Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel PRO/1000 Linux driver |
Bruce Allan | 0d6057e | 2011-01-04 01:16:44 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2011 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 | |
Bruce Allan | 8544b9f | 2010-03-24 12:55:30 +0000 | [diff] [blame] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 31 | #include <linux/module.h> |
| 32 | #include <linux/types.h> |
| 33 | #include <linux/init.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 34 | #include <linux/interrupt.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 35 | #include <linux/pci.h> |
| 36 | #include <linux/vmalloc.h> |
| 37 | #include <linux/pagemap.h> |
| 38 | #include <linux/delay.h> |
| 39 | #include <linux/netdevice.h> |
| 40 | #include <linux/tcp.h> |
| 41 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 43 | #include <net/checksum.h> |
| 44 | #include <net/ip6_checksum.h> |
| 45 | #include <linux/mii.h> |
| 46 | #include <linux/ethtool.h> |
| 47 | #include <linux/if_vlan.h> |
| 48 | #include <linux/cpu.h> |
| 49 | #include <linux/smp.h> |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 50 | #include <linux/pm_qos_params.h> |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 51 | #include <linux/pm_runtime.h> |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 52 | #include <linux/aer.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 53 | #include <linux/prefetch.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 54 | |
| 55 | #include "e1000.h" |
| 56 | |
Bruce Allan | c14c643 | 2010-06-16 13:28:34 +0000 | [diff] [blame] | 57 | #define DRV_EXTRAVERSION "-k2" |
| 58 | |
Bruce Allan | 70d279a | 2011-02-26 03:12:19 +0000 | [diff] [blame] | 59 | #define DRV_VERSION "1.3.10" DRV_EXTRAVERSION |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 60 | char e1000e_driver_name[] = "e1000e"; |
| 61 | const char e1000e_driver_version[] = DRV_VERSION; |
| 62 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 63 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state); |
| 64 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 65 | static const struct e1000_info *e1000_info_tbl[] = { |
| 66 | [board_82571] = &e1000_82571_info, |
| 67 | [board_82572] = &e1000_82572_info, |
| 68 | [board_82573] = &e1000_82573_info, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 69 | [board_82574] = &e1000_82574_info, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 70 | [board_82583] = &e1000_82583_info, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 71 | [board_80003es2lan] = &e1000_es2_info, |
| 72 | [board_ich8lan] = &e1000_ich8_info, |
| 73 | [board_ich9lan] = &e1000_ich9_info, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 74 | [board_ich10lan] = &e1000_ich10_info, |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 75 | [board_pchlan] = &e1000_pch_info, |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 76 | [board_pch2lan] = &e1000_pch2_info, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 79 | struct e1000_reg_info { |
| 80 | u32 ofs; |
| 81 | char *name; |
| 82 | }; |
| 83 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 84 | #define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */ |
| 85 | #define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */ |
| 86 | #define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */ |
| 87 | #define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */ |
| 88 | #define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 89 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 90 | #define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */ |
| 91 | #define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */ |
| 92 | #define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */ |
| 93 | #define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */ |
| 94 | #define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 95 | |
| 96 | static const struct e1000_reg_info e1000_reg_info_tbl[] = { |
| 97 | |
| 98 | /* General Registers */ |
| 99 | {E1000_CTRL, "CTRL"}, |
| 100 | {E1000_STATUS, "STATUS"}, |
| 101 | {E1000_CTRL_EXT, "CTRL_EXT"}, |
| 102 | |
| 103 | /* Interrupt Registers */ |
| 104 | {E1000_ICR, "ICR"}, |
| 105 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 106 | /* Rx Registers */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 107 | {E1000_RCTL, "RCTL"}, |
| 108 | {E1000_RDLEN, "RDLEN"}, |
| 109 | {E1000_RDH, "RDH"}, |
| 110 | {E1000_RDT, "RDT"}, |
| 111 | {E1000_RDTR, "RDTR"}, |
| 112 | {E1000_RXDCTL(0), "RXDCTL"}, |
| 113 | {E1000_ERT, "ERT"}, |
| 114 | {E1000_RDBAL, "RDBAL"}, |
| 115 | {E1000_RDBAH, "RDBAH"}, |
| 116 | {E1000_RDFH, "RDFH"}, |
| 117 | {E1000_RDFT, "RDFT"}, |
| 118 | {E1000_RDFHS, "RDFHS"}, |
| 119 | {E1000_RDFTS, "RDFTS"}, |
| 120 | {E1000_RDFPC, "RDFPC"}, |
| 121 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 122 | /* Tx Registers */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 123 | {E1000_TCTL, "TCTL"}, |
| 124 | {E1000_TDBAL, "TDBAL"}, |
| 125 | {E1000_TDBAH, "TDBAH"}, |
| 126 | {E1000_TDLEN, "TDLEN"}, |
| 127 | {E1000_TDH, "TDH"}, |
| 128 | {E1000_TDT, "TDT"}, |
| 129 | {E1000_TIDV, "TIDV"}, |
| 130 | {E1000_TXDCTL(0), "TXDCTL"}, |
| 131 | {E1000_TADV, "TADV"}, |
| 132 | {E1000_TARC(0), "TARC"}, |
| 133 | {E1000_TDFH, "TDFH"}, |
| 134 | {E1000_TDFT, "TDFT"}, |
| 135 | {E1000_TDFHS, "TDFHS"}, |
| 136 | {E1000_TDFTS, "TDFTS"}, |
| 137 | {E1000_TDFPC, "TDFPC"}, |
| 138 | |
| 139 | /* List Terminator */ |
| 140 | {} |
| 141 | }; |
| 142 | |
| 143 | /* |
| 144 | * e1000_regdump - register printout routine |
| 145 | */ |
| 146 | static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo) |
| 147 | { |
| 148 | int n = 0; |
| 149 | char rname[16]; |
| 150 | u32 regs[8]; |
| 151 | |
| 152 | switch (reginfo->ofs) { |
| 153 | case E1000_RXDCTL(0): |
| 154 | for (n = 0; n < 2; n++) |
| 155 | regs[n] = __er32(hw, E1000_RXDCTL(n)); |
| 156 | break; |
| 157 | case E1000_TXDCTL(0): |
| 158 | for (n = 0; n < 2; n++) |
| 159 | regs[n] = __er32(hw, E1000_TXDCTL(n)); |
| 160 | break; |
| 161 | case E1000_TARC(0): |
| 162 | for (n = 0; n < 2; n++) |
| 163 | regs[n] = __er32(hw, E1000_TARC(n)); |
| 164 | break; |
| 165 | default: |
| 166 | printk(KERN_INFO "%-15s %08x\n", |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 167 | reginfo->name, __er32(hw, reginfo->ofs)); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 168 | return; |
| 169 | } |
| 170 | |
| 171 | snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]"); |
| 172 | printk(KERN_INFO "%-15s ", rname); |
| 173 | for (n = 0; n < 2; n++) |
| 174 | printk(KERN_CONT "%08x ", regs[n]); |
| 175 | printk(KERN_CONT "\n"); |
| 176 | } |
| 177 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 178 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 179 | * e1000e_dump - Print registers, Tx-ring and Rx-ring |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 180 | */ |
| 181 | static void e1000e_dump(struct e1000_adapter *adapter) |
| 182 | { |
| 183 | struct net_device *netdev = adapter->netdev; |
| 184 | struct e1000_hw *hw = &adapter->hw; |
| 185 | struct e1000_reg_info *reginfo; |
| 186 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 187 | struct e1000_tx_desc *tx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 188 | struct my_u0 { |
| 189 | u64 a; |
| 190 | u64 b; |
| 191 | } *u0; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 192 | struct e1000_buffer *buffer_info; |
| 193 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 194 | union e1000_rx_desc_packet_split *rx_desc_ps; |
| 195 | struct e1000_rx_desc *rx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 196 | struct my_u1 { |
| 197 | u64 a; |
| 198 | u64 b; |
| 199 | u64 c; |
| 200 | u64 d; |
| 201 | } *u1; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 202 | u32 staterr; |
| 203 | int i = 0; |
| 204 | |
| 205 | if (!netif_msg_hw(adapter)) |
| 206 | return; |
| 207 | |
| 208 | /* Print netdevice Info */ |
| 209 | if (netdev) { |
| 210 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
| 211 | printk(KERN_INFO "Device Name state " |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 212 | "trans_start last_rx\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 213 | printk(KERN_INFO "%-15s %016lX %016lX %016lX\n", |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 214 | netdev->name, netdev->state, netdev->trans_start, |
| 215 | netdev->last_rx); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /* Print Registers */ |
| 219 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
| 220 | printk(KERN_INFO " Register Name Value\n"); |
| 221 | for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl; |
| 222 | reginfo->name; reginfo++) { |
| 223 | e1000_regdump(hw, reginfo); |
| 224 | } |
| 225 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 226 | /* Print Tx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 227 | if (!netdev || !netif_running(netdev)) |
| 228 | goto exit; |
| 229 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 230 | dev_info(&adapter->pdev->dev, "Tx Ring Summary\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 231 | printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]" |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 232 | " leng ntw timestamp\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 233 | buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean]; |
| 234 | printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n", |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 235 | 0, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 236 | (unsigned long long)buffer_info->dma, |
| 237 | buffer_info->length, |
| 238 | buffer_info->next_to_watch, |
| 239 | (unsigned long long)buffer_info->time_stamp); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 240 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 241 | /* Print Tx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 242 | if (!netif_msg_tx_done(adapter)) |
| 243 | goto rx_ring_summary; |
| 244 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 245 | dev_info(&adapter->pdev->dev, "Tx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 246 | |
| 247 | /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended) |
| 248 | * |
| 249 | * Legacy Transmit Descriptor |
| 250 | * +--------------------------------------------------------------+ |
| 251 | * 0 | Buffer Address [63:0] (Reserved on Write Back) | |
| 252 | * +--------------------------------------------------------------+ |
| 253 | * 8 | Special | CSS | Status | CMD | CSO | Length | |
| 254 | * +--------------------------------------------------------------+ |
| 255 | * 63 48 47 36 35 32 31 24 23 16 15 0 |
| 256 | * |
| 257 | * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload |
| 258 | * 63 48 47 40 39 32 31 16 15 8 7 0 |
| 259 | * +----------------------------------------------------------------+ |
| 260 | * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS | |
| 261 | * +----------------------------------------------------------------+ |
| 262 | * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN | |
| 263 | * +----------------------------------------------------------------+ |
| 264 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 265 | * |
| 266 | * Extended Data Descriptor (DTYP=0x1) |
| 267 | * +----------------------------------------------------------------+ |
| 268 | * 0 | Buffer Address [63:0] | |
| 269 | * +----------------------------------------------------------------+ |
| 270 | * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN | |
| 271 | * +----------------------------------------------------------------+ |
| 272 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 273 | */ |
| 274 | printk(KERN_INFO "Tl[desc] [address 63:0 ] [SpeCssSCmCsLen]" |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 275 | " [bi->dma ] leng ntw timestamp bi->skb " |
| 276 | "<-- Legacy format\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 277 | printk(KERN_INFO "Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen]" |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 278 | " [bi->dma ] leng ntw timestamp bi->skb " |
| 279 | "<-- Ext Context format\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 280 | printk(KERN_INFO "Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen]" |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 281 | " [bi->dma ] leng ntw timestamp bi->skb " |
| 282 | "<-- Ext Data format\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 283 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
| 284 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 285 | buffer_info = &tx_ring->buffer_info[i]; |
| 286 | u0 = (struct my_u0 *)tx_desc; |
| 287 | printk(KERN_INFO "T%c[0x%03X] %016llX %016llX %016llX " |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 288 | "%04X %3X %016llX %p", |
| 289 | (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' : |
| 290 | ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), i, |
Bruce Allan | 8eb64e6 | 2010-06-29 18:12:30 +0000 | [diff] [blame] | 291 | (unsigned long long)le64_to_cpu(u0->a), |
| 292 | (unsigned long long)le64_to_cpu(u0->b), |
| 293 | (unsigned long long)buffer_info->dma, |
| 294 | buffer_info->length, buffer_info->next_to_watch, |
| 295 | (unsigned long long)buffer_info->time_stamp, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 296 | buffer_info->skb); |
| 297 | if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean) |
| 298 | printk(KERN_CONT " NTC/U\n"); |
| 299 | else if (i == tx_ring->next_to_use) |
| 300 | printk(KERN_CONT " NTU\n"); |
| 301 | else if (i == tx_ring->next_to_clean) |
| 302 | printk(KERN_CONT " NTC\n"); |
| 303 | else |
| 304 | printk(KERN_CONT "\n"); |
| 305 | |
| 306 | if (netif_msg_pktdata(adapter) && buffer_info->dma != 0) |
| 307 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 308 | 16, 1, phys_to_virt(buffer_info->dma), |
| 309 | buffer_info->length, true); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 312 | /* Print Rx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 313 | rx_ring_summary: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 314 | dev_info(&adapter->pdev->dev, "Rx Ring Summary\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 315 | printk(KERN_INFO "Queue [NTU] [NTC]\n"); |
| 316 | printk(KERN_INFO " %5d %5X %5X\n", 0, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 317 | rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 318 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 319 | /* Print Rx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 320 | if (!netif_msg_rx_status(adapter)) |
| 321 | goto exit; |
| 322 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 323 | dev_info(&adapter->pdev->dev, "Rx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 324 | switch (adapter->rx_ps_pages) { |
| 325 | case 1: |
| 326 | case 2: |
| 327 | case 3: |
| 328 | /* [Extended] Packet Split Receive Descriptor Format |
| 329 | * |
| 330 | * +-----------------------------------------------------+ |
| 331 | * 0 | Buffer Address 0 [63:0] | |
| 332 | * +-----------------------------------------------------+ |
| 333 | * 8 | Buffer Address 1 [63:0] | |
| 334 | * +-----------------------------------------------------+ |
| 335 | * 16 | Buffer Address 2 [63:0] | |
| 336 | * +-----------------------------------------------------+ |
| 337 | * 24 | Buffer Address 3 [63:0] | |
| 338 | * +-----------------------------------------------------+ |
| 339 | */ |
| 340 | printk(KERN_INFO "R [desc] [buffer 0 63:0 ] " |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 341 | "[buffer 1 63:0 ] " |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 342 | "[buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] " |
| 343 | "[bi->skb] <-- Ext Pkt Split format\n"); |
| 344 | /* [Extended] Receive Descriptor (Write-Back) Format |
| 345 | * |
| 346 | * 63 48 47 32 31 13 12 8 7 4 3 0 |
| 347 | * +------------------------------------------------------+ |
| 348 | * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS | |
| 349 | * | Checksum | Ident | | Queue | | Type | |
| 350 | * +------------------------------------------------------+ |
| 351 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 352 | * +------------------------------------------------------+ |
| 353 | * 63 48 47 32 31 20 19 0 |
| 354 | */ |
| 355 | printk(KERN_INFO "RWB[desc] [ck ipid mrqhsh] " |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 356 | "[vl l0 ee es] " |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 357 | "[ l3 l2 l1 hs] [reserved ] ---------------- " |
| 358 | "[bi->skb] <-- Ext Rx Write-Back format\n"); |
| 359 | for (i = 0; i < rx_ring->count; i++) { |
| 360 | buffer_info = &rx_ring->buffer_info[i]; |
| 361 | rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i); |
| 362 | u1 = (struct my_u1 *)rx_desc_ps; |
| 363 | staterr = |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 364 | le32_to_cpu(rx_desc_ps->wb.middle.status_error); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 365 | if (staterr & E1000_RXD_STAT_DD) { |
| 366 | /* Descriptor Done */ |
| 367 | printk(KERN_INFO "RWB[0x%03X] %016llX " |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 368 | "%016llX %016llX %016llX " |
| 369 | "---------------- %p", i, |
| 370 | (unsigned long long)le64_to_cpu(u1->a), |
| 371 | (unsigned long long)le64_to_cpu(u1->b), |
| 372 | (unsigned long long)le64_to_cpu(u1->c), |
| 373 | (unsigned long long)le64_to_cpu(u1->d), |
| 374 | buffer_info->skb); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 375 | } else { |
| 376 | printk(KERN_INFO "R [0x%03X] %016llX " |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 377 | "%016llX %016llX %016llX %016llX %p", i, |
| 378 | (unsigned long long)le64_to_cpu(u1->a), |
| 379 | (unsigned long long)le64_to_cpu(u1->b), |
| 380 | (unsigned long long)le64_to_cpu(u1->c), |
| 381 | (unsigned long long)le64_to_cpu(u1->d), |
| 382 | (unsigned long long)buffer_info->dma, |
| 383 | buffer_info->skb); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 384 | |
| 385 | if (netif_msg_pktdata(adapter)) |
| 386 | print_hex_dump(KERN_INFO, "", |
| 387 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 388 | phys_to_virt(buffer_info->dma), |
| 389 | adapter->rx_ps_bsize0, true); |
| 390 | } |
| 391 | |
| 392 | if (i == rx_ring->next_to_use) |
| 393 | printk(KERN_CONT " NTU\n"); |
| 394 | else if (i == rx_ring->next_to_clean) |
| 395 | printk(KERN_CONT " NTC\n"); |
| 396 | else |
| 397 | printk(KERN_CONT "\n"); |
| 398 | } |
| 399 | break; |
| 400 | default: |
| 401 | case 0: |
| 402 | /* Legacy Receive Descriptor Format |
| 403 | * |
| 404 | * +-----------------------------------------------------+ |
| 405 | * | Buffer Address [63:0] | |
| 406 | * +-----------------------------------------------------+ |
| 407 | * | VLAN Tag | Errors | Status 0 | Packet csum | Length | |
| 408 | * +-----------------------------------------------------+ |
| 409 | * 63 48 47 40 39 32 31 16 15 0 |
| 410 | */ |
| 411 | printk(KERN_INFO "Rl[desc] [address 63:0 ] " |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 412 | "[vl er S cks ln] [bi->dma ] [bi->skb] " |
| 413 | "<-- Legacy format\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 414 | for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) { |
| 415 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 416 | buffer_info = &rx_ring->buffer_info[i]; |
| 417 | u0 = (struct my_u0 *)rx_desc; |
| 418 | printk(KERN_INFO "Rl[0x%03X] %016llX %016llX " |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 419 | "%016llX %p", i, |
| 420 | (unsigned long long)le64_to_cpu(u0->a), |
| 421 | (unsigned long long)le64_to_cpu(u0->b), |
| 422 | (unsigned long long)buffer_info->dma, |
| 423 | buffer_info->skb); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 424 | if (i == rx_ring->next_to_use) |
| 425 | printk(KERN_CONT " NTU\n"); |
| 426 | else if (i == rx_ring->next_to_clean) |
| 427 | printk(KERN_CONT " NTC\n"); |
| 428 | else |
| 429 | printk(KERN_CONT "\n"); |
| 430 | |
| 431 | if (netif_msg_pktdata(adapter)) |
| 432 | print_hex_dump(KERN_INFO, "", |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 433 | DUMP_PREFIX_ADDRESS, |
| 434 | 16, 1, |
| 435 | phys_to_virt(buffer_info->dma), |
| 436 | adapter->rx_buffer_len, true); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
| 440 | exit: |
| 441 | return; |
| 442 | } |
| 443 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 444 | /** |
| 445 | * e1000_desc_unused - calculate if we have unused descriptors |
| 446 | **/ |
| 447 | static int e1000_desc_unused(struct e1000_ring *ring) |
| 448 | { |
| 449 | if (ring->next_to_clean > ring->next_to_use) |
| 450 | return ring->next_to_clean - ring->next_to_use - 1; |
| 451 | |
| 452 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; |
| 453 | } |
| 454 | |
| 455 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 456 | * e1000_receive_skb - helper function to handle Rx indications |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 457 | * @adapter: board private structure |
| 458 | * @status: descriptor status field as written by hardware |
| 459 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
| 460 | * @skb: pointer to sk_buff to be indicated to stack |
| 461 | **/ |
| 462 | static void e1000_receive_skb(struct e1000_adapter *adapter, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 463 | struct net_device *netdev, struct sk_buff *skb, |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 464 | u8 status, __le16 vlan) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 465 | { |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 466 | u16 tag = le16_to_cpu(vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 467 | skb->protocol = eth_type_trans(skb, netdev); |
| 468 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 469 | if (status & E1000_RXD_STAT_VP) |
| 470 | __vlan_hwaccel_put_tag(skb, tag); |
| 471 | |
| 472 | napi_gro_receive(&adapter->napi, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 476 | * e1000_rx_checksum - Receive Checksum Offload |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 477 | * @adapter: board private structure |
| 478 | * @status_err: receive descriptor status and error fields |
| 479 | * @csum: receive descriptor csum field |
| 480 | * @sk_buff: socket buffer with received data |
| 481 | **/ |
| 482 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
| 483 | u32 csum, struct sk_buff *skb) |
| 484 | { |
| 485 | u16 status = (u16)status_err; |
| 486 | u8 errors = (u8)(status_err >> 24); |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 487 | |
| 488 | skb_checksum_none_assert(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 489 | |
| 490 | /* Ignore Checksum bit is set */ |
| 491 | if (status & E1000_RXD_STAT_IXSM) |
| 492 | return; |
| 493 | /* TCP/UDP checksum error bit is set */ |
| 494 | if (errors & E1000_RXD_ERR_TCPE) { |
| 495 | /* let the stack verify checksum errors */ |
| 496 | adapter->hw_csum_err++; |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | /* TCP/UDP Checksum has not been calculated */ |
| 501 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
| 502 | return; |
| 503 | |
| 504 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 505 | if (status & E1000_RXD_STAT_TCPCS) { |
| 506 | /* TCP checksum is good */ |
| 507 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 508 | } else { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 509 | /* |
| 510 | * IP fragment with UDP payload |
| 511 | * Hardware complements the payload checksum, so we undo it |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 512 | * and then put the value in host order for further stack use. |
| 513 | */ |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 514 | __sum16 sum = (__force __sum16)htons(csum); |
| 515 | skb->csum = csum_unfold(~sum); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 516 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 517 | } |
| 518 | adapter->hw_csum_good++; |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
| 523 | * @adapter: address of board private structure |
| 524 | **/ |
| 525 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
| 526 | int cleaned_count) |
| 527 | { |
| 528 | struct net_device *netdev = adapter->netdev; |
| 529 | struct pci_dev *pdev = adapter->pdev; |
| 530 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 531 | struct e1000_rx_desc *rx_desc; |
| 532 | struct e1000_buffer *buffer_info; |
| 533 | struct sk_buff *skb; |
| 534 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 535 | unsigned int bufsz = adapter->rx_buffer_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 536 | |
| 537 | i = rx_ring->next_to_use; |
| 538 | buffer_info = &rx_ring->buffer_info[i]; |
| 539 | |
| 540 | while (cleaned_count--) { |
| 541 | skb = buffer_info->skb; |
| 542 | if (skb) { |
| 543 | skb_trim(skb, 0); |
| 544 | goto map_skb; |
| 545 | } |
| 546 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 547 | skb = netdev_alloc_skb_ip_align(netdev, bufsz); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 548 | if (!skb) { |
| 549 | /* Better luck next round */ |
| 550 | adapter->alloc_rx_buff_failed++; |
| 551 | break; |
| 552 | } |
| 553 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 554 | buffer_info->skb = skb; |
| 555 | map_skb: |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 556 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 557 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 558 | DMA_FROM_DEVICE); |
| 559 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 560 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 561 | adapter->rx_dma_failed++; |
| 562 | break; |
| 563 | } |
| 564 | |
| 565 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 566 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 567 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 568 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
| 569 | /* |
| 570 | * Force memory writes to complete before letting h/w |
| 571 | * know there are new descriptors to fetch. (Only |
| 572 | * applicable for weak-ordered memory model archs, |
| 573 | * such as IA-64). |
| 574 | */ |
| 575 | wmb(); |
| 576 | writel(i, adapter->hw.hw_addr + rx_ring->tail); |
| 577 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 578 | i++; |
| 579 | if (i == rx_ring->count) |
| 580 | i = 0; |
| 581 | buffer_info = &rx_ring->buffer_info[i]; |
| 582 | } |
| 583 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 584 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /** |
| 588 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
| 589 | * @adapter: address of board private structure |
| 590 | **/ |
| 591 | static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
| 592 | int cleaned_count) |
| 593 | { |
| 594 | struct net_device *netdev = adapter->netdev; |
| 595 | struct pci_dev *pdev = adapter->pdev; |
| 596 | union e1000_rx_desc_packet_split *rx_desc; |
| 597 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 598 | struct e1000_buffer *buffer_info; |
| 599 | struct e1000_ps_page *ps_page; |
| 600 | struct sk_buff *skb; |
| 601 | unsigned int i, j; |
| 602 | |
| 603 | i = rx_ring->next_to_use; |
| 604 | buffer_info = &rx_ring->buffer_info[i]; |
| 605 | |
| 606 | while (cleaned_count--) { |
| 607 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 608 | |
| 609 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 610 | ps_page = &buffer_info->ps_pages[j]; |
| 611 | if (j >= adapter->rx_ps_pages) { |
| 612 | /* all unused desc entries get hw null ptr */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 613 | rx_desc->read.buffer_addr[j + 1] = |
| 614 | ~cpu_to_le64(0); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 615 | continue; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 616 | } |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 617 | if (!ps_page->page) { |
| 618 | ps_page->page = alloc_page(GFP_ATOMIC); |
| 619 | if (!ps_page->page) { |
| 620 | adapter->alloc_rx_buff_failed++; |
| 621 | goto no_buffers; |
| 622 | } |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 623 | ps_page->dma = dma_map_page(&pdev->dev, |
| 624 | ps_page->page, |
| 625 | 0, PAGE_SIZE, |
| 626 | DMA_FROM_DEVICE); |
| 627 | if (dma_mapping_error(&pdev->dev, |
| 628 | ps_page->dma)) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 629 | dev_err(&adapter->pdev->dev, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 630 | "Rx DMA page map failed\n"); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 631 | adapter->rx_dma_failed++; |
| 632 | goto no_buffers; |
| 633 | } |
| 634 | } |
| 635 | /* |
| 636 | * Refresh the desc even if buffer_addrs |
| 637 | * didn't change because each write-back |
| 638 | * erases this info. |
| 639 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 640 | rx_desc->read.buffer_addr[j + 1] = |
| 641 | cpu_to_le64(ps_page->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 644 | skb = netdev_alloc_skb_ip_align(netdev, |
| 645 | adapter->rx_ps_bsize0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 646 | |
| 647 | if (!skb) { |
| 648 | adapter->alloc_rx_buff_failed++; |
| 649 | break; |
| 650 | } |
| 651 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 652 | buffer_info->skb = skb; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 653 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 654 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 655 | DMA_FROM_DEVICE); |
| 656 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 657 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 658 | adapter->rx_dma_failed++; |
| 659 | /* cleanup skb */ |
| 660 | dev_kfree_skb_any(skb); |
| 661 | buffer_info->skb = NULL; |
| 662 | break; |
| 663 | } |
| 664 | |
| 665 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 666 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 667 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
| 668 | /* |
| 669 | * Force memory writes to complete before letting h/w |
| 670 | * know there are new descriptors to fetch. (Only |
| 671 | * applicable for weak-ordered memory model archs, |
| 672 | * such as IA-64). |
| 673 | */ |
| 674 | wmb(); |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 675 | writel(i << 1, adapter->hw.hw_addr + rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 678 | i++; |
| 679 | if (i == rx_ring->count) |
| 680 | i = 0; |
| 681 | buffer_info = &rx_ring->buffer_info[i]; |
| 682 | } |
| 683 | |
| 684 | no_buffers: |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 685 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 689 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
| 690 | * @adapter: address of board private structure |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 691 | * @cleaned_count: number of buffers to allocate this pass |
| 692 | **/ |
| 693 | |
| 694 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, |
| 695 | int cleaned_count) |
| 696 | { |
| 697 | struct net_device *netdev = adapter->netdev; |
| 698 | struct pci_dev *pdev = adapter->pdev; |
| 699 | struct e1000_rx_desc *rx_desc; |
| 700 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 701 | struct e1000_buffer *buffer_info; |
| 702 | struct sk_buff *skb; |
| 703 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 704 | unsigned int bufsz = 256 - 16 /* for skb_reserve */; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 705 | |
| 706 | i = rx_ring->next_to_use; |
| 707 | buffer_info = &rx_ring->buffer_info[i]; |
| 708 | |
| 709 | while (cleaned_count--) { |
| 710 | skb = buffer_info->skb; |
| 711 | if (skb) { |
| 712 | skb_trim(skb, 0); |
| 713 | goto check_page; |
| 714 | } |
| 715 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 716 | skb = netdev_alloc_skb_ip_align(netdev, bufsz); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 717 | if (unlikely(!skb)) { |
| 718 | /* Better luck next round */ |
| 719 | adapter->alloc_rx_buff_failed++; |
| 720 | break; |
| 721 | } |
| 722 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 723 | buffer_info->skb = skb; |
| 724 | check_page: |
| 725 | /* allocate a new page if necessary */ |
| 726 | if (!buffer_info->page) { |
| 727 | buffer_info->page = alloc_page(GFP_ATOMIC); |
| 728 | if (unlikely(!buffer_info->page)) { |
| 729 | adapter->alloc_rx_buff_failed++; |
| 730 | break; |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | if (!buffer_info->dma) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 735 | buffer_info->dma = dma_map_page(&pdev->dev, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 736 | buffer_info->page, 0, |
| 737 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 738 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 739 | |
| 740 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 741 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 742 | |
| 743 | if (unlikely(++i == rx_ring->count)) |
| 744 | i = 0; |
| 745 | buffer_info = &rx_ring->buffer_info[i]; |
| 746 | } |
| 747 | |
| 748 | if (likely(rx_ring->next_to_use != i)) { |
| 749 | rx_ring->next_to_use = i; |
| 750 | if (unlikely(i-- == 0)) |
| 751 | i = (rx_ring->count - 1); |
| 752 | |
| 753 | /* Force memory writes to complete before letting h/w |
| 754 | * know there are new descriptors to fetch. (Only |
| 755 | * applicable for weak-ordered memory model archs, |
| 756 | * such as IA-64). */ |
| 757 | wmb(); |
| 758 | writel(i, adapter->hw.hw_addr + rx_ring->tail); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 763 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
| 764 | * @adapter: board private structure |
| 765 | * |
| 766 | * the return value indicates whether actual cleaning was done, there |
| 767 | * is no guarantee that everything was cleaned |
| 768 | **/ |
| 769 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 770 | int *work_done, int work_to_do) |
| 771 | { |
| 772 | struct net_device *netdev = adapter->netdev; |
| 773 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 774 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 775 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 776 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 777 | struct e1000_buffer *buffer_info, *next_buffer; |
| 778 | u32 length; |
| 779 | unsigned int i; |
| 780 | int cleaned_count = 0; |
| 781 | bool cleaned = 0; |
| 782 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 783 | |
| 784 | i = rx_ring->next_to_clean; |
| 785 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 786 | buffer_info = &rx_ring->buffer_info[i]; |
| 787 | |
| 788 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
| 789 | struct sk_buff *skb; |
| 790 | u8 status; |
| 791 | |
| 792 | if (*work_done >= work_to_do) |
| 793 | break; |
| 794 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 795 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 796 | |
| 797 | status = rx_desc->status; |
| 798 | skb = buffer_info->skb; |
| 799 | buffer_info->skb = NULL; |
| 800 | |
| 801 | prefetch(skb->data - NET_IP_ALIGN); |
| 802 | |
| 803 | i++; |
| 804 | if (i == rx_ring->count) |
| 805 | i = 0; |
| 806 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
| 807 | prefetch(next_rxd); |
| 808 | |
| 809 | next_buffer = &rx_ring->buffer_info[i]; |
| 810 | |
| 811 | cleaned = 1; |
| 812 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 813 | dma_unmap_single(&pdev->dev, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 814 | buffer_info->dma, |
| 815 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 816 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 817 | buffer_info->dma = 0; |
| 818 | |
| 819 | length = le16_to_cpu(rx_desc->length); |
| 820 | |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 821 | /* |
| 822 | * !EOP means multiple descriptors were used to store a single |
| 823 | * packet, if that's the case we need to toss it. In fact, we |
| 824 | * need to toss every packet with the EOP bit clear and the |
| 825 | * next frame that _does_ have the EOP bit set, as it is by |
| 826 | * definition only a frame fragment |
| 827 | */ |
| 828 | if (unlikely(!(status & E1000_RXD_STAT_EOP))) |
| 829 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 830 | |
| 831 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 832 | /* All receives must fit into a single buffer */ |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 833 | e_dbg("Receive packet consumed multiple buffers\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 834 | /* recycle */ |
| 835 | buffer_info->skb = skb; |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 836 | if (status & E1000_RXD_STAT_EOP) |
| 837 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 838 | goto next_desc; |
| 839 | } |
| 840 | |
| 841 | if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) { |
| 842 | /* recycle */ |
| 843 | buffer_info->skb = skb; |
| 844 | goto next_desc; |
| 845 | } |
| 846 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 847 | /* adjust length to remove Ethernet CRC */ |
| 848 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 849 | length -= 4; |
| 850 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 851 | total_rx_bytes += length; |
| 852 | total_rx_packets++; |
| 853 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 854 | /* |
| 855 | * code added for copybreak, this should improve |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 856 | * performance for small packets with large amounts |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 857 | * of reassembly being done in the stack |
| 858 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 859 | if (length < copybreak) { |
| 860 | struct sk_buff *new_skb = |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 861 | netdev_alloc_skb_ip_align(netdev, length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 862 | if (new_skb) { |
Bruce Allan | 808ff67 | 2008-08-08 18:35:56 -0700 | [diff] [blame] | 863 | skb_copy_to_linear_data_offset(new_skb, |
| 864 | -NET_IP_ALIGN, |
| 865 | (skb->data - |
| 866 | NET_IP_ALIGN), |
| 867 | (length + |
| 868 | NET_IP_ALIGN)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 869 | /* save the skb in buffer_info as good */ |
| 870 | buffer_info->skb = skb; |
| 871 | skb = new_skb; |
| 872 | } |
| 873 | /* else just continue with the old one */ |
| 874 | } |
| 875 | /* end copybreak code */ |
| 876 | skb_put(skb, length); |
| 877 | |
| 878 | /* Receive Checksum Offload */ |
| 879 | e1000_rx_checksum(adapter, |
| 880 | (u32)(status) | |
| 881 | ((u32)(rx_desc->errors) << 24), |
| 882 | le16_to_cpu(rx_desc->csum), skb); |
| 883 | |
| 884 | e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special); |
| 885 | |
| 886 | next_desc: |
| 887 | rx_desc->status = 0; |
| 888 | |
| 889 | /* return some buffers to hardware, one at a time is too slow */ |
| 890 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
| 891 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 892 | cleaned_count = 0; |
| 893 | } |
| 894 | |
| 895 | /* use prefetched values */ |
| 896 | rx_desc = next_rxd; |
| 897 | buffer_info = next_buffer; |
| 898 | } |
| 899 | rx_ring->next_to_clean = i; |
| 900 | |
| 901 | cleaned_count = e1000_desc_unused(rx_ring); |
| 902 | if (cleaned_count) |
| 903 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 904 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 905 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 906 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 907 | return cleaned; |
| 908 | } |
| 909 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 910 | static void e1000_put_txbuf(struct e1000_adapter *adapter, |
| 911 | struct e1000_buffer *buffer_info) |
| 912 | { |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 913 | if (buffer_info->dma) { |
| 914 | if (buffer_info->mapped_as_page) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 915 | dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, |
| 916 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 917 | else |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 918 | dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, |
| 919 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 920 | buffer_info->dma = 0; |
| 921 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 922 | if (buffer_info->skb) { |
| 923 | dev_kfree_skb_any(buffer_info->skb); |
| 924 | buffer_info->skb = NULL; |
| 925 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 926 | buffer_info->time_stamp = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 929 | static void e1000_print_hw_hang(struct work_struct *work) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 930 | { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 931 | struct e1000_adapter *adapter = container_of(work, |
| 932 | struct e1000_adapter, |
| 933 | print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 934 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 935 | unsigned int i = tx_ring->next_to_clean; |
| 936 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; |
| 937 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 938 | struct e1000_hw *hw = &adapter->hw; |
| 939 | u16 phy_status, phy_1000t_status, phy_ext_status; |
| 940 | u16 pci_status; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 941 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 942 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 943 | return; |
| 944 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 945 | e1e_rphy(hw, PHY_STATUS, &phy_status); |
| 946 | e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status); |
| 947 | e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status); |
| 948 | |
| 949 | pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status); |
| 950 | |
| 951 | /* detected Hardware unit hang */ |
| 952 | e_err("Detected Hardware Unit Hang:\n" |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 953 | " TDH <%x>\n" |
| 954 | " TDT <%x>\n" |
| 955 | " next_to_use <%x>\n" |
| 956 | " next_to_clean <%x>\n" |
| 957 | "buffer_info[next_to_clean]:\n" |
| 958 | " time_stamp <%lx>\n" |
| 959 | " next_to_watch <%x>\n" |
| 960 | " jiffies <%lx>\n" |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 961 | " next_to_watch.status <%x>\n" |
| 962 | "MAC Status <%x>\n" |
| 963 | "PHY Status <%x>\n" |
| 964 | "PHY 1000BASE-T Status <%x>\n" |
| 965 | "PHY Extended Status <%x>\n" |
| 966 | "PCI Status <%x>\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 967 | readl(adapter->hw.hw_addr + tx_ring->head), |
| 968 | readl(adapter->hw.hw_addr + tx_ring->tail), |
| 969 | tx_ring->next_to_use, |
| 970 | tx_ring->next_to_clean, |
| 971 | tx_ring->buffer_info[eop].time_stamp, |
| 972 | eop, |
| 973 | jiffies, |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 974 | eop_desc->upper.fields.status, |
| 975 | er32(STATUS), |
| 976 | phy_status, |
| 977 | phy_1000t_status, |
| 978 | phy_ext_status, |
| 979 | pci_status); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | /** |
| 983 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 984 | * @adapter: board private structure |
| 985 | * |
| 986 | * the return value indicates whether actual cleaning was done, there |
| 987 | * is no guarantee that everything was cleaned |
| 988 | **/ |
| 989 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter) |
| 990 | { |
| 991 | struct net_device *netdev = adapter->netdev; |
| 992 | struct e1000_hw *hw = &adapter->hw; |
| 993 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 994 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 995 | struct e1000_buffer *buffer_info; |
| 996 | unsigned int i, eop; |
| 997 | unsigned int count = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 998 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; |
| 999 | |
| 1000 | i = tx_ring->next_to_clean; |
| 1001 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1002 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 1003 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1004 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 1005 | (count < tx_ring->count)) { |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1006 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1007 | rmb(); /* read buffer_info after eop_desc */ |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1008 | for (; !cleaned; count++) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1009 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 1010 | buffer_info = &tx_ring->buffer_info[i]; |
| 1011 | cleaned = (i == eop); |
| 1012 | |
| 1013 | if (cleaned) { |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 1014 | total_tx_packets += buffer_info->segs; |
| 1015 | total_tx_bytes += buffer_info->bytecount; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | e1000_put_txbuf(adapter, buffer_info); |
| 1019 | tx_desc->upper.data = 0; |
| 1020 | |
| 1021 | i++; |
| 1022 | if (i == tx_ring->count) |
| 1023 | i = 0; |
| 1024 | } |
| 1025 | |
Terry Loftin | dac8761 | 2010-04-09 10:29:49 +0000 | [diff] [blame] | 1026 | if (i == tx_ring->next_to_use) |
| 1027 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1028 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1029 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | tx_ring->next_to_clean = i; |
| 1033 | |
| 1034 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1035 | if (count && netif_carrier_ok(netdev) && |
| 1036 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1037 | /* Make sure that anybody stopping the queue after this |
| 1038 | * sees the new next_to_clean. |
| 1039 | */ |
| 1040 | smp_mb(); |
| 1041 | |
| 1042 | if (netif_queue_stopped(netdev) && |
| 1043 | !(test_bit(__E1000_DOWN, &adapter->state))) { |
| 1044 | netif_wake_queue(netdev); |
| 1045 | ++adapter->restart_queue; |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | if (adapter->detect_tx_hung) { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1050 | /* |
| 1051 | * Detect a transmit hang in hardware, this serializes the |
| 1052 | * check with the clearing of time_stamp and movement of i |
| 1053 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1054 | adapter->detect_tx_hung = 0; |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1055 | if (tx_ring->buffer_info[i].time_stamp && |
| 1056 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1057 | + (adapter->tx_timeout_factor * HZ)) && |
| 1058 | !(er32(STATUS) & E1000_STATUS_TXOFF)) { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1059 | schedule_work(&adapter->print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1060 | netif_stop_queue(netdev); |
| 1061 | } |
| 1062 | } |
| 1063 | adapter->total_tx_bytes += total_tx_bytes; |
| 1064 | adapter->total_tx_packets += total_tx_packets; |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1065 | return count < tx_ring->count; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1069 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
| 1070 | * @adapter: board private structure |
| 1071 | * |
| 1072 | * the return value indicates whether actual cleaning was done, there |
| 1073 | * is no guarantee that everything was cleaned |
| 1074 | **/ |
| 1075 | static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 1076 | int *work_done, int work_to_do) |
| 1077 | { |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1078 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1079 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
| 1080 | struct net_device *netdev = adapter->netdev; |
| 1081 | struct pci_dev *pdev = adapter->pdev; |
| 1082 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1083 | struct e1000_buffer *buffer_info, *next_buffer; |
| 1084 | struct e1000_ps_page *ps_page; |
| 1085 | struct sk_buff *skb; |
| 1086 | unsigned int i, j; |
| 1087 | u32 length, staterr; |
| 1088 | int cleaned_count = 0; |
| 1089 | bool cleaned = 0; |
| 1090 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 1091 | |
| 1092 | i = rx_ring->next_to_clean; |
| 1093 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 1094 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1095 | buffer_info = &rx_ring->buffer_info[i]; |
| 1096 | |
| 1097 | while (staterr & E1000_RXD_STAT_DD) { |
| 1098 | if (*work_done >= work_to_do) |
| 1099 | break; |
| 1100 | (*work_done)++; |
| 1101 | skb = buffer_info->skb; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1102 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1103 | |
| 1104 | /* in the packet split case this is header only */ |
| 1105 | prefetch(skb->data - NET_IP_ALIGN); |
| 1106 | |
| 1107 | i++; |
| 1108 | if (i == rx_ring->count) |
| 1109 | i = 0; |
| 1110 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
| 1111 | prefetch(next_rxd); |
| 1112 | |
| 1113 | next_buffer = &rx_ring->buffer_info[i]; |
| 1114 | |
| 1115 | cleaned = 1; |
| 1116 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1117 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1118 | adapter->rx_ps_bsize0, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1119 | buffer_info->dma = 0; |
| 1120 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1121 | /* see !EOP comment in other Rx routine */ |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1122 | if (!(staterr & E1000_RXD_STAT_EOP)) |
| 1123 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 1124 | |
| 1125 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1126 | e_dbg("Packet Split buffers didn't pick up the full " |
| 1127 | "packet\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1128 | dev_kfree_skb_irq(skb); |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1129 | if (staterr & E1000_RXD_STAT_EOP) |
| 1130 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1131 | goto next_desc; |
| 1132 | } |
| 1133 | |
| 1134 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
| 1135 | dev_kfree_skb_irq(skb); |
| 1136 | goto next_desc; |
| 1137 | } |
| 1138 | |
| 1139 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 1140 | |
| 1141 | if (!length) { |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1142 | e_dbg("Last part of the packet spanning multiple " |
| 1143 | "descriptors\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1144 | dev_kfree_skb_irq(skb); |
| 1145 | goto next_desc; |
| 1146 | } |
| 1147 | |
| 1148 | /* Good Receive */ |
| 1149 | skb_put(skb, length); |
| 1150 | |
| 1151 | { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1152 | /* |
| 1153 | * this looks ugly, but it seems compiler issues make it |
| 1154 | * more efficient than reusing j |
| 1155 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1156 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 1157 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1158 | /* |
| 1159 | * page alloc/put takes too long and effects small packet |
| 1160 | * throughput, so unsplit small packets and save the alloc/put |
| 1161 | * only valid in softirq (napi) context to call kmap_* |
| 1162 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1163 | if (l1 && (l1 <= copybreak) && |
| 1164 | ((length + l1) <= adapter->rx_ps_bsize0)) { |
| 1165 | u8 *vaddr; |
| 1166 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1167 | ps_page = &buffer_info->ps_pages[0]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1168 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1169 | /* |
| 1170 | * there is no documentation about how to call |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1171 | * kmap_atomic, so we can't hold the mapping |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1172 | * very long |
| 1173 | */ |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1174 | dma_sync_single_for_cpu(&pdev->dev, ps_page->dma, |
| 1175 | PAGE_SIZE, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1176 | vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ); |
| 1177 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
| 1178 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1179 | dma_sync_single_for_device(&pdev->dev, ps_page->dma, |
| 1180 | PAGE_SIZE, DMA_FROM_DEVICE); |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 1181 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1182 | /* remove the CRC */ |
| 1183 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 1184 | l1 -= 4; |
| 1185 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1186 | skb_put(skb, l1); |
| 1187 | goto copydone; |
| 1188 | } /* if */ |
| 1189 | } |
| 1190 | |
| 1191 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
| 1192 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); |
| 1193 | if (!length) |
| 1194 | break; |
| 1195 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1196 | ps_page = &buffer_info->ps_pages[j]; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1197 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1198 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1199 | ps_page->dma = 0; |
| 1200 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); |
| 1201 | ps_page->page = NULL; |
| 1202 | skb->len += length; |
| 1203 | skb->data_len += length; |
| 1204 | skb->truesize += length; |
| 1205 | } |
| 1206 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1207 | /* strip the ethernet crc, problem is we're using pages now so |
| 1208 | * this whole operation can get a little cpu intensive |
| 1209 | */ |
| 1210 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 1211 | pskb_trim(skb, skb->len - 4); |
| 1212 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1213 | copydone: |
| 1214 | total_rx_bytes += skb->len; |
| 1215 | total_rx_packets++; |
| 1216 | |
| 1217 | e1000_rx_checksum(adapter, staterr, le16_to_cpu( |
| 1218 | rx_desc->wb.lower.hi_dword.csum_ip.csum), skb); |
| 1219 | |
| 1220 | if (rx_desc->wb.upper.header_status & |
| 1221 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) |
| 1222 | adapter->rx_hdr_split++; |
| 1223 | |
| 1224 | e1000_receive_skb(adapter, netdev, skb, |
| 1225 | staterr, rx_desc->wb.middle.vlan); |
| 1226 | |
| 1227 | next_desc: |
| 1228 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
| 1229 | buffer_info->skb = NULL; |
| 1230 | |
| 1231 | /* return some buffers to hardware, one at a time is too slow */ |
| 1232 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
| 1233 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 1234 | cleaned_count = 0; |
| 1235 | } |
| 1236 | |
| 1237 | /* use prefetched values */ |
| 1238 | rx_desc = next_rxd; |
| 1239 | buffer_info = next_buffer; |
| 1240 | |
| 1241 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1242 | } |
| 1243 | rx_ring->next_to_clean = i; |
| 1244 | |
| 1245 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1246 | if (cleaned_count) |
| 1247 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 1248 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1249 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1250 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1251 | return cleaned; |
| 1252 | } |
| 1253 | |
| 1254 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1255 | * e1000_consume_page - helper function |
| 1256 | **/ |
| 1257 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
| 1258 | u16 length) |
| 1259 | { |
| 1260 | bi->page = NULL; |
| 1261 | skb->len += length; |
| 1262 | skb->data_len += length; |
| 1263 | skb->truesize += length; |
| 1264 | } |
| 1265 | |
| 1266 | /** |
| 1267 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 1268 | * @adapter: board private structure |
| 1269 | * |
| 1270 | * the return value indicates whether actual cleaning was done, there |
| 1271 | * is no guarantee that everything was cleaned |
| 1272 | **/ |
| 1273 | |
| 1274 | static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, |
| 1275 | int *work_done, int work_to_do) |
| 1276 | { |
| 1277 | struct net_device *netdev = adapter->netdev; |
| 1278 | struct pci_dev *pdev = adapter->pdev; |
| 1279 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1280 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 1281 | struct e1000_buffer *buffer_info, *next_buffer; |
| 1282 | u32 length; |
| 1283 | unsigned int i; |
| 1284 | int cleaned_count = 0; |
| 1285 | bool cleaned = false; |
| 1286 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
| 1287 | |
| 1288 | i = rx_ring->next_to_clean; |
| 1289 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 1290 | buffer_info = &rx_ring->buffer_info[i]; |
| 1291 | |
| 1292 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
| 1293 | struct sk_buff *skb; |
| 1294 | u8 status; |
| 1295 | |
| 1296 | if (*work_done >= work_to_do) |
| 1297 | break; |
| 1298 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1299 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1300 | |
| 1301 | status = rx_desc->status; |
| 1302 | skb = buffer_info->skb; |
| 1303 | buffer_info->skb = NULL; |
| 1304 | |
| 1305 | ++i; |
| 1306 | if (i == rx_ring->count) |
| 1307 | i = 0; |
| 1308 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
| 1309 | prefetch(next_rxd); |
| 1310 | |
| 1311 | next_buffer = &rx_ring->buffer_info[i]; |
| 1312 | |
| 1313 | cleaned = true; |
| 1314 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1315 | dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE, |
| 1316 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1317 | buffer_info->dma = 0; |
| 1318 | |
| 1319 | length = le16_to_cpu(rx_desc->length); |
| 1320 | |
| 1321 | /* errors is only valid for DD + EOP descriptors */ |
| 1322 | if (unlikely((status & E1000_RXD_STAT_EOP) && |
| 1323 | (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) { |
| 1324 | /* recycle both page and skb */ |
| 1325 | buffer_info->skb = skb; |
| 1326 | /* an error means any chain goes out the window |
| 1327 | * too */ |
| 1328 | if (rx_ring->rx_skb_top) |
Bruce Allan | ef5ab89 | 2011-02-10 08:17:21 +0000 | [diff] [blame] | 1329 | dev_kfree_skb_irq(rx_ring->rx_skb_top); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1330 | rx_ring->rx_skb_top = NULL; |
| 1331 | goto next_desc; |
| 1332 | } |
| 1333 | |
Bruce Allan | f0f1a17 | 2010-12-11 05:53:32 +0000 | [diff] [blame] | 1334 | #define rxtop (rx_ring->rx_skb_top) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1335 | if (!(status & E1000_RXD_STAT_EOP)) { |
| 1336 | /* this descriptor is only the beginning (or middle) */ |
| 1337 | if (!rxtop) { |
| 1338 | /* this is the beginning of a chain */ |
| 1339 | rxtop = skb; |
| 1340 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
| 1341 | 0, length); |
| 1342 | } else { |
| 1343 | /* this is the middle of a chain */ |
| 1344 | skb_fill_page_desc(rxtop, |
| 1345 | skb_shinfo(rxtop)->nr_frags, |
| 1346 | buffer_info->page, 0, length); |
| 1347 | /* re-use the skb, only consumed the page */ |
| 1348 | buffer_info->skb = skb; |
| 1349 | } |
| 1350 | e1000_consume_page(buffer_info, rxtop, length); |
| 1351 | goto next_desc; |
| 1352 | } else { |
| 1353 | if (rxtop) { |
| 1354 | /* end of the chain */ |
| 1355 | skb_fill_page_desc(rxtop, |
| 1356 | skb_shinfo(rxtop)->nr_frags, |
| 1357 | buffer_info->page, 0, length); |
| 1358 | /* re-use the current skb, we only consumed the |
| 1359 | * page */ |
| 1360 | buffer_info->skb = skb; |
| 1361 | skb = rxtop; |
| 1362 | rxtop = NULL; |
| 1363 | e1000_consume_page(buffer_info, skb, length); |
| 1364 | } else { |
| 1365 | /* no chain, got EOP, this buf is the packet |
| 1366 | * copybreak to save the put_page/alloc_page */ |
| 1367 | if (length <= copybreak && |
| 1368 | skb_tailroom(skb) >= length) { |
| 1369 | u8 *vaddr; |
| 1370 | vaddr = kmap_atomic(buffer_info->page, |
| 1371 | KM_SKB_DATA_SOFTIRQ); |
| 1372 | memcpy(skb_tail_pointer(skb), vaddr, |
| 1373 | length); |
| 1374 | kunmap_atomic(vaddr, |
| 1375 | KM_SKB_DATA_SOFTIRQ); |
| 1376 | /* re-use the page, so don't erase |
| 1377 | * buffer_info->page */ |
| 1378 | skb_put(skb, length); |
| 1379 | } else { |
| 1380 | skb_fill_page_desc(skb, 0, |
| 1381 | buffer_info->page, 0, |
| 1382 | length); |
| 1383 | e1000_consume_page(buffer_info, skb, |
| 1384 | length); |
| 1385 | } |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | /* Receive Checksum Offload XXX recompute due to CRC strip? */ |
| 1390 | e1000_rx_checksum(adapter, |
| 1391 | (u32)(status) | |
| 1392 | ((u32)(rx_desc->errors) << 24), |
| 1393 | le16_to_cpu(rx_desc->csum), skb); |
| 1394 | |
| 1395 | /* probably a little skewed due to removing CRC */ |
| 1396 | total_rx_bytes += skb->len; |
| 1397 | total_rx_packets++; |
| 1398 | |
| 1399 | /* eth type trans needs skb->data to point to something */ |
| 1400 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1401 | e_err("pskb_may_pull failed.\n"); |
Bruce Allan | ef5ab89 | 2011-02-10 08:17:21 +0000 | [diff] [blame] | 1402 | dev_kfree_skb_irq(skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1403 | goto next_desc; |
| 1404 | } |
| 1405 | |
| 1406 | e1000_receive_skb(adapter, netdev, skb, status, |
| 1407 | rx_desc->special); |
| 1408 | |
| 1409 | next_desc: |
| 1410 | rx_desc->status = 0; |
| 1411 | |
| 1412 | /* return some buffers to hardware, one at a time is too slow */ |
| 1413 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 1414 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 1415 | cleaned_count = 0; |
| 1416 | } |
| 1417 | |
| 1418 | /* use prefetched values */ |
| 1419 | rx_desc = next_rxd; |
| 1420 | buffer_info = next_buffer; |
| 1421 | } |
| 1422 | rx_ring->next_to_clean = i; |
| 1423 | |
| 1424 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1425 | if (cleaned_count) |
| 1426 | adapter->alloc_rx_buf(adapter, cleaned_count); |
| 1427 | |
| 1428 | adapter->total_rx_bytes += total_rx_bytes; |
| 1429 | adapter->total_rx_packets += total_rx_packets; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1430 | return cleaned; |
| 1431 | } |
| 1432 | |
| 1433 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1434 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 1435 | * @adapter: board private structure |
| 1436 | **/ |
| 1437 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter) |
| 1438 | { |
| 1439 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1440 | struct e1000_buffer *buffer_info; |
| 1441 | struct e1000_ps_page *ps_page; |
| 1442 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1443 | unsigned int i, j; |
| 1444 | |
| 1445 | /* Free all the Rx ring sk_buffs */ |
| 1446 | for (i = 0; i < rx_ring->count; i++) { |
| 1447 | buffer_info = &rx_ring->buffer_info[i]; |
| 1448 | if (buffer_info->dma) { |
| 1449 | if (adapter->clean_rx == e1000_clean_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1450 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1451 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1452 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1453 | else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1454 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1455 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1456 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1457 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1458 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1459 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1460 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1461 | buffer_info->dma = 0; |
| 1462 | } |
| 1463 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1464 | if (buffer_info->page) { |
| 1465 | put_page(buffer_info->page); |
| 1466 | buffer_info->page = NULL; |
| 1467 | } |
| 1468 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1469 | if (buffer_info->skb) { |
| 1470 | dev_kfree_skb(buffer_info->skb); |
| 1471 | buffer_info->skb = NULL; |
| 1472 | } |
| 1473 | |
| 1474 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1475 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1476 | if (!ps_page->page) |
| 1477 | break; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1478 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1479 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1480 | ps_page->dma = 0; |
| 1481 | put_page(ps_page->page); |
| 1482 | ps_page->page = NULL; |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | /* there also may be some cached data from a chained receive */ |
| 1487 | if (rx_ring->rx_skb_top) { |
| 1488 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 1489 | rx_ring->rx_skb_top = NULL; |
| 1490 | } |
| 1491 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1492 | /* Zero out the descriptor ring */ |
| 1493 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1494 | |
| 1495 | rx_ring->next_to_clean = 0; |
| 1496 | rx_ring->next_to_use = 0; |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1497 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1498 | |
| 1499 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 1500 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
| 1501 | } |
| 1502 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1503 | static void e1000e_downshift_workaround(struct work_struct *work) |
| 1504 | { |
| 1505 | struct e1000_adapter *adapter = container_of(work, |
| 1506 | struct e1000_adapter, downshift_task); |
| 1507 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1508 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1509 | return; |
| 1510 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1511 | e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); |
| 1512 | } |
| 1513 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1514 | /** |
| 1515 | * e1000_intr_msi - Interrupt Handler |
| 1516 | * @irq: interrupt number |
| 1517 | * @data: pointer to a network interface device structure |
| 1518 | **/ |
| 1519 | static irqreturn_t e1000_intr_msi(int irq, void *data) |
| 1520 | { |
| 1521 | struct net_device *netdev = data; |
| 1522 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1523 | struct e1000_hw *hw = &adapter->hw; |
| 1524 | u32 icr = er32(ICR); |
| 1525 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1526 | /* |
| 1527 | * read ICR disables interrupts using IAM |
| 1528 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1529 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1530 | if (icr & E1000_ICR_LSC) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1531 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1532 | /* |
| 1533 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1534 | * disconnect (LSC) before accessing any PHY registers |
| 1535 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1536 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1537 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1538 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1539 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1540 | /* |
| 1541 | * 80003ES2LAN workaround-- For packet buffer work-around on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1542 | * link down event; disable receives here in the ISR and reset |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1543 | * adapter in watchdog |
| 1544 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1545 | if (netif_carrier_ok(netdev) && |
| 1546 | adapter->flags & FLAG_RX_NEEDS_RESTART) { |
| 1547 | /* disable receives */ |
| 1548 | u32 rctl = er32(RCTL); |
| 1549 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1550 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1551 | } |
| 1552 | /* guard against interrupt when we're going down */ |
| 1553 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1554 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1555 | } |
| 1556 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1557 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1558 | adapter->total_tx_bytes = 0; |
| 1559 | adapter->total_tx_packets = 0; |
| 1560 | adapter->total_rx_bytes = 0; |
| 1561 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1562 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | return IRQ_HANDLED; |
| 1566 | } |
| 1567 | |
| 1568 | /** |
| 1569 | * e1000_intr - Interrupt Handler |
| 1570 | * @irq: interrupt number |
| 1571 | * @data: pointer to a network interface device structure |
| 1572 | **/ |
| 1573 | static irqreturn_t e1000_intr(int irq, void *data) |
| 1574 | { |
| 1575 | struct net_device *netdev = data; |
| 1576 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1577 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1578 | u32 rctl, icr = er32(ICR); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1579 | |
Bruce Allan | a68ea77 | 2009-11-20 23:23:16 +0000 | [diff] [blame] | 1580 | if (!icr || test_bit(__E1000_DOWN, &adapter->state)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1581 | return IRQ_NONE; /* Not our interrupt */ |
| 1582 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1583 | /* |
| 1584 | * IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 1585 | * not set, then the adapter didn't send an interrupt |
| 1586 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1587 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 1588 | return IRQ_NONE; |
| 1589 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1590 | /* |
| 1591 | * Interrupt Auto-Mask...upon reading ICR, |
| 1592 | * interrupts are masked. No need for the |
| 1593 | * IMC write |
| 1594 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1595 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1596 | if (icr & E1000_ICR_LSC) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1597 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1598 | /* |
| 1599 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1600 | * disconnect (LSC) before accessing any PHY registers |
| 1601 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1602 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1603 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1604 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1605 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1606 | /* |
| 1607 | * 80003ES2LAN workaround-- |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1608 | * For packet buffer work-around on link down event; |
| 1609 | * disable receives here in the ISR and |
| 1610 | * reset adapter in watchdog |
| 1611 | */ |
| 1612 | if (netif_carrier_ok(netdev) && |
| 1613 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { |
| 1614 | /* disable receives */ |
| 1615 | rctl = er32(RCTL); |
| 1616 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1617 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1618 | } |
| 1619 | /* guard against interrupt when we're going down */ |
| 1620 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1621 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1622 | } |
| 1623 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1624 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1625 | adapter->total_tx_bytes = 0; |
| 1626 | adapter->total_tx_packets = 0; |
| 1627 | adapter->total_rx_bytes = 0; |
| 1628 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1629 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | return IRQ_HANDLED; |
| 1633 | } |
| 1634 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1635 | static irqreturn_t e1000_msix_other(int irq, void *data) |
| 1636 | { |
| 1637 | struct net_device *netdev = data; |
| 1638 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1639 | struct e1000_hw *hw = &adapter->hw; |
| 1640 | u32 icr = er32(ICR); |
| 1641 | |
| 1642 | if (!(icr & E1000_ICR_INT_ASSERTED)) { |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1643 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1644 | ew32(IMS, E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1645 | return IRQ_NONE; |
| 1646 | } |
| 1647 | |
| 1648 | if (icr & adapter->eiac_mask) |
| 1649 | ew32(ICS, (icr & adapter->eiac_mask)); |
| 1650 | |
| 1651 | if (icr & E1000_ICR_OTHER) { |
| 1652 | if (!(icr & E1000_ICR_LSC)) |
| 1653 | goto no_link_interrupt; |
| 1654 | hw->mac.get_link_status = 1; |
| 1655 | /* guard against interrupt when we're going down */ |
| 1656 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1657 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1658 | } |
| 1659 | |
| 1660 | no_link_interrupt: |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1661 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1662 | ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1663 | |
| 1664 | return IRQ_HANDLED; |
| 1665 | } |
| 1666 | |
| 1667 | |
| 1668 | static irqreturn_t e1000_intr_msix_tx(int irq, void *data) |
| 1669 | { |
| 1670 | struct net_device *netdev = data; |
| 1671 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1672 | struct e1000_hw *hw = &adapter->hw; |
| 1673 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1674 | |
| 1675 | |
| 1676 | adapter->total_tx_bytes = 0; |
| 1677 | adapter->total_tx_packets = 0; |
| 1678 | |
| 1679 | if (!e1000_clean_tx_irq(adapter)) |
| 1680 | /* Ring was not completely cleaned, so fire another interrupt */ |
| 1681 | ew32(ICS, tx_ring->ims_val); |
| 1682 | |
| 1683 | return IRQ_HANDLED; |
| 1684 | } |
| 1685 | |
| 1686 | static irqreturn_t e1000_intr_msix_rx(int irq, void *data) |
| 1687 | { |
| 1688 | struct net_device *netdev = data; |
| 1689 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1690 | |
| 1691 | /* Write the ITR value calculated at the end of the |
| 1692 | * previous interrupt. |
| 1693 | */ |
| 1694 | if (adapter->rx_ring->set_itr) { |
| 1695 | writel(1000000000 / (adapter->rx_ring->itr_val * 256), |
| 1696 | adapter->hw.hw_addr + adapter->rx_ring->itr_register); |
| 1697 | adapter->rx_ring->set_itr = 0; |
| 1698 | } |
| 1699 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1700 | if (napi_schedule_prep(&adapter->napi)) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1701 | adapter->total_rx_bytes = 0; |
| 1702 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1703 | __napi_schedule(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1704 | } |
| 1705 | return IRQ_HANDLED; |
| 1706 | } |
| 1707 | |
| 1708 | /** |
| 1709 | * e1000_configure_msix - Configure MSI-X hardware |
| 1710 | * |
| 1711 | * e1000_configure_msix sets up the hardware to properly |
| 1712 | * generate MSI-X interrupts. |
| 1713 | **/ |
| 1714 | static void e1000_configure_msix(struct e1000_adapter *adapter) |
| 1715 | { |
| 1716 | struct e1000_hw *hw = &adapter->hw; |
| 1717 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1718 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1719 | int vector = 0; |
| 1720 | u32 ctrl_ext, ivar = 0; |
| 1721 | |
| 1722 | adapter->eiac_mask = 0; |
| 1723 | |
| 1724 | /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ |
| 1725 | if (hw->mac.type == e1000_82574) { |
| 1726 | u32 rfctl = er32(RFCTL); |
| 1727 | rfctl |= E1000_RFCTL_ACK_DIS; |
| 1728 | ew32(RFCTL, rfctl); |
| 1729 | } |
| 1730 | |
| 1731 | #define E1000_IVAR_INT_ALLOC_VALID 0x8 |
| 1732 | /* Configure Rx vector */ |
| 1733 | rx_ring->ims_val = E1000_IMS_RXQ0; |
| 1734 | adapter->eiac_mask |= rx_ring->ims_val; |
| 1735 | if (rx_ring->itr_val) |
| 1736 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1737 | hw->hw_addr + rx_ring->itr_register); |
| 1738 | else |
| 1739 | writel(1, hw->hw_addr + rx_ring->itr_register); |
| 1740 | ivar = E1000_IVAR_INT_ALLOC_VALID | vector; |
| 1741 | |
| 1742 | /* Configure Tx vector */ |
| 1743 | tx_ring->ims_val = E1000_IMS_TXQ0; |
| 1744 | vector++; |
| 1745 | if (tx_ring->itr_val) |
| 1746 | writel(1000000000 / (tx_ring->itr_val * 256), |
| 1747 | hw->hw_addr + tx_ring->itr_register); |
| 1748 | else |
| 1749 | writel(1, hw->hw_addr + tx_ring->itr_register); |
| 1750 | adapter->eiac_mask |= tx_ring->ims_val; |
| 1751 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); |
| 1752 | |
| 1753 | /* set vector for Other Causes, e.g. link changes */ |
| 1754 | vector++; |
| 1755 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); |
| 1756 | if (rx_ring->itr_val) |
| 1757 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1758 | hw->hw_addr + E1000_EITR_82574(vector)); |
| 1759 | else |
| 1760 | writel(1, hw->hw_addr + E1000_EITR_82574(vector)); |
| 1761 | |
| 1762 | /* Cause Tx interrupts on every write back */ |
| 1763 | ivar |= (1 << 31); |
| 1764 | |
| 1765 | ew32(IVAR, ivar); |
| 1766 | |
| 1767 | /* enable MSI-X PBA support */ |
| 1768 | ctrl_ext = er32(CTRL_EXT); |
| 1769 | ctrl_ext |= E1000_CTRL_EXT_PBA_CLR; |
| 1770 | |
| 1771 | /* Auto-Mask Other interrupts upon ICR read */ |
| 1772 | #define E1000_EIAC_MASK_82574 0x01F00000 |
| 1773 | ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER); |
| 1774 | ctrl_ext |= E1000_CTRL_EXT_EIAME; |
| 1775 | ew32(CTRL_EXT, ctrl_ext); |
| 1776 | e1e_flush(); |
| 1777 | } |
| 1778 | |
| 1779 | void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) |
| 1780 | { |
| 1781 | if (adapter->msix_entries) { |
| 1782 | pci_disable_msix(adapter->pdev); |
| 1783 | kfree(adapter->msix_entries); |
| 1784 | adapter->msix_entries = NULL; |
| 1785 | } else if (adapter->flags & FLAG_MSI_ENABLED) { |
| 1786 | pci_disable_msi(adapter->pdev); |
| 1787 | adapter->flags &= ~FLAG_MSI_ENABLED; |
| 1788 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | /** |
| 1792 | * e1000e_set_interrupt_capability - set MSI or MSI-X if supported |
| 1793 | * |
| 1794 | * Attempt to configure interrupts using the best available |
| 1795 | * capabilities of the hardware and kernel. |
| 1796 | **/ |
| 1797 | void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) |
| 1798 | { |
| 1799 | int err; |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1800 | int i; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1801 | |
| 1802 | switch (adapter->int_mode) { |
| 1803 | case E1000E_INT_MODE_MSIX: |
| 1804 | if (adapter->flags & FLAG_HAS_MSIX) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1805 | adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */ |
| 1806 | adapter->msix_entries = kcalloc(adapter->num_vectors, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1807 | sizeof(struct msix_entry), |
| 1808 | GFP_KERNEL); |
| 1809 | if (adapter->msix_entries) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1810 | for (i = 0; i < adapter->num_vectors; i++) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1811 | adapter->msix_entries[i].entry = i; |
| 1812 | |
| 1813 | err = pci_enable_msix(adapter->pdev, |
| 1814 | adapter->msix_entries, |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1815 | adapter->num_vectors); |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 1816 | if (err == 0) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1817 | return; |
| 1818 | } |
| 1819 | /* MSI-X failed, so fall through and try MSI */ |
| 1820 | e_err("Failed to initialize MSI-X interrupts. " |
| 1821 | "Falling back to MSI interrupts.\n"); |
| 1822 | e1000e_reset_interrupt_capability(adapter); |
| 1823 | } |
| 1824 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 1825 | /* Fall through */ |
| 1826 | case E1000E_INT_MODE_MSI: |
| 1827 | if (!pci_enable_msi(adapter->pdev)) { |
| 1828 | adapter->flags |= FLAG_MSI_ENABLED; |
| 1829 | } else { |
| 1830 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
| 1831 | e_err("Failed to initialize MSI interrupts. Falling " |
| 1832 | "back to legacy interrupts.\n"); |
| 1833 | } |
| 1834 | /* Fall through */ |
| 1835 | case E1000E_INT_MODE_LEGACY: |
| 1836 | /* Don't do anything; this is the system default */ |
| 1837 | break; |
| 1838 | } |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1839 | |
| 1840 | /* store the number of vectors being used */ |
| 1841 | adapter->num_vectors = 1; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | /** |
| 1845 | * e1000_request_msix - Initialize MSI-X interrupts |
| 1846 | * |
| 1847 | * e1000_request_msix allocates MSI-X vectors and requests interrupts from the |
| 1848 | * kernel. |
| 1849 | **/ |
| 1850 | static int e1000_request_msix(struct e1000_adapter *adapter) |
| 1851 | { |
| 1852 | struct net_device *netdev = adapter->netdev; |
| 1853 | int err = 0, vector = 0; |
| 1854 | |
| 1855 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 1856 | snprintf(adapter->rx_ring->name, |
| 1857 | sizeof(adapter->rx_ring->name) - 1, |
| 1858 | "%s-rx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1859 | else |
| 1860 | memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); |
| 1861 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1862 | e1000_intr_msix_rx, 0, adapter->rx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1863 | netdev); |
| 1864 | if (err) |
| 1865 | goto out; |
| 1866 | adapter->rx_ring->itr_register = E1000_EITR_82574(vector); |
| 1867 | adapter->rx_ring->itr_val = adapter->itr; |
| 1868 | vector++; |
| 1869 | |
| 1870 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 1871 | snprintf(adapter->tx_ring->name, |
| 1872 | sizeof(adapter->tx_ring->name) - 1, |
| 1873 | "%s-tx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1874 | else |
| 1875 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); |
| 1876 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1877 | e1000_intr_msix_tx, 0, adapter->tx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1878 | netdev); |
| 1879 | if (err) |
| 1880 | goto out; |
| 1881 | adapter->tx_ring->itr_register = E1000_EITR_82574(vector); |
| 1882 | adapter->tx_ring->itr_val = adapter->itr; |
| 1883 | vector++; |
| 1884 | |
| 1885 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1886 | e1000_msix_other, 0, netdev->name, netdev); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1887 | if (err) |
| 1888 | goto out; |
| 1889 | |
| 1890 | e1000_configure_msix(adapter); |
| 1891 | return 0; |
| 1892 | out: |
| 1893 | return err; |
| 1894 | } |
| 1895 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 1896 | /** |
| 1897 | * e1000_request_irq - initialize interrupts |
| 1898 | * |
| 1899 | * Attempts to configure interrupts using the best available |
| 1900 | * capabilities of the hardware and kernel. |
| 1901 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1902 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 1903 | { |
| 1904 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1905 | int err; |
| 1906 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1907 | if (adapter->msix_entries) { |
| 1908 | err = e1000_request_msix(adapter); |
| 1909 | if (!err) |
| 1910 | return err; |
| 1911 | /* fall back to MSI */ |
| 1912 | e1000e_reset_interrupt_capability(adapter); |
| 1913 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 1914 | e1000e_set_interrupt_capability(adapter); |
| 1915 | } |
| 1916 | if (adapter->flags & FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1917 | err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1918 | netdev->name, netdev); |
| 1919 | if (!err) |
| 1920 | return err; |
| 1921 | |
| 1922 | /* fall back to legacy interrupt */ |
| 1923 | e1000e_reset_interrupt_capability(adapter); |
| 1924 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1927 | err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1928 | netdev->name, netdev); |
| 1929 | if (err) |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 1930 | e_err("Unable to allocate interrupt, Error: %d\n", err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1931 | |
| 1932 | return err; |
| 1933 | } |
| 1934 | |
| 1935 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 1936 | { |
| 1937 | struct net_device *netdev = adapter->netdev; |
| 1938 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1939 | if (adapter->msix_entries) { |
| 1940 | int vector = 0; |
| 1941 | |
| 1942 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 1943 | vector++; |
| 1944 | |
| 1945 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 1946 | vector++; |
| 1947 | |
| 1948 | /* Other Causes interrupt vector */ |
| 1949 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 1950 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1951 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1952 | |
| 1953 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | /** |
| 1957 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 1958 | **/ |
| 1959 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
| 1960 | { |
| 1961 | struct e1000_hw *hw = &adapter->hw; |
| 1962 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1963 | ew32(IMC, ~0); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1964 | if (adapter->msix_entries) |
| 1965 | ew32(EIAC_82574, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1966 | e1e_flush(); |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1967 | |
| 1968 | if (adapter->msix_entries) { |
| 1969 | int i; |
| 1970 | for (i = 0; i < adapter->num_vectors; i++) |
| 1971 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1972 | } else { |
| 1973 | synchronize_irq(adapter->pdev->irq); |
| 1974 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | /** |
| 1978 | * e1000_irq_enable - Enable default interrupt generation settings |
| 1979 | **/ |
| 1980 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
| 1981 | { |
| 1982 | struct e1000_hw *hw = &adapter->hw; |
| 1983 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1984 | if (adapter->msix_entries) { |
| 1985 | ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); |
| 1986 | ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC); |
| 1987 | } else { |
| 1988 | ew32(IMS, IMS_ENABLE_MASK); |
| 1989 | } |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 1990 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 1994 | * e1000e_get_hw_control - get control of the h/w from f/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1995 | * @adapter: address of board private structure |
| 1996 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 1997 | * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1998 | * For ASF and Pass Through versions of f/w this means that |
| 1999 | * the driver is loaded. For AMT version (only with 82573) |
| 2000 | * of the f/w this means that the network i/f is open. |
| 2001 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2002 | void e1000e_get_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2003 | { |
| 2004 | struct e1000_hw *hw = &adapter->hw; |
| 2005 | u32 ctrl_ext; |
| 2006 | u32 swsm; |
| 2007 | |
| 2008 | /* Let firmware know the driver has taken over */ |
| 2009 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2010 | swsm = er32(SWSM); |
| 2011 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
| 2012 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2013 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2014 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2019 | * e1000e_release_hw_control - release control of the h/w to f/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2020 | * @adapter: address of board private structure |
| 2021 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2022 | * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2023 | * For ASF and Pass Through versions of f/w this means that the |
| 2024 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 2025 | * of the f/w this means that the network i/f is closed. |
| 2026 | * |
| 2027 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2028 | void e1000e_release_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2029 | { |
| 2030 | struct e1000_hw *hw = &adapter->hw; |
| 2031 | u32 ctrl_ext; |
| 2032 | u32 swsm; |
| 2033 | |
| 2034 | /* Let firmware taken over control of h/w */ |
| 2035 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2036 | swsm = er32(SWSM); |
| 2037 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
| 2038 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2039 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2040 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2041 | } |
| 2042 | } |
| 2043 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2044 | /** |
| 2045 | * @e1000_alloc_ring - allocate memory for a ring structure |
| 2046 | **/ |
| 2047 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, |
| 2048 | struct e1000_ring *ring) |
| 2049 | { |
| 2050 | struct pci_dev *pdev = adapter->pdev; |
| 2051 | |
| 2052 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, |
| 2053 | GFP_KERNEL); |
| 2054 | if (!ring->desc) |
| 2055 | return -ENOMEM; |
| 2056 | |
| 2057 | return 0; |
| 2058 | } |
| 2059 | |
| 2060 | /** |
| 2061 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) |
| 2062 | * @adapter: board private structure |
| 2063 | * |
| 2064 | * Return 0 on success, negative on failure |
| 2065 | **/ |
| 2066 | int e1000e_setup_tx_resources(struct e1000_adapter *adapter) |
| 2067 | { |
| 2068 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2069 | int err = -ENOMEM, size; |
| 2070 | |
| 2071 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2072 | tx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2073 | if (!tx_ring->buffer_info) |
| 2074 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2075 | |
| 2076 | /* round up to nearest 4K */ |
| 2077 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
| 2078 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2079 | |
| 2080 | err = e1000_alloc_ring_dma(adapter, tx_ring); |
| 2081 | if (err) |
| 2082 | goto err; |
| 2083 | |
| 2084 | tx_ring->next_to_use = 0; |
| 2085 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2086 | |
| 2087 | return 0; |
| 2088 | err: |
| 2089 | vfree(tx_ring->buffer_info); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 2090 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2091 | return err; |
| 2092 | } |
| 2093 | |
| 2094 | /** |
| 2095 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) |
| 2096 | * @adapter: board private structure |
| 2097 | * |
| 2098 | * Returns 0 on success, negative on failure |
| 2099 | **/ |
| 2100 | int e1000e_setup_rx_resources(struct e1000_adapter *adapter) |
| 2101 | { |
| 2102 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2103 | struct e1000_buffer *buffer_info; |
| 2104 | int i, size, desc_len, err = -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2105 | |
| 2106 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2107 | rx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2108 | if (!rx_ring->buffer_info) |
| 2109 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2110 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2111 | for (i = 0; i < rx_ring->count; i++) { |
| 2112 | buffer_info = &rx_ring->buffer_info[i]; |
| 2113 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, |
| 2114 | sizeof(struct e1000_ps_page), |
| 2115 | GFP_KERNEL); |
| 2116 | if (!buffer_info->ps_pages) |
| 2117 | goto err_pages; |
| 2118 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2119 | |
| 2120 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 2121 | |
| 2122 | /* Round up to nearest 4K */ |
| 2123 | rx_ring->size = rx_ring->count * desc_len; |
| 2124 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2125 | |
| 2126 | err = e1000_alloc_ring_dma(adapter, rx_ring); |
| 2127 | if (err) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2128 | goto err_pages; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2129 | |
| 2130 | rx_ring->next_to_clean = 0; |
| 2131 | rx_ring->next_to_use = 0; |
| 2132 | rx_ring->rx_skb_top = NULL; |
| 2133 | |
| 2134 | return 0; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2135 | |
| 2136 | err_pages: |
| 2137 | for (i = 0; i < rx_ring->count; i++) { |
| 2138 | buffer_info = &rx_ring->buffer_info[i]; |
| 2139 | kfree(buffer_info->ps_pages); |
| 2140 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2141 | err: |
| 2142 | vfree(rx_ring->buffer_info); |
Bruce Allan | e926244 | 2010-11-24 06:02:06 +0000 | [diff] [blame] | 2143 | e_err("Unable to allocate memory for the receive descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2144 | return err; |
| 2145 | } |
| 2146 | |
| 2147 | /** |
| 2148 | * e1000_clean_tx_ring - Free Tx Buffers |
| 2149 | * @adapter: board private structure |
| 2150 | **/ |
| 2151 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter) |
| 2152 | { |
| 2153 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2154 | struct e1000_buffer *buffer_info; |
| 2155 | unsigned long size; |
| 2156 | unsigned int i; |
| 2157 | |
| 2158 | for (i = 0; i < tx_ring->count; i++) { |
| 2159 | buffer_info = &tx_ring->buffer_info[i]; |
| 2160 | e1000_put_txbuf(adapter, buffer_info); |
| 2161 | } |
| 2162 | |
| 2163 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2164 | memset(tx_ring->buffer_info, 0, size); |
| 2165 | |
| 2166 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2167 | |
| 2168 | tx_ring->next_to_use = 0; |
| 2169 | tx_ring->next_to_clean = 0; |
| 2170 | |
| 2171 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 2172 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
| 2173 | } |
| 2174 | |
| 2175 | /** |
| 2176 | * e1000e_free_tx_resources - Free Tx Resources per Queue |
| 2177 | * @adapter: board private structure |
| 2178 | * |
| 2179 | * Free all transmit software resources |
| 2180 | **/ |
| 2181 | void e1000e_free_tx_resources(struct e1000_adapter *adapter) |
| 2182 | { |
| 2183 | struct pci_dev *pdev = adapter->pdev; |
| 2184 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2185 | |
| 2186 | e1000_clean_tx_ring(adapter); |
| 2187 | |
| 2188 | vfree(tx_ring->buffer_info); |
| 2189 | tx_ring->buffer_info = NULL; |
| 2190 | |
| 2191 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 2192 | tx_ring->dma); |
| 2193 | tx_ring->desc = NULL; |
| 2194 | } |
| 2195 | |
| 2196 | /** |
| 2197 | * e1000e_free_rx_resources - Free Rx Resources |
| 2198 | * @adapter: board private structure |
| 2199 | * |
| 2200 | * Free all receive software resources |
| 2201 | **/ |
| 2202 | |
| 2203 | void e1000e_free_rx_resources(struct e1000_adapter *adapter) |
| 2204 | { |
| 2205 | struct pci_dev *pdev = adapter->pdev; |
| 2206 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2207 | int i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2208 | |
| 2209 | e1000_clean_rx_ring(adapter); |
| 2210 | |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2211 | for (i = 0; i < rx_ring->count; i++) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2212 | kfree(rx_ring->buffer_info[i].ps_pages); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2213 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2214 | vfree(rx_ring->buffer_info); |
| 2215 | rx_ring->buffer_info = NULL; |
| 2216 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2217 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 2218 | rx_ring->dma); |
| 2219 | rx_ring->desc = NULL; |
| 2220 | } |
| 2221 | |
| 2222 | /** |
| 2223 | * e1000_update_itr - update the dynamic ITR value based on statistics |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2224 | * @adapter: pointer to adapter |
| 2225 | * @itr_setting: current adapter->itr |
| 2226 | * @packets: the number of packets during this measurement interval |
| 2227 | * @bytes: the number of bytes during this measurement interval |
| 2228 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2229 | * Stores a new ITR value based on packets and byte |
| 2230 | * counts during the last interrupt. The advantage of per interrupt |
| 2231 | * computation is faster updates and more accurate ITR for the current |
| 2232 | * traffic pattern. Constants in this function were computed |
| 2233 | * based on theoretical maximum wire speed and thresholds were set based |
| 2234 | * on testing data as well as attempting to minimize response time |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2235 | * while increasing bulk throughput. This functionality is controlled |
| 2236 | * by the InterruptThrottleRate module parameter. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2237 | **/ |
| 2238 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
| 2239 | u16 itr_setting, int packets, |
| 2240 | int bytes) |
| 2241 | { |
| 2242 | unsigned int retval = itr_setting; |
| 2243 | |
| 2244 | if (packets == 0) |
| 2245 | goto update_itr_done; |
| 2246 | |
| 2247 | switch (itr_setting) { |
| 2248 | case lowest_latency: |
| 2249 | /* handle TSO and jumbo frames */ |
| 2250 | if (bytes/packets > 8000) |
| 2251 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2252 | else if ((packets < 5) && (bytes > 512)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2253 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2254 | break; |
| 2255 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2256 | if (bytes > 10000) { |
| 2257 | /* this if handles the TSO accounting */ |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2258 | if (bytes/packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2259 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2260 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2261 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2262 | else if ((packets > 35)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2263 | retval = lowest_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2264 | } else if (bytes/packets > 2000) { |
| 2265 | retval = bulk_latency; |
| 2266 | } else if (packets <= 2 && bytes < 512) { |
| 2267 | retval = lowest_latency; |
| 2268 | } |
| 2269 | break; |
| 2270 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2271 | if (bytes > 25000) { |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2272 | if (packets > 35) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2273 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2274 | } else if (bytes < 6000) { |
| 2275 | retval = low_latency; |
| 2276 | } |
| 2277 | break; |
| 2278 | } |
| 2279 | |
| 2280 | update_itr_done: |
| 2281 | return retval; |
| 2282 | } |
| 2283 | |
| 2284 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2285 | { |
| 2286 | struct e1000_hw *hw = &adapter->hw; |
| 2287 | u16 current_itr; |
| 2288 | u32 new_itr = adapter->itr; |
| 2289 | |
| 2290 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2291 | if (adapter->link_speed != SPEED_1000) { |
| 2292 | current_itr = 0; |
| 2293 | new_itr = 4000; |
| 2294 | goto set_itr_now; |
| 2295 | } |
| 2296 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2297 | if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 2298 | new_itr = 0; |
| 2299 | goto set_itr_now; |
| 2300 | } |
| 2301 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2302 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2303 | adapter->tx_itr, |
| 2304 | adapter->total_tx_packets, |
| 2305 | adapter->total_tx_bytes); |
| 2306 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2307 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2308 | adapter->tx_itr = low_latency; |
| 2309 | |
| 2310 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2311 | adapter->rx_itr, |
| 2312 | adapter->total_rx_packets, |
| 2313 | adapter->total_rx_bytes); |
| 2314 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2315 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2316 | adapter->rx_itr = low_latency; |
| 2317 | |
| 2318 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2319 | |
| 2320 | switch (current_itr) { |
| 2321 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2322 | case lowest_latency: |
| 2323 | new_itr = 70000; |
| 2324 | break; |
| 2325 | case low_latency: |
| 2326 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2327 | break; |
| 2328 | case bulk_latency: |
| 2329 | new_itr = 4000; |
| 2330 | break; |
| 2331 | default: |
| 2332 | break; |
| 2333 | } |
| 2334 | |
| 2335 | set_itr_now: |
| 2336 | if (new_itr != adapter->itr) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2337 | /* |
| 2338 | * this attempts to bias the interrupt rate towards Bulk |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2339 | * by adding intermediate steps when interrupt rate is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2340 | * increasing |
| 2341 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2342 | new_itr = new_itr > adapter->itr ? |
| 2343 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2344 | new_itr; |
| 2345 | adapter->itr = new_itr; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2346 | adapter->rx_ring->itr_val = new_itr; |
| 2347 | if (adapter->msix_entries) |
| 2348 | adapter->rx_ring->set_itr = 1; |
| 2349 | else |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2350 | if (new_itr) |
| 2351 | ew32(ITR, 1000000000 / (new_itr * 256)); |
| 2352 | else |
| 2353 | ew32(ITR, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | /** |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2358 | * e1000_alloc_queues - Allocate memory for all rings |
| 2359 | * @adapter: board private structure to initialize |
| 2360 | **/ |
| 2361 | static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) |
| 2362 | { |
| 2363 | adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
| 2364 | if (!adapter->tx_ring) |
| 2365 | goto err; |
| 2366 | |
| 2367 | adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
| 2368 | if (!adapter->rx_ring) |
| 2369 | goto err; |
| 2370 | |
| 2371 | return 0; |
| 2372 | err: |
| 2373 | e_err("Unable to allocate memory for queues\n"); |
| 2374 | kfree(adapter->rx_ring); |
| 2375 | kfree(adapter->tx_ring); |
| 2376 | return -ENOMEM; |
| 2377 | } |
| 2378 | |
| 2379 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2380 | * e1000_clean - NAPI Rx polling callback |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2381 | * @napi: struct associated with this polling callback |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2382 | * @budget: amount of packets driver is allowed to process this poll |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2383 | **/ |
| 2384 | static int e1000_clean(struct napi_struct *napi, int budget) |
| 2385 | { |
| 2386 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2387 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2388 | struct net_device *poll_dev = adapter->netdev; |
Andy Gospodarek | 679e8a0 | 2009-06-18 11:57:37 +0000 | [diff] [blame] | 2389 | int tx_cleaned = 1, work_done = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2390 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 2391 | adapter = netdev_priv(poll_dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2392 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2393 | if (adapter->msix_entries && |
| 2394 | !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) |
| 2395 | goto clean_rx; |
| 2396 | |
Jesse Brandeburg | 92af3e9 | 2009-01-19 14:17:08 +0000 | [diff] [blame] | 2397 | tx_cleaned = e1000_clean_tx_irq(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2398 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2399 | clean_rx: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2400 | adapter->clean_rx(adapter, &work_done, budget); |
| 2401 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 2402 | if (!tx_cleaned) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2403 | work_done = budget; |
| 2404 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 2405 | /* If budget not fully consumed, exit the polling mode */ |
| 2406 | if (work_done < budget) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2407 | if (adapter->itr_setting & 3) |
| 2408 | e1000_set_itr(adapter); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2409 | napi_complete(napi); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 2410 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 2411 | if (adapter->msix_entries) |
| 2412 | ew32(IMS, adapter->rx_ring->ims_val); |
| 2413 | else |
| 2414 | e1000_irq_enable(adapter); |
| 2415 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | return work_done; |
| 2419 | } |
| 2420 | |
| 2421 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2422 | { |
| 2423 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2424 | struct e1000_hw *hw = &adapter->hw; |
| 2425 | u32 vfta, index; |
| 2426 | |
| 2427 | /* don't update vlan cookie if already programmed */ |
| 2428 | if ((adapter->hw.mng_cookie.status & |
| 2429 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2430 | (vid == adapter->mng_vlan_id)) |
| 2431 | return; |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2432 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2433 | /* add VID to filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2434 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2435 | index = (vid >> 5) & 0x7F; |
| 2436 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2437 | vfta |= (1 << (vid & 0x1F)); |
| 2438 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2439 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2440 | |
| 2441 | set_bit(vid, adapter->active_vlans); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2445 | { |
| 2446 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2447 | struct e1000_hw *hw = &adapter->hw; |
| 2448 | u32 vfta, index; |
| 2449 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2450 | if ((adapter->hw.mng_cookie.status & |
| 2451 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2452 | (vid == adapter->mng_vlan_id)) { |
| 2453 | /* release control to f/w */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2454 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2455 | return; |
| 2456 | } |
| 2457 | |
| 2458 | /* remove VID from filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2459 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2460 | index = (vid >> 5) & 0x7F; |
| 2461 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2462 | vfta &= ~(1 << (vid & 0x1F)); |
| 2463 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2464 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2465 | |
| 2466 | clear_bit(vid, adapter->active_vlans); |
| 2467 | } |
| 2468 | |
| 2469 | /** |
| 2470 | * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering |
| 2471 | * @adapter: board private structure to initialize |
| 2472 | **/ |
| 2473 | static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter) |
| 2474 | { |
| 2475 | struct net_device *netdev = adapter->netdev; |
| 2476 | struct e1000_hw *hw = &adapter->hw; |
| 2477 | u32 rctl; |
| 2478 | |
| 2479 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2480 | /* disable VLAN receive filtering */ |
| 2481 | rctl = er32(RCTL); |
| 2482 | rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN); |
| 2483 | ew32(RCTL, rctl); |
| 2484 | |
| 2485 | if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { |
| 2486 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 2487 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 2488 | } |
| 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | /** |
| 2493 | * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering |
| 2494 | * @adapter: board private structure to initialize |
| 2495 | **/ |
| 2496 | static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter) |
| 2497 | { |
| 2498 | struct e1000_hw *hw = &adapter->hw; |
| 2499 | u32 rctl; |
| 2500 | |
| 2501 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2502 | /* enable VLAN receive filtering */ |
| 2503 | rctl = er32(RCTL); |
| 2504 | rctl |= E1000_RCTL_VFE; |
| 2505 | rctl &= ~E1000_RCTL_CFIEN; |
| 2506 | ew32(RCTL, rctl); |
| 2507 | } |
| 2508 | } |
| 2509 | |
| 2510 | /** |
| 2511 | * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping |
| 2512 | * @adapter: board private structure to initialize |
| 2513 | **/ |
| 2514 | static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter) |
| 2515 | { |
| 2516 | struct e1000_hw *hw = &adapter->hw; |
| 2517 | u32 ctrl; |
| 2518 | |
| 2519 | /* disable VLAN tag insert/strip */ |
| 2520 | ctrl = er32(CTRL); |
| 2521 | ctrl &= ~E1000_CTRL_VME; |
| 2522 | ew32(CTRL, ctrl); |
| 2523 | } |
| 2524 | |
| 2525 | /** |
| 2526 | * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping |
| 2527 | * @adapter: board private structure to initialize |
| 2528 | **/ |
| 2529 | static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter) |
| 2530 | { |
| 2531 | struct e1000_hw *hw = &adapter->hw; |
| 2532 | u32 ctrl; |
| 2533 | |
| 2534 | /* enable VLAN tag insert/strip */ |
| 2535 | ctrl = er32(CTRL); |
| 2536 | ctrl |= E1000_CTRL_VME; |
| 2537 | ew32(CTRL, ctrl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 2541 | { |
| 2542 | struct net_device *netdev = adapter->netdev; |
| 2543 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 2544 | u16 old_vid = adapter->mng_vlan_id; |
| 2545 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2546 | if (adapter->hw.mng_cookie.status & |
| 2547 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
| 2548 | e1000_vlan_rx_add_vid(netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2549 | adapter->mng_vlan_id = vid; |
| 2550 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2551 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2552 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid)) |
| 2553 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
| 2557 | { |
| 2558 | u16 vid; |
| 2559 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2560 | e1000_vlan_rx_add_vid(adapter->netdev, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2561 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2562 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2563 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2566 | static void e1000_init_manageability_pt(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2567 | { |
| 2568 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2569 | u32 manc, manc2h, mdef, i, j; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2570 | |
| 2571 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) |
| 2572 | return; |
| 2573 | |
| 2574 | manc = er32(MANC); |
| 2575 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2576 | /* |
| 2577 | * enable receiving management packets to the host. this will probably |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2578 | * generate destination unreachable messages from the host OS, but |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2579 | * the packets will be handled on SMBUS |
| 2580 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2581 | manc |= E1000_MANC_EN_MNG2HOST; |
| 2582 | manc2h = er32(MANC2H); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2583 | |
| 2584 | switch (hw->mac.type) { |
| 2585 | default: |
| 2586 | manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664); |
| 2587 | break; |
| 2588 | case e1000_82574: |
| 2589 | case e1000_82583: |
| 2590 | /* |
| 2591 | * Check if IPMI pass-through decision filter already exists; |
| 2592 | * if so, enable it. |
| 2593 | */ |
| 2594 | for (i = 0, j = 0; i < 8; i++) { |
| 2595 | mdef = er32(MDEF(i)); |
| 2596 | |
| 2597 | /* Ignore filters with anything other than IPMI ports */ |
Dan Carpenter | 3b21b50 | 2010-06-02 13:43:15 +0000 | [diff] [blame] | 2598 | if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2599 | continue; |
| 2600 | |
| 2601 | /* Enable this decision filter in MANC2H */ |
| 2602 | if (mdef) |
| 2603 | manc2h |= (1 << i); |
| 2604 | |
| 2605 | j |= mdef; |
| 2606 | } |
| 2607 | |
| 2608 | if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
| 2609 | break; |
| 2610 | |
| 2611 | /* Create new decision filter in an empty filter */ |
| 2612 | for (i = 0, j = 0; i < 8; i++) |
| 2613 | if (er32(MDEF(i)) == 0) { |
| 2614 | ew32(MDEF(i), (E1000_MDEF_PORT_623 | |
| 2615 | E1000_MDEF_PORT_664)); |
| 2616 | manc2h |= (1 << 1); |
| 2617 | j++; |
| 2618 | break; |
| 2619 | } |
| 2620 | |
| 2621 | if (!j) |
| 2622 | e_warn("Unable to create IPMI pass-through filter\n"); |
| 2623 | break; |
| 2624 | } |
| 2625 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2626 | ew32(MANC2H, manc2h); |
| 2627 | ew32(MANC, manc); |
| 2628 | } |
| 2629 | |
| 2630 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2631 | * e1000_configure_tx - Configure Transmit Unit after Reset |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2632 | * @adapter: board private structure |
| 2633 | * |
| 2634 | * Configure the Tx unit of the MAC after a reset. |
| 2635 | **/ |
| 2636 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
| 2637 | { |
| 2638 | struct e1000_hw *hw = &adapter->hw; |
| 2639 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2640 | u64 tdba; |
| 2641 | u32 tdlen, tctl, tipg, tarc; |
| 2642 | u32 ipgr1, ipgr2; |
| 2643 | |
| 2644 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 2645 | tdba = tx_ring->dma; |
| 2646 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2647 | ew32(TDBAL, (tdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2648 | ew32(TDBAH, (tdba >> 32)); |
| 2649 | ew32(TDLEN, tdlen); |
| 2650 | ew32(TDH, 0); |
| 2651 | ew32(TDT, 0); |
| 2652 | tx_ring->head = E1000_TDH; |
| 2653 | tx_ring->tail = E1000_TDT; |
| 2654 | |
| 2655 | /* Set the default values for the Tx Inter Packet Gap timer */ |
| 2656 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */ |
| 2657 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */ |
| 2658 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */ |
| 2659 | |
| 2660 | if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN) |
| 2661 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */ |
| 2662 | |
| 2663 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 2664 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
| 2665 | ew32(TIPG, tipg); |
| 2666 | |
| 2667 | /* Set the Tx Interrupt Delay register */ |
| 2668 | ew32(TIDV, adapter->tx_int_delay); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2669 | /* Tx irq moderation */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2670 | ew32(TADV, adapter->tx_abs_int_delay); |
| 2671 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2672 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 2673 | u32 txdctl = er32(TXDCTL(0)); |
| 2674 | txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH | |
| 2675 | E1000_TXDCTL_WTHRESH); |
| 2676 | /* |
| 2677 | * set up some performance related parameters to encourage the |
| 2678 | * hardware to use the bus more efficiently in bursts, depends |
| 2679 | * on the tx_int_delay to be enabled, |
| 2680 | * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time |
| 2681 | * hthresh = 1 ==> prefetch when one or more available |
| 2682 | * pthresh = 0x1f ==> prefetch if internal cache 31 or less |
| 2683 | * BEWARE: this seems to work but should be considered first if |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2684 | * there are Tx hangs or other Tx related bugs |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2685 | */ |
| 2686 | txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE; |
| 2687 | ew32(TXDCTL(0), txdctl); |
| 2688 | /* erratum work around: set txdctl the same for both queues */ |
| 2689 | ew32(TXDCTL(1), txdctl); |
| 2690 | } |
| 2691 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2692 | /* Program the Transmit Control Register */ |
| 2693 | tctl = er32(TCTL); |
| 2694 | tctl &= ~E1000_TCTL_CT; |
| 2695 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
| 2696 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 2697 | |
| 2698 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2699 | tarc = er32(TARC(0)); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2700 | /* |
| 2701 | * set the speed mode bit, we'll clear it if we're not at |
| 2702 | * gigabit link later |
| 2703 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2704 | #define SPEED_MODE_BIT (1 << 21) |
| 2705 | tarc |= SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2706 | ew32(TARC(0), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | /* errata: program both queues to unweighted RR */ |
| 2710 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2711 | tarc = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2712 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2713 | ew32(TARC(0), tarc); |
| 2714 | tarc = er32(TARC(1)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2715 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2716 | ew32(TARC(1), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2717 | } |
| 2718 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2719 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 2720 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 2721 | |
| 2722 | /* only set IDE if we are delaying interrupts using the timers */ |
| 2723 | if (adapter->tx_int_delay) |
| 2724 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
| 2725 | |
| 2726 | /* enable Report Status bit */ |
| 2727 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 2728 | |
| 2729 | ew32(TCTL, tctl); |
| 2730 | |
Simon Horman | edfea6e6 | 2009-06-08 14:28:36 +0000 | [diff] [blame] | 2731 | e1000e_config_collision_dist(hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | /** |
| 2735 | * e1000_setup_rctl - configure the receive control registers |
| 2736 | * @adapter: Board private structure |
| 2737 | **/ |
| 2738 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 2739 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
| 2740 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
| 2741 | { |
| 2742 | struct e1000_hw *hw = &adapter->hw; |
| 2743 | u32 rctl, rfctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2744 | u32 pages = 0; |
| 2745 | |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 2746 | /* Workaround Si errata on 82579 - configure jumbo frame flow */ |
| 2747 | if (hw->mac.type == e1000_pch2lan) { |
| 2748 | s32 ret_val; |
| 2749 | |
| 2750 | if (adapter->netdev->mtu > ETH_DATA_LEN) |
| 2751 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true); |
| 2752 | else |
| 2753 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false); |
Bruce Allan | dd93f95 | 2011-01-06 14:29:48 +0000 | [diff] [blame] | 2754 | |
| 2755 | if (ret_val) |
| 2756 | e_dbg("failed to enable jumbo frame workaround mode\n"); |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 2757 | } |
| 2758 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2759 | /* Program MC offset vector base */ |
| 2760 | rctl = er32(RCTL); |
| 2761 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 2762 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 2763 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 2764 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 2765 | |
| 2766 | /* Do not Store bad packets */ |
| 2767 | rctl &= ~E1000_RCTL_SBP; |
| 2768 | |
| 2769 | /* Enable Long Packet receive */ |
| 2770 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2771 | rctl &= ~E1000_RCTL_LPE; |
| 2772 | else |
| 2773 | rctl |= E1000_RCTL_LPE; |
| 2774 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 2775 | /* Some systems expect that the CRC is included in SMBUS traffic. The |
| 2776 | * hardware strips the CRC before sending to both SMBUS (BMC) and to |
| 2777 | * host memory when this is enabled |
| 2778 | */ |
| 2779 | if (adapter->flags2 & FLAG2_CRC_STRIPPING) |
| 2780 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 5918bd8 | 2008-02-12 15:20:24 -0800 | [diff] [blame] | 2781 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 2782 | /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ |
| 2783 | if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { |
| 2784 | u16 phy_data; |
| 2785 | |
| 2786 | e1e_rphy(hw, PHY_REG(770, 26), &phy_data); |
| 2787 | phy_data &= 0xfff8; |
| 2788 | phy_data |= (1 << 2); |
| 2789 | e1e_wphy(hw, PHY_REG(770, 26), phy_data); |
| 2790 | |
| 2791 | e1e_rphy(hw, 22, &phy_data); |
| 2792 | phy_data &= 0x0fff; |
| 2793 | phy_data |= (1 << 14); |
| 2794 | e1e_wphy(hw, 0x10, 0x2823); |
| 2795 | e1e_wphy(hw, 0x11, 0x0003); |
| 2796 | e1e_wphy(hw, 22, phy_data); |
| 2797 | } |
| 2798 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2799 | /* Setup buffer sizes */ |
| 2800 | rctl &= ~E1000_RCTL_SZ_4096; |
| 2801 | rctl |= E1000_RCTL_BSEX; |
| 2802 | switch (adapter->rx_buffer_len) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2803 | case 2048: |
| 2804 | default: |
| 2805 | rctl |= E1000_RCTL_SZ_2048; |
| 2806 | rctl &= ~E1000_RCTL_BSEX; |
| 2807 | break; |
| 2808 | case 4096: |
| 2809 | rctl |= E1000_RCTL_SZ_4096; |
| 2810 | break; |
| 2811 | case 8192: |
| 2812 | rctl |= E1000_RCTL_SZ_8192; |
| 2813 | break; |
| 2814 | case 16384: |
| 2815 | rctl |= E1000_RCTL_SZ_16384; |
| 2816 | break; |
| 2817 | } |
| 2818 | |
| 2819 | /* |
| 2820 | * 82571 and greater support packet-split where the protocol |
| 2821 | * header is placed in skb->data and the packet data is |
| 2822 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 2823 | * In the case of a non-split, skb->data is linearly filled, |
| 2824 | * followed by the page buffers. Therefore, skb->data is |
| 2825 | * sized to hold the largest protocol header. |
| 2826 | * |
| 2827 | * allocations using alloc_page take too long for regular MTU |
| 2828 | * so only enable packet split for jumbo frames |
| 2829 | * |
| 2830 | * Using pages when the page size is greater than 16k wastes |
| 2831 | * a lot of memory, since we allocate 3 pages at all times |
| 2832 | * per packet. |
| 2833 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2834 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Bruce Allan | dbcb9fe | 2010-06-17 18:59:27 +0000 | [diff] [blame] | 2835 | if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) && |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2836 | (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2837 | adapter->rx_ps_pages = pages; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2838 | else |
| 2839 | adapter->rx_ps_pages = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2840 | |
| 2841 | if (adapter->rx_ps_pages) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 2842 | u32 psrctl = 0; |
| 2843 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2844 | /* Configure extra packet-split registers */ |
| 2845 | rfctl = er32(RFCTL); |
| 2846 | rfctl |= E1000_RFCTL_EXTEN; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2847 | /* |
| 2848 | * disable packet split support for IPv6 extension headers, |
| 2849 | * because some malformed IPv6 headers can hang the Rx |
| 2850 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2851 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
| 2852 | E1000_RFCTL_NEW_IPV6_EXT_DIS); |
| 2853 | |
| 2854 | ew32(RFCTL, rfctl); |
| 2855 | |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 2856 | /* Enable Packet split descriptors */ |
| 2857 | rctl |= E1000_RCTL_DTYP_PS; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2858 | |
| 2859 | psrctl |= adapter->rx_ps_bsize0 >> |
| 2860 | E1000_PSRCTL_BSIZE0_SHIFT; |
| 2861 | |
| 2862 | switch (adapter->rx_ps_pages) { |
| 2863 | case 3: |
| 2864 | psrctl |= PAGE_SIZE << |
| 2865 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 2866 | case 2: |
| 2867 | psrctl |= PAGE_SIZE << |
| 2868 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 2869 | case 1: |
| 2870 | psrctl |= PAGE_SIZE >> |
| 2871 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 2872 | break; |
| 2873 | } |
| 2874 | |
| 2875 | ew32(PSRCTL, psrctl); |
| 2876 | } |
| 2877 | |
| 2878 | ew32(RCTL, rctl); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2879 | /* just started the receive unit, no need to restart */ |
| 2880 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2881 | } |
| 2882 | |
| 2883 | /** |
| 2884 | * e1000_configure_rx - Configure Receive Unit after Reset |
| 2885 | * @adapter: board private structure |
| 2886 | * |
| 2887 | * Configure the Rx unit of the MAC after a reset. |
| 2888 | **/ |
| 2889 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
| 2890 | { |
| 2891 | struct e1000_hw *hw = &adapter->hw; |
| 2892 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 2893 | u64 rdba; |
| 2894 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
| 2895 | |
| 2896 | if (adapter->rx_ps_pages) { |
| 2897 | /* this is a 32 byte descriptor */ |
| 2898 | rdlen = rx_ring->count * |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2899 | sizeof(union e1000_rx_desc_packet_split); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2900 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 2901 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2902 | } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { |
| 2903 | rdlen = rx_ring->count * sizeof(struct e1000_rx_desc); |
| 2904 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 2905 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2906 | } else { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2907 | rdlen = rx_ring->count * sizeof(struct e1000_rx_desc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2908 | adapter->clean_rx = e1000_clean_rx_irq; |
| 2909 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 2910 | } |
| 2911 | |
| 2912 | /* disable receives while setting up the descriptors */ |
| 2913 | rctl = er32(RCTL); |
| 2914 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 2915 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 2916 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2917 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2918 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 2919 | /* |
| 2920 | * set the writeback threshold (only takes effect if the RDTR |
| 2921 | * is set). set GRAN=1 and write back up to 0x4 worth, and |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2922 | * enable prefetching of 0x20 Rx descriptors |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2923 | * granularity = 01 |
| 2924 | * wthresh = 04, |
| 2925 | * hthresh = 04, |
| 2926 | * pthresh = 0x20 |
| 2927 | */ |
| 2928 | ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 2929 | ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 2930 | |
| 2931 | /* |
| 2932 | * override the delay timers for enabling bursting, only if |
| 2933 | * the value was not set by the user via module options |
| 2934 | */ |
| 2935 | if (adapter->rx_int_delay == DEFAULT_RDTR) |
| 2936 | adapter->rx_int_delay = BURST_RDTR; |
| 2937 | if (adapter->rx_abs_int_delay == DEFAULT_RADV) |
| 2938 | adapter->rx_abs_int_delay = BURST_RADV; |
| 2939 | } |
| 2940 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2941 | /* set the Receive Delay Timer Register */ |
| 2942 | ew32(RDTR, adapter->rx_int_delay); |
| 2943 | |
| 2944 | /* irq moderation */ |
| 2945 | ew32(RADV, adapter->rx_abs_int_delay); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2946 | if ((adapter->itr_setting != 0) && (adapter->itr != 0)) |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2947 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2948 | |
| 2949 | ctrl_ext = er32(CTRL_EXT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2950 | /* Auto-Mask interrupts upon ICR access */ |
| 2951 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 2952 | ew32(IAM, 0xffffffff); |
| 2953 | ew32(CTRL_EXT, ctrl_ext); |
| 2954 | e1e_flush(); |
| 2955 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2956 | /* |
| 2957 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2958 | * the Base and Length of the Rx Descriptor Ring |
| 2959 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2960 | rdba = rx_ring->dma; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2961 | ew32(RDBAL, (rdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2962 | ew32(RDBAH, (rdba >> 32)); |
| 2963 | ew32(RDLEN, rdlen); |
| 2964 | ew32(RDH, 0); |
| 2965 | ew32(RDT, 0); |
| 2966 | rx_ring->head = E1000_RDH; |
| 2967 | rx_ring->tail = E1000_RDT; |
| 2968 | |
| 2969 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 2970 | rxcsum = er32(RXCSUM); |
| 2971 | if (adapter->flags & FLAG_RX_CSUM_ENABLED) { |
| 2972 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 2973 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2974 | /* |
| 2975 | * IPv4 payload checksum for UDP fragments must be |
| 2976 | * used in conjunction with packet-split. |
| 2977 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2978 | if (adapter->rx_ps_pages) |
| 2979 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 2980 | } else { |
| 2981 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 2982 | /* no need to clear IPPCSE as it defaults to 0 */ |
| 2983 | } |
| 2984 | ew32(RXCSUM, rxcsum); |
| 2985 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2986 | /* |
| 2987 | * Enable early receives on supported devices, only takes effect when |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2988 | * 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] | 2989 | * units), e.g. using jumbo frames when setting to E1000_ERT_2048 |
| 2990 | */ |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2991 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 2992 | (adapter->hw.mac.type == e1000_pch2lan)) { |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 2993 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 2994 | u32 rxdctl = er32(RXDCTL(0)); |
| 2995 | ew32(RXDCTL(0), rxdctl | 0x3); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2996 | if (adapter->flags & FLAG_HAS_ERT) |
| 2997 | ew32(ERT, E1000_ERT_2048 | (1 << 13)); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 2998 | /* |
| 2999 | * With jumbo frames and early-receive enabled, |
| 3000 | * excessive C-state transition latencies result in |
| 3001 | * dropped transactions. |
| 3002 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3003 | pm_qos_update_request(&adapter->netdev->pm_qos_req, 55); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3004 | } else { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3005 | pm_qos_update_request(&adapter->netdev->pm_qos_req, |
| 3006 | PM_QOS_DEFAULT_VALUE); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3007 | } |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3008 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3009 | |
| 3010 | /* Enable Receives */ |
| 3011 | ew32(RCTL, rctl); |
| 3012 | } |
| 3013 | |
| 3014 | /** |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 3015 | * e1000_update_mc_addr_list - Update Multicast addresses |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3016 | * @hw: pointer to the HW structure |
| 3017 | * @mc_addr_list: array of multicast addresses to program |
| 3018 | * @mc_addr_count: number of multicast addresses to program |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3019 | * |
Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 3020 | * Updates the Multicast Table Array. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3021 | * The caller must have a packed mc_addr_list of multicast addresses. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3022 | **/ |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 3023 | static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list, |
Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 3024 | u32 mc_addr_count) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3025 | { |
Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 3026 | 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] | 3027 | } |
| 3028 | |
| 3029 | /** |
| 3030 | * e1000_set_multi - Multicast and Promiscuous mode set |
| 3031 | * @netdev: network interface device structure |
| 3032 | * |
| 3033 | * The set_multi entry point is called whenever the multicast address |
| 3034 | * list or the network interface flags are updated. This routine is |
| 3035 | * responsible for configuring the hardware for proper multicast, |
| 3036 | * promiscuous mode, and all-multi behavior. |
| 3037 | **/ |
| 3038 | static void e1000_set_multi(struct net_device *netdev) |
| 3039 | { |
| 3040 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3041 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3042 | struct netdev_hw_addr *ha; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3043 | u8 *mta_list; |
| 3044 | u32 rctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3045 | |
| 3046 | /* Check for Promiscuous and All Multicast modes */ |
| 3047 | |
| 3048 | rctl = er32(RCTL); |
| 3049 | |
| 3050 | if (netdev->flags & IFF_PROMISC) { |
| 3051 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3052 | rctl &= ~E1000_RCTL_VFE; |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3053 | /* Do not hardware filter VLANs in promisc mode */ |
| 3054 | e1000e_vlan_filter_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3055 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3056 | if (netdev->flags & IFF_ALLMULTI) { |
| 3057 | rctl |= E1000_RCTL_MPE; |
| 3058 | rctl &= ~E1000_RCTL_UPE; |
| 3059 | } else { |
| 3060 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 3061 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3062 | e1000e_vlan_filter_enable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | ew32(RCTL, rctl); |
| 3066 | |
Jiri Pirko | 7aeef97 | 2010-02-05 02:52:39 +0000 | [diff] [blame] | 3067 | if (!netdev_mc_empty(netdev)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 3068 | int i = 0; |
| 3069 | |
Jiri Pirko | 7aeef97 | 2010-02-05 02:52:39 +0000 | [diff] [blame] | 3070 | mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3071 | if (!mta_list) |
| 3072 | return; |
| 3073 | |
| 3074 | /* prepare a packed array of only addresses. */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3075 | netdev_for_each_mc_addr(ha, netdev) |
| 3076 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3077 | |
Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 3078 | e1000_update_mc_addr_list(hw, mta_list, i); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3079 | kfree(mta_list); |
| 3080 | } else { |
| 3081 | /* |
| 3082 | * if we're called from probe, we might not have |
| 3083 | * anything to do here, so clear out the list |
| 3084 | */ |
Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 3085 | e1000_update_mc_addr_list(hw, NULL, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3086 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3087 | |
| 3088 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3089 | e1000e_vlan_strip_enable(adapter); |
| 3090 | else |
| 3091 | e1000e_vlan_strip_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3095 | * e1000_configure - configure the hardware for Rx and Tx |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3096 | * @adapter: private board structure |
| 3097 | **/ |
| 3098 | static void e1000_configure(struct e1000_adapter *adapter) |
| 3099 | { |
| 3100 | e1000_set_multi(adapter->netdev); |
| 3101 | |
| 3102 | e1000_restore_vlan(adapter); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 3103 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3104 | |
| 3105 | e1000_configure_tx(adapter); |
| 3106 | e1000_setup_rctl(adapter); |
| 3107 | e1000_configure_rx(adapter); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3108 | adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | /** |
| 3112 | * e1000e_power_up_phy - restore link in case the phy was powered down |
| 3113 | * @adapter: address of board private structure |
| 3114 | * |
| 3115 | * The phy may be powered down to save power and turn off link when the |
| 3116 | * driver is unloaded and wake on lan is not enabled (among others) |
| 3117 | * *** this routine MUST be followed by a call to e1000e_reset *** |
| 3118 | **/ |
| 3119 | void e1000e_power_up_phy(struct e1000_adapter *adapter) |
| 3120 | { |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3121 | if (adapter->hw.phy.ops.power_up) |
| 3122 | adapter->hw.phy.ops.power_up(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3123 | |
| 3124 | adapter->hw.mac.ops.setup_link(&adapter->hw); |
| 3125 | } |
| 3126 | |
| 3127 | /** |
| 3128 | * e1000_power_down_phy - Power down the PHY |
| 3129 | * |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3130 | * Power down the PHY so no link is implied when interface is down. |
| 3131 | * The PHY cannot be powered down if management or WoL is active. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3132 | */ |
| 3133 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 3134 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3135 | /* WoL is enabled */ |
Auke Kok | 23b66e2 | 2008-02-11 09:25:51 -0800 | [diff] [blame] | 3136 | if (adapter->wol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3137 | return; |
| 3138 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3139 | if (adapter->hw.phy.ops.power_down) |
| 3140 | adapter->hw.phy.ops.power_down(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | /** |
| 3144 | * e1000e_reset - bring the hardware into a known good state |
| 3145 | * |
| 3146 | * This function boots the hardware and enables some settings that |
| 3147 | * require a configuration cycle of the hardware - those cannot be |
| 3148 | * set/changed during runtime. After reset the device needs to be |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3149 | * properly configured for Rx, Tx etc. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3150 | */ |
| 3151 | void e1000e_reset(struct e1000_adapter *adapter) |
| 3152 | { |
| 3153 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3154 | struct e1000_fc_info *fc = &adapter->hw.fc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3155 | struct e1000_hw *hw = &adapter->hw; |
| 3156 | u32 tx_space, min_tx_space, min_rx_space; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3157 | u32 pba = adapter->pba; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3158 | u16 hwm; |
| 3159 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3160 | /* reset Packet Buffer Allocation to default */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3161 | ew32(PBA, pba); |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3162 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3163 | if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3164 | /* |
| 3165 | * To maintain wire speed transmits, the Tx FIFO should be |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3166 | * large enough to accommodate two full transmit packets, |
| 3167 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 3168 | * the Rx FIFO should be large enough to accommodate at least |
| 3169 | * one full receive packet and is similarly rounded up and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3170 | * expressed in KB. |
| 3171 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3172 | pba = er32(PBA); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3173 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3174 | tx_space = pba >> 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3175 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3176 | pba &= 0xffff; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3177 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3178 | * the Tx fifo also stores 16 bytes of information about the Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3179 | * but don't include ethernet FCS because hardware appends it |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3180 | */ |
| 3181 | min_tx_space = (adapter->max_frame_size + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3182 | sizeof(struct e1000_tx_desc) - |
| 3183 | ETH_FCS_LEN) * 2; |
| 3184 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 3185 | min_tx_space >>= 10; |
| 3186 | /* software strips receive CRC, so leave room for it */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3187 | min_rx_space = adapter->max_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3188 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 3189 | min_rx_space >>= 10; |
| 3190 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3191 | /* |
| 3192 | * If current Tx allocation is less than the min Tx FIFO size, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3193 | * 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] | 3194 | * allocation, take space away from current Rx allocation |
| 3195 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3196 | if ((tx_space < min_tx_space) && |
| 3197 | ((min_tx_space - tx_space) < pba)) { |
| 3198 | pba -= min_tx_space - tx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3199 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3200 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3201 | * if short on Rx space, Rx wins and must trump Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3202 | * adjustment or use Early Receive if available |
| 3203 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3204 | if ((pba < min_rx_space) && |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3205 | (!(adapter->flags & FLAG_HAS_ERT))) |
| 3206 | /* ERT enabled in e1000_configure_rx */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3207 | pba = min_rx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3208 | } |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3209 | |
| 3210 | ew32(PBA, pba); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3213 | /* |
| 3214 | * flow control settings |
| 3215 | * |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3216 | * The high water mark must be low enough to fit one full frame |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3217 | * (or the size used for early receive) above it in the Rx FIFO. |
| 3218 | * Set it to the lower of: |
| 3219 | * - 90% of the Rx FIFO size, and |
| 3220 | * - the full Rx FIFO size minus the early receive size (for parts |
| 3221 | * with ERT support assuming ERT set to E1000_ERT_2048), or |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3222 | * - the full Rx FIFO size minus one full frame |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3223 | */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3224 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
| 3225 | fc->pause_time = 0xFFFF; |
| 3226 | else |
| 3227 | fc->pause_time = E1000_FC_PAUSE_TIME; |
| 3228 | fc->send_xon = 1; |
| 3229 | fc->current_mode = fc->requested_mode; |
| 3230 | |
| 3231 | switch (hw->mac.type) { |
| 3232 | default: |
| 3233 | if ((adapter->flags & FLAG_HAS_ERT) && |
| 3234 | (adapter->netdev->mtu > ETH_DATA_LEN)) |
| 3235 | hwm = min(((pba << 10) * 9 / 10), |
| 3236 | ((pba << 10) - (E1000_ERT_2048 << 3))); |
| 3237 | else |
| 3238 | hwm = min(((pba << 10) * 9 / 10), |
| 3239 | ((pba << 10) - adapter->max_frame_size)); |
| 3240 | |
| 3241 | fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ |
| 3242 | fc->low_water = fc->high_water - 8; |
| 3243 | break; |
| 3244 | case e1000_pchlan: |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3245 | /* |
| 3246 | * Workaround PCH LOM adapter hangs with certain network |
| 3247 | * loads. If hangs persist, try disabling Tx flow control. |
| 3248 | */ |
| 3249 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3250 | fc->high_water = 0x3500; |
| 3251 | fc->low_water = 0x1500; |
| 3252 | } else { |
| 3253 | fc->high_water = 0x5000; |
| 3254 | fc->low_water = 0x3000; |
| 3255 | } |
Bruce Allan | a305595 | 2010-05-10 15:02:12 +0000 | [diff] [blame] | 3256 | fc->refresh_time = 0x1000; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3257 | break; |
| 3258 | case e1000_pch2lan: |
| 3259 | fc->high_water = 0x05C20; |
| 3260 | fc->low_water = 0x05048; |
| 3261 | fc->pause_time = 0x0650; |
| 3262 | fc->refresh_time = 0x0400; |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3263 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3264 | pba = 14; |
| 3265 | ew32(PBA, pba); |
| 3266 | } |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3267 | break; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3268 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3269 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3270 | /* |
| 3271 | * Disable Adaptive Interrupt Moderation if 2 full packets cannot |
| 3272 | * fit in receive buffer and early-receive not supported. |
| 3273 | */ |
| 3274 | if (adapter->itr_setting & 0x3) { |
| 3275 | if (((adapter->max_frame_size * 2) > (pba << 10)) && |
| 3276 | !(adapter->flags & FLAG_HAS_ERT)) { |
| 3277 | if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) { |
| 3278 | dev_info(&adapter->pdev->dev, |
| 3279 | "Interrupt Throttle Rate turned off\n"); |
| 3280 | adapter->flags2 |= FLAG2_DISABLE_AIM; |
| 3281 | ew32(ITR, 0); |
| 3282 | } |
| 3283 | } else if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 3284 | dev_info(&adapter->pdev->dev, |
| 3285 | "Interrupt Throttle Rate turned on\n"); |
| 3286 | adapter->flags2 &= ~FLAG2_DISABLE_AIM; |
| 3287 | adapter->itr = 20000; |
| 3288 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
| 3289 | } |
| 3290 | } |
| 3291 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3292 | /* Allow time for pending master requests to run */ |
| 3293 | mac->ops.reset_hw(hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3294 | |
| 3295 | /* |
| 3296 | * For parts with AMT enabled, let the firmware know |
| 3297 | * that the network interface is in control |
| 3298 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 3299 | if (adapter->flags & FLAG_HAS_AMT) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3300 | e1000e_get_hw_control(adapter); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3301 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3302 | ew32(WUC, 0); |
| 3303 | |
| 3304 | if (mac->ops.init_hw(hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 3305 | e_err("Hardware Error\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3306 | |
| 3307 | e1000_update_mng_vlan(adapter); |
| 3308 | |
| 3309 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 3310 | ew32(VET, ETH_P_8021Q); |
| 3311 | |
| 3312 | e1000e_reset_adaptive(hw); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3313 | |
| 3314 | if (!netif_running(adapter->netdev) && |
| 3315 | !test_bit(__E1000_TESTING, &adapter->state)) { |
| 3316 | e1000_power_down_phy(adapter); |
| 3317 | return; |
| 3318 | } |
| 3319 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3320 | e1000_get_phy_info(hw); |
| 3321 | |
Bruce Allan | 918d719 | 2009-06-02 11:28:20 +0000 | [diff] [blame] | 3322 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && |
| 3323 | !(adapter->flags & FLAG_SMART_POWER_DOWN)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3324 | u16 phy_data = 0; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3325 | /* |
| 3326 | * speed up time to link by disabling smart power down, ignore |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3327 | * the return value of this function because there is nothing |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3328 | * different we would do if it failed |
| 3329 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3330 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
| 3331 | phy_data &= ~IGP02E1000_PM_SPD; |
| 3332 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 3333 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3334 | } |
| 3335 | |
| 3336 | int e1000e_up(struct e1000_adapter *adapter) |
| 3337 | { |
| 3338 | struct e1000_hw *hw = &adapter->hw; |
| 3339 | |
| 3340 | /* hardware has been reset, we need to reload some things */ |
| 3341 | e1000_configure(adapter); |
| 3342 | |
| 3343 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3344 | |
| 3345 | napi_enable(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3346 | if (adapter->msix_entries) |
| 3347 | e1000_configure_msix(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3348 | e1000_irq_enable(adapter); |
| 3349 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame^] | 3350 | netif_start_queue(adapter->netdev); |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3351 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3352 | /* fire a link change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3353 | if (adapter->msix_entries) |
| 3354 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3355 | else |
| 3356 | ew32(ICS, E1000_ICS_LSC); |
| 3357 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3358 | return 0; |
| 3359 | } |
| 3360 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3361 | static void e1000e_flush_descriptors(struct e1000_adapter *adapter) |
| 3362 | { |
| 3363 | struct e1000_hw *hw = &adapter->hw; |
| 3364 | |
| 3365 | if (!(adapter->flags2 & FLAG2_DMA_BURST)) |
| 3366 | return; |
| 3367 | |
| 3368 | /* flush pending descriptor writebacks to memory */ |
| 3369 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 3370 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 3371 | |
| 3372 | /* execute the writes immediately */ |
| 3373 | e1e_flush(); |
| 3374 | } |
| 3375 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3376 | static void e1000e_update_stats(struct e1000_adapter *adapter); |
| 3377 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3378 | void e1000e_down(struct e1000_adapter *adapter) |
| 3379 | { |
| 3380 | struct net_device *netdev = adapter->netdev; |
| 3381 | struct e1000_hw *hw = &adapter->hw; |
| 3382 | u32 tctl, rctl; |
| 3383 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3384 | /* |
| 3385 | * signal that we're down so the interrupt handler does not |
| 3386 | * reschedule our watchdog timer |
| 3387 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3388 | set_bit(__E1000_DOWN, &adapter->state); |
| 3389 | |
| 3390 | /* disable receives in the hardware */ |
| 3391 | rctl = er32(RCTL); |
| 3392 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 3393 | /* flush and sleep below */ |
| 3394 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3395 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3396 | |
| 3397 | /* disable transmits in the hardware */ |
| 3398 | tctl = er32(TCTL); |
| 3399 | tctl &= ~E1000_TCTL_EN; |
| 3400 | ew32(TCTL, tctl); |
| 3401 | /* flush both disables and wait for them to finish */ |
| 3402 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3403 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3404 | |
| 3405 | napi_disable(&adapter->napi); |
| 3406 | e1000_irq_disable(adapter); |
| 3407 | |
| 3408 | del_timer_sync(&adapter->watchdog_timer); |
| 3409 | del_timer_sync(&adapter->phy_info_timer); |
| 3410 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3411 | netif_carrier_off(netdev); |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3412 | |
| 3413 | spin_lock(&adapter->stats64_lock); |
| 3414 | e1000e_update_stats(adapter); |
| 3415 | spin_unlock(&adapter->stats64_lock); |
| 3416 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame^] | 3417 | e1000e_flush_descriptors(adapter); |
| 3418 | e1000_clean_tx_ring(adapter); |
| 3419 | e1000_clean_rx_ring(adapter); |
| 3420 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3421 | adapter->link_speed = 0; |
| 3422 | adapter->link_duplex = 0; |
| 3423 | |
Jeff Kirsher | 52cc308 | 2008-06-24 17:01:29 -0700 | [diff] [blame] | 3424 | if (!pci_channel_offline(adapter->pdev)) |
| 3425 | e1000e_reset(adapter); |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3426 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3427 | /* |
| 3428 | * TODO: for power management, we could drop the link and |
| 3429 | * pci_disable_device here. |
| 3430 | */ |
| 3431 | } |
| 3432 | |
| 3433 | void e1000e_reinit_locked(struct e1000_adapter *adapter) |
| 3434 | { |
| 3435 | might_sleep(); |
| 3436 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3437 | usleep_range(1000, 2000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3438 | e1000e_down(adapter); |
| 3439 | e1000e_up(adapter); |
| 3440 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 3441 | } |
| 3442 | |
| 3443 | /** |
| 3444 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 3445 | * @adapter: board private structure to initialize |
| 3446 | * |
| 3447 | * e1000_sw_init initializes the Adapter private data structure. |
| 3448 | * Fields are initialized based on PCI device information and |
| 3449 | * OS network device settings (MTU size). |
| 3450 | **/ |
| 3451 | static int __devinit e1000_sw_init(struct e1000_adapter *adapter) |
| 3452 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3453 | struct net_device *netdev = adapter->netdev; |
| 3454 | |
| 3455 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN; |
| 3456 | adapter->rx_ps_bsize0 = 128; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3457 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3458 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3459 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3460 | spin_lock_init(&adapter->stats64_lock); |
| 3461 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3462 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3463 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3464 | if (e1000_alloc_queues(adapter)) |
| 3465 | return -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3466 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3467 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3468 | e1000_irq_disable(adapter); |
| 3469 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3470 | set_bit(__E1000_DOWN, &adapter->state); |
| 3471 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3472 | } |
| 3473 | |
| 3474 | /** |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3475 | * e1000_intr_msi_test - Interrupt Handler |
| 3476 | * @irq: interrupt number |
| 3477 | * @data: pointer to a network interface device structure |
| 3478 | **/ |
| 3479 | static irqreturn_t e1000_intr_msi_test(int irq, void *data) |
| 3480 | { |
| 3481 | struct net_device *netdev = data; |
| 3482 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3483 | struct e1000_hw *hw = &adapter->hw; |
| 3484 | u32 icr = er32(ICR); |
| 3485 | |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 3486 | e_dbg("icr is %08X\n", icr); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3487 | if (icr & E1000_ICR_RXSEQ) { |
| 3488 | adapter->flags &= ~FLAG_MSI_TEST_FAILED; |
| 3489 | wmb(); |
| 3490 | } |
| 3491 | |
| 3492 | return IRQ_HANDLED; |
| 3493 | } |
| 3494 | |
| 3495 | /** |
| 3496 | * e1000_test_msi_interrupt - Returns 0 for successful test |
| 3497 | * @adapter: board private struct |
| 3498 | * |
| 3499 | * code flow taken from tg3.c |
| 3500 | **/ |
| 3501 | static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) |
| 3502 | { |
| 3503 | struct net_device *netdev = adapter->netdev; |
| 3504 | struct e1000_hw *hw = &adapter->hw; |
| 3505 | int err; |
| 3506 | |
| 3507 | /* poll_enable hasn't been called yet, so don't need disable */ |
| 3508 | /* clear any pending events */ |
| 3509 | er32(ICR); |
| 3510 | |
| 3511 | /* free the real vector and request a test handler */ |
| 3512 | e1000_free_irq(adapter); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3513 | e1000e_reset_interrupt_capability(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3514 | |
| 3515 | /* Assume that the test fails, if it succeeds then the test |
| 3516 | * MSI irq handler will unset this flag */ |
| 3517 | adapter->flags |= FLAG_MSI_TEST_FAILED; |
| 3518 | |
| 3519 | err = pci_enable_msi(adapter->pdev); |
| 3520 | if (err) |
| 3521 | goto msi_test_failed; |
| 3522 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3523 | err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3524 | netdev->name, netdev); |
| 3525 | if (err) { |
| 3526 | pci_disable_msi(adapter->pdev); |
| 3527 | goto msi_test_failed; |
| 3528 | } |
| 3529 | |
| 3530 | wmb(); |
| 3531 | |
| 3532 | e1000_irq_enable(adapter); |
| 3533 | |
| 3534 | /* fire an unusual interrupt on the test handler */ |
| 3535 | ew32(ICS, E1000_ICS_RXSEQ); |
| 3536 | e1e_flush(); |
| 3537 | msleep(50); |
| 3538 | |
| 3539 | e1000_irq_disable(adapter); |
| 3540 | |
| 3541 | rmb(); |
| 3542 | |
| 3543 | if (adapter->flags & FLAG_MSI_TEST_FAILED) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3544 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 3545 | e_info("MSI interrupt test failed, using legacy interrupt.\n"); |
| 3546 | } else |
| 3547 | e_dbg("MSI interrupt test succeeded!\n"); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3548 | |
| 3549 | free_irq(adapter->pdev->irq, netdev); |
| 3550 | pci_disable_msi(adapter->pdev); |
| 3551 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3552 | msi_test_failed: |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3553 | e1000e_set_interrupt_capability(adapter); |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 3554 | return e1000_request_irq(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
| 3557 | /** |
| 3558 | * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored |
| 3559 | * @adapter: board private struct |
| 3560 | * |
| 3561 | * code flow taken from tg3.c, called with e1000 interrupts disabled. |
| 3562 | **/ |
| 3563 | static int e1000_test_msi(struct e1000_adapter *adapter) |
| 3564 | { |
| 3565 | int err; |
| 3566 | u16 pci_cmd; |
| 3567 | |
| 3568 | if (!(adapter->flags & FLAG_MSI_ENABLED)) |
| 3569 | return 0; |
| 3570 | |
| 3571 | /* disable SERR in case the MSI write causes a master abort */ |
| 3572 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 3573 | if (pci_cmd & PCI_COMMAND_SERR) |
| 3574 | pci_write_config_word(adapter->pdev, PCI_COMMAND, |
| 3575 | pci_cmd & ~PCI_COMMAND_SERR); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3576 | |
| 3577 | err = e1000_test_msi_interrupt(adapter); |
| 3578 | |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 3579 | /* re-enable SERR */ |
| 3580 | if (pci_cmd & PCI_COMMAND_SERR) { |
| 3581 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
| 3582 | pci_cmd |= PCI_COMMAND_SERR; |
| 3583 | pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); |
| 3584 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3585 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3586 | return err; |
| 3587 | } |
| 3588 | |
| 3589 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3590 | * e1000_open - Called when a network interface is made active |
| 3591 | * @netdev: network interface device structure |
| 3592 | * |
| 3593 | * Returns 0 on success, negative value on failure |
| 3594 | * |
| 3595 | * The open entry point is called when a network interface is made |
| 3596 | * active by the system (IFF_UP). At this point all resources needed |
| 3597 | * for transmit and receive operations are allocated, the interrupt |
| 3598 | * handler is registered with the OS, the watchdog timer is started, |
| 3599 | * and the stack is notified that the interface is ready. |
| 3600 | **/ |
| 3601 | static int e1000_open(struct net_device *netdev) |
| 3602 | { |
| 3603 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3604 | struct e1000_hw *hw = &adapter->hw; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3605 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3606 | int err; |
| 3607 | |
| 3608 | /* disallow open during test */ |
| 3609 | if (test_bit(__E1000_TESTING, &adapter->state)) |
| 3610 | return -EBUSY; |
| 3611 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3612 | pm_runtime_get_sync(&pdev->dev); |
| 3613 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 3614 | netif_carrier_off(netdev); |
| 3615 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3616 | /* allocate transmit descriptors */ |
| 3617 | err = e1000e_setup_tx_resources(adapter); |
| 3618 | if (err) |
| 3619 | goto err_setup_tx; |
| 3620 | |
| 3621 | /* allocate receive descriptors */ |
| 3622 | err = e1000e_setup_rx_resources(adapter); |
| 3623 | if (err) |
| 3624 | goto err_setup_rx; |
| 3625 | |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 3626 | /* |
| 3627 | * If AMT is enabled, let the firmware know that the network |
| 3628 | * interface is now open and reset the part to a known state. |
| 3629 | */ |
| 3630 | if (adapter->flags & FLAG_HAS_AMT) { |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3631 | e1000e_get_hw_control(adapter); |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 3632 | e1000e_reset(adapter); |
| 3633 | } |
| 3634 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3635 | e1000e_power_up_phy(adapter); |
| 3636 | |
| 3637 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 3638 | if ((adapter->hw.mng_cookie.status & |
| 3639 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
| 3640 | e1000_update_mng_vlan(adapter); |
| 3641 | |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3642 | /* DMA latency requirement to workaround early-receive/jumbo issue */ |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3643 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 3644 | (adapter->hw.mac.type == e1000_pch2lan)) |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 3645 | pm_qos_add_request(&adapter->netdev->pm_qos_req, |
| 3646 | PM_QOS_CPU_DMA_LATENCY, |
| 3647 | PM_QOS_DEFAULT_VALUE); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3648 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3649 | /* |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3650 | * before we allocate an interrupt, we must be ready to handle it. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3651 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 3652 | * 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] | 3653 | * clean_rx handler before we do so. |
| 3654 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3655 | e1000_configure(adapter); |
| 3656 | |
| 3657 | err = e1000_request_irq(adapter); |
| 3658 | if (err) |
| 3659 | goto err_req_irq; |
| 3660 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3661 | /* |
| 3662 | * Work around PCIe errata with MSI interrupts causing some chipsets to |
| 3663 | * ignore e1000e MSI messages, which means we need to test our MSI |
| 3664 | * interrupt now |
| 3665 | */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3666 | if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3667 | err = e1000_test_msi(adapter); |
| 3668 | if (err) { |
| 3669 | e_err("Interrupt allocation failed\n"); |
| 3670 | goto err_req_irq; |
| 3671 | } |
| 3672 | } |
| 3673 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3674 | /* From here on the code is the same as e1000e_up() */ |
| 3675 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3676 | |
| 3677 | napi_enable(&adapter->napi); |
| 3678 | |
| 3679 | e1000_irq_enable(adapter); |
| 3680 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3681 | netif_start_queue(netdev); |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 3682 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3683 | adapter->idle_check = true; |
| 3684 | pm_runtime_put(&pdev->dev); |
| 3685 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3686 | /* fire a link status change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3687 | if (adapter->msix_entries) |
| 3688 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3689 | else |
| 3690 | ew32(ICS, E1000_ICS_LSC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3691 | |
| 3692 | return 0; |
| 3693 | |
| 3694 | err_req_irq: |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3695 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3696 | e1000_power_down_phy(adapter); |
| 3697 | e1000e_free_rx_resources(adapter); |
| 3698 | err_setup_rx: |
| 3699 | e1000e_free_tx_resources(adapter); |
| 3700 | err_setup_tx: |
| 3701 | e1000e_reset(adapter); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3702 | pm_runtime_put_sync(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3703 | |
| 3704 | return err; |
| 3705 | } |
| 3706 | |
| 3707 | /** |
| 3708 | * e1000_close - Disables a network interface |
| 3709 | * @netdev: network interface device structure |
| 3710 | * |
| 3711 | * Returns 0, this is not allowed to fail |
| 3712 | * |
| 3713 | * The close entry point is called when an interface is de-activated |
| 3714 | * by the OS. The hardware is still under the drivers control, but |
| 3715 | * needs to be disabled. A global MAC reset is issued to stop the |
| 3716 | * hardware, and all transmit and receive resources are freed. |
| 3717 | **/ |
| 3718 | static int e1000_close(struct net_device *netdev) |
| 3719 | { |
| 3720 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3721 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3722 | |
| 3723 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3724 | |
| 3725 | pm_runtime_get_sync(&pdev->dev); |
| 3726 | |
| 3727 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 3728 | e1000e_down(adapter); |
| 3729 | e1000_free_irq(adapter); |
| 3730 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3731 | e1000_power_down_phy(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3732 | |
| 3733 | e1000e_free_tx_resources(adapter); |
| 3734 | e1000e_free_rx_resources(adapter); |
| 3735 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3736 | /* |
| 3737 | * kill manageability vlan ID if supported, but not if a vlan with |
| 3738 | * the same ID is registered on the host OS (let 8021q kill it) |
| 3739 | */ |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3740 | if (adapter->hw.mng_cookie.status & |
| 3741 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3742 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 3743 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3744 | /* |
| 3745 | * If AMT is enabled, let the firmware know that the network |
| 3746 | * interface is now closed |
| 3747 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3748 | if ((adapter->flags & FLAG_HAS_AMT) && |
| 3749 | !test_bit(__E1000_TESTING, &adapter->state)) |
| 3750 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3751 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3752 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 3753 | (adapter->hw.mac.type == e1000_pch2lan)) |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 3754 | pm_qos_remove_request(&adapter->netdev->pm_qos_req); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3755 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3756 | pm_runtime_put_sync(&pdev->dev); |
| 3757 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3758 | return 0; |
| 3759 | } |
| 3760 | /** |
| 3761 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 3762 | * @netdev: network interface device structure |
| 3763 | * @p: pointer to an address structure |
| 3764 | * |
| 3765 | * Returns 0 on success, negative on failure |
| 3766 | **/ |
| 3767 | static int e1000_set_mac(struct net_device *netdev, void *p) |
| 3768 | { |
| 3769 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3770 | struct sockaddr *addr = p; |
| 3771 | |
| 3772 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3773 | return -EADDRNOTAVAIL; |
| 3774 | |
| 3775 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 3776 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 3777 | |
| 3778 | e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0); |
| 3779 | |
| 3780 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { |
| 3781 | /* activate the work around */ |
| 3782 | e1000e_set_laa_state_82571(&adapter->hw, 1); |
| 3783 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3784 | /* |
| 3785 | * 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] | 3786 | * between the time RAR[0] gets clobbered and the time it |
| 3787 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
| 3788 | * of the RARs and no incoming packets directed to this port |
| 3789 | * are dropped. Eventually the LAA will be in RAR[0] and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3790 | * RAR[14] |
| 3791 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3792 | e1000e_rar_set(&adapter->hw, |
| 3793 | adapter->hw.mac.addr, |
| 3794 | adapter->hw.mac.rar_entry_count - 1); |
| 3795 | } |
| 3796 | |
| 3797 | return 0; |
| 3798 | } |
| 3799 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 3800 | /** |
| 3801 | * e1000e_update_phy_task - work thread to update phy |
| 3802 | * @work: pointer to our work struct |
| 3803 | * |
| 3804 | * this worker thread exists because we must acquire a |
| 3805 | * semaphore to read the phy, which we could msleep while |
| 3806 | * waiting for it, and we can't msleep in a timer. |
| 3807 | **/ |
| 3808 | static void e1000e_update_phy_task(struct work_struct *work) |
| 3809 | { |
| 3810 | struct e1000_adapter *adapter = container_of(work, |
| 3811 | struct e1000_adapter, update_phy_task); |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 3812 | |
| 3813 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 3814 | return; |
| 3815 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 3816 | e1000_get_phy_info(&adapter->hw); |
| 3817 | } |
| 3818 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3819 | /* |
| 3820 | * Need to wait a few seconds after link up to get diagnostic information from |
| 3821 | * the phy |
| 3822 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3823 | static void e1000_update_phy_info(unsigned long data) |
| 3824 | { |
| 3825 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 3826 | |
| 3827 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 3828 | return; |
| 3829 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 3830 | schedule_work(&adapter->update_phy_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | /** |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3834 | * e1000e_update_phy_stats - Update the PHY statistics counters |
| 3835 | * @adapter: board private structure |
| 3836 | **/ |
| 3837 | static void e1000e_update_phy_stats(struct e1000_adapter *adapter) |
| 3838 | { |
| 3839 | struct e1000_hw *hw = &adapter->hw; |
| 3840 | s32 ret_val; |
| 3841 | u16 phy_data; |
| 3842 | |
| 3843 | ret_val = hw->phy.ops.acquire(hw); |
| 3844 | if (ret_val) |
| 3845 | return; |
| 3846 | |
| 3847 | hw->phy.addr = 1; |
| 3848 | |
| 3849 | #define HV_PHY_STATS_PAGE 778 |
| 3850 | /* |
| 3851 | * A page set is expensive so check if already on desired page. |
| 3852 | * If not, set to the page with the PHY status registers. |
| 3853 | */ |
| 3854 | ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 3855 | &phy_data); |
| 3856 | if (ret_val) |
| 3857 | goto release; |
| 3858 | if (phy_data != (HV_PHY_STATS_PAGE << IGP_PAGE_SHIFT)) { |
| 3859 | ret_val = e1000e_write_phy_reg_mdic(hw, |
| 3860 | IGP01E1000_PHY_PAGE_SELECT, |
| 3861 | (HV_PHY_STATS_PAGE << |
| 3862 | IGP_PAGE_SHIFT)); |
| 3863 | if (ret_val) |
| 3864 | goto release; |
| 3865 | } |
| 3866 | |
| 3867 | /* Read/clear the upper 16-bit registers and read/accumulate lower */ |
| 3868 | |
| 3869 | /* Single Collision Count */ |
| 3870 | e1000e_read_phy_reg_mdic(hw, HV_SCC_UPPER & MAX_PHY_REG_ADDRESS, |
| 3871 | &phy_data); |
| 3872 | ret_val = e1000e_read_phy_reg_mdic(hw, |
| 3873 | HV_SCC_LOWER & MAX_PHY_REG_ADDRESS, |
| 3874 | &phy_data); |
| 3875 | if (!ret_val) |
| 3876 | adapter->stats.scc += phy_data; |
| 3877 | |
| 3878 | /* Excessive Collision Count */ |
| 3879 | e1000e_read_phy_reg_mdic(hw, HV_ECOL_UPPER & MAX_PHY_REG_ADDRESS, |
| 3880 | &phy_data); |
| 3881 | ret_val = e1000e_read_phy_reg_mdic(hw, |
| 3882 | HV_ECOL_LOWER & MAX_PHY_REG_ADDRESS, |
| 3883 | &phy_data); |
| 3884 | if (!ret_val) |
| 3885 | adapter->stats.ecol += phy_data; |
| 3886 | |
| 3887 | /* Multiple Collision Count */ |
| 3888 | e1000e_read_phy_reg_mdic(hw, HV_MCC_UPPER & MAX_PHY_REG_ADDRESS, |
| 3889 | &phy_data); |
| 3890 | ret_val = e1000e_read_phy_reg_mdic(hw, |
| 3891 | HV_MCC_LOWER & MAX_PHY_REG_ADDRESS, |
| 3892 | &phy_data); |
| 3893 | if (!ret_val) |
| 3894 | adapter->stats.mcc += phy_data; |
| 3895 | |
| 3896 | /* Late Collision Count */ |
| 3897 | e1000e_read_phy_reg_mdic(hw, HV_LATECOL_UPPER & MAX_PHY_REG_ADDRESS, |
| 3898 | &phy_data); |
| 3899 | ret_val = e1000e_read_phy_reg_mdic(hw, |
| 3900 | HV_LATECOL_LOWER & |
| 3901 | MAX_PHY_REG_ADDRESS, |
| 3902 | &phy_data); |
| 3903 | if (!ret_val) |
| 3904 | adapter->stats.latecol += phy_data; |
| 3905 | |
| 3906 | /* Collision Count - also used for adaptive IFS */ |
| 3907 | e1000e_read_phy_reg_mdic(hw, HV_COLC_UPPER & MAX_PHY_REG_ADDRESS, |
| 3908 | &phy_data); |
| 3909 | ret_val = e1000e_read_phy_reg_mdic(hw, |
| 3910 | HV_COLC_LOWER & MAX_PHY_REG_ADDRESS, |
| 3911 | &phy_data); |
| 3912 | if (!ret_val) |
| 3913 | hw->mac.collision_delta = phy_data; |
| 3914 | |
| 3915 | /* Defer Count */ |
| 3916 | e1000e_read_phy_reg_mdic(hw, HV_DC_UPPER & MAX_PHY_REG_ADDRESS, |
| 3917 | &phy_data); |
| 3918 | ret_val = e1000e_read_phy_reg_mdic(hw, |
| 3919 | HV_DC_LOWER & MAX_PHY_REG_ADDRESS, |
| 3920 | &phy_data); |
| 3921 | if (!ret_val) |
| 3922 | adapter->stats.dc += phy_data; |
| 3923 | |
| 3924 | /* Transmit with no CRS */ |
| 3925 | e1000e_read_phy_reg_mdic(hw, HV_TNCRS_UPPER & MAX_PHY_REG_ADDRESS, |
| 3926 | &phy_data); |
| 3927 | ret_val = e1000e_read_phy_reg_mdic(hw, |
| 3928 | HV_TNCRS_LOWER & MAX_PHY_REG_ADDRESS, |
| 3929 | &phy_data); |
| 3930 | if (!ret_val) |
| 3931 | adapter->stats.tncrs += phy_data; |
| 3932 | |
| 3933 | release: |
| 3934 | hw->phy.ops.release(hw); |
| 3935 | } |
| 3936 | |
| 3937 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3938 | * e1000e_update_stats - Update the board statistics counters |
| 3939 | * @adapter: board private structure |
| 3940 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3941 | static void e1000e_update_stats(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3942 | { |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 3943 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3944 | struct e1000_hw *hw = &adapter->hw; |
| 3945 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3946 | |
| 3947 | /* |
| 3948 | * Prevent stats update while adapter is being reset, or if the pci |
| 3949 | * connection is down. |
| 3950 | */ |
| 3951 | if (adapter->link_speed == 0) |
| 3952 | return; |
| 3953 | if (pci_channel_offline(pdev)) |
| 3954 | return; |
| 3955 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3956 | adapter->stats.crcerrs += er32(CRCERRS); |
| 3957 | adapter->stats.gprc += er32(GPRC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3958 | adapter->stats.gorc += er32(GORCL); |
| 3959 | er32(GORCH); /* Clear gorc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3960 | adapter->stats.bprc += er32(BPRC); |
| 3961 | adapter->stats.mprc += er32(MPRC); |
| 3962 | adapter->stats.roc += er32(ROC); |
| 3963 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3964 | adapter->stats.mpc += er32(MPC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3965 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3966 | /* Half-duplex statistics */ |
| 3967 | if (adapter->link_duplex == HALF_DUPLEX) { |
| 3968 | if (adapter->flags2 & FLAG2_HAS_PHY_STATS) { |
| 3969 | e1000e_update_phy_stats(adapter); |
| 3970 | } else { |
| 3971 | adapter->stats.scc += er32(SCC); |
| 3972 | adapter->stats.ecol += er32(ECOL); |
| 3973 | adapter->stats.mcc += er32(MCC); |
| 3974 | adapter->stats.latecol += er32(LATECOL); |
| 3975 | adapter->stats.dc += er32(DC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3976 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3977 | hw->mac.collision_delta = er32(COLC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3978 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3979 | if ((hw->mac.type != e1000_82574) && |
| 3980 | (hw->mac.type != e1000_82583)) |
| 3981 | adapter->stats.tncrs += er32(TNCRS); |
| 3982 | } |
| 3983 | adapter->stats.colc += hw->mac.collision_delta; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3984 | } |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3985 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3986 | adapter->stats.xonrxc += er32(XONRXC); |
| 3987 | adapter->stats.xontxc += er32(XONTXC); |
| 3988 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 3989 | adapter->stats.xofftxc += er32(XOFFTXC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3990 | adapter->stats.gptc += er32(GPTC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3991 | adapter->stats.gotc += er32(GOTCL); |
| 3992 | er32(GOTCH); /* Clear gotc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3993 | adapter->stats.rnbc += er32(RNBC); |
| 3994 | adapter->stats.ruc += er32(RUC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3995 | |
| 3996 | adapter->stats.mptc += er32(MPTC); |
| 3997 | adapter->stats.bptc += er32(BPTC); |
| 3998 | |
| 3999 | /* used for adaptive IFS */ |
| 4000 | |
| 4001 | hw->mac.tx_packet_delta = er32(TPT); |
| 4002 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4003 | |
| 4004 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 4005 | adapter->stats.rxerrc += er32(RXERRC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4006 | adapter->stats.cexterr += er32(CEXTERR); |
| 4007 | adapter->stats.tsctc += er32(TSCTC); |
| 4008 | adapter->stats.tsctfc += er32(TSCTFC); |
| 4009 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4010 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4011 | netdev->stats.multicast = adapter->stats.mprc; |
| 4012 | netdev->stats.collisions = adapter->stats.colc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4013 | |
| 4014 | /* Rx Errors */ |
| 4015 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4016 | /* |
| 4017 | * RLEC on some newer hardware can be incorrect so build |
| 4018 | * our own version based on RUC and ROC |
| 4019 | */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4020 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4021 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 4022 | adapter->stats.ruc + adapter->stats.roc + |
| 4023 | adapter->stats.cexterr; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4024 | netdev->stats.rx_length_errors = adapter->stats.ruc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4025 | adapter->stats.roc; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4026 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4027 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; |
| 4028 | netdev->stats.rx_missed_errors = adapter->stats.mpc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4029 | |
| 4030 | /* Tx Errors */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4031 | netdev->stats.tx_errors = adapter->stats.ecol + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4032 | adapter->stats.latecol; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4033 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
| 4034 | netdev->stats.tx_window_errors = adapter->stats.latecol; |
| 4035 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4036 | |
| 4037 | /* Tx Dropped needs to be maintained elsewhere */ |
| 4038 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4039 | /* Management Stats */ |
| 4040 | adapter->stats.mgptc += er32(MGTPTC); |
| 4041 | adapter->stats.mgprc += er32(MGTPRC); |
| 4042 | adapter->stats.mgpdc += er32(MGTPDC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4043 | } |
| 4044 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4045 | /** |
| 4046 | * e1000_phy_read_status - Update the PHY register status snapshot |
| 4047 | * @adapter: board private structure |
| 4048 | **/ |
| 4049 | static void e1000_phy_read_status(struct e1000_adapter *adapter) |
| 4050 | { |
| 4051 | struct e1000_hw *hw = &adapter->hw; |
| 4052 | struct e1000_phy_regs *phy = &adapter->phy_regs; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4053 | |
| 4054 | if ((er32(STATUS) & E1000_STATUS_LU) && |
| 4055 | (adapter->hw.phy.media_type == e1000_media_type_copper)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4056 | int ret_val; |
| 4057 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4058 | ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr); |
| 4059 | ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr); |
| 4060 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise); |
| 4061 | ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa); |
| 4062 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion); |
| 4063 | ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000); |
| 4064 | ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000); |
| 4065 | ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus); |
| 4066 | if (ret_val) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4067 | e_warn("Error reading PHY register\n"); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4068 | } else { |
| 4069 | /* |
| 4070 | * Do not read PHY registers if link is not up |
| 4071 | * Set values to typical power-on defaults |
| 4072 | */ |
| 4073 | phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); |
| 4074 | phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | |
| 4075 | BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | |
| 4076 | BMSR_ERCAP); |
| 4077 | phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | |
| 4078 | ADVERTISE_ALL | ADVERTISE_CSMA); |
| 4079 | phy->lpa = 0; |
| 4080 | phy->expansion = EXPANSION_ENABLENPAGE; |
| 4081 | phy->ctrl1000 = ADVERTISE_1000FULL; |
| 4082 | phy->stat1000 = 0; |
| 4083 | phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); |
| 4084 | } |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4085 | } |
| 4086 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4087 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
| 4088 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4089 | struct e1000_hw *hw = &adapter->hw; |
| 4090 | u32 ctrl = er32(CTRL); |
| 4091 | |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4092 | /* Link status message must follow this format for user tools */ |
| 4093 | printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, " |
| 4094 | "Flow Control: %s\n", |
| 4095 | adapter->netdev->name, |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4096 | adapter->link_speed, |
| 4097 | (adapter->link_duplex == FULL_DUPLEX) ? |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4098 | "Full Duplex" : "Half Duplex", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4099 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ? |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4100 | "Rx/Tx" : |
| 4101 | ((ctrl & E1000_CTRL_RFCE) ? "Rx" : |
| 4102 | ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None"))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4103 | } |
| 4104 | |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 4105 | static bool e1000e_has_link(struct e1000_adapter *adapter) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4106 | { |
| 4107 | struct e1000_hw *hw = &adapter->hw; |
| 4108 | bool link_active = 0; |
| 4109 | s32 ret_val = 0; |
| 4110 | |
| 4111 | /* |
| 4112 | * get_link_status is set on LSC (link status) interrupt or |
| 4113 | * Rx sequence error interrupt. get_link_status will stay |
| 4114 | * false until the check_for_link establishes link |
| 4115 | * for copper adapters ONLY |
| 4116 | */ |
| 4117 | switch (hw->phy.media_type) { |
| 4118 | case e1000_media_type_copper: |
| 4119 | if (hw->mac.get_link_status) { |
| 4120 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4121 | link_active = !hw->mac.get_link_status; |
| 4122 | } else { |
| 4123 | link_active = 1; |
| 4124 | } |
| 4125 | break; |
| 4126 | case e1000_media_type_fiber: |
| 4127 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4128 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 4129 | break; |
| 4130 | case e1000_media_type_internal_serdes: |
| 4131 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4132 | link_active = adapter->hw.mac.serdes_has_link; |
| 4133 | break; |
| 4134 | default: |
| 4135 | case e1000_media_type_unknown: |
| 4136 | break; |
| 4137 | } |
| 4138 | |
| 4139 | if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && |
| 4140 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 4141 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4142 | e_info("Gigabit has been disabled, downgrading speed\n"); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4143 | } |
| 4144 | |
| 4145 | return link_active; |
| 4146 | } |
| 4147 | |
| 4148 | static void e1000e_enable_receives(struct e1000_adapter *adapter) |
| 4149 | { |
| 4150 | /* make sure the receive unit is started */ |
| 4151 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 4152 | (adapter->flags & FLAG_RX_RESTART_NOW)) { |
| 4153 | struct e1000_hw *hw = &adapter->hw; |
| 4154 | u32 rctl = er32(RCTL); |
| 4155 | ew32(RCTL, rctl | E1000_RCTL_EN); |
| 4156 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
| 4157 | } |
| 4158 | } |
| 4159 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4160 | static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter) |
| 4161 | { |
| 4162 | struct e1000_hw *hw = &adapter->hw; |
| 4163 | |
| 4164 | /* |
| 4165 | * With 82574 controllers, PHY needs to be checked periodically |
| 4166 | * for hung state and reset, if two calls return true |
| 4167 | */ |
| 4168 | if (e1000_check_phy_82574(hw)) |
| 4169 | adapter->phy_hang_count++; |
| 4170 | else |
| 4171 | adapter->phy_hang_count = 0; |
| 4172 | |
| 4173 | if (adapter->phy_hang_count > 1) { |
| 4174 | adapter->phy_hang_count = 0; |
| 4175 | schedule_work(&adapter->reset_task); |
| 4176 | } |
| 4177 | } |
| 4178 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4179 | /** |
| 4180 | * e1000_watchdog - Timer Call-back |
| 4181 | * @data: pointer to adapter cast into an unsigned long |
| 4182 | **/ |
| 4183 | static void e1000_watchdog(unsigned long data) |
| 4184 | { |
| 4185 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 4186 | |
| 4187 | /* Do the rest outside of interrupt context */ |
| 4188 | schedule_work(&adapter->watchdog_task); |
| 4189 | |
| 4190 | /* TODO: make this use queue_delayed_work() */ |
| 4191 | } |
| 4192 | |
| 4193 | static void e1000_watchdog_task(struct work_struct *work) |
| 4194 | { |
| 4195 | struct e1000_adapter *adapter = container_of(work, |
| 4196 | struct e1000_adapter, watchdog_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4197 | struct net_device *netdev = adapter->netdev; |
| 4198 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4199 | struct e1000_phy_info *phy = &adapter->hw.phy; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4200 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4201 | struct e1000_hw *hw = &adapter->hw; |
| 4202 | u32 link, tctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4203 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4204 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4205 | return; |
| 4206 | |
David S. Miller | b405e8d | 2010-02-04 22:31:41 -0800 | [diff] [blame] | 4207 | link = e1000e_has_link(adapter); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4208 | if ((netif_carrier_ok(netdev)) && link) { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4209 | /* Cancel scheduled suspend requests. */ |
| 4210 | pm_runtime_resume(netdev->dev.parent); |
| 4211 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4212 | e1000e_enable_receives(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4213 | goto link_up; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4214 | } |
| 4215 | |
| 4216 | if ((e1000e_enable_tx_pkt_filtering(hw)) && |
| 4217 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) |
| 4218 | e1000_update_mng_vlan(adapter); |
| 4219 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4220 | if (link) { |
| 4221 | if (!netif_carrier_ok(netdev)) { |
| 4222 | bool txb2b = 1; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4223 | |
| 4224 | /* Cancel scheduled suspend requests. */ |
| 4225 | pm_runtime_resume(netdev->dev.parent); |
| 4226 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4227 | /* update snapshot of PHY registers on LSC */ |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4228 | e1000_phy_read_status(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4229 | mac->ops.get_link_up_info(&adapter->hw, |
| 4230 | &adapter->link_speed, |
| 4231 | &adapter->link_duplex); |
| 4232 | e1000_print_link_info(adapter); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4233 | /* |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 4234 | * On supported PHYs, check for duplex mismatch only |
| 4235 | * if link has autonegotiated at 10/100 half |
| 4236 | */ |
| 4237 | if ((hw->phy.type == e1000_phy_igp_3 || |
| 4238 | hw->phy.type == e1000_phy_bm) && |
| 4239 | (hw->mac.autoneg == true) && |
| 4240 | (adapter->link_speed == SPEED_10 || |
| 4241 | adapter->link_speed == SPEED_100) && |
| 4242 | (adapter->link_duplex == HALF_DUPLEX)) { |
| 4243 | u16 autoneg_exp; |
| 4244 | |
| 4245 | e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp); |
| 4246 | |
| 4247 | if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS)) |
| 4248 | e_info("Autonegotiated half duplex but" |
| 4249 | " link partner cannot autoneg. " |
| 4250 | " Try forcing full duplex if " |
| 4251 | "link gets many collisions.\n"); |
| 4252 | } |
| 4253 | |
Emil Tantilov | f49c57e | 2010-03-24 12:55:02 +0000 | [diff] [blame] | 4254 | /* adjust timeout factor according to speed/duplex */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4255 | adapter->tx_timeout_factor = 1; |
| 4256 | switch (adapter->link_speed) { |
| 4257 | case SPEED_10: |
| 4258 | txb2b = 0; |
Bruce Allan | 10f1b49 | 2008-08-08 18:36:01 -0700 | [diff] [blame] | 4259 | adapter->tx_timeout_factor = 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4260 | break; |
| 4261 | case SPEED_100: |
| 4262 | txb2b = 0; |
Bruce Allan | 4c86e0b | 2009-11-19 12:35:26 +0000 | [diff] [blame] | 4263 | adapter->tx_timeout_factor = 10; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4264 | break; |
| 4265 | } |
| 4266 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4267 | /* |
| 4268 | * workaround: re-program speed mode bit after |
| 4269 | * link-up event |
| 4270 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4271 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
| 4272 | !txb2b) { |
| 4273 | u32 tarc0; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4274 | tarc0 = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4275 | tarc0 &= ~SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4276 | ew32(TARC(0), tarc0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4277 | } |
| 4278 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4279 | /* |
| 4280 | * disable TSO for pcie and 10/100 speeds, to avoid |
| 4281 | * some hardware issues |
| 4282 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4283 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
| 4284 | switch (adapter->link_speed) { |
| 4285 | case SPEED_10: |
| 4286 | case SPEED_100: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4287 | e_info("10/100 speed: disabling TSO\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4288 | netdev->features &= ~NETIF_F_TSO; |
| 4289 | netdev->features &= ~NETIF_F_TSO6; |
| 4290 | break; |
| 4291 | case SPEED_1000: |
| 4292 | netdev->features |= NETIF_F_TSO; |
| 4293 | netdev->features |= NETIF_F_TSO6; |
| 4294 | break; |
| 4295 | default: |
| 4296 | /* oops */ |
| 4297 | break; |
| 4298 | } |
| 4299 | } |
| 4300 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4301 | /* |
| 4302 | * enable transmits in the hardware, need to do this |
| 4303 | * after setting TARC(0) |
| 4304 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4305 | tctl = er32(TCTL); |
| 4306 | tctl |= E1000_TCTL_EN; |
| 4307 | ew32(TCTL, tctl); |
| 4308 | |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4309 | /* |
| 4310 | * Perform any post-link-up configuration before |
| 4311 | * reporting link up. |
| 4312 | */ |
| 4313 | if (phy->ops.cfg_on_link_up) |
| 4314 | phy->ops.cfg_on_link_up(hw); |
| 4315 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4316 | netif_carrier_on(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4317 | |
| 4318 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4319 | mod_timer(&adapter->phy_info_timer, |
| 4320 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4321 | } |
| 4322 | } else { |
| 4323 | if (netif_carrier_ok(netdev)) { |
| 4324 | adapter->link_speed = 0; |
| 4325 | adapter->link_duplex = 0; |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4326 | /* Link status message must follow this format */ |
| 4327 | printk(KERN_INFO "e1000e: %s NIC Link is Down\n", |
| 4328 | adapter->netdev->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4329 | netif_carrier_off(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4330 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4331 | mod_timer(&adapter->phy_info_timer, |
| 4332 | round_jiffies(jiffies + 2 * HZ)); |
| 4333 | |
| 4334 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) |
| 4335 | schedule_work(&adapter->reset_task); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4336 | else |
| 4337 | pm_schedule_suspend(netdev->dev.parent, |
| 4338 | LINK_TIMEOUT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4339 | } |
| 4340 | } |
| 4341 | |
| 4342 | link_up: |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4343 | spin_lock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4344 | e1000e_update_stats(adapter); |
| 4345 | |
| 4346 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 4347 | adapter->tpt_old = adapter->stats.tpt; |
| 4348 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; |
| 4349 | adapter->colc_old = adapter->stats.colc; |
| 4350 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4351 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
| 4352 | adapter->gorc_old = adapter->stats.gorc; |
| 4353 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; |
| 4354 | adapter->gotc_old = adapter->stats.gotc; |
Flavio Leitner | 2084b11 | 2011-04-05 04:27:43 +0000 | [diff] [blame] | 4355 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4356 | |
| 4357 | e1000e_update_adaptive(&adapter->hw); |
| 4358 | |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4359 | if (!netif_carrier_ok(netdev) && |
| 4360 | (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) { |
| 4361 | /* |
| 4362 | * We've lost link, so the controller stops DMA, |
| 4363 | * but we've got queued Tx work that's never going |
| 4364 | * to get done, so reset controller to flush Tx. |
| 4365 | * (Do the reset outside of interrupt context). |
| 4366 | */ |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4367 | schedule_work(&adapter->reset_task); |
| 4368 | /* return immediately since reset is imminent */ |
| 4369 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4370 | } |
| 4371 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4372 | /* Simple mode for Interrupt Throttle Rate (ITR) */ |
| 4373 | if (adapter->itr_setting == 4) { |
| 4374 | /* |
| 4375 | * Symmetric Tx/Rx gets a reduced ITR=2000; |
| 4376 | * Total asymmetrical Tx or Rx gets ITR=8000; |
| 4377 | * everyone else is between 2000-8000. |
| 4378 | */ |
| 4379 | u32 goc = (adapter->gotc + adapter->gorc) / 10000; |
| 4380 | u32 dif = (adapter->gotc > adapter->gorc ? |
| 4381 | adapter->gotc - adapter->gorc : |
| 4382 | adapter->gorc - adapter->gotc) / 10000; |
| 4383 | u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 4384 | |
| 4385 | ew32(ITR, 1000000000 / (itr * 256)); |
| 4386 | } |
| 4387 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4388 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4389 | if (adapter->msix_entries) |
| 4390 | ew32(ICS, adapter->rx_ring->ims_val); |
| 4391 | else |
| 4392 | ew32(ICS, E1000_ICS_RXDMT0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4393 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4394 | /* flush pending descriptors to memory before detecting Tx hang */ |
| 4395 | e1000e_flush_descriptors(adapter); |
| 4396 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4397 | /* Force detection of hung controller every watchdog period */ |
| 4398 | adapter->detect_tx_hung = 1; |
| 4399 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4400 | /* |
| 4401 | * With 82571 controllers, LAA may be overwritten due to controller |
| 4402 | * reset from the other port. Set the appropriate LAA in RAR[0] |
| 4403 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4404 | if (e1000e_get_laa_state_82571(hw)) |
| 4405 | e1000e_rar_set(hw, adapter->hw.mac.addr, 0); |
| 4406 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4407 | if (adapter->flags2 & FLAG2_CHECK_PHY_HANG) |
| 4408 | e1000e_check_82574_phy_workaround(adapter); |
| 4409 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4410 | /* Reset the timer */ |
| 4411 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4412 | mod_timer(&adapter->watchdog_timer, |
| 4413 | round_jiffies(jiffies + 2 * HZ)); |
| 4414 | } |
| 4415 | |
| 4416 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 4417 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 4418 | #define E1000_TX_FLAGS_TSO 0x00000004 |
| 4419 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
| 4420 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 4421 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 4422 | |
| 4423 | static int e1000_tso(struct e1000_adapter *adapter, |
| 4424 | struct sk_buff *skb) |
| 4425 | { |
| 4426 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4427 | struct e1000_context_desc *context_desc; |
| 4428 | struct e1000_buffer *buffer_info; |
| 4429 | unsigned int i; |
| 4430 | u32 cmd_length = 0; |
| 4431 | u16 ipcse = 0, tucse, mss; |
| 4432 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4433 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4434 | if (!skb_is_gso(skb)) |
| 4435 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4436 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4437 | if (skb_header_cloned(skb)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4438 | int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4439 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4440 | if (err) |
| 4441 | return err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4442 | } |
| 4443 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4444 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 4445 | mss = skb_shinfo(skb)->gso_size; |
| 4446 | if (skb->protocol == htons(ETH_P_IP)) { |
| 4447 | struct iphdr *iph = ip_hdr(skb); |
| 4448 | iph->tot_len = 0; |
| 4449 | iph->check = 0; |
| 4450 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, |
| 4451 | 0, IPPROTO_TCP, 0); |
| 4452 | cmd_length = E1000_TXD_CMD_IP; |
| 4453 | ipcse = skb_transport_offset(skb) - 1; |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 4454 | } else if (skb_is_gso_v6(skb)) { |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4455 | ipv6_hdr(skb)->payload_len = 0; |
| 4456 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 4457 | &ipv6_hdr(skb)->daddr, |
| 4458 | 0, IPPROTO_TCP, 0); |
| 4459 | ipcse = 0; |
| 4460 | } |
| 4461 | ipcss = skb_network_offset(skb); |
| 4462 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
| 4463 | tucss = skb_transport_offset(skb); |
| 4464 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
| 4465 | tucse = 0; |
| 4466 | |
| 4467 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
| 4468 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
| 4469 | |
| 4470 | i = tx_ring->next_to_use; |
| 4471 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 4472 | buffer_info = &tx_ring->buffer_info[i]; |
| 4473 | |
| 4474 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 4475 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 4476 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 4477 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 4478 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 4479 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 4480 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 4481 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 4482 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 4483 | |
| 4484 | buffer_info->time_stamp = jiffies; |
| 4485 | buffer_info->next_to_watch = i; |
| 4486 | |
| 4487 | i++; |
| 4488 | if (i == tx_ring->count) |
| 4489 | i = 0; |
| 4490 | tx_ring->next_to_use = i; |
| 4491 | |
| 4492 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 4496 | { |
| 4497 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4498 | struct e1000_context_desc *context_desc; |
| 4499 | struct e1000_buffer *buffer_info; |
| 4500 | unsigned int i; |
| 4501 | u8 css; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4502 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4503 | __be16 protocol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4504 | |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4505 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 4506 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4507 | |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4508 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) |
| 4509 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 4510 | else |
| 4511 | protocol = skb->protocol; |
| 4512 | |
Arthur Jones | 3f51839 | 2009-03-20 15:56:35 -0700 | [diff] [blame] | 4513 | switch (protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4514 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4515 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 4516 | cmd_len |= E1000_TXD_CMD_TCP; |
| 4517 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4518 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4519 | /* XXX not handling all IPV6 headers */ |
| 4520 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 4521 | cmd_len |= E1000_TXD_CMD_TCP; |
| 4522 | break; |
| 4523 | default: |
| 4524 | if (unlikely(net_ratelimit())) |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4525 | e_warn("checksum_partial proto=%x!\n", |
| 4526 | be16_to_cpu(protocol)); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4527 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4528 | } |
| 4529 | |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 4530 | css = skb_checksum_start_offset(skb); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4531 | |
| 4532 | i = tx_ring->next_to_use; |
| 4533 | buffer_info = &tx_ring->buffer_info[i]; |
| 4534 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 4535 | |
| 4536 | context_desc->lower_setup.ip_config = 0; |
| 4537 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 4538 | context_desc->upper_setup.tcp_fields.tucso = |
| 4539 | css + skb->csum_offset; |
| 4540 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 4541 | context_desc->tcp_seg_setup.data = 0; |
| 4542 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 4543 | |
| 4544 | buffer_info->time_stamp = jiffies; |
| 4545 | buffer_info->next_to_watch = i; |
| 4546 | |
| 4547 | i++; |
| 4548 | if (i == tx_ring->count) |
| 4549 | i = 0; |
| 4550 | tx_ring->next_to_use = i; |
| 4551 | |
| 4552 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | #define E1000_MAX_PER_TXD 8192 |
| 4556 | #define E1000_MAX_TXD_PWR 12 |
| 4557 | |
| 4558 | static int e1000_tx_map(struct e1000_adapter *adapter, |
| 4559 | struct sk_buff *skb, unsigned int first, |
| 4560 | unsigned int max_per_txd, unsigned int nr_frags, |
| 4561 | unsigned int mss) |
| 4562 | { |
| 4563 | struct e1000_ring *tx_ring = adapter->tx_ring; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4564 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4565 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 4566 | unsigned int len = skb_headlen(skb); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4567 | unsigned int offset = 0, size, count = 0, i; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4568 | unsigned int f, bytecount, segs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4569 | |
| 4570 | i = tx_ring->next_to_use; |
| 4571 | |
| 4572 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4573 | buffer_info = &tx_ring->buffer_info[i]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4574 | size = min(len, max_per_txd); |
| 4575 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4576 | buffer_info->length = size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4577 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4578 | buffer_info->next_to_watch = i; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4579 | buffer_info->dma = dma_map_single(&pdev->dev, |
| 4580 | skb->data + offset, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4581 | size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4582 | buffer_info->mapped_as_page = false; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4583 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4584 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4585 | |
| 4586 | len -= size; |
| 4587 | offset += size; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4588 | count++; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4589 | |
| 4590 | if (len) { |
| 4591 | i++; |
| 4592 | if (i == tx_ring->count) |
| 4593 | i = 0; |
| 4594 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | for (f = 0; f < nr_frags; f++) { |
| 4598 | struct skb_frag_struct *frag; |
| 4599 | |
| 4600 | frag = &skb_shinfo(skb)->frags[f]; |
| 4601 | len = frag->size; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4602 | offset = frag->page_offset; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4603 | |
| 4604 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4605 | i++; |
| 4606 | if (i == tx_ring->count) |
| 4607 | i = 0; |
| 4608 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4609 | buffer_info = &tx_ring->buffer_info[i]; |
| 4610 | size = min(len, max_per_txd); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4611 | |
| 4612 | buffer_info->length = size; |
| 4613 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4614 | buffer_info->next_to_watch = i; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4615 | buffer_info->dma = dma_map_page(&pdev->dev, frag->page, |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4616 | offset, size, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4617 | DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4618 | buffer_info->mapped_as_page = true; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4619 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4620 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4621 | |
| 4622 | len -= size; |
| 4623 | offset += size; |
| 4624 | count++; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4625 | } |
| 4626 | } |
| 4627 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4628 | segs = skb_shinfo(skb)->gso_segs ? : 1; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4629 | /* multiply data chunks by size of headers */ |
| 4630 | bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len; |
| 4631 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4632 | tx_ring->buffer_info[i].skb = skb; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4633 | tx_ring->buffer_info[i].segs = segs; |
| 4634 | tx_ring->buffer_info[i].bytecount = bytecount; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4635 | tx_ring->buffer_info[first].next_to_watch = i; |
| 4636 | |
| 4637 | return count; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4638 | |
| 4639 | dma_error: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4640 | dev_err(&pdev->dev, "Tx DMA map failed\n"); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4641 | buffer_info->dma = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4642 | if (count) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4643 | count--; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4644 | |
| 4645 | while (count--) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4646 | if (i == 0) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4647 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4648 | i--; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4649 | buffer_info = &tx_ring->buffer_info[i]; |
Joe Perches | 1d51c41 | 2010-11-14 17:04:32 +0000 | [diff] [blame] | 4650 | e1000_put_txbuf(adapter, buffer_info); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4651 | } |
| 4652 | |
| 4653 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | static void e1000_tx_queue(struct e1000_adapter *adapter, |
| 4657 | int tx_flags, int count) |
| 4658 | { |
| 4659 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4660 | struct e1000_tx_desc *tx_desc = NULL; |
| 4661 | struct e1000_buffer *buffer_info; |
| 4662 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 4663 | unsigned int i; |
| 4664 | |
| 4665 | if (tx_flags & E1000_TX_FLAGS_TSO) { |
| 4666 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 4667 | E1000_TXD_CMD_TSE; |
| 4668 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 4669 | |
| 4670 | if (tx_flags & E1000_TX_FLAGS_IPV4) |
| 4671 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
| 4672 | } |
| 4673 | |
| 4674 | if (tx_flags & E1000_TX_FLAGS_CSUM) { |
| 4675 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 4676 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 4677 | } |
| 4678 | |
| 4679 | if (tx_flags & E1000_TX_FLAGS_VLAN) { |
| 4680 | txd_lower |= E1000_TXD_CMD_VLE; |
| 4681 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 4682 | } |
| 4683 | |
| 4684 | i = tx_ring->next_to_use; |
| 4685 | |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 4686 | do { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4687 | buffer_info = &tx_ring->buffer_info[i]; |
| 4688 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 4689 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4690 | tx_desc->lower.data = |
| 4691 | cpu_to_le32(txd_lower | buffer_info->length); |
| 4692 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
| 4693 | |
| 4694 | i++; |
| 4695 | if (i == tx_ring->count) |
| 4696 | i = 0; |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 4697 | } while (--count > 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4698 | |
| 4699 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 4700 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4701 | /* |
| 4702 | * Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4703 | * know there are new descriptors to fetch. (Only |
| 4704 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4705 | * such as IA-64). |
| 4706 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4707 | wmb(); |
| 4708 | |
| 4709 | tx_ring->next_to_use = i; |
| 4710 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4711 | /* |
| 4712 | * we need this if more than one processor can write to our tail |
| 4713 | * at a time, it synchronizes IO on IA64/Altix systems |
| 4714 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4715 | mmiowb(); |
| 4716 | } |
| 4717 | |
| 4718 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 4719 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 4720 | struct sk_buff *skb) |
| 4721 | { |
| 4722 | struct e1000_hw *hw = &adapter->hw; |
| 4723 | u16 length, offset; |
| 4724 | |
| 4725 | if (vlan_tx_tag_present(skb)) { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 4726 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
| 4727 | (adapter->hw.mng_cookie.status & |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4728 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) |
| 4729 | return 0; |
| 4730 | } |
| 4731 | |
| 4732 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) |
| 4733 | return 0; |
| 4734 | |
| 4735 | if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP)) |
| 4736 | return 0; |
| 4737 | |
| 4738 | { |
| 4739 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14); |
| 4740 | struct udphdr *udp; |
| 4741 | |
| 4742 | if (ip->protocol != IPPROTO_UDP) |
| 4743 | return 0; |
| 4744 | |
| 4745 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 4746 | if (ntohs(udp->dest) != 67) |
| 4747 | return 0; |
| 4748 | |
| 4749 | offset = (u8 *)udp + 8 - skb->data; |
| 4750 | length = skb->len - offset; |
| 4751 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); |
| 4752 | } |
| 4753 | |
| 4754 | return 0; |
| 4755 | } |
| 4756 | |
| 4757 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 4758 | { |
| 4759 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4760 | |
| 4761 | netif_stop_queue(netdev); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4762 | /* |
| 4763 | * Herbert's original patch had: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4764 | * smp_mb__after_netif_stop_queue(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4765 | * but since that doesn't exist yet, just open code it. |
| 4766 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4767 | smp_mb(); |
| 4768 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4769 | /* |
| 4770 | * We need to check again in a case another CPU has just |
| 4771 | * made room available. |
| 4772 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4773 | if (e1000_desc_unused(adapter->tx_ring) < size) |
| 4774 | return -EBUSY; |
| 4775 | |
| 4776 | /* A reprieve! */ |
| 4777 | netif_start_queue(netdev); |
| 4778 | ++adapter->restart_queue; |
| 4779 | return 0; |
| 4780 | } |
| 4781 | |
| 4782 | static int e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 4783 | { |
| 4784 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4785 | |
| 4786 | if (e1000_desc_unused(adapter->tx_ring) >= size) |
| 4787 | return 0; |
| 4788 | return __e1000_maybe_stop_tx(netdev, size); |
| 4789 | } |
| 4790 | |
| 4791 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 4792 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 4793 | struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4794 | { |
| 4795 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4796 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4797 | unsigned int first; |
| 4798 | unsigned int max_per_txd = E1000_MAX_PER_TXD; |
| 4799 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 4800 | unsigned int tx_flags = 0; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 4801 | unsigned int len = skb_headlen(skb); |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 4802 | unsigned int nr_frags; |
| 4803 | unsigned int mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4804 | int count = 0; |
| 4805 | int tso; |
| 4806 | unsigned int f; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4807 | |
| 4808 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 4809 | dev_kfree_skb_any(skb); |
| 4810 | return NETDEV_TX_OK; |
| 4811 | } |
| 4812 | |
| 4813 | if (skb->len <= 0) { |
| 4814 | dev_kfree_skb_any(skb); |
| 4815 | return NETDEV_TX_OK; |
| 4816 | } |
| 4817 | |
| 4818 | mss = skb_shinfo(skb)->gso_size; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4819 | /* |
| 4820 | * The controller does a simple calculation to |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4821 | * make sure there is enough room in the FIFO before |
| 4822 | * initiating the DMA for each buffer. The calc is: |
| 4823 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 4824 | * overrun the FIFO, adjust the max buffer len if mss |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4825 | * drops. |
| 4826 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4827 | if (mss) { |
| 4828 | u8 hdr_len; |
| 4829 | max_per_txd = min(mss << 2, max_per_txd); |
| 4830 | max_txd_pwr = fls(max_per_txd) - 1; |
| 4831 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4832 | /* |
| 4833 | * TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 4834 | * points to just header, pull a few bytes of payload from |
| 4835 | * frags into skb->data |
| 4836 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4837 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4838 | /* |
| 4839 | * we do this workaround for ES2LAN, but it is un-necessary, |
| 4840 | * avoiding it could save a lot of cycles |
| 4841 | */ |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 4842 | if (skb->data_len && (hdr_len == len)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4843 | unsigned int pull_size; |
| 4844 | |
| 4845 | pull_size = min((unsigned int)4, skb->data_len); |
| 4846 | if (!__pskb_pull_tail(skb, pull_size)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4847 | e_err("__pskb_pull_tail failed.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4848 | dev_kfree_skb_any(skb); |
| 4849 | return NETDEV_TX_OK; |
| 4850 | } |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 4851 | len = skb_headlen(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | /* reserve a descriptor for the offload context */ |
| 4856 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 4857 | count++; |
| 4858 | count++; |
| 4859 | |
| 4860 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 4861 | |
| 4862 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 4863 | for (f = 0; f < nr_frags; f++) |
| 4864 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 4865 | max_txd_pwr); |
| 4866 | |
| 4867 | if (adapter->hw.mac.tx_pkt_filtering) |
| 4868 | e1000_transfer_dhcp_info(adapter, skb); |
| 4869 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4870 | /* |
| 4871 | * need: count + 2 desc gap to keep tail from touching |
| 4872 | * head, otherwise try next time |
| 4873 | */ |
Jesse Brandeburg | 92af3e9 | 2009-01-19 14:17:08 +0000 | [diff] [blame] | 4874 | if (e1000_maybe_stop_tx(netdev, count + 2)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4875 | return NETDEV_TX_BUSY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4876 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 4877 | if (vlan_tx_tag_present(skb)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4878 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 4879 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 4880 | } |
| 4881 | |
| 4882 | first = tx_ring->next_to_use; |
| 4883 | |
| 4884 | tso = e1000_tso(adapter, skb); |
| 4885 | if (tso < 0) { |
| 4886 | dev_kfree_skb_any(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4887 | return NETDEV_TX_OK; |
| 4888 | } |
| 4889 | |
| 4890 | if (tso) |
| 4891 | tx_flags |= E1000_TX_FLAGS_TSO; |
| 4892 | else if (e1000_tx_csum(adapter, skb)) |
| 4893 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 4894 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4895 | /* |
| 4896 | * 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] | 4897 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4898 | * no longer assume, we must. |
| 4899 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4900 | if (skb->protocol == htons(ETH_P_IP)) |
| 4901 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 4902 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4903 | /* if count is 0 then mapping error has occurred */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4904 | 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] | 4905 | if (count) { |
| 4906 | e1000_tx_queue(adapter, tx_flags, count); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4907 | /* Make sure there is space in the ring for the next send. */ |
| 4908 | e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2); |
| 4909 | |
| 4910 | } else { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4911 | dev_kfree_skb_any(skb); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4912 | tx_ring->buffer_info[first].time_stamp = 0; |
| 4913 | tx_ring->next_to_use = first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4914 | } |
| 4915 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4916 | return NETDEV_TX_OK; |
| 4917 | } |
| 4918 | |
| 4919 | /** |
| 4920 | * e1000_tx_timeout - Respond to a Tx Hang |
| 4921 | * @netdev: network interface device structure |
| 4922 | **/ |
| 4923 | static void e1000_tx_timeout(struct net_device *netdev) |
| 4924 | { |
| 4925 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4926 | |
| 4927 | /* Do the reset outside of interrupt context */ |
| 4928 | adapter->tx_timeout_count++; |
| 4929 | schedule_work(&adapter->reset_task); |
| 4930 | } |
| 4931 | |
| 4932 | static void e1000_reset_task(struct work_struct *work) |
| 4933 | { |
| 4934 | struct e1000_adapter *adapter; |
| 4935 | adapter = container_of(work, struct e1000_adapter, reset_task); |
| 4936 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4937 | /* don't run the task if already down */ |
| 4938 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4939 | return; |
| 4940 | |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 4941 | if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 4942 | (adapter->flags & FLAG_RX_RESTART_NOW))) { |
| 4943 | e1000e_dump(adapter); |
| 4944 | e_err("Reset adapter\n"); |
| 4945 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4946 | e1000e_reinit_locked(adapter); |
| 4947 | } |
| 4948 | |
| 4949 | /** |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4950 | * e1000_get_stats64 - Get System Network Statistics |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4951 | * @netdev: network interface device structure |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4952 | * @stats: rtnl_link_stats64 pointer |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4953 | * |
| 4954 | * Returns the address of the device statistics structure. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4955 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4956 | struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev, |
| 4957 | struct rtnl_link_stats64 *stats) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4958 | { |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4959 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4960 | |
| 4961 | memset(stats, 0, sizeof(struct rtnl_link_stats64)); |
| 4962 | spin_lock(&adapter->stats64_lock); |
| 4963 | e1000e_update_stats(adapter); |
| 4964 | /* Fill out the OS statistics structure */ |
| 4965 | stats->rx_bytes = adapter->stats.gorc; |
| 4966 | stats->rx_packets = adapter->stats.gprc; |
| 4967 | stats->tx_bytes = adapter->stats.gotc; |
| 4968 | stats->tx_packets = adapter->stats.gptc; |
| 4969 | stats->multicast = adapter->stats.mprc; |
| 4970 | stats->collisions = adapter->stats.colc; |
| 4971 | |
| 4972 | /* Rx Errors */ |
| 4973 | |
| 4974 | /* |
| 4975 | * RLEC on some newer hardware can be incorrect so build |
| 4976 | * our own version based on RUC and ROC |
| 4977 | */ |
| 4978 | stats->rx_errors = adapter->stats.rxerrc + |
| 4979 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 4980 | adapter->stats.ruc + adapter->stats.roc + |
| 4981 | adapter->stats.cexterr; |
| 4982 | stats->rx_length_errors = adapter->stats.ruc + |
| 4983 | adapter->stats.roc; |
| 4984 | stats->rx_crc_errors = adapter->stats.crcerrs; |
| 4985 | stats->rx_frame_errors = adapter->stats.algnerrc; |
| 4986 | stats->rx_missed_errors = adapter->stats.mpc; |
| 4987 | |
| 4988 | /* Tx Errors */ |
| 4989 | stats->tx_errors = adapter->stats.ecol + |
| 4990 | adapter->stats.latecol; |
| 4991 | stats->tx_aborted_errors = adapter->stats.ecol; |
| 4992 | stats->tx_window_errors = adapter->stats.latecol; |
| 4993 | stats->tx_carrier_errors = adapter->stats.tncrs; |
| 4994 | |
| 4995 | /* Tx Dropped needs to be maintained elsewhere */ |
| 4996 | |
| 4997 | spin_unlock(&adapter->stats64_lock); |
| 4998 | return stats; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | /** |
| 5002 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 5003 | * @netdev: network interface device structure |
| 5004 | * @new_mtu: new value for maximum frame size |
| 5005 | * |
| 5006 | * Returns 0 on success, negative on failure |
| 5007 | **/ |
| 5008 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 5009 | { |
| 5010 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5011 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5012 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5013 | /* Jumbo frame support */ |
| 5014 | if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) && |
| 5015 | !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
| 5016 | e_err("Jumbo Frames not supported.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5017 | return -EINVAL; |
| 5018 | } |
| 5019 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5020 | /* Supported frame sizes */ |
| 5021 | if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) || |
| 5022 | (max_frame > adapter->max_hw_frame_size)) { |
| 5023 | e_err("Unsupported MTU setting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5024 | return -EINVAL; |
| 5025 | } |
| 5026 | |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 5027 | /* Jumbo frame workaround on 82579 requires CRC be stripped */ |
| 5028 | if ((adapter->hw.mac.type == e1000_pch2lan) && |
| 5029 | !(adapter->flags2 & FLAG2_CRC_STRIPPING) && |
| 5030 | (new_mtu > ETH_DATA_LEN)) { |
| 5031 | e_err("Jumbo Frames not supported on 82579 when CRC " |
| 5032 | "stripping is disabled.\n"); |
| 5033 | return -EINVAL; |
| 5034 | } |
| 5035 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5036 | /* 82573 Errata 17 */ |
| 5037 | if (((adapter->hw.mac.type == e1000_82573) || |
| 5038 | (adapter->hw.mac.type == e1000_82574)) && |
| 5039 | (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) { |
| 5040 | adapter->flags2 |= FLAG2_DISABLE_ASPM_L1; |
| 5041 | e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1); |
| 5042 | } |
| 5043 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5044 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 5045 | usleep_range(1000, 2000); |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5046 | /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5047 | adapter->max_frame_size = max_frame; |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5048 | e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
| 5049 | netdev->mtu = new_mtu; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5050 | if (netif_running(netdev)) |
| 5051 | e1000e_down(adapter); |
| 5052 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5053 | /* |
| 5054 | * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5055 | * means we reserve 2 more, this pushes us to allocate from the next |
| 5056 | * larger slab size. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5057 | * i.e. RXBUFFER_2048 --> size-4096 slab |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5058 | * However with the new *_jumbo_rx* routines, jumbo receives will use |
| 5059 | * fragmented skbs |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5060 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5061 | |
Jesse Brandeburg | 9926146 | 2010-01-22 22:56:16 +0000 | [diff] [blame] | 5062 | if (max_frame <= 2048) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5063 | adapter->rx_buffer_len = 2048; |
| 5064 | else |
| 5065 | adapter->rx_buffer_len = 4096; |
| 5066 | |
| 5067 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
| 5068 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || |
| 5069 | (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) |
| 5070 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5071 | + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5072 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5073 | if (netif_running(netdev)) |
| 5074 | e1000e_up(adapter); |
| 5075 | else |
| 5076 | e1000e_reset(adapter); |
| 5077 | |
| 5078 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 5079 | |
| 5080 | return 0; |
| 5081 | } |
| 5082 | |
| 5083 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 5084 | int cmd) |
| 5085 | { |
| 5086 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5087 | struct mii_ioctl_data *data = if_mii(ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5088 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5089 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5090 | return -EOPNOTSUPP; |
| 5091 | |
| 5092 | switch (cmd) { |
| 5093 | case SIOCGMIIPHY: |
| 5094 | data->phy_id = adapter->hw.phy.addr; |
| 5095 | break; |
| 5096 | case SIOCGMIIREG: |
Bruce Allan | b16a002 | 2009-11-20 23:24:30 +0000 | [diff] [blame] | 5097 | e1000_phy_read_status(adapter); |
| 5098 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5099 | switch (data->reg_num & 0x1F) { |
| 5100 | case MII_BMCR: |
| 5101 | data->val_out = adapter->phy_regs.bmcr; |
| 5102 | break; |
| 5103 | case MII_BMSR: |
| 5104 | data->val_out = adapter->phy_regs.bmsr; |
| 5105 | break; |
| 5106 | case MII_PHYSID1: |
| 5107 | data->val_out = (adapter->hw.phy.id >> 16); |
| 5108 | break; |
| 5109 | case MII_PHYSID2: |
| 5110 | data->val_out = (adapter->hw.phy.id & 0xFFFF); |
| 5111 | break; |
| 5112 | case MII_ADVERTISE: |
| 5113 | data->val_out = adapter->phy_regs.advertise; |
| 5114 | break; |
| 5115 | case MII_LPA: |
| 5116 | data->val_out = adapter->phy_regs.lpa; |
| 5117 | break; |
| 5118 | case MII_EXPANSION: |
| 5119 | data->val_out = adapter->phy_regs.expansion; |
| 5120 | break; |
| 5121 | case MII_CTRL1000: |
| 5122 | data->val_out = adapter->phy_regs.ctrl1000; |
| 5123 | break; |
| 5124 | case MII_STAT1000: |
| 5125 | data->val_out = adapter->phy_regs.stat1000; |
| 5126 | break; |
| 5127 | case MII_ESTATUS: |
| 5128 | data->val_out = adapter->phy_regs.estatus; |
| 5129 | break; |
| 5130 | default: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5131 | return -EIO; |
| 5132 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5133 | break; |
| 5134 | case SIOCSMIIREG: |
| 5135 | default: |
| 5136 | return -EOPNOTSUPP; |
| 5137 | } |
| 5138 | return 0; |
| 5139 | } |
| 5140 | |
| 5141 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 5142 | { |
| 5143 | switch (cmd) { |
| 5144 | case SIOCGMIIPHY: |
| 5145 | case SIOCGMIIREG: |
| 5146 | case SIOCSMIIREG: |
| 5147 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 5148 | default: |
| 5149 | return -EOPNOTSUPP; |
| 5150 | } |
| 5151 | } |
| 5152 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5153 | static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) |
| 5154 | { |
| 5155 | struct e1000_hw *hw = &adapter->hw; |
| 5156 | u32 i, mac_reg; |
| 5157 | u16 phy_reg; |
| 5158 | int retval = 0; |
| 5159 | |
| 5160 | /* copy MAC RARs to PHY RARs */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 5161 | e1000_copy_rx_addrs_to_phy_ich8lan(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5162 | |
| 5163 | /* copy MAC MTA to PHY MTA */ |
| 5164 | for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { |
| 5165 | mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); |
| 5166 | e1e_wphy(hw, BM_MTA(i), (u16)(mac_reg & 0xFFFF)); |
| 5167 | e1e_wphy(hw, BM_MTA(i) + 1, (u16)((mac_reg >> 16) & 0xFFFF)); |
| 5168 | } |
| 5169 | |
| 5170 | /* configure PHY Rx Control register */ |
| 5171 | e1e_rphy(&adapter->hw, BM_RCTL, &phy_reg); |
| 5172 | mac_reg = er32(RCTL); |
| 5173 | if (mac_reg & E1000_RCTL_UPE) |
| 5174 | phy_reg |= BM_RCTL_UPE; |
| 5175 | if (mac_reg & E1000_RCTL_MPE) |
| 5176 | phy_reg |= BM_RCTL_MPE; |
| 5177 | phy_reg &= ~(BM_RCTL_MO_MASK); |
| 5178 | if (mac_reg & E1000_RCTL_MO_3) |
| 5179 | phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) |
| 5180 | << BM_RCTL_MO_SHIFT); |
| 5181 | if (mac_reg & E1000_RCTL_BAM) |
| 5182 | phy_reg |= BM_RCTL_BAM; |
| 5183 | if (mac_reg & E1000_RCTL_PMCF) |
| 5184 | phy_reg |= BM_RCTL_PMCF; |
| 5185 | mac_reg = er32(CTRL); |
| 5186 | if (mac_reg & E1000_CTRL_RFCE) |
| 5187 | phy_reg |= BM_RCTL_RFCE; |
| 5188 | e1e_wphy(&adapter->hw, BM_RCTL, phy_reg); |
| 5189 | |
| 5190 | /* enable PHY wakeup in MAC register */ |
| 5191 | ew32(WUFC, wufc); |
| 5192 | ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN); |
| 5193 | |
| 5194 | /* configure and enable PHY wakeup in PHY registers */ |
| 5195 | e1e_wphy(&adapter->hw, BM_WUFC, wufc); |
| 5196 | e1e_wphy(&adapter->hw, BM_WUC, E1000_WUC_PME_EN); |
| 5197 | |
| 5198 | /* activate PHY wakeup */ |
Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 5199 | retval = hw->phy.ops.acquire(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5200 | if (retval) { |
| 5201 | e_err("Could not acquire PHY\n"); |
| 5202 | return retval; |
| 5203 | } |
| 5204 | e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 5205 | (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT)); |
| 5206 | retval = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg); |
| 5207 | if (retval) { |
| 5208 | e_err("Could not read PHY page 769\n"); |
| 5209 | goto out; |
| 5210 | } |
| 5211 | phy_reg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; |
| 5212 | retval = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg); |
| 5213 | if (retval) |
| 5214 | e_err("Could not set PHY Host Wakeup bit\n"); |
| 5215 | out: |
Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 5216 | hw->phy.ops.release(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5217 | |
| 5218 | return retval; |
| 5219 | } |
| 5220 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5221 | static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake, |
| 5222 | bool runtime) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5223 | { |
| 5224 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5225 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5226 | struct e1000_hw *hw = &adapter->hw; |
| 5227 | u32 ctrl, ctrl_ext, rctl, status; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5228 | /* Runtime suspend should only enable wakeup for link changes */ |
| 5229 | u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5230 | int retval = 0; |
| 5231 | |
| 5232 | netif_device_detach(netdev); |
| 5233 | |
| 5234 | if (netif_running(netdev)) { |
| 5235 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 5236 | e1000e_down(adapter); |
| 5237 | e1000_free_irq(adapter); |
| 5238 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5239 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5240 | |
| 5241 | retval = pci_save_state(pdev); |
| 5242 | if (retval) |
| 5243 | return retval; |
| 5244 | |
| 5245 | status = er32(STATUS); |
| 5246 | if (status & E1000_STATUS_LU) |
| 5247 | wufc &= ~E1000_WUFC_LNKC; |
| 5248 | |
| 5249 | if (wufc) { |
| 5250 | e1000_setup_rctl(adapter); |
| 5251 | e1000_set_multi(netdev); |
| 5252 | |
| 5253 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5254 | if (wufc & E1000_WUFC_MC) { |
| 5255 | rctl = er32(RCTL); |
| 5256 | rctl |= E1000_RCTL_MPE; |
| 5257 | ew32(RCTL, rctl); |
| 5258 | } |
| 5259 | |
| 5260 | ctrl = er32(CTRL); |
| 5261 | /* advertise wake from D3Cold */ |
| 5262 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5263 | /* phy power management enable */ |
| 5264 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5265 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 5266 | if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) |
| 5267 | ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5268 | ew32(CTRL, ctrl); |
| 5269 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5270 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
| 5271 | adapter->hw.phy.media_type == |
| 5272 | e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5273 | /* keep the laser running in D3 */ |
| 5274 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | 93a23f4 | 2009-12-08 07:27:41 +0000 | [diff] [blame] | 5275 | ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5276 | ew32(CTRL_EXT, ctrl_ext); |
| 5277 | } |
| 5278 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5279 | if (adapter->flags & FLAG_IS_ICH) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5280 | e1000_suspend_workarounds_ich8lan(&adapter->hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5281 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5282 | /* Allow time for pending master requests to run */ |
| 5283 | e1000e_disable_pcie_master(&adapter->hw); |
| 5284 | |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5285 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5286 | /* enable wakeup by the PHY */ |
| 5287 | retval = e1000_init_phy_wakeup(adapter, wufc); |
| 5288 | if (retval) |
| 5289 | return retval; |
| 5290 | } else { |
| 5291 | /* enable wakeup by the MAC */ |
| 5292 | ew32(WUFC, wufc); |
| 5293 | ew32(WUC, E1000_WUC_PME_EN); |
| 5294 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5295 | } else { |
| 5296 | ew32(WUC, 0); |
| 5297 | ew32(WUFC, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5298 | } |
| 5299 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5300 | *enable_wake = !!wufc; |
| 5301 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5302 | /* make sure adapter isn't asleep if manageability is enabled */ |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5303 | if ((adapter->flags & FLAG_MNG_PT_ENABLED) || |
| 5304 | (hw->mac.ops.check_mng_mode(hw))) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5305 | *enable_wake = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5306 | |
| 5307 | if (adapter->hw.phy.type == e1000_phy_igp_3) |
| 5308 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
| 5309 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5310 | /* |
| 5311 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5312 | * would have already happened in close and is redundant. |
| 5313 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5314 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5315 | |
| 5316 | pci_disable_device(pdev); |
| 5317 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5318 | return 0; |
| 5319 | } |
| 5320 | |
| 5321 | static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake) |
| 5322 | { |
| 5323 | if (sleep && wake) { |
| 5324 | pci_prepare_to_sleep(pdev); |
| 5325 | return; |
| 5326 | } |
| 5327 | |
| 5328 | pci_wake_from_d3(pdev, wake); |
| 5329 | pci_set_power_state(pdev, PCI_D3hot); |
| 5330 | } |
| 5331 | |
| 5332 | static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, |
| 5333 | bool wake) |
| 5334 | { |
| 5335 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5336 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5337 | |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5338 | /* |
| 5339 | * The pci-e switch on some quad port adapters will report a |
| 5340 | * correctable error when the MAC transitions from D0 to D3. To |
| 5341 | * prevent this we need to mask off the correctable errors on the |
| 5342 | * downstream port of the pci-e switch. |
| 5343 | */ |
| 5344 | if (adapter->flags & FLAG_IS_QUAD_PORT) { |
| 5345 | struct pci_dev *us_dev = pdev->bus->self; |
| 5346 | int pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP); |
| 5347 | u16 devctl; |
| 5348 | |
| 5349 | pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl); |
| 5350 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, |
| 5351 | (devctl & ~PCI_EXP_DEVCTL_CERE)); |
| 5352 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5353 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5354 | |
| 5355 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl); |
| 5356 | } else { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5357 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5358 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5359 | } |
| 5360 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5361 | #ifdef CONFIG_PCIEASPM |
| 5362 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
| 5363 | { |
Yinghai Lu | 9f728f5 | 2011-05-12 17:11:47 -0700 | [diff] [blame] | 5364 | pci_disable_link_state_locked(pdev, state); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5365 | } |
| 5366 | #else |
| 5367 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5368 | { |
| 5369 | int pos; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5370 | u16 reg16; |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5371 | |
| 5372 | /* |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5373 | * Both device and parent should have the same ASPM setting. |
| 5374 | * Disable ASPM in downstream component first and then upstream. |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5375 | */ |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5376 | pos = pci_pcie_cap(pdev); |
| 5377 | pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16); |
| 5378 | reg16 &= ~state; |
| 5379 | pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16); |
| 5380 | |
Anton Blanchard | 0c75ba2 | 2010-04-28 21:46:06 +0000 | [diff] [blame] | 5381 | if (!pdev->bus->self) |
| 5382 | return; |
| 5383 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5384 | pos = pci_pcie_cap(pdev->bus->self); |
| 5385 | pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, ®16); |
| 5386 | reg16 &= ~state; |
| 5387 | pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16); |
| 5388 | } |
| 5389 | #endif |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5390 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5391 | { |
| 5392 | dev_info(&pdev->dev, "Disabling ASPM %s %s\n", |
| 5393 | (state & PCIE_LINK_STATE_L0S) ? "L0s" : "", |
| 5394 | (state & PCIE_LINK_STATE_L1) ? "L1" : ""); |
| 5395 | |
| 5396 | __e1000e_disable_aspm(pdev, state); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5397 | } |
| 5398 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 5399 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5400 | static bool e1000e_pm_ready(struct e1000_adapter *adapter) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5401 | { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5402 | return !!adapter->tx_ring->buffer_info; |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5403 | } |
| 5404 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5405 | static int __e1000_resume(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5406 | { |
| 5407 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5408 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5409 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5410 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5411 | u32 err; |
| 5412 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5413 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5414 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
| 5415 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
| 5416 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5417 | if (aspm_disable_flag) |
| 5418 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 5419 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5420 | pci_set_power_state(pdev, PCI_D0); |
| 5421 | pci_restore_state(pdev); |
Bruce Allan | 28b8f04 | 2010-01-07 16:30:56 +0000 | [diff] [blame] | 5422 | pci_save_state(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5423 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5424 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5425 | if (netif_running(netdev)) { |
| 5426 | err = e1000_request_irq(adapter); |
| 5427 | if (err) |
| 5428 | return err; |
| 5429 | } |
| 5430 | |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5431 | if (hw->mac.type == e1000_pch2lan) |
| 5432 | e1000_resume_workarounds_pchlan(&adapter->hw); |
| 5433 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5434 | e1000e_power_up_phy(adapter); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5435 | |
| 5436 | /* report the system wakeup cause from S3/S4 */ |
| 5437 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
| 5438 | u16 phy_data; |
| 5439 | |
| 5440 | e1e_rphy(&adapter->hw, BM_WUS, &phy_data); |
| 5441 | if (phy_data) { |
| 5442 | e_info("PHY Wakeup cause - %s\n", |
| 5443 | phy_data & E1000_WUS_EX ? "Unicast Packet" : |
| 5444 | phy_data & E1000_WUS_MC ? "Multicast Packet" : |
| 5445 | phy_data & E1000_WUS_BC ? "Broadcast Packet" : |
| 5446 | phy_data & E1000_WUS_MAG ? "Magic Packet" : |
| 5447 | phy_data & E1000_WUS_LNKC ? "Link Status " |
| 5448 | " Change" : "other"); |
| 5449 | } |
| 5450 | e1e_wphy(&adapter->hw, BM_WUS, ~0); |
| 5451 | } else { |
| 5452 | u32 wus = er32(WUS); |
| 5453 | if (wus) { |
| 5454 | e_info("MAC Wakeup cause - %s\n", |
| 5455 | wus & E1000_WUS_EX ? "Unicast Packet" : |
| 5456 | wus & E1000_WUS_MC ? "Multicast Packet" : |
| 5457 | wus & E1000_WUS_BC ? "Broadcast Packet" : |
| 5458 | wus & E1000_WUS_MAG ? "Magic Packet" : |
| 5459 | wus & E1000_WUS_LNKC ? "Link Status Change" : |
| 5460 | "other"); |
| 5461 | } |
| 5462 | ew32(WUS, ~0); |
| 5463 | } |
| 5464 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5465 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5466 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 5467 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5468 | |
| 5469 | if (netif_running(netdev)) |
| 5470 | e1000e_up(adapter); |
| 5471 | |
| 5472 | netif_device_attach(netdev); |
| 5473 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5474 | /* |
| 5475 | * 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] | 5476 | * 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] | 5477 | * under the control of the driver. |
| 5478 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5479 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5480 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5481 | |
| 5482 | return 0; |
| 5483 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5484 | |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5485 | #ifdef CONFIG_PM_SLEEP |
| 5486 | static int e1000_suspend(struct device *dev) |
| 5487 | { |
| 5488 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5489 | int retval; |
| 5490 | bool wake; |
| 5491 | |
| 5492 | retval = __e1000_shutdown(pdev, &wake, false); |
| 5493 | if (!retval) |
| 5494 | e1000_complete_shutdown(pdev, true, wake); |
| 5495 | |
| 5496 | return retval; |
| 5497 | } |
| 5498 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5499 | static int e1000_resume(struct device *dev) |
| 5500 | { |
| 5501 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5502 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5503 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5504 | |
| 5505 | if (e1000e_pm_ready(adapter)) |
| 5506 | adapter->idle_check = true; |
| 5507 | |
| 5508 | return __e1000_resume(pdev); |
| 5509 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5510 | #endif /* CONFIG_PM_SLEEP */ |
| 5511 | |
| 5512 | #ifdef CONFIG_PM_RUNTIME |
| 5513 | static int e1000_runtime_suspend(struct device *dev) |
| 5514 | { |
| 5515 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5516 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5517 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5518 | |
| 5519 | if (e1000e_pm_ready(adapter)) { |
| 5520 | bool wake; |
| 5521 | |
| 5522 | __e1000_shutdown(pdev, &wake, true); |
| 5523 | } |
| 5524 | |
| 5525 | return 0; |
| 5526 | } |
| 5527 | |
| 5528 | static int e1000_idle(struct device *dev) |
| 5529 | { |
| 5530 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5531 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5532 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5533 | |
| 5534 | if (!e1000e_pm_ready(adapter)) |
| 5535 | return 0; |
| 5536 | |
| 5537 | if (adapter->idle_check) { |
| 5538 | adapter->idle_check = false; |
| 5539 | if (!e1000e_has_link(adapter)) |
| 5540 | pm_schedule_suspend(dev, MSEC_PER_SEC); |
| 5541 | } |
| 5542 | |
| 5543 | return -EBUSY; |
| 5544 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5545 | |
| 5546 | static int e1000_runtime_resume(struct device *dev) |
| 5547 | { |
| 5548 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5549 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5550 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5551 | |
| 5552 | if (!e1000e_pm_ready(adapter)) |
| 5553 | return 0; |
| 5554 | |
| 5555 | adapter->idle_check = !dev->power.runtime_auto; |
| 5556 | return __e1000_resume(pdev); |
| 5557 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5558 | #endif /* CONFIG_PM_RUNTIME */ |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 5559 | #endif /* CONFIG_PM */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5560 | |
| 5561 | static void e1000_shutdown(struct pci_dev *pdev) |
| 5562 | { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5563 | bool wake = false; |
| 5564 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5565 | __e1000_shutdown(pdev, &wake, false); |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5566 | |
| 5567 | if (system_state == SYSTEM_POWER_OFF) |
| 5568 | e1000_complete_shutdown(pdev, false, wake); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5572 | |
| 5573 | static irqreturn_t e1000_intr_msix(int irq, void *data) |
| 5574 | { |
| 5575 | struct net_device *netdev = data; |
| 5576 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5577 | |
| 5578 | if (adapter->msix_entries) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 5579 | int vector, msix_irq; |
| 5580 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5581 | vector = 0; |
| 5582 | msix_irq = adapter->msix_entries[vector].vector; |
| 5583 | disable_irq(msix_irq); |
| 5584 | e1000_intr_msix_rx(msix_irq, netdev); |
| 5585 | enable_irq(msix_irq); |
| 5586 | |
| 5587 | vector++; |
| 5588 | msix_irq = adapter->msix_entries[vector].vector; |
| 5589 | disable_irq(msix_irq); |
| 5590 | e1000_intr_msix_tx(msix_irq, netdev); |
| 5591 | enable_irq(msix_irq); |
| 5592 | |
| 5593 | vector++; |
| 5594 | msix_irq = adapter->msix_entries[vector].vector; |
| 5595 | disable_irq(msix_irq); |
| 5596 | e1000_msix_other(msix_irq, netdev); |
| 5597 | enable_irq(msix_irq); |
| 5598 | } |
| 5599 | |
| 5600 | return IRQ_HANDLED; |
| 5601 | } |
| 5602 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5603 | /* |
| 5604 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5605 | * without having to re-enable interrupts. It's not called while |
| 5606 | * the interrupt routine is executing. |
| 5607 | */ |
| 5608 | static void e1000_netpoll(struct net_device *netdev) |
| 5609 | { |
| 5610 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5611 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5612 | switch (adapter->int_mode) { |
| 5613 | case E1000E_INT_MODE_MSIX: |
| 5614 | e1000_intr_msix(adapter->pdev->irq, netdev); |
| 5615 | break; |
| 5616 | case E1000E_INT_MODE_MSI: |
| 5617 | disable_irq(adapter->pdev->irq); |
| 5618 | e1000_intr_msi(adapter->pdev->irq, netdev); |
| 5619 | enable_irq(adapter->pdev->irq); |
| 5620 | break; |
| 5621 | default: /* E1000E_INT_MODE_LEGACY */ |
| 5622 | disable_irq(adapter->pdev->irq); |
| 5623 | e1000_intr(adapter->pdev->irq, netdev); |
| 5624 | enable_irq(adapter->pdev->irq); |
| 5625 | break; |
| 5626 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5627 | } |
| 5628 | #endif |
| 5629 | |
| 5630 | /** |
| 5631 | * e1000_io_error_detected - called when PCI error is detected |
| 5632 | * @pdev: Pointer to PCI device |
| 5633 | * @state: The current pci connection state |
| 5634 | * |
| 5635 | * This function is called after a PCI bus error affecting |
| 5636 | * this device has been detected. |
| 5637 | */ |
| 5638 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 5639 | pci_channel_state_t state) |
| 5640 | { |
| 5641 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5642 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5643 | |
| 5644 | netif_device_detach(netdev); |
| 5645 | |
Mike Mason | c93b5a7 | 2009-06-30 12:45:53 +0000 | [diff] [blame] | 5646 | if (state == pci_channel_io_perm_failure) |
| 5647 | return PCI_ERS_RESULT_DISCONNECT; |
| 5648 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5649 | if (netif_running(netdev)) |
| 5650 | e1000e_down(adapter); |
| 5651 | pci_disable_device(pdev); |
| 5652 | |
| 5653 | /* Request a slot slot reset. */ |
| 5654 | return PCI_ERS_RESULT_NEED_RESET; |
| 5655 | } |
| 5656 | |
| 5657 | /** |
| 5658 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 5659 | * @pdev: Pointer to PCI device |
| 5660 | * |
| 5661 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5662 | * resembles the first-half of the e1000_resume routine. |
| 5663 | */ |
| 5664 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 5665 | { |
| 5666 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5667 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5668 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5669 | u16 aspm_disable_flag = 0; |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5670 | int err; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5671 | pci_ers_result_t result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5672 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5673 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5674 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5675 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5676 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5677 | if (aspm_disable_flag) |
| 5678 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 5679 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 5680 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5681 | if (err) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5682 | dev_err(&pdev->dev, |
| 5683 | "Cannot re-enable PCI device after reset.\n"); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5684 | result = PCI_ERS_RESULT_DISCONNECT; |
| 5685 | } else { |
| 5686 | pci_set_master(pdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5687 | pdev->state_saved = true; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5688 | pci_restore_state(pdev); |
| 5689 | |
| 5690 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5691 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 5692 | |
| 5693 | e1000e_reset(adapter); |
| 5694 | ew32(WUS, ~0); |
| 5695 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5696 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5697 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5698 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5699 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5700 | return result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5701 | } |
| 5702 | |
| 5703 | /** |
| 5704 | * e1000_io_resume - called when traffic can start flowing again. |
| 5705 | * @pdev: Pointer to PCI device |
| 5706 | * |
| 5707 | * This callback is called when the error recovery driver tells us that |
| 5708 | * its OK to resume normal operation. Implementation resembles the |
| 5709 | * second-half of the e1000_resume routine. |
| 5710 | */ |
| 5711 | static void e1000_io_resume(struct pci_dev *pdev) |
| 5712 | { |
| 5713 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5714 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5715 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 5716 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5717 | |
| 5718 | if (netif_running(netdev)) { |
| 5719 | if (e1000e_up(adapter)) { |
| 5720 | dev_err(&pdev->dev, |
| 5721 | "can't bring device back up after reset\n"); |
| 5722 | return; |
| 5723 | } |
| 5724 | } |
| 5725 | |
| 5726 | netif_device_attach(netdev); |
| 5727 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5728 | /* |
| 5729 | * 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] | 5730 | * 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] | 5731 | * under the control of the driver. |
| 5732 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5733 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5734 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5735 | |
| 5736 | } |
| 5737 | |
| 5738 | static void e1000_print_device_info(struct e1000_adapter *adapter) |
| 5739 | { |
| 5740 | struct e1000_hw *hw = &adapter->hw; |
| 5741 | struct net_device *netdev = adapter->netdev; |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5742 | u32 ret_val; |
| 5743 | u8 pba_str[E1000_PBANUM_LENGTH]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5744 | |
| 5745 | /* print bus type/speed/width info */ |
Bruce Allan | a5cc764 | 2011-03-19 00:31:23 +0000 | [diff] [blame] | 5746 | e_info("(PCI Express:2.5GT/s:%s) %pM\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5747 | /* bus width */ |
| 5748 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
| 5749 | "Width x1"), |
| 5750 | /* MAC address */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5751 | netdev->dev_addr); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5752 | e_info("Intel(R) PRO/%s Network Connection\n", |
| 5753 | (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5754 | ret_val = e1000_read_pba_string_generic(hw, pba_str, |
| 5755 | E1000_PBANUM_LENGTH); |
| 5756 | if (ret_val) |
Bruce Allan | e0dc4f1 | 2011-01-06 14:29:50 +0000 | [diff] [blame] | 5757 | strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5758 | e_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 5759 | hw->mac.type, hw->phy.type, pba_str); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5760 | } |
| 5761 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5762 | static void e1000_eeprom_checks(struct e1000_adapter *adapter) |
| 5763 | { |
| 5764 | struct e1000_hw *hw = &adapter->hw; |
| 5765 | int ret_val; |
| 5766 | u16 buf = 0; |
| 5767 | |
| 5768 | if (hw->mac.type != e1000_82573) |
| 5769 | return; |
| 5770 | |
| 5771 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 5772 | if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) { |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5773 | /* Deep Smart Power Down (DSPD) */ |
Frans Pop | 6c2a9ef | 2008-09-22 14:52:22 -0700 | [diff] [blame] | 5774 | dev_warn(&adapter->pdev->dev, |
| 5775 | "Warning: detected DSPD enabled in EEPROM\n"); |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5776 | } |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5779 | static const struct net_device_ops e1000e_netdev_ops = { |
| 5780 | .ndo_open = e1000_open, |
| 5781 | .ndo_stop = e1000_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5782 | .ndo_start_xmit = e1000_xmit_frame, |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5783 | .ndo_get_stats64 = e1000e_get_stats64, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5784 | .ndo_set_multicast_list = e1000_set_multi, |
| 5785 | .ndo_set_mac_address = e1000_set_mac, |
| 5786 | .ndo_change_mtu = e1000_change_mtu, |
| 5787 | .ndo_do_ioctl = e1000_ioctl, |
| 5788 | .ndo_tx_timeout = e1000_tx_timeout, |
| 5789 | .ndo_validate_addr = eth_validate_addr, |
| 5790 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5791 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 5792 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 5793 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5794 | .ndo_poll_controller = e1000_netpoll, |
| 5795 | #endif |
| 5796 | }; |
| 5797 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5798 | /** |
| 5799 | * e1000_probe - Device Initialization Routine |
| 5800 | * @pdev: PCI device information struct |
| 5801 | * @ent: entry in e1000_pci_tbl |
| 5802 | * |
| 5803 | * Returns 0 on success, negative on failure |
| 5804 | * |
| 5805 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 5806 | * The OS initialization, configuring of the adapter private structure, |
| 5807 | * and a hardware reset occur. |
| 5808 | **/ |
| 5809 | static int __devinit e1000_probe(struct pci_dev *pdev, |
| 5810 | const struct pci_device_id *ent) |
| 5811 | { |
| 5812 | struct net_device *netdev; |
| 5813 | struct e1000_adapter *adapter; |
| 5814 | struct e1000_hw *hw; |
| 5815 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; |
Becky Bruce | f47e81f | 2008-05-01 18:03:11 -0500 | [diff] [blame] | 5816 | resource_size_t mmio_start, mmio_len; |
| 5817 | resource_size_t flash_start, flash_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5818 | |
| 5819 | static int cards_found; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5820 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5821 | int i, err, pci_using_dac; |
| 5822 | u16 eeprom_data = 0; |
| 5823 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
| 5824 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5825 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5826 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5827 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5828 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5829 | if (aspm_disable_flag) |
| 5830 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5831 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 5832 | err = pci_enable_device_mem(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5833 | if (err) |
| 5834 | return err; |
| 5835 | |
| 5836 | pci_using_dac = 0; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5837 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5838 | if (!err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5839 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5840 | if (!err) |
| 5841 | pci_using_dac = 1; |
| 5842 | } else { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5843 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5844 | if (err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5845 | err = dma_set_coherent_mask(&pdev->dev, |
| 5846 | DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5847 | if (err) { |
| 5848 | dev_err(&pdev->dev, "No usable DMA " |
| 5849 | "configuration, aborting\n"); |
| 5850 | goto err_dma; |
| 5851 | } |
| 5852 | } |
| 5853 | } |
| 5854 | |
Arjan van de Ven | e8de148 | 2008-10-22 19:55:31 -0700 | [diff] [blame] | 5855 | err = pci_request_selected_regions_exclusive(pdev, |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 5856 | pci_select_bars(pdev, IORESOURCE_MEM), |
| 5857 | e1000e_driver_name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5858 | if (err) |
| 5859 | goto err_pci_reg; |
| 5860 | |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 5861 | /* AER (Advanced Error Reporting) hooks */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 5862 | pci_enable_pcie_error_reporting(pdev); |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 5863 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5864 | pci_set_master(pdev); |
Bruce Allan | 438b365 | 2008-11-21 16:51:33 -0800 | [diff] [blame] | 5865 | /* PCI config space info */ |
| 5866 | err = pci_save_state(pdev); |
| 5867 | if (err) |
| 5868 | goto err_alloc_etherdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5869 | |
| 5870 | err = -ENOMEM; |
| 5871 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
| 5872 | if (!netdev) |
| 5873 | goto err_alloc_etherdev; |
| 5874 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5875 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 5876 | |
Tom Herbert | f85e4df | 2010-05-05 14:03:32 +0000 | [diff] [blame] | 5877 | netdev->irq = pdev->irq; |
| 5878 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5879 | pci_set_drvdata(pdev, netdev); |
| 5880 | adapter = netdev_priv(netdev); |
| 5881 | hw = &adapter->hw; |
| 5882 | adapter->netdev = netdev; |
| 5883 | adapter->pdev = pdev; |
| 5884 | adapter->ei = ei; |
| 5885 | adapter->pba = ei->pba; |
| 5886 | adapter->flags = ei->flags; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 5887 | adapter->flags2 = ei->flags2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5888 | adapter->hw.adapter = adapter; |
| 5889 | adapter->hw.mac.type = ei->mac; |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5890 | adapter->max_hw_frame_size = ei->max_hw_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5891 | adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; |
| 5892 | |
| 5893 | mmio_start = pci_resource_start(pdev, 0); |
| 5894 | mmio_len = pci_resource_len(pdev, 0); |
| 5895 | |
| 5896 | err = -EIO; |
| 5897 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 5898 | if (!adapter->hw.hw_addr) |
| 5899 | goto err_ioremap; |
| 5900 | |
| 5901 | if ((adapter->flags & FLAG_HAS_FLASH) && |
| 5902 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
| 5903 | flash_start = pci_resource_start(pdev, 1); |
| 5904 | flash_len = pci_resource_len(pdev, 1); |
| 5905 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
| 5906 | if (!adapter->hw.flash_address) |
| 5907 | goto err_flashmap; |
| 5908 | } |
| 5909 | |
| 5910 | /* construct the net_device struct */ |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5911 | netdev->netdev_ops = &e1000e_netdev_ops; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5912 | e1000e_set_ethtool_ops(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5913 | netdev->watchdog_timeo = 5 * HZ; |
| 5914 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5915 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
| 5916 | |
| 5917 | netdev->mem_start = mmio_start; |
| 5918 | netdev->mem_end = mmio_start + mmio_len; |
| 5919 | |
| 5920 | adapter->bd_number = cards_found++; |
| 5921 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5922 | e1000e_check_options(adapter); |
| 5923 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5924 | /* setup adapter struct */ |
| 5925 | err = e1000_sw_init(adapter); |
| 5926 | if (err) |
| 5927 | goto err_sw_init; |
| 5928 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5929 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 5930 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 5931 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 5932 | |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 5933 | err = ei->get_variants(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5934 | if (err) |
| 5935 | goto err_hw_init; |
| 5936 | |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 5937 | if ((adapter->flags & FLAG_IS_ICH) && |
| 5938 | (adapter->flags & FLAG_READ_ONLY_NVM)) |
| 5939 | e1000e_write_protect_nvm_ich8lan(&adapter->hw); |
| 5940 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5941 | hw->mac.ops.get_bus_info(&adapter->hw); |
| 5942 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5943 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5944 | |
| 5945 | /* Copper options */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5946 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5947 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
| 5948 | adapter->hw.phy.disable_polarity_correction = 0; |
| 5949 | adapter->hw.phy.ms_type = e1000_ms_hw_default; |
| 5950 | } |
| 5951 | |
| 5952 | if (e1000_check_reset_block(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5953 | e_info("PHY reset is blocked due to SOL/IDER session.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5954 | |
| 5955 | netdev->features = NETIF_F_SG | |
| 5956 | NETIF_F_HW_CSUM | |
| 5957 | NETIF_F_HW_VLAN_TX | |
| 5958 | NETIF_F_HW_VLAN_RX; |
| 5959 | |
| 5960 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
| 5961 | netdev->features |= NETIF_F_HW_VLAN_FILTER; |
| 5962 | |
| 5963 | netdev->features |= NETIF_F_TSO; |
| 5964 | netdev->features |= NETIF_F_TSO6; |
| 5965 | |
Jeff Kirsher | a5136e2 | 2008-06-05 04:07:28 -0700 | [diff] [blame] | 5966 | netdev->vlan_features |= NETIF_F_TSO; |
| 5967 | netdev->vlan_features |= NETIF_F_TSO6; |
| 5968 | netdev->vlan_features |= NETIF_F_HW_CSUM; |
| 5969 | netdev->vlan_features |= NETIF_F_SG; |
| 5970 | |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 5971 | if (pci_using_dac) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5972 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 5973 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 5974 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5975 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5976 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
| 5977 | adapter->flags |= FLAG_MNG_PT_ENABLED; |
| 5978 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5979 | /* |
| 5980 | * before reading the NVM, reset the controller to |
| 5981 | * put the device in a known good starting state |
| 5982 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5983 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 5984 | |
| 5985 | /* |
| 5986 | * systems with ASPM and others may see the checksum fail on the first |
| 5987 | * attempt. Let's give it a few tries |
| 5988 | */ |
| 5989 | for (i = 0;; i++) { |
| 5990 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) |
| 5991 | break; |
| 5992 | if (i == 2) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5993 | e_err("The NVM Checksum Is Not Valid\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5994 | err = -EIO; |
| 5995 | goto err_eeprom; |
| 5996 | } |
| 5997 | } |
| 5998 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5999 | e1000_eeprom_checks(adapter); |
| 6000 | |
Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 6001 | /* copy the MAC address */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6002 | if (e1000e_read_mac_addr(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6003 | e_err("NVM Read Error while reading MAC address\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6004 | |
| 6005 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 6006 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 6007 | |
| 6008 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 6009 | e_err("Invalid MAC Address: %pM\n", netdev->perm_addr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6010 | err = -EIO; |
| 6011 | goto err_eeprom; |
| 6012 | } |
| 6013 | |
| 6014 | init_timer(&adapter->watchdog_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6015 | adapter->watchdog_timer.function = e1000_watchdog; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6016 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 6017 | |
| 6018 | init_timer(&adapter->phy_info_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6019 | adapter->phy_info_timer.function = e1000_update_phy_info; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6020 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 6021 | |
| 6022 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
| 6023 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 6024 | INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); |
| 6025 | INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6026 | INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6027 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6028 | /* Initialize link parameters. User can change them with ethtool */ |
| 6029 | adapter->hw.mac.autoneg = 1; |
Auke Kok | 309af40 | 2007-10-05 15:22:02 -0700 | [diff] [blame] | 6030 | adapter->fc_autoneg = 1; |
Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 6031 | adapter->hw.fc.requested_mode = e1000_fc_default; |
| 6032 | adapter->hw.fc.current_mode = e1000_fc_default; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6033 | adapter->hw.phy.autoneg_advertised = 0x2f; |
| 6034 | |
| 6035 | /* ring size defaults */ |
| 6036 | adapter->rx_ring->count = 256; |
| 6037 | adapter->tx_ring->count = 256; |
| 6038 | |
| 6039 | /* |
| 6040 | * Initial Wake on LAN setting - If APM wake is enabled in |
| 6041 | * the EEPROM, enable the ACPI Magic Packet filter |
| 6042 | */ |
| 6043 | if (adapter->flags & FLAG_APME_IN_WUC) { |
| 6044 | /* APME bit in EEPROM is mapped to WUC.APME */ |
| 6045 | eeprom_data = er32(WUC); |
| 6046 | eeprom_apme_mask = E1000_WUC_APME; |
Bruce Allan | 4def99b | 2011-02-02 09:30:36 +0000 | [diff] [blame] | 6047 | if ((hw->mac.type > e1000_ich10lan) && |
| 6048 | (eeprom_data & E1000_WUC_PHY_WAKE)) |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6049 | adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6050 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
| 6051 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && |
| 6052 | (adapter->hw.bus.func == 1)) |
| 6053 | e1000_read_nvm(&adapter->hw, |
| 6054 | NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 6055 | else |
| 6056 | e1000_read_nvm(&adapter->hw, |
| 6057 | NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 6058 | } |
| 6059 | |
| 6060 | /* fetch WoL from EEPROM */ |
| 6061 | if (eeprom_data & eeprom_apme_mask) |
| 6062 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 6063 | |
| 6064 | /* |
| 6065 | * now that we have the eeprom settings, apply the special cases |
| 6066 | * where the eeprom may be wrong or the board simply won't support |
| 6067 | * wake on lan on a particular port |
| 6068 | */ |
| 6069 | if (!(adapter->flags & FLAG_HAS_WOL)) |
| 6070 | adapter->eeprom_wol = 0; |
| 6071 | |
| 6072 | /* initialize the wol settings based on the eeprom settings */ |
| 6073 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | 6ff6802 | 2008-11-12 09:52:32 +0000 | [diff] [blame] | 6074 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6075 | |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 6076 | /* save off EEPROM version number */ |
| 6077 | e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); |
| 6078 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6079 | /* reset the hardware with the new settings */ |
| 6080 | e1000e_reset(adapter); |
| 6081 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6082 | /* |
| 6083 | * 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] | 6084 | * 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] | 6085 | * under the control of the driver. |
| 6086 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6087 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6088 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6089 | |
Bruce Allan | e0dc4f1 | 2011-01-06 14:29:50 +0000 | [diff] [blame] | 6090 | strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6091 | err = register_netdev(netdev); |
| 6092 | if (err) |
| 6093 | goto err_register; |
| 6094 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 6095 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 6096 | netif_carrier_off(netdev); |
| 6097 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6098 | e1000_print_device_info(adapter); |
| 6099 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6100 | if (pci_dev_run_wake(pdev)) |
| 6101 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6102 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6103 | return 0; |
| 6104 | |
| 6105 | err_register: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6106 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6107 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6108 | err_eeprom: |
| 6109 | if (!e1000_check_reset_block(&adapter->hw)) |
| 6110 | e1000_phy_hw_reset(&adapter->hw); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6111 | err_hw_init: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6112 | kfree(adapter->tx_ring); |
| 6113 | kfree(adapter->rx_ring); |
| 6114 | err_sw_init: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6115 | if (adapter->hw.flash_address) |
| 6116 | iounmap(adapter->hw.flash_address); |
Jeff Kirsher | e82f54b | 2008-11-14 06:45:07 +0000 | [diff] [blame] | 6117 | e1000e_reset_interrupt_capability(adapter); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6118 | err_flashmap: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6119 | iounmap(adapter->hw.hw_addr); |
| 6120 | err_ioremap: |
| 6121 | free_netdev(netdev); |
| 6122 | err_alloc_etherdev: |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6123 | pci_release_selected_regions(pdev, |
| 6124 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6125 | err_pci_reg: |
| 6126 | err_dma: |
| 6127 | pci_disable_device(pdev); |
| 6128 | return err; |
| 6129 | } |
| 6130 | |
| 6131 | /** |
| 6132 | * e1000_remove - Device Removal Routine |
| 6133 | * @pdev: PCI device information struct |
| 6134 | * |
| 6135 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 6136 | * that it should release a PCI device. The could be caused by a |
| 6137 | * Hot-Plug event, or because the driver is going to be removed from |
| 6138 | * memory. |
| 6139 | **/ |
| 6140 | static void __devexit e1000_remove(struct pci_dev *pdev) |
| 6141 | { |
| 6142 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6143 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6144 | bool down = test_bit(__E1000_DOWN, &adapter->state); |
| 6145 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6146 | /* |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 6147 | * The timers may be rescheduled, so explicitly disable them |
| 6148 | * from being rescheduled. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6149 | */ |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6150 | if (!down) |
| 6151 | set_bit(__E1000_DOWN, &adapter->state); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6152 | del_timer_sync(&adapter->watchdog_timer); |
| 6153 | del_timer_sync(&adapter->phy_info_timer); |
| 6154 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6155 | cancel_work_sync(&adapter->reset_task); |
| 6156 | cancel_work_sync(&adapter->watchdog_task); |
| 6157 | cancel_work_sync(&adapter->downshift_task); |
| 6158 | cancel_work_sync(&adapter->update_phy_task); |
| 6159 | cancel_work_sync(&adapter->print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6160 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6161 | if (!(netdev->flags & IFF_UP)) |
| 6162 | e1000_power_down_phy(adapter); |
| 6163 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6164 | /* Don't lie to e1000_close() down the road. */ |
| 6165 | if (!down) |
| 6166 | clear_bit(__E1000_DOWN, &adapter->state); |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6167 | unregister_netdev(netdev); |
| 6168 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6169 | if (pci_dev_run_wake(pdev)) |
| 6170 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6171 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6172 | /* |
| 6173 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 6174 | * would have already happened in close and is redundant. |
| 6175 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6176 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6177 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6178 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6179 | kfree(adapter->tx_ring); |
| 6180 | kfree(adapter->rx_ring); |
| 6181 | |
| 6182 | iounmap(adapter->hw.hw_addr); |
| 6183 | if (adapter->hw.flash_address) |
| 6184 | iounmap(adapter->hw.flash_address); |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6185 | pci_release_selected_regions(pdev, |
| 6186 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6187 | |
| 6188 | free_netdev(netdev); |
| 6189 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6190 | /* AER disable */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6191 | pci_disable_pcie_error_reporting(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6192 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6193 | pci_disable_device(pdev); |
| 6194 | } |
| 6195 | |
| 6196 | /* PCI Error Recovery (ERS) */ |
| 6197 | static struct pci_error_handlers e1000_err_handler = { |
| 6198 | .error_detected = e1000_io_error_detected, |
| 6199 | .slot_reset = e1000_io_slot_reset, |
| 6200 | .resume = e1000_io_resume, |
| 6201 | }; |
| 6202 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 6203 | static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6204 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
| 6205 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, |
| 6206 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, |
| 6207 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 }, |
| 6208 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
| 6209 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, |
Auke Kok | 040babf | 2007-10-31 15:22:05 -0700 | [diff] [blame] | 6210 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
| 6211 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, |
| 6212 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6213 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6214 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
| 6215 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, |
| 6216 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, |
| 6217 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6218 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6219 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
| 6220 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, |
| 6221 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6222 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6223 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, |
Bruce Allan | bef28b1 | 2009-03-24 23:28:02 -0700 | [diff] [blame] | 6224 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 6225 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6226 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6227 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
| 6228 | board_80003es2lan }, |
| 6229 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), |
| 6230 | board_80003es2lan }, |
| 6231 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), |
| 6232 | board_80003es2lan }, |
| 6233 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), |
| 6234 | board_80003es2lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6235 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6236 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
| 6237 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, |
| 6238 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, |
| 6239 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, |
| 6240 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, |
| 6241 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, |
| 6242 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, |
Bruce Allan | 9e135a2 | 2009-12-01 15:50:31 +0000 | [diff] [blame] | 6243 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6244 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6245 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
| 6246 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, |
| 6247 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, |
| 6248 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, |
| 6249 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, |
Bruce Allan | 2f15f9d | 2008-08-26 18:36:36 -0700 | [diff] [blame] | 6250 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6251 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, |
| 6252 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, |
| 6253 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, |
| 6254 | |
| 6255 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, |
| 6256 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, |
| 6257 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6258 | |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6259 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, |
| 6260 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, |
Bruce Allan | 10df0b9 | 2010-05-10 15:02:52 +0000 | [diff] [blame] | 6261 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan }, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6262 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6263 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, |
| 6264 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, |
| 6265 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, |
| 6266 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, |
| 6267 | |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 6268 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan }, |
| 6269 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan }, |
| 6270 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6271 | { } /* terminate list */ |
| 6272 | }; |
| 6273 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 6274 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6275 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6276 | static const struct dev_pm_ops e1000_pm_ops = { |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6277 | SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume) |
| 6278 | SET_RUNTIME_PM_OPS(e1000_runtime_suspend, |
| 6279 | e1000_runtime_resume, e1000_idle) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6280 | }; |
David S. Miller | e50208a | 2010-03-16 23:36:24 -0700 | [diff] [blame] | 6281 | #endif |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6282 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6283 | /* PCI Device API Driver */ |
| 6284 | static struct pci_driver e1000_driver = { |
| 6285 | .name = e1000e_driver_name, |
| 6286 | .id_table = e1000_pci_tbl, |
| 6287 | .probe = e1000_probe, |
| 6288 | .remove = __devexit_p(e1000_remove), |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6289 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6290 | .driver.pm = &e1000_pm_ops, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6291 | #endif |
| 6292 | .shutdown = e1000_shutdown, |
| 6293 | .err_handler = &e1000_err_handler |
| 6294 | }; |
| 6295 | |
| 6296 | /** |
| 6297 | * e1000_init_module - Driver Registration Routine |
| 6298 | * |
| 6299 | * e1000_init_module is the first routine called when the driver is |
| 6300 | * loaded. All it does is register with the PCI subsystem. |
| 6301 | **/ |
| 6302 | static int __init e1000_init_module(void) |
| 6303 | { |
| 6304 | int ret; |
Bruce Allan | 8544b9f | 2010-03-24 12:55:30 +0000 | [diff] [blame] | 6305 | pr_info("Intel(R) PRO/1000 Network Driver - %s\n", |
| 6306 | e1000e_driver_version); |
Bruce Allan | 0d6057e | 2011-01-04 01:16:44 +0000 | [diff] [blame] | 6307 | pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6308 | ret = pci_register_driver(&e1000_driver); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 6309 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6310 | return ret; |
| 6311 | } |
| 6312 | module_init(e1000_init_module); |
| 6313 | |
| 6314 | /** |
| 6315 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 6316 | * |
| 6317 | * e1000_exit_module is called just before the driver is removed |
| 6318 | * from memory. |
| 6319 | **/ |
| 6320 | static void __exit e1000_exit_module(void) |
| 6321 | { |
| 6322 | pci_unregister_driver(&e1000_driver); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6323 | } |
| 6324 | module_exit(e1000_exit_module); |
| 6325 | |
| 6326 | |
| 6327 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 6328 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 6329 | MODULE_LICENSE("GPL"); |
| 6330 | MODULE_VERSION(DRV_VERSION); |
| 6331 | |
| 6332 | /* e1000_main.c */ |