]>
Commit | Line | Data |
---|---|---|
ae06c70b | 1 | // SPDX-License-Identifier: GPL-2.0 |
51dce24b | 2 | /* Copyright(c) 1999 - 2018 Intel Corporation. */ |
bc7f75fa | 3 | |
8544b9f7 BA |
4 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
5 | ||
bc7f75fa AK |
6 | #include <linux/module.h> |
7 | #include <linux/types.h> | |
8 | #include <linux/init.h> | |
9 | #include <linux/pci.h> | |
10 | #include <linux/vmalloc.h> | |
11 | #include <linux/pagemap.h> | |
12 | #include <linux/delay.h> | |
13 | #include <linux/netdevice.h> | |
9fb7a5f7 | 14 | #include <linux/interrupt.h> |
bc7f75fa AK |
15 | #include <linux/tcp.h> |
16 | #include <linux/ipv6.h> | |
5a0e3ad6 | 17 | #include <linux/slab.h> |
bc7f75fa AK |
18 | #include <net/checksum.h> |
19 | #include <net/ip6_checksum.h> | |
bc7f75fa AK |
20 | #include <linux/ethtool.h> |
21 | #include <linux/if_vlan.h> | |
22 | #include <linux/cpu.h> | |
23 | #include <linux/smp.h> | |
e8db0be1 | 24 | #include <linux/pm_qos.h> |
23606cf5 | 25 | #include <linux/pm_runtime.h> |
111b9dc5 | 26 | #include <linux/aer.h> |
70c71606 | 27 | #include <linux/prefetch.h> |
bc7f75fa AK |
28 | |
29 | #include "e1000.h" | |
30 | ||
b3ccf267 | 31 | #define DRV_EXTRAVERSION "-k" |
c14c643b | 32 | |
d2d7d4e4 | 33 | #define DRV_VERSION "3.2.6" DRV_EXTRAVERSION |
bc7f75fa AK |
34 | char e1000e_driver_name[] = "e1000e"; |
35 | const char e1000e_driver_version[] = DRV_VERSION; | |
36 | ||
b3f4d599 | 37 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
38 | static int debug = -1; | |
39 | module_param(debug, int, 0); | |
40 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); | |
41 | ||
bc7f75fa AK |
42 | static const struct e1000_info *e1000_info_tbl[] = { |
43 | [board_82571] = &e1000_82571_info, | |
44 | [board_82572] = &e1000_82572_info, | |
45 | [board_82573] = &e1000_82573_info, | |
4662e82b | 46 | [board_82574] = &e1000_82574_info, |
8c81c9c3 | 47 | [board_82583] = &e1000_82583_info, |
bc7f75fa AK |
48 | [board_80003es2lan] = &e1000_es2_info, |
49 | [board_ich8lan] = &e1000_ich8_info, | |
50 | [board_ich9lan] = &e1000_ich9_info, | |
f4187b56 | 51 | [board_ich10lan] = &e1000_ich10_info, |
a4f58f54 | 52 | [board_pchlan] = &e1000_pch_info, |
d3738bb8 | 53 | [board_pch2lan] = &e1000_pch2_info, |
2fbe4526 | 54 | [board_pch_lpt] = &e1000_pch_lpt_info, |
79849ebc | 55 | [board_pch_spt] = &e1000_pch_spt_info, |
3a3173b9 | 56 | [board_pch_cnp] = &e1000_pch_cnp_info, |
bc7f75fa AK |
57 | }; |
58 | ||
84f4ee90 TI |
59 | struct e1000_reg_info { |
60 | u32 ofs; | |
61 | char *name; | |
62 | }; | |
63 | ||
84f4ee90 | 64 | static const struct e1000_reg_info e1000_reg_info_tbl[] = { |
84f4ee90 TI |
65 | /* General Registers */ |
66 | {E1000_CTRL, "CTRL"}, | |
67 | {E1000_STATUS, "STATUS"}, | |
68 | {E1000_CTRL_EXT, "CTRL_EXT"}, | |
69 | ||
70 | /* Interrupt Registers */ | |
71 | {E1000_ICR, "ICR"}, | |
72 | ||
af667a29 | 73 | /* Rx Registers */ |
84f4ee90 | 74 | {E1000_RCTL, "RCTL"}, |
1e36052e BA |
75 | {E1000_RDLEN(0), "RDLEN"}, |
76 | {E1000_RDH(0), "RDH"}, | |
77 | {E1000_RDT(0), "RDT"}, | |
84f4ee90 TI |
78 | {E1000_RDTR, "RDTR"}, |
79 | {E1000_RXDCTL(0), "RXDCTL"}, | |
80 | {E1000_ERT, "ERT"}, | |
1e36052e BA |
81 | {E1000_RDBAL(0), "RDBAL"}, |
82 | {E1000_RDBAH(0), "RDBAH"}, | |
84f4ee90 TI |
83 | {E1000_RDFH, "RDFH"}, |
84 | {E1000_RDFT, "RDFT"}, | |
85 | {E1000_RDFHS, "RDFHS"}, | |
86 | {E1000_RDFTS, "RDFTS"}, | |
87 | {E1000_RDFPC, "RDFPC"}, | |
88 | ||
af667a29 | 89 | /* Tx Registers */ |
84f4ee90 | 90 | {E1000_TCTL, "TCTL"}, |
1e36052e BA |
91 | {E1000_TDBAL(0), "TDBAL"}, |
92 | {E1000_TDBAH(0), "TDBAH"}, | |
93 | {E1000_TDLEN(0), "TDLEN"}, | |
94 | {E1000_TDH(0), "TDH"}, | |
95 | {E1000_TDT(0), "TDT"}, | |
84f4ee90 TI |
96 | {E1000_TIDV, "TIDV"}, |
97 | {E1000_TXDCTL(0), "TXDCTL"}, | |
98 | {E1000_TADV, "TADV"}, | |
99 | {E1000_TARC(0), "TARC"}, | |
100 | {E1000_TDFH, "TDFH"}, | |
101 | {E1000_TDFT, "TDFT"}, | |
102 | {E1000_TDFHS, "TDFHS"}, | |
103 | {E1000_TDFTS, "TDFTS"}, | |
104 | {E1000_TDFPC, "TDFPC"}, | |
105 | ||
106 | /* List Terminator */ | |
f36bb6ca | 107 | {0, NULL} |
84f4ee90 TI |
108 | }; |
109 | ||
c6f3148c AK |
110 | /** |
111 | * __ew32_prepare - prepare to write to MAC CSR register on certain parts | |
112 | * @hw: pointer to the HW structure | |
113 | * | |
114 | * When updating the MAC CSR registers, the Manageability Engine (ME) could | |
115 | * be accessing the registers at the same time. Normally, this is handled in | |
116 | * h/w by an arbiter but on some parts there is a bug that acknowledges Host | |
117 | * accesses later than it should which could result in the register to have | |
118 | * an incorrect value. Workaround this by checking the FWSM register which | |
119 | * has bit 24 set while ME is accessing MAC CSR registers, wait if it is set | |
120 | * and try again a number of times. | |
121 | **/ | |
d0150186 | 122 | static void __ew32_prepare(struct e1000_hw *hw) |
c6f3148c AK |
123 | { |
124 | s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT; | |
125 | ||
126 | while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i) | |
127 | udelay(50); | |
c6f3148c AK |
128 | } |
129 | ||
130 | void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val) | |
131 | { | |
132 | if (hw->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) | |
133 | __ew32_prepare(hw); | |
134 | ||
135 | writel(val, hw->hw_addr + reg); | |
136 | } | |
137 | ||
e921eb1a | 138 | /** |
84f4ee90 | 139 | * e1000_regdump - register printout routine |
e921eb1a BA |
140 | * @hw: pointer to the HW structure |
141 | * @reginfo: pointer to the register info table | |
142 | **/ | |
84f4ee90 TI |
143 | static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo) |
144 | { | |
145 | int n = 0; | |
146 | char rname[16]; | |
147 | u32 regs[8]; | |
148 | ||
149 | switch (reginfo->ofs) { | |
150 | case E1000_RXDCTL(0): | |
151 | for (n = 0; n < 2; n++) | |
152 | regs[n] = __er32(hw, E1000_RXDCTL(n)); | |
153 | break; | |
154 | case E1000_TXDCTL(0): | |
155 | for (n = 0; n < 2; n++) | |
156 | regs[n] = __er32(hw, E1000_TXDCTL(n)); | |
157 | break; | |
158 | case E1000_TARC(0): | |
159 | for (n = 0; n < 2; n++) | |
160 | regs[n] = __er32(hw, E1000_TARC(n)); | |
161 | break; | |
162 | default: | |
ef456f85 JK |
163 | pr_info("%-15s %08x\n", |
164 | reginfo->name, __er32(hw, reginfo->ofs)); | |
84f4ee90 TI |
165 | return; |
166 | } | |
167 | ||
168 | snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]"); | |
ef456f85 | 169 | pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]); |
84f4ee90 TI |
170 | } |
171 | ||
f0c5dadf ET |
172 | static void e1000e_dump_ps_pages(struct e1000_adapter *adapter, |
173 | struct e1000_buffer *bi) | |
174 | { | |
175 | int i; | |
176 | struct e1000_ps_page *ps_page; | |
177 | ||
178 | for (i = 0; i < adapter->rx_ps_pages; i++) { | |
179 | ps_page = &bi->ps_pages[i]; | |
180 | ||
181 | if (ps_page->page) { | |
182 | pr_info("packet dump for ps_page %d:\n", i); | |
183 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, | |
184 | 16, 1, page_address(ps_page->page), | |
185 | PAGE_SIZE, true); | |
186 | } | |
187 | } | |
188 | } | |
189 | ||
e921eb1a | 190 | /** |
af667a29 | 191 | * e1000e_dump - Print registers, Tx-ring and Rx-ring |
e921eb1a BA |
192 | * @adapter: board private structure |
193 | **/ | |
84f4ee90 TI |
194 | static void e1000e_dump(struct e1000_adapter *adapter) |
195 | { | |
196 | struct net_device *netdev = adapter->netdev; | |
197 | struct e1000_hw *hw = &adapter->hw; | |
198 | struct e1000_reg_info *reginfo; | |
199 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
200 | struct e1000_tx_desc *tx_desc; | |
af667a29 | 201 | struct my_u0 { |
e885d762 BA |
202 | __le64 a; |
203 | __le64 b; | |
af667a29 | 204 | } *u0; |
84f4ee90 TI |
205 | struct e1000_buffer *buffer_info; |
206 | struct e1000_ring *rx_ring = adapter->rx_ring; | |
207 | union e1000_rx_desc_packet_split *rx_desc_ps; | |
5f450212 | 208 | union e1000_rx_desc_extended *rx_desc; |
af667a29 | 209 | struct my_u1 { |
e885d762 BA |
210 | __le64 a; |
211 | __le64 b; | |
212 | __le64 c; | |
213 | __le64 d; | |
af667a29 | 214 | } *u1; |
84f4ee90 TI |
215 | u32 staterr; |
216 | int i = 0; | |
217 | ||
218 | if (!netif_msg_hw(adapter)) | |
219 | return; | |
220 | ||
221 | /* Print netdevice Info */ | |
222 | if (netdev) { | |
223 | dev_info(&adapter->pdev->dev, "Net device Info\n"); | |
4a7c9726 TK |
224 | pr_info("Device Name state trans_start\n"); |
225 | pr_info("%-15s %016lX %016lX\n", netdev->name, | |
226 | netdev->state, dev_trans_start(netdev)); | |
84f4ee90 TI |
227 | } |
228 | ||
229 | /* Print Registers */ | |
230 | dev_info(&adapter->pdev->dev, "Register Dump\n"); | |
ef456f85 | 231 | pr_info(" Register Name Value\n"); |
84f4ee90 TI |
232 | for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl; |
233 | reginfo->name; reginfo++) { | |
234 | e1000_regdump(hw, reginfo); | |
235 | } | |
236 | ||
af667a29 | 237 | /* Print Tx Ring Summary */ |
84f4ee90 | 238 | if (!netdev || !netif_running(netdev)) |
fe1e980f | 239 | return; |
84f4ee90 | 240 | |
af667a29 | 241 | dev_info(&adapter->pdev->dev, "Tx Ring Summary\n"); |
ef456f85 | 242 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); |
84f4ee90 | 243 | buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean]; |
ef456f85 JK |
244 | pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n", |
245 | 0, tx_ring->next_to_use, tx_ring->next_to_clean, | |
246 | (unsigned long long)buffer_info->dma, | |
247 | buffer_info->length, | |
248 | buffer_info->next_to_watch, | |
249 | (unsigned long long)buffer_info->time_stamp); | |
84f4ee90 | 250 | |
af667a29 | 251 | /* Print Tx Ring */ |
84f4ee90 TI |
252 | if (!netif_msg_tx_done(adapter)) |
253 | goto rx_ring_summary; | |
254 | ||
af667a29 | 255 | dev_info(&adapter->pdev->dev, "Tx Ring Dump\n"); |
84f4ee90 TI |
256 | |
257 | /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended) | |
258 | * | |
259 | * Legacy Transmit Descriptor | |
260 | * +--------------------------------------------------------------+ | |
261 | * 0 | Buffer Address [63:0] (Reserved on Write Back) | | |
262 | * +--------------------------------------------------------------+ | |
263 | * 8 | Special | CSS | Status | CMD | CSO | Length | | |
264 | * +--------------------------------------------------------------+ | |
265 | * 63 48 47 36 35 32 31 24 23 16 15 0 | |
266 | * | |
267 | * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload | |
268 | * 63 48 47 40 39 32 31 16 15 8 7 0 | |
269 | * +----------------------------------------------------------------+ | |
270 | * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS | | |
271 | * +----------------------------------------------------------------+ | |
272 | * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN | | |
273 | * +----------------------------------------------------------------+ | |
274 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 | |
275 | * | |
276 | * Extended Data Descriptor (DTYP=0x1) | |
277 | * +----------------------------------------------------------------+ | |
278 | * 0 | Buffer Address [63:0] | | |
279 | * +----------------------------------------------------------------+ | |
280 | * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN | | |
281 | * +----------------------------------------------------------------+ | |
282 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 | |
283 | */ | |
ef456f85 JK |
284 | pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n"); |
285 | pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n"); | |
286 | pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n"); | |
84f4ee90 | 287 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
ef456f85 | 288 | const char *next_desc; |
84f4ee90 TI |
289 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
290 | buffer_info = &tx_ring->buffer_info[i]; | |
291 | u0 = (struct my_u0 *)tx_desc; | |
84f4ee90 | 292 | if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean) |
ef456f85 | 293 | next_desc = " NTC/U"; |
84f4ee90 | 294 | else if (i == tx_ring->next_to_use) |
ef456f85 | 295 | next_desc = " NTU"; |
84f4ee90 | 296 | else if (i == tx_ring->next_to_clean) |
ef456f85 | 297 | next_desc = " NTC"; |
84f4ee90 | 298 | else |
ef456f85 JK |
299 | next_desc = ""; |
300 | pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n", | |
18dd2392 JK |
301 | (!(le64_to_cpu(u0->b) & BIT(29)) ? 'l' : |
302 | ((le64_to_cpu(u0->b) & BIT(20)) ? 'd' : 'c')), | |
ef456f85 JK |
303 | i, |
304 | (unsigned long long)le64_to_cpu(u0->a), | |
305 | (unsigned long long)le64_to_cpu(u0->b), | |
306 | (unsigned long long)buffer_info->dma, | |
307 | buffer_info->length, buffer_info->next_to_watch, | |
308 | (unsigned long long)buffer_info->time_stamp, | |
309 | buffer_info->skb, next_desc); | |
84f4ee90 | 310 | |
f0c5dadf | 311 | if (netif_msg_pktdata(adapter) && buffer_info->skb) |
84f4ee90 | 312 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, |
f0c5dadf ET |
313 | 16, 1, buffer_info->skb->data, |
314 | buffer_info->skb->len, true); | |
84f4ee90 TI |
315 | } |
316 | ||
af667a29 | 317 | /* Print Rx Ring Summary */ |
84f4ee90 | 318 | rx_ring_summary: |
af667a29 | 319 | dev_info(&adapter->pdev->dev, "Rx Ring Summary\n"); |
ef456f85 JK |
320 | pr_info("Queue [NTU] [NTC]\n"); |
321 | pr_info(" %5d %5X %5X\n", | |
322 | 0, rx_ring->next_to_use, rx_ring->next_to_clean); | |
84f4ee90 | 323 | |
af667a29 | 324 | /* Print Rx Ring */ |
84f4ee90 | 325 | if (!netif_msg_rx_status(adapter)) |
fe1e980f | 326 | return; |
84f4ee90 | 327 | |
af667a29 | 328 | dev_info(&adapter->pdev->dev, "Rx Ring Dump\n"); |
84f4ee90 TI |
329 | switch (adapter->rx_ps_pages) { |
330 | case 1: | |
331 | case 2: | |
332 | case 3: | |
333 | /* [Extended] Packet Split Receive Descriptor Format | |
334 | * | |
335 | * +-----------------------------------------------------+ | |
336 | * 0 | Buffer Address 0 [63:0] | | |
337 | * +-----------------------------------------------------+ | |
338 | * 8 | Buffer Address 1 [63:0] | | |
339 | * +-----------------------------------------------------+ | |
340 | * 16 | Buffer Address 2 [63:0] | | |
341 | * +-----------------------------------------------------+ | |
342 | * 24 | Buffer Address 3 [63:0] | | |
343 | * +-----------------------------------------------------+ | |
344 | */ | |
ef456f85 | 345 | pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n"); |
84f4ee90 TI |
346 | /* [Extended] Receive Descriptor (Write-Back) Format |
347 | * | |
348 | * 63 48 47 32 31 13 12 8 7 4 3 0 | |
349 | * +------------------------------------------------------+ | |
350 | * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS | | |
351 | * | Checksum | Ident | | Queue | | Type | | |
352 | * +------------------------------------------------------+ | |
353 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | | |
354 | * +------------------------------------------------------+ | |
355 | * 63 48 47 32 31 20 19 0 | |
356 | */ | |
ef456f85 | 357 | pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n"); |
84f4ee90 | 358 | for (i = 0; i < rx_ring->count; i++) { |
ef456f85 | 359 | const char *next_desc; |
84f4ee90 TI |
360 | buffer_info = &rx_ring->buffer_info[i]; |
361 | rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i); | |
362 | u1 = (struct my_u1 *)rx_desc_ps; | |
363 | staterr = | |
af667a29 | 364 | le32_to_cpu(rx_desc_ps->wb.middle.status_error); |
ef456f85 JK |
365 | |
366 | if (i == rx_ring->next_to_use) | |
367 | next_desc = " NTU"; | |
368 | else if (i == rx_ring->next_to_clean) | |
369 | next_desc = " NTC"; | |
370 | else | |
371 | next_desc = ""; | |
372 | ||
84f4ee90 TI |
373 | if (staterr & E1000_RXD_STAT_DD) { |
374 | /* Descriptor Done */ | |
ef456f85 JK |
375 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n", |
376 | "RWB", i, | |
377 | (unsigned long long)le64_to_cpu(u1->a), | |
378 | (unsigned long long)le64_to_cpu(u1->b), | |
379 | (unsigned long long)le64_to_cpu(u1->c), | |
380 | (unsigned long long)le64_to_cpu(u1->d), | |
381 | buffer_info->skb, next_desc); | |
84f4ee90 | 382 | } else { |
ef456f85 JK |
383 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n", |
384 | "R ", i, | |
385 | (unsigned long long)le64_to_cpu(u1->a), | |
386 | (unsigned long long)le64_to_cpu(u1->b), | |
387 | (unsigned long long)le64_to_cpu(u1->c), | |
388 | (unsigned long long)le64_to_cpu(u1->d), | |
389 | (unsigned long long)buffer_info->dma, | |
390 | buffer_info->skb, next_desc); | |
84f4ee90 TI |
391 | |
392 | if (netif_msg_pktdata(adapter)) | |
f0c5dadf ET |
393 | e1000e_dump_ps_pages(adapter, |
394 | buffer_info); | |
84f4ee90 | 395 | } |
84f4ee90 TI |
396 | } |
397 | break; | |
398 | default: | |
399 | case 0: | |
5f450212 | 400 | /* Extended Receive Descriptor (Read) Format |
84f4ee90 | 401 | * |
5f450212 BA |
402 | * +-----------------------------------------------------+ |
403 | * 0 | Buffer Address [63:0] | | |
404 | * +-----------------------------------------------------+ | |
405 | * 8 | Reserved | | |
406 | * +-----------------------------------------------------+ | |
84f4ee90 | 407 | */ |
ef456f85 | 408 | pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n"); |
5f450212 BA |
409 | /* Extended Receive Descriptor (Write-Back) Format |
410 | * | |
411 | * 63 48 47 32 31 24 23 4 3 0 | |
412 | * +------------------------------------------------------+ | |
413 | * | RSS Hash | | | | | |
414 | * 0 +-------------------+ Rsvd | Reserved | MRQ RSS | | |
415 | * | Packet | IP | | | Type | | |
416 | * | Checksum | Ident | | | | | |
417 | * +------------------------------------------------------+ | |
418 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | | |
419 | * +------------------------------------------------------+ | |
420 | * 63 48 47 32 31 20 19 0 | |
421 | */ | |
ef456f85 | 422 | pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n"); |
5f450212 BA |
423 | |
424 | for (i = 0; i < rx_ring->count; i++) { | |
ef456f85 JK |
425 | const char *next_desc; |
426 | ||
84f4ee90 | 427 | buffer_info = &rx_ring->buffer_info[i]; |
5f450212 BA |
428 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
429 | u1 = (struct my_u1 *)rx_desc; | |
430 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | |
ef456f85 JK |
431 | |
432 | if (i == rx_ring->next_to_use) | |
433 | next_desc = " NTU"; | |
434 | else if (i == rx_ring->next_to_clean) | |
435 | next_desc = " NTC"; | |
436 | else | |
437 | next_desc = ""; | |
438 | ||
5f450212 BA |
439 | if (staterr & E1000_RXD_STAT_DD) { |
440 | /* Descriptor Done */ | |
ef456f85 JK |
441 | pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n", |
442 | "RWB", i, | |
443 | (unsigned long long)le64_to_cpu(u1->a), | |
444 | (unsigned long long)le64_to_cpu(u1->b), | |
445 | buffer_info->skb, next_desc); | |
5f450212 | 446 | } else { |
ef456f85 JK |
447 | pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n", |
448 | "R ", i, | |
449 | (unsigned long long)le64_to_cpu(u1->a), | |
450 | (unsigned long long)le64_to_cpu(u1->b), | |
451 | (unsigned long long)buffer_info->dma, | |
452 | buffer_info->skb, next_desc); | |
5f450212 | 453 | |
f0c5dadf ET |
454 | if (netif_msg_pktdata(adapter) && |
455 | buffer_info->skb) | |
5f450212 BA |
456 | print_hex_dump(KERN_INFO, "", |
457 | DUMP_PREFIX_ADDRESS, 16, | |
458 | 1, | |
f0c5dadf | 459 | buffer_info->skb->data, |
5f450212 BA |
460 | adapter->rx_buffer_len, |
461 | true); | |
462 | } | |
84f4ee90 TI |
463 | } |
464 | } | |
84f4ee90 TI |
465 | } |
466 | ||
bc7f75fa AK |
467 | /** |
468 | * e1000_desc_unused - calculate if we have unused descriptors | |
469 | **/ | |
470 | static int e1000_desc_unused(struct e1000_ring *ring) | |
471 | { | |
472 | if (ring->next_to_clean > ring->next_to_use) | |
473 | return ring->next_to_clean - ring->next_to_use - 1; | |
474 | ||
475 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; | |
476 | } | |
477 | ||
b67e1913 BA |
478 | /** |
479 | * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp | |
480 | * @adapter: board private structure | |
481 | * @hwtstamps: time stamp structure to update | |
482 | * @systim: unsigned 64bit system time value. | |
483 | * | |
484 | * Convert the system time value stored in the RX/TXSTMP registers into a | |
485 | * hwtstamp which can be used by the upper level time stamping functions. | |
486 | * | |
487 | * The 'systim_lock' spinlock is used to protect the consistency of the | |
488 | * system time value. This is needed because reading the 64 bit time | |
489 | * value involves reading two 32 bit registers. The first read latches the | |
490 | * value. | |
491 | **/ | |
492 | static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter, | |
493 | struct skb_shared_hwtstamps *hwtstamps, | |
494 | u64 systim) | |
495 | { | |
496 | u64 ns; | |
497 | unsigned long flags; | |
498 | ||
499 | spin_lock_irqsave(&adapter->systim_lock, flags); | |
500 | ns = timecounter_cyc2time(&adapter->tc, systim); | |
501 | spin_unlock_irqrestore(&adapter->systim_lock, flags); | |
502 | ||
503 | memset(hwtstamps, 0, sizeof(*hwtstamps)); | |
504 | hwtstamps->hwtstamp = ns_to_ktime(ns); | |
505 | } | |
506 | ||
507 | /** | |
508 | * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp | |
509 | * @adapter: board private structure | |
510 | * @status: descriptor extended error and status field | |
511 | * @skb: particular skb to include time stamp | |
512 | * | |
513 | * If the time stamp is valid, convert it into the timecounter ns value | |
514 | * and store that result into the shhwtstamps structure which is passed | |
515 | * up the network stack. | |
516 | **/ | |
517 | static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status, | |
518 | struct sk_buff *skb) | |
519 | { | |
520 | struct e1000_hw *hw = &adapter->hw; | |
521 | u64 rxstmp; | |
522 | ||
523 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) || | |
524 | !(status & E1000_RXDEXT_STATERR_TST) || | |
525 | !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) | |
526 | return; | |
527 | ||
528 | /* The Rx time stamp registers contain the time stamp. No other | |
529 | * received packet will be time stamped until the Rx time stamp | |
530 | * registers are read. Because only one packet can be time stamped | |
531 | * at a time, the register values must belong to this packet and | |
532 | * therefore none of the other additional attributes need to be | |
533 | * compared. | |
534 | */ | |
535 | rxstmp = (u64)er32(RXSTMPL); | |
536 | rxstmp |= (u64)er32(RXSTMPH) << 32; | |
537 | e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp); | |
538 | ||
539 | adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP; | |
540 | } | |
541 | ||
bc7f75fa | 542 | /** |
ad68076e | 543 | * e1000_receive_skb - helper function to handle Rx indications |
bc7f75fa | 544 | * @adapter: board private structure |
b67e1913 | 545 | * @staterr: descriptor extended error and status field as written by hardware |
bc7f75fa AK |
546 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
547 | * @skb: pointer to sk_buff to be indicated to stack | |
548 | **/ | |
549 | static void e1000_receive_skb(struct e1000_adapter *adapter, | |
af667a29 | 550 | struct net_device *netdev, struct sk_buff *skb, |
b67e1913 | 551 | u32 staterr, __le16 vlan) |
bc7f75fa | 552 | { |
86d70e53 | 553 | u16 tag = le16_to_cpu(vlan); |
b67e1913 BA |
554 | |
555 | e1000e_rx_hwtstamp(adapter, staterr, skb); | |
556 | ||
bc7f75fa AK |
557 | skb->protocol = eth_type_trans(skb, netdev); |
558 | ||
b67e1913 | 559 | if (staterr & E1000_RXD_STAT_VP) |
86a9bad3 | 560 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag); |
86d70e53 JK |
561 | |
562 | napi_gro_receive(&adapter->napi, skb); | |
bc7f75fa AK |
563 | } |
564 | ||
565 | /** | |
af667a29 | 566 | * e1000_rx_checksum - Receive Checksum Offload |
afd12939 BA |
567 | * @adapter: board private structure |
568 | * @status_err: receive descriptor status and error fields | |
569 | * @csum: receive descriptor csum field | |
570 | * @sk_buff: socket buffer with received data | |
bc7f75fa AK |
571 | **/ |
572 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, | |
2e1706f2 | 573 | struct sk_buff *skb) |
bc7f75fa AK |
574 | { |
575 | u16 status = (u16)status_err; | |
576 | u8 errors = (u8)(status_err >> 24); | |
bc8acf2c ED |
577 | |
578 | skb_checksum_none_assert(skb); | |
bc7f75fa | 579 | |
afd12939 BA |
580 | /* Rx checksum disabled */ |
581 | if (!(adapter->netdev->features & NETIF_F_RXCSUM)) | |
582 | return; | |
583 | ||
bc7f75fa AK |
584 | /* Ignore Checksum bit is set */ |
585 | if (status & E1000_RXD_STAT_IXSM) | |
586 | return; | |
afd12939 | 587 | |
2e1706f2 BA |
588 | /* TCP/UDP checksum error bit or IP checksum error bit is set */ |
589 | if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) { | |
bc7f75fa AK |
590 | /* let the stack verify checksum errors */ |
591 | adapter->hw_csum_err++; | |
592 | return; | |
593 | } | |
594 | ||
595 | /* TCP/UDP Checksum has not been calculated */ | |
596 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) | |
597 | return; | |
598 | ||
599 | /* It must be a TCP or UDP packet with a valid checksum */ | |
2e1706f2 | 600 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
bc7f75fa AK |
601 | adapter->hw_csum_good++; |
602 | } | |
603 | ||
55aa6985 | 604 | static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i) |
c6e7f51e | 605 | { |
55aa6985 | 606 | struct e1000_adapter *adapter = rx_ring->adapter; |
c6e7f51e | 607 | struct e1000_hw *hw = &adapter->hw; |
bdc125f7 | 608 | |
d0150186 | 609 | __ew32_prepare(hw); |
bdc125f7 | 610 | writel(i, rx_ring->tail); |
c6e7f51e | 611 | |
d0150186 | 612 | if (unlikely(i != readl(rx_ring->tail))) { |
c6e7f51e | 613 | u32 rctl = er32(RCTL); |
6cf08d1c | 614 | |
c6e7f51e BA |
615 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
616 | e_err("ME firmware caused invalid RDT - resetting\n"); | |
617 | schedule_work(&adapter->reset_task); | |
618 | } | |
619 | } | |
620 | ||
55aa6985 | 621 | static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i) |
c6e7f51e | 622 | { |
55aa6985 | 623 | struct e1000_adapter *adapter = tx_ring->adapter; |
c6e7f51e BA |
624 | struct e1000_hw *hw = &adapter->hw; |
625 | ||
d0150186 | 626 | __ew32_prepare(hw); |
bdc125f7 BA |
627 | writel(i, tx_ring->tail); |
628 | ||
d0150186 | 629 | if (unlikely(i != readl(tx_ring->tail))) { |
c6e7f51e | 630 | u32 tctl = er32(TCTL); |
6cf08d1c | 631 | |
c6e7f51e BA |
632 | ew32(TCTL, tctl & ~E1000_TCTL_EN); |
633 | e_err("ME firmware caused invalid TDT - resetting\n"); | |
634 | schedule_work(&adapter->reset_task); | |
635 | } | |
636 | } | |
637 | ||
bc7f75fa | 638 | /** |
5f450212 | 639 | * e1000_alloc_rx_buffers - Replace used receive buffers |
55aa6985 | 640 | * @rx_ring: Rx descriptor ring |
bc7f75fa | 641 | **/ |
55aa6985 | 642 | static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring, |
c2fed996 | 643 | int cleaned_count, gfp_t gfp) |
bc7f75fa | 644 | { |
55aa6985 | 645 | struct e1000_adapter *adapter = rx_ring->adapter; |
bc7f75fa AK |
646 | struct net_device *netdev = adapter->netdev; |
647 | struct pci_dev *pdev = adapter->pdev; | |
5f450212 | 648 | union e1000_rx_desc_extended *rx_desc; |
bc7f75fa AK |
649 | struct e1000_buffer *buffer_info; |
650 | struct sk_buff *skb; | |
651 | unsigned int i; | |
89d71a66 | 652 | unsigned int bufsz = adapter->rx_buffer_len; |
bc7f75fa AK |
653 | |
654 | i = rx_ring->next_to_use; | |
655 | buffer_info = &rx_ring->buffer_info[i]; | |
656 | ||
657 | while (cleaned_count--) { | |
658 | skb = buffer_info->skb; | |
659 | if (skb) { | |
660 | skb_trim(skb, 0); | |
661 | goto map_skb; | |
662 | } | |
663 | ||
c2fed996 | 664 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
bc7f75fa AK |
665 | if (!skb) { |
666 | /* Better luck next round */ | |
667 | adapter->alloc_rx_buff_failed++; | |
668 | break; | |
669 | } | |
670 | ||
bc7f75fa AK |
671 | buffer_info->skb = skb; |
672 | map_skb: | |
0be3f55f | 673 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
bc7f75fa | 674 | adapter->rx_buffer_len, |
0be3f55f NN |
675 | DMA_FROM_DEVICE); |
676 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { | |
af667a29 | 677 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
bc7f75fa AK |
678 | adapter->rx_dma_failed++; |
679 | break; | |
680 | } | |
681 | ||
5f450212 BA |
682 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
683 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); | |
bc7f75fa | 684 | |
50849d79 | 685 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
e921eb1a | 686 | /* Force memory writes to complete before letting h/w |
50849d79 TH |
687 | * know there are new descriptors to fetch. (Only |
688 | * applicable for weak-ordered memory model archs, | |
689 | * such as IA-64). | |
690 | */ | |
691 | wmb(); | |
c6e7f51e | 692 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
55aa6985 | 693 | e1000e_update_rdt_wa(rx_ring, i); |
c6e7f51e | 694 | else |
c5083cf6 | 695 | writel(i, rx_ring->tail); |
50849d79 | 696 | } |
bc7f75fa AK |
697 | i++; |
698 | if (i == rx_ring->count) | |
699 | i = 0; | |
700 | buffer_info = &rx_ring->buffer_info[i]; | |
701 | } | |
702 | ||
50849d79 | 703 | rx_ring->next_to_use = i; |
bc7f75fa AK |
704 | } |
705 | ||
706 | /** | |
707 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split | |
55aa6985 | 708 | * @rx_ring: Rx descriptor ring |
bc7f75fa | 709 | **/ |
55aa6985 | 710 | static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring, |
c2fed996 | 711 | int cleaned_count, gfp_t gfp) |
bc7f75fa | 712 | { |
55aa6985 | 713 | struct e1000_adapter *adapter = rx_ring->adapter; |
bc7f75fa AK |
714 | struct net_device *netdev = adapter->netdev; |
715 | struct pci_dev *pdev = adapter->pdev; | |
716 | union e1000_rx_desc_packet_split *rx_desc; | |
bc7f75fa AK |
717 | struct e1000_buffer *buffer_info; |
718 | struct e1000_ps_page *ps_page; | |
719 | struct sk_buff *skb; | |
720 | unsigned int i, j; | |
721 | ||
722 | i = rx_ring->next_to_use; | |
723 | buffer_info = &rx_ring->buffer_info[i]; | |
724 | ||
725 | while (cleaned_count--) { | |
726 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); | |
727 | ||
728 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { | |
47f44e40 AK |
729 | ps_page = &buffer_info->ps_pages[j]; |
730 | if (j >= adapter->rx_ps_pages) { | |
731 | /* all unused desc entries get hw null ptr */ | |
af667a29 BA |
732 | rx_desc->read.buffer_addr[j + 1] = |
733 | ~cpu_to_le64(0); | |
47f44e40 AK |
734 | continue; |
735 | } | |
736 | if (!ps_page->page) { | |
c2fed996 | 737 | ps_page->page = alloc_page(gfp); |
bc7f75fa | 738 | if (!ps_page->page) { |
47f44e40 AK |
739 | adapter->alloc_rx_buff_failed++; |
740 | goto no_buffers; | |
741 | } | |
0be3f55f NN |
742 | ps_page->dma = dma_map_page(&pdev->dev, |
743 | ps_page->page, | |
744 | 0, PAGE_SIZE, | |
745 | DMA_FROM_DEVICE); | |
746 | if (dma_mapping_error(&pdev->dev, | |
747 | ps_page->dma)) { | |
47f44e40 | 748 | dev_err(&adapter->pdev->dev, |
af667a29 | 749 | "Rx DMA page map failed\n"); |
47f44e40 AK |
750 | adapter->rx_dma_failed++; |
751 | goto no_buffers; | |
bc7f75fa | 752 | } |
bc7f75fa | 753 | } |
e921eb1a | 754 | /* Refresh the desc even if buffer_addrs |
47f44e40 AK |
755 | * didn't change because each write-back |
756 | * erases this info. | |
757 | */ | |
af667a29 BA |
758 | rx_desc->read.buffer_addr[j + 1] = |
759 | cpu_to_le64(ps_page->dma); | |
bc7f75fa AK |
760 | } |
761 | ||
e5fe2541 | 762 | skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0, |
c2fed996 | 763 | gfp); |
bc7f75fa AK |
764 | |
765 | if (!skb) { | |
766 | adapter->alloc_rx_buff_failed++; | |
767 | break; | |
768 | } | |
769 | ||
bc7f75fa | 770 | buffer_info->skb = skb; |
0be3f55f | 771 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
bc7f75fa | 772 | adapter->rx_ps_bsize0, |
0be3f55f NN |
773 | DMA_FROM_DEVICE); |
774 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { | |
af667a29 | 775 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
bc7f75fa AK |
776 | adapter->rx_dma_failed++; |
777 | /* cleanup skb */ | |
778 | dev_kfree_skb_any(skb); | |
779 | buffer_info->skb = NULL; | |
780 | break; | |
781 | } | |
782 | ||
783 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); | |
784 | ||
50849d79 | 785 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
e921eb1a | 786 | /* Force memory writes to complete before letting h/w |
50849d79 TH |
787 | * know there are new descriptors to fetch. (Only |
788 | * applicable for weak-ordered memory model archs, | |
789 | * such as IA-64). | |
790 | */ | |
791 | wmb(); | |
c6e7f51e | 792 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
55aa6985 | 793 | e1000e_update_rdt_wa(rx_ring, i << 1); |
c6e7f51e | 794 | else |
c5083cf6 | 795 | writel(i << 1, rx_ring->tail); |
50849d79 TH |
796 | } |
797 | ||
bc7f75fa AK |
798 | i++; |
799 | if (i == rx_ring->count) | |
800 | i = 0; | |
801 | buffer_info = &rx_ring->buffer_info[i]; | |
802 | } | |
803 | ||
804 | no_buffers: | |
50849d79 | 805 | rx_ring->next_to_use = i; |
bc7f75fa AK |
806 | } |
807 | ||
97ac8cae BA |
808 | /** |
809 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers | |
55aa6985 | 810 | * @rx_ring: Rx descriptor ring |
97ac8cae BA |
811 | * @cleaned_count: number of buffers to allocate this pass |
812 | **/ | |
813 | ||
55aa6985 | 814 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring, |
c2fed996 | 815 | int cleaned_count, gfp_t gfp) |
97ac8cae | 816 | { |
55aa6985 | 817 | struct e1000_adapter *adapter = rx_ring->adapter; |
97ac8cae BA |
818 | struct net_device *netdev = adapter->netdev; |
819 | struct pci_dev *pdev = adapter->pdev; | |
5f450212 | 820 | union e1000_rx_desc_extended *rx_desc; |
97ac8cae BA |
821 | struct e1000_buffer *buffer_info; |
822 | struct sk_buff *skb; | |
823 | unsigned int i; | |
2a2293b9 | 824 | unsigned int bufsz = 256 - 16; /* for skb_reserve */ |
97ac8cae BA |
825 | |
826 | i = rx_ring->next_to_use; | |
827 | buffer_info = &rx_ring->buffer_info[i]; | |
828 | ||
829 | while (cleaned_count--) { | |
830 | skb = buffer_info->skb; | |
831 | if (skb) { | |
832 | skb_trim(skb, 0); | |
833 | goto check_page; | |
834 | } | |
835 | ||
c2fed996 | 836 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
97ac8cae BA |
837 | if (unlikely(!skb)) { |
838 | /* Better luck next round */ | |
839 | adapter->alloc_rx_buff_failed++; | |
840 | break; | |
841 | } | |
842 | ||
97ac8cae BA |
843 | buffer_info->skb = skb; |
844 | check_page: | |
845 | /* allocate a new page if necessary */ | |
846 | if (!buffer_info->page) { | |
c2fed996 | 847 | buffer_info->page = alloc_page(gfp); |
97ac8cae BA |
848 | if (unlikely(!buffer_info->page)) { |
849 | adapter->alloc_rx_buff_failed++; | |
850 | break; | |
851 | } | |
852 | } | |
853 | ||
37287fae | 854 | if (!buffer_info->dma) { |
0be3f55f | 855 | buffer_info->dma = dma_map_page(&pdev->dev, |
f0ff4398 BA |
856 | buffer_info->page, 0, |
857 | PAGE_SIZE, | |
0be3f55f | 858 | DMA_FROM_DEVICE); |
37287fae CP |
859 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
860 | adapter->alloc_rx_buff_failed++; | |
861 | break; | |
862 | } | |
863 | } | |
97ac8cae | 864 | |
5f450212 BA |
865 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
866 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); | |
97ac8cae BA |
867 | |
868 | if (unlikely(++i == rx_ring->count)) | |
869 | i = 0; | |
870 | buffer_info = &rx_ring->buffer_info[i]; | |
871 | } | |
872 | ||
873 | if (likely(rx_ring->next_to_use != i)) { | |
874 | rx_ring->next_to_use = i; | |
875 | if (unlikely(i-- == 0)) | |
876 | i = (rx_ring->count - 1); | |
877 | ||
878 | /* Force memory writes to complete before letting h/w | |
879 | * know there are new descriptors to fetch. (Only | |
880 | * applicable for weak-ordered memory model archs, | |
e921eb1a BA |
881 | * such as IA-64). |
882 | */ | |
97ac8cae | 883 | wmb(); |
c6e7f51e | 884 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
55aa6985 | 885 | e1000e_update_rdt_wa(rx_ring, i); |
c6e7f51e | 886 | else |
c5083cf6 | 887 | writel(i, rx_ring->tail); |
97ac8cae BA |
888 | } |
889 | } | |
890 | ||
70495a50 BA |
891 | static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss, |
892 | struct sk_buff *skb) | |
893 | { | |
894 | if (netdev->features & NETIF_F_RXHASH) | |
e25909bc | 895 | skb_set_hash(skb, le32_to_cpu(rss), PKT_HASH_TYPE_L3); |
70495a50 BA |
896 | } |
897 | ||
bc7f75fa | 898 | /** |
55aa6985 BA |
899 | * e1000_clean_rx_irq - Send received data up the network stack |
900 | * @rx_ring: Rx descriptor ring | |
bc7f75fa AK |
901 | * |
902 | * the return value indicates whether actual cleaning was done, there | |
903 | * is no guarantee that everything was cleaned | |
904 | **/ | |
55aa6985 BA |
905 | static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
906 | int work_to_do) | |
bc7f75fa | 907 | { |
55aa6985 | 908 | struct e1000_adapter *adapter = rx_ring->adapter; |
bc7f75fa AK |
909 | struct net_device *netdev = adapter->netdev; |
910 | struct pci_dev *pdev = adapter->pdev; | |
3bb99fe2 | 911 | struct e1000_hw *hw = &adapter->hw; |
5f450212 | 912 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
bc7f75fa | 913 | struct e1000_buffer *buffer_info, *next_buffer; |
5f450212 | 914 | u32 length, staterr; |
bc7f75fa AK |
915 | unsigned int i; |
916 | int cleaned_count = 0; | |
3db1cd5c | 917 | bool cleaned = false; |
bc7f75fa AK |
918 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
919 | ||
920 | i = rx_ring->next_to_clean; | |
5f450212 BA |
921 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
922 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | |
bc7f75fa AK |
923 | buffer_info = &rx_ring->buffer_info[i]; |
924 | ||
5f450212 | 925 | while (staterr & E1000_RXD_STAT_DD) { |
bc7f75fa | 926 | struct sk_buff *skb; |
bc7f75fa AK |
927 | |
928 | if (*work_done >= work_to_do) | |
929 | break; | |
930 | (*work_done)++; | |
837a1dba | 931 | dma_rmb(); /* read descriptor and rx_buffer_info after status DD */ |
bc7f75fa | 932 | |
bc7f75fa AK |
933 | skb = buffer_info->skb; |
934 | buffer_info->skb = NULL; | |
935 | ||
936 | prefetch(skb->data - NET_IP_ALIGN); | |
937 | ||
938 | i++; | |
939 | if (i == rx_ring->count) | |
940 | i = 0; | |
5f450212 | 941 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
bc7f75fa AK |
942 | prefetch(next_rxd); |
943 | ||
944 | next_buffer = &rx_ring->buffer_info[i]; | |
945 | ||
3db1cd5c | 946 | cleaned = true; |
bc7f75fa | 947 | cleaned_count++; |
e5fe2541 BA |
948 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
949 | adapter->rx_buffer_len, DMA_FROM_DEVICE); | |
bc7f75fa AK |
950 | buffer_info->dma = 0; |
951 | ||
5f450212 | 952 | length = le16_to_cpu(rx_desc->wb.upper.length); |
bc7f75fa | 953 | |
e921eb1a | 954 | /* !EOP means multiple descriptors were used to store a single |
b94b5028 JB |
955 | * packet, if that's the case we need to toss it. In fact, we |
956 | * need to toss every packet with the EOP bit clear and the | |
957 | * next frame that _does_ have the EOP bit set, as it is by | |
958 | * definition only a frame fragment | |
959 | */ | |
5f450212 | 960 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) |
b94b5028 JB |
961 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
962 | ||
963 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { | |
bc7f75fa | 964 | /* All receives must fit into a single buffer */ |
3bb99fe2 | 965 | e_dbg("Receive packet consumed multiple buffers\n"); |
bc7f75fa AK |
966 | /* recycle */ |
967 | buffer_info->skb = skb; | |
5f450212 | 968 | if (staterr & E1000_RXD_STAT_EOP) |
b94b5028 | 969 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
bc7f75fa AK |
970 | goto next_desc; |
971 | } | |
972 | ||
cf955e6c BG |
973 | if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
974 | !(netdev->features & NETIF_F_RXALL))) { | |
bc7f75fa AK |
975 | /* recycle */ |
976 | buffer_info->skb = skb; | |
977 | goto next_desc; | |
978 | } | |
979 | ||
eb7c3adb | 980 | /* adjust length to remove Ethernet CRC */ |
0184039a BG |
981 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
982 | /* If configured to store CRC, don't subtract FCS, | |
983 | * but keep the FCS bytes out of the total_rx_bytes | |
984 | * counter | |
985 | */ | |
986 | if (netdev->features & NETIF_F_RXFCS) | |
987 | total_rx_bytes -= 4; | |
988 | else | |
989 | length -= 4; | |
990 | } | |
eb7c3adb | 991 | |
bc7f75fa AK |
992 | total_rx_bytes += length; |
993 | total_rx_packets++; | |
994 | ||
e921eb1a | 995 | /* code added for copybreak, this should improve |
bc7f75fa | 996 | * performance for small packets with large amounts |
ad68076e BA |
997 | * of reassembly being done in the stack |
998 | */ | |
bc7f75fa AK |
999 | if (length < copybreak) { |
1000 | struct sk_buff *new_skb = | |
67fd893e | 1001 | napi_alloc_skb(&adapter->napi, length); |
bc7f75fa | 1002 | if (new_skb) { |
808ff676 BA |
1003 | skb_copy_to_linear_data_offset(new_skb, |
1004 | -NET_IP_ALIGN, | |
1005 | (skb->data - | |
1006 | NET_IP_ALIGN), | |
1007 | (length + | |
1008 | NET_IP_ALIGN)); | |
bc7f75fa AK |
1009 | /* save the skb in buffer_info as good */ |
1010 | buffer_info->skb = skb; | |
1011 | skb = new_skb; | |
1012 | } | |
1013 | /* else just continue with the old one */ | |
1014 | } | |
1015 | /* end copybreak code */ | |
1016 | skb_put(skb, length); | |
1017 | ||
1018 | /* Receive Checksum Offload */ | |
2e1706f2 | 1019 | e1000_rx_checksum(adapter, staterr, skb); |
bc7f75fa | 1020 | |
70495a50 BA |
1021 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
1022 | ||
5f450212 BA |
1023 | e1000_receive_skb(adapter, netdev, skb, staterr, |
1024 | rx_desc->wb.upper.vlan); | |
bc7f75fa AK |
1025 | |
1026 | next_desc: | |
5f450212 | 1027 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
bc7f75fa AK |
1028 | |
1029 | /* return some buffers to hardware, one at a time is too slow */ | |
1030 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { | |
55aa6985 | 1031 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
c2fed996 | 1032 | GFP_ATOMIC); |
bc7f75fa AK |
1033 | cleaned_count = 0; |
1034 | } | |
1035 | ||
1036 | /* use prefetched values */ | |
1037 | rx_desc = next_rxd; | |
1038 | buffer_info = next_buffer; | |
5f450212 BA |
1039 | |
1040 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | |
bc7f75fa AK |
1041 | } |
1042 | rx_ring->next_to_clean = i; | |
1043 | ||
1044 | cleaned_count = e1000_desc_unused(rx_ring); | |
1045 | if (cleaned_count) | |
55aa6985 | 1046 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
bc7f75fa | 1047 | |
bc7f75fa | 1048 | adapter->total_rx_bytes += total_rx_bytes; |
7c25769f | 1049 | adapter->total_rx_packets += total_rx_packets; |
bc7f75fa AK |
1050 | return cleaned; |
1051 | } | |
1052 | ||
55aa6985 | 1053 | static void e1000_put_txbuf(struct e1000_ring *tx_ring, |
377b6273 FF |
1054 | struct e1000_buffer *buffer_info, |
1055 | bool drop) | |
bc7f75fa | 1056 | { |
55aa6985 BA |
1057 | struct e1000_adapter *adapter = tx_ring->adapter; |
1058 | ||
03b1320d AD |
1059 | if (buffer_info->dma) { |
1060 | if (buffer_info->mapped_as_page) | |
0be3f55f NN |
1061 | dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, |
1062 | buffer_info->length, DMA_TO_DEVICE); | |
03b1320d | 1063 | else |
0be3f55f NN |
1064 | dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, |
1065 | buffer_info->length, DMA_TO_DEVICE); | |
03b1320d AD |
1066 | buffer_info->dma = 0; |
1067 | } | |
bc7f75fa | 1068 | if (buffer_info->skb) { |
377b6273 FF |
1069 | if (drop) |
1070 | dev_kfree_skb_any(buffer_info->skb); | |
1071 | else | |
1072 | dev_consume_skb_any(buffer_info->skb); | |
bc7f75fa AK |
1073 | buffer_info->skb = NULL; |
1074 | } | |
1b7719c4 | 1075 | buffer_info->time_stamp = 0; |
bc7f75fa AK |
1076 | } |
1077 | ||
41cec6f1 | 1078 | static void e1000_print_hw_hang(struct work_struct *work) |
bc7f75fa | 1079 | { |
41cec6f1 | 1080 | struct e1000_adapter *adapter = container_of(work, |
f0ff4398 BA |
1081 | struct e1000_adapter, |
1082 | print_hang_task); | |
09357b00 | 1083 | struct net_device *netdev = adapter->netdev; |
bc7f75fa AK |
1084 | struct e1000_ring *tx_ring = adapter->tx_ring; |
1085 | unsigned int i = tx_ring->next_to_clean; | |
1086 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; | |
1087 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); | |
41cec6f1 BA |
1088 | struct e1000_hw *hw = &adapter->hw; |
1089 | u16 phy_status, phy_1000t_status, phy_ext_status; | |
1090 | u16 pci_status; | |
1091 | ||
615b32af JB |
1092 | if (test_bit(__E1000_DOWN, &adapter->state)) |
1093 | return; | |
1094 | ||
e5fe2541 | 1095 | if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) { |
e921eb1a | 1096 | /* May be block on write-back, flush and detect again |
09357b00 JK |
1097 | * flush pending descriptor writebacks to memory |
1098 | */ | |
1099 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); | |
1100 | /* execute the writes immediately */ | |
1101 | e1e_flush(); | |
e921eb1a | 1102 | /* Due to rare timing issues, write to TIDV again to ensure |
bf03085f MV |
1103 | * the write is successful |
1104 | */ | |
1105 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); | |
1106 | /* execute the writes immediately */ | |
1107 | e1e_flush(); | |
09357b00 JK |
1108 | adapter->tx_hang_recheck = true; |
1109 | return; | |
1110 | } | |
09357b00 | 1111 | adapter->tx_hang_recheck = false; |
d9554e96 DE |
1112 | |
1113 | if (er32(TDH(0)) == er32(TDT(0))) { | |
1114 | e_dbg("false hang detected, ignoring\n"); | |
1115 | return; | |
1116 | } | |
1117 | ||
1118 | /* Real hang detected */ | |
09357b00 JK |
1119 | netif_stop_queue(netdev); |
1120 | ||
c2ade1a4 BA |
1121 | e1e_rphy(hw, MII_BMSR, &phy_status); |
1122 | e1e_rphy(hw, MII_STAT1000, &phy_1000t_status); | |
1123 | e1e_rphy(hw, MII_ESTATUS, &phy_ext_status); | |
bc7f75fa | 1124 | |
41cec6f1 BA |
1125 | pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status); |
1126 | ||
1127 | /* detected Hardware unit hang */ | |
1128 | e_err("Detected Hardware Unit Hang:\n" | |
44defeb3 JK |
1129 | " TDH <%x>\n" |
1130 | " TDT <%x>\n" | |
1131 | " next_to_use <%x>\n" | |
1132 | " next_to_clean <%x>\n" | |
1133 | "buffer_info[next_to_clean]:\n" | |
1134 | " time_stamp <%lx>\n" | |
1135 | " next_to_watch <%x>\n" | |
1136 | " jiffies <%lx>\n" | |
41cec6f1 BA |
1137 | " next_to_watch.status <%x>\n" |
1138 | "MAC Status <%x>\n" | |
1139 | "PHY Status <%x>\n" | |
1140 | "PHY 1000BASE-T Status <%x>\n" | |
1141 | "PHY Extended Status <%x>\n" | |
1142 | "PCI Status <%x>\n", | |
e5fe2541 BA |
1143 | readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use, |
1144 | tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp, | |
1145 | eop, jiffies, eop_desc->upper.fields.status, er32(STATUS), | |
1146 | phy_status, phy_1000t_status, phy_ext_status, pci_status); | |
7c0427ee | 1147 | |
d9554e96 DE |
1148 | e1000e_dump(adapter); |
1149 | ||
7c0427ee BA |
1150 | /* Suggest workaround for known h/w issue */ |
1151 | if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE)) | |
1152 | e_err("Try turning off Tx pause (flow control) via ethtool\n"); | |
bc7f75fa AK |
1153 | } |
1154 | ||
b67e1913 BA |
1155 | /** |
1156 | * e1000e_tx_hwtstamp_work - check for Tx time stamp | |
1157 | * @work: pointer to work struct | |
1158 | * | |
1159 | * This work function polls the TSYNCTXCTL valid bit to determine when a | |
1160 | * timestamp has been taken for the current stored skb. The timestamp must | |
1161 | * be for this skb because only one such packet is allowed in the queue. | |
1162 | */ | |
1163 | static void e1000e_tx_hwtstamp_work(struct work_struct *work) | |
1164 | { | |
1165 | struct e1000_adapter *adapter = container_of(work, struct e1000_adapter, | |
1166 | tx_hwtstamp_work); | |
1167 | struct e1000_hw *hw = &adapter->hw; | |
1168 | ||
b67e1913 | 1169 | if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) { |
5012863b | 1170 | struct sk_buff *skb = adapter->tx_hwtstamp_skb; |
b67e1913 BA |
1171 | struct skb_shared_hwtstamps shhwtstamps; |
1172 | u64 txstmp; | |
1173 | ||
1174 | txstmp = er32(TXSTMPL); | |
1175 | txstmp |= (u64)er32(TXSTMPH) << 32; | |
1176 | ||
1177 | e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp); | |
1178 | ||
5012863b JK |
1179 | /* Clear the global tx_hwtstamp_skb pointer and force writes |
1180 | * prior to notifying the stack of a Tx timestamp. | |
1181 | */ | |
b67e1913 | 1182 | adapter->tx_hwtstamp_skb = NULL; |
5012863b JK |
1183 | wmb(); /* force write prior to skb_tstamp_tx */ |
1184 | ||
1185 | skb_tstamp_tx(skb, &shhwtstamps); | |
377b6273 | 1186 | dev_consume_skb_any(skb); |
59c871c5 JK |
1187 | } else if (time_after(jiffies, adapter->tx_hwtstamp_start |
1188 | + adapter->tx_timeout_factor * HZ)) { | |
1189 | dev_kfree_skb_any(adapter->tx_hwtstamp_skb); | |
1190 | adapter->tx_hwtstamp_skb = NULL; | |
1191 | adapter->tx_hwtstamp_timeouts++; | |
c5ffe7e1 | 1192 | e_warn("clearing Tx timestamp hang\n"); |
b67e1913 BA |
1193 | } else { |
1194 | /* reschedule to check later */ | |
1195 | schedule_work(&adapter->tx_hwtstamp_work); | |
1196 | } | |
1197 | } | |
1198 | ||
bc7f75fa AK |
1199 | /** |
1200 | * e1000_clean_tx_irq - Reclaim resources after transmit completes | |
55aa6985 | 1201 | * @tx_ring: Tx descriptor ring |
bc7f75fa AK |
1202 | * |
1203 | * the return value indicates whether actual cleaning was done, there | |
1204 | * is no guarantee that everything was cleaned | |
1205 | **/ | |
55aa6985 | 1206 | static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring) |
bc7f75fa | 1207 | { |
55aa6985 | 1208 | struct e1000_adapter *adapter = tx_ring->adapter; |
bc7f75fa AK |
1209 | struct net_device *netdev = adapter->netdev; |
1210 | struct e1000_hw *hw = &adapter->hw; | |
bc7f75fa AK |
1211 | struct e1000_tx_desc *tx_desc, *eop_desc; |
1212 | struct e1000_buffer *buffer_info; | |
1213 | unsigned int i, eop; | |
1214 | unsigned int count = 0; | |
bc7f75fa | 1215 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; |
3f0cfa3b | 1216 | unsigned int bytes_compl = 0, pkts_compl = 0; |
bc7f75fa AK |
1217 | |
1218 | i = tx_ring->next_to_clean; | |
1219 | eop = tx_ring->buffer_info[i].next_to_watch; | |
1220 | eop_desc = E1000_TX_DESC(*tx_ring, eop); | |
1221 | ||
12d04a3c AD |
1222 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
1223 | (count < tx_ring->count)) { | |
a86043c2 | 1224 | bool cleaned = false; |
6cf08d1c | 1225 | |
837a1dba | 1226 | dma_rmb(); /* read buffer_info after eop_desc */ |
a86043c2 | 1227 | for (; !cleaned; count++) { |
bc7f75fa AK |
1228 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
1229 | buffer_info = &tx_ring->buffer_info[i]; | |
1230 | cleaned = (i == eop); | |
1231 | ||
1232 | if (cleaned) { | |
9ed318d5 TH |
1233 | total_tx_packets += buffer_info->segs; |
1234 | total_tx_bytes += buffer_info->bytecount; | |
3f0cfa3b TH |
1235 | if (buffer_info->skb) { |
1236 | bytes_compl += buffer_info->skb->len; | |
1237 | pkts_compl++; | |
1238 | } | |
bc7f75fa AK |
1239 | } |
1240 | ||
377b6273 | 1241 | e1000_put_txbuf(tx_ring, buffer_info, false); |
bc7f75fa AK |
1242 | tx_desc->upper.data = 0; |
1243 | ||
1244 | i++; | |
1245 | if (i == tx_ring->count) | |
1246 | i = 0; | |
1247 | } | |
1248 | ||
dac87619 TL |
1249 | if (i == tx_ring->next_to_use) |
1250 | break; | |
bc7f75fa AK |
1251 | eop = tx_ring->buffer_info[i].next_to_watch; |
1252 | eop_desc = E1000_TX_DESC(*tx_ring, eop); | |
bc7f75fa AK |
1253 | } |
1254 | ||
1255 | tx_ring->next_to_clean = i; | |
1256 | ||
3f0cfa3b TH |
1257 | netdev_completed_queue(netdev, pkts_compl, bytes_compl); |
1258 | ||
bc7f75fa | 1259 | #define TX_WAKE_THRESHOLD 32 |
a86043c2 JB |
1260 | if (count && netif_carrier_ok(netdev) && |
1261 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { | |
bc7f75fa AK |
1262 | /* Make sure that anybody stopping the queue after this |
1263 | * sees the new next_to_clean. | |
1264 | */ | |
1265 | smp_mb(); | |
1266 | ||
1267 | if (netif_queue_stopped(netdev) && | |
1268 | !(test_bit(__E1000_DOWN, &adapter->state))) { | |
1269 | netif_wake_queue(netdev); | |
1270 | ++adapter->restart_queue; | |
1271 | } | |
1272 | } | |
1273 | ||
1274 | if (adapter->detect_tx_hung) { | |
e921eb1a | 1275 | /* Detect a transmit hang in hardware, this serializes the |
41cec6f1 BA |
1276 | * check with the clearing of time_stamp and movement of i |
1277 | */ | |
3db1cd5c | 1278 | adapter->detect_tx_hung = false; |
12d04a3c AD |
1279 | if (tx_ring->buffer_info[i].time_stamp && |
1280 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp | |
8e95a202 | 1281 | + (adapter->tx_timeout_factor * HZ)) && |
09357b00 | 1282 | !(er32(STATUS) & E1000_STATUS_TXOFF)) |
41cec6f1 | 1283 | schedule_work(&adapter->print_hang_task); |
09357b00 JK |
1284 | else |
1285 | adapter->tx_hang_recheck = false; | |
bc7f75fa AK |
1286 | } |
1287 | adapter->total_tx_bytes += total_tx_bytes; | |
1288 | adapter->total_tx_packets += total_tx_packets; | |
807540ba | 1289 | return count < tx_ring->count; |
bc7f75fa AK |
1290 | } |
1291 | ||
bc7f75fa AK |
1292 | /** |
1293 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split | |
55aa6985 | 1294 | * @rx_ring: Rx descriptor ring |
bc7f75fa AK |
1295 | * |
1296 | * the return value indicates whether actual cleaning was done, there | |
1297 | * is no guarantee that everything was cleaned | |
1298 | **/ | |
55aa6985 BA |
1299 | static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done, |
1300 | int work_to_do) | |
bc7f75fa | 1301 | { |
55aa6985 | 1302 | struct e1000_adapter *adapter = rx_ring->adapter; |
3bb99fe2 | 1303 | struct e1000_hw *hw = &adapter->hw; |
bc7f75fa AK |
1304 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
1305 | struct net_device *netdev = adapter->netdev; | |
1306 | struct pci_dev *pdev = adapter->pdev; | |
bc7f75fa AK |
1307 | struct e1000_buffer *buffer_info, *next_buffer; |
1308 | struct e1000_ps_page *ps_page; | |
1309 | struct sk_buff *skb; | |
1310 | unsigned int i, j; | |
1311 | u32 length, staterr; | |
1312 | int cleaned_count = 0; | |
3db1cd5c | 1313 | bool cleaned = false; |
bc7f75fa AK |
1314 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
1315 | ||
1316 | i = rx_ring->next_to_clean; | |
1317 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); | |
1318 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); | |
1319 | buffer_info = &rx_ring->buffer_info[i]; | |
1320 | ||
1321 | while (staterr & E1000_RXD_STAT_DD) { | |
1322 | if (*work_done >= work_to_do) | |
1323 | break; | |
1324 | (*work_done)++; | |
1325 | skb = buffer_info->skb; | |
837a1dba | 1326 | dma_rmb(); /* read descriptor and rx_buffer_info after status DD */ |
bc7f75fa AK |
1327 | |
1328 | /* in the packet split case this is header only */ | |
1329 | prefetch(skb->data - NET_IP_ALIGN); | |
1330 | ||
1331 | i++; | |
1332 | if (i == rx_ring->count) | |
1333 | i = 0; | |
1334 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); | |
1335 | prefetch(next_rxd); | |
1336 | ||
1337 | next_buffer = &rx_ring->buffer_info[i]; | |
1338 | ||
3db1cd5c | 1339 | cleaned = true; |
bc7f75fa | 1340 | cleaned_count++; |
0be3f55f | 1341 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
af667a29 | 1342 | adapter->rx_ps_bsize0, DMA_FROM_DEVICE); |
bc7f75fa AK |
1343 | buffer_info->dma = 0; |
1344 | ||
af667a29 | 1345 | /* see !EOP comment in other Rx routine */ |
b94b5028 JB |
1346 | if (!(staterr & E1000_RXD_STAT_EOP)) |
1347 | adapter->flags2 |= FLAG2_IS_DISCARDING; | |
1348 | ||
1349 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { | |
ef456f85 | 1350 | e_dbg("Packet Split buffers didn't pick up the full packet\n"); |
bc7f75fa | 1351 | dev_kfree_skb_irq(skb); |
b94b5028 JB |
1352 | if (staterr & E1000_RXD_STAT_EOP) |
1353 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; | |
bc7f75fa AK |
1354 | goto next_desc; |
1355 | } | |
1356 | ||
cf955e6c BG |
1357 | if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
1358 | !(netdev->features & NETIF_F_RXALL))) { | |
bc7f75fa AK |
1359 | dev_kfree_skb_irq(skb); |
1360 | goto next_desc; | |
1361 | } | |
1362 | ||
1363 | length = le16_to_cpu(rx_desc->wb.middle.length0); | |
1364 | ||
1365 | if (!length) { | |
ef456f85 | 1366 | e_dbg("Last part of the packet spanning multiple descriptors\n"); |
bc7f75fa AK |
1367 | dev_kfree_skb_irq(skb); |
1368 | goto next_desc; | |
1369 | } | |
1370 | ||
1371 | /* Good Receive */ | |
1372 | skb_put(skb, length); | |
1373 | ||
1374 | { | |
e921eb1a | 1375 | /* this looks ugly, but it seems compiler issues make |
0e15df49 BA |
1376 | * it more efficient than reusing j |
1377 | */ | |
1378 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); | |
bc7f75fa | 1379 | |
e921eb1a | 1380 | /* page alloc/put takes too long and effects small |
0e15df49 BA |
1381 | * packet throughput, so unsplit small packets and |
1382 | * save the alloc/put only valid in softirq (napi) | |
1383 | * context to call kmap_* | |
ad68076e | 1384 | */ |
0e15df49 BA |
1385 | if (l1 && (l1 <= copybreak) && |
1386 | ((length + l1) <= adapter->rx_ps_bsize0)) { | |
1387 | u8 *vaddr; | |
1388 | ||
1389 | ps_page = &buffer_info->ps_pages[0]; | |
1390 | ||
e921eb1a | 1391 | /* there is no documentation about how to call |
0e15df49 BA |
1392 | * kmap_atomic, so we can't hold the mapping |
1393 | * very long | |
1394 | */ | |
1395 | dma_sync_single_for_cpu(&pdev->dev, | |
1396 | ps_page->dma, | |
1397 | PAGE_SIZE, | |
1398 | DMA_FROM_DEVICE); | |
9f393834 | 1399 | vaddr = kmap_atomic(ps_page->page); |
0e15df49 | 1400 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
9f393834 | 1401 | kunmap_atomic(vaddr); |
0e15df49 BA |
1402 | dma_sync_single_for_device(&pdev->dev, |
1403 | ps_page->dma, | |
1404 | PAGE_SIZE, | |
1405 | DMA_FROM_DEVICE); | |
1406 | ||
1407 | /* remove the CRC */ | |
0184039a BG |
1408 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
1409 | if (!(netdev->features & NETIF_F_RXFCS)) | |
1410 | l1 -= 4; | |
1411 | } | |
0e15df49 BA |
1412 | |
1413 | skb_put(skb, l1); | |
1414 | goto copydone; | |
e80bd1d1 | 1415 | } /* if */ |
bc7f75fa AK |
1416 | } |
1417 | ||
1418 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { | |
1419 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); | |
1420 | if (!length) | |
1421 | break; | |
1422 | ||
47f44e40 | 1423 | ps_page = &buffer_info->ps_pages[j]; |
0be3f55f NN |
1424 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
1425 | DMA_FROM_DEVICE); | |
bc7f75fa AK |
1426 | ps_page->dma = 0; |
1427 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); | |
1428 | ps_page->page = NULL; | |
1429 | skb->len += length; | |
1430 | skb->data_len += length; | |
98a045d7 | 1431 | skb->truesize += PAGE_SIZE; |
bc7f75fa AK |
1432 | } |
1433 | ||
eb7c3adb JK |
1434 | /* strip the ethernet crc, problem is we're using pages now so |
1435 | * this whole operation can get a little cpu intensive | |
1436 | */ | |
0184039a BG |
1437 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
1438 | if (!(netdev->features & NETIF_F_RXFCS)) | |
1439 | pskb_trim(skb, skb->len - 4); | |
1440 | } | |
eb7c3adb | 1441 | |
bc7f75fa AK |
1442 | copydone: |
1443 | total_rx_bytes += skb->len; | |
1444 | total_rx_packets++; | |
1445 | ||
2e1706f2 | 1446 | e1000_rx_checksum(adapter, staterr, skb); |
bc7f75fa | 1447 | |
70495a50 BA |
1448 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
1449 | ||
bc7f75fa | 1450 | if (rx_desc->wb.upper.header_status & |
17e813ec | 1451 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) |
bc7f75fa AK |
1452 | adapter->rx_hdr_split++; |
1453 | ||
b67e1913 BA |
1454 | e1000_receive_skb(adapter, netdev, skb, staterr, |
1455 | rx_desc->wb.middle.vlan); | |
bc7f75fa AK |
1456 | |
1457 | next_desc: | |
1458 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); | |
1459 | buffer_info->skb = NULL; | |
1460 | ||
1461 | /* return some buffers to hardware, one at a time is too slow */ | |
1462 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { | |
55aa6985 | 1463 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
c2fed996 | 1464 | GFP_ATOMIC); |
bc7f75fa AK |
1465 | cleaned_count = 0; |
1466 | } | |
1467 | ||
1468 | /* use prefetched values */ | |
1469 | rx_desc = next_rxd; | |
1470 | buffer_info = next_buffer; | |
1471 | ||
1472 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); | |
1473 | } | |
1474 | rx_ring->next_to_clean = i; | |
1475 | ||
1476 | cleaned_count = e1000_desc_unused(rx_ring); | |
1477 | if (cleaned_count) | |
55aa6985 | 1478 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
bc7f75fa | 1479 | |
bc7f75fa | 1480 | adapter->total_rx_bytes += total_rx_bytes; |
7c25769f | 1481 | adapter->total_rx_packets += total_rx_packets; |
bc7f75fa AK |
1482 | return cleaned; |
1483 | } | |
1484 | ||
97ac8cae BA |
1485 | /** |
1486 | * e1000_consume_page - helper function | |
1487 | **/ | |
1488 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, | |
66501f56 | 1489 | u16 length) |
97ac8cae BA |
1490 | { |
1491 | bi->page = NULL; | |
1492 | skb->len += length; | |
1493 | skb->data_len += length; | |
98a045d7 | 1494 | skb->truesize += PAGE_SIZE; |
97ac8cae BA |
1495 | } |
1496 | ||
1497 | /** | |
1498 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy | |
1499 | * @adapter: board private structure | |
1500 | * | |
1501 | * the return value indicates whether actual cleaning was done, there | |
1502 | * is no guarantee that everything was cleaned | |
1503 | **/ | |
55aa6985 BA |
1504 | static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
1505 | int work_to_do) | |
97ac8cae | 1506 | { |
55aa6985 | 1507 | struct e1000_adapter *adapter = rx_ring->adapter; |
97ac8cae BA |
1508 | struct net_device *netdev = adapter->netdev; |
1509 | struct pci_dev *pdev = adapter->pdev; | |
5f450212 | 1510 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
97ac8cae | 1511 | struct e1000_buffer *buffer_info, *next_buffer; |
5f450212 | 1512 | u32 length, staterr; |
97ac8cae BA |
1513 | unsigned int i; |
1514 | int cleaned_count = 0; | |
1515 | bool cleaned = false; | |
362e20ca | 1516 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
17e813ec | 1517 | struct skb_shared_info *shinfo; |
97ac8cae BA |
1518 | |
1519 | i = rx_ring->next_to_clean; | |
5f450212 BA |
1520 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
1521 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | |
97ac8cae BA |
1522 | buffer_info = &rx_ring->buffer_info[i]; |
1523 | ||
5f450212 | 1524 | while (staterr & E1000_RXD_STAT_DD) { |
97ac8cae | 1525 | struct sk_buff *skb; |
97ac8cae BA |
1526 | |
1527 | if (*work_done >= work_to_do) | |
1528 | break; | |
1529 | (*work_done)++; | |
837a1dba | 1530 | dma_rmb(); /* read descriptor and rx_buffer_info after status DD */ |
97ac8cae | 1531 | |
97ac8cae BA |
1532 | skb = buffer_info->skb; |
1533 | buffer_info->skb = NULL; | |
1534 | ||
1535 | ++i; | |
1536 | if (i == rx_ring->count) | |
1537 | i = 0; | |
5f450212 | 1538 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
97ac8cae BA |
1539 | prefetch(next_rxd); |
1540 | ||
1541 | next_buffer = &rx_ring->buffer_info[i]; | |
1542 | ||
1543 | cleaned = true; | |
1544 | cleaned_count++; | |
0be3f55f NN |
1545 | dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE, |
1546 | DMA_FROM_DEVICE); | |
97ac8cae BA |
1547 | buffer_info->dma = 0; |
1548 | ||
5f450212 | 1549 | length = le16_to_cpu(rx_desc->wb.upper.length); |
97ac8cae BA |
1550 | |
1551 | /* errors is only valid for DD + EOP descriptors */ | |
5f450212 | 1552 | if (unlikely((staterr & E1000_RXD_STAT_EOP) && |
cf955e6c BG |
1553 | ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
1554 | !(netdev->features & NETIF_F_RXALL)))) { | |
5f450212 BA |
1555 | /* recycle both page and skb */ |
1556 | buffer_info->skb = skb; | |
1557 | /* an error means any chain goes out the window too */ | |
1558 | if (rx_ring->rx_skb_top) | |
1559 | dev_kfree_skb_irq(rx_ring->rx_skb_top); | |
1560 | rx_ring->rx_skb_top = NULL; | |
1561 | goto next_desc; | |
97ac8cae | 1562 | } |
f0f1a172 | 1563 | #define rxtop (rx_ring->rx_skb_top) |
5f450212 | 1564 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
97ac8cae BA |
1565 | /* this descriptor is only the beginning (or middle) */ |
1566 | if (!rxtop) { | |
1567 | /* this is the beginning of a chain */ | |
1568 | rxtop = skb; | |
1569 | skb_fill_page_desc(rxtop, 0, buffer_info->page, | |
f0ff4398 | 1570 | 0, length); |
97ac8cae BA |
1571 | } else { |
1572 | /* this is the middle of a chain */ | |
17e813ec BA |
1573 | shinfo = skb_shinfo(rxtop); |
1574 | skb_fill_page_desc(rxtop, shinfo->nr_frags, | |
1575 | buffer_info->page, 0, | |
1576 | length); | |
97ac8cae BA |
1577 | /* re-use the skb, only consumed the page */ |
1578 | buffer_info->skb = skb; | |
1579 | } | |
1580 | e1000_consume_page(buffer_info, rxtop, length); | |
1581 | goto next_desc; | |
1582 | } else { | |
1583 | if (rxtop) { | |
1584 | /* end of the chain */ | |
17e813ec BA |
1585 | shinfo = skb_shinfo(rxtop); |
1586 | skb_fill_page_desc(rxtop, shinfo->nr_frags, | |
1587 | buffer_info->page, 0, | |
1588 | length); | |
97ac8cae | 1589 | /* re-use the current skb, we only consumed the |
e921eb1a BA |
1590 | * page |
1591 | */ | |
97ac8cae BA |
1592 | buffer_info->skb = skb; |
1593 | skb = rxtop; | |
1594 | rxtop = NULL; | |
1595 | e1000_consume_page(buffer_info, skb, length); | |
1596 | } else { | |
1597 | /* no chain, got EOP, this buf is the packet | |
e921eb1a BA |
1598 | * copybreak to save the put_page/alloc_page |
1599 | */ | |
97ac8cae BA |
1600 | if (length <= copybreak && |
1601 | skb_tailroom(skb) >= length) { | |
1602 | u8 *vaddr; | |
4679026d | 1603 | vaddr = kmap_atomic(buffer_info->page); |
97ac8cae BA |
1604 | memcpy(skb_tail_pointer(skb), vaddr, |
1605 | length); | |
4679026d | 1606 | kunmap_atomic(vaddr); |
97ac8cae | 1607 | /* re-use the page, so don't erase |
e921eb1a BA |
1608 | * buffer_info->page |
1609 | */ | |
97ac8cae BA |
1610 | skb_put(skb, length); |
1611 | } else { | |
1612 | skb_fill_page_desc(skb, 0, | |
f0ff4398 BA |
1613 | buffer_info->page, 0, |
1614 | length); | |
97ac8cae | 1615 | e1000_consume_page(buffer_info, skb, |
f0ff4398 | 1616 | length); |
97ac8cae BA |
1617 | } |
1618 | } | |
1619 | } | |
1620 | ||
2e1706f2 BA |
1621 | /* Receive Checksum Offload */ |
1622 | e1000_rx_checksum(adapter, staterr, skb); | |
97ac8cae | 1623 | |
70495a50 BA |
1624 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
1625 | ||
97ac8cae BA |
1626 | /* probably a little skewed due to removing CRC */ |
1627 | total_rx_bytes += skb->len; | |
1628 | total_rx_packets++; | |
1629 | ||
1630 | /* eth type trans needs skb->data to point to something */ | |
1631 | if (!pskb_may_pull(skb, ETH_HLEN)) { | |
44defeb3 | 1632 | e_err("pskb_may_pull failed.\n"); |
ef5ab89c | 1633 | dev_kfree_skb_irq(skb); |
97ac8cae BA |
1634 | goto next_desc; |
1635 | } | |
1636 | ||
5f450212 BA |
1637 | e1000_receive_skb(adapter, netdev, skb, staterr, |
1638 | rx_desc->wb.upper.vlan); | |
97ac8cae BA |
1639 | |
1640 | next_desc: | |
5f450212 | 1641 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
97ac8cae BA |
1642 | |
1643 | /* return some buffers to hardware, one at a time is too slow */ | |
1644 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { | |
55aa6985 | 1645 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
c2fed996 | 1646 | GFP_ATOMIC); |
97ac8cae BA |
1647 | cleaned_count = 0; |
1648 | } | |
1649 | ||
1650 | /* use prefetched values */ | |
1651 | rx_desc = next_rxd; | |
1652 | buffer_info = next_buffer; | |
5f450212 BA |
1653 | |
1654 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | |
97ac8cae BA |
1655 | } |
1656 | rx_ring->next_to_clean = i; | |
1657 | ||
1658 | cleaned_count = e1000_desc_unused(rx_ring); | |
1659 | if (cleaned_count) | |
55aa6985 | 1660 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
97ac8cae BA |
1661 | |
1662 | adapter->total_rx_bytes += total_rx_bytes; | |
1663 | adapter->total_rx_packets += total_rx_packets; | |
97ac8cae BA |
1664 | return cleaned; |
1665 | } | |
1666 | ||
bc7f75fa AK |
1667 | /** |
1668 | * e1000_clean_rx_ring - Free Rx Buffers per Queue | |
55aa6985 | 1669 | * @rx_ring: Rx descriptor ring |
bc7f75fa | 1670 | **/ |
55aa6985 | 1671 | static void e1000_clean_rx_ring(struct e1000_ring *rx_ring) |
bc7f75fa | 1672 | { |
55aa6985 | 1673 | struct e1000_adapter *adapter = rx_ring->adapter; |
bc7f75fa AK |
1674 | struct e1000_buffer *buffer_info; |
1675 | struct e1000_ps_page *ps_page; | |
1676 | struct pci_dev *pdev = adapter->pdev; | |
bc7f75fa AK |
1677 | unsigned int i, j; |
1678 | ||
1679 | /* Free all the Rx ring sk_buffs */ | |
1680 | for (i = 0; i < rx_ring->count; i++) { | |
1681 | buffer_info = &rx_ring->buffer_info[i]; | |
1682 | if (buffer_info->dma) { | |
1683 | if (adapter->clean_rx == e1000_clean_rx_irq) | |
0be3f55f | 1684 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
bc7f75fa | 1685 | adapter->rx_buffer_len, |
0be3f55f | 1686 | DMA_FROM_DEVICE); |
97ac8cae | 1687 | else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) |
0be3f55f | 1688 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
f0ff4398 | 1689 | PAGE_SIZE, DMA_FROM_DEVICE); |
bc7f75fa | 1690 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
0be3f55f | 1691 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
bc7f75fa | 1692 | adapter->rx_ps_bsize0, |
0be3f55f | 1693 | DMA_FROM_DEVICE); |
bc7f75fa AK |
1694 | buffer_info->dma = 0; |
1695 | } | |
1696 | ||
97ac8cae BA |
1697 | if (buffer_info->page) { |
1698 | put_page(buffer_info->page); | |
1699 | buffer_info->page = NULL; | |
1700 | } | |
1701 | ||
bc7f75fa AK |
1702 | if (buffer_info->skb) { |
1703 | dev_kfree_skb(buffer_info->skb); | |
1704 | buffer_info->skb = NULL; | |
1705 | } | |
1706 | ||
1707 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { | |
47f44e40 | 1708 | ps_page = &buffer_info->ps_pages[j]; |
bc7f75fa AK |
1709 | if (!ps_page->page) |
1710 | break; | |
0be3f55f NN |
1711 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
1712 | DMA_FROM_DEVICE); | |
bc7f75fa AK |
1713 | ps_page->dma = 0; |
1714 | put_page(ps_page->page); | |
1715 | ps_page->page = NULL; | |
1716 | } | |
1717 | } | |
1718 | ||
1719 | /* there also may be some cached data from a chained receive */ | |
1720 | if (rx_ring->rx_skb_top) { | |
1721 | dev_kfree_skb(rx_ring->rx_skb_top); | |
1722 | rx_ring->rx_skb_top = NULL; | |
1723 | } | |
1724 | ||
bc7f75fa AK |
1725 | /* Zero out the descriptor ring */ |
1726 | memset(rx_ring->desc, 0, rx_ring->size); | |
1727 | ||
1728 | rx_ring->next_to_clean = 0; | |
1729 | rx_ring->next_to_use = 0; | |
b94b5028 | 1730 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
bc7f75fa AK |
1731 | } |
1732 | ||
a8f88ff5 JB |
1733 | static void e1000e_downshift_workaround(struct work_struct *work) |
1734 | { | |
1735 | struct e1000_adapter *adapter = container_of(work, | |
17e813ec BA |
1736 | struct e1000_adapter, |
1737 | downshift_task); | |
a8f88ff5 | 1738 | |
615b32af JB |
1739 | if (test_bit(__E1000_DOWN, &adapter->state)) |
1740 | return; | |
1741 | ||
a8f88ff5 JB |
1742 | e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); |
1743 | } | |
1744 | ||
bc7f75fa AK |
1745 | /** |
1746 | * e1000_intr_msi - Interrupt Handler | |
1747 | * @irq: interrupt number | |
1748 | * @data: pointer to a network interface device structure | |
1749 | **/ | |
8bb62869 | 1750 | static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data) |
bc7f75fa AK |
1751 | { |
1752 | struct net_device *netdev = data; | |
1753 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
1754 | struct e1000_hw *hw = &adapter->hw; | |
1755 | u32 icr = er32(ICR); | |
1756 | ||
e921eb1a | 1757 | /* read ICR disables interrupts using IAM */ |
573cca8c | 1758 | if (icr & E1000_ICR_LSC) { |
f92518dd | 1759 | hw->mac.get_link_status = true; |
e921eb1a | 1760 | /* ICH8 workaround-- Call gig speed drop workaround on cable |
ad68076e BA |
1761 | * disconnect (LSC) before accessing any PHY registers |
1762 | */ | |
bc7f75fa AK |
1763 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
1764 | (!(er32(STATUS) & E1000_STATUS_LU))) | |
a8f88ff5 | 1765 | schedule_work(&adapter->downshift_task); |
bc7f75fa | 1766 | |
e921eb1a | 1767 | /* 80003ES2LAN workaround-- For packet buffer work-around on |
bc7f75fa | 1768 | * link down event; disable receives here in the ISR and reset |
ad68076e BA |
1769 | * adapter in watchdog |
1770 | */ | |
bc7f75fa AK |
1771 | if (netif_carrier_ok(netdev) && |
1772 | adapter->flags & FLAG_RX_NEEDS_RESTART) { | |
1773 | /* disable receives */ | |
1774 | u32 rctl = er32(RCTL); | |
6cf08d1c | 1775 | |
bc7f75fa | 1776 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
12d43f7d | 1777 | adapter->flags |= FLAG_RESTART_NOW; |
bc7f75fa AK |
1778 | } |
1779 | /* guard against interrupt when we're going down */ | |
1780 | if (!test_bit(__E1000_DOWN, &adapter->state)) | |
b4275924 | 1781 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
bc7f75fa AK |
1782 | } |
1783 | ||
94fb848b | 1784 | /* Reset on uncorrectable ECC error */ |
c8744f44 | 1785 | if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) { |
94fb848b BA |
1786 | u32 pbeccsts = er32(PBECCSTS); |
1787 | ||
1788 | adapter->corr_errors += | |
1789 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; | |
1790 | adapter->uncorr_errors += | |
1791 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> | |
1792 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; | |
1793 | ||
1794 | /* Do the reset outside of interrupt context */ | |
1795 | schedule_work(&adapter->reset_task); | |
1796 | ||
1797 | /* return immediately since reset is imminent */ | |
1798 | return IRQ_HANDLED; | |
1799 | } | |
1800 | ||
288379f0 | 1801 | if (napi_schedule_prep(&adapter->napi)) { |
bc7f75fa AK |
1802 | adapter->total_tx_bytes = 0; |
1803 | adapter->total_tx_packets = 0; | |
1804 | adapter->total_rx_bytes = 0; | |
1805 | adapter->total_rx_packets = 0; | |
288379f0 | 1806 | __napi_schedule(&adapter->napi); |
bc7f75fa AK |
1807 | } |
1808 | ||
1809 | return IRQ_HANDLED; | |
1810 | } | |
1811 | ||
1812 | /** | |
1813 | * e1000_intr - Interrupt Handler | |
1814 | * @irq: interrupt number | |
1815 | * @data: pointer to a network interface device structure | |
1816 | **/ | |
8bb62869 | 1817 | static irqreturn_t e1000_intr(int __always_unused irq, void *data) |
bc7f75fa AK |
1818 | { |
1819 | struct net_device *netdev = data; | |
1820 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
1821 | struct e1000_hw *hw = &adapter->hw; | |
bc7f75fa | 1822 | u32 rctl, icr = er32(ICR); |
4662e82b | 1823 | |
a68ea775 | 1824 | if (!icr || test_bit(__E1000_DOWN, &adapter->state)) |
e80bd1d1 | 1825 | return IRQ_NONE; /* Not our interrupt */ |
bc7f75fa | 1826 | |
e921eb1a | 1827 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
ad68076e BA |
1828 | * not set, then the adapter didn't send an interrupt |
1829 | */ | |
bc7f75fa AK |
1830 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
1831 | return IRQ_NONE; | |
1832 | ||
e921eb1a | 1833 | /* Interrupt Auto-Mask...upon reading ICR, |
ad68076e BA |
1834 | * interrupts are masked. No need for the |
1835 | * IMC write | |
1836 | */ | |
bc7f75fa | 1837 | |
573cca8c | 1838 | if (icr & E1000_ICR_LSC) { |
f92518dd | 1839 | hw->mac.get_link_status = true; |
e921eb1a | 1840 | /* ICH8 workaround-- Call gig speed drop workaround on cable |
ad68076e BA |
1841 | * disconnect (LSC) before accessing any PHY registers |
1842 | */ | |
bc7f75fa AK |
1843 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
1844 | (!(er32(STATUS) & E1000_STATUS_LU))) | |
a8f88ff5 | 1845 | schedule_work(&adapter->downshift_task); |
bc7f75fa | 1846 | |
e921eb1a | 1847 | /* 80003ES2LAN workaround-- |
bc7f75fa AK |
1848 | * For packet buffer work-around on link down event; |
1849 | * disable receives here in the ISR and | |
1850 | * reset adapter in watchdog | |
1851 | */ | |
1852 | if (netif_carrier_ok(netdev) && | |
1853 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { | |
1854 | /* disable receives */ | |
1855 | rctl = er32(RCTL); | |
1856 | ew32(RCTL, rctl & ~E1000_RCTL_EN); | |
12d43f7d | 1857 | adapter->flags |= FLAG_RESTART_NOW; |
bc7f75fa AK |
1858 | } |
1859 | /* guard against interrupt when we're going down */ | |
1860 | if (!test_bit(__E1000_DOWN, &adapter->state)) | |
b4275924 | 1861 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
bc7f75fa AK |
1862 | } |
1863 | ||
94fb848b | 1864 | /* Reset on uncorrectable ECC error */ |
c8744f44 | 1865 | if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) { |
94fb848b BA |
1866 | u32 pbeccsts = er32(PBECCSTS); |
1867 | ||
1868 | adapter->corr_errors += | |
1869 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; | |
1870 | adapter->uncorr_errors += | |
1871 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> | |
1872 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; | |
1873 | ||
1874 | /* Do the reset outside of interrupt context */ | |
1875 | schedule_work(&adapter->reset_task); | |
1876 | ||
1877 | /* return immediately since reset is imminent */ | |
1878 | return IRQ_HANDLED; | |
1879 | } | |
1880 | ||
288379f0 | 1881 | if (napi_schedule_prep(&adapter->napi)) { |
bc7f75fa AK |
1882 | adapter->total_tx_bytes = 0; |
1883 | adapter->total_tx_packets = 0; | |
1884 | adapter->total_rx_bytes = 0; | |
1885 | adapter->total_rx_packets = 0; | |
288379f0 | 1886 | __napi_schedule(&adapter->napi); |
bc7f75fa AK |
1887 | } |
1888 | ||
1889 | return IRQ_HANDLED; | |
1890 | } | |
1891 | ||
8bb62869 | 1892 | static irqreturn_t e1000_msix_other(int __always_unused irq, void *data) |
4662e82b BA |
1893 | { |
1894 | struct net_device *netdev = data; | |
1895 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
1896 | struct e1000_hw *hw = &adapter->hw; | |
116f4a64 | 1897 | u32 icr = er32(ICR); |
745d0bd3 | 1898 | |
361a954e BP |
1899 | if (icr & adapter->eiac_mask) |
1900 | ew32(ICS, (icr & adapter->eiac_mask)); | |
1901 | ||
4aea7a5c | 1902 | if (icr & E1000_ICR_LSC) { |
4aea7a5c BP |
1903 | hw->mac.get_link_status = true; |
1904 | /* guard against interrupt when we're going down */ | |
1905 | if (!test_bit(__E1000_DOWN, &adapter->state)) | |
b4275924 | 1906 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
4aea7a5c | 1907 | } |
4662e82b | 1908 | |
1f0ea197 | 1909 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
116f4a64 | 1910 | ew32(IMS, E1000_IMS_OTHER | IMS_OTHER_MASK); |
4662e82b | 1911 | |
4662e82b BA |
1912 | return IRQ_HANDLED; |
1913 | } | |
1914 | ||
8bb62869 | 1915 | static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data) |
4662e82b BA |
1916 | { |
1917 | struct net_device *netdev = data; | |
1918 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
1919 | struct e1000_hw *hw = &adapter->hw; | |
1920 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
1921 | ||
4662e82b BA |
1922 | adapter->total_tx_bytes = 0; |
1923 | adapter->total_tx_packets = 0; | |
1924 | ||
55aa6985 | 1925 | if (!e1000_clean_tx_irq(tx_ring)) |
4662e82b BA |
1926 | /* Ring was not completely cleaned, so fire another interrupt */ |
1927 | ew32(ICS, tx_ring->ims_val); | |
1928 | ||
0a8047ac BP |
1929 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
1930 | ew32(IMS, adapter->tx_ring->ims_val); | |
1931 | ||
4662e82b BA |
1932 | return IRQ_HANDLED; |
1933 | } | |
1934 | ||
8bb62869 | 1935 | static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data) |
4662e82b BA |
1936 | { |
1937 | struct net_device *netdev = data; | |
1938 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
55aa6985 | 1939 | struct e1000_ring *rx_ring = adapter->rx_ring; |
4662e82b BA |
1940 | |
1941 | /* Write the ITR value calculated at the end of the | |
1942 | * previous interrupt. | |
1943 | */ | |
55aa6985 | 1944 | if (rx_ring->set_itr) { |
b77ac46b DF |
1945 | u32 itr = rx_ring->itr_val ? |
1946 | 1000000000 / (rx_ring->itr_val * 256) : 0; | |
1947 | ||
1948 | writel(itr, rx_ring->itr_register); | |
55aa6985 | 1949 | rx_ring->set_itr = 0; |
4662e82b BA |
1950 | } |
1951 | ||
288379f0 | 1952 | if (napi_schedule_prep(&adapter->napi)) { |
4662e82b BA |
1953 | adapter->total_rx_bytes = 0; |
1954 | adapter->total_rx_packets = 0; | |
288379f0 | 1955 | __napi_schedule(&adapter->napi); |
4662e82b BA |
1956 | } |
1957 | return IRQ_HANDLED; | |
1958 | } | |
1959 | ||
1960 | /** | |
1961 | * e1000_configure_msix - Configure MSI-X hardware | |
1962 | * | |
1963 | * e1000_configure_msix sets up the hardware to properly | |
1964 | * generate MSI-X interrupts. | |
1965 | **/ | |
1966 | static void e1000_configure_msix(struct e1000_adapter *adapter) | |
1967 | { | |
1968 | struct e1000_hw *hw = &adapter->hw; | |
1969 | struct e1000_ring *rx_ring = adapter->rx_ring; | |
1970 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
1971 | int vector = 0; | |
1972 | u32 ctrl_ext, ivar = 0; | |
1973 | ||
1974 | adapter->eiac_mask = 0; | |
1975 | ||
1976 | /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ | |
1977 | if (hw->mac.type == e1000_82574) { | |
1978 | u32 rfctl = er32(RFCTL); | |
6cf08d1c | 1979 | |
4662e82b BA |
1980 | rfctl |= E1000_RFCTL_ACK_DIS; |
1981 | ew32(RFCTL, rfctl); | |
1982 | } | |
1983 | ||
4662e82b BA |
1984 | /* Configure Rx vector */ |
1985 | rx_ring->ims_val = E1000_IMS_RXQ0; | |
1986 | adapter->eiac_mask |= rx_ring->ims_val; | |
1987 | if (rx_ring->itr_val) | |
1988 | writel(1000000000 / (rx_ring->itr_val * 256), | |
c5083cf6 | 1989 | rx_ring->itr_register); |
4662e82b | 1990 | else |
c5083cf6 | 1991 | writel(1, rx_ring->itr_register); |
4662e82b BA |
1992 | ivar = E1000_IVAR_INT_ALLOC_VALID | vector; |
1993 | ||
1994 | /* Configure Tx vector */ | |
1995 | tx_ring->ims_val = E1000_IMS_TXQ0; | |
1996 | vector++; | |
1997 | if (tx_ring->itr_val) | |
1998 | writel(1000000000 / (tx_ring->itr_val * 256), | |
c5083cf6 | 1999 | tx_ring->itr_register); |
4662e82b | 2000 | else |
c5083cf6 | 2001 | writel(1, tx_ring->itr_register); |
4662e82b BA |
2002 | adapter->eiac_mask |= tx_ring->ims_val; |
2003 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); | |
2004 | ||
2005 | /* set vector for Other Causes, e.g. link changes */ | |
2006 | vector++; | |
2007 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); | |
2008 | if (rx_ring->itr_val) | |
2009 | writel(1000000000 / (rx_ring->itr_val * 256), | |
2010 | hw->hw_addr + E1000_EITR_82574(vector)); | |
2011 | else | |
2012 | writel(1, hw->hw_addr + E1000_EITR_82574(vector)); | |
2013 | ||
2014 | /* Cause Tx interrupts on every write back */ | |
18dd2392 | 2015 | ivar |= BIT(31); |
4662e82b BA |
2016 | |
2017 | ew32(IVAR, ivar); | |
2018 | ||
2019 | /* enable MSI-X PBA support */ | |
0a8047ac BP |
2020 | ctrl_ext = er32(CTRL_EXT) & ~E1000_CTRL_EXT_IAME; |
2021 | ctrl_ext |= E1000_CTRL_EXT_PBA_CLR | E1000_CTRL_EXT_EIAME; | |
4662e82b BA |
2022 | ew32(CTRL_EXT, ctrl_ext); |
2023 | e1e_flush(); | |
2024 | } | |
2025 | ||
2026 | void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) | |
2027 | { | |
2028 | if (adapter->msix_entries) { | |
2029 | pci_disable_msix(adapter->pdev); | |
2030 | kfree(adapter->msix_entries); | |
2031 | adapter->msix_entries = NULL; | |
2032 | } else if (adapter->flags & FLAG_MSI_ENABLED) { | |
2033 | pci_disable_msi(adapter->pdev); | |
2034 | adapter->flags &= ~FLAG_MSI_ENABLED; | |
2035 | } | |
4662e82b BA |
2036 | } |
2037 | ||
2038 | /** | |
2039 | * e1000e_set_interrupt_capability - set MSI or MSI-X if supported | |
2040 | * | |
2041 | * Attempt to configure interrupts using the best available | |
2042 | * capabilities of the hardware and kernel. | |
2043 | **/ | |
2044 | void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) | |
2045 | { | |
2046 | int err; | |
8e86acd7 | 2047 | int i; |
4662e82b BA |
2048 | |
2049 | switch (adapter->int_mode) { | |
2050 | case E1000E_INT_MODE_MSIX: | |
2051 | if (adapter->flags & FLAG_HAS_MSIX) { | |
8e86acd7 JK |
2052 | adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */ |
2053 | adapter->msix_entries = kcalloc(adapter->num_vectors, | |
17e813ec BA |
2054 | sizeof(struct |
2055 | msix_entry), | |
2056 | GFP_KERNEL); | |
4662e82b | 2057 | if (adapter->msix_entries) { |
0cc7c959 AG |
2058 | struct e1000_adapter *a = adapter; |
2059 | ||
8e86acd7 | 2060 | for (i = 0; i < adapter->num_vectors; i++) |
4662e82b BA |
2061 | adapter->msix_entries[i].entry = i; |
2062 | ||
0cc7c959 AG |
2063 | err = pci_enable_msix_range(a->pdev, |
2064 | a->msix_entries, | |
2065 | a->num_vectors, | |
2066 | a->num_vectors); | |
2067 | if (err > 0) | |
4662e82b BA |
2068 | return; |
2069 | } | |
2070 | /* MSI-X failed, so fall through and try MSI */ | |
ef456f85 | 2071 | e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n"); |
4662e82b BA |
2072 | e1000e_reset_interrupt_capability(adapter); |
2073 | } | |
2074 | adapter->int_mode = E1000E_INT_MODE_MSI; | |
2075 | /* Fall through */ | |
2076 | case E1000E_INT_MODE_MSI: | |
2077 | if (!pci_enable_msi(adapter->pdev)) { | |
2078 | adapter->flags |= FLAG_MSI_ENABLED; | |
2079 | } else { | |
2080 | adapter->int_mode = E1000E_INT_MODE_LEGACY; | |
ef456f85 | 2081 | e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n"); |
4662e82b BA |
2082 | } |
2083 | /* Fall through */ | |
2084 | case E1000E_INT_MODE_LEGACY: | |
2085 | /* Don't do anything; this is the system default */ | |
2086 | break; | |
2087 | } | |
8e86acd7 JK |
2088 | |
2089 | /* store the number of vectors being used */ | |
2090 | adapter->num_vectors = 1; | |
4662e82b BA |
2091 | } |
2092 | ||
2093 | /** | |
2094 | * e1000_request_msix - Initialize MSI-X interrupts | |
2095 | * | |
2096 | * e1000_request_msix allocates MSI-X vectors and requests interrupts from the | |
2097 | * kernel. | |
2098 | **/ | |
2099 | static int e1000_request_msix(struct e1000_adapter *adapter) | |
2100 | { | |
2101 | struct net_device *netdev = adapter->netdev; | |
2102 | int err = 0, vector = 0; | |
2103 | ||
2104 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) | |
79f5e840 BA |
2105 | snprintf(adapter->rx_ring->name, |
2106 | sizeof(adapter->rx_ring->name) - 1, | |
135e7245 | 2107 | "%.14s-rx-0", netdev->name); |
4662e82b BA |
2108 | else |
2109 | memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); | |
2110 | err = request_irq(adapter->msix_entries[vector].vector, | |
a0607fd3 | 2111 | e1000_intr_msix_rx, 0, adapter->rx_ring->name, |
4662e82b BA |
2112 | netdev); |
2113 | if (err) | |
5015e53a | 2114 | return err; |
c5083cf6 BA |
2115 | adapter->rx_ring->itr_register = adapter->hw.hw_addr + |
2116 | E1000_EITR_82574(vector); | |
4662e82b BA |
2117 | adapter->rx_ring->itr_val = adapter->itr; |
2118 | vector++; | |
2119 | ||
2120 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) | |
79f5e840 BA |
2121 | snprintf(adapter->tx_ring->name, |
2122 | sizeof(adapter->tx_ring->name) - 1, | |
135e7245 | 2123 | "%.14s-tx-0", netdev->name); |
4662e82b BA |
2124 | else |
2125 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); | |
2126 | err = request_irq(adapter->msix_entries[vector].vector, | |
a0607fd3 | 2127 | e1000_intr_msix_tx, 0, adapter->tx_ring->name, |
4662e82b BA |
2128 | netdev); |
2129 | if (err) | |
5015e53a | 2130 | return err; |
c5083cf6 BA |
2131 | adapter->tx_ring->itr_register = adapter->hw.hw_addr + |
2132 | E1000_EITR_82574(vector); | |
4662e82b BA |
2133 | adapter->tx_ring->itr_val = adapter->itr; |
2134 | vector++; | |
2135 | ||
2136 | err = request_irq(adapter->msix_entries[vector].vector, | |
a0607fd3 | 2137 | e1000_msix_other, 0, netdev->name, netdev); |
4662e82b | 2138 | if (err) |
5015e53a | 2139 | return err; |
4662e82b BA |
2140 | |
2141 | e1000_configure_msix(adapter); | |
5015e53a | 2142 | |
4662e82b | 2143 | return 0; |
4662e82b BA |
2144 | } |
2145 | ||
f8d59f78 BA |
2146 | /** |
2147 | * e1000_request_irq - initialize interrupts | |
2148 | * | |
2149 | * Attempts to configure interrupts using the best available | |
2150 | * capabilities of the hardware and kernel. | |
2151 | **/ | |
bc7f75fa AK |
2152 | static int e1000_request_irq(struct e1000_adapter *adapter) |
2153 | { | |
2154 | struct net_device *netdev = adapter->netdev; | |
bc7f75fa AK |
2155 | int err; |
2156 | ||
4662e82b BA |
2157 | if (adapter->msix_entries) { |
2158 | err = e1000_request_msix(adapter); | |
2159 | if (!err) | |
2160 | return err; | |
2161 | /* fall back to MSI */ | |
2162 | e1000e_reset_interrupt_capability(adapter); | |
2163 | adapter->int_mode = E1000E_INT_MODE_MSI; | |
2164 | e1000e_set_interrupt_capability(adapter); | |
bc7f75fa | 2165 | } |
4662e82b | 2166 | if (adapter->flags & FLAG_MSI_ENABLED) { |
a0607fd3 | 2167 | err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, |
4662e82b BA |
2168 | netdev->name, netdev); |
2169 | if (!err) | |
2170 | return err; | |
bc7f75fa | 2171 | |
4662e82b BA |
2172 | /* fall back to legacy interrupt */ |
2173 | e1000e_reset_interrupt_capability(adapter); | |
2174 | adapter->int_mode = E1000E_INT_MODE_LEGACY; | |
bc7f75fa AK |
2175 | } |
2176 | ||
a0607fd3 | 2177 | err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, |
4662e82b BA |
2178 | netdev->name, netdev); |
2179 | if (err) | |
2180 | e_err("Unable to allocate interrupt, Error: %d\n", err); | |
2181 | ||
bc7f75fa AK |
2182 | return err; |
2183 | } | |
2184 | ||
2185 | static void e1000_free_irq(struct e1000_adapter *adapter) | |
2186 | { | |
2187 | struct net_device *netdev = adapter->netdev; | |
2188 | ||
4662e82b BA |
2189 | if (adapter->msix_entries) { |
2190 | int vector = 0; | |
2191 | ||
2192 | free_irq(adapter->msix_entries[vector].vector, netdev); | |
2193 | vector++; | |
2194 | ||
2195 | free_irq(adapter->msix_entries[vector].vector, netdev); | |
2196 | vector++; | |
2197 | ||
2198 | /* Other Causes interrupt vector */ | |
2199 | free_irq(adapter->msix_entries[vector].vector, netdev); | |
2200 | return; | |
bc7f75fa | 2201 | } |
4662e82b BA |
2202 | |
2203 | free_irq(adapter->pdev->irq, netdev); | |
bc7f75fa AK |
2204 | } |
2205 | ||
2206 | /** | |
2207 | * e1000_irq_disable - Mask off interrupt generation on the NIC | |
2208 | **/ | |
2209 | static void e1000_irq_disable(struct e1000_adapter *adapter) | |
2210 | { | |
2211 | struct e1000_hw *hw = &adapter->hw; | |
2212 | ||
bc7f75fa | 2213 | ew32(IMC, ~0); |
4662e82b BA |
2214 | if (adapter->msix_entries) |
2215 | ew32(EIAC_82574, 0); | |
bc7f75fa | 2216 | e1e_flush(); |
8e86acd7 JK |
2217 | |
2218 | if (adapter->msix_entries) { | |
2219 | int i; | |
6cf08d1c | 2220 | |
8e86acd7 JK |
2221 | for (i = 0; i < adapter->num_vectors; i++) |
2222 | synchronize_irq(adapter->msix_entries[i].vector); | |
2223 | } else { | |
2224 | synchronize_irq(adapter->pdev->irq); | |
2225 | } | |
bc7f75fa AK |
2226 | } |
2227 | ||
2228 | /** | |
2229 | * e1000_irq_enable - Enable default interrupt generation settings | |
2230 | **/ | |
2231 | static void e1000_irq_enable(struct e1000_adapter *adapter) | |
2232 | { | |
2233 | struct e1000_hw *hw = &adapter->hw; | |
2234 | ||
4662e82b BA |
2235 | if (adapter->msix_entries) { |
2236 | ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); | |
116f4a64 BP |
2237 | ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | |
2238 | IMS_OTHER_MASK); | |
c8744f44 | 2239 | } else if (hw->mac.type >= e1000_pch_lpt) { |
94fb848b | 2240 | ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER); |
4662e82b BA |
2241 | } else { |
2242 | ew32(IMS, IMS_ENABLE_MASK); | |
2243 | } | |
74ef9c39 | 2244 | e1e_flush(); |
bc7f75fa AK |
2245 | } |
2246 | ||
2247 | /** | |
31dbe5b4 | 2248 | * e1000e_get_hw_control - get control of the h/w from f/w |
bc7f75fa AK |
2249 | * @adapter: address of board private structure |
2250 | * | |
31dbe5b4 | 2251 | * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
bc7f75fa AK |
2252 | * For ASF and Pass Through versions of f/w this means that |
2253 | * the driver is loaded. For AMT version (only with 82573) | |
2254 | * of the f/w this means that the network i/f is open. | |
2255 | **/ | |
31dbe5b4 | 2256 | void e1000e_get_hw_control(struct e1000_adapter *adapter) |
bc7f75fa AK |
2257 | { |
2258 | struct e1000_hw *hw = &adapter->hw; | |
2259 | u32 ctrl_ext; | |
2260 | u32 swsm; | |
2261 | ||
2262 | /* Let firmware know the driver has taken over */ | |
2263 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { | |
2264 | swsm = er32(SWSM); | |
2265 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); | |
2266 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { | |
2267 | ctrl_ext = er32(CTRL_EXT); | |
ad68076e | 2268 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
bc7f75fa AK |
2269 | } |
2270 | } | |
2271 | ||
2272 | /** | |
31dbe5b4 | 2273 | * e1000e_release_hw_control - release control of the h/w to f/w |
bc7f75fa AK |
2274 | * @adapter: address of board private structure |
2275 | * | |
31dbe5b4 | 2276 | * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
bc7f75fa AK |
2277 | * For ASF and Pass Through versions of f/w this means that the |
2278 | * driver is no longer loaded. For AMT version (only with 82573) i | |
2279 | * of the f/w this means that the network i/f is closed. | |
2280 | * | |
2281 | **/ | |
31dbe5b4 | 2282 | void e1000e_release_hw_control(struct e1000_adapter *adapter) |
bc7f75fa AK |
2283 | { |
2284 | struct e1000_hw *hw = &adapter->hw; | |
2285 | u32 ctrl_ext; | |
2286 | u32 swsm; | |
2287 | ||
2288 | /* Let firmware taken over control of h/w */ | |
2289 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { | |
2290 | swsm = er32(SWSM); | |
2291 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); | |
2292 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { | |
2293 | ctrl_ext = er32(CTRL_EXT); | |
ad68076e | 2294 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
bc7f75fa AK |
2295 | } |
2296 | } | |
2297 | ||
bc7f75fa | 2298 | /** |
49ce9c2c | 2299 | * e1000_alloc_ring_dma - allocate memory for a ring structure |
bc7f75fa AK |
2300 | **/ |
2301 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, | |
2302 | struct e1000_ring *ring) | |
2303 | { | |
2304 | struct pci_dev *pdev = adapter->pdev; | |
2305 | ||
750afb08 LC |
2306 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, |
2307 | GFP_KERNEL); | |
bc7f75fa AK |
2308 | if (!ring->desc) |
2309 | return -ENOMEM; | |
2310 | ||
2311 | return 0; | |
2312 | } | |
2313 | ||
2314 | /** | |
2315 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) | |
55aa6985 | 2316 | * @tx_ring: Tx descriptor ring |
bc7f75fa AK |
2317 | * |
2318 | * Return 0 on success, negative on failure | |
2319 | **/ | |
55aa6985 | 2320 | int e1000e_setup_tx_resources(struct e1000_ring *tx_ring) |
bc7f75fa | 2321 | { |
55aa6985 | 2322 | struct e1000_adapter *adapter = tx_ring->adapter; |
bc7f75fa AK |
2323 | int err = -ENOMEM, size; |
2324 | ||
2325 | size = sizeof(struct e1000_buffer) * tx_ring->count; | |
89bf67f1 | 2326 | tx_ring->buffer_info = vzalloc(size); |
bc7f75fa AK |
2327 | if (!tx_ring->buffer_info) |
2328 | goto err; | |
bc7f75fa AK |
2329 | |
2330 | /* round up to nearest 4K */ | |
2331 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); | |
2332 | tx_ring->size = ALIGN(tx_ring->size, 4096); | |
2333 | ||
2334 | err = e1000_alloc_ring_dma(adapter, tx_ring); | |
2335 | if (err) | |
2336 | goto err; | |
2337 | ||
2338 | tx_ring->next_to_use = 0; | |
2339 | tx_ring->next_to_clean = 0; | |
bc7f75fa AK |
2340 | |
2341 | return 0; | |
2342 | err: | |
2343 | vfree(tx_ring->buffer_info); | |
44defeb3 | 2344 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
bc7f75fa AK |
2345 | return err; |
2346 | } | |
2347 | ||
2348 | /** | |
2349 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) | |
55aa6985 | 2350 | * @rx_ring: Rx descriptor ring |
bc7f75fa AK |
2351 | * |
2352 | * Returns 0 on success, negative on failure | |
2353 | **/ | |
55aa6985 | 2354 | int e1000e_setup_rx_resources(struct e1000_ring *rx_ring) |
bc7f75fa | 2355 | { |
55aa6985 | 2356 | struct e1000_adapter *adapter = rx_ring->adapter; |
47f44e40 AK |
2357 | struct e1000_buffer *buffer_info; |
2358 | int i, size, desc_len, err = -ENOMEM; | |
bc7f75fa AK |
2359 | |
2360 | size = sizeof(struct e1000_buffer) * rx_ring->count; | |
89bf67f1 | 2361 | rx_ring->buffer_info = vzalloc(size); |
bc7f75fa AK |
2362 | if (!rx_ring->buffer_info) |
2363 | goto err; | |
bc7f75fa | 2364 | |
47f44e40 AK |
2365 | for (i = 0; i < rx_ring->count; i++) { |
2366 | buffer_info = &rx_ring->buffer_info[i]; | |
2367 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, | |
2368 | sizeof(struct e1000_ps_page), | |
2369 | GFP_KERNEL); | |
2370 | if (!buffer_info->ps_pages) | |
2371 | goto err_pages; | |
2372 | } | |
bc7f75fa AK |
2373 | |
2374 | desc_len = sizeof(union e1000_rx_desc_packet_split); | |
2375 | ||
2376 | /* Round up to nearest 4K */ | |
2377 | rx_ring->size = rx_ring->count * desc_len; | |
2378 | rx_ring->size = ALIGN(rx_ring->size, 4096); | |
2379 | ||
2380 | err = e1000_alloc_ring_dma(adapter, rx_ring); | |
2381 | if (err) | |
47f44e40 | 2382 | goto err_pages; |
bc7f75fa AK |
2383 | |
2384 | rx_ring->next_to_clean = 0; | |
2385 | rx_ring->next_to_use = 0; | |
2386 | rx_ring->rx_skb_top = NULL; | |
2387 | ||
2388 | return 0; | |
47f44e40 AK |
2389 | |
2390 | err_pages: | |
2391 | for (i = 0; i < rx_ring->count; i++) { | |
2392 | buffer_info = &rx_ring->buffer_info[i]; | |
2393 | kfree(buffer_info->ps_pages); | |
2394 | } | |
bc7f75fa AK |
2395 | err: |
2396 | vfree(rx_ring->buffer_info); | |
e9262447 | 2397 | e_err("Unable to allocate memory for the receive descriptor ring\n"); |
bc7f75fa AK |
2398 | return err; |
2399 | } | |
2400 | ||
2401 | /** | |
2402 | * e1000_clean_tx_ring - Free Tx Buffers | |
55aa6985 | 2403 | * @tx_ring: Tx descriptor ring |
bc7f75fa | 2404 | **/ |
55aa6985 | 2405 | static void e1000_clean_tx_ring(struct e1000_ring *tx_ring) |
bc7f75fa | 2406 | { |
55aa6985 | 2407 | struct e1000_adapter *adapter = tx_ring->adapter; |
bc7f75fa AK |
2408 | struct e1000_buffer *buffer_info; |
2409 | unsigned long size; | |
2410 | unsigned int i; | |
2411 | ||
2412 | for (i = 0; i < tx_ring->count; i++) { | |
2413 | buffer_info = &tx_ring->buffer_info[i]; | |
377b6273 | 2414 | e1000_put_txbuf(tx_ring, buffer_info, false); |
bc7f75fa AK |
2415 | } |
2416 | ||
3f0cfa3b | 2417 | netdev_reset_queue(adapter->netdev); |
bc7f75fa AK |
2418 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
2419 | memset(tx_ring->buffer_info, 0, size); | |
2420 | ||
2421 | memset(tx_ring->desc, 0, tx_ring->size); | |
2422 | ||
2423 | tx_ring->next_to_use = 0; | |
2424 | tx_ring->next_to_clean = 0; | |
bc7f75fa AK |
2425 | } |
2426 | ||
2427 | /** | |
2428 | * e1000e_free_tx_resources - Free Tx Resources per Queue | |
55aa6985 | 2429 | * @tx_ring: Tx descriptor ring |
bc7f75fa AK |
2430 | * |
2431 | * Free all transmit software resources | |
2432 | **/ | |
55aa6985 | 2433 | void e1000e_free_tx_resources(struct e1000_ring *tx_ring) |
bc7f75fa | 2434 | { |
55aa6985 | 2435 | struct e1000_adapter *adapter = tx_ring->adapter; |
bc7f75fa | 2436 | struct pci_dev *pdev = adapter->pdev; |
bc7f75fa | 2437 | |
55aa6985 | 2438 | e1000_clean_tx_ring(tx_ring); |
bc7f75fa AK |
2439 | |
2440 | vfree(tx_ring->buffer_info); | |
2441 | tx_ring->buffer_info = NULL; | |
2442 | ||
2443 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, | |
2444 | tx_ring->dma); | |
2445 | tx_ring->desc = NULL; | |
2446 | } | |
2447 | ||
2448 | /** | |
2449 | * e1000e_free_rx_resources - Free Rx Resources | |
55aa6985 | 2450 | * @rx_ring: Rx descriptor ring |
bc7f75fa AK |
2451 | * |
2452 | * Free all receive software resources | |
2453 | **/ | |
55aa6985 | 2454 | void e1000e_free_rx_resources(struct e1000_ring *rx_ring) |
bc7f75fa | 2455 | { |
55aa6985 | 2456 | struct e1000_adapter *adapter = rx_ring->adapter; |
bc7f75fa | 2457 | struct pci_dev *pdev = adapter->pdev; |
47f44e40 | 2458 | int i; |
bc7f75fa | 2459 | |
55aa6985 | 2460 | e1000_clean_rx_ring(rx_ring); |
bc7f75fa | 2461 | |
b1cdfead | 2462 | for (i = 0; i < rx_ring->count; i++) |
47f44e40 | 2463 | kfree(rx_ring->buffer_info[i].ps_pages); |
47f44e40 | 2464 | |
bc7f75fa AK |
2465 | vfree(rx_ring->buffer_info); |
2466 | rx_ring->buffer_info = NULL; | |
2467 | ||
bc7f75fa AK |
2468 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
2469 | rx_ring->dma); | |
2470 | rx_ring->desc = NULL; | |
2471 | } | |
2472 | ||
2473 | /** | |
2474 | * e1000_update_itr - update the dynamic ITR value based on statistics | |
489815ce AK |
2475 | * @adapter: pointer to adapter |
2476 | * @itr_setting: current adapter->itr | |
2477 | * @packets: the number of packets during this measurement interval | |
2478 | * @bytes: the number of bytes during this measurement interval | |
2479 | * | |
bc7f75fa AK |
2480 | * Stores a new ITR value based on packets and byte |
2481 | * counts during the last interrupt. The advantage of per interrupt | |
2482 | * computation is faster updates and more accurate ITR for the current | |
2483 | * traffic pattern. Constants in this function were computed | |
2484 | * based on theoretical maximum wire speed and thresholds were set based | |
2485 | * on testing data as well as attempting to minimize response time | |
4662e82b BA |
2486 | * while increasing bulk throughput. This functionality is controlled |
2487 | * by the InterruptThrottleRate module parameter. | |
bc7f75fa | 2488 | **/ |
8bb62869 | 2489 | static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes) |
bc7f75fa AK |
2490 | { |
2491 | unsigned int retval = itr_setting; | |
2492 | ||
2493 | if (packets == 0) | |
5015e53a | 2494 | return itr_setting; |
bc7f75fa AK |
2495 | |
2496 | switch (itr_setting) { | |
2497 | case lowest_latency: | |
2498 | /* handle TSO and jumbo frames */ | |
362e20ca | 2499 | if (bytes / packets > 8000) |
bc7f75fa | 2500 | retval = bulk_latency; |
b1cdfead | 2501 | else if ((packets < 5) && (bytes > 512)) |
bc7f75fa | 2502 | retval = low_latency; |
bc7f75fa | 2503 | break; |
e80bd1d1 | 2504 | case low_latency: /* 50 usec aka 20000 ints/s */ |
bc7f75fa AK |
2505 | if (bytes > 10000) { |
2506 | /* this if handles the TSO accounting */ | |
362e20ca | 2507 | if (bytes / packets > 8000) |
bc7f75fa | 2508 | retval = bulk_latency; |
362e20ca | 2509 | else if ((packets < 10) || ((bytes / packets) > 1200)) |
bc7f75fa | 2510 | retval = bulk_latency; |
b1cdfead | 2511 | else if ((packets > 35)) |
bc7f75fa | 2512 | retval = lowest_latency; |
362e20ca | 2513 | } else if (bytes / packets > 2000) { |
bc7f75fa AK |
2514 | retval = bulk_latency; |
2515 | } else if (packets <= 2 && bytes < 512) { | |
2516 | retval = lowest_latency; | |
2517 | } | |
2518 | break; | |
e80bd1d1 | 2519 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
bc7f75fa | 2520 | if (bytes > 25000) { |
b1cdfead | 2521 | if (packets > 35) |
bc7f75fa | 2522 | retval = low_latency; |
bc7f75fa AK |
2523 | } else if (bytes < 6000) { |
2524 | retval = low_latency; | |
2525 | } | |
2526 | break; | |
2527 | } | |
2528 | ||
bc7f75fa AK |
2529 | return retval; |
2530 | } | |
2531 | ||
2532 | static void e1000_set_itr(struct e1000_adapter *adapter) | |
2533 | { | |
bc7f75fa AK |
2534 | u16 current_itr; |
2535 | u32 new_itr = adapter->itr; | |
2536 | ||
2537 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ | |
2538 | if (adapter->link_speed != SPEED_1000) { | |
2539 | current_itr = 0; | |
2540 | new_itr = 4000; | |
2541 | goto set_itr_now; | |
2542 | } | |
2543 | ||
828bac87 BA |
2544 | if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
2545 | new_itr = 0; | |
2546 | goto set_itr_now; | |
2547 | } | |
2548 | ||
8bb62869 BA |
2549 | adapter->tx_itr = e1000_update_itr(adapter->tx_itr, |
2550 | adapter->total_tx_packets, | |
2551 | adapter->total_tx_bytes); | |
bc7f75fa AK |
2552 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
2553 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) | |
2554 | adapter->tx_itr = low_latency; | |
2555 | ||
8bb62869 BA |
2556 | adapter->rx_itr = e1000_update_itr(adapter->rx_itr, |
2557 | adapter->total_rx_packets, | |
2558 | adapter->total_rx_bytes); | |
bc7f75fa AK |
2559 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
2560 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) | |
2561 | adapter->rx_itr = low_latency; | |
2562 | ||
2563 | current_itr = max(adapter->rx_itr, adapter->tx_itr); | |
2564 | ||
bc7f75fa | 2565 | /* counts and packets in update_itr are dependent on these numbers */ |
33550cec | 2566 | switch (current_itr) { |
bc7f75fa AK |
2567 | case lowest_latency: |
2568 | new_itr = 70000; | |
2569 | break; | |
2570 | case low_latency: | |
e80bd1d1 | 2571 | new_itr = 20000; /* aka hwitr = ~200 */ |
bc7f75fa AK |
2572 | break; |
2573 | case bulk_latency: | |
2574 | new_itr = 4000; | |
2575 | break; | |
2576 | default: | |
2577 | break; | |
2578 | } | |
2579 | ||
2580 | set_itr_now: | |
2581 | if (new_itr != adapter->itr) { | |
e921eb1a | 2582 | /* this attempts to bias the interrupt rate towards Bulk |
bc7f75fa | 2583 | * by adding intermediate steps when interrupt rate is |
ad68076e BA |
2584 | * increasing |
2585 | */ | |
bc7f75fa | 2586 | new_itr = new_itr > adapter->itr ? |
f0ff4398 | 2587 | min(adapter->itr + (new_itr >> 2), new_itr) : new_itr; |
bc7f75fa | 2588 | adapter->itr = new_itr; |
4662e82b BA |
2589 | adapter->rx_ring->itr_val = new_itr; |
2590 | if (adapter->msix_entries) | |
2591 | adapter->rx_ring->set_itr = 1; | |
2592 | else | |
e3d14b08 | 2593 | e1000e_write_itr(adapter, new_itr); |
bc7f75fa AK |
2594 | } |
2595 | } | |
2596 | ||
22a4cca2 MV |
2597 | /** |
2598 | * e1000e_write_itr - write the ITR value to the appropriate registers | |
2599 | * @adapter: address of board private structure | |
2600 | * @itr: new ITR value to program | |
2601 | * | |
2602 | * e1000e_write_itr determines if the adapter is in MSI-X mode | |
2603 | * and, if so, writes the EITR registers with the ITR value. | |
2604 | * Otherwise, it writes the ITR value into the ITR register. | |
2605 | **/ | |
2606 | void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr) | |
2607 | { | |
2608 | struct e1000_hw *hw = &adapter->hw; | |
2609 | u32 new_itr = itr ? 1000000000 / (itr * 256) : 0; | |
2610 | ||
2611 | if (adapter->msix_entries) { | |
2612 | int vector; | |
2613 | ||
2614 | for (vector = 0; vector < adapter->num_vectors; vector++) | |
2615 | writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector)); | |
2616 | } else { | |
2617 | ew32(ITR, new_itr); | |
2618 | } | |
2619 | } | |
2620 | ||
4662e82b BA |
2621 | /** |
2622 | * e1000_alloc_queues - Allocate memory for all rings | |
2623 | * @adapter: board private structure to initialize | |
2624 | **/ | |
9f9a12f8 | 2625 | static int e1000_alloc_queues(struct e1000_adapter *adapter) |
4662e82b | 2626 | { |
55aa6985 BA |
2627 | int size = sizeof(struct e1000_ring); |
2628 | ||
2629 | adapter->tx_ring = kzalloc(size, GFP_KERNEL); | |
4662e82b BA |
2630 | if (!adapter->tx_ring) |
2631 | goto err; | |
55aa6985 BA |
2632 | adapter->tx_ring->count = adapter->tx_ring_count; |
2633 | adapter->tx_ring->adapter = adapter; | |
4662e82b | 2634 | |
55aa6985 | 2635 | adapter->rx_ring = kzalloc(size, GFP_KERNEL); |
4662e82b BA |
2636 | if (!adapter->rx_ring) |
2637 | goto err; | |
55aa6985 BA |
2638 | adapter->rx_ring->count = adapter->rx_ring_count; |
2639 | adapter->rx_ring->adapter = adapter; | |
4662e82b BA |
2640 | |
2641 | return 0; | |
2642 | err: | |
2643 | e_err("Unable to allocate memory for queues\n"); | |
2644 | kfree(adapter->rx_ring); | |
2645 | kfree(adapter->tx_ring); | |
2646 | return -ENOMEM; | |
2647 | } | |
2648 | ||
bc7f75fa | 2649 | /** |
c58c8a78 | 2650 | * e1000e_poll - NAPI Rx polling callback |
ad68076e | 2651 | * @napi: struct associated with this polling callback |
0bcd952f | 2652 | * @budget: number of packets driver is allowed to process this poll |
bc7f75fa | 2653 | **/ |
0bcd952f | 2654 | static int e1000e_poll(struct napi_struct *napi, int budget) |
bc7f75fa | 2655 | { |
c58c8a78 BA |
2656 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, |
2657 | napi); | |
4662e82b | 2658 | struct e1000_hw *hw = &adapter->hw; |
bc7f75fa | 2659 | struct net_device *poll_dev = adapter->netdev; |
679e8a0f | 2660 | int tx_cleaned = 1, work_done = 0; |
bc7f75fa | 2661 | |
4cf1653a | 2662 | adapter = netdev_priv(poll_dev); |
bc7f75fa | 2663 | |
c58c8a78 BA |
2664 | if (!adapter->msix_entries || |
2665 | (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) | |
2666 | tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring); | |
4662e82b | 2667 | |
0bcd952f | 2668 | adapter->clean_rx(adapter->rx_ring, &work_done, budget); |
d2c7ddd6 | 2669 | |
0bcd952f JB |
2670 | if (!tx_cleaned || work_done == budget) |
2671 | return budget; | |
bc7f75fa | 2672 | |
0bcd952f JB |
2673 | /* Exit the polling mode, but don't re-enable interrupts if stack might |
2674 | * poll us due to busy-polling | |
2675 | */ | |
2676 | if (likely(napi_complete_done(napi, work_done))) { | |
bc7f75fa AK |
2677 | if (adapter->itr_setting & 3) |
2678 | e1000_set_itr(adapter); | |
a3c69fef JB |
2679 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
2680 | if (adapter->msix_entries) | |
1f0ea197 | 2681 | ew32(IMS, adapter->rx_ring->ims_val); |
a3c69fef JB |
2682 | else |
2683 | e1000_irq_enable(adapter); | |
2684 | } | |
bc7f75fa AK |
2685 | } |
2686 | ||
2687 | return work_done; | |
2688 | } | |
2689 | ||
80d5c368 | 2690 | static int e1000_vlan_rx_add_vid(struct net_device *netdev, |
603cdca9 | 2691 | __always_unused __be16 proto, u16 vid) |
bc7f75fa AK |
2692 | { |
2693 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
2694 | struct e1000_hw *hw = &adapter->hw; | |
2695 | u32 vfta, index; | |
2696 | ||
2697 | /* don't update vlan cookie if already programmed */ | |
2698 | if ((adapter->hw.mng_cookie.status & | |
2699 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && | |
2700 | (vid == adapter->mng_vlan_id)) | |
8e586137 | 2701 | return 0; |
caaddaf8 | 2702 | |
bc7f75fa | 2703 | /* add VID to filter table */ |
caaddaf8 BA |
2704 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
2705 | index = (vid >> 5) & 0x7F; | |
2706 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); | |
18dd2392 | 2707 | vfta |= BIT((vid & 0x1F)); |
caaddaf8 BA |
2708 | hw->mac.ops.write_vfta(hw, index, vfta); |
2709 | } | |
86d70e53 JK |
2710 | |
2711 | set_bit(vid, adapter->active_vlans); | |
8e586137 JP |
2712 | |
2713 | return 0; | |
bc7f75fa AK |
2714 | } |
2715 | ||
80d5c368 | 2716 | static int e1000_vlan_rx_kill_vid(struct net_device *netdev, |
603cdca9 | 2717 | __always_unused __be16 proto, u16 vid) |
bc7f75fa AK |
2718 | { |
2719 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
2720 | struct e1000_hw *hw = &adapter->hw; | |
2721 | u32 vfta, index; | |
2722 | ||
bc7f75fa AK |
2723 | if ((adapter->hw.mng_cookie.status & |
2724 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && | |
2725 | (vid == adapter->mng_vlan_id)) { | |
2726 | /* release control to f/w */ | |
31dbe5b4 | 2727 | e1000e_release_hw_control(adapter); |
8e586137 | 2728 | return 0; |
bc7f75fa AK |
2729 | } |
2730 | ||
2731 | /* remove VID from filter table */ | |
caaddaf8 BA |
2732 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
2733 | index = (vid >> 5) & 0x7F; | |
2734 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); | |
18dd2392 | 2735 | vfta &= ~BIT((vid & 0x1F)); |
caaddaf8 BA |
2736 | hw->mac.ops.write_vfta(hw, index, vfta); |
2737 | } | |
86d70e53 JK |
2738 | |
2739 | clear_bit(vid, adapter->active_vlans); | |
8e586137 JP |
2740 | |
2741 | return 0; | |
bc7f75fa AK |
2742 | } |
2743 | ||
86d70e53 JK |
2744 | /** |
2745 | * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering | |
2746 | * @adapter: board private structure to initialize | |
2747 | **/ | |
2748 | static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter) | |
bc7f75fa AK |
2749 | { |
2750 | struct net_device *netdev = adapter->netdev; | |
86d70e53 JK |
2751 | struct e1000_hw *hw = &adapter->hw; |
2752 | u32 rctl; | |
bc7f75fa | 2753 | |
86d70e53 JK |
2754 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
2755 | /* disable VLAN receive filtering */ | |
2756 | rctl = er32(RCTL); | |
2757 | rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN); | |
2758 | ew32(RCTL, rctl); | |
2759 | ||
2760 | if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { | |
80d5c368 PM |
2761 | e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), |
2762 | adapter->mng_vlan_id); | |
86d70e53 | 2763 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
bc7f75fa | 2764 | } |
bc7f75fa AK |
2765 | } |
2766 | } | |
2767 | ||
86d70e53 JK |
2768 | /** |
2769 | * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering | |
2770 | * @adapter: board private structure to initialize | |
2771 | **/ | |
2772 | static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter) | |
2773 | { | |
2774 | struct e1000_hw *hw = &adapter->hw; | |
2775 | u32 rctl; | |
2776 | ||
2777 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { | |
2778 | /* enable VLAN receive filtering */ | |
2779 | rctl = er32(RCTL); | |
2780 | rctl |= E1000_RCTL_VFE; | |
2781 | rctl &= ~E1000_RCTL_CFIEN; | |
2782 | ew32(RCTL, rctl); | |
2783 | } | |
2784 | } | |
bc7f75fa | 2785 | |
86d70e53 | 2786 | /** |
889ad456 | 2787 | * e1000e_vlan_strip_disable - helper to disable HW VLAN stripping |
86d70e53 JK |
2788 | * @adapter: board private structure to initialize |
2789 | **/ | |
2790 | static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter) | |
bc7f75fa | 2791 | { |
bc7f75fa | 2792 | struct e1000_hw *hw = &adapter->hw; |
86d70e53 | 2793 | u32 ctrl; |
bc7f75fa | 2794 | |
86d70e53 JK |
2795 | /* disable VLAN tag insert/strip */ |
2796 | ctrl = er32(CTRL); | |
2797 | ctrl &= ~E1000_CTRL_VME; | |
2798 | ew32(CTRL, ctrl); | |
2799 | } | |
bc7f75fa | 2800 | |
86d70e53 JK |
2801 | /** |
2802 | * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping | |
2803 | * @adapter: board private structure to initialize | |
2804 | **/ | |
2805 | static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter) | |
2806 | { | |
2807 | struct e1000_hw *hw = &adapter->hw; | |
2808 | u32 ctrl; | |
bc7f75fa | 2809 | |
86d70e53 JK |
2810 | /* enable VLAN tag insert/strip */ |
2811 | ctrl = er32(CTRL); | |
2812 | ctrl |= E1000_CTRL_VME; | |
2813 | ew32(CTRL, ctrl); | |
2814 | } | |
bc7f75fa | 2815 | |
86d70e53 JK |
2816 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
2817 | { | |
2818 | struct net_device *netdev = adapter->netdev; | |
2819 | u16 vid = adapter->hw.mng_cookie.vlan_id; | |
2820 | u16 old_vid = adapter->mng_vlan_id; | |
2821 | ||
e5fe2541 | 2822 | if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
80d5c368 | 2823 | e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid); |
86d70e53 | 2824 | adapter->mng_vlan_id = vid; |
bc7f75fa AK |
2825 | } |
2826 | ||
86d70e53 | 2827 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid)) |
80d5c368 | 2828 | e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid); |
bc7f75fa AK |
2829 | } |
2830 | ||
2831 | static void e1000_restore_vlan(struct e1000_adapter *adapter) | |
2832 | { | |
2833 | u16 vid; | |
2834 | ||
80d5c368 | 2835 | e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
bc7f75fa | 2836 | |
86d70e53 | 2837 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
80d5c368 | 2838 | e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
bc7f75fa AK |
2839 | } |
2840 | ||
cd791618 | 2841 | static void e1000_init_manageability_pt(struct e1000_adapter *adapter) |
bc7f75fa AK |
2842 | { |
2843 | struct e1000_hw *hw = &adapter->hw; | |
cd791618 | 2844 | u32 manc, manc2h, mdef, i, j; |
bc7f75fa AK |
2845 | |
2846 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) | |
2847 | return; | |
2848 | ||
2849 | manc = er32(MANC); | |
2850 | ||
e921eb1a | 2851 | /* enable receiving management packets to the host. this will probably |
bc7f75fa | 2852 | * generate destination unreachable messages from the host OS, but |
ad68076e BA |
2853 | * the packets will be handled on SMBUS |
2854 | */ | |
bc7f75fa AK |
2855 | manc |= E1000_MANC_EN_MNG2HOST; |
2856 | manc2h = er32(MANC2H); | |
cd791618 BA |
2857 | |
2858 | switch (hw->mac.type) { | |
2859 | default: | |
2860 | manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664); | |
2861 | break; | |
2862 | case e1000_82574: | |
2863 | case e1000_82583: | |
e921eb1a | 2864 | /* Check if IPMI pass-through decision filter already exists; |
cd791618 BA |
2865 | * if so, enable it. |
2866 | */ | |
2867 | for (i = 0, j = 0; i < 8; i++) { | |
2868 | mdef = er32(MDEF(i)); | |
2869 | ||
2870 | /* Ignore filters with anything other than IPMI ports */ | |
3b21b508 | 2871 | if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
cd791618 BA |
2872 | continue; |
2873 | ||
2874 | /* Enable this decision filter in MANC2H */ | |
2875 | if (mdef) | |
18dd2392 | 2876 | manc2h |= BIT(i); |
cd791618 BA |
2877 | |
2878 | j |= mdef; | |
2879 | } | |
2880 | ||
2881 | if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) | |
2882 | break; | |
2883 | ||
2884 | /* Create new decision filter in an empty filter */ | |
2885 | for (i = 0, j = 0; i < 8; i++) | |
2886 | if (er32(MDEF(i)) == 0) { | |
2887 | ew32(MDEF(i), (E1000_MDEF_PORT_623 | | |
2888 | E1000_MDEF_PORT_664)); | |
18dd2392 | 2889 | manc2h |= BIT(1); |
cd791618 BA |
2890 | j++; |
2891 | break; | |
2892 | } | |
2893 | ||
2894 | if (!j) | |
2895 | e_warn("Unable to create IPMI pass-through filter\n"); | |
2896 | break; | |
2897 | } | |
2898 | ||
bc7f75fa AK |
2899 | ew32(MANC2H, manc2h); |
2900 | ew32(MANC, manc); | |
2901 | } | |
2902 | ||
2903 | /** | |
af667a29 | 2904 | * e1000_configure_tx - Configure Transmit Unit after Reset |
bc7f75fa AK |
2905 | * @adapter: board private structure |
2906 | * | |
2907 | * Configure the Tx unit of the MAC after a reset. | |
2908 | **/ | |
2909 | static void e1000_configure_tx(struct e1000_adapter *adapter) | |
2910 | { | |
2911 | struct e1000_hw *hw = &adapter->hw; | |
2912 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
2913 | u64 tdba; | |
e7e834aa | 2914 | u32 tdlen, tctl, tarc; |
bc7f75fa AK |
2915 | |
2916 | /* Setup the HW Tx Head and Tail descriptor pointers */ | |
2917 | tdba = tx_ring->dma; | |
2918 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); | |
1e36052e BA |
2919 | ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32))); |
2920 | ew32(TDBAH(0), (tdba >> 32)); | |
2921 | ew32(TDLEN(0), tdlen); | |
2922 | ew32(TDH(0), 0); | |
2923 | ew32(TDT(0), 0); | |
2924 | tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0); | |
2925 | tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0); | |
bc7f75fa | 2926 | |
0845d45e JJB |
2927 | writel(0, tx_ring->head); |
2928 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) | |
2929 | e1000e_update_tdt_wa(tx_ring, 0); | |
2930 | else | |
2931 | writel(0, tx_ring->tail); | |
2932 | ||
bc7f75fa AK |
2933 | /* Set the Tx Interrupt Delay register */ |
2934 | ew32(TIDV, adapter->tx_int_delay); | |
ad68076e | 2935 | /* Tx irq moderation */ |
bc7f75fa AK |
2936 | ew32(TADV, adapter->tx_abs_int_delay); |
2937 | ||
3a3b7586 JB |
2938 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
2939 | u32 txdctl = er32(TXDCTL(0)); | |
6cf08d1c | 2940 | |
3a3b7586 JB |
2941 | txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH | |
2942 | E1000_TXDCTL_WTHRESH); | |
e921eb1a | 2943 | /* set up some performance related parameters to encourage the |
3a3b7586 JB |
2944 | * hardware to use the bus more efficiently in bursts, depends |
2945 | * on the tx_int_delay to be enabled, | |
8edc0e62 | 2946 | * wthresh = 1 ==> burst write is disabled to avoid Tx stalls |
3a3b7586 JB |
2947 | * hthresh = 1 ==> prefetch when one or more available |
2948 | * pthresh = 0x1f ==> prefetch if internal cache 31 or less | |
2949 | * BEWARE: this seems to work but should be considered first if | |
af667a29 | 2950 | * there are Tx hangs or other Tx related bugs |
3a3b7586 JB |
2951 | */ |
2952 | txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE; | |
2953 | ew32(TXDCTL(0), txdctl); | |
3a3b7586 | 2954 | } |
56032be7 BA |
2955 | /* erratum work around: set txdctl the same for both queues */ |
2956 | ew32(TXDCTL(1), er32(TXDCTL(0))); | |
3a3b7586 | 2957 | |
e7e834aa DE |
2958 | /* Program the Transmit Control Register */ |
2959 | tctl = er32(TCTL); | |
2960 | tctl &= ~E1000_TCTL_CT; | |
2961 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | | |
2962 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); | |
2963 | ||
bc7f75fa | 2964 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { |
e9ec2c0f | 2965 | tarc = er32(TARC(0)); |
e921eb1a | 2966 | /* set the speed mode bit, we'll clear it if we're not at |
ad68076e BA |
2967 | * gigabit link later |
2968 | */ | |
18dd2392 | 2969 | #define SPEED_MODE_BIT BIT(21) |
bc7f75fa | 2970 | tarc |= SPEED_MODE_BIT; |
e9ec2c0f | 2971 | ew32(TARC(0), tarc); |
bc7f75fa AK |
2972 | } |
2973 | ||
2974 | /* errata: program both queues to unweighted RR */ | |
2975 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { | |
e9ec2c0f | 2976 | tarc = er32(TARC(0)); |
bc7f75fa | 2977 | tarc |= 1; |
e9ec2c0f JK |
2978 | ew32(TARC(0), tarc); |
2979 | tarc = er32(TARC(1)); | |
bc7f75fa | 2980 | tarc |= 1; |
e9ec2c0f | 2981 | ew32(TARC(1), tarc); |
bc7f75fa AK |
2982 | } |
2983 | ||
bc7f75fa AK |
2984 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
2985 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; | |
2986 | ||
2987 | /* only set IDE if we are delaying interrupts using the timers */ | |
2988 | if (adapter->tx_int_delay) | |
2989 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; | |
2990 | ||
2991 | /* enable Report Status bit */ | |
2992 | adapter->txd_cmd |= E1000_TXD_CMD_RS; | |
2993 | ||
e7e834aa DE |
2994 | ew32(TCTL, tctl); |
2995 | ||
57cde763 | 2996 | hw->mac.ops.config_collision_dist(hw); |
79849ebc | 2997 | |
b10effb9 SN |
2998 | /* SPT and KBL Si errata workaround to avoid data corruption */ |
2999 | if (hw->mac.type == e1000_pch_spt) { | |
79849ebc DE |
3000 | u32 reg_val; |
3001 | ||
3002 | reg_val = er32(IOSFPC); | |
3003 | reg_val |= E1000_RCTL_RDMTS_HEX; | |
3004 | ew32(IOSFPC, reg_val); | |
3005 | ||
3006 | reg_val = er32(TARC(0)); | |
c0f4b163 SN |
3007 | /* SPT and KBL Si errata workaround to avoid Tx hang. |
3008 | * Dropping the number of outstanding requests from | |
3009 | * 3 to 2 in order to avoid a buffer overrun. | |
3010 | */ | |
3011 | reg_val &= ~E1000_TARC0_CB_MULTIQ_3_REQ; | |
3012 | reg_val |= E1000_TARC0_CB_MULTIQ_2_REQ; | |
79849ebc DE |
3013 | ew32(TARC(0), reg_val); |
3014 | } | |
bc7f75fa AK |
3015 | } |
3016 | ||
3017 | /** | |
3018 | * e1000_setup_rctl - configure the receive control registers | |
3019 | * @adapter: Board private structure | |
3020 | **/ | |
3021 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ | |
3022 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) | |
3023 | static void e1000_setup_rctl(struct e1000_adapter *adapter) | |
3024 | { | |
3025 | struct e1000_hw *hw = &adapter->hw; | |
3026 | u32 rctl, rfctl; | |
bc7f75fa AK |
3027 | u32 pages = 0; |
3028 | ||
b20a7744 DE |
3029 | /* Workaround Si errata on PCHx - configure jumbo frame flow. |
3030 | * If jumbo frames not set, program related MAC/PHY registers | |
3031 | * to h/w defaults | |
3032 | */ | |
3033 | if (hw->mac.type >= e1000_pch2lan) { | |
3034 | s32 ret_val; | |
3035 | ||
3036 | if (adapter->netdev->mtu > ETH_DATA_LEN) | |
3037 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true); | |
3038 | else | |
3039 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false); | |
3040 | ||
3041 | if (ret_val) | |
3042 | e_dbg("failed to enable|disable jumbo frame workaround mode\n"); | |
3043 | } | |
a1ce6473 | 3044 | |
bc7f75fa AK |
3045 | /* Program MC offset vector base */ |
3046 | rctl = er32(RCTL); | |
3047 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); | |
3048 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | | |
f0ff4398 BA |
3049 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
3050 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); | |
bc7f75fa AK |
3051 | |
3052 | /* Do not Store bad packets */ | |
3053 | rctl &= ~E1000_RCTL_SBP; | |
3054 | ||
3055 | /* Enable Long Packet receive */ | |
3056 | if (adapter->netdev->mtu <= ETH_DATA_LEN) | |
3057 | rctl &= ~E1000_RCTL_LPE; | |
3058 | else | |
3059 | rctl |= E1000_RCTL_LPE; | |
3060 | ||
eb7c3adb JK |
3061 | /* Some systems expect that the CRC is included in SMBUS traffic. The |
3062 | * hardware strips the CRC before sending to both SMBUS (BMC) and to | |
3063 | * host memory when this is enabled | |
3064 | */ | |
3065 | if (adapter->flags2 & FLAG2_CRC_STRIPPING) | |
3066 | rctl |= E1000_RCTL_SECRC; | |
5918bd88 | 3067 | |
a4f58f54 BA |
3068 | /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ |
3069 | if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { | |
3070 | u16 phy_data; | |
3071 | ||
3072 | e1e_rphy(hw, PHY_REG(770, 26), &phy_data); | |
3073 | phy_data &= 0xfff8; | |
18dd2392 | 3074 | phy_data |= BIT(2); |
a4f58f54 BA |
3075 | e1e_wphy(hw, PHY_REG(770, 26), phy_data); |
3076 | ||
3077 | e1e_rphy(hw, 22, &phy_data); | |
3078 | phy_data &= 0x0fff; | |
18dd2392 | 3079 | phy_data |= BIT(14); |
a4f58f54 BA |
3080 | e1e_wphy(hw, 0x10, 0x2823); |
3081 | e1e_wphy(hw, 0x11, 0x0003); | |
3082 | e1e_wphy(hw, 22, phy_data); | |
3083 | } | |
3084 | ||
bc7f75fa AK |
3085 | /* Setup buffer sizes */ |
3086 | rctl &= ~E1000_RCTL_SZ_4096; | |
3087 | rctl |= E1000_RCTL_BSEX; | |
3088 | switch (adapter->rx_buffer_len) { | |
bc7f75fa AK |
3089 | case 2048: |
3090 | default: | |
3091 | rctl |= E1000_RCTL_SZ_2048; | |
3092 | rctl &= ~E1000_RCTL_BSEX; | |
3093 | break; | |
3094 | case 4096: | |
3095 | rctl |= E1000_RCTL_SZ_4096; | |
3096 | break; | |
3097 | case 8192: | |
3098 | rctl |= E1000_RCTL_SZ_8192; | |
3099 | break; | |
3100 | case 16384: | |
3101 | rctl |= E1000_RCTL_SZ_16384; | |
3102 | break; | |
3103 | } | |
3104 | ||
5f450212 BA |
3105 | /* Enable Extended Status in all Receive Descriptors */ |
3106 | rfctl = er32(RFCTL); | |
3107 | rfctl |= E1000_RFCTL_EXTEN; | |
f6bd5577 | 3108 | ew32(RFCTL, rfctl); |
5f450212 | 3109 | |
e921eb1a | 3110 | /* 82571 and greater support packet-split where the protocol |
bc7f75fa AK |
3111 | * header is placed in skb->data and the packet data is |
3112 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. | |
3113 | * In the case of a non-split, skb->data is linearly filled, | |
3114 | * followed by the page buffers. Therefore, skb->data is | |
3115 | * sized to hold the largest protocol header. | |
3116 | * | |
3117 | * allocations using alloc_page take too long for regular MTU | |
3118 | * so only enable packet split for jumbo frames | |
3119 | * | |
3120 | * Using pages when the page size is greater than 16k wastes | |
3121 | * a lot of memory, since we allocate 3 pages at all times | |
3122 | * per packet. | |
3123 | */ | |
bc7f75fa | 3124 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
79d4e908 | 3125 | if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) |
bc7f75fa | 3126 | adapter->rx_ps_pages = pages; |
97ac8cae BA |
3127 | else |
3128 | adapter->rx_ps_pages = 0; | |
bc7f75fa AK |
3129 | |
3130 | if (adapter->rx_ps_pages) { | |
90da0669 BA |
3131 | u32 psrctl = 0; |
3132 | ||
140a7480 AK |
3133 | /* Enable Packet split descriptors */ |
3134 | rctl |= E1000_RCTL_DTYP_PS; | |
bc7f75fa | 3135 | |
e5fe2541 | 3136 | psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT; |
bc7f75fa AK |
3137 | |
3138 | switch (adapter->rx_ps_pages) { | |
3139 | case 3: | |
e5fe2541 BA |
3140 | psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT; |
3141 | /* fall-through */ | |
bc7f75fa | 3142 | case 2: |
e5fe2541 BA |
3143 | psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT; |
3144 | /* fall-through */ | |
bc7f75fa | 3145 | case 1: |
e5fe2541 | 3146 | psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT; |
bc7f75fa AK |
3147 | break; |
3148 | } | |
3149 | ||
3150 | ew32(PSRCTL, psrctl); | |
3151 | } | |
3152 | ||
cf955e6c BG |
3153 | /* This is useful for sniffing bad packets. */ |
3154 | if (adapter->netdev->features & NETIF_F_RXALL) { | |
3155 | /* UPE and MPE will be handled by normal PROMISC logic | |
e921eb1a BA |
3156 | * in e1000e_set_rx_mode |
3157 | */ | |
e80bd1d1 BA |
3158 | rctl |= (E1000_RCTL_SBP | /* Receive bad packets */ |
3159 | E1000_RCTL_BAM | /* RX All Bcast Pkts */ | |
3160 | E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */ | |
cf955e6c | 3161 | |
e80bd1d1 BA |
3162 | rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */ |
3163 | E1000_RCTL_DPF | /* Allow filtered pause */ | |
3164 | E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */ | |
cf955e6c BG |
3165 | /* Do not mess with E1000_CTRL_VME, it affects transmit as well, |
3166 | * and that breaks VLANs. | |
3167 | */ | |
3168 | } | |
3169 | ||
bc7f75fa | 3170 | ew32(RCTL, rctl); |
318a94d6 | 3171 | /* just started the receive unit, no need to restart */ |
12d43f7d | 3172 | adapter->flags &= ~FLAG_RESTART_NOW; |
bc7f75fa AK |
3173 | } |
3174 | ||
3175 | /** | |
3176 | * e1000_configure_rx - Configure Receive Unit after Reset | |
3177 | * @adapter: board private structure | |
3178 | * | |
3179 | * Configure the Rx unit of the MAC after a reset. | |
3180 | **/ | |
3181 | static void e1000_configure_rx(struct e1000_adapter *adapter) | |
3182 | { | |
3183 | struct e1000_hw *hw = &adapter->hw; | |
3184 | struct e1000_ring *rx_ring = adapter->rx_ring; | |
3185 | u64 rdba; | |
3186 | u32 rdlen, rctl, rxcsum, ctrl_ext; | |
3187 | ||
3188 | if (adapter->rx_ps_pages) { | |
3189 | /* this is a 32 byte descriptor */ | |
3190 | rdlen = rx_ring->count * | |
af667a29 | 3191 | sizeof(union e1000_rx_desc_packet_split); |
bc7f75fa AK |
3192 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
3193 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; | |
97ac8cae | 3194 | } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { |
5f450212 | 3195 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
97ac8cae BA |
3196 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
3197 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; | |
bc7f75fa | 3198 | } else { |
5f450212 | 3199 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
bc7f75fa AK |
3200 | adapter->clean_rx = e1000_clean_rx_irq; |
3201 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; | |
3202 | } | |
3203 | ||
3204 | /* disable receives while setting up the descriptors */ | |
3205 | rctl = er32(RCTL); | |
7f99ae63 BA |
3206 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
3207 | ew32(RCTL, rctl & ~E1000_RCTL_EN); | |
bc7f75fa | 3208 | e1e_flush(); |
ab6973ae | 3209 | usleep_range(10000, 11000); |
bc7f75fa | 3210 | |
3a3b7586 | 3211 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
e921eb1a | 3212 | /* set the writeback threshold (only takes effect if the RDTR |
3a3b7586 | 3213 | * is set). set GRAN=1 and write back up to 0x4 worth, and |
af667a29 | 3214 | * enable prefetching of 0x20 Rx descriptors |
3a3b7586 JB |
3215 | * granularity = 01 |
3216 | * wthresh = 04, | |
3217 | * hthresh = 04, | |
3218 | * pthresh = 0x20 | |
3219 | */ | |
3220 | ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE); | |
3221 | ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE); | |
3a3b7586 JB |
3222 | } |
3223 | ||
bc7f75fa AK |
3224 | /* set the Receive Delay Timer Register */ |
3225 | ew32(RDTR, adapter->rx_int_delay); | |
3226 | ||
3227 | /* irq moderation */ | |
3228 | ew32(RADV, adapter->rx_abs_int_delay); | |
828bac87 | 3229 | if ((adapter->itr_setting != 0) && (adapter->itr != 0)) |
22a4cca2 | 3230 | e1000e_write_itr(adapter, adapter->itr); |
bc7f75fa AK |
3231 | |
3232 | ctrl_ext = er32(CTRL_EXT); | |
bc7f75fa AK |
3233 | /* Auto-Mask interrupts upon ICR access */ |
3234 | ctrl_ext |= E1000_CTRL_EXT_IAME; | |
3235 | ew32(IAM, 0xffffffff); | |
3236 | ew32(CTRL_EXT, ctrl_ext); | |
3237 | e1e_flush(); | |
3238 | ||
e921eb1a | 3239 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
ad68076e BA |
3240 | * the Base and Length of the Rx Descriptor Ring |
3241 | */ | |
bc7f75fa | 3242 | rdba = rx_ring->dma; |
1e36052e BA |
3243 | ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32))); |
3244 | ew32(RDBAH(0), (rdba >> 32)); | |
3245 | ew32(RDLEN(0), rdlen); | |
3246 | ew32(RDH(0), 0); | |
3247 | ew32(RDT(0), 0); | |
3248 | rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0); | |
3249 | rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0); | |
bc7f75fa | 3250 | |
0845d45e JJB |
3251 | writel(0, rx_ring->head); |
3252 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) | |
3253 | e1000e_update_rdt_wa(rx_ring, 0); | |
3254 | else | |
3255 | writel(0, rx_ring->tail); | |
3256 | ||
bc7f75fa AK |
3257 | /* Enable Receive Checksum Offload for TCP and UDP */ |
3258 | rxcsum = er32(RXCSUM); | |
2e1706f2 | 3259 | if (adapter->netdev->features & NETIF_F_RXCSUM) |
bc7f75fa | 3260 | rxcsum |= E1000_RXCSUM_TUOFL; |
2e1706f2 | 3261 | else |
bc7f75fa | 3262 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
bc7f75fa AK |
3263 | ew32(RXCSUM, rxcsum); |
3264 | ||
3e35d991 BA |
3265 | /* With jumbo frames, excessive C-state transition latencies result |
3266 | * in dropped transactions. | |
3267 | */ | |
3268 | if (adapter->netdev->mtu > ETH_DATA_LEN) { | |
3269 | u32 lat = | |
3270 | ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 - | |
3271 | adapter->max_frame_size) * 8 / 1000; | |
3272 | ||
3273 | if (adapter->flags & FLAG_IS_ICH) { | |
53ec5498 | 3274 | u32 rxdctl = er32(RXDCTL(0)); |
6cf08d1c | 3275 | |
b701cacd | 3276 | ew32(RXDCTL(0), rxdctl | 0x3 | BIT(8)); |
53ec5498 | 3277 | } |
3e35d991 | 3278 | |
8299b006 MT |
3279 | dev_info(&adapter->pdev->dev, |
3280 | "Some CPU C-states have been disabled in order to enable jumbo frames\n"); | |
e2c65448 | 3281 | pm_qos_update_request(&adapter->pm_qos_req, lat); |
3e35d991 | 3282 | } else { |
e2c65448 | 3283 | pm_qos_update_request(&adapter->pm_qos_req, |
3e35d991 | 3284 | PM_QOS_DEFAULT_VALUE); |
97ac8cae | 3285 | } |
bc7f75fa AK |
3286 | |
3287 | /* Enable Receives */ | |
3288 | ew32(RCTL, rctl); | |
3289 | } | |
3290 | ||
3291 | /** | |
ef9b965a JB |
3292 | * e1000e_write_mc_addr_list - write multicast addresses to MTA |
3293 | * @netdev: network interface device structure | |
bc7f75fa | 3294 | * |
ef9b965a JB |
3295 | * Writes multicast address list to the MTA hash table. |
3296 | * Returns: -ENOMEM on failure | |
3297 | * 0 on no addresses written | |
3298 | * X on writing X addresses to MTA | |
3299 | */ | |
3300 | static int e1000e_write_mc_addr_list(struct net_device *netdev) | |
3301 | { | |
3302 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3303 | struct e1000_hw *hw = &adapter->hw; | |
3304 | struct netdev_hw_addr *ha; | |
3305 | u8 *mta_list; | |
3306 | int i; | |
3307 | ||
3308 | if (netdev_mc_empty(netdev)) { | |
3309 | /* nothing to program, so clear mc list */ | |
3310 | hw->mac.ops.update_mc_addr_list(hw, NULL, 0); | |
3311 | return 0; | |
3312 | } | |
3313 | ||
6396bb22 | 3314 | mta_list = kcalloc(netdev_mc_count(netdev), ETH_ALEN, GFP_ATOMIC); |
ef9b965a JB |
3315 | if (!mta_list) |
3316 | return -ENOMEM; | |
3317 | ||
3318 | /* update_mc_addr_list expects a packed array of only addresses. */ | |
3319 | i = 0; | |
3320 | netdev_for_each_mc_addr(ha, netdev) | |
f0ff4398 | 3321 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
ef9b965a JB |
3322 | |
3323 | hw->mac.ops.update_mc_addr_list(hw, mta_list, i); | |
3324 | kfree(mta_list); | |
3325 | ||
3326 | return netdev_mc_count(netdev); | |
3327 | } | |
3328 | ||
3329 | /** | |
3330 | * e1000e_write_uc_addr_list - write unicast addresses to RAR table | |
3331 | * @netdev: network interface device structure | |
bc7f75fa | 3332 | * |
ef9b965a JB |
3333 | * Writes unicast address list to the RAR table. |
3334 | * Returns: -ENOMEM on failure/insufficient address space | |
3335 | * 0 on no addresses written | |
3336 | * X on writing X addresses to the RAR table | |
bc7f75fa | 3337 | **/ |
ef9b965a | 3338 | static int e1000e_write_uc_addr_list(struct net_device *netdev) |
bc7f75fa | 3339 | { |
ef9b965a JB |
3340 | struct e1000_adapter *adapter = netdev_priv(netdev); |
3341 | struct e1000_hw *hw = &adapter->hw; | |
b3e5bf1f | 3342 | unsigned int rar_entries; |
ef9b965a JB |
3343 | int count = 0; |
3344 | ||
b3e5bf1f DE |
3345 | rar_entries = hw->mac.ops.rar_get_count(hw); |
3346 | ||
ef9b965a JB |
3347 | /* save a rar entry for our hardware address */ |
3348 | rar_entries--; | |
3349 | ||
3350 | /* save a rar entry for the LAA workaround */ | |
3351 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) | |
3352 | rar_entries--; | |
3353 | ||
3354 | /* return ENOMEM indicating insufficient memory for addresses */ | |
3355 | if (netdev_uc_count(netdev) > rar_entries) | |
3356 | return -ENOMEM; | |
3357 | ||
3358 | if (!netdev_uc_empty(netdev) && rar_entries) { | |
3359 | struct netdev_hw_addr *ha; | |
3360 | ||
e921eb1a | 3361 | /* write the addresses in reverse order to avoid write |
ef9b965a JB |
3362 | * combining |
3363 | */ | |
3364 | netdev_for_each_uc_addr(ha, netdev) { | |
847042a6 | 3365 | int ret_val; |
b3e5bf1f | 3366 | |
ef9b965a JB |
3367 | if (!rar_entries) |
3368 | break; | |
847042a6 BW |
3369 | ret_val = hw->mac.ops.rar_set(hw, ha->addr, rar_entries--); |
3370 | if (ret_val < 0) | |
b3e5bf1f | 3371 | return -ENOMEM; |
ef9b965a JB |
3372 | count++; |
3373 | } | |
3374 | } | |
3375 | ||
3376 | /* zero out the remaining RAR entries not used above */ | |
3377 | for (; rar_entries > 0; rar_entries--) { | |
3378 | ew32(RAH(rar_entries), 0); | |
3379 | ew32(RAL(rar_entries), 0); | |
3380 | } | |
3381 | e1e_flush(); | |
3382 | ||
3383 | return count; | |
bc7f75fa AK |
3384 | } |
3385 | ||
3386 | /** | |
ef9b965a | 3387 | * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set |
bc7f75fa AK |
3388 | * @netdev: network interface device structure |
3389 | * | |
ef9b965a JB |
3390 | * The ndo_set_rx_mode entry point is called whenever the unicast or multicast |
3391 | * address list or the network interface flags are updated. This routine is | |
3392 | * responsible for configuring the hardware for proper unicast, multicast, | |
bc7f75fa AK |
3393 | * promiscuous mode, and all-multi behavior. |
3394 | **/ | |
ef9b965a | 3395 | static void e1000e_set_rx_mode(struct net_device *netdev) |
bc7f75fa AK |
3396 | { |
3397 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3398 | struct e1000_hw *hw = &adapter->hw; | |
bc7f75fa | 3399 | u32 rctl; |
bc7f75fa | 3400 | |
63eb48f1 DE |
3401 | if (pm_runtime_suspended(netdev->dev.parent)) |
3402 | return; | |
3403 | ||
bc7f75fa | 3404 | /* Check for Promiscuous and All Multicast modes */ |
bc7f75fa AK |
3405 | rctl = er32(RCTL); |
3406 | ||
ef9b965a JB |
3407 | /* clear the affected bits */ |
3408 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); | |
3409 | ||
bc7f75fa AK |
3410 | if (netdev->flags & IFF_PROMISC) { |
3411 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); | |
86d70e53 JK |
3412 | /* Do not hardware filter VLANs in promisc mode */ |
3413 | e1000e_vlan_filter_disable(adapter); | |
bc7f75fa | 3414 | } else { |
ef9b965a | 3415 | int count; |
3d3a1676 | 3416 | |
746b9f02 PM |
3417 | if (netdev->flags & IFF_ALLMULTI) { |
3418 | rctl |= E1000_RCTL_MPE; | |
746b9f02 | 3419 | } else { |
e921eb1a | 3420 | /* Write addresses to the MTA, if the attempt fails |
ef9b965a JB |
3421 | * then we should just turn on promiscuous mode so |
3422 | * that we can at least receive multicast traffic | |
3423 | */ | |
3424 | count = e1000e_write_mc_addr_list(netdev); | |
3425 | if (count < 0) | |
3426 | rctl |= E1000_RCTL_MPE; | |
746b9f02 | 3427 | } |
86d70e53 | 3428 | e1000e_vlan_filter_enable(adapter); |
e921eb1a | 3429 | /* Write addresses to available RAR registers, if there is not |
ef9b965a JB |
3430 | * sufficient space to store all the addresses then enable |
3431 | * unicast promiscuous mode | |
bc7f75fa | 3432 | */ |
ef9b965a JB |
3433 | count = e1000e_write_uc_addr_list(netdev); |
3434 | if (count < 0) | |
3435 | rctl |= E1000_RCTL_UPE; | |
bc7f75fa | 3436 | } |
86d70e53 | 3437 | |
ef9b965a JB |
3438 | ew32(RCTL, rctl); |
3439 | ||
83808641 | 3440 | if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) |
86d70e53 JK |
3441 | e1000e_vlan_strip_enable(adapter); |
3442 | else | |
3443 | e1000e_vlan_strip_disable(adapter); | |
bc7f75fa AK |
3444 | } |
3445 | ||
70495a50 BA |
3446 | static void e1000e_setup_rss_hash(struct e1000_adapter *adapter) |
3447 | { | |
3448 | struct e1000_hw *hw = &adapter->hw; | |
3449 | u32 mrqc, rxcsum; | |
5c8d19da | 3450 | u32 rss_key[10]; |
70495a50 | 3451 | int i; |
70495a50 | 3452 | |
5c8d19da | 3453 | netdev_rss_key_fill(rss_key, sizeof(rss_key)); |
70495a50 | 3454 | for (i = 0; i < 10; i++) |
5c8d19da | 3455 | ew32(RSSRK(i), rss_key[i]); |
70495a50 BA |
3456 | |
3457 | /* Direct all traffic to queue 0 */ | |
3458 | for (i = 0; i < 32; i++) | |
3459 | ew32(RETA(i), 0); | |
3460 | ||
e921eb1a | 3461 | /* Disable raw packet checksumming so that RSS hash is placed in |
70495a50 BA |
3462 | * descriptor on writeback. |
3463 | */ | |
3464 | rxcsum = er32(RXCSUM); | |
3465 | rxcsum |= E1000_RXCSUM_PCSD; | |
3466 | ||
3467 | ew32(RXCSUM, rxcsum); | |
3468 | ||
3469 | mrqc = (E1000_MRQC_RSS_FIELD_IPV4 | | |
3470 | E1000_MRQC_RSS_FIELD_IPV4_TCP | | |
3471 | E1000_MRQC_RSS_FIELD_IPV6 | | |
3472 | E1000_MRQC_RSS_FIELD_IPV6_TCP | | |
3473 | E1000_MRQC_RSS_FIELD_IPV6_TCP_EX); | |
3474 | ||
3475 | ew32(MRQC, mrqc); | |
3476 | } | |
3477 | ||
b67e1913 BA |
3478 | /** |
3479 | * e1000e_get_base_timinca - get default SYSTIM time increment attributes | |
3480 | * @adapter: board private structure | |
3481 | * @timinca: pointer to returned time increment attributes | |
3482 | * | |
3483 | * Get attributes for incrementing the System Time Register SYSTIML/H at | |
3484 | * the default base frequency, and set the cyclecounter shift value. | |
3485 | **/ | |
d89777bf | 3486 | s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca) |
b67e1913 BA |
3487 | { |
3488 | struct e1000_hw *hw = &adapter->hw; | |
3489 | u32 incvalue, incperiod, shift; | |
3490 | ||
79849ebc DE |
3491 | /* Make sure clock is enabled on I217/I218/I219 before checking |
3492 | * the frequency | |
3493 | */ | |
c8744f44 | 3494 | if ((hw->mac.type >= e1000_pch_lpt) && |
b67e1913 BA |
3495 | !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) && |
3496 | !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) { | |
3497 | u32 fextnvm7 = er32(FEXTNVM7); | |
3498 | ||
18dd2392 JK |
3499 | if (!(fextnvm7 & BIT(0))) { |
3500 | ew32(FEXTNVM7, fextnvm7 | BIT(0)); | |
b67e1913 BA |
3501 | e1e_flush(); |
3502 | } | |
3503 | } | |
3504 | ||
3505 | switch (hw->mac.type) { | |
3506 | case e1000_pch2lan: | |
5313eecc | 3507 | /* Stable 96MHz frequency */ |
68fe1d5d SN |
3508 | incperiod = INCPERIOD_96MHZ; |
3509 | incvalue = INCVALUE_96MHZ; | |
3510 | shift = INCVALUE_SHIFT_96MHZ; | |
3511 | adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ; | |
5313eecc | 3512 | break; |
b67e1913 | 3513 | case e1000_pch_lpt: |
83129b37 | 3514 | if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) { |
b67e1913 | 3515 | /* Stable 96MHz frequency */ |
68fe1d5d SN |
3516 | incperiod = INCPERIOD_96MHZ; |
3517 | incvalue = INCVALUE_96MHZ; | |
3518 | shift = INCVALUE_SHIFT_96MHZ; | |
3519 | adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ; | |
83129b37 YL |
3520 | } else { |
3521 | /* Stable 25MHz frequency */ | |
68fe1d5d SN |
3522 | incperiod = INCPERIOD_25MHZ; |
3523 | incvalue = INCVALUE_25MHZ; | |
3524 | shift = INCVALUE_SHIFT_25MHZ; | |
83129b37 YL |
3525 | adapter->cc.shift = shift; |
3526 | } | |
3527 | break; | |
3528 | case e1000_pch_spt: | |
fff200ca BP |
3529 | /* Stable 24MHz frequency */ |
3530 | incperiod = INCPERIOD_24MHZ; | |
3531 | incvalue = INCVALUE_24MHZ; | |
3532 | shift = INCVALUE_SHIFT_24MHZ; | |
3533 | adapter->cc.shift = shift; | |
3534 | break; | |
68fe1d5d SN |
3535 | case e1000_pch_cnp: |
3536 | if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) { | |
3537 | /* Stable 24MHz frequency */ | |
3538 | incperiod = INCPERIOD_24MHZ; | |
3539 | incvalue = INCVALUE_24MHZ; | |
3540 | shift = INCVALUE_SHIFT_24MHZ; | |
3541 | adapter->cc.shift = shift; | |
3542 | } else { | |
3543 | /* Stable 38400KHz frequency */ | |
3544 | incperiod = INCPERIOD_38400KHZ; | |
3545 | incvalue = INCVALUE_38400KHZ; | |
3546 | shift = INCVALUE_SHIFT_38400KHZ; | |
3547 | adapter->cc.shift = shift; | |
3548 | } | |
3549 | break; | |
b67e1913 BA |
3550 | case e1000_82574: |
3551 | case e1000_82583: | |
3552 | /* Stable 25MHz frequency */ | |
68fe1d5d SN |
3553 | incperiod = INCPERIOD_25MHZ; |
3554 | incvalue = INCVALUE_25MHZ; | |
3555 | shift = INCVALUE_SHIFT_25MHZ; | |
b67e1913 BA |
3556 | adapter->cc.shift = shift; |
3557 | break; | |
3558 | default: | |
3559 | return -EINVAL; | |
3560 | } | |
3561 | ||
3562 | *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) | | |
3563 | ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK)); | |
3564 | ||
3565 | return 0; | |
3566 | } | |
3567 | ||
3568 | /** | |
3569 | * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable | |
3570 | * @adapter: board private structure | |
3571 | * | |
3572 | * Outgoing time stamping can be enabled and disabled. Play nice and | |
3573 | * disable it when requested, although it shouldn't cause any overhead | |
3574 | * when no packet needs it. At most one packet in the queue may be | |
3575 | * marked for time stamping, otherwise it would be impossible to tell | |
3576 | * for sure to which packet the hardware time stamp belongs. | |
3577 | * | |
3578 | * Incoming time stamping has to be configured via the hardware filters. | |
3579 | * Not all combinations are supported, in particular event type has to be | |
3580 | * specified. Matching the kind of event packet is not supported, with the | |
3581 | * exception of "all V2 events regardless of level 2 or 4". | |
3582 | **/ | |
62d7e3a2 BH |
3583 | static int e1000e_config_hwtstamp(struct e1000_adapter *adapter, |
3584 | struct hwtstamp_config *config) | |
b67e1913 BA |
3585 | { |
3586 | struct e1000_hw *hw = &adapter->hw; | |
b67e1913 BA |
3587 | u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED; |
3588 | u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; | |
d89777bf BA |
3589 | u32 rxmtrl = 0; |
3590 | u16 rxudp = 0; | |
3591 | bool is_l4 = false; | |
3592 | bool is_l2 = false; | |
b67e1913 | 3593 | u32 regval; |
b67e1913 BA |
3594 | |
3595 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) | |
3596 | return -EINVAL; | |
3597 | ||
3598 | /* flags reserved for future extensions - must be zero */ | |
3599 | if (config->flags) | |
3600 | return -EINVAL; | |
3601 | ||
3602 | switch (config->tx_type) { | |
3603 | case HWTSTAMP_TX_OFF: | |
3604 | tsync_tx_ctl = 0; | |
3605 | break; | |
3606 | case HWTSTAMP_TX_ON: | |
3607 | break; | |
3608 | default: | |
3609 | return -ERANGE; | |
3610 | } | |
3611 | ||
3612 | switch (config->rx_filter) { | |
3613 | case HWTSTAMP_FILTER_NONE: | |
3614 | tsync_rx_ctl = 0; | |
3615 | break; | |
d89777bf BA |
3616 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
3617 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; | |
3618 | rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE; | |
3619 | is_l4 = true; | |
3620 | break; | |
3621 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: | |
3622 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; | |
3623 | rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE; | |
3624 | is_l4 = true; | |
3625 | break; | |
3626 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: | |
3627 | /* Also time stamps V2 L2 Path Delay Request/Response */ | |
3628 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2; | |
3629 | rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE; | |
3630 | is_l2 = true; | |
3631 | break; | |
3632 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: | |
3633 | /* Also time stamps V2 L2 Path Delay Request/Response. */ | |
3634 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2; | |
3635 | rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE; | |
3636 | is_l2 = true; | |
3637 | break; | |
3638 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: | |
3639 | /* Hardware cannot filter just V2 L4 Sync messages; | |
3640 | * fall-through to V2 (both L2 and L4) Sync. | |
3641 | */ | |
3642 | case HWTSTAMP_FILTER_PTP_V2_SYNC: | |
3643 | /* Also time stamps V2 Path Delay Request/Response. */ | |
3644 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; | |
3645 | rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE; | |
3646 | is_l2 = true; | |
3647 | is_l4 = true; | |
3648 | break; | |
3649 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: | |
3650 | /* Hardware cannot filter just V2 L4 Delay Request messages; | |
3651 | * fall-through to V2 (both L2 and L4) Delay Request. | |
3652 | */ | |
3653 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: | |
3654 | /* Also time stamps V2 Path Delay Request/Response. */ | |
3655 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; | |
3656 | rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE; | |
3657 | is_l2 = true; | |
3658 | is_l4 = true; | |
3659 | break; | |
3660 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: | |
3661 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: | |
3662 | /* Hardware cannot filter just V2 L4 or L2 Event messages; | |
3663 | * fall-through to all V2 (both L2 and L4) Events. | |
3664 | */ | |
3665 | case HWTSTAMP_FILTER_PTP_V2_EVENT: | |
3666 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2; | |
3667 | config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; | |
3668 | is_l2 = true; | |
3669 | is_l4 = true; | |
3670 | break; | |
3671 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: | |
3672 | /* For V1, the hardware can only filter Sync messages or | |
3673 | * Delay Request messages but not both so fall-through to | |
3674 | * time stamp all packets. | |
3675 | */ | |
e3412575 | 3676 | case HWTSTAMP_FILTER_NTP_ALL: |
b67e1913 | 3677 | case HWTSTAMP_FILTER_ALL: |
d89777bf BA |
3678 | is_l2 = true; |
3679 | is_l4 = true; | |
b67e1913 BA |
3680 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; |
3681 | config->rx_filter = HWTSTAMP_FILTER_ALL; | |
3682 | break; | |
3683 | default: | |
3684 | return -ERANGE; | |
3685 | } | |
3686 | ||
62d7e3a2 BH |
3687 | adapter->hwtstamp_config = *config; |
3688 | ||
b67e1913 BA |
3689 | /* enable/disable Tx h/w time stamping */ |
3690 | regval = er32(TSYNCTXCTL); | |
3691 | regval &= ~E1000_TSYNCTXCTL_ENABLED; | |
3692 | regval |= tsync_tx_ctl; | |
3693 | ew32(TSYNCTXCTL, regval); | |
3694 | if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) != | |
3695 | (regval & E1000_TSYNCTXCTL_ENABLED)) { | |
3696 | e_err("Timesync Tx Control register not set as expected\n"); | |
3697 | return -EAGAIN; | |
3698 | } | |
3699 | ||
3700 | /* enable/disable Rx h/w time stamping */ | |
3701 | regval = er32(TSYNCRXCTL); | |
3702 | regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK); | |
3703 | regval |= tsync_rx_ctl; | |
3704 | ew32(TSYNCRXCTL, regval); | |
3705 | if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED | | |
3706 | E1000_TSYNCRXCTL_TYPE_MASK)) != | |
3707 | (regval & (E1000_TSYNCRXCTL_ENABLED | | |
3708 | E1000_TSYNCRXCTL_TYPE_MASK))) { | |
3709 | e_err("Timesync Rx Control register not set as expected\n"); | |
3710 | return -EAGAIN; | |
3711 | } | |
3712 | ||
d89777bf BA |
3713 | /* L2: define ethertype filter for time stamped packets */ |
3714 | if (is_l2) | |
3715 | rxmtrl |= ETH_P_1588; | |
3716 | ||
3717 | /* define which PTP packets get time stamped */ | |
3718 | ew32(RXMTRL, rxmtrl); | |
3719 | ||
3720 | /* Filter by destination port */ | |
3721 | if (is_l4) { | |
3722 | rxudp = PTP_EV_PORT; | |
3723 | cpu_to_be16s(&rxudp); | |
3724 | } | |
3725 | ew32(RXUDP, rxudp); | |
3726 | ||
3727 | e1e_flush(); | |
3728 | ||
b67e1913 | 3729 | /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */ |
70806a7f BA |
3730 | er32(RXSTMPH); |
3731 | er32(TXSTMPH); | |
b67e1913 | 3732 | |
b67e1913 BA |
3733 | return 0; |
3734 | } | |
3735 | ||
bc7f75fa | 3736 | /** |
ad68076e | 3737 | * e1000_configure - configure the hardware for Rx and Tx |
bc7f75fa AK |
3738 | * @adapter: private board structure |
3739 | **/ | |
3740 | static void e1000_configure(struct e1000_adapter *adapter) | |
3741 | { | |
55aa6985 BA |
3742 | struct e1000_ring *rx_ring = adapter->rx_ring; |
3743 | ||
ef9b965a | 3744 | e1000e_set_rx_mode(adapter->netdev); |
bc7f75fa AK |
3745 | |
3746 | e1000_restore_vlan(adapter); | |
cd791618 | 3747 | e1000_init_manageability_pt(adapter); |
bc7f75fa AK |
3748 | |
3749 | e1000_configure_tx(adapter); | |
70495a50 BA |
3750 | |
3751 | if (adapter->netdev->features & NETIF_F_RXHASH) | |
3752 | e1000e_setup_rss_hash(adapter); | |
bc7f75fa AK |
3753 | e1000_setup_rctl(adapter); |
3754 | e1000_configure_rx(adapter); | |
55aa6985 | 3755 | adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL); |
bc7f75fa AK |
3756 | } |
3757 | ||
3758 | /** | |
3759 | * e1000e_power_up_phy - restore link in case the phy was powered down | |
3760 | * @adapter: address of board private structure | |
3761 | * | |
3762 | * The phy may be powered down to save power and turn off link when the | |
3763 | * driver is unloaded and wake on lan is not enabled (among others) | |
3764 | * *** this routine MUST be followed by a call to e1000e_reset *** | |
3765 | **/ | |
3766 | void e1000e_power_up_phy(struct e1000_adapter *adapter) | |
3767 | { | |
17f208de BA |
3768 | if (adapter->hw.phy.ops.power_up) |
3769 | adapter->hw.phy.ops.power_up(&adapter->hw); | |
bc7f75fa AK |
3770 | |
3771 | adapter->hw.mac.ops.setup_link(&adapter->hw); | |
3772 | } | |
3773 | ||
3774 | /** | |
3775 | * e1000_power_down_phy - Power down the PHY | |
3776 | * | |
17f208de BA |
3777 | * Power down the PHY so no link is implied when interface is down. |
3778 | * The PHY cannot be powered down if management or WoL is active. | |
bc7f75fa AK |
3779 | */ |
3780 | static void e1000_power_down_phy(struct e1000_adapter *adapter) | |
3781 | { | |
17f208de BA |
3782 | if (adapter->hw.phy.ops.power_down) |
3783 | adapter->hw.phy.ops.power_down(&adapter->hw); | |
bc7f75fa AK |
3784 | } |
3785 | ||
ad851fbb YL |
3786 | /** |
3787 | * e1000_flush_tx_ring - remove all descriptors from the tx_ring | |
3788 | * | |
3789 | * We want to clear all pending descriptors from the TX ring. | |
3790 | * zeroing happens when the HW reads the regs. We assign the ring itself as | |
3791 | * the data of the next descriptor. We don't care about the data we are about | |
3792 | * to reset the HW. | |
3793 | */ | |
3794 | static void e1000_flush_tx_ring(struct e1000_adapter *adapter) | |
3795 | { | |
3796 | struct e1000_hw *hw = &adapter->hw; | |
3797 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
3798 | struct e1000_tx_desc *tx_desc = NULL; | |
3799 | u32 tdt, tctl, txd_lower = E1000_TXD_CMD_IFCS; | |
3800 | u16 size = 512; | |
3801 | ||
3802 | tctl = er32(TCTL); | |
3803 | ew32(TCTL, tctl | E1000_TCTL_EN); | |
3804 | tdt = er32(TDT(0)); | |
3805 | BUG_ON(tdt != tx_ring->next_to_use); | |
3806 | tx_desc = E1000_TX_DESC(*tx_ring, tx_ring->next_to_use); | |
3807 | tx_desc->buffer_addr = tx_ring->dma; | |
3808 | ||
3809 | tx_desc->lower.data = cpu_to_le32(txd_lower | size); | |
3810 | tx_desc->upper.data = 0; | |
3811 | /* flush descriptors to memory before notifying the HW */ | |
3812 | wmb(); | |
3813 | tx_ring->next_to_use++; | |
3814 | if (tx_ring->next_to_use == tx_ring->count) | |
3815 | tx_ring->next_to_use = 0; | |
3816 | ew32(TDT(0), tx_ring->next_to_use); | |
ad851fbb YL |
3817 | usleep_range(200, 250); |
3818 | } | |
3819 | ||
3820 | /** | |
3821 | * e1000_flush_rx_ring - remove all descriptors from the rx_ring | |
3822 | * | |
3823 | * Mark all descriptors in the RX ring as consumed and disable the rx ring | |
3824 | */ | |
3825 | static void e1000_flush_rx_ring(struct e1000_adapter *adapter) | |
3826 | { | |
3827 | u32 rctl, rxdctl; | |
3828 | struct e1000_hw *hw = &adapter->hw; | |
3829 | ||
3830 | rctl = er32(RCTL); | |
3831 | ew32(RCTL, rctl & ~E1000_RCTL_EN); | |
3832 | e1e_flush(); | |
3833 | usleep_range(100, 150); | |
3834 | ||
3835 | rxdctl = er32(RXDCTL(0)); | |
3836 | /* zero the lower 14 bits (prefetch and host thresholds) */ | |
3837 | rxdctl &= 0xffffc000; | |
3838 | ||
3839 | /* update thresholds: prefetch threshold to 31, host threshold to 1 | |
3840 | * and make sure the granularity is "descriptors" and not "cache lines" | |
3841 | */ | |
18dd2392 | 3842 | rxdctl |= (0x1F | BIT(8) | E1000_RXDCTL_THRESH_UNIT_DESC); |
ad851fbb YL |
3843 | |
3844 | ew32(RXDCTL(0), rxdctl); | |
3845 | /* momentarily enable the RX ring for the changes to take effect */ | |
3846 | ew32(RCTL, rctl | E1000_RCTL_EN); | |
3847 | e1e_flush(); | |
3848 | usleep_range(100, 150); | |
3849 | ew32(RCTL, rctl & ~E1000_RCTL_EN); | |
3850 | } | |
3851 | ||
3852 | /** | |
3853 | * e1000_flush_desc_rings - remove all descriptors from the descriptor rings | |
3854 | * | |
3855 | * In i219, the descriptor rings must be emptied before resetting the HW | |
3856 | * or before changing the device state to D3 during runtime (runtime PM). | |
3857 | * | |
3858 | * Failure to do this will cause the HW to enter a unit hang state which can | |
3859 | * only be released by PCI reset on the device | |
3860 | * | |
3861 | */ | |
3862 | ||
3863 | static void e1000_flush_desc_rings(struct e1000_adapter *adapter) | |
3864 | { | |
ff917429 | 3865 | u16 hang_state; |
ad851fbb YL |
3866 | u32 fext_nvm11, tdlen; |
3867 | struct e1000_hw *hw = &adapter->hw; | |
3868 | ||
3869 | /* First, disable MULR fix in FEXTNVM11 */ | |
3870 | fext_nvm11 = er32(FEXTNVM11); | |
3871 | fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX; | |
3872 | ew32(FEXTNVM11, fext_nvm11); | |
3873 | /* do nothing if we're not in faulty state, or if the queue is empty */ | |
3874 | tdlen = er32(TDLEN(0)); | |
ff917429 YL |
3875 | pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS, |
3876 | &hang_state); | |
3877 | if (!(hang_state & FLUSH_DESC_REQUIRED) || !tdlen) | |
ad851fbb YL |
3878 | return; |
3879 | e1000_flush_tx_ring(adapter); | |
3880 | /* recheck, maybe the fault is caused by the rx ring */ | |
ff917429 YL |
3881 | pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS, |
3882 | &hang_state); | |
3883 | if (hang_state & FLUSH_DESC_REQUIRED) | |
ad851fbb YL |
3884 | e1000_flush_rx_ring(adapter); |
3885 | } | |
3886 | ||
aa524b66 JK |
3887 | /** |
3888 | * e1000e_systim_reset - reset the timesync registers after a hardware reset | |
3889 | * @adapter: board private structure | |
3890 | * | |
3891 | * When the MAC is reset, all hardware bits for timesync will be reset to the | |
3892 | * default values. This function will restore the settings last in place. | |
3893 | * Since the clock SYSTIME registers are reset, we will simply restore the | |
3894 | * cyclecounter to the kernel real clock time. | |
3895 | **/ | |
3896 | static void e1000e_systim_reset(struct e1000_adapter *adapter) | |
3897 | { | |
3898 | struct ptp_clock_info *info = &adapter->ptp_clock_info; | |
3899 | struct e1000_hw *hw = &adapter->hw; | |
3900 | unsigned long flags; | |
3901 | u32 timinca; | |
3902 | s32 ret_val; | |
3903 | ||
3904 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) | |
3905 | return; | |
3906 | ||
3907 | if (info->adjfreq) { | |
3908 | /* restore the previous ptp frequency delta */ | |
3909 | ret_val = info->adjfreq(info, adapter->ptp_delta); | |
3910 | } else { | |
3911 | /* set the default base frequency if no adjustment possible */ | |
3912 | ret_val = e1000e_get_base_timinca(adapter, &timinca); | |
3913 | if (!ret_val) | |
3914 | ew32(TIMINCA, timinca); | |
3915 | } | |
3916 | ||
3917 | if (ret_val) { | |
3918 | dev_warn(&adapter->pdev->dev, | |
3919 | "Failed to restore TIMINCA clock rate delta: %d\n", | |
3920 | ret_val); | |
3921 | return; | |
3922 | } | |
3923 | ||
3924 | /* reset the systim ns time counter */ | |
3925 | spin_lock_irqsave(&adapter->systim_lock, flags); | |
3926 | timecounter_init(&adapter->tc, &adapter->cc, | |
3927 | ktime_to_ns(ktime_get_real())); | |
3928 | spin_unlock_irqrestore(&adapter->systim_lock, flags); | |
3929 | ||
3930 | /* restore the previous hwtstamp configuration settings */ | |
3931 | e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config); | |
3932 | } | |
3933 | ||
bc7f75fa AK |
3934 | /** |
3935 | * e1000e_reset - bring the hardware into a known good state | |
3936 | * | |
3937 | * This function boots the hardware and enables some settings that | |
3938 | * require a configuration cycle of the hardware - those cannot be | |
3939 | * set/changed during runtime. After reset the device needs to be | |
ad68076e | 3940 | * properly configured for Rx, Tx etc. |
bc7f75fa AK |
3941 | */ |
3942 | void e1000e_reset(struct e1000_adapter *adapter) | |
3943 | { | |
3944 | struct e1000_mac_info *mac = &adapter->hw.mac; | |
318a94d6 | 3945 | struct e1000_fc_info *fc = &adapter->hw.fc; |
bc7f75fa AK |
3946 | struct e1000_hw *hw = &adapter->hw; |
3947 | u32 tx_space, min_tx_space, min_rx_space; | |
318a94d6 | 3948 | u32 pba = adapter->pba; |
bc7f75fa AK |
3949 | u16 hwm; |
3950 | ||
ad68076e | 3951 | /* reset Packet Buffer Allocation to default */ |
318a94d6 | 3952 | ew32(PBA, pba); |
df762464 | 3953 | |
8084b86d | 3954 | if (adapter->max_frame_size > (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) { |
e921eb1a | 3955 | /* To maintain wire speed transmits, the Tx FIFO should be |
bc7f75fa AK |
3956 | * large enough to accommodate two full transmit packets, |
3957 | * rounded up to the next 1KB and expressed in KB. Likewise, | |
3958 | * the Rx FIFO should be large enough to accommodate at least | |
3959 | * one full receive packet and is similarly rounded up and | |
ad68076e BA |
3960 | * expressed in KB. |
3961 | */ | |
df762464 | 3962 | pba = er32(PBA); |
bc7f75fa | 3963 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
df762464 | 3964 | tx_space = pba >> 16; |
bc7f75fa | 3965 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
df762464 | 3966 | pba &= 0xffff; |
e921eb1a | 3967 | /* the Tx fifo also stores 16 bytes of information about the Tx |
ad68076e | 3968 | * but don't include ethernet FCS because hardware appends it |
318a94d6 JK |
3969 | */ |
3970 | min_tx_space = (adapter->max_frame_size + | |
e5fe2541 | 3971 | sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2; |
bc7f75fa AK |
3972 | min_tx_space = ALIGN(min_tx_space, 1024); |
3973 | min_tx_space >>= 10; | |
3974 | /* software strips receive CRC, so leave room for it */ | |
318a94d6 | 3975 | min_rx_space = adapter->max_frame_size; |
bc7f75fa AK |
3976 | min_rx_space = ALIGN(min_rx_space, 1024); |
3977 | min_rx_space >>= 10; | |
3978 | ||
e921eb1a | 3979 | /* If current Tx allocation is less than the min Tx FIFO size, |
bc7f75fa | 3980 | * and the min Tx FIFO size is less than the current Rx FIFO |
ad68076e BA |
3981 | * allocation, take space away from current Rx allocation |
3982 | */ | |
df762464 AK |
3983 | if ((tx_space < min_tx_space) && |
3984 | ((min_tx_space - tx_space) < pba)) { | |
3985 | pba -= min_tx_space - tx_space; | |
bc7f75fa | 3986 | |
e921eb1a | 3987 | /* if short on Rx space, Rx wins and must trump Tx |
419e551c | 3988 | * adjustment |
ad68076e | 3989 | */ |
79d4e908 | 3990 | if (pba < min_rx_space) |
df762464 | 3991 | pba = min_rx_space; |
bc7f75fa | 3992 | } |
df762464 AK |
3993 | |
3994 | ew32(PBA, pba); | |
bc7f75fa AK |
3995 | } |
3996 | ||
e921eb1a | 3997 | /* flow control settings |
ad68076e | 3998 | * |
38eb394e | 3999 | * The high water mark must be low enough to fit one full frame |
bc7f75fa AK |
4000 | * (or the size used for early receive) above it in the Rx FIFO. |
4001 | * Set it to the lower of: | |
4002 | * - 90% of the Rx FIFO size, and | |
38eb394e | 4003 | * - the full Rx FIFO size minus one full frame |
ad68076e | 4004 | */ |
d3738bb8 BA |
4005 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
4006 | fc->pause_time = 0xFFFF; | |
4007 | else | |
4008 | fc->pause_time = E1000_FC_PAUSE_TIME; | |
b20caa80 | 4009 | fc->send_xon = true; |
d3738bb8 BA |
4010 | fc->current_mode = fc->requested_mode; |
4011 | ||
4012 | switch (hw->mac.type) { | |
79d4e908 BA |
4013 | case e1000_ich9lan: |
4014 | case e1000_ich10lan: | |
4015 | if (adapter->netdev->mtu > ETH_DATA_LEN) { | |
4016 | pba = 14; | |
4017 | ew32(PBA, pba); | |
4018 | fc->high_water = 0x2800; | |
4019 | fc->low_water = fc->high_water - 8; | |
4020 | break; | |
4021 | } | |
4022 | /* fall-through */ | |
d3738bb8 | 4023 | default: |
79d4e908 BA |
4024 | hwm = min(((pba << 10) * 9 / 10), |
4025 | ((pba << 10) - adapter->max_frame_size)); | |
d3738bb8 | 4026 | |
e80bd1d1 | 4027 | fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ |
d3738bb8 BA |
4028 | fc->low_water = fc->high_water - 8; |
4029 | break; | |
4030 | case e1000_pchlan: | |
e921eb1a | 4031 | /* Workaround PCH LOM adapter hangs with certain network |
38eb394e BA |
4032 | * loads. If hangs persist, try disabling Tx flow control. |
4033 | */ | |
4034 | if (adapter->netdev->mtu > ETH_DATA_LEN) { | |
4035 | fc->high_water = 0x3500; | |
e80bd1d1 | 4036 | fc->low_water = 0x1500; |
38eb394e BA |
4037 | } else { |
4038 | fc->high_water = 0x5000; | |
e80bd1d1 | 4039 | fc->low_water = 0x3000; |
38eb394e | 4040 | } |
a305595b | 4041 | fc->refresh_time = 0x1000; |
d3738bb8 BA |
4042 | break; |
4043 | case e1000_pch2lan: | |
2fbe4526 | 4044 | case e1000_pch_lpt: |
79849ebc | 4045 | case e1000_pch_spt: |
c8744f44 | 4046 | case e1000_pch_cnp: |
f74dc880 MBM |
4047 | fc->refresh_time = 0xFFFF; |
4048 | fc->pause_time = 0xFFFF; | |
347b5201 BA |
4049 | |
4050 | if (adapter->netdev->mtu <= ETH_DATA_LEN) { | |
4051 | fc->high_water = 0x05C20; | |
4052 | fc->low_water = 0x05048; | |
347b5201 | 4053 | break; |
828bac87 | 4054 | } |
347b5201 | 4055 | |
ce345e08 BA |
4056 | pba = 14; |
4057 | ew32(PBA, pba); | |
347b5201 BA |
4058 | fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH; |
4059 | fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL; | |
d3738bb8 | 4060 | break; |
38eb394e | 4061 | } |
bc7f75fa | 4062 | |
e921eb1a | 4063 | /* Alignment of Tx data is on an arbitrary byte boundary with the |
d821a4c4 BA |
4064 | * maximum size per Tx descriptor limited only to the transmit |
4065 | * allocation of the packet buffer minus 96 bytes with an upper | |
4066 | * limit of 24KB due to receive synchronization limitations. | |
4067 | */ | |
4068 | adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96, | |
4069 | 24 << 10); | |
4070 | ||
e921eb1a | 4071 | /* Disable Adaptive Interrupt Moderation if 2 full packets cannot |
79d4e908 | 4072 | * fit in receive buffer. |
828bac87 BA |
4073 | */ |
4074 | if (adapter->itr_setting & 0x3) { | |
79d4e908 | 4075 | if ((adapter->max_frame_size * 2) > (pba << 10)) { |
828bac87 BA |
4076 | if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) { |
4077 | dev_info(&adapter->pdev->dev, | |
17e813ec | 4078 | "Interrupt Throttle Rate off\n"); |
828bac87 | 4079 | adapter->flags2 |= FLAG2_DISABLE_AIM; |
22a4cca2 | 4080 | e1000e_write_itr(adapter, 0); |
828bac87 BA |
4081 | } |
4082 | } else if (adapter->flags2 & FLAG2_DISABLE_AIM) { | |
4083 | dev_info(&adapter->pdev->dev, | |
17e813ec | 4084 | "Interrupt Throttle Rate on\n"); |
828bac87 BA |
4085 | adapter->flags2 &= ~FLAG2_DISABLE_AIM; |
4086 | adapter->itr = 20000; | |
22a4cca2 | 4087 | e1000e_write_itr(adapter, adapter->itr); |
828bac87 BA |
4088 | } |
4089 | } | |
4090 | ||
c8744f44 | 4091 | if (hw->mac.type >= e1000_pch_spt) |
0ffc5646 | 4092 | e1000_flush_desc_rings(adapter); |
bc7f75fa AK |
4093 | /* Allow time for pending master requests to run */ |
4094 | mac->ops.reset_hw(hw); | |
97ac8cae | 4095 | |
e921eb1a | 4096 | /* For parts with AMT enabled, let the firmware know |
97ac8cae BA |
4097 | * that the network interface is in control |
4098 | */ | |
c43bc57e | 4099 | if (adapter->flags & FLAG_HAS_AMT) |
31dbe5b4 | 4100 | e1000e_get_hw_control(adapter); |
97ac8cae | 4101 | |
bc7f75fa AK |
4102 | ew32(WUC, 0); |
4103 | ||
4104 | if (mac->ops.init_hw(hw)) | |
44defeb3 | 4105 | e_err("Hardware Error\n"); |
bc7f75fa AK |
4106 | |
4107 | e1000_update_mng_vlan(adapter); | |
4108 | ||
4109 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ | |
4110 | ew32(VET, ETH_P_8021Q); | |
4111 | ||
4112 | e1000e_reset_adaptive(hw); | |
31dbe5b4 | 4113 | |
aa524b66 JK |
4114 | /* restore systim and hwtstamp settings */ |
4115 | e1000e_systim_reset(adapter); | |
b67e1913 | 4116 | |
d495bcb8 BA |
4117 | /* Set EEE advertisement as appropriate */ |
4118 | if (adapter->flags2 & FLAG2_HAS_EEE) { | |
4119 | s32 ret_val; | |
4120 | u16 adv_addr; | |
4121 | ||
4122 | switch (hw->phy.type) { | |
4123 | case e1000_phy_82579: | |
4124 | adv_addr = I82579_EEE_ADVERTISEMENT; | |
4125 | break; | |
4126 | case e1000_phy_i217: | |
4127 | adv_addr = I217_EEE_ADVERTISEMENT; | |
4128 | break; | |
4129 | default: | |
4130 | dev_err(&adapter->pdev->dev, | |
4131 | "Invalid PHY type setting EEE advertisement\n"); | |
4132 | return; | |
4133 | } | |
4134 | ||
4135 | ret_val = hw->phy.ops.acquire(hw); | |
4136 | if (ret_val) { | |
4137 | dev_err(&adapter->pdev->dev, | |
4138 | "EEE advertisement - unable to acquire PHY\n"); | |
4139 | return; | |
4140 | } | |
4141 | ||
4142 | e1000_write_emi_reg_locked(hw, adv_addr, | |
4143 | hw->dev_spec.ich8lan.eee_disable ? | |
4144 | 0 : adapter->eee_advert); | |
4145 | ||
4146 | hw->phy.ops.release(hw); | |
4147 | } | |
4148 | ||
31dbe5b4 | 4149 | if (!netif_running(adapter->netdev) && |
28002099 | 4150 | !test_bit(__E1000_TESTING, &adapter->state)) |
31dbe5b4 | 4151 | e1000_power_down_phy(adapter); |
31dbe5b4 | 4152 | |
bc7f75fa AK |
4153 | e1000_get_phy_info(hw); |
4154 | ||
918d7197 BA |
4155 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && |
4156 | !(adapter->flags & FLAG_SMART_POWER_DOWN)) { | |
bc7f75fa | 4157 | u16 phy_data = 0; |
e921eb1a | 4158 | /* speed up time to link by disabling smart power down, ignore |
bc7f75fa | 4159 | * the return value of this function because there is nothing |
ad68076e BA |
4160 | * different we would do if it failed |
4161 | */ | |
bc7f75fa AK |
4162 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
4163 | phy_data &= ~IGP02E1000_PM_SPD; | |
4164 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); | |
4165 | } | |
c8744f44 | 4166 | if (hw->mac.type >= e1000_pch_spt && adapter->int_mode == 0) { |
ec945cfb YL |
4167 | u32 reg; |
4168 | ||
4169 | /* Fextnvm7 @ 0xe4[2] = 1 */ | |
4170 | reg = er32(FEXTNVM7); | |
4171 | reg |= E1000_FEXTNVM7_SIDE_CLK_UNGATE; | |
4172 | ew32(FEXTNVM7, reg); | |
4173 | /* Fextnvm9 @ 0x5bb4[13:12] = 11 */ | |
4174 | reg = er32(FEXTNVM9); | |
4175 | reg |= E1000_FEXTNVM9_IOSFSB_CLKGATE_DIS | | |
4176 | E1000_FEXTNVM9_IOSFSB_CLKREQ_DIS; | |
4177 | ew32(FEXTNVM9, reg); | |
4178 | } | |
4179 | ||
bc7f75fa AK |
4180 | } |
4181 | ||
a61cfe4f BP |
4182 | /** |
4183 | * e1000e_trigger_lsc - trigger an LSC interrupt | |
4184 | * @adapter: | |
4185 | * | |
4186 | * Fire a link status change interrupt to start the watchdog. | |
4187 | **/ | |
4188 | static void e1000e_trigger_lsc(struct e1000_adapter *adapter) | |
bc7f75fa AK |
4189 | { |
4190 | struct e1000_hw *hw = &adapter->hw; | |
4191 | ||
a61cfe4f | 4192 | if (adapter->msix_entries) |
4aea7a5c | 4193 | ew32(ICS, E1000_ICS_LSC | E1000_ICS_OTHER); |
a61cfe4f BP |
4194 | else |
4195 | ew32(ICS, E1000_ICS_LSC); | |
4196 | } | |
4197 | ||
4198 | void e1000e_up(struct e1000_adapter *adapter) | |
4199 | { | |
bc7f75fa AK |
4200 | /* hardware has been reset, we need to reload some things */ |
4201 | e1000_configure(adapter); | |
4202 | ||
4203 | clear_bit(__E1000_DOWN, &adapter->state); | |
4204 | ||
4662e82b BA |
4205 | if (adapter->msix_entries) |
4206 | e1000_configure_msix(adapter); | |
bc7f75fa AK |
4207 | e1000_irq_enable(adapter); |
4208 | ||
d17ba0f6 | 4209 | /* Tx queue started by watchdog timer when link is up */ |
4cb9be7a | 4210 | |
a61cfe4f | 4211 | e1000e_trigger_lsc(adapter); |
bc7f75fa AK |
4212 | } |
4213 | ||
713b3c9e JB |
4214 | static void e1000e_flush_descriptors(struct e1000_adapter *adapter) |
4215 | { | |
4216 | struct e1000_hw *hw = &adapter->hw; | |
4217 | ||
4218 | if (!(adapter->flags2 & FLAG2_DMA_BURST)) | |
4219 | return; | |
4220 | ||
4221 | /* flush pending descriptor writebacks to memory */ | |
4222 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); | |
4223 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); | |
4224 | ||
4225 | /* execute the writes immediately */ | |
4226 | e1e_flush(); | |
bf03085f | 4227 | |
e921eb1a | 4228 | /* due to rare timing issues, write to TIDV/RDTR again to ensure the |
bf03085f MV |
4229 | * write is successful |
4230 | */ | |
4231 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); | |
4232 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); | |
713b3c9e JB |
4233 | |
4234 | /* execute the writes immediately */ | |
4235 | e1e_flush(); | |
4236 | } | |
4237 | ||
67fd4fcb JK |
4238 | static void e1000e_update_stats(struct e1000_adapter *adapter); |
4239 | ||
28002099 DE |
4240 | /** |
4241 | * e1000e_down - quiesce the device and optionally reset the hardware | |
4242 | * @adapter: board private structure | |
4243 | * @reset: boolean flag to reset the hardware or not | |
4244 | */ | |
4245 | void e1000e_down(struct e1000_adapter *adapter, bool reset) | |
bc7f75fa AK |
4246 | { |
4247 | struct net_device *netdev = adapter->netdev; | |
4248 | struct e1000_hw *hw = &adapter->hw; | |
4249 | u32 tctl, rctl; | |
4250 | ||
e921eb1a | 4251 | /* signal that we're down so the interrupt handler does not |
ad68076e BA |
4252 | * reschedule our watchdog timer |
4253 | */ | |
bc7f75fa AK |
4254 | set_bit(__E1000_DOWN, &adapter->state); |
4255 | ||
a60a132e ET |
4256 | netif_carrier_off(netdev); |
4257 | ||
bc7f75fa AK |
4258 | /* disable receives in the hardware */ |
4259 | rctl = er32(RCTL); | |
7f99ae63 BA |
4260 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
4261 | ew32(RCTL, rctl & ~E1000_RCTL_EN); | |
bc7f75fa AK |
4262 | /* flush and sleep below */ |
4263 | ||
4cb9be7a | 4264 | netif_stop_queue(netdev); |
bc7f75fa AK |
4265 | |
4266 | /* disable transmits in the hardware */ | |
4267 | tctl = er32(TCTL); | |
4268 | tctl &= ~E1000_TCTL_EN; | |
4269 | ew32(TCTL, tctl); | |
7f99ae63 | 4270 | |
bc7f75fa AK |
4271 | /* flush both disables and wait for them to finish */ |
4272 | e1e_flush(); | |
ab6973ae | 4273 | usleep_range(10000, 11000); |
bc7f75fa | 4274 | |
bc7f75fa AK |
4275 | e1000_irq_disable(adapter); |
4276 | ||
a3b87a4c BA |
4277 | napi_synchronize(&adapter->napi); |
4278 | ||
b4275924 | 4279 | del_timer_sync(&adapter->watchdog_timer); |
bc7f75fa AK |
4280 | del_timer_sync(&adapter->phy_info_timer); |
4281 | ||
67fd4fcb JK |
4282 | spin_lock(&adapter->stats64_lock); |
4283 | e1000e_update_stats(adapter); | |
4284 | spin_unlock(&adapter->stats64_lock); | |
4285 | ||
400484fa | 4286 | e1000e_flush_descriptors(adapter); |
400484fa | 4287 | |
bc7f75fa AK |
4288 | adapter->link_speed = 0; |
4289 | adapter->link_duplex = 0; | |
4290 | ||
da1e2046 BA |
4291 | /* Disable Si errata workaround on PCHx for jumbo frame flow */ |
4292 | if ((hw->mac.type >= e1000_pch2lan) && | |
4293 | (adapter->netdev->mtu > ETH_DATA_LEN) && | |
4294 | e1000_lv_jumbo_workaround_ich8lan(hw, false)) | |
4295 | e_dbg("failed to disable jumbo frame workaround mode\n"); | |
4296 | ||
0ffc5646 YL |
4297 | if (!pci_channel_offline(adapter->pdev)) { |
4298 | if (reset) | |
4299 | e1000e_reset(adapter); | |
c8744f44 | 4300 | else if (hw->mac.type >= e1000_pch_spt) |
0ffc5646 YL |
4301 | e1000_flush_desc_rings(adapter); |
4302 | } | |
4303 | e1000_clean_tx_ring(adapter->tx_ring); | |
4304 | e1000_clean_rx_ring(adapter->rx_ring); | |
bc7f75fa AK |
4305 | } |
4306 | ||
4307 | void e1000e_reinit_locked(struct e1000_adapter *adapter) | |
4308 | { | |
4309 | might_sleep(); | |
4310 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) | |
ab6973ae | 4311 | usleep_range(1000, 1100); |
28002099 | 4312 | e1000e_down(adapter, true); |
bc7f75fa AK |
4313 | e1000e_up(adapter); |
4314 | clear_bit(__E1000_RESETTING, &adapter->state); | |
4315 | } | |
4316 | ||
0be5b96c JW |
4317 | /** |
4318 | * e1000e_sanitize_systim - sanitize raw cycle counter reads | |
4319 | * @hw: pointer to the HW structure | |
98942d70 ML |
4320 | * @systim: PHC time value read, sanitized and returned |
4321 | * @sts: structure to hold system time before and after reading SYSTIML, | |
4322 | * may be NULL | |
0be5b96c JW |
4323 | * |
4324 | * Errata for 82574/82583 possible bad bits read from SYSTIMH/L: | |
4325 | * check to see that the time is incrementing at a reasonable | |
4326 | * rate and is a multiple of incvalue. | |
4327 | **/ | |
98942d70 ML |
4328 | static u64 e1000e_sanitize_systim(struct e1000_hw *hw, u64 systim, |
4329 | struct ptp_system_timestamp *sts) | |
0be5b96c JW |
4330 | { |
4331 | u64 time_delta, rem, temp; | |
a5a1d1c2 | 4332 | u64 systim_next; |
0be5b96c JW |
4333 | u32 incvalue; |
4334 | int i; | |
4335 | ||
4336 | incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK; | |
4337 | for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) { | |
4338 | /* latch SYSTIMH on read of SYSTIML */ | |
98942d70 | 4339 | ptp_read_system_prets(sts); |
a5a1d1c2 | 4340 | systim_next = (u64)er32(SYSTIML); |
98942d70 | 4341 | ptp_read_system_postts(sts); |
a5a1d1c2 | 4342 | systim_next |= (u64)er32(SYSTIMH) << 32; |
0be5b96c JW |
4343 | |
4344 | time_delta = systim_next - systim; | |
4345 | temp = time_delta; | |
4346 | /* VMWare users have seen incvalue of zero, don't div / 0 */ | |
4347 | rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0); | |
4348 | ||
4349 | systim = systim_next; | |
4350 | ||
4351 | if ((time_delta < E1000_82574_SYSTIM_EPSILON) && (rem == 0)) | |
4352 | break; | |
4353 | } | |
4354 | ||
4355 | return systim; | |
4356 | } | |
4357 | ||
b67e1913 | 4358 | /** |
98942d70 ML |
4359 | * e1000e_read_systim - read SYSTIM register |
4360 | * @adapter: board private structure | |
4361 | * @sts: structure which will contain system time before and after reading | |
4362 | * SYSTIML, may be NULL | |
b67e1913 | 4363 | **/ |
98942d70 ML |
4364 | u64 e1000e_read_systim(struct e1000_adapter *adapter, |
4365 | struct ptp_system_timestamp *sts) | |
b67e1913 | 4366 | { |
b67e1913 | 4367 | struct e1000_hw *hw = &adapter->hw; |
98942d70 | 4368 | u32 systimel, systimel_2, systimeh; |
a5a1d1c2 | 4369 | u64 systim; |
37b12910 RA |
4370 | /* SYSTIMH latching upon SYSTIML read does not work well. |
4371 | * This means that if SYSTIML overflows after we read it but before | |
4372 | * we read SYSTIMH, the value of SYSTIMH has been incremented and we | |
4373 | * will experience a huge non linear increment in the systime value | |
4374 | * to fix that we test for overflow and if true, we re-read systime. | |
83129b37 | 4375 | */ |
98942d70 | 4376 | ptp_read_system_prets(sts); |
ab507c9a | 4377 | systimel = er32(SYSTIML); |
98942d70 | 4378 | ptp_read_system_postts(sts); |
37b12910 | 4379 | systimeh = er32(SYSTIMH); |
ab507c9a DV |
4380 | /* Is systimel is so large that overflow is possible? */ |
4381 | if (systimel >= (u32)0xffffffff - E1000_TIMINCA_INCVALUE_MASK) { | |
98942d70 ML |
4382 | ptp_read_system_prets(sts); |
4383 | systimel_2 = er32(SYSTIML); | |
4384 | ptp_read_system_postts(sts); | |
ab507c9a DV |
4385 | if (systimel > systimel_2) { |
4386 | /* There was an overflow, read again SYSTIMH, and use | |
4387 | * systimel_2 | |
4388 | */ | |
4389 | systimeh = er32(SYSTIMH); | |
4390 | systimel = systimel_2; | |
4391 | } | |
37b12910 | 4392 | } |
a5a1d1c2 TG |
4393 | systim = (u64)systimel; |
4394 | systim |= (u64)systimeh << 32; | |
b67e1913 | 4395 | |
0be5b96c | 4396 | if (adapter->flags2 & FLAG2_CHECK_SYSTIM_OVERFLOW) |
98942d70 | 4397 | systim = e1000e_sanitize_systim(hw, systim, sts); |
5e7ff970 | 4398 | |
b67e1913 BA |
4399 | return systim; |
4400 | } | |
4401 | ||
98942d70 ML |
4402 | /** |
4403 | * e1000e_cyclecounter_read - read raw cycle counter (used by time counter) | |
4404 | * @cc: cyclecounter structure | |
4405 | **/ | |
4406 | static u64 e1000e_cyclecounter_read(const struct cyclecounter *cc) | |
4407 | { | |
4408 | struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter, | |
4409 | cc); | |
4410 | ||
4411 | return e1000e_read_systim(adapter, NULL); | |
4412 | } | |
4413 | ||
bc7f75fa AK |
4414 | /** |
4415 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) | |
4416 | * @adapter: board private structure to initialize | |
4417 | * | |
4418 | * e1000_sw_init initializes the Adapter private data structure. | |
4419 | * Fields are initialized based on PCI device information and | |
4420 | * OS network device settings (MTU size). | |
4421 | **/ | |
9f9a12f8 | 4422 | static int e1000_sw_init(struct e1000_adapter *adapter) |
bc7f75fa | 4423 | { |
bc7f75fa AK |
4424 | struct net_device *netdev = adapter->netdev; |
4425 | ||
8084b86d | 4426 | adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN; |
bc7f75fa | 4427 | adapter->rx_ps_bsize0 = 128; |
8084b86d | 4428 | adapter->max_frame_size = netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; |
318a94d6 | 4429 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
55aa6985 BA |
4430 | adapter->tx_ring_count = E1000_DEFAULT_TXD; |
4431 | adapter->rx_ring_count = E1000_DEFAULT_RXD; | |
bc7f75fa | 4432 | |
67fd4fcb JK |
4433 | spin_lock_init(&adapter->stats64_lock); |
4434 | ||
4662e82b | 4435 | e1000e_set_interrupt_capability(adapter); |
bc7f75fa | 4436 | |
4662e82b BA |
4437 | if (e1000_alloc_queues(adapter)) |
4438 | return -ENOMEM; | |
bc7f75fa | 4439 | |
b67e1913 BA |
4440 | /* Setup hardware time stamping cyclecounter */ |
4441 | if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) { | |
4442 | adapter->cc.read = e1000e_cyclecounter_read; | |
4d045b4c | 4443 | adapter->cc.mask = CYCLECOUNTER_MASK(64); |
b67e1913 BA |
4444 | adapter->cc.mult = 1; |
4445 | /* cc.shift set in e1000e_get_base_tininca() */ | |
4446 | ||
4447 | spin_lock_init(&adapter->systim_lock); | |
4448 | INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work); | |
4449 | } | |
4450 | ||
bc7f75fa | 4451 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
bc7f75fa AK |
4452 | e1000_irq_disable(adapter); |
4453 | ||
bc7f75fa AK |
4454 | set_bit(__E1000_DOWN, &adapter->state); |
4455 | return 0; | |
bc7f75fa AK |
4456 | } |
4457 | ||
f8d59f78 BA |
4458 | /** |
4459 | * e1000_intr_msi_test - Interrupt Handler | |
4460 | * @irq: interrupt number | |
4461 | * @data: pointer to a network interface device structure | |
4462 | **/ | |
8bb62869 | 4463 | static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data) |
f8d59f78 BA |
4464 | { |
4465 | struct net_device *netdev = data; | |
4466 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
4467 | struct e1000_hw *hw = &adapter->hw; | |
4468 | u32 icr = er32(ICR); | |
4469 | ||
3bb99fe2 | 4470 | e_dbg("icr is %08X\n", icr); |
f8d59f78 BA |
4471 | if (icr & E1000_ICR_RXSEQ) { |
4472 | adapter->flags &= ~FLAG_MSI_TEST_FAILED; | |
e921eb1a | 4473 | /* Force memory writes to complete before acknowledging the |
bc76329d BA |
4474 | * interrupt is handled. |
4475 | */ | |
f8d59f78 BA |
4476 | wmb(); |
4477 | } | |
4478 | ||
4479 | return IRQ_HANDLED; | |
4480 | } | |
4481 | ||
4482 | /** | |
4483 | * e1000_test_msi_interrupt - Returns 0 for successful test | |
4484 | * @adapter: board private struct | |
4485 | * | |
4486 | * code flow taken from tg3.c | |
4487 | **/ | |
4488 | static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) | |
4489 | { | |
4490 | struct net_device *netdev = adapter->netdev; | |
4491 | struct e1000_hw *hw = &adapter->hw; | |
4492 | int err; | |
4493 | ||
4494 | /* poll_enable hasn't been called yet, so don't need disable */ | |
4495 | /* clear any pending events */ | |
4496 | er32(ICR); | |
4497 | ||
4498 | /* free the real vector and request a test handler */ | |
4499 | e1000_free_irq(adapter); | |
4662e82b | 4500 | e1000e_reset_interrupt_capability(adapter); |
f8d59f78 BA |
4501 | |
4502 | /* Assume that the test fails, if it succeeds then the test | |
e921eb1a BA |
4503 | * MSI irq handler will unset this flag |
4504 | */ | |
f8d59f78 BA |
4505 | adapter->flags |= FLAG_MSI_TEST_FAILED; |
4506 | ||
4507 | err = pci_enable_msi(adapter->pdev); | |
4508 | if (err) | |
4509 | goto msi_test_failed; | |
4510 | ||
a0607fd3 | 4511 | err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, |
f8d59f78 BA |
4512 | netdev->name, netdev); |
4513 | if (err) { | |
4514 | pci_disable_msi(adapter->pdev); | |
4515 | goto msi_test_failed; | |
4516 | } | |
4517 | ||
e921eb1a | 4518 | /* Force memory writes to complete before enabling and firing an |
bc76329d BA |
4519 | * interrupt. |
4520 | */ | |
f8d59f78 BA |
4521 | wmb(); |
4522 | ||
4523 | e1000_irq_enable(adapter); | |
4524 | ||
4525 | /* fire an unusual interrupt on the test handler */ | |
4526 | ew32(ICS, E1000_ICS_RXSEQ); | |
4527 | e1e_flush(); | |
569a3aff | 4528 | msleep(100); |
f8d59f78 BA |
4529 | |
4530 | e1000_irq_disable(adapter); | |
4531 | ||
bc76329d | 4532 | rmb(); /* read flags after interrupt has been fired */ |
f8d59f78 BA |
4533 | |
4534 | if (adapter->flags & FLAG_MSI_TEST_FAILED) { | |
4662e82b | 4535 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
068e8a30 | 4536 | e_info("MSI interrupt test failed, using legacy interrupt.\n"); |
24b706b2 | 4537 | } else { |
068e8a30 | 4538 | e_dbg("MSI interrupt test succeeded!\n"); |
24b706b2 | 4539 | } |
f8d59f78 BA |
4540 | |
4541 | free_irq(adapter->pdev->irq, netdev); | |
4542 | pci_disable_msi(adapter->pdev); | |
4543 | ||
f8d59f78 | 4544 | msi_test_failed: |
4662e82b | 4545 | e1000e_set_interrupt_capability(adapter); |
068e8a30 | 4546 | return e1000_request_irq(adapter); |
f8d59f78 BA |
4547 | } |
4548 | ||
4549 | /** | |
4550 | * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored | |
4551 | * @adapter: board private struct | |
4552 | * | |
4553 | * code flow taken from tg3.c, called with e1000 interrupts disabled. | |
4554 | **/ | |
4555 | static int e1000_test_msi(struct e1000_adapter *adapter) | |
4556 | { | |
4557 | int err; | |
4558 | u16 pci_cmd; | |
4559 | ||
4560 | if (!(adapter->flags & FLAG_MSI_ENABLED)) | |
4561 | return 0; | |
4562 | ||
4563 | /* disable SERR in case the MSI write causes a master abort */ | |
4564 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); | |
36f2407f DN |
4565 | if (pci_cmd & PCI_COMMAND_SERR) |
4566 | pci_write_config_word(adapter->pdev, PCI_COMMAND, | |
4567 | pci_cmd & ~PCI_COMMAND_SERR); | |
f8d59f78 BA |
4568 | |
4569 | err = e1000_test_msi_interrupt(adapter); | |
4570 | ||
36f2407f DN |
4571 | /* re-enable SERR */ |
4572 | if (pci_cmd & PCI_COMMAND_SERR) { | |
4573 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); | |
4574 | pci_cmd |= PCI_COMMAND_SERR; | |
4575 | pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); | |
4576 | } | |
f8d59f78 | 4577 | |
f8d59f78 BA |
4578 | return err; |
4579 | } | |
4580 | ||
bc7f75fa | 4581 | /** |
d5ea45da | 4582 | * e1000e_open - Called when a network interface is made active |
bc7f75fa AK |
4583 | * @netdev: network interface device structure |
4584 | * | |
4585 | * Returns 0 on success, negative value on failure | |
4586 | * | |
4587 | * The open entry point is called when a network interface is made | |
4588 | * active by the system (IFF_UP). At this point all resources needed | |
4589 | * for transmit and receive operations are allocated, the interrupt | |
4590 | * handler is registered with the OS, the watchdog timer is started, | |
4591 | * and the stack is notified that the interface is ready. | |
4592 | **/ | |
d5ea45da | 4593 | int e1000e_open(struct net_device *netdev) |
bc7f75fa AK |
4594 | { |
4595 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
4596 | struct e1000_hw *hw = &adapter->hw; | |
23606cf5 | 4597 | struct pci_dev *pdev = adapter->pdev; |
bc7f75fa AK |
4598 | int err; |
4599 | ||
4600 | /* disallow open during test */ | |
4601 | if (test_bit(__E1000_TESTING, &adapter->state)) | |
4602 | return -EBUSY; | |
4603 | ||
23606cf5 RW |
4604 | pm_runtime_get_sync(&pdev->dev); |
4605 | ||
9c563d20 | 4606 | netif_carrier_off(netdev); |
d17ba0f6 | 4607 | netif_stop_queue(netdev); |
9c563d20 | 4608 | |
bc7f75fa | 4609 | /* allocate transmit descriptors */ |
55aa6985 | 4610 | err = e1000e_setup_tx_resources(adapter->tx_ring); |
bc7f75fa AK |
4611 | if (err) |
4612 | goto err_setup_tx; | |
4613 | ||
4614 | /* allocate receive descriptors */ | |
55aa6985 | 4615 | err = e1000e_setup_rx_resources(adapter->rx_ring); |
bc7f75fa AK |
4616 | if (err) |
4617 | goto err_setup_rx; | |
4618 | ||
e921eb1a | 4619 | /* If AMT is enabled, let the firmware know that the network |
11b08be8 BA |
4620 | * interface is now open and reset the part to a known state. |
4621 | */ | |
4622 | if (adapter->flags & FLAG_HAS_AMT) { | |
31dbe5b4 | 4623 | e1000e_get_hw_control(adapter); |
11b08be8 BA |
4624 | e1000e_reset(adapter); |
4625 | } | |
4626 | ||
bc7f75fa AK |
4627 | e1000e_power_up_phy(adapter); |
4628 | ||
4629 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; | |
e5fe2541 | 4630 | if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
bc7f75fa AK |
4631 | e1000_update_mng_vlan(adapter); |
4632 | ||
79d4e908 | 4633 | /* DMA latency requirement to workaround jumbo issue */ |
e2c65448 | 4634 | pm_qos_add_request(&adapter->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, |
3e35d991 | 4635 | PM_QOS_DEFAULT_VALUE); |
c128ec29 | 4636 | |
e921eb1a | 4637 | /* before we allocate an interrupt, we must be ready to handle it. |
bc7f75fa AK |
4638 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
4639 | * as soon as we call pci_request_irq, so we have to setup our | |
ad68076e BA |
4640 | * clean_rx handler before we do so. |
4641 | */ | |
bc7f75fa AK |
4642 | e1000_configure(adapter); |
4643 | ||
4644 | err = e1000_request_irq(adapter); | |
4645 | if (err) | |
4646 | goto err_req_irq; | |
4647 | ||
e921eb1a | 4648 | /* Work around PCIe errata with MSI interrupts causing some chipsets to |
f8d59f78 BA |
4649 | * ignore e1000e MSI messages, which means we need to test our MSI |
4650 | * interrupt now | |
4651 | */ | |
4662e82b | 4652 | if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { |
f8d59f78 BA |
4653 | err = e1000_test_msi(adapter); |
4654 | if (err) { | |
4655 | e_err("Interrupt allocation failed\n"); | |
4656 | goto err_req_irq; | |
4657 | } | |
4658 | } | |
4659 | ||
bc7f75fa AK |
4660 | /* From here on the code is the same as e1000e_up() */ |
4661 | clear_bit(__E1000_DOWN, &adapter->state); | |
4662 | ||
4663 | napi_enable(&adapter->napi); | |
4664 | ||
4665 | e1000_irq_enable(adapter); | |
4666 | ||
09357b00 | 4667 | adapter->tx_hang_recheck = false; |
d55b53ff | 4668 | |
66148bab | 4669 | hw->mac.get_link_status = true; |
23606cf5 RW |
4670 | pm_runtime_put(&pdev->dev); |
4671 | ||
a61cfe4f | 4672 | e1000e_trigger_lsc(adapter); |
bc7f75fa AK |
4673 | |
4674 | return 0; | |
4675 | ||
4676 | err_req_irq: | |
7faae964 | 4677 | pm_qos_remove_request(&adapter->pm_qos_req); |
31dbe5b4 | 4678 | e1000e_release_hw_control(adapter); |
bc7f75fa | 4679 | e1000_power_down_phy(adapter); |
55aa6985 | 4680 | e1000e_free_rx_resources(adapter->rx_ring); |
bc7f75fa | 4681 | err_setup_rx: |
55aa6985 | 4682 | e1000e_free_tx_resources(adapter->tx_ring); |
bc7f75fa AK |
4683 | err_setup_tx: |
4684 | e1000e_reset(adapter); | |
23606cf5 | 4685 | pm_runtime_put_sync(&pdev->dev); |
bc7f75fa AK |
4686 | |
4687 | return err; | |
4688 | } | |
4689 | ||
4690 | /** | |
d5ea45da | 4691 | * e1000e_close - Disables a network interface |
bc7f75fa AK |
4692 | * @netdev: network interface device structure |
4693 | * | |
4694 | * Returns 0, this is not allowed to fail | |
4695 | * | |
4696 | * The close entry point is called when an interface is de-activated | |
4697 | * by the OS. The hardware is still under the drivers control, but | |
4698 | * needs to be disabled. A global MAC reset is issued to stop the | |
4699 | * hardware, and all transmit and receive resources are freed. | |
4700 | **/ | |
d5ea45da | 4701 | int e1000e_close(struct net_device *netdev) |
bc7f75fa AK |
4702 | { |
4703 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
23606cf5 | 4704 | struct pci_dev *pdev = adapter->pdev; |
bb9e44d0 BA |
4705 | int count = E1000_CHECK_RESET_COUNT; |
4706 | ||
4707 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) | |
ab6973ae | 4708 | usleep_range(10000, 11000); |
bc7f75fa AK |
4709 | |
4710 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); | |
23606cf5 RW |
4711 | |
4712 | pm_runtime_get_sync(&pdev->dev); | |
4713 | ||
94d0b5b5 | 4714 | if (netif_device_present(netdev)) { |
28002099 | 4715 | e1000e_down(adapter, true); |
23606cf5 | 4716 | e1000_free_irq(adapter); |
63eb48f1 DE |
4717 | |
4718 | /* Link status message must follow this format */ | |
94d0b5b5 | 4719 | pr_info("%s NIC Link is Down\n", netdev->name); |
23606cf5 | 4720 | } |
a3b87a4c BA |
4721 | |
4722 | napi_disable(&adapter->napi); | |
4723 | ||
55aa6985 BA |
4724 | e1000e_free_tx_resources(adapter->tx_ring); |
4725 | e1000e_free_rx_resources(adapter->rx_ring); | |
bc7f75fa | 4726 | |
e921eb1a | 4727 | /* kill manageability vlan ID if supported, but not if a vlan with |
ad68076e BA |
4728 | * the same ID is registered on the host OS (let 8021q kill it) |
4729 | */ | |
e5fe2541 | 4730 | if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) |
80d5c368 PM |
4731 | e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), |
4732 | adapter->mng_vlan_id); | |
bc7f75fa | 4733 | |
e921eb1a | 4734 | /* If AMT is enabled, let the firmware know that the network |
ad68076e BA |
4735 | * interface is now closed |
4736 | */ | |
31dbe5b4 BA |
4737 | if ((adapter->flags & FLAG_HAS_AMT) && |
4738 | !test_bit(__E1000_TESTING, &adapter->state)) | |
4739 | e1000e_release_hw_control(adapter); | |
bc7f75fa | 4740 | |
e2c65448 | 4741 | pm_qos_remove_request(&adapter->pm_qos_req); |
c128ec29 | 4742 | |
23606cf5 RW |
4743 | pm_runtime_put_sync(&pdev->dev); |
4744 | ||
bc7f75fa AK |
4745 | return 0; |
4746 | } | |
fc830b78 | 4747 | |
bc7f75fa AK |
4748 | /** |
4749 | * e1000_set_mac - Change the Ethernet Address of the NIC | |
4750 | * @netdev: network interface device structure | |
4751 | * @p: pointer to an address structure | |
4752 | * | |
4753 | * Returns 0 on success, negative on failure | |
4754 | **/ | |
4755 | static int e1000_set_mac(struct net_device *netdev, void *p) | |
4756 | { | |
4757 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
69e1e019 | 4758 | struct e1000_hw *hw = &adapter->hw; |
bc7f75fa AK |
4759 | struct sockaddr *addr = p; |
4760 | ||
4761 | if (!is_valid_ether_addr(addr->sa_data)) | |
4762 | return -EADDRNOTAVAIL; | |
4763 | ||
4764 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); | |
4765 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); | |
4766 | ||
69e1e019 | 4767 | hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0); |
bc7f75fa AK |
4768 | |
4769 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { | |
4770 | /* activate the work around */ | |
4771 | e1000e_set_laa_state_82571(&adapter->hw, 1); | |
4772 | ||
e921eb1a | 4773 | /* Hold a copy of the LAA in RAR[14] This is done so that |
bc7f75fa AK |
4774 | * between the time RAR[0] gets clobbered and the time it |
4775 | * gets fixed (in e1000_watchdog), the actual LAA is in one | |
4776 | * of the RARs and no incoming packets directed to this port | |
4777 | * are dropped. Eventually the LAA will be in RAR[0] and | |
ad68076e BA |
4778 | * RAR[14] |
4779 | */ | |
69e1e019 BA |
4780 | hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, |
4781 | adapter->hw.mac.rar_entry_count - 1); | |
bc7f75fa AK |
4782 | } |
4783 | ||
4784 | return 0; | |
4785 | } | |
4786 | ||
a8f88ff5 JB |
4787 | /** |
4788 | * e1000e_update_phy_task - work thread to update phy | |
4789 | * @work: pointer to our work struct | |
4790 | * | |
4791 | * this worker thread exists because we must acquire a | |
4792 | * semaphore to read the phy, which we could msleep while | |
4793 | * waiting for it, and we can't msleep in a timer. | |
4794 | **/ | |
4795 | static void e1000e_update_phy_task(struct work_struct *work) | |
4796 | { | |
4797 | struct e1000_adapter *adapter = container_of(work, | |
17e813ec BA |
4798 | struct e1000_adapter, |
4799 | update_phy_task); | |
a03206ed | 4800 | struct e1000_hw *hw = &adapter->hw; |
615b32af JB |
4801 | |
4802 | if (test_bit(__E1000_DOWN, &adapter->state)) | |
4803 | return; | |
4804 | ||
a03206ed DE |
4805 | e1000_get_phy_info(hw); |
4806 | ||
4807 | /* Enable EEE on 82579 after link up */ | |
50844bb7 | 4808 | if (hw->phy.type >= e1000_phy_82579) |
a03206ed | 4809 | e1000_set_eee_pchlan(hw); |
a8f88ff5 JB |
4810 | } |
4811 | ||
e921eb1a BA |
4812 | /** |
4813 | * e1000_update_phy_info - timre call-back to update PHY info | |
4814 | * @data: pointer to adapter cast into an unsigned long | |
4815 | * | |
ad68076e BA |
4816 | * Need to wait a few seconds after link up to get diagnostic information from |
4817 | * the phy | |
e921eb1a | 4818 | **/ |
26566eae | 4819 | static void e1000_update_phy_info(struct timer_list *t) |
bc7f75fa | 4820 | { |
26566eae | 4821 | struct e1000_adapter *adapter = from_timer(adapter, t, phy_info_timer); |
615b32af JB |
4822 | |
4823 | if (test_bit(__E1000_DOWN, &adapter->state)) | |
4824 | return; | |
4825 | ||
a8f88ff5 | 4826 | schedule_work(&adapter->update_phy_task); |
bc7f75fa AK |
4827 | } |
4828 | ||
8c7bbb92 BA |
4829 | /** |
4830 | * e1000e_update_phy_stats - Update the PHY statistics counters | |
4831 | * @adapter: board private structure | |
2b6b168d BA |
4832 | * |
4833 | * Read/clear the upper 16-bit PHY registers and read/accumulate lower | |
8c7bbb92 BA |
4834 | **/ |
4835 | static void e1000e_update_phy_stats(struct e1000_adapter *adapter) | |
4836 | { | |
4837 | struct e1000_hw *hw = &adapter->hw; | |
4838 | s32 ret_val; | |
4839 | u16 phy_data; | |
4840 | ||
4841 | ret_val = hw->phy.ops.acquire(hw); | |
4842 | if (ret_val) | |
4843 | return; | |
4844 | ||
e921eb1a | 4845 | /* A page set is expensive so check if already on desired page. |
8c7bbb92 BA |
4846 | * If not, set to the page with the PHY status registers. |
4847 | */ | |
2b6b168d | 4848 | hw->phy.addr = 1; |
8c7bbb92 BA |
4849 | ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
4850 | &phy_data); | |
4851 | if (ret_val) | |
4852 | goto release; | |
2b6b168d BA |
4853 | if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) { |
4854 | ret_val = hw->phy.ops.set_page(hw, | |
4855 | HV_STATS_PAGE << IGP_PAGE_SHIFT); | |
8c7bbb92 BA |
4856 | if (ret_val) |
4857 | goto release; | |
4858 | } | |
4859 | ||
8c7bbb92 | 4860 | /* Single Collision Count */ |
2b6b168d BA |
4861 | hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data); |
4862 | ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data); | |
8c7bbb92 BA |
4863 | if (!ret_val) |
4864 | adapter->stats.scc += phy_data; | |
4865 | ||
4866 | /* Excessive Collision Count */ | |
2b6b168d BA |
4867 | hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data); |
4868 | ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data); | |
8c7bbb92 BA |
4869 | if (!ret_val) |
4870 | adapter->stats.ecol += phy_data; | |
4871 | ||
4872 | /* Multiple Collision Count */ | |
2b6b168d BA |
4873 | hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data); |
4874 | ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data); | |
8c7bbb92 BA |
4875 | if (!ret_val) |
4876 | adapter->stats.mcc += phy_data; | |
4877 | ||
4878 | /* Late Collision Count */ | |
2b6b168d BA |
4879 | hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data); |
4880 | ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data); | |
8c7bbb92 BA |
4881 | if (!ret_val) |
4882 | adapter->stats.latecol += phy_data; | |
4883 | ||
4884 | /* Collision Count - also used for adaptive IFS */ | |
2b6b168d BA |
4885 | hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data); |
4886 | ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data); | |
8c7bbb92 BA |
4887 | if (!ret_val) |
4888 | hw->mac.collision_delta = phy_data; | |
4889 | ||
4890 | /* Defer Count */ | |
2b6b168d BA |
4891 | hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data); |
4892 | ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data); | |
8c7bbb92 BA |
4893 | if (!ret_val) |
4894 | adapter->stats.dc += phy_data; | |
4895 | ||
4896 | /* Transmit with no CRS */ | |
2b6b168d BA |
4897 | hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data); |
4898 | ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data); | |
8c7bbb92 BA |
4899 | if (!ret_val) |
4900 | adapter->stats.tncrs += phy_data; | |
4901 | ||
4902 | release: | |
4903 | hw->phy.ops.release(hw); | |
4904 | } | |
4905 | ||
bc7f75fa AK |
4906 | /** |
4907 | * e1000e_update_stats - Update the board statistics counters | |
4908 | * @adapter: board private structure | |
4909 | **/ | |
67fd4fcb | 4910 | static void e1000e_update_stats(struct e1000_adapter *adapter) |
bc7f75fa | 4911 | { |
7274c20f | 4912 | struct net_device *netdev = adapter->netdev; |
bc7f75fa AK |
4913 | struct e1000_hw *hw = &adapter->hw; |
4914 | struct pci_dev *pdev = adapter->pdev; | |
bc7f75fa | 4915 | |
e921eb1a | 4916 | /* Prevent stats update while adapter is being reset, or if the pci |
bc7f75fa AK |
4917 | * connection is down. |
4918 | */ | |
4919 | if (adapter->link_speed == 0) | |
4920 | return; | |
4921 | if (pci_channel_offline(pdev)) | |
4922 | return; | |
4923 | ||
bc7f75fa AK |
4924 | adapter->stats.crcerrs += er32(CRCERRS); |
4925 | adapter->stats.gprc += er32(GPRC); | |
7c25769f | 4926 | adapter->stats.gorc += er32(GORCL); |
e80bd1d1 | 4927 | er32(GORCH); /* Clear gorc */ |
bc7f75fa AK |
4928 | adapter->stats.bprc += er32(BPRC); |
4929 | adapter->stats.mprc += er32(MPRC); | |
4930 | adapter->stats.roc += er32(ROC); | |
4931 | ||
bc7f75fa | 4932 | adapter->stats.mpc += er32(MPC); |
8c7bbb92 BA |
4933 | |
4934 | /* Half-duplex statistics */ | |
4935 | if (adapter->link_duplex == HALF_DUPLEX) { | |
4936 | if (adapter->flags2 & FLAG2_HAS_PHY_STATS) { | |
4937 | e1000e_update_phy_stats(adapter); | |
4938 | } else { | |
4939 | adapter->stats.scc += er32(SCC); | |
4940 | adapter->stats.ecol += er32(ECOL); | |
4941 | adapter->stats.mcc += er32(MCC); | |
4942 | adapter->stats.latecol += er32(LATECOL); | |
4943 | adapter->stats.dc += er32(DC); | |
4944 | ||
4945 | hw->mac.collision_delta = er32(COLC); | |
4946 | ||
4947 | if ((hw->mac.type != e1000_82574) && | |
4948 | (hw->mac.type != e1000_82583)) | |
4949 | adapter->stats.tncrs += er32(TNCRS); | |
4950 | } | |
4951 | adapter->stats.colc += hw->mac.collision_delta; | |
a4f58f54 | 4952 | } |
8c7bbb92 | 4953 | |
bc7f75fa AK |
4954 | adapter->stats.xonrxc += er32(XONRXC); |
4955 | adapter->stats.xontxc += er32(XONTXC); | |
4956 | adapter->stats.xoffrxc += er32(XOFFRXC); | |
4957 | adapter->stats.xofftxc += er32(XOFFTXC); | |
bc7f75fa | 4958 | adapter->stats.gptc += er32(GPTC); |
7c25769f | 4959 | adapter->stats.gotc += er32(GOTCL); |
e80bd1d1 | 4960 | er32(GOTCH); /* Clear gotc */ |
bc7f75fa AK |
4961 | adapter->stats.rnbc += er32(RNBC); |
4962 | adapter->stats.ruc += er32(RUC); | |
bc7f75fa AK |
4963 | |
4964 | adapter->stats.mptc += er32(MPTC); | |
4965 | adapter->stats.bptc += er32(BPTC); | |
4966 | ||
4967 | /* used for adaptive IFS */ | |
4968 | ||
4969 | hw->mac.tx_packet_delta = er32(TPT); | |
4970 | adapter->stats.tpt += hw->mac.tx_packet_delta; | |
bc7f75fa AK |
4971 | |
4972 | adapter->stats.algnerrc += er32(ALGNERRC); | |
4973 | adapter->stats.rxerrc += er32(RXERRC); | |
bc7f75fa AK |
4974 | adapter->stats.cexterr += er32(CEXTERR); |
4975 | adapter->stats.tsctc += er32(TSCTC); | |
4976 | adapter->stats.tsctfc += er32(TSCTFC); | |
4977 | ||
bc7f75fa | 4978 | /* Fill out the OS statistics structure */ |
7274c20f AK |
4979 | netdev->stats.multicast = adapter->stats.mprc; |
4980 | netdev->stats.collisions = adapter->stats.colc; | |
bc7f75fa AK |
4981 | |
4982 | /* Rx Errors */ | |
4983 | ||
e921eb1a | 4984 | /* RLEC on some newer hardware can be incorrect so build |
ad68076e BA |
4985 | * our own version based on RUC and ROC |
4986 | */ | |
7274c20f | 4987 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
f0ff4398 BA |
4988 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
4989 | adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr; | |
7274c20f | 4990 | netdev->stats.rx_length_errors = adapter->stats.ruc + |
f0ff4398 | 4991 | adapter->stats.roc; |
7274c20f AK |
4992 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
4993 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; | |
4994 | netdev->stats.rx_missed_errors = adapter->stats.mpc; | |
bc7f75fa AK |
4995 | |
4996 | /* Tx Errors */ | |
f0ff4398 | 4997 | netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol; |
7274c20f AK |
4998 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
4999 | netdev->stats.tx_window_errors = adapter->stats.latecol; | |
5000 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; | |
bc7f75fa AK |
5001 | |
5002 | /* Tx Dropped needs to be maintained elsewhere */ | |
5003 | ||
bc7f75fa AK |
5004 | /* Management Stats */ |
5005 | adapter->stats.mgptc += er32(MGTPTC); | |
5006 | adapter->stats.mgprc += er32(MGTPRC); | |
5007 | adapter->stats.mgpdc += er32(MGTPDC); | |
94fb848b BA |
5008 | |
5009 | /* Correctable ECC Errors */ | |
c8744f44 | 5010 | if (hw->mac.type >= e1000_pch_lpt) { |
94fb848b | 5011 | u32 pbeccsts = er32(PBECCSTS); |
6cf08d1c | 5012 | |
94fb848b BA |
5013 | adapter->corr_errors += |
5014 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; | |
5015 | adapter->uncorr_errors += | |
5016 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> | |
5017 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; | |
5018 | } | |
bc7f75fa AK |
5019 | } |
5020 | ||
7c25769f BA |
5021 | /** |
5022 | * e1000_phy_read_status - Update the PHY register status snapshot | |
5023 | * @adapter: board private structure | |
5024 | **/ | |
5025 | static void e1000_phy_read_status(struct e1000_adapter *adapter) | |
5026 | { | |
5027 | struct e1000_hw *hw = &adapter->hw; | |
5028 | struct e1000_phy_regs *phy = &adapter->phy_regs; | |
7c25769f | 5029 | |
97390ab8 BA |
5030 | if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) && |
5031 | (er32(STATUS) & E1000_STATUS_LU) && | |
7c25769f | 5032 | (adapter->hw.phy.media_type == e1000_media_type_copper)) { |
90da0669 BA |
5033 | int ret_val; |
5034 | ||
c2ade1a4 BA |
5035 | ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr); |
5036 | ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr); | |
5037 | ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise); | |
5038 | ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa); | |
5039 | ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion); | |
5040 | ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000); | |
5041 | ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000); | |
5042 | ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus); | |
7c25769f | 5043 | if (ret_val) |
44defeb3 | 5044 | e_warn("Error reading PHY register\n"); |
7c25769f | 5045 | } else { |
e921eb1a | 5046 | /* Do not read PHY registers if link is not up |
7c25769f BA |
5047 | * Set values to typical power-on defaults |
5048 | */ | |
5049 | phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); | |
5050 | phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | | |
5051 | BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | | |
5052 | BMSR_ERCAP); | |
5053 | phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | | |
5054 | ADVERTISE_ALL | ADVERTISE_CSMA); | |
5055 | phy->lpa = 0; | |
5056 | phy->expansion = EXPANSION_ENABLENPAGE; | |
5057 | phy->ctrl1000 = ADVERTISE_1000FULL; | |
5058 | phy->stat1000 = 0; | |
5059 | phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); | |
5060 | } | |
7c25769f BA |
5061 | } |
5062 | ||
bc7f75fa AK |
5063 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
5064 | { | |
bc7f75fa AK |
5065 | struct e1000_hw *hw = &adapter->hw; |
5066 | u32 ctrl = er32(CTRL); | |
5067 | ||
8f12fe86 | 5068 | /* Link status message must follow this format for user tools */ |
7dbc1672 BA |
5069 | pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n", |
5070 | adapter->netdev->name, adapter->link_speed, | |
ef456f85 JK |
5071 | adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half", |
5072 | (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" : | |
5073 | (ctrl & E1000_CTRL_RFCE) ? "Rx" : | |
5074 | (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None"); | |
bc7f75fa AK |
5075 | } |
5076 | ||
0c6bdb30 | 5077 | static bool e1000e_has_link(struct e1000_adapter *adapter) |
318a94d6 JK |
5078 | { |
5079 | struct e1000_hw *hw = &adapter->hw; | |
3db1cd5c | 5080 | bool link_active = false; |
318a94d6 JK |
5081 | s32 ret_val = 0; |
5082 | ||
e921eb1a | 5083 | /* get_link_status is set on LSC (link status) interrupt or |
318a94d6 | 5084 | * Rx sequence error interrupt. get_link_status will stay |
65a29da1 | 5085 | * true until the check_for_link establishes link |
318a94d6 JK |
5086 | * for copper adapters ONLY |
5087 | */ | |
5088 | switch (hw->phy.media_type) { | |
5089 | case e1000_media_type_copper: | |
5090 | if (hw->mac.get_link_status) { | |
5091 | ret_val = hw->mac.ops.check_for_link(hw); | |
3016e0a0 | 5092 | link_active = !hw->mac.get_link_status; |
318a94d6 | 5093 | } else { |
3db1cd5c | 5094 | link_active = true; |
318a94d6 JK |
5095 | } |
5096 | break; | |
5097 | case e1000_media_type_fiber: | |
5098 | ret_val = hw->mac.ops.check_for_link(hw); | |
5099 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); | |
5100 | break; | |
5101 | case e1000_media_type_internal_serdes: | |
5102 | ret_val = hw->mac.ops.check_for_link(hw); | |
65a29da1 | 5103 | link_active = hw->mac.serdes_has_link; |
318a94d6 JK |
5104 | break; |
5105 | default: | |
5106 | case e1000_media_type_unknown: | |
5107 | break; | |
5108 | } | |
5109 | ||
d3509f8b | 5110 | if ((ret_val == -E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && |
318a94d6 JK |
5111 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
5112 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ | |
44defeb3 | 5113 | e_info("Gigabit has been disabled, downgrading speed\n"); |
318a94d6 JK |
5114 | } |
5115 | ||
5116 | return link_active; | |
5117 | } | |
5118 | ||
5119 | static void e1000e_enable_receives(struct e1000_adapter *adapter) | |
5120 | { | |
5121 | /* make sure the receive unit is started */ | |
5122 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && | |
12d43f7d | 5123 | (adapter->flags & FLAG_RESTART_NOW)) { |
318a94d6 JK |
5124 | struct e1000_hw *hw = &adapter->hw; |
5125 | u32 rctl = er32(RCTL); | |
6cf08d1c | 5126 | |
318a94d6 | 5127 | ew32(RCTL, rctl | E1000_RCTL_EN); |
12d43f7d | 5128 | adapter->flags &= ~FLAG_RESTART_NOW; |
318a94d6 JK |
5129 | } |
5130 | } | |
5131 | ||
ff10e13c CW |
5132 | static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter) |
5133 | { | |
5134 | struct e1000_hw *hw = &adapter->hw; | |
5135 | ||
e921eb1a | 5136 | /* With 82574 controllers, PHY needs to be checked periodically |
ff10e13c CW |
5137 | * for hung state and reset, if two calls return true |
5138 | */ | |
5139 | if (e1000_check_phy_82574(hw)) | |
5140 | adapter->phy_hang_count++; | |
5141 | else | |
5142 | adapter->phy_hang_count = 0; | |
5143 | ||
5144 | if (adapter->phy_hang_count > 1) { | |
5145 | adapter->phy_hang_count = 0; | |
d9554e96 | 5146 | e_dbg("PHY appears hung - resetting\n"); |
ff10e13c CW |
5147 | schedule_work(&adapter->reset_task); |
5148 | } | |
5149 | } | |
5150 | ||
b4275924 JK |
5151 | /** |
5152 | * e1000_watchdog - Timer Call-back | |
5153 | * @data: pointer to adapter cast into an unsigned long | |
5154 | **/ | |
5155 | static void e1000_watchdog(struct timer_list *t) | |
5156 | { | |
5157 | struct e1000_adapter *adapter = from_timer(adapter, t, watchdog_timer); | |
5158 | ||
5159 | /* Do the rest outside of interrupt context */ | |
5160 | schedule_work(&adapter->watchdog_task); | |
5161 | ||
5162 | /* TODO: make this use queue_delayed_work() */ | |
5163 | } | |
5164 | ||
bc7f75fa AK |
5165 | static void e1000_watchdog_task(struct work_struct *work) |
5166 | { | |
5167 | struct e1000_adapter *adapter = container_of(work, | |
17e813ec | 5168 | struct e1000_adapter, |
b4275924 | 5169 | watchdog_task); |
bc7f75fa AK |
5170 | struct net_device *netdev = adapter->netdev; |
5171 | struct e1000_mac_info *mac = &adapter->hw.mac; | |
75eb0fad | 5172 | struct e1000_phy_info *phy = &adapter->hw.phy; |
bc7f75fa | 5173 | struct e1000_ring *tx_ring = adapter->tx_ring; |
def4ec6d | 5174 | u32 dmoff_exit_timeout = 100, tries = 0; |
bc7f75fa | 5175 | struct e1000_hw *hw = &adapter->hw; |
def4ec6d | 5176 | u32 link, tctl, pcim_state; |
bc7f75fa | 5177 | |
615b32af JB |
5178 | if (test_bit(__E1000_DOWN, &adapter->state)) |
5179 | return; | |
5180 | ||
b405e8df | 5181 | link = e1000e_has_link(adapter); |
318a94d6 | 5182 | if ((netif_carrier_ok(netdev)) && link) { |
23606cf5 RW |
5183 | /* Cancel scheduled suspend requests. */ |
5184 | pm_runtime_resume(netdev->dev.parent); | |
5185 | ||
318a94d6 | 5186 | e1000e_enable_receives(adapter); |
bc7f75fa | 5187 | goto link_up; |
bc7f75fa AK |
5188 | } |
5189 | ||
5190 | if ((e1000e_enable_tx_pkt_filtering(hw)) && | |
5191 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) | |
5192 | e1000_update_mng_vlan(adapter); | |
5193 | ||
bc7f75fa AK |
5194 | if (link) { |
5195 | if (!netif_carrier_ok(netdev)) { | |
3db1cd5c | 5196 | bool txb2b = true; |
23606cf5 RW |
5197 | |
5198 | /* Cancel scheduled suspend requests. */ | |
5199 | pm_runtime_resume(netdev->dev.parent); | |
5200 | ||
def4ec6d | 5201 | /* Checking if MAC is in DMoff state*/ |
ff65c8bb | 5202 | if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) { |
def4ec6d | 5203 | pcim_state = er32(STATUS); |
ff65c8bb SN |
5204 | while (pcim_state & E1000_STATUS_PCIM_STATE) { |
5205 | if (tries++ == dmoff_exit_timeout) { | |
5206 | e_dbg("Error in exiting dmoff\n"); | |
5207 | break; | |
5208 | } | |
5209 | usleep_range(10000, 20000); | |
5210 | pcim_state = er32(STATUS); | |
5211 | ||
5212 | /* Checking if MAC exited DMoff state */ | |
5213 | if (!(pcim_state & E1000_STATUS_PCIM_STATE)) | |
5214 | e1000_phy_hw_reset(&adapter->hw); | |
5215 | } | |
def4ec6d VL |
5216 | } |
5217 | ||
318a94d6 | 5218 | /* update snapshot of PHY registers on LSC */ |
7c25769f | 5219 | e1000_phy_read_status(adapter); |
bc7f75fa | 5220 | mac->ops.get_link_up_info(&adapter->hw, |
17e813ec BA |
5221 | &adapter->link_speed, |
5222 | &adapter->link_duplex); | |
bc7f75fa | 5223 | e1000_print_link_info(adapter); |
e792cd91 KS |
5224 | |
5225 | /* check if SmartSpeed worked */ | |
5226 | e1000e_check_downshift(hw); | |
5227 | if (phy->speed_downgraded) | |
5228 | netdev_warn(netdev, | |
5229 | "Link Speed was downgraded by SmartSpeed\n"); | |
5230 | ||
e921eb1a | 5231 | /* On supported PHYs, check for duplex mismatch only |
f4187b56 BA |
5232 | * if link has autonegotiated at 10/100 half |
5233 | */ | |
5234 | if ((hw->phy.type == e1000_phy_igp_3 || | |
5235 | hw->phy.type == e1000_phy_bm) && | |
138953bb | 5236 | hw->mac.autoneg && |
f4187b56 BA |
5237 | (adapter->link_speed == SPEED_10 || |
5238 | adapter->link_speed == SPEED_100) && | |
5239 | (adapter->link_duplex == HALF_DUPLEX)) { | |
5240 | u16 autoneg_exp; | |
5241 | ||
c2ade1a4 | 5242 | e1e_rphy(hw, MII_EXPANSION, &autoneg_exp); |
f4187b56 | 5243 | |
c2ade1a4 | 5244 | if (!(autoneg_exp & EXPANSION_NWAY)) |
ef456f85 | 5245 | e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n"); |
f4187b56 BA |
5246 | } |
5247 | ||
f49c57e1 | 5248 | /* adjust timeout factor according to speed/duplex */ |
bc7f75fa AK |
5249 | adapter->tx_timeout_factor = 1; |
5250 | switch (adapter->link_speed) { | |
5251 | case SPEED_10: | |
3db1cd5c | 5252 | txb2b = false; |
10f1b492 | 5253 | adapter->tx_timeout_factor = 16; |
bc7f75fa AK |
5254 | break; |
5255 | case SPEED_100: | |
3db1cd5c | 5256 | txb2b = false; |
4c86e0b9 | 5257 | adapter->tx_timeout_factor = 10; |
bc7f75fa AK |
5258 | break; |
5259 | } | |
5260 | ||
e921eb1a | 5261 | /* workaround: re-program speed mode bit after |
ad68076e BA |
5262 | * link-up event |
5263 | */ | |
bc7f75fa AK |
5264 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
5265 | !txb2b) { | |
5266 | u32 tarc0; | |
6cf08d1c | 5267 | |
e9ec2c0f | 5268 | tarc0 = er32(TARC(0)); |
bc7f75fa | 5269 | tarc0 &= ~SPEED_MODE_BIT; |
e9ec2c0f | 5270 | ew32(TARC(0), tarc0); |
bc7f75fa AK |
5271 | } |
5272 | ||
e921eb1a | 5273 | /* disable TSO for pcie and 10/100 speeds, to avoid |
ad68076e BA |
5274 | * some hardware issues |
5275 | */ | |
bc7f75fa AK |
5276 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
5277 | switch (adapter->link_speed) { | |
5278 | case SPEED_10: | |
5279 | case SPEED_100: | |
44defeb3 | 5280 | e_info("10/100 speed: disabling TSO\n"); |
bc7f75fa AK |
5281 | netdev->features &= ~NETIF_F_TSO; |
5282 | netdev->features &= ~NETIF_F_TSO6; | |
5283 | break; | |
5284 | case SPEED_1000: | |
5285 | netdev->features |= NETIF_F_TSO; | |
5286 | netdev->features |= NETIF_F_TSO6; | |
5287 | break; | |
5288 | default: | |
5289 | /* oops */ | |
5290 | break; | |
5291 | } | |
d364a579 KHF |
5292 | if (hw->mac.type == e1000_pch_spt) { |
5293 | netdev->features &= ~NETIF_F_TSO; | |
5294 | netdev->features &= ~NETIF_F_TSO6; | |
5295 | } | |
bc7f75fa AK |
5296 | } |
5297 | ||
e921eb1a | 5298 | /* enable transmits in the hardware, need to do this |
ad68076e BA |
5299 | * after setting TARC(0) |
5300 | */ | |
bc7f75fa AK |
5301 | tctl = er32(TCTL); |
5302 | tctl |= E1000_TCTL_EN; | |
5303 | ew32(TCTL, tctl); | |
5304 | ||
e921eb1a | 5305 | /* Perform any post-link-up configuration before |
75eb0fad BA |
5306 | * reporting link up. |
5307 | */ | |
5308 | if (phy->ops.cfg_on_link_up) | |
5309 | phy->ops.cfg_on_link_up(hw); | |
5310 | ||
d17ba0f6 | 5311 | netif_wake_queue(netdev); |
bc7f75fa | 5312 | netif_carrier_on(netdev); |
bc7f75fa AK |
5313 | |
5314 | if (!test_bit(__E1000_DOWN, &adapter->state)) | |
5315 | mod_timer(&adapter->phy_info_timer, | |
5316 | round_jiffies(jiffies + 2 * HZ)); | |
bc7f75fa AK |
5317 | } |
5318 | } else { | |
5319 | if (netif_carrier_ok(netdev)) { | |
5320 | adapter->link_speed = 0; | |
5321 | adapter->link_duplex = 0; | |
8f12fe86 | 5322 | /* Link status message must follow this format */ |
7dbc1672 | 5323 | pr_info("%s NIC Link is Down\n", adapter->netdev->name); |
bc7f75fa | 5324 | netif_carrier_off(netdev); |
d17ba0f6 | 5325 | netif_stop_queue(netdev); |
bc7f75fa AK |
5326 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
5327 | mod_timer(&adapter->phy_info_timer, | |
5328 | round_jiffies(jiffies + 2 * HZ)); | |
5329 | ||
d9554e96 DE |
5330 | /* 8000ES2LAN requires a Rx packet buffer work-around |
5331 | * on link down event; reset the controller to flush | |
5332 | * the Rx packet buffer. | |
12d43f7d | 5333 | */ |
caff422e | 5334 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) |
12d43f7d | 5335 | adapter->flags |= FLAG_RESTART_NOW; |
23606cf5 RW |
5336 | else |
5337 | pm_schedule_suspend(netdev->dev.parent, | |
17e813ec | 5338 | LINK_TIMEOUT); |
bc7f75fa AK |
5339 | } |
5340 | } | |
5341 | ||
5342 | link_up: | |
67fd4fcb | 5343 | spin_lock(&adapter->stats64_lock); |
bc7f75fa AK |
5344 | e1000e_update_stats(adapter); |
5345 | ||
5346 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; | |
5347 | adapter->tpt_old = adapter->stats.tpt; | |
5348 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; | |
5349 | adapter->colc_old = adapter->stats.colc; | |
5350 | ||
7c25769f BA |
5351 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
5352 | adapter->gorc_old = adapter->stats.gorc; | |
5353 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; | |
5354 | adapter->gotc_old = adapter->stats.gotc; | |
2084b114 | 5355 | spin_unlock(&adapter->stats64_lock); |
bc7f75fa | 5356 | |
caff422e KK |
5357 | /* If the link is lost the controller stops DMA, but |
5358 | * if there is queued Tx work it cannot be done. So | |
5359 | * reset the controller to flush the Tx packet buffers. | |
5360 | */ | |
5361 | if (!netif_carrier_ok(netdev) && | |
5362 | (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) | |
5363 | adapter->flags |= FLAG_RESTART_NOW; | |
5364 | ||
d9554e96 | 5365 | /* If reset is necessary, do it outside of interrupt context. */ |
12d43f7d | 5366 | if (adapter->flags & FLAG_RESTART_NOW) { |
90da0669 BA |
5367 | schedule_work(&adapter->reset_task); |
5368 | /* return immediately since reset is imminent */ | |
5369 | return; | |
bc7f75fa AK |
5370 | } |
5371 | ||
12d43f7d BA |
5372 | e1000e_update_adaptive(&adapter->hw); |
5373 | ||
eab2abf5 JB |
5374 | /* Simple mode for Interrupt Throttle Rate (ITR) */ |
5375 | if (adapter->itr_setting == 4) { | |
e921eb1a | 5376 | /* Symmetric Tx/Rx gets a reduced ITR=2000; |
eab2abf5 JB |
5377 | * Total asymmetrical Tx or Rx gets ITR=8000; |
5378 | * everyone else is between 2000-8000. | |
5379 | */ | |
5380 | u32 goc = (adapter->gotc + adapter->gorc) / 10000; | |
5381 | u32 dif = (adapter->gotc > adapter->gorc ? | |
17e813ec BA |
5382 | adapter->gotc - adapter->gorc : |
5383 | adapter->gorc - adapter->gotc) / 10000; | |
eab2abf5 JB |
5384 | u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
5385 | ||
22a4cca2 | 5386 | e1000e_write_itr(adapter, itr); |
eab2abf5 JB |
5387 | } |
5388 | ||
ad68076e | 5389 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
4662e82b BA |
5390 | if (adapter->msix_entries) |
5391 | ew32(ICS, adapter->rx_ring->ims_val); | |
5392 | else | |
5393 | ew32(ICS, E1000_ICS_RXDMT0); | |
bc7f75fa | 5394 | |
713b3c9e JB |
5395 | /* flush pending descriptors to memory before detecting Tx hang */ |
5396 | e1000e_flush_descriptors(adapter); | |
5397 | ||
bc7f75fa | 5398 | /* Force detection of hung controller every watchdog period */ |
3db1cd5c | 5399 | adapter->detect_tx_hung = true; |
bc7f75fa | 5400 | |
e921eb1a | 5401 | /* With 82571 controllers, LAA may be overwritten due to controller |
ad68076e BA |
5402 | * reset from the other port. Set the appropriate LAA in RAR[0] |
5403 | */ | |
bc7f75fa | 5404 | if (e1000e_get_laa_state_82571(hw)) |
69e1e019 | 5405 | hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0); |
bc7f75fa | 5406 | |
ff10e13c CW |
5407 | if (adapter->flags2 & FLAG2_CHECK_PHY_HANG) |
5408 | e1000e_check_82574_phy_workaround(adapter); | |
5409 | ||
b67e1913 BA |
5410 | /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */ |
5411 | if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) { | |
5412 | if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) && | |
5413 | (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) { | |
5414 | er32(RXSTMPH); | |
5415 | adapter->rx_hwtstamp_cleared++; | |
5416 | } else { | |
5417 | adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP; | |
5418 | } | |
5419 | } | |
5420 | ||
bc7f75fa AK |
5421 | /* Reset the timer */ |
5422 | if (!test_bit(__E1000_DOWN, &adapter->state)) | |
b4275924 JK |
5423 | mod_timer(&adapter->watchdog_timer, |
5424 | round_jiffies(jiffies + 2 * HZ)); | |
bc7f75fa AK |
5425 | } |
5426 | ||
5427 | #define E1000_TX_FLAGS_CSUM 0x00000001 | |
5428 | #define E1000_TX_FLAGS_VLAN 0x00000002 | |
5429 | #define E1000_TX_FLAGS_TSO 0x00000004 | |
5430 | #define E1000_TX_FLAGS_IPV4 0x00000008 | |
943146de | 5431 | #define E1000_TX_FLAGS_NO_FCS 0x00000010 |
b67e1913 | 5432 | #define E1000_TX_FLAGS_HWTSTAMP 0x00000020 |
bc7f75fa AK |
5433 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
5434 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 | |
5435 | ||
47ccd1ed VY |
5436 | static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb, |
5437 | __be16 protocol) | |
bc7f75fa | 5438 | { |
bc7f75fa AK |
5439 | struct e1000_context_desc *context_desc; |
5440 | struct e1000_buffer *buffer_info; | |
5441 | unsigned int i; | |
5442 | u32 cmd_length = 0; | |
70443ae9 | 5443 | u16 ipcse = 0, mss; |
bc7f75fa | 5444 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
bcf1f57f | 5445 | int err; |
bc7f75fa | 5446 | |
3d5e33c9 BA |
5447 | if (!skb_is_gso(skb)) |
5448 | return 0; | |
bc7f75fa | 5449 | |
bcf1f57f FR |
5450 | err = skb_cow_head(skb, 0); |
5451 | if (err < 0) | |
5452 | return err; | |
bc7f75fa | 5453 | |
3d5e33c9 BA |
5454 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
5455 | mss = skb_shinfo(skb)->gso_size; | |
47ccd1ed | 5456 | if (protocol == htons(ETH_P_IP)) { |
3d5e33c9 BA |
5457 | struct iphdr *iph = ip_hdr(skb); |
5458 | iph->tot_len = 0; | |
5459 | iph->check = 0; | |
5460 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, | |
f0ff4398 | 5461 | 0, IPPROTO_TCP, 0); |
3d5e33c9 BA |
5462 | cmd_length = E1000_TXD_CMD_IP; |
5463 | ipcse = skb_transport_offset(skb) - 1; | |
8e1e8a47 | 5464 | } else if (skb_is_gso_v6(skb)) { |
3d5e33c9 BA |
5465 | ipv6_hdr(skb)->payload_len = 0; |
5466 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, | |
f0ff4398 BA |
5467 | &ipv6_hdr(skb)->daddr, |
5468 | 0, IPPROTO_TCP, 0); | |
3d5e33c9 BA |
5469 | ipcse = 0; |
5470 | } | |
5471 | ipcss = skb_network_offset(skb); | |
5472 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; | |
5473 | tucss = skb_transport_offset(skb); | |
5474 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; | |
3d5e33c9 BA |
5475 | |
5476 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | | |
f0ff4398 | 5477 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
3d5e33c9 BA |
5478 | |
5479 | i = tx_ring->next_to_use; | |
5480 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); | |
5481 | buffer_info = &tx_ring->buffer_info[i]; | |
5482 | ||
e80bd1d1 BA |
5483 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
5484 | context_desc->lower_setup.ip_fields.ipcso = ipcso; | |
5485 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); | |
3d5e33c9 BA |
5486 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
5487 | context_desc->upper_setup.tcp_fields.tucso = tucso; | |
70443ae9 | 5488 | context_desc->upper_setup.tcp_fields.tucse = 0; |
e80bd1d1 | 5489 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
3d5e33c9 BA |
5490 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
5491 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); | |
5492 | ||
5493 | buffer_info->time_stamp = jiffies; | |
5494 | buffer_info->next_to_watch = i; | |
5495 | ||
5496 | i++; | |
5497 | if (i == tx_ring->count) | |
5498 | i = 0; | |
5499 | tx_ring->next_to_use = i; | |
5500 | ||
5501 | return 1; | |
bc7f75fa AK |
5502 | } |
5503 | ||
47ccd1ed VY |
5504 | static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb, |
5505 | __be16 protocol) | |
bc7f75fa | 5506 | { |
55aa6985 | 5507 | struct e1000_adapter *adapter = tx_ring->adapter; |
bc7f75fa AK |
5508 | struct e1000_context_desc *context_desc; |
5509 | struct e1000_buffer *buffer_info; | |
5510 | unsigned int i; | |
5511 | u8 css; | |
af807c82 | 5512 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
bc7f75fa | 5513 | |
af807c82 | 5514 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
3992c8ed | 5515 | return false; |
bc7f75fa | 5516 | |
3f518390 | 5517 | switch (protocol) { |
09640e63 | 5518 | case cpu_to_be16(ETH_P_IP): |
af807c82 DG |
5519 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
5520 | cmd_len |= E1000_TXD_CMD_TCP; | |
5521 | break; | |
09640e63 | 5522 | case cpu_to_be16(ETH_P_IPV6): |
af807c82 DG |
5523 | /* XXX not handling all IPV6 headers */ |
5524 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) | |
5525 | cmd_len |= E1000_TXD_CMD_TCP; | |
5526 | break; | |
5527 | default: | |
5528 | if (unlikely(net_ratelimit())) | |
5f66f208 AJ |
5529 | e_warn("checksum_partial proto=%x!\n", |
5530 | be16_to_cpu(protocol)); | |
af807c82 | 5531 | break; |
bc7f75fa AK |
5532 | } |
5533 | ||
0d0b1672 | 5534 | css = skb_checksum_start_offset(skb); |
af807c82 DG |
5535 | |
5536 | i = tx_ring->next_to_use; | |
5537 | buffer_info = &tx_ring->buffer_info[i]; | |
5538 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); | |
5539 | ||
5540 | context_desc->lower_setup.ip_config = 0; | |
5541 | context_desc->upper_setup.tcp_fields.tucss = css; | |
f0ff4398 | 5542 | context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset; |
af807c82 DG |
5543 | context_desc->upper_setup.tcp_fields.tucse = 0; |
5544 | context_desc->tcp_seg_setup.data = 0; | |
5545 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); | |
5546 | ||
5547 | buffer_info->time_stamp = jiffies; | |
5548 | buffer_info->next_to_watch = i; | |
5549 | ||
5550 | i++; | |
5551 | if (i == tx_ring->count) | |
5552 | i = 0; | |
5553 | tx_ring->next_to_use = i; | |
5554 | ||
3992c8ed | 5555 | return true; |
bc7f75fa AK |
5556 | } |
5557 | ||
55aa6985 BA |
5558 | static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb, |
5559 | unsigned int first, unsigned int max_per_txd, | |
d821a4c4 | 5560 | unsigned int nr_frags) |
bc7f75fa | 5561 | { |
55aa6985 | 5562 | struct e1000_adapter *adapter = tx_ring->adapter; |
03b1320d | 5563 | struct pci_dev *pdev = adapter->pdev; |
1b7719c4 | 5564 | struct e1000_buffer *buffer_info; |
8ddc951c | 5565 | unsigned int len = skb_headlen(skb); |
03b1320d | 5566 | unsigned int offset = 0, size, count = 0, i; |
9ed318d5 | 5567 | unsigned int f, bytecount, segs; |
bc7f75fa AK |
5568 | |
5569 | i = tx_ring->next_to_use; | |
5570 | ||
5571 | while (len) { | |
1b7719c4 | 5572 | buffer_info = &tx_ring->buffer_info[i]; |
bc7f75fa AK |
5573 | size = min(len, max_per_txd); |
5574 | ||
bc7f75fa | 5575 | buffer_info->length = size; |
bc7f75fa | 5576 | buffer_info->time_stamp = jiffies; |
bc7f75fa | 5577 | buffer_info->next_to_watch = i; |
0be3f55f NN |
5578 | buffer_info->dma = dma_map_single(&pdev->dev, |
5579 | skb->data + offset, | |
af667a29 | 5580 | size, DMA_TO_DEVICE); |
03b1320d | 5581 | buffer_info->mapped_as_page = false; |
0be3f55f | 5582 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
03b1320d | 5583 | goto dma_error; |
bc7f75fa AK |
5584 | |
5585 | len -= size; | |
5586 | offset += size; | |
03b1320d | 5587 | count++; |
1b7719c4 AD |
5588 | |
5589 | if (len) { | |
5590 | i++; | |
5591 | if (i == tx_ring->count) | |
5592 | i = 0; | |
5593 | } | |
bc7f75fa AK |
5594 | } |
5595 | ||
5596 | for (f = 0; f < nr_frags; f++) { | |
d7840976 | 5597 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[f]; |
bc7f75fa | 5598 | |
9e903e08 | 5599 | len = skb_frag_size(frag); |
877749bf | 5600 | offset = 0; |
bc7f75fa AK |
5601 | |
5602 | while (len) { | |
1b7719c4 AD |
5603 | i++; |
5604 | if (i == tx_ring->count) | |
5605 | i = 0; | |
5606 | ||
bc7f75fa AK |
5607 | buffer_info = &tx_ring->buffer_info[i]; |
5608 | size = min(len, max_per_txd); | |
bc7f75fa AK |
5609 | |
5610 | buffer_info->length = size; | |
5611 | buffer_info->time_stamp = jiffies; | |
bc7f75fa | 5612 | buffer_info->next_to_watch = i; |
877749bf | 5613 | buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag, |
17e813ec BA |
5614 | offset, size, |
5615 | DMA_TO_DEVICE); | |
03b1320d | 5616 | buffer_info->mapped_as_page = true; |
0be3f55f | 5617 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
03b1320d | 5618 | goto dma_error; |
bc7f75fa AK |
5619 | |
5620 | len -= size; | |
5621 | offset += size; | |
5622 | count++; | |
bc7f75fa AK |
5623 | } |
5624 | } | |
5625 | ||
af667a29 | 5626 | segs = skb_shinfo(skb)->gso_segs ? : 1; |
9ed318d5 TH |
5627 | /* multiply data chunks by size of headers */ |
5628 | bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len; | |
5629 | ||
bc7f75fa | 5630 | tx_ring->buffer_info[i].skb = skb; |
9ed318d5 TH |
5631 | tx_ring->buffer_info[i].segs = segs; |
5632 | tx_ring->buffer_info[i].bytecount = bytecount; | |
bc7f75fa AK |
5633 | tx_ring->buffer_info[first].next_to_watch = i; |
5634 | ||
5635 | return count; | |
03b1320d AD |
5636 | |
5637 | dma_error: | |
af667a29 | 5638 | dev_err(&pdev->dev, "Tx DMA map failed\n"); |
03b1320d | 5639 | buffer_info->dma = 0; |
c1fa347f | 5640 | if (count) |
03b1320d | 5641 | count--; |
c1fa347f RK |
5642 | |
5643 | while (count--) { | |
af667a29 | 5644 | if (i == 0) |
03b1320d | 5645 | i += tx_ring->count; |
c1fa347f | 5646 | i--; |
03b1320d | 5647 | buffer_info = &tx_ring->buffer_info[i]; |
377b6273 | 5648 | e1000_put_txbuf(tx_ring, buffer_info, true); |
03b1320d AD |
5649 | } |
5650 | ||
5651 | return 0; | |
bc7f75fa AK |
5652 | } |
5653 | ||
55aa6985 | 5654 | static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count) |
bc7f75fa | 5655 | { |
55aa6985 | 5656 | struct e1000_adapter *adapter = tx_ring->adapter; |
bc7f75fa AK |
5657 | struct e1000_tx_desc *tx_desc = NULL; |
5658 | struct e1000_buffer *buffer_info; | |
5659 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; | |
5660 | unsigned int i; | |
5661 | ||
5662 | if (tx_flags & E1000_TX_FLAGS_TSO) { | |
5663 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | | |
f0ff4398 | 5664 | E1000_TXD_CMD_TSE; |
bc7f75fa AK |
5665 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
5666 | ||
5667 | if (tx_flags & E1000_TX_FLAGS_IPV4) | |
5668 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; | |
5669 | } | |
5670 | ||
5671 | if (tx_flags & E1000_TX_FLAGS_CSUM) { | |
5672 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; | |
5673 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; | |
5674 | } | |
5675 | ||
5676 | if (tx_flags & E1000_TX_FLAGS_VLAN) { | |
5677 | txd_lower |= E1000_TXD_CMD_VLE; | |
5678 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); | |
5679 | } | |
5680 | ||
943146de BG |
5681 | if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS)) |
5682 | txd_lower &= ~(E1000_TXD_CMD_IFCS); | |
5683 | ||
b67e1913 BA |
5684 | if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) { |
5685 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; | |
5686 | txd_upper |= E1000_TXD_EXTCMD_TSTAMP; | |
5687 | } | |
5688 | ||
bc7f75fa AK |
5689 | i = tx_ring->next_to_use; |
5690 | ||
36b973df | 5691 | do { |
bc7f75fa AK |
5692 | buffer_info = &tx_ring->buffer_info[i]; |
5693 | tx_desc = E1000_TX_DESC(*tx_ring, i); | |
5694 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); | |
f0ff4398 BA |
5695 | tx_desc->lower.data = cpu_to_le32(txd_lower | |
5696 | buffer_info->length); | |
bc7f75fa AK |
5697 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
5698 | ||
5699 | i++; | |
5700 | if (i == tx_ring->count) | |
5701 | i = 0; | |
36b973df | 5702 | } while (--count > 0); |
bc7f75fa AK |
5703 | |
5704 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); | |
5705 | ||
943146de BG |
5706 | /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */ |
5707 | if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS)) | |
5708 | tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS)); | |
5709 | ||
e921eb1a | 5710 | /* Force memory writes to complete before letting h/w |
bc7f75fa AK |
5711 | * know there are new descriptors to fetch. (Only |
5712 | * applicable for weak-ordered memory model archs, | |
ad68076e BA |
5713 | * such as IA-64). |
5714 | */ | |
bc7f75fa AK |
5715 | wmb(); |
5716 | ||
5717 | tx_ring->next_to_use = i; | |
bc7f75fa AK |
5718 | } |
5719 | ||
5720 | #define MINIMUM_DHCP_PACKET_SIZE 282 | |
5721 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, | |
5722 | struct sk_buff *skb) | |
5723 | { | |
e80bd1d1 | 5724 | struct e1000_hw *hw = &adapter->hw; |
bc7f75fa AK |
5725 | u16 length, offset; |
5726 | ||
df8a39de JP |
5727 | if (skb_vlan_tag_present(skb) && |
5728 | !((skb_vlan_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && | |
d60923c4 BA |
5729 | (adapter->hw.mng_cookie.status & |
5730 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) | |
5731 | return 0; | |
bc7f75fa AK |
5732 | |
5733 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) | |
5734 | return 0; | |
5735 | ||
53aa82da | 5736 | if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP)) |
bc7f75fa AK |
5737 | return 0; |
5738 | ||
5739 | { | |
362e20ca | 5740 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14); |
bc7f75fa AK |
5741 | struct udphdr *udp; |
5742 | ||
5743 | if (ip->protocol != IPPROTO_UDP) | |
5744 | return 0; | |
5745 | ||
5746 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); | |
5747 | if (ntohs(udp->dest) != 67) | |
5748 | return 0; | |
5749 | ||
5750 | offset = (u8 *)udp + 8 - skb->data; | |
5751 | length = skb->len - offset; | |
5752 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); | |
5753 | } | |
5754 | ||
5755 | return 0; | |
5756 | } | |
5757 | ||
55aa6985 | 5758 | static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size) |
bc7f75fa | 5759 | { |
55aa6985 | 5760 | struct e1000_adapter *adapter = tx_ring->adapter; |
bc7f75fa | 5761 | |
55aa6985 | 5762 | netif_stop_queue(adapter->netdev); |
e921eb1a | 5763 | /* Herbert's original patch had: |
bc7f75fa | 5764 | * smp_mb__after_netif_stop_queue(); |
ad68076e BA |
5765 | * but since that doesn't exist yet, just open code it. |
5766 | */ | |
bc7f75fa AK |
5767 | smp_mb(); |
5768 | ||
e921eb1a | 5769 | /* We need to check again in a case another CPU has just |
ad68076e BA |
5770 | * made room available. |
5771 | */ | |
55aa6985 | 5772 | if (e1000_desc_unused(tx_ring) < size) |
bc7f75fa AK |
5773 | return -EBUSY; |
5774 | ||
5775 | /* A reprieve! */ | |
55aa6985 | 5776 | netif_start_queue(adapter->netdev); |
bc7f75fa AK |
5777 | ++adapter->restart_queue; |
5778 | return 0; | |
5779 | } | |
5780 | ||
55aa6985 | 5781 | static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size) |
bc7f75fa | 5782 | { |
d821a4c4 BA |
5783 | BUG_ON(size > tx_ring->count); |
5784 | ||
55aa6985 | 5785 | if (e1000_desc_unused(tx_ring) >= size) |
bc7f75fa | 5786 | return 0; |
55aa6985 | 5787 | return __e1000_maybe_stop_tx(tx_ring, size); |
bc7f75fa AK |
5788 | } |
5789 | ||
3b29a56d SH |
5790 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
5791 | struct net_device *netdev) | |
bc7f75fa AK |
5792 | { |
5793 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
5794 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
5795 | unsigned int first; | |
bc7f75fa | 5796 | unsigned int tx_flags = 0; |
e743d313 | 5797 | unsigned int len = skb_headlen(skb); |
4e6c709c AK |
5798 | unsigned int nr_frags; |
5799 | unsigned int mss; | |
bc7f75fa AK |
5800 | int count = 0; |
5801 | int tso; | |
5802 | unsigned int f; | |
47ccd1ed | 5803 | __be16 protocol = vlan_get_protocol(skb); |
bc7f75fa AK |
5804 | |
5805 | if (test_bit(__E1000_DOWN, &adapter->state)) { | |
5806 | dev_kfree_skb_any(skb); | |
5807 | return NETDEV_TX_OK; | |
5808 | } | |
5809 | ||
5810 | if (skb->len <= 0) { | |
5811 | dev_kfree_skb_any(skb); | |
5812 | return NETDEV_TX_OK; | |
5813 | } | |
5814 | ||
e921eb1a | 5815 | /* The minimum packet size with TCTL.PSP set is 17 bytes so |
6e97c170 TD |
5816 | * pad skb in order to meet this minimum size requirement |
5817 | */ | |
a94d9e22 AD |
5818 | if (skb_put_padto(skb, 17)) |
5819 | return NETDEV_TX_OK; | |
6e97c170 | 5820 | |
bc7f75fa | 5821 | mss = skb_shinfo(skb)->gso_size; |
bc7f75fa AK |
5822 | if (mss) { |
5823 | u8 hdr_len; | |
bc7f75fa | 5824 | |
e921eb1a | 5825 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
ad68076e BA |
5826 | * points to just header, pull a few bytes of payload from |
5827 | * frags into skb->data | |
5828 | */ | |
bc7f75fa | 5829 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
e921eb1a | 5830 | /* we do this workaround for ES2LAN, but it is un-necessary, |
ad68076e BA |
5831 | * avoiding it could save a lot of cycles |
5832 | */ | |
4e6c709c | 5833 | if (skb->data_len && (hdr_len == len)) { |
bc7f75fa AK |
5834 | unsigned int pull_size; |
5835 | ||
a2a5b323 | 5836 | pull_size = min_t(unsigned int, 4, skb->data_len); |
bc7f75fa | 5837 | if (!__pskb_pull_tail(skb, pull_size)) { |
44defeb3 | 5838 | e_err("__pskb_pull_tail failed.\n"); |
bc7f75fa AK |
5839 | dev_kfree_skb_any(skb); |
5840 | return NETDEV_TX_OK; | |
5841 | } | |
e743d313 | 5842 | len = skb_headlen(skb); |
bc7f75fa AK |
5843 | } |
5844 | } | |
5845 | ||
5846 | /* reserve a descriptor for the offload context */ | |
5847 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) | |
5848 | count++; | |
5849 | count++; | |
5850 | ||
d821a4c4 | 5851 | count += DIV_ROUND_UP(len, adapter->tx_fifo_limit); |
bc7f75fa AK |
5852 | |
5853 | nr_frags = skb_shinfo(skb)->nr_frags; | |
5854 | for (f = 0; f < nr_frags; f++) | |
d821a4c4 BA |
5855 | count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]), |
5856 | adapter->tx_fifo_limit); | |
bc7f75fa AK |
5857 | |
5858 | if (adapter->hw.mac.tx_pkt_filtering) | |
5859 | e1000_transfer_dhcp_info(adapter, skb); | |
5860 | ||
e921eb1a | 5861 | /* need: count + 2 desc gap to keep tail from touching |
ad68076e BA |
5862 | * head, otherwise try next time |
5863 | */ | |
55aa6985 | 5864 | if (e1000_maybe_stop_tx(tx_ring, count + 2)) |
bc7f75fa | 5865 | return NETDEV_TX_BUSY; |
bc7f75fa | 5866 | |
df8a39de | 5867 | if (skb_vlan_tag_present(skb)) { |
bc7f75fa | 5868 | tx_flags |= E1000_TX_FLAGS_VLAN; |
df8a39de JP |
5869 | tx_flags |= (skb_vlan_tag_get(skb) << |
5870 | E1000_TX_FLAGS_VLAN_SHIFT); | |
bc7f75fa AK |
5871 | } |
5872 | ||
5873 | first = tx_ring->next_to_use; | |
5874 | ||
47ccd1ed | 5875 | tso = e1000_tso(tx_ring, skb, protocol); |
bc7f75fa AK |
5876 | if (tso < 0) { |
5877 | dev_kfree_skb_any(skb); | |
bc7f75fa AK |
5878 | return NETDEV_TX_OK; |
5879 | } | |
5880 | ||
5881 | if (tso) | |
5882 | tx_flags |= E1000_TX_FLAGS_TSO; | |
47ccd1ed | 5883 | else if (e1000_tx_csum(tx_ring, skb, protocol)) |
bc7f75fa AK |
5884 | tx_flags |= E1000_TX_FLAGS_CSUM; |
5885 | ||
e921eb1a | 5886 | /* Old method was to assume IPv4 packet by default if TSO was enabled. |
bc7f75fa | 5887 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
ad68076e BA |
5888 | * no longer assume, we must. |
5889 | */ | |
47ccd1ed | 5890 | if (protocol == htons(ETH_P_IP)) |
bc7f75fa AK |
5891 | tx_flags |= E1000_TX_FLAGS_IPV4; |
5892 | ||
943146de BG |
5893 | if (unlikely(skb->no_fcs)) |
5894 | tx_flags |= E1000_TX_FLAGS_NO_FCS; | |
5895 | ||
25985edc | 5896 | /* if count is 0 then mapping error has occurred */ |
d821a4c4 BA |
5897 | count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit, |
5898 | nr_frags); | |
1b7719c4 | 5899 | if (count) { |
6930895d | 5900 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
cff57141 JK |
5901 | (adapter->flags & FLAG_HAS_HW_TIMESTAMP)) { |
5902 | if (!adapter->tx_hwtstamp_skb) { | |
5903 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; | |
5904 | tx_flags |= E1000_TX_FLAGS_HWTSTAMP; | |
5905 | adapter->tx_hwtstamp_skb = skb_get(skb); | |
5906 | adapter->tx_hwtstamp_start = jiffies; | |
5907 | schedule_work(&adapter->tx_hwtstamp_work); | |
5908 | } else { | |
5909 | adapter->tx_hwtstamp_skipped++; | |
5910 | } | |
b67e1913 | 5911 | } |
80be3129 | 5912 | |
74abc9b1 ML |
5913 | skb_tx_timestamp(skb); |
5914 | ||
3f0cfa3b | 5915 | netdev_sent_queue(netdev, skb->len); |
55aa6985 | 5916 | e1000_tx_queue(tx_ring, tx_flags, count); |
1b7719c4 | 5917 | /* Make sure there is space in the ring for the next send. */ |
d821a4c4 BA |
5918 | e1000_maybe_stop_tx(tx_ring, |
5919 | (MAX_SKB_FRAGS * | |
5920 | DIV_ROUND_UP(PAGE_SIZE, | |
5921 | adapter->tx_fifo_limit) + 2)); | |
472f31f5 | 5922 | |
6b16f9ee | 5923 | if (!netdev_xmit_more() || |
472f31f5 FW |
5924 | netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) { |
5925 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) | |
5926 | e1000e_update_tdt_wa(tx_ring, | |
5927 | tx_ring->next_to_use); | |
5928 | else | |
5929 | writel(tx_ring->next_to_use, tx_ring->tail); | |
472f31f5 | 5930 | } |
1b7719c4 | 5931 | } else { |
bc7f75fa | 5932 | dev_kfree_skb_any(skb); |
1b7719c4 AD |
5933 | tx_ring->buffer_info[first].time_stamp = 0; |
5934 | tx_ring->next_to_use = first; | |
bc7f75fa AK |
5935 | } |
5936 | ||
bc7f75fa AK |
5937 | return NETDEV_TX_OK; |
5938 | } | |
5939 | ||
5940 | /** | |
5941 | * e1000_tx_timeout - Respond to a Tx Hang | |
5942 | * @netdev: network interface device structure | |
5943 | **/ | |
5944 | static void e1000_tx_timeout(struct net_device *netdev) | |
5945 | { | |
5946 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
5947 | ||
5948 | /* Do the reset outside of interrupt context */ | |
5949 | adapter->tx_timeout_count++; | |
5950 | schedule_work(&adapter->reset_task); | |
5951 | } | |
5952 | ||
5953 | static void e1000_reset_task(struct work_struct *work) | |
5954 | { | |
5955 | struct e1000_adapter *adapter; | |
5956 | adapter = container_of(work, struct e1000_adapter, reset_task); | |
5957 | ||
e8e8f100 | 5958 | rtnl_lock(); |
615b32af | 5959 | /* don't run the task if already down */ |
e8e8f100 VL |
5960 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
5961 | rtnl_unlock(); | |
615b32af | 5962 | return; |
e8e8f100 | 5963 | } |
615b32af | 5964 | |
12d43f7d | 5965 | if (!(adapter->flags & FLAG_RESTART_NOW)) { |
affa9dfb | 5966 | e1000e_dump(adapter); |
12d43f7d | 5967 | e_err("Reset adapter unexpectedly\n"); |
affa9dfb | 5968 | } |
bc7f75fa | 5969 | e1000e_reinit_locked(adapter); |
e8e8f100 | 5970 | rtnl_unlock(); |
bc7f75fa AK |
5971 | } |
5972 | ||
5973 | /** | |
67fd4fcb | 5974 | * e1000_get_stats64 - Get System Network Statistics |
bc7f75fa | 5975 | * @netdev: network interface device structure |
67fd4fcb | 5976 | * @stats: rtnl_link_stats64 pointer |
bc7f75fa AK |
5977 | * |
5978 | * Returns the address of the device statistics structure. | |
bc7f75fa | 5979 | **/ |
bc1f4470 | 5980 | void e1000e_get_stats64(struct net_device *netdev, |
5981 | struct rtnl_link_stats64 *stats) | |
bc7f75fa | 5982 | { |
67fd4fcb JK |
5983 | struct e1000_adapter *adapter = netdev_priv(netdev); |
5984 | ||
67fd4fcb JK |
5985 | spin_lock(&adapter->stats64_lock); |
5986 | e1000e_update_stats(adapter); | |
5987 | /* Fill out the OS statistics structure */ | |
5988 | stats->rx_bytes = adapter->stats.gorc; | |
5989 | stats->rx_packets = adapter->stats.gprc; | |
5990 | stats->tx_bytes = adapter->stats.gotc; | |
5991 | stats->tx_packets = adapter->stats.gptc; | |
5992 | stats->multicast = adapter->stats.mprc; | |
5993 | stats->collisions = adapter->stats.colc; | |
5994 | ||
5995 | /* Rx Errors */ | |
5996 | ||
e921eb1a | 5997 | /* RLEC on some newer hardware can be incorrect so build |
67fd4fcb JK |
5998 | * our own version based on RUC and ROC |
5999 | */ | |
6000 | stats->rx_errors = adapter->stats.rxerrc + | |
f0ff4398 BA |
6001 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
6002 | adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr; | |
6003 | stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc; | |
67fd4fcb JK |
6004 | stats->rx_crc_errors = adapter->stats.crcerrs; |
6005 | stats->rx_frame_errors = adapter->stats.algnerrc; | |
6006 | stats->rx_missed_errors = adapter->stats.mpc; | |
6007 | ||
6008 | /* Tx Errors */ | |
f0ff4398 | 6009 | stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol; |
67fd4fcb JK |
6010 | stats->tx_aborted_errors = adapter->stats.ecol; |
6011 | stats->tx_window_errors = adapter->stats.latecol; | |
6012 | stats->tx_carrier_errors = adapter->stats.tncrs; | |
6013 | ||
6014 | /* Tx Dropped needs to be maintained elsewhere */ | |
6015 | ||
6016 | spin_unlock(&adapter->stats64_lock); | |
bc7f75fa AK |
6017 | } |
6018 | ||
6019 | /** | |
6020 | * e1000_change_mtu - Change the Maximum Transfer Unit | |
6021 | * @netdev: network interface device structure | |
6022 | * @new_mtu: new value for maximum frame size | |
6023 | * | |
6024 | * Returns 0 on success, negative on failure | |
6025 | **/ | |
6026 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) | |
6027 | { | |
6028 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
8084b86d | 6029 | int max_frame = new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; |
bc7f75fa | 6030 | |
2adc55c9 | 6031 | /* Jumbo frame support */ |
91c527a5 | 6032 | if ((new_mtu > ETH_DATA_LEN) && |
2e1706f2 BA |
6033 | !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
6034 | e_err("Jumbo Frames not supported.\n"); | |
6035 | return -EINVAL; | |
bc7f75fa AK |
6036 | } |
6037 | ||
2fbe4526 BA |
6038 | /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */ |
6039 | if ((adapter->hw.mac.type >= e1000_pch2lan) && | |
a1ce6473 BA |
6040 | !(adapter->flags2 & FLAG2_CRC_STRIPPING) && |
6041 | (new_mtu > ETH_DATA_LEN)) { | |
2fbe4526 | 6042 | e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n"); |
a1ce6473 BA |
6043 | return -EINVAL; |
6044 | } | |
6045 | ||
bc7f75fa | 6046 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
ab6973ae | 6047 | usleep_range(1000, 1100); |
610c9928 | 6048 | /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ |
318a94d6 | 6049 | adapter->max_frame_size = max_frame; |
610c9928 BA |
6050 | e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
6051 | netdev->mtu = new_mtu; | |
63eb48f1 DE |
6052 | |
6053 | pm_runtime_get_sync(netdev->dev.parent); | |
6054 | ||
bc7f75fa | 6055 | if (netif_running(netdev)) |
28002099 | 6056 | e1000e_down(adapter, true); |
bc7f75fa | 6057 | |
e921eb1a | 6058 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
bc7f75fa AK |
6059 | * means we reserve 2 more, this pushes us to allocate from the next |
6060 | * larger slab size. | |
ad68076e | 6061 | * i.e. RXBUFFER_2048 --> size-4096 slab |
97ac8cae BA |
6062 | * However with the new *_jumbo_rx* routines, jumbo receives will use |
6063 | * fragmented skbs | |
ad68076e | 6064 | */ |
bc7f75fa | 6065 | |
9926146b | 6066 | if (max_frame <= 2048) |
bc7f75fa AK |
6067 | adapter->rx_buffer_len = 2048; |
6068 | else | |
6069 | adapter->rx_buffer_len = 4096; | |
6070 | ||
6071 | /* adjust allocation if LPE protects us, and we aren't using SBP */ | |
8084b86d AD |
6072 | if (max_frame <= (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) |
6073 | adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN; | |
bc7f75fa | 6074 | |
bc7f75fa AK |
6075 | if (netif_running(netdev)) |
6076 | e1000e_up(adapter); | |
6077 | else | |
6078 | e1000e_reset(adapter); | |
6079 | ||
63eb48f1 DE |
6080 | pm_runtime_put_sync(netdev->dev.parent); |
6081 | ||
bc7f75fa AK |
6082 | clear_bit(__E1000_RESETTING, &adapter->state); |
6083 | ||
6084 | return 0; | |
6085 | } | |
6086 | ||
6087 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, | |
6088 | int cmd) | |
6089 | { | |
6090 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
6091 | struct mii_ioctl_data *data = if_mii(ifr); | |
bc7f75fa | 6092 | |
318a94d6 | 6093 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
bc7f75fa AK |
6094 | return -EOPNOTSUPP; |
6095 | ||
6096 | switch (cmd) { | |
6097 | case SIOCGMIIPHY: | |
6098 | data->phy_id = adapter->hw.phy.addr; | |
6099 | break; | |
6100 | case SIOCGMIIREG: | |
b16a002e BA |
6101 | e1000_phy_read_status(adapter); |
6102 | ||
7c25769f BA |
6103 | switch (data->reg_num & 0x1F) { |
6104 | case MII_BMCR: | |
6105 | data->val_out = adapter->phy_regs.bmcr; | |
6106 | break; | |
6107 | case MII_BMSR: | |
6108 | data->val_out = adapter->phy_regs.bmsr; | |
6109 | break; | |
6110 | case MII_PHYSID1: | |
6111 | data->val_out = (adapter->hw.phy.id >> 16); | |
6112 | break; | |
6113 | case MII_PHYSID2: | |
6114 | data->val_out = (adapter->hw.phy.id & 0xFFFF); | |
6115 | break; | |
6116 | case MII_ADVERTISE: | |
6117 | data->val_out = adapter->phy_regs.advertise; | |
6118 | break; | |
6119 | case MII_LPA: | |
6120 | data->val_out = adapter->phy_regs.lpa; | |
6121 | break; | |
6122 | case MII_EXPANSION: | |
6123 | data->val_out = adapter->phy_regs.expansion; | |
6124 | break; | |
6125 | case MII_CTRL1000: | |
6126 | data->val_out = adapter->phy_regs.ctrl1000; | |
6127 | break; | |
6128 | case MII_STAT1000: | |
6129 | data->val_out = adapter->phy_regs.stat1000; | |
6130 | break; | |
6131 | case MII_ESTATUS: | |
6132 | data->val_out = adapter->phy_regs.estatus; | |
6133 | break; | |
6134 | default: | |
bc7f75fa AK |
6135 | return -EIO; |
6136 | } | |
bc7f75fa AK |
6137 | break; |
6138 | case SIOCSMIIREG: | |
6139 | default: | |
6140 | return -EOPNOTSUPP; | |
6141 | } | |
6142 | return 0; | |
6143 | } | |
6144 | ||
b67e1913 BA |
6145 | /** |
6146 | * e1000e_hwtstamp_ioctl - control hardware time stamping | |
6147 | * @netdev: network interface device structure | |
6148 | * @ifreq: interface request | |
6149 | * | |
6150 | * Outgoing time stamping can be enabled and disabled. Play nice and | |
6151 | * disable it when requested, although it shouldn't cause any overhead | |
6152 | * when no packet needs it. At most one packet in the queue may be | |
6153 | * marked for time stamping, otherwise it would be impossible to tell | |
6154 | * for sure to which packet the hardware time stamp belongs. | |
6155 | * | |
6156 | * Incoming time stamping has to be configured via the hardware filters. | |
6157 | * Not all combinations are supported, in particular event type has to be | |
6158 | * specified. Matching the kind of event packet is not supported, with the | |
6159 | * exception of "all V2 events regardless of level 2 or 4". | |
6160 | **/ | |
4e8cff64 | 6161 | static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr) |
b67e1913 BA |
6162 | { |
6163 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
6164 | struct hwtstamp_config config; | |
6165 | int ret_val; | |
6166 | ||
6167 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) | |
6168 | return -EFAULT; | |
6169 | ||
62d7e3a2 | 6170 | ret_val = e1000e_config_hwtstamp(adapter, &config); |
b67e1913 BA |
6171 | if (ret_val) |
6172 | return ret_val; | |
6173 | ||
d89777bf BA |
6174 | switch (config.rx_filter) { |
6175 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: | |
6176 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: | |
6177 | case HWTSTAMP_FILTER_PTP_V2_SYNC: | |
6178 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: | |
6179 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: | |
6180 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: | |
6181 | /* With V2 type filters which specify a Sync or Delay Request, | |
6182 | * Path Delay Request/Response messages are also time stamped | |
6183 | * by hardware so notify the caller the requested packets plus | |
6184 | * some others are time stamped. | |
6185 | */ | |
6186 | config.rx_filter = HWTSTAMP_FILTER_SOME; | |
6187 | break; | |
6188 | default: | |
6189 | break; | |
6190 | } | |
6191 | ||
b67e1913 BA |
6192 | return copy_to_user(ifr->ifr_data, &config, |
6193 | sizeof(config)) ? -EFAULT : 0; | |
6194 | } | |
6195 | ||
4e8cff64 BH |
6196 | static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr) |
6197 | { | |
6198 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
6199 | ||
6200 | return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config, | |
6201 | sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0; | |
6202 | } | |
6203 | ||
bc7f75fa AK |
6204 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
6205 | { | |
6206 | switch (cmd) { | |
6207 | case SIOCGMIIPHY: | |
6208 | case SIOCGMIIREG: | |
6209 | case SIOCSMIIREG: | |
6210 | return e1000_mii_ioctl(netdev, ifr, cmd); | |
b67e1913 | 6211 | case SIOCSHWTSTAMP: |
4e8cff64 BH |
6212 | return e1000e_hwtstamp_set(netdev, ifr); |
6213 | case SIOCGHWTSTAMP: | |
6214 | return e1000e_hwtstamp_get(netdev, ifr); | |
bc7f75fa AK |
6215 | default: |
6216 | return -EOPNOTSUPP; | |
6217 | } | |
6218 | } | |
6219 | ||
a4f58f54 BA |
6220 | static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) |
6221 | { | |
6222 | struct e1000_hw *hw = &adapter->hw; | |
74f350ee | 6223 | u32 i, mac_reg, wuc; |
2b6b168d | 6224 | u16 phy_reg, wuc_enable; |
70806a7f | 6225 | int retval; |
a4f58f54 BA |
6226 | |
6227 | /* copy MAC RARs to PHY RARs */ | |
d3738bb8 | 6228 | e1000_copy_rx_addrs_to_phy_ich8lan(hw); |
a4f58f54 | 6229 | |
2b6b168d BA |
6230 | retval = hw->phy.ops.acquire(hw); |
6231 | if (retval) { | |
6232 | e_err("Could not acquire PHY\n"); | |
6233 | return retval; | |
6234 | } | |
6235 | ||
6236 | /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */ | |
6237 | retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable); | |
6238 | if (retval) | |
75ce1532 | 6239 | goto release; |
2b6b168d BA |
6240 | |
6241 | /* copy MAC MTA to PHY MTA - only needed for pchlan */ | |
a4f58f54 BA |
6242 | for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { |
6243 | mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); | |
2b6b168d BA |
6244 | hw->phy.ops.write_reg_page(hw, BM_MTA(i), |
6245 | (u16)(mac_reg & 0xFFFF)); | |
6246 | hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1, | |
6247 | (u16)((mac_reg >> 16) & 0xFFFF)); | |
a4f58f54 BA |
6248 | } |
6249 | ||
6250 | /* configure PHY Rx Control register */ | |
2b6b168d | 6251 | hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg); |
a4f58f54 BA |
6252 | mac_reg = er32(RCTL); |
6253 | if (mac_reg & E1000_RCTL_UPE) | |
6254 | phy_reg |= BM_RCTL_UPE; | |
6255 | if (mac_reg & E1000_RCTL_MPE) | |
6256 | phy_reg |= BM_RCTL_MPE; | |
6257 | phy_reg &= ~(BM_RCTL_MO_MASK); | |
6258 | if (mac_reg & E1000_RCTL_MO_3) | |
6259 | phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) | |
17e813ec | 6260 | << BM_RCTL_MO_SHIFT); |
a4f58f54 BA |
6261 | if (mac_reg & E1000_RCTL_BAM) |
6262 | phy_reg |= BM_RCTL_BAM; | |
6263 | if (mac_reg & E1000_RCTL_PMCF) | |
6264 | phy_reg |= BM_RCTL_PMCF; | |
6265 | mac_reg = er32(CTRL); | |
6266 | if (mac_reg & E1000_CTRL_RFCE) | |
6267 | phy_reg |= BM_RCTL_RFCE; | |
2b6b168d | 6268 | hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg); |
a4f58f54 | 6269 | |
74f350ee DE |
6270 | wuc = E1000_WUC_PME_EN; |
6271 | if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC)) | |
6272 | wuc |= E1000_WUC_APME; | |
6273 | ||
a4f58f54 BA |
6274 | /* enable PHY wakeup in MAC register */ |
6275 | ew32(WUFC, wufc); | |
74f350ee DE |
6276 | ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME | |
6277 | E1000_WUC_PME_STATUS | wuc)); | |
a4f58f54 BA |
6278 | |
6279 | /* configure and enable PHY wakeup in PHY registers */ | |
2b6b168d | 6280 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc); |
74f350ee | 6281 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc); |
a4f58f54 BA |
6282 | |
6283 | /* activate PHY wakeup */ | |
2b6b168d BA |
6284 | wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; |
6285 | retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable); | |
a4f58f54 BA |
6286 | if (retval) |
6287 | e_err("Could not set PHY Host Wakeup bit\n"); | |
75ce1532 | 6288 | release: |
94d8186a | 6289 | hw->phy.ops.release(hw); |
a4f58f54 BA |
6290 | |
6291 | return retval; | |
6292 | } | |
6293 | ||
2a7e19af DE |
6294 | static void e1000e_flush_lpic(struct pci_dev *pdev) |
6295 | { | |
6296 | struct net_device *netdev = pci_get_drvdata(pdev); | |
6297 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
6298 | struct e1000_hw *hw = &adapter->hw; | |
6299 | u32 ret_val; | |
6300 | ||
6301 | pm_runtime_get_sync(netdev->dev.parent); | |
6302 | ||
6303 | ret_val = hw->phy.ops.acquire(hw); | |
6304 | if (ret_val) | |
6305 | goto fl_out; | |
6306 | ||
6307 | pr_info("EEE TX LPI TIMER: %08X\n", | |
6308 | er32(LPIC) >> E1000_LPIC_LPIET_SHIFT); | |
6309 | ||
6310 | hw->phy.ops.release(hw); | |
6311 | ||
6312 | fl_out: | |
6313 | pm_runtime_put_sync(netdev->dev.parent); | |
6314 | } | |
6315 | ||
76bd88da SN |
6316 | /* S0ix implementation */ |
6317 | static void e1000e_s0ix_entry_flow(struct e1000_adapter *adapter) | |
6318 | { | |
6319 | struct e1000_hw *hw = &adapter->hw; | |
6320 | u32 mac_data; | |
6321 | u16 phy_data; | |
6322 | ||
6323 | /* Disable the periodic inband message, | |
6324 | * don't request PCIe clock in K1 page770_17[10:9] = 10b | |
6325 | */ | |
6326 | e1e_rphy(hw, HV_PM_CTRL, &phy_data); | |
6327 | phy_data &= ~HV_PM_CTRL_K1_CLK_REQ; | |
6328 | phy_data |= BIT(10); | |
6329 | e1e_wphy(hw, HV_PM_CTRL, phy_data); | |
6330 | ||
6331 | /* Make sure we don't exit K1 every time a new packet arrives | |
6332 | * 772_29[5] = 1 CS_Mode_Stay_In_K1 | |
6333 | */ | |
6334 | e1e_rphy(hw, I217_CGFREG, &phy_data); | |
6335 | phy_data |= BIT(5); | |
6336 | e1e_wphy(hw, I217_CGFREG, phy_data); | |
6337 | ||
6338 | /* Change the MAC/PHY interface to SMBus | |
6339 | * Force the SMBus in PHY page769_23[0] = 1 | |
6340 | * Force the SMBus in MAC CTRL_EXT[11] = 1 | |
6341 | */ | |
6342 | e1e_rphy(hw, CV_SMB_CTRL, &phy_data); | |
6343 | phy_data |= CV_SMB_CTRL_FORCE_SMBUS; | |
6344 | e1e_wphy(hw, CV_SMB_CTRL, phy_data); | |
6345 | mac_data = er32(CTRL_EXT); | |
6346 | mac_data |= E1000_CTRL_EXT_FORCE_SMBUS; | |
6347 | ew32(CTRL_EXT, mac_data); | |
6348 | ||
6349 | /* DFT control: PHY bit: page769_20[0] = 1 | |
6350 | * Gate PPW via EXTCNF_CTRL - set 0x0F00[7] = 1 | |
6351 | */ | |
6352 | e1e_rphy(hw, I82579_DFT_CTRL, &phy_data); | |
6353 | phy_data |= BIT(0); | |
6354 | e1e_wphy(hw, I82579_DFT_CTRL, phy_data); | |
6355 | ||
6356 | mac_data = er32(EXTCNF_CTRL); | |
6357 | mac_data |= E1000_EXTCNF_CTRL_GATE_PHY_CFG; | |
6358 | ew32(EXTCNF_CTRL, mac_data); | |
6359 | ||
6360 | /* Check MAC Tx/Rx packet buffer pointers. | |
6361 | * Reset MAC Tx/Rx packet buffer pointers to suppress any | |
6362 | * pending traffic indication that would prevent power gating. | |
6363 | */ | |
6364 | mac_data = er32(TDFH); | |
6365 | if (mac_data) | |
6366 | ew32(TDFH, 0); | |
6367 | mac_data = er32(TDFT); | |
6368 | if (mac_data) | |
6369 | ew32(TDFT, 0); | |
6370 | mac_data = er32(TDFHS); | |
6371 | if (mac_data) | |
6372 | ew32(TDFHS, 0); | |
6373 | mac_data = er32(TDFTS); | |
6374 | if (mac_data) | |
6375 | ew32(TDFTS, 0); | |
6376 | mac_data = er32(TDFPC); | |
6377 | if (mac_data) | |
6378 | ew32(TDFPC, 0); | |
6379 | mac_data = er32(RDFH); | |
6380 | if (mac_data) | |
6381 | ew32(RDFH, 0); | |
6382 | mac_data = er32(RDFT); | |
6383 | if (mac_data) | |
6384 | ew32(RDFT, 0); | |
6385 | mac_data = er32(RDFHS); | |
6386 | if (mac_data) | |
6387 | ew32(RDFHS, 0); | |
6388 | mac_data = er32(RDFTS); | |
6389 | if (mac_data) | |
6390 | ew32(RDFTS, 0); | |
6391 | mac_data = er32(RDFPC); | |
6392 | if (mac_data) | |
6393 | ew32(RDFPC, 0); | |
6394 | ||
6395 | /* Enable the Dynamic Power Gating in the MAC */ | |
6396 | mac_data = er32(FEXTNVM7); | |
6397 | mac_data |= BIT(22); | |
6398 | ew32(FEXTNVM7, mac_data); | |
6399 | ||
6400 | /* Disable the time synchronization clock */ | |
6401 | mac_data = er32(FEXTNVM7); | |
6402 | mac_data |= BIT(31); | |
6403 | mac_data &= ~BIT(0); | |
6404 | ew32(FEXTNVM7, mac_data); | |
6405 | ||
6406 | /* Dynamic Power Gating Enable */ | |
6407 | mac_data = er32(CTRL_EXT); | |
6408 | mac_data |= BIT(3); | |
6409 | ew32(CTRL_EXT, mac_data); | |
6410 | ||
6411 | /* Enable the Dynamic Clock Gating in the DMA and MAC */ | |
6412 | mac_data = er32(CTRL_EXT); | |
6413 | mac_data |= E1000_CTRL_EXT_DMA_DYN_CLK_EN; | |
6414 | ew32(CTRL_EXT, mac_data); | |
6415 | ||
6416 | /* No MAC DPG gating SLP_S0 in modern standby | |
6417 | * Switch the logic of the lanphypc to use PMC counter | |
6418 | */ | |
6419 | mac_data = er32(FEXTNVM5); | |
6420 | mac_data |= BIT(7); | |
6421 | ew32(FEXTNVM5, mac_data); | |
6422 | } | |
6423 | ||
6424 | static void e1000e_s0ix_exit_flow(struct e1000_adapter *adapter) | |
6425 | { | |
6426 | struct e1000_hw *hw = &adapter->hw; | |
6427 | u32 mac_data; | |
6428 | u16 phy_data; | |
6429 | ||
6430 | /* Disable the Dynamic Power Gating in the MAC */ | |
6431 | mac_data = er32(FEXTNVM7); | |
6432 | mac_data &= 0xFFBFFFFF; | |
6433 | ew32(FEXTNVM7, mac_data); | |
6434 | ||
6435 | /* Enable the time synchronization clock */ | |
6436 | mac_data = er32(FEXTNVM7); | |
6437 | mac_data |= BIT(0); | |
6438 | ew32(FEXTNVM7, mac_data); | |
6439 | ||
6440 | /* Disable Dynamic Power Gating */ | |
6441 | mac_data = er32(CTRL_EXT); | |
6442 | mac_data &= 0xFFFFFFF7; | |
6443 | ew32(CTRL_EXT, mac_data); | |
6444 | ||
6445 | /* Disable the Dynamic Clock Gating in the DMA and MAC */ | |
6446 | mac_data = er32(CTRL_EXT); | |
6447 | mac_data &= 0xFFF7FFFF; | |
6448 | ew32(CTRL_EXT, mac_data); | |
6449 | ||
6450 | /* Revert the lanphypc logic to use the internal Gbe counter | |
6451 | * and not the PMC counter | |
6452 | */ | |
6453 | mac_data = er32(FEXTNVM5); | |
6454 | mac_data &= 0xFFFFFF7F; | |
6455 | ew32(FEXTNVM5, mac_data); | |
6456 | ||
6457 | /* Enable the periodic inband message, | |
6458 | * Request PCIe clock in K1 page770_17[10:9] =01b | |
6459 | */ | |
6460 | e1e_rphy(hw, HV_PM_CTRL, &phy_data); | |
6461 | phy_data &= 0xFBFF; | |
6462 | phy_data |= HV_PM_CTRL_K1_CLK_REQ; | |
6463 | e1e_wphy(hw, HV_PM_CTRL, phy_data); | |
6464 | ||
6465 | /* Return back configuration | |
6466 | * 772_29[5] = 0 CS_Mode_Stay_In_K1 | |
6467 | */ | |
6468 | e1e_rphy(hw, I217_CGFREG, &phy_data); | |
6469 | phy_data &= 0xFFDF; | |
6470 | e1e_wphy(hw, I217_CGFREG, phy_data); | |
6471 | ||
6472 | /* Change the MAC/PHY interface to Kumeran | |
6473 | * Unforce the SMBus in PHY page769_23[0] = 0 | |
6474 | * Unforce the SMBus in MAC CTRL_EXT[11] = 0 | |
6475 | */ | |
6476 | e1e_rphy(hw, CV_SMB_CTRL, &phy_data); | |
6477 | phy_data &= ~CV_SMB_CTRL_FORCE_SMBUS; | |
6478 | e1e_wphy(hw, CV_SMB_CTRL, phy_data); | |
6479 | mac_data = er32(CTRL_EXT); | |
6480 | mac_data &= ~E1000_CTRL_EXT_FORCE_SMBUS; | |
6481 | ew32(CTRL_EXT, mac_data); | |
6482 | } | |
6483 | ||
28002099 | 6484 | static int e1000e_pm_freeze(struct device *dev) |
bc7f75fa | 6485 | { |
ee2e80c1 | 6486 | struct net_device *netdev = dev_get_drvdata(dev); |
bc7f75fa | 6487 | struct e1000_adapter *adapter = netdev_priv(netdev); |
94d0b5b5 | 6488 | bool present; |
bc7f75fa | 6489 | |
94d0b5b5 AD |
6490 | rtnl_lock(); |
6491 | ||
6492 | present = netif_device_present(netdev); | |
bc7f75fa AK |
6493 | netif_device_detach(netdev); |
6494 | ||
94d0b5b5 | 6495 | if (present && netif_running(netdev)) { |
bb9e44d0 BA |
6496 | int count = E1000_CHECK_RESET_COUNT; |
6497 | ||
6498 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) | |
ab6973ae | 6499 | usleep_range(10000, 11000); |
bb9e44d0 | 6500 | |
bc7f75fa | 6501 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
28002099 DE |
6502 | |
6503 | /* Quiesce the device without resetting the hardware */ | |
6504 | e1000e_down(adapter, false); | |
bc7f75fa AK |
6505 | e1000_free_irq(adapter); |
6506 | } | |
94d0b5b5 AD |
6507 | rtnl_unlock(); |
6508 | ||
9f47a48e | 6509 | e1000e_reset_interrupt_capability(adapter); |
bc7f75fa | 6510 | |
28002099 DE |
6511 | /* Allow time for pending master requests to run */ |
6512 | e1000e_disable_pcie_master(&adapter->hw); | |
6513 | ||
6514 | return 0; | |
6515 | } | |
6516 | ||
6517 | static int __e1000_shutdown(struct pci_dev *pdev, bool runtime) | |
6518 | { | |
6519 | struct net_device *netdev = pci_get_drvdata(pdev); | |
6520 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
6521 | struct e1000_hw *hw = &adapter->hw; | |
021a1eac | 6522 | u32 ctrl, ctrl_ext, rctl, status, wufc; |
28002099 DE |
6523 | int retval = 0; |
6524 | ||
021a1eac CY |
6525 | /* Runtime suspend should only enable wakeup for link changes */ |
6526 | if (runtime) | |
6527 | wufc = E1000_WUFC_LNKC; | |
6528 | else if (device_may_wakeup(&pdev->dev)) | |
6529 | wufc = adapter->wol; | |
6530 | else | |
6531 | wufc = 0; | |
6532 | ||
bc7f75fa AK |
6533 | status = er32(STATUS); |
6534 | if (status & E1000_STATUS_LU) | |
6535 | wufc &= ~E1000_WUFC_LNKC; | |
6536 | ||
6537 | if (wufc) { | |
6538 | e1000_setup_rctl(adapter); | |
ef9b965a | 6539 | e1000e_set_rx_mode(netdev); |
bc7f75fa AK |
6540 | |
6541 | /* turn on all-multi mode if wake on multicast is enabled */ | |
6542 | if (wufc & E1000_WUFC_MC) { | |
6543 | rctl = er32(RCTL); | |
6544 | rctl |= E1000_RCTL_MPE; | |
6545 | ew32(RCTL, rctl); | |
6546 | } | |
6547 | ||
6548 | ctrl = er32(CTRL); | |
a4f58f54 BA |
6549 | ctrl |= E1000_CTRL_ADVD3WUC; |
6550 | if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) | |
6551 | ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; | |
bc7f75fa AK |
6552 | ew32(CTRL, ctrl); |
6553 | ||
318a94d6 JK |
6554 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
6555 | adapter->hw.phy.media_type == | |
6556 | e1000_media_type_internal_serdes) { | |
bc7f75fa AK |
6557 | /* keep the laser running in D3 */ |
6558 | ctrl_ext = er32(CTRL_EXT); | |
93a23f48 | 6559 | ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; |
bc7f75fa AK |
6560 | ew32(CTRL_EXT, ctrl_ext); |
6561 | } | |
6562 | ||
63eb48f1 DE |
6563 | if (!runtime) |
6564 | e1000e_power_up_phy(adapter); | |
6565 | ||
97ac8cae | 6566 | if (adapter->flags & FLAG_IS_ICH) |
99730e4c | 6567 | e1000_suspend_workarounds_ich8lan(&adapter->hw); |
97ac8cae | 6568 | |
82776a4b | 6569 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
a4f58f54 BA |
6570 | /* enable wakeup by the PHY */ |
6571 | retval = e1000_init_phy_wakeup(adapter, wufc); | |
6572 | if (retval) | |
6573 | return retval; | |
6574 | } else { | |
6575 | /* enable wakeup by the MAC */ | |
6576 | ew32(WUFC, wufc); | |
6577 | ew32(WUC, E1000_WUC_PME_EN); | |
6578 | } | |
bc7f75fa AK |
6579 | } else { |
6580 | ew32(WUC, 0); | |
6581 | ew32(WUFC, 0); | |
28002099 DE |
6582 | |
6583 | e1000_power_down_phy(adapter); | |
bc7f75fa AK |
6584 | } |
6585 | ||
74f350ee | 6586 | if (adapter->hw.phy.type == e1000_phy_igp_3) { |
bc7f75fa | 6587 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
c8744f44 | 6588 | } else if (hw->mac.type >= e1000_pch_lpt) { |
021a1eac | 6589 | if (wufc && !(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC))) |
74f350ee DE |
6590 | /* ULP does not support wake from unicast, multicast |
6591 | * or broadcast. | |
6592 | */ | |
6593 | retval = e1000_enable_ulp_lpt_lp(hw, !runtime); | |
6594 | ||
6595 | if (retval) | |
6596 | return retval; | |
6597 | } | |
6598 | ||
f5ac7445 RA |
6599 | /* Ensure that the appropriate bits are set in LPI_CTRL |
6600 | * for EEE in Sx | |
6601 | */ | |
6602 | if ((hw->phy.type >= e1000_phy_i217) && | |
6603 | adapter->eee_advert && hw->dev_spec.ich8lan.eee_lp_ability) { | |
6604 | u16 lpi_ctrl = 0; | |
6605 | ||
6606 | retval = hw->phy.ops.acquire(hw); | |
6607 | if (!retval) { | |
6608 | retval = e1e_rphy_locked(hw, I82579_LPI_CTRL, | |
6609 | &lpi_ctrl); | |
6610 | if (!retval) { | |
6611 | if (adapter->eee_advert & | |
6612 | hw->dev_spec.ich8lan.eee_lp_ability & | |
6613 | I82579_EEE_100_SUPPORTED) | |
6614 | lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE; | |
6615 | if (adapter->eee_advert & | |
6616 | hw->dev_spec.ich8lan.eee_lp_ability & | |
6617 | I82579_EEE_1000_SUPPORTED) | |
6618 | lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE; | |
6619 | ||
6620 | retval = e1e_wphy_locked(hw, I82579_LPI_CTRL, | |
6621 | lpi_ctrl); | |
6622 | } | |
6623 | } | |
6624 | hw->phy.ops.release(hw); | |
6625 | } | |
bc7f75fa | 6626 | |
e921eb1a | 6627 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
ad68076e BA |
6628 | * would have already happened in close and is redundant. |
6629 | */ | |
31dbe5b4 | 6630 | e1000e_release_hw_control(adapter); |
bc7f75fa | 6631 | |
24b41c97 DN |
6632 | pci_clear_master(pdev); |
6633 | ||
e921eb1a | 6634 | /* The pci-e switch on some quad port adapters will report a |
005cbdfc AD |
6635 | * correctable error when the MAC transitions from D0 to D3. To |
6636 | * prevent this we need to mask off the correctable errors on the | |
6637 | * downstream port of the pci-e switch. | |
e8c254c5 LZ |
6638 | * |
6639 | * We don't have the associated upstream bridge while assigning | |
6640 | * the PCI device into guest. For example, the KVM on power is | |
6641 | * one of the cases. | |
005cbdfc AD |
6642 | */ |
6643 | if (adapter->flags & FLAG_IS_QUAD_PORT) { | |
6644 | struct pci_dev *us_dev = pdev->bus->self; | |
005cbdfc AD |
6645 | u16 devctl; |
6646 | ||
e8c254c5 LZ |
6647 | if (!us_dev) |
6648 | return 0; | |
6649 | ||
f8c0fcac JL |
6650 | pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl); |
6651 | pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, | |
6652 | (devctl & ~PCI_EXP_DEVCTL_CERE)); | |
005cbdfc | 6653 | |
66148bab KK |
6654 | pci_save_state(pdev); |
6655 | pci_prepare_to_sleep(pdev); | |
005cbdfc | 6656 | |
f8c0fcac | 6657 | pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl); |
005cbdfc | 6658 | } |
66148bab KK |
6659 | |
6660 | return 0; | |
bc7f75fa AK |
6661 | } |
6662 | ||
13129d9b | 6663 | /** |
beb0a152 | 6664 | * __e1000e_disable_aspm - Disable ASPM states |
13129d9b CW |
6665 | * @pdev: pointer to PCI device struct |
6666 | * @state: bit-mask of ASPM states to disable | |
beb0a152 | 6667 | * @locked: indication if this context holds pci_bus_sem locked. |
13129d9b CW |
6668 | * |
6669 | * Some devices *must* have certain ASPM states disabled per hardware errata. | |
6670 | **/ | |
beb0a152 | 6671 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state, int locked) |
6f461f6c | 6672 | { |
13129d9b CW |
6673 | struct pci_dev *parent = pdev->bus->self; |
6674 | u16 aspm_dis_mask = 0; | |
6675 | u16 pdev_aspmc, parent_aspmc; | |
6676 | ||
6677 | switch (state) { | |
6678 | case PCIE_LINK_STATE_L0S: | |
6679 | case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1: | |
6680 | aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S; | |
6681 | /* fall-through - can't have L1 without L0s */ | |
6682 | case PCIE_LINK_STATE_L1: | |
6683 | aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1; | |
6684 | break; | |
6685 | default: | |
6686 | return; | |
6687 | } | |
6688 | ||
6689 | pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc); | |
6690 | pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC; | |
6691 | ||
6692 | if (parent) { | |
6693 | pcie_capability_read_word(parent, PCI_EXP_LNKCTL, | |
6694 | &parent_aspmc); | |
6695 | parent_aspmc &= PCI_EXP_LNKCTL_ASPMC; | |
6696 | } | |
6697 | ||
6698 | /* Nothing to do if the ASPM states to be disabled already are */ | |
6699 | if (!(pdev_aspmc & aspm_dis_mask) && | |
6700 | (!parent || !(parent_aspmc & aspm_dis_mask))) | |
6701 | return; | |
6702 | ||
6703 | dev_info(&pdev->dev, "Disabling ASPM %s %s\n", | |
6704 | (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ? | |
6705 | "L0s" : "", | |
6706 | (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ? | |
6707 | "L1" : ""); | |
6708 | ||
6709 | #ifdef CONFIG_PCIEASPM | |
beb0a152 YL |
6710 | if (locked) |
6711 | pci_disable_link_state_locked(pdev, state); | |
6712 | else | |
6713 | pci_disable_link_state(pdev, state); | |
ffe0b2ff | 6714 | |
13129d9b CW |
6715 | /* Double-check ASPM control. If not disabled by the above, the |
6716 | * BIOS is preventing that from happening (or CONFIG_PCIEASPM is | |
6717 | * not enabled); override by writing PCI config space directly. | |
6718 | */ | |
6719 | pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc); | |
6720 | pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC; | |
6721 | ||
6722 | if (!(aspm_dis_mask & pdev_aspmc)) | |
6723 | return; | |
6724 | #endif | |
ffe0b2ff | 6725 | |
e921eb1a | 6726 | /* Both device and parent should have the same ASPM setting. |
6f461f6c | 6727 | * Disable ASPM in downstream component first and then upstream. |
1eae4eb2 | 6728 | */ |
13129d9b | 6729 | pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask); |
6f461f6c | 6730 | |
13129d9b CW |
6731 | if (parent) |
6732 | pcie_capability_clear_word(parent, PCI_EXP_LNKCTL, | |
6733 | aspm_dis_mask); | |
1eae4eb2 AK |
6734 | } |
6735 | ||
beb0a152 YL |
6736 | /** |
6737 | * e1000e_disable_aspm - Disable ASPM states. | |
6738 | * @pdev: pointer to PCI device struct | |
6739 | * @state: bit-mask of ASPM states to disable | |
6740 | * | |
6741 | * This function acquires the pci_bus_sem! | |
6742 | * Some devices *must* have certain ASPM states disabled per hardware errata. | |
6743 | **/ | |
6744 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) | |
6745 | { | |
6746 | __e1000e_disable_aspm(pdev, state, 0); | |
6747 | } | |
6748 | ||
6749 | /** | |
6750 | * e1000e_disable_aspm_locked Disable ASPM states. | |
6751 | * @pdev: pointer to PCI device struct | |
6752 | * @state: bit-mask of ASPM states to disable | |
6753 | * | |
6754 | * This function must be called with pci_bus_sem acquired! | |
6755 | * Some devices *must* have certain ASPM states disabled per hardware errata. | |
6756 | **/ | |
6757 | static void e1000e_disable_aspm_locked(struct pci_dev *pdev, u16 state) | |
6758 | { | |
6759 | __e1000e_disable_aspm(pdev, state, 1); | |
6760 | } | |
6761 | ||
94d0b5b5 AD |
6762 | static int e1000e_pm_thaw(struct device *dev) |
6763 | { | |
6764 | struct net_device *netdev = dev_get_drvdata(dev); | |
6765 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
6766 | int rc = 0; | |
6767 | ||
6768 | e1000e_set_interrupt_capability(adapter); | |
6769 | ||
6770 | rtnl_lock(); | |
6771 | if (netif_running(netdev)) { | |
6772 | rc = e1000_request_irq(adapter); | |
6773 | if (rc) | |
6774 | goto err_irq; | |
6775 | ||
6776 | e1000e_up(adapter); | |
6777 | } | |
6778 | ||
6779 | netif_device_attach(netdev); | |
6780 | err_irq: | |
6781 | rtnl_unlock(); | |
6782 | ||
6783 | return rc; | |
6784 | } | |
6785 | ||
aa338601 | 6786 | #ifdef CONFIG_PM |
23606cf5 | 6787 | static int __e1000_resume(struct pci_dev *pdev) |
bc7f75fa AK |
6788 | { |
6789 | struct net_device *netdev = pci_get_drvdata(pdev); | |
6790 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
6791 | struct e1000_hw *hw = &adapter->hw; | |
78cd29d5 | 6792 | u16 aspm_disable_flag = 0; |
bc7f75fa | 6793 | |
78cd29d5 BA |
6794 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
6795 | aspm_disable_flag = PCIE_LINK_STATE_L0S; | |
6796 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) | |
6797 | aspm_disable_flag |= PCIE_LINK_STATE_L1; | |
6798 | if (aspm_disable_flag) | |
2758f9ed | 6799 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
78cd29d5 | 6800 | |
66148bab | 6801 | pci_set_master(pdev); |
6e4f6f6b | 6802 | |
2fbe4526 | 6803 | if (hw->mac.type >= e1000_pch2lan) |
99730e4c BA |
6804 | e1000_resume_workarounds_pchlan(&adapter->hw); |
6805 | ||
bc7f75fa | 6806 | e1000e_power_up_phy(adapter); |
a4f58f54 BA |
6807 | |
6808 | /* report the system wakeup cause from S3/S4 */ | |
6809 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { | |
6810 | u16 phy_data; | |
6811 | ||
6812 | e1e_rphy(&adapter->hw, BM_WUS, &phy_data); | |
6813 | if (phy_data) { | |
6814 | e_info("PHY Wakeup cause - %s\n", | |
17e813ec BA |
6815 | phy_data & E1000_WUS_EX ? "Unicast Packet" : |
6816 | phy_data & E1000_WUS_MC ? "Multicast Packet" : | |
6817 | phy_data & E1000_WUS_BC ? "Broadcast Packet" : | |
6818 | phy_data & E1000_WUS_MAG ? "Magic Packet" : | |
6819 | phy_data & E1000_WUS_LNKC ? | |
6820 | "Link Status Change" : "other"); | |
a4f58f54 BA |
6821 | } |
6822 | e1e_wphy(&adapter->hw, BM_WUS, ~0); | |
6823 | } else { | |
6824 | u32 wus = er32(WUS); | |
6cf08d1c | 6825 | |
a4f58f54 BA |
6826 | if (wus) { |
6827 | e_info("MAC Wakeup cause - %s\n", | |
17e813ec BA |
6828 | wus & E1000_WUS_EX ? "Unicast Packet" : |
6829 | wus & E1000_WUS_MC ? "Multicast Packet" : | |
6830 | wus & E1000_WUS_BC ? "Broadcast Packet" : | |
6831 | wus & E1000_WUS_MAG ? "Magic Packet" : | |
6832 | wus & E1000_WUS_LNKC ? "Link Status Change" : | |
6833 | "other"); | |
a4f58f54 BA |
6834 | } |
6835 | ew32(WUS, ~0); | |
6836 | } | |
6837 | ||
bc7f75fa | 6838 | e1000e_reset(adapter); |
bc7f75fa | 6839 | |
cd791618 | 6840 | e1000_init_manageability_pt(adapter); |
bc7f75fa | 6841 | |
e921eb1a | 6842 | /* If the controller has AMT, do not set DRV_LOAD until the interface |
bc7f75fa | 6843 | * is up. For all other cases, let the f/w know that the h/w is now |
ad68076e BA |
6844 | * under the control of the driver. |
6845 | */ | |
c43bc57e | 6846 | if (!(adapter->flags & FLAG_HAS_AMT)) |
31dbe5b4 | 6847 | e1000e_get_hw_control(adapter); |
bc7f75fa AK |
6848 | |
6849 | return 0; | |
6850 | } | |
23606cf5 | 6851 | |
3e7986f6 | 6852 | #ifdef CONFIG_PM_SLEEP |
28002099 | 6853 | static int e1000e_pm_suspend(struct device *dev) |
a0340162 | 6854 | { |
76bd88da SN |
6855 | struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev)); |
6856 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
a0340162 | 6857 | struct pci_dev *pdev = to_pci_dev(dev); |
76bd88da | 6858 | struct e1000_hw *hw = &adapter->hw; |
833521eb | 6859 | int rc; |
a0340162 | 6860 | |
2a7e19af DE |
6861 | e1000e_flush_lpic(pdev); |
6862 | ||
28002099 DE |
6863 | e1000e_pm_freeze(dev); |
6864 | ||
833521eb CW |
6865 | rc = __e1000_shutdown(pdev, false); |
6866 | if (rc) | |
6867 | e1000e_pm_thaw(dev); | |
6868 | ||
76bd88da | 6869 | /* Introduce S0ix implementation */ |
7bb734ad | 6870 | if (hw->mac.type >= e1000_pch_cnp) |
76bd88da SN |
6871 | e1000e_s0ix_entry_flow(adapter); |
6872 | ||
833521eb | 6873 | return rc; |
a0340162 RW |
6874 | } |
6875 | ||
28002099 | 6876 | static int e1000e_pm_resume(struct device *dev) |
23606cf5 | 6877 | { |
76bd88da SN |
6878 | struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev)); |
6879 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
23606cf5 | 6880 | struct pci_dev *pdev = to_pci_dev(dev); |
76bd88da | 6881 | struct e1000_hw *hw = &adapter->hw; |
28002099 | 6882 | int rc; |
23606cf5 | 6883 | |
76bd88da | 6884 | /* Introduce S0ix implementation */ |
7bb734ad | 6885 | if (hw->mac.type >= e1000_pch_cnp) |
76bd88da SN |
6886 | e1000e_s0ix_exit_flow(adapter); |
6887 | ||
28002099 DE |
6888 | rc = __e1000_resume(pdev); |
6889 | if (rc) | |
6890 | return rc; | |
23606cf5 | 6891 | |
28002099 | 6892 | return e1000e_pm_thaw(dev); |
23606cf5 | 6893 | } |
38a529b5 | 6894 | #endif /* CONFIG_PM_SLEEP */ |
a0340162 | 6895 | |
63eb48f1 | 6896 | static int e1000e_pm_runtime_idle(struct device *dev) |
a0340162 | 6897 | { |
ee2e80c1 | 6898 | struct net_device *netdev = dev_get_drvdata(dev); |
a0340162 | 6899 | struct e1000_adapter *adapter = netdev_priv(netdev); |
2116bc25 | 6900 | u16 eee_lp; |
a0340162 | 6901 | |
2116bc25 DE |
6902 | eee_lp = adapter->hw.dev_spec.ich8lan.eee_lp_ability; |
6903 | ||
6904 | if (!e1000e_has_link(adapter)) { | |
6905 | adapter->hw.dev_spec.ich8lan.eee_lp_ability = eee_lp; | |
63eb48f1 | 6906 | pm_schedule_suspend(dev, 5 * MSEC_PER_SEC); |
2116bc25 | 6907 | } |
a0340162 | 6908 | |
63eb48f1 | 6909 | return -EBUSY; |
a0340162 RW |
6910 | } |
6911 | ||
63eb48f1 | 6912 | static int e1000e_pm_runtime_resume(struct device *dev) |
a0340162 RW |
6913 | { |
6914 | struct pci_dev *pdev = to_pci_dev(dev); | |
6915 | struct net_device *netdev = pci_get_drvdata(pdev); | |
6916 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
63eb48f1 | 6917 | int rc; |
a0340162 | 6918 | |
63eb48f1 DE |
6919 | rc = __e1000_resume(pdev); |
6920 | if (rc) | |
6921 | return rc; | |
a0340162 | 6922 | |
63eb48f1 | 6923 | if (netdev->flags & IFF_UP) |
386164d9 | 6924 | e1000e_up(adapter); |
a0340162 | 6925 | |
63eb48f1 | 6926 | return rc; |
a0340162 | 6927 | } |
23606cf5 | 6928 | |
63eb48f1 | 6929 | static int e1000e_pm_runtime_suspend(struct device *dev) |
23606cf5 RW |
6930 | { |
6931 | struct pci_dev *pdev = to_pci_dev(dev); | |
6932 | struct net_device *netdev = pci_get_drvdata(pdev); | |
6933 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
6934 | ||
63eb48f1 DE |
6935 | if (netdev->flags & IFF_UP) { |
6936 | int count = E1000_CHECK_RESET_COUNT; | |
6937 | ||
6938 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) | |
ab6973ae | 6939 | usleep_range(10000, 11000); |
23606cf5 | 6940 | |
63eb48f1 DE |
6941 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
6942 | ||
6943 | /* Down the device without resetting the hardware */ | |
6944 | e1000e_down(adapter, false); | |
6945 | } | |
6946 | ||
6947 | if (__e1000_shutdown(pdev, true)) { | |
6948 | e1000e_pm_runtime_resume(dev); | |
6949 | return -EBUSY; | |
6950 | } | |
6951 | ||
6952 | return 0; | |
23606cf5 | 6953 | } |
aa338601 | 6954 | #endif /* CONFIG_PM */ |
bc7f75fa AK |
6955 | |
6956 | static void e1000_shutdown(struct pci_dev *pdev) | |
6957 | { | |
2a7e19af DE |
6958 | e1000e_flush_lpic(pdev); |
6959 | ||
28002099 DE |
6960 | e1000e_pm_freeze(&pdev->dev); |
6961 | ||
66148bab | 6962 | __e1000_shutdown(pdev, false); |
bc7f75fa AK |
6963 | } |
6964 | ||
6965 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
147b2c8c | 6966 | |
8bb62869 | 6967 | static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data) |
147b2c8c DD |
6968 | { |
6969 | struct net_device *netdev = data; | |
6970 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
147b2c8c DD |
6971 | |
6972 | if (adapter->msix_entries) { | |
90da0669 BA |
6973 | int vector, msix_irq; |
6974 | ||
147b2c8c DD |
6975 | vector = 0; |
6976 | msix_irq = adapter->msix_entries[vector].vector; | |
fd8e597b KK |
6977 | if (disable_hardirq(msix_irq)) |
6978 | e1000_intr_msix_rx(msix_irq, netdev); | |
147b2c8c DD |
6979 | enable_irq(msix_irq); |
6980 | ||
6981 | vector++; | |
6982 | msix_irq = adapter->msix_entries[vector].vector; | |
fd8e597b KK |
6983 | if (disable_hardirq(msix_irq)) |
6984 | e1000_intr_msix_tx(msix_irq, netdev); | |
147b2c8c DD |
6985 | enable_irq(msix_irq); |
6986 | ||
6987 | vector++; | |
6988 | msix_irq = adapter->msix_entries[vector].vector; | |
fd8e597b KK |
6989 | if (disable_hardirq(msix_irq)) |
6990 | e1000_msix_other(msix_irq, netdev); | |
147b2c8c DD |
6991 | enable_irq(msix_irq); |
6992 | } | |
6993 | ||
6994 | return IRQ_HANDLED; | |
6995 | } | |
6996 | ||
e921eb1a BA |
6997 | /** |
6998 | * e1000_netpoll | |
6999 | * @netdev: network interface device structure | |
7000 | * | |
bc7f75fa AK |
7001 | * Polling 'interrupt' - used by things like netconsole to send skbs |
7002 | * without having to re-enable interrupts. It's not called while | |
7003 | * the interrupt routine is executing. | |
7004 | */ | |
7005 | static void e1000_netpoll(struct net_device *netdev) | |
7006 | { | |
7007 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
7008 | ||
147b2c8c DD |
7009 | switch (adapter->int_mode) { |
7010 | case E1000E_INT_MODE_MSIX: | |
7011 | e1000_intr_msix(adapter->pdev->irq, netdev); | |
7012 | break; | |
7013 | case E1000E_INT_MODE_MSI: | |
31119129 WC |
7014 | if (disable_hardirq(adapter->pdev->irq)) |
7015 | e1000_intr_msi(adapter->pdev->irq, netdev); | |
147b2c8c DD |
7016 | enable_irq(adapter->pdev->irq); |
7017 | break; | |
e80bd1d1 | 7018 | default: /* E1000E_INT_MODE_LEGACY */ |
31119129 WC |
7019 | if (disable_hardirq(adapter->pdev->irq)) |
7020 | e1000_intr(adapter->pdev->irq, netdev); | |
147b2c8c DD |
7021 | enable_irq(adapter->pdev->irq); |
7022 | break; | |
7023 | } | |
bc7f75fa AK |
7024 | } |
7025 | #endif | |
7026 | ||
7027 | /** | |
7028 | * e1000_io_error_detected - called when PCI error is detected | |
7029 | * @pdev: Pointer to PCI device | |
7030 | * @state: The current pci connection state | |
7031 | * | |
7032 | * This function is called after a PCI bus error affecting | |
7033 | * this device has been detected. | |
7034 | */ | |
7035 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, | |
7036 | pci_channel_state_t state) | |
7037 | { | |
94d0b5b5 | 7038 | e1000e_pm_freeze(&pdev->dev); |
bc7f75fa | 7039 | |
c93b5a76 MM |
7040 | if (state == pci_channel_io_perm_failure) |
7041 | return PCI_ERS_RESULT_DISCONNECT; | |
7042 | ||
bc7f75fa AK |
7043 | pci_disable_device(pdev); |
7044 | ||
7045 | /* Request a slot slot reset. */ | |
7046 | return PCI_ERS_RESULT_NEED_RESET; | |
7047 | } | |
7048 | ||
7049 | /** | |
7050 | * e1000_io_slot_reset - called after the pci bus has been reset. | |
7051 | * @pdev: Pointer to PCI device | |
7052 | * | |
7053 | * Restart the card from scratch, as if from a cold-boot. Implementation | |
28002099 | 7054 | * resembles the first-half of the e1000e_pm_resume routine. |
bc7f75fa AK |
7055 | */ |
7056 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) | |
7057 | { | |
7058 | struct net_device *netdev = pci_get_drvdata(pdev); | |
7059 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
7060 | struct e1000_hw *hw = &adapter->hw; | |
78cd29d5 | 7061 | u16 aspm_disable_flag = 0; |
6e4f6f6b | 7062 | int err; |
111b9dc5 | 7063 | pci_ers_result_t result; |
bc7f75fa | 7064 | |
78cd29d5 BA |
7065 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
7066 | aspm_disable_flag = PCIE_LINK_STATE_L0S; | |
6f461f6c | 7067 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
78cd29d5 BA |
7068 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
7069 | if (aspm_disable_flag) | |
2758f9ed | 7070 | e1000e_disable_aspm_locked(pdev, aspm_disable_flag); |
78cd29d5 | 7071 | |
f0f422e5 | 7072 | err = pci_enable_device_mem(pdev); |
6e4f6f6b | 7073 | if (err) { |
bc7f75fa AK |
7074 | dev_err(&pdev->dev, |
7075 | "Cannot re-enable PCI device after reset.\n"); | |
111b9dc5 JB |
7076 | result = PCI_ERS_RESULT_DISCONNECT; |
7077 | } else { | |
23606cf5 | 7078 | pdev->state_saved = true; |
111b9dc5 | 7079 | pci_restore_state(pdev); |
66148bab | 7080 | pci_set_master(pdev); |
bc7f75fa | 7081 | |
111b9dc5 JB |
7082 | pci_enable_wake(pdev, PCI_D3hot, 0); |
7083 | pci_enable_wake(pdev, PCI_D3cold, 0); | |
bc7f75fa | 7084 | |
111b9dc5 JB |
7085 | e1000e_reset(adapter); |
7086 | ew32(WUS, ~0); | |
7087 | result = PCI_ERS_RESULT_RECOVERED; | |
7088 | } | |
bc7f75fa | 7089 | |
111b9dc5 | 7090 | return result; |
bc7f75fa AK |
7091 | } |
7092 | ||
7093 | /** | |
7094 | * e1000_io_resume - called when traffic can start flowing again. | |
7095 | * @pdev: Pointer to PCI device | |
7096 | * | |
7097 | * This callback is called when the error recovery driver tells us that | |
7098 | * its OK to resume normal operation. Implementation resembles the | |
28002099 | 7099 | * second-half of the e1000e_pm_resume routine. |
bc7f75fa AK |
7100 | */ |
7101 | static void e1000_io_resume(struct pci_dev *pdev) | |
7102 | { | |
7103 | struct net_device *netdev = pci_get_drvdata(pdev); | |
7104 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
7105 | ||
cd791618 | 7106 | e1000_init_manageability_pt(adapter); |
bc7f75fa | 7107 | |
94d0b5b5 | 7108 | e1000e_pm_thaw(&pdev->dev); |
bc7f75fa | 7109 | |
e921eb1a | 7110 | /* If the controller has AMT, do not set DRV_LOAD until the interface |
bc7f75fa | 7111 | * is up. For all other cases, let the f/w know that the h/w is now |
ad68076e BA |
7112 | * under the control of the driver. |
7113 | */ | |
c43bc57e | 7114 | if (!(adapter->flags & FLAG_HAS_AMT)) |
31dbe5b4 | 7115 | e1000e_get_hw_control(adapter); |
bc7f75fa AK |
7116 | } |
7117 | ||
7118 | static void e1000_print_device_info(struct e1000_adapter *adapter) | |
7119 | { | |
7120 | struct e1000_hw *hw = &adapter->hw; | |
7121 | struct net_device *netdev = adapter->netdev; | |
073287c0 BA |
7122 | u32 ret_val; |
7123 | u8 pba_str[E1000_PBANUM_LENGTH]; | |
bc7f75fa AK |
7124 | |
7125 | /* print bus type/speed/width info */ | |
a5cc7642 | 7126 | e_info("(PCI Express:2.5GT/s:%s) %pM\n", |
44defeb3 JK |
7127 | /* bus width */ |
7128 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : | |
f0ff4398 | 7129 | "Width x1"), |
44defeb3 | 7130 | /* MAC address */ |
7c510e4b | 7131 | netdev->dev_addr); |
44defeb3 JK |
7132 | e_info("Intel(R) PRO/%s Network Connection\n", |
7133 | (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); | |
073287c0 BA |
7134 | ret_val = e1000_read_pba_string_generic(hw, pba_str, |
7135 | E1000_PBANUM_LENGTH); | |
7136 | if (ret_val) | |
f2315bf1 | 7137 | strlcpy((char *)pba_str, "Unknown", sizeof(pba_str)); |
073287c0 BA |
7138 | e_info("MAC: %d, PHY: %d, PBA No: %s\n", |
7139 | hw->mac.type, hw->phy.type, pba_str); | |
bc7f75fa AK |
7140 | } |
7141 | ||
10aa4c04 AK |
7142 | static void e1000_eeprom_checks(struct e1000_adapter *adapter) |
7143 | { | |
7144 | struct e1000_hw *hw = &adapter->hw; | |
7145 | int ret_val; | |
7146 | u16 buf = 0; | |
7147 | ||
7148 | if (hw->mac.type != e1000_82573) | |
7149 | return; | |
7150 | ||
7151 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); | |
e885d762 | 7152 | le16_to_cpus(&buf); |
18dd2392 | 7153 | if (!ret_val && (!(buf & BIT(0)))) { |
10aa4c04 | 7154 | /* Deep Smart Power Down (DSPD) */ |
6c2a9efa FP |
7155 | dev_warn(&adapter->pdev->dev, |
7156 | "Warning: detected DSPD enabled in EEPROM\n"); | |
10aa4c04 | 7157 | } |
10aa4c04 AK |
7158 | } |
7159 | ||
55e7fe5b AD |
7160 | static netdev_features_t e1000_fix_features(struct net_device *netdev, |
7161 | netdev_features_t features) | |
7162 | { | |
7163 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
7164 | struct e1000_hw *hw = &adapter->hw; | |
7165 | ||
7166 | /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */ | |
7167 | if ((hw->mac.type >= e1000_pch2lan) && (netdev->mtu > ETH_DATA_LEN)) | |
7168 | features &= ~NETIF_F_RXFCS; | |
7169 | ||
83808641 JW |
7170 | /* Since there is no support for separate Rx/Tx vlan accel |
7171 | * enable/disable make sure Tx flag is always in same state as Rx. | |
7172 | */ | |
7173 | if (features & NETIF_F_HW_VLAN_CTAG_RX) | |
7174 | features |= NETIF_F_HW_VLAN_CTAG_TX; | |
7175 | else | |
7176 | features &= ~NETIF_F_HW_VLAN_CTAG_TX; | |
7177 | ||
55e7fe5b AD |
7178 | return features; |
7179 | } | |
7180 | ||
c8f44aff | 7181 | static int e1000_set_features(struct net_device *netdev, |
70495a50 | 7182 | netdev_features_t features) |
dc221294 BA |
7183 | { |
7184 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
c8f44aff | 7185 | netdev_features_t changed = features ^ netdev->features; |
dc221294 BA |
7186 | |
7187 | if (changed & (NETIF_F_TSO | NETIF_F_TSO6)) | |
7188 | adapter->flags |= FLAG_TSO_FORCE; | |
7189 | ||
f646968f | 7190 | if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX | |
cf955e6c BG |
7191 | NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS | |
7192 | NETIF_F_RXALL))) | |
dc221294 BA |
7193 | return 0; |
7194 | ||
0184039a BG |
7195 | if (changed & NETIF_F_RXFCS) { |
7196 | if (features & NETIF_F_RXFCS) { | |
7197 | adapter->flags2 &= ~FLAG2_CRC_STRIPPING; | |
7198 | } else { | |
7199 | /* We need to take it back to defaults, which might mean | |
7200 | * stripping is still disabled at the adapter level. | |
7201 | */ | |
7202 | if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING) | |
7203 | adapter->flags2 |= FLAG2_CRC_STRIPPING; | |
7204 | else | |
7205 | adapter->flags2 &= ~FLAG2_CRC_STRIPPING; | |
7206 | } | |
7207 | } | |
7208 | ||
70495a50 BA |
7209 | netdev->features = features; |
7210 | ||
dc221294 BA |
7211 | if (netif_running(netdev)) |
7212 | e1000e_reinit_locked(adapter); | |
7213 | else | |
7214 | e1000e_reset(adapter); | |
7215 | ||
b0ddfe2b | 7216 | return 1; |
dc221294 BA |
7217 | } |
7218 | ||
651c2466 | 7219 | static const struct net_device_ops e1000e_netdev_ops = { |
d5ea45da SA |
7220 | .ndo_open = e1000e_open, |
7221 | .ndo_stop = e1000e_close, | |
00829823 | 7222 | .ndo_start_xmit = e1000_xmit_frame, |
67fd4fcb | 7223 | .ndo_get_stats64 = e1000e_get_stats64, |
ef9b965a | 7224 | .ndo_set_rx_mode = e1000e_set_rx_mode, |
651c2466 SH |
7225 | .ndo_set_mac_address = e1000_set_mac, |
7226 | .ndo_change_mtu = e1000_change_mtu, | |
7227 | .ndo_do_ioctl = e1000_ioctl, | |
7228 | .ndo_tx_timeout = e1000_tx_timeout, | |
7229 | .ndo_validate_addr = eth_validate_addr, | |
7230 | ||
651c2466 SH |
7231 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
7232 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, | |
7233 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
7234 | .ndo_poll_controller = e1000_netpoll, | |
7235 | #endif | |
dc221294 | 7236 | .ndo_set_features = e1000_set_features, |
55e7fe5b | 7237 | .ndo_fix_features = e1000_fix_features, |
f2701b18 | 7238 | .ndo_features_check = passthru_features_check, |
651c2466 SH |
7239 | }; |
7240 | ||
bc7f75fa AK |
7241 | /** |
7242 | * e1000_probe - Device Initialization Routine | |
7243 | * @pdev: PCI device information struct | |
7244 | * @ent: entry in e1000_pci_tbl | |
7245 | * | |
7246 | * Returns 0 on success, negative on failure | |
7247 | * | |
7248 | * e1000_probe initializes an adapter identified by a pci_dev structure. | |
7249 | * The OS initialization, configuring of the adapter private structure, | |
7250 | * and a hardware reset occur. | |
7251 | **/ | |
1dd06ae8 | 7252 | static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
bc7f75fa AK |
7253 | { |
7254 | struct net_device *netdev; | |
7255 | struct e1000_adapter *adapter; | |
7256 | struct e1000_hw *hw; | |
7257 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; | |
f47e81fc BB |
7258 | resource_size_t mmio_start, mmio_len; |
7259 | resource_size_t flash_start, flash_len; | |
bc7f75fa | 7260 | static int cards_found; |
78cd29d5 | 7261 | u16 aspm_disable_flag = 0; |
17e813ec | 7262 | int bars, i, err, pci_using_dac; |
bc7f75fa AK |
7263 | u16 eeprom_data = 0; |
7264 | u16 eeprom_apme_mask = E1000_EEPROM_APME; | |
847042a6 | 7265 | s32 ret_val = 0; |
bc7f75fa | 7266 | |
78cd29d5 BA |
7267 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S) |
7268 | aspm_disable_flag = PCIE_LINK_STATE_L0S; | |
6f461f6c | 7269 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L1) |
78cd29d5 BA |
7270 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
7271 | if (aspm_disable_flag) | |
7272 | e1000e_disable_aspm(pdev, aspm_disable_flag); | |
6e4f6f6b | 7273 | |
f0f422e5 | 7274 | err = pci_enable_device_mem(pdev); |
bc7f75fa AK |
7275 | if (err) |
7276 | return err; | |
7277 | ||
7278 | pci_using_dac = 0; | |
718a39eb | 7279 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
bc7f75fa | 7280 | if (!err) { |
718a39eb | 7281 | pci_using_dac = 1; |
bc7f75fa | 7282 | } else { |
718a39eb | 7283 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
bc7f75fa | 7284 | if (err) { |
718a39eb RK |
7285 | dev_err(&pdev->dev, |
7286 | "No usable DMA configuration, aborting\n"); | |
7287 | goto err_dma; | |
bc7f75fa AK |
7288 | } |
7289 | } | |
7290 | ||
17e813ec BA |
7291 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
7292 | err = pci_request_selected_regions_exclusive(pdev, bars, | |
7293 | e1000e_driver_name); | |
bc7f75fa AK |
7294 | if (err) |
7295 | goto err_pci_reg; | |
7296 | ||
68eac460 | 7297 | /* AER (Advanced Error Reporting) hooks */ |
19d5afd4 | 7298 | pci_enable_pcie_error_reporting(pdev); |
68eac460 | 7299 | |
bc7f75fa | 7300 | pci_set_master(pdev); |
438b365a BA |
7301 | /* PCI config space info */ |
7302 | err = pci_save_state(pdev); | |
7303 | if (err) | |
7304 | goto err_alloc_etherdev; | |
bc7f75fa AK |
7305 | |
7306 | err = -ENOMEM; | |
7307 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); | |
7308 | if (!netdev) | |
7309 | goto err_alloc_etherdev; | |
7310 | ||
bc7f75fa AK |
7311 | SET_NETDEV_DEV(netdev, &pdev->dev); |
7312 | ||
f85e4dfa TH |
7313 | netdev->irq = pdev->irq; |
7314 | ||
bc7f75fa AK |
7315 | pci_set_drvdata(pdev, netdev); |
7316 | adapter = netdev_priv(netdev); | |
7317 | hw = &adapter->hw; | |
7318 | adapter->netdev = netdev; | |
7319 | adapter->pdev = pdev; | |
7320 | adapter->ei = ei; | |
7321 | adapter->pba = ei->pba; | |
7322 | adapter->flags = ei->flags; | |
eb7c3adb | 7323 | adapter->flags2 = ei->flags2; |
bc7f75fa AK |
7324 | adapter->hw.adapter = adapter; |
7325 | adapter->hw.mac.type = ei->mac; | |
2adc55c9 | 7326 | adapter->max_hw_frame_size = ei->max_hw_frame_size; |
b3f4d599 | 7327 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
bc7f75fa AK |
7328 | |
7329 | mmio_start = pci_resource_start(pdev, 0); | |
7330 | mmio_len = pci_resource_len(pdev, 0); | |
7331 | ||
7332 | err = -EIO; | |
7333 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); | |
7334 | if (!adapter->hw.hw_addr) | |
7335 | goto err_ioremap; | |
7336 | ||
7337 | if ((adapter->flags & FLAG_HAS_FLASH) && | |
1103a631 YL |
7338 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM) && |
7339 | (hw->mac.type < e1000_pch_spt)) { | |
bc7f75fa AK |
7340 | flash_start = pci_resource_start(pdev, 1); |
7341 | flash_len = pci_resource_len(pdev, 1); | |
7342 | adapter->hw.flash_address = ioremap(flash_start, flash_len); | |
7343 | if (!adapter->hw.flash_address) | |
7344 | goto err_flashmap; | |
7345 | } | |
7346 | ||
d495bcb8 BA |
7347 | /* Set default EEE advertisement */ |
7348 | if (adapter->flags2 & FLAG2_HAS_EEE) | |
7349 | adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T; | |
7350 | ||
bc7f75fa | 7351 | /* construct the net_device struct */ |
e80bd1d1 | 7352 | netdev->netdev_ops = &e1000e_netdev_ops; |
bc7f75fa | 7353 | e1000e_set_ethtool_ops(netdev); |
e80bd1d1 | 7354 | netdev->watchdog_timeo = 5 * HZ; |
c58c8a78 | 7355 | netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64); |
f2315bf1 | 7356 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
bc7f75fa AK |
7357 | |
7358 | netdev->mem_start = mmio_start; | |
7359 | netdev->mem_end = mmio_start + mmio_len; | |
7360 | ||
7361 | adapter->bd_number = cards_found++; | |
7362 | ||
4662e82b BA |
7363 | e1000e_check_options(adapter); |
7364 | ||
bc7f75fa AK |
7365 | /* setup adapter struct */ |
7366 | err = e1000_sw_init(adapter); | |
7367 | if (err) | |
7368 | goto err_sw_init; | |
7369 | ||
bc7f75fa AK |
7370 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
7371 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); | |
7372 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); | |
7373 | ||
69e3fd8c | 7374 | err = ei->get_variants(adapter); |
bc7f75fa AK |
7375 | if (err) |
7376 | goto err_hw_init; | |
7377 | ||
4a770358 | 7378 | if ((adapter->flags & FLAG_IS_ICH) && |
152c0a97 YL |
7379 | (adapter->flags & FLAG_READ_ONLY_NVM) && |
7380 | (hw->mac.type < e1000_pch_spt)) | |
4a770358 BA |
7381 | e1000e_write_protect_nvm_ich8lan(&adapter->hw); |
7382 | ||
bc7f75fa AK |
7383 | hw->mac.ops.get_bus_info(&adapter->hw); |
7384 | ||
318a94d6 | 7385 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
bc7f75fa AK |
7386 | |
7387 | /* Copper options */ | |
318a94d6 | 7388 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
bc7f75fa AK |
7389 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
7390 | adapter->hw.phy.disable_polarity_correction = 0; | |
7391 | adapter->hw.phy.ms_type = e1000_ms_hw_default; | |
7392 | } | |
7393 | ||
470a5420 | 7394 | if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw)) |
185095fb BA |
7395 | dev_info(&pdev->dev, |
7396 | "PHY reset is blocked due to SOL/IDER session.\n"); | |
bc7f75fa | 7397 | |
dc221294 BA |
7398 | /* Set initial default active device features */ |
7399 | netdev->features = (NETIF_F_SG | | |
f646968f PM |
7400 | NETIF_F_HW_VLAN_CTAG_RX | |
7401 | NETIF_F_HW_VLAN_CTAG_TX | | |
dc221294 BA |
7402 | NETIF_F_TSO | |
7403 | NETIF_F_TSO6 | | |
70495a50 | 7404 | NETIF_F_RXHASH | |
dc221294 BA |
7405 | NETIF_F_RXCSUM | |
7406 | NETIF_F_HW_CSUM); | |
7407 | ||
7408 | /* Set user-changeable features (subset of all device features) */ | |
7409 | netdev->hw_features = netdev->features; | |
0184039a | 7410 | netdev->hw_features |= NETIF_F_RXFCS; |
943146de | 7411 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
cf955e6c | 7412 | netdev->hw_features |= NETIF_F_RXALL; |
bc7f75fa AK |
7413 | |
7414 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) | |
f646968f | 7415 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
bc7f75fa | 7416 | |
dc221294 BA |
7417 | netdev->vlan_features |= (NETIF_F_SG | |
7418 | NETIF_F_TSO | | |
7419 | NETIF_F_TSO6 | | |
7420 | NETIF_F_HW_CSUM); | |
a5136e23 | 7421 | |
ef9b965a JB |
7422 | netdev->priv_flags |= IFF_UNICAST_FLT; |
7423 | ||
7b872a55 | 7424 | if (pci_using_dac) { |
bc7f75fa | 7425 | netdev->features |= NETIF_F_HIGHDMA; |
7b872a55 YZ |
7426 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
7427 | } | |
bc7f75fa | 7428 | |
91c527a5 JW |
7429 | /* MTU range: 68 - max_hw_frame_size */ |
7430 | netdev->min_mtu = ETH_MIN_MTU; | |
7431 | netdev->max_mtu = adapter->max_hw_frame_size - | |
7432 | (VLAN_ETH_HLEN + ETH_FCS_LEN); | |
7433 | ||
bc7f75fa AK |
7434 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
7435 | adapter->flags |= FLAG_MNG_PT_ENABLED; | |
7436 | ||
e921eb1a | 7437 | /* before reading the NVM, reset the controller to |
ad68076e BA |
7438 | * put the device in a known good starting state |
7439 | */ | |
bc7f75fa AK |
7440 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
7441 | ||
e921eb1a | 7442 | /* systems with ASPM and others may see the checksum fail on the first |
bc7f75fa AK |
7443 | * attempt. Let's give it a few tries |
7444 | */ | |
7445 | for (i = 0;; i++) { | |
7446 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) | |
7447 | break; | |
7448 | if (i == 2) { | |
185095fb | 7449 | dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n"); |
bc7f75fa AK |
7450 | err = -EIO; |
7451 | goto err_eeprom; | |
7452 | } | |
7453 | } | |
7454 | ||
10aa4c04 AK |
7455 | e1000_eeprom_checks(adapter); |
7456 | ||
608f8a0d | 7457 | /* copy the MAC address */ |
bc7f75fa | 7458 | if (e1000e_read_mac_addr(&adapter->hw)) |
185095fb BA |
7459 | dev_err(&pdev->dev, |
7460 | "NVM Read Error while reading MAC address\n"); | |
bc7f75fa AK |
7461 | |
7462 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); | |
bc7f75fa | 7463 | |
aaeb6cdf | 7464 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
185095fb | 7465 | dev_err(&pdev->dev, "Invalid MAC Address: %pM\n", |
aaeb6cdf | 7466 | netdev->dev_addr); |
bc7f75fa AK |
7467 | err = -EIO; |
7468 | goto err_eeprom; | |
7469 | } | |
7470 | ||
b4275924 | 7471 | timer_setup(&adapter->watchdog_timer, e1000_watchdog, 0); |
26566eae | 7472 | timer_setup(&adapter->phy_info_timer, e1000_update_phy_info, 0); |
bc7f75fa AK |
7473 | |
7474 | INIT_WORK(&adapter->reset_task, e1000_reset_task); | |
b4275924 | 7475 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
a8f88ff5 JB |
7476 | INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); |
7477 | INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); | |
41cec6f1 | 7478 | INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang); |
bc7f75fa | 7479 | |
bc7f75fa AK |
7480 | /* Initialize link parameters. User can change them with ethtool */ |
7481 | adapter->hw.mac.autoneg = 1; | |
3db1cd5c | 7482 | adapter->fc_autoneg = true; |
5c48ef3e BA |
7483 | adapter->hw.fc.requested_mode = e1000_fc_default; |
7484 | adapter->hw.fc.current_mode = e1000_fc_default; | |
bc7f75fa AK |
7485 | adapter->hw.phy.autoneg_advertised = 0x2f; |
7486 | ||
e921eb1a | 7487 | /* Initial Wake on LAN setting - If APM wake is enabled in |
bc7f75fa AK |
7488 | * the EEPROM, enable the ACPI Magic Packet filter |
7489 | */ | |
7490 | if (adapter->flags & FLAG_APME_IN_WUC) { | |
7491 | /* APME bit in EEPROM is mapped to WUC.APME */ | |
7492 | eeprom_data = er32(WUC); | |
7493 | eeprom_apme_mask = E1000_WUC_APME; | |
4def99bb BA |
7494 | if ((hw->mac.type > e1000_ich10lan) && |
7495 | (eeprom_data & E1000_WUC_PHY_WAKE)) | |
a4f58f54 | 7496 | adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; |
bc7f75fa AK |
7497 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
7498 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && | |
7499 | (adapter->hw.bus.func == 1)) | |
847042a6 | 7500 | ret_val = e1000_read_nvm(&adapter->hw, |
491a04d2 DE |
7501 | NVM_INIT_CONTROL3_PORT_B, |
7502 | 1, &eeprom_data); | |
bc7f75fa | 7503 | else |
847042a6 | 7504 | ret_val = e1000_read_nvm(&adapter->hw, |
491a04d2 DE |
7505 | NVM_INIT_CONTROL3_PORT_A, |
7506 | 1, &eeprom_data); | |
bc7f75fa AK |
7507 | } |
7508 | ||
7509 | /* fetch WoL from EEPROM */ | |
847042a6 BW |
7510 | if (ret_val) |
7511 | e_dbg("NVM read error getting WoL initial values: %d\n", ret_val); | |
491a04d2 | 7512 | else if (eeprom_data & eeprom_apme_mask) |
bc7f75fa AK |
7513 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
7514 | ||
e921eb1a | 7515 | /* now that we have the eeprom settings, apply the special cases |
bc7f75fa AK |
7516 | * where the eeprom may be wrong or the board simply won't support |
7517 | * wake on lan on a particular port | |
7518 | */ | |
7519 | if (!(adapter->flags & FLAG_HAS_WOL)) | |
7520 | adapter->eeprom_wol = 0; | |
7521 | ||
7522 | /* initialize the wol settings based on the eeprom settings */ | |
7523 | adapter->wol = adapter->eeprom_wol; | |
66148bab KK |
7524 | |
7525 | /* make sure adapter isn't asleep if manageability is enabled */ | |
7526 | if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) || | |
7527 | (hw->mac.ops.check_mng_mode(hw))) | |
7528 | device_wakeup_enable(&pdev->dev); | |
bc7f75fa | 7529 | |
84527590 | 7530 | /* save off EEPROM version number */ |
847042a6 | 7531 | ret_val = e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); |
491a04d2 | 7532 | |
847042a6 BW |
7533 | if (ret_val) { |
7534 | e_dbg("NVM read error getting EEPROM version: %d\n", ret_val); | |
491a04d2 DE |
7535 | adapter->eeprom_vers = 0; |
7536 | } | |
84527590 | 7537 | |
aa524b66 JK |
7538 | /* init PTP hardware clock */ |
7539 | e1000e_ptp_init(adapter); | |
7540 | ||
bc7f75fa AK |
7541 | /* reset the hardware with the new settings */ |
7542 | e1000e_reset(adapter); | |
7543 | ||
e921eb1a | 7544 | /* If the controller has AMT, do not set DRV_LOAD until the interface |
bc7f75fa | 7545 | * is up. For all other cases, let the f/w know that the h/w is now |
ad68076e BA |
7546 | * under the control of the driver. |
7547 | */ | |
c43bc57e | 7548 | if (!(adapter->flags & FLAG_HAS_AMT)) |
31dbe5b4 | 7549 | e1000e_get_hw_control(adapter); |
bc7f75fa | 7550 | |
f2315bf1 | 7551 | strlcpy(netdev->name, "eth%d", sizeof(netdev->name)); |
bc7f75fa AK |
7552 | err = register_netdev(netdev); |
7553 | if (err) | |
7554 | goto err_register; | |
7555 | ||
9c563d20 JB |
7556 | /* carrier off reporting is important to ethtool even BEFORE open */ |
7557 | netif_carrier_off(netdev); | |
7558 | ||
bc7f75fa AK |
7559 | e1000_print_device_info(adapter); |
7560 | ||
59f58708 KHF |
7561 | dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NEVER_SKIP); |
7562 | ||
459d69c4 | 7563 | if (pci_dev_run_wake(pdev) && hw->mac.type < e1000_pch_cnp) |
f3ec4f87 | 7564 | pm_runtime_put_noidle(&pdev->dev); |
23606cf5 | 7565 | |
bc7f75fa AK |
7566 | return 0; |
7567 | ||
7568 | err_register: | |
c43bc57e | 7569 | if (!(adapter->flags & FLAG_HAS_AMT)) |
31dbe5b4 | 7570 | e1000e_release_hw_control(adapter); |
bc7f75fa | 7571 | err_eeprom: |
470a5420 | 7572 | if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw)) |
bc7f75fa | 7573 | e1000_phy_hw_reset(&adapter->hw); |
c43bc57e | 7574 | err_hw_init: |
bc7f75fa AK |
7575 | kfree(adapter->tx_ring); |
7576 | kfree(adapter->rx_ring); | |
7577 | err_sw_init: | |
1103a631 | 7578 | if ((adapter->hw.flash_address) && (hw->mac.type < e1000_pch_spt)) |
c43bc57e | 7579 | iounmap(adapter->hw.flash_address); |
e82f54ba | 7580 | e1000e_reset_interrupt_capability(adapter); |
c43bc57e | 7581 | err_flashmap: |
bc7f75fa AK |
7582 | iounmap(adapter->hw.hw_addr); |
7583 | err_ioremap: | |
7584 | free_netdev(netdev); | |
7585 | err_alloc_etherdev: | |
59ca1767 | 7586 | pci_disable_pcie_error_reporting(pdev); |
56d766d6 | 7587 | pci_release_mem_regions(pdev); |
bc7f75fa AK |
7588 | err_pci_reg: |
7589 | err_dma: | |
7590 | pci_disable_device(pdev); | |
7591 | return err; | |
7592 | } | |
7593 | ||
7594 | /** | |
7595 | * e1000_remove - Device Removal Routine | |
7596 | * @pdev: PCI device information struct | |
7597 | * | |
7598 | * e1000_remove is called by the PCI subsystem to alert the driver | |
7599 | * that it should release a PCI device. The could be caused by a | |
7600 | * Hot-Plug event, or because the driver is going to be removed from | |
7601 | * memory. | |
7602 | **/ | |
9f9a12f8 | 7603 | static void e1000_remove(struct pci_dev *pdev) |
bc7f75fa AK |
7604 | { |
7605 | struct net_device *netdev = pci_get_drvdata(pdev); | |
7606 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
23606cf5 | 7607 | |
d89777bf BA |
7608 | e1000e_ptp_remove(adapter); |
7609 | ||
e921eb1a | 7610 | /* The timers may be rescheduled, so explicitly disable them |
23f333a2 | 7611 | * from being rescheduled. |
ad68076e | 7612 | */ |
4f2d8236 | 7613 | set_bit(__E1000_DOWN, &adapter->state); |
b4275924 | 7614 | del_timer_sync(&adapter->watchdog_timer); |
bc7f75fa AK |
7615 | del_timer_sync(&adapter->phy_info_timer); |
7616 | ||
41cec6f1 | 7617 | cancel_work_sync(&adapter->reset_task); |
b4275924 | 7618 | cancel_work_sync(&adapter->watchdog_task); |
41cec6f1 BA |
7619 | cancel_work_sync(&adapter->downshift_task); |
7620 | cancel_work_sync(&adapter->update_phy_task); | |
7621 | cancel_work_sync(&adapter->print_hang_task); | |
bc7f75fa | 7622 | |
b67e1913 BA |
7623 | if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) { |
7624 | cancel_work_sync(&adapter->tx_hwtstamp_work); | |
7625 | if (adapter->tx_hwtstamp_skb) { | |
377b6273 | 7626 | dev_consume_skb_any(adapter->tx_hwtstamp_skb); |
b67e1913 BA |
7627 | adapter->tx_hwtstamp_skb = NULL; |
7628 | } | |
7629 | } | |
7630 | ||
17f208de BA |
7631 | unregister_netdev(netdev); |
7632 | ||
f3ec4f87 AS |
7633 | if (pci_dev_run_wake(pdev)) |
7634 | pm_runtime_get_noresume(&pdev->dev); | |
23606cf5 | 7635 | |
e921eb1a | 7636 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
ad68076e BA |
7637 | * would have already happened in close and is redundant. |
7638 | */ | |
31dbe5b4 | 7639 | e1000e_release_hw_control(adapter); |
bc7f75fa | 7640 | |
4662e82b | 7641 | e1000e_reset_interrupt_capability(adapter); |
bc7f75fa AK |
7642 | kfree(adapter->tx_ring); |
7643 | kfree(adapter->rx_ring); | |
7644 | ||
7645 | iounmap(adapter->hw.hw_addr); | |
1103a631 YL |
7646 | if ((adapter->hw.flash_address) && |
7647 | (adapter->hw.mac.type < e1000_pch_spt)) | |
bc7f75fa | 7648 | iounmap(adapter->hw.flash_address); |
56d766d6 | 7649 | pci_release_mem_regions(pdev); |
bc7f75fa AK |
7650 | |
7651 | free_netdev(netdev); | |
7652 | ||
111b9dc5 | 7653 | /* AER disable */ |
19d5afd4 | 7654 | pci_disable_pcie_error_reporting(pdev); |
111b9dc5 | 7655 | |
bc7f75fa AK |
7656 | pci_disable_device(pdev); |
7657 | } | |
7658 | ||
7659 | /* PCI Error Recovery (ERS) */ | |
3646f0e5 | 7660 | static const struct pci_error_handlers e1000_err_handler = { |
bc7f75fa AK |
7661 | .error_detected = e1000_io_error_detected, |
7662 | .slot_reset = e1000_io_slot_reset, | |
7663 | .resume = e1000_io_resume, | |
7664 | }; | |
7665 | ||
0e8e842b | 7666 | static const struct pci_device_id e1000_pci_tbl[] = { |
bc7f75fa AK |
7667 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
7668 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, | |
7669 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, | |
c29c3ba5 BA |
7670 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), |
7671 | board_82571 }, | |
bc7f75fa AK |
7672 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
7673 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, | |
040babf9 AK |
7674 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
7675 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, | |
7676 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, | |
ad68076e | 7677 | |
bc7f75fa AK |
7678 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
7679 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, | |
7680 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, | |
7681 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, | |
ad68076e | 7682 | |
bc7f75fa AK |
7683 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
7684 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, | |
7685 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, | |
ad68076e | 7686 | |
4662e82b | 7687 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, |
bef28b11 | 7688 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, |
8c81c9c3 | 7689 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, |
4662e82b | 7690 | |
bc7f75fa AK |
7691 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
7692 | board_80003es2lan }, | |
7693 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), | |
7694 | board_80003es2lan }, | |
7695 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), | |
7696 | board_80003es2lan }, | |
7697 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), | |
7698 | board_80003es2lan }, | |
ad68076e | 7699 | |
bc7f75fa AK |
7700 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
7701 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, | |
7702 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, | |
7703 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, | |
7704 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, | |
7705 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, | |
7706 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, | |
9e135a2e | 7707 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan }, |
ad68076e | 7708 | |
bc7f75fa AK |
7709 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
7710 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, | |
7711 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, | |
7712 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, | |
7713 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, | |
2f15f9d6 | 7714 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, |
97ac8cae BA |
7715 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, |
7716 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, | |
7717 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, | |
7718 | ||
7719 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, | |
7720 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, | |
7721 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, | |
bc7f75fa | 7722 | |
f4187b56 BA |
7723 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, |
7724 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, | |
10df0b91 | 7725 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan }, |
f4187b56 | 7726 | |
a4f58f54 BA |
7727 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, |
7728 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, | |
7729 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, | |
7730 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, | |
7731 | ||
d3738bb8 BA |
7732 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan }, |
7733 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan }, | |
7734 | ||
2fbe4526 BA |
7735 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt }, |
7736 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt }, | |
16e310ae BA |
7737 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt }, |
7738 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt }, | |
91a3d82f BA |
7739 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt }, |
7740 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt }, | |
7741 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt }, | |
7742 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt }, | |
79849ebc DE |
7743 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM), board_pch_spt }, |
7744 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V), board_pch_spt }, | |
7745 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM2), board_pch_spt }, | |
7746 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V2), board_pch_spt }, | |
f3ed935d | 7747 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LBG_I219_LM3), board_pch_spt }, |
9cd34b3a RA |
7748 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM4), board_pch_spt }, |
7749 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V4), board_pch_spt }, | |
7750 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM5), board_pch_spt }, | |
7751 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V5), board_pch_spt }, | |
3a3173b9 SN |
7752 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM6), board_pch_cnp }, |
7753 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V6), board_pch_cnp }, | |
7754 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM7), board_pch_cnp }, | |
7755 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V7), board_pch_cnp }, | |
48f76b68 SN |
7756 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM8), board_pch_cnp }, |
7757 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V8), board_pch_cnp }, | |
7758 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM9), board_pch_cnp }, | |
7759 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V9), board_pch_cnp }, | |
ceaad0e5 SN |
7760 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM10), board_pch_cnp }, |
7761 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V10), board_pch_cnp }, | |
7762 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM11), board_pch_cnp }, | |
7763 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V11), board_pch_cnp }, | |
7764 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM12), board_pch_spt }, | |
7765 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V12), board_pch_spt }, | |
2fbe4526 | 7766 | |
f36bb6ca | 7767 | { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */ |
bc7f75fa AK |
7768 | }; |
7769 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); | |
7770 | ||
23606cf5 | 7771 | static const struct dev_pm_ops e1000_pm_ops = { |
72f72dcc | 7772 | #ifdef CONFIG_PM_SLEEP |
28002099 DE |
7773 | .suspend = e1000e_pm_suspend, |
7774 | .resume = e1000e_pm_resume, | |
7775 | .freeze = e1000e_pm_freeze, | |
7776 | .thaw = e1000e_pm_thaw, | |
7777 | .poweroff = e1000e_pm_suspend, | |
7778 | .restore = e1000e_pm_resume, | |
72f72dcc | 7779 | #endif |
63eb48f1 DE |
7780 | SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume, |
7781 | e1000e_pm_runtime_idle) | |
23606cf5 RW |
7782 | }; |
7783 | ||
bc7f75fa AK |
7784 | /* PCI Device API Driver */ |
7785 | static struct pci_driver e1000_driver = { | |
7786 | .name = e1000e_driver_name, | |
7787 | .id_table = e1000_pci_tbl, | |
7788 | .probe = e1000_probe, | |
9f9a12f8 | 7789 | .remove = e1000_remove, |
f36bb6ca BA |
7790 | .driver = { |
7791 | .pm = &e1000_pm_ops, | |
7792 | }, | |
bc7f75fa AK |
7793 | .shutdown = e1000_shutdown, |
7794 | .err_handler = &e1000_err_handler | |
7795 | }; | |
7796 | ||
7797 | /** | |
7798 | * e1000_init_module - Driver Registration Routine | |
7799 | * | |
7800 | * e1000_init_module is the first routine called when the driver is | |
7801 | * loaded. All it does is register with the PCI subsystem. | |
7802 | **/ | |
7803 | static int __init e1000_init_module(void) | |
7804 | { | |
8544b9f7 BA |
7805 | pr_info("Intel(R) PRO/1000 Network Driver - %s\n", |
7806 | e1000e_driver_version); | |
529498cd | 7807 | pr_info("Copyright(c) 1999 - 2015 Intel Corporation.\n"); |
53ec5498 | 7808 | |
5a5e889c | 7809 | return pci_register_driver(&e1000_driver); |
bc7f75fa AK |
7810 | } |
7811 | module_init(e1000_init_module); | |
7812 | ||
7813 | /** | |
7814 | * e1000_exit_module - Driver Exit Cleanup Routine | |
7815 | * | |
7816 | * e1000_exit_module is called just before the driver is removed | |
7817 | * from memory. | |
7818 | **/ | |
7819 | static void __exit e1000_exit_module(void) | |
7820 | { | |
7821 | pci_unregister_driver(&e1000_driver); | |
7822 | } | |
7823 | module_exit(e1000_exit_module); | |
7824 | ||
bc7f75fa AK |
7825 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
7826 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); | |
98674ebe | 7827 | MODULE_LICENSE("GPL v2"); |
bc7f75fa AK |
7828 | MODULE_VERSION(DRV_VERSION); |
7829 | ||
06c24b91 | 7830 | /* netdev.c */ |