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> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/vmalloc.h> |
| 36 | #include <linux/pagemap.h> |
| 37 | #include <linux/delay.h> |
| 38 | #include <linux/netdevice.h> |
Bruce Allan | 9fb7a5f | 2011-07-29 05:52:51 +0000 | [diff] [blame] | 39 | #include <linux/interrupt.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 7e0bb71 | 2011-10-25 15:18:39 +0200 | [diff] [blame] | 50 | #include <linux/pm_qos.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 | c5778b4 | 2011-07-29 05:53:12 +0000 | [diff] [blame] | 59 | #define DRV_VERSION "1.5.1" 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: |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 166 | pr_info("%-15s %08x\n", |
| 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]"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 172 | pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 175 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 176 | * e1000e_dump - Print registers, Tx-ring and Rx-ring |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 177 | */ |
| 178 | static void e1000e_dump(struct e1000_adapter *adapter) |
| 179 | { |
| 180 | struct net_device *netdev = adapter->netdev; |
| 181 | struct e1000_hw *hw = &adapter->hw; |
| 182 | struct e1000_reg_info *reginfo; |
| 183 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 184 | struct e1000_tx_desc *tx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 185 | struct my_u0 { |
| 186 | u64 a; |
| 187 | u64 b; |
| 188 | } *u0; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 189 | struct e1000_buffer *buffer_info; |
| 190 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 191 | union e1000_rx_desc_packet_split *rx_desc_ps; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 192 | union e1000_rx_desc_extended *rx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 193 | struct my_u1 { |
| 194 | u64 a; |
| 195 | u64 b; |
| 196 | u64 c; |
| 197 | u64 d; |
| 198 | } *u1; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 199 | u32 staterr; |
| 200 | int i = 0; |
| 201 | |
| 202 | if (!netif_msg_hw(adapter)) |
| 203 | return; |
| 204 | |
| 205 | /* Print netdevice Info */ |
| 206 | if (netdev) { |
| 207 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 208 | pr_info("Device Name state trans_start last_rx\n"); |
| 209 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 210 | netdev->name, netdev->state, netdev->trans_start, |
| 211 | netdev->last_rx); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /* Print Registers */ |
| 215 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 216 | pr_info(" Register Name Value\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 217 | for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl; |
| 218 | reginfo->name; reginfo++) { |
| 219 | e1000_regdump(hw, reginfo); |
| 220 | } |
| 221 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 222 | /* Print Tx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 223 | if (!netdev || !netif_running(netdev)) |
| 224 | goto exit; |
| 225 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 226 | dev_info(&adapter->pdev->dev, "Tx Ring Summary\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 227 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 228 | buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean]; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 229 | pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n", |
| 230 | 0, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 231 | (unsigned long long)buffer_info->dma, |
| 232 | buffer_info->length, |
| 233 | buffer_info->next_to_watch, |
| 234 | (unsigned long long)buffer_info->time_stamp); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 235 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 236 | /* Print Tx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 237 | if (!netif_msg_tx_done(adapter)) |
| 238 | goto rx_ring_summary; |
| 239 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 240 | dev_info(&adapter->pdev->dev, "Tx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 241 | |
| 242 | /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended) |
| 243 | * |
| 244 | * Legacy Transmit Descriptor |
| 245 | * +--------------------------------------------------------------+ |
| 246 | * 0 | Buffer Address [63:0] (Reserved on Write Back) | |
| 247 | * +--------------------------------------------------------------+ |
| 248 | * 8 | Special | CSS | Status | CMD | CSO | Length | |
| 249 | * +--------------------------------------------------------------+ |
| 250 | * 63 48 47 36 35 32 31 24 23 16 15 0 |
| 251 | * |
| 252 | * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload |
| 253 | * 63 48 47 40 39 32 31 16 15 8 7 0 |
| 254 | * +----------------------------------------------------------------+ |
| 255 | * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS | |
| 256 | * +----------------------------------------------------------------+ |
| 257 | * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN | |
| 258 | * +----------------------------------------------------------------+ |
| 259 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 260 | * |
| 261 | * Extended Data Descriptor (DTYP=0x1) |
| 262 | * +----------------------------------------------------------------+ |
| 263 | * 0 | Buffer Address [63:0] | |
| 264 | * +----------------------------------------------------------------+ |
| 265 | * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN | |
| 266 | * +----------------------------------------------------------------+ |
| 267 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 268 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 269 | pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n"); |
| 270 | pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n"); |
| 271 | pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 272 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 273 | const char *next_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 274 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 275 | buffer_info = &tx_ring->buffer_info[i]; |
| 276 | u0 = (struct my_u0 *)tx_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 277 | if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 278 | next_desc = " NTC/U"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 279 | else if (i == tx_ring->next_to_use) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 280 | next_desc = " NTU"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 281 | else if (i == tx_ring->next_to_clean) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 282 | next_desc = " NTC"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 283 | else |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 284 | next_desc = ""; |
| 285 | pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n", |
| 286 | (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' : |
| 287 | ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), |
| 288 | i, |
| 289 | (unsigned long long)le64_to_cpu(u0->a), |
| 290 | (unsigned long long)le64_to_cpu(u0->b), |
| 291 | (unsigned long long)buffer_info->dma, |
| 292 | buffer_info->length, buffer_info->next_to_watch, |
| 293 | (unsigned long long)buffer_info->time_stamp, |
| 294 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 295 | |
| 296 | if (netif_msg_pktdata(adapter) && buffer_info->dma != 0) |
| 297 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 298 | 16, 1, phys_to_virt(buffer_info->dma), |
| 299 | buffer_info->length, true); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 302 | /* Print Rx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 303 | rx_ring_summary: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 304 | dev_info(&adapter->pdev->dev, "Rx Ring Summary\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 305 | pr_info("Queue [NTU] [NTC]\n"); |
| 306 | pr_info(" %5d %5X %5X\n", |
| 307 | 0, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 308 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 309 | /* Print Rx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 310 | if (!netif_msg_rx_status(adapter)) |
| 311 | goto exit; |
| 312 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 313 | dev_info(&adapter->pdev->dev, "Rx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 314 | switch (adapter->rx_ps_pages) { |
| 315 | case 1: |
| 316 | case 2: |
| 317 | case 3: |
| 318 | /* [Extended] Packet Split Receive Descriptor Format |
| 319 | * |
| 320 | * +-----------------------------------------------------+ |
| 321 | * 0 | Buffer Address 0 [63:0] | |
| 322 | * +-----------------------------------------------------+ |
| 323 | * 8 | Buffer Address 1 [63:0] | |
| 324 | * +-----------------------------------------------------+ |
| 325 | * 16 | Buffer Address 2 [63:0] | |
| 326 | * +-----------------------------------------------------+ |
| 327 | * 24 | Buffer Address 3 [63:0] | |
| 328 | * +-----------------------------------------------------+ |
| 329 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 330 | pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 331 | /* [Extended] Receive Descriptor (Write-Back) Format |
| 332 | * |
| 333 | * 63 48 47 32 31 13 12 8 7 4 3 0 |
| 334 | * +------------------------------------------------------+ |
| 335 | * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS | |
| 336 | * | Checksum | Ident | | Queue | | Type | |
| 337 | * +------------------------------------------------------+ |
| 338 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 339 | * +------------------------------------------------------+ |
| 340 | * 63 48 47 32 31 20 19 0 |
| 341 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 342 | pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 343 | for (i = 0; i < rx_ring->count; i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 344 | const char *next_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 345 | buffer_info = &rx_ring->buffer_info[i]; |
| 346 | rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i); |
| 347 | u1 = (struct my_u1 *)rx_desc_ps; |
| 348 | staterr = |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 349 | le32_to_cpu(rx_desc_ps->wb.middle.status_error); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 350 | |
| 351 | if (i == rx_ring->next_to_use) |
| 352 | next_desc = " NTU"; |
| 353 | else if (i == rx_ring->next_to_clean) |
| 354 | next_desc = " NTC"; |
| 355 | else |
| 356 | next_desc = ""; |
| 357 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 358 | if (staterr & E1000_RXD_STAT_DD) { |
| 359 | /* Descriptor Done */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 360 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n", |
| 361 | "RWB", i, |
| 362 | (unsigned long long)le64_to_cpu(u1->a), |
| 363 | (unsigned long long)le64_to_cpu(u1->b), |
| 364 | (unsigned long long)le64_to_cpu(u1->c), |
| 365 | (unsigned long long)le64_to_cpu(u1->d), |
| 366 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 367 | } else { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 368 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n", |
| 369 | "R ", 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 | (unsigned long long)buffer_info->dma, |
| 375 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 376 | |
| 377 | if (netif_msg_pktdata(adapter)) |
| 378 | print_hex_dump(KERN_INFO, "", |
| 379 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 380 | phys_to_virt(buffer_info->dma), |
| 381 | adapter->rx_ps_bsize0, true); |
| 382 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 383 | } |
| 384 | break; |
| 385 | default: |
| 386 | case 0: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 387 | /* Extended Receive Descriptor (Read) Format |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 388 | * |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 389 | * +-----------------------------------------------------+ |
| 390 | * 0 | Buffer Address [63:0] | |
| 391 | * +-----------------------------------------------------+ |
| 392 | * 8 | Reserved | |
| 393 | * +-----------------------------------------------------+ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 394 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 395 | pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n"); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 396 | /* Extended Receive Descriptor (Write-Back) Format |
| 397 | * |
| 398 | * 63 48 47 32 31 24 23 4 3 0 |
| 399 | * +------------------------------------------------------+ |
| 400 | * | RSS Hash | | | | |
| 401 | * 0 +-------------------+ Rsvd | Reserved | MRQ RSS | |
| 402 | * | Packet | IP | | | Type | |
| 403 | * | Checksum | Ident | | | | |
| 404 | * +------------------------------------------------------+ |
| 405 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 406 | * +------------------------------------------------------+ |
| 407 | * 63 48 47 32 31 20 19 0 |
| 408 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 409 | pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n"); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 410 | |
| 411 | for (i = 0; i < rx_ring->count; i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 412 | const char *next_desc; |
| 413 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 414 | buffer_info = &rx_ring->buffer_info[i]; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 415 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 416 | u1 = (struct my_u1 *)rx_desc; |
| 417 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 418 | |
| 419 | if (i == rx_ring->next_to_use) |
| 420 | next_desc = " NTU"; |
| 421 | else if (i == rx_ring->next_to_clean) |
| 422 | next_desc = " NTC"; |
| 423 | else |
| 424 | next_desc = ""; |
| 425 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 426 | if (staterr & E1000_RXD_STAT_DD) { |
| 427 | /* Descriptor Done */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 428 | pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n", |
| 429 | "RWB", i, |
| 430 | (unsigned long long)le64_to_cpu(u1->a), |
| 431 | (unsigned long long)le64_to_cpu(u1->b), |
| 432 | buffer_info->skb, next_desc); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 433 | } else { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 434 | pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n", |
| 435 | "R ", i, |
| 436 | (unsigned long long)le64_to_cpu(u1->a), |
| 437 | (unsigned long long)le64_to_cpu(u1->b), |
| 438 | (unsigned long long)buffer_info->dma, |
| 439 | buffer_info->skb, next_desc); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 440 | |
| 441 | if (netif_msg_pktdata(adapter)) |
| 442 | print_hex_dump(KERN_INFO, "", |
| 443 | DUMP_PREFIX_ADDRESS, 16, |
| 444 | 1, |
| 445 | phys_to_virt |
| 446 | (buffer_info->dma), |
| 447 | adapter->rx_buffer_len, |
| 448 | true); |
| 449 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
| 453 | exit: |
| 454 | return; |
| 455 | } |
| 456 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 457 | /** |
| 458 | * e1000_desc_unused - calculate if we have unused descriptors |
| 459 | **/ |
| 460 | static int e1000_desc_unused(struct e1000_ring *ring) |
| 461 | { |
| 462 | if (ring->next_to_clean > ring->next_to_use) |
| 463 | return ring->next_to_clean - ring->next_to_use - 1; |
| 464 | |
| 465 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; |
| 466 | } |
| 467 | |
| 468 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 469 | * e1000_receive_skb - helper function to handle Rx indications |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 470 | * @adapter: board private structure |
| 471 | * @status: descriptor status field as written by hardware |
| 472 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
| 473 | * @skb: pointer to sk_buff to be indicated to stack |
| 474 | **/ |
| 475 | static void e1000_receive_skb(struct e1000_adapter *adapter, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 476 | struct net_device *netdev, struct sk_buff *skb, |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 477 | u8 status, __le16 vlan) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 478 | { |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 479 | u16 tag = le16_to_cpu(vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 480 | skb->protocol = eth_type_trans(skb, netdev); |
| 481 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 482 | if (status & E1000_RXD_STAT_VP) |
| 483 | __vlan_hwaccel_put_tag(skb, tag); |
| 484 | |
| 485 | napi_gro_receive(&adapter->napi, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 489 | * e1000_rx_checksum - Receive Checksum Offload |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 490 | * @adapter: board private structure |
| 491 | * @status_err: receive descriptor status and error fields |
| 492 | * @csum: receive descriptor csum field |
| 493 | * @sk_buff: socket buffer with received data |
| 494 | **/ |
| 495 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
| 496 | u32 csum, struct sk_buff *skb) |
| 497 | { |
| 498 | u16 status = (u16)status_err; |
| 499 | u8 errors = (u8)(status_err >> 24); |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 500 | |
| 501 | skb_checksum_none_assert(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 502 | |
| 503 | /* Ignore Checksum bit is set */ |
| 504 | if (status & E1000_RXD_STAT_IXSM) |
| 505 | return; |
| 506 | /* TCP/UDP checksum error bit is set */ |
| 507 | if (errors & E1000_RXD_ERR_TCPE) { |
| 508 | /* let the stack verify checksum errors */ |
| 509 | adapter->hw_csum_err++; |
| 510 | return; |
| 511 | } |
| 512 | |
| 513 | /* TCP/UDP Checksum has not been calculated */ |
| 514 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
| 515 | return; |
| 516 | |
| 517 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 518 | if (status & E1000_RXD_STAT_TCPCS) { |
| 519 | /* TCP checksum is good */ |
| 520 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 521 | } else { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 522 | /* |
| 523 | * IP fragment with UDP payload |
| 524 | * Hardware complements the payload checksum, so we undo it |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 525 | * and then put the value in host order for further stack use. |
| 526 | */ |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 527 | __sum16 sum = (__force __sum16)htons(csum); |
| 528 | skb->csum = csum_unfold(~sum); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 529 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 530 | } |
| 531 | adapter->hw_csum_good++; |
| 532 | } |
| 533 | |
| 534 | /** |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 535 | * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa() |
| 536 | * @hw: pointer to the HW structure |
| 537 | * @tail: address of tail descriptor register |
| 538 | * @i: value to write to tail descriptor register |
| 539 | * |
| 540 | * When updating the tail register, the ME could be accessing Host CSR |
| 541 | * registers at the same time. Normally, this is handled in h/w by an |
| 542 | * arbiter but on some parts there is a bug that acknowledges Host accesses |
| 543 | * later than it should which could result in the descriptor register to |
| 544 | * have an incorrect value. Workaround this by checking the FWSM register |
| 545 | * which has bit 24 set while ME is accessing Host CSR registers, wait |
| 546 | * if it is set and try again a number of times. |
| 547 | **/ |
| 548 | static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, u8 __iomem * tail, |
| 549 | unsigned int i) |
| 550 | { |
| 551 | unsigned int j = 0; |
| 552 | |
| 553 | while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) && |
| 554 | (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI)) |
| 555 | udelay(50); |
| 556 | |
| 557 | writel(i, tail); |
| 558 | |
| 559 | if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail))) |
| 560 | return E1000_ERR_SWFW_SYNC; |
| 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | static void e1000e_update_rdt_wa(struct e1000_adapter *adapter, unsigned int i) |
| 566 | { |
| 567 | u8 __iomem *tail = (adapter->hw.hw_addr + adapter->rx_ring->tail); |
| 568 | struct e1000_hw *hw = &adapter->hw; |
| 569 | |
| 570 | if (e1000e_update_tail_wa(hw, tail, i)) { |
| 571 | u32 rctl = er32(RCTL); |
| 572 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 573 | e_err("ME firmware caused invalid RDT - resetting\n"); |
| 574 | schedule_work(&adapter->reset_task); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | static void e1000e_update_tdt_wa(struct e1000_adapter *adapter, unsigned int i) |
| 579 | { |
| 580 | u8 __iomem *tail = (adapter->hw.hw_addr + adapter->tx_ring->tail); |
| 581 | struct e1000_hw *hw = &adapter->hw; |
| 582 | |
| 583 | if (e1000e_update_tail_wa(hw, tail, i)) { |
| 584 | u32 tctl = er32(TCTL); |
| 585 | ew32(TCTL, tctl & ~E1000_TCTL_EN); |
| 586 | e_err("ME firmware caused invalid TDT - resetting\n"); |
| 587 | schedule_work(&adapter->reset_task); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | /** |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 592 | * e1000_alloc_rx_buffers - Replace used receive buffers |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 593 | * @adapter: address of board private structure |
| 594 | **/ |
| 595 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 596 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 597 | { |
| 598 | struct net_device *netdev = adapter->netdev; |
| 599 | struct pci_dev *pdev = adapter->pdev; |
| 600 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 601 | union e1000_rx_desc_extended *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 602 | struct e1000_buffer *buffer_info; |
| 603 | struct sk_buff *skb; |
| 604 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 605 | unsigned int bufsz = adapter->rx_buffer_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 606 | |
| 607 | i = rx_ring->next_to_use; |
| 608 | buffer_info = &rx_ring->buffer_info[i]; |
| 609 | |
| 610 | while (cleaned_count--) { |
| 611 | skb = buffer_info->skb; |
| 612 | if (skb) { |
| 613 | skb_trim(skb, 0); |
| 614 | goto map_skb; |
| 615 | } |
| 616 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 617 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 618 | if (!skb) { |
| 619 | /* Better luck next round */ |
| 620 | adapter->alloc_rx_buff_failed++; |
| 621 | break; |
| 622 | } |
| 623 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 624 | buffer_info->skb = skb; |
| 625 | map_skb: |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 626 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 627 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 628 | DMA_FROM_DEVICE); |
| 629 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 630 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 631 | adapter->rx_dma_failed++; |
| 632 | break; |
| 633 | } |
| 634 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 635 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 636 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 637 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 638 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
| 639 | /* |
| 640 | * Force memory writes to complete before letting h/w |
| 641 | * know there are new descriptors to fetch. (Only |
| 642 | * applicable for weak-ordered memory model archs, |
| 643 | * such as IA-64). |
| 644 | */ |
| 645 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 646 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 647 | e1000e_update_rdt_wa(adapter, i); |
| 648 | else |
| 649 | writel(i, adapter->hw.hw_addr + rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 650 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 651 | i++; |
| 652 | if (i == rx_ring->count) |
| 653 | i = 0; |
| 654 | buffer_info = &rx_ring->buffer_info[i]; |
| 655 | } |
| 656 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 657 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | /** |
| 661 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
| 662 | * @adapter: address of board private structure |
| 663 | **/ |
| 664 | static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 665 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 666 | { |
| 667 | struct net_device *netdev = adapter->netdev; |
| 668 | struct pci_dev *pdev = adapter->pdev; |
| 669 | union e1000_rx_desc_packet_split *rx_desc; |
| 670 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 671 | struct e1000_buffer *buffer_info; |
| 672 | struct e1000_ps_page *ps_page; |
| 673 | struct sk_buff *skb; |
| 674 | unsigned int i, j; |
| 675 | |
| 676 | i = rx_ring->next_to_use; |
| 677 | buffer_info = &rx_ring->buffer_info[i]; |
| 678 | |
| 679 | while (cleaned_count--) { |
| 680 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 681 | |
| 682 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 683 | ps_page = &buffer_info->ps_pages[j]; |
| 684 | if (j >= adapter->rx_ps_pages) { |
| 685 | /* all unused desc entries get hw null ptr */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 686 | rx_desc->read.buffer_addr[j + 1] = |
| 687 | ~cpu_to_le64(0); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 688 | continue; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 689 | } |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 690 | if (!ps_page->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 691 | ps_page->page = alloc_page(gfp); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 692 | if (!ps_page->page) { |
| 693 | adapter->alloc_rx_buff_failed++; |
| 694 | goto no_buffers; |
| 695 | } |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 696 | ps_page->dma = dma_map_page(&pdev->dev, |
| 697 | ps_page->page, |
| 698 | 0, PAGE_SIZE, |
| 699 | DMA_FROM_DEVICE); |
| 700 | if (dma_mapping_error(&pdev->dev, |
| 701 | ps_page->dma)) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 702 | dev_err(&adapter->pdev->dev, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 703 | "Rx DMA page map failed\n"); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 704 | adapter->rx_dma_failed++; |
| 705 | goto no_buffers; |
| 706 | } |
| 707 | } |
| 708 | /* |
| 709 | * Refresh the desc even if buffer_addrs |
| 710 | * didn't change because each write-back |
| 711 | * erases this info. |
| 712 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 713 | rx_desc->read.buffer_addr[j + 1] = |
| 714 | cpu_to_le64(ps_page->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 717 | skb = __netdev_alloc_skb_ip_align(netdev, |
| 718 | adapter->rx_ps_bsize0, |
| 719 | gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 720 | |
| 721 | if (!skb) { |
| 722 | adapter->alloc_rx_buff_failed++; |
| 723 | break; |
| 724 | } |
| 725 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 726 | buffer_info->skb = skb; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 727 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 728 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 729 | DMA_FROM_DEVICE); |
| 730 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 731 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 732 | adapter->rx_dma_failed++; |
| 733 | /* cleanup skb */ |
| 734 | dev_kfree_skb_any(skb); |
| 735 | buffer_info->skb = NULL; |
| 736 | break; |
| 737 | } |
| 738 | |
| 739 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 740 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 741 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
| 742 | /* |
| 743 | * Force memory writes to complete before letting h/w |
| 744 | * know there are new descriptors to fetch. (Only |
| 745 | * applicable for weak-ordered memory model archs, |
| 746 | * such as IA-64). |
| 747 | */ |
| 748 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 749 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 750 | e1000e_update_rdt_wa(adapter, i << 1); |
| 751 | else |
| 752 | writel(i << 1, |
| 753 | adapter->hw.hw_addr + rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 756 | i++; |
| 757 | if (i == rx_ring->count) |
| 758 | i = 0; |
| 759 | buffer_info = &rx_ring->buffer_info[i]; |
| 760 | } |
| 761 | |
| 762 | no_buffers: |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 763 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 767 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
| 768 | * @adapter: address of board private structure |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 769 | * @cleaned_count: number of buffers to allocate this pass |
| 770 | **/ |
| 771 | |
| 772 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 773 | int cleaned_count, gfp_t gfp) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 774 | { |
| 775 | struct net_device *netdev = adapter->netdev; |
| 776 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 777 | union e1000_rx_desc_extended *rx_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 778 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 779 | struct e1000_buffer *buffer_info; |
| 780 | struct sk_buff *skb; |
| 781 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 782 | unsigned int bufsz = 256 - 16 /* for skb_reserve */; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 783 | |
| 784 | i = rx_ring->next_to_use; |
| 785 | buffer_info = &rx_ring->buffer_info[i]; |
| 786 | |
| 787 | while (cleaned_count--) { |
| 788 | skb = buffer_info->skb; |
| 789 | if (skb) { |
| 790 | skb_trim(skb, 0); |
| 791 | goto check_page; |
| 792 | } |
| 793 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 794 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 795 | if (unlikely(!skb)) { |
| 796 | /* Better luck next round */ |
| 797 | adapter->alloc_rx_buff_failed++; |
| 798 | break; |
| 799 | } |
| 800 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 801 | buffer_info->skb = skb; |
| 802 | check_page: |
| 803 | /* allocate a new page if necessary */ |
| 804 | if (!buffer_info->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 805 | buffer_info->page = alloc_page(gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 806 | if (unlikely(!buffer_info->page)) { |
| 807 | adapter->alloc_rx_buff_failed++; |
| 808 | break; |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | if (!buffer_info->dma) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 813 | buffer_info->dma = dma_map_page(&pdev->dev, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 814 | buffer_info->page, 0, |
| 815 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 816 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 817 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 818 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 819 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 820 | |
| 821 | if (unlikely(++i == rx_ring->count)) |
| 822 | i = 0; |
| 823 | buffer_info = &rx_ring->buffer_info[i]; |
| 824 | } |
| 825 | |
| 826 | if (likely(rx_ring->next_to_use != i)) { |
| 827 | rx_ring->next_to_use = i; |
| 828 | if (unlikely(i-- == 0)) |
| 829 | i = (rx_ring->count - 1); |
| 830 | |
| 831 | /* Force memory writes to complete before letting h/w |
| 832 | * know there are new descriptors to fetch. (Only |
| 833 | * applicable for weak-ordered memory model archs, |
| 834 | * such as IA-64). */ |
| 835 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 836 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 837 | e1000e_update_rdt_wa(adapter, i); |
| 838 | else |
| 839 | writel(i, adapter->hw.hw_addr + rx_ring->tail); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | |
| 843 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 844 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
| 845 | * @adapter: board private structure |
| 846 | * |
| 847 | * the return value indicates whether actual cleaning was done, there |
| 848 | * is no guarantee that everything was cleaned |
| 849 | **/ |
| 850 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 851 | int *work_done, int work_to_do) |
| 852 | { |
| 853 | struct net_device *netdev = adapter->netdev; |
| 854 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 855 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 856 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 857 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 858 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 859 | u32 length, staterr; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 860 | unsigned int i; |
| 861 | int cleaned_count = 0; |
| 862 | bool cleaned = 0; |
| 863 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 864 | |
| 865 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 866 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 867 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 868 | buffer_info = &rx_ring->buffer_info[i]; |
| 869 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 870 | while (staterr & E1000_RXD_STAT_DD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 871 | struct sk_buff *skb; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 872 | |
| 873 | if (*work_done >= work_to_do) |
| 874 | break; |
| 875 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 876 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 877 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 878 | skb = buffer_info->skb; |
| 879 | buffer_info->skb = NULL; |
| 880 | |
| 881 | prefetch(skb->data - NET_IP_ALIGN); |
| 882 | |
| 883 | i++; |
| 884 | if (i == rx_ring->count) |
| 885 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 886 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 887 | prefetch(next_rxd); |
| 888 | |
| 889 | next_buffer = &rx_ring->buffer_info[i]; |
| 890 | |
| 891 | cleaned = 1; |
| 892 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 893 | dma_unmap_single(&pdev->dev, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 894 | buffer_info->dma, |
| 895 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 896 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 897 | buffer_info->dma = 0; |
| 898 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 899 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 900 | |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 901 | /* |
| 902 | * !EOP means multiple descriptors were used to store a single |
| 903 | * packet, if that's the case we need to toss it. In fact, we |
| 904 | * need to toss every packet with the EOP bit clear and the |
| 905 | * next frame that _does_ have the EOP bit set, as it is by |
| 906 | * definition only a frame fragment |
| 907 | */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 908 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 909 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 910 | |
| 911 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 912 | /* All receives must fit into a single buffer */ |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 913 | e_dbg("Receive packet consumed multiple buffers\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 914 | /* recycle */ |
| 915 | buffer_info->skb = skb; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 916 | if (staterr & E1000_RXD_STAT_EOP) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 917 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 918 | goto next_desc; |
| 919 | } |
| 920 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 921 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 922 | /* recycle */ |
| 923 | buffer_info->skb = skb; |
| 924 | goto next_desc; |
| 925 | } |
| 926 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 927 | /* adjust length to remove Ethernet CRC */ |
| 928 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 929 | length -= 4; |
| 930 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 931 | total_rx_bytes += length; |
| 932 | total_rx_packets++; |
| 933 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 934 | /* |
| 935 | * code added for copybreak, this should improve |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 936 | * performance for small packets with large amounts |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 937 | * of reassembly being done in the stack |
| 938 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 939 | if (length < copybreak) { |
| 940 | struct sk_buff *new_skb = |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 941 | netdev_alloc_skb_ip_align(netdev, length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 942 | if (new_skb) { |
Bruce Allan | 808ff67 | 2008-08-08 18:35:56 -0700 | [diff] [blame] | 943 | skb_copy_to_linear_data_offset(new_skb, |
| 944 | -NET_IP_ALIGN, |
| 945 | (skb->data - |
| 946 | NET_IP_ALIGN), |
| 947 | (length + |
| 948 | NET_IP_ALIGN)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 949 | /* save the skb in buffer_info as good */ |
| 950 | buffer_info->skb = skb; |
| 951 | skb = new_skb; |
| 952 | } |
| 953 | /* else just continue with the old one */ |
| 954 | } |
| 955 | /* end copybreak code */ |
| 956 | skb_put(skb, length); |
| 957 | |
| 958 | /* Receive Checksum Offload */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 959 | e1000_rx_checksum(adapter, staterr, |
| 960 | le16_to_cpu(rx_desc->wb.lower.hi_dword. |
| 961 | csum_ip.csum), skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 962 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 963 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 964 | rx_desc->wb.upper.vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 965 | |
| 966 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 967 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 968 | |
| 969 | /* return some buffers to hardware, one at a time is too slow */ |
| 970 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 971 | adapter->alloc_rx_buf(adapter, cleaned_count, |
| 972 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 973 | cleaned_count = 0; |
| 974 | } |
| 975 | |
| 976 | /* use prefetched values */ |
| 977 | rx_desc = next_rxd; |
| 978 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 979 | |
| 980 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 981 | } |
| 982 | rx_ring->next_to_clean = i; |
| 983 | |
| 984 | cleaned_count = e1000_desc_unused(rx_ring); |
| 985 | if (cleaned_count) |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 986 | adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 987 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 988 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 989 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 990 | return cleaned; |
| 991 | } |
| 992 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 993 | static void e1000_put_txbuf(struct e1000_adapter *adapter, |
| 994 | struct e1000_buffer *buffer_info) |
| 995 | { |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 996 | if (buffer_info->dma) { |
| 997 | if (buffer_info->mapped_as_page) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 998 | dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, |
| 999 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1000 | else |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1001 | dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, |
| 1002 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1003 | buffer_info->dma = 0; |
| 1004 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1005 | if (buffer_info->skb) { |
| 1006 | dev_kfree_skb_any(buffer_info->skb); |
| 1007 | buffer_info->skb = NULL; |
| 1008 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 1009 | buffer_info->time_stamp = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1012 | static void e1000_print_hw_hang(struct work_struct *work) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1013 | { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1014 | struct e1000_adapter *adapter = container_of(work, |
| 1015 | struct e1000_adapter, |
| 1016 | print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1017 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1018 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1019 | unsigned int i = tx_ring->next_to_clean; |
| 1020 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; |
| 1021 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1022 | struct e1000_hw *hw = &adapter->hw; |
| 1023 | u16 phy_status, phy_1000t_status, phy_ext_status; |
| 1024 | u16 pci_status; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1025 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1026 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1027 | return; |
| 1028 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1029 | if (!adapter->tx_hang_recheck && |
| 1030 | (adapter->flags2 & FLAG2_DMA_BURST)) { |
| 1031 | /* May be block on write-back, flush and detect again |
| 1032 | * flush pending descriptor writebacks to memory |
| 1033 | */ |
| 1034 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 1035 | /* execute the writes immediately */ |
| 1036 | e1e_flush(); |
| 1037 | adapter->tx_hang_recheck = true; |
| 1038 | return; |
| 1039 | } |
| 1040 | /* Real hang detected */ |
| 1041 | adapter->tx_hang_recheck = false; |
| 1042 | netif_stop_queue(netdev); |
| 1043 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1044 | e1e_rphy(hw, PHY_STATUS, &phy_status); |
| 1045 | e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status); |
| 1046 | e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status); |
| 1047 | |
| 1048 | pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status); |
| 1049 | |
| 1050 | /* detected Hardware unit hang */ |
| 1051 | e_err("Detected Hardware Unit Hang:\n" |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1052 | " TDH <%x>\n" |
| 1053 | " TDT <%x>\n" |
| 1054 | " next_to_use <%x>\n" |
| 1055 | " next_to_clean <%x>\n" |
| 1056 | "buffer_info[next_to_clean]:\n" |
| 1057 | " time_stamp <%lx>\n" |
| 1058 | " next_to_watch <%x>\n" |
| 1059 | " jiffies <%lx>\n" |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1060 | " next_to_watch.status <%x>\n" |
| 1061 | "MAC Status <%x>\n" |
| 1062 | "PHY Status <%x>\n" |
| 1063 | "PHY 1000BASE-T Status <%x>\n" |
| 1064 | "PHY Extended Status <%x>\n" |
| 1065 | "PCI Status <%x>\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1066 | readl(adapter->hw.hw_addr + tx_ring->head), |
| 1067 | readl(adapter->hw.hw_addr + tx_ring->tail), |
| 1068 | tx_ring->next_to_use, |
| 1069 | tx_ring->next_to_clean, |
| 1070 | tx_ring->buffer_info[eop].time_stamp, |
| 1071 | eop, |
| 1072 | jiffies, |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1073 | eop_desc->upper.fields.status, |
| 1074 | er32(STATUS), |
| 1075 | phy_status, |
| 1076 | phy_1000t_status, |
| 1077 | phy_ext_status, |
| 1078 | pci_status); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | /** |
| 1082 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 1083 | * @adapter: board private structure |
| 1084 | * |
| 1085 | * the return value indicates whether actual cleaning was done, there |
| 1086 | * is no guarantee that everything was cleaned |
| 1087 | **/ |
| 1088 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter) |
| 1089 | { |
| 1090 | struct net_device *netdev = adapter->netdev; |
| 1091 | struct e1000_hw *hw = &adapter->hw; |
| 1092 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1093 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 1094 | struct e1000_buffer *buffer_info; |
| 1095 | unsigned int i, eop; |
| 1096 | unsigned int count = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1097 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1098 | unsigned int bytes_compl = 0, pkts_compl = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1099 | |
| 1100 | i = tx_ring->next_to_clean; |
| 1101 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1102 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 1103 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1104 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 1105 | (count < tx_ring->count)) { |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1106 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1107 | rmb(); /* read buffer_info after eop_desc */ |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1108 | for (; !cleaned; count++) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1109 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 1110 | buffer_info = &tx_ring->buffer_info[i]; |
| 1111 | cleaned = (i == eop); |
| 1112 | |
| 1113 | if (cleaned) { |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 1114 | total_tx_packets += buffer_info->segs; |
| 1115 | total_tx_bytes += buffer_info->bytecount; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1116 | if (buffer_info->skb) { |
| 1117 | bytes_compl += buffer_info->skb->len; |
| 1118 | pkts_compl++; |
| 1119 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | e1000_put_txbuf(adapter, buffer_info); |
| 1123 | tx_desc->upper.data = 0; |
| 1124 | |
| 1125 | i++; |
| 1126 | if (i == tx_ring->count) |
| 1127 | i = 0; |
| 1128 | } |
| 1129 | |
Terry Loftin | dac8761 | 2010-04-09 10:29:49 +0000 | [diff] [blame] | 1130 | if (i == tx_ring->next_to_use) |
| 1131 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1132 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1133 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | tx_ring->next_to_clean = i; |
| 1137 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1138 | netdev_completed_queue(netdev, pkts_compl, bytes_compl); |
| 1139 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1140 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1141 | if (count && netif_carrier_ok(netdev) && |
| 1142 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1143 | /* Make sure that anybody stopping the queue after this |
| 1144 | * sees the new next_to_clean. |
| 1145 | */ |
| 1146 | smp_mb(); |
| 1147 | |
| 1148 | if (netif_queue_stopped(netdev) && |
| 1149 | !(test_bit(__E1000_DOWN, &adapter->state))) { |
| 1150 | netif_wake_queue(netdev); |
| 1151 | ++adapter->restart_queue; |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | if (adapter->detect_tx_hung) { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1156 | /* |
| 1157 | * Detect a transmit hang in hardware, this serializes the |
| 1158 | * check with the clearing of time_stamp and movement of i |
| 1159 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1160 | adapter->detect_tx_hung = 0; |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1161 | if (tx_ring->buffer_info[i].time_stamp && |
| 1162 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1163 | + (adapter->tx_timeout_factor * HZ)) && |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1164 | !(er32(STATUS) & E1000_STATUS_TXOFF)) |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1165 | schedule_work(&adapter->print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1166 | else |
| 1167 | adapter->tx_hang_recheck = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1168 | } |
| 1169 | adapter->total_tx_bytes += total_tx_bytes; |
| 1170 | adapter->total_tx_packets += total_tx_packets; |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1171 | return count < tx_ring->count; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1175 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
| 1176 | * @adapter: board private structure |
| 1177 | * |
| 1178 | * the return value indicates whether actual cleaning was done, there |
| 1179 | * is no guarantee that everything was cleaned |
| 1180 | **/ |
| 1181 | static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 1182 | int *work_done, int work_to_do) |
| 1183 | { |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1184 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1185 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
| 1186 | struct net_device *netdev = adapter->netdev; |
| 1187 | struct pci_dev *pdev = adapter->pdev; |
| 1188 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1189 | struct e1000_buffer *buffer_info, *next_buffer; |
| 1190 | struct e1000_ps_page *ps_page; |
| 1191 | struct sk_buff *skb; |
| 1192 | unsigned int i, j; |
| 1193 | u32 length, staterr; |
| 1194 | int cleaned_count = 0; |
| 1195 | bool cleaned = 0; |
| 1196 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 1197 | |
| 1198 | i = rx_ring->next_to_clean; |
| 1199 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 1200 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1201 | buffer_info = &rx_ring->buffer_info[i]; |
| 1202 | |
| 1203 | while (staterr & E1000_RXD_STAT_DD) { |
| 1204 | if (*work_done >= work_to_do) |
| 1205 | break; |
| 1206 | (*work_done)++; |
| 1207 | skb = buffer_info->skb; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1208 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1209 | |
| 1210 | /* in the packet split case this is header only */ |
| 1211 | prefetch(skb->data - NET_IP_ALIGN); |
| 1212 | |
| 1213 | i++; |
| 1214 | if (i == rx_ring->count) |
| 1215 | i = 0; |
| 1216 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
| 1217 | prefetch(next_rxd); |
| 1218 | |
| 1219 | next_buffer = &rx_ring->buffer_info[i]; |
| 1220 | |
| 1221 | cleaned = 1; |
| 1222 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1223 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1224 | adapter->rx_ps_bsize0, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1225 | buffer_info->dma = 0; |
| 1226 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1227 | /* see !EOP comment in other Rx routine */ |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1228 | if (!(staterr & E1000_RXD_STAT_EOP)) |
| 1229 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 1230 | |
| 1231 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1232 | e_dbg("Packet Split buffers didn't pick up the full packet\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1233 | dev_kfree_skb_irq(skb); |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1234 | if (staterr & E1000_RXD_STAT_EOP) |
| 1235 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1236 | goto next_desc; |
| 1237 | } |
| 1238 | |
| 1239 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
| 1240 | dev_kfree_skb_irq(skb); |
| 1241 | goto next_desc; |
| 1242 | } |
| 1243 | |
| 1244 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 1245 | |
| 1246 | if (!length) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1247 | e_dbg("Last part of the packet spanning multiple descriptors\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1248 | dev_kfree_skb_irq(skb); |
| 1249 | goto next_desc; |
| 1250 | } |
| 1251 | |
| 1252 | /* Good Receive */ |
| 1253 | skb_put(skb, length); |
| 1254 | |
| 1255 | { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1256 | /* |
| 1257 | * this looks ugly, but it seems compiler issues make it |
| 1258 | * more efficient than reusing j |
| 1259 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1260 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 1261 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1262 | /* |
| 1263 | * page alloc/put takes too long and effects small packet |
| 1264 | * throughput, so unsplit small packets and save the alloc/put |
| 1265 | * only valid in softirq (napi) context to call kmap_* |
| 1266 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1267 | if (l1 && (l1 <= copybreak) && |
| 1268 | ((length + l1) <= adapter->rx_ps_bsize0)) { |
| 1269 | u8 *vaddr; |
| 1270 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1271 | ps_page = &buffer_info->ps_pages[0]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1272 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1273 | /* |
| 1274 | * there is no documentation about how to call |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1275 | * kmap_atomic, so we can't hold the mapping |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1276 | * very long |
| 1277 | */ |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1278 | dma_sync_single_for_cpu(&pdev->dev, ps_page->dma, |
| 1279 | PAGE_SIZE, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1280 | vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ); |
| 1281 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
| 1282 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1283 | dma_sync_single_for_device(&pdev->dev, ps_page->dma, |
| 1284 | PAGE_SIZE, DMA_FROM_DEVICE); |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 1285 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1286 | /* remove the CRC */ |
| 1287 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 1288 | l1 -= 4; |
| 1289 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1290 | skb_put(skb, l1); |
| 1291 | goto copydone; |
| 1292 | } /* if */ |
| 1293 | } |
| 1294 | |
| 1295 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
| 1296 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); |
| 1297 | if (!length) |
| 1298 | break; |
| 1299 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1300 | ps_page = &buffer_info->ps_pages[j]; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1301 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1302 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1303 | ps_page->dma = 0; |
| 1304 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); |
| 1305 | ps_page->page = NULL; |
| 1306 | skb->len += length; |
| 1307 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1308 | skb->truesize += PAGE_SIZE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1311 | /* strip the ethernet crc, problem is we're using pages now so |
| 1312 | * this whole operation can get a little cpu intensive |
| 1313 | */ |
| 1314 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 1315 | pskb_trim(skb, skb->len - 4); |
| 1316 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1317 | copydone: |
| 1318 | total_rx_bytes += skb->len; |
| 1319 | total_rx_packets++; |
| 1320 | |
| 1321 | e1000_rx_checksum(adapter, staterr, le16_to_cpu( |
| 1322 | rx_desc->wb.lower.hi_dword.csum_ip.csum), skb); |
| 1323 | |
| 1324 | if (rx_desc->wb.upper.header_status & |
| 1325 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) |
| 1326 | adapter->rx_hdr_split++; |
| 1327 | |
| 1328 | e1000_receive_skb(adapter, netdev, skb, |
| 1329 | staterr, rx_desc->wb.middle.vlan); |
| 1330 | |
| 1331 | next_desc: |
| 1332 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
| 1333 | buffer_info->skb = NULL; |
| 1334 | |
| 1335 | /* return some buffers to hardware, one at a time is too slow */ |
| 1336 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1337 | adapter->alloc_rx_buf(adapter, cleaned_count, |
| 1338 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1339 | cleaned_count = 0; |
| 1340 | } |
| 1341 | |
| 1342 | /* use prefetched values */ |
| 1343 | rx_desc = next_rxd; |
| 1344 | buffer_info = next_buffer; |
| 1345 | |
| 1346 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1347 | } |
| 1348 | rx_ring->next_to_clean = i; |
| 1349 | |
| 1350 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1351 | if (cleaned_count) |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1352 | adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1353 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1354 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1355 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1356 | return cleaned; |
| 1357 | } |
| 1358 | |
| 1359 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1360 | * e1000_consume_page - helper function |
| 1361 | **/ |
| 1362 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
| 1363 | u16 length) |
| 1364 | { |
| 1365 | bi->page = NULL; |
| 1366 | skb->len += length; |
| 1367 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1368 | skb->truesize += PAGE_SIZE; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | /** |
| 1372 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 1373 | * @adapter: board private structure |
| 1374 | * |
| 1375 | * the return value indicates whether actual cleaning was done, there |
| 1376 | * is no guarantee that everything was cleaned |
| 1377 | **/ |
| 1378 | |
| 1379 | static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, |
| 1380 | int *work_done, int work_to_do) |
| 1381 | { |
| 1382 | struct net_device *netdev = adapter->netdev; |
| 1383 | struct pci_dev *pdev = adapter->pdev; |
| 1384 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1385 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1386 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1387 | u32 length, staterr; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1388 | unsigned int i; |
| 1389 | int cleaned_count = 0; |
| 1390 | bool cleaned = false; |
| 1391 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
| 1392 | |
| 1393 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1394 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 1395 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1396 | buffer_info = &rx_ring->buffer_info[i]; |
| 1397 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1398 | while (staterr & E1000_RXD_STAT_DD) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1399 | struct sk_buff *skb; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1400 | |
| 1401 | if (*work_done >= work_to_do) |
| 1402 | break; |
| 1403 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1404 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1405 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1406 | skb = buffer_info->skb; |
| 1407 | buffer_info->skb = NULL; |
| 1408 | |
| 1409 | ++i; |
| 1410 | if (i == rx_ring->count) |
| 1411 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1412 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1413 | prefetch(next_rxd); |
| 1414 | |
| 1415 | next_buffer = &rx_ring->buffer_info[i]; |
| 1416 | |
| 1417 | cleaned = true; |
| 1418 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1419 | dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE, |
| 1420 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1421 | buffer_info->dma = 0; |
| 1422 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1423 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1424 | |
| 1425 | /* errors is only valid for DD + EOP descriptors */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1426 | if (unlikely((staterr & E1000_RXD_STAT_EOP) && |
| 1427 | (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) { |
| 1428 | /* recycle both page and skb */ |
| 1429 | buffer_info->skb = skb; |
| 1430 | /* an error means any chain goes out the window too */ |
| 1431 | if (rx_ring->rx_skb_top) |
| 1432 | dev_kfree_skb_irq(rx_ring->rx_skb_top); |
| 1433 | rx_ring->rx_skb_top = NULL; |
| 1434 | goto next_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
Bruce Allan | f0f1a17 | 2010-12-11 05:53:32 +0000 | [diff] [blame] | 1437 | #define rxtop (rx_ring->rx_skb_top) |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1438 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1439 | /* this descriptor is only the beginning (or middle) */ |
| 1440 | if (!rxtop) { |
| 1441 | /* this is the beginning of a chain */ |
| 1442 | rxtop = skb; |
| 1443 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
| 1444 | 0, length); |
| 1445 | } else { |
| 1446 | /* this is the middle of a chain */ |
| 1447 | skb_fill_page_desc(rxtop, |
| 1448 | skb_shinfo(rxtop)->nr_frags, |
| 1449 | buffer_info->page, 0, length); |
| 1450 | /* re-use the skb, only consumed the page */ |
| 1451 | buffer_info->skb = skb; |
| 1452 | } |
| 1453 | e1000_consume_page(buffer_info, rxtop, length); |
| 1454 | goto next_desc; |
| 1455 | } else { |
| 1456 | if (rxtop) { |
| 1457 | /* end of the chain */ |
| 1458 | skb_fill_page_desc(rxtop, |
| 1459 | skb_shinfo(rxtop)->nr_frags, |
| 1460 | buffer_info->page, 0, length); |
| 1461 | /* re-use the current skb, we only consumed the |
| 1462 | * page */ |
| 1463 | buffer_info->skb = skb; |
| 1464 | skb = rxtop; |
| 1465 | rxtop = NULL; |
| 1466 | e1000_consume_page(buffer_info, skb, length); |
| 1467 | } else { |
| 1468 | /* no chain, got EOP, this buf is the packet |
| 1469 | * copybreak to save the put_page/alloc_page */ |
| 1470 | if (length <= copybreak && |
| 1471 | skb_tailroom(skb) >= length) { |
| 1472 | u8 *vaddr; |
| 1473 | vaddr = kmap_atomic(buffer_info->page, |
| 1474 | KM_SKB_DATA_SOFTIRQ); |
| 1475 | memcpy(skb_tail_pointer(skb), vaddr, |
| 1476 | length); |
| 1477 | kunmap_atomic(vaddr, |
| 1478 | KM_SKB_DATA_SOFTIRQ); |
| 1479 | /* re-use the page, so don't erase |
| 1480 | * buffer_info->page */ |
| 1481 | skb_put(skb, length); |
| 1482 | } else { |
| 1483 | skb_fill_page_desc(skb, 0, |
| 1484 | buffer_info->page, 0, |
| 1485 | length); |
| 1486 | e1000_consume_page(buffer_info, skb, |
| 1487 | length); |
| 1488 | } |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | /* Receive Checksum Offload XXX recompute due to CRC strip? */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1493 | e1000_rx_checksum(adapter, staterr, |
| 1494 | le16_to_cpu(rx_desc->wb.lower.hi_dword. |
| 1495 | csum_ip.csum), skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1496 | |
| 1497 | /* probably a little skewed due to removing CRC */ |
| 1498 | total_rx_bytes += skb->len; |
| 1499 | total_rx_packets++; |
| 1500 | |
| 1501 | /* eth type trans needs skb->data to point to something */ |
| 1502 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1503 | e_err("pskb_may_pull failed.\n"); |
Bruce Allan | ef5ab89 | 2011-02-10 08:17:21 +0000 | [diff] [blame] | 1504 | dev_kfree_skb_irq(skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1505 | goto next_desc; |
| 1506 | } |
| 1507 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1508 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1509 | rx_desc->wb.upper.vlan); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1510 | |
| 1511 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1512 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1513 | |
| 1514 | /* return some buffers to hardware, one at a time is too slow */ |
| 1515 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1516 | adapter->alloc_rx_buf(adapter, cleaned_count, |
| 1517 | GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1518 | cleaned_count = 0; |
| 1519 | } |
| 1520 | |
| 1521 | /* use prefetched values */ |
| 1522 | rx_desc = next_rxd; |
| 1523 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1524 | |
| 1525 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1526 | } |
| 1527 | rx_ring->next_to_clean = i; |
| 1528 | |
| 1529 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1530 | if (cleaned_count) |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1531 | adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1532 | |
| 1533 | adapter->total_rx_bytes += total_rx_bytes; |
| 1534 | adapter->total_rx_packets += total_rx_packets; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1535 | return cleaned; |
| 1536 | } |
| 1537 | |
| 1538 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1539 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 1540 | * @adapter: board private structure |
| 1541 | **/ |
| 1542 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter) |
| 1543 | { |
| 1544 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1545 | struct e1000_buffer *buffer_info; |
| 1546 | struct e1000_ps_page *ps_page; |
| 1547 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1548 | unsigned int i, j; |
| 1549 | |
| 1550 | /* Free all the Rx ring sk_buffs */ |
| 1551 | for (i = 0; i < rx_ring->count; i++) { |
| 1552 | buffer_info = &rx_ring->buffer_info[i]; |
| 1553 | if (buffer_info->dma) { |
| 1554 | if (adapter->clean_rx == e1000_clean_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1555 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1556 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1557 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1558 | else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1559 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1560 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1561 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1562 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1563 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1564 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1565 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1566 | buffer_info->dma = 0; |
| 1567 | } |
| 1568 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1569 | if (buffer_info->page) { |
| 1570 | put_page(buffer_info->page); |
| 1571 | buffer_info->page = NULL; |
| 1572 | } |
| 1573 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1574 | if (buffer_info->skb) { |
| 1575 | dev_kfree_skb(buffer_info->skb); |
| 1576 | buffer_info->skb = NULL; |
| 1577 | } |
| 1578 | |
| 1579 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1580 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1581 | if (!ps_page->page) |
| 1582 | break; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1583 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1584 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1585 | ps_page->dma = 0; |
| 1586 | put_page(ps_page->page); |
| 1587 | ps_page->page = NULL; |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | /* there also may be some cached data from a chained receive */ |
| 1592 | if (rx_ring->rx_skb_top) { |
| 1593 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 1594 | rx_ring->rx_skb_top = NULL; |
| 1595 | } |
| 1596 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1597 | /* Zero out the descriptor ring */ |
| 1598 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1599 | |
| 1600 | rx_ring->next_to_clean = 0; |
| 1601 | rx_ring->next_to_use = 0; |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1602 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1603 | |
| 1604 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 1605 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
| 1606 | } |
| 1607 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1608 | static void e1000e_downshift_workaround(struct work_struct *work) |
| 1609 | { |
| 1610 | struct e1000_adapter *adapter = container_of(work, |
| 1611 | struct e1000_adapter, downshift_task); |
| 1612 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1613 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1614 | return; |
| 1615 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1616 | e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); |
| 1617 | } |
| 1618 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1619 | /** |
| 1620 | * e1000_intr_msi - Interrupt Handler |
| 1621 | * @irq: interrupt number |
| 1622 | * @data: pointer to a network interface device structure |
| 1623 | **/ |
| 1624 | static irqreturn_t e1000_intr_msi(int irq, void *data) |
| 1625 | { |
| 1626 | struct net_device *netdev = data; |
| 1627 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1628 | struct e1000_hw *hw = &adapter->hw; |
| 1629 | u32 icr = er32(ICR); |
| 1630 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1631 | /* |
| 1632 | * read ICR disables interrupts using IAM |
| 1633 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1634 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1635 | if (icr & E1000_ICR_LSC) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1636 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1637 | /* |
| 1638 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1639 | * disconnect (LSC) before accessing any PHY registers |
| 1640 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1641 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1642 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1643 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1644 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1645 | /* |
| 1646 | * 80003ES2LAN workaround-- For packet buffer work-around on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1647 | * link down event; disable receives here in the ISR and reset |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1648 | * adapter in watchdog |
| 1649 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1650 | if (netif_carrier_ok(netdev) && |
| 1651 | adapter->flags & FLAG_RX_NEEDS_RESTART) { |
| 1652 | /* disable receives */ |
| 1653 | u32 rctl = er32(RCTL); |
| 1654 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1655 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1656 | } |
| 1657 | /* guard against interrupt when we're going down */ |
| 1658 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1659 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1660 | } |
| 1661 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1662 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1663 | adapter->total_tx_bytes = 0; |
| 1664 | adapter->total_tx_packets = 0; |
| 1665 | adapter->total_rx_bytes = 0; |
| 1666 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1667 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | return IRQ_HANDLED; |
| 1671 | } |
| 1672 | |
| 1673 | /** |
| 1674 | * e1000_intr - Interrupt Handler |
| 1675 | * @irq: interrupt number |
| 1676 | * @data: pointer to a network interface device structure |
| 1677 | **/ |
| 1678 | static irqreturn_t e1000_intr(int irq, void *data) |
| 1679 | { |
| 1680 | struct net_device *netdev = data; |
| 1681 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1682 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1683 | u32 rctl, icr = er32(ICR); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1684 | |
Bruce Allan | a68ea77 | 2009-11-20 23:23:16 +0000 | [diff] [blame] | 1685 | if (!icr || test_bit(__E1000_DOWN, &adapter->state)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1686 | return IRQ_NONE; /* Not our interrupt */ |
| 1687 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1688 | /* |
| 1689 | * IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 1690 | * not set, then the adapter didn't send an interrupt |
| 1691 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1692 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 1693 | return IRQ_NONE; |
| 1694 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1695 | /* |
| 1696 | * Interrupt Auto-Mask...upon reading ICR, |
| 1697 | * interrupts are masked. No need for the |
| 1698 | * IMC write |
| 1699 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1700 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1701 | if (icr & E1000_ICR_LSC) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1702 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1703 | /* |
| 1704 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1705 | * disconnect (LSC) before accessing any PHY registers |
| 1706 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1707 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1708 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1709 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1710 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1711 | /* |
| 1712 | * 80003ES2LAN workaround-- |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1713 | * For packet buffer work-around on link down event; |
| 1714 | * disable receives here in the ISR and |
| 1715 | * reset adapter in watchdog |
| 1716 | */ |
| 1717 | if (netif_carrier_ok(netdev) && |
| 1718 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { |
| 1719 | /* disable receives */ |
| 1720 | rctl = er32(RCTL); |
| 1721 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1722 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1723 | } |
| 1724 | /* guard against interrupt when we're going down */ |
| 1725 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1726 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1727 | } |
| 1728 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1729 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1730 | adapter->total_tx_bytes = 0; |
| 1731 | adapter->total_tx_packets = 0; |
| 1732 | adapter->total_rx_bytes = 0; |
| 1733 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1734 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | return IRQ_HANDLED; |
| 1738 | } |
| 1739 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1740 | static irqreturn_t e1000_msix_other(int irq, void *data) |
| 1741 | { |
| 1742 | struct net_device *netdev = data; |
| 1743 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1744 | struct e1000_hw *hw = &adapter->hw; |
| 1745 | u32 icr = er32(ICR); |
| 1746 | |
| 1747 | if (!(icr & E1000_ICR_INT_ASSERTED)) { |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1748 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1749 | ew32(IMS, E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1750 | return IRQ_NONE; |
| 1751 | } |
| 1752 | |
| 1753 | if (icr & adapter->eiac_mask) |
| 1754 | ew32(ICS, (icr & adapter->eiac_mask)); |
| 1755 | |
| 1756 | if (icr & E1000_ICR_OTHER) { |
| 1757 | if (!(icr & E1000_ICR_LSC)) |
| 1758 | goto no_link_interrupt; |
| 1759 | hw->mac.get_link_status = 1; |
| 1760 | /* guard against interrupt when we're going down */ |
| 1761 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1762 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1763 | } |
| 1764 | |
| 1765 | no_link_interrupt: |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1766 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1767 | ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1768 | |
| 1769 | return IRQ_HANDLED; |
| 1770 | } |
| 1771 | |
| 1772 | |
| 1773 | static irqreturn_t e1000_intr_msix_tx(int irq, void *data) |
| 1774 | { |
| 1775 | struct net_device *netdev = data; |
| 1776 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1777 | struct e1000_hw *hw = &adapter->hw; |
| 1778 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1779 | |
| 1780 | |
| 1781 | adapter->total_tx_bytes = 0; |
| 1782 | adapter->total_tx_packets = 0; |
| 1783 | |
| 1784 | if (!e1000_clean_tx_irq(adapter)) |
| 1785 | /* Ring was not completely cleaned, so fire another interrupt */ |
| 1786 | ew32(ICS, tx_ring->ims_val); |
| 1787 | |
| 1788 | return IRQ_HANDLED; |
| 1789 | } |
| 1790 | |
| 1791 | static irqreturn_t e1000_intr_msix_rx(int irq, void *data) |
| 1792 | { |
| 1793 | struct net_device *netdev = data; |
| 1794 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1795 | |
| 1796 | /* Write the ITR value calculated at the end of the |
| 1797 | * previous interrupt. |
| 1798 | */ |
| 1799 | if (adapter->rx_ring->set_itr) { |
| 1800 | writel(1000000000 / (adapter->rx_ring->itr_val * 256), |
| 1801 | adapter->hw.hw_addr + adapter->rx_ring->itr_register); |
| 1802 | adapter->rx_ring->set_itr = 0; |
| 1803 | } |
| 1804 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1805 | if (napi_schedule_prep(&adapter->napi)) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1806 | adapter->total_rx_bytes = 0; |
| 1807 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1808 | __napi_schedule(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1809 | } |
| 1810 | return IRQ_HANDLED; |
| 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * e1000_configure_msix - Configure MSI-X hardware |
| 1815 | * |
| 1816 | * e1000_configure_msix sets up the hardware to properly |
| 1817 | * generate MSI-X interrupts. |
| 1818 | **/ |
| 1819 | static void e1000_configure_msix(struct e1000_adapter *adapter) |
| 1820 | { |
| 1821 | struct e1000_hw *hw = &adapter->hw; |
| 1822 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1823 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1824 | int vector = 0; |
| 1825 | u32 ctrl_ext, ivar = 0; |
| 1826 | |
| 1827 | adapter->eiac_mask = 0; |
| 1828 | |
| 1829 | /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ |
| 1830 | if (hw->mac.type == e1000_82574) { |
| 1831 | u32 rfctl = er32(RFCTL); |
| 1832 | rfctl |= E1000_RFCTL_ACK_DIS; |
| 1833 | ew32(RFCTL, rfctl); |
| 1834 | } |
| 1835 | |
| 1836 | #define E1000_IVAR_INT_ALLOC_VALID 0x8 |
| 1837 | /* Configure Rx vector */ |
| 1838 | rx_ring->ims_val = E1000_IMS_RXQ0; |
| 1839 | adapter->eiac_mask |= rx_ring->ims_val; |
| 1840 | if (rx_ring->itr_val) |
| 1841 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1842 | hw->hw_addr + rx_ring->itr_register); |
| 1843 | else |
| 1844 | writel(1, hw->hw_addr + rx_ring->itr_register); |
| 1845 | ivar = E1000_IVAR_INT_ALLOC_VALID | vector; |
| 1846 | |
| 1847 | /* Configure Tx vector */ |
| 1848 | tx_ring->ims_val = E1000_IMS_TXQ0; |
| 1849 | vector++; |
| 1850 | if (tx_ring->itr_val) |
| 1851 | writel(1000000000 / (tx_ring->itr_val * 256), |
| 1852 | hw->hw_addr + tx_ring->itr_register); |
| 1853 | else |
| 1854 | writel(1, hw->hw_addr + tx_ring->itr_register); |
| 1855 | adapter->eiac_mask |= tx_ring->ims_val; |
| 1856 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); |
| 1857 | |
| 1858 | /* set vector for Other Causes, e.g. link changes */ |
| 1859 | vector++; |
| 1860 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); |
| 1861 | if (rx_ring->itr_val) |
| 1862 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1863 | hw->hw_addr + E1000_EITR_82574(vector)); |
| 1864 | else |
| 1865 | writel(1, hw->hw_addr + E1000_EITR_82574(vector)); |
| 1866 | |
| 1867 | /* Cause Tx interrupts on every write back */ |
| 1868 | ivar |= (1 << 31); |
| 1869 | |
| 1870 | ew32(IVAR, ivar); |
| 1871 | |
| 1872 | /* enable MSI-X PBA support */ |
| 1873 | ctrl_ext = er32(CTRL_EXT); |
| 1874 | ctrl_ext |= E1000_CTRL_EXT_PBA_CLR; |
| 1875 | |
| 1876 | /* Auto-Mask Other interrupts upon ICR read */ |
| 1877 | #define E1000_EIAC_MASK_82574 0x01F00000 |
| 1878 | ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER); |
| 1879 | ctrl_ext |= E1000_CTRL_EXT_EIAME; |
| 1880 | ew32(CTRL_EXT, ctrl_ext); |
| 1881 | e1e_flush(); |
| 1882 | } |
| 1883 | |
| 1884 | void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) |
| 1885 | { |
| 1886 | if (adapter->msix_entries) { |
| 1887 | pci_disable_msix(adapter->pdev); |
| 1888 | kfree(adapter->msix_entries); |
| 1889 | adapter->msix_entries = NULL; |
| 1890 | } else if (adapter->flags & FLAG_MSI_ENABLED) { |
| 1891 | pci_disable_msi(adapter->pdev); |
| 1892 | adapter->flags &= ~FLAG_MSI_ENABLED; |
| 1893 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | /** |
| 1897 | * e1000e_set_interrupt_capability - set MSI or MSI-X if supported |
| 1898 | * |
| 1899 | * Attempt to configure interrupts using the best available |
| 1900 | * capabilities of the hardware and kernel. |
| 1901 | **/ |
| 1902 | void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) |
| 1903 | { |
| 1904 | int err; |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1905 | int i; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1906 | |
| 1907 | switch (adapter->int_mode) { |
| 1908 | case E1000E_INT_MODE_MSIX: |
| 1909 | if (adapter->flags & FLAG_HAS_MSIX) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1910 | adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */ |
| 1911 | adapter->msix_entries = kcalloc(adapter->num_vectors, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1912 | sizeof(struct msix_entry), |
| 1913 | GFP_KERNEL); |
| 1914 | if (adapter->msix_entries) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1915 | for (i = 0; i < adapter->num_vectors; i++) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1916 | adapter->msix_entries[i].entry = i; |
| 1917 | |
| 1918 | err = pci_enable_msix(adapter->pdev, |
| 1919 | adapter->msix_entries, |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1920 | adapter->num_vectors); |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 1921 | if (err == 0) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1922 | return; |
| 1923 | } |
| 1924 | /* MSI-X failed, so fall through and try MSI */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1925 | e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n"); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1926 | e1000e_reset_interrupt_capability(adapter); |
| 1927 | } |
| 1928 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 1929 | /* Fall through */ |
| 1930 | case E1000E_INT_MODE_MSI: |
| 1931 | if (!pci_enable_msi(adapter->pdev)) { |
| 1932 | adapter->flags |= FLAG_MSI_ENABLED; |
| 1933 | } else { |
| 1934 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1935 | e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n"); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1936 | } |
| 1937 | /* Fall through */ |
| 1938 | case E1000E_INT_MODE_LEGACY: |
| 1939 | /* Don't do anything; this is the system default */ |
| 1940 | break; |
| 1941 | } |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1942 | |
| 1943 | /* store the number of vectors being used */ |
| 1944 | adapter->num_vectors = 1; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | /** |
| 1948 | * e1000_request_msix - Initialize MSI-X interrupts |
| 1949 | * |
| 1950 | * e1000_request_msix allocates MSI-X vectors and requests interrupts from the |
| 1951 | * kernel. |
| 1952 | **/ |
| 1953 | static int e1000_request_msix(struct e1000_adapter *adapter) |
| 1954 | { |
| 1955 | struct net_device *netdev = adapter->netdev; |
| 1956 | int err = 0, vector = 0; |
| 1957 | |
| 1958 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 1959 | snprintf(adapter->rx_ring->name, |
| 1960 | sizeof(adapter->rx_ring->name) - 1, |
| 1961 | "%s-rx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1962 | else |
| 1963 | memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); |
| 1964 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1965 | e1000_intr_msix_rx, 0, adapter->rx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1966 | netdev); |
| 1967 | if (err) |
| 1968 | goto out; |
| 1969 | adapter->rx_ring->itr_register = E1000_EITR_82574(vector); |
| 1970 | adapter->rx_ring->itr_val = adapter->itr; |
| 1971 | vector++; |
| 1972 | |
| 1973 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 1974 | snprintf(adapter->tx_ring->name, |
| 1975 | sizeof(adapter->tx_ring->name) - 1, |
| 1976 | "%s-tx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1977 | else |
| 1978 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); |
| 1979 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1980 | e1000_intr_msix_tx, 0, adapter->tx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1981 | netdev); |
| 1982 | if (err) |
| 1983 | goto out; |
| 1984 | adapter->tx_ring->itr_register = E1000_EITR_82574(vector); |
| 1985 | adapter->tx_ring->itr_val = adapter->itr; |
| 1986 | vector++; |
| 1987 | |
| 1988 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1989 | e1000_msix_other, 0, netdev->name, netdev); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1990 | if (err) |
| 1991 | goto out; |
| 1992 | |
| 1993 | e1000_configure_msix(adapter); |
| 1994 | return 0; |
| 1995 | out: |
| 1996 | return err; |
| 1997 | } |
| 1998 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 1999 | /** |
| 2000 | * e1000_request_irq - initialize interrupts |
| 2001 | * |
| 2002 | * Attempts to configure interrupts using the best available |
| 2003 | * capabilities of the hardware and kernel. |
| 2004 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2005 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 2006 | { |
| 2007 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2008 | int err; |
| 2009 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2010 | if (adapter->msix_entries) { |
| 2011 | err = e1000_request_msix(adapter); |
| 2012 | if (!err) |
| 2013 | return err; |
| 2014 | /* fall back to MSI */ |
| 2015 | e1000e_reset_interrupt_capability(adapter); |
| 2016 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 2017 | e1000e_set_interrupt_capability(adapter); |
| 2018 | } |
| 2019 | if (adapter->flags & FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2020 | err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2021 | netdev->name, netdev); |
| 2022 | if (!err) |
| 2023 | return err; |
| 2024 | |
| 2025 | /* fall back to legacy interrupt */ |
| 2026 | e1000e_reset_interrupt_capability(adapter); |
| 2027 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2030 | err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2031 | netdev->name, netdev); |
| 2032 | if (err) |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2033 | e_err("Unable to allocate interrupt, Error: %d\n", err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2034 | |
| 2035 | return err; |
| 2036 | } |
| 2037 | |
| 2038 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 2039 | { |
| 2040 | struct net_device *netdev = adapter->netdev; |
| 2041 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2042 | if (adapter->msix_entries) { |
| 2043 | int vector = 0; |
| 2044 | |
| 2045 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2046 | vector++; |
| 2047 | |
| 2048 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2049 | vector++; |
| 2050 | |
| 2051 | /* Other Causes interrupt vector */ |
| 2052 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2053 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2054 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2055 | |
| 2056 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | /** |
| 2060 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 2061 | **/ |
| 2062 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
| 2063 | { |
| 2064 | struct e1000_hw *hw = &adapter->hw; |
| 2065 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2066 | ew32(IMC, ~0); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2067 | if (adapter->msix_entries) |
| 2068 | ew32(EIAC_82574, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2069 | e1e_flush(); |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2070 | |
| 2071 | if (adapter->msix_entries) { |
| 2072 | int i; |
| 2073 | for (i = 0; i < adapter->num_vectors; i++) |
| 2074 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2075 | } else { |
| 2076 | synchronize_irq(adapter->pdev->irq); |
| 2077 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | /** |
| 2081 | * e1000_irq_enable - Enable default interrupt generation settings |
| 2082 | **/ |
| 2083 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
| 2084 | { |
| 2085 | struct e1000_hw *hw = &adapter->hw; |
| 2086 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2087 | if (adapter->msix_entries) { |
| 2088 | ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); |
| 2089 | ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC); |
| 2090 | } else { |
| 2091 | ew32(IMS, IMS_ENABLE_MASK); |
| 2092 | } |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 2093 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2097 | * 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] | 2098 | * @adapter: address of board private structure |
| 2099 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2100 | * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2101 | * For ASF and Pass Through versions of f/w this means that |
| 2102 | * the driver is loaded. For AMT version (only with 82573) |
| 2103 | * of the f/w this means that the network i/f is open. |
| 2104 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2105 | void e1000e_get_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2106 | { |
| 2107 | struct e1000_hw *hw = &adapter->hw; |
| 2108 | u32 ctrl_ext; |
| 2109 | u32 swsm; |
| 2110 | |
| 2111 | /* Let firmware know the driver has taken over */ |
| 2112 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2113 | swsm = er32(SWSM); |
| 2114 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
| 2115 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2116 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2117 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2122 | * 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] | 2123 | * @adapter: address of board private structure |
| 2124 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2125 | * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2126 | * For ASF and Pass Through versions of f/w this means that the |
| 2127 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 2128 | * of the f/w this means that the network i/f is closed. |
| 2129 | * |
| 2130 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2131 | void e1000e_release_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2132 | { |
| 2133 | struct e1000_hw *hw = &adapter->hw; |
| 2134 | u32 ctrl_ext; |
| 2135 | u32 swsm; |
| 2136 | |
| 2137 | /* Let firmware taken over control of h/w */ |
| 2138 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2139 | swsm = er32(SWSM); |
| 2140 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
| 2141 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2142 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2143 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2144 | } |
| 2145 | } |
| 2146 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2147 | /** |
| 2148 | * @e1000_alloc_ring - allocate memory for a ring structure |
| 2149 | **/ |
| 2150 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, |
| 2151 | struct e1000_ring *ring) |
| 2152 | { |
| 2153 | struct pci_dev *pdev = adapter->pdev; |
| 2154 | |
| 2155 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, |
| 2156 | GFP_KERNEL); |
| 2157 | if (!ring->desc) |
| 2158 | return -ENOMEM; |
| 2159 | |
| 2160 | return 0; |
| 2161 | } |
| 2162 | |
| 2163 | /** |
| 2164 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) |
| 2165 | * @adapter: board private structure |
| 2166 | * |
| 2167 | * Return 0 on success, negative on failure |
| 2168 | **/ |
| 2169 | int e1000e_setup_tx_resources(struct e1000_adapter *adapter) |
| 2170 | { |
| 2171 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2172 | int err = -ENOMEM, size; |
| 2173 | |
| 2174 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2175 | tx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2176 | if (!tx_ring->buffer_info) |
| 2177 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2178 | |
| 2179 | /* round up to nearest 4K */ |
| 2180 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
| 2181 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2182 | |
| 2183 | err = e1000_alloc_ring_dma(adapter, tx_ring); |
| 2184 | if (err) |
| 2185 | goto err; |
| 2186 | |
| 2187 | tx_ring->next_to_use = 0; |
| 2188 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2189 | |
| 2190 | return 0; |
| 2191 | err: |
| 2192 | vfree(tx_ring->buffer_info); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 2193 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2194 | return err; |
| 2195 | } |
| 2196 | |
| 2197 | /** |
| 2198 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) |
| 2199 | * @adapter: board private structure |
| 2200 | * |
| 2201 | * Returns 0 on success, negative on failure |
| 2202 | **/ |
| 2203 | int e1000e_setup_rx_resources(struct e1000_adapter *adapter) |
| 2204 | { |
| 2205 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2206 | struct e1000_buffer *buffer_info; |
| 2207 | int i, size, desc_len, err = -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2208 | |
| 2209 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2210 | rx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2211 | if (!rx_ring->buffer_info) |
| 2212 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2213 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2214 | for (i = 0; i < rx_ring->count; i++) { |
| 2215 | buffer_info = &rx_ring->buffer_info[i]; |
| 2216 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, |
| 2217 | sizeof(struct e1000_ps_page), |
| 2218 | GFP_KERNEL); |
| 2219 | if (!buffer_info->ps_pages) |
| 2220 | goto err_pages; |
| 2221 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2222 | |
| 2223 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 2224 | |
| 2225 | /* Round up to nearest 4K */ |
| 2226 | rx_ring->size = rx_ring->count * desc_len; |
| 2227 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2228 | |
| 2229 | err = e1000_alloc_ring_dma(adapter, rx_ring); |
| 2230 | if (err) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2231 | goto err_pages; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2232 | |
| 2233 | rx_ring->next_to_clean = 0; |
| 2234 | rx_ring->next_to_use = 0; |
| 2235 | rx_ring->rx_skb_top = NULL; |
| 2236 | |
| 2237 | return 0; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2238 | |
| 2239 | err_pages: |
| 2240 | for (i = 0; i < rx_ring->count; i++) { |
| 2241 | buffer_info = &rx_ring->buffer_info[i]; |
| 2242 | kfree(buffer_info->ps_pages); |
| 2243 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2244 | err: |
| 2245 | vfree(rx_ring->buffer_info); |
Bruce Allan | e926244 | 2010-11-24 06:02:06 +0000 | [diff] [blame] | 2246 | e_err("Unable to allocate memory for the receive descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2247 | return err; |
| 2248 | } |
| 2249 | |
| 2250 | /** |
| 2251 | * e1000_clean_tx_ring - Free Tx Buffers |
| 2252 | * @adapter: board private structure |
| 2253 | **/ |
| 2254 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter) |
| 2255 | { |
| 2256 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2257 | struct e1000_buffer *buffer_info; |
| 2258 | unsigned long size; |
| 2259 | unsigned int i; |
| 2260 | |
| 2261 | for (i = 0; i < tx_ring->count; i++) { |
| 2262 | buffer_info = &tx_ring->buffer_info[i]; |
| 2263 | e1000_put_txbuf(adapter, buffer_info); |
| 2264 | } |
| 2265 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 2266 | netdev_reset_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2267 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2268 | memset(tx_ring->buffer_info, 0, size); |
| 2269 | |
| 2270 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2271 | |
| 2272 | tx_ring->next_to_use = 0; |
| 2273 | tx_ring->next_to_clean = 0; |
| 2274 | |
| 2275 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 2276 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
| 2277 | } |
| 2278 | |
| 2279 | /** |
| 2280 | * e1000e_free_tx_resources - Free Tx Resources per Queue |
| 2281 | * @adapter: board private structure |
| 2282 | * |
| 2283 | * Free all transmit software resources |
| 2284 | **/ |
| 2285 | void e1000e_free_tx_resources(struct e1000_adapter *adapter) |
| 2286 | { |
| 2287 | struct pci_dev *pdev = adapter->pdev; |
| 2288 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2289 | |
| 2290 | e1000_clean_tx_ring(adapter); |
| 2291 | |
| 2292 | vfree(tx_ring->buffer_info); |
| 2293 | tx_ring->buffer_info = NULL; |
| 2294 | |
| 2295 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 2296 | tx_ring->dma); |
| 2297 | tx_ring->desc = NULL; |
| 2298 | } |
| 2299 | |
| 2300 | /** |
| 2301 | * e1000e_free_rx_resources - Free Rx Resources |
| 2302 | * @adapter: board private structure |
| 2303 | * |
| 2304 | * Free all receive software resources |
| 2305 | **/ |
| 2306 | |
| 2307 | void e1000e_free_rx_resources(struct e1000_adapter *adapter) |
| 2308 | { |
| 2309 | struct pci_dev *pdev = adapter->pdev; |
| 2310 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2311 | int i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2312 | |
| 2313 | e1000_clean_rx_ring(adapter); |
| 2314 | |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2315 | for (i = 0; i < rx_ring->count; i++) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2316 | kfree(rx_ring->buffer_info[i].ps_pages); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2317 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2318 | vfree(rx_ring->buffer_info); |
| 2319 | rx_ring->buffer_info = NULL; |
| 2320 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2321 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 2322 | rx_ring->dma); |
| 2323 | rx_ring->desc = NULL; |
| 2324 | } |
| 2325 | |
| 2326 | /** |
| 2327 | * e1000_update_itr - update the dynamic ITR value based on statistics |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2328 | * @adapter: pointer to adapter |
| 2329 | * @itr_setting: current adapter->itr |
| 2330 | * @packets: the number of packets during this measurement interval |
| 2331 | * @bytes: the number of bytes during this measurement interval |
| 2332 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2333 | * Stores a new ITR value based on packets and byte |
| 2334 | * counts during the last interrupt. The advantage of per interrupt |
| 2335 | * computation is faster updates and more accurate ITR for the current |
| 2336 | * traffic pattern. Constants in this function were computed |
| 2337 | * based on theoretical maximum wire speed and thresholds were set based |
| 2338 | * on testing data as well as attempting to minimize response time |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2339 | * while increasing bulk throughput. This functionality is controlled |
| 2340 | * by the InterruptThrottleRate module parameter. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2341 | **/ |
| 2342 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
| 2343 | u16 itr_setting, int packets, |
| 2344 | int bytes) |
| 2345 | { |
| 2346 | unsigned int retval = itr_setting; |
| 2347 | |
| 2348 | if (packets == 0) |
| 2349 | goto update_itr_done; |
| 2350 | |
| 2351 | switch (itr_setting) { |
| 2352 | case lowest_latency: |
| 2353 | /* handle TSO and jumbo frames */ |
| 2354 | if (bytes/packets > 8000) |
| 2355 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2356 | else if ((packets < 5) && (bytes > 512)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2357 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2358 | break; |
| 2359 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2360 | if (bytes > 10000) { |
| 2361 | /* this if handles the TSO accounting */ |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2362 | if (bytes/packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2363 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2364 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2365 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2366 | else if ((packets > 35)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2367 | retval = lowest_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2368 | } else if (bytes/packets > 2000) { |
| 2369 | retval = bulk_latency; |
| 2370 | } else if (packets <= 2 && bytes < 512) { |
| 2371 | retval = lowest_latency; |
| 2372 | } |
| 2373 | break; |
| 2374 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2375 | if (bytes > 25000) { |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2376 | if (packets > 35) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2377 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2378 | } else if (bytes < 6000) { |
| 2379 | retval = low_latency; |
| 2380 | } |
| 2381 | break; |
| 2382 | } |
| 2383 | |
| 2384 | update_itr_done: |
| 2385 | return retval; |
| 2386 | } |
| 2387 | |
| 2388 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2389 | { |
| 2390 | struct e1000_hw *hw = &adapter->hw; |
| 2391 | u16 current_itr; |
| 2392 | u32 new_itr = adapter->itr; |
| 2393 | |
| 2394 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2395 | if (adapter->link_speed != SPEED_1000) { |
| 2396 | current_itr = 0; |
| 2397 | new_itr = 4000; |
| 2398 | goto set_itr_now; |
| 2399 | } |
| 2400 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2401 | if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 2402 | new_itr = 0; |
| 2403 | goto set_itr_now; |
| 2404 | } |
| 2405 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2406 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2407 | adapter->tx_itr, |
| 2408 | adapter->total_tx_packets, |
| 2409 | adapter->total_tx_bytes); |
| 2410 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2411 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2412 | adapter->tx_itr = low_latency; |
| 2413 | |
| 2414 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2415 | adapter->rx_itr, |
| 2416 | adapter->total_rx_packets, |
| 2417 | adapter->total_rx_bytes); |
| 2418 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2419 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2420 | adapter->rx_itr = low_latency; |
| 2421 | |
| 2422 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2423 | |
| 2424 | switch (current_itr) { |
| 2425 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2426 | case lowest_latency: |
| 2427 | new_itr = 70000; |
| 2428 | break; |
| 2429 | case low_latency: |
| 2430 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2431 | break; |
| 2432 | case bulk_latency: |
| 2433 | new_itr = 4000; |
| 2434 | break; |
| 2435 | default: |
| 2436 | break; |
| 2437 | } |
| 2438 | |
| 2439 | set_itr_now: |
| 2440 | if (new_itr != adapter->itr) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2441 | /* |
| 2442 | * this attempts to bias the interrupt rate towards Bulk |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2443 | * by adding intermediate steps when interrupt rate is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2444 | * increasing |
| 2445 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2446 | new_itr = new_itr > adapter->itr ? |
| 2447 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2448 | new_itr; |
| 2449 | adapter->itr = new_itr; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2450 | adapter->rx_ring->itr_val = new_itr; |
| 2451 | if (adapter->msix_entries) |
| 2452 | adapter->rx_ring->set_itr = 1; |
| 2453 | else |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2454 | if (new_itr) |
| 2455 | ew32(ITR, 1000000000 / (new_itr * 256)); |
| 2456 | else |
| 2457 | ew32(ITR, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2458 | } |
| 2459 | } |
| 2460 | |
| 2461 | /** |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2462 | * e1000_alloc_queues - Allocate memory for all rings |
| 2463 | * @adapter: board private structure to initialize |
| 2464 | **/ |
| 2465 | static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) |
| 2466 | { |
| 2467 | adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
| 2468 | if (!adapter->tx_ring) |
| 2469 | goto err; |
| 2470 | |
| 2471 | adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
| 2472 | if (!adapter->rx_ring) |
| 2473 | goto err; |
| 2474 | |
| 2475 | return 0; |
| 2476 | err: |
| 2477 | e_err("Unable to allocate memory for queues\n"); |
| 2478 | kfree(adapter->rx_ring); |
| 2479 | kfree(adapter->tx_ring); |
| 2480 | return -ENOMEM; |
| 2481 | } |
| 2482 | |
| 2483 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2484 | * e1000_clean - NAPI Rx polling callback |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2485 | * @napi: struct associated with this polling callback |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2486 | * @budget: amount of packets driver is allowed to process this poll |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2487 | **/ |
| 2488 | static int e1000_clean(struct napi_struct *napi, int budget) |
| 2489 | { |
| 2490 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2491 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2492 | struct net_device *poll_dev = adapter->netdev; |
Andy Gospodarek | 679e8a0 | 2009-06-18 11:57:37 +0000 | [diff] [blame] | 2493 | int tx_cleaned = 1, work_done = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2494 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 2495 | adapter = netdev_priv(poll_dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2496 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2497 | if (adapter->msix_entries && |
| 2498 | !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) |
| 2499 | goto clean_rx; |
| 2500 | |
Jesse Brandeburg | 92af3e9 | 2009-01-19 14:17:08 +0000 | [diff] [blame] | 2501 | tx_cleaned = e1000_clean_tx_irq(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2502 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2503 | clean_rx: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2504 | adapter->clean_rx(adapter, &work_done, budget); |
| 2505 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 2506 | if (!tx_cleaned) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2507 | work_done = budget; |
| 2508 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 2509 | /* If budget not fully consumed, exit the polling mode */ |
| 2510 | if (work_done < budget) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2511 | if (adapter->itr_setting & 3) |
| 2512 | e1000_set_itr(adapter); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2513 | napi_complete(napi); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 2514 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 2515 | if (adapter->msix_entries) |
| 2516 | ew32(IMS, adapter->rx_ring->ims_val); |
| 2517 | else |
| 2518 | e1000_irq_enable(adapter); |
| 2519 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | return work_done; |
| 2523 | } |
| 2524 | |
| 2525 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2526 | { |
| 2527 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2528 | struct e1000_hw *hw = &adapter->hw; |
| 2529 | u32 vfta, index; |
| 2530 | |
| 2531 | /* don't update vlan cookie if already programmed */ |
| 2532 | if ((adapter->hw.mng_cookie.status & |
| 2533 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2534 | (vid == adapter->mng_vlan_id)) |
| 2535 | return; |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2536 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2537 | /* add VID to filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2538 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2539 | index = (vid >> 5) & 0x7F; |
| 2540 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2541 | vfta |= (1 << (vid & 0x1F)); |
| 2542 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2543 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2544 | |
| 2545 | set_bit(vid, adapter->active_vlans); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2549 | { |
| 2550 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2551 | struct e1000_hw *hw = &adapter->hw; |
| 2552 | u32 vfta, index; |
| 2553 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2554 | if ((adapter->hw.mng_cookie.status & |
| 2555 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2556 | (vid == adapter->mng_vlan_id)) { |
| 2557 | /* release control to f/w */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2558 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2559 | return; |
| 2560 | } |
| 2561 | |
| 2562 | /* remove VID from filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2563 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2564 | index = (vid >> 5) & 0x7F; |
| 2565 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2566 | vfta &= ~(1 << (vid & 0x1F)); |
| 2567 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2568 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2569 | |
| 2570 | clear_bit(vid, adapter->active_vlans); |
| 2571 | } |
| 2572 | |
| 2573 | /** |
| 2574 | * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering |
| 2575 | * @adapter: board private structure to initialize |
| 2576 | **/ |
| 2577 | static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter) |
| 2578 | { |
| 2579 | struct net_device *netdev = adapter->netdev; |
| 2580 | struct e1000_hw *hw = &adapter->hw; |
| 2581 | u32 rctl; |
| 2582 | |
| 2583 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2584 | /* disable VLAN receive filtering */ |
| 2585 | rctl = er32(RCTL); |
| 2586 | rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN); |
| 2587 | ew32(RCTL, rctl); |
| 2588 | |
| 2589 | if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { |
| 2590 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 2591 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 2592 | } |
| 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | /** |
| 2597 | * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering |
| 2598 | * @adapter: board private structure to initialize |
| 2599 | **/ |
| 2600 | static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter) |
| 2601 | { |
| 2602 | struct e1000_hw *hw = &adapter->hw; |
| 2603 | u32 rctl; |
| 2604 | |
| 2605 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2606 | /* enable VLAN receive filtering */ |
| 2607 | rctl = er32(RCTL); |
| 2608 | rctl |= E1000_RCTL_VFE; |
| 2609 | rctl &= ~E1000_RCTL_CFIEN; |
| 2610 | ew32(RCTL, rctl); |
| 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | /** |
| 2615 | * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping |
| 2616 | * @adapter: board private structure to initialize |
| 2617 | **/ |
| 2618 | static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter) |
| 2619 | { |
| 2620 | struct e1000_hw *hw = &adapter->hw; |
| 2621 | u32 ctrl; |
| 2622 | |
| 2623 | /* disable VLAN tag insert/strip */ |
| 2624 | ctrl = er32(CTRL); |
| 2625 | ctrl &= ~E1000_CTRL_VME; |
| 2626 | ew32(CTRL, ctrl); |
| 2627 | } |
| 2628 | |
| 2629 | /** |
| 2630 | * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping |
| 2631 | * @adapter: board private structure to initialize |
| 2632 | **/ |
| 2633 | static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter) |
| 2634 | { |
| 2635 | struct e1000_hw *hw = &adapter->hw; |
| 2636 | u32 ctrl; |
| 2637 | |
| 2638 | /* enable VLAN tag insert/strip */ |
| 2639 | ctrl = er32(CTRL); |
| 2640 | ctrl |= E1000_CTRL_VME; |
| 2641 | ew32(CTRL, ctrl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 2645 | { |
| 2646 | struct net_device *netdev = adapter->netdev; |
| 2647 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 2648 | u16 old_vid = adapter->mng_vlan_id; |
| 2649 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2650 | if (adapter->hw.mng_cookie.status & |
| 2651 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
| 2652 | e1000_vlan_rx_add_vid(netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2653 | adapter->mng_vlan_id = vid; |
| 2654 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2655 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2656 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid)) |
| 2657 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
| 2661 | { |
| 2662 | u16 vid; |
| 2663 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2664 | e1000_vlan_rx_add_vid(adapter->netdev, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2665 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2666 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2667 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2668 | } |
| 2669 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2670 | static void e1000_init_manageability_pt(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2671 | { |
| 2672 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2673 | u32 manc, manc2h, mdef, i, j; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2674 | |
| 2675 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) |
| 2676 | return; |
| 2677 | |
| 2678 | manc = er32(MANC); |
| 2679 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2680 | /* |
| 2681 | * enable receiving management packets to the host. this will probably |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2682 | * generate destination unreachable messages from the host OS, but |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2683 | * the packets will be handled on SMBUS |
| 2684 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2685 | manc |= E1000_MANC_EN_MNG2HOST; |
| 2686 | manc2h = er32(MANC2H); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2687 | |
| 2688 | switch (hw->mac.type) { |
| 2689 | default: |
| 2690 | manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664); |
| 2691 | break; |
| 2692 | case e1000_82574: |
| 2693 | case e1000_82583: |
| 2694 | /* |
| 2695 | * Check if IPMI pass-through decision filter already exists; |
| 2696 | * if so, enable it. |
| 2697 | */ |
| 2698 | for (i = 0, j = 0; i < 8; i++) { |
| 2699 | mdef = er32(MDEF(i)); |
| 2700 | |
| 2701 | /* Ignore filters with anything other than IPMI ports */ |
Dan Carpenter | 3b21b50 | 2010-06-02 13:43:15 +0000 | [diff] [blame] | 2702 | if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2703 | continue; |
| 2704 | |
| 2705 | /* Enable this decision filter in MANC2H */ |
| 2706 | if (mdef) |
| 2707 | manc2h |= (1 << i); |
| 2708 | |
| 2709 | j |= mdef; |
| 2710 | } |
| 2711 | |
| 2712 | if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
| 2713 | break; |
| 2714 | |
| 2715 | /* Create new decision filter in an empty filter */ |
| 2716 | for (i = 0, j = 0; i < 8; i++) |
| 2717 | if (er32(MDEF(i)) == 0) { |
| 2718 | ew32(MDEF(i), (E1000_MDEF_PORT_623 | |
| 2719 | E1000_MDEF_PORT_664)); |
| 2720 | manc2h |= (1 << 1); |
| 2721 | j++; |
| 2722 | break; |
| 2723 | } |
| 2724 | |
| 2725 | if (!j) |
| 2726 | e_warn("Unable to create IPMI pass-through filter\n"); |
| 2727 | break; |
| 2728 | } |
| 2729 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2730 | ew32(MANC2H, manc2h); |
| 2731 | ew32(MANC, manc); |
| 2732 | } |
| 2733 | |
| 2734 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2735 | * e1000_configure_tx - Configure Transmit Unit after Reset |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2736 | * @adapter: board private structure |
| 2737 | * |
| 2738 | * Configure the Tx unit of the MAC after a reset. |
| 2739 | **/ |
| 2740 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
| 2741 | { |
| 2742 | struct e1000_hw *hw = &adapter->hw; |
| 2743 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2744 | u64 tdba; |
| 2745 | u32 tdlen, tctl, tipg, tarc; |
| 2746 | u32 ipgr1, ipgr2; |
| 2747 | |
| 2748 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 2749 | tdba = tx_ring->dma; |
| 2750 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2751 | ew32(TDBAL, (tdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2752 | ew32(TDBAH, (tdba >> 32)); |
| 2753 | ew32(TDLEN, tdlen); |
| 2754 | ew32(TDH, 0); |
| 2755 | ew32(TDT, 0); |
| 2756 | tx_ring->head = E1000_TDH; |
| 2757 | tx_ring->tail = E1000_TDT; |
| 2758 | |
| 2759 | /* Set the default values for the Tx Inter Packet Gap timer */ |
| 2760 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */ |
| 2761 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */ |
| 2762 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */ |
| 2763 | |
| 2764 | if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN) |
| 2765 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */ |
| 2766 | |
| 2767 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 2768 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
| 2769 | ew32(TIPG, tipg); |
| 2770 | |
| 2771 | /* Set the Tx Interrupt Delay register */ |
| 2772 | ew32(TIDV, adapter->tx_int_delay); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2773 | /* Tx irq moderation */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2774 | ew32(TADV, adapter->tx_abs_int_delay); |
| 2775 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2776 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 2777 | u32 txdctl = er32(TXDCTL(0)); |
| 2778 | txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH | |
| 2779 | E1000_TXDCTL_WTHRESH); |
| 2780 | /* |
| 2781 | * set up some performance related parameters to encourage the |
| 2782 | * hardware to use the bus more efficiently in bursts, depends |
| 2783 | * on the tx_int_delay to be enabled, |
| 2784 | * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time |
| 2785 | * hthresh = 1 ==> prefetch when one or more available |
| 2786 | * pthresh = 0x1f ==> prefetch if internal cache 31 or less |
| 2787 | * BEWARE: this seems to work but should be considered first if |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2788 | * there are Tx hangs or other Tx related bugs |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2789 | */ |
| 2790 | txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE; |
| 2791 | ew32(TXDCTL(0), txdctl); |
| 2792 | /* erratum work around: set txdctl the same for both queues */ |
| 2793 | ew32(TXDCTL(1), txdctl); |
| 2794 | } |
| 2795 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2796 | /* Program the Transmit Control Register */ |
| 2797 | tctl = er32(TCTL); |
| 2798 | tctl &= ~E1000_TCTL_CT; |
| 2799 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
| 2800 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 2801 | |
| 2802 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2803 | tarc = er32(TARC(0)); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2804 | /* |
| 2805 | * set the speed mode bit, we'll clear it if we're not at |
| 2806 | * gigabit link later |
| 2807 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2808 | #define SPEED_MODE_BIT (1 << 21) |
| 2809 | tarc |= SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2810 | ew32(TARC(0), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | /* errata: program both queues to unweighted RR */ |
| 2814 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2815 | tarc = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2816 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2817 | ew32(TARC(0), tarc); |
| 2818 | tarc = er32(TARC(1)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2819 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2820 | ew32(TARC(1), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2821 | } |
| 2822 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2823 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 2824 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 2825 | |
| 2826 | /* only set IDE if we are delaying interrupts using the timers */ |
| 2827 | if (adapter->tx_int_delay) |
| 2828 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
| 2829 | |
| 2830 | /* enable Report Status bit */ |
| 2831 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 2832 | |
| 2833 | ew32(TCTL, tctl); |
| 2834 | |
Simon Horman | edfea6e6 | 2009-06-08 14:28:36 +0000 | [diff] [blame] | 2835 | e1000e_config_collision_dist(hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | /** |
| 2839 | * e1000_setup_rctl - configure the receive control registers |
| 2840 | * @adapter: Board private structure |
| 2841 | **/ |
| 2842 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 2843 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
| 2844 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
| 2845 | { |
| 2846 | struct e1000_hw *hw = &adapter->hw; |
| 2847 | u32 rctl, rfctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2848 | u32 pages = 0; |
| 2849 | |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 2850 | /* Workaround Si errata on 82579 - configure jumbo frame flow */ |
| 2851 | if (hw->mac.type == e1000_pch2lan) { |
| 2852 | s32 ret_val; |
| 2853 | |
| 2854 | if (adapter->netdev->mtu > ETH_DATA_LEN) |
| 2855 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true); |
| 2856 | else |
| 2857 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false); |
Bruce Allan | dd93f95 | 2011-01-06 14:29:48 +0000 | [diff] [blame] | 2858 | |
| 2859 | if (ret_val) |
| 2860 | e_dbg("failed to enable jumbo frame workaround mode\n"); |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 2861 | } |
| 2862 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2863 | /* Program MC offset vector base */ |
| 2864 | rctl = er32(RCTL); |
| 2865 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 2866 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 2867 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 2868 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 2869 | |
| 2870 | /* Do not Store bad packets */ |
| 2871 | rctl &= ~E1000_RCTL_SBP; |
| 2872 | |
| 2873 | /* Enable Long Packet receive */ |
| 2874 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2875 | rctl &= ~E1000_RCTL_LPE; |
| 2876 | else |
| 2877 | rctl |= E1000_RCTL_LPE; |
| 2878 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 2879 | /* Some systems expect that the CRC is included in SMBUS traffic. The |
| 2880 | * hardware strips the CRC before sending to both SMBUS (BMC) and to |
| 2881 | * host memory when this is enabled |
| 2882 | */ |
| 2883 | if (adapter->flags2 & FLAG2_CRC_STRIPPING) |
| 2884 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 5918bd8 | 2008-02-12 15:20:24 -0800 | [diff] [blame] | 2885 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 2886 | /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ |
| 2887 | if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { |
| 2888 | u16 phy_data; |
| 2889 | |
| 2890 | e1e_rphy(hw, PHY_REG(770, 26), &phy_data); |
| 2891 | phy_data &= 0xfff8; |
| 2892 | phy_data |= (1 << 2); |
| 2893 | e1e_wphy(hw, PHY_REG(770, 26), phy_data); |
| 2894 | |
| 2895 | e1e_rphy(hw, 22, &phy_data); |
| 2896 | phy_data &= 0x0fff; |
| 2897 | phy_data |= (1 << 14); |
| 2898 | e1e_wphy(hw, 0x10, 0x2823); |
| 2899 | e1e_wphy(hw, 0x11, 0x0003); |
| 2900 | e1e_wphy(hw, 22, phy_data); |
| 2901 | } |
| 2902 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2903 | /* Setup buffer sizes */ |
| 2904 | rctl &= ~E1000_RCTL_SZ_4096; |
| 2905 | rctl |= E1000_RCTL_BSEX; |
| 2906 | switch (adapter->rx_buffer_len) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2907 | case 2048: |
| 2908 | default: |
| 2909 | rctl |= E1000_RCTL_SZ_2048; |
| 2910 | rctl &= ~E1000_RCTL_BSEX; |
| 2911 | break; |
| 2912 | case 4096: |
| 2913 | rctl |= E1000_RCTL_SZ_4096; |
| 2914 | break; |
| 2915 | case 8192: |
| 2916 | rctl |= E1000_RCTL_SZ_8192; |
| 2917 | break; |
| 2918 | case 16384: |
| 2919 | rctl |= E1000_RCTL_SZ_16384; |
| 2920 | break; |
| 2921 | } |
| 2922 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 2923 | /* Enable Extended Status in all Receive Descriptors */ |
| 2924 | rfctl = er32(RFCTL); |
| 2925 | rfctl |= E1000_RFCTL_EXTEN; |
| 2926 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2927 | /* |
| 2928 | * 82571 and greater support packet-split where the protocol |
| 2929 | * header is placed in skb->data and the packet data is |
| 2930 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 2931 | * In the case of a non-split, skb->data is linearly filled, |
| 2932 | * followed by the page buffers. Therefore, skb->data is |
| 2933 | * sized to hold the largest protocol header. |
| 2934 | * |
| 2935 | * allocations using alloc_page take too long for regular MTU |
| 2936 | * so only enable packet split for jumbo frames |
| 2937 | * |
| 2938 | * Using pages when the page size is greater than 16k wastes |
| 2939 | * a lot of memory, since we allocate 3 pages at all times |
| 2940 | * per packet. |
| 2941 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2942 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Bruce Allan | dbcb9fe | 2010-06-17 18:59:27 +0000 | [diff] [blame] | 2943 | if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) && |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2944 | (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2945 | adapter->rx_ps_pages = pages; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2946 | else |
| 2947 | adapter->rx_ps_pages = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2948 | |
| 2949 | if (adapter->rx_ps_pages) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 2950 | u32 psrctl = 0; |
| 2951 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2952 | /* |
| 2953 | * disable packet split support for IPv6 extension headers, |
| 2954 | * because some malformed IPv6 headers can hang the Rx |
| 2955 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2956 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
| 2957 | E1000_RFCTL_NEW_IPV6_EXT_DIS); |
| 2958 | |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 2959 | /* Enable Packet split descriptors */ |
| 2960 | rctl |= E1000_RCTL_DTYP_PS; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2961 | |
| 2962 | psrctl |= adapter->rx_ps_bsize0 >> |
| 2963 | E1000_PSRCTL_BSIZE0_SHIFT; |
| 2964 | |
| 2965 | switch (adapter->rx_ps_pages) { |
| 2966 | case 3: |
| 2967 | psrctl |= PAGE_SIZE << |
| 2968 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 2969 | case 2: |
| 2970 | psrctl |= PAGE_SIZE << |
| 2971 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 2972 | case 1: |
| 2973 | psrctl |= PAGE_SIZE >> |
| 2974 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 2975 | break; |
| 2976 | } |
| 2977 | |
| 2978 | ew32(PSRCTL, psrctl); |
| 2979 | } |
| 2980 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 2981 | ew32(RFCTL, rfctl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2982 | ew32(RCTL, rctl); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2983 | /* just started the receive unit, no need to restart */ |
| 2984 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | /** |
| 2988 | * e1000_configure_rx - Configure Receive Unit after Reset |
| 2989 | * @adapter: board private structure |
| 2990 | * |
| 2991 | * Configure the Rx unit of the MAC after a reset. |
| 2992 | **/ |
| 2993 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
| 2994 | { |
| 2995 | struct e1000_hw *hw = &adapter->hw; |
| 2996 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 2997 | u64 rdba; |
| 2998 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
| 2999 | |
| 3000 | if (adapter->rx_ps_pages) { |
| 3001 | /* this is a 32 byte descriptor */ |
| 3002 | rdlen = rx_ring->count * |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3003 | sizeof(union e1000_rx_desc_packet_split); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3004 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 3005 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3006 | } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3007 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3008 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 3009 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3010 | } else { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3011 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3012 | adapter->clean_rx = e1000_clean_rx_irq; |
| 3013 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 3014 | } |
| 3015 | |
| 3016 | /* disable receives while setting up the descriptors */ |
| 3017 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3018 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3019 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3020 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3021 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3022 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3023 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 3024 | /* |
| 3025 | * set the writeback threshold (only takes effect if the RDTR |
| 3026 | * 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] | 3027 | * enable prefetching of 0x20 Rx descriptors |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3028 | * granularity = 01 |
| 3029 | * wthresh = 04, |
| 3030 | * hthresh = 04, |
| 3031 | * pthresh = 0x20 |
| 3032 | */ |
| 3033 | ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3034 | ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3035 | |
| 3036 | /* |
| 3037 | * override the delay timers for enabling bursting, only if |
| 3038 | * the value was not set by the user via module options |
| 3039 | */ |
| 3040 | if (adapter->rx_int_delay == DEFAULT_RDTR) |
| 3041 | adapter->rx_int_delay = BURST_RDTR; |
| 3042 | if (adapter->rx_abs_int_delay == DEFAULT_RADV) |
| 3043 | adapter->rx_abs_int_delay = BURST_RADV; |
| 3044 | } |
| 3045 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3046 | /* set the Receive Delay Timer Register */ |
| 3047 | ew32(RDTR, adapter->rx_int_delay); |
| 3048 | |
| 3049 | /* irq moderation */ |
| 3050 | ew32(RADV, adapter->rx_abs_int_delay); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3051 | if ((adapter->itr_setting != 0) && (adapter->itr != 0)) |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3052 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3053 | |
| 3054 | ctrl_ext = er32(CTRL_EXT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3055 | /* Auto-Mask interrupts upon ICR access */ |
| 3056 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 3057 | ew32(IAM, 0xffffffff); |
| 3058 | ew32(CTRL_EXT, ctrl_ext); |
| 3059 | e1e_flush(); |
| 3060 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3061 | /* |
| 3062 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3063 | * the Base and Length of the Rx Descriptor Ring |
| 3064 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3065 | rdba = rx_ring->dma; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3066 | ew32(RDBAL, (rdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3067 | ew32(RDBAH, (rdba >> 32)); |
| 3068 | ew32(RDLEN, rdlen); |
| 3069 | ew32(RDH, 0); |
| 3070 | ew32(RDT, 0); |
| 3071 | rx_ring->head = E1000_RDH; |
| 3072 | rx_ring->tail = E1000_RDT; |
| 3073 | |
| 3074 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 3075 | rxcsum = er32(RXCSUM); |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 3076 | if (adapter->netdev->features & NETIF_F_RXCSUM) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3077 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 3078 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3079 | /* |
| 3080 | * IPv4 payload checksum for UDP fragments must be |
| 3081 | * used in conjunction with packet-split. |
| 3082 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3083 | if (adapter->rx_ps_pages) |
| 3084 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 3085 | } else { |
| 3086 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 3087 | /* no need to clear IPPCSE as it defaults to 0 */ |
| 3088 | } |
| 3089 | ew32(RXCSUM, rxcsum); |
| 3090 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3091 | /* |
| 3092 | * Enable early receives on supported devices, only takes effect when |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3093 | * 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] | 3094 | * units), e.g. using jumbo frames when setting to E1000_ERT_2048 |
| 3095 | */ |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3096 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 3097 | (adapter->hw.mac.type == e1000_pch2lan)) { |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3098 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3099 | u32 rxdctl = er32(RXDCTL(0)); |
| 3100 | ew32(RXDCTL(0), rxdctl | 0x3); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3101 | if (adapter->flags & FLAG_HAS_ERT) |
| 3102 | ew32(ERT, E1000_ERT_2048 | (1 << 13)); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3103 | /* |
| 3104 | * With jumbo frames and early-receive enabled, |
| 3105 | * excessive C-state transition latencies result in |
| 3106 | * dropped transactions. |
| 3107 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3108 | pm_qos_update_request(&adapter->netdev->pm_qos_req, 55); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3109 | } else { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3110 | pm_qos_update_request(&adapter->netdev->pm_qos_req, |
| 3111 | PM_QOS_DEFAULT_VALUE); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3112 | } |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3113 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3114 | |
| 3115 | /* Enable Receives */ |
| 3116 | ew32(RCTL, rctl); |
| 3117 | } |
| 3118 | |
| 3119 | /** |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3120 | * e1000e_write_mc_addr_list - write multicast addresses to MTA |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3121 | * @netdev: network interface device structure |
| 3122 | * |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3123 | * Writes multicast address list to the MTA hash table. |
| 3124 | * Returns: -ENOMEM on failure |
| 3125 | * 0 on no addresses written |
| 3126 | * X on writing X addresses to MTA |
| 3127 | */ |
| 3128 | static int e1000e_write_mc_addr_list(struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3129 | { |
| 3130 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3131 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3132 | struct netdev_hw_addr *ha; |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3133 | u8 *mta_list; |
| 3134 | int i; |
| 3135 | |
| 3136 | if (netdev_mc_empty(netdev)) { |
| 3137 | /* nothing to program, so clear mc list */ |
| 3138 | hw->mac.ops.update_mc_addr_list(hw, NULL, 0); |
| 3139 | return 0; |
| 3140 | } |
| 3141 | |
| 3142 | mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC); |
| 3143 | if (!mta_list) |
| 3144 | return -ENOMEM; |
| 3145 | |
| 3146 | /* update_mc_addr_list expects a packed array of only addresses. */ |
| 3147 | i = 0; |
| 3148 | netdev_for_each_mc_addr(ha, netdev) |
| 3149 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
| 3150 | |
| 3151 | hw->mac.ops.update_mc_addr_list(hw, mta_list, i); |
| 3152 | kfree(mta_list); |
| 3153 | |
| 3154 | return netdev_mc_count(netdev); |
| 3155 | } |
| 3156 | |
| 3157 | /** |
| 3158 | * e1000e_write_uc_addr_list - write unicast addresses to RAR table |
| 3159 | * @netdev: network interface device structure |
| 3160 | * |
| 3161 | * Writes unicast address list to the RAR table. |
| 3162 | * Returns: -ENOMEM on failure/insufficient address space |
| 3163 | * 0 on no addresses written |
| 3164 | * X on writing X addresses to the RAR table |
| 3165 | **/ |
| 3166 | static int e1000e_write_uc_addr_list(struct net_device *netdev) |
| 3167 | { |
| 3168 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3169 | struct e1000_hw *hw = &adapter->hw; |
| 3170 | unsigned int rar_entries = hw->mac.rar_entry_count; |
| 3171 | int count = 0; |
| 3172 | |
| 3173 | /* save a rar entry for our hardware address */ |
| 3174 | rar_entries--; |
| 3175 | |
| 3176 | /* save a rar entry for the LAA workaround */ |
| 3177 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) |
| 3178 | rar_entries--; |
| 3179 | |
| 3180 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3181 | if (netdev_uc_count(netdev) > rar_entries) |
| 3182 | return -ENOMEM; |
| 3183 | |
| 3184 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3185 | struct netdev_hw_addr *ha; |
| 3186 | |
| 3187 | /* |
| 3188 | * write the addresses in reverse order to avoid write |
| 3189 | * combining |
| 3190 | */ |
| 3191 | netdev_for_each_uc_addr(ha, netdev) { |
| 3192 | if (!rar_entries) |
| 3193 | break; |
| 3194 | e1000e_rar_set(hw, ha->addr, rar_entries--); |
| 3195 | count++; |
| 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | /* zero out the remaining RAR entries not used above */ |
| 3200 | for (; rar_entries > 0; rar_entries--) { |
| 3201 | ew32(RAH(rar_entries), 0); |
| 3202 | ew32(RAL(rar_entries), 0); |
| 3203 | } |
| 3204 | e1e_flush(); |
| 3205 | |
| 3206 | return count; |
| 3207 | } |
| 3208 | |
| 3209 | /** |
| 3210 | * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set |
| 3211 | * @netdev: network interface device structure |
| 3212 | * |
| 3213 | * The ndo_set_rx_mode entry point is called whenever the unicast or multicast |
| 3214 | * address list or the network interface flags are updated. This routine is |
| 3215 | * responsible for configuring the hardware for proper unicast, multicast, |
| 3216 | * promiscuous mode, and all-multi behavior. |
| 3217 | **/ |
| 3218 | static void e1000e_set_rx_mode(struct net_device *netdev) |
| 3219 | { |
| 3220 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3221 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3222 | u32 rctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3223 | |
| 3224 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3225 | rctl = er32(RCTL); |
| 3226 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3227 | /* clear the affected bits */ |
| 3228 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 3229 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3230 | if (netdev->flags & IFF_PROMISC) { |
| 3231 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3232 | /* Do not hardware filter VLANs in promisc mode */ |
| 3233 | e1000e_vlan_filter_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3234 | } else { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3235 | int count; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3236 | if (netdev->flags & IFF_ALLMULTI) { |
| 3237 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3238 | } else { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3239 | /* |
| 3240 | * Write addresses to the MTA, if the attempt fails |
| 3241 | * then we should just turn on promiscuous mode so |
| 3242 | * that we can at least receive multicast traffic |
| 3243 | */ |
| 3244 | count = e1000e_write_mc_addr_list(netdev); |
| 3245 | if (count < 0) |
| 3246 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3247 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3248 | e1000e_vlan_filter_enable(adapter); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3249 | /* |
| 3250 | * Write addresses to available RAR registers, if there is not |
| 3251 | * sufficient space to store all the addresses then enable |
| 3252 | * unicast promiscuous mode |
| 3253 | */ |
| 3254 | count = e1000e_write_uc_addr_list(netdev); |
| 3255 | if (count < 0) |
| 3256 | rctl |= E1000_RCTL_UPE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | ew32(RCTL, rctl); |
| 3260 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3261 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3262 | e1000e_vlan_strip_enable(adapter); |
| 3263 | else |
| 3264 | e1000e_vlan_strip_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3268 | * e1000_configure - configure the hardware for Rx and Tx |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3269 | * @adapter: private board structure |
| 3270 | **/ |
| 3271 | static void e1000_configure(struct e1000_adapter *adapter) |
| 3272 | { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3273 | e1000e_set_rx_mode(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3274 | |
| 3275 | e1000_restore_vlan(adapter); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 3276 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3277 | |
| 3278 | e1000_configure_tx(adapter); |
| 3279 | e1000_setup_rctl(adapter); |
| 3280 | e1000_configure_rx(adapter); |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 3281 | adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring), |
| 3282 | GFP_KERNEL); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3283 | } |
| 3284 | |
| 3285 | /** |
| 3286 | * e1000e_power_up_phy - restore link in case the phy was powered down |
| 3287 | * @adapter: address of board private structure |
| 3288 | * |
| 3289 | * The phy may be powered down to save power and turn off link when the |
| 3290 | * driver is unloaded and wake on lan is not enabled (among others) |
| 3291 | * *** this routine MUST be followed by a call to e1000e_reset *** |
| 3292 | **/ |
| 3293 | void e1000e_power_up_phy(struct e1000_adapter *adapter) |
| 3294 | { |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3295 | if (adapter->hw.phy.ops.power_up) |
| 3296 | adapter->hw.phy.ops.power_up(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3297 | |
| 3298 | adapter->hw.mac.ops.setup_link(&adapter->hw); |
| 3299 | } |
| 3300 | |
| 3301 | /** |
| 3302 | * e1000_power_down_phy - Power down the PHY |
| 3303 | * |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3304 | * Power down the PHY so no link is implied when interface is down. |
| 3305 | * The PHY cannot be powered down if management or WoL is active. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3306 | */ |
| 3307 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 3308 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3309 | /* WoL is enabled */ |
Auke Kok | 23b66e2 | 2008-02-11 09:25:51 -0800 | [diff] [blame] | 3310 | if (adapter->wol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3311 | return; |
| 3312 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3313 | if (adapter->hw.phy.ops.power_down) |
| 3314 | adapter->hw.phy.ops.power_down(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | /** |
| 3318 | * e1000e_reset - bring the hardware into a known good state |
| 3319 | * |
| 3320 | * This function boots the hardware and enables some settings that |
| 3321 | * require a configuration cycle of the hardware - those cannot be |
| 3322 | * set/changed during runtime. After reset the device needs to be |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3323 | * properly configured for Rx, Tx etc. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3324 | */ |
| 3325 | void e1000e_reset(struct e1000_adapter *adapter) |
| 3326 | { |
| 3327 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3328 | struct e1000_fc_info *fc = &adapter->hw.fc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3329 | struct e1000_hw *hw = &adapter->hw; |
| 3330 | u32 tx_space, min_tx_space, min_rx_space; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3331 | u32 pba = adapter->pba; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3332 | u16 hwm; |
| 3333 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3334 | /* reset Packet Buffer Allocation to default */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3335 | ew32(PBA, pba); |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3336 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3337 | if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3338 | /* |
| 3339 | * To maintain wire speed transmits, the Tx FIFO should be |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3340 | * large enough to accommodate two full transmit packets, |
| 3341 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 3342 | * the Rx FIFO should be large enough to accommodate at least |
| 3343 | * one full receive packet and is similarly rounded up and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3344 | * expressed in KB. |
| 3345 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3346 | pba = er32(PBA); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3347 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3348 | tx_space = pba >> 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3349 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3350 | pba &= 0xffff; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3351 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3352 | * the Tx fifo also stores 16 bytes of information about the Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3353 | * but don't include ethernet FCS because hardware appends it |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3354 | */ |
| 3355 | min_tx_space = (adapter->max_frame_size + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3356 | sizeof(struct e1000_tx_desc) - |
| 3357 | ETH_FCS_LEN) * 2; |
| 3358 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 3359 | min_tx_space >>= 10; |
| 3360 | /* software strips receive CRC, so leave room for it */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3361 | min_rx_space = adapter->max_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3362 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 3363 | min_rx_space >>= 10; |
| 3364 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3365 | /* |
| 3366 | * If current Tx allocation is less than the min Tx FIFO size, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3367 | * 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] | 3368 | * allocation, take space away from current Rx allocation |
| 3369 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3370 | if ((tx_space < min_tx_space) && |
| 3371 | ((min_tx_space - tx_space) < pba)) { |
| 3372 | pba -= min_tx_space - tx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3373 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3374 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3375 | * if short on Rx space, Rx wins and must trump Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3376 | * adjustment or use Early Receive if available |
| 3377 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3378 | if ((pba < min_rx_space) && |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3379 | (!(adapter->flags & FLAG_HAS_ERT))) |
| 3380 | /* ERT enabled in e1000_configure_rx */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3381 | pba = min_rx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3382 | } |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3383 | |
| 3384 | ew32(PBA, pba); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3385 | } |
| 3386 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3387 | /* |
| 3388 | * flow control settings |
| 3389 | * |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3390 | * 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] | 3391 | * (or the size used for early receive) above it in the Rx FIFO. |
| 3392 | * Set it to the lower of: |
| 3393 | * - 90% of the Rx FIFO size, and |
| 3394 | * - the full Rx FIFO size minus the early receive size (for parts |
| 3395 | * with ERT support assuming ERT set to E1000_ERT_2048), or |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3396 | * - the full Rx FIFO size minus one full frame |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3397 | */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3398 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
| 3399 | fc->pause_time = 0xFFFF; |
| 3400 | else |
| 3401 | fc->pause_time = E1000_FC_PAUSE_TIME; |
| 3402 | fc->send_xon = 1; |
| 3403 | fc->current_mode = fc->requested_mode; |
| 3404 | |
| 3405 | switch (hw->mac.type) { |
| 3406 | default: |
| 3407 | if ((adapter->flags & FLAG_HAS_ERT) && |
| 3408 | (adapter->netdev->mtu > ETH_DATA_LEN)) |
| 3409 | hwm = min(((pba << 10) * 9 / 10), |
| 3410 | ((pba << 10) - (E1000_ERT_2048 << 3))); |
| 3411 | else |
| 3412 | hwm = min(((pba << 10) * 9 / 10), |
| 3413 | ((pba << 10) - adapter->max_frame_size)); |
| 3414 | |
| 3415 | fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ |
| 3416 | fc->low_water = fc->high_water - 8; |
| 3417 | break; |
| 3418 | case e1000_pchlan: |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3419 | /* |
| 3420 | * Workaround PCH LOM adapter hangs with certain network |
| 3421 | * loads. If hangs persist, try disabling Tx flow control. |
| 3422 | */ |
| 3423 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3424 | fc->high_water = 0x3500; |
| 3425 | fc->low_water = 0x1500; |
| 3426 | } else { |
| 3427 | fc->high_water = 0x5000; |
| 3428 | fc->low_water = 0x3000; |
| 3429 | } |
Bruce Allan | a305595 | 2010-05-10 15:02:12 +0000 | [diff] [blame] | 3430 | fc->refresh_time = 0x1000; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3431 | break; |
| 3432 | case e1000_pch2lan: |
| 3433 | fc->high_water = 0x05C20; |
| 3434 | fc->low_water = 0x05048; |
| 3435 | fc->pause_time = 0x0650; |
| 3436 | fc->refresh_time = 0x0400; |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3437 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3438 | pba = 14; |
| 3439 | ew32(PBA, pba); |
| 3440 | } |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3441 | break; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3442 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3443 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3444 | /* |
| 3445 | * Disable Adaptive Interrupt Moderation if 2 full packets cannot |
| 3446 | * fit in receive buffer and early-receive not supported. |
| 3447 | */ |
| 3448 | if (adapter->itr_setting & 0x3) { |
| 3449 | if (((adapter->max_frame_size * 2) > (pba << 10)) && |
| 3450 | !(adapter->flags & FLAG_HAS_ERT)) { |
| 3451 | if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) { |
| 3452 | dev_info(&adapter->pdev->dev, |
| 3453 | "Interrupt Throttle Rate turned off\n"); |
| 3454 | adapter->flags2 |= FLAG2_DISABLE_AIM; |
| 3455 | ew32(ITR, 0); |
| 3456 | } |
| 3457 | } else if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 3458 | dev_info(&adapter->pdev->dev, |
| 3459 | "Interrupt Throttle Rate turned on\n"); |
| 3460 | adapter->flags2 &= ~FLAG2_DISABLE_AIM; |
| 3461 | adapter->itr = 20000; |
| 3462 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
| 3463 | } |
| 3464 | } |
| 3465 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3466 | /* Allow time for pending master requests to run */ |
| 3467 | mac->ops.reset_hw(hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3468 | |
| 3469 | /* |
| 3470 | * For parts with AMT enabled, let the firmware know |
| 3471 | * that the network interface is in control |
| 3472 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 3473 | if (adapter->flags & FLAG_HAS_AMT) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3474 | e1000e_get_hw_control(adapter); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3475 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3476 | ew32(WUC, 0); |
| 3477 | |
| 3478 | if (mac->ops.init_hw(hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 3479 | e_err("Hardware Error\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3480 | |
| 3481 | e1000_update_mng_vlan(adapter); |
| 3482 | |
| 3483 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 3484 | ew32(VET, ETH_P_8021Q); |
| 3485 | |
| 3486 | e1000e_reset_adaptive(hw); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3487 | |
| 3488 | if (!netif_running(adapter->netdev) && |
| 3489 | !test_bit(__E1000_TESTING, &adapter->state)) { |
| 3490 | e1000_power_down_phy(adapter); |
| 3491 | return; |
| 3492 | } |
| 3493 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3494 | e1000_get_phy_info(hw); |
| 3495 | |
Bruce Allan | 918d719 | 2009-06-02 11:28:20 +0000 | [diff] [blame] | 3496 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && |
| 3497 | !(adapter->flags & FLAG_SMART_POWER_DOWN)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3498 | u16 phy_data = 0; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3499 | /* |
| 3500 | * speed up time to link by disabling smart power down, ignore |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3501 | * the return value of this function because there is nothing |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3502 | * different we would do if it failed |
| 3503 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3504 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
| 3505 | phy_data &= ~IGP02E1000_PM_SPD; |
| 3506 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 3507 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | int e1000e_up(struct e1000_adapter *adapter) |
| 3511 | { |
| 3512 | struct e1000_hw *hw = &adapter->hw; |
| 3513 | |
| 3514 | /* hardware has been reset, we need to reload some things */ |
| 3515 | e1000_configure(adapter); |
| 3516 | |
| 3517 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3518 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3519 | if (adapter->msix_entries) |
| 3520 | e1000_configure_msix(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3521 | e1000_irq_enable(adapter); |
| 3522 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 3523 | netif_start_queue(adapter->netdev); |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3524 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3525 | /* fire a link change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3526 | if (adapter->msix_entries) |
| 3527 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3528 | else |
| 3529 | ew32(ICS, E1000_ICS_LSC); |
| 3530 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3531 | return 0; |
| 3532 | } |
| 3533 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3534 | static void e1000e_flush_descriptors(struct e1000_adapter *adapter) |
| 3535 | { |
| 3536 | struct e1000_hw *hw = &adapter->hw; |
| 3537 | |
| 3538 | if (!(adapter->flags2 & FLAG2_DMA_BURST)) |
| 3539 | return; |
| 3540 | |
| 3541 | /* flush pending descriptor writebacks to memory */ |
| 3542 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 3543 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 3544 | |
| 3545 | /* execute the writes immediately */ |
| 3546 | e1e_flush(); |
| 3547 | } |
| 3548 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3549 | static void e1000e_update_stats(struct e1000_adapter *adapter); |
| 3550 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3551 | void e1000e_down(struct e1000_adapter *adapter) |
| 3552 | { |
| 3553 | struct net_device *netdev = adapter->netdev; |
| 3554 | struct e1000_hw *hw = &adapter->hw; |
| 3555 | u32 tctl, rctl; |
| 3556 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3557 | /* |
| 3558 | * signal that we're down so the interrupt handler does not |
| 3559 | * reschedule our watchdog timer |
| 3560 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3561 | set_bit(__E1000_DOWN, &adapter->state); |
| 3562 | |
| 3563 | /* disable receives in the hardware */ |
| 3564 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3565 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3566 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3567 | /* flush and sleep below */ |
| 3568 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3569 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3570 | |
| 3571 | /* disable transmits in the hardware */ |
| 3572 | tctl = er32(TCTL); |
| 3573 | tctl &= ~E1000_TCTL_EN; |
| 3574 | ew32(TCTL, tctl); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3575 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3576 | /* flush both disables and wait for them to finish */ |
| 3577 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3578 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3579 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3580 | e1000_irq_disable(adapter); |
| 3581 | |
| 3582 | del_timer_sync(&adapter->watchdog_timer); |
| 3583 | del_timer_sync(&adapter->phy_info_timer); |
| 3584 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3585 | netif_carrier_off(netdev); |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3586 | |
| 3587 | spin_lock(&adapter->stats64_lock); |
| 3588 | e1000e_update_stats(adapter); |
| 3589 | spin_unlock(&adapter->stats64_lock); |
| 3590 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 3591 | e1000e_flush_descriptors(adapter); |
| 3592 | e1000_clean_tx_ring(adapter); |
| 3593 | e1000_clean_rx_ring(adapter); |
| 3594 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3595 | adapter->link_speed = 0; |
| 3596 | adapter->link_duplex = 0; |
| 3597 | |
Jeff Kirsher | 52cc308 | 2008-06-24 17:01:29 -0700 | [diff] [blame] | 3598 | if (!pci_channel_offline(adapter->pdev)) |
| 3599 | e1000e_reset(adapter); |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3600 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3601 | /* |
| 3602 | * TODO: for power management, we could drop the link and |
| 3603 | * pci_disable_device here. |
| 3604 | */ |
| 3605 | } |
| 3606 | |
| 3607 | void e1000e_reinit_locked(struct e1000_adapter *adapter) |
| 3608 | { |
| 3609 | might_sleep(); |
| 3610 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3611 | usleep_range(1000, 2000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3612 | e1000e_down(adapter); |
| 3613 | e1000e_up(adapter); |
| 3614 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 3615 | } |
| 3616 | |
| 3617 | /** |
| 3618 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 3619 | * @adapter: board private structure to initialize |
| 3620 | * |
| 3621 | * e1000_sw_init initializes the Adapter private data structure. |
| 3622 | * Fields are initialized based on PCI device information and |
| 3623 | * OS network device settings (MTU size). |
| 3624 | **/ |
| 3625 | static int __devinit e1000_sw_init(struct e1000_adapter *adapter) |
| 3626 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3627 | struct net_device *netdev = adapter->netdev; |
| 3628 | |
| 3629 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN; |
| 3630 | adapter->rx_ps_bsize0 = 128; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3631 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3632 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3633 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3634 | spin_lock_init(&adapter->stats64_lock); |
| 3635 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3636 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3637 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3638 | if (e1000_alloc_queues(adapter)) |
| 3639 | return -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3640 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3641 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3642 | e1000_irq_disable(adapter); |
| 3643 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3644 | set_bit(__E1000_DOWN, &adapter->state); |
| 3645 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | /** |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3649 | * e1000_intr_msi_test - Interrupt Handler |
| 3650 | * @irq: interrupt number |
| 3651 | * @data: pointer to a network interface device structure |
| 3652 | **/ |
| 3653 | static irqreturn_t e1000_intr_msi_test(int irq, void *data) |
| 3654 | { |
| 3655 | struct net_device *netdev = data; |
| 3656 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3657 | struct e1000_hw *hw = &adapter->hw; |
| 3658 | u32 icr = er32(ICR); |
| 3659 | |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 3660 | e_dbg("icr is %08X\n", icr); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3661 | if (icr & E1000_ICR_RXSEQ) { |
| 3662 | adapter->flags &= ~FLAG_MSI_TEST_FAILED; |
| 3663 | wmb(); |
| 3664 | } |
| 3665 | |
| 3666 | return IRQ_HANDLED; |
| 3667 | } |
| 3668 | |
| 3669 | /** |
| 3670 | * e1000_test_msi_interrupt - Returns 0 for successful test |
| 3671 | * @adapter: board private struct |
| 3672 | * |
| 3673 | * code flow taken from tg3.c |
| 3674 | **/ |
| 3675 | static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) |
| 3676 | { |
| 3677 | struct net_device *netdev = adapter->netdev; |
| 3678 | struct e1000_hw *hw = &adapter->hw; |
| 3679 | int err; |
| 3680 | |
| 3681 | /* poll_enable hasn't been called yet, so don't need disable */ |
| 3682 | /* clear any pending events */ |
| 3683 | er32(ICR); |
| 3684 | |
| 3685 | /* free the real vector and request a test handler */ |
| 3686 | e1000_free_irq(adapter); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3687 | e1000e_reset_interrupt_capability(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3688 | |
| 3689 | /* Assume that the test fails, if it succeeds then the test |
| 3690 | * MSI irq handler will unset this flag */ |
| 3691 | adapter->flags |= FLAG_MSI_TEST_FAILED; |
| 3692 | |
| 3693 | err = pci_enable_msi(adapter->pdev); |
| 3694 | if (err) |
| 3695 | goto msi_test_failed; |
| 3696 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3697 | err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3698 | netdev->name, netdev); |
| 3699 | if (err) { |
| 3700 | pci_disable_msi(adapter->pdev); |
| 3701 | goto msi_test_failed; |
| 3702 | } |
| 3703 | |
| 3704 | wmb(); |
| 3705 | |
| 3706 | e1000_irq_enable(adapter); |
| 3707 | |
| 3708 | /* fire an unusual interrupt on the test handler */ |
| 3709 | ew32(ICS, E1000_ICS_RXSEQ); |
| 3710 | e1e_flush(); |
| 3711 | msleep(50); |
| 3712 | |
| 3713 | e1000_irq_disable(adapter); |
| 3714 | |
| 3715 | rmb(); |
| 3716 | |
| 3717 | if (adapter->flags & FLAG_MSI_TEST_FAILED) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3718 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 3719 | e_info("MSI interrupt test failed, using legacy interrupt.\n"); |
| 3720 | } else |
| 3721 | e_dbg("MSI interrupt test succeeded!\n"); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3722 | |
| 3723 | free_irq(adapter->pdev->irq, netdev); |
| 3724 | pci_disable_msi(adapter->pdev); |
| 3725 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3726 | msi_test_failed: |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3727 | e1000e_set_interrupt_capability(adapter); |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 3728 | return e1000_request_irq(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | /** |
| 3732 | * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored |
| 3733 | * @adapter: board private struct |
| 3734 | * |
| 3735 | * code flow taken from tg3.c, called with e1000 interrupts disabled. |
| 3736 | **/ |
| 3737 | static int e1000_test_msi(struct e1000_adapter *adapter) |
| 3738 | { |
| 3739 | int err; |
| 3740 | u16 pci_cmd; |
| 3741 | |
| 3742 | if (!(adapter->flags & FLAG_MSI_ENABLED)) |
| 3743 | return 0; |
| 3744 | |
| 3745 | /* disable SERR in case the MSI write causes a master abort */ |
| 3746 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 3747 | if (pci_cmd & PCI_COMMAND_SERR) |
| 3748 | pci_write_config_word(adapter->pdev, PCI_COMMAND, |
| 3749 | pci_cmd & ~PCI_COMMAND_SERR); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3750 | |
| 3751 | err = e1000_test_msi_interrupt(adapter); |
| 3752 | |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 3753 | /* re-enable SERR */ |
| 3754 | if (pci_cmd & PCI_COMMAND_SERR) { |
| 3755 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
| 3756 | pci_cmd |= PCI_COMMAND_SERR; |
| 3757 | pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); |
| 3758 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3759 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3760 | return err; |
| 3761 | } |
| 3762 | |
| 3763 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3764 | * e1000_open - Called when a network interface is made active |
| 3765 | * @netdev: network interface device structure |
| 3766 | * |
| 3767 | * Returns 0 on success, negative value on failure |
| 3768 | * |
| 3769 | * The open entry point is called when a network interface is made |
| 3770 | * active by the system (IFF_UP). At this point all resources needed |
| 3771 | * for transmit and receive operations are allocated, the interrupt |
| 3772 | * handler is registered with the OS, the watchdog timer is started, |
| 3773 | * and the stack is notified that the interface is ready. |
| 3774 | **/ |
| 3775 | static int e1000_open(struct net_device *netdev) |
| 3776 | { |
| 3777 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3778 | struct e1000_hw *hw = &adapter->hw; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3779 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3780 | int err; |
| 3781 | |
| 3782 | /* disallow open during test */ |
| 3783 | if (test_bit(__E1000_TESTING, &adapter->state)) |
| 3784 | return -EBUSY; |
| 3785 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3786 | pm_runtime_get_sync(&pdev->dev); |
| 3787 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 3788 | netif_carrier_off(netdev); |
| 3789 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3790 | /* allocate transmit descriptors */ |
| 3791 | err = e1000e_setup_tx_resources(adapter); |
| 3792 | if (err) |
| 3793 | goto err_setup_tx; |
| 3794 | |
| 3795 | /* allocate receive descriptors */ |
| 3796 | err = e1000e_setup_rx_resources(adapter); |
| 3797 | if (err) |
| 3798 | goto err_setup_rx; |
| 3799 | |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 3800 | /* |
| 3801 | * If AMT is enabled, let the firmware know that the network |
| 3802 | * interface is now open and reset the part to a known state. |
| 3803 | */ |
| 3804 | if (adapter->flags & FLAG_HAS_AMT) { |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3805 | e1000e_get_hw_control(adapter); |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 3806 | e1000e_reset(adapter); |
| 3807 | } |
| 3808 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3809 | e1000e_power_up_phy(adapter); |
| 3810 | |
| 3811 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 3812 | if ((adapter->hw.mng_cookie.status & |
| 3813 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
| 3814 | e1000_update_mng_vlan(adapter); |
| 3815 | |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3816 | /* DMA latency requirement to workaround early-receive/jumbo issue */ |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3817 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 3818 | (adapter->hw.mac.type == e1000_pch2lan)) |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 3819 | pm_qos_add_request(&adapter->netdev->pm_qos_req, |
| 3820 | PM_QOS_CPU_DMA_LATENCY, |
| 3821 | PM_QOS_DEFAULT_VALUE); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3822 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3823 | /* |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3824 | * before we allocate an interrupt, we must be ready to handle it. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3825 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 3826 | * 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] | 3827 | * clean_rx handler before we do so. |
| 3828 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3829 | e1000_configure(adapter); |
| 3830 | |
| 3831 | err = e1000_request_irq(adapter); |
| 3832 | if (err) |
| 3833 | goto err_req_irq; |
| 3834 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3835 | /* |
| 3836 | * Work around PCIe errata with MSI interrupts causing some chipsets to |
| 3837 | * ignore e1000e MSI messages, which means we need to test our MSI |
| 3838 | * interrupt now |
| 3839 | */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3840 | if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3841 | err = e1000_test_msi(adapter); |
| 3842 | if (err) { |
| 3843 | e_err("Interrupt allocation failed\n"); |
| 3844 | goto err_req_irq; |
| 3845 | } |
| 3846 | } |
| 3847 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3848 | /* From here on the code is the same as e1000e_up() */ |
| 3849 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3850 | |
| 3851 | napi_enable(&adapter->napi); |
| 3852 | |
| 3853 | e1000_irq_enable(adapter); |
| 3854 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 3855 | adapter->tx_hang_recheck = false; |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3856 | netif_start_queue(netdev); |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 3857 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3858 | adapter->idle_check = true; |
| 3859 | pm_runtime_put(&pdev->dev); |
| 3860 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3861 | /* fire a link status change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3862 | if (adapter->msix_entries) |
| 3863 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3864 | else |
| 3865 | ew32(ICS, E1000_ICS_LSC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3866 | |
| 3867 | return 0; |
| 3868 | |
| 3869 | err_req_irq: |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3870 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3871 | e1000_power_down_phy(adapter); |
| 3872 | e1000e_free_rx_resources(adapter); |
| 3873 | err_setup_rx: |
| 3874 | e1000e_free_tx_resources(adapter); |
| 3875 | err_setup_tx: |
| 3876 | e1000e_reset(adapter); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3877 | pm_runtime_put_sync(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3878 | |
| 3879 | return err; |
| 3880 | } |
| 3881 | |
| 3882 | /** |
| 3883 | * e1000_close - Disables a network interface |
| 3884 | * @netdev: network interface device structure |
| 3885 | * |
| 3886 | * Returns 0, this is not allowed to fail |
| 3887 | * |
| 3888 | * The close entry point is called when an interface is de-activated |
| 3889 | * by the OS. The hardware is still under the drivers control, but |
| 3890 | * needs to be disabled. A global MAC reset is issued to stop the |
| 3891 | * hardware, and all transmit and receive resources are freed. |
| 3892 | **/ |
| 3893 | static int e1000_close(struct net_device *netdev) |
| 3894 | { |
| 3895 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3896 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3897 | |
| 3898 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3899 | |
| 3900 | pm_runtime_get_sync(&pdev->dev); |
| 3901 | |
Bruce Allan | 5f4a780 | 2011-11-29 08:09:19 +0000 | [diff] [blame^] | 3902 | napi_disable(&adapter->napi); |
| 3903 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3904 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 3905 | e1000e_down(adapter); |
| 3906 | e1000_free_irq(adapter); |
| 3907 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3908 | e1000_power_down_phy(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3909 | |
| 3910 | e1000e_free_tx_resources(adapter); |
| 3911 | e1000e_free_rx_resources(adapter); |
| 3912 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3913 | /* |
| 3914 | * kill manageability vlan ID if supported, but not if a vlan with |
| 3915 | * the same ID is registered on the host OS (let 8021q kill it) |
| 3916 | */ |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3917 | if (adapter->hw.mng_cookie.status & |
| 3918 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3919 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 3920 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3921 | /* |
| 3922 | * If AMT is enabled, let the firmware know that the network |
| 3923 | * interface is now closed |
| 3924 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3925 | if ((adapter->flags & FLAG_HAS_AMT) && |
| 3926 | !test_bit(__E1000_TESTING, &adapter->state)) |
| 3927 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3928 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3929 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 3930 | (adapter->hw.mac.type == e1000_pch2lan)) |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 3931 | pm_qos_remove_request(&adapter->netdev->pm_qos_req); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3932 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3933 | pm_runtime_put_sync(&pdev->dev); |
| 3934 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3935 | return 0; |
| 3936 | } |
| 3937 | /** |
| 3938 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 3939 | * @netdev: network interface device structure |
| 3940 | * @p: pointer to an address structure |
| 3941 | * |
| 3942 | * Returns 0 on success, negative on failure |
| 3943 | **/ |
| 3944 | static int e1000_set_mac(struct net_device *netdev, void *p) |
| 3945 | { |
| 3946 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3947 | struct sockaddr *addr = p; |
| 3948 | |
| 3949 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3950 | return -EADDRNOTAVAIL; |
| 3951 | |
| 3952 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 3953 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 3954 | |
| 3955 | e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0); |
| 3956 | |
| 3957 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { |
| 3958 | /* activate the work around */ |
| 3959 | e1000e_set_laa_state_82571(&adapter->hw, 1); |
| 3960 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3961 | /* |
| 3962 | * 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] | 3963 | * between the time RAR[0] gets clobbered and the time it |
| 3964 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
| 3965 | * of the RARs and no incoming packets directed to this port |
| 3966 | * are dropped. Eventually the LAA will be in RAR[0] and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3967 | * RAR[14] |
| 3968 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3969 | e1000e_rar_set(&adapter->hw, |
| 3970 | adapter->hw.mac.addr, |
| 3971 | adapter->hw.mac.rar_entry_count - 1); |
| 3972 | } |
| 3973 | |
| 3974 | return 0; |
| 3975 | } |
| 3976 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 3977 | /** |
| 3978 | * e1000e_update_phy_task - work thread to update phy |
| 3979 | * @work: pointer to our work struct |
| 3980 | * |
| 3981 | * this worker thread exists because we must acquire a |
| 3982 | * semaphore to read the phy, which we could msleep while |
| 3983 | * waiting for it, and we can't msleep in a timer. |
| 3984 | **/ |
| 3985 | static void e1000e_update_phy_task(struct work_struct *work) |
| 3986 | { |
| 3987 | struct e1000_adapter *adapter = container_of(work, |
| 3988 | struct e1000_adapter, update_phy_task); |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 3989 | |
| 3990 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 3991 | return; |
| 3992 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 3993 | e1000_get_phy_info(&adapter->hw); |
| 3994 | } |
| 3995 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3996 | /* |
| 3997 | * Need to wait a few seconds after link up to get diagnostic information from |
| 3998 | * the phy |
| 3999 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4000 | static void e1000_update_phy_info(unsigned long data) |
| 4001 | { |
| 4002 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4003 | |
| 4004 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4005 | return; |
| 4006 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4007 | schedule_work(&adapter->update_phy_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | /** |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4011 | * e1000e_update_phy_stats - Update the PHY statistics counters |
| 4012 | * @adapter: board private structure |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4013 | * |
| 4014 | * Read/clear the upper 16-bit PHY registers and read/accumulate lower |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4015 | **/ |
| 4016 | static void e1000e_update_phy_stats(struct e1000_adapter *adapter) |
| 4017 | { |
| 4018 | struct e1000_hw *hw = &adapter->hw; |
| 4019 | s32 ret_val; |
| 4020 | u16 phy_data; |
| 4021 | |
| 4022 | ret_val = hw->phy.ops.acquire(hw); |
| 4023 | if (ret_val) |
| 4024 | return; |
| 4025 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4026 | /* |
| 4027 | * A page set is expensive so check if already on desired page. |
| 4028 | * If not, set to the page with the PHY status registers. |
| 4029 | */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4030 | hw->phy.addr = 1; |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4031 | ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 4032 | &phy_data); |
| 4033 | if (ret_val) |
| 4034 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4035 | if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) { |
| 4036 | ret_val = hw->phy.ops.set_page(hw, |
| 4037 | HV_STATS_PAGE << IGP_PAGE_SHIFT); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4038 | if (ret_val) |
| 4039 | goto release; |
| 4040 | } |
| 4041 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4042 | /* Single Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4043 | hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data); |
| 4044 | 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] | 4045 | if (!ret_val) |
| 4046 | adapter->stats.scc += phy_data; |
| 4047 | |
| 4048 | /* Excessive Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4049 | hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data); |
| 4050 | 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] | 4051 | if (!ret_val) |
| 4052 | adapter->stats.ecol += phy_data; |
| 4053 | |
| 4054 | /* Multiple Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4055 | hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data); |
| 4056 | 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] | 4057 | if (!ret_val) |
| 4058 | adapter->stats.mcc += phy_data; |
| 4059 | |
| 4060 | /* Late Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4061 | hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data); |
| 4062 | 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] | 4063 | if (!ret_val) |
| 4064 | adapter->stats.latecol += phy_data; |
| 4065 | |
| 4066 | /* Collision Count - also used for adaptive IFS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4067 | hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data); |
| 4068 | 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] | 4069 | if (!ret_val) |
| 4070 | hw->mac.collision_delta = phy_data; |
| 4071 | |
| 4072 | /* Defer Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4073 | hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data); |
| 4074 | 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] | 4075 | if (!ret_val) |
| 4076 | adapter->stats.dc += phy_data; |
| 4077 | |
| 4078 | /* Transmit with no CRS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4079 | hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data); |
| 4080 | 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] | 4081 | if (!ret_val) |
| 4082 | adapter->stats.tncrs += phy_data; |
| 4083 | |
| 4084 | release: |
| 4085 | hw->phy.ops.release(hw); |
| 4086 | } |
| 4087 | |
| 4088 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4089 | * e1000e_update_stats - Update the board statistics counters |
| 4090 | * @adapter: board private structure |
| 4091 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4092 | static void e1000e_update_stats(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4093 | { |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4094 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4095 | struct e1000_hw *hw = &adapter->hw; |
| 4096 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4097 | |
| 4098 | /* |
| 4099 | * Prevent stats update while adapter is being reset, or if the pci |
| 4100 | * connection is down. |
| 4101 | */ |
| 4102 | if (adapter->link_speed == 0) |
| 4103 | return; |
| 4104 | if (pci_channel_offline(pdev)) |
| 4105 | return; |
| 4106 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4107 | adapter->stats.crcerrs += er32(CRCERRS); |
| 4108 | adapter->stats.gprc += er32(GPRC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4109 | adapter->stats.gorc += er32(GORCL); |
| 4110 | er32(GORCH); /* Clear gorc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4111 | adapter->stats.bprc += er32(BPRC); |
| 4112 | adapter->stats.mprc += er32(MPRC); |
| 4113 | adapter->stats.roc += er32(ROC); |
| 4114 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4115 | adapter->stats.mpc += er32(MPC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4116 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4117 | /* Half-duplex statistics */ |
| 4118 | if (adapter->link_duplex == HALF_DUPLEX) { |
| 4119 | if (adapter->flags2 & FLAG2_HAS_PHY_STATS) { |
| 4120 | e1000e_update_phy_stats(adapter); |
| 4121 | } else { |
| 4122 | adapter->stats.scc += er32(SCC); |
| 4123 | adapter->stats.ecol += er32(ECOL); |
| 4124 | adapter->stats.mcc += er32(MCC); |
| 4125 | adapter->stats.latecol += er32(LATECOL); |
| 4126 | adapter->stats.dc += er32(DC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4127 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4128 | hw->mac.collision_delta = er32(COLC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4129 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4130 | if ((hw->mac.type != e1000_82574) && |
| 4131 | (hw->mac.type != e1000_82583)) |
| 4132 | adapter->stats.tncrs += er32(TNCRS); |
| 4133 | } |
| 4134 | adapter->stats.colc += hw->mac.collision_delta; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4135 | } |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4136 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4137 | adapter->stats.xonrxc += er32(XONRXC); |
| 4138 | adapter->stats.xontxc += er32(XONTXC); |
| 4139 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 4140 | adapter->stats.xofftxc += er32(XOFFTXC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4141 | adapter->stats.gptc += er32(GPTC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4142 | adapter->stats.gotc += er32(GOTCL); |
| 4143 | er32(GOTCH); /* Clear gotc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4144 | adapter->stats.rnbc += er32(RNBC); |
| 4145 | adapter->stats.ruc += er32(RUC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4146 | |
| 4147 | adapter->stats.mptc += er32(MPTC); |
| 4148 | adapter->stats.bptc += er32(BPTC); |
| 4149 | |
| 4150 | /* used for adaptive IFS */ |
| 4151 | |
| 4152 | hw->mac.tx_packet_delta = er32(TPT); |
| 4153 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4154 | |
| 4155 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 4156 | adapter->stats.rxerrc += er32(RXERRC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4157 | adapter->stats.cexterr += er32(CEXTERR); |
| 4158 | adapter->stats.tsctc += er32(TSCTC); |
| 4159 | adapter->stats.tsctfc += er32(TSCTFC); |
| 4160 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4161 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4162 | netdev->stats.multicast = adapter->stats.mprc; |
| 4163 | netdev->stats.collisions = adapter->stats.colc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4164 | |
| 4165 | /* Rx Errors */ |
| 4166 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4167 | /* |
| 4168 | * RLEC on some newer hardware can be incorrect so build |
| 4169 | * our own version based on RUC and ROC |
| 4170 | */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4171 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4172 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 4173 | adapter->stats.ruc + adapter->stats.roc + |
| 4174 | adapter->stats.cexterr; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4175 | netdev->stats.rx_length_errors = adapter->stats.ruc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4176 | adapter->stats.roc; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4177 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4178 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; |
| 4179 | netdev->stats.rx_missed_errors = adapter->stats.mpc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4180 | |
| 4181 | /* Tx Errors */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4182 | netdev->stats.tx_errors = adapter->stats.ecol + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4183 | adapter->stats.latecol; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4184 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
| 4185 | netdev->stats.tx_window_errors = adapter->stats.latecol; |
| 4186 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4187 | |
| 4188 | /* Tx Dropped needs to be maintained elsewhere */ |
| 4189 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4190 | /* Management Stats */ |
| 4191 | adapter->stats.mgptc += er32(MGTPTC); |
| 4192 | adapter->stats.mgprc += er32(MGTPRC); |
| 4193 | adapter->stats.mgpdc += er32(MGTPDC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4194 | } |
| 4195 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4196 | /** |
| 4197 | * e1000_phy_read_status - Update the PHY register status snapshot |
| 4198 | * @adapter: board private structure |
| 4199 | **/ |
| 4200 | static void e1000_phy_read_status(struct e1000_adapter *adapter) |
| 4201 | { |
| 4202 | struct e1000_hw *hw = &adapter->hw; |
| 4203 | struct e1000_phy_regs *phy = &adapter->phy_regs; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4204 | |
| 4205 | if ((er32(STATUS) & E1000_STATUS_LU) && |
| 4206 | (adapter->hw.phy.media_type == e1000_media_type_copper)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4207 | int ret_val; |
| 4208 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4209 | ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr); |
| 4210 | ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr); |
| 4211 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise); |
| 4212 | ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa); |
| 4213 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion); |
| 4214 | ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000); |
| 4215 | ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000); |
| 4216 | ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus); |
| 4217 | if (ret_val) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4218 | e_warn("Error reading PHY register\n"); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4219 | } else { |
| 4220 | /* |
| 4221 | * Do not read PHY registers if link is not up |
| 4222 | * Set values to typical power-on defaults |
| 4223 | */ |
| 4224 | phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); |
| 4225 | phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | |
| 4226 | BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | |
| 4227 | BMSR_ERCAP); |
| 4228 | phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | |
| 4229 | ADVERTISE_ALL | ADVERTISE_CSMA); |
| 4230 | phy->lpa = 0; |
| 4231 | phy->expansion = EXPANSION_ENABLENPAGE; |
| 4232 | phy->ctrl1000 = ADVERTISE_1000FULL; |
| 4233 | phy->stat1000 = 0; |
| 4234 | phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); |
| 4235 | } |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4236 | } |
| 4237 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4238 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
| 4239 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4240 | struct e1000_hw *hw = &adapter->hw; |
| 4241 | u32 ctrl = er32(CTRL); |
| 4242 | |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4243 | /* Link status message must follow this format for user tools */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 4244 | printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n", |
| 4245 | adapter->netdev->name, |
| 4246 | adapter->link_speed, |
| 4247 | adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half", |
| 4248 | (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" : |
| 4249 | (ctrl & E1000_CTRL_RFCE) ? "Rx" : |
| 4250 | (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4251 | } |
| 4252 | |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 4253 | static bool e1000e_has_link(struct e1000_adapter *adapter) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4254 | { |
| 4255 | struct e1000_hw *hw = &adapter->hw; |
| 4256 | bool link_active = 0; |
| 4257 | s32 ret_val = 0; |
| 4258 | |
| 4259 | /* |
| 4260 | * get_link_status is set on LSC (link status) interrupt or |
| 4261 | * Rx sequence error interrupt. get_link_status will stay |
| 4262 | * false until the check_for_link establishes link |
| 4263 | * for copper adapters ONLY |
| 4264 | */ |
| 4265 | switch (hw->phy.media_type) { |
| 4266 | case e1000_media_type_copper: |
| 4267 | if (hw->mac.get_link_status) { |
| 4268 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4269 | link_active = !hw->mac.get_link_status; |
| 4270 | } else { |
| 4271 | link_active = 1; |
| 4272 | } |
| 4273 | break; |
| 4274 | case e1000_media_type_fiber: |
| 4275 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4276 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 4277 | break; |
| 4278 | case e1000_media_type_internal_serdes: |
| 4279 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4280 | link_active = adapter->hw.mac.serdes_has_link; |
| 4281 | break; |
| 4282 | default: |
| 4283 | case e1000_media_type_unknown: |
| 4284 | break; |
| 4285 | } |
| 4286 | |
| 4287 | if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && |
| 4288 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 4289 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4290 | e_info("Gigabit has been disabled, downgrading speed\n"); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4291 | } |
| 4292 | |
| 4293 | return link_active; |
| 4294 | } |
| 4295 | |
| 4296 | static void e1000e_enable_receives(struct e1000_adapter *adapter) |
| 4297 | { |
| 4298 | /* make sure the receive unit is started */ |
| 4299 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 4300 | (adapter->flags & FLAG_RX_RESTART_NOW)) { |
| 4301 | struct e1000_hw *hw = &adapter->hw; |
| 4302 | u32 rctl = er32(RCTL); |
| 4303 | ew32(RCTL, rctl | E1000_RCTL_EN); |
| 4304 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
| 4305 | } |
| 4306 | } |
| 4307 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4308 | static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter) |
| 4309 | { |
| 4310 | struct e1000_hw *hw = &adapter->hw; |
| 4311 | |
| 4312 | /* |
| 4313 | * With 82574 controllers, PHY needs to be checked periodically |
| 4314 | * for hung state and reset, if two calls return true |
| 4315 | */ |
| 4316 | if (e1000_check_phy_82574(hw)) |
| 4317 | adapter->phy_hang_count++; |
| 4318 | else |
| 4319 | adapter->phy_hang_count = 0; |
| 4320 | |
| 4321 | if (adapter->phy_hang_count > 1) { |
| 4322 | adapter->phy_hang_count = 0; |
| 4323 | schedule_work(&adapter->reset_task); |
| 4324 | } |
| 4325 | } |
| 4326 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4327 | /** |
| 4328 | * e1000_watchdog - Timer Call-back |
| 4329 | * @data: pointer to adapter cast into an unsigned long |
| 4330 | **/ |
| 4331 | static void e1000_watchdog(unsigned long data) |
| 4332 | { |
| 4333 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 4334 | |
| 4335 | /* Do the rest outside of interrupt context */ |
| 4336 | schedule_work(&adapter->watchdog_task); |
| 4337 | |
| 4338 | /* TODO: make this use queue_delayed_work() */ |
| 4339 | } |
| 4340 | |
| 4341 | static void e1000_watchdog_task(struct work_struct *work) |
| 4342 | { |
| 4343 | struct e1000_adapter *adapter = container_of(work, |
| 4344 | struct e1000_adapter, watchdog_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4345 | struct net_device *netdev = adapter->netdev; |
| 4346 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4347 | struct e1000_phy_info *phy = &adapter->hw.phy; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4348 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4349 | struct e1000_hw *hw = &adapter->hw; |
| 4350 | u32 link, tctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4351 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4352 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4353 | return; |
| 4354 | |
David S. Miller | b405e8d | 2010-02-04 22:31:41 -0800 | [diff] [blame] | 4355 | link = e1000e_has_link(adapter); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4356 | if ((netif_carrier_ok(netdev)) && link) { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4357 | /* Cancel scheduled suspend requests. */ |
| 4358 | pm_runtime_resume(netdev->dev.parent); |
| 4359 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4360 | e1000e_enable_receives(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4361 | goto link_up; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | if ((e1000e_enable_tx_pkt_filtering(hw)) && |
| 4365 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) |
| 4366 | e1000_update_mng_vlan(adapter); |
| 4367 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4368 | if (link) { |
| 4369 | if (!netif_carrier_ok(netdev)) { |
| 4370 | bool txb2b = 1; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4371 | |
| 4372 | /* Cancel scheduled suspend requests. */ |
| 4373 | pm_runtime_resume(netdev->dev.parent); |
| 4374 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4375 | /* update snapshot of PHY registers on LSC */ |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4376 | e1000_phy_read_status(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4377 | mac->ops.get_link_up_info(&adapter->hw, |
| 4378 | &adapter->link_speed, |
| 4379 | &adapter->link_duplex); |
| 4380 | e1000_print_link_info(adapter); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4381 | /* |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 4382 | * On supported PHYs, check for duplex mismatch only |
| 4383 | * if link has autonegotiated at 10/100 half |
| 4384 | */ |
| 4385 | if ((hw->phy.type == e1000_phy_igp_3 || |
| 4386 | hw->phy.type == e1000_phy_bm) && |
| 4387 | (hw->mac.autoneg == true) && |
| 4388 | (adapter->link_speed == SPEED_10 || |
| 4389 | adapter->link_speed == SPEED_100) && |
| 4390 | (adapter->link_duplex == HALF_DUPLEX)) { |
| 4391 | u16 autoneg_exp; |
| 4392 | |
| 4393 | e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp); |
| 4394 | |
| 4395 | if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS)) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 4396 | e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n"); |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 4397 | } |
| 4398 | |
Emil Tantilov | f49c57e | 2010-03-24 12:55:02 +0000 | [diff] [blame] | 4399 | /* adjust timeout factor according to speed/duplex */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4400 | adapter->tx_timeout_factor = 1; |
| 4401 | switch (adapter->link_speed) { |
| 4402 | case SPEED_10: |
| 4403 | txb2b = 0; |
Bruce Allan | 10f1b49 | 2008-08-08 18:36:01 -0700 | [diff] [blame] | 4404 | adapter->tx_timeout_factor = 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4405 | break; |
| 4406 | case SPEED_100: |
| 4407 | txb2b = 0; |
Bruce Allan | 4c86e0b | 2009-11-19 12:35:26 +0000 | [diff] [blame] | 4408 | adapter->tx_timeout_factor = 10; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4409 | break; |
| 4410 | } |
| 4411 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4412 | /* |
| 4413 | * workaround: re-program speed mode bit after |
| 4414 | * link-up event |
| 4415 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4416 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
| 4417 | !txb2b) { |
| 4418 | u32 tarc0; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4419 | tarc0 = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4420 | tarc0 &= ~SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4421 | ew32(TARC(0), tarc0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4422 | } |
| 4423 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4424 | /* |
| 4425 | * disable TSO for pcie and 10/100 speeds, to avoid |
| 4426 | * some hardware issues |
| 4427 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4428 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
| 4429 | switch (adapter->link_speed) { |
| 4430 | case SPEED_10: |
| 4431 | case SPEED_100: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4432 | e_info("10/100 speed: disabling TSO\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4433 | netdev->features &= ~NETIF_F_TSO; |
| 4434 | netdev->features &= ~NETIF_F_TSO6; |
| 4435 | break; |
| 4436 | case SPEED_1000: |
| 4437 | netdev->features |= NETIF_F_TSO; |
| 4438 | netdev->features |= NETIF_F_TSO6; |
| 4439 | break; |
| 4440 | default: |
| 4441 | /* oops */ |
| 4442 | break; |
| 4443 | } |
| 4444 | } |
| 4445 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4446 | /* |
| 4447 | * enable transmits in the hardware, need to do this |
| 4448 | * after setting TARC(0) |
| 4449 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4450 | tctl = er32(TCTL); |
| 4451 | tctl |= E1000_TCTL_EN; |
| 4452 | ew32(TCTL, tctl); |
| 4453 | |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4454 | /* |
| 4455 | * Perform any post-link-up configuration before |
| 4456 | * reporting link up. |
| 4457 | */ |
| 4458 | if (phy->ops.cfg_on_link_up) |
| 4459 | phy->ops.cfg_on_link_up(hw); |
| 4460 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4461 | netif_carrier_on(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4462 | |
| 4463 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4464 | mod_timer(&adapter->phy_info_timer, |
| 4465 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4466 | } |
| 4467 | } else { |
| 4468 | if (netif_carrier_ok(netdev)) { |
| 4469 | adapter->link_speed = 0; |
| 4470 | adapter->link_duplex = 0; |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4471 | /* Link status message must follow this format */ |
| 4472 | printk(KERN_INFO "e1000e: %s NIC Link is Down\n", |
| 4473 | adapter->netdev->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4474 | netif_carrier_off(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4475 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4476 | mod_timer(&adapter->phy_info_timer, |
| 4477 | round_jiffies(jiffies + 2 * HZ)); |
| 4478 | |
| 4479 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) |
| 4480 | schedule_work(&adapter->reset_task); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4481 | else |
| 4482 | pm_schedule_suspend(netdev->dev.parent, |
| 4483 | LINK_TIMEOUT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | link_up: |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4488 | spin_lock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4489 | e1000e_update_stats(adapter); |
| 4490 | |
| 4491 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 4492 | adapter->tpt_old = adapter->stats.tpt; |
| 4493 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; |
| 4494 | adapter->colc_old = adapter->stats.colc; |
| 4495 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4496 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
| 4497 | adapter->gorc_old = adapter->stats.gorc; |
| 4498 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; |
| 4499 | adapter->gotc_old = adapter->stats.gotc; |
Flavio Leitner | 2084b11 | 2011-04-05 04:27:43 +0000 | [diff] [blame] | 4500 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4501 | |
| 4502 | e1000e_update_adaptive(&adapter->hw); |
| 4503 | |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4504 | if (!netif_carrier_ok(netdev) && |
| 4505 | (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) { |
| 4506 | /* |
| 4507 | * We've lost link, so the controller stops DMA, |
| 4508 | * but we've got queued Tx work that's never going |
| 4509 | * to get done, so reset controller to flush Tx. |
| 4510 | * (Do the reset outside of interrupt context). |
| 4511 | */ |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4512 | schedule_work(&adapter->reset_task); |
| 4513 | /* return immediately since reset is imminent */ |
| 4514 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4515 | } |
| 4516 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4517 | /* Simple mode for Interrupt Throttle Rate (ITR) */ |
| 4518 | if (adapter->itr_setting == 4) { |
| 4519 | /* |
| 4520 | * Symmetric Tx/Rx gets a reduced ITR=2000; |
| 4521 | * Total asymmetrical Tx or Rx gets ITR=8000; |
| 4522 | * everyone else is between 2000-8000. |
| 4523 | */ |
| 4524 | u32 goc = (adapter->gotc + adapter->gorc) / 10000; |
| 4525 | u32 dif = (adapter->gotc > adapter->gorc ? |
| 4526 | adapter->gotc - adapter->gorc : |
| 4527 | adapter->gorc - adapter->gotc) / 10000; |
| 4528 | u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 4529 | |
| 4530 | ew32(ITR, 1000000000 / (itr * 256)); |
| 4531 | } |
| 4532 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4533 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4534 | if (adapter->msix_entries) |
| 4535 | ew32(ICS, adapter->rx_ring->ims_val); |
| 4536 | else |
| 4537 | ew32(ICS, E1000_ICS_RXDMT0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4538 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4539 | /* flush pending descriptors to memory before detecting Tx hang */ |
| 4540 | e1000e_flush_descriptors(adapter); |
| 4541 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4542 | /* Force detection of hung controller every watchdog period */ |
| 4543 | adapter->detect_tx_hung = 1; |
| 4544 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4545 | /* |
| 4546 | * With 82571 controllers, LAA may be overwritten due to controller |
| 4547 | * reset from the other port. Set the appropriate LAA in RAR[0] |
| 4548 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4549 | if (e1000e_get_laa_state_82571(hw)) |
| 4550 | e1000e_rar_set(hw, adapter->hw.mac.addr, 0); |
| 4551 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4552 | if (adapter->flags2 & FLAG2_CHECK_PHY_HANG) |
| 4553 | e1000e_check_82574_phy_workaround(adapter); |
| 4554 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4555 | /* Reset the timer */ |
| 4556 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4557 | mod_timer(&adapter->watchdog_timer, |
| 4558 | round_jiffies(jiffies + 2 * HZ)); |
| 4559 | } |
| 4560 | |
| 4561 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 4562 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 4563 | #define E1000_TX_FLAGS_TSO 0x00000004 |
| 4564 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
| 4565 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 4566 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 4567 | |
| 4568 | static int e1000_tso(struct e1000_adapter *adapter, |
| 4569 | struct sk_buff *skb) |
| 4570 | { |
| 4571 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4572 | struct e1000_context_desc *context_desc; |
| 4573 | struct e1000_buffer *buffer_info; |
| 4574 | unsigned int i; |
| 4575 | u32 cmd_length = 0; |
| 4576 | u16 ipcse = 0, tucse, mss; |
| 4577 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4578 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4579 | if (!skb_is_gso(skb)) |
| 4580 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4581 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4582 | if (skb_header_cloned(skb)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4583 | int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4584 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4585 | if (err) |
| 4586 | return err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4587 | } |
| 4588 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4589 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 4590 | mss = skb_shinfo(skb)->gso_size; |
| 4591 | if (skb->protocol == htons(ETH_P_IP)) { |
| 4592 | struct iphdr *iph = ip_hdr(skb); |
| 4593 | iph->tot_len = 0; |
| 4594 | iph->check = 0; |
| 4595 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, |
| 4596 | 0, IPPROTO_TCP, 0); |
| 4597 | cmd_length = E1000_TXD_CMD_IP; |
| 4598 | ipcse = skb_transport_offset(skb) - 1; |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 4599 | } else if (skb_is_gso_v6(skb)) { |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4600 | ipv6_hdr(skb)->payload_len = 0; |
| 4601 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 4602 | &ipv6_hdr(skb)->daddr, |
| 4603 | 0, IPPROTO_TCP, 0); |
| 4604 | ipcse = 0; |
| 4605 | } |
| 4606 | ipcss = skb_network_offset(skb); |
| 4607 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
| 4608 | tucss = skb_transport_offset(skb); |
| 4609 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
| 4610 | tucse = 0; |
| 4611 | |
| 4612 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
| 4613 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
| 4614 | |
| 4615 | i = tx_ring->next_to_use; |
| 4616 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 4617 | buffer_info = &tx_ring->buffer_info[i]; |
| 4618 | |
| 4619 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 4620 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 4621 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 4622 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 4623 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 4624 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 4625 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 4626 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 4627 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 4628 | |
| 4629 | buffer_info->time_stamp = jiffies; |
| 4630 | buffer_info->next_to_watch = i; |
| 4631 | |
| 4632 | i++; |
| 4633 | if (i == tx_ring->count) |
| 4634 | i = 0; |
| 4635 | tx_ring->next_to_use = i; |
| 4636 | |
| 4637 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4638 | } |
| 4639 | |
| 4640 | static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 4641 | { |
| 4642 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4643 | struct e1000_context_desc *context_desc; |
| 4644 | struct e1000_buffer *buffer_info; |
| 4645 | unsigned int i; |
| 4646 | u8 css; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4647 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4648 | __be16 protocol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4649 | |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4650 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 4651 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4652 | |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4653 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) |
| 4654 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 4655 | else |
| 4656 | protocol = skb->protocol; |
| 4657 | |
Arthur Jones | 3f51839 | 2009-03-20 15:56:35 -0700 | [diff] [blame] | 4658 | switch (protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4659 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4660 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 4661 | cmd_len |= E1000_TXD_CMD_TCP; |
| 4662 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4663 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4664 | /* XXX not handling all IPV6 headers */ |
| 4665 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 4666 | cmd_len |= E1000_TXD_CMD_TCP; |
| 4667 | break; |
| 4668 | default: |
| 4669 | if (unlikely(net_ratelimit())) |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4670 | e_warn("checksum_partial proto=%x!\n", |
| 4671 | be16_to_cpu(protocol)); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4672 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 4675 | css = skb_checksum_start_offset(skb); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4676 | |
| 4677 | i = tx_ring->next_to_use; |
| 4678 | buffer_info = &tx_ring->buffer_info[i]; |
| 4679 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 4680 | |
| 4681 | context_desc->lower_setup.ip_config = 0; |
| 4682 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 4683 | context_desc->upper_setup.tcp_fields.tucso = |
| 4684 | css + skb->csum_offset; |
| 4685 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 4686 | context_desc->tcp_seg_setup.data = 0; |
| 4687 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 4688 | |
| 4689 | buffer_info->time_stamp = jiffies; |
| 4690 | buffer_info->next_to_watch = i; |
| 4691 | |
| 4692 | i++; |
| 4693 | if (i == tx_ring->count) |
| 4694 | i = 0; |
| 4695 | tx_ring->next_to_use = i; |
| 4696 | |
| 4697 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | #define E1000_MAX_PER_TXD 8192 |
| 4701 | #define E1000_MAX_TXD_PWR 12 |
| 4702 | |
| 4703 | static int e1000_tx_map(struct e1000_adapter *adapter, |
| 4704 | struct sk_buff *skb, unsigned int first, |
| 4705 | unsigned int max_per_txd, unsigned int nr_frags, |
| 4706 | unsigned int mss) |
| 4707 | { |
| 4708 | struct e1000_ring *tx_ring = adapter->tx_ring; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4709 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4710 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 4711 | unsigned int len = skb_headlen(skb); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4712 | unsigned int offset = 0, size, count = 0, i; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4713 | unsigned int f, bytecount, segs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4714 | |
| 4715 | i = tx_ring->next_to_use; |
| 4716 | |
| 4717 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4718 | buffer_info = &tx_ring->buffer_info[i]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4719 | size = min(len, max_per_txd); |
| 4720 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4721 | buffer_info->length = size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4722 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4723 | buffer_info->next_to_watch = i; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4724 | buffer_info->dma = dma_map_single(&pdev->dev, |
| 4725 | skb->data + offset, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4726 | size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4727 | buffer_info->mapped_as_page = false; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4728 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4729 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4730 | |
| 4731 | len -= size; |
| 4732 | offset += size; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4733 | count++; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4734 | |
| 4735 | if (len) { |
| 4736 | i++; |
| 4737 | if (i == tx_ring->count) |
| 4738 | i = 0; |
| 4739 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | for (f = 0; f < nr_frags; f++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 4743 | const struct skb_frag_struct *frag; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4744 | |
| 4745 | frag = &skb_shinfo(skb)->frags[f]; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 4746 | len = skb_frag_size(frag); |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 4747 | offset = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4748 | |
| 4749 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4750 | i++; |
| 4751 | if (i == tx_ring->count) |
| 4752 | i = 0; |
| 4753 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4754 | buffer_info = &tx_ring->buffer_info[i]; |
| 4755 | size = min(len, max_per_txd); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4756 | |
| 4757 | buffer_info->length = size; |
| 4758 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4759 | buffer_info->next_to_watch = i; |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 4760 | buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag, |
| 4761 | offset, size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4762 | buffer_info->mapped_as_page = true; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4763 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4764 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4765 | |
| 4766 | len -= size; |
| 4767 | offset += size; |
| 4768 | count++; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4769 | } |
| 4770 | } |
| 4771 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4772 | segs = skb_shinfo(skb)->gso_segs ? : 1; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4773 | /* multiply data chunks by size of headers */ |
| 4774 | bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len; |
| 4775 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4776 | tx_ring->buffer_info[i].skb = skb; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4777 | tx_ring->buffer_info[i].segs = segs; |
| 4778 | tx_ring->buffer_info[i].bytecount = bytecount; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4779 | tx_ring->buffer_info[first].next_to_watch = i; |
| 4780 | |
| 4781 | return count; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4782 | |
| 4783 | dma_error: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4784 | dev_err(&pdev->dev, "Tx DMA map failed\n"); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4785 | buffer_info->dma = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4786 | if (count) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4787 | count--; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4788 | |
| 4789 | while (count--) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4790 | if (i == 0) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4791 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4792 | i--; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4793 | buffer_info = &tx_ring->buffer_info[i]; |
Joe Perches | 1d51c41 | 2010-11-14 17:04:32 +0000 | [diff] [blame] | 4794 | e1000_put_txbuf(adapter, buffer_info); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4795 | } |
| 4796 | |
| 4797 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | static void e1000_tx_queue(struct e1000_adapter *adapter, |
| 4801 | int tx_flags, int count) |
| 4802 | { |
| 4803 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4804 | struct e1000_tx_desc *tx_desc = NULL; |
| 4805 | struct e1000_buffer *buffer_info; |
| 4806 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 4807 | unsigned int i; |
| 4808 | |
| 4809 | if (tx_flags & E1000_TX_FLAGS_TSO) { |
| 4810 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 4811 | E1000_TXD_CMD_TSE; |
| 4812 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 4813 | |
| 4814 | if (tx_flags & E1000_TX_FLAGS_IPV4) |
| 4815 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
| 4816 | } |
| 4817 | |
| 4818 | if (tx_flags & E1000_TX_FLAGS_CSUM) { |
| 4819 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 4820 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 4821 | } |
| 4822 | |
| 4823 | if (tx_flags & E1000_TX_FLAGS_VLAN) { |
| 4824 | txd_lower |= E1000_TXD_CMD_VLE; |
| 4825 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 4826 | } |
| 4827 | |
| 4828 | i = tx_ring->next_to_use; |
| 4829 | |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 4830 | do { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4831 | buffer_info = &tx_ring->buffer_info[i]; |
| 4832 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 4833 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4834 | tx_desc->lower.data = |
| 4835 | cpu_to_le32(txd_lower | buffer_info->length); |
| 4836 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
| 4837 | |
| 4838 | i++; |
| 4839 | if (i == tx_ring->count) |
| 4840 | i = 0; |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 4841 | } while (--count > 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4842 | |
| 4843 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 4844 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4845 | /* |
| 4846 | * Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4847 | * know there are new descriptors to fetch. (Only |
| 4848 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4849 | * such as IA-64). |
| 4850 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4851 | wmb(); |
| 4852 | |
| 4853 | tx_ring->next_to_use = i; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 4854 | |
| 4855 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 4856 | e1000e_update_tdt_wa(adapter, i); |
| 4857 | else |
| 4858 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 4859 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4860 | /* |
| 4861 | * we need this if more than one processor can write to our tail |
| 4862 | * at a time, it synchronizes IO on IA64/Altix systems |
| 4863 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4864 | mmiowb(); |
| 4865 | } |
| 4866 | |
| 4867 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 4868 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 4869 | struct sk_buff *skb) |
| 4870 | { |
| 4871 | struct e1000_hw *hw = &adapter->hw; |
| 4872 | u16 length, offset; |
| 4873 | |
| 4874 | if (vlan_tx_tag_present(skb)) { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 4875 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
| 4876 | (adapter->hw.mng_cookie.status & |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4877 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) |
| 4878 | return 0; |
| 4879 | } |
| 4880 | |
| 4881 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) |
| 4882 | return 0; |
| 4883 | |
| 4884 | if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP)) |
| 4885 | return 0; |
| 4886 | |
| 4887 | { |
| 4888 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14); |
| 4889 | struct udphdr *udp; |
| 4890 | |
| 4891 | if (ip->protocol != IPPROTO_UDP) |
| 4892 | return 0; |
| 4893 | |
| 4894 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 4895 | if (ntohs(udp->dest) != 67) |
| 4896 | return 0; |
| 4897 | |
| 4898 | offset = (u8 *)udp + 8 - skb->data; |
| 4899 | length = skb->len - offset; |
| 4900 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); |
| 4901 | } |
| 4902 | |
| 4903 | return 0; |
| 4904 | } |
| 4905 | |
| 4906 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 4907 | { |
| 4908 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4909 | |
| 4910 | netif_stop_queue(netdev); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4911 | /* |
| 4912 | * Herbert's original patch had: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4913 | * smp_mb__after_netif_stop_queue(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4914 | * but since that doesn't exist yet, just open code it. |
| 4915 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4916 | smp_mb(); |
| 4917 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4918 | /* |
| 4919 | * We need to check again in a case another CPU has just |
| 4920 | * made room available. |
| 4921 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4922 | if (e1000_desc_unused(adapter->tx_ring) < size) |
| 4923 | return -EBUSY; |
| 4924 | |
| 4925 | /* A reprieve! */ |
| 4926 | netif_start_queue(netdev); |
| 4927 | ++adapter->restart_queue; |
| 4928 | return 0; |
| 4929 | } |
| 4930 | |
| 4931 | static int e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 4932 | { |
| 4933 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4934 | |
| 4935 | if (e1000_desc_unused(adapter->tx_ring) >= size) |
| 4936 | return 0; |
| 4937 | return __e1000_maybe_stop_tx(netdev, size); |
| 4938 | } |
| 4939 | |
| 4940 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 4941 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 4942 | struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4943 | { |
| 4944 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4945 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4946 | unsigned int first; |
| 4947 | unsigned int max_per_txd = E1000_MAX_PER_TXD; |
| 4948 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 4949 | unsigned int tx_flags = 0; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 4950 | unsigned int len = skb_headlen(skb); |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 4951 | unsigned int nr_frags; |
| 4952 | unsigned int mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4953 | int count = 0; |
| 4954 | int tso; |
| 4955 | unsigned int f; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4956 | |
| 4957 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 4958 | dev_kfree_skb_any(skb); |
| 4959 | return NETDEV_TX_OK; |
| 4960 | } |
| 4961 | |
| 4962 | if (skb->len <= 0) { |
| 4963 | dev_kfree_skb_any(skb); |
| 4964 | return NETDEV_TX_OK; |
| 4965 | } |
| 4966 | |
| 4967 | mss = skb_shinfo(skb)->gso_size; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4968 | /* |
| 4969 | * The controller does a simple calculation to |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4970 | * make sure there is enough room in the FIFO before |
| 4971 | * initiating the DMA for each buffer. The calc is: |
| 4972 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 4973 | * overrun the FIFO, adjust the max buffer len if mss |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4974 | * drops. |
| 4975 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4976 | if (mss) { |
| 4977 | u8 hdr_len; |
| 4978 | max_per_txd = min(mss << 2, max_per_txd); |
| 4979 | max_txd_pwr = fls(max_per_txd) - 1; |
| 4980 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4981 | /* |
| 4982 | * TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 4983 | * points to just header, pull a few bytes of payload from |
| 4984 | * frags into skb->data |
| 4985 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4986 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4987 | /* |
| 4988 | * we do this workaround for ES2LAN, but it is un-necessary, |
| 4989 | * avoiding it could save a lot of cycles |
| 4990 | */ |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 4991 | if (skb->data_len && (hdr_len == len)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4992 | unsigned int pull_size; |
| 4993 | |
| 4994 | pull_size = min((unsigned int)4, skb->data_len); |
| 4995 | if (!__pskb_pull_tail(skb, pull_size)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4996 | e_err("__pskb_pull_tail failed.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4997 | dev_kfree_skb_any(skb); |
| 4998 | return NETDEV_TX_OK; |
| 4999 | } |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5000 | len = skb_headlen(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5001 | } |
| 5002 | } |
| 5003 | |
| 5004 | /* reserve a descriptor for the offload context */ |
| 5005 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5006 | count++; |
| 5007 | count++; |
| 5008 | |
| 5009 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 5010 | |
| 5011 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 5012 | for (f = 0; f < nr_frags; f++) |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5013 | count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]), |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5014 | max_txd_pwr); |
| 5015 | |
| 5016 | if (adapter->hw.mac.tx_pkt_filtering) |
| 5017 | e1000_transfer_dhcp_info(adapter, skb); |
| 5018 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5019 | /* |
| 5020 | * need: count + 2 desc gap to keep tail from touching |
| 5021 | * head, otherwise try next time |
| 5022 | */ |
Jesse Brandeburg | 92af3e9 | 2009-01-19 14:17:08 +0000 | [diff] [blame] | 5023 | if (e1000_maybe_stop_tx(netdev, count + 2)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5024 | return NETDEV_TX_BUSY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5025 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 5026 | if (vlan_tx_tag_present(skb)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5027 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 5028 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 5029 | } |
| 5030 | |
| 5031 | first = tx_ring->next_to_use; |
| 5032 | |
| 5033 | tso = e1000_tso(adapter, skb); |
| 5034 | if (tso < 0) { |
| 5035 | dev_kfree_skb_any(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5036 | return NETDEV_TX_OK; |
| 5037 | } |
| 5038 | |
| 5039 | if (tso) |
| 5040 | tx_flags |= E1000_TX_FLAGS_TSO; |
| 5041 | else if (e1000_tx_csum(adapter, skb)) |
| 5042 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 5043 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5044 | /* |
| 5045 | * 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] | 5046 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5047 | * no longer assume, we must. |
| 5048 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5049 | if (skb->protocol == htons(ETH_P_IP)) |
| 5050 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 5051 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5052 | /* if count is 0 then mapping error has occurred */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5053 | 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] | 5054 | if (count) { |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 5055 | netdev_sent_queue(netdev, skb->len); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5056 | e1000_tx_queue(adapter, tx_flags, count); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5057 | /* Make sure there is space in the ring for the next send. */ |
| 5058 | e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2); |
| 5059 | |
| 5060 | } else { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5061 | dev_kfree_skb_any(skb); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5062 | tx_ring->buffer_info[first].time_stamp = 0; |
| 5063 | tx_ring->next_to_use = first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5064 | } |
| 5065 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5066 | return NETDEV_TX_OK; |
| 5067 | } |
| 5068 | |
| 5069 | /** |
| 5070 | * e1000_tx_timeout - Respond to a Tx Hang |
| 5071 | * @netdev: network interface device structure |
| 5072 | **/ |
| 5073 | static void e1000_tx_timeout(struct net_device *netdev) |
| 5074 | { |
| 5075 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5076 | |
| 5077 | /* Do the reset outside of interrupt context */ |
| 5078 | adapter->tx_timeout_count++; |
| 5079 | schedule_work(&adapter->reset_task); |
| 5080 | } |
| 5081 | |
| 5082 | static void e1000_reset_task(struct work_struct *work) |
| 5083 | { |
| 5084 | struct e1000_adapter *adapter; |
| 5085 | adapter = container_of(work, struct e1000_adapter, reset_task); |
| 5086 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 5087 | /* don't run the task if already down */ |
| 5088 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 5089 | return; |
| 5090 | |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 5091 | if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 5092 | (adapter->flags & FLAG_RX_RESTART_NOW))) { |
| 5093 | e1000e_dump(adapter); |
| 5094 | e_err("Reset adapter\n"); |
| 5095 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5096 | e1000e_reinit_locked(adapter); |
| 5097 | } |
| 5098 | |
| 5099 | /** |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5100 | * e1000_get_stats64 - Get System Network Statistics |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5101 | * @netdev: network interface device structure |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5102 | * @stats: rtnl_link_stats64 pointer |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5103 | * |
| 5104 | * Returns the address of the device statistics structure. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5105 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5106 | struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev, |
| 5107 | struct rtnl_link_stats64 *stats) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5108 | { |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5109 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5110 | |
| 5111 | memset(stats, 0, sizeof(struct rtnl_link_stats64)); |
| 5112 | spin_lock(&adapter->stats64_lock); |
| 5113 | e1000e_update_stats(adapter); |
| 5114 | /* Fill out the OS statistics structure */ |
| 5115 | stats->rx_bytes = adapter->stats.gorc; |
| 5116 | stats->rx_packets = adapter->stats.gprc; |
| 5117 | stats->tx_bytes = adapter->stats.gotc; |
| 5118 | stats->tx_packets = adapter->stats.gptc; |
| 5119 | stats->multicast = adapter->stats.mprc; |
| 5120 | stats->collisions = adapter->stats.colc; |
| 5121 | |
| 5122 | /* Rx Errors */ |
| 5123 | |
| 5124 | /* |
| 5125 | * RLEC on some newer hardware can be incorrect so build |
| 5126 | * our own version based on RUC and ROC |
| 5127 | */ |
| 5128 | stats->rx_errors = adapter->stats.rxerrc + |
| 5129 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 5130 | adapter->stats.ruc + adapter->stats.roc + |
| 5131 | adapter->stats.cexterr; |
| 5132 | stats->rx_length_errors = adapter->stats.ruc + |
| 5133 | adapter->stats.roc; |
| 5134 | stats->rx_crc_errors = adapter->stats.crcerrs; |
| 5135 | stats->rx_frame_errors = adapter->stats.algnerrc; |
| 5136 | stats->rx_missed_errors = adapter->stats.mpc; |
| 5137 | |
| 5138 | /* Tx Errors */ |
| 5139 | stats->tx_errors = adapter->stats.ecol + |
| 5140 | adapter->stats.latecol; |
| 5141 | stats->tx_aborted_errors = adapter->stats.ecol; |
| 5142 | stats->tx_window_errors = adapter->stats.latecol; |
| 5143 | stats->tx_carrier_errors = adapter->stats.tncrs; |
| 5144 | |
| 5145 | /* Tx Dropped needs to be maintained elsewhere */ |
| 5146 | |
| 5147 | spin_unlock(&adapter->stats64_lock); |
| 5148 | return stats; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5149 | } |
| 5150 | |
| 5151 | /** |
| 5152 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 5153 | * @netdev: network interface device structure |
| 5154 | * @new_mtu: new value for maximum frame size |
| 5155 | * |
| 5156 | * Returns 0 on success, negative on failure |
| 5157 | **/ |
| 5158 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 5159 | { |
| 5160 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5161 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5162 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5163 | /* Jumbo frame support */ |
| 5164 | if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) && |
| 5165 | !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
| 5166 | e_err("Jumbo Frames not supported.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5167 | return -EINVAL; |
| 5168 | } |
| 5169 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5170 | /* Supported frame sizes */ |
| 5171 | if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) || |
| 5172 | (max_frame > adapter->max_hw_frame_size)) { |
| 5173 | e_err("Unsupported MTU setting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5174 | return -EINVAL; |
| 5175 | } |
| 5176 | |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 5177 | /* Jumbo frame workaround on 82579 requires CRC be stripped */ |
| 5178 | if ((adapter->hw.mac.type == e1000_pch2lan) && |
| 5179 | !(adapter->flags2 & FLAG2_CRC_STRIPPING) && |
| 5180 | (new_mtu > ETH_DATA_LEN)) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 5181 | e_err("Jumbo Frames not supported on 82579 when CRC stripping is disabled.\n"); |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 5182 | return -EINVAL; |
| 5183 | } |
| 5184 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5185 | /* 82573 Errata 17 */ |
| 5186 | if (((adapter->hw.mac.type == e1000_82573) || |
| 5187 | (adapter->hw.mac.type == e1000_82574)) && |
| 5188 | (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) { |
| 5189 | adapter->flags2 |= FLAG2_DISABLE_ASPM_L1; |
| 5190 | e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1); |
| 5191 | } |
| 5192 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5193 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 5194 | usleep_range(1000, 2000); |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5195 | /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5196 | adapter->max_frame_size = max_frame; |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5197 | e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
| 5198 | netdev->mtu = new_mtu; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5199 | if (netif_running(netdev)) |
| 5200 | e1000e_down(adapter); |
| 5201 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5202 | /* |
| 5203 | * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5204 | * means we reserve 2 more, this pushes us to allocate from the next |
| 5205 | * larger slab size. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5206 | * i.e. RXBUFFER_2048 --> size-4096 slab |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5207 | * However with the new *_jumbo_rx* routines, jumbo receives will use |
| 5208 | * fragmented skbs |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5209 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5210 | |
Jesse Brandeburg | 9926146 | 2010-01-22 22:56:16 +0000 | [diff] [blame] | 5211 | if (max_frame <= 2048) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5212 | adapter->rx_buffer_len = 2048; |
| 5213 | else |
| 5214 | adapter->rx_buffer_len = 4096; |
| 5215 | |
| 5216 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
| 5217 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || |
| 5218 | (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) |
| 5219 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5220 | + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5221 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5222 | if (netif_running(netdev)) |
| 5223 | e1000e_up(adapter); |
| 5224 | else |
| 5225 | e1000e_reset(adapter); |
| 5226 | |
| 5227 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 5228 | |
| 5229 | return 0; |
| 5230 | } |
| 5231 | |
| 5232 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 5233 | int cmd) |
| 5234 | { |
| 5235 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5236 | struct mii_ioctl_data *data = if_mii(ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5237 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5238 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5239 | return -EOPNOTSUPP; |
| 5240 | |
| 5241 | switch (cmd) { |
| 5242 | case SIOCGMIIPHY: |
| 5243 | data->phy_id = adapter->hw.phy.addr; |
| 5244 | break; |
| 5245 | case SIOCGMIIREG: |
Bruce Allan | b16a002 | 2009-11-20 23:24:30 +0000 | [diff] [blame] | 5246 | e1000_phy_read_status(adapter); |
| 5247 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5248 | switch (data->reg_num & 0x1F) { |
| 5249 | case MII_BMCR: |
| 5250 | data->val_out = adapter->phy_regs.bmcr; |
| 5251 | break; |
| 5252 | case MII_BMSR: |
| 5253 | data->val_out = adapter->phy_regs.bmsr; |
| 5254 | break; |
| 5255 | case MII_PHYSID1: |
| 5256 | data->val_out = (adapter->hw.phy.id >> 16); |
| 5257 | break; |
| 5258 | case MII_PHYSID2: |
| 5259 | data->val_out = (adapter->hw.phy.id & 0xFFFF); |
| 5260 | break; |
| 5261 | case MII_ADVERTISE: |
| 5262 | data->val_out = adapter->phy_regs.advertise; |
| 5263 | break; |
| 5264 | case MII_LPA: |
| 5265 | data->val_out = adapter->phy_regs.lpa; |
| 5266 | break; |
| 5267 | case MII_EXPANSION: |
| 5268 | data->val_out = adapter->phy_regs.expansion; |
| 5269 | break; |
| 5270 | case MII_CTRL1000: |
| 5271 | data->val_out = adapter->phy_regs.ctrl1000; |
| 5272 | break; |
| 5273 | case MII_STAT1000: |
| 5274 | data->val_out = adapter->phy_regs.stat1000; |
| 5275 | break; |
| 5276 | case MII_ESTATUS: |
| 5277 | data->val_out = adapter->phy_regs.estatus; |
| 5278 | break; |
| 5279 | default: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5280 | return -EIO; |
| 5281 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5282 | break; |
| 5283 | case SIOCSMIIREG: |
| 5284 | default: |
| 5285 | return -EOPNOTSUPP; |
| 5286 | } |
| 5287 | return 0; |
| 5288 | } |
| 5289 | |
| 5290 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 5291 | { |
| 5292 | switch (cmd) { |
| 5293 | case SIOCGMIIPHY: |
| 5294 | case SIOCGMIIREG: |
| 5295 | case SIOCSMIIREG: |
| 5296 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 5297 | default: |
| 5298 | return -EOPNOTSUPP; |
| 5299 | } |
| 5300 | } |
| 5301 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5302 | static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) |
| 5303 | { |
| 5304 | struct e1000_hw *hw = &adapter->hw; |
| 5305 | u32 i, mac_reg; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5306 | u16 phy_reg, wuc_enable; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5307 | int retval = 0; |
| 5308 | |
| 5309 | /* copy MAC RARs to PHY RARs */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 5310 | e1000_copy_rx_addrs_to_phy_ich8lan(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5311 | |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5312 | retval = hw->phy.ops.acquire(hw); |
| 5313 | if (retval) { |
| 5314 | e_err("Could not acquire PHY\n"); |
| 5315 | return retval; |
| 5316 | } |
| 5317 | |
| 5318 | /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */ |
| 5319 | retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
| 5320 | if (retval) |
| 5321 | goto out; |
| 5322 | |
| 5323 | /* copy MAC MTA to PHY MTA - only needed for pchlan */ |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5324 | for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { |
| 5325 | mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5326 | hw->phy.ops.write_reg_page(hw, BM_MTA(i), |
| 5327 | (u16)(mac_reg & 0xFFFF)); |
| 5328 | hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1, |
| 5329 | (u16)((mac_reg >> 16) & 0xFFFF)); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | /* configure PHY Rx Control register */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5333 | hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5334 | mac_reg = er32(RCTL); |
| 5335 | if (mac_reg & E1000_RCTL_UPE) |
| 5336 | phy_reg |= BM_RCTL_UPE; |
| 5337 | if (mac_reg & E1000_RCTL_MPE) |
| 5338 | phy_reg |= BM_RCTL_MPE; |
| 5339 | phy_reg &= ~(BM_RCTL_MO_MASK); |
| 5340 | if (mac_reg & E1000_RCTL_MO_3) |
| 5341 | phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) |
| 5342 | << BM_RCTL_MO_SHIFT); |
| 5343 | if (mac_reg & E1000_RCTL_BAM) |
| 5344 | phy_reg |= BM_RCTL_BAM; |
| 5345 | if (mac_reg & E1000_RCTL_PMCF) |
| 5346 | phy_reg |= BM_RCTL_PMCF; |
| 5347 | mac_reg = er32(CTRL); |
| 5348 | if (mac_reg & E1000_CTRL_RFCE) |
| 5349 | phy_reg |= BM_RCTL_RFCE; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5350 | hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5351 | |
| 5352 | /* enable PHY wakeup in MAC register */ |
| 5353 | ew32(WUFC, wufc); |
| 5354 | ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN); |
| 5355 | |
| 5356 | /* configure and enable PHY wakeup in PHY registers */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5357 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc); |
| 5358 | 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] | 5359 | |
| 5360 | /* activate PHY wakeup */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5361 | wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; |
| 5362 | retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5363 | if (retval) |
| 5364 | e_err("Could not set PHY Host Wakeup bit\n"); |
| 5365 | out: |
Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 5366 | hw->phy.ops.release(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5367 | |
| 5368 | return retval; |
| 5369 | } |
| 5370 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5371 | static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake, |
| 5372 | bool runtime) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5373 | { |
| 5374 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5375 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5376 | struct e1000_hw *hw = &adapter->hw; |
| 5377 | u32 ctrl, ctrl_ext, rctl, status; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5378 | /* Runtime suspend should only enable wakeup for link changes */ |
| 5379 | u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5380 | int retval = 0; |
| 5381 | |
| 5382 | netif_device_detach(netdev); |
| 5383 | |
| 5384 | if (netif_running(netdev)) { |
| 5385 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 5386 | e1000e_down(adapter); |
| 5387 | e1000_free_irq(adapter); |
| 5388 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5389 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5390 | |
| 5391 | retval = pci_save_state(pdev); |
| 5392 | if (retval) |
| 5393 | return retval; |
| 5394 | |
| 5395 | status = er32(STATUS); |
| 5396 | if (status & E1000_STATUS_LU) |
| 5397 | wufc &= ~E1000_WUFC_LNKC; |
| 5398 | |
| 5399 | if (wufc) { |
| 5400 | e1000_setup_rctl(adapter); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 5401 | e1000e_set_rx_mode(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5402 | |
| 5403 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5404 | if (wufc & E1000_WUFC_MC) { |
| 5405 | rctl = er32(RCTL); |
| 5406 | rctl |= E1000_RCTL_MPE; |
| 5407 | ew32(RCTL, rctl); |
| 5408 | } |
| 5409 | |
| 5410 | ctrl = er32(CTRL); |
| 5411 | /* advertise wake from D3Cold */ |
| 5412 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5413 | /* phy power management enable */ |
| 5414 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5415 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 5416 | if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) |
| 5417 | ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5418 | ew32(CTRL, ctrl); |
| 5419 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5420 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
| 5421 | adapter->hw.phy.media_type == |
| 5422 | e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5423 | /* keep the laser running in D3 */ |
| 5424 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | 93a23f4 | 2009-12-08 07:27:41 +0000 | [diff] [blame] | 5425 | ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5426 | ew32(CTRL_EXT, ctrl_ext); |
| 5427 | } |
| 5428 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5429 | if (adapter->flags & FLAG_IS_ICH) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5430 | e1000_suspend_workarounds_ich8lan(&adapter->hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5431 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5432 | /* Allow time for pending master requests to run */ |
| 5433 | e1000e_disable_pcie_master(&adapter->hw); |
| 5434 | |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5435 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5436 | /* enable wakeup by the PHY */ |
| 5437 | retval = e1000_init_phy_wakeup(adapter, wufc); |
| 5438 | if (retval) |
| 5439 | return retval; |
| 5440 | } else { |
| 5441 | /* enable wakeup by the MAC */ |
| 5442 | ew32(WUFC, wufc); |
| 5443 | ew32(WUC, E1000_WUC_PME_EN); |
| 5444 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5445 | } else { |
| 5446 | ew32(WUC, 0); |
| 5447 | ew32(WUFC, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5448 | } |
| 5449 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5450 | *enable_wake = !!wufc; |
| 5451 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5452 | /* make sure adapter isn't asleep if manageability is enabled */ |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5453 | if ((adapter->flags & FLAG_MNG_PT_ENABLED) || |
| 5454 | (hw->mac.ops.check_mng_mode(hw))) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5455 | *enable_wake = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5456 | |
| 5457 | if (adapter->hw.phy.type == e1000_phy_igp_3) |
| 5458 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
| 5459 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5460 | /* |
| 5461 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5462 | * would have already happened in close and is redundant. |
| 5463 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5464 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5465 | |
| 5466 | pci_disable_device(pdev); |
| 5467 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5468 | return 0; |
| 5469 | } |
| 5470 | |
| 5471 | static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake) |
| 5472 | { |
| 5473 | if (sleep && wake) { |
| 5474 | pci_prepare_to_sleep(pdev); |
| 5475 | return; |
| 5476 | } |
| 5477 | |
| 5478 | pci_wake_from_d3(pdev, wake); |
| 5479 | pci_set_power_state(pdev, PCI_D3hot); |
| 5480 | } |
| 5481 | |
| 5482 | static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, |
| 5483 | bool wake) |
| 5484 | { |
| 5485 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5486 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5487 | |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5488 | /* |
| 5489 | * The pci-e switch on some quad port adapters will report a |
| 5490 | * correctable error when the MAC transitions from D0 to D3. To |
| 5491 | * prevent this we need to mask off the correctable errors on the |
| 5492 | * downstream port of the pci-e switch. |
| 5493 | */ |
| 5494 | if (adapter->flags & FLAG_IS_QUAD_PORT) { |
| 5495 | struct pci_dev *us_dev = pdev->bus->self; |
Jon Mason | 353064d | 2011-06-27 07:43:47 +0000 | [diff] [blame] | 5496 | int pos = pci_pcie_cap(us_dev); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5497 | u16 devctl; |
| 5498 | |
| 5499 | pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl); |
| 5500 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, |
| 5501 | (devctl & ~PCI_EXP_DEVCTL_CERE)); |
| 5502 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5503 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5504 | |
| 5505 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl); |
| 5506 | } else { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5507 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5508 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5509 | } |
| 5510 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5511 | #ifdef CONFIG_PCIEASPM |
| 5512 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
| 5513 | { |
Yinghai Lu | 9f728f5 | 2011-05-12 17:11:47 -0700 | [diff] [blame] | 5514 | pci_disable_link_state_locked(pdev, state); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5515 | } |
| 5516 | #else |
| 5517 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5518 | { |
| 5519 | int pos; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5520 | u16 reg16; |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5521 | |
| 5522 | /* |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5523 | * Both device and parent should have the same ASPM setting. |
| 5524 | * Disable ASPM in downstream component first and then upstream. |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5525 | */ |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5526 | pos = pci_pcie_cap(pdev); |
| 5527 | pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16); |
| 5528 | reg16 &= ~state; |
| 5529 | pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16); |
| 5530 | |
Anton Blanchard | 0c75ba2 | 2010-04-28 21:46:06 +0000 | [diff] [blame] | 5531 | if (!pdev->bus->self) |
| 5532 | return; |
| 5533 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5534 | pos = pci_pcie_cap(pdev->bus->self); |
| 5535 | pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, ®16); |
| 5536 | reg16 &= ~state; |
| 5537 | pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16); |
| 5538 | } |
| 5539 | #endif |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5540 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5541 | { |
| 5542 | dev_info(&pdev->dev, "Disabling ASPM %s %s\n", |
| 5543 | (state & PCIE_LINK_STATE_L0S) ? "L0s" : "", |
| 5544 | (state & PCIE_LINK_STATE_L1) ? "L1" : ""); |
| 5545 | |
| 5546 | __e1000e_disable_aspm(pdev, state); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5547 | } |
| 5548 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 5549 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5550 | static bool e1000e_pm_ready(struct e1000_adapter *adapter) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5551 | { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5552 | return !!adapter->tx_ring->buffer_info; |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5553 | } |
| 5554 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5555 | static int __e1000_resume(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5556 | { |
| 5557 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5558 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5559 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5560 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5561 | u32 err; |
| 5562 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5563 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5564 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
| 5565 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
| 5566 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5567 | if (aspm_disable_flag) |
| 5568 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 5569 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5570 | pci_set_power_state(pdev, PCI_D0); |
| 5571 | pci_restore_state(pdev); |
Bruce Allan | 28b8f04 | 2010-01-07 16:30:56 +0000 | [diff] [blame] | 5572 | pci_save_state(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5573 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5574 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5575 | if (netif_running(netdev)) { |
| 5576 | err = e1000_request_irq(adapter); |
| 5577 | if (err) |
| 5578 | return err; |
| 5579 | } |
| 5580 | |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5581 | if (hw->mac.type == e1000_pch2lan) |
| 5582 | e1000_resume_workarounds_pchlan(&adapter->hw); |
| 5583 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5584 | e1000e_power_up_phy(adapter); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5585 | |
| 5586 | /* report the system wakeup cause from S3/S4 */ |
| 5587 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
| 5588 | u16 phy_data; |
| 5589 | |
| 5590 | e1e_rphy(&adapter->hw, BM_WUS, &phy_data); |
| 5591 | if (phy_data) { |
| 5592 | e_info("PHY Wakeup cause - %s\n", |
| 5593 | phy_data & E1000_WUS_EX ? "Unicast Packet" : |
| 5594 | phy_data & E1000_WUS_MC ? "Multicast Packet" : |
| 5595 | phy_data & E1000_WUS_BC ? "Broadcast Packet" : |
| 5596 | phy_data & E1000_WUS_MAG ? "Magic Packet" : |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 5597 | phy_data & E1000_WUS_LNKC ? |
| 5598 | "Link Status Change" : "other"); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5599 | } |
| 5600 | e1e_wphy(&adapter->hw, BM_WUS, ~0); |
| 5601 | } else { |
| 5602 | u32 wus = er32(WUS); |
| 5603 | if (wus) { |
| 5604 | e_info("MAC Wakeup cause - %s\n", |
| 5605 | wus & E1000_WUS_EX ? "Unicast Packet" : |
| 5606 | wus & E1000_WUS_MC ? "Multicast Packet" : |
| 5607 | wus & E1000_WUS_BC ? "Broadcast Packet" : |
| 5608 | wus & E1000_WUS_MAG ? "Magic Packet" : |
| 5609 | wus & E1000_WUS_LNKC ? "Link Status Change" : |
| 5610 | "other"); |
| 5611 | } |
| 5612 | ew32(WUS, ~0); |
| 5613 | } |
| 5614 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5615 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5616 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 5617 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5618 | |
| 5619 | if (netif_running(netdev)) |
| 5620 | e1000e_up(adapter); |
| 5621 | |
| 5622 | netif_device_attach(netdev); |
| 5623 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5624 | /* |
| 5625 | * 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] | 5626 | * 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] | 5627 | * under the control of the driver. |
| 5628 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5629 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5630 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5631 | |
| 5632 | return 0; |
| 5633 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5634 | |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5635 | #ifdef CONFIG_PM_SLEEP |
| 5636 | static int e1000_suspend(struct device *dev) |
| 5637 | { |
| 5638 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5639 | int retval; |
| 5640 | bool wake; |
| 5641 | |
| 5642 | retval = __e1000_shutdown(pdev, &wake, false); |
| 5643 | if (!retval) |
| 5644 | e1000_complete_shutdown(pdev, true, wake); |
| 5645 | |
| 5646 | return retval; |
| 5647 | } |
| 5648 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5649 | static int e1000_resume(struct device *dev) |
| 5650 | { |
| 5651 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5652 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5653 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5654 | |
| 5655 | if (e1000e_pm_ready(adapter)) |
| 5656 | adapter->idle_check = true; |
| 5657 | |
| 5658 | return __e1000_resume(pdev); |
| 5659 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5660 | #endif /* CONFIG_PM_SLEEP */ |
| 5661 | |
| 5662 | #ifdef CONFIG_PM_RUNTIME |
| 5663 | static int e1000_runtime_suspend(struct device *dev) |
| 5664 | { |
| 5665 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5666 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5667 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5668 | |
| 5669 | if (e1000e_pm_ready(adapter)) { |
| 5670 | bool wake; |
| 5671 | |
| 5672 | __e1000_shutdown(pdev, &wake, true); |
| 5673 | } |
| 5674 | |
| 5675 | return 0; |
| 5676 | } |
| 5677 | |
| 5678 | static int e1000_idle(struct device *dev) |
| 5679 | { |
| 5680 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5681 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5682 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5683 | |
| 5684 | if (!e1000e_pm_ready(adapter)) |
| 5685 | return 0; |
| 5686 | |
| 5687 | if (adapter->idle_check) { |
| 5688 | adapter->idle_check = false; |
| 5689 | if (!e1000e_has_link(adapter)) |
| 5690 | pm_schedule_suspend(dev, MSEC_PER_SEC); |
| 5691 | } |
| 5692 | |
| 5693 | return -EBUSY; |
| 5694 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5695 | |
| 5696 | static int e1000_runtime_resume(struct device *dev) |
| 5697 | { |
| 5698 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5699 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5700 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5701 | |
| 5702 | if (!e1000e_pm_ready(adapter)) |
| 5703 | return 0; |
| 5704 | |
| 5705 | adapter->idle_check = !dev->power.runtime_auto; |
| 5706 | return __e1000_resume(pdev); |
| 5707 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5708 | #endif /* CONFIG_PM_RUNTIME */ |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 5709 | #endif /* CONFIG_PM */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5710 | |
| 5711 | static void e1000_shutdown(struct pci_dev *pdev) |
| 5712 | { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5713 | bool wake = false; |
| 5714 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5715 | __e1000_shutdown(pdev, &wake, false); |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5716 | |
| 5717 | if (system_state == SYSTEM_POWER_OFF) |
| 5718 | e1000_complete_shutdown(pdev, false, wake); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5719 | } |
| 5720 | |
| 5721 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5722 | |
| 5723 | static irqreturn_t e1000_intr_msix(int irq, void *data) |
| 5724 | { |
| 5725 | struct net_device *netdev = data; |
| 5726 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5727 | |
| 5728 | if (adapter->msix_entries) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 5729 | int vector, msix_irq; |
| 5730 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5731 | vector = 0; |
| 5732 | msix_irq = adapter->msix_entries[vector].vector; |
| 5733 | disable_irq(msix_irq); |
| 5734 | e1000_intr_msix_rx(msix_irq, netdev); |
| 5735 | enable_irq(msix_irq); |
| 5736 | |
| 5737 | vector++; |
| 5738 | msix_irq = adapter->msix_entries[vector].vector; |
| 5739 | disable_irq(msix_irq); |
| 5740 | e1000_intr_msix_tx(msix_irq, netdev); |
| 5741 | enable_irq(msix_irq); |
| 5742 | |
| 5743 | vector++; |
| 5744 | msix_irq = adapter->msix_entries[vector].vector; |
| 5745 | disable_irq(msix_irq); |
| 5746 | e1000_msix_other(msix_irq, netdev); |
| 5747 | enable_irq(msix_irq); |
| 5748 | } |
| 5749 | |
| 5750 | return IRQ_HANDLED; |
| 5751 | } |
| 5752 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5753 | /* |
| 5754 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5755 | * without having to re-enable interrupts. It's not called while |
| 5756 | * the interrupt routine is executing. |
| 5757 | */ |
| 5758 | static void e1000_netpoll(struct net_device *netdev) |
| 5759 | { |
| 5760 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5761 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5762 | switch (adapter->int_mode) { |
| 5763 | case E1000E_INT_MODE_MSIX: |
| 5764 | e1000_intr_msix(adapter->pdev->irq, netdev); |
| 5765 | break; |
| 5766 | case E1000E_INT_MODE_MSI: |
| 5767 | disable_irq(adapter->pdev->irq); |
| 5768 | e1000_intr_msi(adapter->pdev->irq, netdev); |
| 5769 | enable_irq(adapter->pdev->irq); |
| 5770 | break; |
| 5771 | default: /* E1000E_INT_MODE_LEGACY */ |
| 5772 | disable_irq(adapter->pdev->irq); |
| 5773 | e1000_intr(adapter->pdev->irq, netdev); |
| 5774 | enable_irq(adapter->pdev->irq); |
| 5775 | break; |
| 5776 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5777 | } |
| 5778 | #endif |
| 5779 | |
| 5780 | /** |
| 5781 | * e1000_io_error_detected - called when PCI error is detected |
| 5782 | * @pdev: Pointer to PCI device |
| 5783 | * @state: The current pci connection state |
| 5784 | * |
| 5785 | * This function is called after a PCI bus error affecting |
| 5786 | * this device has been detected. |
| 5787 | */ |
| 5788 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 5789 | pci_channel_state_t state) |
| 5790 | { |
| 5791 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5792 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5793 | |
| 5794 | netif_device_detach(netdev); |
| 5795 | |
Mike Mason | c93b5a7 | 2009-06-30 12:45:53 +0000 | [diff] [blame] | 5796 | if (state == pci_channel_io_perm_failure) |
| 5797 | return PCI_ERS_RESULT_DISCONNECT; |
| 5798 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5799 | if (netif_running(netdev)) |
| 5800 | e1000e_down(adapter); |
| 5801 | pci_disable_device(pdev); |
| 5802 | |
| 5803 | /* Request a slot slot reset. */ |
| 5804 | return PCI_ERS_RESULT_NEED_RESET; |
| 5805 | } |
| 5806 | |
| 5807 | /** |
| 5808 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 5809 | * @pdev: Pointer to PCI device |
| 5810 | * |
| 5811 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5812 | * resembles the first-half of the e1000_resume routine. |
| 5813 | */ |
| 5814 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 5815 | { |
| 5816 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5817 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5818 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5819 | u16 aspm_disable_flag = 0; |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5820 | int err; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5821 | pci_ers_result_t result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5822 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5823 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5824 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5825 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5826 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5827 | if (aspm_disable_flag) |
| 5828 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 5829 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 5830 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5831 | if (err) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5832 | dev_err(&pdev->dev, |
| 5833 | "Cannot re-enable PCI device after reset.\n"); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5834 | result = PCI_ERS_RESULT_DISCONNECT; |
| 5835 | } else { |
| 5836 | pci_set_master(pdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5837 | pdev->state_saved = true; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5838 | pci_restore_state(pdev); |
| 5839 | |
| 5840 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5841 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 5842 | |
| 5843 | e1000e_reset(adapter); |
| 5844 | ew32(WUS, ~0); |
| 5845 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5846 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5847 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5848 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5849 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5850 | return result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5851 | } |
| 5852 | |
| 5853 | /** |
| 5854 | * e1000_io_resume - called when traffic can start flowing again. |
| 5855 | * @pdev: Pointer to PCI device |
| 5856 | * |
| 5857 | * This callback is called when the error recovery driver tells us that |
| 5858 | * its OK to resume normal operation. Implementation resembles the |
| 5859 | * second-half of the e1000_resume routine. |
| 5860 | */ |
| 5861 | static void e1000_io_resume(struct pci_dev *pdev) |
| 5862 | { |
| 5863 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5864 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5865 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 5866 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5867 | |
| 5868 | if (netif_running(netdev)) { |
| 5869 | if (e1000e_up(adapter)) { |
| 5870 | dev_err(&pdev->dev, |
| 5871 | "can't bring device back up after reset\n"); |
| 5872 | return; |
| 5873 | } |
| 5874 | } |
| 5875 | |
| 5876 | netif_device_attach(netdev); |
| 5877 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5878 | /* |
| 5879 | * 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] | 5880 | * 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] | 5881 | * under the control of the driver. |
| 5882 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5883 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5884 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5885 | |
| 5886 | } |
| 5887 | |
| 5888 | static void e1000_print_device_info(struct e1000_adapter *adapter) |
| 5889 | { |
| 5890 | struct e1000_hw *hw = &adapter->hw; |
| 5891 | struct net_device *netdev = adapter->netdev; |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5892 | u32 ret_val; |
| 5893 | u8 pba_str[E1000_PBANUM_LENGTH]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5894 | |
| 5895 | /* print bus type/speed/width info */ |
Bruce Allan | a5cc764 | 2011-03-19 00:31:23 +0000 | [diff] [blame] | 5896 | e_info("(PCI Express:2.5GT/s:%s) %pM\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5897 | /* bus width */ |
| 5898 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
| 5899 | "Width x1"), |
| 5900 | /* MAC address */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5901 | netdev->dev_addr); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5902 | e_info("Intel(R) PRO/%s Network Connection\n", |
| 5903 | (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5904 | ret_val = e1000_read_pba_string_generic(hw, pba_str, |
| 5905 | E1000_PBANUM_LENGTH); |
| 5906 | if (ret_val) |
Bruce Allan | e0dc4f1 | 2011-01-06 14:29:50 +0000 | [diff] [blame] | 5907 | strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5908 | e_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 5909 | hw->mac.type, hw->phy.type, pba_str); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5910 | } |
| 5911 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5912 | static void e1000_eeprom_checks(struct e1000_adapter *adapter) |
| 5913 | { |
| 5914 | struct e1000_hw *hw = &adapter->hw; |
| 5915 | int ret_val; |
| 5916 | u16 buf = 0; |
| 5917 | |
| 5918 | if (hw->mac.type != e1000_82573) |
| 5919 | return; |
| 5920 | |
| 5921 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 5922 | if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) { |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5923 | /* Deep Smart Power Down (DSPD) */ |
Frans Pop | 6c2a9ef | 2008-09-22 14:52:22 -0700 | [diff] [blame] | 5924 | dev_warn(&adapter->pdev->dev, |
| 5925 | "Warning: detected DSPD enabled in EEPROM\n"); |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5926 | } |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5927 | } |
| 5928 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 5929 | static int e1000_set_features(struct net_device *netdev, |
| 5930 | netdev_features_t features) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 5931 | { |
| 5932 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 5933 | netdev_features_t changed = features ^ netdev->features; |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 5934 | |
| 5935 | if (changed & (NETIF_F_TSO | NETIF_F_TSO6)) |
| 5936 | adapter->flags |= FLAG_TSO_FORCE; |
| 5937 | |
| 5938 | if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX | |
| 5939 | NETIF_F_RXCSUM))) |
| 5940 | return 0; |
| 5941 | |
| 5942 | if (netif_running(netdev)) |
| 5943 | e1000e_reinit_locked(adapter); |
| 5944 | else |
| 5945 | e1000e_reset(adapter); |
| 5946 | |
| 5947 | return 0; |
| 5948 | } |
| 5949 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5950 | static const struct net_device_ops e1000e_netdev_ops = { |
| 5951 | .ndo_open = e1000_open, |
| 5952 | .ndo_stop = e1000_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5953 | .ndo_start_xmit = e1000_xmit_frame, |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5954 | .ndo_get_stats64 = e1000e_get_stats64, |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 5955 | .ndo_set_rx_mode = e1000e_set_rx_mode, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5956 | .ndo_set_mac_address = e1000_set_mac, |
| 5957 | .ndo_change_mtu = e1000_change_mtu, |
| 5958 | .ndo_do_ioctl = e1000_ioctl, |
| 5959 | .ndo_tx_timeout = e1000_tx_timeout, |
| 5960 | .ndo_validate_addr = eth_validate_addr, |
| 5961 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5962 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 5963 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 5964 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5965 | .ndo_poll_controller = e1000_netpoll, |
| 5966 | #endif |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 5967 | .ndo_set_features = e1000_set_features, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 5968 | }; |
| 5969 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5970 | /** |
| 5971 | * e1000_probe - Device Initialization Routine |
| 5972 | * @pdev: PCI device information struct |
| 5973 | * @ent: entry in e1000_pci_tbl |
| 5974 | * |
| 5975 | * Returns 0 on success, negative on failure |
| 5976 | * |
| 5977 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 5978 | * The OS initialization, configuring of the adapter private structure, |
| 5979 | * and a hardware reset occur. |
| 5980 | **/ |
| 5981 | static int __devinit e1000_probe(struct pci_dev *pdev, |
| 5982 | const struct pci_device_id *ent) |
| 5983 | { |
| 5984 | struct net_device *netdev; |
| 5985 | struct e1000_adapter *adapter; |
| 5986 | struct e1000_hw *hw; |
| 5987 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; |
Becky Bruce | f47e81f | 2008-05-01 18:03:11 -0500 | [diff] [blame] | 5988 | resource_size_t mmio_start, mmio_len; |
| 5989 | resource_size_t flash_start, flash_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5990 | |
| 5991 | static int cards_found; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5992 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5993 | int i, err, pci_using_dac; |
| 5994 | u16 eeprom_data = 0; |
| 5995 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
| 5996 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5997 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5998 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5999 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6000 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 6001 | if (aspm_disable_flag) |
| 6002 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6003 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6004 | err = pci_enable_device_mem(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6005 | if (err) |
| 6006 | return err; |
| 6007 | |
| 6008 | pci_using_dac = 0; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6009 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6010 | if (!err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6011 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6012 | if (!err) |
| 6013 | pci_using_dac = 1; |
| 6014 | } else { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6015 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6016 | if (err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6017 | err = dma_set_coherent_mask(&pdev->dev, |
| 6018 | DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6019 | if (err) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 6020 | dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6021 | goto err_dma; |
| 6022 | } |
| 6023 | } |
| 6024 | } |
| 6025 | |
Arjan van de Ven | e8de148 | 2008-10-22 19:55:31 -0700 | [diff] [blame] | 6026 | err = pci_request_selected_regions_exclusive(pdev, |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6027 | pci_select_bars(pdev, IORESOURCE_MEM), |
| 6028 | e1000e_driver_name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6029 | if (err) |
| 6030 | goto err_pci_reg; |
| 6031 | |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 6032 | /* AER (Advanced Error Reporting) hooks */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6033 | pci_enable_pcie_error_reporting(pdev); |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 6034 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6035 | pci_set_master(pdev); |
Bruce Allan | 438b365 | 2008-11-21 16:51:33 -0800 | [diff] [blame] | 6036 | /* PCI config space info */ |
| 6037 | err = pci_save_state(pdev); |
| 6038 | if (err) |
| 6039 | goto err_alloc_etherdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6040 | |
| 6041 | err = -ENOMEM; |
| 6042 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
| 6043 | if (!netdev) |
| 6044 | goto err_alloc_etherdev; |
| 6045 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6046 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 6047 | |
Tom Herbert | f85e4df | 2010-05-05 14:03:32 +0000 | [diff] [blame] | 6048 | netdev->irq = pdev->irq; |
| 6049 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6050 | pci_set_drvdata(pdev, netdev); |
| 6051 | adapter = netdev_priv(netdev); |
| 6052 | hw = &adapter->hw; |
| 6053 | adapter->netdev = netdev; |
| 6054 | adapter->pdev = pdev; |
| 6055 | adapter->ei = ei; |
| 6056 | adapter->pba = ei->pba; |
| 6057 | adapter->flags = ei->flags; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 6058 | adapter->flags2 = ei->flags2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6059 | adapter->hw.adapter = adapter; |
| 6060 | adapter->hw.mac.type = ei->mac; |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 6061 | adapter->max_hw_frame_size = ei->max_hw_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6062 | adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; |
| 6063 | |
| 6064 | mmio_start = pci_resource_start(pdev, 0); |
| 6065 | mmio_len = pci_resource_len(pdev, 0); |
| 6066 | |
| 6067 | err = -EIO; |
| 6068 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 6069 | if (!adapter->hw.hw_addr) |
| 6070 | goto err_ioremap; |
| 6071 | |
| 6072 | if ((adapter->flags & FLAG_HAS_FLASH) && |
| 6073 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
| 6074 | flash_start = pci_resource_start(pdev, 1); |
| 6075 | flash_len = pci_resource_len(pdev, 1); |
| 6076 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
| 6077 | if (!adapter->hw.flash_address) |
| 6078 | goto err_flashmap; |
| 6079 | } |
| 6080 | |
| 6081 | /* construct the net_device struct */ |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6082 | netdev->netdev_ops = &e1000e_netdev_ops; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6083 | e1000e_set_ethtool_ops(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6084 | netdev->watchdog_timeo = 5 * HZ; |
| 6085 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6086 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
| 6087 | |
| 6088 | netdev->mem_start = mmio_start; |
| 6089 | netdev->mem_end = mmio_start + mmio_len; |
| 6090 | |
| 6091 | adapter->bd_number = cards_found++; |
| 6092 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6093 | e1000e_check_options(adapter); |
| 6094 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6095 | /* setup adapter struct */ |
| 6096 | err = e1000_sw_init(adapter); |
| 6097 | if (err) |
| 6098 | goto err_sw_init; |
| 6099 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6100 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 6101 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 6102 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 6103 | |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 6104 | err = ei->get_variants(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6105 | if (err) |
| 6106 | goto err_hw_init; |
| 6107 | |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 6108 | if ((adapter->flags & FLAG_IS_ICH) && |
| 6109 | (adapter->flags & FLAG_READ_ONLY_NVM)) |
| 6110 | e1000e_write_protect_nvm_ich8lan(&adapter->hw); |
| 6111 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6112 | hw->mac.ops.get_bus_info(&adapter->hw); |
| 6113 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6114 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6115 | |
| 6116 | /* Copper options */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6117 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6118 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
| 6119 | adapter->hw.phy.disable_polarity_correction = 0; |
| 6120 | adapter->hw.phy.ms_type = e1000_ms_hw_default; |
| 6121 | } |
| 6122 | |
| 6123 | if (e1000_check_reset_block(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6124 | e_info("PHY reset is blocked due to SOL/IDER session.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6125 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6126 | /* Set initial default active device features */ |
| 6127 | netdev->features = (NETIF_F_SG | |
| 6128 | NETIF_F_HW_VLAN_RX | |
| 6129 | NETIF_F_HW_VLAN_TX | |
| 6130 | NETIF_F_TSO | |
| 6131 | NETIF_F_TSO6 | |
| 6132 | NETIF_F_RXCSUM | |
| 6133 | NETIF_F_HW_CSUM); |
| 6134 | |
| 6135 | /* Set user-changeable features (subset of all device features) */ |
| 6136 | netdev->hw_features = netdev->features; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6137 | |
| 6138 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
| 6139 | netdev->features |= NETIF_F_HW_VLAN_FILTER; |
| 6140 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6141 | netdev->vlan_features |= (NETIF_F_SG | |
| 6142 | NETIF_F_TSO | |
| 6143 | NETIF_F_TSO6 | |
| 6144 | NETIF_F_HW_CSUM); |
Jeff Kirsher | a5136e2 | 2008-06-05 04:07:28 -0700 | [diff] [blame] | 6145 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 6146 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 6147 | |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 6148 | if (pci_using_dac) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6149 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 6150 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 6151 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6152 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6153 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
| 6154 | adapter->flags |= FLAG_MNG_PT_ENABLED; |
| 6155 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6156 | /* |
| 6157 | * before reading the NVM, reset the controller to |
| 6158 | * put the device in a known good starting state |
| 6159 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6160 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 6161 | |
| 6162 | /* |
| 6163 | * systems with ASPM and others may see the checksum fail on the first |
| 6164 | * attempt. Let's give it a few tries |
| 6165 | */ |
| 6166 | for (i = 0;; i++) { |
| 6167 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) |
| 6168 | break; |
| 6169 | if (i == 2) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6170 | e_err("The NVM Checksum Is Not Valid\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6171 | err = -EIO; |
| 6172 | goto err_eeprom; |
| 6173 | } |
| 6174 | } |
| 6175 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6176 | e1000_eeprom_checks(adapter); |
| 6177 | |
Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 6178 | /* copy the MAC address */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6179 | if (e1000e_read_mac_addr(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6180 | e_err("NVM Read Error while reading MAC address\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6181 | |
| 6182 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 6183 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 6184 | |
| 6185 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 6186 | e_err("Invalid MAC Address: %pM\n", netdev->perm_addr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6187 | err = -EIO; |
| 6188 | goto err_eeprom; |
| 6189 | } |
| 6190 | |
| 6191 | init_timer(&adapter->watchdog_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6192 | adapter->watchdog_timer.function = e1000_watchdog; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6193 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 6194 | |
| 6195 | init_timer(&adapter->phy_info_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6196 | adapter->phy_info_timer.function = e1000_update_phy_info; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6197 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 6198 | |
| 6199 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
| 6200 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 6201 | INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); |
| 6202 | INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6203 | INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6204 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6205 | /* Initialize link parameters. User can change them with ethtool */ |
| 6206 | adapter->hw.mac.autoneg = 1; |
Auke Kok | 309af40 | 2007-10-05 15:22:02 -0700 | [diff] [blame] | 6207 | adapter->fc_autoneg = 1; |
Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 6208 | adapter->hw.fc.requested_mode = e1000_fc_default; |
| 6209 | adapter->hw.fc.current_mode = e1000_fc_default; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6210 | adapter->hw.phy.autoneg_advertised = 0x2f; |
| 6211 | |
| 6212 | /* ring size defaults */ |
| 6213 | adapter->rx_ring->count = 256; |
| 6214 | adapter->tx_ring->count = 256; |
| 6215 | |
| 6216 | /* |
| 6217 | * Initial Wake on LAN setting - If APM wake is enabled in |
| 6218 | * the EEPROM, enable the ACPI Magic Packet filter |
| 6219 | */ |
| 6220 | if (adapter->flags & FLAG_APME_IN_WUC) { |
| 6221 | /* APME bit in EEPROM is mapped to WUC.APME */ |
| 6222 | eeprom_data = er32(WUC); |
| 6223 | eeprom_apme_mask = E1000_WUC_APME; |
Bruce Allan | 4def99b | 2011-02-02 09:30:36 +0000 | [diff] [blame] | 6224 | if ((hw->mac.type > e1000_ich10lan) && |
| 6225 | (eeprom_data & E1000_WUC_PHY_WAKE)) |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6226 | adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6227 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
| 6228 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && |
| 6229 | (adapter->hw.bus.func == 1)) |
| 6230 | e1000_read_nvm(&adapter->hw, |
| 6231 | NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 6232 | else |
| 6233 | e1000_read_nvm(&adapter->hw, |
| 6234 | NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 6235 | } |
| 6236 | |
| 6237 | /* fetch WoL from EEPROM */ |
| 6238 | if (eeprom_data & eeprom_apme_mask) |
| 6239 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 6240 | |
| 6241 | /* |
| 6242 | * now that we have the eeprom settings, apply the special cases |
| 6243 | * where the eeprom may be wrong or the board simply won't support |
| 6244 | * wake on lan on a particular port |
| 6245 | */ |
| 6246 | if (!(adapter->flags & FLAG_HAS_WOL)) |
| 6247 | adapter->eeprom_wol = 0; |
| 6248 | |
| 6249 | /* initialize the wol settings based on the eeprom settings */ |
| 6250 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | 6ff6802 | 2008-11-12 09:52:32 +0000 | [diff] [blame] | 6251 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6252 | |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 6253 | /* save off EEPROM version number */ |
| 6254 | e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); |
| 6255 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6256 | /* reset the hardware with the new settings */ |
| 6257 | e1000e_reset(adapter); |
| 6258 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6259 | /* |
| 6260 | * 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] | 6261 | * 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] | 6262 | * under the control of the driver. |
| 6263 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6264 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6265 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6266 | |
Bruce Allan | e0dc4f1 | 2011-01-06 14:29:50 +0000 | [diff] [blame] | 6267 | strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6268 | err = register_netdev(netdev); |
| 6269 | if (err) |
| 6270 | goto err_register; |
| 6271 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 6272 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 6273 | netif_carrier_off(netdev); |
| 6274 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6275 | e1000_print_device_info(adapter); |
| 6276 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6277 | if (pci_dev_run_wake(pdev)) |
| 6278 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6279 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6280 | return 0; |
| 6281 | |
| 6282 | err_register: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6283 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6284 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6285 | err_eeprom: |
| 6286 | if (!e1000_check_reset_block(&adapter->hw)) |
| 6287 | e1000_phy_hw_reset(&adapter->hw); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6288 | err_hw_init: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6289 | kfree(adapter->tx_ring); |
| 6290 | kfree(adapter->rx_ring); |
| 6291 | err_sw_init: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6292 | if (adapter->hw.flash_address) |
| 6293 | iounmap(adapter->hw.flash_address); |
Jeff Kirsher | e82f54b | 2008-11-14 06:45:07 +0000 | [diff] [blame] | 6294 | e1000e_reset_interrupt_capability(adapter); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6295 | err_flashmap: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6296 | iounmap(adapter->hw.hw_addr); |
| 6297 | err_ioremap: |
| 6298 | free_netdev(netdev); |
| 6299 | err_alloc_etherdev: |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6300 | pci_release_selected_regions(pdev, |
| 6301 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6302 | err_pci_reg: |
| 6303 | err_dma: |
| 6304 | pci_disable_device(pdev); |
| 6305 | return err; |
| 6306 | } |
| 6307 | |
| 6308 | /** |
| 6309 | * e1000_remove - Device Removal Routine |
| 6310 | * @pdev: PCI device information struct |
| 6311 | * |
| 6312 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 6313 | * that it should release a PCI device. The could be caused by a |
| 6314 | * Hot-Plug event, or because the driver is going to be removed from |
| 6315 | * memory. |
| 6316 | **/ |
| 6317 | static void __devexit e1000_remove(struct pci_dev *pdev) |
| 6318 | { |
| 6319 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6320 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6321 | bool down = test_bit(__E1000_DOWN, &adapter->state); |
| 6322 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6323 | /* |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 6324 | * The timers may be rescheduled, so explicitly disable them |
| 6325 | * from being rescheduled. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6326 | */ |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6327 | if (!down) |
| 6328 | set_bit(__E1000_DOWN, &adapter->state); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6329 | del_timer_sync(&adapter->watchdog_timer); |
| 6330 | del_timer_sync(&adapter->phy_info_timer); |
| 6331 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6332 | cancel_work_sync(&adapter->reset_task); |
| 6333 | cancel_work_sync(&adapter->watchdog_task); |
| 6334 | cancel_work_sync(&adapter->downshift_task); |
| 6335 | cancel_work_sync(&adapter->update_phy_task); |
| 6336 | cancel_work_sync(&adapter->print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6337 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6338 | if (!(netdev->flags & IFF_UP)) |
| 6339 | e1000_power_down_phy(adapter); |
| 6340 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6341 | /* Don't lie to e1000_close() down the road. */ |
| 6342 | if (!down) |
| 6343 | clear_bit(__E1000_DOWN, &adapter->state); |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6344 | unregister_netdev(netdev); |
| 6345 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6346 | if (pci_dev_run_wake(pdev)) |
| 6347 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6348 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6349 | /* |
| 6350 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 6351 | * would have already happened in close and is redundant. |
| 6352 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6353 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6354 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6355 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6356 | kfree(adapter->tx_ring); |
| 6357 | kfree(adapter->rx_ring); |
| 6358 | |
| 6359 | iounmap(adapter->hw.hw_addr); |
| 6360 | if (adapter->hw.flash_address) |
| 6361 | iounmap(adapter->hw.flash_address); |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6362 | pci_release_selected_regions(pdev, |
| 6363 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6364 | |
| 6365 | free_netdev(netdev); |
| 6366 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6367 | /* AER disable */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6368 | pci_disable_pcie_error_reporting(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6369 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6370 | pci_disable_device(pdev); |
| 6371 | } |
| 6372 | |
| 6373 | /* PCI Error Recovery (ERS) */ |
| 6374 | static struct pci_error_handlers e1000_err_handler = { |
| 6375 | .error_detected = e1000_io_error_detected, |
| 6376 | .slot_reset = e1000_io_slot_reset, |
| 6377 | .resume = e1000_io_resume, |
| 6378 | }; |
| 6379 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 6380 | static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6381 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
| 6382 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, |
| 6383 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, |
| 6384 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 }, |
| 6385 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
| 6386 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, |
Auke Kok | 040babf | 2007-10-31 15:22:05 -0700 | [diff] [blame] | 6387 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
| 6388 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, |
| 6389 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6390 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6391 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
| 6392 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, |
| 6393 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, |
| 6394 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6395 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6396 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
| 6397 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, |
| 6398 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6399 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6400 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, |
Bruce Allan | bef28b1 | 2009-03-24 23:28:02 -0700 | [diff] [blame] | 6401 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 6402 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6403 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6404 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
| 6405 | board_80003es2lan }, |
| 6406 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), |
| 6407 | board_80003es2lan }, |
| 6408 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), |
| 6409 | board_80003es2lan }, |
| 6410 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), |
| 6411 | board_80003es2lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6412 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6413 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
| 6414 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, |
| 6415 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, |
| 6416 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, |
| 6417 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, |
| 6418 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, |
| 6419 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, |
Bruce Allan | 9e135a2 | 2009-12-01 15:50:31 +0000 | [diff] [blame] | 6420 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6421 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6422 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
| 6423 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, |
| 6424 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, |
| 6425 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, |
| 6426 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, |
Bruce Allan | 2f15f9d | 2008-08-26 18:36:36 -0700 | [diff] [blame] | 6427 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6428 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, |
| 6429 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, |
| 6430 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, |
| 6431 | |
| 6432 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, |
| 6433 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, |
| 6434 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6435 | |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6436 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, |
| 6437 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, |
Bruce Allan | 10df0b9 | 2010-05-10 15:02:52 +0000 | [diff] [blame] | 6438 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan }, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6439 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6440 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, |
| 6441 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, |
| 6442 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, |
| 6443 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, |
| 6444 | |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 6445 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan }, |
| 6446 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan }, |
| 6447 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6448 | { } /* terminate list */ |
| 6449 | }; |
| 6450 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 6451 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6452 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6453 | static const struct dev_pm_ops e1000_pm_ops = { |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6454 | SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume) |
| 6455 | SET_RUNTIME_PM_OPS(e1000_runtime_suspend, |
| 6456 | e1000_runtime_resume, e1000_idle) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6457 | }; |
David S. Miller | e50208a | 2010-03-16 23:36:24 -0700 | [diff] [blame] | 6458 | #endif |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6459 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6460 | /* PCI Device API Driver */ |
| 6461 | static struct pci_driver e1000_driver = { |
| 6462 | .name = e1000e_driver_name, |
| 6463 | .id_table = e1000_pci_tbl, |
| 6464 | .probe = e1000_probe, |
| 6465 | .remove = __devexit_p(e1000_remove), |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6466 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6467 | .driver.pm = &e1000_pm_ops, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6468 | #endif |
| 6469 | .shutdown = e1000_shutdown, |
| 6470 | .err_handler = &e1000_err_handler |
| 6471 | }; |
| 6472 | |
| 6473 | /** |
| 6474 | * e1000_init_module - Driver Registration Routine |
| 6475 | * |
| 6476 | * e1000_init_module is the first routine called when the driver is |
| 6477 | * loaded. All it does is register with the PCI subsystem. |
| 6478 | **/ |
| 6479 | static int __init e1000_init_module(void) |
| 6480 | { |
| 6481 | int ret; |
Bruce Allan | 8544b9f | 2010-03-24 12:55:30 +0000 | [diff] [blame] | 6482 | pr_info("Intel(R) PRO/1000 Network Driver - %s\n", |
| 6483 | e1000e_driver_version); |
Bruce Allan | 0d6057e | 2011-01-04 01:16:44 +0000 | [diff] [blame] | 6484 | pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6485 | ret = pci_register_driver(&e1000_driver); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 6486 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6487 | return ret; |
| 6488 | } |
| 6489 | module_init(e1000_init_module); |
| 6490 | |
| 6491 | /** |
| 6492 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 6493 | * |
| 6494 | * e1000_exit_module is called just before the driver is removed |
| 6495 | * from memory. |
| 6496 | **/ |
| 6497 | static void __exit e1000_exit_module(void) |
| 6498 | { |
| 6499 | pci_unregister_driver(&e1000_driver); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6500 | } |
| 6501 | module_exit(e1000_exit_module); |
| 6502 | |
| 6503 | |
| 6504 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 6505 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 6506 | MODULE_LICENSE("GPL"); |
| 6507 | MODULE_VERSION(DRV_VERSION); |
| 6508 | |
| 6509 | /* e1000_main.c */ |