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> |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 46 | #include <linux/pm_qos_params.h> |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 47 | #include <linux/aer.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 48 | |
| 49 | #include "e1000.h" |
| 50 | |
Bruce Allan | 3be8c94 | 2009-06-02 11:29:56 +0000 | [diff] [blame] | 51 | #define DRV_VERSION "1.0.2-k2" |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 52 | char e1000e_driver_name[] = "e1000e"; |
| 53 | const char e1000e_driver_version[] = DRV_VERSION; |
| 54 | |
| 55 | static const struct e1000_info *e1000_info_tbl[] = { |
| 56 | [board_82571] = &e1000_82571_info, |
| 57 | [board_82572] = &e1000_82572_info, |
| 58 | [board_82573] = &e1000_82573_info, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 59 | [board_82574] = &e1000_82574_info, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 60 | [board_82583] = &e1000_82583_info, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 61 | [board_80003es2lan] = &e1000_es2_info, |
| 62 | [board_ich8lan] = &e1000_ich8_info, |
| 63 | [board_ich9lan] = &e1000_ich9_info, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 64 | [board_ich10lan] = &e1000_ich10_info, |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 65 | [board_pchlan] = &e1000_pch_info, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | #ifdef DEBUG |
| 69 | /** |
| 70 | * e1000_get_hw_dev_name - return device name string |
| 71 | * used by hardware layer to print debugging information |
| 72 | **/ |
| 73 | char *e1000e_get_hw_dev_name(struct e1000_hw *hw) |
| 74 | { |
Auke Kok | 589c085 | 2007-10-04 11:38:43 -0700 | [diff] [blame] | 75 | return hw->adapter->netdev->name; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 76 | } |
| 77 | #endif |
| 78 | |
| 79 | /** |
| 80 | * e1000_desc_unused - calculate if we have unused descriptors |
| 81 | **/ |
| 82 | static int e1000_desc_unused(struct e1000_ring *ring) |
| 83 | { |
| 84 | if (ring->next_to_clean > ring->next_to_use) |
| 85 | return ring->next_to_clean - ring->next_to_use - 1; |
| 86 | |
| 87 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; |
| 88 | } |
| 89 | |
| 90 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 91 | * e1000_receive_skb - helper function to handle Rx indications |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 92 | * @adapter: board private structure |
| 93 | * @status: descriptor status field as written by hardware |
| 94 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
| 95 | * @skb: pointer to sk_buff to be indicated to stack |
| 96 | **/ |
| 97 | static void e1000_receive_skb(struct e1000_adapter *adapter, |
| 98 | struct net_device *netdev, |
| 99 | struct sk_buff *skb, |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 100 | u8 status, __le16 vlan) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 101 | { |
| 102 | skb->protocol = eth_type_trans(skb, netdev); |
| 103 | |
| 104 | if (adapter->vlgrp && (status & E1000_RXD_STAT_VP)) |
Herbert Xu | c405b82 | 2009-01-14 20:37:59 -0800 | [diff] [blame] | 105 | vlan_gro_receive(&adapter->napi, adapter->vlgrp, |
| 106 | le16_to_cpu(vlan), skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 107 | else |
Herbert Xu | 89c88b1 | 2008-12-15 23:46:15 -0800 | [diff] [blame] | 108 | napi_gro_receive(&adapter->napi, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /** |
| 112 | * e1000_rx_checksum - Receive Checksum Offload for 82543 |
| 113 | * @adapter: board private structure |
| 114 | * @status_err: receive descriptor status and error fields |
| 115 | * @csum: receive descriptor csum field |
| 116 | * @sk_buff: socket buffer with received data |
| 117 | **/ |
| 118 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
| 119 | u32 csum, struct sk_buff *skb) |
| 120 | { |
| 121 | u16 status = (u16)status_err; |
| 122 | u8 errors = (u8)(status_err >> 24); |
| 123 | skb->ip_summed = CHECKSUM_NONE; |
| 124 | |
| 125 | /* Ignore Checksum bit is set */ |
| 126 | if (status & E1000_RXD_STAT_IXSM) |
| 127 | return; |
| 128 | /* TCP/UDP checksum error bit is set */ |
| 129 | if (errors & E1000_RXD_ERR_TCPE) { |
| 130 | /* let the stack verify checksum errors */ |
| 131 | adapter->hw_csum_err++; |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | /* TCP/UDP Checksum has not been calculated */ |
| 136 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
| 137 | return; |
| 138 | |
| 139 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 140 | if (status & E1000_RXD_STAT_TCPCS) { |
| 141 | /* TCP checksum is good */ |
| 142 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 143 | } else { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 144 | /* |
| 145 | * IP fragment with UDP payload |
| 146 | * Hardware complements the payload checksum, so we undo it |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 147 | * and then put the value in host order for further stack use. |
| 148 | */ |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 149 | __sum16 sum = (__force __sum16)htons(csum); |
| 150 | skb->csum = csum_unfold(~sum); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 151 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 152 | } |
| 153 | adapter->hw_csum_good++; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
| 158 | * @adapter: address of board private structure |
| 159 | **/ |
| 160 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
| 161 | int cleaned_count) |
| 162 | { |
| 163 | struct net_device *netdev = adapter->netdev; |
| 164 | struct pci_dev *pdev = adapter->pdev; |
| 165 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 166 | struct e1000_rx_desc *rx_desc; |
| 167 | struct e1000_buffer *buffer_info; |
| 168 | struct sk_buff *skb; |
| 169 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 170 | unsigned int bufsz = adapter->rx_buffer_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 171 | |
| 172 | i = rx_ring->next_to_use; |
| 173 | buffer_info = &rx_ring->buffer_info[i]; |
| 174 | |
| 175 | while (cleaned_count--) { |
| 176 | skb = buffer_info->skb; |
| 177 | if (skb) { |
| 178 | skb_trim(skb, 0); |
| 179 | goto map_skb; |
| 180 | } |
| 181 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 182 | skb = netdev_alloc_skb_ip_align(netdev, bufsz); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 183 | if (!skb) { |
| 184 | /* Better luck next round */ |
| 185 | adapter->alloc_rx_buff_failed++; |
| 186 | break; |
| 187 | } |
| 188 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 189 | buffer_info->skb = skb; |
| 190 | map_skb: |
| 191 | buffer_info->dma = pci_map_single(pdev, skb->data, |
| 192 | adapter->rx_buffer_len, |
| 193 | PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 194 | if (pci_dma_mapping_error(pdev, buffer_info->dma)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 195 | dev_err(&pdev->dev, "RX DMA map failed\n"); |
| 196 | adapter->rx_dma_failed++; |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 201 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 202 | |
| 203 | i++; |
| 204 | if (i == rx_ring->count) |
| 205 | i = 0; |
| 206 | buffer_info = &rx_ring->buffer_info[i]; |
| 207 | } |
| 208 | |
| 209 | if (rx_ring->next_to_use != i) { |
| 210 | rx_ring->next_to_use = i; |
| 211 | if (i-- == 0) |
| 212 | i = (rx_ring->count - 1); |
| 213 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 214 | /* |
| 215 | * Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 216 | * know there are new descriptors to fetch. (Only |
| 217 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 218 | * such as IA-64). |
| 219 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 220 | wmb(); |
| 221 | writel(i, adapter->hw.hw_addr + rx_ring->tail); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
| 227 | * @adapter: address of board private structure |
| 228 | **/ |
| 229 | static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
| 230 | int cleaned_count) |
| 231 | { |
| 232 | struct net_device *netdev = adapter->netdev; |
| 233 | struct pci_dev *pdev = adapter->pdev; |
| 234 | union e1000_rx_desc_packet_split *rx_desc; |
| 235 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 236 | struct e1000_buffer *buffer_info; |
| 237 | struct e1000_ps_page *ps_page; |
| 238 | struct sk_buff *skb; |
| 239 | unsigned int i, j; |
| 240 | |
| 241 | i = rx_ring->next_to_use; |
| 242 | buffer_info = &rx_ring->buffer_info[i]; |
| 243 | |
| 244 | while (cleaned_count--) { |
| 245 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 246 | |
| 247 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 248 | ps_page = &buffer_info->ps_pages[j]; |
| 249 | if (j >= adapter->rx_ps_pages) { |
| 250 | /* all unused desc entries get hw null ptr */ |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 251 | rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 252 | continue; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 253 | } |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 254 | if (!ps_page->page) { |
| 255 | ps_page->page = alloc_page(GFP_ATOMIC); |
| 256 | if (!ps_page->page) { |
| 257 | adapter->alloc_rx_buff_failed++; |
| 258 | goto no_buffers; |
| 259 | } |
| 260 | ps_page->dma = pci_map_page(pdev, |
| 261 | ps_page->page, |
| 262 | 0, PAGE_SIZE, |
| 263 | PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 264 | if (pci_dma_mapping_error(pdev, ps_page->dma)) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 265 | dev_err(&adapter->pdev->dev, |
| 266 | "RX DMA page map failed\n"); |
| 267 | adapter->rx_dma_failed++; |
| 268 | goto no_buffers; |
| 269 | } |
| 270 | } |
| 271 | /* |
| 272 | * Refresh the desc even if buffer_addrs |
| 273 | * didn't change because each write-back |
| 274 | * erases this info. |
| 275 | */ |
| 276 | rx_desc->read.buffer_addr[j+1] = |
| 277 | cpu_to_le64(ps_page->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 280 | skb = netdev_alloc_skb_ip_align(netdev, |
| 281 | adapter->rx_ps_bsize0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 282 | |
| 283 | if (!skb) { |
| 284 | adapter->alloc_rx_buff_failed++; |
| 285 | break; |
| 286 | } |
| 287 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 288 | buffer_info->skb = skb; |
| 289 | buffer_info->dma = pci_map_single(pdev, skb->data, |
| 290 | adapter->rx_ps_bsize0, |
| 291 | PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 292 | if (pci_dma_mapping_error(pdev, buffer_info->dma)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 293 | dev_err(&pdev->dev, "RX DMA map failed\n"); |
| 294 | adapter->rx_dma_failed++; |
| 295 | /* cleanup skb */ |
| 296 | dev_kfree_skb_any(skb); |
| 297 | buffer_info->skb = NULL; |
| 298 | break; |
| 299 | } |
| 300 | |
| 301 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 302 | |
| 303 | i++; |
| 304 | if (i == rx_ring->count) |
| 305 | i = 0; |
| 306 | buffer_info = &rx_ring->buffer_info[i]; |
| 307 | } |
| 308 | |
| 309 | no_buffers: |
| 310 | if (rx_ring->next_to_use != i) { |
| 311 | rx_ring->next_to_use = i; |
| 312 | |
| 313 | if (!(i--)) |
| 314 | i = (rx_ring->count - 1); |
| 315 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 316 | /* |
| 317 | * Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 318 | * know there are new descriptors to fetch. (Only |
| 319 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 320 | * such as IA-64). |
| 321 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 322 | wmb(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 323 | /* |
| 324 | * Hardware increments by 16 bytes, but packet split |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 325 | * descriptors are 32 bytes...so we increment tail |
| 326 | * twice as much. |
| 327 | */ |
| 328 | writel(i<<1, adapter->hw.hw_addr + rx_ring->tail); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 333 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
| 334 | * @adapter: address of board private structure |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 335 | * @cleaned_count: number of buffers to allocate this pass |
| 336 | **/ |
| 337 | |
| 338 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, |
| 339 | int cleaned_count) |
| 340 | { |
| 341 | struct net_device *netdev = adapter->netdev; |
| 342 | struct pci_dev *pdev = adapter->pdev; |
| 343 | struct e1000_rx_desc *rx_desc; |
| 344 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 345 | struct e1000_buffer *buffer_info; |
| 346 | struct sk_buff *skb; |
| 347 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 348 | unsigned int bufsz = 256 - 16 /* for skb_reserve */; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 349 | |
| 350 | i = rx_ring->next_to_use; |
| 351 | buffer_info = &rx_ring->buffer_info[i]; |
| 352 | |
| 353 | while (cleaned_count--) { |
| 354 | skb = buffer_info->skb; |
| 355 | if (skb) { |
| 356 | skb_trim(skb, 0); |
| 357 | goto check_page; |
| 358 | } |
| 359 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 360 | skb = netdev_alloc_skb_ip_align(netdev, bufsz); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 361 | if (unlikely(!skb)) { |
| 362 | /* Better luck next round */ |
| 363 | adapter->alloc_rx_buff_failed++; |
| 364 | break; |
| 365 | } |
| 366 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 367 | buffer_info->skb = skb; |
| 368 | check_page: |
| 369 | /* allocate a new page if necessary */ |
| 370 | if (!buffer_info->page) { |
| 371 | buffer_info->page = alloc_page(GFP_ATOMIC); |
| 372 | if (unlikely(!buffer_info->page)) { |
| 373 | adapter->alloc_rx_buff_failed++; |
| 374 | break; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | if (!buffer_info->dma) |
| 379 | buffer_info->dma = pci_map_page(pdev, |
| 380 | buffer_info->page, 0, |
| 381 | PAGE_SIZE, |
| 382 | PCI_DMA_FROMDEVICE); |
| 383 | |
| 384 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 385 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 386 | |
| 387 | if (unlikely(++i == rx_ring->count)) |
| 388 | i = 0; |
| 389 | buffer_info = &rx_ring->buffer_info[i]; |
| 390 | } |
| 391 | |
| 392 | if (likely(rx_ring->next_to_use != i)) { |
| 393 | rx_ring->next_to_use = i; |
| 394 | if (unlikely(i-- == 0)) |
| 395 | i = (rx_ring->count - 1); |
| 396 | |
| 397 | /* Force memory writes to complete before letting h/w |
| 398 | * know there are new descriptors to fetch. (Only |
| 399 | * applicable for weak-ordered memory model archs, |
| 400 | * such as IA-64). */ |
| 401 | wmb(); |
| 402 | writel(i, adapter->hw.hw_addr + rx_ring->tail); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 407 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
| 408 | * @adapter: board private structure |
| 409 | * |
| 410 | * the return value indicates whether actual cleaning was done, there |
| 411 | * is no guarantee that everything was cleaned |
| 412 | **/ |
| 413 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 414 | int *work_done, int work_to_do) |
| 415 | { |
| 416 | struct net_device *netdev = adapter->netdev; |
| 417 | struct pci_dev *pdev = adapter->pdev; |
| 418 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 419 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 420 | struct e1000_buffer *buffer_info, *next_buffer; |
| 421 | u32 length; |
| 422 | unsigned int i; |
| 423 | int cleaned_count = 0; |
| 424 | bool cleaned = 0; |
| 425 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 426 | |
| 427 | i = rx_ring->next_to_clean; |
| 428 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 429 | buffer_info = &rx_ring->buffer_info[i]; |
| 430 | |
| 431 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
| 432 | struct sk_buff *skb; |
| 433 | u8 status; |
| 434 | |
| 435 | if (*work_done >= work_to_do) |
| 436 | break; |
| 437 | (*work_done)++; |
| 438 | |
| 439 | status = rx_desc->status; |
| 440 | skb = buffer_info->skb; |
| 441 | buffer_info->skb = NULL; |
| 442 | |
| 443 | prefetch(skb->data - NET_IP_ALIGN); |
| 444 | |
| 445 | i++; |
| 446 | if (i == rx_ring->count) |
| 447 | i = 0; |
| 448 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
| 449 | prefetch(next_rxd); |
| 450 | |
| 451 | next_buffer = &rx_ring->buffer_info[i]; |
| 452 | |
| 453 | cleaned = 1; |
| 454 | cleaned_count++; |
| 455 | pci_unmap_single(pdev, |
| 456 | buffer_info->dma, |
| 457 | adapter->rx_buffer_len, |
| 458 | PCI_DMA_FROMDEVICE); |
| 459 | buffer_info->dma = 0; |
| 460 | |
| 461 | length = le16_to_cpu(rx_desc->length); |
| 462 | |
| 463 | /* !EOP means multiple descriptors were used to store a single |
| 464 | * packet, also make sure the frame isn't just CRC only */ |
| 465 | if (!(status & E1000_RXD_STAT_EOP) || (length <= 4)) { |
| 466 | /* All receives must fit into a single buffer */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 467 | e_dbg("%s: Receive packet consumed multiple buffers\n", |
| 468 | netdev->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 469 | /* recycle */ |
| 470 | buffer_info->skb = skb; |
| 471 | goto next_desc; |
| 472 | } |
| 473 | |
| 474 | if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) { |
| 475 | /* recycle */ |
| 476 | buffer_info->skb = skb; |
| 477 | goto next_desc; |
| 478 | } |
| 479 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 480 | /* adjust length to remove Ethernet CRC */ |
| 481 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 482 | length -= 4; |
| 483 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 484 | total_rx_bytes += length; |
| 485 | total_rx_packets++; |
| 486 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 487 | /* |
| 488 | * code added for copybreak, this should improve |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 489 | * performance for small packets with large amounts |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 490 | * of reassembly being done in the stack |
| 491 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 492 | if (length < copybreak) { |
| 493 | struct sk_buff *new_skb = |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 494 | netdev_alloc_skb_ip_align(netdev, length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 495 | if (new_skb) { |
Bruce Allan | 808ff67 | 2008-08-08 18:35:56 -0700 | [diff] [blame] | 496 | skb_copy_to_linear_data_offset(new_skb, |
| 497 | -NET_IP_ALIGN, |
| 498 | (skb->data - |
| 499 | NET_IP_ALIGN), |
| 500 | (length + |
| 501 | NET_IP_ALIGN)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 502 | /* save the skb in buffer_info as good */ |
| 503 | buffer_info->skb = skb; |
| 504 | skb = new_skb; |
| 505 | } |
| 506 | /* else just continue with the old one */ |
| 507 | } |
| 508 | /* end copybreak code */ |
| 509 | skb_put(skb, length); |
| 510 | |
| 511 | /* Receive Checksum Offload */ |
| 512 | e1000_rx_checksum(adapter, |
| 513 | (u32)(status) | |
| 514 | ((u32)(rx_desc->errors) << 24), |
| 515 | le16_to_cpu(rx_desc->csum), skb); |
| 516 | |
| 517 | e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special); |
| 518 | |
| 519 | next_desc: |
| 520 | rx_desc->status = 0; |
| 521 | |
| 522 | /* return some buffers to hardware, one at a time is too slow */ |
| 523 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
| 524 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 525 | cleaned_count = 0; |
| 526 | } |
| 527 | |
| 528 | /* use prefetched values */ |
| 529 | rx_desc = next_rxd; |
| 530 | buffer_info = next_buffer; |
| 531 | } |
| 532 | rx_ring->next_to_clean = i; |
| 533 | |
| 534 | cleaned_count = e1000_desc_unused(rx_ring); |
| 535 | if (cleaned_count) |
| 536 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 537 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 538 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 539 | adapter->total_rx_packets += total_rx_packets; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 540 | netdev->stats.rx_bytes += total_rx_bytes; |
| 541 | netdev->stats.rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 542 | return cleaned; |
| 543 | } |
| 544 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 545 | static void e1000_put_txbuf(struct e1000_adapter *adapter, |
| 546 | struct e1000_buffer *buffer_info) |
| 547 | { |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 548 | buffer_info->dma = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 549 | if (buffer_info->skb) { |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 550 | skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb, |
| 551 | DMA_TO_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 552 | dev_kfree_skb_any(buffer_info->skb); |
| 553 | buffer_info->skb = NULL; |
| 554 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 555 | buffer_info->time_stamp = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | static void e1000_print_tx_hang(struct e1000_adapter *adapter) |
| 559 | { |
| 560 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 561 | unsigned int i = tx_ring->next_to_clean; |
| 562 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; |
| 563 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 564 | |
| 565 | /* detected Tx unit hang */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 566 | e_err("Detected Tx Unit Hang:\n" |
| 567 | " TDH <%x>\n" |
| 568 | " TDT <%x>\n" |
| 569 | " next_to_use <%x>\n" |
| 570 | " next_to_clean <%x>\n" |
| 571 | "buffer_info[next_to_clean]:\n" |
| 572 | " time_stamp <%lx>\n" |
| 573 | " next_to_watch <%x>\n" |
| 574 | " jiffies <%lx>\n" |
| 575 | " next_to_watch.status <%x>\n", |
| 576 | readl(adapter->hw.hw_addr + tx_ring->head), |
| 577 | readl(adapter->hw.hw_addr + tx_ring->tail), |
| 578 | tx_ring->next_to_use, |
| 579 | tx_ring->next_to_clean, |
| 580 | tx_ring->buffer_info[eop].time_stamp, |
| 581 | eop, |
| 582 | jiffies, |
| 583 | eop_desc->upper.fields.status); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /** |
| 587 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 588 | * @adapter: board private structure |
| 589 | * |
| 590 | * the return value indicates whether actual cleaning was done, there |
| 591 | * is no guarantee that everything was cleaned |
| 592 | **/ |
| 593 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter) |
| 594 | { |
| 595 | struct net_device *netdev = adapter->netdev; |
| 596 | struct e1000_hw *hw = &adapter->hw; |
| 597 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 598 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 599 | struct e1000_buffer *buffer_info; |
| 600 | unsigned int i, eop; |
| 601 | unsigned int count = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 602 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; |
| 603 | |
| 604 | i = tx_ring->next_to_clean; |
| 605 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 606 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 607 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 608 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 609 | (count < tx_ring->count)) { |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 610 | bool cleaned = false; |
| 611 | for (; !cleaned; count++) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 612 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 613 | buffer_info = &tx_ring->buffer_info[i]; |
| 614 | cleaned = (i == eop); |
| 615 | |
| 616 | if (cleaned) { |
| 617 | struct sk_buff *skb = buffer_info->skb; |
| 618 | unsigned int segs, bytecount; |
| 619 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 620 | /* multiply data chunks by size of headers */ |
| 621 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
| 622 | skb->len; |
| 623 | total_tx_packets += segs; |
| 624 | total_tx_bytes += bytecount; |
| 625 | } |
| 626 | |
| 627 | e1000_put_txbuf(adapter, buffer_info); |
| 628 | tx_desc->upper.data = 0; |
| 629 | |
| 630 | i++; |
| 631 | if (i == tx_ring->count) |
| 632 | i = 0; |
| 633 | } |
| 634 | |
| 635 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 636 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | tx_ring->next_to_clean = i; |
| 640 | |
| 641 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 642 | if (count && netif_carrier_ok(netdev) && |
| 643 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 644 | /* Make sure that anybody stopping the queue after this |
| 645 | * sees the new next_to_clean. |
| 646 | */ |
| 647 | smp_mb(); |
| 648 | |
| 649 | if (netif_queue_stopped(netdev) && |
| 650 | !(test_bit(__E1000_DOWN, &adapter->state))) { |
| 651 | netif_wake_queue(netdev); |
| 652 | ++adapter->restart_queue; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | if (adapter->detect_tx_hung) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 657 | /* Detect a transmit hang in hardware, this serializes the |
| 658 | * check with the clearing of time_stamp and movement of i */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 659 | adapter->detect_tx_hung = 0; |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 660 | if (tx_ring->buffer_info[i].time_stamp && |
| 661 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 662 | + (adapter->tx_timeout_factor * HZ)) |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 663 | && !(er32(STATUS) & E1000_STATUS_TXOFF)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 664 | e1000_print_tx_hang(adapter); |
| 665 | netif_stop_queue(netdev); |
| 666 | } |
| 667 | } |
| 668 | adapter->total_tx_bytes += total_tx_bytes; |
| 669 | adapter->total_tx_packets += total_tx_packets; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 670 | netdev->stats.tx_bytes += total_tx_bytes; |
| 671 | netdev->stats.tx_packets += total_tx_packets; |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 672 | return (count < tx_ring->count); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 676 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
| 677 | * @adapter: board private structure |
| 678 | * |
| 679 | * the return value indicates whether actual cleaning was done, there |
| 680 | * is no guarantee that everything was cleaned |
| 681 | **/ |
| 682 | static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 683 | int *work_done, int work_to_do) |
| 684 | { |
| 685 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
| 686 | struct net_device *netdev = adapter->netdev; |
| 687 | struct pci_dev *pdev = adapter->pdev; |
| 688 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 689 | struct e1000_buffer *buffer_info, *next_buffer; |
| 690 | struct e1000_ps_page *ps_page; |
| 691 | struct sk_buff *skb; |
| 692 | unsigned int i, j; |
| 693 | u32 length, staterr; |
| 694 | int cleaned_count = 0; |
| 695 | bool cleaned = 0; |
| 696 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 697 | |
| 698 | i = rx_ring->next_to_clean; |
| 699 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 700 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 701 | buffer_info = &rx_ring->buffer_info[i]; |
| 702 | |
| 703 | while (staterr & E1000_RXD_STAT_DD) { |
| 704 | if (*work_done >= work_to_do) |
| 705 | break; |
| 706 | (*work_done)++; |
| 707 | skb = buffer_info->skb; |
| 708 | |
| 709 | /* in the packet split case this is header only */ |
| 710 | prefetch(skb->data - NET_IP_ALIGN); |
| 711 | |
| 712 | i++; |
| 713 | if (i == rx_ring->count) |
| 714 | i = 0; |
| 715 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
| 716 | prefetch(next_rxd); |
| 717 | |
| 718 | next_buffer = &rx_ring->buffer_info[i]; |
| 719 | |
| 720 | cleaned = 1; |
| 721 | cleaned_count++; |
| 722 | pci_unmap_single(pdev, buffer_info->dma, |
| 723 | adapter->rx_ps_bsize0, |
| 724 | PCI_DMA_FROMDEVICE); |
| 725 | buffer_info->dma = 0; |
| 726 | |
| 727 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 728 | e_dbg("%s: Packet Split buffers didn't pick up the " |
| 729 | "full packet\n", netdev->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 730 | dev_kfree_skb_irq(skb); |
| 731 | goto next_desc; |
| 732 | } |
| 733 | |
| 734 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
| 735 | dev_kfree_skb_irq(skb); |
| 736 | goto next_desc; |
| 737 | } |
| 738 | |
| 739 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 740 | |
| 741 | if (!length) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 742 | e_dbg("%s: Last part of the packet spanning multiple " |
| 743 | "descriptors\n", netdev->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 744 | dev_kfree_skb_irq(skb); |
| 745 | goto next_desc; |
| 746 | } |
| 747 | |
| 748 | /* Good Receive */ |
| 749 | skb_put(skb, length); |
| 750 | |
| 751 | { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 752 | /* |
| 753 | * this looks ugly, but it seems compiler issues make it |
| 754 | * more efficient than reusing j |
| 755 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 756 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 757 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 758 | /* |
| 759 | * page alloc/put takes too long and effects small packet |
| 760 | * throughput, so unsplit small packets and save the alloc/put |
| 761 | * only valid in softirq (napi) context to call kmap_* |
| 762 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 763 | if (l1 && (l1 <= copybreak) && |
| 764 | ((length + l1) <= adapter->rx_ps_bsize0)) { |
| 765 | u8 *vaddr; |
| 766 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 767 | ps_page = &buffer_info->ps_pages[0]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 768 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 769 | /* |
| 770 | * there is no documentation about how to call |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 771 | * kmap_atomic, so we can't hold the mapping |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 772 | * very long |
| 773 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 774 | pci_dma_sync_single_for_cpu(pdev, ps_page->dma, |
| 775 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 776 | vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ); |
| 777 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
| 778 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
| 779 | pci_dma_sync_single_for_device(pdev, ps_page->dma, |
| 780 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 781 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 782 | /* remove the CRC */ |
| 783 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 784 | l1 -= 4; |
| 785 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 786 | skb_put(skb, l1); |
| 787 | goto copydone; |
| 788 | } /* if */ |
| 789 | } |
| 790 | |
| 791 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
| 792 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); |
| 793 | if (!length) |
| 794 | break; |
| 795 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 796 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 797 | pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE, |
| 798 | PCI_DMA_FROMDEVICE); |
| 799 | ps_page->dma = 0; |
| 800 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); |
| 801 | ps_page->page = NULL; |
| 802 | skb->len += length; |
| 803 | skb->data_len += length; |
| 804 | skb->truesize += length; |
| 805 | } |
| 806 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 807 | /* strip the ethernet crc, problem is we're using pages now so |
| 808 | * this whole operation can get a little cpu intensive |
| 809 | */ |
| 810 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 811 | pskb_trim(skb, skb->len - 4); |
| 812 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 813 | copydone: |
| 814 | total_rx_bytes += skb->len; |
| 815 | total_rx_packets++; |
| 816 | |
| 817 | e1000_rx_checksum(adapter, staterr, le16_to_cpu( |
| 818 | rx_desc->wb.lower.hi_dword.csum_ip.csum), skb); |
| 819 | |
| 820 | if (rx_desc->wb.upper.header_status & |
| 821 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) |
| 822 | adapter->rx_hdr_split++; |
| 823 | |
| 824 | e1000_receive_skb(adapter, netdev, skb, |
| 825 | staterr, rx_desc->wb.middle.vlan); |
| 826 | |
| 827 | next_desc: |
| 828 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
| 829 | buffer_info->skb = NULL; |
| 830 | |
| 831 | /* return some buffers to hardware, one at a time is too slow */ |
| 832 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
| 833 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 834 | cleaned_count = 0; |
| 835 | } |
| 836 | |
| 837 | /* use prefetched values */ |
| 838 | rx_desc = next_rxd; |
| 839 | buffer_info = next_buffer; |
| 840 | |
| 841 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 842 | } |
| 843 | rx_ring->next_to_clean = i; |
| 844 | |
| 845 | cleaned_count = e1000_desc_unused(rx_ring); |
| 846 | if (cleaned_count) |
| 847 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 848 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 849 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 850 | adapter->total_rx_packets += total_rx_packets; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 851 | netdev->stats.rx_bytes += total_rx_bytes; |
| 852 | netdev->stats.rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 853 | return cleaned; |
| 854 | } |
| 855 | |
| 856 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 857 | * e1000_consume_page - helper function |
| 858 | **/ |
| 859 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
| 860 | u16 length) |
| 861 | { |
| 862 | bi->page = NULL; |
| 863 | skb->len += length; |
| 864 | skb->data_len += length; |
| 865 | skb->truesize += length; |
| 866 | } |
| 867 | |
| 868 | /** |
| 869 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 870 | * @adapter: board private structure |
| 871 | * |
| 872 | * the return value indicates whether actual cleaning was done, there |
| 873 | * is no guarantee that everything was cleaned |
| 874 | **/ |
| 875 | |
| 876 | static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, |
| 877 | int *work_done, int work_to_do) |
| 878 | { |
| 879 | struct net_device *netdev = adapter->netdev; |
| 880 | struct pci_dev *pdev = adapter->pdev; |
| 881 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 882 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 883 | struct e1000_buffer *buffer_info, *next_buffer; |
| 884 | u32 length; |
| 885 | unsigned int i; |
| 886 | int cleaned_count = 0; |
| 887 | bool cleaned = false; |
| 888 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
| 889 | |
| 890 | i = rx_ring->next_to_clean; |
| 891 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 892 | buffer_info = &rx_ring->buffer_info[i]; |
| 893 | |
| 894 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
| 895 | struct sk_buff *skb; |
| 896 | u8 status; |
| 897 | |
| 898 | if (*work_done >= work_to_do) |
| 899 | break; |
| 900 | (*work_done)++; |
| 901 | |
| 902 | status = rx_desc->status; |
| 903 | skb = buffer_info->skb; |
| 904 | buffer_info->skb = NULL; |
| 905 | |
| 906 | ++i; |
| 907 | if (i == rx_ring->count) |
| 908 | i = 0; |
| 909 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
| 910 | prefetch(next_rxd); |
| 911 | |
| 912 | next_buffer = &rx_ring->buffer_info[i]; |
| 913 | |
| 914 | cleaned = true; |
| 915 | cleaned_count++; |
| 916 | pci_unmap_page(pdev, buffer_info->dma, PAGE_SIZE, |
| 917 | PCI_DMA_FROMDEVICE); |
| 918 | buffer_info->dma = 0; |
| 919 | |
| 920 | length = le16_to_cpu(rx_desc->length); |
| 921 | |
| 922 | /* errors is only valid for DD + EOP descriptors */ |
| 923 | if (unlikely((status & E1000_RXD_STAT_EOP) && |
| 924 | (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) { |
| 925 | /* recycle both page and skb */ |
| 926 | buffer_info->skb = skb; |
| 927 | /* an error means any chain goes out the window |
| 928 | * too */ |
| 929 | if (rx_ring->rx_skb_top) |
| 930 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 931 | rx_ring->rx_skb_top = NULL; |
| 932 | goto next_desc; |
| 933 | } |
| 934 | |
| 935 | #define rxtop rx_ring->rx_skb_top |
| 936 | if (!(status & E1000_RXD_STAT_EOP)) { |
| 937 | /* this descriptor is only the beginning (or middle) */ |
| 938 | if (!rxtop) { |
| 939 | /* this is the beginning of a chain */ |
| 940 | rxtop = skb; |
| 941 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
| 942 | 0, length); |
| 943 | } else { |
| 944 | /* this is the middle of a chain */ |
| 945 | skb_fill_page_desc(rxtop, |
| 946 | skb_shinfo(rxtop)->nr_frags, |
| 947 | buffer_info->page, 0, length); |
| 948 | /* re-use the skb, only consumed the page */ |
| 949 | buffer_info->skb = skb; |
| 950 | } |
| 951 | e1000_consume_page(buffer_info, rxtop, length); |
| 952 | goto next_desc; |
| 953 | } else { |
| 954 | if (rxtop) { |
| 955 | /* end of the chain */ |
| 956 | skb_fill_page_desc(rxtop, |
| 957 | skb_shinfo(rxtop)->nr_frags, |
| 958 | buffer_info->page, 0, length); |
| 959 | /* re-use the current skb, we only consumed the |
| 960 | * page */ |
| 961 | buffer_info->skb = skb; |
| 962 | skb = rxtop; |
| 963 | rxtop = NULL; |
| 964 | e1000_consume_page(buffer_info, skb, length); |
| 965 | } else { |
| 966 | /* no chain, got EOP, this buf is the packet |
| 967 | * copybreak to save the put_page/alloc_page */ |
| 968 | if (length <= copybreak && |
| 969 | skb_tailroom(skb) >= length) { |
| 970 | u8 *vaddr; |
| 971 | vaddr = kmap_atomic(buffer_info->page, |
| 972 | KM_SKB_DATA_SOFTIRQ); |
| 973 | memcpy(skb_tail_pointer(skb), vaddr, |
| 974 | length); |
| 975 | kunmap_atomic(vaddr, |
| 976 | KM_SKB_DATA_SOFTIRQ); |
| 977 | /* re-use the page, so don't erase |
| 978 | * buffer_info->page */ |
| 979 | skb_put(skb, length); |
| 980 | } else { |
| 981 | skb_fill_page_desc(skb, 0, |
| 982 | buffer_info->page, 0, |
| 983 | length); |
| 984 | e1000_consume_page(buffer_info, skb, |
| 985 | length); |
| 986 | } |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | /* Receive Checksum Offload XXX recompute due to CRC strip? */ |
| 991 | e1000_rx_checksum(adapter, |
| 992 | (u32)(status) | |
| 993 | ((u32)(rx_desc->errors) << 24), |
| 994 | le16_to_cpu(rx_desc->csum), skb); |
| 995 | |
| 996 | /* probably a little skewed due to removing CRC */ |
| 997 | total_rx_bytes += skb->len; |
| 998 | total_rx_packets++; |
| 999 | |
| 1000 | /* eth type trans needs skb->data to point to something */ |
| 1001 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1002 | e_err("pskb_may_pull failed.\n"); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1003 | dev_kfree_skb(skb); |
| 1004 | goto next_desc; |
| 1005 | } |
| 1006 | |
| 1007 | e1000_receive_skb(adapter, netdev, skb, status, |
| 1008 | rx_desc->special); |
| 1009 | |
| 1010 | next_desc: |
| 1011 | rx_desc->status = 0; |
| 1012 | |
| 1013 | /* return some buffers to hardware, one at a time is too slow */ |
| 1014 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 1015 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 1016 | cleaned_count = 0; |
| 1017 | } |
| 1018 | |
| 1019 | /* use prefetched values */ |
| 1020 | rx_desc = next_rxd; |
| 1021 | buffer_info = next_buffer; |
| 1022 | } |
| 1023 | rx_ring->next_to_clean = i; |
| 1024 | |
| 1025 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1026 | if (cleaned_count) |
| 1027 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 1028 | |
| 1029 | adapter->total_rx_bytes += total_rx_bytes; |
| 1030 | adapter->total_rx_packets += total_rx_packets; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 1031 | netdev->stats.rx_bytes += total_rx_bytes; |
| 1032 | netdev->stats.rx_packets += total_rx_packets; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1033 | return cleaned; |
| 1034 | } |
| 1035 | |
| 1036 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1037 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 1038 | * @adapter: board private structure |
| 1039 | **/ |
| 1040 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter) |
| 1041 | { |
| 1042 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1043 | struct e1000_buffer *buffer_info; |
| 1044 | struct e1000_ps_page *ps_page; |
| 1045 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1046 | unsigned int i, j; |
| 1047 | |
| 1048 | /* Free all the Rx ring sk_buffs */ |
| 1049 | for (i = 0; i < rx_ring->count; i++) { |
| 1050 | buffer_info = &rx_ring->buffer_info[i]; |
| 1051 | if (buffer_info->dma) { |
| 1052 | if (adapter->clean_rx == e1000_clean_rx_irq) |
| 1053 | pci_unmap_single(pdev, buffer_info->dma, |
| 1054 | adapter->rx_buffer_len, |
| 1055 | PCI_DMA_FROMDEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1056 | else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) |
| 1057 | pci_unmap_page(pdev, buffer_info->dma, |
| 1058 | PAGE_SIZE, |
| 1059 | PCI_DMA_FROMDEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1060 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
| 1061 | pci_unmap_single(pdev, buffer_info->dma, |
| 1062 | adapter->rx_ps_bsize0, |
| 1063 | PCI_DMA_FROMDEVICE); |
| 1064 | buffer_info->dma = 0; |
| 1065 | } |
| 1066 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1067 | if (buffer_info->page) { |
| 1068 | put_page(buffer_info->page); |
| 1069 | buffer_info->page = NULL; |
| 1070 | } |
| 1071 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1072 | if (buffer_info->skb) { |
| 1073 | dev_kfree_skb(buffer_info->skb); |
| 1074 | buffer_info->skb = NULL; |
| 1075 | } |
| 1076 | |
| 1077 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1078 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1079 | if (!ps_page->page) |
| 1080 | break; |
| 1081 | pci_unmap_page(pdev, ps_page->dma, PAGE_SIZE, |
| 1082 | PCI_DMA_FROMDEVICE); |
| 1083 | ps_page->dma = 0; |
| 1084 | put_page(ps_page->page); |
| 1085 | ps_page->page = NULL; |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | /* there also may be some cached data from a chained receive */ |
| 1090 | if (rx_ring->rx_skb_top) { |
| 1091 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 1092 | rx_ring->rx_skb_top = NULL; |
| 1093 | } |
| 1094 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1095 | /* Zero out the descriptor ring */ |
| 1096 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1097 | |
| 1098 | rx_ring->next_to_clean = 0; |
| 1099 | rx_ring->next_to_use = 0; |
| 1100 | |
| 1101 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 1102 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
| 1103 | } |
| 1104 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1105 | static void e1000e_downshift_workaround(struct work_struct *work) |
| 1106 | { |
| 1107 | struct e1000_adapter *adapter = container_of(work, |
| 1108 | struct e1000_adapter, downshift_task); |
| 1109 | |
| 1110 | e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); |
| 1111 | } |
| 1112 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1113 | /** |
| 1114 | * e1000_intr_msi - Interrupt Handler |
| 1115 | * @irq: interrupt number |
| 1116 | * @data: pointer to a network interface device structure |
| 1117 | **/ |
| 1118 | static irqreturn_t e1000_intr_msi(int irq, void *data) |
| 1119 | { |
| 1120 | struct net_device *netdev = data; |
| 1121 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1122 | struct e1000_hw *hw = &adapter->hw; |
| 1123 | u32 icr = er32(ICR); |
| 1124 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1125 | /* |
| 1126 | * read ICR disables interrupts using IAM |
| 1127 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1128 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1129 | if (icr & E1000_ICR_LSC) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1130 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1131 | /* |
| 1132 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1133 | * disconnect (LSC) before accessing any PHY registers |
| 1134 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1135 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1136 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1137 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1138 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1139 | /* |
| 1140 | * 80003ES2LAN workaround-- For packet buffer work-around on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1141 | * link down event; disable receives here in the ISR and reset |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1142 | * adapter in watchdog |
| 1143 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1144 | if (netif_carrier_ok(netdev) && |
| 1145 | adapter->flags & FLAG_RX_NEEDS_RESTART) { |
| 1146 | /* disable receives */ |
| 1147 | u32 rctl = er32(RCTL); |
| 1148 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1149 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1150 | } |
| 1151 | /* guard against interrupt when we're going down */ |
| 1152 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1153 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1154 | } |
| 1155 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1156 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1157 | adapter->total_tx_bytes = 0; |
| 1158 | adapter->total_tx_packets = 0; |
| 1159 | adapter->total_rx_bytes = 0; |
| 1160 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1161 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | return IRQ_HANDLED; |
| 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * e1000_intr - Interrupt Handler |
| 1169 | * @irq: interrupt number |
| 1170 | * @data: pointer to a network interface device structure |
| 1171 | **/ |
| 1172 | static irqreturn_t e1000_intr(int irq, void *data) |
| 1173 | { |
| 1174 | struct net_device *netdev = data; |
| 1175 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1176 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1177 | u32 rctl, icr = er32(ICR); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1178 | |
Bruce Allan | a68ea77 | 2009-11-20 23:23:16 +0000 | [diff] [blame] | 1179 | if (!icr || test_bit(__E1000_DOWN, &adapter->state)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1180 | return IRQ_NONE; /* Not our interrupt */ |
| 1181 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1182 | /* |
| 1183 | * IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 1184 | * not set, then the adapter didn't send an interrupt |
| 1185 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1186 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 1187 | return IRQ_NONE; |
| 1188 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1189 | /* |
| 1190 | * Interrupt Auto-Mask...upon reading ICR, |
| 1191 | * interrupts are masked. No need for the |
| 1192 | * IMC write |
| 1193 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1194 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1195 | if (icr & E1000_ICR_LSC) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1196 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1197 | /* |
| 1198 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1199 | * disconnect (LSC) before accessing any PHY registers |
| 1200 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1201 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1202 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1203 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1204 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1205 | /* |
| 1206 | * 80003ES2LAN workaround-- |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1207 | * For packet buffer work-around on link down event; |
| 1208 | * disable receives here in the ISR and |
| 1209 | * reset adapter in watchdog |
| 1210 | */ |
| 1211 | if (netif_carrier_ok(netdev) && |
| 1212 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { |
| 1213 | /* disable receives */ |
| 1214 | rctl = er32(RCTL); |
| 1215 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1216 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1217 | } |
| 1218 | /* guard against interrupt when we're going down */ |
| 1219 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1220 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1221 | } |
| 1222 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1223 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1224 | adapter->total_tx_bytes = 0; |
| 1225 | adapter->total_tx_packets = 0; |
| 1226 | adapter->total_rx_bytes = 0; |
| 1227 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1228 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | return IRQ_HANDLED; |
| 1232 | } |
| 1233 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1234 | static irqreturn_t e1000_msix_other(int irq, void *data) |
| 1235 | { |
| 1236 | struct net_device *netdev = data; |
| 1237 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1238 | struct e1000_hw *hw = &adapter->hw; |
| 1239 | u32 icr = er32(ICR); |
| 1240 | |
| 1241 | if (!(icr & E1000_ICR_INT_ASSERTED)) { |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1242 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1243 | ew32(IMS, E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1244 | return IRQ_NONE; |
| 1245 | } |
| 1246 | |
| 1247 | if (icr & adapter->eiac_mask) |
| 1248 | ew32(ICS, (icr & adapter->eiac_mask)); |
| 1249 | |
| 1250 | if (icr & E1000_ICR_OTHER) { |
| 1251 | if (!(icr & E1000_ICR_LSC)) |
| 1252 | goto no_link_interrupt; |
| 1253 | hw->mac.get_link_status = 1; |
| 1254 | /* guard against interrupt when we're going down */ |
| 1255 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1256 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1257 | } |
| 1258 | |
| 1259 | no_link_interrupt: |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1260 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1261 | ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1262 | |
| 1263 | return IRQ_HANDLED; |
| 1264 | } |
| 1265 | |
| 1266 | |
| 1267 | static irqreturn_t e1000_intr_msix_tx(int irq, void *data) |
| 1268 | { |
| 1269 | struct net_device *netdev = data; |
| 1270 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1271 | struct e1000_hw *hw = &adapter->hw; |
| 1272 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1273 | |
| 1274 | |
| 1275 | adapter->total_tx_bytes = 0; |
| 1276 | adapter->total_tx_packets = 0; |
| 1277 | |
| 1278 | if (!e1000_clean_tx_irq(adapter)) |
| 1279 | /* Ring was not completely cleaned, so fire another interrupt */ |
| 1280 | ew32(ICS, tx_ring->ims_val); |
| 1281 | |
| 1282 | return IRQ_HANDLED; |
| 1283 | } |
| 1284 | |
| 1285 | static irqreturn_t e1000_intr_msix_rx(int irq, void *data) |
| 1286 | { |
| 1287 | struct net_device *netdev = data; |
| 1288 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1289 | |
| 1290 | /* Write the ITR value calculated at the end of the |
| 1291 | * previous interrupt. |
| 1292 | */ |
| 1293 | if (adapter->rx_ring->set_itr) { |
| 1294 | writel(1000000000 / (adapter->rx_ring->itr_val * 256), |
| 1295 | adapter->hw.hw_addr + adapter->rx_ring->itr_register); |
| 1296 | adapter->rx_ring->set_itr = 0; |
| 1297 | } |
| 1298 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1299 | if (napi_schedule_prep(&adapter->napi)) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1300 | adapter->total_rx_bytes = 0; |
| 1301 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1302 | __napi_schedule(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1303 | } |
| 1304 | return IRQ_HANDLED; |
| 1305 | } |
| 1306 | |
| 1307 | /** |
| 1308 | * e1000_configure_msix - Configure MSI-X hardware |
| 1309 | * |
| 1310 | * e1000_configure_msix sets up the hardware to properly |
| 1311 | * generate MSI-X interrupts. |
| 1312 | **/ |
| 1313 | static void e1000_configure_msix(struct e1000_adapter *adapter) |
| 1314 | { |
| 1315 | struct e1000_hw *hw = &adapter->hw; |
| 1316 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1317 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1318 | int vector = 0; |
| 1319 | u32 ctrl_ext, ivar = 0; |
| 1320 | |
| 1321 | adapter->eiac_mask = 0; |
| 1322 | |
| 1323 | /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ |
| 1324 | if (hw->mac.type == e1000_82574) { |
| 1325 | u32 rfctl = er32(RFCTL); |
| 1326 | rfctl |= E1000_RFCTL_ACK_DIS; |
| 1327 | ew32(RFCTL, rfctl); |
| 1328 | } |
| 1329 | |
| 1330 | #define E1000_IVAR_INT_ALLOC_VALID 0x8 |
| 1331 | /* Configure Rx vector */ |
| 1332 | rx_ring->ims_val = E1000_IMS_RXQ0; |
| 1333 | adapter->eiac_mask |= rx_ring->ims_val; |
| 1334 | if (rx_ring->itr_val) |
| 1335 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1336 | hw->hw_addr + rx_ring->itr_register); |
| 1337 | else |
| 1338 | writel(1, hw->hw_addr + rx_ring->itr_register); |
| 1339 | ivar = E1000_IVAR_INT_ALLOC_VALID | vector; |
| 1340 | |
| 1341 | /* Configure Tx vector */ |
| 1342 | tx_ring->ims_val = E1000_IMS_TXQ0; |
| 1343 | vector++; |
| 1344 | if (tx_ring->itr_val) |
| 1345 | writel(1000000000 / (tx_ring->itr_val * 256), |
| 1346 | hw->hw_addr + tx_ring->itr_register); |
| 1347 | else |
| 1348 | writel(1, hw->hw_addr + tx_ring->itr_register); |
| 1349 | adapter->eiac_mask |= tx_ring->ims_val; |
| 1350 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); |
| 1351 | |
| 1352 | /* set vector for Other Causes, e.g. link changes */ |
| 1353 | vector++; |
| 1354 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); |
| 1355 | if (rx_ring->itr_val) |
| 1356 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1357 | hw->hw_addr + E1000_EITR_82574(vector)); |
| 1358 | else |
| 1359 | writel(1, hw->hw_addr + E1000_EITR_82574(vector)); |
| 1360 | |
| 1361 | /* Cause Tx interrupts on every write back */ |
| 1362 | ivar |= (1 << 31); |
| 1363 | |
| 1364 | ew32(IVAR, ivar); |
| 1365 | |
| 1366 | /* enable MSI-X PBA support */ |
| 1367 | ctrl_ext = er32(CTRL_EXT); |
| 1368 | ctrl_ext |= E1000_CTRL_EXT_PBA_CLR; |
| 1369 | |
| 1370 | /* Auto-Mask Other interrupts upon ICR read */ |
| 1371 | #define E1000_EIAC_MASK_82574 0x01F00000 |
| 1372 | ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER); |
| 1373 | ctrl_ext |= E1000_CTRL_EXT_EIAME; |
| 1374 | ew32(CTRL_EXT, ctrl_ext); |
| 1375 | e1e_flush(); |
| 1376 | } |
| 1377 | |
| 1378 | void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) |
| 1379 | { |
| 1380 | if (adapter->msix_entries) { |
| 1381 | pci_disable_msix(adapter->pdev); |
| 1382 | kfree(adapter->msix_entries); |
| 1383 | adapter->msix_entries = NULL; |
| 1384 | } else if (adapter->flags & FLAG_MSI_ENABLED) { |
| 1385 | pci_disable_msi(adapter->pdev); |
| 1386 | adapter->flags &= ~FLAG_MSI_ENABLED; |
| 1387 | } |
| 1388 | |
| 1389 | return; |
| 1390 | } |
| 1391 | |
| 1392 | /** |
| 1393 | * e1000e_set_interrupt_capability - set MSI or MSI-X if supported |
| 1394 | * |
| 1395 | * Attempt to configure interrupts using the best available |
| 1396 | * capabilities of the hardware and kernel. |
| 1397 | **/ |
| 1398 | void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) |
| 1399 | { |
| 1400 | int err; |
| 1401 | int numvecs, i; |
| 1402 | |
| 1403 | |
| 1404 | switch (adapter->int_mode) { |
| 1405 | case E1000E_INT_MODE_MSIX: |
| 1406 | if (adapter->flags & FLAG_HAS_MSIX) { |
| 1407 | numvecs = 3; /* RxQ0, TxQ0 and other */ |
| 1408 | adapter->msix_entries = kcalloc(numvecs, |
| 1409 | sizeof(struct msix_entry), |
| 1410 | GFP_KERNEL); |
| 1411 | if (adapter->msix_entries) { |
| 1412 | for (i = 0; i < numvecs; i++) |
| 1413 | adapter->msix_entries[i].entry = i; |
| 1414 | |
| 1415 | err = pci_enable_msix(adapter->pdev, |
| 1416 | adapter->msix_entries, |
| 1417 | numvecs); |
| 1418 | if (err == 0) |
| 1419 | return; |
| 1420 | } |
| 1421 | /* MSI-X failed, so fall through and try MSI */ |
| 1422 | e_err("Failed to initialize MSI-X interrupts. " |
| 1423 | "Falling back to MSI interrupts.\n"); |
| 1424 | e1000e_reset_interrupt_capability(adapter); |
| 1425 | } |
| 1426 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 1427 | /* Fall through */ |
| 1428 | case E1000E_INT_MODE_MSI: |
| 1429 | if (!pci_enable_msi(adapter->pdev)) { |
| 1430 | adapter->flags |= FLAG_MSI_ENABLED; |
| 1431 | } else { |
| 1432 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
| 1433 | e_err("Failed to initialize MSI interrupts. Falling " |
| 1434 | "back to legacy interrupts.\n"); |
| 1435 | } |
| 1436 | /* Fall through */ |
| 1437 | case E1000E_INT_MODE_LEGACY: |
| 1438 | /* Don't do anything; this is the system default */ |
| 1439 | break; |
| 1440 | } |
| 1441 | |
| 1442 | return; |
| 1443 | } |
| 1444 | |
| 1445 | /** |
| 1446 | * e1000_request_msix - Initialize MSI-X interrupts |
| 1447 | * |
| 1448 | * e1000_request_msix allocates MSI-X vectors and requests interrupts from the |
| 1449 | * kernel. |
| 1450 | **/ |
| 1451 | static int e1000_request_msix(struct e1000_adapter *adapter) |
| 1452 | { |
| 1453 | struct net_device *netdev = adapter->netdev; |
| 1454 | int err = 0, vector = 0; |
| 1455 | |
| 1456 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Alexander Duyck | cb7b48f | 2008-12-05 15:08:03 -0800 | [diff] [blame] | 1457 | sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1458 | else |
| 1459 | memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); |
| 1460 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1461 | e1000_intr_msix_rx, 0, adapter->rx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1462 | netdev); |
| 1463 | if (err) |
| 1464 | goto out; |
| 1465 | adapter->rx_ring->itr_register = E1000_EITR_82574(vector); |
| 1466 | adapter->rx_ring->itr_val = adapter->itr; |
| 1467 | vector++; |
| 1468 | |
| 1469 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Alexander Duyck | cb7b48f | 2008-12-05 15:08:03 -0800 | [diff] [blame] | 1470 | sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1471 | else |
| 1472 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); |
| 1473 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1474 | e1000_intr_msix_tx, 0, adapter->tx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1475 | netdev); |
| 1476 | if (err) |
| 1477 | goto out; |
| 1478 | adapter->tx_ring->itr_register = E1000_EITR_82574(vector); |
| 1479 | adapter->tx_ring->itr_val = adapter->itr; |
| 1480 | vector++; |
| 1481 | |
| 1482 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1483 | e1000_msix_other, 0, netdev->name, netdev); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1484 | if (err) |
| 1485 | goto out; |
| 1486 | |
| 1487 | e1000_configure_msix(adapter); |
| 1488 | return 0; |
| 1489 | out: |
| 1490 | return err; |
| 1491 | } |
| 1492 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 1493 | /** |
| 1494 | * e1000_request_irq - initialize interrupts |
| 1495 | * |
| 1496 | * Attempts to configure interrupts using the best available |
| 1497 | * capabilities of the hardware and kernel. |
| 1498 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1499 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 1500 | { |
| 1501 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1502 | int err; |
| 1503 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1504 | if (adapter->msix_entries) { |
| 1505 | err = e1000_request_msix(adapter); |
| 1506 | if (!err) |
| 1507 | return err; |
| 1508 | /* fall back to MSI */ |
| 1509 | e1000e_reset_interrupt_capability(adapter); |
| 1510 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 1511 | e1000e_set_interrupt_capability(adapter); |
| 1512 | } |
| 1513 | if (adapter->flags & FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1514 | err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1515 | netdev->name, netdev); |
| 1516 | if (!err) |
| 1517 | return err; |
| 1518 | |
| 1519 | /* fall back to legacy interrupt */ |
| 1520 | e1000e_reset_interrupt_capability(adapter); |
| 1521 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1524 | err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1525 | netdev->name, netdev); |
| 1526 | if (err) |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 1527 | e_err("Unable to allocate interrupt, Error: %d\n", err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1528 | |
| 1529 | return err; |
| 1530 | } |
| 1531 | |
| 1532 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 1533 | { |
| 1534 | struct net_device *netdev = adapter->netdev; |
| 1535 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1536 | if (adapter->msix_entries) { |
| 1537 | int vector = 0; |
| 1538 | |
| 1539 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 1540 | vector++; |
| 1541 | |
| 1542 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 1543 | vector++; |
| 1544 | |
| 1545 | /* Other Causes interrupt vector */ |
| 1546 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 1547 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1548 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1549 | |
| 1550 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | /** |
| 1554 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 1555 | **/ |
| 1556 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
| 1557 | { |
| 1558 | struct e1000_hw *hw = &adapter->hw; |
| 1559 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1560 | ew32(IMC, ~0); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1561 | if (adapter->msix_entries) |
| 1562 | ew32(EIAC_82574, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1563 | e1e_flush(); |
| 1564 | synchronize_irq(adapter->pdev->irq); |
| 1565 | } |
| 1566 | |
| 1567 | /** |
| 1568 | * e1000_irq_enable - Enable default interrupt generation settings |
| 1569 | **/ |
| 1570 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
| 1571 | { |
| 1572 | struct e1000_hw *hw = &adapter->hw; |
| 1573 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1574 | if (adapter->msix_entries) { |
| 1575 | ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); |
| 1576 | ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC); |
| 1577 | } else { |
| 1578 | ew32(IMS, IMS_ENABLE_MASK); |
| 1579 | } |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 1580 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | /** |
| 1584 | * e1000_get_hw_control - get control of the h/w from f/w |
| 1585 | * @adapter: address of board private structure |
| 1586 | * |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 1587 | * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1588 | * For ASF and Pass Through versions of f/w this means that |
| 1589 | * the driver is loaded. For AMT version (only with 82573) |
| 1590 | * of the f/w this means that the network i/f is open. |
| 1591 | **/ |
| 1592 | static void e1000_get_hw_control(struct e1000_adapter *adapter) |
| 1593 | { |
| 1594 | struct e1000_hw *hw = &adapter->hw; |
| 1595 | u32 ctrl_ext; |
| 1596 | u32 swsm; |
| 1597 | |
| 1598 | /* Let firmware know the driver has taken over */ |
| 1599 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 1600 | swsm = er32(SWSM); |
| 1601 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
| 1602 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 1603 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1604 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | /** |
| 1609 | * e1000_release_hw_control - release control of the h/w to f/w |
| 1610 | * @adapter: address of board private structure |
| 1611 | * |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 1612 | * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1613 | * For ASF and Pass Through versions of f/w this means that the |
| 1614 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 1615 | * of the f/w this means that the network i/f is closed. |
| 1616 | * |
| 1617 | **/ |
| 1618 | static void e1000_release_hw_control(struct e1000_adapter *adapter) |
| 1619 | { |
| 1620 | struct e1000_hw *hw = &adapter->hw; |
| 1621 | u32 ctrl_ext; |
| 1622 | u32 swsm; |
| 1623 | |
| 1624 | /* Let firmware taken over control of h/w */ |
| 1625 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 1626 | swsm = er32(SWSM); |
| 1627 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
| 1628 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 1629 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1630 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1631 | } |
| 1632 | } |
| 1633 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1634 | /** |
| 1635 | * @e1000_alloc_ring - allocate memory for a ring structure |
| 1636 | **/ |
| 1637 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, |
| 1638 | struct e1000_ring *ring) |
| 1639 | { |
| 1640 | struct pci_dev *pdev = adapter->pdev; |
| 1641 | |
| 1642 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, |
| 1643 | GFP_KERNEL); |
| 1644 | if (!ring->desc) |
| 1645 | return -ENOMEM; |
| 1646 | |
| 1647 | return 0; |
| 1648 | } |
| 1649 | |
| 1650 | /** |
| 1651 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) |
| 1652 | * @adapter: board private structure |
| 1653 | * |
| 1654 | * Return 0 on success, negative on failure |
| 1655 | **/ |
| 1656 | int e1000e_setup_tx_resources(struct e1000_adapter *adapter) |
| 1657 | { |
| 1658 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1659 | int err = -ENOMEM, size; |
| 1660 | |
| 1661 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 1662 | tx_ring->buffer_info = vmalloc(size); |
| 1663 | if (!tx_ring->buffer_info) |
| 1664 | goto err; |
| 1665 | memset(tx_ring->buffer_info, 0, size); |
| 1666 | |
| 1667 | /* round up to nearest 4K */ |
| 1668 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
| 1669 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 1670 | |
| 1671 | err = e1000_alloc_ring_dma(adapter, tx_ring); |
| 1672 | if (err) |
| 1673 | goto err; |
| 1674 | |
| 1675 | tx_ring->next_to_use = 0; |
| 1676 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1677 | |
| 1678 | return 0; |
| 1679 | err: |
| 1680 | vfree(tx_ring->buffer_info); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1681 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1682 | return err; |
| 1683 | } |
| 1684 | |
| 1685 | /** |
| 1686 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) |
| 1687 | * @adapter: board private structure |
| 1688 | * |
| 1689 | * Returns 0 on success, negative on failure |
| 1690 | **/ |
| 1691 | int e1000e_setup_rx_resources(struct e1000_adapter *adapter) |
| 1692 | { |
| 1693 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1694 | struct e1000_buffer *buffer_info; |
| 1695 | int i, size, desc_len, err = -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1696 | |
| 1697 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
| 1698 | rx_ring->buffer_info = vmalloc(size); |
| 1699 | if (!rx_ring->buffer_info) |
| 1700 | goto err; |
| 1701 | memset(rx_ring->buffer_info, 0, size); |
| 1702 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1703 | for (i = 0; i < rx_ring->count; i++) { |
| 1704 | buffer_info = &rx_ring->buffer_info[i]; |
| 1705 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, |
| 1706 | sizeof(struct e1000_ps_page), |
| 1707 | GFP_KERNEL); |
| 1708 | if (!buffer_info->ps_pages) |
| 1709 | goto err_pages; |
| 1710 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1711 | |
| 1712 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 1713 | |
| 1714 | /* Round up to nearest 4K */ |
| 1715 | rx_ring->size = rx_ring->count * desc_len; |
| 1716 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 1717 | |
| 1718 | err = e1000_alloc_ring_dma(adapter, rx_ring); |
| 1719 | if (err) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1720 | goto err_pages; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1721 | |
| 1722 | rx_ring->next_to_clean = 0; |
| 1723 | rx_ring->next_to_use = 0; |
| 1724 | rx_ring->rx_skb_top = NULL; |
| 1725 | |
| 1726 | return 0; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1727 | |
| 1728 | err_pages: |
| 1729 | for (i = 0; i < rx_ring->count; i++) { |
| 1730 | buffer_info = &rx_ring->buffer_info[i]; |
| 1731 | kfree(buffer_info->ps_pages); |
| 1732 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1733 | err: |
| 1734 | vfree(rx_ring->buffer_info); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1735 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1736 | return err; |
| 1737 | } |
| 1738 | |
| 1739 | /** |
| 1740 | * e1000_clean_tx_ring - Free Tx Buffers |
| 1741 | * @adapter: board private structure |
| 1742 | **/ |
| 1743 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter) |
| 1744 | { |
| 1745 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1746 | struct e1000_buffer *buffer_info; |
| 1747 | unsigned long size; |
| 1748 | unsigned int i; |
| 1749 | |
| 1750 | for (i = 0; i < tx_ring->count; i++) { |
| 1751 | buffer_info = &tx_ring->buffer_info[i]; |
| 1752 | e1000_put_txbuf(adapter, buffer_info); |
| 1753 | } |
| 1754 | |
| 1755 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 1756 | memset(tx_ring->buffer_info, 0, size); |
| 1757 | |
| 1758 | memset(tx_ring->desc, 0, tx_ring->size); |
| 1759 | |
| 1760 | tx_ring->next_to_use = 0; |
| 1761 | tx_ring->next_to_clean = 0; |
| 1762 | |
| 1763 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 1764 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
| 1765 | } |
| 1766 | |
| 1767 | /** |
| 1768 | * e1000e_free_tx_resources - Free Tx Resources per Queue |
| 1769 | * @adapter: board private structure |
| 1770 | * |
| 1771 | * Free all transmit software resources |
| 1772 | **/ |
| 1773 | void e1000e_free_tx_resources(struct e1000_adapter *adapter) |
| 1774 | { |
| 1775 | struct pci_dev *pdev = adapter->pdev; |
| 1776 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1777 | |
| 1778 | e1000_clean_tx_ring(adapter); |
| 1779 | |
| 1780 | vfree(tx_ring->buffer_info); |
| 1781 | tx_ring->buffer_info = NULL; |
| 1782 | |
| 1783 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 1784 | tx_ring->dma); |
| 1785 | tx_ring->desc = NULL; |
| 1786 | } |
| 1787 | |
| 1788 | /** |
| 1789 | * e1000e_free_rx_resources - Free Rx Resources |
| 1790 | * @adapter: board private structure |
| 1791 | * |
| 1792 | * Free all receive software resources |
| 1793 | **/ |
| 1794 | |
| 1795 | void e1000e_free_rx_resources(struct e1000_adapter *adapter) |
| 1796 | { |
| 1797 | struct pci_dev *pdev = adapter->pdev; |
| 1798 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1799 | int i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1800 | |
| 1801 | e1000_clean_rx_ring(adapter); |
| 1802 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1803 | for (i = 0; i < rx_ring->count; i++) { |
| 1804 | kfree(rx_ring->buffer_info[i].ps_pages); |
| 1805 | } |
| 1806 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1807 | vfree(rx_ring->buffer_info); |
| 1808 | rx_ring->buffer_info = NULL; |
| 1809 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1810 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 1811 | rx_ring->dma); |
| 1812 | rx_ring->desc = NULL; |
| 1813 | } |
| 1814 | |
| 1815 | /** |
| 1816 | * e1000_update_itr - update the dynamic ITR value based on statistics |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 1817 | * @adapter: pointer to adapter |
| 1818 | * @itr_setting: current adapter->itr |
| 1819 | * @packets: the number of packets during this measurement interval |
| 1820 | * @bytes: the number of bytes during this measurement interval |
| 1821 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1822 | * Stores a new ITR value based on packets and byte |
| 1823 | * counts during the last interrupt. The advantage of per interrupt |
| 1824 | * computation is faster updates and more accurate ITR for the current |
| 1825 | * traffic pattern. Constants in this function were computed |
| 1826 | * based on theoretical maximum wire speed and thresholds were set based |
| 1827 | * on testing data as well as attempting to minimize response time |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1828 | * while increasing bulk throughput. This functionality is controlled |
| 1829 | * by the InterruptThrottleRate module parameter. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1830 | **/ |
| 1831 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
| 1832 | u16 itr_setting, int packets, |
| 1833 | int bytes) |
| 1834 | { |
| 1835 | unsigned int retval = itr_setting; |
| 1836 | |
| 1837 | if (packets == 0) |
| 1838 | goto update_itr_done; |
| 1839 | |
| 1840 | switch (itr_setting) { |
| 1841 | case lowest_latency: |
| 1842 | /* handle TSO and jumbo frames */ |
| 1843 | if (bytes/packets > 8000) |
| 1844 | retval = bulk_latency; |
| 1845 | else if ((packets < 5) && (bytes > 512)) { |
| 1846 | retval = low_latency; |
| 1847 | } |
| 1848 | break; |
| 1849 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 1850 | if (bytes > 10000) { |
| 1851 | /* this if handles the TSO accounting */ |
| 1852 | if (bytes/packets > 8000) { |
| 1853 | retval = bulk_latency; |
| 1854 | } else if ((packets < 10) || ((bytes/packets) > 1200)) { |
| 1855 | retval = bulk_latency; |
| 1856 | } else if ((packets > 35)) { |
| 1857 | retval = lowest_latency; |
| 1858 | } |
| 1859 | } else if (bytes/packets > 2000) { |
| 1860 | retval = bulk_latency; |
| 1861 | } else if (packets <= 2 && bytes < 512) { |
| 1862 | retval = lowest_latency; |
| 1863 | } |
| 1864 | break; |
| 1865 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 1866 | if (bytes > 25000) { |
| 1867 | if (packets > 35) { |
| 1868 | retval = low_latency; |
| 1869 | } |
| 1870 | } else if (bytes < 6000) { |
| 1871 | retval = low_latency; |
| 1872 | } |
| 1873 | break; |
| 1874 | } |
| 1875 | |
| 1876 | update_itr_done: |
| 1877 | return retval; |
| 1878 | } |
| 1879 | |
| 1880 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 1881 | { |
| 1882 | struct e1000_hw *hw = &adapter->hw; |
| 1883 | u16 current_itr; |
| 1884 | u32 new_itr = adapter->itr; |
| 1885 | |
| 1886 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 1887 | if (adapter->link_speed != SPEED_1000) { |
| 1888 | current_itr = 0; |
| 1889 | new_itr = 4000; |
| 1890 | goto set_itr_now; |
| 1891 | } |
| 1892 | |
| 1893 | adapter->tx_itr = e1000_update_itr(adapter, |
| 1894 | adapter->tx_itr, |
| 1895 | adapter->total_tx_packets, |
| 1896 | adapter->total_tx_bytes); |
| 1897 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 1898 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 1899 | adapter->tx_itr = low_latency; |
| 1900 | |
| 1901 | adapter->rx_itr = e1000_update_itr(adapter, |
| 1902 | adapter->rx_itr, |
| 1903 | adapter->total_rx_packets, |
| 1904 | adapter->total_rx_bytes); |
| 1905 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 1906 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 1907 | adapter->rx_itr = low_latency; |
| 1908 | |
| 1909 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 1910 | |
| 1911 | switch (current_itr) { |
| 1912 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1913 | case lowest_latency: |
| 1914 | new_itr = 70000; |
| 1915 | break; |
| 1916 | case low_latency: |
| 1917 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1918 | break; |
| 1919 | case bulk_latency: |
| 1920 | new_itr = 4000; |
| 1921 | break; |
| 1922 | default: |
| 1923 | break; |
| 1924 | } |
| 1925 | |
| 1926 | set_itr_now: |
| 1927 | if (new_itr != adapter->itr) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1928 | /* |
| 1929 | * this attempts to bias the interrupt rate towards Bulk |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1930 | * by adding intermediate steps when interrupt rate is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1931 | * increasing |
| 1932 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1933 | new_itr = new_itr > adapter->itr ? |
| 1934 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 1935 | new_itr; |
| 1936 | adapter->itr = new_itr; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1937 | adapter->rx_ring->itr_val = new_itr; |
| 1938 | if (adapter->msix_entries) |
| 1939 | adapter->rx_ring->set_itr = 1; |
| 1940 | else |
| 1941 | ew32(ITR, 1000000000 / (new_itr * 256)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | /** |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1946 | * e1000_alloc_queues - Allocate memory for all rings |
| 1947 | * @adapter: board private structure to initialize |
| 1948 | **/ |
| 1949 | static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) |
| 1950 | { |
| 1951 | adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
| 1952 | if (!adapter->tx_ring) |
| 1953 | goto err; |
| 1954 | |
| 1955 | adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
| 1956 | if (!adapter->rx_ring) |
| 1957 | goto err; |
| 1958 | |
| 1959 | return 0; |
| 1960 | err: |
| 1961 | e_err("Unable to allocate memory for queues\n"); |
| 1962 | kfree(adapter->rx_ring); |
| 1963 | kfree(adapter->tx_ring); |
| 1964 | return -ENOMEM; |
| 1965 | } |
| 1966 | |
| 1967 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1968 | * e1000_clean - NAPI Rx polling callback |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1969 | * @napi: struct associated with this polling callback |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 1970 | * @budget: amount of packets driver is allowed to process this poll |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1971 | **/ |
| 1972 | static int e1000_clean(struct napi_struct *napi, int budget) |
| 1973 | { |
| 1974 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1975 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1976 | struct net_device *poll_dev = adapter->netdev; |
Andy Gospodarek | 679e8a0 | 2009-06-18 11:57:37 +0000 | [diff] [blame] | 1977 | int tx_cleaned = 1, work_done = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1978 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1979 | adapter = netdev_priv(poll_dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1980 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1981 | if (adapter->msix_entries && |
| 1982 | !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) |
| 1983 | goto clean_rx; |
| 1984 | |
Jesse Brandeburg | 92af3e9 | 2009-01-19 14:17:08 +0000 | [diff] [blame] | 1985 | tx_cleaned = e1000_clean_tx_irq(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1986 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1987 | clean_rx: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1988 | adapter->clean_rx(adapter, &work_done, budget); |
| 1989 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1990 | if (!tx_cleaned) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 1991 | work_done = budget; |
| 1992 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 1993 | /* If budget not fully consumed, exit the polling mode */ |
| 1994 | if (work_done < budget) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1995 | if (adapter->itr_setting & 3) |
| 1996 | e1000_set_itr(adapter); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1997 | napi_complete(napi); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1998 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 1999 | if (adapter->msix_entries) |
| 2000 | ew32(IMS, adapter->rx_ring->ims_val); |
| 2001 | else |
| 2002 | e1000_irq_enable(adapter); |
| 2003 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | return work_done; |
| 2007 | } |
| 2008 | |
| 2009 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2010 | { |
| 2011 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2012 | struct e1000_hw *hw = &adapter->hw; |
| 2013 | u32 vfta, index; |
| 2014 | |
| 2015 | /* don't update vlan cookie if already programmed */ |
| 2016 | if ((adapter->hw.mng_cookie.status & |
| 2017 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2018 | (vid == adapter->mng_vlan_id)) |
| 2019 | return; |
| 2020 | /* add VID to filter table */ |
| 2021 | index = (vid >> 5) & 0x7F; |
| 2022 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2023 | vfta |= (1 << (vid & 0x1F)); |
| 2024 | e1000e_write_vfta(hw, index, vfta); |
| 2025 | } |
| 2026 | |
| 2027 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2028 | { |
| 2029 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2030 | struct e1000_hw *hw = &adapter->hw; |
| 2031 | u32 vfta, index; |
| 2032 | |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 2033 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 2034 | e1000_irq_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2035 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 2036 | |
| 2037 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 2038 | e1000_irq_enable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2039 | |
| 2040 | if ((adapter->hw.mng_cookie.status & |
| 2041 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2042 | (vid == adapter->mng_vlan_id)) { |
| 2043 | /* release control to f/w */ |
| 2044 | e1000_release_hw_control(adapter); |
| 2045 | return; |
| 2046 | } |
| 2047 | |
| 2048 | /* remove VID from filter table */ |
| 2049 | index = (vid >> 5) & 0x7F; |
| 2050 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2051 | vfta &= ~(1 << (vid & 0x1F)); |
| 2052 | e1000e_write_vfta(hw, index, vfta); |
| 2053 | } |
| 2054 | |
| 2055 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 2056 | { |
| 2057 | struct net_device *netdev = adapter->netdev; |
| 2058 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 2059 | u16 old_vid = adapter->mng_vlan_id; |
| 2060 | |
| 2061 | if (!adapter->vlgrp) |
| 2062 | return; |
| 2063 | |
| 2064 | if (!vlan_group_get_device(adapter->vlgrp, vid)) { |
| 2065 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 2066 | if (adapter->hw.mng_cookie.status & |
| 2067 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
| 2068 | e1000_vlan_rx_add_vid(netdev, vid); |
| 2069 | adapter->mng_vlan_id = vid; |
| 2070 | } |
| 2071 | |
| 2072 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && |
| 2073 | (vid != old_vid) && |
| 2074 | !vlan_group_get_device(adapter->vlgrp, old_vid)) |
| 2075 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
| 2076 | } else { |
| 2077 | adapter->mng_vlan_id = vid; |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | |
| 2082 | static void e1000_vlan_rx_register(struct net_device *netdev, |
| 2083 | struct vlan_group *grp) |
| 2084 | { |
| 2085 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2086 | struct e1000_hw *hw = &adapter->hw; |
| 2087 | u32 ctrl, rctl; |
| 2088 | |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 2089 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 2090 | e1000_irq_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2091 | adapter->vlgrp = grp; |
| 2092 | |
| 2093 | if (grp) { |
| 2094 | /* enable VLAN tag insert/strip */ |
| 2095 | ctrl = er32(CTRL); |
| 2096 | ctrl |= E1000_CTRL_VME; |
| 2097 | ew32(CTRL, ctrl); |
| 2098 | |
| 2099 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2100 | /* enable VLAN receive filtering */ |
| 2101 | rctl = er32(RCTL); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2102 | rctl &= ~E1000_RCTL_CFIEN; |
| 2103 | ew32(RCTL, rctl); |
| 2104 | e1000_update_mng_vlan(adapter); |
| 2105 | } |
| 2106 | } else { |
| 2107 | /* disable VLAN tag insert/strip */ |
| 2108 | ctrl = er32(CTRL); |
| 2109 | ctrl &= ~E1000_CTRL_VME; |
| 2110 | ew32(CTRL, ctrl); |
| 2111 | |
| 2112 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2113 | if (adapter->mng_vlan_id != |
| 2114 | (u16)E1000_MNG_VLAN_NONE) { |
| 2115 | e1000_vlan_rx_kill_vid(netdev, |
| 2116 | adapter->mng_vlan_id); |
| 2117 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 2118 | } |
| 2119 | } |
| 2120 | } |
| 2121 | |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 2122 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 2123 | e1000_irq_enable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
| 2127 | { |
| 2128 | u16 vid; |
| 2129 | |
| 2130 | e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 2131 | |
| 2132 | if (!adapter->vlgrp) |
| 2133 | return; |
| 2134 | |
| 2135 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 2136 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 2137 | continue; |
| 2138 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | static void e1000_init_manageability(struct e1000_adapter *adapter) |
| 2143 | { |
| 2144 | struct e1000_hw *hw = &adapter->hw; |
| 2145 | u32 manc, manc2h; |
| 2146 | |
| 2147 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) |
| 2148 | return; |
| 2149 | |
| 2150 | manc = er32(MANC); |
| 2151 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2152 | /* |
| 2153 | * enable receiving management packets to the host. this will probably |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2154 | * generate destination unreachable messages from the host OS, but |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2155 | * the packets will be handled on SMBUS |
| 2156 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2157 | manc |= E1000_MANC_EN_MNG2HOST; |
| 2158 | manc2h = er32(MANC2H); |
| 2159 | #define E1000_MNG2HOST_PORT_623 (1 << 5) |
| 2160 | #define E1000_MNG2HOST_PORT_664 (1 << 6) |
| 2161 | manc2h |= E1000_MNG2HOST_PORT_623; |
| 2162 | manc2h |= E1000_MNG2HOST_PORT_664; |
| 2163 | ew32(MANC2H, manc2h); |
| 2164 | ew32(MANC, manc); |
| 2165 | } |
| 2166 | |
| 2167 | /** |
| 2168 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 2169 | * @adapter: board private structure |
| 2170 | * |
| 2171 | * Configure the Tx unit of the MAC after a reset. |
| 2172 | **/ |
| 2173 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
| 2174 | { |
| 2175 | struct e1000_hw *hw = &adapter->hw; |
| 2176 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2177 | u64 tdba; |
| 2178 | u32 tdlen, tctl, tipg, tarc; |
| 2179 | u32 ipgr1, ipgr2; |
| 2180 | |
| 2181 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 2182 | tdba = tx_ring->dma; |
| 2183 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2184 | ew32(TDBAL, (tdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2185 | ew32(TDBAH, (tdba >> 32)); |
| 2186 | ew32(TDLEN, tdlen); |
| 2187 | ew32(TDH, 0); |
| 2188 | ew32(TDT, 0); |
| 2189 | tx_ring->head = E1000_TDH; |
| 2190 | tx_ring->tail = E1000_TDT; |
| 2191 | |
| 2192 | /* Set the default values for the Tx Inter Packet Gap timer */ |
| 2193 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */ |
| 2194 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */ |
| 2195 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */ |
| 2196 | |
| 2197 | if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN) |
| 2198 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */ |
| 2199 | |
| 2200 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 2201 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
| 2202 | ew32(TIPG, tipg); |
| 2203 | |
| 2204 | /* Set the Tx Interrupt Delay register */ |
| 2205 | ew32(TIDV, adapter->tx_int_delay); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2206 | /* Tx irq moderation */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2207 | ew32(TADV, adapter->tx_abs_int_delay); |
| 2208 | |
| 2209 | /* Program the Transmit Control Register */ |
| 2210 | tctl = er32(TCTL); |
| 2211 | tctl &= ~E1000_TCTL_CT; |
| 2212 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
| 2213 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 2214 | |
| 2215 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2216 | tarc = er32(TARC(0)); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2217 | /* |
| 2218 | * set the speed mode bit, we'll clear it if we're not at |
| 2219 | * gigabit link later |
| 2220 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2221 | #define SPEED_MODE_BIT (1 << 21) |
| 2222 | tarc |= SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2223 | ew32(TARC(0), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | /* errata: program both queues to unweighted RR */ |
| 2227 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2228 | tarc = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2229 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2230 | ew32(TARC(0), tarc); |
| 2231 | tarc = er32(TARC(1)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2232 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2233 | ew32(TARC(1), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2236 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 2237 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 2238 | |
| 2239 | /* only set IDE if we are delaying interrupts using the timers */ |
| 2240 | if (adapter->tx_int_delay) |
| 2241 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
| 2242 | |
| 2243 | /* enable Report Status bit */ |
| 2244 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 2245 | |
| 2246 | ew32(TCTL, tctl); |
| 2247 | |
Simon Horman | edfea6e6 | 2009-06-08 14:28:36 +0000 | [diff] [blame] | 2248 | e1000e_config_collision_dist(hw); |
| 2249 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2250 | adapter->tx_queue_len = adapter->netdev->tx_queue_len; |
| 2251 | } |
| 2252 | |
| 2253 | /** |
| 2254 | * e1000_setup_rctl - configure the receive control registers |
| 2255 | * @adapter: Board private structure |
| 2256 | **/ |
| 2257 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 2258 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
| 2259 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
| 2260 | { |
| 2261 | struct e1000_hw *hw = &adapter->hw; |
| 2262 | u32 rctl, rfctl; |
| 2263 | u32 psrctl = 0; |
| 2264 | u32 pages = 0; |
| 2265 | |
| 2266 | /* Program MC offset vector base */ |
| 2267 | rctl = er32(RCTL); |
| 2268 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 2269 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 2270 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 2271 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 2272 | |
| 2273 | /* Do not Store bad packets */ |
| 2274 | rctl &= ~E1000_RCTL_SBP; |
| 2275 | |
| 2276 | /* Enable Long Packet receive */ |
| 2277 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2278 | rctl &= ~E1000_RCTL_LPE; |
| 2279 | else |
| 2280 | rctl |= E1000_RCTL_LPE; |
| 2281 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 2282 | /* Some systems expect that the CRC is included in SMBUS traffic. The |
| 2283 | * hardware strips the CRC before sending to both SMBUS (BMC) and to |
| 2284 | * host memory when this is enabled |
| 2285 | */ |
| 2286 | if (adapter->flags2 & FLAG2_CRC_STRIPPING) |
| 2287 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 5918bd8 | 2008-02-12 15:20:24 -0800 | [diff] [blame] | 2288 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 2289 | /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ |
| 2290 | if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { |
| 2291 | u16 phy_data; |
| 2292 | |
| 2293 | e1e_rphy(hw, PHY_REG(770, 26), &phy_data); |
| 2294 | phy_data &= 0xfff8; |
| 2295 | phy_data |= (1 << 2); |
| 2296 | e1e_wphy(hw, PHY_REG(770, 26), phy_data); |
| 2297 | |
| 2298 | e1e_rphy(hw, 22, &phy_data); |
| 2299 | phy_data &= 0x0fff; |
| 2300 | phy_data |= (1 << 14); |
| 2301 | e1e_wphy(hw, 0x10, 0x2823); |
| 2302 | e1e_wphy(hw, 0x11, 0x0003); |
| 2303 | e1e_wphy(hw, 22, phy_data); |
| 2304 | } |
| 2305 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2306 | /* Setup buffer sizes */ |
| 2307 | rctl &= ~E1000_RCTL_SZ_4096; |
| 2308 | rctl |= E1000_RCTL_BSEX; |
| 2309 | switch (adapter->rx_buffer_len) { |
| 2310 | case 256: |
| 2311 | rctl |= E1000_RCTL_SZ_256; |
| 2312 | rctl &= ~E1000_RCTL_BSEX; |
| 2313 | break; |
| 2314 | case 512: |
| 2315 | rctl |= E1000_RCTL_SZ_512; |
| 2316 | rctl &= ~E1000_RCTL_BSEX; |
| 2317 | break; |
| 2318 | case 1024: |
| 2319 | rctl |= E1000_RCTL_SZ_1024; |
| 2320 | rctl &= ~E1000_RCTL_BSEX; |
| 2321 | break; |
| 2322 | case 2048: |
| 2323 | default: |
| 2324 | rctl |= E1000_RCTL_SZ_2048; |
| 2325 | rctl &= ~E1000_RCTL_BSEX; |
| 2326 | break; |
| 2327 | case 4096: |
| 2328 | rctl |= E1000_RCTL_SZ_4096; |
| 2329 | break; |
| 2330 | case 8192: |
| 2331 | rctl |= E1000_RCTL_SZ_8192; |
| 2332 | break; |
| 2333 | case 16384: |
| 2334 | rctl |= E1000_RCTL_SZ_16384; |
| 2335 | break; |
| 2336 | } |
| 2337 | |
| 2338 | /* |
| 2339 | * 82571 and greater support packet-split where the protocol |
| 2340 | * header is placed in skb->data and the packet data is |
| 2341 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 2342 | * In the case of a non-split, skb->data is linearly filled, |
| 2343 | * followed by the page buffers. Therefore, skb->data is |
| 2344 | * sized to hold the largest protocol header. |
| 2345 | * |
| 2346 | * allocations using alloc_page take too long for regular MTU |
| 2347 | * so only enable packet split for jumbo frames |
| 2348 | * |
| 2349 | * Using pages when the page size is greater than 16k wastes |
| 2350 | * a lot of memory, since we allocate 3 pages at all times |
| 2351 | * per packet. |
| 2352 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2353 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2354 | if (!(adapter->flags & FLAG_IS_ICH) && (pages <= 3) && |
| 2355 | (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2356 | adapter->rx_ps_pages = pages; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2357 | else |
| 2358 | adapter->rx_ps_pages = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2359 | |
| 2360 | if (adapter->rx_ps_pages) { |
| 2361 | /* Configure extra packet-split registers */ |
| 2362 | rfctl = er32(RFCTL); |
| 2363 | rfctl |= E1000_RFCTL_EXTEN; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2364 | /* |
| 2365 | * disable packet split support for IPv6 extension headers, |
| 2366 | * because some malformed IPv6 headers can hang the Rx |
| 2367 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2368 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
| 2369 | E1000_RFCTL_NEW_IPV6_EXT_DIS); |
| 2370 | |
| 2371 | ew32(RFCTL, rfctl); |
| 2372 | |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 2373 | /* Enable Packet split descriptors */ |
| 2374 | rctl |= E1000_RCTL_DTYP_PS; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2375 | |
| 2376 | psrctl |= adapter->rx_ps_bsize0 >> |
| 2377 | E1000_PSRCTL_BSIZE0_SHIFT; |
| 2378 | |
| 2379 | switch (adapter->rx_ps_pages) { |
| 2380 | case 3: |
| 2381 | psrctl |= PAGE_SIZE << |
| 2382 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 2383 | case 2: |
| 2384 | psrctl |= PAGE_SIZE << |
| 2385 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 2386 | case 1: |
| 2387 | psrctl |= PAGE_SIZE >> |
| 2388 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 2389 | break; |
| 2390 | } |
| 2391 | |
| 2392 | ew32(PSRCTL, psrctl); |
| 2393 | } |
| 2394 | |
| 2395 | ew32(RCTL, rctl); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2396 | /* just started the receive unit, no need to restart */ |
| 2397 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | /** |
| 2401 | * e1000_configure_rx - Configure Receive Unit after Reset |
| 2402 | * @adapter: board private structure |
| 2403 | * |
| 2404 | * Configure the Rx unit of the MAC after a reset. |
| 2405 | **/ |
| 2406 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
| 2407 | { |
| 2408 | struct e1000_hw *hw = &adapter->hw; |
| 2409 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 2410 | u64 rdba; |
| 2411 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
| 2412 | |
| 2413 | if (adapter->rx_ps_pages) { |
| 2414 | /* this is a 32 byte descriptor */ |
| 2415 | rdlen = rx_ring->count * |
| 2416 | sizeof(union e1000_rx_desc_packet_split); |
| 2417 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 2418 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2419 | } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { |
| 2420 | rdlen = rx_ring->count * sizeof(struct e1000_rx_desc); |
| 2421 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 2422 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2423 | } else { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2424 | rdlen = rx_ring->count * sizeof(struct e1000_rx_desc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2425 | adapter->clean_rx = e1000_clean_rx_irq; |
| 2426 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 2427 | } |
| 2428 | |
| 2429 | /* disable receives while setting up the descriptors */ |
| 2430 | rctl = er32(RCTL); |
| 2431 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 2432 | e1e_flush(); |
| 2433 | msleep(10); |
| 2434 | |
| 2435 | /* set the Receive Delay Timer Register */ |
| 2436 | ew32(RDTR, adapter->rx_int_delay); |
| 2437 | |
| 2438 | /* irq moderation */ |
| 2439 | ew32(RADV, adapter->rx_abs_int_delay); |
| 2440 | if (adapter->itr_setting != 0) |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2441 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2442 | |
| 2443 | ctrl_ext = er32(CTRL_EXT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2444 | /* Auto-Mask interrupts upon ICR access */ |
| 2445 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 2446 | ew32(IAM, 0xffffffff); |
| 2447 | ew32(CTRL_EXT, ctrl_ext); |
| 2448 | e1e_flush(); |
| 2449 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2450 | /* |
| 2451 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2452 | * the Base and Length of the Rx Descriptor Ring |
| 2453 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2454 | rdba = rx_ring->dma; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2455 | ew32(RDBAL, (rdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2456 | ew32(RDBAH, (rdba >> 32)); |
| 2457 | ew32(RDLEN, rdlen); |
| 2458 | ew32(RDH, 0); |
| 2459 | ew32(RDT, 0); |
| 2460 | rx_ring->head = E1000_RDH; |
| 2461 | rx_ring->tail = E1000_RDT; |
| 2462 | |
| 2463 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 2464 | rxcsum = er32(RXCSUM); |
| 2465 | if (adapter->flags & FLAG_RX_CSUM_ENABLED) { |
| 2466 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 2467 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2468 | /* |
| 2469 | * IPv4 payload checksum for UDP fragments must be |
| 2470 | * used in conjunction with packet-split. |
| 2471 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2472 | if (adapter->rx_ps_pages) |
| 2473 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 2474 | } else { |
| 2475 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 2476 | /* no need to clear IPPCSE as it defaults to 0 */ |
| 2477 | } |
| 2478 | ew32(RXCSUM, rxcsum); |
| 2479 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2480 | /* |
| 2481 | * Enable early receives on supported devices, only takes effect when |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2482 | * 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] | 2483 | * units), e.g. using jumbo frames when setting to E1000_ERT_2048 |
| 2484 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2485 | if ((adapter->flags & FLAG_HAS_ERT) && |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2486 | (adapter->netdev->mtu > ETH_DATA_LEN)) { |
| 2487 | u32 rxdctl = er32(RXDCTL(0)); |
| 2488 | ew32(RXDCTL(0), rxdctl | 0x3); |
| 2489 | ew32(ERT, E1000_ERT_2048 | (1 << 13)); |
| 2490 | /* |
| 2491 | * With jumbo frames and early-receive enabled, excessive |
| 2492 | * C4->C2 latencies result in dropped transactions. |
| 2493 | */ |
| 2494 | pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, |
| 2495 | e1000e_driver_name, 55); |
| 2496 | } else { |
| 2497 | pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, |
| 2498 | e1000e_driver_name, |
| 2499 | PM_QOS_DEFAULT_VALUE); |
| 2500 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2501 | |
| 2502 | /* Enable Receives */ |
| 2503 | ew32(RCTL, rctl); |
| 2504 | } |
| 2505 | |
| 2506 | /** |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 2507 | * e1000_update_mc_addr_list - Update Multicast addresses |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2508 | * @hw: pointer to the HW structure |
| 2509 | * @mc_addr_list: array of multicast addresses to program |
| 2510 | * @mc_addr_count: number of multicast addresses to program |
| 2511 | * @rar_used_count: the first RAR register free to program |
| 2512 | * @rar_count: total number of supported Receive Address Registers |
| 2513 | * |
| 2514 | * Updates the Receive Address Registers and Multicast Table Array. |
| 2515 | * The caller must have a packed mc_addr_list of multicast addresses. |
| 2516 | * The parameter rar_count will usually be hw->mac.rar_entry_count |
| 2517 | * unless there are workarounds that change this. Currently no func pointer |
| 2518 | * exists and all implementations are handled in the generic version of this |
| 2519 | * function. |
| 2520 | **/ |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 2521 | static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list, |
| 2522 | u32 mc_addr_count, u32 rar_used_count, |
| 2523 | u32 rar_count) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2524 | { |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 2525 | 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] | 2526 | rar_used_count, rar_count); |
| 2527 | } |
| 2528 | |
| 2529 | /** |
| 2530 | * e1000_set_multi - Multicast and Promiscuous mode set |
| 2531 | * @netdev: network interface device structure |
| 2532 | * |
| 2533 | * The set_multi entry point is called whenever the multicast address |
| 2534 | * list or the network interface flags are updated. This routine is |
| 2535 | * responsible for configuring the hardware for proper multicast, |
| 2536 | * promiscuous mode, and all-multi behavior. |
| 2537 | **/ |
| 2538 | static void e1000_set_multi(struct net_device *netdev) |
| 2539 | { |
| 2540 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2541 | struct e1000_hw *hw = &adapter->hw; |
| 2542 | struct e1000_mac_info *mac = &hw->mac; |
| 2543 | struct dev_mc_list *mc_ptr; |
| 2544 | u8 *mta_list; |
| 2545 | u32 rctl; |
| 2546 | int i; |
| 2547 | |
| 2548 | /* Check for Promiscuous and All Multicast modes */ |
| 2549 | |
| 2550 | rctl = er32(RCTL); |
| 2551 | |
| 2552 | if (netdev->flags & IFF_PROMISC) { |
| 2553 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2554 | rctl &= ~E1000_RCTL_VFE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2555 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2556 | if (netdev->flags & IFF_ALLMULTI) { |
| 2557 | rctl |= E1000_RCTL_MPE; |
| 2558 | rctl &= ~E1000_RCTL_UPE; |
| 2559 | } else { |
| 2560 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 2561 | } |
Patrick McHardy | 78ed11a | 2008-07-16 20:16:14 -0700 | [diff] [blame] | 2562 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2563 | rctl |= E1000_RCTL_VFE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | ew32(RCTL, rctl); |
| 2567 | |
| 2568 | if (netdev->mc_count) { |
| 2569 | mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC); |
| 2570 | if (!mta_list) |
| 2571 | return; |
| 2572 | |
| 2573 | /* prepare a packed array of only addresses. */ |
| 2574 | mc_ptr = netdev->mc_list; |
| 2575 | |
| 2576 | for (i = 0; i < netdev->mc_count; i++) { |
| 2577 | if (!mc_ptr) |
| 2578 | break; |
| 2579 | memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr, |
| 2580 | ETH_ALEN); |
| 2581 | mc_ptr = mc_ptr->next; |
| 2582 | } |
| 2583 | |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 2584 | e1000_update_mc_addr_list(hw, mta_list, i, 1, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2585 | mac->rar_entry_count); |
| 2586 | kfree(mta_list); |
| 2587 | } else { |
| 2588 | /* |
| 2589 | * if we're called from probe, we might not have |
| 2590 | * anything to do here, so clear out the list |
| 2591 | */ |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 2592 | 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] | 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2597 | * e1000_configure - configure the hardware for Rx and Tx |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2598 | * @adapter: private board structure |
| 2599 | **/ |
| 2600 | static void e1000_configure(struct e1000_adapter *adapter) |
| 2601 | { |
| 2602 | e1000_set_multi(adapter->netdev); |
| 2603 | |
| 2604 | e1000_restore_vlan(adapter); |
| 2605 | e1000_init_manageability(adapter); |
| 2606 | |
| 2607 | e1000_configure_tx(adapter); |
| 2608 | e1000_setup_rctl(adapter); |
| 2609 | e1000_configure_rx(adapter); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2610 | adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | /** |
| 2614 | * e1000e_power_up_phy - restore link in case the phy was powered down |
| 2615 | * @adapter: address of board private structure |
| 2616 | * |
| 2617 | * The phy may be powered down to save power and turn off link when the |
| 2618 | * driver is unloaded and wake on lan is not enabled (among others) |
| 2619 | * *** this routine MUST be followed by a call to e1000e_reset *** |
| 2620 | **/ |
| 2621 | void e1000e_power_up_phy(struct e1000_adapter *adapter) |
| 2622 | { |
| 2623 | u16 mii_reg = 0; |
| 2624 | |
| 2625 | /* Just clear the power down bit to wake the phy back up */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2626 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2627 | /* |
| 2628 | * According to the manual, the phy will retain its |
| 2629 | * settings across a power-down/up cycle |
| 2630 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2631 | e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg); |
| 2632 | mii_reg &= ~MII_CR_POWER_DOWN; |
| 2633 | e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg); |
| 2634 | } |
| 2635 | |
| 2636 | adapter->hw.mac.ops.setup_link(&adapter->hw); |
| 2637 | } |
| 2638 | |
| 2639 | /** |
| 2640 | * e1000_power_down_phy - Power down the PHY |
| 2641 | * |
| 2642 | * Power down the PHY so no link is implied when interface is down |
| 2643 | * The PHY cannot be powered down is management or WoL is active |
| 2644 | */ |
| 2645 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 2646 | { |
| 2647 | struct e1000_hw *hw = &adapter->hw; |
| 2648 | u16 mii_reg; |
| 2649 | |
| 2650 | /* WoL is enabled */ |
Auke Kok | 23b66e2 | 2008-02-11 09:25:51 -0800 | [diff] [blame] | 2651 | if (adapter->wol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2652 | return; |
| 2653 | |
| 2654 | /* non-copper PHY? */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2655 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2656 | return; |
| 2657 | |
| 2658 | /* reset is blocked because of a SoL/IDER session */ |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2659 | if (e1000e_check_mng_mode(hw) || e1000_check_reset_block(hw)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2660 | return; |
| 2661 | |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2662 | /* manageability (AMT) is enabled */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2663 | if (er32(MANC) & E1000_MANC_SMBUS_EN) |
| 2664 | return; |
| 2665 | |
| 2666 | /* power down the PHY */ |
| 2667 | e1e_rphy(hw, PHY_CONTROL, &mii_reg); |
| 2668 | mii_reg |= MII_CR_POWER_DOWN; |
| 2669 | e1e_wphy(hw, PHY_CONTROL, mii_reg); |
| 2670 | mdelay(1); |
| 2671 | } |
| 2672 | |
| 2673 | /** |
| 2674 | * e1000e_reset - bring the hardware into a known good state |
| 2675 | * |
| 2676 | * This function boots the hardware and enables some settings that |
| 2677 | * require a configuration cycle of the hardware - those cannot be |
| 2678 | * set/changed during runtime. After reset the device needs to be |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2679 | * properly configured for Rx, Tx etc. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2680 | */ |
| 2681 | void e1000e_reset(struct e1000_adapter *adapter) |
| 2682 | { |
| 2683 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2684 | struct e1000_fc_info *fc = &adapter->hw.fc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2685 | struct e1000_hw *hw = &adapter->hw; |
| 2686 | u32 tx_space, min_tx_space, min_rx_space; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2687 | u32 pba = adapter->pba; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2688 | u16 hwm; |
| 2689 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2690 | /* reset Packet Buffer Allocation to default */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2691 | ew32(PBA, pba); |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2692 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2693 | if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2694 | /* |
| 2695 | * To maintain wire speed transmits, the Tx FIFO should be |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2696 | * large enough to accommodate two full transmit packets, |
| 2697 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 2698 | * the Rx FIFO should be large enough to accommodate at least |
| 2699 | * one full receive packet and is similarly rounded up and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2700 | * expressed in KB. |
| 2701 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2702 | pba = er32(PBA); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2703 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2704 | tx_space = pba >> 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2705 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2706 | pba &= 0xffff; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2707 | /* |
| 2708 | * the Tx fifo also stores 16 bytes of information about the tx |
| 2709 | * but don't include ethernet FCS because hardware appends it |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2710 | */ |
| 2711 | min_tx_space = (adapter->max_frame_size + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2712 | sizeof(struct e1000_tx_desc) - |
| 2713 | ETH_FCS_LEN) * 2; |
| 2714 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 2715 | min_tx_space >>= 10; |
| 2716 | /* software strips receive CRC, so leave room for it */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2717 | min_rx_space = adapter->max_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2718 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 2719 | min_rx_space >>= 10; |
| 2720 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2721 | /* |
| 2722 | * If current Tx allocation is less than the min Tx FIFO size, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2723 | * 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] | 2724 | * allocation, take space away from current Rx allocation |
| 2725 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2726 | if ((tx_space < min_tx_space) && |
| 2727 | ((min_tx_space - tx_space) < pba)) { |
| 2728 | pba -= min_tx_space - tx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2729 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2730 | /* |
| 2731 | * if short on Rx space, Rx wins and must trump tx |
| 2732 | * adjustment or use Early Receive if available |
| 2733 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2734 | if ((pba < min_rx_space) && |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2735 | (!(adapter->flags & FLAG_HAS_ERT))) |
| 2736 | /* ERT enabled in e1000_configure_rx */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2737 | pba = min_rx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2738 | } |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 2739 | |
| 2740 | ew32(PBA, pba); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2743 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2744 | /* |
| 2745 | * flow control settings |
| 2746 | * |
Bruce Allan | 3ec2a2b | 2009-06-02 11:28:39 +0000 | [diff] [blame] | 2747 | * The high water mark must be low enough to fit two full frame |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2748 | * (or the size used for early receive) above it in the Rx FIFO. |
| 2749 | * Set it to the lower of: |
| 2750 | * - 90% of the Rx FIFO size, and |
| 2751 | * - the full Rx FIFO size minus the early receive size (for parts |
| 2752 | * with ERT support assuming ERT set to E1000_ERT_2048), or |
Bruce Allan | 3ec2a2b | 2009-06-02 11:28:39 +0000 | [diff] [blame] | 2753 | * - the full Rx FIFO size minus two full frames |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2754 | */ |
Bruce Allan | 3ec2a2b | 2009-06-02 11:28:39 +0000 | [diff] [blame] | 2755 | if ((adapter->flags & FLAG_HAS_ERT) && |
| 2756 | (adapter->netdev->mtu > ETH_DATA_LEN)) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2757 | hwm = min(((pba << 10) * 9 / 10), |
| 2758 | ((pba << 10) - (E1000_ERT_2048 << 3))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2759 | else |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2760 | hwm = min(((pba << 10) * 9 / 10), |
Bruce Allan | 3ec2a2b | 2009-06-02 11:28:39 +0000 | [diff] [blame] | 2761 | ((pba << 10) - (2 * adapter->max_frame_size))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2762 | |
Bruce Allan | 3ec2a2b | 2009-06-02 11:28:39 +0000 | [diff] [blame] | 2763 | fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ |
| 2764 | fc->low_water = (fc->high_water - (2 * adapter->max_frame_size)); |
| 2765 | fc->low_water &= E1000_FCRTL_RTL; /* 8-byte granularity */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2766 | |
| 2767 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2768 | fc->pause_time = 0xFFFF; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2769 | else |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2770 | fc->pause_time = E1000_FC_PAUSE_TIME; |
| 2771 | fc->send_xon = 1; |
Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 2772 | fc->current_mode = fc->requested_mode; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2773 | |
| 2774 | /* Allow time for pending master requests to run */ |
| 2775 | mac->ops.reset_hw(hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2776 | |
| 2777 | /* |
| 2778 | * For parts with AMT enabled, let the firmware know |
| 2779 | * that the network interface is in control |
| 2780 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 2781 | if (adapter->flags & FLAG_HAS_AMT) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2782 | e1000_get_hw_control(adapter); |
| 2783 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2784 | ew32(WUC, 0); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 2785 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) |
| 2786 | e1e_wphy(&adapter->hw, BM_WUC, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2787 | |
| 2788 | if (mac->ops.init_hw(hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 2789 | e_err("Hardware Error\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2790 | |
| 2791 | e1000_update_mng_vlan(adapter); |
| 2792 | |
| 2793 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 2794 | ew32(VET, ETH_P_8021Q); |
| 2795 | |
| 2796 | e1000e_reset_adaptive(hw); |
| 2797 | e1000_get_phy_info(hw); |
| 2798 | |
Bruce Allan | 918d719 | 2009-06-02 11:28:20 +0000 | [diff] [blame] | 2799 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && |
| 2800 | !(adapter->flags & FLAG_SMART_POWER_DOWN)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2801 | u16 phy_data = 0; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2802 | /* |
| 2803 | * speed up time to link by disabling smart power down, ignore |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2804 | * the return value of this function because there is nothing |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2805 | * different we would do if it failed |
| 2806 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2807 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
| 2808 | phy_data &= ~IGP02E1000_PM_SPD; |
| 2809 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 2810 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | int e1000e_up(struct e1000_adapter *adapter) |
| 2814 | { |
| 2815 | struct e1000_hw *hw = &adapter->hw; |
| 2816 | |
| 2817 | /* hardware has been reset, we need to reload some things */ |
| 2818 | e1000_configure(adapter); |
| 2819 | |
| 2820 | clear_bit(__E1000_DOWN, &adapter->state); |
| 2821 | |
| 2822 | napi_enable(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2823 | if (adapter->msix_entries) |
| 2824 | e1000_configure_msix(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2825 | e1000_irq_enable(adapter); |
| 2826 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 2827 | netif_wake_queue(adapter->netdev); |
| 2828 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2829 | /* fire a link change interrupt to start the watchdog */ |
| 2830 | ew32(ICS, E1000_ICS_LSC); |
| 2831 | return 0; |
| 2832 | } |
| 2833 | |
| 2834 | void e1000e_down(struct e1000_adapter *adapter) |
| 2835 | { |
| 2836 | struct net_device *netdev = adapter->netdev; |
| 2837 | struct e1000_hw *hw = &adapter->hw; |
| 2838 | u32 tctl, rctl; |
| 2839 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2840 | /* |
| 2841 | * signal that we're down so the interrupt handler does not |
| 2842 | * reschedule our watchdog timer |
| 2843 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2844 | set_bit(__E1000_DOWN, &adapter->state); |
| 2845 | |
| 2846 | /* disable receives in the hardware */ |
| 2847 | rctl = er32(RCTL); |
| 2848 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 2849 | /* flush and sleep below */ |
| 2850 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 2851 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2852 | |
| 2853 | /* disable transmits in the hardware */ |
| 2854 | tctl = er32(TCTL); |
| 2855 | tctl &= ~E1000_TCTL_EN; |
| 2856 | ew32(TCTL, tctl); |
| 2857 | /* flush both disables and wait for them to finish */ |
| 2858 | e1e_flush(); |
| 2859 | msleep(10); |
| 2860 | |
| 2861 | napi_disable(&adapter->napi); |
| 2862 | e1000_irq_disable(adapter); |
| 2863 | |
| 2864 | del_timer_sync(&adapter->watchdog_timer); |
| 2865 | del_timer_sync(&adapter->phy_info_timer); |
| 2866 | |
| 2867 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 2868 | netif_carrier_off(netdev); |
| 2869 | adapter->link_speed = 0; |
| 2870 | adapter->link_duplex = 0; |
| 2871 | |
Jeff Kirsher | 52cc308 | 2008-06-24 17:01:29 -0700 | [diff] [blame] | 2872 | if (!pci_channel_offline(adapter->pdev)) |
| 2873 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2874 | e1000_clean_tx_ring(adapter); |
| 2875 | e1000_clean_rx_ring(adapter); |
| 2876 | |
| 2877 | /* |
| 2878 | * TODO: for power management, we could drop the link and |
| 2879 | * pci_disable_device here. |
| 2880 | */ |
| 2881 | } |
| 2882 | |
| 2883 | void e1000e_reinit_locked(struct e1000_adapter *adapter) |
| 2884 | { |
| 2885 | might_sleep(); |
| 2886 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
| 2887 | msleep(1); |
| 2888 | e1000e_down(adapter); |
| 2889 | e1000e_up(adapter); |
| 2890 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 2891 | } |
| 2892 | |
| 2893 | /** |
| 2894 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 2895 | * @adapter: board private structure to initialize |
| 2896 | * |
| 2897 | * e1000_sw_init initializes the Adapter private data structure. |
| 2898 | * Fields are initialized based on PCI device information and |
| 2899 | * OS network device settings (MTU size). |
| 2900 | **/ |
| 2901 | static int __devinit e1000_sw_init(struct e1000_adapter *adapter) |
| 2902 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2903 | struct net_device *netdev = adapter->netdev; |
| 2904 | |
| 2905 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN; |
| 2906 | adapter->rx_ps_bsize0 = 128; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2907 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 2908 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2909 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2910 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2911 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2912 | if (e1000_alloc_queues(adapter)) |
| 2913 | return -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2914 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2915 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2916 | e1000_irq_disable(adapter); |
| 2917 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2918 | set_bit(__E1000_DOWN, &adapter->state); |
| 2919 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
| 2922 | /** |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2923 | * e1000_intr_msi_test - Interrupt Handler |
| 2924 | * @irq: interrupt number |
| 2925 | * @data: pointer to a network interface device structure |
| 2926 | **/ |
| 2927 | static irqreturn_t e1000_intr_msi_test(int irq, void *data) |
| 2928 | { |
| 2929 | struct net_device *netdev = data; |
| 2930 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2931 | struct e1000_hw *hw = &adapter->hw; |
| 2932 | u32 icr = er32(ICR); |
| 2933 | |
| 2934 | e_dbg("%s: icr is %08X\n", netdev->name, icr); |
| 2935 | if (icr & E1000_ICR_RXSEQ) { |
| 2936 | adapter->flags &= ~FLAG_MSI_TEST_FAILED; |
| 2937 | wmb(); |
| 2938 | } |
| 2939 | |
| 2940 | return IRQ_HANDLED; |
| 2941 | } |
| 2942 | |
| 2943 | /** |
| 2944 | * e1000_test_msi_interrupt - Returns 0 for successful test |
| 2945 | * @adapter: board private struct |
| 2946 | * |
| 2947 | * code flow taken from tg3.c |
| 2948 | **/ |
| 2949 | static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) |
| 2950 | { |
| 2951 | struct net_device *netdev = adapter->netdev; |
| 2952 | struct e1000_hw *hw = &adapter->hw; |
| 2953 | int err; |
| 2954 | |
| 2955 | /* poll_enable hasn't been called yet, so don't need disable */ |
| 2956 | /* clear any pending events */ |
| 2957 | er32(ICR); |
| 2958 | |
| 2959 | /* free the real vector and request a test handler */ |
| 2960 | e1000_free_irq(adapter); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2961 | e1000e_reset_interrupt_capability(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2962 | |
| 2963 | /* Assume that the test fails, if it succeeds then the test |
| 2964 | * MSI irq handler will unset this flag */ |
| 2965 | adapter->flags |= FLAG_MSI_TEST_FAILED; |
| 2966 | |
| 2967 | err = pci_enable_msi(adapter->pdev); |
| 2968 | if (err) |
| 2969 | goto msi_test_failed; |
| 2970 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2971 | err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2972 | netdev->name, netdev); |
| 2973 | if (err) { |
| 2974 | pci_disable_msi(adapter->pdev); |
| 2975 | goto msi_test_failed; |
| 2976 | } |
| 2977 | |
| 2978 | wmb(); |
| 2979 | |
| 2980 | e1000_irq_enable(adapter); |
| 2981 | |
| 2982 | /* fire an unusual interrupt on the test handler */ |
| 2983 | ew32(ICS, E1000_ICS_RXSEQ); |
| 2984 | e1e_flush(); |
| 2985 | msleep(50); |
| 2986 | |
| 2987 | e1000_irq_disable(adapter); |
| 2988 | |
| 2989 | rmb(); |
| 2990 | |
| 2991 | if (adapter->flags & FLAG_MSI_TEST_FAILED) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2992 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2993 | err = -EIO; |
| 2994 | e_info("MSI interrupt test failed!\n"); |
| 2995 | } |
| 2996 | |
| 2997 | free_irq(adapter->pdev->irq, netdev); |
| 2998 | pci_disable_msi(adapter->pdev); |
| 2999 | |
| 3000 | if (err == -EIO) |
| 3001 | goto msi_test_failed; |
| 3002 | |
| 3003 | /* okay so the test worked, restore settings */ |
| 3004 | e_dbg("%s: MSI interrupt test succeeded!\n", netdev->name); |
| 3005 | msi_test_failed: |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3006 | e1000e_set_interrupt_capability(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3007 | e1000_request_irq(adapter); |
| 3008 | return err; |
| 3009 | } |
| 3010 | |
| 3011 | /** |
| 3012 | * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored |
| 3013 | * @adapter: board private struct |
| 3014 | * |
| 3015 | * code flow taken from tg3.c, called with e1000 interrupts disabled. |
| 3016 | **/ |
| 3017 | static int e1000_test_msi(struct e1000_adapter *adapter) |
| 3018 | { |
| 3019 | int err; |
| 3020 | u16 pci_cmd; |
| 3021 | |
| 3022 | if (!(adapter->flags & FLAG_MSI_ENABLED)) |
| 3023 | return 0; |
| 3024 | |
| 3025 | /* disable SERR in case the MSI write causes a master abort */ |
| 3026 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
| 3027 | pci_write_config_word(adapter->pdev, PCI_COMMAND, |
| 3028 | pci_cmd & ~PCI_COMMAND_SERR); |
| 3029 | |
| 3030 | err = e1000_test_msi_interrupt(adapter); |
| 3031 | |
| 3032 | /* restore previous setting of command word */ |
| 3033 | pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); |
| 3034 | |
| 3035 | /* success ! */ |
| 3036 | if (!err) |
| 3037 | return 0; |
| 3038 | |
| 3039 | /* EIO means MSI test failed */ |
| 3040 | if (err != -EIO) |
| 3041 | return err; |
| 3042 | |
| 3043 | /* back to INTx mode */ |
| 3044 | e_warn("MSI interrupt test failed, using legacy interrupt.\n"); |
| 3045 | |
| 3046 | e1000_free_irq(adapter); |
| 3047 | |
| 3048 | err = e1000_request_irq(adapter); |
| 3049 | |
| 3050 | return err; |
| 3051 | } |
| 3052 | |
| 3053 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3054 | * e1000_open - Called when a network interface is made active |
| 3055 | * @netdev: network interface device structure |
| 3056 | * |
| 3057 | * Returns 0 on success, negative value on failure |
| 3058 | * |
| 3059 | * The open entry point is called when a network interface is made |
| 3060 | * active by the system (IFF_UP). At this point all resources needed |
| 3061 | * for transmit and receive operations are allocated, the interrupt |
| 3062 | * handler is registered with the OS, the watchdog timer is started, |
| 3063 | * and the stack is notified that the interface is ready. |
| 3064 | **/ |
| 3065 | static int e1000_open(struct net_device *netdev) |
| 3066 | { |
| 3067 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3068 | struct e1000_hw *hw = &adapter->hw; |
| 3069 | int err; |
| 3070 | |
| 3071 | /* disallow open during test */ |
| 3072 | if (test_bit(__E1000_TESTING, &adapter->state)) |
| 3073 | return -EBUSY; |
| 3074 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 3075 | netif_carrier_off(netdev); |
| 3076 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3077 | /* allocate transmit descriptors */ |
| 3078 | err = e1000e_setup_tx_resources(adapter); |
| 3079 | if (err) |
| 3080 | goto err_setup_tx; |
| 3081 | |
| 3082 | /* allocate receive descriptors */ |
| 3083 | err = e1000e_setup_rx_resources(adapter); |
| 3084 | if (err) |
| 3085 | goto err_setup_rx; |
| 3086 | |
| 3087 | e1000e_power_up_phy(adapter); |
| 3088 | |
| 3089 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 3090 | if ((adapter->hw.mng_cookie.status & |
| 3091 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
| 3092 | e1000_update_mng_vlan(adapter); |
| 3093 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3094 | /* |
| 3095 | * If AMT is enabled, let the firmware know that the network |
| 3096 | * interface is now open |
| 3097 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 3098 | if (adapter->flags & FLAG_HAS_AMT) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3099 | e1000_get_hw_control(adapter); |
| 3100 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3101 | /* |
| 3102 | * before we allocate an interrupt, we must be ready to handle it. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3103 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 3104 | * 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] | 3105 | * clean_rx handler before we do so. |
| 3106 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3107 | e1000_configure(adapter); |
| 3108 | |
| 3109 | err = e1000_request_irq(adapter); |
| 3110 | if (err) |
| 3111 | goto err_req_irq; |
| 3112 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3113 | /* |
| 3114 | * Work around PCIe errata with MSI interrupts causing some chipsets to |
| 3115 | * ignore e1000e MSI messages, which means we need to test our MSI |
| 3116 | * interrupt now |
| 3117 | */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3118 | if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3119 | err = e1000_test_msi(adapter); |
| 3120 | if (err) { |
| 3121 | e_err("Interrupt allocation failed\n"); |
| 3122 | goto err_req_irq; |
| 3123 | } |
| 3124 | } |
| 3125 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3126 | /* From here on the code is the same as e1000e_up() */ |
| 3127 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3128 | |
| 3129 | napi_enable(&adapter->napi); |
| 3130 | |
| 3131 | e1000_irq_enable(adapter); |
| 3132 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3133 | netif_start_queue(netdev); |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 3134 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3135 | /* fire a link status change interrupt to start the watchdog */ |
| 3136 | ew32(ICS, E1000_ICS_LSC); |
| 3137 | |
| 3138 | return 0; |
| 3139 | |
| 3140 | err_req_irq: |
| 3141 | e1000_release_hw_control(adapter); |
| 3142 | e1000_power_down_phy(adapter); |
| 3143 | e1000e_free_rx_resources(adapter); |
| 3144 | err_setup_rx: |
| 3145 | e1000e_free_tx_resources(adapter); |
| 3146 | err_setup_tx: |
| 3147 | e1000e_reset(adapter); |
| 3148 | |
| 3149 | return err; |
| 3150 | } |
| 3151 | |
| 3152 | /** |
| 3153 | * e1000_close - Disables a network interface |
| 3154 | * @netdev: network interface device structure |
| 3155 | * |
| 3156 | * Returns 0, this is not allowed to fail |
| 3157 | * |
| 3158 | * The close entry point is called when an interface is de-activated |
| 3159 | * by the OS. The hardware is still under the drivers control, but |
| 3160 | * needs to be disabled. A global MAC reset is issued to stop the |
| 3161 | * hardware, and all transmit and receive resources are freed. |
| 3162 | **/ |
| 3163 | static int e1000_close(struct net_device *netdev) |
| 3164 | { |
| 3165 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3166 | |
| 3167 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 3168 | e1000e_down(adapter); |
| 3169 | e1000_power_down_phy(adapter); |
| 3170 | e1000_free_irq(adapter); |
| 3171 | |
| 3172 | e1000e_free_tx_resources(adapter); |
| 3173 | e1000e_free_rx_resources(adapter); |
| 3174 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3175 | /* |
| 3176 | * kill manageability vlan ID if supported, but not if a vlan with |
| 3177 | * the same ID is registered on the host OS (let 8021q kill it) |
| 3178 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3179 | if ((adapter->hw.mng_cookie.status & |
| 3180 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 3181 | !(adapter->vlgrp && |
| 3182 | vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) |
| 3183 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 3184 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3185 | /* |
| 3186 | * If AMT is enabled, let the firmware know that the network |
| 3187 | * interface is now closed |
| 3188 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 3189 | if (adapter->flags & FLAG_HAS_AMT) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3190 | e1000_release_hw_control(adapter); |
| 3191 | |
| 3192 | return 0; |
| 3193 | } |
| 3194 | /** |
| 3195 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 3196 | * @netdev: network interface device structure |
| 3197 | * @p: pointer to an address structure |
| 3198 | * |
| 3199 | * Returns 0 on success, negative on failure |
| 3200 | **/ |
| 3201 | static int e1000_set_mac(struct net_device *netdev, void *p) |
| 3202 | { |
| 3203 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3204 | struct sockaddr *addr = p; |
| 3205 | |
| 3206 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3207 | return -EADDRNOTAVAIL; |
| 3208 | |
| 3209 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 3210 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 3211 | |
| 3212 | e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0); |
| 3213 | |
| 3214 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { |
| 3215 | /* activate the work around */ |
| 3216 | e1000e_set_laa_state_82571(&adapter->hw, 1); |
| 3217 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3218 | /* |
| 3219 | * 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] | 3220 | * between the time RAR[0] gets clobbered and the time it |
| 3221 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
| 3222 | * of the RARs and no incoming packets directed to this port |
| 3223 | * are dropped. Eventually the LAA will be in RAR[0] and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3224 | * RAR[14] |
| 3225 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3226 | e1000e_rar_set(&adapter->hw, |
| 3227 | adapter->hw.mac.addr, |
| 3228 | adapter->hw.mac.rar_entry_count - 1); |
| 3229 | } |
| 3230 | |
| 3231 | return 0; |
| 3232 | } |
| 3233 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 3234 | /** |
| 3235 | * e1000e_update_phy_task - work thread to update phy |
| 3236 | * @work: pointer to our work struct |
| 3237 | * |
| 3238 | * this worker thread exists because we must acquire a |
| 3239 | * semaphore to read the phy, which we could msleep while |
| 3240 | * waiting for it, and we can't msleep in a timer. |
| 3241 | **/ |
| 3242 | static void e1000e_update_phy_task(struct work_struct *work) |
| 3243 | { |
| 3244 | struct e1000_adapter *adapter = container_of(work, |
| 3245 | struct e1000_adapter, update_phy_task); |
| 3246 | e1000_get_phy_info(&adapter->hw); |
| 3247 | } |
| 3248 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3249 | /* |
| 3250 | * Need to wait a few seconds after link up to get diagnostic information from |
| 3251 | * the phy |
| 3252 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3253 | static void e1000_update_phy_info(unsigned long data) |
| 3254 | { |
| 3255 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 3256 | schedule_work(&adapter->update_phy_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | /** |
| 3260 | * e1000e_update_stats - Update the board statistics counters |
| 3261 | * @adapter: board private structure |
| 3262 | **/ |
| 3263 | void e1000e_update_stats(struct e1000_adapter *adapter) |
| 3264 | { |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 3265 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3266 | struct e1000_hw *hw = &adapter->hw; |
| 3267 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3268 | u16 phy_data; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3269 | |
| 3270 | /* |
| 3271 | * Prevent stats update while adapter is being reset, or if the pci |
| 3272 | * connection is down. |
| 3273 | */ |
| 3274 | if (adapter->link_speed == 0) |
| 3275 | return; |
| 3276 | if (pci_channel_offline(pdev)) |
| 3277 | return; |
| 3278 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3279 | adapter->stats.crcerrs += er32(CRCERRS); |
| 3280 | adapter->stats.gprc += er32(GPRC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3281 | adapter->stats.gorc += er32(GORCL); |
| 3282 | er32(GORCH); /* Clear gorc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3283 | adapter->stats.bprc += er32(BPRC); |
| 3284 | adapter->stats.mprc += er32(MPRC); |
| 3285 | adapter->stats.roc += er32(ROC); |
| 3286 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3287 | adapter->stats.mpc += er32(MPC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3288 | if ((hw->phy.type == e1000_phy_82578) || |
| 3289 | (hw->phy.type == e1000_phy_82577)) { |
| 3290 | e1e_rphy(hw, HV_SCC_UPPER, &phy_data); |
| 3291 | e1e_rphy(hw, HV_SCC_LOWER, &phy_data); |
| 3292 | adapter->stats.scc += phy_data; |
| 3293 | |
| 3294 | e1e_rphy(hw, HV_ECOL_UPPER, &phy_data); |
| 3295 | e1e_rphy(hw, HV_ECOL_LOWER, &phy_data); |
| 3296 | adapter->stats.ecol += phy_data; |
| 3297 | |
| 3298 | e1e_rphy(hw, HV_MCC_UPPER, &phy_data); |
| 3299 | e1e_rphy(hw, HV_MCC_LOWER, &phy_data); |
| 3300 | adapter->stats.mcc += phy_data; |
| 3301 | |
| 3302 | e1e_rphy(hw, HV_LATECOL_UPPER, &phy_data); |
| 3303 | e1e_rphy(hw, HV_LATECOL_LOWER, &phy_data); |
| 3304 | adapter->stats.latecol += phy_data; |
| 3305 | |
| 3306 | e1e_rphy(hw, HV_DC_UPPER, &phy_data); |
| 3307 | e1e_rphy(hw, HV_DC_LOWER, &phy_data); |
| 3308 | adapter->stats.dc += phy_data; |
| 3309 | } else { |
| 3310 | adapter->stats.scc += er32(SCC); |
| 3311 | adapter->stats.ecol += er32(ECOL); |
| 3312 | adapter->stats.mcc += er32(MCC); |
| 3313 | adapter->stats.latecol += er32(LATECOL); |
| 3314 | adapter->stats.dc += er32(DC); |
| 3315 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3316 | adapter->stats.xonrxc += er32(XONRXC); |
| 3317 | adapter->stats.xontxc += er32(XONTXC); |
| 3318 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 3319 | adapter->stats.xofftxc += er32(XOFFTXC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3320 | adapter->stats.gptc += er32(GPTC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3321 | adapter->stats.gotc += er32(GOTCL); |
| 3322 | er32(GOTCH); /* Clear gotc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3323 | adapter->stats.rnbc += er32(RNBC); |
| 3324 | adapter->stats.ruc += er32(RUC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3325 | |
| 3326 | adapter->stats.mptc += er32(MPTC); |
| 3327 | adapter->stats.bptc += er32(BPTC); |
| 3328 | |
| 3329 | /* used for adaptive IFS */ |
| 3330 | |
| 3331 | hw->mac.tx_packet_delta = er32(TPT); |
| 3332 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3333 | if ((hw->phy.type == e1000_phy_82578) || |
| 3334 | (hw->phy.type == e1000_phy_82577)) { |
| 3335 | e1e_rphy(hw, HV_COLC_UPPER, &phy_data); |
| 3336 | e1e_rphy(hw, HV_COLC_LOWER, &phy_data); |
| 3337 | hw->mac.collision_delta = phy_data; |
| 3338 | } else { |
| 3339 | hw->mac.collision_delta = er32(COLC); |
| 3340 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3341 | adapter->stats.colc += hw->mac.collision_delta; |
| 3342 | |
| 3343 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 3344 | adapter->stats.rxerrc += er32(RXERRC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3345 | if ((hw->phy.type == e1000_phy_82578) || |
| 3346 | (hw->phy.type == e1000_phy_82577)) { |
| 3347 | e1e_rphy(hw, HV_TNCRS_UPPER, &phy_data); |
| 3348 | e1e_rphy(hw, HV_TNCRS_LOWER, &phy_data); |
| 3349 | adapter->stats.tncrs += phy_data; |
| 3350 | } else { |
| 3351 | if ((hw->mac.type != e1000_82574) && |
| 3352 | (hw->mac.type != e1000_82583)) |
| 3353 | adapter->stats.tncrs += er32(TNCRS); |
| 3354 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3355 | adapter->stats.cexterr += er32(CEXTERR); |
| 3356 | adapter->stats.tsctc += er32(TSCTC); |
| 3357 | adapter->stats.tsctfc += er32(TSCTFC); |
| 3358 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3359 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 3360 | netdev->stats.multicast = adapter->stats.mprc; |
| 3361 | netdev->stats.collisions = adapter->stats.colc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3362 | |
| 3363 | /* Rx Errors */ |
| 3364 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3365 | /* |
| 3366 | * RLEC on some newer hardware can be incorrect so build |
| 3367 | * our own version based on RUC and ROC |
| 3368 | */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 3369 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3370 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 3371 | adapter->stats.ruc + adapter->stats.roc + |
| 3372 | adapter->stats.cexterr; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 3373 | netdev->stats.rx_length_errors = adapter->stats.ruc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3374 | adapter->stats.roc; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 3375 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 3376 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; |
| 3377 | netdev->stats.rx_missed_errors = adapter->stats.mpc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3378 | |
| 3379 | /* Tx Errors */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 3380 | netdev->stats.tx_errors = adapter->stats.ecol + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3381 | adapter->stats.latecol; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 3382 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
| 3383 | netdev->stats.tx_window_errors = adapter->stats.latecol; |
| 3384 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3385 | |
| 3386 | /* Tx Dropped needs to be maintained elsewhere */ |
| 3387 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3388 | /* Management Stats */ |
| 3389 | adapter->stats.mgptc += er32(MGTPTC); |
| 3390 | adapter->stats.mgprc += er32(MGTPRC); |
| 3391 | adapter->stats.mgpdc += er32(MGTPDC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3394 | /** |
| 3395 | * e1000_phy_read_status - Update the PHY register status snapshot |
| 3396 | * @adapter: board private structure |
| 3397 | **/ |
| 3398 | static void e1000_phy_read_status(struct e1000_adapter *adapter) |
| 3399 | { |
| 3400 | struct e1000_hw *hw = &adapter->hw; |
| 3401 | struct e1000_phy_regs *phy = &adapter->phy_regs; |
| 3402 | int ret_val; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3403 | |
| 3404 | if ((er32(STATUS) & E1000_STATUS_LU) && |
| 3405 | (adapter->hw.phy.media_type == e1000_media_type_copper)) { |
| 3406 | ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr); |
| 3407 | ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr); |
| 3408 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise); |
| 3409 | ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa); |
| 3410 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion); |
| 3411 | ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000); |
| 3412 | ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000); |
| 3413 | ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus); |
| 3414 | if (ret_val) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 3415 | e_warn("Error reading PHY register\n"); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3416 | } else { |
| 3417 | /* |
| 3418 | * Do not read PHY registers if link is not up |
| 3419 | * Set values to typical power-on defaults |
| 3420 | */ |
| 3421 | phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); |
| 3422 | phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | |
| 3423 | BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | |
| 3424 | BMSR_ERCAP); |
| 3425 | phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | |
| 3426 | ADVERTISE_ALL | ADVERTISE_CSMA); |
| 3427 | phy->lpa = 0; |
| 3428 | phy->expansion = EXPANSION_ENABLENPAGE; |
| 3429 | phy->ctrl1000 = ADVERTISE_1000FULL; |
| 3430 | phy->stat1000 = 0; |
| 3431 | phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); |
| 3432 | } |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3433 | } |
| 3434 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3435 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
| 3436 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3437 | struct e1000_hw *hw = &adapter->hw; |
| 3438 | u32 ctrl = er32(CTRL); |
| 3439 | |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 3440 | /* Link status message must follow this format for user tools */ |
| 3441 | printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, " |
| 3442 | "Flow Control: %s\n", |
| 3443 | adapter->netdev->name, |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 3444 | adapter->link_speed, |
| 3445 | (adapter->link_duplex == FULL_DUPLEX) ? |
| 3446 | "Full Duplex" : "Half Duplex", |
| 3447 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ? |
| 3448 | "RX/TX" : |
| 3449 | ((ctrl & E1000_CTRL_RFCE) ? "RX" : |
| 3450 | ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None" ))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3451 | } |
| 3452 | |
Bruce Allan | a20e4cf | 2008-11-21 17:01:35 -0800 | [diff] [blame] | 3453 | bool e1000_has_link(struct e1000_adapter *adapter) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3454 | { |
| 3455 | struct e1000_hw *hw = &adapter->hw; |
| 3456 | bool link_active = 0; |
| 3457 | s32 ret_val = 0; |
| 3458 | |
| 3459 | /* |
| 3460 | * get_link_status is set on LSC (link status) interrupt or |
| 3461 | * Rx sequence error interrupt. get_link_status will stay |
| 3462 | * false until the check_for_link establishes link |
| 3463 | * for copper adapters ONLY |
| 3464 | */ |
| 3465 | switch (hw->phy.media_type) { |
| 3466 | case e1000_media_type_copper: |
| 3467 | if (hw->mac.get_link_status) { |
| 3468 | ret_val = hw->mac.ops.check_for_link(hw); |
| 3469 | link_active = !hw->mac.get_link_status; |
| 3470 | } else { |
| 3471 | link_active = 1; |
| 3472 | } |
| 3473 | break; |
| 3474 | case e1000_media_type_fiber: |
| 3475 | ret_val = hw->mac.ops.check_for_link(hw); |
| 3476 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 3477 | break; |
| 3478 | case e1000_media_type_internal_serdes: |
| 3479 | ret_val = hw->mac.ops.check_for_link(hw); |
| 3480 | link_active = adapter->hw.mac.serdes_has_link; |
| 3481 | break; |
| 3482 | default: |
| 3483 | case e1000_media_type_unknown: |
| 3484 | break; |
| 3485 | } |
| 3486 | |
| 3487 | if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && |
| 3488 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 3489 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 3490 | e_info("Gigabit has been disabled, downgrading speed\n"); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | return link_active; |
| 3494 | } |
| 3495 | |
| 3496 | static void e1000e_enable_receives(struct e1000_adapter *adapter) |
| 3497 | { |
| 3498 | /* make sure the receive unit is started */ |
| 3499 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 3500 | (adapter->flags & FLAG_RX_RESTART_NOW)) { |
| 3501 | struct e1000_hw *hw = &adapter->hw; |
| 3502 | u32 rctl = er32(RCTL); |
| 3503 | ew32(RCTL, rctl | E1000_RCTL_EN); |
| 3504 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
| 3505 | } |
| 3506 | } |
| 3507 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3508 | /** |
| 3509 | * e1000_watchdog - Timer Call-back |
| 3510 | * @data: pointer to adapter cast into an unsigned long |
| 3511 | **/ |
| 3512 | static void e1000_watchdog(unsigned long data) |
| 3513 | { |
| 3514 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 3515 | |
| 3516 | /* Do the rest outside of interrupt context */ |
| 3517 | schedule_work(&adapter->watchdog_task); |
| 3518 | |
| 3519 | /* TODO: make this use queue_delayed_work() */ |
| 3520 | } |
| 3521 | |
| 3522 | static void e1000_watchdog_task(struct work_struct *work) |
| 3523 | { |
| 3524 | struct e1000_adapter *adapter = container_of(work, |
| 3525 | struct e1000_adapter, watchdog_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3526 | struct net_device *netdev = adapter->netdev; |
| 3527 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 3528 | struct e1000_phy_info *phy = &adapter->hw.phy; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3529 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 3530 | struct e1000_hw *hw = &adapter->hw; |
| 3531 | u32 link, tctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3532 | int tx_pending = 0; |
| 3533 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3534 | link = e1000_has_link(adapter); |
| 3535 | if ((netif_carrier_ok(netdev)) && link) { |
| 3536 | e1000e_enable_receives(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3537 | goto link_up; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | if ((e1000e_enable_tx_pkt_filtering(hw)) && |
| 3541 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) |
| 3542 | e1000_update_mng_vlan(adapter); |
| 3543 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3544 | if (link) { |
| 3545 | if (!netif_carrier_ok(netdev)) { |
| 3546 | bool txb2b = 1; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3547 | /* update snapshot of PHY registers on LSC */ |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3548 | e1000_phy_read_status(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3549 | mac->ops.get_link_up_info(&adapter->hw, |
| 3550 | &adapter->link_speed, |
| 3551 | &adapter->link_duplex); |
| 3552 | e1000_print_link_info(adapter); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3553 | /* |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 3554 | * On supported PHYs, check for duplex mismatch only |
| 3555 | * if link has autonegotiated at 10/100 half |
| 3556 | */ |
| 3557 | if ((hw->phy.type == e1000_phy_igp_3 || |
| 3558 | hw->phy.type == e1000_phy_bm) && |
| 3559 | (hw->mac.autoneg == true) && |
| 3560 | (adapter->link_speed == SPEED_10 || |
| 3561 | adapter->link_speed == SPEED_100) && |
| 3562 | (adapter->link_duplex == HALF_DUPLEX)) { |
| 3563 | u16 autoneg_exp; |
| 3564 | |
| 3565 | e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp); |
| 3566 | |
| 3567 | if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS)) |
| 3568 | e_info("Autonegotiated half duplex but" |
| 3569 | " link partner cannot autoneg. " |
| 3570 | " Try forcing full duplex if " |
| 3571 | "link gets many collisions.\n"); |
| 3572 | } |
| 3573 | |
| 3574 | /* |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3575 | * tweak tx_queue_len according to speed/duplex |
| 3576 | * and adjust the timeout factor |
| 3577 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3578 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 3579 | adapter->tx_timeout_factor = 1; |
| 3580 | switch (adapter->link_speed) { |
| 3581 | case SPEED_10: |
| 3582 | txb2b = 0; |
| 3583 | netdev->tx_queue_len = 10; |
Bruce Allan | 10f1b49 | 2008-08-08 18:36:01 -0700 | [diff] [blame] | 3584 | adapter->tx_timeout_factor = 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3585 | break; |
| 3586 | case SPEED_100: |
| 3587 | txb2b = 0; |
| 3588 | netdev->tx_queue_len = 100; |
| 3589 | /* maybe add some timeout factor ? */ |
| 3590 | break; |
| 3591 | } |
| 3592 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3593 | /* |
| 3594 | * workaround: re-program speed mode bit after |
| 3595 | * link-up event |
| 3596 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3597 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
| 3598 | !txb2b) { |
| 3599 | u32 tarc0; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 3600 | tarc0 = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3601 | tarc0 &= ~SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 3602 | ew32(TARC(0), tarc0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3605 | /* |
| 3606 | * disable TSO for pcie and 10/100 speeds, to avoid |
| 3607 | * some hardware issues |
| 3608 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3609 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
| 3610 | switch (adapter->link_speed) { |
| 3611 | case SPEED_10: |
| 3612 | case SPEED_100: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 3613 | e_info("10/100 speed: disabling TSO\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3614 | netdev->features &= ~NETIF_F_TSO; |
| 3615 | netdev->features &= ~NETIF_F_TSO6; |
| 3616 | break; |
| 3617 | case SPEED_1000: |
| 3618 | netdev->features |= NETIF_F_TSO; |
| 3619 | netdev->features |= NETIF_F_TSO6; |
| 3620 | break; |
| 3621 | default: |
| 3622 | /* oops */ |
| 3623 | break; |
| 3624 | } |
| 3625 | } |
| 3626 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3627 | /* |
| 3628 | * enable transmits in the hardware, need to do this |
| 3629 | * after setting TARC(0) |
| 3630 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3631 | tctl = er32(TCTL); |
| 3632 | tctl |= E1000_TCTL_EN; |
| 3633 | ew32(TCTL, tctl); |
| 3634 | |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 3635 | /* |
| 3636 | * Perform any post-link-up configuration before |
| 3637 | * reporting link up. |
| 3638 | */ |
| 3639 | if (phy->ops.cfg_on_link_up) |
| 3640 | phy->ops.cfg_on_link_up(hw); |
| 3641 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3642 | netif_carrier_on(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3643 | |
| 3644 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 3645 | mod_timer(&adapter->phy_info_timer, |
| 3646 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3647 | } |
| 3648 | } else { |
| 3649 | if (netif_carrier_ok(netdev)) { |
| 3650 | adapter->link_speed = 0; |
| 3651 | adapter->link_duplex = 0; |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 3652 | /* Link status message must follow this format */ |
| 3653 | printk(KERN_INFO "e1000e: %s NIC Link is Down\n", |
| 3654 | adapter->netdev->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3655 | netif_carrier_off(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3656 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 3657 | mod_timer(&adapter->phy_info_timer, |
| 3658 | round_jiffies(jiffies + 2 * HZ)); |
| 3659 | |
| 3660 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) |
| 3661 | schedule_work(&adapter->reset_task); |
| 3662 | } |
| 3663 | } |
| 3664 | |
| 3665 | link_up: |
| 3666 | e1000e_update_stats(adapter); |
| 3667 | |
| 3668 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 3669 | adapter->tpt_old = adapter->stats.tpt; |
| 3670 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; |
| 3671 | adapter->colc_old = adapter->stats.colc; |
| 3672 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3673 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
| 3674 | adapter->gorc_old = adapter->stats.gorc; |
| 3675 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; |
| 3676 | adapter->gotc_old = adapter->stats.gotc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3677 | |
| 3678 | e1000e_update_adaptive(&adapter->hw); |
| 3679 | |
| 3680 | if (!netif_carrier_ok(netdev)) { |
| 3681 | tx_pending = (e1000_desc_unused(tx_ring) + 1 < |
| 3682 | tx_ring->count); |
| 3683 | if (tx_pending) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3684 | /* |
| 3685 | * We've lost link, so the controller stops DMA, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3686 | * but we've got queued Tx work that's never going |
| 3687 | * to get done, so reset controller to flush Tx. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3688 | * (Do the reset outside of interrupt context). |
| 3689 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3690 | adapter->tx_timeout_count++; |
| 3691 | schedule_work(&adapter->reset_task); |
Jesse Brandeburg | c2d5ab4 | 2009-05-07 11:07:35 +0000 | [diff] [blame] | 3692 | /* return immediately since reset is imminent */ |
| 3693 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3694 | } |
| 3695 | } |
| 3696 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3697 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3698 | if (adapter->msix_entries) |
| 3699 | ew32(ICS, adapter->rx_ring->ims_val); |
| 3700 | else |
| 3701 | ew32(ICS, E1000_ICS_RXDMT0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3702 | |
| 3703 | /* Force detection of hung controller every watchdog period */ |
| 3704 | adapter->detect_tx_hung = 1; |
| 3705 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3706 | /* |
| 3707 | * With 82571 controllers, LAA may be overwritten due to controller |
| 3708 | * reset from the other port. Set the appropriate LAA in RAR[0] |
| 3709 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3710 | if (e1000e_get_laa_state_82571(hw)) |
| 3711 | e1000e_rar_set(hw, adapter->hw.mac.addr, 0); |
| 3712 | |
| 3713 | /* Reset the timer */ |
| 3714 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 3715 | mod_timer(&adapter->watchdog_timer, |
| 3716 | round_jiffies(jiffies + 2 * HZ)); |
| 3717 | } |
| 3718 | |
| 3719 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 3720 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 3721 | #define E1000_TX_FLAGS_TSO 0x00000004 |
| 3722 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
| 3723 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 3724 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 3725 | |
| 3726 | static int e1000_tso(struct e1000_adapter *adapter, |
| 3727 | struct sk_buff *skb) |
| 3728 | { |
| 3729 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 3730 | struct e1000_context_desc *context_desc; |
| 3731 | struct e1000_buffer *buffer_info; |
| 3732 | unsigned int i; |
| 3733 | u32 cmd_length = 0; |
| 3734 | u16 ipcse = 0, tucse, mss; |
| 3735 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
| 3736 | int err; |
| 3737 | |
| 3738 | if (skb_is_gso(skb)) { |
| 3739 | if (skb_header_cloned(skb)) { |
| 3740 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 3741 | if (err) |
| 3742 | return err; |
| 3743 | } |
| 3744 | |
| 3745 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 3746 | mss = skb_shinfo(skb)->gso_size; |
| 3747 | if (skb->protocol == htons(ETH_P_IP)) { |
| 3748 | struct iphdr *iph = ip_hdr(skb); |
| 3749 | iph->tot_len = 0; |
| 3750 | iph->check = 0; |
| 3751 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 3752 | iph->daddr, 0, |
| 3753 | IPPROTO_TCP, |
| 3754 | 0); |
| 3755 | cmd_length = E1000_TXD_CMD_IP; |
| 3756 | ipcse = skb_transport_offset(skb) - 1; |
| 3757 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
| 3758 | ipv6_hdr(skb)->payload_len = 0; |
| 3759 | tcp_hdr(skb)->check = |
| 3760 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 3761 | &ipv6_hdr(skb)->daddr, |
| 3762 | 0, IPPROTO_TCP, 0); |
| 3763 | ipcse = 0; |
| 3764 | } |
| 3765 | ipcss = skb_network_offset(skb); |
| 3766 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
| 3767 | tucss = skb_transport_offset(skb); |
| 3768 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
| 3769 | tucse = 0; |
| 3770 | |
| 3771 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
| 3772 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
| 3773 | |
| 3774 | i = tx_ring->next_to_use; |
| 3775 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 3776 | buffer_info = &tx_ring->buffer_info[i]; |
| 3777 | |
| 3778 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 3779 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 3780 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 3781 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 3782 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 3783 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 3784 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 3785 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 3786 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 3787 | |
| 3788 | buffer_info->time_stamp = jiffies; |
| 3789 | buffer_info->next_to_watch = i; |
| 3790 | |
| 3791 | i++; |
| 3792 | if (i == tx_ring->count) |
| 3793 | i = 0; |
| 3794 | tx_ring->next_to_use = i; |
| 3795 | |
| 3796 | return 1; |
| 3797 | } |
| 3798 | |
| 3799 | return 0; |
| 3800 | } |
| 3801 | |
| 3802 | static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 3803 | { |
| 3804 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 3805 | struct e1000_context_desc *context_desc; |
| 3806 | struct e1000_buffer *buffer_info; |
| 3807 | unsigned int i; |
| 3808 | u8 css; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 3809 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 3810 | __be16 protocol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3811 | |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 3812 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 3813 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3814 | |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 3815 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) |
| 3816 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 3817 | else |
| 3818 | protocol = skb->protocol; |
| 3819 | |
Arthur Jones | 3f51839 | 2009-03-20 15:56:35 -0700 | [diff] [blame] | 3820 | switch (protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 3821 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 3822 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 3823 | cmd_len |= E1000_TXD_CMD_TCP; |
| 3824 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 3825 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 3826 | /* XXX not handling all IPV6 headers */ |
| 3827 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 3828 | cmd_len |= E1000_TXD_CMD_TCP; |
| 3829 | break; |
| 3830 | default: |
| 3831 | if (unlikely(net_ratelimit())) |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 3832 | e_warn("checksum_partial proto=%x!\n", |
| 3833 | be16_to_cpu(protocol)); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 3834 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3835 | } |
| 3836 | |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 3837 | css = skb_transport_offset(skb); |
| 3838 | |
| 3839 | i = tx_ring->next_to_use; |
| 3840 | buffer_info = &tx_ring->buffer_info[i]; |
| 3841 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 3842 | |
| 3843 | context_desc->lower_setup.ip_config = 0; |
| 3844 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 3845 | context_desc->upper_setup.tcp_fields.tucso = |
| 3846 | css + skb->csum_offset; |
| 3847 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 3848 | context_desc->tcp_seg_setup.data = 0; |
| 3849 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 3850 | |
| 3851 | buffer_info->time_stamp = jiffies; |
| 3852 | buffer_info->next_to_watch = i; |
| 3853 | |
| 3854 | i++; |
| 3855 | if (i == tx_ring->count) |
| 3856 | i = 0; |
| 3857 | tx_ring->next_to_use = i; |
| 3858 | |
| 3859 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | #define E1000_MAX_PER_TXD 8192 |
| 3863 | #define E1000_MAX_TXD_PWR 12 |
| 3864 | |
| 3865 | static int e1000_tx_map(struct e1000_adapter *adapter, |
| 3866 | struct sk_buff *skb, unsigned int first, |
| 3867 | unsigned int max_per_txd, unsigned int nr_frags, |
| 3868 | unsigned int mss) |
| 3869 | { |
| 3870 | struct e1000_ring *tx_ring = adapter->tx_ring; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 3871 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 3872 | unsigned int len = skb_headlen(skb); |
| 3873 | unsigned int offset, size, count = 0, i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3874 | unsigned int f; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 3875 | dma_addr_t *map; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3876 | |
| 3877 | i = tx_ring->next_to_use; |
| 3878 | |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 3879 | if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) { |
| 3880 | dev_err(&adapter->pdev->dev, "TX DMA map failed\n"); |
| 3881 | adapter->tx_dma_failed++; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 3882 | return 0; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 3883 | } |
| 3884 | |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 3885 | map = skb_shinfo(skb)->dma_maps; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 3886 | offset = 0; |
| 3887 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3888 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 3889 | buffer_info = &tx_ring->buffer_info[i]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3890 | size = min(len, max_per_txd); |
| 3891 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3892 | buffer_info->length = size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3893 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3894 | buffer_info->next_to_watch = i; |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 3895 | buffer_info->dma = skb_shinfo(skb)->dma_head + offset; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 3896 | count++; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3897 | |
| 3898 | len -= size; |
| 3899 | offset += size; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 3900 | |
| 3901 | if (len) { |
| 3902 | i++; |
| 3903 | if (i == tx_ring->count) |
| 3904 | i = 0; |
| 3905 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | for (f = 0; f < nr_frags; f++) { |
| 3909 | struct skb_frag_struct *frag; |
| 3910 | |
| 3911 | frag = &skb_shinfo(skb)->frags[f]; |
| 3912 | len = frag->size; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 3913 | offset = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3914 | |
| 3915 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 3916 | i++; |
| 3917 | if (i == tx_ring->count) |
| 3918 | i = 0; |
| 3919 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3920 | buffer_info = &tx_ring->buffer_info[i]; |
| 3921 | size = min(len, max_per_txd); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3922 | |
| 3923 | buffer_info->length = size; |
| 3924 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3925 | buffer_info->next_to_watch = i; |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 3926 | buffer_info->dma = map[f] + offset; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3927 | |
| 3928 | len -= size; |
| 3929 | offset += size; |
| 3930 | count++; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3931 | } |
| 3932 | } |
| 3933 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3934 | tx_ring->buffer_info[i].skb = skb; |
| 3935 | tx_ring->buffer_info[first].next_to_watch = i; |
| 3936 | |
| 3937 | return count; |
| 3938 | } |
| 3939 | |
| 3940 | static void e1000_tx_queue(struct e1000_adapter *adapter, |
| 3941 | int tx_flags, int count) |
| 3942 | { |
| 3943 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 3944 | struct e1000_tx_desc *tx_desc = NULL; |
| 3945 | struct e1000_buffer *buffer_info; |
| 3946 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 3947 | unsigned int i; |
| 3948 | |
| 3949 | if (tx_flags & E1000_TX_FLAGS_TSO) { |
| 3950 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 3951 | E1000_TXD_CMD_TSE; |
| 3952 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3953 | |
| 3954 | if (tx_flags & E1000_TX_FLAGS_IPV4) |
| 3955 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
| 3956 | } |
| 3957 | |
| 3958 | if (tx_flags & E1000_TX_FLAGS_CSUM) { |
| 3959 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 3960 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3961 | } |
| 3962 | |
| 3963 | if (tx_flags & E1000_TX_FLAGS_VLAN) { |
| 3964 | txd_lower |= E1000_TXD_CMD_VLE; |
| 3965 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 3966 | } |
| 3967 | |
| 3968 | i = tx_ring->next_to_use; |
| 3969 | |
| 3970 | while (count--) { |
| 3971 | buffer_info = &tx_ring->buffer_info[i]; |
| 3972 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3973 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 3974 | tx_desc->lower.data = |
| 3975 | cpu_to_le32(txd_lower | buffer_info->length); |
| 3976 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
| 3977 | |
| 3978 | i++; |
| 3979 | if (i == tx_ring->count) |
| 3980 | i = 0; |
| 3981 | } |
| 3982 | |
| 3983 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 3984 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3985 | /* |
| 3986 | * Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3987 | * know there are new descriptors to fetch. (Only |
| 3988 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3989 | * such as IA-64). |
| 3990 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3991 | wmb(); |
| 3992 | |
| 3993 | tx_ring->next_to_use = i; |
| 3994 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3995 | /* |
| 3996 | * we need this if more than one processor can write to our tail |
| 3997 | * at a time, it synchronizes IO on IA64/Altix systems |
| 3998 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3999 | mmiowb(); |
| 4000 | } |
| 4001 | |
| 4002 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 4003 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 4004 | struct sk_buff *skb) |
| 4005 | { |
| 4006 | struct e1000_hw *hw = &adapter->hw; |
| 4007 | u16 length, offset; |
| 4008 | |
| 4009 | if (vlan_tx_tag_present(skb)) { |
| 4010 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) |
| 4011 | && (adapter->hw.mng_cookie.status & |
| 4012 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) |
| 4013 | return 0; |
| 4014 | } |
| 4015 | |
| 4016 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) |
| 4017 | return 0; |
| 4018 | |
| 4019 | if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP)) |
| 4020 | return 0; |
| 4021 | |
| 4022 | { |
| 4023 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14); |
| 4024 | struct udphdr *udp; |
| 4025 | |
| 4026 | if (ip->protocol != IPPROTO_UDP) |
| 4027 | return 0; |
| 4028 | |
| 4029 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 4030 | if (ntohs(udp->dest) != 67) |
| 4031 | return 0; |
| 4032 | |
| 4033 | offset = (u8 *)udp + 8 - skb->data; |
| 4034 | length = skb->len - offset; |
| 4035 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); |
| 4036 | } |
| 4037 | |
| 4038 | return 0; |
| 4039 | } |
| 4040 | |
| 4041 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 4042 | { |
| 4043 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4044 | |
| 4045 | netif_stop_queue(netdev); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4046 | /* |
| 4047 | * Herbert's original patch had: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4048 | * smp_mb__after_netif_stop_queue(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4049 | * but since that doesn't exist yet, just open code it. |
| 4050 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4051 | smp_mb(); |
| 4052 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4053 | /* |
| 4054 | * We need to check again in a case another CPU has just |
| 4055 | * made room available. |
| 4056 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4057 | if (e1000_desc_unused(adapter->tx_ring) < size) |
| 4058 | return -EBUSY; |
| 4059 | |
| 4060 | /* A reprieve! */ |
| 4061 | netif_start_queue(netdev); |
| 4062 | ++adapter->restart_queue; |
| 4063 | return 0; |
| 4064 | } |
| 4065 | |
| 4066 | static int e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 4067 | { |
| 4068 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4069 | |
| 4070 | if (e1000_desc_unused(adapter->tx_ring) >= size) |
| 4071 | return 0; |
| 4072 | return __e1000_maybe_stop_tx(netdev, size); |
| 4073 | } |
| 4074 | |
| 4075 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 4076 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 4077 | struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4078 | { |
| 4079 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4080 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4081 | unsigned int first; |
| 4082 | unsigned int max_per_txd = E1000_MAX_PER_TXD; |
| 4083 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 4084 | unsigned int tx_flags = 0; |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 4085 | unsigned int len = skb->len - skb->data_len; |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 4086 | unsigned int nr_frags; |
| 4087 | unsigned int mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4088 | int count = 0; |
| 4089 | int tso; |
| 4090 | unsigned int f; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4091 | |
| 4092 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 4093 | dev_kfree_skb_any(skb); |
| 4094 | return NETDEV_TX_OK; |
| 4095 | } |
| 4096 | |
| 4097 | if (skb->len <= 0) { |
| 4098 | dev_kfree_skb_any(skb); |
| 4099 | return NETDEV_TX_OK; |
| 4100 | } |
| 4101 | |
| 4102 | mss = skb_shinfo(skb)->gso_size; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4103 | /* |
| 4104 | * The controller does a simple calculation to |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4105 | * make sure there is enough room in the FIFO before |
| 4106 | * initiating the DMA for each buffer. The calc is: |
| 4107 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 4108 | * overrun the FIFO, adjust the max buffer len if mss |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4109 | * drops. |
| 4110 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4111 | if (mss) { |
| 4112 | u8 hdr_len; |
| 4113 | max_per_txd = min(mss << 2, max_per_txd); |
| 4114 | max_txd_pwr = fls(max_per_txd) - 1; |
| 4115 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4116 | /* |
| 4117 | * TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 4118 | * points to just header, pull a few bytes of payload from |
| 4119 | * frags into skb->data |
| 4120 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4121 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4122 | /* |
| 4123 | * we do this workaround for ES2LAN, but it is un-necessary, |
| 4124 | * avoiding it could save a lot of cycles |
| 4125 | */ |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 4126 | if (skb->data_len && (hdr_len == len)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4127 | unsigned int pull_size; |
| 4128 | |
| 4129 | pull_size = min((unsigned int)4, skb->data_len); |
| 4130 | if (!__pskb_pull_tail(skb, pull_size)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4131 | e_err("__pskb_pull_tail failed.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4132 | dev_kfree_skb_any(skb); |
| 4133 | return NETDEV_TX_OK; |
| 4134 | } |
| 4135 | len = skb->len - skb->data_len; |
| 4136 | } |
| 4137 | } |
| 4138 | |
| 4139 | /* reserve a descriptor for the offload context */ |
| 4140 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 4141 | count++; |
| 4142 | count++; |
| 4143 | |
| 4144 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 4145 | |
| 4146 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 4147 | for (f = 0; f < nr_frags; f++) |
| 4148 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 4149 | max_txd_pwr); |
| 4150 | |
| 4151 | if (adapter->hw.mac.tx_pkt_filtering) |
| 4152 | e1000_transfer_dhcp_info(adapter, skb); |
| 4153 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4154 | /* |
| 4155 | * need: count + 2 desc gap to keep tail from touching |
| 4156 | * head, otherwise try next time |
| 4157 | */ |
Jesse Brandeburg | 92af3e9 | 2009-01-19 14:17:08 +0000 | [diff] [blame] | 4158 | if (e1000_maybe_stop_tx(netdev, count + 2)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4159 | return NETDEV_TX_BUSY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4160 | |
| 4161 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 4162 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 4163 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 4164 | } |
| 4165 | |
| 4166 | first = tx_ring->next_to_use; |
| 4167 | |
| 4168 | tso = e1000_tso(adapter, skb); |
| 4169 | if (tso < 0) { |
| 4170 | dev_kfree_skb_any(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4171 | return NETDEV_TX_OK; |
| 4172 | } |
| 4173 | |
| 4174 | if (tso) |
| 4175 | tx_flags |= E1000_TX_FLAGS_TSO; |
| 4176 | else if (e1000_tx_csum(adapter, skb)) |
| 4177 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 4178 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4179 | /* |
| 4180 | * 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] | 4181 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4182 | * no longer assume, we must. |
| 4183 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4184 | if (skb->protocol == htons(ETH_P_IP)) |
| 4185 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 4186 | |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4187 | /* if count is 0 then mapping error has occured */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4188 | count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4189 | if (count) { |
| 4190 | e1000_tx_queue(adapter, tx_flags, count); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4191 | /* Make sure there is space in the ring for the next send. */ |
| 4192 | e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2); |
| 4193 | |
| 4194 | } else { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4195 | dev_kfree_skb_any(skb); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4196 | tx_ring->buffer_info[first].time_stamp = 0; |
| 4197 | tx_ring->next_to_use = first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4198 | } |
| 4199 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4200 | return NETDEV_TX_OK; |
| 4201 | } |
| 4202 | |
| 4203 | /** |
| 4204 | * e1000_tx_timeout - Respond to a Tx Hang |
| 4205 | * @netdev: network interface device structure |
| 4206 | **/ |
| 4207 | static void e1000_tx_timeout(struct net_device *netdev) |
| 4208 | { |
| 4209 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4210 | |
| 4211 | /* Do the reset outside of interrupt context */ |
| 4212 | adapter->tx_timeout_count++; |
| 4213 | schedule_work(&adapter->reset_task); |
| 4214 | } |
| 4215 | |
| 4216 | static void e1000_reset_task(struct work_struct *work) |
| 4217 | { |
| 4218 | struct e1000_adapter *adapter; |
| 4219 | adapter = container_of(work, struct e1000_adapter, reset_task); |
| 4220 | |
| 4221 | e1000e_reinit_locked(adapter); |
| 4222 | } |
| 4223 | |
| 4224 | /** |
| 4225 | * e1000_get_stats - Get System Network Statistics |
| 4226 | * @netdev: network interface device structure |
| 4227 | * |
| 4228 | * Returns the address of the device statistics structure. |
| 4229 | * The statistics are actually updated from the timer callback. |
| 4230 | **/ |
| 4231 | static struct net_device_stats *e1000_get_stats(struct net_device *netdev) |
| 4232 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4233 | /* only return the current stats */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4234 | return &netdev->stats; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4235 | } |
| 4236 | |
| 4237 | /** |
| 4238 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 4239 | * @netdev: network interface device structure |
| 4240 | * @new_mtu: new value for maximum frame size |
| 4241 | * |
| 4242 | * Returns 0 on success, negative on failure |
| 4243 | **/ |
| 4244 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 4245 | { |
| 4246 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4247 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4248 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 4249 | /* Jumbo frame support */ |
| 4250 | if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) && |
| 4251 | !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
| 4252 | e_err("Jumbo Frames not supported.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4253 | return -EINVAL; |
| 4254 | } |
| 4255 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 4256 | /* Supported frame sizes */ |
| 4257 | if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) || |
| 4258 | (max_frame > adapter->max_hw_frame_size)) { |
| 4259 | e_err("Unsupported MTU setting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4260 | return -EINVAL; |
| 4261 | } |
| 4262 | |
| 4263 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
| 4264 | msleep(1); |
| 4265 | /* e1000e_down has a dependency on max_frame_size */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4266 | adapter->max_frame_size = max_frame; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4267 | if (netif_running(netdev)) |
| 4268 | e1000e_down(adapter); |
| 4269 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4270 | /* |
| 4271 | * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4272 | * means we reserve 2 more, this pushes us to allocate from the next |
| 4273 | * larger slab size. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4274 | * i.e. RXBUFFER_2048 --> size-4096 slab |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 4275 | * However with the new *_jumbo_rx* routines, jumbo receives will use |
| 4276 | * fragmented skbs |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4277 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4278 | |
| 4279 | if (max_frame <= 256) |
| 4280 | adapter->rx_buffer_len = 256; |
| 4281 | else if (max_frame <= 512) |
| 4282 | adapter->rx_buffer_len = 512; |
| 4283 | else if (max_frame <= 1024) |
| 4284 | adapter->rx_buffer_len = 1024; |
| 4285 | else if (max_frame <= 2048) |
| 4286 | adapter->rx_buffer_len = 2048; |
| 4287 | else |
| 4288 | adapter->rx_buffer_len = 4096; |
| 4289 | |
| 4290 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
| 4291 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || |
| 4292 | (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) |
| 4293 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4294 | + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4295 | |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4296 | e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4297 | netdev->mtu = new_mtu; |
| 4298 | |
| 4299 | if (netif_running(netdev)) |
| 4300 | e1000e_up(adapter); |
| 4301 | else |
| 4302 | e1000e_reset(adapter); |
| 4303 | |
| 4304 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 4305 | |
| 4306 | return 0; |
| 4307 | } |
| 4308 | |
| 4309 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 4310 | int cmd) |
| 4311 | { |
| 4312 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4313 | struct mii_ioctl_data *data = if_mii(ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4314 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4315 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4316 | return -EOPNOTSUPP; |
| 4317 | |
| 4318 | switch (cmd) { |
| 4319 | case SIOCGMIIPHY: |
| 4320 | data->phy_id = adapter->hw.phy.addr; |
| 4321 | break; |
| 4322 | case SIOCGMIIREG: |
Bruce Allan | b16a002 | 2009-11-20 23:24:30 +0000 | [diff] [blame^] | 4323 | e1000_phy_read_status(adapter); |
| 4324 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4325 | switch (data->reg_num & 0x1F) { |
| 4326 | case MII_BMCR: |
| 4327 | data->val_out = adapter->phy_regs.bmcr; |
| 4328 | break; |
| 4329 | case MII_BMSR: |
| 4330 | data->val_out = adapter->phy_regs.bmsr; |
| 4331 | break; |
| 4332 | case MII_PHYSID1: |
| 4333 | data->val_out = (adapter->hw.phy.id >> 16); |
| 4334 | break; |
| 4335 | case MII_PHYSID2: |
| 4336 | data->val_out = (adapter->hw.phy.id & 0xFFFF); |
| 4337 | break; |
| 4338 | case MII_ADVERTISE: |
| 4339 | data->val_out = adapter->phy_regs.advertise; |
| 4340 | break; |
| 4341 | case MII_LPA: |
| 4342 | data->val_out = adapter->phy_regs.lpa; |
| 4343 | break; |
| 4344 | case MII_EXPANSION: |
| 4345 | data->val_out = adapter->phy_regs.expansion; |
| 4346 | break; |
| 4347 | case MII_CTRL1000: |
| 4348 | data->val_out = adapter->phy_regs.ctrl1000; |
| 4349 | break; |
| 4350 | case MII_STAT1000: |
| 4351 | data->val_out = adapter->phy_regs.stat1000; |
| 4352 | break; |
| 4353 | case MII_ESTATUS: |
| 4354 | data->val_out = adapter->phy_regs.estatus; |
| 4355 | break; |
| 4356 | default: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4357 | return -EIO; |
| 4358 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4359 | break; |
| 4360 | case SIOCSMIIREG: |
| 4361 | default: |
| 4362 | return -EOPNOTSUPP; |
| 4363 | } |
| 4364 | return 0; |
| 4365 | } |
| 4366 | |
| 4367 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4368 | { |
| 4369 | switch (cmd) { |
| 4370 | case SIOCGMIIPHY: |
| 4371 | case SIOCGMIIREG: |
| 4372 | case SIOCSMIIREG: |
| 4373 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 4374 | default: |
| 4375 | return -EOPNOTSUPP; |
| 4376 | } |
| 4377 | } |
| 4378 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4379 | static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) |
| 4380 | { |
| 4381 | struct e1000_hw *hw = &adapter->hw; |
| 4382 | u32 i, mac_reg; |
| 4383 | u16 phy_reg; |
| 4384 | int retval = 0; |
| 4385 | |
| 4386 | /* copy MAC RARs to PHY RARs */ |
| 4387 | for (i = 0; i < adapter->hw.mac.rar_entry_count; i++) { |
| 4388 | mac_reg = er32(RAL(i)); |
| 4389 | e1e_wphy(hw, BM_RAR_L(i), (u16)(mac_reg & 0xFFFF)); |
| 4390 | e1e_wphy(hw, BM_RAR_M(i), (u16)((mac_reg >> 16) & 0xFFFF)); |
| 4391 | mac_reg = er32(RAH(i)); |
| 4392 | e1e_wphy(hw, BM_RAR_H(i), (u16)(mac_reg & 0xFFFF)); |
| 4393 | e1e_wphy(hw, BM_RAR_CTRL(i), (u16)((mac_reg >> 16) & 0xFFFF)); |
| 4394 | } |
| 4395 | |
| 4396 | /* copy MAC MTA to PHY MTA */ |
| 4397 | for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { |
| 4398 | mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); |
| 4399 | e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF)); |
| 4400 | e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF)); |
| 4401 | } |
| 4402 | |
| 4403 | /* configure PHY Rx Control register */ |
| 4404 | e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg); |
| 4405 | mac_reg = er32(RCTL); |
| 4406 | if (mac_reg & E1000_RCTL_UPE) |
| 4407 | phy_reg |= BM_RCTL_UPE; |
| 4408 | if (mac_reg & E1000_RCTL_MPE) |
| 4409 | phy_reg |= BM_RCTL_MPE; |
| 4410 | phy_reg &= ~(BM_RCTL_MO_MASK); |
| 4411 | if (mac_reg & E1000_RCTL_MO_3) |
| 4412 | phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) |
| 4413 | << BM_RCTL_MO_SHIFT); |
| 4414 | if (mac_reg & E1000_RCTL_BAM) |
| 4415 | phy_reg |= BM_RCTL_BAM; |
| 4416 | if (mac_reg & E1000_RCTL_PMCF) |
| 4417 | phy_reg |= BM_RCTL_PMCF; |
| 4418 | mac_reg = er32(CTRL); |
| 4419 | if (mac_reg & E1000_CTRL_RFCE) |
| 4420 | phy_reg |= BM_RCTL_RFCE; |
| 4421 | e1e_wphy(&adapter->hw, BM_RCTL, phy_reg); |
| 4422 | |
| 4423 | /* enable PHY wakeup in MAC register */ |
| 4424 | ew32(WUFC, wufc); |
| 4425 | ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN); |
| 4426 | |
| 4427 | /* configure and enable PHY wakeup in PHY registers */ |
| 4428 | e1e_wphy(&adapter->hw, BM_WUFC, wufc); |
| 4429 | e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN); |
| 4430 | |
| 4431 | /* activate PHY wakeup */ |
| 4432 | retval = hw->phy.ops.acquire_phy(hw); |
| 4433 | if (retval) { |
| 4434 | e_err("Could not acquire PHY\n"); |
| 4435 | return retval; |
| 4436 | } |
| 4437 | e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 4438 | (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT)); |
| 4439 | retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg); |
| 4440 | if (retval) { |
| 4441 | e_err("Could not read PHY page 769\n"); |
| 4442 | goto out; |
| 4443 | } |
| 4444 | phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; |
| 4445 | retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg); |
| 4446 | if (retval) |
| 4447 | e_err("Could not set PHY Host Wakeup bit\n"); |
| 4448 | out: |
| 4449 | hw->phy.ops.release_phy(hw); |
| 4450 | |
| 4451 | return retval; |
| 4452 | } |
| 4453 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 4454 | static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4455 | { |
| 4456 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4457 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4458 | struct e1000_hw *hw = &adapter->hw; |
| 4459 | u32 ctrl, ctrl_ext, rctl, status; |
| 4460 | u32 wufc = adapter->wol; |
| 4461 | int retval = 0; |
| 4462 | |
| 4463 | netif_device_detach(netdev); |
| 4464 | |
| 4465 | if (netif_running(netdev)) { |
| 4466 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 4467 | e1000e_down(adapter); |
| 4468 | e1000_free_irq(adapter); |
| 4469 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4470 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4471 | |
| 4472 | retval = pci_save_state(pdev); |
| 4473 | if (retval) |
| 4474 | return retval; |
| 4475 | |
| 4476 | status = er32(STATUS); |
| 4477 | if (status & E1000_STATUS_LU) |
| 4478 | wufc &= ~E1000_WUFC_LNKC; |
| 4479 | |
| 4480 | if (wufc) { |
| 4481 | e1000_setup_rctl(adapter); |
| 4482 | e1000_set_multi(netdev); |
| 4483 | |
| 4484 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 4485 | if (wufc & E1000_WUFC_MC) { |
| 4486 | rctl = er32(RCTL); |
| 4487 | rctl |= E1000_RCTL_MPE; |
| 4488 | ew32(RCTL, rctl); |
| 4489 | } |
| 4490 | |
| 4491 | ctrl = er32(CTRL); |
| 4492 | /* advertise wake from D3Cold */ |
| 4493 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 4494 | /* phy power management enable */ |
| 4495 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4496 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 4497 | if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) |
| 4498 | ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4499 | ew32(CTRL, ctrl); |
| 4500 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4501 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
| 4502 | adapter->hw.phy.media_type == |
| 4503 | e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4504 | /* keep the laser running in D3 */ |
| 4505 | ctrl_ext = er32(CTRL_EXT); |
| 4506 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
| 4507 | ew32(CTRL_EXT, ctrl_ext); |
| 4508 | } |
| 4509 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 4510 | if (adapter->flags & FLAG_IS_ICH) |
| 4511 | e1000e_disable_gig_wol_ich8lan(&adapter->hw); |
| 4512 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4513 | /* Allow time for pending master requests to run */ |
| 4514 | e1000e_disable_pcie_master(&adapter->hw); |
| 4515 | |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 4516 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4517 | /* enable wakeup by the PHY */ |
| 4518 | retval = e1000_init_phy_wakeup(adapter, wufc); |
| 4519 | if (retval) |
| 4520 | return retval; |
| 4521 | } else { |
| 4522 | /* enable wakeup by the MAC */ |
| 4523 | ew32(WUFC, wufc); |
| 4524 | ew32(WUC, E1000_WUC_PME_EN); |
| 4525 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4526 | } else { |
| 4527 | ew32(WUC, 0); |
| 4528 | ew32(WUFC, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4529 | } |
| 4530 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 4531 | *enable_wake = !!wufc; |
| 4532 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4533 | /* make sure adapter isn't asleep if manageability is enabled */ |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 4534 | if ((adapter->flags & FLAG_MNG_PT_ENABLED) || |
| 4535 | (hw->mac.ops.check_mng_mode(hw))) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 4536 | *enable_wake = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4537 | |
| 4538 | if (adapter->hw.phy.type == e1000_phy_igp_3) |
| 4539 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
| 4540 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4541 | /* |
| 4542 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 4543 | * would have already happened in close and is redundant. |
| 4544 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4545 | e1000_release_hw_control(adapter); |
| 4546 | |
| 4547 | pci_disable_device(pdev); |
| 4548 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 4549 | return 0; |
| 4550 | } |
| 4551 | |
| 4552 | static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake) |
| 4553 | { |
| 4554 | if (sleep && wake) { |
| 4555 | pci_prepare_to_sleep(pdev); |
| 4556 | return; |
| 4557 | } |
| 4558 | |
| 4559 | pci_wake_from_d3(pdev, wake); |
| 4560 | pci_set_power_state(pdev, PCI_D3hot); |
| 4561 | } |
| 4562 | |
| 4563 | static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, |
| 4564 | bool wake) |
| 4565 | { |
| 4566 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4567 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4568 | |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 4569 | /* |
| 4570 | * The pci-e switch on some quad port adapters will report a |
| 4571 | * correctable error when the MAC transitions from D0 to D3. To |
| 4572 | * prevent this we need to mask off the correctable errors on the |
| 4573 | * downstream port of the pci-e switch. |
| 4574 | */ |
| 4575 | if (adapter->flags & FLAG_IS_QUAD_PORT) { |
| 4576 | struct pci_dev *us_dev = pdev->bus->self; |
| 4577 | int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP); |
| 4578 | u16 devctl; |
| 4579 | |
| 4580 | pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl); |
| 4581 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, |
| 4582 | (devctl & ~PCI_EXP_DEVCTL_CERE)); |
| 4583 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 4584 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 4585 | |
| 4586 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl); |
| 4587 | } else { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 4588 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 4589 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4590 | } |
| 4591 | |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 4592 | static void e1000e_disable_l1aspm(struct pci_dev *pdev) |
| 4593 | { |
| 4594 | int pos; |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 4595 | u16 val; |
| 4596 | |
| 4597 | /* |
| 4598 | * 82573 workaround - disable L1 ASPM on mobile chipsets |
| 4599 | * |
| 4600 | * L1 ASPM on various mobile (ich7) chipsets do not behave properly |
| 4601 | * resulting in lost data or garbage information on the pci-e link |
| 4602 | * level. This could result in (false) bad EEPROM checksum errors, |
| 4603 | * long ping times (up to 2s) or even a system freeze/hang. |
| 4604 | * |
| 4605 | * Unfortunately this feature saves about 1W power consumption when |
| 4606 | * active. |
| 4607 | */ |
| 4608 | pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 4609 | pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &val); |
| 4610 | if (val & 0x2) { |
| 4611 | dev_warn(&pdev->dev, "Disabling L1 ASPM\n"); |
| 4612 | val &= ~0x2; |
| 4613 | pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, val); |
| 4614 | } |
| 4615 | } |
| 4616 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4617 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 4618 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4619 | { |
| 4620 | int retval; |
| 4621 | bool wake; |
| 4622 | |
| 4623 | retval = __e1000_shutdown(pdev, &wake); |
| 4624 | if (!retval) |
| 4625 | e1000_complete_shutdown(pdev, true, wake); |
| 4626 | |
| 4627 | return retval; |
| 4628 | } |
| 4629 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4630 | static int e1000_resume(struct pci_dev *pdev) |
| 4631 | { |
| 4632 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4633 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4634 | struct e1000_hw *hw = &adapter->hw; |
| 4635 | u32 err; |
| 4636 | |
| 4637 | pci_set_power_state(pdev, PCI_D0); |
| 4638 | pci_restore_state(pdev); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 4639 | e1000e_disable_l1aspm(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 4640 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 4641 | err = pci_enable_device_mem(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4642 | if (err) { |
| 4643 | dev_err(&pdev->dev, |
| 4644 | "Cannot enable PCI device from suspend\n"); |
| 4645 | return err; |
| 4646 | } |
| 4647 | |
| 4648 | pci_set_master(pdev); |
| 4649 | |
| 4650 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 4651 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 4652 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4653 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4654 | if (netif_running(netdev)) { |
| 4655 | err = e1000_request_irq(adapter); |
| 4656 | if (err) |
| 4657 | return err; |
| 4658 | } |
| 4659 | |
| 4660 | e1000e_power_up_phy(adapter); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4661 | |
| 4662 | /* report the system wakeup cause from S3/S4 */ |
| 4663 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
| 4664 | u16 phy_data; |
| 4665 | |
| 4666 | e1e_rphy(&adapter->hw, BM_WUS, &phy_data); |
| 4667 | if (phy_data) { |
| 4668 | e_info("PHY Wakeup cause - %s\n", |
| 4669 | phy_data & E1000_WUS_EX ? "Unicast Packet" : |
| 4670 | phy_data & E1000_WUS_MC ? "Multicast Packet" : |
| 4671 | phy_data & E1000_WUS_BC ? "Broadcast Packet" : |
| 4672 | phy_data & E1000_WUS_MAG ? "Magic Packet" : |
| 4673 | phy_data & E1000_WUS_LNKC ? "Link Status " |
| 4674 | " Change" : "other"); |
| 4675 | } |
| 4676 | e1e_wphy(&adapter->hw, BM_WUS, ~0); |
| 4677 | } else { |
| 4678 | u32 wus = er32(WUS); |
| 4679 | if (wus) { |
| 4680 | e_info("MAC Wakeup cause - %s\n", |
| 4681 | wus & E1000_WUS_EX ? "Unicast Packet" : |
| 4682 | wus & E1000_WUS_MC ? "Multicast Packet" : |
| 4683 | wus & E1000_WUS_BC ? "Broadcast Packet" : |
| 4684 | wus & E1000_WUS_MAG ? "Magic Packet" : |
| 4685 | wus & E1000_WUS_LNKC ? "Link Status Change" : |
| 4686 | "other"); |
| 4687 | } |
| 4688 | ew32(WUS, ~0); |
| 4689 | } |
| 4690 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4691 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4692 | |
| 4693 | e1000_init_manageability(adapter); |
| 4694 | |
| 4695 | if (netif_running(netdev)) |
| 4696 | e1000e_up(adapter); |
| 4697 | |
| 4698 | netif_device_attach(netdev); |
| 4699 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4700 | /* |
| 4701 | * 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] | 4702 | * 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] | 4703 | * under the control of the driver. |
| 4704 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 4705 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4706 | e1000_get_hw_control(adapter); |
| 4707 | |
| 4708 | return 0; |
| 4709 | } |
| 4710 | #endif |
| 4711 | |
| 4712 | static void e1000_shutdown(struct pci_dev *pdev) |
| 4713 | { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 4714 | bool wake = false; |
| 4715 | |
| 4716 | __e1000_shutdown(pdev, &wake); |
| 4717 | |
| 4718 | if (system_state == SYSTEM_POWER_OFF) |
| 4719 | e1000_complete_shutdown(pdev, false, wake); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4723 | /* |
| 4724 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 4725 | * without having to re-enable interrupts. It's not called while |
| 4726 | * the interrupt routine is executing. |
| 4727 | */ |
| 4728 | static void e1000_netpoll(struct net_device *netdev) |
| 4729 | { |
| 4730 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4731 | |
| 4732 | disable_irq(adapter->pdev->irq); |
| 4733 | e1000_intr(adapter->pdev->irq, netdev); |
| 4734 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4735 | enable_irq(adapter->pdev->irq); |
| 4736 | } |
| 4737 | #endif |
| 4738 | |
| 4739 | /** |
| 4740 | * e1000_io_error_detected - called when PCI error is detected |
| 4741 | * @pdev: Pointer to PCI device |
| 4742 | * @state: The current pci connection state |
| 4743 | * |
| 4744 | * This function is called after a PCI bus error affecting |
| 4745 | * this device has been detected. |
| 4746 | */ |
| 4747 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 4748 | pci_channel_state_t state) |
| 4749 | { |
| 4750 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4751 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4752 | |
| 4753 | netif_device_detach(netdev); |
| 4754 | |
Mike Mason | c93b5a7 | 2009-06-30 12:45:53 +0000 | [diff] [blame] | 4755 | if (state == pci_channel_io_perm_failure) |
| 4756 | return PCI_ERS_RESULT_DISCONNECT; |
| 4757 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4758 | if (netif_running(netdev)) |
| 4759 | e1000e_down(adapter); |
| 4760 | pci_disable_device(pdev); |
| 4761 | |
| 4762 | /* Request a slot slot reset. */ |
| 4763 | return PCI_ERS_RESULT_NEED_RESET; |
| 4764 | } |
| 4765 | |
| 4766 | /** |
| 4767 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 4768 | * @pdev: Pointer to PCI device |
| 4769 | * |
| 4770 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 4771 | * resembles the first-half of the e1000_resume routine. |
| 4772 | */ |
| 4773 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 4774 | { |
| 4775 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4776 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4777 | struct e1000_hw *hw = &adapter->hw; |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 4778 | int err; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 4779 | pci_ers_result_t result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4780 | |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 4781 | e1000e_disable_l1aspm(pdev); |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 4782 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 4783 | if (err) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4784 | dev_err(&pdev->dev, |
| 4785 | "Cannot re-enable PCI device after reset.\n"); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 4786 | result = PCI_ERS_RESULT_DISCONNECT; |
| 4787 | } else { |
| 4788 | pci_set_master(pdev); |
| 4789 | pci_restore_state(pdev); |
| 4790 | |
| 4791 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 4792 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 4793 | |
| 4794 | e1000e_reset(adapter); |
| 4795 | ew32(WUS, ~0); |
| 4796 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4797 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4798 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 4799 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4800 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 4801 | return result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4802 | } |
| 4803 | |
| 4804 | /** |
| 4805 | * e1000_io_resume - called when traffic can start flowing again. |
| 4806 | * @pdev: Pointer to PCI device |
| 4807 | * |
| 4808 | * This callback is called when the error recovery driver tells us that |
| 4809 | * its OK to resume normal operation. Implementation resembles the |
| 4810 | * second-half of the e1000_resume routine. |
| 4811 | */ |
| 4812 | static void e1000_io_resume(struct pci_dev *pdev) |
| 4813 | { |
| 4814 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4815 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4816 | |
| 4817 | e1000_init_manageability(adapter); |
| 4818 | |
| 4819 | if (netif_running(netdev)) { |
| 4820 | if (e1000e_up(adapter)) { |
| 4821 | dev_err(&pdev->dev, |
| 4822 | "can't bring device back up after reset\n"); |
| 4823 | return; |
| 4824 | } |
| 4825 | } |
| 4826 | |
| 4827 | netif_device_attach(netdev); |
| 4828 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4829 | /* |
| 4830 | * 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] | 4831 | * 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] | 4832 | * under the control of the driver. |
| 4833 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 4834 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4835 | e1000_get_hw_control(adapter); |
| 4836 | |
| 4837 | } |
| 4838 | |
| 4839 | static void e1000_print_device_info(struct e1000_adapter *adapter) |
| 4840 | { |
| 4841 | struct e1000_hw *hw = &adapter->hw; |
| 4842 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 4843 | u32 pba_num; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4844 | |
| 4845 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 4846 | e_info("(PCI Express:2.5GB/s:%s) %pM\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4847 | /* bus width */ |
| 4848 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
| 4849 | "Width x1"), |
| 4850 | /* MAC address */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 4851 | netdev->dev_addr); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4852 | e_info("Intel(R) PRO/%s Network Connection\n", |
| 4853 | (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 4854 | e1000e_read_pba_num(hw, &pba_num); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4855 | e_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
| 4856 | hw->mac.type, hw->phy.type, (pba_num >> 8), (pba_num & 0xff)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4857 | } |
| 4858 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 4859 | static void e1000_eeprom_checks(struct e1000_adapter *adapter) |
| 4860 | { |
| 4861 | struct e1000_hw *hw = &adapter->hw; |
| 4862 | int ret_val; |
| 4863 | u16 buf = 0; |
| 4864 | |
| 4865 | if (hw->mac.type != e1000_82573) |
| 4866 | return; |
| 4867 | |
| 4868 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 4869 | if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) { |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 4870 | /* Deep Smart Power Down (DSPD) */ |
Frans Pop | 6c2a9ef | 2008-09-22 14:52:22 -0700 | [diff] [blame] | 4871 | dev_warn(&adapter->pdev->dev, |
| 4872 | "Warning: detected DSPD enabled in EEPROM\n"); |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | ret_val = e1000_read_nvm(hw, NVM_INIT_3GIO_3, 1, &buf); |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 4876 | if (!ret_val && (le16_to_cpu(buf) & (3 << 2))) { |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 4877 | /* ASPM enable */ |
Frans Pop | 6c2a9ef | 2008-09-22 14:52:22 -0700 | [diff] [blame] | 4878 | dev_warn(&adapter->pdev->dev, |
| 4879 | "Warning: detected ASPM enabled in EEPROM\n"); |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 4880 | } |
| 4881 | } |
| 4882 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 4883 | static const struct net_device_ops e1000e_netdev_ops = { |
| 4884 | .ndo_open = e1000_open, |
| 4885 | .ndo_stop = e1000_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4886 | .ndo_start_xmit = e1000_xmit_frame, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 4887 | .ndo_get_stats = e1000_get_stats, |
| 4888 | .ndo_set_multicast_list = e1000_set_multi, |
| 4889 | .ndo_set_mac_address = e1000_set_mac, |
| 4890 | .ndo_change_mtu = e1000_change_mtu, |
| 4891 | .ndo_do_ioctl = e1000_ioctl, |
| 4892 | .ndo_tx_timeout = e1000_tx_timeout, |
| 4893 | .ndo_validate_addr = eth_validate_addr, |
| 4894 | |
| 4895 | .ndo_vlan_rx_register = e1000_vlan_rx_register, |
| 4896 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 4897 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 4898 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4899 | .ndo_poll_controller = e1000_netpoll, |
| 4900 | #endif |
| 4901 | }; |
| 4902 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4903 | /** |
| 4904 | * e1000_probe - Device Initialization Routine |
| 4905 | * @pdev: PCI device information struct |
| 4906 | * @ent: entry in e1000_pci_tbl |
| 4907 | * |
| 4908 | * Returns 0 on success, negative on failure |
| 4909 | * |
| 4910 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 4911 | * The OS initialization, configuring of the adapter private structure, |
| 4912 | * and a hardware reset occur. |
| 4913 | **/ |
| 4914 | static int __devinit e1000_probe(struct pci_dev *pdev, |
| 4915 | const struct pci_device_id *ent) |
| 4916 | { |
| 4917 | struct net_device *netdev; |
| 4918 | struct e1000_adapter *adapter; |
| 4919 | struct e1000_hw *hw; |
| 4920 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; |
Becky Bruce | f47e81f | 2008-05-01 18:03:11 -0500 | [diff] [blame] | 4921 | resource_size_t mmio_start, mmio_len; |
| 4922 | resource_size_t flash_start, flash_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4923 | |
| 4924 | static int cards_found; |
| 4925 | int i, err, pci_using_dac; |
| 4926 | u16 eeprom_data = 0; |
| 4927 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
| 4928 | |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 4929 | e1000e_disable_l1aspm(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 4930 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 4931 | err = pci_enable_device_mem(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4932 | if (err) |
| 4933 | return err; |
| 4934 | |
| 4935 | pci_using_dac = 0; |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 4936 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4937 | if (!err) { |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 4938 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4939 | if (!err) |
| 4940 | pci_using_dac = 1; |
| 4941 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4942 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4943 | if (err) { |
| 4944 | err = pci_set_consistent_dma_mask(pdev, |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4945 | DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4946 | if (err) { |
| 4947 | dev_err(&pdev->dev, "No usable DMA " |
| 4948 | "configuration, aborting\n"); |
| 4949 | goto err_dma; |
| 4950 | } |
| 4951 | } |
| 4952 | } |
| 4953 | |
Arjan van de Ven | e8de148 | 2008-10-22 19:55:31 -0700 | [diff] [blame] | 4954 | err = pci_request_selected_regions_exclusive(pdev, |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 4955 | pci_select_bars(pdev, IORESOURCE_MEM), |
| 4956 | e1000e_driver_name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4957 | if (err) |
| 4958 | goto err_pci_reg; |
| 4959 | |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 4960 | /* AER (Advanced Error Reporting) hooks */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 4961 | pci_enable_pcie_error_reporting(pdev); |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 4962 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4963 | pci_set_master(pdev); |
Bruce Allan | 438b365 | 2008-11-21 16:51:33 -0800 | [diff] [blame] | 4964 | /* PCI config space info */ |
| 4965 | err = pci_save_state(pdev); |
| 4966 | if (err) |
| 4967 | goto err_alloc_etherdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4968 | |
| 4969 | err = -ENOMEM; |
| 4970 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
| 4971 | if (!netdev) |
| 4972 | goto err_alloc_etherdev; |
| 4973 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4974 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 4975 | |
| 4976 | pci_set_drvdata(pdev, netdev); |
| 4977 | adapter = netdev_priv(netdev); |
| 4978 | hw = &adapter->hw; |
| 4979 | adapter->netdev = netdev; |
| 4980 | adapter->pdev = pdev; |
| 4981 | adapter->ei = ei; |
| 4982 | adapter->pba = ei->pba; |
| 4983 | adapter->flags = ei->flags; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 4984 | adapter->flags2 = ei->flags2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4985 | adapter->hw.adapter = adapter; |
| 4986 | adapter->hw.mac.type = ei->mac; |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 4987 | adapter->max_hw_frame_size = ei->max_hw_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4988 | adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; |
| 4989 | |
| 4990 | mmio_start = pci_resource_start(pdev, 0); |
| 4991 | mmio_len = pci_resource_len(pdev, 0); |
| 4992 | |
| 4993 | err = -EIO; |
| 4994 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 4995 | if (!adapter->hw.hw_addr) |
| 4996 | goto err_ioremap; |
| 4997 | |
| 4998 | if ((adapter->flags & FLAG_HAS_FLASH) && |
| 4999 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
| 5000 | flash_start = pci_resource_start(pdev, 1); |
| 5001 | flash_len = pci_resource_len(pdev, 1); |
| 5002 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
| 5003 | if (!adapter->hw.flash_address) |
| 5004 | goto err_flashmap; |
| 5005 | } |
| 5006 | |
| 5007 | /* construct the net_device struct */ |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5008 | netdev->netdev_ops = &e1000e_netdev_ops; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5009 | e1000e_set_ethtool_ops(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5010 | netdev->watchdog_timeo = 5 * HZ; |
| 5011 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5012 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
| 5013 | |
| 5014 | netdev->mem_start = mmio_start; |
| 5015 | netdev->mem_end = mmio_start + mmio_len; |
| 5016 | |
| 5017 | adapter->bd_number = cards_found++; |
| 5018 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5019 | e1000e_check_options(adapter); |
| 5020 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5021 | /* setup adapter struct */ |
| 5022 | err = e1000_sw_init(adapter); |
| 5023 | if (err) |
| 5024 | goto err_sw_init; |
| 5025 | |
| 5026 | err = -EIO; |
| 5027 | |
| 5028 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 5029 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 5030 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 5031 | |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 5032 | err = ei->get_variants(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5033 | if (err) |
| 5034 | goto err_hw_init; |
| 5035 | |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 5036 | if ((adapter->flags & FLAG_IS_ICH) && |
| 5037 | (adapter->flags & FLAG_READ_ONLY_NVM)) |
| 5038 | e1000e_write_protect_nvm_ich8lan(&adapter->hw); |
| 5039 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5040 | hw->mac.ops.get_bus_info(&adapter->hw); |
| 5041 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5042 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5043 | |
| 5044 | /* Copper options */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5045 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5046 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
| 5047 | adapter->hw.phy.disable_polarity_correction = 0; |
| 5048 | adapter->hw.phy.ms_type = e1000_ms_hw_default; |
| 5049 | } |
| 5050 | |
| 5051 | if (e1000_check_reset_block(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5052 | e_info("PHY reset is blocked due to SOL/IDER session.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5053 | |
| 5054 | netdev->features = NETIF_F_SG | |
| 5055 | NETIF_F_HW_CSUM | |
| 5056 | NETIF_F_HW_VLAN_TX | |
| 5057 | NETIF_F_HW_VLAN_RX; |
| 5058 | |
| 5059 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
| 5060 | netdev->features |= NETIF_F_HW_VLAN_FILTER; |
| 5061 | |
| 5062 | netdev->features |= NETIF_F_TSO; |
| 5063 | netdev->features |= NETIF_F_TSO6; |
| 5064 | |
Jeff Kirsher | a5136e2 | 2008-06-05 04:07:28 -0700 | [diff] [blame] | 5065 | netdev->vlan_features |= NETIF_F_TSO; |
| 5066 | netdev->vlan_features |= NETIF_F_TSO6; |
| 5067 | netdev->vlan_features |= NETIF_F_HW_CSUM; |
| 5068 | netdev->vlan_features |= NETIF_F_SG; |
| 5069 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5070 | if (pci_using_dac) |
| 5071 | netdev->features |= NETIF_F_HIGHDMA; |
| 5072 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5073 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
| 5074 | adapter->flags |= FLAG_MNG_PT_ENABLED; |
| 5075 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5076 | /* |
| 5077 | * before reading the NVM, reset the controller to |
| 5078 | * put the device in a known good starting state |
| 5079 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5080 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 5081 | |
| 5082 | /* |
| 5083 | * systems with ASPM and others may see the checksum fail on the first |
| 5084 | * attempt. Let's give it a few tries |
| 5085 | */ |
| 5086 | for (i = 0;; i++) { |
| 5087 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) |
| 5088 | break; |
| 5089 | if (i == 2) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5090 | e_err("The NVM Checksum Is Not Valid\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5091 | err = -EIO; |
| 5092 | goto err_eeprom; |
| 5093 | } |
| 5094 | } |
| 5095 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5096 | e1000_eeprom_checks(adapter); |
| 5097 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5098 | /* copy the MAC address out of the NVM */ |
| 5099 | if (e1000e_read_mac_addr(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5100 | e_err("NVM Read Error while reading MAC address\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5101 | |
| 5102 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 5103 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 5104 | |
| 5105 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5106 | e_err("Invalid MAC Address: %pM\n", netdev->perm_addr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5107 | err = -EIO; |
| 5108 | goto err_eeprom; |
| 5109 | } |
| 5110 | |
| 5111 | init_timer(&adapter->watchdog_timer); |
| 5112 | adapter->watchdog_timer.function = &e1000_watchdog; |
| 5113 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 5114 | |
| 5115 | init_timer(&adapter->phy_info_timer); |
| 5116 | adapter->phy_info_timer.function = &e1000_update_phy_info; |
| 5117 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 5118 | |
| 5119 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
| 5120 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 5121 | INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); |
| 5122 | INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5123 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5124 | /* Initialize link parameters. User can change them with ethtool */ |
| 5125 | adapter->hw.mac.autoneg = 1; |
Auke Kok | 309af40 | 2007-10-05 15:22:02 -0700 | [diff] [blame] | 5126 | adapter->fc_autoneg = 1; |
Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 5127 | adapter->hw.fc.requested_mode = e1000_fc_default; |
| 5128 | adapter->hw.fc.current_mode = e1000_fc_default; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5129 | adapter->hw.phy.autoneg_advertised = 0x2f; |
| 5130 | |
| 5131 | /* ring size defaults */ |
| 5132 | adapter->rx_ring->count = 256; |
| 5133 | adapter->tx_ring->count = 256; |
| 5134 | |
| 5135 | /* |
| 5136 | * Initial Wake on LAN setting - If APM wake is enabled in |
| 5137 | * the EEPROM, enable the ACPI Magic Packet filter |
| 5138 | */ |
| 5139 | if (adapter->flags & FLAG_APME_IN_WUC) { |
| 5140 | /* APME bit in EEPROM is mapped to WUC.APME */ |
| 5141 | eeprom_data = er32(WUC); |
| 5142 | eeprom_apme_mask = E1000_WUC_APME; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5143 | if (eeprom_data & E1000_WUC_PHY_WAKE) |
| 5144 | adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5145 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
| 5146 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && |
| 5147 | (adapter->hw.bus.func == 1)) |
| 5148 | e1000_read_nvm(&adapter->hw, |
| 5149 | NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 5150 | else |
| 5151 | e1000_read_nvm(&adapter->hw, |
| 5152 | NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 5153 | } |
| 5154 | |
| 5155 | /* fetch WoL from EEPROM */ |
| 5156 | if (eeprom_data & eeprom_apme_mask) |
| 5157 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 5158 | |
| 5159 | /* |
| 5160 | * now that we have the eeprom settings, apply the special cases |
| 5161 | * where the eeprom may be wrong or the board simply won't support |
| 5162 | * wake on lan on a particular port |
| 5163 | */ |
| 5164 | if (!(adapter->flags & FLAG_HAS_WOL)) |
| 5165 | adapter->eeprom_wol = 0; |
| 5166 | |
| 5167 | /* initialize the wol settings based on the eeprom settings */ |
| 5168 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | 6ff6802 | 2008-11-12 09:52:32 +0000 | [diff] [blame] | 5169 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5170 | |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 5171 | /* save off EEPROM version number */ |
| 5172 | e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); |
| 5173 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5174 | /* reset the hardware with the new settings */ |
| 5175 | e1000e_reset(adapter); |
| 5176 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5177 | /* |
| 5178 | * 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] | 5179 | * 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] | 5180 | * under the control of the driver. |
| 5181 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5182 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5183 | e1000_get_hw_control(adapter); |
| 5184 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5185 | strcpy(netdev->name, "eth%d"); |
| 5186 | err = register_netdev(netdev); |
| 5187 | if (err) |
| 5188 | goto err_register; |
| 5189 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 5190 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 5191 | netif_carrier_off(netdev); |
| 5192 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5193 | e1000_print_device_info(adapter); |
| 5194 | |
| 5195 | return 0; |
| 5196 | |
| 5197 | err_register: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5198 | if (!(adapter->flags & FLAG_HAS_AMT)) |
| 5199 | e1000_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5200 | err_eeprom: |
| 5201 | if (!e1000_check_reset_block(&adapter->hw)) |
| 5202 | e1000_phy_hw_reset(&adapter->hw); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5203 | err_hw_init: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5204 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5205 | kfree(adapter->tx_ring); |
| 5206 | kfree(adapter->rx_ring); |
| 5207 | err_sw_init: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5208 | if (adapter->hw.flash_address) |
| 5209 | iounmap(adapter->hw.flash_address); |
Jeff Kirsher | e82f54b | 2008-11-14 06:45:07 +0000 | [diff] [blame] | 5210 | e1000e_reset_interrupt_capability(adapter); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5211 | err_flashmap: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5212 | iounmap(adapter->hw.hw_addr); |
| 5213 | err_ioremap: |
| 5214 | free_netdev(netdev); |
| 5215 | err_alloc_etherdev: |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 5216 | pci_release_selected_regions(pdev, |
| 5217 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5218 | err_pci_reg: |
| 5219 | err_dma: |
| 5220 | pci_disable_device(pdev); |
| 5221 | return err; |
| 5222 | } |
| 5223 | |
| 5224 | /** |
| 5225 | * e1000_remove - Device Removal Routine |
| 5226 | * @pdev: PCI device information struct |
| 5227 | * |
| 5228 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 5229 | * that it should release a PCI device. The could be caused by a |
| 5230 | * Hot-Plug event, or because the driver is going to be removed from |
| 5231 | * memory. |
| 5232 | **/ |
| 5233 | static void __devexit e1000_remove(struct pci_dev *pdev) |
| 5234 | { |
| 5235 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5236 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5237 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5238 | /* |
| 5239 | * flush_scheduled work may reschedule our watchdog task, so |
| 5240 | * explicitly disable watchdog tasks from being rescheduled |
| 5241 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5242 | set_bit(__E1000_DOWN, &adapter->state); |
| 5243 | del_timer_sync(&adapter->watchdog_timer); |
| 5244 | del_timer_sync(&adapter->phy_info_timer); |
| 5245 | |
| 5246 | flush_scheduled_work(); |
| 5247 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5248 | /* |
| 5249 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5250 | * would have already happened in close and is redundant. |
| 5251 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5252 | e1000_release_hw_control(adapter); |
| 5253 | |
| 5254 | unregister_netdev(netdev); |
| 5255 | |
| 5256 | if (!e1000_check_reset_block(&adapter->hw)) |
| 5257 | e1000_phy_hw_reset(&adapter->hw); |
| 5258 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5259 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5260 | kfree(adapter->tx_ring); |
| 5261 | kfree(adapter->rx_ring); |
| 5262 | |
| 5263 | iounmap(adapter->hw.hw_addr); |
| 5264 | if (adapter->hw.flash_address) |
| 5265 | iounmap(adapter->hw.flash_address); |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 5266 | pci_release_selected_regions(pdev, |
| 5267 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5268 | |
| 5269 | free_netdev(netdev); |
| 5270 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5271 | /* AER disable */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 5272 | pci_disable_pcie_error_reporting(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5273 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5274 | pci_disable_device(pdev); |
| 5275 | } |
| 5276 | |
| 5277 | /* PCI Error Recovery (ERS) */ |
| 5278 | static struct pci_error_handlers e1000_err_handler = { |
| 5279 | .error_detected = e1000_io_error_detected, |
| 5280 | .slot_reset = e1000_io_slot_reset, |
| 5281 | .resume = e1000_io_resume, |
| 5282 | }; |
| 5283 | |
| 5284 | static struct pci_device_id e1000_pci_tbl[] = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5285 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
| 5286 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, |
| 5287 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, |
| 5288 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 }, |
| 5289 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
| 5290 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, |
Auke Kok | 040babf | 2007-10-31 15:22:05 -0700 | [diff] [blame] | 5291 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
| 5292 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, |
| 5293 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5294 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5295 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
| 5296 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, |
| 5297 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, |
| 5298 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5299 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5300 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
| 5301 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, |
| 5302 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5303 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5304 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, |
Bruce Allan | bef28b1 | 2009-03-24 23:28:02 -0700 | [diff] [blame] | 5305 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 5306 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5307 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5308 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
| 5309 | board_80003es2lan }, |
| 5310 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), |
| 5311 | board_80003es2lan }, |
| 5312 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), |
| 5313 | board_80003es2lan }, |
| 5314 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), |
| 5315 | board_80003es2lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5316 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5317 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
| 5318 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, |
| 5319 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, |
| 5320 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, |
| 5321 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, |
| 5322 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, |
| 5323 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5324 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5325 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
| 5326 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, |
| 5327 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, |
| 5328 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, |
| 5329 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, |
Bruce Allan | 2f15f9d | 2008-08-26 18:36:36 -0700 | [diff] [blame] | 5330 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5331 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, |
| 5332 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, |
| 5333 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, |
| 5334 | |
| 5335 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, |
| 5336 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, |
| 5337 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5338 | |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 5339 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, |
| 5340 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, |
| 5341 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5342 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, |
| 5343 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, |
| 5344 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, |
| 5345 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, |
| 5346 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5347 | { } /* terminate list */ |
| 5348 | }; |
| 5349 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 5350 | |
| 5351 | /* PCI Device API Driver */ |
| 5352 | static struct pci_driver e1000_driver = { |
| 5353 | .name = e1000e_driver_name, |
| 5354 | .id_table = e1000_pci_tbl, |
| 5355 | .probe = e1000_probe, |
| 5356 | .remove = __devexit_p(e1000_remove), |
| 5357 | #ifdef CONFIG_PM |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5358 | /* Power Management Hooks */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5359 | .suspend = e1000_suspend, |
| 5360 | .resume = e1000_resume, |
| 5361 | #endif |
| 5362 | .shutdown = e1000_shutdown, |
| 5363 | .err_handler = &e1000_err_handler |
| 5364 | }; |
| 5365 | |
| 5366 | /** |
| 5367 | * e1000_init_module - Driver Registration Routine |
| 5368 | * |
| 5369 | * e1000_init_module is the first routine called when the driver is |
| 5370 | * loaded. All it does is register with the PCI subsystem. |
| 5371 | **/ |
| 5372 | static int __init e1000_init_module(void) |
| 5373 | { |
| 5374 | int ret; |
| 5375 | printk(KERN_INFO "%s: Intel(R) PRO/1000 Network Driver - %s\n", |
| 5376 | e1000e_driver_name, e1000e_driver_version); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5377 | printk(KERN_INFO "%s: Copyright (c) 1999-2008 Intel Corporation.\n", |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5378 | e1000e_driver_name); |
| 5379 | ret = pci_register_driver(&e1000_driver); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5380 | pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name, |
| 5381 | PM_QOS_DEFAULT_VALUE); |
| 5382 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5383 | return ret; |
| 5384 | } |
| 5385 | module_init(e1000_init_module); |
| 5386 | |
| 5387 | /** |
| 5388 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 5389 | * |
| 5390 | * e1000_exit_module is called just before the driver is removed |
| 5391 | * from memory. |
| 5392 | **/ |
| 5393 | static void __exit e1000_exit_module(void) |
| 5394 | { |
| 5395 | pci_unregister_driver(&e1000_driver); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5396 | pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, e1000e_driver_name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5397 | } |
| 5398 | module_exit(e1000_exit_module); |
| 5399 | |
| 5400 | |
| 5401 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 5402 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 5403 | MODULE_LICENSE("GPL"); |
| 5404 | MODULE_VERSION(DRV_VERSION); |
| 5405 | |
| 5406 | /* e1000_main.c */ |