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_NET_POLL_CONTROLLER
209 /* for netdump / net console */
210 static void igb_netpoll(struct net_device
*);
212 #ifdef CONFIG_PCI_IOV
213 static unsigned int max_vfs
;
214 module_param(max_vfs
, uint
, 0);
215 MODULE_PARM_DESC(max_vfs
, "Maximum number of virtual functions to allocate per physical function");
216 #endif /* CONFIG_PCI_IOV */
218 static pci_ers_result_t
igb_io_error_detected(struct pci_dev
*,
219 pci_channel_state_t
);
220 static pci_ers_result_t
igb_io_slot_reset(struct pci_dev
*);
221 static void igb_io_resume(struct pci_dev
*);
223 static const struct pci_error_handlers igb_err_handler
= {
224 .error_detected
= igb_io_error_detected
,
225 .slot_reset
= igb_io_slot_reset
,
226 .resume
= igb_io_resume
,
229 static void igb_init_dmac(struct igb_adapter
*adapter
, u32 pba
);
231 static struct pci_driver igb_driver
= {
232 .name
= igb_driver_name
,
233 .id_table
= igb_pci_tbl
,
235 .remove
= igb_remove
,
237 .driver
.pm
= &igb_pm_ops
,
239 .shutdown
= igb_shutdown
,
240 .sriov_configure
= igb_pci_sriov_configure
,
241 .err_handler
= &igb_err_handler
244 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
245 MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
246 MODULE_LICENSE("GPL");
247 MODULE_VERSION(DRV_VERSION
);
249 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
250 static int debug
= -1;
251 module_param(debug
, int, 0);
252 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
254 struct igb_reg_info
{
259 static const struct igb_reg_info igb_reg_info_tbl
[] = {
261 /* General Registers */
262 {E1000_CTRL
, "CTRL"},
263 {E1000_STATUS
, "STATUS"},
264 {E1000_CTRL_EXT
, "CTRL_EXT"},
266 /* Interrupt Registers */
270 {E1000_RCTL
, "RCTL"},
271 {E1000_RDLEN(0), "RDLEN"},
272 {E1000_RDH(0), "RDH"},
273 {E1000_RDT(0), "RDT"},
274 {E1000_RXDCTL(0), "RXDCTL"},
275 {E1000_RDBAL(0), "RDBAL"},
276 {E1000_RDBAH(0), "RDBAH"},
279 {E1000_TCTL
, "TCTL"},
280 {E1000_TDBAL(0), "TDBAL"},
281 {E1000_TDBAH(0), "TDBAH"},
282 {E1000_TDLEN(0), "TDLEN"},
283 {E1000_TDH(0), "TDH"},
284 {E1000_TDT(0), "TDT"},
285 {E1000_TXDCTL(0), "TXDCTL"},
286 {E1000_TDFH
, "TDFH"},
287 {E1000_TDFT
, "TDFT"},
288 {E1000_TDFHS
, "TDFHS"},
289 {E1000_TDFPC
, "TDFPC"},
291 /* List Terminator */
295 /* igb_regdump - register printout routine */
296 static void igb_regdump(struct e1000_hw
*hw
, struct igb_reg_info
*reginfo
)
302 switch (reginfo
->ofs
) {
304 for (n
= 0; n
< 4; n
++)
305 regs
[n
] = rd32(E1000_RDLEN(n
));
308 for (n
= 0; n
< 4; n
++)
309 regs
[n
] = rd32(E1000_RDH(n
));
312 for (n
= 0; n
< 4; n
++)
313 regs
[n
] = rd32(E1000_RDT(n
));
315 case E1000_RXDCTL(0):
316 for (n
= 0; n
< 4; n
++)
317 regs
[n
] = rd32(E1000_RXDCTL(n
));
320 for (n
= 0; n
< 4; n
++)
321 regs
[n
] = rd32(E1000_RDBAL(n
));
324 for (n
= 0; n
< 4; n
++)
325 regs
[n
] = rd32(E1000_RDBAH(n
));
328 for (n
= 0; n
< 4; n
++)
329 regs
[n
] = rd32(E1000_RDBAL(n
));
332 for (n
= 0; n
< 4; n
++)
333 regs
[n
] = rd32(E1000_TDBAH(n
));
336 for (n
= 0; n
< 4; n
++)
337 regs
[n
] = rd32(E1000_TDLEN(n
));
340 for (n
= 0; n
< 4; n
++)
341 regs
[n
] = rd32(E1000_TDH(n
));
344 for (n
= 0; n
< 4; n
++)
345 regs
[n
] = rd32(E1000_TDT(n
));
347 case E1000_TXDCTL(0):
348 for (n
= 0; n
< 4; n
++)
349 regs
[n
] = rd32(E1000_TXDCTL(n
));
352 pr_info("%-15s %08x\n", reginfo
->name
, rd32(reginfo
->ofs
));
356 snprintf(rname
, 16, "%s%s", reginfo
->name
, "[0-3]");
357 pr_info("%-15s %08x %08x %08x %08x\n", rname
, regs
[0], regs
[1],
361 /* igb_dump - Print registers, Tx-rings and Rx-rings */
362 static void igb_dump(struct igb_adapter
*adapter
)
364 struct net_device
*netdev
= adapter
->netdev
;
365 struct e1000_hw
*hw
= &adapter
->hw
;
366 struct igb_reg_info
*reginfo
;
367 struct igb_ring
*tx_ring
;
368 union e1000_adv_tx_desc
*tx_desc
;
369 struct my_u0
{ u64 a
; u64 b
; } *u0
;
370 struct igb_ring
*rx_ring
;
371 union e1000_adv_rx_desc
*rx_desc
;
375 if (!netif_msg_hw(adapter
))
378 /* Print netdevice Info */
380 dev_info(&adapter
->pdev
->dev
, "Net device Info\n");
381 pr_info("Device Name state trans_start\n");
382 pr_info("%-15s %016lX %016lX\n", netdev
->name
,
383 netdev
->state
, dev_trans_start(netdev
));
386 /* Print Registers */
387 dev_info(&adapter
->pdev
->dev
, "Register Dump\n");
388 pr_info(" Register Name Value\n");
389 for (reginfo
= (struct igb_reg_info
*)igb_reg_info_tbl
;
390 reginfo
->name
; reginfo
++) {
391 igb_regdump(hw
, reginfo
);
394 /* Print TX Ring Summary */
395 if (!netdev
|| !netif_running(netdev
))
398 dev_info(&adapter
->pdev
->dev
, "TX Rings Summary\n");
399 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
400 for (n
= 0; n
< adapter
->num_tx_queues
; n
++) {
401 struct igb_tx_buffer
*buffer_info
;
402 tx_ring
= adapter
->tx_ring
[n
];
403 buffer_info
= &tx_ring
->tx_buffer_info
[tx_ring
->next_to_clean
];
404 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
405 n
, tx_ring
->next_to_use
, tx_ring
->next_to_clean
,
406 (u64
)dma_unmap_addr(buffer_info
, dma
),
407 dma_unmap_len(buffer_info
, len
),
408 buffer_info
->next_to_watch
,
409 (u64
)buffer_info
->time_stamp
);
413 if (!netif_msg_tx_done(adapter
))
414 goto rx_ring_summary
;
416 dev_info(&adapter
->pdev
->dev
, "TX Rings Dump\n");
418 /* Transmit Descriptor Formats
420 * Advanced Transmit Descriptor
421 * +--------------------------------------------------------------+
422 * 0 | Buffer Address [63:0] |
423 * +--------------------------------------------------------------+
424 * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN |
425 * +--------------------------------------------------------------+
426 * 63 46 45 40 39 38 36 35 32 31 24 15 0
429 for (n
= 0; n
< adapter
->num_tx_queues
; n
++) {
430 tx_ring
= adapter
->tx_ring
[n
];
431 pr_info("------------------------------------\n");
432 pr_info("TX QUEUE INDEX = %d\n", tx_ring
->queue_index
);
433 pr_info("------------------------------------\n");
434 pr_info("T [desc] [address 63:0 ] [PlPOCIStDDM Ln] [bi->dma ] leng ntw timestamp bi->skb\n");
436 for (i
= 0; tx_ring
->desc
&& (i
< tx_ring
->count
); i
++) {
437 const char *next_desc
;
438 struct igb_tx_buffer
*buffer_info
;
439 tx_desc
= IGB_TX_DESC(tx_ring
, i
);
440 buffer_info
= &tx_ring
->tx_buffer_info
[i
];
441 u0
= (struct my_u0
*)tx_desc
;
442 if (i
== tx_ring
->next_to_use
&&
443 i
== tx_ring
->next_to_clean
)
444 next_desc
= " NTC/U";
445 else if (i
== tx_ring
->next_to_use
)
447 else if (i
== tx_ring
->next_to_clean
)
452 pr_info("T [0x%03X] %016llX %016llX %016llX %04X %p %016llX %p%s\n",
453 i
, le64_to_cpu(u0
->a
),
455 (u64
)dma_unmap_addr(buffer_info
, dma
),
456 dma_unmap_len(buffer_info
, len
),
457 buffer_info
->next_to_watch
,
458 (u64
)buffer_info
->time_stamp
,
459 buffer_info
->skb
, next_desc
);
461 if (netif_msg_pktdata(adapter
) && buffer_info
->skb
)
462 print_hex_dump(KERN_INFO
, "",
464 16, 1, buffer_info
->skb
->data
,
465 dma_unmap_len(buffer_info
, len
),
470 /* Print RX Rings Summary */
472 dev_info(&adapter
->pdev
->dev
, "RX Rings Summary\n");
473 pr_info("Queue [NTU] [NTC]\n");
474 for (n
= 0; n
< adapter
->num_rx_queues
; n
++) {
475 rx_ring
= adapter
->rx_ring
[n
];
476 pr_info(" %5d %5X %5X\n",
477 n
, rx_ring
->next_to_use
, rx_ring
->next_to_clean
);
481 if (!netif_msg_rx_status(adapter
))
484 dev_info(&adapter
->pdev
->dev
, "RX Rings Dump\n");
486 /* Advanced Receive Descriptor (Read) Format
488 * +-----------------------------------------------------+
489 * 0 | Packet Buffer Address [63:1] |A0/NSE|
490 * +----------------------------------------------+------+
491 * 8 | Header Buffer Address [63:1] | DD |
492 * +-----------------------------------------------------+
495 * Advanced Receive Descriptor (Write-Back) Format
497 * 63 48 47 32 31 30 21 20 17 16 4 3 0
498 * +------------------------------------------------------+
499 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
500 * | Checksum Ident | | | | Type | Type |
501 * +------------------------------------------------------+
502 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
503 * +------------------------------------------------------+
504 * 63 48 47 32 31 20 19 0
507 for (n
= 0; n
< adapter
->num_rx_queues
; n
++) {
508 rx_ring
= adapter
->rx_ring
[n
];
509 pr_info("------------------------------------\n");
510 pr_info("RX QUEUE INDEX = %d\n", rx_ring
->queue_index
);
511 pr_info("------------------------------------\n");
512 pr_info("R [desc] [ PktBuf A0] [ HeadBuf DD] [bi->dma ] [bi->skb] <-- Adv Rx Read format\n");
513 pr_info("RWB[desc] [PcsmIpSHl PtRs] [vl er S cks ln] ---------------- [bi->skb] <-- Adv Rx Write-Back format\n");
515 for (i
= 0; i
< rx_ring
->count
; i
++) {
516 const char *next_desc
;
517 struct igb_rx_buffer
*buffer_info
;
518 buffer_info
= &rx_ring
->rx_buffer_info
[i
];
519 rx_desc
= IGB_RX_DESC(rx_ring
, i
);
520 u0
= (struct my_u0
*)rx_desc
;
521 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
523 if (i
== rx_ring
->next_to_use
)
525 else if (i
== rx_ring
->next_to_clean
)
530 if (staterr
& E1000_RXD_STAT_DD
) {
531 /* Descriptor Done */
532 pr_info("%s[0x%03X] %016llX %016llX ---------------- %s\n",
538 pr_info("%s[0x%03X] %016llX %016llX %016llX %s\n",
542 (u64
)buffer_info
->dma
,
545 if (netif_msg_pktdata(adapter
) &&
546 buffer_info
->dma
&& buffer_info
->page
) {
547 print_hex_dump(KERN_INFO
, "",
550 page_address(buffer_info
->page
) +
551 buffer_info
->page_offset
,
552 igb_rx_bufsz(rx_ring
), true);
563 * igb_get_i2c_data - Reads the I2C SDA data bit
564 * @hw: pointer to hardware structure
565 * @i2cctl: Current value of I2CCTL register
567 * Returns the I2C data bit value
569 static int igb_get_i2c_data(void *data
)
571 struct igb_adapter
*adapter
= (struct igb_adapter
*)data
;
572 struct e1000_hw
*hw
= &adapter
->hw
;
573 s32 i2cctl
= rd32(E1000_I2CPARAMS
);
575 return !!(i2cctl
& E1000_I2C_DATA_IN
);
579 * igb_set_i2c_data - Sets the I2C data bit
580 * @data: pointer to hardware structure
581 * @state: I2C data value (0 or 1) to set
583 * Sets the I2C data bit
585 static void igb_set_i2c_data(void *data
, int state
)
587 struct igb_adapter
*adapter
= (struct igb_adapter
*)data
;
588 struct e1000_hw
*hw
= &adapter
->hw
;
589 s32 i2cctl
= rd32(E1000_I2CPARAMS
);
592 i2cctl
|= E1000_I2C_DATA_OUT
;
594 i2cctl
&= ~E1000_I2C_DATA_OUT
;
596 i2cctl
&= ~E1000_I2C_DATA_OE_N
;
597 i2cctl
|= E1000_I2C_CLK_OE_N
;
598 wr32(E1000_I2CPARAMS
, i2cctl
);
604 * igb_set_i2c_clk - Sets the I2C SCL clock
605 * @data: pointer to hardware structure
606 * @state: state to set clock
608 * Sets the I2C clock line to state
610 static void igb_set_i2c_clk(void *data
, int state
)
612 struct igb_adapter
*adapter
= (struct igb_adapter
*)data
;
613 struct e1000_hw
*hw
= &adapter
->hw
;
614 s32 i2cctl
= rd32(E1000_I2CPARAMS
);
617 i2cctl
|= E1000_I2C_CLK_OUT
;
618 i2cctl
&= ~E1000_I2C_CLK_OE_N
;
620 i2cctl
&= ~E1000_I2C_CLK_OUT
;
621 i2cctl
&= ~E1000_I2C_CLK_OE_N
;
623 wr32(E1000_I2CPARAMS
, i2cctl
);
628 * igb_get_i2c_clk - Gets the I2C SCL clock state
629 * @data: pointer to hardware structure
631 * Gets the I2C clock state
633 static int igb_get_i2c_clk(void *data
)
635 struct igb_adapter
*adapter
= (struct igb_adapter
*)data
;
636 struct e1000_hw
*hw
= &adapter
->hw
;
637 s32 i2cctl
= rd32(E1000_I2CPARAMS
);
639 return !!(i2cctl
& E1000_I2C_CLK_IN
);
642 static const struct i2c_algo_bit_data igb_i2c_algo
= {
643 .setsda
= igb_set_i2c_data
,
644 .setscl
= igb_set_i2c_clk
,
645 .getsda
= igb_get_i2c_data
,
646 .getscl
= igb_get_i2c_clk
,
652 * igb_get_hw_dev - return device
653 * @hw: pointer to hardware structure
655 * used by hardware layer to print debugging information
657 struct net_device
*igb_get_hw_dev(struct e1000_hw
*hw
)
659 struct igb_adapter
*adapter
= hw
->back
;
660 return adapter
->netdev
;
664 * igb_init_module - Driver Registration Routine
666 * igb_init_module is the first routine called when the driver is
667 * loaded. All it does is register with the PCI subsystem.
669 static int __init
igb_init_module(void)
673 pr_info("%s - version %s\n",
674 igb_driver_string
, igb_driver_version
);
675 pr_info("%s\n", igb_copyright
);
677 #ifdef CONFIG_IGB_DCA
678 dca_register_notify(&dca_notifier
);
680 ret
= pci_register_driver(&igb_driver
);
684 module_init(igb_init_module
);
687 * igb_exit_module - Driver Exit Cleanup Routine
689 * igb_exit_module is called just before the driver is removed
692 static void __exit
igb_exit_module(void)
694 #ifdef CONFIG_IGB_DCA
695 dca_unregister_notify(&dca_notifier
);
697 pci_unregister_driver(&igb_driver
);
700 module_exit(igb_exit_module
);
702 #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
704 * igb_cache_ring_register - Descriptor ring to register mapping
705 * @adapter: board private structure to initialize
707 * Once we know the feature-set enabled for the device, we'll cache
708 * the register offset the descriptor ring is assigned to.
710 static void igb_cache_ring_register(struct igb_adapter
*adapter
)
713 u32 rbase_offset
= adapter
->vfs_allocated_count
;
715 switch (adapter
->hw
.mac
.type
) {
717 /* The queues are allocated for virtualization such that VF 0
718 * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
719 * In order to avoid collision we start at the first free queue
720 * and continue consuming queues in the same sequence
722 if (adapter
->vfs_allocated_count
) {
723 for (; i
< adapter
->rss_queues
; i
++)
724 adapter
->rx_ring
[i
]->reg_idx
= rbase_offset
+
736 for (; i
< adapter
->num_rx_queues
; i
++)
737 adapter
->rx_ring
[i
]->reg_idx
= rbase_offset
+ i
;
738 for (; j
< adapter
->num_tx_queues
; j
++)
739 adapter
->tx_ring
[j
]->reg_idx
= rbase_offset
+ j
;
744 u32
igb_rd32(struct e1000_hw
*hw
, u32 reg
)
746 struct igb_adapter
*igb
= container_of(hw
, struct igb_adapter
, hw
);
747 u8 __iomem
*hw_addr
= READ_ONCE(hw
->hw_addr
);
750 if (E1000_REMOVED(hw_addr
))
753 value
= readl(&hw_addr
[reg
]);
755 /* reads should not return all F's */
756 if (!(~value
) && (!reg
|| !(~readl(hw_addr
)))) {
757 struct net_device
*netdev
= igb
->netdev
;
759 netdev_err(netdev
, "PCIe link lost\n");
766 * igb_write_ivar - configure ivar for given MSI-X vector
767 * @hw: pointer to the HW structure
768 * @msix_vector: vector number we are allocating to a given ring
769 * @index: row index of IVAR register to write within IVAR table
770 * @offset: column offset of in IVAR, should be multiple of 8
772 * This function is intended to handle the writing of the IVAR register
773 * for adapters 82576 and newer. The IVAR table consists of 2 columns,
774 * each containing an cause allocation for an Rx and Tx ring, and a
775 * variable number of rows depending on the number of queues supported.
777 static void igb_write_ivar(struct e1000_hw
*hw
, int msix_vector
,
778 int index
, int offset
)
780 u32 ivar
= array_rd32(E1000_IVAR0
, index
);
782 /* clear any bits that are currently set */
783 ivar
&= ~((u32
)0xFF << offset
);
785 /* write vector and valid bit */
786 ivar
|= (msix_vector
| E1000_IVAR_VALID
) << offset
;
788 array_wr32(E1000_IVAR0
, index
, ivar
);
791 #define IGB_N0_QUEUE -1
792 static void igb_assign_vector(struct igb_q_vector
*q_vector
, int msix_vector
)
794 struct igb_adapter
*adapter
= q_vector
->adapter
;
795 struct e1000_hw
*hw
= &adapter
->hw
;
796 int rx_queue
= IGB_N0_QUEUE
;
797 int tx_queue
= IGB_N0_QUEUE
;
800 if (q_vector
->rx
.ring
)
801 rx_queue
= q_vector
->rx
.ring
->reg_idx
;
802 if (q_vector
->tx
.ring
)
803 tx_queue
= q_vector
->tx
.ring
->reg_idx
;
805 switch (hw
->mac
.type
) {
807 /* The 82575 assigns vectors using a bitmask, which matches the
808 * bitmask for the EICR/EIMS/EIMC registers. To assign one
809 * or more queues to a vector, we write the appropriate bits
810 * into the MSIXBM register for that vector.
812 if (rx_queue
> IGB_N0_QUEUE
)
813 msixbm
= E1000_EICR_RX_QUEUE0
<< rx_queue
;
814 if (tx_queue
> IGB_N0_QUEUE
)
815 msixbm
|= E1000_EICR_TX_QUEUE0
<< tx_queue
;
816 if (!(adapter
->flags
& IGB_FLAG_HAS_MSIX
) && msix_vector
== 0)
817 msixbm
|= E1000_EIMS_OTHER
;
818 array_wr32(E1000_MSIXBM(0), msix_vector
, msixbm
);
819 q_vector
->eims_value
= msixbm
;
822 /* 82576 uses a table that essentially consists of 2 columns
823 * with 8 rows. The ordering is column-major so we use the
824 * lower 3 bits as the row index, and the 4th bit as the
827 if (rx_queue
> IGB_N0_QUEUE
)
828 igb_write_ivar(hw
, msix_vector
,
830 (rx_queue
& 0x8) << 1);
831 if (tx_queue
> IGB_N0_QUEUE
)
832 igb_write_ivar(hw
, msix_vector
,
834 ((tx_queue
& 0x8) << 1) + 8);
835 q_vector
->eims_value
= BIT(msix_vector
);
842 /* On 82580 and newer adapters the scheme is similar to 82576
843 * however instead of ordering column-major we have things
844 * ordered row-major. So we traverse the table by using
845 * bit 0 as the column offset, and the remaining bits as the
848 if (rx_queue
> IGB_N0_QUEUE
)
849 igb_write_ivar(hw
, msix_vector
,
851 (rx_queue
& 0x1) << 4);
852 if (tx_queue
> IGB_N0_QUEUE
)
853 igb_write_ivar(hw
, msix_vector
,
855 ((tx_queue
& 0x1) << 4) + 8);
856 q_vector
->eims_value
= BIT(msix_vector
);
863 /* add q_vector eims value to global eims_enable_mask */
864 adapter
->eims_enable_mask
|= q_vector
->eims_value
;
866 /* configure q_vector to set itr on first interrupt */
867 q_vector
->set_itr
= 1;
871 * igb_configure_msix - Configure MSI-X hardware
872 * @adapter: board private structure to initialize
874 * igb_configure_msix sets up the hardware to properly
875 * generate MSI-X interrupts.
877 static void igb_configure_msix(struct igb_adapter
*adapter
)
881 struct e1000_hw
*hw
= &adapter
->hw
;
883 adapter
->eims_enable_mask
= 0;
885 /* set vector for other causes, i.e. link changes */
886 switch (hw
->mac
.type
) {
888 tmp
= rd32(E1000_CTRL_EXT
);
889 /* enable MSI-X PBA support*/
890 tmp
|= E1000_CTRL_EXT_PBA_CLR
;
892 /* Auto-Mask interrupts upon ICR read. */
893 tmp
|= E1000_CTRL_EXT_EIAME
;
894 tmp
|= E1000_CTRL_EXT_IRCA
;
896 wr32(E1000_CTRL_EXT
, tmp
);
898 /* enable msix_other interrupt */
899 array_wr32(E1000_MSIXBM(0), vector
++, E1000_EIMS_OTHER
);
900 adapter
->eims_other
= E1000_EIMS_OTHER
;
910 /* Turn on MSI-X capability first, or our settings
911 * won't stick. And it will take days to debug.
913 wr32(E1000_GPIE
, E1000_GPIE_MSIX_MODE
|
914 E1000_GPIE_PBA
| E1000_GPIE_EIAME
|
917 /* enable msix_other interrupt */
918 adapter
->eims_other
= BIT(vector
);
919 tmp
= (vector
++ | E1000_IVAR_VALID
) << 8;
921 wr32(E1000_IVAR_MISC
, tmp
);
924 /* do nothing, since nothing else supports MSI-X */
926 } /* switch (hw->mac.type) */
928 adapter
->eims_enable_mask
|= adapter
->eims_other
;
930 for (i
= 0; i
< adapter
->num_q_vectors
; i
++)
931 igb_assign_vector(adapter
->q_vector
[i
], vector
++);
937 * igb_request_msix - Initialize MSI-X interrupts
938 * @adapter: board private structure to initialize
940 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
943 static int igb_request_msix(struct igb_adapter
*adapter
)
945 struct net_device
*netdev
= adapter
->netdev
;
946 int i
, err
= 0, vector
= 0, free_vector
= 0;
948 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
949 igb_msix_other
, 0, netdev
->name
, adapter
);
953 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
954 struct igb_q_vector
*q_vector
= adapter
->q_vector
[i
];
958 q_vector
->itr_register
= adapter
->io_addr
+ E1000_EITR(vector
);
960 if (q_vector
->rx
.ring
&& q_vector
->tx
.ring
)
961 sprintf(q_vector
->name
, "%s-TxRx-%u", netdev
->name
,
962 q_vector
->rx
.ring
->queue_index
);
963 else if (q_vector
->tx
.ring
)
964 sprintf(q_vector
->name
, "%s-tx-%u", netdev
->name
,
965 q_vector
->tx
.ring
->queue_index
);
966 else if (q_vector
->rx
.ring
)
967 sprintf(q_vector
->name
, "%s-rx-%u", netdev
->name
,
968 q_vector
->rx
.ring
->queue_index
);
970 sprintf(q_vector
->name
, "%s-unused", netdev
->name
);
972 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
973 igb_msix_ring
, 0, q_vector
->name
,
979 igb_configure_msix(adapter
);
983 /* free already assigned IRQs */
984 free_irq(adapter
->msix_entries
[free_vector
++].vector
, adapter
);
987 for (i
= 0; i
< vector
; i
++) {
988 free_irq(adapter
->msix_entries
[free_vector
++].vector
,
989 adapter
->q_vector
[i
]);
996 * igb_free_q_vector - Free memory allocated for specific interrupt vector
997 * @adapter: board private structure to initialize
998 * @v_idx: Index of vector to be freed
1000 * This function frees the memory allocated to the q_vector.
1002 static void igb_free_q_vector(struct igb_adapter
*adapter
, int v_idx
)
1004 struct igb_q_vector
*q_vector
= adapter
->q_vector
[v_idx
];
1006 adapter
->q_vector
[v_idx
] = NULL
;
1008 /* igb_get_stats64() might access the rings on this vector,
1009 * we must wait a grace period before freeing it.
1012 kfree_rcu(q_vector
, rcu
);
1016 * igb_reset_q_vector - Reset config for interrupt vector
1017 * @adapter: board private structure to initialize
1018 * @v_idx: Index of vector to be reset
1020 * If NAPI is enabled it will delete any references to the
1021 * NAPI struct. This is preparation for igb_free_q_vector.
1023 static void igb_reset_q_vector(struct igb_adapter
*adapter
, int v_idx
)
1025 struct igb_q_vector
*q_vector
= adapter
->q_vector
[v_idx
];
1027 /* Coming from igb_set_interrupt_capability, the vectors are not yet
1028 * allocated. So, q_vector is NULL so we should stop here.
1033 if (q_vector
->tx
.ring
)
1034 adapter
->tx_ring
[q_vector
->tx
.ring
->queue_index
] = NULL
;
1036 if (q_vector
->rx
.ring
)
1037 adapter
->rx_ring
[q_vector
->rx
.ring
->queue_index
] = NULL
;
1039 netif_napi_del(&q_vector
->napi
);
1043 static void igb_reset_interrupt_capability(struct igb_adapter
*adapter
)
1045 int v_idx
= adapter
->num_q_vectors
;
1047 if (adapter
->flags
& IGB_FLAG_HAS_MSIX
)
1048 pci_disable_msix(adapter
->pdev
);
1049 else if (adapter
->flags
& IGB_FLAG_HAS_MSI
)
1050 pci_disable_msi(adapter
->pdev
);
1053 igb_reset_q_vector(adapter
, v_idx
);
1057 * igb_free_q_vectors - Free memory allocated for interrupt vectors
1058 * @adapter: board private structure to initialize
1060 * This function frees the memory allocated to the q_vectors. In addition if
1061 * NAPI is enabled it will delete any references to the NAPI struct prior
1062 * to freeing the q_vector.
1064 static void igb_free_q_vectors(struct igb_adapter
*adapter
)
1066 int v_idx
= adapter
->num_q_vectors
;
1068 adapter
->num_tx_queues
= 0;
1069 adapter
->num_rx_queues
= 0;
1070 adapter
->num_q_vectors
= 0;
1073 igb_reset_q_vector(adapter
, v_idx
);
1074 igb_free_q_vector(adapter
, v_idx
);
1079 * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
1080 * @adapter: board private structure to initialize
1082 * This function resets the device so that it has 0 Rx queues, Tx queues, and
1083 * MSI-X interrupts allocated.
1085 static void igb_clear_interrupt_scheme(struct igb_adapter
*adapter
)
1087 igb_free_q_vectors(adapter
);
1088 igb_reset_interrupt_capability(adapter
);
1092 * igb_set_interrupt_capability - set MSI or MSI-X if supported
1093 * @adapter: board private structure to initialize
1094 * @msix: boolean value of MSIX capability
1096 * Attempt to configure interrupts using the best available
1097 * capabilities of the hardware and kernel.
1099 static void igb_set_interrupt_capability(struct igb_adapter
*adapter
, bool msix
)
1106 adapter
->flags
|= IGB_FLAG_HAS_MSIX
;
1108 /* Number of supported queues. */
1109 adapter
->num_rx_queues
= adapter
->rss_queues
;
1110 if (adapter
->vfs_allocated_count
)
1111 adapter
->num_tx_queues
= 1;
1113 adapter
->num_tx_queues
= adapter
->rss_queues
;
1115 /* start with one vector for every Rx queue */
1116 numvecs
= adapter
->num_rx_queues
;
1118 /* if Tx handler is separate add 1 for every Tx queue */
1119 if (!(adapter
->flags
& IGB_FLAG_QUEUE_PAIRS
))
1120 numvecs
+= adapter
->num_tx_queues
;
1122 /* store the number of vectors reserved for queues */
1123 adapter
->num_q_vectors
= numvecs
;
1125 /* add 1 vector for link status interrupts */
1127 for (i
= 0; i
< numvecs
; i
++)
1128 adapter
->msix_entries
[i
].entry
= i
;
1130 err
= pci_enable_msix_range(adapter
->pdev
,
1131 adapter
->msix_entries
,
1137 igb_reset_interrupt_capability(adapter
);
1139 /* If we can't do MSI-X, try MSI */
1141 adapter
->flags
&= ~IGB_FLAG_HAS_MSIX
;
1142 #ifdef CONFIG_PCI_IOV
1143 /* disable SR-IOV for non MSI-X configurations */
1144 if (adapter
->vf_data
) {
1145 struct e1000_hw
*hw
= &adapter
->hw
;
1146 /* disable iov and allow time for transactions to clear */
1147 pci_disable_sriov(adapter
->pdev
);
1150 kfree(adapter
->vf_mac_list
);
1151 adapter
->vf_mac_list
= NULL
;
1152 kfree(adapter
->vf_data
);
1153 adapter
->vf_data
= NULL
;
1154 wr32(E1000_IOVCTL
, E1000_IOVCTL_REUSE_VFQ
);
1157 dev_info(&adapter
->pdev
->dev
, "IOV Disabled\n");
1160 adapter
->vfs_allocated_count
= 0;
1161 adapter
->rss_queues
= 1;
1162 adapter
->flags
|= IGB_FLAG_QUEUE_PAIRS
;
1163 adapter
->num_rx_queues
= 1;
1164 adapter
->num_tx_queues
= 1;
1165 adapter
->num_q_vectors
= 1;
1166 if (!pci_enable_msi(adapter
->pdev
))
1167 adapter
->flags
|= IGB_FLAG_HAS_MSI
;
1170 static void igb_add_ring(struct igb_ring
*ring
,
1171 struct igb_ring_container
*head
)
1178 * igb_alloc_q_vector - Allocate memory for a single interrupt vector
1179 * @adapter: board private structure to initialize
1180 * @v_count: q_vectors allocated on adapter, used for ring interleaving
1181 * @v_idx: index of vector in adapter struct
1182 * @txr_count: total number of Tx rings to allocate
1183 * @txr_idx: index of first Tx ring to allocate
1184 * @rxr_count: total number of Rx rings to allocate
1185 * @rxr_idx: index of first Rx ring to allocate
1187 * We allocate one q_vector. If allocation fails we return -ENOMEM.
1189 static int igb_alloc_q_vector(struct igb_adapter
*adapter
,
1190 int v_count
, int v_idx
,
1191 int txr_count
, int txr_idx
,
1192 int rxr_count
, int rxr_idx
)
1194 struct igb_q_vector
*q_vector
;
1195 struct igb_ring
*ring
;
1196 int ring_count
, size
;
1198 /* igb only supports 1 Tx and/or 1 Rx queue per vector */
1199 if (txr_count
> 1 || rxr_count
> 1)
1202 ring_count
= txr_count
+ rxr_count
;
1203 size
= sizeof(struct igb_q_vector
) +
1204 (sizeof(struct igb_ring
) * ring_count
);
1206 /* allocate q_vector and rings */
1207 q_vector
= adapter
->q_vector
[v_idx
];
1209 q_vector
= kzalloc(size
, GFP_KERNEL
);
1210 } else if (size
> ksize(q_vector
)) {
1211 kfree_rcu(q_vector
, rcu
);
1212 q_vector
= kzalloc(size
, GFP_KERNEL
);
1214 memset(q_vector
, 0, size
);
1219 /* initialize NAPI */
1220 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
1223 /* tie q_vector and adapter together */
1224 adapter
->q_vector
[v_idx
] = q_vector
;
1225 q_vector
->adapter
= adapter
;
1227 /* initialize work limits */
1228 q_vector
->tx
.work_limit
= adapter
->tx_work_limit
;
1230 /* initialize ITR configuration */
1231 q_vector
->itr_register
= adapter
->io_addr
+ E1000_EITR(0);
1232 q_vector
->itr_val
= IGB_START_ITR
;
1234 /* initialize pointer to rings */
1235 ring
= q_vector
->ring
;
1239 /* rx or rx/tx vector */
1240 if (!adapter
->rx_itr_setting
|| adapter
->rx_itr_setting
> 3)
1241 q_vector
->itr_val
= adapter
->rx_itr_setting
;
1243 /* tx only vector */
1244 if (!adapter
->tx_itr_setting
|| adapter
->tx_itr_setting
> 3)
1245 q_vector
->itr_val
= adapter
->tx_itr_setting
;
1249 /* assign generic ring traits */
1250 ring
->dev
= &adapter
->pdev
->dev
;
1251 ring
->netdev
= adapter
->netdev
;
1253 /* configure backlink on ring */
1254 ring
->q_vector
= q_vector
;
1256 /* update q_vector Tx values */
1257 igb_add_ring(ring
, &q_vector
->tx
);
1259 /* For 82575, context index must be unique per ring. */
1260 if (adapter
->hw
.mac
.type
== e1000_82575
)
1261 set_bit(IGB_RING_FLAG_TX_CTX_IDX
, &ring
->flags
);
1263 /* apply Tx specific ring traits */
1264 ring
->count
= adapter
->tx_ring_count
;
1265 ring
->queue_index
= txr_idx
;
1267 ring
->cbs_enable
= false;
1268 ring
->idleslope
= 0;
1269 ring
->sendslope
= 0;
1273 u64_stats_init(&ring
->tx_syncp
);
1274 u64_stats_init(&ring
->tx_syncp2
);
1276 /* assign ring to adapter */
1277 adapter
->tx_ring
[txr_idx
] = ring
;
1279 /* push pointer to next ring */
1284 /* assign generic ring traits */
1285 ring
->dev
= &adapter
->pdev
->dev
;
1286 ring
->netdev
= adapter
->netdev
;
1288 /* configure backlink on ring */
1289 ring
->q_vector
= q_vector
;
1291 /* update q_vector Rx values */
1292 igb_add_ring(ring
, &q_vector
->rx
);
1294 /* set flag indicating ring supports SCTP checksum offload */
1295 if (adapter
->hw
.mac
.type
>= e1000_82576
)
1296 set_bit(IGB_RING_FLAG_RX_SCTP_CSUM
, &ring
->flags
);
1298 /* On i350, i354, i210, and i211, loopback VLAN packets
1299 * have the tag byte-swapped.
1301 if (adapter
->hw
.mac
.type
>= e1000_i350
)
1302 set_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP
, &ring
->flags
);
1304 /* apply Rx specific ring traits */
1305 ring
->count
= adapter
->rx_ring_count
;
1306 ring
->queue_index
= rxr_idx
;
1308 u64_stats_init(&ring
->rx_syncp
);
1310 /* assign ring to adapter */
1311 adapter
->rx_ring
[rxr_idx
] = ring
;
1319 * igb_alloc_q_vectors - Allocate memory for interrupt vectors
1320 * @adapter: board private structure to initialize
1322 * We allocate one q_vector per queue interrupt. If allocation fails we
1325 static int igb_alloc_q_vectors(struct igb_adapter
*adapter
)
1327 int q_vectors
= adapter
->num_q_vectors
;
1328 int rxr_remaining
= adapter
->num_rx_queues
;
1329 int txr_remaining
= adapter
->num_tx_queues
;
1330 int rxr_idx
= 0, txr_idx
= 0, v_idx
= 0;
1333 if (q_vectors
>= (rxr_remaining
+ txr_remaining
)) {
1334 for (; rxr_remaining
; v_idx
++) {
1335 err
= igb_alloc_q_vector(adapter
, q_vectors
, v_idx
,
1341 /* update counts and index */
1347 for (; v_idx
< q_vectors
; v_idx
++) {
1348 int rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- v_idx
);
1349 int tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- v_idx
);
1351 err
= igb_alloc_q_vector(adapter
, q_vectors
, v_idx
,
1352 tqpv
, txr_idx
, rqpv
, rxr_idx
);
1357 /* update counts and index */
1358 rxr_remaining
-= rqpv
;
1359 txr_remaining
-= tqpv
;
1367 adapter
->num_tx_queues
= 0;
1368 adapter
->num_rx_queues
= 0;
1369 adapter
->num_q_vectors
= 0;
1372 igb_free_q_vector(adapter
, v_idx
);
1378 * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
1379 * @adapter: board private structure to initialize
1380 * @msix: boolean value of MSIX capability
1382 * This function initializes the interrupts and allocates all of the queues.
1384 static int igb_init_interrupt_scheme(struct igb_adapter
*adapter
, bool msix
)
1386 struct pci_dev
*pdev
= adapter
->pdev
;
1389 igb_set_interrupt_capability(adapter
, msix
);
1391 err
= igb_alloc_q_vectors(adapter
);
1393 dev_err(&pdev
->dev
, "Unable to allocate memory for vectors\n");
1394 goto err_alloc_q_vectors
;
1397 igb_cache_ring_register(adapter
);
1401 err_alloc_q_vectors
:
1402 igb_reset_interrupt_capability(adapter
);
1407 * igb_request_irq - initialize interrupts
1408 * @adapter: board private structure to initialize
1410 * Attempts to configure interrupts using the best available
1411 * capabilities of the hardware and kernel.
1413 static int igb_request_irq(struct igb_adapter
*adapter
)
1415 struct net_device
*netdev
= adapter
->netdev
;
1416 struct pci_dev
*pdev
= adapter
->pdev
;
1419 if (adapter
->flags
& IGB_FLAG_HAS_MSIX
) {
1420 err
= igb_request_msix(adapter
);
1423 /* fall back to MSI */
1424 igb_free_all_tx_resources(adapter
);
1425 igb_free_all_rx_resources(adapter
);
1427 igb_clear_interrupt_scheme(adapter
);
1428 err
= igb_init_interrupt_scheme(adapter
, false);
1432 igb_setup_all_tx_resources(adapter
);
1433 igb_setup_all_rx_resources(adapter
);
1434 igb_configure(adapter
);
1437 igb_assign_vector(adapter
->q_vector
[0], 0);
1439 if (adapter
->flags
& IGB_FLAG_HAS_MSI
) {
1440 err
= request_irq(pdev
->irq
, igb_intr_msi
, 0,
1441 netdev
->name
, adapter
);
1445 /* fall back to legacy interrupts */
1446 igb_reset_interrupt_capability(adapter
);
1447 adapter
->flags
&= ~IGB_FLAG_HAS_MSI
;
1450 err
= request_irq(pdev
->irq
, igb_intr
, IRQF_SHARED
,
1451 netdev
->name
, adapter
);
1454 dev_err(&pdev
->dev
, "Error %d getting interrupt\n",
1461 static void igb_free_irq(struct igb_adapter
*adapter
)
1463 if (adapter
->flags
& IGB_FLAG_HAS_MSIX
) {
1466 free_irq(adapter
->msix_entries
[vector
++].vector
, adapter
);
1468 for (i
= 0; i
< adapter
->num_q_vectors
; i
++)
1469 free_irq(adapter
->msix_entries
[vector
++].vector
,
1470 adapter
->q_vector
[i
]);
1472 free_irq(adapter
->pdev
->irq
, adapter
);
1477 * igb_irq_disable - Mask off interrupt generation on the NIC
1478 * @adapter: board private structure
1480 static void igb_irq_disable(struct igb_adapter
*adapter
)
1482 struct e1000_hw
*hw
= &adapter
->hw
;
1484 /* we need to be careful when disabling interrupts. The VFs are also
1485 * mapped into these registers and so clearing the bits can cause
1486 * issues on the VF drivers so we only need to clear what we set
1488 if (adapter
->flags
& IGB_FLAG_HAS_MSIX
) {
1489 u32 regval
= rd32(E1000_EIAM
);
1491 wr32(E1000_EIAM
, regval
& ~adapter
->eims_enable_mask
);
1492 wr32(E1000_EIMC
, adapter
->eims_enable_mask
);
1493 regval
= rd32(E1000_EIAC
);
1494 wr32(E1000_EIAC
, regval
& ~adapter
->eims_enable_mask
);
1498 wr32(E1000_IMC
, ~0);
1500 if (adapter
->flags
& IGB_FLAG_HAS_MSIX
) {
1503 for (i
= 0; i
< adapter
->num_q_vectors
; i
++)
1504 synchronize_irq(adapter
->msix_entries
[i
].vector
);
1506 synchronize_irq(adapter
->pdev
->irq
);
1511 * igb_irq_enable - Enable default interrupt generation settings
1512 * @adapter: board private structure
1514 static void igb_irq_enable(struct igb_adapter
*adapter
)
1516 struct e1000_hw
*hw
= &adapter
->hw
;
1518 if (adapter
->flags
& IGB_FLAG_HAS_MSIX
) {
1519 u32 ims
= E1000_IMS_LSC
| E1000_IMS_DOUTSYNC
| E1000_IMS_DRSTA
;
1520 u32 regval
= rd32(E1000_EIAC
);
1522 wr32(E1000_EIAC
, regval
| adapter
->eims_enable_mask
);
1523 regval
= rd32(E1000_EIAM
);
1524 wr32(E1000_EIAM
, regval
| adapter
->eims_enable_mask
);
1525 wr32(E1000_EIMS
, adapter
->eims_enable_mask
);
1526 if (adapter
->vfs_allocated_count
) {
1527 wr32(E1000_MBVFIMR
, 0xFF);
1528 ims
|= E1000_IMS_VMMB
;
1530 wr32(E1000_IMS
, ims
);
1532 wr32(E1000_IMS
, IMS_ENABLE_MASK
|
1534 wr32(E1000_IAM
, IMS_ENABLE_MASK
|
1539 static void igb_update_mng_vlan(struct igb_adapter
*adapter
)
1541 struct e1000_hw
*hw
= &adapter
->hw
;
1542 u16 pf_id
= adapter
->vfs_allocated_count
;
1543 u16 vid
= adapter
->hw
.mng_cookie
.vlan_id
;
1544 u16 old_vid
= adapter
->mng_vlan_id
;
1546 if (hw
->mng_cookie
.status
& E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) {
1547 /* add VID to filter table */
1548 igb_vfta_set(hw
, vid
, pf_id
, true, true);
1549 adapter
->mng_vlan_id
= vid
;
1551 adapter
->mng_vlan_id
= IGB_MNG_VLAN_NONE
;
1554 if ((old_vid
!= (u16
)IGB_MNG_VLAN_NONE
) &&
1556 !test_bit(old_vid
, adapter
->active_vlans
)) {
1557 /* remove VID from filter table */
1558 igb_vfta_set(hw
, vid
, pf_id
, false, true);
1563 * igb_release_hw_control - release control of the h/w to f/w
1564 * @adapter: address of board private structure
1566 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
1567 * For ASF and Pass Through versions of f/w this means that the
1568 * driver is no longer loaded.
1570 static void igb_release_hw_control(struct igb_adapter
*adapter
)
1572 struct e1000_hw
*hw
= &adapter
->hw
;
1575 /* Let firmware take over control of h/w */
1576 ctrl_ext
= rd32(E1000_CTRL_EXT
);
1577 wr32(E1000_CTRL_EXT
,
1578 ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
1582 * igb_get_hw_control - get control of the h/w from f/w
1583 * @adapter: address of board private structure
1585 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
1586 * For ASF and Pass Through versions of f/w this means that
1587 * the driver is loaded.
1589 static void igb_get_hw_control(struct igb_adapter
*adapter
)
1591 struct e1000_hw
*hw
= &adapter
->hw
;
1594 /* Let firmware know the driver has taken over */
1595 ctrl_ext
= rd32(E1000_CTRL_EXT
);
1596 wr32(E1000_CTRL_EXT
,
1597 ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
1600 static void enable_fqtss(struct igb_adapter
*adapter
, bool enable
)
1602 struct net_device
*netdev
= adapter
->netdev
;
1603 struct e1000_hw
*hw
= &adapter
->hw
;
1605 WARN_ON(hw
->mac
.type
!= e1000_i210
);
1608 adapter
->flags
|= IGB_FLAG_FQTSS
;
1610 adapter
->flags
&= ~IGB_FLAG_FQTSS
;
1612 if (netif_running(netdev
))
1613 schedule_work(&adapter
->reset_task
);
1616 static bool is_fqtss_enabled(struct igb_adapter
*adapter
)
1618 return (adapter
->flags
& IGB_FLAG_FQTSS
) ? true : false;
1621 static void set_tx_desc_fetch_prio(struct e1000_hw
*hw
, int queue
,
1622 enum tx_queue_prio prio
)
1626 WARN_ON(hw
->mac
.type
!= e1000_i210
);
1627 WARN_ON(queue
< 0 || queue
> 4);
1629 val
= rd32(E1000_I210_TXDCTL(queue
));
1631 if (prio
== TX_QUEUE_PRIO_HIGH
)
1632 val
|= E1000_TXDCTL_PRIORITY
;
1634 val
&= ~E1000_TXDCTL_PRIORITY
;
1636 wr32(E1000_I210_TXDCTL(queue
), val
);
1639 static void set_queue_mode(struct e1000_hw
*hw
, int queue
, enum queue_mode mode
)
1643 WARN_ON(hw
->mac
.type
!= e1000_i210
);
1644 WARN_ON(queue
< 0 || queue
> 1);
1646 val
= rd32(E1000_I210_TQAVCC(queue
));
1648 if (mode
== QUEUE_MODE_STREAM_RESERVATION
)
1649 val
|= E1000_TQAVCC_QUEUEMODE
;
1651 val
&= ~E1000_TQAVCC_QUEUEMODE
;
1653 wr32(E1000_I210_TQAVCC(queue
), val
);
1656 static bool is_any_cbs_enabled(struct igb_adapter
*adapter
)
1660 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1661 if (adapter
->tx_ring
[i
]->cbs_enable
)
1668 static bool is_any_txtime_enabled(struct igb_adapter
*adapter
)
1672 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1673 if (adapter
->tx_ring
[i
]->launchtime_enable
)
1681 * igb_config_tx_modes - Configure "Qav Tx mode" features on igb
1682 * @adapter: pointer to adapter struct
1683 * @queue: queue number
1685 * Configure CBS and Launchtime for a given hardware queue.
1686 * Parameters are retrieved from the correct Tx ring, so
1687 * igb_save_cbs_params() and igb_save_txtime_params() should be used
1688 * for setting those correctly prior to this function being called.
1690 static void igb_config_tx_modes(struct igb_adapter
*adapter
, int queue
)
1692 struct igb_ring
*ring
= adapter
->tx_ring
[queue
];
1693 struct net_device
*netdev
= adapter
->netdev
;
1694 struct e1000_hw
*hw
= &adapter
->hw
;
1695 u32 tqavcc
, tqavctrl
;
1698 WARN_ON(hw
->mac
.type
!= e1000_i210
);
1699 WARN_ON(queue
< 0 || queue
> 1);
1701 /* If any of the Qav features is enabled, configure queues as SR and
1702 * with HIGH PRIO. If none is, then configure them with LOW PRIO and
1705 if (ring
->cbs_enable
|| ring
->launchtime_enable
) {
1706 set_tx_desc_fetch_prio(hw
, queue
, TX_QUEUE_PRIO_HIGH
);
1707 set_queue_mode(hw
, queue
, QUEUE_MODE_STREAM_RESERVATION
);
1709 set_tx_desc_fetch_prio(hw
, queue
, TX_QUEUE_PRIO_LOW
);
1710 set_queue_mode(hw
, queue
, QUEUE_MODE_STRICT_PRIORITY
);
1713 /* If CBS is enabled, set DataTranARB and config its parameters. */
1714 if (ring
->cbs_enable
|| queue
== 0) {
1715 /* i210 does not allow the queue 0 to be in the Strict
1716 * Priority mode while the Qav mode is enabled, so,
1717 * instead of disabling strict priority mode, we give
1718 * queue 0 the maximum of credits possible.
1720 * See section 8.12.19 of the i210 datasheet, "Note:
1721 * Queue0 QueueMode must be set to 1b when
1722 * TransmitMode is set to Qav."
1724 if (queue
== 0 && !ring
->cbs_enable
) {
1725 /* max "linkspeed" idleslope in kbps */
1726 ring
->idleslope
= 1000000;
1727 ring
->hicredit
= ETH_FRAME_LEN
;
1730 /* Always set data transfer arbitration to credit-based
1731 * shaper algorithm on TQAVCTRL if CBS is enabled for any of
1734 tqavctrl
= rd32(E1000_I210_TQAVCTRL
);
1735 tqavctrl
|= E1000_TQAVCTRL_DATATRANARB
;
1736 wr32(E1000_I210_TQAVCTRL
, tqavctrl
);
1738 /* According to i210 datasheet section 7.2.7.7, we should set
1739 * the 'idleSlope' field from TQAVCC register following the
1742 * For 100 Mbps link speed:
1744 * value = BW * 0x7735 * 0.2 (E1)
1746 * For 1000Mbps link speed:
1748 * value = BW * 0x7735 * 2 (E2)
1750 * E1 and E2 can be merged into one equation as shown below.
1751 * Note that 'link-speed' is in Mbps.
1753 * value = BW * 0x7735 * 2 * link-speed
1754 * -------------- (E3)
1757 * 'BW' is the percentage bandwidth out of full link speed
1758 * which can be found with the following equation. Note that
1759 * idleSlope here is the parameter from this function which
1763 * ----------------- (E4)
1766 * That said, we can come up with a generic equation to
1767 * calculate the value we should set it TQAVCC register by
1768 * replacing 'BW' in E3 by E4. The resulting equation is:
1770 * value = idleSlope * 0x7735 * 2 * link-speed
1771 * ----------------- -------------- (E5)
1772 * link-speed * 1000 1000
1774 * 'link-speed' is present in both sides of the fraction so
1775 * it is canceled out. The final equation is the following:
1777 * value = idleSlope * 61034
1778 * ----------------- (E6)
1781 * NOTE: For i210, given the above, we can see that idleslope
1782 * is represented in 16.38431 kbps units by the value at
1783 * the TQAVCC register (1Gbps / 61034), which reduces
1784 * the granularity for idleslope increments.
1785 * For instance, if you want to configure a 2576kbps
1786 * idleslope, the value to be written on the register
1787 * would have to be 157.23. If rounded down, you end
1788 * up with less bandwidth available than originally
1789 * required (~2572 kbps). If rounded up, you end up
1790 * with a higher bandwidth (~2589 kbps). Below the
1791 * approach we take is to always round up the
1792 * calculated value, so the resulting bandwidth might
1793 * be slightly higher for some configurations.
1795 value
= DIV_ROUND_UP_ULL(ring
->idleslope
* 61034ULL, 1000000);
1797 tqavcc
= rd32(E1000_I210_TQAVCC(queue
));
1798 tqavcc
&= ~E1000_TQAVCC_IDLESLOPE_MASK
;
1800 wr32(E1000_I210_TQAVCC(queue
), tqavcc
);
1802 wr32(E1000_I210_TQAVHC(queue
),
1803 0x80000000 + ring
->hicredit
* 0x7735);
1806 /* Set idleSlope to zero. */
1807 tqavcc
= rd32(E1000_I210_TQAVCC(queue
));
1808 tqavcc
&= ~E1000_TQAVCC_IDLESLOPE_MASK
;
1809 wr32(E1000_I210_TQAVCC(queue
), tqavcc
);
1811 /* Set hiCredit to zero. */
1812 wr32(E1000_I210_TQAVHC(queue
), 0);
1814 /* If CBS is not enabled for any queues anymore, then return to
1815 * the default state of Data Transmission Arbitration on
1818 if (!is_any_cbs_enabled(adapter
)) {
1819 tqavctrl
= rd32(E1000_I210_TQAVCTRL
);
1820 tqavctrl
&= ~E1000_TQAVCTRL_DATATRANARB
;
1821 wr32(E1000_I210_TQAVCTRL
, tqavctrl
);
1825 /* If LaunchTime is enabled, set DataTranTIM. */
1826 if (ring
->launchtime_enable
) {
1827 /* Always set DataTranTIM on TQAVCTRL if LaunchTime is enabled
1828 * for any of the SR queues, and configure fetchtime delta.
1830 * - LaunchTime will be enabled for all SR queues.
1831 * - A fixed offset can be added relative to the launch
1832 * time of all packets if configured at reg LAUNCH_OS0.
1833 * We are keeping it as 0 for now (default value).
1835 tqavctrl
= rd32(E1000_I210_TQAVCTRL
);
1836 tqavctrl
|= E1000_TQAVCTRL_DATATRANTIM
|
1837 E1000_TQAVCTRL_FETCHTIME_DELTA
;
1838 wr32(E1000_I210_TQAVCTRL
, tqavctrl
);
1840 /* If Launchtime is not enabled for any SR queues anymore,
1841 * then clear DataTranTIM on TQAVCTRL and clear fetchtime delta,
1842 * effectively disabling Launchtime.
1844 if (!is_any_txtime_enabled(adapter
)) {
1845 tqavctrl
= rd32(E1000_I210_TQAVCTRL
);
1846 tqavctrl
&= ~E1000_TQAVCTRL_DATATRANTIM
;
1847 tqavctrl
&= ~E1000_TQAVCTRL_FETCHTIME_DELTA
;
1848 wr32(E1000_I210_TQAVCTRL
, tqavctrl
);
1852 /* XXX: In i210 controller the sendSlope and loCredit parameters from
1853 * CBS are not configurable by software so we don't do any 'controller
1854 * configuration' in respect to these parameters.
1857 netdev_dbg(netdev
, "Qav Tx mode: cbs %s, launchtime %s, queue %d \
1858 idleslope %d sendslope %d hiCredit %d \
1860 (ring
->cbs_enable
) ? "enabled" : "disabled",
1861 (ring
->launchtime_enable
) ? "enabled" : "disabled", queue
,
1862 ring
->idleslope
, ring
->sendslope
, ring
->hicredit
,
1866 static int igb_save_txtime_params(struct igb_adapter
*adapter
, int queue
,
1869 struct igb_ring
*ring
;
1871 if (queue
< 0 || queue
> adapter
->num_tx_queues
)
1874 ring
= adapter
->tx_ring
[queue
];
1875 ring
->launchtime_enable
= enable
;
1880 static int igb_save_cbs_params(struct igb_adapter
*adapter
, int queue
,
1881 bool enable
, int idleslope
, int sendslope
,
1882 int hicredit
, int locredit
)
1884 struct igb_ring
*ring
;
1886 if (queue
< 0 || queue
> adapter
->num_tx_queues
)
1889 ring
= adapter
->tx_ring
[queue
];
1891 ring
->cbs_enable
= enable
;
1892 ring
->idleslope
= idleslope
;
1893 ring
->sendslope
= sendslope
;
1894 ring
->hicredit
= hicredit
;
1895 ring
->locredit
= locredit
;
1901 * igb_setup_tx_mode - Switch to/from Qav Tx mode when applicable
1902 * @adapter: pointer to adapter struct
1904 * Configure TQAVCTRL register switching the controller's Tx mode
1905 * if FQTSS mode is enabled or disabled. Additionally, will issue
1906 * a call to igb_config_tx_modes() per queue so any previously saved
1907 * Tx parameters are applied.
1909 static void igb_setup_tx_mode(struct igb_adapter
*adapter
)
1911 struct net_device
*netdev
= adapter
->netdev
;
1912 struct e1000_hw
*hw
= &adapter
->hw
;
1915 /* Only i210 controller supports changing the transmission mode. */
1916 if (hw
->mac
.type
!= e1000_i210
)
1919 if (is_fqtss_enabled(adapter
)) {
1922 /* Configure TQAVCTRL register: set transmit mode to 'Qav',
1923 * set data fetch arbitration to 'round robin', set SP_WAIT_SR
1924 * so SP queues wait for SR ones.
1926 val
= rd32(E1000_I210_TQAVCTRL
);
1927 val
|= E1000_TQAVCTRL_XMIT_MODE
| E1000_TQAVCTRL_SP_WAIT_SR
;
1928 val
&= ~E1000_TQAVCTRL_DATAFETCHARB
;
1929 wr32(E1000_I210_TQAVCTRL
, val
);
1931 /* Configure Tx and Rx packet buffers sizes as described in
1932 * i210 datasheet section 7.2.7.7.
1934 val
= rd32(E1000_TXPBS
);
1935 val
&= ~I210_TXPBSIZE_MASK
;
1936 val
|= I210_TXPBSIZE_PB0_8KB
| I210_TXPBSIZE_PB1_8KB
|
1937 I210_TXPBSIZE_PB2_4KB
| I210_TXPBSIZE_PB3_4KB
;
1938 wr32(E1000_TXPBS
, val
);
1940 val
= rd32(E1000_RXPBS
);
1941 val
&= ~I210_RXPBSIZE_MASK
;
1942 val
|= I210_RXPBSIZE_PB_32KB
;
1943 wr32(E1000_RXPBS
, val
);
1945 /* Section 8.12.9 states that MAX_TPKT_SIZE from DTXMXPKTSZ
1946 * register should not exceed the buffer size programmed in
1947 * TXPBS. The smallest buffer size programmed in TXPBS is 4kB
1948 * so according to the datasheet we should set MAX_TPKT_SIZE to
1951 * However, when we do so, no frame from queue 2 and 3 are
1952 * transmitted. It seems the MAX_TPKT_SIZE should not be great
1953 * or _equal_ to the buffer size programmed in TXPBS. For this
1954 * reason, we set set MAX_ TPKT_SIZE to (4kB - 1) / 64.
1956 val
= (4096 - 1) / 64;
1957 wr32(E1000_I210_DTXMXPKTSZ
, val
);
1959 /* Since FQTSS mode is enabled, apply any CBS configuration
1960 * previously set. If no previous CBS configuration has been
1961 * done, then the initial configuration is applied, which means
1964 max_queue
= (adapter
->num_tx_queues
< I210_SR_QUEUES_NUM
) ?
1965 adapter
->num_tx_queues
: I210_SR_QUEUES_NUM
;
1967 for (i
= 0; i
< max_queue
; i
++) {
1968 igb_config_tx_modes(adapter
, i
);
1971 wr32(E1000_RXPBS
, I210_RXPBSIZE_DEFAULT
);
1972 wr32(E1000_TXPBS
, I210_TXPBSIZE_DEFAULT
);
1973 wr32(E1000_I210_DTXMXPKTSZ
, I210_DTXMXPKTSZ_DEFAULT
);
1975 val
= rd32(E1000_I210_TQAVCTRL
);
1976 /* According to Section 8.12.21, the other flags we've set when
1977 * enabling FQTSS are not relevant when disabling FQTSS so we
1978 * don't set they here.
1980 val
&= ~E1000_TQAVCTRL_XMIT_MODE
;
1981 wr32(E1000_I210_TQAVCTRL
, val
);
1984 netdev_dbg(netdev
, "FQTSS %s\n", (is_fqtss_enabled(adapter
)) ?
1985 "enabled" : "disabled");
1989 * igb_configure - configure the hardware for RX and TX
1990 * @adapter: private board structure
1992 static void igb_configure(struct igb_adapter
*adapter
)
1994 struct net_device
*netdev
= adapter
->netdev
;
1997 igb_get_hw_control(adapter
);
1998 igb_set_rx_mode(netdev
);
1999 igb_setup_tx_mode(adapter
);
2001 igb_restore_vlan(adapter
);
2003 igb_setup_tctl(adapter
);
2004 igb_setup_mrqc(adapter
);
2005 igb_setup_rctl(adapter
);
2007 igb_nfc_filter_restore(adapter
);
2008 igb_configure_tx(adapter
);
2009 igb_configure_rx(adapter
);
2011 igb_rx_fifo_flush_82575(&adapter
->hw
);
2013 /* call igb_desc_unused which always leaves
2014 * at least 1 descriptor unused to make sure
2015 * next_to_use != next_to_clean
2017 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2018 struct igb_ring
*ring
= adapter
->rx_ring
[i
];
2019 igb_alloc_rx_buffers(ring
, igb_desc_unused(ring
));
2024 * igb_power_up_link - Power up the phy/serdes link
2025 * @adapter: address of board private structure
2027 void igb_power_up_link(struct igb_adapter
*adapter
)
2029 igb_reset_phy(&adapter
->hw
);
2031 if (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
)
2032 igb_power_up_phy_copper(&adapter
->hw
);
2034 igb_power_up_serdes_link_82575(&adapter
->hw
);
2036 igb_setup_link(&adapter
->hw
);
2040 * igb_power_down_link - Power down the phy/serdes link
2041 * @adapter: address of board private structure
2043 static void igb_power_down_link(struct igb_adapter
*adapter
)
2045 if (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
)
2046 igb_power_down_phy_copper_82575(&adapter
->hw
);
2048 igb_shutdown_serdes_link_82575(&adapter
->hw
);
2052 * Detect and switch function for Media Auto Sense
2053 * @adapter: address of the board private structure
2055 static void igb_check_swap_media(struct igb_adapter
*adapter
)
2057 struct e1000_hw
*hw
= &adapter
->hw
;
2058 u32 ctrl_ext
, connsw
;
2059 bool swap_now
= false;
2061 ctrl_ext
= rd32(E1000_CTRL_EXT
);
2062 connsw
= rd32(E1000_CONNSW
);
2064 /* need to live swap if current media is copper and we have fiber/serdes
2068 if ((hw
->phy
.media_type
== e1000_media_type_copper
) &&
2069 (!(connsw
& E1000_CONNSW_AUTOSENSE_EN
))) {
2071 } else if (!(connsw
& E1000_CONNSW_SERDESD
)) {
2072 /* copper signal takes time to appear */
2073 if (adapter
->copper_tries
< 4) {
2074 adapter
->copper_tries
++;
2075 connsw
|= E1000_CONNSW_AUTOSENSE_CONF
;
2076 wr32(E1000_CONNSW
, connsw
);
2079 adapter
->copper_tries
= 0;
2080 if ((connsw
& E1000_CONNSW_PHYSD
) &&
2081 (!(connsw
& E1000_CONNSW_PHY_PDN
))) {
2083 connsw
&= ~E1000_CONNSW_AUTOSENSE_CONF
;
2084 wr32(E1000_CONNSW
, connsw
);
2092 switch (hw
->phy
.media_type
) {
2093 case e1000_media_type_copper
:
2094 netdev_info(adapter
->netdev
,
2095 "MAS: changing media to fiber/serdes\n");
2097 E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
;
2098 adapter
->flags
|= IGB_FLAG_MEDIA_RESET
;
2099 adapter
->copper_tries
= 0;
2101 case e1000_media_type_internal_serdes
:
2102 case e1000_media_type_fiber
:
2103 netdev_info(adapter
->netdev
,
2104 "MAS: changing media to copper\n");
2106 ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
;
2107 adapter
->flags
|= IGB_FLAG_MEDIA_RESET
;
2110 /* shouldn't get here during regular operation */
2111 netdev_err(adapter
->netdev
,
2112 "AMS: Invalid media type found, returning\n");
2115 wr32(E1000_CTRL_EXT
, ctrl_ext
);
2119 * igb_up - Open the interface and prepare it to handle traffic
2120 * @adapter: board private structure
2122 int igb_up(struct igb_adapter
*adapter
)
2124 struct e1000_hw
*hw
= &adapter
->hw
;
2127 /* hardware has been reset, we need to reload some things */
2128 igb_configure(adapter
);
2130 clear_bit(__IGB_DOWN
, &adapter
->state
);
2132 for (i
= 0; i
< adapter
->num_q_vectors
; i
++)
2133 napi_enable(&(adapter
->q_vector
[i
]->napi
));
2135 if (adapter
->flags
& IGB_FLAG_HAS_MSIX
)
2136 igb_configure_msix(adapter
);
2138 igb_assign_vector(adapter
->q_vector
[0], 0);
2140 /* Clear any pending interrupts. */
2143 igb_irq_enable(adapter
);
2145 /* notify VFs that reset has been completed */
2146 if (adapter
->vfs_allocated_count
) {
2147 u32 reg_data
= rd32(E1000_CTRL_EXT
);
2149 reg_data
|= E1000_CTRL_EXT_PFRSTD
;
2150 wr32(E1000_CTRL_EXT
, reg_data
);
2153 netif_tx_start_all_queues(adapter
->netdev
);
2155 /* start the watchdog. */
2156 hw
->mac
.get_link_status
= 1;
2157 schedule_work(&adapter
->watchdog_task
);
2159 if ((adapter
->flags
& IGB_FLAG_EEE
) &&
2160 (!hw
->dev_spec
._82575
.eee_disable
))
2161 adapter
->eee_advert
= MDIO_EEE_100TX
| MDIO_EEE_1000T
;
2166 void igb_down(struct igb_adapter
*adapter
)
2168 struct net_device
*netdev
= adapter
->netdev
;
2169 struct e1000_hw
*hw
= &adapter
->hw
;
2173 /* signal that we're down so the interrupt handler does not
2174 * reschedule our watchdog timer
2176 set_bit(__IGB_DOWN
, &adapter
->state
);
2178 /* disable receives in the hardware */
2179 rctl
= rd32(E1000_RCTL
);
2180 wr32(E1000_RCTL
, rctl
& ~E1000_RCTL_EN
);
2181 /* flush and sleep below */
2183 igb_nfc_filter_exit(adapter
);
2185 netif_carrier_off(netdev
);
2186 netif_tx_stop_all_queues(netdev
);
2188 /* disable transmits in the hardware */
2189 tctl
= rd32(E1000_TCTL
);
2190 tctl
&= ~E1000_TCTL_EN
;
2191 wr32(E1000_TCTL
, tctl
);
2192 /* flush both disables and wait for them to finish */
2194 usleep_range(10000, 11000);
2196 igb_irq_disable(adapter
);
2198 adapter
->flags
&= ~IGB_FLAG_NEED_LINK_UPDATE
;
2200 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
2201 if (adapter
->q_vector
[i
]) {
2202 napi_synchronize(&adapter
->q_vector
[i
]->napi
);
2203 napi_disable(&adapter
->q_vector
[i
]->napi
);
2207 del_timer_sync(&adapter
->watchdog_timer
);
2208 del_timer_sync(&adapter
->phy_info_timer
);
2210 /* record the stats before reset*/
2211 spin_lock(&adapter
->stats64_lock
);
2212 igb_update_stats(adapter
);
2213 spin_unlock(&adapter
->stats64_lock
);
2215 adapter
->link_speed
= 0;
2216 adapter
->link_duplex
= 0;
2218 if (!pci_channel_offline(adapter
->pdev
))
2221 /* clear VLAN promisc flag so VFTA will be updated if necessary */
2222 adapter
->flags
&= ~IGB_FLAG_VLAN_PROMISC
;
2224 igb_clean_all_tx_rings(adapter
);
2225 igb_clean_all_rx_rings(adapter
);
2226 #ifdef CONFIG_IGB_DCA
2228 /* since we reset the hardware DCA settings were cleared */
2229 igb_setup_dca(adapter
);
2233 void igb_reinit_locked(struct igb_adapter
*adapter
)
2235 WARN_ON(in_interrupt());
2236 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
2237 usleep_range(1000, 2000);
2240 clear_bit(__IGB_RESETTING
, &adapter
->state
);
2243 /** igb_enable_mas - Media Autosense re-enable after swap
2245 * @adapter: adapter struct
2247 static void igb_enable_mas(struct igb_adapter
*adapter
)
2249 struct e1000_hw
*hw
= &adapter
->hw
;
2250 u32 connsw
= rd32(E1000_CONNSW
);
2252 /* configure for SerDes media detect */
2253 if ((hw
->phy
.media_type
== e1000_media_type_copper
) &&
2254 (!(connsw
& E1000_CONNSW_SERDESD
))) {
2255 connsw
|= E1000_CONNSW_ENRGSRC
;
2256 connsw
|= E1000_CONNSW_AUTOSENSE_EN
;
2257 wr32(E1000_CONNSW
, connsw
);
2262 void igb_reset(struct igb_adapter
*adapter
)
2264 struct pci_dev
*pdev
= adapter
->pdev
;
2265 struct e1000_hw
*hw
= &adapter
->hw
;
2266 struct e1000_mac_info
*mac
= &hw
->mac
;
2267 struct e1000_fc_info
*fc
= &hw
->fc
;
2270 /* Repartition Pba for greater than 9k mtu
2271 * To take effect CTRL.RST is required.
2273 switch (mac
->type
) {
2277 pba
= rd32(E1000_RXPBS
);
2278 pba
= igb_rxpbs_adjust_82580(pba
);
2281 pba
= rd32(E1000_RXPBS
);
2282 pba
&= E1000_RXPBS_SIZE_MASK_82576
;
2288 pba
= E1000_PBA_34K
;
2292 if (mac
->type
== e1000_82575
) {
2293 u32 min_rx_space
, min_tx_space
, needed_tx_space
;
2295 /* write Rx PBA so that hardware can report correct Tx PBA */
2296 wr32(E1000_PBA
, pba
);
2298 /* To maintain wire speed transmits, the Tx FIFO should be
2299 * large enough to accommodate two full transmit packets,
2300 * rounded up to the next 1KB and expressed in KB. Likewise,
2301 * the Rx FIFO should be large enough to accommodate at least
2302 * one full receive packet and is similarly rounded up and
2305 min_rx_space
= DIV_ROUND_UP(MAX_JUMBO_FRAME_SIZE
, 1024);
2307 /* The Tx FIFO also stores 16 bytes of information about the Tx
2308 * but don't include Ethernet FCS because hardware appends it.
2309 * We only need to round down to the nearest 512 byte block
2310 * count since the value we care about is 2 frames, not 1.
2312 min_tx_space
= adapter
->max_frame_size
;
2313 min_tx_space
+= sizeof(union e1000_adv_tx_desc
) - ETH_FCS_LEN
;
2314 min_tx_space
= DIV_ROUND_UP(min_tx_space
, 512);
2316 /* upper 16 bits has Tx packet buffer allocation size in KB */
2317 needed_tx_space
= min_tx_space
- (rd32(E1000_PBA
) >> 16);
2319 /* If current Tx allocation is less than the min Tx FIFO size,
2320 * and the min Tx FIFO size is less than the current Rx FIFO
2321 * allocation, take space away from current Rx allocation.
2323 if (needed_tx_space
< pba
) {
2324 pba
-= needed_tx_space
;
2326 /* if short on Rx space, Rx wins and must trump Tx
2329 if (pba
< min_rx_space
)
2333 /* adjust PBA for jumbo frames */
2334 wr32(E1000_PBA
, pba
);
2337 /* flow control settings
2338 * The high water mark must be low enough to fit one full frame
2339 * after transmitting the pause frame. As such we must have enough
2340 * space to allow for us to complete our current transmit and then
2341 * receive the frame that is in progress from the link partner.
2343 * - the full Rx FIFO size minus one full Tx plus one full Rx frame
2345 hwm
= (pba
<< 10) - (adapter
->max_frame_size
+ MAX_JUMBO_FRAME_SIZE
);
2347 fc
->high_water
= hwm
& 0xFFFFFFF0; /* 16-byte granularity */
2348 fc
->low_water
= fc
->high_water
- 16;
2349 fc
->pause_time
= 0xFFFF;
2351 fc
->current_mode
= fc
->requested_mode
;
2353 /* disable receive for all VFs and wait one second */
2354 if (adapter
->vfs_allocated_count
) {
2357 for (i
= 0 ; i
< adapter
->vfs_allocated_count
; i
++)
2358 adapter
->vf_data
[i
].flags
&= IGB_VF_FLAG_PF_SET_MAC
;
2360 /* ping all the active vfs to let them know we are going down */
2361 igb_ping_all_vfs(adapter
);
2363 /* disable transmits and receives */
2364 wr32(E1000_VFRE
, 0);
2365 wr32(E1000_VFTE
, 0);
2368 /* Allow time for pending master requests to run */
2369 hw
->mac
.ops
.reset_hw(hw
);
2372 if (adapter
->flags
& IGB_FLAG_MEDIA_RESET
) {
2373 /* need to resetup here after media swap */
2374 adapter
->ei
.get_invariants(hw
);
2375 adapter
->flags
&= ~IGB_FLAG_MEDIA_RESET
;
2377 if ((mac
->type
== e1000_82575
) &&
2378 (adapter
->flags
& IGB_FLAG_MAS_ENABLE
)) {
2379 igb_enable_mas(adapter
);
2381 if (hw
->mac
.ops
.init_hw(hw
))
2382 dev_err(&pdev
->dev
, "Hardware Error\n");
2384 /* RAR registers were cleared during init_hw, clear mac table */
2385 igb_flush_mac_table(adapter
);
2386 __dev_uc_unsync(adapter
->netdev
, NULL
);
2388 /* Recover default RAR entry */
2389 igb_set_default_mac_filter(adapter
);
2391 /* Flow control settings reset on hardware reset, so guarantee flow
2392 * control is off when forcing speed.
2394 if (!hw
->mac
.autoneg
)
2395 igb_force_mac_fc(hw
);
2397 igb_init_dmac(adapter
, pba
);
2398 #ifdef CONFIG_IGB_HWMON
2399 /* Re-initialize the thermal sensor on i350 devices. */
2400 if (!test_bit(__IGB_DOWN
, &adapter
->state
)) {
2401 if (mac
->type
== e1000_i350
&& hw
->bus
.func
== 0) {
2402 /* If present, re-initialize the external thermal sensor
2406 mac
->ops
.init_thermal_sensor_thresh(hw
);
2410 /* Re-establish EEE setting */
2411 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
2412 switch (mac
->type
) {
2416 igb_set_eee_i350(hw
, true, true);
2419 igb_set_eee_i354(hw
, true, true);
2425 if (!netif_running(adapter
->netdev
))
2426 igb_power_down_link(adapter
);
2428 igb_update_mng_vlan(adapter
);
2430 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2431 wr32(E1000_VET
, ETHERNET_IEEE_VLAN_TYPE
);
2433 /* Re-enable PTP, where applicable. */
2434 if (adapter
->ptp_flags
& IGB_PTP_ENABLED
)
2435 igb_ptp_reset(adapter
);
2437 igb_get_phy_info(hw
);
2440 static netdev_features_t
igb_fix_features(struct net_device
*netdev
,
2441 netdev_features_t features
)
2443 /* Since there is no support for separate Rx/Tx vlan accel
2444 * enable/disable make sure Tx flag is always in same state as Rx.
2446 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
2447 features
|= NETIF_F_HW_VLAN_CTAG_TX
;
2449 features
&= ~NETIF_F_HW_VLAN_CTAG_TX
;
2454 static int igb_set_features(struct net_device
*netdev
,
2455 netdev_features_t features
)
2457 netdev_features_t changed
= netdev
->features
^ features
;
2458 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2460 if (changed
& NETIF_F_HW_VLAN_CTAG_RX
)
2461 igb_vlan_mode(netdev
, features
);
2463 if (!(changed
& (NETIF_F_RXALL
| NETIF_F_NTUPLE
)))
2466 if (!(features
& NETIF_F_NTUPLE
)) {
2467 struct hlist_node
*node2
;
2468 struct igb_nfc_filter
*rule
;
2470 spin_lock(&adapter
->nfc_lock
);
2471 hlist_for_each_entry_safe(rule
, node2
,
2472 &adapter
->nfc_filter_list
, nfc_node
) {
2473 igb_erase_filter(adapter
, rule
);
2474 hlist_del(&rule
->nfc_node
);
2477 spin_unlock(&adapter
->nfc_lock
);
2478 adapter
->nfc_filter_count
= 0;
2481 netdev
->features
= features
;
2483 if (netif_running(netdev
))
2484 igb_reinit_locked(adapter
);
2491 static int igb_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
2492 struct net_device
*dev
,
2493 const unsigned char *addr
, u16 vid
,
2496 /* guarantee we can provide a unique filter for the unicast address */
2497 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
)) {
2498 struct igb_adapter
*adapter
= netdev_priv(dev
);
2499 int vfn
= adapter
->vfs_allocated_count
;
2501 if (netdev_uc_count(dev
) >= igb_available_rars(adapter
, vfn
))
2505 return ndo_dflt_fdb_add(ndm
, tb
, dev
, addr
, vid
, flags
);
2508 #define IGB_MAX_MAC_HDR_LEN 127
2509 #define IGB_MAX_NETWORK_HDR_LEN 511
2511 static netdev_features_t
2512 igb_features_check(struct sk_buff
*skb
, struct net_device
*dev
,
2513 netdev_features_t features
)
2515 unsigned int network_hdr_len
, mac_hdr_len
;
2517 /* Make certain the headers can be described by a context descriptor */
2518 mac_hdr_len
= skb_network_header(skb
) - skb
->data
;
2519 if (unlikely(mac_hdr_len
> IGB_MAX_MAC_HDR_LEN
))
2520 return features
& ~(NETIF_F_HW_CSUM
|
2522 NETIF_F_HW_VLAN_CTAG_TX
|
2526 network_hdr_len
= skb_checksum_start(skb
) - skb_network_header(skb
);
2527 if (unlikely(network_hdr_len
> IGB_MAX_NETWORK_HDR_LEN
))
2528 return features
& ~(NETIF_F_HW_CSUM
|
2533 /* We can only support IPV4 TSO in tunnels if we can mangle the
2534 * inner IP ID field, so strip TSO if MANGLEID is not supported.
2536 if (skb
->encapsulation
&& !(features
& NETIF_F_TSO_MANGLEID
))
2537 features
&= ~NETIF_F_TSO
;
2542 static void igb_offload_apply(struct igb_adapter
*adapter
, s32 queue
)
2544 if (!is_fqtss_enabled(adapter
)) {
2545 enable_fqtss(adapter
, true);
2549 igb_config_tx_modes(adapter
, queue
);
2551 if (!is_any_cbs_enabled(adapter
) && !is_any_txtime_enabled(adapter
))
2552 enable_fqtss(adapter
, false);
2555 static int igb_offload_cbs(struct igb_adapter
*adapter
,
2556 struct tc_cbs_qopt_offload
*qopt
)
2558 struct e1000_hw
*hw
= &adapter
->hw
;
2561 /* CBS offloading is only supported by i210 controller. */
2562 if (hw
->mac
.type
!= e1000_i210
)
2565 /* CBS offloading is only supported by queue 0 and queue 1. */
2566 if (qopt
->queue
< 0 || qopt
->queue
> 1)
2569 err
= igb_save_cbs_params(adapter
, qopt
->queue
, qopt
->enable
,
2570 qopt
->idleslope
, qopt
->sendslope
,
2571 qopt
->hicredit
, qopt
->locredit
);
2575 igb_offload_apply(adapter
, qopt
->queue
);
2580 #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
2581 #define VLAN_PRIO_FULL_MASK (0x07)
2583 static int igb_parse_cls_flower(struct igb_adapter
*adapter
,
2584 struct tc_cls_flower_offload
*f
,
2586 struct igb_nfc_filter
*input
)
2588 struct netlink_ext_ack
*extack
= f
->common
.extack
;
2590 if (f
->dissector
->used_keys
&
2591 ~(BIT(FLOW_DISSECTOR_KEY_BASIC
) |
2592 BIT(FLOW_DISSECTOR_KEY_CONTROL
) |
2593 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS
) |
2594 BIT(FLOW_DISSECTOR_KEY_VLAN
))) {
2595 NL_SET_ERR_MSG_MOD(extack
,
2596 "Unsupported key used, only BASIC, CONTROL, ETH_ADDRS and VLAN are supported");
2600 if (dissector_uses_key(f
->dissector
, FLOW_DISSECTOR_KEY_ETH_ADDRS
)) {
2601 struct flow_dissector_key_eth_addrs
*key
, *mask
;
2603 key
= skb_flow_dissector_target(f
->dissector
,
2604 FLOW_DISSECTOR_KEY_ETH_ADDRS
,
2606 mask
= skb_flow_dissector_target(f
->dissector
,
2607 FLOW_DISSECTOR_KEY_ETH_ADDRS
,
2610 if (!is_zero_ether_addr(mask
->dst
)) {
2611 if (!is_broadcast_ether_addr(mask
->dst
)) {
2612 NL_SET_ERR_MSG_MOD(extack
, "Only full masks are supported for destination MAC address");
2616 input
->filter
.match_flags
|=
2617 IGB_FILTER_FLAG_DST_MAC_ADDR
;
2618 ether_addr_copy(input
->filter
.dst_addr
, key
->dst
);
2621 if (!is_zero_ether_addr(mask
->src
)) {
2622 if (!is_broadcast_ether_addr(mask
->src
)) {
2623 NL_SET_ERR_MSG_MOD(extack
, "Only full masks are supported for source MAC address");
2627 input
->filter
.match_flags
|=
2628 IGB_FILTER_FLAG_SRC_MAC_ADDR
;
2629 ether_addr_copy(input
->filter
.src_addr
, key
->src
);
2633 if (dissector_uses_key(f
->dissector
, FLOW_DISSECTOR_KEY_BASIC
)) {
2634 struct flow_dissector_key_basic
*key
, *mask
;
2636 key
= skb_flow_dissector_target(f
->dissector
,
2637 FLOW_DISSECTOR_KEY_BASIC
,
2639 mask
= skb_flow_dissector_target(f
->dissector
,
2640 FLOW_DISSECTOR_KEY_BASIC
,
2643 if (mask
->n_proto
) {
2644 if (mask
->n_proto
!= ETHER_TYPE_FULL_MASK
) {
2645 NL_SET_ERR_MSG_MOD(extack
, "Only full mask is supported for EtherType filter");
2649 input
->filter
.match_flags
|= IGB_FILTER_FLAG_ETHER_TYPE
;
2650 input
->filter
.etype
= key
->n_proto
;
2654 if (dissector_uses_key(f
->dissector
, FLOW_DISSECTOR_KEY_VLAN
)) {
2655 struct flow_dissector_key_vlan
*key
, *mask
;
2657 key
= skb_flow_dissector_target(f
->dissector
,
2658 FLOW_DISSECTOR_KEY_VLAN
,
2660 mask
= skb_flow_dissector_target(f
->dissector
,
2661 FLOW_DISSECTOR_KEY_VLAN
,
2664 if (mask
->vlan_priority
) {
2665 if (mask
->vlan_priority
!= VLAN_PRIO_FULL_MASK
) {
2666 NL_SET_ERR_MSG_MOD(extack
, "Only full mask is supported for VLAN priority");
2670 input
->filter
.match_flags
|= IGB_FILTER_FLAG_VLAN_TCI
;
2671 input
->filter
.vlan_tci
= key
->vlan_priority
;
2675 input
->action
= traffic_class
;
2676 input
->cookie
= f
->cookie
;
2681 static int igb_configure_clsflower(struct igb_adapter
*adapter
,
2682 struct tc_cls_flower_offload
*cls_flower
)
2684 struct netlink_ext_ack
*extack
= cls_flower
->common
.extack
;
2685 struct igb_nfc_filter
*filter
, *f
;
2688 tc
= tc_classid_to_hwtc(adapter
->netdev
, cls_flower
->classid
);
2690 NL_SET_ERR_MSG_MOD(extack
, "Invalid traffic class");
2694 filter
= kzalloc(sizeof(*filter
), GFP_KERNEL
);
2698 err
= igb_parse_cls_flower(adapter
, cls_flower
, tc
, filter
);
2702 spin_lock(&adapter
->nfc_lock
);
2704 hlist_for_each_entry(f
, &adapter
->nfc_filter_list
, nfc_node
) {
2705 if (!memcmp(&f
->filter
, &filter
->filter
, sizeof(f
->filter
))) {
2707 NL_SET_ERR_MSG_MOD(extack
,
2708 "This filter is already set in ethtool");
2713 hlist_for_each_entry(f
, &adapter
->cls_flower_list
, nfc_node
) {
2714 if (!memcmp(&f
->filter
, &filter
->filter
, sizeof(f
->filter
))) {
2716 NL_SET_ERR_MSG_MOD(extack
,
2717 "This filter is already set in cls_flower");
2722 err
= igb_add_filter(adapter
, filter
);
2724 NL_SET_ERR_MSG_MOD(extack
, "Could not add filter to the adapter");
2728 hlist_add_head(&filter
->nfc_node
, &adapter
->cls_flower_list
);
2730 spin_unlock(&adapter
->nfc_lock
);
2735 spin_unlock(&adapter
->nfc_lock
);
2743 static int igb_delete_clsflower(struct igb_adapter
*adapter
,
2744 struct tc_cls_flower_offload
*cls_flower
)
2746 struct igb_nfc_filter
*filter
;
2749 spin_lock(&adapter
->nfc_lock
);
2751 hlist_for_each_entry(filter
, &adapter
->cls_flower_list
, nfc_node
)
2752 if (filter
->cookie
== cls_flower
->cookie
)
2760 err
= igb_erase_filter(adapter
, filter
);
2764 hlist_del(&filter
->nfc_node
);
2768 spin_unlock(&adapter
->nfc_lock
);
2773 static int igb_setup_tc_cls_flower(struct igb_adapter
*adapter
,
2774 struct tc_cls_flower_offload
*cls_flower
)
2776 switch (cls_flower
->command
) {
2777 case TC_CLSFLOWER_REPLACE
:
2778 return igb_configure_clsflower(adapter
, cls_flower
);
2779 case TC_CLSFLOWER_DESTROY
:
2780 return igb_delete_clsflower(adapter
, cls_flower
);
2781 case TC_CLSFLOWER_STATS
:
2788 static int igb_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
2791 struct igb_adapter
*adapter
= cb_priv
;
2793 if (!tc_cls_can_offload_and_chain0(adapter
->netdev
, type_data
))
2797 case TC_SETUP_CLSFLOWER
:
2798 return igb_setup_tc_cls_flower(adapter
, type_data
);
2805 static int igb_setup_tc_block(struct igb_adapter
*adapter
,
2806 struct tc_block_offload
*f
)
2808 if (f
->binder_type
!= TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS
)
2811 switch (f
->command
) {
2813 return tcf_block_cb_register(f
->block
, igb_setup_tc_block_cb
,
2814 adapter
, adapter
, f
->extack
);
2815 case TC_BLOCK_UNBIND
:
2816 tcf_block_cb_unregister(f
->block
, igb_setup_tc_block_cb
,
2824 static int igb_offload_txtime(struct igb_adapter
*adapter
,
2825 struct tc_etf_qopt_offload
*qopt
)
2827 struct e1000_hw
*hw
= &adapter
->hw
;
2830 /* Launchtime offloading is only supported by i210 controller. */
2831 if (hw
->mac
.type
!= e1000_i210
)
2834 /* Launchtime offloading is only supported by queues 0 and 1. */
2835 if (qopt
->queue
< 0 || qopt
->queue
> 1)
2838 err
= igb_save_txtime_params(adapter
, qopt
->queue
, qopt
->enable
);
2842 igb_offload_apply(adapter
, qopt
->queue
);
2847 static int igb_setup_tc(struct net_device
*dev
, enum tc_setup_type type
,
2850 struct igb_adapter
*adapter
= netdev_priv(dev
);
2853 case TC_SETUP_QDISC_CBS
:
2854 return igb_offload_cbs(adapter
, type_data
);
2855 case TC_SETUP_BLOCK
:
2856 return igb_setup_tc_block(adapter
, type_data
);
2857 case TC_SETUP_QDISC_ETF
:
2858 return igb_offload_txtime(adapter
, type_data
);
2865 static const struct net_device_ops igb_netdev_ops
= {
2866 .ndo_open
= igb_open
,
2867 .ndo_stop
= igb_close
,
2868 .ndo_start_xmit
= igb_xmit_frame
,
2869 .ndo_get_stats64
= igb_get_stats64
,
2870 .ndo_set_rx_mode
= igb_set_rx_mode
,
2871 .ndo_set_mac_address
= igb_set_mac
,
2872 .ndo_change_mtu
= igb_change_mtu
,
2873 .ndo_do_ioctl
= igb_ioctl
,
2874 .ndo_tx_timeout
= igb_tx_timeout
,
2875 .ndo_validate_addr
= eth_validate_addr
,
2876 .ndo_vlan_rx_add_vid
= igb_vlan_rx_add_vid
,
2877 .ndo_vlan_rx_kill_vid
= igb_vlan_rx_kill_vid
,
2878 .ndo_set_vf_mac
= igb_ndo_set_vf_mac
,
2879 .ndo_set_vf_vlan
= igb_ndo_set_vf_vlan
,
2880 .ndo_set_vf_rate
= igb_ndo_set_vf_bw
,
2881 .ndo_set_vf_spoofchk
= igb_ndo_set_vf_spoofchk
,
2882 .ndo_set_vf_trust
= igb_ndo_set_vf_trust
,
2883 .ndo_get_vf_config
= igb_ndo_get_vf_config
,
2884 #ifdef CONFIG_NET_POLL_CONTROLLER
2885 .ndo_poll_controller
= igb_netpoll
,
2887 .ndo_fix_features
= igb_fix_features
,
2888 .ndo_set_features
= igb_set_features
,
2889 .ndo_fdb_add
= igb_ndo_fdb_add
,
2890 .ndo_features_check
= igb_features_check
,
2891 .ndo_setup_tc
= igb_setup_tc
,
2895 * igb_set_fw_version - Configure version string for ethtool
2896 * @adapter: adapter struct
2898 void igb_set_fw_version(struct igb_adapter
*adapter
)
2900 struct e1000_hw
*hw
= &adapter
->hw
;
2901 struct e1000_fw_version fw
;
2903 igb_get_fw_version(hw
, &fw
);
2905 switch (hw
->mac
.type
) {
2908 if (!(igb_get_flash_presence_i210(hw
))) {
2909 snprintf(adapter
->fw_version
,
2910 sizeof(adapter
->fw_version
),
2912 fw
.invm_major
, fw
.invm_minor
,
2918 /* if option is rom valid, display its version too */
2920 snprintf(adapter
->fw_version
,
2921 sizeof(adapter
->fw_version
),
2922 "%d.%d, 0x%08x, %d.%d.%d",
2923 fw
.eep_major
, fw
.eep_minor
, fw
.etrack_id
,
2924 fw
.or_major
, fw
.or_build
, fw
.or_patch
);
2926 } else if (fw
.etrack_id
!= 0X0000) {
2927 snprintf(adapter
->fw_version
,
2928 sizeof(adapter
->fw_version
),
2930 fw
.eep_major
, fw
.eep_minor
, fw
.etrack_id
);
2932 snprintf(adapter
->fw_version
,
2933 sizeof(adapter
->fw_version
),
2935 fw
.eep_major
, fw
.eep_minor
, fw
.eep_build
);
2942 * igb_init_mas - init Media Autosense feature if enabled in the NVM
2944 * @adapter: adapter struct
2946 static void igb_init_mas(struct igb_adapter
*adapter
)
2948 struct e1000_hw
*hw
= &adapter
->hw
;
2951 hw
->nvm
.ops
.read(hw
, NVM_COMPAT
, 1, &eeprom_data
);
2952 switch (hw
->bus
.func
) {
2954 if (eeprom_data
& IGB_MAS_ENABLE_0
) {
2955 adapter
->flags
|= IGB_FLAG_MAS_ENABLE
;
2956 netdev_info(adapter
->netdev
,
2957 "MAS: Enabling Media Autosense for port %d\n",
2962 if (eeprom_data
& IGB_MAS_ENABLE_1
) {
2963 adapter
->flags
|= IGB_FLAG_MAS_ENABLE
;
2964 netdev_info(adapter
->netdev
,
2965 "MAS: Enabling Media Autosense for port %d\n",
2970 if (eeprom_data
& IGB_MAS_ENABLE_2
) {
2971 adapter
->flags
|= IGB_FLAG_MAS_ENABLE
;
2972 netdev_info(adapter
->netdev
,
2973 "MAS: Enabling Media Autosense for port %d\n",
2978 if (eeprom_data
& IGB_MAS_ENABLE_3
) {
2979 adapter
->flags
|= IGB_FLAG_MAS_ENABLE
;
2980 netdev_info(adapter
->netdev
,
2981 "MAS: Enabling Media Autosense for port %d\n",
2986 /* Shouldn't get here */
2987 netdev_err(adapter
->netdev
,
2988 "MAS: Invalid port configuration, returning\n");
2994 * igb_init_i2c - Init I2C interface
2995 * @adapter: pointer to adapter structure
2997 static s32
igb_init_i2c(struct igb_adapter
*adapter
)
3001 /* I2C interface supported on i350 devices */
3002 if (adapter
->hw
.mac
.type
!= e1000_i350
)
3005 /* Initialize the i2c bus which is controlled by the registers.
3006 * This bus will use the i2c_algo_bit structue that implements
3007 * the protocol through toggling of the 4 bits in the register.
3009 adapter
->i2c_adap
.owner
= THIS_MODULE
;
3010 adapter
->i2c_algo
= igb_i2c_algo
;
3011 adapter
->i2c_algo
.data
= adapter
;
3012 adapter
->i2c_adap
.algo_data
= &adapter
->i2c_algo
;
3013 adapter
->i2c_adap
.dev
.parent
= &adapter
->pdev
->dev
;
3014 strlcpy(adapter
->i2c_adap
.name
, "igb BB",
3015 sizeof(adapter
->i2c_adap
.name
));
3016 status
= i2c_bit_add_bus(&adapter
->i2c_adap
);
3021 * igb_probe - Device Initialization Routine
3022 * @pdev: PCI device information struct
3023 * @ent: entry in igb_pci_tbl
3025 * Returns 0 on success, negative on failure
3027 * igb_probe initializes an adapter identified by a pci_dev structure.
3028 * The OS initialization, configuring of the adapter private structure,
3029 * and a hardware reset occur.
3031 static int igb_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
3033 struct net_device
*netdev
;
3034 struct igb_adapter
*adapter
;
3035 struct e1000_hw
*hw
;
3036 u16 eeprom_data
= 0;
3038 static int global_quad_port_a
; /* global quad port a indication */
3039 const struct e1000_info
*ei
= igb_info_tbl
[ent
->driver_data
];
3040 int err
, pci_using_dac
;
3041 u8 part_str
[E1000_PBANUM_LENGTH
];
3043 /* Catch broken hardware that put the wrong VF device ID in
3044 * the PCIe SR-IOV capability.
3046 if (pdev
->is_virtfn
) {
3047 WARN(1, KERN_ERR
"%s (%hx:%hx) should not be a VF!\n",
3048 pci_name(pdev
), pdev
->vendor
, pdev
->device
);
3052 err
= pci_enable_device_mem(pdev
);
3057 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
3061 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
3064 "No usable DMA configuration, aborting\n");
3069 err
= pci_request_mem_regions(pdev
, igb_driver_name
);
3073 pci_enable_pcie_error_reporting(pdev
);
3075 pci_set_master(pdev
);
3076 pci_save_state(pdev
);
3079 netdev
= alloc_etherdev_mq(sizeof(struct igb_adapter
),
3082 goto err_alloc_etherdev
;
3084 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3086 pci_set_drvdata(pdev
, netdev
);
3087 adapter
= netdev_priv(netdev
);
3088 adapter
->netdev
= netdev
;
3089 adapter
->pdev
= pdev
;
3092 adapter
->msg_enable
= netif_msg_init(debug
, DEFAULT_MSG_ENABLE
);
3095 adapter
->io_addr
= pci_iomap(pdev
, 0, 0);
3096 if (!adapter
->io_addr
)
3098 /* hw->hw_addr can be altered, we'll use adapter->io_addr for unmap */
3099 hw
->hw_addr
= adapter
->io_addr
;
3101 netdev
->netdev_ops
= &igb_netdev_ops
;
3102 igb_set_ethtool_ops(netdev
);
3103 netdev
->watchdog_timeo
= 5 * HZ
;
3105 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
3107 netdev
->mem_start
= pci_resource_start(pdev
, 0);
3108 netdev
->mem_end
= pci_resource_end(pdev
, 0);
3110 /* PCI config space info */
3111 hw
->vendor_id
= pdev
->vendor
;
3112 hw
->device_id
= pdev
->device
;
3113 hw
->revision_id
= pdev
->revision
;
3114 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
3115 hw
->subsystem_device_id
= pdev
->subsystem_device
;
3117 /* Copy the default MAC, PHY and NVM function pointers */
3118 memcpy(&hw
->mac
.ops
, ei
->mac_ops
, sizeof(hw
->mac
.ops
));
3119 memcpy(&hw
->phy
.ops
, ei
->phy_ops
, sizeof(hw
->phy
.ops
));
3120 memcpy(&hw
->nvm
.ops
, ei
->nvm_ops
, sizeof(hw
->nvm
.ops
));
3121 /* Initialize skew-specific constants */
3122 err
= ei
->get_invariants(hw
);
3126 /* setup the private structure */
3127 err
= igb_sw_init(adapter
);
3131 igb_get_bus_info_pcie(hw
);
3133 hw
->phy
.autoneg_wait_to_complete
= false;
3135 /* Copper options */
3136 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
3137 hw
->phy
.mdix
= AUTO_ALL_MODES
;
3138 hw
->phy
.disable_polarity_correction
= false;
3139 hw
->phy
.ms_type
= e1000_ms_hw_default
;
3142 if (igb_check_reset_block(hw
))
3143 dev_info(&pdev
->dev
,
3144 "PHY reset is blocked due to SOL/IDER session.\n");
3146 /* features is initialized to 0 in allocation, it might have bits
3147 * set by igb_sw_init so we should use an or instead of an
3150 netdev
->features
|= NETIF_F_SG
|
3157 if (hw
->mac
.type
>= e1000_82576
)
3158 netdev
->features
|= NETIF_F_SCTP_CRC
;
3160 if (hw
->mac
.type
>= e1000_i350
)
3161 netdev
->features
|= NETIF_F_HW_TC
;
3163 #define IGB_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
3164 NETIF_F_GSO_GRE_CSUM | \
3165 NETIF_F_GSO_IPXIP4 | \
3166 NETIF_F_GSO_IPXIP6 | \
3167 NETIF_F_GSO_UDP_TUNNEL | \
3168 NETIF_F_GSO_UDP_TUNNEL_CSUM)
3170 netdev
->gso_partial_features
= IGB_GSO_PARTIAL_FEATURES
;
3171 netdev
->features
|= NETIF_F_GSO_PARTIAL
| IGB_GSO_PARTIAL_FEATURES
;
3173 /* copy netdev features into list of user selectable features */
3174 netdev
->hw_features
|= netdev
->features
|
3175 NETIF_F_HW_VLAN_CTAG_RX
|
3176 NETIF_F_HW_VLAN_CTAG_TX
|
3179 if (hw
->mac
.type
>= e1000_i350
)
3180 netdev
->hw_features
|= NETIF_F_NTUPLE
;
3183 netdev
->features
|= NETIF_F_HIGHDMA
;
3185 netdev
->vlan_features
|= netdev
->features
| NETIF_F_TSO_MANGLEID
;
3186 netdev
->mpls_features
|= NETIF_F_HW_CSUM
;
3187 netdev
->hw_enc_features
|= netdev
->vlan_features
;
3189 /* set this bit last since it cannot be part of vlan_features */
3190 netdev
->features
|= NETIF_F_HW_VLAN_CTAG_FILTER
|
3191 NETIF_F_HW_VLAN_CTAG_RX
|
3192 NETIF_F_HW_VLAN_CTAG_TX
;
3194 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
3196 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
3198 /* MTU range: 68 - 9216 */
3199 netdev
->min_mtu
= ETH_MIN_MTU
;
3200 netdev
->max_mtu
= MAX_STD_JUMBO_FRAME_SIZE
;
3202 adapter
->en_mng_pt
= igb_enable_mng_pass_thru(hw
);
3204 /* before reading the NVM, reset the controller to put the device in a
3205 * known good starting state
3207 hw
->mac
.ops
.reset_hw(hw
);
3209 /* make sure the NVM is good , i211/i210 parts can have special NVM
3210 * that doesn't contain a checksum
3212 switch (hw
->mac
.type
) {
3215 if (igb_get_flash_presence_i210(hw
)) {
3216 if (hw
->nvm
.ops
.validate(hw
) < 0) {
3218 "The NVM Checksum Is Not Valid\n");
3225 if (hw
->nvm
.ops
.validate(hw
) < 0) {
3226 dev_err(&pdev
->dev
, "The NVM Checksum Is Not Valid\n");
3233 if (eth_platform_get_mac_address(&pdev
->dev
, hw
->mac
.addr
)) {
3234 /* copy the MAC address out of the NVM */
3235 if (hw
->mac
.ops
.read_mac_addr(hw
))
3236 dev_err(&pdev
->dev
, "NVM Read Error\n");
3239 memcpy(netdev
->dev_addr
, hw
->mac
.addr
, netdev
->addr_len
);
3241 if (!is_valid_ether_addr(netdev
->dev_addr
)) {
3242 dev_err(&pdev
->dev
, "Invalid MAC Address\n");
3247 igb_set_default_mac_filter(adapter
);
3249 /* get firmware version for ethtool -i */
3250 igb_set_fw_version(adapter
);
3252 /* configure RXPBSIZE and TXPBSIZE */
3253 if (hw
->mac
.type
== e1000_i210
) {
3254 wr32(E1000_RXPBS
, I210_RXPBSIZE_DEFAULT
);
3255 wr32(E1000_TXPBS
, I210_TXPBSIZE_DEFAULT
);
3258 timer_setup(&adapter
->watchdog_timer
, igb_watchdog
, 0);
3259 timer_setup(&adapter
->phy_info_timer
, igb_update_phy_info
, 0);
3261 INIT_WORK(&adapter
->reset_task
, igb_reset_task
);
3262 INIT_WORK(&adapter
->watchdog_task
, igb_watchdog_task
);
3264 /* Initialize link properties that are user-changeable */
3265 adapter
->fc_autoneg
= true;
3266 hw
->mac
.autoneg
= true;
3267 hw
->phy
.autoneg_advertised
= 0x2f;
3269 hw
->fc
.requested_mode
= e1000_fc_default
;
3270 hw
->fc
.current_mode
= e1000_fc_default
;
3272 igb_validate_mdi_setting(hw
);
3274 /* By default, support wake on port A */
3275 if (hw
->bus
.func
== 0)
3276 adapter
->flags
|= IGB_FLAG_WOL_SUPPORTED
;
3278 /* Check the NVM for wake support on non-port A ports */
3279 if (hw
->mac
.type
>= e1000_82580
)
3280 hw
->nvm
.ops
.read(hw
, NVM_INIT_CONTROL3_PORT_A
+
3281 NVM_82580_LAN_FUNC_OFFSET(hw
->bus
.func
), 1,
3283 else if (hw
->bus
.func
== 1)
3284 hw
->nvm
.ops
.read(hw
, NVM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
3286 if (eeprom_data
& IGB_EEPROM_APME
)
3287 adapter
->flags
|= IGB_FLAG_WOL_SUPPORTED
;
3289 /* now that we have the eeprom settings, apply the special cases where
3290 * the eeprom may be wrong or the board simply won't support wake on
3291 * lan on a particular port
3293 switch (pdev
->device
) {
3294 case E1000_DEV_ID_82575GB_QUAD_COPPER
:
3295 adapter
->flags
&= ~IGB_FLAG_WOL_SUPPORTED
;
3297 case E1000_DEV_ID_82575EB_FIBER_SERDES
:
3298 case E1000_DEV_ID_82576_FIBER
:
3299 case E1000_DEV_ID_82576_SERDES
:
3300 /* Wake events only supported on port A for dual fiber
3301 * regardless of eeprom setting
3303 if (rd32(E1000_STATUS
) & E1000_STATUS_FUNC_1
)
3304 adapter
->flags
&= ~IGB_FLAG_WOL_SUPPORTED
;
3306 case E1000_DEV_ID_82576_QUAD_COPPER
:
3307 case E1000_DEV_ID_82576_QUAD_COPPER_ET2
:
3308 /* if quad port adapter, disable WoL on all but port A */
3309 if (global_quad_port_a
!= 0)
3310 adapter
->flags
&= ~IGB_FLAG_WOL_SUPPORTED
;
3312 adapter
->flags
|= IGB_FLAG_QUAD_PORT_A
;
3313 /* Reset for multiple quad port adapters */
3314 if (++global_quad_port_a
== 4)
3315 global_quad_port_a
= 0;
3318 /* If the device can't wake, don't set software support */
3319 if (!device_can_wakeup(&adapter
->pdev
->dev
))
3320 adapter
->flags
&= ~IGB_FLAG_WOL_SUPPORTED
;
3323 /* initialize the wol settings based on the eeprom settings */
3324 if (adapter
->flags
& IGB_FLAG_WOL_SUPPORTED
)
3325 adapter
->wol
|= E1000_WUFC_MAG
;
3327 /* Some vendors want WoL disabled by default, but still supported */
3328 if ((hw
->mac
.type
== e1000_i350
) &&
3329 (pdev
->subsystem_vendor
== PCI_VENDOR_ID_HP
)) {
3330 adapter
->flags
|= IGB_FLAG_WOL_SUPPORTED
;
3334 /* Some vendors want the ability to Use the EEPROM setting as
3335 * enable/disable only, and not for capability
3337 if (((hw
->mac
.type
== e1000_i350
) ||
3338 (hw
->mac
.type
== e1000_i354
)) &&
3339 (pdev
->subsystem_vendor
== PCI_VENDOR_ID_DELL
)) {
3340 adapter
->flags
|= IGB_FLAG_WOL_SUPPORTED
;
3343 if (hw
->mac
.type
== e1000_i350
) {
3344 if (((pdev
->subsystem_device
== 0x5001) ||
3345 (pdev
->subsystem_device
== 0x5002)) &&
3346 (hw
->bus
.func
== 0)) {
3347 adapter
->flags
|= IGB_FLAG_WOL_SUPPORTED
;
3350 if (pdev
->subsystem_device
== 0x1F52)
3351 adapter
->flags
|= IGB_FLAG_WOL_SUPPORTED
;
3354 device_set_wakeup_enable(&adapter
->pdev
->dev
,
3355 adapter
->flags
& IGB_FLAG_WOL_SUPPORTED
);
3357 /* reset the hardware with the new settings */
3360 /* Init the I2C interface */
3361 err
= igb_init_i2c(adapter
);
3363 dev_err(&pdev
->dev
, "failed to init i2c interface\n");
3367 /* let the f/w know that the h/w is now under the control of the
3370 igb_get_hw_control(adapter
);
3372 strcpy(netdev
->name
, "eth%d");
3373 err
= register_netdev(netdev
);
3377 /* carrier off reporting is important to ethtool even BEFORE open */
3378 netif_carrier_off(netdev
);
3380 #ifdef CONFIG_IGB_DCA
3381 if (dca_add_requester(&pdev
->dev
) == 0) {
3382 adapter
->flags
|= IGB_FLAG_DCA_ENABLED
;
3383 dev_info(&pdev
->dev
, "DCA enabled\n");
3384 igb_setup_dca(adapter
);
3388 #ifdef CONFIG_IGB_HWMON
3389 /* Initialize the thermal sensor on i350 devices. */
3390 if (hw
->mac
.type
== e1000_i350
&& hw
->bus
.func
== 0) {
3393 /* Read the NVM to determine if this i350 device supports an
3394 * external thermal sensor.
3396 hw
->nvm
.ops
.read(hw
, NVM_ETS_CFG
, 1, &ets_word
);
3397 if (ets_word
!= 0x0000 && ets_word
!= 0xFFFF)
3398 adapter
->ets
= true;
3400 adapter
->ets
= false;
3401 if (igb_sysfs_init(adapter
))
3403 "failed to allocate sysfs resources\n");
3405 adapter
->ets
= false;
3408 /* Check if Media Autosense is enabled */
3410 if (hw
->dev_spec
._82575
.mas_capable
)
3411 igb_init_mas(adapter
);
3413 /* do hw tstamp init after resetting */
3414 igb_ptp_init(adapter
);
3416 dev_info(&pdev
->dev
, "Intel(R) Gigabit Ethernet Network Connection\n");
3417 /* print bus type/speed/width info, not applicable to i354 */
3418 if (hw
->mac
.type
!= e1000_i354
) {
3419 dev_info(&pdev
->dev
, "%s: (PCIe:%s:%s) %pM\n",
3421 ((hw
->bus
.speed
== e1000_bus_speed_2500
) ? "2.5Gb/s" :
3422 (hw
->bus
.speed
== e1000_bus_speed_5000
) ? "5.0Gb/s" :
3424 ((hw
->bus
.width
== e1000_bus_width_pcie_x4
) ?
3426 (hw
->bus
.width
== e1000_bus_width_pcie_x2
) ?
3428 (hw
->bus
.width
== e1000_bus_width_pcie_x1
) ?
3429 "Width x1" : "unknown"), netdev
->dev_addr
);
3432 if ((hw
->mac
.type
>= e1000_i210
||
3433 igb_get_flash_presence_i210(hw
))) {
3434 ret_val
= igb_read_part_string(hw
, part_str
,
3435 E1000_PBANUM_LENGTH
);
3437 ret_val
= -E1000_ERR_INVM_VALUE_NOT_FOUND
;
3441 strcpy(part_str
, "Unknown");
3442 dev_info(&pdev
->dev
, "%s: PBA No: %s\n", netdev
->name
, part_str
);
3443 dev_info(&pdev
->dev
,
3444 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
3445 (adapter
->flags
& IGB_FLAG_HAS_MSIX
) ? "MSI-X" :
3446 (adapter
->flags
& IGB_FLAG_HAS_MSI
) ? "MSI" : "legacy",
3447 adapter
->num_rx_queues
, adapter
->num_tx_queues
);
3448 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
3449 switch (hw
->mac
.type
) {
3453 /* Enable EEE for internal copper PHY devices */
3454 err
= igb_set_eee_i350(hw
, true, true);
3456 (!hw
->dev_spec
._82575
.eee_disable
)) {
3457 adapter
->eee_advert
=
3458 MDIO_EEE_100TX
| MDIO_EEE_1000T
;
3459 adapter
->flags
|= IGB_FLAG_EEE
;
3463 if ((rd32(E1000_CTRL_EXT
) &
3464 E1000_CTRL_EXT_LINK_MODE_SGMII
)) {
3465 err
= igb_set_eee_i354(hw
, true, true);
3467 (!hw
->dev_spec
._82575
.eee_disable
)) {
3468 adapter
->eee_advert
=
3469 MDIO_EEE_100TX
| MDIO_EEE_1000T
;
3470 adapter
->flags
|= IGB_FLAG_EEE
;
3478 pm_runtime_put_noidle(&pdev
->dev
);
3482 igb_release_hw_control(adapter
);
3483 memset(&adapter
->i2c_adap
, 0, sizeof(adapter
->i2c_adap
));
3485 if (!igb_check_reset_block(hw
))
3488 if (hw
->flash_address
)
3489 iounmap(hw
->flash_address
);
3491 kfree(adapter
->mac_table
);
3492 kfree(adapter
->shadow_vfta
);
3493 igb_clear_interrupt_scheme(adapter
);
3494 #ifdef CONFIG_PCI_IOV
3495 igb_disable_sriov(pdev
);
3497 pci_iounmap(pdev
, adapter
->io_addr
);
3499 free_netdev(netdev
);
3501 pci_release_mem_regions(pdev
);
3504 pci_disable_device(pdev
);
3508 #ifdef CONFIG_PCI_IOV
3509 static int igb_disable_sriov(struct pci_dev
*pdev
)
3511 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3512 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3513 struct e1000_hw
*hw
= &adapter
->hw
;
3515 /* reclaim resources allocated to VFs */
3516 if (adapter
->vf_data
) {
3517 /* disable iov and allow time for transactions to clear */
3518 if (pci_vfs_assigned(pdev
)) {
3519 dev_warn(&pdev
->dev
,
3520 "Cannot deallocate SR-IOV virtual functions while they are assigned - VFs will not be deallocated\n");
3523 pci_disable_sriov(pdev
);
3527 kfree(adapter
->vf_mac_list
);
3528 adapter
->vf_mac_list
= NULL
;
3529 kfree(adapter
->vf_data
);
3530 adapter
->vf_data
= NULL
;
3531 adapter
->vfs_allocated_count
= 0;
3532 wr32(E1000_IOVCTL
, E1000_IOVCTL_REUSE_VFQ
);
3535 dev_info(&pdev
->dev
, "IOV Disabled\n");
3537 /* Re-enable DMA Coalescing flag since IOV is turned off */
3538 adapter
->flags
|= IGB_FLAG_DMAC
;
3544 static int igb_enable_sriov(struct pci_dev
*pdev
, int num_vfs
)
3546 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3547 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3548 int old_vfs
= pci_num_vf(pdev
);
3549 struct vf_mac_filter
*mac_list
;
3551 int num_vf_mac_filters
, i
;
3553 if (!(adapter
->flags
& IGB_FLAG_HAS_MSIX
) || num_vfs
> 7) {
3561 dev_info(&pdev
->dev
, "%d pre-allocated VFs found - override max_vfs setting of %d\n",
3563 adapter
->vfs_allocated_count
= old_vfs
;
3565 adapter
->vfs_allocated_count
= num_vfs
;
3567 adapter
->vf_data
= kcalloc(adapter
->vfs_allocated_count
,
3568 sizeof(struct vf_data_storage
), GFP_KERNEL
);
3570 /* if allocation failed then we do not support SR-IOV */
3571 if (!adapter
->vf_data
) {
3572 adapter
->vfs_allocated_count
= 0;
3577 /* Due to the limited number of RAR entries calculate potential
3578 * number of MAC filters available for the VFs. Reserve entries
3579 * for PF default MAC, PF MAC filters and at least one RAR entry
3580 * for each VF for VF MAC.
3582 num_vf_mac_filters
= adapter
->hw
.mac
.rar_entry_count
-
3583 (1 + IGB_PF_MAC_FILTERS_RESERVED
+
3584 adapter
->vfs_allocated_count
);
3586 adapter
->vf_mac_list
= kcalloc(num_vf_mac_filters
,
3587 sizeof(struct vf_mac_filter
),
3590 mac_list
= adapter
->vf_mac_list
;
3591 INIT_LIST_HEAD(&adapter
->vf_macs
.l
);
3593 if (adapter
->vf_mac_list
) {
3594 /* Initialize list of VF MAC filters */
3595 for (i
= 0; i
< num_vf_mac_filters
; i
++) {
3597 mac_list
->free
= true;
3598 list_add(&mac_list
->l
, &adapter
->vf_macs
.l
);
3602 /* If we could not allocate memory for the VF MAC filters
3603 * we can continue without this feature but warn user.
3606 "Unable to allocate memory for VF MAC filter list\n");
3609 /* only call pci_enable_sriov() if no VFs are allocated already */
3611 err
= pci_enable_sriov(pdev
, adapter
->vfs_allocated_count
);
3615 dev_info(&pdev
->dev
, "%d VFs allocated\n",
3616 adapter
->vfs_allocated_count
);
3617 for (i
= 0; i
< adapter
->vfs_allocated_count
; i
++)
3618 igb_vf_configure(adapter
, i
);
3620 /* DMA Coalescing is not supported in IOV mode. */
3621 adapter
->flags
&= ~IGB_FLAG_DMAC
;
3625 kfree(adapter
->vf_mac_list
);
3626 adapter
->vf_mac_list
= NULL
;
3627 kfree(adapter
->vf_data
);
3628 adapter
->vf_data
= NULL
;
3629 adapter
->vfs_allocated_count
= 0;
3636 * igb_remove_i2c - Cleanup I2C interface
3637 * @adapter: pointer to adapter structure
3639 static void igb_remove_i2c(struct igb_adapter
*adapter
)
3641 /* free the adapter bus structure */
3642 i2c_del_adapter(&adapter
->i2c_adap
);
3646 * igb_remove - Device Removal Routine
3647 * @pdev: PCI device information struct
3649 * igb_remove is called by the PCI subsystem to alert the driver
3650 * that it should release a PCI device. The could be caused by a
3651 * Hot-Plug event, or because the driver is going to be removed from
3654 static void igb_remove(struct pci_dev
*pdev
)
3656 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3657 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3658 struct e1000_hw
*hw
= &adapter
->hw
;
3660 pm_runtime_get_noresume(&pdev
->dev
);
3661 #ifdef CONFIG_IGB_HWMON
3662 igb_sysfs_exit(adapter
);
3664 igb_remove_i2c(adapter
);
3665 igb_ptp_stop(adapter
);
3666 /* The watchdog timer may be rescheduled, so explicitly
3667 * disable watchdog from being rescheduled.
3669 set_bit(__IGB_DOWN
, &adapter
->state
);
3670 del_timer_sync(&adapter
->watchdog_timer
);
3671 del_timer_sync(&adapter
->phy_info_timer
);
3673 cancel_work_sync(&adapter
->reset_task
);
3674 cancel_work_sync(&adapter
->watchdog_task
);
3676 #ifdef CONFIG_IGB_DCA
3677 if (adapter
->flags
& IGB_FLAG_DCA_ENABLED
) {
3678 dev_info(&pdev
->dev
, "DCA disabled\n");
3679 dca_remove_requester(&pdev
->dev
);
3680 adapter
->flags
&= ~IGB_FLAG_DCA_ENABLED
;
3681 wr32(E1000_DCA_CTRL
, E1000_DCA_CTRL_DCA_MODE_DISABLE
);
3685 /* Release control of h/w to f/w. If f/w is AMT enabled, this
3686 * would have already happened in close and is redundant.
3688 igb_release_hw_control(adapter
);
3690 #ifdef CONFIG_PCI_IOV
3691 igb_disable_sriov(pdev
);
3694 unregister_netdev(netdev
);
3696 igb_clear_interrupt_scheme(adapter
);
3698 pci_iounmap(pdev
, adapter
->io_addr
);
3699 if (hw
->flash_address
)
3700 iounmap(hw
->flash_address
);
3701 pci_release_mem_regions(pdev
);
3703 kfree(adapter
->mac_table
);
3704 kfree(adapter
->shadow_vfta
);
3705 free_netdev(netdev
);
3707 pci_disable_pcie_error_reporting(pdev
);
3709 pci_disable_device(pdev
);
3713 * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space
3714 * @adapter: board private structure to initialize
3716 * This function initializes the vf specific data storage and then attempts to
3717 * allocate the VFs. The reason for ordering it this way is because it is much
3718 * mor expensive time wise to disable SR-IOV than it is to allocate and free
3719 * the memory for the VFs.
3721 static void igb_probe_vfs(struct igb_adapter
*adapter
)
3723 #ifdef CONFIG_PCI_IOV
3724 struct pci_dev
*pdev
= adapter
->pdev
;
3725 struct e1000_hw
*hw
= &adapter
->hw
;
3727 /* Virtualization features not supported on i210 family. */
3728 if ((hw
->mac
.type
== e1000_i210
) || (hw
->mac
.type
== e1000_i211
))
3731 /* Of the below we really only want the effect of getting
3732 * IGB_FLAG_HAS_MSIX set (if available), without which
3733 * igb_enable_sriov() has no effect.
3735 igb_set_interrupt_capability(adapter
, true);
3736 igb_reset_interrupt_capability(adapter
);
3738 pci_sriov_set_totalvfs(pdev
, 7);
3739 igb_enable_sriov(pdev
, max_vfs
);
3741 #endif /* CONFIG_PCI_IOV */
3744 unsigned int igb_get_max_rss_queues(struct igb_adapter
*adapter
)
3746 struct e1000_hw
*hw
= &adapter
->hw
;
3747 unsigned int max_rss_queues
;
3749 /* Determine the maximum number of RSS queues supported. */
3750 switch (hw
->mac
.type
) {
3752 max_rss_queues
= IGB_MAX_RX_QUEUES_I211
;
3756 max_rss_queues
= IGB_MAX_RX_QUEUES_82575
;
3759 /* I350 cannot do RSS and SR-IOV at the same time */
3760 if (!!adapter
->vfs_allocated_count
) {
3766 if (!!adapter
->vfs_allocated_count
) {
3774 max_rss_queues
= IGB_MAX_RX_QUEUES
;
3778 return max_rss_queues
;
3781 static void igb_init_queue_configuration(struct igb_adapter
*adapter
)
3785 max_rss_queues
= igb_get_max_rss_queues(adapter
);
3786 adapter
->rss_queues
= min_t(u32
, max_rss_queues
, num_online_cpus());
3788 igb_set_flag_queue_pairs(adapter
, max_rss_queues
);
3791 void igb_set_flag_queue_pairs(struct igb_adapter
*adapter
,
3792 const u32 max_rss_queues
)
3794 struct e1000_hw
*hw
= &adapter
->hw
;
3796 /* Determine if we need to pair queues. */
3797 switch (hw
->mac
.type
) {
3800 /* Device supports enough interrupts without queue pairing. */
3808 /* If rss_queues > half of max_rss_queues, pair the queues in
3809 * order to conserve interrupts due to limited supply.
3811 if (adapter
->rss_queues
> (max_rss_queues
/ 2))
3812 adapter
->flags
|= IGB_FLAG_QUEUE_PAIRS
;
3814 adapter
->flags
&= ~IGB_FLAG_QUEUE_PAIRS
;
3820 * igb_sw_init - Initialize general software structures (struct igb_adapter)
3821 * @adapter: board private structure to initialize
3823 * igb_sw_init initializes the Adapter private data structure.
3824 * Fields are initialized based on PCI device information and
3825 * OS network device settings (MTU size).
3827 static int igb_sw_init(struct igb_adapter
*adapter
)
3829 struct e1000_hw
*hw
= &adapter
->hw
;
3830 struct net_device
*netdev
= adapter
->netdev
;
3831 struct pci_dev
*pdev
= adapter
->pdev
;
3833 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->bus
.pci_cmd_word
);
3835 /* set default ring sizes */
3836 adapter
->tx_ring_count
= IGB_DEFAULT_TXD
;
3837 adapter
->rx_ring_count
= IGB_DEFAULT_RXD
;
3839 /* set default ITR values */
3840 adapter
->rx_itr_setting
= IGB_DEFAULT_ITR
;
3841 adapter
->tx_itr_setting
= IGB_DEFAULT_ITR
;
3843 /* set default work limits */
3844 adapter
->tx_work_limit
= IGB_DEFAULT_TX_WORK
;
3846 adapter
->max_frame_size
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+
3848 adapter
->min_frame_size
= ETH_ZLEN
+ ETH_FCS_LEN
;
3850 spin_lock_init(&adapter
->nfc_lock
);
3851 spin_lock_init(&adapter
->stats64_lock
);
3852 #ifdef CONFIG_PCI_IOV
3853 switch (hw
->mac
.type
) {
3857 dev_warn(&pdev
->dev
,
3858 "Maximum of 7 VFs per PF, using max\n");
3859 max_vfs
= adapter
->vfs_allocated_count
= 7;
3861 adapter
->vfs_allocated_count
= max_vfs
;
3862 if (adapter
->vfs_allocated_count
)
3863 dev_warn(&pdev
->dev
,
3864 "Enabling SR-IOV VFs using the module parameter is deprecated - please use the pci sysfs interface.\n");
3869 #endif /* CONFIG_PCI_IOV */
3871 /* Assume MSI-X interrupts, will be checked during IRQ allocation */
3872 adapter
->flags
|= IGB_FLAG_HAS_MSIX
;
3874 adapter
->mac_table
= kcalloc(hw
->mac
.rar_entry_count
,
3875 sizeof(struct igb_mac_addr
),
3877 if (!adapter
->mac_table
)
3880 igb_probe_vfs(adapter
);
3882 igb_init_queue_configuration(adapter
);
3884 /* Setup and initialize a copy of the hw vlan table array */
3885 adapter
->shadow_vfta
= kcalloc(E1000_VLAN_FILTER_TBL_SIZE
, sizeof(u32
),
3887 if (!adapter
->shadow_vfta
)
3890 /* This call may decrease the number of queues */
3891 if (igb_init_interrupt_scheme(adapter
, true)) {
3892 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
3896 /* Explicitly disable IRQ since the NIC can be in any state. */
3897 igb_irq_disable(adapter
);
3899 if (hw
->mac
.type
>= e1000_i350
)
3900 adapter
->flags
&= ~IGB_FLAG_DMAC
;
3902 set_bit(__IGB_DOWN
, &adapter
->state
);
3907 * igb_open - Called when a network interface is made active
3908 * @netdev: network interface device structure
3910 * Returns 0 on success, negative value on failure
3912 * The open entry point is called when a network interface is made
3913 * active by the system (IFF_UP). At this point all resources needed
3914 * for transmit and receive operations are allocated, the interrupt
3915 * handler is registered with the OS, the watchdog timer is started,
3916 * and the stack is notified that the interface is ready.
3918 static int __igb_open(struct net_device
*netdev
, bool resuming
)
3920 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3921 struct e1000_hw
*hw
= &adapter
->hw
;
3922 struct pci_dev
*pdev
= adapter
->pdev
;
3926 /* disallow open during test */
3927 if (test_bit(__IGB_TESTING
, &adapter
->state
)) {
3933 pm_runtime_get_sync(&pdev
->dev
);
3935 netif_carrier_off(netdev
);
3937 /* allocate transmit descriptors */
3938 err
= igb_setup_all_tx_resources(adapter
);
3942 /* allocate receive descriptors */
3943 err
= igb_setup_all_rx_resources(adapter
);
3947 igb_power_up_link(adapter
);
3949 /* before we allocate an interrupt, we must be ready to handle it.
3950 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3951 * as soon as we call pci_request_irq, so we have to setup our
3952 * clean_rx handler before we do so.
3954 igb_configure(adapter
);
3956 err
= igb_request_irq(adapter
);
3960 /* Notify the stack of the actual queue counts. */
3961 err
= netif_set_real_num_tx_queues(adapter
->netdev
,
3962 adapter
->num_tx_queues
);
3964 goto err_set_queues
;
3966 err
= netif_set_real_num_rx_queues(adapter
->netdev
,
3967 adapter
->num_rx_queues
);
3969 goto err_set_queues
;
3971 /* From here on the code is the same as igb_up() */
3972 clear_bit(__IGB_DOWN
, &adapter
->state
);
3974 for (i
= 0; i
< adapter
->num_q_vectors
; i
++)
3975 napi_enable(&(adapter
->q_vector
[i
]->napi
));
3977 /* Clear any pending interrupts. */
3981 igb_irq_enable(adapter
);
3983 /* notify VFs that reset has been completed */
3984 if (adapter
->vfs_allocated_count
) {
3985 u32 reg_data
= rd32(E1000_CTRL_EXT
);
3987 reg_data
|= E1000_CTRL_EXT_PFRSTD
;
3988 wr32(E1000_CTRL_EXT
, reg_data
);
3991 netif_tx_start_all_queues(netdev
);
3994 pm_runtime_put(&pdev
->dev
);
3996 /* start the watchdog. */
3997 hw
->mac
.get_link_status
= 1;
3998 schedule_work(&adapter
->watchdog_task
);
4003 igb_free_irq(adapter
);
4005 igb_release_hw_control(adapter
);
4006 igb_power_down_link(adapter
);
4007 igb_free_all_rx_resources(adapter
);
4009 igb_free_all_tx_resources(adapter
);
4013 pm_runtime_put(&pdev
->dev
);
4018 int igb_open(struct net_device
*netdev
)
4020 return __igb_open(netdev
, false);
4024 * igb_close - Disables a network interface
4025 * @netdev: network interface device structure
4027 * Returns 0, this is not allowed to fail
4029 * The close entry point is called when an interface is de-activated
4030 * by the OS. The hardware is still under the driver's control, but
4031 * needs to be disabled. A global MAC reset is issued to stop the
4032 * hardware, and all transmit and receive resources are freed.
4034 static int __igb_close(struct net_device
*netdev
, bool suspending
)
4036 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4037 struct pci_dev
*pdev
= adapter
->pdev
;
4039 WARN_ON(test_bit(__IGB_RESETTING
, &adapter
->state
));
4042 pm_runtime_get_sync(&pdev
->dev
);
4045 igb_free_irq(adapter
);
4047 igb_free_all_tx_resources(adapter
);
4048 igb_free_all_rx_resources(adapter
);
4051 pm_runtime_put_sync(&pdev
->dev
);
4055 int igb_close(struct net_device
*netdev
)
4057 if (netif_device_present(netdev
) || netdev
->dismantle
)
4058 return __igb_close(netdev
, false);
4063 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
4064 * @tx_ring: tx descriptor ring (for a specific queue) to setup
4066 * Return 0 on success, negative on failure
4068 int igb_setup_tx_resources(struct igb_ring
*tx_ring
)
4070 struct device
*dev
= tx_ring
->dev
;
4073 size
= sizeof(struct igb_tx_buffer
) * tx_ring
->count
;
4075 tx_ring
->tx_buffer_info
= vmalloc(size
);
4076 if (!tx_ring
->tx_buffer_info
)
4079 /* round up to nearest 4K */
4080 tx_ring
->size
= tx_ring
->count
* sizeof(union e1000_adv_tx_desc
);
4081 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
4083 tx_ring
->desc
= dma_alloc_coherent(dev
, tx_ring
->size
,
4084 &tx_ring
->dma
, GFP_KERNEL
);
4088 tx_ring
->next_to_use
= 0;
4089 tx_ring
->next_to_clean
= 0;
4094 vfree(tx_ring
->tx_buffer_info
);
4095 tx_ring
->tx_buffer_info
= NULL
;
4096 dev_err(dev
, "Unable to allocate memory for the Tx descriptor ring\n");
4101 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
4102 * (Descriptors) for all queues
4103 * @adapter: board private structure
4105 * Return 0 on success, negative on failure
4107 static int igb_setup_all_tx_resources(struct igb_adapter
*adapter
)
4109 struct pci_dev
*pdev
= adapter
->pdev
;
4112 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
4113 err
= igb_setup_tx_resources(adapter
->tx_ring
[i
]);
4116 "Allocation for Tx Queue %u failed\n", i
);
4117 for (i
--; i
>= 0; i
--)
4118 igb_free_tx_resources(adapter
->tx_ring
[i
]);
4127 * igb_setup_tctl - configure the transmit control registers
4128 * @adapter: Board private structure
4130 void igb_setup_tctl(struct igb_adapter
*adapter
)
4132 struct e1000_hw
*hw
= &adapter
->hw
;
4135 /* disable queue 0 which is enabled by default on 82575 and 82576 */
4136 wr32(E1000_TXDCTL(0), 0);
4138 /* Program the Transmit Control Register */
4139 tctl
= rd32(E1000_TCTL
);
4140 tctl
&= ~E1000_TCTL_CT
;
4141 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
4142 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
4144 igb_config_collision_dist(hw
);
4146 /* Enable transmits */
4147 tctl
|= E1000_TCTL_EN
;
4149 wr32(E1000_TCTL
, tctl
);
4153 * igb_configure_tx_ring - Configure transmit ring after Reset
4154 * @adapter: board private structure
4155 * @ring: tx ring to configure
4157 * Configure a transmit ring after a reset.
4159 void igb_configure_tx_ring(struct igb_adapter
*adapter
,
4160 struct igb_ring
*ring
)
4162 struct e1000_hw
*hw
= &adapter
->hw
;
4164 u64 tdba
= ring
->dma
;
4165 int reg_idx
= ring
->reg_idx
;
4167 wr32(E1000_TDLEN(reg_idx
),
4168 ring
->count
* sizeof(union e1000_adv_tx_desc
));
4169 wr32(E1000_TDBAL(reg_idx
),
4170 tdba
& 0x00000000ffffffffULL
);
4171 wr32(E1000_TDBAH(reg_idx
), tdba
>> 32);
4173 ring
->tail
= adapter
->io_addr
+ E1000_TDT(reg_idx
);
4174 wr32(E1000_TDH(reg_idx
), 0);
4175 writel(0, ring
->tail
);
4177 txdctl
|= IGB_TX_PTHRESH
;
4178 txdctl
|= IGB_TX_HTHRESH
<< 8;
4179 txdctl
|= IGB_TX_WTHRESH
<< 16;
4181 /* reinitialize tx_buffer_info */
4182 memset(ring
->tx_buffer_info
, 0,
4183 sizeof(struct igb_tx_buffer
) * ring
->count
);
4185 txdctl
|= E1000_TXDCTL_QUEUE_ENABLE
;
4186 wr32(E1000_TXDCTL(reg_idx
), txdctl
);
4190 * igb_configure_tx - Configure transmit Unit after Reset
4191 * @adapter: board private structure
4193 * Configure the Tx unit of the MAC after a reset.
4195 static void igb_configure_tx(struct igb_adapter
*adapter
)
4197 struct e1000_hw
*hw
= &adapter
->hw
;
4200 /* disable the queues */
4201 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4202 wr32(E1000_TXDCTL(adapter
->tx_ring
[i
]->reg_idx
), 0);
4205 usleep_range(10000, 20000);
4207 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4208 igb_configure_tx_ring(adapter
, adapter
->tx_ring
[i
]);
4212 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
4213 * @rx_ring: Rx descriptor ring (for a specific queue) to setup
4215 * Returns 0 on success, negative on failure
4217 int igb_setup_rx_resources(struct igb_ring
*rx_ring
)
4219 struct device
*dev
= rx_ring
->dev
;
4222 size
= sizeof(struct igb_rx_buffer
) * rx_ring
->count
;
4224 rx_ring
->rx_buffer_info
= vmalloc(size
);
4225 if (!rx_ring
->rx_buffer_info
)
4228 /* Round up to nearest 4K */
4229 rx_ring
->size
= rx_ring
->count
* sizeof(union e1000_adv_rx_desc
);
4230 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
4232 rx_ring
->desc
= dma_alloc_coherent(dev
, rx_ring
->size
,
4233 &rx_ring
->dma
, GFP_KERNEL
);
4237 rx_ring
->next_to_alloc
= 0;
4238 rx_ring
->next_to_clean
= 0;
4239 rx_ring
->next_to_use
= 0;
4244 vfree(rx_ring
->rx_buffer_info
);
4245 rx_ring
->rx_buffer_info
= NULL
;
4246 dev_err(dev
, "Unable to allocate memory for the Rx descriptor ring\n");
4251 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
4252 * (Descriptors) for all queues
4253 * @adapter: board private structure
4255 * Return 0 on success, negative on failure
4257 static int igb_setup_all_rx_resources(struct igb_adapter
*adapter
)
4259 struct pci_dev
*pdev
= adapter
->pdev
;
4262 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4263 err
= igb_setup_rx_resources(adapter
->rx_ring
[i
]);
4266 "Allocation for Rx Queue %u failed\n", i
);
4267 for (i
--; i
>= 0; i
--)
4268 igb_free_rx_resources(adapter
->rx_ring
[i
]);
4277 * igb_setup_mrqc - configure the multiple receive queue control registers
4278 * @adapter: Board private structure
4280 static void igb_setup_mrqc(struct igb_adapter
*adapter
)
4282 struct e1000_hw
*hw
= &adapter
->hw
;
4284 u32 j
, num_rx_queues
;
4287 netdev_rss_key_fill(rss_key
, sizeof(rss_key
));
4288 for (j
= 0; j
< 10; j
++)
4289 wr32(E1000_RSSRK(j
), rss_key
[j
]);
4291 num_rx_queues
= adapter
->rss_queues
;
4293 switch (hw
->mac
.type
) {
4295 /* 82576 supports 2 RSS queues for SR-IOV */
4296 if (adapter
->vfs_allocated_count
)
4303 if (adapter
->rss_indir_tbl_init
!= num_rx_queues
) {
4304 for (j
= 0; j
< IGB_RETA_SIZE
; j
++)
4305 adapter
->rss_indir_tbl
[j
] =
4306 (j
* num_rx_queues
) / IGB_RETA_SIZE
;
4307 adapter
->rss_indir_tbl_init
= num_rx_queues
;
4309 igb_write_rss_indir_tbl(adapter
);
4311 /* Disable raw packet checksumming so that RSS hash is placed in
4312 * descriptor on writeback. No need to enable TCP/UDP/IP checksum
4313 * offloads as they are enabled by default
4315 rxcsum
= rd32(E1000_RXCSUM
);
4316 rxcsum
|= E1000_RXCSUM_PCSD
;
4318 if (adapter
->hw
.mac
.type
>= e1000_82576
)
4319 /* Enable Receive Checksum Offload for SCTP */
4320 rxcsum
|= E1000_RXCSUM_CRCOFL
;
4322 /* Don't need to set TUOFL or IPOFL, they default to 1 */
4323 wr32(E1000_RXCSUM
, rxcsum
);
4325 /* Generate RSS hash based on packet types, TCP/UDP
4326 * port numbers and/or IPv4/v6 src and dst addresses
4328 mrqc
= E1000_MRQC_RSS_FIELD_IPV4
|
4329 E1000_MRQC_RSS_FIELD_IPV4_TCP
|
4330 E1000_MRQC_RSS_FIELD_IPV6
|
4331 E1000_MRQC_RSS_FIELD_IPV6_TCP
|
4332 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX
;
4334 if (adapter
->flags
& IGB_FLAG_RSS_FIELD_IPV4_UDP
)
4335 mrqc
|= E1000_MRQC_RSS_FIELD_IPV4_UDP
;
4336 if (adapter
->flags
& IGB_FLAG_RSS_FIELD_IPV6_UDP
)
4337 mrqc
|= E1000_MRQC_RSS_FIELD_IPV6_UDP
;
4339 /* If VMDq is enabled then we set the appropriate mode for that, else
4340 * we default to RSS so that an RSS hash is calculated per packet even
4341 * if we are only using one queue
4343 if (adapter
->vfs_allocated_count
) {
4344 if (hw
->mac
.type
> e1000_82575
) {
4345 /* Set the default pool for the PF's first queue */
4346 u32 vtctl
= rd32(E1000_VT_CTL
);
4348 vtctl
&= ~(E1000_VT_CTL_DEFAULT_POOL_MASK
|
4349 E1000_VT_CTL_DISABLE_DEF_POOL
);
4350 vtctl
|= adapter
->vfs_allocated_count
<<
4351 E1000_VT_CTL_DEFAULT_POOL_SHIFT
;
4352 wr32(E1000_VT_CTL
, vtctl
);
4354 if (adapter
->rss_queues
> 1)
4355 mrqc
|= E1000_MRQC_ENABLE_VMDQ_RSS_MQ
;
4357 mrqc
|= E1000_MRQC_ENABLE_VMDQ
;
4359 if (hw
->mac
.type
!= e1000_i211
)
4360 mrqc
|= E1000_MRQC_ENABLE_RSS_MQ
;
4362 igb_vmm_control(adapter
);
4364 wr32(E1000_MRQC
, mrqc
);
4368 * igb_setup_rctl - configure the receive control registers
4369 * @adapter: Board private structure
4371 void igb_setup_rctl(struct igb_adapter
*adapter
)
4373 struct e1000_hw
*hw
= &adapter
->hw
;
4376 rctl
= rd32(E1000_RCTL
);
4378 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
4379 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
4381 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_RDMTS_HALF
|
4382 (hw
->mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
4384 /* enable stripping of CRC. It's unlikely this will break BMC
4385 * redirection as it did with e1000. Newer features require
4386 * that the HW strips the CRC.
4388 rctl
|= E1000_RCTL_SECRC
;
4390 /* disable store bad packets and clear size bits. */
4391 rctl
&= ~(E1000_RCTL_SBP
| E1000_RCTL_SZ_256
);
4393 /* enable LPE to allow for reception of jumbo frames */
4394 rctl
|= E1000_RCTL_LPE
;
4396 /* disable queue 0 to prevent tail write w/o re-config */
4397 wr32(E1000_RXDCTL(0), 0);
4399 /* Attention!!! For SR-IOV PF driver operations you must enable
4400 * queue drop for all VF and PF queues to prevent head of line blocking
4401 * if an un-trusted VF does not provide descriptors to hardware.
4403 if (adapter
->vfs_allocated_count
) {
4404 /* set all queue drop enable bits */
4405 wr32(E1000_QDE
, ALL_QUEUES
);
4408 /* This is useful for sniffing bad packets. */
4409 if (adapter
->netdev
->features
& NETIF_F_RXALL
) {
4410 /* UPE and MPE will be handled by normal PROMISC logic
4411 * in e1000e_set_rx_mode
4413 rctl
|= (E1000_RCTL_SBP
| /* Receive bad packets */
4414 E1000_RCTL_BAM
| /* RX All Bcast Pkts */
4415 E1000_RCTL_PMCF
); /* RX All MAC Ctrl Pkts */
4417 rctl
&= ~(E1000_RCTL_DPF
| /* Allow filtered pause */
4418 E1000_RCTL_CFIEN
); /* Dis VLAN CFIEN Filter */
4419 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
4420 * and that breaks VLANs.
4424 wr32(E1000_RCTL
, rctl
);
4427 static inline int igb_set_vf_rlpml(struct igb_adapter
*adapter
, int size
,
4430 struct e1000_hw
*hw
= &adapter
->hw
;
4433 if (size
> MAX_JUMBO_FRAME_SIZE
)
4434 size
= MAX_JUMBO_FRAME_SIZE
;
4436 vmolr
= rd32(E1000_VMOLR(vfn
));
4437 vmolr
&= ~E1000_VMOLR_RLPML_MASK
;
4438 vmolr
|= size
| E1000_VMOLR_LPE
;
4439 wr32(E1000_VMOLR(vfn
), vmolr
);
4444 static inline void igb_set_vf_vlan_strip(struct igb_adapter
*adapter
,
4445 int vfn
, bool enable
)
4447 struct e1000_hw
*hw
= &adapter
->hw
;
4450 if (hw
->mac
.type
< e1000_82576
)
4453 if (hw
->mac
.type
== e1000_i350
)
4454 reg
= E1000_DVMOLR(vfn
);
4456 reg
= E1000_VMOLR(vfn
);
4460 val
|= E1000_VMOLR_STRVLAN
;
4462 val
&= ~(E1000_VMOLR_STRVLAN
);
4466 static inline void igb_set_vmolr(struct igb_adapter
*adapter
,
4469 struct e1000_hw
*hw
= &adapter
->hw
;
4472 /* This register exists only on 82576 and newer so if we are older then
4473 * we should exit and do nothing
4475 if (hw
->mac
.type
< e1000_82576
)
4478 vmolr
= rd32(E1000_VMOLR(vfn
));
4480 vmolr
|= E1000_VMOLR_AUPE
; /* Accept untagged packets */
4482 vmolr
&= ~(E1000_VMOLR_AUPE
); /* Tagged packets ONLY */
4484 /* clear all bits that might not be set */
4485 vmolr
&= ~(E1000_VMOLR_BAM
| E1000_VMOLR_RSSE
);
4487 if (adapter
->rss_queues
> 1 && vfn
== adapter
->vfs_allocated_count
)
4488 vmolr
|= E1000_VMOLR_RSSE
; /* enable RSS */
4489 /* for VMDq only allow the VFs and pool 0 to accept broadcast and
4492 if (vfn
<= adapter
->vfs_allocated_count
)
4493 vmolr
|= E1000_VMOLR_BAM
; /* Accept broadcast */
4495 wr32(E1000_VMOLR(vfn
), vmolr
);
4499 * igb_configure_rx_ring - Configure a receive ring after Reset
4500 * @adapter: board private structure
4501 * @ring: receive ring to be configured
4503 * Configure the Rx unit of the MAC after a reset.
4505 void igb_configure_rx_ring(struct igb_adapter
*adapter
,
4506 struct igb_ring
*ring
)
4508 struct e1000_hw
*hw
= &adapter
->hw
;
4509 union e1000_adv_rx_desc
*rx_desc
;
4510 u64 rdba
= ring
->dma
;
4511 int reg_idx
= ring
->reg_idx
;
4512 u32 srrctl
= 0, rxdctl
= 0;
4514 /* disable the queue */
4515 wr32(E1000_RXDCTL(reg_idx
), 0);
4517 /* Set DMA base address registers */
4518 wr32(E1000_RDBAL(reg_idx
),
4519 rdba
& 0x00000000ffffffffULL
);
4520 wr32(E1000_RDBAH(reg_idx
), rdba
>> 32);
4521 wr32(E1000_RDLEN(reg_idx
),
4522 ring
->count
* sizeof(union e1000_adv_rx_desc
));
4524 /* initialize head and tail */
4525 ring
->tail
= adapter
->io_addr
+ E1000_RDT(reg_idx
);
4526 wr32(E1000_RDH(reg_idx
), 0);
4527 writel(0, ring
->tail
);
4529 /* set descriptor configuration */
4530 srrctl
= IGB_RX_HDR_LEN
<< E1000_SRRCTL_BSIZEHDRSIZE_SHIFT
;
4531 if (ring_uses_large_buffer(ring
))
4532 srrctl
|= IGB_RXBUFFER_3072
>> E1000_SRRCTL_BSIZEPKT_SHIFT
;
4534 srrctl
|= IGB_RXBUFFER_2048
>> E1000_SRRCTL_BSIZEPKT_SHIFT
;
4535 srrctl
|= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF
;
4536 if (hw
->mac
.type
>= e1000_82580
)
4537 srrctl
|= E1000_SRRCTL_TIMESTAMP
;
4538 /* Only set Drop Enable if we are supporting multiple queues */
4539 if (adapter
->vfs_allocated_count
|| adapter
->num_rx_queues
> 1)
4540 srrctl
|= E1000_SRRCTL_DROP_EN
;
4542 wr32(E1000_SRRCTL(reg_idx
), srrctl
);
4544 /* set filtering for VMDQ pools */
4545 igb_set_vmolr(adapter
, reg_idx
& 0x7, true);
4547 rxdctl
|= IGB_RX_PTHRESH
;
4548 rxdctl
|= IGB_RX_HTHRESH
<< 8;
4549 rxdctl
|= IGB_RX_WTHRESH
<< 16;
4551 /* initialize rx_buffer_info */
4552 memset(ring
->rx_buffer_info
, 0,
4553 sizeof(struct igb_rx_buffer
) * ring
->count
);
4555 /* initialize Rx descriptor 0 */
4556 rx_desc
= IGB_RX_DESC(ring
, 0);
4557 rx_desc
->wb
.upper
.length
= 0;
4559 /* enable receive descriptor fetching */
4560 rxdctl
|= E1000_RXDCTL_QUEUE_ENABLE
;
4561 wr32(E1000_RXDCTL(reg_idx
), rxdctl
);
4564 static void igb_set_rx_buffer_len(struct igb_adapter
*adapter
,
4565 struct igb_ring
*rx_ring
)
4567 /* set build_skb and buffer size flags */
4568 clear_ring_build_skb_enabled(rx_ring
);
4569 clear_ring_uses_large_buffer(rx_ring
);
4571 if (adapter
->flags
& IGB_FLAG_RX_LEGACY
)
4574 set_ring_build_skb_enabled(rx_ring
);
4576 #if (PAGE_SIZE < 8192)
4577 if (adapter
->max_frame_size
<= IGB_MAX_FRAME_BUILD_SKB
)
4580 set_ring_uses_large_buffer(rx_ring
);
4585 * igb_configure_rx - Configure receive Unit after Reset
4586 * @adapter: board private structure
4588 * Configure the Rx unit of the MAC after a reset.
4590 static void igb_configure_rx(struct igb_adapter
*adapter
)
4594 /* set the correct pool for the PF default MAC address in entry 0 */
4595 igb_set_default_mac_filter(adapter
);
4597 /* Setup the HW Rx Head and Tail Descriptor Pointers and
4598 * the Base and Length of the Rx Descriptor Ring
4600 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4601 struct igb_ring
*rx_ring
= adapter
->rx_ring
[i
];
4603 igb_set_rx_buffer_len(adapter
, rx_ring
);
4604 igb_configure_rx_ring(adapter
, rx_ring
);
4609 * igb_free_tx_resources - Free Tx Resources per Queue
4610 * @tx_ring: Tx descriptor ring for a specific queue
4612 * Free all transmit software resources
4614 void igb_free_tx_resources(struct igb_ring
*tx_ring
)
4616 igb_clean_tx_ring(tx_ring
);
4618 vfree(tx_ring
->tx_buffer_info
);
4619 tx_ring
->tx_buffer_info
= NULL
;
4621 /* if not set, then don't free */
4625 dma_free_coherent(tx_ring
->dev
, tx_ring
->size
,
4626 tx_ring
->desc
, tx_ring
->dma
);
4628 tx_ring
->desc
= NULL
;
4632 * igb_free_all_tx_resources - Free Tx Resources for All Queues
4633 * @adapter: board private structure
4635 * Free all transmit software resources
4637 static void igb_free_all_tx_resources(struct igb_adapter
*adapter
)
4641 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4642 if (adapter
->tx_ring
[i
])
4643 igb_free_tx_resources(adapter
->tx_ring
[i
]);
4647 * igb_clean_tx_ring - Free Tx Buffers
4648 * @tx_ring: ring to be cleaned
4650 static void igb_clean_tx_ring(struct igb_ring
*tx_ring
)
4652 u16 i
= tx_ring
->next_to_clean
;
4653 struct igb_tx_buffer
*tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
4655 while (i
!= tx_ring
->next_to_use
) {
4656 union e1000_adv_tx_desc
*eop_desc
, *tx_desc
;
4658 /* Free all the Tx ring sk_buffs */
4659 dev_kfree_skb_any(tx_buffer
->skb
);
4661 /* unmap skb header data */
4662 dma_unmap_single(tx_ring
->dev
,
4663 dma_unmap_addr(tx_buffer
, dma
),
4664 dma_unmap_len(tx_buffer
, len
),
4667 /* check for eop_desc to determine the end of the packet */
4668 eop_desc
= tx_buffer
->next_to_watch
;
4669 tx_desc
= IGB_TX_DESC(tx_ring
, i
);
4671 /* unmap remaining buffers */
4672 while (tx_desc
!= eop_desc
) {
4676 if (unlikely(i
== tx_ring
->count
)) {
4678 tx_buffer
= tx_ring
->tx_buffer_info
;
4679 tx_desc
= IGB_TX_DESC(tx_ring
, 0);
4682 /* unmap any remaining paged data */
4683 if (dma_unmap_len(tx_buffer
, len
))
4684 dma_unmap_page(tx_ring
->dev
,
4685 dma_unmap_addr(tx_buffer
, dma
),
4686 dma_unmap_len(tx_buffer
, len
),
4690 /* move us one more past the eop_desc for start of next pkt */
4693 if (unlikely(i
== tx_ring
->count
)) {
4695 tx_buffer
= tx_ring
->tx_buffer_info
;
4699 /* reset BQL for queue */
4700 netdev_tx_reset_queue(txring_txq(tx_ring
));
4702 /* reset next_to_use and next_to_clean */
4703 tx_ring
->next_to_use
= 0;
4704 tx_ring
->next_to_clean
= 0;
4708 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
4709 * @adapter: board private structure
4711 static void igb_clean_all_tx_rings(struct igb_adapter
*adapter
)
4715 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4716 if (adapter
->tx_ring
[i
])
4717 igb_clean_tx_ring(adapter
->tx_ring
[i
]);
4721 * igb_free_rx_resources - Free Rx Resources
4722 * @rx_ring: ring to clean the resources from
4724 * Free all receive software resources
4726 void igb_free_rx_resources(struct igb_ring
*rx_ring
)
4728 igb_clean_rx_ring(rx_ring
);
4730 vfree(rx_ring
->rx_buffer_info
);
4731 rx_ring
->rx_buffer_info
= NULL
;
4733 /* if not set, then don't free */
4737 dma_free_coherent(rx_ring
->dev
, rx_ring
->size
,
4738 rx_ring
->desc
, rx_ring
->dma
);
4740 rx_ring
->desc
= NULL
;
4744 * igb_free_all_rx_resources - Free Rx Resources for All Queues
4745 * @adapter: board private structure
4747 * Free all receive software resources
4749 static void igb_free_all_rx_resources(struct igb_adapter
*adapter
)
4753 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4754 if (adapter
->rx_ring
[i
])
4755 igb_free_rx_resources(adapter
->rx_ring
[i
]);
4759 * igb_clean_rx_ring - Free Rx Buffers per Queue
4760 * @rx_ring: ring to free buffers from
4762 static void igb_clean_rx_ring(struct igb_ring
*rx_ring
)
4764 u16 i
= rx_ring
->next_to_clean
;
4767 dev_kfree_skb(rx_ring
->skb
);
4768 rx_ring
->skb
= NULL
;
4770 /* Free all the Rx ring sk_buffs */
4771 while (i
!= rx_ring
->next_to_alloc
) {
4772 struct igb_rx_buffer
*buffer_info
= &rx_ring
->rx_buffer_info
[i
];
4774 /* Invalidate cache lines that may have been written to by
4775 * device so that we avoid corrupting memory.
4777 dma_sync_single_range_for_cpu(rx_ring
->dev
,
4779 buffer_info
->page_offset
,
4780 igb_rx_bufsz(rx_ring
),
4783 /* free resources associated with mapping */
4784 dma_unmap_page_attrs(rx_ring
->dev
,
4786 igb_rx_pg_size(rx_ring
),
4789 __page_frag_cache_drain(buffer_info
->page
,
4790 buffer_info
->pagecnt_bias
);
4793 if (i
== rx_ring
->count
)
4797 rx_ring
->next_to_alloc
= 0;
4798 rx_ring
->next_to_clean
= 0;
4799 rx_ring
->next_to_use
= 0;
4803 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
4804 * @adapter: board private structure
4806 static void igb_clean_all_rx_rings(struct igb_adapter
*adapter
)
4810 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4811 if (adapter
->rx_ring
[i
])
4812 igb_clean_rx_ring(adapter
->rx_ring
[i
]);
4816 * igb_set_mac - Change the Ethernet Address of the NIC
4817 * @netdev: network interface device structure
4818 * @p: pointer to an address structure
4820 * Returns 0 on success, negative on failure
4822 static int igb_set_mac(struct net_device
*netdev
, void *p
)
4824 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4825 struct e1000_hw
*hw
= &adapter
->hw
;
4826 struct sockaddr
*addr
= p
;
4828 if (!is_valid_ether_addr(addr
->sa_data
))
4829 return -EADDRNOTAVAIL
;
4831 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
4832 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
4834 /* set the correct pool for the new PF MAC address in entry 0 */
4835 igb_set_default_mac_filter(adapter
);
4841 * igb_write_mc_addr_list - write multicast addresses to MTA
4842 * @netdev: network interface device structure
4844 * Writes multicast address list to the MTA hash table.
4845 * Returns: -ENOMEM on failure
4846 * 0 on no addresses written
4847 * X on writing X addresses to MTA
4849 static int igb_write_mc_addr_list(struct net_device
*netdev
)
4851 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4852 struct e1000_hw
*hw
= &adapter
->hw
;
4853 struct netdev_hw_addr
*ha
;
4857 if (netdev_mc_empty(netdev
)) {
4858 /* nothing to program, so clear mc list */
4859 igb_update_mc_addr_list(hw
, NULL
, 0);
4860 igb_restore_vf_multicasts(adapter
);
4864 mta_list
= kcalloc(netdev_mc_count(netdev
), 6, GFP_ATOMIC
);
4868 /* The shared function expects a packed array of only addresses. */
4870 netdev_for_each_mc_addr(ha
, netdev
)
4871 memcpy(mta_list
+ (i
++ * ETH_ALEN
), ha
->addr
, ETH_ALEN
);
4873 igb_update_mc_addr_list(hw
, mta_list
, i
);
4876 return netdev_mc_count(netdev
);
4879 static int igb_vlan_promisc_enable(struct igb_adapter
*adapter
)
4881 struct e1000_hw
*hw
= &adapter
->hw
;
4884 switch (hw
->mac
.type
) {
4888 /* VLAN filtering needed for VLAN prio filter */
4889 if (adapter
->netdev
->features
& NETIF_F_NTUPLE
)
4895 /* VLAN filtering needed for pool filtering */
4896 if (adapter
->vfs_allocated_count
)
4903 /* We are already in VLAN promisc, nothing to do */
4904 if (adapter
->flags
& IGB_FLAG_VLAN_PROMISC
)
4907 if (!adapter
->vfs_allocated_count
)
4910 /* Add PF to all active pools */
4911 pf_id
= adapter
->vfs_allocated_count
+ E1000_VLVF_POOLSEL_SHIFT
;
4913 for (i
= E1000_VLVF_ARRAY_SIZE
; --i
;) {
4914 u32 vlvf
= rd32(E1000_VLVF(i
));
4917 wr32(E1000_VLVF(i
), vlvf
);
4921 /* Set all bits in the VLAN filter table array */
4922 for (i
= E1000_VLAN_FILTER_TBL_SIZE
; i
--;)
4923 hw
->mac
.ops
.write_vfta(hw
, i
, ~0U);
4925 /* Set flag so we don't redo unnecessary work */
4926 adapter
->flags
|= IGB_FLAG_VLAN_PROMISC
;
4931 #define VFTA_BLOCK_SIZE 8
4932 static void igb_scrub_vfta(struct igb_adapter
*adapter
, u32 vfta_offset
)
4934 struct e1000_hw
*hw
= &adapter
->hw
;
4935 u32 vfta
[VFTA_BLOCK_SIZE
] = { 0 };
4936 u32 vid_start
= vfta_offset
* 32;
4937 u32 vid_end
= vid_start
+ (VFTA_BLOCK_SIZE
* 32);
4938 u32 i
, vid
, word
, bits
, pf_id
;
4940 /* guarantee that we don't scrub out management VLAN */
4941 vid
= adapter
->mng_vlan_id
;
4942 if (vid
>= vid_start
&& vid
< vid_end
)
4943 vfta
[(vid
- vid_start
) / 32] |= BIT(vid
% 32);
4945 if (!adapter
->vfs_allocated_count
)
4948 pf_id
= adapter
->vfs_allocated_count
+ E1000_VLVF_POOLSEL_SHIFT
;
4950 for (i
= E1000_VLVF_ARRAY_SIZE
; --i
;) {
4951 u32 vlvf
= rd32(E1000_VLVF(i
));
4953 /* pull VLAN ID from VLVF */
4954 vid
= vlvf
& VLAN_VID_MASK
;
4956 /* only concern ourselves with a certain range */
4957 if (vid
< vid_start
|| vid
>= vid_end
)
4960 if (vlvf
& E1000_VLVF_VLANID_ENABLE
) {
4961 /* record VLAN ID in VFTA */
4962 vfta
[(vid
- vid_start
) / 32] |= BIT(vid
% 32);
4964 /* if PF is part of this then continue */
4965 if (test_bit(vid
, adapter
->active_vlans
))
4969 /* remove PF from the pool */
4971 bits
&= rd32(E1000_VLVF(i
));
4972 wr32(E1000_VLVF(i
), bits
);
4976 /* extract values from active_vlans and write back to VFTA */
4977 for (i
= VFTA_BLOCK_SIZE
; i
--;) {
4978 vid
= (vfta_offset
+ i
) * 32;
4979 word
= vid
/ BITS_PER_LONG
;
4980 bits
= vid
% BITS_PER_LONG
;
4982 vfta
[i
] |= adapter
->active_vlans
[word
] >> bits
;
4984 hw
->mac
.ops
.write_vfta(hw
, vfta_offset
+ i
, vfta
[i
]);
4988 static void igb_vlan_promisc_disable(struct igb_adapter
*adapter
)
4992 /* We are not in VLAN promisc, nothing to do */
4993 if (!(adapter
->flags
& IGB_FLAG_VLAN_PROMISC
))
4996 /* Set flag so we don't redo unnecessary work */
4997 adapter
->flags
&= ~IGB_FLAG_VLAN_PROMISC
;
4999 for (i
= 0; i
< E1000_VLAN_FILTER_TBL_SIZE
; i
+= VFTA_BLOCK_SIZE
)
5000 igb_scrub_vfta(adapter
, i
);
5004 * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
5005 * @netdev: network interface device structure
5007 * The set_rx_mode entry point is called whenever the unicast or multicast
5008 * address lists or the network interface flags are updated. This routine is
5009 * responsible for configuring the hardware for proper unicast, multicast,
5010 * promiscuous mode, and all-multi behavior.
5012 static void igb_set_rx_mode(struct net_device
*netdev
)
5014 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5015 struct e1000_hw
*hw
= &adapter
->hw
;
5016 unsigned int vfn
= adapter
->vfs_allocated_count
;
5017 u32 rctl
= 0, vmolr
= 0, rlpml
= MAX_JUMBO_FRAME_SIZE
;
5020 /* Check for Promiscuous and All Multicast modes */
5021 if (netdev
->flags
& IFF_PROMISC
) {
5022 rctl
|= E1000_RCTL_UPE
| E1000_RCTL_MPE
;
5023 vmolr
|= E1000_VMOLR_MPME
;
5025 /* enable use of UTA filter to force packets to default pool */
5026 if (hw
->mac
.type
== e1000_82576
)
5027 vmolr
|= E1000_VMOLR_ROPE
;
5029 if (netdev
->flags
& IFF_ALLMULTI
) {
5030 rctl
|= E1000_RCTL_MPE
;
5031 vmolr
|= E1000_VMOLR_MPME
;
5033 /* Write addresses to the MTA, if the attempt fails
5034 * then we should just turn on promiscuous mode so
5035 * that we can at least receive multicast traffic
5037 count
= igb_write_mc_addr_list(netdev
);
5039 rctl
|= E1000_RCTL_MPE
;
5040 vmolr
|= E1000_VMOLR_MPME
;
5042 vmolr
|= E1000_VMOLR_ROMPE
;
5047 /* Write addresses to available RAR registers, if there is not
5048 * sufficient space to store all the addresses then enable
5049 * unicast promiscuous mode
5051 if (__dev_uc_sync(netdev
, igb_uc_sync
, igb_uc_unsync
)) {
5052 rctl
|= E1000_RCTL_UPE
;
5053 vmolr
|= E1000_VMOLR_ROPE
;
5056 /* enable VLAN filtering by default */
5057 rctl
|= E1000_RCTL_VFE
;
5059 /* disable VLAN filtering for modes that require it */
5060 if ((netdev
->flags
& IFF_PROMISC
) ||
5061 (netdev
->features
& NETIF_F_RXALL
)) {
5062 /* if we fail to set all rules then just clear VFE */
5063 if (igb_vlan_promisc_enable(adapter
))
5064 rctl
&= ~E1000_RCTL_VFE
;
5066 igb_vlan_promisc_disable(adapter
);
5069 /* update state of unicast, multicast, and VLAN filtering modes */
5070 rctl
|= rd32(E1000_RCTL
) & ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
|
5072 wr32(E1000_RCTL
, rctl
);
5074 #if (PAGE_SIZE < 8192)
5075 if (!adapter
->vfs_allocated_count
) {
5076 if (adapter
->max_frame_size
<= IGB_MAX_FRAME_BUILD_SKB
)
5077 rlpml
= IGB_MAX_FRAME_BUILD_SKB
;
5080 wr32(E1000_RLPML
, rlpml
);
5082 /* In order to support SR-IOV and eventually VMDq it is necessary to set
5083 * the VMOLR to enable the appropriate modes. Without this workaround
5084 * we will have issues with VLAN tag stripping not being done for frames
5085 * that are only arriving because we are the default pool
5087 if ((hw
->mac
.type
< e1000_82576
) || (hw
->mac
.type
> e1000_i350
))
5090 /* set UTA to appropriate mode */
5091 igb_set_uta(adapter
, !!(vmolr
& E1000_VMOLR_ROPE
));
5093 vmolr
|= rd32(E1000_VMOLR(vfn
)) &
5094 ~(E1000_VMOLR_ROPE
| E1000_VMOLR_MPME
| E1000_VMOLR_ROMPE
);
5096 /* enable Rx jumbo frames, restrict as needed to support build_skb */
5097 vmolr
&= ~E1000_VMOLR_RLPML_MASK
;
5098 #if (PAGE_SIZE < 8192)
5099 if (adapter
->max_frame_size
<= IGB_MAX_FRAME_BUILD_SKB
)
5100 vmolr
|= IGB_MAX_FRAME_BUILD_SKB
;
5103 vmolr
|= MAX_JUMBO_FRAME_SIZE
;
5104 vmolr
|= E1000_VMOLR_LPE
;
5106 wr32(E1000_VMOLR(vfn
), vmolr
);
5108 igb_restore_vf_multicasts(adapter
);
5111 static void igb_check_wvbr(struct igb_adapter
*adapter
)
5113 struct e1000_hw
*hw
= &adapter
->hw
;
5116 switch (hw
->mac
.type
) {
5119 wvbr
= rd32(E1000_WVBR
);
5127 adapter
->wvbr
|= wvbr
;
5130 #define IGB_STAGGERED_QUEUE_OFFSET 8
5132 static void igb_spoof_check(struct igb_adapter
*adapter
)
5139 for (j
= 0; j
< adapter
->vfs_allocated_count
; j
++) {
5140 if (adapter
->wvbr
& BIT(j
) ||
5141 adapter
->wvbr
& BIT(j
+ IGB_STAGGERED_QUEUE_OFFSET
)) {
5142 dev_warn(&adapter
->pdev
->dev
,
5143 "Spoof event(s) detected on VF %d\n", j
);
5146 BIT(j
+ IGB_STAGGERED_QUEUE_OFFSET
));
5151 /* Need to wait a few seconds after link up to get diagnostic information from
5154 static void igb_update_phy_info(struct timer_list
*t
)
5156 struct igb_adapter
*adapter
= from_timer(adapter
, t
, phy_info_timer
);
5157 igb_get_phy_info(&adapter
->hw
);
5161 * igb_has_link - check shared code for link and determine up/down
5162 * @adapter: pointer to driver private info
5164 bool igb_has_link(struct igb_adapter
*adapter
)
5166 struct e1000_hw
*hw
= &adapter
->hw
;
5167 bool link_active
= false;
5169 /* get_link_status is set on LSC (link status) interrupt or
5170 * rx sequence error interrupt. get_link_status will stay
5171 * false until the e1000_check_for_link establishes link
5172 * for copper adapters ONLY
5174 switch (hw
->phy
.media_type
) {
5175 case e1000_media_type_copper
:
5176 if (!hw
->mac
.get_link_status
)
5179 case e1000_media_type_internal_serdes
:
5180 hw
->mac
.ops
.check_for_link(hw
);
5181 link_active
= !hw
->mac
.get_link_status
;
5184 case e1000_media_type_unknown
:
5188 if (((hw
->mac
.type
== e1000_i210
) ||
5189 (hw
->mac
.type
== e1000_i211
)) &&
5190 (hw
->phy
.id
== I210_I_PHY_ID
)) {
5191 if (!netif_carrier_ok(adapter
->netdev
)) {
5192 adapter
->flags
&= ~IGB_FLAG_NEED_LINK_UPDATE
;
5193 } else if (!(adapter
->flags
& IGB_FLAG_NEED_LINK_UPDATE
)) {
5194 adapter
->flags
|= IGB_FLAG_NEED_LINK_UPDATE
;
5195 adapter
->link_check_timeout
= jiffies
;
5202 static bool igb_thermal_sensor_event(struct e1000_hw
*hw
, u32 event
)
5205 u32 ctrl_ext
, thstat
;
5207 /* check for thermal sensor event on i350 copper only */
5208 if (hw
->mac
.type
== e1000_i350
) {
5209 thstat
= rd32(E1000_THSTAT
);
5210 ctrl_ext
= rd32(E1000_CTRL_EXT
);
5212 if ((hw
->phy
.media_type
== e1000_media_type_copper
) &&
5213 !(ctrl_ext
& E1000_CTRL_EXT_LINK_MODE_SGMII
))
5214 ret
= !!(thstat
& event
);
5221 * igb_check_lvmmc - check for malformed packets received
5222 * and indicated in LVMMC register
5223 * @adapter: pointer to adapter
5225 static void igb_check_lvmmc(struct igb_adapter
*adapter
)
5227 struct e1000_hw
*hw
= &adapter
->hw
;
5230 lvmmc
= rd32(E1000_LVMMC
);
5232 if (unlikely(net_ratelimit())) {
5233 netdev_warn(adapter
->netdev
,
5234 "malformed Tx packet detected and dropped, LVMMC:0x%08x\n",
5241 * igb_watchdog - Timer Call-back
5242 * @data: pointer to adapter cast into an unsigned long
5244 static void igb_watchdog(struct timer_list
*t
)
5246 struct igb_adapter
*adapter
= from_timer(adapter
, t
, watchdog_timer
);
5247 /* Do the rest outside of interrupt context */
5248 schedule_work(&adapter
->watchdog_task
);
5251 static void igb_watchdog_task(struct work_struct
*work
)
5253 struct igb_adapter
*adapter
= container_of(work
,
5256 struct e1000_hw
*hw
= &adapter
->hw
;
5257 struct e1000_phy_info
*phy
= &hw
->phy
;
5258 struct net_device
*netdev
= adapter
->netdev
;
5262 u16 phy_data
, retry_count
= 20;
5264 link
= igb_has_link(adapter
);
5266 if (adapter
->flags
& IGB_FLAG_NEED_LINK_UPDATE
) {
5267 if (time_after(jiffies
, (adapter
->link_check_timeout
+ HZ
)))
5268 adapter
->flags
&= ~IGB_FLAG_NEED_LINK_UPDATE
;
5273 /* Force link down if we have fiber to swap to */
5274 if (adapter
->flags
& IGB_FLAG_MAS_ENABLE
) {
5275 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
5276 connsw
= rd32(E1000_CONNSW
);
5277 if (!(connsw
& E1000_CONNSW_AUTOSENSE_EN
))
5282 /* Perform a reset if the media type changed. */
5283 if (hw
->dev_spec
._82575
.media_changed
) {
5284 hw
->dev_spec
._82575
.media_changed
= false;
5285 adapter
->flags
|= IGB_FLAG_MEDIA_RESET
;
5288 /* Cancel scheduled suspend requests. */
5289 pm_runtime_resume(netdev
->dev
.parent
);
5291 if (!netif_carrier_ok(netdev
)) {
5294 hw
->mac
.ops
.get_speed_and_duplex(hw
,
5295 &adapter
->link_speed
,
5296 &adapter
->link_duplex
);
5298 ctrl
= rd32(E1000_CTRL
);
5299 /* Links status message must follow this format */
5301 "igb: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
5303 adapter
->link_speed
,
5304 adapter
->link_duplex
== FULL_DUPLEX
?
5306 (ctrl
& E1000_CTRL_TFCE
) &&
5307 (ctrl
& E1000_CTRL_RFCE
) ? "RX/TX" :
5308 (ctrl
& E1000_CTRL_RFCE
) ? "RX" :
5309 (ctrl
& E1000_CTRL_TFCE
) ? "TX" : "None");
5311 /* disable EEE if enabled */
5312 if ((adapter
->flags
& IGB_FLAG_EEE
) &&
5313 (adapter
->link_duplex
== HALF_DUPLEX
)) {
5314 dev_info(&adapter
->pdev
->dev
,
5315 "EEE Disabled: unsupported at half duplex. Re-enable using ethtool when at full duplex.\n");
5316 adapter
->hw
.dev_spec
._82575
.eee_disable
= true;
5317 adapter
->flags
&= ~IGB_FLAG_EEE
;
5320 /* check if SmartSpeed worked */
5321 igb_check_downshift(hw
);
5322 if (phy
->speed_downgraded
)
5323 netdev_warn(netdev
, "Link Speed was downgraded by SmartSpeed\n");
5325 /* check for thermal sensor event */
5326 if (igb_thermal_sensor_event(hw
,
5327 E1000_THSTAT_LINK_THROTTLE
))
5328 netdev_info(netdev
, "The network adapter link speed was downshifted because it overheated\n");
5330 /* adjust timeout factor according to speed/duplex */
5331 adapter
->tx_timeout_factor
= 1;
5332 switch (adapter
->link_speed
) {
5334 adapter
->tx_timeout_factor
= 14;
5337 /* maybe add some timeout factor ? */
5341 if (adapter
->link_speed
!= SPEED_1000
)
5344 /* wait for Remote receiver status OK */
5346 if (!igb_read_phy_reg(hw
, PHY_1000T_STATUS
,
5348 if (!(phy_data
& SR_1000T_REMOTE_RX_STATUS
) &&
5352 goto retry_read_status
;
5353 } else if (!retry_count
) {
5354 dev_err(&adapter
->pdev
->dev
, "exceed max 2 second\n");
5357 dev_err(&adapter
->pdev
->dev
, "read 1000Base-T Status Reg\n");
5360 netif_carrier_on(netdev
);
5362 igb_ping_all_vfs(adapter
);
5363 igb_check_vf_rate_limit(adapter
);
5365 /* link state has changed, schedule phy info update */
5366 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
5367 mod_timer(&adapter
->phy_info_timer
,
5368 round_jiffies(jiffies
+ 2 * HZ
));
5371 if (netif_carrier_ok(netdev
)) {
5372 adapter
->link_speed
= 0;
5373 adapter
->link_duplex
= 0;
5375 /* check for thermal sensor event */
5376 if (igb_thermal_sensor_event(hw
,
5377 E1000_THSTAT_PWR_DOWN
)) {
5378 netdev_err(netdev
, "The network adapter was stopped because it overheated\n");
5381 /* Links status message must follow this format */
5382 netdev_info(netdev
, "igb: %s NIC Link is Down\n",
5384 netif_carrier_off(netdev
);
5386 igb_ping_all_vfs(adapter
);
5388 /* link state has changed, schedule phy info update */
5389 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
5390 mod_timer(&adapter
->phy_info_timer
,
5391 round_jiffies(jiffies
+ 2 * HZ
));
5393 /* link is down, time to check for alternate media */
5394 if (adapter
->flags
& IGB_FLAG_MAS_ENABLE
) {
5395 igb_check_swap_media(adapter
);
5396 if (adapter
->flags
& IGB_FLAG_MEDIA_RESET
) {
5397 schedule_work(&adapter
->reset_task
);
5398 /* return immediately */
5402 pm_schedule_suspend(netdev
->dev
.parent
,
5405 /* also check for alternate media here */
5406 } else if (!netif_carrier_ok(netdev
) &&
5407 (adapter
->flags
& IGB_FLAG_MAS_ENABLE
)) {
5408 igb_check_swap_media(adapter
);
5409 if (adapter
->flags
& IGB_FLAG_MEDIA_RESET
) {
5410 schedule_work(&adapter
->reset_task
);
5411 /* return immediately */
5417 spin_lock(&adapter
->stats64_lock
);
5418 igb_update_stats(adapter
);
5419 spin_unlock(&adapter
->stats64_lock
);
5421 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5422 struct igb_ring
*tx_ring
= adapter
->tx_ring
[i
];
5423 if (!netif_carrier_ok(netdev
)) {
5424 /* We've lost link, so the controller stops DMA,
5425 * but we've got queued Tx work that's never going
5426 * to get done, so reset controller to flush Tx.
5427 * (Do the reset outside of interrupt context).
5429 if (igb_desc_unused(tx_ring
) + 1 < tx_ring
->count
) {
5430 adapter
->tx_timeout_count
++;
5431 schedule_work(&adapter
->reset_task
);
5432 /* return immediately since reset is imminent */
5437 /* Force detection of hung controller every watchdog period */
5438 set_bit(IGB_RING_FLAG_TX_DETECT_HANG
, &tx_ring
->flags
);
5441 /* Cause software interrupt to ensure Rx ring is cleaned */
5442 if (adapter
->flags
& IGB_FLAG_HAS_MSIX
) {
5445 for (i
= 0; i
< adapter
->num_q_vectors
; i
++)
5446 eics
|= adapter
->q_vector
[i
]->eims_value
;
5447 wr32(E1000_EICS
, eics
);
5449 wr32(E1000_ICS
, E1000_ICS_RXDMT0
);
5452 igb_spoof_check(adapter
);
5453 igb_ptp_rx_hang(adapter
);
5454 igb_ptp_tx_hang(adapter
);
5456 /* Check LVMMC register on i350/i354 only */
5457 if ((adapter
->hw
.mac
.type
== e1000_i350
) ||
5458 (adapter
->hw
.mac
.type
== e1000_i354
))
5459 igb_check_lvmmc(adapter
);
5461 /* Reset the timer */
5462 if (!test_bit(__IGB_DOWN
, &adapter
->state
)) {
5463 if (adapter
->flags
& IGB_FLAG_NEED_LINK_UPDATE
)
5464 mod_timer(&adapter
->watchdog_timer
,
5465 round_jiffies(jiffies
+ HZ
));
5467 mod_timer(&adapter
->watchdog_timer
,
5468 round_jiffies(jiffies
+ 2 * HZ
));
5472 enum latency_range
{
5476 latency_invalid
= 255
5480 * igb_update_ring_itr - update the dynamic ITR value based on packet size
5481 * @q_vector: pointer to q_vector
5483 * Stores a new ITR value based on strictly on packet size. This
5484 * algorithm is less sophisticated than that used in igb_update_itr,
5485 * due to the difficulty of synchronizing statistics across multiple
5486 * receive rings. The divisors and thresholds used by this function
5487 * were determined based on theoretical maximum wire speed and testing
5488 * data, in order to minimize response time while increasing bulk
5490 * This functionality is controlled by ethtool's coalescing settings.
5491 * NOTE: This function is called only when operating in a multiqueue
5492 * receive environment.
5494 static void igb_update_ring_itr(struct igb_q_vector
*q_vector
)
5496 int new_val
= q_vector
->itr_val
;
5497 int avg_wire_size
= 0;
5498 struct igb_adapter
*adapter
= q_vector
->adapter
;
5499 unsigned int packets
;
5501 /* For non-gigabit speeds, just fix the interrupt rate at 4000
5502 * ints/sec - ITR timer value of 120 ticks.
5504 if (adapter
->link_speed
!= SPEED_1000
) {
5505 new_val
= IGB_4K_ITR
;
5509 packets
= q_vector
->rx
.total_packets
;
5511 avg_wire_size
= q_vector
->rx
.total_bytes
/ packets
;
5513 packets
= q_vector
->tx
.total_packets
;
5515 avg_wire_size
= max_t(u32
, avg_wire_size
,
5516 q_vector
->tx
.total_bytes
/ packets
);
5518 /* if avg_wire_size isn't set no work was done */
5522 /* Add 24 bytes to size to account for CRC, preamble, and gap */
5523 avg_wire_size
+= 24;
5525 /* Don't starve jumbo frames */
5526 avg_wire_size
= min(avg_wire_size
, 3000);
5528 /* Give a little boost to mid-size frames */
5529 if ((avg_wire_size
> 300) && (avg_wire_size
< 1200))
5530 new_val
= avg_wire_size
/ 3;
5532 new_val
= avg_wire_size
/ 2;
5534 /* conservative mode (itr 3) eliminates the lowest_latency setting */
5535 if (new_val
< IGB_20K_ITR
&&
5536 ((q_vector
->rx
.ring
&& adapter
->rx_itr_setting
== 3) ||
5537 (!q_vector
->rx
.ring
&& adapter
->tx_itr_setting
== 3)))
5538 new_val
= IGB_20K_ITR
;
5541 if (new_val
!= q_vector
->itr_val
) {
5542 q_vector
->itr_val
= new_val
;
5543 q_vector
->set_itr
= 1;
5546 q_vector
->rx
.total_bytes
= 0;
5547 q_vector
->rx
.total_packets
= 0;
5548 q_vector
->tx
.total_bytes
= 0;
5549 q_vector
->tx
.total_packets
= 0;
5553 * igb_update_itr - update the dynamic ITR value based on statistics
5554 * @q_vector: pointer to q_vector
5555 * @ring_container: ring info to update the itr for
5557 * Stores a new ITR value based on packets and byte
5558 * counts during the last interrupt. The advantage of per interrupt
5559 * computation is faster updates and more accurate ITR for the current
5560 * traffic pattern. Constants in this function were computed
5561 * based on theoretical maximum wire speed and thresholds were set based
5562 * on testing data as well as attempting to minimize response time
5563 * while increasing bulk throughput.
5564 * This functionality is controlled by ethtool's coalescing settings.
5565 * NOTE: These calculations are only valid when operating in a single-
5566 * queue environment.
5568 static void igb_update_itr(struct igb_q_vector
*q_vector
,
5569 struct igb_ring_container
*ring_container
)
5571 unsigned int packets
= ring_container
->total_packets
;
5572 unsigned int bytes
= ring_container
->total_bytes
;
5573 u8 itrval
= ring_container
->itr
;
5575 /* no packets, exit with status unchanged */
5580 case lowest_latency
:
5581 /* handle TSO and jumbo frames */
5582 if (bytes
/packets
> 8000)
5583 itrval
= bulk_latency
;
5584 else if ((packets
< 5) && (bytes
> 512))
5585 itrval
= low_latency
;
5587 case low_latency
: /* 50 usec aka 20000 ints/s */
5588 if (bytes
> 10000) {
5589 /* this if handles the TSO accounting */
5590 if (bytes
/packets
> 8000)
5591 itrval
= bulk_latency
;
5592 else if ((packets
< 10) || ((bytes
/packets
) > 1200))
5593 itrval
= bulk_latency
;
5594 else if ((packets
> 35))
5595 itrval
= lowest_latency
;
5596 } else if (bytes
/packets
> 2000) {
5597 itrval
= bulk_latency
;
5598 } else if (packets
<= 2 && bytes
< 512) {
5599 itrval
= lowest_latency
;
5602 case bulk_latency
: /* 250 usec aka 4000 ints/s */
5603 if (bytes
> 25000) {
5605 itrval
= low_latency
;
5606 } else if (bytes
< 1500) {
5607 itrval
= low_latency
;
5612 /* clear work counters since we have the values we need */
5613 ring_container
->total_bytes
= 0;
5614 ring_container
->total_packets
= 0;
5616 /* write updated itr to ring container */
5617 ring_container
->itr
= itrval
;
5620 static void igb_set_itr(struct igb_q_vector
*q_vector
)
5622 struct igb_adapter
*adapter
= q_vector
->adapter
;
5623 u32 new_itr
= q_vector
->itr_val
;
5626 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
5627 if (adapter
->link_speed
!= SPEED_1000
) {
5629 new_itr
= IGB_4K_ITR
;
5633 igb_update_itr(q_vector
, &q_vector
->tx
);
5634 igb_update_itr(q_vector
, &q_vector
->rx
);
5636 current_itr
= max(q_vector
->rx
.itr
, q_vector
->tx
.itr
);
5638 /* conservative mode (itr 3) eliminates the lowest_latency setting */
5639 if (current_itr
== lowest_latency
&&
5640 ((q_vector
->rx
.ring
&& adapter
->rx_itr_setting
== 3) ||
5641 (!q_vector
->rx
.ring
&& adapter
->tx_itr_setting
== 3)))
5642 current_itr
= low_latency
;
5644 switch (current_itr
) {
5645 /* counts and packets in update_itr are dependent on these numbers */
5646 case lowest_latency
:
5647 new_itr
= IGB_70K_ITR
; /* 70,000 ints/sec */
5650 new_itr
= IGB_20K_ITR
; /* 20,000 ints/sec */
5653 new_itr
= IGB_4K_ITR
; /* 4,000 ints/sec */
5660 if (new_itr
!= q_vector
->itr_val
) {
5661 /* this attempts to bias the interrupt rate towards Bulk
5662 * by adding intermediate steps when interrupt rate is
5665 new_itr
= new_itr
> q_vector
->itr_val
?
5666 max((new_itr
* q_vector
->itr_val
) /
5667 (new_itr
+ (q_vector
->itr_val
>> 2)),
5669 /* Don't write the value here; it resets the adapter's
5670 * internal timer, and causes us to delay far longer than
5671 * we should between interrupts. Instead, we write the ITR
5672 * value at the beginning of the next interrupt so the timing
5673 * ends up being correct.
5675 q_vector
->itr_val
= new_itr
;
5676 q_vector
->set_itr
= 1;
5680 static void igb_tx_ctxtdesc(struct igb_ring
*tx_ring
,
5681 struct igb_tx_buffer
*first
,
5682 u32 vlan_macip_lens
, u32 type_tucmd
,
5685 struct e1000_adv_tx_context_desc
*context_desc
;
5686 u16 i
= tx_ring
->next_to_use
;
5687 struct timespec64 ts
;
5689 context_desc
= IGB_TX_CTXTDESC(tx_ring
, i
);
5692 tx_ring
->next_to_use
= (i
< tx_ring
->count
) ? i
: 0;
5694 /* set bits to identify this as an advanced context descriptor */
5695 type_tucmd
|= E1000_TXD_CMD_DEXT
| E1000_ADVTXD_DTYP_CTXT
;
5697 /* For 82575, context index must be unique per ring. */
5698 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX
, &tx_ring
->flags
))
5699 mss_l4len_idx
|= tx_ring
->reg_idx
<< 4;
5701 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
5702 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd
);
5703 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
5705 /* We assume there is always a valid tx time available. Invalid times
5706 * should have been handled by the upper layers.
5708 if (tx_ring
->launchtime_enable
) {
5709 ts
= ns_to_timespec64(first
->skb
->tstamp
);
5710 context_desc
->seqnum_seed
= cpu_to_le32(ts
.tv_nsec
/ 32);
5712 context_desc
->seqnum_seed
= 0;
5716 static int igb_tso(struct igb_ring
*tx_ring
,
5717 struct igb_tx_buffer
*first
,
5720 u32 vlan_macip_lens
, type_tucmd
, mss_l4len_idx
;
5721 struct sk_buff
*skb
= first
->skb
;
5731 u32 paylen
, l4_offset
;
5734 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
5737 if (!skb_is_gso(skb
))
5740 err
= skb_cow_head(skb
, 0);
5744 ip
.hdr
= skb_network_header(skb
);
5745 l4
.hdr
= skb_checksum_start(skb
);
5747 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5748 type_tucmd
= E1000_ADVTXD_TUCMD_L4T_TCP
;
5750 /* initialize outer IP header fields */
5751 if (ip
.v4
->version
== 4) {
5752 unsigned char *csum_start
= skb_checksum_start(skb
);
5753 unsigned char *trans_start
= ip
.hdr
+ (ip
.v4
->ihl
* 4);
5755 /* IP header will have to cancel out any data that
5756 * is not a part of the outer IP header
5758 ip
.v4
->check
= csum_fold(csum_partial(trans_start
,
5759 csum_start
- trans_start
,
5761 type_tucmd
|= E1000_ADVTXD_TUCMD_IPV4
;
5764 first
->tx_flags
|= IGB_TX_FLAGS_TSO
|
5768 ip
.v6
->payload_len
= 0;
5769 first
->tx_flags
|= IGB_TX_FLAGS_TSO
|
5773 /* determine offset of inner transport header */
5774 l4_offset
= l4
.hdr
- skb
->data
;
5776 /* compute length of segmentation header */
5777 *hdr_len
= (l4
.tcp
->doff
* 4) + l4_offset
;
5779 /* remove payload length from inner checksum */
5780 paylen
= skb
->len
- l4_offset
;
5781 csum_replace_by_diff(&l4
.tcp
->check
, htonl(paylen
));
5783 /* update gso size and bytecount with header size */
5784 first
->gso_segs
= skb_shinfo(skb
)->gso_segs
;
5785 first
->bytecount
+= (first
->gso_segs
- 1) * *hdr_len
;
5788 mss_l4len_idx
= (*hdr_len
- l4_offset
) << E1000_ADVTXD_L4LEN_SHIFT
;
5789 mss_l4len_idx
|= skb_shinfo(skb
)->gso_size
<< E1000_ADVTXD_MSS_SHIFT
;
5791 /* VLAN MACLEN IPLEN */
5792 vlan_macip_lens
= l4
.hdr
- ip
.hdr
;
5793 vlan_macip_lens
|= (ip
.hdr
- skb
->data
) << E1000_ADVTXD_MACLEN_SHIFT
;
5794 vlan_macip_lens
|= first
->tx_flags
& IGB_TX_FLAGS_VLAN_MASK
;
5796 igb_tx_ctxtdesc(tx_ring
, first
, vlan_macip_lens
,
5797 type_tucmd
, mss_l4len_idx
);
5802 static inline bool igb_ipv6_csum_is_sctp(struct sk_buff
*skb
)
5804 unsigned int offset
= 0;
5806 ipv6_find_hdr(skb
, &offset
, IPPROTO_SCTP
, NULL
, NULL
);
5808 return offset
== skb_checksum_start_offset(skb
);
5811 static void igb_tx_csum(struct igb_ring
*tx_ring
, struct igb_tx_buffer
*first
)
5813 struct sk_buff
*skb
= first
->skb
;
5814 u32 vlan_macip_lens
= 0;
5817 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
) {
5819 if (!(first
->tx_flags
& IGB_TX_FLAGS_VLAN
) &&
5820 !tx_ring
->launchtime_enable
)
5825 switch (skb
->csum_offset
) {
5826 case offsetof(struct tcphdr
, check
):
5827 type_tucmd
= E1000_ADVTXD_TUCMD_L4T_TCP
;
5829 case offsetof(struct udphdr
, check
):
5831 case offsetof(struct sctphdr
, checksum
):
5832 /* validate that this is actually an SCTP request */
5833 if (((first
->protocol
== htons(ETH_P_IP
)) &&
5834 (ip_hdr(skb
)->protocol
== IPPROTO_SCTP
)) ||
5835 ((first
->protocol
== htons(ETH_P_IPV6
)) &&
5836 igb_ipv6_csum_is_sctp(skb
))) {
5837 type_tucmd
= E1000_ADVTXD_TUCMD_L4T_SCTP
;
5842 skb_checksum_help(skb
);
5846 /* update TX checksum flag */
5847 first
->tx_flags
|= IGB_TX_FLAGS_CSUM
;
5848 vlan_macip_lens
= skb_checksum_start_offset(skb
) -
5849 skb_network_offset(skb
);
5851 vlan_macip_lens
|= skb_network_offset(skb
) << E1000_ADVTXD_MACLEN_SHIFT
;
5852 vlan_macip_lens
|= first
->tx_flags
& IGB_TX_FLAGS_VLAN_MASK
;
5854 igb_tx_ctxtdesc(tx_ring
, first
, vlan_macip_lens
, type_tucmd
, 0);
5857 #define IGB_SET_FLAG(_input, _flag, _result) \
5858 ((_flag <= _result) ? \
5859 ((u32)(_input & _flag) * (_result / _flag)) : \
5860 ((u32)(_input & _flag) / (_flag / _result)))
5862 static u32
igb_tx_cmd_type(struct sk_buff
*skb
, u32 tx_flags
)
5864 /* set type for advanced descriptor with frame checksum insertion */
5865 u32 cmd_type
= E1000_ADVTXD_DTYP_DATA
|
5866 E1000_ADVTXD_DCMD_DEXT
|
5867 E1000_ADVTXD_DCMD_IFCS
;
5869 /* set HW vlan bit if vlan is present */
5870 cmd_type
|= IGB_SET_FLAG(tx_flags
, IGB_TX_FLAGS_VLAN
,
5871 (E1000_ADVTXD_DCMD_VLE
));
5873 /* set segmentation bits for TSO */
5874 cmd_type
|= IGB_SET_FLAG(tx_flags
, IGB_TX_FLAGS_TSO
,
5875 (E1000_ADVTXD_DCMD_TSE
));
5877 /* set timestamp bit if present */
5878 cmd_type
|= IGB_SET_FLAG(tx_flags
, IGB_TX_FLAGS_TSTAMP
,
5879 (E1000_ADVTXD_MAC_TSTAMP
));
5881 /* insert frame checksum */
5882 cmd_type
^= IGB_SET_FLAG(skb
->no_fcs
, 1, E1000_ADVTXD_DCMD_IFCS
);
5887 static void igb_tx_olinfo_status(struct igb_ring
*tx_ring
,
5888 union e1000_adv_tx_desc
*tx_desc
,
5889 u32 tx_flags
, unsigned int paylen
)
5891 u32 olinfo_status
= paylen
<< E1000_ADVTXD_PAYLEN_SHIFT
;
5893 /* 82575 requires a unique index per ring */
5894 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX
, &tx_ring
->flags
))
5895 olinfo_status
|= tx_ring
->reg_idx
<< 4;
5897 /* insert L4 checksum */
5898 olinfo_status
|= IGB_SET_FLAG(tx_flags
,
5900 (E1000_TXD_POPTS_TXSM
<< 8));
5902 /* insert IPv4 checksum */
5903 olinfo_status
|= IGB_SET_FLAG(tx_flags
,
5905 (E1000_TXD_POPTS_IXSM
<< 8));
5907 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
5910 static int __igb_maybe_stop_tx(struct igb_ring
*tx_ring
, const u16 size
)
5912 struct net_device
*netdev
= tx_ring
->netdev
;
5914 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
5916 /* Herbert's original patch had:
5917 * smp_mb__after_netif_stop_queue();
5918 * but since that doesn't exist yet, just open code it.
5922 /* We need to check again in a case another CPU has just
5923 * made room available.
5925 if (igb_desc_unused(tx_ring
) < size
)
5929 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
5931 u64_stats_update_begin(&tx_ring
->tx_syncp2
);
5932 tx_ring
->tx_stats
.restart_queue2
++;
5933 u64_stats_update_end(&tx_ring
->tx_syncp2
);
5938 static inline int igb_maybe_stop_tx(struct igb_ring
*tx_ring
, const u16 size
)
5940 if (igb_desc_unused(tx_ring
) >= size
)
5942 return __igb_maybe_stop_tx(tx_ring
, size
);
5945 static int igb_tx_map(struct igb_ring
*tx_ring
,
5946 struct igb_tx_buffer
*first
,
5949 struct sk_buff
*skb
= first
->skb
;
5950 struct igb_tx_buffer
*tx_buffer
;
5951 union e1000_adv_tx_desc
*tx_desc
;
5952 struct skb_frag_struct
*frag
;
5954 unsigned int data_len
, size
;
5955 u32 tx_flags
= first
->tx_flags
;
5956 u32 cmd_type
= igb_tx_cmd_type(skb
, tx_flags
);
5957 u16 i
= tx_ring
->next_to_use
;
5959 tx_desc
= IGB_TX_DESC(tx_ring
, i
);
5961 igb_tx_olinfo_status(tx_ring
, tx_desc
, tx_flags
, skb
->len
- hdr_len
);
5963 size
= skb_headlen(skb
);
5964 data_len
= skb
->data_len
;
5966 dma
= dma_map_single(tx_ring
->dev
, skb
->data
, size
, DMA_TO_DEVICE
);
5970 for (frag
= &skb_shinfo(skb
)->frags
[0];; frag
++) {
5971 if (dma_mapping_error(tx_ring
->dev
, dma
))
5974 /* record length, and DMA address */
5975 dma_unmap_len_set(tx_buffer
, len
, size
);
5976 dma_unmap_addr_set(tx_buffer
, dma
, dma
);
5978 tx_desc
->read
.buffer_addr
= cpu_to_le64(dma
);
5980 while (unlikely(size
> IGB_MAX_DATA_PER_TXD
)) {
5981 tx_desc
->read
.cmd_type_len
=
5982 cpu_to_le32(cmd_type
^ IGB_MAX_DATA_PER_TXD
);
5986 if (i
== tx_ring
->count
) {
5987 tx_desc
= IGB_TX_DESC(tx_ring
, 0);
5990 tx_desc
->read
.olinfo_status
= 0;
5992 dma
+= IGB_MAX_DATA_PER_TXD
;
5993 size
-= IGB_MAX_DATA_PER_TXD
;
5995 tx_desc
->read
.buffer_addr
= cpu_to_le64(dma
);
5998 if (likely(!data_len
))
6001 tx_desc
->read
.cmd_type_len
= cpu_to_le32(cmd_type
^ size
);
6005 if (i
== tx_ring
->count
) {
6006 tx_desc
= IGB_TX_DESC(tx_ring
, 0);
6009 tx_desc
->read
.olinfo_status
= 0;
6011 size
= skb_frag_size(frag
);
6014 dma
= skb_frag_dma_map(tx_ring
->dev
, frag
, 0,
6015 size
, DMA_TO_DEVICE
);
6017 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
6020 /* write last descriptor with RS and EOP bits */
6021 cmd_type
|= size
| IGB_TXD_DCMD
;
6022 tx_desc
->read
.cmd_type_len
= cpu_to_le32(cmd_type
);
6024 netdev_tx_sent_queue(txring_txq(tx_ring
), first
->bytecount
);
6026 /* set the timestamp */
6027 first
->time_stamp
= jiffies
;
6029 /* Force memory writes to complete before letting h/w know there
6030 * are new descriptors to fetch. (Only applicable for weak-ordered
6031 * memory model archs, such as IA-64).
6033 * We also need this memory barrier to make certain all of the
6034 * status bits have been updated before next_to_watch is written.
6038 /* set next_to_watch value indicating a packet is present */
6039 first
->next_to_watch
= tx_desc
;
6042 if (i
== tx_ring
->count
)
6045 tx_ring
->next_to_use
= i
;
6047 /* Make sure there is space in the ring for the next send. */
6048 igb_maybe_stop_tx(tx_ring
, DESC_NEEDED
);
6050 if (netif_xmit_stopped(txring_txq(tx_ring
)) || !skb
->xmit_more
) {
6051 writel(i
, tx_ring
->tail
);
6053 /* we need this if more than one processor can write to our tail
6054 * at a time, it synchronizes IO on IA64/Altix systems
6061 dev_err(tx_ring
->dev
, "TX DMA map failed\n");
6062 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
6064 /* clear dma mappings for failed tx_buffer_info map */
6065 while (tx_buffer
!= first
) {
6066 if (dma_unmap_len(tx_buffer
, len
))
6067 dma_unmap_page(tx_ring
->dev
,
6068 dma_unmap_addr(tx_buffer
, dma
),
6069 dma_unmap_len(tx_buffer
, len
),
6071 dma_unmap_len_set(tx_buffer
, len
, 0);
6074 i
+= tx_ring
->count
;
6075 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
6078 if (dma_unmap_len(tx_buffer
, len
))
6079 dma_unmap_single(tx_ring
->dev
,
6080 dma_unmap_addr(tx_buffer
, dma
),
6081 dma_unmap_len(tx_buffer
, len
),
6083 dma_unmap_len_set(tx_buffer
, len
, 0);
6085 dev_kfree_skb_any(tx_buffer
->skb
);
6086 tx_buffer
->skb
= NULL
;
6088 tx_ring
->next_to_use
= i
;
6093 netdev_tx_t
igb_xmit_frame_ring(struct sk_buff
*skb
,
6094 struct igb_ring
*tx_ring
)
6096 struct igb_tx_buffer
*first
;
6100 u16 count
= TXD_USE_COUNT(skb_headlen(skb
));
6101 __be16 protocol
= vlan_get_protocol(skb
);
6104 /* need: 1 descriptor per page * PAGE_SIZE/IGB_MAX_DATA_PER_TXD,
6105 * + 1 desc for skb_headlen/IGB_MAX_DATA_PER_TXD,
6106 * + 2 desc gap to keep tail from touching head,
6107 * + 1 desc for context descriptor,
6108 * otherwise try next time
6110 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
6111 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
6113 if (igb_maybe_stop_tx(tx_ring
, count
+ 3)) {
6114 /* this is a hard error */
6115 return NETDEV_TX_BUSY
;
6118 /* record the location of the first descriptor for this packet */
6119 first
= &tx_ring
->tx_buffer_info
[tx_ring
->next_to_use
];
6121 first
->bytecount
= skb
->len
;
6122 first
->gso_segs
= 1;
6124 if (unlikely(skb_shinfo(skb
)->tx_flags
& SKBTX_HW_TSTAMP
)) {
6125 struct igb_adapter
*adapter
= netdev_priv(tx_ring
->netdev
);
6127 if (adapter
->tstamp_config
.tx_type
== HWTSTAMP_TX_ON
&&
6128 !test_and_set_bit_lock(__IGB_PTP_TX_IN_PROGRESS
,
6130 skb_shinfo(skb
)->tx_flags
|= SKBTX_IN_PROGRESS
;
6131 tx_flags
|= IGB_TX_FLAGS_TSTAMP
;
6133 adapter
->ptp_tx_skb
= skb_get(skb
);
6134 adapter
->ptp_tx_start
= jiffies
;
6135 if (adapter
->hw
.mac
.type
== e1000_82576
)
6136 schedule_work(&adapter
->ptp_tx_work
);
6138 adapter
->tx_hwtstamp_skipped
++;
6142 if (skb_vlan_tag_present(skb
)) {
6143 tx_flags
|= IGB_TX_FLAGS_VLAN
;
6144 tx_flags
|= (skb_vlan_tag_get(skb
) << IGB_TX_FLAGS_VLAN_SHIFT
);
6147 /* record initial flags and protocol */
6148 first
->tx_flags
= tx_flags
;
6149 first
->protocol
= protocol
;
6151 tso
= igb_tso(tx_ring
, first
, &hdr_len
);
6155 igb_tx_csum(tx_ring
, first
);
6157 skb_tx_timestamp(skb
);
6159 if (igb_tx_map(tx_ring
, first
, hdr_len
))
6160 goto cleanup_tx_tstamp
;
6162 return NETDEV_TX_OK
;
6165 dev_kfree_skb_any(first
->skb
);
6168 if (unlikely(tx_flags
& IGB_TX_FLAGS_TSTAMP
)) {
6169 struct igb_adapter
*adapter
= netdev_priv(tx_ring
->netdev
);
6171 dev_kfree_skb_any(adapter
->ptp_tx_skb
);
6172 adapter
->ptp_tx_skb
= NULL
;
6173 if (adapter
->hw
.mac
.type
== e1000_82576
)
6174 cancel_work_sync(&adapter
->ptp_tx_work
);
6175 clear_bit_unlock(__IGB_PTP_TX_IN_PROGRESS
, &adapter
->state
);
6178 return NETDEV_TX_OK
;
6181 static inline struct igb_ring
*igb_tx_queue_mapping(struct igb_adapter
*adapter
,
6182 struct sk_buff
*skb
)
6184 unsigned int r_idx
= skb
->queue_mapping
;
6186 if (r_idx
>= adapter
->num_tx_queues
)
6187 r_idx
= r_idx
% adapter
->num_tx_queues
;
6189 return adapter
->tx_ring
[r_idx
];
6192 static netdev_tx_t
igb_xmit_frame(struct sk_buff
*skb
,
6193 struct net_device
*netdev
)
6195 struct igb_adapter
*adapter
= netdev_priv(netdev
);
6197 /* The minimum packet size with TCTL.PSP set is 17 so pad the skb
6198 * in order to meet this minimum size requirement.
6200 if (skb_put_padto(skb
, 17))
6201 return NETDEV_TX_OK
;
6203 return igb_xmit_frame_ring(skb
, igb_tx_queue_mapping(adapter
, skb
));
6207 * igb_tx_timeout - Respond to a Tx Hang
6208 * @netdev: network interface device structure
6210 static void igb_tx_timeout(struct net_device
*netdev
)
6212 struct igb_adapter
*adapter
= netdev_priv(netdev
);
6213 struct e1000_hw
*hw
= &adapter
->hw
;
6215 /* Do the reset outside of interrupt context */
6216 adapter
->tx_timeout_count
++;
6218 if (hw
->mac
.type
>= e1000_82580
)
6219 hw
->dev_spec
._82575
.global_device_reset
= true;
6221 schedule_work(&adapter
->reset_task
);
6223 (adapter
->eims_enable_mask
& ~adapter
->eims_other
));
6226 static void igb_reset_task(struct work_struct
*work
)
6228 struct igb_adapter
*adapter
;
6229 adapter
= container_of(work
, struct igb_adapter
, reset_task
);
6232 netdev_err(adapter
->netdev
, "Reset adapter\n");
6233 igb_reinit_locked(adapter
);
6237 * igb_get_stats64 - Get System Network Statistics
6238 * @netdev: network interface device structure
6239 * @stats: rtnl_link_stats64 pointer
6241 static void igb_get_stats64(struct net_device
*netdev
,
6242 struct rtnl_link_stats64
*stats
)
6244 struct igb_adapter
*adapter
= netdev_priv(netdev
);
6246 spin_lock(&adapter
->stats64_lock
);
6247 igb_update_stats(adapter
);
6248 memcpy(stats
, &adapter
->stats64
, sizeof(*stats
));
6249 spin_unlock(&adapter
->stats64_lock
);
6253 * igb_change_mtu - Change the Maximum Transfer Unit
6254 * @netdev: network interface device structure
6255 * @new_mtu: new value for maximum frame size
6257 * Returns 0 on success, negative on failure
6259 static int igb_change_mtu(struct net_device
*netdev
, int new_mtu
)
6261 struct igb_adapter
*adapter
= netdev_priv(netdev
);
6262 struct pci_dev
*pdev
= adapter
->pdev
;
6263 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
6265 /* adjust max frame to be at least the size of a standard frame */
6266 if (max_frame
< (ETH_FRAME_LEN
+ ETH_FCS_LEN
))
6267 max_frame
= ETH_FRAME_LEN
+ ETH_FCS_LEN
;
6269 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
6270 usleep_range(1000, 2000);
6272 /* igb_down has a dependency on max_frame_size */
6273 adapter
->max_frame_size
= max_frame
;
6275 if (netif_running(netdev
))
6278 dev_info(&pdev
->dev
, "changing MTU from %d to %d\n",
6279 netdev
->mtu
, new_mtu
);
6280 netdev
->mtu
= new_mtu
;
6282 if (netif_running(netdev
))
6287 clear_bit(__IGB_RESETTING
, &adapter
->state
);
6293 * igb_update_stats - Update the board statistics counters
6294 * @adapter: board private structure
6296 void igb_update_stats(struct igb_adapter
*adapter
)
6298 struct rtnl_link_stats64
*net_stats
= &adapter
->stats64
;
6299 struct e1000_hw
*hw
= &adapter
->hw
;
6300 struct pci_dev
*pdev
= adapter
->pdev
;
6305 u64 _bytes
, _packets
;
6307 /* Prevent stats update while adapter is being reset, or if the pci
6308 * connection is down.
6310 if (adapter
->link_speed
== 0)
6312 if (pci_channel_offline(pdev
))
6319 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
6320 struct igb_ring
*ring
= adapter
->rx_ring
[i
];
6321 u32 rqdpc
= rd32(E1000_RQDPC(i
));
6322 if (hw
->mac
.type
>= e1000_i210
)
6323 wr32(E1000_RQDPC(i
), 0);
6326 ring
->rx_stats
.drops
+= rqdpc
;
6327 net_stats
->rx_fifo_errors
+= rqdpc
;
6331 start
= u64_stats_fetch_begin_irq(&ring
->rx_syncp
);
6332 _bytes
= ring
->rx_stats
.bytes
;
6333 _packets
= ring
->rx_stats
.packets
;
6334 } while (u64_stats_fetch_retry_irq(&ring
->rx_syncp
, start
));
6336 packets
+= _packets
;
6339 net_stats
->rx_bytes
= bytes
;
6340 net_stats
->rx_packets
= packets
;
6344 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
6345 struct igb_ring
*ring
= adapter
->tx_ring
[i
];
6347 start
= u64_stats_fetch_begin_irq(&ring
->tx_syncp
);
6348 _bytes
= ring
->tx_stats
.bytes
;
6349 _packets
= ring
->tx_stats
.packets
;
6350 } while (u64_stats_fetch_retry_irq(&ring
->tx_syncp
, start
));
6352 packets
+= _packets
;
6354 net_stats
->tx_bytes
= bytes
;
6355 net_stats
->tx_packets
= packets
;
6358 /* read stats registers */
6359 adapter
->stats
.crcerrs
+= rd32(E1000_CRCERRS
);
6360 adapter
->stats
.gprc
+= rd32(E1000_GPRC
);
6361 adapter
->stats
.gorc
+= rd32(E1000_GORCL
);
6362 rd32(E1000_GORCH
); /* clear GORCL */
6363 adapter
->stats
.bprc
+= rd32(E1000_BPRC
);
6364 adapter
->stats
.mprc
+= rd32(E1000_MPRC
);
6365 adapter
->stats
.roc
+= rd32(E1000_ROC
);
6367 adapter
->stats
.prc64
+= rd32(E1000_PRC64
);
6368 adapter
->stats
.prc127
+= rd32(E1000_PRC127
);
6369 adapter
->stats
.prc255
+= rd32(E1000_PRC255
);
6370 adapter
->stats
.prc511
+= rd32(E1000_PRC511
);
6371 adapter
->stats
.prc1023
+= rd32(E1000_PRC1023
);
6372 adapter
->stats
.prc1522
+= rd32(E1000_PRC1522
);
6373 adapter
->stats
.symerrs
+= rd32(E1000_SYMERRS
);
6374 adapter
->stats
.sec
+= rd32(E1000_SEC
);
6376 mpc
= rd32(E1000_MPC
);
6377 adapter
->stats
.mpc
+= mpc
;
6378 net_stats
->rx_fifo_errors
+= mpc
;
6379 adapter
->stats
.scc
+= rd32(E1000_SCC
);
6380 adapter
->stats
.ecol
+= rd32(E1000_ECOL
);
6381 adapter
->stats
.mcc
+= rd32(E1000_MCC
);
6382 adapter
->stats
.latecol
+= rd32(E1000_LATECOL
);
6383 adapter
->stats
.dc
+= rd32(E1000_DC
);
6384 adapter
->stats
.rlec
+= rd32(E1000_RLEC
);
6385 adapter
->stats
.xonrxc
+= rd32(E1000_XONRXC
);
6386 adapter
->stats
.xontxc
+= rd32(E1000_XONTXC
);
6387 adapter
->stats
.xoffrxc
+= rd32(E1000_XOFFRXC
);
6388 adapter
->stats
.xofftxc
+= rd32(E1000_XOFFTXC
);
6389 adapter
->stats
.fcruc
+= rd32(E1000_FCRUC
);
6390 adapter
->stats
.gptc
+= rd32(E1000_GPTC
);
6391 adapter
->stats
.gotc
+= rd32(E1000_GOTCL
);
6392 rd32(E1000_GOTCH
); /* clear GOTCL */
6393 adapter
->stats
.rnbc
+= rd32(E1000_RNBC
);
6394 adapter
->stats
.ruc
+= rd32(E1000_RUC
);
6395 adapter
->stats
.rfc
+= rd32(E1000_RFC
);
6396 adapter
->stats
.rjc
+= rd32(E1000_RJC
);
6397 adapter
->stats
.tor
+= rd32(E1000_TORH
);
6398 adapter
->stats
.tot
+= rd32(E1000_TOTH
);
6399 adapter
->stats
.tpr
+= rd32(E1000_TPR
);
6401 adapter
->stats
.ptc64
+= rd32(E1000_PTC64
);
6402 adapter
->stats
.ptc127
+= rd32(E1000_PTC127
);
6403 adapter
->stats
.ptc255
+= rd32(E1000_PTC255
);
6404 adapter
->stats
.ptc511
+= rd32(E1000_PTC511
);
6405 adapter
->stats
.ptc1023
+= rd32(E1000_PTC1023
);
6406 adapter
->stats
.ptc1522
+= rd32(E1000_PTC1522
);
6408 adapter
->stats
.mptc
+= rd32(E1000_MPTC
);
6409 adapter
->stats
.bptc
+= rd32(E1000_BPTC
);
6411 adapter
->stats
.tpt
+= rd32(E1000_TPT
);
6412 adapter
->stats
.colc
+= rd32(E1000_COLC
);
6414 adapter
->stats
.algnerrc
+= rd32(E1000_ALGNERRC
);
6415 /* read internal phy specific stats */
6416 reg
= rd32(E1000_CTRL_EXT
);
6417 if (!(reg
& E1000_CTRL_EXT_LINK_MODE_MASK
)) {
6418 adapter
->stats
.rxerrc
+= rd32(E1000_RXERRC
);
6420 /* this stat has invalid values on i210/i211 */
6421 if ((hw
->mac
.type
!= e1000_i210
) &&
6422 (hw
->mac
.type
!= e1000_i211
))
6423 adapter
->stats
.tncrs
+= rd32(E1000_TNCRS
);
6426 adapter
->stats
.tsctc
+= rd32(E1000_TSCTC
);
6427 adapter
->stats
.tsctfc
+= rd32(E1000_TSCTFC
);
6429 adapter
->stats
.iac
+= rd32(E1000_IAC
);
6430 adapter
->stats
.icrxoc
+= rd32(E1000_ICRXOC
);
6431 adapter
->stats
.icrxptc
+= rd32(E1000_ICRXPTC
);
6432 adapter
->stats
.icrxatc
+= rd32(E1000_ICRXATC
);
6433 adapter
->stats
.ictxptc
+= rd32(E1000_ICTXPTC
);
6434 adapter
->stats
.ictxatc
+= rd32(E1000_ICTXATC
);
6435 adapter
->stats
.ictxqec
+= rd32(E1000_ICTXQEC
);
6436 adapter
->stats
.ictxqmtc
+= rd32(E1000_ICTXQMTC
);
6437 adapter
->stats
.icrxdmtc
+= rd32(E1000_ICRXDMTC
);
6439 /* Fill out the OS statistics structure */
6440 net_stats
->multicast
= adapter
->stats
.mprc
;
6441 net_stats
->collisions
= adapter
->stats
.colc
;
6445 /* RLEC on some newer hardware can be incorrect so build
6446 * our own version based on RUC and ROC
6448 net_stats
->rx_errors
= adapter
->stats
.rxerrc
+
6449 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
6450 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
6451 adapter
->stats
.cexterr
;
6452 net_stats
->rx_length_errors
= adapter
->stats
.ruc
+
6454 net_stats
->rx_crc_errors
= adapter
->stats
.crcerrs
;
6455 net_stats
->rx_frame_errors
= adapter
->stats
.algnerrc
;
6456 net_stats
->rx_missed_errors
= adapter
->stats
.mpc
;
6459 net_stats
->tx_errors
= adapter
->stats
.ecol
+
6460 adapter
->stats
.latecol
;
6461 net_stats
->tx_aborted_errors
= adapter
->stats
.ecol
;
6462 net_stats
->tx_window_errors
= adapter
->stats
.latecol
;
6463 net_stats
->tx_carrier_errors
= adapter
->stats
.tncrs
;
6465 /* Tx Dropped needs to be maintained elsewhere */
6467 /* Management Stats */
6468 adapter
->stats
.mgptc
+= rd32(E1000_MGTPTC
);
6469 adapter
->stats
.mgprc
+= rd32(E1000_MGTPRC
);
6470 adapter
->stats
.mgpdc
+= rd32(E1000_MGTPDC
);
6473 reg
= rd32(E1000_MANC
);
6474 if (reg
& E1000_MANC_EN_BMC2OS
) {
6475 adapter
->stats
.o2bgptc
+= rd32(E1000_O2BGPTC
);
6476 adapter
->stats
.o2bspc
+= rd32(E1000_O2BSPC
);
6477 adapter
->stats
.b2ospc
+= rd32(E1000_B2OSPC
);
6478 adapter
->stats
.b2ogprc
+= rd32(E1000_B2OGPRC
);
6482 static void igb_tsync_interrupt(struct igb_adapter
*adapter
)
6484 struct e1000_hw
*hw
= &adapter
->hw
;
6485 struct ptp_clock_event event
;
6486 struct timespec64 ts
;
6487 u32 ack
= 0, tsauxc
, sec
, nsec
, tsicr
= rd32(E1000_TSICR
);
6489 if (tsicr
& TSINTR_SYS_WRAP
) {
6490 event
.type
= PTP_CLOCK_PPS
;
6491 if (adapter
->ptp_caps
.pps
)
6492 ptp_clock_event(adapter
->ptp_clock
, &event
);
6493 ack
|= TSINTR_SYS_WRAP
;
6496 if (tsicr
& E1000_TSICR_TXTS
) {
6497 /* retrieve hardware timestamp */
6498 schedule_work(&adapter
->ptp_tx_work
);
6499 ack
|= E1000_TSICR_TXTS
;
6502 if (tsicr
& TSINTR_TT0
) {
6503 spin_lock(&adapter
->tmreg_lock
);
6504 ts
= timespec64_add(adapter
->perout
[0].start
,
6505 adapter
->perout
[0].period
);
6506 /* u32 conversion of tv_sec is safe until y2106 */
6507 wr32(E1000_TRGTTIML0
, ts
.tv_nsec
);
6508 wr32(E1000_TRGTTIMH0
, (u32
)ts
.tv_sec
);
6509 tsauxc
= rd32(E1000_TSAUXC
);
6510 tsauxc
|= TSAUXC_EN_TT0
;
6511 wr32(E1000_TSAUXC
, tsauxc
);
6512 adapter
->perout
[0].start
= ts
;
6513 spin_unlock(&adapter
->tmreg_lock
);
6517 if (tsicr
& TSINTR_TT1
) {
6518 spin_lock(&adapter
->tmreg_lock
);
6519 ts
= timespec64_add(adapter
->perout
[1].start
,
6520 adapter
->perout
[1].period
);
6521 wr32(E1000_TRGTTIML1
, ts
.tv_nsec
);
6522 wr32(E1000_TRGTTIMH1
, (u32
)ts
.tv_sec
);
6523 tsauxc
= rd32(E1000_TSAUXC
);
6524 tsauxc
|= TSAUXC_EN_TT1
;
6525 wr32(E1000_TSAUXC
, tsauxc
);
6526 adapter
->perout
[1].start
= ts
;
6527 spin_unlock(&adapter
->tmreg_lock
);
6531 if (tsicr
& TSINTR_AUTT0
) {
6532 nsec
= rd32(E1000_AUXSTMPL0
);
6533 sec
= rd32(E1000_AUXSTMPH0
);
6534 event
.type
= PTP_CLOCK_EXTTS
;
6536 event
.timestamp
= sec
* 1000000000ULL + nsec
;
6537 ptp_clock_event(adapter
->ptp_clock
, &event
);
6538 ack
|= TSINTR_AUTT0
;
6541 if (tsicr
& TSINTR_AUTT1
) {
6542 nsec
= rd32(E1000_AUXSTMPL1
);
6543 sec
= rd32(E1000_AUXSTMPH1
);
6544 event
.type
= PTP_CLOCK_EXTTS
;
6546 event
.timestamp
= sec
* 1000000000ULL + nsec
;
6547 ptp_clock_event(adapter
->ptp_clock
, &event
);
6548 ack
|= TSINTR_AUTT1
;
6551 /* acknowledge the interrupts */
6552 wr32(E1000_TSICR
, ack
);
6555 static irqreturn_t
igb_msix_other(int irq
, void *data
)
6557 struct igb_adapter
*adapter
= data
;
6558 struct e1000_hw
*hw
= &adapter
->hw
;
6559 u32 icr
= rd32(E1000_ICR
);
6560 /* reading ICR causes bit 31 of EICR to be cleared */
6562 if (icr
& E1000_ICR_DRSTA
)
6563 schedule_work(&adapter
->reset_task
);
6565 if (icr
& E1000_ICR_DOUTSYNC
) {
6566 /* HW is reporting DMA is out of sync */
6567 adapter
->stats
.doosync
++;
6568 /* The DMA Out of Sync is also indication of a spoof event
6569 * in IOV mode. Check the Wrong VM Behavior register to
6570 * see if it is really a spoof event.
6572 igb_check_wvbr(adapter
);
6575 /* Check for a mailbox event */
6576 if (icr
& E1000_ICR_VMMB
)
6577 igb_msg_task(adapter
);
6579 if (icr
& E1000_ICR_LSC
) {
6580 hw
->mac
.get_link_status
= 1;
6581 /* guard against interrupt when we're going down */
6582 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
6583 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
6586 if (icr
& E1000_ICR_TS
)
6587 igb_tsync_interrupt(adapter
);
6589 wr32(E1000_EIMS
, adapter
->eims_other
);
6594 static void igb_write_itr(struct igb_q_vector
*q_vector
)
6596 struct igb_adapter
*adapter
= q_vector
->adapter
;
6597 u32 itr_val
= q_vector
->itr_val
& 0x7FFC;
6599 if (!q_vector
->set_itr
)
6605 if (adapter
->hw
.mac
.type
== e1000_82575
)
6606 itr_val
|= itr_val
<< 16;
6608 itr_val
|= E1000_EITR_CNT_IGNR
;
6610 writel(itr_val
, q_vector
->itr_register
);
6611 q_vector
->set_itr
= 0;
6614 static irqreturn_t
igb_msix_ring(int irq
, void *data
)
6616 struct igb_q_vector
*q_vector
= data
;
6618 /* Write the ITR value calculated from the previous interrupt. */
6619 igb_write_itr(q_vector
);
6621 napi_schedule(&q_vector
->napi
);
6626 #ifdef CONFIG_IGB_DCA
6627 static void igb_update_tx_dca(struct igb_adapter
*adapter
,
6628 struct igb_ring
*tx_ring
,
6631 struct e1000_hw
*hw
= &adapter
->hw
;
6632 u32 txctrl
= dca3_get_tag(tx_ring
->dev
, cpu
);
6634 if (hw
->mac
.type
!= e1000_82575
)
6635 txctrl
<<= E1000_DCA_TXCTRL_CPUID_SHIFT
;
6637 /* We can enable relaxed ordering for reads, but not writes when
6638 * DCA is enabled. This is due to a known issue in some chipsets
6639 * which will cause the DCA tag to be cleared.
6641 txctrl
|= E1000_DCA_TXCTRL_DESC_RRO_EN
|
6642 E1000_DCA_TXCTRL_DATA_RRO_EN
|
6643 E1000_DCA_TXCTRL_DESC_DCA_EN
;
6645 wr32(E1000_DCA_TXCTRL(tx_ring
->reg_idx
), txctrl
);
6648 static void igb_update_rx_dca(struct igb_adapter
*adapter
,
6649 struct igb_ring
*rx_ring
,
6652 struct e1000_hw
*hw
= &adapter
->hw
;
6653 u32 rxctrl
= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
6655 if (hw
->mac
.type
!= e1000_82575
)
6656 rxctrl
<<= E1000_DCA_RXCTRL_CPUID_SHIFT
;
6658 /* We can enable relaxed ordering for reads, but not writes when
6659 * DCA is enabled. This is due to a known issue in some chipsets
6660 * which will cause the DCA tag to be cleared.
6662 rxctrl
|= E1000_DCA_RXCTRL_DESC_RRO_EN
|
6663 E1000_DCA_RXCTRL_DESC_DCA_EN
;
6665 wr32(E1000_DCA_RXCTRL(rx_ring
->reg_idx
), rxctrl
);
6668 static void igb_update_dca(struct igb_q_vector
*q_vector
)
6670 struct igb_adapter
*adapter
= q_vector
->adapter
;
6671 int cpu
= get_cpu();
6673 if (q_vector
->cpu
== cpu
)
6676 if (q_vector
->tx
.ring
)
6677 igb_update_tx_dca(adapter
, q_vector
->tx
.ring
, cpu
);
6679 if (q_vector
->rx
.ring
)
6680 igb_update_rx_dca(adapter
, q_vector
->rx
.ring
, cpu
);
6682 q_vector
->cpu
= cpu
;
6687 static void igb_setup_dca(struct igb_adapter
*adapter
)
6689 struct e1000_hw
*hw
= &adapter
->hw
;
6692 if (!(adapter
->flags
& IGB_FLAG_DCA_ENABLED
))
6695 /* Always use CB2 mode, difference is masked in the CB driver. */
6696 wr32(E1000_DCA_CTRL
, E1000_DCA_CTRL_DCA_MODE_CB2
);
6698 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
6699 adapter
->q_vector
[i
]->cpu
= -1;
6700 igb_update_dca(adapter
->q_vector
[i
]);
6704 static int __igb_notify_dca(struct device
*dev
, void *data
)
6706 struct net_device
*netdev
= dev_get_drvdata(dev
);
6707 struct igb_adapter
*adapter
= netdev_priv(netdev
);
6708 struct pci_dev
*pdev
= adapter
->pdev
;
6709 struct e1000_hw
*hw
= &adapter
->hw
;
6710 unsigned long event
= *(unsigned long *)data
;
6713 case DCA_PROVIDER_ADD
:
6714 /* if already enabled, don't do it again */
6715 if (adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
6717 if (dca_add_requester(dev
) == 0) {
6718 adapter
->flags
|= IGB_FLAG_DCA_ENABLED
;
6719 dev_info(&pdev
->dev
, "DCA enabled\n");
6720 igb_setup_dca(adapter
);
6723 /* Fall Through since DCA is disabled. */
6724 case DCA_PROVIDER_REMOVE
:
6725 if (adapter
->flags
& IGB_FLAG_DCA_ENABLED
) {
6726 /* without this a class_device is left
6727 * hanging around in the sysfs model
6729 dca_remove_requester(dev
);
6730 dev_info(&pdev
->dev
, "DCA disabled\n");
6731 adapter
->flags
&= ~IGB_FLAG_DCA_ENABLED
;
6732 wr32(E1000_DCA_CTRL
, E1000_DCA_CTRL_DCA_MODE_DISABLE
);
6740 static int igb_notify_dca(struct notifier_block
*nb
, unsigned long event
,
6745 ret_val
= driver_for_each_device(&igb_driver
.driver
, NULL
, &event
,
6748 return ret_val
? NOTIFY_BAD
: NOTIFY_DONE
;
6750 #endif /* CONFIG_IGB_DCA */
6752 #ifdef CONFIG_PCI_IOV
6753 static int igb_vf_configure(struct igb_adapter
*adapter
, int vf
)
6755 unsigned char mac_addr
[ETH_ALEN
];
6757 eth_zero_addr(mac_addr
);
6758 igb_set_vf_mac(adapter
, vf
, mac_addr
);
6760 /* By default spoof check is enabled for all VFs */
6761 adapter
->vf_data
[vf
].spoofchk_enabled
= true;
6763 /* By default VFs are not trusted */
6764 adapter
->vf_data
[vf
].trusted
= false;
6770 static void igb_ping_all_vfs(struct igb_adapter
*adapter
)
6772 struct e1000_hw
*hw
= &adapter
->hw
;
6776 for (i
= 0 ; i
< adapter
->vfs_allocated_count
; i
++) {
6777 ping
= E1000_PF_CONTROL_MSG
;
6778 if (adapter
->vf_data
[i
].flags
& IGB_VF_FLAG_CTS
)
6779 ping
|= E1000_VT_MSGTYPE_CTS
;
6780 igb_write_mbx(hw
, &ping
, 1, i
);
6784 static int igb_set_vf_promisc(struct igb_adapter
*adapter
, u32
*msgbuf
, u32 vf
)
6786 struct e1000_hw
*hw
= &adapter
->hw
;
6787 u32 vmolr
= rd32(E1000_VMOLR(vf
));
6788 struct vf_data_storage
*vf_data
= &adapter
->vf_data
[vf
];
6790 vf_data
->flags
&= ~(IGB_VF_FLAG_UNI_PROMISC
|
6791 IGB_VF_FLAG_MULTI_PROMISC
);
6792 vmolr
&= ~(E1000_VMOLR_ROPE
| E1000_VMOLR_ROMPE
| E1000_VMOLR_MPME
);
6794 if (*msgbuf
& E1000_VF_SET_PROMISC_MULTICAST
) {
6795 vmolr
|= E1000_VMOLR_MPME
;
6796 vf_data
->flags
|= IGB_VF_FLAG_MULTI_PROMISC
;
6797 *msgbuf
&= ~E1000_VF_SET_PROMISC_MULTICAST
;
6799 /* if we have hashes and we are clearing a multicast promisc
6800 * flag we need to write the hashes to the MTA as this step
6801 * was previously skipped
6803 if (vf_data
->num_vf_mc_hashes
> 30) {
6804 vmolr
|= E1000_VMOLR_MPME
;
6805 } else if (vf_data
->num_vf_mc_hashes
) {
6808 vmolr
|= E1000_VMOLR_ROMPE
;
6809 for (j
= 0; j
< vf_data
->num_vf_mc_hashes
; j
++)
6810 igb_mta_set(hw
, vf_data
->vf_mc_hashes
[j
]);
6814 wr32(E1000_VMOLR(vf
), vmolr
);
6816 /* there are flags left unprocessed, likely not supported */
6817 if (*msgbuf
& E1000_VT_MSGINFO_MASK
)
6823 static int igb_set_vf_multicasts(struct igb_adapter
*adapter
,
6824 u32
*msgbuf
, u32 vf
)
6826 int n
= (msgbuf
[0] & E1000_VT_MSGINFO_MASK
) >> E1000_VT_MSGINFO_SHIFT
;
6827 u16
*hash_list
= (u16
*)&msgbuf
[1];
6828 struct vf_data_storage
*vf_data
= &adapter
->vf_data
[vf
];
6831 /* salt away the number of multicast addresses assigned
6832 * to this VF for later use to restore when the PF multi cast
6835 vf_data
->num_vf_mc_hashes
= n
;
6837 /* only up to 30 hash values supported */
6841 /* store the hashes for later use */
6842 for (i
= 0; i
< n
; i
++)
6843 vf_data
->vf_mc_hashes
[i
] = hash_list
[i
];
6845 /* Flush and reset the mta with the new values */
6846 igb_set_rx_mode(adapter
->netdev
);
6851 static void igb_restore_vf_multicasts(struct igb_adapter
*adapter
)
6853 struct e1000_hw
*hw
= &adapter
->hw
;
6854 struct vf_data_storage
*vf_data
;
6857 for (i
= 0; i
< adapter
->vfs_allocated_count
; i
++) {
6858 u32 vmolr
= rd32(E1000_VMOLR(i
));
6860 vmolr
&= ~(E1000_VMOLR_ROMPE
| E1000_VMOLR_MPME
);
6862 vf_data
= &adapter
->vf_data
[i
];
6864 if ((vf_data
->num_vf_mc_hashes
> 30) ||
6865 (vf_data
->flags
& IGB_VF_FLAG_MULTI_PROMISC
)) {
6866 vmolr
|= E1000_VMOLR_MPME
;
6867 } else if (vf_data
->num_vf_mc_hashes
) {
6868 vmolr
|= E1000_VMOLR_ROMPE
;
6869 for (j
= 0; j
< vf_data
->num_vf_mc_hashes
; j
++)
6870 igb_mta_set(hw
, vf_data
->vf_mc_hashes
[j
]);
6872 wr32(E1000_VMOLR(i
), vmolr
);
6876 static void igb_clear_vf_vfta(struct igb_adapter
*adapter
, u32 vf
)
6878 struct e1000_hw
*hw
= &adapter
->hw
;
6879 u32 pool_mask
, vlvf_mask
, i
;
6881 /* create mask for VF and other pools */
6882 pool_mask
= E1000_VLVF_POOLSEL_MASK
;
6883 vlvf_mask
= BIT(E1000_VLVF_POOLSEL_SHIFT
+ vf
);
6885 /* drop PF from pool bits */
6886 pool_mask
&= ~BIT(E1000_VLVF_POOLSEL_SHIFT
+
6887 adapter
->vfs_allocated_count
);
6889 /* Find the vlan filter for this id */
6890 for (i
= E1000_VLVF_ARRAY_SIZE
; i
--;) {
6891 u32 vlvf
= rd32(E1000_VLVF(i
));
6892 u32 vfta_mask
, vid
, vfta
;
6894 /* remove the vf from the pool */
6895 if (!(vlvf
& vlvf_mask
))
6898 /* clear out bit from VLVF */
6901 /* if other pools are present, just remove ourselves */
6902 if (vlvf
& pool_mask
)
6905 /* if PF is present, leave VFTA */
6906 if (vlvf
& E1000_VLVF_POOLSEL_MASK
)
6909 vid
= vlvf
& E1000_VLVF_VLANID_MASK
;
6910 vfta_mask
= BIT(vid
% 32);
6912 /* clear bit from VFTA */
6913 vfta
= adapter
->shadow_vfta
[vid
/ 32];
6914 if (vfta
& vfta_mask
)
6915 hw
->mac
.ops
.write_vfta(hw
, vid
/ 32, vfta
^ vfta_mask
);
6917 /* clear pool selection enable */
6918 if (adapter
->flags
& IGB_FLAG_VLAN_PROMISC
)
6919 vlvf
&= E1000_VLVF_POOLSEL_MASK
;
6923 /* clear pool bits */
6924 wr32(E1000_VLVF(i
), vlvf
);
6928 static int igb_find_vlvf_entry(struct e1000_hw
*hw
, u32 vlan
)
6933 /* short cut the special case */
6937 /* Search for the VLAN id in the VLVF entries */
6938 for (idx
= E1000_VLVF_ARRAY_SIZE
; --idx
;) {
6939 vlvf
= rd32(E1000_VLVF(idx
));
6940 if ((vlvf
& VLAN_VID_MASK
) == vlan
)
6947 static void igb_update_pf_vlvf(struct igb_adapter
*adapter
, u32 vid
)
6949 struct e1000_hw
*hw
= &adapter
->hw
;
6953 idx
= igb_find_vlvf_entry(hw
, vid
);
6957 /* See if any other pools are set for this VLAN filter
6958 * entry other than the PF.
6960 pf_id
= adapter
->vfs_allocated_count
+ E1000_VLVF_POOLSEL_SHIFT
;
6961 bits
= ~BIT(pf_id
) & E1000_VLVF_POOLSEL_MASK
;
6962 bits
&= rd32(E1000_VLVF(idx
));
6964 /* Disable the filter so this falls into the default pool. */
6966 if (adapter
->flags
& IGB_FLAG_VLAN_PROMISC
)
6967 wr32(E1000_VLVF(idx
), BIT(pf_id
));
6969 wr32(E1000_VLVF(idx
), 0);
6973 static s32
igb_set_vf_vlan(struct igb_adapter
*adapter
, u32 vid
,
6976 int pf_id
= adapter
->vfs_allocated_count
;
6977 struct e1000_hw
*hw
= &adapter
->hw
;
6980 /* If VLAN overlaps with one the PF is currently monitoring make
6981 * sure that we are able to allocate a VLVF entry. This may be
6982 * redundant but it guarantees PF will maintain visibility to
6985 if (add
&& test_bit(vid
, adapter
->active_vlans
)) {
6986 err
= igb_vfta_set(hw
, vid
, pf_id
, true, false);
6991 err
= igb_vfta_set(hw
, vid
, vf
, add
, false);
6996 /* If we failed to add the VF VLAN or we are removing the VF VLAN
6997 * we may need to drop the PF pool bit in order to allow us to free
6998 * up the VLVF resources.
7000 if (test_bit(vid
, adapter
->active_vlans
) ||
7001 (adapter
->flags
& IGB_FLAG_VLAN_PROMISC
))
7002 igb_update_pf_vlvf(adapter
, vid
);
7007 static void igb_set_vmvir(struct igb_adapter
*adapter
, u32 vid
, u32 vf
)
7009 struct e1000_hw
*hw
= &adapter
->hw
;
7012 wr32(E1000_VMVIR(vf
), (vid
| E1000_VMVIR_VLANA_DEFAULT
));
7014 wr32(E1000_VMVIR(vf
), 0);
7017 static int igb_enable_port_vlan(struct igb_adapter
*adapter
, int vf
,
7022 err
= igb_set_vf_vlan(adapter
, vlan
, true, vf
);
7026 igb_set_vmvir(adapter
, vlan
| (qos
<< VLAN_PRIO_SHIFT
), vf
);
7027 igb_set_vmolr(adapter
, vf
, !vlan
);
7029 /* revoke access to previous VLAN */
7030 if (vlan
!= adapter
->vf_data
[vf
].pf_vlan
)
7031 igb_set_vf_vlan(adapter
, adapter
->vf_data
[vf
].pf_vlan
,
7034 adapter
->vf_data
[vf
].pf_vlan
= vlan
;
7035 adapter
->vf_data
[vf
].pf_qos
= qos
;
7036 igb_set_vf_vlan_strip(adapter
, vf
, true);
7037 dev_info(&adapter
->pdev
->dev
,
7038 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan
, qos
, vf
);
7039 if (test_bit(__IGB_DOWN
, &adapter
->state
)) {
7040 dev_warn(&adapter
->pdev
->dev
,
7041 "The VF VLAN has been set, but the PF device is not up.\n");
7042 dev_warn(&adapter
->pdev
->dev
,
7043 "Bring the PF device up before attempting to use the VF device.\n");
7049 static int igb_disable_port_vlan(struct igb_adapter
*adapter
, int vf
)
7051 /* Restore tagless access via VLAN 0 */
7052 igb_set_vf_vlan(adapter
, 0, true, vf
);
7054 igb_set_vmvir(adapter
, 0, vf
);
7055 igb_set_vmolr(adapter
, vf
, true);
7057 /* Remove any PF assigned VLAN */
7058 if (adapter
->vf_data
[vf
].pf_vlan
)
7059 igb_set_vf_vlan(adapter
, adapter
->vf_data
[vf
].pf_vlan
,
7062 adapter
->vf_data
[vf
].pf_vlan
= 0;
7063 adapter
->vf_data
[vf
].pf_qos
= 0;
7064 igb_set_vf_vlan_strip(adapter
, vf
, false);
7069 static int igb_ndo_set_vf_vlan(struct net_device
*netdev
, int vf
,
7070 u16 vlan
, u8 qos
, __be16 vlan_proto
)
7072 struct igb_adapter
*adapter
= netdev_priv(netdev
);
7074 if ((vf
>= adapter
->vfs_allocated_count
) || (vlan
> 4095) || (qos
> 7))
7077 if (vlan_proto
!= htons(ETH_P_8021Q
))
7078 return -EPROTONOSUPPORT
;
7080 return (vlan
|| qos
) ? igb_enable_port_vlan(adapter
, vf
, vlan
, qos
) :
7081 igb_disable_port_vlan(adapter
, vf
);
7084 static int igb_set_vf_vlan_msg(struct igb_adapter
*adapter
, u32
*msgbuf
, u32 vf
)
7086 int add
= (msgbuf
[0] & E1000_VT_MSGINFO_MASK
) >> E1000_VT_MSGINFO_SHIFT
;
7087 int vid
= (msgbuf
[1] & E1000_VLVF_VLANID_MASK
);
7090 if (adapter
->vf_data
[vf
].pf_vlan
)
7093 /* VLAN 0 is a special case, don't allow it to be removed */
7097 ret
= igb_set_vf_vlan(adapter
, vid
, !!add
, vf
);
7099 igb_set_vf_vlan_strip(adapter
, vf
, !!vid
);
7103 static inline void igb_vf_reset(struct igb_adapter
*adapter
, u32 vf
)
7105 struct vf_data_storage
*vf_data
= &adapter
->vf_data
[vf
];
7107 /* clear flags - except flag that indicates PF has set the MAC */
7108 vf_data
->flags
&= IGB_VF_FLAG_PF_SET_MAC
;
7109 vf_data
->last_nack
= jiffies
;
7111 /* reset vlans for device */
7112 igb_clear_vf_vfta(adapter
, vf
);
7113 igb_set_vf_vlan(adapter
, vf_data
->pf_vlan
, true, vf
);
7114 igb_set_vmvir(adapter
, vf_data
->pf_vlan
|
7115 (vf_data
->pf_qos
<< VLAN_PRIO_SHIFT
), vf
);
7116 igb_set_vmolr(adapter
, vf
, !vf_data
->pf_vlan
);
7117 igb_set_vf_vlan_strip(adapter
, vf
, !!(vf_data
->pf_vlan
));
7119 /* reset multicast table array for vf */
7120 adapter
->vf_data
[vf
].num_vf_mc_hashes
= 0;
7122 /* Flush and reset the mta with the new values */
7123 igb_set_rx_mode(adapter
->netdev
);
7126 static void igb_vf_reset_event(struct igb_adapter
*adapter
, u32 vf
)
7128 unsigned char *vf_mac
= adapter
->vf_data
[vf
].vf_mac_addresses
;
7130 /* clear mac address as we were hotplug removed/added */
7131 if (!(adapter
->vf_data
[vf
].flags
& IGB_VF_FLAG_PF_SET_MAC
))
7132 eth_zero_addr(vf_mac
);
7134 /* process remaining reset events */
7135 igb_vf_reset(adapter
, vf
);
7138 static void igb_vf_reset_msg(struct igb_adapter
*adapter
, u32 vf
)
7140 struct e1000_hw
*hw
= &adapter
->hw
;
7141 unsigned char *vf_mac
= adapter
->vf_data
[vf
].vf_mac_addresses
;
7143 u8
*addr
= (u8
*)(&msgbuf
[1]);
7145 /* process all the same items cleared in a function level reset */
7146 igb_vf_reset(adapter
, vf
);
7148 /* set vf mac address */
7149 igb_set_vf_mac(adapter
, vf
, vf_mac
);
7151 /* enable transmit and receive for vf */
7152 reg
= rd32(E1000_VFTE
);
7153 wr32(E1000_VFTE
, reg
| BIT(vf
));
7154 reg
= rd32(E1000_VFRE
);
7155 wr32(E1000_VFRE
, reg
| BIT(vf
));
7157 adapter
->vf_data
[vf
].flags
|= IGB_VF_FLAG_CTS
;
7159 /* reply to reset with ack and vf mac address */
7160 if (!is_zero_ether_addr(vf_mac
)) {
7161 msgbuf
[0] = E1000_VF_RESET
| E1000_VT_MSGTYPE_ACK
;
7162 memcpy(addr
, vf_mac
, ETH_ALEN
);
7164 msgbuf
[0] = E1000_VF_RESET
| E1000_VT_MSGTYPE_NACK
;
7166 igb_write_mbx(hw
, msgbuf
, 3, vf
);
7169 static void igb_flush_mac_table(struct igb_adapter
*adapter
)
7171 struct e1000_hw
*hw
= &adapter
->hw
;
7174 for (i
= 0; i
< hw
->mac
.rar_entry_count
; i
++) {
7175 adapter
->mac_table
[i
].state
&= ~IGB_MAC_STATE_IN_USE
;
7176 memset(adapter
->mac_table
[i
].addr
, 0, ETH_ALEN
);
7177 adapter
->mac_table
[i
].queue
= 0;
7178 igb_rar_set_index(adapter
, i
);
7182 static int igb_available_rars(struct igb_adapter
*adapter
, u8 queue
)
7184 struct e1000_hw
*hw
= &adapter
->hw
;
7185 /* do not count rar entries reserved for VFs MAC addresses */
7186 int rar_entries
= hw
->mac
.rar_entry_count
-
7187 adapter
->vfs_allocated_count
;
7190 for (i
= 0; i
< rar_entries
; i
++) {
7191 /* do not count default entries */
7192 if (adapter
->mac_table
[i
].state
& IGB_MAC_STATE_DEFAULT
)
7195 /* do not count "in use" entries for different queues */
7196 if ((adapter
->mac_table
[i
].state
& IGB_MAC_STATE_IN_USE
) &&
7197 (adapter
->mac_table
[i
].queue
!= queue
))
7206 /* Set default MAC address for the PF in the first RAR entry */
7207 static void igb_set_default_mac_filter(struct igb_adapter
*adapter
)
7209 struct igb_mac_addr
*mac_table
= &adapter
->mac_table
[0];
7211 ether_addr_copy(mac_table
->addr
, adapter
->hw
.mac
.addr
);
7212 mac_table
->queue
= adapter
->vfs_allocated_count
;
7213 mac_table
->state
= IGB_MAC_STATE_DEFAULT
| IGB_MAC_STATE_IN_USE
;
7215 igb_rar_set_index(adapter
, 0);
7218 /* If the filter to be added and an already existing filter express
7219 * the same address and address type, it should be possible to only
7220 * override the other configurations, for example the queue to steer
7223 static bool igb_mac_entry_can_be_used(const struct igb_mac_addr
*entry
,
7224 const u8
*addr
, const u8 flags
)
7226 if (!(entry
->state
& IGB_MAC_STATE_IN_USE
))
7229 if ((entry
->state
& IGB_MAC_STATE_SRC_ADDR
) !=
7230 (flags
& IGB_MAC_STATE_SRC_ADDR
))
7233 if (!ether_addr_equal(addr
, entry
->addr
))
7239 /* Add a MAC filter for 'addr' directing matching traffic to 'queue',
7240 * 'flags' is used to indicate what kind of match is made, match is by
7241 * default for the destination address, if matching by source address
7242 * is desired the flag IGB_MAC_STATE_SRC_ADDR can be used.
7244 static int igb_add_mac_filter_flags(struct igb_adapter
*adapter
,
7245 const u8
*addr
, const u8 queue
,
7248 struct e1000_hw
*hw
= &adapter
->hw
;
7249 int rar_entries
= hw
->mac
.rar_entry_count
-
7250 adapter
->vfs_allocated_count
;
7253 if (is_zero_ether_addr(addr
))
7256 /* Search for the first empty entry in the MAC table.
7257 * Do not touch entries at the end of the table reserved for the VF MAC
7260 for (i
= 0; i
< rar_entries
; i
++) {
7261 if (!igb_mac_entry_can_be_used(&adapter
->mac_table
[i
],
7265 ether_addr_copy(adapter
->mac_table
[i
].addr
, addr
);
7266 adapter
->mac_table
[i
].queue
= queue
;
7267 adapter
->mac_table
[i
].state
|= IGB_MAC_STATE_IN_USE
| flags
;
7269 igb_rar_set_index(adapter
, i
);
7276 static int igb_add_mac_filter(struct igb_adapter
*adapter
, const u8
*addr
,
7279 return igb_add_mac_filter_flags(adapter
, addr
, queue
, 0);
7282 /* Remove a MAC filter for 'addr' directing matching traffic to
7283 * 'queue', 'flags' is used to indicate what kind of match need to be
7284 * removed, match is by default for the destination address, if
7285 * matching by source address is to be removed the flag
7286 * IGB_MAC_STATE_SRC_ADDR can be used.
7288 static int igb_del_mac_filter_flags(struct igb_adapter
*adapter
,
7289 const u8
*addr
, const u8 queue
,
7292 struct e1000_hw
*hw
= &adapter
->hw
;
7293 int rar_entries
= hw
->mac
.rar_entry_count
-
7294 adapter
->vfs_allocated_count
;
7297 if (is_zero_ether_addr(addr
))
7300 /* Search for matching entry in the MAC table based on given address
7301 * and queue. Do not touch entries at the end of the table reserved
7302 * for the VF MAC addresses.
7304 for (i
= 0; i
< rar_entries
; i
++) {
7305 if (!(adapter
->mac_table
[i
].state
& IGB_MAC_STATE_IN_USE
))
7307 if ((adapter
->mac_table
[i
].state
& flags
) != flags
)
7309 if (adapter
->mac_table
[i
].queue
!= queue
)
7311 if (!ether_addr_equal(adapter
->mac_table
[i
].addr
, addr
))
7314 /* When a filter for the default address is "deleted",
7315 * we return it to its initial configuration
7317 if (adapter
->mac_table
[i
].state
& IGB_MAC_STATE_DEFAULT
) {
7318 adapter
->mac_table
[i
].state
=
7319 IGB_MAC_STATE_DEFAULT
| IGB_MAC_STATE_IN_USE
;
7320 adapter
->mac_table
[i
].queue
=
7321 adapter
->vfs_allocated_count
;
7323 adapter
->mac_table
[i
].state
= 0;
7324 adapter
->mac_table
[i
].queue
= 0;
7325 memset(adapter
->mac_table
[i
].addr
, 0, ETH_ALEN
);
7328 igb_rar_set_index(adapter
, i
);
7335 static int igb_del_mac_filter(struct igb_adapter
*adapter
, const u8
*addr
,
7338 return igb_del_mac_filter_flags(adapter
, addr
, queue
, 0);
7341 int igb_add_mac_steering_filter(struct igb_adapter
*adapter
,
7342 const u8
*addr
, u8 queue
, u8 flags
)
7344 struct e1000_hw
*hw
= &adapter
->hw
;
7346 /* In theory, this should be supported on 82575 as well, but
7347 * that part wasn't easily accessible during development.
7349 if (hw
->mac
.type
!= e1000_i210
)
7352 return igb_add_mac_filter_flags(adapter
, addr
, queue
,
7353 IGB_MAC_STATE_QUEUE_STEERING
| flags
);
7356 int igb_del_mac_steering_filter(struct igb_adapter
*adapter
,
7357 const u8
*addr
, u8 queue
, u8 flags
)
7359 return igb_del_mac_filter_flags(adapter
, addr
, queue
,
7360 IGB_MAC_STATE_QUEUE_STEERING
| flags
);
7363 static int igb_uc_sync(struct net_device
*netdev
, const unsigned char *addr
)
7365 struct igb_adapter
*adapter
= netdev_priv(netdev
);
7368 ret
= igb_add_mac_filter(adapter
, addr
, adapter
->vfs_allocated_count
);
7370 return min_t(int, ret
, 0);
7373 static int igb_uc_unsync(struct net_device
*netdev
, const unsigned char *addr
)
7375 struct igb_adapter
*adapter
= netdev_priv(netdev
);
7377 igb_del_mac_filter(adapter
, addr
, adapter
->vfs_allocated_count
);
7382 static int igb_set_vf_mac_filter(struct igb_adapter
*adapter
, const int vf
,
7383 const u32 info
, const u8
*addr
)
7385 struct pci_dev
*pdev
= adapter
->pdev
;
7386 struct vf_data_storage
*vf_data
= &adapter
->vf_data
[vf
];
7387 struct list_head
*pos
;
7388 struct vf_mac_filter
*entry
= NULL
;
7392 case E1000_VF_MAC_FILTER_CLR
:
7393 /* remove all unicast MAC filters related to the current VF */
7394 list_for_each(pos
, &adapter
->vf_macs
.l
) {
7395 entry
= list_entry(pos
, struct vf_mac_filter
, l
);
7396 if (entry
->vf
== vf
) {
7399 igb_del_mac_filter(adapter
, entry
->vf_mac
, vf
);
7403 case E1000_VF_MAC_FILTER_ADD
:
7404 if ((vf_data
->flags
& IGB_VF_FLAG_PF_SET_MAC
) &&
7405 !vf_data
->trusted
) {
7406 dev_warn(&pdev
->dev
,
7407 "VF %d requested MAC filter but is administratively denied\n",
7411 if (!is_valid_ether_addr(addr
)) {
7412 dev_warn(&pdev
->dev
,
7413 "VF %d attempted to set invalid MAC filter\n",
7418 /* try to find empty slot in the list */
7419 list_for_each(pos
, &adapter
->vf_macs
.l
) {
7420 entry
= list_entry(pos
, struct vf_mac_filter
, l
);
7425 if (entry
&& entry
->free
) {
7426 entry
->free
= false;
7428 ether_addr_copy(entry
->vf_mac
, addr
);
7430 ret
= igb_add_mac_filter(adapter
, addr
, vf
);
7431 ret
= min_t(int, ret
, 0);
7437 dev_warn(&pdev
->dev
,
7438 "VF %d has requested MAC filter but there is no space for it\n",
7449 static int igb_set_vf_mac_addr(struct igb_adapter
*adapter
, u32
*msg
, int vf
)
7451 struct pci_dev
*pdev
= adapter
->pdev
;
7452 struct vf_data_storage
*vf_data
= &adapter
->vf_data
[vf
];
7453 u32 info
= msg
[0] & E1000_VT_MSGINFO_MASK
;
7455 /* The VF MAC Address is stored in a packed array of bytes
7456 * starting at the second 32 bit word of the msg array
7458 unsigned char *addr
= (unsigned char *)&msg
[1];
7462 if ((vf_data
->flags
& IGB_VF_FLAG_PF_SET_MAC
) &&
7463 !vf_data
->trusted
) {
7464 dev_warn(&pdev
->dev
,
7465 "VF %d attempted to override administratively set MAC address\nReload the VF driver to resume operations\n",
7470 if (!is_valid_ether_addr(addr
)) {
7471 dev_warn(&pdev
->dev
,
7472 "VF %d attempted to set invalid MAC\n",
7477 ret
= igb_set_vf_mac(adapter
, vf
, addr
);
7479 ret
= igb_set_vf_mac_filter(adapter
, vf
, info
, addr
);
7485 static void igb_rcv_ack_from_vf(struct igb_adapter
*adapter
, u32 vf
)
7487 struct e1000_hw
*hw
= &adapter
->hw
;
7488 struct vf_data_storage
*vf_data
= &adapter
->vf_data
[vf
];
7489 u32 msg
= E1000_VT_MSGTYPE_NACK
;
7491 /* if device isn't clear to send it shouldn't be reading either */
7492 if (!(vf_data
->flags
& IGB_VF_FLAG_CTS
) &&
7493 time_after(jiffies
, vf_data
->last_nack
+ (2 * HZ
))) {
7494 igb_write_mbx(hw
, &msg
, 1, vf
);
7495 vf_data
->last_nack
= jiffies
;
7499 static void igb_rcv_msg_from_vf(struct igb_adapter
*adapter
, u32 vf
)
7501 struct pci_dev
*pdev
= adapter
->pdev
;
7502 u32 msgbuf
[E1000_VFMAILBOX_SIZE
];
7503 struct e1000_hw
*hw
= &adapter
->hw
;
7504 struct vf_data_storage
*vf_data
= &adapter
->vf_data
[vf
];
7507 retval
= igb_read_mbx(hw
, msgbuf
, E1000_VFMAILBOX_SIZE
, vf
, false);
7510 /* if receive failed revoke VF CTS stats and restart init */
7511 dev_err(&pdev
->dev
, "Error receiving message from VF\n");
7512 vf_data
->flags
&= ~IGB_VF_FLAG_CTS
;
7513 if (!time_after(jiffies
, vf_data
->last_nack
+ (2 * HZ
)))
7518 /* this is a message we already processed, do nothing */
7519 if (msgbuf
[0] & (E1000_VT_MSGTYPE_ACK
| E1000_VT_MSGTYPE_NACK
))
7522 /* until the vf completes a reset it should not be
7523 * allowed to start any configuration.
7525 if (msgbuf
[0] == E1000_VF_RESET
) {
7526 /* unlocks mailbox */
7527 igb_vf_reset_msg(adapter
, vf
);
7531 if (!(vf_data
->flags
& IGB_VF_FLAG_CTS
)) {
7532 if (!time_after(jiffies
, vf_data
->last_nack
+ (2 * HZ
)))
7538 switch ((msgbuf
[0] & 0xFFFF)) {
7539 case E1000_VF_SET_MAC_ADDR
:
7540 retval
= igb_set_vf_mac_addr(adapter
, msgbuf
, vf
);
7542 case E1000_VF_SET_PROMISC
:
7543 retval
= igb_set_vf_promisc(adapter
, msgbuf
, vf
);
7545 case E1000_VF_SET_MULTICAST
:
7546 retval
= igb_set_vf_multicasts(adapter
, msgbuf
, vf
);
7548 case E1000_VF_SET_LPE
:
7549 retval
= igb_set_vf_rlpml(adapter
, msgbuf
[1], vf
);
7551 case E1000_VF_SET_VLAN
:
7553 if (vf_data
->pf_vlan
)
7554 dev_warn(&pdev
->dev
,
7555 "VF %d attempted to override administratively set VLAN tag\nReload the VF driver to resume operations\n",
7558 retval
= igb_set_vf_vlan_msg(adapter
, msgbuf
, vf
);
7561 dev_err(&pdev
->dev
, "Unhandled Msg %08x\n", msgbuf
[0]);
7566 msgbuf
[0] |= E1000_VT_MSGTYPE_CTS
;
7568 /* notify the VF of the results of what it sent us */
7570 msgbuf
[0] |= E1000_VT_MSGTYPE_NACK
;
7572 msgbuf
[0] |= E1000_VT_MSGTYPE_ACK
;
7574 /* unlocks mailbox */
7575 igb_write_mbx(hw
, msgbuf
, 1, vf
);
7579 igb_unlock_mbx(hw
, vf
);
7582 static void igb_msg_task(struct igb_adapter
*adapter
)
7584 struct e1000_hw
*hw
= &adapter
->hw
;
7587 for (vf
= 0; vf
< adapter
->vfs_allocated_count
; vf
++) {
7588 /* process any reset requests */
7589 if (!igb_check_for_rst(hw
, vf
))
7590 igb_vf_reset_event(adapter
, vf
);
7592 /* process any messages pending */
7593 if (!igb_check_for_msg(hw
, vf
))
7594 igb_rcv_msg_from_vf(adapter
, vf
);
7596 /* process any acks */
7597 if (!igb_check_for_ack(hw
, vf
))
7598 igb_rcv_ack_from_vf(adapter
, vf
);
7603 * igb_set_uta - Set unicast filter table address
7604 * @adapter: board private structure
7605 * @set: boolean indicating if we are setting or clearing bits
7607 * The unicast table address is a register array of 32-bit registers.
7608 * The table is meant to be used in a way similar to how the MTA is used
7609 * however due to certain limitations in the hardware it is necessary to
7610 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
7611 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
7613 static void igb_set_uta(struct igb_adapter
*adapter
, bool set
)
7615 struct e1000_hw
*hw
= &adapter
->hw
;
7616 u32 uta
= set
? ~0 : 0;
7619 /* we only need to do this if VMDq is enabled */
7620 if (!adapter
->vfs_allocated_count
)
7623 for (i
= hw
->mac
.uta_reg_count
; i
--;)
7624 array_wr32(E1000_UTA
, i
, uta
);
7628 * igb_intr_msi - Interrupt Handler
7629 * @irq: interrupt number
7630 * @data: pointer to a network interface device structure
7632 static irqreturn_t
igb_intr_msi(int irq
, void *data
)
7634 struct igb_adapter
*adapter
= data
;
7635 struct igb_q_vector
*q_vector
= adapter
->q_vector
[0];
7636 struct e1000_hw
*hw
= &adapter
->hw
;
7637 /* read ICR disables interrupts using IAM */
7638 u32 icr
= rd32(E1000_ICR
);
7640 igb_write_itr(q_vector
);
7642 if (icr
& E1000_ICR_DRSTA
)
7643 schedule_work(&adapter
->reset_task
);
7645 if (icr
& E1000_ICR_DOUTSYNC
) {
7646 /* HW is reporting DMA is out of sync */
7647 adapter
->stats
.doosync
++;
7650 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
7651 hw
->mac
.get_link_status
= 1;
7652 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
7653 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
7656 if (icr
& E1000_ICR_TS
)
7657 igb_tsync_interrupt(adapter
);
7659 napi_schedule(&q_vector
->napi
);
7665 * igb_intr - Legacy Interrupt Handler
7666 * @irq: interrupt number
7667 * @data: pointer to a network interface device structure
7669 static irqreturn_t
igb_intr(int irq
, void *data
)
7671 struct igb_adapter
*adapter
= data
;
7672 struct igb_q_vector
*q_vector
= adapter
->q_vector
[0];
7673 struct e1000_hw
*hw
= &adapter
->hw
;
7674 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
7675 * need for the IMC write
7677 u32 icr
= rd32(E1000_ICR
);
7679 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
7680 * not set, then the adapter didn't send an interrupt
7682 if (!(icr
& E1000_ICR_INT_ASSERTED
))
7685 igb_write_itr(q_vector
);
7687 if (icr
& E1000_ICR_DRSTA
)
7688 schedule_work(&adapter
->reset_task
);
7690 if (icr
& E1000_ICR_DOUTSYNC
) {
7691 /* HW is reporting DMA is out of sync */
7692 adapter
->stats
.doosync
++;
7695 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
7696 hw
->mac
.get_link_status
= 1;
7697 /* guard against interrupt when we're going down */
7698 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
7699 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
7702 if (icr
& E1000_ICR_TS
)
7703 igb_tsync_interrupt(adapter
);
7705 napi_schedule(&q_vector
->napi
);
7710 static void igb_ring_irq_enable(struct igb_q_vector
*q_vector
)
7712 struct igb_adapter
*adapter
= q_vector
->adapter
;
7713 struct e1000_hw
*hw
= &adapter
->hw
;
7715 if ((q_vector
->rx
.ring
&& (adapter
->rx_itr_setting
& 3)) ||
7716 (!q_vector
->rx
.ring
&& (adapter
->tx_itr_setting
& 3))) {
7717 if ((adapter
->num_q_vectors
== 1) && !adapter
->vf_data
)
7718 igb_set_itr(q_vector
);
7720 igb_update_ring_itr(q_vector
);
7723 if (!test_bit(__IGB_DOWN
, &adapter
->state
)) {
7724 if (adapter
->flags
& IGB_FLAG_HAS_MSIX
)
7725 wr32(E1000_EIMS
, q_vector
->eims_value
);
7727 igb_irq_enable(adapter
);
7732 * igb_poll - NAPI Rx polling callback
7733 * @napi: napi polling structure
7734 * @budget: count of how many packets we should handle
7736 static int igb_poll(struct napi_struct
*napi
, int budget
)
7738 struct igb_q_vector
*q_vector
= container_of(napi
,
7739 struct igb_q_vector
,
7741 bool clean_complete
= true;
7744 #ifdef CONFIG_IGB_DCA
7745 if (q_vector
->adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
7746 igb_update_dca(q_vector
);
7748 if (q_vector
->tx
.ring
)
7749 clean_complete
= igb_clean_tx_irq(q_vector
, budget
);
7751 if (q_vector
->rx
.ring
) {
7752 int cleaned
= igb_clean_rx_irq(q_vector
, budget
);
7754 work_done
+= cleaned
;
7755 if (cleaned
>= budget
)
7756 clean_complete
= false;
7759 /* If all work not completed, return budget and keep polling */
7760 if (!clean_complete
)
7763 /* If not enough Rx work done, exit the polling mode */
7764 napi_complete_done(napi
, work_done
);
7765 igb_ring_irq_enable(q_vector
);
7771 * igb_clean_tx_irq - Reclaim resources after transmit completes
7772 * @q_vector: pointer to q_vector containing needed info
7773 * @napi_budget: Used to determine if we are in netpoll
7775 * returns true if ring is completely cleaned
7777 static bool igb_clean_tx_irq(struct igb_q_vector
*q_vector
, int napi_budget
)
7779 struct igb_adapter
*adapter
= q_vector
->adapter
;
7780 struct igb_ring
*tx_ring
= q_vector
->tx
.ring
;
7781 struct igb_tx_buffer
*tx_buffer
;
7782 union e1000_adv_tx_desc
*tx_desc
;
7783 unsigned int total_bytes
= 0, total_packets
= 0;
7784 unsigned int budget
= q_vector
->tx
.work_limit
;
7785 unsigned int i
= tx_ring
->next_to_clean
;
7787 if (test_bit(__IGB_DOWN
, &adapter
->state
))
7790 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
7791 tx_desc
= IGB_TX_DESC(tx_ring
, i
);
7792 i
-= tx_ring
->count
;
7795 union e1000_adv_tx_desc
*eop_desc
= tx_buffer
->next_to_watch
;
7797 /* if next_to_watch is not set then there is no work pending */
7801 /* prevent any other reads prior to eop_desc */
7804 /* if DD is not set pending work has not been completed */
7805 if (!(eop_desc
->wb
.status
& cpu_to_le32(E1000_TXD_STAT_DD
)))
7808 /* clear next_to_watch to prevent false hangs */
7809 tx_buffer
->next_to_watch
= NULL
;
7811 /* update the statistics for this packet */
7812 total_bytes
+= tx_buffer
->bytecount
;
7813 total_packets
+= tx_buffer
->gso_segs
;
7816 napi_consume_skb(tx_buffer
->skb
, napi_budget
);
7818 /* unmap skb header data */
7819 dma_unmap_single(tx_ring
->dev
,
7820 dma_unmap_addr(tx_buffer
, dma
),
7821 dma_unmap_len(tx_buffer
, len
),
7824 /* clear tx_buffer data */
7825 dma_unmap_len_set(tx_buffer
, len
, 0);
7827 /* clear last DMA location and unmap remaining buffers */
7828 while (tx_desc
!= eop_desc
) {
7833 i
-= tx_ring
->count
;
7834 tx_buffer
= tx_ring
->tx_buffer_info
;
7835 tx_desc
= IGB_TX_DESC(tx_ring
, 0);
7838 /* unmap any remaining paged data */
7839 if (dma_unmap_len(tx_buffer
, len
)) {
7840 dma_unmap_page(tx_ring
->dev
,
7841 dma_unmap_addr(tx_buffer
, dma
),
7842 dma_unmap_len(tx_buffer
, len
),
7844 dma_unmap_len_set(tx_buffer
, len
, 0);
7848 /* move us one more past the eop_desc for start of next pkt */
7853 i
-= tx_ring
->count
;
7854 tx_buffer
= tx_ring
->tx_buffer_info
;
7855 tx_desc
= IGB_TX_DESC(tx_ring
, 0);
7858 /* issue prefetch for next Tx descriptor */
7861 /* update budget accounting */
7863 } while (likely(budget
));
7865 netdev_tx_completed_queue(txring_txq(tx_ring
),
7866 total_packets
, total_bytes
);
7867 i
+= tx_ring
->count
;
7868 tx_ring
->next_to_clean
= i
;
7869 u64_stats_update_begin(&tx_ring
->tx_syncp
);
7870 tx_ring
->tx_stats
.bytes
+= total_bytes
;
7871 tx_ring
->tx_stats
.packets
+= total_packets
;
7872 u64_stats_update_end(&tx_ring
->tx_syncp
);
7873 q_vector
->tx
.total_bytes
+= total_bytes
;
7874 q_vector
->tx
.total_packets
+= total_packets
;
7876 if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG
, &tx_ring
->flags
)) {
7877 struct e1000_hw
*hw
= &adapter
->hw
;
7879 /* Detect a transmit hang in hardware, this serializes the
7880 * check with the clearing of time_stamp and movement of i
7882 clear_bit(IGB_RING_FLAG_TX_DETECT_HANG
, &tx_ring
->flags
);
7883 if (tx_buffer
->next_to_watch
&&
7884 time_after(jiffies
, tx_buffer
->time_stamp
+
7885 (adapter
->tx_timeout_factor
* HZ
)) &&
7886 !(rd32(E1000_STATUS
) & E1000_STATUS_TXOFF
)) {
7888 /* detected Tx unit hang */
7889 dev_err(tx_ring
->dev
,
7890 "Detected Tx Unit Hang\n"
7894 " next_to_use <%x>\n"
7895 " next_to_clean <%x>\n"
7896 "buffer_info[next_to_clean]\n"
7897 " time_stamp <%lx>\n"
7898 " next_to_watch <%p>\n"
7900 " desc.status <%x>\n",
7901 tx_ring
->queue_index
,
7902 rd32(E1000_TDH(tx_ring
->reg_idx
)),
7903 readl(tx_ring
->tail
),
7904 tx_ring
->next_to_use
,
7905 tx_ring
->next_to_clean
,
7906 tx_buffer
->time_stamp
,
7907 tx_buffer
->next_to_watch
,
7909 tx_buffer
->next_to_watch
->wb
.status
);
7910 netif_stop_subqueue(tx_ring
->netdev
,
7911 tx_ring
->queue_index
);
7913 /* we are about to reset, no point in enabling stuff */
7918 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
7919 if (unlikely(total_packets
&&
7920 netif_carrier_ok(tx_ring
->netdev
) &&
7921 igb_desc_unused(tx_ring
) >= TX_WAKE_THRESHOLD
)) {
7922 /* Make sure that anybody stopping the queue after this
7923 * sees the new next_to_clean.
7926 if (__netif_subqueue_stopped(tx_ring
->netdev
,
7927 tx_ring
->queue_index
) &&
7928 !(test_bit(__IGB_DOWN
, &adapter
->state
))) {
7929 netif_wake_subqueue(tx_ring
->netdev
,
7930 tx_ring
->queue_index
);
7932 u64_stats_update_begin(&tx_ring
->tx_syncp
);
7933 tx_ring
->tx_stats
.restart_queue
++;
7934 u64_stats_update_end(&tx_ring
->tx_syncp
);
7942 * igb_reuse_rx_page - page flip buffer and store it back on the ring
7943 * @rx_ring: rx descriptor ring to store buffers on
7944 * @old_buff: donor buffer to have page reused
7946 * Synchronizes page for reuse by the adapter
7948 static void igb_reuse_rx_page(struct igb_ring
*rx_ring
,
7949 struct igb_rx_buffer
*old_buff
)
7951 struct igb_rx_buffer
*new_buff
;
7952 u16 nta
= rx_ring
->next_to_alloc
;
7954 new_buff
= &rx_ring
->rx_buffer_info
[nta
];
7956 /* update, and store next to alloc */
7958 rx_ring
->next_to_alloc
= (nta
< rx_ring
->count
) ? nta
: 0;
7960 /* Transfer page from old buffer to new buffer.
7961 * Move each member individually to avoid possible store
7962 * forwarding stalls.
7964 new_buff
->dma
= old_buff
->dma
;
7965 new_buff
->page
= old_buff
->page
;
7966 new_buff
->page_offset
= old_buff
->page_offset
;
7967 new_buff
->pagecnt_bias
= old_buff
->pagecnt_bias
;
7970 static inline bool igb_page_is_reserved(struct page
*page
)
7972 return (page_to_nid(page
) != numa_mem_id()) || page_is_pfmemalloc(page
);
7975 static bool igb_can_reuse_rx_page(struct igb_rx_buffer
*rx_buffer
)
7977 unsigned int pagecnt_bias
= rx_buffer
->pagecnt_bias
;
7978 struct page
*page
= rx_buffer
->page
;
7980 /* avoid re-using remote pages */
7981 if (unlikely(igb_page_is_reserved(page
)))
7984 #if (PAGE_SIZE < 8192)
7985 /* if we are only owner of page we can reuse it */
7986 if (unlikely((page_ref_count(page
) - pagecnt_bias
) > 1))
7989 #define IGB_LAST_OFFSET \
7990 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IGB_RXBUFFER_2048)
7992 if (rx_buffer
->page_offset
> IGB_LAST_OFFSET
)
7996 /* If we have drained the page fragment pool we need to update
7997 * the pagecnt_bias and page count so that we fully restock the
7998 * number of references the driver holds.
8000 if (unlikely(!pagecnt_bias
)) {
8001 page_ref_add(page
, USHRT_MAX
);
8002 rx_buffer
->pagecnt_bias
= USHRT_MAX
;
8009 * igb_add_rx_frag - Add contents of Rx buffer to sk_buff
8010 * @rx_ring: rx descriptor ring to transact packets on
8011 * @rx_buffer: buffer containing page to add
8012 * @skb: sk_buff to place the data into
8013 * @size: size of buffer to be added
8015 * This function will add the data contained in rx_buffer->page to the skb.
8017 static void igb_add_rx_frag(struct igb_ring
*rx_ring
,
8018 struct igb_rx_buffer
*rx_buffer
,
8019 struct sk_buff
*skb
,
8022 #if (PAGE_SIZE < 8192)
8023 unsigned int truesize
= igb_rx_pg_size(rx_ring
) / 2;
8025 unsigned int truesize
= ring_uses_build_skb(rx_ring
) ?
8026 SKB_DATA_ALIGN(IGB_SKB_PAD
+ size
) :
8027 SKB_DATA_ALIGN(size
);
8029 skb_add_rx_frag(skb
, skb_shinfo(skb
)->nr_frags
, rx_buffer
->page
,
8030 rx_buffer
->page_offset
, size
, truesize
);
8031 #if (PAGE_SIZE < 8192)
8032 rx_buffer
->page_offset
^= truesize
;
8034 rx_buffer
->page_offset
+= truesize
;
8038 static struct sk_buff
*igb_construct_skb(struct igb_ring
*rx_ring
,
8039 struct igb_rx_buffer
*rx_buffer
,
8040 union e1000_adv_rx_desc
*rx_desc
,
8043 void *va
= page_address(rx_buffer
->page
) + rx_buffer
->page_offset
;
8044 #if (PAGE_SIZE < 8192)
8045 unsigned int truesize
= igb_rx_pg_size(rx_ring
) / 2;
8047 unsigned int truesize
= SKB_DATA_ALIGN(size
);
8049 unsigned int headlen
;
8050 struct sk_buff
*skb
;
8052 /* prefetch first cache line of first page */
8054 #if L1_CACHE_BYTES < 128
8055 prefetch(va
+ L1_CACHE_BYTES
);
8058 /* allocate a skb to store the frags */
8059 skb
= napi_alloc_skb(&rx_ring
->q_vector
->napi
, IGB_RX_HDR_LEN
);
8063 if (unlikely(igb_test_staterr(rx_desc
, E1000_RXDADV_STAT_TSIP
))) {
8064 igb_ptp_rx_pktstamp(rx_ring
->q_vector
, va
, skb
);
8065 va
+= IGB_TS_HDR_LEN
;
8066 size
-= IGB_TS_HDR_LEN
;
8069 /* Determine available headroom for copy */
8071 if (headlen
> IGB_RX_HDR_LEN
)
8072 headlen
= eth_get_headlen(va
, IGB_RX_HDR_LEN
);
8074 /* align pull length to size of long to optimize memcpy performance */
8075 memcpy(__skb_put(skb
, headlen
), va
, ALIGN(headlen
, sizeof(long)));
8077 /* update all of the pointers */
8080 skb_add_rx_frag(skb
, 0, rx_buffer
->page
,
8081 (va
+ headlen
) - page_address(rx_buffer
->page
),
8083 #if (PAGE_SIZE < 8192)
8084 rx_buffer
->page_offset
^= truesize
;
8086 rx_buffer
->page_offset
+= truesize
;
8089 rx_buffer
->pagecnt_bias
++;
8095 static struct sk_buff
*igb_build_skb(struct igb_ring
*rx_ring
,
8096 struct igb_rx_buffer
*rx_buffer
,
8097 union e1000_adv_rx_desc
*rx_desc
,
8100 void *va
= page_address(rx_buffer
->page
) + rx_buffer
->page_offset
;
8101 #if (PAGE_SIZE < 8192)
8102 unsigned int truesize
= igb_rx_pg_size(rx_ring
) / 2;
8104 unsigned int truesize
= SKB_DATA_ALIGN(sizeof(struct skb_shared_info
)) +
8105 SKB_DATA_ALIGN(IGB_SKB_PAD
+ size
);
8107 struct sk_buff
*skb
;
8109 /* prefetch first cache line of first page */
8111 #if L1_CACHE_BYTES < 128
8112 prefetch(va
+ L1_CACHE_BYTES
);
8115 /* build an skb around the page buffer */
8116 skb
= build_skb(va
- IGB_SKB_PAD
, truesize
);
8120 /* update pointers within the skb to store the data */
8121 skb_reserve(skb
, IGB_SKB_PAD
);
8122 __skb_put(skb
, size
);
8124 /* pull timestamp out of packet data */
8125 if (igb_test_staterr(rx_desc
, E1000_RXDADV_STAT_TSIP
)) {
8126 igb_ptp_rx_pktstamp(rx_ring
->q_vector
, skb
->data
, skb
);
8127 __skb_pull(skb
, IGB_TS_HDR_LEN
);
8130 /* update buffer offset */
8131 #if (PAGE_SIZE < 8192)
8132 rx_buffer
->page_offset
^= truesize
;
8134 rx_buffer
->page_offset
+= truesize
;
8140 static inline void igb_rx_checksum(struct igb_ring
*ring
,
8141 union e1000_adv_rx_desc
*rx_desc
,
8142 struct sk_buff
*skb
)
8144 skb_checksum_none_assert(skb
);
8146 /* Ignore Checksum bit is set */
8147 if (igb_test_staterr(rx_desc
, E1000_RXD_STAT_IXSM
))
8150 /* Rx checksum disabled via ethtool */
8151 if (!(ring
->netdev
->features
& NETIF_F_RXCSUM
))
8154 /* TCP/UDP checksum error bit is set */
8155 if (igb_test_staterr(rx_desc
,
8156 E1000_RXDEXT_STATERR_TCPE
|
8157 E1000_RXDEXT_STATERR_IPE
)) {
8158 /* work around errata with sctp packets where the TCPE aka
8159 * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
8160 * packets, (aka let the stack check the crc32c)
8162 if (!((skb
->len
== 60) &&
8163 test_bit(IGB_RING_FLAG_RX_SCTP_CSUM
, &ring
->flags
))) {
8164 u64_stats_update_begin(&ring
->rx_syncp
);
8165 ring
->rx_stats
.csum_err
++;
8166 u64_stats_update_end(&ring
->rx_syncp
);
8168 /* let the stack verify checksum errors */
8171 /* It must be a TCP or UDP packet with a valid checksum */
8172 if (igb_test_staterr(rx_desc
, E1000_RXD_STAT_TCPCS
|
8173 E1000_RXD_STAT_UDPCS
))
8174 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
8176 dev_dbg(ring
->dev
, "cksum success: bits %08X\n",
8177 le32_to_cpu(rx_desc
->wb
.upper
.status_error
));
8180 static inline void igb_rx_hash(struct igb_ring
*ring
,
8181 union e1000_adv_rx_desc
*rx_desc
,
8182 struct sk_buff
*skb
)
8184 if (ring
->netdev
->features
& NETIF_F_RXHASH
)
8186 le32_to_cpu(rx_desc
->wb
.lower
.hi_dword
.rss
),
8191 * igb_is_non_eop - process handling of non-EOP buffers
8192 * @rx_ring: Rx ring being processed
8193 * @rx_desc: Rx descriptor for current buffer
8194 * @skb: current socket buffer containing buffer in progress
8196 * This function updates next to clean. If the buffer is an EOP buffer
8197 * this function exits returning false, otherwise it will place the
8198 * sk_buff in the next buffer to be chained and return true indicating
8199 * that this is in fact a non-EOP buffer.
8201 static bool igb_is_non_eop(struct igb_ring
*rx_ring
,
8202 union e1000_adv_rx_desc
*rx_desc
)
8204 u32 ntc
= rx_ring
->next_to_clean
+ 1;
8206 /* fetch, update, and store next to clean */
8207 ntc
= (ntc
< rx_ring
->count
) ? ntc
: 0;
8208 rx_ring
->next_to_clean
= ntc
;
8210 prefetch(IGB_RX_DESC(rx_ring
, ntc
));
8212 if (likely(igb_test_staterr(rx_desc
, E1000_RXD_STAT_EOP
)))
8219 * igb_cleanup_headers - Correct corrupted or empty headers
8220 * @rx_ring: rx descriptor ring packet is being transacted on
8221 * @rx_desc: pointer to the EOP Rx descriptor
8222 * @skb: pointer to current skb being fixed
8224 * Address the case where we are pulling data in on pages only
8225 * and as such no data is present in the skb header.
8227 * In addition if skb is not at least 60 bytes we need to pad it so that
8228 * it is large enough to qualify as a valid Ethernet frame.
8230 * Returns true if an error was encountered and skb was freed.
8232 static bool igb_cleanup_headers(struct igb_ring
*rx_ring
,
8233 union e1000_adv_rx_desc
*rx_desc
,
8234 struct sk_buff
*skb
)
8236 if (unlikely((igb_test_staterr(rx_desc
,
8237 E1000_RXDEXT_ERR_FRAME_ERR_MASK
)))) {
8238 struct net_device
*netdev
= rx_ring
->netdev
;
8239 if (!(netdev
->features
& NETIF_F_RXALL
)) {
8240 dev_kfree_skb_any(skb
);
8245 /* if eth_skb_pad returns an error the skb was freed */
8246 if (eth_skb_pad(skb
))
8253 * igb_process_skb_fields - Populate skb header fields from Rx descriptor
8254 * @rx_ring: rx descriptor ring packet is being transacted on
8255 * @rx_desc: pointer to the EOP Rx descriptor
8256 * @skb: pointer to current skb being populated
8258 * This function checks the ring, descriptor, and packet information in
8259 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
8260 * other fields within the skb.
8262 static void igb_process_skb_fields(struct igb_ring
*rx_ring
,
8263 union e1000_adv_rx_desc
*rx_desc
,
8264 struct sk_buff
*skb
)
8266 struct net_device
*dev
= rx_ring
->netdev
;
8268 igb_rx_hash(rx_ring
, rx_desc
, skb
);
8270 igb_rx_checksum(rx_ring
, rx_desc
, skb
);
8272 if (igb_test_staterr(rx_desc
, E1000_RXDADV_STAT_TS
) &&
8273 !igb_test_staterr(rx_desc
, E1000_RXDADV_STAT_TSIP
))
8274 igb_ptp_rx_rgtstamp(rx_ring
->q_vector
, skb
);
8276 if ((dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
) &&
8277 igb_test_staterr(rx_desc
, E1000_RXD_STAT_VP
)) {
8280 if (igb_test_staterr(rx_desc
, E1000_RXDEXT_STATERR_LB
) &&
8281 test_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP
, &rx_ring
->flags
))
8282 vid
= be16_to_cpu(rx_desc
->wb
.upper
.vlan
);
8284 vid
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
8286 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), vid
);
8289 skb_record_rx_queue(skb
, rx_ring
->queue_index
);
8291 skb
->protocol
= eth_type_trans(skb
, rx_ring
->netdev
);
8294 static struct igb_rx_buffer
*igb_get_rx_buffer(struct igb_ring
*rx_ring
,
8295 const unsigned int size
)
8297 struct igb_rx_buffer
*rx_buffer
;
8299 rx_buffer
= &rx_ring
->rx_buffer_info
[rx_ring
->next_to_clean
];
8300 prefetchw(rx_buffer
->page
);
8302 /* we are reusing so sync this buffer for CPU use */
8303 dma_sync_single_range_for_cpu(rx_ring
->dev
,
8305 rx_buffer
->page_offset
,
8309 rx_buffer
->pagecnt_bias
--;
8314 static void igb_put_rx_buffer(struct igb_ring
*rx_ring
,
8315 struct igb_rx_buffer
*rx_buffer
)
8317 if (igb_can_reuse_rx_page(rx_buffer
)) {
8318 /* hand second half of page back to the ring */
8319 igb_reuse_rx_page(rx_ring
, rx_buffer
);
8321 /* We are not reusing the buffer so unmap it and free
8322 * any references we are holding to it
8324 dma_unmap_page_attrs(rx_ring
->dev
, rx_buffer
->dma
,
8325 igb_rx_pg_size(rx_ring
), DMA_FROM_DEVICE
,
8327 __page_frag_cache_drain(rx_buffer
->page
,
8328 rx_buffer
->pagecnt_bias
);
8331 /* clear contents of rx_buffer */
8332 rx_buffer
->page
= NULL
;
8335 static int igb_clean_rx_irq(struct igb_q_vector
*q_vector
, const int budget
)
8337 struct igb_ring
*rx_ring
= q_vector
->rx
.ring
;
8338 struct sk_buff
*skb
= rx_ring
->skb
;
8339 unsigned int total_bytes
= 0, total_packets
= 0;
8340 u16 cleaned_count
= igb_desc_unused(rx_ring
);
8342 while (likely(total_packets
< budget
)) {
8343 union e1000_adv_rx_desc
*rx_desc
;
8344 struct igb_rx_buffer
*rx_buffer
;
8347 /* return some buffers to hardware, one at a time is too slow */
8348 if (cleaned_count
>= IGB_RX_BUFFER_WRITE
) {
8349 igb_alloc_rx_buffers(rx_ring
, cleaned_count
);
8353 rx_desc
= IGB_RX_DESC(rx_ring
, rx_ring
->next_to_clean
);
8354 size
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
8358 /* This memory barrier is needed to keep us from reading
8359 * any other fields out of the rx_desc until we know the
8360 * descriptor has been written back
8364 rx_buffer
= igb_get_rx_buffer(rx_ring
, size
);
8366 /* retrieve a buffer from the ring */
8368 igb_add_rx_frag(rx_ring
, rx_buffer
, skb
, size
);
8369 else if (ring_uses_build_skb(rx_ring
))
8370 skb
= igb_build_skb(rx_ring
, rx_buffer
, rx_desc
, size
);
8372 skb
= igb_construct_skb(rx_ring
, rx_buffer
,
8375 /* exit if we failed to retrieve a buffer */
8377 rx_ring
->rx_stats
.alloc_failed
++;
8378 rx_buffer
->pagecnt_bias
++;
8382 igb_put_rx_buffer(rx_ring
, rx_buffer
);
8385 /* fetch next buffer in frame if non-eop */
8386 if (igb_is_non_eop(rx_ring
, rx_desc
))
8389 /* verify the packet layout is correct */
8390 if (igb_cleanup_headers(rx_ring
, rx_desc
, skb
)) {
8395 /* probably a little skewed due to removing CRC */
8396 total_bytes
+= skb
->len
;
8398 /* populate checksum, timestamp, VLAN, and protocol */
8399 igb_process_skb_fields(rx_ring
, rx_desc
, skb
);
8401 napi_gro_receive(&q_vector
->napi
, skb
);
8403 /* reset skb pointer */
8406 /* update budget accounting */
8410 /* place incomplete frames back on ring for completion */
8413 u64_stats_update_begin(&rx_ring
->rx_syncp
);
8414 rx_ring
->rx_stats
.packets
+= total_packets
;
8415 rx_ring
->rx_stats
.bytes
+= total_bytes
;
8416 u64_stats_update_end(&rx_ring
->rx_syncp
);
8417 q_vector
->rx
.total_packets
+= total_packets
;
8418 q_vector
->rx
.total_bytes
+= total_bytes
;
8421 igb_alloc_rx_buffers(rx_ring
, cleaned_count
);
8423 return total_packets
;
8426 static inline unsigned int igb_rx_offset(struct igb_ring
*rx_ring
)
8428 return ring_uses_build_skb(rx_ring
) ? IGB_SKB_PAD
: 0;
8431 static bool igb_alloc_mapped_page(struct igb_ring
*rx_ring
,
8432 struct igb_rx_buffer
*bi
)
8434 struct page
*page
= bi
->page
;
8437 /* since we are recycling buffers we should seldom need to alloc */
8441 /* alloc new page for storage */
8442 page
= dev_alloc_pages(igb_rx_pg_order(rx_ring
));
8443 if (unlikely(!page
)) {
8444 rx_ring
->rx_stats
.alloc_failed
++;
8448 /* map page for use */
8449 dma
= dma_map_page_attrs(rx_ring
->dev
, page
, 0,
8450 igb_rx_pg_size(rx_ring
),
8454 /* if mapping failed free memory back to system since
8455 * there isn't much point in holding memory we can't use
8457 if (dma_mapping_error(rx_ring
->dev
, dma
)) {
8458 __free_pages(page
, igb_rx_pg_order(rx_ring
));
8460 rx_ring
->rx_stats
.alloc_failed
++;
8466 bi
->page_offset
= igb_rx_offset(rx_ring
);
8467 bi
->pagecnt_bias
= 1;
8473 * igb_alloc_rx_buffers - Replace used receive buffers; packet split
8474 * @adapter: address of board private structure
8476 void igb_alloc_rx_buffers(struct igb_ring
*rx_ring
, u16 cleaned_count
)
8478 union e1000_adv_rx_desc
*rx_desc
;
8479 struct igb_rx_buffer
*bi
;
8480 u16 i
= rx_ring
->next_to_use
;
8487 rx_desc
= IGB_RX_DESC(rx_ring
, i
);
8488 bi
= &rx_ring
->rx_buffer_info
[i
];
8489 i
-= rx_ring
->count
;
8491 bufsz
= igb_rx_bufsz(rx_ring
);
8494 if (!igb_alloc_mapped_page(rx_ring
, bi
))
8497 /* sync the buffer for use by the device */
8498 dma_sync_single_range_for_device(rx_ring
->dev
, bi
->dma
,
8499 bi
->page_offset
, bufsz
,
8502 /* Refresh the desc even if buffer_addrs didn't change
8503 * because each write-back erases this info.
8505 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
+ bi
->page_offset
);
8511 rx_desc
= IGB_RX_DESC(rx_ring
, 0);
8512 bi
= rx_ring
->rx_buffer_info
;
8513 i
-= rx_ring
->count
;
8516 /* clear the length for the next_to_use descriptor */
8517 rx_desc
->wb
.upper
.length
= 0;
8520 } while (cleaned_count
);
8522 i
+= rx_ring
->count
;
8524 if (rx_ring
->next_to_use
!= i
) {
8525 /* record the next descriptor to use */
8526 rx_ring
->next_to_use
= i
;
8528 /* update next to alloc since we have filled the ring */
8529 rx_ring
->next_to_alloc
= i
;
8531 /* Force memory writes to complete before letting h/w
8532 * know there are new descriptors to fetch. (Only
8533 * applicable for weak-ordered memory model archs,
8537 writel(i
, rx_ring
->tail
);
8547 static int igb_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
8549 struct igb_adapter
*adapter
= netdev_priv(netdev
);
8550 struct mii_ioctl_data
*data
= if_mii(ifr
);
8552 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
8557 data
->phy_id
= adapter
->hw
.phy
.addr
;
8560 if (igb_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
8577 static int igb_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
8583 return igb_mii_ioctl(netdev
, ifr
, cmd
);
8585 return igb_ptp_get_ts_config(netdev
, ifr
);
8587 return igb_ptp_set_ts_config(netdev
, ifr
);
8593 void igb_read_pci_cfg(struct e1000_hw
*hw
, u32 reg
, u16
*value
)
8595 struct igb_adapter
*adapter
= hw
->back
;
8597 pci_read_config_word(adapter
->pdev
, reg
, value
);
8600 void igb_write_pci_cfg(struct e1000_hw
*hw
, u32 reg
, u16
*value
)
8602 struct igb_adapter
*adapter
= hw
->back
;
8604 pci_write_config_word(adapter
->pdev
, reg
, *value
);
8607 s32
igb_read_pcie_cap_reg(struct e1000_hw
*hw
, u32 reg
, u16
*value
)
8609 struct igb_adapter
*adapter
= hw
->back
;
8611 if (pcie_capability_read_word(adapter
->pdev
, reg
, value
))
8612 return -E1000_ERR_CONFIG
;
8617 s32
igb_write_pcie_cap_reg(struct e1000_hw
*hw
, u32 reg
, u16
*value
)
8619 struct igb_adapter
*adapter
= hw
->back
;
8621 if (pcie_capability_write_word(adapter
->pdev
, reg
, *value
))
8622 return -E1000_ERR_CONFIG
;
8627 static void igb_vlan_mode(struct net_device
*netdev
, netdev_features_t features
)
8629 struct igb_adapter
*adapter
= netdev_priv(netdev
);
8630 struct e1000_hw
*hw
= &adapter
->hw
;
8632 bool enable
= !!(features
& NETIF_F_HW_VLAN_CTAG_RX
);
8635 /* enable VLAN tag insert/strip */
8636 ctrl
= rd32(E1000_CTRL
);
8637 ctrl
|= E1000_CTRL_VME
;
8638 wr32(E1000_CTRL
, ctrl
);
8640 /* Disable CFI check */
8641 rctl
= rd32(E1000_RCTL
);
8642 rctl
&= ~E1000_RCTL_CFIEN
;
8643 wr32(E1000_RCTL
, rctl
);
8645 /* disable VLAN tag insert/strip */
8646 ctrl
= rd32(E1000_CTRL
);
8647 ctrl
&= ~E1000_CTRL_VME
;
8648 wr32(E1000_CTRL
, ctrl
);
8651 igb_set_vf_vlan_strip(adapter
, adapter
->vfs_allocated_count
, enable
);
8654 static int igb_vlan_rx_add_vid(struct net_device
*netdev
,
8655 __be16 proto
, u16 vid
)
8657 struct igb_adapter
*adapter
= netdev_priv(netdev
);
8658 struct e1000_hw
*hw
= &adapter
->hw
;
8659 int pf_id
= adapter
->vfs_allocated_count
;
8661 /* add the filter since PF can receive vlans w/o entry in vlvf */
8662 if (!vid
|| !(adapter
->flags
& IGB_FLAG_VLAN_PROMISC
))
8663 igb_vfta_set(hw
, vid
, pf_id
, true, !!vid
);
8665 set_bit(vid
, adapter
->active_vlans
);
8670 static int igb_vlan_rx_kill_vid(struct net_device
*netdev
,
8671 __be16 proto
, u16 vid
)
8673 struct igb_adapter
*adapter
= netdev_priv(netdev
);
8674 int pf_id
= adapter
->vfs_allocated_count
;
8675 struct e1000_hw
*hw
= &adapter
->hw
;
8677 /* remove VID from filter table */
8678 if (vid
&& !(adapter
->flags
& IGB_FLAG_VLAN_PROMISC
))
8679 igb_vfta_set(hw
, vid
, pf_id
, false, true);
8681 clear_bit(vid
, adapter
->active_vlans
);
8686 static void igb_restore_vlan(struct igb_adapter
*adapter
)
8690 igb_vlan_mode(adapter
->netdev
, adapter
->netdev
->features
);
8691 igb_vlan_rx_add_vid(adapter
->netdev
, htons(ETH_P_8021Q
), 0);
8693 for_each_set_bit_from(vid
, adapter
->active_vlans
, VLAN_N_VID
)
8694 igb_vlan_rx_add_vid(adapter
->netdev
, htons(ETH_P_8021Q
), vid
);
8697 int igb_set_spd_dplx(struct igb_adapter
*adapter
, u32 spd
, u8 dplx
)
8699 struct pci_dev
*pdev
= adapter
->pdev
;
8700 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
8704 /* Make sure dplx is at most 1 bit and lsb of speed is not set
8705 * for the switch() below to work
8707 if ((spd
& 1) || (dplx
& ~1))
8710 /* Fiber NIC's only allow 1000 gbps Full duplex
8711 * and 100Mbps Full duplex for 100baseFx sfp
8713 if (adapter
->hw
.phy
.media_type
== e1000_media_type_internal_serdes
) {
8714 switch (spd
+ dplx
) {
8715 case SPEED_10
+ DUPLEX_HALF
:
8716 case SPEED_10
+ DUPLEX_FULL
:
8717 case SPEED_100
+ DUPLEX_HALF
:
8724 switch (spd
+ dplx
) {
8725 case SPEED_10
+ DUPLEX_HALF
:
8726 mac
->forced_speed_duplex
= ADVERTISE_10_HALF
;
8728 case SPEED_10
+ DUPLEX_FULL
:
8729 mac
->forced_speed_duplex
= ADVERTISE_10_FULL
;
8731 case SPEED_100
+ DUPLEX_HALF
:
8732 mac
->forced_speed_duplex
= ADVERTISE_100_HALF
;
8734 case SPEED_100
+ DUPLEX_FULL
:
8735 mac
->forced_speed_duplex
= ADVERTISE_100_FULL
;
8737 case SPEED_1000
+ DUPLEX_FULL
:
8739 adapter
->hw
.phy
.autoneg_advertised
= ADVERTISE_1000_FULL
;
8741 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
8746 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
8747 adapter
->hw
.phy
.mdix
= AUTO_ALL_MODES
;
8752 dev_err(&pdev
->dev
, "Unsupported Speed/Duplex configuration\n");
8756 static int __igb_shutdown(struct pci_dev
*pdev
, bool *enable_wake
,
8759 struct net_device
*netdev
= pci_get_drvdata(pdev
);
8760 struct igb_adapter
*adapter
= netdev_priv(netdev
);
8761 struct e1000_hw
*hw
= &adapter
->hw
;
8762 u32 ctrl
, rctl
, status
;
8763 u32 wufc
= runtime
? E1000_WUFC_LNKC
: adapter
->wol
;
8769 netif_device_detach(netdev
);
8771 if (netif_running(netdev
))
8772 __igb_close(netdev
, true);
8774 igb_ptp_suspend(adapter
);
8776 igb_clear_interrupt_scheme(adapter
);
8780 retval
= pci_save_state(pdev
);
8785 status
= rd32(E1000_STATUS
);
8786 if (status
& E1000_STATUS_LU
)
8787 wufc
&= ~E1000_WUFC_LNKC
;
8790 igb_setup_rctl(adapter
);
8791 igb_set_rx_mode(netdev
);
8793 /* turn on all-multi mode if wake on multicast is enabled */
8794 if (wufc
& E1000_WUFC_MC
) {
8795 rctl
= rd32(E1000_RCTL
);
8796 rctl
|= E1000_RCTL_MPE
;
8797 wr32(E1000_RCTL
, rctl
);
8800 ctrl
= rd32(E1000_CTRL
);
8801 /* advertise wake from D3Cold */
8802 #define E1000_CTRL_ADVD3WUC 0x00100000
8803 /* phy power management enable */
8804 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
8805 ctrl
|= E1000_CTRL_ADVD3WUC
;
8806 wr32(E1000_CTRL
, ctrl
);
8808 /* Allow time for pending master requests to run */
8809 igb_disable_pcie_master(hw
);
8811 wr32(E1000_WUC
, E1000_WUC_PME_EN
);
8812 wr32(E1000_WUFC
, wufc
);
8815 wr32(E1000_WUFC
, 0);
8818 *enable_wake
= wufc
|| adapter
->en_mng_pt
;
8820 igb_power_down_link(adapter
);
8822 igb_power_up_link(adapter
);
8824 /* Release control of h/w to f/w. If f/w is AMT enabled, this
8825 * would have already happened in close and is redundant.
8827 igb_release_hw_control(adapter
);
8829 pci_disable_device(pdev
);
8834 static void igb_deliver_wake_packet(struct net_device
*netdev
)
8836 struct igb_adapter
*adapter
= netdev_priv(netdev
);
8837 struct e1000_hw
*hw
= &adapter
->hw
;
8838 struct sk_buff
*skb
;
8841 wupl
= rd32(E1000_WUPL
) & E1000_WUPL_MASK
;
8843 /* WUPM stores only the first 128 bytes of the wake packet.
8844 * Read the packet only if we have the whole thing.
8846 if ((wupl
== 0) || (wupl
> E1000_WUPM_BYTES
))
8849 skb
= netdev_alloc_skb_ip_align(netdev
, E1000_WUPM_BYTES
);
8855 /* Ensure reads are 32-bit aligned */
8856 wupl
= roundup(wupl
, 4);
8858 memcpy_fromio(skb
->data
, hw
->hw_addr
+ E1000_WUPM_REG(0), wupl
);
8860 skb
->protocol
= eth_type_trans(skb
, netdev
);
8864 static int __maybe_unused
igb_suspend(struct device
*dev
)
8868 struct pci_dev
*pdev
= to_pci_dev(dev
);
8870 retval
= __igb_shutdown(pdev
, &wake
, 0);
8875 pci_prepare_to_sleep(pdev
);
8877 pci_wake_from_d3(pdev
, false);
8878 pci_set_power_state(pdev
, PCI_D3hot
);
8884 static int __maybe_unused
igb_resume(struct device
*dev
)
8886 struct pci_dev
*pdev
= to_pci_dev(dev
);
8887 struct net_device
*netdev
= pci_get_drvdata(pdev
);
8888 struct igb_adapter
*adapter
= netdev_priv(netdev
);
8889 struct e1000_hw
*hw
= &adapter
->hw
;
8892 pci_set_power_state(pdev
, PCI_D0
);
8893 pci_restore_state(pdev
);
8894 pci_save_state(pdev
);
8896 if (!pci_device_is_present(pdev
))
8898 err
= pci_enable_device_mem(pdev
);
8901 "igb: Cannot enable PCI device from suspend\n");
8904 pci_set_master(pdev
);
8906 pci_enable_wake(pdev
, PCI_D3hot
, 0);
8907 pci_enable_wake(pdev
, PCI_D3cold
, 0);
8909 if (igb_init_interrupt_scheme(adapter
, true)) {
8910 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
8916 /* let the f/w know that the h/w is now under the control of the
8919 igb_get_hw_control(adapter
);
8921 val
= rd32(E1000_WUS
);
8922 if (val
& WAKE_PKT_WUS
)
8923 igb_deliver_wake_packet(netdev
);
8925 wr32(E1000_WUS
, ~0);
8928 if (!err
&& netif_running(netdev
))
8929 err
= __igb_open(netdev
, true);
8932 netif_device_attach(netdev
);
8938 static int __maybe_unused
igb_runtime_idle(struct device
*dev
)
8940 struct pci_dev
*pdev
= to_pci_dev(dev
);
8941 struct net_device
*netdev
= pci_get_drvdata(pdev
);
8942 struct igb_adapter
*adapter
= netdev_priv(netdev
);
8944 if (!igb_has_link(adapter
))
8945 pm_schedule_suspend(dev
, MSEC_PER_SEC
* 5);
8950 static int __maybe_unused
igb_runtime_suspend(struct device
*dev
)
8952 struct pci_dev
*pdev
= to_pci_dev(dev
);
8956 retval
= __igb_shutdown(pdev
, &wake
, 1);
8961 pci_prepare_to_sleep(pdev
);
8963 pci_wake_from_d3(pdev
, false);
8964 pci_set_power_state(pdev
, PCI_D3hot
);
8970 static int __maybe_unused
igb_runtime_resume(struct device
*dev
)
8972 return igb_resume(dev
);
8975 static void igb_shutdown(struct pci_dev
*pdev
)
8979 __igb_shutdown(pdev
, &wake
, 0);
8981 if (system_state
== SYSTEM_POWER_OFF
) {
8982 pci_wake_from_d3(pdev
, wake
);
8983 pci_set_power_state(pdev
, PCI_D3hot
);
8987 #ifdef CONFIG_PCI_IOV
8988 static int igb_sriov_reinit(struct pci_dev
*dev
)
8990 struct net_device
*netdev
= pci_get_drvdata(dev
);
8991 struct igb_adapter
*adapter
= netdev_priv(netdev
);
8992 struct pci_dev
*pdev
= adapter
->pdev
;
8996 if (netif_running(netdev
))
9001 igb_clear_interrupt_scheme(adapter
);
9003 igb_init_queue_configuration(adapter
);
9005 if (igb_init_interrupt_scheme(adapter
, true)) {
9007 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
9011 if (netif_running(netdev
))
9019 static int igb_pci_disable_sriov(struct pci_dev
*dev
)
9021 int err
= igb_disable_sriov(dev
);
9024 err
= igb_sriov_reinit(dev
);
9029 static int igb_pci_enable_sriov(struct pci_dev
*dev
, int num_vfs
)
9031 int err
= igb_enable_sriov(dev
, num_vfs
);
9036 err
= igb_sriov_reinit(dev
);
9045 static int igb_pci_sriov_configure(struct pci_dev
*dev
, int num_vfs
)
9047 #ifdef CONFIG_PCI_IOV
9049 return igb_pci_disable_sriov(dev
);
9051 return igb_pci_enable_sriov(dev
, num_vfs
);
9056 #ifdef CONFIG_NET_POLL_CONTROLLER
9057 /* Polling 'interrupt' - used by things like netconsole to send skbs
9058 * without having to re-enable interrupts. It's not called while
9059 * the interrupt routine is executing.
9061 static void igb_netpoll(struct net_device
*netdev
)
9063 struct igb_adapter
*adapter
= netdev_priv(netdev
);
9064 struct e1000_hw
*hw
= &adapter
->hw
;
9065 struct igb_q_vector
*q_vector
;
9068 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
9069 q_vector
= adapter
->q_vector
[i
];
9070 if (adapter
->flags
& IGB_FLAG_HAS_MSIX
)
9071 wr32(E1000_EIMC
, q_vector
->eims_value
);
9073 igb_irq_disable(adapter
);
9074 napi_schedule(&q_vector
->napi
);
9077 #endif /* CONFIG_NET_POLL_CONTROLLER */
9080 * igb_io_error_detected - called when PCI error is detected
9081 * @pdev: Pointer to PCI device
9082 * @state: The current pci connection state
9084 * This function is called after a PCI bus error affecting
9085 * this device has been detected.
9087 static pci_ers_result_t
igb_io_error_detected(struct pci_dev
*pdev
,
9088 pci_channel_state_t state
)
9090 struct net_device
*netdev
= pci_get_drvdata(pdev
);
9091 struct igb_adapter
*adapter
= netdev_priv(netdev
);
9093 netif_device_detach(netdev
);
9095 if (state
== pci_channel_io_perm_failure
)
9096 return PCI_ERS_RESULT_DISCONNECT
;
9098 if (netif_running(netdev
))
9100 pci_disable_device(pdev
);
9102 /* Request a slot slot reset. */
9103 return PCI_ERS_RESULT_NEED_RESET
;
9107 * igb_io_slot_reset - called after the pci bus has been reset.
9108 * @pdev: Pointer to PCI device
9110 * Restart the card from scratch, as if from a cold-boot. Implementation
9111 * resembles the first-half of the igb_resume routine.
9113 static pci_ers_result_t
igb_io_slot_reset(struct pci_dev
*pdev
)
9115 struct net_device
*netdev
= pci_get_drvdata(pdev
);
9116 struct igb_adapter
*adapter
= netdev_priv(netdev
);
9117 struct e1000_hw
*hw
= &adapter
->hw
;
9118 pci_ers_result_t result
;
9121 if (pci_enable_device_mem(pdev
)) {
9123 "Cannot re-enable PCI device after reset.\n");
9124 result
= PCI_ERS_RESULT_DISCONNECT
;
9126 pci_set_master(pdev
);
9127 pci_restore_state(pdev
);
9128 pci_save_state(pdev
);
9130 pci_enable_wake(pdev
, PCI_D3hot
, 0);
9131 pci_enable_wake(pdev
, PCI_D3cold
, 0);
9133 /* In case of PCI error, adapter lose its HW address
9134 * so we should re-assign it here.
9136 hw
->hw_addr
= adapter
->io_addr
;
9139 wr32(E1000_WUS
, ~0);
9140 result
= PCI_ERS_RESULT_RECOVERED
;
9143 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
9146 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9148 /* non-fatal, continue */
9155 * igb_io_resume - called when traffic can start flowing again.
9156 * @pdev: Pointer to PCI device
9158 * This callback is called when the error recovery driver tells us that
9159 * its OK to resume normal operation. Implementation resembles the
9160 * second-half of the igb_resume routine.
9162 static void igb_io_resume(struct pci_dev
*pdev
)
9164 struct net_device
*netdev
= pci_get_drvdata(pdev
);
9165 struct igb_adapter
*adapter
= netdev_priv(netdev
);
9167 if (netif_running(netdev
)) {
9168 if (igb_up(adapter
)) {
9169 dev_err(&pdev
->dev
, "igb_up failed after reset\n");
9174 netif_device_attach(netdev
);
9176 /* let the f/w know that the h/w is now under the control of the
9179 igb_get_hw_control(adapter
);
9183 * igb_rar_set_index - Sync RAL[index] and RAH[index] registers with MAC table
9184 * @adapter: Pointer to adapter structure
9185 * @index: Index of the RAR entry which need to be synced with MAC table
9187 static void igb_rar_set_index(struct igb_adapter
*adapter
, u32 index
)
9189 struct e1000_hw
*hw
= &adapter
->hw
;
9190 u32 rar_low
, rar_high
;
9191 u8
*addr
= adapter
->mac_table
[index
].addr
;
9193 /* HW expects these to be in network order when they are plugged
9194 * into the registers which are little endian. In order to guarantee
9195 * that ordering we need to do an leXX_to_cpup here in order to be
9196 * ready for the byteswap that occurs with writel
9198 rar_low
= le32_to_cpup((__le32
*)(addr
));
9199 rar_high
= le16_to_cpup((__le16
*)(addr
+ 4));
9201 /* Indicate to hardware the Address is Valid. */
9202 if (adapter
->mac_table
[index
].state
& IGB_MAC_STATE_IN_USE
) {
9203 if (is_valid_ether_addr(addr
))
9204 rar_high
|= E1000_RAH_AV
;
9206 if (adapter
->mac_table
[index
].state
& IGB_MAC_STATE_SRC_ADDR
)
9207 rar_high
|= E1000_RAH_ASEL_SRC_ADDR
;
9209 switch (hw
->mac
.type
) {
9212 if (adapter
->mac_table
[index
].state
&
9213 IGB_MAC_STATE_QUEUE_STEERING
)
9214 rar_high
|= E1000_RAH_QSEL_ENABLE
;
9216 rar_high
|= E1000_RAH_POOL_1
*
9217 adapter
->mac_table
[index
].queue
;
9220 rar_high
|= E1000_RAH_POOL_1
<<
9221 adapter
->mac_table
[index
].queue
;
9226 wr32(E1000_RAL(index
), rar_low
);
9228 wr32(E1000_RAH(index
), rar_high
);
9232 static int igb_set_vf_mac(struct igb_adapter
*adapter
,
9233 int vf
, unsigned char *mac_addr
)
9235 struct e1000_hw
*hw
= &adapter
->hw
;
9236 /* VF MAC addresses start at end of receive addresses and moves
9237 * towards the first, as a result a collision should not be possible
9239 int rar_entry
= hw
->mac
.rar_entry_count
- (vf
+ 1);
9240 unsigned char *vf_mac_addr
= adapter
->vf_data
[vf
].vf_mac_addresses
;
9242 ether_addr_copy(vf_mac_addr
, mac_addr
);
9243 ether_addr_copy(adapter
->mac_table
[rar_entry
].addr
, mac_addr
);
9244 adapter
->mac_table
[rar_entry
].queue
= vf
;
9245 adapter
->mac_table
[rar_entry
].state
|= IGB_MAC_STATE_IN_USE
;
9246 igb_rar_set_index(adapter
, rar_entry
);
9251 static int igb_ndo_set_vf_mac(struct net_device
*netdev
, int vf
, u8
*mac
)
9253 struct igb_adapter
*adapter
= netdev_priv(netdev
);
9255 if (vf
>= adapter
->vfs_allocated_count
)
9258 /* Setting the VF MAC to 0 reverts the IGB_VF_FLAG_PF_SET_MAC
9259 * flag and allows to overwrite the MAC via VF netdev. This
9260 * is necessary to allow libvirt a way to restore the original
9261 * MAC after unbinding vfio-pci and reloading igbvf after shutting
9264 if (is_zero_ether_addr(mac
)) {
9265 adapter
->vf_data
[vf
].flags
&= ~IGB_VF_FLAG_PF_SET_MAC
;
9266 dev_info(&adapter
->pdev
->dev
,
9267 "remove administratively set MAC on VF %d\n",
9269 } else if (is_valid_ether_addr(mac
)) {
9270 adapter
->vf_data
[vf
].flags
|= IGB_VF_FLAG_PF_SET_MAC
;
9271 dev_info(&adapter
->pdev
->dev
, "setting MAC %pM on VF %d\n",
9273 dev_info(&adapter
->pdev
->dev
,
9274 "Reload the VF driver to make this change effective.");
9275 /* Generate additional warning if PF is down */
9276 if (test_bit(__IGB_DOWN
, &adapter
->state
)) {
9277 dev_warn(&adapter
->pdev
->dev
,
9278 "The VF MAC address has been set, but the PF device is not up.\n");
9279 dev_warn(&adapter
->pdev
->dev
,
9280 "Bring the PF device up before attempting to use the VF device.\n");
9285 return igb_set_vf_mac(adapter
, vf
, mac
);
9288 static int igb_link_mbps(int internal_link_speed
)
9290 switch (internal_link_speed
) {
9300 static void igb_set_vf_rate_limit(struct e1000_hw
*hw
, int vf
, int tx_rate
,
9307 /* Calculate the rate factor values to set */
9308 rf_int
= link_speed
/ tx_rate
;
9309 rf_dec
= (link_speed
- (rf_int
* tx_rate
));
9310 rf_dec
= (rf_dec
* BIT(E1000_RTTBCNRC_RF_INT_SHIFT
)) /
9313 bcnrc_val
= E1000_RTTBCNRC_RS_ENA
;
9314 bcnrc_val
|= ((rf_int
<< E1000_RTTBCNRC_RF_INT_SHIFT
) &
9315 E1000_RTTBCNRC_RF_INT_MASK
);
9316 bcnrc_val
|= (rf_dec
& E1000_RTTBCNRC_RF_DEC_MASK
);
9321 wr32(E1000_RTTDQSEL
, vf
); /* vf X uses queue X */
9322 /* Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
9323 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported.
9325 wr32(E1000_RTTBCNRM
, 0x14);
9326 wr32(E1000_RTTBCNRC
, bcnrc_val
);
9329 static void igb_check_vf_rate_limit(struct igb_adapter
*adapter
)
9331 int actual_link_speed
, i
;
9332 bool reset_rate
= false;
9334 /* VF TX rate limit was not set or not supported */
9335 if ((adapter
->vf_rate_link_speed
== 0) ||
9336 (adapter
->hw
.mac
.type
!= e1000_82576
))
9339 actual_link_speed
= igb_link_mbps(adapter
->link_speed
);
9340 if (actual_link_speed
!= adapter
->vf_rate_link_speed
) {
9342 adapter
->vf_rate_link_speed
= 0;
9343 dev_info(&adapter
->pdev
->dev
,
9344 "Link speed has been changed. VF Transmit rate is disabled\n");
9347 for (i
= 0; i
< adapter
->vfs_allocated_count
; i
++) {
9349 adapter
->vf_data
[i
].tx_rate
= 0;
9351 igb_set_vf_rate_limit(&adapter
->hw
, i
,
9352 adapter
->vf_data
[i
].tx_rate
,
9357 static int igb_ndo_set_vf_bw(struct net_device
*netdev
, int vf
,
9358 int min_tx_rate
, int max_tx_rate
)
9360 struct igb_adapter
*adapter
= netdev_priv(netdev
);
9361 struct e1000_hw
*hw
= &adapter
->hw
;
9362 int actual_link_speed
;
9364 if (hw
->mac
.type
!= e1000_82576
)
9370 actual_link_speed
= igb_link_mbps(adapter
->link_speed
);
9371 if ((vf
>= adapter
->vfs_allocated_count
) ||
9372 (!(rd32(E1000_STATUS
) & E1000_STATUS_LU
)) ||
9373 (max_tx_rate
< 0) ||
9374 (max_tx_rate
> actual_link_speed
))
9377 adapter
->vf_rate_link_speed
= actual_link_speed
;
9378 adapter
->vf_data
[vf
].tx_rate
= (u16
)max_tx_rate
;
9379 igb_set_vf_rate_limit(hw
, vf
, max_tx_rate
, actual_link_speed
);
9384 static int igb_ndo_set_vf_spoofchk(struct net_device
*netdev
, int vf
,
9387 struct igb_adapter
*adapter
= netdev_priv(netdev
);
9388 struct e1000_hw
*hw
= &adapter
->hw
;
9389 u32 reg_val
, reg_offset
;
9391 if (!adapter
->vfs_allocated_count
)
9394 if (vf
>= adapter
->vfs_allocated_count
)
9397 reg_offset
= (hw
->mac
.type
== e1000_82576
) ? E1000_DTXSWC
: E1000_TXSWC
;
9398 reg_val
= rd32(reg_offset
);
9400 reg_val
|= (BIT(vf
) |
9401 BIT(vf
+ E1000_DTXSWC_VLAN_SPOOF_SHIFT
));
9403 reg_val
&= ~(BIT(vf
) |
9404 BIT(vf
+ E1000_DTXSWC_VLAN_SPOOF_SHIFT
));
9405 wr32(reg_offset
, reg_val
);
9407 adapter
->vf_data
[vf
].spoofchk_enabled
= setting
;
9411 static int igb_ndo_set_vf_trust(struct net_device
*netdev
, int vf
, bool setting
)
9413 struct igb_adapter
*adapter
= netdev_priv(netdev
);
9415 if (vf
>= adapter
->vfs_allocated_count
)
9417 if (adapter
->vf_data
[vf
].trusted
== setting
)
9420 adapter
->vf_data
[vf
].trusted
= setting
;
9422 dev_info(&adapter
->pdev
->dev
, "VF %u is %strusted\n",
9423 vf
, setting
? "" : "not ");
9427 static int igb_ndo_get_vf_config(struct net_device
*netdev
,
9428 int vf
, struct ifla_vf_info
*ivi
)
9430 struct igb_adapter
*adapter
= netdev_priv(netdev
);
9431 if (vf
>= adapter
->vfs_allocated_count
)
9434 memcpy(&ivi
->mac
, adapter
->vf_data
[vf
].vf_mac_addresses
, ETH_ALEN
);
9435 ivi
->max_tx_rate
= adapter
->vf_data
[vf
].tx_rate
;
9436 ivi
->min_tx_rate
= 0;
9437 ivi
->vlan
= adapter
->vf_data
[vf
].pf_vlan
;
9438 ivi
->qos
= adapter
->vf_data
[vf
].pf_qos
;
9439 ivi
->spoofchk
= adapter
->vf_data
[vf
].spoofchk_enabled
;
9440 ivi
->trusted
= adapter
->vf_data
[vf
].trusted
;
9444 static void igb_vmm_control(struct igb_adapter
*adapter
)
9446 struct e1000_hw
*hw
= &adapter
->hw
;
9449 switch (hw
->mac
.type
) {
9455 /* replication is not supported for 82575 */
9458 /* notify HW that the MAC is adding vlan tags */
9459 reg
= rd32(E1000_DTXCTL
);
9460 reg
|= E1000_DTXCTL_VLAN_ADDED
;
9461 wr32(E1000_DTXCTL
, reg
);
9464 /* enable replication vlan tag stripping */
9465 reg
= rd32(E1000_RPLOLR
);
9466 reg
|= E1000_RPLOLR_STRVLAN
;
9467 wr32(E1000_RPLOLR
, reg
);
9470 /* none of the above registers are supported by i350 */
9474 if (adapter
->vfs_allocated_count
) {
9475 igb_vmdq_set_loopback_pf(hw
, true);
9476 igb_vmdq_set_replication_pf(hw
, true);
9477 igb_vmdq_set_anti_spoofing_pf(hw
, true,
9478 adapter
->vfs_allocated_count
);
9480 igb_vmdq_set_loopback_pf(hw
, false);
9481 igb_vmdq_set_replication_pf(hw
, false);
9485 static void igb_init_dmac(struct igb_adapter
*adapter
, u32 pba
)
9487 struct e1000_hw
*hw
= &adapter
->hw
;
9491 if (hw
->mac
.type
> e1000_82580
) {
9492 if (adapter
->flags
& IGB_FLAG_DMAC
) {
9495 /* force threshold to 0. */
9496 wr32(E1000_DMCTXTH
, 0);
9498 /* DMA Coalescing high water mark needs to be greater
9499 * than the Rx threshold. Set hwm to PBA - max frame
9500 * size in 16B units, capping it at PBA - 6KB.
9502 hwm
= 64 * (pba
- 6);
9503 reg
= rd32(E1000_FCRTC
);
9504 reg
&= ~E1000_FCRTC_RTH_COAL_MASK
;
9505 reg
|= ((hwm
<< E1000_FCRTC_RTH_COAL_SHIFT
)
9506 & E1000_FCRTC_RTH_COAL_MASK
);
9507 wr32(E1000_FCRTC
, reg
);
9509 /* Set the DMA Coalescing Rx threshold to PBA - 2 * max
9510 * frame size, capping it at PBA - 10KB.
9512 dmac_thr
= pba
- 10;
9513 reg
= rd32(E1000_DMACR
);
9514 reg
&= ~E1000_DMACR_DMACTHR_MASK
;
9515 reg
|= ((dmac_thr
<< E1000_DMACR_DMACTHR_SHIFT
)
9516 & E1000_DMACR_DMACTHR_MASK
);
9518 /* transition to L0x or L1 if available..*/
9519 reg
|= (E1000_DMACR_DMAC_EN
| E1000_DMACR_DMAC_LX_MASK
);
9521 /* watchdog timer= +-1000 usec in 32usec intervals */
9524 /* Disable BMC-to-OS Watchdog Enable */
9525 if (hw
->mac
.type
!= e1000_i354
)
9526 reg
&= ~E1000_DMACR_DC_BMC2OSW_EN
;
9528 wr32(E1000_DMACR
, reg
);
9530 /* no lower threshold to disable
9531 * coalescing(smart fifb)-UTRESH=0
9533 wr32(E1000_DMCRTRH
, 0);
9535 reg
= (IGB_DMCTLX_DCFLUSH_DIS
| 0x4);
9537 wr32(E1000_DMCTLX
, reg
);
9539 /* free space in tx packet buffer to wake from
9542 wr32(E1000_DMCTXTH
, (IGB_MIN_TXPBSIZE
-
9543 (IGB_TX_BUF_4096
+ adapter
->max_frame_size
)) >> 6);
9545 /* make low power state decision controlled
9548 reg
= rd32(E1000_PCIEMISC
);
9549 reg
&= ~E1000_PCIEMISC_LX_DECISION
;
9550 wr32(E1000_PCIEMISC
, reg
);
9551 } /* endif adapter->dmac is not disabled */
9552 } else if (hw
->mac
.type
== e1000_82580
) {
9553 u32 reg
= rd32(E1000_PCIEMISC
);
9555 wr32(E1000_PCIEMISC
, reg
& ~E1000_PCIEMISC_LX_DECISION
);
9556 wr32(E1000_DMACR
, 0);
9561 * igb_read_i2c_byte - Reads 8 bit word over I2C
9562 * @hw: pointer to hardware structure
9563 * @byte_offset: byte offset to read
9564 * @dev_addr: device address
9567 * Performs byte read operation over I2C interface at
9568 * a specified device address.
9570 s32
igb_read_i2c_byte(struct e1000_hw
*hw
, u8 byte_offset
,
9571 u8 dev_addr
, u8
*data
)
9573 struct igb_adapter
*adapter
= container_of(hw
, struct igb_adapter
, hw
);
9574 struct i2c_client
*this_client
= adapter
->i2c_client
;
9579 return E1000_ERR_I2C
;
9581 swfw_mask
= E1000_SWFW_PHY0_SM
;
9583 if (hw
->mac
.ops
.acquire_swfw_sync(hw
, swfw_mask
))
9584 return E1000_ERR_SWFW_SYNC
;
9586 status
= i2c_smbus_read_byte_data(this_client
, byte_offset
);
9587 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
9590 return E1000_ERR_I2C
;
9598 * igb_write_i2c_byte - Writes 8 bit word over I2C
9599 * @hw: pointer to hardware structure
9600 * @byte_offset: byte offset to write
9601 * @dev_addr: device address
9602 * @data: value to write
9604 * Performs byte write operation over I2C interface at
9605 * a specified device address.
9607 s32
igb_write_i2c_byte(struct e1000_hw
*hw
, u8 byte_offset
,
9608 u8 dev_addr
, u8 data
)
9610 struct igb_adapter
*adapter
= container_of(hw
, struct igb_adapter
, hw
);
9611 struct i2c_client
*this_client
= adapter
->i2c_client
;
9613 u16 swfw_mask
= E1000_SWFW_PHY0_SM
;
9616 return E1000_ERR_I2C
;
9618 if (hw
->mac
.ops
.acquire_swfw_sync(hw
, swfw_mask
))
9619 return E1000_ERR_SWFW_SYNC
;
9620 status
= i2c_smbus_write_byte_data(this_client
, byte_offset
, data
);
9621 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
9624 return E1000_ERR_I2C
;
9630 int igb_reinit_queues(struct igb_adapter
*adapter
)
9632 struct net_device
*netdev
= adapter
->netdev
;
9633 struct pci_dev
*pdev
= adapter
->pdev
;
9636 if (netif_running(netdev
))
9639 igb_reset_interrupt_capability(adapter
);
9641 if (igb_init_interrupt_scheme(adapter
, true)) {
9642 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
9646 if (netif_running(netdev
))
9647 err
= igb_open(netdev
);
9652 static void igb_nfc_filter_exit(struct igb_adapter
*adapter
)
9654 struct igb_nfc_filter
*rule
;
9656 spin_lock(&adapter
->nfc_lock
);
9658 hlist_for_each_entry(rule
, &adapter
->nfc_filter_list
, nfc_node
)
9659 igb_erase_filter(adapter
, rule
);
9661 hlist_for_each_entry(rule
, &adapter
->cls_flower_list
, nfc_node
)
9662 igb_erase_filter(adapter
, rule
);
9664 spin_unlock(&adapter
->nfc_lock
);
9667 static void igb_nfc_filter_restore(struct igb_adapter
*adapter
)
9669 struct igb_nfc_filter
*rule
;
9671 spin_lock(&adapter
->nfc_lock
);
9673 hlist_for_each_entry(rule
, &adapter
->nfc_filter_list
, nfc_node
)
9674 igb_add_filter(adapter
, rule
);
9676 spin_unlock(&adapter
->nfc_lock
);