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