aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/e1000e/netdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/e1000e/netdev.c')
-rw-r--r--drivers/net/e1000e/netdev.c835
1 files changed, 660 insertions, 175 deletions
diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c
index 88d54d3efcef..c5f65a29865a 100644
--- a/drivers/net/e1000e/netdev.c
+++ b/drivers/net/e1000e/netdev.c
@@ -26,6 +26,8 @@
26 26
27*******************************************************************************/ 27*******************************************************************************/
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/module.h> 31#include <linux/module.h>
30#include <linux/types.h> 32#include <linux/types.h>
31#include <linux/init.h> 33#include <linux/init.h>
@@ -36,6 +38,7 @@
36#include <linux/netdevice.h> 38#include <linux/netdevice.h>
37#include <linux/tcp.h> 39#include <linux/tcp.h>
38#include <linux/ipv6.h> 40#include <linux/ipv6.h>
41#include <linux/slab.h>
39#include <net/checksum.h> 42#include <net/checksum.h>
40#include <net/ip6_checksum.h> 43#include <net/ip6_checksum.h>
41#include <linux/mii.h> 44#include <linux/mii.h>
@@ -44,11 +47,12 @@
44#include <linux/cpu.h> 47#include <linux/cpu.h>
45#include <linux/smp.h> 48#include <linux/smp.h>
46#include <linux/pm_qos_params.h> 49#include <linux/pm_qos_params.h>
50#include <linux/pm_runtime.h>
47#include <linux/aer.h> 51#include <linux/aer.h>
48 52
49#include "e1000.h" 53#include "e1000.h"
50 54
51#define DRV_VERSION "1.0.2-k2" 55#define DRV_VERSION "1.0.2-k4"
52char e1000e_driver_name[] = "e1000e"; 56char e1000e_driver_name[] = "e1000e";
53const char e1000e_driver_version[] = DRV_VERSION; 57const char e1000e_driver_version[] = DRV_VERSION;
54 58
@@ -65,6 +69,361 @@ static const struct e1000_info *e1000_info_tbl[] = {
65 [board_pchlan] = &e1000_pch_info, 69 [board_pchlan] = &e1000_pch_info,
66}; 70};
67 71
72struct e1000_reg_info {
73 u32 ofs;
74 char *name;
75};
76
77#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
78#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
79#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
80#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
81#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
82
83#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
84#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
85#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
86#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
87#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
88
89static const struct e1000_reg_info e1000_reg_info_tbl[] = {
90
91 /* General Registers */
92 {E1000_CTRL, "CTRL"},
93 {E1000_STATUS, "STATUS"},
94 {E1000_CTRL_EXT, "CTRL_EXT"},
95
96 /* Interrupt Registers */
97 {E1000_ICR, "ICR"},
98
99 /* RX Registers */
100 {E1000_RCTL, "RCTL"},
101 {E1000_RDLEN, "RDLEN"},
102 {E1000_RDH, "RDH"},
103 {E1000_RDT, "RDT"},
104 {E1000_RDTR, "RDTR"},
105 {E1000_RXDCTL(0), "RXDCTL"},
106 {E1000_ERT, "ERT"},
107 {E1000_RDBAL, "RDBAL"},
108 {E1000_RDBAH, "RDBAH"},
109 {E1000_RDFH, "RDFH"},
110 {E1000_RDFT, "RDFT"},
111 {E1000_RDFHS, "RDFHS"},
112 {E1000_RDFTS, "RDFTS"},
113 {E1000_RDFPC, "RDFPC"},
114
115 /* TX Registers */
116 {E1000_TCTL, "TCTL"},
117 {E1000_TDBAL, "TDBAL"},
118 {E1000_TDBAH, "TDBAH"},
119 {E1000_TDLEN, "TDLEN"},
120 {E1000_TDH, "TDH"},
121 {E1000_TDT, "TDT"},
122 {E1000_TIDV, "TIDV"},
123 {E1000_TXDCTL(0), "TXDCTL"},
124 {E1000_TADV, "TADV"},
125 {E1000_TARC(0), "TARC"},
126 {E1000_TDFH, "TDFH"},
127 {E1000_TDFT, "TDFT"},
128 {E1000_TDFHS, "TDFHS"},
129 {E1000_TDFTS, "TDFTS"},
130 {E1000_TDFPC, "TDFPC"},
131
132 /* List Terminator */
133 {}
134};
135
136/*
137 * e1000_regdump - register printout routine
138 */
139static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
140{
141 int n = 0;
142 char rname[16];
143 u32 regs[8];
144
145 switch (reginfo->ofs) {
146 case E1000_RXDCTL(0):
147 for (n = 0; n < 2; n++)
148 regs[n] = __er32(hw, E1000_RXDCTL(n));
149 break;
150 case E1000_TXDCTL(0):
151 for (n = 0; n < 2; n++)
152 regs[n] = __er32(hw, E1000_TXDCTL(n));
153 break;
154 case E1000_TARC(0):
155 for (n = 0; n < 2; n++)
156 regs[n] = __er32(hw, E1000_TARC(n));
157 break;
158 default:
159 printk(KERN_INFO "%-15s %08x\n",
160 reginfo->name, __er32(hw, reginfo->ofs));
161 return;
162 }
163
164 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
165 printk(KERN_INFO "%-15s ", rname);
166 for (n = 0; n < 2; n++)
167 printk(KERN_CONT "%08x ", regs[n]);
168 printk(KERN_CONT "\n");
169}
170
171
172/*
173 * e1000e_dump - Print registers, tx-ring and rx-ring
174 */
175static void e1000e_dump(struct e1000_adapter *adapter)
176{
177 struct net_device *netdev = adapter->netdev;
178 struct e1000_hw *hw = &adapter->hw;
179 struct e1000_reg_info *reginfo;
180 struct e1000_ring *tx_ring = adapter->tx_ring;
181 struct e1000_tx_desc *tx_desc;
182 struct my_u0 { u64 a; u64 b; } *u0;
183 struct e1000_buffer *buffer_info;
184 struct e1000_ring *rx_ring = adapter->rx_ring;
185 union e1000_rx_desc_packet_split *rx_desc_ps;
186 struct e1000_rx_desc *rx_desc;
187 struct my_u1 { u64 a; u64 b; u64 c; u64 d; } *u1;
188 u32 staterr;
189 int i = 0;
190
191 if (!netif_msg_hw(adapter))
192 return;
193
194 /* Print netdevice Info */
195 if (netdev) {
196 dev_info(&adapter->pdev->dev, "Net device Info\n");
197 printk(KERN_INFO "Device Name state "
198 "trans_start last_rx\n");
199 printk(KERN_INFO "%-15s %016lX %016lX %016lX\n",
200 netdev->name,
201 netdev->state,
202 netdev->trans_start,
203 netdev->last_rx);
204 }
205
206 /* Print Registers */
207 dev_info(&adapter->pdev->dev, "Register Dump\n");
208 printk(KERN_INFO " Register Name Value\n");
209 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
210 reginfo->name; reginfo++) {
211 e1000_regdump(hw, reginfo);
212 }
213
214 /* Print TX Ring Summary */
215 if (!netdev || !netif_running(netdev))
216 goto exit;
217
218 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
219 printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]"
220 " leng ntw timestamp\n");
221 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
222 printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n",
223 0, tx_ring->next_to_use, tx_ring->next_to_clean,
224 (u64)buffer_info->dma,
225 buffer_info->length,
226 buffer_info->next_to_watch,
227 (u64)buffer_info->time_stamp);
228
229 /* Print TX Rings */
230 if (!netif_msg_tx_done(adapter))
231 goto rx_ring_summary;
232
233 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
234
235 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
236 *
237 * Legacy Transmit Descriptor
238 * +--------------------------------------------------------------+
239 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
240 * +--------------------------------------------------------------+
241 * 8 | Special | CSS | Status | CMD | CSO | Length |
242 * +--------------------------------------------------------------+
243 * 63 48 47 36 35 32 31 24 23 16 15 0
244 *
245 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
246 * 63 48 47 40 39 32 31 16 15 8 7 0
247 * +----------------------------------------------------------------+
248 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
249 * +----------------------------------------------------------------+
250 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
251 * +----------------------------------------------------------------+
252 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
253 *
254 * Extended Data Descriptor (DTYP=0x1)
255 * +----------------------------------------------------------------+
256 * 0 | Buffer Address [63:0] |
257 * +----------------------------------------------------------------+
258 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
259 * +----------------------------------------------------------------+
260 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
261 */
262 printk(KERN_INFO "Tl[desc] [address 63:0 ] [SpeCssSCmCsLen]"
263 " [bi->dma ] leng ntw timestamp bi->skb "
264 "<-- Legacy format\n");
265 printk(KERN_INFO "Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen]"
266 " [bi->dma ] leng ntw timestamp bi->skb "
267 "<-- Ext Context format\n");
268 printk(KERN_INFO "Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen]"
269 " [bi->dma ] leng ntw timestamp bi->skb "
270 "<-- Ext Data format\n");
271 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
272 tx_desc = E1000_TX_DESC(*tx_ring, i);
273 buffer_info = &tx_ring->buffer_info[i];
274 u0 = (struct my_u0 *)tx_desc;
275 printk(KERN_INFO "T%c[0x%03X] %016llX %016llX %016llX "
276 "%04X %3X %016llX %p",
277 (!(le64_to_cpu(u0->b) & (1<<29)) ? 'l' :
278 ((le64_to_cpu(u0->b) & (1<<20)) ? 'd' : 'c')), i,
279 le64_to_cpu(u0->a), le64_to_cpu(u0->b),
280 (u64)buffer_info->dma, buffer_info->length,
281 buffer_info->next_to_watch, (u64)buffer_info->time_stamp,
282 buffer_info->skb);
283 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
284 printk(KERN_CONT " NTC/U\n");
285 else if (i == tx_ring->next_to_use)
286 printk(KERN_CONT " NTU\n");
287 else if (i == tx_ring->next_to_clean)
288 printk(KERN_CONT " NTC\n");
289 else
290 printk(KERN_CONT "\n");
291
292 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
293 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
294 16, 1, phys_to_virt(buffer_info->dma),
295 buffer_info->length, true);
296 }
297
298 /* Print RX Rings Summary */
299rx_ring_summary:
300 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
301 printk(KERN_INFO "Queue [NTU] [NTC]\n");
302 printk(KERN_INFO " %5d %5X %5X\n", 0,
303 rx_ring->next_to_use, rx_ring->next_to_clean);
304
305 /* Print RX Rings */
306 if (!netif_msg_rx_status(adapter))
307 goto exit;
308
309 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
310 switch (adapter->rx_ps_pages) {
311 case 1:
312 case 2:
313 case 3:
314 /* [Extended] Packet Split Receive Descriptor Format
315 *
316 * +-----------------------------------------------------+
317 * 0 | Buffer Address 0 [63:0] |
318 * +-----------------------------------------------------+
319 * 8 | Buffer Address 1 [63:0] |
320 * +-----------------------------------------------------+
321 * 16 | Buffer Address 2 [63:0] |
322 * +-----------------------------------------------------+
323 * 24 | Buffer Address 3 [63:0] |
324 * +-----------------------------------------------------+
325 */
326 printk(KERN_INFO "R [desc] [buffer 0 63:0 ] "
327 "[buffer 1 63:0 ] "
328 "[buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] "
329 "[bi->skb] <-- Ext Pkt Split format\n");
330 /* [Extended] Receive Descriptor (Write-Back) Format
331 *
332 * 63 48 47 32 31 13 12 8 7 4 3 0
333 * +------------------------------------------------------+
334 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
335 * | Checksum | Ident | | Queue | | Type |
336 * +------------------------------------------------------+
337 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
338 * +------------------------------------------------------+
339 * 63 48 47 32 31 20 19 0
340 */
341 printk(KERN_INFO "RWB[desc] [ck ipid mrqhsh] "
342 "[vl l0 ee es] "
343 "[ l3 l2 l1 hs] [reserved ] ---------------- "
344 "[bi->skb] <-- Ext Rx Write-Back format\n");
345 for (i = 0; i < rx_ring->count; i++) {
346 buffer_info = &rx_ring->buffer_info[i];
347 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
348 u1 = (struct my_u1 *)rx_desc_ps;
349 staterr =
350 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
351 if (staterr & E1000_RXD_STAT_DD) {
352 /* Descriptor Done */
353 printk(KERN_INFO "RWB[0x%03X] %016llX "
354 "%016llX %016llX %016llX "
355 "---------------- %p", i,
356 le64_to_cpu(u1->a),
357 le64_to_cpu(u1->b),
358 le64_to_cpu(u1->c),
359 le64_to_cpu(u1->d),
360 buffer_info->skb);
361 } else {
362 printk(KERN_INFO "R [0x%03X] %016llX "
363 "%016llX %016llX %016llX %016llX %p", i,
364 le64_to_cpu(u1->a),
365 le64_to_cpu(u1->b),
366 le64_to_cpu(u1->c),
367 le64_to_cpu(u1->d),
368 (u64)buffer_info->dma,
369 buffer_info->skb);
370
371 if (netif_msg_pktdata(adapter))
372 print_hex_dump(KERN_INFO, "",
373 DUMP_PREFIX_ADDRESS, 16, 1,
374 phys_to_virt(buffer_info->dma),
375 adapter->rx_ps_bsize0, true);
376 }
377
378 if (i == rx_ring->next_to_use)
379 printk(KERN_CONT " NTU\n");
380 else if (i == rx_ring->next_to_clean)
381 printk(KERN_CONT " NTC\n");
382 else
383 printk(KERN_CONT "\n");
384 }
385 break;
386 default:
387 case 0:
388 /* Legacy Receive Descriptor Format
389 *
390 * +-----------------------------------------------------+
391 * | Buffer Address [63:0] |
392 * +-----------------------------------------------------+
393 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
394 * +-----------------------------------------------------+
395 * 63 48 47 40 39 32 31 16 15 0
396 */
397 printk(KERN_INFO "Rl[desc] [address 63:0 ] "
398 "[vl er S cks ln] [bi->dma ] [bi->skb] "
399 "<-- Legacy format\n");
400 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
401 rx_desc = E1000_RX_DESC(*rx_ring, i);
402 buffer_info = &rx_ring->buffer_info[i];
403 u0 = (struct my_u0 *)rx_desc;
404 printk(KERN_INFO "Rl[0x%03X] %016llX %016llX "
405 "%016llX %p",
406 i, le64_to_cpu(u0->a), le64_to_cpu(u0->b),
407 (u64)buffer_info->dma, buffer_info->skb);
408 if (i == rx_ring->next_to_use)
409 printk(KERN_CONT " NTU\n");
410 else if (i == rx_ring->next_to_clean)
411 printk(KERN_CONT " NTC\n");
412 else
413 printk(KERN_CONT "\n");
414
415 if (netif_msg_pktdata(adapter))
416 print_hex_dump(KERN_INFO, "",
417 DUMP_PREFIX_ADDRESS,
418 16, 1, phys_to_virt(buffer_info->dma),
419 adapter->rx_buffer_len, true);
420 }
421 }
422
423exit:
424 return;
425}
426
68/** 427/**
69 * e1000_desc_unused - calculate if we have unused descriptors 428 * e1000_desc_unused - calculate if we have unused descriptors
70 **/ 429 **/
@@ -177,10 +536,10 @@ static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
177 536
178 buffer_info->skb = skb; 537 buffer_info->skb = skb;
179map_skb: 538map_skb:
180 buffer_info->dma = pci_map_single(pdev, skb->data, 539 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
181 adapter->rx_buffer_len, 540 adapter->rx_buffer_len,
182 PCI_DMA_FROMDEVICE); 541 DMA_FROM_DEVICE);
183 if (pci_dma_mapping_error(pdev, buffer_info->dma)) { 542 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
184 dev_err(&pdev->dev, "RX DMA map failed\n"); 543 dev_err(&pdev->dev, "RX DMA map failed\n");
185 adapter->rx_dma_failed++; 544 adapter->rx_dma_failed++;
186 break; 545 break;
@@ -189,26 +548,23 @@ map_skb:
189 rx_desc = E1000_RX_DESC(*rx_ring, i); 548 rx_desc = E1000_RX_DESC(*rx_ring, i);
190 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); 549 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
191 550
551 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
552 /*
553 * Force memory writes to complete before letting h/w
554 * know there are new descriptors to fetch. (Only
555 * applicable for weak-ordered memory model archs,
556 * such as IA-64).
557 */
558 wmb();
559 writel(i, adapter->hw.hw_addr + rx_ring->tail);
560 }
192 i++; 561 i++;
193 if (i == rx_ring->count) 562 if (i == rx_ring->count)
194 i = 0; 563 i = 0;
195 buffer_info = &rx_ring->buffer_info[i]; 564 buffer_info = &rx_ring->buffer_info[i];
196 } 565 }
197 566
198 if (rx_ring->next_to_use != i) { 567 rx_ring->next_to_use = i;
199 rx_ring->next_to_use = i;
200 if (i-- == 0)
201 i = (rx_ring->count - 1);
202
203 /*
204 * Force memory writes to complete before letting h/w
205 * know there are new descriptors to fetch. (Only
206 * applicable for weak-ordered memory model archs,
207 * such as IA-64).
208 */
209 wmb();
210 writel(i, adapter->hw.hw_addr + rx_ring->tail);
211 }
212} 568}
213 569
214/** 570/**
@@ -246,11 +602,12 @@ static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
246 adapter->alloc_rx_buff_failed++; 602 adapter->alloc_rx_buff_failed++;
247 goto no_buffers; 603 goto no_buffers;
248 } 604 }
249 ps_page->dma = pci_map_page(pdev, 605 ps_page->dma = dma_map_page(&pdev->dev,
250 ps_page->page, 606 ps_page->page,
251 0, PAGE_SIZE, 607 0, PAGE_SIZE,
252 PCI_DMA_FROMDEVICE); 608 DMA_FROM_DEVICE);
253 if (pci_dma_mapping_error(pdev, ps_page->dma)) { 609 if (dma_mapping_error(&pdev->dev,
610 ps_page->dma)) {
254 dev_err(&adapter->pdev->dev, 611 dev_err(&adapter->pdev->dev,
255 "RX DMA page map failed\n"); 612 "RX DMA page map failed\n");
256 adapter->rx_dma_failed++; 613 adapter->rx_dma_failed++;
@@ -275,10 +632,10 @@ static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
275 } 632 }
276 633
277 buffer_info->skb = skb; 634 buffer_info->skb = skb;
278 buffer_info->dma = pci_map_single(pdev, skb->data, 635 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
279 adapter->rx_ps_bsize0, 636 adapter->rx_ps_bsize0,
280 PCI_DMA_FROMDEVICE); 637 DMA_FROM_DEVICE);
281 if (pci_dma_mapping_error(pdev, buffer_info->dma)) { 638 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
282 dev_err(&pdev->dev, "RX DMA map failed\n"); 639 dev_err(&pdev->dev, "RX DMA map failed\n");
283 adapter->rx_dma_failed++; 640 adapter->rx_dma_failed++;
284 /* cleanup skb */ 641 /* cleanup skb */
@@ -289,6 +646,17 @@ static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
289 646
290 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); 647 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
291 648
649 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
650 /*
651 * Force memory writes to complete before letting h/w
652 * know there are new descriptors to fetch. (Only
653 * applicable for weak-ordered memory model archs,
654 * such as IA-64).
655 */
656 wmb();
657 writel(i<<1, adapter->hw.hw_addr + rx_ring->tail);
658 }
659
292 i++; 660 i++;
293 if (i == rx_ring->count) 661 if (i == rx_ring->count)
294 i = 0; 662 i = 0;
@@ -296,26 +664,7 @@ static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
296 } 664 }
297 665
298no_buffers: 666no_buffers:
299 if (rx_ring->next_to_use != i) { 667 rx_ring->next_to_use = i;
300 rx_ring->next_to_use = i;
301
302 if (!(i--))
303 i = (rx_ring->count - 1);
304
305 /*
306 * Force memory writes to complete before letting h/w
307 * know there are new descriptors to fetch. (Only
308 * applicable for weak-ordered memory model archs,
309 * such as IA-64).
310 */
311 wmb();
312 /*
313 * Hardware increments by 16 bytes, but packet split
314 * descriptors are 32 bytes...so we increment tail
315 * twice as much.
316 */
317 writel(i<<1, adapter->hw.hw_addr + rx_ring->tail);
318 }
319} 668}
320 669
321/** 670/**
@@ -365,10 +714,10 @@ check_page:
365 } 714 }
366 715
367 if (!buffer_info->dma) 716 if (!buffer_info->dma)
368 buffer_info->dma = pci_map_page(pdev, 717 buffer_info->dma = dma_map_page(&pdev->dev,
369 buffer_info->page, 0, 718 buffer_info->page, 0,
370 PAGE_SIZE, 719 PAGE_SIZE,
371 PCI_DMA_FROMDEVICE); 720 DMA_FROM_DEVICE);
372 721
373 rx_desc = E1000_RX_DESC(*rx_ring, i); 722 rx_desc = E1000_RX_DESC(*rx_ring, i);
374 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); 723 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
@@ -442,10 +791,10 @@ static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
442 791
443 cleaned = 1; 792 cleaned = 1;
444 cleaned_count++; 793 cleaned_count++;
445 pci_unmap_single(pdev, 794 dma_unmap_single(&pdev->dev,
446 buffer_info->dma, 795 buffer_info->dma,
447 adapter->rx_buffer_len, 796 adapter->rx_buffer_len,
448 PCI_DMA_FROMDEVICE); 797 DMA_FROM_DEVICE);
449 buffer_info->dma = 0; 798 buffer_info->dma = 0;
450 799
451 length = le16_to_cpu(rx_desc->length); 800 length = le16_to_cpu(rx_desc->length);
@@ -546,12 +895,11 @@ static void e1000_put_txbuf(struct e1000_adapter *adapter,
546{ 895{
547 if (buffer_info->dma) { 896 if (buffer_info->dma) {
548 if (buffer_info->mapped_as_page) 897 if (buffer_info->mapped_as_page)
549 pci_unmap_page(adapter->pdev, buffer_info->dma, 898 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
550 buffer_info->length, PCI_DMA_TODEVICE); 899 buffer_info->length, DMA_TO_DEVICE);
551 else 900 else
552 pci_unmap_single(adapter->pdev, buffer_info->dma, 901 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
553 buffer_info->length, 902 buffer_info->length, DMA_TO_DEVICE);
554 PCI_DMA_TODEVICE);
555 buffer_info->dma = 0; 903 buffer_info->dma = 0;
556 } 904 }
557 if (buffer_info->skb) { 905 if (buffer_info->skb) {
@@ -642,14 +990,8 @@ static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
642 cleaned = (i == eop); 990 cleaned = (i == eop);
643 991
644 if (cleaned) { 992 if (cleaned) {
645 struct sk_buff *skb = buffer_info->skb; 993 total_tx_packets += buffer_info->segs;
646 unsigned int segs, bytecount; 994 total_tx_bytes += buffer_info->bytecount;
647 segs = skb_shinfo(skb)->gso_segs ?: 1;
648 /* multiply data chunks by size of headers */
649 bytecount = ((segs - 1) * skb_headlen(skb)) +
650 skb->len;
651 total_tx_packets += segs;
652 total_tx_bytes += bytecount;
653 } 995 }
654 996
655 e1000_put_txbuf(adapter, buffer_info); 997 e1000_put_txbuf(adapter, buffer_info);
@@ -660,6 +1002,8 @@ static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
660 i = 0; 1002 i = 0;
661 } 1003 }
662 1004
1005 if (i == tx_ring->next_to_use)
1006 break;
663 eop = tx_ring->buffer_info[i].next_to_watch; 1007 eop = tx_ring->buffer_info[i].next_to_watch;
664 eop_desc = E1000_TX_DESC(*tx_ring, eop); 1008 eop_desc = E1000_TX_DESC(*tx_ring, eop);
665 } 1009 }
@@ -750,9 +1094,9 @@ static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
750 1094
751 cleaned = 1; 1095 cleaned = 1;
752 cleaned_count++; 1096 cleaned_count++;
753 pci_unmap_single(pdev, buffer_info->dma, 1097 dma_unmap_single(&pdev->dev, buffer_info->dma,
754 adapter->rx_ps_bsize0, 1098 adapter->rx_ps_bsize0,
755 PCI_DMA_FROMDEVICE); 1099 DMA_FROM_DEVICE);
756 buffer_info->dma = 0; 1100 buffer_info->dma = 0;
757 1101
758 /* see !EOP comment in other rx routine */ 1102 /* see !EOP comment in other rx routine */
@@ -808,13 +1152,13 @@ static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
808 * kmap_atomic, so we can't hold the mapping 1152 * kmap_atomic, so we can't hold the mapping
809 * very long 1153 * very long
810 */ 1154 */
811 pci_dma_sync_single_for_cpu(pdev, ps_page->dma, 1155 dma_sync_single_for_cpu(&pdev->dev, ps_page->dma,
812 PAGE_SIZE, PCI_DMA_FROMDEVICE); 1156 PAGE_SIZE, DMA_FROM_DEVICE);
813 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ); 1157 vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ);
814 memcpy(skb_tail_pointer(skb), vaddr, l1); 1158 memcpy(skb_tail_pointer(skb), vaddr, l1);
815 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); 1159 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
816 pci_dma_sync_single_for_device(pdev, ps_page->dma, 1160 dma_sync_single_for_device(&pdev->dev, ps_page->dma,
817 PAGE_SIZE, PCI_DMA_FROMDEVICE); 1161 PAGE_SIZE, DMA_FROM_DEVICE);
818 1162
819 /* remove the CRC */ 1163 /* remove the CRC */
820 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) 1164 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING))
@@ -831,8 +1175,8 @@ static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
831 break; 1175 break;
832 1176
833 ps_page = &buffer_info->ps_pages[j]; 1177 ps_page = &buffer_info->ps_pages[j];
834 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE, 1178 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
835 PCI_DMA_FROMDEVICE); 1179 DMA_FROM_DEVICE);
836 ps_page->dma = 0; 1180 ps_page->dma = 0;
837 skb_fill_page_desc(skb, j, ps_page->page, 0, length); 1181 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
838 ps_page->page = NULL; 1182 ps_page->page = NULL;
@@ -950,8 +1294,8 @@ static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
950 1294
951 cleaned = true; 1295 cleaned = true;
952 cleaned_count++; 1296 cleaned_count++;
953 pci_unmap_page(pdev, buffer_info->dma, PAGE_SIZE, 1297 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
954 PCI_DMA_FROMDEVICE); 1298 DMA_FROM_DEVICE);
955 buffer_info->dma = 0; 1299 buffer_info->dma = 0;
956 1300
957 length = le16_to_cpu(rx_desc->length); 1301 length = le16_to_cpu(rx_desc->length);
@@ -1087,17 +1431,17 @@ static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1087 buffer_info = &rx_ring->buffer_info[i]; 1431 buffer_info = &rx_ring->buffer_info[i];
1088 if (buffer_info->dma) { 1432 if (buffer_info->dma) {
1089 if (adapter->clean_rx == e1000_clean_rx_irq) 1433 if (adapter->clean_rx == e1000_clean_rx_irq)
1090 pci_unmap_single(pdev, buffer_info->dma, 1434 dma_unmap_single(&pdev->dev, buffer_info->dma,
1091 adapter->rx_buffer_len, 1435 adapter->rx_buffer_len,
1092 PCI_DMA_FROMDEVICE); 1436 DMA_FROM_DEVICE);
1093 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) 1437 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
1094 pci_unmap_page(pdev, buffer_info->dma, 1438 dma_unmap_page(&pdev->dev, buffer_info->dma,
1095 PAGE_SIZE, 1439 PAGE_SIZE,
1096 PCI_DMA_FROMDEVICE); 1440 DMA_FROM_DEVICE);
1097 else if (adapter->clean_rx == e1000_clean_rx_irq_ps) 1441 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
1098 pci_unmap_single(pdev, buffer_info->dma, 1442 dma_unmap_single(&pdev->dev, buffer_info->dma,
1099 adapter->rx_ps_bsize0, 1443 adapter->rx_ps_bsize0,
1100 PCI_DMA_FROMDEVICE); 1444 DMA_FROM_DEVICE);
1101 buffer_info->dma = 0; 1445 buffer_info->dma = 0;
1102 } 1446 }
1103 1447
@@ -1115,8 +1459,8 @@ static void e1000_clean_rx_ring(struct e1000_adapter *adapter)
1115 ps_page = &buffer_info->ps_pages[j]; 1459 ps_page = &buffer_info->ps_pages[j];
1116 if (!ps_page->page) 1460 if (!ps_page->page)
1117 break; 1461 break;
1118 pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE, 1462 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1119 PCI_DMA_FROMDEVICE); 1463 DMA_FROM_DEVICE);
1120 ps_page->dma = 0; 1464 ps_page->dma = 0;
1121 put_page(ps_page->page); 1465 put_page(ps_page->page);
1122 ps_page->page = NULL; 1466 ps_page->page = NULL;
@@ -2289,8 +2633,6 @@ static void e1000_configure_tx(struct e1000_adapter *adapter)
2289 ew32(TCTL, tctl); 2633 ew32(TCTL, tctl);
2290 2634
2291 e1000e_config_collision_dist(hw); 2635 e1000e_config_collision_dist(hw);
2292
2293 adapter->tx_queue_len = adapter->netdev->tx_queue_len;
2294} 2636}
2295 2637
2296/** 2638/**
@@ -2564,7 +2906,7 @@ static void e1000_set_multi(struct net_device *netdev)
2564{ 2906{
2565 struct e1000_adapter *adapter = netdev_priv(netdev); 2907 struct e1000_adapter *adapter = netdev_priv(netdev);
2566 struct e1000_hw *hw = &adapter->hw; 2908 struct e1000_hw *hw = &adapter->hw;
2567 struct dev_mc_list *mc_ptr; 2909 struct netdev_hw_addr *ha;
2568 u8 *mta_list; 2910 u8 *mta_list;
2569 u32 rctl; 2911 u32 rctl;
2570 int i; 2912 int i;
@@ -2596,9 +2938,8 @@ static void e1000_set_multi(struct net_device *netdev)
2596 2938
2597 /* prepare a packed array of only addresses. */ 2939 /* prepare a packed array of only addresses. */
2598 i = 0; 2940 i = 0;
2599 netdev_for_each_mc_addr(mc_ptr, netdev) 2941 netdev_for_each_mc_addr(ha, netdev)
2600 memcpy(mta_list + (i++ * ETH_ALEN), 2942 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
2601 mc_ptr->dmi_addr, ETH_ALEN);
2602 2943
2603 e1000_update_mc_addr_list(hw, mta_list, i); 2944 e1000_update_mc_addr_list(hw, mta_list, i);
2604 kfree(mta_list); 2945 kfree(mta_list);
@@ -2877,7 +3218,6 @@ void e1000e_down(struct e1000_adapter *adapter)
2877 del_timer_sync(&adapter->watchdog_timer); 3218 del_timer_sync(&adapter->watchdog_timer);
2878 del_timer_sync(&adapter->phy_info_timer); 3219 del_timer_sync(&adapter->phy_info_timer);
2879 3220
2880 netdev->tx_queue_len = adapter->tx_queue_len;
2881 netif_carrier_off(netdev); 3221 netif_carrier_off(netdev);
2882 adapter->link_speed = 0; 3222 adapter->link_speed = 0;
2883 adapter->link_duplex = 0; 3223 adapter->link_duplex = 0;
@@ -3083,12 +3423,15 @@ static int e1000_open(struct net_device *netdev)
3083{ 3423{
3084 struct e1000_adapter *adapter = netdev_priv(netdev); 3424 struct e1000_adapter *adapter = netdev_priv(netdev);
3085 struct e1000_hw *hw = &adapter->hw; 3425 struct e1000_hw *hw = &adapter->hw;
3426 struct pci_dev *pdev = adapter->pdev;
3086 int err; 3427 int err;
3087 3428
3088 /* disallow open during test */ 3429 /* disallow open during test */
3089 if (test_bit(__E1000_TESTING, &adapter->state)) 3430 if (test_bit(__E1000_TESTING, &adapter->state))
3090 return -EBUSY; 3431 return -EBUSY;
3091 3432
3433 pm_runtime_get_sync(&pdev->dev);
3434
3092 netif_carrier_off(netdev); 3435 netif_carrier_off(netdev);
3093 3436
3094 /* allocate transmit descriptors */ 3437 /* allocate transmit descriptors */
@@ -3149,6 +3492,9 @@ static int e1000_open(struct net_device *netdev)
3149 3492
3150 netif_start_queue(netdev); 3493 netif_start_queue(netdev);
3151 3494
3495 adapter->idle_check = true;
3496 pm_runtime_put(&pdev->dev);
3497
3152 /* fire a link status change interrupt to start the watchdog */ 3498 /* fire a link status change interrupt to start the watchdog */
3153 ew32(ICS, E1000_ICS_LSC); 3499 ew32(ICS, E1000_ICS_LSC);
3154 3500
@@ -3162,6 +3508,7 @@ err_setup_rx:
3162 e1000e_free_tx_resources(adapter); 3508 e1000e_free_tx_resources(adapter);
3163err_setup_tx: 3509err_setup_tx:
3164 e1000e_reset(adapter); 3510 e1000e_reset(adapter);
3511 pm_runtime_put_sync(&pdev->dev);
3165 3512
3166 return err; 3513 return err;
3167} 3514}
@@ -3180,11 +3527,17 @@ err_setup_tx:
3180static int e1000_close(struct net_device *netdev) 3527static int e1000_close(struct net_device *netdev)
3181{ 3528{
3182 struct e1000_adapter *adapter = netdev_priv(netdev); 3529 struct e1000_adapter *adapter = netdev_priv(netdev);
3530 struct pci_dev *pdev = adapter->pdev;
3183 3531
3184 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); 3532 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3185 e1000e_down(adapter); 3533
3534 pm_runtime_get_sync(&pdev->dev);
3535
3536 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3537 e1000e_down(adapter);
3538 e1000_free_irq(adapter);
3539 }
3186 e1000_power_down_phy(adapter); 3540 e1000_power_down_phy(adapter);
3187 e1000_free_irq(adapter);
3188 3541
3189 e1000e_free_tx_resources(adapter); 3542 e1000e_free_tx_resources(adapter);
3190 e1000e_free_rx_resources(adapter); 3543 e1000e_free_rx_resources(adapter);
@@ -3206,6 +3559,8 @@ static int e1000_close(struct net_device *netdev)
3206 if (adapter->flags & FLAG_HAS_AMT) 3559 if (adapter->flags & FLAG_HAS_AMT)
3207 e1000_release_hw_control(adapter); 3560 e1000_release_hw_control(adapter);
3208 3561
3562 pm_runtime_put_sync(&pdev->dev);
3563
3209 return 0; 3564 return 0;
3210} 3565}
3211/** 3566/**
@@ -3550,6 +3905,9 @@ static void e1000_watchdog_task(struct work_struct *work)
3550 3905
3551 link = e1000e_has_link(adapter); 3906 link = e1000e_has_link(adapter);
3552 if ((netif_carrier_ok(netdev)) && link) { 3907 if ((netif_carrier_ok(netdev)) && link) {
3908 /* Cancel scheduled suspend requests. */
3909 pm_runtime_resume(netdev->dev.parent);
3910
3553 e1000e_enable_receives(adapter); 3911 e1000e_enable_receives(adapter);
3554 goto link_up; 3912 goto link_up;
3555 } 3913 }
@@ -3561,6 +3919,10 @@ static void e1000_watchdog_task(struct work_struct *work)
3561 if (link) { 3919 if (link) {
3562 if (!netif_carrier_ok(netdev)) { 3920 if (!netif_carrier_ok(netdev)) {
3563 bool txb2b = 1; 3921 bool txb2b = 1;
3922
3923 /* Cancel scheduled suspend requests. */
3924 pm_runtime_resume(netdev->dev.parent);
3925
3564 /* update snapshot of PHY registers on LSC */ 3926 /* update snapshot of PHY registers on LSC */
3565 e1000_phy_read_status(adapter); 3927 e1000_phy_read_status(adapter);
3566 mac->ops.get_link_up_info(&adapter->hw, 3928 mac->ops.get_link_up_info(&adapter->hw,
@@ -3588,21 +3950,15 @@ static void e1000_watchdog_task(struct work_struct *work)
3588 "link gets many collisions.\n"); 3950 "link gets many collisions.\n");
3589 } 3951 }
3590 3952
3591 /* 3953 /* adjust timeout factor according to speed/duplex */
3592 * tweak tx_queue_len according to speed/duplex
3593 * and adjust the timeout factor
3594 */
3595 netdev->tx_queue_len = adapter->tx_queue_len;
3596 adapter->tx_timeout_factor = 1; 3954 adapter->tx_timeout_factor = 1;
3597 switch (adapter->link_speed) { 3955 switch (adapter->link_speed) {
3598 case SPEED_10: 3956 case SPEED_10:
3599 txb2b = 0; 3957 txb2b = 0;
3600 netdev->tx_queue_len = 10;
3601 adapter->tx_timeout_factor = 16; 3958 adapter->tx_timeout_factor = 16;
3602 break; 3959 break;
3603 case SPEED_100: 3960 case SPEED_100:
3604 txb2b = 0; 3961 txb2b = 0;
3605 netdev->tx_queue_len = 100;
3606 adapter->tx_timeout_factor = 10; 3962 adapter->tx_timeout_factor = 10;
3607 break; 3963 break;
3608 } 3964 }
@@ -3676,6 +4032,9 @@ static void e1000_watchdog_task(struct work_struct *work)
3676 4032
3677 if (adapter->flags & FLAG_RX_NEEDS_RESTART) 4033 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
3678 schedule_work(&adapter->reset_task); 4034 schedule_work(&adapter->reset_task);
4035 else
4036 pm_schedule_suspend(netdev->dev.parent,
4037 LINK_TIMEOUT);
3679 } 4038 }
3680 } 4039 }
3681 4040
@@ -3711,6 +4070,22 @@ link_up:
3711 } 4070 }
3712 } 4071 }
3713 4072
4073 /* Simple mode for Interrupt Throttle Rate (ITR) */
4074 if (adapter->itr_setting == 4) {
4075 /*
4076 * Symmetric Tx/Rx gets a reduced ITR=2000;
4077 * Total asymmetrical Tx or Rx gets ITR=8000;
4078 * everyone else is between 2000-8000.
4079 */
4080 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4081 u32 dif = (adapter->gotc > adapter->gorc ?
4082 adapter->gotc - adapter->gorc :
4083 adapter->gorc - adapter->gotc) / 10000;
4084 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4085
4086 ew32(ITR, 1000000000 / (itr * 256));
4087 }
4088
3714 /* Cause software interrupt to ensure Rx ring is cleaned */ 4089 /* Cause software interrupt to ensure Rx ring is cleaned */
3715 if (adapter->msix_entries) 4090 if (adapter->msix_entries)
3716 ew32(ICS, adapter->rx_ring->ims_val); 4091 ew32(ICS, adapter->rx_ring->ims_val);
@@ -3885,7 +4260,7 @@ static int e1000_tx_map(struct e1000_adapter *adapter,
3885 struct e1000_buffer *buffer_info; 4260 struct e1000_buffer *buffer_info;
3886 unsigned int len = skb_headlen(skb); 4261 unsigned int len = skb_headlen(skb);
3887 unsigned int offset = 0, size, count = 0, i; 4262 unsigned int offset = 0, size, count = 0, i;
3888 unsigned int f; 4263 unsigned int f, bytecount, segs;
3889 4264
3890 i = tx_ring->next_to_use; 4265 i = tx_ring->next_to_use;
3891 4266
@@ -3896,10 +4271,11 @@ static int e1000_tx_map(struct e1000_adapter *adapter,
3896 buffer_info->length = size; 4271 buffer_info->length = size;
3897 buffer_info->time_stamp = jiffies; 4272 buffer_info->time_stamp = jiffies;
3898 buffer_info->next_to_watch = i; 4273 buffer_info->next_to_watch = i;
3899 buffer_info->dma = pci_map_single(pdev, skb->data + offset, 4274 buffer_info->dma = dma_map_single(&pdev->dev,
3900 size, PCI_DMA_TODEVICE); 4275 skb->data + offset,
4276 size, DMA_TO_DEVICE);
3901 buffer_info->mapped_as_page = false; 4277 buffer_info->mapped_as_page = false;
3902 if (pci_dma_mapping_error(pdev, buffer_info->dma)) 4278 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
3903 goto dma_error; 4279 goto dma_error;
3904 4280
3905 len -= size; 4281 len -= size;
@@ -3931,11 +4307,11 @@ static int e1000_tx_map(struct e1000_adapter *adapter,
3931 buffer_info->length = size; 4307 buffer_info->length = size;
3932 buffer_info->time_stamp = jiffies; 4308 buffer_info->time_stamp = jiffies;
3933 buffer_info->next_to_watch = i; 4309 buffer_info->next_to_watch = i;
3934 buffer_info->dma = pci_map_page(pdev, frag->page, 4310 buffer_info->dma = dma_map_page(&pdev->dev, frag->page,
3935 offset, size, 4311 offset, size,
3936 PCI_DMA_TODEVICE); 4312 DMA_TO_DEVICE);
3937 buffer_info->mapped_as_page = true; 4313 buffer_info->mapped_as_page = true;
3938 if (pci_dma_mapping_error(pdev, buffer_info->dma)) 4314 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
3939 goto dma_error; 4315 goto dma_error;
3940 4316
3941 len -= size; 4317 len -= size;
@@ -3944,7 +4320,13 @@ static int e1000_tx_map(struct e1000_adapter *adapter,
3944 } 4320 }
3945 } 4321 }
3946 4322
4323 segs = skb_shinfo(skb)->gso_segs ?: 1;
4324 /* multiply data chunks by size of headers */
4325 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4326
3947 tx_ring->buffer_info[i].skb = skb; 4327 tx_ring->buffer_info[i].skb = skb;
4328 tx_ring->buffer_info[i].segs = segs;
4329 tx_ring->buffer_info[i].bytecount = bytecount;
3948 tx_ring->buffer_info[first].next_to_watch = i; 4330 tx_ring->buffer_info[first].next_to_watch = i;
3949 4331
3950 return count; 4332 return count;
@@ -4111,7 +4493,7 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4111 unsigned int max_per_txd = E1000_MAX_PER_TXD; 4493 unsigned int max_per_txd = E1000_MAX_PER_TXD;
4112 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; 4494 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
4113 unsigned int tx_flags = 0; 4495 unsigned int tx_flags = 0;
4114 unsigned int len = skb->len - skb->data_len; 4496 unsigned int len = skb_headlen(skb);
4115 unsigned int nr_frags; 4497 unsigned int nr_frags;
4116 unsigned int mss; 4498 unsigned int mss;
4117 int count = 0; 4499 int count = 0;
@@ -4161,7 +4543,7 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4161 dev_kfree_skb_any(skb); 4543 dev_kfree_skb_any(skb);
4162 return NETDEV_TX_OK; 4544 return NETDEV_TX_OK;
4163 } 4545 }
4164 len = skb->len - skb->data_len; 4546 len = skb_headlen(skb);
4165 } 4547 }
4166 } 4548 }
4167 4549
@@ -4247,6 +4629,8 @@ static void e1000_reset_task(struct work_struct *work)
4247 struct e1000_adapter *adapter; 4629 struct e1000_adapter *adapter;
4248 adapter = container_of(work, struct e1000_adapter, reset_task); 4630 adapter = container_of(work, struct e1000_adapter, reset_task);
4249 4631
4632 e1000e_dump(adapter);
4633 e_err("Reset adapter\n");
4250 e1000e_reinit_locked(adapter); 4634 e1000e_reinit_locked(adapter);
4251} 4635}
4252 4636
@@ -4289,6 +4673,14 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4289 return -EINVAL; 4673 return -EINVAL;
4290 } 4674 }
4291 4675
4676 /* 82573 Errata 17 */
4677 if (((adapter->hw.mac.type == e1000_82573) ||
4678 (adapter->hw.mac.type == e1000_82574)) &&
4679 (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) {
4680 adapter->flags2 |= FLAG2_DISABLE_ASPM_L1;
4681 e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1);
4682 }
4683
4292 while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) 4684 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
4293 msleep(1); 4685 msleep(1);
4294 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ 4686 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
@@ -4473,13 +4865,15 @@ out:
4473 return retval; 4865 return retval;
4474} 4866}
4475 4867
4476static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake) 4868static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
4869 bool runtime)
4477{ 4870{
4478 struct net_device *netdev = pci_get_drvdata(pdev); 4871 struct net_device *netdev = pci_get_drvdata(pdev);
4479 struct e1000_adapter *adapter = netdev_priv(netdev); 4872 struct e1000_adapter *adapter = netdev_priv(netdev);
4480 struct e1000_hw *hw = &adapter->hw; 4873 struct e1000_hw *hw = &adapter->hw;
4481 u32 ctrl, ctrl_ext, rctl, status; 4874 u32 ctrl, ctrl_ext, rctl, status;
4482 u32 wufc = adapter->wol; 4875 /* Runtime suspend should only enable wakeup for link changes */
4876 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
4483 int retval = 0; 4877 int retval = 0;
4484 4878
4485 netif_device_detach(netdev); 4879 netif_device_detach(netdev);
@@ -4611,45 +5005,51 @@ static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
4611 } 5005 }
4612} 5006}
4613 5007
4614static void e1000e_disable_l1aspm(struct pci_dev *pdev) 5008#ifdef CONFIG_PCIEASPM
5009static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5010{
5011 pci_disable_link_state(pdev, state);
5012}
5013#else
5014static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
4615{ 5015{
4616 int pos; 5016 int pos;
4617 u16 val; 5017 u16 reg16;
4618 5018
4619 /* 5019 /*
4620 * 82573 workaround - disable L1 ASPM on mobile chipsets 5020 * Both device and parent should have the same ASPM setting.
4621 * 5021 * Disable ASPM in downstream component first and then upstream.
4622 * L1 ASPM on various mobile (ich7) chipsets do not behave properly
4623 * resulting in lost data or garbage information on the pci-e link
4624 * level. This could result in (false) bad EEPROM checksum errors,
4625 * long ping times (up to 2s) or even a system freeze/hang.
4626 *
4627 * Unfortunately this feature saves about 1W power consumption when
4628 * active.
4629 */ 5022 */
4630 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); 5023 pos = pci_pcie_cap(pdev);
4631 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val); 5024 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
4632 if (val & 0x2) { 5025 reg16 &= ~state;
4633 dev_warn(&pdev->dev, "Disabling L1 ASPM\n"); 5026 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
4634 val &= ~0x2;
4635 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val);
4636 }
4637}
4638 5027
4639#ifdef CONFIG_PM 5028 if (!pdev->bus->self)
4640static int e1000_suspend(struct pci_dev *pdev, pm_message_t state) 5029 return;
5030
5031 pos = pci_pcie_cap(pdev->bus->self);
5032 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16);
5033 reg16 &= ~state;
5034 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5035}
5036#endif
5037void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
4641{ 5038{
4642 int retval; 5039 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
4643 bool wake; 5040 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5041 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
4644 5042
4645 retval = __e1000_shutdown(pdev, &wake); 5043 __e1000e_disable_aspm(pdev, state);
4646 if (!retval) 5044}
4647 e1000_complete_shutdown(pdev, true, wake);
4648 5045
4649 return retval; 5046#ifdef CONFIG_PM_OPS
5047static bool e1000e_pm_ready(struct e1000_adapter *adapter)
5048{
5049 return !!adapter->tx_ring->buffer_info;
4650} 5050}
4651 5051
4652static int e1000_resume(struct pci_dev *pdev) 5052static int __e1000_resume(struct pci_dev *pdev)
4653{ 5053{
4654 struct net_device *netdev = pci_get_drvdata(pdev); 5054 struct net_device *netdev = pci_get_drvdata(pdev);
4655 struct e1000_adapter *adapter = netdev_priv(netdev); 5055 struct e1000_adapter *adapter = netdev_priv(netdev);
@@ -4659,19 +5059,8 @@ static int e1000_resume(struct pci_dev *pdev)
4659 pci_set_power_state(pdev, PCI_D0); 5059 pci_set_power_state(pdev, PCI_D0);
4660 pci_restore_state(pdev); 5060 pci_restore_state(pdev);
4661 pci_save_state(pdev); 5061 pci_save_state(pdev);
4662 e1000e_disable_l1aspm(pdev); 5062 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
4663 5063 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
4664 err = pci_enable_device_mem(pdev);
4665 if (err) {
4666 dev_err(&pdev->dev,
4667 "Cannot enable PCI device from suspend\n");
4668 return err;
4669 }
4670
4671 pci_set_master(pdev);
4672
4673 pci_enable_wake(pdev, PCI_D3hot, 0);
4674 pci_enable_wake(pdev, PCI_D3cold, 0);
4675 5064
4676 e1000e_set_interrupt_capability(adapter); 5065 e1000e_set_interrupt_capability(adapter);
4677 if (netif_running(netdev)) { 5066 if (netif_running(netdev)) {
@@ -4730,13 +5119,88 @@ static int e1000_resume(struct pci_dev *pdev)
4730 5119
4731 return 0; 5120 return 0;
4732} 5121}
4733#endif 5122
5123#ifdef CONFIG_PM_SLEEP
5124static int e1000_suspend(struct device *dev)
5125{
5126 struct pci_dev *pdev = to_pci_dev(dev);
5127 int retval;
5128 bool wake;
5129
5130 retval = __e1000_shutdown(pdev, &wake, false);
5131 if (!retval)
5132 e1000_complete_shutdown(pdev, true, wake);
5133
5134 return retval;
5135}
5136
5137static int e1000_resume(struct device *dev)
5138{
5139 struct pci_dev *pdev = to_pci_dev(dev);
5140 struct net_device *netdev = pci_get_drvdata(pdev);
5141 struct e1000_adapter *adapter = netdev_priv(netdev);
5142
5143 if (e1000e_pm_ready(adapter))
5144 adapter->idle_check = true;
5145
5146 return __e1000_resume(pdev);
5147}
5148#endif /* CONFIG_PM_SLEEP */
5149
5150#ifdef CONFIG_PM_RUNTIME
5151static int e1000_runtime_suspend(struct device *dev)
5152{
5153 struct pci_dev *pdev = to_pci_dev(dev);
5154 struct net_device *netdev = pci_get_drvdata(pdev);
5155 struct e1000_adapter *adapter = netdev_priv(netdev);
5156
5157 if (e1000e_pm_ready(adapter)) {
5158 bool wake;
5159
5160 __e1000_shutdown(pdev, &wake, true);
5161 }
5162
5163 return 0;
5164}
5165
5166static int e1000_idle(struct device *dev)
5167{
5168 struct pci_dev *pdev = to_pci_dev(dev);
5169 struct net_device *netdev = pci_get_drvdata(pdev);
5170 struct e1000_adapter *adapter = netdev_priv(netdev);
5171
5172 if (!e1000e_pm_ready(adapter))
5173 return 0;
5174
5175 if (adapter->idle_check) {
5176 adapter->idle_check = false;
5177 if (!e1000e_has_link(adapter))
5178 pm_schedule_suspend(dev, MSEC_PER_SEC);
5179 }
5180
5181 return -EBUSY;
5182}
5183
5184static int e1000_runtime_resume(struct device *dev)
5185{
5186 struct pci_dev *pdev = to_pci_dev(dev);
5187 struct net_device *netdev = pci_get_drvdata(pdev);
5188 struct e1000_adapter *adapter = netdev_priv(netdev);
5189
5190 if (!e1000e_pm_ready(adapter))
5191 return 0;
5192
5193 adapter->idle_check = !dev->power.runtime_auto;
5194 return __e1000_resume(pdev);
5195}
5196#endif /* CONFIG_PM_RUNTIME */
5197#endif /* CONFIG_PM_OPS */
4734 5198
4735static void e1000_shutdown(struct pci_dev *pdev) 5199static void e1000_shutdown(struct pci_dev *pdev)
4736{ 5200{
4737 bool wake = false; 5201 bool wake = false;
4738 5202
4739 __e1000_shutdown(pdev, &wake); 5203 __e1000_shutdown(pdev, &wake, false);
4740 5204
4741 if (system_state == SYSTEM_POWER_OFF) 5205 if (system_state == SYSTEM_POWER_OFF)
4742 e1000_complete_shutdown(pdev, false, wake); 5206 e1000_complete_shutdown(pdev, false, wake);
@@ -4801,7 +5265,8 @@ static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4801 int err; 5265 int err;
4802 pci_ers_result_t result; 5266 pci_ers_result_t result;
4803 5267
4804 e1000e_disable_l1aspm(pdev); 5268 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5269 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
4805 err = pci_enable_device_mem(pdev); 5270 err = pci_enable_device_mem(pdev);
4806 if (err) { 5271 if (err) {
4807 dev_err(&pdev->dev, 5272 dev_err(&pdev->dev,
@@ -4809,8 +5274,8 @@ static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4809 result = PCI_ERS_RESULT_DISCONNECT; 5274 result = PCI_ERS_RESULT_DISCONNECT;
4810 } else { 5275 } else {
4811 pci_set_master(pdev); 5276 pci_set_master(pdev);
5277 pdev->state_saved = true;
4812 pci_restore_state(pdev); 5278 pci_restore_state(pdev);
4813 pci_save_state(pdev);
4814 5279
4815 pci_enable_wake(pdev, PCI_D3hot, 0); 5280 pci_enable_wake(pdev, PCI_D3hot, 0);
4816 pci_enable_wake(pdev, PCI_D3cold, 0); 5281 pci_enable_wake(pdev, PCI_D3cold, 0);
@@ -4895,13 +5360,6 @@ static void e1000_eeprom_checks(struct e1000_adapter *adapter)
4895 dev_warn(&adapter->pdev->dev, 5360 dev_warn(&adapter->pdev->dev,
4896 "Warning: detected DSPD enabled in EEPROM\n"); 5361 "Warning: detected DSPD enabled in EEPROM\n");
4897 } 5362 }
4898
4899 ret_val = e1000_read_nvm(hw, NVM_INIT_3GIO_3, 1, &buf);
4900 if (!ret_val && (le16_to_cpu(buf) & (3 << 2))) {
4901 /* ASPM enable */
4902 dev_warn(&adapter->pdev->dev,
4903 "Warning: detected ASPM enabled in EEPROM\n");
4904 }
4905} 5363}
4906 5364
4907static const struct net_device_ops e1000e_netdev_ops = { 5365static const struct net_device_ops e1000e_netdev_ops = {
@@ -4950,23 +5408,24 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
4950 u16 eeprom_data = 0; 5408 u16 eeprom_data = 0;
4951 u16 eeprom_apme_mask = E1000_EEPROM_APME; 5409 u16 eeprom_apme_mask = E1000_EEPROM_APME;
4952 5410
4953 e1000e_disable_l1aspm(pdev); 5411 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
5412 e1000e_disable_aspm(pdev, PCIE_LINK_STATE_L1);
4954 5413
4955 err = pci_enable_device_mem(pdev); 5414 err = pci_enable_device_mem(pdev);
4956 if (err) 5415 if (err)
4957 return err; 5416 return err;
4958 5417
4959 pci_using_dac = 0; 5418 pci_using_dac = 0;
4960 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); 5419 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
4961 if (!err) { 5420 if (!err) {
4962 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); 5421 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
4963 if (!err) 5422 if (!err)
4964 pci_using_dac = 1; 5423 pci_using_dac = 1;
4965 } else { 5424 } else {
4966 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 5425 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
4967 if (err) { 5426 if (err) {
4968 err = pci_set_consistent_dma_mask(pdev, 5427 err = dma_set_coherent_mask(&pdev->dev,
4969 DMA_BIT_MASK(32)); 5428 DMA_BIT_MASK(32));
4970 if (err) { 5429 if (err) {
4971 dev_err(&pdev->dev, "No usable DMA " 5430 dev_err(&pdev->dev, "No usable DMA "
4972 "configuration, aborting\n"); 5431 "configuration, aborting\n");
@@ -4997,6 +5456,8 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
4997 5456
4998 SET_NETDEV_DEV(netdev, &pdev->dev); 5457 SET_NETDEV_DEV(netdev, &pdev->dev);
4999 5458
5459 netdev->irq = pdev->irq;
5460
5000 pci_set_drvdata(pdev, netdev); 5461 pci_set_drvdata(pdev, netdev);
5001 adapter = netdev_priv(netdev); 5462 adapter = netdev_priv(netdev);
5002 hw = &adapter->hw; 5463 hw = &adapter->hw;
@@ -5217,6 +5678,12 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
5217 5678
5218 e1000_print_device_info(adapter); 5679 e1000_print_device_info(adapter);
5219 5680
5681 if (pci_dev_run_wake(pdev)) {
5682 pm_runtime_set_active(&pdev->dev);
5683 pm_runtime_enable(&pdev->dev);
5684 }
5685 pm_schedule_suspend(&pdev->dev, MSEC_PER_SEC);
5686
5220 return 0; 5687 return 0;
5221 5688
5222err_register: 5689err_register:
@@ -5259,12 +5726,16 @@ static void __devexit e1000_remove(struct pci_dev *pdev)
5259{ 5726{
5260 struct net_device *netdev = pci_get_drvdata(pdev); 5727 struct net_device *netdev = pci_get_drvdata(pdev);
5261 struct e1000_adapter *adapter = netdev_priv(netdev); 5728 struct e1000_adapter *adapter = netdev_priv(netdev);
5729 bool down = test_bit(__E1000_DOWN, &adapter->state);
5730
5731 pm_runtime_get_sync(&pdev->dev);
5262 5732
5263 /* 5733 /*
5264 * flush_scheduled work may reschedule our watchdog task, so 5734 * flush_scheduled work may reschedule our watchdog task, so
5265 * explicitly disable watchdog tasks from being rescheduled 5735 * explicitly disable watchdog tasks from being rescheduled
5266 */ 5736 */
5267 set_bit(__E1000_DOWN, &adapter->state); 5737 if (!down)
5738 set_bit(__E1000_DOWN, &adapter->state);
5268 del_timer_sync(&adapter->watchdog_timer); 5739 del_timer_sync(&adapter->watchdog_timer);
5269 del_timer_sync(&adapter->phy_info_timer); 5740 del_timer_sync(&adapter->phy_info_timer);
5270 5741
@@ -5278,8 +5749,17 @@ static void __devexit e1000_remove(struct pci_dev *pdev)
5278 if (!(netdev->flags & IFF_UP)) 5749 if (!(netdev->flags & IFF_UP))
5279 e1000_power_down_phy(adapter); 5750 e1000_power_down_phy(adapter);
5280 5751
5752 /* Don't lie to e1000_close() down the road. */
5753 if (!down)
5754 clear_bit(__E1000_DOWN, &adapter->state);
5281 unregister_netdev(netdev); 5755 unregister_netdev(netdev);
5282 5756
5757 if (pci_dev_run_wake(pdev)) {
5758 pm_runtime_disable(&pdev->dev);
5759 pm_runtime_set_suspended(&pdev->dev);
5760 }
5761 pm_runtime_put_noidle(&pdev->dev);
5762
5283 /* 5763 /*
5284 * Release control of h/w to f/w. If f/w is AMT enabled, this 5764 * Release control of h/w to f/w. If f/w is AMT enabled, this
5285 * would have already happened in close and is redundant. 5765 * would have already happened in close and is redundant.
@@ -5379,16 +5859,22 @@ static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
5379}; 5859};
5380MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); 5860MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
5381 5861
5862#ifdef CONFIG_PM_OPS
5863static const struct dev_pm_ops e1000_pm_ops = {
5864 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
5865 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
5866 e1000_runtime_resume, e1000_idle)
5867};
5868#endif
5869
5382/* PCI Device API Driver */ 5870/* PCI Device API Driver */
5383static struct pci_driver e1000_driver = { 5871static struct pci_driver e1000_driver = {
5384 .name = e1000e_driver_name, 5872 .name = e1000e_driver_name,
5385 .id_table = e1000_pci_tbl, 5873 .id_table = e1000_pci_tbl,
5386 .probe = e1000_probe, 5874 .probe = e1000_probe,
5387 .remove = __devexit_p(e1000_remove), 5875 .remove = __devexit_p(e1000_remove),
5388#ifdef CONFIG_PM 5876#ifdef CONFIG_PM_OPS
5389 /* Power Management Hooks */ 5877 .driver.pm = &e1000_pm_ops,
5390 .suspend = e1000_suspend,
5391 .resume = e1000_resume,
5392#endif 5878#endif
5393 .shutdown = e1000_shutdown, 5879 .shutdown = e1000_shutdown,
5394 .err_handler = &e1000_err_handler 5880 .err_handler = &e1000_err_handler
@@ -5403,10 +5889,9 @@ static struct pci_driver e1000_driver = {
5403static int __init e1000_init_module(void) 5889static int __init e1000_init_module(void)
5404{ 5890{
5405 int ret; 5891 int ret;
5406 printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n", 5892 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
5407 e1000e_driver_name, e1000e_driver_version); 5893 e1000e_driver_version);
5408 printk(KERN_INFO "%s: Copyright (c) 1999 - 2009 Intel Corporation.\n", 5894 pr_info("Copyright (c) 1999 - 2009 Intel Corporation.\n");
5409 e1000e_driver_name);
5410 ret = pci_register_driver(&e1000_driver); 5895 ret = pci_register_driver(&e1000_driver);
5411 5896
5412 return ret; 5897 return ret;