Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel PRO/1000 Linux driver |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4 | Copyright(c) 1999 - 2008 Intel Corporation. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
| 23 | Linux NICS <linux.nics@intel.com> |
| 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/types.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/pci.h> |
| 33 | #include <linux/vmalloc.h> |
| 34 | #include <linux/pagemap.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/netdevice.h> |
| 37 | #include <linux/tcp.h> |
| 38 | #include <linux/ipv6.h> |
| 39 | #include <net/checksum.h> |
| 40 | #include <net/ip6_checksum.h> |
| 41 | #include <linux/mii.h> |
| 42 | #include <linux/ethtool.h> |
| 43 | #include <linux/if_vlan.h> |
| 44 | #include <linux/cpu.h> |
| 45 | #include <linux/smp.h> |
| 46 | |
| 47 | #include "e1000.h" |
| 48 | |
| 49 | #define DRV_VERSION "0.2.0" |
| 50 | char e1000e_driver_name[] = "e1000e"; |
| 51 | const char e1000e_driver_version[] = DRV_VERSION; |
| 52 | |
| 53 | static const struct e1000_info *e1000_info_tbl[] = { |
| 54 | [board_82571] = &e1000_82571_info, |
| 55 | [board_82572] = &e1000_82572_info, |
| 56 | [board_82573] = &e1000_82573_info, |
| 57 | [board_80003es2lan] = &e1000_es2_info, |
| 58 | [board_ich8lan] = &e1000_ich8_info, |
| 59 | [board_ich9lan] = &e1000_ich9_info, |
| 60 | }; |
| 61 | |
| 62 | #ifdef DEBUG |
| 63 | /** |
| 64 | * e1000_get_hw_dev_name - return device name string |
| 65 | * used by hardware layer to print debugging information |
| 66 | **/ |
| 67 | char *e1000e_get_hw_dev_name(struct e1000_hw *hw) |
| 68 | { |
Auke Kok | 589c085 | 2007-10-04 11:38:43 -0700 | [diff] [blame] | 69 | return hw->adapter->netdev->name; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 85 | * e1000_receive_skb - helper function to handle Rx indications |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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, |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 94 | u8 status, __le16 vlan) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 141 | /* |
| 142 | * IP fragment with UDP payload |
| 143 | * Hardware complements the payload checksum, so we undo it |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 144 | * and then put the value in host order for further stack use. |
| 145 | */ |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 146 | __sum16 sum = (__force __sum16)htons(csum); |
| 147 | skb->csum = csum_unfold(~sum); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 186 | /* |
| 187 | * Make buffer alignment 2 beyond a 16 byte boundary |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 218 | /* |
| 219 | * Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 220 | * know there are new descriptors to fetch. (Only |
| 221 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 222 | * such as IA-64). |
| 223 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 252 | ps_page = &buffer_info->ps_pages[j]; |
| 253 | if (j >= adapter->rx_ps_pages) { |
| 254 | /* all unused desc entries get hw null ptr */ |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 255 | rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 256 | continue; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 257 | } |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 258 | if (!ps_page->page) { |
| 259 | ps_page->page = alloc_page(GFP_ATOMIC); |
| 260 | if (!ps_page->page) { |
| 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; |
| 273 | } |
| 274 | } |
| 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); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 292 | /* |
| 293 | * Make buffer alignment 2 beyond a 16 byte boundary |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 327 | /* |
| 328 | * Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 329 | * know there are new descriptors to fetch. (Only |
| 330 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 331 | * such as IA-64). |
| 332 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 333 | wmb(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 334 | /* |
| 335 | * Hardware increments by 16 bytes, but packet split |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
| 343 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 417 | total_rx_bytes += length; |
| 418 | total_rx_packets++; |
| 419 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 420 | /* |
| 421 | * code added for copybreak, this should improve |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 422 | * performance for small packets with large amounts |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 423 | * of reassembly being done in the stack |
| 424 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
| 469 | adapter->total_rx_packets += total_rx_packets; |
| 470 | adapter->total_rx_bytes += total_rx_bytes; |
Auke Kok | 4198869 | 2007-11-13 20:48:36 -0800 | [diff] [blame] | 471 | adapter->net_stats.rx_packets += total_rx_packets; |
| 472 | adapter->net_stats.rx_bytes += total_rx_bytes; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 473 | return cleaned; |
| 474 | } |
| 475 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 594 | /* |
| 595 | * Detect a transmit hang in hardware, this serializes the |
| 596 | * check with the clearing of time_stamp and movement of i |
| 597 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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)) |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 602 | && !(er32(STATUS) & E1000_STATUS_TXOFF)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
Auke Kok | 4198869 | 2007-11-13 20:48:36 -0800 | [diff] [blame] | 609 | adapter->net_stats.tx_packets += total_tx_packets; |
| 610 | adapter->net_stats.tx_bytes += total_tx_bytes; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 611 | return cleaned; |
| 612 | } |
| 613 | |
| 614 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 691 | /* |
| 692 | * this looks ugly, but it seems compiler issues make it |
| 693 | * more efficient than reusing j |
| 694 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 695 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 696 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 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 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 702 | if (l1 && (l1 <= copybreak) && |
| 703 | ((length + l1) <= adapter->rx_ps_bsize0)) { |
| 704 | u8 *vaddr; |
| 705 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 706 | ps_page = &buffer_info->ps_pages[0]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 707 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 708 | /* |
| 709 | * there is no documentation about how to call |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 710 | * kmap_atomic, so we can't hold the mapping |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 711 | * very long |
| 712 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 720 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 731 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
| 778 | adapter->total_rx_packets += total_rx_packets; |
| 779 | adapter->total_rx_bytes += total_rx_bytes; |
Auke Kok | 4198869 | 2007-11-13 20:48:36 -0800 | [diff] [blame] | 780 | adapter->net_stats.rx_packets += total_rx_packets; |
| 781 | adapter->net_stats.rx_bytes += total_rx_bytes; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 818 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 857 | /* |
| 858 | * read ICR disables interrupts using IAM |
| 859 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 860 | |
| 861 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 862 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 863 | /* |
| 864 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 865 | * disconnect (LSC) before accessing any PHY registers |
| 866 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 867 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 868 | (!(er32(STATUS) & E1000_STATUS_LU))) |
| 869 | e1000e_gig_downshift_workaround_ich8lan(hw); |
| 870 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 871 | /* |
| 872 | * 80003ES2LAN workaround-- For packet buffer work-around on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 873 | * link down event; disable receives here in the ISR and reset |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 874 | * adapter in watchdog |
| 875 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 881 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 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 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 918 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 919 | return IRQ_NONE; |
| 920 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 921 | /* |
| 922 | * Interrupt Auto-Mask...upon reading ICR, |
| 923 | * interrupts are masked. No need for the |
| 924 | * IMC write |
| 925 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 926 | |
| 927 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 928 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 929 | /* |
| 930 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 931 | * disconnect (LSC) before accessing any PHY registers |
| 932 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 933 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 934 | (!(er32(STATUS) & E1000_STATUS_LU))) |
| 935 | e1000e_gig_downshift_workaround_ich8lan(hw); |
| 936 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 937 | /* |
| 938 | * 80003ES2LAN workaround-- |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 948 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 969 | irq_handler_t handler = e1000_intr; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 970 | int irq_flags = IRQF_SHARED; |
| 971 | int err; |
| 972 | |
Andy Gospodarek | 9b71c5e | 2008-02-01 08:21:44 -0800 | [diff] [blame] | 973 | if (!pci_enable_msi(adapter->pdev)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 974 | adapter->flags |= FLAG_MSI_ENABLED; |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 975 | handler = e1000_intr_msi; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 976 | irq_flags = 0; |
| 977 | } |
| 978 | |
| 979 | err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name, |
| 980 | netdev); |
| 981 | if (err) { |
Andy Gospodarek | 9b71c5e | 2008-02-01 08:21:44 -0800 | [diff] [blame] | 982 | ndev_err(netdev, |
| 983 | "Unable to allocate %s interrupt (return: %d)\n", |
| 984 | adapter->flags & FLAG_MSI_ENABLED ? "MSI":"INTx", |
| 985 | err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 986 | if (adapter->flags & FLAG_MSI_ENABLED) |
| 987 | pci_disable_msi(adapter->pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 1023 | ew32(IMS, IMS_ENABLE_MASK); |
| 1024 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | * |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 1031 | * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1048 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | * |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 1056 | * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1074 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1140 | struct e1000_buffer *buffer_info; |
| 1141 | int i, size, desc_len, err = -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 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 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1166 | goto err_pages; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 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 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1179 | err: |
| 1180 | vfree(rx_ring->buffer_info); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1246 | int i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1247 | |
| 1248 | e1000_clean_rx_ring(adapter); |
| 1249 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1250 | for (i = 0; i < rx_ring->count; i++) { |
| 1251 | kfree(rx_ring->buffer_info[i].ps_pages); |
| 1252 | } |
| 1253 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1254 | vfree(rx_ring->buffer_info); |
| 1255 | rx_ring->buffer_info = NULL; |
| 1256 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 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 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1376 | /* |
| 1377 | * this attempts to bias the interrupt rate towards Bulk |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1378 | * by adding intermediate steps when interrupt rate is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1379 | * increasing |
| 1380 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1391 | * @napi: struct associated with this polling callback |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 1392 | * @budget: amount of packets driver is allowed to process this poll |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 1398 | int tx_cleaned = 0, work_done = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1399 | |
| 1400 | /* Must NOT use netdev_priv macro here. */ |
| 1401 | adapter = poll_dev->priv; |
| 1402 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1403 | /* |
| 1404 | * e1000_clean is called per-cpu. This lock protects |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1405 | * tx_ring from being cleaned by multiple cpus |
| 1406 | * simultaneously. A failure obtaining the lock means |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1407 | * tx_ring is currently being cleaned anyway. |
| 1408 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1409 | if (spin_trylock(&adapter->tx_queue_lock)) { |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 1410 | tx_cleaned = e1000_clean_tx_irq(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1411 | spin_unlock(&adapter->tx_queue_lock); |
| 1412 | } |
| 1413 | |
| 1414 | adapter->clean_rx(adapter, &work_done, budget); |
| 1415 | |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 1416 | if (tx_cleaned) |
| 1417 | work_done = budget; |
| 1418 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 1419 | /* If budget not fully consumed, exit the polling mode */ |
| 1420 | if (work_done < budget) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 1454 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1455 | e1000_irq_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1456 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 1457 | |
| 1458 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1459 | e1000_irq_enable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 1510 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1511 | e1000_irq_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 1548 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1549 | e1000_irq_enable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1578 | /* |
| 1579 | * enable receiving management packets to the host. this will probably |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1580 | * generate destination unreachable messages from the host OS, but |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1581 | * the packets will be handled on SMBUS |
| 1582 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1632 | /* Tx irq moderation */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 1642 | tarc = er32(TARC(0)); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1643 | /* |
| 1644 | * set the speed mode bit, we'll clear it if we're not at |
| 1645 | * gigabit link later |
| 1646 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1647 | #define SPEED_MODE_BIT (1 << 21) |
| 1648 | tarc |= SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 1649 | ew32(TARC(0), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | /* errata: program both queues to unweighted RR */ |
| 1653 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 1654 | tarc = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1655 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 1656 | ew32(TARC(0), tarc); |
| 1657 | tarc = er32(TARC(1)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1658 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 1659 | ew32(TARC(1), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Auke Kok | 5918bd8 | 2008-02-12 15:20:24 -0800 | [diff] [blame] | 1708 | /* Enable hardware CRC frame stripping */ |
| 1709 | rctl |= E1000_RCTL_SECRC; |
| 1710 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1767 | /* |
| 1768 | * disable packet split support for IPv6 extension headers, |
| 1769 | * because some malformed IPv6 headers can hang the Rx |
| 1770 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1771 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
| 1772 | E1000_RFCTL_NEW_IPV6_EXT_DIS); |
| 1773 | |
| 1774 | ew32(RFCTL, rfctl); |
| 1775 | |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 1776 | /* Enable Packet split descriptors */ |
| 1777 | rctl |= E1000_RCTL_DTYP_PS; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1799 | /* just started the receive unit, no need to restart */ |
| 1800 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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) |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1841 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1852 | /* |
| 1853 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 1854 | * the Base and Length of the Rx Descriptor Ring |
| 1855 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1870 | /* |
| 1871 | * IPv4 payload checksum for UDP fragments must be |
| 1872 | * used in conjunction with packet-split. |
| 1873 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1882 | /* |
| 1883 | * Enable early receives on supported devices, only takes effect when |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1884 | * packet size is equal or larger than the specified value (in 8 byte |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1885 | * units), e.g. using jumbo frames when setting to E1000_ERT_2048 |
| 1886 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | /** |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 1896 | * e1000_update_mc_addr_list - Update Multicast addresses |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | **/ |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 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) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1913 | { |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 1914 | hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 1968 | e1000_update_mc_addr_list(hw, mta_list, i, 1, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | */ |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 1976 | e1000_update_mc_addr_list(hw, NULL, 0, 1, mac->rar_entry_count); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | |
| 1980 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1981 | * e1000_configure - configure the hardware for Rx and Tx |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1994 | adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2010 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2011 | /* |
| 2012 | * According to the manual, the phy will retain its |
| 2013 | * settings across a power-down/up cycle |
| 2014 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 */ |
Auke Kok | 23b66e2 | 2008-02-11 09:25:51 -0800 | [diff] [blame] | 2035 | if (adapter->wol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2036 | return; |
| 2037 | |
| 2038 | /* non-copper PHY? */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2039 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2040 | return; |
| 2041 | |
| 2042 | /* reset is blocked because of a SoL/IDER session */ |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2043 | if (e1000e_check_mng_mode(hw) || e1000_check_reset_block(hw)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2044 | return; |
| 2045 | |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2046 | /* manageability (AMT) is enabled */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2063 | * properly configured for Rx, Tx etc. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2064 | */ |
| 2065 | void e1000e_reset(struct e1000_adapter *adapter) |
| 2066 | { |
| 2067 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2068 | struct e1000_fc_info *fc = &adapter->hw.fc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2069 | struct e1000_hw *hw = &adapter->hw; |
| 2070 | u32 tx_space, min_tx_space, min_rx_space; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2071 | u32 pba = adapter->pba; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2072 | u16 hwm; |
| 2073 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2074 | /* reset Packet Buffer Allocation to default */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2075 | ew32(PBA, pba); |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2076 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2077 | if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2078 | /* |
| 2079 | * To maintain wire speed transmits, the Tx FIFO should be |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2084 | * expressed in KB. |
| 2085 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2086 | pba = er32(PBA); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2087 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2088 | tx_space = pba >> 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2089 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2090 | pba &= 0xffff; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 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 |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2094 | */ |
| 2095 | min_tx_space = (adapter->max_frame_size + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2101 | min_rx_space = adapter->max_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2102 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 2103 | min_rx_space >>= 10; |
| 2104 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2105 | /* |
| 2106 | * If current Tx allocation is less than the min Tx FIFO size, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2107 | * and the min Tx FIFO size is less than the current Rx FIFO |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2108 | * allocation, take space away from current Rx allocation |
| 2109 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2110 | if ((tx_space < min_tx_space) && |
| 2111 | ((min_tx_space - tx_space) < pba)) { |
| 2112 | pba -= min_tx_space - tx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2113 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2114 | /* |
| 2115 | * if short on Rx space, Rx wins and must trump tx |
| 2116 | * adjustment or use Early Receive if available |
| 2117 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2118 | if ((pba < min_rx_space) && |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2119 | (!(adapter->flags & FLAG_HAS_ERT))) |
| 2120 | /* ERT enabled in e1000_configure_rx */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2121 | pba = min_rx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2122 | } |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2123 | |
| 2124 | ew32(PBA, pba); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2127 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2128 | /* |
| 2129 | * flow control settings |
| 2130 | * |
| 2131 | * The high water mark must be low enough to fit one full frame |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2137 | * - the full Rx FIFO size minus one full frame |
| 2138 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2139 | if (adapter->flags & FLAG_HAS_ERT) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2140 | hwm = min(((pba << 10) * 9 / 10), |
| 2141 | ((pba << 10) - (E1000_ERT_2048 << 3))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2142 | else |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2143 | hwm = min(((pba << 10) * 9 / 10), |
| 2144 | ((pba << 10) - adapter->max_frame_size)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2145 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2146 | fc->high_water = hwm & 0xFFF8; /* 8-byte granularity */ |
| 2147 | fc->low_water = fc->high_water - 8; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2148 | |
| 2149 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2150 | fc->pause_time = 0xFFFF; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2151 | else |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2152 | fc->pause_time = E1000_FC_PAUSE_TIME; |
| 2153 | fc->send_xon = 1; |
| 2154 | fc->type = fc->original_type; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2173 | /* |
| 2174 | * speed up time to link by disabling smart power down, ignore |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2175 | * the return value of this function because there is nothing |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2176 | * different we would do if it failed |
| 2177 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2207 | /* |
| 2208 | * signal that we're down so the interrupt handler does not |
| 2209 | * reschedule our watchdog timer |
| 2210 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2273 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 2274 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2340 | /* |
| 2341 | * If AMT is enabled, let the firmware know that the network |
| 2342 | * interface is now open |
| 2343 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2344 | if ((adapter->flags & FLAG_HAS_AMT) && |
| 2345 | e1000e_check_mng_mode(&adapter->hw)) |
| 2346 | e1000_get_hw_control(adapter); |
| 2347 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2348 | /* |
| 2349 | * before we allocate an interrupt, we must be ready to handle it. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2352 | * clean_rx handler before we do so. |
| 2353 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 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 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2417 | /* |
| 2418 | * If AMT is enabled, let the firmware know that the network |
| 2419 | * interface is now closed |
| 2420 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2451 | /* |
| 2452 | * Hold a copy of the LAA in RAR[14] This is done so that |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2457 | * RAR[14] |
| 2458 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2467 | /* |
| 2468 | * Need to wait a few seconds after link up to get diagnostic information from |
| 2469 | * the phy |
| 2470 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2501 | /* |
| 2502 | * these counters are modified from e1000_adjust_tbi_stats, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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); |
| 2509 | adapter->stats.gorcl += er32(GORCL); |
| 2510 | adapter->stats.gorch += er32(GORCH); |
| 2511 | adapter->stats.bprc += er32(BPRC); |
| 2512 | adapter->stats.mprc += er32(MPRC); |
| 2513 | adapter->stats.roc += er32(ROC); |
| 2514 | |
| 2515 | if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) { |
| 2516 | adapter->stats.prc64 += er32(PRC64); |
| 2517 | adapter->stats.prc127 += er32(PRC127); |
| 2518 | adapter->stats.prc255 += er32(PRC255); |
| 2519 | adapter->stats.prc511 += er32(PRC511); |
| 2520 | adapter->stats.prc1023 += er32(PRC1023); |
| 2521 | adapter->stats.prc1522 += er32(PRC1522); |
| 2522 | adapter->stats.symerrs += er32(SYMERRS); |
| 2523 | adapter->stats.sec += er32(SEC); |
| 2524 | } |
| 2525 | |
| 2526 | adapter->stats.mpc += er32(MPC); |
| 2527 | adapter->stats.scc += er32(SCC); |
| 2528 | adapter->stats.ecol += er32(ECOL); |
| 2529 | adapter->stats.mcc += er32(MCC); |
| 2530 | adapter->stats.latecol += er32(LATECOL); |
| 2531 | adapter->stats.dc += er32(DC); |
| 2532 | adapter->stats.rlec += er32(RLEC); |
| 2533 | adapter->stats.xonrxc += er32(XONRXC); |
| 2534 | adapter->stats.xontxc += er32(XONTXC); |
| 2535 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 2536 | adapter->stats.xofftxc += er32(XOFFTXC); |
| 2537 | adapter->stats.fcruc += er32(FCRUC); |
| 2538 | adapter->stats.gptc += er32(GPTC); |
| 2539 | adapter->stats.gotcl += er32(GOTCL); |
| 2540 | adapter->stats.gotch += er32(GOTCH); |
| 2541 | adapter->stats.rnbc += er32(RNBC); |
| 2542 | adapter->stats.ruc += er32(RUC); |
| 2543 | adapter->stats.rfc += er32(RFC); |
| 2544 | adapter->stats.rjc += er32(RJC); |
| 2545 | adapter->stats.torl += er32(TORL); |
| 2546 | adapter->stats.torh += er32(TORH); |
| 2547 | adapter->stats.totl += er32(TOTL); |
| 2548 | adapter->stats.toth += er32(TOTH); |
| 2549 | adapter->stats.tpr += er32(TPR); |
| 2550 | |
| 2551 | if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) { |
| 2552 | adapter->stats.ptc64 += er32(PTC64); |
| 2553 | adapter->stats.ptc127 += er32(PTC127); |
| 2554 | adapter->stats.ptc255 += er32(PTC255); |
| 2555 | adapter->stats.ptc511 += er32(PTC511); |
| 2556 | adapter->stats.ptc1023 += er32(PTC1023); |
| 2557 | adapter->stats.ptc1522 += er32(PTC1522); |
| 2558 | } |
| 2559 | |
| 2560 | adapter->stats.mptc += er32(MPTC); |
| 2561 | adapter->stats.bptc += er32(BPTC); |
| 2562 | |
| 2563 | /* used for adaptive IFS */ |
| 2564 | |
| 2565 | hw->mac.tx_packet_delta = er32(TPT); |
| 2566 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
| 2567 | hw->mac.collision_delta = er32(COLC); |
| 2568 | adapter->stats.colc += hw->mac.collision_delta; |
| 2569 | |
| 2570 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 2571 | adapter->stats.rxerrc += er32(RXERRC); |
| 2572 | adapter->stats.tncrs += er32(TNCRS); |
| 2573 | adapter->stats.cexterr += er32(CEXTERR); |
| 2574 | adapter->stats.tsctc += er32(TSCTC); |
| 2575 | adapter->stats.tsctfc += er32(TSCTFC); |
| 2576 | |
| 2577 | adapter->stats.iac += er32(IAC); |
| 2578 | |
| 2579 | if (adapter->flags & FLAG_HAS_STATS_ICR_ICT) { |
| 2580 | adapter->stats.icrxoc += er32(ICRXOC); |
| 2581 | adapter->stats.icrxptc += er32(ICRXPTC); |
| 2582 | adapter->stats.icrxatc += er32(ICRXATC); |
| 2583 | adapter->stats.ictxptc += er32(ICTXPTC); |
| 2584 | adapter->stats.ictxatc += er32(ICTXATC); |
| 2585 | adapter->stats.ictxqec += er32(ICTXQEC); |
| 2586 | adapter->stats.ictxqmtc += er32(ICTXQMTC); |
| 2587 | adapter->stats.icrxdmtc += er32(ICRXDMTC); |
| 2588 | } |
| 2589 | |
| 2590 | /* Fill out the OS statistics structure */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2591 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 2592 | adapter->net_stats.collisions = adapter->stats.colc; |
| 2593 | |
| 2594 | /* Rx Errors */ |
| 2595 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2596 | /* |
| 2597 | * RLEC on some newer hardware can be incorrect so build |
| 2598 | * our own version based on RUC and ROC |
| 2599 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2600 | adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
| 2601 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 2602 | adapter->stats.ruc + adapter->stats.roc + |
| 2603 | adapter->stats.cexterr; |
| 2604 | adapter->net_stats.rx_length_errors = adapter->stats.ruc + |
| 2605 | adapter->stats.roc; |
| 2606 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
| 2607 | adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
| 2608 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
| 2609 | |
| 2610 | /* Tx Errors */ |
| 2611 | adapter->net_stats.tx_errors = adapter->stats.ecol + |
| 2612 | adapter->stats.latecol; |
| 2613 | adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
| 2614 | adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
| 2615 | adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
| 2616 | |
| 2617 | /* Tx Dropped needs to be maintained elsewhere */ |
| 2618 | |
| 2619 | /* Phy Stats */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2620 | if (hw->phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2621 | if ((adapter->link_speed == SPEED_1000) && |
| 2622 | (!e1e_rphy(hw, PHY_1000T_STATUS, &phy_tmp))) { |
| 2623 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 2624 | adapter->phy_stats.idle_errors += phy_tmp; |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | /* Management Stats */ |
| 2629 | adapter->stats.mgptc += er32(MGTPTC); |
| 2630 | adapter->stats.mgprc += er32(MGTPRC); |
| 2631 | adapter->stats.mgpdc += er32(MGTPDC); |
| 2632 | |
| 2633 | spin_unlock_irqrestore(&adapter->stats_lock, irq_flags); |
| 2634 | } |
| 2635 | |
| 2636 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
| 2637 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2638 | struct e1000_hw *hw = &adapter->hw; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2639 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2640 | u32 ctrl = er32(CTRL); |
| 2641 | |
| 2642 | ndev_info(netdev, |
| 2643 | "Link is Up %d Mbps %s, Flow Control: %s\n", |
| 2644 | adapter->link_speed, |
| 2645 | (adapter->link_duplex == FULL_DUPLEX) ? |
| 2646 | "Full Duplex" : "Half Duplex", |
| 2647 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ? |
| 2648 | "RX/TX" : |
| 2649 | ((ctrl & E1000_CTRL_RFCE) ? "RX" : |
| 2650 | ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" ))); |
| 2651 | } |
| 2652 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2653 | static bool e1000_has_link(struct e1000_adapter *adapter) |
| 2654 | { |
| 2655 | struct e1000_hw *hw = &adapter->hw; |
| 2656 | bool link_active = 0; |
| 2657 | s32 ret_val = 0; |
| 2658 | |
| 2659 | /* |
| 2660 | * get_link_status is set on LSC (link status) interrupt or |
| 2661 | * Rx sequence error interrupt. get_link_status will stay |
| 2662 | * false until the check_for_link establishes link |
| 2663 | * for copper adapters ONLY |
| 2664 | */ |
| 2665 | switch (hw->phy.media_type) { |
| 2666 | case e1000_media_type_copper: |
| 2667 | if (hw->mac.get_link_status) { |
| 2668 | ret_val = hw->mac.ops.check_for_link(hw); |
| 2669 | link_active = !hw->mac.get_link_status; |
| 2670 | } else { |
| 2671 | link_active = 1; |
| 2672 | } |
| 2673 | break; |
| 2674 | case e1000_media_type_fiber: |
| 2675 | ret_val = hw->mac.ops.check_for_link(hw); |
| 2676 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 2677 | break; |
| 2678 | case e1000_media_type_internal_serdes: |
| 2679 | ret_val = hw->mac.ops.check_for_link(hw); |
| 2680 | link_active = adapter->hw.mac.serdes_has_link; |
| 2681 | break; |
| 2682 | default: |
| 2683 | case e1000_media_type_unknown: |
| 2684 | break; |
| 2685 | } |
| 2686 | |
| 2687 | if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && |
| 2688 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 2689 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ |
| 2690 | ndev_info(adapter->netdev, |
| 2691 | "Gigabit has been disabled, downgrading speed\n"); |
| 2692 | } |
| 2693 | |
| 2694 | return link_active; |
| 2695 | } |
| 2696 | |
| 2697 | static void e1000e_enable_receives(struct e1000_adapter *adapter) |
| 2698 | { |
| 2699 | /* make sure the receive unit is started */ |
| 2700 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 2701 | (adapter->flags & FLAG_RX_RESTART_NOW)) { |
| 2702 | struct e1000_hw *hw = &adapter->hw; |
| 2703 | u32 rctl = er32(RCTL); |
| 2704 | ew32(RCTL, rctl | E1000_RCTL_EN); |
| 2705 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
| 2706 | } |
| 2707 | } |
| 2708 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2709 | /** |
| 2710 | * e1000_watchdog - Timer Call-back |
| 2711 | * @data: pointer to adapter cast into an unsigned long |
| 2712 | **/ |
| 2713 | static void e1000_watchdog(unsigned long data) |
| 2714 | { |
| 2715 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2716 | |
| 2717 | /* Do the rest outside of interrupt context */ |
| 2718 | schedule_work(&adapter->watchdog_task); |
| 2719 | |
| 2720 | /* TODO: make this use queue_delayed_work() */ |
| 2721 | } |
| 2722 | |
| 2723 | static void e1000_watchdog_task(struct work_struct *work) |
| 2724 | { |
| 2725 | struct e1000_adapter *adapter = container_of(work, |
| 2726 | struct e1000_adapter, watchdog_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2727 | struct net_device *netdev = adapter->netdev; |
| 2728 | struct e1000_mac_info *mac = &adapter->hw.mac; |
| 2729 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2730 | struct e1000_hw *hw = &adapter->hw; |
| 2731 | u32 link, tctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2732 | int tx_pending = 0; |
| 2733 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2734 | link = e1000_has_link(adapter); |
| 2735 | if ((netif_carrier_ok(netdev)) && link) { |
| 2736 | e1000e_enable_receives(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2737 | goto link_up; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | if ((e1000e_enable_tx_pkt_filtering(hw)) && |
| 2741 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) |
| 2742 | e1000_update_mng_vlan(adapter); |
| 2743 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2744 | if (link) { |
| 2745 | if (!netif_carrier_ok(netdev)) { |
| 2746 | bool txb2b = 1; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2747 | /* update snapshot of PHY registers on LSC */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2748 | mac->ops.get_link_up_info(&adapter->hw, |
| 2749 | &adapter->link_speed, |
| 2750 | &adapter->link_duplex); |
| 2751 | e1000_print_link_info(adapter); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2752 | /* |
| 2753 | * tweak tx_queue_len according to speed/duplex |
| 2754 | * and adjust the timeout factor |
| 2755 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2756 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 2757 | adapter->tx_timeout_factor = 1; |
| 2758 | switch (adapter->link_speed) { |
| 2759 | case SPEED_10: |
| 2760 | txb2b = 0; |
| 2761 | netdev->tx_queue_len = 10; |
| 2762 | adapter->tx_timeout_factor = 14; |
| 2763 | break; |
| 2764 | case SPEED_100: |
| 2765 | txb2b = 0; |
| 2766 | netdev->tx_queue_len = 100; |
| 2767 | /* maybe add some timeout factor ? */ |
| 2768 | break; |
| 2769 | } |
| 2770 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2771 | /* |
| 2772 | * workaround: re-program speed mode bit after |
| 2773 | * link-up event |
| 2774 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2775 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
| 2776 | !txb2b) { |
| 2777 | u32 tarc0; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2778 | tarc0 = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2779 | tarc0 &= ~SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2780 | ew32(TARC(0), tarc0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2781 | } |
| 2782 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2783 | /* |
| 2784 | * disable TSO for pcie and 10/100 speeds, to avoid |
| 2785 | * some hardware issues |
| 2786 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2787 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
| 2788 | switch (adapter->link_speed) { |
| 2789 | case SPEED_10: |
| 2790 | case SPEED_100: |
| 2791 | ndev_info(netdev, |
| 2792 | "10/100 speed: disabling TSO\n"); |
| 2793 | netdev->features &= ~NETIF_F_TSO; |
| 2794 | netdev->features &= ~NETIF_F_TSO6; |
| 2795 | break; |
| 2796 | case SPEED_1000: |
| 2797 | netdev->features |= NETIF_F_TSO; |
| 2798 | netdev->features |= NETIF_F_TSO6; |
| 2799 | break; |
| 2800 | default: |
| 2801 | /* oops */ |
| 2802 | break; |
| 2803 | } |
| 2804 | } |
| 2805 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2806 | /* |
| 2807 | * enable transmits in the hardware, need to do this |
| 2808 | * after setting TARC(0) |
| 2809 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2810 | tctl = er32(TCTL); |
| 2811 | tctl |= E1000_TCTL_EN; |
| 2812 | ew32(TCTL, tctl); |
| 2813 | |
| 2814 | netif_carrier_on(netdev); |
| 2815 | netif_wake_queue(netdev); |
| 2816 | |
| 2817 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 2818 | mod_timer(&adapter->phy_info_timer, |
| 2819 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2820 | } |
| 2821 | } else { |
| 2822 | if (netif_carrier_ok(netdev)) { |
| 2823 | adapter->link_speed = 0; |
| 2824 | adapter->link_duplex = 0; |
| 2825 | ndev_info(netdev, "Link is Down\n"); |
| 2826 | netif_carrier_off(netdev); |
| 2827 | netif_stop_queue(netdev); |
| 2828 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 2829 | mod_timer(&adapter->phy_info_timer, |
| 2830 | round_jiffies(jiffies + 2 * HZ)); |
| 2831 | |
| 2832 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) |
| 2833 | schedule_work(&adapter->reset_task); |
| 2834 | } |
| 2835 | } |
| 2836 | |
| 2837 | link_up: |
| 2838 | e1000e_update_stats(adapter); |
| 2839 | |
| 2840 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 2841 | adapter->tpt_old = adapter->stats.tpt; |
| 2842 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; |
| 2843 | adapter->colc_old = adapter->stats.colc; |
| 2844 | |
| 2845 | adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
| 2846 | adapter->gorcl_old = adapter->stats.gorcl; |
| 2847 | adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
| 2848 | adapter->gotcl_old = adapter->stats.gotcl; |
| 2849 | |
| 2850 | e1000e_update_adaptive(&adapter->hw); |
| 2851 | |
| 2852 | if (!netif_carrier_ok(netdev)) { |
| 2853 | tx_pending = (e1000_desc_unused(tx_ring) + 1 < |
| 2854 | tx_ring->count); |
| 2855 | if (tx_pending) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2856 | /* |
| 2857 | * We've lost link, so the controller stops DMA, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2858 | * but we've got queued Tx work that's never going |
| 2859 | * to get done, so reset controller to flush Tx. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2860 | * (Do the reset outside of interrupt context). |
| 2861 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2862 | adapter->tx_timeout_count++; |
| 2863 | schedule_work(&adapter->reset_task); |
| 2864 | } |
| 2865 | } |
| 2866 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2867 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2868 | ew32(ICS, E1000_ICS_RXDMT0); |
| 2869 | |
| 2870 | /* Force detection of hung controller every watchdog period */ |
| 2871 | adapter->detect_tx_hung = 1; |
| 2872 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2873 | /* |
| 2874 | * With 82571 controllers, LAA may be overwritten due to controller |
| 2875 | * reset from the other port. Set the appropriate LAA in RAR[0] |
| 2876 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2877 | if (e1000e_get_laa_state_82571(hw)) |
| 2878 | e1000e_rar_set(hw, adapter->hw.mac.addr, 0); |
| 2879 | |
| 2880 | /* Reset the timer */ |
| 2881 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 2882 | mod_timer(&adapter->watchdog_timer, |
| 2883 | round_jiffies(jiffies + 2 * HZ)); |
| 2884 | } |
| 2885 | |
| 2886 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 2887 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 2888 | #define E1000_TX_FLAGS_TSO 0x00000004 |
| 2889 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
| 2890 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 2891 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 2892 | |
| 2893 | static int e1000_tso(struct e1000_adapter *adapter, |
| 2894 | struct sk_buff *skb) |
| 2895 | { |
| 2896 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2897 | struct e1000_context_desc *context_desc; |
| 2898 | struct e1000_buffer *buffer_info; |
| 2899 | unsigned int i; |
| 2900 | u32 cmd_length = 0; |
| 2901 | u16 ipcse = 0, tucse, mss; |
| 2902 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
| 2903 | int err; |
| 2904 | |
| 2905 | if (skb_is_gso(skb)) { |
| 2906 | if (skb_header_cloned(skb)) { |
| 2907 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2908 | if (err) |
| 2909 | return err; |
| 2910 | } |
| 2911 | |
| 2912 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 2913 | mss = skb_shinfo(skb)->gso_size; |
| 2914 | if (skb->protocol == htons(ETH_P_IP)) { |
| 2915 | struct iphdr *iph = ip_hdr(skb); |
| 2916 | iph->tot_len = 0; |
| 2917 | iph->check = 0; |
| 2918 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 2919 | iph->daddr, 0, |
| 2920 | IPPROTO_TCP, |
| 2921 | 0); |
| 2922 | cmd_length = E1000_TXD_CMD_IP; |
| 2923 | ipcse = skb_transport_offset(skb) - 1; |
| 2924 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
| 2925 | ipv6_hdr(skb)->payload_len = 0; |
| 2926 | tcp_hdr(skb)->check = |
| 2927 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 2928 | &ipv6_hdr(skb)->daddr, |
| 2929 | 0, IPPROTO_TCP, 0); |
| 2930 | ipcse = 0; |
| 2931 | } |
| 2932 | ipcss = skb_network_offset(skb); |
| 2933 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
| 2934 | tucss = skb_transport_offset(skb); |
| 2935 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
| 2936 | tucse = 0; |
| 2937 | |
| 2938 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
| 2939 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
| 2940 | |
| 2941 | i = tx_ring->next_to_use; |
| 2942 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 2943 | buffer_info = &tx_ring->buffer_info[i]; |
| 2944 | |
| 2945 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 2946 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 2947 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 2948 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 2949 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 2950 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 2951 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 2952 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 2953 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 2954 | |
| 2955 | buffer_info->time_stamp = jiffies; |
| 2956 | buffer_info->next_to_watch = i; |
| 2957 | |
| 2958 | i++; |
| 2959 | if (i == tx_ring->count) |
| 2960 | i = 0; |
| 2961 | tx_ring->next_to_use = i; |
| 2962 | |
| 2963 | return 1; |
| 2964 | } |
| 2965 | |
| 2966 | return 0; |
| 2967 | } |
| 2968 | |
| 2969 | static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 2970 | { |
| 2971 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2972 | struct e1000_context_desc *context_desc; |
| 2973 | struct e1000_buffer *buffer_info; |
| 2974 | unsigned int i; |
| 2975 | u8 css; |
| 2976 | |
| 2977 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 2978 | css = skb_transport_offset(skb); |
| 2979 | |
| 2980 | i = tx_ring->next_to_use; |
| 2981 | buffer_info = &tx_ring->buffer_info[i]; |
| 2982 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 2983 | |
| 2984 | context_desc->lower_setup.ip_config = 0; |
| 2985 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 2986 | context_desc->upper_setup.tcp_fields.tucso = |
| 2987 | css + skb->csum_offset; |
| 2988 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 2989 | context_desc->tcp_seg_setup.data = 0; |
| 2990 | context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT); |
| 2991 | |
| 2992 | buffer_info->time_stamp = jiffies; |
| 2993 | buffer_info->next_to_watch = i; |
| 2994 | |
| 2995 | i++; |
| 2996 | if (i == tx_ring->count) |
| 2997 | i = 0; |
| 2998 | tx_ring->next_to_use = i; |
| 2999 | |
| 3000 | return 1; |
| 3001 | } |
| 3002 | |
| 3003 | return 0; |
| 3004 | } |
| 3005 | |
| 3006 | #define E1000_MAX_PER_TXD 8192 |
| 3007 | #define E1000_MAX_TXD_PWR 12 |
| 3008 | |
| 3009 | static int e1000_tx_map(struct e1000_adapter *adapter, |
| 3010 | struct sk_buff *skb, unsigned int first, |
| 3011 | unsigned int max_per_txd, unsigned int nr_frags, |
| 3012 | unsigned int mss) |
| 3013 | { |
| 3014 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 3015 | struct e1000_buffer *buffer_info; |
| 3016 | unsigned int len = skb->len - skb->data_len; |
| 3017 | unsigned int offset = 0, size, count = 0, i; |
| 3018 | unsigned int f; |
| 3019 | |
| 3020 | i = tx_ring->next_to_use; |
| 3021 | |
| 3022 | while (len) { |
| 3023 | buffer_info = &tx_ring->buffer_info[i]; |
| 3024 | size = min(len, max_per_txd); |
| 3025 | |
| 3026 | /* Workaround for premature desc write-backs |
| 3027 | * in TSO mode. Append 4-byte sentinel desc */ |
| 3028 | if (mss && !nr_frags && size == len && size > 8) |
| 3029 | size -= 4; |
| 3030 | |
| 3031 | buffer_info->length = size; |
| 3032 | /* set time_stamp *before* dma to help avoid a possible race */ |
| 3033 | buffer_info->time_stamp = jiffies; |
| 3034 | buffer_info->dma = |
| 3035 | pci_map_single(adapter->pdev, |
| 3036 | skb->data + offset, |
| 3037 | size, |
| 3038 | PCI_DMA_TODEVICE); |
| 3039 | if (pci_dma_mapping_error(buffer_info->dma)) { |
| 3040 | dev_err(&adapter->pdev->dev, "TX DMA map failed\n"); |
| 3041 | adapter->tx_dma_failed++; |
| 3042 | return -1; |
| 3043 | } |
| 3044 | buffer_info->next_to_watch = i; |
| 3045 | |
| 3046 | len -= size; |
| 3047 | offset += size; |
| 3048 | count++; |
| 3049 | i++; |
| 3050 | if (i == tx_ring->count) |
| 3051 | i = 0; |
| 3052 | } |
| 3053 | |
| 3054 | for (f = 0; f < nr_frags; f++) { |
| 3055 | struct skb_frag_struct *frag; |
| 3056 | |
| 3057 | frag = &skb_shinfo(skb)->frags[f]; |
| 3058 | len = frag->size; |
| 3059 | offset = frag->page_offset; |
| 3060 | |
| 3061 | while (len) { |
| 3062 | buffer_info = &tx_ring->buffer_info[i]; |
| 3063 | size = min(len, max_per_txd); |
| 3064 | /* Workaround for premature desc write-backs |
| 3065 | * in TSO mode. Append 4-byte sentinel desc */ |
| 3066 | if (mss && f == (nr_frags-1) && size == len && size > 8) |
| 3067 | size -= 4; |
| 3068 | |
| 3069 | buffer_info->length = size; |
| 3070 | buffer_info->time_stamp = jiffies; |
| 3071 | buffer_info->dma = |
| 3072 | pci_map_page(adapter->pdev, |
| 3073 | frag->page, |
| 3074 | offset, |
| 3075 | size, |
| 3076 | PCI_DMA_TODEVICE); |
| 3077 | if (pci_dma_mapping_error(buffer_info->dma)) { |
| 3078 | dev_err(&adapter->pdev->dev, |
| 3079 | "TX DMA page map failed\n"); |
| 3080 | adapter->tx_dma_failed++; |
| 3081 | return -1; |
| 3082 | } |
| 3083 | |
| 3084 | buffer_info->next_to_watch = i; |
| 3085 | |
| 3086 | len -= size; |
| 3087 | offset += size; |
| 3088 | count++; |
| 3089 | |
| 3090 | i++; |
| 3091 | if (i == tx_ring->count) |
| 3092 | i = 0; |
| 3093 | } |
| 3094 | } |
| 3095 | |
| 3096 | if (i == 0) |
| 3097 | i = tx_ring->count - 1; |
| 3098 | else |
| 3099 | i--; |
| 3100 | |
| 3101 | tx_ring->buffer_info[i].skb = skb; |
| 3102 | tx_ring->buffer_info[first].next_to_watch = i; |
| 3103 | |
| 3104 | return count; |
| 3105 | } |
| 3106 | |
| 3107 | static void e1000_tx_queue(struct e1000_adapter *adapter, |
| 3108 | int tx_flags, int count) |
| 3109 | { |
| 3110 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 3111 | struct e1000_tx_desc *tx_desc = NULL; |
| 3112 | struct e1000_buffer *buffer_info; |
| 3113 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 3114 | unsigned int i; |
| 3115 | |
| 3116 | if (tx_flags & E1000_TX_FLAGS_TSO) { |
| 3117 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 3118 | E1000_TXD_CMD_TSE; |
| 3119 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3120 | |
| 3121 | if (tx_flags & E1000_TX_FLAGS_IPV4) |
| 3122 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
| 3123 | } |
| 3124 | |
| 3125 | if (tx_flags & E1000_TX_FLAGS_CSUM) { |
| 3126 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 3127 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3128 | } |
| 3129 | |
| 3130 | if (tx_flags & E1000_TX_FLAGS_VLAN) { |
| 3131 | txd_lower |= E1000_TXD_CMD_VLE; |
| 3132 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 3133 | } |
| 3134 | |
| 3135 | i = tx_ring->next_to_use; |
| 3136 | |
| 3137 | while (count--) { |
| 3138 | buffer_info = &tx_ring->buffer_info[i]; |
| 3139 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3140 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 3141 | tx_desc->lower.data = |
| 3142 | cpu_to_le32(txd_lower | buffer_info->length); |
| 3143 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
| 3144 | |
| 3145 | i++; |
| 3146 | if (i == tx_ring->count) |
| 3147 | i = 0; |
| 3148 | } |
| 3149 | |
| 3150 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 3151 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3152 | /* |
| 3153 | * Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3154 | * know there are new descriptors to fetch. (Only |
| 3155 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3156 | * such as IA-64). |
| 3157 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3158 | wmb(); |
| 3159 | |
| 3160 | tx_ring->next_to_use = i; |
| 3161 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3162 | /* |
| 3163 | * we need this if more than one processor can write to our tail |
| 3164 | * at a time, it synchronizes IO on IA64/Altix systems |
| 3165 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3166 | mmiowb(); |
| 3167 | } |
| 3168 | |
| 3169 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 3170 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 3171 | struct sk_buff *skb) |
| 3172 | { |
| 3173 | struct e1000_hw *hw = &adapter->hw; |
| 3174 | u16 length, offset; |
| 3175 | |
| 3176 | if (vlan_tx_tag_present(skb)) { |
| 3177 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) |
| 3178 | && (adapter->hw.mng_cookie.status & |
| 3179 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) |
| 3180 | return 0; |
| 3181 | } |
| 3182 | |
| 3183 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) |
| 3184 | return 0; |
| 3185 | |
| 3186 | if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP)) |
| 3187 | return 0; |
| 3188 | |
| 3189 | { |
| 3190 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14); |
| 3191 | struct udphdr *udp; |
| 3192 | |
| 3193 | if (ip->protocol != IPPROTO_UDP) |
| 3194 | return 0; |
| 3195 | |
| 3196 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 3197 | if (ntohs(udp->dest) != 67) |
| 3198 | return 0; |
| 3199 | |
| 3200 | offset = (u8 *)udp + 8 - skb->data; |
| 3201 | length = skb->len - offset; |
| 3202 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); |
| 3203 | } |
| 3204 | |
| 3205 | return 0; |
| 3206 | } |
| 3207 | |
| 3208 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 3209 | { |
| 3210 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3211 | |
| 3212 | netif_stop_queue(netdev); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3213 | /* |
| 3214 | * Herbert's original patch had: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3215 | * smp_mb__after_netif_stop_queue(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3216 | * but since that doesn't exist yet, just open code it. |
| 3217 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3218 | smp_mb(); |
| 3219 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3220 | /* |
| 3221 | * We need to check again in a case another CPU has just |
| 3222 | * made room available. |
| 3223 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3224 | if (e1000_desc_unused(adapter->tx_ring) < size) |
| 3225 | return -EBUSY; |
| 3226 | |
| 3227 | /* A reprieve! */ |
| 3228 | netif_start_queue(netdev); |
| 3229 | ++adapter->restart_queue; |
| 3230 | return 0; |
| 3231 | } |
| 3232 | |
| 3233 | static int e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 3234 | { |
| 3235 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3236 | |
| 3237 | if (e1000_desc_unused(adapter->tx_ring) >= size) |
| 3238 | return 0; |
| 3239 | return __e1000_maybe_stop_tx(netdev, size); |
| 3240 | } |
| 3241 | |
| 3242 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
| 3243 | static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 3244 | { |
| 3245 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3246 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 3247 | unsigned int first; |
| 3248 | unsigned int max_per_txd = E1000_MAX_PER_TXD; |
| 3249 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 3250 | unsigned int tx_flags = 0; |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 3251 | unsigned int len = skb->len - skb->data_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3252 | unsigned long irq_flags; |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 3253 | unsigned int nr_frags; |
| 3254 | unsigned int mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3255 | int count = 0; |
| 3256 | int tso; |
| 3257 | unsigned int f; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3258 | |
| 3259 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 3260 | dev_kfree_skb_any(skb); |
| 3261 | return NETDEV_TX_OK; |
| 3262 | } |
| 3263 | |
| 3264 | if (skb->len <= 0) { |
| 3265 | dev_kfree_skb_any(skb); |
| 3266 | return NETDEV_TX_OK; |
| 3267 | } |
| 3268 | |
| 3269 | mss = skb_shinfo(skb)->gso_size; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3270 | /* |
| 3271 | * The controller does a simple calculation to |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3272 | * make sure there is enough room in the FIFO before |
| 3273 | * initiating the DMA for each buffer. The calc is: |
| 3274 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 3275 | * overrun the FIFO, adjust the max buffer len if mss |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3276 | * drops. |
| 3277 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3278 | if (mss) { |
| 3279 | u8 hdr_len; |
| 3280 | max_per_txd = min(mss << 2, max_per_txd); |
| 3281 | max_txd_pwr = fls(max_per_txd) - 1; |
| 3282 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3283 | /* |
| 3284 | * TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 3285 | * points to just header, pull a few bytes of payload from |
| 3286 | * frags into skb->data |
| 3287 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3288 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3289 | /* |
| 3290 | * we do this workaround for ES2LAN, but it is un-necessary, |
| 3291 | * avoiding it could save a lot of cycles |
| 3292 | */ |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 3293 | if (skb->data_len && (hdr_len == len)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3294 | unsigned int pull_size; |
| 3295 | |
| 3296 | pull_size = min((unsigned int)4, skb->data_len); |
| 3297 | if (!__pskb_pull_tail(skb, pull_size)) { |
| 3298 | ndev_err(netdev, |
| 3299 | "__pskb_pull_tail failed.\n"); |
| 3300 | dev_kfree_skb_any(skb); |
| 3301 | return NETDEV_TX_OK; |
| 3302 | } |
| 3303 | len = skb->len - skb->data_len; |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | /* reserve a descriptor for the offload context */ |
| 3308 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 3309 | count++; |
| 3310 | count++; |
| 3311 | |
| 3312 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 3313 | |
| 3314 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 3315 | for (f = 0; f < nr_frags; f++) |
| 3316 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 3317 | max_txd_pwr); |
| 3318 | |
| 3319 | if (adapter->hw.mac.tx_pkt_filtering) |
| 3320 | e1000_transfer_dhcp_info(adapter, skb); |
| 3321 | |
| 3322 | if (!spin_trylock_irqsave(&adapter->tx_queue_lock, irq_flags)) |
| 3323 | /* Collision - tell upper layer to requeue */ |
| 3324 | return NETDEV_TX_LOCKED; |
| 3325 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3326 | /* |
| 3327 | * need: count + 2 desc gap to keep tail from touching |
| 3328 | * head, otherwise try next time |
| 3329 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3330 | if (e1000_maybe_stop_tx(netdev, count + 2)) { |
| 3331 | spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags); |
| 3332 | return NETDEV_TX_BUSY; |
| 3333 | } |
| 3334 | |
| 3335 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 3336 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 3337 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 3338 | } |
| 3339 | |
| 3340 | first = tx_ring->next_to_use; |
| 3341 | |
| 3342 | tso = e1000_tso(adapter, skb); |
| 3343 | if (tso < 0) { |
| 3344 | dev_kfree_skb_any(skb); |
| 3345 | spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags); |
| 3346 | return NETDEV_TX_OK; |
| 3347 | } |
| 3348 | |
| 3349 | if (tso) |
| 3350 | tx_flags |= E1000_TX_FLAGS_TSO; |
| 3351 | else if (e1000_tx_csum(adapter, skb)) |
| 3352 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 3353 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3354 | /* |
| 3355 | * Old method was to assume IPv4 packet by default if TSO was enabled. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3356 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3357 | * no longer assume, we must. |
| 3358 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3359 | if (skb->protocol == htons(ETH_P_IP)) |
| 3360 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 3361 | |
| 3362 | count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss); |
| 3363 | if (count < 0) { |
| 3364 | /* handle pci_map_single() error in e1000_tx_map */ |
| 3365 | dev_kfree_skb_any(skb); |
| 3366 | spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags); |
Krishna Kumar | 7b5dfe1a | 2007-09-21 09:41:15 -0700 | [diff] [blame] | 3367 | return NETDEV_TX_OK; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | e1000_tx_queue(adapter, tx_flags, count); |
| 3371 | |
| 3372 | netdev->trans_start = jiffies; |
| 3373 | |
| 3374 | /* Make sure there is space in the ring for the next send. */ |
| 3375 | e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2); |
| 3376 | |
| 3377 | spin_unlock_irqrestore(&adapter->tx_queue_lock, irq_flags); |
| 3378 | return NETDEV_TX_OK; |
| 3379 | } |
| 3380 | |
| 3381 | /** |
| 3382 | * e1000_tx_timeout - Respond to a Tx Hang |
| 3383 | * @netdev: network interface device structure |
| 3384 | **/ |
| 3385 | static void e1000_tx_timeout(struct net_device *netdev) |
| 3386 | { |
| 3387 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3388 | |
| 3389 | /* Do the reset outside of interrupt context */ |
| 3390 | adapter->tx_timeout_count++; |
| 3391 | schedule_work(&adapter->reset_task); |
| 3392 | } |
| 3393 | |
| 3394 | static void e1000_reset_task(struct work_struct *work) |
| 3395 | { |
| 3396 | struct e1000_adapter *adapter; |
| 3397 | adapter = container_of(work, struct e1000_adapter, reset_task); |
| 3398 | |
| 3399 | e1000e_reinit_locked(adapter); |
| 3400 | } |
| 3401 | |
| 3402 | /** |
| 3403 | * e1000_get_stats - Get System Network Statistics |
| 3404 | * @netdev: network interface device structure |
| 3405 | * |
| 3406 | * Returns the address of the device statistics structure. |
| 3407 | * The statistics are actually updated from the timer callback. |
| 3408 | **/ |
| 3409 | static struct net_device_stats *e1000_get_stats(struct net_device *netdev) |
| 3410 | { |
| 3411 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3412 | |
| 3413 | /* only return the current stats */ |
| 3414 | return &adapter->net_stats; |
| 3415 | } |
| 3416 | |
| 3417 | /** |
| 3418 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 3419 | * @netdev: network interface device structure |
| 3420 | * @new_mtu: new value for maximum frame size |
| 3421 | * |
| 3422 | * Returns 0 on success, negative on failure |
| 3423 | **/ |
| 3424 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 3425 | { |
| 3426 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3427 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3428 | |
| 3429 | if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) || |
| 3430 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
| 3431 | ndev_err(netdev, "Invalid MTU setting\n"); |
| 3432 | return -EINVAL; |
| 3433 | } |
| 3434 | |
| 3435 | /* Jumbo frame size limits */ |
| 3436 | if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) { |
| 3437 | if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
| 3438 | ndev_err(netdev, "Jumbo Frames not supported.\n"); |
| 3439 | return -EINVAL; |
| 3440 | } |
| 3441 | if (adapter->hw.phy.type == e1000_phy_ife) { |
| 3442 | ndev_err(netdev, "Jumbo Frames not supported.\n"); |
| 3443 | return -EINVAL; |
| 3444 | } |
| 3445 | } |
| 3446 | |
| 3447 | #define MAX_STD_JUMBO_FRAME_SIZE 9234 |
| 3448 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
| 3449 | ndev_err(netdev, "MTU > 9216 not supported.\n"); |
| 3450 | return -EINVAL; |
| 3451 | } |
| 3452 | |
| 3453 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
| 3454 | msleep(1); |
| 3455 | /* e1000e_down has a dependency on max_frame_size */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3456 | adapter->max_frame_size = max_frame; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3457 | if (netif_running(netdev)) |
| 3458 | e1000e_down(adapter); |
| 3459 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3460 | /* |
| 3461 | * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3462 | * means we reserve 2 more, this pushes us to allocate from the next |
| 3463 | * larger slab size. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3464 | * i.e. RXBUFFER_2048 --> size-4096 slab |
| 3465 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3466 | |
| 3467 | if (max_frame <= 256) |
| 3468 | adapter->rx_buffer_len = 256; |
| 3469 | else if (max_frame <= 512) |
| 3470 | adapter->rx_buffer_len = 512; |
| 3471 | else if (max_frame <= 1024) |
| 3472 | adapter->rx_buffer_len = 1024; |
| 3473 | else if (max_frame <= 2048) |
| 3474 | adapter->rx_buffer_len = 2048; |
| 3475 | else |
| 3476 | adapter->rx_buffer_len = 4096; |
| 3477 | |
| 3478 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
| 3479 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || |
| 3480 | (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) |
| 3481 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3482 | + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3483 | |
| 3484 | ndev_info(netdev, "changing MTU from %d to %d\n", |
| 3485 | netdev->mtu, new_mtu); |
| 3486 | netdev->mtu = new_mtu; |
| 3487 | |
| 3488 | if (netif_running(netdev)) |
| 3489 | e1000e_up(adapter); |
| 3490 | else |
| 3491 | e1000e_reset(adapter); |
| 3492 | |
| 3493 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 3494 | |
| 3495 | return 0; |
| 3496 | } |
| 3497 | |
| 3498 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 3499 | int cmd) |
| 3500 | { |
| 3501 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3502 | struct mii_ioctl_data *data = if_mii(ifr); |
| 3503 | unsigned long irq_flags; |
| 3504 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3505 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3506 | return -EOPNOTSUPP; |
| 3507 | |
| 3508 | switch (cmd) { |
| 3509 | case SIOCGMIIPHY: |
| 3510 | data->phy_id = adapter->hw.phy.addr; |
| 3511 | break; |
| 3512 | case SIOCGMIIREG: |
| 3513 | if (!capable(CAP_NET_ADMIN)) |
| 3514 | return -EPERM; |
| 3515 | spin_lock_irqsave(&adapter->stats_lock, irq_flags); |
| 3516 | if (e1e_rphy(&adapter->hw, data->reg_num & 0x1F, |
| 3517 | &data->val_out)) { |
| 3518 | spin_unlock_irqrestore(&adapter->stats_lock, irq_flags); |
| 3519 | return -EIO; |
| 3520 | } |
| 3521 | spin_unlock_irqrestore(&adapter->stats_lock, irq_flags); |
| 3522 | break; |
| 3523 | case SIOCSMIIREG: |
| 3524 | default: |
| 3525 | return -EOPNOTSUPP; |
| 3526 | } |
| 3527 | return 0; |
| 3528 | } |
| 3529 | |
| 3530 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 3531 | { |
| 3532 | switch (cmd) { |
| 3533 | case SIOCGMIIPHY: |
| 3534 | case SIOCGMIIREG: |
| 3535 | case SIOCSMIIREG: |
| 3536 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 3537 | default: |
| 3538 | return -EOPNOTSUPP; |
| 3539 | } |
| 3540 | } |
| 3541 | |
| 3542 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
| 3543 | { |
| 3544 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3545 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3546 | struct e1000_hw *hw = &adapter->hw; |
| 3547 | u32 ctrl, ctrl_ext, rctl, status; |
| 3548 | u32 wufc = adapter->wol; |
| 3549 | int retval = 0; |
| 3550 | |
| 3551 | netif_device_detach(netdev); |
| 3552 | |
| 3553 | if (netif_running(netdev)) { |
| 3554 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 3555 | e1000e_down(adapter); |
| 3556 | e1000_free_irq(adapter); |
| 3557 | } |
| 3558 | |
| 3559 | retval = pci_save_state(pdev); |
| 3560 | if (retval) |
| 3561 | return retval; |
| 3562 | |
| 3563 | status = er32(STATUS); |
| 3564 | if (status & E1000_STATUS_LU) |
| 3565 | wufc &= ~E1000_WUFC_LNKC; |
| 3566 | |
| 3567 | if (wufc) { |
| 3568 | e1000_setup_rctl(adapter); |
| 3569 | e1000_set_multi(netdev); |
| 3570 | |
| 3571 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 3572 | if (wufc & E1000_WUFC_MC) { |
| 3573 | rctl = er32(RCTL); |
| 3574 | rctl |= E1000_RCTL_MPE; |
| 3575 | ew32(RCTL, rctl); |
| 3576 | } |
| 3577 | |
| 3578 | ctrl = er32(CTRL); |
| 3579 | /* advertise wake from D3Cold */ |
| 3580 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 3581 | /* phy power management enable */ |
| 3582 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 3583 | ctrl |= E1000_CTRL_ADVD3WUC | |
| 3584 | E1000_CTRL_EN_PHY_PWR_MGMT; |
| 3585 | ew32(CTRL, ctrl); |
| 3586 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3587 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
| 3588 | adapter->hw.phy.media_type == |
| 3589 | e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3590 | /* keep the laser running in D3 */ |
| 3591 | ctrl_ext = er32(CTRL_EXT); |
| 3592 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
| 3593 | ew32(CTRL_EXT, ctrl_ext); |
| 3594 | } |
| 3595 | |
| 3596 | /* Allow time for pending master requests to run */ |
| 3597 | e1000e_disable_pcie_master(&adapter->hw); |
| 3598 | |
| 3599 | ew32(WUC, E1000_WUC_PME_EN); |
| 3600 | ew32(WUFC, wufc); |
| 3601 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 3602 | pci_enable_wake(pdev, PCI_D3cold, 1); |
| 3603 | } else { |
| 3604 | ew32(WUC, 0); |
| 3605 | ew32(WUFC, 0); |
| 3606 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 3607 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 3608 | } |
| 3609 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3610 | /* make sure adapter isn't asleep if manageability is enabled */ |
| 3611 | if (adapter->flags & FLAG_MNG_PT_ENABLED) { |
| 3612 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 3613 | pci_enable_wake(pdev, PCI_D3cold, 1); |
| 3614 | } |
| 3615 | |
| 3616 | if (adapter->hw.phy.type == e1000_phy_igp_3) |
| 3617 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
| 3618 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3619 | /* |
| 3620 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 3621 | * would have already happened in close and is redundant. |
| 3622 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3623 | e1000_release_hw_control(adapter); |
| 3624 | |
| 3625 | pci_disable_device(pdev); |
| 3626 | |
| 3627 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 3628 | |
| 3629 | return 0; |
| 3630 | } |
| 3631 | |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 3632 | static void e1000e_disable_l1aspm(struct pci_dev *pdev) |
| 3633 | { |
| 3634 | int pos; |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 3635 | u16 val; |
| 3636 | |
| 3637 | /* |
| 3638 | * 82573 workaround - disable L1 ASPM on mobile chipsets |
| 3639 | * |
| 3640 | * L1 ASPM on various mobile (ich7) chipsets do not behave properly |
| 3641 | * resulting in lost data or garbage information on the pci-e link |
| 3642 | * level. This could result in (false) bad EEPROM checksum errors, |
| 3643 | * long ping times (up to 2s) or even a system freeze/hang. |
| 3644 | * |
| 3645 | * Unfortunately this feature saves about 1W power consumption when |
| 3646 | * active. |
| 3647 | */ |
| 3648 | pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 3649 | pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val); |
| 3650 | if (val & 0x2) { |
| 3651 | dev_warn(&pdev->dev, "Disabling L1 ASPM\n"); |
| 3652 | val &= ~0x2; |
| 3653 | pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val); |
| 3654 | } |
| 3655 | } |
| 3656 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3657 | #ifdef CONFIG_PM |
| 3658 | static int e1000_resume(struct pci_dev *pdev) |
| 3659 | { |
| 3660 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3661 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3662 | struct e1000_hw *hw = &adapter->hw; |
| 3663 | u32 err; |
| 3664 | |
| 3665 | pci_set_power_state(pdev, PCI_D0); |
| 3666 | pci_restore_state(pdev); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 3667 | e1000e_disable_l1aspm(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3668 | err = pci_enable_device(pdev); |
| 3669 | if (err) { |
| 3670 | dev_err(&pdev->dev, |
| 3671 | "Cannot enable PCI device from suspend\n"); |
| 3672 | return err; |
| 3673 | } |
| 3674 | |
| 3675 | pci_set_master(pdev); |
| 3676 | |
| 3677 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 3678 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 3679 | |
| 3680 | if (netif_running(netdev)) { |
| 3681 | err = e1000_request_irq(adapter); |
| 3682 | if (err) |
| 3683 | return err; |
| 3684 | } |
| 3685 | |
| 3686 | e1000e_power_up_phy(adapter); |
| 3687 | e1000e_reset(adapter); |
| 3688 | ew32(WUS, ~0); |
| 3689 | |
| 3690 | e1000_init_manageability(adapter); |
| 3691 | |
| 3692 | if (netif_running(netdev)) |
| 3693 | e1000e_up(adapter); |
| 3694 | |
| 3695 | netif_device_attach(netdev); |
| 3696 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3697 | /* |
| 3698 | * If the controller has AMT, do not set DRV_LOAD until the interface |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3699 | * is up. For all other cases, let the f/w know that the h/w is now |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3700 | * under the control of the driver. |
| 3701 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3702 | if (!(adapter->flags & FLAG_HAS_AMT) || !e1000e_check_mng_mode(&adapter->hw)) |
| 3703 | e1000_get_hw_control(adapter); |
| 3704 | |
| 3705 | return 0; |
| 3706 | } |
| 3707 | #endif |
| 3708 | |
| 3709 | static void e1000_shutdown(struct pci_dev *pdev) |
| 3710 | { |
| 3711 | e1000_suspend(pdev, PMSG_SUSPEND); |
| 3712 | } |
| 3713 | |
| 3714 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3715 | /* |
| 3716 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 3717 | * without having to re-enable interrupts. It's not called while |
| 3718 | * the interrupt routine is executing. |
| 3719 | */ |
| 3720 | static void e1000_netpoll(struct net_device *netdev) |
| 3721 | { |
| 3722 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3723 | |
| 3724 | disable_irq(adapter->pdev->irq); |
| 3725 | e1000_intr(adapter->pdev->irq, netdev); |
| 3726 | |
| 3727 | e1000_clean_tx_irq(adapter); |
| 3728 | |
| 3729 | enable_irq(adapter->pdev->irq); |
| 3730 | } |
| 3731 | #endif |
| 3732 | |
| 3733 | /** |
| 3734 | * e1000_io_error_detected - called when PCI error is detected |
| 3735 | * @pdev: Pointer to PCI device |
| 3736 | * @state: The current pci connection state |
| 3737 | * |
| 3738 | * This function is called after a PCI bus error affecting |
| 3739 | * this device has been detected. |
| 3740 | */ |
| 3741 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 3742 | pci_channel_state_t state) |
| 3743 | { |
| 3744 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3745 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3746 | |
| 3747 | netif_device_detach(netdev); |
| 3748 | |
| 3749 | if (netif_running(netdev)) |
| 3750 | e1000e_down(adapter); |
| 3751 | pci_disable_device(pdev); |
| 3752 | |
| 3753 | /* Request a slot slot reset. */ |
| 3754 | return PCI_ERS_RESULT_NEED_RESET; |
| 3755 | } |
| 3756 | |
| 3757 | /** |
| 3758 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 3759 | * @pdev: Pointer to PCI device |
| 3760 | * |
| 3761 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 3762 | * resembles the first-half of the e1000_resume routine. |
| 3763 | */ |
| 3764 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 3765 | { |
| 3766 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3767 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3768 | struct e1000_hw *hw = &adapter->hw; |
| 3769 | |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 3770 | e1000e_disable_l1aspm(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3771 | if (pci_enable_device(pdev)) { |
| 3772 | dev_err(&pdev->dev, |
| 3773 | "Cannot re-enable PCI device after reset.\n"); |
| 3774 | return PCI_ERS_RESULT_DISCONNECT; |
| 3775 | } |
| 3776 | pci_set_master(pdev); |
| 3777 | |
| 3778 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 3779 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 3780 | |
| 3781 | e1000e_reset(adapter); |
| 3782 | ew32(WUS, ~0); |
| 3783 | |
| 3784 | return PCI_ERS_RESULT_RECOVERED; |
| 3785 | } |
| 3786 | |
| 3787 | /** |
| 3788 | * e1000_io_resume - called when traffic can start flowing again. |
| 3789 | * @pdev: Pointer to PCI device |
| 3790 | * |
| 3791 | * This callback is called when the error recovery driver tells us that |
| 3792 | * its OK to resume normal operation. Implementation resembles the |
| 3793 | * second-half of the e1000_resume routine. |
| 3794 | */ |
| 3795 | static void e1000_io_resume(struct pci_dev *pdev) |
| 3796 | { |
| 3797 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3798 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3799 | |
| 3800 | e1000_init_manageability(adapter); |
| 3801 | |
| 3802 | if (netif_running(netdev)) { |
| 3803 | if (e1000e_up(adapter)) { |
| 3804 | dev_err(&pdev->dev, |
| 3805 | "can't bring device back up after reset\n"); |
| 3806 | return; |
| 3807 | } |
| 3808 | } |
| 3809 | |
| 3810 | netif_device_attach(netdev); |
| 3811 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3812 | /* |
| 3813 | * If the controller has AMT, do not set DRV_LOAD until the interface |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3814 | * is up. For all other cases, let the f/w know that the h/w is now |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3815 | * under the control of the driver. |
| 3816 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3817 | if (!(adapter->flags & FLAG_HAS_AMT) || |
| 3818 | !e1000e_check_mng_mode(&adapter->hw)) |
| 3819 | e1000_get_hw_control(adapter); |
| 3820 | |
| 3821 | } |
| 3822 | |
| 3823 | static void e1000_print_device_info(struct e1000_adapter *adapter) |
| 3824 | { |
| 3825 | struct e1000_hw *hw = &adapter->hw; |
| 3826 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame^] | 3827 | u32 pba_num; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3828 | |
| 3829 | /* print bus type/speed/width info */ |
| 3830 | ndev_info(netdev, "(PCI Express:2.5GB/s:%s) " |
| 3831 | "%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 3832 | /* bus width */ |
| 3833 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
| 3834 | "Width x1"), |
| 3835 | /* MAC address */ |
| 3836 | netdev->dev_addr[0], netdev->dev_addr[1], |
| 3837 | netdev->dev_addr[2], netdev->dev_addr[3], |
| 3838 | netdev->dev_addr[4], netdev->dev_addr[5]); |
| 3839 | ndev_info(netdev, "Intel(R) PRO/%s Network Connection\n", |
| 3840 | (hw->phy.type == e1000_phy_ife) |
| 3841 | ? "10/100" : "1000"); |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame^] | 3842 | e1000e_read_pba_num(hw, &pba_num); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3843 | ndev_info(netdev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
| 3844 | hw->mac.type, hw->phy.type, |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame^] | 3845 | (pba_num >> 8), (pba_num & 0xff)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | /** |
| 3849 | * e1000_probe - Device Initialization Routine |
| 3850 | * @pdev: PCI device information struct |
| 3851 | * @ent: entry in e1000_pci_tbl |
| 3852 | * |
| 3853 | * Returns 0 on success, negative on failure |
| 3854 | * |
| 3855 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 3856 | * The OS initialization, configuring of the adapter private structure, |
| 3857 | * and a hardware reset occur. |
| 3858 | **/ |
| 3859 | static int __devinit e1000_probe(struct pci_dev *pdev, |
| 3860 | const struct pci_device_id *ent) |
| 3861 | { |
| 3862 | struct net_device *netdev; |
| 3863 | struct e1000_adapter *adapter; |
| 3864 | struct e1000_hw *hw; |
| 3865 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; |
| 3866 | unsigned long mmio_start, mmio_len; |
| 3867 | unsigned long flash_start, flash_len; |
| 3868 | |
| 3869 | static int cards_found; |
| 3870 | int i, err, pci_using_dac; |
| 3871 | u16 eeprom_data = 0; |
| 3872 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
| 3873 | |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 3874 | e1000e_disable_l1aspm(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3875 | err = pci_enable_device(pdev); |
| 3876 | if (err) |
| 3877 | return err; |
| 3878 | |
| 3879 | pci_using_dac = 0; |
| 3880 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); |
| 3881 | if (!err) { |
| 3882 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); |
| 3883 | if (!err) |
| 3884 | pci_using_dac = 1; |
| 3885 | } else { |
| 3886 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 3887 | if (err) { |
| 3888 | err = pci_set_consistent_dma_mask(pdev, |
| 3889 | DMA_32BIT_MASK); |
| 3890 | if (err) { |
| 3891 | dev_err(&pdev->dev, "No usable DMA " |
| 3892 | "configuration, aborting\n"); |
| 3893 | goto err_dma; |
| 3894 | } |
| 3895 | } |
| 3896 | } |
| 3897 | |
| 3898 | err = pci_request_regions(pdev, e1000e_driver_name); |
| 3899 | if (err) |
| 3900 | goto err_pci_reg; |
| 3901 | |
| 3902 | pci_set_master(pdev); |
| 3903 | |
| 3904 | err = -ENOMEM; |
| 3905 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
| 3906 | if (!netdev) |
| 3907 | goto err_alloc_etherdev; |
| 3908 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3909 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 3910 | |
| 3911 | pci_set_drvdata(pdev, netdev); |
| 3912 | adapter = netdev_priv(netdev); |
| 3913 | hw = &adapter->hw; |
| 3914 | adapter->netdev = netdev; |
| 3915 | adapter->pdev = pdev; |
| 3916 | adapter->ei = ei; |
| 3917 | adapter->pba = ei->pba; |
| 3918 | adapter->flags = ei->flags; |
| 3919 | adapter->hw.adapter = adapter; |
| 3920 | adapter->hw.mac.type = ei->mac; |
| 3921 | adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; |
| 3922 | |
| 3923 | mmio_start = pci_resource_start(pdev, 0); |
| 3924 | mmio_len = pci_resource_len(pdev, 0); |
| 3925 | |
| 3926 | err = -EIO; |
| 3927 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 3928 | if (!adapter->hw.hw_addr) |
| 3929 | goto err_ioremap; |
| 3930 | |
| 3931 | if ((adapter->flags & FLAG_HAS_FLASH) && |
| 3932 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
| 3933 | flash_start = pci_resource_start(pdev, 1); |
| 3934 | flash_len = pci_resource_len(pdev, 1); |
| 3935 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
| 3936 | if (!adapter->hw.flash_address) |
| 3937 | goto err_flashmap; |
| 3938 | } |
| 3939 | |
| 3940 | /* construct the net_device struct */ |
| 3941 | netdev->open = &e1000_open; |
| 3942 | netdev->stop = &e1000_close; |
| 3943 | netdev->hard_start_xmit = &e1000_xmit_frame; |
| 3944 | netdev->get_stats = &e1000_get_stats; |
| 3945 | netdev->set_multicast_list = &e1000_set_multi; |
| 3946 | netdev->set_mac_address = &e1000_set_mac; |
| 3947 | netdev->change_mtu = &e1000_change_mtu; |
| 3948 | netdev->do_ioctl = &e1000_ioctl; |
| 3949 | e1000e_set_ethtool_ops(netdev); |
| 3950 | netdev->tx_timeout = &e1000_tx_timeout; |
| 3951 | netdev->watchdog_timeo = 5 * HZ; |
| 3952 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
| 3953 | netdev->vlan_rx_register = e1000_vlan_rx_register; |
| 3954 | netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; |
| 3955 | netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid; |
| 3956 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3957 | netdev->poll_controller = e1000_netpoll; |
| 3958 | #endif |
| 3959 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
| 3960 | |
| 3961 | netdev->mem_start = mmio_start; |
| 3962 | netdev->mem_end = mmio_start + mmio_len; |
| 3963 | |
| 3964 | adapter->bd_number = cards_found++; |
| 3965 | |
| 3966 | /* setup adapter struct */ |
| 3967 | err = e1000_sw_init(adapter); |
| 3968 | if (err) |
| 3969 | goto err_sw_init; |
| 3970 | |
| 3971 | err = -EIO; |
| 3972 | |
| 3973 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 3974 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 3975 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 3976 | |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame^] | 3977 | err = ei->get_variants(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3978 | if (err) |
| 3979 | goto err_hw_init; |
| 3980 | |
| 3981 | hw->mac.ops.get_bus_info(&adapter->hw); |
| 3982 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3983 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3984 | |
| 3985 | /* Copper options */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3986 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3987 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
| 3988 | adapter->hw.phy.disable_polarity_correction = 0; |
| 3989 | adapter->hw.phy.ms_type = e1000_ms_hw_default; |
| 3990 | } |
| 3991 | |
| 3992 | if (e1000_check_reset_block(&adapter->hw)) |
| 3993 | ndev_info(netdev, |
| 3994 | "PHY reset is blocked due to SOL/IDER session.\n"); |
| 3995 | |
| 3996 | netdev->features = NETIF_F_SG | |
| 3997 | NETIF_F_HW_CSUM | |
| 3998 | NETIF_F_HW_VLAN_TX | |
| 3999 | NETIF_F_HW_VLAN_RX; |
| 4000 | |
| 4001 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
| 4002 | netdev->features |= NETIF_F_HW_VLAN_FILTER; |
| 4003 | |
| 4004 | netdev->features |= NETIF_F_TSO; |
| 4005 | netdev->features |= NETIF_F_TSO6; |
| 4006 | |
| 4007 | if (pci_using_dac) |
| 4008 | netdev->features |= NETIF_F_HIGHDMA; |
| 4009 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4010 | /* |
| 4011 | * We should not be using LLTX anymore, but we are still Tx faster with |
| 4012 | * it. |
| 4013 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4014 | netdev->features |= NETIF_F_LLTX; |
| 4015 | |
| 4016 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
| 4017 | adapter->flags |= FLAG_MNG_PT_ENABLED; |
| 4018 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4019 | /* |
| 4020 | * before reading the NVM, reset the controller to |
| 4021 | * put the device in a known good starting state |
| 4022 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4023 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 4024 | |
| 4025 | /* |
| 4026 | * systems with ASPM and others may see the checksum fail on the first |
| 4027 | * attempt. Let's give it a few tries |
| 4028 | */ |
| 4029 | for (i = 0;; i++) { |
| 4030 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) |
| 4031 | break; |
| 4032 | if (i == 2) { |
| 4033 | ndev_err(netdev, "The NVM Checksum Is Not Valid\n"); |
| 4034 | err = -EIO; |
| 4035 | goto err_eeprom; |
| 4036 | } |
| 4037 | } |
| 4038 | |
| 4039 | /* copy the MAC address out of the NVM */ |
| 4040 | if (e1000e_read_mac_addr(&adapter->hw)) |
| 4041 | ndev_err(netdev, "NVM Read Error while reading MAC address\n"); |
| 4042 | |
| 4043 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 4044 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 4045 | |
| 4046 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
| 4047 | ndev_err(netdev, "Invalid MAC Address: " |
| 4048 | "%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 4049 | netdev->perm_addr[0], netdev->perm_addr[1], |
| 4050 | netdev->perm_addr[2], netdev->perm_addr[3], |
| 4051 | netdev->perm_addr[4], netdev->perm_addr[5]); |
| 4052 | err = -EIO; |
| 4053 | goto err_eeprom; |
| 4054 | } |
| 4055 | |
| 4056 | init_timer(&adapter->watchdog_timer); |
| 4057 | adapter->watchdog_timer.function = &e1000_watchdog; |
| 4058 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 4059 | |
| 4060 | init_timer(&adapter->phy_info_timer); |
| 4061 | adapter->phy_info_timer.function = &e1000_update_phy_info; |
| 4062 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 4063 | |
| 4064 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
| 4065 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
| 4066 | |
| 4067 | e1000e_check_options(adapter); |
| 4068 | |
| 4069 | /* Initialize link parameters. User can change them with ethtool */ |
| 4070 | adapter->hw.mac.autoneg = 1; |
Auke Kok | 309af40 | 2007-10-05 15:22:02 -0700 | [diff] [blame] | 4071 | adapter->fc_autoneg = 1; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4072 | adapter->hw.fc.original_type = e1000_fc_default; |
| 4073 | adapter->hw.fc.type = e1000_fc_default; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4074 | adapter->hw.phy.autoneg_advertised = 0x2f; |
| 4075 | |
| 4076 | /* ring size defaults */ |
| 4077 | adapter->rx_ring->count = 256; |
| 4078 | adapter->tx_ring->count = 256; |
| 4079 | |
| 4080 | /* |
| 4081 | * Initial Wake on LAN setting - If APM wake is enabled in |
| 4082 | * the EEPROM, enable the ACPI Magic Packet filter |
| 4083 | */ |
| 4084 | if (adapter->flags & FLAG_APME_IN_WUC) { |
| 4085 | /* APME bit in EEPROM is mapped to WUC.APME */ |
| 4086 | eeprom_data = er32(WUC); |
| 4087 | eeprom_apme_mask = E1000_WUC_APME; |
| 4088 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
| 4089 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && |
| 4090 | (adapter->hw.bus.func == 1)) |
| 4091 | e1000_read_nvm(&adapter->hw, |
| 4092 | NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 4093 | else |
| 4094 | e1000_read_nvm(&adapter->hw, |
| 4095 | NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 4096 | } |
| 4097 | |
| 4098 | /* fetch WoL from EEPROM */ |
| 4099 | if (eeprom_data & eeprom_apme_mask) |
| 4100 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 4101 | |
| 4102 | /* |
| 4103 | * now that we have the eeprom settings, apply the special cases |
| 4104 | * where the eeprom may be wrong or the board simply won't support |
| 4105 | * wake on lan on a particular port |
| 4106 | */ |
| 4107 | if (!(adapter->flags & FLAG_HAS_WOL)) |
| 4108 | adapter->eeprom_wol = 0; |
| 4109 | |
| 4110 | /* initialize the wol settings based on the eeprom settings */ |
| 4111 | adapter->wol = adapter->eeprom_wol; |
| 4112 | |
| 4113 | /* reset the hardware with the new settings */ |
| 4114 | e1000e_reset(adapter); |
| 4115 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4116 | /* |
| 4117 | * If the controller has AMT, do not set DRV_LOAD until the interface |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4118 | * is up. For all other cases, let the f/w know that the h/w is now |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4119 | * under the control of the driver. |
| 4120 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4121 | if (!(adapter->flags & FLAG_HAS_AMT) || |
| 4122 | !e1000e_check_mng_mode(&adapter->hw)) |
| 4123 | e1000_get_hw_control(adapter); |
| 4124 | |
| 4125 | /* tell the stack to leave us alone until e1000_open() is called */ |
| 4126 | netif_carrier_off(netdev); |
| 4127 | netif_stop_queue(netdev); |
| 4128 | |
| 4129 | strcpy(netdev->name, "eth%d"); |
| 4130 | err = register_netdev(netdev); |
| 4131 | if (err) |
| 4132 | goto err_register; |
| 4133 | |
| 4134 | e1000_print_device_info(adapter); |
| 4135 | |
| 4136 | return 0; |
| 4137 | |
| 4138 | err_register: |
| 4139 | err_hw_init: |
| 4140 | e1000_release_hw_control(adapter); |
| 4141 | err_eeprom: |
| 4142 | if (!e1000_check_reset_block(&adapter->hw)) |
| 4143 | e1000_phy_hw_reset(&adapter->hw); |
| 4144 | |
| 4145 | if (adapter->hw.flash_address) |
| 4146 | iounmap(adapter->hw.flash_address); |
| 4147 | |
| 4148 | err_flashmap: |
| 4149 | kfree(adapter->tx_ring); |
| 4150 | kfree(adapter->rx_ring); |
| 4151 | err_sw_init: |
| 4152 | iounmap(adapter->hw.hw_addr); |
| 4153 | err_ioremap: |
| 4154 | free_netdev(netdev); |
| 4155 | err_alloc_etherdev: |
| 4156 | pci_release_regions(pdev); |
| 4157 | err_pci_reg: |
| 4158 | err_dma: |
| 4159 | pci_disable_device(pdev); |
| 4160 | return err; |
| 4161 | } |
| 4162 | |
| 4163 | /** |
| 4164 | * e1000_remove - Device Removal Routine |
| 4165 | * @pdev: PCI device information struct |
| 4166 | * |
| 4167 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 4168 | * that it should release a PCI device. The could be caused by a |
| 4169 | * Hot-Plug event, or because the driver is going to be removed from |
| 4170 | * memory. |
| 4171 | **/ |
| 4172 | static void __devexit e1000_remove(struct pci_dev *pdev) |
| 4173 | { |
| 4174 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4175 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4176 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4177 | /* |
| 4178 | * flush_scheduled work may reschedule our watchdog task, so |
| 4179 | * explicitly disable watchdog tasks from being rescheduled |
| 4180 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4181 | set_bit(__E1000_DOWN, &adapter->state); |
| 4182 | del_timer_sync(&adapter->watchdog_timer); |
| 4183 | del_timer_sync(&adapter->phy_info_timer); |
| 4184 | |
| 4185 | flush_scheduled_work(); |
| 4186 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4187 | /* |
| 4188 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 4189 | * would have already happened in close and is redundant. |
| 4190 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4191 | e1000_release_hw_control(adapter); |
| 4192 | |
| 4193 | unregister_netdev(netdev); |
| 4194 | |
| 4195 | if (!e1000_check_reset_block(&adapter->hw)) |
| 4196 | e1000_phy_hw_reset(&adapter->hw); |
| 4197 | |
| 4198 | kfree(adapter->tx_ring); |
| 4199 | kfree(adapter->rx_ring); |
| 4200 | |
| 4201 | iounmap(adapter->hw.hw_addr); |
| 4202 | if (adapter->hw.flash_address) |
| 4203 | iounmap(adapter->hw.flash_address); |
| 4204 | pci_release_regions(pdev); |
| 4205 | |
| 4206 | free_netdev(netdev); |
| 4207 | |
| 4208 | pci_disable_device(pdev); |
| 4209 | } |
| 4210 | |
| 4211 | /* PCI Error Recovery (ERS) */ |
| 4212 | static struct pci_error_handlers e1000_err_handler = { |
| 4213 | .error_detected = e1000_io_error_detected, |
| 4214 | .slot_reset = e1000_io_slot_reset, |
| 4215 | .resume = e1000_io_resume, |
| 4216 | }; |
| 4217 | |
| 4218 | static struct pci_device_id e1000_pci_tbl[] = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4219 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
| 4220 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, |
| 4221 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, |
| 4222 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 }, |
| 4223 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
| 4224 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, |
Auke Kok | 040babf | 2007-10-31 15:22:05 -0700 | [diff] [blame] | 4225 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
| 4226 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, |
| 4227 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4228 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4229 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
| 4230 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, |
| 4231 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, |
| 4232 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4233 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4234 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
| 4235 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, |
| 4236 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4237 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4238 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
| 4239 | board_80003es2lan }, |
| 4240 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), |
| 4241 | board_80003es2lan }, |
| 4242 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), |
| 4243 | board_80003es2lan }, |
| 4244 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), |
| 4245 | board_80003es2lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4246 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4247 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
| 4248 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, |
| 4249 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, |
| 4250 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, |
| 4251 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, |
| 4252 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, |
| 4253 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4254 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4255 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
| 4256 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, |
| 4257 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, |
| 4258 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, |
| 4259 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, |
| 4260 | |
| 4261 | { } /* terminate list */ |
| 4262 | }; |
| 4263 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 4264 | |
| 4265 | /* PCI Device API Driver */ |
| 4266 | static struct pci_driver e1000_driver = { |
| 4267 | .name = e1000e_driver_name, |
| 4268 | .id_table = e1000_pci_tbl, |
| 4269 | .probe = e1000_probe, |
| 4270 | .remove = __devexit_p(e1000_remove), |
| 4271 | #ifdef CONFIG_PM |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4272 | /* Power Management Hooks */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4273 | .suspend = e1000_suspend, |
| 4274 | .resume = e1000_resume, |
| 4275 | #endif |
| 4276 | .shutdown = e1000_shutdown, |
| 4277 | .err_handler = &e1000_err_handler |
| 4278 | }; |
| 4279 | |
| 4280 | /** |
| 4281 | * e1000_init_module - Driver Registration Routine |
| 4282 | * |
| 4283 | * e1000_init_module is the first routine called when the driver is |
| 4284 | * loaded. All it does is register with the PCI subsystem. |
| 4285 | **/ |
| 4286 | static int __init e1000_init_module(void) |
| 4287 | { |
| 4288 | int ret; |
| 4289 | printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n", |
| 4290 | e1000e_driver_name, e1000e_driver_version); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4291 | printk(KERN_INFO "%s: Copyright (c) 1999-2008 Intel Corporation.\n", |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4292 | e1000e_driver_name); |
| 4293 | ret = pci_register_driver(&e1000_driver); |
| 4294 | |
| 4295 | return ret; |
| 4296 | } |
| 4297 | module_init(e1000_init_module); |
| 4298 | |
| 4299 | /** |
| 4300 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 4301 | * |
| 4302 | * e1000_exit_module is called just before the driver is removed |
| 4303 | * from memory. |
| 4304 | **/ |
| 4305 | static void __exit e1000_exit_module(void) |
| 4306 | { |
| 4307 | pci_unregister_driver(&e1000_driver); |
| 4308 | } |
| 4309 | module_exit(e1000_exit_module); |
| 4310 | |
| 4311 | |
| 4312 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 4313 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 4314 | MODULE_LICENSE("GPL"); |
| 4315 | MODULE_VERSION(DRV_VERSION); |
| 4316 | |
| 4317 | /* e1000_main.c */ |