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