1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2018 Intel Corporation. */
4 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6 #include <linux/module.h>
7 #include <linux/types.h>
8 #include <linux/init.h>
9 #include <linux/bitops.h>
10 #include <linux/vmalloc.h>
11 #include <linux/pagemap.h>
12 #include <linux/netdevice.h>
13 #include <linux/ipv6.h>
14 #include <linux/slab.h>
15 #include <net/checksum.h>
16 #include <net/ip6_checksum.h>
17 #include <net/pkt_sched.h>
18 #include <net/pkt_cls.h>
19 #include <linux/net_tstamp.h>
20 #include <linux/mii.h>
21 #include <linux/ethtool.h>
23 #include <linux/if_vlan.h>
24 #include <linux/pci.h>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
28 #include <linux/tcp.h>
29 #include <linux/sctp.h>
30 #include <linux/if_ether.h>
31 #include <linux/aer.h>
32 #include <linux/prefetch.h>
33 #include <linux/pm_runtime.h>
34 #include <linux/etherdevice.h>
36 #include <linux/dca.h>
38 #include <linux/i2c.h>
44 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
45 __stringify(BUILD) "-k"
48 QUEUE_MODE_STRICT_PRIORITY,
49 QUEUE_MODE_STREAM_RESERVATION,
57 char igb_driver_name[] = "igb";
58 char igb_driver_version[] = DRV_VERSION;
59 static const char igb_driver_string[] =
60 "Intel(R) Gigabit Ethernet Network Driver";
61 static const char igb_copyright[] =
62 "Copyright (c) 2007-2014 Intel Corporation.";
64 static const struct e1000_info *igb_info_tbl[] = {
65 [board_82575] = &e1000_82575_info,
68 static const struct pci_device_id igb_pci_tbl[] = {
69 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
70 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_SGMII) },
71 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
72 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I211_COPPER), board_82575 },
73 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER), board_82575 },
74 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_FIBER), board_82575 },
75 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES), board_82575 },
76 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SGMII), board_82575 },
77 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER_FLASHLESS), board_82575 },
78 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES_FLASHLESS), board_82575 },
79 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER), board_82575 },
80 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER), board_82575 },
81 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES), board_82575 },
82 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII), board_82575 },
83 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER), board_82575 },
84 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER), board_82575 },
85 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_QUAD_FIBER), board_82575 },
86 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES), board_82575 },
87 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII), board_82575 },
88 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL), board_82575 },
89 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SGMII), board_82575 },
90 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SERDES), board_82575 },
91 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_BACKPLANE), board_82575 },
92 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SFP), board_82575 },
93 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
94 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 },
95 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES), board_82575 },
96 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
97 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
98 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 },
99 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2), board_82575 },
100 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 },
101 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
102 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
103 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
104 /* required last entry */
108 MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
110 static int igb_setup_all_tx_resources(struct igb_adapter *);
111 static int igb_setup_all_rx_resources(struct igb_adapter *);
112 static void igb_free_all_tx_resources(struct igb_adapter *);
113 static void igb_free_all_rx_resources(struct igb_adapter *);
114 static void igb_setup_mrqc(struct igb_adapter *);
115 static int igb_probe(struct pci_dev *, const struct pci_device_id *);
116 static void igb_remove(struct pci_dev *pdev);
117 static int igb_sw_init(struct igb_adapter *);
118 int igb_open(struct net_device *);
119 int igb_close(struct net_device *);
120 static void igb_configure(struct igb_adapter *);
121 static void igb_configure_tx(struct igb_adapter *);
122 static void igb_configure_rx(struct igb_adapter *);
123 static void igb_clean_all_tx_rings(struct igb_adapter *);
124 static void igb_clean_all_rx_rings(struct igb_adapter *);
125 static void igb_clean_tx_ring(struct igb_ring *);
126 static void igb_clean_rx_ring(struct igb_ring *);
127 static void igb_set_rx_mode(struct net_device *);
128 static void igb_update_phy_info(struct timer_list *);
129 static void igb_watchdog(struct timer_list *);
130 static void igb_watchdog_task(struct work_struct *);
131 static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, struct net_device *);
132 static void igb_get_stats64(struct net_device *dev,
133 struct rtnl_link_stats64 *stats);
134 static int igb_change_mtu(struct net_device *, int);
135 static int igb_set_mac(struct net_device *, void *);
136 static void igb_set_uta(struct igb_adapter *adapter, bool set);
137 static irqreturn_t igb_intr(int irq, void *);
138 static irqreturn_t igb_intr_msi(int irq, void *);
139 static irqreturn_t igb_msix_other(int irq, void *);
140 static irqreturn_t igb_msix_ring(int irq, void *);
141 #ifdef CONFIG_IGB_DCA
142 static void igb_update_dca(struct igb_q_vector *);
143 static void igb_setup_dca(struct igb_adapter *);
144 #endif /* CONFIG_IGB_DCA */
145 static int igb_poll(struct napi_struct *, int);
146 static bool igb_clean_tx_irq(struct igb_q_vector *, int);
147 static int igb_clean_rx_irq(struct igb_q_vector *, int);
148 static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
149 static void igb_tx_timeout(struct net_device *);
150 static void igb_reset_task(struct work_struct *);
151 static void igb_vlan_mode(struct net_device *netdev,
152 netdev_features_t features);
153 static int igb_vlan_rx_add_vid(struct net_device *, __be16, u16);
154 static int igb_vlan_rx_kill_vid(struct net_device *, __be16, u16);
155 static void igb_restore_vlan(struct igb_adapter *);
156 static void igb_rar_set_index(struct igb_adapter *, u32);
157 static void igb_ping_all_vfs(struct igb_adapter *);
158 static void igb_msg_task(struct igb_adapter *);
159 static void igb_vmm_control(struct igb_adapter *);
160 static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *);
161 static void igb_flush_mac_table(struct igb_adapter *);
162 static int igb_available_rars(struct igb_adapter *, u8);
163 static void igb_set_default_mac_filter(struct igb_adapter *);
164 static int igb_uc_sync(struct net_device *, const unsigned char *);
165 static int igb_uc_unsync(struct net_device *, const unsigned char *);
166 static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
167 static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac);
168 static int igb_ndo_set_vf_vlan(struct net_device *netdev,
169 int vf, u16 vlan, u8 qos, __be16 vlan_proto);
170 static int igb_ndo_set_vf_bw(struct net_device *, int, int, int);
171 static int igb_ndo_set_vf_spoofchk(struct net_device *netdev, int vf,
173 static int igb_ndo_set_vf_trust(struct net_device *netdev, int vf,
175 static int igb_ndo_get_vf_config(struct net_device *netdev, int vf,
176 struct ifla_vf_info *ivi);
177 static void igb_check_vf_rate_limit(struct igb_adapter *);
178 static void igb_nfc_filter_exit(struct igb_adapter *adapter);
179 static void igb_nfc_filter_restore(struct igb_adapter *adapter);
181 #ifdef CONFIG_PCI_IOV
182 static int igb_vf_configure(struct igb_adapter *adapter, int vf);
183 static int igb_pci_enable_sriov(struct pci_dev *dev, int num_vfs);
184 static int igb_disable_sriov(struct pci_dev *dev);
185 static int igb_pci_disable_sriov(struct pci_dev *dev);
188 static int igb_suspend(struct device *);
189 static int igb_resume(struct device *);
190 static int igb_runtime_suspend(struct device *dev);
191 static int igb_runtime_resume(struct device *dev);
192 static int igb_runtime_idle(struct device *dev);
193 static const struct dev_pm_ops igb_pm_ops = {
194 SET_SYSTEM_SLEEP_PM_OPS(igb_suspend, igb_resume)
195 SET_RUNTIME_PM_OPS(igb_runtime_suspend, igb_runtime_resume,
198 static void igb_shutdown(struct pci_dev *);
199 static int igb_pci_sriov_configure(struct pci_dev *dev, int num_vfs);
200 #ifdef CONFIG_IGB_DCA
201 static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
202 static struct notifier_block dca_notifier = {
203 .notifier_call = igb_notify_dca,
208 #ifdef CONFIG_PCI_IOV
209 static unsigned int max_vfs;
210 module_param(max_vfs, uint, 0);
211 MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate per physical function");
212 #endif /* CONFIG_PCI_IOV */
214 static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
215 pci_channel_state_t);
216 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
217 static void igb_io_resume(struct pci_dev *);
219 static const struct pci_error_handlers igb_err_handler = {
220 .error_detected = igb_io_error_detected,
221 .slot_reset = igb_io_slot_reset,
222 .resume = igb_io_resume,
225 static void igb_init_dmac(struct igb_adapter *adapter, u32 pba);
227 static struct pci_driver igb_driver = {
228 .name = igb_driver_name,
229 .id_table = igb_pci_tbl,
231 .remove = igb_remove,
233 .driver.pm = &igb_pm_ops,
235 .shutdown = igb_shutdown,
236 .sriov_configure = igb_pci_sriov_configure,
237 .err_handler = &igb_err_handler
240 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
241 MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
242 MODULE_LICENSE("GPL");
243 MODULE_VERSION(DRV_VERSION);
245 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
246 static int debug = -1;
247 module_param(debug, int, 0);
248 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
250 struct igb_reg_info {
255 static const struct igb_reg_info igb_reg_info_tbl[] = {
257 /* General Registers */
258 {E1000_CTRL, "CTRL"},
259 {E1000_STATUS, "STATUS"},
260 {E1000_CTRL_EXT, "CTRL_EXT"},
262 /* Interrupt Registers */
266 {E1000_RCTL, "RCTL"},
267 {E1000_RDLEN(0), "RDLEN"},
268 {E1000_RDH(0), "RDH"},
269 {E1000_RDT(0), "RDT"},
270 {E1000_RXDCTL(0), "RXDCTL"},
271 {E1000_RDBAL(0), "RDBAL"},
272 {E1000_RDBAH(0), "RDBAH"},
275 {E1000_TCTL, "TCTL"},
276 {E1000_TDBAL(0), "TDBAL"},
277 {E1000_TDBAH(0), "TDBAH"},
278 {E1000_TDLEN(0), "TDLEN"},
279 {E1000_TDH(0), "TDH"},
280 {E1000_TDT(0), "TDT"},
281 {E1000_TXDCTL(0), "TXDCTL"},
282 {E1000_TDFH, "TDFH"},
283 {E1000_TDFT, "TDFT"},
284 {E1000_TDFHS, "TDFHS"},
285 {E1000_TDFPC, "TDFPC"},
287 /* List Terminator */
291 /* igb_regdump - register printout routine */
292 static void igb_regdump(struct e1000_hw *hw, struct igb_reg_info *reginfo)
298 switch (reginfo->ofs) {
300 for (n = 0; n < 4; n++)
301 regs[n] = rd32(E1000_RDLEN(n));
304 for (n = 0; n < 4; n++)
305 regs[n] = rd32(E1000_RDH(n));
308 for (n = 0; n < 4; n++)
309 regs[n] = rd32(E1000_RDT(n));
311 case E1000_RXDCTL(0):
312 for (n = 0; n < 4; n++)
313 regs[n] = rd32(E1000_RXDCTL(n));
316 for (n = 0; n < 4; n++)
317 regs[n] = rd32(E1000_RDBAL(n));
320 for (n = 0; n < 4; n++)
321 regs[n] = rd32(E1000_RDBAH(n));
324 for (n = 0; n < 4; n++)
325 regs[n] = rd32(E1000_RDBAL(n));
328 for (n = 0; n < 4; n++)
329 regs[n] = rd32(E1000_TDBAH(n));
332 for (n = 0; n < 4; n++)
333 regs[n] = rd32(E1000_TDLEN(n));
336 for (n = 0; n < 4; n++)
337 regs[n] = rd32(E1000_TDH(n));
340 for (n = 0; n < 4; n++)
341 regs[n] = rd32(E1000_TDT(n));
343 case E1000_TXDCTL(0):
344 for (n = 0; n < 4; n++)
345 regs[n] = rd32(E1000_TXDCTL(n));
348 pr_info("%-15s %08x\n", reginfo->name, rd32(reginfo->ofs));
352 snprintf(rname, 16, "%s%s", reginfo->name, "[0-3]");
353 pr_info("%-15s %08x %08x %08x %08x\n", rname, regs[0], regs[1],
357 /* igb_dump - Print registers, Tx-rings and Rx-rings */
358 static void igb_dump(struct igb_adapter *adapter)
360 struct net_device *netdev = adapter->netdev;
361 struct e1000_hw *hw = &adapter->hw;
362 struct igb_reg_info *reginfo;
363 struct igb_ring *tx_ring;
364 union e1000_adv_tx_desc *tx_desc;
365 struct my_u0 { u64 a; u64 b; } *u0;
366 struct igb_ring *rx_ring;
367 union e1000_adv_rx_desc *rx_desc;
371 if (!netif_msg_hw(adapter))
374 /* Print netdevice Info */
376 dev_info(&adapter->pdev->dev, "Net device Info\n");
377 pr_info("Device Name state trans_start\n");
378 pr_info("%-15s %016lX %016lX\n", netdev->name,
379 netdev->state, dev_trans_start(netdev));
382 /* Print Registers */
383 dev_info(&adapter->pdev->dev, "Register Dump\n");
384 pr_info(" Register Name Value\n");
385 for (reginfo = (struct igb_reg_info *)igb_reg_info_tbl;
386 reginfo->name; reginfo++) {
387 igb_regdump(hw, reginfo);
390 /* Print TX Ring Summary */
391 if (!netdev || !netif_running(netdev))
394 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
395 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
396 for (n = 0; n < adapter->num_tx_queues; n++) {
397 struct igb_tx_buffer *buffer_info;
398 tx_ring = adapter->tx_ring[n];
399 buffer_info = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
400 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
401 n, tx_ring->next_to_use, tx_ring->next_to_clean,
402 (u64)dma_unmap_addr(buffer_info, dma),
403 dma_unmap_len(buffer_info, len),
404 buffer_info->next_to_watch,
405 (u64)buffer_info->time_stamp);
409 if (!netif_msg_tx_done(adapter))
410 goto rx_ring_summary;
412 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
414 /* Transmit Descriptor Formats
416 * Advanced Transmit Descriptor
417 * +--------------------------------------------------------------+
418 * 0 | Buffer Address [63:0] |
419 * +--------------------------------------------------------------+
420 * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN |
421 * +--------------------------------------------------------------+
422 * 63 46 45 40 39 38 36 35 32 31 24 15 0
425 for (n = 0; n < adapter->num_tx_queues; n++) {
426 tx_ring = adapter->tx_ring[n];
427 pr_info("------------------------------------\n");
428 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
429 pr_info("------------------------------------\n");
430 pr_info("T [desc] [address 63:0 ] [PlPOCIStDDM Ln] [bi->dma ] leng ntw timestamp bi->skb\n");
432 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
433 const char *next_desc;
434 struct igb_tx_buffer *buffer_info;
435 tx_desc = IGB_TX_DESC(tx_ring, i);
436 buffer_info = &tx_ring->tx_buffer_info[i];
437 u0 = (struct my_u0 *)tx_desc;
438 if (i == tx_ring->next_to_use &&
439 i == tx_ring->next_to_clean)
440 next_desc = " NTC/U";
441 else if (i == tx_ring->next_to_use)
443 else if (i == tx_ring->next_to_clean)
448 pr_info("T [0x%03X] %016llX %016llX %016llX %04X %p %016llX %p%s\n",
449 i, le64_to_cpu(u0->a),
451 (u64)dma_unmap_addr(buffer_info, dma),
452 dma_unmap_len(buffer_info, len),
453 buffer_info->next_to_watch,
454 (u64)buffer_info->time_stamp,
455 buffer_info->skb, next_desc);
457 if (netif_msg_pktdata(adapter) && buffer_info->skb)
458 print_hex_dump(KERN_INFO, "",
460 16, 1, buffer_info->skb->data,
461 dma_unmap_len(buffer_info, len),
466 /* Print RX Rings Summary */
468 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
469 pr_info("Queue [NTU] [NTC]\n");
470 for (n = 0; n < adapter->num_rx_queues; n++) {
471 rx_ring = adapter->rx_ring[n];
472 pr_info(" %5d %5X %5X\n",
473 n, rx_ring->next_to_use, rx_ring->next_to_clean);
477 if (!netif_msg_rx_status(adapter))
480 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
482 /* Advanced Receive Descriptor (Read) Format
484 * +-----------------------------------------------------+
485 * 0 | Packet Buffer Address [63:1] |A0/NSE|
486 * +----------------------------------------------+------+
487 * 8 | Header Buffer Address [63:1] | DD |
488 * +-----------------------------------------------------+
491 * Advanced Receive Descriptor (Write-Back) Format
493 * 63 48 47 32 31 30 21 20 17 16 4 3 0
494 * +------------------------------------------------------+
495 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
496 * | Checksum Ident | | | | Type | Type |
497 * +------------------------------------------------------+
498 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
499 * +------------------------------------------------------+
500 * 63 48 47 32 31 20 19 0
503 for (n = 0; n < adapter->num_rx_queues; n++) {
504 rx_ring = adapter->rx_ring[n];
505 pr_info("------------------------------------\n");
506 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
507 pr_info("------------------------------------\n");
508 pr_info("R [desc] [ PktBuf A0] [ HeadBuf DD] [bi->dma ] [bi->skb] <-- Adv Rx Read format\n");
509 pr_info("RWB[desc] [PcsmIpSHl PtRs] [vl er S cks ln] ---------------- [bi->skb] <-- Adv Rx Write-Back format\n");
511 for (i = 0; i < rx_ring->count; i++) {
512 const char *next_desc;
513 struct igb_rx_buffer *buffer_info;
514 buffer_info = &rx_ring->rx_buffer_info[i];
515 rx_desc = IGB_RX_DESC(rx_ring, i);
516 u0 = (struct my_u0 *)rx_desc;
517 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
519 if (i == rx_ring->next_to_use)
521 else if (i == rx_ring->next_to_clean)
526 if (staterr & E1000_RXD_STAT_DD) {
527 /* Descriptor Done */
528 pr_info("%s[0x%03X] %016llX %016llX ---------------- %s\n",
534 pr_info("%s[0x%03X] %016llX %016llX %016llX %s\n",
538 (u64)buffer_info->dma,
541 if (netif_msg_pktdata(adapter) &&
542 buffer_info->dma && buffer_info->page) {
543 print_hex_dump(KERN_INFO, "",
546 page_address(buffer_info->page) +
547 buffer_info->page_offset,
548 igb_rx_bufsz(rx_ring), true);
559 * igb_get_i2c_data - Reads the I2C SDA data bit
560 * @hw: pointer to hardware structure
561 * @i2cctl: Current value of I2CCTL register
563 * Returns the I2C data bit value
565 static int igb_get_i2c_data(void *data)
567 struct igb_adapter *adapter = (struct igb_adapter *)data;
568 struct e1000_hw *hw = &adapter->hw;
569 s32 i2cctl = rd32(E1000_I2CPARAMS);
571 return !!(i2cctl & E1000_I2C_DATA_IN);
575 * igb_set_i2c_data - Sets the I2C data bit
576 * @data: pointer to hardware structure
577 * @state: I2C data value (0 or 1) to set
579 * Sets the I2C data bit
581 static void igb_set_i2c_data(void *data, int state)
583 struct igb_adapter *adapter = (struct igb_adapter *)data;
584 struct e1000_hw *hw = &adapter->hw;
585 s32 i2cctl = rd32(E1000_I2CPARAMS);
588 i2cctl |= E1000_I2C_DATA_OUT;
590 i2cctl &= ~E1000_I2C_DATA_OUT;
592 i2cctl &= ~E1000_I2C_DATA_OE_N;
593 i2cctl |= E1000_I2C_CLK_OE_N;
594 wr32(E1000_I2CPARAMS, i2cctl);
600 * igb_set_i2c_clk - Sets the I2C SCL clock
601 * @data: pointer to hardware structure
602 * @state: state to set clock
604 * Sets the I2C clock line to state
606 static void igb_set_i2c_clk(void *data, int state)
608 struct igb_adapter *adapter = (struct igb_adapter *)data;
609 struct e1000_hw *hw = &adapter->hw;
610 s32 i2cctl = rd32(E1000_I2CPARAMS);
613 i2cctl |= E1000_I2C_CLK_OUT;
614 i2cctl &= ~E1000_I2C_CLK_OE_N;
616 i2cctl &= ~E1000_I2C_CLK_OUT;
617 i2cctl &= ~E1000_I2C_CLK_OE_N;
619 wr32(E1000_I2CPARAMS, i2cctl);
624 * igb_get_i2c_clk - Gets the I2C SCL clock state
625 * @data: pointer to hardware structure
627 * Gets the I2C clock state
629 static int igb_get_i2c_clk(void *data)
631 struct igb_adapter *adapter = (struct igb_adapter *)data;
632 struct e1000_hw *hw = &adapter->hw;
633 s32 i2cctl = rd32(E1000_I2CPARAMS);
635 return !!(i2cctl & E1000_I2C_CLK_IN);
638 static const struct i2c_algo_bit_data igb_i2c_algo = {
639 .setsda = igb_set_i2c_data,
640 .setscl = igb_set_i2c_clk,
641 .getsda = igb_get_i2c_data,
642 .getscl = igb_get_i2c_clk,
648 * igb_get_hw_dev - return device
649 * @hw: pointer to hardware structure
651 * used by hardware layer to print debugging information
653 struct net_device *igb_get_hw_dev(struct e1000_hw *hw)
655 struct igb_adapter *adapter = hw->back;
656 return adapter->netdev;
660 * igb_init_module - Driver Registration Routine
662 * igb_init_module is the first routine called when the driver is
663 * loaded. All it does is register with the PCI subsystem.
665 static int __init igb_init_module(void)
669 pr_info("%s - version %s\n",
670 igb_driver_string, igb_driver_version);
671 pr_info("%s\n", igb_copyright);
673 #ifdef CONFIG_IGB_DCA
674 dca_register_notify(&dca_notifier);
676 ret = pci_register_driver(&igb_driver);
680 module_init(igb_init_module);
683 * igb_exit_module - Driver Exit Cleanup Routine
685 * igb_exit_module is called just before the driver is removed
688 static void __exit igb_exit_module(void)
690 #ifdef CONFIG_IGB_DCA
691 dca_unregister_notify(&dca_notifier);
693 pci_unregister_driver(&igb_driver);
696 module_exit(igb_exit_module);
698 #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
700 * igb_cache_ring_register - Descriptor ring to register mapping
701 * @adapter: board private structure to initialize
703 * Once we know the feature-set enabled for the device, we'll cache
704 * the register offset the descriptor ring is assigned to.
706 static void igb_cache_ring_register(struct igb_adapter *adapter)
709 u32 rbase_offset = adapter->vfs_allocated_count;
711 switch (adapter->hw.mac.type) {
713 /* The queues are allocated for virtualization such that VF 0
714 * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
715 * In order to avoid collision we start at the first free queue
716 * and continue consuming queues in the same sequence
718 if (adapter->vfs_allocated_count) {
719 for (; i < adapter->rss_queues; i++)
720 adapter->rx_ring[i]->reg_idx = rbase_offset +
732 for (; i < adapter->num_rx_queues; i++)
733 adapter->rx_ring[i]->reg_idx = rbase_offset + i;
734 for (; j < adapter->num_tx_queues; j++)
735 adapter->tx_ring[j]->reg_idx = rbase_offset + j;
740 u32 igb_rd32(struct e1000_hw *hw, u32 reg)
742 struct igb_adapter *igb = container_of(hw, struct igb_adapter, hw);
743 u8 __iomem *hw_addr = READ_ONCE(hw->hw_addr);
746 if (E1000_REMOVED(hw_addr))
749 value = readl(&hw_addr[reg]);
751 /* reads should not return all F's */
752 if (!(~value) && (!reg || !(~readl(hw_addr)))) {
753 struct net_device *netdev = igb->netdev;
755 netdev_err(netdev, "PCIe link lost\n");
762 * igb_write_ivar - configure ivar for given MSI-X vector
763 * @hw: pointer to the HW structure
764 * @msix_vector: vector number we are allocating to a given ring
765 * @index: row index of IVAR register to write within IVAR table
766 * @offset: column offset of in IVAR, should be multiple of 8
768 * This function is intended to handle the writing of the IVAR register
769 * for adapters 82576 and newer. The IVAR table consists of 2 columns,
770 * each containing an cause allocation for an Rx and Tx ring, and a
771 * variable number of rows depending on the number of queues supported.
773 static void igb_write_ivar(struct e1000_hw *hw, int msix_vector,
774 int index, int offset)
776 u32 ivar = array_rd32(E1000_IVAR0, index);
778 /* clear any bits that are currently set */
779 ivar &= ~((u32)0xFF << offset);
781 /* write vector and valid bit */
782 ivar |= (msix_vector | E1000_IVAR_VALID) << offset;
784 array_wr32(E1000_IVAR0, index, ivar);
787 #define IGB_N0_QUEUE -1
788 static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector)
790 struct igb_adapter *adapter = q_vector->adapter;
791 struct e1000_hw *hw = &adapter->hw;
792 int rx_queue = IGB_N0_QUEUE;
793 int tx_queue = IGB_N0_QUEUE;
796 if (q_vector->rx.ring)
797 rx_queue = q_vector->rx.ring->reg_idx;
798 if (q_vector->tx.ring)
799 tx_queue = q_vector->tx.ring->reg_idx;
801 switch (hw->mac.type) {
803 /* The 82575 assigns vectors using a bitmask, which matches the
804 * bitmask for the EICR/EIMS/EIMC registers. To assign one
805 * or more queues to a vector, we write the appropriate bits
806 * into the MSIXBM register for that vector.
808 if (rx_queue > IGB_N0_QUEUE)
809 msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
810 if (tx_queue > IGB_N0_QUEUE)
811 msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
812 if (!(adapter->flags & IGB_FLAG_HAS_MSIX) && msix_vector == 0)
813 msixbm |= E1000_EIMS_OTHER;
814 array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
815 q_vector->eims_value = msixbm;
818 /* 82576 uses a table that essentially consists of 2 columns
819 * with 8 rows. The ordering is column-major so we use the
820 * lower 3 bits as the row index, and the 4th bit as the
823 if (rx_queue > IGB_N0_QUEUE)
824 igb_write_ivar(hw, msix_vector,
826 (rx_queue & 0x8) << 1);
827 if (tx_queue > IGB_N0_QUEUE)
828 igb_write_ivar(hw, msix_vector,
830 ((tx_queue & 0x8) << 1) + 8);
831 q_vector->eims_value = BIT(msix_vector);
838 /* On 82580 and newer adapters the scheme is similar to 82576
839 * however instead of ordering column-major we have things
840 * ordered row-major. So we traverse the table by using
841 * bit 0 as the column offset, and the remaining bits as the
844 if (rx_queue > IGB_N0_QUEUE)
845 igb_write_ivar(hw, msix_vector,
847 (rx_queue & 0x1) << 4);
848 if (tx_queue > IGB_N0_QUEUE)
849 igb_write_ivar(hw, msix_vector,
851 ((tx_queue & 0x1) << 4) + 8);
852 q_vector->eims_value = BIT(msix_vector);
859 /* add q_vector eims value to global eims_enable_mask */
860 adapter->eims_enable_mask |= q_vector->eims_value;
862 /* configure q_vector to set itr on first interrupt */
863 q_vector->set_itr = 1;
867 * igb_configure_msix - Configure MSI-X hardware
868 * @adapter: board private structure to initialize
870 * igb_configure_msix sets up the hardware to properly
871 * generate MSI-X interrupts.
873 static void igb_configure_msix(struct igb_adapter *adapter)
877 struct e1000_hw *hw = &adapter->hw;
879 adapter->eims_enable_mask = 0;
881 /* set vector for other causes, i.e. link changes */
882 switch (hw->mac.type) {
884 tmp = rd32(E1000_CTRL_EXT);
885 /* enable MSI-X PBA support*/
886 tmp |= E1000_CTRL_EXT_PBA_CLR;
888 /* Auto-Mask interrupts upon ICR read. */
889 tmp |= E1000_CTRL_EXT_EIAME;
890 tmp |= E1000_CTRL_EXT_IRCA;
892 wr32(E1000_CTRL_EXT, tmp);
894 /* enable msix_other interrupt */
895 array_wr32(E1000_MSIXBM(0), vector++, E1000_EIMS_OTHER);
896 adapter->eims_other = E1000_EIMS_OTHER;
906 /* Turn on MSI-X capability first, or our settings
907 * won't stick. And it will take days to debug.
909 wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
910 E1000_GPIE_PBA | E1000_GPIE_EIAME |
913 /* enable msix_other interrupt */
914 adapter->eims_other = BIT(vector);
915 tmp = (vector++ | E1000_IVAR_VALID) << 8;
917 wr32(E1000_IVAR_MISC, tmp);
920 /* do nothing, since nothing else supports MSI-X */
922 } /* switch (hw->mac.type) */
924 adapter->eims_enable_mask |= adapter->eims_other;
926 for (i = 0; i < adapter->num_q_vectors; i++)
927 igb_assign_vector(adapter->q_vector[i], vector++);
933 * igb_request_msix - Initialize MSI-X interrupts
934 * @adapter: board private structure to initialize
936 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
939 static int igb_request_msix(struct igb_adapter *adapter)
941 unsigned int num_q_vectors = adapter->num_q_vectors;
942 struct net_device *netdev = adapter->netdev;
943 int i, err = 0, vector = 0, free_vector = 0;
945 err = request_irq(adapter->msix_entries[vector].vector,
946 igb_msix_other, 0, netdev->name, adapter);
950 if (num_q_vectors > MAX_Q_VECTORS) {
951 num_q_vectors = MAX_Q_VECTORS;
952 dev_warn(&adapter->pdev->dev,
953 "The number of queue vectors (%d) is higher than max allowed (%d)\n",
954 adapter->num_q_vectors, MAX_Q_VECTORS);
956 for (i = 0; i < num_q_vectors; i++) {
957 struct igb_q_vector *q_vector = adapter->q_vector[i];
961 q_vector->itr_register = adapter->io_addr + E1000_EITR(vector);
963 if (q_vector->rx.ring && q_vector->tx.ring)
964 sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
965 q_vector->rx.ring->queue_index);
966 else if (q_vector->tx.ring)
967 sprintf(q_vector->name, "%s-tx-%u", netdev->name,
968 q_vector->tx.ring->queue_index);
969 else if (q_vector->rx.ring)
970 sprintf(q_vector->name, "%s-rx-%u", netdev->name,
971 q_vector->rx.ring->queue_index);
973 sprintf(q_vector->name, "%s-unused", netdev->name);
975 err = request_irq(adapter->msix_entries[vector].vector,
976 igb_msix_ring, 0, q_vector->name,
982 igb_configure_msix(adapter);
986 /* free already assigned IRQs */
987 free_irq(adapter->msix_entries[free_vector++].vector, adapter);
990 for (i = 0; i < vector; i++) {
991 free_irq(adapter->msix_entries[free_vector++].vector,
992 adapter->q_vector[i]);
999 * igb_free_q_vector - Free memory allocated for specific interrupt vector
1000 * @adapter: board private structure to initialize
1001 * @v_idx: Index of vector to be freed
1003 * This function frees the memory allocated to the q_vector.
1005 static void igb_free_q_vector(struct igb_adapter *adapter, int v_idx)
1007 struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
1009 adapter->q_vector[v_idx] = NULL;
1011 /* igb_get_stats64() might access the rings on this vector,
1012 * we must wait a grace period before freeing it.
1015 kfree_rcu(q_vector, rcu);
1019 * igb_reset_q_vector - Reset config for interrupt vector
1020 * @adapter: board private structure to initialize
1021 * @v_idx: Index of vector to be reset
1023 * If NAPI is enabled it will delete any references to the
1024 * NAPI struct. This is preparation for igb_free_q_vector.
1026 static void igb_reset_q_vector(struct igb_adapter *adapter, int v_idx)
1028 struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
1030 /* Coming from igb_set_interrupt_capability, the vectors are not yet
1031 * allocated. So, q_vector is NULL so we should stop here.
1036 if (q_vector->tx.ring)
1037 adapter->tx_ring[q_vector->tx.ring->queue_index] = NULL;
1039 if (q_vector->rx.ring)
1040 adapter->rx_ring[q_vector->rx.ring->queue_index] = NULL;
1042 netif_napi_del(&q_vector->napi);
1046 static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
1048 int v_idx = adapter->num_q_vectors;
1050 if (adapter->flags & IGB_FLAG_HAS_MSIX)
1051 pci_disable_msix(adapter->pdev);
1052 else if (adapter->flags & IGB_FLAG_HAS_MSI)
1053 pci_disable_msi(adapter->pdev);
1056 igb_reset_q_vector(adapter, v_idx);
1060 * igb_free_q_vectors - Free memory allocated for interrupt vectors
1061 * @adapter: board private structure to initialize
1063 * This function frees the memory allocated to the q_vectors. In addition if
1064 * NAPI is enabled it will delete any references to the NAPI struct prior
1065 * to freeing the q_vector.
1067 static void igb_free_q_vectors(struct igb_adapter *adapter)
1069 int v_idx = adapter->num_q_vectors;
1071 adapter->num_tx_queues = 0;
1072 adapter->num_rx_queues = 0;
1073 adapter->num_q_vectors = 0;
1076 igb_reset_q_vector(adapter, v_idx);
1077 igb_free_q_vector(adapter, v_idx);
1082 * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
1083 * @adapter: board private structure to initialize
1085 * This function resets the device so that it has 0 Rx queues, Tx queues, and
1086 * MSI-X interrupts allocated.
1088 static void igb_clear_interrupt_scheme(struct igb_adapter *adapter)
1090 igb_free_q_vectors(adapter);
1091 igb_reset_interrupt_capability(adapter);
1095 * igb_set_interrupt_capability - set MSI or MSI-X if supported
1096 * @adapter: board private structure to initialize
1097 * @msix: boolean value of MSIX capability
1099 * Attempt to configure interrupts using the best available
1100 * capabilities of the hardware and kernel.
1102 static void igb_set_interrupt_capability(struct igb_adapter *adapter, bool msix)
1109 adapter->flags |= IGB_FLAG_HAS_MSIX;
1111 /* Number of supported queues. */
1112 adapter->num_rx_queues = adapter->rss_queues;
1113 if (adapter->vfs_allocated_count)
1114 adapter->num_tx_queues = 1;
1116 adapter->num_tx_queues = adapter->rss_queues;
1118 /* start with one vector for every Rx queue */
1119 numvecs = adapter->num_rx_queues;
1121 /* if Tx handler is separate add 1 for every Tx queue */
1122 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS))
1123 numvecs += adapter->num_tx_queues;
1125 /* store the number of vectors reserved for queues */
1126 adapter->num_q_vectors = numvecs;
1128 /* add 1 vector for link status interrupts */
1130 for (i = 0; i < numvecs; i++)
1131 adapter->msix_entries[i].entry = i;
1133 err = pci_enable_msix_range(adapter->pdev,
1134 adapter->msix_entries,
1140 igb_reset_interrupt_capability(adapter);
1142 /* If we can't do MSI-X, try MSI */
1144 adapter->flags &= ~IGB_FLAG_HAS_MSIX;
1145 #ifdef CONFIG_PCI_IOV
1146 /* disable SR-IOV for non MSI-X configurations */
1147 if (adapter->vf_data) {
1148 struct e1000_hw *hw = &adapter->hw;
1149 /* disable iov and allow time for transactions to clear */
1150 pci_disable_sriov(adapter->pdev);
1153 kfree(adapter->vf_mac_list);
1154 adapter->vf_mac_list = NULL;
1155 kfree(adapter->vf_data);
1156 adapter->vf_data = NULL;
1157 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
1160 dev_info(&adapter->pdev->dev, "IOV Disabled\n");
1163 adapter->vfs_allocated_count = 0;
1164 adapter->rss_queues = 1;
1165 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
1166 adapter->num_rx_queues = 1;
1167 adapter->num_tx_queues = 1;
1168 adapter->num_q_vectors = 1;
1169 if (!pci_enable_msi(adapter->pdev))
1170 adapter->flags |= IGB_FLAG_HAS_MSI;
1173 static void igb_add_ring(struct igb_ring *ring,
1174 struct igb_ring_container *head)
1181 * igb_alloc_q_vector - Allocate memory for a single interrupt vector
1182 * @adapter: board private structure to initialize
1183 * @v_count: q_vectors allocated on adapter, used for ring interleaving
1184 * @v_idx: index of vector in adapter struct
1185 * @txr_count: total number of Tx rings to allocate
1186 * @txr_idx: index of first Tx ring to allocate
1187 * @rxr_count: total number of Rx rings to allocate
1188 * @rxr_idx: index of first Rx ring to allocate
1190 * We allocate one q_vector. If allocation fails we return -ENOMEM.
1192 static int igb_alloc_q_vector(struct igb_adapter *adapter,
1193 int v_count, int v_idx,
1194 int txr_count, int txr_idx,
1195 int rxr_count, int rxr_idx)
1197 struct igb_q_vector *q_vector;
1198 struct igb_ring *ring;
1199 int ring_count, size;
1201 /* igb only supports 1 Tx and/or 1 Rx queue per vector */
1202 if (txr_count > 1 || rxr_count > 1)
1205 ring_count = txr_count + rxr_count;
1206 size = sizeof(struct igb_q_vector) +
1207 (sizeof(struct igb_ring) * ring_count);
1209 /* allocate q_vector and rings */
1210 q_vector = adapter->q_vector[v_idx];
1212 q_vector = kzalloc(size, GFP_KERNEL);
1213 } else if (size > ksize(q_vector)) {
1214 kfree_rcu(q_vector, rcu);
1215 q_vector = kzalloc(size, GFP_KERNEL);
1217 memset(q_vector, 0, size);
1222 /* initialize NAPI */
1223 netif_napi_add(adapter->netdev, &q_vector->napi,
1226 /* tie q_vector and adapter together */
1227 adapter->q_vector[v_idx] = q_vector;
1228 q_vector->adapter = adapter;
1230 /* initialize work limits */
1231 q_vector->tx.work_limit = adapter->tx_work_limit;
1233 /* initialize ITR configuration */
1234 q_vector->itr_register = adapter->io_addr + E1000_EITR(0);
1235 q_vector->itr_val = IGB_START_ITR;
1237 /* initialize pointer to rings */
1238 ring = q_vector->ring;
1242 /* rx or rx/tx vector */
1243 if (!adapter->rx_itr_setting || adapter->rx_itr_setting > 3)
1244 q_vector->itr_val = adapter->rx_itr_setting;
1246 /* tx only vector */
1247 if (!adapter->tx_itr_setting || adapter->tx_itr_setting > 3)
1248 q_vector->itr_val = adapter->tx_itr_setting;
1252 /* assign generic ring traits */
1253 ring->dev = &adapter->pdev->dev;
1254 ring->netdev = adapter->netdev;
1256 /* configure backlink on ring */
1257 ring->q_vector = q_vector;
1259 /* update q_vector Tx values */
1260 igb_add_ring(ring, &q_vector->tx);
1262 /* For 82575, context index must be unique per ring. */
1263 if (adapter->hw.mac.type == e1000_82575)
1264 set_bit(IGB_RING_FLAG_TX_CTX_IDX, &ring->flags);
1266 /* apply Tx specific ring traits */
1267 ring->count = adapter->tx_ring_count;
1268 ring->queue_index = txr_idx;
1270 ring->cbs_enable = false;
1271 ring->idleslope = 0;
1272 ring->sendslope = 0;
1276 u64_stats_init(&ring->tx_syncp);
1277 u64_stats_init(&ring->tx_syncp2);
1279 /* assign ring to adapter */
1280 adapter->tx_ring[txr_idx] = ring;
1282 /* push pointer to next ring */
1287 /* assign generic ring traits */
1288 ring->dev = &adapter->pdev->dev;
1289 ring->netdev = adapter->netdev;
1291 /* configure backlink on ring */
1292 ring->q_vector = q_vector;
1294 /* update q_vector Rx values */
1295 igb_add_ring(ring, &q_vector->rx);
1297 /* set flag indicating ring supports SCTP checksum offload */
1298 if (adapter->hw.mac.type >= e1000_82576)
1299 set_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags);
1301 /* On i350, i354, i210, and i211, loopback VLAN packets
1302 * have the tag byte-swapped.
1304 if (adapter->hw.mac.type >= e1000_i350)
1305 set_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &ring->flags);
1307 /* apply Rx specific ring traits */
1308 ring->count = adapter->rx_ring_count;
1309 ring->queue_index = rxr_idx;
1311 u64_stats_init(&ring->rx_syncp);
1313 /* assign ring to adapter */
1314 adapter->rx_ring[rxr_idx] = ring;
1322 * igb_alloc_q_vectors - Allocate memory for interrupt vectors
1323 * @adapter: board private structure to initialize
1325 * We allocate one q_vector per queue interrupt. If allocation fails we
1328 static int igb_alloc_q_vectors(struct igb_adapter *adapter)
1330 int q_vectors = adapter->num_q_vectors;
1331 int rxr_remaining = adapter->num_rx_queues;
1332 int txr_remaining = adapter->num_tx_queues;
1333 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
1336 if (q_vectors >= (rxr_remaining + txr_remaining)) {
1337 for (; rxr_remaining; v_idx++) {
1338 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1344 /* update counts and index */
1350 for (; v_idx < q_vectors; v_idx++) {
1351 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx);
1352 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx);
1354 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1355 tqpv, txr_idx, rqpv, rxr_idx);
1360 /* update counts and index */
1361 rxr_remaining -= rqpv;
1362 txr_remaining -= tqpv;
1370 adapter->num_tx_queues = 0;
1371 adapter->num_rx_queues = 0;
1372 adapter->num_q_vectors = 0;
1375 igb_free_q_vector(adapter, v_idx);
1381 * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
1382 * @adapter: board private structure to initialize
1383 * @msix: boolean value of MSIX capability
1385 * This function initializes the interrupts and allocates all of the queues.
1387 static int igb_init_interrupt_scheme(struct igb_adapter *adapter, bool msix)
1389 struct pci_dev *pdev = adapter->pdev;
1392 igb_set_interrupt_capability(adapter, msix);
1394 err = igb_alloc_q_vectors(adapter);
1396 dev_err(&pdev->dev, "Unable to allocate memory for vectors\n");
1397 goto err_alloc_q_vectors;
1400 igb_cache_ring_register(adapter);
1404 err_alloc_q_vectors:
1405 igb_reset_interrupt_capability(adapter);
1410 * igb_request_irq - initialize interrupts
1411 * @adapter: board private structure to initialize
1413 * Attempts to configure interrupts using the best available
1414 * capabilities of the hardware and kernel.
1416 static int igb_request_irq(struct igb_adapter *adapter)
1418 struct net_device *netdev = adapter->netdev;
1419 struct pci_dev *pdev = adapter->pdev;
1422 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1423 err = igb_request_msix(adapter);
1426 /* fall back to MSI */
1427 igb_free_all_tx_resources(adapter);
1428 igb_free_all_rx_resources(adapter);
1430 igb_clear_interrupt_scheme(adapter);
1431 err = igb_init_interrupt_scheme(adapter, false);
1435 igb_setup_all_tx_resources(adapter);
1436 igb_setup_all_rx_resources(adapter);
1437 igb_configure(adapter);
1440 igb_assign_vector(adapter->q_vector[0], 0);
1442 if (adapter->flags & IGB_FLAG_HAS_MSI) {
1443 err = request_irq(pdev->irq, igb_intr_msi, 0,
1444 netdev->name, adapter);
1448 /* fall back to legacy interrupts */
1449 igb_reset_interrupt_capability(adapter);
1450 adapter->flags &= ~IGB_FLAG_HAS_MSI;
1453 err = request_irq(pdev->irq, igb_intr, IRQF_SHARED,
1454 netdev->name, adapter);
1457 dev_err(&pdev->dev, "Error %d getting interrupt\n",
1464 static void igb_free_irq(struct igb_adapter *adapter)
1466 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1469 free_irq(adapter->msix_entries[vector++].vector, adapter);
1471 for (i = 0; i < adapter->num_q_vectors; i++)
1472 free_irq(adapter->msix_entries[vector++].vector,
1473 adapter->q_vector[i]);
1475 free_irq(adapter->pdev->irq, adapter);
1480 * igb_irq_disable - Mask off interrupt generation on the NIC
1481 * @adapter: board private structure
1483 static void igb_irq_disable(struct igb_adapter *adapter)
1485 struct e1000_hw *hw = &adapter->hw;
1487 /* we need to be careful when disabling interrupts. The VFs are also
1488 * mapped into these registers and so clearing the bits can cause
1489 * issues on the VF drivers so we only need to clear what we set
1491 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1492 u32 regval = rd32(E1000_EIAM);
1494 wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask);
1495 wr32(E1000_EIMC, adapter->eims_enable_mask);
1496 regval = rd32(E1000_EIAC);
1497 wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask);
1501 wr32(E1000_IMC, ~0);
1503 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1506 for (i = 0; i < adapter->num_q_vectors; i++)
1507 synchronize_irq(adapter->msix_entries[i].vector);
1509 synchronize_irq(adapter->pdev->irq);
1514 * igb_irq_enable - Enable default interrupt generation settings
1515 * @adapter: board private structure
1517 static void igb_irq_enable(struct igb_adapter *adapter)
1519 struct e1000_hw *hw = &adapter->hw;
1521 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1522 u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_DRSTA;
1523 u32 regval = rd32(E1000_EIAC);
1525 wr32(E1000_EIAC, regval | adapter->eims_enable_mask);
1526 regval = rd32(E1000_EIAM);
1527 wr32(E1000_EIAM, regval | adapter->eims_enable_mask);
1528 wr32(E1000_EIMS, adapter->eims_enable_mask);
1529 if (adapter->vfs_allocated_count) {
1530 wr32(E1000_MBVFIMR, 0xFF);
1531 ims |= E1000_IMS_VMMB;
1533 wr32(E1000_IMS, ims);
1535 wr32(E1000_IMS, IMS_ENABLE_MASK |
1537 wr32(E1000_IAM, IMS_ENABLE_MASK |
1542 static void igb_update_mng_vlan(struct igb_adapter *adapter)
1544 struct e1000_hw *hw = &adapter->hw;
1545 u16 pf_id = adapter->vfs_allocated_count;
1546 u16 vid = adapter->hw.mng_cookie.vlan_id;
1547 u16 old_vid = adapter->mng_vlan_id;
1549 if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
1550 /* add VID to filter table */
1551 igb_vfta_set(hw, vid, pf_id, true, true);
1552 adapter->mng_vlan_id = vid;
1554 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
1557 if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
1559 !test_bit(old_vid, adapter->active_vlans)) {
1560 /* remove VID from filter table */
1561 igb_vfta_set(hw, vid, pf_id, false, true);
1566 * igb_release_hw_control - release control of the h/w to f/w
1567 * @adapter: address of board private structure
1569 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
1570 * For ASF and Pass Through versions of f/w this means that the
1571 * driver is no longer loaded.
1573 static void igb_release_hw_control(struct igb_adapter *adapter)
1575 struct e1000_hw *hw = &adapter->hw;
1578 /* Let firmware take over control of h/w */
1579 ctrl_ext = rd32(E1000_CTRL_EXT);
1580 wr32(E1000_CTRL_EXT,
1581 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1585 * igb_get_hw_control - get control of the h/w from f/w
1586 * @adapter: address of board private structure
1588 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
1589 * For ASF and Pass Through versions of f/w this means that
1590 * the driver is loaded.
1592 static void igb_get_hw_control(struct igb_adapter *adapter)
1594 struct e1000_hw *hw = &adapter->hw;
1597 /* Let firmware know the driver has taken over */
1598 ctrl_ext = rd32(E1000_CTRL_EXT);
1599 wr32(E1000_CTRL_EXT,
1600 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1603 static void enable_fqtss(struct igb_adapter *adapter, bool enable)
1605 struct net_device *netdev = adapter->netdev;
1606 struct e1000_hw *hw = &adapter->hw;
1608 WARN_ON(hw->mac.type != e1000_i210);
1611 adapter->flags |= IGB_FLAG_FQTSS;
1613 adapter->flags &= ~IGB_FLAG_FQTSS;
1615 if (netif_running(netdev))
1616 schedule_work(&adapter->reset_task);
1619 static bool is_fqtss_enabled(struct igb_adapter *adapter)
1621 return (adapter->flags & IGB_FLAG_FQTSS) ? true : false;
1624 static void set_tx_desc_fetch_prio(struct e1000_hw *hw, int queue,
1625 enum tx_queue_prio prio)
1629 WARN_ON(hw->mac.type != e1000_i210);
1630 WARN_ON(queue < 0 || queue > 4);
1632 val = rd32(E1000_I210_TXDCTL(queue));
1634 if (prio == TX_QUEUE_PRIO_HIGH)
1635 val |= E1000_TXDCTL_PRIORITY;
1637 val &= ~E1000_TXDCTL_PRIORITY;
1639 wr32(E1000_I210_TXDCTL(queue), val);
1642 static void set_queue_mode(struct e1000_hw *hw, int queue, enum queue_mode mode)
1646 WARN_ON(hw->mac.type != e1000_i210);
1647 WARN_ON(queue < 0 || queue > 1);
1649 val = rd32(E1000_I210_TQAVCC(queue));
1651 if (mode == QUEUE_MODE_STREAM_RESERVATION)
1652 val |= E1000_TQAVCC_QUEUEMODE;
1654 val &= ~E1000_TQAVCC_QUEUEMODE;
1656 wr32(E1000_I210_TQAVCC(queue), val);
1659 static bool is_any_cbs_enabled(struct igb_adapter *adapter)
1663 for (i = 0; i < adapter->num_tx_queues; i++) {
1664 if (adapter->tx_ring[i]->cbs_enable)
1671 static bool is_any_txtime_enabled(struct igb_adapter *adapter)
1675 for (i = 0; i < adapter->num_tx_queues; i++) {
1676 if (adapter->tx_ring[i]->launchtime_enable)
1684 * igb_config_tx_modes - Configure "Qav Tx mode" features on igb
1685 * @adapter: pointer to adapter struct
1686 * @queue: queue number
1688 * Configure CBS and Launchtime for a given hardware queue.
1689 * Parameters are retrieved from the correct Tx ring, so
1690 * igb_save_cbs_params() and igb_save_txtime_params() should be used
1691 * for setting those correctly prior to this function being called.
1693 static void igb_config_tx_modes(struct igb_adapter *adapter, int queue)
1695 struct net_device *netdev = adapter->netdev;
1696 struct e1000_hw *hw = &adapter->hw;
1697 struct igb_ring *ring;
1698 u32 tqavcc, tqavctrl;
1701 WARN_ON(hw->mac.type != e1000_i210);
1702 WARN_ON(queue < 0 || queue > 1);
1703 ring = adapter->tx_ring[queue];
1705 /* If any of the Qav features is enabled, configure queues as SR and
1706 * with HIGH PRIO. If none is, then configure them with LOW PRIO and
1709 if (ring->cbs_enable || ring->launchtime_enable) {
1710 set_tx_desc_fetch_prio(hw, queue, TX_QUEUE_PRIO_HIGH);
1711 set_queue_mode(hw, queue, QUEUE_MODE_STREAM_RESERVATION);
1713 set_tx_desc_fetch_prio(hw, queue, TX_QUEUE_PRIO_LOW);
1714 set_queue_mode(hw, queue, QUEUE_MODE_STRICT_PRIORITY);
1717 /* If CBS is enabled, set DataTranARB and config its parameters. */
1718 if (ring->cbs_enable || queue == 0) {
1719 /* i210 does not allow the queue 0 to be in the Strict
1720 * Priority mode while the Qav mode is enabled, so,
1721 * instead of disabling strict priority mode, we give
1722 * queue 0 the maximum of credits possible.
1724 * See section 8.12.19 of the i210 datasheet, "Note:
1725 * Queue0 QueueMode must be set to 1b when
1726 * TransmitMode is set to Qav."
1728 if (queue == 0 && !ring->cbs_enable) {
1729 /* max "linkspeed" idleslope in kbps */
1730 ring->idleslope = 1000000;
1731 ring->hicredit = ETH_FRAME_LEN;
1734 /* Always set data transfer arbitration to credit-based
1735 * shaper algorithm on TQAVCTRL if CBS is enabled for any of
1738 tqavctrl = rd32(E1000_I210_TQAVCTRL);
1739 tqavctrl |= E1000_TQAVCTRL_DATATRANARB;
1740 wr32(E1000_I210_TQAVCTRL, tqavctrl);
1742 /* According to i210 datasheet section 7.2.7.7, we should set
1743 * the 'idleSlope' field from TQAVCC register following the
1746 * For 100 Mbps link speed:
1748 * value = BW * 0x7735 * 0.2 (E1)
1750 * For 1000Mbps link speed:
1752 * value = BW * 0x7735 * 2 (E2)
1754 * E1 and E2 can be merged into one equation as shown below.
1755 * Note that 'link-speed' is in Mbps.
1757 * value = BW * 0x7735 * 2 * link-speed
1758 * -------------- (E3)
1761 * 'BW' is the percentage bandwidth out of full link speed
1762 * which can be found with the following equation. Note that
1763 * idleSlope here is the parameter from this function which
1767 * ----------------- (E4)
1770 * That said, we can come up with a generic equation to
1771 * calculate the value we should set it TQAVCC register by
1772 * replacing 'BW' in E3 by E4. The resulting equation is:
1774 * value = idleSlope * 0x7735 * 2 * link-speed
1775 * ----------------- -------------- (E5)
1776 * link-speed * 1000 1000
1778 * 'link-speed' is present in both sides of the fraction so
1779 * it is canceled out. The final equation is the following:
1781 * value = idleSlope * 61034
1782 * ----------------- (E6)
1785 * NOTE: For i210, given the above, we can see that idleslope
1786 * is represented in 16.38431 kbps units by the value at
1787 * the TQAVCC register (1Gbps / 61034), which reduces
1788 * the granularity for idleslope increments.
1789 * For instance, if you want to configure a 2576kbps
1790 * idleslope, the value to be written on the register
1791 * would have to be 157.23. If rounded down, you end
1792 * up with less bandwidth available than originally
1793 * required (~2572 kbps). If rounded up, you end up
1794 * with a higher bandwidth (~2589 kbps). Below the
1795 * approach we take is to always round up the
1796 * calculated value, so the resulting bandwidth might
1797 * be slightly higher for some configurations.
1799 value = DIV_ROUND_UP_ULL(ring->idleslope * 61034ULL, 1000000);
1801 tqavcc = rd32(E1000_I210_TQAVCC(queue));
1802 tqavcc &= ~E1000_TQAVCC_IDLESLOPE_MASK;
1804 wr32(E1000_I210_TQAVCC(queue), tqavcc);
1806 wr32(E1000_I210_TQAVHC(queue),
1807 0x80000000 + ring->hicredit * 0x7735);
1810 /* Set idleSlope to zero. */
1811 tqavcc = rd32(E1000_I210_TQAVCC(queue));
1812 tqavcc &= ~E1000_TQAVCC_IDLESLOPE_MASK;
1813 wr32(E1000_I210_TQAVCC(queue), tqavcc);
1815 /* Set hiCredit to zero. */
1816 wr32(E1000_I210_TQAVHC(queue), 0);
1818 /* If CBS is not enabled for any queues anymore, then return to
1819 * the default state of Data Transmission Arbitration on
1822 if (!is_any_cbs_enabled(adapter)) {
1823 tqavctrl = rd32(E1000_I210_TQAVCTRL);
1824 tqavctrl &= ~E1000_TQAVCTRL_DATATRANARB;
1825 wr32(E1000_I210_TQAVCTRL, tqavctrl);
1829 /* If LaunchTime is enabled, set DataTranTIM. */
1830 if (ring->launchtime_enable) {
1831 /* Always set DataTranTIM on TQAVCTRL if LaunchTime is enabled
1832 * for any of the SR queues, and configure fetchtime delta.
1834 * - LaunchTime will be enabled for all SR queues.
1835 * - A fixed offset can be added relative to the launch
1836 * time of all packets if configured at reg LAUNCH_OS0.
1837 * We are keeping it as 0 for now (default value).
1839 tqavctrl = rd32(E1000_I210_TQAVCTRL);
1840 tqavctrl |= E1000_TQAVCTRL_DATATRANTIM |
1841 E1000_TQAVCTRL_FETCHTIME_DELTA;
1842 wr32(E1000_I210_TQAVCTRL, tqavctrl);
1844 /* If Launchtime is not enabled for any SR queues anymore,
1845 * then clear DataTranTIM on TQAVCTRL and clear fetchtime delta,
1846 * effectively disabling Launchtime.
1848 if (!is_any_txtime_enabled(adapter)) {
1849 tqavctrl = rd32(E1000_I210_TQAVCTRL);
1850 tqavctrl &= ~E1000_TQAVCTRL_DATATRANTIM;
1851 tqavctrl &= ~E1000_TQAVCTRL_FETCHTIME_DELTA;
1852 wr32(E1000_I210_TQAVCTRL, tqavctrl);
1856 /* XXX: In i210 controller the sendSlope and loCredit parameters from
1857 * CBS are not configurable by software so we don't do any 'controller
1858 * configuration' in respect to these parameters.
1861 netdev_dbg(netdev, "Qav Tx mode: cbs %s, launchtime %s, queue %d \
1862 idleslope %d sendslope %d hiCredit %d \
1864 (ring->cbs_enable) ? "enabled" : "disabled",
1865 (ring->launchtime_enable) ? "enabled" : "disabled", queue,
1866 ring->idleslope, ring->sendslope, ring->hicredit,
1870 static int igb_save_txtime_params(struct igb_adapter *adapter, int queue,
1873 struct igb_ring *ring;
1875 if (queue < 0 || queue > adapter->num_tx_queues)
1878 ring = adapter->tx_ring[queue];
1879 ring->launchtime_enable = enable;
1884 static int igb_save_cbs_params(struct igb_adapter *adapter, int queue,
1885 bool enable, int idleslope, int sendslope,
1886 int hicredit, int locredit)
1888 struct igb_ring *ring;
1890 if (queue < 0 || queue > adapter->num_tx_queues)
1893 ring = adapter->tx_ring[queue];
1895 ring->cbs_enable = enable;
1896 ring->idleslope = idleslope;
1897 ring->sendslope = sendslope;
1898 ring->hicredit = hicredit;
1899 ring->locredit = locredit;
1905 * igb_setup_tx_mode - Switch to/from Qav Tx mode when applicable
1906 * @adapter: pointer to adapter struct
1908 * Configure TQAVCTRL register switching the controller's Tx mode
1909 * if FQTSS mode is enabled or disabled. Additionally, will issue
1910 * a call to igb_config_tx_modes() per queue so any previously saved
1911 * Tx parameters are applied.
1913 static void igb_setup_tx_mode(struct igb_adapter *adapter)
1915 struct net_device *netdev = adapter->netdev;
1916 struct e1000_hw *hw = &adapter->hw;
1919 /* Only i210 controller supports changing the transmission mode. */
1920 if (hw->mac.type != e1000_i210)
1923 if (is_fqtss_enabled(adapter)) {
1926 /* Configure TQAVCTRL register: set transmit mode to 'Qav',
1927 * set data fetch arbitration to 'round robin', set SP_WAIT_SR
1928 * so SP queues wait for SR ones.
1930 val = rd32(E1000_I210_TQAVCTRL);
1931 val |= E1000_TQAVCTRL_XMIT_MODE | E1000_TQAVCTRL_SP_WAIT_SR;
1932 val &= ~E1000_TQAVCTRL_DATAFETCHARB;
1933 wr32(E1000_I210_TQAVCTRL, val);
1935 /* Configure Tx and Rx packet buffers sizes as described in
1936 * i210 datasheet section 7.2.7.7.
1938 val = rd32(E1000_TXPBS);
1939 val &= ~I210_TXPBSIZE_MASK;
1940 val |= I210_TXPBSIZE_PB0_8KB | I210_TXPBSIZE_PB1_8KB |
1941 I210_TXPBSIZE_PB2_4KB | I210_TXPBSIZE_PB3_4KB;
1942 wr32(E1000_TXPBS, val);
1944 val = rd32(E1000_RXPBS);
1945 val &= ~I210_RXPBSIZE_MASK;
1946 val |= I210_RXPBSIZE_PB_32KB;
1947 wr32(E1000_RXPBS, val);
1949 /* Section 8.12.9 states that MAX_TPKT_SIZE from DTXMXPKTSZ
1950 * register should not exceed the buffer size programmed in
1951 * TXPBS. The smallest buffer size programmed in TXPBS is 4kB
1952 * so according to the datasheet we should set MAX_TPKT_SIZE to
1955 * However, when we do so, no frame from queue 2 and 3 are
1956 * transmitted. It seems the MAX_TPKT_SIZE should not be great
1957 * or _equal_ to the buffer size programmed in TXPBS. For this
1958 * reason, we set set MAX_ TPKT_SIZE to (4kB - 1) / 64.
1960 val = (4096 - 1) / 64;
1961 wr32(E1000_I210_DTXMXPKTSZ, val);
1963 /* Since FQTSS mode is enabled, apply any CBS configuration
1964 * previously set. If no previous CBS configuration has been
1965 * done, then the initial configuration is applied, which means
1968 max_queue = (adapter->num_tx_queues < I210_SR_QUEUES_NUM) ?
1969 adapter->num_tx_queues : I210_SR_QUEUES_NUM;
1971 for (i = 0; i < max_queue; i++) {
1972 igb_config_tx_modes(adapter, i);
1975 wr32(E1000_RXPBS, I210_RXPBSIZE_DEFAULT);
1976 wr32(E1000_TXPBS, I210_TXPBSIZE_DEFAULT);
1977 wr32(E1000_I210_DTXMXPKTSZ, I210_DTXMXPKTSZ_DEFAULT);
1979 val = rd32(E1000_I210_TQAVCTRL);
1980 /* According to Section 8.12.21, the other flags we've set when
1981 * enabling FQTSS are not relevant when disabling FQTSS so we
1982 * don't set they here.
1984 val &= ~E1000_TQAVCTRL_XMIT_MODE;
1985 wr32(E1000_I210_TQAVCTRL, val);
1988 netdev_dbg(netdev, "FQTSS %s\n", (is_fqtss_enabled(adapter)) ?
1989 "enabled" : "disabled");
1993 * igb_configure - configure the hardware for RX and TX
1994 * @adapter: private board structure
1996 static void igb_configure(struct igb_adapter *adapter)
1998 struct net_device *netdev = adapter->netdev;
2001 igb_get_hw_control(adapter);
2002 igb_set_rx_mode(netdev);
2003 igb_setup_tx_mode(adapter);
2005 igb_restore_vlan(adapter);
2007 igb_setup_tctl(adapter);
2008 igb_setup_mrqc(adapter);
2009 igb_setup_rctl(adapter);
2011 igb_nfc_filter_restore(adapter);
2012 igb_configure_tx(adapter);
2013 igb_configure_rx(adapter);
2015 igb_rx_fifo_flush_82575(&adapter->hw);
2017 /* call igb_desc_unused which always leaves
2018 * at least 1 descriptor unused to make sure
2019 * next_to_use != next_to_clean
2021 for (i = 0; i < adapter->num_rx_queues; i++) {
2022 struct igb_ring *ring = adapter->rx_ring[i];
2023 igb_alloc_rx_buffers(ring, igb_desc_unused(ring));
2028 * igb_power_up_link - Power up the phy/serdes link
2029 * @adapter: address of board private structure
2031 void igb_power_up_link(struct igb_adapter *adapter)
2033 igb_reset_phy(&adapter->hw);
2035 if (adapter->hw.phy.media_type == e1000_media_type_copper)
2036 igb_power_up_phy_copper(&adapter->hw);
2038 igb_power_up_serdes_link_82575(&adapter->hw);
2040 igb_setup_link(&adapter->hw);
2044 * igb_power_down_link - Power down the phy/serdes link
2045 * @adapter: address of board private structure
2047 static void igb_power_down_link(struct igb_adapter *adapter)
2049 if (adapter->hw.phy.media_type == e1000_media_type_copper)
2050 igb_power_down_phy_copper_82575(&adapter->hw);
2052 igb_shutdown_serdes_link_82575(&adapter->hw);
2056 * Detect and switch function for Media Auto Sense
2057 * @adapter: address of the board private structure
2059 static void igb_check_swap_media(struct igb_adapter *adapter)
2061 struct e1000_hw *hw = &adapter->hw;
2062 u32 ctrl_ext, connsw;
2063 bool swap_now = false;
2065 ctrl_ext = rd32(E1000_CTRL_EXT);
2066 connsw = rd32(E1000_CONNSW);
2068 /* need to live swap if current media is copper and we have fiber/serdes
2072 if ((hw->phy.media_type == e1000_media_type_copper) &&
2073 (!(connsw & E1000_CONNSW_AUTOSENSE_EN))) {
2075 } else if ((hw->phy.media_type != e1000_media_type_copper) &&
2076 !(connsw & E1000_CONNSW_SERDESD)) {
2077 /* copper signal takes time to appear */
2078 if (adapter->copper_tries < 4) {
2079 adapter->copper_tries++;
2080 connsw |= E1000_CONNSW_AUTOSENSE_CONF;
2081 wr32(E1000_CONNSW, connsw);
2084 adapter->copper_tries = 0;
2085 if ((connsw & E1000_CONNSW_PHYSD) &&
2086 (!(connsw & E1000_CONNSW_PHY_PDN))) {
2088 connsw &= ~E1000_CONNSW_AUTOSENSE_CONF;
2089 wr32(E1000_CONNSW, connsw);
2097 switch (hw->phy.media_type) {
2098 case e1000_media_type_copper:
2099 netdev_info(adapter->netdev,
2100 "MAS: changing media to fiber/serdes\n");
2102 E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
2103 adapter->flags |= IGB_FLAG_MEDIA_RESET;
2104 adapter->copper_tries = 0;
2106 case e1000_media_type_internal_serdes:
2107 case e1000_media_type_fiber:
2108 netdev_info(adapter->netdev,
2109 "MAS: changing media to copper\n");
2111 ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
2112 adapter->flags |= IGB_FLAG_MEDIA_RESET;
2115 /* shouldn't get here during regular operation */
2116 netdev_err(adapter->netdev,
2117 "AMS: Invalid media type found, returning\n");
2120 wr32(E1000_CTRL_EXT, ctrl_ext);
2124 * igb_up - Open the interface and prepare it to handle traffic
2125 * @adapter: board private structure
2127 int igb_up(struct igb_adapter *adapter)
2129 struct e1000_hw *hw = &adapter->hw;
2132 /* hardware has been reset, we need to reload some things */
2133 igb_configure(adapter);
2135 clear_bit(__IGB_DOWN, &adapter->state);
2137 for (i = 0; i < adapter->num_q_vectors; i++)
2138 napi_enable(&(adapter->q_vector[i]->napi));
2140 if (adapter->flags & IGB_FLAG_HAS_MSIX)
2141 igb_configure_msix(adapter);
2143 igb_assign_vector(adapter->q_vector[0], 0);
2145 /* Clear any pending interrupts. */
2148 igb_irq_enable(adapter);
2150 /* notify VFs that reset has been completed */
2151 if (adapter->vfs_allocated_count) {
2152 u32 reg_data = rd32(E1000_CTRL_EXT);
2154 reg_data |= E1000_CTRL_EXT_PFRSTD;
2155 wr32(E1000_CTRL_EXT, reg_data);
2158 netif_tx_start_all_queues(adapter->netdev);
2160 /* start the watchdog. */
2161 hw->mac.get_link_status = 1;
2162 schedule_work(&adapter->watchdog_task);
2164 if ((adapter->flags & IGB_FLAG_EEE) &&
2165 (!hw->dev_spec._82575.eee_disable))
2166 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
2171 void igb_down(struct igb_adapter *adapter)
2173 struct net_device *netdev = adapter->netdev;
2174 struct e1000_hw *hw = &adapter->hw;
2178 /* signal that we're down so the interrupt handler does not
2179 * reschedule our watchdog timer
2181 set_bit(__IGB_DOWN, &adapter->state);
2183 /* disable receives in the hardware */
2184 rctl = rd32(E1000_RCTL);
2185 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
2186 /* flush and sleep below */
2188 igb_nfc_filter_exit(adapter);
2190 netif_carrier_off(netdev);
2191 netif_tx_stop_all_queues(netdev);
2193 /* disable transmits in the hardware */
2194 tctl = rd32(E1000_TCTL);
2195 tctl &= ~E1000_TCTL_EN;
2196 wr32(E1000_TCTL, tctl);
2197 /* flush both disables and wait for them to finish */
2199 usleep_range(10000, 11000);
2201 igb_irq_disable(adapter);
2203 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
2205 for (i = 0; i < adapter->num_q_vectors; i++) {
2206 if (adapter->q_vector[i]) {
2207 napi_synchronize(&adapter->q_vector[i]->napi);
2208 napi_disable(&adapter->q_vector[i]->napi);
2212 del_timer_sync(&adapter->watchdog_timer);
2213 del_timer_sync(&adapter->phy_info_timer);
2215 /* record the stats before reset*/
2216 spin_lock(&adapter->stats64_lock);
2217 igb_update_stats(adapter);
2218 spin_unlock(&adapter->stats64_lock);
2220 adapter->link_speed = 0;
2221 adapter->link_duplex = 0;
2223 if (!pci_channel_offline(adapter->pdev))
2226 /* clear VLAN promisc flag so VFTA will be updated if necessary */
2227 adapter->flags &= ~IGB_FLAG_VLAN_PROMISC;
2229 igb_clean_all_tx_rings(adapter);
2230 igb_clean_all_rx_rings(adapter);
2231 #ifdef CONFIG_IGB_DCA
2233 /* since we reset the hardware DCA settings were cleared */
2234 igb_setup_dca(adapter);
2238 void igb_reinit_locked(struct igb_adapter *adapter)
2240 WARN_ON(in_interrupt());
2241 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
2242 usleep_range(1000, 2000);
2245 clear_bit(__IGB_RESETTING, &adapter->state);
2248 /** igb_enable_mas - Media Autosense re-enable after swap
2250 * @adapter: adapter struct
2252 static void igb_enable_mas(struct igb_adapter *adapter)
2254 struct e1000_hw *hw = &adapter->hw;
2255 u32 connsw = rd32(E1000_CONNSW);
2257 /* configure for SerDes media detect */
2258 if ((hw->phy.media_type == e1000_media_type_copper) &&
2259 (!(connsw & E1000_CONNSW_SERDESD))) {
2260 connsw |= E1000_CONNSW_ENRGSRC;
2261 connsw |= E1000_CONNSW_AUTOSENSE_EN;
2262 wr32(E1000_CONNSW, connsw);
2267 void igb_reset(struct igb_adapter *adapter)
2269 struct pci_dev *pdev = adapter->pdev;
2270 struct e1000_hw *hw = &adapter->hw;
2271 struct e1000_mac_info *mac = &hw->mac;
2272 struct e1000_fc_info *fc = &hw->fc;
2275 /* Repartition Pba for greater than 9k mtu
2276 * To take effect CTRL.RST is required.
2278 switch (mac->type) {
2282 pba = rd32(E1000_RXPBS);
2283 pba = igb_rxpbs_adjust_82580(pba);
2286 pba = rd32(E1000_RXPBS);
2287 pba &= E1000_RXPBS_SIZE_MASK_82576;
2293 pba = E1000_PBA_34K;
2297 if (mac->type == e1000_82575) {
2298 u32 min_rx_space, min_tx_space, needed_tx_space;
2300 /* write Rx PBA so that hardware can report correct Tx PBA */
2301 wr32(E1000_PBA, pba);
2303 /* To maintain wire speed transmits, the Tx FIFO should be
2304 * large enough to accommodate two full transmit packets,
2305 * rounded up to the next 1KB and expressed in KB. Likewise,
2306 * the Rx FIFO should be large enough to accommodate at least
2307 * one full receive packet and is similarly rounded up and
2310 min_rx_space = DIV_ROUND_UP(MAX_JUMBO_FRAME_SIZE, 1024);
2312 /* The Tx FIFO also stores 16 bytes of information about the Tx
2313 * but don't include Ethernet FCS because hardware appends it.
2314 * We only need to round down to the nearest 512 byte block
2315 * count since the value we care about is 2 frames, not 1.
2317 min_tx_space = adapter->max_frame_size;
2318 min_tx_space += sizeof(union e1000_adv_tx_desc) - ETH_FCS_LEN;
2319 min_tx_space = DIV_ROUND_UP(min_tx_space, 512);
2321 /* upper 16 bits has Tx packet buffer allocation size in KB */
2322 needed_tx_space = min_tx_space - (rd32(E1000_PBA) >> 16);
2324 /* If current Tx allocation is less than the min Tx FIFO size,
2325 * and the min Tx FIFO size is less than the current Rx FIFO
2326 * allocation, take space away from current Rx allocation.
2328 if (needed_tx_space < pba) {
2329 pba -= needed_tx_space;
2331 /* if short on Rx space, Rx wins and must trump Tx
2334 if (pba < min_rx_space)
2338 /* adjust PBA for jumbo frames */
2339 wr32(E1000_PBA, pba);
2342 /* flow control settings
2343 * The high water mark must be low enough to fit one full frame
2344 * after transmitting the pause frame. As such we must have enough
2345 * space to allow for us to complete our current transmit and then
2346 * receive the frame that is in progress from the link partner.
2348 * - the full Rx FIFO size minus one full Tx plus one full Rx frame
2350 hwm = (pba << 10) - (adapter->max_frame_size + MAX_JUMBO_FRAME_SIZE);
2352 fc->high_water = hwm & 0xFFFFFFF0; /* 16-byte granularity */
2353 fc->low_water = fc->high_water - 16;
2354 fc->pause_time = 0xFFFF;
2356 fc->current_mode = fc->requested_mode;
2358 /* disable receive for all VFs and wait one second */
2359 if (adapter->vfs_allocated_count) {
2362 for (i = 0 ; i < adapter->vfs_allocated_count; i++)
2363 adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC;
2365 /* ping all the active vfs to let them know we are going down */
2366 igb_ping_all_vfs(adapter);
2368 /* disable transmits and receives */
2369 wr32(E1000_VFRE, 0);
2370 wr32(E1000_VFTE, 0);
2373 /* Allow time for pending master requests to run */
2374 hw->mac.ops.reset_hw(hw);
2377 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
2378 /* need to resetup here after media swap */
2379 adapter->ei.get_invariants(hw);
2380 adapter->flags &= ~IGB_FLAG_MEDIA_RESET;
2382 if ((mac->type == e1000_82575) &&
2383 (adapter->flags & IGB_FLAG_MAS_ENABLE)) {
2384 igb_enable_mas(adapter);
2386 if (hw->mac.ops.init_hw(hw))
2387 dev_err(&pdev->dev, "Hardware Error\n");
2389 /* RAR registers were cleared during init_hw, clear mac table */
2390 igb_flush_mac_table(adapter);
2391 __dev_uc_unsync(adapter->netdev, NULL);
2393 /* Recover default RAR entry */
2394 igb_set_default_mac_filter(adapter);
2396 /* Flow control settings reset on hardware reset, so guarantee flow
2397 * control is off when forcing speed.
2399 if (!hw->mac.autoneg)
2400 igb_force_mac_fc(hw);
2402 igb_init_dmac(adapter, pba);
2403 #ifdef CONFIG_IGB_HWMON
2404 /* Re-initialize the thermal sensor on i350 devices. */
2405 if (!test_bit(__IGB_DOWN, &adapter->state)) {
2406 if (mac->type == e1000_i350 && hw->bus.func == 0) {
2407 /* If present, re-initialize the external thermal sensor
2411 mac->ops.init_thermal_sensor_thresh(hw);
2415 /* Re-establish EEE setting */
2416 if (hw->phy.media_type == e1000_media_type_copper) {
2417 switch (mac->type) {
2421 igb_set_eee_i350(hw, true, true);
2424 igb_set_eee_i354(hw, true, true);
2430 if (!netif_running(adapter->netdev))
2431 igb_power_down_link(adapter);
2433 igb_update_mng_vlan(adapter);
2435 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2436 wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
2438 /* Re-enable PTP, where applicable. */
2439 if (adapter->ptp_flags & IGB_PTP_ENABLED)
2440 igb_ptp_reset(adapter);
2442 igb_get_phy_info(hw);
2445 static netdev_features_t igb_fix_features(struct net_device *netdev,
2446 netdev_features_t features)
2448 /* Since there is no support for separate Rx/Tx vlan accel
2449 * enable/disable make sure Tx flag is always in same state as Rx.
2451 if (features & NETIF_F_HW_VLAN_CTAG_RX)
2452 features |= NETIF_F_HW_VLAN_CTAG_TX;
2454 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
2459 static int igb_set_features(struct net_device *netdev,
2460 netdev_features_t features)
2462 netdev_features_t changed = netdev->features ^ features;
2463 struct igb_adapter *adapter = netdev_priv(netdev);
2465 if (changed & NETIF_F_HW_VLAN_CTAG_RX)
2466 igb_vlan_mode(netdev, features);
2468 if (!(changed & (NETIF_F_RXALL | NETIF_F_NTUPLE)))
2471 if (!(features & NETIF_F_NTUPLE)) {
2472 struct hlist_node *node2;
2473 struct igb_nfc_filter *rule;
2475 spin_lock(&adapter->nfc_lock);
2476 hlist_for_each_entry_safe(rule, node2,
2477 &adapter->nfc_filter_list, nfc_node) {
2478 igb_erase_filter(adapter, rule);
2479 hlist_del(&rule->nfc_node);
2482 spin_unlock(&adapter->nfc_lock);
2483 adapter->nfc_filter_count = 0;
2486 netdev->features = features;
2488 if (netif_running(netdev))
2489 igb_reinit_locked(adapter);
2496 static int igb_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
2497 struct net_device *dev,
2498 const unsigned char *addr, u16 vid,
2501 /* guarantee we can provide a unique filter for the unicast address */
2502 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
2503 struct igb_adapter *adapter = netdev_priv(dev);
2504 int vfn = adapter->vfs_allocated_count;
2506 if (netdev_uc_count(dev) >= igb_available_rars(adapter, vfn))
2510 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
2513 #define IGB_MAX_MAC_HDR_LEN 127
2514 #define IGB_MAX_NETWORK_HDR_LEN 511
2516 static netdev_features_t
2517 igb_features_check(struct sk_buff *skb, struct net_device *dev,
2518 netdev_features_t features)
2520 unsigned int network_hdr_len, mac_hdr_len;
2522 /* Make certain the headers can be described by a context descriptor */
2523 mac_hdr_len = skb_network_header(skb) - skb->data;
2524 if (unlikely(mac_hdr_len > IGB_MAX_MAC_HDR_LEN))
2525 return features & ~(NETIF_F_HW_CSUM |
2527 NETIF_F_HW_VLAN_CTAG_TX |
2531 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
2532 if (unlikely(network_hdr_len > IGB_MAX_NETWORK_HDR_LEN))
2533 return features & ~(NETIF_F_HW_CSUM |
2538 /* We can only support IPV4 TSO in tunnels if we can mangle the
2539 * inner IP ID field, so strip TSO if MANGLEID is not supported.
2541 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
2542 features &= ~NETIF_F_TSO;
2547 static void igb_offload_apply(struct igb_adapter *adapter, s32 queue)
2549 if (!is_fqtss_enabled(adapter)) {
2550 enable_fqtss(adapter, true);
2554 igb_config_tx_modes(adapter, queue);
2556 if (!is_any_cbs_enabled(adapter) && !is_any_txtime_enabled(adapter))
2557 enable_fqtss(adapter, false);
2560 static int igb_offload_cbs(struct igb_adapter *adapter,
2561 struct tc_cbs_qopt_offload *qopt)
2563 struct e1000_hw *hw = &adapter->hw;
2566 /* CBS offloading is only supported by i210 controller. */
2567 if (hw->mac.type != e1000_i210)
2570 /* CBS offloading is only supported by queue 0 and queue 1. */
2571 if (qopt->queue < 0 || qopt->queue > 1)
2574 err = igb_save_cbs_params(adapter, qopt->queue, qopt->enable,
2575 qopt->idleslope, qopt->sendslope,
2576 qopt->hicredit, qopt->locredit);
2580 igb_offload_apply(adapter, qopt->queue);
2585 #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
2586 #define VLAN_PRIO_FULL_MASK (0x07)
2588 static int igb_parse_cls_flower(struct igb_adapter *adapter,
2589 struct tc_cls_flower_offload *f,
2591 struct igb_nfc_filter *input)
2593 struct netlink_ext_ack *extack = f->common.extack;
2595 if (f->dissector->used_keys &
2596 ~(BIT(FLOW_DISSECTOR_KEY_BASIC) |
2597 BIT(FLOW_DISSECTOR_KEY_CONTROL) |
2598 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
2599 BIT(FLOW_DISSECTOR_KEY_VLAN))) {
2600 NL_SET_ERR_MSG_MOD(extack,
2601 "Unsupported key used, only BASIC, CONTROL, ETH_ADDRS and VLAN are supported");
2605 if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
2606 struct flow_dissector_key_eth_addrs *key, *mask;
2608 key = skb_flow_dissector_target(f->dissector,
2609 FLOW_DISSECTOR_KEY_ETH_ADDRS,
2611 mask = skb_flow_dissector_target(f->dissector,
2612 FLOW_DISSECTOR_KEY_ETH_ADDRS,
2615 if (!is_zero_ether_addr(mask->dst)) {
2616 if (!is_broadcast_ether_addr(mask->dst)) {
2617 NL_SET_ERR_MSG_MOD(extack, "Only full masks are supported for destination MAC address");
2621 input->filter.match_flags |=
2622 IGB_FILTER_FLAG_DST_MAC_ADDR;
2623 ether_addr_copy(input->filter.dst_addr, key->dst);
2626 if (!is_zero_ether_addr(mask->src)) {
2627 if (!is_broadcast_ether_addr(mask->src)) {
2628 NL_SET_ERR_MSG_MOD(extack, "Only full masks are supported for source MAC address");
2632 input->filter.match_flags |=
2633 IGB_FILTER_FLAG_SRC_MAC_ADDR;
2634 ether_addr_copy(input->filter.src_addr, key->src);
2638 if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_BASIC)) {
2639 struct flow_dissector_key_basic *key, *mask;
2641 key = skb_flow_dissector_target(f->dissector,
2642 FLOW_DISSECTOR_KEY_BASIC,
2644 mask = skb_flow_dissector_target(f->dissector,
2645 FLOW_DISSECTOR_KEY_BASIC,
2648 if (mask->n_proto) {
2649 if (mask->n_proto != ETHER_TYPE_FULL_MASK) {
2650 NL_SET_ERR_MSG_MOD(extack, "Only full mask is supported for EtherType filter");
2654 input->filter.match_flags |= IGB_FILTER_FLAG_ETHER_TYPE;
2655 input->filter.etype = key->n_proto;
2659 if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
2660 struct flow_dissector_key_vlan *key, *mask;
2662 key = skb_flow_dissector_target(f->dissector,
2663 FLOW_DISSECTOR_KEY_VLAN,
2665 mask = skb_flow_dissector_target(f->dissector,
2666 FLOW_DISSECTOR_KEY_VLAN,
2669 if (mask->vlan_priority) {
2670 if (mask->vlan_priority != VLAN_PRIO_FULL_MASK) {
2671 NL_SET_ERR_MSG_MOD(extack, "Only full mask is supported for VLAN priority");
2675 input->filter.match_flags |= IGB_FILTER_FLAG_VLAN_TCI;
2676 input->filter.vlan_tci = key->vlan_priority;
2680 input->action = traffic_class;
2681 input->cookie = f->cookie;
2686 static int igb_configure_clsflower(struct igb_adapter *adapter,
2687 struct tc_cls_flower_offload *cls_flower)
2689 struct netlink_ext_ack *extack = cls_flower->common.extack;
2690 struct igb_nfc_filter *filter, *f;
2693 tc = tc_classid_to_hwtc(adapter->netdev, cls_flower->classid);
2695 NL_SET_ERR_MSG_MOD(extack, "Invalid traffic class");
2699 filter = kzalloc(sizeof(*filter), GFP_KERNEL);
2703 err = igb_parse_cls_flower(adapter, cls_flower, tc, filter);
2707 spin_lock(&adapter->nfc_lock);
2709 hlist_for_each_entry(f, &adapter->nfc_filter_list, nfc_node) {
2710 if (!memcmp(&f->filter, &filter->filter, sizeof(f->filter))) {
2712 NL_SET_ERR_MSG_MOD(extack,
2713 "This filter is already set in ethtool");
2718 hlist_for_each_entry(f, &adapter->cls_flower_list, nfc_node) {
2719 if (!memcmp(&f->filter, &filter->filter, sizeof(f->filter))) {
2721 NL_SET_ERR_MSG_MOD(extack,
2722 "This filter is already set in cls_flower");
2727 err = igb_add_filter(adapter, filter);
2729 NL_SET_ERR_MSG_MOD(extack, "Could not add filter to the adapter");
2733 hlist_add_head(&filter->nfc_node, &adapter->cls_flower_list);
2735 spin_unlock(&adapter->nfc_lock);
2740 spin_unlock(&adapter->nfc_lock);
2748 static int igb_delete_clsflower(struct igb_adapter *adapter,
2749 struct tc_cls_flower_offload *cls_flower)
2751 struct igb_nfc_filter *filter;
2754 spin_lock(&adapter->nfc_lock);
2756 hlist_for_each_entry(filter, &adapter->cls_flower_list, nfc_node)
2757 if (filter->cookie == cls_flower->cookie)
2765 err = igb_erase_filter(adapter, filter);
2769 hlist_del(&filter->nfc_node);
2773 spin_unlock(&adapter->nfc_lock);
2778 static int igb_setup_tc_cls_flower(struct igb_adapter *adapter,
2779 struct tc_cls_flower_offload *cls_flower)
2781 switch (cls_flower->command) {
2782 case TC_CLSFLOWER_REPLACE:
2783 return igb_configure_clsflower(adapter, cls_flower);
2784 case TC_CLSFLOWER_DESTROY:
2785 return igb_delete_clsflower(adapter, cls_flower);
2786 case TC_CLSFLOWER_STATS:
2793 static int igb_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
2796 struct igb_adapter *adapter = cb_priv;
2798 if (!tc_cls_can_offload_and_chain0(adapter->netdev, type_data))
2802 case TC_SETUP_CLSFLOWER:
2803 return igb_setup_tc_cls_flower(adapter, type_data);
2810 static int igb_setup_tc_block(struct igb_adapter *adapter,
2811 struct tc_block_offload *f)
2813 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
2816 switch (f->command) {
2818 return tcf_block_cb_register(f->block, igb_setup_tc_block_cb,
2819 adapter, adapter, f->extack);
2820 case TC_BLOCK_UNBIND:
2821 tcf_block_cb_unregister(f->block, igb_setup_tc_block_cb,
2829 static int igb_offload_txtime(struct igb_adapter *adapter,
2830 struct tc_etf_qopt_offload *qopt)
2832 struct e1000_hw *hw = &adapter->hw;
2835 /* Launchtime offloading is only supported by i210 controller. */
2836 if (hw->mac.type != e1000_i210)
2839 /* Launchtime offloading is only supported by queues 0 and 1. */
2840 if (qopt->queue < 0 || qopt->queue > 1)
2843 err = igb_save_txtime_params(adapter, qopt->queue, qopt->enable);
2847 igb_offload_apply(adapter, qopt->queue);
2852 static int igb_setup_tc(struct net_device *dev, enum tc_setup_type type,
2855 struct igb_adapter *adapter = netdev_priv(dev);
2858 case TC_SETUP_QDISC_CBS:
2859 return igb_offload_cbs(adapter, type_data);
2860 case TC_SETUP_BLOCK:
2861 return igb_setup_tc_block(adapter, type_data);
2862 case TC_SETUP_QDISC_ETF:
2863 return igb_offload_txtime(adapter, type_data);
2870 static const struct net_device_ops igb_netdev_ops = {
2871 .ndo_open = igb_open,
2872 .ndo_stop = igb_close,
2873 .ndo_start_xmit = igb_xmit_frame,
2874 .ndo_get_stats64 = igb_get_stats64,
2875 .ndo_set_rx_mode = igb_set_rx_mode,
2876 .ndo_set_mac_address = igb_set_mac,
2877 .ndo_change_mtu = igb_change_mtu,
2878 .ndo_do_ioctl = igb_ioctl,
2879 .ndo_tx_timeout = igb_tx_timeout,
2880 .ndo_validate_addr = eth_validate_addr,
2881 .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
2882 .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
2883 .ndo_set_vf_mac = igb_ndo_set_vf_mac,
2884 .ndo_set_vf_vlan = igb_ndo_set_vf_vlan,
2885 .ndo_set_vf_rate = igb_ndo_set_vf_bw,
2886 .ndo_set_vf_spoofchk = igb_ndo_set_vf_spoofchk,
2887 .ndo_set_vf_trust = igb_ndo_set_vf_trust,
2888 .ndo_get_vf_config = igb_ndo_get_vf_config,
2889 .ndo_fix_features = igb_fix_features,
2890 .ndo_set_features = igb_set_features,
2891 .ndo_fdb_add = igb_ndo_fdb_add,
2892 .ndo_features_check = igb_features_check,
2893 .ndo_setup_tc = igb_setup_tc,
2897 * igb_set_fw_version - Configure version string for ethtool
2898 * @adapter: adapter struct
2900 void igb_set_fw_version(struct igb_adapter *adapter)
2902 struct e1000_hw *hw = &adapter->hw;
2903 struct e1000_fw_version fw;
2905 igb_get_fw_version(hw, &fw);
2907 switch (hw->mac.type) {
2910 if (!(igb_get_flash_presence_i210(hw))) {
2911 snprintf(adapter->fw_version,
2912 sizeof(adapter->fw_version),
2914 fw.invm_major, fw.invm_minor,
2920 /* if option is rom valid, display its version too */
2922 snprintf(adapter->fw_version,
2923 sizeof(adapter->fw_version),
2924 "%d.%d, 0x%08x, %d.%d.%d",
2925 fw.eep_major, fw.eep_minor, fw.etrack_id,
2926 fw.or_major, fw.or_build, fw.or_patch);
2928 } else if (fw.etrack_id != 0X0000) {
2929 snprintf(adapter->fw_version,
2930 sizeof(adapter->fw_version),
2932 fw.eep_major, fw.eep_minor, fw.etrack_id);
2934 snprintf(adapter->fw_version,
2935 sizeof(adapter->fw_version),
2937 fw.eep_major, fw.eep_minor, fw.eep_build);
2944 * igb_init_mas - init Media Autosense feature if enabled in the NVM
2946 * @adapter: adapter struct
2948 static void igb_init_mas(struct igb_adapter *adapter)
2950 struct e1000_hw *hw = &adapter->hw;
2953 hw->nvm.ops.read(hw, NVM_COMPAT, 1, &eeprom_data);
2954 switch (hw->bus.func) {
2956 if (eeprom_data & IGB_MAS_ENABLE_0) {
2957 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2958 netdev_info(adapter->netdev,
2959 "MAS: Enabling Media Autosense for port %d\n",
2964 if (eeprom_data & IGB_MAS_ENABLE_1) {
2965 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2966 netdev_info(adapter->netdev,
2967 "MAS: Enabling Media Autosense for port %d\n",
2972 if (eeprom_data & IGB_MAS_ENABLE_2) {
2973 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2974 netdev_info(adapter->netdev,
2975 "MAS: Enabling Media Autosense for port %d\n",
2980 if (eeprom_data & IGB_MAS_ENABLE_3) {
2981 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2982 netdev_info(adapter->netdev,
2983 "MAS: Enabling Media Autosense for port %d\n",
2988 /* Shouldn't get here */
2989 netdev_err(adapter->netdev,
2990 "MAS: Invalid port configuration, returning\n");
2996 * igb_init_i2c - Init I2C interface
2997 * @adapter: pointer to adapter structure
2999 static s32 igb_init_i2c(struct igb_adapter *adapter)
3003 /* I2C interface supported on i350 devices */
3004 if (adapter->hw.mac.type != e1000_i350)
3007 /* Initialize the i2c bus which is controlled by the registers.
3008 * This bus will use the i2c_algo_bit structue that implements
3009 * the protocol through toggling of the 4 bits in the register.
3011 adapter->i2c_adap.owner = THIS_MODULE;
3012 adapter->i2c_algo = igb_i2c_algo;
3013 adapter->i2c_algo.data = adapter;
3014 adapter->i2c_adap.algo_data = &adapter->i2c_algo;
3015 adapter->i2c_adap.dev.parent = &adapter->pdev->dev;
3016 strlcpy(adapter->i2c_adap.name, "igb BB",
3017 sizeof(adapter->i2c_adap.name));
3018 status = i2c_bit_add_bus(&adapter->i2c_adap);
3023 * igb_probe - Device Initialization Routine
3024 * @pdev: PCI device information struct
3025 * @ent: entry in igb_pci_tbl
3027 * Returns 0 on success, negative on failure
3029 * igb_probe initializes an adapter identified by a pci_dev structure.
3030 * The OS initialization, configuring of the adapter private structure,
3031 * and a hardware reset occur.
3033 static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3035 struct net_device *netdev;
3036 struct igb_adapter *adapter;
3037 struct e1000_hw *hw;
3038 u16 eeprom_data = 0;
3040 static int global_quad_port_a; /* global quad port a indication */
3041 const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
3042 int err, pci_using_dac;
3043 u8 part_str[E1000_PBANUM_LENGTH];
3045 /* Catch broken hardware that put the wrong VF device ID in
3046 * the PCIe SR-IOV capability.
3048 if (pdev->is_virtfn) {
3049 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
3050 pci_name(pdev), pdev->vendor, pdev->device);
3054 err = pci_enable_device_mem(pdev);
3059 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
3063 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
3066 "No usable DMA configuration, aborting\n");
3071 err = pci_request_mem_regions(pdev, igb_driver_name);
3075 pci_enable_pcie_error_reporting(pdev);
3077 pci_set_master(pdev);
3078 pci_save_state(pdev);
3081 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
3084 goto err_alloc_etherdev;
3086 SET_NETDEV_DEV(netdev, &pdev->dev);
3088 pci_set_drvdata(pdev, netdev);
3089 adapter = netdev_priv(netdev);
3090 adapter->netdev = netdev;
3091 adapter->pdev = pdev;
3094 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
3097 adapter->io_addr = pci_iomap(pdev, 0, 0);
3098 if (!adapter->io_addr)
3100 /* hw->hw_addr can be altered, we'll use adapter->io_addr for unmap */
3101 hw->hw_addr = adapter->io_addr;
3103 netdev->netdev_ops = &igb_netdev_ops;
3104 igb_set_ethtool_ops(netdev);
3105 netdev->watchdog_timeo = 5 * HZ;
3107 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
3109 netdev->mem_start = pci_resource_start(pdev, 0);
3110 netdev->mem_end = pci_resource_end(pdev, 0);
3112 /* PCI config space info */
3113 hw->vendor_id = pdev->vendor;
3114 hw->device_id = pdev->device;
3115 hw->revision_id = pdev->revision;
3116 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3117 hw->subsystem_device_id = pdev->subsystem_device;
3119 /* Copy the default MAC, PHY and NVM function pointers */
3120 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
3121 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
3122 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
3123 /* Initialize skew-specific constants */
3124 err = ei->get_invariants(hw);
3128 /* setup the private structure */
3129 err = igb_sw_init(adapter);
3133 igb_get_bus_info_pcie(hw);
3135 hw->phy.autoneg_wait_to_complete = false;
3137 /* Copper options */
3138 if (hw->phy.media_type == e1000_media_type_copper) {
3139 hw->phy.mdix = AUTO_ALL_MODES;
3140 hw->phy.disable_polarity_correction = false;
3141 hw->phy.ms_type = e1000_ms_hw_default;
3144 if (igb_check_reset_block(hw))
3145 dev_info(&pdev->dev,
3146 "PHY reset is blocked due to SOL/IDER session.\n");
3148 /* features is initialized to 0 in allocation, it might have bits
3149 * set by igb_sw_init so we should use an or instead of an
3152 netdev->features |= NETIF_F_SG |
3159 if (hw->mac.type >= e1000_82576)
3160 netdev->features |= NETIF_F_SCTP_CRC;
3162 if (hw->mac.type >= e1000_i350)
3163 netdev->features |= NETIF_F_HW_TC;
3165 #define IGB_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
3166 NETIF_F_GSO_GRE_CSUM | \
3167 NETIF_F_GSO_IPXIP4 | \
3168 NETIF_F_GSO_IPXIP6 | \
3169 NETIF_F_GSO_UDP_TUNNEL | \
3170 NETIF_F_GSO_UDP_TUNNEL_CSUM)
3172 netdev->gso_partial_features = IGB_GSO_PARTIAL_FEATURES;
3173 netdev->features |= NETIF_F_GSO_PARTIAL | IGB_GSO_PARTIAL_FEATURES;
3175 /* copy netdev features into list of user selectable features */
3176 netdev->hw_features |= netdev->features |
3177 NETIF_F_HW_VLAN_CTAG_RX |
3178 NETIF_F_HW_VLAN_CTAG_TX |
3181 if (hw->mac.type >= e1000_i350)
3182 netdev->hw_features |= NETIF_F_NTUPLE;
3185 netdev->features |= NETIF_F_HIGHDMA;
3187 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
3188 netdev->mpls_features |= NETIF_F_HW_CSUM;
3189 netdev->hw_enc_features |= netdev->vlan_features;
3191 /* set this bit last since it cannot be part of vlan_features */
3192 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
3193 NETIF_F_HW_VLAN_CTAG_RX |
3194 NETIF_F_HW_VLAN_CTAG_TX;
3196 netdev->priv_flags |= IFF_SUPP_NOFCS;
3198 netdev->priv_flags |= IFF_UNICAST_FLT;
3200 /* MTU range: 68 - 9216 */
3201 netdev->min_mtu = ETH_MIN_MTU;
3202 netdev->max_mtu = MAX_STD_JUMBO_FRAME_SIZE;
3204 adapter->en_mng_pt = igb_enable_mng_pass_thru(hw);
3206 /* before reading the NVM, reset the controller to put the device in a
3207 * known good starting state
3209 hw->mac.ops.reset_hw(hw);
3211 /* make sure the NVM is good , i211/i210 parts can have special NVM
3212 * that doesn't contain a checksum
3214 switch (hw->mac.type) {
3217 if (igb_get_flash_presence_i210(hw)) {
3218 if (hw->nvm.ops.validate(hw) < 0) {
3220 "The NVM Checksum Is Not Valid\n");
3227 if (hw->nvm.ops.validate(hw) < 0) {
3228 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
3235 if (eth_platform_get_mac_address(&pdev->dev, hw->mac.addr)) {
3236 /* copy the MAC address out of the NVM */
3237 if (hw->mac.ops.read_mac_addr(hw))
3238 dev_err(&pdev->dev, "NVM Read Error\n");
3241 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
3243 if (!is_valid_ether_addr(netdev->dev_addr)) {
3244 dev_err(&pdev->dev, "Invalid MAC Address\n");
3249 igb_set_default_mac_filter(adapter);
3251 /* get firmware version for ethtool -i */
3252 igb_set_fw_version(adapter);
3254 /* configure RXPBSIZE and TXPBSIZE */
3255 if (hw->mac.type == e1000_i210) {
3256 wr32(E1000_RXPBS, I210_RXPBSIZE_DEFAULT);
3257 wr32(E1000_TXPBS, I210_TXPBSIZE_DEFAULT);
3260 timer_setup(&adapter->watchdog_timer, igb_watchdog, 0);
3261 timer_setup(&adapter->phy_info_timer, igb_update_phy_info, 0);
3263 INIT_WORK(&adapter->reset_task, igb_reset_task);
3264 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
3266 /* Initialize link properties that are user-changeable */
3267 adapter->fc_autoneg = true;
3268 hw->mac.autoneg = true;
3269 hw->phy.autoneg_advertised = 0x2f;
3271 hw->fc.requested_mode = e1000_fc_default;
3272 hw->fc.current_mode = e1000_fc_default;
3274 igb_validate_mdi_setting(hw);
3276 /* By default, support wake on port A */
3277 if (hw->bus.func == 0)
3278 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
3280 /* Check the NVM for wake support on non-port A ports */
3281 if (hw->mac.type >= e1000_82580)
3282 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
3283 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
3285 else if (hw->bus.func == 1)
3286 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
3288 if (eeprom_data & IGB_EEPROM_APME)
3289 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
3291 /* now that we have the eeprom settings, apply the special cases where
3292 * the eeprom may be wrong or the board simply won't support wake on
3293 * lan on a particular port
3295 switch (pdev->device) {
3296 case E1000_DEV_ID_82575GB_QUAD_COPPER:
3297 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
3299 case E1000_DEV_ID_82575EB_FIBER_SERDES:
3300 case E1000_DEV_ID_82576_FIBER:
3301 case E1000_DEV_ID_82576_SERDES:
3302 /* Wake events only supported on port A for dual fiber
3303 * regardless of eeprom setting
3305 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
3306 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
3308 case E1000_DEV_ID_82576_QUAD_COPPER:
3309 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
3310 /* if quad port adapter, disable WoL on all but port A */
3311 if (global_quad_port_a != 0)
3312 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
3314 adapter->flags |= IGB_FLAG_QUAD_PORT_A;
3315 /* Reset for multiple quad port adapters */
3316 if (++global_quad_port_a == 4)
3317 global_quad_port_a = 0;
3320 /* If the device can't wake, don't set software support */
3321 if (!device_can_wakeup(&adapter->pdev->dev))
3322 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
3325 /* initialize the wol settings based on the eeprom settings */
3326 if (adapter->flags & IGB_FLAG_WOL_SUPPORTED)
3327 adapter->wol |= E1000_WUFC_MAG;
3329 /* Some vendors want WoL disabled by default, but still supported */
3330 if ((hw->mac.type == e1000_i350) &&
3331 (pdev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
3332 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
3336 /* Some vendors want the ability to Use the EEPROM setting as
3337 * enable/disable only, and not for capability
3339 if (((hw->mac.type == e1000_i350) ||
3340 (hw->mac.type == e1000_i354)) &&
3341 (pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)) {
3342 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
3345 if (hw->mac.type == e1000_i350) {
3346 if (((pdev->subsystem_device == 0x5001) ||
3347 (pdev->subsystem_device == 0x5002)) &&
3348 (hw->bus.func == 0)) {
3349 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
3352 if (pdev->subsystem_device == 0x1F52)
3353 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
3356 device_set_wakeup_enable(&adapter->pdev->dev,
3357 adapter->flags & IGB_FLAG_WOL_SUPPORTED);
3359 /* reset the hardware with the new settings */
3362 /* Init the I2C interface */
3363 err = igb_init_i2c(adapter);
3365 dev_err(&pdev->dev, "failed to init i2c interface\n");
3369 /* let the f/w know that the h/w is now under the control of the
3372 igb_get_hw_control(adapter);
3374 strcpy(netdev->name, "eth%d");
3375 err = register_netdev(netdev);
3379 /* carrier off reporting is important to ethtool even BEFORE open */
3380 netif_carrier_off(netdev);
3382 #ifdef CONFIG_IGB_DCA
3383 if (dca_add_requester(&pdev->dev) == 0) {
3384 adapter->flags |= IGB_FLAG_DCA_ENABLED;
3385 dev_info(&pdev->dev, "DCA enabled\n");
3386 igb_setup_dca(adapter);
3390 #ifdef CONFIG_IGB_HWMON
3391 /* Initialize the thermal sensor on i350 devices. */
3392 if (hw->mac.type == e1000_i350 && hw->bus.func == 0) {
3395 /* Read the NVM to determine if this i350 device supports an
3396 * external thermal sensor.
3398 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_word);
3399 if (ets_word != 0x0000 && ets_word != 0xFFFF)
3400 adapter->ets = true;
3402 adapter->ets = false;
3403 if (igb_sysfs_init(adapter))
3405 "failed to allocate sysfs resources\n");
3407 adapter->ets = false;
3410 /* Check if Media Autosense is enabled */
3412 if (hw->dev_spec._82575.mas_capable)
3413 igb_init_mas(adapter);
3415 /* do hw tstamp init after resetting */
3416 igb_ptp_init(adapter);
3418 dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
3419 /* print bus type/speed/width info, not applicable to i354 */
3420 if (hw->mac.type != e1000_i354) {
3421 dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
3423 ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
3424 (hw->bus.speed == e1000_bus_speed_5000) ? "5.0Gb/s" :
3426 ((hw->bus.width == e1000_bus_width_pcie_x4) ?
3428 (hw->bus.width == e1000_bus_width_pcie_x2) ?
3430 (hw->bus.width == e1000_bus_width_pcie_x1) ?
3431 "Width x1" : "unknown"), netdev->dev_addr);
3434 if ((hw->mac.type >= e1000_i210 ||
3435 igb_get_flash_presence_i210(hw))) {
3436 ret_val = igb_read_part_string(hw, part_str,
3437 E1000_PBANUM_LENGTH);
3439 ret_val = -E1000_ERR_INVM_VALUE_NOT_FOUND;
3443 strcpy(part_str, "Unknown");
3444 dev_info(&pdev->dev, "%s: PBA No: %s\n", netdev->name, part_str);
3445 dev_info(&pdev->dev,
3446 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
3447 (adapter->flags & IGB_FLAG_HAS_MSIX) ? "MSI-X" :
3448 (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
3449 adapter->num_rx_queues, adapter->num_tx_queues);
3450 if (hw->phy.media_type == e1000_media_type_copper) {
3451 switch (hw->mac.type) {
3455 /* Enable EEE for internal copper PHY devices */
3456 err = igb_set_eee_i350(hw, true, true);
3458 (!hw->dev_spec._82575.eee_disable)) {
3459 adapter->eee_advert =
3460 MDIO_EEE_100TX | MDIO_EEE_1000T;
3461 adapter->flags |= IGB_FLAG_EEE;
3465 if ((rd32(E1000_CTRL_EXT) &
3466 E1000_CTRL_EXT_LINK_MODE_SGMII)) {
3467 err = igb_set_eee_i354(hw, true, true);
3469 (!hw->dev_spec._82575.eee_disable)) {
3470 adapter->eee_advert =
3471 MDIO_EEE_100TX | MDIO_EEE_1000T;
3472 adapter->flags |= IGB_FLAG_EEE;
3481 dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NEVER_SKIP);
3483 pm_runtime_put_noidle(&pdev->dev);
3487 igb_release_hw_control(adapter);
3488 memset(&adapter->i2c_adap, 0, sizeof(adapter->i2c_adap));
3490 if (!igb_check_reset_block(hw))
3493 if (hw->flash_address)
3494 iounmap(hw->flash_address);
3496 kfree(adapter->mac_table);
3497 kfree(adapter->shadow_vfta);
3498 igb_clear_interrupt_scheme(adapter);
3499 #ifdef CONFIG_PCI_IOV
3500 igb_disable_sriov(pdev);
3502 pci_iounmap(pdev, adapter->io_addr);
3504 free_netdev(netdev);
3506 pci_disable_pcie_error_reporting(pdev);
3507 pci_release_mem_regions(pdev);
3510 pci_disable_device(pdev);
3514 #ifdef CONFIG_PCI_IOV
3515 static int igb_disable_sriov(struct pci_dev *pdev)
3517 struct net_device *netdev = pci_get_drvdata(pdev);
3518 struct igb_adapter *adapter = netdev_priv(netdev);
3519 struct e1000_hw *hw = &adapter->hw;
3521 /* reclaim resources allocated to VFs */
3522 if (adapter->vf_data) {
3523 /* disable iov and allow time for transactions to clear */
3524 if (pci_vfs_assigned(pdev)) {
3525 dev_warn(&pdev->dev,
3526 "Cannot deallocate SR-IOV virtual functions while they are assigned - VFs will not be deallocated\n");
3529 pci_disable_sriov(pdev);
3533 kfree(adapter->vf_mac_list);
3534 adapter->vf_mac_list = NULL;
3535 kfree(adapter->vf_data);
3536 adapter->vf_data = NULL;
3537 adapter->vfs_allocated_count = 0;
3538 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
3541 dev_info(&pdev->dev, "IOV Disabled\n");
3543 /* Re-enable DMA Coalescing flag since IOV is turned off */
3544 adapter->flags |= IGB_FLAG_DMAC;
3550 static int igb_enable_sriov(struct pci_dev *pdev, int num_vfs)
3552 struct net_device *netdev = pci_get_drvdata(pdev);
3553 struct igb_adapter *adapter = netdev_priv(netdev);
3554 int old_vfs = pci_num_vf(pdev);
3555 struct vf_mac_filter *mac_list;
3557 int num_vf_mac_filters, i;
3559 if (!(adapter->flags & IGB_FLAG_HAS_MSIX) || num_vfs > 7) {
3567 dev_info(&pdev->dev, "%d pre-allocated VFs found - override max_vfs setting of %d\n",
3569 adapter->vfs_allocated_count = old_vfs;
3571 adapter->vfs_allocated_count = num_vfs;
3573 adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
3574 sizeof(struct vf_data_storage), GFP_KERNEL);
3576 /* if allocation failed then we do not support SR-IOV */
3577 if (!adapter->vf_data) {
3578 adapter->vfs_allocated_count = 0;
3583 /* Due to the limited number of RAR entries calculate potential
3584 * number of MAC filters available for the VFs. Reserve entries
3585 * for PF default MAC, PF MAC filters and at least one RAR entry
3586 * for each VF for VF MAC.
3588 num_vf_mac_filters = adapter->hw.mac.rar_entry_count -
3589 (1 + IGB_PF_MAC_FILTERS_RESERVED +
3590 adapter->vfs_allocated_count);
3592 adapter->vf_mac_list = kcalloc(num_vf_mac_filters,
3593 sizeof(struct vf_mac_filter),
3596 mac_list = adapter->vf_mac_list;
3597 INIT_LIST_HEAD(&adapter->vf_macs.l);
3599 if (adapter->vf_mac_list) {
3600 /* Initialize list of VF MAC filters */
3601 for (i = 0; i < num_vf_mac_filters; i++) {
3603 mac_list->free = true;
3604 list_add(&mac_list->l, &adapter->vf_macs.l);
3608 /* If we could not allocate memory for the VF MAC filters
3609 * we can continue without this feature but warn user.
3612 "Unable to allocate memory for VF MAC filter list\n");
3615 /* only call pci_enable_sriov() if no VFs are allocated already */
3617 err = pci_enable_sriov(pdev, adapter->vfs_allocated_count);
3621 dev_info(&pdev->dev, "%d VFs allocated\n",
3622 adapter->vfs_allocated_count);
3623 for (i = 0; i < adapter->vfs_allocated_count; i++)
3624 igb_vf_configure(adapter, i);
3626 /* DMA Coalescing is not supported in IOV mode. */
3627 adapter->flags &= ~IGB_FLAG_DMAC;
3631 kfree(adapter->vf_mac_list);
3632 adapter->vf_mac_list = NULL;
3633 kfree(adapter->vf_data);
3634 adapter->vf_data = NULL;
3635 adapter->vfs_allocated_count = 0;
3642 * igb_remove_i2c - Cleanup I2C interface
3643 * @adapter: pointer to adapter structure
3645 static void igb_remove_i2c(struct igb_adapter *adapter)
3647 /* free the adapter bus structure */
3648 i2c_del_adapter(&adapter->i2c_adap);
3652 * igb_remove - Device Removal Routine
3653 * @pdev: PCI device information struct
3655 * igb_remove is called by the PCI subsystem to alert the driver
3656 * that it should release a PCI device. The could be caused by a
3657 * Hot-Plug event, or because the driver is going to be removed from
3660 static void igb_remove(struct pci_dev *pdev)
3662 struct net_device *netdev = pci_get_drvdata(pdev);
3663 struct igb_adapter *adapter = netdev_priv(netdev);
3664 struct e1000_hw *hw = &adapter->hw;
3666 pm_runtime_get_noresume(&pdev->dev);
3667 #ifdef CONFIG_IGB_HWMON
3668 igb_sysfs_exit(adapter);
3670 igb_remove_i2c(adapter);
3671 igb_ptp_stop(adapter);
3672 /* The watchdog timer may be rescheduled, so explicitly
3673 * disable watchdog from being rescheduled.
3675 set_bit(__IGB_DOWN, &adapter->state);
3676 del_timer_sync(&adapter->watchdog_timer);
3677 del_timer_sync(&adapter->phy_info_timer);
3679 cancel_work_sync(&adapter->reset_task);
3680 cancel_work_sync(&adapter->watchdog_task);
3682 #ifdef CONFIG_IGB_DCA
3683 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
3684 dev_info(&pdev->dev, "DCA disabled\n");
3685 dca_remove_requester(&pdev->dev);
3686 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
3687 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
3691 /* Release control of h/w to f/w. If f/w is AMT enabled, this
3692 * would have already happened in close and is redundant.
3694 igb_release_hw_control(adapter);
3696 #ifdef CONFIG_PCI_IOV
3697 igb_disable_sriov(pdev);
3700 unregister_netdev(netdev);
3702 igb_clear_interrupt_scheme(adapter);
3704 pci_iounmap(pdev, adapter->io_addr);
3705 if (hw->flash_address)
3706 iounmap(hw->flash_address);
3707 pci_release_mem_regions(pdev);
3709 kfree(adapter->mac_table);
3710 kfree(adapter->shadow_vfta);
3711 free_netdev(netdev);
3713 pci_disable_pcie_error_reporting(pdev);
3715 pci_disable_device(pdev);
3719 * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space
3720 * @adapter: board private structure to initialize
3722 * This function initializes the vf specific data storage and then attempts to
3723 * allocate the VFs. The reason for ordering it this way is because it is much
3724 * mor expensive time wise to disable SR-IOV than it is to allocate and free
3725 * the memory for the VFs.
3727 static void igb_probe_vfs(struct igb_adapter *adapter)
3729 #ifdef CONFIG_PCI_IOV
3730 struct pci_dev *pdev = adapter->pdev;
3731 struct e1000_hw *hw = &adapter->hw;
3733 /* Virtualization features not supported on i210 family. */
3734 if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211))
3737 /* Of the below we really only want the effect of getting
3738 * IGB_FLAG_HAS_MSIX set (if available), without which
3739 * igb_enable_sriov() has no effect.
3741 igb_set_interrupt_capability(adapter, true);
3742 igb_reset_interrupt_capability(adapter);
3744 pci_sriov_set_totalvfs(pdev, 7);
3745 igb_enable_sriov(pdev, max_vfs);
3747 #endif /* CONFIG_PCI_IOV */
3750 unsigned int igb_get_max_rss_queues(struct igb_adapter *adapter)
3752 struct e1000_hw *hw = &adapter->hw;
3753 unsigned int max_rss_queues;
3755 /* Determine the maximum number of RSS queues supported. */
3756 switch (hw->mac.type) {
3758 max_rss_queues = IGB_MAX_RX_QUEUES_I211;
3762 max_rss_queues = IGB_MAX_RX_QUEUES_82575;
3765 /* I350 cannot do RSS and SR-IOV at the same time */
3766 if (!!adapter->vfs_allocated_count) {
3772 if (!!adapter->vfs_allocated_count) {
3780 max_rss_queues = IGB_MAX_RX_QUEUES;
3784 return max_rss_queues;
3787 static void igb_init_queue_configuration(struct igb_adapter *adapter)
3791 max_rss_queues = igb_get_max_rss_queues(adapter);
3792 adapter->rss_queues = min_t(u32, max_rss_queues, num_online_cpus());
3794 igb_set_flag_queue_pairs(adapter, max_rss_queues);
3797 void igb_set_flag_queue_pairs(struct igb_adapter *adapter,
3798 const u32 max_rss_queues)
3800 struct e1000_hw *hw = &adapter->hw;
3802 /* Determine if we need to pair queues. */
3803 switch (hw->mac.type) {
3806 /* Device supports enough interrupts without queue pairing. */
3814 /* If rss_queues > half of max_rss_queues, pair the queues in
3815 * order to conserve interrupts due to limited supply.
3817 if (adapter->rss_queues > (max_rss_queues / 2))
3818 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
3820 adapter->flags &= ~IGB_FLAG_QUEUE_PAIRS;
3826 * igb_sw_init - Initialize general software structures (struct igb_adapter)
3827 * @adapter: board private structure to initialize
3829 * igb_sw_init initializes the Adapter private data structure.
3830 * Fields are initialized based on PCI device information and
3831 * OS network device settings (MTU size).
3833 static int igb_sw_init(struct igb_adapter *adapter)
3835 struct e1000_hw *hw = &adapter->hw;
3836 struct net_device *netdev = adapter->netdev;
3837 struct pci_dev *pdev = adapter->pdev;
3839 pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
3841 /* set default ring sizes */
3842 adapter->tx_ring_count = IGB_DEFAULT_TXD;
3843 adapter->rx_ring_count = IGB_DEFAULT_RXD;
3845 /* set default ITR values */
3846 adapter->rx_itr_setting = IGB_DEFAULT_ITR;
3847 adapter->tx_itr_setting = IGB_DEFAULT_ITR;
3849 /* set default work limits */
3850 adapter->tx_work_limit = IGB_DEFAULT_TX_WORK;
3852 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN +
3854 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
3856 spin_lock_init(&adapter->nfc_lock);
3857 spin_lock_init(&adapter->stats64_lock);
3858 #ifdef CONFIG_PCI_IOV
3859 switch (hw->mac.type) {
3863 dev_warn(&pdev->dev,
3864 "Maximum of 7 VFs per PF, using max\n");
3865 max_vfs = adapter->vfs_allocated_count = 7;
3867 adapter->vfs_allocated_count = max_vfs;
3868 if (adapter->vfs_allocated_count)
3869 dev_warn(&pdev->dev,
3870 "Enabling SR-IOV VFs using the module parameter is deprecated - please use the pci sysfs interface.\n");
3875 #endif /* CONFIG_PCI_IOV */
3877 /* Assume MSI-X interrupts, will be checked during IRQ allocation */
3878 adapter->flags |= IGB_FLAG_HAS_MSIX;
3880 adapter->mac_table = kcalloc(hw->mac.rar_entry_count,
3881 sizeof(struct igb_mac_addr),
3883 if (!adapter->mac_table)
3886 igb_probe_vfs(adapter);
3888 igb_init_queue_configuration(adapter);
3890 /* Setup and initialize a copy of the hw vlan table array */
3891 adapter->shadow_vfta = kcalloc(E1000_VLAN_FILTER_TBL_SIZE, sizeof(u32),
3893 if (!adapter->shadow_vfta)
3896 /* This call may decrease the number of queues */
3897 if (igb_init_interrupt_scheme(adapter, true)) {
3898 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
3902 /* Explicitly disable IRQ since the NIC can be in any state. */
3903 igb_irq_disable(adapter);
3905 if (hw->mac.type >= e1000_i350)
3906 adapter->flags &= ~IGB_FLAG_DMAC;
3908 set_bit(__IGB_DOWN, &adapter->state);
3913 * igb_open - Called when a network interface is made active
3914 * @netdev: network interface device structure
3916 * Returns 0 on success, negative value on failure
3918 * The open entry point is called when a network interface is made
3919 * active by the system (IFF_UP). At this point all resources needed
3920 * for transmit and receive operations are allocated, the interrupt
3921 * handler is registered with the OS, the watchdog timer is started,
3922 * and the stack is notified that the interface is ready.
3924 static int __igb_open(struct net_device *netdev, bool resuming)
3926 struct igb_adapter *adapter = netdev_priv(netdev);
3927 struct e1000_hw *hw = &adapter->hw;
3928 struct pci_dev *pdev = adapter->pdev;
3932 /* disallow open during test */
3933 if (test_bit(__IGB_TESTING, &adapter->state)) {
3939 pm_runtime_get_sync(&pdev->dev);
3941 netif_carrier_off(netdev);
3943 /* allocate transmit descriptors */
3944 err = igb_setup_all_tx_resources(adapter);
3948 /* allocate receive descriptors */
3949 err = igb_setup_all_rx_resources(adapter);
3953 igb_power_up_link(adapter);
3955 /* before we allocate an interrupt, we must be ready to handle it.
3956 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3957 * as soon as we call pci_request_irq, so we have to setup our
3958 * clean_rx handler before we do so.
3960 igb_configure(adapter);
3962 err = igb_request_irq(adapter);
3966 /* Notify the stack of the actual queue counts. */
3967 err = netif_set_real_num_tx_queues(adapter->netdev,
3968 adapter->num_tx_queues);
3970 goto err_set_queues;
3972 err = netif_set_real_num_rx_queues(adapter->netdev,
3973 adapter->num_rx_queues);
3975 goto err_set_queues;
3977 /* From here on the code is the same as igb_up() */
3978 clear_bit(__IGB_DOWN, &adapter->state);
3980 for (i = 0; i < adapter->num_q_vectors; i++)
3981 napi_enable(&(adapter->q_vector[i]->napi));
3983 /* Clear any pending interrupts. */
3987 igb_irq_enable(adapter);
3989 /* notify VFs that reset has been completed */
3990 if (adapter->vfs_allocated_count) {
3991 u32 reg_data = rd32(E1000_CTRL_EXT);
3993 reg_data |= E1000_CTRL_EXT_PFRSTD;
3994 wr32(E1000_CTRL_EXT, reg_data);
3997 netif_tx_start_all_queues(netdev);
4000 pm_runtime_put(&pdev->dev);
4002 /* start the watchdog. */
4003 hw->mac.get_link_status = 1;
4004 schedule_work(&adapter->watchdog_task);
4009 igb_free_irq(adapter);
4011 igb_release_hw_control(adapter);
4012 igb_power_down_link(adapter);
4013 igb_free_all_rx_resources(adapter);
4015 igb_free_all_tx_resources(adapter);
4019 pm_runtime_put(&pdev->dev);
4024 int igb_open(struct net_device *netdev)
4026 return __igb_open(netdev, false);
4030 * igb_close - Disables a network interface
4031 * @netdev: network interface device structure
4033 * Returns 0, this is not allowed to fail
4035 * The close entry point is called when an interface is de-activated
4036 * by the OS. The hardware is still under the driver's control, but
4037 * needs to be disabled. A global MAC reset is issued to stop the
4038 * hardware, and all transmit and receive resources are freed.
4040 static int __igb_close(struct net_device *netdev, bool suspending)
4042 struct igb_adapter *adapter = netdev_priv(netdev);
4043 struct pci_dev *pdev = adapter->pdev;
4045 WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
4048 pm_runtime_get_sync(&pdev->dev);
4051 igb_free_irq(adapter);
4053 igb_free_all_tx_resources(adapter);
4054 igb_free_all_rx_resources(adapter);
4057 pm_runtime_put_sync(&pdev->dev);
4061 int igb_close(struct net_device *netdev)
4063 if (netif_device_present(netdev) || netdev->dismantle)
4064 return __igb_close(netdev, false);
4069 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
4070 * @tx_ring: tx descriptor ring (for a specific queue) to setup
4072 * Return 0 on success, negative on failure
4074 int igb_setup_tx_resources(struct igb_ring *tx_ring)
4076 struct device *dev = tx_ring->dev;
4079 size = sizeof(struct igb_tx_buffer) * tx_ring->count;
4081 tx_ring->tx_buffer_info = vmalloc(size);
4082 if (!tx_ring->tx_buffer_info)
4085 /* round up to nearest 4K */
4086 tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
4087 tx_ring->size = ALIGN(tx_ring->size, 4096);
4089 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4090 &tx_ring->dma, GFP_KERNEL);
4094 tx_ring->next_to_use = 0;
4095 tx_ring->next_to_clean = 0;
4100 vfree(tx_ring->tx_buffer_info);
4101 tx_ring->tx_buffer_info = NULL;
4102 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
4107 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
4108 * (Descriptors) for all queues
4109 * @adapter: board private structure
4111 * Return 0 on success, negative on failure
4113 static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
4115 struct pci_dev *pdev = adapter->pdev;
4118 for (i = 0; i < adapter->num_tx_queues; i++) {
4119 err = igb_setup_tx_resources(adapter->tx_ring[i]);
4122 "Allocation for Tx Queue %u failed\n", i);
4123 for (i--; i >= 0; i--)
4124 igb_free_tx_resources(adapter->tx_ring[i]);
4133 * igb_setup_tctl - configure the transmit control registers
4134 * @adapter: Board private structure
4136 void igb_setup_tctl(struct igb_adapter *adapter)
4138 struct e1000_hw *hw = &adapter->hw;
4141 /* disable queue 0 which is enabled by default on 82575 and 82576 */
4142 wr32(E1000_TXDCTL(0), 0);
4144 /* Program the Transmit Control Register */
4145 tctl = rd32(E1000_TCTL);
4146 tctl &= ~E1000_TCTL_CT;
4147 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
4148 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
4150 igb_config_collision_dist(hw);
4152 /* Enable transmits */
4153 tctl |= E1000_TCTL_EN;
4155 wr32(E1000_TCTL, tctl);
4159 * igb_configure_tx_ring - Configure transmit ring after Reset
4160 * @adapter: board private structure
4161 * @ring: tx ring to configure
4163 * Configure a transmit ring after a reset.
4165 void igb_configure_tx_ring(struct igb_adapter *adapter,
4166 struct igb_ring *ring)
4168 struct e1000_hw *hw = &adapter->hw;
4170 u64 tdba = ring->dma;
4171 int reg_idx = ring->reg_idx;
4173 wr32(E1000_TDLEN(reg_idx),
4174 ring->count * sizeof(union e1000_adv_tx_desc));
4175 wr32(E1000_TDBAL(reg_idx),
4176 tdba & 0x00000000ffffffffULL);
4177 wr32(E1000_TDBAH(reg_idx), tdba >> 32);
4179 ring->tail = adapter->io_addr + E1000_TDT(reg_idx);
4180 wr32(E1000_TDH(reg_idx), 0);
4181 writel(0, ring->tail);
4183 txdctl |= IGB_TX_PTHRESH;
4184 txdctl |= IGB_TX_HTHRESH << 8;
4185 txdctl |= IGB_TX_WTHRESH << 16;
4187 /* reinitialize tx_buffer_info */
4188 memset(ring->tx_buffer_info, 0,
4189 sizeof(struct igb_tx_buffer) * ring->count);
4191 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
4192 wr32(E1000_TXDCTL(reg_idx), txdctl);
4196 * igb_configure_tx - Configure transmit Unit after Reset
4197 * @adapter: board private structure
4199 * Configure the Tx unit of the MAC after a reset.
4201 static void igb_configure_tx(struct igb_adapter *adapter)
4203 struct e1000_hw *hw = &adapter->hw;
4206 /* disable the queues */
4207 for (i = 0; i < adapter->num_tx_queues; i++)
4208 wr32(E1000_TXDCTL(adapter->tx_ring[i]->reg_idx), 0);
4211 usleep_range(10000, 20000);
4213 for (i = 0; i < adapter->num_tx_queues; i++)
4214 igb_configure_tx_ring(adapter, adapter->tx_ring[i]);
4218 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
4219 * @rx_ring: Rx descriptor ring (for a specific queue) to setup
4221 * Returns 0 on success, negative on failure
4223 int igb_setup_rx_resources(struct igb_ring *rx_ring)
4225 struct device *dev = rx_ring->dev;
4228 size = sizeof(struct igb_rx_buffer) * rx_ring->count;
4230 rx_ring->rx_buffer_info = vmalloc(size);
4231 if (!rx_ring->rx_buffer_info)
4234 /* Round up to nearest 4K */
4235 rx_ring->size = rx_ring->count * sizeof(union e1000_adv_rx_desc);
4236 rx_ring->size = ALIGN(rx_ring->size, 4096);
4238 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4239 &rx_ring->dma, GFP_KERNEL);
4243 rx_ring->next_to_alloc = 0;
4244 rx_ring->next_to_clean = 0;
4245 rx_ring->next_to_use = 0;
4250 vfree(rx_ring->rx_buffer_info);
4251 rx_ring->rx_buffer_info = NULL;
4252 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
4257 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
4258 * (Descriptors) for all queues
4259 * @adapter: board private structure
4261 * Return 0 on success, negative on failure
4263 static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
4265 struct pci_dev *pdev = adapter->pdev;
4268 for (i = 0; i < adapter->num_rx_queues; i++) {
4269 err = igb_setup_rx_resources(adapter->rx_ring[i]);
4272 "Allocation for Rx Queue %u failed\n", i);
4273 for (i--; i >= 0; i--)
4274 igb_free_rx_resources(adapter->rx_ring[i]);
4283 * igb_setup_mrqc - configure the multiple receive queue control registers
4284 * @adapter: Board private structure
4286 static void igb_setup_mrqc(struct igb_adapter *adapter)
4288 struct e1000_hw *hw = &adapter->hw;
4290 u32 j, num_rx_queues;
4293 netdev_rss_key_fill(rss_key, sizeof(rss_key));
4294 for (j = 0; j < 10; j++)
4295 wr32(E1000_RSSRK(j), rss_key[j]);
4297 num_rx_queues = adapter->rss_queues;
4299 switch (hw->mac.type) {
4301 /* 82576 supports 2 RSS queues for SR-IOV */
4302 if (adapter->vfs_allocated_count)
4309 if (adapter->rss_indir_tbl_init != num_rx_queues) {
4310 for (j = 0; j < IGB_RETA_SIZE; j++)
4311 adapter->rss_indir_tbl[j] =
4312 (j * num_rx_queues) / IGB_RETA_SIZE;
4313 adapter->rss_indir_tbl_init = num_rx_queues;
4315 igb_write_rss_indir_tbl(adapter);
4317 /* Disable raw packet checksumming so that RSS hash is placed in
4318 * descriptor on writeback. No need to enable TCP/UDP/IP checksum
4319 * offloads as they are enabled by default
4321 rxcsum = rd32(E1000_RXCSUM);
4322 rxcsum |= E1000_RXCSUM_PCSD;
4324 if (adapter->hw.mac.type >= e1000_82576)
4325 /* Enable Receive Checksum Offload for SCTP */
4326 rxcsum |= E1000_RXCSUM_CRCOFL;
4328 /* Don't need to set TUOFL or IPOFL, they default to 1 */
4329 wr32(E1000_RXCSUM, rxcsum);
4331 /* Generate RSS hash based on packet types, TCP/UDP
4332 * port numbers and/or IPv4/v6 src and dst addresses
4334 mrqc = E1000_MRQC_RSS_FIELD_IPV4 |
4335 E1000_MRQC_RSS_FIELD_IPV4_TCP |
4336 E1000_MRQC_RSS_FIELD_IPV6 |
4337 E1000_MRQC_RSS_FIELD_IPV6_TCP |
4338 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
4340 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
4341 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
4342 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
4343 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
4345 /* If VMDq is enabled then we set the appropriate mode for that, else
4346 * we default to RSS so that an RSS hash is calculated per packet even
4347 * if we are only using one queue
4349 if (adapter->vfs_allocated_count) {
4350 if (hw->mac.type > e1000_82575) {
4351 /* Set the default pool for the PF's first queue */
4352 u32 vtctl = rd32(E1000_VT_CTL);
4354 vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
4355 E1000_VT_CTL_DISABLE_DEF_POOL);
4356 vtctl |= adapter->vfs_allocated_count <<
4357 E1000_VT_CTL_DEFAULT_POOL_SHIFT;
4358 wr32(E1000_VT_CTL, vtctl);
4360 if (adapter->rss_queues > 1)
4361 mrqc |= E1000_MRQC_ENABLE_VMDQ_RSS_MQ;
4363 mrqc |= E1000_MRQC_ENABLE_VMDQ;
4365 if (hw->mac.type != e1000_i211)
4366 mrqc |= E1000_MRQC_ENABLE_RSS_MQ;
4368 igb_vmm_control(adapter);
4370 wr32(E1000_MRQC, mrqc);
4374 * igb_setup_rctl - configure the receive control registers
4375 * @adapter: Board private structure
4377 void igb_setup_rctl(struct igb_adapter *adapter)
4379 struct e1000_hw *hw = &adapter->hw;
4382 rctl = rd32(E1000_RCTL);
4384 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
4385 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
4387 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
4388 (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
4390 /* enable stripping of CRC. It's unlikely this will break BMC
4391 * redirection as it did with e1000. Newer features require
4392 * that the HW strips the CRC.
4394 rctl |= E1000_RCTL_SECRC;
4396 /* disable store bad packets and clear size bits. */
4397 rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
4399 /* enable LPE to allow for reception of jumbo frames */
4400 rctl |= E1000_RCTL_LPE;
4402 /* disable queue 0 to prevent tail write w/o re-config */
4403 wr32(E1000_RXDCTL(0), 0);
4405 /* Attention!!! For SR-IOV PF driver operations you must enable
4406 * queue drop for all VF and PF queues to prevent head of line blocking
4407 * if an un-trusted VF does not provide descriptors to hardware.
4409 if (adapter->vfs_allocated_count) {
4410 /* set all queue drop enable bits */
4411 wr32(E1000_QDE, ALL_QUEUES);
4414 /* This is useful for sniffing bad packets. */
4415 if (adapter->netdev->features & NETIF_F_RXALL) {
4416 /* UPE and MPE will be handled by normal PROMISC logic
4417 * in e1000e_set_rx_mode
4419 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
4420 E1000_RCTL_BAM | /* RX All Bcast Pkts */
4421 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
4423 rctl &= ~(E1000_RCTL_DPF | /* Allow filtered pause */
4424 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
4425 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
4426 * and that breaks VLANs.
4430 wr32(E1000_RCTL, rctl);
4433 static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
4436 struct e1000_hw *hw = &adapter->hw;
4439 if (size > MAX_JUMBO_FRAME_SIZE)
4440 size = MAX_JUMBO_FRAME_SIZE;
4442 vmolr = rd32(E1000_VMOLR(vfn));
4443 vmolr &= ~E1000_VMOLR_RLPML_MASK;
4444 vmolr |= size | E1000_VMOLR_LPE;
4445 wr32(E1000_VMOLR(vfn), vmolr);
4450 static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
4451 int vfn, bool enable)
4453 struct e1000_hw *hw = &adapter->hw;
4456 if (hw->mac.type < e1000_82576)
4459 if (hw->mac.type == e1000_i350)
4460 reg = E1000_DVMOLR(vfn);
4462 reg = E1000_VMOLR(vfn);
4466 val |= E1000_VMOLR_STRVLAN;
4468 val &= ~(E1000_VMOLR_STRVLAN);
4472 static inline void igb_set_vmolr(struct igb_adapter *adapter,
4475 struct e1000_hw *hw = &adapter->hw;
4478 /* This register exists only on 82576 and newer so if we are older then
4479 * we should exit and do nothing
4481 if (hw->mac.type < e1000_82576)
4484 vmolr = rd32(E1000_VMOLR(vfn));
4486 vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */
4488 vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */
4490 /* clear all bits that might not be set */
4491 vmolr &= ~(E1000_VMOLR_BAM | E1000_VMOLR_RSSE);
4493 if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count)
4494 vmolr |= E1000_VMOLR_RSSE; /* enable RSS */
4495 /* for VMDq only allow the VFs and pool 0 to accept broadcast and
4498 if (vfn <= adapter->vfs_allocated_count)
4499 vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */
4501 wr32(E1000_VMOLR(vfn), vmolr);
4505 * igb_configure_rx_ring - Configure a receive ring after Reset
4506 * @adapter: board private structure
4507 * @ring: receive ring to be configured
4509 * Configure the Rx unit of the MAC after a reset.
4511 void igb_configure_rx_ring(struct igb_adapter *adapter,
4512 struct igb_ring *ring)
4514 struct e1000_hw *hw = &adapter->hw;
4515 union e1000_adv_rx_desc *rx_desc;
4516 u64 rdba = ring->dma;
4517 int reg_idx = ring->reg_idx;
4518 u32 srrctl = 0, rxdctl = 0;
4520 /* disable the queue */
4521 wr32(E1000_RXDCTL(reg_idx), 0);
4523 /* Set DMA base address registers */
4524 wr32(E1000_RDBAL(reg_idx),
4525 rdba & 0x00000000ffffffffULL);
4526 wr32(E1000_RDBAH(reg_idx), rdba >> 32);
4527 wr32(E1000_RDLEN(reg_idx),
4528 ring->count * sizeof(union e1000_adv_rx_desc));
4530 /* initialize head and tail */
4531 ring->tail = adapter->io_addr + E1000_RDT(reg_idx);
4532 wr32(E1000_RDH(reg_idx), 0);
4533 writel(0, ring->tail);
4535 /* set descriptor configuration */
4536 srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
4537 if (ring_uses_large_buffer(ring))
4538 srrctl |= IGB_RXBUFFER_3072 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
4540 srrctl |= IGB_RXBUFFER_2048 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
4541 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
4542 if (hw->mac.type >= e1000_82580)
4543 srrctl |= E1000_SRRCTL_TIMESTAMP;
4544 /* Only set Drop Enable if we are supporting multiple queues */
4545 if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1)
4546 srrctl |= E1000_SRRCTL_DROP_EN;
4548 wr32(E1000_SRRCTL(reg_idx), srrctl);
4550 /* set filtering for VMDQ pools */
4551 igb_set_vmolr(adapter, reg_idx & 0x7, true);
4553 rxdctl |= IGB_RX_PTHRESH;
4554 rxdctl |= IGB_RX_HTHRESH << 8;
4555 rxdctl |= IGB_RX_WTHRESH << 16;
4557 /* initialize rx_buffer_info */
4558 memset(ring->rx_buffer_info, 0,
4559 sizeof(struct igb_rx_buffer) * ring->count);
4561 /* initialize Rx descriptor 0 */
4562 rx_desc = IGB_RX_DESC(ring, 0);
4563 rx_desc->wb.upper.length = 0;
4565 /* enable receive descriptor fetching */
4566 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
4567 wr32(E1000_RXDCTL(reg_idx), rxdctl);
4570 static void igb_set_rx_buffer_len(struct igb_adapter *adapter,
4571 struct igb_ring *rx_ring)
4573 /* set build_skb and buffer size flags */
4574 clear_ring_build_skb_enabled(rx_ring);
4575 clear_ring_uses_large_buffer(rx_ring);
4577 if (adapter->flags & IGB_FLAG_RX_LEGACY)
4580 set_ring_build_skb_enabled(rx_ring);
4582 #if (PAGE_SIZE < 8192)
4583 if (adapter->max_frame_size <= IGB_MAX_FRAME_BUILD_SKB)
4586 set_ring_uses_large_buffer(rx_ring);
4591 * igb_configure_rx - Configure receive Unit after Reset
4592 * @adapter: board private structure
4594 * Configure the Rx unit of the MAC after a reset.
4596 static void igb_configure_rx(struct igb_adapter *adapter)
4600 /* set the correct pool for the PF default MAC address in entry 0 */
4601 igb_set_default_mac_filter(adapter);
4603 /* Setup the HW Rx Head and Tail Descriptor Pointers and
4604 * the Base and Length of the Rx Descriptor Ring
4606 for (i = 0; i < adapter->num_rx_queues; i++) {
4607 struct igb_ring *rx_ring = adapter->rx_ring[i];
4609 igb_set_rx_buffer_len(adapter, rx_ring);
4610 igb_configure_rx_ring(adapter, rx_ring);
4615 * igb_free_tx_resources - Free Tx Resources per Queue
4616 * @tx_ring: Tx descriptor ring for a specific queue
4618 * Free all transmit software resources
4620 void igb_free_tx_resources(struct igb_ring *tx_ring)
4622 igb_clean_tx_ring(tx_ring);
4624 vfree(tx_ring->tx_buffer_info);
4625 tx_ring->tx_buffer_info = NULL;
4627 /* if not set, then don't free */
4631 dma_free_coherent(tx_ring->dev, tx_ring->size,
4632 tx_ring->desc, tx_ring->dma);
4634 tx_ring->desc = NULL;
4638 * igb_free_all_tx_resources - Free Tx Resources for All Queues
4639 * @adapter: board private structure
4641 * Free all transmit software resources
4643 static void igb_free_all_tx_resources(struct igb_adapter *adapter)
4647 for (i = 0; i < adapter->num_tx_queues; i++)
4648 if (adapter->tx_ring[i])
4649 igb_free_tx_resources(adapter->tx_ring[i]);
4653 * igb_clean_tx_ring - Free Tx Buffers
4654 * @tx_ring: ring to be cleaned
4656 static void igb_clean_tx_ring(struct igb_ring *tx_ring)
4658 u16 i = tx_ring->next_to_clean;
4659 struct igb_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
4661 while (i != tx_ring->next_to_use) {
4662 union e1000_adv_tx_desc *eop_desc, *tx_desc;
4664 /* Free all the Tx ring sk_buffs */
4665 dev_kfree_skb_any(tx_buffer->skb);
4667 /* unmap skb header data */
4668 dma_unmap_single(tx_ring->dev,
4669 dma_unmap_addr(tx_buffer, dma),
4670 dma_unmap_len(tx_buffer, len),
4673 /* check for eop_desc to determine the end of the packet */
4674 eop_desc = tx_buffer->next_to_watch;
4675 tx_desc = IGB_TX_DESC(tx_ring, i);
4677 /* unmap remaining buffers */
4678 while (tx_desc != eop_desc) {
4682 if (unlikely(i == tx_ring->count)) {
4684 tx_buffer = tx_ring->tx_buffer_info;
4685 tx_desc = IGB_TX_DESC(tx_ring, 0);
4688 /* unmap any remaining paged data */
4689 if (dma_unmap_len(tx_buffer, len))
4690 dma_unmap_page(tx_ring->dev,
4691 dma_unmap_addr(tx_buffer, dma),
4692 dma_unmap_len(tx_buffer, len),
4696 tx_buffer->next_to_watch = NULL;
4698 /* move us one more past the eop_desc for start of next pkt */
4701 if (unlikely(i == tx_ring->count)) {
4703 tx_buffer = tx_ring->tx_buffer_info;
4707 /* reset BQL for queue */
4708 netdev_tx_reset_queue(txring_txq(tx_ring));
4710 /* reset next_to_use and next_to_clean */
4711 tx_ring->next_to_use = 0;
4712 tx_ring->next_to_clean = 0;
4716 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
4717 * @adapter: board private structure
4719 static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
4723 for (i = 0; i < adapter->num_tx_queues; i++)
4724 if (adapter->tx_ring[i])
4725 igb_clean_tx_ring(adapter->tx_ring[i]);
4729 * igb_free_rx_resources - Free Rx Resources
4730 * @rx_ring: ring to clean the resources from
4732 * Free all receive software resources
4734 void igb_free_rx_resources(struct igb_ring *rx_ring)
4736 igb_clean_rx_ring(rx_ring);
4738 vfree(rx_ring->rx_buffer_info);
4739 rx_ring->rx_buffer_info = NULL;
4741 /* if not set, then don't free */
4745 dma_free_coherent(rx_ring->dev, rx_ring->size,
4746 rx_ring->desc, rx_ring->dma);
4748 rx_ring->desc = NULL;
4752 * igb_free_all_rx_resources - Free Rx Resources for All Queues
4753 * @adapter: board private structure
4755 * Free all receive software resources
4757 static void igb_free_all_rx_resources(struct igb_adapter *adapter)
4761 for (i = 0; i < adapter->num_rx_queues; i++)
4762 if (adapter->rx_ring[i])
4763 igb_free_rx_resources(adapter->rx_ring[i]);
4767 * igb_clean_rx_ring - Free Rx Buffers per Queue
4768 * @rx_ring: ring to free buffers from
4770 static void igb_clean_rx_ring(struct igb_ring *rx_ring)
4772 u16 i = rx_ring->next_to_clean;
4775 dev_kfree_skb(rx_ring->skb);
4776 rx_ring->skb = NULL;
4778 /* Free all the Rx ring sk_buffs */
4779 while (i != rx_ring->next_to_alloc) {
4780 struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
4782 /* Invalidate cache lines that may have been written to by
4783 * device so that we avoid corrupting memory.
4785 dma_sync_single_range_for_cpu(rx_ring->dev,
4787 buffer_info->page_offset,
4788 igb_rx_bufsz(rx_ring),
4791 /* free resources associated with mapping */
4792 dma_unmap_page_attrs(rx_ring->dev,
4794 igb_rx_pg_size(rx_ring),
4797 __page_frag_cache_drain(buffer_info->page,
4798 buffer_info->pagecnt_bias);
4801 if (i == rx_ring->count)
4805 rx_ring->next_to_alloc = 0;
4806 rx_ring->next_to_clean = 0;
4807 rx_ring->next_to_use = 0;
4811 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
4812 * @adapter: board private structure
4814 static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
4818 for (i = 0; i < adapter->num_rx_queues; i++)
4819 if (adapter->rx_ring[i])
4820 igb_clean_rx_ring(adapter->rx_ring[i]);
4824 * igb_set_mac - Change the Ethernet Address of the NIC
4825 * @netdev: network interface device structure
4826 * @p: pointer to an address structure
4828 * Returns 0 on success, negative on failure
4830 static int igb_set_mac(struct net_device *netdev, void *p)
4832 struct igb_adapter *adapter = netdev_priv(netdev);
4833 struct e1000_hw *hw = &adapter->hw;
4834 struct sockaddr *addr = p;
4836 if (!is_valid_ether_addr(addr->sa_data))
4837 return -EADDRNOTAVAIL;
4839 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4840 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
4842 /* set the correct pool for the new PF MAC address in entry 0 */
4843 igb_set_default_mac_filter(adapter);
4849 * igb_write_mc_addr_list - write multicast addresses to MTA
4850 * @netdev: network interface device structure
4852 * Writes multicast address list to the MTA hash table.
4853 * Returns: -ENOMEM on failure
4854 * 0 on no addresses written
4855 * X on writing X addresses to MTA
4857 static int igb_write_mc_addr_list(struct net_device *netdev)
4859 struct igb_adapter *adapter = netdev_priv(netdev);
4860 struct e1000_hw *hw = &adapter->hw;
4861 struct netdev_hw_addr *ha;
4865 if (netdev_mc_empty(netdev)) {
4866 /* nothing to program, so clear mc list */
4867 igb_update_mc_addr_list(hw, NULL, 0);
4868 igb_restore_vf_multicasts(adapter);
4872 mta_list = kcalloc(netdev_mc_count(netdev), 6, GFP_ATOMIC);
4876 /* The shared function expects a packed array of only addresses. */
4878 netdev_for_each_mc_addr(ha, netdev)
4879 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
4881 igb_update_mc_addr_list(hw, mta_list, i);
4884 return netdev_mc_count(netdev);
4887 static int igb_vlan_promisc_enable(struct igb_adapter *adapter)
4889 struct e1000_hw *hw = &adapter->hw;
4892 switch (hw->mac.type) {
4896 /* VLAN filtering needed for VLAN prio filter */
4897 if (adapter->netdev->features & NETIF_F_NTUPLE)
4903 /* VLAN filtering needed for pool filtering */
4904 if (adapter->vfs_allocated_count)
4911 /* We are already in VLAN promisc, nothing to do */
4912 if (adapter->flags & IGB_FLAG_VLAN_PROMISC)
4915 if (!adapter->vfs_allocated_count)
4918 /* Add PF to all active pools */
4919 pf_id = adapter->vfs_allocated_count + E1000_VLVF_POOLSEL_SHIFT;
4921 for (i = E1000_VLVF_ARRAY_SIZE; --i;) {
4922 u32 vlvf = rd32(E1000_VLVF(i));
4925 wr32(E1000_VLVF(i), vlvf);
4929 /* Set all bits in the VLAN filter table array */
4930 for (i = E1000_VLAN_FILTER_TBL_SIZE; i--;)
4931 hw->mac.ops.write_vfta(hw, i, ~0U);
4933 /* Set flag so we don't redo unnecessary work */
4934 adapter->flags |= IGB_FLAG_VLAN_PROMISC;
4939 #define VFTA_BLOCK_SIZE 8
4940 static void igb_scrub_vfta(struct igb_adapter *adapter, u32 vfta_offset)
4942 struct e1000_hw *hw = &adapter->hw;
4943 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4944 u32 vid_start = vfta_offset * 32;
4945 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4946 u32 i, vid, word, bits, pf_id;
4948 /* guarantee that we don't scrub out management VLAN */
4949 vid = adapter->mng_vlan_id;
4950 if (vid >= vid_start && vid < vid_end)
4951 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
4953 if (!adapter->vfs_allocated_count)
4956 pf_id = adapter->vfs_allocated_count + E1000_VLVF_POOLSEL_SHIFT;
4958 for (i = E1000_VLVF_ARRAY_SIZE; --i;) {
4959 u32 vlvf = rd32(E1000_VLVF(i));
4961 /* pull VLAN ID from VLVF */
4962 vid = vlvf & VLAN_VID_MASK;
4964 /* only concern ourselves with a certain range */
4965 if (vid < vid_start || vid >= vid_end)
4968 if (vlvf & E1000_VLVF_VLANID_ENABLE) {
4969 /* record VLAN ID in VFTA */
4970 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
4972 /* if PF is part of this then continue */
4973 if (test_bit(vid, adapter->active_vlans))
4977 /* remove PF from the pool */
4979 bits &= rd32(E1000_VLVF(i));
4980 wr32(E1000_VLVF(i), bits);
4984 /* extract values from active_vlans and write back to VFTA */
4985 for (i = VFTA_BLOCK_SIZE; i--;) {
4986 vid = (vfta_offset + i) * 32;
4987 word = vid / BITS_PER_LONG;
4988 bits = vid % BITS_PER_LONG;
4990 vfta[i] |= adapter->active_vlans[word] >> bits;
4992 hw->mac.ops.write_vfta(hw, vfta_offset + i, vfta[i]);
4996 static void igb_vlan_promisc_disable(struct igb_adapter *adapter)
5000 /* We are not in VLAN promisc, nothing to do */
5001 if (!(adapter->flags & IGB_FLAG_VLAN_PROMISC))
5004 /* Set flag so we don't redo unnecessary work */
5005 adapter->flags &= ~IGB_FLAG_VLAN_PROMISC;
5007 for (i = 0; i < E1000_VLAN_FILTER_TBL_SIZE; i += VFTA_BLOCK_SIZE)
5008 igb_scrub_vfta(adapter, i);
5012 * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
5013 * @netdev: network interface device structure
5015 * The set_rx_mode entry point is called whenever the unicast or multicast
5016 * address lists or the network interface flags are updated. This routine is
5017 * responsible for configuring the hardware for proper unicast, multicast,
5018 * promiscuous mode, and all-multi behavior.
5020 static void igb_set_rx_mode(struct net_device *netdev)
5022 struct igb_adapter *adapter = netdev_priv(netdev);
5023 struct e1000_hw *hw = &adapter->hw;
5024 unsigned int vfn = adapter->vfs_allocated_count;
5025 u32 rctl = 0, vmolr = 0, rlpml = MAX_JUMBO_FRAME_SIZE;
5028 /* Check for Promiscuous and All Multicast modes */
5029 if (netdev->flags & IFF_PROMISC) {
5030 rctl |= E1000_RCTL_UPE | E1000_RCTL_MPE;
5031 vmolr |= E1000_VMOLR_MPME;
5033 /* enable use of UTA filter to force packets to default pool */
5034 if (hw->mac.type == e1000_82576)
5035 vmolr |= E1000_VMOLR_ROPE;
5037 if (netdev->flags & IFF_ALLMULTI) {
5038 rctl |= E1000_RCTL_MPE;
5039 vmolr |= E1000_VMOLR_MPME;
5041 /* Write addresses to the MTA, if the attempt fails
5042 * then we should just turn on promiscuous mode so
5043 * that we can at least receive multicast traffic
5045 count = igb_write_mc_addr_list(netdev);
5047 rctl |= E1000_RCTL_MPE;
5048 vmolr |= E1000_VMOLR_MPME;
5050 vmolr |= E1000_VMOLR_ROMPE;
5055 /* Write addresses to available RAR registers, if there is not
5056 * sufficient space to store all the addresses then enable
5057 * unicast promiscuous mode
5059 if (__dev_uc_sync(netdev, igb_uc_sync, igb_uc_unsync)) {
5060 rctl |= E1000_RCTL_UPE;
5061 vmolr |= E1000_VMOLR_ROPE;
5064 /* enable VLAN filtering by default */
5065 rctl |= E1000_RCTL_VFE;
5067 /* disable VLAN filtering for modes that require it */
5068 if ((netdev->flags & IFF_PROMISC) ||
5069 (netdev->features & NETIF_F_RXALL)) {
5070 /* if we fail to set all rules then just clear VFE */
5071 if (igb_vlan_promisc_enable(adapter))
5072 rctl &= ~E1000_RCTL_VFE;
5074 igb_vlan_promisc_disable(adapter);
5077 /* update state of unicast, multicast, and VLAN filtering modes */
5078 rctl |= rd32(E1000_RCTL) & ~(E1000_RCTL_UPE | E1000_RCTL_MPE |
5080 wr32(E1000_RCTL, rctl);
5082 #if (PAGE_SIZE < 8192)
5083 if (!adapter->vfs_allocated_count) {
5084 if (adapter->max_frame_size <= IGB_MAX_FRAME_BUILD_SKB)
5085 rlpml = IGB_MAX_FRAME_BUILD_SKB;
5088 wr32(E1000_RLPML, rlpml);
5090 /* In order to support SR-IOV and eventually VMDq it is necessary to set
5091 * the VMOLR to enable the appropriate modes. Without this workaround
5092 * we will have issues with VLAN tag stripping not being done for frames
5093 * that are only arriving because we are the default pool
5095 if ((hw->mac.type < e1000_82576) || (hw->mac.type > e1000_i350))
5098 /* set UTA to appropriate mode */
5099 igb_set_uta(adapter, !!(vmolr & E1000_VMOLR_ROPE));
5101 vmolr |= rd32(E1000_VMOLR(vfn)) &
5102 ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
5104 /* enable Rx jumbo frames, restrict as needed to support build_skb */
5105 vmolr &= ~E1000_VMOLR_RLPML_MASK;
5106 #if (PAGE_SIZE < 8192)
5107 if (adapter->max_frame_size <= IGB_MAX_FRAME_BUILD_SKB)
5108 vmolr |= IGB_MAX_FRAME_BUILD_SKB;
5111 vmolr |= MAX_JUMBO_FRAME_SIZE;
5112 vmolr |= E1000_VMOLR_LPE;
5114 wr32(E1000_VMOLR(vfn), vmolr);
5116 igb_restore_vf_multicasts(adapter);
5119 static void igb_check_wvbr(struct igb_adapter *adapter)
5121 struct e1000_hw *hw = &adapter->hw;
5124 switch (hw->mac.type) {
5127 wvbr = rd32(E1000_WVBR);
5135 adapter->wvbr |= wvbr;
5138 #define IGB_STAGGERED_QUEUE_OFFSET 8
5140 static void igb_spoof_check(struct igb_adapter *adapter)
5147 for (j = 0; j < adapter->vfs_allocated_count; j++) {
5148 if (adapter->wvbr & BIT(j) ||
5149 adapter->wvbr & BIT(j + IGB_STAGGERED_QUEUE_OFFSET)) {
5150 dev_warn(&adapter->pdev->dev,
5151 "Spoof event(s) detected on VF %d\n", j);
5154 BIT(j + IGB_STAGGERED_QUEUE_OFFSET));
5159 /* Need to wait a few seconds after link up to get diagnostic information from
5162 static void igb_update_phy_info(struct timer_list *t)
5164 struct igb_adapter *adapter = from_timer(adapter, t, phy_info_timer);
5165 igb_get_phy_info(&adapter->hw);
5169 * igb_has_link - check shared code for link and determine up/down
5170 * @adapter: pointer to driver private info
5172 bool igb_has_link(struct igb_adapter *adapter)
5174 struct e1000_hw *hw = &adapter->hw;
5175 bool link_active = false;
5177 /* get_link_status is set on LSC (link status) interrupt or
5178 * rx sequence error interrupt. get_link_status will stay
5179 * false until the e1000_check_for_link establishes link
5180 * for copper adapters ONLY
5182 switch (hw->phy.media_type) {
5183 case e1000_media_type_copper:
5184 if (!hw->mac.get_link_status)
5187 case e1000_media_type_internal_serdes:
5188 hw->mac.ops.check_for_link(hw);
5189 link_active = !hw->mac.get_link_status;
5192 case e1000_media_type_unknown:
5196 if (((hw->mac.type == e1000_i210) ||
5197 (hw->mac.type == e1000_i211)) &&
5198 (hw->phy.id == I210_I_PHY_ID)) {
5199 if (!netif_carrier_ok(adapter->netdev)) {
5200 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
5201 } else if (!(adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)) {
5202 adapter->flags |= IGB_FLAG_NEED_LINK_UPDATE;
5203 adapter->link_check_timeout = jiffies;
5210 static bool igb_thermal_sensor_event(struct e1000_hw *hw, u32 event)
5213 u32 ctrl_ext, thstat;
5215 /* check for thermal sensor event on i350 copper only */
5216 if (hw->mac.type == e1000_i350) {
5217 thstat = rd32(E1000_THSTAT);
5218 ctrl_ext = rd32(E1000_CTRL_EXT);
5220 if ((hw->phy.media_type == e1000_media_type_copper) &&
5221 !(ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII))
5222 ret = !!(thstat & event);
5229 * igb_check_lvmmc - check for malformed packets received
5230 * and indicated in LVMMC register
5231 * @adapter: pointer to adapter
5233 static void igb_check_lvmmc(struct igb_adapter *adapter)
5235 struct e1000_hw *hw = &adapter->hw;
5238 lvmmc = rd32(E1000_LVMMC);
5240 if (unlikely(net_ratelimit())) {
5241 netdev_warn(adapter->netdev,
5242 "malformed Tx packet detected and dropped, LVMMC:0x%08x\n",
5249 * igb_watchdog - Timer Call-back
5250 * @data: pointer to adapter cast into an unsigned long
5252 static void igb_watchdog(struct timer_list *t)
5254 struct igb_adapter *adapter = from_timer(adapter, t, watchdog_timer);
5255 /* Do the rest outside of interrupt context */
5256 schedule_work(&adapter->watchdog_task);
5259 static void igb_watchdog_task(struct work_struct *work)
5261 struct igb_adapter *adapter = container_of(work,
5264 struct e1000_hw *hw = &adapter->hw;
5265 struct e1000_phy_info *phy = &hw->phy;
5266 struct net_device *netdev = adapter->netdev;
5270 u16 phy_data, retry_count = 20;
5272 link = igb_has_link(adapter);
5274 if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE) {
5275 if (time_after(jiffies, (adapter->link_check_timeout + HZ)))
5276 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
5281 /* Force link down if we have fiber to swap to */
5282 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
5283 if (hw->phy.media_type == e1000_media_type_copper) {
5284 connsw = rd32(E1000_CONNSW);
5285 if (!(connsw & E1000_CONNSW_AUTOSENSE_EN))
5290 /* Perform a reset if the media type changed. */
5291 if (hw->dev_spec._82575.media_changed) {
5292 hw->dev_spec._82575.media_changed = false;
5293 adapter->flags |= IGB_FLAG_MEDIA_RESET;
5296 /* Cancel scheduled suspend requests. */
5297 pm_runtime_resume(netdev->dev.parent);
5299 if (!netif_carrier_ok(netdev)) {
5302 hw->mac.ops.get_speed_and_duplex(hw,
5303 &adapter->link_speed,
5304 &adapter->link_duplex);
5306 ctrl = rd32(E1000_CTRL);
5307 /* Links status message must follow this format */
5309 "igb: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
5311 adapter->link_speed,
5312 adapter->link_duplex == FULL_DUPLEX ?
5314 (ctrl & E1000_CTRL_TFCE) &&
5315 (ctrl & E1000_CTRL_RFCE) ? "RX/TX" :
5316 (ctrl & E1000_CTRL_RFCE) ? "RX" :
5317 (ctrl & E1000_CTRL_TFCE) ? "TX" : "None");
5319 /* disable EEE if enabled */
5320 if ((adapter->flags & IGB_FLAG_EEE) &&
5321 (adapter->link_duplex == HALF_DUPLEX)) {
5322 dev_info(&adapter->pdev->dev,
5323 "EEE Disabled: unsupported at half duplex. Re-enable using ethtool when at full duplex.\n");
5324 adapter->hw.dev_spec._82575.eee_disable = true;
5325 adapter->flags &= ~IGB_FLAG_EEE;
5328 /* check if SmartSpeed worked */
5329 igb_check_downshift(hw);
5330 if (phy->speed_downgraded)
5331 netdev_warn(netdev, "Link Speed was downgraded by SmartSpeed\n");
5333 /* check for thermal sensor event */
5334 if (igb_thermal_sensor_event(hw,
5335 E1000_THSTAT_LINK_THROTTLE))
5336 netdev_info(netdev, "The network adapter link speed was downshifted because it overheated\n");
5338 /* adjust timeout factor according to speed/duplex */
5339 adapter->tx_timeout_factor = 1;
5340 switch (adapter->link_speed) {
5342 adapter->tx_timeout_factor = 14;
5345 /* maybe add some timeout factor ? */
5349 if (adapter->link_speed != SPEED_1000 ||
5350 !hw->phy.ops.read_reg)
5353 /* wait for Remote receiver status OK */
5355 if (!igb_read_phy_reg(hw, PHY_1000T_STATUS,
5357 if (!(phy_data & SR_1000T_REMOTE_RX_STATUS) &&
5361 goto retry_read_status;
5362 } else if (!retry_count) {
5363 dev_err(&adapter->pdev->dev, "exceed max 2 second\n");
5366 dev_err(&adapter->pdev->dev, "read 1000Base-T Status Reg\n");
5369 netif_carrier_on(netdev);
5371 igb_ping_all_vfs(adapter);
5372 igb_check_vf_rate_limit(adapter);
5374 /* link state has changed, schedule phy info update */
5375 if (!test_bit(__IGB_DOWN, &adapter->state))
5376 mod_timer(&adapter->phy_info_timer,
5377 round_jiffies(jiffies + 2 * HZ));
5380 if (netif_carrier_ok(netdev)) {
5381 adapter->link_speed = 0;
5382 adapter->link_duplex = 0;
5384 /* check for thermal sensor event */
5385 if (igb_thermal_sensor_event(hw,
5386 E1000_THSTAT_PWR_DOWN)) {
5387 netdev_err(netdev, "The network adapter was stopped because it overheated\n");
5390 /* Links status message must follow this format */
5391 netdev_info(netdev, "igb: %s NIC Link is Down\n",
5393 netif_carrier_off(netdev);
5395 igb_ping_all_vfs(adapter);
5397 /* link state has changed, schedule phy info update */
5398 if (!test_bit(__IGB_DOWN, &adapter->state))
5399 mod_timer(&adapter->phy_info_timer,
5400 round_jiffies(jiffies + 2 * HZ));
5402 /* link is down, time to check for alternate media */
5403 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
5404 igb_check_swap_media(adapter);
5405 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
5406 schedule_work(&adapter->reset_task);
5407 /* return immediately */
5411 pm_schedule_suspend(netdev->dev.parent,
5414 /* also check for alternate media here */
5415 } else if (!netif_carrier_ok(netdev) &&
5416 (adapter->flags & IGB_FLAG_MAS_ENABLE)) {
5417 igb_check_swap_media(adapter);
5418 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
5419 schedule_work(&adapter->reset_task);
5420 /* return immediately */
5426 spin_lock(&adapter->stats64_lock);
5427 igb_update_stats(adapter);
5428 spin_unlock(&adapter->stats64_lock);
5430 for (i = 0; i < adapter->num_tx_queues; i++) {
5431 struct igb_ring *tx_ring = adapter->tx_ring[i];
5432 if (!netif_carrier_ok(netdev)) {
5433 /* We've lost link, so the controller stops DMA,
5434 * but we've got queued Tx work that's never going
5435 * to get done, so reset controller to flush Tx.
5436 * (Do the reset outside of interrupt context).
5438 if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
5439 adapter->tx_timeout_count++;
5440 schedule_work(&adapter->reset_task);
5441 /* return immediately since reset is imminent */
5446 /* Force detection of hung controller every watchdog period */
5447 set_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
5450 /* Cause software interrupt to ensure Rx ring is cleaned */
5451 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
5454 for (i = 0; i < adapter->num_q_vectors; i++)
5455 eics |= adapter->q_vector[i]->eims_value;
5456 wr32(E1000_EICS, eics);
5458 wr32(E1000_ICS, E1000_ICS_RXDMT0);
5461 igb_spoof_check(adapter);
5462 igb_ptp_rx_hang(adapter);
5463 igb_ptp_tx_hang(adapter);
5465 /* Check LVMMC register on i350/i354 only */
5466 if ((adapter->hw.mac.type == e1000_i350) ||
5467 (adapter->hw.mac.type == e1000_i354))
5468 igb_check_lvmmc(adapter);
5470 /* Reset the timer */
5471 if (!test_bit(__IGB_DOWN, &adapter->state)) {
5472 if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)
5473 mod_timer(&adapter->watchdog_timer,
5474 round_jiffies(jiffies + HZ));
5476 mod_timer(&adapter->watchdog_timer,
5477 round_jiffies(jiffies + 2 * HZ));
5481 enum latency_range {
5485 latency_invalid = 255
5489 * igb_update_ring_itr - update the dynamic ITR value based on packet size
5490 * @q_vector: pointer to q_vector
5492 * Stores a new ITR value based on strictly on packet size. This
5493 * algorithm is less sophisticated than that used in igb_update_itr,
5494 * due to the difficulty of synchronizing statistics across multiple
5495 * receive rings. The divisors and thresholds used by this function
5496 * were determined based on theoretical maximum wire speed and testing
5497 * data, in order to minimize response time while increasing bulk
5499 * This functionality is controlled by ethtool's coalescing settings.
5500 * NOTE: This function is called only when operating in a multiqueue
5501 * receive environment.
5503 static void igb_update_ring_itr(struct igb_q_vector *q_vector)
5505 int new_val = q_vector->itr_val;
5506 int avg_wire_size = 0;
5507 struct igb_adapter *adapter = q_vector->adapter;
5508 unsigned int packets;
5510 /* For non-gigabit speeds, just fix the interrupt rate at 4000
5511 * ints/sec - ITR timer value of 120 ticks.
5513 if (adapter->link_speed != SPEED_1000) {
5514 new_val = IGB_4K_ITR;
5518 packets = q_vector->rx.total_packets;
5520 avg_wire_size = q_vector->rx.total_bytes / packets;
5522 packets = q_vector->tx.total_packets;
5524 avg_wire_size = max_t(u32, avg_wire_size,
5525 q_vector->tx.total_bytes / packets);
5527 /* if avg_wire_size isn't set no work was done */
5531 /* Add 24 bytes to size to account for CRC, preamble, and gap */
5532 avg_wire_size += 24;
5534 /* Don't starve jumbo frames */
5535 avg_wire_size = min(avg_wire_size, 3000);
5537 /* Give a little boost to mid-size frames */
5538 if ((avg_wire_size > 300) && (avg_wire_size < 1200))
5539 new_val = avg_wire_size / 3;
5541 new_val = avg_wire_size / 2;
5543 /* conservative mode (itr 3) eliminates the lowest_latency setting */
5544 if (new_val < IGB_20K_ITR &&
5545 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
5546 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
5547 new_val = IGB_20K_ITR;
5550 if (new_val != q_vector->itr_val) {
5551 q_vector->itr_val = new_val;
5552 q_vector->set_itr = 1;
5555 q_vector->rx.total_bytes = 0;
5556 q_vector->rx.total_packets = 0;
5557 q_vector->tx.total_bytes = 0;
5558 q_vector->tx.total_packets = 0;
5562 * igb_update_itr - update the dynamic ITR value based on statistics
5563 * @q_vector: pointer to q_vector
5564 * @ring_container: ring info to update the itr for
5566 * Stores a new ITR value based on packets and byte
5567 * counts during the last interrupt. The advantage of per interrupt
5568 * computation is faster updates and more accurate ITR for the current
5569 * traffic pattern. Constants in this function were computed
5570 * based on theoretical maximum wire speed and thresholds were set based
5571 * on testing data as well as attempting to minimize response time
5572 * while increasing bulk throughput.
5573 * This functionality is controlled by ethtool's coalescing settings.
5574 * NOTE: These calculations are only valid when operating in a single-
5575 * queue environment.
5577 static void igb_update_itr(struct igb_q_vector *q_vector,
5578 struct igb_ring_container *ring_container)
5580 unsigned int packets = ring_container->total_packets;
5581 unsigned int bytes = ring_container->total_bytes;
5582 u8 itrval = ring_container->itr;
5584 /* no packets, exit with status unchanged */
5589 case lowest_latency:
5590 /* handle TSO and jumbo frames */
5591 if (bytes/packets > 8000)
5592 itrval = bulk_latency;
5593 else if ((packets < 5) && (bytes > 512))
5594 itrval = low_latency;
5596 case low_latency: /* 50 usec aka 20000 ints/s */
5597 if (bytes > 10000) {
5598 /* this if handles the TSO accounting */
5599 if (bytes/packets > 8000)
5600 itrval = bulk_latency;
5601 else if ((packets < 10) || ((bytes/packets) > 1200))
5602 itrval = bulk_latency;
5603 else if ((packets > 35))
5604 itrval = lowest_latency;
5605 } else if (bytes/packets > 2000) {
5606 itrval = bulk_latency;
5607 } else if (packets <= 2 && bytes < 512) {
5608 itrval = lowest_latency;
5611 case bulk_latency: /* 250 usec aka 4000 ints/s */
5612 if (bytes > 25000) {
5614 itrval = low_latency;
5615 } else if (bytes < 1500) {
5616 itrval = low_latency;
5621 /* clear work counters since we have the values we need */
5622 ring_container->total_bytes = 0;
5623 ring_container->total_packets = 0;
5625 /* write updated itr to ring container */
5626 ring_container->itr = itrval;
5629 static void igb_set_itr(struct igb_q_vector *q_vector)
5631 struct igb_adapter *adapter = q_vector->adapter;
5632 u32 new_itr = q_vector->itr_val;
5635 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
5636 if (adapter->link_speed != SPEED_1000) {
5638 new_itr = IGB_4K_ITR;
5642 igb_update_itr(q_vector, &q_vector->tx);
5643 igb_update_itr(q_vector, &q_vector->rx);
5645 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
5647 /* conservative mode (itr 3) eliminates the lowest_latency setting */
5648 if (current_itr == lowest_latency &&
5649 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
5650 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
5651 current_itr = low_latency;
5653 switch (current_itr) {
5654 /* counts and packets in update_itr are dependent on these numbers */
5655 case lowest_latency:
5656 new_itr = IGB_70K_ITR; /* 70,000 ints/sec */
5659 new_itr = IGB_20K_ITR; /* 20,000 ints/sec */
5662 new_itr = IGB_4K_ITR; /* 4,000 ints/sec */
5669 if (new_itr != q_vector->itr_val) {
5670 /* this attempts to bias the interrupt rate towards Bulk
5671 * by adding intermediate steps when interrupt rate is
5674 new_itr = new_itr > q_vector->itr_val ?
5675 max((new_itr * q_vector->itr_val) /
5676 (new_itr + (q_vector->itr_val >> 2)),
5678 /* Don't write the value here; it resets the adapter's
5679 * internal timer, and causes us to delay far longer than
5680 * we should between interrupts. Instead, we write the ITR
5681 * value at the beginning of the next interrupt so the timing
5682 * ends up being correct.
5684 q_vector->itr_val = new_itr;
5685 q_vector->set_itr = 1;
5689 static void igb_tx_ctxtdesc(struct igb_ring *tx_ring,
5690 struct igb_tx_buffer *first,
5691 u32 vlan_macip_lens, u32 type_tucmd,
5694 struct e1000_adv_tx_context_desc *context_desc;
5695 u16 i = tx_ring->next_to_use;
5696 struct timespec64 ts;
5698 context_desc = IGB_TX_CTXTDESC(tx_ring, i);
5701 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
5703 /* set bits to identify this as an advanced context descriptor */
5704 type_tucmd |= E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
5706 /* For 82575, context index must be unique per ring. */
5707 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
5708 mss_l4len_idx |= tx_ring->reg_idx << 4;
5710 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
5711 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
5712 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
5714 /* We assume there is always a valid tx time available. Invalid times
5715 * should have been handled by the upper layers.
5717 if (tx_ring->launchtime_enable) {
5718 ts = ns_to_timespec64(first->skb->tstamp);
5719 first->skb->tstamp = 0;
5720 context_desc->seqnum_seed = cpu_to_le32(ts.tv_nsec / 32);
5722 context_desc->seqnum_seed = 0;
5726 static int igb_tso(struct igb_ring *tx_ring,
5727 struct igb_tx_buffer *first,
5730 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
5731 struct sk_buff *skb = first->skb;
5741 u32 paylen, l4_offset;
5744 if (skb->ip_summed != CHECKSUM_PARTIAL)
5747 if (!skb_is_gso(skb))
5750 err = skb_cow_head(skb, 0);
5754 ip.hdr = skb_network_header(skb);
5755 l4.hdr = skb_checksum_start(skb);
5757 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5758 type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
5760 /* initialize outer IP header fields */
5761 if (ip.v4->version == 4) {
5762 unsigned char *csum_start = skb_checksum_start(skb);
5763 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
5765 /* IP header will have to cancel out any data that
5766 * is not a part of the outer IP header
5768 ip.v4->check = csum_fold(csum_partial(trans_start,
5769 csum_start - trans_start,
5771 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
5774 first->tx_flags |= IGB_TX_FLAGS_TSO |
5778 ip.v6->payload_len = 0;
5779 first->tx_flags |= IGB_TX_FLAGS_TSO |
5783 /* determine offset of inner transport header */
5784 l4_offset = l4.hdr - skb->data;
5786 /* compute length of segmentation header */
5787 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
5789 /* remove payload length from inner checksum */
5790 paylen = skb->len - l4_offset;
5791 csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
5793 /* update gso size and bytecount with header size */
5794 first->gso_segs = skb_shinfo(skb)->gso_segs;
5795 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5798 mss_l4len_idx = (*hdr_len - l4_offset) << E1000_ADVTXD_L4LEN_SHIFT;
5799 mss_l4len_idx |= skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT;
5801 /* VLAN MACLEN IPLEN */
5802 vlan_macip_lens = l4.hdr - ip.hdr;
5803 vlan_macip_lens |= (ip.hdr - skb->data) << E1000_ADVTXD_MACLEN_SHIFT;
5804 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
5806 igb_tx_ctxtdesc(tx_ring, first, vlan_macip_lens,
5807 type_tucmd, mss_l4len_idx);
5812 static inline bool igb_ipv6_csum_is_sctp(struct sk_buff *skb)
5814 unsigned int offset = 0;
5816 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
5818 return offset == skb_checksum_start_offset(skb);
5821 static void igb_tx_csum(struct igb_ring *tx_ring, struct igb_tx_buffer *first)
5823 struct sk_buff *skb = first->skb;
5824 u32 vlan_macip_lens = 0;
5827 if (skb->ip_summed != CHECKSUM_PARTIAL) {
5829 if (!(first->tx_flags & IGB_TX_FLAGS_VLAN) &&
5830 !tx_ring->launchtime_enable)
5835 switch (skb->csum_offset) {
5836 case offsetof(struct tcphdr, check):
5837 type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
5839 case offsetof(struct udphdr, check):
5841 case offsetof(struct sctphdr, checksum):
5842 /* validate that this is actually an SCTP request */
5843 if (((first->protocol == htons(ETH_P_IP)) &&
5844 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
5845 ((first->protocol == htons(ETH_P_IPV6)) &&
5846 igb_ipv6_csum_is_sctp(skb))) {
5847 type_tucmd = E1000_ADVTXD_TUCMD_L4T_SCTP;
5852 skb_checksum_help(skb);
5856 /* update TX checksum flag */
5857 first->tx_flags |= IGB_TX_FLAGS_CSUM;
5858 vlan_macip_lens = skb_checksum_start_offset(skb) -
5859 skb_network_offset(skb);
5861 vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
5862 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
5864 igb_tx_ctxtdesc(tx_ring, first, vlan_macip_lens, type_tucmd, 0);
5867 #define IGB_SET_FLAG(_input, _flag, _result) \
5868 ((_flag <= _result) ? \
5869 ((u32)(_input & _flag) * (_result / _flag)) : \
5870 ((u32)(_input & _flag) / (_flag / _result)))
5872 static u32 igb_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
5874 /* set type for advanced descriptor with frame checksum insertion */
5875 u32 cmd_type = E1000_ADVTXD_DTYP_DATA |
5876 E1000_ADVTXD_DCMD_DEXT |
5877 E1000_ADVTXD_DCMD_IFCS;
5879 /* set HW vlan bit if vlan is present */
5880 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_VLAN,
5881 (E1000_ADVTXD_DCMD_VLE));
5883 /* set segmentation bits for TSO */
5884 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSO,
5885 (E1000_ADVTXD_DCMD_TSE));
5887 /* set timestamp bit if present */
5888 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSTAMP,
5889 (E1000_ADVTXD_MAC_TSTAMP));
5891 /* insert frame checksum */
5892 cmd_type ^= IGB_SET_FLAG(skb->no_fcs, 1, E1000_ADVTXD_DCMD_IFCS);
5897 static void igb_tx_olinfo_status(struct igb_ring *tx_ring,
5898 union e1000_adv_tx_desc *tx_desc,
5899 u32 tx_flags, unsigned int paylen)
5901 u32 olinfo_status = paylen << E1000_ADVTXD_PAYLEN_SHIFT;
5903 /* 82575 requires a unique index per ring */
5904 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
5905 olinfo_status |= tx_ring->reg_idx << 4;
5907 /* insert L4 checksum */
5908 olinfo_status |= IGB_SET_FLAG(tx_flags,
5910 (E1000_TXD_POPTS_TXSM << 8));
5912 /* insert IPv4 checksum */
5913 olinfo_status |= IGB_SET_FLAG(tx_flags,
5915 (E1000_TXD_POPTS_IXSM << 8));
5917 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
5920 static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
5922 struct net_device *netdev = tx_ring->netdev;
5924 netif_stop_subqueue(netdev, tx_ring->queue_index);
5926 /* Herbert's original patch had:
5927 * smp_mb__after_netif_stop_queue();
5928 * but since that doesn't exist yet, just open code it.
5932 /* We need to check again in a case another CPU has just
5933 * made room available.
5935 if (igb_desc_unused(tx_ring) < size)
5939 netif_wake_subqueue(netdev, tx_ring->queue_index);
5941 u64_stats_update_begin(&tx_ring->tx_syncp2);
5942 tx_ring->tx_stats.restart_queue2++;
5943 u64_stats_update_end(&tx_ring->tx_syncp2);
5948 static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
5950 if (igb_desc_unused(tx_ring) >= size)
5952 return __igb_maybe_stop_tx(tx_ring, size);
5955 static int igb_tx_map(struct igb_ring *tx_ring,
5956 struct igb_tx_buffer *first,
5959 struct sk_buff *skb = first->skb;
5960 struct igb_tx_buffer *tx_buffer;
5961 union e1000_adv_tx_desc *tx_desc;
5962 struct skb_frag_struct *frag;
5964 unsigned int data_len, size;
5965 u32 tx_flags = first->tx_flags;
5966 u32 cmd_type = igb_tx_cmd_type(skb, tx_flags);
5967 u16 i = tx_ring->next_to_use;
5969 tx_desc = IGB_TX_DESC(tx_ring, i);
5971 igb_tx_olinfo_status(tx_ring, tx_desc, tx_flags, skb->len - hdr_len);
5973 size = skb_headlen(skb);
5974 data_len = skb->data_len;
5976 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
5980 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
5981 if (dma_mapping_error(tx_ring->dev, dma))
5984 /* record length, and DMA address */
5985 dma_unmap_len_set(tx_buffer, len, size);
5986 dma_unmap_addr_set(tx_buffer, dma, dma);
5988 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5990 while (unlikely(size > IGB_MAX_DATA_PER_TXD)) {
5991 tx_desc->read.cmd_type_len =
5992 cpu_to_le32(cmd_type ^ IGB_MAX_DATA_PER_TXD);
5996 if (i == tx_ring->count) {
5997 tx_desc = IGB_TX_DESC(tx_ring, 0);
6000 tx_desc->read.olinfo_status = 0;
6002 dma += IGB_MAX_DATA_PER_TXD;
6003 size -= IGB_MAX_DATA_PER_TXD;
6005 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6008 if (likely(!data_len))
6011 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
6015 if (i == tx_ring->count) {
6016 tx_desc = IGB_TX_DESC(tx_ring, 0);
6019 tx_desc->read.olinfo_status = 0;
6021 size = skb_frag_size(frag);
6024 dma = skb_frag_dma_map(tx_ring->dev, frag, 0,
6025 size, DMA_TO_DEVICE);
6027 tx_buffer = &tx_ring->tx_buffer_info[i];
6030 /* write last descriptor with RS and EOP bits */
6031 cmd_type |= size | IGB_TXD_DCMD;
6032 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
6034 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
6036 /* set the timestamp */
6037 first->time_stamp = jiffies;
6039 /* Force memory writes to complete before letting h/w know there
6040 * are new descriptors to fetch. (Only applicable for weak-ordered
6041 * memory model archs, such as IA-64).
6043 * We also need this memory barrier to make certain all of the
6044 * status bits have been updated before next_to_watch is written.
6048 /* set next_to_watch value indicating a packet is present */
6049 first->next_to_watch = tx_desc;
6052 if (i == tx_ring->count)
6055 tx_ring->next_to_use = i;
6057 /* Make sure there is space in the ring for the next send. */
6058 igb_maybe_stop_tx(tx_ring, DESC_NEEDED);
6060 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
6061 writel(i, tx_ring->tail);
6063 /* we need this if more than one processor can write to our tail
6064 * at a time, it synchronizes IO on IA64/Altix systems
6071 dev_err(tx_ring->dev, "TX DMA map failed\n");
6072 tx_buffer = &tx_ring->tx_buffer_info[i];
6074 /* clear dma mappings for failed tx_buffer_info map */
6075 while (tx_buffer != first) {
6076 if (dma_unmap_len(tx_buffer, len))
6077 dma_unmap_page(tx_ring->dev,
6078 dma_unmap_addr(tx_buffer, dma),
6079 dma_unmap_len(tx_buffer, len),
6081 dma_unmap_len_set(tx_buffer, len, 0);
6084 i += tx_ring->count;
6085 tx_buffer = &tx_ring->tx_buffer_info[i];
6088 if (dma_unmap_len(tx_buffer, len))
6089 dma_unmap_single(tx_ring->dev,
6090 dma_unmap_addr(tx_buffer, dma),
6091 dma_unmap_len(tx_buffer, len),
6093 dma_unmap_len_set(tx_buffer, len, 0);
6095 dev_kfree_skb_any(tx_buffer->skb);
6096 tx_buffer->skb = NULL;
6098 tx_ring->next_to_use = i;
6103 netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,
6104 struct igb_ring *tx_ring)
6106 struct igb_tx_buffer *first;
6110 u16 count = TXD_USE_COUNT(skb_headlen(skb));
6111 __be16 protocol = vlan_get_protocol(skb);
6114 /* need: 1 descriptor per page * PAGE_SIZE/IGB_MAX_DATA_PER_TXD,
6115 * + 1 desc for skb_headlen/IGB_MAX_DATA_PER_TXD,
6116 * + 2 desc gap to keep tail from touching head,
6117 * + 1 desc for context descriptor,
6118 * otherwise try next time
6120 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6121 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6123 if (igb_maybe_stop_tx(tx_ring, count + 3)) {
6124 /* this is a hard error */
6125 return NETDEV_TX_BUSY;
6128 /* record the location of the first descriptor for this packet */
6129 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6131 first->bytecount = skb->len;
6132 first->gso_segs = 1;
6134 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
6135 struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
6137 if (adapter->tstamp_config.tx_type == HWTSTAMP_TX_ON &&
6138 !test_and_set_bit_lock(__IGB_PTP_TX_IN_PROGRESS,
6140 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
6141 tx_flags |= IGB_TX_FLAGS_TSTAMP;
6143 adapter->ptp_tx_skb = skb_get(skb);
6144 adapter->ptp_tx_start = jiffies;
6145 if (adapter->hw.mac.type == e1000_82576)
6146 schedule_work(&adapter->ptp_tx_work);
6148 adapter->tx_hwtstamp_skipped++;
6152 if (skb_vlan_tag_present(skb)) {
6153 tx_flags |= IGB_TX_FLAGS_VLAN;
6154 tx_flags |= (skb_vlan_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
6157 /* record initial flags and protocol */
6158 first->tx_flags = tx_flags;
6159 first->protocol = protocol;
6161 tso = igb_tso(tx_ring, first, &hdr_len);
6165 igb_tx_csum(tx_ring, first);
6167 skb_tx_timestamp(skb);
6169 if (igb_tx_map(tx_ring, first, hdr_len))
6170 goto cleanup_tx_tstamp;
6172 return NETDEV_TX_OK;
6175 dev_kfree_skb_any(first->skb);
6178 if (unlikely(tx_flags & IGB_TX_FLAGS_TSTAMP)) {
6179 struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
6181 dev_kfree_skb_any(adapter->ptp_tx_skb);
6182 adapter->ptp_tx_skb = NULL;
6183 if (adapter->hw.mac.type == e1000_82576)
6184 cancel_work_sync(&adapter->ptp_tx_work);
6185 clear_bit_unlock(__IGB_PTP_TX_IN_PROGRESS, &adapter->state);
6188 return NETDEV_TX_OK;
6191 static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter,
6192 struct sk_buff *skb)
6194 unsigned int r_idx = skb->queue_mapping;
6196 if (r_idx >= adapter->num_tx_queues)
6197 r_idx = r_idx % adapter->num_tx_queues;
6199 return adapter->tx_ring[r_idx];
6202 static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
6203 struct net_device *netdev)
6205 struct igb_adapter *adapter = netdev_priv(netdev);
6207 /* The minimum packet size with TCTL.PSP set is 17 so pad the skb
6208 * in order to meet this minimum size requirement.
6210 if (skb_put_padto(skb, 17))
6211 return NETDEV_TX_OK;
6213 return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb));
6217 * igb_tx_timeout - Respond to a Tx Hang
6218 * @netdev: network interface device structure
6220 static void igb_tx_timeout(struct net_device *netdev)
6222 struct igb_adapter *adapter = netdev_priv(netdev);
6223 struct e1000_hw *hw = &adapter->hw;
6225 /* Do the reset outside of interrupt context */
6226 adapter->tx_timeout_count++;
6228 if (hw->mac.type >= e1000_82580)
6229 hw->dev_spec._82575.global_device_reset = true;
6231 schedule_work(&adapter->reset_task);
6233 (adapter->eims_enable_mask & ~adapter->eims_other));
6236 static void igb_reset_task(struct work_struct *work)
6238 struct igb_adapter *adapter;
6239 adapter = container_of(work, struct igb_adapter, reset_task);
6242 /* If we're already down or resetting, just bail */
6243 if (test_bit(__IGB_DOWN, &adapter->state) ||
6244 test_bit(__IGB_RESETTING, &adapter->state)) {
6250 netdev_err(adapter->netdev, "Reset adapter\n");
6251 igb_reinit_locked(adapter);
6256 * igb_get_stats64 - Get System Network Statistics
6257 * @netdev: network interface device structure
6258 * @stats: rtnl_link_stats64 pointer
6260 static void igb_get_stats64(struct net_device *netdev,
6261 struct rtnl_link_stats64 *stats)
6263 struct igb_adapter *adapter = netdev_priv(netdev);
6265 spin_lock(&adapter->stats64_lock);
6266 igb_update_stats(adapter);
6267 memcpy(stats, &adapter->stats64, sizeof(*stats));
6268 spin_unlock(&adapter->stats64_lock);
6272 * igb_change_mtu - Change the Maximum Transfer Unit
6273 * @netdev: network interface device structure
6274 * @new_mtu: new value for maximum frame size
6276 * Returns 0 on success, negative on failure
6278 static int igb_change_mtu(struct net_device *netdev, int new_mtu)
6280 struct igb_adapter *adapter = netdev_priv(netdev);
6281 struct pci_dev *pdev = adapter->pdev;
6282 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
6284 /* adjust max frame to be at least the size of a standard frame */
6285 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
6286 max_frame = ETH_FRAME_LEN + ETH_FCS_LEN;
6288 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
6289 usleep_range(1000, 2000);
6291 /* igb_down has a dependency on max_frame_size */
6292 adapter->max_frame_size = max_frame;
6294 if (netif_running(netdev))
6297 dev_info(&pdev->dev, "changing MTU from %d to %d\n",
6298 netdev->mtu, new_mtu);
6299 netdev->mtu = new_mtu;
6301 if (netif_running(netdev))
6306 clear_bit(__IGB_RESETTING, &adapter->state);
6312 * igb_update_stats - Update the board statistics counters
6313 * @adapter: board private structure
6315 void igb_update_stats(struct igb_adapter *adapter)
6317 struct rtnl_link_stats64 *net_stats = &adapter->stats64;
6318 struct e1000_hw *hw = &adapter->hw;
6319 struct pci_dev *pdev = adapter->pdev;
6324 u64 _bytes, _packets;
6326 /* Prevent stats update while adapter is being reset, or if the pci
6327 * connection is down.
6329 if (adapter->link_speed == 0)
6331 if (pci_channel_offline(pdev))
6338 for (i = 0; i < adapter->num_rx_queues; i++) {
6339 struct igb_ring *ring = adapter->rx_ring[i];
6340 u32 rqdpc = rd32(E1000_RQDPC(i));
6341 if (hw->mac.type >= e1000_i210)
6342 wr32(E1000_RQDPC(i), 0);
6345 ring->rx_stats.drops += rqdpc;
6346 net_stats->rx_fifo_errors += rqdpc;
6350 start = u64_stats_fetch_begin_irq(&ring->rx_syncp);
6351 _bytes = ring->rx_stats.bytes;
6352 _packets = ring->rx_stats.packets;
6353 } while (u64_stats_fetch_retry_irq(&ring->rx_syncp, start));
6355 packets += _packets;
6358 net_stats->rx_bytes = bytes;
6359 net_stats->rx_packets = packets;
6363 for (i = 0; i < adapter->num_tx_queues; i++) {
6364 struct igb_ring *ring = adapter->tx_ring[i];
6366 start = u64_stats_fetch_begin_irq(&ring->tx_syncp);
6367 _bytes = ring->tx_stats.bytes;
6368 _packets = ring->tx_stats.packets;
6369 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp, start));
6371 packets += _packets;
6373 net_stats->tx_bytes = bytes;
6374 net_stats->tx_packets = packets;
6377 /* read stats registers */
6378 adapter->stats.crcerrs += rd32(E1000_CRCERRS);
6379 adapter->stats.gprc += rd32(E1000_GPRC);
6380 adapter->stats.gorc += rd32(E1000_GORCL);
6381 rd32(E1000_GORCH); /* clear GORCL */
6382 adapter->stats.bprc += rd32(E1000_BPRC);
6383 adapter->stats.mprc += rd32(E1000_MPRC);
6384 adapter->stats.roc += rd32(E1000_ROC);
6386 adapter->stats.prc64 += rd32(E1000_PRC64);
6387 adapter->stats.prc127 += rd32(E1000_PRC127);
6388 adapter->stats.prc255 += rd32(E1000_PRC255);
6389 adapter->stats.prc511 += rd32(E1000_PRC511);
6390 adapter->stats.prc1023 += rd32(E1000_PRC1023);
6391 adapter->stats.prc1522 += rd32(E1000_PRC1522);
6392 adapter->stats.symerrs += rd32(E1000_SYMERRS);
6393 adapter->stats.sec += rd32(E1000_SEC);
6395 mpc = rd32(E1000_MPC);
6396 adapter->stats.mpc += mpc;
6397 net_stats->rx_fifo_errors += mpc;
6398 adapter->stats.scc += rd32(E1000_SCC);
6399 adapter->stats.ecol += rd32(E1000_ECOL);
6400 adapter->stats.mcc += rd32(E1000_MCC);
6401 adapter->stats.latecol += rd32(E1000_LATECOL);
6402 adapter->stats.dc += rd32(E1000_DC);
6403 adapter->stats.rlec += rd32(E1000_RLEC);
6404 adapter->stats.xonrxc += rd32(E1000_XONRXC);
6405 adapter->stats.xontxc += rd32(E1000_XONTXC);
6406 adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
6407 adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
6408 adapter->stats.fcruc += rd32(E1000_FCRUC);
6409 adapter->stats.gptc += rd32(E1000_GPTC);
6410 adapter->stats.gotc += rd32(E1000_GOTCL);
6411 rd32(E1000_GOTCH); /* clear GOTCL */
6412 adapter->stats.rnbc += rd32(E1000_RNBC);
6413 adapter->stats.ruc += rd32(E1000_RUC);
6414 adapter->stats.rfc += rd32(E1000_RFC);
6415 adapter->stats.rjc += rd32(E1000_RJC);
6416 adapter->stats.tor += rd32(E1000_TORH);
6417 adapter->stats.tot += rd32(E1000_TOTH);
6418 adapter->stats.tpr += rd32(E1000_TPR);
6420 adapter->stats.ptc64 += rd32(E1000_PTC64);
6421 adapter->stats.ptc127 += rd32(E1000_PTC127);
6422 adapter->stats.ptc255 += rd32(E1000_PTC255);
6423 adapter->stats.ptc511 += rd32(E1000_PTC511);
6424 adapter->stats.ptc1023 += rd32(E1000_PTC1023);
6425 adapter->stats.ptc1522 += rd32(E1000_PTC1522);
6427 adapter->stats.mptc += rd32(E1000_MPTC);
6428 adapter->stats.bptc += rd32(E1000_BPTC);
6430 adapter->stats.tpt += rd32(E1000_TPT);
6431 adapter->stats.colc += rd32(E1000_COLC);
6433 adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
6434 /* read internal phy specific stats */
6435 reg = rd32(E1000_CTRL_EXT);
6436 if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {
6437 adapter->stats.rxerrc += rd32(E1000_RXERRC);
6439 /* this stat has invalid values on i210/i211 */
6440 if ((hw->mac.type != e1000_i210) &&
6441 (hw->mac.type != e1000_i211))
6442 adapter->stats.tncrs += rd32(E1000_TNCRS);
6445 adapter->stats.tsctc += rd32(E1000_TSCTC);
6446 adapter->stats.tsctfc += rd32(E1000_TSCTFC);
6448 adapter->stats.iac += rd32(E1000_IAC);
6449 adapter->stats.icrxoc += rd32(E1000_ICRXOC);
6450 adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
6451 adapter->stats.icrxatc += rd32(E1000_ICRXATC);
6452 adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
6453 adapter->stats.ictxatc += rd32(E1000_ICTXATC);
6454 adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
6455 adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
6456 adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
6458 /* Fill out the OS statistics structure */
6459 net_stats->multicast = adapter->stats.mprc;
6460 net_stats->collisions = adapter->stats.colc;
6464 /* RLEC on some newer hardware can be incorrect so build
6465 * our own version based on RUC and ROC
6467 net_stats->rx_errors = adapter->stats.rxerrc +
6468 adapter->stats.crcerrs + adapter->stats.algnerrc +
6469 adapter->stats.ruc + adapter->stats.roc +
6470 adapter->stats.cexterr;
6471 net_stats->rx_length_errors = adapter->stats.ruc +
6473 net_stats->rx_crc_errors = adapter->stats.crcerrs;
6474 net_stats->rx_frame_errors = adapter->stats.algnerrc;
6475 net_stats->rx_missed_errors = adapter->stats.mpc;
6478 net_stats->tx_errors = adapter->stats.ecol +
6479 adapter->stats.latecol;
6480 net_stats->tx_aborted_errors = adapter->stats.ecol;
6481 net_stats->tx_window_errors = adapter->stats.latecol;
6482 net_stats->tx_carrier_errors = adapter->stats.tncrs;
6484 /* Tx Dropped needs to be maintained elsewhere */
6486 /* Management Stats */
6487 adapter->stats.mgptc += rd32(E1000_MGTPTC);
6488 adapter->stats.mgprc += rd32(E1000_MGTPRC);
6489 adapter->stats.mgpdc += rd32(E1000_MGTPDC);
6492 reg = rd32(E1000_MANC);
6493 if (reg & E1000_MANC_EN_BMC2OS) {
6494 adapter->stats.o2bgptc += rd32(E1000_O2BGPTC);
6495 adapter->stats.o2bspc += rd32(E1000_O2BSPC);
6496 adapter->stats.b2ospc += rd32(E1000_B2OSPC);
6497 adapter->stats.b2ogprc += rd32(E1000_B2OGPRC);
6501 static void igb_tsync_interrupt(struct igb_adapter *adapter)
6503 struct e1000_hw *hw = &adapter->hw;
6504 struct ptp_clock_event event;
6505 struct timespec64 ts;
6506 u32 ack = 0, tsauxc, sec, nsec, tsicr = rd32(E1000_TSICR);
6508 if (tsicr & TSINTR_SYS_WRAP) {
6509 event.type = PTP_CLOCK_PPS;
6510 if (adapter->ptp_caps.pps)
6511 ptp_clock_event(adapter->ptp_clock, &event);
6512 ack |= TSINTR_SYS_WRAP;
6515 if (tsicr & E1000_TSICR_TXTS) {
6516 /* retrieve hardware timestamp */
6517 schedule_work(&adapter->ptp_tx_work);
6518 ack |= E1000_TSICR_TXTS;
6521 if (tsicr & TSINTR_TT0) {
6522 spin_lock(&adapter->tmreg_lock);
6523 ts = timespec64_add(adapter->perout[0].start,
6524 adapter->perout[0].period);
6525 /* u32 conversion of tv_sec is safe until y2106 */
6526 wr32(E1000_TRGTTIML0, ts.tv_nsec);
6527 wr32(E1000_TRGTTIMH0, (u32)ts.tv_sec);
6528 tsauxc = rd32(E1000_TSAUXC);
6529 tsauxc |= TSAUXC_EN_TT0;
6530 wr32(E1000_TSAUXC, tsauxc);
6531 adapter->perout[0].start = ts;
6532 spin_unlock(&adapter->tmreg_lock);
6536 if (tsicr & TSINTR_TT1) {
6537 spin_lock(&adapter->tmreg_lock);
6538 ts = timespec64_add(adapter->perout[1].start,
6539 adapter->perout[1].period);
6540 wr32(E1000_TRGTTIML1, ts.tv_nsec);
6541 wr32(E1000_TRGTTIMH1, (u32)ts.tv_sec);
6542 tsauxc = rd32(E1000_TSAUXC);
6543 tsauxc |= TSAUXC_EN_TT1;
6544 wr32(E1000_TSAUXC, tsauxc);
6545 adapter->perout[1].start = ts;
6546 spin_unlock(&adapter->tmreg_lock);
6550 if (tsicr & TSINTR_AUTT0) {
6551 nsec = rd32(E1000_AUXSTMPL0);
6552 sec = rd32(E1000_AUXSTMPH0);
6553 event.type = PTP_CLOCK_EXTTS;
6555 event.timestamp = sec * 1000000000ULL + nsec;
6556 ptp_clock_event(adapter->ptp_clock, &event);
6557 ack |= TSINTR_AUTT0;
6560 if (tsicr & TSINTR_AUTT1) {
6561 nsec = rd32(E1000_AUXSTMPL1);
6562 sec = rd32(E1000_AUXSTMPH1);
6563 event.type = PTP_CLOCK_EXTTS;
6565 event.timestamp = sec * 1000000000ULL + nsec;
6566 ptp_clock_event(adapter->ptp_clock, &event);
6567 ack |= TSINTR_AUTT1;
6570 /* acknowledge the interrupts */
6571 wr32(E1000_TSICR, ack);
6574 static irqreturn_t igb_msix_other(int irq, void *data)
6576 struct igb_adapter *adapter = data;
6577 struct e1000_hw *hw = &adapter->hw;
6578 u32 icr = rd32(E1000_ICR);
6579 /* reading ICR causes bit 31 of EICR to be cleared */
6581 if (icr & E1000_ICR_DRSTA)
6582 schedule_work(&adapter->reset_task);
6584 if (icr & E1000_ICR_DOUTSYNC) {
6585 /* HW is reporting DMA is out of sync */
6586 adapter->stats.doosync++;
6587 /* The DMA Out of Sync is also indication of a spoof event
6588 * in IOV mode. Check the Wrong VM Behavior register to
6589 * see if it is really a spoof event.
6591 igb_check_wvbr(adapter);
6594 /* Check for a mailbox event */
6595 if (icr & E1000_ICR_VMMB)
6596 igb_msg_task(adapter);
6598 if (icr & E1000_ICR_LSC) {
6599 hw->mac.get_link_status = 1;
6600 /* guard against interrupt when we're going down */
6601 if (!test_bit(__IGB_DOWN, &adapter->state))
6602 mod_timer(&adapter->watchdog_timer, jiffies + 1);
6605 if (icr & E1000_ICR_TS)
6606 igb_tsync_interrupt(adapter);
6608 wr32(E1000_EIMS, adapter->eims_other);
6613 static void igb_write_itr(struct igb_q_vector *q_vector)
6615 struct igb_adapter *adapter = q_vector->adapter;
6616 u32 itr_val = q_vector->itr_val & 0x7FFC;
6618 if (!q_vector->set_itr)
6624 if (adapter->hw.mac.type == e1000_82575)
6625 itr_val |= itr_val << 16;
6627 itr_val |= E1000_EITR_CNT_IGNR;
6629 writel(itr_val, q_vector->itr_register);
6630 q_vector->set_itr = 0;
6633 static irqreturn_t igb_msix_ring(int irq, void *data)
6635 struct igb_q_vector *q_vector = data;
6637 /* Write the ITR value calculated from the previous interrupt. */
6638 igb_write_itr(q_vector);
6640 napi_schedule(&q_vector->napi);
6645 #ifdef CONFIG_IGB_DCA
6646 static void igb_update_tx_dca(struct igb_adapter *adapter,
6647 struct igb_ring *tx_ring,
6650 struct e1000_hw *hw = &adapter->hw;
6651 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
6653 if (hw->mac.type != e1000_82575)
6654 txctrl <<= E1000_DCA_TXCTRL_CPUID_SHIFT;
6656 /* We can enable relaxed ordering for reads, but not writes when
6657 * DCA is enabled. This is due to a known issue in some chipsets
6658 * which will cause the DCA tag to be cleared.
6660 txctrl |= E1000_DCA_TXCTRL_DESC_RRO_EN |
6661 E1000_DCA_TXCTRL_DATA_RRO_EN |
6662 E1000_DCA_TXCTRL_DESC_DCA_EN;
6664 wr32(E1000_DCA_TXCTRL(tx_ring->reg_idx), txctrl);
6667 static void igb_update_rx_dca(struct igb_adapter *adapter,
6668 struct igb_ring *rx_ring,
6671 struct e1000_hw *hw = &adapter->hw;
6672 u32 rxctrl = dca3_get_tag(&adapter->pdev->dev, cpu);
6674 if (hw->mac.type != e1000_82575)
6675 rxctrl <<= E1000_DCA_RXCTRL_CPUID_SHIFT;
6677 /* We can enable relaxed ordering for reads, but not writes when
6678 * DCA is enabled. This is due to a known issue in some chipsets
6679 * which will cause the DCA tag to be cleared.
6681 rxctrl |= E1000_DCA_RXCTRL_DESC_RRO_EN |
6682 E1000_DCA_RXCTRL_DESC_DCA_EN;
6684 wr32(E1000_DCA_RXCTRL(rx_ring->reg_idx), rxctrl);
6687 static void igb_update_dca(struct igb_q_vector *q_vector)
6689 struct igb_adapter *adapter = q_vector->adapter;
6690 int cpu = get_cpu();
6692 if (q_vector->cpu == cpu)
6695 if (q_vector->tx.ring)
6696 igb_update_tx_dca(adapter, q_vector->tx.ring, cpu);
6698 if (q_vector->rx.ring)
6699 igb_update_rx_dca(adapter, q_vector->rx.ring, cpu);
6701 q_vector->cpu = cpu;
6706 static void igb_setup_dca(struct igb_adapter *adapter)
6708 struct e1000_hw *hw = &adapter->hw;
6711 if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
6714 /* Always use CB2 mode, difference is masked in the CB driver. */
6715 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
6717 for (i = 0; i < adapter->num_q_vectors; i++) {
6718 adapter->q_vector[i]->cpu = -1;
6719 igb_update_dca(adapter->q_vector[i]);
6723 static int __igb_notify_dca(struct device *dev, void *data)
6725 struct net_device *netdev = dev_get_drvdata(dev);
6726 struct igb_adapter *adapter = netdev_priv(netdev);
6727 struct pci_dev *pdev = adapter->pdev;
6728 struct e1000_hw *hw = &adapter->hw;
6729 unsigned long event = *(unsigned long *)data;
6732 case DCA_PROVIDER_ADD:
6733 /* if already enabled, don't do it again */
6734 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
6736 if (dca_add_requester(dev) == 0) {
6737 adapter->flags |= IGB_FLAG_DCA_ENABLED;
6738 dev_info(&pdev->dev, "DCA enabled\n");
6739 igb_setup_dca(adapter);
6742 /* Fall Through since DCA is disabled. */
6743 case DCA_PROVIDER_REMOVE:
6744 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
6745 /* without this a class_device is left
6746 * hanging around in the sysfs model
6748 dca_remove_requester(dev);
6749 dev_info(&pdev->dev, "DCA disabled\n");
6750 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
6751 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
6759 static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
6764 ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
6767 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
6769 #endif /* CONFIG_IGB_DCA */
6771 #ifdef CONFIG_PCI_IOV
6772 static int igb_vf_configure(struct igb_adapter *adapter, int vf)
6774 unsigned char mac_addr[ETH_ALEN];
6776 eth_zero_addr(mac_addr);
6777 igb_set_vf_mac(adapter, vf, mac_addr);
6779 /* By default spoof check is enabled for all VFs */
6780 adapter->vf_data[vf].spoofchk_enabled = true;
6782 /* By default VFs are not trusted */
6783 adapter->vf_data[vf].trusted = false;
6789 static void igb_ping_all_vfs(struct igb_adapter *adapter)
6791 struct e1000_hw *hw = &adapter->hw;
6795 for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
6796 ping = E1000_PF_CONTROL_MSG;
6797 if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
6798 ping |= E1000_VT_MSGTYPE_CTS;
6799 igb_write_mbx(hw, &ping, 1, i);
6803 static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
6805 struct e1000_hw *hw = &adapter->hw;
6806 u32 vmolr = rd32(E1000_VMOLR(vf));
6807 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6809 vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC |
6810 IGB_VF_FLAG_MULTI_PROMISC);
6811 vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
6813 if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) {
6814 vmolr |= E1000_VMOLR_MPME;
6815 vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC;
6816 *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST;
6818 /* if we have hashes and we are clearing a multicast promisc
6819 * flag we need to write the hashes to the MTA as this step
6820 * was previously skipped
6822 if (vf_data->num_vf_mc_hashes > 30) {
6823 vmolr |= E1000_VMOLR_MPME;
6824 } else if (vf_data->num_vf_mc_hashes) {
6827 vmolr |= E1000_VMOLR_ROMPE;
6828 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
6829 igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
6833 wr32(E1000_VMOLR(vf), vmolr);
6835 /* there are flags left unprocessed, likely not supported */
6836 if (*msgbuf & E1000_VT_MSGINFO_MASK)
6842 static int igb_set_vf_multicasts(struct igb_adapter *adapter,
6843 u32 *msgbuf, u32 vf)
6845 int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
6846 u16 *hash_list = (u16 *)&msgbuf[1];
6847 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6850 /* salt away the number of multicast addresses assigned
6851 * to this VF for later use to restore when the PF multi cast
6854 vf_data->num_vf_mc_hashes = n;
6856 /* only up to 30 hash values supported */
6860 /* store the hashes for later use */
6861 for (i = 0; i < n; i++)
6862 vf_data->vf_mc_hashes[i] = hash_list[i];
6864 /* Flush and reset the mta with the new values */
6865 igb_set_rx_mode(adapter->netdev);
6870 static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
6872 struct e1000_hw *hw = &adapter->hw;
6873 struct vf_data_storage *vf_data;
6876 for (i = 0; i < adapter->vfs_allocated_count; i++) {
6877 u32 vmolr = rd32(E1000_VMOLR(i));
6879 vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
6881 vf_data = &adapter->vf_data[i];
6883 if ((vf_data->num_vf_mc_hashes > 30) ||
6884 (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) {
6885 vmolr |= E1000_VMOLR_MPME;
6886 } else if (vf_data->num_vf_mc_hashes) {
6887 vmolr |= E1000_VMOLR_ROMPE;
6888 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
6889 igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
6891 wr32(E1000_VMOLR(i), vmolr);
6895 static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
6897 struct e1000_hw *hw = &adapter->hw;
6898 u32 pool_mask, vlvf_mask, i;
6900 /* create mask for VF and other pools */
6901 pool_mask = E1000_VLVF_POOLSEL_MASK;
6902 vlvf_mask = BIT(E1000_VLVF_POOLSEL_SHIFT + vf);
6904 /* drop PF from pool bits */
6905 pool_mask &= ~BIT(E1000_VLVF_POOLSEL_SHIFT +
6906 adapter->vfs_allocated_count);
6908 /* Find the vlan filter for this id */
6909 for (i = E1000_VLVF_ARRAY_SIZE; i--;) {
6910 u32 vlvf = rd32(E1000_VLVF(i));
6911 u32 vfta_mask, vid, vfta;
6913 /* remove the vf from the pool */
6914 if (!(vlvf & vlvf_mask))
6917 /* clear out bit from VLVF */
6920 /* if other pools are present, just remove ourselves */
6921 if (vlvf & pool_mask)
6924 /* if PF is present, leave VFTA */
6925 if (vlvf & E1000_VLVF_POOLSEL_MASK)
6928 vid = vlvf & E1000_VLVF_VLANID_MASK;
6929 vfta_mask = BIT(vid % 32);
6931 /* clear bit from VFTA */
6932 vfta = adapter->shadow_vfta[vid / 32];
6933 if (vfta & vfta_mask)
6934 hw->mac.ops.write_vfta(hw, vid / 32, vfta ^ vfta_mask);
6936 /* clear pool selection enable */
6937 if (adapter->flags & IGB_FLAG_VLAN_PROMISC)
6938 vlvf &= E1000_VLVF_POOLSEL_MASK;
6942 /* clear pool bits */
6943 wr32(E1000_VLVF(i), vlvf);
6947 static int igb_find_vlvf_entry(struct e1000_hw *hw, u32 vlan)
6952 /* short cut the special case */
6956 /* Search for the VLAN id in the VLVF entries */
6957 for (idx = E1000_VLVF_ARRAY_SIZE; --idx;) {
6958 vlvf = rd32(E1000_VLVF(idx));
6959 if ((vlvf & VLAN_VID_MASK) == vlan)
6966 static void igb_update_pf_vlvf(struct igb_adapter *adapter, u32 vid)
6968 struct e1000_hw *hw = &adapter->hw;
6972 idx = igb_find_vlvf_entry(hw, vid);
6976 /* See if any other pools are set for this VLAN filter
6977 * entry other than the PF.
6979 pf_id = adapter->vfs_allocated_count + E1000_VLVF_POOLSEL_SHIFT;
6980 bits = ~BIT(pf_id) & E1000_VLVF_POOLSEL_MASK;
6981 bits &= rd32(E1000_VLVF(idx));
6983 /* Disable the filter so this falls into the default pool. */
6985 if (adapter->flags & IGB_FLAG_VLAN_PROMISC)
6986 wr32(E1000_VLVF(idx), BIT(pf_id));
6988 wr32(E1000_VLVF(idx), 0);
6992 static s32 igb_set_vf_vlan(struct igb_adapter *adapter, u32 vid,
6995 int pf_id = adapter->vfs_allocated_count;
6996 struct e1000_hw *hw = &adapter->hw;
6999 /* If VLAN overlaps with one the PF is currently monitoring make
7000 * sure that we are able to allocate a VLVF entry. This may be
7001 * redundant but it guarantees PF will maintain visibility to
7004 if (add && test_bit(vid, adapter->active_vlans)) {
7005 err = igb_vfta_set(hw, vid, pf_id, true, false);
7010 err = igb_vfta_set(hw, vid, vf, add, false);
7015 /* If we failed to add the VF VLAN or we are removing the VF VLAN
7016 * we may need to drop the PF pool bit in order to allow us to free
7017 * up the VLVF resources.
7019 if (test_bit(vid, adapter->active_vlans) ||
7020 (adapter->flags & IGB_FLAG_VLAN_PROMISC))
7021 igb_update_pf_vlvf(adapter, vid);
7026 static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf)
7028 struct e1000_hw *hw = &adapter->hw;
7031 wr32(E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT));
7033 wr32(E1000_VMVIR(vf), 0);
7036 static int igb_enable_port_vlan(struct igb_adapter *adapter, int vf,
7041 err = igb_set_vf_vlan(adapter, vlan, true, vf);
7045 igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
7046 igb_set_vmolr(adapter, vf, !vlan);
7048 /* revoke access to previous VLAN */
7049 if (vlan != adapter->vf_data[vf].pf_vlan)
7050 igb_set_vf_vlan(adapter, adapter->vf_data[vf].pf_vlan,
7053 adapter->vf_data[vf].pf_vlan = vlan;
7054 adapter->vf_data[vf].pf_qos = qos;
7055 igb_set_vf_vlan_strip(adapter, vf, true);
7056 dev_info(&adapter->pdev->dev,
7057 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
7058 if (test_bit(__IGB_DOWN, &adapter->state)) {
7059 dev_warn(&adapter->pdev->dev,
7060 "The VF VLAN has been set, but the PF device is not up.\n");
7061 dev_warn(&adapter->pdev->dev,
7062 "Bring the PF device up before attempting to use the VF device.\n");
7068 static int igb_disable_port_vlan(struct igb_adapter *adapter, int vf)
7070 /* Restore tagless access via VLAN 0 */
7071 igb_set_vf_vlan(adapter, 0, true, vf);
7073 igb_set_vmvir(adapter, 0, vf);
7074 igb_set_vmolr(adapter, vf, true);
7076 /* Remove any PF assigned VLAN */
7077 if (adapter->vf_data[vf].pf_vlan)
7078 igb_set_vf_vlan(adapter, adapter->vf_data[vf].pf_vlan,
7081 adapter->vf_data[vf].pf_vlan = 0;
7082 adapter->vf_data[vf].pf_qos = 0;
7083 igb_set_vf_vlan_strip(adapter, vf, false);
7088 static int igb_ndo_set_vf_vlan(struct net_device *netdev, int vf,
7089 u16 vlan, u8 qos, __be16 vlan_proto)
7091 struct igb_adapter *adapter = netdev_priv(netdev);
7093 if ((vf >= adapter->vfs_allocated_count) || (vlan > 4095) || (qos > 7))
7096 if (vlan_proto != htons(ETH_P_8021Q))
7097 return -EPROTONOSUPPORT;
7099 return (vlan || qos) ? igb_enable_port_vlan(adapter, vf, vlan, qos) :
7100 igb_disable_port_vlan(adapter, vf);
7103 static int igb_set_vf_vlan_msg(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
7105 int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
7106 int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
7109 if (adapter->vf_data[vf].pf_vlan)
7112 /* VLAN 0 is a special case, don't allow it to be removed */
7116 ret = igb_set_vf_vlan(adapter, vid, !!add, vf);
7118 igb_set_vf_vlan_strip(adapter, vf, !!vid);
7122 static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf)
7124 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
7126 /* clear flags - except flag that indicates PF has set the MAC */
7127 vf_data->flags &= IGB_VF_FLAG_PF_SET_MAC;
7128 vf_data->last_nack = jiffies;
7130 /* reset vlans for device */
7131 igb_clear_vf_vfta(adapter, vf);
7132 igb_set_vf_vlan(adapter, vf_data->pf_vlan, true, vf);
7133 igb_set_vmvir(adapter, vf_data->pf_vlan |
7134 (vf_data->pf_qos << VLAN_PRIO_SHIFT), vf);
7135 igb_set_vmolr(adapter, vf, !vf_data->pf_vlan);
7136 igb_set_vf_vlan_strip(adapter, vf, !!(vf_data->pf_vlan));
7138 /* reset multicast table array for vf */
7139 adapter->vf_data[vf].num_vf_mc_hashes = 0;
7141 /* Flush and reset the mta with the new values */
7142 igb_set_rx_mode(adapter->netdev);
7145 static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
7147 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
7149 /* clear mac address as we were hotplug removed/added */
7150 if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC))
7151 eth_zero_addr(vf_mac);
7153 /* process remaining reset events */
7154 igb_vf_reset(adapter, vf);
7157 static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
7159 struct e1000_hw *hw = &adapter->hw;
7160 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
7162 u8 *addr = (u8 *)(&msgbuf[1]);
7164 /* process all the same items cleared in a function level reset */
7165 igb_vf_reset(adapter, vf);
7167 /* set vf mac address */
7168 igb_set_vf_mac(adapter, vf, vf_mac);
7170 /* enable transmit and receive for vf */
7171 reg = rd32(E1000_VFTE);
7172 wr32(E1000_VFTE, reg | BIT(vf));
7173 reg = rd32(E1000_VFRE);
7174 wr32(E1000_VFRE, reg | BIT(vf));
7176 adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS;
7178 /* reply to reset with ack and vf mac address */
7179 if (!is_zero_ether_addr(vf_mac)) {
7180 msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
7181 memcpy(addr, vf_mac, ETH_ALEN);
7183 msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_NACK;
7185 igb_write_mbx(hw, msgbuf, 3, vf);
7188 static void igb_flush_mac_table(struct igb_adapter *adapter)
7190 struct e1000_hw *hw = &adapter->hw;
7193 for (i = 0; i < hw->mac.rar_entry_count; i++) {
7194 adapter->mac_table[i].state &= ~IGB_MAC_STATE_IN_USE;
7195 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
7196 adapter->mac_table[i].queue = 0;
7197 igb_rar_set_index(adapter, i);
7201 static int igb_available_rars(struct igb_adapter *adapter, u8 queue)
7203 struct e1000_hw *hw = &adapter->hw;
7204 /* do not count rar entries reserved for VFs MAC addresses */
7205 int rar_entries = hw->mac.rar_entry_count -
7206 adapter->vfs_allocated_count;
7209 for (i = 0; i < rar_entries; i++) {
7210 /* do not count default entries */
7211 if (adapter->mac_table[i].state & IGB_MAC_STATE_DEFAULT)
7214 /* do not count "in use" entries for different queues */
7215 if ((adapter->mac_table[i].state & IGB_MAC_STATE_IN_USE) &&
7216 (adapter->mac_table[i].queue != queue))
7225 /* Set default MAC address for the PF in the first RAR entry */
7226 static void igb_set_default_mac_filter(struct igb_adapter *adapter)
7228 struct igb_mac_addr *mac_table = &adapter->mac_table[0];
7230 ether_addr_copy(mac_table->addr, adapter->hw.mac.addr);
7231 mac_table->queue = adapter->vfs_allocated_count;
7232 mac_table->state = IGB_MAC_STATE_DEFAULT | IGB_MAC_STATE_IN_USE;
7234 igb_rar_set_index(adapter, 0);
7237 /* If the filter to be added and an already existing filter express
7238 * the same address and address type, it should be possible to only
7239 * override the other configurations, for example the queue to steer
7242 static bool igb_mac_entry_can_be_used(const struct igb_mac_addr *entry,
7243 const u8 *addr, const u8 flags)
7245 if (!(entry->state & IGB_MAC_STATE_IN_USE))
7248 if ((entry->state & IGB_MAC_STATE_SRC_ADDR) !=
7249 (flags & IGB_MAC_STATE_SRC_ADDR))
7252 if (!ether_addr_equal(addr, entry->addr))
7258 /* Add a MAC filter for 'addr' directing matching traffic to 'queue',
7259 * 'flags' is used to indicate what kind of match is made, match is by
7260 * default for the destination address, if matching by source address
7261 * is desired the flag IGB_MAC_STATE_SRC_ADDR can be used.
7263 static int igb_add_mac_filter_flags(struct igb_adapter *adapter,
7264 const u8 *addr, const u8 queue,
7267 struct e1000_hw *hw = &adapter->hw;
7268 int rar_entries = hw->mac.rar_entry_count -
7269 adapter->vfs_allocated_count;
7272 if (is_zero_ether_addr(addr))
7275 /* Search for the first empty entry in the MAC table.
7276 * Do not touch entries at the end of the table reserved for the VF MAC
7279 for (i = 0; i < rar_entries; i++) {
7280 if (!igb_mac_entry_can_be_used(&adapter->mac_table[i],
7284 ether_addr_copy(adapter->mac_table[i].addr, addr);
7285 adapter->mac_table[i].queue = queue;
7286 adapter->mac_table[i].state |= IGB_MAC_STATE_IN_USE | flags;
7288 igb_rar_set_index(adapter, i);
7295 static int igb_add_mac_filter(struct igb_adapter *adapter, const u8 *addr,
7298 return igb_add_mac_filter_flags(adapter, addr, queue, 0);
7301 /* Remove a MAC filter for 'addr' directing matching traffic to
7302 * 'queue', 'flags' is used to indicate what kind of match need to be
7303 * removed, match is by default for the destination address, if
7304 * matching by source address is to be removed the flag
7305 * IGB_MAC_STATE_SRC_ADDR can be used.
7307 static int igb_del_mac_filter_flags(struct igb_adapter *adapter,
7308 const u8 *addr, const u8 queue,
7311 struct e1000_hw *hw = &adapter->hw;
7312 int rar_entries = hw->mac.rar_entry_count -
7313 adapter->vfs_allocated_count;
7316 if (is_zero_ether_addr(addr))
7319 /* Search for matching entry in the MAC table based on given address
7320 * and queue. Do not touch entries at the end of the table reserved
7321 * for the VF MAC addresses.
7323 for (i = 0; i < rar_entries; i++) {
7324 if (!(adapter->mac_table[i].state & IGB_MAC_STATE_IN_USE))
7326 if ((adapter->mac_table[i].state & flags) != flags)
7328 if (adapter->mac_table[i].queue != queue)
7330 if (!ether_addr_equal(adapter->mac_table[i].addr, addr))
7333 /* When a filter for the default address is "deleted",
7334 * we return it to its initial configuration
7336 if (adapter->mac_table[i].state & IGB_MAC_STATE_DEFAULT) {
7337 adapter->mac_table[i].state =
7338 IGB_MAC_STATE_DEFAULT | IGB_MAC_STATE_IN_USE;
7339 adapter->mac_table[i].queue =
7340 adapter->vfs_allocated_count;
7342 adapter->mac_table[i].state = 0;
7343 adapter->mac_table[i].queue = 0;
7344 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
7347 igb_rar_set_index(adapter, i);
7354 static int igb_del_mac_filter(struct igb_adapter *adapter, const u8 *addr,
7357 return igb_del_mac_filter_flags(adapter, addr, queue, 0);
7360 int igb_add_mac_steering_filter(struct igb_adapter *adapter,
7361 const u8 *addr, u8 queue, u8 flags)
7363 struct e1000_hw *hw = &adapter->hw;
7365 /* In theory, this should be supported on 82575 as well, but
7366 * that part wasn't easily accessible during development.
7368 if (hw->mac.type != e1000_i210)
7371 return igb_add_mac_filter_flags(adapter, addr, queue,
7372 IGB_MAC_STATE_QUEUE_STEERING | flags);
7375 int igb_del_mac_steering_filter(struct igb_adapter *adapter,
7376 const u8 *addr, u8 queue, u8 flags)
7378 return igb_del_mac_filter_flags(adapter, addr, queue,
7379 IGB_MAC_STATE_QUEUE_STEERING | flags);
7382 static int igb_uc_sync(struct net_device *netdev, const unsigned char *addr)
7384 struct igb_adapter *adapter = netdev_priv(netdev);
7387 ret = igb_add_mac_filter(adapter, addr, adapter->vfs_allocated_count);
7389 return min_t(int, ret, 0);
7392 static int igb_uc_unsync(struct net_device *netdev, const unsigned char *addr)
7394 struct igb_adapter *adapter = netdev_priv(netdev);
7396 igb_del_mac_filter(adapter, addr, adapter->vfs_allocated_count);
7401 static int igb_set_vf_mac_filter(struct igb_adapter *adapter, const int vf,
7402 const u32 info, const u8 *addr)
7404 struct pci_dev *pdev = adapter->pdev;
7405 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
7406 struct list_head *pos;
7407 struct vf_mac_filter *entry = NULL;
7410 if ((vf_data->flags & IGB_VF_FLAG_PF_SET_MAC) &&
7411 !vf_data->trusted) {
7412 dev_warn(&pdev->dev,
7413 "VF %d requested MAC filter but is administratively denied\n",
7417 if (!is_valid_ether_addr(addr)) {
7418 dev_warn(&pdev->dev,
7419 "VF %d attempted to set invalid MAC filter\n",
7425 case E1000_VF_MAC_FILTER_CLR:
7426 /* remove all unicast MAC filters related to the current VF */
7427 list_for_each(pos, &adapter->vf_macs.l) {
7428 entry = list_entry(pos, struct vf_mac_filter, l);
7429 if (entry->vf == vf) {
7432 igb_del_mac_filter(adapter, entry->vf_mac, vf);
7436 case E1000_VF_MAC_FILTER_ADD:
7437 /* try to find empty slot in the list */
7438 list_for_each(pos, &adapter->vf_macs.l) {
7439 entry = list_entry(pos, struct vf_mac_filter, l);
7444 if (entry && entry->free) {
7445 entry->free = false;
7447 ether_addr_copy(entry->vf_mac, addr);
7449 ret = igb_add_mac_filter(adapter, addr, vf);
7450 ret = min_t(int, ret, 0);
7456 dev_warn(&pdev->dev,
7457 "VF %d has requested MAC filter but there is no space for it\n",
7468 static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
7470 struct pci_dev *pdev = adapter->pdev;
7471 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
7472 u32 info = msg[0] & E1000_VT_MSGINFO_MASK;
7474 /* The VF MAC Address is stored in a packed array of bytes
7475 * starting at the second 32 bit word of the msg array
7477 unsigned char *addr = (unsigned char *)&msg[1];
7481 if ((vf_data->flags & IGB_VF_FLAG_PF_SET_MAC) &&
7482 !vf_data->trusted) {
7483 dev_warn(&pdev->dev,
7484 "VF %d attempted to override administratively set MAC address\nReload the VF driver to resume operations\n",
7489 if (!is_valid_ether_addr(addr)) {
7490 dev_warn(&pdev->dev,
7491 "VF %d attempted to set invalid MAC\n",
7496 ret = igb_set_vf_mac(adapter, vf, addr);
7498 ret = igb_set_vf_mac_filter(adapter, vf, info, addr);
7504 static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
7506 struct e1000_hw *hw = &adapter->hw;
7507 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
7508 u32 msg = E1000_VT_MSGTYPE_NACK;
7510 /* if device isn't clear to send it shouldn't be reading either */
7511 if (!(vf_data->flags & IGB_VF_FLAG_CTS) &&
7512 time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
7513 igb_write_mbx(hw, &msg, 1, vf);
7514 vf_data->last_nack = jiffies;
7518 static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
7520 struct pci_dev *pdev = adapter->pdev;
7521 u32 msgbuf[E1000_VFMAILBOX_SIZE];
7522 struct e1000_hw *hw = &adapter->hw;
7523 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
7526 retval = igb_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf, false);
7529 /* if receive failed revoke VF CTS stats and restart init */
7530 dev_err(&pdev->dev, "Error receiving message from VF\n");
7531 vf_data->flags &= ~IGB_VF_FLAG_CTS;
7532 if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
7537 /* this is a message we already processed, do nothing */
7538 if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
7541 /* until the vf completes a reset it should not be
7542 * allowed to start any configuration.
7544 if (msgbuf[0] == E1000_VF_RESET) {
7545 /* unlocks mailbox */
7546 igb_vf_reset_msg(adapter, vf);
7550 if (!(vf_data->flags & IGB_VF_FLAG_CTS)) {
7551 if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
7557 switch ((msgbuf[0] & 0xFFFF)) {
7558 case E1000_VF_SET_MAC_ADDR:
7559 retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
7561 case E1000_VF_SET_PROMISC:
7562 retval = igb_set_vf_promisc(adapter, msgbuf, vf);
7564 case E1000_VF_SET_MULTICAST:
7565 retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
7567 case E1000_VF_SET_LPE:
7568 retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
7570 case E1000_VF_SET_VLAN:
7572 if (vf_data->pf_vlan)
7573 dev_warn(&pdev->dev,
7574 "VF %d attempted to override administratively set VLAN tag\nReload the VF driver to resume operations\n",
7577 retval = igb_set_vf_vlan_msg(adapter, msgbuf, vf);
7580 dev_err(&pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]);
7585 msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
7587 /* notify the VF of the results of what it sent us */
7589 msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
7591 msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
7593 /* unlocks mailbox */
7594 igb_write_mbx(hw, msgbuf, 1, vf);
7598 igb_unlock_mbx(hw, vf);
7601 static void igb_msg_task(struct igb_adapter *adapter)
7603 struct e1000_hw *hw = &adapter->hw;
7606 for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
7607 /* process any reset requests */
7608 if (!igb_check_for_rst(hw, vf))
7609 igb_vf_reset_event(adapter, vf);
7611 /* process any messages pending */
7612 if (!igb_check_for_msg(hw, vf))
7613 igb_rcv_msg_from_vf(adapter, vf);
7615 /* process any acks */
7616 if (!igb_check_for_ack(hw, vf))
7617 igb_rcv_ack_from_vf(adapter, vf);
7622 * igb_set_uta - Set unicast filter table address
7623 * @adapter: board private structure
7624 * @set: boolean indicating if we are setting or clearing bits
7626 * The unicast table address is a register array of 32-bit registers.
7627 * The table is meant to be used in a way similar to how the MTA is used
7628 * however due to certain limitations in the hardware it is necessary to
7629 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
7630 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
7632 static void igb_set_uta(struct igb_adapter *adapter, bool set)
7634 struct e1000_hw *hw = &adapter->hw;
7635 u32 uta = set ? ~0 : 0;
7638 /* we only need to do this if VMDq is enabled */
7639 if (!adapter->vfs_allocated_count)
7642 for (i = hw->mac.uta_reg_count; i--;)
7643 array_wr32(E1000_UTA, i, uta);
7647 * igb_intr_msi - Interrupt Handler
7648 * @irq: interrupt number
7649 * @data: pointer to a network interface device structure
7651 static irqreturn_t igb_intr_msi(int irq, void *data)
7653 struct igb_adapter *adapter = data;
7654 struct igb_q_vector *q_vector = adapter->q_vector[0];
7655 struct e1000_hw *hw = &adapter->hw;
7656 /* read ICR disables interrupts using IAM */
7657 u32 icr = rd32(E1000_ICR);
7659 igb_write_itr(q_vector);
7661 if (icr & E1000_ICR_DRSTA)
7662 schedule_work(&adapter->reset_task);
7664 if (icr & E1000_ICR_DOUTSYNC) {
7665 /* HW is reporting DMA is out of sync */
7666 adapter->stats.doosync++;
7669 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
7670 hw->mac.get_link_status = 1;
7671 if (!test_bit(__IGB_DOWN, &adapter->state))
7672 mod_timer(&adapter->watchdog_timer, jiffies + 1);
7675 if (icr & E1000_ICR_TS)
7676 igb_tsync_interrupt(adapter);
7678 napi_schedule(&q_vector->napi);
7684 * igb_intr - Legacy Interrupt Handler
7685 * @irq: interrupt number
7686 * @data: pointer to a network interface device structure
7688 static irqreturn_t igb_intr(int irq, void *data)
7690 struct igb_adapter *adapter = data;
7691 struct igb_q_vector *q_vector = adapter->q_vector[0];
7692 struct e1000_hw *hw = &adapter->hw;
7693 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
7694 * need for the IMC write
7696 u32 icr = rd32(E1000_ICR);
7698 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
7699 * not set, then the adapter didn't send an interrupt
7701 if (!(icr & E1000_ICR_INT_ASSERTED))
7704 igb_write_itr(q_vector);
7706 if (icr & E1000_ICR_DRSTA)
7707 schedule_work(&adapter->reset_task);
7709 if (icr & E1000_ICR_DOUTSYNC) {
7710 /* HW is reporting DMA is out of sync */
7711 adapter->stats.doosync++;
7714 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
7715 hw->mac.get_link_status = 1;
7716 /* guard against interrupt when we're going down */
7717 if (!test_bit(__IGB_DOWN, &adapter->state))
7718 mod_timer(&adapter->watchdog_timer, jiffies + 1);
7721 if (icr & E1000_ICR_TS)
7722 igb_tsync_interrupt(adapter);
7724 napi_schedule(&q_vector->napi);
7729 static void igb_ring_irq_enable(struct igb_q_vector *q_vector)
7731 struct igb_adapter *adapter = q_vector->adapter;
7732 struct e1000_hw *hw = &adapter->hw;
7734 if ((q_vector->rx.ring && (adapter->rx_itr_setting & 3)) ||
7735 (!q_vector->rx.ring && (adapter->tx_itr_setting & 3))) {
7736 if ((adapter->num_q_vectors == 1) && !adapter->vf_data)
7737 igb_set_itr(q_vector);
7739 igb_update_ring_itr(q_vector);
7742 if (!test_bit(__IGB_DOWN, &adapter->state)) {
7743 if (adapter->flags & IGB_FLAG_HAS_MSIX)
7744 wr32(E1000_EIMS, q_vector->eims_value);
7746 igb_irq_enable(adapter);
7751 * igb_poll - NAPI Rx polling callback
7752 * @napi: napi polling structure
7753 * @budget: count of how many packets we should handle
7755 static int igb_poll(struct napi_struct *napi, int budget)
7757 struct igb_q_vector *q_vector = container_of(napi,
7758 struct igb_q_vector,
7760 bool clean_complete = true;
7763 #ifdef CONFIG_IGB_DCA
7764 if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
7765 igb_update_dca(q_vector);
7767 if (q_vector->tx.ring)
7768 clean_complete = igb_clean_tx_irq(q_vector, budget);
7770 if (q_vector->rx.ring) {
7771 int cleaned = igb_clean_rx_irq(q_vector, budget);
7773 work_done += cleaned;
7774 if (cleaned >= budget)
7775 clean_complete = false;
7778 /* If all work not completed, return budget and keep polling */
7779 if (!clean_complete)
7782 /* If not enough Rx work done, exit the polling mode */
7783 napi_complete_done(napi, work_done);
7784 igb_ring_irq_enable(q_vector);
7790 * igb_clean_tx_irq - Reclaim resources after transmit completes
7791 * @q_vector: pointer to q_vector containing needed info
7792 * @napi_budget: Used to determine if we are in netpoll
7794 * returns true if ring is completely cleaned
7796 static bool igb_clean_tx_irq(struct igb_q_vector *q_vector, int napi_budget)
7798 struct igb_adapter *adapter = q_vector->adapter;
7799 struct igb_ring *tx_ring = q_vector->tx.ring;
7800 struct igb_tx_buffer *tx_buffer;
7801 union e1000_adv_tx_desc *tx_desc;
7802 unsigned int total_bytes = 0, total_packets = 0;
7803 unsigned int budget = q_vector->tx.work_limit;
7804 unsigned int i = tx_ring->next_to_clean;
7806 if (test_bit(__IGB_DOWN, &adapter->state))
7809 tx_buffer = &tx_ring->tx_buffer_info[i];
7810 tx_desc = IGB_TX_DESC(tx_ring, i);
7811 i -= tx_ring->count;
7814 union e1000_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
7816 /* if next_to_watch is not set then there is no work pending */
7820 /* prevent any other reads prior to eop_desc */
7823 /* if DD is not set pending work has not been completed */
7824 if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)))
7827 /* clear next_to_watch to prevent false hangs */
7828 tx_buffer->next_to_watch = NULL;
7830 /* update the statistics for this packet */
7831 total_bytes += tx_buffer->bytecount;
7832 total_packets += tx_buffer->gso_segs;
7835 napi_consume_skb(tx_buffer->skb, napi_budget);
7837 /* unmap skb header data */
7838 dma_unmap_single(tx_ring->dev,
7839 dma_unmap_addr(tx_buffer, dma),
7840 dma_unmap_len(tx_buffer, len),
7843 /* clear tx_buffer data */
7844 dma_unmap_len_set(tx_buffer, len, 0);
7846 /* clear last DMA location and unmap remaining buffers */
7847 while (tx_desc != eop_desc) {
7852 i -= tx_ring->count;
7853 tx_buffer = tx_ring->tx_buffer_info;
7854 tx_desc = IGB_TX_DESC(tx_ring, 0);
7857 /* unmap any remaining paged data */
7858 if (dma_unmap_len(tx_buffer, len)) {
7859 dma_unmap_page(tx_ring->dev,
7860 dma_unmap_addr(tx_buffer, dma),
7861 dma_unmap_len(tx_buffer, len),
7863 dma_unmap_len_set(tx_buffer, len, 0);
7867 /* move us one more past the eop_desc for start of next pkt */
7872 i -= tx_ring->count;
7873 tx_buffer = tx_ring->tx_buffer_info;
7874 tx_desc = IGB_TX_DESC(tx_ring, 0);
7877 /* issue prefetch for next Tx descriptor */
7880 /* update budget accounting */
7882 } while (likely(budget));
7884 netdev_tx_completed_queue(txring_txq(tx_ring),
7885 total_packets, total_bytes);
7886 i += tx_ring->count;
7887 tx_ring->next_to_clean = i;
7888 u64_stats_update_begin(&tx_ring->tx_syncp);
7889 tx_ring->tx_stats.bytes += total_bytes;
7890 tx_ring->tx_stats.packets += total_packets;
7891 u64_stats_update_end(&tx_ring->tx_syncp);
7892 q_vector->tx.total_bytes += total_bytes;
7893 q_vector->tx.total_packets += total_packets;
7895 if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags)) {
7896 struct e1000_hw *hw = &adapter->hw;
7898 /* Detect a transmit hang in hardware, this serializes the
7899 * check with the clearing of time_stamp and movement of i
7901 clear_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
7902 if (tx_buffer->next_to_watch &&
7903 time_after(jiffies, tx_buffer->time_stamp +
7904 (adapter->tx_timeout_factor * HZ)) &&
7905 !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) {
7907 /* detected Tx unit hang */
7908 dev_err(tx_ring->dev,
7909 "Detected Tx Unit Hang\n"
7913 " next_to_use <%x>\n"
7914 " next_to_clean <%x>\n"
7915 "buffer_info[next_to_clean]\n"
7916 " time_stamp <%lx>\n"
7917 " next_to_watch <%p>\n"
7919 " desc.status <%x>\n",
7920 tx_ring->queue_index,
7921 rd32(E1000_TDH(tx_ring->reg_idx)),
7922 readl(tx_ring->tail),
7923 tx_ring->next_to_use,
7924 tx_ring->next_to_clean,
7925 tx_buffer->time_stamp,
7926 tx_buffer->next_to_watch,
7928 tx_buffer->next_to_watch->wb.status);
7929 netif_stop_subqueue(tx_ring->netdev,
7930 tx_ring->queue_index);
7932 /* we are about to reset, no point in enabling stuff */
7937 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
7938 if (unlikely(total_packets &&
7939 netif_carrier_ok(tx_ring->netdev) &&
7940 igb_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD)) {
7941 /* Make sure that anybody stopping the queue after this
7942 * sees the new next_to_clean.
7945 if (__netif_subqueue_stopped(tx_ring->netdev,
7946 tx_ring->queue_index) &&
7947 !(test_bit(__IGB_DOWN, &adapter->state))) {
7948 netif_wake_subqueue(tx_ring->netdev,
7949 tx_ring->queue_index);
7951 u64_stats_update_begin(&tx_ring->tx_syncp);
7952 tx_ring->tx_stats.restart_queue++;
7953 u64_stats_update_end(&tx_ring->tx_syncp);
7961 * igb_reuse_rx_page - page flip buffer and store it back on the ring
7962 * @rx_ring: rx descriptor ring to store buffers on
7963 * @old_buff: donor buffer to have page reused
7965 * Synchronizes page for reuse by the adapter
7967 static void igb_reuse_rx_page(struct igb_ring *rx_ring,
7968 struct igb_rx_buffer *old_buff)
7970 struct igb_rx_buffer *new_buff;
7971 u16 nta = rx_ring->next_to_alloc;
7973 new_buff = &rx_ring->rx_buffer_info[nta];
7975 /* update, and store next to alloc */
7977 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
7979 /* Transfer page from old buffer to new buffer.
7980 * Move each member individually to avoid possible store
7981 * forwarding stalls.
7983 new_buff->dma = old_buff->dma;
7984 new_buff->page = old_buff->page;
7985 new_buff->page_offset = old_buff->page_offset;
7986 new_buff->pagecnt_bias = old_buff->pagecnt_bias;
7989 static inline bool igb_page_is_reserved(struct page *page)
7991 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
7994 static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer)
7996 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
7997 struct page *page = rx_buffer->page;
7999 /* avoid re-using remote pages */
8000 if (unlikely(igb_page_is_reserved(page)))
8003 #if (PAGE_SIZE < 8192)
8004 /* if we are only owner of page we can reuse it */
8005 if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
8008 #define IGB_LAST_OFFSET \
8009 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IGB_RXBUFFER_2048)
8011 if (rx_buffer->page_offset > IGB_LAST_OFFSET)
8015 /* If we have drained the page fragment pool we need to update
8016 * the pagecnt_bias and page count so that we fully restock the
8017 * number of references the driver holds.
8019 if (unlikely(!pagecnt_bias)) {
8020 page_ref_add(page, USHRT_MAX);
8021 rx_buffer->pagecnt_bias = USHRT_MAX;
8028 * igb_add_rx_frag - Add contents of Rx buffer to sk_buff
8029 * @rx_ring: rx descriptor ring to transact packets on
8030 * @rx_buffer: buffer containing page to add
8031 * @skb: sk_buff to place the data into
8032 * @size: size of buffer to be added
8034 * This function will add the data contained in rx_buffer->page to the skb.
8036 static void igb_add_rx_frag(struct igb_ring *rx_ring,
8037 struct igb_rx_buffer *rx_buffer,
8038 struct sk_buff *skb,
8041 #if (PAGE_SIZE < 8192)
8042 unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
8044 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
8045 SKB_DATA_ALIGN(IGB_SKB_PAD + size) :
8046 SKB_DATA_ALIGN(size);
8048 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
8049 rx_buffer->page_offset, size, truesize);
8050 #if (PAGE_SIZE < 8192)
8051 rx_buffer->page_offset ^= truesize;
8053 rx_buffer->page_offset += truesize;
8057 static struct sk_buff *igb_construct_skb(struct igb_ring *rx_ring,
8058 struct igb_rx_buffer *rx_buffer,
8059 union e1000_adv_rx_desc *rx_desc,
8062 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
8063 #if (PAGE_SIZE < 8192)
8064 unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
8066 unsigned int truesize = SKB_DATA_ALIGN(size);
8068 unsigned int headlen;
8069 struct sk_buff *skb;
8071 /* prefetch first cache line of first page */
8073 #if L1_CACHE_BYTES < 128
8074 prefetch(va + L1_CACHE_BYTES);
8077 /* allocate a skb to store the frags */
8078 skb = napi_alloc_skb(&rx_ring->q_vector->napi, IGB_RX_HDR_LEN);
8082 if (unlikely(igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))) {
8083 igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
8084 va += IGB_TS_HDR_LEN;
8085 size -= IGB_TS_HDR_LEN;
8088 /* Determine available headroom for copy */
8090 if (headlen > IGB_RX_HDR_LEN)
8091 headlen = eth_get_headlen(va, IGB_RX_HDR_LEN);
8093 /* align pull length to size of long to optimize memcpy performance */
8094 memcpy(__skb_put(skb, headlen), va, ALIGN(headlen, sizeof(long)));
8096 /* update all of the pointers */
8099 skb_add_rx_frag(skb, 0, rx_buffer->page,
8100 (va + headlen) - page_address(rx_buffer->page),
8102 #if (PAGE_SIZE < 8192)
8103 rx_buffer->page_offset ^= truesize;
8105 rx_buffer->page_offset += truesize;
8108 rx_buffer->pagecnt_bias++;
8114 static struct sk_buff *igb_build_skb(struct igb_ring *rx_ring,
8115 struct igb_rx_buffer *rx_buffer,
8116 union e1000_adv_rx_desc *rx_desc,
8119 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
8120 #if (PAGE_SIZE < 8192)
8121 unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
8123 unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
8124 SKB_DATA_ALIGN(IGB_SKB_PAD + size);
8126 struct sk_buff *skb;
8128 /* prefetch first cache line of first page */
8130 #if L1_CACHE_BYTES < 128
8131 prefetch(va + L1_CACHE_BYTES);
8134 /* build an skb around the page buffer */
8135 skb = build_skb(va - IGB_SKB_PAD, truesize);
8139 /* update pointers within the skb to store the data */
8140 skb_reserve(skb, IGB_SKB_PAD);
8141 __skb_put(skb, size);
8143 /* pull timestamp out of packet data */
8144 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
8145 igb_ptp_rx_pktstamp(rx_ring->q_vector, skb->data, skb);
8146 __skb_pull(skb, IGB_TS_HDR_LEN);
8149 /* update buffer offset */
8150 #if (PAGE_SIZE < 8192)
8151 rx_buffer->page_offset ^= truesize;
8153 rx_buffer->page_offset += truesize;
8159 static inline void igb_rx_checksum(struct igb_ring *ring,
8160 union e1000_adv_rx_desc *rx_desc,
8161 struct sk_buff *skb)
8163 skb_checksum_none_assert(skb);
8165 /* Ignore Checksum bit is set */
8166 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_IXSM))
8169 /* Rx checksum disabled via ethtool */
8170 if (!(ring->netdev->features & NETIF_F_RXCSUM))
8173 /* TCP/UDP checksum error bit is set */
8174 if (igb_test_staterr(rx_desc,
8175 E1000_RXDEXT_STATERR_TCPE |
8176 E1000_RXDEXT_STATERR_IPE)) {
8177 /* work around errata with sctp packets where the TCPE aka
8178 * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
8179 * packets, (aka let the stack check the crc32c)
8181 if (!((skb->len == 60) &&
8182 test_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags))) {
8183 u64_stats_update_begin(&ring->rx_syncp);
8184 ring->rx_stats.csum_err++;
8185 u64_stats_update_end(&ring->rx_syncp);
8187 /* let the stack verify checksum errors */
8190 /* It must be a TCP or UDP packet with a valid checksum */
8191 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_TCPCS |
8192 E1000_RXD_STAT_UDPCS))
8193 skb->ip_summed = CHECKSUM_UNNECESSARY;
8195 dev_dbg(ring->dev, "cksum success: bits %08X\n",
8196 le32_to_cpu(rx_desc->wb.upper.status_error));
8199 static inline void igb_rx_hash(struct igb_ring *ring,
8200 union e1000_adv_rx_desc *rx_desc,
8201 struct sk_buff *skb)
8203 if (ring->netdev->features & NETIF_F_RXHASH)
8205 le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
8210 * igb_is_non_eop - process handling of non-EOP buffers
8211 * @rx_ring: Rx ring being processed
8212 * @rx_desc: Rx descriptor for current buffer
8213 * @skb: current socket buffer containing buffer in progress
8215 * This function updates next to clean. If the buffer is an EOP buffer
8216 * this function exits returning false, otherwise it will place the
8217 * sk_buff in the next buffer to be chained and return true indicating
8218 * that this is in fact a non-EOP buffer.
8220 static bool igb_is_non_eop(struct igb_ring *rx_ring,
8221 union e1000_adv_rx_desc *rx_desc)
8223 u32 ntc = rx_ring->next_to_clean + 1;
8225 /* fetch, update, and store next to clean */
8226 ntc = (ntc < rx_ring->count) ? ntc : 0;
8227 rx_ring->next_to_clean = ntc;
8229 prefetch(IGB_RX_DESC(rx_ring, ntc));
8231 if (likely(igb_test_staterr(rx_desc, E1000_RXD_STAT_EOP)))
8238 * igb_cleanup_headers - Correct corrupted or empty headers
8239 * @rx_ring: rx descriptor ring packet is being transacted on
8240 * @rx_desc: pointer to the EOP Rx descriptor
8241 * @skb: pointer to current skb being fixed
8243 * Address the case where we are pulling data in on pages only
8244 * and as such no data is present in the skb header.
8246 * In addition if skb is not at least 60 bytes we need to pad it so that
8247 * it is large enough to qualify as a valid Ethernet frame.
8249 * Returns true if an error was encountered and skb was freed.
8251 static bool igb_cleanup_headers(struct igb_ring *rx_ring,
8252 union e1000_adv_rx_desc *rx_desc,
8253 struct sk_buff *skb)
8255 if (unlikely((igb_test_staterr(rx_desc,
8256 E1000_RXDEXT_ERR_FRAME_ERR_MASK)))) {
8257 struct net_device *netdev = rx_ring->netdev;
8258 if (!(netdev->features & NETIF_F_RXALL)) {
8259 dev_kfree_skb_any(skb);
8264 /* if eth_skb_pad returns an error the skb was freed */
8265 if (eth_skb_pad(skb))
8272 * igb_process_skb_fields - Populate skb header fields from Rx descriptor
8273 * @rx_ring: rx descriptor ring packet is being transacted on
8274 * @rx_desc: pointer to the EOP Rx descriptor
8275 * @skb: pointer to current skb being populated
8277 * This function checks the ring, descriptor, and packet information in
8278 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
8279 * other fields within the skb.
8281 static void igb_process_skb_fields(struct igb_ring *rx_ring,
8282 union e1000_adv_rx_desc *rx_desc,
8283 struct sk_buff *skb)
8285 struct net_device *dev = rx_ring->netdev;
8287 igb_rx_hash(rx_ring, rx_desc, skb);
8289 igb_rx_checksum(rx_ring, rx_desc, skb);
8291 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TS) &&
8292 !igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))
8293 igb_ptp_rx_rgtstamp(rx_ring->q_vector, skb);
8295 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
8296 igb_test_staterr(rx_desc, E1000_RXD_STAT_VP)) {
8299 if (igb_test_staterr(rx_desc, E1000_RXDEXT_STATERR_LB) &&
8300 test_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &rx_ring->flags))
8301 vid = be16_to_cpu(rx_desc->wb.upper.vlan);
8303 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
8305 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
8308 skb_record_rx_queue(skb, rx_ring->queue_index);
8310 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
8313 static struct igb_rx_buffer *igb_get_rx_buffer(struct igb_ring *rx_ring,
8314 const unsigned int size)
8316 struct igb_rx_buffer *rx_buffer;
8318 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
8319 prefetchw(rx_buffer->page);
8321 /* we are reusing so sync this buffer for CPU use */
8322 dma_sync_single_range_for_cpu(rx_ring->dev,
8324 rx_buffer->page_offset,
8328 rx_buffer->pagecnt_bias--;
8333 static void igb_put_rx_buffer(struct igb_ring *rx_ring,
8334 struct igb_rx_buffer *rx_buffer)
8336 if (igb_can_reuse_rx_page(rx_buffer)) {
8337 /* hand second half of page back to the ring */
8338 igb_reuse_rx_page(rx_ring, rx_buffer);
8340 /* We are not reusing the buffer so unmap it and free
8341 * any references we are holding to it
8343 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
8344 igb_rx_pg_size(rx_ring), DMA_FROM_DEVICE,
8346 __page_frag_cache_drain(rx_buffer->page,
8347 rx_buffer->pagecnt_bias);
8350 /* clear contents of rx_buffer */
8351 rx_buffer->page = NULL;
8354 static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)
8356 struct igb_ring *rx_ring = q_vector->rx.ring;
8357 struct sk_buff *skb = rx_ring->skb;
8358 unsigned int total_bytes = 0, total_packets = 0;
8359 u16 cleaned_count = igb_desc_unused(rx_ring);
8361 while (likely(total_packets < budget)) {
8362 union e1000_adv_rx_desc *rx_desc;
8363 struct igb_rx_buffer *rx_buffer;
8366 /* return some buffers to hardware, one at a time is too slow */
8367 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
8368 igb_alloc_rx_buffers(rx_ring, cleaned_count);
8372 rx_desc = IGB_RX_DESC(rx_ring, rx_ring->next_to_clean);
8373 size = le16_to_cpu(rx_desc->wb.upper.length);
8377 /* This memory barrier is needed to keep us from reading
8378 * any other fields out of the rx_desc until we know the
8379 * descriptor has been written back
8383 rx_buffer = igb_get_rx_buffer(rx_ring, size);
8385 /* retrieve a buffer from the ring */
8387 igb_add_rx_frag(rx_ring, rx_buffer, skb, size);
8388 else if (ring_uses_build_skb(rx_ring))
8389 skb = igb_build_skb(rx_ring, rx_buffer, rx_desc, size);
8391 skb = igb_construct_skb(rx_ring, rx_buffer,
8394 /* exit if we failed to retrieve a buffer */
8396 rx_ring->rx_stats.alloc_failed++;
8397 rx_buffer->pagecnt_bias++;
8401 igb_put_rx_buffer(rx_ring, rx_buffer);
8404 /* fetch next buffer in frame if non-eop */
8405 if (igb_is_non_eop(rx_ring, rx_desc))
8408 /* verify the packet layout is correct */
8409 if (igb_cleanup_headers(rx_ring, rx_desc, skb)) {
8414 /* probably a little skewed due to removing CRC */
8415 total_bytes += skb->len;
8417 /* populate checksum, timestamp, VLAN, and protocol */
8418 igb_process_skb_fields(rx_ring, rx_desc, skb);
8420 napi_gro_receive(&q_vector->napi, skb);
8422 /* reset skb pointer */
8425 /* update budget accounting */
8429 /* place incomplete frames back on ring for completion */
8432 u64_stats_update_begin(&rx_ring->rx_syncp);
8433 rx_ring->rx_stats.packets += total_packets;
8434 rx_ring->rx_stats.bytes += total_bytes;
8435 u64_stats_update_end(&rx_ring->rx_syncp);
8436 q_vector->rx.total_packets += total_packets;
8437 q_vector->rx.total_bytes += total_bytes;
8440 igb_alloc_rx_buffers(rx_ring, cleaned_count);
8442 return total_packets;
8445 static inline unsigned int igb_rx_offset(struct igb_ring *rx_ring)
8447 return ring_uses_build_skb(rx_ring) ? IGB_SKB_PAD : 0;
8450 static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
8451 struct igb_rx_buffer *bi)
8453 struct page *page = bi->page;
8456 /* since we are recycling buffers we should seldom need to alloc */
8460 /* alloc new page for storage */
8461 page = dev_alloc_pages(igb_rx_pg_order(rx_ring));
8462 if (unlikely(!page)) {
8463 rx_ring->rx_stats.alloc_failed++;
8467 /* map page for use */
8468 dma = dma_map_page_attrs(rx_ring->dev, page, 0,
8469 igb_rx_pg_size(rx_ring),
8473 /* if mapping failed free memory back to system since
8474 * there isn't much point in holding memory we can't use
8476 if (dma_mapping_error(rx_ring->dev, dma)) {
8477 __free_pages(page, igb_rx_pg_order(rx_ring));
8479 rx_ring->rx_stats.alloc_failed++;
8485 bi->page_offset = igb_rx_offset(rx_ring);
8486 bi->pagecnt_bias = 1;
8492 * igb_alloc_rx_buffers - Replace used receive buffers; packet split
8493 * @adapter: address of board private structure
8495 void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)
8497 union e1000_adv_rx_desc *rx_desc;
8498 struct igb_rx_buffer *bi;
8499 u16 i = rx_ring->next_to_use;
8506 rx_desc = IGB_RX_DESC(rx_ring, i);
8507 bi = &rx_ring->rx_buffer_info[i];
8508 i -= rx_ring->count;
8510 bufsz = igb_rx_bufsz(rx_ring);
8513 if (!igb_alloc_mapped_page(rx_ring, bi))
8516 /* sync the buffer for use by the device */
8517 dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
8518 bi->page_offset, bufsz,
8521 /* Refresh the desc even if buffer_addrs didn't change
8522 * because each write-back erases this info.
8524 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
8530 rx_desc = IGB_RX_DESC(rx_ring, 0);
8531 bi = rx_ring->rx_buffer_info;
8532 i -= rx_ring->count;
8535 /* clear the length for the next_to_use descriptor */
8536 rx_desc->wb.upper.length = 0;
8539 } while (cleaned_count);
8541 i += rx_ring->count;
8543 if (rx_ring->next_to_use != i) {
8544 /* record the next descriptor to use */
8545 rx_ring->next_to_use = i;
8547 /* update next to alloc since we have filled the ring */
8548 rx_ring->next_to_alloc = i;
8550 /* Force memory writes to complete before letting h/w
8551 * know there are new descriptors to fetch. (Only
8552 * applicable for weak-ordered memory model archs,
8556 writel(i, rx_ring->tail);
8566 static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
8568 struct igb_adapter *adapter = netdev_priv(netdev);
8569 struct mii_ioctl_data *data = if_mii(ifr);
8571 if (adapter->hw.phy.media_type != e1000_media_type_copper)
8576 data->phy_id = adapter->hw.phy.addr;
8579 if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
8596 static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
8602 return igb_mii_ioctl(netdev, ifr, cmd);
8604 return igb_ptp_get_ts_config(netdev, ifr);
8606 return igb_ptp_set_ts_config(netdev, ifr);
8612 void igb_read_pci_cfg(struct e1000_hw *hw, u32 reg, u16 *value)
8614 struct igb_adapter *adapter = hw->back;
8616 pci_read_config_word(adapter->pdev, reg, value);
8619 void igb_write_pci_cfg(struct e1000_hw *hw, u32 reg, u16 *value)
8621 struct igb_adapter *adapter = hw->back;
8623 pci_write_config_word(adapter->pdev, reg, *value);
8626 s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
8628 struct igb_adapter *adapter = hw->back;
8630 if (pcie_capability_read_word(adapter->pdev, reg, value))
8631 return -E1000_ERR_CONFIG;
8636 s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
8638 struct igb_adapter *adapter = hw->back;
8640 if (pcie_capability_write_word(adapter->pdev, reg, *value))
8641 return -E1000_ERR_CONFIG;
8646 static void igb_vlan_mode(struct net_device *netdev, netdev_features_t features)
8648 struct igb_adapter *adapter = netdev_priv(netdev);
8649 struct e1000_hw *hw = &adapter->hw;
8651 bool enable = !!(features & NETIF_F_HW_VLAN_CTAG_RX);
8654 /* enable VLAN tag insert/strip */
8655 ctrl = rd32(E1000_CTRL);
8656 ctrl |= E1000_CTRL_VME;
8657 wr32(E1000_CTRL, ctrl);
8659 /* Disable CFI check */
8660 rctl = rd32(E1000_RCTL);
8661 rctl &= ~E1000_RCTL_CFIEN;
8662 wr32(E1000_RCTL, rctl);
8664 /* disable VLAN tag insert/strip */
8665 ctrl = rd32(E1000_CTRL);
8666 ctrl &= ~E1000_CTRL_VME;
8667 wr32(E1000_CTRL, ctrl);
8670 igb_set_vf_vlan_strip(adapter, adapter->vfs_allocated_count, enable);
8673 static int igb_vlan_rx_add_vid(struct net_device *netdev,
8674 __be16 proto, u16 vid)
8676 struct igb_adapter *adapter = netdev_priv(netdev);
8677 struct e1000_hw *hw = &adapter->hw;
8678 int pf_id = adapter->vfs_allocated_count;
8680 /* add the filter since PF can receive vlans w/o entry in vlvf */
8681 if (!vid || !(adapter->flags & IGB_FLAG_VLAN_PROMISC))
8682 igb_vfta_set(hw, vid, pf_id, true, !!vid);
8684 set_bit(vid, adapter->active_vlans);
8689 static int igb_vlan_rx_kill_vid(struct net_device *netdev,
8690 __be16 proto, u16 vid)
8692 struct igb_adapter *adapter = netdev_priv(netdev);
8693 int pf_id = adapter->vfs_allocated_count;
8694 struct e1000_hw *hw = &adapter->hw;
8696 /* remove VID from filter table */
8697 if (vid && !(adapter->flags & IGB_FLAG_VLAN_PROMISC))
8698 igb_vfta_set(hw, vid, pf_id, false, true);
8700 clear_bit(vid, adapter->active_vlans);
8705 static void igb_restore_vlan(struct igb_adapter *adapter)
8709 igb_vlan_mode(adapter->netdev, adapter->netdev->features);
8710 igb_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
8712 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
8713 igb_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
8716 int igb_set_spd_dplx(struct igb_adapter *adapter, u32 spd, u8 dplx)
8718 struct pci_dev *pdev = adapter->pdev;
8719 struct e1000_mac_info *mac = &adapter->hw.mac;
8723 /* Make sure dplx is at most 1 bit and lsb of speed is not set
8724 * for the switch() below to work
8726 if ((spd & 1) || (dplx & ~1))
8729 /* Fiber NIC's only allow 1000 gbps Full duplex
8730 * and 100Mbps Full duplex for 100baseFx sfp
8732 if (adapter->hw.phy.media_type == e1000_media_type_internal_serdes) {
8733 switch (spd + dplx) {
8734 case SPEED_10 + DUPLEX_HALF:
8735 case SPEED_10 + DUPLEX_FULL:
8736 case SPEED_100 + DUPLEX_HALF:
8743 switch (spd + dplx) {
8744 case SPEED_10 + DUPLEX_HALF:
8745 mac->forced_speed_duplex = ADVERTISE_10_HALF;
8747 case SPEED_10 + DUPLEX_FULL:
8748 mac->forced_speed_duplex = ADVERTISE_10_FULL;
8750 case SPEED_100 + DUPLEX_HALF:
8751 mac->forced_speed_duplex = ADVERTISE_100_HALF;
8753 case SPEED_100 + DUPLEX_FULL:
8754 mac->forced_speed_duplex = ADVERTISE_100_FULL;
8756 case SPEED_1000 + DUPLEX_FULL:
8758 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
8760 case SPEED_1000 + DUPLEX_HALF: /* not supported */
8765 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
8766 adapter->hw.phy.mdix = AUTO_ALL_MODES;
8771 dev_err(&pdev->dev, "Unsupported Speed/Duplex configuration\n");
8775 static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
8778 struct net_device *netdev = pci_get_drvdata(pdev);
8779 struct igb_adapter *adapter = netdev_priv(netdev);
8780 struct e1000_hw *hw = &adapter->hw;
8781 u32 ctrl, rctl, status;
8782 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
8786 netif_device_detach(netdev);
8788 if (netif_running(netdev))
8789 __igb_close(netdev, true);
8791 igb_ptp_suspend(adapter);
8793 igb_clear_interrupt_scheme(adapter);
8796 status = rd32(E1000_STATUS);
8797 if (status & E1000_STATUS_LU)
8798 wufc &= ~E1000_WUFC_LNKC;
8801 igb_setup_rctl(adapter);
8802 igb_set_rx_mode(netdev);
8804 /* turn on all-multi mode if wake on multicast is enabled */
8805 if (wufc & E1000_WUFC_MC) {
8806 rctl = rd32(E1000_RCTL);
8807 rctl |= E1000_RCTL_MPE;
8808 wr32(E1000_RCTL, rctl);
8811 ctrl = rd32(E1000_CTRL);
8812 ctrl |= E1000_CTRL_ADVD3WUC;
8813 wr32(E1000_CTRL, ctrl);
8815 /* Allow time for pending master requests to run */
8816 igb_disable_pcie_master(hw);
8818 wr32(E1000_WUC, E1000_WUC_PME_EN);
8819 wr32(E1000_WUFC, wufc);
8822 wr32(E1000_WUFC, 0);
8825 wake = wufc || adapter->en_mng_pt;
8827 igb_power_down_link(adapter);
8829 igb_power_up_link(adapter);
8832 *enable_wake = wake;
8834 /* Release control of h/w to f/w. If f/w is AMT enabled, this
8835 * would have already happened in close and is redundant.
8837 igb_release_hw_control(adapter);
8839 pci_disable_device(pdev);
8844 static void igb_deliver_wake_packet(struct net_device *netdev)
8846 struct igb_adapter *adapter = netdev_priv(netdev);
8847 struct e1000_hw *hw = &adapter->hw;
8848 struct sk_buff *skb;
8851 wupl = rd32(E1000_WUPL) & E1000_WUPL_MASK;
8853 /* WUPM stores only the first 128 bytes of the wake packet.
8854 * Read the packet only if we have the whole thing.
8856 if ((wupl == 0) || (wupl > E1000_WUPM_BYTES))
8859 skb = netdev_alloc_skb_ip_align(netdev, E1000_WUPM_BYTES);
8865 /* Ensure reads are 32-bit aligned */
8866 wupl = roundup(wupl, 4);
8868 memcpy_fromio(skb->data, hw->hw_addr + E1000_WUPM_REG(0), wupl);
8870 skb->protocol = eth_type_trans(skb, netdev);
8874 static int __maybe_unused igb_suspend(struct device *dev)
8876 return __igb_shutdown(to_pci_dev(dev), NULL, 0);
8879 static int __maybe_unused igb_resume(struct device *dev)
8881 struct pci_dev *pdev = to_pci_dev(dev);
8882 struct net_device *netdev = pci_get_drvdata(pdev);
8883 struct igb_adapter *adapter = netdev_priv(netdev);
8884 struct e1000_hw *hw = &adapter->hw;
8887 pci_set_power_state(pdev, PCI_D0);
8888 pci_restore_state(pdev);
8889 pci_save_state(pdev);
8891 if (!pci_device_is_present(pdev))
8893 err = pci_enable_device_mem(pdev);
8896 "igb: Cannot enable PCI device from suspend\n");
8899 pci_set_master(pdev);
8901 pci_enable_wake(pdev, PCI_D3hot, 0);
8902 pci_enable_wake(pdev, PCI_D3cold, 0);
8904 if (igb_init_interrupt_scheme(adapter, true)) {
8905 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
8911 /* let the f/w know that the h/w is now under the control of the
8914 igb_get_hw_control(adapter);
8916 val = rd32(E1000_WUS);
8917 if (val & WAKE_PKT_WUS)
8918 igb_deliver_wake_packet(netdev);
8920 wr32(E1000_WUS, ~0);
8923 if (!err && netif_running(netdev))
8924 err = __igb_open(netdev, true);
8927 netif_device_attach(netdev);
8933 static int __maybe_unused igb_runtime_idle(struct device *dev)
8935 struct pci_dev *pdev = to_pci_dev(dev);
8936 struct net_device *netdev = pci_get_drvdata(pdev);
8937 struct igb_adapter *adapter = netdev_priv(netdev);
8939 if (!igb_has_link(adapter))
8940 pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
8945 static int __maybe_unused igb_runtime_suspend(struct device *dev)
8947 return __igb_shutdown(to_pci_dev(dev), NULL, 1);
8950 static int __maybe_unused igb_runtime_resume(struct device *dev)
8952 return igb_resume(dev);
8955 static void igb_shutdown(struct pci_dev *pdev)
8959 __igb_shutdown(pdev, &wake, 0);
8961 if (system_state == SYSTEM_POWER_OFF) {
8962 pci_wake_from_d3(pdev, wake);
8963 pci_set_power_state(pdev, PCI_D3hot);
8967 #ifdef CONFIG_PCI_IOV
8968 static int igb_sriov_reinit(struct pci_dev *dev)
8970 struct net_device *netdev = pci_get_drvdata(dev);
8971 struct igb_adapter *adapter = netdev_priv(netdev);
8972 struct pci_dev *pdev = adapter->pdev;
8976 if (netif_running(netdev))
8981 igb_clear_interrupt_scheme(adapter);
8983 igb_init_queue_configuration(adapter);
8985 if (igb_init_interrupt_scheme(adapter, true)) {
8987 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
8991 if (netif_running(netdev))
8999 static int igb_pci_disable_sriov(struct pci_dev *dev)
9001 int err = igb_disable_sriov(dev);
9004 err = igb_sriov_reinit(dev);
9009 static int igb_pci_enable_sriov(struct pci_dev *dev, int num_vfs)
9011 int err = igb_enable_sriov(dev, num_vfs);
9016 err = igb_sriov_reinit(dev);
9025 static int igb_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
9027 #ifdef CONFIG_PCI_IOV
9029 return igb_pci_disable_sriov(dev);
9031 return igb_pci_enable_sriov(dev, num_vfs);
9037 * igb_io_error_detected - called when PCI error is detected
9038 * @pdev: Pointer to PCI device
9039 * @state: The current pci connection state
9041 * This function is called after a PCI bus error affecting
9042 * this device has been detected.
9044 static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
9045 pci_channel_state_t state)
9047 struct net_device *netdev = pci_get_drvdata(pdev);
9048 struct igb_adapter *adapter = netdev_priv(netdev);
9050 netif_device_detach(netdev);
9052 if (state == pci_channel_io_perm_failure)
9053 return PCI_ERS_RESULT_DISCONNECT;
9055 if (netif_running(netdev))
9057 pci_disable_device(pdev);
9059 /* Request a slot slot reset. */
9060 return PCI_ERS_RESULT_NEED_RESET;
9064 * igb_io_slot_reset - called after the pci bus has been reset.
9065 * @pdev: Pointer to PCI device
9067 * Restart the card from scratch, as if from a cold-boot. Implementation
9068 * resembles the first-half of the igb_resume routine.
9070 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
9072 struct net_device *netdev = pci_get_drvdata(pdev);
9073 struct igb_adapter *adapter = netdev_priv(netdev);
9074 struct e1000_hw *hw = &adapter->hw;
9075 pci_ers_result_t result;
9078 if (pci_enable_device_mem(pdev)) {
9080 "Cannot re-enable PCI device after reset.\n");
9081 result = PCI_ERS_RESULT_DISCONNECT;
9083 pci_set_master(pdev);
9084 pci_restore_state(pdev);
9085 pci_save_state(pdev);
9087 pci_enable_wake(pdev, PCI_D3hot, 0);
9088 pci_enable_wake(pdev, PCI_D3cold, 0);
9090 /* In case of PCI error, adapter lose its HW address
9091 * so we should re-assign it here.
9093 hw->hw_addr = adapter->io_addr;
9096 wr32(E1000_WUS, ~0);
9097 result = PCI_ERS_RESULT_RECOVERED;
9100 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9103 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9105 /* non-fatal, continue */
9112 * igb_io_resume - called when traffic can start flowing again.
9113 * @pdev: Pointer to PCI device
9115 * This callback is called when the error recovery driver tells us that
9116 * its OK to resume normal operation. Implementation resembles the
9117 * second-half of the igb_resume routine.
9119 static void igb_io_resume(struct pci_dev *pdev)
9121 struct net_device *netdev = pci_get_drvdata(pdev);
9122 struct igb_adapter *adapter = netdev_priv(netdev);
9124 if (netif_running(netdev)) {
9125 if (igb_up(adapter)) {
9126 dev_err(&pdev->dev, "igb_up failed after reset\n");
9131 netif_device_attach(netdev);
9133 /* let the f/w know that the h/w is now under the control of the
9136 igb_get_hw_control(adapter);
9140 * igb_rar_set_index - Sync RAL[index] and RAH[index] registers with MAC table
9141 * @adapter: Pointer to adapter structure
9142 * @index: Index of the RAR entry which need to be synced with MAC table
9144 static void igb_rar_set_index(struct igb_adapter *adapter, u32 index)
9146 struct e1000_hw *hw = &adapter->hw;
9147 u32 rar_low, rar_high;
9148 u8 *addr = adapter->mac_table[index].addr;
9150 /* HW expects these to be in network order when they are plugged
9151 * into the registers which are little endian. In order to guarantee
9152 * that ordering we need to do an leXX_to_cpup here in order to be
9153 * ready for the byteswap that occurs with writel
9155 rar_low = le32_to_cpup((__le32 *)(addr));
9156 rar_high = le16_to_cpup((__le16 *)(addr + 4));
9158 /* Indicate to hardware the Address is Valid. */
9159 if (adapter->mac_table[index].state & IGB_MAC_STATE_IN_USE) {
9160 if (is_valid_ether_addr(addr))
9161 rar_high |= E1000_RAH_AV;
9163 if (adapter->mac_table[index].state & IGB_MAC_STATE_SRC_ADDR)
9164 rar_high |= E1000_RAH_ASEL_SRC_ADDR;
9166 switch (hw->mac.type) {
9169 if (adapter->mac_table[index].state &
9170 IGB_MAC_STATE_QUEUE_STEERING)
9171 rar_high |= E1000_RAH_QSEL_ENABLE;
9173 rar_high |= E1000_RAH_POOL_1 *
9174 adapter->mac_table[index].queue;
9177 rar_high |= E1000_RAH_POOL_1 <<
9178 adapter->mac_table[index].queue;
9183 wr32(E1000_RAL(index), rar_low);
9185 wr32(E1000_RAH(index), rar_high);
9189 static int igb_set_vf_mac(struct igb_adapter *adapter,
9190 int vf, unsigned char *mac_addr)
9192 struct e1000_hw *hw = &adapter->hw;
9193 /* VF MAC addresses start at end of receive addresses and moves
9194 * towards the first, as a result a collision should not be possible
9196 int rar_entry = hw->mac.rar_entry_count - (vf + 1);
9197 unsigned char *vf_mac_addr = adapter->vf_data[vf].vf_mac_addresses;
9199 ether_addr_copy(vf_mac_addr, mac_addr);
9200 ether_addr_copy(adapter->mac_table[rar_entry].addr, mac_addr);
9201 adapter->mac_table[rar_entry].queue = vf;
9202 adapter->mac_table[rar_entry].state |= IGB_MAC_STATE_IN_USE;
9203 igb_rar_set_index(adapter, rar_entry);
9208 static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
9210 struct igb_adapter *adapter = netdev_priv(netdev);
9212 if (vf >= adapter->vfs_allocated_count)
9215 /* Setting the VF MAC to 0 reverts the IGB_VF_FLAG_PF_SET_MAC
9216 * flag and allows to overwrite the MAC via VF netdev. This
9217 * is necessary to allow libvirt a way to restore the original
9218 * MAC after unbinding vfio-pci and reloading igbvf after shutting
9221 if (is_zero_ether_addr(mac)) {
9222 adapter->vf_data[vf].flags &= ~IGB_VF_FLAG_PF_SET_MAC;
9223 dev_info(&adapter->pdev->dev,
9224 "remove administratively set MAC on VF %d\n",
9226 } else if (is_valid_ether_addr(mac)) {
9227 adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC;
9228 dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n",
9230 dev_info(&adapter->pdev->dev,
9231 "Reload the VF driver to make this change effective.");
9232 /* Generate additional warning if PF is down */
9233 if (test_bit(__IGB_DOWN, &adapter->state)) {
9234 dev_warn(&adapter->pdev->dev,
9235 "The VF MAC address has been set, but the PF device is not up.\n");
9236 dev_warn(&adapter->pdev->dev,
9237 "Bring the PF device up before attempting to use the VF device.\n");
9242 return igb_set_vf_mac(adapter, vf, mac);
9245 static int igb_link_mbps(int internal_link_speed)
9247 switch (internal_link_speed) {
9257 static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
9264 /* Calculate the rate factor values to set */
9265 rf_int = link_speed / tx_rate;
9266 rf_dec = (link_speed - (rf_int * tx_rate));
9267 rf_dec = (rf_dec * BIT(E1000_RTTBCNRC_RF_INT_SHIFT)) /
9270 bcnrc_val = E1000_RTTBCNRC_RS_ENA;
9271 bcnrc_val |= ((rf_int << E1000_RTTBCNRC_RF_INT_SHIFT) &
9272 E1000_RTTBCNRC_RF_INT_MASK);
9273 bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
9278 wr32(E1000_RTTDQSEL, vf); /* vf X uses queue X */
9279 /* Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
9280 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported.
9282 wr32(E1000_RTTBCNRM, 0x14);
9283 wr32(E1000_RTTBCNRC, bcnrc_val);
9286 static void igb_check_vf_rate_limit(struct igb_adapter *adapter)
9288 int actual_link_speed, i;
9289 bool reset_rate = false;
9291 /* VF TX rate limit was not set or not supported */
9292 if ((adapter->vf_rate_link_speed == 0) ||
9293 (adapter->hw.mac.type != e1000_82576))
9296 actual_link_speed = igb_link_mbps(adapter->link_speed);
9297 if (actual_link_speed != adapter->vf_rate_link_speed) {
9299 adapter->vf_rate_link_speed = 0;
9300 dev_info(&adapter->pdev->dev,
9301 "Link speed has been changed. VF Transmit rate is disabled\n");
9304 for (i = 0; i < adapter->vfs_allocated_count; i++) {
9306 adapter->vf_data[i].tx_rate = 0;
9308 igb_set_vf_rate_limit(&adapter->hw, i,
9309 adapter->vf_data[i].tx_rate,
9314 static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf,
9315 int min_tx_rate, int max_tx_rate)
9317 struct igb_adapter *adapter = netdev_priv(netdev);
9318 struct e1000_hw *hw = &adapter->hw;
9319 int actual_link_speed;
9321 if (hw->mac.type != e1000_82576)
9327 actual_link_speed = igb_link_mbps(adapter->link_speed);
9328 if ((vf >= adapter->vfs_allocated_count) ||
9329 (!(rd32(E1000_STATUS) & E1000_STATUS_LU)) ||
9330 (max_tx_rate < 0) ||
9331 (max_tx_rate > actual_link_speed))
9334 adapter->vf_rate_link_speed = actual_link_speed;
9335 adapter->vf_data[vf].tx_rate = (u16)max_tx_rate;
9336 igb_set_vf_rate_limit(hw, vf, max_tx_rate, actual_link_speed);
9341 static int igb_ndo_set_vf_spoofchk(struct net_device *netdev, int vf,
9344 struct igb_adapter *adapter = netdev_priv(netdev);
9345 struct e1000_hw *hw = &adapter->hw;
9346 u32 reg_val, reg_offset;
9348 if (!adapter->vfs_allocated_count)
9351 if (vf >= adapter->vfs_allocated_count)
9354 reg_offset = (hw->mac.type == e1000_82576) ? E1000_DTXSWC : E1000_TXSWC;
9355 reg_val = rd32(reg_offset);
9357 reg_val |= (BIT(vf) |
9358 BIT(vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT));
9360 reg_val &= ~(BIT(vf) |
9361 BIT(vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT));
9362 wr32(reg_offset, reg_val);
9364 adapter->vf_data[vf].spoofchk_enabled = setting;
9368 static int igb_ndo_set_vf_trust(struct net_device *netdev, int vf, bool setting)
9370 struct igb_adapter *adapter = netdev_priv(netdev);
9372 if (vf >= adapter->vfs_allocated_count)
9374 if (adapter->vf_data[vf].trusted == setting)
9377 adapter->vf_data[vf].trusted = setting;
9379 dev_info(&adapter->pdev->dev, "VF %u is %strusted\n",
9380 vf, setting ? "" : "not ");
9384 static int igb_ndo_get_vf_config(struct net_device *netdev,
9385 int vf, struct ifla_vf_info *ivi)
9387 struct igb_adapter *adapter = netdev_priv(netdev);
9388 if (vf >= adapter->vfs_allocated_count)
9391 memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN);
9392 ivi->max_tx_rate = adapter->vf_data[vf].tx_rate;
9393 ivi->min_tx_rate = 0;
9394 ivi->vlan = adapter->vf_data[vf].pf_vlan;
9395 ivi->qos = adapter->vf_data[vf].pf_qos;
9396 ivi->spoofchk = adapter->vf_data[vf].spoofchk_enabled;
9397 ivi->trusted = adapter->vf_data[vf].trusted;
9401 static void igb_vmm_control(struct igb_adapter *adapter)
9403 struct e1000_hw *hw = &adapter->hw;
9406 switch (hw->mac.type) {
9412 /* replication is not supported for 82575 */
9415 /* notify HW that the MAC is adding vlan tags */
9416 reg = rd32(E1000_DTXCTL);
9417 reg |= E1000_DTXCTL_VLAN_ADDED;
9418 wr32(E1000_DTXCTL, reg);
9421 /* enable replication vlan tag stripping */
9422 reg = rd32(E1000_RPLOLR);
9423 reg |= E1000_RPLOLR_STRVLAN;
9424 wr32(E1000_RPLOLR, reg);
9427 /* none of the above registers are supported by i350 */
9431 if (adapter->vfs_allocated_count) {
9432 igb_vmdq_set_loopback_pf(hw, true);
9433 igb_vmdq_set_replication_pf(hw, true);
9434 igb_vmdq_set_anti_spoofing_pf(hw, true,
9435 adapter->vfs_allocated_count);
9437 igb_vmdq_set_loopback_pf(hw, false);
9438 igb_vmdq_set_replication_pf(hw, false);
9442 static void igb_init_dmac(struct igb_adapter *adapter, u32 pba)
9444 struct e1000_hw *hw = &adapter->hw;
9448 if (hw->mac.type > e1000_82580) {
9449 if (adapter->flags & IGB_FLAG_DMAC) {
9452 /* force threshold to 0. */
9453 wr32(E1000_DMCTXTH, 0);
9455 /* DMA Coalescing high water mark needs to be greater
9456 * than the Rx threshold. Set hwm to PBA - max frame
9457 * size in 16B units, capping it at PBA - 6KB.
9459 hwm = 64 * (pba - 6);
9460 reg = rd32(E1000_FCRTC);
9461 reg &= ~E1000_FCRTC_RTH_COAL_MASK;
9462 reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
9463 & E1000_FCRTC_RTH_COAL_MASK);
9464 wr32(E1000_FCRTC, reg);
9466 /* Set the DMA Coalescing Rx threshold to PBA - 2 * max
9467 * frame size, capping it at PBA - 10KB.
9469 dmac_thr = pba - 10;
9470 reg = rd32(E1000_DMACR);
9471 reg &= ~E1000_DMACR_DMACTHR_MASK;
9472 reg |= ((dmac_thr << E1000_DMACR_DMACTHR_SHIFT)
9473 & E1000_DMACR_DMACTHR_MASK);
9475 /* transition to L0x or L1 if available..*/
9476 reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
9478 /* watchdog timer= +-1000 usec in 32usec intervals */
9481 /* Disable BMC-to-OS Watchdog Enable */
9482 if (hw->mac.type != e1000_i354)
9483 reg &= ~E1000_DMACR_DC_BMC2OSW_EN;
9485 wr32(E1000_DMACR, reg);
9487 /* no lower threshold to disable
9488 * coalescing(smart fifb)-UTRESH=0
9490 wr32(E1000_DMCRTRH, 0);
9492 reg = (IGB_DMCTLX_DCFLUSH_DIS | 0x4);
9494 wr32(E1000_DMCTLX, reg);
9496 /* free space in tx packet buffer to wake from
9499 wr32(E1000_DMCTXTH, (IGB_MIN_TXPBSIZE -
9500 (IGB_TX_BUF_4096 + adapter->max_frame_size)) >> 6);
9502 /* make low power state decision controlled
9505 reg = rd32(E1000_PCIEMISC);
9506 reg &= ~E1000_PCIEMISC_LX_DECISION;
9507 wr32(E1000_PCIEMISC, reg);
9508 } /* endif adapter->dmac is not disabled */
9509 } else if (hw->mac.type == e1000_82580) {
9510 u32 reg = rd32(E1000_PCIEMISC);
9512 wr32(E1000_PCIEMISC, reg & ~E1000_PCIEMISC_LX_DECISION);
9513 wr32(E1000_DMACR, 0);
9518 * igb_read_i2c_byte - Reads 8 bit word over I2C
9519 * @hw: pointer to hardware structure
9520 * @byte_offset: byte offset to read
9521 * @dev_addr: device address
9524 * Performs byte read operation over I2C interface at
9525 * a specified device address.
9527 s32 igb_read_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
9528 u8 dev_addr, u8 *data)
9530 struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
9531 struct i2c_client *this_client = adapter->i2c_client;
9536 return E1000_ERR_I2C;
9538 swfw_mask = E1000_SWFW_PHY0_SM;
9540 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
9541 return E1000_ERR_SWFW_SYNC;
9543 status = i2c_smbus_read_byte_data(this_client, byte_offset);
9544 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
9547 return E1000_ERR_I2C;
9555 * igb_write_i2c_byte - Writes 8 bit word over I2C
9556 * @hw: pointer to hardware structure
9557 * @byte_offset: byte offset to write
9558 * @dev_addr: device address
9559 * @data: value to write
9561 * Performs byte write operation over I2C interface at
9562 * a specified device address.
9564 s32 igb_write_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
9565 u8 dev_addr, u8 data)
9567 struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
9568 struct i2c_client *this_client = adapter->i2c_client;
9570 u16 swfw_mask = E1000_SWFW_PHY0_SM;
9573 return E1000_ERR_I2C;
9575 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
9576 return E1000_ERR_SWFW_SYNC;
9577 status = i2c_smbus_write_byte_data(this_client, byte_offset, data);
9578 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
9581 return E1000_ERR_I2C;
9587 int igb_reinit_queues(struct igb_adapter *adapter)
9589 struct net_device *netdev = adapter->netdev;
9590 struct pci_dev *pdev = adapter->pdev;
9593 if (netif_running(netdev))
9596 igb_reset_interrupt_capability(adapter);
9598 if (igb_init_interrupt_scheme(adapter, true)) {
9599 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
9603 if (netif_running(netdev))
9604 err = igb_open(netdev);
9609 static void igb_nfc_filter_exit(struct igb_adapter *adapter)
9611 struct igb_nfc_filter *rule;
9613 spin_lock(&adapter->nfc_lock);
9615 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node)
9616 igb_erase_filter(adapter, rule);
9618 hlist_for_each_entry(rule, &adapter->cls_flower_list, nfc_node)
9619 igb_erase_filter(adapter, rule);
9621 spin_unlock(&adapter->nfc_lock);
9624 static void igb_nfc_filter_restore(struct igb_adapter *adapter)
9626 struct igb_nfc_filter *rule;
9628 spin_lock(&adapter->nfc_lock);
9630 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node)
9631 igb_add_filter(adapter, rule);
9633 spin_unlock(&adapter->nfc_lock);