Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel PRO/1000 Linux driver |
Bruce Allan | f5e261e | 2012-01-01 16:00:03 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2012 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 | 058e8ed | 2011-12-16 00:47:04 +0000 | [diff] [blame] | 59 | #define DRV_VERSION "1.9.5" 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 */ |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 140 | {0, NULL} |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 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 { |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 186 | __le64 a; |
| 187 | __le64 b; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 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 { |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 194 | __le64 a; |
| 195 | __le64 b; |
| 196 | __le64 c; |
| 197 | __le64 d; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 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)) |
Bruce Allan | fe1e980 | 2012-01-31 06:37:54 +0000 | [diff] [blame] | 224 | return; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 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)) |
Bruce Allan | fe1e980 | 2012-01-31 06:37:54 +0000 | [diff] [blame] | 311 | return; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 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 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 454 | /** |
| 455 | * e1000_desc_unused - calculate if we have unused descriptors |
| 456 | **/ |
| 457 | static int e1000_desc_unused(struct e1000_ring *ring) |
| 458 | { |
| 459 | if (ring->next_to_clean > ring->next_to_use) |
| 460 | return ring->next_to_clean - ring->next_to_use - 1; |
| 461 | |
| 462 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; |
| 463 | } |
| 464 | |
| 465 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 466 | * e1000_receive_skb - helper function to handle Rx indications |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 467 | * @adapter: board private structure |
| 468 | * @status: descriptor status field as written by hardware |
| 469 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
| 470 | * @skb: pointer to sk_buff to be indicated to stack |
| 471 | **/ |
| 472 | static void e1000_receive_skb(struct e1000_adapter *adapter, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 473 | struct net_device *netdev, struct sk_buff *skb, |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 474 | u8 status, __le16 vlan) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 475 | { |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 476 | u16 tag = le16_to_cpu(vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 477 | skb->protocol = eth_type_trans(skb, netdev); |
| 478 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 479 | if (status & E1000_RXD_STAT_VP) |
| 480 | __vlan_hwaccel_put_tag(skb, tag); |
| 481 | |
| 482 | napi_gro_receive(&adapter->napi, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 486 | * e1000_rx_checksum - Receive Checksum Offload |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 487 | * @adapter: board private structure |
| 488 | * @status_err: receive descriptor status and error fields |
| 489 | * @csum: receive descriptor csum field |
| 490 | * @sk_buff: socket buffer with received data |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 491 | **/ |
| 492 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 493 | __le16 csum, struct sk_buff *skb) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 494 | { |
| 495 | u16 status = (u16)status_err; |
| 496 | u8 errors = (u8)(status_err >> 24); |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 497 | |
| 498 | skb_checksum_none_assert(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 499 | |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 500 | /* Rx checksum disabled */ |
| 501 | if (!(adapter->netdev->features & NETIF_F_RXCSUM)) |
| 502 | return; |
| 503 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 504 | /* Ignore Checksum bit is set */ |
| 505 | if (status & E1000_RXD_STAT_IXSM) |
| 506 | return; |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 507 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 508 | /* TCP/UDP checksum error bit is set */ |
| 509 | if (errors & E1000_RXD_ERR_TCPE) { |
| 510 | /* let the stack verify checksum errors */ |
| 511 | adapter->hw_csum_err++; |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | /* TCP/UDP Checksum has not been calculated */ |
| 516 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
| 517 | return; |
| 518 | |
| 519 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 520 | if (status & E1000_RXD_STAT_TCPCS) { |
| 521 | /* TCP checksum is good */ |
| 522 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 523 | } else { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 524 | /* |
| 525 | * IP fragment with UDP payload |
| 526 | * Hardware complements the payload checksum, so we undo it |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 527 | * and then put the value in host order for further stack use. |
| 528 | */ |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 529 | __sum16 sum = (__force __sum16)swab16((__force u16)csum); |
Al Viro | a39fe74 | 2007-12-11 19:50:34 +0000 | [diff] [blame] | 530 | skb->csum = csum_unfold(~sum); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 531 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 532 | } |
| 533 | adapter->hw_csum_good++; |
| 534 | } |
| 535 | |
| 536 | /** |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 537 | * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa() |
| 538 | * @hw: pointer to the HW structure |
| 539 | * @tail: address of tail descriptor register |
| 540 | * @i: value to write to tail descriptor register |
| 541 | * |
| 542 | * When updating the tail register, the ME could be accessing Host CSR |
| 543 | * registers at the same time. Normally, this is handled in h/w by an |
| 544 | * arbiter but on some parts there is a bug that acknowledges Host accesses |
| 545 | * later than it should which could result in the descriptor register to |
| 546 | * have an incorrect value. Workaround this by checking the FWSM register |
| 547 | * which has bit 24 set while ME is accessing Host CSR registers, wait |
| 548 | * if it is set and try again a number of times. |
| 549 | **/ |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 550 | 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] | 551 | unsigned int i) |
| 552 | { |
| 553 | unsigned int j = 0; |
| 554 | |
| 555 | while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) && |
| 556 | (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI)) |
| 557 | udelay(50); |
| 558 | |
| 559 | writel(i, tail); |
| 560 | |
| 561 | if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail))) |
| 562 | return E1000_ERR_SWFW_SYNC; |
| 563 | |
| 564 | return 0; |
| 565 | } |
| 566 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 567 | static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i) |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 568 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 569 | struct e1000_adapter *adapter = rx_ring->adapter; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 570 | struct e1000_hw *hw = &adapter->hw; |
| 571 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 572 | if (e1000e_update_tail_wa(hw, rx_ring->tail, i)) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 573 | u32 rctl = er32(RCTL); |
| 574 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 575 | e_err("ME firmware caused invalid RDT - resetting\n"); |
| 576 | schedule_work(&adapter->reset_task); |
| 577 | } |
| 578 | } |
| 579 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 580 | static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i) |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 581 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 582 | struct e1000_adapter *adapter = tx_ring->adapter; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 583 | struct e1000_hw *hw = &adapter->hw; |
| 584 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 585 | if (e1000e_update_tail_wa(hw, tx_ring->tail, i)) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 586 | u32 tctl = er32(TCTL); |
| 587 | ew32(TCTL, tctl & ~E1000_TCTL_EN); |
| 588 | e_err("ME firmware caused invalid TDT - resetting\n"); |
| 589 | schedule_work(&adapter->reset_task); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | /** |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 594 | * e1000_alloc_rx_buffers - Replace used receive buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 595 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 596 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 597 | static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 598 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 599 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 600 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 601 | struct net_device *netdev = adapter->netdev; |
| 602 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 603 | union e1000_rx_desc_extended *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 604 | struct e1000_buffer *buffer_info; |
| 605 | struct sk_buff *skb; |
| 606 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 607 | unsigned int bufsz = adapter->rx_buffer_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 608 | |
| 609 | i = rx_ring->next_to_use; |
| 610 | buffer_info = &rx_ring->buffer_info[i]; |
| 611 | |
| 612 | while (cleaned_count--) { |
| 613 | skb = buffer_info->skb; |
| 614 | if (skb) { |
| 615 | skb_trim(skb, 0); |
| 616 | goto map_skb; |
| 617 | } |
| 618 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 619 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 620 | if (!skb) { |
| 621 | /* Better luck next round */ |
| 622 | adapter->alloc_rx_buff_failed++; |
| 623 | break; |
| 624 | } |
| 625 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 626 | buffer_info->skb = skb; |
| 627 | map_skb: |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 628 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 629 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 630 | DMA_FROM_DEVICE); |
| 631 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 632 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 633 | adapter->rx_dma_failed++; |
| 634 | break; |
| 635 | } |
| 636 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 637 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 638 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 639 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 640 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
| 641 | /* |
| 642 | * Force memory writes to complete before letting h/w |
| 643 | * know there are new descriptors to fetch. (Only |
| 644 | * applicable for weak-ordered memory model archs, |
| 645 | * such as IA-64). |
| 646 | */ |
| 647 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 648 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 649 | e1000e_update_rdt_wa(rx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 650 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 651 | writel(i, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 652 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 653 | i++; |
| 654 | if (i == rx_ring->count) |
| 655 | i = 0; |
| 656 | buffer_info = &rx_ring->buffer_info[i]; |
| 657 | } |
| 658 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 659 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | /** |
| 663 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 664 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 665 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 666 | static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 667 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 668 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 669 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 670 | struct net_device *netdev = adapter->netdev; |
| 671 | struct pci_dev *pdev = adapter->pdev; |
| 672 | union e1000_rx_desc_packet_split *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 673 | struct e1000_buffer *buffer_info; |
| 674 | struct e1000_ps_page *ps_page; |
| 675 | struct sk_buff *skb; |
| 676 | unsigned int i, j; |
| 677 | |
| 678 | i = rx_ring->next_to_use; |
| 679 | buffer_info = &rx_ring->buffer_info[i]; |
| 680 | |
| 681 | while (cleaned_count--) { |
| 682 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 683 | |
| 684 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 685 | ps_page = &buffer_info->ps_pages[j]; |
| 686 | if (j >= adapter->rx_ps_pages) { |
| 687 | /* all unused desc entries get hw null ptr */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 688 | rx_desc->read.buffer_addr[j + 1] = |
| 689 | ~cpu_to_le64(0); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 690 | continue; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 691 | } |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 692 | if (!ps_page->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 693 | ps_page->page = alloc_page(gfp); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 694 | if (!ps_page->page) { |
| 695 | adapter->alloc_rx_buff_failed++; |
| 696 | goto no_buffers; |
| 697 | } |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 698 | ps_page->dma = dma_map_page(&pdev->dev, |
| 699 | ps_page->page, |
| 700 | 0, PAGE_SIZE, |
| 701 | DMA_FROM_DEVICE); |
| 702 | if (dma_mapping_error(&pdev->dev, |
| 703 | ps_page->dma)) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 704 | dev_err(&adapter->pdev->dev, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 705 | "Rx DMA page map failed\n"); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 706 | adapter->rx_dma_failed++; |
| 707 | goto no_buffers; |
| 708 | } |
| 709 | } |
| 710 | /* |
| 711 | * Refresh the desc even if buffer_addrs |
| 712 | * didn't change because each write-back |
| 713 | * erases this info. |
| 714 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 715 | rx_desc->read.buffer_addr[j + 1] = |
| 716 | cpu_to_le64(ps_page->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 719 | skb = __netdev_alloc_skb_ip_align(netdev, |
| 720 | adapter->rx_ps_bsize0, |
| 721 | gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 722 | |
| 723 | if (!skb) { |
| 724 | adapter->alloc_rx_buff_failed++; |
| 725 | break; |
| 726 | } |
| 727 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 728 | buffer_info->skb = skb; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 729 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 730 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 731 | DMA_FROM_DEVICE); |
| 732 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 733 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 734 | adapter->rx_dma_failed++; |
| 735 | /* cleanup skb */ |
| 736 | dev_kfree_skb_any(skb); |
| 737 | buffer_info->skb = NULL; |
| 738 | break; |
| 739 | } |
| 740 | |
| 741 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 742 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 743 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
| 744 | /* |
| 745 | * Force memory writes to complete before letting h/w |
| 746 | * know there are new descriptors to fetch. (Only |
| 747 | * applicable for weak-ordered memory model archs, |
| 748 | * such as IA-64). |
| 749 | */ |
| 750 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 751 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 752 | e1000e_update_rdt_wa(rx_ring, i << 1); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 753 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 754 | writel(i << 1, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 757 | i++; |
| 758 | if (i == rx_ring->count) |
| 759 | i = 0; |
| 760 | buffer_info = &rx_ring->buffer_info[i]; |
| 761 | } |
| 762 | |
| 763 | no_buffers: |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 764 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 768 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 769 | * @rx_ring: Rx descriptor ring |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 770 | * @cleaned_count: number of buffers to allocate this pass |
| 771 | **/ |
| 772 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 773 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 774 | int cleaned_count, gfp_t gfp) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 775 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 776 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 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_buffer *buffer_info; |
| 781 | struct sk_buff *skb; |
| 782 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 783 | unsigned int bufsz = 256 - 16 /* for skb_reserve */; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 784 | |
| 785 | i = rx_ring->next_to_use; |
| 786 | buffer_info = &rx_ring->buffer_info[i]; |
| 787 | |
| 788 | while (cleaned_count--) { |
| 789 | skb = buffer_info->skb; |
| 790 | if (skb) { |
| 791 | skb_trim(skb, 0); |
| 792 | goto check_page; |
| 793 | } |
| 794 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 795 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 796 | if (unlikely(!skb)) { |
| 797 | /* Better luck next round */ |
| 798 | adapter->alloc_rx_buff_failed++; |
| 799 | break; |
| 800 | } |
| 801 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 802 | buffer_info->skb = skb; |
| 803 | check_page: |
| 804 | /* allocate a new page if necessary */ |
| 805 | if (!buffer_info->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 806 | buffer_info->page = alloc_page(gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 807 | if (unlikely(!buffer_info->page)) { |
| 808 | adapter->alloc_rx_buff_failed++; |
| 809 | break; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | if (!buffer_info->dma) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 814 | buffer_info->dma = dma_map_page(&pdev->dev, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 815 | buffer_info->page, 0, |
| 816 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 817 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 818 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 819 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 820 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 821 | |
| 822 | if (unlikely(++i == rx_ring->count)) |
| 823 | i = 0; |
| 824 | buffer_info = &rx_ring->buffer_info[i]; |
| 825 | } |
| 826 | |
| 827 | if (likely(rx_ring->next_to_use != i)) { |
| 828 | rx_ring->next_to_use = i; |
| 829 | if (unlikely(i-- == 0)) |
| 830 | i = (rx_ring->count - 1); |
| 831 | |
| 832 | /* Force memory writes to complete before letting h/w |
| 833 | * know there are new descriptors to fetch. (Only |
| 834 | * applicable for weak-ordered memory model archs, |
| 835 | * such as IA-64). */ |
| 836 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 837 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 838 | e1000e_update_rdt_wa(rx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 839 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 840 | writel(i, rx_ring->tail); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 844 | static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss, |
| 845 | struct sk_buff *skb) |
| 846 | { |
| 847 | if (netdev->features & NETIF_F_RXHASH) |
| 848 | skb->rxhash = le32_to_cpu(rss); |
| 849 | } |
| 850 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 851 | /** |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 852 | * e1000_clean_rx_irq - Send received data up the network stack |
| 853 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 854 | * |
| 855 | * the return value indicates whether actual cleaning was done, there |
| 856 | * is no guarantee that everything was cleaned |
| 857 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 858 | static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
| 859 | int work_to_do) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 860 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 861 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 865 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 866 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 867 | u32 length, staterr; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 868 | unsigned int i; |
| 869 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 870 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 871 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 872 | |
| 873 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 874 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 875 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 876 | buffer_info = &rx_ring->buffer_info[i]; |
| 877 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 878 | while (staterr & E1000_RXD_STAT_DD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 879 | struct sk_buff *skb; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 880 | |
| 881 | if (*work_done >= work_to_do) |
| 882 | break; |
| 883 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 884 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 885 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 886 | skb = buffer_info->skb; |
| 887 | buffer_info->skb = NULL; |
| 888 | |
| 889 | prefetch(skb->data - NET_IP_ALIGN); |
| 890 | |
| 891 | i++; |
| 892 | if (i == rx_ring->count) |
| 893 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 894 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 895 | prefetch(next_rxd); |
| 896 | |
| 897 | next_buffer = &rx_ring->buffer_info[i]; |
| 898 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 899 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 900 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 901 | dma_unmap_single(&pdev->dev, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 902 | buffer_info->dma, |
| 903 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 904 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 905 | buffer_info->dma = 0; |
| 906 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 907 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 908 | |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 909 | /* |
| 910 | * !EOP means multiple descriptors were used to store a single |
| 911 | * packet, if that's the case we need to toss it. In fact, we |
| 912 | * need to toss every packet with the EOP bit clear and the |
| 913 | * next frame that _does_ have the EOP bit set, as it is by |
| 914 | * definition only a frame fragment |
| 915 | */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 916 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 917 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 918 | |
| 919 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 920 | /* All receives must fit into a single buffer */ |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 921 | e_dbg("Receive packet consumed multiple buffers\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 922 | /* recycle */ |
| 923 | buffer_info->skb = skb; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 924 | if (staterr & E1000_RXD_STAT_EOP) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 925 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 926 | goto next_desc; |
| 927 | } |
| 928 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 929 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 930 | /* recycle */ |
| 931 | buffer_info->skb = skb; |
| 932 | goto next_desc; |
| 933 | } |
| 934 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 935 | /* adjust length to remove Ethernet CRC */ |
| 936 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 937 | length -= 4; |
| 938 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 939 | total_rx_bytes += length; |
| 940 | total_rx_packets++; |
| 941 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 942 | /* |
| 943 | * code added for copybreak, this should improve |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 944 | * performance for small packets with large amounts |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 945 | * of reassembly being done in the stack |
| 946 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 947 | if (length < copybreak) { |
| 948 | struct sk_buff *new_skb = |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 949 | netdev_alloc_skb_ip_align(netdev, length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 950 | if (new_skb) { |
Bruce Allan | 808ff67 | 2008-08-08 18:35:56 -0700 | [diff] [blame] | 951 | skb_copy_to_linear_data_offset(new_skb, |
| 952 | -NET_IP_ALIGN, |
| 953 | (skb->data - |
| 954 | NET_IP_ALIGN), |
| 955 | (length + |
| 956 | NET_IP_ALIGN)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 957 | /* save the skb in buffer_info as good */ |
| 958 | buffer_info->skb = skb; |
| 959 | skb = new_skb; |
| 960 | } |
| 961 | /* else just continue with the old one */ |
| 962 | } |
| 963 | /* end copybreak code */ |
| 964 | skb_put(skb, length); |
| 965 | |
| 966 | /* Receive Checksum Offload */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 967 | e1000_rx_checksum(adapter, staterr, |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 968 | rx_desc->wb.lower.hi_dword.csum_ip.csum, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 969 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 970 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 971 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 972 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 973 | rx_desc->wb.upper.vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 974 | |
| 975 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 976 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 977 | |
| 978 | /* return some buffers to hardware, one at a time is too slow */ |
| 979 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 980 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 981 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 982 | cleaned_count = 0; |
| 983 | } |
| 984 | |
| 985 | /* use prefetched values */ |
| 986 | rx_desc = next_rxd; |
| 987 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 988 | |
| 989 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 990 | } |
| 991 | rx_ring->next_to_clean = i; |
| 992 | |
| 993 | cleaned_count = e1000_desc_unused(rx_ring); |
| 994 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 995 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 996 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 997 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 998 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 999 | return cleaned; |
| 1000 | } |
| 1001 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1002 | static void e1000_put_txbuf(struct e1000_ring *tx_ring, |
| 1003 | struct e1000_buffer *buffer_info) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1004 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1005 | struct e1000_adapter *adapter = tx_ring->adapter; |
| 1006 | |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1007 | if (buffer_info->dma) { |
| 1008 | if (buffer_info->mapped_as_page) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1009 | dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, |
| 1010 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1011 | else |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1012 | dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, |
| 1013 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1014 | buffer_info->dma = 0; |
| 1015 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1016 | if (buffer_info->skb) { |
| 1017 | dev_kfree_skb_any(buffer_info->skb); |
| 1018 | buffer_info->skb = NULL; |
| 1019 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 1020 | buffer_info->time_stamp = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1023 | static void e1000_print_hw_hang(struct work_struct *work) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1024 | { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1025 | struct e1000_adapter *adapter = container_of(work, |
| 1026 | struct e1000_adapter, |
| 1027 | print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1028 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1029 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1030 | unsigned int i = tx_ring->next_to_clean; |
| 1031 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; |
| 1032 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1033 | struct e1000_hw *hw = &adapter->hw; |
| 1034 | u16 phy_status, phy_1000t_status, phy_ext_status; |
| 1035 | u16 pci_status; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1036 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1037 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1038 | return; |
| 1039 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1040 | if (!adapter->tx_hang_recheck && |
| 1041 | (adapter->flags2 & FLAG2_DMA_BURST)) { |
| 1042 | /* May be block on write-back, flush and detect again |
| 1043 | * flush pending descriptor writebacks to memory |
| 1044 | */ |
| 1045 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 1046 | /* execute the writes immediately */ |
| 1047 | e1e_flush(); |
| 1048 | adapter->tx_hang_recheck = true; |
| 1049 | return; |
| 1050 | } |
| 1051 | /* Real hang detected */ |
| 1052 | adapter->tx_hang_recheck = false; |
| 1053 | netif_stop_queue(netdev); |
| 1054 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1055 | e1e_rphy(hw, PHY_STATUS, &phy_status); |
| 1056 | e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status); |
| 1057 | e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status); |
| 1058 | |
| 1059 | pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status); |
| 1060 | |
| 1061 | /* detected Hardware unit hang */ |
| 1062 | e_err("Detected Hardware Unit Hang:\n" |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1063 | " TDH <%x>\n" |
| 1064 | " TDT <%x>\n" |
| 1065 | " next_to_use <%x>\n" |
| 1066 | " next_to_clean <%x>\n" |
| 1067 | "buffer_info[next_to_clean]:\n" |
| 1068 | " time_stamp <%lx>\n" |
| 1069 | " next_to_watch <%x>\n" |
| 1070 | " jiffies <%lx>\n" |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1071 | " next_to_watch.status <%x>\n" |
| 1072 | "MAC Status <%x>\n" |
| 1073 | "PHY Status <%x>\n" |
| 1074 | "PHY 1000BASE-T Status <%x>\n" |
| 1075 | "PHY Extended Status <%x>\n" |
| 1076 | "PCI Status <%x>\n", |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1077 | readl(tx_ring->head), |
| 1078 | readl(tx_ring->tail), |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1079 | tx_ring->next_to_use, |
| 1080 | tx_ring->next_to_clean, |
| 1081 | tx_ring->buffer_info[eop].time_stamp, |
| 1082 | eop, |
| 1083 | jiffies, |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1084 | eop_desc->upper.fields.status, |
| 1085 | er32(STATUS), |
| 1086 | phy_status, |
| 1087 | phy_1000t_status, |
| 1088 | phy_ext_status, |
| 1089 | pci_status); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | /** |
| 1093 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1094 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1095 | * |
| 1096 | * the return value indicates whether actual cleaning was done, there |
| 1097 | * is no guarantee that everything was cleaned |
| 1098 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1099 | static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1100 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1101 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1102 | struct net_device *netdev = adapter->netdev; |
| 1103 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1104 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 1105 | struct e1000_buffer *buffer_info; |
| 1106 | unsigned int i, eop; |
| 1107 | unsigned int count = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1108 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1109 | unsigned int bytes_compl = 0, pkts_compl = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1110 | |
| 1111 | i = tx_ring->next_to_clean; |
| 1112 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1113 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 1114 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1115 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 1116 | (count < tx_ring->count)) { |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1117 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1118 | rmb(); /* read buffer_info after eop_desc */ |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1119 | for (; !cleaned; count++) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1120 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 1121 | buffer_info = &tx_ring->buffer_info[i]; |
| 1122 | cleaned = (i == eop); |
| 1123 | |
| 1124 | if (cleaned) { |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 1125 | total_tx_packets += buffer_info->segs; |
| 1126 | total_tx_bytes += buffer_info->bytecount; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1127 | if (buffer_info->skb) { |
| 1128 | bytes_compl += buffer_info->skb->len; |
| 1129 | pkts_compl++; |
| 1130 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1133 | e1000_put_txbuf(tx_ring, buffer_info); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1134 | tx_desc->upper.data = 0; |
| 1135 | |
| 1136 | i++; |
| 1137 | if (i == tx_ring->count) |
| 1138 | i = 0; |
| 1139 | } |
| 1140 | |
Terry Loftin | dac8761 | 2010-04-09 10:29:49 +0000 | [diff] [blame] | 1141 | if (i == tx_ring->next_to_use) |
| 1142 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1143 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1144 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | tx_ring->next_to_clean = i; |
| 1148 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1149 | netdev_completed_queue(netdev, pkts_compl, bytes_compl); |
| 1150 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1151 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1152 | if (count && netif_carrier_ok(netdev) && |
| 1153 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1154 | /* Make sure that anybody stopping the queue after this |
| 1155 | * sees the new next_to_clean. |
| 1156 | */ |
| 1157 | smp_mb(); |
| 1158 | |
| 1159 | if (netif_queue_stopped(netdev) && |
| 1160 | !(test_bit(__E1000_DOWN, &adapter->state))) { |
| 1161 | netif_wake_queue(netdev); |
| 1162 | ++adapter->restart_queue; |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | if (adapter->detect_tx_hung) { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1167 | /* |
| 1168 | * Detect a transmit hang in hardware, this serializes the |
| 1169 | * check with the clearing of time_stamp and movement of i |
| 1170 | */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1171 | adapter->detect_tx_hung = false; |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1172 | if (tx_ring->buffer_info[i].time_stamp && |
| 1173 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1174 | + (adapter->tx_timeout_factor * HZ)) && |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1175 | !(er32(STATUS) & E1000_STATUS_TXOFF)) |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1176 | schedule_work(&adapter->print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1177 | else |
| 1178 | adapter->tx_hang_recheck = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1179 | } |
| 1180 | adapter->total_tx_bytes += total_tx_bytes; |
| 1181 | adapter->total_tx_packets += total_tx_packets; |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1182 | return count < tx_ring->count; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1186 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1187 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1188 | * |
| 1189 | * the return value indicates whether actual cleaning was done, there |
| 1190 | * is no guarantee that everything was cleaned |
| 1191 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1192 | static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done, |
| 1193 | int work_to_do) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1194 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1195 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1196 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1197 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
| 1198 | struct net_device *netdev = adapter->netdev; |
| 1199 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1200 | struct e1000_buffer *buffer_info, *next_buffer; |
| 1201 | struct e1000_ps_page *ps_page; |
| 1202 | struct sk_buff *skb; |
| 1203 | unsigned int i, j; |
| 1204 | u32 length, staterr; |
| 1205 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1206 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1207 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 1208 | |
| 1209 | i = rx_ring->next_to_clean; |
| 1210 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 1211 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1212 | buffer_info = &rx_ring->buffer_info[i]; |
| 1213 | |
| 1214 | while (staterr & E1000_RXD_STAT_DD) { |
| 1215 | if (*work_done >= work_to_do) |
| 1216 | break; |
| 1217 | (*work_done)++; |
| 1218 | skb = buffer_info->skb; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1219 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1220 | |
| 1221 | /* in the packet split case this is header only */ |
| 1222 | prefetch(skb->data - NET_IP_ALIGN); |
| 1223 | |
| 1224 | i++; |
| 1225 | if (i == rx_ring->count) |
| 1226 | i = 0; |
| 1227 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
| 1228 | prefetch(next_rxd); |
| 1229 | |
| 1230 | next_buffer = &rx_ring->buffer_info[i]; |
| 1231 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1232 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1233 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1234 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1235 | adapter->rx_ps_bsize0, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1236 | buffer_info->dma = 0; |
| 1237 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1238 | /* see !EOP comment in other Rx routine */ |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1239 | if (!(staterr & E1000_RXD_STAT_EOP)) |
| 1240 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 1241 | |
| 1242 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1243 | 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] | 1244 | dev_kfree_skb_irq(skb); |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1245 | if (staterr & E1000_RXD_STAT_EOP) |
| 1246 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1247 | goto next_desc; |
| 1248 | } |
| 1249 | |
| 1250 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
| 1251 | dev_kfree_skb_irq(skb); |
| 1252 | goto next_desc; |
| 1253 | } |
| 1254 | |
| 1255 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 1256 | |
| 1257 | if (!length) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1258 | e_dbg("Last part of the packet spanning multiple descriptors\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1259 | dev_kfree_skb_irq(skb); |
| 1260 | goto next_desc; |
| 1261 | } |
| 1262 | |
| 1263 | /* Good Receive */ |
| 1264 | skb_put(skb, length); |
| 1265 | |
| 1266 | { |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1267 | /* |
| 1268 | * this looks ugly, but it seems compiler issues make |
| 1269 | * it more efficient than reusing j |
| 1270 | */ |
| 1271 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1272 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1273 | /* |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1274 | * page alloc/put takes too long and effects small |
| 1275 | * packet throughput, so unsplit small packets and |
| 1276 | * save the alloc/put only valid in softirq (napi) |
| 1277 | * context to call kmap_* |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1278 | */ |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1279 | if (l1 && (l1 <= copybreak) && |
| 1280 | ((length + l1) <= adapter->rx_ps_bsize0)) { |
| 1281 | u8 *vaddr; |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 1282 | |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1283 | ps_page = &buffer_info->ps_pages[0]; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1284 | |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1285 | /* |
| 1286 | * there is no documentation about how to call |
| 1287 | * kmap_atomic, so we can't hold the mapping |
| 1288 | * very long |
| 1289 | */ |
| 1290 | dma_sync_single_for_cpu(&pdev->dev, |
| 1291 | ps_page->dma, |
| 1292 | PAGE_SIZE, |
| 1293 | DMA_FROM_DEVICE); |
| 1294 | vaddr = kmap_atomic(ps_page->page, |
| 1295 | KM_SKB_DATA_SOFTIRQ); |
| 1296 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
| 1297 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
| 1298 | dma_sync_single_for_device(&pdev->dev, |
| 1299 | ps_page->dma, |
| 1300 | PAGE_SIZE, |
| 1301 | DMA_FROM_DEVICE); |
| 1302 | |
| 1303 | /* remove the CRC */ |
| 1304 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 1305 | l1 -= 4; |
| 1306 | |
| 1307 | skb_put(skb, l1); |
| 1308 | goto copydone; |
| 1309 | } /* if */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
| 1313 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); |
| 1314 | if (!length) |
| 1315 | break; |
| 1316 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1317 | ps_page = &buffer_info->ps_pages[j]; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1318 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1319 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1320 | ps_page->dma = 0; |
| 1321 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); |
| 1322 | ps_page->page = NULL; |
| 1323 | skb->len += length; |
| 1324 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1325 | skb->truesize += PAGE_SIZE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1328 | /* strip the ethernet crc, problem is we're using pages now so |
| 1329 | * this whole operation can get a little cpu intensive |
| 1330 | */ |
| 1331 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) |
| 1332 | pskb_trim(skb, skb->len - 4); |
| 1333 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1334 | copydone: |
| 1335 | total_rx_bytes += skb->len; |
| 1336 | total_rx_packets++; |
| 1337 | |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 1338 | e1000_rx_checksum(adapter, staterr, |
| 1339 | rx_desc->wb.lower.hi_dword.csum_ip.csum, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1340 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1341 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1342 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1343 | if (rx_desc->wb.upper.header_status & |
| 1344 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) |
| 1345 | adapter->rx_hdr_split++; |
| 1346 | |
| 1347 | e1000_receive_skb(adapter, netdev, skb, |
| 1348 | staterr, rx_desc->wb.middle.vlan); |
| 1349 | |
| 1350 | next_desc: |
| 1351 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
| 1352 | buffer_info->skb = NULL; |
| 1353 | |
| 1354 | /* return some buffers to hardware, one at a time is too slow */ |
| 1355 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1356 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1357 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1358 | cleaned_count = 0; |
| 1359 | } |
| 1360 | |
| 1361 | /* use prefetched values */ |
| 1362 | rx_desc = next_rxd; |
| 1363 | buffer_info = next_buffer; |
| 1364 | |
| 1365 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1366 | } |
| 1367 | rx_ring->next_to_clean = i; |
| 1368 | |
| 1369 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1370 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1371 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1372 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1373 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1374 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1375 | return cleaned; |
| 1376 | } |
| 1377 | |
| 1378 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1379 | * e1000_consume_page - helper function |
| 1380 | **/ |
| 1381 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
| 1382 | u16 length) |
| 1383 | { |
| 1384 | bi->page = NULL; |
| 1385 | skb->len += length; |
| 1386 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1387 | skb->truesize += PAGE_SIZE; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | /** |
| 1391 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 1392 | * @adapter: board private structure |
| 1393 | * |
| 1394 | * the return value indicates whether actual cleaning was done, there |
| 1395 | * is no guarantee that everything was cleaned |
| 1396 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1397 | static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
| 1398 | int work_to_do) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1399 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1400 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1401 | struct net_device *netdev = adapter->netdev; |
| 1402 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1403 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1404 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1405 | u32 length, staterr; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1406 | unsigned int i; |
| 1407 | int cleaned_count = 0; |
| 1408 | bool cleaned = false; |
| 1409 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
| 1410 | |
| 1411 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1412 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 1413 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1414 | buffer_info = &rx_ring->buffer_info[i]; |
| 1415 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1416 | while (staterr & E1000_RXD_STAT_DD) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1417 | struct sk_buff *skb; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1418 | |
| 1419 | if (*work_done >= work_to_do) |
| 1420 | break; |
| 1421 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1422 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1423 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1424 | skb = buffer_info->skb; |
| 1425 | buffer_info->skb = NULL; |
| 1426 | |
| 1427 | ++i; |
| 1428 | if (i == rx_ring->count) |
| 1429 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1430 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1431 | prefetch(next_rxd); |
| 1432 | |
| 1433 | next_buffer = &rx_ring->buffer_info[i]; |
| 1434 | |
| 1435 | cleaned = true; |
| 1436 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1437 | dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE, |
| 1438 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1439 | buffer_info->dma = 0; |
| 1440 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1441 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1442 | |
| 1443 | /* errors is only valid for DD + EOP descriptors */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1444 | if (unlikely((staterr & E1000_RXD_STAT_EOP) && |
| 1445 | (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK))) { |
| 1446 | /* recycle both page and skb */ |
| 1447 | buffer_info->skb = skb; |
| 1448 | /* an error means any chain goes out the window too */ |
| 1449 | if (rx_ring->rx_skb_top) |
| 1450 | dev_kfree_skb_irq(rx_ring->rx_skb_top); |
| 1451 | rx_ring->rx_skb_top = NULL; |
| 1452 | goto next_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
Bruce Allan | f0f1a17 | 2010-12-11 05:53:32 +0000 | [diff] [blame] | 1455 | #define rxtop (rx_ring->rx_skb_top) |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1456 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1457 | /* this descriptor is only the beginning (or middle) */ |
| 1458 | if (!rxtop) { |
| 1459 | /* this is the beginning of a chain */ |
| 1460 | rxtop = skb; |
| 1461 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
| 1462 | 0, length); |
| 1463 | } else { |
| 1464 | /* this is the middle of a chain */ |
| 1465 | skb_fill_page_desc(rxtop, |
| 1466 | skb_shinfo(rxtop)->nr_frags, |
| 1467 | buffer_info->page, 0, length); |
| 1468 | /* re-use the skb, only consumed the page */ |
| 1469 | buffer_info->skb = skb; |
| 1470 | } |
| 1471 | e1000_consume_page(buffer_info, rxtop, length); |
| 1472 | goto next_desc; |
| 1473 | } else { |
| 1474 | if (rxtop) { |
| 1475 | /* end of the chain */ |
| 1476 | skb_fill_page_desc(rxtop, |
| 1477 | skb_shinfo(rxtop)->nr_frags, |
| 1478 | buffer_info->page, 0, length); |
| 1479 | /* re-use the current skb, we only consumed the |
| 1480 | * page */ |
| 1481 | buffer_info->skb = skb; |
| 1482 | skb = rxtop; |
| 1483 | rxtop = NULL; |
| 1484 | e1000_consume_page(buffer_info, skb, length); |
| 1485 | } else { |
| 1486 | /* no chain, got EOP, this buf is the packet |
| 1487 | * copybreak to save the put_page/alloc_page */ |
| 1488 | if (length <= copybreak && |
| 1489 | skb_tailroom(skb) >= length) { |
| 1490 | u8 *vaddr; |
| 1491 | vaddr = kmap_atomic(buffer_info->page, |
| 1492 | KM_SKB_DATA_SOFTIRQ); |
| 1493 | memcpy(skb_tail_pointer(skb), vaddr, |
| 1494 | length); |
| 1495 | kunmap_atomic(vaddr, |
| 1496 | KM_SKB_DATA_SOFTIRQ); |
| 1497 | /* re-use the page, so don't erase |
| 1498 | * buffer_info->page */ |
| 1499 | skb_put(skb, length); |
| 1500 | } else { |
| 1501 | skb_fill_page_desc(skb, 0, |
| 1502 | buffer_info->page, 0, |
| 1503 | length); |
| 1504 | e1000_consume_page(buffer_info, skb, |
| 1505 | length); |
| 1506 | } |
| 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | /* Receive Checksum Offload XXX recompute due to CRC strip? */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1511 | e1000_rx_checksum(adapter, staterr, |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 1512 | rx_desc->wb.lower.hi_dword.csum_ip.csum, skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1513 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1514 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1515 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1516 | /* probably a little skewed due to removing CRC */ |
| 1517 | total_rx_bytes += skb->len; |
| 1518 | total_rx_packets++; |
| 1519 | |
| 1520 | /* eth type trans needs skb->data to point to something */ |
| 1521 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1522 | e_err("pskb_may_pull failed.\n"); |
Bruce Allan | ef5ab89 | 2011-02-10 08:17:21 +0000 | [diff] [blame] | 1523 | dev_kfree_skb_irq(skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1524 | goto next_desc; |
| 1525 | } |
| 1526 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1527 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1528 | rx_desc->wb.upper.vlan); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1529 | |
| 1530 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1531 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1532 | |
| 1533 | /* return some buffers to hardware, one at a time is too slow */ |
| 1534 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1535 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1536 | GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1537 | cleaned_count = 0; |
| 1538 | } |
| 1539 | |
| 1540 | /* use prefetched values */ |
| 1541 | rx_desc = next_rxd; |
| 1542 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1543 | |
| 1544 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1545 | } |
| 1546 | rx_ring->next_to_clean = i; |
| 1547 | |
| 1548 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1549 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1550 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1551 | |
| 1552 | adapter->total_rx_bytes += total_rx_bytes; |
| 1553 | adapter->total_rx_packets += total_rx_packets; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1554 | return cleaned; |
| 1555 | } |
| 1556 | |
| 1557 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1558 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1559 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1560 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1561 | static void e1000_clean_rx_ring(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1562 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1563 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1564 | struct e1000_buffer *buffer_info; |
| 1565 | struct e1000_ps_page *ps_page; |
| 1566 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1567 | unsigned int i, j; |
| 1568 | |
| 1569 | /* Free all the Rx ring sk_buffs */ |
| 1570 | for (i = 0; i < rx_ring->count; i++) { |
| 1571 | buffer_info = &rx_ring->buffer_info[i]; |
| 1572 | if (buffer_info->dma) { |
| 1573 | if (adapter->clean_rx == e1000_clean_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1574 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1575 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1576 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1577 | else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1578 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1579 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1580 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1581 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1582 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1583 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1584 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1585 | buffer_info->dma = 0; |
| 1586 | } |
| 1587 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1588 | if (buffer_info->page) { |
| 1589 | put_page(buffer_info->page); |
| 1590 | buffer_info->page = NULL; |
| 1591 | } |
| 1592 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1593 | if (buffer_info->skb) { |
| 1594 | dev_kfree_skb(buffer_info->skb); |
| 1595 | buffer_info->skb = NULL; |
| 1596 | } |
| 1597 | |
| 1598 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1599 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1600 | if (!ps_page->page) |
| 1601 | break; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1602 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1603 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1604 | ps_page->dma = 0; |
| 1605 | put_page(ps_page->page); |
| 1606 | ps_page->page = NULL; |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | /* there also may be some cached data from a chained receive */ |
| 1611 | if (rx_ring->rx_skb_top) { |
| 1612 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 1613 | rx_ring->rx_skb_top = NULL; |
| 1614 | } |
| 1615 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1616 | /* Zero out the descriptor ring */ |
| 1617 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1618 | |
| 1619 | rx_ring->next_to_clean = 0; |
| 1620 | rx_ring->next_to_use = 0; |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1621 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1622 | |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1623 | writel(0, rx_ring->head); |
| 1624 | writel(0, rx_ring->tail); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1625 | } |
| 1626 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1627 | static void e1000e_downshift_workaround(struct work_struct *work) |
| 1628 | { |
| 1629 | struct e1000_adapter *adapter = container_of(work, |
| 1630 | struct e1000_adapter, downshift_task); |
| 1631 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1632 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1633 | return; |
| 1634 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1635 | e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); |
| 1636 | } |
| 1637 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1638 | /** |
| 1639 | * e1000_intr_msi - Interrupt Handler |
| 1640 | * @irq: interrupt number |
| 1641 | * @data: pointer to a network interface device structure |
| 1642 | **/ |
| 1643 | static irqreturn_t e1000_intr_msi(int irq, void *data) |
| 1644 | { |
| 1645 | struct net_device *netdev = data; |
| 1646 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1647 | struct e1000_hw *hw = &adapter->hw; |
| 1648 | u32 icr = er32(ICR); |
| 1649 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1650 | /* |
| 1651 | * read ICR disables interrupts using IAM |
| 1652 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1653 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1654 | if (icr & E1000_ICR_LSC) { |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1655 | hw->mac.get_link_status = true; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1656 | /* |
| 1657 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1658 | * disconnect (LSC) before accessing any PHY registers |
| 1659 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1660 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1661 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1662 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1663 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1664 | /* |
| 1665 | * 80003ES2LAN workaround-- For packet buffer work-around on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1666 | * link down event; disable receives here in the ISR and reset |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1667 | * adapter in watchdog |
| 1668 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1669 | if (netif_carrier_ok(netdev) && |
| 1670 | adapter->flags & FLAG_RX_NEEDS_RESTART) { |
| 1671 | /* disable receives */ |
| 1672 | u32 rctl = er32(RCTL); |
| 1673 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1674 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1675 | } |
| 1676 | /* guard against interrupt when we're going down */ |
| 1677 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1678 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1679 | } |
| 1680 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1681 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1682 | adapter->total_tx_bytes = 0; |
| 1683 | adapter->total_tx_packets = 0; |
| 1684 | adapter->total_rx_bytes = 0; |
| 1685 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1686 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | return IRQ_HANDLED; |
| 1690 | } |
| 1691 | |
| 1692 | /** |
| 1693 | * e1000_intr - Interrupt Handler |
| 1694 | * @irq: interrupt number |
| 1695 | * @data: pointer to a network interface device structure |
| 1696 | **/ |
| 1697 | static irqreturn_t e1000_intr(int irq, void *data) |
| 1698 | { |
| 1699 | struct net_device *netdev = data; |
| 1700 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1701 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1702 | u32 rctl, icr = er32(ICR); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1703 | |
Bruce Allan | a68ea77 | 2009-11-20 23:23:16 +0000 | [diff] [blame] | 1704 | if (!icr || test_bit(__E1000_DOWN, &adapter->state)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1705 | return IRQ_NONE; /* Not our interrupt */ |
| 1706 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1707 | /* |
| 1708 | * IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 1709 | * not set, then the adapter didn't send an interrupt |
| 1710 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1711 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 1712 | return IRQ_NONE; |
| 1713 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1714 | /* |
| 1715 | * Interrupt Auto-Mask...upon reading ICR, |
| 1716 | * interrupts are masked. No need for the |
| 1717 | * IMC write |
| 1718 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1719 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1720 | if (icr & E1000_ICR_LSC) { |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1721 | hw->mac.get_link_status = true; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1722 | /* |
| 1723 | * ICH8 workaround-- Call gig speed drop workaround on cable |
| 1724 | * disconnect (LSC) before accessing any PHY registers |
| 1725 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1726 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1727 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1728 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1729 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1730 | /* |
| 1731 | * 80003ES2LAN workaround-- |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1732 | * For packet buffer work-around on link down event; |
| 1733 | * disable receives here in the ISR and |
| 1734 | * reset adapter in watchdog |
| 1735 | */ |
| 1736 | if (netif_carrier_ok(netdev) && |
| 1737 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { |
| 1738 | /* disable receives */ |
| 1739 | rctl = er32(RCTL); |
| 1740 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1741 | adapter->flags |= FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1742 | } |
| 1743 | /* guard against interrupt when we're going down */ |
| 1744 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1745 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1746 | } |
| 1747 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1748 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1749 | adapter->total_tx_bytes = 0; |
| 1750 | adapter->total_tx_packets = 0; |
| 1751 | adapter->total_rx_bytes = 0; |
| 1752 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1753 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | return IRQ_HANDLED; |
| 1757 | } |
| 1758 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1759 | static irqreturn_t e1000_msix_other(int irq, void *data) |
| 1760 | { |
| 1761 | struct net_device *netdev = data; |
| 1762 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1763 | struct e1000_hw *hw = &adapter->hw; |
| 1764 | u32 icr = er32(ICR); |
| 1765 | |
| 1766 | if (!(icr & E1000_ICR_INT_ASSERTED)) { |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1767 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1768 | ew32(IMS, E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1769 | return IRQ_NONE; |
| 1770 | } |
| 1771 | |
| 1772 | if (icr & adapter->eiac_mask) |
| 1773 | ew32(ICS, (icr & adapter->eiac_mask)); |
| 1774 | |
| 1775 | if (icr & E1000_ICR_OTHER) { |
| 1776 | if (!(icr & E1000_ICR_LSC)) |
| 1777 | goto no_link_interrupt; |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1778 | hw->mac.get_link_status = true; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1779 | /* guard against interrupt when we're going down */ |
| 1780 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1781 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1782 | } |
| 1783 | |
| 1784 | no_link_interrupt: |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1785 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1786 | ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1787 | |
| 1788 | return IRQ_HANDLED; |
| 1789 | } |
| 1790 | |
| 1791 | |
| 1792 | static irqreturn_t e1000_intr_msix_tx(int irq, void *data) |
| 1793 | { |
| 1794 | struct net_device *netdev = data; |
| 1795 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1796 | struct e1000_hw *hw = &adapter->hw; |
| 1797 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1798 | |
| 1799 | |
| 1800 | adapter->total_tx_bytes = 0; |
| 1801 | adapter->total_tx_packets = 0; |
| 1802 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1803 | if (!e1000_clean_tx_irq(tx_ring)) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1804 | /* Ring was not completely cleaned, so fire another interrupt */ |
| 1805 | ew32(ICS, tx_ring->ims_val); |
| 1806 | |
| 1807 | return IRQ_HANDLED; |
| 1808 | } |
| 1809 | |
| 1810 | static irqreturn_t e1000_intr_msix_rx(int irq, void *data) |
| 1811 | { |
| 1812 | struct net_device *netdev = data; |
| 1813 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1814 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1815 | |
| 1816 | /* Write the ITR value calculated at the end of the |
| 1817 | * previous interrupt. |
| 1818 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1819 | if (rx_ring->set_itr) { |
| 1820 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1821 | rx_ring->itr_register); |
| 1822 | rx_ring->set_itr = 0; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1825 | if (napi_schedule_prep(&adapter->napi)) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1826 | adapter->total_rx_bytes = 0; |
| 1827 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1828 | __napi_schedule(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1829 | } |
| 1830 | return IRQ_HANDLED; |
| 1831 | } |
| 1832 | |
| 1833 | /** |
| 1834 | * e1000_configure_msix - Configure MSI-X hardware |
| 1835 | * |
| 1836 | * e1000_configure_msix sets up the hardware to properly |
| 1837 | * generate MSI-X interrupts. |
| 1838 | **/ |
| 1839 | static void e1000_configure_msix(struct e1000_adapter *adapter) |
| 1840 | { |
| 1841 | struct e1000_hw *hw = &adapter->hw; |
| 1842 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1843 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1844 | int vector = 0; |
| 1845 | u32 ctrl_ext, ivar = 0; |
| 1846 | |
| 1847 | adapter->eiac_mask = 0; |
| 1848 | |
| 1849 | /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ |
| 1850 | if (hw->mac.type == e1000_82574) { |
| 1851 | u32 rfctl = er32(RFCTL); |
| 1852 | rfctl |= E1000_RFCTL_ACK_DIS; |
| 1853 | ew32(RFCTL, rfctl); |
| 1854 | } |
| 1855 | |
| 1856 | #define E1000_IVAR_INT_ALLOC_VALID 0x8 |
| 1857 | /* Configure Rx vector */ |
| 1858 | rx_ring->ims_val = E1000_IMS_RXQ0; |
| 1859 | adapter->eiac_mask |= rx_ring->ims_val; |
| 1860 | if (rx_ring->itr_val) |
| 1861 | writel(1000000000 / (rx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1862 | rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1863 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1864 | writel(1, rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1865 | ivar = E1000_IVAR_INT_ALLOC_VALID | vector; |
| 1866 | |
| 1867 | /* Configure Tx vector */ |
| 1868 | tx_ring->ims_val = E1000_IMS_TXQ0; |
| 1869 | vector++; |
| 1870 | if (tx_ring->itr_val) |
| 1871 | writel(1000000000 / (tx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1872 | tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1873 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1874 | writel(1, tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1875 | adapter->eiac_mask |= tx_ring->ims_val; |
| 1876 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); |
| 1877 | |
| 1878 | /* set vector for Other Causes, e.g. link changes */ |
| 1879 | vector++; |
| 1880 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); |
| 1881 | if (rx_ring->itr_val) |
| 1882 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1883 | hw->hw_addr + E1000_EITR_82574(vector)); |
| 1884 | else |
| 1885 | writel(1, hw->hw_addr + E1000_EITR_82574(vector)); |
| 1886 | |
| 1887 | /* Cause Tx interrupts on every write back */ |
| 1888 | ivar |= (1 << 31); |
| 1889 | |
| 1890 | ew32(IVAR, ivar); |
| 1891 | |
| 1892 | /* enable MSI-X PBA support */ |
| 1893 | ctrl_ext = er32(CTRL_EXT); |
| 1894 | ctrl_ext |= E1000_CTRL_EXT_PBA_CLR; |
| 1895 | |
| 1896 | /* Auto-Mask Other interrupts upon ICR read */ |
| 1897 | #define E1000_EIAC_MASK_82574 0x01F00000 |
| 1898 | ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER); |
| 1899 | ctrl_ext |= E1000_CTRL_EXT_EIAME; |
| 1900 | ew32(CTRL_EXT, ctrl_ext); |
| 1901 | e1e_flush(); |
| 1902 | } |
| 1903 | |
| 1904 | void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) |
| 1905 | { |
| 1906 | if (adapter->msix_entries) { |
| 1907 | pci_disable_msix(adapter->pdev); |
| 1908 | kfree(adapter->msix_entries); |
| 1909 | adapter->msix_entries = NULL; |
| 1910 | } else if (adapter->flags & FLAG_MSI_ENABLED) { |
| 1911 | pci_disable_msi(adapter->pdev); |
| 1912 | adapter->flags &= ~FLAG_MSI_ENABLED; |
| 1913 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | /** |
| 1917 | * e1000e_set_interrupt_capability - set MSI or MSI-X if supported |
| 1918 | * |
| 1919 | * Attempt to configure interrupts using the best available |
| 1920 | * capabilities of the hardware and kernel. |
| 1921 | **/ |
| 1922 | void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) |
| 1923 | { |
| 1924 | int err; |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1925 | int i; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1926 | |
| 1927 | switch (adapter->int_mode) { |
| 1928 | case E1000E_INT_MODE_MSIX: |
| 1929 | if (adapter->flags & FLAG_HAS_MSIX) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1930 | adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */ |
| 1931 | adapter->msix_entries = kcalloc(adapter->num_vectors, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1932 | sizeof(struct msix_entry), |
| 1933 | GFP_KERNEL); |
| 1934 | if (adapter->msix_entries) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1935 | for (i = 0; i < adapter->num_vectors; i++) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1936 | adapter->msix_entries[i].entry = i; |
| 1937 | |
| 1938 | err = pci_enable_msix(adapter->pdev, |
| 1939 | adapter->msix_entries, |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1940 | adapter->num_vectors); |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 1941 | if (err == 0) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1942 | return; |
| 1943 | } |
| 1944 | /* MSI-X failed, so fall through and try MSI */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1945 | 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] | 1946 | e1000e_reset_interrupt_capability(adapter); |
| 1947 | } |
| 1948 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 1949 | /* Fall through */ |
| 1950 | case E1000E_INT_MODE_MSI: |
| 1951 | if (!pci_enable_msi(adapter->pdev)) { |
| 1952 | adapter->flags |= FLAG_MSI_ENABLED; |
| 1953 | } else { |
| 1954 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1955 | 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] | 1956 | } |
| 1957 | /* Fall through */ |
| 1958 | case E1000E_INT_MODE_LEGACY: |
| 1959 | /* Don't do anything; this is the system default */ |
| 1960 | break; |
| 1961 | } |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 1962 | |
| 1963 | /* store the number of vectors being used */ |
| 1964 | adapter->num_vectors = 1; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * e1000_request_msix - Initialize MSI-X interrupts |
| 1969 | * |
| 1970 | * e1000_request_msix allocates MSI-X vectors and requests interrupts from the |
| 1971 | * kernel. |
| 1972 | **/ |
| 1973 | static int e1000_request_msix(struct e1000_adapter *adapter) |
| 1974 | { |
| 1975 | struct net_device *netdev = adapter->netdev; |
| 1976 | int err = 0, vector = 0; |
| 1977 | |
| 1978 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 1979 | snprintf(adapter->rx_ring->name, |
| 1980 | sizeof(adapter->rx_ring->name) - 1, |
| 1981 | "%s-rx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1982 | else |
| 1983 | memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); |
| 1984 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1985 | e1000_intr_msix_rx, 0, adapter->rx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1986 | netdev); |
| 1987 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 1988 | return err; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1989 | adapter->rx_ring->itr_register = adapter->hw.hw_addr + |
| 1990 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1991 | adapter->rx_ring->itr_val = adapter->itr; |
| 1992 | vector++; |
| 1993 | |
| 1994 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 1995 | snprintf(adapter->tx_ring->name, |
| 1996 | sizeof(adapter->tx_ring->name) - 1, |
| 1997 | "%s-tx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1998 | else |
| 1999 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); |
| 2000 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2001 | e1000_intr_msix_tx, 0, adapter->tx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2002 | netdev); |
| 2003 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2004 | return err; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2005 | adapter->tx_ring->itr_register = adapter->hw.hw_addr + |
| 2006 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2007 | adapter->tx_ring->itr_val = adapter->itr; |
| 2008 | vector++; |
| 2009 | |
| 2010 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2011 | e1000_msix_other, 0, netdev->name, netdev); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2012 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2013 | return err; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2014 | |
| 2015 | e1000_configure_msix(adapter); |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2016 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2017 | return 0; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2020 | /** |
| 2021 | * e1000_request_irq - initialize interrupts |
| 2022 | * |
| 2023 | * Attempts to configure interrupts using the best available |
| 2024 | * capabilities of the hardware and kernel. |
| 2025 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2026 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 2027 | { |
| 2028 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2029 | int err; |
| 2030 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2031 | if (adapter->msix_entries) { |
| 2032 | err = e1000_request_msix(adapter); |
| 2033 | if (!err) |
| 2034 | return err; |
| 2035 | /* fall back to MSI */ |
| 2036 | e1000e_reset_interrupt_capability(adapter); |
| 2037 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 2038 | e1000e_set_interrupt_capability(adapter); |
| 2039 | } |
| 2040 | if (adapter->flags & FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2041 | err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2042 | netdev->name, netdev); |
| 2043 | if (!err) |
| 2044 | return err; |
| 2045 | |
| 2046 | /* fall back to legacy interrupt */ |
| 2047 | e1000e_reset_interrupt_capability(adapter); |
| 2048 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2051 | err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2052 | netdev->name, netdev); |
| 2053 | if (err) |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2054 | e_err("Unable to allocate interrupt, Error: %d\n", err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2055 | |
| 2056 | return err; |
| 2057 | } |
| 2058 | |
| 2059 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 2060 | { |
| 2061 | struct net_device *netdev = adapter->netdev; |
| 2062 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2063 | if (adapter->msix_entries) { |
| 2064 | int vector = 0; |
| 2065 | |
| 2066 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2067 | vector++; |
| 2068 | |
| 2069 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2070 | vector++; |
| 2071 | |
| 2072 | /* Other Causes interrupt vector */ |
| 2073 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2074 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2075 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2076 | |
| 2077 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | /** |
| 2081 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 2082 | **/ |
| 2083 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
| 2084 | { |
| 2085 | struct e1000_hw *hw = &adapter->hw; |
| 2086 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2087 | ew32(IMC, ~0); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2088 | if (adapter->msix_entries) |
| 2089 | ew32(EIAC_82574, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2090 | e1e_flush(); |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2091 | |
| 2092 | if (adapter->msix_entries) { |
| 2093 | int i; |
| 2094 | for (i = 0; i < adapter->num_vectors; i++) |
| 2095 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2096 | } else { |
| 2097 | synchronize_irq(adapter->pdev->irq); |
| 2098 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | /** |
| 2102 | * e1000_irq_enable - Enable default interrupt generation settings |
| 2103 | **/ |
| 2104 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
| 2105 | { |
| 2106 | struct e1000_hw *hw = &adapter->hw; |
| 2107 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2108 | if (adapter->msix_entries) { |
| 2109 | ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); |
| 2110 | ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC); |
| 2111 | } else { |
| 2112 | ew32(IMS, IMS_ENABLE_MASK); |
| 2113 | } |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 2114 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2118 | * 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] | 2119 | * @adapter: address of board private structure |
| 2120 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2121 | * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2122 | * For ASF and Pass Through versions of f/w this means that |
| 2123 | * the driver is loaded. For AMT version (only with 82573) |
| 2124 | * of the f/w this means that the network i/f is open. |
| 2125 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2126 | void e1000e_get_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2127 | { |
| 2128 | struct e1000_hw *hw = &adapter->hw; |
| 2129 | u32 ctrl_ext; |
| 2130 | u32 swsm; |
| 2131 | |
| 2132 | /* Let firmware know the driver has taken over */ |
| 2133 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2134 | swsm = er32(SWSM); |
| 2135 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
| 2136 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2137 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2138 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2143 | * 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] | 2144 | * @adapter: address of board private structure |
| 2145 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2146 | * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2147 | * For ASF and Pass Through versions of f/w this means that the |
| 2148 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 2149 | * of the f/w this means that the network i/f is closed. |
| 2150 | * |
| 2151 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2152 | void e1000e_release_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2153 | { |
| 2154 | struct e1000_hw *hw = &adapter->hw; |
| 2155 | u32 ctrl_ext; |
| 2156 | u32 swsm; |
| 2157 | |
| 2158 | /* Let firmware taken over control of h/w */ |
| 2159 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2160 | swsm = er32(SWSM); |
| 2161 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
| 2162 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2163 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2164 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2165 | } |
| 2166 | } |
| 2167 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2168 | /** |
| 2169 | * @e1000_alloc_ring - allocate memory for a ring structure |
| 2170 | **/ |
| 2171 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, |
| 2172 | struct e1000_ring *ring) |
| 2173 | { |
| 2174 | struct pci_dev *pdev = adapter->pdev; |
| 2175 | |
| 2176 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, |
| 2177 | GFP_KERNEL); |
| 2178 | if (!ring->desc) |
| 2179 | return -ENOMEM; |
| 2180 | |
| 2181 | return 0; |
| 2182 | } |
| 2183 | |
| 2184 | /** |
| 2185 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2186 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2187 | * |
| 2188 | * Return 0 on success, negative on failure |
| 2189 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2190 | int e1000e_setup_tx_resources(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2191 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2192 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2193 | int err = -ENOMEM, size; |
| 2194 | |
| 2195 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2196 | tx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2197 | if (!tx_ring->buffer_info) |
| 2198 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2199 | |
| 2200 | /* round up to nearest 4K */ |
| 2201 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
| 2202 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2203 | |
| 2204 | err = e1000_alloc_ring_dma(adapter, tx_ring); |
| 2205 | if (err) |
| 2206 | goto err; |
| 2207 | |
| 2208 | tx_ring->next_to_use = 0; |
| 2209 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2210 | |
| 2211 | return 0; |
| 2212 | err: |
| 2213 | vfree(tx_ring->buffer_info); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 2214 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2215 | return err; |
| 2216 | } |
| 2217 | |
| 2218 | /** |
| 2219 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2220 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2221 | * |
| 2222 | * Returns 0 on success, negative on failure |
| 2223 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2224 | int e1000e_setup_rx_resources(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2225 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2226 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2227 | struct e1000_buffer *buffer_info; |
| 2228 | int i, size, desc_len, err = -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2229 | |
| 2230 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2231 | rx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2232 | if (!rx_ring->buffer_info) |
| 2233 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2234 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2235 | for (i = 0; i < rx_ring->count; i++) { |
| 2236 | buffer_info = &rx_ring->buffer_info[i]; |
| 2237 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, |
| 2238 | sizeof(struct e1000_ps_page), |
| 2239 | GFP_KERNEL); |
| 2240 | if (!buffer_info->ps_pages) |
| 2241 | goto err_pages; |
| 2242 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2243 | |
| 2244 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 2245 | |
| 2246 | /* Round up to nearest 4K */ |
| 2247 | rx_ring->size = rx_ring->count * desc_len; |
| 2248 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2249 | |
| 2250 | err = e1000_alloc_ring_dma(adapter, rx_ring); |
| 2251 | if (err) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2252 | goto err_pages; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2253 | |
| 2254 | rx_ring->next_to_clean = 0; |
| 2255 | rx_ring->next_to_use = 0; |
| 2256 | rx_ring->rx_skb_top = NULL; |
| 2257 | |
| 2258 | return 0; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2259 | |
| 2260 | err_pages: |
| 2261 | for (i = 0; i < rx_ring->count; i++) { |
| 2262 | buffer_info = &rx_ring->buffer_info[i]; |
| 2263 | kfree(buffer_info->ps_pages); |
| 2264 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2265 | err: |
| 2266 | vfree(rx_ring->buffer_info); |
Bruce Allan | e926244 | 2010-11-24 06:02:06 +0000 | [diff] [blame] | 2267 | e_err("Unable to allocate memory for the receive descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2268 | return err; |
| 2269 | } |
| 2270 | |
| 2271 | /** |
| 2272 | * e1000_clean_tx_ring - Free Tx Buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2273 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2274 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2275 | static void e1000_clean_tx_ring(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2276 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2277 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2278 | struct e1000_buffer *buffer_info; |
| 2279 | unsigned long size; |
| 2280 | unsigned int i; |
| 2281 | |
| 2282 | for (i = 0; i < tx_ring->count; i++) { |
| 2283 | buffer_info = &tx_ring->buffer_info[i]; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2284 | e1000_put_txbuf(tx_ring, buffer_info); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 2287 | netdev_reset_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2288 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2289 | memset(tx_ring->buffer_info, 0, size); |
| 2290 | |
| 2291 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2292 | |
| 2293 | tx_ring->next_to_use = 0; |
| 2294 | tx_ring->next_to_clean = 0; |
| 2295 | |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2296 | writel(0, tx_ring->head); |
| 2297 | writel(0, tx_ring->tail); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | /** |
| 2301 | * e1000e_free_tx_resources - Free Tx Resources per Queue |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2302 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2303 | * |
| 2304 | * Free all transmit software resources |
| 2305 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2306 | void e1000e_free_tx_resources(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2307 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2308 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2309 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2310 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2311 | e1000_clean_tx_ring(tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2312 | |
| 2313 | vfree(tx_ring->buffer_info); |
| 2314 | tx_ring->buffer_info = NULL; |
| 2315 | |
| 2316 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 2317 | tx_ring->dma); |
| 2318 | tx_ring->desc = NULL; |
| 2319 | } |
| 2320 | |
| 2321 | /** |
| 2322 | * e1000e_free_rx_resources - Free Rx Resources |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2323 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2324 | * |
| 2325 | * Free all receive software resources |
| 2326 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2327 | void e1000e_free_rx_resources(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2328 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2329 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2330 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2331 | int i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2332 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2333 | e1000_clean_rx_ring(rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2334 | |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2335 | for (i = 0; i < rx_ring->count; i++) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2336 | kfree(rx_ring->buffer_info[i].ps_pages); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2337 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2338 | vfree(rx_ring->buffer_info); |
| 2339 | rx_ring->buffer_info = NULL; |
| 2340 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2341 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 2342 | rx_ring->dma); |
| 2343 | rx_ring->desc = NULL; |
| 2344 | } |
| 2345 | |
| 2346 | /** |
| 2347 | * e1000_update_itr - update the dynamic ITR value based on statistics |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2348 | * @adapter: pointer to adapter |
| 2349 | * @itr_setting: current adapter->itr |
| 2350 | * @packets: the number of packets during this measurement interval |
| 2351 | * @bytes: the number of bytes during this measurement interval |
| 2352 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2353 | * Stores a new ITR value based on packets and byte |
| 2354 | * counts during the last interrupt. The advantage of per interrupt |
| 2355 | * computation is faster updates and more accurate ITR for the current |
| 2356 | * traffic pattern. Constants in this function were computed |
| 2357 | * based on theoretical maximum wire speed and thresholds were set based |
| 2358 | * on testing data as well as attempting to minimize response time |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2359 | * while increasing bulk throughput. This functionality is controlled |
| 2360 | * by the InterruptThrottleRate module parameter. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2361 | **/ |
| 2362 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
| 2363 | u16 itr_setting, int packets, |
| 2364 | int bytes) |
| 2365 | { |
| 2366 | unsigned int retval = itr_setting; |
| 2367 | |
| 2368 | if (packets == 0) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2369 | return itr_setting; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2370 | |
| 2371 | switch (itr_setting) { |
| 2372 | case lowest_latency: |
| 2373 | /* handle TSO and jumbo frames */ |
| 2374 | if (bytes/packets > 8000) |
| 2375 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2376 | else if ((packets < 5) && (bytes > 512)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2377 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2378 | break; |
| 2379 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2380 | if (bytes > 10000) { |
| 2381 | /* this if handles the TSO accounting */ |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2382 | if (bytes/packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2383 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2384 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2385 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2386 | else if ((packets > 35)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2387 | retval = lowest_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2388 | } else if (bytes/packets > 2000) { |
| 2389 | retval = bulk_latency; |
| 2390 | } else if (packets <= 2 && bytes < 512) { |
| 2391 | retval = lowest_latency; |
| 2392 | } |
| 2393 | break; |
| 2394 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2395 | if (bytes > 25000) { |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2396 | if (packets > 35) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2397 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2398 | } else if (bytes < 6000) { |
| 2399 | retval = low_latency; |
| 2400 | } |
| 2401 | break; |
| 2402 | } |
| 2403 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2404 | return retval; |
| 2405 | } |
| 2406 | |
| 2407 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2408 | { |
| 2409 | struct e1000_hw *hw = &adapter->hw; |
| 2410 | u16 current_itr; |
| 2411 | u32 new_itr = adapter->itr; |
| 2412 | |
| 2413 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2414 | if (adapter->link_speed != SPEED_1000) { |
| 2415 | current_itr = 0; |
| 2416 | new_itr = 4000; |
| 2417 | goto set_itr_now; |
| 2418 | } |
| 2419 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2420 | if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 2421 | new_itr = 0; |
| 2422 | goto set_itr_now; |
| 2423 | } |
| 2424 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2425 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2426 | adapter->tx_itr, |
| 2427 | adapter->total_tx_packets, |
| 2428 | adapter->total_tx_bytes); |
| 2429 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2430 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2431 | adapter->tx_itr = low_latency; |
| 2432 | |
| 2433 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2434 | adapter->rx_itr, |
| 2435 | adapter->total_rx_packets, |
| 2436 | adapter->total_rx_bytes); |
| 2437 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2438 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2439 | adapter->rx_itr = low_latency; |
| 2440 | |
| 2441 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2442 | |
| 2443 | switch (current_itr) { |
| 2444 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2445 | case lowest_latency: |
| 2446 | new_itr = 70000; |
| 2447 | break; |
| 2448 | case low_latency: |
| 2449 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2450 | break; |
| 2451 | case bulk_latency: |
| 2452 | new_itr = 4000; |
| 2453 | break; |
| 2454 | default: |
| 2455 | break; |
| 2456 | } |
| 2457 | |
| 2458 | set_itr_now: |
| 2459 | if (new_itr != adapter->itr) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2460 | /* |
| 2461 | * this attempts to bias the interrupt rate towards Bulk |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2462 | * by adding intermediate steps when interrupt rate is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2463 | * increasing |
| 2464 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2465 | new_itr = new_itr > adapter->itr ? |
| 2466 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2467 | new_itr; |
| 2468 | adapter->itr = new_itr; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2469 | adapter->rx_ring->itr_val = new_itr; |
| 2470 | if (adapter->msix_entries) |
| 2471 | adapter->rx_ring->set_itr = 1; |
| 2472 | else |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2473 | if (new_itr) |
| 2474 | ew32(ITR, 1000000000 / (new_itr * 256)); |
| 2475 | else |
| 2476 | ew32(ITR, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | /** |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2481 | * e1000_alloc_queues - Allocate memory for all rings |
| 2482 | * @adapter: board private structure to initialize |
| 2483 | **/ |
| 2484 | static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) |
| 2485 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2486 | int size = sizeof(struct e1000_ring); |
| 2487 | |
| 2488 | adapter->tx_ring = kzalloc(size, GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2489 | if (!adapter->tx_ring) |
| 2490 | goto err; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2491 | adapter->tx_ring->count = adapter->tx_ring_count; |
| 2492 | adapter->tx_ring->adapter = adapter; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2493 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2494 | adapter->rx_ring = kzalloc(size, GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2495 | if (!adapter->rx_ring) |
| 2496 | goto err; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2497 | adapter->rx_ring->count = adapter->rx_ring_count; |
| 2498 | adapter->rx_ring->adapter = adapter; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2499 | |
| 2500 | return 0; |
| 2501 | err: |
| 2502 | e_err("Unable to allocate memory for queues\n"); |
| 2503 | kfree(adapter->rx_ring); |
| 2504 | kfree(adapter->tx_ring); |
| 2505 | return -ENOMEM; |
| 2506 | } |
| 2507 | |
| 2508 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2509 | * e1000_clean - NAPI Rx polling callback |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2510 | * @napi: struct associated with this polling callback |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2511 | * @budget: amount of packets driver is allowed to process this poll |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2512 | **/ |
| 2513 | static int e1000_clean(struct napi_struct *napi, int budget) |
| 2514 | { |
| 2515 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2516 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2517 | struct net_device *poll_dev = adapter->netdev; |
Andy Gospodarek | 679e8a0 | 2009-06-18 11:57:37 +0000 | [diff] [blame] | 2518 | int tx_cleaned = 1, work_done = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2519 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 2520 | adapter = netdev_priv(poll_dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2521 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2522 | if (adapter->msix_entries && |
| 2523 | !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) |
| 2524 | goto clean_rx; |
| 2525 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2526 | tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2527 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2528 | clean_rx: |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2529 | adapter->clean_rx(adapter->rx_ring, &work_done, budget); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2530 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 2531 | if (!tx_cleaned) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2532 | work_done = budget; |
| 2533 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 2534 | /* If budget not fully consumed, exit the polling mode */ |
| 2535 | if (work_done < budget) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2536 | if (adapter->itr_setting & 3) |
| 2537 | e1000_set_itr(adapter); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2538 | napi_complete(napi); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 2539 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 2540 | if (adapter->msix_entries) |
| 2541 | ew32(IMS, adapter->rx_ring->ims_val); |
| 2542 | else |
| 2543 | e1000_irq_enable(adapter); |
| 2544 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | return work_done; |
| 2548 | } |
| 2549 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2550 | 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] | 2551 | { |
| 2552 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2553 | struct e1000_hw *hw = &adapter->hw; |
| 2554 | u32 vfta, index; |
| 2555 | |
| 2556 | /* don't update vlan cookie if already programmed */ |
| 2557 | if ((adapter->hw.mng_cookie.status & |
| 2558 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2559 | (vid == adapter->mng_vlan_id)) |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2560 | return 0; |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2561 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2562 | /* add VID to filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2563 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2564 | index = (vid >> 5) & 0x7F; |
| 2565 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2566 | vfta |= (1 << (vid & 0x1F)); |
| 2567 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2568 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2569 | |
| 2570 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2571 | |
| 2572 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2575 | 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] | 2576 | { |
| 2577 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2578 | struct e1000_hw *hw = &adapter->hw; |
| 2579 | u32 vfta, index; |
| 2580 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2581 | if ((adapter->hw.mng_cookie.status & |
| 2582 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2583 | (vid == adapter->mng_vlan_id)) { |
| 2584 | /* release control to f/w */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2585 | e1000e_release_hw_control(adapter); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2586 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | /* remove VID from filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2590 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2591 | index = (vid >> 5) & 0x7F; |
| 2592 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2593 | vfta &= ~(1 << (vid & 0x1F)); |
| 2594 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2595 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2596 | |
| 2597 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2598 | |
| 2599 | return 0; |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | /** |
| 2603 | * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering |
| 2604 | * @adapter: board private structure to initialize |
| 2605 | **/ |
| 2606 | static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter) |
| 2607 | { |
| 2608 | struct net_device *netdev = adapter->netdev; |
| 2609 | struct e1000_hw *hw = &adapter->hw; |
| 2610 | u32 rctl; |
| 2611 | |
| 2612 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2613 | /* disable VLAN receive filtering */ |
| 2614 | rctl = er32(RCTL); |
| 2615 | rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN); |
| 2616 | ew32(RCTL, rctl); |
| 2617 | |
| 2618 | if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { |
| 2619 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 2620 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 2621 | } |
| 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | /** |
| 2626 | * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering |
| 2627 | * @adapter: board private structure to initialize |
| 2628 | **/ |
| 2629 | static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter) |
| 2630 | { |
| 2631 | struct e1000_hw *hw = &adapter->hw; |
| 2632 | u32 rctl; |
| 2633 | |
| 2634 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2635 | /* enable VLAN receive filtering */ |
| 2636 | rctl = er32(RCTL); |
| 2637 | rctl |= E1000_RCTL_VFE; |
| 2638 | rctl &= ~E1000_RCTL_CFIEN; |
| 2639 | ew32(RCTL, rctl); |
| 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | /** |
| 2644 | * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping |
| 2645 | * @adapter: board private structure to initialize |
| 2646 | **/ |
| 2647 | static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter) |
| 2648 | { |
| 2649 | struct e1000_hw *hw = &adapter->hw; |
| 2650 | u32 ctrl; |
| 2651 | |
| 2652 | /* disable VLAN tag insert/strip */ |
| 2653 | ctrl = er32(CTRL); |
| 2654 | ctrl &= ~E1000_CTRL_VME; |
| 2655 | ew32(CTRL, ctrl); |
| 2656 | } |
| 2657 | |
| 2658 | /** |
| 2659 | * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping |
| 2660 | * @adapter: board private structure to initialize |
| 2661 | **/ |
| 2662 | static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter) |
| 2663 | { |
| 2664 | struct e1000_hw *hw = &adapter->hw; |
| 2665 | u32 ctrl; |
| 2666 | |
| 2667 | /* enable VLAN tag insert/strip */ |
| 2668 | ctrl = er32(CTRL); |
| 2669 | ctrl |= E1000_CTRL_VME; |
| 2670 | ew32(CTRL, ctrl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 2674 | { |
| 2675 | struct net_device *netdev = adapter->netdev; |
| 2676 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 2677 | u16 old_vid = adapter->mng_vlan_id; |
| 2678 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2679 | if (adapter->hw.mng_cookie.status & |
| 2680 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
| 2681 | e1000_vlan_rx_add_vid(netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2682 | adapter->mng_vlan_id = vid; |
| 2683 | } |
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 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid)) |
| 2686 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
| 2690 | { |
| 2691 | u16 vid; |
| 2692 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2693 | e1000_vlan_rx_add_vid(adapter->netdev, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2694 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2695 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2696 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2699 | static void e1000_init_manageability_pt(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2700 | { |
| 2701 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2702 | u32 manc, manc2h, mdef, i, j; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2703 | |
| 2704 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) |
| 2705 | return; |
| 2706 | |
| 2707 | manc = er32(MANC); |
| 2708 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2709 | /* |
| 2710 | * enable receiving management packets to the host. this will probably |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2711 | * generate destination unreachable messages from the host OS, but |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2712 | * the packets will be handled on SMBUS |
| 2713 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2714 | manc |= E1000_MANC_EN_MNG2HOST; |
| 2715 | manc2h = er32(MANC2H); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2716 | |
| 2717 | switch (hw->mac.type) { |
| 2718 | default: |
| 2719 | manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664); |
| 2720 | break; |
| 2721 | case e1000_82574: |
| 2722 | case e1000_82583: |
| 2723 | /* |
| 2724 | * Check if IPMI pass-through decision filter already exists; |
| 2725 | * if so, enable it. |
| 2726 | */ |
| 2727 | for (i = 0, j = 0; i < 8; i++) { |
| 2728 | mdef = er32(MDEF(i)); |
| 2729 | |
| 2730 | /* Ignore filters with anything other than IPMI ports */ |
Dan Carpenter | 3b21b50 | 2010-06-02 13:43:15 +0000 | [diff] [blame] | 2731 | if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2732 | continue; |
| 2733 | |
| 2734 | /* Enable this decision filter in MANC2H */ |
| 2735 | if (mdef) |
| 2736 | manc2h |= (1 << i); |
| 2737 | |
| 2738 | j |= mdef; |
| 2739 | } |
| 2740 | |
| 2741 | if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
| 2742 | break; |
| 2743 | |
| 2744 | /* Create new decision filter in an empty filter */ |
| 2745 | for (i = 0, j = 0; i < 8; i++) |
| 2746 | if (er32(MDEF(i)) == 0) { |
| 2747 | ew32(MDEF(i), (E1000_MDEF_PORT_623 | |
| 2748 | E1000_MDEF_PORT_664)); |
| 2749 | manc2h |= (1 << 1); |
| 2750 | j++; |
| 2751 | break; |
| 2752 | } |
| 2753 | |
| 2754 | if (!j) |
| 2755 | e_warn("Unable to create IPMI pass-through filter\n"); |
| 2756 | break; |
| 2757 | } |
| 2758 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2759 | ew32(MANC2H, manc2h); |
| 2760 | ew32(MANC, manc); |
| 2761 | } |
| 2762 | |
| 2763 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2764 | * e1000_configure_tx - Configure Transmit Unit after Reset |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2765 | * @adapter: board private structure |
| 2766 | * |
| 2767 | * Configure the Tx unit of the MAC after a reset. |
| 2768 | **/ |
| 2769 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
| 2770 | { |
| 2771 | struct e1000_hw *hw = &adapter->hw; |
| 2772 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2773 | u64 tdba; |
Bruce Allan | c550b12 | 2011-12-16 00:46:17 +0000 | [diff] [blame] | 2774 | u32 tdlen, tarc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2775 | |
| 2776 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 2777 | tdba = tx_ring->dma; |
| 2778 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2779 | ew32(TDBAL, (tdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2780 | ew32(TDBAH, (tdba >> 32)); |
| 2781 | ew32(TDLEN, tdlen); |
| 2782 | ew32(TDH, 0); |
| 2783 | ew32(TDT, 0); |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2784 | tx_ring->head = adapter->hw.hw_addr + E1000_TDH; |
| 2785 | tx_ring->tail = adapter->hw.hw_addr + E1000_TDT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2786 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2787 | /* Set the Tx Interrupt Delay register */ |
| 2788 | ew32(TIDV, adapter->tx_int_delay); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2789 | /* Tx irq moderation */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2790 | ew32(TADV, adapter->tx_abs_int_delay); |
| 2791 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2792 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 2793 | u32 txdctl = er32(TXDCTL(0)); |
| 2794 | txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH | |
| 2795 | E1000_TXDCTL_WTHRESH); |
| 2796 | /* |
| 2797 | * set up some performance related parameters to encourage the |
| 2798 | * hardware to use the bus more efficiently in bursts, depends |
| 2799 | * on the tx_int_delay to be enabled, |
| 2800 | * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time |
| 2801 | * hthresh = 1 ==> prefetch when one or more available |
| 2802 | * pthresh = 0x1f ==> prefetch if internal cache 31 or less |
| 2803 | * BEWARE: this seems to work but should be considered first if |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2804 | * there are Tx hangs or other Tx related bugs |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2805 | */ |
| 2806 | txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE; |
| 2807 | ew32(TXDCTL(0), txdctl); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2808 | } |
Bruce Allan | 56032be | 2011-12-16 00:46:01 +0000 | [diff] [blame] | 2809 | /* erratum work around: set txdctl the same for both queues */ |
| 2810 | ew32(TXDCTL(1), er32(TXDCTL(0))); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2811 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2812 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2813 | tarc = er32(TARC(0)); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2814 | /* |
| 2815 | * set the speed mode bit, we'll clear it if we're not at |
| 2816 | * gigabit link later |
| 2817 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2818 | #define SPEED_MODE_BIT (1 << 21) |
| 2819 | tarc |= SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2820 | ew32(TARC(0), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | /* errata: program both queues to unweighted RR */ |
| 2824 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2825 | tarc = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2826 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2827 | ew32(TARC(0), tarc); |
| 2828 | tarc = er32(TARC(1)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2829 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2830 | ew32(TARC(1), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2833 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 2834 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 2835 | |
| 2836 | /* only set IDE if we are delaying interrupts using the timers */ |
| 2837 | if (adapter->tx_int_delay) |
| 2838 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
| 2839 | |
| 2840 | /* enable Report Status bit */ |
| 2841 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 2842 | |
Simon Horman | edfea6e6 | 2009-06-08 14:28:36 +0000 | [diff] [blame] | 2843 | e1000e_config_collision_dist(hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | /** |
| 2847 | * e1000_setup_rctl - configure the receive control registers |
| 2848 | * @adapter: Board private structure |
| 2849 | **/ |
| 2850 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 2851 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
| 2852 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
| 2853 | { |
| 2854 | struct e1000_hw *hw = &adapter->hw; |
| 2855 | u32 rctl, rfctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2856 | u32 pages = 0; |
| 2857 | |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 2858 | /* Workaround Si errata on 82579 - configure jumbo frame flow */ |
| 2859 | if (hw->mac.type == e1000_pch2lan) { |
| 2860 | s32 ret_val; |
| 2861 | |
| 2862 | if (adapter->netdev->mtu > ETH_DATA_LEN) |
| 2863 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true); |
| 2864 | else |
| 2865 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false); |
Bruce Allan | dd93f95 | 2011-01-06 14:29:48 +0000 | [diff] [blame] | 2866 | |
| 2867 | if (ret_val) |
| 2868 | e_dbg("failed to enable jumbo frame workaround mode\n"); |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 2869 | } |
| 2870 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2871 | /* Program MC offset vector base */ |
| 2872 | rctl = er32(RCTL); |
| 2873 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 2874 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 2875 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 2876 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 2877 | |
| 2878 | /* Do not Store bad packets */ |
| 2879 | rctl &= ~E1000_RCTL_SBP; |
| 2880 | |
| 2881 | /* Enable Long Packet receive */ |
| 2882 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2883 | rctl &= ~E1000_RCTL_LPE; |
| 2884 | else |
| 2885 | rctl |= E1000_RCTL_LPE; |
| 2886 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 2887 | /* Some systems expect that the CRC is included in SMBUS traffic. The |
| 2888 | * hardware strips the CRC before sending to both SMBUS (BMC) and to |
| 2889 | * host memory when this is enabled |
| 2890 | */ |
| 2891 | if (adapter->flags2 & FLAG2_CRC_STRIPPING) |
| 2892 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 5918bd8 | 2008-02-12 15:20:24 -0800 | [diff] [blame] | 2893 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 2894 | /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ |
| 2895 | if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { |
| 2896 | u16 phy_data; |
| 2897 | |
| 2898 | e1e_rphy(hw, PHY_REG(770, 26), &phy_data); |
| 2899 | phy_data &= 0xfff8; |
| 2900 | phy_data |= (1 << 2); |
| 2901 | e1e_wphy(hw, PHY_REG(770, 26), phy_data); |
| 2902 | |
| 2903 | e1e_rphy(hw, 22, &phy_data); |
| 2904 | phy_data &= 0x0fff; |
| 2905 | phy_data |= (1 << 14); |
| 2906 | e1e_wphy(hw, 0x10, 0x2823); |
| 2907 | e1e_wphy(hw, 0x11, 0x0003); |
| 2908 | e1e_wphy(hw, 22, phy_data); |
| 2909 | } |
| 2910 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2911 | /* Setup buffer sizes */ |
| 2912 | rctl &= ~E1000_RCTL_SZ_4096; |
| 2913 | rctl |= E1000_RCTL_BSEX; |
| 2914 | switch (adapter->rx_buffer_len) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2915 | case 2048: |
| 2916 | default: |
| 2917 | rctl |= E1000_RCTL_SZ_2048; |
| 2918 | rctl &= ~E1000_RCTL_BSEX; |
| 2919 | break; |
| 2920 | case 4096: |
| 2921 | rctl |= E1000_RCTL_SZ_4096; |
| 2922 | break; |
| 2923 | case 8192: |
| 2924 | rctl |= E1000_RCTL_SZ_8192; |
| 2925 | break; |
| 2926 | case 16384: |
| 2927 | rctl |= E1000_RCTL_SZ_16384; |
| 2928 | break; |
| 2929 | } |
| 2930 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 2931 | /* Enable Extended Status in all Receive Descriptors */ |
| 2932 | rfctl = er32(RFCTL); |
| 2933 | rfctl |= E1000_RFCTL_EXTEN; |
| 2934 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2935 | /* |
| 2936 | * 82571 and greater support packet-split where the protocol |
| 2937 | * header is placed in skb->data and the packet data is |
| 2938 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 2939 | * In the case of a non-split, skb->data is linearly filled, |
| 2940 | * followed by the page buffers. Therefore, skb->data is |
| 2941 | * sized to hold the largest protocol header. |
| 2942 | * |
| 2943 | * allocations using alloc_page take too long for regular MTU |
| 2944 | * so only enable packet split for jumbo frames |
| 2945 | * |
| 2946 | * Using pages when the page size is greater than 16k wastes |
| 2947 | * a lot of memory, since we allocate 3 pages at all times |
| 2948 | * per packet. |
| 2949 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2950 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 2951 | if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2952 | adapter->rx_ps_pages = pages; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 2953 | else |
| 2954 | adapter->rx_ps_pages = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2955 | |
| 2956 | if (adapter->rx_ps_pages) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 2957 | u32 psrctl = 0; |
| 2958 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2959 | /* |
| 2960 | * disable packet split support for IPv6 extension headers, |
| 2961 | * because some malformed IPv6 headers can hang the Rx |
| 2962 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2963 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
| 2964 | E1000_RFCTL_NEW_IPV6_EXT_DIS); |
| 2965 | |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 2966 | /* Enable Packet split descriptors */ |
| 2967 | rctl |= E1000_RCTL_DTYP_PS; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2968 | |
| 2969 | psrctl |= adapter->rx_ps_bsize0 >> |
| 2970 | E1000_PSRCTL_BSIZE0_SHIFT; |
| 2971 | |
| 2972 | switch (adapter->rx_ps_pages) { |
| 2973 | case 3: |
| 2974 | psrctl |= PAGE_SIZE << |
| 2975 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 2976 | case 2: |
| 2977 | psrctl |= PAGE_SIZE << |
| 2978 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 2979 | case 1: |
| 2980 | psrctl |= PAGE_SIZE >> |
| 2981 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 2982 | break; |
| 2983 | } |
| 2984 | |
| 2985 | ew32(PSRCTL, psrctl); |
| 2986 | } |
| 2987 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 2988 | ew32(RFCTL, rfctl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2989 | ew32(RCTL, rctl); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 2990 | /* just started the receive unit, no need to restart */ |
| 2991 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | /** |
| 2995 | * e1000_configure_rx - Configure Receive Unit after Reset |
| 2996 | * @adapter: board private structure |
| 2997 | * |
| 2998 | * Configure the Rx unit of the MAC after a reset. |
| 2999 | **/ |
| 3000 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
| 3001 | { |
| 3002 | struct e1000_hw *hw = &adapter->hw; |
| 3003 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 3004 | u64 rdba; |
| 3005 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
| 3006 | |
| 3007 | if (adapter->rx_ps_pages) { |
| 3008 | /* this is a 32 byte descriptor */ |
| 3009 | rdlen = rx_ring->count * |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3010 | sizeof(union e1000_rx_desc_packet_split); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3011 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 3012 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3013 | } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3014 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3015 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 3016 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3017 | } else { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3018 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3019 | adapter->clean_rx = e1000_clean_rx_irq; |
| 3020 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 3021 | } |
| 3022 | |
| 3023 | /* disable receives while setting up the descriptors */ |
| 3024 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3025 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3026 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3027 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3028 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3029 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3030 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 3031 | /* |
| 3032 | * set the writeback threshold (only takes effect if the RDTR |
| 3033 | * 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] | 3034 | * enable prefetching of 0x20 Rx descriptors |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3035 | * granularity = 01 |
| 3036 | * wthresh = 04, |
| 3037 | * hthresh = 04, |
| 3038 | * pthresh = 0x20 |
| 3039 | */ |
| 3040 | ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3041 | ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3042 | |
| 3043 | /* |
| 3044 | * override the delay timers for enabling bursting, only if |
| 3045 | * the value was not set by the user via module options |
| 3046 | */ |
| 3047 | if (adapter->rx_int_delay == DEFAULT_RDTR) |
| 3048 | adapter->rx_int_delay = BURST_RDTR; |
| 3049 | if (adapter->rx_abs_int_delay == DEFAULT_RADV) |
| 3050 | adapter->rx_abs_int_delay = BURST_RADV; |
| 3051 | } |
| 3052 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3053 | /* set the Receive Delay Timer Register */ |
| 3054 | ew32(RDTR, adapter->rx_int_delay); |
| 3055 | |
| 3056 | /* irq moderation */ |
| 3057 | ew32(RADV, adapter->rx_abs_int_delay); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3058 | if ((adapter->itr_setting != 0) && (adapter->itr != 0)) |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3059 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3060 | |
| 3061 | ctrl_ext = er32(CTRL_EXT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3062 | /* Auto-Mask interrupts upon ICR access */ |
| 3063 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 3064 | ew32(IAM, 0xffffffff); |
| 3065 | ew32(CTRL_EXT, ctrl_ext); |
| 3066 | e1e_flush(); |
| 3067 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3068 | /* |
| 3069 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3070 | * the Base and Length of the Rx Descriptor Ring |
| 3071 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3072 | rdba = rx_ring->dma; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3073 | ew32(RDBAL, (rdba & DMA_BIT_MASK(32))); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3074 | ew32(RDBAH, (rdba >> 32)); |
| 3075 | ew32(RDLEN, rdlen); |
| 3076 | ew32(RDH, 0); |
| 3077 | ew32(RDT, 0); |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 3078 | rx_ring->head = adapter->hw.hw_addr + E1000_RDH; |
| 3079 | rx_ring->tail = adapter->hw.hw_addr + E1000_RDT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3080 | |
| 3081 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 3082 | rxcsum = er32(RXCSUM); |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 3083 | if (adapter->netdev->features & NETIF_F_RXCSUM) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3084 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 3085 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3086 | /* |
| 3087 | * IPv4 payload checksum for UDP fragments must be |
| 3088 | * used in conjunction with packet-split. |
| 3089 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3090 | if (adapter->rx_ps_pages) |
| 3091 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 3092 | } else { |
| 3093 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 3094 | /* no need to clear IPPCSE as it defaults to 0 */ |
| 3095 | } |
| 3096 | ew32(RXCSUM, rxcsum); |
| 3097 | |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3098 | if (adapter->hw.mac.type == e1000_pch2lan) { |
| 3099 | /* |
| 3100 | * With jumbo frames, excessive C-state transition |
| 3101 | * latencies result in dropped transactions. |
| 3102 | */ |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3103 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3104 | u32 rxdctl = er32(RXDCTL(0)); |
| 3105 | ew32(RXDCTL(0), rxdctl | 0x3); |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3106 | pm_qos_update_request(&adapter->netdev->pm_qos_req, 55); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3107 | } else { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3108 | pm_qos_update_request(&adapter->netdev->pm_qos_req, |
| 3109 | PM_QOS_DEFAULT_VALUE); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3110 | } |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3111 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3112 | |
| 3113 | /* Enable Receives */ |
| 3114 | ew32(RCTL, rctl); |
| 3115 | } |
| 3116 | |
| 3117 | /** |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3118 | * e1000e_write_mc_addr_list - write multicast addresses to MTA |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3119 | * @netdev: network interface device structure |
| 3120 | * |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3121 | * Writes multicast address list to the MTA hash table. |
| 3122 | * Returns: -ENOMEM on failure |
| 3123 | * 0 on no addresses written |
| 3124 | * X on writing X addresses to MTA |
| 3125 | */ |
| 3126 | static int e1000e_write_mc_addr_list(struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3127 | { |
| 3128 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3129 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3130 | struct netdev_hw_addr *ha; |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3131 | u8 *mta_list; |
| 3132 | int i; |
| 3133 | |
| 3134 | if (netdev_mc_empty(netdev)) { |
| 3135 | /* nothing to program, so clear mc list */ |
| 3136 | hw->mac.ops.update_mc_addr_list(hw, NULL, 0); |
| 3137 | return 0; |
| 3138 | } |
| 3139 | |
| 3140 | mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC); |
| 3141 | if (!mta_list) |
| 3142 | return -ENOMEM; |
| 3143 | |
| 3144 | /* update_mc_addr_list expects a packed array of only addresses. */ |
| 3145 | i = 0; |
| 3146 | netdev_for_each_mc_addr(ha, netdev) |
| 3147 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
| 3148 | |
| 3149 | hw->mac.ops.update_mc_addr_list(hw, mta_list, i); |
| 3150 | kfree(mta_list); |
| 3151 | |
| 3152 | return netdev_mc_count(netdev); |
| 3153 | } |
| 3154 | |
| 3155 | /** |
| 3156 | * e1000e_write_uc_addr_list - write unicast addresses to RAR table |
| 3157 | * @netdev: network interface device structure |
| 3158 | * |
| 3159 | * Writes unicast address list to the RAR table. |
| 3160 | * Returns: -ENOMEM on failure/insufficient address space |
| 3161 | * 0 on no addresses written |
| 3162 | * X on writing X addresses to the RAR table |
| 3163 | **/ |
| 3164 | static int e1000e_write_uc_addr_list(struct net_device *netdev) |
| 3165 | { |
| 3166 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3167 | struct e1000_hw *hw = &adapter->hw; |
| 3168 | unsigned int rar_entries = hw->mac.rar_entry_count; |
| 3169 | int count = 0; |
| 3170 | |
| 3171 | /* save a rar entry for our hardware address */ |
| 3172 | rar_entries--; |
| 3173 | |
| 3174 | /* save a rar entry for the LAA workaround */ |
| 3175 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) |
| 3176 | rar_entries--; |
| 3177 | |
| 3178 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3179 | if (netdev_uc_count(netdev) > rar_entries) |
| 3180 | return -ENOMEM; |
| 3181 | |
| 3182 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3183 | struct netdev_hw_addr *ha; |
| 3184 | |
| 3185 | /* |
| 3186 | * write the addresses in reverse order to avoid write |
| 3187 | * combining |
| 3188 | */ |
| 3189 | netdev_for_each_uc_addr(ha, netdev) { |
| 3190 | if (!rar_entries) |
| 3191 | break; |
| 3192 | e1000e_rar_set(hw, ha->addr, rar_entries--); |
| 3193 | count++; |
| 3194 | } |
| 3195 | } |
| 3196 | |
| 3197 | /* zero out the remaining RAR entries not used above */ |
| 3198 | for (; rar_entries > 0; rar_entries--) { |
| 3199 | ew32(RAH(rar_entries), 0); |
| 3200 | ew32(RAL(rar_entries), 0); |
| 3201 | } |
| 3202 | e1e_flush(); |
| 3203 | |
| 3204 | return count; |
| 3205 | } |
| 3206 | |
| 3207 | /** |
| 3208 | * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set |
| 3209 | * @netdev: network interface device structure |
| 3210 | * |
| 3211 | * The ndo_set_rx_mode entry point is called whenever the unicast or multicast |
| 3212 | * address list or the network interface flags are updated. This routine is |
| 3213 | * responsible for configuring the hardware for proper unicast, multicast, |
| 3214 | * promiscuous mode, and all-multi behavior. |
| 3215 | **/ |
| 3216 | static void e1000e_set_rx_mode(struct net_device *netdev) |
| 3217 | { |
| 3218 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3219 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3220 | u32 rctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3221 | |
| 3222 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3223 | rctl = er32(RCTL); |
| 3224 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3225 | /* clear the affected bits */ |
| 3226 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 3227 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3228 | if (netdev->flags & IFF_PROMISC) { |
| 3229 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3230 | /* Do not hardware filter VLANs in promisc mode */ |
| 3231 | e1000e_vlan_filter_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3232 | } else { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3233 | int count; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3234 | if (netdev->flags & IFF_ALLMULTI) { |
| 3235 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3236 | } else { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3237 | /* |
| 3238 | * Write addresses to the MTA, if the attempt fails |
| 3239 | * then we should just turn on promiscuous mode so |
| 3240 | * that we can at least receive multicast traffic |
| 3241 | */ |
| 3242 | count = e1000e_write_mc_addr_list(netdev); |
| 3243 | if (count < 0) |
| 3244 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3245 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3246 | e1000e_vlan_filter_enable(adapter); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3247 | /* |
| 3248 | * Write addresses to available RAR registers, if there is not |
| 3249 | * sufficient space to store all the addresses then enable |
| 3250 | * unicast promiscuous mode |
| 3251 | */ |
| 3252 | count = e1000e_write_uc_addr_list(netdev); |
| 3253 | if (count < 0) |
| 3254 | rctl |= E1000_RCTL_UPE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | ew32(RCTL, rctl); |
| 3258 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3259 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3260 | e1000e_vlan_strip_enable(adapter); |
| 3261 | else |
| 3262 | e1000e_vlan_strip_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3265 | static void e1000e_setup_rss_hash(struct e1000_adapter *adapter) |
| 3266 | { |
| 3267 | struct e1000_hw *hw = &adapter->hw; |
| 3268 | u32 mrqc, rxcsum; |
| 3269 | int i; |
| 3270 | static const u32 rsskey[10] = { |
| 3271 | 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0, |
| 3272 | 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe |
| 3273 | }; |
| 3274 | |
| 3275 | /* Fill out hash function seed */ |
| 3276 | for (i = 0; i < 10; i++) |
| 3277 | ew32(RSSRK(i), rsskey[i]); |
| 3278 | |
| 3279 | /* Direct all traffic to queue 0 */ |
| 3280 | for (i = 0; i < 32; i++) |
| 3281 | ew32(RETA(i), 0); |
| 3282 | |
| 3283 | /* |
| 3284 | * Disable raw packet checksumming so that RSS hash is placed in |
| 3285 | * descriptor on writeback. |
| 3286 | */ |
| 3287 | rxcsum = er32(RXCSUM); |
| 3288 | rxcsum |= E1000_RXCSUM_PCSD; |
| 3289 | |
| 3290 | ew32(RXCSUM, rxcsum); |
| 3291 | |
| 3292 | mrqc = (E1000_MRQC_RSS_FIELD_IPV4 | |
| 3293 | E1000_MRQC_RSS_FIELD_IPV4_TCP | |
| 3294 | E1000_MRQC_RSS_FIELD_IPV6 | |
| 3295 | E1000_MRQC_RSS_FIELD_IPV6_TCP | |
| 3296 | E1000_MRQC_RSS_FIELD_IPV6_TCP_EX); |
| 3297 | |
| 3298 | ew32(MRQC, mrqc); |
| 3299 | } |
| 3300 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3301 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3302 | * e1000_configure - configure the hardware for Rx and Tx |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3303 | * @adapter: private board structure |
| 3304 | **/ |
| 3305 | static void e1000_configure(struct e1000_adapter *adapter) |
| 3306 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3307 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 3308 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3309 | e1000e_set_rx_mode(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3310 | |
| 3311 | e1000_restore_vlan(adapter); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 3312 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3313 | |
| 3314 | e1000_configure_tx(adapter); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3315 | |
| 3316 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 3317 | e1000e_setup_rss_hash(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3318 | e1000_setup_rctl(adapter); |
| 3319 | e1000_configure_rx(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3320 | adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | /** |
| 3324 | * e1000e_power_up_phy - restore link in case the phy was powered down |
| 3325 | * @adapter: address of board private structure |
| 3326 | * |
| 3327 | * The phy may be powered down to save power and turn off link when the |
| 3328 | * driver is unloaded and wake on lan is not enabled (among others) |
| 3329 | * *** this routine MUST be followed by a call to e1000e_reset *** |
| 3330 | **/ |
| 3331 | void e1000e_power_up_phy(struct e1000_adapter *adapter) |
| 3332 | { |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3333 | if (adapter->hw.phy.ops.power_up) |
| 3334 | adapter->hw.phy.ops.power_up(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3335 | |
| 3336 | adapter->hw.mac.ops.setup_link(&adapter->hw); |
| 3337 | } |
| 3338 | |
| 3339 | /** |
| 3340 | * e1000_power_down_phy - Power down the PHY |
| 3341 | * |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3342 | * Power down the PHY so no link is implied when interface is down. |
| 3343 | * The PHY cannot be powered down if management or WoL is active. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3344 | */ |
| 3345 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 3346 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3347 | /* WoL is enabled */ |
Auke Kok | 23b66e2 | 2008-02-11 09:25:51 -0800 | [diff] [blame] | 3348 | if (adapter->wol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3349 | return; |
| 3350 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3351 | if (adapter->hw.phy.ops.power_down) |
| 3352 | adapter->hw.phy.ops.power_down(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3353 | } |
| 3354 | |
| 3355 | /** |
| 3356 | * e1000e_reset - bring the hardware into a known good state |
| 3357 | * |
| 3358 | * This function boots the hardware and enables some settings that |
| 3359 | * require a configuration cycle of the hardware - those cannot be |
| 3360 | * set/changed during runtime. After reset the device needs to be |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3361 | * properly configured for Rx, Tx etc. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3362 | */ |
| 3363 | void e1000e_reset(struct e1000_adapter *adapter) |
| 3364 | { |
| 3365 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3366 | struct e1000_fc_info *fc = &adapter->hw.fc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3367 | struct e1000_hw *hw = &adapter->hw; |
| 3368 | u32 tx_space, min_tx_space, min_rx_space; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3369 | u32 pba = adapter->pba; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3370 | u16 hwm; |
| 3371 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3372 | /* reset Packet Buffer Allocation to default */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3373 | ew32(PBA, pba); |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3374 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3375 | if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3376 | /* |
| 3377 | * To maintain wire speed transmits, the Tx FIFO should be |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3378 | * large enough to accommodate two full transmit packets, |
| 3379 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 3380 | * the Rx FIFO should be large enough to accommodate at least |
| 3381 | * one full receive packet and is similarly rounded up and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3382 | * expressed in KB. |
| 3383 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3384 | pba = er32(PBA); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3385 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3386 | tx_space = pba >> 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3387 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3388 | pba &= 0xffff; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3389 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3390 | * the Tx fifo also stores 16 bytes of information about the Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3391 | * but don't include ethernet FCS because hardware appends it |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3392 | */ |
| 3393 | min_tx_space = (adapter->max_frame_size + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3394 | sizeof(struct e1000_tx_desc) - |
| 3395 | ETH_FCS_LEN) * 2; |
| 3396 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 3397 | min_tx_space >>= 10; |
| 3398 | /* software strips receive CRC, so leave room for it */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3399 | min_rx_space = adapter->max_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3400 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 3401 | min_rx_space >>= 10; |
| 3402 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3403 | /* |
| 3404 | * If current Tx allocation is less than the min Tx FIFO size, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3405 | * 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] | 3406 | * allocation, take space away from current Rx allocation |
| 3407 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3408 | if ((tx_space < min_tx_space) && |
| 3409 | ((min_tx_space - tx_space) < pba)) { |
| 3410 | pba -= min_tx_space - tx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3411 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3412 | /* |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3413 | * if short on Rx space, Rx wins and must trump Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3414 | * adjustment or use Early Receive if available |
| 3415 | */ |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3416 | if (pba < min_rx_space) |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3417 | pba = min_rx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3418 | } |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3419 | |
| 3420 | ew32(PBA, pba); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3421 | } |
| 3422 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3423 | /* |
| 3424 | * flow control settings |
| 3425 | * |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3426 | * 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] | 3427 | * (or the size used for early receive) above it in the Rx FIFO. |
| 3428 | * Set it to the lower of: |
| 3429 | * - 90% of the Rx FIFO size, and |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3430 | * - the full Rx FIFO size minus one full frame |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3431 | */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3432 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
| 3433 | fc->pause_time = 0xFFFF; |
| 3434 | else |
| 3435 | fc->pause_time = E1000_FC_PAUSE_TIME; |
| 3436 | fc->send_xon = 1; |
| 3437 | fc->current_mode = fc->requested_mode; |
| 3438 | |
| 3439 | switch (hw->mac.type) { |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3440 | case e1000_ich9lan: |
| 3441 | case e1000_ich10lan: |
| 3442 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3443 | pba = 14; |
| 3444 | ew32(PBA, pba); |
| 3445 | fc->high_water = 0x2800; |
| 3446 | fc->low_water = fc->high_water - 8; |
| 3447 | break; |
| 3448 | } |
| 3449 | /* fall-through */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3450 | default: |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3451 | hwm = min(((pba << 10) * 9 / 10), |
| 3452 | ((pba << 10) - adapter->max_frame_size)); |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3453 | |
| 3454 | fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ |
| 3455 | fc->low_water = fc->high_water - 8; |
| 3456 | break; |
| 3457 | case e1000_pchlan: |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3458 | /* |
| 3459 | * Workaround PCH LOM adapter hangs with certain network |
| 3460 | * loads. If hangs persist, try disabling Tx flow control. |
| 3461 | */ |
| 3462 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3463 | fc->high_water = 0x3500; |
| 3464 | fc->low_water = 0x1500; |
| 3465 | } else { |
| 3466 | fc->high_water = 0x5000; |
| 3467 | fc->low_water = 0x3000; |
| 3468 | } |
Bruce Allan | a305595 | 2010-05-10 15:02:12 +0000 | [diff] [blame] | 3469 | fc->refresh_time = 0x1000; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3470 | break; |
| 3471 | case e1000_pch2lan: |
| 3472 | fc->high_water = 0x05C20; |
| 3473 | fc->low_water = 0x05048; |
| 3474 | fc->pause_time = 0x0650; |
| 3475 | fc->refresh_time = 0x0400; |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3476 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3477 | pba = 14; |
| 3478 | ew32(PBA, pba); |
| 3479 | } |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3480 | break; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3481 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3482 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3483 | /* |
| 3484 | * Disable Adaptive Interrupt Moderation if 2 full packets cannot |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3485 | * fit in receive buffer. |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3486 | */ |
| 3487 | if (adapter->itr_setting & 0x3) { |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3488 | if ((adapter->max_frame_size * 2) > (pba << 10)) { |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3489 | if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) { |
| 3490 | dev_info(&adapter->pdev->dev, |
| 3491 | "Interrupt Throttle Rate turned off\n"); |
| 3492 | adapter->flags2 |= FLAG2_DISABLE_AIM; |
| 3493 | ew32(ITR, 0); |
| 3494 | } |
| 3495 | } else if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 3496 | dev_info(&adapter->pdev->dev, |
| 3497 | "Interrupt Throttle Rate turned on\n"); |
| 3498 | adapter->flags2 &= ~FLAG2_DISABLE_AIM; |
| 3499 | adapter->itr = 20000; |
| 3500 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
| 3501 | } |
| 3502 | } |
| 3503 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3504 | /* Allow time for pending master requests to run */ |
| 3505 | mac->ops.reset_hw(hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3506 | |
| 3507 | /* |
| 3508 | * For parts with AMT enabled, let the firmware know |
| 3509 | * that the network interface is in control |
| 3510 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 3511 | if (adapter->flags & FLAG_HAS_AMT) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3512 | e1000e_get_hw_control(adapter); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3513 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3514 | ew32(WUC, 0); |
| 3515 | |
| 3516 | if (mac->ops.init_hw(hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 3517 | e_err("Hardware Error\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3518 | |
| 3519 | e1000_update_mng_vlan(adapter); |
| 3520 | |
| 3521 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 3522 | ew32(VET, ETH_P_8021Q); |
| 3523 | |
| 3524 | e1000e_reset_adaptive(hw); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3525 | |
| 3526 | if (!netif_running(adapter->netdev) && |
| 3527 | !test_bit(__E1000_TESTING, &adapter->state)) { |
| 3528 | e1000_power_down_phy(adapter); |
| 3529 | return; |
| 3530 | } |
| 3531 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3532 | e1000_get_phy_info(hw); |
| 3533 | |
Bruce Allan | 918d719 | 2009-06-02 11:28:20 +0000 | [diff] [blame] | 3534 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && |
| 3535 | !(adapter->flags & FLAG_SMART_POWER_DOWN)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3536 | u16 phy_data = 0; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3537 | /* |
| 3538 | * speed up time to link by disabling smart power down, ignore |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3539 | * the return value of this function because there is nothing |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3540 | * different we would do if it failed |
| 3541 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3542 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
| 3543 | phy_data &= ~IGP02E1000_PM_SPD; |
| 3544 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 3545 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | int e1000e_up(struct e1000_adapter *adapter) |
| 3549 | { |
| 3550 | struct e1000_hw *hw = &adapter->hw; |
| 3551 | |
| 3552 | /* hardware has been reset, we need to reload some things */ |
| 3553 | e1000_configure(adapter); |
| 3554 | |
| 3555 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3556 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3557 | if (adapter->msix_entries) |
| 3558 | e1000_configure_msix(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3559 | e1000_irq_enable(adapter); |
| 3560 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 3561 | netif_start_queue(adapter->netdev); |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3562 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3563 | /* fire a link change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3564 | if (adapter->msix_entries) |
| 3565 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3566 | else |
| 3567 | ew32(ICS, E1000_ICS_LSC); |
| 3568 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3569 | return 0; |
| 3570 | } |
| 3571 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3572 | static void e1000e_flush_descriptors(struct e1000_adapter *adapter) |
| 3573 | { |
| 3574 | struct e1000_hw *hw = &adapter->hw; |
| 3575 | |
| 3576 | if (!(adapter->flags2 & FLAG2_DMA_BURST)) |
| 3577 | return; |
| 3578 | |
| 3579 | /* flush pending descriptor writebacks to memory */ |
| 3580 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 3581 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 3582 | |
| 3583 | /* execute the writes immediately */ |
| 3584 | e1e_flush(); |
| 3585 | } |
| 3586 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3587 | static void e1000e_update_stats(struct e1000_adapter *adapter); |
| 3588 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3589 | void e1000e_down(struct e1000_adapter *adapter) |
| 3590 | { |
| 3591 | struct net_device *netdev = adapter->netdev; |
| 3592 | struct e1000_hw *hw = &adapter->hw; |
| 3593 | u32 tctl, rctl; |
| 3594 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3595 | /* |
| 3596 | * signal that we're down so the interrupt handler does not |
| 3597 | * reschedule our watchdog timer |
| 3598 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3599 | set_bit(__E1000_DOWN, &adapter->state); |
| 3600 | |
| 3601 | /* disable receives in the hardware */ |
| 3602 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3603 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3604 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3605 | /* flush and sleep below */ |
| 3606 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3607 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3608 | |
| 3609 | /* disable transmits in the hardware */ |
| 3610 | tctl = er32(TCTL); |
| 3611 | tctl &= ~E1000_TCTL_EN; |
| 3612 | ew32(TCTL, tctl); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3613 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3614 | /* flush both disables and wait for them to finish */ |
| 3615 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3616 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3617 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3618 | e1000_irq_disable(adapter); |
| 3619 | |
| 3620 | del_timer_sync(&adapter->watchdog_timer); |
| 3621 | del_timer_sync(&adapter->phy_info_timer); |
| 3622 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3623 | netif_carrier_off(netdev); |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3624 | |
| 3625 | spin_lock(&adapter->stats64_lock); |
| 3626 | e1000e_update_stats(adapter); |
| 3627 | spin_unlock(&adapter->stats64_lock); |
| 3628 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 3629 | e1000e_flush_descriptors(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3630 | e1000_clean_tx_ring(adapter->tx_ring); |
| 3631 | e1000_clean_rx_ring(adapter->rx_ring); |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 3632 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3633 | adapter->link_speed = 0; |
| 3634 | adapter->link_duplex = 0; |
| 3635 | |
Jeff Kirsher | 52cc308 | 2008-06-24 17:01:29 -0700 | [diff] [blame] | 3636 | if (!pci_channel_offline(adapter->pdev)) |
| 3637 | e1000e_reset(adapter); |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3638 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3639 | /* |
| 3640 | * TODO: for power management, we could drop the link and |
| 3641 | * pci_disable_device here. |
| 3642 | */ |
| 3643 | } |
| 3644 | |
| 3645 | void e1000e_reinit_locked(struct e1000_adapter *adapter) |
| 3646 | { |
| 3647 | might_sleep(); |
| 3648 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3649 | usleep_range(1000, 2000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3650 | e1000e_down(adapter); |
| 3651 | e1000e_up(adapter); |
| 3652 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 3653 | } |
| 3654 | |
| 3655 | /** |
| 3656 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 3657 | * @adapter: board private structure to initialize |
| 3658 | * |
| 3659 | * e1000_sw_init initializes the Adapter private data structure. |
| 3660 | * Fields are initialized based on PCI device information and |
| 3661 | * OS network device settings (MTU size). |
| 3662 | **/ |
| 3663 | static int __devinit e1000_sw_init(struct e1000_adapter *adapter) |
| 3664 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3665 | struct net_device *netdev = adapter->netdev; |
| 3666 | |
| 3667 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN; |
| 3668 | adapter->rx_ps_bsize0 = 128; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3669 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3670 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3671 | adapter->tx_ring_count = E1000_DEFAULT_TXD; |
| 3672 | adapter->rx_ring_count = E1000_DEFAULT_RXD; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3673 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3674 | spin_lock_init(&adapter->stats64_lock); |
| 3675 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3676 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3677 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3678 | if (e1000_alloc_queues(adapter)) |
| 3679 | return -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3680 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3681 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3682 | e1000_irq_disable(adapter); |
| 3683 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3684 | set_bit(__E1000_DOWN, &adapter->state); |
| 3685 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | /** |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3689 | * e1000_intr_msi_test - Interrupt Handler |
| 3690 | * @irq: interrupt number |
| 3691 | * @data: pointer to a network interface device structure |
| 3692 | **/ |
| 3693 | static irqreturn_t e1000_intr_msi_test(int irq, void *data) |
| 3694 | { |
| 3695 | struct net_device *netdev = data; |
| 3696 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3697 | struct e1000_hw *hw = &adapter->hw; |
| 3698 | u32 icr = er32(ICR); |
| 3699 | |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 3700 | e_dbg("icr is %08X\n", icr); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3701 | if (icr & E1000_ICR_RXSEQ) { |
| 3702 | adapter->flags &= ~FLAG_MSI_TEST_FAILED; |
| 3703 | wmb(); |
| 3704 | } |
| 3705 | |
| 3706 | return IRQ_HANDLED; |
| 3707 | } |
| 3708 | |
| 3709 | /** |
| 3710 | * e1000_test_msi_interrupt - Returns 0 for successful test |
| 3711 | * @adapter: board private struct |
| 3712 | * |
| 3713 | * code flow taken from tg3.c |
| 3714 | **/ |
| 3715 | static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) |
| 3716 | { |
| 3717 | struct net_device *netdev = adapter->netdev; |
| 3718 | struct e1000_hw *hw = &adapter->hw; |
| 3719 | int err; |
| 3720 | |
| 3721 | /* poll_enable hasn't been called yet, so don't need disable */ |
| 3722 | /* clear any pending events */ |
| 3723 | er32(ICR); |
| 3724 | |
| 3725 | /* free the real vector and request a test handler */ |
| 3726 | e1000_free_irq(adapter); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3727 | e1000e_reset_interrupt_capability(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3728 | |
| 3729 | /* Assume that the test fails, if it succeeds then the test |
| 3730 | * MSI irq handler will unset this flag */ |
| 3731 | adapter->flags |= FLAG_MSI_TEST_FAILED; |
| 3732 | |
| 3733 | err = pci_enable_msi(adapter->pdev); |
| 3734 | if (err) |
| 3735 | goto msi_test_failed; |
| 3736 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3737 | err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3738 | netdev->name, netdev); |
| 3739 | if (err) { |
| 3740 | pci_disable_msi(adapter->pdev); |
| 3741 | goto msi_test_failed; |
| 3742 | } |
| 3743 | |
| 3744 | wmb(); |
| 3745 | |
| 3746 | e1000_irq_enable(adapter); |
| 3747 | |
| 3748 | /* fire an unusual interrupt on the test handler */ |
| 3749 | ew32(ICS, E1000_ICS_RXSEQ); |
| 3750 | e1e_flush(); |
| 3751 | msleep(50); |
| 3752 | |
| 3753 | e1000_irq_disable(adapter); |
| 3754 | |
| 3755 | rmb(); |
| 3756 | |
| 3757 | if (adapter->flags & FLAG_MSI_TEST_FAILED) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3758 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 3759 | e_info("MSI interrupt test failed, using legacy interrupt.\n"); |
Bruce Allan | 24b706b | 2012-01-31 06:37:22 +0000 | [diff] [blame] | 3760 | } else { |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 3761 | e_dbg("MSI interrupt test succeeded!\n"); |
Bruce Allan | 24b706b | 2012-01-31 06:37:22 +0000 | [diff] [blame] | 3762 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3763 | |
| 3764 | free_irq(adapter->pdev->irq, netdev); |
| 3765 | pci_disable_msi(adapter->pdev); |
| 3766 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3767 | msi_test_failed: |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3768 | e1000e_set_interrupt_capability(adapter); |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 3769 | return e1000_request_irq(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | /** |
| 3773 | * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored |
| 3774 | * @adapter: board private struct |
| 3775 | * |
| 3776 | * code flow taken from tg3.c, called with e1000 interrupts disabled. |
| 3777 | **/ |
| 3778 | static int e1000_test_msi(struct e1000_adapter *adapter) |
| 3779 | { |
| 3780 | int err; |
| 3781 | u16 pci_cmd; |
| 3782 | |
| 3783 | if (!(adapter->flags & FLAG_MSI_ENABLED)) |
| 3784 | return 0; |
| 3785 | |
| 3786 | /* disable SERR in case the MSI write causes a master abort */ |
| 3787 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 3788 | if (pci_cmd & PCI_COMMAND_SERR) |
| 3789 | pci_write_config_word(adapter->pdev, PCI_COMMAND, |
| 3790 | pci_cmd & ~PCI_COMMAND_SERR); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3791 | |
| 3792 | err = e1000_test_msi_interrupt(adapter); |
| 3793 | |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 3794 | /* re-enable SERR */ |
| 3795 | if (pci_cmd & PCI_COMMAND_SERR) { |
| 3796 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
| 3797 | pci_cmd |= PCI_COMMAND_SERR; |
| 3798 | pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); |
| 3799 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3800 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3801 | return err; |
| 3802 | } |
| 3803 | |
| 3804 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3805 | * e1000_open - Called when a network interface is made active |
| 3806 | * @netdev: network interface device structure |
| 3807 | * |
| 3808 | * Returns 0 on success, negative value on failure |
| 3809 | * |
| 3810 | * The open entry point is called when a network interface is made |
| 3811 | * active by the system (IFF_UP). At this point all resources needed |
| 3812 | * for transmit and receive operations are allocated, the interrupt |
| 3813 | * handler is registered with the OS, the watchdog timer is started, |
| 3814 | * and the stack is notified that the interface is ready. |
| 3815 | **/ |
| 3816 | static int e1000_open(struct net_device *netdev) |
| 3817 | { |
| 3818 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3819 | struct e1000_hw *hw = &adapter->hw; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3820 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3821 | int err; |
| 3822 | |
| 3823 | /* disallow open during test */ |
| 3824 | if (test_bit(__E1000_TESTING, &adapter->state)) |
| 3825 | return -EBUSY; |
| 3826 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3827 | pm_runtime_get_sync(&pdev->dev); |
| 3828 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 3829 | netif_carrier_off(netdev); |
| 3830 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3831 | /* allocate transmit descriptors */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3832 | err = e1000e_setup_tx_resources(adapter->tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3833 | if (err) |
| 3834 | goto err_setup_tx; |
| 3835 | |
| 3836 | /* allocate receive descriptors */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3837 | err = e1000e_setup_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3838 | if (err) |
| 3839 | goto err_setup_rx; |
| 3840 | |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 3841 | /* |
| 3842 | * If AMT is enabled, let the firmware know that the network |
| 3843 | * interface is now open and reset the part to a known state. |
| 3844 | */ |
| 3845 | if (adapter->flags & FLAG_HAS_AMT) { |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3846 | e1000e_get_hw_control(adapter); |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 3847 | e1000e_reset(adapter); |
| 3848 | } |
| 3849 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3850 | e1000e_power_up_phy(adapter); |
| 3851 | |
| 3852 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 3853 | if ((adapter->hw.mng_cookie.status & |
| 3854 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
| 3855 | e1000_update_mng_vlan(adapter); |
| 3856 | |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3857 | /* DMA latency requirement to workaround jumbo issue */ |
| 3858 | if (adapter->hw.mac.type == e1000_pch2lan) |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 3859 | pm_qos_add_request(&adapter->netdev->pm_qos_req, |
| 3860 | PM_QOS_CPU_DMA_LATENCY, |
| 3861 | PM_QOS_DEFAULT_VALUE); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3862 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3863 | /* |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3864 | * before we allocate an interrupt, we must be ready to handle it. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3865 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 3866 | * 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] | 3867 | * clean_rx handler before we do so. |
| 3868 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3869 | e1000_configure(adapter); |
| 3870 | |
| 3871 | err = e1000_request_irq(adapter); |
| 3872 | if (err) |
| 3873 | goto err_req_irq; |
| 3874 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3875 | /* |
| 3876 | * Work around PCIe errata with MSI interrupts causing some chipsets to |
| 3877 | * ignore e1000e MSI messages, which means we need to test our MSI |
| 3878 | * interrupt now |
| 3879 | */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3880 | if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 3881 | err = e1000_test_msi(adapter); |
| 3882 | if (err) { |
| 3883 | e_err("Interrupt allocation failed\n"); |
| 3884 | goto err_req_irq; |
| 3885 | } |
| 3886 | } |
| 3887 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3888 | /* From here on the code is the same as e1000e_up() */ |
| 3889 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3890 | |
| 3891 | napi_enable(&adapter->napi); |
| 3892 | |
| 3893 | e1000_irq_enable(adapter); |
| 3894 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 3895 | adapter->tx_hang_recheck = false; |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3896 | netif_start_queue(netdev); |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 3897 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3898 | adapter->idle_check = true; |
| 3899 | pm_runtime_put(&pdev->dev); |
| 3900 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3901 | /* fire a link status change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3902 | if (adapter->msix_entries) |
| 3903 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3904 | else |
| 3905 | ew32(ICS, E1000_ICS_LSC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3906 | |
| 3907 | return 0; |
| 3908 | |
| 3909 | err_req_irq: |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3910 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3911 | e1000_power_down_phy(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3912 | e1000e_free_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3913 | err_setup_rx: |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3914 | e1000e_free_tx_resources(adapter->tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3915 | err_setup_tx: |
| 3916 | e1000e_reset(adapter); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3917 | pm_runtime_put_sync(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3918 | |
| 3919 | return err; |
| 3920 | } |
| 3921 | |
| 3922 | /** |
| 3923 | * e1000_close - Disables a network interface |
| 3924 | * @netdev: network interface device structure |
| 3925 | * |
| 3926 | * Returns 0, this is not allowed to fail |
| 3927 | * |
| 3928 | * The close entry point is called when an interface is de-activated |
| 3929 | * by the OS. The hardware is still under the drivers control, but |
| 3930 | * needs to be disabled. A global MAC reset is issued to stop the |
| 3931 | * hardware, and all transmit and receive resources are freed. |
| 3932 | **/ |
| 3933 | static int e1000_close(struct net_device *netdev) |
| 3934 | { |
| 3935 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3936 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3937 | |
| 3938 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3939 | |
| 3940 | pm_runtime_get_sync(&pdev->dev); |
| 3941 | |
Bruce Allan | 5f4a780 | 2011-11-29 08:09:19 +0000 | [diff] [blame] | 3942 | napi_disable(&adapter->napi); |
| 3943 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3944 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 3945 | e1000e_down(adapter); |
| 3946 | e1000_free_irq(adapter); |
| 3947 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3948 | e1000_power_down_phy(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3949 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3950 | e1000e_free_tx_resources(adapter->tx_ring); |
| 3951 | e1000e_free_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3952 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3953 | /* |
| 3954 | * kill manageability vlan ID if supported, but not if a vlan with |
| 3955 | * the same ID is registered on the host OS (let 8021q kill it) |
| 3956 | */ |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3957 | if (adapter->hw.mng_cookie.status & |
| 3958 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3959 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 3960 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3961 | /* |
| 3962 | * If AMT is enabled, let the firmware know that the network |
| 3963 | * interface is now closed |
| 3964 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3965 | if ((adapter->flags & FLAG_HAS_AMT) && |
| 3966 | !test_bit(__E1000_TESTING, &adapter->state)) |
| 3967 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3968 | |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3969 | if (adapter->hw.mac.type == e1000_pch2lan) |
Linus Torvalds | 6ba7401 | 2010-08-04 11:47:58 -0700 | [diff] [blame] | 3970 | pm_qos_remove_request(&adapter->netdev->pm_qos_req); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 3971 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 3972 | pm_runtime_put_sync(&pdev->dev); |
| 3973 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3974 | return 0; |
| 3975 | } |
| 3976 | /** |
| 3977 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 3978 | * @netdev: network interface device structure |
| 3979 | * @p: pointer to an address structure |
| 3980 | * |
| 3981 | * Returns 0 on success, negative on failure |
| 3982 | **/ |
| 3983 | static int e1000_set_mac(struct net_device *netdev, void *p) |
| 3984 | { |
| 3985 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3986 | struct sockaddr *addr = p; |
| 3987 | |
| 3988 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3989 | return -EADDRNOTAVAIL; |
| 3990 | |
| 3991 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 3992 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 3993 | |
| 3994 | e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0); |
| 3995 | |
| 3996 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { |
| 3997 | /* activate the work around */ |
| 3998 | e1000e_set_laa_state_82571(&adapter->hw, 1); |
| 3999 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4000 | /* |
| 4001 | * 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] | 4002 | * between the time RAR[0] gets clobbered and the time it |
| 4003 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
| 4004 | * of the RARs and no incoming packets directed to this port |
| 4005 | * are dropped. Eventually the LAA will be in RAR[0] and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4006 | * RAR[14] |
| 4007 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4008 | e1000e_rar_set(&adapter->hw, |
| 4009 | adapter->hw.mac.addr, |
| 4010 | adapter->hw.mac.rar_entry_count - 1); |
| 4011 | } |
| 4012 | |
| 4013 | return 0; |
| 4014 | } |
| 4015 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4016 | /** |
| 4017 | * e1000e_update_phy_task - work thread to update phy |
| 4018 | * @work: pointer to our work struct |
| 4019 | * |
| 4020 | * this worker thread exists because we must acquire a |
| 4021 | * semaphore to read the phy, which we could msleep while |
| 4022 | * waiting for it, and we can't msleep in a timer. |
| 4023 | **/ |
| 4024 | static void e1000e_update_phy_task(struct work_struct *work) |
| 4025 | { |
| 4026 | struct e1000_adapter *adapter = container_of(work, |
| 4027 | struct e1000_adapter, update_phy_task); |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4028 | |
| 4029 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4030 | return; |
| 4031 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4032 | e1000_get_phy_info(&adapter->hw); |
| 4033 | } |
| 4034 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4035 | /* |
| 4036 | * Need to wait a few seconds after link up to get diagnostic information from |
| 4037 | * the phy |
| 4038 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4039 | static void e1000_update_phy_info(unsigned long data) |
| 4040 | { |
| 4041 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4042 | |
| 4043 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4044 | return; |
| 4045 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4046 | schedule_work(&adapter->update_phy_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4047 | } |
| 4048 | |
| 4049 | /** |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4050 | * e1000e_update_phy_stats - Update the PHY statistics counters |
| 4051 | * @adapter: board private structure |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4052 | * |
| 4053 | * Read/clear the upper 16-bit PHY registers and read/accumulate lower |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4054 | **/ |
| 4055 | static void e1000e_update_phy_stats(struct e1000_adapter *adapter) |
| 4056 | { |
| 4057 | struct e1000_hw *hw = &adapter->hw; |
| 4058 | s32 ret_val; |
| 4059 | u16 phy_data; |
| 4060 | |
| 4061 | ret_val = hw->phy.ops.acquire(hw); |
| 4062 | if (ret_val) |
| 4063 | return; |
| 4064 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4065 | /* |
| 4066 | * A page set is expensive so check if already on desired page. |
| 4067 | * If not, set to the page with the PHY status registers. |
| 4068 | */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4069 | hw->phy.addr = 1; |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4070 | ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 4071 | &phy_data); |
| 4072 | if (ret_val) |
| 4073 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4074 | if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) { |
| 4075 | ret_val = hw->phy.ops.set_page(hw, |
| 4076 | HV_STATS_PAGE << IGP_PAGE_SHIFT); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4077 | if (ret_val) |
| 4078 | goto release; |
| 4079 | } |
| 4080 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4081 | /* Single Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4082 | hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data); |
| 4083 | 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] | 4084 | if (!ret_val) |
| 4085 | adapter->stats.scc += phy_data; |
| 4086 | |
| 4087 | /* Excessive Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4088 | hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data); |
| 4089 | 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] | 4090 | if (!ret_val) |
| 4091 | adapter->stats.ecol += phy_data; |
| 4092 | |
| 4093 | /* Multiple Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4094 | hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data); |
| 4095 | 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] | 4096 | if (!ret_val) |
| 4097 | adapter->stats.mcc += phy_data; |
| 4098 | |
| 4099 | /* Late Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4100 | hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data); |
| 4101 | 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] | 4102 | if (!ret_val) |
| 4103 | adapter->stats.latecol += phy_data; |
| 4104 | |
| 4105 | /* Collision Count - also used for adaptive IFS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4106 | hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data); |
| 4107 | 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] | 4108 | if (!ret_val) |
| 4109 | hw->mac.collision_delta = phy_data; |
| 4110 | |
| 4111 | /* Defer Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4112 | hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data); |
| 4113 | 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] | 4114 | if (!ret_val) |
| 4115 | adapter->stats.dc += phy_data; |
| 4116 | |
| 4117 | /* Transmit with no CRS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4118 | hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data); |
| 4119 | 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] | 4120 | if (!ret_val) |
| 4121 | adapter->stats.tncrs += phy_data; |
| 4122 | |
| 4123 | release: |
| 4124 | hw->phy.ops.release(hw); |
| 4125 | } |
| 4126 | |
| 4127 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4128 | * e1000e_update_stats - Update the board statistics counters |
| 4129 | * @adapter: board private structure |
| 4130 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4131 | static void e1000e_update_stats(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4132 | { |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4133 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4134 | struct e1000_hw *hw = &adapter->hw; |
| 4135 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4136 | |
| 4137 | /* |
| 4138 | * Prevent stats update while adapter is being reset, or if the pci |
| 4139 | * connection is down. |
| 4140 | */ |
| 4141 | if (adapter->link_speed == 0) |
| 4142 | return; |
| 4143 | if (pci_channel_offline(pdev)) |
| 4144 | return; |
| 4145 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4146 | adapter->stats.crcerrs += er32(CRCERRS); |
| 4147 | adapter->stats.gprc += er32(GPRC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4148 | adapter->stats.gorc += er32(GORCL); |
| 4149 | er32(GORCH); /* Clear gorc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4150 | adapter->stats.bprc += er32(BPRC); |
| 4151 | adapter->stats.mprc += er32(MPRC); |
| 4152 | adapter->stats.roc += er32(ROC); |
| 4153 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4154 | adapter->stats.mpc += er32(MPC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4155 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4156 | /* Half-duplex statistics */ |
| 4157 | if (adapter->link_duplex == HALF_DUPLEX) { |
| 4158 | if (adapter->flags2 & FLAG2_HAS_PHY_STATS) { |
| 4159 | e1000e_update_phy_stats(adapter); |
| 4160 | } else { |
| 4161 | adapter->stats.scc += er32(SCC); |
| 4162 | adapter->stats.ecol += er32(ECOL); |
| 4163 | adapter->stats.mcc += er32(MCC); |
| 4164 | adapter->stats.latecol += er32(LATECOL); |
| 4165 | adapter->stats.dc += er32(DC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4166 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4167 | hw->mac.collision_delta = er32(COLC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4168 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4169 | if ((hw->mac.type != e1000_82574) && |
| 4170 | (hw->mac.type != e1000_82583)) |
| 4171 | adapter->stats.tncrs += er32(TNCRS); |
| 4172 | } |
| 4173 | adapter->stats.colc += hw->mac.collision_delta; |
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 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4176 | adapter->stats.xonrxc += er32(XONRXC); |
| 4177 | adapter->stats.xontxc += er32(XONTXC); |
| 4178 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 4179 | adapter->stats.xofftxc += er32(XOFFTXC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4180 | adapter->stats.gptc += er32(GPTC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4181 | adapter->stats.gotc += er32(GOTCL); |
| 4182 | er32(GOTCH); /* Clear gotc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4183 | adapter->stats.rnbc += er32(RNBC); |
| 4184 | adapter->stats.ruc += er32(RUC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4185 | |
| 4186 | adapter->stats.mptc += er32(MPTC); |
| 4187 | adapter->stats.bptc += er32(BPTC); |
| 4188 | |
| 4189 | /* used for adaptive IFS */ |
| 4190 | |
| 4191 | hw->mac.tx_packet_delta = er32(TPT); |
| 4192 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4193 | |
| 4194 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 4195 | adapter->stats.rxerrc += er32(RXERRC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4196 | adapter->stats.cexterr += er32(CEXTERR); |
| 4197 | adapter->stats.tsctc += er32(TSCTC); |
| 4198 | adapter->stats.tsctfc += er32(TSCTFC); |
| 4199 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4200 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4201 | netdev->stats.multicast = adapter->stats.mprc; |
| 4202 | netdev->stats.collisions = adapter->stats.colc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4203 | |
| 4204 | /* Rx Errors */ |
| 4205 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4206 | /* |
| 4207 | * RLEC on some newer hardware can be incorrect so build |
| 4208 | * our own version based on RUC and ROC |
| 4209 | */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4210 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4211 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 4212 | adapter->stats.ruc + adapter->stats.roc + |
| 4213 | adapter->stats.cexterr; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4214 | netdev->stats.rx_length_errors = adapter->stats.ruc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4215 | adapter->stats.roc; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4216 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4217 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; |
| 4218 | netdev->stats.rx_missed_errors = adapter->stats.mpc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4219 | |
| 4220 | /* Tx Errors */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4221 | netdev->stats.tx_errors = adapter->stats.ecol + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4222 | adapter->stats.latecol; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4223 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
| 4224 | netdev->stats.tx_window_errors = adapter->stats.latecol; |
| 4225 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4226 | |
| 4227 | /* Tx Dropped needs to be maintained elsewhere */ |
| 4228 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4229 | /* Management Stats */ |
| 4230 | adapter->stats.mgptc += er32(MGTPTC); |
| 4231 | adapter->stats.mgprc += er32(MGTPRC); |
| 4232 | adapter->stats.mgpdc += er32(MGTPDC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4233 | } |
| 4234 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4235 | /** |
| 4236 | * e1000_phy_read_status - Update the PHY register status snapshot |
| 4237 | * @adapter: board private structure |
| 4238 | **/ |
| 4239 | static void e1000_phy_read_status(struct e1000_adapter *adapter) |
| 4240 | { |
| 4241 | struct e1000_hw *hw = &adapter->hw; |
| 4242 | struct e1000_phy_regs *phy = &adapter->phy_regs; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4243 | |
| 4244 | if ((er32(STATUS) & E1000_STATUS_LU) && |
| 4245 | (adapter->hw.phy.media_type == e1000_media_type_copper)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4246 | int ret_val; |
| 4247 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4248 | ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr); |
| 4249 | ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr); |
| 4250 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise); |
| 4251 | ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa); |
| 4252 | ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion); |
| 4253 | ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000); |
| 4254 | ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000); |
| 4255 | ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus); |
| 4256 | if (ret_val) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4257 | e_warn("Error reading PHY register\n"); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4258 | } else { |
| 4259 | /* |
| 4260 | * Do not read PHY registers if link is not up |
| 4261 | * Set values to typical power-on defaults |
| 4262 | */ |
| 4263 | phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); |
| 4264 | phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | |
| 4265 | BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | |
| 4266 | BMSR_ERCAP); |
| 4267 | phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | |
| 4268 | ADVERTISE_ALL | ADVERTISE_CSMA); |
| 4269 | phy->lpa = 0; |
| 4270 | phy->expansion = EXPANSION_ENABLENPAGE; |
| 4271 | phy->ctrl1000 = ADVERTISE_1000FULL; |
| 4272 | phy->stat1000 = 0; |
| 4273 | phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); |
| 4274 | } |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4275 | } |
| 4276 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4277 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
| 4278 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4279 | struct e1000_hw *hw = &adapter->hw; |
| 4280 | u32 ctrl = er32(CTRL); |
| 4281 | |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4282 | /* Link status message must follow this format for user tools */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 4283 | printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n", |
| 4284 | adapter->netdev->name, |
| 4285 | adapter->link_speed, |
| 4286 | adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half", |
| 4287 | (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" : |
| 4288 | (ctrl & E1000_CTRL_RFCE) ? "Rx" : |
| 4289 | (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4290 | } |
| 4291 | |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 4292 | static bool e1000e_has_link(struct e1000_adapter *adapter) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4293 | { |
| 4294 | struct e1000_hw *hw = &adapter->hw; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4295 | bool link_active = false; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4296 | s32 ret_val = 0; |
| 4297 | |
| 4298 | /* |
| 4299 | * get_link_status is set on LSC (link status) interrupt or |
| 4300 | * Rx sequence error interrupt. get_link_status will stay |
| 4301 | * false until the check_for_link establishes link |
| 4302 | * for copper adapters ONLY |
| 4303 | */ |
| 4304 | switch (hw->phy.media_type) { |
| 4305 | case e1000_media_type_copper: |
| 4306 | if (hw->mac.get_link_status) { |
| 4307 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4308 | link_active = !hw->mac.get_link_status; |
| 4309 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4310 | link_active = true; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4311 | } |
| 4312 | break; |
| 4313 | case e1000_media_type_fiber: |
| 4314 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4315 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 4316 | break; |
| 4317 | case e1000_media_type_internal_serdes: |
| 4318 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4319 | link_active = adapter->hw.mac.serdes_has_link; |
| 4320 | break; |
| 4321 | default: |
| 4322 | case e1000_media_type_unknown: |
| 4323 | break; |
| 4324 | } |
| 4325 | |
| 4326 | if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && |
| 4327 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 4328 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4329 | e_info("Gigabit has been disabled, downgrading speed\n"); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4330 | } |
| 4331 | |
| 4332 | return link_active; |
| 4333 | } |
| 4334 | |
| 4335 | static void e1000e_enable_receives(struct e1000_adapter *adapter) |
| 4336 | { |
| 4337 | /* make sure the receive unit is started */ |
| 4338 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 4339 | (adapter->flags & FLAG_RX_RESTART_NOW)) { |
| 4340 | struct e1000_hw *hw = &adapter->hw; |
| 4341 | u32 rctl = er32(RCTL); |
| 4342 | ew32(RCTL, rctl | E1000_RCTL_EN); |
| 4343 | adapter->flags &= ~FLAG_RX_RESTART_NOW; |
| 4344 | } |
| 4345 | } |
| 4346 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4347 | static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter) |
| 4348 | { |
| 4349 | struct e1000_hw *hw = &adapter->hw; |
| 4350 | |
| 4351 | /* |
| 4352 | * With 82574 controllers, PHY needs to be checked periodically |
| 4353 | * for hung state and reset, if two calls return true |
| 4354 | */ |
| 4355 | if (e1000_check_phy_82574(hw)) |
| 4356 | adapter->phy_hang_count++; |
| 4357 | else |
| 4358 | adapter->phy_hang_count = 0; |
| 4359 | |
| 4360 | if (adapter->phy_hang_count > 1) { |
| 4361 | adapter->phy_hang_count = 0; |
| 4362 | schedule_work(&adapter->reset_task); |
| 4363 | } |
| 4364 | } |
| 4365 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4366 | /** |
| 4367 | * e1000_watchdog - Timer Call-back |
| 4368 | * @data: pointer to adapter cast into an unsigned long |
| 4369 | **/ |
| 4370 | static void e1000_watchdog(unsigned long data) |
| 4371 | { |
| 4372 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 4373 | |
| 4374 | /* Do the rest outside of interrupt context */ |
| 4375 | schedule_work(&adapter->watchdog_task); |
| 4376 | |
| 4377 | /* TODO: make this use queue_delayed_work() */ |
| 4378 | } |
| 4379 | |
| 4380 | static void e1000_watchdog_task(struct work_struct *work) |
| 4381 | { |
| 4382 | struct e1000_adapter *adapter = container_of(work, |
| 4383 | struct e1000_adapter, watchdog_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4384 | struct net_device *netdev = adapter->netdev; |
| 4385 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4386 | struct e1000_phy_info *phy = &adapter->hw.phy; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4387 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4388 | struct e1000_hw *hw = &adapter->hw; |
| 4389 | u32 link, tctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4390 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4391 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4392 | return; |
| 4393 | |
David S. Miller | b405e8d | 2010-02-04 22:31:41 -0800 | [diff] [blame] | 4394 | link = e1000e_has_link(adapter); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4395 | if ((netif_carrier_ok(netdev)) && link) { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4396 | /* Cancel scheduled suspend requests. */ |
| 4397 | pm_runtime_resume(netdev->dev.parent); |
| 4398 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4399 | e1000e_enable_receives(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4400 | goto link_up; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | if ((e1000e_enable_tx_pkt_filtering(hw)) && |
| 4404 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) |
| 4405 | e1000_update_mng_vlan(adapter); |
| 4406 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4407 | if (link) { |
| 4408 | if (!netif_carrier_ok(netdev)) { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4409 | bool txb2b = true; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4410 | |
| 4411 | /* Cancel scheduled suspend requests. */ |
| 4412 | pm_runtime_resume(netdev->dev.parent); |
| 4413 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4414 | /* update snapshot of PHY registers on LSC */ |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4415 | e1000_phy_read_status(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4416 | mac->ops.get_link_up_info(&adapter->hw, |
| 4417 | &adapter->link_speed, |
| 4418 | &adapter->link_duplex); |
| 4419 | e1000_print_link_info(adapter); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4420 | /* |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 4421 | * On supported PHYs, check for duplex mismatch only |
| 4422 | * if link has autonegotiated at 10/100 half |
| 4423 | */ |
| 4424 | if ((hw->phy.type == e1000_phy_igp_3 || |
| 4425 | hw->phy.type == e1000_phy_bm) && |
| 4426 | (hw->mac.autoneg == true) && |
| 4427 | (adapter->link_speed == SPEED_10 || |
| 4428 | adapter->link_speed == SPEED_100) && |
| 4429 | (adapter->link_duplex == HALF_DUPLEX)) { |
| 4430 | u16 autoneg_exp; |
| 4431 | |
| 4432 | e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp); |
| 4433 | |
| 4434 | if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS)) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 4435 | 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] | 4436 | } |
| 4437 | |
Emil Tantilov | f49c57e | 2010-03-24 12:55:02 +0000 | [diff] [blame] | 4438 | /* adjust timeout factor according to speed/duplex */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4439 | adapter->tx_timeout_factor = 1; |
| 4440 | switch (adapter->link_speed) { |
| 4441 | case SPEED_10: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4442 | txb2b = false; |
Bruce Allan | 10f1b49 | 2008-08-08 18:36:01 -0700 | [diff] [blame] | 4443 | adapter->tx_timeout_factor = 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4444 | break; |
| 4445 | case SPEED_100: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4446 | txb2b = false; |
Bruce Allan | 4c86e0b | 2009-11-19 12:35:26 +0000 | [diff] [blame] | 4447 | adapter->tx_timeout_factor = 10; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4448 | break; |
| 4449 | } |
| 4450 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4451 | /* |
| 4452 | * workaround: re-program speed mode bit after |
| 4453 | * link-up event |
| 4454 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4455 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
| 4456 | !txb2b) { |
| 4457 | u32 tarc0; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4458 | tarc0 = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4459 | tarc0 &= ~SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4460 | ew32(TARC(0), tarc0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4461 | } |
| 4462 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4463 | /* |
| 4464 | * disable TSO for pcie and 10/100 speeds, to avoid |
| 4465 | * some hardware issues |
| 4466 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4467 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
| 4468 | switch (adapter->link_speed) { |
| 4469 | case SPEED_10: |
| 4470 | case SPEED_100: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4471 | e_info("10/100 speed: disabling TSO\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4472 | netdev->features &= ~NETIF_F_TSO; |
| 4473 | netdev->features &= ~NETIF_F_TSO6; |
| 4474 | break; |
| 4475 | case SPEED_1000: |
| 4476 | netdev->features |= NETIF_F_TSO; |
| 4477 | netdev->features |= NETIF_F_TSO6; |
| 4478 | break; |
| 4479 | default: |
| 4480 | /* oops */ |
| 4481 | break; |
| 4482 | } |
| 4483 | } |
| 4484 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4485 | /* |
| 4486 | * enable transmits in the hardware, need to do this |
| 4487 | * after setting TARC(0) |
| 4488 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4489 | tctl = er32(TCTL); |
| 4490 | tctl |= E1000_TCTL_EN; |
| 4491 | ew32(TCTL, tctl); |
| 4492 | |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4493 | /* |
| 4494 | * Perform any post-link-up configuration before |
| 4495 | * reporting link up. |
| 4496 | */ |
| 4497 | if (phy->ops.cfg_on_link_up) |
| 4498 | phy->ops.cfg_on_link_up(hw); |
| 4499 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4500 | netif_carrier_on(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4501 | |
| 4502 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4503 | mod_timer(&adapter->phy_info_timer, |
| 4504 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4505 | } |
| 4506 | } else { |
| 4507 | if (netif_carrier_ok(netdev)) { |
| 4508 | adapter->link_speed = 0; |
| 4509 | adapter->link_duplex = 0; |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4510 | /* Link status message must follow this format */ |
| 4511 | printk(KERN_INFO "e1000e: %s NIC Link is Down\n", |
| 4512 | adapter->netdev->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4513 | netif_carrier_off(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4514 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4515 | mod_timer(&adapter->phy_info_timer, |
| 4516 | round_jiffies(jiffies + 2 * HZ)); |
| 4517 | |
| 4518 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) |
| 4519 | schedule_work(&adapter->reset_task); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4520 | else |
| 4521 | pm_schedule_suspend(netdev->dev.parent, |
| 4522 | LINK_TIMEOUT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | link_up: |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4527 | spin_lock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4528 | e1000e_update_stats(adapter); |
| 4529 | |
| 4530 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 4531 | adapter->tpt_old = adapter->stats.tpt; |
| 4532 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; |
| 4533 | adapter->colc_old = adapter->stats.colc; |
| 4534 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4535 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
| 4536 | adapter->gorc_old = adapter->stats.gorc; |
| 4537 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; |
| 4538 | adapter->gotc_old = adapter->stats.gotc; |
Flavio Leitner | 2084b11 | 2011-04-05 04:27:43 +0000 | [diff] [blame] | 4539 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4540 | |
| 4541 | e1000e_update_adaptive(&adapter->hw); |
| 4542 | |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4543 | if (!netif_carrier_ok(netdev) && |
| 4544 | (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) { |
| 4545 | /* |
| 4546 | * We've lost link, so the controller stops DMA, |
| 4547 | * but we've got queued Tx work that's never going |
| 4548 | * to get done, so reset controller to flush Tx. |
| 4549 | * (Do the reset outside of interrupt context). |
| 4550 | */ |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4551 | schedule_work(&adapter->reset_task); |
| 4552 | /* return immediately since reset is imminent */ |
| 4553 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4554 | } |
| 4555 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4556 | /* Simple mode for Interrupt Throttle Rate (ITR) */ |
| 4557 | if (adapter->itr_setting == 4) { |
| 4558 | /* |
| 4559 | * Symmetric Tx/Rx gets a reduced ITR=2000; |
| 4560 | * Total asymmetrical Tx or Rx gets ITR=8000; |
| 4561 | * everyone else is between 2000-8000. |
| 4562 | */ |
| 4563 | u32 goc = (adapter->gotc + adapter->gorc) / 10000; |
| 4564 | u32 dif = (adapter->gotc > adapter->gorc ? |
| 4565 | adapter->gotc - adapter->gorc : |
| 4566 | adapter->gorc - adapter->gotc) / 10000; |
| 4567 | u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 4568 | |
| 4569 | ew32(ITR, 1000000000 / (itr * 256)); |
| 4570 | } |
| 4571 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4572 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4573 | if (adapter->msix_entries) |
| 4574 | ew32(ICS, adapter->rx_ring->ims_val); |
| 4575 | else |
| 4576 | ew32(ICS, E1000_ICS_RXDMT0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4577 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4578 | /* flush pending descriptors to memory before detecting Tx hang */ |
| 4579 | e1000e_flush_descriptors(adapter); |
| 4580 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4581 | /* Force detection of hung controller every watchdog period */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4582 | adapter->detect_tx_hung = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4583 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4584 | /* |
| 4585 | * With 82571 controllers, LAA may be overwritten due to controller |
| 4586 | * reset from the other port. Set the appropriate LAA in RAR[0] |
| 4587 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4588 | if (e1000e_get_laa_state_82571(hw)) |
| 4589 | e1000e_rar_set(hw, adapter->hw.mac.addr, 0); |
| 4590 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4591 | if (adapter->flags2 & FLAG2_CHECK_PHY_HANG) |
| 4592 | e1000e_check_82574_phy_workaround(adapter); |
| 4593 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4594 | /* Reset the timer */ |
| 4595 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4596 | mod_timer(&adapter->watchdog_timer, |
| 4597 | round_jiffies(jiffies + 2 * HZ)); |
| 4598 | } |
| 4599 | |
| 4600 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 4601 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 4602 | #define E1000_TX_FLAGS_TSO 0x00000004 |
| 4603 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
| 4604 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 4605 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 4606 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4607 | static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4608 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4609 | struct e1000_context_desc *context_desc; |
| 4610 | struct e1000_buffer *buffer_info; |
| 4611 | unsigned int i; |
| 4612 | u32 cmd_length = 0; |
| 4613 | u16 ipcse = 0, tucse, mss; |
| 4614 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4615 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4616 | if (!skb_is_gso(skb)) |
| 4617 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4618 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4619 | if (skb_header_cloned(skb)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4620 | int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4621 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4622 | if (err) |
| 4623 | return err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4624 | } |
| 4625 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4626 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 4627 | mss = skb_shinfo(skb)->gso_size; |
| 4628 | if (skb->protocol == htons(ETH_P_IP)) { |
| 4629 | struct iphdr *iph = ip_hdr(skb); |
| 4630 | iph->tot_len = 0; |
| 4631 | iph->check = 0; |
| 4632 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, |
| 4633 | 0, IPPROTO_TCP, 0); |
| 4634 | cmd_length = E1000_TXD_CMD_IP; |
| 4635 | ipcse = skb_transport_offset(skb) - 1; |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 4636 | } else if (skb_is_gso_v6(skb)) { |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 4637 | ipv6_hdr(skb)->payload_len = 0; |
| 4638 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 4639 | &ipv6_hdr(skb)->daddr, |
| 4640 | 0, IPPROTO_TCP, 0); |
| 4641 | ipcse = 0; |
| 4642 | } |
| 4643 | ipcss = skb_network_offset(skb); |
| 4644 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
| 4645 | tucss = skb_transport_offset(skb); |
| 4646 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
| 4647 | tucse = 0; |
| 4648 | |
| 4649 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
| 4650 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
| 4651 | |
| 4652 | i = tx_ring->next_to_use; |
| 4653 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 4654 | buffer_info = &tx_ring->buffer_info[i]; |
| 4655 | |
| 4656 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 4657 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 4658 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 4659 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 4660 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 4661 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 4662 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 4663 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 4664 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 4665 | |
| 4666 | buffer_info->time_stamp = jiffies; |
| 4667 | buffer_info->next_to_watch = i; |
| 4668 | |
| 4669 | i++; |
| 4670 | if (i == tx_ring->count) |
| 4671 | i = 0; |
| 4672 | tx_ring->next_to_use = i; |
| 4673 | |
| 4674 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4675 | } |
| 4676 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4677 | static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4678 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4679 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4680 | struct e1000_context_desc *context_desc; |
| 4681 | struct e1000_buffer *buffer_info; |
| 4682 | unsigned int i; |
| 4683 | u8 css; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4684 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4685 | __be16 protocol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4686 | |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4687 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 4688 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4689 | |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4690 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) |
| 4691 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 4692 | else |
| 4693 | protocol = skb->protocol; |
| 4694 | |
Arthur Jones | 3f51839 | 2009-03-20 15:56:35 -0700 | [diff] [blame] | 4695 | switch (protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4696 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4697 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 4698 | cmd_len |= E1000_TXD_CMD_TCP; |
| 4699 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4700 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4701 | /* XXX not handling all IPV6 headers */ |
| 4702 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 4703 | cmd_len |= E1000_TXD_CMD_TCP; |
| 4704 | break; |
| 4705 | default: |
| 4706 | if (unlikely(net_ratelimit())) |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 4707 | e_warn("checksum_partial proto=%x!\n", |
| 4708 | be16_to_cpu(protocol)); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4709 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4710 | } |
| 4711 | |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 4712 | css = skb_checksum_start_offset(skb); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 4713 | |
| 4714 | i = tx_ring->next_to_use; |
| 4715 | buffer_info = &tx_ring->buffer_info[i]; |
| 4716 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 4717 | |
| 4718 | context_desc->lower_setup.ip_config = 0; |
| 4719 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 4720 | context_desc->upper_setup.tcp_fields.tucso = |
| 4721 | css + skb->csum_offset; |
| 4722 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 4723 | context_desc->tcp_seg_setup.data = 0; |
| 4724 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 4725 | |
| 4726 | buffer_info->time_stamp = jiffies; |
| 4727 | buffer_info->next_to_watch = i; |
| 4728 | |
| 4729 | i++; |
| 4730 | if (i == tx_ring->count) |
| 4731 | i = 0; |
| 4732 | tx_ring->next_to_use = i; |
| 4733 | |
| 4734 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | #define E1000_MAX_PER_TXD 8192 |
| 4738 | #define E1000_MAX_TXD_PWR 12 |
| 4739 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4740 | static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb, |
| 4741 | unsigned int first, unsigned int max_per_txd, |
| 4742 | unsigned int nr_frags, unsigned int mss) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4743 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4744 | struct e1000_adapter *adapter = tx_ring->adapter; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4745 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4746 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 4747 | unsigned int len = skb_headlen(skb); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4748 | unsigned int offset = 0, size, count = 0, i; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4749 | unsigned int f, bytecount, segs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4750 | |
| 4751 | i = tx_ring->next_to_use; |
| 4752 | |
| 4753 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4754 | buffer_info = &tx_ring->buffer_info[i]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4755 | size = min(len, max_per_txd); |
| 4756 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4757 | buffer_info->length = size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4758 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4759 | buffer_info->next_to_watch = i; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4760 | buffer_info->dma = dma_map_single(&pdev->dev, |
| 4761 | skb->data + offset, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4762 | size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4763 | buffer_info->mapped_as_page = false; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4764 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4765 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4766 | |
| 4767 | len -= size; |
| 4768 | offset += size; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4769 | count++; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4770 | |
| 4771 | if (len) { |
| 4772 | i++; |
| 4773 | if (i == tx_ring->count) |
| 4774 | i = 0; |
| 4775 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | for (f = 0; f < nr_frags; f++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 4779 | const struct skb_frag_struct *frag; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4780 | |
| 4781 | frag = &skb_shinfo(skb)->frags[f]; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 4782 | len = skb_frag_size(frag); |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 4783 | offset = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4784 | |
| 4785 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 4786 | i++; |
| 4787 | if (i == tx_ring->count) |
| 4788 | i = 0; |
| 4789 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4790 | buffer_info = &tx_ring->buffer_info[i]; |
| 4791 | size = min(len, max_per_txd); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4792 | |
| 4793 | buffer_info->length = size; |
| 4794 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4795 | buffer_info->next_to_watch = i; |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 4796 | buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag, |
| 4797 | offset, size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4798 | buffer_info->mapped_as_page = true; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 4799 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4800 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4801 | |
| 4802 | len -= size; |
| 4803 | offset += size; |
| 4804 | count++; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4805 | } |
| 4806 | } |
| 4807 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4808 | segs = skb_shinfo(skb)->gso_segs ? : 1; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4809 | /* multiply data chunks by size of headers */ |
| 4810 | bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len; |
| 4811 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4812 | tx_ring->buffer_info[i].skb = skb; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 4813 | tx_ring->buffer_info[i].segs = segs; |
| 4814 | tx_ring->buffer_info[i].bytecount = bytecount; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4815 | tx_ring->buffer_info[first].next_to_watch = i; |
| 4816 | |
| 4817 | return count; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4818 | |
| 4819 | dma_error: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4820 | dev_err(&pdev->dev, "Tx DMA map failed\n"); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4821 | buffer_info->dma = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4822 | if (count) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4823 | count--; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4824 | |
| 4825 | while (count--) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 4826 | if (i == 0) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4827 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 4828 | i--; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4829 | buffer_info = &tx_ring->buffer_info[i]; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4830 | e1000_put_txbuf(tx_ring, buffer_info); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4834 | } |
| 4835 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4836 | static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4837 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4838 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4839 | struct e1000_tx_desc *tx_desc = NULL; |
| 4840 | struct e1000_buffer *buffer_info; |
| 4841 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 4842 | unsigned int i; |
| 4843 | |
| 4844 | if (tx_flags & E1000_TX_FLAGS_TSO) { |
| 4845 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 4846 | E1000_TXD_CMD_TSE; |
| 4847 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 4848 | |
| 4849 | if (tx_flags & E1000_TX_FLAGS_IPV4) |
| 4850 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
| 4851 | } |
| 4852 | |
| 4853 | if (tx_flags & E1000_TX_FLAGS_CSUM) { |
| 4854 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 4855 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 4856 | } |
| 4857 | |
| 4858 | if (tx_flags & E1000_TX_FLAGS_VLAN) { |
| 4859 | txd_lower |= E1000_TXD_CMD_VLE; |
| 4860 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 4861 | } |
| 4862 | |
| 4863 | i = tx_ring->next_to_use; |
| 4864 | |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 4865 | do { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4866 | buffer_info = &tx_ring->buffer_info[i]; |
| 4867 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 4868 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4869 | tx_desc->lower.data = |
| 4870 | cpu_to_le32(txd_lower | buffer_info->length); |
| 4871 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
| 4872 | |
| 4873 | i++; |
| 4874 | if (i == tx_ring->count) |
| 4875 | i = 0; |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 4876 | } while (--count > 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4877 | |
| 4878 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 4879 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4880 | /* |
| 4881 | * Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4882 | * know there are new descriptors to fetch. (Only |
| 4883 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4884 | * such as IA-64). |
| 4885 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4886 | wmb(); |
| 4887 | |
| 4888 | tx_ring->next_to_use = i; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 4889 | |
| 4890 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4891 | e1000e_update_tdt_wa(tx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 4892 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 4893 | writel(i, tx_ring->tail); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 4894 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4895 | /* |
| 4896 | * we need this if more than one processor can write to our tail |
| 4897 | * at a time, it synchronizes IO on IA64/Altix systems |
| 4898 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4899 | mmiowb(); |
| 4900 | } |
| 4901 | |
| 4902 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 4903 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 4904 | struct sk_buff *skb) |
| 4905 | { |
| 4906 | struct e1000_hw *hw = &adapter->hw; |
| 4907 | u16 length, offset; |
| 4908 | |
| 4909 | if (vlan_tx_tag_present(skb)) { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 4910 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
| 4911 | (adapter->hw.mng_cookie.status & |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4912 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) |
| 4913 | return 0; |
| 4914 | } |
| 4915 | |
| 4916 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) |
| 4917 | return 0; |
| 4918 | |
| 4919 | if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP)) |
| 4920 | return 0; |
| 4921 | |
| 4922 | { |
| 4923 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14); |
| 4924 | struct udphdr *udp; |
| 4925 | |
| 4926 | if (ip->protocol != IPPROTO_UDP) |
| 4927 | return 0; |
| 4928 | |
| 4929 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 4930 | if (ntohs(udp->dest) != 67) |
| 4931 | return 0; |
| 4932 | |
| 4933 | offset = (u8 *)udp + 8 - skb->data; |
| 4934 | length = skb->len - offset; |
| 4935 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); |
| 4936 | } |
| 4937 | |
| 4938 | return 0; |
| 4939 | } |
| 4940 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4941 | static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4942 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4943 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4944 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4945 | netif_stop_queue(adapter->netdev); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4946 | /* |
| 4947 | * Herbert's original patch had: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4948 | * smp_mb__after_netif_stop_queue(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4949 | * but since that doesn't exist yet, just open code it. |
| 4950 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4951 | smp_mb(); |
| 4952 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4953 | /* |
| 4954 | * We need to check again in a case another CPU has just |
| 4955 | * made room available. |
| 4956 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4957 | if (e1000_desc_unused(tx_ring) < size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4958 | return -EBUSY; |
| 4959 | |
| 4960 | /* A reprieve! */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4961 | netif_start_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4962 | ++adapter->restart_queue; |
| 4963 | return 0; |
| 4964 | } |
| 4965 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4966 | static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4967 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4968 | if (e1000_desc_unused(tx_ring) >= size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4969 | return 0; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4970 | return __e1000_maybe_stop_tx(tx_ring, size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4971 | } |
| 4972 | |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 4973 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1) |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 4974 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 4975 | struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4976 | { |
| 4977 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4978 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4979 | unsigned int first; |
| 4980 | unsigned int max_per_txd = E1000_MAX_PER_TXD; |
| 4981 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 4982 | unsigned int tx_flags = 0; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 4983 | unsigned int len = skb_headlen(skb); |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 4984 | unsigned int nr_frags; |
| 4985 | unsigned int mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4986 | int count = 0; |
| 4987 | int tso; |
| 4988 | unsigned int f; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4989 | |
| 4990 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 4991 | dev_kfree_skb_any(skb); |
| 4992 | return NETDEV_TX_OK; |
| 4993 | } |
| 4994 | |
| 4995 | if (skb->len <= 0) { |
| 4996 | dev_kfree_skb_any(skb); |
| 4997 | return NETDEV_TX_OK; |
| 4998 | } |
| 4999 | |
| 5000 | mss = skb_shinfo(skb)->gso_size; |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5001 | /* |
| 5002 | * The controller does a simple calculation to |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5003 | * make sure there is enough room in the FIFO before |
| 5004 | * initiating the DMA for each buffer. The calc is: |
| 5005 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 5006 | * overrun the FIFO, adjust the max buffer len if mss |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5007 | * drops. |
| 5008 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5009 | if (mss) { |
| 5010 | u8 hdr_len; |
| 5011 | max_per_txd = min(mss << 2, max_per_txd); |
| 5012 | max_txd_pwr = fls(max_per_txd) - 1; |
| 5013 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5014 | /* |
| 5015 | * TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 5016 | * points to just header, pull a few bytes of payload from |
| 5017 | * frags into skb->data |
| 5018 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5019 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5020 | /* |
| 5021 | * we do this workaround for ES2LAN, but it is un-necessary, |
| 5022 | * avoiding it could save a lot of cycles |
| 5023 | */ |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 5024 | if (skb->data_len && (hdr_len == len)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5025 | unsigned int pull_size; |
| 5026 | |
Bruce Allan | a2a5b32 | 2012-01-31 06:37:17 +0000 | [diff] [blame] | 5027 | pull_size = min_t(unsigned int, 4, skb->data_len); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5028 | if (!__pskb_pull_tail(skb, pull_size)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5029 | e_err("__pskb_pull_tail failed.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5030 | dev_kfree_skb_any(skb); |
| 5031 | return NETDEV_TX_OK; |
| 5032 | } |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5033 | len = skb_headlen(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5034 | } |
| 5035 | } |
| 5036 | |
| 5037 | /* reserve a descriptor for the offload context */ |
| 5038 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5039 | count++; |
| 5040 | count++; |
| 5041 | |
| 5042 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 5043 | |
| 5044 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 5045 | for (f = 0; f < nr_frags; f++) |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5046 | count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]), |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5047 | max_txd_pwr); |
| 5048 | |
| 5049 | if (adapter->hw.mac.tx_pkt_filtering) |
| 5050 | e1000_transfer_dhcp_info(adapter, skb); |
| 5051 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5052 | /* |
| 5053 | * need: count + 2 desc gap to keep tail from touching |
| 5054 | * head, otherwise try next time |
| 5055 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5056 | if (e1000_maybe_stop_tx(tx_ring, count + 2)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5057 | return NETDEV_TX_BUSY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5058 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 5059 | if (vlan_tx_tag_present(skb)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5060 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 5061 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 5062 | } |
| 5063 | |
| 5064 | first = tx_ring->next_to_use; |
| 5065 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5066 | tso = e1000_tso(tx_ring, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5067 | if (tso < 0) { |
| 5068 | dev_kfree_skb_any(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5069 | return NETDEV_TX_OK; |
| 5070 | } |
| 5071 | |
| 5072 | if (tso) |
| 5073 | tx_flags |= E1000_TX_FLAGS_TSO; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5074 | else if (e1000_tx_csum(tx_ring, skb)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5075 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 5076 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5077 | /* |
| 5078 | * 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] | 5079 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5080 | * no longer assume, we must. |
| 5081 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5082 | if (skb->protocol == htons(ETH_P_IP)) |
| 5083 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 5084 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5085 | /* if count is 0 then mapping error has occurred */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5086 | count = e1000_tx_map(tx_ring, skb, first, max_per_txd, nr_frags, mss); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5087 | if (count) { |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 5088 | netdev_sent_queue(netdev, skb->len); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5089 | e1000_tx_queue(tx_ring, tx_flags, count); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5090 | /* Make sure there is space in the ring for the next send. */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5091 | e1000_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 2); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5092 | |
| 5093 | } else { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5094 | dev_kfree_skb_any(skb); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5095 | tx_ring->buffer_info[first].time_stamp = 0; |
| 5096 | tx_ring->next_to_use = first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5097 | } |
| 5098 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5099 | return NETDEV_TX_OK; |
| 5100 | } |
| 5101 | |
| 5102 | /** |
| 5103 | * e1000_tx_timeout - Respond to a Tx Hang |
| 5104 | * @netdev: network interface device structure |
| 5105 | **/ |
| 5106 | static void e1000_tx_timeout(struct net_device *netdev) |
| 5107 | { |
| 5108 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5109 | |
| 5110 | /* Do the reset outside of interrupt context */ |
| 5111 | adapter->tx_timeout_count++; |
| 5112 | schedule_work(&adapter->reset_task); |
| 5113 | } |
| 5114 | |
| 5115 | static void e1000_reset_task(struct work_struct *work) |
| 5116 | { |
| 5117 | struct e1000_adapter *adapter; |
| 5118 | adapter = container_of(work, struct e1000_adapter, reset_task); |
| 5119 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 5120 | /* don't run the task if already down */ |
| 5121 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 5122 | return; |
| 5123 | |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 5124 | if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
| 5125 | (adapter->flags & FLAG_RX_RESTART_NOW))) { |
| 5126 | e1000e_dump(adapter); |
| 5127 | e_err("Reset adapter\n"); |
| 5128 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5129 | e1000e_reinit_locked(adapter); |
| 5130 | } |
| 5131 | |
| 5132 | /** |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5133 | * e1000_get_stats64 - Get System Network Statistics |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5134 | * @netdev: network interface device structure |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5135 | * @stats: rtnl_link_stats64 pointer |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5136 | * |
| 5137 | * Returns the address of the device statistics structure. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5138 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5139 | struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev, |
| 5140 | struct rtnl_link_stats64 *stats) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5141 | { |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5142 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5143 | |
| 5144 | memset(stats, 0, sizeof(struct rtnl_link_stats64)); |
| 5145 | spin_lock(&adapter->stats64_lock); |
| 5146 | e1000e_update_stats(adapter); |
| 5147 | /* Fill out the OS statistics structure */ |
| 5148 | stats->rx_bytes = adapter->stats.gorc; |
| 5149 | stats->rx_packets = adapter->stats.gprc; |
| 5150 | stats->tx_bytes = adapter->stats.gotc; |
| 5151 | stats->tx_packets = adapter->stats.gptc; |
| 5152 | stats->multicast = adapter->stats.mprc; |
| 5153 | stats->collisions = adapter->stats.colc; |
| 5154 | |
| 5155 | /* Rx Errors */ |
| 5156 | |
| 5157 | /* |
| 5158 | * RLEC on some newer hardware can be incorrect so build |
| 5159 | * our own version based on RUC and ROC |
| 5160 | */ |
| 5161 | stats->rx_errors = adapter->stats.rxerrc + |
| 5162 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 5163 | adapter->stats.ruc + adapter->stats.roc + |
| 5164 | adapter->stats.cexterr; |
| 5165 | stats->rx_length_errors = adapter->stats.ruc + |
| 5166 | adapter->stats.roc; |
| 5167 | stats->rx_crc_errors = adapter->stats.crcerrs; |
| 5168 | stats->rx_frame_errors = adapter->stats.algnerrc; |
| 5169 | stats->rx_missed_errors = adapter->stats.mpc; |
| 5170 | |
| 5171 | /* Tx Errors */ |
| 5172 | stats->tx_errors = adapter->stats.ecol + |
| 5173 | adapter->stats.latecol; |
| 5174 | stats->tx_aborted_errors = adapter->stats.ecol; |
| 5175 | stats->tx_window_errors = adapter->stats.latecol; |
| 5176 | stats->tx_carrier_errors = adapter->stats.tncrs; |
| 5177 | |
| 5178 | /* Tx Dropped needs to be maintained elsewhere */ |
| 5179 | |
| 5180 | spin_unlock(&adapter->stats64_lock); |
| 5181 | return stats; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | /** |
| 5185 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 5186 | * @netdev: network interface device structure |
| 5187 | * @new_mtu: new value for maximum frame size |
| 5188 | * |
| 5189 | * Returns 0 on success, negative on failure |
| 5190 | **/ |
| 5191 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 5192 | { |
| 5193 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5194 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5195 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5196 | /* Jumbo frame support */ |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 5197 | if (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) { |
| 5198 | if (!(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
| 5199 | e_err("Jumbo Frames not supported.\n"); |
| 5200 | return -EINVAL; |
| 5201 | } |
| 5202 | |
| 5203 | /* |
| 5204 | * IP payload checksum (enabled with jumbos/packet-split when |
| 5205 | * Rx checksum is enabled) and generation of RSS hash is |
| 5206 | * mutually exclusive in the hardware. |
| 5207 | */ |
| 5208 | if ((netdev->features & NETIF_F_RXCSUM) && |
| 5209 | (netdev->features & NETIF_F_RXHASH)) { |
| 5210 | 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"); |
| 5211 | return -EINVAL; |
| 5212 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5213 | } |
| 5214 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5215 | /* Supported frame sizes */ |
| 5216 | if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) || |
| 5217 | (max_frame > adapter->max_hw_frame_size)) { |
| 5218 | e_err("Unsupported MTU setting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5219 | return -EINVAL; |
| 5220 | } |
| 5221 | |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 5222 | /* Jumbo frame workaround on 82579 requires CRC be stripped */ |
| 5223 | if ((adapter->hw.mac.type == e1000_pch2lan) && |
| 5224 | !(adapter->flags2 & FLAG2_CRC_STRIPPING) && |
| 5225 | (new_mtu > ETH_DATA_LEN)) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 5226 | 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] | 5227 | return -EINVAL; |
| 5228 | } |
| 5229 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5230 | /* 82573 Errata 17 */ |
| 5231 | if (((adapter->hw.mac.type == e1000_82573) || |
| 5232 | (adapter->hw.mac.type == e1000_82574)) && |
| 5233 | (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) { |
| 5234 | adapter->flags2 |= FLAG2_DISABLE_ASPM_L1; |
| 5235 | e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1); |
| 5236 | } |
| 5237 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5238 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 5239 | usleep_range(1000, 2000); |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5240 | /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5241 | adapter->max_frame_size = max_frame; |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5242 | e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
| 5243 | netdev->mtu = new_mtu; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5244 | if (netif_running(netdev)) |
| 5245 | e1000e_down(adapter); |
| 5246 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5247 | /* |
| 5248 | * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5249 | * means we reserve 2 more, this pushes us to allocate from the next |
| 5250 | * larger slab size. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5251 | * i.e. RXBUFFER_2048 --> size-4096 slab |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5252 | * However with the new *_jumbo_rx* routines, jumbo receives will use |
| 5253 | * fragmented skbs |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5254 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5255 | |
Jesse Brandeburg | 9926146 | 2010-01-22 22:56:16 +0000 | [diff] [blame] | 5256 | if (max_frame <= 2048) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5257 | adapter->rx_buffer_len = 2048; |
| 5258 | else |
| 5259 | adapter->rx_buffer_len = 4096; |
| 5260 | |
| 5261 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
| 5262 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || |
| 5263 | (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) |
| 5264 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5265 | + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5266 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5267 | if (netif_running(netdev)) |
| 5268 | e1000e_up(adapter); |
| 5269 | else |
| 5270 | e1000e_reset(adapter); |
| 5271 | |
| 5272 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 5273 | |
| 5274 | return 0; |
| 5275 | } |
| 5276 | |
| 5277 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 5278 | int cmd) |
| 5279 | { |
| 5280 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5281 | struct mii_ioctl_data *data = if_mii(ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5282 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5283 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5284 | return -EOPNOTSUPP; |
| 5285 | |
| 5286 | switch (cmd) { |
| 5287 | case SIOCGMIIPHY: |
| 5288 | data->phy_id = adapter->hw.phy.addr; |
| 5289 | break; |
| 5290 | case SIOCGMIIREG: |
Bruce Allan | b16a002 | 2009-11-20 23:24:30 +0000 | [diff] [blame] | 5291 | e1000_phy_read_status(adapter); |
| 5292 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5293 | switch (data->reg_num & 0x1F) { |
| 5294 | case MII_BMCR: |
| 5295 | data->val_out = adapter->phy_regs.bmcr; |
| 5296 | break; |
| 5297 | case MII_BMSR: |
| 5298 | data->val_out = adapter->phy_regs.bmsr; |
| 5299 | break; |
| 5300 | case MII_PHYSID1: |
| 5301 | data->val_out = (adapter->hw.phy.id >> 16); |
| 5302 | break; |
| 5303 | case MII_PHYSID2: |
| 5304 | data->val_out = (adapter->hw.phy.id & 0xFFFF); |
| 5305 | break; |
| 5306 | case MII_ADVERTISE: |
| 5307 | data->val_out = adapter->phy_regs.advertise; |
| 5308 | break; |
| 5309 | case MII_LPA: |
| 5310 | data->val_out = adapter->phy_regs.lpa; |
| 5311 | break; |
| 5312 | case MII_EXPANSION: |
| 5313 | data->val_out = adapter->phy_regs.expansion; |
| 5314 | break; |
| 5315 | case MII_CTRL1000: |
| 5316 | data->val_out = adapter->phy_regs.ctrl1000; |
| 5317 | break; |
| 5318 | case MII_STAT1000: |
| 5319 | data->val_out = adapter->phy_regs.stat1000; |
| 5320 | break; |
| 5321 | case MII_ESTATUS: |
| 5322 | data->val_out = adapter->phy_regs.estatus; |
| 5323 | break; |
| 5324 | default: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5325 | return -EIO; |
| 5326 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5327 | break; |
| 5328 | case SIOCSMIIREG: |
| 5329 | default: |
| 5330 | return -EOPNOTSUPP; |
| 5331 | } |
| 5332 | return 0; |
| 5333 | } |
| 5334 | |
| 5335 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 5336 | { |
| 5337 | switch (cmd) { |
| 5338 | case SIOCGMIIPHY: |
| 5339 | case SIOCGMIIREG: |
| 5340 | case SIOCSMIIREG: |
| 5341 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 5342 | default: |
| 5343 | return -EOPNOTSUPP; |
| 5344 | } |
| 5345 | } |
| 5346 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5347 | static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) |
| 5348 | { |
| 5349 | struct e1000_hw *hw = &adapter->hw; |
| 5350 | u32 i, mac_reg; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5351 | u16 phy_reg, wuc_enable; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5352 | int retval = 0; |
| 5353 | |
| 5354 | /* copy MAC RARs to PHY RARs */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 5355 | e1000_copy_rx_addrs_to_phy_ich8lan(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5356 | |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5357 | retval = hw->phy.ops.acquire(hw); |
| 5358 | if (retval) { |
| 5359 | e_err("Could not acquire PHY\n"); |
| 5360 | return retval; |
| 5361 | } |
| 5362 | |
| 5363 | /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */ |
| 5364 | retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
| 5365 | if (retval) |
Bruce Allan | 75ce153 | 2012-02-08 02:54:48 +0000 | [diff] [blame] | 5366 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5367 | |
| 5368 | /* copy MAC MTA to PHY MTA - only needed for pchlan */ |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5369 | for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { |
| 5370 | mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5371 | hw->phy.ops.write_reg_page(hw, BM_MTA(i), |
| 5372 | (u16)(mac_reg & 0xFFFF)); |
| 5373 | hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1, |
| 5374 | (u16)((mac_reg >> 16) & 0xFFFF)); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5375 | } |
| 5376 | |
| 5377 | /* configure PHY Rx Control register */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5378 | hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5379 | mac_reg = er32(RCTL); |
| 5380 | if (mac_reg & E1000_RCTL_UPE) |
| 5381 | phy_reg |= BM_RCTL_UPE; |
| 5382 | if (mac_reg & E1000_RCTL_MPE) |
| 5383 | phy_reg |= BM_RCTL_MPE; |
| 5384 | phy_reg &= ~(BM_RCTL_MO_MASK); |
| 5385 | if (mac_reg & E1000_RCTL_MO_3) |
| 5386 | phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) |
| 5387 | << BM_RCTL_MO_SHIFT); |
| 5388 | if (mac_reg & E1000_RCTL_BAM) |
| 5389 | phy_reg |= BM_RCTL_BAM; |
| 5390 | if (mac_reg & E1000_RCTL_PMCF) |
| 5391 | phy_reg |= BM_RCTL_PMCF; |
| 5392 | mac_reg = er32(CTRL); |
| 5393 | if (mac_reg & E1000_CTRL_RFCE) |
| 5394 | phy_reg |= BM_RCTL_RFCE; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5395 | hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5396 | |
| 5397 | /* enable PHY wakeup in MAC register */ |
| 5398 | ew32(WUFC, wufc); |
| 5399 | ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN); |
| 5400 | |
| 5401 | /* configure and enable PHY wakeup in PHY registers */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5402 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc); |
| 5403 | 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] | 5404 | |
| 5405 | /* activate PHY wakeup */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5406 | wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; |
| 5407 | retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5408 | if (retval) |
| 5409 | e_err("Could not set PHY Host Wakeup bit\n"); |
Bruce Allan | 75ce153 | 2012-02-08 02:54:48 +0000 | [diff] [blame] | 5410 | release: |
Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 5411 | hw->phy.ops.release(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5412 | |
| 5413 | return retval; |
| 5414 | } |
| 5415 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5416 | static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake, |
| 5417 | bool runtime) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5418 | { |
| 5419 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5420 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5421 | struct e1000_hw *hw = &adapter->hw; |
| 5422 | u32 ctrl, ctrl_ext, rctl, status; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5423 | /* Runtime suspend should only enable wakeup for link changes */ |
| 5424 | u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5425 | int retval = 0; |
| 5426 | |
| 5427 | netif_device_detach(netdev); |
| 5428 | |
| 5429 | if (netif_running(netdev)) { |
| 5430 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 5431 | e1000e_down(adapter); |
| 5432 | e1000_free_irq(adapter); |
| 5433 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5434 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5435 | |
| 5436 | retval = pci_save_state(pdev); |
| 5437 | if (retval) |
| 5438 | return retval; |
| 5439 | |
| 5440 | status = er32(STATUS); |
| 5441 | if (status & E1000_STATUS_LU) |
| 5442 | wufc &= ~E1000_WUFC_LNKC; |
| 5443 | |
| 5444 | if (wufc) { |
| 5445 | e1000_setup_rctl(adapter); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 5446 | e1000e_set_rx_mode(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5447 | |
| 5448 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5449 | if (wufc & E1000_WUFC_MC) { |
| 5450 | rctl = er32(RCTL); |
| 5451 | rctl |= E1000_RCTL_MPE; |
| 5452 | ew32(RCTL, rctl); |
| 5453 | } |
| 5454 | |
| 5455 | ctrl = er32(CTRL); |
| 5456 | /* advertise wake from D3Cold */ |
| 5457 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5458 | /* phy power management enable */ |
| 5459 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5460 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 5461 | if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) |
| 5462 | ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5463 | ew32(CTRL, ctrl); |
| 5464 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5465 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
| 5466 | adapter->hw.phy.media_type == |
| 5467 | e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5468 | /* keep the laser running in D3 */ |
| 5469 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | 93a23f4 | 2009-12-08 07:27:41 +0000 | [diff] [blame] | 5470 | ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5471 | ew32(CTRL_EXT, ctrl_ext); |
| 5472 | } |
| 5473 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5474 | if (adapter->flags & FLAG_IS_ICH) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5475 | e1000_suspend_workarounds_ich8lan(&adapter->hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5476 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5477 | /* Allow time for pending master requests to run */ |
| 5478 | e1000e_disable_pcie_master(&adapter->hw); |
| 5479 | |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5480 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5481 | /* enable wakeup by the PHY */ |
| 5482 | retval = e1000_init_phy_wakeup(adapter, wufc); |
| 5483 | if (retval) |
| 5484 | return retval; |
| 5485 | } else { |
| 5486 | /* enable wakeup by the MAC */ |
| 5487 | ew32(WUFC, wufc); |
| 5488 | ew32(WUC, E1000_WUC_PME_EN); |
| 5489 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5490 | } else { |
| 5491 | ew32(WUC, 0); |
| 5492 | ew32(WUFC, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5493 | } |
| 5494 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5495 | *enable_wake = !!wufc; |
| 5496 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5497 | /* make sure adapter isn't asleep if manageability is enabled */ |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5498 | if ((adapter->flags & FLAG_MNG_PT_ENABLED) || |
| 5499 | (hw->mac.ops.check_mng_mode(hw))) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5500 | *enable_wake = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5501 | |
| 5502 | if (adapter->hw.phy.type == e1000_phy_igp_3) |
| 5503 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
| 5504 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5505 | /* |
| 5506 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5507 | * would have already happened in close and is redundant. |
| 5508 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5509 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5510 | |
| 5511 | pci_disable_device(pdev); |
| 5512 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5513 | return 0; |
| 5514 | } |
| 5515 | |
| 5516 | static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake) |
| 5517 | { |
| 5518 | if (sleep && wake) { |
| 5519 | pci_prepare_to_sleep(pdev); |
| 5520 | return; |
| 5521 | } |
| 5522 | |
| 5523 | pci_wake_from_d3(pdev, wake); |
| 5524 | pci_set_power_state(pdev, PCI_D3hot); |
| 5525 | } |
| 5526 | |
| 5527 | static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, |
| 5528 | bool wake) |
| 5529 | { |
| 5530 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5531 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5532 | |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5533 | /* |
| 5534 | * The pci-e switch on some quad port adapters will report a |
| 5535 | * correctable error when the MAC transitions from D0 to D3. To |
| 5536 | * prevent this we need to mask off the correctable errors on the |
| 5537 | * downstream port of the pci-e switch. |
| 5538 | */ |
| 5539 | if (adapter->flags & FLAG_IS_QUAD_PORT) { |
| 5540 | struct pci_dev *us_dev = pdev->bus->self; |
Jon Mason | 353064d | 2011-06-27 07:43:47 +0000 | [diff] [blame] | 5541 | int pos = pci_pcie_cap(us_dev); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5542 | u16 devctl; |
| 5543 | |
| 5544 | pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl); |
| 5545 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, |
| 5546 | (devctl & ~PCI_EXP_DEVCTL_CERE)); |
| 5547 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5548 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5549 | |
| 5550 | pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl); |
| 5551 | } else { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5552 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 5553 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5554 | } |
| 5555 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5556 | #ifdef CONFIG_PCIEASPM |
| 5557 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
| 5558 | { |
Yinghai Lu | 9f728f5 | 2011-05-12 17:11:47 -0700 | [diff] [blame] | 5559 | pci_disable_link_state_locked(pdev, state); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5560 | } |
| 5561 | #else |
| 5562 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5563 | { |
| 5564 | int pos; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5565 | u16 reg16; |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5566 | |
| 5567 | /* |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5568 | * Both device and parent should have the same ASPM setting. |
| 5569 | * Disable ASPM in downstream component first and then upstream. |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5570 | */ |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5571 | pos = pci_pcie_cap(pdev); |
| 5572 | pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16); |
| 5573 | reg16 &= ~state; |
| 5574 | pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16); |
| 5575 | |
Anton Blanchard | 0c75ba2 | 2010-04-28 21:46:06 +0000 | [diff] [blame] | 5576 | if (!pdev->bus->self) |
| 5577 | return; |
| 5578 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5579 | pos = pci_pcie_cap(pdev->bus->self); |
| 5580 | pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, ®16); |
| 5581 | reg16 &= ~state; |
| 5582 | pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16); |
| 5583 | } |
| 5584 | #endif |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5585 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5586 | { |
| 5587 | dev_info(&pdev->dev, "Disabling ASPM %s %s\n", |
| 5588 | (state & PCIE_LINK_STATE_L0S) ? "L0s" : "", |
| 5589 | (state & PCIE_LINK_STATE_L1) ? "L1" : ""); |
| 5590 | |
| 5591 | __e1000e_disable_aspm(pdev, state); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 5592 | } |
| 5593 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 5594 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5595 | static bool e1000e_pm_ready(struct e1000_adapter *adapter) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5596 | { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5597 | return !!adapter->tx_ring->buffer_info; |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5598 | } |
| 5599 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5600 | static int __e1000_resume(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5601 | { |
| 5602 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5603 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5604 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5605 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5606 | u32 err; |
| 5607 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5608 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5609 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
| 5610 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
| 5611 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5612 | if (aspm_disable_flag) |
| 5613 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 5614 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5615 | pci_set_power_state(pdev, PCI_D0); |
| 5616 | pci_restore_state(pdev); |
Bruce Allan | 28b8f04 | 2010-01-07 16:30:56 +0000 | [diff] [blame] | 5617 | pci_save_state(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5618 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5619 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5620 | if (netif_running(netdev)) { |
| 5621 | err = e1000_request_irq(adapter); |
| 5622 | if (err) |
| 5623 | return err; |
| 5624 | } |
| 5625 | |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5626 | if (hw->mac.type == e1000_pch2lan) |
| 5627 | e1000_resume_workarounds_pchlan(&adapter->hw); |
| 5628 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5629 | e1000e_power_up_phy(adapter); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5630 | |
| 5631 | /* report the system wakeup cause from S3/S4 */ |
| 5632 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
| 5633 | u16 phy_data; |
| 5634 | |
| 5635 | e1e_rphy(&adapter->hw, BM_WUS, &phy_data); |
| 5636 | if (phy_data) { |
| 5637 | e_info("PHY Wakeup cause - %s\n", |
| 5638 | phy_data & E1000_WUS_EX ? "Unicast Packet" : |
| 5639 | phy_data & E1000_WUS_MC ? "Multicast Packet" : |
| 5640 | phy_data & E1000_WUS_BC ? "Broadcast Packet" : |
| 5641 | phy_data & E1000_WUS_MAG ? "Magic Packet" : |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 5642 | phy_data & E1000_WUS_LNKC ? |
| 5643 | "Link Status Change" : "other"); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5644 | } |
| 5645 | e1e_wphy(&adapter->hw, BM_WUS, ~0); |
| 5646 | } else { |
| 5647 | u32 wus = er32(WUS); |
| 5648 | if (wus) { |
| 5649 | e_info("MAC Wakeup cause - %s\n", |
| 5650 | wus & E1000_WUS_EX ? "Unicast Packet" : |
| 5651 | wus & E1000_WUS_MC ? "Multicast Packet" : |
| 5652 | wus & E1000_WUS_BC ? "Broadcast Packet" : |
| 5653 | wus & E1000_WUS_MAG ? "Magic Packet" : |
| 5654 | wus & E1000_WUS_LNKC ? "Link Status Change" : |
| 5655 | "other"); |
| 5656 | } |
| 5657 | ew32(WUS, ~0); |
| 5658 | } |
| 5659 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5660 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5661 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 5662 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5663 | |
| 5664 | if (netif_running(netdev)) |
| 5665 | e1000e_up(adapter); |
| 5666 | |
| 5667 | netif_device_attach(netdev); |
| 5668 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5669 | /* |
| 5670 | * 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] | 5671 | * 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] | 5672 | * under the control of the driver. |
| 5673 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5674 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5675 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5676 | |
| 5677 | return 0; |
| 5678 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5679 | |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5680 | #ifdef CONFIG_PM_SLEEP |
| 5681 | static int e1000_suspend(struct device *dev) |
| 5682 | { |
| 5683 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5684 | int retval; |
| 5685 | bool wake; |
| 5686 | |
| 5687 | retval = __e1000_shutdown(pdev, &wake, false); |
| 5688 | if (!retval) |
| 5689 | e1000_complete_shutdown(pdev, true, wake); |
| 5690 | |
| 5691 | return retval; |
| 5692 | } |
| 5693 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5694 | static int e1000_resume(struct device *dev) |
| 5695 | { |
| 5696 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5697 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5698 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5699 | |
| 5700 | if (e1000e_pm_ready(adapter)) |
| 5701 | adapter->idle_check = true; |
| 5702 | |
| 5703 | return __e1000_resume(pdev); |
| 5704 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5705 | #endif /* CONFIG_PM_SLEEP */ |
| 5706 | |
| 5707 | #ifdef CONFIG_PM_RUNTIME |
| 5708 | static int e1000_runtime_suspend(struct device *dev) |
| 5709 | { |
| 5710 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5711 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5712 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5713 | |
| 5714 | if (e1000e_pm_ready(adapter)) { |
| 5715 | bool wake; |
| 5716 | |
| 5717 | __e1000_shutdown(pdev, &wake, true); |
| 5718 | } |
| 5719 | |
| 5720 | return 0; |
| 5721 | } |
| 5722 | |
| 5723 | static int e1000_idle(struct device *dev) |
| 5724 | { |
| 5725 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5726 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5727 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5728 | |
| 5729 | if (!e1000e_pm_ready(adapter)) |
| 5730 | return 0; |
| 5731 | |
| 5732 | if (adapter->idle_check) { |
| 5733 | adapter->idle_check = false; |
| 5734 | if (!e1000e_has_link(adapter)) |
| 5735 | pm_schedule_suspend(dev, MSEC_PER_SEC); |
| 5736 | } |
| 5737 | |
| 5738 | return -EBUSY; |
| 5739 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5740 | |
| 5741 | static int e1000_runtime_resume(struct device *dev) |
| 5742 | { |
| 5743 | struct pci_dev *pdev = to_pci_dev(dev); |
| 5744 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5745 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5746 | |
| 5747 | if (!e1000e_pm_ready(adapter)) |
| 5748 | return 0; |
| 5749 | |
| 5750 | adapter->idle_check = !dev->power.runtime_auto; |
| 5751 | return __e1000_resume(pdev); |
| 5752 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 5753 | #endif /* CONFIG_PM_RUNTIME */ |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 5754 | #endif /* CONFIG_PM */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5755 | |
| 5756 | static void e1000_shutdown(struct pci_dev *pdev) |
| 5757 | { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5758 | bool wake = false; |
| 5759 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5760 | __e1000_shutdown(pdev, &wake, false); |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5761 | |
| 5762 | if (system_state == SYSTEM_POWER_OFF) |
| 5763 | e1000_complete_shutdown(pdev, false, wake); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5764 | } |
| 5765 | |
| 5766 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5767 | |
| 5768 | static irqreturn_t e1000_intr_msix(int irq, void *data) |
| 5769 | { |
| 5770 | struct net_device *netdev = data; |
| 5771 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5772 | |
| 5773 | if (adapter->msix_entries) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 5774 | int vector, msix_irq; |
| 5775 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5776 | vector = 0; |
| 5777 | msix_irq = adapter->msix_entries[vector].vector; |
| 5778 | disable_irq(msix_irq); |
| 5779 | e1000_intr_msix_rx(msix_irq, netdev); |
| 5780 | enable_irq(msix_irq); |
| 5781 | |
| 5782 | vector++; |
| 5783 | msix_irq = adapter->msix_entries[vector].vector; |
| 5784 | disable_irq(msix_irq); |
| 5785 | e1000_intr_msix_tx(msix_irq, netdev); |
| 5786 | enable_irq(msix_irq); |
| 5787 | |
| 5788 | vector++; |
| 5789 | msix_irq = adapter->msix_entries[vector].vector; |
| 5790 | disable_irq(msix_irq); |
| 5791 | e1000_msix_other(msix_irq, netdev); |
| 5792 | enable_irq(msix_irq); |
| 5793 | } |
| 5794 | |
| 5795 | return IRQ_HANDLED; |
| 5796 | } |
| 5797 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5798 | /* |
| 5799 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5800 | * without having to re-enable interrupts. It's not called while |
| 5801 | * the interrupt routine is executing. |
| 5802 | */ |
| 5803 | static void e1000_netpoll(struct net_device *netdev) |
| 5804 | { |
| 5805 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5806 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 5807 | switch (adapter->int_mode) { |
| 5808 | case E1000E_INT_MODE_MSIX: |
| 5809 | e1000_intr_msix(adapter->pdev->irq, netdev); |
| 5810 | break; |
| 5811 | case E1000E_INT_MODE_MSI: |
| 5812 | disable_irq(adapter->pdev->irq); |
| 5813 | e1000_intr_msi(adapter->pdev->irq, netdev); |
| 5814 | enable_irq(adapter->pdev->irq); |
| 5815 | break; |
| 5816 | default: /* E1000E_INT_MODE_LEGACY */ |
| 5817 | disable_irq(adapter->pdev->irq); |
| 5818 | e1000_intr(adapter->pdev->irq, netdev); |
| 5819 | enable_irq(adapter->pdev->irq); |
| 5820 | break; |
| 5821 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5822 | } |
| 5823 | #endif |
| 5824 | |
| 5825 | /** |
| 5826 | * e1000_io_error_detected - called when PCI error is detected |
| 5827 | * @pdev: Pointer to PCI device |
| 5828 | * @state: The current pci connection state |
| 5829 | * |
| 5830 | * This function is called after a PCI bus error affecting |
| 5831 | * this device has been detected. |
| 5832 | */ |
| 5833 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 5834 | pci_channel_state_t state) |
| 5835 | { |
| 5836 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5837 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5838 | |
| 5839 | netif_device_detach(netdev); |
| 5840 | |
Mike Mason | c93b5a7 | 2009-06-30 12:45:53 +0000 | [diff] [blame] | 5841 | if (state == pci_channel_io_perm_failure) |
| 5842 | return PCI_ERS_RESULT_DISCONNECT; |
| 5843 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5844 | if (netif_running(netdev)) |
| 5845 | e1000e_down(adapter); |
| 5846 | pci_disable_device(pdev); |
| 5847 | |
| 5848 | /* Request a slot slot reset. */ |
| 5849 | return PCI_ERS_RESULT_NEED_RESET; |
| 5850 | } |
| 5851 | |
| 5852 | /** |
| 5853 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 5854 | * @pdev: Pointer to PCI device |
| 5855 | * |
| 5856 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5857 | * resembles the first-half of the e1000_resume routine. |
| 5858 | */ |
| 5859 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 5860 | { |
| 5861 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5862 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5863 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5864 | u16 aspm_disable_flag = 0; |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5865 | int err; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5866 | pci_ers_result_t result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5867 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5868 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 5869 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 5870 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 5871 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 5872 | if (aspm_disable_flag) |
| 5873 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 5874 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 5875 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 5876 | if (err) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5877 | dev_err(&pdev->dev, |
| 5878 | "Cannot re-enable PCI device after reset.\n"); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5879 | result = PCI_ERS_RESULT_DISCONNECT; |
| 5880 | } else { |
| 5881 | pci_set_master(pdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5882 | pdev->state_saved = true; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5883 | pci_restore_state(pdev); |
| 5884 | |
| 5885 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5886 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 5887 | |
| 5888 | e1000e_reset(adapter); |
| 5889 | ew32(WUS, ~0); |
| 5890 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5891 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5892 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5893 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5894 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 5895 | return result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5896 | } |
| 5897 | |
| 5898 | /** |
| 5899 | * e1000_io_resume - called when traffic can start flowing again. |
| 5900 | * @pdev: Pointer to PCI device |
| 5901 | * |
| 5902 | * This callback is called when the error recovery driver tells us that |
| 5903 | * its OK to resume normal operation. Implementation resembles the |
| 5904 | * second-half of the e1000_resume routine. |
| 5905 | */ |
| 5906 | static void e1000_io_resume(struct pci_dev *pdev) |
| 5907 | { |
| 5908 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5909 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5910 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 5911 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5912 | |
| 5913 | if (netif_running(netdev)) { |
| 5914 | if (e1000e_up(adapter)) { |
| 5915 | dev_err(&pdev->dev, |
| 5916 | "can't bring device back up after reset\n"); |
| 5917 | return; |
| 5918 | } |
| 5919 | } |
| 5920 | |
| 5921 | netif_device_attach(netdev); |
| 5922 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5923 | /* |
| 5924 | * 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] | 5925 | * 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] | 5926 | * under the control of the driver. |
| 5927 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 5928 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5929 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5930 | |
| 5931 | } |
| 5932 | |
| 5933 | static void e1000_print_device_info(struct e1000_adapter *adapter) |
| 5934 | { |
| 5935 | struct e1000_hw *hw = &adapter->hw; |
| 5936 | struct net_device *netdev = adapter->netdev; |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5937 | u32 ret_val; |
| 5938 | u8 pba_str[E1000_PBANUM_LENGTH]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5939 | |
| 5940 | /* print bus type/speed/width info */ |
Bruce Allan | a5cc764 | 2011-03-19 00:31:23 +0000 | [diff] [blame] | 5941 | e_info("(PCI Express:2.5GT/s:%s) %pM\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5942 | /* bus width */ |
| 5943 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
| 5944 | "Width x1"), |
| 5945 | /* MAC address */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5946 | netdev->dev_addr); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5947 | e_info("Intel(R) PRO/%s Network Connection\n", |
| 5948 | (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5949 | ret_val = e1000_read_pba_string_generic(hw, pba_str, |
| 5950 | E1000_PBANUM_LENGTH); |
| 5951 | if (ret_val) |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 5952 | strlcpy((char *)pba_str, "Unknown", sizeof(pba_str)); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 5953 | e_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 5954 | hw->mac.type, hw->phy.type, pba_str); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5955 | } |
| 5956 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5957 | static void e1000_eeprom_checks(struct e1000_adapter *adapter) |
| 5958 | { |
| 5959 | struct e1000_hw *hw = &adapter->hw; |
| 5960 | int ret_val; |
| 5961 | u16 buf = 0; |
| 5962 | |
| 5963 | if (hw->mac.type != e1000_82573) |
| 5964 | return; |
| 5965 | |
| 5966 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 5967 | le16_to_cpus(&buf); |
| 5968 | if (!ret_val && (!(buf & (1 << 0)))) { |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5969 | /* Deep Smart Power Down (DSPD) */ |
Frans Pop | 6c2a9ef | 2008-09-22 14:52:22 -0700 | [diff] [blame] | 5970 | dev_warn(&adapter->pdev->dev, |
| 5971 | "Warning: detected DSPD enabled in EEPROM\n"); |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5972 | } |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 5973 | } |
| 5974 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 5975 | static int e1000_set_features(struct net_device *netdev, |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 5976 | netdev_features_t features) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 5977 | { |
| 5978 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 5979 | netdev_features_t changed = features ^ netdev->features; |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 5980 | |
| 5981 | if (changed & (NETIF_F_TSO | NETIF_F_TSO6)) |
| 5982 | adapter->flags |= FLAG_TSO_FORCE; |
| 5983 | |
| 5984 | if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 5985 | NETIF_F_RXCSUM | NETIF_F_RXHASH))) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 5986 | return 0; |
| 5987 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 5988 | /* |
| 5989 | * IP payload checksum (enabled with jumbos/packet-split when Rx |
| 5990 | * checksum is enabled) and generation of RSS hash is mutually |
| 5991 | * exclusive in the hardware. |
| 5992 | */ |
| 5993 | if (adapter->rx_ps_pages && |
| 5994 | (features & NETIF_F_RXCSUM) && (features & NETIF_F_RXHASH)) { |
| 5995 | 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"); |
| 5996 | return -EINVAL; |
| 5997 | } |
| 5998 | |
| 5999 | netdev->features = features; |
| 6000 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6001 | if (netif_running(netdev)) |
| 6002 | e1000e_reinit_locked(adapter); |
| 6003 | else |
| 6004 | e1000e_reset(adapter); |
| 6005 | |
| 6006 | return 0; |
| 6007 | } |
| 6008 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6009 | static const struct net_device_ops e1000e_netdev_ops = { |
| 6010 | .ndo_open = e1000_open, |
| 6011 | .ndo_stop = e1000_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 6012 | .ndo_start_xmit = e1000_xmit_frame, |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6013 | .ndo_get_stats64 = e1000e_get_stats64, |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 6014 | .ndo_set_rx_mode = e1000e_set_rx_mode, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6015 | .ndo_set_mac_address = e1000_set_mac, |
| 6016 | .ndo_change_mtu = e1000_change_mtu, |
| 6017 | .ndo_do_ioctl = e1000_ioctl, |
| 6018 | .ndo_tx_timeout = e1000_tx_timeout, |
| 6019 | .ndo_validate_addr = eth_validate_addr, |
| 6020 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6021 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 6022 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 6023 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6024 | .ndo_poll_controller = e1000_netpoll, |
| 6025 | #endif |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6026 | .ndo_set_features = e1000_set_features, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6027 | }; |
| 6028 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6029 | /** |
| 6030 | * e1000_probe - Device Initialization Routine |
| 6031 | * @pdev: PCI device information struct |
| 6032 | * @ent: entry in e1000_pci_tbl |
| 6033 | * |
| 6034 | * Returns 0 on success, negative on failure |
| 6035 | * |
| 6036 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 6037 | * The OS initialization, configuring of the adapter private structure, |
| 6038 | * and a hardware reset occur. |
| 6039 | **/ |
| 6040 | static int __devinit e1000_probe(struct pci_dev *pdev, |
| 6041 | const struct pci_device_id *ent) |
| 6042 | { |
| 6043 | struct net_device *netdev; |
| 6044 | struct e1000_adapter *adapter; |
| 6045 | struct e1000_hw *hw; |
| 6046 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; |
Becky Bruce | f47e81f | 2008-05-01 18:03:11 -0500 | [diff] [blame] | 6047 | resource_size_t mmio_start, mmio_len; |
| 6048 | resource_size_t flash_start, flash_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6049 | |
| 6050 | static int cards_found; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6051 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6052 | int i, err, pci_using_dac; |
| 6053 | u16 eeprom_data = 0; |
| 6054 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
| 6055 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6056 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 6057 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6058 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6059 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 6060 | if (aspm_disable_flag) |
| 6061 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6062 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6063 | err = pci_enable_device_mem(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6064 | if (err) |
| 6065 | return err; |
| 6066 | |
| 6067 | pci_using_dac = 0; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6068 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6069 | if (!err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6070 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6071 | if (!err) |
| 6072 | pci_using_dac = 1; |
| 6073 | } else { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6074 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6075 | if (err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6076 | err = dma_set_coherent_mask(&pdev->dev, |
| 6077 | DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6078 | if (err) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 6079 | dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6080 | goto err_dma; |
| 6081 | } |
| 6082 | } |
| 6083 | } |
| 6084 | |
Arjan van de Ven | e8de148 | 2008-10-22 19:55:31 -0700 | [diff] [blame] | 6085 | err = pci_request_selected_regions_exclusive(pdev, |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6086 | pci_select_bars(pdev, IORESOURCE_MEM), |
| 6087 | e1000e_driver_name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6088 | if (err) |
| 6089 | goto err_pci_reg; |
| 6090 | |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 6091 | /* AER (Advanced Error Reporting) hooks */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6092 | pci_enable_pcie_error_reporting(pdev); |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 6093 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6094 | pci_set_master(pdev); |
Bruce Allan | 438b365 | 2008-11-21 16:51:33 -0800 | [diff] [blame] | 6095 | /* PCI config space info */ |
| 6096 | err = pci_save_state(pdev); |
| 6097 | if (err) |
| 6098 | goto err_alloc_etherdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6099 | |
| 6100 | err = -ENOMEM; |
| 6101 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
| 6102 | if (!netdev) |
| 6103 | goto err_alloc_etherdev; |
| 6104 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6105 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 6106 | |
Tom Herbert | f85e4df | 2010-05-05 14:03:32 +0000 | [diff] [blame] | 6107 | netdev->irq = pdev->irq; |
| 6108 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6109 | pci_set_drvdata(pdev, netdev); |
| 6110 | adapter = netdev_priv(netdev); |
| 6111 | hw = &adapter->hw; |
| 6112 | adapter->netdev = netdev; |
| 6113 | adapter->pdev = pdev; |
| 6114 | adapter->ei = ei; |
| 6115 | adapter->pba = ei->pba; |
| 6116 | adapter->flags = ei->flags; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 6117 | adapter->flags2 = ei->flags2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6118 | adapter->hw.adapter = adapter; |
| 6119 | adapter->hw.mac.type = ei->mac; |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 6120 | adapter->max_hw_frame_size = ei->max_hw_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6121 | adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; |
| 6122 | |
| 6123 | mmio_start = pci_resource_start(pdev, 0); |
| 6124 | mmio_len = pci_resource_len(pdev, 0); |
| 6125 | |
| 6126 | err = -EIO; |
| 6127 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 6128 | if (!adapter->hw.hw_addr) |
| 6129 | goto err_ioremap; |
| 6130 | |
| 6131 | if ((adapter->flags & FLAG_HAS_FLASH) && |
| 6132 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
| 6133 | flash_start = pci_resource_start(pdev, 1); |
| 6134 | flash_len = pci_resource_len(pdev, 1); |
| 6135 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
| 6136 | if (!adapter->hw.flash_address) |
| 6137 | goto err_flashmap; |
| 6138 | } |
| 6139 | |
| 6140 | /* construct the net_device struct */ |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6141 | netdev->netdev_ops = &e1000e_netdev_ops; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6142 | e1000e_set_ethtool_ops(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6143 | netdev->watchdog_timeo = 5 * HZ; |
| 6144 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 6145 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6146 | |
| 6147 | netdev->mem_start = mmio_start; |
| 6148 | netdev->mem_end = mmio_start + mmio_len; |
| 6149 | |
| 6150 | adapter->bd_number = cards_found++; |
| 6151 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6152 | e1000e_check_options(adapter); |
| 6153 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6154 | /* setup adapter struct */ |
| 6155 | err = e1000_sw_init(adapter); |
| 6156 | if (err) |
| 6157 | goto err_sw_init; |
| 6158 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6159 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 6160 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 6161 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 6162 | |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 6163 | err = ei->get_variants(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6164 | if (err) |
| 6165 | goto err_hw_init; |
| 6166 | |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 6167 | if ((adapter->flags & FLAG_IS_ICH) && |
| 6168 | (adapter->flags & FLAG_READ_ONLY_NVM)) |
| 6169 | e1000e_write_protect_nvm_ich8lan(&adapter->hw); |
| 6170 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6171 | hw->mac.ops.get_bus_info(&adapter->hw); |
| 6172 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6173 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6174 | |
| 6175 | /* Copper options */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6176 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6177 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
| 6178 | adapter->hw.phy.disable_polarity_correction = 0; |
| 6179 | adapter->hw.phy.ms_type = e1000_ms_hw_default; |
| 6180 | } |
| 6181 | |
| 6182 | if (e1000_check_reset_block(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6183 | e_info("PHY reset is blocked due to SOL/IDER session.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6184 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6185 | /* Set initial default active device features */ |
| 6186 | netdev->features = (NETIF_F_SG | |
| 6187 | NETIF_F_HW_VLAN_RX | |
| 6188 | NETIF_F_HW_VLAN_TX | |
| 6189 | NETIF_F_TSO | |
| 6190 | NETIF_F_TSO6 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 6191 | NETIF_F_RXHASH | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6192 | NETIF_F_RXCSUM | |
| 6193 | NETIF_F_HW_CSUM); |
| 6194 | |
| 6195 | /* Set user-changeable features (subset of all device features) */ |
| 6196 | netdev->hw_features = netdev->features; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6197 | |
| 6198 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
| 6199 | netdev->features |= NETIF_F_HW_VLAN_FILTER; |
| 6200 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6201 | netdev->vlan_features |= (NETIF_F_SG | |
| 6202 | NETIF_F_TSO | |
| 6203 | NETIF_F_TSO6 | |
| 6204 | NETIF_F_HW_CSUM); |
Jeff Kirsher | a5136e2 | 2008-06-05 04:07:28 -0700 | [diff] [blame] | 6205 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 6206 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 6207 | |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 6208 | if (pci_using_dac) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6209 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 6210 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 6211 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6212 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6213 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
| 6214 | adapter->flags |= FLAG_MNG_PT_ENABLED; |
| 6215 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6216 | /* |
| 6217 | * before reading the NVM, reset the controller to |
| 6218 | * put the device in a known good starting state |
| 6219 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6220 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 6221 | |
| 6222 | /* |
| 6223 | * systems with ASPM and others may see the checksum fail on the first |
| 6224 | * attempt. Let's give it a few tries |
| 6225 | */ |
| 6226 | for (i = 0;; i++) { |
| 6227 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) |
| 6228 | break; |
| 6229 | if (i == 2) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6230 | e_err("The NVM Checksum Is Not Valid\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6231 | err = -EIO; |
| 6232 | goto err_eeprom; |
| 6233 | } |
| 6234 | } |
| 6235 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6236 | e1000_eeprom_checks(adapter); |
| 6237 | |
Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 6238 | /* copy the MAC address */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6239 | if (e1000e_read_mac_addr(&adapter->hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6240 | e_err("NVM Read Error while reading MAC address\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6241 | |
| 6242 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 6243 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 6244 | |
| 6245 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 6246 | e_err("Invalid MAC Address: %pM\n", netdev->perm_addr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6247 | err = -EIO; |
| 6248 | goto err_eeprom; |
| 6249 | } |
| 6250 | |
| 6251 | init_timer(&adapter->watchdog_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6252 | adapter->watchdog_timer.function = e1000_watchdog; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6253 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 6254 | |
| 6255 | init_timer(&adapter->phy_info_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6256 | adapter->phy_info_timer.function = e1000_update_phy_info; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6257 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 6258 | |
| 6259 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
| 6260 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 6261 | INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); |
| 6262 | INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6263 | INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6264 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6265 | /* Initialize link parameters. User can change them with ethtool */ |
| 6266 | adapter->hw.mac.autoneg = 1; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6267 | adapter->fc_autoneg = true; |
Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 6268 | adapter->hw.fc.requested_mode = e1000_fc_default; |
| 6269 | adapter->hw.fc.current_mode = e1000_fc_default; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6270 | adapter->hw.phy.autoneg_advertised = 0x2f; |
| 6271 | |
| 6272 | /* ring size defaults */ |
| 6273 | adapter->rx_ring->count = 256; |
| 6274 | adapter->tx_ring->count = 256; |
| 6275 | |
| 6276 | /* |
| 6277 | * Initial Wake on LAN setting - If APM wake is enabled in |
| 6278 | * the EEPROM, enable the ACPI Magic Packet filter |
| 6279 | */ |
| 6280 | if (adapter->flags & FLAG_APME_IN_WUC) { |
| 6281 | /* APME bit in EEPROM is mapped to WUC.APME */ |
| 6282 | eeprom_data = er32(WUC); |
| 6283 | eeprom_apme_mask = E1000_WUC_APME; |
Bruce Allan | 4def99b | 2011-02-02 09:30:36 +0000 | [diff] [blame] | 6284 | if ((hw->mac.type > e1000_ich10lan) && |
| 6285 | (eeprom_data & E1000_WUC_PHY_WAKE)) |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6286 | adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6287 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
| 6288 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && |
| 6289 | (adapter->hw.bus.func == 1)) |
| 6290 | e1000_read_nvm(&adapter->hw, |
| 6291 | NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 6292 | else |
| 6293 | e1000_read_nvm(&adapter->hw, |
| 6294 | NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 6295 | } |
| 6296 | |
| 6297 | /* fetch WoL from EEPROM */ |
| 6298 | if (eeprom_data & eeprom_apme_mask) |
| 6299 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 6300 | |
| 6301 | /* |
| 6302 | * now that we have the eeprom settings, apply the special cases |
| 6303 | * where the eeprom may be wrong or the board simply won't support |
| 6304 | * wake on lan on a particular port |
| 6305 | */ |
| 6306 | if (!(adapter->flags & FLAG_HAS_WOL)) |
| 6307 | adapter->eeprom_wol = 0; |
| 6308 | |
| 6309 | /* initialize the wol settings based on the eeprom settings */ |
| 6310 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | 6ff6802 | 2008-11-12 09:52:32 +0000 | [diff] [blame] | 6311 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6312 | |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 6313 | /* save off EEPROM version number */ |
| 6314 | e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); |
| 6315 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6316 | /* reset the hardware with the new settings */ |
| 6317 | e1000e_reset(adapter); |
| 6318 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6319 | /* |
| 6320 | * 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] | 6321 | * 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] | 6322 | * under the control of the driver. |
| 6323 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6324 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6325 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6326 | |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 6327 | strlcpy(netdev->name, "eth%d", sizeof(netdev->name)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6328 | err = register_netdev(netdev); |
| 6329 | if (err) |
| 6330 | goto err_register; |
| 6331 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 6332 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 6333 | netif_carrier_off(netdev); |
| 6334 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6335 | e1000_print_device_info(adapter); |
| 6336 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6337 | if (pci_dev_run_wake(pdev)) |
| 6338 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6339 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6340 | return 0; |
| 6341 | |
| 6342 | err_register: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6343 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6344 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6345 | err_eeprom: |
| 6346 | if (!e1000_check_reset_block(&adapter->hw)) |
| 6347 | e1000_phy_hw_reset(&adapter->hw); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6348 | err_hw_init: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6349 | kfree(adapter->tx_ring); |
| 6350 | kfree(adapter->rx_ring); |
| 6351 | err_sw_init: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6352 | if (adapter->hw.flash_address) |
| 6353 | iounmap(adapter->hw.flash_address); |
Jeff Kirsher | e82f54b | 2008-11-14 06:45:07 +0000 | [diff] [blame] | 6354 | e1000e_reset_interrupt_capability(adapter); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6355 | err_flashmap: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6356 | iounmap(adapter->hw.hw_addr); |
| 6357 | err_ioremap: |
| 6358 | free_netdev(netdev); |
| 6359 | err_alloc_etherdev: |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6360 | pci_release_selected_regions(pdev, |
| 6361 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6362 | err_pci_reg: |
| 6363 | err_dma: |
| 6364 | pci_disable_device(pdev); |
| 6365 | return err; |
| 6366 | } |
| 6367 | |
| 6368 | /** |
| 6369 | * e1000_remove - Device Removal Routine |
| 6370 | * @pdev: PCI device information struct |
| 6371 | * |
| 6372 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 6373 | * that it should release a PCI device. The could be caused by a |
| 6374 | * Hot-Plug event, or because the driver is going to be removed from |
| 6375 | * memory. |
| 6376 | **/ |
| 6377 | static void __devexit e1000_remove(struct pci_dev *pdev) |
| 6378 | { |
| 6379 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6380 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6381 | bool down = test_bit(__E1000_DOWN, &adapter->state); |
| 6382 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6383 | /* |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 6384 | * The timers may be rescheduled, so explicitly disable them |
| 6385 | * from being rescheduled. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6386 | */ |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6387 | if (!down) |
| 6388 | set_bit(__E1000_DOWN, &adapter->state); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6389 | del_timer_sync(&adapter->watchdog_timer); |
| 6390 | del_timer_sync(&adapter->phy_info_timer); |
| 6391 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6392 | cancel_work_sync(&adapter->reset_task); |
| 6393 | cancel_work_sync(&adapter->watchdog_task); |
| 6394 | cancel_work_sync(&adapter->downshift_task); |
| 6395 | cancel_work_sync(&adapter->update_phy_task); |
| 6396 | cancel_work_sync(&adapter->print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6397 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6398 | if (!(netdev->flags & IFF_UP)) |
| 6399 | e1000_power_down_phy(adapter); |
| 6400 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6401 | /* Don't lie to e1000_close() down the road. */ |
| 6402 | if (!down) |
| 6403 | clear_bit(__E1000_DOWN, &adapter->state); |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6404 | unregister_netdev(netdev); |
| 6405 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6406 | if (pci_dev_run_wake(pdev)) |
| 6407 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6408 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6409 | /* |
| 6410 | * Release control of h/w to f/w. If f/w is AMT enabled, this |
| 6411 | * would have already happened in close and is redundant. |
| 6412 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6413 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6414 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6415 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6416 | kfree(adapter->tx_ring); |
| 6417 | kfree(adapter->rx_ring); |
| 6418 | |
| 6419 | iounmap(adapter->hw.hw_addr); |
| 6420 | if (adapter->hw.flash_address) |
| 6421 | iounmap(adapter->hw.flash_address); |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6422 | pci_release_selected_regions(pdev, |
| 6423 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6424 | |
| 6425 | free_netdev(netdev); |
| 6426 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6427 | /* AER disable */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6428 | pci_disable_pcie_error_reporting(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6429 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6430 | pci_disable_device(pdev); |
| 6431 | } |
| 6432 | |
| 6433 | /* PCI Error Recovery (ERS) */ |
| 6434 | static struct pci_error_handlers e1000_err_handler = { |
| 6435 | .error_detected = e1000_io_error_detected, |
| 6436 | .slot_reset = e1000_io_slot_reset, |
| 6437 | .resume = e1000_io_resume, |
| 6438 | }; |
| 6439 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 6440 | static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6441 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
| 6442 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, |
| 6443 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, |
| 6444 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 }, |
| 6445 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
| 6446 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, |
Auke Kok | 040babf | 2007-10-31 15:22:05 -0700 | [diff] [blame] | 6447 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
| 6448 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, |
| 6449 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6450 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6451 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
| 6452 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, |
| 6453 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, |
| 6454 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6455 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6456 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
| 6457 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, |
| 6458 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6459 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6460 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, |
Bruce Allan | bef28b1 | 2009-03-24 23:28:02 -0700 | [diff] [blame] | 6461 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 6462 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6463 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6464 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
| 6465 | board_80003es2lan }, |
| 6466 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), |
| 6467 | board_80003es2lan }, |
| 6468 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), |
| 6469 | board_80003es2lan }, |
| 6470 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), |
| 6471 | board_80003es2lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6472 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6473 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
| 6474 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, |
| 6475 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, |
| 6476 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, |
| 6477 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, |
| 6478 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, |
| 6479 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, |
Bruce Allan | 9e135a2 | 2009-12-01 15:50:31 +0000 | [diff] [blame] | 6480 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6481 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6482 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
| 6483 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, |
| 6484 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, |
| 6485 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, |
| 6486 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, |
Bruce Allan | 2f15f9d | 2008-08-26 18:36:36 -0700 | [diff] [blame] | 6487 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6488 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, |
| 6489 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, |
| 6490 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, |
| 6491 | |
| 6492 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, |
| 6493 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, |
| 6494 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6495 | |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6496 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, |
| 6497 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, |
Bruce Allan | 10df0b9 | 2010-05-10 15:02:52 +0000 | [diff] [blame] | 6498 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan }, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6499 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6500 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, |
| 6501 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, |
| 6502 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, |
| 6503 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, |
| 6504 | |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 6505 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan }, |
| 6506 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan }, |
| 6507 | |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 6508 | { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6509 | }; |
| 6510 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 6511 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6512 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6513 | static const struct dev_pm_ops e1000_pm_ops = { |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6514 | SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume) |
| 6515 | SET_RUNTIME_PM_OPS(e1000_runtime_suspend, |
| 6516 | e1000_runtime_resume, e1000_idle) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6517 | }; |
David S. Miller | e50208a | 2010-03-16 23:36:24 -0700 | [diff] [blame] | 6518 | #endif |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6519 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6520 | /* PCI Device API Driver */ |
| 6521 | static struct pci_driver e1000_driver = { |
| 6522 | .name = e1000e_driver_name, |
| 6523 | .id_table = e1000_pci_tbl, |
| 6524 | .probe = e1000_probe, |
| 6525 | .remove = __devexit_p(e1000_remove), |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6526 | #ifdef CONFIG_PM |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 6527 | .driver = { |
| 6528 | .pm = &e1000_pm_ops, |
| 6529 | }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6530 | #endif |
| 6531 | .shutdown = e1000_shutdown, |
| 6532 | .err_handler = &e1000_err_handler |
| 6533 | }; |
| 6534 | |
| 6535 | /** |
| 6536 | * e1000_init_module - Driver Registration Routine |
| 6537 | * |
| 6538 | * e1000_init_module is the first routine called when the driver is |
| 6539 | * loaded. All it does is register with the PCI subsystem. |
| 6540 | **/ |
| 6541 | static int __init e1000_init_module(void) |
| 6542 | { |
| 6543 | int ret; |
Bruce Allan | 8544b9f | 2010-03-24 12:55:30 +0000 | [diff] [blame] | 6544 | pr_info("Intel(R) PRO/1000 Network Driver - %s\n", |
| 6545 | e1000e_driver_version); |
Bruce Allan | f5e261e | 2012-01-01 16:00:03 +0000 | [diff] [blame] | 6546 | pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6547 | ret = pci_register_driver(&e1000_driver); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 6548 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6549 | return ret; |
| 6550 | } |
| 6551 | module_init(e1000_init_module); |
| 6552 | |
| 6553 | /** |
| 6554 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 6555 | * |
| 6556 | * e1000_exit_module is called just before the driver is removed |
| 6557 | * from memory. |
| 6558 | **/ |
| 6559 | static void __exit e1000_exit_module(void) |
| 6560 | { |
| 6561 | pci_unregister_driver(&e1000_driver); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6562 | } |
| 6563 | module_exit(e1000_exit_module); |
| 6564 | |
| 6565 | |
| 6566 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 6567 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 6568 | MODULE_LICENSE("GPL"); |
| 6569 | MODULE_VERSION(DRV_VERSION); |
| 6570 | |
| 6571 | /* e1000_main.c */ |