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 | b3ccf26 | 2011-05-19 01:53:41 +0000 | [diff] [blame] | 57 | #define DRV_EXTRAVERSION "-k" |
Bruce Allan | c14c643 | 2010-06-16 13:28:34 +0000 | [diff] [blame] | 58 | |
Bruce Allan | b3ccf26 | 2011-05-19 01:53:41 +0000 | [diff] [blame] | 59 | #define DRV_VERSION "1.3.16" 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, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 526 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 547 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
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, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 592 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 618 | ps_page->page = alloc_page(gfp); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 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 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 644 | skb = __netdev_alloc_skb_ip_align(netdev, |
| 645 | adapter->rx_ps_bsize0, |
| 646 | gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 647 | |
| 648 | if (!skb) { |
| 649 | adapter->alloc_rx_buff_failed++; |
| 650 | break; |
| 651 | } |
| 652 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 653 | buffer_info->skb = skb; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 654 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 655 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 656 | DMA_FROM_DEVICE); |
| 657 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 658 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 659 | adapter->rx_dma_failed++; |
| 660 | /* cleanup skb */ |
| 661 | dev_kfree_skb_any(skb); |
| 662 | buffer_info->skb = NULL; |
| 663 | break; |
| 664 | } |
| 665 | |
| 666 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 667 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 668 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
| 669 | /* |
| 670 | * Force memory writes to complete before letting h/w |
| 671 | * know there are new descriptors to fetch. (Only |
| 672 | * applicable for weak-ordered memory model archs, |
| 673 | * such as IA-64). |
| 674 | */ |
| 675 | wmb(); |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 676 | writel(i << 1, adapter->hw.hw_addr + rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 677 | } |
| 678 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 679 | i++; |
| 680 | if (i == rx_ring->count) |
| 681 | i = 0; |
| 682 | buffer_info = &rx_ring->buffer_info[i]; |
| 683 | } |
| 684 | |
| 685 | no_buffers: |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 686 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 690 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
| 691 | * @adapter: address of board private structure |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 692 | * @cleaned_count: number of buffers to allocate this pass |
| 693 | **/ |
| 694 | |
| 695 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 696 | int cleaned_count, gfp_t gfp) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 697 | { |
| 698 | struct net_device *netdev = adapter->netdev; |
| 699 | struct pci_dev *pdev = adapter->pdev; |
| 700 | struct e1000_rx_desc *rx_desc; |
| 701 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 702 | struct e1000_buffer *buffer_info; |
| 703 | struct sk_buff *skb; |
| 704 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 705 | unsigned int bufsz = 256 - 16 /* for skb_reserve */; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 706 | |
| 707 | i = rx_ring->next_to_use; |
| 708 | buffer_info = &rx_ring->buffer_info[i]; |
| 709 | |
| 710 | while (cleaned_count--) { |
| 711 | skb = buffer_info->skb; |
| 712 | if (skb) { |
| 713 | skb_trim(skb, 0); |
| 714 | goto check_page; |
| 715 | } |
| 716 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 717 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 718 | if (unlikely(!skb)) { |
| 719 | /* Better luck next round */ |
| 720 | adapter->alloc_rx_buff_failed++; |
| 721 | break; |
| 722 | } |
| 723 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 724 | buffer_info->skb = skb; |
| 725 | check_page: |
| 726 | /* allocate a new page if necessary */ |
| 727 | if (!buffer_info->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 728 | buffer_info->page = alloc_page(gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 729 | if (unlikely(!buffer_info->page)) { |
| 730 | adapter->alloc_rx_buff_failed++; |
| 731 | break; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | if (!buffer_info->dma) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 736 | buffer_info->dma = dma_map_page(&pdev->dev, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 737 | buffer_info->page, 0, |
| 738 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 739 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 740 | |
| 741 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 742 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 743 | |
| 744 | if (unlikely(++i == rx_ring->count)) |
| 745 | i = 0; |
| 746 | buffer_info = &rx_ring->buffer_info[i]; |
| 747 | } |
| 748 | |
| 749 | if (likely(rx_ring->next_to_use != i)) { |
| 750 | rx_ring->next_to_use = i; |
| 751 | if (unlikely(i-- == 0)) |
| 752 | i = (rx_ring->count - 1); |
| 753 | |
| 754 | /* Force memory writes to complete before letting h/w |
| 755 | * know there are new descriptors to fetch. (Only |
| 756 | * applicable for weak-ordered memory model archs, |
| 757 | * such as IA-64). */ |
| 758 | wmb(); |
| 759 | writel(i, adapter->hw.hw_addr + rx_ring->tail); |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 764 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
| 765 | * @adapter: board private structure |
| 766 | * |
| 767 | * the return value indicates whether actual cleaning was done, there |
| 768 | * is no guarantee that everything was cleaned |
| 769 | **/ |
| 770 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 771 | int *work_done, int work_to_do) |
| 772 | { |
| 773 | struct net_device *netdev = adapter->netdev; |
| 774 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 775 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 776 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 777 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 778 | struct e1000_buffer *buffer_info, *next_buffer; |
| 779 | u32 length; |
| 780 | unsigned int i; |
| 781 | int cleaned_count = 0; |
| 782 | bool cleaned = 0; |
| 783 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 784 | |
| 785 | i = rx_ring->next_to_clean; |
| 786 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 787 | buffer_info = &rx_ring->buffer_info[i]; |
| 788 | |
| 789 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
| 790 | struct sk_buff *skb; |
| 791 | u8 status; |
| 792 | |
| 793 | if (*work_done >= work_to_do) |
| 794 | break; |
| 795 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 796 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 797 | |
| 798 | status = rx_desc->status; |
| 799 | skb = buffer_info->skb; |
| 800 | buffer_info->skb = NULL; |
| 801 | |
| 802 | prefetch(skb->data - NET_IP_ALIGN); |
| 803 | |
| 804 | i++; |
| 805 | if (i == rx_ring->count) |
| 806 | i = 0; |
| 807 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
| 808 | prefetch(next_rxd); |
| 809 | |
| 810 | next_buffer = &rx_ring->buffer_info[i]; |
| 811 | |
| 812 | cleaned = 1; |
| 813 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 814 | dma_unmap_single(&pdev->dev, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 815 | buffer_info->dma, |
| 816 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 817 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 818 | buffer_info->dma = 0; |
| 819 | |
| 820 | length = le16_to_cpu(rx_desc->length); |
| 821 | |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 822 | /* |
| 823 | * !EOP means multiple descriptors were used to store a single |
| 824 | * packet, if that's the case we need to toss it. In fact, we |
| 825 | * need to toss every packet with the EOP bit clear and the |
| 826 | * next frame that _does_ have the EOP bit set, as it is by |
| 827 | * definition only a frame fragment |
| 828 | */ |
| 829 | if (unlikely(!(status & E1000_RXD_STAT_EOP))) |
| 830 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 831 | |
| 832 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 833 | /* All receives must fit into a single buffer */ |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 834 | e_dbg("Receive packet consumed multiple buffers\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 835 | /* recycle */ |
| 836 | buffer_info->skb = skb; |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 837 | if (status & E1000_RXD_STAT_EOP) |
| 838 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 839 | goto next_desc; |
| 840 | } |
| 841 | |
| 842 | if (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) { |
| 843 | /* recycle */ |
| 844 | buffer_info->skb = skb; |
| 845 | goto next_desc; |
| 846 | } |
| 847 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 848 | /* adjust length to remove Ethernet CRC */ |
| 849 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 850 | length -= 4; |
| 851 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 852 | total_rx_bytes += length; |
| 853 | total_rx_packets++; |
| 854 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 855 | /* |
| 856 | * code added for copybreak, this should improve |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 857 | * performance for small packets with large amounts |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 858 | * of reassembly being done in the stack |
| 859 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 860 | if (length < copybreak) { |
| 861 | struct sk_buff *new_skb = |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 862 | netdev_alloc_skb_ip_align(netdev, length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 863 | if (new_skb) { |
Bruce Allan | 808ff67 | 2008-08-08 18:35:56 -0700 | [diff] [blame] | 864 | skb_copy_to_linear_data_offset(new_skb, |
| 865 | -NET_IP_ALIGN, |
| 866 | (skb->data - |
| 867 | NET_IP_ALIGN), |
| 868 | (length + |
| 869 | NET_IP_ALIGN)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 870 | /* save the skb in buffer_info as good */ |
| 871 | buffer_info->skb = skb; |
| 872 | skb = new_skb; |
| 873 | } |
| 874 | /* else just continue with the old one */ |
| 875 | } |
| 876 | /* end copybreak code */ |
| 877 | skb_put(skb, length); |
| 878 | |
| 879 | /* Receive Checksum Offload */ |
| 880 | e1000_rx_checksum(adapter, |
| 881 | (u32)(status) | |
| 882 | ((u32)(rx_desc->errors) << 24), |
| 883 | le16_to_cpu(rx_desc->csum), skb); |
| 884 | |
| 885 | e1000_receive_skb(adapter, netdev, skb,status,rx_desc->special); |
| 886 | |
| 887 | next_desc: |
| 888 | rx_desc->status = 0; |
| 889 | |
| 890 | /* return some buffers to hardware, one at a time is too slow */ |
| 891 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 892 | adapter->alloc_rx_buf(adapter, cleaned_count, |
| 893 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 894 | cleaned_count = 0; |
| 895 | } |
| 896 | |
| 897 | /* use prefetched values */ |
| 898 | rx_desc = next_rxd; |
| 899 | buffer_info = next_buffer; |
| 900 | } |
| 901 | rx_ring->next_to_clean = i; |
| 902 | |
| 903 | cleaned_count = e1000_desc_unused(rx_ring); |
| 904 | if (cleaned_count) |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 905 | adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 906 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 907 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 908 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 909 | return cleaned; |
| 910 | } |
| 911 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 912 | static void e1000_put_txbuf(struct e1000_adapter *adapter, |
| 913 | struct e1000_buffer *buffer_info) |
| 914 | { |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 915 | if (buffer_info->dma) { |
| 916 | if (buffer_info->mapped_as_page) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 917 | dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, |
| 918 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 919 | else |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 920 | dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, |
| 921 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 922 | buffer_info->dma = 0; |
| 923 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 924 | if (buffer_info->skb) { |
| 925 | dev_kfree_skb_any(buffer_info->skb); |
| 926 | buffer_info->skb = NULL; |
| 927 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 928 | buffer_info->time_stamp = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 931 | static void e1000_print_hw_hang(struct work_struct *work) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 932 | { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 933 | struct e1000_adapter *adapter = container_of(work, |
| 934 | struct e1000_adapter, |
| 935 | print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 936 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 937 | unsigned int i = tx_ring->next_to_clean; |
| 938 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; |
| 939 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 940 | struct e1000_hw *hw = &adapter->hw; |
| 941 | u16 phy_status, phy_1000t_status, phy_ext_status; |
| 942 | u16 pci_status; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 943 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 944 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 945 | return; |
| 946 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 947 | e1e_rphy(hw, PHY_STATUS, &phy_status); |
| 948 | e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status); |
| 949 | e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status); |
| 950 | |
| 951 | pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status); |
| 952 | |
| 953 | /* detected Hardware unit hang */ |
| 954 | e_err("Detected Hardware Unit Hang:\n" |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 955 | " TDH <%x>\n" |
| 956 | " TDT <%x>\n" |
| 957 | " next_to_use <%x>\n" |
| 958 | " next_to_clean <%x>\n" |
| 959 | "buffer_info[next_to_clean]:\n" |
| 960 | " time_stamp <%lx>\n" |
| 961 | " next_to_watch <%x>\n" |
| 962 | " jiffies <%lx>\n" |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 963 | " next_to_watch.status <%x>\n" |
| 964 | "MAC Status <%x>\n" |
| 965 | "PHY Status <%x>\n" |
| 966 | "PHY 1000BASE-T Status <%x>\n" |
| 967 | "PHY Extended Status <%x>\n" |
| 968 | "PCI Status <%x>\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 969 | readl(adapter->hw.hw_addr + tx_ring->head), |
| 970 | readl(adapter->hw.hw_addr + tx_ring->tail), |
| 971 | tx_ring->next_to_use, |
| 972 | tx_ring->next_to_clean, |
| 973 | tx_ring->buffer_info[eop].time_stamp, |
| 974 | eop, |
| 975 | jiffies, |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 976 | eop_desc->upper.fields.status, |
| 977 | er32(STATUS), |
| 978 | phy_status, |
| 979 | phy_1000t_status, |
| 980 | phy_ext_status, |
| 981 | pci_status); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | /** |
| 985 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 986 | * @adapter: board private structure |
| 987 | * |
| 988 | * the return value indicates whether actual cleaning was done, there |
| 989 | * is no guarantee that everything was cleaned |
| 990 | **/ |
| 991 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter) |
| 992 | { |
| 993 | struct net_device *netdev = adapter->netdev; |
| 994 | struct e1000_hw *hw = &adapter->hw; |
| 995 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 996 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 997 | struct e1000_buffer *buffer_info; |
| 998 | unsigned int i, eop; |
| 999 | unsigned int count = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1000 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; |
| 1001 | |
| 1002 | i = tx_ring->next_to_clean; |
| 1003 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1004 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 1005 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1006 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 1007 | (count < tx_ring->count)) { |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1008 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1009 | rmb(); /* read buffer_info after eop_desc */ |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1010 | for (; !cleaned; count++) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1011 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 1012 | buffer_info = &tx_ring->buffer_info[i]; |
| 1013 | cleaned = (i == eop); |
| 1014 | |
| 1015 | if (cleaned) { |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 1016 | total_tx_packets += buffer_info->segs; |
| 1017 | total_tx_bytes += buffer_info->bytecount; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | e1000_put_txbuf(adapter, buffer_info); |
| 1021 | tx_desc->upper.data = 0; |
| 1022 | |
| 1023 | i++; |
| 1024 | if (i == tx_ring->count) |
| 1025 | i = 0; |
| 1026 | } |
| 1027 | |
Terry Loftin | dac8761 | 2010-04-09 10:29:49 +0000 | [diff] [blame] | 1028 | if (i == tx_ring->next_to_use) |
| 1029 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1030 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1031 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | tx_ring->next_to_clean = i; |
| 1035 | |
| 1036 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1037 | if (count && netif_carrier_ok(netdev) && |
| 1038 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1039 | /* Make sure that anybody stopping the queue after this |
| 1040 | * sees the new next_to_clean. |
| 1041 | */ |
| 1042 | smp_mb(); |
| 1043 | |
| 1044 | if (netif_queue_stopped(netdev) && |
| 1045 | !(test_bit(__E1000_DOWN, &adapter->state))) { |
| 1046 | netif_wake_queue(netdev); |
| 1047 | ++adapter->restart_queue; |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | if (adapter->detect_tx_hung) { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1052 | /* |
| 1053 | * Detect a transmit hang in hardware, this serializes the |
| 1054 | * check with the clearing of time_stamp and movement of i |
| 1055 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1056 | adapter->detect_tx_hung = 0; |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1057 | if (tx_ring->buffer_info[i].time_stamp && |
| 1058 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1059 | + (adapter->tx_timeout_factor * HZ)) && |
| 1060 | !(er32(STATUS) & E1000_STATUS_TXOFF)) { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1061 | schedule_work(&adapter->print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1062 | netif_stop_queue(netdev); |
| 1063 | } |
| 1064 | } |
| 1065 | adapter->total_tx_bytes += total_tx_bytes; |
| 1066 | adapter->total_tx_packets += total_tx_packets; |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1067 | return count < tx_ring->count; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1071 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
| 1072 | * @adapter: board private structure |
| 1073 | * |
| 1074 | * the return value indicates whether actual cleaning was done, there |
| 1075 | * is no guarantee that everything was cleaned |
| 1076 | **/ |
| 1077 | static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 1078 | int *work_done, int work_to_do) |
| 1079 | { |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1080 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1081 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
| 1082 | struct net_device *netdev = adapter->netdev; |
| 1083 | struct pci_dev *pdev = adapter->pdev; |
| 1084 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1085 | struct e1000_buffer *buffer_info, *next_buffer; |
| 1086 | struct e1000_ps_page *ps_page; |
| 1087 | struct sk_buff *skb; |
| 1088 | unsigned int i, j; |
| 1089 | u32 length, staterr; |
| 1090 | int cleaned_count = 0; |
| 1091 | bool cleaned = 0; |
| 1092 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 1093 | |
| 1094 | i = rx_ring->next_to_clean; |
| 1095 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 1096 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1097 | buffer_info = &rx_ring->buffer_info[i]; |
| 1098 | |
| 1099 | while (staterr & E1000_RXD_STAT_DD) { |
| 1100 | if (*work_done >= work_to_do) |
| 1101 | break; |
| 1102 | (*work_done)++; |
| 1103 | skb = buffer_info->skb; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1104 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1105 | |
| 1106 | /* in the packet split case this is header only */ |
| 1107 | prefetch(skb->data - NET_IP_ALIGN); |
| 1108 | |
| 1109 | i++; |
| 1110 | if (i == rx_ring->count) |
| 1111 | i = 0; |
| 1112 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
| 1113 | prefetch(next_rxd); |
| 1114 | |
| 1115 | next_buffer = &rx_ring->buffer_info[i]; |
| 1116 | |
| 1117 | cleaned = 1; |
| 1118 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1119 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1120 | adapter->rx_ps_bsize0, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1121 | buffer_info->dma = 0; |
| 1122 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1123 | /* see !EOP comment in other Rx routine */ |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1124 | if (!(staterr & E1000_RXD_STAT_EOP)) |
| 1125 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 1126 | |
| 1127 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1128 | e_dbg("Packet Split buffers didn't pick up the full " |
| 1129 | "packet\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1130 | dev_kfree_skb_irq(skb); |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1131 | if (staterr & E1000_RXD_STAT_EOP) |
| 1132 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1133 | goto next_desc; |
| 1134 | } |
| 1135 | |
| 1136 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
| 1137 | dev_kfree_skb_irq(skb); |
| 1138 | goto next_desc; |
| 1139 | } |
| 1140 | |
| 1141 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 1142 | |
| 1143 | if (!length) { |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1144 | e_dbg("Last part of the packet spanning multiple " |
| 1145 | "descriptors\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1146 | dev_kfree_skb_irq(skb); |
| 1147 | goto next_desc; |
| 1148 | } |
| 1149 | |
| 1150 | /* Good Receive */ |
| 1151 | skb_put(skb, length); |
| 1152 | |
| 1153 | { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1154 | /* |
| 1155 | * this looks ugly, but it seems compiler issues make it |
| 1156 | * more efficient than reusing j |
| 1157 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1158 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 1159 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1160 | /* |
| 1161 | * page alloc/put takes too long and effects small packet |
| 1162 | * throughput, so unsplit small packets and save the alloc/put |
| 1163 | * only valid in softirq (napi) context to call kmap_* |
| 1164 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1165 | if (l1 && (l1 <= copybreak) && |
| 1166 | ((length + l1) <= adapter->rx_ps_bsize0)) { |
| 1167 | u8 *vaddr; |
| 1168 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1169 | ps_page = &buffer_info->ps_pages[0]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1170 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1171 | /* |
| 1172 | * there is no documentation about how to call |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1173 | * kmap_atomic, so we can't hold the mapping |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1174 | * very long |
| 1175 | */ |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1176 | dma_sync_single_for_cpu(&pdev->dev, ps_page->dma, |
| 1177 | PAGE_SIZE, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1178 | vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ); |
| 1179 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
| 1180 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1181 | dma_sync_single_for_device(&pdev->dev, ps_page->dma, |
| 1182 | PAGE_SIZE, DMA_FROM_DEVICE); |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 1183 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1184 | /* remove the CRC */ |
| 1185 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 1186 | l1 -= 4; |
| 1187 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1188 | skb_put(skb, l1); |
| 1189 | goto copydone; |
| 1190 | } /* if */ |
| 1191 | } |
| 1192 | |
| 1193 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
| 1194 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); |
| 1195 | if (!length) |
| 1196 | break; |
| 1197 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1198 | ps_page = &buffer_info->ps_pages[j]; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1199 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1200 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1201 | ps_page->dma = 0; |
| 1202 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); |
| 1203 | ps_page->page = NULL; |
| 1204 | skb->len += length; |
| 1205 | skb->data_len += length; |
| 1206 | skb->truesize += length; |
| 1207 | } |
| 1208 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1209 | /* strip the ethernet crc, problem is we're using pages now so |
| 1210 | * this whole operation can get a little cpu intensive |
| 1211 | */ |
| 1212 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 1213 | pskb_trim(skb, skb->len - 4); |
| 1214 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1215 | copydone: |
| 1216 | total_rx_bytes += skb->len; |
| 1217 | total_rx_packets++; |
| 1218 | |
| 1219 | e1000_rx_checksum(adapter, staterr, le16_to_cpu( |
| 1220 | rx_desc->wb.lower.hi_dword.csum_ip.csum), skb); |
| 1221 | |
| 1222 | if (rx_desc->wb.upper.header_status & |
| 1223 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) |
| 1224 | adapter->rx_hdr_split++; |
| 1225 | |
| 1226 | e1000_receive_skb(adapter, netdev, skb, |
| 1227 | staterr, rx_desc->wb.middle.vlan); |
| 1228 | |
| 1229 | next_desc: |
| 1230 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
| 1231 | buffer_info->skb = NULL; |
| 1232 | |
| 1233 | /* return some buffers to hardware, one at a time is too slow */ |
| 1234 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 1235 | adapter->alloc_rx_buf(adapter, cleaned_count, |
| 1236 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1237 | cleaned_count = 0; |
| 1238 | } |
| 1239 | |
| 1240 | /* use prefetched values */ |
| 1241 | rx_desc = next_rxd; |
| 1242 | buffer_info = next_buffer; |
| 1243 | |
| 1244 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1245 | } |
| 1246 | rx_ring->next_to_clean = i; |
| 1247 | |
| 1248 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1249 | if (cleaned_count) |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 1250 | adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1251 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1252 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1253 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1254 | return cleaned; |
| 1255 | } |
| 1256 | |
| 1257 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1258 | * e1000_consume_page - helper function |
| 1259 | **/ |
| 1260 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
| 1261 | u16 length) |
| 1262 | { |
| 1263 | bi->page = NULL; |
| 1264 | skb->len += length; |
| 1265 | skb->data_len += length; |
| 1266 | skb->truesize += length; |
| 1267 | } |
| 1268 | |
| 1269 | /** |
| 1270 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 1271 | * @adapter: board private structure |
| 1272 | * |
| 1273 | * the return value indicates whether actual cleaning was done, there |
| 1274 | * is no guarantee that everything was cleaned |
| 1275 | **/ |
| 1276 | |
| 1277 | static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, |
| 1278 | int *work_done, int work_to_do) |
| 1279 | { |
| 1280 | struct net_device *netdev = adapter->netdev; |
| 1281 | struct pci_dev *pdev = adapter->pdev; |
| 1282 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1283 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 1284 | struct e1000_buffer *buffer_info, *next_buffer; |
| 1285 | u32 length; |
| 1286 | unsigned int i; |
| 1287 | int cleaned_count = 0; |
| 1288 | bool cleaned = false; |
| 1289 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
| 1290 | |
| 1291 | i = rx_ring->next_to_clean; |
| 1292 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 1293 | buffer_info = &rx_ring->buffer_info[i]; |
| 1294 | |
| 1295 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
| 1296 | struct sk_buff *skb; |
| 1297 | u8 status; |
| 1298 | |
| 1299 | if (*work_done >= work_to_do) |
| 1300 | break; |
| 1301 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1302 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1303 | |
| 1304 | status = rx_desc->status; |
| 1305 | skb = buffer_info->skb; |
| 1306 | buffer_info->skb = NULL; |
| 1307 | |
| 1308 | ++i; |
| 1309 | if (i == rx_ring->count) |
| 1310 | i = 0; |
| 1311 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
| 1312 | prefetch(next_rxd); |
| 1313 | |
| 1314 | next_buffer = &rx_ring->buffer_info[i]; |
| 1315 | |
| 1316 | cleaned = true; |
| 1317 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1318 | dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE, |
| 1319 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1320 | buffer_info->dma = 0; |
| 1321 | |
| 1322 | length = le16_to_cpu(rx_desc->length); |
| 1323 | |
| 1324 | /* errors is only valid for DD + EOP descriptors */ |
| 1325 | if (unlikely((status & E1000_RXD_STAT_EOP) && |
| 1326 | (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) { |
| 1327 | /* recycle both page and skb */ |
| 1328 | buffer_info->skb = skb; |
| 1329 | /* an error means any chain goes out the window |
| 1330 | * too */ |
| 1331 | if (rx_ring->rx_skb_top) |
Bruce Allan | ef5ab89 | 2011-02-10 08:17:21 +0000 | [diff] [blame] | 1332 | dev_kfree_skb_irq(rx_ring->rx_skb_top); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1333 | rx_ring->rx_skb_top = NULL; |
| 1334 | goto next_desc; |
| 1335 | } |
| 1336 | |
Bruce Allan | f0f1a17 | 2010-12-11 05:53:32 +0000 | [diff] [blame] | 1337 | #define rxtop (rx_ring->rx_skb_top) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1338 | if (!(status & E1000_RXD_STAT_EOP)) { |
| 1339 | /* this descriptor is only the beginning (or middle) */ |
| 1340 | if (!rxtop) { |
| 1341 | /* this is the beginning of a chain */ |
| 1342 | rxtop = skb; |
| 1343 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
| 1344 | 0, length); |
| 1345 | } else { |
| 1346 | /* this is the middle of a chain */ |
| 1347 | skb_fill_page_desc(rxtop, |
| 1348 | skb_shinfo(rxtop)->nr_frags, |
| 1349 | buffer_info->page, 0, length); |
| 1350 | /* re-use the skb, only consumed the page */ |
| 1351 | buffer_info->skb = skb; |
| 1352 | } |
| 1353 | e1000_consume_page(buffer_info, rxtop, length); |
| 1354 | goto next_desc; |
| 1355 | } else { |
| 1356 | if (rxtop) { |
| 1357 | /* end of the chain */ |
| 1358 | skb_fill_page_desc(rxtop, |
| 1359 | skb_shinfo(rxtop)->nr_frags, |
| 1360 | buffer_info->page, 0, length); |
| 1361 | /* re-use the current skb, we only consumed the |
| 1362 | * page */ |
| 1363 | buffer_info->skb = skb; |
| 1364 | skb = rxtop; |
| 1365 | rxtop = NULL; |
| 1366 | e1000_consume_page(buffer_info, skb, length); |
| 1367 | } else { |
| 1368 | /* no chain, got EOP, this buf is the packet |
| 1369 | * copybreak to save the put_page/alloc_page */ |
| 1370 | if (length <= copybreak && |
| 1371 | skb_tailroom(skb) >= length) { |
| 1372 | u8 *vaddr; |
| 1373 | vaddr = kmap_atomic(buffer_info->page, |
| 1374 | KM_SKB_DATA_SOFTIRQ); |
| 1375 | memcpy(skb_tail_pointer(skb), vaddr, |
| 1376 | length); |
| 1377 | kunmap_atomic(vaddr, |
| 1378 | KM_SKB_DATA_SOFTIRQ); |
| 1379 | /* re-use the page, so don't erase |
| 1380 | * buffer_info->page */ |
| 1381 | skb_put(skb, length); |
| 1382 | } else { |
| 1383 | skb_fill_page_desc(skb, 0, |
| 1384 | buffer_info->page, 0, |
| 1385 | length); |
| 1386 | e1000_consume_page(buffer_info, skb, |
| 1387 | length); |
| 1388 | } |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | /* Receive Checksum Offload XXX recompute due to CRC strip? */ |
| 1393 | e1000_rx_checksum(adapter, |
| 1394 | (u32)(status) | |
| 1395 | ((u32)(rx_desc->errors) << 24), |
| 1396 | le16_to_cpu(rx_desc->csum), skb); |
| 1397 | |
| 1398 | /* probably a little skewed due to removing CRC */ |
| 1399 | total_rx_bytes += skb->len; |
| 1400 | total_rx_packets++; |
| 1401 | |
| 1402 | /* eth type trans needs skb->data to point to something */ |
| 1403 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1404 | e_err("pskb_may_pull failed.\n"); |
Bruce Allan | ef5ab89 | 2011-02-10 08:17:21 +0000 | [diff] [blame] | 1405 | dev_kfree_skb_irq(skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1406 | goto next_desc; |
| 1407 | } |
| 1408 | |
| 1409 | e1000_receive_skb(adapter, netdev, skb, status, |
| 1410 | rx_desc->special); |
| 1411 | |
| 1412 | next_desc: |
| 1413 | rx_desc->status = 0; |
| 1414 | |
| 1415 | /* return some buffers to hardware, one at a time is too slow */ |
| 1416 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 1417 | adapter->alloc_rx_buf(adapter, cleaned_count, |
| 1418 | GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1419 | cleaned_count = 0; |
| 1420 | } |
| 1421 | |
| 1422 | /* use prefetched values */ |
| 1423 | rx_desc = next_rxd; |
| 1424 | buffer_info = next_buffer; |
| 1425 | } |
| 1426 | rx_ring->next_to_clean = i; |
| 1427 | |
| 1428 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1429 | if (cleaned_count) |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 1430 | adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1431 | |
| 1432 | adapter->total_rx_bytes += total_rx_bytes; |
| 1433 | adapter->total_rx_packets += total_rx_packets; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1434 | return cleaned; |
| 1435 | } |
| 1436 | |
| 1437 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1438 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 1439 | * @adapter: board private structure |
| 1440 | **/ |
| 1441 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter) |
| 1442 | { |
| 1443 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1444 | struct e1000_buffer *buffer_info; |
| 1445 | struct e1000_ps_page *ps_page; |
| 1446 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1447 | unsigned int i, j; |
| 1448 | |
| 1449 | /* Free all the Rx ring sk_buffs */ |
| 1450 | for (i = 0; i < rx_ring->count; i++) { |
| 1451 | buffer_info = &rx_ring->buffer_info[i]; |
| 1452 | if (buffer_info->dma) { |
| 1453 | if (adapter->clean_rx == e1000_clean_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1454 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1455 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1456 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1457 | else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1458 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1459 | PAGE_SIZE, |
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 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1462 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1463 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1464 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1465 | buffer_info->dma = 0; |
| 1466 | } |
| 1467 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1468 | if (buffer_info->page) { |
| 1469 | put_page(buffer_info->page); |
| 1470 | buffer_info->page = NULL; |
| 1471 | } |
| 1472 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1473 | if (buffer_info->skb) { |
| 1474 | dev_kfree_skb(buffer_info->skb); |
| 1475 | buffer_info->skb = NULL; |
| 1476 | } |
| 1477 | |
| 1478 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1479 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1480 | if (!ps_page->page) |
| 1481 | break; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1482 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1483 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1484 | ps_page->dma = 0; |
| 1485 | put_page(ps_page->page); |
| 1486 | ps_page->page = NULL; |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | /* there also may be some cached data from a chained receive */ |
| 1491 | if (rx_ring->rx_skb_top) { |
| 1492 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 1493 | rx_ring->rx_skb_top = NULL; |
| 1494 | } |
| 1495 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1496 | /* Zero out the descriptor ring */ |
| 1497 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1498 | |
| 1499 | rx_ring->next_to_clean = 0; |
| 1500 | rx_ring->next_to_use = 0; |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1501 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1502 | |
| 1503 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 1504 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
| 1505 | } |
| 1506 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1507 | static void e1000e_downshift_workaround(struct work_struct *work) |
| 1508 | { |
| 1509 | struct e1000_adapter *adapter = container_of(work, |
| 1510 | struct e1000_adapter, downshift_task); |
| 1511 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1512 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1513 | return; |
| 1514 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1515 | e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); |
| 1516 | } |
| 1517 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1518 | /** |
| 1519 | * e1000_intr_msi - Interrupt Handler |
| 1520 | * @irq: interrupt number |
| 1521 | * @data: pointer to a network interface device structure |
| 1522 | **/ |
| 1523 | static irqreturn_t e1000_intr_msi(int irq, void *data) |
| 1524 | { |
| 1525 | struct net_device *netdev = data; |
| 1526 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1527 | struct e1000_hw *hw = &adapter->hw; |
| 1528 | u32 icr = er32(ICR); |
| 1529 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1530 | /* |
| 1531 | * read ICR disables interrupts using IAM |
| 1532 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1533 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1534 | if (icr & E1000_ICR_LSC) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1535 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1536 | /* |
| 1537 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1538 | * disconnect (LSC) before accessing any PHY registers |
| 1539 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1540 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1541 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1542 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1543 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1544 | /* |
| 1545 | * 80003ES2LAN workaround-- For packet buffer work-around on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1546 | * link down event; disable receives here in the ISR and reset |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1547 | * adapter in watchdog |
| 1548 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1549 | if (netif_carrier_ok(netdev) && |
| 1550 | adapter->flags & FLAG_RX_NEEDS_RESTART) { |
| 1551 | /* disable receives */ |
| 1552 | u32 rctl = er32(RCTL); |
| 1553 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1554 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1555 | } |
| 1556 | /* guard against interrupt when we're going down */ |
| 1557 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1558 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1559 | } |
| 1560 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1561 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1562 | adapter->total_tx_bytes = 0; |
| 1563 | adapter->total_tx_packets = 0; |
| 1564 | adapter->total_rx_bytes = 0; |
| 1565 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1566 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | return IRQ_HANDLED; |
| 1570 | } |
| 1571 | |
| 1572 | /** |
| 1573 | * e1000_intr - Interrupt Handler |
| 1574 | * @irq: interrupt number |
| 1575 | * @data: pointer to a network interface device structure |
| 1576 | **/ |
| 1577 | static irqreturn_t e1000_intr(int irq, void *data) |
| 1578 | { |
| 1579 | struct net_device *netdev = data; |
| 1580 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1581 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1582 | u32 rctl, icr = er32(ICR); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1583 | |
Bruce Allan | a68ea77 | 2009-11-20 23:23:16 +0000 | [diff] [blame] | 1584 | if (!icr || test_bit(__E1000_DOWN, &adapter->state)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1585 | return IRQ_NONE; /* Not our interrupt */ |
| 1586 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1587 | /* |
| 1588 | * IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 1589 | * not set, then the adapter didn't send an interrupt |
| 1590 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1591 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 1592 | return IRQ_NONE; |
| 1593 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1594 | /* |
| 1595 | * Interrupt Auto-Mask...upon reading ICR, |
| 1596 | * interrupts are masked. No need for the |
| 1597 | * IMC write |
| 1598 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1599 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1600 | if (icr & E1000_ICR_LSC) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1601 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1602 | /* |
| 1603 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1604 | * disconnect (LSC) before accessing any PHY registers |
| 1605 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1606 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1607 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1608 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1609 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1610 | /* |
| 1611 | * 80003ES2LAN workaround-- |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1612 | * For packet buffer work-around on link down event; |
| 1613 | * disable receives here in the ISR and |
| 1614 | * reset adapter in watchdog |
| 1615 | */ |
| 1616 | if (netif_carrier_ok(netdev) && |
| 1617 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { |
| 1618 | /* disable receives */ |
| 1619 | rctl = er32(RCTL); |
| 1620 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1621 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1622 | } |
| 1623 | /* guard against interrupt when we're going down */ |
| 1624 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1625 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1626 | } |
| 1627 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1628 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1629 | adapter->total_tx_bytes = 0; |
| 1630 | adapter->total_tx_packets = 0; |
| 1631 | adapter->total_rx_bytes = 0; |
| 1632 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1633 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | return IRQ_HANDLED; |
| 1637 | } |
| 1638 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1639 | static irqreturn_t e1000_msix_other(int irq, void *data) |
| 1640 | { |
| 1641 | struct net_device *netdev = data; |
| 1642 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1643 | struct e1000_hw *hw = &adapter->hw; |
| 1644 | u32 icr = er32(ICR); |
| 1645 | |
| 1646 | if (!(icr & E1000_ICR_INT_ASSERTED)) { |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1647 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1648 | ew32(IMS, E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1649 | return IRQ_NONE; |
| 1650 | } |
| 1651 | |
| 1652 | if (icr & adapter->eiac_mask) |
| 1653 | ew32(ICS, (icr & adapter->eiac_mask)); |
| 1654 | |
| 1655 | if (icr & E1000_ICR_OTHER) { |
| 1656 | if (!(icr & E1000_ICR_LSC)) |
| 1657 | goto no_link_interrupt; |
| 1658 | hw->mac.get_link_status = 1; |
| 1659 | /* guard against interrupt when we're going down */ |
| 1660 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1661 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1662 | } |
| 1663 | |
| 1664 | no_link_interrupt: |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1665 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1666 | ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1667 | |
| 1668 | return IRQ_HANDLED; |
| 1669 | } |
| 1670 | |
| 1671 | |
| 1672 | static irqreturn_t e1000_intr_msix_tx(int irq, void *data) |
| 1673 | { |
| 1674 | struct net_device *netdev = data; |
| 1675 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1676 | struct e1000_hw *hw = &adapter->hw; |
| 1677 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1678 | |
| 1679 | |
| 1680 | adapter->total_tx_bytes = 0; |
| 1681 | adapter->total_tx_packets = 0; |
| 1682 | |
| 1683 | if (!e1000_clean_tx_irq(adapter)) |
| 1684 | /* Ring was not completely cleaned, so fire another interrupt */ |
| 1685 | ew32(ICS, tx_ring->ims_val); |
| 1686 | |
| 1687 | return IRQ_HANDLED; |
| 1688 | } |
| 1689 | |
| 1690 | static irqreturn_t e1000_intr_msix_rx(int irq, void *data) |
| 1691 | { |
| 1692 | struct net_device *netdev = data; |
| 1693 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1694 | |
| 1695 | /* Write the ITR value calculated at the end of the |
| 1696 | * previous interrupt. |
| 1697 | */ |
| 1698 | if (adapter->rx_ring->set_itr) { |
| 1699 | writel(1000000000 / (adapter->rx_ring->itr_val * 256), |
| 1700 | adapter->hw.hw_addr + adapter->rx_ring->itr_register); |
| 1701 | adapter->rx_ring->set_itr = 0; |
| 1702 | } |
| 1703 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1704 | if (napi_schedule_prep(&adapter->napi)) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1705 | adapter->total_rx_bytes = 0; |
| 1706 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1707 | __napi_schedule(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1708 | } |
| 1709 | return IRQ_HANDLED; |
| 1710 | } |
| 1711 | |
| 1712 | /** |
| 1713 | * e1000_configure_msix - Configure MSI-X hardware |
| 1714 | * |
| 1715 | * e1000_configure_msix sets up the hardware to properly |
| 1716 | * generate MSI-X interrupts. |
| 1717 | **/ |
| 1718 | static void e1000_configure_msix(struct e1000_adapter *adapter) |
| 1719 | { |
| 1720 | struct e1000_hw *hw = &adapter->hw; |
| 1721 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1722 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1723 | int vector = 0; |
| 1724 | u32 ctrl_ext, ivar = 0; |
| 1725 | |
| 1726 | adapter->eiac_mask = 0; |
| 1727 | |
| 1728 | /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ |
| 1729 | if (hw->mac.type == e1000_82574) { |
| 1730 | u32 rfctl = er32(RFCTL); |
| 1731 | rfctl |= E1000_RFCTL_ACK_DIS; |
| 1732 | ew32(RFCTL, rfctl); |
| 1733 | } |
| 1734 | |
| 1735 | #define E1000_IVAR_INT_ALLOC_VALID 0x8 |
| 1736 | /* Configure Rx vector */ |
| 1737 | rx_ring->ims_val = E1000_IMS_RXQ0; |
| 1738 | adapter->eiac_mask |= rx_ring->ims_val; |
| 1739 | if (rx_ring->itr_val) |
| 1740 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1741 | hw->hw_addr + rx_ring->itr_register); |
| 1742 | else |
| 1743 | writel(1, hw->hw_addr + rx_ring->itr_register); |
| 1744 | ivar = E1000_IVAR_INT_ALLOC_VALID | vector; |
| 1745 | |
| 1746 | /* Configure Tx vector */ |
| 1747 | tx_ring->ims_val = E1000_IMS_TXQ0; |
| 1748 | vector++; |
| 1749 | if (tx_ring->itr_val) |
| 1750 | writel(1000000000 / (tx_ring->itr_val * 256), |
| 1751 | hw->hw_addr + tx_ring->itr_register); |
| 1752 | else |
| 1753 | writel(1, hw->hw_addr + tx_ring->itr_register); |
| 1754 | adapter->eiac_mask |= tx_ring->ims_val; |
| 1755 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); |
| 1756 | |
| 1757 | /* set vector for Other Causes, e.g. link changes */ |
| 1758 | vector++; |
| 1759 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); |
| 1760 | if (rx_ring->itr_val) |
| 1761 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1762 | hw->hw_addr + E1000_EITR_82574(vector)); |
| 1763 | else |
| 1764 | writel(1, hw->hw_addr + E1000_EITR_82574(vector)); |
| 1765 | |
| 1766 | /* Cause Tx interrupts on every write back */ |
| 1767 | ivar |= (1 << 31); |
| 1768 | |
| 1769 | ew32(IVAR, ivar); |
| 1770 | |
| 1771 | /* enable MSI-X PBA support */ |
| 1772 | ctrl_ext = er32(CTRL_EXT); |
| 1773 | ctrl_ext |= E1000_CTRL_EXT_PBA_CLR; |
| 1774 | |
| 1775 | /* Auto-Mask Other interrupts upon ICR read */ |
| 1776 | #define E1000_EIAC_MASK_82574 0x01F00000 |
| 1777 | ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER); |
| 1778 | ctrl_ext |= E1000_CTRL_EXT_EIAME; |
| 1779 | ew32(CTRL_EXT, ctrl_ext); |
| 1780 | e1e_flush(); |
| 1781 | } |
| 1782 | |
| 1783 | void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) |
| 1784 | { |
| 1785 | if (adapter->msix_entries) { |
| 1786 | pci_disable_msix(adapter->pdev); |
| 1787 | kfree(adapter->msix_entries); |
| 1788 | adapter->msix_entries = NULL; |
| 1789 | } else if (adapter->flags & FLAG_MSI_ENABLED) { |
| 1790 | pci_disable_msi(adapter->pdev); |
| 1791 | adapter->flags &= ~FLAG_MSI_ENABLED; |
| 1792 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | /** |
| 1796 | * e1000e_set_interrupt_capability - set MSI or MSI-X if supported |
| 1797 | * |
| 1798 | * Attempt to configure interrupts using the best available |
| 1799 | * capabilities of the hardware and kernel. |
| 1800 | **/ |
| 1801 | void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) |
| 1802 | { |
| 1803 | int err; |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1804 | int i; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1805 | |
| 1806 | switch (adapter->int_mode) { |
| 1807 | case E1000E_INT_MODE_MSIX: |
| 1808 | if (adapter->flags & FLAG_HAS_MSIX) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1809 | adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */ |
| 1810 | adapter->msix_entries = kcalloc(adapter->num_vectors, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1811 | sizeof(struct msix_entry), |
| 1812 | GFP_KERNEL); |
| 1813 | if (adapter->msix_entries) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1814 | for (i = 0; i < adapter->num_vectors; i++) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1815 | adapter->msix_entries[i].entry = i; |
| 1816 | |
| 1817 | err = pci_enable_msix(adapter->pdev, |
| 1818 | adapter->msix_entries, |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1819 | adapter->num_vectors); |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 1820 | if (err == 0) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1821 | return; |
| 1822 | } |
| 1823 | /* MSI-X failed, so fall through and try MSI */ |
| 1824 | e_err("Failed to initialize MSI-X interrupts. " |
| 1825 | "Falling back to MSI interrupts.\n"); |
| 1826 | e1000e_reset_interrupt_capability(adapter); |
| 1827 | } |
| 1828 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 1829 | /* Fall through */ |
| 1830 | case E1000E_INT_MODE_MSI: |
| 1831 | if (!pci_enable_msi(adapter->pdev)) { |
| 1832 | adapter->flags |= FLAG_MSI_ENABLED; |
| 1833 | } else { |
| 1834 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
| 1835 | e_err("Failed to initialize MSI interrupts. Falling " |
| 1836 | "back to legacy interrupts.\n"); |
| 1837 | } |
| 1838 | /* Fall through */ |
| 1839 | case E1000E_INT_MODE_LEGACY: |
| 1840 | /* Don't do anything; this is the system default */ |
| 1841 | break; |
| 1842 | } |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1843 | |
| 1844 | /* store the number of vectors being used */ |
| 1845 | adapter->num_vectors = 1; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | /** |
| 1849 | * e1000_request_msix - Initialize MSI-X interrupts |
| 1850 | * |
| 1851 | * e1000_request_msix allocates MSI-X vectors and requests interrupts from the |
| 1852 | * kernel. |
| 1853 | **/ |
| 1854 | static int e1000_request_msix(struct e1000_adapter *adapter) |
| 1855 | { |
| 1856 | struct net_device *netdev = adapter->netdev; |
| 1857 | int err = 0, vector = 0; |
| 1858 | |
| 1859 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 1860 | snprintf(adapter->rx_ring->name, |
| 1861 | sizeof(adapter->rx_ring->name) - 1, |
| 1862 | "%s-rx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1863 | else |
| 1864 | memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); |
| 1865 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1866 | e1000_intr_msix_rx, 0, adapter->rx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1867 | netdev); |
| 1868 | if (err) |
| 1869 | goto out; |
| 1870 | adapter->rx_ring->itr_register = E1000_EITR_82574(vector); |
| 1871 | adapter->rx_ring->itr_val = adapter->itr; |
| 1872 | vector++; |
| 1873 | |
| 1874 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 1875 | snprintf(adapter->tx_ring->name, |
| 1876 | sizeof(adapter->tx_ring->name) - 1, |
| 1877 | "%s-tx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1878 | else |
| 1879 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); |
| 1880 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1881 | e1000_intr_msix_tx, 0, adapter->tx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1882 | netdev); |
| 1883 | if (err) |
| 1884 | goto out; |
| 1885 | adapter->tx_ring->itr_register = E1000_EITR_82574(vector); |
| 1886 | adapter->tx_ring->itr_val = adapter->itr; |
| 1887 | vector++; |
| 1888 | |
| 1889 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1890 | e1000_msix_other, 0, netdev->name, netdev); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1891 | if (err) |
| 1892 | goto out; |
| 1893 | |
| 1894 | e1000_configure_msix(adapter); |
| 1895 | return 0; |
| 1896 | out: |
| 1897 | return err; |
| 1898 | } |
| 1899 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 1900 | /** |
| 1901 | * e1000_request_irq - initialize interrupts |
| 1902 | * |
| 1903 | * Attempts to configure interrupts using the best available |
| 1904 | * capabilities of the hardware and kernel. |
| 1905 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1906 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 1907 | { |
| 1908 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1909 | int err; |
| 1910 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1911 | if (adapter->msix_entries) { |
| 1912 | err = e1000_request_msix(adapter); |
| 1913 | if (!err) |
| 1914 | return err; |
| 1915 | /* fall back to MSI */ |
| 1916 | e1000e_reset_interrupt_capability(adapter); |
| 1917 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 1918 | e1000e_set_interrupt_capability(adapter); |
| 1919 | } |
| 1920 | if (adapter->flags & FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1921 | err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1922 | netdev->name, netdev); |
| 1923 | if (!err) |
| 1924 | return err; |
| 1925 | |
| 1926 | /* fall back to legacy interrupt */ |
| 1927 | e1000e_reset_interrupt_capability(adapter); |
| 1928 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1931 | err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1932 | netdev->name, netdev); |
| 1933 | if (err) |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 1934 | e_err("Unable to allocate interrupt, Error: %d\n", err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1935 | |
| 1936 | return err; |
| 1937 | } |
| 1938 | |
| 1939 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 1940 | { |
| 1941 | struct net_device *netdev = adapter->netdev; |
| 1942 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1943 | if (adapter->msix_entries) { |
| 1944 | int vector = 0; |
| 1945 | |
| 1946 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 1947 | vector++; |
| 1948 | |
| 1949 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 1950 | vector++; |
| 1951 | |
| 1952 | /* Other Causes interrupt vector */ |
| 1953 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 1954 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1955 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1956 | |
| 1957 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | /** |
| 1961 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 1962 | **/ |
| 1963 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
| 1964 | { |
| 1965 | struct e1000_hw *hw = &adapter->hw; |
| 1966 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1967 | ew32(IMC, ~0); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1968 | if (adapter->msix_entries) |
| 1969 | ew32(EIAC_82574, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1970 | e1e_flush(); |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1971 | |
| 1972 | if (adapter->msix_entries) { |
| 1973 | int i; |
| 1974 | for (i = 0; i < adapter->num_vectors; i++) |
| 1975 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1976 | } else { |
| 1977 | synchronize_irq(adapter->pdev->irq); |
| 1978 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | /** |
| 1982 | * e1000_irq_enable - Enable default interrupt generation settings |
| 1983 | **/ |
| 1984 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
| 1985 | { |
| 1986 | struct e1000_hw *hw = &adapter->hw; |
| 1987 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1988 | if (adapter->msix_entries) { |
| 1989 | ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); |
| 1990 | ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC); |
| 1991 | } else { |
| 1992 | ew32(IMS, IMS_ENABLE_MASK); |
| 1993 | } |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 1994 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 1998 | * 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] | 1999 | * @adapter: address of board private structure |
| 2000 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2001 | * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2002 | * For ASF and Pass Through versions of f/w this means that |
| 2003 | * the driver is loaded. For AMT version (only with 82573) |
| 2004 | * of the f/w this means that the network i/f is open. |
| 2005 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2006 | void e1000e_get_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2007 | { |
| 2008 | struct e1000_hw *hw = &adapter->hw; |
| 2009 | u32 ctrl_ext; |
| 2010 | u32 swsm; |
| 2011 | |
| 2012 | /* Let firmware know the driver has taken over */ |
| 2013 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2014 | swsm = er32(SWSM); |
| 2015 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
| 2016 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2017 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2018 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2019 | } |
| 2020 | } |
| 2021 | |
| 2022 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2023 | * 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] | 2024 | * @adapter: address of board private structure |
| 2025 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2026 | * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2027 | * For ASF and Pass Through versions of f/w this means that the |
| 2028 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 2029 | * of the f/w this means that the network i/f is closed. |
| 2030 | * |
| 2031 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2032 | void e1000e_release_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2033 | { |
| 2034 | struct e1000_hw *hw = &adapter->hw; |
| 2035 | u32 ctrl_ext; |
| 2036 | u32 swsm; |
| 2037 | |
| 2038 | /* Let firmware taken over control of h/w */ |
| 2039 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2040 | swsm = er32(SWSM); |
| 2041 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
| 2042 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2043 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2044 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2045 | } |
| 2046 | } |
| 2047 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2048 | /** |
| 2049 | * @e1000_alloc_ring - allocate memory for a ring structure |
| 2050 | **/ |
| 2051 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, |
| 2052 | struct e1000_ring *ring) |
| 2053 | { |
| 2054 | struct pci_dev *pdev = adapter->pdev; |
| 2055 | |
| 2056 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, |
| 2057 | GFP_KERNEL); |
| 2058 | if (!ring->desc) |
| 2059 | return -ENOMEM; |
| 2060 | |
| 2061 | return 0; |
| 2062 | } |
| 2063 | |
| 2064 | /** |
| 2065 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) |
| 2066 | * @adapter: board private structure |
| 2067 | * |
| 2068 | * Return 0 on success, negative on failure |
| 2069 | **/ |
| 2070 | int e1000e_setup_tx_resources(struct e1000_adapter *adapter) |
| 2071 | { |
| 2072 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2073 | int err = -ENOMEM, size; |
| 2074 | |
| 2075 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2076 | tx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2077 | if (!tx_ring->buffer_info) |
| 2078 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2079 | |
| 2080 | /* round up to nearest 4K */ |
| 2081 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
| 2082 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2083 | |
| 2084 | err = e1000_alloc_ring_dma(adapter, tx_ring); |
| 2085 | if (err) |
| 2086 | goto err; |
| 2087 | |
| 2088 | tx_ring->next_to_use = 0; |
| 2089 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2090 | |
| 2091 | return 0; |
| 2092 | err: |
| 2093 | vfree(tx_ring->buffer_info); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 2094 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2095 | return err; |
| 2096 | } |
| 2097 | |
| 2098 | /** |
| 2099 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) |
| 2100 | * @adapter: board private structure |
| 2101 | * |
| 2102 | * Returns 0 on success, negative on failure |
| 2103 | **/ |
| 2104 | int e1000e_setup_rx_resources(struct e1000_adapter *adapter) |
| 2105 | { |
| 2106 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2107 | struct e1000_buffer *buffer_info; |
| 2108 | int i, size, desc_len, err = -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2109 | |
| 2110 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2111 | rx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2112 | if (!rx_ring->buffer_info) |
| 2113 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2114 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2115 | for (i = 0; i < rx_ring->count; i++) { |
| 2116 | buffer_info = &rx_ring->buffer_info[i]; |
| 2117 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, |
| 2118 | sizeof(struct e1000_ps_page), |
| 2119 | GFP_KERNEL); |
| 2120 | if (!buffer_info->ps_pages) |
| 2121 | goto err_pages; |
| 2122 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2123 | |
| 2124 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 2125 | |
| 2126 | /* Round up to nearest 4K */ |
| 2127 | rx_ring->size = rx_ring->count * desc_len; |
| 2128 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2129 | |
| 2130 | err = e1000_alloc_ring_dma(adapter, rx_ring); |
| 2131 | if (err) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2132 | goto err_pages; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2133 | |
| 2134 | rx_ring->next_to_clean = 0; |
| 2135 | rx_ring->next_to_use = 0; |
| 2136 | rx_ring->rx_skb_top = NULL; |
| 2137 | |
| 2138 | return 0; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2139 | |
| 2140 | err_pages: |
| 2141 | for (i = 0; i < rx_ring->count; i++) { |
| 2142 | buffer_info = &rx_ring->buffer_info[i]; |
| 2143 | kfree(buffer_info->ps_pages); |
| 2144 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2145 | err: |
| 2146 | vfree(rx_ring->buffer_info); |
Bruce Allan | e926244 | 2010-11-24 06:02:06 +0000 | [diff] [blame] | 2147 | e_err("Unable to allocate memory for the receive descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2148 | return err; |
| 2149 | } |
| 2150 | |
| 2151 | /** |
| 2152 | * e1000_clean_tx_ring - Free Tx Buffers |
| 2153 | * @adapter: board private structure |
| 2154 | **/ |
| 2155 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter) |
| 2156 | { |
| 2157 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2158 | struct e1000_buffer *buffer_info; |
| 2159 | unsigned long size; |
| 2160 | unsigned int i; |
| 2161 | |
| 2162 | for (i = 0; i < tx_ring->count; i++) { |
| 2163 | buffer_info = &tx_ring->buffer_info[i]; |
| 2164 | e1000_put_txbuf(adapter, buffer_info); |
| 2165 | } |
| 2166 | |
| 2167 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2168 | memset(tx_ring->buffer_info, 0, size); |
| 2169 | |
| 2170 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2171 | |
| 2172 | tx_ring->next_to_use = 0; |
| 2173 | tx_ring->next_to_clean = 0; |
| 2174 | |
| 2175 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 2176 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
| 2177 | } |
| 2178 | |
| 2179 | /** |
| 2180 | * e1000e_free_tx_resources - Free Tx Resources per Queue |
| 2181 | * @adapter: board private structure |
| 2182 | * |
| 2183 | * Free all transmit software resources |
| 2184 | **/ |
| 2185 | void e1000e_free_tx_resources(struct e1000_adapter *adapter) |
| 2186 | { |
| 2187 | struct pci_dev *pdev = adapter->pdev; |
| 2188 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2189 | |
| 2190 | e1000_clean_tx_ring(adapter); |
| 2191 | |
| 2192 | vfree(tx_ring->buffer_info); |
| 2193 | tx_ring->buffer_info = NULL; |
| 2194 | |
| 2195 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 2196 | tx_ring->dma); |
| 2197 | tx_ring->desc = NULL; |
| 2198 | } |
| 2199 | |
| 2200 | /** |
| 2201 | * e1000e_free_rx_resources - Free Rx Resources |
| 2202 | * @adapter: board private structure |
| 2203 | * |
| 2204 | * Free all receive software resources |
| 2205 | **/ |
| 2206 | |
| 2207 | void e1000e_free_rx_resources(struct e1000_adapter *adapter) |
| 2208 | { |
| 2209 | struct pci_dev *pdev = adapter->pdev; |
| 2210 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2211 | int i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2212 | |
| 2213 | e1000_clean_rx_ring(adapter); |
| 2214 | |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2215 | for (i = 0; i < rx_ring->count; i++) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2216 | kfree(rx_ring->buffer_info[i].ps_pages); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2217 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2218 | vfree(rx_ring->buffer_info); |
| 2219 | rx_ring->buffer_info = NULL; |
| 2220 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2221 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 2222 | rx_ring->dma); |
| 2223 | rx_ring->desc = NULL; |
| 2224 | } |
| 2225 | |
| 2226 | /** |
| 2227 | * e1000_update_itr - update the dynamic ITR value based on statistics |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2228 | * @adapter: pointer to adapter |
| 2229 | * @itr_setting: current adapter->itr |
| 2230 | * @packets: the number of packets during this measurement interval |
| 2231 | * @bytes: the number of bytes during this measurement interval |
| 2232 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2233 | * Stores a new ITR value based on packets and byte |
| 2234 | * counts during the last interrupt. The advantage of per interrupt |
| 2235 | * computation is faster updates and more accurate ITR for the current |
| 2236 | * traffic pattern. Constants in this function were computed |
| 2237 | * based on theoretical maximum wire speed and thresholds were set based |
| 2238 | * on testing data as well as attempting to minimize response time |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2239 | * while increasing bulk throughput. This functionality is controlled |
| 2240 | * by the InterruptThrottleRate module parameter. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2241 | **/ |
| 2242 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
| 2243 | u16 itr_setting, int packets, |
| 2244 | int bytes) |
| 2245 | { |
| 2246 | unsigned int retval = itr_setting; |
| 2247 | |
| 2248 | if (packets == 0) |
| 2249 | goto update_itr_done; |
| 2250 | |
| 2251 | switch (itr_setting) { |
| 2252 | case lowest_latency: |
| 2253 | /* handle TSO and jumbo frames */ |
| 2254 | if (bytes/packets > 8000) |
| 2255 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2256 | else if ((packets < 5) && (bytes > 512)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2257 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2258 | break; |
| 2259 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2260 | if (bytes > 10000) { |
| 2261 | /* this if handles the TSO accounting */ |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2262 | if (bytes/packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2263 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2264 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2265 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2266 | else if ((packets > 35)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2267 | retval = lowest_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2268 | } else if (bytes/packets > 2000) { |
| 2269 | retval = bulk_latency; |
| 2270 | } else if (packets <= 2 && bytes < 512) { |
| 2271 | retval = lowest_latency; |
| 2272 | } |
| 2273 | break; |
| 2274 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2275 | if (bytes > 25000) { |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2276 | if (packets > 35) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2277 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2278 | } else if (bytes < 6000) { |
| 2279 | retval = low_latency; |
| 2280 | } |
| 2281 | break; |
| 2282 | } |
| 2283 | |
| 2284 | update_itr_done: |
| 2285 | return retval; |
| 2286 | } |
| 2287 | |
| 2288 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2289 | { |
| 2290 | struct e1000_hw *hw = &adapter->hw; |
| 2291 | u16 current_itr; |
| 2292 | u32 new_itr = adapter->itr; |
| 2293 | |
| 2294 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2295 | if (adapter->link_speed != SPEED_1000) { |
| 2296 | current_itr = 0; |
| 2297 | new_itr = 4000; |
| 2298 | goto set_itr_now; |
| 2299 | } |
| 2300 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2301 | if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 2302 | new_itr = 0; |
| 2303 | goto set_itr_now; |
| 2304 | } |
| 2305 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2306 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2307 | adapter->tx_itr, |
| 2308 | adapter->total_tx_packets, |
| 2309 | adapter->total_tx_bytes); |
| 2310 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2311 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2312 | adapter->tx_itr = low_latency; |
| 2313 | |
| 2314 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2315 | adapter->rx_itr, |
| 2316 | adapter->total_rx_packets, |
| 2317 | adapter->total_rx_bytes); |
| 2318 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2319 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2320 | adapter->rx_itr = low_latency; |
| 2321 | |
| 2322 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2323 | |
| 2324 | switch (current_itr) { |
| 2325 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2326 | case lowest_latency: |
| 2327 | new_itr = 70000; |
| 2328 | break; |
| 2329 | case low_latency: |
| 2330 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2331 | break; |
| 2332 | case bulk_latency: |
| 2333 | new_itr = 4000; |
| 2334 | break; |
| 2335 | default: |
| 2336 | break; |
| 2337 | } |
| 2338 | |
| 2339 | set_itr_now: |
| 2340 | if (new_itr != adapter->itr) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2341 | /* |
| 2342 | * this attempts to bias the interrupt rate towards Bulk |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2343 | * by adding intermediate steps when interrupt rate is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2344 | * increasing |
| 2345 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2346 | new_itr = new_itr > adapter->itr ? |
| 2347 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2348 | new_itr; |
| 2349 | adapter->itr = new_itr; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2350 | adapter->rx_ring->itr_val = new_itr; |
| 2351 | if (adapter->msix_entries) |
| 2352 | adapter->rx_ring->set_itr = 1; |
| 2353 | else |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2354 | if (new_itr) |
| 2355 | ew32(ITR, 1000000000 / (new_itr * 256)); |
| 2356 | else |
| 2357 | ew32(ITR, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | /** |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2362 | * e1000_alloc_queues - Allocate memory for all rings |
| 2363 | * @adapter: board private structure to initialize |
| 2364 | **/ |
| 2365 | static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) |
| 2366 | { |
| 2367 | adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
| 2368 | if (!adapter->tx_ring) |
| 2369 | goto err; |
| 2370 | |
| 2371 | adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
| 2372 | if (!adapter->rx_ring) |
| 2373 | goto err; |
| 2374 | |
| 2375 | return 0; |
| 2376 | err: |
| 2377 | e_err("Unable to allocate memory for queues\n"); |
| 2378 | kfree(adapter->rx_ring); |
| 2379 | kfree(adapter->tx_ring); |
| 2380 | return -ENOMEM; |
| 2381 | } |
| 2382 | |
| 2383 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2384 | * e1000_clean - NAPI Rx polling callback |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2385 | * @napi: struct associated with this polling callback |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2386 | * @budget: amount of packets driver is allowed to process this poll |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2387 | **/ |
| 2388 | static int e1000_clean(struct napi_struct *napi, int budget) |
| 2389 | { |
| 2390 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2391 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2392 | struct net_device *poll_dev = adapter->netdev; |
Andy Gospodarek | 679e8a0 | 2009-06-18 11:57:37 +0000 | [diff] [blame] | 2393 | int tx_cleaned = 1, work_done = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2394 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 2395 | adapter = netdev_priv(poll_dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2396 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2397 | if (adapter->msix_entries && |
| 2398 | !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) |
| 2399 | goto clean_rx; |
| 2400 | |
Jesse Brandeburg | 92af3e9 | 2009-01-19 14:17:08 +0000 | [diff] [blame] | 2401 | tx_cleaned = e1000_clean_tx_irq(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2402 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2403 | clean_rx: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2404 | adapter->clean_rx(adapter, &work_done, budget); |
| 2405 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 2406 | if (!tx_cleaned) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2407 | work_done = budget; |
| 2408 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 2409 | /* If budget not fully consumed, exit the polling mode */ |
| 2410 | if (work_done < budget) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2411 | if (adapter->itr_setting & 3) |
| 2412 | e1000_set_itr(adapter); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2413 | napi_complete(napi); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 2414 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 2415 | if (adapter->msix_entries) |
| 2416 | ew32(IMS, adapter->rx_ring->ims_val); |
| 2417 | else |
| 2418 | e1000_irq_enable(adapter); |
| 2419 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | return work_done; |
| 2423 | } |
| 2424 | |
| 2425 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2426 | { |
| 2427 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2428 | struct e1000_hw *hw = &adapter->hw; |
| 2429 | u32 vfta, index; |
| 2430 | |
| 2431 | /* don't update vlan cookie if already programmed */ |
| 2432 | if ((adapter->hw.mng_cookie.status & |
| 2433 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2434 | (vid == adapter->mng_vlan_id)) |
| 2435 | return; |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2436 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2437 | /* add VID to filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2438 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2439 | index = (vid >> 5) & 0x7F; |
| 2440 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2441 | vfta |= (1 << (vid & 0x1F)); |
| 2442 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2443 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2444 | |
| 2445 | set_bit(vid, adapter->active_vlans); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2449 | { |
| 2450 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2451 | struct e1000_hw *hw = &adapter->hw; |
| 2452 | u32 vfta, index; |
| 2453 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2454 | if ((adapter->hw.mng_cookie.status & |
| 2455 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2456 | (vid == adapter->mng_vlan_id)) { |
| 2457 | /* release control to f/w */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2458 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2459 | return; |
| 2460 | } |
| 2461 | |
| 2462 | /* remove VID from filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2463 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2464 | index = (vid >> 5) & 0x7F; |
| 2465 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2466 | vfta &= ~(1 << (vid & 0x1F)); |
| 2467 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2468 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2469 | |
| 2470 | clear_bit(vid, adapter->active_vlans); |
| 2471 | } |
| 2472 | |
| 2473 | /** |
| 2474 | * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering |
| 2475 | * @adapter: board private structure to initialize |
| 2476 | **/ |
| 2477 | static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter) |
| 2478 | { |
| 2479 | struct net_device *netdev = adapter->netdev; |
| 2480 | struct e1000_hw *hw = &adapter->hw; |
| 2481 | u32 rctl; |
| 2482 | |
| 2483 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2484 | /* disable VLAN receive filtering */ |
| 2485 | rctl = er32(RCTL); |
| 2486 | rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN); |
| 2487 | ew32(RCTL, rctl); |
| 2488 | |
| 2489 | if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { |
| 2490 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 2491 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 2492 | } |
| 2493 | } |
| 2494 | } |
| 2495 | |
| 2496 | /** |
| 2497 | * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering |
| 2498 | * @adapter: board private structure to initialize |
| 2499 | **/ |
| 2500 | static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter) |
| 2501 | { |
| 2502 | struct e1000_hw *hw = &adapter->hw; |
| 2503 | u32 rctl; |
| 2504 | |
| 2505 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2506 | /* enable VLAN receive filtering */ |
| 2507 | rctl = er32(RCTL); |
| 2508 | rctl |= E1000_RCTL_VFE; |
| 2509 | rctl &= ~E1000_RCTL_CFIEN; |
| 2510 | ew32(RCTL, rctl); |
| 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | /** |
| 2515 | * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping |
| 2516 | * @adapter: board private structure to initialize |
| 2517 | **/ |
| 2518 | static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter) |
| 2519 | { |
| 2520 | struct e1000_hw *hw = &adapter->hw; |
| 2521 | u32 ctrl; |
| 2522 | |
| 2523 | /* disable VLAN tag insert/strip */ |
| 2524 | ctrl = er32(CTRL); |
| 2525 | ctrl &= ~E1000_CTRL_VME; |
| 2526 | ew32(CTRL, ctrl); |
| 2527 | } |
| 2528 | |
| 2529 | /** |
| 2530 | * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping |
| 2531 | * @adapter: board private structure to initialize |
| 2532 | **/ |
| 2533 | static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter) |
| 2534 | { |
| 2535 | struct e1000_hw *hw = &adapter->hw; |
| 2536 | u32 ctrl; |
| 2537 | |
| 2538 | /* enable VLAN tag insert/strip */ |
| 2539 | ctrl = er32(CTRL); |
| 2540 | ctrl |= E1000_CTRL_VME; |
| 2541 | ew32(CTRL, ctrl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 2545 | { |
| 2546 | struct net_device *netdev = adapter->netdev; |
| 2547 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 2548 | u16 old_vid = adapter->mng_vlan_id; |
| 2549 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2550 | if (adapter->hw.mng_cookie.status & |
| 2551 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
| 2552 | e1000_vlan_rx_add_vid(netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2553 | adapter->mng_vlan_id = vid; |
| 2554 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2555 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2556 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid)) |
| 2557 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
| 2561 | { |
| 2562 | u16 vid; |
| 2563 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2564 | e1000_vlan_rx_add_vid(adapter->netdev, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2565 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2566 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2567 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2570 | static void e1000_init_manageability_pt(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2571 | { |
| 2572 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2573 | u32 manc, manc2h, mdef, i, j; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2574 | |
| 2575 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) |
| 2576 | return; |
| 2577 | |
| 2578 | manc = er32(MANC); |
| 2579 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2580 | /* |
| 2581 | * enable receiving management packets to the host. this will probably |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2582 | * generate destination unreachable messages from the host OS, but |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2583 | * the packets will be handled on SMBUS |
| 2584 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2585 | manc |= E1000_MANC_EN_MNG2HOST; |
| 2586 | manc2h = er32(MANC2H); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2587 | |
| 2588 | switch (hw->mac.type) { |
| 2589 | default: |
| 2590 | manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664); |
| 2591 | break; |
| 2592 | case e1000_82574: |
| 2593 | case e1000_82583: |
| 2594 | /* |
| 2595 | * Check if IPMI pass-through decision filter already exists; |
| 2596 | * if so, enable it. |
| 2597 | */ |
| 2598 | for (i = 0, j = 0; i < 8; i++) { |
| 2599 | mdef = er32(MDEF(i)); |
| 2600 | |
| 2601 | /* Ignore filters with anything other than IPMI ports */ |
Dan Carpenter | 3b21b50 | 2010-06-02 13:43:15 +0000 | [diff] [blame] | 2602 | if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2603 | continue; |
| 2604 | |
| 2605 | /* Enable this decision filter in MANC2H */ |
| 2606 | if (mdef) |
| 2607 | manc2h |= (1 << i); |
| 2608 | |
| 2609 | j |= mdef; |
| 2610 | } |
| 2611 | |
| 2612 | if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
| 2613 | break; |
| 2614 | |
| 2615 | /* Create new decision filter in an empty filter */ |
| 2616 | for (i = 0, j = 0; i < 8; i++) |
| 2617 | if (er32(MDEF(i)) == 0) { |
| 2618 | ew32(MDEF(i), (E1000_MDEF_PORT_623 | |
| 2619 | E1000_MDEF_PORT_664)); |
| 2620 | manc2h |= (1 << 1); |
| 2621 | j++; |
| 2622 | break; |
| 2623 | } |
| 2624 | |
| 2625 | if (!j) |
| 2626 | e_warn("Unable to create IPMI pass-through filter\n"); |
| 2627 | break; |
| 2628 | } |
| 2629 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2630 | ew32(MANC2H, manc2h); |
| 2631 | ew32(MANC, manc); |
| 2632 | } |
| 2633 | |
| 2634 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2635 | * e1000_configure_tx - Configure Transmit Unit after Reset |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2636 | * @adapter: board private structure |
| 2637 | * |
| 2638 | * Configure the Tx unit of the MAC after a reset. |
| 2639 | **/ |
| 2640 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
| 2641 | { |
| 2642 | struct e1000_hw *hw = &adapter->hw; |
| 2643 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2644 | u64 tdba; |
| 2645 | u32 tdlen, tctl, tipg, tarc; |
| 2646 | u32 ipgr1, ipgr2; |
| 2647 | |
| 2648 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 2649 | tdba = tx_ring->dma; |
| 2650 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2651 | ew32(TDBAL, (tdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2652 | ew32(TDBAH, (tdba >> 32)); |
| 2653 | ew32(TDLEN, tdlen); |
| 2654 | ew32(TDH, 0); |
| 2655 | ew32(TDT, 0); |
| 2656 | tx_ring->head = E1000_TDH; |
| 2657 | tx_ring->tail = E1000_TDT; |
| 2658 | |
| 2659 | /* Set the default values for the Tx Inter Packet Gap timer */ |
| 2660 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */ |
| 2661 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */ |
| 2662 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */ |
| 2663 | |
| 2664 | if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN) |
| 2665 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */ |
| 2666 | |
| 2667 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 2668 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
| 2669 | ew32(TIPG, tipg); |
| 2670 | |
| 2671 | /* Set the Tx Interrupt Delay register */ |
| 2672 | ew32(TIDV, adapter->tx_int_delay); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2673 | /* Tx irq moderation */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2674 | ew32(TADV, adapter->tx_abs_int_delay); |
| 2675 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2676 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 2677 | u32 txdctl = er32(TXDCTL(0)); |
| 2678 | txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH | |
| 2679 | E1000_TXDCTL_WTHRESH); |
| 2680 | /* |
| 2681 | * set up some performance related parameters to encourage the |
| 2682 | * hardware to use the bus more efficiently in bursts, depends |
| 2683 | * on the tx_int_delay to be enabled, |
| 2684 | * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time |
| 2685 | * hthresh = 1 ==> prefetch when one or more available |
| 2686 | * pthresh = 0x1f ==> prefetch if internal cache 31 or less |
| 2687 | * BEWARE: this seems to work but should be considered first if |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2688 | * there are Tx hangs or other Tx related bugs |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2689 | */ |
| 2690 | txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE; |
| 2691 | ew32(TXDCTL(0), txdctl); |
| 2692 | /* erratum work around: set txdctl the same for both queues */ |
| 2693 | ew32(TXDCTL(1), txdctl); |
| 2694 | } |
| 2695 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2696 | /* Program the Transmit Control Register */ |
| 2697 | tctl = er32(TCTL); |
| 2698 | tctl &= ~E1000_TCTL_CT; |
| 2699 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
| 2700 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 2701 | |
| 2702 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2703 | tarc = er32(TARC(0)); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2704 | /* |
| 2705 | * set the speed mode bit, we'll clear it if we're not at |
| 2706 | * gigabit link later |
| 2707 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2708 | #define SPEED_MODE_BIT (1 << 21) |
| 2709 | tarc |= SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2710 | ew32(TARC(0), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2711 | } |
| 2712 | |
| 2713 | /* errata: program both queues to unweighted RR */ |
| 2714 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2715 | tarc = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2716 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2717 | ew32(TARC(0), tarc); |
| 2718 | tarc = er32(TARC(1)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2719 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2720 | ew32(TARC(1), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2723 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 2724 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 2725 | |
| 2726 | /* only set IDE if we are delaying interrupts using the timers */ |
| 2727 | if (adapter->tx_int_delay) |
| 2728 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
| 2729 | |
| 2730 | /* enable Report Status bit */ |
| 2731 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 2732 | |
| 2733 | ew32(TCTL, tctl); |
| 2734 | |
Simon Horman | edfea6e6 | 2009-06-08 14:28:36 +0000 | [diff] [blame] | 2735 | e1000e_config_collision_dist(hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | /** |
| 2739 | * e1000_setup_rctl - configure the receive control registers |
| 2740 | * @adapter: Board private structure |
| 2741 | **/ |
| 2742 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 2743 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
| 2744 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
| 2745 | { |
| 2746 | struct e1000_hw *hw = &adapter->hw; |
| 2747 | u32 rctl, rfctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2748 | u32 pages = 0; |
| 2749 | |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 2750 | /* Workaround Si errata on 82579 - configure jumbo frame flow */ |
| 2751 | if (hw->mac.type == e1000_pch2lan) { |
| 2752 | s32 ret_val; |
| 2753 | |
| 2754 | if (adapter->netdev->mtu > ETH_DATA_LEN) |
| 2755 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true); |
| 2756 | else |
| 2757 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false); |
Bruce Allan | dd93f95 | 2011-01-06 14:29:48 +0000 | [diff] [blame] | 2758 | |
| 2759 | if (ret_val) |
| 2760 | e_dbg("failed to enable jumbo frame workaround mode\n"); |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2763 | /* Program MC offset vector base */ |
| 2764 | rctl = er32(RCTL); |
| 2765 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 2766 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 2767 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 2768 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 2769 | |
| 2770 | /* Do not Store bad packets */ |
| 2771 | rctl &= ~E1000_RCTL_SBP; |
| 2772 | |
| 2773 | /* Enable Long Packet receive */ |
| 2774 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2775 | rctl &= ~E1000_RCTL_LPE; |
| 2776 | else |
| 2777 | rctl |= E1000_RCTL_LPE; |
| 2778 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 2779 | /* Some systems expect that the CRC is included in SMBUS traffic. The |
| 2780 | * hardware strips the CRC before sending to both SMBUS (BMC) and to |
| 2781 | * host memory when this is enabled |
| 2782 | */ |
| 2783 | if (adapter->flags2 & FLAG2_CRC_STRIPPING) |
| 2784 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 5918bd8 | 2008-02-12 15:20:24 -0800 | [diff] [blame] | 2785 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 2786 | /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ |
| 2787 | if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { |
| 2788 | u16 phy_data; |
| 2789 | |
| 2790 | e1e_rphy(hw, PHY_REG(770, 26), &phy_data); |
| 2791 | phy_data &= 0xfff8; |
| 2792 | phy_data |= (1 << 2); |
| 2793 | e1e_wphy(hw, PHY_REG(770, 26), phy_data); |
| 2794 | |
| 2795 | e1e_rphy(hw, 22, &phy_data); |
| 2796 | phy_data &= 0x0fff; |
| 2797 | phy_data |= (1 << 14); |
| 2798 | e1e_wphy(hw, 0x10, 0x2823); |
| 2799 | e1e_wphy(hw, 0x11, 0x0003); |
| 2800 | e1e_wphy(hw, 22, phy_data); |
| 2801 | } |
| 2802 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2803 | /* Setup buffer sizes */ |
| 2804 | rctl &= ~E1000_RCTL_SZ_4096; |
| 2805 | rctl |= E1000_RCTL_BSEX; |
| 2806 | switch (adapter->rx_buffer_len) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2807 | case 2048: |
| 2808 | default: |
| 2809 | rctl |= E1000_RCTL_SZ_2048; |
| 2810 | rctl &= ~E1000_RCTL_BSEX; |
| 2811 | break; |
| 2812 | case 4096: |
| 2813 | rctl |= E1000_RCTL_SZ_4096; |
| 2814 | break; |
| 2815 | case 8192: |
| 2816 | rctl |= E1000_RCTL_SZ_8192; |
| 2817 | break; |
| 2818 | case 16384: |
| 2819 | rctl |= E1000_RCTL_SZ_16384; |
| 2820 | break; |
| 2821 | } |
| 2822 | |
| 2823 | /* |
| 2824 | * 82571 and greater support packet-split where the protocol |
| 2825 | * header is placed in skb->data and the packet data is |
| 2826 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 2827 | * In the case of a non-split, skb->data is linearly filled, |
| 2828 | * followed by the page buffers. Therefore, skb->data is |
| 2829 | * sized to hold the largest protocol header. |
| 2830 | * |
| 2831 | * allocations using alloc_page take too long for regular MTU |
| 2832 | * so only enable packet split for jumbo frames |
| 2833 | * |
| 2834 | * Using pages when the page size is greater than 16k wastes |
| 2835 | * a lot of memory, since we allocate 3 pages at all times |
| 2836 | * per packet. |
| 2837 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2838 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Bruce Allan | dbcb9fe | 2010-06-17 18:59:27 +0000 | [diff] [blame] | 2839 | if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) && |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2840 | (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2841 | adapter->rx_ps_pages = pages; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2842 | else |
| 2843 | adapter->rx_ps_pages = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2844 | |
| 2845 | if (adapter->rx_ps_pages) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 2846 | u32 psrctl = 0; |
| 2847 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2848 | /* Configure extra packet-split registers */ |
| 2849 | rfctl = er32(RFCTL); |
| 2850 | rfctl |= E1000_RFCTL_EXTEN; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2851 | /* |
| 2852 | * disable packet split support for IPv6 extension headers, |
| 2853 | * because some malformed IPv6 headers can hang the Rx |
| 2854 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2855 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
| 2856 | E1000_RFCTL_NEW_IPV6_EXT_DIS); |
| 2857 | |
| 2858 | ew32(RFCTL, rfctl); |
| 2859 | |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 2860 | /* Enable Packet split descriptors */ |
| 2861 | rctl |= E1000_RCTL_DTYP_PS; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2862 | |
| 2863 | psrctl |= adapter->rx_ps_bsize0 >> |
| 2864 | E1000_PSRCTL_BSIZE0_SHIFT; |
| 2865 | |
| 2866 | switch (adapter->rx_ps_pages) { |
| 2867 | case 3: |
| 2868 | psrctl |= PAGE_SIZE << |
| 2869 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 2870 | case 2: |
| 2871 | psrctl |= PAGE_SIZE << |
| 2872 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 2873 | case 1: |
| 2874 | psrctl |= PAGE_SIZE >> |
| 2875 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 2876 | break; |
| 2877 | } |
| 2878 | |
| 2879 | ew32(PSRCTL, psrctl); |
| 2880 | } |
| 2881 | |
| 2882 | ew32(RCTL, rctl); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2883 | /* just started the receive unit, no need to restart */ |
| 2884 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | /** |
| 2888 | * e1000_configure_rx - Configure Receive Unit after Reset |
| 2889 | * @adapter: board private structure |
| 2890 | * |
| 2891 | * Configure the Rx unit of the MAC after a reset. |
| 2892 | **/ |
| 2893 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
| 2894 | { |
| 2895 | struct e1000_hw *hw = &adapter->hw; |
| 2896 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 2897 | u64 rdba; |
| 2898 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
| 2899 | |
| 2900 | if (adapter->rx_ps_pages) { |
| 2901 | /* this is a 32 byte descriptor */ |
| 2902 | rdlen = rx_ring->count * |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2903 | sizeof(union e1000_rx_desc_packet_split); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2904 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 2905 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2906 | } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { |
| 2907 | rdlen = rx_ring->count * sizeof(struct e1000_rx_desc); |
| 2908 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 2909 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2910 | } else { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2911 | rdlen = rx_ring->count * sizeof(struct e1000_rx_desc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2912 | adapter->clean_rx = e1000_clean_rx_irq; |
| 2913 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 2914 | } |
| 2915 | |
| 2916 | /* disable receives while setting up the descriptors */ |
| 2917 | rctl = er32(RCTL); |
| 2918 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 2919 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 2920 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2921 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2922 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 2923 | /* |
| 2924 | * set the writeback threshold (only takes effect if the RDTR |
| 2925 | * 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] | 2926 | * enable prefetching of 0x20 Rx descriptors |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2927 | * granularity = 01 |
| 2928 | * wthresh = 04, |
| 2929 | * hthresh = 04, |
| 2930 | * pthresh = 0x20 |
| 2931 | */ |
| 2932 | ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 2933 | ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 2934 | |
| 2935 | /* |
| 2936 | * override the delay timers for enabling bursting, only if |
| 2937 | * the value was not set by the user via module options |
| 2938 | */ |
| 2939 | if (adapter->rx_int_delay == DEFAULT_RDTR) |
| 2940 | adapter->rx_int_delay = BURST_RDTR; |
| 2941 | if (adapter->rx_abs_int_delay == DEFAULT_RADV) |
| 2942 | adapter->rx_abs_int_delay = BURST_RADV; |
| 2943 | } |
| 2944 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2945 | /* set the Receive Delay Timer Register */ |
| 2946 | ew32(RDTR, adapter->rx_int_delay); |
| 2947 | |
| 2948 | /* irq moderation */ |
| 2949 | ew32(RADV, adapter->rx_abs_int_delay); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2950 | if ((adapter->itr_setting != 0) && (adapter->itr != 0)) |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2951 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2952 | |
| 2953 | ctrl_ext = er32(CTRL_EXT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2954 | /* Auto-Mask interrupts upon ICR access */ |
| 2955 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 2956 | ew32(IAM, 0xffffffff); |
| 2957 | ew32(CTRL_EXT, ctrl_ext); |
| 2958 | e1e_flush(); |
| 2959 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2960 | /* |
| 2961 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2962 | * the Base and Length of the Rx Descriptor Ring |
| 2963 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2964 | rdba = rx_ring->dma; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2965 | ew32(RDBAL, (rdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2966 | ew32(RDBAH, (rdba >> 32)); |
| 2967 | ew32(RDLEN, rdlen); |
| 2968 | ew32(RDH, 0); |
| 2969 | ew32(RDT, 0); |
| 2970 | rx_ring->head = E1000_RDH; |
| 2971 | rx_ring->tail = E1000_RDT; |
| 2972 | |
| 2973 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 2974 | rxcsum = er32(RXCSUM); |
| 2975 | if (adapter->flags & FLAG_RX_CSUM_ENABLED) { |
| 2976 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 2977 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2978 | /* |
| 2979 | * IPv4 payload checksum for UDP fragments must be |
| 2980 | * used in conjunction with packet-split. |
| 2981 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2982 | if (adapter->rx_ps_pages) |
| 2983 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 2984 | } else { |
| 2985 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 2986 | /* no need to clear IPPCSE as it defaults to 0 */ |
| 2987 | } |
| 2988 | ew32(RXCSUM, rxcsum); |
| 2989 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2990 | /* |
| 2991 | * Enable early receives on supported devices, only takes effect when |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2992 | * 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] | 2993 | * units), e.g. using jumbo frames when setting to E1000_ERT_2048 |
| 2994 | */ |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2995 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 2996 | (adapter->hw.mac.type == e1000_pch2lan)) { |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 2997 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 2998 | u32 rxdctl = er32(RXDCTL(0)); |
| 2999 | ew32(RXDCTL(0), rxdctl | 0x3); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3000 | if (adapter->flags & FLAG_HAS_ERT) |
| 3001 | ew32(ERT, E1000_ERT_2048 | (1 << 13)); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3002 | /* |
| 3003 | * With jumbo frames and early-receive enabled, |
| 3004 | * excessive C-state transition latencies result in |
| 3005 | * dropped transactions. |
| 3006 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3007 | pm_qos_update_request(&adapter->netdev->pm_qos_req, 55); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3008 | } else { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3009 | pm_qos_update_request(&adapter->netdev->pm_qos_req, |
| 3010 | PM_QOS_DEFAULT_VALUE); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3011 | } |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3012 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3013 | |
| 3014 | /* Enable Receives */ |
| 3015 | ew32(RCTL, rctl); |
| 3016 | } |
| 3017 | |
| 3018 | /** |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 3019 | * e1000_update_mc_addr_list - Update Multicast addresses |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3020 | * @hw: pointer to the HW structure |
| 3021 | * @mc_addr_list: array of multicast addresses to program |
| 3022 | * @mc_addr_count: number of multicast addresses to program |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3023 | * |
Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 3024 | * Updates the Multicast Table Array. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3025 | * The caller must have a packed mc_addr_list of multicast addresses. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3026 | **/ |
Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 3027 | 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] | 3028 | u32 mc_addr_count) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3029 | { |
Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 3030 | 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] | 3031 | } |
| 3032 | |
| 3033 | /** |
| 3034 | * e1000_set_multi - Multicast and Promiscuous mode set |
| 3035 | * @netdev: network interface device structure |
| 3036 | * |
| 3037 | * The set_multi entry point is called whenever the multicast address |
| 3038 | * list or the network interface flags are updated. This routine is |
| 3039 | * responsible for configuring the hardware for proper multicast, |
| 3040 | * promiscuous mode, and all-multi behavior. |
| 3041 | **/ |
| 3042 | static void e1000_set_multi(struct net_device *netdev) |
| 3043 | { |
| 3044 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3045 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3046 | struct netdev_hw_addr *ha; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3047 | u8 *mta_list; |
| 3048 | u32 rctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3049 | |
| 3050 | /* Check for Promiscuous and All Multicast modes */ |
| 3051 | |
| 3052 | rctl = er32(RCTL); |
| 3053 | |
| 3054 | if (netdev->flags & IFF_PROMISC) { |
| 3055 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3056 | rctl &= ~E1000_RCTL_VFE; |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3057 | /* Do not hardware filter VLANs in promisc mode */ |
| 3058 | e1000e_vlan_filter_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3059 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3060 | if (netdev->flags & IFF_ALLMULTI) { |
| 3061 | rctl |= E1000_RCTL_MPE; |
| 3062 | rctl &= ~E1000_RCTL_UPE; |
| 3063 | } else { |
| 3064 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 3065 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3066 | e1000e_vlan_filter_enable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | ew32(RCTL, rctl); |
| 3070 | |
Jiri Pirko | 7aeef97 | 2010-02-05 02:52:39 +0000 | [diff] [blame] | 3071 | if (!netdev_mc_empty(netdev)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 3072 | int i = 0; |
| 3073 | |
Jiri Pirko | 7aeef97 | 2010-02-05 02:52:39 +0000 | [diff] [blame] | 3074 | mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3075 | if (!mta_list) |
| 3076 | return; |
| 3077 | |
| 3078 | /* prepare a packed array of only addresses. */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3079 | netdev_for_each_mc_addr(ha, netdev) |
| 3080 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3081 | |
Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 3082 | e1000_update_mc_addr_list(hw, mta_list, i); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3083 | kfree(mta_list); |
| 3084 | } else { |
| 3085 | /* |
| 3086 | * if we're called from probe, we might not have |
| 3087 | * anything to do here, so clear out the list |
| 3088 | */ |
Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 3089 | e1000_update_mc_addr_list(hw, NULL, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3090 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3091 | |
| 3092 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3093 | e1000e_vlan_strip_enable(adapter); |
| 3094 | else |
| 3095 | e1000e_vlan_strip_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3099 | * e1000_configure - configure the hardware for Rx and Tx |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3100 | * @adapter: private board structure |
| 3101 | **/ |
| 3102 | static void e1000_configure(struct e1000_adapter *adapter) |
| 3103 | { |
| 3104 | e1000_set_multi(adapter->netdev); |
| 3105 | |
| 3106 | e1000_restore_vlan(adapter); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 3107 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3108 | |
| 3109 | e1000_configure_tx(adapter); |
| 3110 | e1000_setup_rctl(adapter); |
| 3111 | e1000_configure_rx(adapter); |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame^] | 3112 | adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring), |
| 3113 | GFP_KERNEL); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | /** |
| 3117 | * e1000e_power_up_phy - restore link in case the phy was powered down |
| 3118 | * @adapter: address of board private structure |
| 3119 | * |
| 3120 | * The phy may be powered down to save power and turn off link when the |
| 3121 | * driver is unloaded and wake on lan is not enabled (among others) |
| 3122 | * *** this routine MUST be followed by a call to e1000e_reset *** |
| 3123 | **/ |
| 3124 | void e1000e_power_up_phy(struct e1000_adapter *adapter) |
| 3125 | { |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3126 | if (adapter->hw.phy.ops.power_up) |
| 3127 | adapter->hw.phy.ops.power_up(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3128 | |
| 3129 | adapter->hw.mac.ops.setup_link(&adapter->hw); |
| 3130 | } |
| 3131 | |
| 3132 | /** |
| 3133 | * e1000_power_down_phy - Power down the PHY |
| 3134 | * |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3135 | * Power down the PHY so no link is implied when interface is down. |
| 3136 | * The PHY cannot be powered down if management or WoL is active. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3137 | */ |
| 3138 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 3139 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3140 | /* WoL is enabled */ |
Auke Kok | 23b66e2 | 2008-02-11 09:25:51 -0800 | [diff] [blame] | 3141 | if (adapter->wol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3142 | return; |
| 3143 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3144 | if (adapter->hw.phy.ops.power_down) |
| 3145 | adapter->hw.phy.ops.power_down(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | /** |
| 3149 | * e1000e_reset - bring the hardware into a known good state |
| 3150 | * |
| 3151 | * This function boots the hardware and enables some settings that |
| 3152 | * require a configuration cycle of the hardware - those cannot be |
| 3153 | * set/changed during runtime. After reset the device needs to be |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3154 | * properly configured for Rx, Tx etc. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3155 | */ |
| 3156 | void e1000e_reset(struct e1000_adapter *adapter) |
| 3157 | { |
| 3158 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3159 | struct e1000_fc_info *fc = &adapter->hw.fc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3160 | struct e1000_hw *hw = &adapter->hw; |
| 3161 | u32 tx_space, min_tx_space, min_rx_space; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3162 | u32 pba = adapter->pba; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3163 | u16 hwm; |
| 3164 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3165 | /* reset Packet Buffer Allocation to default */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3166 | ew32(PBA, pba); |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3167 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3168 | if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3169 | /* |
| 3170 | * To maintain wire speed transmits, the Tx FIFO should be |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3171 | * large enough to accommodate two full transmit packets, |
| 3172 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 3173 | * the Rx FIFO should be large enough to accommodate at least |
| 3174 | * one full receive packet and is similarly rounded up and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3175 | * expressed in KB. |
| 3176 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3177 | pba = er32(PBA); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3178 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3179 | tx_space = pba >> 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3180 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3181 | pba &= 0xffff; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3182 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3183 | * the Tx fifo also stores 16 bytes of information about the Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3184 | * but don't include ethernet FCS because hardware appends it |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3185 | */ |
| 3186 | min_tx_space = (adapter->max_frame_size + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3187 | sizeof(struct e1000_tx_desc) - |
| 3188 | ETH_FCS_LEN) * 2; |
| 3189 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 3190 | min_tx_space >>= 10; |
| 3191 | /* software strips receive CRC, so leave room for it */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3192 | min_rx_space = adapter->max_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3193 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 3194 | min_rx_space >>= 10; |
| 3195 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3196 | /* |
| 3197 | * If current Tx allocation is less than the min Tx FIFO size, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3198 | * 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] | 3199 | * allocation, take space away from current Rx allocation |
| 3200 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3201 | if ((tx_space < min_tx_space) && |
| 3202 | ((min_tx_space - tx_space) < pba)) { |
| 3203 | pba -= min_tx_space - tx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3204 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3205 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3206 | * if short on Rx space, Rx wins and must trump Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3207 | * adjustment or use Early Receive if available |
| 3208 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3209 | if ((pba < min_rx_space) && |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3210 | (!(adapter->flags & FLAG_HAS_ERT))) |
| 3211 | /* ERT enabled in e1000_configure_rx */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3212 | pba = min_rx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3213 | } |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3214 | |
| 3215 | ew32(PBA, pba); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3216 | } |
| 3217 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3218 | /* |
| 3219 | * flow control settings |
| 3220 | * |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3221 | * 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] | 3222 | * (or the size used for early receive) above it in the Rx FIFO. |
| 3223 | * Set it to the lower of: |
| 3224 | * - 90% of the Rx FIFO size, and |
| 3225 | * - the full Rx FIFO size minus the early receive size (for parts |
| 3226 | * with ERT support assuming ERT set to E1000_ERT_2048), or |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3227 | * - the full Rx FIFO size minus one full frame |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3228 | */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3229 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
| 3230 | fc->pause_time = 0xFFFF; |
| 3231 | else |
| 3232 | fc->pause_time = E1000_FC_PAUSE_TIME; |
| 3233 | fc->send_xon = 1; |
| 3234 | fc->current_mode = fc->requested_mode; |
| 3235 | |
| 3236 | switch (hw->mac.type) { |
| 3237 | default: |
| 3238 | if ((adapter->flags & FLAG_HAS_ERT) && |
| 3239 | (adapter->netdev->mtu > ETH_DATA_LEN)) |
| 3240 | hwm = min(((pba << 10) * 9 / 10), |
| 3241 | ((pba << 10) - (E1000_ERT_2048 << 3))); |
| 3242 | else |
| 3243 | hwm = min(((pba << 10) * 9 / 10), |
| 3244 | ((pba << 10) - adapter->max_frame_size)); |
| 3245 | |
| 3246 | fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ |
| 3247 | fc->low_water = fc->high_water - 8; |
| 3248 | break; |
| 3249 | case e1000_pchlan: |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3250 | /* |
| 3251 | * Workaround PCH LOM adapter hangs with certain network |
| 3252 | * loads. If hangs persist, try disabling Tx flow control. |
| 3253 | */ |
| 3254 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3255 | fc->high_water = 0x3500; |
| 3256 | fc->low_water = 0x1500; |
| 3257 | } else { |
| 3258 | fc->high_water = 0x5000; |
| 3259 | fc->low_water = 0x3000; |
| 3260 | } |
Bruce Allan | a305595 | 2010-05-10 15:02:12 +0000 | [diff] [blame] | 3261 | fc->refresh_time = 0x1000; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3262 | break; |
| 3263 | case e1000_pch2lan: |
| 3264 | fc->high_water = 0x05C20; |
| 3265 | fc->low_water = 0x05048; |
| 3266 | fc->pause_time = 0x0650; |
| 3267 | fc->refresh_time = 0x0400; |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3268 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3269 | pba = 14; |
| 3270 | ew32(PBA, pba); |
| 3271 | } |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3272 | break; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3273 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3274 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3275 | /* |
| 3276 | * Disable Adaptive Interrupt Moderation if 2 full packets cannot |
| 3277 | * fit in receive buffer and early-receive not supported. |
| 3278 | */ |
| 3279 | if (adapter->itr_setting & 0x3) { |
| 3280 | if (((adapter->max_frame_size * 2) > (pba << 10)) && |
| 3281 | !(adapter->flags & FLAG_HAS_ERT)) { |
| 3282 | if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) { |
| 3283 | dev_info(&adapter->pdev->dev, |
| 3284 | "Interrupt Throttle Rate turned off\n"); |
| 3285 | adapter->flags2 |= FLAG2_DISABLE_AIM; |
| 3286 | ew32(ITR, 0); |
| 3287 | } |
| 3288 | } else if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 3289 | dev_info(&adapter->pdev->dev, |
| 3290 | "Interrupt Throttle Rate turned on\n"); |
| 3291 | adapter->flags2 &= ~FLAG2_DISABLE_AIM; |
| 3292 | adapter->itr = 20000; |
| 3293 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
| 3294 | } |
| 3295 | } |
| 3296 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3297 | /* Allow time for pending master requests to run */ |
| 3298 | mac->ops.reset_hw(hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3299 | |
| 3300 | /* |
| 3301 | * For parts with AMT enabled, let the firmware know |
| 3302 | * that the network interface is in control |
| 3303 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 3304 | if (adapter->flags & FLAG_HAS_AMT) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3305 | e1000e_get_hw_control(adapter); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3306 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3307 | ew32(WUC, 0); |
| 3308 | |
| 3309 | if (mac->ops.init_hw(hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 3310 | e_err("Hardware Error\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3311 | |
| 3312 | e1000_update_mng_vlan(adapter); |
| 3313 | |
| 3314 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 3315 | ew32(VET, ETH_P_8021Q); |
| 3316 | |
| 3317 | e1000e_reset_adaptive(hw); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3318 | |
| 3319 | if (!netif_running(adapter->netdev) && |
| 3320 | !test_bit(__E1000_TESTING, &adapter->state)) { |
| 3321 | e1000_power_down_phy(adapter); |
| 3322 | return; |
| 3323 | } |
| 3324 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3325 | e1000_get_phy_info(hw); |
| 3326 | |
Bruce Allan | 918d719 | 2009-06-02 11:28:20 +0000 | [diff] [blame] | 3327 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && |
| 3328 | !(adapter->flags & FLAG_SMART_POWER_DOWN)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3329 | u16 phy_data = 0; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3330 | /* |
| 3331 | * speed up time to link by disabling smart power down, ignore |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3332 | * the return value of this function because there is nothing |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3333 | * different we would do if it failed |
| 3334 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3335 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
| 3336 | phy_data &= ~IGP02E1000_PM_SPD; |
| 3337 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 3338 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | int e1000e_up(struct e1000_adapter *adapter) |
| 3342 | { |
| 3343 | struct e1000_hw *hw = &adapter->hw; |
| 3344 | |
| 3345 | /* hardware has been reset, we need to reload some things */ |
| 3346 | e1000_configure(adapter); |
| 3347 | |
| 3348 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3349 | |
| 3350 | napi_enable(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3351 | if (adapter->msix_entries) |
| 3352 | e1000_configure_msix(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3353 | e1000_irq_enable(adapter); |
| 3354 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 3355 | netif_start_queue(adapter->netdev); |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3356 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3357 | /* fire a link change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3358 | if (adapter->msix_entries) |
| 3359 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3360 | else |
| 3361 | ew32(ICS, E1000_ICS_LSC); |
| 3362 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3363 | return 0; |
| 3364 | } |
| 3365 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3366 | static void e1000e_flush_descriptors(struct e1000_adapter *adapter) |
| 3367 | { |
| 3368 | struct e1000_hw *hw = &adapter->hw; |
| 3369 | |
| 3370 | if (!(adapter->flags2 & FLAG2_DMA_BURST)) |
| 3371 | return; |
| 3372 | |
| 3373 | /* flush pending descriptor writebacks to memory */ |
| 3374 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 3375 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 3376 | |
| 3377 | /* execute the writes immediately */ |
| 3378 | e1e_flush(); |
| 3379 | } |
| 3380 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3381 | static void e1000e_update_stats(struct e1000_adapter *adapter); |
| 3382 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3383 | void e1000e_down(struct e1000_adapter *adapter) |
| 3384 | { |
| 3385 | struct net_device *netdev = adapter->netdev; |
| 3386 | struct e1000_hw *hw = &adapter->hw; |
| 3387 | u32 tctl, rctl; |
| 3388 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3389 | /* |
| 3390 | * signal that we're down so the interrupt handler does not |
| 3391 | * reschedule our watchdog timer |
| 3392 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3393 | set_bit(__E1000_DOWN, &adapter->state); |
| 3394 | |
| 3395 | /* disable receives in the hardware */ |
| 3396 | rctl = er32(RCTL); |
| 3397 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 3398 | /* flush and sleep below */ |
| 3399 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3400 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3401 | |
| 3402 | /* disable transmits in the hardware */ |
| 3403 | tctl = er32(TCTL); |
| 3404 | tctl &= ~E1000_TCTL_EN; |
| 3405 | ew32(TCTL, tctl); |
| 3406 | /* flush both disables and wait for them to finish */ |
| 3407 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3408 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3409 | |
| 3410 | napi_disable(&adapter->napi); |
| 3411 | e1000_irq_disable(adapter); |
| 3412 | |
| 3413 | del_timer_sync(&adapter->watchdog_timer); |
| 3414 | del_timer_sync(&adapter->phy_info_timer); |
| 3415 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3416 | netif_carrier_off(netdev); |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3417 | |
| 3418 | spin_lock(&adapter->stats64_lock); |
| 3419 | e1000e_update_stats(adapter); |
| 3420 | spin_unlock(&adapter->stats64_lock); |
| 3421 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 3422 | e1000e_flush_descriptors(adapter); |
| 3423 | e1000_clean_tx_ring(adapter); |
| 3424 | e1000_clean_rx_ring(adapter); |
| 3425 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3426 | adapter->link_speed = 0; |
| 3427 | adapter->link_duplex = 0; |
| 3428 | |
Jeff Kirsher | 52cc308 | 2008-06-24 17:01:29 -0700 | [diff] [blame] | 3429 | if (!pci_channel_offline(adapter->pdev)) |
| 3430 | e1000e_reset(adapter); |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3431 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3432 | /* |
| 3433 | * TODO: for power management, we could drop the link and |
| 3434 | * pci_disable_device here. |
| 3435 | */ |
| 3436 | } |
| 3437 | |
| 3438 | void e1000e_reinit_locked(struct e1000_adapter *adapter) |
| 3439 | { |
| 3440 | might_sleep(); |
| 3441 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3442 | usleep_range(1000, 2000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3443 | e1000e_down(adapter); |
| 3444 | e1000e_up(adapter); |
| 3445 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 3446 | } |
| 3447 | |
| 3448 | /** |
| 3449 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 3450 | * @adapter: board private structure to initialize |
| 3451 | * |
| 3452 | * e1000_sw_init initializes the Adapter private data structure. |
| 3453 | * Fields are initialized based on PCI device information and |
| 3454 | * OS network device settings (MTU size). |
| 3455 | **/ |
| 3456 | static int __devinit e1000_sw_init(struct e1000_adapter *adapter) |
| 3457 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3458 | struct net_device *netdev = adapter->netdev; |
| 3459 | |
| 3460 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN; |
| 3461 | adapter->rx_ps_bsize0 = 128; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3462 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3463 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3464 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3465 | spin_lock_init(&adapter->stats64_lock); |
| 3466 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3467 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3468 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3469 | if (e1000_alloc_queues(adapter)) |
| 3470 | return -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3471 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3472 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3473 | e1000_irq_disable(adapter); |
| 3474 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3475 | set_bit(__E1000_DOWN, &adapter->state); |
| 3476 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | /** |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3480 | * e1000_intr_msi_test - Interrupt Handler |
| 3481 | * @irq: interrupt number |
| 3482 | * @data: pointer to a network interface device structure |
| 3483 | **/ |
| 3484 | static irqreturn_t e1000_intr_msi_test(int irq, void *data) |
| 3485 | { |
| 3486 | struct net_device *netdev = data; |
| 3487 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3488 | struct e1000_hw *hw = &adapter->hw; |
| 3489 | u32 icr = er32(ICR); |
| 3490 | |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 3491 | e_dbg("icr is %08X\n", icr); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3492 | if (icr & E1000_ICR_RXSEQ) { |
| 3493 | adapter->flags &= ~FLAG_MSI_TEST_FAILED; |
| 3494 | wmb(); |
| 3495 | } |
| 3496 | |
| 3497 | return IRQ_HANDLED; |
| 3498 | } |
| 3499 | |
| 3500 | /** |
| 3501 | * e1000_test_msi_interrupt - Returns 0 for successful test |
| 3502 | * @adapter: board private struct |
| 3503 | * |
| 3504 | * code flow taken from tg3.c |
| 3505 | **/ |
| 3506 | static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) |
| 3507 | { |
| 3508 | struct net_device *netdev = adapter->netdev; |
| 3509 | struct e1000_hw *hw = &adapter->hw; |
| 3510 | int err; |
| 3511 | |
| 3512 | /* poll_enable hasn't been called yet, so don't need disable */ |
| 3513 | /* clear any pending events */ |
| 3514 | er32(ICR); |
| 3515 | |
| 3516 | /* free the real vector and request a test handler */ |
| 3517 | e1000_free_irq(adapter); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3518 | e1000e_reset_interrupt_capability(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3519 | |
| 3520 | /* Assume that the test fails, if it succeeds then the test |
| 3521 | * MSI irq handler will unset this flag */ |
| 3522 | adapter->flags |= FLAG_MSI_TEST_FAILED; |
| 3523 | |
| 3524 | err = pci_enable_msi(adapter->pdev); |
| 3525 | if (err) |
| 3526 | goto msi_test_failed; |
| 3527 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3528 | err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3529 | netdev->name, netdev); |
| 3530 | if (err) { |
| 3531 | pci_disable_msi(adapter->pdev); |
| 3532 | goto msi_test_failed; |
| 3533 | } |
| 3534 | |
| 3535 | wmb(); |
| 3536 | |
| 3537 | e1000_irq_enable(adapter); |
| 3538 | |
| 3539 | /* fire an unusual interrupt on the test handler */ |
| 3540 | ew32(ICS, E1000_ICS_RXSEQ); |
| 3541 | e1e_flush(); |
| 3542 | msleep(50); |
| 3543 | |
| 3544 | e1000_irq_disable(adapter); |
| 3545 | |
| 3546 | rmb(); |
| 3547 | |
| 3548 | if (adapter->flags & FLAG_MSI_TEST_FAILED) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3549 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 3550 | e_info("MSI interrupt test failed, using legacy interrupt.\n"); |
| 3551 | } else |
| 3552 | e_dbg("MSI interrupt test succeeded!\n"); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3553 | |
| 3554 | free_irq(adapter->pdev->irq, netdev); |
| 3555 | pci_disable_msi(adapter->pdev); |
| 3556 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3557 | msi_test_failed: |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3558 | e1000e_set_interrupt_capability(adapter); |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 3559 | return e1000_request_irq(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3560 | } |
| 3561 | |
| 3562 | /** |
| 3563 | * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored |
| 3564 | * @adapter: board private struct |
| 3565 | * |
| 3566 | * code flow taken from tg3.c, called with e1000 interrupts disabled. |
| 3567 | **/ |
| 3568 | static int e1000_test_msi(struct e1000_adapter *adapter) |
| 3569 | { |
| 3570 | int err; |
| 3571 | u16 pci_cmd; |
| 3572 | |
| 3573 | if (!(adapter->flags & FLAG_MSI_ENABLED)) |
| 3574 | return 0; |
| 3575 | |
| 3576 | /* disable SERR in case the MSI write causes a master abort */ |
| 3577 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 3578 | if (pci_cmd & PCI_COMMAND_SERR) |
| 3579 | pci_write_config_word(adapter->pdev, PCI_COMMAND, |
| 3580 | pci_cmd & ~PCI_COMMAND_SERR); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3581 | |
| 3582 | err = e1000_test_msi_interrupt(adapter); |
| 3583 | |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 3584 | /* re-enable SERR */ |
| 3585 | if (pci_cmd & PCI_COMMAND_SERR) { |
| 3586 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
| 3587 | pci_cmd |= PCI_COMMAND_SERR; |
| 3588 | pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); |
| 3589 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3590 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3591 | return err; |
| 3592 | } |
| 3593 | |
| 3594 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3595 | * e1000_open - Called when a network interface is made active |
| 3596 | * @netdev: network interface device structure |
| 3597 | * |
| 3598 | * Returns 0 on success, negative value on failure |
| 3599 | * |
| 3600 | * The open entry point is called when a network interface is made |
| 3601 | * active by the system (IFF_UP). At this point all resources needed |
| 3602 | * for transmit and receive operations are allocated, the interrupt |
| 3603 | * handler is registered with the OS, the watchdog timer is started, |
| 3604 | * and the stack is notified that the interface is ready. |
| 3605 | **/ |
| 3606 | static int e1000_open(struct net_device *netdev) |
| 3607 | { |
| 3608 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3609 | struct e1000_hw *hw = &adapter->hw; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3610 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3611 | int err; |
| 3612 | |
| 3613 | /* disallow open during test */ |
| 3614 | if (test_bit(__E1000_TESTING, &adapter->state)) |
| 3615 | return -EBUSY; |
| 3616 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3617 | pm_runtime_get_sync(&pdev->dev); |
| 3618 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 3619 | netif_carrier_off(netdev); |
| 3620 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3621 | /* allocate transmit descriptors */ |
| 3622 | err = e1000e_setup_tx_resources(adapter); |
| 3623 | if (err) |
| 3624 | goto err_setup_tx; |
| 3625 | |
| 3626 | /* allocate receive descriptors */ |
| 3627 | err = e1000e_setup_rx_resources(adapter); |
| 3628 | if (err) |
| 3629 | goto err_setup_rx; |
| 3630 | |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 3631 | /* |
| 3632 | * If AMT is enabled, let the firmware know that the network |
| 3633 | * interface is now open and reset the part to a known state. |
| 3634 | */ |
| 3635 | if (adapter->flags & FLAG_HAS_AMT) { |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3636 | e1000e_get_hw_control(adapter); |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 3637 | e1000e_reset(adapter); |
| 3638 | } |
| 3639 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3640 | e1000e_power_up_phy(adapter); |
| 3641 | |
| 3642 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 3643 | if ((adapter->hw.mng_cookie.status & |
| 3644 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
| 3645 | e1000_update_mng_vlan(adapter); |
| 3646 | |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3647 | /* DMA latency requirement to workaround early-receive/jumbo issue */ |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3648 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 3649 | (adapter->hw.mac.type == e1000_pch2lan)) |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 3650 | pm_qos_add_request(&adapter->netdev->pm_qos_req, |
| 3651 | PM_QOS_CPU_DMA_LATENCY, |
| 3652 | PM_QOS_DEFAULT_VALUE); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3653 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3654 | /* |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3655 | * before we allocate an interrupt, we must be ready to handle it. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3656 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 3657 | * 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] | 3658 | * clean_rx handler before we do so. |
| 3659 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3660 | e1000_configure(adapter); |
| 3661 | |
| 3662 | err = e1000_request_irq(adapter); |
| 3663 | if (err) |
| 3664 | goto err_req_irq; |
| 3665 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3666 | /* |
| 3667 | * Work around PCIe errata with MSI interrupts causing some chipsets to |
| 3668 | * ignore e1000e MSI messages, which means we need to test our MSI |
| 3669 | * interrupt now |
| 3670 | */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3671 | if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3672 | err = e1000_test_msi(adapter); |
| 3673 | if (err) { |
| 3674 | e_err("Interrupt allocation failed\n"); |
| 3675 | goto err_req_irq; |
| 3676 | } |
| 3677 | } |
| 3678 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3679 | /* From here on the code is the same as e1000e_up() */ |
| 3680 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3681 | |
| 3682 | napi_enable(&adapter->napi); |
| 3683 | |
| 3684 | e1000_irq_enable(adapter); |
| 3685 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3686 | netif_start_queue(netdev); |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 3687 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3688 | adapter->idle_check = true; |
| 3689 | pm_runtime_put(&pdev->dev); |
| 3690 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3691 | /* fire a link status change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3692 | if (adapter->msix_entries) |
| 3693 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3694 | else |
| 3695 | ew32(ICS, E1000_ICS_LSC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3696 | |
| 3697 | return 0; |
| 3698 | |
| 3699 | err_req_irq: |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3700 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3701 | e1000_power_down_phy(adapter); |
| 3702 | e1000e_free_rx_resources(adapter); |
| 3703 | err_setup_rx: |
| 3704 | e1000e_free_tx_resources(adapter); |
| 3705 | err_setup_tx: |
| 3706 | e1000e_reset(adapter); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3707 | pm_runtime_put_sync(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3708 | |
| 3709 | return err; |
| 3710 | } |
| 3711 | |
| 3712 | /** |
| 3713 | * e1000_close - Disables a network interface |
| 3714 | * @netdev: network interface device structure |
| 3715 | * |
| 3716 | * Returns 0, this is not allowed to fail |
| 3717 | * |
| 3718 | * The close entry point is called when an interface is de-activated |
| 3719 | * by the OS. The hardware is still under the drivers control, but |
| 3720 | * needs to be disabled. A global MAC reset is issued to stop the |
| 3721 | * hardware, and all transmit and receive resources are freed. |
| 3722 | **/ |
| 3723 | static int e1000_close(struct net_device *netdev) |
| 3724 | { |
| 3725 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3726 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3727 | |
| 3728 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3729 | |
| 3730 | pm_runtime_get_sync(&pdev->dev); |
| 3731 | |
| 3732 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 3733 | e1000e_down(adapter); |
| 3734 | e1000_free_irq(adapter); |
| 3735 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3736 | e1000_power_down_phy(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3737 | |
| 3738 | e1000e_free_tx_resources(adapter); |
| 3739 | e1000e_free_rx_resources(adapter); |
| 3740 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3741 | /* |
| 3742 | * kill manageability vlan ID if supported, but not if a vlan with |
| 3743 | * the same ID is registered on the host OS (let 8021q kill it) |
| 3744 | */ |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3745 | if (adapter->hw.mng_cookie.status & |
| 3746 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3747 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 3748 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3749 | /* |
| 3750 | * If AMT is enabled, let the firmware know that the network |
| 3751 | * interface is now closed |
| 3752 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3753 | if ((adapter->flags & FLAG_HAS_AMT) && |
| 3754 | !test_bit(__E1000_TESTING, &adapter->state)) |
| 3755 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3756 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3757 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 3758 | (adapter->hw.mac.type == e1000_pch2lan)) |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 3759 | pm_qos_remove_request(&adapter->netdev->pm_qos_req); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3760 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3761 | pm_runtime_put_sync(&pdev->dev); |
| 3762 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3763 | return 0; |
| 3764 | } |
| 3765 | /** |
| 3766 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 3767 | * @netdev: network interface device structure |
| 3768 | * @p: pointer to an address structure |
| 3769 | * |
| 3770 | * Returns 0 on success, negative on failure |
| 3771 | **/ |
| 3772 | static int e1000_set_mac(struct net_device *netdev, void *p) |
| 3773 | { |
| 3774 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3775 | struct sockaddr *addr = p; |
| 3776 | |
| 3777 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3778 | return -EADDRNOTAVAIL; |
| 3779 | |
| 3780 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 3781 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 3782 | |
| 3783 | e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0); |
| 3784 | |
| 3785 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { |
| 3786 | /* activate the work around */ |
| 3787 | e1000e_set_laa_state_82571(&adapter->hw, 1); |
| 3788 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3789 | /* |
| 3790 | * 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] | 3791 | * between the time RAR[0] gets clobbered and the time it |
| 3792 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
| 3793 | * of the RARs and no incoming packets directed to this port |
| 3794 | * are dropped. Eventually the LAA will be in RAR[0] and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3795 | * RAR[14] |
| 3796 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3797 | e1000e_rar_set(&adapter->hw, |
| 3798 | adapter->hw.mac.addr, |
| 3799 | adapter->hw.mac.rar_entry_count - 1); |
| 3800 | } |
| 3801 | |
| 3802 | return 0; |
| 3803 | } |
| 3804 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 3805 | /** |
| 3806 | * e1000e_update_phy_task - work thread to update phy |
| 3807 | * @work: pointer to our work struct |
| 3808 | * |
| 3809 | * this worker thread exists because we must acquire a |
| 3810 | * semaphore to read the phy, which we could msleep while |
| 3811 | * waiting for it, and we can't msleep in a timer. |
| 3812 | **/ |
| 3813 | static void e1000e_update_phy_task(struct work_struct *work) |
| 3814 | { |
| 3815 | struct e1000_adapter *adapter = container_of(work, |
| 3816 | struct e1000_adapter, update_phy_task); |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 3817 | |
| 3818 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 3819 | return; |
| 3820 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 3821 | e1000_get_phy_info(&adapter->hw); |
| 3822 | } |
| 3823 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3824 | /* |
| 3825 | * Need to wait a few seconds after link up to get diagnostic information from |
| 3826 | * the phy |
| 3827 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3828 | static void e1000_update_phy_info(unsigned long data) |
| 3829 | { |
| 3830 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 3831 | |
| 3832 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 3833 | return; |
| 3834 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 3835 | schedule_work(&adapter->update_phy_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | /** |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3839 | * e1000e_update_phy_stats - Update the PHY statistics counters |
| 3840 | * @adapter: board private structure |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 3841 | * |
| 3842 | * Read/clear the upper 16-bit PHY registers and read/accumulate lower |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3843 | **/ |
| 3844 | static void e1000e_update_phy_stats(struct e1000_adapter *adapter) |
| 3845 | { |
| 3846 | struct e1000_hw *hw = &adapter->hw; |
| 3847 | s32 ret_val; |
| 3848 | u16 phy_data; |
| 3849 | |
| 3850 | ret_val = hw->phy.ops.acquire(hw); |
| 3851 | if (ret_val) |
| 3852 | return; |
| 3853 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3854 | /* |
| 3855 | * A page set is expensive so check if already on desired page. |
| 3856 | * If not, set to the page with the PHY status registers. |
| 3857 | */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 3858 | hw->phy.addr = 1; |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3859 | ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 3860 | &phy_data); |
| 3861 | if (ret_val) |
| 3862 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 3863 | if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) { |
| 3864 | ret_val = hw->phy.ops.set_page(hw, |
| 3865 | HV_STATS_PAGE << IGP_PAGE_SHIFT); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3866 | if (ret_val) |
| 3867 | goto release; |
| 3868 | } |
| 3869 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3870 | /* Single Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 3871 | hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data); |
| 3872 | ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3873 | if (!ret_val) |
| 3874 | adapter->stats.scc += phy_data; |
| 3875 | |
| 3876 | /* Excessive Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 3877 | hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data); |
| 3878 | ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3879 | if (!ret_val) |
| 3880 | adapter->stats.ecol += phy_data; |
| 3881 | |
| 3882 | /* Multiple Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 3883 | hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data); |
| 3884 | ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3885 | if (!ret_val) |
| 3886 | adapter->stats.mcc += phy_data; |
| 3887 | |
| 3888 | /* Late Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 3889 | hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data); |
| 3890 | ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3891 | if (!ret_val) |
| 3892 | adapter->stats.latecol += phy_data; |
| 3893 | |
| 3894 | /* Collision Count - also used for adaptive IFS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 3895 | hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data); |
| 3896 | ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3897 | if (!ret_val) |
| 3898 | hw->mac.collision_delta = phy_data; |
| 3899 | |
| 3900 | /* Defer Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 3901 | hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data); |
| 3902 | ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3903 | if (!ret_val) |
| 3904 | adapter->stats.dc += phy_data; |
| 3905 | |
| 3906 | /* Transmit with no CRS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 3907 | hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data); |
| 3908 | ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3909 | if (!ret_val) |
| 3910 | adapter->stats.tncrs += phy_data; |
| 3911 | |
| 3912 | release: |
| 3913 | hw->phy.ops.release(hw); |
| 3914 | } |
| 3915 | |
| 3916 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3917 | * e1000e_update_stats - Update the board statistics counters |
| 3918 | * @adapter: board private structure |
| 3919 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3920 | static void e1000e_update_stats(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3921 | { |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 3922 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3923 | struct e1000_hw *hw = &adapter->hw; |
| 3924 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3925 | |
| 3926 | /* |
| 3927 | * Prevent stats update while adapter is being reset, or if the pci |
| 3928 | * connection is down. |
| 3929 | */ |
| 3930 | if (adapter->link_speed == 0) |
| 3931 | return; |
| 3932 | if (pci_channel_offline(pdev)) |
| 3933 | return; |
| 3934 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3935 | adapter->stats.crcerrs += er32(CRCERRS); |
| 3936 | adapter->stats.gprc += er32(GPRC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3937 | adapter->stats.gorc += er32(GORCL); |
| 3938 | er32(GORCH); /* Clear gorc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3939 | adapter->stats.bprc += er32(BPRC); |
| 3940 | adapter->stats.mprc += er32(MPRC); |
| 3941 | adapter->stats.roc += er32(ROC); |
| 3942 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3943 | adapter->stats.mpc += er32(MPC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3944 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3945 | /* Half-duplex statistics */ |
| 3946 | if (adapter->link_duplex == HALF_DUPLEX) { |
| 3947 | if (adapter->flags2 & FLAG2_HAS_PHY_STATS) { |
| 3948 | e1000e_update_phy_stats(adapter); |
| 3949 | } else { |
| 3950 | adapter->stats.scc += er32(SCC); |
| 3951 | adapter->stats.ecol += er32(ECOL); |
| 3952 | adapter->stats.mcc += er32(MCC); |
| 3953 | adapter->stats.latecol += er32(LATECOL); |
| 3954 | adapter->stats.dc += er32(DC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3955 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3956 | hw->mac.collision_delta = er32(COLC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3957 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3958 | if ((hw->mac.type != e1000_82574) && |
| 3959 | (hw->mac.type != e1000_82583)) |
| 3960 | adapter->stats.tncrs += er32(TNCRS); |
| 3961 | } |
| 3962 | adapter->stats.colc += hw->mac.collision_delta; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3963 | } |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 3964 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3965 | adapter->stats.xonrxc += er32(XONRXC); |
| 3966 | adapter->stats.xontxc += er32(XONTXC); |
| 3967 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 3968 | adapter->stats.xofftxc += er32(XOFFTXC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3969 | adapter->stats.gptc += er32(GPTC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 3970 | adapter->stats.gotc += er32(GOTCL); |
| 3971 | er32(GOTCH); /* Clear gotc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3972 | adapter->stats.rnbc += er32(RNBC); |
| 3973 | adapter->stats.ruc += er32(RUC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3974 | |
| 3975 | adapter->stats.mptc += er32(MPTC); |
| 3976 | adapter->stats.bptc += er32(BPTC); |
| 3977 | |
| 3978 | /* used for adaptive IFS */ |
| 3979 | |
| 3980 | hw->mac.tx_packet_delta = er32(TPT); |
| 3981 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3982 | |
| 3983 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 3984 | adapter->stats.rxerrc += er32(RXERRC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3985 | adapter->stats.cexterr += er32(CEXTERR); |
| 3986 | adapter->stats.tsctc += er32(TSCTC); |
| 3987 | adapter->stats.tsctfc += er32(TSCTFC); |
| 3988 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3989 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 3990 | netdev->stats.multicast = adapter->stats.mprc; |
| 3991 | netdev->stats.collisions = adapter->stats.colc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3992 | |
| 3993 | /* Rx Errors */ |
| 3994 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3995 | /* |
| 3996 | * RLEC on some newer hardware can be incorrect so build |
| 3997 | * our own version based on RUC and ROC |
| 3998 | */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 3999 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4000 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 4001 | adapter->stats.ruc + adapter->stats.roc + |
| 4002 | adapter->stats.cexterr; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4003 | netdev->stats.rx_length_errors = adapter->stats.ruc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4004 | adapter->stats.roc; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4005 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4006 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; |
| 4007 | netdev->stats.rx_missed_errors = adapter->stats.mpc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4008 | |
| 4009 | /* Tx Errors */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4010 | netdev->stats.tx_errors = adapter->stats.ecol + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4011 | adapter->stats.latecol; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4012 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
| 4013 | netdev->stats.tx_window_errors = adapter->stats.latecol; |
| 4014 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4015 | |
| 4016 | /* Tx Dropped needs to be maintained elsewhere */ |
| 4017 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4018 | /* Management Stats */ |
| 4019 | adapter->stats.mgptc += er32(MGTPTC); |
| 4020 | adapter->stats.mgprc += er32(MGTPRC); |
| 4021 | adapter->stats.mgpdc += er32(MGTPDC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4022 | } |
| 4023 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4024 | /** |
| 4025 | * e1000_phy_read_status - Update the PHY register status snapshot |
| 4026 | * @adapter: board private structure |
| 4027 | **/ |
| 4028 | static void e1000_phy_read_status(struct e1000_adapter *adapter) |
| 4029 | { |
| 4030 | struct e1000_hw *hw = &adapter->hw; |
| 4031 | struct e1000_phy_regs *phy = &adapter->phy_regs; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4032 | |
| 4033 | if ((er32(STATUS) & E1000_STATUS_LU) && |
| 4034 | (adapter->hw.phy.media_type == e1000_media_type_copper)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4035 | int ret_val; |
| 4036 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4037 | ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr); |
| 4038 | ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr); |
| 4039 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise); |
| 4040 | ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa); |
| 4041 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion); |
| 4042 | ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000); |
| 4043 | ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000); |
| 4044 | ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus); |
| 4045 | if (ret_val) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4046 | e_warn("Error reading PHY register\n"); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4047 | } else { |
| 4048 | /* |
| 4049 | * Do not read PHY registers if link is not up |
| 4050 | * Set values to typical power-on defaults |
| 4051 | */ |
| 4052 | phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); |
| 4053 | phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | |
| 4054 | BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | |
| 4055 | BMSR_ERCAP); |
| 4056 | phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | |
| 4057 | ADVERTISE_ALL | ADVERTISE_CSMA); |
| 4058 | phy->lpa = 0; |
| 4059 | phy->expansion = EXPANSION_ENABLENPAGE; |
| 4060 | phy->ctrl1000 = ADVERTISE_1000FULL; |
| 4061 | phy->stat1000 = 0; |
| 4062 | phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); |
| 4063 | } |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4066 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
| 4067 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4068 | struct e1000_hw *hw = &adapter->hw; |
| 4069 | u32 ctrl = er32(CTRL); |
| 4070 | |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4071 | /* Link status message must follow this format for user tools */ |
| 4072 | printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, " |
| 4073 | "Flow Control: %s\n", |
| 4074 | adapter->netdev->name, |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4075 | adapter->link_speed, |
| 4076 | (adapter->link_duplex == FULL_DUPLEX) ? |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4077 | "Full Duplex" : "Half Duplex", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4078 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ? |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4079 | "Rx/Tx" : |
| 4080 | ((ctrl & E1000_CTRL_RFCE) ? "Rx" : |
| 4081 | ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None"))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4082 | } |
| 4083 | |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 4084 | static bool e1000e_has_link(struct e1000_adapter *adapter) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4085 | { |
| 4086 | struct e1000_hw *hw = &adapter->hw; |
| 4087 | bool link_active = 0; |
| 4088 | s32 ret_val = 0; |
| 4089 | |
| 4090 | /* |
| 4091 | * get_link_status is set on LSC (link status) interrupt or |
| 4092 | * Rx sequence error interrupt. get_link_status will stay |
| 4093 | * false until the check_for_link establishes link |
| 4094 | * for copper adapters ONLY |
| 4095 | */ |
| 4096 | switch (hw->phy.media_type) { |
| 4097 | case e1000_media_type_copper: |
| 4098 | if (hw->mac.get_link_status) { |
| 4099 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4100 | link_active = !hw->mac.get_link_status; |
| 4101 | } else { |
| 4102 | link_active = 1; |
| 4103 | } |
| 4104 | break; |
| 4105 | case e1000_media_type_fiber: |
| 4106 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4107 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 4108 | break; |
| 4109 | case e1000_media_type_internal_serdes: |
| 4110 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4111 | link_active = adapter->hw.mac.serdes_has_link; |
| 4112 | break; |
| 4113 | default: |
| 4114 | case e1000_media_type_unknown: |
| 4115 | break; |
| 4116 | } |
| 4117 | |
| 4118 | if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && |
| 4119 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 4120 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4121 | e_info("Gigabit has been disabled, downgrading speed\n"); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4122 | } |
| 4123 | |
| 4124 | return link_active; |
| 4125 | } |
| 4126 | |
| 4127 | static void e1000e_enable_receives(struct e1000_adapter *adapter) |
| 4128 | { |
| 4129 | /* make sure the receive unit is started */ |
| 4130 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 4131 | (adapter->flags & FLAG_RX_RESTART_NOW)) { |
| 4132 | struct e1000_hw *hw = &adapter->hw; |
| 4133 | u32 rctl = er32(RCTL); |
| 4134 | ew32(RCTL, rctl | E1000_RCTL_EN); |
| 4135 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
| 4136 | } |
| 4137 | } |
| 4138 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4139 | static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter) |
| 4140 | { |
| 4141 | struct e1000_hw *hw = &adapter->hw; |
| 4142 | |
| 4143 | /* |
| 4144 | * With 82574 controllers, PHY needs to be checked periodically |
| 4145 | * for hung state and reset, if two calls return true |
| 4146 | */ |
| 4147 | if (e1000_check_phy_82574(hw)) |
| 4148 | adapter->phy_hang_count++; |
| 4149 | else |
| 4150 | adapter->phy_hang_count = 0; |
| 4151 | |
| 4152 | if (adapter->phy_hang_count > 1) { |
| 4153 | adapter->phy_hang_count = 0; |
| 4154 | schedule_work(&adapter->reset_task); |
| 4155 | } |
| 4156 | } |
| 4157 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4158 | /** |
| 4159 | * e1000_watchdog - Timer Call-back |
| 4160 | * @data: pointer to adapter cast into an unsigned long |
| 4161 | **/ |
| 4162 | static void e1000_watchdog(unsigned long data) |
| 4163 | { |
| 4164 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 4165 | |
| 4166 | /* Do the rest outside of interrupt context */ |
| 4167 | schedule_work(&adapter->watchdog_task); |
| 4168 | |
| 4169 | /* TODO: make this use queue_delayed_work() */ |
| 4170 | } |
| 4171 | |
| 4172 | static void e1000_watchdog_task(struct work_struct *work) |
| 4173 | { |
| 4174 | struct e1000_adapter *adapter = container_of(work, |
| 4175 | struct e1000_adapter, watchdog_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4176 | struct net_device *netdev = adapter->netdev; |
| 4177 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4178 | struct e1000_phy_info *phy = &adapter->hw.phy; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4179 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4180 | struct e1000_hw *hw = &adapter->hw; |
| 4181 | u32 link, tctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4182 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4183 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4184 | return; |
| 4185 | |
David S. Miller | b405e8d | 2010-02-04 22:31:41 -0800 | [diff] [blame] | 4186 | link = e1000e_has_link(adapter); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4187 | if ((netif_carrier_ok(netdev)) && link) { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4188 | /* Cancel scheduled suspend requests. */ |
| 4189 | pm_runtime_resume(netdev->dev.parent); |
| 4190 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4191 | e1000e_enable_receives(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4192 | goto link_up; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4193 | } |
| 4194 | |
| 4195 | if ((e1000e_enable_tx_pkt_filtering(hw)) && |
| 4196 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) |
| 4197 | e1000_update_mng_vlan(adapter); |
| 4198 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4199 | if (link) { |
| 4200 | if (!netif_carrier_ok(netdev)) { |
| 4201 | bool txb2b = 1; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4202 | |
| 4203 | /* Cancel scheduled suspend requests. */ |
| 4204 | pm_runtime_resume(netdev->dev.parent); |
| 4205 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4206 | /* update snapshot of PHY registers on LSC */ |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4207 | e1000_phy_read_status(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4208 | mac->ops.get_link_up_info(&adapter->hw, |
| 4209 | &adapter->link_speed, |
| 4210 | &adapter->link_duplex); |
| 4211 | e1000_print_link_info(adapter); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4212 | /* |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 4213 | * On supported PHYs, check for duplex mismatch only |
| 4214 | * if link has autonegotiated at 10/100 half |
| 4215 | */ |
| 4216 | if ((hw->phy.type == e1000_phy_igp_3 || |
| 4217 | hw->phy.type == e1000_phy_bm) && |
| 4218 | (hw->mac.autoneg == true) && |
| 4219 | (adapter->link_speed == SPEED_10 || |
| 4220 | adapter->link_speed == SPEED_100) && |
| 4221 | (adapter->link_duplex == HALF_DUPLEX)) { |
| 4222 | u16 autoneg_exp; |
| 4223 | |
| 4224 | e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp); |
| 4225 | |
| 4226 | if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS)) |
| 4227 | e_info("Autonegotiated half duplex but" |
| 4228 | " link partner cannot autoneg. " |
| 4229 | " Try forcing full duplex if " |
| 4230 | "link gets many collisions.\n"); |
| 4231 | } |
| 4232 | |
Emil Tantilov | f49c57e | 2010-03-24 12:55:02 +0000 | [diff] [blame] | 4233 | /* adjust timeout factor according to speed/duplex */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4234 | adapter->tx_timeout_factor = 1; |
| 4235 | switch (adapter->link_speed) { |
| 4236 | case SPEED_10: |
| 4237 | txb2b = 0; |
Bruce Allan | 10f1b49 | 2008-08-08 18:36:01 -0700 | [diff] [blame] | 4238 | adapter->tx_timeout_factor = 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4239 | break; |
| 4240 | case SPEED_100: |
| 4241 | txb2b = 0; |
Bruce Allan | 4c86e0b | 2009-11-19 12:35:26 +0000 | [diff] [blame] | 4242 | adapter->tx_timeout_factor = 10; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4243 | break; |
| 4244 | } |
| 4245 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4246 | /* |
| 4247 | * workaround: re-program speed mode bit after |
| 4248 | * link-up event |
| 4249 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4250 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
| 4251 | !txb2b) { |
| 4252 | u32 tarc0; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4253 | tarc0 = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4254 | tarc0 &= ~SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4255 | ew32(TARC(0), tarc0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4256 | } |
| 4257 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4258 | /* |
| 4259 | * disable TSO for pcie and 10/100 speeds, to avoid |
| 4260 | * some hardware issues |
| 4261 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4262 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
| 4263 | switch (adapter->link_speed) { |
| 4264 | case SPEED_10: |
| 4265 | case SPEED_100: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4266 | e_info("10/100 speed: disabling TSO\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4267 | netdev->features &= ~NETIF_F_TSO; |
| 4268 | netdev->features &= ~NETIF_F_TSO6; |
| 4269 | break; |
| 4270 | case SPEED_1000: |
| 4271 | netdev->features |= NETIF_F_TSO; |
| 4272 | netdev->features |= NETIF_F_TSO6; |
| 4273 | break; |
| 4274 | default: |
| 4275 | /* oops */ |
| 4276 | break; |
| 4277 | } |
| 4278 | } |
| 4279 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4280 | /* |
| 4281 | * enable transmits in the hardware, need to do this |
| 4282 | * after setting TARC(0) |
| 4283 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4284 | tctl = er32(TCTL); |
| 4285 | tctl |= E1000_TCTL_EN; |
| 4286 | ew32(TCTL, tctl); |
| 4287 | |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4288 | /* |
| 4289 | * Perform any post-link-up configuration before |
| 4290 | * reporting link up. |
| 4291 | */ |
| 4292 | if (phy->ops.cfg_on_link_up) |
| 4293 | phy->ops.cfg_on_link_up(hw); |
| 4294 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4295 | netif_carrier_on(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4296 | |
| 4297 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4298 | mod_timer(&adapter->phy_info_timer, |
| 4299 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4300 | } |
| 4301 | } else { |
| 4302 | if (netif_carrier_ok(netdev)) { |
| 4303 | adapter->link_speed = 0; |
| 4304 | adapter->link_duplex = 0; |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4305 | /* Link status message must follow this format */ |
| 4306 | printk(KERN_INFO "e1000e: %s NIC Link is Down\n", |
| 4307 | adapter->netdev->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4308 | netif_carrier_off(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4309 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4310 | mod_timer(&adapter->phy_info_timer, |
| 4311 | round_jiffies(jiffies + 2 * HZ)); |
| 4312 | |
| 4313 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) |
| 4314 | schedule_work(&adapter->reset_task); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4315 | else |
| 4316 | pm_schedule_suspend(netdev->dev.parent, |
| 4317 | LINK_TIMEOUT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4318 | } |
| 4319 | } |
| 4320 | |
| 4321 | link_up: |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4322 | spin_lock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4323 | e1000e_update_stats(adapter); |
| 4324 | |
| 4325 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 4326 | adapter->tpt_old = adapter->stats.tpt; |
| 4327 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; |
| 4328 | adapter->colc_old = adapter->stats.colc; |
| 4329 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4330 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
| 4331 | adapter->gorc_old = adapter->stats.gorc; |
| 4332 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; |
| 4333 | adapter->gotc_old = adapter->stats.gotc; |
Flavio Leitner | 2084b11 | 2011-04-05 04:27:43 +0000 | [diff] [blame] | 4334 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4335 | |
| 4336 | e1000e_update_adaptive(&adapter->hw); |
| 4337 | |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4338 | if (!netif_carrier_ok(netdev) && |
| 4339 | (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) { |
| 4340 | /* |
| 4341 | * We've lost link, so the controller stops DMA, |
| 4342 | * but we've got queued Tx work that's never going |
| 4343 | * to get done, so reset controller to flush Tx. |
| 4344 | * (Do the reset outside of interrupt context). |
| 4345 | */ |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4346 | schedule_work(&adapter->reset_task); |
| 4347 | /* return immediately since reset is imminent */ |
| 4348 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4349 | } |
| 4350 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4351 | /* Simple mode for Interrupt Throttle Rate (ITR) */ |
| 4352 | if (adapter->itr_setting == 4) { |
| 4353 | /* |
| 4354 | * Symmetric Tx/Rx gets a reduced ITR=2000; |
| 4355 | * Total asymmetrical Tx or Rx gets ITR=8000; |
| 4356 | * everyone else is between 2000-8000. |
| 4357 | */ |
| 4358 | u32 goc = (adapter->gotc + adapter->gorc) / 10000; |
| 4359 | u32 dif = (adapter->gotc > adapter->gorc ? |
| 4360 | adapter->gotc - adapter->gorc : |
| 4361 | adapter->gorc - adapter->gotc) / 10000; |
| 4362 | u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 4363 | |
| 4364 | ew32(ITR, 1000000000 / (itr * 256)); |
| 4365 | } |
| 4366 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4367 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4368 | if (adapter->msix_entries) |
| 4369 | ew32(ICS, adapter->rx_ring->ims_val); |
| 4370 | else |
| 4371 | ew32(ICS, E1000_ICS_RXDMT0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4372 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4373 | /* flush pending descriptors to memory before detecting Tx hang */ |
| 4374 | e1000e_flush_descriptors(adapter); |
| 4375 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4376 | /* Force detection of hung controller every watchdog period */ |
| 4377 | adapter->detect_tx_hung = 1; |
| 4378 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4379 | /* |
| 4380 | * With 82571 controllers, LAA may be overwritten due to controller |
| 4381 | * reset from the other port. Set the appropriate LAA in RAR[0] |
| 4382 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4383 | if (e1000e_get_laa_state_82571(hw)) |
| 4384 | e1000e_rar_set(hw, adapter->hw.mac.addr, 0); |
| 4385 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4386 | if (adapter->flags2 & FLAG2_CHECK_PHY_HANG) |
| 4387 | e1000e_check_82574_phy_workaround(adapter); |
| 4388 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4389 | /* Reset the timer */ |
| 4390 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4391 | mod_timer(&adapter->watchdog_timer, |
| 4392 | round_jiffies(jiffies + 2 * HZ)); |
| 4393 | } |
| 4394 | |
| 4395 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 4396 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 4397 | #define E1000_TX_FLAGS_TSO 0x00000004 |
| 4398 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
| 4399 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 4400 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 4401 | |
| 4402 | static int e1000_tso(struct e1000_adapter *adapter, |
| 4403 | struct sk_buff *skb) |
| 4404 | { |
| 4405 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4406 | struct e1000_context_desc *context_desc; |
| 4407 | struct e1000_buffer *buffer_info; |
| 4408 | unsigned int i; |
| 4409 | u32 cmd_length = 0; |
| 4410 | u16 ipcse = 0, tucse, mss; |
| 4411 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4412 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4413 | if (!skb_is_gso(skb)) |
| 4414 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4415 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4416 | if (skb_header_cloned(skb)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4417 | int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4418 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4419 | if (err) |
| 4420 | return err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4421 | } |
| 4422 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4423 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 4424 | mss = skb_shinfo(skb)->gso_size; |
| 4425 | if (skb->protocol == htons(ETH_P_IP)) { |
| 4426 | struct iphdr *iph = ip_hdr(skb); |
| 4427 | iph->tot_len = 0; |
| 4428 | iph->check = 0; |
| 4429 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, |
| 4430 | 0, IPPROTO_TCP, 0); |
| 4431 | cmd_length = E1000_TXD_CMD_IP; |
| 4432 | ipcse = skb_transport_offset(skb) - 1; |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 4433 | } else if (skb_is_gso_v6(skb)) { |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4434 | ipv6_hdr(skb)->payload_len = 0; |
| 4435 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 4436 | &ipv6_hdr(skb)->daddr, |
| 4437 | 0, IPPROTO_TCP, 0); |
| 4438 | ipcse = 0; |
| 4439 | } |
| 4440 | ipcss = skb_network_offset(skb); |
| 4441 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
| 4442 | tucss = skb_transport_offset(skb); |
| 4443 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
| 4444 | tucse = 0; |
| 4445 | |
| 4446 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
| 4447 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
| 4448 | |
| 4449 | i = tx_ring->next_to_use; |
| 4450 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 4451 | buffer_info = &tx_ring->buffer_info[i]; |
| 4452 | |
| 4453 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 4454 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 4455 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 4456 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 4457 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 4458 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 4459 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 4460 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 4461 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 4462 | |
| 4463 | buffer_info->time_stamp = jiffies; |
| 4464 | buffer_info->next_to_watch = i; |
| 4465 | |
| 4466 | i++; |
| 4467 | if (i == tx_ring->count) |
| 4468 | i = 0; |
| 4469 | tx_ring->next_to_use = i; |
| 4470 | |
| 4471 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 4475 | { |
| 4476 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4477 | struct e1000_context_desc *context_desc; |
| 4478 | struct e1000_buffer *buffer_info; |
| 4479 | unsigned int i; |
| 4480 | u8 css; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4481 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4482 | __be16 protocol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4483 | |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4484 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 4485 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4486 | |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4487 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) |
| 4488 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 4489 | else |
| 4490 | protocol = skb->protocol; |
| 4491 | |
Arthur Jones | 3f51839 | 2009-03-20 15:56:35 -0700 | [diff] [blame] | 4492 | switch (protocol) { |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4493 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4494 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 4495 | cmd_len |= E1000_TXD_CMD_TCP; |
| 4496 | break; |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4497 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4498 | /* XXX not handling all IPV6 headers */ |
| 4499 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 4500 | cmd_len |= E1000_TXD_CMD_TCP; |
| 4501 | break; |
| 4502 | default: |
| 4503 | if (unlikely(net_ratelimit())) |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4504 | e_warn("checksum_partial proto=%x!\n", |
| 4505 | be16_to_cpu(protocol)); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4506 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4507 | } |
| 4508 | |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 4509 | css = skb_checksum_start_offset(skb); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4510 | |
| 4511 | i = tx_ring->next_to_use; |
| 4512 | buffer_info = &tx_ring->buffer_info[i]; |
| 4513 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 4514 | |
| 4515 | context_desc->lower_setup.ip_config = 0; |
| 4516 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 4517 | context_desc->upper_setup.tcp_fields.tucso = |
| 4518 | css + skb->csum_offset; |
| 4519 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 4520 | context_desc->tcp_seg_setup.data = 0; |
| 4521 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 4522 | |
| 4523 | buffer_info->time_stamp = jiffies; |
| 4524 | buffer_info->next_to_watch = i; |
| 4525 | |
| 4526 | i++; |
| 4527 | if (i == tx_ring->count) |
| 4528 | i = 0; |
| 4529 | tx_ring->next_to_use = i; |
| 4530 | |
| 4531 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4532 | } |
| 4533 | |
| 4534 | #define E1000_MAX_PER_TXD 8192 |
| 4535 | #define E1000_MAX_TXD_PWR 12 |
| 4536 | |
| 4537 | static int e1000_tx_map(struct e1000_adapter *adapter, |
| 4538 | struct sk_buff *skb, unsigned int first, |
| 4539 | unsigned int max_per_txd, unsigned int nr_frags, |
| 4540 | unsigned int mss) |
| 4541 | { |
| 4542 | struct e1000_ring *tx_ring = adapter->tx_ring; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4543 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4544 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 4545 | unsigned int len = skb_headlen(skb); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4546 | unsigned int offset = 0, size, count = 0, i; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4547 | unsigned int f, bytecount, segs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4548 | |
| 4549 | i = tx_ring->next_to_use; |
| 4550 | |
| 4551 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4552 | buffer_info = &tx_ring->buffer_info[i]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4553 | size = min(len, max_per_txd); |
| 4554 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4555 | buffer_info->length = size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4556 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4557 | buffer_info->next_to_watch = i; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4558 | buffer_info->dma = dma_map_single(&pdev->dev, |
| 4559 | skb->data + offset, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4560 | size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4561 | buffer_info->mapped_as_page = false; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4562 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4563 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4564 | |
| 4565 | len -= size; |
| 4566 | offset += size; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4567 | count++; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4568 | |
| 4569 | if (len) { |
| 4570 | i++; |
| 4571 | if (i == tx_ring->count) |
| 4572 | i = 0; |
| 4573 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | for (f = 0; f < nr_frags; f++) { |
| 4577 | struct skb_frag_struct *frag; |
| 4578 | |
| 4579 | frag = &skb_shinfo(skb)->frags[f]; |
| 4580 | len = frag->size; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4581 | offset = frag->page_offset; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4582 | |
| 4583 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4584 | i++; |
| 4585 | if (i == tx_ring->count) |
| 4586 | i = 0; |
| 4587 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4588 | buffer_info = &tx_ring->buffer_info[i]; |
| 4589 | size = min(len, max_per_txd); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4590 | |
| 4591 | buffer_info->length = size; |
| 4592 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4593 | buffer_info->next_to_watch = i; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4594 | buffer_info->dma = dma_map_page(&pdev->dev, frag->page, |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4595 | offset, size, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4596 | DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4597 | buffer_info->mapped_as_page = true; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4598 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4599 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4600 | |
| 4601 | len -= size; |
| 4602 | offset += size; |
| 4603 | count++; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4604 | } |
| 4605 | } |
| 4606 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4607 | segs = skb_shinfo(skb)->gso_segs ? : 1; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4608 | /* multiply data chunks by size of headers */ |
| 4609 | bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len; |
| 4610 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4611 | tx_ring->buffer_info[i].skb = skb; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4612 | tx_ring->buffer_info[i].segs = segs; |
| 4613 | tx_ring->buffer_info[i].bytecount = bytecount; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4614 | tx_ring->buffer_info[first].next_to_watch = i; |
| 4615 | |
| 4616 | return count; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4617 | |
| 4618 | dma_error: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4619 | dev_err(&pdev->dev, "Tx DMA map failed\n"); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4620 | buffer_info->dma = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4621 | if (count) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4622 | count--; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4623 | |
| 4624 | while (count--) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4625 | if (i == 0) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4626 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4627 | i--; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4628 | buffer_info = &tx_ring->buffer_info[i]; |
Joe Perches | 1d51c41 | 2010-11-14 17:04:32 +0000 | [diff] [blame] | 4629 | e1000_put_txbuf(adapter, buffer_info); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | static void e1000_tx_queue(struct e1000_adapter *adapter, |
| 4636 | int tx_flags, int count) |
| 4637 | { |
| 4638 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4639 | struct e1000_tx_desc *tx_desc = NULL; |
| 4640 | struct e1000_buffer *buffer_info; |
| 4641 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 4642 | unsigned int i; |
| 4643 | |
| 4644 | if (tx_flags & E1000_TX_FLAGS_TSO) { |
| 4645 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 4646 | E1000_TXD_CMD_TSE; |
| 4647 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 4648 | |
| 4649 | if (tx_flags & E1000_TX_FLAGS_IPV4) |
| 4650 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
| 4651 | } |
| 4652 | |
| 4653 | if (tx_flags & E1000_TX_FLAGS_CSUM) { |
| 4654 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 4655 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 4656 | } |
| 4657 | |
| 4658 | if (tx_flags & E1000_TX_FLAGS_VLAN) { |
| 4659 | txd_lower |= E1000_TXD_CMD_VLE; |
| 4660 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 4661 | } |
| 4662 | |
| 4663 | i = tx_ring->next_to_use; |
| 4664 | |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 4665 | do { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4666 | buffer_info = &tx_ring->buffer_info[i]; |
| 4667 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 4668 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4669 | tx_desc->lower.data = |
| 4670 | cpu_to_le32(txd_lower | buffer_info->length); |
| 4671 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
| 4672 | |
| 4673 | i++; |
| 4674 | if (i == tx_ring->count) |
| 4675 | i = 0; |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 4676 | } while (--count > 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4677 | |
| 4678 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 4679 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4680 | /* |
| 4681 | * Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4682 | * know there are new descriptors to fetch. (Only |
| 4683 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4684 | * such as IA-64). |
| 4685 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4686 | wmb(); |
| 4687 | |
| 4688 | tx_ring->next_to_use = i; |
| 4689 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4690 | /* |
| 4691 | * we need this if more than one processor can write to our tail |
| 4692 | * at a time, it synchronizes IO on IA64/Altix systems |
| 4693 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4694 | mmiowb(); |
| 4695 | } |
| 4696 | |
| 4697 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 4698 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 4699 | struct sk_buff *skb) |
| 4700 | { |
| 4701 | struct e1000_hw *hw = &adapter->hw; |
| 4702 | u16 length, offset; |
| 4703 | |
| 4704 | if (vlan_tx_tag_present(skb)) { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 4705 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
| 4706 | (adapter->hw.mng_cookie.status & |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4707 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) |
| 4708 | return 0; |
| 4709 | } |
| 4710 | |
| 4711 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) |
| 4712 | return 0; |
| 4713 | |
| 4714 | if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP)) |
| 4715 | return 0; |
| 4716 | |
| 4717 | { |
| 4718 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14); |
| 4719 | struct udphdr *udp; |
| 4720 | |
| 4721 | if (ip->protocol != IPPROTO_UDP) |
| 4722 | return 0; |
| 4723 | |
| 4724 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 4725 | if (ntohs(udp->dest) != 67) |
| 4726 | return 0; |
| 4727 | |
| 4728 | offset = (u8 *)udp + 8 - skb->data; |
| 4729 | length = skb->len - offset; |
| 4730 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); |
| 4731 | } |
| 4732 | |
| 4733 | return 0; |
| 4734 | } |
| 4735 | |
| 4736 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 4737 | { |
| 4738 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4739 | |
| 4740 | netif_stop_queue(netdev); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4741 | /* |
| 4742 | * Herbert's original patch had: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4743 | * smp_mb__after_netif_stop_queue(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4744 | * but since that doesn't exist yet, just open code it. |
| 4745 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4746 | smp_mb(); |
| 4747 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4748 | /* |
| 4749 | * We need to check again in a case another CPU has just |
| 4750 | * made room available. |
| 4751 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4752 | if (e1000_desc_unused(adapter->tx_ring) < size) |
| 4753 | return -EBUSY; |
| 4754 | |
| 4755 | /* A reprieve! */ |
| 4756 | netif_start_queue(netdev); |
| 4757 | ++adapter->restart_queue; |
| 4758 | return 0; |
| 4759 | } |
| 4760 | |
| 4761 | static int e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 4762 | { |
| 4763 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4764 | |
| 4765 | if (e1000_desc_unused(adapter->tx_ring) >= size) |
| 4766 | return 0; |
| 4767 | return __e1000_maybe_stop_tx(netdev, size); |
| 4768 | } |
| 4769 | |
| 4770 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 4771 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 4772 | struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4773 | { |
| 4774 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4775 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4776 | unsigned int first; |
| 4777 | unsigned int max_per_txd = E1000_MAX_PER_TXD; |
| 4778 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 4779 | unsigned int tx_flags = 0; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 4780 | unsigned int len = skb_headlen(skb); |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 4781 | unsigned int nr_frags; |
| 4782 | unsigned int mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4783 | int count = 0; |
| 4784 | int tso; |
| 4785 | unsigned int f; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4786 | |
| 4787 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 4788 | dev_kfree_skb_any(skb); |
| 4789 | return NETDEV_TX_OK; |
| 4790 | } |
| 4791 | |
| 4792 | if (skb->len <= 0) { |
| 4793 | dev_kfree_skb_any(skb); |
| 4794 | return NETDEV_TX_OK; |
| 4795 | } |
| 4796 | |
| 4797 | mss = skb_shinfo(skb)->gso_size; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4798 | /* |
| 4799 | * The controller does a simple calculation to |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4800 | * make sure there is enough room in the FIFO before |
| 4801 | * initiating the DMA for each buffer. The calc is: |
| 4802 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 4803 | * overrun the FIFO, adjust the max buffer len if mss |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4804 | * drops. |
| 4805 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4806 | if (mss) { |
| 4807 | u8 hdr_len; |
| 4808 | max_per_txd = min(mss << 2, max_per_txd); |
| 4809 | max_txd_pwr = fls(max_per_txd) - 1; |
| 4810 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4811 | /* |
| 4812 | * TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 4813 | * points to just header, pull a few bytes of payload from |
| 4814 | * frags into skb->data |
| 4815 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4816 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4817 | /* |
| 4818 | * we do this workaround for ES2LAN, but it is un-necessary, |
| 4819 | * avoiding it could save a lot of cycles |
| 4820 | */ |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 4821 | if (skb->data_len && (hdr_len == len)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4822 | unsigned int pull_size; |
| 4823 | |
| 4824 | pull_size = min((unsigned int)4, skb->data_len); |
| 4825 | if (!__pskb_pull_tail(skb, pull_size)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4826 | e_err("__pskb_pull_tail failed.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4827 | dev_kfree_skb_any(skb); |
| 4828 | return NETDEV_TX_OK; |
| 4829 | } |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 4830 | len = skb_headlen(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4831 | } |
| 4832 | } |
| 4833 | |
| 4834 | /* reserve a descriptor for the offload context */ |
| 4835 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 4836 | count++; |
| 4837 | count++; |
| 4838 | |
| 4839 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 4840 | |
| 4841 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 4842 | for (f = 0; f < nr_frags; f++) |
| 4843 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 4844 | max_txd_pwr); |
| 4845 | |
| 4846 | if (adapter->hw.mac.tx_pkt_filtering) |
| 4847 | e1000_transfer_dhcp_info(adapter, skb); |
| 4848 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4849 | /* |
| 4850 | * need: count + 2 desc gap to keep tail from touching |
| 4851 | * head, otherwise try next time |
| 4852 | */ |
Jesse Brandeburg | 92af3e9 | 2009-01-19 14:17:08 +0000 | [diff] [blame] | 4853 | if (e1000_maybe_stop_tx(netdev, count + 2)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4854 | return NETDEV_TX_BUSY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4855 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 4856 | if (vlan_tx_tag_present(skb)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4857 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 4858 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 4859 | } |
| 4860 | |
| 4861 | first = tx_ring->next_to_use; |
| 4862 | |
| 4863 | tso = e1000_tso(adapter, skb); |
| 4864 | if (tso < 0) { |
| 4865 | dev_kfree_skb_any(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4866 | return NETDEV_TX_OK; |
| 4867 | } |
| 4868 | |
| 4869 | if (tso) |
| 4870 | tx_flags |= E1000_TX_FLAGS_TSO; |
| 4871 | else if (e1000_tx_csum(adapter, skb)) |
| 4872 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 4873 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4874 | /* |
| 4875 | * 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] | 4876 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4877 | * no longer assume, we must. |
| 4878 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4879 | if (skb->protocol == htons(ETH_P_IP)) |
| 4880 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 4881 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4882 | /* if count is 0 then mapping error has occurred */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4883 | 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] | 4884 | if (count) { |
| 4885 | e1000_tx_queue(adapter, tx_flags, count); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4886 | /* Make sure there is space in the ring for the next send. */ |
| 4887 | e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2); |
| 4888 | |
| 4889 | } else { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4890 | dev_kfree_skb_any(skb); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4891 | tx_ring->buffer_info[first].time_stamp = 0; |
| 4892 | tx_ring->next_to_use = first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4893 | } |
| 4894 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4895 | return NETDEV_TX_OK; |
| 4896 | } |
| 4897 | |
| 4898 | /** |
| 4899 | * e1000_tx_timeout - Respond to a Tx Hang |
| 4900 | * @netdev: network interface device structure |
| 4901 | **/ |
| 4902 | static void e1000_tx_timeout(struct net_device *netdev) |
| 4903 | { |
| 4904 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4905 | |
| 4906 | /* Do the reset outside of interrupt context */ |
| 4907 | adapter->tx_timeout_count++; |
| 4908 | schedule_work(&adapter->reset_task); |
| 4909 | } |
| 4910 | |
| 4911 | static void e1000_reset_task(struct work_struct *work) |
| 4912 | { |
| 4913 | struct e1000_adapter *adapter; |
| 4914 | adapter = container_of(work, struct e1000_adapter, reset_task); |
| 4915 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4916 | /* don't run the task if already down */ |
| 4917 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4918 | return; |
| 4919 | |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 4920 | if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 4921 | (adapter->flags & FLAG_RX_RESTART_NOW))) { |
| 4922 | e1000e_dump(adapter); |
| 4923 | e_err("Reset adapter\n"); |
| 4924 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4925 | e1000e_reinit_locked(adapter); |
| 4926 | } |
| 4927 | |
| 4928 | /** |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4929 | * e1000_get_stats64 - Get System Network Statistics |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4930 | * @netdev: network interface device structure |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4931 | * @stats: rtnl_link_stats64 pointer |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4932 | * |
| 4933 | * Returns the address of the device statistics structure. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4934 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4935 | struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev, |
| 4936 | struct rtnl_link_stats64 *stats) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4937 | { |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4938 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4939 | |
| 4940 | memset(stats, 0, sizeof(struct rtnl_link_stats64)); |
| 4941 | spin_lock(&adapter->stats64_lock); |
| 4942 | e1000e_update_stats(adapter); |
| 4943 | /* Fill out the OS statistics structure */ |
| 4944 | stats->rx_bytes = adapter->stats.gorc; |
| 4945 | stats->rx_packets = adapter->stats.gprc; |
| 4946 | stats->tx_bytes = adapter->stats.gotc; |
| 4947 | stats->tx_packets = adapter->stats.gptc; |
| 4948 | stats->multicast = adapter->stats.mprc; |
| 4949 | stats->collisions = adapter->stats.colc; |
| 4950 | |
| 4951 | /* Rx Errors */ |
| 4952 | |
| 4953 | /* |
| 4954 | * RLEC on some newer hardware can be incorrect so build |
| 4955 | * our own version based on RUC and ROC |
| 4956 | */ |
| 4957 | stats->rx_errors = adapter->stats.rxerrc + |
| 4958 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 4959 | adapter->stats.ruc + adapter->stats.roc + |
| 4960 | adapter->stats.cexterr; |
| 4961 | stats->rx_length_errors = adapter->stats.ruc + |
| 4962 | adapter->stats.roc; |
| 4963 | stats->rx_crc_errors = adapter->stats.crcerrs; |
| 4964 | stats->rx_frame_errors = adapter->stats.algnerrc; |
| 4965 | stats->rx_missed_errors = adapter->stats.mpc; |
| 4966 | |
| 4967 | /* Tx Errors */ |
| 4968 | stats->tx_errors = adapter->stats.ecol + |
| 4969 | adapter->stats.latecol; |
| 4970 | stats->tx_aborted_errors = adapter->stats.ecol; |
| 4971 | stats->tx_window_errors = adapter->stats.latecol; |
| 4972 | stats->tx_carrier_errors = adapter->stats.tncrs; |
| 4973 | |
| 4974 | /* Tx Dropped needs to be maintained elsewhere */ |
| 4975 | |
| 4976 | spin_unlock(&adapter->stats64_lock); |
| 4977 | return stats; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | /** |
| 4981 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 4982 | * @netdev: network interface device structure |
| 4983 | * @new_mtu: new value for maximum frame size |
| 4984 | * |
| 4985 | * Returns 0 on success, negative on failure |
| 4986 | **/ |
| 4987 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 4988 | { |
| 4989 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4990 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4991 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 4992 | /* Jumbo frame support */ |
| 4993 | if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) && |
| 4994 | !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
| 4995 | e_err("Jumbo Frames not supported.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4996 | return -EINVAL; |
| 4997 | } |
| 4998 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 4999 | /* Supported frame sizes */ |
| 5000 | if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) || |
| 5001 | (max_frame > adapter->max_hw_frame_size)) { |
| 5002 | e_err("Unsupported MTU setting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5003 | return -EINVAL; |
| 5004 | } |
| 5005 | |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 5006 | /* Jumbo frame workaround on 82579 requires CRC be stripped */ |
| 5007 | if ((adapter->hw.mac.type == e1000_pch2lan) && |
| 5008 | !(adapter->flags2 & FLAG2_CRC_STRIPPING) && |
| 5009 | (new_mtu > ETH_DATA_LEN)) { |
| 5010 | e_err("Jumbo Frames not supported on 82579 when CRC " |
| 5011 | "stripping is disabled.\n"); |
| 5012 | return -EINVAL; |
| 5013 | } |
| 5014 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5015 | /* 82573 Errata 17 */ |
| 5016 | if (((adapter->hw.mac.type == e1000_82573) || |
| 5017 | (adapter->hw.mac.type == e1000_82574)) && |
| 5018 | (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) { |
| 5019 | adapter->flags2 |= FLAG2_DISABLE_ASPM_L1; |
| 5020 | e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1); |
| 5021 | } |
| 5022 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5023 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 5024 | usleep_range(1000, 2000); |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5025 | /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5026 | adapter->max_frame_size = max_frame; |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5027 | e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
| 5028 | netdev->mtu = new_mtu; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5029 | if (netif_running(netdev)) |
| 5030 | e1000e_down(adapter); |
| 5031 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5032 | /* |
| 5033 | * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5034 | * means we reserve 2 more, this pushes us to allocate from the next |
| 5035 | * larger slab size. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5036 | * i.e. RXBUFFER_2048 --> size-4096 slab |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5037 | * However with the new *_jumbo_rx* routines, jumbo receives will use |
| 5038 | * fragmented skbs |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5039 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5040 | |
Jesse Brandeburg | 9926146 | 2010-01-22 22:56:16 +0000 | [diff] [blame] | 5041 | if (max_frame <= 2048) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5042 | adapter->rx_buffer_len = 2048; |
| 5043 | else |
| 5044 | adapter->rx_buffer_len = 4096; |
| 5045 | |
| 5046 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
| 5047 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || |
| 5048 | (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) |
| 5049 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5050 | + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5051 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5052 | if (netif_running(netdev)) |
| 5053 | e1000e_up(adapter); |
| 5054 | else |
| 5055 | e1000e_reset(adapter); |
| 5056 | |
| 5057 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 5058 | |
| 5059 | return 0; |
| 5060 | } |
| 5061 | |
| 5062 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 5063 | int cmd) |
| 5064 | { |
| 5065 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5066 | struct mii_ioctl_data *data = if_mii(ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5067 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5068 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5069 | return -EOPNOTSUPP; |
| 5070 | |
| 5071 | switch (cmd) { |
| 5072 | case SIOCGMIIPHY: |
| 5073 | data->phy_id = adapter->hw.phy.addr; |
| 5074 | break; |
| 5075 | case SIOCGMIIREG: |
Bruce Allan | b16a002 | 2009-11-20 23:24:30 +0000 | [diff] [blame] | 5076 | e1000_phy_read_status(adapter); |
| 5077 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5078 | switch (data->reg_num & 0x1F) { |
| 5079 | case MII_BMCR: |
| 5080 | data->val_out = adapter->phy_regs.bmcr; |
| 5081 | break; |
| 5082 | case MII_BMSR: |
| 5083 | data->val_out = adapter->phy_regs.bmsr; |
| 5084 | break; |
| 5085 | case MII_PHYSID1: |
| 5086 | data->val_out = (adapter->hw.phy.id >> 16); |
| 5087 | break; |
| 5088 | case MII_PHYSID2: |
| 5089 | data->val_out = (adapter->hw.phy.id & 0xFFFF); |
| 5090 | break; |
| 5091 | case MII_ADVERTISE: |
| 5092 | data->val_out = adapter->phy_regs.advertise; |
| 5093 | break; |
| 5094 | case MII_LPA: |
| 5095 | data->val_out = adapter->phy_regs.lpa; |
| 5096 | break; |
| 5097 | case MII_EXPANSION: |
| 5098 | data->val_out = adapter->phy_regs.expansion; |
| 5099 | break; |
| 5100 | case MII_CTRL1000: |
| 5101 | data->val_out = adapter->phy_regs.ctrl1000; |
| 5102 | break; |
| 5103 | case MII_STAT1000: |
| 5104 | data->val_out = adapter->phy_regs.stat1000; |
| 5105 | break; |
| 5106 | case MII_ESTATUS: |
| 5107 | data->val_out = adapter->phy_regs.estatus; |
| 5108 | break; |
| 5109 | default: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5110 | return -EIO; |
| 5111 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5112 | break; |
| 5113 | case SIOCSMIIREG: |
| 5114 | default: |
| 5115 | return -EOPNOTSUPP; |
| 5116 | } |
| 5117 | return 0; |
| 5118 | } |
| 5119 | |
| 5120 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 5121 | { |
| 5122 | switch (cmd) { |
| 5123 | case SIOCGMIIPHY: |
| 5124 | case SIOCGMIIREG: |
| 5125 | case SIOCSMIIREG: |
| 5126 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 5127 | default: |
| 5128 | return -EOPNOTSUPP; |
| 5129 | } |
| 5130 | } |
| 5131 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5132 | static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) |
| 5133 | { |
| 5134 | struct e1000_hw *hw = &adapter->hw; |
| 5135 | u32 i, mac_reg; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5136 | u16 phy_reg, wuc_enable; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5137 | int retval = 0; |
| 5138 | |
| 5139 | /* copy MAC RARs to PHY RARs */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 5140 | e1000_copy_rx_addrs_to_phy_ich8lan(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5141 | |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5142 | retval = hw->phy.ops.acquire(hw); |
| 5143 | if (retval) { |
| 5144 | e_err("Could not acquire PHY\n"); |
| 5145 | return retval; |
| 5146 | } |
| 5147 | |
| 5148 | /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */ |
| 5149 | retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
| 5150 | if (retval) |
| 5151 | goto out; |
| 5152 | |
| 5153 | /* copy MAC MTA to PHY MTA - only needed for pchlan */ |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5154 | for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { |
| 5155 | mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5156 | hw->phy.ops.write_reg_page(hw, BM_MTA(i), |
| 5157 | (u16)(mac_reg & 0xFFFF)); |
| 5158 | hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1, |
| 5159 | (u16)((mac_reg >> 16) & 0xFFFF)); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | /* configure PHY Rx Control register */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5163 | hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5164 | mac_reg = er32(RCTL); |
| 5165 | if (mac_reg & E1000_RCTL_UPE) |
| 5166 | phy_reg |= BM_RCTL_UPE; |
| 5167 | if (mac_reg & E1000_RCTL_MPE) |
| 5168 | phy_reg |= BM_RCTL_MPE; |
| 5169 | phy_reg &= ~(BM_RCTL_MO_MASK); |
| 5170 | if (mac_reg & E1000_RCTL_MO_3) |
| 5171 | phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) |
| 5172 | << BM_RCTL_MO_SHIFT); |
| 5173 | if (mac_reg & E1000_RCTL_BAM) |
| 5174 | phy_reg |= BM_RCTL_BAM; |
| 5175 | if (mac_reg & E1000_RCTL_PMCF) |
| 5176 | phy_reg |= BM_RCTL_PMCF; |
| 5177 | mac_reg = er32(CTRL); |
| 5178 | if (mac_reg & E1000_CTRL_RFCE) |
| 5179 | phy_reg |= BM_RCTL_RFCE; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5180 | hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5181 | |
| 5182 | /* enable PHY wakeup in MAC register */ |
| 5183 | ew32(WUFC, wufc); |
| 5184 | ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN); |
| 5185 | |
| 5186 | /* configure and enable PHY wakeup in PHY registers */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5187 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc); |
| 5188 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5189 | |
| 5190 | /* activate PHY wakeup */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5191 | wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; |
| 5192 | retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5193 | if (retval) |
| 5194 | e_err("Could not set PHY Host Wakeup bit\n"); |
| 5195 | out: |
Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 5196 | hw->phy.ops.release(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5197 | |
| 5198 | return retval; |
| 5199 | } |
| 5200 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5201 | static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake, |
| 5202 | bool runtime) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5203 | { |
| 5204 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5205 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5206 | struct e1000_hw *hw = &adapter->hw; |
| 5207 | u32 ctrl, ctrl_ext, rctl, status; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5208 | /* Runtime suspend should only enable wakeup for link changes */ |
| 5209 | u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5210 | int retval = 0; |
| 5211 | |
| 5212 | netif_device_detach(netdev); |
| 5213 | |
| 5214 | if (netif_running(netdev)) { |
| 5215 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 5216 | e1000e_down(adapter); |
| 5217 | e1000_free_irq(adapter); |
| 5218 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5219 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5220 | |
| 5221 | retval = pci_save_state(pdev); |
| 5222 | if (retval) |
| 5223 | return retval; |
| 5224 | |
| 5225 | status = er32(STATUS); |
| 5226 | if (status & E1000_STATUS_LU) |
| 5227 | wufc &= ~E1000_WUFC_LNKC; |
| 5228 | |
| 5229 | if (wufc) { |
| 5230 | e1000_setup_rctl(adapter); |
| 5231 | e1000_set_multi(netdev); |
| 5232 | |
| 5233 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5234 | if (wufc & E1000_WUFC_MC) { |
| 5235 | rctl = er32(RCTL); |
| 5236 | rctl |= E1000_RCTL_MPE; |
| 5237 | ew32(RCTL, rctl); |
| 5238 | } |
| 5239 | |
| 5240 | ctrl = er32(CTRL); |
| 5241 | /* advertise wake from D3Cold */ |
| 5242 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5243 | /* phy power management enable */ |
| 5244 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5245 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 5246 | if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) |
| 5247 | ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5248 | ew32(CTRL, ctrl); |
| 5249 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5250 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
| 5251 | adapter->hw.phy.media_type == |
| 5252 | e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5253 | /* keep the laser running in D3 */ |
| 5254 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | 93a23f4 | 2009-12-08 07:27:41 +0000 | [diff] [blame] | 5255 | ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5256 | ew32(CTRL_EXT, ctrl_ext); |
| 5257 | } |
| 5258 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5259 | if (adapter->flags & FLAG_IS_ICH) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5260 | e1000_suspend_workarounds_ich8lan(&adapter->hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5261 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5262 | /* Allow time for pending master requests to run */ |
| 5263 | e1000e_disable_pcie_master(&adapter->hw); |
| 5264 | |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5265 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5266 | /* enable wakeup by the PHY */ |
| 5267 | retval = e1000_init_phy_wakeup(adapter, wufc); |
| 5268 | if (retval) |
| 5269 | return retval; |
| 5270 | } else { |
| 5271 | /* enable wakeup by the MAC */ |
| 5272 | ew32(WUFC, wufc); |
| 5273 | ew32(WUC, E1000_WUC_PME_EN); |
| 5274 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5275 | } else { |
| 5276 | ew32(WUC, 0); |
| 5277 | ew32(WUFC, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5278 | } |
| 5279 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5280 | *enable_wake = !!wufc; |
| 5281 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5282 | /* make sure adapter isn't asleep if manageability is enabled */ |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5283 | if ((adapter->flags & FLAG_MNG_PT_ENABLED) || |
| 5284 | (hw->mac.ops.check_mng_mode(hw))) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5285 | *enable_wake = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5286 | |
| 5287 | if (adapter->hw.phy.type == e1000_phy_igp_3) |
| 5288 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
| 5289 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5290 | /* |
| 5291 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5292 | * would have already happened in close and is redundant. |
| 5293 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5294 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5295 | |
| 5296 | pci_disable_device(pdev); |
| 5297 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5298 | return 0; |
| 5299 | } |
| 5300 | |
| 5301 | static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake) |
| 5302 | { |
| 5303 | if (sleep && wake) { |
| 5304 | pci_prepare_to_sleep(pdev); |
| 5305 | return; |
| 5306 | } |
| 5307 | |
| 5308 | pci_wake_from_d3(pdev, wake); |
| 5309 | pci_set_power_state(pdev, PCI_D3hot); |
| 5310 | } |
| 5311 | |
| 5312 | static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, |
| 5313 | bool wake) |
| 5314 | { |
| 5315 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5316 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5317 | |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5318 | /* |
| 5319 | * The pci-e switch on some quad port adapters will report a |
| 5320 | * correctable error when the MAC transitions from D0 to D3. To |
| 5321 | * prevent this we need to mask off the correctable errors on the |
| 5322 | * downstream port of the pci-e switch. |
| 5323 | */ |
| 5324 | if (adapter->flags & FLAG_IS_QUAD_PORT) { |
| 5325 | struct pci_dev *us_dev = pdev->bus->self; |
Jon Mason | 353064d | 2011-06-27 07:43:47 +0000 | [diff] [blame] | 5326 | int pos = pci_pcie_cap(us_dev); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5327 | u16 devctl; |
| 5328 | |
| 5329 | pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl); |
| 5330 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, |
| 5331 | (devctl & ~PCI_EXP_DEVCTL_CERE)); |
| 5332 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5333 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5334 | |
| 5335 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl); |
| 5336 | } else { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5337 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5338 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5339 | } |
| 5340 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5341 | #ifdef CONFIG_PCIEASPM |
| 5342 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
| 5343 | { |
Yinghai Lu | 9f728f5 | 2011-05-12 17:11:47 -0700 | [diff] [blame] | 5344 | pci_disable_link_state_locked(pdev, state); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5345 | } |
| 5346 | #else |
| 5347 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5348 | { |
| 5349 | int pos; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5350 | u16 reg16; |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5351 | |
| 5352 | /* |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5353 | * Both device and parent should have the same ASPM setting. |
| 5354 | * Disable ASPM in downstream component first and then upstream. |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5355 | */ |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5356 | pos = pci_pcie_cap(pdev); |
| 5357 | pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16); |
| 5358 | reg16 &= ~state; |
| 5359 | pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16); |
| 5360 | |
Anton Blanchard | 0c75ba2 | 2010-04-28 21:46:06 +0000 | [diff] [blame] | 5361 | if (!pdev->bus->self) |
| 5362 | return; |
| 5363 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5364 | pos = pci_pcie_cap(pdev->bus->self); |
| 5365 | pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, ®16); |
| 5366 | reg16 &= ~state; |
| 5367 | pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16); |
| 5368 | } |
| 5369 | #endif |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5370 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5371 | { |
| 5372 | dev_info(&pdev->dev, "Disabling ASPM %s %s\n", |
| 5373 | (state & PCIE_LINK_STATE_L0S) ? "L0s" : "", |
| 5374 | (state & PCIE_LINK_STATE_L1) ? "L1" : ""); |
| 5375 | |
| 5376 | __e1000e_disable_aspm(pdev, state); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5377 | } |
| 5378 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 5379 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5380 | static bool e1000e_pm_ready(struct e1000_adapter *adapter) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5381 | { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5382 | return !!adapter->tx_ring->buffer_info; |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5383 | } |
| 5384 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5385 | static int __e1000_resume(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5386 | { |
| 5387 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5388 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5389 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5390 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5391 | u32 err; |
| 5392 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5393 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5394 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
| 5395 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
| 5396 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5397 | if (aspm_disable_flag) |
| 5398 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 5399 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5400 | pci_set_power_state(pdev, PCI_D0); |
| 5401 | pci_restore_state(pdev); |
Bruce Allan | 28b8f04 | 2010-01-07 16:30:56 +0000 | [diff] [blame] | 5402 | pci_save_state(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5403 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5404 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5405 | if (netif_running(netdev)) { |
| 5406 | err = e1000_request_irq(adapter); |
| 5407 | if (err) |
| 5408 | return err; |
| 5409 | } |
| 5410 | |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5411 | if (hw->mac.type == e1000_pch2lan) |
| 5412 | e1000_resume_workarounds_pchlan(&adapter->hw); |
| 5413 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5414 | e1000e_power_up_phy(adapter); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5415 | |
| 5416 | /* report the system wakeup cause from S3/S4 */ |
| 5417 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
| 5418 | u16 phy_data; |
| 5419 | |
| 5420 | e1e_rphy(&adapter->hw, BM_WUS, &phy_data); |
| 5421 | if (phy_data) { |
| 5422 | e_info("PHY Wakeup cause - %s\n", |
| 5423 | phy_data & E1000_WUS_EX ? "Unicast Packet" : |
| 5424 | phy_data & E1000_WUS_MC ? "Multicast Packet" : |
| 5425 | phy_data & E1000_WUS_BC ? "Broadcast Packet" : |
| 5426 | phy_data & E1000_WUS_MAG ? "Magic Packet" : |
| 5427 | phy_data & E1000_WUS_LNKC ? "Link Status " |
| 5428 | " Change" : "other"); |
| 5429 | } |
| 5430 | e1e_wphy(&adapter->hw, BM_WUS, ~0); |
| 5431 | } else { |
| 5432 | u32 wus = er32(WUS); |
| 5433 | if (wus) { |
| 5434 | e_info("MAC Wakeup cause - %s\n", |
| 5435 | wus & E1000_WUS_EX ? "Unicast Packet" : |
| 5436 | wus & E1000_WUS_MC ? "Multicast Packet" : |
| 5437 | wus & E1000_WUS_BC ? "Broadcast Packet" : |
| 5438 | wus & E1000_WUS_MAG ? "Magic Packet" : |
| 5439 | wus & E1000_WUS_LNKC ? "Link Status Change" : |
| 5440 | "other"); |
| 5441 | } |
| 5442 | ew32(WUS, ~0); |
| 5443 | } |
| 5444 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5445 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5446 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 5447 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5448 | |
| 5449 | if (netif_running(netdev)) |
| 5450 | e1000e_up(adapter); |
| 5451 | |
| 5452 | netif_device_attach(netdev); |
| 5453 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5454 | /* |
| 5455 | * 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] | 5456 | * 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] | 5457 | * under the control of the driver. |
| 5458 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5459 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5460 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5461 | |
| 5462 | return 0; |
| 5463 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5464 | |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5465 | #ifdef CONFIG_PM_SLEEP |
| 5466 | static int e1000_suspend(struct device *dev) |
| 5467 | { |
| 5468 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5469 | int retval; |
| 5470 | bool wake; |
| 5471 | |
| 5472 | retval = __e1000_shutdown(pdev, &wake, false); |
| 5473 | if (!retval) |
| 5474 | e1000_complete_shutdown(pdev, true, wake); |
| 5475 | |
| 5476 | return retval; |
| 5477 | } |
| 5478 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5479 | static int e1000_resume(struct device *dev) |
| 5480 | { |
| 5481 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5482 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5483 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5484 | |
| 5485 | if (e1000e_pm_ready(adapter)) |
| 5486 | adapter->idle_check = true; |
| 5487 | |
| 5488 | return __e1000_resume(pdev); |
| 5489 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5490 | #endif /* CONFIG_PM_SLEEP */ |
| 5491 | |
| 5492 | #ifdef CONFIG_PM_RUNTIME |
| 5493 | static int e1000_runtime_suspend(struct device *dev) |
| 5494 | { |
| 5495 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5496 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5497 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5498 | |
| 5499 | if (e1000e_pm_ready(adapter)) { |
| 5500 | bool wake; |
| 5501 | |
| 5502 | __e1000_shutdown(pdev, &wake, true); |
| 5503 | } |
| 5504 | |
| 5505 | return 0; |
| 5506 | } |
| 5507 | |
| 5508 | static int e1000_idle(struct device *dev) |
| 5509 | { |
| 5510 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5511 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5512 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5513 | |
| 5514 | if (!e1000e_pm_ready(adapter)) |
| 5515 | return 0; |
| 5516 | |
| 5517 | if (adapter->idle_check) { |
| 5518 | adapter->idle_check = false; |
| 5519 | if (!e1000e_has_link(adapter)) |
| 5520 | pm_schedule_suspend(dev, MSEC_PER_SEC); |
| 5521 | } |
| 5522 | |
| 5523 | return -EBUSY; |
| 5524 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5525 | |
| 5526 | static int e1000_runtime_resume(struct device *dev) |
| 5527 | { |
| 5528 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5529 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5530 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5531 | |
| 5532 | if (!e1000e_pm_ready(adapter)) |
| 5533 | return 0; |
| 5534 | |
| 5535 | adapter->idle_check = !dev->power.runtime_auto; |
| 5536 | return __e1000_resume(pdev); |
| 5537 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5538 | #endif /* CONFIG_PM_RUNTIME */ |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 5539 | #endif /* CONFIG_PM */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5540 | |
| 5541 | static void e1000_shutdown(struct pci_dev *pdev) |
| 5542 | { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5543 | bool wake = false; |
| 5544 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5545 | __e1000_shutdown(pdev, &wake, false); |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5546 | |
| 5547 | if (system_state == SYSTEM_POWER_OFF) |
| 5548 | e1000_complete_shutdown(pdev, false, wake); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5549 | } |
| 5550 | |
| 5551 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5552 | |
| 5553 | static irqreturn_t e1000_intr_msix(int irq, void *data) |
| 5554 | { |
| 5555 | struct net_device *netdev = data; |
| 5556 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5557 | |
| 5558 | if (adapter->msix_entries) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 5559 | int vector, msix_irq; |
| 5560 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5561 | vector = 0; |
| 5562 | msix_irq = adapter->msix_entries[vector].vector; |
| 5563 | disable_irq(msix_irq); |
| 5564 | e1000_intr_msix_rx(msix_irq, netdev); |
| 5565 | enable_irq(msix_irq); |
| 5566 | |
| 5567 | vector++; |
| 5568 | msix_irq = adapter->msix_entries[vector].vector; |
| 5569 | disable_irq(msix_irq); |
| 5570 | e1000_intr_msix_tx(msix_irq, netdev); |
| 5571 | enable_irq(msix_irq); |
| 5572 | |
| 5573 | vector++; |
| 5574 | msix_irq = adapter->msix_entries[vector].vector; |
| 5575 | disable_irq(msix_irq); |
| 5576 | e1000_msix_other(msix_irq, netdev); |
| 5577 | enable_irq(msix_irq); |
| 5578 | } |
| 5579 | |
| 5580 | return IRQ_HANDLED; |
| 5581 | } |
| 5582 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5583 | /* |
| 5584 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5585 | * without having to re-enable interrupts. It's not called while |
| 5586 | * the interrupt routine is executing. |
| 5587 | */ |
| 5588 | static void e1000_netpoll(struct net_device *netdev) |
| 5589 | { |
| 5590 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5591 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5592 | switch (adapter->int_mode) { |
| 5593 | case E1000E_INT_MODE_MSIX: |
| 5594 | e1000_intr_msix(adapter->pdev->irq, netdev); |
| 5595 | break; |
| 5596 | case E1000E_INT_MODE_MSI: |
| 5597 | disable_irq(adapter->pdev->irq); |
| 5598 | e1000_intr_msi(adapter->pdev->irq, netdev); |
| 5599 | enable_irq(adapter->pdev->irq); |
| 5600 | break; |
| 5601 | default: /* E1000E_INT_MODE_LEGACY */ |
| 5602 | disable_irq(adapter->pdev->irq); |
| 5603 | e1000_intr(adapter->pdev->irq, netdev); |
| 5604 | enable_irq(adapter->pdev->irq); |
| 5605 | break; |
| 5606 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5607 | } |
| 5608 | #endif |
| 5609 | |
| 5610 | /** |
| 5611 | * e1000_io_error_detected - called when PCI error is detected |
| 5612 | * @pdev: Pointer to PCI device |
| 5613 | * @state: The current pci connection state |
| 5614 | * |
| 5615 | * This function is called after a PCI bus error affecting |
| 5616 | * this device has been detected. |
| 5617 | */ |
| 5618 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 5619 | pci_channel_state_t state) |
| 5620 | { |
| 5621 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5622 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5623 | |
| 5624 | netif_device_detach(netdev); |
| 5625 | |
Mike Mason | c93b5a7 | 2009-06-30 12:45:53 +0000 | [diff] [blame] | 5626 | if (state == pci_channel_io_perm_failure) |
| 5627 | return PCI_ERS_RESULT_DISCONNECT; |
| 5628 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5629 | if (netif_running(netdev)) |
| 5630 | e1000e_down(adapter); |
| 5631 | pci_disable_device(pdev); |
| 5632 | |
| 5633 | /* Request a slot slot reset. */ |
| 5634 | return PCI_ERS_RESULT_NEED_RESET; |
| 5635 | } |
| 5636 | |
| 5637 | /** |
| 5638 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 5639 | * @pdev: Pointer to PCI device |
| 5640 | * |
| 5641 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5642 | * resembles the first-half of the e1000_resume routine. |
| 5643 | */ |
| 5644 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 5645 | { |
| 5646 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5647 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5648 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5649 | u16 aspm_disable_flag = 0; |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5650 | int err; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5651 | pci_ers_result_t result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5652 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5653 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5654 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5655 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5656 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5657 | if (aspm_disable_flag) |
| 5658 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 5659 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 5660 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5661 | if (err) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5662 | dev_err(&pdev->dev, |
| 5663 | "Cannot re-enable PCI device after reset.\n"); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5664 | result = PCI_ERS_RESULT_DISCONNECT; |
| 5665 | } else { |
| 5666 | pci_set_master(pdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5667 | pdev->state_saved = true; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5668 | pci_restore_state(pdev); |
| 5669 | |
| 5670 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5671 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 5672 | |
| 5673 | e1000e_reset(adapter); |
| 5674 | ew32(WUS, ~0); |
| 5675 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5676 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5677 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5678 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5679 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5680 | return result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5681 | } |
| 5682 | |
| 5683 | /** |
| 5684 | * e1000_io_resume - called when traffic can start flowing again. |
| 5685 | * @pdev: Pointer to PCI device |
| 5686 | * |
| 5687 | * This callback is called when the error recovery driver tells us that |
| 5688 | * its OK to resume normal operation. Implementation resembles the |
| 5689 | * second-half of the e1000_resume routine. |
| 5690 | */ |
| 5691 | static void e1000_io_resume(struct pci_dev *pdev) |
| 5692 | { |
| 5693 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5694 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5695 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 5696 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5697 | |
| 5698 | if (netif_running(netdev)) { |
| 5699 | if (e1000e_up(adapter)) { |
| 5700 | dev_err(&pdev->dev, |
| 5701 | "can't bring device back up after reset\n"); |
| 5702 | return; |
| 5703 | } |
| 5704 | } |
| 5705 | |
| 5706 | netif_device_attach(netdev); |
| 5707 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5708 | /* |
| 5709 | * 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] | 5710 | * 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] | 5711 | * under the control of the driver. |
| 5712 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5713 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5714 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5715 | |
| 5716 | } |
| 5717 | |
| 5718 | static void e1000_print_device_info(struct e1000_adapter *adapter) |
| 5719 | { |
| 5720 | struct e1000_hw *hw = &adapter->hw; |
| 5721 | struct net_device *netdev = adapter->netdev; |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5722 | u32 ret_val; |
| 5723 | u8 pba_str[E1000_PBANUM_LENGTH]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5724 | |
| 5725 | /* print bus type/speed/width info */ |
Bruce Allan | a5cc764 | 2011-03-19 00:31:23 +0000 | [diff] [blame] | 5726 | e_info("(PCI Express:2.5GT/s:%s) %pM\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5727 | /* bus width */ |
| 5728 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
| 5729 | "Width x1"), |
| 5730 | /* MAC address */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5731 | netdev->dev_addr); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5732 | e_info("Intel(R) PRO/%s Network Connection\n", |
| 5733 | (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5734 | ret_val = e1000_read_pba_string_generic(hw, pba_str, |
| 5735 | E1000_PBANUM_LENGTH); |
| 5736 | if (ret_val) |
Bruce Allan | e0dc4f1 | 2011-01-06 14:29:50 +0000 | [diff] [blame] | 5737 | strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5738 | e_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 5739 | hw->mac.type, hw->phy.type, pba_str); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5740 | } |
| 5741 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5742 | static void e1000_eeprom_checks(struct e1000_adapter *adapter) |
| 5743 | { |
| 5744 | struct e1000_hw *hw = &adapter->hw; |
| 5745 | int ret_val; |
| 5746 | u16 buf = 0; |
| 5747 | |
| 5748 | if (hw->mac.type != e1000_82573) |
| 5749 | return; |
| 5750 | |
| 5751 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 5752 | if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) { |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5753 | /* Deep Smart Power Down (DSPD) */ |
Frans Pop | 6c2a9ef | 2008-09-22 14:52:22 -0700 | [diff] [blame] | 5754 | dev_warn(&adapter->pdev->dev, |
| 5755 | "Warning: detected DSPD enabled in EEPROM\n"); |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5756 | } |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5757 | } |
| 5758 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5759 | static const struct net_device_ops e1000e_netdev_ops = { |
| 5760 | .ndo_open = e1000_open, |
| 5761 | .ndo_stop = e1000_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5762 | .ndo_start_xmit = e1000_xmit_frame, |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5763 | .ndo_get_stats64 = e1000e_get_stats64, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5764 | .ndo_set_multicast_list = e1000_set_multi, |
| 5765 | .ndo_set_mac_address = e1000_set_mac, |
| 5766 | .ndo_change_mtu = e1000_change_mtu, |
| 5767 | .ndo_do_ioctl = e1000_ioctl, |
| 5768 | .ndo_tx_timeout = e1000_tx_timeout, |
| 5769 | .ndo_validate_addr = eth_validate_addr, |
| 5770 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5771 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 5772 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 5773 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5774 | .ndo_poll_controller = e1000_netpoll, |
| 5775 | #endif |
| 5776 | }; |
| 5777 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5778 | /** |
| 5779 | * e1000_probe - Device Initialization Routine |
| 5780 | * @pdev: PCI device information struct |
| 5781 | * @ent: entry in e1000_pci_tbl |
| 5782 | * |
| 5783 | * Returns 0 on success, negative on failure |
| 5784 | * |
| 5785 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 5786 | * The OS initialization, configuring of the adapter private structure, |
| 5787 | * and a hardware reset occur. |
| 5788 | **/ |
| 5789 | static int __devinit e1000_probe(struct pci_dev *pdev, |
| 5790 | const struct pci_device_id *ent) |
| 5791 | { |
| 5792 | struct net_device *netdev; |
| 5793 | struct e1000_adapter *adapter; |
| 5794 | struct e1000_hw *hw; |
| 5795 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; |
Becky Bruce | f47e81f | 2008-05-01 18:03:11 -0500 | [diff] [blame] | 5796 | resource_size_t mmio_start, mmio_len; |
| 5797 | resource_size_t flash_start, flash_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5798 | |
| 5799 | static int cards_found; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5800 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5801 | int i, err, pci_using_dac; |
| 5802 | u16 eeprom_data = 0; |
| 5803 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
| 5804 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5805 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5806 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5807 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5808 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5809 | if (aspm_disable_flag) |
| 5810 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5811 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 5812 | err = pci_enable_device_mem(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5813 | if (err) |
| 5814 | return err; |
| 5815 | |
| 5816 | pci_using_dac = 0; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5817 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5818 | if (!err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5819 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5820 | if (!err) |
| 5821 | pci_using_dac = 1; |
| 5822 | } else { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5823 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5824 | if (err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5825 | err = dma_set_coherent_mask(&pdev->dev, |
| 5826 | DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5827 | if (err) { |
| 5828 | dev_err(&pdev->dev, "No usable DMA " |
| 5829 | "configuration, aborting\n"); |
| 5830 | goto err_dma; |
| 5831 | } |
| 5832 | } |
| 5833 | } |
| 5834 | |
Arjan van de Ven | e8de148 | 2008-10-22 19:55:31 -0700 | [diff] [blame] | 5835 | err = pci_request_selected_regions_exclusive(pdev, |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 5836 | pci_select_bars(pdev, IORESOURCE_MEM), |
| 5837 | e1000e_driver_name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5838 | if (err) |
| 5839 | goto err_pci_reg; |
| 5840 | |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 5841 | /* AER (Advanced Error Reporting) hooks */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 5842 | pci_enable_pcie_error_reporting(pdev); |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 5843 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5844 | pci_set_master(pdev); |
Bruce Allan | 438b365 | 2008-11-21 16:51:33 -0800 | [diff] [blame] | 5845 | /* PCI config space info */ |
| 5846 | err = pci_save_state(pdev); |
| 5847 | if (err) |
| 5848 | goto err_alloc_etherdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5849 | |
| 5850 | err = -ENOMEM; |
| 5851 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
| 5852 | if (!netdev) |
| 5853 | goto err_alloc_etherdev; |
| 5854 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5855 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 5856 | |
Tom Herbert | f85e4df | 2010-05-05 14:03:32 +0000 | [diff] [blame] | 5857 | netdev->irq = pdev->irq; |
| 5858 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5859 | pci_set_drvdata(pdev, netdev); |
| 5860 | adapter = netdev_priv(netdev); |
| 5861 | hw = &adapter->hw; |
| 5862 | adapter->netdev = netdev; |
| 5863 | adapter->pdev = pdev; |
| 5864 | adapter->ei = ei; |
| 5865 | adapter->pba = ei->pba; |
| 5866 | adapter->flags = ei->flags; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 5867 | adapter->flags2 = ei->flags2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5868 | adapter->hw.adapter = adapter; |
| 5869 | adapter->hw.mac.type = ei->mac; |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5870 | adapter->max_hw_frame_size = ei->max_hw_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5871 | adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; |
| 5872 | |
| 5873 | mmio_start = pci_resource_start(pdev, 0); |
| 5874 | mmio_len = pci_resource_len(pdev, 0); |
| 5875 | |
| 5876 | err = -EIO; |
| 5877 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 5878 | if (!adapter->hw.hw_addr) |
| 5879 | goto err_ioremap; |
| 5880 | |
| 5881 | if ((adapter->flags & FLAG_HAS_FLASH) && |
| 5882 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
| 5883 | flash_start = pci_resource_start(pdev, 1); |
| 5884 | flash_len = pci_resource_len(pdev, 1); |
| 5885 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
| 5886 | if (!adapter->hw.flash_address) |
| 5887 | goto err_flashmap; |
| 5888 | } |
| 5889 | |
| 5890 | /* construct the net_device struct */ |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5891 | netdev->netdev_ops = &e1000e_netdev_ops; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5892 | e1000e_set_ethtool_ops(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5893 | netdev->watchdog_timeo = 5 * HZ; |
| 5894 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5895 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
| 5896 | |
| 5897 | netdev->mem_start = mmio_start; |
| 5898 | netdev->mem_end = mmio_start + mmio_len; |
| 5899 | |
| 5900 | adapter->bd_number = cards_found++; |
| 5901 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5902 | e1000e_check_options(adapter); |
| 5903 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5904 | /* setup adapter struct */ |
| 5905 | err = e1000_sw_init(adapter); |
| 5906 | if (err) |
| 5907 | goto err_sw_init; |
| 5908 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5909 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 5910 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 5911 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 5912 | |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 5913 | err = ei->get_variants(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5914 | if (err) |
| 5915 | goto err_hw_init; |
| 5916 | |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 5917 | if ((adapter->flags & FLAG_IS_ICH) && |
| 5918 | (adapter->flags & FLAG_READ_ONLY_NVM)) |
| 5919 | e1000e_write_protect_nvm_ich8lan(&adapter->hw); |
| 5920 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5921 | hw->mac.ops.get_bus_info(&adapter->hw); |
| 5922 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5923 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5924 | |
| 5925 | /* Copper options */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5926 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5927 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
| 5928 | adapter->hw.phy.disable_polarity_correction = 0; |
| 5929 | adapter->hw.phy.ms_type = e1000_ms_hw_default; |
| 5930 | } |
| 5931 | |
| 5932 | if (e1000_check_reset_block(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5933 | e_info("PHY reset is blocked due to SOL/IDER session.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5934 | |
| 5935 | netdev->features = NETIF_F_SG | |
| 5936 | NETIF_F_HW_CSUM | |
| 5937 | NETIF_F_HW_VLAN_TX | |
| 5938 | NETIF_F_HW_VLAN_RX; |
| 5939 | |
| 5940 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
| 5941 | netdev->features |= NETIF_F_HW_VLAN_FILTER; |
| 5942 | |
| 5943 | netdev->features |= NETIF_F_TSO; |
| 5944 | netdev->features |= NETIF_F_TSO6; |
| 5945 | |
Jeff Kirsher | a5136e2 | 2008-06-05 04:07:28 -0700 | [diff] [blame] | 5946 | netdev->vlan_features |= NETIF_F_TSO; |
| 5947 | netdev->vlan_features |= NETIF_F_TSO6; |
| 5948 | netdev->vlan_features |= NETIF_F_HW_CSUM; |
| 5949 | netdev->vlan_features |= NETIF_F_SG; |
| 5950 | |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 5951 | if (pci_using_dac) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5952 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 5953 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 5954 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5955 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5956 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
| 5957 | adapter->flags |= FLAG_MNG_PT_ENABLED; |
| 5958 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5959 | /* |
| 5960 | * before reading the NVM, reset the controller to |
| 5961 | * put the device in a known good starting state |
| 5962 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5963 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 5964 | |
| 5965 | /* |
| 5966 | * systems with ASPM and others may see the checksum fail on the first |
| 5967 | * attempt. Let's give it a few tries |
| 5968 | */ |
| 5969 | for (i = 0;; i++) { |
| 5970 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) |
| 5971 | break; |
| 5972 | if (i == 2) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5973 | e_err("The NVM Checksum Is Not Valid\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5974 | err = -EIO; |
| 5975 | goto err_eeprom; |
| 5976 | } |
| 5977 | } |
| 5978 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5979 | e1000_eeprom_checks(adapter); |
| 5980 | |
Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 5981 | /* copy the MAC address */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5982 | if (e1000e_read_mac_addr(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5983 | e_err("NVM Read Error while reading MAC address\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5984 | |
| 5985 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 5986 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 5987 | |
| 5988 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5989 | e_err("Invalid MAC Address: %pM\n", netdev->perm_addr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5990 | err = -EIO; |
| 5991 | goto err_eeprom; |
| 5992 | } |
| 5993 | |
| 5994 | init_timer(&adapter->watchdog_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 5995 | adapter->watchdog_timer.function = e1000_watchdog; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5996 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 5997 | |
| 5998 | init_timer(&adapter->phy_info_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 5999 | adapter->phy_info_timer.function = e1000_update_phy_info; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6000 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 6001 | |
| 6002 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
| 6003 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 6004 | INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); |
| 6005 | INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6006 | INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6007 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6008 | /* Initialize link parameters. User can change them with ethtool */ |
| 6009 | adapter->hw.mac.autoneg = 1; |
Auke Kok | 309af40 | 2007-10-05 15:22:02 -0700 | [diff] [blame] | 6010 | adapter->fc_autoneg = 1; |
Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 6011 | adapter->hw.fc.requested_mode = e1000_fc_default; |
| 6012 | adapter->hw.fc.current_mode = e1000_fc_default; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6013 | adapter->hw.phy.autoneg_advertised = 0x2f; |
| 6014 | |
| 6015 | /* ring size defaults */ |
| 6016 | adapter->rx_ring->count = 256; |
| 6017 | adapter->tx_ring->count = 256; |
| 6018 | |
| 6019 | /* |
| 6020 | * Initial Wake on LAN setting - If APM wake is enabled in |
| 6021 | * the EEPROM, enable the ACPI Magic Packet filter |
| 6022 | */ |
| 6023 | if (adapter->flags & FLAG_APME_IN_WUC) { |
| 6024 | /* APME bit in EEPROM is mapped to WUC.APME */ |
| 6025 | eeprom_data = er32(WUC); |
| 6026 | eeprom_apme_mask = E1000_WUC_APME; |
Bruce Allan | 4def99b | 2011-02-02 09:30:36 +0000 | [diff] [blame] | 6027 | if ((hw->mac.type > e1000_ich10lan) && |
| 6028 | (eeprom_data & E1000_WUC_PHY_WAKE)) |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6029 | adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6030 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
| 6031 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && |
| 6032 | (adapter->hw.bus.func == 1)) |
| 6033 | e1000_read_nvm(&adapter->hw, |
| 6034 | NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 6035 | else |
| 6036 | e1000_read_nvm(&adapter->hw, |
| 6037 | NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 6038 | } |
| 6039 | |
| 6040 | /* fetch WoL from EEPROM */ |
| 6041 | if (eeprom_data & eeprom_apme_mask) |
| 6042 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 6043 | |
| 6044 | /* |
| 6045 | * now that we have the eeprom settings, apply the special cases |
| 6046 | * where the eeprom may be wrong or the board simply won't support |
| 6047 | * wake on lan on a particular port |
| 6048 | */ |
| 6049 | if (!(adapter->flags & FLAG_HAS_WOL)) |
| 6050 | adapter->eeprom_wol = 0; |
| 6051 | |
| 6052 | /* initialize the wol settings based on the eeprom settings */ |
| 6053 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | 6ff6802 | 2008-11-12 09:52:32 +0000 | [diff] [blame] | 6054 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6055 | |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 6056 | /* save off EEPROM version number */ |
| 6057 | e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); |
| 6058 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6059 | /* reset the hardware with the new settings */ |
| 6060 | e1000e_reset(adapter); |
| 6061 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6062 | /* |
| 6063 | * 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] | 6064 | * 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] | 6065 | * under the control of the driver. |
| 6066 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6067 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6068 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6069 | |
Bruce Allan | e0dc4f1 | 2011-01-06 14:29:50 +0000 | [diff] [blame] | 6070 | strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6071 | err = register_netdev(netdev); |
| 6072 | if (err) |
| 6073 | goto err_register; |
| 6074 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 6075 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 6076 | netif_carrier_off(netdev); |
| 6077 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6078 | e1000_print_device_info(adapter); |
| 6079 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6080 | if (pci_dev_run_wake(pdev)) |
| 6081 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6082 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6083 | return 0; |
| 6084 | |
| 6085 | err_register: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6086 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6087 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6088 | err_eeprom: |
| 6089 | if (!e1000_check_reset_block(&adapter->hw)) |
| 6090 | e1000_phy_hw_reset(&adapter->hw); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6091 | err_hw_init: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6092 | kfree(adapter->tx_ring); |
| 6093 | kfree(adapter->rx_ring); |
| 6094 | err_sw_init: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6095 | if (adapter->hw.flash_address) |
| 6096 | iounmap(adapter->hw.flash_address); |
Jeff Kirsher | e82f54b | 2008-11-14 06:45:07 +0000 | [diff] [blame] | 6097 | e1000e_reset_interrupt_capability(adapter); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6098 | err_flashmap: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6099 | iounmap(adapter->hw.hw_addr); |
| 6100 | err_ioremap: |
| 6101 | free_netdev(netdev); |
| 6102 | err_alloc_etherdev: |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6103 | pci_release_selected_regions(pdev, |
| 6104 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6105 | err_pci_reg: |
| 6106 | err_dma: |
| 6107 | pci_disable_device(pdev); |
| 6108 | return err; |
| 6109 | } |
| 6110 | |
| 6111 | /** |
| 6112 | * e1000_remove - Device Removal Routine |
| 6113 | * @pdev: PCI device information struct |
| 6114 | * |
| 6115 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 6116 | * that it should release a PCI device. The could be caused by a |
| 6117 | * Hot-Plug event, or because the driver is going to be removed from |
| 6118 | * memory. |
| 6119 | **/ |
| 6120 | static void __devexit e1000_remove(struct pci_dev *pdev) |
| 6121 | { |
| 6122 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6123 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6124 | bool down = test_bit(__E1000_DOWN, &adapter->state); |
| 6125 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6126 | /* |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 6127 | * The timers may be rescheduled, so explicitly disable them |
| 6128 | * from being rescheduled. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6129 | */ |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6130 | if (!down) |
| 6131 | set_bit(__E1000_DOWN, &adapter->state); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6132 | del_timer_sync(&adapter->watchdog_timer); |
| 6133 | del_timer_sync(&adapter->phy_info_timer); |
| 6134 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6135 | cancel_work_sync(&adapter->reset_task); |
| 6136 | cancel_work_sync(&adapter->watchdog_task); |
| 6137 | cancel_work_sync(&adapter->downshift_task); |
| 6138 | cancel_work_sync(&adapter->update_phy_task); |
| 6139 | cancel_work_sync(&adapter->print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6140 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6141 | if (!(netdev->flags & IFF_UP)) |
| 6142 | e1000_power_down_phy(adapter); |
| 6143 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6144 | /* Don't lie to e1000_close() down the road. */ |
| 6145 | if (!down) |
| 6146 | clear_bit(__E1000_DOWN, &adapter->state); |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6147 | unregister_netdev(netdev); |
| 6148 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6149 | if (pci_dev_run_wake(pdev)) |
| 6150 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6151 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6152 | /* |
| 6153 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 6154 | * would have already happened in close and is redundant. |
| 6155 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6156 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6157 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6158 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6159 | kfree(adapter->tx_ring); |
| 6160 | kfree(adapter->rx_ring); |
| 6161 | |
| 6162 | iounmap(adapter->hw.hw_addr); |
| 6163 | if (adapter->hw.flash_address) |
| 6164 | iounmap(adapter->hw.flash_address); |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6165 | pci_release_selected_regions(pdev, |
| 6166 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6167 | |
| 6168 | free_netdev(netdev); |
| 6169 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6170 | /* AER disable */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6171 | pci_disable_pcie_error_reporting(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6172 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6173 | pci_disable_device(pdev); |
| 6174 | } |
| 6175 | |
| 6176 | /* PCI Error Recovery (ERS) */ |
| 6177 | static struct pci_error_handlers e1000_err_handler = { |
| 6178 | .error_detected = e1000_io_error_detected, |
| 6179 | .slot_reset = e1000_io_slot_reset, |
| 6180 | .resume = e1000_io_resume, |
| 6181 | }; |
| 6182 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 6183 | static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6184 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
| 6185 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, |
| 6186 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, |
| 6187 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 }, |
| 6188 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
| 6189 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, |
Auke Kok | 040babf | 2007-10-31 15:22:05 -0700 | [diff] [blame] | 6190 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
| 6191 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, |
| 6192 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6193 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6194 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
| 6195 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, |
| 6196 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, |
| 6197 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6198 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6199 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
| 6200 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, |
| 6201 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6202 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6203 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, |
Bruce Allan | bef28b1 | 2009-03-24 23:28:02 -0700 | [diff] [blame] | 6204 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 6205 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6206 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6207 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
| 6208 | board_80003es2lan }, |
| 6209 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), |
| 6210 | board_80003es2lan }, |
| 6211 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), |
| 6212 | board_80003es2lan }, |
| 6213 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), |
| 6214 | board_80003es2lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6215 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6216 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
| 6217 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, |
| 6218 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, |
| 6219 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, |
| 6220 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, |
| 6221 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, |
| 6222 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, |
Bruce Allan | 9e135a2 | 2009-12-01 15:50:31 +0000 | [diff] [blame] | 6223 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6224 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6225 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
| 6226 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, |
| 6227 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, |
| 6228 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, |
| 6229 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, |
Bruce Allan | 2f15f9d | 2008-08-26 18:36:36 -0700 | [diff] [blame] | 6230 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6231 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, |
| 6232 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, |
| 6233 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, |
| 6234 | |
| 6235 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, |
| 6236 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, |
| 6237 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6238 | |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6239 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, |
| 6240 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, |
Bruce Allan | 10df0b9 | 2010-05-10 15:02:52 +0000 | [diff] [blame] | 6241 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan }, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6242 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6243 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, |
| 6244 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, |
| 6245 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, |
| 6246 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, |
| 6247 | |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 6248 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan }, |
| 6249 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan }, |
| 6250 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6251 | { } /* terminate list */ |
| 6252 | }; |
| 6253 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 6254 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6255 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6256 | static const struct dev_pm_ops e1000_pm_ops = { |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6257 | SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume) |
| 6258 | SET_RUNTIME_PM_OPS(e1000_runtime_suspend, |
| 6259 | e1000_runtime_resume, e1000_idle) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6260 | }; |
David S. Miller | e50208a | 2010-03-16 23:36:24 -0700 | [diff] [blame] | 6261 | #endif |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6262 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6263 | /* PCI Device API Driver */ |
| 6264 | static struct pci_driver e1000_driver = { |
| 6265 | .name = e1000e_driver_name, |
| 6266 | .id_table = e1000_pci_tbl, |
| 6267 | .probe = e1000_probe, |
| 6268 | .remove = __devexit_p(e1000_remove), |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6269 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6270 | .driver.pm = &e1000_pm_ops, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6271 | #endif |
| 6272 | .shutdown = e1000_shutdown, |
| 6273 | .err_handler = &e1000_err_handler |
| 6274 | }; |
| 6275 | |
| 6276 | /** |
| 6277 | * e1000_init_module - Driver Registration Routine |
| 6278 | * |
| 6279 | * e1000_init_module is the first routine called when the driver is |
| 6280 | * loaded. All it does is register with the PCI subsystem. |
| 6281 | **/ |
| 6282 | static int __init e1000_init_module(void) |
| 6283 | { |
| 6284 | int ret; |
Bruce Allan | 8544b9f | 2010-03-24 12:55:30 +0000 | [diff] [blame] | 6285 | pr_info("Intel(R) PRO/1000 Network Driver - %s\n", |
| 6286 | e1000e_driver_version); |
Bruce Allan | 0d6057e | 2011-01-04 01:16:44 +0000 | [diff] [blame] | 6287 | pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6288 | ret = pci_register_driver(&e1000_driver); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 6289 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6290 | return ret; |
| 6291 | } |
| 6292 | module_init(e1000_init_module); |
| 6293 | |
| 6294 | /** |
| 6295 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 6296 | * |
| 6297 | * e1000_exit_module is called just before the driver is removed |
| 6298 | * from memory. |
| 6299 | **/ |
| 6300 | static void __exit e1000_exit_module(void) |
| 6301 | { |
| 6302 | pci_unregister_driver(&e1000_driver); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6303 | } |
| 6304 | module_exit(e1000_exit_module); |
| 6305 | |
| 6306 | |
| 6307 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 6308 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 6309 | MODULE_LICENSE("GPL"); |
| 6310 | MODULE_VERSION(DRV_VERSION); |
| 6311 | |
| 6312 | /* e1000_main.c */ |