Commit | Line | Data |
---|---|---|
bc7f75fa AK |
1 | /******************************************************************************* |
2 | ||
3 | Intel PRO/1000 Linux driver | |
4 | Copyright(c) 1999 - 2007 Intel Corporation. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify it | |
7 | under the terms and conditions of the GNU General Public License, | |
8 | version 2, as published by the Free Software Foundation. | |
9 | ||
10 | This program is distributed in the hope it will be useful, but WITHOUT | |
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License along with | |
16 | this program; if not, write to the Free Software Foundation, Inc., | |
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | ||
19 | The full GNU General Public License is included in this distribution in | |
20 | the file called "COPYING". | |
21 | ||
22 | Contact Information: | |
23 | Linux NICS <linux.nics@intel.com> | |
24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | |
25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
26 | ||
27 | *******************************************************************************/ | |
28 | ||
29 | #include <linux/module.h> | |
30 | #include <linux/types.h> | |
31 | #include <linux/init.h> | |
32 | #include <linux/pci.h> | |
33 | #include <linux/vmalloc.h> | |
34 | #include <linux/pagemap.h> | |
35 | #include <linux/delay.h> | |
36 | #include <linux/netdevice.h> | |
37 | #include <linux/tcp.h> | |
38 | #include <linux/ipv6.h> | |
39 | #include <net/checksum.h> | |
40 | #include <net/ip6_checksum.h> | |
41 | #include <linux/mii.h> | |
42 | #include <linux/ethtool.h> | |
43 | #include <linux/if_vlan.h> | |
44 | #include <linux/cpu.h> | |
45 | #include <linux/smp.h> | |
46 | ||
47 | #include "e1000.h" | |
48 | ||
49 | #define DRV_VERSION "0.2.0" | |
50 | char e1000e_driver_name[] = "e1000e"; | |
51 | const char e1000e_driver_version[] = DRV_VERSION; | |
52 | ||
53 | static const struct e1000_info *e1000_info_tbl[] = { | |
54 | [board_82571] = &e1000_82571_info, | |
55 | [board_82572] = &e1000_82572_info, | |
56 | [board_82573] = &e1000_82573_info, | |
57 | [board_80003es2lan] = &e1000_es2_info, | |
58 | [board_ich8lan] = &e1000_ich8_info, | |
59 | [board_ich9lan] = &e1000_ich9_info, | |
60 | }; | |
61 | ||
62 | #ifdef DEBUG | |
63 | /** | |
64 | * e1000_get_hw_dev_name - return device name string | |
65 | * used by hardware layer to print debugging information | |
66 | **/ | |
67 | char *e1000e_get_hw_dev_name(struct e1000_hw *hw) | |
68 | { | |
589c085f | 69 | return hw->adapter->netdev->name; |
bc7f75fa AK |
70 | } |
71 | #endif | |
72 | ||
73 | /** | |
74 | * e1000_desc_unused - calculate if we have unused descriptors | |
75 | **/ | |
76 | static int e1000_desc_unused(struct e1000_ring *ring) | |
77 | { | |
78 | if (ring->next_to_clean > ring->next_to_use) | |
79 | return ring->next_to_clean - ring->next_to_use - 1; | |
80 | ||
81 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; | |
82 | } | |
83 | ||
84 | /** | |
85 | * e1000_receive_skb - helper function to handle rx indications | |
86 | * @adapter: board private structure | |
87 | * @status: descriptor status field as written by hardware | |
88 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) | |
89 | * @skb: pointer to sk_buff to be indicated to stack | |
90 | **/ | |
91 | static void e1000_receive_skb(struct e1000_adapter *adapter, | |
92 | struct net_device *netdev, | |
93 | struct sk_buff *skb, | |
a39fe742 | 94 | u8 status, __le16 vlan) |
bc7f75fa AK |
95 | { |
96 | skb->protocol = eth_type_trans(skb, netdev); | |
97 | ||
98 | if (adapter->vlgrp && (status & E1000_RXD_STAT_VP)) | |
99 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, | |
100 | le16_to_cpu(vlan) & | |
101 | E1000_RXD_SPC_VLAN_MASK); | |
102 | else | |
103 | netif_receive_skb(skb); | |
104 | ||
105 | netdev->last_rx = jiffies; | |
106 | } | |
107 | ||
108 | /** | |
109 | * e1000_rx_checksum - Receive Checksum Offload for 82543 | |
110 | * @adapter: board private structure | |
111 | * @status_err: receive descriptor status and error fields | |
112 | * @csum: receive descriptor csum field | |
113 | * @sk_buff: socket buffer with received data | |
114 | **/ | |
115 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, | |
116 | u32 csum, struct sk_buff *skb) | |
117 | { | |
118 | u16 status = (u16)status_err; | |
119 | u8 errors = (u8)(status_err >> 24); | |
120 | skb->ip_summed = CHECKSUM_NONE; | |
121 | ||
122 | /* Ignore Checksum bit is set */ | |
123 | if (status & E1000_RXD_STAT_IXSM) | |
124 | return; | |
125 | /* TCP/UDP checksum error bit is set */ | |
126 | if (errors & E1000_RXD_ERR_TCPE) { | |
127 | /* let the stack verify checksum errors */ | |
128 | adapter->hw_csum_err++; | |
129 | return; | |
130 | } | |
131 | ||
132 | /* TCP/UDP Checksum has not been calculated */ | |
133 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) | |
134 | return; | |
135 | ||
136 | /* It must be a TCP or UDP packet with a valid checksum */ | |
137 | if (status & E1000_RXD_STAT_TCPCS) { | |
138 | /* TCP checksum is good */ | |
139 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
140 | } else { | |
141 | /* IP fragment with UDP payload */ | |
142 | /* Hardware complements the payload checksum, so we undo it | |
143 | * and then put the value in host order for further stack use. | |
144 | */ | |
a39fe742 AV |
145 | __sum16 sum = (__force __sum16)htons(csum); |
146 | skb->csum = csum_unfold(~sum); | |
bc7f75fa AK |
147 | skb->ip_summed = CHECKSUM_COMPLETE; |
148 | } | |
149 | adapter->hw_csum_good++; | |
150 | } | |
151 | ||
152 | /** | |
153 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended | |
154 | * @adapter: address of board private structure | |
155 | **/ | |
156 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, | |
157 | int cleaned_count) | |
158 | { | |
159 | struct net_device *netdev = adapter->netdev; | |
160 | struct pci_dev *pdev = adapter->pdev; | |
161 | struct e1000_ring *rx_ring = adapter->rx_ring; | |
162 | struct e1000_rx_desc *rx_desc; | |
163 | struct e1000_buffer *buffer_info; | |
164 | struct sk_buff *skb; | |
165 | unsigned int i; | |
166 | unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN; | |
167 | ||
168 | i = rx_ring->next_to_use; | |
169 | buffer_info = &rx_ring->buffer_info[i]; | |
170 | ||
171 | while (cleaned_count--) { | |
172 | skb = buffer_info->skb; | |
173 | if (skb) { | |
174 | skb_trim(skb, 0); | |
175 | goto map_skb; | |
176 | } | |
177 | ||
178 | skb = netdev_alloc_skb(netdev, bufsz); | |
179 | if (!skb) { | |
180 | /* Better luck next round */ | |
181 | adapter->alloc_rx_buff_failed++; | |
182 | break; | |
183 | } | |
184 | ||
185 | /* Make buffer alignment 2 beyond a 16 byte boundary | |
186 | * this will result in a 16 byte aligned IP header after | |
187 | * the 14 byte MAC header is removed | |
188 | */ | |
189 | skb_reserve(skb, NET_IP_ALIGN); | |
190 | ||
191 | buffer_info->skb = skb; | |
192 | map_skb: | |
193 | buffer_info->dma = pci_map_single(pdev, skb->data, | |
194 | adapter->rx_buffer_len, | |
195 | PCI_DMA_FROMDEVICE); | |
196 | if (pci_dma_mapping_error(buffer_info->dma)) { | |
197 | dev_err(&pdev->dev, "RX DMA map failed\n"); | |
198 | adapter->rx_dma_failed++; | |
199 | break; | |
200 | } | |
201 | ||
202 | rx_desc = E1000_RX_DESC(*rx_ring, i); | |
203 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); | |
204 | ||
205 | i++; | |
206 | if (i == rx_ring->count) | |
207 | i = 0; | |
208 | buffer_info = &rx_ring->buffer_info[i]; | |
209 | } | |
210 | ||
211 | if (rx_ring->next_to_use != i) { | |
212 | rx_ring->next_to_use = i; | |
213 | if (i-- == 0) | |
214 | i = (rx_ring->count - 1); | |
215 | ||
216 | /* Force memory writes to complete before letting h/w | |
217 | * know there are new descriptors to fetch. (Only | |
218 | * applicable for weak-ordered memory model archs, | |
219 | * such as IA-64). */ | |
220 | wmb(); | |
221 | writel(i, adapter->hw.hw_addr + rx_ring->tail); | |
222 | } | |
223 | } | |
224 | ||
225 | /** | |
226 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split | |
227 | * @adapter: address of board private structure | |
228 | **/ | |
229 | static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, | |
230 | int cleaned_count) | |
231 | { | |
232 | struct net_device *netdev = adapter->netdev; | |
233 | struct pci_dev *pdev = adapter->pdev; | |
234 | union e1000_rx_desc_packet_split *rx_desc; | |
235 | struct e1000_ring *rx_ring = adapter->rx_ring; | |
236 | struct e1000_buffer *buffer_info; | |
237 | struct e1000_ps_page *ps_page; | |
238 | struct sk_buff *skb; | |
239 | unsigned int i, j; | |
240 | ||
241 | i = rx_ring->next_to_use; | |
242 | buffer_info = &rx_ring->buffer_info[i]; | |
243 | ||
244 | while (cleaned_count--) { | |
245 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); | |
246 | ||
247 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { | |
47f44e40 AK |
248 | ps_page = &buffer_info->ps_pages[j]; |
249 | if (j >= adapter->rx_ps_pages) { | |
250 | /* all unused desc entries get hw null ptr */ | |
a39fe742 | 251 | rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0); |
47f44e40 AK |
252 | continue; |
253 | } | |
254 | if (!ps_page->page) { | |
255 | ps_page->page = alloc_page(GFP_ATOMIC); | |
bc7f75fa | 256 | if (!ps_page->page) { |
47f44e40 AK |
257 | adapter->alloc_rx_buff_failed++; |
258 | goto no_buffers; | |
259 | } | |
260 | ps_page->dma = pci_map_page(pdev, | |
261 | ps_page->page, | |
262 | 0, PAGE_SIZE, | |
263 | PCI_DMA_FROMDEVICE); | |
264 | if (pci_dma_mapping_error(ps_page->dma)) { | |
265 | dev_err(&adapter->pdev->dev, | |
266 | "RX DMA page map failed\n"); | |
267 | adapter->rx_dma_failed++; | |
268 | goto no_buffers; | |
bc7f75fa | 269 | } |
bc7f75fa | 270 | } |
47f44e40 AK |
271 | /* |
272 | * Refresh the desc even if buffer_addrs | |
273 | * didn't change because each write-back | |
274 | * erases this info. | |
275 | */ | |
276 | rx_desc->read.buffer_addr[j+1] = | |
277 | cpu_to_le64(ps_page->dma); | |
bc7f75fa AK |
278 | } |
279 | ||
280 | skb = netdev_alloc_skb(netdev, | |
281 | adapter->rx_ps_bsize0 + NET_IP_ALIGN); | |
282 | ||
283 | if (!skb) { | |
284 | adapter->alloc_rx_buff_failed++; | |
285 | break; | |
286 | } | |
287 | ||
288 | /* Make buffer alignment 2 beyond a 16 byte boundary | |
289 | * this will result in a 16 byte aligned IP header after | |
290 | * the 14 byte MAC header is removed | |
291 | */ | |
292 | skb_reserve(skb, NET_IP_ALIGN); | |
293 | ||
294 | buffer_info->skb = skb; | |
295 | buffer_info->dma = pci_map_single(pdev, skb->data, | |
296 | adapter->rx_ps_bsize0, | |
297 | PCI_DMA_FROMDEVICE); | |
298 | if (pci_dma_mapping_error(buffer_info->dma)) { | |
299 | dev_err(&pdev->dev, "RX DMA map failed\n"); | |
300 | adapter->rx_dma_failed++; | |
301 | /* cleanup skb */ | |
302 | dev_kfree_skb_any(skb); | |
303 | buffer_info->skb = NULL; | |
304 | break; | |
305 | } | |
306 | ||
307 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); | |
308 | ||
309 | i++; | |
310 | if (i == rx_ring->count) | |
311 | i = 0; | |
312 | buffer_info = &rx_ring->buffer_info[i]; | |
313 | } | |
314 | ||
315 | no_buffers: | |
316 | if (rx_ring->next_to_use != i) { | |
317 | rx_ring->next_to_use = i; | |
318 | ||
319 | if (!(i--)) | |
320 | i = (rx_ring->count - 1); | |
321 | ||
322 | /* Force memory writes to complete before letting h/w | |
323 | * know there are new descriptors to fetch. (Only | |
324 | * applicable for weak-ordered memory model archs, | |
325 | * such as IA-64). */ | |
326 | wmb(); | |
327 | /* Hardware increments by 16 bytes, but packet split | |
328 | * descriptors are 32 bytes...so we increment tail | |
329 | * twice as much. | |
330 | */ | |
331 | writel(i<<1, adapter->hw.hw_addr + rx_ring->tail); | |
332 | } | |
333 | } | |
334 | ||
bc7f75fa AK |
335 | /** |
336 | * e1000_clean_rx_irq - Send received data up the network stack; legacy | |
337 | * @adapter: board private structure | |
338 | * | |
339 | * the return value indicates whether actual cleaning was done, there | |
340 | * is no guarantee that everything was cleaned | |
341 | **/ | |
342 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, | |
343 | int *work_done, int work_to_do) | |
344 | { | |
345 | struct net_device *netdev = adapter->netdev; | |
346 | struct pci_dev *pdev = adapter->pdev; | |
347 | struct e1000_ring *rx_ring = adapter->rx_ring; | |
348 | struct e1000_rx_desc *rx_desc, *next_rxd; | |
349 | struct e1000_buffer *buffer_info, *next_buffer; | |
350 | u32 length; | |
351 | unsigned int i; | |
352 | int cleaned_count = 0; | |
353 | bool cleaned = 0; | |
354 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; | |
355 | ||
356 | i = rx_ring->next_to_clean; | |
357 | rx_desc = E1000_RX_DESC(*rx_ring, i); | |
358 | buffer_info = &rx_ring->buffer_info[i]; | |
359 | ||
360 | while (rx_desc->status & E1000_RXD_STAT_DD) { | |
361 | struct sk_buff *skb; | |
362 | u8 status; | |
363 | ||
364 | if (*work_done >= work_to_do) | |
365 | break; | |
366 | (*work_done)++; | |
367 | ||
368 | status = rx_desc->status; | |
369 | skb = buffer_info->skb; | |
370 | buffer_info->skb = NULL; | |
371 | ||
372 | prefetch(skb->data - NET_IP_ALIGN); | |
373 | ||
374 | i++; | |
375 | if (i == rx_ring->count) | |
376 | i = 0; | |
377 | next_rxd = E1000_RX_DESC(*rx_ring, i); | |
378 | prefetch(next_rxd); | |
379 | ||
380 | next_buffer = &rx_ring->buffer_info[i]; | |
381 | ||
382 | cleaned = 1; | |
383 | cleaned_count++; | |
384 | pci_unmap_single(pdev, | |
385 | buffer_info->dma, | |
386 | adapter->rx_buffer_len, | |
387 | PCI_DMA_FROMDEVICE); | |
388 | buffer_info->dma = 0; | |
389 | ||
390 | length = le16_to_cpu(rx_desc->length); | |
391 | ||
392 | /* !EOP means multiple descriptors were used to store a single | |
393 | * packet, also make sure the frame isn't just CRC only */ | |
394 | if (!(status & E1000_RXD_STAT_EOP) || (length <= 4)) { | |
395 | /* All receives must fit into a single buffer */ | |
396 | ndev_dbg(netdev, "%s: Receive packet consumed " | |
397 | "multiple buffers\n", netdev->name); | |
398 | /* recycle */ | |
399 | buffer_info->skb = skb; | |
400 | goto next_desc; | |
401 | } | |
402 | ||
403 | if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) { | |
404 | /* recycle */ | |
405 | buffer_info->skb = skb; | |
406 | goto next_desc; | |
407 | } | |
408 | ||
bc7f75fa AK |
409 | total_rx_bytes += length; |
410 | total_rx_packets++; | |
411 | ||
412 | /* code added for copybreak, this should improve | |
413 | * performance for small packets with large amounts | |
414 | * of reassembly being done in the stack */ | |
415 | if (length < copybreak) { | |
416 | struct sk_buff *new_skb = | |
417 | netdev_alloc_skb(netdev, length + NET_IP_ALIGN); | |
418 | if (new_skb) { | |
419 | skb_reserve(new_skb, NET_IP_ALIGN); | |
420 | memcpy(new_skb->data - NET_IP_ALIGN, | |
421 | skb->data - NET_IP_ALIGN, | |
422 | length + NET_IP_ALIGN); | |
423 | /* save the skb in buffer_info as good */ | |
424 | buffer_info->skb = skb; | |
425 | skb = new_skb; | |
426 | } | |
427 | /* else just continue with the old one */ | |
428 | } | |
429 | /* end copybreak code */ | |
430 | skb_put(skb, length); | |
431 | ||
432 | /* Receive Checksum Offload */ | |
433 | e1000_rx_checksum(adapter, | |
434 | (u32)(status) | | |
435 | ((u32)(rx_desc->errors) << 24), | |
436 | le16_to_cpu(rx_desc->csum), skb); | |
437 | ||
438 | e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special); | |
439 | ||
440 | next_desc: | |
441 | rx_desc->status = 0; | |
442 | ||
443 | /* return some buffers to hardware, one at a time is too slow */ | |
444 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { | |
445 | adapter->alloc_rx_buf(adapter, cleaned_count); | |
446 | cleaned_count = 0; | |
447 | } | |
448 | ||
449 | /* use prefetched values */ | |
450 | rx_desc = next_rxd; | |
451 | buffer_info = next_buffer; | |
452 | } | |
453 | rx_ring->next_to_clean = i; | |
454 | ||
455 | cleaned_count = e1000_desc_unused(rx_ring); | |
456 | if (cleaned_count) | |
457 | adapter->alloc_rx_buf(adapter, cleaned_count); | |
458 | ||
459 | adapter->total_rx_packets += total_rx_packets; | |
460 | adapter->total_rx_bytes += total_rx_bytes; | |
41988692 AK |
461 | adapter->net_stats.rx_packets += total_rx_packets; |
462 | adapter->net_stats.rx_bytes += total_rx_bytes; | |
bc7f75fa AK |
463 | return cleaned; |
464 | } | |
465 | ||
bc7f75fa AK |
466 | static void e1000_put_txbuf(struct e1000_adapter *adapter, |
467 | struct e1000_buffer *buffer_info) | |
468 | { | |
469 | if (buffer_info->dma) { | |
470 | pci_unmap_page(adapter->pdev, buffer_info->dma, | |
471 | buffer_info->length, PCI_DMA_TODEVICE); | |
472 | buffer_info->dma = 0; | |
473 | } | |
474 | if (buffer_info->skb) { | |
475 | dev_kfree_skb_any(buffer_info->skb); | |
476 | buffer_info->skb = NULL; | |
477 | } | |
478 | } | |
479 | ||
480 | static void e1000_print_tx_hang(struct e1000_adapter *adapter) | |
481 | { | |
482 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
483 | unsigned int i = tx_ring->next_to_clean; | |
484 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; | |
485 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); | |
486 | struct net_device *netdev = adapter->netdev; | |
487 | ||
488 | /* detected Tx unit hang */ | |
489 | ndev_err(netdev, | |
490 | "Detected Tx Unit Hang:\n" | |
491 | " TDH <%x>\n" | |
492 | " TDT <%x>\n" | |
493 | " next_to_use <%x>\n" | |
494 | " next_to_clean <%x>\n" | |
495 | "buffer_info[next_to_clean]:\n" | |
496 | " time_stamp <%lx>\n" | |
497 | " next_to_watch <%x>\n" | |
498 | " jiffies <%lx>\n" | |
499 | " next_to_watch.status <%x>\n", | |
500 | readl(adapter->hw.hw_addr + tx_ring->head), | |
501 | readl(adapter->hw.hw_addr + tx_ring->tail), | |
502 | tx_ring->next_to_use, | |
503 | tx_ring->next_to_clean, | |
504 | tx_ring->buffer_info[eop].time_stamp, | |
505 | eop, | |
506 | jiffies, | |
507 | eop_desc->upper.fields.status); | |
508 | } | |
509 | ||
510 | /** | |
511 | * e1000_clean_tx_irq - Reclaim resources after transmit completes | |
512 | * @adapter: board private structure | |
513 | * | |
514 | * the return value indicates whether actual cleaning was done, there | |
515 | * is no guarantee that everything was cleaned | |
516 | **/ | |
517 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter) | |
518 | { | |
519 | struct net_device *netdev = adapter->netdev; | |
520 | struct e1000_hw *hw = &adapter->hw; | |
521 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
522 | struct e1000_tx_desc *tx_desc, *eop_desc; | |
523 | struct e1000_buffer *buffer_info; | |
524 | unsigned int i, eop; | |
525 | unsigned int count = 0; | |
526 | bool cleaned = 0; | |
527 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; | |
528 | ||
529 | i = tx_ring->next_to_clean; | |
530 | eop = tx_ring->buffer_info[i].next_to_watch; | |
531 | eop_desc = E1000_TX_DESC(*tx_ring, eop); | |
532 | ||
533 | while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) { | |
534 | for (cleaned = 0; !cleaned; ) { | |
535 | tx_desc = E1000_TX_DESC(*tx_ring, i); | |
536 | buffer_info = &tx_ring->buffer_info[i]; | |
537 | cleaned = (i == eop); | |
538 | ||
539 | if (cleaned) { | |
540 | struct sk_buff *skb = buffer_info->skb; | |
541 | unsigned int segs, bytecount; | |
542 | segs = skb_shinfo(skb)->gso_segs ?: 1; | |
543 | /* multiply data chunks by size of headers */ | |
544 | bytecount = ((segs - 1) * skb_headlen(skb)) + | |
545 | skb->len; | |
546 | total_tx_packets += segs; | |
547 | total_tx_bytes += bytecount; | |
548 | } | |
549 | ||
550 | e1000_put_txbuf(adapter, buffer_info); | |
551 | tx_desc->upper.data = 0; | |
552 | ||
553 | i++; | |
554 | if (i == tx_ring->count) | |
555 | i = 0; | |
556 | } | |
557 | ||
558 | eop = tx_ring->buffer_info[i].next_to_watch; | |
559 | eop_desc = E1000_TX_DESC(*tx_ring, eop); | |
560 | #define E1000_TX_WEIGHT 64 | |
561 | /* weight of a sort for tx, to avoid endless transmit cleanup */ | |
562 | if (count++ == E1000_TX_WEIGHT) | |
563 | break; | |
564 | } | |
565 | ||
566 | tx_ring->next_to_clean = i; | |
567 | ||
568 | #define TX_WAKE_THRESHOLD 32 | |
569 | if (cleaned && netif_carrier_ok(netdev) && | |
570 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { | |
571 | /* Make sure that anybody stopping the queue after this | |
572 | * sees the new next_to_clean. | |
573 | */ | |
574 | smp_mb(); | |
575 | ||
576 | if (netif_queue_stopped(netdev) && | |
577 | !(test_bit(__E1000_DOWN, &adapter->state))) { | |
578 | netif_wake_queue(netdev); | |
579 | ++adapter->restart_queue; | |
580 | } | |
581 | } | |
582 | ||
583 | if (adapter->detect_tx_hung) { | |
584 | /* Detect a transmit hang in hardware, this serializes the | |
585 | * check with the clearing of time_stamp and movement of i */ | |
586 | adapter->detect_tx_hung = 0; | |
587 | if (tx_ring->buffer_info[eop].dma && | |
588 | time_after(jiffies, tx_ring->buffer_info[eop].time_stamp | |
589 | + (adapter->tx_timeout_factor * HZ)) | |
590 | && !(er32(STATUS) & | |
591 | E1000_STATUS_TXOFF)) { | |
592 | e1000_print_tx_hang(adapter); | |
593 | netif_stop_queue(netdev); | |
594 | } | |
595 | } | |
596 | adapter->total_tx_bytes += total_tx_bytes; | |
597 | adapter->total_tx_packets += total_tx_packets; | |
41988692 AK |
598 | adapter->net_stats.tx_packets += total_tx_packets; |
599 | adapter->net_stats.tx_bytes += total_tx_bytes; | |
bc7f75fa AK |
600 | return cleaned; |
601 | } | |
602 | ||
bc7f75fa AK |
603 | /** |
604 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split | |
605 | * @adapter: board private structure | |
606 | * | |
607 | * the return value indicates whether actual cleaning was done, there | |
608 | * is no guarantee that everything was cleaned | |
609 | **/ | |
610 | static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, | |
611 | int *work_done, int work_to_do) | |
612 | { | |
613 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; | |
614 | struct net_device *netdev = adapter->netdev; | |
615 | struct pci_dev *pdev = adapter->pdev; | |
616 | struct e1000_ring *rx_ring = adapter->rx_ring; | |
617 | struct e1000_buffer *buffer_info, *next_buffer; | |
618 | struct e1000_ps_page *ps_page; | |
619 | struct sk_buff *skb; | |
620 | unsigned int i, j; | |
621 | u32 length, staterr; | |
622 | int cleaned_count = 0; | |
623 | bool cleaned = 0; | |
624 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; | |
625 | ||
626 | i = rx_ring->next_to_clean; | |
627 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); | |
628 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); | |
629 | buffer_info = &rx_ring->buffer_info[i]; | |
630 | ||
631 | while (staterr & E1000_RXD_STAT_DD) { | |
632 | if (*work_done >= work_to_do) | |
633 | break; | |
634 | (*work_done)++; | |
635 | skb = buffer_info->skb; | |
636 | ||
637 | /* in the packet split case this is header only */ | |
638 | prefetch(skb->data - NET_IP_ALIGN); | |
639 | ||
640 | i++; | |
641 | if (i == rx_ring->count) | |
642 | i = 0; | |
643 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); | |
644 | prefetch(next_rxd); | |
645 | ||
646 | next_buffer = &rx_ring->buffer_info[i]; | |
647 | ||
648 | cleaned = 1; | |
649 | cleaned_count++; | |
650 | pci_unmap_single(pdev, buffer_info->dma, | |
651 | adapter->rx_ps_bsize0, | |
652 | PCI_DMA_FROMDEVICE); | |
653 | buffer_info->dma = 0; | |
654 | ||
655 | if (!(staterr & E1000_RXD_STAT_EOP)) { | |
656 | ndev_dbg(netdev, "%s: Packet Split buffers didn't pick " | |
657 | "up the full packet\n", netdev->name); | |
658 | dev_kfree_skb_irq(skb); | |
659 | goto next_desc; | |
660 | } | |
661 | ||
662 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { | |
663 | dev_kfree_skb_irq(skb); | |
664 | goto next_desc; | |
665 | } | |
666 | ||
667 | length = le16_to_cpu(rx_desc->wb.middle.length0); | |
668 | ||
669 | if (!length) { | |
670 | ndev_dbg(netdev, "%s: Last part of the packet spanning" | |
671 | " multiple descriptors\n", netdev->name); | |
672 | dev_kfree_skb_irq(skb); | |
673 | goto next_desc; | |
674 | } | |
675 | ||
676 | /* Good Receive */ | |
677 | skb_put(skb, length); | |
678 | ||
679 | { | |
680 | /* this looks ugly, but it seems compiler issues make it | |
681 | more efficient than reusing j */ | |
682 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); | |
683 | ||
684 | /* page alloc/put takes too long and effects small packet | |
685 | * throughput, so unsplit small packets and save the alloc/put*/ | |
686 | if (l1 && (l1 <= copybreak) && | |
687 | ((length + l1) <= adapter->rx_ps_bsize0)) { | |
688 | u8 *vaddr; | |
689 | ||
47f44e40 | 690 | ps_page = &buffer_info->ps_pages[0]; |
bc7f75fa AK |
691 | |
692 | /* there is no documentation about how to call | |
693 | * kmap_atomic, so we can't hold the mapping | |
694 | * very long */ | |
695 | pci_dma_sync_single_for_cpu(pdev, ps_page->dma, | |
696 | PAGE_SIZE, PCI_DMA_FROMDEVICE); | |
697 | vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ); | |
698 | memcpy(skb_tail_pointer(skb), vaddr, l1); | |
699 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); | |
700 | pci_dma_sync_single_for_device(pdev, ps_page->dma, | |
701 | PAGE_SIZE, PCI_DMA_FROMDEVICE); | |
140a7480 | 702 | |
bc7f75fa AK |
703 | skb_put(skb, l1); |
704 | goto copydone; | |
705 | } /* if */ | |
706 | } | |
707 | ||
708 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { | |
709 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); | |
710 | if (!length) | |
711 | break; | |
712 | ||
47f44e40 | 713 | ps_page = &buffer_info->ps_pages[j]; |
bc7f75fa AK |
714 | pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE, |
715 | PCI_DMA_FROMDEVICE); | |
716 | ps_page->dma = 0; | |
717 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); | |
718 | ps_page->page = NULL; | |
719 | skb->len += length; | |
720 | skb->data_len += length; | |
721 | skb->truesize += length; | |
722 | } | |
723 | ||
bc7f75fa AK |
724 | copydone: |
725 | total_rx_bytes += skb->len; | |
726 | total_rx_packets++; | |
727 | ||
728 | e1000_rx_checksum(adapter, staterr, le16_to_cpu( | |
729 | rx_desc->wb.lower.hi_dword.csum_ip.csum), skb); | |
730 | ||
731 | if (rx_desc->wb.upper.header_status & | |
732 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) | |
733 | adapter->rx_hdr_split++; | |
734 | ||
735 | e1000_receive_skb(adapter, netdev, skb, | |
736 | staterr, rx_desc->wb.middle.vlan); | |
737 | ||
738 | next_desc: | |
739 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); | |
740 | buffer_info->skb = NULL; | |
741 | ||
742 | /* return some buffers to hardware, one at a time is too slow */ | |
743 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { | |
744 | adapter->alloc_rx_buf(adapter, cleaned_count); | |
745 | cleaned_count = 0; | |
746 | } | |
747 | ||
748 | /* use prefetched values */ | |
749 | rx_desc = next_rxd; | |
750 | buffer_info = next_buffer; | |
751 | ||
752 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); | |
753 | } | |
754 | rx_ring->next_to_clean = i; | |
755 | ||
756 | cleaned_count = e1000_desc_unused(rx_ring); | |
757 | if (cleaned_count) | |
758 | adapter->alloc_rx_buf(adapter, cleaned_count); | |
759 | ||
760 | adapter->total_rx_packets += total_rx_packets; | |
761 | adapter->total_rx_bytes += total_rx_bytes; | |
41988692 AK |
762 | adapter->net_stats.rx_packets += total_rx_packets; |
763 | adapter->net_stats.rx_bytes += total_rx_bytes; | |
bc7f75fa AK |
764 | return cleaned; |
765 | } | |
766 | ||
767 | /** | |
768 | * e1000_clean_rx_ring - Free Rx Buffers per Queue | |
769 | * @adapter: board private structure | |
770 | **/ | |
771 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter) | |
772 | { | |
773 | struct e1000_ring *rx_ring = adapter->rx_ring; | |
774 | struct e1000_buffer *buffer_info; | |
775 | struct e1000_ps_page *ps_page; | |
776 | struct pci_dev *pdev = adapter->pdev; | |
bc7f75fa AK |
777 | unsigned int i, j; |
778 | ||
779 | /* Free all the Rx ring sk_buffs */ | |
780 | for (i = 0; i < rx_ring->count; i++) { | |
781 | buffer_info = &rx_ring->buffer_info[i]; | |
782 | if (buffer_info->dma) { | |
783 | if (adapter->clean_rx == e1000_clean_rx_irq) | |
784 | pci_unmap_single(pdev, buffer_info->dma, | |
785 | adapter->rx_buffer_len, | |
786 | PCI_DMA_FROMDEVICE); | |
bc7f75fa AK |
787 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
788 | pci_unmap_single(pdev, buffer_info->dma, | |
789 | adapter->rx_ps_bsize0, | |
790 | PCI_DMA_FROMDEVICE); | |
791 | buffer_info->dma = 0; | |
792 | } | |
793 | ||
bc7f75fa AK |
794 | if (buffer_info->skb) { |
795 | dev_kfree_skb(buffer_info->skb); | |
796 | buffer_info->skb = NULL; | |
797 | } | |
798 | ||
799 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { | |
47f44e40 | 800 | ps_page = &buffer_info->ps_pages[j]; |
bc7f75fa AK |
801 | if (!ps_page->page) |
802 | break; | |
803 | pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE, | |
804 | PCI_DMA_FROMDEVICE); | |
805 | ps_page->dma = 0; | |
806 | put_page(ps_page->page); | |
807 | ps_page->page = NULL; | |
808 | } | |
809 | } | |
810 | ||
811 | /* there also may be some cached data from a chained receive */ | |
812 | if (rx_ring->rx_skb_top) { | |
813 | dev_kfree_skb(rx_ring->rx_skb_top); | |
814 | rx_ring->rx_skb_top = NULL; | |
815 | } | |
816 | ||
bc7f75fa AK |
817 | /* Zero out the descriptor ring */ |
818 | memset(rx_ring->desc, 0, rx_ring->size); | |
819 | ||
820 | rx_ring->next_to_clean = 0; | |
821 | rx_ring->next_to_use = 0; | |
822 | ||
823 | writel(0, adapter->hw.hw_addr + rx_ring->head); | |
824 | writel(0, adapter->hw.hw_addr + rx_ring->tail); | |
825 | } | |
826 | ||
827 | /** | |
828 | * e1000_intr_msi - Interrupt Handler | |
829 | * @irq: interrupt number | |
830 | * @data: pointer to a network interface device structure | |
831 | **/ | |
832 | static irqreturn_t e1000_intr_msi(int irq, void *data) | |
833 | { | |
834 | struct net_device *netdev = data; | |
835 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
836 | struct e1000_hw *hw = &adapter->hw; | |
837 | u32 icr = er32(ICR); | |
838 | ||
74ef9c39 | 839 | /* read ICR disables interrupts using IAM */ |
bc7f75fa AK |
840 | |
841 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { | |
842 | hw->mac.get_link_status = 1; | |
843 | /* ICH8 workaround-- Call gig speed drop workaround on cable | |
844 | * disconnect (LSC) before accessing any PHY registers */ | |
845 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && | |
846 | (!(er32(STATUS) & E1000_STATUS_LU))) | |
847 | e1000e_gig_downshift_workaround_ich8lan(hw); | |
848 | ||
849 | /* 80003ES2LAN workaround-- For packet buffer work-around on | |
850 | * link down event; disable receives here in the ISR and reset | |
851 | * adapter in watchdog */ | |
852 | if (netif_carrier_ok(netdev) && | |
853 | adapter->flags & FLAG_RX_NEEDS_RESTART) { | |
854 | /* disable receives */ | |
855 | u32 rctl = er32(RCTL); | |
856 | ew32(RCTL, rctl & ~E1000_RCTL_EN); | |
857 | } | |
858 | /* guard against interrupt when we're going down */ | |
859 | if (!test_bit(__E1000_DOWN, &adapter->state)) | |
860 | mod_timer(&adapter->watchdog_timer, jiffies + 1); | |
861 | } | |
862 | ||
863 | if (netif_rx_schedule_prep(netdev, &adapter->napi)) { | |
864 | adapter->total_tx_bytes = 0; | |
865 | adapter->total_tx_packets = 0; | |
866 | adapter->total_rx_bytes = 0; | |
867 | adapter->total_rx_packets = 0; | |
868 | __netif_rx_schedule(netdev, &adapter->napi); | |
bc7f75fa AK |
869 | } |
870 | ||
871 | return IRQ_HANDLED; | |
872 | } | |
873 | ||
874 | /** | |
875 | * e1000_intr - Interrupt Handler | |
876 | * @irq: interrupt number | |
877 | * @data: pointer to a network interface device structure | |
878 | **/ | |
879 | static irqreturn_t e1000_intr(int irq, void *data) | |
880 | { | |
881 | struct net_device *netdev = data; | |
882 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
883 | struct e1000_hw *hw = &adapter->hw; | |
884 | ||
885 | u32 rctl, icr = er32(ICR); | |
886 | if (!icr) | |
887 | return IRQ_NONE; /* Not our interrupt */ | |
888 | ||
889 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is | |
890 | * not set, then the adapter didn't send an interrupt */ | |
891 | if (!(icr & E1000_ICR_INT_ASSERTED)) | |
892 | return IRQ_NONE; | |
893 | ||
74ef9c39 JB |
894 | /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No |
895 | * need for the IMC write */ | |
bc7f75fa AK |
896 | |
897 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { | |
898 | hw->mac.get_link_status = 1; | |
899 | /* ICH8 workaround-- Call gig speed drop workaround on cable | |
900 | * disconnect (LSC) before accessing any PHY registers */ | |
901 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && | |
902 | (!(er32(STATUS) & E1000_STATUS_LU))) | |
903 | e1000e_gig_downshift_workaround_ich8lan(hw); | |
904 | ||
905 | /* 80003ES2LAN workaround-- | |
906 | * For packet buffer work-around on link down event; | |
907 | * disable receives here in the ISR and | |
908 | * reset adapter in watchdog | |
909 | */ | |
910 | if (netif_carrier_ok(netdev) && | |
911 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { | |
912 | /* disable receives */ | |
913 | rctl = er32(RCTL); | |
914 | ew32(RCTL, rctl & ~E1000_RCTL_EN); | |
915 | } | |
916 | /* guard against interrupt when we're going down */ | |
917 | if (!test_bit(__E1000_DOWN, &adapter->state)) | |
918 | mod_timer(&adapter->watchdog_timer, jiffies + 1); | |
919 | } | |
920 | ||
921 | if (netif_rx_schedule_prep(netdev, &adapter->napi)) { | |
922 | adapter->total_tx_bytes = 0; | |
923 | adapter->total_tx_packets = 0; | |
924 | adapter->total_rx_bytes = 0; | |
925 | adapter->total_rx_packets = 0; | |
926 | __netif_rx_schedule(netdev, &adapter->napi); | |
bc7f75fa AK |
927 | } |
928 | ||
929 | return IRQ_HANDLED; | |
930 | } | |
931 | ||
932 | static int e1000_request_irq(struct e1000_adapter *adapter) | |
933 | { | |
934 | struct net_device *netdev = adapter->netdev; | |
a39fe742 | 935 | irq_handler_t handler = e1000_intr; |
bc7f75fa AK |
936 | int irq_flags = IRQF_SHARED; |
937 | int err; | |
938 | ||
9b71c5e0 | 939 | if (!pci_enable_msi(adapter->pdev)) { |
bc7f75fa | 940 | adapter->flags |= FLAG_MSI_ENABLED; |
a39fe742 | 941 | handler = e1000_intr_msi; |
bc7f75fa AK |
942 | irq_flags = 0; |
943 | } | |
944 | ||
945 | err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name, | |
946 | netdev); | |
947 | if (err) { | |
9b71c5e0 AG |
948 | ndev_err(netdev, |
949 | "Unable to allocate %s interrupt (return: %d)\n", | |
950 | adapter->flags & FLAG_MSI_ENABLED ? "MSI":"INTx", | |
951 | err); | |
bc7f75fa AK |
952 | if (adapter->flags & FLAG_MSI_ENABLED) |
953 | pci_disable_msi(adapter->pdev); | |
bc7f75fa AK |
954 | } |
955 | ||
956 | return err; | |
957 | } | |
958 | ||
959 | static void e1000_free_irq(struct e1000_adapter *adapter) | |
960 | { | |
961 | struct net_device *netdev = adapter->netdev; | |
962 | ||
963 | free_irq(adapter->pdev->irq, netdev); | |
964 | if (adapter->flags & FLAG_MSI_ENABLED) { | |
965 | pci_disable_msi(adapter->pdev); | |
966 | adapter->flags &= ~FLAG_MSI_ENABLED; | |
967 | } | |
968 | } | |
969 | ||
970 | /** | |
971 | * e1000_irq_disable - Mask off interrupt generation on the NIC | |
972 | **/ | |
973 | static void e1000_irq_disable(struct e1000_adapter *adapter) | |
974 | { | |
975 | struct e1000_hw *hw = &adapter->hw; | |
976 | ||
bc7f75fa AK |
977 | ew32(IMC, ~0); |
978 | e1e_flush(); | |
979 | synchronize_irq(adapter->pdev->irq); | |
980 | } | |
981 | ||
982 | /** | |
983 | * e1000_irq_enable - Enable default interrupt generation settings | |
984 | **/ | |
985 | static void e1000_irq_enable(struct e1000_adapter *adapter) | |
986 | { | |
987 | struct e1000_hw *hw = &adapter->hw; | |
988 | ||
74ef9c39 JB |
989 | ew32(IMS, IMS_ENABLE_MASK); |
990 | e1e_flush(); | |
bc7f75fa AK |
991 | } |
992 | ||
993 | /** | |
994 | * e1000_get_hw_control - get control of the h/w from f/w | |
995 | * @adapter: address of board private structure | |
996 | * | |
489815ce | 997 | * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
bc7f75fa AK |
998 | * For ASF and Pass Through versions of f/w this means that |
999 | * the driver is loaded. For AMT version (only with 82573) | |
1000 | * of the f/w this means that the network i/f is open. | |
1001 | **/ | |
1002 | static void e1000_get_hw_control(struct e1000_adapter *adapter) | |
1003 | { | |
1004 | struct e1000_hw *hw = &adapter->hw; | |
1005 | u32 ctrl_ext; | |
1006 | u32 swsm; | |
1007 | ||
1008 | /* Let firmware know the driver has taken over */ | |
1009 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { | |
1010 | swsm = er32(SWSM); | |
1011 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); | |
1012 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { | |
1013 | ctrl_ext = er32(CTRL_EXT); | |
1014 | ew32(CTRL_EXT, | |
1015 | ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); | |
1016 | } | |
1017 | } | |
1018 | ||
1019 | /** | |
1020 | * e1000_release_hw_control - release control of the h/w to f/w | |
1021 | * @adapter: address of board private structure | |
1022 | * | |
489815ce | 1023 | * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
bc7f75fa AK |
1024 | * For ASF and Pass Through versions of f/w this means that the |
1025 | * driver is no longer loaded. For AMT version (only with 82573) i | |
1026 | * of the f/w this means that the network i/f is closed. | |
1027 | * | |
1028 | **/ | |
1029 | static void e1000_release_hw_control(struct e1000_adapter *adapter) | |
1030 | { | |
1031 | struct e1000_hw *hw = &adapter->hw; | |
1032 | u32 ctrl_ext; | |
1033 | u32 swsm; | |
1034 | ||
1035 | /* Let firmware taken over control of h/w */ | |
1036 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { | |
1037 | swsm = er32(SWSM); | |
1038 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); | |
1039 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { | |
1040 | ctrl_ext = er32(CTRL_EXT); | |
1041 | ew32(CTRL_EXT, | |
1042 | ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); | |
1043 | } | |
1044 | } | |
1045 | ||
bc7f75fa AK |
1046 | /** |
1047 | * @e1000_alloc_ring - allocate memory for a ring structure | |
1048 | **/ | |
1049 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, | |
1050 | struct e1000_ring *ring) | |
1051 | { | |
1052 | struct pci_dev *pdev = adapter->pdev; | |
1053 | ||
1054 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, | |
1055 | GFP_KERNEL); | |
1056 | if (!ring->desc) | |
1057 | return -ENOMEM; | |
1058 | ||
1059 | return 0; | |
1060 | } | |
1061 | ||
1062 | /** | |
1063 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) | |
1064 | * @adapter: board private structure | |
1065 | * | |
1066 | * Return 0 on success, negative on failure | |
1067 | **/ | |
1068 | int e1000e_setup_tx_resources(struct e1000_adapter *adapter) | |
1069 | { | |
1070 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
1071 | int err = -ENOMEM, size; | |
1072 | ||
1073 | size = sizeof(struct e1000_buffer) * tx_ring->count; | |
1074 | tx_ring->buffer_info = vmalloc(size); | |
1075 | if (!tx_ring->buffer_info) | |
1076 | goto err; | |
1077 | memset(tx_ring->buffer_info, 0, size); | |
1078 | ||
1079 | /* round up to nearest 4K */ | |
1080 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); | |
1081 | tx_ring->size = ALIGN(tx_ring->size, 4096); | |
1082 | ||
1083 | err = e1000_alloc_ring_dma(adapter, tx_ring); | |
1084 | if (err) | |
1085 | goto err; | |
1086 | ||
1087 | tx_ring->next_to_use = 0; | |
1088 | tx_ring->next_to_clean = 0; | |
1089 | spin_lock_init(&adapter->tx_queue_lock); | |
1090 | ||
1091 | return 0; | |
1092 | err: | |
1093 | vfree(tx_ring->buffer_info); | |
1094 | ndev_err(adapter->netdev, | |
1095 | "Unable to allocate memory for the transmit descriptor ring\n"); | |
1096 | return err; | |
1097 | } | |
1098 | ||
1099 | /** | |
1100 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) | |
1101 | * @adapter: board private structure | |
1102 | * | |
1103 | * Returns 0 on success, negative on failure | |
1104 | **/ | |
1105 | int e1000e_setup_rx_resources(struct e1000_adapter *adapter) | |
1106 | { | |
1107 | struct e1000_ring *rx_ring = adapter->rx_ring; | |
47f44e40 AK |
1108 | struct e1000_buffer *buffer_info; |
1109 | int i, size, desc_len, err = -ENOMEM; | |
bc7f75fa AK |
1110 | |
1111 | size = sizeof(struct e1000_buffer) * rx_ring->count; | |
1112 | rx_ring->buffer_info = vmalloc(size); | |
1113 | if (!rx_ring->buffer_info) | |
1114 | goto err; | |
1115 | memset(rx_ring->buffer_info, 0, size); | |
1116 | ||
47f44e40 AK |
1117 | for (i = 0; i < rx_ring->count; i++) { |
1118 | buffer_info = &rx_ring->buffer_info[i]; | |
1119 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, | |
1120 | sizeof(struct e1000_ps_page), | |
1121 | GFP_KERNEL); | |
1122 | if (!buffer_info->ps_pages) | |
1123 | goto err_pages; | |
1124 | } | |
bc7f75fa AK |
1125 | |
1126 | desc_len = sizeof(union e1000_rx_desc_packet_split); | |
1127 | ||
1128 | /* Round up to nearest 4K */ | |
1129 | rx_ring->size = rx_ring->count * desc_len; | |
1130 | rx_ring->size = ALIGN(rx_ring->size, 4096); | |
1131 | ||
1132 | err = e1000_alloc_ring_dma(adapter, rx_ring); | |
1133 | if (err) | |
47f44e40 | 1134 | goto err_pages; |
bc7f75fa AK |
1135 | |
1136 | rx_ring->next_to_clean = 0; | |
1137 | rx_ring->next_to_use = 0; | |
1138 | rx_ring->rx_skb_top = NULL; | |
1139 | ||
1140 | return 0; | |
47f44e40 AK |
1141 | |
1142 | err_pages: | |
1143 | for (i = 0; i < rx_ring->count; i++) { | |
1144 | buffer_info = &rx_ring->buffer_info[i]; | |
1145 | kfree(buffer_info->ps_pages); | |
1146 | } | |
bc7f75fa AK |
1147 | err: |
1148 | vfree(rx_ring->buffer_info); | |
bc7f75fa AK |
1149 | ndev_err(adapter->netdev, |
1150 | "Unable to allocate memory for the transmit descriptor ring\n"); | |
1151 | return err; | |
1152 | } | |
1153 | ||
1154 | /** | |
1155 | * e1000_clean_tx_ring - Free Tx Buffers | |
1156 | * @adapter: board private structure | |
1157 | **/ | |
1158 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter) | |
1159 | { | |
1160 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
1161 | struct e1000_buffer *buffer_info; | |
1162 | unsigned long size; | |
1163 | unsigned int i; | |
1164 | ||
1165 | for (i = 0; i < tx_ring->count; i++) { | |
1166 | buffer_info = &tx_ring->buffer_info[i]; | |
1167 | e1000_put_txbuf(adapter, buffer_info); | |
1168 | } | |
1169 | ||
1170 | size = sizeof(struct e1000_buffer) * tx_ring->count; | |
1171 | memset(tx_ring->buffer_info, 0, size); | |
1172 | ||
1173 | memset(tx_ring->desc, 0, tx_ring->size); | |
1174 | ||
1175 | tx_ring->next_to_use = 0; | |
1176 | tx_ring->next_to_clean = 0; | |
1177 | ||
1178 | writel(0, adapter->hw.hw_addr + tx_ring->head); | |
1179 | writel(0, adapter->hw.hw_addr + tx_ring->tail); | |
1180 | } | |
1181 | ||
1182 | /** | |
1183 | * e1000e_free_tx_resources - Free Tx Resources per Queue | |
1184 | * @adapter: board private structure | |
1185 | * | |
1186 | * Free all transmit software resources | |
1187 | **/ | |
1188 | void e1000e_free_tx_resources(struct e1000_adapter *adapter) | |
1189 | { | |
1190 | struct pci_dev *pdev = adapter->pdev; | |
1191 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
1192 | ||
1193 | e1000_clean_tx_ring(adapter); | |
1194 | ||
1195 | vfree(tx_ring->buffer_info); | |
1196 | tx_ring->buffer_info = NULL; | |
1197 | ||
1198 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, | |
1199 | tx_ring->dma); | |
1200 | tx_ring->desc = NULL; | |
1201 | } | |
1202 | ||
1203 | /** | |
1204 | * e1000e_free_rx_resources - Free Rx Resources | |
1205 | * @adapter: board private structure | |
1206 | * | |
1207 | * Free all receive software resources | |
1208 | **/ | |
1209 | ||
1210 | void e1000e_free_rx_resources(struct e1000_adapter *adapter) | |
1211 | { | |
1212 | struct pci_dev *pdev = adapter->pdev; | |
1213 | struct e1000_ring *rx_ring = adapter->rx_ring; | |
47f44e40 | 1214 | int i; |
bc7f75fa AK |
1215 | |
1216 | e1000_clean_rx_ring(adapter); | |
1217 | ||
47f44e40 AK |
1218 | for (i = 0; i < rx_ring->count; i++) { |
1219 | kfree(rx_ring->buffer_info[i].ps_pages); | |
1220 | } | |
1221 | ||
bc7f75fa AK |
1222 | vfree(rx_ring->buffer_info); |
1223 | rx_ring->buffer_info = NULL; | |
1224 | ||
bc7f75fa AK |
1225 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
1226 | rx_ring->dma); | |
1227 | rx_ring->desc = NULL; | |
1228 | } | |
1229 | ||
1230 | /** | |
1231 | * e1000_update_itr - update the dynamic ITR value based on statistics | |
489815ce AK |
1232 | * @adapter: pointer to adapter |
1233 | * @itr_setting: current adapter->itr | |
1234 | * @packets: the number of packets during this measurement interval | |
1235 | * @bytes: the number of bytes during this measurement interval | |
1236 | * | |
bc7f75fa AK |
1237 | * Stores a new ITR value based on packets and byte |
1238 | * counts during the last interrupt. The advantage of per interrupt | |
1239 | * computation is faster updates and more accurate ITR for the current | |
1240 | * traffic pattern. Constants in this function were computed | |
1241 | * based on theoretical maximum wire speed and thresholds were set based | |
1242 | * on testing data as well as attempting to minimize response time | |
1243 | * while increasing bulk throughput. | |
1244 | * this functionality is controlled by the InterruptThrottleRate module | |
1245 | * parameter (see e1000_param.c) | |
bc7f75fa AK |
1246 | **/ |
1247 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, | |
1248 | u16 itr_setting, int packets, | |
1249 | int bytes) | |
1250 | { | |
1251 | unsigned int retval = itr_setting; | |
1252 | ||
1253 | if (packets == 0) | |
1254 | goto update_itr_done; | |
1255 | ||
1256 | switch (itr_setting) { | |
1257 | case lowest_latency: | |
1258 | /* handle TSO and jumbo frames */ | |
1259 | if (bytes/packets > 8000) | |
1260 | retval = bulk_latency; | |
1261 | else if ((packets < 5) && (bytes > 512)) { | |
1262 | retval = low_latency; | |
1263 | } | |
1264 | break; | |
1265 | case low_latency: /* 50 usec aka 20000 ints/s */ | |
1266 | if (bytes > 10000) { | |
1267 | /* this if handles the TSO accounting */ | |
1268 | if (bytes/packets > 8000) { | |
1269 | retval = bulk_latency; | |
1270 | } else if ((packets < 10) || ((bytes/packets) > 1200)) { | |
1271 | retval = bulk_latency; | |
1272 | } else if ((packets > 35)) { | |
1273 | retval = lowest_latency; | |
1274 | } | |
1275 | } else if (bytes/packets > 2000) { | |
1276 | retval = bulk_latency; | |
1277 | } else if (packets <= 2 && bytes < 512) { | |
1278 | retval = lowest_latency; | |
1279 | } | |
1280 | break; | |
1281 | case bulk_latency: /* 250 usec aka 4000 ints/s */ | |
1282 | if (bytes > 25000) { | |
1283 | if (packets > 35) { | |
1284 | retval = low_latency; | |
1285 | } | |
1286 | } else if (bytes < 6000) { | |
1287 | retval = low_latency; | |
1288 | } | |
1289 | break; | |
1290 | } | |
1291 | ||
1292 | update_itr_done: | |
1293 | return retval; | |
1294 | } | |
1295 | ||
1296 | static void e1000_set_itr(struct e1000_adapter *adapter) | |
1297 | { | |
1298 | struct e1000_hw *hw = &adapter->hw; | |
1299 | u16 current_itr; | |
1300 | u32 new_itr = adapter->itr; | |
1301 | ||
1302 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ | |
1303 | if (adapter->link_speed != SPEED_1000) { | |
1304 | current_itr = 0; | |
1305 | new_itr = 4000; | |
1306 | goto set_itr_now; | |
1307 | } | |
1308 | ||
1309 | adapter->tx_itr = e1000_update_itr(adapter, | |
1310 | adapter->tx_itr, | |
1311 | adapter->total_tx_packets, | |
1312 | adapter->total_tx_bytes); | |
1313 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ | |
1314 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) | |
1315 | adapter->tx_itr = low_latency; | |
1316 | ||
1317 | adapter->rx_itr = e1000_update_itr(adapter, | |
1318 | adapter->rx_itr, | |
1319 | adapter->total_rx_packets, | |
1320 | adapter->total_rx_bytes); | |
1321 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ | |
1322 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) | |
1323 | adapter->rx_itr = low_latency; | |
1324 | ||
1325 | current_itr = max(adapter->rx_itr, adapter->tx_itr); | |
1326 | ||
1327 | switch (current_itr) { | |
1328 | /* counts and packets in update_itr are dependent on these numbers */ | |
1329 | case lowest_latency: | |
1330 | new_itr = 70000; | |
1331 | break; | |
1332 | case low_latency: | |
1333 | new_itr = 20000; /* aka hwitr = ~200 */ | |
1334 | break; | |
1335 | case bulk_latency: | |
1336 | new_itr = 4000; | |
1337 | break; | |
1338 | default: | |
1339 | break; | |
1340 | } | |
1341 | ||
1342 | set_itr_now: | |
1343 | if (new_itr != adapter->itr) { | |
1344 | /* this attempts to bias the interrupt rate towards Bulk | |
1345 | * by adding intermediate steps when interrupt rate is | |
1346 | * increasing */ | |
1347 | new_itr = new_itr > adapter->itr ? | |
1348 | min(adapter->itr + (new_itr >> 2), new_itr) : | |
1349 | new_itr; | |
1350 | adapter->itr = new_itr; | |
1351 | ew32(ITR, 1000000000 / (new_itr * 256)); | |
1352 | } | |
1353 | } | |
1354 | ||
1355 | /** | |
1356 | * e1000_clean - NAPI Rx polling callback | |
1357 | * @adapter: board private structure | |
489815ce | 1358 | * @budget: amount of packets driver is allowed to process this poll |
bc7f75fa AK |
1359 | **/ |
1360 | static int e1000_clean(struct napi_struct *napi, int budget) | |
1361 | { | |
1362 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); | |
1363 | struct net_device *poll_dev = adapter->netdev; | |
d2c7ddd6 | 1364 | int tx_cleaned = 0, work_done = 0; |
bc7f75fa AK |
1365 | |
1366 | /* Must NOT use netdev_priv macro here. */ | |
1367 | adapter = poll_dev->priv; | |
1368 | ||
bc7f75fa AK |
1369 | /* e1000_clean is called per-cpu. This lock protects |
1370 | * tx_ring from being cleaned by multiple cpus | |
1371 | * simultaneously. A failure obtaining the lock means | |
1372 | * tx_ring is currently being cleaned anyway. */ | |
1373 | if (spin_trylock(&adapter->tx_queue_lock)) { | |
d2c7ddd6 | 1374 | tx_cleaned = e1000_clean_tx_irq(adapter); |
bc7f75fa AK |
1375 | spin_unlock(&adapter->tx_queue_lock); |
1376 | } | |
1377 | ||
1378 | adapter->clean_rx(adapter, &work_done, budget); | |
d2c7ddd6 DM |
1379 | |
1380 | if (tx_cleaned) | |
1381 | work_done = budget; | |
bc7f75fa | 1382 | |
53e52c72 DM |
1383 | /* If budget not fully consumed, exit the polling mode */ |
1384 | if (work_done < budget) { | |
bc7f75fa AK |
1385 | if (adapter->itr_setting & 3) |
1386 | e1000_set_itr(adapter); | |
1387 | netif_rx_complete(poll_dev, napi); | |
1388 | e1000_irq_enable(adapter); | |
1389 | } | |
1390 | ||
1391 | return work_done; | |
1392 | } | |
1393 | ||
1394 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid) | |
1395 | { | |
1396 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
1397 | struct e1000_hw *hw = &adapter->hw; | |
1398 | u32 vfta, index; | |
1399 | ||
1400 | /* don't update vlan cookie if already programmed */ | |
1401 | if ((adapter->hw.mng_cookie.status & | |
1402 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && | |
1403 | (vid == adapter->mng_vlan_id)) | |
1404 | return; | |
1405 | /* add VID to filter table */ | |
1406 | index = (vid >> 5) & 0x7F; | |
1407 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); | |
1408 | vfta |= (1 << (vid & 0x1F)); | |
1409 | e1000e_write_vfta(hw, index, vfta); | |
1410 | } | |
1411 | ||
1412 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) | |
1413 | { | |
1414 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
1415 | struct e1000_hw *hw = &adapter->hw; | |
1416 | u32 vfta, index; | |
1417 | ||
74ef9c39 JB |
1418 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
1419 | e1000_irq_disable(adapter); | |
bc7f75fa | 1420 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
74ef9c39 JB |
1421 | |
1422 | if (!test_bit(__E1000_DOWN, &adapter->state)) | |
1423 | e1000_irq_enable(adapter); | |
bc7f75fa AK |
1424 | |
1425 | if ((adapter->hw.mng_cookie.status & | |
1426 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && | |
1427 | (vid == adapter->mng_vlan_id)) { | |
1428 | /* release control to f/w */ | |
1429 | e1000_release_hw_control(adapter); | |
1430 | return; | |
1431 | } | |
1432 | ||
1433 | /* remove VID from filter table */ | |
1434 | index = (vid >> 5) & 0x7F; | |
1435 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); | |
1436 | vfta &= ~(1 << (vid & 0x1F)); | |
1437 | e1000e_write_vfta(hw, index, vfta); | |
1438 | } | |
1439 | ||
1440 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) | |
1441 | { | |
1442 | struct net_device *netdev = adapter->netdev; | |
1443 | u16 vid = adapter->hw.mng_cookie.vlan_id; | |
1444 | u16 old_vid = adapter->mng_vlan_id; | |
1445 | ||
1446 | if (!adapter->vlgrp) | |
1447 | return; | |
1448 | ||
1449 | if (!vlan_group_get_device(adapter->vlgrp, vid)) { | |
1450 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; | |
1451 | if (adapter->hw.mng_cookie.status & | |
1452 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { | |
1453 | e1000_vlan_rx_add_vid(netdev, vid); | |
1454 | adapter->mng_vlan_id = vid; | |
1455 | } | |
1456 | ||
1457 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && | |
1458 | (vid != old_vid) && | |
1459 | !vlan_group_get_device(adapter->vlgrp, old_vid)) | |
1460 | e1000_vlan_rx_kill_vid(netdev, old_vid); | |
1461 | } else { | |
1462 | adapter->mng_vlan_id = vid; | |
1463 | } | |
1464 | } | |
1465 | ||
1466 | ||
1467 | static void e1000_vlan_rx_register(struct net_device *netdev, | |
1468 | struct vlan_group *grp) | |
1469 | { | |
1470 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
1471 | struct e1000_hw *hw = &adapter->hw; | |
1472 | u32 ctrl, rctl; | |
1473 | ||
74ef9c39 JB |
1474 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
1475 | e1000_irq_disable(adapter); | |
bc7f75fa AK |
1476 | adapter->vlgrp = grp; |
1477 | ||
1478 | if (grp) { | |
1479 | /* enable VLAN tag insert/strip */ | |
1480 | ctrl = er32(CTRL); | |
1481 | ctrl |= E1000_CTRL_VME; | |
1482 | ew32(CTRL, ctrl); | |
1483 | ||
1484 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { | |
1485 | /* enable VLAN receive filtering */ | |
1486 | rctl = er32(RCTL); | |
1487 | rctl |= E1000_RCTL_VFE; | |
1488 | rctl &= ~E1000_RCTL_CFIEN; | |
1489 | ew32(RCTL, rctl); | |
1490 | e1000_update_mng_vlan(adapter); | |
1491 | } | |
1492 | } else { | |
1493 | /* disable VLAN tag insert/strip */ | |
1494 | ctrl = er32(CTRL); | |
1495 | ctrl &= ~E1000_CTRL_VME; | |
1496 | ew32(CTRL, ctrl); | |
1497 | ||
1498 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { | |
1499 | /* disable VLAN filtering */ | |
1500 | rctl = er32(RCTL); | |
1501 | rctl &= ~E1000_RCTL_VFE; | |
1502 | ew32(RCTL, rctl); | |
1503 | if (adapter->mng_vlan_id != | |
1504 | (u16)E1000_MNG_VLAN_NONE) { | |
1505 | e1000_vlan_rx_kill_vid(netdev, | |
1506 | adapter->mng_vlan_id); | |
1507 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; | |
1508 | } | |
1509 | } | |
1510 | } | |
1511 | ||
74ef9c39 JB |
1512 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
1513 | e1000_irq_enable(adapter); | |
bc7f75fa AK |
1514 | } |
1515 | ||
1516 | static void e1000_restore_vlan(struct e1000_adapter *adapter) | |
1517 | { | |
1518 | u16 vid; | |
1519 | ||
1520 | e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); | |
1521 | ||
1522 | if (!adapter->vlgrp) | |
1523 | return; | |
1524 | ||
1525 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { | |
1526 | if (!vlan_group_get_device(adapter->vlgrp, vid)) | |
1527 | continue; | |
1528 | e1000_vlan_rx_add_vid(adapter->netdev, vid); | |
1529 | } | |
1530 | } | |
1531 | ||
1532 | static void e1000_init_manageability(struct e1000_adapter *adapter) | |
1533 | { | |
1534 | struct e1000_hw *hw = &adapter->hw; | |
1535 | u32 manc, manc2h; | |
1536 | ||
1537 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) | |
1538 | return; | |
1539 | ||
1540 | manc = er32(MANC); | |
1541 | ||
bc7f75fa AK |
1542 | /* enable receiving management packets to the host. this will probably |
1543 | * generate destination unreachable messages from the host OS, but | |
1544 | * the packets will be handled on SMBUS */ | |
1545 | manc |= E1000_MANC_EN_MNG2HOST; | |
1546 | manc2h = er32(MANC2H); | |
1547 | #define E1000_MNG2HOST_PORT_623 (1 << 5) | |
1548 | #define E1000_MNG2HOST_PORT_664 (1 << 6) | |
1549 | manc2h |= E1000_MNG2HOST_PORT_623; | |
1550 | manc2h |= E1000_MNG2HOST_PORT_664; | |
1551 | ew32(MANC2H, manc2h); | |
1552 | ew32(MANC, manc); | |
1553 | } | |
1554 | ||
1555 | /** | |
1556 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset | |
1557 | * @adapter: board private structure | |
1558 | * | |
1559 | * Configure the Tx unit of the MAC after a reset. | |
1560 | **/ | |
1561 | static void e1000_configure_tx(struct e1000_adapter *adapter) | |
1562 | { | |
1563 | struct e1000_hw *hw = &adapter->hw; | |
1564 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
1565 | u64 tdba; | |
1566 | u32 tdlen, tctl, tipg, tarc; | |
1567 | u32 ipgr1, ipgr2; | |
1568 | ||
1569 | /* Setup the HW Tx Head and Tail descriptor pointers */ | |
1570 | tdba = tx_ring->dma; | |
1571 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); | |
1572 | ew32(TDBAL, (tdba & DMA_32BIT_MASK)); | |
1573 | ew32(TDBAH, (tdba >> 32)); | |
1574 | ew32(TDLEN, tdlen); | |
1575 | ew32(TDH, 0); | |
1576 | ew32(TDT, 0); | |
1577 | tx_ring->head = E1000_TDH; | |
1578 | tx_ring->tail = E1000_TDT; | |
1579 | ||
1580 | /* Set the default values for the Tx Inter Packet Gap timer */ | |
1581 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */ | |
1582 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */ | |
1583 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */ | |
1584 | ||
1585 | if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN) | |
1586 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */ | |
1587 | ||
1588 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; | |
1589 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; | |
1590 | ew32(TIPG, tipg); | |
1591 | ||
1592 | /* Set the Tx Interrupt Delay register */ | |
1593 | ew32(TIDV, adapter->tx_int_delay); | |
1594 | /* tx irq moderation */ | |
1595 | ew32(TADV, adapter->tx_abs_int_delay); | |
1596 | ||
1597 | /* Program the Transmit Control Register */ | |
1598 | tctl = er32(TCTL); | |
1599 | tctl &= ~E1000_TCTL_CT; | |
1600 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | | |
1601 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); | |
1602 | ||
1603 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { | |
1604 | tarc = er32(TARC0); | |
1605 | /* set the speed mode bit, we'll clear it if we're not at | |
1606 | * gigabit link later */ | |
1607 | #define SPEED_MODE_BIT (1 << 21) | |
1608 | tarc |= SPEED_MODE_BIT; | |
1609 | ew32(TARC0, tarc); | |
1610 | } | |
1611 | ||
1612 | /* errata: program both queues to unweighted RR */ | |
1613 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { | |
1614 | tarc = er32(TARC0); | |
1615 | tarc |= 1; | |
1616 | ew32(TARC0, tarc); | |
1617 | tarc = er32(TARC1); | |
1618 | tarc |= 1; | |
1619 | ew32(TARC1, tarc); | |
1620 | } | |
1621 | ||
1622 | e1000e_config_collision_dist(hw); | |
1623 | ||
1624 | /* Setup Transmit Descriptor Settings for eop descriptor */ | |
1625 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; | |
1626 | ||
1627 | /* only set IDE if we are delaying interrupts using the timers */ | |
1628 | if (adapter->tx_int_delay) | |
1629 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; | |
1630 | ||
1631 | /* enable Report Status bit */ | |
1632 | adapter->txd_cmd |= E1000_TXD_CMD_RS; | |
1633 | ||
1634 | ew32(TCTL, tctl); | |
1635 | ||
1636 | adapter->tx_queue_len = adapter->netdev->tx_queue_len; | |
1637 | } | |
1638 | ||
1639 | /** | |
1640 | * e1000_setup_rctl - configure the receive control registers | |
1641 | * @adapter: Board private structure | |
1642 | **/ | |
1643 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ | |
1644 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) | |
1645 | static void e1000_setup_rctl(struct e1000_adapter *adapter) | |
1646 | { | |
1647 | struct e1000_hw *hw = &adapter->hw; | |
1648 | u32 rctl, rfctl; | |
1649 | u32 psrctl = 0; | |
1650 | u32 pages = 0; | |
1651 | ||
1652 | /* Program MC offset vector base */ | |
1653 | rctl = er32(RCTL); | |
1654 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); | |
1655 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | | |
1656 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | | |
1657 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); | |
1658 | ||
1659 | /* Do not Store bad packets */ | |
1660 | rctl &= ~E1000_RCTL_SBP; | |
1661 | ||
1662 | /* Enable Long Packet receive */ | |
1663 | if (adapter->netdev->mtu <= ETH_DATA_LEN) | |
1664 | rctl &= ~E1000_RCTL_LPE; | |
1665 | else | |
1666 | rctl |= E1000_RCTL_LPE; | |
1667 | ||
5918bd88 AK |
1668 | /* Enable hardware CRC frame stripping */ |
1669 | rctl |= E1000_RCTL_SECRC; | |
1670 | ||
bc7f75fa AK |
1671 | /* Setup buffer sizes */ |
1672 | rctl &= ~E1000_RCTL_SZ_4096; | |
1673 | rctl |= E1000_RCTL_BSEX; | |
1674 | switch (adapter->rx_buffer_len) { | |
1675 | case 256: | |
1676 | rctl |= E1000_RCTL_SZ_256; | |
1677 | rctl &= ~E1000_RCTL_BSEX; | |
1678 | break; | |
1679 | case 512: | |
1680 | rctl |= E1000_RCTL_SZ_512; | |
1681 | rctl &= ~E1000_RCTL_BSEX; | |
1682 | break; | |
1683 | case 1024: | |
1684 | rctl |= E1000_RCTL_SZ_1024; | |
1685 | rctl &= ~E1000_RCTL_BSEX; | |
1686 | break; | |
1687 | case 2048: | |
1688 | default: | |
1689 | rctl |= E1000_RCTL_SZ_2048; | |
1690 | rctl &= ~E1000_RCTL_BSEX; | |
1691 | break; | |
1692 | case 4096: | |
1693 | rctl |= E1000_RCTL_SZ_4096; | |
1694 | break; | |
1695 | case 8192: | |
1696 | rctl |= E1000_RCTL_SZ_8192; | |
1697 | break; | |
1698 | case 16384: | |
1699 | rctl |= E1000_RCTL_SZ_16384; | |
1700 | break; | |
1701 | } | |
1702 | ||
1703 | /* | |
1704 | * 82571 and greater support packet-split where the protocol | |
1705 | * header is placed in skb->data and the packet data is | |
1706 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. | |
1707 | * In the case of a non-split, skb->data is linearly filled, | |
1708 | * followed by the page buffers. Therefore, skb->data is | |
1709 | * sized to hold the largest protocol header. | |
1710 | * | |
1711 | * allocations using alloc_page take too long for regular MTU | |
1712 | * so only enable packet split for jumbo frames | |
1713 | * | |
1714 | * Using pages when the page size is greater than 16k wastes | |
1715 | * a lot of memory, since we allocate 3 pages at all times | |
1716 | * per packet. | |
1717 | */ | |
1718 | adapter->rx_ps_pages = 0; | |
1719 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); | |
1720 | if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) | |
1721 | adapter->rx_ps_pages = pages; | |
1722 | ||
1723 | if (adapter->rx_ps_pages) { | |
1724 | /* Configure extra packet-split registers */ | |
1725 | rfctl = er32(RFCTL); | |
1726 | rfctl |= E1000_RFCTL_EXTEN; | |
1727 | /* disable packet split support for IPv6 extension headers, | |
1728 | * because some malformed IPv6 headers can hang the RX */ | |
1729 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | | |
1730 | E1000_RFCTL_NEW_IPV6_EXT_DIS); | |
1731 | ||
1732 | ew32(RFCTL, rfctl); | |
1733 | ||
140a7480 AK |
1734 | /* Enable Packet split descriptors */ |
1735 | rctl |= E1000_RCTL_DTYP_PS; | |
bc7f75fa AK |
1736 | |
1737 | psrctl |= adapter->rx_ps_bsize0 >> | |
1738 | E1000_PSRCTL_BSIZE0_SHIFT; | |
1739 | ||
1740 | switch (adapter->rx_ps_pages) { | |
1741 | case 3: | |
1742 | psrctl |= PAGE_SIZE << | |
1743 | E1000_PSRCTL_BSIZE3_SHIFT; | |
1744 | case 2: | |
1745 | psrctl |= PAGE_SIZE << | |
1746 | E1000_PSRCTL_BSIZE2_SHIFT; | |
1747 | case 1: | |
1748 | psrctl |= PAGE_SIZE >> | |
1749 | E1000_PSRCTL_BSIZE1_SHIFT; | |
1750 | break; | |
1751 | } | |
1752 | ||
1753 | ew32(PSRCTL, psrctl); | |
1754 | } | |
1755 | ||
1756 | ew32(RCTL, rctl); | |
1757 | } | |
1758 | ||
1759 | /** | |
1760 | * e1000_configure_rx - Configure Receive Unit after Reset | |
1761 | * @adapter: board private structure | |
1762 | * | |
1763 | * Configure the Rx unit of the MAC after a reset. | |
1764 | **/ | |
1765 | static void e1000_configure_rx(struct e1000_adapter *adapter) | |
1766 | { | |
1767 | struct e1000_hw *hw = &adapter->hw; | |
1768 | struct e1000_ring *rx_ring = adapter->rx_ring; | |
1769 | u64 rdba; | |
1770 | u32 rdlen, rctl, rxcsum, ctrl_ext; | |
1771 | ||
1772 | if (adapter->rx_ps_pages) { | |
1773 | /* this is a 32 byte descriptor */ | |
1774 | rdlen = rx_ring->count * | |
1775 | sizeof(union e1000_rx_desc_packet_split); | |
1776 | adapter->clean_rx = e1000_clean_rx_irq_ps; | |
1777 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; | |
bc7f75fa AK |
1778 | } else { |
1779 | rdlen = rx_ring->count * | |
1780 | sizeof(struct e1000_rx_desc); | |
1781 | adapter->clean_rx = e1000_clean_rx_irq; | |
1782 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; | |
1783 | } | |
1784 | ||
1785 | /* disable receives while setting up the descriptors */ | |
1786 | rctl = er32(RCTL); | |
1787 | ew32(RCTL, rctl & ~E1000_RCTL_EN); | |
1788 | e1e_flush(); | |
1789 | msleep(10); | |
1790 | ||
1791 | /* set the Receive Delay Timer Register */ | |
1792 | ew32(RDTR, adapter->rx_int_delay); | |
1793 | ||
1794 | /* irq moderation */ | |
1795 | ew32(RADV, adapter->rx_abs_int_delay); | |
1796 | if (adapter->itr_setting != 0) | |
1797 | ew32(ITR, | |
1798 | 1000000000 / (adapter->itr * 256)); | |
1799 | ||
1800 | ctrl_ext = er32(CTRL_EXT); | |
1801 | /* Reset delay timers after every interrupt */ | |
1802 | ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR; | |
1803 | /* Auto-Mask interrupts upon ICR access */ | |
1804 | ctrl_ext |= E1000_CTRL_EXT_IAME; | |
1805 | ew32(IAM, 0xffffffff); | |
1806 | ew32(CTRL_EXT, ctrl_ext); | |
1807 | e1e_flush(); | |
1808 | ||
1809 | /* Setup the HW Rx Head and Tail Descriptor Pointers and | |
1810 | * the Base and Length of the Rx Descriptor Ring */ | |
1811 | rdba = rx_ring->dma; | |
1812 | ew32(RDBAL, (rdba & DMA_32BIT_MASK)); | |
1813 | ew32(RDBAH, (rdba >> 32)); | |
1814 | ew32(RDLEN, rdlen); | |
1815 | ew32(RDH, 0); | |
1816 | ew32(RDT, 0); | |
1817 | rx_ring->head = E1000_RDH; | |
1818 | rx_ring->tail = E1000_RDT; | |
1819 | ||
1820 | /* Enable Receive Checksum Offload for TCP and UDP */ | |
1821 | rxcsum = er32(RXCSUM); | |
1822 | if (adapter->flags & FLAG_RX_CSUM_ENABLED) { | |
1823 | rxcsum |= E1000_RXCSUM_TUOFL; | |
1824 | ||
1825 | /* IPv4 payload checksum for UDP fragments must be | |
1826 | * used in conjunction with packet-split. */ | |
1827 | if (adapter->rx_ps_pages) | |
1828 | rxcsum |= E1000_RXCSUM_IPPCSE; | |
1829 | } else { | |
1830 | rxcsum &= ~E1000_RXCSUM_TUOFL; | |
1831 | /* no need to clear IPPCSE as it defaults to 0 */ | |
1832 | } | |
1833 | ew32(RXCSUM, rxcsum); | |
1834 | ||
1835 | /* Enable early receives on supported devices, only takes effect when | |
1836 | * packet size is equal or larger than the specified value (in 8 byte | |
1837 | * units), e.g. using jumbo frames when setting to E1000_ERT_2048 */ | |
1838 | if ((adapter->flags & FLAG_HAS_ERT) && | |
1839 | (adapter->netdev->mtu > ETH_DATA_LEN)) | |
1840 | ew32(ERT, E1000_ERT_2048); | |
1841 | ||
1842 | /* Enable Receives */ | |
1843 | ew32(RCTL, rctl); | |
1844 | } | |
1845 | ||
1846 | /** | |
1847 | * e1000_mc_addr_list_update - Update Multicast addresses | |
1848 | * @hw: pointer to the HW structure | |
1849 | * @mc_addr_list: array of multicast addresses to program | |
1850 | * @mc_addr_count: number of multicast addresses to program | |
1851 | * @rar_used_count: the first RAR register free to program | |
1852 | * @rar_count: total number of supported Receive Address Registers | |
1853 | * | |
1854 | * Updates the Receive Address Registers and Multicast Table Array. | |
1855 | * The caller must have a packed mc_addr_list of multicast addresses. | |
1856 | * The parameter rar_count will usually be hw->mac.rar_entry_count | |
1857 | * unless there are workarounds that change this. Currently no func pointer | |
1858 | * exists and all implementations are handled in the generic version of this | |
1859 | * function. | |
1860 | **/ | |
1861 | static void e1000_mc_addr_list_update(struct e1000_hw *hw, u8 *mc_addr_list, | |
1862 | u32 mc_addr_count, u32 rar_used_count, | |
1863 | u32 rar_count) | |
1864 | { | |
1865 | hw->mac.ops.mc_addr_list_update(hw, mc_addr_list, mc_addr_count, | |
1866 | rar_used_count, rar_count); | |
1867 | } | |
1868 | ||
1869 | /** | |
1870 | * e1000_set_multi - Multicast and Promiscuous mode set | |
1871 | * @netdev: network interface device structure | |
1872 | * | |
1873 | * The set_multi entry point is called whenever the multicast address | |
1874 | * list or the network interface flags are updated. This routine is | |
1875 | * responsible for configuring the hardware for proper multicast, | |
1876 | * promiscuous mode, and all-multi behavior. | |
1877 | **/ | |
1878 | static void e1000_set_multi(struct net_device *netdev) | |
1879 | { | |
1880 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
1881 | struct e1000_hw *hw = &adapter->hw; | |
1882 | struct e1000_mac_info *mac = &hw->mac; | |
1883 | struct dev_mc_list *mc_ptr; | |
1884 | u8 *mta_list; | |
1885 | u32 rctl; | |
1886 | int i; | |
1887 | ||
1888 | /* Check for Promiscuous and All Multicast modes */ | |
1889 | ||
1890 | rctl = er32(RCTL); | |
1891 | ||
1892 | if (netdev->flags & IFF_PROMISC) { | |
1893 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); | |
1894 | } else if (netdev->flags & IFF_ALLMULTI) { | |
1895 | rctl |= E1000_RCTL_MPE; | |
1896 | rctl &= ~E1000_RCTL_UPE; | |
1897 | } else { | |
1898 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); | |
1899 | } | |
1900 | ||
1901 | ew32(RCTL, rctl); | |
1902 | ||
1903 | if (netdev->mc_count) { | |
1904 | mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC); | |
1905 | if (!mta_list) | |
1906 | return; | |
1907 | ||
1908 | /* prepare a packed array of only addresses. */ | |
1909 | mc_ptr = netdev->mc_list; | |
1910 | ||
1911 | for (i = 0; i < netdev->mc_count; i++) { | |
1912 | if (!mc_ptr) | |
1913 | break; | |
1914 | memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr, | |
1915 | ETH_ALEN); | |
1916 | mc_ptr = mc_ptr->next; | |
1917 | } | |
1918 | ||
1919 | e1000_mc_addr_list_update(hw, mta_list, i, 1, | |
1920 | mac->rar_entry_count); | |
1921 | kfree(mta_list); | |
1922 | } else { | |
1923 | /* | |
1924 | * if we're called from probe, we might not have | |
1925 | * anything to do here, so clear out the list | |
1926 | */ | |
1927 | e1000_mc_addr_list_update(hw, NULL, 0, 1, | |
1928 | mac->rar_entry_count); | |
1929 | } | |
1930 | } | |
1931 | ||
1932 | /** | |
1933 | * e1000_configure - configure the hardware for RX and TX | |
1934 | * @adapter: private board structure | |
1935 | **/ | |
1936 | static void e1000_configure(struct e1000_adapter *adapter) | |
1937 | { | |
1938 | e1000_set_multi(adapter->netdev); | |
1939 | ||
1940 | e1000_restore_vlan(adapter); | |
1941 | e1000_init_manageability(adapter); | |
1942 | ||
1943 | e1000_configure_tx(adapter); | |
1944 | e1000_setup_rctl(adapter); | |
1945 | e1000_configure_rx(adapter); | |
1946 | adapter->alloc_rx_buf(adapter, | |
1947 | e1000_desc_unused(adapter->rx_ring)); | |
1948 | } | |
1949 | ||
1950 | /** | |
1951 | * e1000e_power_up_phy - restore link in case the phy was powered down | |
1952 | * @adapter: address of board private structure | |
1953 | * | |
1954 | * The phy may be powered down to save power and turn off link when the | |
1955 | * driver is unloaded and wake on lan is not enabled (among others) | |
1956 | * *** this routine MUST be followed by a call to e1000e_reset *** | |
1957 | **/ | |
1958 | void e1000e_power_up_phy(struct e1000_adapter *adapter) | |
1959 | { | |
1960 | u16 mii_reg = 0; | |
1961 | ||
1962 | /* Just clear the power down bit to wake the phy back up */ | |
1963 | if (adapter->hw.media_type == e1000_media_type_copper) { | |
1964 | /* according to the manual, the phy will retain its | |
1965 | * settings across a power-down/up cycle */ | |
1966 | e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg); | |
1967 | mii_reg &= ~MII_CR_POWER_DOWN; | |
1968 | e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg); | |
1969 | } | |
1970 | ||
1971 | adapter->hw.mac.ops.setup_link(&adapter->hw); | |
1972 | } | |
1973 | ||
1974 | /** | |
1975 | * e1000_power_down_phy - Power down the PHY | |
1976 | * | |
1977 | * Power down the PHY so no link is implied when interface is down | |
1978 | * The PHY cannot be powered down is management or WoL is active | |
1979 | */ | |
1980 | static void e1000_power_down_phy(struct e1000_adapter *adapter) | |
1981 | { | |
1982 | struct e1000_hw *hw = &adapter->hw; | |
1983 | u16 mii_reg; | |
1984 | ||
1985 | /* WoL is enabled */ | |
23b66e2b | 1986 | if (adapter->wol) |
bc7f75fa AK |
1987 | return; |
1988 | ||
1989 | /* non-copper PHY? */ | |
1990 | if (adapter->hw.media_type != e1000_media_type_copper) | |
1991 | return; | |
1992 | ||
1993 | /* reset is blocked because of a SoL/IDER session */ | |
1994 | if (e1000e_check_mng_mode(hw) || | |
1995 | e1000_check_reset_block(hw)) | |
1996 | return; | |
1997 | ||
489815ce | 1998 | /* manageability (AMT) is enabled */ |
bc7f75fa AK |
1999 | if (er32(MANC) & E1000_MANC_SMBUS_EN) |
2000 | return; | |
2001 | ||
2002 | /* power down the PHY */ | |
2003 | e1e_rphy(hw, PHY_CONTROL, &mii_reg); | |
2004 | mii_reg |= MII_CR_POWER_DOWN; | |
2005 | e1e_wphy(hw, PHY_CONTROL, mii_reg); | |
2006 | mdelay(1); | |
2007 | } | |
2008 | ||
2009 | /** | |
2010 | * e1000e_reset - bring the hardware into a known good state | |
2011 | * | |
2012 | * This function boots the hardware and enables some settings that | |
2013 | * require a configuration cycle of the hardware - those cannot be | |
2014 | * set/changed during runtime. After reset the device needs to be | |
2015 | * properly configured for rx, tx etc. | |
2016 | */ | |
2017 | void e1000e_reset(struct e1000_adapter *adapter) | |
2018 | { | |
2019 | struct e1000_mac_info *mac = &adapter->hw.mac; | |
2020 | struct e1000_hw *hw = &adapter->hw; | |
2021 | u32 tx_space, min_tx_space, min_rx_space; | |
df762464 | 2022 | u32 pba; |
bc7f75fa AK |
2023 | u16 hwm; |
2024 | ||
df762464 AK |
2025 | ew32(PBA, adapter->pba); |
2026 | ||
bc7f75fa AK |
2027 | if (mac->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN ) { |
2028 | /* To maintain wire speed transmits, the Tx FIFO should be | |
2029 | * large enough to accommodate two full transmit packets, | |
2030 | * rounded up to the next 1KB and expressed in KB. Likewise, | |
2031 | * the Rx FIFO should be large enough to accommodate at least | |
2032 | * one full receive packet and is similarly rounded up and | |
2033 | * expressed in KB. */ | |
df762464 | 2034 | pba = er32(PBA); |
bc7f75fa | 2035 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
df762464 | 2036 | tx_space = pba >> 16; |
bc7f75fa | 2037 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
df762464 | 2038 | pba &= 0xffff; |
bc7f75fa AK |
2039 | /* the tx fifo also stores 16 bytes of information about the tx |
2040 | * but don't include ethernet FCS because hardware appends it */ | |
2041 | min_tx_space = (mac->max_frame_size + | |
2042 | sizeof(struct e1000_tx_desc) - | |
2043 | ETH_FCS_LEN) * 2; | |
2044 | min_tx_space = ALIGN(min_tx_space, 1024); | |
2045 | min_tx_space >>= 10; | |
2046 | /* software strips receive CRC, so leave room for it */ | |
2047 | min_rx_space = mac->max_frame_size; | |
2048 | min_rx_space = ALIGN(min_rx_space, 1024); | |
2049 | min_rx_space >>= 10; | |
2050 | ||
2051 | /* If current Tx allocation is less than the min Tx FIFO size, | |
2052 | * and the min Tx FIFO size is less than the current Rx FIFO | |
2053 | * allocation, take space away from current Rx allocation */ | |
df762464 AK |
2054 | if ((tx_space < min_tx_space) && |
2055 | ((min_tx_space - tx_space) < pba)) { | |
2056 | pba -= min_tx_space - tx_space; | |
bc7f75fa AK |
2057 | |
2058 | /* if short on rx space, rx wins and must trump tx | |
2059 | * adjustment or use Early Receive if available */ | |
df762464 | 2060 | if ((pba < min_rx_space) && |
bc7f75fa AK |
2061 | (!(adapter->flags & FLAG_HAS_ERT))) |
2062 | /* ERT enabled in e1000_configure_rx */ | |
df762464 | 2063 | pba = min_rx_space; |
bc7f75fa | 2064 | } |
df762464 AK |
2065 | |
2066 | ew32(PBA, pba); | |
bc7f75fa AK |
2067 | } |
2068 | ||
bc7f75fa AK |
2069 | |
2070 | /* flow control settings */ | |
2071 | /* The high water mark must be low enough to fit one full frame | |
2072 | * (or the size used for early receive) above it in the Rx FIFO. | |
2073 | * Set it to the lower of: | |
2074 | * - 90% of the Rx FIFO size, and | |
2075 | * - the full Rx FIFO size minus the early receive size (for parts | |
2076 | * with ERT support assuming ERT set to E1000_ERT_2048), or | |
2077 | * - the full Rx FIFO size minus one full frame */ | |
2078 | if (adapter->flags & FLAG_HAS_ERT) | |
2079 | hwm = min(((adapter->pba << 10) * 9 / 10), | |
2080 | ((adapter->pba << 10) - (E1000_ERT_2048 << 3))); | |
2081 | else | |
2082 | hwm = min(((adapter->pba << 10) * 9 / 10), | |
2083 | ((adapter->pba << 10) - mac->max_frame_size)); | |
2084 | ||
2085 | mac->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */ | |
2086 | mac->fc_low_water = mac->fc_high_water - 8; | |
2087 | ||
2088 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) | |
2089 | mac->fc_pause_time = 0xFFFF; | |
2090 | else | |
2091 | mac->fc_pause_time = E1000_FC_PAUSE_TIME; | |
2092 | mac->fc = mac->original_fc; | |
2093 | ||
2094 | /* Allow time for pending master requests to run */ | |
2095 | mac->ops.reset_hw(hw); | |
2096 | ew32(WUC, 0); | |
2097 | ||
2098 | if (mac->ops.init_hw(hw)) | |
2099 | ndev_err(adapter->netdev, "Hardware Error\n"); | |
2100 | ||
2101 | e1000_update_mng_vlan(adapter); | |
2102 | ||
2103 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ | |
2104 | ew32(VET, ETH_P_8021Q); | |
2105 | ||
2106 | e1000e_reset_adaptive(hw); | |
2107 | e1000_get_phy_info(hw); | |
2108 | ||
2109 | if (!(adapter->flags & FLAG_SMART_POWER_DOWN)) { | |
2110 | u16 phy_data = 0; | |
2111 | /* speed up time to link by disabling smart power down, ignore | |
2112 | * the return value of this function because there is nothing | |
2113 | * different we would do if it failed */ | |
2114 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); | |
2115 | phy_data &= ~IGP02E1000_PM_SPD; | |
2116 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); | |
2117 | } | |
bc7f75fa AK |
2118 | } |
2119 | ||
2120 | int e1000e_up(struct e1000_adapter *adapter) | |
2121 | { | |
2122 | struct e1000_hw *hw = &adapter->hw; | |
2123 | ||
2124 | /* hardware has been reset, we need to reload some things */ | |
2125 | e1000_configure(adapter); | |
2126 | ||
2127 | clear_bit(__E1000_DOWN, &adapter->state); | |
2128 | ||
2129 | napi_enable(&adapter->napi); | |
2130 | e1000_irq_enable(adapter); | |
2131 | ||
2132 | /* fire a link change interrupt to start the watchdog */ | |
2133 | ew32(ICS, E1000_ICS_LSC); | |
2134 | return 0; | |
2135 | } | |
2136 | ||
2137 | void e1000e_down(struct e1000_adapter *adapter) | |
2138 | { | |
2139 | struct net_device *netdev = adapter->netdev; | |
2140 | struct e1000_hw *hw = &adapter->hw; | |
2141 | u32 tctl, rctl; | |
2142 | ||
2143 | /* signal that we're down so the interrupt handler does not | |
2144 | * reschedule our watchdog timer */ | |
2145 | set_bit(__E1000_DOWN, &adapter->state); | |
2146 | ||
2147 | /* disable receives in the hardware */ | |
2148 | rctl = er32(RCTL); | |
2149 | ew32(RCTL, rctl & ~E1000_RCTL_EN); | |
2150 | /* flush and sleep below */ | |
2151 | ||
2152 | netif_stop_queue(netdev); | |
2153 | ||
2154 | /* disable transmits in the hardware */ | |
2155 | tctl = er32(TCTL); | |
2156 | tctl &= ~E1000_TCTL_EN; | |
2157 | ew32(TCTL, tctl); | |
2158 | /* flush both disables and wait for them to finish */ | |
2159 | e1e_flush(); | |
2160 | msleep(10); | |
2161 | ||
2162 | napi_disable(&adapter->napi); | |
2163 | e1000_irq_disable(adapter); | |
2164 | ||
2165 | del_timer_sync(&adapter->watchdog_timer); | |
2166 | del_timer_sync(&adapter->phy_info_timer); | |
2167 | ||
2168 | netdev->tx_queue_len = adapter->tx_queue_len; | |
2169 | netif_carrier_off(netdev); | |
2170 | adapter->link_speed = 0; | |
2171 | adapter->link_duplex = 0; | |
2172 | ||
2173 | e1000e_reset(adapter); | |
2174 | e1000_clean_tx_ring(adapter); | |
2175 | e1000_clean_rx_ring(adapter); | |
2176 | ||
2177 | /* | |
2178 | * TODO: for power management, we could drop the link and | |
2179 | * pci_disable_device here. | |
2180 | */ | |
2181 | } | |
2182 | ||
2183 | void e1000e_reinit_locked(struct e1000_adapter *adapter) | |
2184 | { | |
2185 | might_sleep(); | |
2186 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) | |
2187 | msleep(1); | |
2188 | e1000e_down(adapter); | |
2189 | e1000e_up(adapter); | |
2190 | clear_bit(__E1000_RESETTING, &adapter->state); | |
2191 | } | |
2192 | ||
2193 | /** | |
2194 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) | |
2195 | * @adapter: board private structure to initialize | |
2196 | * | |
2197 | * e1000_sw_init initializes the Adapter private data structure. | |
2198 | * Fields are initialized based on PCI device information and | |
2199 | * OS network device settings (MTU size). | |
2200 | **/ | |
2201 | static int __devinit e1000_sw_init(struct e1000_adapter *adapter) | |
2202 | { | |
2203 | struct e1000_hw *hw = &adapter->hw; | |
2204 | struct net_device *netdev = adapter->netdev; | |
2205 | ||
2206 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN; | |
2207 | adapter->rx_ps_bsize0 = 128; | |
2208 | hw->mac.max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; | |
2209 | hw->mac.min_frame_size = ETH_ZLEN + ETH_FCS_LEN; | |
2210 | ||
2211 | adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); | |
2212 | if (!adapter->tx_ring) | |
2213 | goto err; | |
2214 | ||
2215 | adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); | |
2216 | if (!adapter->rx_ring) | |
2217 | goto err; | |
2218 | ||
2219 | spin_lock_init(&adapter->tx_queue_lock); | |
2220 | ||
2221 | /* Explicitly disable IRQ since the NIC can be in any state. */ | |
bc7f75fa AK |
2222 | e1000_irq_disable(adapter); |
2223 | ||
2224 | spin_lock_init(&adapter->stats_lock); | |
2225 | ||
2226 | set_bit(__E1000_DOWN, &adapter->state); | |
2227 | return 0; | |
2228 | ||
2229 | err: | |
2230 | ndev_err(netdev, "Unable to allocate memory for queues\n"); | |
2231 | kfree(adapter->rx_ring); | |
2232 | kfree(adapter->tx_ring); | |
2233 | return -ENOMEM; | |
2234 | } | |
2235 | ||
2236 | /** | |
2237 | * e1000_open - Called when a network interface is made active | |
2238 | * @netdev: network interface device structure | |
2239 | * | |
2240 | * Returns 0 on success, negative value on failure | |
2241 | * | |
2242 | * The open entry point is called when a network interface is made | |
2243 | * active by the system (IFF_UP). At this point all resources needed | |
2244 | * for transmit and receive operations are allocated, the interrupt | |
2245 | * handler is registered with the OS, the watchdog timer is started, | |
2246 | * and the stack is notified that the interface is ready. | |
2247 | **/ | |
2248 | static int e1000_open(struct net_device *netdev) | |
2249 | { | |
2250 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
2251 | struct e1000_hw *hw = &adapter->hw; | |
2252 | int err; | |
2253 | ||
2254 | /* disallow open during test */ | |
2255 | if (test_bit(__E1000_TESTING, &adapter->state)) | |
2256 | return -EBUSY; | |
2257 | ||
2258 | /* allocate transmit descriptors */ | |
2259 | err = e1000e_setup_tx_resources(adapter); | |
2260 | if (err) | |
2261 | goto err_setup_tx; | |
2262 | ||
2263 | /* allocate receive descriptors */ | |
2264 | err = e1000e_setup_rx_resources(adapter); | |
2265 | if (err) | |
2266 | goto err_setup_rx; | |
2267 | ||
2268 | e1000e_power_up_phy(adapter); | |
2269 | ||
2270 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; | |
2271 | if ((adapter->hw.mng_cookie.status & | |
2272 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) | |
2273 | e1000_update_mng_vlan(adapter); | |
2274 | ||
2275 | /* If AMT is enabled, let the firmware know that the network | |
2276 | * interface is now open */ | |
2277 | if ((adapter->flags & FLAG_HAS_AMT) && | |
2278 | e1000e_check_mng_mode(&adapter->hw)) | |
2279 | e1000_get_hw_control(adapter); | |
2280 | ||
2281 | /* before we allocate an interrupt, we must be ready to handle it. | |
2282 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt | |
2283 | * as soon as we call pci_request_irq, so we have to setup our | |
2284 | * clean_rx handler before we do so. */ | |
2285 | e1000_configure(adapter); | |
2286 | ||
2287 | err = e1000_request_irq(adapter); | |
2288 | if (err) | |
2289 | goto err_req_irq; | |
2290 | ||
2291 | /* From here on the code is the same as e1000e_up() */ | |
2292 | clear_bit(__E1000_DOWN, &adapter->state); | |
2293 | ||
2294 | napi_enable(&adapter->napi); | |
2295 | ||
2296 | e1000_irq_enable(adapter); | |
2297 | ||
2298 | /* fire a link status change interrupt to start the watchdog */ | |
2299 | ew32(ICS, E1000_ICS_LSC); | |
2300 | ||
2301 | return 0; | |
2302 | ||
2303 | err_req_irq: | |
2304 | e1000_release_hw_control(adapter); | |
2305 | e1000_power_down_phy(adapter); | |
2306 | e1000e_free_rx_resources(adapter); | |
2307 | err_setup_rx: | |
2308 | e1000e_free_tx_resources(adapter); | |
2309 | err_setup_tx: | |
2310 | e1000e_reset(adapter); | |
2311 | ||
2312 | return err; | |
2313 | } | |
2314 | ||
2315 | /** | |
2316 | * e1000_close - Disables a network interface | |
2317 | * @netdev: network interface device structure | |
2318 | * | |
2319 | * Returns 0, this is not allowed to fail | |
2320 | * | |
2321 | * The close entry point is called when an interface is de-activated | |
2322 | * by the OS. The hardware is still under the drivers control, but | |
2323 | * needs to be disabled. A global MAC reset is issued to stop the | |
2324 | * hardware, and all transmit and receive resources are freed. | |
2325 | **/ | |
2326 | static int e1000_close(struct net_device *netdev) | |
2327 | { | |
2328 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
2329 | ||
2330 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); | |
2331 | e1000e_down(adapter); | |
2332 | e1000_power_down_phy(adapter); | |
2333 | e1000_free_irq(adapter); | |
2334 | ||
2335 | e1000e_free_tx_resources(adapter); | |
2336 | e1000e_free_rx_resources(adapter); | |
2337 | ||
2338 | /* kill manageability vlan ID if supported, but not if a vlan with | |
2339 | * the same ID is registered on the host OS (let 8021q kill it) */ | |
2340 | if ((adapter->hw.mng_cookie.status & | |
2341 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && | |
2342 | !(adapter->vlgrp && | |
2343 | vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) | |
2344 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); | |
2345 | ||
2346 | /* If AMT is enabled, let the firmware know that the network | |
2347 | * interface is now closed */ | |
2348 | if ((adapter->flags & FLAG_HAS_AMT) && | |
2349 | e1000e_check_mng_mode(&adapter->hw)) | |
2350 | e1000_release_hw_control(adapter); | |
2351 | ||
2352 | return 0; | |
2353 | } | |
2354 | /** | |
2355 | * e1000_set_mac - Change the Ethernet Address of the NIC | |
2356 | * @netdev: network interface device structure | |
2357 | * @p: pointer to an address structure | |
2358 | * | |
2359 | * Returns 0 on success, negative on failure | |
2360 | **/ | |
2361 | static int e1000_set_mac(struct net_device *netdev, void *p) | |
2362 | { | |
2363 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
2364 | struct sockaddr *addr = p; | |
2365 | ||
2366 | if (!is_valid_ether_addr(addr->sa_data)) | |
2367 | return -EADDRNOTAVAIL; | |
2368 | ||
2369 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); | |
2370 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); | |
2371 | ||
2372 | e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0); | |
2373 | ||
2374 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { | |
2375 | /* activate the work around */ | |
2376 | e1000e_set_laa_state_82571(&adapter->hw, 1); | |
2377 | ||
2378 | /* Hold a copy of the LAA in RAR[14] This is done so that | |
2379 | * between the time RAR[0] gets clobbered and the time it | |
2380 | * gets fixed (in e1000_watchdog), the actual LAA is in one | |
2381 | * of the RARs and no incoming packets directed to this port | |
2382 | * are dropped. Eventually the LAA will be in RAR[0] and | |
2383 | * RAR[14] */ | |
2384 | e1000e_rar_set(&adapter->hw, | |
2385 | adapter->hw.mac.addr, | |
2386 | adapter->hw.mac.rar_entry_count - 1); | |
2387 | } | |
2388 | ||
2389 | return 0; | |
2390 | } | |
2391 | ||
2392 | /* Need to wait a few seconds after link up to get diagnostic information from | |
2393 | * the phy */ | |
2394 | static void e1000_update_phy_info(unsigned long data) | |
2395 | { | |
2396 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; | |
2397 | e1000_get_phy_info(&adapter->hw); | |
2398 | } | |
2399 | ||
2400 | /** | |
2401 | * e1000e_update_stats - Update the board statistics counters | |
2402 | * @adapter: board private structure | |
2403 | **/ | |
2404 | void e1000e_update_stats(struct e1000_adapter *adapter) | |
2405 | { | |
2406 | struct e1000_hw *hw = &adapter->hw; | |
2407 | struct pci_dev *pdev = adapter->pdev; | |
2408 | unsigned long irq_flags; | |
2409 | u16 phy_tmp; | |
2410 | ||
2411 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF | |
2412 | ||
2413 | /* | |
2414 | * Prevent stats update while adapter is being reset, or if the pci | |
2415 | * connection is down. | |
2416 | */ | |
2417 | if (adapter->link_speed == 0) | |
2418 | return; | |
2419 | if (pci_channel_offline(pdev)) | |
2420 | return; | |
2421 | ||
2422 | spin_lock_irqsave(&adapter->stats_lock, irq_flags); | |
2423 | ||
2424 | /* these counters are modified from e1000_adjust_tbi_stats, | |
2425 | * called from the interrupt context, so they must only | |
2426 | * be written while holding adapter->stats_lock | |
2427 | */ | |
2428 | ||
2429 | adapter->stats.crcerrs += er32(CRCERRS); | |
2430 | adapter->stats.gprc += er32(GPRC); | |
2431 | adapter->stats.gorcl += er32(GORCL); | |
2432 | adapter->stats.gorch += er32(GORCH); | |
2433 | adapter->stats.bprc += er32(BPRC); | |
2434 | adapter->stats.mprc += er32(MPRC); | |
2435 | adapter->stats.roc += er32(ROC); | |
2436 | ||
2437 | if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) { | |
2438 | adapter->stats.prc64 += er32(PRC64); | |
2439 | adapter->stats.prc127 += er32(PRC127); | |
2440 | adapter->stats.prc255 += er32(PRC255); | |
2441 | adapter->stats.prc511 += er32(PRC511); | |
2442 | adapter->stats.prc1023 += er32(PRC1023); | |
2443 | adapter->stats.prc1522 += er32(PRC1522); | |
2444 | adapter->stats.symerrs += er32(SYMERRS); | |
2445 | adapter->stats.sec += er32(SEC); | |
2446 | } | |
2447 | ||
2448 | adapter->stats.mpc += er32(MPC); | |
2449 | adapter->stats.scc += er32(SCC); | |
2450 | adapter->stats.ecol += er32(ECOL); | |
2451 | adapter->stats.mcc += er32(MCC); | |
2452 | adapter->stats.latecol += er32(LATECOL); | |
2453 | adapter->stats.dc += er32(DC); | |
2454 | adapter->stats.rlec += er32(RLEC); | |
2455 | adapter->stats.xonrxc += er32(XONRXC); | |
2456 | adapter->stats.xontxc += er32(XONTXC); | |
2457 | adapter->stats.xoffrxc += er32(XOFFRXC); | |
2458 | adapter->stats.xofftxc += er32(XOFFTXC); | |
2459 | adapter->stats.fcruc += er32(FCRUC); | |
2460 | adapter->stats.gptc += er32(GPTC); | |
2461 | adapter->stats.gotcl += er32(GOTCL); | |
2462 | adapter->stats.gotch += er32(GOTCH); | |
2463 | adapter->stats.rnbc += er32(RNBC); | |
2464 | adapter->stats.ruc += er32(RUC); | |
2465 | adapter->stats.rfc += er32(RFC); | |
2466 | adapter->stats.rjc += er32(RJC); | |
2467 | adapter->stats.torl += er32(TORL); | |
2468 | adapter->stats.torh += er32(TORH); | |
2469 | adapter->stats.totl += er32(TOTL); | |
2470 | adapter->stats.toth += er32(TOTH); | |
2471 | adapter->stats.tpr += er32(TPR); | |
2472 | ||
2473 | if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) { | |
2474 | adapter->stats.ptc64 += er32(PTC64); | |
2475 | adapter->stats.ptc127 += er32(PTC127); | |
2476 | adapter->stats.ptc255 += er32(PTC255); | |
2477 | adapter->stats.ptc511 += er32(PTC511); | |
2478 | adapter->stats.ptc1023 += er32(PTC1023); | |
2479 | adapter->stats.ptc1522 += er32(PTC1522); | |
2480 | } | |
2481 | ||
2482 | adapter->stats.mptc += er32(MPTC); | |
2483 | adapter->stats.bptc += er32(BPTC); | |
2484 | ||
2485 | /* used for adaptive IFS */ | |
2486 | ||
2487 | hw->mac.tx_packet_delta = er32(TPT); | |
2488 | adapter->stats.tpt += hw->mac.tx_packet_delta; | |
2489 | hw->mac.collision_delta = er32(COLC); | |
2490 | adapter->stats.colc += hw->mac.collision_delta; | |
2491 | ||
2492 | adapter->stats.algnerrc += er32(ALGNERRC); | |
2493 | adapter->stats.rxerrc += er32(RXERRC); | |
2494 | adapter->stats.tncrs += er32(TNCRS); | |
2495 | adapter->stats.cexterr += er32(CEXTERR); | |
2496 | adapter->stats.tsctc += er32(TSCTC); | |
2497 | adapter->stats.tsctfc += er32(TSCTFC); | |
2498 | ||
2499 | adapter->stats.iac += er32(IAC); | |
2500 | ||
2501 | if (adapter->flags & FLAG_HAS_STATS_ICR_ICT) { | |
2502 | adapter->stats.icrxoc += er32(ICRXOC); | |
2503 | adapter->stats.icrxptc += er32(ICRXPTC); | |
2504 | adapter->stats.icrxatc += er32(ICRXATC); | |
2505 | adapter->stats.ictxptc += er32(ICTXPTC); | |
2506 | adapter->stats.ictxatc += er32(ICTXATC); | |
2507 | adapter->stats.ictxqec += er32(ICTXQEC); | |
2508 | adapter->stats.ictxqmtc += er32(ICTXQMTC); | |
2509 | adapter->stats.icrxdmtc += er32(ICRXDMTC); | |
2510 | } | |
2511 | ||
2512 | /* Fill out the OS statistics structure */ | |
bc7f75fa AK |
2513 | adapter->net_stats.multicast = adapter->stats.mprc; |
2514 | adapter->net_stats.collisions = adapter->stats.colc; | |
2515 | ||
2516 | /* Rx Errors */ | |
2517 | ||
2518 | /* RLEC on some newer hardware can be incorrect so build | |
2519 | * our own version based on RUC and ROC */ | |
2520 | adapter->net_stats.rx_errors = adapter->stats.rxerrc + | |
2521 | adapter->stats.crcerrs + adapter->stats.algnerrc + | |
2522 | adapter->stats.ruc + adapter->stats.roc + | |
2523 | adapter->stats.cexterr; | |
2524 | adapter->net_stats.rx_length_errors = adapter->stats.ruc + | |
2525 | adapter->stats.roc; | |
2526 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; | |
2527 | adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; | |
2528 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; | |
2529 | ||
2530 | /* Tx Errors */ | |
2531 | adapter->net_stats.tx_errors = adapter->stats.ecol + | |
2532 | adapter->stats.latecol; | |
2533 | adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; | |
2534 | adapter->net_stats.tx_window_errors = adapter->stats.latecol; | |
2535 | adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; | |
2536 | ||
2537 | /* Tx Dropped needs to be maintained elsewhere */ | |
2538 | ||
2539 | /* Phy Stats */ | |
2540 | if (hw->media_type == e1000_media_type_copper) { | |
2541 | if ((adapter->link_speed == SPEED_1000) && | |
2542 | (!e1e_rphy(hw, PHY_1000T_STATUS, &phy_tmp))) { | |
2543 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; | |
2544 | adapter->phy_stats.idle_errors += phy_tmp; | |
2545 | } | |
2546 | } | |
2547 | ||
2548 | /* Management Stats */ | |
2549 | adapter->stats.mgptc += er32(MGTPTC); | |
2550 | adapter->stats.mgprc += er32(MGTPRC); | |
2551 | adapter->stats.mgpdc += er32(MGTPDC); | |
2552 | ||
2553 | spin_unlock_irqrestore(&adapter->stats_lock, irq_flags); | |
2554 | } | |
2555 | ||
2556 | static void e1000_print_link_info(struct e1000_adapter *adapter) | |
2557 | { | |
2558 | struct net_device *netdev = adapter->netdev; | |
2559 | struct e1000_hw *hw = &adapter->hw; | |
2560 | u32 ctrl = er32(CTRL); | |
2561 | ||
2562 | ndev_info(netdev, | |
2563 | "Link is Up %d Mbps %s, Flow Control: %s\n", | |
2564 | adapter->link_speed, | |
2565 | (adapter->link_duplex == FULL_DUPLEX) ? | |
2566 | "Full Duplex" : "Half Duplex", | |
2567 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ? | |
2568 | "RX/TX" : | |
2569 | ((ctrl & E1000_CTRL_RFCE) ? "RX" : | |
2570 | ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" ))); | |
2571 | } | |
2572 | ||
2573 | /** | |
2574 | * e1000_watchdog - Timer Call-back | |
2575 | * @data: pointer to adapter cast into an unsigned long | |
2576 | **/ | |
2577 | static void e1000_watchdog(unsigned long data) | |
2578 | { | |
2579 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; | |
2580 | ||
2581 | /* Do the rest outside of interrupt context */ | |
2582 | schedule_work(&adapter->watchdog_task); | |
2583 | ||
2584 | /* TODO: make this use queue_delayed_work() */ | |
2585 | } | |
2586 | ||
2587 | static void e1000_watchdog_task(struct work_struct *work) | |
2588 | { | |
2589 | struct e1000_adapter *adapter = container_of(work, | |
2590 | struct e1000_adapter, watchdog_task); | |
2591 | ||
2592 | struct net_device *netdev = adapter->netdev; | |
2593 | struct e1000_mac_info *mac = &adapter->hw.mac; | |
2594 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
2595 | struct e1000_hw *hw = &adapter->hw; | |
2596 | u32 link, tctl; | |
2597 | s32 ret_val; | |
2598 | int tx_pending = 0; | |
2599 | ||
2600 | if ((netif_carrier_ok(netdev)) && | |
2601 | (er32(STATUS) & E1000_STATUS_LU)) | |
2602 | goto link_up; | |
2603 | ||
2604 | ret_val = mac->ops.check_for_link(hw); | |
2605 | if ((ret_val == E1000_ERR_PHY) && | |
2606 | (adapter->hw.phy.type == e1000_phy_igp_3) && | |
2607 | (er32(CTRL) & | |
2608 | E1000_PHY_CTRL_GBE_DISABLE)) { | |
2609 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ | |
2610 | ndev_info(netdev, | |
2611 | "Gigabit has been disabled, downgrading speed\n"); | |
2612 | } | |
2613 | ||
2614 | if ((e1000e_enable_tx_pkt_filtering(hw)) && | |
2615 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) | |
2616 | e1000_update_mng_vlan(adapter); | |
2617 | ||
2618 | if ((adapter->hw.media_type == e1000_media_type_internal_serdes) && | |
2619 | !(er32(TXCW) & E1000_TXCW_ANE)) | |
2620 | link = adapter->hw.mac.serdes_has_link; | |
2621 | else | |
2622 | link = er32(STATUS) & E1000_STATUS_LU; | |
2623 | ||
2624 | if (link) { | |
2625 | if (!netif_carrier_ok(netdev)) { | |
2626 | bool txb2b = 1; | |
2627 | mac->ops.get_link_up_info(&adapter->hw, | |
2628 | &adapter->link_speed, | |
2629 | &adapter->link_duplex); | |
2630 | e1000_print_link_info(adapter); | |
2631 | /* tweak tx_queue_len according to speed/duplex | |
2632 | * and adjust the timeout factor */ | |
2633 | netdev->tx_queue_len = adapter->tx_queue_len; | |
2634 | adapter->tx_timeout_factor = 1; | |
2635 | switch (adapter->link_speed) { | |
2636 | case SPEED_10: | |
2637 | txb2b = 0; | |
2638 | netdev->tx_queue_len = 10; | |
2639 | adapter->tx_timeout_factor = 14; | |
2640 | break; | |
2641 | case SPEED_100: | |
2642 | txb2b = 0; | |
2643 | netdev->tx_queue_len = 100; | |
2644 | /* maybe add some timeout factor ? */ | |
2645 | break; | |
2646 | } | |
2647 | ||
2648 | /* workaround: re-program speed mode bit after | |
2649 | * link-up event */ | |
2650 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && | |
2651 | !txb2b) { | |
2652 | u32 tarc0; | |
2653 | tarc0 = er32(TARC0); | |
2654 | tarc0 &= ~SPEED_MODE_BIT; | |
2655 | ew32(TARC0, tarc0); | |
2656 | } | |
2657 | ||
2658 | /* disable TSO for pcie and 10/100 speeds, to avoid | |
2659 | * some hardware issues */ | |
2660 | if (!(adapter->flags & FLAG_TSO_FORCE)) { | |
2661 | switch (adapter->link_speed) { | |
2662 | case SPEED_10: | |
2663 | case SPEED_100: | |
2664 | ndev_info(netdev, | |
2665 | "10/100 speed: disabling TSO\n"); | |
2666 | netdev->features &= ~NETIF_F_TSO; | |
2667 | netdev->features &= ~NETIF_F_TSO6; | |
2668 | break; | |
2669 | case SPEED_1000: | |
2670 | netdev->features |= NETIF_F_TSO; | |
2671 | netdev->features |= NETIF_F_TSO6; | |
2672 | break; | |
2673 | default: | |
2674 | /* oops */ | |
2675 | break; | |
2676 | } | |
2677 | } | |
2678 | ||
2679 | /* enable transmits in the hardware, need to do this | |
2680 | * after setting TARC0 */ | |
2681 | tctl = er32(TCTL); | |
2682 | tctl |= E1000_TCTL_EN; | |
2683 | ew32(TCTL, tctl); | |
2684 | ||
2685 | netif_carrier_on(netdev); | |
2686 | netif_wake_queue(netdev); | |
2687 | ||
2688 | if (!test_bit(__E1000_DOWN, &adapter->state)) | |
2689 | mod_timer(&adapter->phy_info_timer, | |
2690 | round_jiffies(jiffies + 2 * HZ)); | |
2691 | } else { | |
2692 | /* make sure the receive unit is started */ | |
2693 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) { | |
2694 | u32 rctl = er32(RCTL); | |
2695 | ew32(RCTL, rctl | | |
2696 | E1000_RCTL_EN); | |
2697 | } | |
2698 | } | |
2699 | } else { | |
2700 | if (netif_carrier_ok(netdev)) { | |
2701 | adapter->link_speed = 0; | |
2702 | adapter->link_duplex = 0; | |
2703 | ndev_info(netdev, "Link is Down\n"); | |
2704 | netif_carrier_off(netdev); | |
2705 | netif_stop_queue(netdev); | |
2706 | if (!test_bit(__E1000_DOWN, &adapter->state)) | |
2707 | mod_timer(&adapter->phy_info_timer, | |
2708 | round_jiffies(jiffies + 2 * HZ)); | |
2709 | ||
2710 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) | |
2711 | schedule_work(&adapter->reset_task); | |
2712 | } | |
2713 | } | |
2714 | ||
2715 | link_up: | |
2716 | e1000e_update_stats(adapter); | |
2717 | ||
2718 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; | |
2719 | adapter->tpt_old = adapter->stats.tpt; | |
2720 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; | |
2721 | adapter->colc_old = adapter->stats.colc; | |
2722 | ||
2723 | adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; | |
2724 | adapter->gorcl_old = adapter->stats.gorcl; | |
2725 | adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; | |
2726 | adapter->gotcl_old = adapter->stats.gotcl; | |
2727 | ||
2728 | e1000e_update_adaptive(&adapter->hw); | |
2729 | ||
2730 | if (!netif_carrier_ok(netdev)) { | |
2731 | tx_pending = (e1000_desc_unused(tx_ring) + 1 < | |
2732 | tx_ring->count); | |
2733 | if (tx_pending) { | |
2734 | /* We've lost link, so the controller stops DMA, | |
2735 | * but we've got queued Tx work that's never going | |
2736 | * to get done, so reset controller to flush Tx. | |
2737 | * (Do the reset outside of interrupt context). */ | |
2738 | adapter->tx_timeout_count++; | |
2739 | schedule_work(&adapter->reset_task); | |
2740 | } | |
2741 | } | |
2742 | ||
2743 | /* Cause software interrupt to ensure rx ring is cleaned */ | |
2744 | ew32(ICS, E1000_ICS_RXDMT0); | |
2745 | ||
2746 | /* Force detection of hung controller every watchdog period */ | |
2747 | adapter->detect_tx_hung = 1; | |
2748 | ||
2749 | /* With 82571 controllers, LAA may be overwritten due to controller | |
2750 | * reset from the other port. Set the appropriate LAA in RAR[0] */ | |
2751 | if (e1000e_get_laa_state_82571(hw)) | |
2752 | e1000e_rar_set(hw, adapter->hw.mac.addr, 0); | |
2753 | ||
2754 | /* Reset the timer */ | |
2755 | if (!test_bit(__E1000_DOWN, &adapter->state)) | |
2756 | mod_timer(&adapter->watchdog_timer, | |
2757 | round_jiffies(jiffies + 2 * HZ)); | |
2758 | } | |
2759 | ||
2760 | #define E1000_TX_FLAGS_CSUM 0x00000001 | |
2761 | #define E1000_TX_FLAGS_VLAN 0x00000002 | |
2762 | #define E1000_TX_FLAGS_TSO 0x00000004 | |
2763 | #define E1000_TX_FLAGS_IPV4 0x00000008 | |
2764 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 | |
2765 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 | |
2766 | ||
2767 | static int e1000_tso(struct e1000_adapter *adapter, | |
2768 | struct sk_buff *skb) | |
2769 | { | |
2770 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
2771 | struct e1000_context_desc *context_desc; | |
2772 | struct e1000_buffer *buffer_info; | |
2773 | unsigned int i; | |
2774 | u32 cmd_length = 0; | |
2775 | u16 ipcse = 0, tucse, mss; | |
2776 | u8 ipcss, ipcso, tucss, tucso, hdr_len; | |
2777 | int err; | |
2778 | ||
2779 | if (skb_is_gso(skb)) { | |
2780 | if (skb_header_cloned(skb)) { | |
2781 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); | |
2782 | if (err) | |
2783 | return err; | |
2784 | } | |
2785 | ||
2786 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); | |
2787 | mss = skb_shinfo(skb)->gso_size; | |
2788 | if (skb->protocol == htons(ETH_P_IP)) { | |
2789 | struct iphdr *iph = ip_hdr(skb); | |
2790 | iph->tot_len = 0; | |
2791 | iph->check = 0; | |
2792 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, | |
2793 | iph->daddr, 0, | |
2794 | IPPROTO_TCP, | |
2795 | 0); | |
2796 | cmd_length = E1000_TXD_CMD_IP; | |
2797 | ipcse = skb_transport_offset(skb) - 1; | |
2798 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { | |
2799 | ipv6_hdr(skb)->payload_len = 0; | |
2800 | tcp_hdr(skb)->check = | |
2801 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, | |
2802 | &ipv6_hdr(skb)->daddr, | |
2803 | 0, IPPROTO_TCP, 0); | |
2804 | ipcse = 0; | |
2805 | } | |
2806 | ipcss = skb_network_offset(skb); | |
2807 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; | |
2808 | tucss = skb_transport_offset(skb); | |
2809 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; | |
2810 | tucse = 0; | |
2811 | ||
2812 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | | |
2813 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); | |
2814 | ||
2815 | i = tx_ring->next_to_use; | |
2816 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); | |
2817 | buffer_info = &tx_ring->buffer_info[i]; | |
2818 | ||
2819 | context_desc->lower_setup.ip_fields.ipcss = ipcss; | |
2820 | context_desc->lower_setup.ip_fields.ipcso = ipcso; | |
2821 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); | |
2822 | context_desc->upper_setup.tcp_fields.tucss = tucss; | |
2823 | context_desc->upper_setup.tcp_fields.tucso = tucso; | |
2824 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); | |
2825 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); | |
2826 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; | |
2827 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); | |
2828 | ||
2829 | buffer_info->time_stamp = jiffies; | |
2830 | buffer_info->next_to_watch = i; | |
2831 | ||
2832 | i++; | |
2833 | if (i == tx_ring->count) | |
2834 | i = 0; | |
2835 | tx_ring->next_to_use = i; | |
2836 | ||
2837 | return 1; | |
2838 | } | |
2839 | ||
2840 | return 0; | |
2841 | } | |
2842 | ||
2843 | static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb) | |
2844 | { | |
2845 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
2846 | struct e1000_context_desc *context_desc; | |
2847 | struct e1000_buffer *buffer_info; | |
2848 | unsigned int i; | |
2849 | u8 css; | |
2850 | ||
2851 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | |
2852 | css = skb_transport_offset(skb); | |
2853 | ||
2854 | i = tx_ring->next_to_use; | |
2855 | buffer_info = &tx_ring->buffer_info[i]; | |
2856 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); | |
2857 | ||
2858 | context_desc->lower_setup.ip_config = 0; | |
2859 | context_desc->upper_setup.tcp_fields.tucss = css; | |
2860 | context_desc->upper_setup.tcp_fields.tucso = | |
2861 | css + skb->csum_offset; | |
2862 | context_desc->upper_setup.tcp_fields.tucse = 0; | |
2863 | context_desc->tcp_seg_setup.data = 0; | |
2864 | context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT); | |
2865 | ||
2866 | buffer_info->time_stamp = jiffies; | |
2867 | buffer_info->next_to_watch = i; | |
2868 | ||
2869 | i++; | |
2870 | if (i == tx_ring->count) | |
2871 | i = 0; | |
2872 | tx_ring->next_to_use = i; | |
2873 | ||
2874 | return 1; | |
2875 | } | |
2876 | ||
2877 | return 0; | |
2878 | } | |
2879 | ||
2880 | #define E1000_MAX_PER_TXD 8192 | |
2881 | #define E1000_MAX_TXD_PWR 12 | |
2882 | ||
2883 | static int e1000_tx_map(struct e1000_adapter *adapter, | |
2884 | struct sk_buff *skb, unsigned int first, | |
2885 | unsigned int max_per_txd, unsigned int nr_frags, | |
2886 | unsigned int mss) | |
2887 | { | |
2888 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
2889 | struct e1000_buffer *buffer_info; | |
2890 | unsigned int len = skb->len - skb->data_len; | |
2891 | unsigned int offset = 0, size, count = 0, i; | |
2892 | unsigned int f; | |
2893 | ||
2894 | i = tx_ring->next_to_use; | |
2895 | ||
2896 | while (len) { | |
2897 | buffer_info = &tx_ring->buffer_info[i]; | |
2898 | size = min(len, max_per_txd); | |
2899 | ||
2900 | /* Workaround for premature desc write-backs | |
2901 | * in TSO mode. Append 4-byte sentinel desc */ | |
2902 | if (mss && !nr_frags && size == len && size > 8) | |
2903 | size -= 4; | |
2904 | ||
2905 | buffer_info->length = size; | |
2906 | /* set time_stamp *before* dma to help avoid a possible race */ | |
2907 | buffer_info->time_stamp = jiffies; | |
2908 | buffer_info->dma = | |
2909 | pci_map_single(adapter->pdev, | |
2910 | skb->data + offset, | |
2911 | size, | |
2912 | PCI_DMA_TODEVICE); | |
2913 | if (pci_dma_mapping_error(buffer_info->dma)) { | |
2914 | dev_err(&adapter->pdev->dev, "TX DMA map failed\n"); | |
2915 | adapter->tx_dma_failed++; | |
2916 | return -1; | |
2917 | } | |
2918 | buffer_info->next_to_watch = i; | |
2919 | ||
2920 | len -= size; | |
2921 | offset += size; | |
2922 | count++; | |
2923 | i++; | |
2924 | if (i == tx_ring->count) | |
2925 | i = 0; | |
2926 | } | |
2927 | ||
2928 | for (f = 0; f < nr_frags; f++) { | |
2929 | struct skb_frag_struct *frag; | |
2930 | ||
2931 | frag = &skb_shinfo(skb)->frags[f]; | |
2932 | len = frag->size; | |
2933 | offset = frag->page_offset; | |
2934 | ||
2935 | while (len) { | |
2936 | buffer_info = &tx_ring->buffer_info[i]; | |
2937 | size = min(len, max_per_txd); | |
2938 | /* Workaround for premature desc write-backs | |
2939 | * in TSO mode. Append 4-byte sentinel desc */ | |
2940 | if (mss && f == (nr_frags-1) && size == len && size > 8) | |
2941 | size -= 4; | |
2942 | ||
2943 | buffer_info->length = size; | |
2944 | buffer_info->time_stamp = jiffies; | |
2945 | buffer_info->dma = | |
2946 | pci_map_page(adapter->pdev, | |
2947 | frag->page, | |
2948 | offset, | |
2949 | size, | |
2950 | PCI_DMA_TODEVICE); | |
2951 | if (pci_dma_mapping_error(buffer_info->dma)) { | |
2952 | dev_err(&adapter->pdev->dev, | |
2953 | "TX DMA page map failed\n"); | |
2954 | adapter->tx_dma_failed++; | |
2955 | return -1; | |
2956 | } | |
2957 | ||
2958 | buffer_info->next_to_watch = i; | |
2959 | ||
2960 | len -= size; | |
2961 | offset += size; | |
2962 | count++; | |
2963 | ||
2964 | i++; | |
2965 | if (i == tx_ring->count) | |
2966 | i = 0; | |
2967 | } | |
2968 | } | |
2969 | ||
2970 | if (i == 0) | |
2971 | i = tx_ring->count - 1; | |
2972 | else | |
2973 | i--; | |
2974 | ||
2975 | tx_ring->buffer_info[i].skb = skb; | |
2976 | tx_ring->buffer_info[first].next_to_watch = i; | |
2977 | ||
2978 | return count; | |
2979 | } | |
2980 | ||
2981 | static void e1000_tx_queue(struct e1000_adapter *adapter, | |
2982 | int tx_flags, int count) | |
2983 | { | |
2984 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
2985 | struct e1000_tx_desc *tx_desc = NULL; | |
2986 | struct e1000_buffer *buffer_info; | |
2987 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; | |
2988 | unsigned int i; | |
2989 | ||
2990 | if (tx_flags & E1000_TX_FLAGS_TSO) { | |
2991 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | | |
2992 | E1000_TXD_CMD_TSE; | |
2993 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; | |
2994 | ||
2995 | if (tx_flags & E1000_TX_FLAGS_IPV4) | |
2996 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; | |
2997 | } | |
2998 | ||
2999 | if (tx_flags & E1000_TX_FLAGS_CSUM) { | |
3000 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; | |
3001 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; | |
3002 | } | |
3003 | ||
3004 | if (tx_flags & E1000_TX_FLAGS_VLAN) { | |
3005 | txd_lower |= E1000_TXD_CMD_VLE; | |
3006 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); | |
3007 | } | |
3008 | ||
3009 | i = tx_ring->next_to_use; | |
3010 | ||
3011 | while (count--) { | |
3012 | buffer_info = &tx_ring->buffer_info[i]; | |
3013 | tx_desc = E1000_TX_DESC(*tx_ring, i); | |
3014 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); | |
3015 | tx_desc->lower.data = | |
3016 | cpu_to_le32(txd_lower | buffer_info->length); | |
3017 | tx_desc->upper.data = cpu_to_le32(txd_upper); | |
3018 | ||
3019 | i++; | |
3020 | if (i == tx_ring->count) | |
3021 | i = 0; | |
3022 | } | |
3023 | ||
3024 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); | |
3025 | ||
3026 | /* Force memory writes to complete before letting h/w | |
3027 | * know there are new descriptors to fetch. (Only | |
3028 | * applicable for weak-ordered memory model archs, | |
3029 | * such as IA-64). */ | |
3030 | wmb(); | |
3031 | ||
3032 | tx_ring->next_to_use = i; | |
3033 | writel(i, adapter->hw.hw_addr + tx_ring->tail); | |
3034 | /* we need this if more than one processor can write to our tail | |
3035 | * at a time, it synchronizes IO on IA64/Altix systems */ | |
3036 | mmiowb(); | |
3037 | } | |
3038 | ||
3039 | #define MINIMUM_DHCP_PACKET_SIZE 282 | |
3040 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, | |
3041 | struct sk_buff *skb) | |
3042 | { | |
3043 | struct e1000_hw *hw = &adapter->hw; | |
3044 | u16 length, offset; | |
3045 | ||
3046 | if (vlan_tx_tag_present(skb)) { | |
3047 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) | |
3048 | && (adapter->hw.mng_cookie.status & | |
3049 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) | |
3050 | return 0; | |
3051 | } | |
3052 | ||
3053 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) | |
3054 | return 0; | |
3055 | ||
3056 | if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP)) | |
3057 | return 0; | |
3058 | ||
3059 | { | |
3060 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14); | |
3061 | struct udphdr *udp; | |
3062 | ||
3063 | if (ip->protocol != IPPROTO_UDP) | |
3064 | return 0; | |
3065 | ||
3066 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); | |
3067 | if (ntohs(udp->dest) != 67) | |
3068 | return 0; | |
3069 | ||
3070 | offset = (u8 *)udp + 8 - skb->data; | |
3071 | length = skb->len - offset; | |
3072 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); | |
3073 | } | |
3074 | ||
3075 | return 0; | |
3076 | } | |
3077 | ||
3078 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) | |
3079 | { | |
3080 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3081 | ||
3082 | netif_stop_queue(netdev); | |
3083 | /* Herbert's original patch had: | |
3084 | * smp_mb__after_netif_stop_queue(); | |
3085 | * but since that doesn't exist yet, just open code it. */ | |
3086 | smp_mb(); | |
3087 | ||
3088 | /* We need to check again in a case another CPU has just | |
3089 | * made room available. */ | |
3090 | if (e1000_desc_unused(adapter->tx_ring) < size) | |
3091 | return -EBUSY; | |
3092 | ||
3093 | /* A reprieve! */ | |
3094 | netif_start_queue(netdev); | |
3095 | ++adapter->restart_queue; | |
3096 | return 0; | |
3097 | } | |
3098 | ||
3099 | static int e1000_maybe_stop_tx(struct net_device *netdev, int size) | |
3100 | { | |
3101 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3102 | ||
3103 | if (e1000_desc_unused(adapter->tx_ring) >= size) | |
3104 | return 0; | |
3105 | return __e1000_maybe_stop_tx(netdev, size); | |
3106 | } | |
3107 | ||
3108 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) | |
3109 | static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) | |
3110 | { | |
3111 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3112 | struct e1000_ring *tx_ring = adapter->tx_ring; | |
3113 | unsigned int first; | |
3114 | unsigned int max_per_txd = E1000_MAX_PER_TXD; | |
3115 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; | |
3116 | unsigned int tx_flags = 0; | |
4e6c709c | 3117 | unsigned int len = skb->len - skb->data_len; |
bc7f75fa | 3118 | unsigned long irq_flags; |
4e6c709c AK |
3119 | unsigned int nr_frags; |
3120 | unsigned int mss; | |
bc7f75fa AK |
3121 | int count = 0; |
3122 | int tso; | |
3123 | unsigned int f; | |
bc7f75fa AK |
3124 | |
3125 | if (test_bit(__E1000_DOWN, &adapter->state)) { | |
3126 | dev_kfree_skb_any(skb); | |
3127 | return NETDEV_TX_OK; | |
3128 | } | |
3129 | ||
3130 | if (skb->len <= 0) { | |
3131 | dev_kfree_skb_any(skb); | |
3132 | return NETDEV_TX_OK; | |
3133 | } | |
3134 | ||
3135 | mss = skb_shinfo(skb)->gso_size; | |
3136 | /* The controller does a simple calculation to | |
3137 | * make sure there is enough room in the FIFO before | |
3138 | * initiating the DMA for each buffer. The calc is: | |
3139 | * 4 = ceil(buffer len/mss). To make sure we don't | |
3140 | * overrun the FIFO, adjust the max buffer len if mss | |
3141 | * drops. */ | |
3142 | if (mss) { | |
3143 | u8 hdr_len; | |
3144 | max_per_txd = min(mss << 2, max_per_txd); | |
3145 | max_txd_pwr = fls(max_per_txd) - 1; | |
3146 | ||
3147 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data | |
3148 | * points to just header, pull a few bytes of payload from | |
3149 | * frags into skb->data */ | |
3150 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); | |
4e6c709c | 3151 | if (skb->data_len && (hdr_len == len)) { |
bc7f75fa AK |
3152 | unsigned int pull_size; |
3153 | ||
3154 | pull_size = min((unsigned int)4, skb->data_len); | |
3155 | if (!__pskb_pull_tail(skb, pull_size)) { | |
3156 | ndev_err(netdev, | |
3157 | "__pskb_pull_tail failed.\n"); | |
3158 | dev_kfree_skb_any(skb); | |
3159 | return NETDEV_TX_OK; | |
3160 | } | |
3161 | len = skb->len - skb->data_len; | |
3162 | } | |
3163 | } | |
3164 | ||
3165 | /* reserve a descriptor for the offload context */ | |
3166 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) | |
3167 | count++; | |
3168 | count++; | |
3169 | ||
3170 | count += TXD_USE_COUNT(len, max_txd_pwr); | |
3171 | ||
3172 | nr_frags = skb_shinfo(skb)->nr_frags; | |
3173 | for (f = 0; f < nr_frags; f++) | |
3174 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, | |
3175 | max_txd_pwr); | |
3176 | ||
3177 | if (adapter->hw.mac.tx_pkt_filtering) | |
3178 | e1000_transfer_dhcp_info(adapter, skb); | |
3179 | ||
3180 | if (!spin_trylock_irqsave(&adapter->tx_queue_lock, irq_flags)) | |
3181 | /* Collision - tell upper layer to requeue */ | |
3182 | return NETDEV_TX_LOCKED; | |
3183 | ||
3184 | /* need: count + 2 desc gap to keep tail from touching | |
3185 | * head, otherwise try next time */ | |
3186 | if (e1000_maybe_stop_tx(netdev, count + 2)) { | |
3187 | spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags); | |
3188 | return NETDEV_TX_BUSY; | |
3189 | } | |
3190 | ||
3191 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { | |
3192 | tx_flags |= E1000_TX_FLAGS_VLAN; | |
3193 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); | |
3194 | } | |
3195 | ||
3196 | first = tx_ring->next_to_use; | |
3197 | ||
3198 | tso = e1000_tso(adapter, skb); | |
3199 | if (tso < 0) { | |
3200 | dev_kfree_skb_any(skb); | |
3201 | spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags); | |
3202 | return NETDEV_TX_OK; | |
3203 | } | |
3204 | ||
3205 | if (tso) | |
3206 | tx_flags |= E1000_TX_FLAGS_TSO; | |
3207 | else if (e1000_tx_csum(adapter, skb)) | |
3208 | tx_flags |= E1000_TX_FLAGS_CSUM; | |
3209 | ||
3210 | /* Old method was to assume IPv4 packet by default if TSO was enabled. | |
3211 | * 82571 hardware supports TSO capabilities for IPv6 as well... | |
3212 | * no longer assume, we must. */ | |
3213 | if (skb->protocol == htons(ETH_P_IP)) | |
3214 | tx_flags |= E1000_TX_FLAGS_IPV4; | |
3215 | ||
3216 | count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss); | |
3217 | if (count < 0) { | |
3218 | /* handle pci_map_single() error in e1000_tx_map */ | |
3219 | dev_kfree_skb_any(skb); | |
3220 | spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags); | |
7b5dfe1a | 3221 | return NETDEV_TX_OK; |
bc7f75fa AK |
3222 | } |
3223 | ||
3224 | e1000_tx_queue(adapter, tx_flags, count); | |
3225 | ||
3226 | netdev->trans_start = jiffies; | |
3227 | ||
3228 | /* Make sure there is space in the ring for the next send. */ | |
3229 | e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2); | |
3230 | ||
3231 | spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags); | |
3232 | return NETDEV_TX_OK; | |
3233 | } | |
3234 | ||
3235 | /** | |
3236 | * e1000_tx_timeout - Respond to a Tx Hang | |
3237 | * @netdev: network interface device structure | |
3238 | **/ | |
3239 | static void e1000_tx_timeout(struct net_device *netdev) | |
3240 | { | |
3241 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3242 | ||
3243 | /* Do the reset outside of interrupt context */ | |
3244 | adapter->tx_timeout_count++; | |
3245 | schedule_work(&adapter->reset_task); | |
3246 | } | |
3247 | ||
3248 | static void e1000_reset_task(struct work_struct *work) | |
3249 | { | |
3250 | struct e1000_adapter *adapter; | |
3251 | adapter = container_of(work, struct e1000_adapter, reset_task); | |
3252 | ||
3253 | e1000e_reinit_locked(adapter); | |
3254 | } | |
3255 | ||
3256 | /** | |
3257 | * e1000_get_stats - Get System Network Statistics | |
3258 | * @netdev: network interface device structure | |
3259 | * | |
3260 | * Returns the address of the device statistics structure. | |
3261 | * The statistics are actually updated from the timer callback. | |
3262 | **/ | |
3263 | static struct net_device_stats *e1000_get_stats(struct net_device *netdev) | |
3264 | { | |
3265 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3266 | ||
3267 | /* only return the current stats */ | |
3268 | return &adapter->net_stats; | |
3269 | } | |
3270 | ||
3271 | /** | |
3272 | * e1000_change_mtu - Change the Maximum Transfer Unit | |
3273 | * @netdev: network interface device structure | |
3274 | * @new_mtu: new value for maximum frame size | |
3275 | * | |
3276 | * Returns 0 on success, negative on failure | |
3277 | **/ | |
3278 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) | |
3279 | { | |
3280 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3281 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; | |
3282 | ||
3283 | if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) || | |
3284 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { | |
3285 | ndev_err(netdev, "Invalid MTU setting\n"); | |
3286 | return -EINVAL; | |
3287 | } | |
3288 | ||
3289 | /* Jumbo frame size limits */ | |
3290 | if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) { | |
3291 | if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { | |
3292 | ndev_err(netdev, "Jumbo Frames not supported.\n"); | |
3293 | return -EINVAL; | |
3294 | } | |
3295 | if (adapter->hw.phy.type == e1000_phy_ife) { | |
3296 | ndev_err(netdev, "Jumbo Frames not supported.\n"); | |
3297 | return -EINVAL; | |
3298 | } | |
3299 | } | |
3300 | ||
3301 | #define MAX_STD_JUMBO_FRAME_SIZE 9234 | |
3302 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { | |
3303 | ndev_err(netdev, "MTU > 9216 not supported.\n"); | |
3304 | return -EINVAL; | |
3305 | } | |
3306 | ||
3307 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) | |
3308 | msleep(1); | |
3309 | /* e1000e_down has a dependency on max_frame_size */ | |
3310 | adapter->hw.mac.max_frame_size = max_frame; | |
3311 | if (netif_running(netdev)) | |
3312 | e1000e_down(adapter); | |
3313 | ||
3314 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN | |
3315 | * means we reserve 2 more, this pushes us to allocate from the next | |
3316 | * larger slab size. | |
f920c186 | 3317 | * i.e. RXBUFFER_2048 --> size-4096 slab */ |
bc7f75fa AK |
3318 | |
3319 | if (max_frame <= 256) | |
3320 | adapter->rx_buffer_len = 256; | |
3321 | else if (max_frame <= 512) | |
3322 | adapter->rx_buffer_len = 512; | |
3323 | else if (max_frame <= 1024) | |
3324 | adapter->rx_buffer_len = 1024; | |
3325 | else if (max_frame <= 2048) | |
3326 | adapter->rx_buffer_len = 2048; | |
3327 | else | |
3328 | adapter->rx_buffer_len = 4096; | |
3329 | ||
3330 | /* adjust allocation if LPE protects us, and we aren't using SBP */ | |
3331 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || | |
3332 | (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) | |
3333 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN | |
3334 | + ETH_FCS_LEN ; | |
3335 | ||
3336 | ndev_info(netdev, "changing MTU from %d to %d\n", | |
3337 | netdev->mtu, new_mtu); | |
3338 | netdev->mtu = new_mtu; | |
3339 | ||
3340 | if (netif_running(netdev)) | |
3341 | e1000e_up(adapter); | |
3342 | else | |
3343 | e1000e_reset(adapter); | |
3344 | ||
3345 | clear_bit(__E1000_RESETTING, &adapter->state); | |
3346 | ||
3347 | return 0; | |
3348 | } | |
3349 | ||
3350 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, | |
3351 | int cmd) | |
3352 | { | |
3353 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3354 | struct mii_ioctl_data *data = if_mii(ifr); | |
3355 | unsigned long irq_flags; | |
3356 | ||
3357 | if (adapter->hw.media_type != e1000_media_type_copper) | |
3358 | return -EOPNOTSUPP; | |
3359 | ||
3360 | switch (cmd) { | |
3361 | case SIOCGMIIPHY: | |
3362 | data->phy_id = adapter->hw.phy.addr; | |
3363 | break; | |
3364 | case SIOCGMIIREG: | |
3365 | if (!capable(CAP_NET_ADMIN)) | |
3366 | return -EPERM; | |
3367 | spin_lock_irqsave(&adapter->stats_lock, irq_flags); | |
3368 | if (e1e_rphy(&adapter->hw, data->reg_num & 0x1F, | |
3369 | &data->val_out)) { | |
3370 | spin_unlock_irqrestore(&adapter->stats_lock, irq_flags); | |
3371 | return -EIO; | |
3372 | } | |
3373 | spin_unlock_irqrestore(&adapter->stats_lock, irq_flags); | |
3374 | break; | |
3375 | case SIOCSMIIREG: | |
3376 | default: | |
3377 | return -EOPNOTSUPP; | |
3378 | } | |
3379 | return 0; | |
3380 | } | |
3381 | ||
3382 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) | |
3383 | { | |
3384 | switch (cmd) { | |
3385 | case SIOCGMIIPHY: | |
3386 | case SIOCGMIIREG: | |
3387 | case SIOCSMIIREG: | |
3388 | return e1000_mii_ioctl(netdev, ifr, cmd); | |
3389 | default: | |
3390 | return -EOPNOTSUPP; | |
3391 | } | |
3392 | } | |
3393 | ||
3394 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state) | |
3395 | { | |
3396 | struct net_device *netdev = pci_get_drvdata(pdev); | |
3397 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3398 | struct e1000_hw *hw = &adapter->hw; | |
3399 | u32 ctrl, ctrl_ext, rctl, status; | |
3400 | u32 wufc = adapter->wol; | |
3401 | int retval = 0; | |
3402 | ||
3403 | netif_device_detach(netdev); | |
3404 | ||
3405 | if (netif_running(netdev)) { | |
3406 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); | |
3407 | e1000e_down(adapter); | |
3408 | e1000_free_irq(adapter); | |
3409 | } | |
3410 | ||
3411 | retval = pci_save_state(pdev); | |
3412 | if (retval) | |
3413 | return retval; | |
3414 | ||
3415 | status = er32(STATUS); | |
3416 | if (status & E1000_STATUS_LU) | |
3417 | wufc &= ~E1000_WUFC_LNKC; | |
3418 | ||
3419 | if (wufc) { | |
3420 | e1000_setup_rctl(adapter); | |
3421 | e1000_set_multi(netdev); | |
3422 | ||
3423 | /* turn on all-multi mode if wake on multicast is enabled */ | |
3424 | if (wufc & E1000_WUFC_MC) { | |
3425 | rctl = er32(RCTL); | |
3426 | rctl |= E1000_RCTL_MPE; | |
3427 | ew32(RCTL, rctl); | |
3428 | } | |
3429 | ||
3430 | ctrl = er32(CTRL); | |
3431 | /* advertise wake from D3Cold */ | |
3432 | #define E1000_CTRL_ADVD3WUC 0x00100000 | |
3433 | /* phy power management enable */ | |
3434 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 | |
3435 | ctrl |= E1000_CTRL_ADVD3WUC | | |
3436 | E1000_CTRL_EN_PHY_PWR_MGMT; | |
3437 | ew32(CTRL, ctrl); | |
3438 | ||
3439 | if (adapter->hw.media_type == e1000_media_type_fiber || | |
3440 | adapter->hw.media_type == e1000_media_type_internal_serdes) { | |
3441 | /* keep the laser running in D3 */ | |
3442 | ctrl_ext = er32(CTRL_EXT); | |
3443 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; | |
3444 | ew32(CTRL_EXT, ctrl_ext); | |
3445 | } | |
3446 | ||
3447 | /* Allow time for pending master requests to run */ | |
3448 | e1000e_disable_pcie_master(&adapter->hw); | |
3449 | ||
3450 | ew32(WUC, E1000_WUC_PME_EN); | |
3451 | ew32(WUFC, wufc); | |
3452 | pci_enable_wake(pdev, PCI_D3hot, 1); | |
3453 | pci_enable_wake(pdev, PCI_D3cold, 1); | |
3454 | } else { | |
3455 | ew32(WUC, 0); | |
3456 | ew32(WUFC, 0); | |
3457 | pci_enable_wake(pdev, PCI_D3hot, 0); | |
3458 | pci_enable_wake(pdev, PCI_D3cold, 0); | |
3459 | } | |
3460 | ||
bc7f75fa AK |
3461 | /* make sure adapter isn't asleep if manageability is enabled */ |
3462 | if (adapter->flags & FLAG_MNG_PT_ENABLED) { | |
3463 | pci_enable_wake(pdev, PCI_D3hot, 1); | |
3464 | pci_enable_wake(pdev, PCI_D3cold, 1); | |
3465 | } | |
3466 | ||
3467 | if (adapter->hw.phy.type == e1000_phy_igp_3) | |
3468 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); | |
3469 | ||
3470 | /* Release control of h/w to f/w. If f/w is AMT enabled, this | |
3471 | * would have already happened in close and is redundant. */ | |
3472 | e1000_release_hw_control(adapter); | |
3473 | ||
3474 | pci_disable_device(pdev); | |
3475 | ||
3476 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); | |
3477 | ||
3478 | return 0; | |
3479 | } | |
3480 | ||
1eae4eb2 AK |
3481 | static void e1000e_disable_l1aspm(struct pci_dev *pdev) |
3482 | { | |
3483 | int pos; | |
1eae4eb2 AK |
3484 | u16 val; |
3485 | ||
3486 | /* | |
3487 | * 82573 workaround - disable L1 ASPM on mobile chipsets | |
3488 | * | |
3489 | * L1 ASPM on various mobile (ich7) chipsets do not behave properly | |
3490 | * resulting in lost data or garbage information on the pci-e link | |
3491 | * level. This could result in (false) bad EEPROM checksum errors, | |
3492 | * long ping times (up to 2s) or even a system freeze/hang. | |
3493 | * | |
3494 | * Unfortunately this feature saves about 1W power consumption when | |
3495 | * active. | |
3496 | */ | |
3497 | pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); | |
1eae4eb2 AK |
3498 | pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val); |
3499 | if (val & 0x2) { | |
3500 | dev_warn(&pdev->dev, "Disabling L1 ASPM\n"); | |
3501 | val &= ~0x2; | |
3502 | pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val); | |
3503 | } | |
3504 | } | |
3505 | ||
bc7f75fa AK |
3506 | #ifdef CONFIG_PM |
3507 | static int e1000_resume(struct pci_dev *pdev) | |
3508 | { | |
3509 | struct net_device *netdev = pci_get_drvdata(pdev); | |
3510 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3511 | struct e1000_hw *hw = &adapter->hw; | |
3512 | u32 err; | |
3513 | ||
3514 | pci_set_power_state(pdev, PCI_D0); | |
3515 | pci_restore_state(pdev); | |
1eae4eb2 | 3516 | e1000e_disable_l1aspm(pdev); |
bc7f75fa AK |
3517 | err = pci_enable_device(pdev); |
3518 | if (err) { | |
3519 | dev_err(&pdev->dev, | |
3520 | "Cannot enable PCI device from suspend\n"); | |
3521 | return err; | |
3522 | } | |
3523 | ||
3524 | pci_set_master(pdev); | |
3525 | ||
3526 | pci_enable_wake(pdev, PCI_D3hot, 0); | |
3527 | pci_enable_wake(pdev, PCI_D3cold, 0); | |
3528 | ||
3529 | if (netif_running(netdev)) { | |
3530 | err = e1000_request_irq(adapter); | |
3531 | if (err) | |
3532 | return err; | |
3533 | } | |
3534 | ||
3535 | e1000e_power_up_phy(adapter); | |
3536 | e1000e_reset(adapter); | |
3537 | ew32(WUS, ~0); | |
3538 | ||
3539 | e1000_init_manageability(adapter); | |
3540 | ||
3541 | if (netif_running(netdev)) | |
3542 | e1000e_up(adapter); | |
3543 | ||
3544 | netif_device_attach(netdev); | |
3545 | ||
3546 | /* If the controller has AMT, do not set DRV_LOAD until the interface | |
3547 | * is up. For all other cases, let the f/w know that the h/w is now | |
3548 | * under the control of the driver. */ | |
3549 | if (!(adapter->flags & FLAG_HAS_AMT) || !e1000e_check_mng_mode(&adapter->hw)) | |
3550 | e1000_get_hw_control(adapter); | |
3551 | ||
3552 | return 0; | |
3553 | } | |
3554 | #endif | |
3555 | ||
3556 | static void e1000_shutdown(struct pci_dev *pdev) | |
3557 | { | |
3558 | e1000_suspend(pdev, PMSG_SUSPEND); | |
3559 | } | |
3560 | ||
3561 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
3562 | /* | |
3563 | * Polling 'interrupt' - used by things like netconsole to send skbs | |
3564 | * without having to re-enable interrupts. It's not called while | |
3565 | * the interrupt routine is executing. | |
3566 | */ | |
3567 | static void e1000_netpoll(struct net_device *netdev) | |
3568 | { | |
3569 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3570 | ||
3571 | disable_irq(adapter->pdev->irq); | |
3572 | e1000_intr(adapter->pdev->irq, netdev); | |
3573 | ||
3574 | e1000_clean_tx_irq(adapter); | |
3575 | ||
3576 | enable_irq(adapter->pdev->irq); | |
3577 | } | |
3578 | #endif | |
3579 | ||
3580 | /** | |
3581 | * e1000_io_error_detected - called when PCI error is detected | |
3582 | * @pdev: Pointer to PCI device | |
3583 | * @state: The current pci connection state | |
3584 | * | |
3585 | * This function is called after a PCI bus error affecting | |
3586 | * this device has been detected. | |
3587 | */ | |
3588 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, | |
3589 | pci_channel_state_t state) | |
3590 | { | |
3591 | struct net_device *netdev = pci_get_drvdata(pdev); | |
3592 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3593 | ||
3594 | netif_device_detach(netdev); | |
3595 | ||
3596 | if (netif_running(netdev)) | |
3597 | e1000e_down(adapter); | |
3598 | pci_disable_device(pdev); | |
3599 | ||
3600 | /* Request a slot slot reset. */ | |
3601 | return PCI_ERS_RESULT_NEED_RESET; | |
3602 | } | |
3603 | ||
3604 | /** | |
3605 | * e1000_io_slot_reset - called after the pci bus has been reset. | |
3606 | * @pdev: Pointer to PCI device | |
3607 | * | |
3608 | * Restart the card from scratch, as if from a cold-boot. Implementation | |
3609 | * resembles the first-half of the e1000_resume routine. | |
3610 | */ | |
3611 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) | |
3612 | { | |
3613 | struct net_device *netdev = pci_get_drvdata(pdev); | |
3614 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3615 | struct e1000_hw *hw = &adapter->hw; | |
3616 | ||
1eae4eb2 | 3617 | e1000e_disable_l1aspm(pdev); |
bc7f75fa AK |
3618 | if (pci_enable_device(pdev)) { |
3619 | dev_err(&pdev->dev, | |
3620 | "Cannot re-enable PCI device after reset.\n"); | |
3621 | return PCI_ERS_RESULT_DISCONNECT; | |
3622 | } | |
3623 | pci_set_master(pdev); | |
3624 | ||
3625 | pci_enable_wake(pdev, PCI_D3hot, 0); | |
3626 | pci_enable_wake(pdev, PCI_D3cold, 0); | |
3627 | ||
3628 | e1000e_reset(adapter); | |
3629 | ew32(WUS, ~0); | |
3630 | ||
3631 | return PCI_ERS_RESULT_RECOVERED; | |
3632 | } | |
3633 | ||
3634 | /** | |
3635 | * e1000_io_resume - called when traffic can start flowing again. | |
3636 | * @pdev: Pointer to PCI device | |
3637 | * | |
3638 | * This callback is called when the error recovery driver tells us that | |
3639 | * its OK to resume normal operation. Implementation resembles the | |
3640 | * second-half of the e1000_resume routine. | |
3641 | */ | |
3642 | static void e1000_io_resume(struct pci_dev *pdev) | |
3643 | { | |
3644 | struct net_device *netdev = pci_get_drvdata(pdev); | |
3645 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
3646 | ||
3647 | e1000_init_manageability(adapter); | |
3648 | ||
3649 | if (netif_running(netdev)) { | |
3650 | if (e1000e_up(adapter)) { | |
3651 | dev_err(&pdev->dev, | |
3652 | "can't bring device back up after reset\n"); | |
3653 | return; | |
3654 | } | |
3655 | } | |
3656 | ||
3657 | netif_device_attach(netdev); | |
3658 | ||
3659 | /* If the controller has AMT, do not set DRV_LOAD until the interface | |
3660 | * is up. For all other cases, let the f/w know that the h/w is now | |
3661 | * under the control of the driver. */ | |
3662 | if (!(adapter->flags & FLAG_HAS_AMT) || | |
3663 | !e1000e_check_mng_mode(&adapter->hw)) | |
3664 | e1000_get_hw_control(adapter); | |
3665 | ||
3666 | } | |
3667 | ||
3668 | static void e1000_print_device_info(struct e1000_adapter *adapter) | |
3669 | { | |
3670 | struct e1000_hw *hw = &adapter->hw; | |
3671 | struct net_device *netdev = adapter->netdev; | |
3672 | u32 part_num; | |
3673 | ||
3674 | /* print bus type/speed/width info */ | |
3675 | ndev_info(netdev, "(PCI Express:2.5GB/s:%s) " | |
3676 | "%02x:%02x:%02x:%02x:%02x:%02x\n", | |
3677 | /* bus width */ | |
3678 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : | |
3679 | "Width x1"), | |
3680 | /* MAC address */ | |
3681 | netdev->dev_addr[0], netdev->dev_addr[1], | |
3682 | netdev->dev_addr[2], netdev->dev_addr[3], | |
3683 | netdev->dev_addr[4], netdev->dev_addr[5]); | |
3684 | ndev_info(netdev, "Intel(R) PRO/%s Network Connection\n", | |
3685 | (hw->phy.type == e1000_phy_ife) | |
3686 | ? "10/100" : "1000"); | |
3687 | e1000e_read_part_num(hw, &part_num); | |
3688 | ndev_info(netdev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", | |
3689 | hw->mac.type, hw->phy.type, | |
3690 | (part_num >> 8), (part_num & 0xff)); | |
3691 | } | |
3692 | ||
3693 | /** | |
3694 | * e1000_probe - Device Initialization Routine | |
3695 | * @pdev: PCI device information struct | |
3696 | * @ent: entry in e1000_pci_tbl | |
3697 | * | |
3698 | * Returns 0 on success, negative on failure | |
3699 | * | |
3700 | * e1000_probe initializes an adapter identified by a pci_dev structure. | |
3701 | * The OS initialization, configuring of the adapter private structure, | |
3702 | * and a hardware reset occur. | |
3703 | **/ | |
3704 | static int __devinit e1000_probe(struct pci_dev *pdev, | |
3705 | const struct pci_device_id *ent) | |
3706 | { | |
3707 | struct net_device *netdev; | |
3708 | struct e1000_adapter *adapter; | |
3709 | struct e1000_hw *hw; | |
3710 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; | |
3711 | unsigned long mmio_start, mmio_len; | |
3712 | unsigned long flash_start, flash_len; | |
3713 | ||
3714 | static int cards_found; | |
3715 | int i, err, pci_using_dac; | |
3716 | u16 eeprom_data = 0; | |
3717 | u16 eeprom_apme_mask = E1000_EEPROM_APME; | |
3718 | ||
1eae4eb2 | 3719 | e1000e_disable_l1aspm(pdev); |
bc7f75fa AK |
3720 | err = pci_enable_device(pdev); |
3721 | if (err) | |
3722 | return err; | |
3723 | ||
3724 | pci_using_dac = 0; | |
3725 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); | |
3726 | if (!err) { | |
3727 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); | |
3728 | if (!err) | |
3729 | pci_using_dac = 1; | |
3730 | } else { | |
3731 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); | |
3732 | if (err) { | |
3733 | err = pci_set_consistent_dma_mask(pdev, | |
3734 | DMA_32BIT_MASK); | |
3735 | if (err) { | |
3736 | dev_err(&pdev->dev, "No usable DMA " | |
3737 | "configuration, aborting\n"); | |
3738 | goto err_dma; | |
3739 | } | |
3740 | } | |
3741 | } | |
3742 | ||
3743 | err = pci_request_regions(pdev, e1000e_driver_name); | |
3744 | if (err) | |
3745 | goto err_pci_reg; | |
3746 | ||
3747 | pci_set_master(pdev); | |
3748 | ||
3749 | err = -ENOMEM; | |
3750 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); | |
3751 | if (!netdev) | |
3752 | goto err_alloc_etherdev; | |
3753 | ||
bc7f75fa AK |
3754 | SET_NETDEV_DEV(netdev, &pdev->dev); |
3755 | ||
3756 | pci_set_drvdata(pdev, netdev); | |
3757 | adapter = netdev_priv(netdev); | |
3758 | hw = &adapter->hw; | |
3759 | adapter->netdev = netdev; | |
3760 | adapter->pdev = pdev; | |
3761 | adapter->ei = ei; | |
3762 | adapter->pba = ei->pba; | |
3763 | adapter->flags = ei->flags; | |
3764 | adapter->hw.adapter = adapter; | |
3765 | adapter->hw.mac.type = ei->mac; | |
3766 | adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; | |
3767 | ||
3768 | mmio_start = pci_resource_start(pdev, 0); | |
3769 | mmio_len = pci_resource_len(pdev, 0); | |
3770 | ||
3771 | err = -EIO; | |
3772 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); | |
3773 | if (!adapter->hw.hw_addr) | |
3774 | goto err_ioremap; | |
3775 | ||
3776 | if ((adapter->flags & FLAG_HAS_FLASH) && | |
3777 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { | |
3778 | flash_start = pci_resource_start(pdev, 1); | |
3779 | flash_len = pci_resource_len(pdev, 1); | |
3780 | adapter->hw.flash_address = ioremap(flash_start, flash_len); | |
3781 | if (!adapter->hw.flash_address) | |
3782 | goto err_flashmap; | |
3783 | } | |
3784 | ||
3785 | /* construct the net_device struct */ | |
3786 | netdev->open = &e1000_open; | |
3787 | netdev->stop = &e1000_close; | |
3788 | netdev->hard_start_xmit = &e1000_xmit_frame; | |
3789 | netdev->get_stats = &e1000_get_stats; | |
3790 | netdev->set_multicast_list = &e1000_set_multi; | |
3791 | netdev->set_mac_address = &e1000_set_mac; | |
3792 | netdev->change_mtu = &e1000_change_mtu; | |
3793 | netdev->do_ioctl = &e1000_ioctl; | |
3794 | e1000e_set_ethtool_ops(netdev); | |
3795 | netdev->tx_timeout = &e1000_tx_timeout; | |
3796 | netdev->watchdog_timeo = 5 * HZ; | |
3797 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); | |
3798 | netdev->vlan_rx_register = e1000_vlan_rx_register; | |
3799 | netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; | |
3800 | netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid; | |
3801 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
3802 | netdev->poll_controller = e1000_netpoll; | |
3803 | #endif | |
3804 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); | |
3805 | ||
3806 | netdev->mem_start = mmio_start; | |
3807 | netdev->mem_end = mmio_start + mmio_len; | |
3808 | ||
3809 | adapter->bd_number = cards_found++; | |
3810 | ||
3811 | /* setup adapter struct */ | |
3812 | err = e1000_sw_init(adapter); | |
3813 | if (err) | |
3814 | goto err_sw_init; | |
3815 | ||
3816 | err = -EIO; | |
3817 | ||
3818 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); | |
3819 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); | |
3820 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); | |
3821 | ||
3822 | err = ei->get_invariants(adapter); | |
3823 | if (err) | |
3824 | goto err_hw_init; | |
3825 | ||
3826 | hw->mac.ops.get_bus_info(&adapter->hw); | |
3827 | ||
3828 | adapter->hw.phy.wait_for_link = 0; | |
3829 | ||
3830 | /* Copper options */ | |
3831 | if (adapter->hw.media_type == e1000_media_type_copper) { | |
3832 | adapter->hw.phy.mdix = AUTO_ALL_MODES; | |
3833 | adapter->hw.phy.disable_polarity_correction = 0; | |
3834 | adapter->hw.phy.ms_type = e1000_ms_hw_default; | |
3835 | } | |
3836 | ||
3837 | if (e1000_check_reset_block(&adapter->hw)) | |
3838 | ndev_info(netdev, | |
3839 | "PHY reset is blocked due to SOL/IDER session.\n"); | |
3840 | ||
3841 | netdev->features = NETIF_F_SG | | |
3842 | NETIF_F_HW_CSUM | | |
3843 | NETIF_F_HW_VLAN_TX | | |
3844 | NETIF_F_HW_VLAN_RX; | |
3845 | ||
3846 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) | |
3847 | netdev->features |= NETIF_F_HW_VLAN_FILTER; | |
3848 | ||
3849 | netdev->features |= NETIF_F_TSO; | |
3850 | netdev->features |= NETIF_F_TSO6; | |
3851 | ||
3852 | if (pci_using_dac) | |
3853 | netdev->features |= NETIF_F_HIGHDMA; | |
3854 | ||
3855 | /* We should not be using LLTX anymore, but we are still TX faster with | |
3856 | * it. */ | |
3857 | netdev->features |= NETIF_F_LLTX; | |
3858 | ||
3859 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) | |
3860 | adapter->flags |= FLAG_MNG_PT_ENABLED; | |
3861 | ||
3862 | /* before reading the NVM, reset the controller to | |
3863 | * put the device in a known good starting state */ | |
3864 | adapter->hw.mac.ops.reset_hw(&adapter->hw); | |
3865 | ||
3866 | /* | |
3867 | * systems with ASPM and others may see the checksum fail on the first | |
3868 | * attempt. Let's give it a few tries | |
3869 | */ | |
3870 | for (i = 0;; i++) { | |
3871 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) | |
3872 | break; | |
3873 | if (i == 2) { | |
3874 | ndev_err(netdev, "The NVM Checksum Is Not Valid\n"); | |
3875 | err = -EIO; | |
3876 | goto err_eeprom; | |
3877 | } | |
3878 | } | |
3879 | ||
3880 | /* copy the MAC address out of the NVM */ | |
3881 | if (e1000e_read_mac_addr(&adapter->hw)) | |
3882 | ndev_err(netdev, "NVM Read Error while reading MAC address\n"); | |
3883 | ||
3884 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); | |
3885 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); | |
3886 | ||
3887 | if (!is_valid_ether_addr(netdev->perm_addr)) { | |
3888 | ndev_err(netdev, "Invalid MAC Address: " | |
3889 | "%02x:%02x:%02x:%02x:%02x:%02x\n", | |
3890 | netdev->perm_addr[0], netdev->perm_addr[1], | |
3891 | netdev->perm_addr[2], netdev->perm_addr[3], | |
3892 | netdev->perm_addr[4], netdev->perm_addr[5]); | |
3893 | err = -EIO; | |
3894 | goto err_eeprom; | |
3895 | } | |
3896 | ||
3897 | init_timer(&adapter->watchdog_timer); | |
3898 | adapter->watchdog_timer.function = &e1000_watchdog; | |
3899 | adapter->watchdog_timer.data = (unsigned long) adapter; | |
3900 | ||
3901 | init_timer(&adapter->phy_info_timer); | |
3902 | adapter->phy_info_timer.function = &e1000_update_phy_info; | |
3903 | adapter->phy_info_timer.data = (unsigned long) adapter; | |
3904 | ||
3905 | INIT_WORK(&adapter->reset_task, e1000_reset_task); | |
3906 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); | |
3907 | ||
3908 | e1000e_check_options(adapter); | |
3909 | ||
3910 | /* Initialize link parameters. User can change them with ethtool */ | |
3911 | adapter->hw.mac.autoneg = 1; | |
309af40b | 3912 | adapter->fc_autoneg = 1; |
bc7f75fa AK |
3913 | adapter->hw.mac.original_fc = e1000_fc_default; |
3914 | adapter->hw.mac.fc = e1000_fc_default; | |
3915 | adapter->hw.phy.autoneg_advertised = 0x2f; | |
3916 | ||
3917 | /* ring size defaults */ | |
3918 | adapter->rx_ring->count = 256; | |
3919 | adapter->tx_ring->count = 256; | |
3920 | ||
3921 | /* | |
3922 | * Initial Wake on LAN setting - If APM wake is enabled in | |
3923 | * the EEPROM, enable the ACPI Magic Packet filter | |
3924 | */ | |
3925 | if (adapter->flags & FLAG_APME_IN_WUC) { | |
3926 | /* APME bit in EEPROM is mapped to WUC.APME */ | |
3927 | eeprom_data = er32(WUC); | |
3928 | eeprom_apme_mask = E1000_WUC_APME; | |
3929 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { | |
3930 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && | |
3931 | (adapter->hw.bus.func == 1)) | |
3932 | e1000_read_nvm(&adapter->hw, | |
3933 | NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); | |
3934 | else | |
3935 | e1000_read_nvm(&adapter->hw, | |
3936 | NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); | |
3937 | } | |
3938 | ||
3939 | /* fetch WoL from EEPROM */ | |
3940 | if (eeprom_data & eeprom_apme_mask) | |
3941 | adapter->eeprom_wol |= E1000_WUFC_MAG; | |
3942 | ||
3943 | /* | |
3944 | * now that we have the eeprom settings, apply the special cases | |
3945 | * where the eeprom may be wrong or the board simply won't support | |
3946 | * wake on lan on a particular port | |
3947 | */ | |
3948 | if (!(adapter->flags & FLAG_HAS_WOL)) | |
3949 | adapter->eeprom_wol = 0; | |
3950 | ||
3951 | /* initialize the wol settings based on the eeprom settings */ | |
3952 | adapter->wol = adapter->eeprom_wol; | |
3953 | ||
3954 | /* reset the hardware with the new settings */ | |
3955 | e1000e_reset(adapter); | |
3956 | ||
3957 | /* If the controller has AMT, do not set DRV_LOAD until the interface | |
3958 | * is up. For all other cases, let the f/w know that the h/w is now | |
3959 | * under the control of the driver. */ | |
3960 | if (!(adapter->flags & FLAG_HAS_AMT) || | |
3961 | !e1000e_check_mng_mode(&adapter->hw)) | |
3962 | e1000_get_hw_control(adapter); | |
3963 | ||
3964 | /* tell the stack to leave us alone until e1000_open() is called */ | |
3965 | netif_carrier_off(netdev); | |
3966 | netif_stop_queue(netdev); | |
3967 | ||
3968 | strcpy(netdev->name, "eth%d"); | |
3969 | err = register_netdev(netdev); | |
3970 | if (err) | |
3971 | goto err_register; | |
3972 | ||
3973 | e1000_print_device_info(adapter); | |
3974 | ||
3975 | return 0; | |
3976 | ||
3977 | err_register: | |
3978 | err_hw_init: | |
3979 | e1000_release_hw_control(adapter); | |
3980 | err_eeprom: | |
3981 | if (!e1000_check_reset_block(&adapter->hw)) | |
3982 | e1000_phy_hw_reset(&adapter->hw); | |
3983 | ||
3984 | if (adapter->hw.flash_address) | |
3985 | iounmap(adapter->hw.flash_address); | |
3986 | ||
3987 | err_flashmap: | |
3988 | kfree(adapter->tx_ring); | |
3989 | kfree(adapter->rx_ring); | |
3990 | err_sw_init: | |
3991 | iounmap(adapter->hw.hw_addr); | |
3992 | err_ioremap: | |
3993 | free_netdev(netdev); | |
3994 | err_alloc_etherdev: | |
3995 | pci_release_regions(pdev); | |
3996 | err_pci_reg: | |
3997 | err_dma: | |
3998 | pci_disable_device(pdev); | |
3999 | return err; | |
4000 | } | |
4001 | ||
4002 | /** | |
4003 | * e1000_remove - Device Removal Routine | |
4004 | * @pdev: PCI device information struct | |
4005 | * | |
4006 | * e1000_remove is called by the PCI subsystem to alert the driver | |
4007 | * that it should release a PCI device. The could be caused by a | |
4008 | * Hot-Plug event, or because the driver is going to be removed from | |
4009 | * memory. | |
4010 | **/ | |
4011 | static void __devexit e1000_remove(struct pci_dev *pdev) | |
4012 | { | |
4013 | struct net_device *netdev = pci_get_drvdata(pdev); | |
4014 | struct e1000_adapter *adapter = netdev_priv(netdev); | |
4015 | ||
4016 | /* flush_scheduled work may reschedule our watchdog task, so | |
4017 | * explicitly disable watchdog tasks from being rescheduled */ | |
4018 | set_bit(__E1000_DOWN, &adapter->state); | |
4019 | del_timer_sync(&adapter->watchdog_timer); | |
4020 | del_timer_sync(&adapter->phy_info_timer); | |
4021 | ||
4022 | flush_scheduled_work(); | |
4023 | ||
bc7f75fa AK |
4024 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
4025 | * would have already happened in close and is redundant. */ | |
4026 | e1000_release_hw_control(adapter); | |
4027 | ||
4028 | unregister_netdev(netdev); | |
4029 | ||
4030 | if (!e1000_check_reset_block(&adapter->hw)) | |
4031 | e1000_phy_hw_reset(&adapter->hw); | |
4032 | ||
4033 | kfree(adapter->tx_ring); | |
4034 | kfree(adapter->rx_ring); | |
4035 | ||
4036 | iounmap(adapter->hw.hw_addr); | |
4037 | if (adapter->hw.flash_address) | |
4038 | iounmap(adapter->hw.flash_address); | |
4039 | pci_release_regions(pdev); | |
4040 | ||
4041 | free_netdev(netdev); | |
4042 | ||
4043 | pci_disable_device(pdev); | |
4044 | } | |
4045 | ||
4046 | /* PCI Error Recovery (ERS) */ | |
4047 | static struct pci_error_handlers e1000_err_handler = { | |
4048 | .error_detected = e1000_io_error_detected, | |
4049 | .slot_reset = e1000_io_slot_reset, | |
4050 | .resume = e1000_io_resume, | |
4051 | }; | |
4052 | ||
4053 | static struct pci_device_id e1000_pci_tbl[] = { | |
bc7f75fa AK |
4054 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
4055 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, | |
4056 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, | |
4057 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 }, | |
4058 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, | |
4059 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, | |
040babf9 AK |
4060 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
4061 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, | |
4062 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, | |
bc7f75fa AK |
4063 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
4064 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, | |
4065 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, | |
4066 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, | |
4067 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, | |
4068 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, | |
4069 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, | |
4070 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), | |
4071 | board_80003es2lan }, | |
4072 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), | |
4073 | board_80003es2lan }, | |
4074 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), | |
4075 | board_80003es2lan }, | |
4076 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), | |
4077 | board_80003es2lan }, | |
4078 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, | |
4079 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, | |
4080 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, | |
4081 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, | |
4082 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, | |
4083 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, | |
4084 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, | |
bc7f75fa AK |
4085 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
4086 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, | |
4087 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, | |
4088 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, | |
4089 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, | |
4090 | ||
4091 | { } /* terminate list */ | |
4092 | }; | |
4093 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); | |
4094 | ||
4095 | /* PCI Device API Driver */ | |
4096 | static struct pci_driver e1000_driver = { | |
4097 | .name = e1000e_driver_name, | |
4098 | .id_table = e1000_pci_tbl, | |
4099 | .probe = e1000_probe, | |
4100 | .remove = __devexit_p(e1000_remove), | |
4101 | #ifdef CONFIG_PM | |
4102 | /* Power Managment Hooks */ | |
4103 | .suspend = e1000_suspend, | |
4104 | .resume = e1000_resume, | |
4105 | #endif | |
4106 | .shutdown = e1000_shutdown, | |
4107 | .err_handler = &e1000_err_handler | |
4108 | }; | |
4109 | ||
4110 | /** | |
4111 | * e1000_init_module - Driver Registration Routine | |
4112 | * | |
4113 | * e1000_init_module is the first routine called when the driver is | |
4114 | * loaded. All it does is register with the PCI subsystem. | |
4115 | **/ | |
4116 | static int __init e1000_init_module(void) | |
4117 | { | |
4118 | int ret; | |
4119 | printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n", | |
4120 | e1000e_driver_name, e1000e_driver_version); | |
4121 | printk(KERN_INFO "%s: Copyright (c) 1999-2007 Intel Corporation.\n", | |
4122 | e1000e_driver_name); | |
4123 | ret = pci_register_driver(&e1000_driver); | |
4124 | ||
4125 | return ret; | |
4126 | } | |
4127 | module_init(e1000_init_module); | |
4128 | ||
4129 | /** | |
4130 | * e1000_exit_module - Driver Exit Cleanup Routine | |
4131 | * | |
4132 | * e1000_exit_module is called just before the driver is removed | |
4133 | * from memory. | |
4134 | **/ | |
4135 | static void __exit e1000_exit_module(void) | |
4136 | { | |
4137 | pci_unregister_driver(&e1000_driver); | |
4138 | } | |
4139 | module_exit(e1000_exit_module); | |
4140 | ||
4141 | ||
4142 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); | |
4143 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); | |
4144 | MODULE_LICENSE("GPL"); | |
4145 | MODULE_VERSION(DRV_VERSION); | |
4146 | ||
4147 | /* e1000_main.c */ |