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 |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [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 |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 494 | **/ |
| 495 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 496 | __le16 csum, struct sk_buff *skb) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 | |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 503 | /* Rx checksum disabled */ |
| 504 | if (!(adapter->netdev->features & NETIF_F_RXCSUM)) |
| 505 | return; |
| 506 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 507 | /* Ignore Checksum bit is set */ |
| 508 | if (status & E1000_RXD_STAT_IXSM) |
| 509 | return; |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 510 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 511 | /* TCP/UDP checksum error bit is set */ |
| 512 | if (errors & E1000_RXD_ERR_TCPE) { |
| 513 | /* let the stack verify checksum errors */ |
| 514 | adapter->hw_csum_err++; |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | /* TCP/UDP Checksum has not been calculated */ |
| 519 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
| 520 | return; |
| 521 | |
| 522 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 523 | if (status & E1000_RXD_STAT_TCPCS) { |
| 524 | /* TCP checksum is good */ |
| 525 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 526 | } else { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 527 | /* |
| 528 | * IP fragment with UDP payload |
| 529 | * Hardware complements the payload checksum, so we undo it |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 530 | * and then put the value in host order for further stack use. |
| 531 | */ |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 532 | __sum16 sum = (__force __sum16)swab16((__force u16)csum); |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 533 | skb->csum = csum_unfold(~sum); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 534 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 535 | } |
| 536 | adapter->hw_csum_good++; |
| 537 | } |
| 538 | |
| 539 | /** |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 540 | * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa() |
| 541 | * @hw: pointer to the HW structure |
| 542 | * @tail: address of tail descriptor register |
| 543 | * @i: value to write to tail descriptor register |
| 544 | * |
| 545 | * When updating the tail register, the ME could be accessing Host CSR |
| 546 | * registers at the same time. Normally, this is handled in h/w by an |
| 547 | * arbiter but on some parts there is a bug that acknowledges Host accesses |
| 548 | * later than it should which could result in the descriptor register to |
| 549 | * have an incorrect value. Workaround this by checking the FWSM register |
| 550 | * which has bit 24 set while ME is accessing Host CSR registers, wait |
| 551 | * if it is set and try again a number of times. |
| 552 | **/ |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 553 | static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, void __iomem *tail, |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 554 | unsigned int i) |
| 555 | { |
| 556 | unsigned int j = 0; |
| 557 | |
| 558 | while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) && |
| 559 | (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI)) |
| 560 | udelay(50); |
| 561 | |
| 562 | writel(i, tail); |
| 563 | |
| 564 | if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail))) |
| 565 | return E1000_ERR_SWFW_SYNC; |
| 566 | |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | static void e1000e_update_rdt_wa(struct e1000_adapter *adapter, unsigned int i) |
| 571 | { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 572 | struct e1000_hw *hw = &adapter->hw; |
| 573 | |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 574 | if (e1000e_update_tail_wa(hw, adapter->rx_ring->tail, i)) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 575 | u32 rctl = er32(RCTL); |
| 576 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 577 | e_err("ME firmware caused invalid RDT - resetting\n"); |
| 578 | schedule_work(&adapter->reset_task); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | static void e1000e_update_tdt_wa(struct e1000_adapter *adapter, unsigned int i) |
| 583 | { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 584 | struct e1000_hw *hw = &adapter->hw; |
| 585 | |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 586 | if (e1000e_update_tail_wa(hw, adapter->tx_ring->tail, i)) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 587 | u32 tctl = er32(TCTL); |
| 588 | ew32(TCTL, tctl & ~E1000_TCTL_EN); |
| 589 | e_err("ME firmware caused invalid TDT - resetting\n"); |
| 590 | schedule_work(&adapter->reset_task); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | /** |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 595 | * e1000_alloc_rx_buffers - Replace used receive buffers |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 596 | * @adapter: address of board private structure |
| 597 | **/ |
| 598 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 599 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 600 | { |
| 601 | struct net_device *netdev = adapter->netdev; |
| 602 | struct pci_dev *pdev = adapter->pdev; |
| 603 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 604 | union e1000_rx_desc_extended *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 605 | struct e1000_buffer *buffer_info; |
| 606 | struct sk_buff *skb; |
| 607 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 608 | unsigned int bufsz = adapter->rx_buffer_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 609 | |
| 610 | i = rx_ring->next_to_use; |
| 611 | buffer_info = &rx_ring->buffer_info[i]; |
| 612 | |
| 613 | while (cleaned_count--) { |
| 614 | skb = buffer_info->skb; |
| 615 | if (skb) { |
| 616 | skb_trim(skb, 0); |
| 617 | goto map_skb; |
| 618 | } |
| 619 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 620 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 621 | if (!skb) { |
| 622 | /* Better luck next round */ |
| 623 | adapter->alloc_rx_buff_failed++; |
| 624 | break; |
| 625 | } |
| 626 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 627 | buffer_info->skb = skb; |
| 628 | map_skb: |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 629 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 630 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 631 | DMA_FROM_DEVICE); |
| 632 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 633 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 634 | adapter->rx_dma_failed++; |
| 635 | break; |
| 636 | } |
| 637 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 638 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 639 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 640 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 641 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
| 642 | /* |
| 643 | * Force memory writes to complete before letting h/w |
| 644 | * know there are new descriptors to fetch. (Only |
| 645 | * applicable for weak-ordered memory model archs, |
| 646 | * such as IA-64). |
| 647 | */ |
| 648 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 649 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 650 | e1000e_update_rdt_wa(adapter, i); |
| 651 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 652 | writel(i, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 653 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 654 | i++; |
| 655 | if (i == rx_ring->count) |
| 656 | i = 0; |
| 657 | buffer_info = &rx_ring->buffer_info[i]; |
| 658 | } |
| 659 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 660 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /** |
| 664 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
| 665 | * @adapter: address of board private structure |
| 666 | **/ |
| 667 | static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 668 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 669 | { |
| 670 | struct net_device *netdev = adapter->netdev; |
| 671 | struct pci_dev *pdev = adapter->pdev; |
| 672 | union e1000_rx_desc_packet_split *rx_desc; |
| 673 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 674 | struct e1000_buffer *buffer_info; |
| 675 | struct e1000_ps_page *ps_page; |
| 676 | struct sk_buff *skb; |
| 677 | unsigned int i, j; |
| 678 | |
| 679 | i = rx_ring->next_to_use; |
| 680 | buffer_info = &rx_ring->buffer_info[i]; |
| 681 | |
| 682 | while (cleaned_count--) { |
| 683 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 684 | |
| 685 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 686 | ps_page = &buffer_info->ps_pages[j]; |
| 687 | if (j >= adapter->rx_ps_pages) { |
| 688 | /* all unused desc entries get hw null ptr */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 689 | rx_desc->read.buffer_addr[j + 1] = |
| 690 | ~cpu_to_le64(0); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 691 | continue; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 692 | } |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 693 | if (!ps_page->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 694 | ps_page->page = alloc_page(gfp); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 695 | if (!ps_page->page) { |
| 696 | adapter->alloc_rx_buff_failed++; |
| 697 | goto no_buffers; |
| 698 | } |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 699 | ps_page->dma = dma_map_page(&pdev->dev, |
| 700 | ps_page->page, |
| 701 | 0, PAGE_SIZE, |
| 702 | DMA_FROM_DEVICE); |
| 703 | if (dma_mapping_error(&pdev->dev, |
| 704 | ps_page->dma)) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 705 | dev_err(&adapter->pdev->dev, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 706 | "Rx DMA page map failed\n"); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 707 | adapter->rx_dma_failed++; |
| 708 | goto no_buffers; |
| 709 | } |
| 710 | } |
| 711 | /* |
| 712 | * Refresh the desc even if buffer_addrs |
| 713 | * didn't change because each write-back |
| 714 | * erases this info. |
| 715 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 716 | rx_desc->read.buffer_addr[j + 1] = |
| 717 | cpu_to_le64(ps_page->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 720 | skb = __netdev_alloc_skb_ip_align(netdev, |
| 721 | adapter->rx_ps_bsize0, |
| 722 | gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 723 | |
| 724 | if (!skb) { |
| 725 | adapter->alloc_rx_buff_failed++; |
| 726 | break; |
| 727 | } |
| 728 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 729 | buffer_info->skb = skb; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 730 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 731 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 732 | DMA_FROM_DEVICE); |
| 733 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 734 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 735 | adapter->rx_dma_failed++; |
| 736 | /* cleanup skb */ |
| 737 | dev_kfree_skb_any(skb); |
| 738 | buffer_info->skb = NULL; |
| 739 | break; |
| 740 | } |
| 741 | |
| 742 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 743 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 744 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
| 745 | /* |
| 746 | * Force memory writes to complete before letting h/w |
| 747 | * know there are new descriptors to fetch. (Only |
| 748 | * applicable for weak-ordered memory model archs, |
| 749 | * such as IA-64). |
| 750 | */ |
| 751 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 752 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 753 | e1000e_update_rdt_wa(adapter, i << 1); |
| 754 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 755 | writel(i << 1, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 758 | i++; |
| 759 | if (i == rx_ring->count) |
| 760 | i = 0; |
| 761 | buffer_info = &rx_ring->buffer_info[i]; |
| 762 | } |
| 763 | |
| 764 | no_buffers: |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 765 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 769 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
| 770 | * @adapter: address of board private structure |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 771 | * @cleaned_count: number of buffers to allocate this pass |
| 772 | **/ |
| 773 | |
| 774 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 775 | int cleaned_count, gfp_t gfp) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 776 | { |
| 777 | struct net_device *netdev = adapter->netdev; |
| 778 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 779 | union e1000_rx_desc_extended *rx_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 780 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 781 | struct e1000_buffer *buffer_info; |
| 782 | struct sk_buff *skb; |
| 783 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 784 | unsigned int bufsz = 256 - 16 /* for skb_reserve */; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 785 | |
| 786 | i = rx_ring->next_to_use; |
| 787 | buffer_info = &rx_ring->buffer_info[i]; |
| 788 | |
| 789 | while (cleaned_count--) { |
| 790 | skb = buffer_info->skb; |
| 791 | if (skb) { |
| 792 | skb_trim(skb, 0); |
| 793 | goto check_page; |
| 794 | } |
| 795 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 796 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 797 | if (unlikely(!skb)) { |
| 798 | /* Better luck next round */ |
| 799 | adapter->alloc_rx_buff_failed++; |
| 800 | break; |
| 801 | } |
| 802 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 803 | buffer_info->skb = skb; |
| 804 | check_page: |
| 805 | /* allocate a new page if necessary */ |
| 806 | if (!buffer_info->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 807 | buffer_info->page = alloc_page(gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 808 | if (unlikely(!buffer_info->page)) { |
| 809 | adapter->alloc_rx_buff_failed++; |
| 810 | break; |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | if (!buffer_info->dma) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 815 | buffer_info->dma = dma_map_page(&pdev->dev, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 816 | buffer_info->page, 0, |
| 817 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 818 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 819 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 820 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 821 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 822 | |
| 823 | if (unlikely(++i == rx_ring->count)) |
| 824 | i = 0; |
| 825 | buffer_info = &rx_ring->buffer_info[i]; |
| 826 | } |
| 827 | |
| 828 | if (likely(rx_ring->next_to_use != i)) { |
| 829 | rx_ring->next_to_use = i; |
| 830 | if (unlikely(i-- == 0)) |
| 831 | i = (rx_ring->count - 1); |
| 832 | |
| 833 | /* Force memory writes to complete before letting h/w |
| 834 | * know there are new descriptors to fetch. (Only |
| 835 | * applicable for weak-ordered memory model archs, |
| 836 | * such as IA-64). */ |
| 837 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 838 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 839 | e1000e_update_rdt_wa(adapter, i); |
| 840 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 841 | writel(i, rx_ring->tail); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 842 | } |
| 843 | } |
| 844 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 845 | static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss, |
| 846 | struct sk_buff *skb) |
| 847 | { |
| 848 | if (netdev->features & NETIF_F_RXHASH) |
| 849 | skb->rxhash = le32_to_cpu(rss); |
| 850 | } |
| 851 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 852 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 853 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
| 854 | * @adapter: board private structure |
| 855 | * |
| 856 | * the return value indicates whether actual cleaning was done, there |
| 857 | * is no guarantee that everything was cleaned |
| 858 | **/ |
| 859 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 860 | int *work_done, int work_to_do) |
| 861 | { |
| 862 | struct net_device *netdev = adapter->netdev; |
| 863 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 864 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 865 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 866 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 867 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 868 | u32 length, staterr; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 869 | unsigned int i; |
| 870 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 871 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 872 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 873 | |
| 874 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 875 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 876 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 877 | buffer_info = &rx_ring->buffer_info[i]; |
| 878 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 879 | while (staterr & E1000_RXD_STAT_DD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 880 | struct sk_buff *skb; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 881 | |
| 882 | if (*work_done >= work_to_do) |
| 883 | break; |
| 884 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 885 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 886 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 887 | skb = buffer_info->skb; |
| 888 | buffer_info->skb = NULL; |
| 889 | |
| 890 | prefetch(skb->data - NET_IP_ALIGN); |
| 891 | |
| 892 | i++; |
| 893 | if (i == rx_ring->count) |
| 894 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 895 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 896 | prefetch(next_rxd); |
| 897 | |
| 898 | next_buffer = &rx_ring->buffer_info[i]; |
| 899 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 900 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 901 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 902 | dma_unmap_single(&pdev->dev, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 903 | buffer_info->dma, |
| 904 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 905 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 906 | buffer_info->dma = 0; |
| 907 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 908 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 909 | |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 910 | /* |
| 911 | * !EOP means multiple descriptors were used to store a single |
| 912 | * packet, if that's the case we need to toss it. In fact, we |
| 913 | * need to toss every packet with the EOP bit clear and the |
| 914 | * next frame that _does_ have the EOP bit set, as it is by |
| 915 | * definition only a frame fragment |
| 916 | */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 917 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 918 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 919 | |
| 920 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 921 | /* All receives must fit into a single buffer */ |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 922 | e_dbg("Receive packet consumed multiple buffers\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 923 | /* recycle */ |
| 924 | buffer_info->skb = skb; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 925 | if (staterr & E1000_RXD_STAT_EOP) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 926 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 927 | goto next_desc; |
| 928 | } |
| 929 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 930 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 931 | /* recycle */ |
| 932 | buffer_info->skb = skb; |
| 933 | goto next_desc; |
| 934 | } |
| 935 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 936 | /* adjust length to remove Ethernet CRC */ |
| 937 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 938 | length -= 4; |
| 939 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 940 | total_rx_bytes += length; |
| 941 | total_rx_packets++; |
| 942 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 943 | /* |
| 944 | * code added for copybreak, this should improve |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 945 | * performance for small packets with large amounts |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 946 | * of reassembly being done in the stack |
| 947 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 948 | if (length < copybreak) { |
| 949 | struct sk_buff *new_skb = |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 950 | netdev_alloc_skb_ip_align(netdev, length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 951 | if (new_skb) { |
Bruce Allan | 808ff67 | 2008-08-08 18:35:56 -0700 | [diff] [blame] | 952 | skb_copy_to_linear_data_offset(new_skb, |
| 953 | -NET_IP_ALIGN, |
| 954 | (skb->data - |
| 955 | NET_IP_ALIGN), |
| 956 | (length + |
| 957 | NET_IP_ALIGN)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 958 | /* save the skb in buffer_info as good */ |
| 959 | buffer_info->skb = skb; |
| 960 | skb = new_skb; |
| 961 | } |
| 962 | /* else just continue with the old one */ |
| 963 | } |
| 964 | /* end copybreak code */ |
| 965 | skb_put(skb, length); |
| 966 | |
| 967 | /* Receive Checksum Offload */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 968 | e1000_rx_checksum(adapter, staterr, |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 969 | rx_desc->wb.lower.hi_dword.csum_ip.csum, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 970 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 971 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 972 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 973 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 974 | rx_desc->wb.upper.vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 975 | |
| 976 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 977 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 978 | |
| 979 | /* return some buffers to hardware, one at a time is too slow */ |
| 980 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 981 | adapter->alloc_rx_buf(adapter, cleaned_count, |
| 982 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 983 | cleaned_count = 0; |
| 984 | } |
| 985 | |
| 986 | /* use prefetched values */ |
| 987 | rx_desc = next_rxd; |
| 988 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 989 | |
| 990 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 991 | } |
| 992 | rx_ring->next_to_clean = i; |
| 993 | |
| 994 | cleaned_count = e1000_desc_unused(rx_ring); |
| 995 | if (cleaned_count) |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 996 | adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 997 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 998 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 999 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1000 | return cleaned; |
| 1001 | } |
| 1002 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1003 | static void e1000_put_txbuf(struct e1000_adapter *adapter, |
| 1004 | struct e1000_buffer *buffer_info) |
| 1005 | { |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1006 | if (buffer_info->dma) { |
| 1007 | if (buffer_info->mapped_as_page) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1008 | dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, |
| 1009 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1010 | else |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1011 | dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, |
| 1012 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1013 | buffer_info->dma = 0; |
| 1014 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1015 | if (buffer_info->skb) { |
| 1016 | dev_kfree_skb_any(buffer_info->skb); |
| 1017 | buffer_info->skb = NULL; |
| 1018 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 1019 | buffer_info->time_stamp = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1022 | static void e1000_print_hw_hang(struct work_struct *work) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1023 | { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1024 | struct e1000_adapter *adapter = container_of(work, |
| 1025 | struct e1000_adapter, |
| 1026 | print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1027 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1028 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1029 | unsigned int i = tx_ring->next_to_clean; |
| 1030 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; |
| 1031 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1032 | struct e1000_hw *hw = &adapter->hw; |
| 1033 | u16 phy_status, phy_1000t_status, phy_ext_status; |
| 1034 | u16 pci_status; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1035 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1036 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1037 | return; |
| 1038 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1039 | if (!adapter->tx_hang_recheck && |
| 1040 | (adapter->flags2 & FLAG2_DMA_BURST)) { |
| 1041 | /* May be block on write-back, flush and detect again |
| 1042 | * flush pending descriptor writebacks to memory |
| 1043 | */ |
| 1044 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 1045 | /* execute the writes immediately */ |
| 1046 | e1e_flush(); |
| 1047 | adapter->tx_hang_recheck = true; |
| 1048 | return; |
| 1049 | } |
| 1050 | /* Real hang detected */ |
| 1051 | adapter->tx_hang_recheck = false; |
| 1052 | netif_stop_queue(netdev); |
| 1053 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1054 | e1e_rphy(hw, PHY_STATUS, &phy_status); |
| 1055 | e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status); |
| 1056 | e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status); |
| 1057 | |
| 1058 | pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status); |
| 1059 | |
| 1060 | /* detected Hardware unit hang */ |
| 1061 | e_err("Detected Hardware Unit Hang:\n" |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1062 | " TDH <%x>\n" |
| 1063 | " TDT <%x>\n" |
| 1064 | " next_to_use <%x>\n" |
| 1065 | " next_to_clean <%x>\n" |
| 1066 | "buffer_info[next_to_clean]:\n" |
| 1067 | " time_stamp <%lx>\n" |
| 1068 | " next_to_watch <%x>\n" |
| 1069 | " jiffies <%lx>\n" |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1070 | " next_to_watch.status <%x>\n" |
| 1071 | "MAC Status <%x>\n" |
| 1072 | "PHY Status <%x>\n" |
| 1073 | "PHY 1000BASE-T Status <%x>\n" |
| 1074 | "PHY Extended Status <%x>\n" |
| 1075 | "PCI Status <%x>\n", |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 1076 | readl(tx_ring->head), |
| 1077 | readl(tx_ring->tail), |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1078 | tx_ring->next_to_use, |
| 1079 | tx_ring->next_to_clean, |
| 1080 | tx_ring->buffer_info[eop].time_stamp, |
| 1081 | eop, |
| 1082 | jiffies, |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1083 | eop_desc->upper.fields.status, |
| 1084 | er32(STATUS), |
| 1085 | phy_status, |
| 1086 | phy_1000t_status, |
| 1087 | phy_ext_status, |
| 1088 | pci_status); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | /** |
| 1092 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 1093 | * @adapter: board private structure |
| 1094 | * |
| 1095 | * the return value indicates whether actual cleaning was done, there |
| 1096 | * is no guarantee that everything was cleaned |
| 1097 | **/ |
| 1098 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter) |
| 1099 | { |
| 1100 | struct net_device *netdev = adapter->netdev; |
| 1101 | struct e1000_hw *hw = &adapter->hw; |
| 1102 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1103 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 1104 | struct e1000_buffer *buffer_info; |
| 1105 | unsigned int i, eop; |
| 1106 | unsigned int count = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1107 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1108 | unsigned int bytes_compl = 0, pkts_compl = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1109 | |
| 1110 | i = tx_ring->next_to_clean; |
| 1111 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1112 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 1113 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1114 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 1115 | (count < tx_ring->count)) { |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1116 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1117 | rmb(); /* read buffer_info after eop_desc */ |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1118 | for (; !cleaned; count++) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1119 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 1120 | buffer_info = &tx_ring->buffer_info[i]; |
| 1121 | cleaned = (i == eop); |
| 1122 | |
| 1123 | if (cleaned) { |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 1124 | total_tx_packets += buffer_info->segs; |
| 1125 | total_tx_bytes += buffer_info->bytecount; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1126 | if (buffer_info->skb) { |
| 1127 | bytes_compl += buffer_info->skb->len; |
| 1128 | pkts_compl++; |
| 1129 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | e1000_put_txbuf(adapter, buffer_info); |
| 1133 | tx_desc->upper.data = 0; |
| 1134 | |
| 1135 | i++; |
| 1136 | if (i == tx_ring->count) |
| 1137 | i = 0; |
| 1138 | } |
| 1139 | |
Terry Loftin | dac8761 | 2010-04-09 10:29:49 +0000 | [diff] [blame] | 1140 | if (i == tx_ring->next_to_use) |
| 1141 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1142 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1143 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | tx_ring->next_to_clean = i; |
| 1147 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1148 | netdev_completed_queue(netdev, pkts_compl, bytes_compl); |
| 1149 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1150 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1151 | if (count && netif_carrier_ok(netdev) && |
| 1152 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1153 | /* Make sure that anybody stopping the queue after this |
| 1154 | * sees the new next_to_clean. |
| 1155 | */ |
| 1156 | smp_mb(); |
| 1157 | |
| 1158 | if (netif_queue_stopped(netdev) && |
| 1159 | !(test_bit(__E1000_DOWN, &adapter->state))) { |
| 1160 | netif_wake_queue(netdev); |
| 1161 | ++adapter->restart_queue; |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | if (adapter->detect_tx_hung) { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1166 | /* |
| 1167 | * Detect a transmit hang in hardware, this serializes the |
| 1168 | * check with the clearing of time_stamp and movement of i |
| 1169 | */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1170 | adapter->detect_tx_hung = false; |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1171 | if (tx_ring->buffer_info[i].time_stamp && |
| 1172 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1173 | + (adapter->tx_timeout_factor * HZ)) && |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1174 | !(er32(STATUS) & E1000_STATUS_TXOFF)) |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1175 | schedule_work(&adapter->print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1176 | else |
| 1177 | adapter->tx_hang_recheck = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1178 | } |
| 1179 | adapter->total_tx_bytes += total_tx_bytes; |
| 1180 | adapter->total_tx_packets += total_tx_packets; |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1181 | return count < tx_ring->count; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1185 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
| 1186 | * @adapter: board private structure |
| 1187 | * |
| 1188 | * the return value indicates whether actual cleaning was done, there |
| 1189 | * is no guarantee that everything was cleaned |
| 1190 | **/ |
| 1191 | static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 1192 | int *work_done, int work_to_do) |
| 1193 | { |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1194 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1195 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
| 1196 | struct net_device *netdev = adapter->netdev; |
| 1197 | struct pci_dev *pdev = adapter->pdev; |
| 1198 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1199 | struct e1000_buffer *buffer_info, *next_buffer; |
| 1200 | struct e1000_ps_page *ps_page; |
| 1201 | struct sk_buff *skb; |
| 1202 | unsigned int i, j; |
| 1203 | u32 length, staterr; |
| 1204 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1205 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1206 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 1207 | |
| 1208 | i = rx_ring->next_to_clean; |
| 1209 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 1210 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1211 | buffer_info = &rx_ring->buffer_info[i]; |
| 1212 | |
| 1213 | while (staterr & E1000_RXD_STAT_DD) { |
| 1214 | if (*work_done >= work_to_do) |
| 1215 | break; |
| 1216 | (*work_done)++; |
| 1217 | skb = buffer_info->skb; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1218 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1219 | |
| 1220 | /* in the packet split case this is header only */ |
| 1221 | prefetch(skb->data - NET_IP_ALIGN); |
| 1222 | |
| 1223 | i++; |
| 1224 | if (i == rx_ring->count) |
| 1225 | i = 0; |
| 1226 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
| 1227 | prefetch(next_rxd); |
| 1228 | |
| 1229 | next_buffer = &rx_ring->buffer_info[i]; |
| 1230 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1231 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1232 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1233 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1234 | adapter->rx_ps_bsize0, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1235 | buffer_info->dma = 0; |
| 1236 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1237 | /* see !EOP comment in other Rx routine */ |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1238 | if (!(staterr & E1000_RXD_STAT_EOP)) |
| 1239 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 1240 | |
| 1241 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1242 | 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] | 1243 | dev_kfree_skb_irq(skb); |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1244 | if (staterr & E1000_RXD_STAT_EOP) |
| 1245 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1246 | goto next_desc; |
| 1247 | } |
| 1248 | |
| 1249 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
| 1250 | dev_kfree_skb_irq(skb); |
| 1251 | goto next_desc; |
| 1252 | } |
| 1253 | |
| 1254 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 1255 | |
| 1256 | if (!length) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1257 | e_dbg("Last part of the packet spanning multiple descriptors\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1258 | dev_kfree_skb_irq(skb); |
| 1259 | goto next_desc; |
| 1260 | } |
| 1261 | |
| 1262 | /* Good Receive */ |
| 1263 | skb_put(skb, length); |
| 1264 | |
| 1265 | { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1266 | /* |
| 1267 | * this looks ugly, but it seems compiler issues make it |
| 1268 | * more efficient than reusing j |
| 1269 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1270 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 1271 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1272 | /* |
| 1273 | * page alloc/put takes too long and effects small packet |
| 1274 | * throughput, so unsplit small packets and save the alloc/put |
| 1275 | * only valid in softirq (napi) context to call kmap_* |
| 1276 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1277 | if (l1 && (l1 <= copybreak) && |
| 1278 | ((length + l1) <= adapter->rx_ps_bsize0)) { |
| 1279 | u8 *vaddr; |
| 1280 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1281 | ps_page = &buffer_info->ps_pages[0]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1282 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1283 | /* |
| 1284 | * there is no documentation about how to call |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1285 | * kmap_atomic, so we can't hold the mapping |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1286 | * very long |
| 1287 | */ |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1288 | dma_sync_single_for_cpu(&pdev->dev, ps_page->dma, |
| 1289 | PAGE_SIZE, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1290 | vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ); |
| 1291 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
| 1292 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1293 | dma_sync_single_for_device(&pdev->dev, ps_page->dma, |
| 1294 | PAGE_SIZE, DMA_FROM_DEVICE); |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 1295 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1296 | /* remove the CRC */ |
| 1297 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 1298 | l1 -= 4; |
| 1299 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1300 | skb_put(skb, l1); |
| 1301 | goto copydone; |
| 1302 | } /* if */ |
| 1303 | } |
| 1304 | |
| 1305 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
| 1306 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); |
| 1307 | if (!length) |
| 1308 | break; |
| 1309 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1310 | ps_page = &buffer_info->ps_pages[j]; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1311 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1312 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1313 | ps_page->dma = 0; |
| 1314 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); |
| 1315 | ps_page->page = NULL; |
| 1316 | skb->len += length; |
| 1317 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1318 | skb->truesize += PAGE_SIZE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1321 | /* strip the ethernet crc, problem is we're using pages now so |
| 1322 | * this whole operation can get a little cpu intensive |
| 1323 | */ |
| 1324 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 1325 | pskb_trim(skb, skb->len - 4); |
| 1326 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1327 | copydone: |
| 1328 | total_rx_bytes += skb->len; |
| 1329 | total_rx_packets++; |
| 1330 | |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 1331 | e1000_rx_checksum(adapter, staterr, |
| 1332 | rx_desc->wb.lower.hi_dword.csum_ip.csum, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1333 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1334 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1335 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1336 | if (rx_desc->wb.upper.header_status & |
| 1337 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) |
| 1338 | adapter->rx_hdr_split++; |
| 1339 | |
| 1340 | e1000_receive_skb(adapter, netdev, skb, |
| 1341 | staterr, rx_desc->wb.middle.vlan); |
| 1342 | |
| 1343 | next_desc: |
| 1344 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
| 1345 | buffer_info->skb = NULL; |
| 1346 | |
| 1347 | /* return some buffers to hardware, one at a time is too slow */ |
| 1348 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1349 | adapter->alloc_rx_buf(adapter, cleaned_count, |
| 1350 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1351 | cleaned_count = 0; |
| 1352 | } |
| 1353 | |
| 1354 | /* use prefetched values */ |
| 1355 | rx_desc = next_rxd; |
| 1356 | buffer_info = next_buffer; |
| 1357 | |
| 1358 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1359 | } |
| 1360 | rx_ring->next_to_clean = i; |
| 1361 | |
| 1362 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1363 | if (cleaned_count) |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1364 | adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1365 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1366 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1367 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1368 | return cleaned; |
| 1369 | } |
| 1370 | |
| 1371 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1372 | * e1000_consume_page - helper function |
| 1373 | **/ |
| 1374 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
| 1375 | u16 length) |
| 1376 | { |
| 1377 | bi->page = NULL; |
| 1378 | skb->len += length; |
| 1379 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1380 | skb->truesize += PAGE_SIZE; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | /** |
| 1384 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 1385 | * @adapter: board private structure |
| 1386 | * |
| 1387 | * the return value indicates whether actual cleaning was done, there |
| 1388 | * is no guarantee that everything was cleaned |
| 1389 | **/ |
| 1390 | |
| 1391 | static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, |
| 1392 | int *work_done, int work_to_do) |
| 1393 | { |
| 1394 | struct net_device *netdev = adapter->netdev; |
| 1395 | struct pci_dev *pdev = adapter->pdev; |
| 1396 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1397 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1398 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1399 | u32 length, staterr; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1400 | unsigned int i; |
| 1401 | int cleaned_count = 0; |
| 1402 | bool cleaned = false; |
| 1403 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
| 1404 | |
| 1405 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1406 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 1407 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1408 | buffer_info = &rx_ring->buffer_info[i]; |
| 1409 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1410 | while (staterr & E1000_RXD_STAT_DD) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1411 | struct sk_buff *skb; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1412 | |
| 1413 | if (*work_done >= work_to_do) |
| 1414 | break; |
| 1415 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1416 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1417 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1418 | skb = buffer_info->skb; |
| 1419 | buffer_info->skb = NULL; |
| 1420 | |
| 1421 | ++i; |
| 1422 | if (i == rx_ring->count) |
| 1423 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1424 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1425 | prefetch(next_rxd); |
| 1426 | |
| 1427 | next_buffer = &rx_ring->buffer_info[i]; |
| 1428 | |
| 1429 | cleaned = true; |
| 1430 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1431 | dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE, |
| 1432 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1433 | buffer_info->dma = 0; |
| 1434 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1435 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1436 | |
| 1437 | /* errors is only valid for DD + EOP descriptors */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1438 | if (unlikely((staterr & E1000_RXD_STAT_EOP) && |
| 1439 | (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) { |
| 1440 | /* recycle both page and skb */ |
| 1441 | buffer_info->skb = skb; |
| 1442 | /* an error means any chain goes out the window too */ |
| 1443 | if (rx_ring->rx_skb_top) |
| 1444 | dev_kfree_skb_irq(rx_ring->rx_skb_top); |
| 1445 | rx_ring->rx_skb_top = NULL; |
| 1446 | goto next_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Bruce Allan | f0f1a17 | 2010-12-11 05:53:32 +0000 | [diff] [blame] | 1449 | #define rxtop (rx_ring->rx_skb_top) |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1450 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1451 | /* this descriptor is only the beginning (or middle) */ |
| 1452 | if (!rxtop) { |
| 1453 | /* this is the beginning of a chain */ |
| 1454 | rxtop = skb; |
| 1455 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
| 1456 | 0, length); |
| 1457 | } else { |
| 1458 | /* this is the middle of a chain */ |
| 1459 | skb_fill_page_desc(rxtop, |
| 1460 | skb_shinfo(rxtop)->nr_frags, |
| 1461 | buffer_info->page, 0, length); |
| 1462 | /* re-use the skb, only consumed the page */ |
| 1463 | buffer_info->skb = skb; |
| 1464 | } |
| 1465 | e1000_consume_page(buffer_info, rxtop, length); |
| 1466 | goto next_desc; |
| 1467 | } else { |
| 1468 | if (rxtop) { |
| 1469 | /* end of the chain */ |
| 1470 | skb_fill_page_desc(rxtop, |
| 1471 | skb_shinfo(rxtop)->nr_frags, |
| 1472 | buffer_info->page, 0, length); |
| 1473 | /* re-use the current skb, we only consumed the |
| 1474 | * page */ |
| 1475 | buffer_info->skb = skb; |
| 1476 | skb = rxtop; |
| 1477 | rxtop = NULL; |
| 1478 | e1000_consume_page(buffer_info, skb, length); |
| 1479 | } else { |
| 1480 | /* no chain, got EOP, this buf is the packet |
| 1481 | * copybreak to save the put_page/alloc_page */ |
| 1482 | if (length <= copybreak && |
| 1483 | skb_tailroom(skb) >= length) { |
| 1484 | u8 *vaddr; |
| 1485 | vaddr = kmap_atomic(buffer_info->page, |
| 1486 | KM_SKB_DATA_SOFTIRQ); |
| 1487 | memcpy(skb_tail_pointer(skb), vaddr, |
| 1488 | length); |
| 1489 | kunmap_atomic(vaddr, |
| 1490 | KM_SKB_DATA_SOFTIRQ); |
| 1491 | /* re-use the page, so don't erase |
| 1492 | * buffer_info->page */ |
| 1493 | skb_put(skb, length); |
| 1494 | } else { |
| 1495 | skb_fill_page_desc(skb, 0, |
| 1496 | buffer_info->page, 0, |
| 1497 | length); |
| 1498 | e1000_consume_page(buffer_info, skb, |
| 1499 | length); |
| 1500 | } |
| 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | /* Receive Checksum Offload XXX recompute due to CRC strip? */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1505 | e1000_rx_checksum(adapter, staterr, |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 1506 | rx_desc->wb.lower.hi_dword.csum_ip.csum, skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1507 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1508 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1509 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1510 | /* probably a little skewed due to removing CRC */ |
| 1511 | total_rx_bytes += skb->len; |
| 1512 | total_rx_packets++; |
| 1513 | |
| 1514 | /* eth type trans needs skb->data to point to something */ |
| 1515 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1516 | e_err("pskb_may_pull failed.\n"); |
Bruce Allan | ef5ab89 | 2011-02-10 08:17:21 +0000 | [diff] [blame] | 1517 | dev_kfree_skb_irq(skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1518 | goto next_desc; |
| 1519 | } |
| 1520 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1521 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1522 | rx_desc->wb.upper.vlan); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1523 | |
| 1524 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1525 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1526 | |
| 1527 | /* return some buffers to hardware, one at a time is too slow */ |
| 1528 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1529 | adapter->alloc_rx_buf(adapter, cleaned_count, |
| 1530 | GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1531 | cleaned_count = 0; |
| 1532 | } |
| 1533 | |
| 1534 | /* use prefetched values */ |
| 1535 | rx_desc = next_rxd; |
| 1536 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1537 | |
| 1538 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1539 | } |
| 1540 | rx_ring->next_to_clean = i; |
| 1541 | |
| 1542 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1543 | if (cleaned_count) |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1544 | adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1545 | |
| 1546 | adapter->total_rx_bytes += total_rx_bytes; |
| 1547 | adapter->total_rx_packets += total_rx_packets; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1548 | return cleaned; |
| 1549 | } |
| 1550 | |
| 1551 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1552 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 1553 | * @adapter: board private structure |
| 1554 | **/ |
| 1555 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter) |
| 1556 | { |
| 1557 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1558 | struct e1000_buffer *buffer_info; |
| 1559 | struct e1000_ps_page *ps_page; |
| 1560 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1561 | unsigned int i, j; |
| 1562 | |
| 1563 | /* Free all the Rx ring sk_buffs */ |
| 1564 | for (i = 0; i < rx_ring->count; i++) { |
| 1565 | buffer_info = &rx_ring->buffer_info[i]; |
| 1566 | if (buffer_info->dma) { |
| 1567 | if (adapter->clean_rx == e1000_clean_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1568 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1569 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1570 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1571 | else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1572 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1573 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1574 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1575 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1576 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1577 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1578 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1579 | buffer_info->dma = 0; |
| 1580 | } |
| 1581 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1582 | if (buffer_info->page) { |
| 1583 | put_page(buffer_info->page); |
| 1584 | buffer_info->page = NULL; |
| 1585 | } |
| 1586 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1587 | if (buffer_info->skb) { |
| 1588 | dev_kfree_skb(buffer_info->skb); |
| 1589 | buffer_info->skb = NULL; |
| 1590 | } |
| 1591 | |
| 1592 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1593 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1594 | if (!ps_page->page) |
| 1595 | break; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1596 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1597 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1598 | ps_page->dma = 0; |
| 1599 | put_page(ps_page->page); |
| 1600 | ps_page->page = NULL; |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | /* there also may be some cached data from a chained receive */ |
| 1605 | if (rx_ring->rx_skb_top) { |
| 1606 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 1607 | rx_ring->rx_skb_top = NULL; |
| 1608 | } |
| 1609 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1610 | /* Zero out the descriptor ring */ |
| 1611 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1612 | |
| 1613 | rx_ring->next_to_clean = 0; |
| 1614 | rx_ring->next_to_use = 0; |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1615 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1616 | |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 1617 | writel(0, rx_ring->head); |
| 1618 | writel(0, rx_ring->tail); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1621 | static void e1000e_downshift_workaround(struct work_struct *work) |
| 1622 | { |
| 1623 | struct e1000_adapter *adapter = container_of(work, |
| 1624 | struct e1000_adapter, downshift_task); |
| 1625 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1626 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1627 | return; |
| 1628 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1629 | e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); |
| 1630 | } |
| 1631 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1632 | /** |
| 1633 | * e1000_intr_msi - Interrupt Handler |
| 1634 | * @irq: interrupt number |
| 1635 | * @data: pointer to a network interface device structure |
| 1636 | **/ |
| 1637 | static irqreturn_t e1000_intr_msi(int irq, void *data) |
| 1638 | { |
| 1639 | struct net_device *netdev = data; |
| 1640 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1641 | struct e1000_hw *hw = &adapter->hw; |
| 1642 | u32 icr = er32(ICR); |
| 1643 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1644 | /* |
| 1645 | * read ICR disables interrupts using IAM |
| 1646 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1647 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1648 | if (icr & E1000_ICR_LSC) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1649 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1650 | /* |
| 1651 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1652 | * disconnect (LSC) before accessing any PHY registers |
| 1653 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1654 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1655 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1656 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1657 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1658 | /* |
| 1659 | * 80003ES2LAN workaround-- For packet buffer work-around on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1660 | * link down event; disable receives here in the ISR and reset |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1661 | * adapter in watchdog |
| 1662 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1663 | if (netif_carrier_ok(netdev) && |
| 1664 | adapter->flags & FLAG_RX_NEEDS_RESTART) { |
| 1665 | /* disable receives */ |
| 1666 | u32 rctl = er32(RCTL); |
| 1667 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1668 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1669 | } |
| 1670 | /* guard against interrupt when we're going down */ |
| 1671 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1672 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1673 | } |
| 1674 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1675 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1676 | adapter->total_tx_bytes = 0; |
| 1677 | adapter->total_tx_packets = 0; |
| 1678 | adapter->total_rx_bytes = 0; |
| 1679 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1680 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | return IRQ_HANDLED; |
| 1684 | } |
| 1685 | |
| 1686 | /** |
| 1687 | * e1000_intr - Interrupt Handler |
| 1688 | * @irq: interrupt number |
| 1689 | * @data: pointer to a network interface device structure |
| 1690 | **/ |
| 1691 | static irqreturn_t e1000_intr(int irq, void *data) |
| 1692 | { |
| 1693 | struct net_device *netdev = data; |
| 1694 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1695 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1696 | u32 rctl, icr = er32(ICR); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1697 | |
Bruce Allan | a68ea77 | 2009-11-20 23:23:16 +0000 | [diff] [blame] | 1698 | if (!icr || test_bit(__E1000_DOWN, &adapter->state)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1699 | return IRQ_NONE; /* Not our interrupt */ |
| 1700 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1701 | /* |
| 1702 | * IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 1703 | * not set, then the adapter didn't send an interrupt |
| 1704 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1705 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 1706 | return IRQ_NONE; |
| 1707 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1708 | /* |
| 1709 | * Interrupt Auto-Mask...upon reading ICR, |
| 1710 | * interrupts are masked. No need for the |
| 1711 | * IMC write |
| 1712 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1713 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1714 | if (icr & E1000_ICR_LSC) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1715 | hw->mac.get_link_status = 1; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1716 | /* |
| 1717 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1718 | * disconnect (LSC) before accessing any PHY registers |
| 1719 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1720 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1721 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1722 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1723 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1724 | /* |
| 1725 | * 80003ES2LAN workaround-- |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1726 | * For packet buffer work-around on link down event; |
| 1727 | * disable receives here in the ISR and |
| 1728 | * reset adapter in watchdog |
| 1729 | */ |
| 1730 | if (netif_carrier_ok(netdev) && |
| 1731 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { |
| 1732 | /* disable receives */ |
| 1733 | rctl = er32(RCTL); |
| 1734 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1735 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1736 | } |
| 1737 | /* guard against interrupt when we're going down */ |
| 1738 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1739 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1740 | } |
| 1741 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1742 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1743 | adapter->total_tx_bytes = 0; |
| 1744 | adapter->total_tx_packets = 0; |
| 1745 | adapter->total_rx_bytes = 0; |
| 1746 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1747 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | return IRQ_HANDLED; |
| 1751 | } |
| 1752 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1753 | static irqreturn_t e1000_msix_other(int irq, void *data) |
| 1754 | { |
| 1755 | struct net_device *netdev = data; |
| 1756 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1757 | struct e1000_hw *hw = &adapter->hw; |
| 1758 | u32 icr = er32(ICR); |
| 1759 | |
| 1760 | if (!(icr & E1000_ICR_INT_ASSERTED)) { |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1761 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1762 | ew32(IMS, E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1763 | return IRQ_NONE; |
| 1764 | } |
| 1765 | |
| 1766 | if (icr & adapter->eiac_mask) |
| 1767 | ew32(ICS, (icr & adapter->eiac_mask)); |
| 1768 | |
| 1769 | if (icr & E1000_ICR_OTHER) { |
| 1770 | if (!(icr & E1000_ICR_LSC)) |
| 1771 | goto no_link_interrupt; |
| 1772 | hw->mac.get_link_status = 1; |
| 1773 | /* guard against interrupt when we're going down */ |
| 1774 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1775 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1776 | } |
| 1777 | |
| 1778 | no_link_interrupt: |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1779 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1780 | ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1781 | |
| 1782 | return IRQ_HANDLED; |
| 1783 | } |
| 1784 | |
| 1785 | |
| 1786 | static irqreturn_t e1000_intr_msix_tx(int irq, void *data) |
| 1787 | { |
| 1788 | struct net_device *netdev = data; |
| 1789 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1790 | struct e1000_hw *hw = &adapter->hw; |
| 1791 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1792 | |
| 1793 | |
| 1794 | adapter->total_tx_bytes = 0; |
| 1795 | adapter->total_tx_packets = 0; |
| 1796 | |
| 1797 | if (!e1000_clean_tx_irq(adapter)) |
| 1798 | /* Ring was not completely cleaned, so fire another interrupt */ |
| 1799 | ew32(ICS, tx_ring->ims_val); |
| 1800 | |
| 1801 | return IRQ_HANDLED; |
| 1802 | } |
| 1803 | |
| 1804 | static irqreturn_t e1000_intr_msix_rx(int irq, void *data) |
| 1805 | { |
| 1806 | struct net_device *netdev = data; |
| 1807 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1808 | |
| 1809 | /* Write the ITR value calculated at the end of the |
| 1810 | * previous interrupt. |
| 1811 | */ |
| 1812 | if (adapter->rx_ring->set_itr) { |
| 1813 | writel(1000000000 / (adapter->rx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 1814 | adapter->rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1815 | adapter->rx_ring->set_itr = 0; |
| 1816 | } |
| 1817 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1818 | if (napi_schedule_prep(&adapter->napi)) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1819 | adapter->total_rx_bytes = 0; |
| 1820 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1821 | __napi_schedule(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1822 | } |
| 1823 | return IRQ_HANDLED; |
| 1824 | } |
| 1825 | |
| 1826 | /** |
| 1827 | * e1000_configure_msix - Configure MSI-X hardware |
| 1828 | * |
| 1829 | * e1000_configure_msix sets up the hardware to properly |
| 1830 | * generate MSI-X interrupts. |
| 1831 | **/ |
| 1832 | static void e1000_configure_msix(struct e1000_adapter *adapter) |
| 1833 | { |
| 1834 | struct e1000_hw *hw = &adapter->hw; |
| 1835 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1836 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1837 | int vector = 0; |
| 1838 | u32 ctrl_ext, ivar = 0; |
| 1839 | |
| 1840 | adapter->eiac_mask = 0; |
| 1841 | |
| 1842 | /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ |
| 1843 | if (hw->mac.type == e1000_82574) { |
| 1844 | u32 rfctl = er32(RFCTL); |
| 1845 | rfctl |= E1000_RFCTL_ACK_DIS; |
| 1846 | ew32(RFCTL, rfctl); |
| 1847 | } |
| 1848 | |
| 1849 | #define E1000_IVAR_INT_ALLOC_VALID 0x8 |
| 1850 | /* Configure Rx vector */ |
| 1851 | rx_ring->ims_val = E1000_IMS_RXQ0; |
| 1852 | adapter->eiac_mask |= rx_ring->ims_val; |
| 1853 | if (rx_ring->itr_val) |
| 1854 | writel(1000000000 / (rx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 1855 | rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1856 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 1857 | writel(1, rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1858 | ivar = E1000_IVAR_INT_ALLOC_VALID | vector; |
| 1859 | |
| 1860 | /* Configure Tx vector */ |
| 1861 | tx_ring->ims_val = E1000_IMS_TXQ0; |
| 1862 | vector++; |
| 1863 | if (tx_ring->itr_val) |
| 1864 | writel(1000000000 / (tx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 1865 | tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1866 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 1867 | writel(1, tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1868 | adapter->eiac_mask |= tx_ring->ims_val; |
| 1869 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); |
| 1870 | |
| 1871 | /* set vector for Other Causes, e.g. link changes */ |
| 1872 | vector++; |
| 1873 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); |
| 1874 | if (rx_ring->itr_val) |
| 1875 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1876 | hw->hw_addr + E1000_EITR_82574(vector)); |
| 1877 | else |
| 1878 | writel(1, hw->hw_addr + E1000_EITR_82574(vector)); |
| 1879 | |
| 1880 | /* Cause Tx interrupts on every write back */ |
| 1881 | ivar |= (1 << 31); |
| 1882 | |
| 1883 | ew32(IVAR, ivar); |
| 1884 | |
| 1885 | /* enable MSI-X PBA support */ |
| 1886 | ctrl_ext = er32(CTRL_EXT); |
| 1887 | ctrl_ext |= E1000_CTRL_EXT_PBA_CLR; |
| 1888 | |
| 1889 | /* Auto-Mask Other interrupts upon ICR read */ |
| 1890 | #define E1000_EIAC_MASK_82574 0x01F00000 |
| 1891 | ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER); |
| 1892 | ctrl_ext |= E1000_CTRL_EXT_EIAME; |
| 1893 | ew32(CTRL_EXT, ctrl_ext); |
| 1894 | e1e_flush(); |
| 1895 | } |
| 1896 | |
| 1897 | void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) |
| 1898 | { |
| 1899 | if (adapter->msix_entries) { |
| 1900 | pci_disable_msix(adapter->pdev); |
| 1901 | kfree(adapter->msix_entries); |
| 1902 | adapter->msix_entries = NULL; |
| 1903 | } else if (adapter->flags & FLAG_MSI_ENABLED) { |
| 1904 | pci_disable_msi(adapter->pdev); |
| 1905 | adapter->flags &= ~FLAG_MSI_ENABLED; |
| 1906 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | /** |
| 1910 | * e1000e_set_interrupt_capability - set MSI or MSI-X if supported |
| 1911 | * |
| 1912 | * Attempt to configure interrupts using the best available |
| 1913 | * capabilities of the hardware and kernel. |
| 1914 | **/ |
| 1915 | void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) |
| 1916 | { |
| 1917 | int err; |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1918 | int i; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1919 | |
| 1920 | switch (adapter->int_mode) { |
| 1921 | case E1000E_INT_MODE_MSIX: |
| 1922 | if (adapter->flags & FLAG_HAS_MSIX) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1923 | adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */ |
| 1924 | adapter->msix_entries = kcalloc(adapter->num_vectors, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1925 | sizeof(struct msix_entry), |
| 1926 | GFP_KERNEL); |
| 1927 | if (adapter->msix_entries) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1928 | for (i = 0; i < adapter->num_vectors; i++) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1929 | adapter->msix_entries[i].entry = i; |
| 1930 | |
| 1931 | err = pci_enable_msix(adapter->pdev, |
| 1932 | adapter->msix_entries, |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1933 | adapter->num_vectors); |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 1934 | if (err == 0) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1935 | return; |
| 1936 | } |
| 1937 | /* MSI-X failed, so fall through and try MSI */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1938 | 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] | 1939 | e1000e_reset_interrupt_capability(adapter); |
| 1940 | } |
| 1941 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 1942 | /* Fall through */ |
| 1943 | case E1000E_INT_MODE_MSI: |
| 1944 | if (!pci_enable_msi(adapter->pdev)) { |
| 1945 | adapter->flags |= FLAG_MSI_ENABLED; |
| 1946 | } else { |
| 1947 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1948 | 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] | 1949 | } |
| 1950 | /* Fall through */ |
| 1951 | case E1000E_INT_MODE_LEGACY: |
| 1952 | /* Don't do anything; this is the system default */ |
| 1953 | break; |
| 1954 | } |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1955 | |
| 1956 | /* store the number of vectors being used */ |
| 1957 | adapter->num_vectors = 1; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | /** |
| 1961 | * e1000_request_msix - Initialize MSI-X interrupts |
| 1962 | * |
| 1963 | * e1000_request_msix allocates MSI-X vectors and requests interrupts from the |
| 1964 | * kernel. |
| 1965 | **/ |
| 1966 | static int e1000_request_msix(struct e1000_adapter *adapter) |
| 1967 | { |
| 1968 | struct net_device *netdev = adapter->netdev; |
| 1969 | int err = 0, vector = 0; |
| 1970 | |
| 1971 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 1972 | snprintf(adapter->rx_ring->name, |
| 1973 | sizeof(adapter->rx_ring->name) - 1, |
| 1974 | "%s-rx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1975 | else |
| 1976 | memcpy(adapter->rx_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_rx, 0, adapter->rx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1979 | netdev); |
| 1980 | if (err) |
| 1981 | goto out; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 1982 | adapter->rx_ring->itr_register = adapter->hw.hw_addr + |
| 1983 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1984 | adapter->rx_ring->itr_val = adapter->itr; |
| 1985 | vector++; |
| 1986 | |
| 1987 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 1988 | snprintf(adapter->tx_ring->name, |
| 1989 | sizeof(adapter->tx_ring->name) - 1, |
| 1990 | "%s-tx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1991 | else |
| 1992 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); |
| 1993 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1994 | e1000_intr_msix_tx, 0, adapter->tx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1995 | netdev); |
| 1996 | if (err) |
| 1997 | goto out; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 1998 | adapter->tx_ring->itr_register = adapter->hw.hw_addr + |
| 1999 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2000 | adapter->tx_ring->itr_val = adapter->itr; |
| 2001 | vector++; |
| 2002 | |
| 2003 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2004 | e1000_msix_other, 0, netdev->name, netdev); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2005 | if (err) |
| 2006 | goto out; |
| 2007 | |
| 2008 | e1000_configure_msix(adapter); |
| 2009 | return 0; |
| 2010 | out: |
| 2011 | return err; |
| 2012 | } |
| 2013 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2014 | /** |
| 2015 | * e1000_request_irq - initialize interrupts |
| 2016 | * |
| 2017 | * Attempts to configure interrupts using the best available |
| 2018 | * capabilities of the hardware and kernel. |
| 2019 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2020 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 2021 | { |
| 2022 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2023 | int err; |
| 2024 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2025 | if (adapter->msix_entries) { |
| 2026 | err = e1000_request_msix(adapter); |
| 2027 | if (!err) |
| 2028 | return err; |
| 2029 | /* fall back to MSI */ |
| 2030 | e1000e_reset_interrupt_capability(adapter); |
| 2031 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 2032 | e1000e_set_interrupt_capability(adapter); |
| 2033 | } |
| 2034 | if (adapter->flags & FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2035 | err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2036 | netdev->name, netdev); |
| 2037 | if (!err) |
| 2038 | return err; |
| 2039 | |
| 2040 | /* fall back to legacy interrupt */ |
| 2041 | e1000e_reset_interrupt_capability(adapter); |
| 2042 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2045 | err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2046 | netdev->name, netdev); |
| 2047 | if (err) |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2048 | e_err("Unable to allocate interrupt, Error: %d\n", err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2049 | |
| 2050 | return err; |
| 2051 | } |
| 2052 | |
| 2053 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 2054 | { |
| 2055 | struct net_device *netdev = adapter->netdev; |
| 2056 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2057 | if (adapter->msix_entries) { |
| 2058 | int vector = 0; |
| 2059 | |
| 2060 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2061 | vector++; |
| 2062 | |
| 2063 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2064 | vector++; |
| 2065 | |
| 2066 | /* Other Causes interrupt vector */ |
| 2067 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2068 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2069 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2070 | |
| 2071 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | /** |
| 2075 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 2076 | **/ |
| 2077 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
| 2078 | { |
| 2079 | struct e1000_hw *hw = &adapter->hw; |
| 2080 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2081 | ew32(IMC, ~0); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2082 | if (adapter->msix_entries) |
| 2083 | ew32(EIAC_82574, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2084 | e1e_flush(); |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2085 | |
| 2086 | if (adapter->msix_entries) { |
| 2087 | int i; |
| 2088 | for (i = 0; i < adapter->num_vectors; i++) |
| 2089 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2090 | } else { |
| 2091 | synchronize_irq(adapter->pdev->irq); |
| 2092 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | /** |
| 2096 | * e1000_irq_enable - Enable default interrupt generation settings |
| 2097 | **/ |
| 2098 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
| 2099 | { |
| 2100 | struct e1000_hw *hw = &adapter->hw; |
| 2101 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2102 | if (adapter->msix_entries) { |
| 2103 | ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); |
| 2104 | ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC); |
| 2105 | } else { |
| 2106 | ew32(IMS, IMS_ENABLE_MASK); |
| 2107 | } |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 2108 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2112 | * 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] | 2113 | * @adapter: address of board private structure |
| 2114 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2115 | * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2116 | * For ASF and Pass Through versions of f/w this means that |
| 2117 | * the driver is loaded. For AMT version (only with 82573) |
| 2118 | * of the f/w this means that the network i/f is open. |
| 2119 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2120 | void e1000e_get_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2121 | { |
| 2122 | struct e1000_hw *hw = &adapter->hw; |
| 2123 | u32 ctrl_ext; |
| 2124 | u32 swsm; |
| 2125 | |
| 2126 | /* Let firmware know the driver has taken over */ |
| 2127 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2128 | swsm = er32(SWSM); |
| 2129 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
| 2130 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2131 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2132 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2133 | } |
| 2134 | } |
| 2135 | |
| 2136 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2137 | * 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] | 2138 | * @adapter: address of board private structure |
| 2139 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2140 | * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2141 | * For ASF and Pass Through versions of f/w this means that the |
| 2142 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 2143 | * of the f/w this means that the network i/f is closed. |
| 2144 | * |
| 2145 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2146 | void e1000e_release_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2147 | { |
| 2148 | struct e1000_hw *hw = &adapter->hw; |
| 2149 | u32 ctrl_ext; |
| 2150 | u32 swsm; |
| 2151 | |
| 2152 | /* Let firmware taken over control of h/w */ |
| 2153 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2154 | swsm = er32(SWSM); |
| 2155 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
| 2156 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2157 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2158 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2159 | } |
| 2160 | } |
| 2161 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2162 | /** |
| 2163 | * @e1000_alloc_ring - allocate memory for a ring structure |
| 2164 | **/ |
| 2165 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, |
| 2166 | struct e1000_ring *ring) |
| 2167 | { |
| 2168 | struct pci_dev *pdev = adapter->pdev; |
| 2169 | |
| 2170 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, |
| 2171 | GFP_KERNEL); |
| 2172 | if (!ring->desc) |
| 2173 | return -ENOMEM; |
| 2174 | |
| 2175 | return 0; |
| 2176 | } |
| 2177 | |
| 2178 | /** |
| 2179 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) |
| 2180 | * @adapter: board private structure |
| 2181 | * |
| 2182 | * Return 0 on success, negative on failure |
| 2183 | **/ |
| 2184 | int e1000e_setup_tx_resources(struct e1000_adapter *adapter) |
| 2185 | { |
| 2186 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2187 | int err = -ENOMEM, size; |
| 2188 | |
| 2189 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2190 | tx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2191 | if (!tx_ring->buffer_info) |
| 2192 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2193 | |
| 2194 | /* round up to nearest 4K */ |
| 2195 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
| 2196 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2197 | |
| 2198 | err = e1000_alloc_ring_dma(adapter, tx_ring); |
| 2199 | if (err) |
| 2200 | goto err; |
| 2201 | |
| 2202 | tx_ring->next_to_use = 0; |
| 2203 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2204 | |
| 2205 | return 0; |
| 2206 | err: |
| 2207 | vfree(tx_ring->buffer_info); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 2208 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2209 | return err; |
| 2210 | } |
| 2211 | |
| 2212 | /** |
| 2213 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) |
| 2214 | * @adapter: board private structure |
| 2215 | * |
| 2216 | * Returns 0 on success, negative on failure |
| 2217 | **/ |
| 2218 | int e1000e_setup_rx_resources(struct e1000_adapter *adapter) |
| 2219 | { |
| 2220 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2221 | struct e1000_buffer *buffer_info; |
| 2222 | int i, size, desc_len, err = -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2223 | |
| 2224 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2225 | rx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2226 | if (!rx_ring->buffer_info) |
| 2227 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2228 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2229 | for (i = 0; i < rx_ring->count; i++) { |
| 2230 | buffer_info = &rx_ring->buffer_info[i]; |
| 2231 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, |
| 2232 | sizeof(struct e1000_ps_page), |
| 2233 | GFP_KERNEL); |
| 2234 | if (!buffer_info->ps_pages) |
| 2235 | goto err_pages; |
| 2236 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2237 | |
| 2238 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 2239 | |
| 2240 | /* Round up to nearest 4K */ |
| 2241 | rx_ring->size = rx_ring->count * desc_len; |
| 2242 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2243 | |
| 2244 | err = e1000_alloc_ring_dma(adapter, rx_ring); |
| 2245 | if (err) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2246 | goto err_pages; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2247 | |
| 2248 | rx_ring->next_to_clean = 0; |
| 2249 | rx_ring->next_to_use = 0; |
| 2250 | rx_ring->rx_skb_top = NULL; |
| 2251 | |
| 2252 | return 0; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2253 | |
| 2254 | err_pages: |
| 2255 | for (i = 0; i < rx_ring->count; i++) { |
| 2256 | buffer_info = &rx_ring->buffer_info[i]; |
| 2257 | kfree(buffer_info->ps_pages); |
| 2258 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2259 | err: |
| 2260 | vfree(rx_ring->buffer_info); |
Bruce Allan | e926244 | 2010-11-24 06:02:06 +0000 | [diff] [blame] | 2261 | e_err("Unable to allocate memory for the receive descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2262 | return err; |
| 2263 | } |
| 2264 | |
| 2265 | /** |
| 2266 | * e1000_clean_tx_ring - Free Tx Buffers |
| 2267 | * @adapter: board private structure |
| 2268 | **/ |
| 2269 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter) |
| 2270 | { |
| 2271 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2272 | struct e1000_buffer *buffer_info; |
| 2273 | unsigned long size; |
| 2274 | unsigned int i; |
| 2275 | |
| 2276 | for (i = 0; i < tx_ring->count; i++) { |
| 2277 | buffer_info = &tx_ring->buffer_info[i]; |
| 2278 | e1000_put_txbuf(adapter, buffer_info); |
| 2279 | } |
| 2280 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 2281 | netdev_reset_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2282 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2283 | memset(tx_ring->buffer_info, 0, size); |
| 2284 | |
| 2285 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2286 | |
| 2287 | tx_ring->next_to_use = 0; |
| 2288 | tx_ring->next_to_clean = 0; |
| 2289 | |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 2290 | writel(0, tx_ring->head); |
| 2291 | writel(0, tx_ring->tail); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | /** |
| 2295 | * e1000e_free_tx_resources - Free Tx Resources per Queue |
| 2296 | * @adapter: board private structure |
| 2297 | * |
| 2298 | * Free all transmit software resources |
| 2299 | **/ |
| 2300 | void e1000e_free_tx_resources(struct e1000_adapter *adapter) |
| 2301 | { |
| 2302 | struct pci_dev *pdev = adapter->pdev; |
| 2303 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2304 | |
| 2305 | e1000_clean_tx_ring(adapter); |
| 2306 | |
| 2307 | vfree(tx_ring->buffer_info); |
| 2308 | tx_ring->buffer_info = NULL; |
| 2309 | |
| 2310 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 2311 | tx_ring->dma); |
| 2312 | tx_ring->desc = NULL; |
| 2313 | } |
| 2314 | |
| 2315 | /** |
| 2316 | * e1000e_free_rx_resources - Free Rx Resources |
| 2317 | * @adapter: board private structure |
| 2318 | * |
| 2319 | * Free all receive software resources |
| 2320 | **/ |
| 2321 | |
| 2322 | void e1000e_free_rx_resources(struct e1000_adapter *adapter) |
| 2323 | { |
| 2324 | struct pci_dev *pdev = adapter->pdev; |
| 2325 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2326 | int i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2327 | |
| 2328 | e1000_clean_rx_ring(adapter); |
| 2329 | |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2330 | for (i = 0; i < rx_ring->count; i++) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2331 | kfree(rx_ring->buffer_info[i].ps_pages); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2332 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2333 | vfree(rx_ring->buffer_info); |
| 2334 | rx_ring->buffer_info = NULL; |
| 2335 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2336 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 2337 | rx_ring->dma); |
| 2338 | rx_ring->desc = NULL; |
| 2339 | } |
| 2340 | |
| 2341 | /** |
| 2342 | * e1000_update_itr - update the dynamic ITR value based on statistics |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2343 | * @adapter: pointer to adapter |
| 2344 | * @itr_setting: current adapter->itr |
| 2345 | * @packets: the number of packets during this measurement interval |
| 2346 | * @bytes: the number of bytes during this measurement interval |
| 2347 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2348 | * Stores a new ITR value based on packets and byte |
| 2349 | * counts during the last interrupt. The advantage of per interrupt |
| 2350 | * computation is faster updates and more accurate ITR for the current |
| 2351 | * traffic pattern. Constants in this function were computed |
| 2352 | * based on theoretical maximum wire speed and thresholds were set based |
| 2353 | * on testing data as well as attempting to minimize response time |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2354 | * while increasing bulk throughput. This functionality is controlled |
| 2355 | * by the InterruptThrottleRate module parameter. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2356 | **/ |
| 2357 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
| 2358 | u16 itr_setting, int packets, |
| 2359 | int bytes) |
| 2360 | { |
| 2361 | unsigned int retval = itr_setting; |
| 2362 | |
| 2363 | if (packets == 0) |
| 2364 | goto update_itr_done; |
| 2365 | |
| 2366 | switch (itr_setting) { |
| 2367 | case lowest_latency: |
| 2368 | /* handle TSO and jumbo frames */ |
| 2369 | if (bytes/packets > 8000) |
| 2370 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2371 | else if ((packets < 5) && (bytes > 512)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2372 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2373 | break; |
| 2374 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2375 | if (bytes > 10000) { |
| 2376 | /* this if handles the TSO accounting */ |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2377 | if (bytes/packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2378 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2379 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2380 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2381 | else if ((packets > 35)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2382 | retval = lowest_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2383 | } else if (bytes/packets > 2000) { |
| 2384 | retval = bulk_latency; |
| 2385 | } else if (packets <= 2 && bytes < 512) { |
| 2386 | retval = lowest_latency; |
| 2387 | } |
| 2388 | break; |
| 2389 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2390 | if (bytes > 25000) { |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2391 | if (packets > 35) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2392 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2393 | } else if (bytes < 6000) { |
| 2394 | retval = low_latency; |
| 2395 | } |
| 2396 | break; |
| 2397 | } |
| 2398 | |
| 2399 | update_itr_done: |
| 2400 | return retval; |
| 2401 | } |
| 2402 | |
| 2403 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2404 | { |
| 2405 | struct e1000_hw *hw = &adapter->hw; |
| 2406 | u16 current_itr; |
| 2407 | u32 new_itr = adapter->itr; |
| 2408 | |
| 2409 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2410 | if (adapter->link_speed != SPEED_1000) { |
| 2411 | current_itr = 0; |
| 2412 | new_itr = 4000; |
| 2413 | goto set_itr_now; |
| 2414 | } |
| 2415 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2416 | if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 2417 | new_itr = 0; |
| 2418 | goto set_itr_now; |
| 2419 | } |
| 2420 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2421 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2422 | adapter->tx_itr, |
| 2423 | adapter->total_tx_packets, |
| 2424 | adapter->total_tx_bytes); |
| 2425 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2426 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2427 | adapter->tx_itr = low_latency; |
| 2428 | |
| 2429 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2430 | adapter->rx_itr, |
| 2431 | adapter->total_rx_packets, |
| 2432 | adapter->total_rx_bytes); |
| 2433 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2434 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2435 | adapter->rx_itr = low_latency; |
| 2436 | |
| 2437 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2438 | |
| 2439 | switch (current_itr) { |
| 2440 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2441 | case lowest_latency: |
| 2442 | new_itr = 70000; |
| 2443 | break; |
| 2444 | case low_latency: |
| 2445 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2446 | break; |
| 2447 | case bulk_latency: |
| 2448 | new_itr = 4000; |
| 2449 | break; |
| 2450 | default: |
| 2451 | break; |
| 2452 | } |
| 2453 | |
| 2454 | set_itr_now: |
| 2455 | if (new_itr != adapter->itr) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2456 | /* |
| 2457 | * this attempts to bias the interrupt rate towards Bulk |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2458 | * by adding intermediate steps when interrupt rate is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2459 | * increasing |
| 2460 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2461 | new_itr = new_itr > adapter->itr ? |
| 2462 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2463 | new_itr; |
| 2464 | adapter->itr = new_itr; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2465 | adapter->rx_ring->itr_val = new_itr; |
| 2466 | if (adapter->msix_entries) |
| 2467 | adapter->rx_ring->set_itr = 1; |
| 2468 | else |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2469 | if (new_itr) |
| 2470 | ew32(ITR, 1000000000 / (new_itr * 256)); |
| 2471 | else |
| 2472 | ew32(ITR, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | /** |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2477 | * e1000_alloc_queues - Allocate memory for all rings |
| 2478 | * @adapter: board private structure to initialize |
| 2479 | **/ |
| 2480 | static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) |
| 2481 | { |
| 2482 | adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
| 2483 | if (!adapter->tx_ring) |
| 2484 | goto err; |
| 2485 | |
| 2486 | adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); |
| 2487 | if (!adapter->rx_ring) |
| 2488 | goto err; |
| 2489 | |
| 2490 | return 0; |
| 2491 | err: |
| 2492 | e_err("Unable to allocate memory for queues\n"); |
| 2493 | kfree(adapter->rx_ring); |
| 2494 | kfree(adapter->tx_ring); |
| 2495 | return -ENOMEM; |
| 2496 | } |
| 2497 | |
| 2498 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2499 | * e1000_clean - NAPI Rx polling callback |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2500 | * @napi: struct associated with this polling callback |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2501 | * @budget: amount of packets driver is allowed to process this poll |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2502 | **/ |
| 2503 | static int e1000_clean(struct napi_struct *napi, int budget) |
| 2504 | { |
| 2505 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2506 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2507 | struct net_device *poll_dev = adapter->netdev; |
Andy Gospodarek | 679e8a0 | 2009-06-18 11:57:37 +0000 | [diff] [blame] | 2508 | int tx_cleaned = 1, work_done = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2509 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 2510 | adapter = netdev_priv(poll_dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2511 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2512 | if (adapter->msix_entries && |
| 2513 | !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) |
| 2514 | goto clean_rx; |
| 2515 | |
Jesse Brandeburg | 92af3e9 | 2009-01-19 14:17:08 +0000 | [diff] [blame] | 2516 | tx_cleaned = e1000_clean_tx_irq(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2517 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2518 | clean_rx: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2519 | adapter->clean_rx(adapter, &work_done, budget); |
| 2520 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 2521 | if (!tx_cleaned) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2522 | work_done = budget; |
| 2523 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 2524 | /* If budget not fully consumed, exit the polling mode */ |
| 2525 | if (work_done < budget) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2526 | if (adapter->itr_setting & 3) |
| 2527 | e1000_set_itr(adapter); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2528 | napi_complete(napi); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 2529 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 2530 | if (adapter->msix_entries) |
| 2531 | ew32(IMS, adapter->rx_ring->ims_val); |
| 2532 | else |
| 2533 | e1000_irq_enable(adapter); |
| 2534 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | return work_done; |
| 2538 | } |
| 2539 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2540 | 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] | 2541 | { |
| 2542 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2543 | struct e1000_hw *hw = &adapter->hw; |
| 2544 | u32 vfta, index; |
| 2545 | |
| 2546 | /* don't update vlan cookie if already programmed */ |
| 2547 | if ((adapter->hw.mng_cookie.status & |
| 2548 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2549 | (vid == adapter->mng_vlan_id)) |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2550 | return 0; |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2551 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2552 | /* add VID to filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2553 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2554 | index = (vid >> 5) & 0x7F; |
| 2555 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2556 | vfta |= (1 << (vid & 0x1F)); |
| 2557 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2558 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2559 | |
| 2560 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2561 | |
| 2562 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2563 | } |
| 2564 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2565 | 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] | 2566 | { |
| 2567 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2568 | struct e1000_hw *hw = &adapter->hw; |
| 2569 | u32 vfta, index; |
| 2570 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2571 | if ((adapter->hw.mng_cookie.status & |
| 2572 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2573 | (vid == adapter->mng_vlan_id)) { |
| 2574 | /* release control to f/w */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2575 | e1000e_release_hw_control(adapter); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2576 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | /* remove VID from filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2580 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2581 | index = (vid >> 5) & 0x7F; |
| 2582 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2583 | vfta &= ~(1 << (vid & 0x1F)); |
| 2584 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2585 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2586 | |
| 2587 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2588 | |
| 2589 | return 0; |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | /** |
| 2593 | * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering |
| 2594 | * @adapter: board private structure to initialize |
| 2595 | **/ |
| 2596 | static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter) |
| 2597 | { |
| 2598 | struct net_device *netdev = adapter->netdev; |
| 2599 | struct e1000_hw *hw = &adapter->hw; |
| 2600 | u32 rctl; |
| 2601 | |
| 2602 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2603 | /* disable VLAN receive filtering */ |
| 2604 | rctl = er32(RCTL); |
| 2605 | rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN); |
| 2606 | ew32(RCTL, rctl); |
| 2607 | |
| 2608 | if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { |
| 2609 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 2610 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 2611 | } |
| 2612 | } |
| 2613 | } |
| 2614 | |
| 2615 | /** |
| 2616 | * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering |
| 2617 | * @adapter: board private structure to initialize |
| 2618 | **/ |
| 2619 | static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter) |
| 2620 | { |
| 2621 | struct e1000_hw *hw = &adapter->hw; |
| 2622 | u32 rctl; |
| 2623 | |
| 2624 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2625 | /* enable VLAN receive filtering */ |
| 2626 | rctl = er32(RCTL); |
| 2627 | rctl |= E1000_RCTL_VFE; |
| 2628 | rctl &= ~E1000_RCTL_CFIEN; |
| 2629 | ew32(RCTL, rctl); |
| 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | /** |
| 2634 | * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping |
| 2635 | * @adapter: board private structure to initialize |
| 2636 | **/ |
| 2637 | static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter) |
| 2638 | { |
| 2639 | struct e1000_hw *hw = &adapter->hw; |
| 2640 | u32 ctrl; |
| 2641 | |
| 2642 | /* disable VLAN tag insert/strip */ |
| 2643 | ctrl = er32(CTRL); |
| 2644 | ctrl &= ~E1000_CTRL_VME; |
| 2645 | ew32(CTRL, ctrl); |
| 2646 | } |
| 2647 | |
| 2648 | /** |
| 2649 | * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping |
| 2650 | * @adapter: board private structure to initialize |
| 2651 | **/ |
| 2652 | static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter) |
| 2653 | { |
| 2654 | struct e1000_hw *hw = &adapter->hw; |
| 2655 | u32 ctrl; |
| 2656 | |
| 2657 | /* enable VLAN tag insert/strip */ |
| 2658 | ctrl = er32(CTRL); |
| 2659 | ctrl |= E1000_CTRL_VME; |
| 2660 | ew32(CTRL, ctrl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 2664 | { |
| 2665 | struct net_device *netdev = adapter->netdev; |
| 2666 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 2667 | u16 old_vid = adapter->mng_vlan_id; |
| 2668 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2669 | if (adapter->hw.mng_cookie.status & |
| 2670 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
| 2671 | e1000_vlan_rx_add_vid(netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2672 | adapter->mng_vlan_id = vid; |
| 2673 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2674 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2675 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid)) |
| 2676 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
| 2680 | { |
| 2681 | u16 vid; |
| 2682 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2683 | e1000_vlan_rx_add_vid(adapter->netdev, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2684 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2685 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2686 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2687 | } |
| 2688 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2689 | static void e1000_init_manageability_pt(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2690 | { |
| 2691 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2692 | u32 manc, manc2h, mdef, i, j; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2693 | |
| 2694 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) |
| 2695 | return; |
| 2696 | |
| 2697 | manc = er32(MANC); |
| 2698 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2699 | /* |
| 2700 | * enable receiving management packets to the host. this will probably |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2701 | * generate destination unreachable messages from the host OS, but |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2702 | * the packets will be handled on SMBUS |
| 2703 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2704 | manc |= E1000_MANC_EN_MNG2HOST; |
| 2705 | manc2h = er32(MANC2H); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2706 | |
| 2707 | switch (hw->mac.type) { |
| 2708 | default: |
| 2709 | manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664); |
| 2710 | break; |
| 2711 | case e1000_82574: |
| 2712 | case e1000_82583: |
| 2713 | /* |
| 2714 | * Check if IPMI pass-through decision filter already exists; |
| 2715 | * if so, enable it. |
| 2716 | */ |
| 2717 | for (i = 0, j = 0; i < 8; i++) { |
| 2718 | mdef = er32(MDEF(i)); |
| 2719 | |
| 2720 | /* Ignore filters with anything other than IPMI ports */ |
Dan Carpenter | 3b21b50 | 2010-06-02 13:43:15 +0000 | [diff] [blame] | 2721 | if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2722 | continue; |
| 2723 | |
| 2724 | /* Enable this decision filter in MANC2H */ |
| 2725 | if (mdef) |
| 2726 | manc2h |= (1 << i); |
| 2727 | |
| 2728 | j |= mdef; |
| 2729 | } |
| 2730 | |
| 2731 | if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
| 2732 | break; |
| 2733 | |
| 2734 | /* Create new decision filter in an empty filter */ |
| 2735 | for (i = 0, j = 0; i < 8; i++) |
| 2736 | if (er32(MDEF(i)) == 0) { |
| 2737 | ew32(MDEF(i), (E1000_MDEF_PORT_623 | |
| 2738 | E1000_MDEF_PORT_664)); |
| 2739 | manc2h |= (1 << 1); |
| 2740 | j++; |
| 2741 | break; |
| 2742 | } |
| 2743 | |
| 2744 | if (!j) |
| 2745 | e_warn("Unable to create IPMI pass-through filter\n"); |
| 2746 | break; |
| 2747 | } |
| 2748 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2749 | ew32(MANC2H, manc2h); |
| 2750 | ew32(MANC, manc); |
| 2751 | } |
| 2752 | |
| 2753 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2754 | * e1000_configure_tx - Configure Transmit Unit after Reset |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2755 | * @adapter: board private structure |
| 2756 | * |
| 2757 | * Configure the Tx unit of the MAC after a reset. |
| 2758 | **/ |
| 2759 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
| 2760 | { |
| 2761 | struct e1000_hw *hw = &adapter->hw; |
| 2762 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2763 | u64 tdba; |
| 2764 | u32 tdlen, tctl, tipg, tarc; |
| 2765 | u32 ipgr1, ipgr2; |
| 2766 | |
| 2767 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 2768 | tdba = tx_ring->dma; |
| 2769 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2770 | ew32(TDBAL, (tdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2771 | ew32(TDBAH, (tdba >> 32)); |
| 2772 | ew32(TDLEN, tdlen); |
| 2773 | ew32(TDH, 0); |
| 2774 | ew32(TDT, 0); |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 2775 | tx_ring->head = adapter->hw.hw_addr + E1000_TDH; |
| 2776 | tx_ring->tail = adapter->hw.hw_addr + E1000_TDT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2777 | |
| 2778 | /* Set the default values for the Tx Inter Packet Gap timer */ |
| 2779 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */ |
| 2780 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */ |
| 2781 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */ |
| 2782 | |
| 2783 | if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN) |
| 2784 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */ |
| 2785 | |
| 2786 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 2787 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
| 2788 | ew32(TIPG, tipg); |
| 2789 | |
| 2790 | /* Set the Tx Interrupt Delay register */ |
| 2791 | ew32(TIDV, adapter->tx_int_delay); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2792 | /* Tx irq moderation */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2793 | ew32(TADV, adapter->tx_abs_int_delay); |
| 2794 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2795 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 2796 | u32 txdctl = er32(TXDCTL(0)); |
| 2797 | txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH | |
| 2798 | E1000_TXDCTL_WTHRESH); |
| 2799 | /* |
| 2800 | * set up some performance related parameters to encourage the |
| 2801 | * hardware to use the bus more efficiently in bursts, depends |
| 2802 | * on the tx_int_delay to be enabled, |
| 2803 | * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time |
| 2804 | * hthresh = 1 ==> prefetch when one or more available |
| 2805 | * pthresh = 0x1f ==> prefetch if internal cache 31 or less |
| 2806 | * BEWARE: this seems to work but should be considered first if |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2807 | * there are Tx hangs or other Tx related bugs |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2808 | */ |
| 2809 | txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE; |
| 2810 | ew32(TXDCTL(0), txdctl); |
| 2811 | /* erratum work around: set txdctl the same for both queues */ |
| 2812 | ew32(TXDCTL(1), txdctl); |
| 2813 | } |
| 2814 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2815 | /* Program the Transmit Control Register */ |
| 2816 | tctl = er32(TCTL); |
| 2817 | tctl &= ~E1000_TCTL_CT; |
| 2818 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
| 2819 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 2820 | |
| 2821 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2822 | tarc = er32(TARC(0)); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2823 | /* |
| 2824 | * set the speed mode bit, we'll clear it if we're not at |
| 2825 | * gigabit link later |
| 2826 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2827 | #define SPEED_MODE_BIT (1 << 21) |
| 2828 | tarc |= SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2829 | ew32(TARC(0), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | /* errata: program both queues to unweighted RR */ |
| 2833 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2834 | tarc = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2835 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2836 | ew32(TARC(0), tarc); |
| 2837 | tarc = er32(TARC(1)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2838 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2839 | ew32(TARC(1), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2840 | } |
| 2841 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2842 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 2843 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 2844 | |
| 2845 | /* only set IDE if we are delaying interrupts using the timers */ |
| 2846 | if (adapter->tx_int_delay) |
| 2847 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
| 2848 | |
| 2849 | /* enable Report Status bit */ |
| 2850 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 2851 | |
| 2852 | ew32(TCTL, tctl); |
| 2853 | |
Simon Horman | edfea6e6 | 2009-06-08 14:28:36 +0000 | [diff] [blame] | 2854 | e1000e_config_collision_dist(hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | /** |
| 2858 | * e1000_setup_rctl - configure the receive control registers |
| 2859 | * @adapter: Board private structure |
| 2860 | **/ |
| 2861 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 2862 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
| 2863 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
| 2864 | { |
| 2865 | struct e1000_hw *hw = &adapter->hw; |
| 2866 | u32 rctl, rfctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2867 | u32 pages = 0; |
| 2868 | |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 2869 | /* Workaround Si errata on 82579 - configure jumbo frame flow */ |
| 2870 | if (hw->mac.type == e1000_pch2lan) { |
| 2871 | s32 ret_val; |
| 2872 | |
| 2873 | if (adapter->netdev->mtu > ETH_DATA_LEN) |
| 2874 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true); |
| 2875 | else |
| 2876 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false); |
Bruce Allan | dd93f95 | 2011-01-06 14:29:48 +0000 | [diff] [blame] | 2877 | |
| 2878 | if (ret_val) |
| 2879 | e_dbg("failed to enable jumbo frame workaround mode\n"); |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 2880 | } |
| 2881 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2882 | /* Program MC offset vector base */ |
| 2883 | rctl = er32(RCTL); |
| 2884 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 2885 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 2886 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 2887 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 2888 | |
| 2889 | /* Do not Store bad packets */ |
| 2890 | rctl &= ~E1000_RCTL_SBP; |
| 2891 | |
| 2892 | /* Enable Long Packet receive */ |
| 2893 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2894 | rctl &= ~E1000_RCTL_LPE; |
| 2895 | else |
| 2896 | rctl |= E1000_RCTL_LPE; |
| 2897 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 2898 | /* Some systems expect that the CRC is included in SMBUS traffic. The |
| 2899 | * hardware strips the CRC before sending to both SMBUS (BMC) and to |
| 2900 | * host memory when this is enabled |
| 2901 | */ |
| 2902 | if (adapter->flags2 & FLAG2_CRC_STRIPPING) |
| 2903 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 5918bd8 | 2008-02-12 15:20:24 -0800 | [diff] [blame] | 2904 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 2905 | /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ |
| 2906 | if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { |
| 2907 | u16 phy_data; |
| 2908 | |
| 2909 | e1e_rphy(hw, PHY_REG(770, 26), &phy_data); |
| 2910 | phy_data &= 0xfff8; |
| 2911 | phy_data |= (1 << 2); |
| 2912 | e1e_wphy(hw, PHY_REG(770, 26), phy_data); |
| 2913 | |
| 2914 | e1e_rphy(hw, 22, &phy_data); |
| 2915 | phy_data &= 0x0fff; |
| 2916 | phy_data |= (1 << 14); |
| 2917 | e1e_wphy(hw, 0x10, 0x2823); |
| 2918 | e1e_wphy(hw, 0x11, 0x0003); |
| 2919 | e1e_wphy(hw, 22, phy_data); |
| 2920 | } |
| 2921 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2922 | /* Setup buffer sizes */ |
| 2923 | rctl &= ~E1000_RCTL_SZ_4096; |
| 2924 | rctl |= E1000_RCTL_BSEX; |
| 2925 | switch (adapter->rx_buffer_len) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2926 | case 2048: |
| 2927 | default: |
| 2928 | rctl |= E1000_RCTL_SZ_2048; |
| 2929 | rctl &= ~E1000_RCTL_BSEX; |
| 2930 | break; |
| 2931 | case 4096: |
| 2932 | rctl |= E1000_RCTL_SZ_4096; |
| 2933 | break; |
| 2934 | case 8192: |
| 2935 | rctl |= E1000_RCTL_SZ_8192; |
| 2936 | break; |
| 2937 | case 16384: |
| 2938 | rctl |= E1000_RCTL_SZ_16384; |
| 2939 | break; |
| 2940 | } |
| 2941 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 2942 | /* Enable Extended Status in all Receive Descriptors */ |
| 2943 | rfctl = er32(RFCTL); |
| 2944 | rfctl |= E1000_RFCTL_EXTEN; |
| 2945 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2946 | /* |
| 2947 | * 82571 and greater support packet-split where the protocol |
| 2948 | * header is placed in skb->data and the packet data is |
| 2949 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 2950 | * In the case of a non-split, skb->data is linearly filled, |
| 2951 | * followed by the page buffers. Therefore, skb->data is |
| 2952 | * sized to hold the largest protocol header. |
| 2953 | * |
| 2954 | * allocations using alloc_page take too long for regular MTU |
| 2955 | * so only enable packet split for jumbo frames |
| 2956 | * |
| 2957 | * Using pages when the page size is greater than 16k wastes |
| 2958 | * a lot of memory, since we allocate 3 pages at all times |
| 2959 | * per packet. |
| 2960 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2961 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Bruce Allan | dbcb9fe | 2010-06-17 18:59:27 +0000 | [diff] [blame] | 2962 | if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) && |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2963 | (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2964 | adapter->rx_ps_pages = pages; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2965 | else |
| 2966 | adapter->rx_ps_pages = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2967 | |
| 2968 | if (adapter->rx_ps_pages) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 2969 | u32 psrctl = 0; |
| 2970 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2971 | /* |
| 2972 | * disable packet split support for IPv6 extension headers, |
| 2973 | * because some malformed IPv6 headers can hang the Rx |
| 2974 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2975 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
| 2976 | E1000_RFCTL_NEW_IPV6_EXT_DIS); |
| 2977 | |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 2978 | /* Enable Packet split descriptors */ |
| 2979 | rctl |= E1000_RCTL_DTYP_PS; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2980 | |
| 2981 | psrctl |= adapter->rx_ps_bsize0 >> |
| 2982 | E1000_PSRCTL_BSIZE0_SHIFT; |
| 2983 | |
| 2984 | switch (adapter->rx_ps_pages) { |
| 2985 | case 3: |
| 2986 | psrctl |= PAGE_SIZE << |
| 2987 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 2988 | case 2: |
| 2989 | psrctl |= PAGE_SIZE << |
| 2990 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 2991 | case 1: |
| 2992 | psrctl |= PAGE_SIZE >> |
| 2993 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 2994 | break; |
| 2995 | } |
| 2996 | |
| 2997 | ew32(PSRCTL, psrctl); |
| 2998 | } |
| 2999 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3000 | ew32(RFCTL, rfctl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3001 | ew32(RCTL, rctl); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3002 | /* just started the receive unit, no need to restart */ |
| 3003 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | /** |
| 3007 | * e1000_configure_rx - Configure Receive Unit after Reset |
| 3008 | * @adapter: board private structure |
| 3009 | * |
| 3010 | * Configure the Rx unit of the MAC after a reset. |
| 3011 | **/ |
| 3012 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
| 3013 | { |
| 3014 | struct e1000_hw *hw = &adapter->hw; |
| 3015 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 3016 | u64 rdba; |
| 3017 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
| 3018 | |
| 3019 | if (adapter->rx_ps_pages) { |
| 3020 | /* this is a 32 byte descriptor */ |
| 3021 | rdlen = rx_ring->count * |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3022 | sizeof(union e1000_rx_desc_packet_split); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3023 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 3024 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3025 | } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3026 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3027 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 3028 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3029 | } else { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3030 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3031 | adapter->clean_rx = e1000_clean_rx_irq; |
| 3032 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 3033 | } |
| 3034 | |
| 3035 | /* disable receives while setting up the descriptors */ |
| 3036 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3037 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3038 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3039 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3040 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3041 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3042 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 3043 | /* |
| 3044 | * set the writeback threshold (only takes effect if the RDTR |
| 3045 | * 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] | 3046 | * enable prefetching of 0x20 Rx descriptors |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3047 | * granularity = 01 |
| 3048 | * wthresh = 04, |
| 3049 | * hthresh = 04, |
| 3050 | * pthresh = 0x20 |
| 3051 | */ |
| 3052 | ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3053 | ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3054 | |
| 3055 | /* |
| 3056 | * override the delay timers for enabling bursting, only if |
| 3057 | * the value was not set by the user via module options |
| 3058 | */ |
| 3059 | if (adapter->rx_int_delay == DEFAULT_RDTR) |
| 3060 | adapter->rx_int_delay = BURST_RDTR; |
| 3061 | if (adapter->rx_abs_int_delay == DEFAULT_RADV) |
| 3062 | adapter->rx_abs_int_delay = BURST_RADV; |
| 3063 | } |
| 3064 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3065 | /* set the Receive Delay Timer Register */ |
| 3066 | ew32(RDTR, adapter->rx_int_delay); |
| 3067 | |
| 3068 | /* irq moderation */ |
| 3069 | ew32(RADV, adapter->rx_abs_int_delay); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3070 | if ((adapter->itr_setting != 0) && (adapter->itr != 0)) |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3071 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3072 | |
| 3073 | ctrl_ext = er32(CTRL_EXT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3074 | /* Auto-Mask interrupts upon ICR access */ |
| 3075 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 3076 | ew32(IAM, 0xffffffff); |
| 3077 | ew32(CTRL_EXT, ctrl_ext); |
| 3078 | e1e_flush(); |
| 3079 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3080 | /* |
| 3081 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3082 | * the Base and Length of the Rx Descriptor Ring |
| 3083 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3084 | rdba = rx_ring->dma; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3085 | ew32(RDBAL, (rdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3086 | ew32(RDBAH, (rdba >> 32)); |
| 3087 | ew32(RDLEN, rdlen); |
| 3088 | ew32(RDH, 0); |
| 3089 | ew32(RDT, 0); |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 3090 | rx_ring->head = adapter->hw.hw_addr + E1000_RDH; |
| 3091 | rx_ring->tail = adapter->hw.hw_addr + E1000_RDT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3092 | |
| 3093 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 3094 | rxcsum = er32(RXCSUM); |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 3095 | if (adapter->netdev->features & NETIF_F_RXCSUM) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3096 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 3097 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3098 | /* |
| 3099 | * IPv4 payload checksum for UDP fragments must be |
| 3100 | * used in conjunction with packet-split. |
| 3101 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3102 | if (adapter->rx_ps_pages) |
| 3103 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 3104 | } else { |
| 3105 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 3106 | /* no need to clear IPPCSE as it defaults to 0 */ |
| 3107 | } |
| 3108 | ew32(RXCSUM, rxcsum); |
| 3109 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3110 | /* |
| 3111 | * Enable early receives on supported devices, only takes effect when |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3112 | * 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] | 3113 | * units), e.g. using jumbo frames when setting to E1000_ERT_2048 |
| 3114 | */ |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3115 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 3116 | (adapter->hw.mac.type == e1000_pch2lan)) { |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3117 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3118 | u32 rxdctl = er32(RXDCTL(0)); |
| 3119 | ew32(RXDCTL(0), rxdctl | 0x3); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3120 | if (adapter->flags & FLAG_HAS_ERT) |
| 3121 | ew32(ERT, E1000_ERT_2048 | (1 << 13)); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3122 | /* |
| 3123 | * With jumbo frames and early-receive enabled, |
| 3124 | * excessive C-state transition latencies result in |
| 3125 | * dropped transactions. |
| 3126 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3127 | pm_qos_update_request(&adapter->netdev->pm_qos_req, 55); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3128 | } else { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3129 | pm_qos_update_request(&adapter->netdev->pm_qos_req, |
| 3130 | PM_QOS_DEFAULT_VALUE); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3131 | } |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3132 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3133 | |
| 3134 | /* Enable Receives */ |
| 3135 | ew32(RCTL, rctl); |
| 3136 | } |
| 3137 | |
| 3138 | /** |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3139 | * e1000e_write_mc_addr_list - write multicast addresses to MTA |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3140 | * @netdev: network interface device structure |
| 3141 | * |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3142 | * Writes multicast address list to the MTA hash table. |
| 3143 | * Returns: -ENOMEM on failure |
| 3144 | * 0 on no addresses written |
| 3145 | * X on writing X addresses to MTA |
| 3146 | */ |
| 3147 | static int e1000e_write_mc_addr_list(struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3148 | { |
| 3149 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3150 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3151 | struct netdev_hw_addr *ha; |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3152 | u8 *mta_list; |
| 3153 | int i; |
| 3154 | |
| 3155 | if (netdev_mc_empty(netdev)) { |
| 3156 | /* nothing to program, so clear mc list */ |
| 3157 | hw->mac.ops.update_mc_addr_list(hw, NULL, 0); |
| 3158 | return 0; |
| 3159 | } |
| 3160 | |
| 3161 | mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC); |
| 3162 | if (!mta_list) |
| 3163 | return -ENOMEM; |
| 3164 | |
| 3165 | /* update_mc_addr_list expects a packed array of only addresses. */ |
| 3166 | i = 0; |
| 3167 | netdev_for_each_mc_addr(ha, netdev) |
| 3168 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
| 3169 | |
| 3170 | hw->mac.ops.update_mc_addr_list(hw, mta_list, i); |
| 3171 | kfree(mta_list); |
| 3172 | |
| 3173 | return netdev_mc_count(netdev); |
| 3174 | } |
| 3175 | |
| 3176 | /** |
| 3177 | * e1000e_write_uc_addr_list - write unicast addresses to RAR table |
| 3178 | * @netdev: network interface device structure |
| 3179 | * |
| 3180 | * Writes unicast address list to the RAR table. |
| 3181 | * Returns: -ENOMEM on failure/insufficient address space |
| 3182 | * 0 on no addresses written |
| 3183 | * X on writing X addresses to the RAR table |
| 3184 | **/ |
| 3185 | static int e1000e_write_uc_addr_list(struct net_device *netdev) |
| 3186 | { |
| 3187 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3188 | struct e1000_hw *hw = &adapter->hw; |
| 3189 | unsigned int rar_entries = hw->mac.rar_entry_count; |
| 3190 | int count = 0; |
| 3191 | |
| 3192 | /* save a rar entry for our hardware address */ |
| 3193 | rar_entries--; |
| 3194 | |
| 3195 | /* save a rar entry for the LAA workaround */ |
| 3196 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) |
| 3197 | rar_entries--; |
| 3198 | |
| 3199 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3200 | if (netdev_uc_count(netdev) > rar_entries) |
| 3201 | return -ENOMEM; |
| 3202 | |
| 3203 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3204 | struct netdev_hw_addr *ha; |
| 3205 | |
| 3206 | /* |
| 3207 | * write the addresses in reverse order to avoid write |
| 3208 | * combining |
| 3209 | */ |
| 3210 | netdev_for_each_uc_addr(ha, netdev) { |
| 3211 | if (!rar_entries) |
| 3212 | break; |
| 3213 | e1000e_rar_set(hw, ha->addr, rar_entries--); |
| 3214 | count++; |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | /* zero out the remaining RAR entries not used above */ |
| 3219 | for (; rar_entries > 0; rar_entries--) { |
| 3220 | ew32(RAH(rar_entries), 0); |
| 3221 | ew32(RAL(rar_entries), 0); |
| 3222 | } |
| 3223 | e1e_flush(); |
| 3224 | |
| 3225 | return count; |
| 3226 | } |
| 3227 | |
| 3228 | /** |
| 3229 | * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set |
| 3230 | * @netdev: network interface device structure |
| 3231 | * |
| 3232 | * The ndo_set_rx_mode entry point is called whenever the unicast or multicast |
| 3233 | * address list or the network interface flags are updated. This routine is |
| 3234 | * responsible for configuring the hardware for proper unicast, multicast, |
| 3235 | * promiscuous mode, and all-multi behavior. |
| 3236 | **/ |
| 3237 | static void e1000e_set_rx_mode(struct net_device *netdev) |
| 3238 | { |
| 3239 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3240 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3241 | u32 rctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3242 | |
| 3243 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3244 | rctl = er32(RCTL); |
| 3245 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3246 | /* clear the affected bits */ |
| 3247 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 3248 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3249 | if (netdev->flags & IFF_PROMISC) { |
| 3250 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3251 | /* Do not hardware filter VLANs in promisc mode */ |
| 3252 | e1000e_vlan_filter_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3253 | } else { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3254 | int count; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3255 | if (netdev->flags & IFF_ALLMULTI) { |
| 3256 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3257 | } else { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3258 | /* |
| 3259 | * Write addresses to the MTA, if the attempt fails |
| 3260 | * then we should just turn on promiscuous mode so |
| 3261 | * that we can at least receive multicast traffic |
| 3262 | */ |
| 3263 | count = e1000e_write_mc_addr_list(netdev); |
| 3264 | if (count < 0) |
| 3265 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3266 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3267 | e1000e_vlan_filter_enable(adapter); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3268 | /* |
| 3269 | * Write addresses to available RAR registers, if there is not |
| 3270 | * sufficient space to store all the addresses then enable |
| 3271 | * unicast promiscuous mode |
| 3272 | */ |
| 3273 | count = e1000e_write_uc_addr_list(netdev); |
| 3274 | if (count < 0) |
| 3275 | rctl |= E1000_RCTL_UPE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | ew32(RCTL, rctl); |
| 3279 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3280 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3281 | e1000e_vlan_strip_enable(adapter); |
| 3282 | else |
| 3283 | e1000e_vlan_strip_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3286 | static void e1000e_setup_rss_hash(struct e1000_adapter *adapter) |
| 3287 | { |
| 3288 | struct e1000_hw *hw = &adapter->hw; |
| 3289 | u32 mrqc, rxcsum; |
| 3290 | int i; |
| 3291 | static const u32 rsskey[10] = { |
| 3292 | 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0, |
| 3293 | 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe |
| 3294 | }; |
| 3295 | |
| 3296 | /* Fill out hash function seed */ |
| 3297 | for (i = 0; i < 10; i++) |
| 3298 | ew32(RSSRK(i), rsskey[i]); |
| 3299 | |
| 3300 | /* Direct all traffic to queue 0 */ |
| 3301 | for (i = 0; i < 32; i++) |
| 3302 | ew32(RETA(i), 0); |
| 3303 | |
| 3304 | /* |
| 3305 | * Disable raw packet checksumming so that RSS hash is placed in |
| 3306 | * descriptor on writeback. |
| 3307 | */ |
| 3308 | rxcsum = er32(RXCSUM); |
| 3309 | rxcsum |= E1000_RXCSUM_PCSD; |
| 3310 | |
| 3311 | ew32(RXCSUM, rxcsum); |
| 3312 | |
| 3313 | mrqc = (E1000_MRQC_RSS_FIELD_IPV4 | |
| 3314 | E1000_MRQC_RSS_FIELD_IPV4_TCP | |
| 3315 | E1000_MRQC_RSS_FIELD_IPV6 | |
| 3316 | E1000_MRQC_RSS_FIELD_IPV6_TCP | |
| 3317 | E1000_MRQC_RSS_FIELD_IPV6_TCP_EX); |
| 3318 | |
| 3319 | ew32(MRQC, mrqc); |
| 3320 | } |
| 3321 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3322 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3323 | * e1000_configure - configure the hardware for Rx and Tx |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3324 | * @adapter: private board structure |
| 3325 | **/ |
| 3326 | static void e1000_configure(struct e1000_adapter *adapter) |
| 3327 | { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3328 | e1000e_set_rx_mode(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3329 | |
| 3330 | e1000_restore_vlan(adapter); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 3331 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3332 | |
| 3333 | e1000_configure_tx(adapter); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3334 | |
| 3335 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 3336 | e1000e_setup_rss_hash(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3337 | e1000_setup_rctl(adapter); |
| 3338 | e1000_configure_rx(adapter); |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 3339 | adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring), |
| 3340 | GFP_KERNEL); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | /** |
| 3344 | * e1000e_power_up_phy - restore link in case the phy was powered down |
| 3345 | * @adapter: address of board private structure |
| 3346 | * |
| 3347 | * The phy may be powered down to save power and turn off link when the |
| 3348 | * driver is unloaded and wake on lan is not enabled (among others) |
| 3349 | * *** this routine MUST be followed by a call to e1000e_reset *** |
| 3350 | **/ |
| 3351 | void e1000e_power_up_phy(struct e1000_adapter *adapter) |
| 3352 | { |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3353 | if (adapter->hw.phy.ops.power_up) |
| 3354 | adapter->hw.phy.ops.power_up(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3355 | |
| 3356 | adapter->hw.mac.ops.setup_link(&adapter->hw); |
| 3357 | } |
| 3358 | |
| 3359 | /** |
| 3360 | * e1000_power_down_phy - Power down the PHY |
| 3361 | * |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3362 | * Power down the PHY so no link is implied when interface is down. |
| 3363 | * The PHY cannot be powered down if management or WoL is active. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3364 | */ |
| 3365 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 3366 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3367 | /* WoL is enabled */ |
Auke Kok | 23b66e2 | 2008-02-11 09:25:51 -0800 | [diff] [blame] | 3368 | if (adapter->wol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3369 | return; |
| 3370 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3371 | if (adapter->hw.phy.ops.power_down) |
| 3372 | adapter->hw.phy.ops.power_down(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | /** |
| 3376 | * e1000e_reset - bring the hardware into a known good state |
| 3377 | * |
| 3378 | * This function boots the hardware and enables some settings that |
| 3379 | * require a configuration cycle of the hardware - those cannot be |
| 3380 | * set/changed during runtime. After reset the device needs to be |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3381 | * properly configured for Rx, Tx etc. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3382 | */ |
| 3383 | void e1000e_reset(struct e1000_adapter *adapter) |
| 3384 | { |
| 3385 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3386 | struct e1000_fc_info *fc = &adapter->hw.fc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3387 | struct e1000_hw *hw = &adapter->hw; |
| 3388 | u32 tx_space, min_tx_space, min_rx_space; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3389 | u32 pba = adapter->pba; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3390 | u16 hwm; |
| 3391 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3392 | /* reset Packet Buffer Allocation to default */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3393 | ew32(PBA, pba); |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3394 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3395 | if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3396 | /* |
| 3397 | * To maintain wire speed transmits, the Tx FIFO should be |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3398 | * large enough to accommodate two full transmit packets, |
| 3399 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 3400 | * the Rx FIFO should be large enough to accommodate at least |
| 3401 | * one full receive packet and is similarly rounded up and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3402 | * expressed in KB. |
| 3403 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3404 | pba = er32(PBA); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3405 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3406 | tx_space = pba >> 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3407 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3408 | pba &= 0xffff; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3409 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3410 | * the Tx fifo also stores 16 bytes of information about the Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3411 | * but don't include ethernet FCS because hardware appends it |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3412 | */ |
| 3413 | min_tx_space = (adapter->max_frame_size + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3414 | sizeof(struct e1000_tx_desc) - |
| 3415 | ETH_FCS_LEN) * 2; |
| 3416 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 3417 | min_tx_space >>= 10; |
| 3418 | /* software strips receive CRC, so leave room for it */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3419 | min_rx_space = adapter->max_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3420 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 3421 | min_rx_space >>= 10; |
| 3422 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3423 | /* |
| 3424 | * If current Tx allocation is less than the min Tx FIFO size, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3425 | * 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] | 3426 | * allocation, take space away from current Rx allocation |
| 3427 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3428 | if ((tx_space < min_tx_space) && |
| 3429 | ((min_tx_space - tx_space) < pba)) { |
| 3430 | pba -= min_tx_space - tx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3431 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3432 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3433 | * if short on Rx space, Rx wins and must trump Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3434 | * adjustment or use Early Receive if available |
| 3435 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3436 | if ((pba < min_rx_space) && |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3437 | (!(adapter->flags & FLAG_HAS_ERT))) |
| 3438 | /* ERT enabled in e1000_configure_rx */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3439 | pba = min_rx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3440 | } |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3441 | |
| 3442 | ew32(PBA, pba); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3443 | } |
| 3444 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3445 | /* |
| 3446 | * flow control settings |
| 3447 | * |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3448 | * 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] | 3449 | * (or the size used for early receive) above it in the Rx FIFO. |
| 3450 | * Set it to the lower of: |
| 3451 | * - 90% of the Rx FIFO size, and |
| 3452 | * - the full Rx FIFO size minus the early receive size (for parts |
| 3453 | * with ERT support assuming ERT set to E1000_ERT_2048), or |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3454 | * - the full Rx FIFO size minus one full frame |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3455 | */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3456 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
| 3457 | fc->pause_time = 0xFFFF; |
| 3458 | else |
| 3459 | fc->pause_time = E1000_FC_PAUSE_TIME; |
| 3460 | fc->send_xon = 1; |
| 3461 | fc->current_mode = fc->requested_mode; |
| 3462 | |
| 3463 | switch (hw->mac.type) { |
| 3464 | default: |
| 3465 | if ((adapter->flags & FLAG_HAS_ERT) && |
| 3466 | (adapter->netdev->mtu > ETH_DATA_LEN)) |
| 3467 | hwm = min(((pba << 10) * 9 / 10), |
| 3468 | ((pba << 10) - (E1000_ERT_2048 << 3))); |
| 3469 | else |
| 3470 | hwm = min(((pba << 10) * 9 / 10), |
| 3471 | ((pba << 10) - adapter->max_frame_size)); |
| 3472 | |
| 3473 | fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ |
| 3474 | fc->low_water = fc->high_water - 8; |
| 3475 | break; |
| 3476 | case e1000_pchlan: |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3477 | /* |
| 3478 | * Workaround PCH LOM adapter hangs with certain network |
| 3479 | * loads. If hangs persist, try disabling Tx flow control. |
| 3480 | */ |
| 3481 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3482 | fc->high_water = 0x3500; |
| 3483 | fc->low_water = 0x1500; |
| 3484 | } else { |
| 3485 | fc->high_water = 0x5000; |
| 3486 | fc->low_water = 0x3000; |
| 3487 | } |
Bruce Allan | a305595 | 2010-05-10 15:02:12 +0000 | [diff] [blame] | 3488 | fc->refresh_time = 0x1000; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3489 | break; |
| 3490 | case e1000_pch2lan: |
| 3491 | fc->high_water = 0x05C20; |
| 3492 | fc->low_water = 0x05048; |
| 3493 | fc->pause_time = 0x0650; |
| 3494 | fc->refresh_time = 0x0400; |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3495 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3496 | pba = 14; |
| 3497 | ew32(PBA, pba); |
| 3498 | } |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3499 | break; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3500 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3501 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3502 | /* |
| 3503 | * Disable Adaptive Interrupt Moderation if 2 full packets cannot |
| 3504 | * fit in receive buffer and early-receive not supported. |
| 3505 | */ |
| 3506 | if (adapter->itr_setting & 0x3) { |
| 3507 | if (((adapter->max_frame_size * 2) > (pba << 10)) && |
| 3508 | !(adapter->flags & FLAG_HAS_ERT)) { |
| 3509 | if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) { |
| 3510 | dev_info(&adapter->pdev->dev, |
| 3511 | "Interrupt Throttle Rate turned off\n"); |
| 3512 | adapter->flags2 |= FLAG2_DISABLE_AIM; |
| 3513 | ew32(ITR, 0); |
| 3514 | } |
| 3515 | } else if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 3516 | dev_info(&adapter->pdev->dev, |
| 3517 | "Interrupt Throttle Rate turned on\n"); |
| 3518 | adapter->flags2 &= ~FLAG2_DISABLE_AIM; |
| 3519 | adapter->itr = 20000; |
| 3520 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
| 3521 | } |
| 3522 | } |
| 3523 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3524 | /* Allow time for pending master requests to run */ |
| 3525 | mac->ops.reset_hw(hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3526 | |
| 3527 | /* |
| 3528 | * For parts with AMT enabled, let the firmware know |
| 3529 | * that the network interface is in control |
| 3530 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 3531 | if (adapter->flags & FLAG_HAS_AMT) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3532 | e1000e_get_hw_control(adapter); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3533 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3534 | ew32(WUC, 0); |
| 3535 | |
| 3536 | if (mac->ops.init_hw(hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 3537 | e_err("Hardware Error\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3538 | |
| 3539 | e1000_update_mng_vlan(adapter); |
| 3540 | |
| 3541 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 3542 | ew32(VET, ETH_P_8021Q); |
| 3543 | |
| 3544 | e1000e_reset_adaptive(hw); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3545 | |
| 3546 | if (!netif_running(adapter->netdev) && |
| 3547 | !test_bit(__E1000_TESTING, &adapter->state)) { |
| 3548 | e1000_power_down_phy(adapter); |
| 3549 | return; |
| 3550 | } |
| 3551 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3552 | e1000_get_phy_info(hw); |
| 3553 | |
Bruce Allan | 918d719 | 2009-06-02 11:28:20 +0000 | [diff] [blame] | 3554 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && |
| 3555 | !(adapter->flags & FLAG_SMART_POWER_DOWN)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3556 | u16 phy_data = 0; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3557 | /* |
| 3558 | * speed up time to link by disabling smart power down, ignore |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3559 | * the return value of this function because there is nothing |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3560 | * different we would do if it failed |
| 3561 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3562 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
| 3563 | phy_data &= ~IGP02E1000_PM_SPD; |
| 3564 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 3565 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | int e1000e_up(struct e1000_adapter *adapter) |
| 3569 | { |
| 3570 | struct e1000_hw *hw = &adapter->hw; |
| 3571 | |
| 3572 | /* hardware has been reset, we need to reload some things */ |
| 3573 | e1000_configure(adapter); |
| 3574 | |
| 3575 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3576 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3577 | if (adapter->msix_entries) |
| 3578 | e1000_configure_msix(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3579 | e1000_irq_enable(adapter); |
| 3580 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 3581 | netif_start_queue(adapter->netdev); |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3582 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3583 | /* fire a link change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3584 | if (adapter->msix_entries) |
| 3585 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3586 | else |
| 3587 | ew32(ICS, E1000_ICS_LSC); |
| 3588 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3589 | return 0; |
| 3590 | } |
| 3591 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3592 | static void e1000e_flush_descriptors(struct e1000_adapter *adapter) |
| 3593 | { |
| 3594 | struct e1000_hw *hw = &adapter->hw; |
| 3595 | |
| 3596 | if (!(adapter->flags2 & FLAG2_DMA_BURST)) |
| 3597 | return; |
| 3598 | |
| 3599 | /* flush pending descriptor writebacks to memory */ |
| 3600 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 3601 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 3602 | |
| 3603 | /* execute the writes immediately */ |
| 3604 | e1e_flush(); |
| 3605 | } |
| 3606 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3607 | static void e1000e_update_stats(struct e1000_adapter *adapter); |
| 3608 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3609 | void e1000e_down(struct e1000_adapter *adapter) |
| 3610 | { |
| 3611 | struct net_device *netdev = adapter->netdev; |
| 3612 | struct e1000_hw *hw = &adapter->hw; |
| 3613 | u32 tctl, rctl; |
| 3614 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3615 | /* |
| 3616 | * signal that we're down so the interrupt handler does not |
| 3617 | * reschedule our watchdog timer |
| 3618 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3619 | set_bit(__E1000_DOWN, &adapter->state); |
| 3620 | |
| 3621 | /* disable receives in the hardware */ |
| 3622 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3623 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3624 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3625 | /* flush and sleep below */ |
| 3626 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3627 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3628 | |
| 3629 | /* disable transmits in the hardware */ |
| 3630 | tctl = er32(TCTL); |
| 3631 | tctl &= ~E1000_TCTL_EN; |
| 3632 | ew32(TCTL, tctl); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3633 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3634 | /* flush both disables and wait for them to finish */ |
| 3635 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3636 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3637 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3638 | e1000_irq_disable(adapter); |
| 3639 | |
| 3640 | del_timer_sync(&adapter->watchdog_timer); |
| 3641 | del_timer_sync(&adapter->phy_info_timer); |
| 3642 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3643 | netif_carrier_off(netdev); |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3644 | |
| 3645 | spin_lock(&adapter->stats64_lock); |
| 3646 | e1000e_update_stats(adapter); |
| 3647 | spin_unlock(&adapter->stats64_lock); |
| 3648 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 3649 | e1000e_flush_descriptors(adapter); |
| 3650 | e1000_clean_tx_ring(adapter); |
| 3651 | e1000_clean_rx_ring(adapter); |
| 3652 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3653 | adapter->link_speed = 0; |
| 3654 | adapter->link_duplex = 0; |
| 3655 | |
Jeff Kirsher | 52cc308 | 2008-06-24 17:01:29 -0700 | [diff] [blame] | 3656 | if (!pci_channel_offline(adapter->pdev)) |
| 3657 | e1000e_reset(adapter); |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3658 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3659 | /* |
| 3660 | * TODO: for power management, we could drop the link and |
| 3661 | * pci_disable_device here. |
| 3662 | */ |
| 3663 | } |
| 3664 | |
| 3665 | void e1000e_reinit_locked(struct e1000_adapter *adapter) |
| 3666 | { |
| 3667 | might_sleep(); |
| 3668 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3669 | usleep_range(1000, 2000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3670 | e1000e_down(adapter); |
| 3671 | e1000e_up(adapter); |
| 3672 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 3673 | } |
| 3674 | |
| 3675 | /** |
| 3676 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 3677 | * @adapter: board private structure to initialize |
| 3678 | * |
| 3679 | * e1000_sw_init initializes the Adapter private data structure. |
| 3680 | * Fields are initialized based on PCI device information and |
| 3681 | * OS network device settings (MTU size). |
| 3682 | **/ |
| 3683 | static int __devinit e1000_sw_init(struct e1000_adapter *adapter) |
| 3684 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3685 | struct net_device *netdev = adapter->netdev; |
| 3686 | |
| 3687 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN; |
| 3688 | adapter->rx_ps_bsize0 = 128; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3689 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3690 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3691 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3692 | spin_lock_init(&adapter->stats64_lock); |
| 3693 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3694 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3695 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3696 | if (e1000_alloc_queues(adapter)) |
| 3697 | return -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3698 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3699 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3700 | e1000_irq_disable(adapter); |
| 3701 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3702 | set_bit(__E1000_DOWN, &adapter->state); |
| 3703 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | /** |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3707 | * e1000_intr_msi_test - Interrupt Handler |
| 3708 | * @irq: interrupt number |
| 3709 | * @data: pointer to a network interface device structure |
| 3710 | **/ |
| 3711 | static irqreturn_t e1000_intr_msi_test(int irq, void *data) |
| 3712 | { |
| 3713 | struct net_device *netdev = data; |
| 3714 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3715 | struct e1000_hw *hw = &adapter->hw; |
| 3716 | u32 icr = er32(ICR); |
| 3717 | |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 3718 | e_dbg("icr is %08X\n", icr); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3719 | if (icr & E1000_ICR_RXSEQ) { |
| 3720 | adapter->flags &= ~FLAG_MSI_TEST_FAILED; |
| 3721 | wmb(); |
| 3722 | } |
| 3723 | |
| 3724 | return IRQ_HANDLED; |
| 3725 | } |
| 3726 | |
| 3727 | /** |
| 3728 | * e1000_test_msi_interrupt - Returns 0 for successful test |
| 3729 | * @adapter: board private struct |
| 3730 | * |
| 3731 | * code flow taken from tg3.c |
| 3732 | **/ |
| 3733 | static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) |
| 3734 | { |
| 3735 | struct net_device *netdev = adapter->netdev; |
| 3736 | struct e1000_hw *hw = &adapter->hw; |
| 3737 | int err; |
| 3738 | |
| 3739 | /* poll_enable hasn't been called yet, so don't need disable */ |
| 3740 | /* clear any pending events */ |
| 3741 | er32(ICR); |
| 3742 | |
| 3743 | /* free the real vector and request a test handler */ |
| 3744 | e1000_free_irq(adapter); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3745 | e1000e_reset_interrupt_capability(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3746 | |
| 3747 | /* Assume that the test fails, if it succeeds then the test |
| 3748 | * MSI irq handler will unset this flag */ |
| 3749 | adapter->flags |= FLAG_MSI_TEST_FAILED; |
| 3750 | |
| 3751 | err = pci_enable_msi(adapter->pdev); |
| 3752 | if (err) |
| 3753 | goto msi_test_failed; |
| 3754 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3755 | err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3756 | netdev->name, netdev); |
| 3757 | if (err) { |
| 3758 | pci_disable_msi(adapter->pdev); |
| 3759 | goto msi_test_failed; |
| 3760 | } |
| 3761 | |
| 3762 | wmb(); |
| 3763 | |
| 3764 | e1000_irq_enable(adapter); |
| 3765 | |
| 3766 | /* fire an unusual interrupt on the test handler */ |
| 3767 | ew32(ICS, E1000_ICS_RXSEQ); |
| 3768 | e1e_flush(); |
| 3769 | msleep(50); |
| 3770 | |
| 3771 | e1000_irq_disable(adapter); |
| 3772 | |
| 3773 | rmb(); |
| 3774 | |
| 3775 | if (adapter->flags & FLAG_MSI_TEST_FAILED) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3776 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 3777 | e_info("MSI interrupt test failed, using legacy interrupt.\n"); |
| 3778 | } else |
| 3779 | e_dbg("MSI interrupt test succeeded!\n"); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3780 | |
| 3781 | free_irq(adapter->pdev->irq, netdev); |
| 3782 | pci_disable_msi(adapter->pdev); |
| 3783 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3784 | msi_test_failed: |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3785 | e1000e_set_interrupt_capability(adapter); |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 3786 | return e1000_request_irq(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | /** |
| 3790 | * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored |
| 3791 | * @adapter: board private struct |
| 3792 | * |
| 3793 | * code flow taken from tg3.c, called with e1000 interrupts disabled. |
| 3794 | **/ |
| 3795 | static int e1000_test_msi(struct e1000_adapter *adapter) |
| 3796 | { |
| 3797 | int err; |
| 3798 | u16 pci_cmd; |
| 3799 | |
| 3800 | if (!(adapter->flags & FLAG_MSI_ENABLED)) |
| 3801 | return 0; |
| 3802 | |
| 3803 | /* disable SERR in case the MSI write causes a master abort */ |
| 3804 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 3805 | if (pci_cmd & PCI_COMMAND_SERR) |
| 3806 | pci_write_config_word(adapter->pdev, PCI_COMMAND, |
| 3807 | pci_cmd & ~PCI_COMMAND_SERR); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3808 | |
| 3809 | err = e1000_test_msi_interrupt(adapter); |
| 3810 | |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 3811 | /* re-enable SERR */ |
| 3812 | if (pci_cmd & PCI_COMMAND_SERR) { |
| 3813 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
| 3814 | pci_cmd |= PCI_COMMAND_SERR; |
| 3815 | pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); |
| 3816 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3817 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3818 | return err; |
| 3819 | } |
| 3820 | |
| 3821 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3822 | * e1000_open - Called when a network interface is made active |
| 3823 | * @netdev: network interface device structure |
| 3824 | * |
| 3825 | * Returns 0 on success, negative value on failure |
| 3826 | * |
| 3827 | * The open entry point is called when a network interface is made |
| 3828 | * active by the system (IFF_UP). At this point all resources needed |
| 3829 | * for transmit and receive operations are allocated, the interrupt |
| 3830 | * handler is registered with the OS, the watchdog timer is started, |
| 3831 | * and the stack is notified that the interface is ready. |
| 3832 | **/ |
| 3833 | static int e1000_open(struct net_device *netdev) |
| 3834 | { |
| 3835 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3836 | struct e1000_hw *hw = &adapter->hw; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3837 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3838 | int err; |
| 3839 | |
| 3840 | /* disallow open during test */ |
| 3841 | if (test_bit(__E1000_TESTING, &adapter->state)) |
| 3842 | return -EBUSY; |
| 3843 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3844 | pm_runtime_get_sync(&pdev->dev); |
| 3845 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 3846 | netif_carrier_off(netdev); |
| 3847 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3848 | /* allocate transmit descriptors */ |
| 3849 | err = e1000e_setup_tx_resources(adapter); |
| 3850 | if (err) |
| 3851 | goto err_setup_tx; |
| 3852 | |
| 3853 | /* allocate receive descriptors */ |
| 3854 | err = e1000e_setup_rx_resources(adapter); |
| 3855 | if (err) |
| 3856 | goto err_setup_rx; |
| 3857 | |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 3858 | /* |
| 3859 | * If AMT is enabled, let the firmware know that the network |
| 3860 | * interface is now open and reset the part to a known state. |
| 3861 | */ |
| 3862 | if (adapter->flags & FLAG_HAS_AMT) { |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3863 | e1000e_get_hw_control(adapter); |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 3864 | e1000e_reset(adapter); |
| 3865 | } |
| 3866 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3867 | e1000e_power_up_phy(adapter); |
| 3868 | |
| 3869 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 3870 | if ((adapter->hw.mng_cookie.status & |
| 3871 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
| 3872 | e1000_update_mng_vlan(adapter); |
| 3873 | |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3874 | /* DMA latency requirement to workaround early-receive/jumbo issue */ |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3875 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 3876 | (adapter->hw.mac.type == e1000_pch2lan)) |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 3877 | pm_qos_add_request(&adapter->netdev->pm_qos_req, |
| 3878 | PM_QOS_CPU_DMA_LATENCY, |
| 3879 | PM_QOS_DEFAULT_VALUE); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3880 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3881 | /* |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3882 | * before we allocate an interrupt, we must be ready to handle it. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3883 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 3884 | * 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] | 3885 | * clean_rx handler before we do so. |
| 3886 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3887 | e1000_configure(adapter); |
| 3888 | |
| 3889 | err = e1000_request_irq(adapter); |
| 3890 | if (err) |
| 3891 | goto err_req_irq; |
| 3892 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3893 | /* |
| 3894 | * Work around PCIe errata with MSI interrupts causing some chipsets to |
| 3895 | * ignore e1000e MSI messages, which means we need to test our MSI |
| 3896 | * interrupt now |
| 3897 | */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3898 | if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3899 | err = e1000_test_msi(adapter); |
| 3900 | if (err) { |
| 3901 | e_err("Interrupt allocation failed\n"); |
| 3902 | goto err_req_irq; |
| 3903 | } |
| 3904 | } |
| 3905 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3906 | /* From here on the code is the same as e1000e_up() */ |
| 3907 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3908 | |
| 3909 | napi_enable(&adapter->napi); |
| 3910 | |
| 3911 | e1000_irq_enable(adapter); |
| 3912 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 3913 | adapter->tx_hang_recheck = false; |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3914 | netif_start_queue(netdev); |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 3915 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3916 | adapter->idle_check = true; |
| 3917 | pm_runtime_put(&pdev->dev); |
| 3918 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3919 | /* fire a link status change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3920 | if (adapter->msix_entries) |
| 3921 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3922 | else |
| 3923 | ew32(ICS, E1000_ICS_LSC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3924 | |
| 3925 | return 0; |
| 3926 | |
| 3927 | err_req_irq: |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3928 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3929 | e1000_power_down_phy(adapter); |
| 3930 | e1000e_free_rx_resources(adapter); |
| 3931 | err_setup_rx: |
| 3932 | e1000e_free_tx_resources(adapter); |
| 3933 | err_setup_tx: |
| 3934 | e1000e_reset(adapter); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3935 | pm_runtime_put_sync(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3936 | |
| 3937 | return err; |
| 3938 | } |
| 3939 | |
| 3940 | /** |
| 3941 | * e1000_close - Disables a network interface |
| 3942 | * @netdev: network interface device structure |
| 3943 | * |
| 3944 | * Returns 0, this is not allowed to fail |
| 3945 | * |
| 3946 | * The close entry point is called when an interface is de-activated |
| 3947 | * by the OS. The hardware is still under the drivers control, but |
| 3948 | * needs to be disabled. A global MAC reset is issued to stop the |
| 3949 | * hardware, and all transmit and receive resources are freed. |
| 3950 | **/ |
| 3951 | static int e1000_close(struct net_device *netdev) |
| 3952 | { |
| 3953 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3954 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3955 | |
| 3956 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3957 | |
| 3958 | pm_runtime_get_sync(&pdev->dev); |
| 3959 | |
Bruce Allan | 5f4a780 | 2011-11-29 08:09:19 +0000 | [diff] [blame] | 3960 | napi_disable(&adapter->napi); |
| 3961 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3962 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 3963 | e1000e_down(adapter); |
| 3964 | e1000_free_irq(adapter); |
| 3965 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3966 | e1000_power_down_phy(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3967 | |
| 3968 | e1000e_free_tx_resources(adapter); |
| 3969 | e1000e_free_rx_resources(adapter); |
| 3970 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3971 | /* |
| 3972 | * kill manageability vlan ID if supported, but not if a vlan with |
| 3973 | * the same ID is registered on the host OS (let 8021q kill it) |
| 3974 | */ |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3975 | if (adapter->hw.mng_cookie.status & |
| 3976 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3977 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 3978 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3979 | /* |
| 3980 | * If AMT is enabled, let the firmware know that the network |
| 3981 | * interface is now closed |
| 3982 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3983 | if ((adapter->flags & FLAG_HAS_AMT) && |
| 3984 | !test_bit(__E1000_TESTING, &adapter->state)) |
| 3985 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3986 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3987 | if ((adapter->flags & FLAG_HAS_ERT) || |
| 3988 | (adapter->hw.mac.type == e1000_pch2lan)) |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 3989 | pm_qos_remove_request(&adapter->netdev->pm_qos_req); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3990 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3991 | pm_runtime_put_sync(&pdev->dev); |
| 3992 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3993 | return 0; |
| 3994 | } |
| 3995 | /** |
| 3996 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 3997 | * @netdev: network interface device structure |
| 3998 | * @p: pointer to an address structure |
| 3999 | * |
| 4000 | * Returns 0 on success, negative on failure |
| 4001 | **/ |
| 4002 | static int e1000_set_mac(struct net_device *netdev, void *p) |
| 4003 | { |
| 4004 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4005 | struct sockaddr *addr = p; |
| 4006 | |
| 4007 | if (!is_valid_ether_addr(addr->sa_data)) |
| 4008 | return -EADDRNOTAVAIL; |
| 4009 | |
| 4010 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 4011 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 4012 | |
| 4013 | e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0); |
| 4014 | |
| 4015 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { |
| 4016 | /* activate the work around */ |
| 4017 | e1000e_set_laa_state_82571(&adapter->hw, 1); |
| 4018 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4019 | /* |
| 4020 | * 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] | 4021 | * between the time RAR[0] gets clobbered and the time it |
| 4022 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
| 4023 | * of the RARs and no incoming packets directed to this port |
| 4024 | * are dropped. Eventually the LAA will be in RAR[0] and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4025 | * RAR[14] |
| 4026 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4027 | e1000e_rar_set(&adapter->hw, |
| 4028 | adapter->hw.mac.addr, |
| 4029 | adapter->hw.mac.rar_entry_count - 1); |
| 4030 | } |
| 4031 | |
| 4032 | return 0; |
| 4033 | } |
| 4034 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4035 | /** |
| 4036 | * e1000e_update_phy_task - work thread to update phy |
| 4037 | * @work: pointer to our work struct |
| 4038 | * |
| 4039 | * this worker thread exists because we must acquire a |
| 4040 | * semaphore to read the phy, which we could msleep while |
| 4041 | * waiting for it, and we can't msleep in a timer. |
| 4042 | **/ |
| 4043 | static void e1000e_update_phy_task(struct work_struct *work) |
| 4044 | { |
| 4045 | struct e1000_adapter *adapter = container_of(work, |
| 4046 | struct e1000_adapter, update_phy_task); |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4047 | |
| 4048 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4049 | return; |
| 4050 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4051 | e1000_get_phy_info(&adapter->hw); |
| 4052 | } |
| 4053 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4054 | /* |
| 4055 | * Need to wait a few seconds after link up to get diagnostic information from |
| 4056 | * the phy |
| 4057 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4058 | static void e1000_update_phy_info(unsigned long data) |
| 4059 | { |
| 4060 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4061 | |
| 4062 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4063 | return; |
| 4064 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4065 | schedule_work(&adapter->update_phy_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | /** |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4069 | * e1000e_update_phy_stats - Update the PHY statistics counters |
| 4070 | * @adapter: board private structure |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4071 | * |
| 4072 | * Read/clear the upper 16-bit PHY registers and read/accumulate lower |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4073 | **/ |
| 4074 | static void e1000e_update_phy_stats(struct e1000_adapter *adapter) |
| 4075 | { |
| 4076 | struct e1000_hw *hw = &adapter->hw; |
| 4077 | s32 ret_val; |
| 4078 | u16 phy_data; |
| 4079 | |
| 4080 | ret_val = hw->phy.ops.acquire(hw); |
| 4081 | if (ret_val) |
| 4082 | return; |
| 4083 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4084 | /* |
| 4085 | * A page set is expensive so check if already on desired page. |
| 4086 | * If not, set to the page with the PHY status registers. |
| 4087 | */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4088 | hw->phy.addr = 1; |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4089 | ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 4090 | &phy_data); |
| 4091 | if (ret_val) |
| 4092 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4093 | if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) { |
| 4094 | ret_val = hw->phy.ops.set_page(hw, |
| 4095 | HV_STATS_PAGE << IGP_PAGE_SHIFT); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4096 | if (ret_val) |
| 4097 | goto release; |
| 4098 | } |
| 4099 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4100 | /* Single Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4101 | hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data); |
| 4102 | 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] | 4103 | if (!ret_val) |
| 4104 | adapter->stats.scc += phy_data; |
| 4105 | |
| 4106 | /* Excessive Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4107 | hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data); |
| 4108 | 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] | 4109 | if (!ret_val) |
| 4110 | adapter->stats.ecol += phy_data; |
| 4111 | |
| 4112 | /* Multiple Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4113 | hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data); |
| 4114 | 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] | 4115 | if (!ret_val) |
| 4116 | adapter->stats.mcc += phy_data; |
| 4117 | |
| 4118 | /* Late Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4119 | hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data); |
| 4120 | 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] | 4121 | if (!ret_val) |
| 4122 | adapter->stats.latecol += phy_data; |
| 4123 | |
| 4124 | /* Collision Count - also used for adaptive IFS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4125 | hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data); |
| 4126 | 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] | 4127 | if (!ret_val) |
| 4128 | hw->mac.collision_delta = phy_data; |
| 4129 | |
| 4130 | /* Defer Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4131 | hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data); |
| 4132 | 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] | 4133 | if (!ret_val) |
| 4134 | adapter->stats.dc += phy_data; |
| 4135 | |
| 4136 | /* Transmit with no CRS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4137 | hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data); |
| 4138 | 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] | 4139 | if (!ret_val) |
| 4140 | adapter->stats.tncrs += phy_data; |
| 4141 | |
| 4142 | release: |
| 4143 | hw->phy.ops.release(hw); |
| 4144 | } |
| 4145 | |
| 4146 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4147 | * e1000e_update_stats - Update the board statistics counters |
| 4148 | * @adapter: board private structure |
| 4149 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4150 | static void e1000e_update_stats(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4151 | { |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4152 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4153 | struct e1000_hw *hw = &adapter->hw; |
| 4154 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4155 | |
| 4156 | /* |
| 4157 | * Prevent stats update while adapter is being reset, or if the pci |
| 4158 | * connection is down. |
| 4159 | */ |
| 4160 | if (adapter->link_speed == 0) |
| 4161 | return; |
| 4162 | if (pci_channel_offline(pdev)) |
| 4163 | return; |
| 4164 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4165 | adapter->stats.crcerrs += er32(CRCERRS); |
| 4166 | adapter->stats.gprc += er32(GPRC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4167 | adapter->stats.gorc += er32(GORCL); |
| 4168 | er32(GORCH); /* Clear gorc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4169 | adapter->stats.bprc += er32(BPRC); |
| 4170 | adapter->stats.mprc += er32(MPRC); |
| 4171 | adapter->stats.roc += er32(ROC); |
| 4172 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4173 | adapter->stats.mpc += er32(MPC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4174 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4175 | /* Half-duplex statistics */ |
| 4176 | if (adapter->link_duplex == HALF_DUPLEX) { |
| 4177 | if (adapter->flags2 & FLAG2_HAS_PHY_STATS) { |
| 4178 | e1000e_update_phy_stats(adapter); |
| 4179 | } else { |
| 4180 | adapter->stats.scc += er32(SCC); |
| 4181 | adapter->stats.ecol += er32(ECOL); |
| 4182 | adapter->stats.mcc += er32(MCC); |
| 4183 | adapter->stats.latecol += er32(LATECOL); |
| 4184 | adapter->stats.dc += er32(DC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4185 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4186 | hw->mac.collision_delta = er32(COLC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4187 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4188 | if ((hw->mac.type != e1000_82574) && |
| 4189 | (hw->mac.type != e1000_82583)) |
| 4190 | adapter->stats.tncrs += er32(TNCRS); |
| 4191 | } |
| 4192 | adapter->stats.colc += hw->mac.collision_delta; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4193 | } |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4194 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4195 | adapter->stats.xonrxc += er32(XONRXC); |
| 4196 | adapter->stats.xontxc += er32(XONTXC); |
| 4197 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 4198 | adapter->stats.xofftxc += er32(XOFFTXC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4199 | adapter->stats.gptc += er32(GPTC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4200 | adapter->stats.gotc += er32(GOTCL); |
| 4201 | er32(GOTCH); /* Clear gotc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4202 | adapter->stats.rnbc += er32(RNBC); |
| 4203 | adapter->stats.ruc += er32(RUC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4204 | |
| 4205 | adapter->stats.mptc += er32(MPTC); |
| 4206 | adapter->stats.bptc += er32(BPTC); |
| 4207 | |
| 4208 | /* used for adaptive IFS */ |
| 4209 | |
| 4210 | hw->mac.tx_packet_delta = er32(TPT); |
| 4211 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4212 | |
| 4213 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 4214 | adapter->stats.rxerrc += er32(RXERRC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4215 | adapter->stats.cexterr += er32(CEXTERR); |
| 4216 | adapter->stats.tsctc += er32(TSCTC); |
| 4217 | adapter->stats.tsctfc += er32(TSCTFC); |
| 4218 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4219 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4220 | netdev->stats.multicast = adapter->stats.mprc; |
| 4221 | netdev->stats.collisions = adapter->stats.colc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4222 | |
| 4223 | /* Rx Errors */ |
| 4224 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4225 | /* |
| 4226 | * RLEC on some newer hardware can be incorrect so build |
| 4227 | * our own version based on RUC and ROC |
| 4228 | */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4229 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4230 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 4231 | adapter->stats.ruc + adapter->stats.roc + |
| 4232 | adapter->stats.cexterr; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4233 | netdev->stats.rx_length_errors = adapter->stats.ruc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4234 | adapter->stats.roc; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4235 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4236 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; |
| 4237 | netdev->stats.rx_missed_errors = adapter->stats.mpc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4238 | |
| 4239 | /* Tx Errors */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4240 | netdev->stats.tx_errors = adapter->stats.ecol + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4241 | adapter->stats.latecol; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4242 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
| 4243 | netdev->stats.tx_window_errors = adapter->stats.latecol; |
| 4244 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4245 | |
| 4246 | /* Tx Dropped needs to be maintained elsewhere */ |
| 4247 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4248 | /* Management Stats */ |
| 4249 | adapter->stats.mgptc += er32(MGTPTC); |
| 4250 | adapter->stats.mgprc += er32(MGTPRC); |
| 4251 | adapter->stats.mgpdc += er32(MGTPDC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4252 | } |
| 4253 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4254 | /** |
| 4255 | * e1000_phy_read_status - Update the PHY register status snapshot |
| 4256 | * @adapter: board private structure |
| 4257 | **/ |
| 4258 | static void e1000_phy_read_status(struct e1000_adapter *adapter) |
| 4259 | { |
| 4260 | struct e1000_hw *hw = &adapter->hw; |
| 4261 | struct e1000_phy_regs *phy = &adapter->phy_regs; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4262 | |
| 4263 | if ((er32(STATUS) & E1000_STATUS_LU) && |
| 4264 | (adapter->hw.phy.media_type == e1000_media_type_copper)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4265 | int ret_val; |
| 4266 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4267 | ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr); |
| 4268 | ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr); |
| 4269 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise); |
| 4270 | ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa); |
| 4271 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion); |
| 4272 | ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000); |
| 4273 | ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000); |
| 4274 | ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus); |
| 4275 | if (ret_val) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4276 | e_warn("Error reading PHY register\n"); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4277 | } else { |
| 4278 | /* |
| 4279 | * Do not read PHY registers if link is not up |
| 4280 | * Set values to typical power-on defaults |
| 4281 | */ |
| 4282 | phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); |
| 4283 | phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | |
| 4284 | BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | |
| 4285 | BMSR_ERCAP); |
| 4286 | phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | |
| 4287 | ADVERTISE_ALL | ADVERTISE_CSMA); |
| 4288 | phy->lpa = 0; |
| 4289 | phy->expansion = EXPANSION_ENABLENPAGE; |
| 4290 | phy->ctrl1000 = ADVERTISE_1000FULL; |
| 4291 | phy->stat1000 = 0; |
| 4292 | phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); |
| 4293 | } |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4294 | } |
| 4295 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4296 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
| 4297 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4298 | struct e1000_hw *hw = &adapter->hw; |
| 4299 | u32 ctrl = er32(CTRL); |
| 4300 | |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4301 | /* Link status message must follow this format for user tools */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 4302 | printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n", |
| 4303 | adapter->netdev->name, |
| 4304 | adapter->link_speed, |
| 4305 | adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half", |
| 4306 | (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" : |
| 4307 | (ctrl & E1000_CTRL_RFCE) ? "Rx" : |
| 4308 | (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4309 | } |
| 4310 | |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 4311 | static bool e1000e_has_link(struct e1000_adapter *adapter) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4312 | { |
| 4313 | struct e1000_hw *hw = &adapter->hw; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4314 | bool link_active = false; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4315 | s32 ret_val = 0; |
| 4316 | |
| 4317 | /* |
| 4318 | * get_link_status is set on LSC (link status) interrupt or |
| 4319 | * Rx sequence error interrupt. get_link_status will stay |
| 4320 | * false until the check_for_link establishes link |
| 4321 | * for copper adapters ONLY |
| 4322 | */ |
| 4323 | switch (hw->phy.media_type) { |
| 4324 | case e1000_media_type_copper: |
| 4325 | if (hw->mac.get_link_status) { |
| 4326 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4327 | link_active = !hw->mac.get_link_status; |
| 4328 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4329 | link_active = true; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4330 | } |
| 4331 | break; |
| 4332 | case e1000_media_type_fiber: |
| 4333 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4334 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 4335 | break; |
| 4336 | case e1000_media_type_internal_serdes: |
| 4337 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4338 | link_active = adapter->hw.mac.serdes_has_link; |
| 4339 | break; |
| 4340 | default: |
| 4341 | case e1000_media_type_unknown: |
| 4342 | break; |
| 4343 | } |
| 4344 | |
| 4345 | if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && |
| 4346 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 4347 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4348 | e_info("Gigabit has been disabled, downgrading speed\n"); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | return link_active; |
| 4352 | } |
| 4353 | |
| 4354 | static void e1000e_enable_receives(struct e1000_adapter *adapter) |
| 4355 | { |
| 4356 | /* make sure the receive unit is started */ |
| 4357 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 4358 | (adapter->flags & FLAG_RX_RESTART_NOW)) { |
| 4359 | struct e1000_hw *hw = &adapter->hw; |
| 4360 | u32 rctl = er32(RCTL); |
| 4361 | ew32(RCTL, rctl | E1000_RCTL_EN); |
| 4362 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
| 4363 | } |
| 4364 | } |
| 4365 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4366 | static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter) |
| 4367 | { |
| 4368 | struct e1000_hw *hw = &adapter->hw; |
| 4369 | |
| 4370 | /* |
| 4371 | * With 82574 controllers, PHY needs to be checked periodically |
| 4372 | * for hung state and reset, if two calls return true |
| 4373 | */ |
| 4374 | if (e1000_check_phy_82574(hw)) |
| 4375 | adapter->phy_hang_count++; |
| 4376 | else |
| 4377 | adapter->phy_hang_count = 0; |
| 4378 | |
| 4379 | if (adapter->phy_hang_count > 1) { |
| 4380 | adapter->phy_hang_count = 0; |
| 4381 | schedule_work(&adapter->reset_task); |
| 4382 | } |
| 4383 | } |
| 4384 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4385 | /** |
| 4386 | * e1000_watchdog - Timer Call-back |
| 4387 | * @data: pointer to adapter cast into an unsigned long |
| 4388 | **/ |
| 4389 | static void e1000_watchdog(unsigned long data) |
| 4390 | { |
| 4391 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 4392 | |
| 4393 | /* Do the rest outside of interrupt context */ |
| 4394 | schedule_work(&adapter->watchdog_task); |
| 4395 | |
| 4396 | /* TODO: make this use queue_delayed_work() */ |
| 4397 | } |
| 4398 | |
| 4399 | static void e1000_watchdog_task(struct work_struct *work) |
| 4400 | { |
| 4401 | struct e1000_adapter *adapter = container_of(work, |
| 4402 | struct e1000_adapter, watchdog_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4403 | struct net_device *netdev = adapter->netdev; |
| 4404 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4405 | struct e1000_phy_info *phy = &adapter->hw.phy; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4406 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4407 | struct e1000_hw *hw = &adapter->hw; |
| 4408 | u32 link, tctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4409 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4410 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4411 | return; |
| 4412 | |
David S. Miller | b405e8d | 2010-02-04 22:31:41 -0800 | [diff] [blame] | 4413 | link = e1000e_has_link(adapter); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4414 | if ((netif_carrier_ok(netdev)) && link) { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4415 | /* Cancel scheduled suspend requests. */ |
| 4416 | pm_runtime_resume(netdev->dev.parent); |
| 4417 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4418 | e1000e_enable_receives(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4419 | goto link_up; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | if ((e1000e_enable_tx_pkt_filtering(hw)) && |
| 4423 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) |
| 4424 | e1000_update_mng_vlan(adapter); |
| 4425 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4426 | if (link) { |
| 4427 | if (!netif_carrier_ok(netdev)) { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4428 | bool txb2b = true; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4429 | |
| 4430 | /* Cancel scheduled suspend requests. */ |
| 4431 | pm_runtime_resume(netdev->dev.parent); |
| 4432 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4433 | /* update snapshot of PHY registers on LSC */ |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4434 | e1000_phy_read_status(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4435 | mac->ops.get_link_up_info(&adapter->hw, |
| 4436 | &adapter->link_speed, |
| 4437 | &adapter->link_duplex); |
| 4438 | e1000_print_link_info(adapter); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4439 | /* |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 4440 | * On supported PHYs, check for duplex mismatch only |
| 4441 | * if link has autonegotiated at 10/100 half |
| 4442 | */ |
| 4443 | if ((hw->phy.type == e1000_phy_igp_3 || |
| 4444 | hw->phy.type == e1000_phy_bm) && |
| 4445 | (hw->mac.autoneg == true) && |
| 4446 | (adapter->link_speed == SPEED_10 || |
| 4447 | adapter->link_speed == SPEED_100) && |
| 4448 | (adapter->link_duplex == HALF_DUPLEX)) { |
| 4449 | u16 autoneg_exp; |
| 4450 | |
| 4451 | e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp); |
| 4452 | |
| 4453 | if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS)) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 4454 | 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] | 4455 | } |
| 4456 | |
Emil Tantilov | f49c57e | 2010-03-24 12:55:02 +0000 | [diff] [blame] | 4457 | /* adjust timeout factor according to speed/duplex */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4458 | adapter->tx_timeout_factor = 1; |
| 4459 | switch (adapter->link_speed) { |
| 4460 | case SPEED_10: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4461 | txb2b = false; |
Bruce Allan | 10f1b49 | 2008-08-08 18:36:01 -0700 | [diff] [blame] | 4462 | adapter->tx_timeout_factor = 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4463 | break; |
| 4464 | case SPEED_100: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4465 | txb2b = false; |
Bruce Allan | 4c86e0b | 2009-11-19 12:35:26 +0000 | [diff] [blame] | 4466 | adapter->tx_timeout_factor = 10; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4467 | break; |
| 4468 | } |
| 4469 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4470 | /* |
| 4471 | * workaround: re-program speed mode bit after |
| 4472 | * link-up event |
| 4473 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4474 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
| 4475 | !txb2b) { |
| 4476 | u32 tarc0; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4477 | tarc0 = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4478 | tarc0 &= ~SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4479 | ew32(TARC(0), tarc0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4480 | } |
| 4481 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4482 | /* |
| 4483 | * disable TSO for pcie and 10/100 speeds, to avoid |
| 4484 | * some hardware issues |
| 4485 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4486 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
| 4487 | switch (adapter->link_speed) { |
| 4488 | case SPEED_10: |
| 4489 | case SPEED_100: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4490 | e_info("10/100 speed: disabling TSO\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4491 | netdev->features &= ~NETIF_F_TSO; |
| 4492 | netdev->features &= ~NETIF_F_TSO6; |
| 4493 | break; |
| 4494 | case SPEED_1000: |
| 4495 | netdev->features |= NETIF_F_TSO; |
| 4496 | netdev->features |= NETIF_F_TSO6; |
| 4497 | break; |
| 4498 | default: |
| 4499 | /* oops */ |
| 4500 | break; |
| 4501 | } |
| 4502 | } |
| 4503 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4504 | /* |
| 4505 | * enable transmits in the hardware, need to do this |
| 4506 | * after setting TARC(0) |
| 4507 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4508 | tctl = er32(TCTL); |
| 4509 | tctl |= E1000_TCTL_EN; |
| 4510 | ew32(TCTL, tctl); |
| 4511 | |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4512 | /* |
| 4513 | * Perform any post-link-up configuration before |
| 4514 | * reporting link up. |
| 4515 | */ |
| 4516 | if (phy->ops.cfg_on_link_up) |
| 4517 | phy->ops.cfg_on_link_up(hw); |
| 4518 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4519 | netif_carrier_on(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4520 | |
| 4521 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4522 | mod_timer(&adapter->phy_info_timer, |
| 4523 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4524 | } |
| 4525 | } else { |
| 4526 | if (netif_carrier_ok(netdev)) { |
| 4527 | adapter->link_speed = 0; |
| 4528 | adapter->link_duplex = 0; |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4529 | /* Link status message must follow this format */ |
| 4530 | printk(KERN_INFO "e1000e: %s NIC Link is Down\n", |
| 4531 | adapter->netdev->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4532 | netif_carrier_off(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4533 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4534 | mod_timer(&adapter->phy_info_timer, |
| 4535 | round_jiffies(jiffies + 2 * HZ)); |
| 4536 | |
| 4537 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) |
| 4538 | schedule_work(&adapter->reset_task); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4539 | else |
| 4540 | pm_schedule_suspend(netdev->dev.parent, |
| 4541 | LINK_TIMEOUT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4542 | } |
| 4543 | } |
| 4544 | |
| 4545 | link_up: |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4546 | spin_lock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4547 | e1000e_update_stats(adapter); |
| 4548 | |
| 4549 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 4550 | adapter->tpt_old = adapter->stats.tpt; |
| 4551 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; |
| 4552 | adapter->colc_old = adapter->stats.colc; |
| 4553 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4554 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
| 4555 | adapter->gorc_old = adapter->stats.gorc; |
| 4556 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; |
| 4557 | adapter->gotc_old = adapter->stats.gotc; |
Flavio Leitner | 2084b11 | 2011-04-05 04:27:43 +0000 | [diff] [blame] | 4558 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4559 | |
| 4560 | e1000e_update_adaptive(&adapter->hw); |
| 4561 | |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4562 | if (!netif_carrier_ok(netdev) && |
| 4563 | (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) { |
| 4564 | /* |
| 4565 | * We've lost link, so the controller stops DMA, |
| 4566 | * but we've got queued Tx work that's never going |
| 4567 | * to get done, so reset controller to flush Tx. |
| 4568 | * (Do the reset outside of interrupt context). |
| 4569 | */ |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4570 | schedule_work(&adapter->reset_task); |
| 4571 | /* return immediately since reset is imminent */ |
| 4572 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4573 | } |
| 4574 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4575 | /* Simple mode for Interrupt Throttle Rate (ITR) */ |
| 4576 | if (adapter->itr_setting == 4) { |
| 4577 | /* |
| 4578 | * Symmetric Tx/Rx gets a reduced ITR=2000; |
| 4579 | * Total asymmetrical Tx or Rx gets ITR=8000; |
| 4580 | * everyone else is between 2000-8000. |
| 4581 | */ |
| 4582 | u32 goc = (adapter->gotc + adapter->gorc) / 10000; |
| 4583 | u32 dif = (adapter->gotc > adapter->gorc ? |
| 4584 | adapter->gotc - adapter->gorc : |
| 4585 | adapter->gorc - adapter->gotc) / 10000; |
| 4586 | u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 4587 | |
| 4588 | ew32(ITR, 1000000000 / (itr * 256)); |
| 4589 | } |
| 4590 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4591 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4592 | if (adapter->msix_entries) |
| 4593 | ew32(ICS, adapter->rx_ring->ims_val); |
| 4594 | else |
| 4595 | ew32(ICS, E1000_ICS_RXDMT0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4596 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4597 | /* flush pending descriptors to memory before detecting Tx hang */ |
| 4598 | e1000e_flush_descriptors(adapter); |
| 4599 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4600 | /* Force detection of hung controller every watchdog period */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4601 | adapter->detect_tx_hung = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4602 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4603 | /* |
| 4604 | * With 82571 controllers, LAA may be overwritten due to controller |
| 4605 | * reset from the other port. Set the appropriate LAA in RAR[0] |
| 4606 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4607 | if (e1000e_get_laa_state_82571(hw)) |
| 4608 | e1000e_rar_set(hw, adapter->hw.mac.addr, 0); |
| 4609 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4610 | if (adapter->flags2 & FLAG2_CHECK_PHY_HANG) |
| 4611 | e1000e_check_82574_phy_workaround(adapter); |
| 4612 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4613 | /* Reset the timer */ |
| 4614 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4615 | mod_timer(&adapter->watchdog_timer, |
| 4616 | round_jiffies(jiffies + 2 * HZ)); |
| 4617 | } |
| 4618 | |
| 4619 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 4620 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 4621 | #define E1000_TX_FLAGS_TSO 0x00000004 |
| 4622 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
| 4623 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 4624 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 4625 | |
| 4626 | static int e1000_tso(struct e1000_adapter *adapter, |
| 4627 | struct sk_buff *skb) |
| 4628 | { |
| 4629 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4630 | struct e1000_context_desc *context_desc; |
| 4631 | struct e1000_buffer *buffer_info; |
| 4632 | unsigned int i; |
| 4633 | u32 cmd_length = 0; |
| 4634 | u16 ipcse = 0, tucse, mss; |
| 4635 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4636 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4637 | if (!skb_is_gso(skb)) |
| 4638 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4639 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4640 | if (skb_header_cloned(skb)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4641 | int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4642 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4643 | if (err) |
| 4644 | return err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4645 | } |
| 4646 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4647 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 4648 | mss = skb_shinfo(skb)->gso_size; |
| 4649 | if (skb->protocol == htons(ETH_P_IP)) { |
| 4650 | struct iphdr *iph = ip_hdr(skb); |
| 4651 | iph->tot_len = 0; |
| 4652 | iph->check = 0; |
| 4653 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, |
| 4654 | 0, IPPROTO_TCP, 0); |
| 4655 | cmd_length = E1000_TXD_CMD_IP; |
| 4656 | ipcse = skb_transport_offset(skb) - 1; |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 4657 | } else if (skb_is_gso_v6(skb)) { |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4658 | ipv6_hdr(skb)->payload_len = 0; |
| 4659 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 4660 | &ipv6_hdr(skb)->daddr, |
| 4661 | 0, IPPROTO_TCP, 0); |
| 4662 | ipcse = 0; |
| 4663 | } |
| 4664 | ipcss = skb_network_offset(skb); |
| 4665 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
| 4666 | tucss = skb_transport_offset(skb); |
| 4667 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
| 4668 | tucse = 0; |
| 4669 | |
| 4670 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
| 4671 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
| 4672 | |
| 4673 | i = tx_ring->next_to_use; |
| 4674 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 4675 | buffer_info = &tx_ring->buffer_info[i]; |
| 4676 | |
| 4677 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 4678 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 4679 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 4680 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 4681 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 4682 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 4683 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 4684 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 4685 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 4686 | |
| 4687 | buffer_info->time_stamp = jiffies; |
| 4688 | buffer_info->next_to_watch = i; |
| 4689 | |
| 4690 | i++; |
| 4691 | if (i == tx_ring->count) |
| 4692 | i = 0; |
| 4693 | tx_ring->next_to_use = i; |
| 4694 | |
| 4695 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 4699 | { |
| 4700 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4701 | struct e1000_context_desc *context_desc; |
| 4702 | struct e1000_buffer *buffer_info; |
| 4703 | unsigned int i; |
| 4704 | u8 css; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4705 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4706 | __be16 protocol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4707 | |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4708 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 4709 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4710 | |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4711 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) |
| 4712 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 4713 | else |
| 4714 | protocol = skb->protocol; |
| 4715 | |
Arthur Jones | 3f51839 | 2009-03-20 15:56:35 -0700 | [diff] [blame] | 4716 | switch (protocol) { |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4717 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4718 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 4719 | cmd_len |= E1000_TXD_CMD_TCP; |
| 4720 | break; |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4721 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4722 | /* XXX not handling all IPV6 headers */ |
| 4723 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 4724 | cmd_len |= E1000_TXD_CMD_TCP; |
| 4725 | break; |
| 4726 | default: |
| 4727 | if (unlikely(net_ratelimit())) |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4728 | e_warn("checksum_partial proto=%x!\n", |
| 4729 | be16_to_cpu(protocol)); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4730 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4731 | } |
| 4732 | |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 4733 | css = skb_checksum_start_offset(skb); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4734 | |
| 4735 | i = tx_ring->next_to_use; |
| 4736 | buffer_info = &tx_ring->buffer_info[i]; |
| 4737 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 4738 | |
| 4739 | context_desc->lower_setup.ip_config = 0; |
| 4740 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 4741 | context_desc->upper_setup.tcp_fields.tucso = |
| 4742 | css + skb->csum_offset; |
| 4743 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 4744 | context_desc->tcp_seg_setup.data = 0; |
| 4745 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 4746 | |
| 4747 | buffer_info->time_stamp = jiffies; |
| 4748 | buffer_info->next_to_watch = i; |
| 4749 | |
| 4750 | i++; |
| 4751 | if (i == tx_ring->count) |
| 4752 | i = 0; |
| 4753 | tx_ring->next_to_use = i; |
| 4754 | |
| 4755 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4756 | } |
| 4757 | |
| 4758 | #define E1000_MAX_PER_TXD 8192 |
| 4759 | #define E1000_MAX_TXD_PWR 12 |
| 4760 | |
| 4761 | static int e1000_tx_map(struct e1000_adapter *adapter, |
| 4762 | struct sk_buff *skb, unsigned int first, |
| 4763 | unsigned int max_per_txd, unsigned int nr_frags, |
| 4764 | unsigned int mss) |
| 4765 | { |
| 4766 | struct e1000_ring *tx_ring = adapter->tx_ring; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4767 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4768 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 4769 | unsigned int len = skb_headlen(skb); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4770 | unsigned int offset = 0, size, count = 0, i; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4771 | unsigned int f, bytecount, segs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4772 | |
| 4773 | i = tx_ring->next_to_use; |
| 4774 | |
| 4775 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4776 | buffer_info = &tx_ring->buffer_info[i]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4777 | size = min(len, max_per_txd); |
| 4778 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4779 | buffer_info->length = size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4780 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4781 | buffer_info->next_to_watch = i; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4782 | buffer_info->dma = dma_map_single(&pdev->dev, |
| 4783 | skb->data + offset, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4784 | size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4785 | buffer_info->mapped_as_page = false; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4786 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4787 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4788 | |
| 4789 | len -= size; |
| 4790 | offset += size; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4791 | count++; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4792 | |
| 4793 | if (len) { |
| 4794 | i++; |
| 4795 | if (i == tx_ring->count) |
| 4796 | i = 0; |
| 4797 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | for (f = 0; f < nr_frags; f++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 4801 | const struct skb_frag_struct *frag; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4802 | |
| 4803 | frag = &skb_shinfo(skb)->frags[f]; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 4804 | len = skb_frag_size(frag); |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 4805 | offset = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4806 | |
| 4807 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4808 | i++; |
| 4809 | if (i == tx_ring->count) |
| 4810 | i = 0; |
| 4811 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4812 | buffer_info = &tx_ring->buffer_info[i]; |
| 4813 | size = min(len, max_per_txd); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4814 | |
| 4815 | buffer_info->length = size; |
| 4816 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4817 | buffer_info->next_to_watch = i; |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 4818 | buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag, |
| 4819 | offset, size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4820 | buffer_info->mapped_as_page = true; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4821 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4822 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4823 | |
| 4824 | len -= size; |
| 4825 | offset += size; |
| 4826 | count++; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4827 | } |
| 4828 | } |
| 4829 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4830 | segs = skb_shinfo(skb)->gso_segs ? : 1; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4831 | /* multiply data chunks by size of headers */ |
| 4832 | bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len; |
| 4833 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4834 | tx_ring->buffer_info[i].skb = skb; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4835 | tx_ring->buffer_info[i].segs = segs; |
| 4836 | tx_ring->buffer_info[i].bytecount = bytecount; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4837 | tx_ring->buffer_info[first].next_to_watch = i; |
| 4838 | |
| 4839 | return count; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4840 | |
| 4841 | dma_error: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4842 | dev_err(&pdev->dev, "Tx DMA map failed\n"); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4843 | buffer_info->dma = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4844 | if (count) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4845 | count--; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4846 | |
| 4847 | while (count--) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4848 | if (i == 0) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4849 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4850 | i--; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4851 | buffer_info = &tx_ring->buffer_info[i]; |
Joe Perches | 1d51c41 | 2010-11-14 17:04:32 +0000 | [diff] [blame] | 4852 | e1000_put_txbuf(adapter, buffer_info); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4853 | } |
| 4854 | |
| 4855 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | static void e1000_tx_queue(struct e1000_adapter *adapter, |
| 4859 | int tx_flags, int count) |
| 4860 | { |
| 4861 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4862 | struct e1000_tx_desc *tx_desc = NULL; |
| 4863 | struct e1000_buffer *buffer_info; |
| 4864 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 4865 | unsigned int i; |
| 4866 | |
| 4867 | if (tx_flags & E1000_TX_FLAGS_TSO) { |
| 4868 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 4869 | E1000_TXD_CMD_TSE; |
| 4870 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 4871 | |
| 4872 | if (tx_flags & E1000_TX_FLAGS_IPV4) |
| 4873 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
| 4874 | } |
| 4875 | |
| 4876 | if (tx_flags & E1000_TX_FLAGS_CSUM) { |
| 4877 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 4878 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 4879 | } |
| 4880 | |
| 4881 | if (tx_flags & E1000_TX_FLAGS_VLAN) { |
| 4882 | txd_lower |= E1000_TXD_CMD_VLE; |
| 4883 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 4884 | } |
| 4885 | |
| 4886 | i = tx_ring->next_to_use; |
| 4887 | |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 4888 | do { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4889 | buffer_info = &tx_ring->buffer_info[i]; |
| 4890 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 4891 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4892 | tx_desc->lower.data = |
| 4893 | cpu_to_le32(txd_lower | buffer_info->length); |
| 4894 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
| 4895 | |
| 4896 | i++; |
| 4897 | if (i == tx_ring->count) |
| 4898 | i = 0; |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 4899 | } while (--count > 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4900 | |
| 4901 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 4902 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4903 | /* |
| 4904 | * Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4905 | * know there are new descriptors to fetch. (Only |
| 4906 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4907 | * such as IA-64). |
| 4908 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4909 | wmb(); |
| 4910 | |
| 4911 | tx_ring->next_to_use = i; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 4912 | |
| 4913 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 4914 | e1000e_update_tdt_wa(adapter, i); |
| 4915 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame^] | 4916 | writel(i, tx_ring->tail); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 4917 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4918 | /* |
| 4919 | * we need this if more than one processor can write to our tail |
| 4920 | * at a time, it synchronizes IO on IA64/Altix systems |
| 4921 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4922 | mmiowb(); |
| 4923 | } |
| 4924 | |
| 4925 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 4926 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 4927 | struct sk_buff *skb) |
| 4928 | { |
| 4929 | struct e1000_hw *hw = &adapter->hw; |
| 4930 | u16 length, offset; |
| 4931 | |
| 4932 | if (vlan_tx_tag_present(skb)) { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 4933 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
| 4934 | (adapter->hw.mng_cookie.status & |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4935 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) |
| 4936 | return 0; |
| 4937 | } |
| 4938 | |
| 4939 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) |
| 4940 | return 0; |
| 4941 | |
| 4942 | if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP)) |
| 4943 | return 0; |
| 4944 | |
| 4945 | { |
| 4946 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14); |
| 4947 | struct udphdr *udp; |
| 4948 | |
| 4949 | if (ip->protocol != IPPROTO_UDP) |
| 4950 | return 0; |
| 4951 | |
| 4952 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 4953 | if (ntohs(udp->dest) != 67) |
| 4954 | return 0; |
| 4955 | |
| 4956 | offset = (u8 *)udp + 8 - skb->data; |
| 4957 | length = skb->len - offset; |
| 4958 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); |
| 4959 | } |
| 4960 | |
| 4961 | return 0; |
| 4962 | } |
| 4963 | |
| 4964 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 4965 | { |
| 4966 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4967 | |
| 4968 | netif_stop_queue(netdev); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4969 | /* |
| 4970 | * Herbert's original patch had: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4971 | * smp_mb__after_netif_stop_queue(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4972 | * but since that doesn't exist yet, just open code it. |
| 4973 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4974 | smp_mb(); |
| 4975 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4976 | /* |
| 4977 | * We need to check again in a case another CPU has just |
| 4978 | * made room available. |
| 4979 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4980 | if (e1000_desc_unused(adapter->tx_ring) < size) |
| 4981 | return -EBUSY; |
| 4982 | |
| 4983 | /* A reprieve! */ |
| 4984 | netif_start_queue(netdev); |
| 4985 | ++adapter->restart_queue; |
| 4986 | return 0; |
| 4987 | } |
| 4988 | |
| 4989 | static int e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 4990 | { |
| 4991 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4992 | |
| 4993 | if (e1000_desc_unused(adapter->tx_ring) >= size) |
| 4994 | return 0; |
| 4995 | return __e1000_maybe_stop_tx(netdev, size); |
| 4996 | } |
| 4997 | |
| 4998 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 4999 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 5000 | struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5001 | { |
| 5002 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5003 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 5004 | unsigned int first; |
| 5005 | unsigned int max_per_txd = E1000_MAX_PER_TXD; |
| 5006 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 5007 | unsigned int tx_flags = 0; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5008 | unsigned int len = skb_headlen(skb); |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 5009 | unsigned int nr_frags; |
| 5010 | unsigned int mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5011 | int count = 0; |
| 5012 | int tso; |
| 5013 | unsigned int f; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5014 | |
| 5015 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 5016 | dev_kfree_skb_any(skb); |
| 5017 | return NETDEV_TX_OK; |
| 5018 | } |
| 5019 | |
| 5020 | if (skb->len <= 0) { |
| 5021 | dev_kfree_skb_any(skb); |
| 5022 | return NETDEV_TX_OK; |
| 5023 | } |
| 5024 | |
| 5025 | mss = skb_shinfo(skb)->gso_size; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5026 | /* |
| 5027 | * The controller does a simple calculation to |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5028 | * make sure there is enough room in the FIFO before |
| 5029 | * initiating the DMA for each buffer. The calc is: |
| 5030 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 5031 | * overrun the FIFO, adjust the max buffer len if mss |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5032 | * drops. |
| 5033 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5034 | if (mss) { |
| 5035 | u8 hdr_len; |
| 5036 | max_per_txd = min(mss << 2, max_per_txd); |
| 5037 | max_txd_pwr = fls(max_per_txd) - 1; |
| 5038 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5039 | /* |
| 5040 | * TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 5041 | * points to just header, pull a few bytes of payload from |
| 5042 | * frags into skb->data |
| 5043 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5044 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5045 | /* |
| 5046 | * we do this workaround for ES2LAN, but it is un-necessary, |
| 5047 | * avoiding it could save a lot of cycles |
| 5048 | */ |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 5049 | if (skb->data_len && (hdr_len == len)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5050 | unsigned int pull_size; |
| 5051 | |
| 5052 | pull_size = min((unsigned int)4, skb->data_len); |
| 5053 | if (!__pskb_pull_tail(skb, pull_size)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5054 | e_err("__pskb_pull_tail failed.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5055 | dev_kfree_skb_any(skb); |
| 5056 | return NETDEV_TX_OK; |
| 5057 | } |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5058 | len = skb_headlen(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5059 | } |
| 5060 | } |
| 5061 | |
| 5062 | /* reserve a descriptor for the offload context */ |
| 5063 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5064 | count++; |
| 5065 | count++; |
| 5066 | |
| 5067 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 5068 | |
| 5069 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 5070 | for (f = 0; f < nr_frags; f++) |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5071 | count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]), |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5072 | max_txd_pwr); |
| 5073 | |
| 5074 | if (adapter->hw.mac.tx_pkt_filtering) |
| 5075 | e1000_transfer_dhcp_info(adapter, skb); |
| 5076 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5077 | /* |
| 5078 | * need: count + 2 desc gap to keep tail from touching |
| 5079 | * head, otherwise try next time |
| 5080 | */ |
Jesse Brandeburg | 92af3e9 | 2009-01-19 14:17:08 +0000 | [diff] [blame] | 5081 | if (e1000_maybe_stop_tx(netdev, count + 2)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5082 | return NETDEV_TX_BUSY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5083 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 5084 | if (vlan_tx_tag_present(skb)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5085 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 5086 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 5087 | } |
| 5088 | |
| 5089 | first = tx_ring->next_to_use; |
| 5090 | |
| 5091 | tso = e1000_tso(adapter, skb); |
| 5092 | if (tso < 0) { |
| 5093 | dev_kfree_skb_any(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5094 | return NETDEV_TX_OK; |
| 5095 | } |
| 5096 | |
| 5097 | if (tso) |
| 5098 | tx_flags |= E1000_TX_FLAGS_TSO; |
| 5099 | else if (e1000_tx_csum(adapter, skb)) |
| 5100 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 5101 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5102 | /* |
| 5103 | * 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] | 5104 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5105 | * no longer assume, we must. |
| 5106 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5107 | if (skb->protocol == htons(ETH_P_IP)) |
| 5108 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 5109 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5110 | /* if count is 0 then mapping error has occurred */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5111 | 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] | 5112 | if (count) { |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 5113 | netdev_sent_queue(netdev, skb->len); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5114 | e1000_tx_queue(adapter, tx_flags, count); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5115 | /* Make sure there is space in the ring for the next send. */ |
| 5116 | e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2); |
| 5117 | |
| 5118 | } else { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5119 | dev_kfree_skb_any(skb); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5120 | tx_ring->buffer_info[first].time_stamp = 0; |
| 5121 | tx_ring->next_to_use = first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5122 | } |
| 5123 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5124 | return NETDEV_TX_OK; |
| 5125 | } |
| 5126 | |
| 5127 | /** |
| 5128 | * e1000_tx_timeout - Respond to a Tx Hang |
| 5129 | * @netdev: network interface device structure |
| 5130 | **/ |
| 5131 | static void e1000_tx_timeout(struct net_device *netdev) |
| 5132 | { |
| 5133 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5134 | |
| 5135 | /* Do the reset outside of interrupt context */ |
| 5136 | adapter->tx_timeout_count++; |
| 5137 | schedule_work(&adapter->reset_task); |
| 5138 | } |
| 5139 | |
| 5140 | static void e1000_reset_task(struct work_struct *work) |
| 5141 | { |
| 5142 | struct e1000_adapter *adapter; |
| 5143 | adapter = container_of(work, struct e1000_adapter, reset_task); |
| 5144 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 5145 | /* don't run the task if already down */ |
| 5146 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 5147 | return; |
| 5148 | |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 5149 | if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 5150 | (adapter->flags & FLAG_RX_RESTART_NOW))) { |
| 5151 | e1000e_dump(adapter); |
| 5152 | e_err("Reset adapter\n"); |
| 5153 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5154 | e1000e_reinit_locked(adapter); |
| 5155 | } |
| 5156 | |
| 5157 | /** |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5158 | * e1000_get_stats64 - Get System Network Statistics |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5159 | * @netdev: network interface device structure |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5160 | * @stats: rtnl_link_stats64 pointer |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5161 | * |
| 5162 | * Returns the address of the device statistics structure. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5163 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5164 | struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev, |
| 5165 | struct rtnl_link_stats64 *stats) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5166 | { |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5167 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5168 | |
| 5169 | memset(stats, 0, sizeof(struct rtnl_link_stats64)); |
| 5170 | spin_lock(&adapter->stats64_lock); |
| 5171 | e1000e_update_stats(adapter); |
| 5172 | /* Fill out the OS statistics structure */ |
| 5173 | stats->rx_bytes = adapter->stats.gorc; |
| 5174 | stats->rx_packets = adapter->stats.gprc; |
| 5175 | stats->tx_bytes = adapter->stats.gotc; |
| 5176 | stats->tx_packets = adapter->stats.gptc; |
| 5177 | stats->multicast = adapter->stats.mprc; |
| 5178 | stats->collisions = adapter->stats.colc; |
| 5179 | |
| 5180 | /* Rx Errors */ |
| 5181 | |
| 5182 | /* |
| 5183 | * RLEC on some newer hardware can be incorrect so build |
| 5184 | * our own version based on RUC and ROC |
| 5185 | */ |
| 5186 | stats->rx_errors = adapter->stats.rxerrc + |
| 5187 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 5188 | adapter->stats.ruc + adapter->stats.roc + |
| 5189 | adapter->stats.cexterr; |
| 5190 | stats->rx_length_errors = adapter->stats.ruc + |
| 5191 | adapter->stats.roc; |
| 5192 | stats->rx_crc_errors = adapter->stats.crcerrs; |
| 5193 | stats->rx_frame_errors = adapter->stats.algnerrc; |
| 5194 | stats->rx_missed_errors = adapter->stats.mpc; |
| 5195 | |
| 5196 | /* Tx Errors */ |
| 5197 | stats->tx_errors = adapter->stats.ecol + |
| 5198 | adapter->stats.latecol; |
| 5199 | stats->tx_aborted_errors = adapter->stats.ecol; |
| 5200 | stats->tx_window_errors = adapter->stats.latecol; |
| 5201 | stats->tx_carrier_errors = adapter->stats.tncrs; |
| 5202 | |
| 5203 | /* Tx Dropped needs to be maintained elsewhere */ |
| 5204 | |
| 5205 | spin_unlock(&adapter->stats64_lock); |
| 5206 | return stats; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5207 | } |
| 5208 | |
| 5209 | /** |
| 5210 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 5211 | * @netdev: network interface device structure |
| 5212 | * @new_mtu: new value for maximum frame size |
| 5213 | * |
| 5214 | * Returns 0 on success, negative on failure |
| 5215 | **/ |
| 5216 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 5217 | { |
| 5218 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5219 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5220 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5221 | /* Jumbo frame support */ |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 5222 | if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) { |
| 5223 | if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
| 5224 | e_err("Jumbo Frames not supported.\n"); |
| 5225 | return -EINVAL; |
| 5226 | } |
| 5227 | |
| 5228 | /* |
| 5229 | * IP payload checksum (enabled with jumbos/packet-split when |
| 5230 | * Rx checksum is enabled) and generation of RSS hash is |
| 5231 | * mutually exclusive in the hardware. |
| 5232 | */ |
| 5233 | if ((netdev->features & NETIF_F_RXCSUM) && |
| 5234 | (netdev->features & NETIF_F_RXHASH)) { |
| 5235 | e_err("Jumbo frames cannot be enabled when both receive checksum offload and receive hashing are enabled. Disable one of the receive offload features before enabling jumbos.\n"); |
| 5236 | return -EINVAL; |
| 5237 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5238 | } |
| 5239 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5240 | /* Supported frame sizes */ |
| 5241 | if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) || |
| 5242 | (max_frame > adapter->max_hw_frame_size)) { |
| 5243 | e_err("Unsupported MTU setting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5244 | return -EINVAL; |
| 5245 | } |
| 5246 | |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 5247 | /* Jumbo frame workaround on 82579 requires CRC be stripped */ |
| 5248 | if ((adapter->hw.mac.type == e1000_pch2lan) && |
| 5249 | !(adapter->flags2 & FLAG2_CRC_STRIPPING) && |
| 5250 | (new_mtu > ETH_DATA_LEN)) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 5251 | 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] | 5252 | return -EINVAL; |
| 5253 | } |
| 5254 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5255 | /* 82573 Errata 17 */ |
| 5256 | if (((adapter->hw.mac.type == e1000_82573) || |
| 5257 | (adapter->hw.mac.type == e1000_82574)) && |
| 5258 | (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) { |
| 5259 | adapter->flags2 |= FLAG2_DISABLE_ASPM_L1; |
| 5260 | e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1); |
| 5261 | } |
| 5262 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5263 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 5264 | usleep_range(1000, 2000); |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5265 | /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5266 | adapter->max_frame_size = max_frame; |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5267 | e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
| 5268 | netdev->mtu = new_mtu; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5269 | if (netif_running(netdev)) |
| 5270 | e1000e_down(adapter); |
| 5271 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5272 | /* |
| 5273 | * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5274 | * means we reserve 2 more, this pushes us to allocate from the next |
| 5275 | * larger slab size. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5276 | * i.e. RXBUFFER_2048 --> size-4096 slab |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5277 | * However with the new *_jumbo_rx* routines, jumbo receives will use |
| 5278 | * fragmented skbs |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5279 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5280 | |
Jesse Brandeburg | 9926146 | 2010-01-22 22:56:16 +0000 | [diff] [blame] | 5281 | if (max_frame <= 2048) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5282 | adapter->rx_buffer_len = 2048; |
| 5283 | else |
| 5284 | adapter->rx_buffer_len = 4096; |
| 5285 | |
| 5286 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
| 5287 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || |
| 5288 | (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) |
| 5289 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5290 | + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5291 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5292 | if (netif_running(netdev)) |
| 5293 | e1000e_up(adapter); |
| 5294 | else |
| 5295 | e1000e_reset(adapter); |
| 5296 | |
| 5297 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 5298 | |
| 5299 | return 0; |
| 5300 | } |
| 5301 | |
| 5302 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 5303 | int cmd) |
| 5304 | { |
| 5305 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5306 | struct mii_ioctl_data *data = if_mii(ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5307 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5308 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5309 | return -EOPNOTSUPP; |
| 5310 | |
| 5311 | switch (cmd) { |
| 5312 | case SIOCGMIIPHY: |
| 5313 | data->phy_id = adapter->hw.phy.addr; |
| 5314 | break; |
| 5315 | case SIOCGMIIREG: |
Bruce Allan | b16a002 | 2009-11-20 23:24:30 +0000 | [diff] [blame] | 5316 | e1000_phy_read_status(adapter); |
| 5317 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5318 | switch (data->reg_num & 0x1F) { |
| 5319 | case MII_BMCR: |
| 5320 | data->val_out = adapter->phy_regs.bmcr; |
| 5321 | break; |
| 5322 | case MII_BMSR: |
| 5323 | data->val_out = adapter->phy_regs.bmsr; |
| 5324 | break; |
| 5325 | case MII_PHYSID1: |
| 5326 | data->val_out = (adapter->hw.phy.id >> 16); |
| 5327 | break; |
| 5328 | case MII_PHYSID2: |
| 5329 | data->val_out = (adapter->hw.phy.id & 0xFFFF); |
| 5330 | break; |
| 5331 | case MII_ADVERTISE: |
| 5332 | data->val_out = adapter->phy_regs.advertise; |
| 5333 | break; |
| 5334 | case MII_LPA: |
| 5335 | data->val_out = adapter->phy_regs.lpa; |
| 5336 | break; |
| 5337 | case MII_EXPANSION: |
| 5338 | data->val_out = adapter->phy_regs.expansion; |
| 5339 | break; |
| 5340 | case MII_CTRL1000: |
| 5341 | data->val_out = adapter->phy_regs.ctrl1000; |
| 5342 | break; |
| 5343 | case MII_STAT1000: |
| 5344 | data->val_out = adapter->phy_regs.stat1000; |
| 5345 | break; |
| 5346 | case MII_ESTATUS: |
| 5347 | data->val_out = adapter->phy_regs.estatus; |
| 5348 | break; |
| 5349 | default: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5350 | return -EIO; |
| 5351 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5352 | break; |
| 5353 | case SIOCSMIIREG: |
| 5354 | default: |
| 5355 | return -EOPNOTSUPP; |
| 5356 | } |
| 5357 | return 0; |
| 5358 | } |
| 5359 | |
| 5360 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 5361 | { |
| 5362 | switch (cmd) { |
| 5363 | case SIOCGMIIPHY: |
| 5364 | case SIOCGMIIREG: |
| 5365 | case SIOCSMIIREG: |
| 5366 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 5367 | default: |
| 5368 | return -EOPNOTSUPP; |
| 5369 | } |
| 5370 | } |
| 5371 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5372 | static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) |
| 5373 | { |
| 5374 | struct e1000_hw *hw = &adapter->hw; |
| 5375 | u32 i, mac_reg; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5376 | u16 phy_reg, wuc_enable; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5377 | int retval = 0; |
| 5378 | |
| 5379 | /* copy MAC RARs to PHY RARs */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 5380 | e1000_copy_rx_addrs_to_phy_ich8lan(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5381 | |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5382 | retval = hw->phy.ops.acquire(hw); |
| 5383 | if (retval) { |
| 5384 | e_err("Could not acquire PHY\n"); |
| 5385 | return retval; |
| 5386 | } |
| 5387 | |
| 5388 | /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */ |
| 5389 | retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
| 5390 | if (retval) |
| 5391 | goto out; |
| 5392 | |
| 5393 | /* copy MAC MTA to PHY MTA - only needed for pchlan */ |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5394 | for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { |
| 5395 | mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5396 | hw->phy.ops.write_reg_page(hw, BM_MTA(i), |
| 5397 | (u16)(mac_reg & 0xFFFF)); |
| 5398 | hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1, |
| 5399 | (u16)((mac_reg >> 16) & 0xFFFF)); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | /* configure PHY Rx Control register */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5403 | hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5404 | mac_reg = er32(RCTL); |
| 5405 | if (mac_reg & E1000_RCTL_UPE) |
| 5406 | phy_reg |= BM_RCTL_UPE; |
| 5407 | if (mac_reg & E1000_RCTL_MPE) |
| 5408 | phy_reg |= BM_RCTL_MPE; |
| 5409 | phy_reg &= ~(BM_RCTL_MO_MASK); |
| 5410 | if (mac_reg & E1000_RCTL_MO_3) |
| 5411 | phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) |
| 5412 | << BM_RCTL_MO_SHIFT); |
| 5413 | if (mac_reg & E1000_RCTL_BAM) |
| 5414 | phy_reg |= BM_RCTL_BAM; |
| 5415 | if (mac_reg & E1000_RCTL_PMCF) |
| 5416 | phy_reg |= BM_RCTL_PMCF; |
| 5417 | mac_reg = er32(CTRL); |
| 5418 | if (mac_reg & E1000_CTRL_RFCE) |
| 5419 | phy_reg |= BM_RCTL_RFCE; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5420 | hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5421 | |
| 5422 | /* enable PHY wakeup in MAC register */ |
| 5423 | ew32(WUFC, wufc); |
| 5424 | ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN); |
| 5425 | |
| 5426 | /* configure and enable PHY wakeup in PHY registers */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5427 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc); |
| 5428 | 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] | 5429 | |
| 5430 | /* activate PHY wakeup */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5431 | wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; |
| 5432 | retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5433 | if (retval) |
| 5434 | e_err("Could not set PHY Host Wakeup bit\n"); |
| 5435 | out: |
Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 5436 | hw->phy.ops.release(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5437 | |
| 5438 | return retval; |
| 5439 | } |
| 5440 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5441 | static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake, |
| 5442 | bool runtime) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5443 | { |
| 5444 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5445 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5446 | struct e1000_hw *hw = &adapter->hw; |
| 5447 | u32 ctrl, ctrl_ext, rctl, status; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5448 | /* Runtime suspend should only enable wakeup for link changes */ |
| 5449 | u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5450 | int retval = 0; |
| 5451 | |
| 5452 | netif_device_detach(netdev); |
| 5453 | |
| 5454 | if (netif_running(netdev)) { |
| 5455 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 5456 | e1000e_down(adapter); |
| 5457 | e1000_free_irq(adapter); |
| 5458 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5459 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5460 | |
| 5461 | retval = pci_save_state(pdev); |
| 5462 | if (retval) |
| 5463 | return retval; |
| 5464 | |
| 5465 | status = er32(STATUS); |
| 5466 | if (status & E1000_STATUS_LU) |
| 5467 | wufc &= ~E1000_WUFC_LNKC; |
| 5468 | |
| 5469 | if (wufc) { |
| 5470 | e1000_setup_rctl(adapter); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 5471 | e1000e_set_rx_mode(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5472 | |
| 5473 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5474 | if (wufc & E1000_WUFC_MC) { |
| 5475 | rctl = er32(RCTL); |
| 5476 | rctl |= E1000_RCTL_MPE; |
| 5477 | ew32(RCTL, rctl); |
| 5478 | } |
| 5479 | |
| 5480 | ctrl = er32(CTRL); |
| 5481 | /* advertise wake from D3Cold */ |
| 5482 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5483 | /* phy power management enable */ |
| 5484 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5485 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 5486 | if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) |
| 5487 | ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5488 | ew32(CTRL, ctrl); |
| 5489 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5490 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
| 5491 | adapter->hw.phy.media_type == |
| 5492 | e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5493 | /* keep the laser running in D3 */ |
| 5494 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | 93a23f4 | 2009-12-08 07:27:41 +0000 | [diff] [blame] | 5495 | ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5496 | ew32(CTRL_EXT, ctrl_ext); |
| 5497 | } |
| 5498 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5499 | if (adapter->flags & FLAG_IS_ICH) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5500 | e1000_suspend_workarounds_ich8lan(&adapter->hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5501 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5502 | /* Allow time for pending master requests to run */ |
| 5503 | e1000e_disable_pcie_master(&adapter->hw); |
| 5504 | |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5505 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5506 | /* enable wakeup by the PHY */ |
| 5507 | retval = e1000_init_phy_wakeup(adapter, wufc); |
| 5508 | if (retval) |
| 5509 | return retval; |
| 5510 | } else { |
| 5511 | /* enable wakeup by the MAC */ |
| 5512 | ew32(WUFC, wufc); |
| 5513 | ew32(WUC, E1000_WUC_PME_EN); |
| 5514 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5515 | } else { |
| 5516 | ew32(WUC, 0); |
| 5517 | ew32(WUFC, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5518 | } |
| 5519 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5520 | *enable_wake = !!wufc; |
| 5521 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5522 | /* make sure adapter isn't asleep if manageability is enabled */ |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5523 | if ((adapter->flags & FLAG_MNG_PT_ENABLED) || |
| 5524 | (hw->mac.ops.check_mng_mode(hw))) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5525 | *enable_wake = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5526 | |
| 5527 | if (adapter->hw.phy.type == e1000_phy_igp_3) |
| 5528 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
| 5529 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5530 | /* |
| 5531 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5532 | * would have already happened in close and is redundant. |
| 5533 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5534 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5535 | |
| 5536 | pci_disable_device(pdev); |
| 5537 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5538 | return 0; |
| 5539 | } |
| 5540 | |
| 5541 | static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake) |
| 5542 | { |
| 5543 | if (sleep && wake) { |
| 5544 | pci_prepare_to_sleep(pdev); |
| 5545 | return; |
| 5546 | } |
| 5547 | |
| 5548 | pci_wake_from_d3(pdev, wake); |
| 5549 | pci_set_power_state(pdev, PCI_D3hot); |
| 5550 | } |
| 5551 | |
| 5552 | static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, |
| 5553 | bool wake) |
| 5554 | { |
| 5555 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5556 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5557 | |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5558 | /* |
| 5559 | * The pci-e switch on some quad port adapters will report a |
| 5560 | * correctable error when the MAC transitions from D0 to D3. To |
| 5561 | * prevent this we need to mask off the correctable errors on the |
| 5562 | * downstream port of the pci-e switch. |
| 5563 | */ |
| 5564 | if (adapter->flags & FLAG_IS_QUAD_PORT) { |
| 5565 | struct pci_dev *us_dev = pdev->bus->self; |
Jon Mason | 353064d | 2011-06-27 07:43:47 +0000 | [diff] [blame] | 5566 | int pos = pci_pcie_cap(us_dev); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5567 | u16 devctl; |
| 5568 | |
| 5569 | pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl); |
| 5570 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, |
| 5571 | (devctl & ~PCI_EXP_DEVCTL_CERE)); |
| 5572 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5573 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5574 | |
| 5575 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl); |
| 5576 | } else { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5577 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5578 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5579 | } |
| 5580 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5581 | #ifdef CONFIG_PCIEASPM |
| 5582 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
| 5583 | { |
Yinghai Lu | 9f728f5 | 2011-05-12 17:11:47 -0700 | [diff] [blame] | 5584 | pci_disable_link_state_locked(pdev, state); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5585 | } |
| 5586 | #else |
| 5587 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5588 | { |
| 5589 | int pos; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5590 | u16 reg16; |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5591 | |
| 5592 | /* |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5593 | * Both device and parent should have the same ASPM setting. |
| 5594 | * Disable ASPM in downstream component first and then upstream. |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5595 | */ |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5596 | pos = pci_pcie_cap(pdev); |
| 5597 | pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16); |
| 5598 | reg16 &= ~state; |
| 5599 | pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16); |
| 5600 | |
Anton Blanchard | 0c75ba2 | 2010-04-28 21:46:06 +0000 | [diff] [blame] | 5601 | if (!pdev->bus->self) |
| 5602 | return; |
| 5603 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5604 | pos = pci_pcie_cap(pdev->bus->self); |
| 5605 | pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, ®16); |
| 5606 | reg16 &= ~state; |
| 5607 | pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16); |
| 5608 | } |
| 5609 | #endif |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5610 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5611 | { |
| 5612 | dev_info(&pdev->dev, "Disabling ASPM %s %s\n", |
| 5613 | (state & PCIE_LINK_STATE_L0S) ? "L0s" : "", |
| 5614 | (state & PCIE_LINK_STATE_L1) ? "L1" : ""); |
| 5615 | |
| 5616 | __e1000e_disable_aspm(pdev, state); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5617 | } |
| 5618 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 5619 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5620 | static bool e1000e_pm_ready(struct e1000_adapter *adapter) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5621 | { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5622 | return !!adapter->tx_ring->buffer_info; |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5623 | } |
| 5624 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5625 | static int __e1000_resume(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5626 | { |
| 5627 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5628 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5629 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5630 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5631 | u32 err; |
| 5632 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5633 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5634 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
| 5635 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
| 5636 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5637 | if (aspm_disable_flag) |
| 5638 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 5639 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5640 | pci_set_power_state(pdev, PCI_D0); |
| 5641 | pci_restore_state(pdev); |
Bruce Allan | 28b8f04 | 2010-01-07 16:30:56 +0000 | [diff] [blame] | 5642 | pci_save_state(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5643 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5644 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5645 | if (netif_running(netdev)) { |
| 5646 | err = e1000_request_irq(adapter); |
| 5647 | if (err) |
| 5648 | return err; |
| 5649 | } |
| 5650 | |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5651 | if (hw->mac.type == e1000_pch2lan) |
| 5652 | e1000_resume_workarounds_pchlan(&adapter->hw); |
| 5653 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5654 | e1000e_power_up_phy(adapter); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5655 | |
| 5656 | /* report the system wakeup cause from S3/S4 */ |
| 5657 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
| 5658 | u16 phy_data; |
| 5659 | |
| 5660 | e1e_rphy(&adapter->hw, BM_WUS, &phy_data); |
| 5661 | if (phy_data) { |
| 5662 | e_info("PHY Wakeup cause - %s\n", |
| 5663 | phy_data & E1000_WUS_EX ? "Unicast Packet" : |
| 5664 | phy_data & E1000_WUS_MC ? "Multicast Packet" : |
| 5665 | phy_data & E1000_WUS_BC ? "Broadcast Packet" : |
| 5666 | phy_data & E1000_WUS_MAG ? "Magic Packet" : |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 5667 | phy_data & E1000_WUS_LNKC ? |
| 5668 | "Link Status Change" : "other"); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5669 | } |
| 5670 | e1e_wphy(&adapter->hw, BM_WUS, ~0); |
| 5671 | } else { |
| 5672 | u32 wus = er32(WUS); |
| 5673 | if (wus) { |
| 5674 | e_info("MAC Wakeup cause - %s\n", |
| 5675 | wus & E1000_WUS_EX ? "Unicast Packet" : |
| 5676 | wus & E1000_WUS_MC ? "Multicast Packet" : |
| 5677 | wus & E1000_WUS_BC ? "Broadcast Packet" : |
| 5678 | wus & E1000_WUS_MAG ? "Magic Packet" : |
| 5679 | wus & E1000_WUS_LNKC ? "Link Status Change" : |
| 5680 | "other"); |
| 5681 | } |
| 5682 | ew32(WUS, ~0); |
| 5683 | } |
| 5684 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5685 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5686 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 5687 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5688 | |
| 5689 | if (netif_running(netdev)) |
| 5690 | e1000e_up(adapter); |
| 5691 | |
| 5692 | netif_device_attach(netdev); |
| 5693 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5694 | /* |
| 5695 | * 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] | 5696 | * 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] | 5697 | * under the control of the driver. |
| 5698 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5699 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5700 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5701 | |
| 5702 | return 0; |
| 5703 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5704 | |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5705 | #ifdef CONFIG_PM_SLEEP |
| 5706 | static int e1000_suspend(struct device *dev) |
| 5707 | { |
| 5708 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5709 | int retval; |
| 5710 | bool wake; |
| 5711 | |
| 5712 | retval = __e1000_shutdown(pdev, &wake, false); |
| 5713 | if (!retval) |
| 5714 | e1000_complete_shutdown(pdev, true, wake); |
| 5715 | |
| 5716 | return retval; |
| 5717 | } |
| 5718 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5719 | static int e1000_resume(struct device *dev) |
| 5720 | { |
| 5721 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5722 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5723 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5724 | |
| 5725 | if (e1000e_pm_ready(adapter)) |
| 5726 | adapter->idle_check = true; |
| 5727 | |
| 5728 | return __e1000_resume(pdev); |
| 5729 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5730 | #endif /* CONFIG_PM_SLEEP */ |
| 5731 | |
| 5732 | #ifdef CONFIG_PM_RUNTIME |
| 5733 | static int e1000_runtime_suspend(struct device *dev) |
| 5734 | { |
| 5735 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5736 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5737 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5738 | |
| 5739 | if (e1000e_pm_ready(adapter)) { |
| 5740 | bool wake; |
| 5741 | |
| 5742 | __e1000_shutdown(pdev, &wake, true); |
| 5743 | } |
| 5744 | |
| 5745 | return 0; |
| 5746 | } |
| 5747 | |
| 5748 | static int e1000_idle(struct device *dev) |
| 5749 | { |
| 5750 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5751 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5752 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5753 | |
| 5754 | if (!e1000e_pm_ready(adapter)) |
| 5755 | return 0; |
| 5756 | |
| 5757 | if (adapter->idle_check) { |
| 5758 | adapter->idle_check = false; |
| 5759 | if (!e1000e_has_link(adapter)) |
| 5760 | pm_schedule_suspend(dev, MSEC_PER_SEC); |
| 5761 | } |
| 5762 | |
| 5763 | return -EBUSY; |
| 5764 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5765 | |
| 5766 | static int e1000_runtime_resume(struct device *dev) |
| 5767 | { |
| 5768 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5769 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5770 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5771 | |
| 5772 | if (!e1000e_pm_ready(adapter)) |
| 5773 | return 0; |
| 5774 | |
| 5775 | adapter->idle_check = !dev->power.runtime_auto; |
| 5776 | return __e1000_resume(pdev); |
| 5777 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5778 | #endif /* CONFIG_PM_RUNTIME */ |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 5779 | #endif /* CONFIG_PM */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5780 | |
| 5781 | static void e1000_shutdown(struct pci_dev *pdev) |
| 5782 | { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5783 | bool wake = false; |
| 5784 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5785 | __e1000_shutdown(pdev, &wake, false); |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5786 | |
| 5787 | if (system_state == SYSTEM_POWER_OFF) |
| 5788 | e1000_complete_shutdown(pdev, false, wake); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5792 | |
| 5793 | static irqreturn_t e1000_intr_msix(int irq, void *data) |
| 5794 | { |
| 5795 | struct net_device *netdev = data; |
| 5796 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5797 | |
| 5798 | if (adapter->msix_entries) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 5799 | int vector, msix_irq; |
| 5800 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5801 | vector = 0; |
| 5802 | msix_irq = adapter->msix_entries[vector].vector; |
| 5803 | disable_irq(msix_irq); |
| 5804 | e1000_intr_msix_rx(msix_irq, netdev); |
| 5805 | enable_irq(msix_irq); |
| 5806 | |
| 5807 | vector++; |
| 5808 | msix_irq = adapter->msix_entries[vector].vector; |
| 5809 | disable_irq(msix_irq); |
| 5810 | e1000_intr_msix_tx(msix_irq, netdev); |
| 5811 | enable_irq(msix_irq); |
| 5812 | |
| 5813 | vector++; |
| 5814 | msix_irq = adapter->msix_entries[vector].vector; |
| 5815 | disable_irq(msix_irq); |
| 5816 | e1000_msix_other(msix_irq, netdev); |
| 5817 | enable_irq(msix_irq); |
| 5818 | } |
| 5819 | |
| 5820 | return IRQ_HANDLED; |
| 5821 | } |
| 5822 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5823 | /* |
| 5824 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5825 | * without having to re-enable interrupts. It's not called while |
| 5826 | * the interrupt routine is executing. |
| 5827 | */ |
| 5828 | static void e1000_netpoll(struct net_device *netdev) |
| 5829 | { |
| 5830 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5831 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5832 | switch (adapter->int_mode) { |
| 5833 | case E1000E_INT_MODE_MSIX: |
| 5834 | e1000_intr_msix(adapter->pdev->irq, netdev); |
| 5835 | break; |
| 5836 | case E1000E_INT_MODE_MSI: |
| 5837 | disable_irq(adapter->pdev->irq); |
| 5838 | e1000_intr_msi(adapter->pdev->irq, netdev); |
| 5839 | enable_irq(adapter->pdev->irq); |
| 5840 | break; |
| 5841 | default: /* E1000E_INT_MODE_LEGACY */ |
| 5842 | disable_irq(adapter->pdev->irq); |
| 5843 | e1000_intr(adapter->pdev->irq, netdev); |
| 5844 | enable_irq(adapter->pdev->irq); |
| 5845 | break; |
| 5846 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5847 | } |
| 5848 | #endif |
| 5849 | |
| 5850 | /** |
| 5851 | * e1000_io_error_detected - called when PCI error is detected |
| 5852 | * @pdev: Pointer to PCI device |
| 5853 | * @state: The current pci connection state |
| 5854 | * |
| 5855 | * This function is called after a PCI bus error affecting |
| 5856 | * this device has been detected. |
| 5857 | */ |
| 5858 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 5859 | pci_channel_state_t state) |
| 5860 | { |
| 5861 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5862 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5863 | |
| 5864 | netif_device_detach(netdev); |
| 5865 | |
Mike Mason | c93b5a7 | 2009-06-30 12:45:53 +0000 | [diff] [blame] | 5866 | if (state == pci_channel_io_perm_failure) |
| 5867 | return PCI_ERS_RESULT_DISCONNECT; |
| 5868 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5869 | if (netif_running(netdev)) |
| 5870 | e1000e_down(adapter); |
| 5871 | pci_disable_device(pdev); |
| 5872 | |
| 5873 | /* Request a slot slot reset. */ |
| 5874 | return PCI_ERS_RESULT_NEED_RESET; |
| 5875 | } |
| 5876 | |
| 5877 | /** |
| 5878 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 5879 | * @pdev: Pointer to PCI device |
| 5880 | * |
| 5881 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5882 | * resembles the first-half of the e1000_resume routine. |
| 5883 | */ |
| 5884 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 5885 | { |
| 5886 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5887 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5888 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5889 | u16 aspm_disable_flag = 0; |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5890 | int err; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5891 | pci_ers_result_t result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5892 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5893 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5894 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5895 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5896 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5897 | if (aspm_disable_flag) |
| 5898 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 5899 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 5900 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5901 | if (err) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5902 | dev_err(&pdev->dev, |
| 5903 | "Cannot re-enable PCI device after reset.\n"); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5904 | result = PCI_ERS_RESULT_DISCONNECT; |
| 5905 | } else { |
| 5906 | pci_set_master(pdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5907 | pdev->state_saved = true; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5908 | pci_restore_state(pdev); |
| 5909 | |
| 5910 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5911 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 5912 | |
| 5913 | e1000e_reset(adapter); |
| 5914 | ew32(WUS, ~0); |
| 5915 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5916 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5917 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5918 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5919 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5920 | return result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | /** |
| 5924 | * e1000_io_resume - called when traffic can start flowing again. |
| 5925 | * @pdev: Pointer to PCI device |
| 5926 | * |
| 5927 | * This callback is called when the error recovery driver tells us that |
| 5928 | * its OK to resume normal operation. Implementation resembles the |
| 5929 | * second-half of the e1000_resume routine. |
| 5930 | */ |
| 5931 | static void e1000_io_resume(struct pci_dev *pdev) |
| 5932 | { |
| 5933 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5934 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5935 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 5936 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5937 | |
| 5938 | if (netif_running(netdev)) { |
| 5939 | if (e1000e_up(adapter)) { |
| 5940 | dev_err(&pdev->dev, |
| 5941 | "can't bring device back up after reset\n"); |
| 5942 | return; |
| 5943 | } |
| 5944 | } |
| 5945 | |
| 5946 | netif_device_attach(netdev); |
| 5947 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5948 | /* |
| 5949 | * 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] | 5950 | * 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] | 5951 | * under the control of the driver. |
| 5952 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5953 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5954 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5955 | |
| 5956 | } |
| 5957 | |
| 5958 | static void e1000_print_device_info(struct e1000_adapter *adapter) |
| 5959 | { |
| 5960 | struct e1000_hw *hw = &adapter->hw; |
| 5961 | struct net_device *netdev = adapter->netdev; |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5962 | u32 ret_val; |
| 5963 | u8 pba_str[E1000_PBANUM_LENGTH]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5964 | |
| 5965 | /* print bus type/speed/width info */ |
Bruce Allan | a5cc764 | 2011-03-19 00:31:23 +0000 | [diff] [blame] | 5966 | e_info("(PCI Express:2.5GT/s:%s) %pM\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5967 | /* bus width */ |
| 5968 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
| 5969 | "Width x1"), |
| 5970 | /* MAC address */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5971 | netdev->dev_addr); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5972 | e_info("Intel(R) PRO/%s Network Connection\n", |
| 5973 | (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5974 | ret_val = e1000_read_pba_string_generic(hw, pba_str, |
| 5975 | E1000_PBANUM_LENGTH); |
| 5976 | if (ret_val) |
Bruce Allan | e0dc4f1 | 2011-01-06 14:29:50 +0000 | [diff] [blame] | 5977 | strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5978 | e_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 5979 | hw->mac.type, hw->phy.type, pba_str); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5980 | } |
| 5981 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5982 | static void e1000_eeprom_checks(struct e1000_adapter *adapter) |
| 5983 | { |
| 5984 | struct e1000_hw *hw = &adapter->hw; |
| 5985 | int ret_val; |
| 5986 | u16 buf = 0; |
| 5987 | |
| 5988 | if (hw->mac.type != e1000_82573) |
| 5989 | return; |
| 5990 | |
| 5991 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 5992 | if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) { |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5993 | /* Deep Smart Power Down (DSPD) */ |
Frans Pop | 6c2a9ef | 2008-09-22 14:52:22 -0700 | [diff] [blame] | 5994 | dev_warn(&adapter->pdev->dev, |
| 5995 | "Warning: detected DSPD enabled in EEPROM\n"); |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5996 | } |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5997 | } |
| 5998 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 5999 | static int e1000_set_features(struct net_device *netdev, |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 6000 | netdev_features_t features) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6001 | { |
| 6002 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 6003 | netdev_features_t changed = features ^ netdev->features; |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6004 | |
| 6005 | if (changed & (NETIF_F_TSO | NETIF_F_TSO6)) |
| 6006 | adapter->flags |= FLAG_TSO_FORCE; |
| 6007 | |
| 6008 | if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 6009 | NETIF_F_RXCSUM | NETIF_F_RXHASH))) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6010 | return 0; |
| 6011 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 6012 | /* |
| 6013 | * IP payload checksum (enabled with jumbos/packet-split when Rx |
| 6014 | * checksum is enabled) and generation of RSS hash is mutually |
| 6015 | * exclusive in the hardware. |
| 6016 | */ |
| 6017 | if (adapter->rx_ps_pages && |
| 6018 | (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) { |
| 6019 | e_err("Enabling both receive checksum offload and receive hashing is not possible with jumbo frames. Disable jumbos or enable only one of the receive offload features.\n"); |
| 6020 | return -EINVAL; |
| 6021 | } |
| 6022 | |
| 6023 | netdev->features = features; |
| 6024 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6025 | if (netif_running(netdev)) |
| 6026 | e1000e_reinit_locked(adapter); |
| 6027 | else |
| 6028 | e1000e_reset(adapter); |
| 6029 | |
| 6030 | return 0; |
| 6031 | } |
| 6032 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6033 | static const struct net_device_ops e1000e_netdev_ops = { |
| 6034 | .ndo_open = e1000_open, |
| 6035 | .ndo_stop = e1000_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 6036 | .ndo_start_xmit = e1000_xmit_frame, |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6037 | .ndo_get_stats64 = e1000e_get_stats64, |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 6038 | .ndo_set_rx_mode = e1000e_set_rx_mode, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6039 | .ndo_set_mac_address = e1000_set_mac, |
| 6040 | .ndo_change_mtu = e1000_change_mtu, |
| 6041 | .ndo_do_ioctl = e1000_ioctl, |
| 6042 | .ndo_tx_timeout = e1000_tx_timeout, |
| 6043 | .ndo_validate_addr = eth_validate_addr, |
| 6044 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6045 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 6046 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 6047 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6048 | .ndo_poll_controller = e1000_netpoll, |
| 6049 | #endif |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6050 | .ndo_set_features = e1000_set_features, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6051 | }; |
| 6052 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6053 | /** |
| 6054 | * e1000_probe - Device Initialization Routine |
| 6055 | * @pdev: PCI device information struct |
| 6056 | * @ent: entry in e1000_pci_tbl |
| 6057 | * |
| 6058 | * Returns 0 on success, negative on failure |
| 6059 | * |
| 6060 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 6061 | * The OS initialization, configuring of the adapter private structure, |
| 6062 | * and a hardware reset occur. |
| 6063 | **/ |
| 6064 | static int __devinit e1000_probe(struct pci_dev *pdev, |
| 6065 | const struct pci_device_id *ent) |
| 6066 | { |
| 6067 | struct net_device *netdev; |
| 6068 | struct e1000_adapter *adapter; |
| 6069 | struct e1000_hw *hw; |
| 6070 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; |
Becky Bruce | f47e81f | 2008-05-01 18:03:11 -0500 | [diff] [blame] | 6071 | resource_size_t mmio_start, mmio_len; |
| 6072 | resource_size_t flash_start, flash_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6073 | |
| 6074 | static int cards_found; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6075 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6076 | int i, err, pci_using_dac; |
| 6077 | u16 eeprom_data = 0; |
| 6078 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
| 6079 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6080 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 6081 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6082 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6083 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 6084 | if (aspm_disable_flag) |
| 6085 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6086 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6087 | err = pci_enable_device_mem(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6088 | if (err) |
| 6089 | return err; |
| 6090 | |
| 6091 | pci_using_dac = 0; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6092 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6093 | if (!err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6094 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6095 | if (!err) |
| 6096 | pci_using_dac = 1; |
| 6097 | } else { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6098 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6099 | if (err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6100 | err = dma_set_coherent_mask(&pdev->dev, |
| 6101 | DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6102 | if (err) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 6103 | dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6104 | goto err_dma; |
| 6105 | } |
| 6106 | } |
| 6107 | } |
| 6108 | |
Arjan van de Ven | e8de148 | 2008-10-22 19:55:31 -0700 | [diff] [blame] | 6109 | err = pci_request_selected_regions_exclusive(pdev, |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6110 | pci_select_bars(pdev, IORESOURCE_MEM), |
| 6111 | e1000e_driver_name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6112 | if (err) |
| 6113 | goto err_pci_reg; |
| 6114 | |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 6115 | /* AER (Advanced Error Reporting) hooks */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6116 | pci_enable_pcie_error_reporting(pdev); |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 6117 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6118 | pci_set_master(pdev); |
Bruce Allan | 438b365 | 2008-11-21 16:51:33 -0800 | [diff] [blame] | 6119 | /* PCI config space info */ |
| 6120 | err = pci_save_state(pdev); |
| 6121 | if (err) |
| 6122 | goto err_alloc_etherdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6123 | |
| 6124 | err = -ENOMEM; |
| 6125 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
| 6126 | if (!netdev) |
| 6127 | goto err_alloc_etherdev; |
| 6128 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6129 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 6130 | |
Tom Herbert | f85e4df | 2010-05-05 14:03:32 +0000 | [diff] [blame] | 6131 | netdev->irq = pdev->irq; |
| 6132 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6133 | pci_set_drvdata(pdev, netdev); |
| 6134 | adapter = netdev_priv(netdev); |
| 6135 | hw = &adapter->hw; |
| 6136 | adapter->netdev = netdev; |
| 6137 | adapter->pdev = pdev; |
| 6138 | adapter->ei = ei; |
| 6139 | adapter->pba = ei->pba; |
| 6140 | adapter->flags = ei->flags; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 6141 | adapter->flags2 = ei->flags2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6142 | adapter->hw.adapter = adapter; |
| 6143 | adapter->hw.mac.type = ei->mac; |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 6144 | adapter->max_hw_frame_size = ei->max_hw_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6145 | adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; |
| 6146 | |
| 6147 | mmio_start = pci_resource_start(pdev, 0); |
| 6148 | mmio_len = pci_resource_len(pdev, 0); |
| 6149 | |
| 6150 | err = -EIO; |
| 6151 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 6152 | if (!adapter->hw.hw_addr) |
| 6153 | goto err_ioremap; |
| 6154 | |
| 6155 | if ((adapter->flags & FLAG_HAS_FLASH) && |
| 6156 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
| 6157 | flash_start = pci_resource_start(pdev, 1); |
| 6158 | flash_len = pci_resource_len(pdev, 1); |
| 6159 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
| 6160 | if (!adapter->hw.flash_address) |
| 6161 | goto err_flashmap; |
| 6162 | } |
| 6163 | |
| 6164 | /* construct the net_device struct */ |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6165 | netdev->netdev_ops = &e1000e_netdev_ops; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6166 | e1000e_set_ethtool_ops(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6167 | netdev->watchdog_timeo = 5 * HZ; |
| 6168 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6169 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
| 6170 | |
| 6171 | netdev->mem_start = mmio_start; |
| 6172 | netdev->mem_end = mmio_start + mmio_len; |
| 6173 | |
| 6174 | adapter->bd_number = cards_found++; |
| 6175 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6176 | e1000e_check_options(adapter); |
| 6177 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6178 | /* setup adapter struct */ |
| 6179 | err = e1000_sw_init(adapter); |
| 6180 | if (err) |
| 6181 | goto err_sw_init; |
| 6182 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6183 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 6184 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 6185 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 6186 | |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 6187 | err = ei->get_variants(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6188 | if (err) |
| 6189 | goto err_hw_init; |
| 6190 | |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 6191 | if ((adapter->flags & FLAG_IS_ICH) && |
| 6192 | (adapter->flags & FLAG_READ_ONLY_NVM)) |
| 6193 | e1000e_write_protect_nvm_ich8lan(&adapter->hw); |
| 6194 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6195 | hw->mac.ops.get_bus_info(&adapter->hw); |
| 6196 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6197 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6198 | |
| 6199 | /* Copper options */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6200 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6201 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
| 6202 | adapter->hw.phy.disable_polarity_correction = 0; |
| 6203 | adapter->hw.phy.ms_type = e1000_ms_hw_default; |
| 6204 | } |
| 6205 | |
| 6206 | if (e1000_check_reset_block(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6207 | e_info("PHY reset is blocked due to SOL/IDER session.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6208 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6209 | /* Set initial default active device features */ |
| 6210 | netdev->features = (NETIF_F_SG | |
| 6211 | NETIF_F_HW_VLAN_RX | |
| 6212 | NETIF_F_HW_VLAN_TX | |
| 6213 | NETIF_F_TSO | |
| 6214 | NETIF_F_TSO6 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 6215 | NETIF_F_RXHASH | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6216 | NETIF_F_RXCSUM | |
| 6217 | NETIF_F_HW_CSUM); |
| 6218 | |
| 6219 | /* Set user-changeable features (subset of all device features) */ |
| 6220 | netdev->hw_features = netdev->features; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6221 | |
| 6222 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
| 6223 | netdev->features |= NETIF_F_HW_VLAN_FILTER; |
| 6224 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6225 | netdev->vlan_features |= (NETIF_F_SG | |
| 6226 | NETIF_F_TSO | |
| 6227 | NETIF_F_TSO6 | |
| 6228 | NETIF_F_HW_CSUM); |
Jeff Kirsher | a5136e2 | 2008-06-05 04:07:28 -0700 | [diff] [blame] | 6229 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 6230 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 6231 | |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 6232 | if (pci_using_dac) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6233 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 6234 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 6235 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6236 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6237 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
| 6238 | adapter->flags |= FLAG_MNG_PT_ENABLED; |
| 6239 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6240 | /* |
| 6241 | * before reading the NVM, reset the controller to |
| 6242 | * put the device in a known good starting state |
| 6243 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6244 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 6245 | |
| 6246 | /* |
| 6247 | * systems with ASPM and others may see the checksum fail on the first |
| 6248 | * attempt. Let's give it a few tries |
| 6249 | */ |
| 6250 | for (i = 0;; i++) { |
| 6251 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) |
| 6252 | break; |
| 6253 | if (i == 2) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6254 | e_err("The NVM Checksum Is Not Valid\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6255 | err = -EIO; |
| 6256 | goto err_eeprom; |
| 6257 | } |
| 6258 | } |
| 6259 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6260 | e1000_eeprom_checks(adapter); |
| 6261 | |
Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 6262 | /* copy the MAC address */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6263 | if (e1000e_read_mac_addr(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6264 | e_err("NVM Read Error while reading MAC address\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6265 | |
| 6266 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 6267 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 6268 | |
| 6269 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 6270 | e_err("Invalid MAC Address: %pM\n", netdev->perm_addr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6271 | err = -EIO; |
| 6272 | goto err_eeprom; |
| 6273 | } |
| 6274 | |
| 6275 | init_timer(&adapter->watchdog_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6276 | adapter->watchdog_timer.function = e1000_watchdog; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6277 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 6278 | |
| 6279 | init_timer(&adapter->phy_info_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6280 | adapter->phy_info_timer.function = e1000_update_phy_info; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6281 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 6282 | |
| 6283 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
| 6284 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 6285 | INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); |
| 6286 | INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6287 | INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6288 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6289 | /* Initialize link parameters. User can change them with ethtool */ |
| 6290 | adapter->hw.mac.autoneg = 1; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6291 | adapter->fc_autoneg = true; |
Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 6292 | adapter->hw.fc.requested_mode = e1000_fc_default; |
| 6293 | adapter->hw.fc.current_mode = e1000_fc_default; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6294 | adapter->hw.phy.autoneg_advertised = 0x2f; |
| 6295 | |
| 6296 | /* ring size defaults */ |
| 6297 | adapter->rx_ring->count = 256; |
| 6298 | adapter->tx_ring->count = 256; |
| 6299 | |
| 6300 | /* |
| 6301 | * Initial Wake on LAN setting - If APM wake is enabled in |
| 6302 | * the EEPROM, enable the ACPI Magic Packet filter |
| 6303 | */ |
| 6304 | if (adapter->flags & FLAG_APME_IN_WUC) { |
| 6305 | /* APME bit in EEPROM is mapped to WUC.APME */ |
| 6306 | eeprom_data = er32(WUC); |
| 6307 | eeprom_apme_mask = E1000_WUC_APME; |
Bruce Allan | 4def99b | 2011-02-02 09:30:36 +0000 | [diff] [blame] | 6308 | if ((hw->mac.type > e1000_ich10lan) && |
| 6309 | (eeprom_data & E1000_WUC_PHY_WAKE)) |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6310 | adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6311 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
| 6312 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && |
| 6313 | (adapter->hw.bus.func == 1)) |
| 6314 | e1000_read_nvm(&adapter->hw, |
| 6315 | NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 6316 | else |
| 6317 | e1000_read_nvm(&adapter->hw, |
| 6318 | NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 6319 | } |
| 6320 | |
| 6321 | /* fetch WoL from EEPROM */ |
| 6322 | if (eeprom_data & eeprom_apme_mask) |
| 6323 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 6324 | |
| 6325 | /* |
| 6326 | * now that we have the eeprom settings, apply the special cases |
| 6327 | * where the eeprom may be wrong or the board simply won't support |
| 6328 | * wake on lan on a particular port |
| 6329 | */ |
| 6330 | if (!(adapter->flags & FLAG_HAS_WOL)) |
| 6331 | adapter->eeprom_wol = 0; |
| 6332 | |
| 6333 | /* initialize the wol settings based on the eeprom settings */ |
| 6334 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | 6ff6802 | 2008-11-12 09:52:32 +0000 | [diff] [blame] | 6335 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6336 | |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 6337 | /* save off EEPROM version number */ |
| 6338 | e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); |
| 6339 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6340 | /* reset the hardware with the new settings */ |
| 6341 | e1000e_reset(adapter); |
| 6342 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6343 | /* |
| 6344 | * 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] | 6345 | * 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] | 6346 | * under the control of the driver. |
| 6347 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6348 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6349 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6350 | |
Bruce Allan | e0dc4f1 | 2011-01-06 14:29:50 +0000 | [diff] [blame] | 6351 | strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6352 | err = register_netdev(netdev); |
| 6353 | if (err) |
| 6354 | goto err_register; |
| 6355 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 6356 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 6357 | netif_carrier_off(netdev); |
| 6358 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6359 | e1000_print_device_info(adapter); |
| 6360 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6361 | if (pci_dev_run_wake(pdev)) |
| 6362 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6363 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6364 | return 0; |
| 6365 | |
| 6366 | err_register: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6367 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6368 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6369 | err_eeprom: |
| 6370 | if (!e1000_check_reset_block(&adapter->hw)) |
| 6371 | e1000_phy_hw_reset(&adapter->hw); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6372 | err_hw_init: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6373 | kfree(adapter->tx_ring); |
| 6374 | kfree(adapter->rx_ring); |
| 6375 | err_sw_init: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6376 | if (adapter->hw.flash_address) |
| 6377 | iounmap(adapter->hw.flash_address); |
Jeff Kirsher | e82f54b | 2008-11-14 06:45:07 +0000 | [diff] [blame] | 6378 | e1000e_reset_interrupt_capability(adapter); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6379 | err_flashmap: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6380 | iounmap(adapter->hw.hw_addr); |
| 6381 | err_ioremap: |
| 6382 | free_netdev(netdev); |
| 6383 | err_alloc_etherdev: |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6384 | pci_release_selected_regions(pdev, |
| 6385 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6386 | err_pci_reg: |
| 6387 | err_dma: |
| 6388 | pci_disable_device(pdev); |
| 6389 | return err; |
| 6390 | } |
| 6391 | |
| 6392 | /** |
| 6393 | * e1000_remove - Device Removal Routine |
| 6394 | * @pdev: PCI device information struct |
| 6395 | * |
| 6396 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 6397 | * that it should release a PCI device. The could be caused by a |
| 6398 | * Hot-Plug event, or because the driver is going to be removed from |
| 6399 | * memory. |
| 6400 | **/ |
| 6401 | static void __devexit e1000_remove(struct pci_dev *pdev) |
| 6402 | { |
| 6403 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6404 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6405 | bool down = test_bit(__E1000_DOWN, &adapter->state); |
| 6406 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6407 | /* |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 6408 | * The timers may be rescheduled, so explicitly disable them |
| 6409 | * from being rescheduled. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6410 | */ |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6411 | if (!down) |
| 6412 | set_bit(__E1000_DOWN, &adapter->state); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6413 | del_timer_sync(&adapter->watchdog_timer); |
| 6414 | del_timer_sync(&adapter->phy_info_timer); |
| 6415 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6416 | cancel_work_sync(&adapter->reset_task); |
| 6417 | cancel_work_sync(&adapter->watchdog_task); |
| 6418 | cancel_work_sync(&adapter->downshift_task); |
| 6419 | cancel_work_sync(&adapter->update_phy_task); |
| 6420 | cancel_work_sync(&adapter->print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6421 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6422 | if (!(netdev->flags & IFF_UP)) |
| 6423 | e1000_power_down_phy(adapter); |
| 6424 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6425 | /* Don't lie to e1000_close() down the road. */ |
| 6426 | if (!down) |
| 6427 | clear_bit(__E1000_DOWN, &adapter->state); |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6428 | unregister_netdev(netdev); |
| 6429 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6430 | if (pci_dev_run_wake(pdev)) |
| 6431 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6432 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6433 | /* |
| 6434 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 6435 | * would have already happened in close and is redundant. |
| 6436 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6437 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6438 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6439 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6440 | kfree(adapter->tx_ring); |
| 6441 | kfree(adapter->rx_ring); |
| 6442 | |
| 6443 | iounmap(adapter->hw.hw_addr); |
| 6444 | if (adapter->hw.flash_address) |
| 6445 | iounmap(adapter->hw.flash_address); |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6446 | pci_release_selected_regions(pdev, |
| 6447 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6448 | |
| 6449 | free_netdev(netdev); |
| 6450 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6451 | /* AER disable */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6452 | pci_disable_pcie_error_reporting(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6453 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6454 | pci_disable_device(pdev); |
| 6455 | } |
| 6456 | |
| 6457 | /* PCI Error Recovery (ERS) */ |
| 6458 | static struct pci_error_handlers e1000_err_handler = { |
| 6459 | .error_detected = e1000_io_error_detected, |
| 6460 | .slot_reset = e1000_io_slot_reset, |
| 6461 | .resume = e1000_io_resume, |
| 6462 | }; |
| 6463 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 6464 | static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6465 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
| 6466 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, |
| 6467 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, |
| 6468 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 }, |
| 6469 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
| 6470 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, |
Auke Kok | 040babf | 2007-10-31 15:22:05 -0700 | [diff] [blame] | 6471 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
| 6472 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, |
| 6473 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6474 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6475 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
| 6476 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, |
| 6477 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, |
| 6478 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6479 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6480 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
| 6481 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, |
| 6482 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6483 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6484 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, |
Bruce Allan | bef28b1 | 2009-03-24 23:28:02 -0700 | [diff] [blame] | 6485 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 6486 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6487 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6488 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
| 6489 | board_80003es2lan }, |
| 6490 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), |
| 6491 | board_80003es2lan }, |
| 6492 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), |
| 6493 | board_80003es2lan }, |
| 6494 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), |
| 6495 | board_80003es2lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6496 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6497 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
| 6498 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, |
| 6499 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, |
| 6500 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, |
| 6501 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, |
| 6502 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, |
| 6503 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, |
Bruce Allan | 9e135a2 | 2009-12-01 15:50:31 +0000 | [diff] [blame] | 6504 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6505 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6506 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
| 6507 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, |
| 6508 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, |
| 6509 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, |
| 6510 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, |
Bruce Allan | 2f15f9d | 2008-08-26 18:36:36 -0700 | [diff] [blame] | 6511 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6512 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, |
| 6513 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, |
| 6514 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, |
| 6515 | |
| 6516 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, |
| 6517 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, |
| 6518 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6519 | |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6520 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, |
| 6521 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, |
Bruce Allan | 10df0b9 | 2010-05-10 15:02:52 +0000 | [diff] [blame] | 6522 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan }, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6523 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6524 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, |
| 6525 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, |
| 6526 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, |
| 6527 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, |
| 6528 | |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 6529 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan }, |
| 6530 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan }, |
| 6531 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6532 | { } /* terminate list */ |
| 6533 | }; |
| 6534 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 6535 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6536 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6537 | static const struct dev_pm_ops e1000_pm_ops = { |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6538 | SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume) |
| 6539 | SET_RUNTIME_PM_OPS(e1000_runtime_suspend, |
| 6540 | e1000_runtime_resume, e1000_idle) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6541 | }; |
David S. Miller | e50208a | 2010-03-16 23:36:24 -0700 | [diff] [blame] | 6542 | #endif |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6543 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6544 | /* PCI Device API Driver */ |
| 6545 | static struct pci_driver e1000_driver = { |
| 6546 | .name = e1000e_driver_name, |
| 6547 | .id_table = e1000_pci_tbl, |
| 6548 | .probe = e1000_probe, |
| 6549 | .remove = __devexit_p(e1000_remove), |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6550 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6551 | .driver.pm = &e1000_pm_ops, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6552 | #endif |
| 6553 | .shutdown = e1000_shutdown, |
| 6554 | .err_handler = &e1000_err_handler |
| 6555 | }; |
| 6556 | |
| 6557 | /** |
| 6558 | * e1000_init_module - Driver Registration Routine |
| 6559 | * |
| 6560 | * e1000_init_module is the first routine called when the driver is |
| 6561 | * loaded. All it does is register with the PCI subsystem. |
| 6562 | **/ |
| 6563 | static int __init e1000_init_module(void) |
| 6564 | { |
| 6565 | int ret; |
Bruce Allan | 8544b9f | 2010-03-24 12:55:30 +0000 | [diff] [blame] | 6566 | pr_info("Intel(R) PRO/1000 Network Driver - %s\n", |
| 6567 | e1000e_driver_version); |
Bruce Allan | 0d6057e | 2011-01-04 01:16:44 +0000 | [diff] [blame] | 6568 | pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6569 | ret = pci_register_driver(&e1000_driver); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 6570 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6571 | return ret; |
| 6572 | } |
| 6573 | module_init(e1000_init_module); |
| 6574 | |
| 6575 | /** |
| 6576 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 6577 | * |
| 6578 | * e1000_exit_module is called just before the driver is removed |
| 6579 | * from memory. |
| 6580 | **/ |
| 6581 | static void __exit e1000_exit_module(void) |
| 6582 | { |
| 6583 | pci_unregister_driver(&e1000_driver); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6584 | } |
| 6585 | module_exit(e1000_exit_module); |
| 6586 | |
| 6587 | |
| 6588 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 6589 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 6590 | MODULE_LICENSE("GPL"); |
| 6591 | MODULE_VERSION(DRV_VERSION); |
| 6592 | |
| 6593 | /* e1000_main.c */ |