Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel PRO/1000 Linux driver |
Bruce Allan | bf67044 | 2013-01-01 16:00:01 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2013 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> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 45 | #include <linux/ethtool.h> |
| 46 | #include <linux/if_vlan.h> |
| 47 | #include <linux/cpu.h> |
| 48 | #include <linux/smp.h> |
Linus Torvalds | 7e0bb71 | 2011-10-25 15:18:39 +0200 | [diff] [blame] | 49 | #include <linux/pm_qos.h> |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 50 | #include <linux/pm_runtime.h> |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 51 | #include <linux/aer.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 52 | #include <linux/prefetch.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 53 | |
| 54 | #include "e1000.h" |
| 55 | |
Bruce Allan | b3ccf26 | 2011-05-19 01:53:41 +0000 | [diff] [blame] | 56 | #define DRV_EXTRAVERSION "-k" |
Bruce Allan | c14c643 | 2010-06-16 13:28:34 +0000 | [diff] [blame] | 57 | |
Bruce Allan | 9e01990 | 2013-01-12 07:28:54 +0000 | [diff] [blame] | 58 | #define DRV_VERSION "2.2.14" DRV_EXTRAVERSION |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 59 | char e1000e_driver_name[] = "e1000e"; |
| 60 | const char e1000e_driver_version[] = DRV_VERSION; |
| 61 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 62 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 63 | static int debug = -1; |
| 64 | module_param(debug, int, 0); |
| 65 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 66 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 67 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state); |
| 68 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 69 | static const struct e1000_info *e1000_info_tbl[] = { |
| 70 | [board_82571] = &e1000_82571_info, |
| 71 | [board_82572] = &e1000_82572_info, |
| 72 | [board_82573] = &e1000_82573_info, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 73 | [board_82574] = &e1000_82574_info, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 74 | [board_82583] = &e1000_82583_info, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 75 | [board_80003es2lan] = &e1000_es2_info, |
| 76 | [board_ich8lan] = &e1000_ich8_info, |
| 77 | [board_ich9lan] = &e1000_ich9_info, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 78 | [board_ich10lan] = &e1000_ich10_info, |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 79 | [board_pchlan] = &e1000_pch_info, |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 80 | [board_pch2lan] = &e1000_pch2_info, |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 81 | [board_pch_lpt] = &e1000_pch_lpt_info, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 84 | struct e1000_reg_info { |
| 85 | u32 ofs; |
| 86 | char *name; |
| 87 | }; |
| 88 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 89 | static const struct e1000_reg_info e1000_reg_info_tbl[] = { |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 90 | /* General Registers */ |
| 91 | {E1000_CTRL, "CTRL"}, |
| 92 | {E1000_STATUS, "STATUS"}, |
| 93 | {E1000_CTRL_EXT, "CTRL_EXT"}, |
| 94 | |
| 95 | /* Interrupt Registers */ |
| 96 | {E1000_ICR, "ICR"}, |
| 97 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 98 | /* Rx Registers */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 99 | {E1000_RCTL, "RCTL"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 100 | {E1000_RDLEN(0), "RDLEN"}, |
| 101 | {E1000_RDH(0), "RDH"}, |
| 102 | {E1000_RDT(0), "RDT"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 103 | {E1000_RDTR, "RDTR"}, |
| 104 | {E1000_RXDCTL(0), "RXDCTL"}, |
| 105 | {E1000_ERT, "ERT"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 106 | {E1000_RDBAL(0), "RDBAL"}, |
| 107 | {E1000_RDBAH(0), "RDBAH"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 108 | {E1000_RDFH, "RDFH"}, |
| 109 | {E1000_RDFT, "RDFT"}, |
| 110 | {E1000_RDFHS, "RDFHS"}, |
| 111 | {E1000_RDFTS, "RDFTS"}, |
| 112 | {E1000_RDFPC, "RDFPC"}, |
| 113 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 114 | /* Tx Registers */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 115 | {E1000_TCTL, "TCTL"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 116 | {E1000_TDBAL(0), "TDBAL"}, |
| 117 | {E1000_TDBAH(0), "TDBAH"}, |
| 118 | {E1000_TDLEN(0), "TDLEN"}, |
| 119 | {E1000_TDH(0), "TDH"}, |
| 120 | {E1000_TDT(0), "TDT"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 121 | {E1000_TIDV, "TIDV"}, |
| 122 | {E1000_TXDCTL(0), "TXDCTL"}, |
| 123 | {E1000_TADV, "TADV"}, |
| 124 | {E1000_TARC(0), "TARC"}, |
| 125 | {E1000_TDFH, "TDFH"}, |
| 126 | {E1000_TDFT, "TDFT"}, |
| 127 | {E1000_TDFHS, "TDFHS"}, |
| 128 | {E1000_TDFTS, "TDFTS"}, |
| 129 | {E1000_TDFPC, "TDFPC"}, |
| 130 | |
| 131 | /* List Terminator */ |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 132 | {0, NULL} |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 135 | /** |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 136 | * e1000_regdump - register printout routine |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 137 | * @hw: pointer to the HW structure |
| 138 | * @reginfo: pointer to the register info table |
| 139 | **/ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 140 | static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo) |
| 141 | { |
| 142 | int n = 0; |
| 143 | char rname[16]; |
| 144 | u32 regs[8]; |
| 145 | |
| 146 | switch (reginfo->ofs) { |
| 147 | case E1000_RXDCTL(0): |
| 148 | for (n = 0; n < 2; n++) |
| 149 | regs[n] = __er32(hw, E1000_RXDCTL(n)); |
| 150 | break; |
| 151 | case E1000_TXDCTL(0): |
| 152 | for (n = 0; n < 2; n++) |
| 153 | regs[n] = __er32(hw, E1000_TXDCTL(n)); |
| 154 | break; |
| 155 | case E1000_TARC(0): |
| 156 | for (n = 0; n < 2; n++) |
| 157 | regs[n] = __er32(hw, E1000_TARC(n)); |
| 158 | break; |
| 159 | default: |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 160 | pr_info("%-15s %08x\n", |
| 161 | reginfo->name, __er32(hw, reginfo->ofs)); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 162 | return; |
| 163 | } |
| 164 | |
| 165 | snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 166 | pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 169 | static void e1000e_dump_ps_pages(struct e1000_adapter *adapter, |
| 170 | struct e1000_buffer *bi) |
| 171 | { |
| 172 | int i; |
| 173 | struct e1000_ps_page *ps_page; |
| 174 | |
| 175 | for (i = 0; i < adapter->rx_ps_pages; i++) { |
| 176 | ps_page = &bi->ps_pages[i]; |
| 177 | |
| 178 | if (ps_page->page) { |
| 179 | pr_info("packet dump for ps_page %d:\n", i); |
| 180 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, |
| 181 | 16, 1, page_address(ps_page->page), |
| 182 | PAGE_SIZE, true); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 187 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 188 | * e1000e_dump - Print registers, Tx-ring and Rx-ring |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 189 | * @adapter: board private structure |
| 190 | **/ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 191 | static void e1000e_dump(struct e1000_adapter *adapter) |
| 192 | { |
| 193 | struct net_device *netdev = adapter->netdev; |
| 194 | struct e1000_hw *hw = &adapter->hw; |
| 195 | struct e1000_reg_info *reginfo; |
| 196 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 197 | struct e1000_tx_desc *tx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 198 | struct my_u0 { |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 199 | __le64 a; |
| 200 | __le64 b; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 201 | } *u0; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 202 | struct e1000_buffer *buffer_info; |
| 203 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 204 | union e1000_rx_desc_packet_split *rx_desc_ps; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 205 | union e1000_rx_desc_extended *rx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 206 | struct my_u1 { |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 207 | __le64 a; |
| 208 | __le64 b; |
| 209 | __le64 c; |
| 210 | __le64 d; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 211 | } *u1; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 212 | u32 staterr; |
| 213 | int i = 0; |
| 214 | |
| 215 | if (!netif_msg_hw(adapter)) |
| 216 | return; |
| 217 | |
| 218 | /* Print netdevice Info */ |
| 219 | if (netdev) { |
| 220 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 221 | pr_info("Device Name state trans_start last_rx\n"); |
| 222 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 223 | netdev->name, netdev->state, netdev->trans_start, |
| 224 | netdev->last_rx); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /* Print Registers */ |
| 228 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 229 | pr_info(" Register Name Value\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 230 | for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl; |
| 231 | reginfo->name; reginfo++) { |
| 232 | e1000_regdump(hw, reginfo); |
| 233 | } |
| 234 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 235 | /* Print Tx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 236 | if (!netdev || !netif_running(netdev)) |
Bruce Allan | fe1e980 | 2012-01-31 06:37:54 +0000 | [diff] [blame] | 237 | return; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 238 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 239 | dev_info(&adapter->pdev->dev, "Tx Ring Summary\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 240 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 241 | buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean]; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 242 | pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n", |
| 243 | 0, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 244 | (unsigned long long)buffer_info->dma, |
| 245 | buffer_info->length, |
| 246 | buffer_info->next_to_watch, |
| 247 | (unsigned long long)buffer_info->time_stamp); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 248 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 249 | /* Print Tx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 250 | if (!netif_msg_tx_done(adapter)) |
| 251 | goto rx_ring_summary; |
| 252 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 253 | dev_info(&adapter->pdev->dev, "Tx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 254 | |
| 255 | /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended) |
| 256 | * |
| 257 | * Legacy Transmit Descriptor |
| 258 | * +--------------------------------------------------------------+ |
| 259 | * 0 | Buffer Address [63:0] (Reserved on Write Back) | |
| 260 | * +--------------------------------------------------------------+ |
| 261 | * 8 | Special | CSS | Status | CMD | CSO | Length | |
| 262 | * +--------------------------------------------------------------+ |
| 263 | * 63 48 47 36 35 32 31 24 23 16 15 0 |
| 264 | * |
| 265 | * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload |
| 266 | * 63 48 47 40 39 32 31 16 15 8 7 0 |
| 267 | * +----------------------------------------------------------------+ |
| 268 | * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS | |
| 269 | * +----------------------------------------------------------------+ |
| 270 | * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN | |
| 271 | * +----------------------------------------------------------------+ |
| 272 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 273 | * |
| 274 | * Extended Data Descriptor (DTYP=0x1) |
| 275 | * +----------------------------------------------------------------+ |
| 276 | * 0 | Buffer Address [63:0] | |
| 277 | * +----------------------------------------------------------------+ |
| 278 | * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN | |
| 279 | * +----------------------------------------------------------------+ |
| 280 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 281 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 282 | pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n"); |
| 283 | pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n"); |
| 284 | 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] | 285 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 286 | const char *next_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 287 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 288 | buffer_info = &tx_ring->buffer_info[i]; |
| 289 | u0 = (struct my_u0 *)tx_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 290 | 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] | 291 | next_desc = " NTC/U"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 292 | else if (i == tx_ring->next_to_use) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 293 | next_desc = " NTU"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 294 | else if (i == tx_ring->next_to_clean) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 295 | next_desc = " NTC"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 296 | else |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 297 | next_desc = ""; |
| 298 | pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n", |
| 299 | (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' : |
| 300 | ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), |
| 301 | i, |
| 302 | (unsigned long long)le64_to_cpu(u0->a), |
| 303 | (unsigned long long)le64_to_cpu(u0->b), |
| 304 | (unsigned long long)buffer_info->dma, |
| 305 | buffer_info->length, buffer_info->next_to_watch, |
| 306 | (unsigned long long)buffer_info->time_stamp, |
| 307 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 308 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 309 | if (netif_msg_pktdata(adapter) && buffer_info->skb) |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 310 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 311 | 16, 1, buffer_info->skb->data, |
| 312 | buffer_info->skb->len, true); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 315 | /* Print Rx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 316 | rx_ring_summary: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 317 | dev_info(&adapter->pdev->dev, "Rx Ring Summary\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 318 | pr_info("Queue [NTU] [NTC]\n"); |
| 319 | pr_info(" %5d %5X %5X\n", |
| 320 | 0, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 321 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 322 | /* Print Rx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 323 | if (!netif_msg_rx_status(adapter)) |
Bruce Allan | fe1e980 | 2012-01-31 06:37:54 +0000 | [diff] [blame] | 324 | return; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 325 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 326 | dev_info(&adapter->pdev->dev, "Rx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 327 | switch (adapter->rx_ps_pages) { |
| 328 | case 1: |
| 329 | case 2: |
| 330 | case 3: |
| 331 | /* [Extended] Packet Split Receive Descriptor Format |
| 332 | * |
| 333 | * +-----------------------------------------------------+ |
| 334 | * 0 | Buffer Address 0 [63:0] | |
| 335 | * +-----------------------------------------------------+ |
| 336 | * 8 | Buffer Address 1 [63:0] | |
| 337 | * +-----------------------------------------------------+ |
| 338 | * 16 | Buffer Address 2 [63:0] | |
| 339 | * +-----------------------------------------------------+ |
| 340 | * 24 | Buffer Address 3 [63:0] | |
| 341 | * +-----------------------------------------------------+ |
| 342 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 343 | 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] | 344 | /* [Extended] Receive Descriptor (Write-Back) Format |
| 345 | * |
| 346 | * 63 48 47 32 31 13 12 8 7 4 3 0 |
| 347 | * +------------------------------------------------------+ |
| 348 | * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS | |
| 349 | * | Checksum | Ident | | Queue | | Type | |
| 350 | * +------------------------------------------------------+ |
| 351 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 352 | * +------------------------------------------------------+ |
| 353 | * 63 48 47 32 31 20 19 0 |
| 354 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 355 | 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] | 356 | for (i = 0; i < rx_ring->count; i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 357 | const char *next_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 358 | buffer_info = &rx_ring->buffer_info[i]; |
| 359 | rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i); |
| 360 | u1 = (struct my_u1 *)rx_desc_ps; |
| 361 | staterr = |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 362 | le32_to_cpu(rx_desc_ps->wb.middle.status_error); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 363 | |
| 364 | if (i == rx_ring->next_to_use) |
| 365 | next_desc = " NTU"; |
| 366 | else if (i == rx_ring->next_to_clean) |
| 367 | next_desc = " NTC"; |
| 368 | else |
| 369 | next_desc = ""; |
| 370 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 371 | if (staterr & E1000_RXD_STAT_DD) { |
| 372 | /* Descriptor Done */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 373 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n", |
| 374 | "RWB", i, |
| 375 | (unsigned long long)le64_to_cpu(u1->a), |
| 376 | (unsigned long long)le64_to_cpu(u1->b), |
| 377 | (unsigned long long)le64_to_cpu(u1->c), |
| 378 | (unsigned long long)le64_to_cpu(u1->d), |
| 379 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 380 | } else { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 381 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n", |
| 382 | "R ", i, |
| 383 | (unsigned long long)le64_to_cpu(u1->a), |
| 384 | (unsigned long long)le64_to_cpu(u1->b), |
| 385 | (unsigned long long)le64_to_cpu(u1->c), |
| 386 | (unsigned long long)le64_to_cpu(u1->d), |
| 387 | (unsigned long long)buffer_info->dma, |
| 388 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 389 | |
| 390 | if (netif_msg_pktdata(adapter)) |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 391 | e1000e_dump_ps_pages(adapter, |
| 392 | buffer_info); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 393 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 394 | } |
| 395 | break; |
| 396 | default: |
| 397 | case 0: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 398 | /* Extended Receive Descriptor (Read) Format |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 399 | * |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 400 | * +-----------------------------------------------------+ |
| 401 | * 0 | Buffer Address [63:0] | |
| 402 | * +-----------------------------------------------------+ |
| 403 | * 8 | Reserved | |
| 404 | * +-----------------------------------------------------+ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 405 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 406 | 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] | 407 | /* Extended Receive Descriptor (Write-Back) Format |
| 408 | * |
| 409 | * 63 48 47 32 31 24 23 4 3 0 |
| 410 | * +------------------------------------------------------+ |
| 411 | * | RSS Hash | | | | |
| 412 | * 0 +-------------------+ Rsvd | Reserved | MRQ RSS | |
| 413 | * | Packet | IP | | | Type | |
| 414 | * | Checksum | Ident | | | | |
| 415 | * +------------------------------------------------------+ |
| 416 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 417 | * +------------------------------------------------------+ |
| 418 | * 63 48 47 32 31 20 19 0 |
| 419 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 420 | 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] | 421 | |
| 422 | for (i = 0; i < rx_ring->count; i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 423 | const char *next_desc; |
| 424 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 425 | buffer_info = &rx_ring->buffer_info[i]; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 426 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 427 | u1 = (struct my_u1 *)rx_desc; |
| 428 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 429 | |
| 430 | if (i == rx_ring->next_to_use) |
| 431 | next_desc = " NTU"; |
| 432 | else if (i == rx_ring->next_to_clean) |
| 433 | next_desc = " NTC"; |
| 434 | else |
| 435 | next_desc = ""; |
| 436 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 437 | if (staterr & E1000_RXD_STAT_DD) { |
| 438 | /* Descriptor Done */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 439 | pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n", |
| 440 | "RWB", i, |
| 441 | (unsigned long long)le64_to_cpu(u1->a), |
| 442 | (unsigned long long)le64_to_cpu(u1->b), |
| 443 | buffer_info->skb, next_desc); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 444 | } else { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 445 | pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n", |
| 446 | "R ", i, |
| 447 | (unsigned long long)le64_to_cpu(u1->a), |
| 448 | (unsigned long long)le64_to_cpu(u1->b), |
| 449 | (unsigned long long)buffer_info->dma, |
| 450 | buffer_info->skb, next_desc); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 451 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 452 | if (netif_msg_pktdata(adapter) && |
| 453 | buffer_info->skb) |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 454 | print_hex_dump(KERN_INFO, "", |
| 455 | DUMP_PREFIX_ADDRESS, 16, |
| 456 | 1, |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 457 | buffer_info->skb->data, |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 458 | adapter->rx_buffer_len, |
| 459 | true); |
| 460 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 461 | } |
| 462 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 465 | /** |
| 466 | * e1000_desc_unused - calculate if we have unused descriptors |
| 467 | **/ |
| 468 | static int e1000_desc_unused(struct e1000_ring *ring) |
| 469 | { |
| 470 | if (ring->next_to_clean > ring->next_to_use) |
| 471 | return ring->next_to_clean - ring->next_to_use - 1; |
| 472 | |
| 473 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; |
| 474 | } |
| 475 | |
| 476 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 477 | * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp |
| 478 | * @adapter: board private structure |
| 479 | * @hwtstamps: time stamp structure to update |
| 480 | * @systim: unsigned 64bit system time value. |
| 481 | * |
| 482 | * Convert the system time value stored in the RX/TXSTMP registers into a |
| 483 | * hwtstamp which can be used by the upper level time stamping functions. |
| 484 | * |
| 485 | * The 'systim_lock' spinlock is used to protect the consistency of the |
| 486 | * system time value. This is needed because reading the 64 bit time |
| 487 | * value involves reading two 32 bit registers. The first read latches the |
| 488 | * value. |
| 489 | **/ |
| 490 | static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter, |
| 491 | struct skb_shared_hwtstamps *hwtstamps, |
| 492 | u64 systim) |
| 493 | { |
| 494 | u64 ns; |
| 495 | unsigned long flags; |
| 496 | |
| 497 | spin_lock_irqsave(&adapter->systim_lock, flags); |
| 498 | ns = timecounter_cyc2time(&adapter->tc, systim); |
| 499 | spin_unlock_irqrestore(&adapter->systim_lock, flags); |
| 500 | |
| 501 | memset(hwtstamps, 0, sizeof(*hwtstamps)); |
| 502 | hwtstamps->hwtstamp = ns_to_ktime(ns); |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp |
| 507 | * @adapter: board private structure |
| 508 | * @status: descriptor extended error and status field |
| 509 | * @skb: particular skb to include time stamp |
| 510 | * |
| 511 | * If the time stamp is valid, convert it into the timecounter ns value |
| 512 | * and store that result into the shhwtstamps structure which is passed |
| 513 | * up the network stack. |
| 514 | **/ |
| 515 | static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status, |
| 516 | struct sk_buff *skb) |
| 517 | { |
| 518 | struct e1000_hw *hw = &adapter->hw; |
| 519 | u64 rxstmp; |
| 520 | |
| 521 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) || |
| 522 | !(status & E1000_RXDEXT_STATERR_TST) || |
| 523 | !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) |
| 524 | return; |
| 525 | |
| 526 | /* The Rx time stamp registers contain the time stamp. No other |
| 527 | * received packet will be time stamped until the Rx time stamp |
| 528 | * registers are read. Because only one packet can be time stamped |
| 529 | * at a time, the register values must belong to this packet and |
| 530 | * therefore none of the other additional attributes need to be |
| 531 | * compared. |
| 532 | */ |
| 533 | rxstmp = (u64)er32(RXSTMPL); |
| 534 | rxstmp |= (u64)er32(RXSTMPH) << 32; |
| 535 | e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp); |
| 536 | |
| 537 | adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP; |
| 538 | } |
| 539 | |
| 540 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 541 | * e1000_receive_skb - helper function to handle Rx indications |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 542 | * @adapter: board private structure |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 543 | * @staterr: descriptor extended error and status field as written by hardware |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 544 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
| 545 | * @skb: pointer to sk_buff to be indicated to stack |
| 546 | **/ |
| 547 | static void e1000_receive_skb(struct e1000_adapter *adapter, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 548 | struct net_device *netdev, struct sk_buff *skb, |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 549 | u32 staterr, __le16 vlan) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 550 | { |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 551 | u16 tag = le16_to_cpu(vlan); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 552 | |
| 553 | e1000e_rx_hwtstamp(adapter, staterr, skb); |
| 554 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 555 | skb->protocol = eth_type_trans(skb, netdev); |
| 556 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 557 | if (staterr & E1000_RXD_STAT_VP) |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 558 | __vlan_hwaccel_put_tag(skb, tag); |
| 559 | |
| 560 | napi_gro_receive(&adapter->napi, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 564 | * e1000_rx_checksum - Receive Checksum Offload |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 565 | * @adapter: board private structure |
| 566 | * @status_err: receive descriptor status and error fields |
| 567 | * @csum: receive descriptor csum field |
| 568 | * @sk_buff: socket buffer with received data |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 569 | **/ |
| 570 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 571 | struct sk_buff *skb) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 572 | { |
| 573 | u16 status = (u16)status_err; |
| 574 | u8 errors = (u8)(status_err >> 24); |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 575 | |
| 576 | skb_checksum_none_assert(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 577 | |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 578 | /* Rx checksum disabled */ |
| 579 | if (!(adapter->netdev->features & NETIF_F_RXCSUM)) |
| 580 | return; |
| 581 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 582 | /* Ignore Checksum bit is set */ |
| 583 | if (status & E1000_RXD_STAT_IXSM) |
| 584 | return; |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 585 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 586 | /* TCP/UDP checksum error bit or IP checksum error bit is set */ |
| 587 | if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 588 | /* let the stack verify checksum errors */ |
| 589 | adapter->hw_csum_err++; |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | /* TCP/UDP Checksum has not been calculated */ |
| 594 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
| 595 | return; |
| 596 | |
| 597 | /* It must be a TCP or UDP packet with a valid checksum */ |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 598 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 599 | adapter->hw_csum_good++; |
| 600 | } |
| 601 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 602 | 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] | 603 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 604 | struct e1000_adapter *adapter = rx_ring->adapter; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 605 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 606 | s32 ret_val = __ew32_prepare(hw); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 607 | |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 608 | writel(i, rx_ring->tail); |
| 609 | |
| 610 | if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 611 | u32 rctl = er32(RCTL); |
| 612 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 613 | e_err("ME firmware caused invalid RDT - resetting\n"); |
| 614 | schedule_work(&adapter->reset_task); |
| 615 | } |
| 616 | } |
| 617 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 618 | 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] | 619 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 620 | struct e1000_adapter *adapter = tx_ring->adapter; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 621 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 622 | s32 ret_val = __ew32_prepare(hw); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 623 | |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 624 | writel(i, tx_ring->tail); |
| 625 | |
| 626 | if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 627 | u32 tctl = er32(TCTL); |
| 628 | ew32(TCTL, tctl & ~E1000_TCTL_EN); |
| 629 | e_err("ME firmware caused invalid TDT - resetting\n"); |
| 630 | schedule_work(&adapter->reset_task); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | /** |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 635 | * e1000_alloc_rx_buffers - Replace used receive buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 636 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 637 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 638 | static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 639 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 640 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 641 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 642 | struct net_device *netdev = adapter->netdev; |
| 643 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 644 | union e1000_rx_desc_extended *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 645 | struct e1000_buffer *buffer_info; |
| 646 | struct sk_buff *skb; |
| 647 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 648 | unsigned int bufsz = adapter->rx_buffer_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 649 | |
| 650 | i = rx_ring->next_to_use; |
| 651 | buffer_info = &rx_ring->buffer_info[i]; |
| 652 | |
| 653 | while (cleaned_count--) { |
| 654 | skb = buffer_info->skb; |
| 655 | if (skb) { |
| 656 | skb_trim(skb, 0); |
| 657 | goto map_skb; |
| 658 | } |
| 659 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 660 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 661 | if (!skb) { |
| 662 | /* Better luck next round */ |
| 663 | adapter->alloc_rx_buff_failed++; |
| 664 | break; |
| 665 | } |
| 666 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 667 | buffer_info->skb = skb; |
| 668 | map_skb: |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 669 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 670 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 671 | DMA_FROM_DEVICE); |
| 672 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 673 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 674 | adapter->rx_dma_failed++; |
| 675 | break; |
| 676 | } |
| 677 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 678 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 679 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 680 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 681 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 682 | /* Force memory writes to complete before letting h/w |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 683 | * know there are new descriptors to fetch. (Only |
| 684 | * applicable for weak-ordered memory model archs, |
| 685 | * such as IA-64). |
| 686 | */ |
| 687 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 688 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 689 | e1000e_update_rdt_wa(rx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 690 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 691 | writel(i, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 692 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 693 | i++; |
| 694 | if (i == rx_ring->count) |
| 695 | i = 0; |
| 696 | buffer_info = &rx_ring->buffer_info[i]; |
| 697 | } |
| 698 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 699 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | /** |
| 703 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 704 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 705 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 706 | static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 707 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 708 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 709 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 710 | struct net_device *netdev = adapter->netdev; |
| 711 | struct pci_dev *pdev = adapter->pdev; |
| 712 | union e1000_rx_desc_packet_split *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 713 | struct e1000_buffer *buffer_info; |
| 714 | struct e1000_ps_page *ps_page; |
| 715 | struct sk_buff *skb; |
| 716 | unsigned int i, j; |
| 717 | |
| 718 | i = rx_ring->next_to_use; |
| 719 | buffer_info = &rx_ring->buffer_info[i]; |
| 720 | |
| 721 | while (cleaned_count--) { |
| 722 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 723 | |
| 724 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 725 | ps_page = &buffer_info->ps_pages[j]; |
| 726 | if (j >= adapter->rx_ps_pages) { |
| 727 | /* all unused desc entries get hw null ptr */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 728 | rx_desc->read.buffer_addr[j + 1] = |
| 729 | ~cpu_to_le64(0); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 730 | continue; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 731 | } |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 732 | if (!ps_page->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 733 | ps_page->page = alloc_page(gfp); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 734 | if (!ps_page->page) { |
| 735 | adapter->alloc_rx_buff_failed++; |
| 736 | goto no_buffers; |
| 737 | } |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 738 | ps_page->dma = dma_map_page(&pdev->dev, |
| 739 | ps_page->page, |
| 740 | 0, PAGE_SIZE, |
| 741 | DMA_FROM_DEVICE); |
| 742 | if (dma_mapping_error(&pdev->dev, |
| 743 | ps_page->dma)) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 744 | dev_err(&adapter->pdev->dev, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 745 | "Rx DMA page map failed\n"); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 746 | adapter->rx_dma_failed++; |
| 747 | goto no_buffers; |
| 748 | } |
| 749 | } |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 750 | /* Refresh the desc even if buffer_addrs |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 751 | * didn't change because each write-back |
| 752 | * erases this info. |
| 753 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 754 | rx_desc->read.buffer_addr[j + 1] = |
| 755 | cpu_to_le64(ps_page->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 758 | skb = __netdev_alloc_skb_ip_align(netdev, |
| 759 | adapter->rx_ps_bsize0, |
| 760 | gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 761 | |
| 762 | if (!skb) { |
| 763 | adapter->alloc_rx_buff_failed++; |
| 764 | break; |
| 765 | } |
| 766 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 767 | buffer_info->skb = skb; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 768 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 769 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 770 | DMA_FROM_DEVICE); |
| 771 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 772 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 773 | adapter->rx_dma_failed++; |
| 774 | /* cleanup skb */ |
| 775 | dev_kfree_skb_any(skb); |
| 776 | buffer_info->skb = NULL; |
| 777 | break; |
| 778 | } |
| 779 | |
| 780 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 781 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 782 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 783 | /* Force memory writes to complete before letting h/w |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 784 | * know there are new descriptors to fetch. (Only |
| 785 | * applicable for weak-ordered memory model archs, |
| 786 | * such as IA-64). |
| 787 | */ |
| 788 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 789 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 790 | e1000e_update_rdt_wa(rx_ring, i << 1); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 791 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 792 | writel(i << 1, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 795 | i++; |
| 796 | if (i == rx_ring->count) |
| 797 | i = 0; |
| 798 | buffer_info = &rx_ring->buffer_info[i]; |
| 799 | } |
| 800 | |
| 801 | no_buffers: |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 802 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 806 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 807 | * @rx_ring: Rx descriptor ring |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 808 | * @cleaned_count: number of buffers to allocate this pass |
| 809 | **/ |
| 810 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 811 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 812 | int cleaned_count, gfp_t gfp) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 813 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 814 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 815 | struct net_device *netdev = adapter->netdev; |
| 816 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 817 | union e1000_rx_desc_extended *rx_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 818 | struct e1000_buffer *buffer_info; |
| 819 | struct sk_buff *skb; |
| 820 | unsigned int i; |
Bruce Allan | 2a2293b | 2012-12-05 06:26:35 +0000 | [diff] [blame] | 821 | unsigned int bufsz = 256 - 16; /* for skb_reserve */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 822 | |
| 823 | i = rx_ring->next_to_use; |
| 824 | buffer_info = &rx_ring->buffer_info[i]; |
| 825 | |
| 826 | while (cleaned_count--) { |
| 827 | skb = buffer_info->skb; |
| 828 | if (skb) { |
| 829 | skb_trim(skb, 0); |
| 830 | goto check_page; |
| 831 | } |
| 832 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 833 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 834 | if (unlikely(!skb)) { |
| 835 | /* Better luck next round */ |
| 836 | adapter->alloc_rx_buff_failed++; |
| 837 | break; |
| 838 | } |
| 839 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 840 | buffer_info->skb = skb; |
| 841 | check_page: |
| 842 | /* allocate a new page if necessary */ |
| 843 | if (!buffer_info->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 844 | buffer_info->page = alloc_page(gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 845 | if (unlikely(!buffer_info->page)) { |
| 846 | adapter->alloc_rx_buff_failed++; |
| 847 | break; |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | if (!buffer_info->dma) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 852 | buffer_info->dma = dma_map_page(&pdev->dev, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 853 | buffer_info->page, 0, |
| 854 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 855 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 856 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 857 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 858 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 859 | |
| 860 | if (unlikely(++i == rx_ring->count)) |
| 861 | i = 0; |
| 862 | buffer_info = &rx_ring->buffer_info[i]; |
| 863 | } |
| 864 | |
| 865 | if (likely(rx_ring->next_to_use != i)) { |
| 866 | rx_ring->next_to_use = i; |
| 867 | if (unlikely(i-- == 0)) |
| 868 | i = (rx_ring->count - 1); |
| 869 | |
| 870 | /* Force memory writes to complete before letting h/w |
| 871 | * know there are new descriptors to fetch. (Only |
| 872 | * applicable for weak-ordered memory model archs, |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 873 | * such as IA-64). |
| 874 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 875 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 876 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 877 | e1000e_update_rdt_wa(rx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 878 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 879 | writel(i, rx_ring->tail); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 883 | static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss, |
| 884 | struct sk_buff *skb) |
| 885 | { |
| 886 | if (netdev->features & NETIF_F_RXHASH) |
| 887 | skb->rxhash = le32_to_cpu(rss); |
| 888 | } |
| 889 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 890 | /** |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 891 | * e1000_clean_rx_irq - Send received data up the network stack |
| 892 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 893 | * |
| 894 | * the return value indicates whether actual cleaning was done, there |
| 895 | * is no guarantee that everything was cleaned |
| 896 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 897 | static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
| 898 | int work_to_do) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 899 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 900 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 901 | struct net_device *netdev = adapter->netdev; |
| 902 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 903 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 904 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 905 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 906 | u32 length, staterr; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 907 | unsigned int i; |
| 908 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 909 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 910 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 911 | |
| 912 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 913 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 914 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 915 | buffer_info = &rx_ring->buffer_info[i]; |
| 916 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 917 | while (staterr & E1000_RXD_STAT_DD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 918 | struct sk_buff *skb; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 919 | |
| 920 | if (*work_done >= work_to_do) |
| 921 | break; |
| 922 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 923 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 924 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 925 | skb = buffer_info->skb; |
| 926 | buffer_info->skb = NULL; |
| 927 | |
| 928 | prefetch(skb->data - NET_IP_ALIGN); |
| 929 | |
| 930 | i++; |
| 931 | if (i == rx_ring->count) |
| 932 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 933 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 934 | prefetch(next_rxd); |
| 935 | |
| 936 | next_buffer = &rx_ring->buffer_info[i]; |
| 937 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 938 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 939 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 940 | dma_unmap_single(&pdev->dev, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 941 | buffer_info->dma, |
| 942 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 943 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 944 | buffer_info->dma = 0; |
| 945 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 946 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 947 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 948 | /* !EOP means multiple descriptors were used to store a single |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 949 | * packet, if that's the case we need to toss it. In fact, we |
| 950 | * need to toss every packet with the EOP bit clear and the |
| 951 | * next frame that _does_ have the EOP bit set, as it is by |
| 952 | * definition only a frame fragment |
| 953 | */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 954 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 955 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 956 | |
| 957 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 958 | /* All receives must fit into a single buffer */ |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 959 | e_dbg("Receive packet consumed multiple buffers\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 960 | /* recycle */ |
| 961 | buffer_info->skb = skb; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 962 | if (staterr & E1000_RXD_STAT_EOP) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 963 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 964 | goto next_desc; |
| 965 | } |
| 966 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 967 | if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 968 | !(netdev->features & NETIF_F_RXALL))) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 969 | /* recycle */ |
| 970 | buffer_info->skb = skb; |
| 971 | goto next_desc; |
| 972 | } |
| 973 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 974 | /* adjust length to remove Ethernet CRC */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 975 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 976 | /* If configured to store CRC, don't subtract FCS, |
| 977 | * but keep the FCS bytes out of the total_rx_bytes |
| 978 | * counter |
| 979 | */ |
| 980 | if (netdev->features & NETIF_F_RXFCS) |
| 981 | total_rx_bytes -= 4; |
| 982 | else |
| 983 | length -= 4; |
| 984 | } |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 985 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 986 | total_rx_bytes += length; |
| 987 | total_rx_packets++; |
| 988 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 989 | /* code added for copybreak, this should improve |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 990 | * performance for small packets with large amounts |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 991 | * of reassembly being done in the stack |
| 992 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 993 | if (length < copybreak) { |
| 994 | struct sk_buff *new_skb = |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 995 | netdev_alloc_skb_ip_align(netdev, length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 996 | if (new_skb) { |
Bruce Allan | 808ff67 | 2008-08-08 18:35:56 -0700 | [diff] [blame] | 997 | skb_copy_to_linear_data_offset(new_skb, |
| 998 | -NET_IP_ALIGN, |
| 999 | (skb->data - |
| 1000 | NET_IP_ALIGN), |
| 1001 | (length + |
| 1002 | NET_IP_ALIGN)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1003 | /* save the skb in buffer_info as good */ |
| 1004 | buffer_info->skb = skb; |
| 1005 | skb = new_skb; |
| 1006 | } |
| 1007 | /* else just continue with the old one */ |
| 1008 | } |
| 1009 | /* end copybreak code */ |
| 1010 | skb_put(skb, length); |
| 1011 | |
| 1012 | /* Receive Checksum Offload */ |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1013 | e1000_rx_checksum(adapter, staterr, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1014 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1015 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1016 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1017 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1018 | rx_desc->wb.upper.vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1019 | |
| 1020 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1021 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1022 | |
| 1023 | /* return some buffers to hardware, one at a time is too slow */ |
| 1024 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1025 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1026 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1027 | cleaned_count = 0; |
| 1028 | } |
| 1029 | |
| 1030 | /* use prefetched values */ |
| 1031 | rx_desc = next_rxd; |
| 1032 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1033 | |
| 1034 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1035 | } |
| 1036 | rx_ring->next_to_clean = i; |
| 1037 | |
| 1038 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1039 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1040 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1041 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1042 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1043 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1044 | return cleaned; |
| 1045 | } |
| 1046 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1047 | static void e1000_put_txbuf(struct e1000_ring *tx_ring, |
| 1048 | struct e1000_buffer *buffer_info) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1049 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1050 | struct e1000_adapter *adapter = tx_ring->adapter; |
| 1051 | |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1052 | if (buffer_info->dma) { |
| 1053 | if (buffer_info->mapped_as_page) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1054 | dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, |
| 1055 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1056 | else |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1057 | dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, |
| 1058 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1059 | buffer_info->dma = 0; |
| 1060 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1061 | if (buffer_info->skb) { |
| 1062 | dev_kfree_skb_any(buffer_info->skb); |
| 1063 | buffer_info->skb = NULL; |
| 1064 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 1065 | buffer_info->time_stamp = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1068 | static void e1000_print_hw_hang(struct work_struct *work) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1069 | { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1070 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1071 | struct e1000_adapter, |
| 1072 | print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1073 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1074 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1075 | unsigned int i = tx_ring->next_to_clean; |
| 1076 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; |
| 1077 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1078 | struct e1000_hw *hw = &adapter->hw; |
| 1079 | u16 phy_status, phy_1000t_status, phy_ext_status; |
| 1080 | u16 pci_status; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1081 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1082 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1083 | return; |
| 1084 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1085 | if (!adapter->tx_hang_recheck && |
| 1086 | (adapter->flags2 & FLAG2_DMA_BURST)) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1087 | /* May be block on write-back, flush and detect again |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1088 | * flush pending descriptor writebacks to memory |
| 1089 | */ |
| 1090 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 1091 | /* execute the writes immediately */ |
| 1092 | e1e_flush(); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1093 | /* Due to rare timing issues, write to TIDV again to ensure |
Matthew Vick | bf03085 | 2012-03-16 09:03:00 +0000 | [diff] [blame] | 1094 | * the write is successful |
| 1095 | */ |
| 1096 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 1097 | /* execute the writes immediately */ |
| 1098 | e1e_flush(); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1099 | adapter->tx_hang_recheck = true; |
| 1100 | return; |
| 1101 | } |
| 1102 | /* Real hang detected */ |
| 1103 | adapter->tx_hang_recheck = false; |
| 1104 | netif_stop_queue(netdev); |
| 1105 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 1106 | e1e_rphy(hw, MII_BMSR, &phy_status); |
| 1107 | e1e_rphy(hw, MII_STAT1000, &phy_1000t_status); |
| 1108 | e1e_rphy(hw, MII_ESTATUS, &phy_ext_status); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1109 | |
| 1110 | pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status); |
| 1111 | |
| 1112 | /* detected Hardware unit hang */ |
| 1113 | e_err("Detected Hardware Unit Hang:\n" |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1114 | " TDH <%x>\n" |
| 1115 | " TDT <%x>\n" |
| 1116 | " next_to_use <%x>\n" |
| 1117 | " next_to_clean <%x>\n" |
| 1118 | "buffer_info[next_to_clean]:\n" |
| 1119 | " time_stamp <%lx>\n" |
| 1120 | " next_to_watch <%x>\n" |
| 1121 | " jiffies <%lx>\n" |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1122 | " next_to_watch.status <%x>\n" |
| 1123 | "MAC Status <%x>\n" |
| 1124 | "PHY Status <%x>\n" |
| 1125 | "PHY 1000BASE-T Status <%x>\n" |
| 1126 | "PHY Extended Status <%x>\n" |
| 1127 | "PCI Status <%x>\n", |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1128 | readl(tx_ring->head), |
| 1129 | readl(tx_ring->tail), |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1130 | tx_ring->next_to_use, |
| 1131 | tx_ring->next_to_clean, |
| 1132 | tx_ring->buffer_info[eop].time_stamp, |
| 1133 | eop, |
| 1134 | jiffies, |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1135 | eop_desc->upper.fields.status, |
| 1136 | er32(STATUS), |
| 1137 | phy_status, |
| 1138 | phy_1000t_status, |
| 1139 | phy_ext_status, |
| 1140 | pci_status); |
Bruce Allan | 7c0427e | 2012-03-20 03:48:08 +0000 | [diff] [blame] | 1141 | |
| 1142 | /* Suggest workaround for known h/w issue */ |
| 1143 | if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE)) |
| 1144 | e_err("Try turning off Tx pause (flow control) via ethtool\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1148 | * e1000e_tx_hwtstamp_work - check for Tx time stamp |
| 1149 | * @work: pointer to work struct |
| 1150 | * |
| 1151 | * This work function polls the TSYNCTXCTL valid bit to determine when a |
| 1152 | * timestamp has been taken for the current stored skb. The timestamp must |
| 1153 | * be for this skb because only one such packet is allowed in the queue. |
| 1154 | */ |
| 1155 | static void e1000e_tx_hwtstamp_work(struct work_struct *work) |
| 1156 | { |
| 1157 | struct e1000_adapter *adapter = container_of(work, struct e1000_adapter, |
| 1158 | tx_hwtstamp_work); |
| 1159 | struct e1000_hw *hw = &adapter->hw; |
| 1160 | |
| 1161 | if (!adapter->tx_hwtstamp_skb) |
| 1162 | return; |
| 1163 | |
| 1164 | if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) { |
| 1165 | struct skb_shared_hwtstamps shhwtstamps; |
| 1166 | u64 txstmp; |
| 1167 | |
| 1168 | txstmp = er32(TXSTMPL); |
| 1169 | txstmp |= (u64)er32(TXSTMPH) << 32; |
| 1170 | |
| 1171 | e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp); |
| 1172 | |
| 1173 | skb_tstamp_tx(adapter->tx_hwtstamp_skb, &shhwtstamps); |
| 1174 | dev_kfree_skb_any(adapter->tx_hwtstamp_skb); |
| 1175 | adapter->tx_hwtstamp_skb = NULL; |
| 1176 | } else { |
| 1177 | /* reschedule to check later */ |
| 1178 | schedule_work(&adapter->tx_hwtstamp_work); |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1183 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1184 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1185 | * |
| 1186 | * the return value indicates whether actual cleaning was done, there |
| 1187 | * is no guarantee that everything was cleaned |
| 1188 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1189 | static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1190 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1191 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1192 | struct net_device *netdev = adapter->netdev; |
| 1193 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1194 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 1195 | struct e1000_buffer *buffer_info; |
| 1196 | unsigned int i, eop; |
| 1197 | unsigned int count = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1198 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1199 | unsigned int bytes_compl = 0, pkts_compl = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1200 | |
| 1201 | i = tx_ring->next_to_clean; |
| 1202 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1203 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 1204 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1205 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 1206 | (count < tx_ring->count)) { |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1207 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1208 | rmb(); /* read buffer_info after eop_desc */ |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1209 | for (; !cleaned; count++) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1210 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 1211 | buffer_info = &tx_ring->buffer_info[i]; |
| 1212 | cleaned = (i == eop); |
| 1213 | |
| 1214 | if (cleaned) { |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 1215 | total_tx_packets += buffer_info->segs; |
| 1216 | total_tx_bytes += buffer_info->bytecount; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1217 | if (buffer_info->skb) { |
| 1218 | bytes_compl += buffer_info->skb->len; |
| 1219 | pkts_compl++; |
| 1220 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1223 | e1000_put_txbuf(tx_ring, buffer_info); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1224 | tx_desc->upper.data = 0; |
| 1225 | |
| 1226 | i++; |
| 1227 | if (i == tx_ring->count) |
| 1228 | i = 0; |
| 1229 | } |
| 1230 | |
Terry Loftin | dac8761 | 2010-04-09 10:29:49 +0000 | [diff] [blame] | 1231 | if (i == tx_ring->next_to_use) |
| 1232 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1233 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1234 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | tx_ring->next_to_clean = i; |
| 1238 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1239 | netdev_completed_queue(netdev, pkts_compl, bytes_compl); |
| 1240 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1241 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1242 | if (count && netif_carrier_ok(netdev) && |
| 1243 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1244 | /* Make sure that anybody stopping the queue after this |
| 1245 | * sees the new next_to_clean. |
| 1246 | */ |
| 1247 | smp_mb(); |
| 1248 | |
| 1249 | if (netif_queue_stopped(netdev) && |
| 1250 | !(test_bit(__E1000_DOWN, &adapter->state))) { |
| 1251 | netif_wake_queue(netdev); |
| 1252 | ++adapter->restart_queue; |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | if (adapter->detect_tx_hung) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1257 | /* Detect a transmit hang in hardware, this serializes the |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1258 | * check with the clearing of time_stamp and movement of i |
| 1259 | */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1260 | adapter->detect_tx_hung = false; |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1261 | if (tx_ring->buffer_info[i].time_stamp && |
| 1262 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1263 | + (adapter->tx_timeout_factor * HZ)) && |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1264 | !(er32(STATUS) & E1000_STATUS_TXOFF)) |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1265 | schedule_work(&adapter->print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1266 | else |
| 1267 | adapter->tx_hang_recheck = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1268 | } |
| 1269 | adapter->total_tx_bytes += total_tx_bytes; |
| 1270 | adapter->total_tx_packets += total_tx_packets; |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1271 | return count < tx_ring->count; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1275 | * 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] | 1276 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1277 | * |
| 1278 | * the return value indicates whether actual cleaning was done, there |
| 1279 | * is no guarantee that everything was cleaned |
| 1280 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1281 | static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done, |
| 1282 | int work_to_do) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1283 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1284 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1285 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1286 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
| 1287 | struct net_device *netdev = adapter->netdev; |
| 1288 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1289 | struct e1000_buffer *buffer_info, *next_buffer; |
| 1290 | struct e1000_ps_page *ps_page; |
| 1291 | struct sk_buff *skb; |
| 1292 | unsigned int i, j; |
| 1293 | u32 length, staterr; |
| 1294 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1295 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1296 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 1297 | |
| 1298 | i = rx_ring->next_to_clean; |
| 1299 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 1300 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1301 | buffer_info = &rx_ring->buffer_info[i]; |
| 1302 | |
| 1303 | while (staterr & E1000_RXD_STAT_DD) { |
| 1304 | if (*work_done >= work_to_do) |
| 1305 | break; |
| 1306 | (*work_done)++; |
| 1307 | skb = buffer_info->skb; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1308 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1309 | |
| 1310 | /* in the packet split case this is header only */ |
| 1311 | prefetch(skb->data - NET_IP_ALIGN); |
| 1312 | |
| 1313 | i++; |
| 1314 | if (i == rx_ring->count) |
| 1315 | i = 0; |
| 1316 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
| 1317 | prefetch(next_rxd); |
| 1318 | |
| 1319 | next_buffer = &rx_ring->buffer_info[i]; |
| 1320 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1321 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1322 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1323 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1324 | adapter->rx_ps_bsize0, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1325 | buffer_info->dma = 0; |
| 1326 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1327 | /* see !EOP comment in other Rx routine */ |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1328 | if (!(staterr & E1000_RXD_STAT_EOP)) |
| 1329 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 1330 | |
| 1331 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1332 | 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] | 1333 | dev_kfree_skb_irq(skb); |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1334 | if (staterr & E1000_RXD_STAT_EOP) |
| 1335 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1336 | goto next_desc; |
| 1337 | } |
| 1338 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 1339 | if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 1340 | !(netdev->features & NETIF_F_RXALL))) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1341 | dev_kfree_skb_irq(skb); |
| 1342 | goto next_desc; |
| 1343 | } |
| 1344 | |
| 1345 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 1346 | |
| 1347 | if (!length) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1348 | e_dbg("Last part of the packet spanning multiple descriptors\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1349 | dev_kfree_skb_irq(skb); |
| 1350 | goto next_desc; |
| 1351 | } |
| 1352 | |
| 1353 | /* Good Receive */ |
| 1354 | skb_put(skb, length); |
| 1355 | |
| 1356 | { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1357 | /* this looks ugly, but it seems compiler issues make |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1358 | * it more efficient than reusing j |
| 1359 | */ |
| 1360 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1361 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1362 | /* page alloc/put takes too long and effects small |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1363 | * packet throughput, so unsplit small packets and |
| 1364 | * save the alloc/put only valid in softirq (napi) |
| 1365 | * context to call kmap_* |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1366 | */ |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1367 | if (l1 && (l1 <= copybreak) && |
| 1368 | ((length + l1) <= adapter->rx_ps_bsize0)) { |
| 1369 | u8 *vaddr; |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 1370 | |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1371 | ps_page = &buffer_info->ps_pages[0]; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1372 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1373 | /* there is no documentation about how to call |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1374 | * kmap_atomic, so we can't hold the mapping |
| 1375 | * very long |
| 1376 | */ |
| 1377 | dma_sync_single_for_cpu(&pdev->dev, |
| 1378 | ps_page->dma, |
| 1379 | PAGE_SIZE, |
| 1380 | DMA_FROM_DEVICE); |
Linus Torvalds | 9f39383 | 2012-03-21 09:40:26 -0700 | [diff] [blame] | 1381 | vaddr = kmap_atomic(ps_page->page); |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1382 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
Linus Torvalds | 9f39383 | 2012-03-21 09:40:26 -0700 | [diff] [blame] | 1383 | kunmap_atomic(vaddr); |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1384 | dma_sync_single_for_device(&pdev->dev, |
| 1385 | ps_page->dma, |
| 1386 | PAGE_SIZE, |
| 1387 | DMA_FROM_DEVICE); |
| 1388 | |
| 1389 | /* remove the CRC */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 1390 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 1391 | if (!(netdev->features & NETIF_F_RXFCS)) |
| 1392 | l1 -= 4; |
| 1393 | } |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1394 | |
| 1395 | skb_put(skb, l1); |
| 1396 | goto copydone; |
| 1397 | } /* if */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
| 1401 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); |
| 1402 | if (!length) |
| 1403 | break; |
| 1404 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1405 | ps_page = &buffer_info->ps_pages[j]; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1406 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1407 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1408 | ps_page->dma = 0; |
| 1409 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); |
| 1410 | ps_page->page = NULL; |
| 1411 | skb->len += length; |
| 1412 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1413 | skb->truesize += PAGE_SIZE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1416 | /* strip the ethernet crc, problem is we're using pages now so |
| 1417 | * this whole operation can get a little cpu intensive |
| 1418 | */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 1419 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 1420 | if (!(netdev->features & NETIF_F_RXFCS)) |
| 1421 | pskb_trim(skb, skb->len - 4); |
| 1422 | } |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1423 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1424 | copydone: |
| 1425 | total_rx_bytes += skb->len; |
| 1426 | total_rx_packets++; |
| 1427 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1428 | e1000_rx_checksum(adapter, staterr, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1429 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1430 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1431 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1432 | if (rx_desc->wb.upper.header_status & |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1433 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1434 | adapter->rx_hdr_split++; |
| 1435 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1436 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1437 | rx_desc->wb.middle.vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1438 | |
| 1439 | next_desc: |
| 1440 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
| 1441 | buffer_info->skb = NULL; |
| 1442 | |
| 1443 | /* return some buffers to hardware, one at a time is too slow */ |
| 1444 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1445 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1446 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1447 | cleaned_count = 0; |
| 1448 | } |
| 1449 | |
| 1450 | /* use prefetched values */ |
| 1451 | rx_desc = next_rxd; |
| 1452 | buffer_info = next_buffer; |
| 1453 | |
| 1454 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1455 | } |
| 1456 | rx_ring->next_to_clean = i; |
| 1457 | |
| 1458 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1459 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1460 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1461 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1462 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1463 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1464 | return cleaned; |
| 1465 | } |
| 1466 | |
| 1467 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1468 | * e1000_consume_page - helper function |
| 1469 | **/ |
| 1470 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
Bruce Allan | 66501f5 | 2013-02-20 04:05:55 +0000 | [diff] [blame] | 1471 | u16 length) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1472 | { |
| 1473 | bi->page = NULL; |
| 1474 | skb->len += length; |
| 1475 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1476 | skb->truesize += PAGE_SIZE; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | /** |
| 1480 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 1481 | * @adapter: board private structure |
| 1482 | * |
| 1483 | * the return value indicates whether actual cleaning was done, there |
| 1484 | * is no guarantee that everything was cleaned |
| 1485 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1486 | static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
| 1487 | int work_to_do) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1488 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1489 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1490 | struct net_device *netdev = adapter->netdev; |
| 1491 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1492 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1493 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1494 | u32 length, staterr; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1495 | unsigned int i; |
| 1496 | int cleaned_count = 0; |
| 1497 | bool cleaned = false; |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 1498 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1499 | struct skb_shared_info *shinfo; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1500 | |
| 1501 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1502 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 1503 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1504 | buffer_info = &rx_ring->buffer_info[i]; |
| 1505 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1506 | while (staterr & E1000_RXD_STAT_DD) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1507 | struct sk_buff *skb; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1508 | |
| 1509 | if (*work_done >= work_to_do) |
| 1510 | break; |
| 1511 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1512 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1513 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1514 | skb = buffer_info->skb; |
| 1515 | buffer_info->skb = NULL; |
| 1516 | |
| 1517 | ++i; |
| 1518 | if (i == rx_ring->count) |
| 1519 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1520 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1521 | prefetch(next_rxd); |
| 1522 | |
| 1523 | next_buffer = &rx_ring->buffer_info[i]; |
| 1524 | |
| 1525 | cleaned = true; |
| 1526 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1527 | dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE, |
| 1528 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1529 | buffer_info->dma = 0; |
| 1530 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1531 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1532 | |
| 1533 | /* errors is only valid for DD + EOP descriptors */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1534 | if (unlikely((staterr & E1000_RXD_STAT_EOP) && |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 1535 | ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 1536 | !(netdev->features & NETIF_F_RXALL)))) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1537 | /* recycle both page and skb */ |
| 1538 | buffer_info->skb = skb; |
| 1539 | /* an error means any chain goes out the window too */ |
| 1540 | if (rx_ring->rx_skb_top) |
| 1541 | dev_kfree_skb_irq(rx_ring->rx_skb_top); |
| 1542 | rx_ring->rx_skb_top = NULL; |
| 1543 | goto next_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Bruce Allan | f0f1a17 | 2010-12-11 05:53:32 +0000 | [diff] [blame] | 1546 | #define rxtop (rx_ring->rx_skb_top) |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1547 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1548 | /* this descriptor is only the beginning (or middle) */ |
| 1549 | if (!rxtop) { |
| 1550 | /* this is the beginning of a chain */ |
| 1551 | rxtop = skb; |
| 1552 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1553 | 0, length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1554 | } else { |
| 1555 | /* this is the middle of a chain */ |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1556 | shinfo = skb_shinfo(rxtop); |
| 1557 | skb_fill_page_desc(rxtop, shinfo->nr_frags, |
| 1558 | buffer_info->page, 0, |
| 1559 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1560 | /* re-use the skb, only consumed the page */ |
| 1561 | buffer_info->skb = skb; |
| 1562 | } |
| 1563 | e1000_consume_page(buffer_info, rxtop, length); |
| 1564 | goto next_desc; |
| 1565 | } else { |
| 1566 | if (rxtop) { |
| 1567 | /* end of the chain */ |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1568 | shinfo = skb_shinfo(rxtop); |
| 1569 | skb_fill_page_desc(rxtop, shinfo->nr_frags, |
| 1570 | buffer_info->page, 0, |
| 1571 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1572 | /* re-use the current skb, we only consumed the |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1573 | * page |
| 1574 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1575 | buffer_info->skb = skb; |
| 1576 | skb = rxtop; |
| 1577 | rxtop = NULL; |
| 1578 | e1000_consume_page(buffer_info, skb, length); |
| 1579 | } else { |
| 1580 | /* no chain, got EOP, this buf is the packet |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1581 | * copybreak to save the put_page/alloc_page |
| 1582 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1583 | if (length <= copybreak && |
| 1584 | skb_tailroom(skb) >= length) { |
| 1585 | u8 *vaddr; |
Cong Wang | 4679026 | 2011-11-25 23:14:23 +0800 | [diff] [blame] | 1586 | vaddr = kmap_atomic(buffer_info->page); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1587 | memcpy(skb_tail_pointer(skb), vaddr, |
| 1588 | length); |
Cong Wang | 4679026 | 2011-11-25 23:14:23 +0800 | [diff] [blame] | 1589 | kunmap_atomic(vaddr); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1590 | /* re-use the page, so don't erase |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1591 | * buffer_info->page |
| 1592 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1593 | skb_put(skb, length); |
| 1594 | } else { |
| 1595 | skb_fill_page_desc(skb, 0, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1596 | buffer_info->page, 0, |
| 1597 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1598 | e1000_consume_page(buffer_info, skb, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1599 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1600 | } |
| 1601 | } |
| 1602 | } |
| 1603 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1604 | /* Receive Checksum Offload */ |
| 1605 | e1000_rx_checksum(adapter, staterr, skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1606 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1607 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1608 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1609 | /* probably a little skewed due to removing CRC */ |
| 1610 | total_rx_bytes += skb->len; |
| 1611 | total_rx_packets++; |
| 1612 | |
| 1613 | /* eth type trans needs skb->data to point to something */ |
| 1614 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1615 | e_err("pskb_may_pull failed.\n"); |
Bruce Allan | ef5ab89 | 2011-02-10 08:17:21 +0000 | [diff] [blame] | 1616 | dev_kfree_skb_irq(skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1617 | goto next_desc; |
| 1618 | } |
| 1619 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1620 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1621 | rx_desc->wb.upper.vlan); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1622 | |
| 1623 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1624 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1625 | |
| 1626 | /* return some buffers to hardware, one at a time is too slow */ |
| 1627 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1628 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1629 | GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1630 | cleaned_count = 0; |
| 1631 | } |
| 1632 | |
| 1633 | /* use prefetched values */ |
| 1634 | rx_desc = next_rxd; |
| 1635 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1636 | |
| 1637 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1638 | } |
| 1639 | rx_ring->next_to_clean = i; |
| 1640 | |
| 1641 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1642 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1643 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1644 | |
| 1645 | adapter->total_rx_bytes += total_rx_bytes; |
| 1646 | adapter->total_rx_packets += total_rx_packets; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1647 | return cleaned; |
| 1648 | } |
| 1649 | |
| 1650 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1651 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1652 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1653 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1654 | static void e1000_clean_rx_ring(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1655 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1656 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1657 | struct e1000_buffer *buffer_info; |
| 1658 | struct e1000_ps_page *ps_page; |
| 1659 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1660 | unsigned int i, j; |
| 1661 | |
| 1662 | /* Free all the Rx ring sk_buffs */ |
| 1663 | for (i = 0; i < rx_ring->count; i++) { |
| 1664 | buffer_info = &rx_ring->buffer_info[i]; |
| 1665 | if (buffer_info->dma) { |
| 1666 | if (adapter->clean_rx == e1000_clean_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1667 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1668 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1669 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1670 | else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1671 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1672 | PAGE_SIZE, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1673 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1674 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1675 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1676 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1677 | buffer_info->dma = 0; |
| 1678 | } |
| 1679 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1680 | if (buffer_info->page) { |
| 1681 | put_page(buffer_info->page); |
| 1682 | buffer_info->page = NULL; |
| 1683 | } |
| 1684 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1685 | if (buffer_info->skb) { |
| 1686 | dev_kfree_skb(buffer_info->skb); |
| 1687 | buffer_info->skb = NULL; |
| 1688 | } |
| 1689 | |
| 1690 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1691 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1692 | if (!ps_page->page) |
| 1693 | break; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1694 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1695 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1696 | ps_page->dma = 0; |
| 1697 | put_page(ps_page->page); |
| 1698 | ps_page->page = NULL; |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | /* there also may be some cached data from a chained receive */ |
| 1703 | if (rx_ring->rx_skb_top) { |
| 1704 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 1705 | rx_ring->rx_skb_top = NULL; |
| 1706 | } |
| 1707 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1708 | /* Zero out the descriptor ring */ |
| 1709 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1710 | |
| 1711 | rx_ring->next_to_clean = 0; |
| 1712 | rx_ring->next_to_use = 0; |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1713 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1714 | |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1715 | writel(0, rx_ring->head); |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 1716 | if (rx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 1717 | e1000e_update_rdt_wa(rx_ring, 0); |
| 1718 | else |
| 1719 | writel(0, rx_ring->tail); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1722 | static void e1000e_downshift_workaround(struct work_struct *work) |
| 1723 | { |
| 1724 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1725 | struct e1000_adapter, |
| 1726 | downshift_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1727 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1728 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1729 | return; |
| 1730 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1731 | e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); |
| 1732 | } |
| 1733 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1734 | /** |
| 1735 | * e1000_intr_msi - Interrupt Handler |
| 1736 | * @irq: interrupt number |
| 1737 | * @data: pointer to a network interface device structure |
| 1738 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1739 | static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1740 | { |
| 1741 | struct net_device *netdev = data; |
| 1742 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1743 | struct e1000_hw *hw = &adapter->hw; |
| 1744 | u32 icr = er32(ICR); |
| 1745 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1746 | /* read ICR disables interrupts using IAM */ |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1747 | if (icr & E1000_ICR_LSC) { |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1748 | hw->mac.get_link_status = true; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1749 | /* ICH8 workaround-- Call gig speed drop workaround on cable |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1750 | * disconnect (LSC) before accessing any PHY registers |
| 1751 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1752 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1753 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1754 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1755 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1756 | /* 80003ES2LAN workaround-- For packet buffer work-around on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1757 | * link down event; disable receives here in the ISR and reset |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1758 | * adapter in watchdog |
| 1759 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1760 | if (netif_carrier_ok(netdev) && |
| 1761 | adapter->flags & FLAG_RX_NEEDS_RESTART) { |
| 1762 | /* disable receives */ |
| 1763 | u32 rctl = er32(RCTL); |
| 1764 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 1765 | adapter->flags |= FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1766 | } |
| 1767 | /* guard against interrupt when we're going down */ |
| 1768 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1769 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1770 | } |
| 1771 | |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1772 | /* Reset on uncorrectable ECC error */ |
| 1773 | if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) { |
| 1774 | u32 pbeccsts = er32(PBECCSTS); |
| 1775 | |
| 1776 | adapter->corr_errors += |
| 1777 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 1778 | adapter->uncorr_errors += |
| 1779 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 1780 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 1781 | |
| 1782 | /* Do the reset outside of interrupt context */ |
| 1783 | schedule_work(&adapter->reset_task); |
| 1784 | |
| 1785 | /* return immediately since reset is imminent */ |
| 1786 | return IRQ_HANDLED; |
| 1787 | } |
| 1788 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1789 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1790 | adapter->total_tx_bytes = 0; |
| 1791 | adapter->total_tx_packets = 0; |
| 1792 | adapter->total_rx_bytes = 0; |
| 1793 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1794 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | return IRQ_HANDLED; |
| 1798 | } |
| 1799 | |
| 1800 | /** |
| 1801 | * e1000_intr - Interrupt Handler |
| 1802 | * @irq: interrupt number |
| 1803 | * @data: pointer to a network interface device structure |
| 1804 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1805 | static irqreturn_t e1000_intr(int __always_unused irq, void *data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1806 | { |
| 1807 | struct net_device *netdev = data; |
| 1808 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1809 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1810 | u32 rctl, icr = er32(ICR); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1811 | |
Bruce Allan | a68ea77 | 2009-11-20 23:23:16 +0000 | [diff] [blame] | 1812 | if (!icr || test_bit(__E1000_DOWN, &adapter->state)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1813 | return IRQ_NONE; /* Not our interrupt */ |
| 1814 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1815 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1816 | * not set, then the adapter didn't send an interrupt |
| 1817 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1818 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 1819 | return IRQ_NONE; |
| 1820 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1821 | /* Interrupt Auto-Mask...upon reading ICR, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1822 | * interrupts are masked. No need for the |
| 1823 | * IMC write |
| 1824 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1825 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1826 | if (icr & E1000_ICR_LSC) { |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1827 | hw->mac.get_link_status = true; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1828 | /* ICH8 workaround-- Call gig speed drop workaround on cable |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1829 | * disconnect (LSC) before accessing any PHY registers |
| 1830 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1831 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1832 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1833 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1834 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1835 | /* 80003ES2LAN workaround-- |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1836 | * For packet buffer work-around on link down event; |
| 1837 | * disable receives here in the ISR and |
| 1838 | * reset adapter in watchdog |
| 1839 | */ |
| 1840 | if (netif_carrier_ok(netdev) && |
| 1841 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { |
| 1842 | /* disable receives */ |
| 1843 | rctl = er32(RCTL); |
| 1844 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 1845 | adapter->flags |= FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1846 | } |
| 1847 | /* guard against interrupt when we're going down */ |
| 1848 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1849 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1850 | } |
| 1851 | |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1852 | /* Reset on uncorrectable ECC error */ |
| 1853 | if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) { |
| 1854 | u32 pbeccsts = er32(PBECCSTS); |
| 1855 | |
| 1856 | adapter->corr_errors += |
| 1857 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 1858 | adapter->uncorr_errors += |
| 1859 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 1860 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 1861 | |
| 1862 | /* Do the reset outside of interrupt context */ |
| 1863 | schedule_work(&adapter->reset_task); |
| 1864 | |
| 1865 | /* return immediately since reset is imminent */ |
| 1866 | return IRQ_HANDLED; |
| 1867 | } |
| 1868 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1869 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1870 | adapter->total_tx_bytes = 0; |
| 1871 | adapter->total_tx_packets = 0; |
| 1872 | adapter->total_rx_bytes = 0; |
| 1873 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1874 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | return IRQ_HANDLED; |
| 1878 | } |
| 1879 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1880 | static irqreturn_t e1000_msix_other(int __always_unused irq, void *data) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1881 | { |
| 1882 | struct net_device *netdev = data; |
| 1883 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1884 | struct e1000_hw *hw = &adapter->hw; |
| 1885 | u32 icr = er32(ICR); |
| 1886 | |
| 1887 | if (!(icr & E1000_ICR_INT_ASSERTED)) { |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1888 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1889 | ew32(IMS, E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1890 | return IRQ_NONE; |
| 1891 | } |
| 1892 | |
| 1893 | if (icr & adapter->eiac_mask) |
| 1894 | ew32(ICS, (icr & adapter->eiac_mask)); |
| 1895 | |
| 1896 | if (icr & E1000_ICR_OTHER) { |
| 1897 | if (!(icr & E1000_ICR_LSC)) |
| 1898 | goto no_link_interrupt; |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1899 | hw->mac.get_link_status = true; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1900 | /* guard against interrupt when we're going down */ |
| 1901 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1902 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1903 | } |
| 1904 | |
| 1905 | no_link_interrupt: |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1906 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1907 | ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1908 | |
| 1909 | return IRQ_HANDLED; |
| 1910 | } |
| 1911 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1912 | static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1913 | { |
| 1914 | struct net_device *netdev = data; |
| 1915 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1916 | struct e1000_hw *hw = &adapter->hw; |
| 1917 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1918 | |
| 1919 | |
| 1920 | adapter->total_tx_bytes = 0; |
| 1921 | adapter->total_tx_packets = 0; |
| 1922 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1923 | if (!e1000_clean_tx_irq(tx_ring)) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1924 | /* Ring was not completely cleaned, so fire another interrupt */ |
| 1925 | ew32(ICS, tx_ring->ims_val); |
| 1926 | |
| 1927 | return IRQ_HANDLED; |
| 1928 | } |
| 1929 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1930 | static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1931 | { |
| 1932 | struct net_device *netdev = data; |
| 1933 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1934 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1935 | |
| 1936 | /* Write the ITR value calculated at the end of the |
| 1937 | * previous interrupt. |
| 1938 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1939 | if (rx_ring->set_itr) { |
| 1940 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1941 | rx_ring->itr_register); |
| 1942 | rx_ring->set_itr = 0; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1945 | if (napi_schedule_prep(&adapter->napi)) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1946 | adapter->total_rx_bytes = 0; |
| 1947 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1948 | __napi_schedule(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1949 | } |
| 1950 | return IRQ_HANDLED; |
| 1951 | } |
| 1952 | |
| 1953 | /** |
| 1954 | * e1000_configure_msix - Configure MSI-X hardware |
| 1955 | * |
| 1956 | * e1000_configure_msix sets up the hardware to properly |
| 1957 | * generate MSI-X interrupts. |
| 1958 | **/ |
| 1959 | static void e1000_configure_msix(struct e1000_adapter *adapter) |
| 1960 | { |
| 1961 | struct e1000_hw *hw = &adapter->hw; |
| 1962 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1963 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1964 | int vector = 0; |
| 1965 | u32 ctrl_ext, ivar = 0; |
| 1966 | |
| 1967 | adapter->eiac_mask = 0; |
| 1968 | |
| 1969 | /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ |
| 1970 | if (hw->mac.type == e1000_82574) { |
| 1971 | u32 rfctl = er32(RFCTL); |
| 1972 | rfctl |= E1000_RFCTL_ACK_DIS; |
| 1973 | ew32(RFCTL, rfctl); |
| 1974 | } |
| 1975 | |
| 1976 | #define E1000_IVAR_INT_ALLOC_VALID 0x8 |
| 1977 | /* Configure Rx vector */ |
| 1978 | rx_ring->ims_val = E1000_IMS_RXQ0; |
| 1979 | adapter->eiac_mask |= rx_ring->ims_val; |
| 1980 | if (rx_ring->itr_val) |
| 1981 | writel(1000000000 / (rx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1982 | rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1983 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1984 | writel(1, rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1985 | ivar = E1000_IVAR_INT_ALLOC_VALID | vector; |
| 1986 | |
| 1987 | /* Configure Tx vector */ |
| 1988 | tx_ring->ims_val = E1000_IMS_TXQ0; |
| 1989 | vector++; |
| 1990 | if (tx_ring->itr_val) |
| 1991 | writel(1000000000 / (tx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1992 | tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1993 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1994 | writel(1, tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1995 | adapter->eiac_mask |= tx_ring->ims_val; |
| 1996 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); |
| 1997 | |
| 1998 | /* set vector for Other Causes, e.g. link changes */ |
| 1999 | vector++; |
| 2000 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); |
| 2001 | if (rx_ring->itr_val) |
| 2002 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 2003 | hw->hw_addr + E1000_EITR_82574(vector)); |
| 2004 | else |
| 2005 | writel(1, hw->hw_addr + E1000_EITR_82574(vector)); |
| 2006 | |
| 2007 | /* Cause Tx interrupts on every write back */ |
| 2008 | ivar |= (1 << 31); |
| 2009 | |
| 2010 | ew32(IVAR, ivar); |
| 2011 | |
| 2012 | /* enable MSI-X PBA support */ |
| 2013 | ctrl_ext = er32(CTRL_EXT); |
| 2014 | ctrl_ext |= E1000_CTRL_EXT_PBA_CLR; |
| 2015 | |
| 2016 | /* Auto-Mask Other interrupts upon ICR read */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2017 | ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER); |
| 2018 | ctrl_ext |= E1000_CTRL_EXT_EIAME; |
| 2019 | ew32(CTRL_EXT, ctrl_ext); |
| 2020 | e1e_flush(); |
| 2021 | } |
| 2022 | |
| 2023 | void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) |
| 2024 | { |
| 2025 | if (adapter->msix_entries) { |
| 2026 | pci_disable_msix(adapter->pdev); |
| 2027 | kfree(adapter->msix_entries); |
| 2028 | adapter->msix_entries = NULL; |
| 2029 | } else if (adapter->flags & FLAG_MSI_ENABLED) { |
| 2030 | pci_disable_msi(adapter->pdev); |
| 2031 | adapter->flags &= ~FLAG_MSI_ENABLED; |
| 2032 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | /** |
| 2036 | * e1000e_set_interrupt_capability - set MSI or MSI-X if supported |
| 2037 | * |
| 2038 | * Attempt to configure interrupts using the best available |
| 2039 | * capabilities of the hardware and kernel. |
| 2040 | **/ |
| 2041 | void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) |
| 2042 | { |
| 2043 | int err; |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2044 | int i; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2045 | |
| 2046 | switch (adapter->int_mode) { |
| 2047 | case E1000E_INT_MODE_MSIX: |
| 2048 | if (adapter->flags & FLAG_HAS_MSIX) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2049 | adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */ |
| 2050 | adapter->msix_entries = kcalloc(adapter->num_vectors, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 2051 | sizeof(struct |
| 2052 | msix_entry), |
| 2053 | GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2054 | if (adapter->msix_entries) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2055 | for (i = 0; i < adapter->num_vectors; i++) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2056 | adapter->msix_entries[i].entry = i; |
| 2057 | |
| 2058 | err = pci_enable_msix(adapter->pdev, |
| 2059 | adapter->msix_entries, |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2060 | adapter->num_vectors); |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2061 | if (err == 0) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2062 | return; |
| 2063 | } |
| 2064 | /* MSI-X failed, so fall through and try MSI */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 2065 | 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] | 2066 | e1000e_reset_interrupt_capability(adapter); |
| 2067 | } |
| 2068 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 2069 | /* Fall through */ |
| 2070 | case E1000E_INT_MODE_MSI: |
| 2071 | if (!pci_enable_msi(adapter->pdev)) { |
| 2072 | adapter->flags |= FLAG_MSI_ENABLED; |
| 2073 | } else { |
| 2074 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 2075 | 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] | 2076 | } |
| 2077 | /* Fall through */ |
| 2078 | case E1000E_INT_MODE_LEGACY: |
| 2079 | /* Don't do anything; this is the system default */ |
| 2080 | break; |
| 2081 | } |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2082 | |
| 2083 | /* store the number of vectors being used */ |
| 2084 | adapter->num_vectors = 1; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | /** |
| 2088 | * e1000_request_msix - Initialize MSI-X interrupts |
| 2089 | * |
| 2090 | * e1000_request_msix allocates MSI-X vectors and requests interrupts from the |
| 2091 | * kernel. |
| 2092 | **/ |
| 2093 | static int e1000_request_msix(struct e1000_adapter *adapter) |
| 2094 | { |
| 2095 | struct net_device *netdev = adapter->netdev; |
| 2096 | int err = 0, vector = 0; |
| 2097 | |
| 2098 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 2099 | snprintf(adapter->rx_ring->name, |
| 2100 | sizeof(adapter->rx_ring->name) - 1, |
| 2101 | "%s-rx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2102 | else |
| 2103 | memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); |
| 2104 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2105 | e1000_intr_msix_rx, 0, adapter->rx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2106 | netdev); |
| 2107 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2108 | return err; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2109 | adapter->rx_ring->itr_register = adapter->hw.hw_addr + |
| 2110 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2111 | adapter->rx_ring->itr_val = adapter->itr; |
| 2112 | vector++; |
| 2113 | |
| 2114 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 2115 | snprintf(adapter->tx_ring->name, |
| 2116 | sizeof(adapter->tx_ring->name) - 1, |
| 2117 | "%s-tx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2118 | else |
| 2119 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); |
| 2120 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2121 | e1000_intr_msix_tx, 0, adapter->tx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2122 | netdev); |
| 2123 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2124 | return err; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2125 | adapter->tx_ring->itr_register = adapter->hw.hw_addr + |
| 2126 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2127 | adapter->tx_ring->itr_val = adapter->itr; |
| 2128 | vector++; |
| 2129 | |
| 2130 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2131 | e1000_msix_other, 0, netdev->name, netdev); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2132 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2133 | return err; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2134 | |
| 2135 | e1000_configure_msix(adapter); |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2136 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2137 | return 0; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2140 | /** |
| 2141 | * e1000_request_irq - initialize interrupts |
| 2142 | * |
| 2143 | * Attempts to configure interrupts using the best available |
| 2144 | * capabilities of the hardware and kernel. |
| 2145 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2146 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 2147 | { |
| 2148 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2149 | int err; |
| 2150 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2151 | if (adapter->msix_entries) { |
| 2152 | err = e1000_request_msix(adapter); |
| 2153 | if (!err) |
| 2154 | return err; |
| 2155 | /* fall back to MSI */ |
| 2156 | e1000e_reset_interrupt_capability(adapter); |
| 2157 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 2158 | e1000e_set_interrupt_capability(adapter); |
| 2159 | } |
| 2160 | if (adapter->flags & FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2161 | err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2162 | netdev->name, netdev); |
| 2163 | if (!err) |
| 2164 | return err; |
| 2165 | |
| 2166 | /* fall back to legacy interrupt */ |
| 2167 | e1000e_reset_interrupt_capability(adapter); |
| 2168 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2171 | err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2172 | netdev->name, netdev); |
| 2173 | if (err) |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2174 | e_err("Unable to allocate interrupt, Error: %d\n", err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2175 | |
| 2176 | return err; |
| 2177 | } |
| 2178 | |
| 2179 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 2180 | { |
| 2181 | struct net_device *netdev = adapter->netdev; |
| 2182 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2183 | if (adapter->msix_entries) { |
| 2184 | int vector = 0; |
| 2185 | |
| 2186 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2187 | vector++; |
| 2188 | |
| 2189 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2190 | vector++; |
| 2191 | |
| 2192 | /* Other Causes interrupt vector */ |
| 2193 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2194 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2195 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2196 | |
| 2197 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | /** |
| 2201 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 2202 | **/ |
| 2203 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
| 2204 | { |
| 2205 | struct e1000_hw *hw = &adapter->hw; |
| 2206 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2207 | ew32(IMC, ~0); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2208 | if (adapter->msix_entries) |
| 2209 | ew32(EIAC_82574, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2210 | e1e_flush(); |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2211 | |
| 2212 | if (adapter->msix_entries) { |
| 2213 | int i; |
| 2214 | for (i = 0; i < adapter->num_vectors; i++) |
| 2215 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2216 | } else { |
| 2217 | synchronize_irq(adapter->pdev->irq); |
| 2218 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | /** |
| 2222 | * e1000_irq_enable - Enable default interrupt generation settings |
| 2223 | **/ |
| 2224 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
| 2225 | { |
| 2226 | struct e1000_hw *hw = &adapter->hw; |
| 2227 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2228 | if (adapter->msix_entries) { |
| 2229 | ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); |
| 2230 | ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC); |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 2231 | } else if (hw->mac.type == e1000_pch_lpt) { |
| 2232 | ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2233 | } else { |
| 2234 | ew32(IMS, IMS_ENABLE_MASK); |
| 2235 | } |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 2236 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2240 | * 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] | 2241 | * @adapter: address of board private structure |
| 2242 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2243 | * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2244 | * For ASF and Pass Through versions of f/w this means that |
| 2245 | * the driver is loaded. For AMT version (only with 82573) |
| 2246 | * of the f/w this means that the network i/f is open. |
| 2247 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2248 | void e1000e_get_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2249 | { |
| 2250 | struct e1000_hw *hw = &adapter->hw; |
| 2251 | u32 ctrl_ext; |
| 2252 | u32 swsm; |
| 2253 | |
| 2254 | /* Let firmware know the driver has taken over */ |
| 2255 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2256 | swsm = er32(SWSM); |
| 2257 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
| 2258 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2259 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2260 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2261 | } |
| 2262 | } |
| 2263 | |
| 2264 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2265 | * 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] | 2266 | * @adapter: address of board private structure |
| 2267 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2268 | * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2269 | * For ASF and Pass Through versions of f/w this means that the |
| 2270 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 2271 | * of the f/w this means that the network i/f is closed. |
| 2272 | * |
| 2273 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2274 | void e1000e_release_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2275 | { |
| 2276 | struct e1000_hw *hw = &adapter->hw; |
| 2277 | u32 ctrl_ext; |
| 2278 | u32 swsm; |
| 2279 | |
| 2280 | /* Let firmware taken over control of h/w */ |
| 2281 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2282 | swsm = er32(SWSM); |
| 2283 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
| 2284 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2285 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2286 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2287 | } |
| 2288 | } |
| 2289 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2290 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 2291 | * e1000_alloc_ring_dma - allocate memory for a ring structure |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2292 | **/ |
| 2293 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, |
| 2294 | struct e1000_ring *ring) |
| 2295 | { |
| 2296 | struct pci_dev *pdev = adapter->pdev; |
| 2297 | |
| 2298 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, |
| 2299 | GFP_KERNEL); |
| 2300 | if (!ring->desc) |
| 2301 | return -ENOMEM; |
| 2302 | |
| 2303 | return 0; |
| 2304 | } |
| 2305 | |
| 2306 | /** |
| 2307 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2308 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2309 | * |
| 2310 | * Return 0 on success, negative on failure |
| 2311 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2312 | int e1000e_setup_tx_resources(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2313 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2314 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2315 | int err = -ENOMEM, size; |
| 2316 | |
| 2317 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2318 | tx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2319 | if (!tx_ring->buffer_info) |
| 2320 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2321 | |
| 2322 | /* round up to nearest 4K */ |
| 2323 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
| 2324 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2325 | |
| 2326 | err = e1000_alloc_ring_dma(adapter, tx_ring); |
| 2327 | if (err) |
| 2328 | goto err; |
| 2329 | |
| 2330 | tx_ring->next_to_use = 0; |
| 2331 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2332 | |
| 2333 | return 0; |
| 2334 | err: |
| 2335 | vfree(tx_ring->buffer_info); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 2336 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2337 | return err; |
| 2338 | } |
| 2339 | |
| 2340 | /** |
| 2341 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2342 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2343 | * |
| 2344 | * Returns 0 on success, negative on failure |
| 2345 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2346 | int e1000e_setup_rx_resources(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2347 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2348 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2349 | struct e1000_buffer *buffer_info; |
| 2350 | int i, size, desc_len, err = -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2351 | |
| 2352 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2353 | rx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2354 | if (!rx_ring->buffer_info) |
| 2355 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2356 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2357 | for (i = 0; i < rx_ring->count; i++) { |
| 2358 | buffer_info = &rx_ring->buffer_info[i]; |
| 2359 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, |
| 2360 | sizeof(struct e1000_ps_page), |
| 2361 | GFP_KERNEL); |
| 2362 | if (!buffer_info->ps_pages) |
| 2363 | goto err_pages; |
| 2364 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2365 | |
| 2366 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 2367 | |
| 2368 | /* Round up to nearest 4K */ |
| 2369 | rx_ring->size = rx_ring->count * desc_len; |
| 2370 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2371 | |
| 2372 | err = e1000_alloc_ring_dma(adapter, rx_ring); |
| 2373 | if (err) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2374 | goto err_pages; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2375 | |
| 2376 | rx_ring->next_to_clean = 0; |
| 2377 | rx_ring->next_to_use = 0; |
| 2378 | rx_ring->rx_skb_top = NULL; |
| 2379 | |
| 2380 | return 0; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2381 | |
| 2382 | err_pages: |
| 2383 | for (i = 0; i < rx_ring->count; i++) { |
| 2384 | buffer_info = &rx_ring->buffer_info[i]; |
| 2385 | kfree(buffer_info->ps_pages); |
| 2386 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2387 | err: |
| 2388 | vfree(rx_ring->buffer_info); |
Bruce Allan | e926244 | 2010-11-24 06:02:06 +0000 | [diff] [blame] | 2389 | e_err("Unable to allocate memory for the receive descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2390 | return err; |
| 2391 | } |
| 2392 | |
| 2393 | /** |
| 2394 | * e1000_clean_tx_ring - Free Tx Buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2395 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2396 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2397 | static void e1000_clean_tx_ring(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2398 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2399 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2400 | struct e1000_buffer *buffer_info; |
| 2401 | unsigned long size; |
| 2402 | unsigned int i; |
| 2403 | |
| 2404 | for (i = 0; i < tx_ring->count; i++) { |
| 2405 | buffer_info = &tx_ring->buffer_info[i]; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2406 | e1000_put_txbuf(tx_ring, buffer_info); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 2409 | netdev_reset_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2410 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2411 | memset(tx_ring->buffer_info, 0, size); |
| 2412 | |
| 2413 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2414 | |
| 2415 | tx_ring->next_to_use = 0; |
| 2416 | tx_ring->next_to_clean = 0; |
| 2417 | |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2418 | writel(0, tx_ring->head); |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 2419 | if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 2420 | e1000e_update_tdt_wa(tx_ring, 0); |
| 2421 | else |
| 2422 | writel(0, tx_ring->tail); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | /** |
| 2426 | * e1000e_free_tx_resources - Free Tx Resources per Queue |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2427 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2428 | * |
| 2429 | * Free all transmit software resources |
| 2430 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2431 | void e1000e_free_tx_resources(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2432 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2433 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2434 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2435 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2436 | e1000_clean_tx_ring(tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2437 | |
| 2438 | vfree(tx_ring->buffer_info); |
| 2439 | tx_ring->buffer_info = NULL; |
| 2440 | |
| 2441 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 2442 | tx_ring->dma); |
| 2443 | tx_ring->desc = NULL; |
| 2444 | } |
| 2445 | |
| 2446 | /** |
| 2447 | * e1000e_free_rx_resources - Free Rx Resources |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2448 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2449 | * |
| 2450 | * Free all receive software resources |
| 2451 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2452 | void e1000e_free_rx_resources(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2453 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2454 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2455 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2456 | int i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2457 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2458 | e1000_clean_rx_ring(rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2459 | |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2460 | for (i = 0; i < rx_ring->count; i++) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2461 | kfree(rx_ring->buffer_info[i].ps_pages); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2462 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2463 | vfree(rx_ring->buffer_info); |
| 2464 | rx_ring->buffer_info = NULL; |
| 2465 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2466 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 2467 | rx_ring->dma); |
| 2468 | rx_ring->desc = NULL; |
| 2469 | } |
| 2470 | |
| 2471 | /** |
| 2472 | * e1000_update_itr - update the dynamic ITR value based on statistics |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2473 | * @adapter: pointer to adapter |
| 2474 | * @itr_setting: current adapter->itr |
| 2475 | * @packets: the number of packets during this measurement interval |
| 2476 | * @bytes: the number of bytes during this measurement interval |
| 2477 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2478 | * Stores a new ITR value based on packets and byte |
| 2479 | * counts during the last interrupt. The advantage of per interrupt |
| 2480 | * computation is faster updates and more accurate ITR for the current |
| 2481 | * traffic pattern. Constants in this function were computed |
| 2482 | * based on theoretical maximum wire speed and thresholds were set based |
| 2483 | * on testing data as well as attempting to minimize response time |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2484 | * while increasing bulk throughput. This functionality is controlled |
| 2485 | * by the InterruptThrottleRate module parameter. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2486 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2487 | static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2488 | { |
| 2489 | unsigned int retval = itr_setting; |
| 2490 | |
| 2491 | if (packets == 0) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2492 | return itr_setting; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2493 | |
| 2494 | switch (itr_setting) { |
| 2495 | case lowest_latency: |
| 2496 | /* handle TSO and jumbo frames */ |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2497 | if (bytes / packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2498 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2499 | else if ((packets < 5) && (bytes > 512)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2500 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2501 | break; |
| 2502 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2503 | if (bytes > 10000) { |
| 2504 | /* this if handles the TSO accounting */ |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2505 | if (bytes / packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2506 | retval = bulk_latency; |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2507 | else if ((packets < 10) || ((bytes / packets) > 1200)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2508 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2509 | else if ((packets > 35)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2510 | retval = lowest_latency; |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2511 | } else if (bytes / packets > 2000) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2512 | retval = bulk_latency; |
| 2513 | } else if (packets <= 2 && bytes < 512) { |
| 2514 | retval = lowest_latency; |
| 2515 | } |
| 2516 | break; |
| 2517 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2518 | if (bytes > 25000) { |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2519 | if (packets > 35) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2520 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2521 | } else if (bytes < 6000) { |
| 2522 | retval = low_latency; |
| 2523 | } |
| 2524 | break; |
| 2525 | } |
| 2526 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2527 | return retval; |
| 2528 | } |
| 2529 | |
| 2530 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2531 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2532 | u16 current_itr; |
| 2533 | u32 new_itr = adapter->itr; |
| 2534 | |
| 2535 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2536 | if (adapter->link_speed != SPEED_1000) { |
| 2537 | current_itr = 0; |
| 2538 | new_itr = 4000; |
| 2539 | goto set_itr_now; |
| 2540 | } |
| 2541 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2542 | if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 2543 | new_itr = 0; |
| 2544 | goto set_itr_now; |
| 2545 | } |
| 2546 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2547 | adapter->tx_itr = e1000_update_itr(adapter->tx_itr, |
| 2548 | adapter->total_tx_packets, |
| 2549 | adapter->total_tx_bytes); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2550 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2551 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2552 | adapter->tx_itr = low_latency; |
| 2553 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2554 | adapter->rx_itr = e1000_update_itr(adapter->rx_itr, |
| 2555 | adapter->total_rx_packets, |
| 2556 | adapter->total_rx_bytes); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2557 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2558 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2559 | adapter->rx_itr = low_latency; |
| 2560 | |
| 2561 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2562 | |
| 2563 | switch (current_itr) { |
| 2564 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2565 | case lowest_latency: |
| 2566 | new_itr = 70000; |
| 2567 | break; |
| 2568 | case low_latency: |
| 2569 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2570 | break; |
| 2571 | case bulk_latency: |
| 2572 | new_itr = 4000; |
| 2573 | break; |
| 2574 | default: |
| 2575 | break; |
| 2576 | } |
| 2577 | |
| 2578 | set_itr_now: |
| 2579 | if (new_itr != adapter->itr) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2580 | /* this attempts to bias the interrupt rate towards Bulk |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2581 | * by adding intermediate steps when interrupt rate is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2582 | * increasing |
| 2583 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2584 | new_itr = new_itr > adapter->itr ? |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 2585 | min(adapter->itr + (new_itr >> 2), new_itr) : new_itr; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2586 | adapter->itr = new_itr; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2587 | adapter->rx_ring->itr_val = new_itr; |
| 2588 | if (adapter->msix_entries) |
| 2589 | adapter->rx_ring->set_itr = 1; |
| 2590 | else |
Bruce Allan | e3d14b0 | 2012-12-05 06:26:51 +0000 | [diff] [blame] | 2591 | e1000e_write_itr(adapter, new_itr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2592 | } |
| 2593 | } |
| 2594 | |
| 2595 | /** |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 2596 | * e1000e_write_itr - write the ITR value to the appropriate registers |
| 2597 | * @adapter: address of board private structure |
| 2598 | * @itr: new ITR value to program |
| 2599 | * |
| 2600 | * e1000e_write_itr determines if the adapter is in MSI-X mode |
| 2601 | * and, if so, writes the EITR registers with the ITR value. |
| 2602 | * Otherwise, it writes the ITR value into the ITR register. |
| 2603 | **/ |
| 2604 | void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr) |
| 2605 | { |
| 2606 | struct e1000_hw *hw = &adapter->hw; |
| 2607 | u32 new_itr = itr ? 1000000000 / (itr * 256) : 0; |
| 2608 | |
| 2609 | if (adapter->msix_entries) { |
| 2610 | int vector; |
| 2611 | |
| 2612 | for (vector = 0; vector < adapter->num_vectors; vector++) |
| 2613 | writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector)); |
| 2614 | } else { |
| 2615 | ew32(ITR, new_itr); |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | /** |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2620 | * e1000_alloc_queues - Allocate memory for all rings |
| 2621 | * @adapter: board private structure to initialize |
| 2622 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 2623 | static int e1000_alloc_queues(struct e1000_adapter *adapter) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2624 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2625 | int size = sizeof(struct e1000_ring); |
| 2626 | |
| 2627 | adapter->tx_ring = kzalloc(size, GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2628 | if (!adapter->tx_ring) |
| 2629 | goto err; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2630 | adapter->tx_ring->count = adapter->tx_ring_count; |
| 2631 | adapter->tx_ring->adapter = adapter; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2632 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2633 | adapter->rx_ring = kzalloc(size, GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2634 | if (!adapter->rx_ring) |
| 2635 | goto err; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2636 | adapter->rx_ring->count = adapter->rx_ring_count; |
| 2637 | adapter->rx_ring->adapter = adapter; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2638 | |
| 2639 | return 0; |
| 2640 | err: |
| 2641 | e_err("Unable to allocate memory for queues\n"); |
| 2642 | kfree(adapter->rx_ring); |
| 2643 | kfree(adapter->tx_ring); |
| 2644 | return -ENOMEM; |
| 2645 | } |
| 2646 | |
| 2647 | /** |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2648 | * e1000e_poll - NAPI Rx polling callback |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2649 | * @napi: struct associated with this polling callback |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2650 | * @weight: number of packets driver is allowed to process this poll |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2651 | **/ |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2652 | static int e1000e_poll(struct napi_struct *napi, int weight) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2653 | { |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2654 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, |
| 2655 | napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2656 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2657 | struct net_device *poll_dev = adapter->netdev; |
Andy Gospodarek | 679e8a0 | 2009-06-18 11:57:37 +0000 | [diff] [blame] | 2658 | int tx_cleaned = 1, work_done = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2659 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 2660 | adapter = netdev_priv(poll_dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2661 | |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2662 | if (!adapter->msix_entries || |
| 2663 | (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) |
| 2664 | tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2665 | |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2666 | adapter->clean_rx(adapter->rx_ring, &work_done, weight); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2667 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 2668 | if (!tx_cleaned) |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2669 | work_done = weight; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2670 | |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2671 | /* If weight not fully consumed, exit the polling mode */ |
| 2672 | if (work_done < weight) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2673 | if (adapter->itr_setting & 3) |
| 2674 | e1000_set_itr(adapter); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2675 | napi_complete(napi); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 2676 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 2677 | if (adapter->msix_entries) |
| 2678 | ew32(IMS, adapter->rx_ring->ims_val); |
| 2679 | else |
| 2680 | e1000_irq_enable(adapter); |
| 2681 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | return work_done; |
| 2685 | } |
| 2686 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2687 | 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] | 2688 | { |
| 2689 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2690 | struct e1000_hw *hw = &adapter->hw; |
| 2691 | u32 vfta, index; |
| 2692 | |
| 2693 | /* don't update vlan cookie if already programmed */ |
| 2694 | if ((adapter->hw.mng_cookie.status & |
| 2695 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2696 | (vid == adapter->mng_vlan_id)) |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2697 | return 0; |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2698 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2699 | /* add VID to filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2700 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2701 | index = (vid >> 5) & 0x7F; |
| 2702 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2703 | vfta |= (1 << (vid & 0x1F)); |
| 2704 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2705 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2706 | |
| 2707 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2708 | |
| 2709 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2710 | } |
| 2711 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2712 | 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] | 2713 | { |
| 2714 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2715 | struct e1000_hw *hw = &adapter->hw; |
| 2716 | u32 vfta, index; |
| 2717 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2718 | if ((adapter->hw.mng_cookie.status & |
| 2719 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2720 | (vid == adapter->mng_vlan_id)) { |
| 2721 | /* release control to f/w */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2722 | e1000e_release_hw_control(adapter); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2723 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | /* remove VID from filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2727 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2728 | index = (vid >> 5) & 0x7F; |
| 2729 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2730 | vfta &= ~(1 << (vid & 0x1F)); |
| 2731 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2732 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2733 | |
| 2734 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2735 | |
| 2736 | return 0; |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | /** |
| 2740 | * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering |
| 2741 | * @adapter: board private structure to initialize |
| 2742 | **/ |
| 2743 | static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter) |
| 2744 | { |
| 2745 | struct net_device *netdev = adapter->netdev; |
| 2746 | struct e1000_hw *hw = &adapter->hw; |
| 2747 | u32 rctl; |
| 2748 | |
| 2749 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2750 | /* disable VLAN receive filtering */ |
| 2751 | rctl = er32(RCTL); |
| 2752 | rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN); |
| 2753 | ew32(RCTL, rctl); |
| 2754 | |
| 2755 | if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { |
| 2756 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 2757 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 2758 | } |
| 2759 | } |
| 2760 | } |
| 2761 | |
| 2762 | /** |
| 2763 | * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering |
| 2764 | * @adapter: board private structure to initialize |
| 2765 | **/ |
| 2766 | static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter) |
| 2767 | { |
| 2768 | struct e1000_hw *hw = &adapter->hw; |
| 2769 | u32 rctl; |
| 2770 | |
| 2771 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2772 | /* enable VLAN receive filtering */ |
| 2773 | rctl = er32(RCTL); |
| 2774 | rctl |= E1000_RCTL_VFE; |
| 2775 | rctl &= ~E1000_RCTL_CFIEN; |
| 2776 | ew32(RCTL, rctl); |
| 2777 | } |
| 2778 | } |
| 2779 | |
| 2780 | /** |
| 2781 | * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping |
| 2782 | * @adapter: board private structure to initialize |
| 2783 | **/ |
| 2784 | static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter) |
| 2785 | { |
| 2786 | struct e1000_hw *hw = &adapter->hw; |
| 2787 | u32 ctrl; |
| 2788 | |
| 2789 | /* disable VLAN tag insert/strip */ |
| 2790 | ctrl = er32(CTRL); |
| 2791 | ctrl &= ~E1000_CTRL_VME; |
| 2792 | ew32(CTRL, ctrl); |
| 2793 | } |
| 2794 | |
| 2795 | /** |
| 2796 | * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping |
| 2797 | * @adapter: board private structure to initialize |
| 2798 | **/ |
| 2799 | static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter) |
| 2800 | { |
| 2801 | struct e1000_hw *hw = &adapter->hw; |
| 2802 | u32 ctrl; |
| 2803 | |
| 2804 | /* enable VLAN tag insert/strip */ |
| 2805 | ctrl = er32(CTRL); |
| 2806 | ctrl |= E1000_CTRL_VME; |
| 2807 | ew32(CTRL, ctrl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 2811 | { |
| 2812 | struct net_device *netdev = adapter->netdev; |
| 2813 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 2814 | u16 old_vid = adapter->mng_vlan_id; |
| 2815 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2816 | if (adapter->hw.mng_cookie.status & |
| 2817 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
| 2818 | e1000_vlan_rx_add_vid(netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2819 | adapter->mng_vlan_id = vid; |
| 2820 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2821 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2822 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid)) |
| 2823 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
| 2827 | { |
| 2828 | u16 vid; |
| 2829 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2830 | e1000_vlan_rx_add_vid(adapter->netdev, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2831 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2832 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 2833 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2836 | static void e1000_init_manageability_pt(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2837 | { |
| 2838 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2839 | u32 manc, manc2h, mdef, i, j; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2840 | |
| 2841 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) |
| 2842 | return; |
| 2843 | |
| 2844 | manc = er32(MANC); |
| 2845 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2846 | /* enable receiving management packets to the host. this will probably |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2847 | * generate destination unreachable messages from the host OS, but |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2848 | * the packets will be handled on SMBUS |
| 2849 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2850 | manc |= E1000_MANC_EN_MNG2HOST; |
| 2851 | manc2h = er32(MANC2H); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2852 | |
| 2853 | switch (hw->mac.type) { |
| 2854 | default: |
| 2855 | manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664); |
| 2856 | break; |
| 2857 | case e1000_82574: |
| 2858 | case e1000_82583: |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2859 | /* Check if IPMI pass-through decision filter already exists; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2860 | * if so, enable it. |
| 2861 | */ |
| 2862 | for (i = 0, j = 0; i < 8; i++) { |
| 2863 | mdef = er32(MDEF(i)); |
| 2864 | |
| 2865 | /* Ignore filters with anything other than IPMI ports */ |
Dan Carpenter | 3b21b50 | 2010-06-02 13:43:15 +0000 | [diff] [blame] | 2866 | if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2867 | continue; |
| 2868 | |
| 2869 | /* Enable this decision filter in MANC2H */ |
| 2870 | if (mdef) |
| 2871 | manc2h |= (1 << i); |
| 2872 | |
| 2873 | j |= mdef; |
| 2874 | } |
| 2875 | |
| 2876 | if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
| 2877 | break; |
| 2878 | |
| 2879 | /* Create new decision filter in an empty filter */ |
| 2880 | for (i = 0, j = 0; i < 8; i++) |
| 2881 | if (er32(MDEF(i)) == 0) { |
| 2882 | ew32(MDEF(i), (E1000_MDEF_PORT_623 | |
| 2883 | E1000_MDEF_PORT_664)); |
| 2884 | manc2h |= (1 << 1); |
| 2885 | j++; |
| 2886 | break; |
| 2887 | } |
| 2888 | |
| 2889 | if (!j) |
| 2890 | e_warn("Unable to create IPMI pass-through filter\n"); |
| 2891 | break; |
| 2892 | } |
| 2893 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2894 | ew32(MANC2H, manc2h); |
| 2895 | ew32(MANC, manc); |
| 2896 | } |
| 2897 | |
| 2898 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2899 | * e1000_configure_tx - Configure Transmit Unit after Reset |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2900 | * @adapter: board private structure |
| 2901 | * |
| 2902 | * Configure the Tx unit of the MAC after a reset. |
| 2903 | **/ |
| 2904 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
| 2905 | { |
| 2906 | struct e1000_hw *hw = &adapter->hw; |
| 2907 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2908 | u64 tdba; |
Bruce Allan | c550b12 | 2011-12-16 00:46:17 +0000 | [diff] [blame] | 2909 | u32 tdlen, tarc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2910 | |
| 2911 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 2912 | tdba = tx_ring->dma; |
| 2913 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 2914 | ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32))); |
| 2915 | ew32(TDBAH(0), (tdba >> 32)); |
| 2916 | ew32(TDLEN(0), tdlen); |
| 2917 | ew32(TDH(0), 0); |
| 2918 | ew32(TDT(0), 0); |
| 2919 | tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0); |
| 2920 | tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2921 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2922 | /* Set the Tx Interrupt Delay register */ |
| 2923 | ew32(TIDV, adapter->tx_int_delay); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2924 | /* Tx irq moderation */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2925 | ew32(TADV, adapter->tx_abs_int_delay); |
| 2926 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2927 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 2928 | u32 txdctl = er32(TXDCTL(0)); |
| 2929 | txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH | |
| 2930 | E1000_TXDCTL_WTHRESH); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2931 | /* set up some performance related parameters to encourage the |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2932 | * hardware to use the bus more efficiently in bursts, depends |
| 2933 | * on the tx_int_delay to be enabled, |
Hiroaki SHIMODA | 8edc0e6 | 2012-10-10 15:34:20 +0000 | [diff] [blame] | 2934 | * wthresh = 1 ==> burst write is disabled to avoid Tx stalls |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2935 | * hthresh = 1 ==> prefetch when one or more available |
| 2936 | * pthresh = 0x1f ==> prefetch if internal cache 31 or less |
| 2937 | * BEWARE: this seems to work but should be considered first if |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2938 | * there are Tx hangs or other Tx related bugs |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2939 | */ |
| 2940 | txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE; |
| 2941 | ew32(TXDCTL(0), txdctl); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2942 | } |
Bruce Allan | 56032be | 2011-12-16 00:46:01 +0000 | [diff] [blame] | 2943 | /* erratum work around: set txdctl the same for both queues */ |
| 2944 | ew32(TXDCTL(1), er32(TXDCTL(0))); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2945 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2946 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2947 | tarc = er32(TARC(0)); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2948 | /* set the speed mode bit, we'll clear it if we're not at |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2949 | * gigabit link later |
| 2950 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2951 | #define SPEED_MODE_BIT (1 << 21) |
| 2952 | tarc |= SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2953 | ew32(TARC(0), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | /* errata: program both queues to unweighted RR */ |
| 2957 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2958 | tarc = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2959 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2960 | ew32(TARC(0), tarc); |
| 2961 | tarc = er32(TARC(1)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2962 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2963 | ew32(TARC(1), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2964 | } |
| 2965 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2966 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 2967 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 2968 | |
| 2969 | /* only set IDE if we are delaying interrupts using the timers */ |
| 2970 | if (adapter->tx_int_delay) |
| 2971 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
| 2972 | |
| 2973 | /* enable Report Status bit */ |
| 2974 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 2975 | |
Bruce Allan | 57cde76 | 2012-02-22 09:02:58 +0000 | [diff] [blame] | 2976 | hw->mac.ops.config_collision_dist(hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | /** |
| 2980 | * e1000_setup_rctl - configure the receive control registers |
| 2981 | * @adapter: Board private structure |
| 2982 | **/ |
| 2983 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 2984 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
| 2985 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
| 2986 | { |
| 2987 | struct e1000_hw *hw = &adapter->hw; |
| 2988 | u32 rctl, rfctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2989 | u32 pages = 0; |
| 2990 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 2991 | /* Workaround Si errata on PCHx - configure jumbo frame flow */ |
| 2992 | if (hw->mac.type >= e1000_pch2lan) { |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 2993 | s32 ret_val; |
| 2994 | |
| 2995 | if (adapter->netdev->mtu > ETH_DATA_LEN) |
| 2996 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true); |
| 2997 | else |
| 2998 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false); |
Bruce Allan | dd93f95 | 2011-01-06 14:29:48 +0000 | [diff] [blame] | 2999 | |
| 3000 | if (ret_val) |
| 3001 | e_dbg("failed to enable jumbo frame workaround mode\n"); |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 3002 | } |
| 3003 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3004 | /* Program MC offset vector base */ |
| 3005 | rctl = er32(RCTL); |
| 3006 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 3007 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 3008 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 3009 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3010 | |
| 3011 | /* Do not Store bad packets */ |
| 3012 | rctl &= ~E1000_RCTL_SBP; |
| 3013 | |
| 3014 | /* Enable Long Packet receive */ |
| 3015 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 3016 | rctl &= ~E1000_RCTL_LPE; |
| 3017 | else |
| 3018 | rctl |= E1000_RCTL_LPE; |
| 3019 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 3020 | /* Some systems expect that the CRC is included in SMBUS traffic. The |
| 3021 | * hardware strips the CRC before sending to both SMBUS (BMC) and to |
| 3022 | * host memory when this is enabled |
| 3023 | */ |
| 3024 | if (adapter->flags2 & FLAG2_CRC_STRIPPING) |
| 3025 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 5918bd8 | 2008-02-12 15:20:24 -0800 | [diff] [blame] | 3026 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3027 | /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ |
| 3028 | if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { |
| 3029 | u16 phy_data; |
| 3030 | |
| 3031 | e1e_rphy(hw, PHY_REG(770, 26), &phy_data); |
| 3032 | phy_data &= 0xfff8; |
| 3033 | phy_data |= (1 << 2); |
| 3034 | e1e_wphy(hw, PHY_REG(770, 26), phy_data); |
| 3035 | |
| 3036 | e1e_rphy(hw, 22, &phy_data); |
| 3037 | phy_data &= 0x0fff; |
| 3038 | phy_data |= (1 << 14); |
| 3039 | e1e_wphy(hw, 0x10, 0x2823); |
| 3040 | e1e_wphy(hw, 0x11, 0x0003); |
| 3041 | e1e_wphy(hw, 22, phy_data); |
| 3042 | } |
| 3043 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3044 | /* Setup buffer sizes */ |
| 3045 | rctl &= ~E1000_RCTL_SZ_4096; |
| 3046 | rctl |= E1000_RCTL_BSEX; |
| 3047 | switch (adapter->rx_buffer_len) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3048 | case 2048: |
| 3049 | default: |
| 3050 | rctl |= E1000_RCTL_SZ_2048; |
| 3051 | rctl &= ~E1000_RCTL_BSEX; |
| 3052 | break; |
| 3053 | case 4096: |
| 3054 | rctl |= E1000_RCTL_SZ_4096; |
| 3055 | break; |
| 3056 | case 8192: |
| 3057 | rctl |= E1000_RCTL_SZ_8192; |
| 3058 | break; |
| 3059 | case 16384: |
| 3060 | rctl |= E1000_RCTL_SZ_16384; |
| 3061 | break; |
| 3062 | } |
| 3063 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3064 | /* Enable Extended Status in all Receive Descriptors */ |
| 3065 | rfctl = er32(RFCTL); |
| 3066 | rfctl |= E1000_RFCTL_EXTEN; |
Matthew Vick | f6bd557 | 2012-04-25 08:01:05 +0000 | [diff] [blame] | 3067 | ew32(RFCTL, rfctl); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3068 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3069 | /* 82571 and greater support packet-split where the protocol |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3070 | * header is placed in skb->data and the packet data is |
| 3071 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 3072 | * In the case of a non-split, skb->data is linearly filled, |
| 3073 | * followed by the page buffers. Therefore, skb->data is |
| 3074 | * sized to hold the largest protocol header. |
| 3075 | * |
| 3076 | * allocations using alloc_page take too long for regular MTU |
| 3077 | * so only enable packet split for jumbo frames |
| 3078 | * |
| 3079 | * Using pages when the page size is greater than 16k wastes |
| 3080 | * a lot of memory, since we allocate 3 pages at all times |
| 3081 | * per packet. |
| 3082 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3083 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3084 | if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3085 | adapter->rx_ps_pages = pages; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3086 | else |
| 3087 | adapter->rx_ps_pages = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3088 | |
| 3089 | if (adapter->rx_ps_pages) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 3090 | u32 psrctl = 0; |
| 3091 | |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 3092 | /* Enable Packet split descriptors */ |
| 3093 | rctl |= E1000_RCTL_DTYP_PS; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3094 | |
| 3095 | psrctl |= adapter->rx_ps_bsize0 >> |
| 3096 | E1000_PSRCTL_BSIZE0_SHIFT; |
| 3097 | |
| 3098 | switch (adapter->rx_ps_pages) { |
| 3099 | case 3: |
| 3100 | psrctl |= PAGE_SIZE << |
| 3101 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 3102 | case 2: |
| 3103 | psrctl |= PAGE_SIZE << |
| 3104 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 3105 | case 1: |
| 3106 | psrctl |= PAGE_SIZE >> |
| 3107 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 3108 | break; |
| 3109 | } |
| 3110 | |
| 3111 | ew32(PSRCTL, psrctl); |
| 3112 | } |
| 3113 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 3114 | /* This is useful for sniffing bad packets. */ |
| 3115 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 3116 | /* UPE and MPE will be handled by normal PROMISC logic |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3117 | * in e1000e_set_rx_mode |
| 3118 | */ |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 3119 | rctl |= (E1000_RCTL_SBP | /* Receive bad packets */ |
| 3120 | E1000_RCTL_BAM | /* RX All Bcast Pkts */ |
| 3121 | E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 3122 | |
| 3123 | rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */ |
| 3124 | E1000_RCTL_DPF | /* Allow filtered pause */ |
| 3125 | E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */ |
| 3126 | /* Do not mess with E1000_CTRL_VME, it affects transmit as well, |
| 3127 | * and that breaks VLANs. |
| 3128 | */ |
| 3129 | } |
| 3130 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3131 | ew32(RCTL, rctl); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3132 | /* just started the receive unit, no need to restart */ |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 3133 | adapter->flags &= ~FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | /** |
| 3137 | * e1000_configure_rx - Configure Receive Unit after Reset |
| 3138 | * @adapter: board private structure |
| 3139 | * |
| 3140 | * Configure the Rx unit of the MAC after a reset. |
| 3141 | **/ |
| 3142 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
| 3143 | { |
| 3144 | struct e1000_hw *hw = &adapter->hw; |
| 3145 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 3146 | u64 rdba; |
| 3147 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
| 3148 | |
| 3149 | if (adapter->rx_ps_pages) { |
| 3150 | /* this is a 32 byte descriptor */ |
| 3151 | rdlen = rx_ring->count * |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3152 | sizeof(union e1000_rx_desc_packet_split); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3153 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 3154 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3155 | } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3156 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3157 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 3158 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3159 | } else { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3160 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3161 | adapter->clean_rx = e1000_clean_rx_irq; |
| 3162 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 3163 | } |
| 3164 | |
| 3165 | /* disable receives while setting up the descriptors */ |
| 3166 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3167 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3168 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3169 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3170 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3171 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3172 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3173 | /* set the writeback threshold (only takes effect if the RDTR |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3174 | * 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] | 3175 | * enable prefetching of 0x20 Rx descriptors |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3176 | * granularity = 01 |
| 3177 | * wthresh = 04, |
| 3178 | * hthresh = 04, |
| 3179 | * pthresh = 0x20 |
| 3180 | */ |
| 3181 | ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3182 | ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3183 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3184 | /* override the delay timers for enabling bursting, only if |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3185 | * the value was not set by the user via module options |
| 3186 | */ |
| 3187 | if (adapter->rx_int_delay == DEFAULT_RDTR) |
| 3188 | adapter->rx_int_delay = BURST_RDTR; |
| 3189 | if (adapter->rx_abs_int_delay == DEFAULT_RADV) |
| 3190 | adapter->rx_abs_int_delay = BURST_RADV; |
| 3191 | } |
| 3192 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3193 | /* set the Receive Delay Timer Register */ |
| 3194 | ew32(RDTR, adapter->rx_int_delay); |
| 3195 | |
| 3196 | /* irq moderation */ |
| 3197 | ew32(RADV, adapter->rx_abs_int_delay); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3198 | if ((adapter->itr_setting != 0) && (adapter->itr != 0)) |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 3199 | e1000e_write_itr(adapter, adapter->itr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3200 | |
| 3201 | ctrl_ext = er32(CTRL_EXT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3202 | /* Auto-Mask interrupts upon ICR access */ |
| 3203 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 3204 | ew32(IAM, 0xffffffff); |
| 3205 | ew32(CTRL_EXT, ctrl_ext); |
| 3206 | e1e_flush(); |
| 3207 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3208 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3209 | * the Base and Length of the Rx Descriptor Ring |
| 3210 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3211 | rdba = rx_ring->dma; |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 3212 | ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32))); |
| 3213 | ew32(RDBAH(0), (rdba >> 32)); |
| 3214 | ew32(RDLEN(0), rdlen); |
| 3215 | ew32(RDH(0), 0); |
| 3216 | ew32(RDT(0), 0); |
| 3217 | rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0); |
| 3218 | rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3219 | |
| 3220 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 3221 | rxcsum = er32(RXCSUM); |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 3222 | if (adapter->netdev->features & NETIF_F_RXCSUM) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3223 | rxcsum |= E1000_RXCSUM_TUOFL; |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 3224 | else |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3225 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3226 | ew32(RXCSUM, rxcsum); |
| 3227 | |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 3228 | /* With jumbo frames, excessive C-state transition latencies result |
| 3229 | * in dropped transactions. |
| 3230 | */ |
| 3231 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3232 | u32 lat = |
| 3233 | ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 - |
| 3234 | adapter->max_frame_size) * 8 / 1000; |
| 3235 | |
| 3236 | if (adapter->flags & FLAG_IS_ICH) { |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3237 | u32 rxdctl = er32(RXDCTL(0)); |
| 3238 | ew32(RXDCTL(0), rxdctl | 0x3); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3239 | } |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 3240 | |
| 3241 | pm_qos_update_request(&adapter->netdev->pm_qos_req, lat); |
| 3242 | } else { |
| 3243 | pm_qos_update_request(&adapter->netdev->pm_qos_req, |
| 3244 | PM_QOS_DEFAULT_VALUE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3245 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3246 | |
| 3247 | /* Enable Receives */ |
| 3248 | ew32(RCTL, rctl); |
| 3249 | } |
| 3250 | |
| 3251 | /** |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3252 | * e1000e_write_mc_addr_list - write multicast addresses to MTA |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3253 | * @netdev: network interface device structure |
| 3254 | * |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3255 | * Writes multicast address list to the MTA hash table. |
| 3256 | * Returns: -ENOMEM on failure |
| 3257 | * 0 on no addresses written |
| 3258 | * X on writing X addresses to MTA |
| 3259 | */ |
| 3260 | static int e1000e_write_mc_addr_list(struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3261 | { |
| 3262 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3263 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3264 | struct netdev_hw_addr *ha; |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3265 | u8 *mta_list; |
| 3266 | int i; |
| 3267 | |
| 3268 | if (netdev_mc_empty(netdev)) { |
| 3269 | /* nothing to program, so clear mc list */ |
| 3270 | hw->mac.ops.update_mc_addr_list(hw, NULL, 0); |
| 3271 | return 0; |
| 3272 | } |
| 3273 | |
| 3274 | mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC); |
| 3275 | if (!mta_list) |
| 3276 | return -ENOMEM; |
| 3277 | |
| 3278 | /* update_mc_addr_list expects a packed array of only addresses. */ |
| 3279 | i = 0; |
| 3280 | netdev_for_each_mc_addr(ha, netdev) |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 3281 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3282 | |
| 3283 | hw->mac.ops.update_mc_addr_list(hw, mta_list, i); |
| 3284 | kfree(mta_list); |
| 3285 | |
| 3286 | return netdev_mc_count(netdev); |
| 3287 | } |
| 3288 | |
| 3289 | /** |
| 3290 | * e1000e_write_uc_addr_list - write unicast addresses to RAR table |
| 3291 | * @netdev: network interface device structure |
| 3292 | * |
| 3293 | * Writes unicast address list to the RAR table. |
| 3294 | * Returns: -ENOMEM on failure/insufficient address space |
| 3295 | * 0 on no addresses written |
| 3296 | * X on writing X addresses to the RAR table |
| 3297 | **/ |
| 3298 | static int e1000e_write_uc_addr_list(struct net_device *netdev) |
| 3299 | { |
| 3300 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3301 | struct e1000_hw *hw = &adapter->hw; |
| 3302 | unsigned int rar_entries = hw->mac.rar_entry_count; |
| 3303 | int count = 0; |
| 3304 | |
| 3305 | /* save a rar entry for our hardware address */ |
| 3306 | rar_entries--; |
| 3307 | |
| 3308 | /* save a rar entry for the LAA workaround */ |
| 3309 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) |
| 3310 | rar_entries--; |
| 3311 | |
| 3312 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3313 | if (netdev_uc_count(netdev) > rar_entries) |
| 3314 | return -ENOMEM; |
| 3315 | |
| 3316 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3317 | struct netdev_hw_addr *ha; |
| 3318 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3319 | /* write the addresses in reverse order to avoid write |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3320 | * combining |
| 3321 | */ |
| 3322 | netdev_for_each_uc_addr(ha, netdev) { |
| 3323 | if (!rar_entries) |
| 3324 | break; |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 3325 | hw->mac.ops.rar_set(hw, ha->addr, rar_entries--); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3326 | count++; |
| 3327 | } |
| 3328 | } |
| 3329 | |
| 3330 | /* zero out the remaining RAR entries not used above */ |
| 3331 | for (; rar_entries > 0; rar_entries--) { |
| 3332 | ew32(RAH(rar_entries), 0); |
| 3333 | ew32(RAL(rar_entries), 0); |
| 3334 | } |
| 3335 | e1e_flush(); |
| 3336 | |
| 3337 | return count; |
| 3338 | } |
| 3339 | |
| 3340 | /** |
| 3341 | * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set |
| 3342 | * @netdev: network interface device structure |
| 3343 | * |
| 3344 | * The ndo_set_rx_mode entry point is called whenever the unicast or multicast |
| 3345 | * address list or the network interface flags are updated. This routine is |
| 3346 | * responsible for configuring the hardware for proper unicast, multicast, |
| 3347 | * promiscuous mode, and all-multi behavior. |
| 3348 | **/ |
| 3349 | static void e1000e_set_rx_mode(struct net_device *netdev) |
| 3350 | { |
| 3351 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3352 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3353 | u32 rctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3354 | |
| 3355 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3356 | rctl = er32(RCTL); |
| 3357 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3358 | /* clear the affected bits */ |
| 3359 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 3360 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3361 | if (netdev->flags & IFF_PROMISC) { |
| 3362 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3363 | /* Do not hardware filter VLANs in promisc mode */ |
| 3364 | e1000e_vlan_filter_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3365 | } else { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3366 | int count; |
Bruce Allan | 3d3a167 | 2012-02-23 03:13:18 +0000 | [diff] [blame] | 3367 | |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3368 | if (netdev->flags & IFF_ALLMULTI) { |
| 3369 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3370 | } else { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3371 | /* Write addresses to the MTA, if the attempt fails |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3372 | * then we should just turn on promiscuous mode so |
| 3373 | * that we can at least receive multicast traffic |
| 3374 | */ |
| 3375 | count = e1000e_write_mc_addr_list(netdev); |
| 3376 | if (count < 0) |
| 3377 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3378 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3379 | e1000e_vlan_filter_enable(adapter); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3380 | /* Write addresses to available RAR registers, if there is not |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3381 | * sufficient space to store all the addresses then enable |
| 3382 | * unicast promiscuous mode |
| 3383 | */ |
| 3384 | count = e1000e_write_uc_addr_list(netdev); |
| 3385 | if (count < 0) |
| 3386 | rctl |= E1000_RCTL_UPE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | ew32(RCTL, rctl); |
| 3390 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3391 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3392 | e1000e_vlan_strip_enable(adapter); |
| 3393 | else |
| 3394 | e1000e_vlan_strip_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3395 | } |
| 3396 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3397 | static void e1000e_setup_rss_hash(struct e1000_adapter *adapter) |
| 3398 | { |
| 3399 | struct e1000_hw *hw = &adapter->hw; |
| 3400 | u32 mrqc, rxcsum; |
| 3401 | int i; |
| 3402 | static const u32 rsskey[10] = { |
| 3403 | 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0, |
| 3404 | 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe |
| 3405 | }; |
| 3406 | |
| 3407 | /* Fill out hash function seed */ |
| 3408 | for (i = 0; i < 10; i++) |
| 3409 | ew32(RSSRK(i), rsskey[i]); |
| 3410 | |
| 3411 | /* Direct all traffic to queue 0 */ |
| 3412 | for (i = 0; i < 32; i++) |
| 3413 | ew32(RETA(i), 0); |
| 3414 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3415 | /* Disable raw packet checksumming so that RSS hash is placed in |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3416 | * descriptor on writeback. |
| 3417 | */ |
| 3418 | rxcsum = er32(RXCSUM); |
| 3419 | rxcsum |= E1000_RXCSUM_PCSD; |
| 3420 | |
| 3421 | ew32(RXCSUM, rxcsum); |
| 3422 | |
| 3423 | mrqc = (E1000_MRQC_RSS_FIELD_IPV4 | |
| 3424 | E1000_MRQC_RSS_FIELD_IPV4_TCP | |
| 3425 | E1000_MRQC_RSS_FIELD_IPV6 | |
| 3426 | E1000_MRQC_RSS_FIELD_IPV6_TCP | |
| 3427 | E1000_MRQC_RSS_FIELD_IPV6_TCP_EX); |
| 3428 | |
| 3429 | ew32(MRQC, mrqc); |
| 3430 | } |
| 3431 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3432 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3433 | * e1000e_get_base_timinca - get default SYSTIM time increment attributes |
| 3434 | * @adapter: board private structure |
| 3435 | * @timinca: pointer to returned time increment attributes |
| 3436 | * |
| 3437 | * Get attributes for incrementing the System Time Register SYSTIML/H at |
| 3438 | * the default base frequency, and set the cyclecounter shift value. |
| 3439 | **/ |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3440 | s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca) |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3441 | { |
| 3442 | struct e1000_hw *hw = &adapter->hw; |
| 3443 | u32 incvalue, incperiod, shift; |
| 3444 | |
| 3445 | /* Make sure clock is enabled on I217 before checking the frequency */ |
| 3446 | if ((hw->mac.type == e1000_pch_lpt) && |
| 3447 | !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) && |
| 3448 | !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) { |
| 3449 | u32 fextnvm7 = er32(FEXTNVM7); |
| 3450 | |
| 3451 | if (!(fextnvm7 & (1 << 0))) { |
| 3452 | ew32(FEXTNVM7, fextnvm7 | (1 << 0)); |
| 3453 | e1e_flush(); |
| 3454 | } |
| 3455 | } |
| 3456 | |
| 3457 | switch (hw->mac.type) { |
| 3458 | case e1000_pch2lan: |
| 3459 | case e1000_pch_lpt: |
| 3460 | /* On I217, the clock frequency is 25MHz or 96MHz as |
| 3461 | * indicated by the System Clock Frequency Indication |
| 3462 | */ |
| 3463 | if ((hw->mac.type != e1000_pch_lpt) || |
| 3464 | (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) { |
| 3465 | /* Stable 96MHz frequency */ |
| 3466 | incperiod = INCPERIOD_96MHz; |
| 3467 | incvalue = INCVALUE_96MHz; |
| 3468 | shift = INCVALUE_SHIFT_96MHz; |
| 3469 | adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz; |
| 3470 | break; |
| 3471 | } |
| 3472 | /* fall-through */ |
| 3473 | case e1000_82574: |
| 3474 | case e1000_82583: |
| 3475 | /* Stable 25MHz frequency */ |
| 3476 | incperiod = INCPERIOD_25MHz; |
| 3477 | incvalue = INCVALUE_25MHz; |
| 3478 | shift = INCVALUE_SHIFT_25MHz; |
| 3479 | adapter->cc.shift = shift; |
| 3480 | break; |
| 3481 | default: |
| 3482 | return -EINVAL; |
| 3483 | } |
| 3484 | |
| 3485 | *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) | |
| 3486 | ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK)); |
| 3487 | |
| 3488 | return 0; |
| 3489 | } |
| 3490 | |
| 3491 | /** |
| 3492 | * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable |
| 3493 | * @adapter: board private structure |
| 3494 | * |
| 3495 | * Outgoing time stamping can be enabled and disabled. Play nice and |
| 3496 | * disable it when requested, although it shouldn't cause any overhead |
| 3497 | * when no packet needs it. At most one packet in the queue may be |
| 3498 | * marked for time stamping, otherwise it would be impossible to tell |
| 3499 | * for sure to which packet the hardware time stamp belongs. |
| 3500 | * |
| 3501 | * Incoming time stamping has to be configured via the hardware filters. |
| 3502 | * Not all combinations are supported, in particular event type has to be |
| 3503 | * specified. Matching the kind of event packet is not supported, with the |
| 3504 | * exception of "all V2 events regardless of level 2 or 4". |
| 3505 | **/ |
| 3506 | static int e1000e_config_hwtstamp(struct e1000_adapter *adapter) |
| 3507 | { |
| 3508 | struct e1000_hw *hw = &adapter->hw; |
| 3509 | struct hwtstamp_config *config = &adapter->hwtstamp_config; |
| 3510 | u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED; |
| 3511 | u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3512 | u32 rxmtrl = 0; |
| 3513 | u16 rxudp = 0; |
| 3514 | bool is_l4 = false; |
| 3515 | bool is_l2 = false; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3516 | u32 regval; |
| 3517 | s32 ret_val; |
| 3518 | |
| 3519 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) |
| 3520 | return -EINVAL; |
| 3521 | |
| 3522 | /* flags reserved for future extensions - must be zero */ |
| 3523 | if (config->flags) |
| 3524 | return -EINVAL; |
| 3525 | |
| 3526 | switch (config->tx_type) { |
| 3527 | case HWTSTAMP_TX_OFF: |
| 3528 | tsync_tx_ctl = 0; |
| 3529 | break; |
| 3530 | case HWTSTAMP_TX_ON: |
| 3531 | break; |
| 3532 | default: |
| 3533 | return -ERANGE; |
| 3534 | } |
| 3535 | |
| 3536 | switch (config->rx_filter) { |
| 3537 | case HWTSTAMP_FILTER_NONE: |
| 3538 | tsync_rx_ctl = 0; |
| 3539 | break; |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3540 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 3541 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
| 3542 | rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE; |
| 3543 | is_l4 = true; |
| 3544 | break; |
| 3545 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 3546 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
| 3547 | rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE; |
| 3548 | is_l4 = true; |
| 3549 | break; |
| 3550 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 3551 | /* Also time stamps V2 L2 Path Delay Request/Response */ |
| 3552 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2; |
| 3553 | rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE; |
| 3554 | is_l2 = true; |
| 3555 | break; |
| 3556 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 3557 | /* Also time stamps V2 L2 Path Delay Request/Response. */ |
| 3558 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2; |
| 3559 | rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE; |
| 3560 | is_l2 = true; |
| 3561 | break; |
| 3562 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 3563 | /* Hardware cannot filter just V2 L4 Sync messages; |
| 3564 | * fall-through to V2 (both L2 and L4) Sync. |
| 3565 | */ |
| 3566 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 3567 | /* Also time stamps V2 Path Delay Request/Response. */ |
| 3568 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
| 3569 | rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE; |
| 3570 | is_l2 = true; |
| 3571 | is_l4 = true; |
| 3572 | break; |
| 3573 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 3574 | /* Hardware cannot filter just V2 L4 Delay Request messages; |
| 3575 | * fall-through to V2 (both L2 and L4) Delay Request. |
| 3576 | */ |
| 3577 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 3578 | /* Also time stamps V2 Path Delay Request/Response. */ |
| 3579 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
| 3580 | rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE; |
| 3581 | is_l2 = true; |
| 3582 | is_l4 = true; |
| 3583 | break; |
| 3584 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 3585 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 3586 | /* Hardware cannot filter just V2 L4 or L2 Event messages; |
| 3587 | * fall-through to all V2 (both L2 and L4) Events. |
| 3588 | */ |
| 3589 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 3590 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2; |
| 3591 | config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
| 3592 | is_l2 = true; |
| 3593 | is_l4 = true; |
| 3594 | break; |
| 3595 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 3596 | /* For V1, the hardware can only filter Sync messages or |
| 3597 | * Delay Request messages but not both so fall-through to |
| 3598 | * time stamp all packets. |
| 3599 | */ |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3600 | case HWTSTAMP_FILTER_ALL: |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3601 | is_l2 = true; |
| 3602 | is_l4 = true; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3603 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; |
| 3604 | config->rx_filter = HWTSTAMP_FILTER_ALL; |
| 3605 | break; |
| 3606 | default: |
| 3607 | return -ERANGE; |
| 3608 | } |
| 3609 | |
| 3610 | /* enable/disable Tx h/w time stamping */ |
| 3611 | regval = er32(TSYNCTXCTL); |
| 3612 | regval &= ~E1000_TSYNCTXCTL_ENABLED; |
| 3613 | regval |= tsync_tx_ctl; |
| 3614 | ew32(TSYNCTXCTL, regval); |
| 3615 | if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) != |
| 3616 | (regval & E1000_TSYNCTXCTL_ENABLED)) { |
| 3617 | e_err("Timesync Tx Control register not set as expected\n"); |
| 3618 | return -EAGAIN; |
| 3619 | } |
| 3620 | |
| 3621 | /* enable/disable Rx h/w time stamping */ |
| 3622 | regval = er32(TSYNCRXCTL); |
| 3623 | regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK); |
| 3624 | regval |= tsync_rx_ctl; |
| 3625 | ew32(TSYNCRXCTL, regval); |
| 3626 | if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED | |
| 3627 | E1000_TSYNCRXCTL_TYPE_MASK)) != |
| 3628 | (regval & (E1000_TSYNCRXCTL_ENABLED | |
| 3629 | E1000_TSYNCRXCTL_TYPE_MASK))) { |
| 3630 | e_err("Timesync Rx Control register not set as expected\n"); |
| 3631 | return -EAGAIN; |
| 3632 | } |
| 3633 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3634 | /* L2: define ethertype filter for time stamped packets */ |
| 3635 | if (is_l2) |
| 3636 | rxmtrl |= ETH_P_1588; |
| 3637 | |
| 3638 | /* define which PTP packets get time stamped */ |
| 3639 | ew32(RXMTRL, rxmtrl); |
| 3640 | |
| 3641 | /* Filter by destination port */ |
| 3642 | if (is_l4) { |
| 3643 | rxudp = PTP_EV_PORT; |
| 3644 | cpu_to_be16s(&rxudp); |
| 3645 | } |
| 3646 | ew32(RXUDP, rxudp); |
| 3647 | |
| 3648 | e1e_flush(); |
| 3649 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3650 | /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */ |
Bruce Allan | 70806a7 | 2013-01-05 05:08:37 +0000 | [diff] [blame] | 3651 | er32(RXSTMPH); |
| 3652 | er32(TXSTMPH); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3653 | |
| 3654 | /* Get and set the System Time Register SYSTIM base frequency */ |
| 3655 | ret_val = e1000e_get_base_timinca(adapter, ®val); |
| 3656 | if (ret_val) |
| 3657 | return ret_val; |
| 3658 | ew32(TIMINCA, regval); |
| 3659 | |
| 3660 | /* reset the ns time counter */ |
| 3661 | timecounter_init(&adapter->tc, &adapter->cc, |
| 3662 | ktime_to_ns(ktime_get_real())); |
| 3663 | |
| 3664 | return 0; |
| 3665 | } |
| 3666 | |
| 3667 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3668 | * e1000_configure - configure the hardware for Rx and Tx |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3669 | * @adapter: private board structure |
| 3670 | **/ |
| 3671 | static void e1000_configure(struct e1000_adapter *adapter) |
| 3672 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3673 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 3674 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3675 | e1000e_set_rx_mode(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3676 | |
| 3677 | e1000_restore_vlan(adapter); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 3678 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3679 | |
| 3680 | e1000_configure_tx(adapter); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3681 | |
| 3682 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 3683 | e1000e_setup_rss_hash(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3684 | e1000_setup_rctl(adapter); |
| 3685 | e1000_configure_rx(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3686 | 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] | 3687 | } |
| 3688 | |
| 3689 | /** |
| 3690 | * e1000e_power_up_phy - restore link in case the phy was powered down |
| 3691 | * @adapter: address of board private structure |
| 3692 | * |
| 3693 | * The phy may be powered down to save power and turn off link when the |
| 3694 | * driver is unloaded and wake on lan is not enabled (among others) |
| 3695 | * *** this routine MUST be followed by a call to e1000e_reset *** |
| 3696 | **/ |
| 3697 | void e1000e_power_up_phy(struct e1000_adapter *adapter) |
| 3698 | { |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3699 | if (adapter->hw.phy.ops.power_up) |
| 3700 | adapter->hw.phy.ops.power_up(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3701 | |
| 3702 | adapter->hw.mac.ops.setup_link(&adapter->hw); |
| 3703 | } |
| 3704 | |
| 3705 | /** |
| 3706 | * e1000_power_down_phy - Power down the PHY |
| 3707 | * |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3708 | * Power down the PHY so no link is implied when interface is down. |
| 3709 | * The PHY cannot be powered down if management or WoL is active. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3710 | */ |
| 3711 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 3712 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3713 | /* WoL is enabled */ |
Auke Kok | 23b66e2 | 2008-02-11 09:25:51 -0800 | [diff] [blame] | 3714 | if (adapter->wol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3715 | return; |
| 3716 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3717 | if (adapter->hw.phy.ops.power_down) |
| 3718 | adapter->hw.phy.ops.power_down(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | /** |
| 3722 | * e1000e_reset - bring the hardware into a known good state |
| 3723 | * |
| 3724 | * This function boots the hardware and enables some settings that |
| 3725 | * require a configuration cycle of the hardware - those cannot be |
| 3726 | * set/changed during runtime. After reset the device needs to be |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3727 | * properly configured for Rx, Tx etc. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3728 | */ |
| 3729 | void e1000e_reset(struct e1000_adapter *adapter) |
| 3730 | { |
| 3731 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3732 | struct e1000_fc_info *fc = &adapter->hw.fc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3733 | struct e1000_hw *hw = &adapter->hw; |
| 3734 | u32 tx_space, min_tx_space, min_rx_space; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3735 | u32 pba = adapter->pba; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3736 | u16 hwm; |
| 3737 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3738 | /* reset Packet Buffer Allocation to default */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3739 | ew32(PBA, pba); |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3740 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3741 | if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3742 | /* To maintain wire speed transmits, the Tx FIFO should be |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3743 | * large enough to accommodate two full transmit packets, |
| 3744 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 3745 | * the Rx FIFO should be large enough to accommodate at least |
| 3746 | * one full receive packet and is similarly rounded up and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3747 | * expressed in KB. |
| 3748 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3749 | pba = er32(PBA); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3750 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3751 | tx_space = pba >> 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3752 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3753 | pba &= 0xffff; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3754 | /* the Tx fifo also stores 16 bytes of information about the Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3755 | * but don't include ethernet FCS because hardware appends it |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3756 | */ |
| 3757 | min_tx_space = (adapter->max_frame_size + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3758 | sizeof(struct e1000_tx_desc) - |
| 3759 | ETH_FCS_LEN) * 2; |
| 3760 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 3761 | min_tx_space >>= 10; |
| 3762 | /* software strips receive CRC, so leave room for it */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3763 | min_rx_space = adapter->max_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3764 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 3765 | min_rx_space >>= 10; |
| 3766 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3767 | /* If current Tx allocation is less than the min Tx FIFO size, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3768 | * 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] | 3769 | * allocation, take space away from current Rx allocation |
| 3770 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3771 | if ((tx_space < min_tx_space) && |
| 3772 | ((min_tx_space - tx_space) < pba)) { |
| 3773 | pba -= min_tx_space - tx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3774 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3775 | /* if short on Rx space, Rx wins and must trump Tx |
Bruce Allan | 419e551 | 2012-08-17 06:18:02 +0000 | [diff] [blame] | 3776 | * adjustment |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3777 | */ |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3778 | if (pba < min_rx_space) |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3779 | pba = min_rx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3780 | } |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3781 | |
| 3782 | ew32(PBA, pba); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3783 | } |
| 3784 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3785 | /* flow control settings |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3786 | * |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3787 | * 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] | 3788 | * (or the size used for early receive) above it in the Rx FIFO. |
| 3789 | * Set it to the lower of: |
| 3790 | * - 90% of the Rx FIFO size, and |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3791 | * - the full Rx FIFO size minus one full frame |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3792 | */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3793 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
| 3794 | fc->pause_time = 0xFFFF; |
| 3795 | else |
| 3796 | fc->pause_time = E1000_FC_PAUSE_TIME; |
Bruce Allan | b20caa8 | 2012-02-22 09:03:03 +0000 | [diff] [blame] | 3797 | fc->send_xon = true; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3798 | fc->current_mode = fc->requested_mode; |
| 3799 | |
| 3800 | switch (hw->mac.type) { |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3801 | case e1000_ich9lan: |
| 3802 | case e1000_ich10lan: |
| 3803 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3804 | pba = 14; |
| 3805 | ew32(PBA, pba); |
| 3806 | fc->high_water = 0x2800; |
| 3807 | fc->low_water = fc->high_water - 8; |
| 3808 | break; |
| 3809 | } |
| 3810 | /* fall-through */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3811 | default: |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3812 | hwm = min(((pba << 10) * 9 / 10), |
| 3813 | ((pba << 10) - adapter->max_frame_size)); |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3814 | |
| 3815 | fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ |
| 3816 | fc->low_water = fc->high_water - 8; |
| 3817 | break; |
| 3818 | case e1000_pchlan: |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3819 | /* Workaround PCH LOM adapter hangs with certain network |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3820 | * loads. If hangs persist, try disabling Tx flow control. |
| 3821 | */ |
| 3822 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3823 | fc->high_water = 0x3500; |
| 3824 | fc->low_water = 0x1500; |
| 3825 | } else { |
| 3826 | fc->high_water = 0x5000; |
| 3827 | fc->low_water = 0x3000; |
| 3828 | } |
Bruce Allan | a305595 | 2010-05-10 15:02:12 +0000 | [diff] [blame] | 3829 | fc->refresh_time = 0x1000; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3830 | break; |
| 3831 | case e1000_pch2lan: |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 3832 | case e1000_pch_lpt: |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3833 | fc->refresh_time = 0x0400; |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 3834 | |
| 3835 | if (adapter->netdev->mtu <= ETH_DATA_LEN) { |
| 3836 | fc->high_water = 0x05C20; |
| 3837 | fc->low_water = 0x05048; |
| 3838 | fc->pause_time = 0x0650; |
| 3839 | break; |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3840 | } |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 3841 | |
| 3842 | fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH; |
| 3843 | fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3844 | break; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3845 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3846 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3847 | /* Alignment of Tx data is on an arbitrary byte boundary with the |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 3848 | * maximum size per Tx descriptor limited only to the transmit |
| 3849 | * allocation of the packet buffer minus 96 bytes with an upper |
| 3850 | * limit of 24KB due to receive synchronization limitations. |
| 3851 | */ |
| 3852 | adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96, |
| 3853 | 24 << 10); |
| 3854 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3855 | /* Disable Adaptive Interrupt Moderation if 2 full packets cannot |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3856 | * fit in receive buffer. |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3857 | */ |
| 3858 | if (adapter->itr_setting & 0x3) { |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3859 | if ((adapter->max_frame_size * 2) > (pba << 10)) { |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3860 | if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) { |
| 3861 | dev_info(&adapter->pdev->dev, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 3862 | "Interrupt Throttle Rate off\n"); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3863 | adapter->flags2 |= FLAG2_DISABLE_AIM; |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 3864 | e1000e_write_itr(adapter, 0); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3865 | } |
| 3866 | } else if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 3867 | dev_info(&adapter->pdev->dev, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 3868 | "Interrupt Throttle Rate on\n"); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3869 | adapter->flags2 &= ~FLAG2_DISABLE_AIM; |
| 3870 | adapter->itr = 20000; |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 3871 | e1000e_write_itr(adapter, adapter->itr); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3872 | } |
| 3873 | } |
| 3874 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3875 | /* Allow time for pending master requests to run */ |
| 3876 | mac->ops.reset_hw(hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3877 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3878 | /* For parts with AMT enabled, let the firmware know |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3879 | * that the network interface is in control |
| 3880 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 3881 | if (adapter->flags & FLAG_HAS_AMT) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3882 | e1000e_get_hw_control(adapter); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3883 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3884 | ew32(WUC, 0); |
| 3885 | |
| 3886 | if (mac->ops.init_hw(hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 3887 | e_err("Hardware Error\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3888 | |
| 3889 | e1000_update_mng_vlan(adapter); |
| 3890 | |
| 3891 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 3892 | ew32(VET, ETH_P_8021Q); |
| 3893 | |
| 3894 | e1000e_reset_adaptive(hw); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3895 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3896 | /* initialize systim and reset the ns time counter */ |
| 3897 | e1000e_config_hwtstamp(adapter); |
| 3898 | |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3899 | if (!netif_running(adapter->netdev) && |
| 3900 | !test_bit(__E1000_TESTING, &adapter->state)) { |
| 3901 | e1000_power_down_phy(adapter); |
| 3902 | return; |
| 3903 | } |
| 3904 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3905 | e1000_get_phy_info(hw); |
| 3906 | |
Bruce Allan | 918d719 | 2009-06-02 11:28:20 +0000 | [diff] [blame] | 3907 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && |
| 3908 | !(adapter->flags & FLAG_SMART_POWER_DOWN)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3909 | u16 phy_data = 0; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3910 | /* speed up time to link by disabling smart power down, ignore |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3911 | * the return value of this function because there is nothing |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3912 | * different we would do if it failed |
| 3913 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3914 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
| 3915 | phy_data &= ~IGP02E1000_PM_SPD; |
| 3916 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 3917 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3918 | } |
| 3919 | |
| 3920 | int e1000e_up(struct e1000_adapter *adapter) |
| 3921 | { |
| 3922 | struct e1000_hw *hw = &adapter->hw; |
| 3923 | |
| 3924 | /* hardware has been reset, we need to reload some things */ |
| 3925 | e1000_configure(adapter); |
| 3926 | |
| 3927 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3928 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3929 | if (adapter->msix_entries) |
| 3930 | e1000_configure_msix(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3931 | e1000_irq_enable(adapter); |
| 3932 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 3933 | netif_start_queue(adapter->netdev); |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3934 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3935 | /* fire a link change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3936 | if (adapter->msix_entries) |
| 3937 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3938 | else |
| 3939 | ew32(ICS, E1000_ICS_LSC); |
| 3940 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3941 | return 0; |
| 3942 | } |
| 3943 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3944 | static void e1000e_flush_descriptors(struct e1000_adapter *adapter) |
| 3945 | { |
| 3946 | struct e1000_hw *hw = &adapter->hw; |
| 3947 | |
| 3948 | if (!(adapter->flags2 & FLAG2_DMA_BURST)) |
| 3949 | return; |
| 3950 | |
| 3951 | /* flush pending descriptor writebacks to memory */ |
| 3952 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 3953 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 3954 | |
| 3955 | /* execute the writes immediately */ |
| 3956 | e1e_flush(); |
Matthew Vick | bf03085 | 2012-03-16 09:03:00 +0000 | [diff] [blame] | 3957 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3958 | /* due to rare timing issues, write to TIDV/RDTR again to ensure the |
Matthew Vick | bf03085 | 2012-03-16 09:03:00 +0000 | [diff] [blame] | 3959 | * write is successful |
| 3960 | */ |
| 3961 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 3962 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 3963 | |
| 3964 | /* execute the writes immediately */ |
| 3965 | e1e_flush(); |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3966 | } |
| 3967 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3968 | static void e1000e_update_stats(struct e1000_adapter *adapter); |
| 3969 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3970 | void e1000e_down(struct e1000_adapter *adapter) |
| 3971 | { |
| 3972 | struct net_device *netdev = adapter->netdev; |
| 3973 | struct e1000_hw *hw = &adapter->hw; |
| 3974 | u32 tctl, rctl; |
| 3975 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3976 | /* signal that we're down so the interrupt handler does not |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3977 | * reschedule our watchdog timer |
| 3978 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3979 | set_bit(__E1000_DOWN, &adapter->state); |
| 3980 | |
| 3981 | /* disable receives in the hardware */ |
| 3982 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3983 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3984 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3985 | /* flush and sleep below */ |
| 3986 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3987 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3988 | |
| 3989 | /* disable transmits in the hardware */ |
| 3990 | tctl = er32(TCTL); |
| 3991 | tctl &= ~E1000_TCTL_EN; |
| 3992 | ew32(TCTL, tctl); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3993 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3994 | /* flush both disables and wait for them to finish */ |
| 3995 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3996 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3997 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3998 | e1000_irq_disable(adapter); |
| 3999 | |
| 4000 | del_timer_sync(&adapter->watchdog_timer); |
| 4001 | del_timer_sync(&adapter->phy_info_timer); |
| 4002 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4003 | netif_carrier_off(netdev); |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4004 | |
| 4005 | spin_lock(&adapter->stats64_lock); |
| 4006 | e1000e_update_stats(adapter); |
| 4007 | spin_unlock(&adapter->stats64_lock); |
| 4008 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 4009 | e1000e_flush_descriptors(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4010 | e1000_clean_tx_ring(adapter->tx_ring); |
| 4011 | e1000_clean_rx_ring(adapter->rx_ring); |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 4012 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4013 | adapter->link_speed = 0; |
| 4014 | adapter->link_duplex = 0; |
| 4015 | |
Jeff Kirsher | 52cc308 | 2008-06-24 17:01:29 -0700 | [diff] [blame] | 4016 | if (!pci_channel_offline(adapter->pdev)) |
| 4017 | e1000e_reset(adapter); |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4018 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4019 | /* TODO: for power management, we could drop the link and |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4020 | * pci_disable_device here. |
| 4021 | */ |
| 4022 | } |
| 4023 | |
| 4024 | void e1000e_reinit_locked(struct e1000_adapter *adapter) |
| 4025 | { |
| 4026 | might_sleep(); |
| 4027 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 4028 | usleep_range(1000, 2000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4029 | e1000e_down(adapter); |
| 4030 | e1000e_up(adapter); |
| 4031 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 4032 | } |
| 4033 | |
| 4034 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4035 | * e1000e_cyclecounter_read - read raw cycle counter (used by time counter) |
| 4036 | * @cc: cyclecounter structure |
| 4037 | **/ |
| 4038 | static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc) |
| 4039 | { |
| 4040 | struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter, |
| 4041 | cc); |
| 4042 | struct e1000_hw *hw = &adapter->hw; |
| 4043 | cycle_t systim; |
| 4044 | |
| 4045 | /* latch SYSTIMH on read of SYSTIML */ |
| 4046 | systim = (cycle_t)er32(SYSTIML); |
| 4047 | systim |= (cycle_t)er32(SYSTIMH) << 32; |
| 4048 | |
| 4049 | return systim; |
| 4050 | } |
| 4051 | |
| 4052 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4053 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 4054 | * @adapter: board private structure to initialize |
| 4055 | * |
| 4056 | * e1000_sw_init initializes the Adapter private data structure. |
| 4057 | * Fields are initialized based on PCI device information and |
| 4058 | * OS network device settings (MTU size). |
| 4059 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 4060 | static int e1000_sw_init(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4061 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4062 | struct net_device *netdev = adapter->netdev; |
| 4063 | |
| 4064 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN; |
| 4065 | adapter->rx_ps_bsize0 = 128; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4066 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4067 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4068 | adapter->tx_ring_count = E1000_DEFAULT_TXD; |
| 4069 | adapter->rx_ring_count = E1000_DEFAULT_RXD; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4070 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4071 | spin_lock_init(&adapter->stats64_lock); |
| 4072 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4073 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4074 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4075 | if (e1000_alloc_queues(adapter)) |
| 4076 | return -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4077 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4078 | /* Setup hardware time stamping cyclecounter */ |
| 4079 | if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) { |
| 4080 | adapter->cc.read = e1000e_cyclecounter_read; |
| 4081 | adapter->cc.mask = CLOCKSOURCE_MASK(64); |
| 4082 | adapter->cc.mult = 1; |
| 4083 | /* cc.shift set in e1000e_get_base_tininca() */ |
| 4084 | |
| 4085 | spin_lock_init(&adapter->systim_lock); |
| 4086 | INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work); |
| 4087 | } |
| 4088 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4089 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4090 | e1000_irq_disable(adapter); |
| 4091 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4092 | set_bit(__E1000_DOWN, &adapter->state); |
| 4093 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | /** |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4097 | * e1000_intr_msi_test - Interrupt Handler |
| 4098 | * @irq: interrupt number |
| 4099 | * @data: pointer to a network interface device structure |
| 4100 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 4101 | static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data) |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4102 | { |
| 4103 | struct net_device *netdev = data; |
| 4104 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4105 | struct e1000_hw *hw = &adapter->hw; |
| 4106 | u32 icr = er32(ICR); |
| 4107 | |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 4108 | e_dbg("icr is %08X\n", icr); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4109 | if (icr & E1000_ICR_RXSEQ) { |
| 4110 | adapter->flags &= ~FLAG_MSI_TEST_FAILED; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4111 | /* Force memory writes to complete before acknowledging the |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4112 | * interrupt is handled. |
| 4113 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4114 | wmb(); |
| 4115 | } |
| 4116 | |
| 4117 | return IRQ_HANDLED; |
| 4118 | } |
| 4119 | |
| 4120 | /** |
| 4121 | * e1000_test_msi_interrupt - Returns 0 for successful test |
| 4122 | * @adapter: board private struct |
| 4123 | * |
| 4124 | * code flow taken from tg3.c |
| 4125 | **/ |
| 4126 | static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) |
| 4127 | { |
| 4128 | struct net_device *netdev = adapter->netdev; |
| 4129 | struct e1000_hw *hw = &adapter->hw; |
| 4130 | int err; |
| 4131 | |
| 4132 | /* poll_enable hasn't been called yet, so don't need disable */ |
| 4133 | /* clear any pending events */ |
| 4134 | er32(ICR); |
| 4135 | |
| 4136 | /* free the real vector and request a test handler */ |
| 4137 | e1000_free_irq(adapter); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4138 | e1000e_reset_interrupt_capability(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4139 | |
| 4140 | /* Assume that the test fails, if it succeeds then the test |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4141 | * MSI irq handler will unset this flag |
| 4142 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4143 | adapter->flags |= FLAG_MSI_TEST_FAILED; |
| 4144 | |
| 4145 | err = pci_enable_msi(adapter->pdev); |
| 4146 | if (err) |
| 4147 | goto msi_test_failed; |
| 4148 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 4149 | err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4150 | netdev->name, netdev); |
| 4151 | if (err) { |
| 4152 | pci_disable_msi(adapter->pdev); |
| 4153 | goto msi_test_failed; |
| 4154 | } |
| 4155 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4156 | /* Force memory writes to complete before enabling and firing an |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4157 | * interrupt. |
| 4158 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4159 | wmb(); |
| 4160 | |
| 4161 | e1000_irq_enable(adapter); |
| 4162 | |
| 4163 | /* fire an unusual interrupt on the test handler */ |
| 4164 | ew32(ICS, E1000_ICS_RXSEQ); |
| 4165 | e1e_flush(); |
Prasanna S Panchamukhi | 569a3af | 2012-04-19 17:01:00 +0000 | [diff] [blame] | 4166 | msleep(100); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4167 | |
| 4168 | e1000_irq_disable(adapter); |
| 4169 | |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4170 | rmb(); /* read flags after interrupt has been fired */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4171 | |
| 4172 | if (adapter->flags & FLAG_MSI_TEST_FAILED) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4173 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4174 | e_info("MSI interrupt test failed, using legacy interrupt.\n"); |
Bruce Allan | 24b706b | 2012-01-31 06:37:22 +0000 | [diff] [blame] | 4175 | } else { |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4176 | e_dbg("MSI interrupt test succeeded!\n"); |
Bruce Allan | 24b706b | 2012-01-31 06:37:22 +0000 | [diff] [blame] | 4177 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4178 | |
| 4179 | free_irq(adapter->pdev->irq, netdev); |
| 4180 | pci_disable_msi(adapter->pdev); |
| 4181 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4182 | msi_test_failed: |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4183 | e1000e_set_interrupt_capability(adapter); |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4184 | return e1000_request_irq(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4185 | } |
| 4186 | |
| 4187 | /** |
| 4188 | * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored |
| 4189 | * @adapter: board private struct |
| 4190 | * |
| 4191 | * code flow taken from tg3.c, called with e1000 interrupts disabled. |
| 4192 | **/ |
| 4193 | static int e1000_test_msi(struct e1000_adapter *adapter) |
| 4194 | { |
| 4195 | int err; |
| 4196 | u16 pci_cmd; |
| 4197 | |
| 4198 | if (!(adapter->flags & FLAG_MSI_ENABLED)) |
| 4199 | return 0; |
| 4200 | |
| 4201 | /* disable SERR in case the MSI write causes a master abort */ |
| 4202 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 4203 | if (pci_cmd & PCI_COMMAND_SERR) |
| 4204 | pci_write_config_word(adapter->pdev, PCI_COMMAND, |
| 4205 | pci_cmd & ~PCI_COMMAND_SERR); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4206 | |
| 4207 | err = e1000_test_msi_interrupt(adapter); |
| 4208 | |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 4209 | /* re-enable SERR */ |
| 4210 | if (pci_cmd & PCI_COMMAND_SERR) { |
| 4211 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
| 4212 | pci_cmd |= PCI_COMMAND_SERR; |
| 4213 | pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); |
| 4214 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4215 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4216 | return err; |
| 4217 | } |
| 4218 | |
| 4219 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4220 | * e1000_open - Called when a network interface is made active |
| 4221 | * @netdev: network interface device structure |
| 4222 | * |
| 4223 | * Returns 0 on success, negative value on failure |
| 4224 | * |
| 4225 | * The open entry point is called when a network interface is made |
| 4226 | * active by the system (IFF_UP). At this point all resources needed |
| 4227 | * for transmit and receive operations are allocated, the interrupt |
| 4228 | * handler is registered with the OS, the watchdog timer is started, |
| 4229 | * and the stack is notified that the interface is ready. |
| 4230 | **/ |
| 4231 | static int e1000_open(struct net_device *netdev) |
| 4232 | { |
| 4233 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4234 | struct e1000_hw *hw = &adapter->hw; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4235 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4236 | int err; |
| 4237 | |
| 4238 | /* disallow open during test */ |
| 4239 | if (test_bit(__E1000_TESTING, &adapter->state)) |
| 4240 | return -EBUSY; |
| 4241 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4242 | pm_runtime_get_sync(&pdev->dev); |
| 4243 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 4244 | netif_carrier_off(netdev); |
| 4245 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4246 | /* allocate transmit descriptors */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4247 | err = e1000e_setup_tx_resources(adapter->tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4248 | if (err) |
| 4249 | goto err_setup_tx; |
| 4250 | |
| 4251 | /* allocate receive descriptors */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4252 | err = e1000e_setup_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4253 | if (err) |
| 4254 | goto err_setup_rx; |
| 4255 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4256 | /* If AMT is enabled, let the firmware know that the network |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 4257 | * interface is now open and reset the part to a known state. |
| 4258 | */ |
| 4259 | if (adapter->flags & FLAG_HAS_AMT) { |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4260 | e1000e_get_hw_control(adapter); |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 4261 | e1000e_reset(adapter); |
| 4262 | } |
| 4263 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4264 | e1000e_power_up_phy(adapter); |
| 4265 | |
| 4266 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 4267 | if ((adapter->hw.mng_cookie.status & |
| 4268 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
| 4269 | e1000_update_mng_vlan(adapter); |
| 4270 | |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4271 | /* DMA latency requirement to workaround jumbo issue */ |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 4272 | pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, |
| 4273 | PM_QOS_DEFAULT_VALUE); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 4274 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4275 | /* before we allocate an interrupt, we must be ready to handle it. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4276 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 4277 | * 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] | 4278 | * clean_rx handler before we do so. |
| 4279 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4280 | e1000_configure(adapter); |
| 4281 | |
| 4282 | err = e1000_request_irq(adapter); |
| 4283 | if (err) |
| 4284 | goto err_req_irq; |
| 4285 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4286 | /* Work around PCIe errata with MSI interrupts causing some chipsets to |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4287 | * ignore e1000e MSI messages, which means we need to test our MSI |
| 4288 | * interrupt now |
| 4289 | */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4290 | if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4291 | err = e1000_test_msi(adapter); |
| 4292 | if (err) { |
| 4293 | e_err("Interrupt allocation failed\n"); |
| 4294 | goto err_req_irq; |
| 4295 | } |
| 4296 | } |
| 4297 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4298 | /* From here on the code is the same as e1000e_up() */ |
| 4299 | clear_bit(__E1000_DOWN, &adapter->state); |
| 4300 | |
| 4301 | napi_enable(&adapter->napi); |
| 4302 | |
| 4303 | e1000_irq_enable(adapter); |
| 4304 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 4305 | adapter->tx_hang_recheck = false; |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 4306 | netif_start_queue(netdev); |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4307 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4308 | adapter->idle_check = true; |
| 4309 | pm_runtime_put(&pdev->dev); |
| 4310 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4311 | /* fire a link status change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 4312 | if (adapter->msix_entries) |
| 4313 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 4314 | else |
| 4315 | ew32(ICS, E1000_ICS_LSC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4316 | |
| 4317 | return 0; |
| 4318 | |
| 4319 | err_req_irq: |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4320 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4321 | e1000_power_down_phy(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4322 | e1000e_free_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4323 | err_setup_rx: |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4324 | e1000e_free_tx_resources(adapter->tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4325 | err_setup_tx: |
| 4326 | e1000e_reset(adapter); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4327 | pm_runtime_put_sync(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4328 | |
| 4329 | return err; |
| 4330 | } |
| 4331 | |
| 4332 | /** |
| 4333 | * e1000_close - Disables a network interface |
| 4334 | * @netdev: network interface device structure |
| 4335 | * |
| 4336 | * Returns 0, this is not allowed to fail |
| 4337 | * |
| 4338 | * The close entry point is called when an interface is de-activated |
| 4339 | * by the OS. The hardware is still under the drivers control, but |
| 4340 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4341 | * hardware, and all transmit and receive resources are freed. |
| 4342 | **/ |
| 4343 | static int e1000_close(struct net_device *netdev) |
| 4344 | { |
| 4345 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4346 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | bb9e44d | 2012-03-21 00:39:12 +0000 | [diff] [blame] | 4347 | int count = E1000_CHECK_RESET_COUNT; |
| 4348 | |
| 4349 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) |
| 4350 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4351 | |
| 4352 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4353 | |
| 4354 | pm_runtime_get_sync(&pdev->dev); |
| 4355 | |
Bruce Allan | 5f4a780 | 2011-11-29 08:09:19 +0000 | [diff] [blame] | 4356 | napi_disable(&adapter->napi); |
| 4357 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4358 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 4359 | e1000e_down(adapter); |
| 4360 | e1000_free_irq(adapter); |
| 4361 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4362 | e1000_power_down_phy(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4363 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4364 | e1000e_free_tx_resources(adapter->tx_ring); |
| 4365 | e1000e_free_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4366 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4367 | /* kill manageability vlan ID if supported, but not if a vlan with |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4368 | * the same ID is registered on the host OS (let 8021q kill it) |
| 4369 | */ |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 4370 | if (adapter->hw.mng_cookie.status & |
| 4371 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4372 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 4373 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4374 | /* If AMT is enabled, let the firmware know that the network |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4375 | * interface is now closed |
| 4376 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4377 | if ((adapter->flags & FLAG_HAS_AMT) && |
| 4378 | !test_bit(__E1000_TESTING, &adapter->state)) |
| 4379 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4380 | |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 4381 | pm_qos_remove_request(&adapter->netdev->pm_qos_req); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 4382 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4383 | pm_runtime_put_sync(&pdev->dev); |
| 4384 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4385 | return 0; |
| 4386 | } |
| 4387 | /** |
| 4388 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 4389 | * @netdev: network interface device structure |
| 4390 | * @p: pointer to an address structure |
| 4391 | * |
| 4392 | * Returns 0 on success, negative on failure |
| 4393 | **/ |
| 4394 | static int e1000_set_mac(struct net_device *netdev, void *p) |
| 4395 | { |
| 4396 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4397 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4398 | struct sockaddr *addr = p; |
| 4399 | |
| 4400 | if (!is_valid_ether_addr(addr->sa_data)) |
| 4401 | return -EADDRNOTAVAIL; |
| 4402 | |
| 4403 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 4404 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 4405 | |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4406 | hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4407 | |
| 4408 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { |
| 4409 | /* activate the work around */ |
| 4410 | e1000e_set_laa_state_82571(&adapter->hw, 1); |
| 4411 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4412 | /* 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] | 4413 | * between the time RAR[0] gets clobbered and the time it |
| 4414 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
| 4415 | * of the RARs and no incoming packets directed to this port |
| 4416 | * are dropped. Eventually the LAA will be in RAR[0] and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4417 | * RAR[14] |
| 4418 | */ |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4419 | hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, |
| 4420 | adapter->hw.mac.rar_entry_count - 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | return 0; |
| 4424 | } |
| 4425 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4426 | /** |
| 4427 | * e1000e_update_phy_task - work thread to update phy |
| 4428 | * @work: pointer to our work struct |
| 4429 | * |
| 4430 | * this worker thread exists because we must acquire a |
| 4431 | * semaphore to read the phy, which we could msleep while |
| 4432 | * waiting for it, and we can't msleep in a timer. |
| 4433 | **/ |
| 4434 | static void e1000e_update_phy_task(struct work_struct *work) |
| 4435 | { |
| 4436 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 4437 | struct e1000_adapter, |
| 4438 | update_phy_task); |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4439 | |
| 4440 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4441 | return; |
| 4442 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4443 | e1000_get_phy_info(&adapter->hw); |
| 4444 | } |
| 4445 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4446 | /** |
| 4447 | * e1000_update_phy_info - timre call-back to update PHY info |
| 4448 | * @data: pointer to adapter cast into an unsigned long |
| 4449 | * |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4450 | * Need to wait a few seconds after link up to get diagnostic information from |
| 4451 | * the phy |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4452 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4453 | static void e1000_update_phy_info(unsigned long data) |
| 4454 | { |
Bruce Allan | 53aa82d | 2013-02-20 04:06:06 +0000 | [diff] [blame^] | 4455 | struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4456 | |
| 4457 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4458 | return; |
| 4459 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4460 | schedule_work(&adapter->update_phy_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | /** |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4464 | * e1000e_update_phy_stats - Update the PHY statistics counters |
| 4465 | * @adapter: board private structure |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4466 | * |
| 4467 | * Read/clear the upper 16-bit PHY registers and read/accumulate lower |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4468 | **/ |
| 4469 | static void e1000e_update_phy_stats(struct e1000_adapter *adapter) |
| 4470 | { |
| 4471 | struct e1000_hw *hw = &adapter->hw; |
| 4472 | s32 ret_val; |
| 4473 | u16 phy_data; |
| 4474 | |
| 4475 | ret_val = hw->phy.ops.acquire(hw); |
| 4476 | if (ret_val) |
| 4477 | return; |
| 4478 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4479 | /* A page set is expensive so check if already on desired page. |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4480 | * If not, set to the page with the PHY status registers. |
| 4481 | */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4482 | hw->phy.addr = 1; |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4483 | ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 4484 | &phy_data); |
| 4485 | if (ret_val) |
| 4486 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4487 | if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) { |
| 4488 | ret_val = hw->phy.ops.set_page(hw, |
| 4489 | HV_STATS_PAGE << IGP_PAGE_SHIFT); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4490 | if (ret_val) |
| 4491 | goto release; |
| 4492 | } |
| 4493 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4494 | /* Single Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4495 | hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data); |
| 4496 | 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] | 4497 | if (!ret_val) |
| 4498 | adapter->stats.scc += phy_data; |
| 4499 | |
| 4500 | /* Excessive Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4501 | hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data); |
| 4502 | 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] | 4503 | if (!ret_val) |
| 4504 | adapter->stats.ecol += phy_data; |
| 4505 | |
| 4506 | /* Multiple Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4507 | hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data); |
| 4508 | 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] | 4509 | if (!ret_val) |
| 4510 | adapter->stats.mcc += phy_data; |
| 4511 | |
| 4512 | /* Late Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4513 | hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data); |
| 4514 | 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] | 4515 | if (!ret_val) |
| 4516 | adapter->stats.latecol += phy_data; |
| 4517 | |
| 4518 | /* Collision Count - also used for adaptive IFS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4519 | hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data); |
| 4520 | 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] | 4521 | if (!ret_val) |
| 4522 | hw->mac.collision_delta = phy_data; |
| 4523 | |
| 4524 | /* Defer Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4525 | hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data); |
| 4526 | 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] | 4527 | if (!ret_val) |
| 4528 | adapter->stats.dc += phy_data; |
| 4529 | |
| 4530 | /* Transmit with no CRS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4531 | hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data); |
| 4532 | 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] | 4533 | if (!ret_val) |
| 4534 | adapter->stats.tncrs += phy_data; |
| 4535 | |
| 4536 | release: |
| 4537 | hw->phy.ops.release(hw); |
| 4538 | } |
| 4539 | |
| 4540 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4541 | * e1000e_update_stats - Update the board statistics counters |
| 4542 | * @adapter: board private structure |
| 4543 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4544 | static void e1000e_update_stats(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4545 | { |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4546 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4547 | struct e1000_hw *hw = &adapter->hw; |
| 4548 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4549 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4550 | /* Prevent stats update while adapter is being reset, or if the pci |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4551 | * connection is down. |
| 4552 | */ |
| 4553 | if (adapter->link_speed == 0) |
| 4554 | return; |
| 4555 | if (pci_channel_offline(pdev)) |
| 4556 | return; |
| 4557 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4558 | adapter->stats.crcerrs += er32(CRCERRS); |
| 4559 | adapter->stats.gprc += er32(GPRC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4560 | adapter->stats.gorc += er32(GORCL); |
| 4561 | er32(GORCH); /* Clear gorc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4562 | adapter->stats.bprc += er32(BPRC); |
| 4563 | adapter->stats.mprc += er32(MPRC); |
| 4564 | adapter->stats.roc += er32(ROC); |
| 4565 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4566 | adapter->stats.mpc += er32(MPC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4567 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4568 | /* Half-duplex statistics */ |
| 4569 | if (adapter->link_duplex == HALF_DUPLEX) { |
| 4570 | if (adapter->flags2 & FLAG2_HAS_PHY_STATS) { |
| 4571 | e1000e_update_phy_stats(adapter); |
| 4572 | } else { |
| 4573 | adapter->stats.scc += er32(SCC); |
| 4574 | adapter->stats.ecol += er32(ECOL); |
| 4575 | adapter->stats.mcc += er32(MCC); |
| 4576 | adapter->stats.latecol += er32(LATECOL); |
| 4577 | adapter->stats.dc += er32(DC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4578 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4579 | hw->mac.collision_delta = er32(COLC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4580 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4581 | if ((hw->mac.type != e1000_82574) && |
| 4582 | (hw->mac.type != e1000_82583)) |
| 4583 | adapter->stats.tncrs += er32(TNCRS); |
| 4584 | } |
| 4585 | adapter->stats.colc += hw->mac.collision_delta; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4586 | } |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4587 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4588 | adapter->stats.xonrxc += er32(XONRXC); |
| 4589 | adapter->stats.xontxc += er32(XONTXC); |
| 4590 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 4591 | adapter->stats.xofftxc += er32(XOFFTXC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4592 | adapter->stats.gptc += er32(GPTC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4593 | adapter->stats.gotc += er32(GOTCL); |
| 4594 | er32(GOTCH); /* Clear gotc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4595 | adapter->stats.rnbc += er32(RNBC); |
| 4596 | adapter->stats.ruc += er32(RUC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4597 | |
| 4598 | adapter->stats.mptc += er32(MPTC); |
| 4599 | adapter->stats.bptc += er32(BPTC); |
| 4600 | |
| 4601 | /* used for adaptive IFS */ |
| 4602 | |
| 4603 | hw->mac.tx_packet_delta = er32(TPT); |
| 4604 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4605 | |
| 4606 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 4607 | adapter->stats.rxerrc += er32(RXERRC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4608 | adapter->stats.cexterr += er32(CEXTERR); |
| 4609 | adapter->stats.tsctc += er32(TSCTC); |
| 4610 | adapter->stats.tsctfc += er32(TSCTFC); |
| 4611 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4612 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4613 | netdev->stats.multicast = adapter->stats.mprc; |
| 4614 | netdev->stats.collisions = adapter->stats.colc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4615 | |
| 4616 | /* Rx Errors */ |
| 4617 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4618 | /* RLEC on some newer hardware can be incorrect so build |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4619 | * our own version based on RUC and ROC |
| 4620 | */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4621 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 4622 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 4623 | adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4624 | netdev->stats.rx_length_errors = adapter->stats.ruc + |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 4625 | adapter->stats.roc; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4626 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4627 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; |
| 4628 | netdev->stats.rx_missed_errors = adapter->stats.mpc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4629 | |
| 4630 | /* Tx Errors */ |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 4631 | netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4632 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
| 4633 | netdev->stats.tx_window_errors = adapter->stats.latecol; |
| 4634 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4635 | |
| 4636 | /* Tx Dropped needs to be maintained elsewhere */ |
| 4637 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4638 | /* Management Stats */ |
| 4639 | adapter->stats.mgptc += er32(MGTPTC); |
| 4640 | adapter->stats.mgprc += er32(MGTPRC); |
| 4641 | adapter->stats.mgpdc += er32(MGTPDC); |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 4642 | |
| 4643 | /* Correctable ECC Errors */ |
| 4644 | if (hw->mac.type == e1000_pch_lpt) { |
| 4645 | u32 pbeccsts = er32(PBECCSTS); |
| 4646 | adapter->corr_errors += |
| 4647 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 4648 | adapter->uncorr_errors += |
| 4649 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 4650 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 4651 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4652 | } |
| 4653 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4654 | /** |
| 4655 | * e1000_phy_read_status - Update the PHY register status snapshot |
| 4656 | * @adapter: board private structure |
| 4657 | **/ |
| 4658 | static void e1000_phy_read_status(struct e1000_adapter *adapter) |
| 4659 | { |
| 4660 | struct e1000_hw *hw = &adapter->hw; |
| 4661 | struct e1000_phy_regs *phy = &adapter->phy_regs; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4662 | |
| 4663 | if ((er32(STATUS) & E1000_STATUS_LU) && |
| 4664 | (adapter->hw.phy.media_type == e1000_media_type_copper)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4665 | int ret_val; |
| 4666 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 4667 | ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr); |
| 4668 | ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr); |
| 4669 | ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise); |
| 4670 | ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa); |
| 4671 | ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion); |
| 4672 | ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000); |
| 4673 | ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000); |
| 4674 | ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4675 | if (ret_val) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4676 | e_warn("Error reading PHY register\n"); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4677 | } else { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4678 | /* Do not read PHY registers if link is not up |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4679 | * Set values to typical power-on defaults |
| 4680 | */ |
| 4681 | phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); |
| 4682 | phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | |
| 4683 | BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | |
| 4684 | BMSR_ERCAP); |
| 4685 | phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | |
| 4686 | ADVERTISE_ALL | ADVERTISE_CSMA); |
| 4687 | phy->lpa = 0; |
| 4688 | phy->expansion = EXPANSION_ENABLENPAGE; |
| 4689 | phy->ctrl1000 = ADVERTISE_1000FULL; |
| 4690 | phy->stat1000 = 0; |
| 4691 | phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); |
| 4692 | } |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4693 | } |
| 4694 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4695 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
| 4696 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4697 | struct e1000_hw *hw = &adapter->hw; |
| 4698 | u32 ctrl = er32(CTRL); |
| 4699 | |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4700 | /* Link status message must follow this format for user tools */ |
Bruce Allan | 7dbc167 | 2013-01-12 03:11:25 +0000 | [diff] [blame] | 4701 | pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n", |
| 4702 | adapter->netdev->name, adapter->link_speed, |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 4703 | adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half", |
| 4704 | (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" : |
| 4705 | (ctrl & E1000_CTRL_RFCE) ? "Rx" : |
| 4706 | (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4707 | } |
| 4708 | |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 4709 | static bool e1000e_has_link(struct e1000_adapter *adapter) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4710 | { |
| 4711 | struct e1000_hw *hw = &adapter->hw; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4712 | bool link_active = false; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4713 | s32 ret_val = 0; |
| 4714 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4715 | /* get_link_status is set on LSC (link status) interrupt or |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4716 | * Rx sequence error interrupt. get_link_status will stay |
| 4717 | * false until the check_for_link establishes link |
| 4718 | * for copper adapters ONLY |
| 4719 | */ |
| 4720 | switch (hw->phy.media_type) { |
| 4721 | case e1000_media_type_copper: |
| 4722 | if (hw->mac.get_link_status) { |
| 4723 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4724 | link_active = !hw->mac.get_link_status; |
| 4725 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4726 | link_active = true; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4727 | } |
| 4728 | break; |
| 4729 | case e1000_media_type_fiber: |
| 4730 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4731 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 4732 | break; |
| 4733 | case e1000_media_type_internal_serdes: |
| 4734 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4735 | link_active = adapter->hw.mac.serdes_has_link; |
| 4736 | break; |
| 4737 | default: |
| 4738 | case e1000_media_type_unknown: |
| 4739 | break; |
| 4740 | } |
| 4741 | |
| 4742 | if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && |
| 4743 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 4744 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4745 | e_info("Gigabit has been disabled, downgrading speed\n"); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | return link_active; |
| 4749 | } |
| 4750 | |
| 4751 | static void e1000e_enable_receives(struct e1000_adapter *adapter) |
| 4752 | { |
| 4753 | /* make sure the receive unit is started */ |
| 4754 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 4755 | (adapter->flags & FLAG_RESTART_NOW)) { |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4756 | struct e1000_hw *hw = &adapter->hw; |
| 4757 | u32 rctl = er32(RCTL); |
| 4758 | ew32(RCTL, rctl | E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 4759 | adapter->flags &= ~FLAG_RESTART_NOW; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4760 | } |
| 4761 | } |
| 4762 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4763 | static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter) |
| 4764 | { |
| 4765 | struct e1000_hw *hw = &adapter->hw; |
| 4766 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4767 | /* With 82574 controllers, PHY needs to be checked periodically |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4768 | * for hung state and reset, if two calls return true |
| 4769 | */ |
| 4770 | if (e1000_check_phy_82574(hw)) |
| 4771 | adapter->phy_hang_count++; |
| 4772 | else |
| 4773 | adapter->phy_hang_count = 0; |
| 4774 | |
| 4775 | if (adapter->phy_hang_count > 1) { |
| 4776 | adapter->phy_hang_count = 0; |
| 4777 | schedule_work(&adapter->reset_task); |
| 4778 | } |
| 4779 | } |
| 4780 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4781 | /** |
| 4782 | * e1000_watchdog - Timer Call-back |
| 4783 | * @data: pointer to adapter cast into an unsigned long |
| 4784 | **/ |
| 4785 | static void e1000_watchdog(unsigned long data) |
| 4786 | { |
Bruce Allan | 53aa82d | 2013-02-20 04:06:06 +0000 | [diff] [blame^] | 4787 | struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4788 | |
| 4789 | /* Do the rest outside of interrupt context */ |
| 4790 | schedule_work(&adapter->watchdog_task); |
| 4791 | |
| 4792 | /* TODO: make this use queue_delayed_work() */ |
| 4793 | } |
| 4794 | |
| 4795 | static void e1000_watchdog_task(struct work_struct *work) |
| 4796 | { |
| 4797 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 4798 | struct e1000_adapter, |
| 4799 | watchdog_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4800 | struct net_device *netdev = adapter->netdev; |
| 4801 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4802 | struct e1000_phy_info *phy = &adapter->hw.phy; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4803 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4804 | struct e1000_hw *hw = &adapter->hw; |
| 4805 | u32 link, tctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4806 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4807 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4808 | return; |
| 4809 | |
David S. Miller | b405e8d | 2010-02-04 22:31:41 -0800 | [diff] [blame] | 4810 | link = e1000e_has_link(adapter); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4811 | if ((netif_carrier_ok(netdev)) && link) { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4812 | /* Cancel scheduled suspend requests. */ |
| 4813 | pm_runtime_resume(netdev->dev.parent); |
| 4814 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4815 | e1000e_enable_receives(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4816 | goto link_up; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4817 | } |
| 4818 | |
| 4819 | if ((e1000e_enable_tx_pkt_filtering(hw)) && |
| 4820 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) |
| 4821 | e1000_update_mng_vlan(adapter); |
| 4822 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4823 | if (link) { |
| 4824 | if (!netif_carrier_ok(netdev)) { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4825 | bool txb2b = true; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4826 | |
| 4827 | /* Cancel scheduled suspend requests. */ |
| 4828 | pm_runtime_resume(netdev->dev.parent); |
| 4829 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4830 | /* update snapshot of PHY registers on LSC */ |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4831 | e1000_phy_read_status(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4832 | mac->ops.get_link_up_info(&adapter->hw, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 4833 | &adapter->link_speed, |
| 4834 | &adapter->link_duplex); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4835 | e1000_print_link_info(adapter); |
Koki Sanagi | e792cd9 | 2013-02-03 14:03:55 +0000 | [diff] [blame] | 4836 | |
| 4837 | /* check if SmartSpeed worked */ |
| 4838 | e1000e_check_downshift(hw); |
| 4839 | if (phy->speed_downgraded) |
| 4840 | netdev_warn(netdev, |
| 4841 | "Link Speed was downgraded by SmartSpeed\n"); |
| 4842 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4843 | /* On supported PHYs, check for duplex mismatch only |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 4844 | * if link has autonegotiated at 10/100 half |
| 4845 | */ |
| 4846 | if ((hw->phy.type == e1000_phy_igp_3 || |
| 4847 | hw->phy.type == e1000_phy_bm) && |
| 4848 | (hw->mac.autoneg == true) && |
| 4849 | (adapter->link_speed == SPEED_10 || |
| 4850 | adapter->link_speed == SPEED_100) && |
| 4851 | (adapter->link_duplex == HALF_DUPLEX)) { |
| 4852 | u16 autoneg_exp; |
| 4853 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 4854 | e1e_rphy(hw, MII_EXPANSION, &autoneg_exp); |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 4855 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 4856 | if (!(autoneg_exp & EXPANSION_NWAY)) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 4857 | 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] | 4858 | } |
| 4859 | |
Emil Tantilov | f49c57e | 2010-03-24 12:55:02 +0000 | [diff] [blame] | 4860 | /* adjust timeout factor according to speed/duplex */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4861 | adapter->tx_timeout_factor = 1; |
| 4862 | switch (adapter->link_speed) { |
| 4863 | case SPEED_10: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4864 | txb2b = false; |
Bruce Allan | 10f1b49 | 2008-08-08 18:36:01 -0700 | [diff] [blame] | 4865 | adapter->tx_timeout_factor = 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4866 | break; |
| 4867 | case SPEED_100: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4868 | txb2b = false; |
Bruce Allan | 4c86e0b | 2009-11-19 12:35:26 +0000 | [diff] [blame] | 4869 | adapter->tx_timeout_factor = 10; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4870 | break; |
| 4871 | } |
| 4872 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4873 | /* workaround: re-program speed mode bit after |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4874 | * link-up event |
| 4875 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4876 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
| 4877 | !txb2b) { |
| 4878 | u32 tarc0; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4879 | tarc0 = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4880 | tarc0 &= ~SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4881 | ew32(TARC(0), tarc0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4882 | } |
| 4883 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4884 | /* disable TSO for pcie and 10/100 speeds, to avoid |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4885 | * some hardware issues |
| 4886 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4887 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
| 4888 | switch (adapter->link_speed) { |
| 4889 | case SPEED_10: |
| 4890 | case SPEED_100: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4891 | e_info("10/100 speed: disabling TSO\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4892 | netdev->features &= ~NETIF_F_TSO; |
| 4893 | netdev->features &= ~NETIF_F_TSO6; |
| 4894 | break; |
| 4895 | case SPEED_1000: |
| 4896 | netdev->features |= NETIF_F_TSO; |
| 4897 | netdev->features |= NETIF_F_TSO6; |
| 4898 | break; |
| 4899 | default: |
| 4900 | /* oops */ |
| 4901 | break; |
| 4902 | } |
| 4903 | } |
| 4904 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4905 | /* enable transmits in the hardware, need to do this |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4906 | * after setting TARC(0) |
| 4907 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4908 | tctl = er32(TCTL); |
| 4909 | tctl |= E1000_TCTL_EN; |
| 4910 | ew32(TCTL, tctl); |
| 4911 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4912 | /* Perform any post-link-up configuration before |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4913 | * reporting link up. |
| 4914 | */ |
| 4915 | if (phy->ops.cfg_on_link_up) |
| 4916 | phy->ops.cfg_on_link_up(hw); |
| 4917 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4918 | netif_carrier_on(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4919 | |
| 4920 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4921 | mod_timer(&adapter->phy_info_timer, |
| 4922 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4923 | } |
| 4924 | } else { |
| 4925 | if (netif_carrier_ok(netdev)) { |
| 4926 | adapter->link_speed = 0; |
| 4927 | adapter->link_duplex = 0; |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4928 | /* Link status message must follow this format */ |
Bruce Allan | 7dbc167 | 2013-01-12 03:11:25 +0000 | [diff] [blame] | 4929 | pr_info("%s NIC Link is Down\n", adapter->netdev->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4930 | netif_carrier_off(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4931 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4932 | mod_timer(&adapter->phy_info_timer, |
| 4933 | round_jiffies(jiffies + 2 * HZ)); |
| 4934 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 4935 | /* The link is lost so the controller stops DMA. |
| 4936 | * If there is queued Tx work that cannot be done |
| 4937 | * or if on an 8000ES2LAN which requires a Rx packet |
| 4938 | * buffer work-around on link down event, reset the |
| 4939 | * controller to flush the Tx/Rx packet buffers. |
| 4940 | * (Do the reset outside of interrupt context). |
| 4941 | */ |
| 4942 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) || |
| 4943 | (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) |
| 4944 | adapter->flags |= FLAG_RESTART_NOW; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4945 | else |
| 4946 | pm_schedule_suspend(netdev->dev.parent, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 4947 | LINK_TIMEOUT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4948 | } |
| 4949 | } |
| 4950 | |
| 4951 | link_up: |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4952 | spin_lock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4953 | e1000e_update_stats(adapter); |
| 4954 | |
| 4955 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 4956 | adapter->tpt_old = adapter->stats.tpt; |
| 4957 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; |
| 4958 | adapter->colc_old = adapter->stats.colc; |
| 4959 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4960 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
| 4961 | adapter->gorc_old = adapter->stats.gorc; |
| 4962 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; |
| 4963 | adapter->gotc_old = adapter->stats.gotc; |
Flavio Leitner | 2084b11 | 2011-04-05 04:27:43 +0000 | [diff] [blame] | 4964 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4965 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 4966 | if (adapter->flags & FLAG_RESTART_NOW) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4967 | schedule_work(&adapter->reset_task); |
| 4968 | /* return immediately since reset is imminent */ |
| 4969 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4970 | } |
| 4971 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 4972 | e1000e_update_adaptive(&adapter->hw); |
| 4973 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4974 | /* Simple mode for Interrupt Throttle Rate (ITR) */ |
| 4975 | if (adapter->itr_setting == 4) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4976 | /* Symmetric Tx/Rx gets a reduced ITR=2000; |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4977 | * Total asymmetrical Tx or Rx gets ITR=8000; |
| 4978 | * everyone else is between 2000-8000. |
| 4979 | */ |
| 4980 | u32 goc = (adapter->gotc + adapter->gorc) / 10000; |
| 4981 | u32 dif = (adapter->gotc > adapter->gorc ? |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 4982 | adapter->gotc - adapter->gorc : |
| 4983 | adapter->gorc - adapter->gotc) / 10000; |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4984 | u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 4985 | |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 4986 | e1000e_write_itr(adapter, itr); |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4987 | } |
| 4988 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4989 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4990 | if (adapter->msix_entries) |
| 4991 | ew32(ICS, adapter->rx_ring->ims_val); |
| 4992 | else |
| 4993 | ew32(ICS, E1000_ICS_RXDMT0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4994 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4995 | /* flush pending descriptors to memory before detecting Tx hang */ |
| 4996 | e1000e_flush_descriptors(adapter); |
| 4997 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4998 | /* Force detection of hung controller every watchdog period */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4999 | adapter->detect_tx_hung = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5000 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5001 | /* With 82571 controllers, LAA may be overwritten due to controller |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5002 | * reset from the other port. Set the appropriate LAA in RAR[0] |
| 5003 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5004 | if (e1000e_get_laa_state_82571(hw)) |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 5005 | hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5006 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 5007 | if (adapter->flags2 & FLAG2_CHECK_PHY_HANG) |
| 5008 | e1000e_check_82574_phy_workaround(adapter); |
| 5009 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5010 | /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */ |
| 5011 | if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) { |
| 5012 | if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) && |
| 5013 | (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) { |
| 5014 | er32(RXSTMPH); |
| 5015 | adapter->rx_hwtstamp_cleared++; |
| 5016 | } else { |
| 5017 | adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP; |
| 5018 | } |
| 5019 | } |
| 5020 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5021 | /* Reset the timer */ |
| 5022 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 5023 | mod_timer(&adapter->watchdog_timer, |
| 5024 | round_jiffies(jiffies + 2 * HZ)); |
| 5025 | } |
| 5026 | |
| 5027 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 5028 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 5029 | #define E1000_TX_FLAGS_TSO 0x00000004 |
| 5030 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5031 | #define E1000_TX_FLAGS_NO_FCS 0x00000010 |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5032 | #define E1000_TX_FLAGS_HWTSTAMP 0x00000020 |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5033 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 5034 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 5035 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5036 | 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] | 5037 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5038 | struct e1000_context_desc *context_desc; |
| 5039 | struct e1000_buffer *buffer_info; |
| 5040 | unsigned int i; |
| 5041 | u32 cmd_length = 0; |
Bruce Allan | 70443ae | 2012-08-17 06:18:13 +0000 | [diff] [blame] | 5042 | u16 ipcse = 0, mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5043 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5044 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5045 | if (!skb_is_gso(skb)) |
| 5046 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5047 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5048 | if (skb_header_cloned(skb)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 5049 | int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 5050 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5051 | if (err) |
| 5052 | return err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5053 | } |
| 5054 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5055 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 5056 | mss = skb_shinfo(skb)->gso_size; |
| 5057 | if (skb->protocol == htons(ETH_P_IP)) { |
| 5058 | struct iphdr *iph = ip_hdr(skb); |
| 5059 | iph->tot_len = 0; |
| 5060 | iph->check = 0; |
| 5061 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5062 | 0, IPPROTO_TCP, 0); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5063 | cmd_length = E1000_TXD_CMD_IP; |
| 5064 | ipcse = skb_transport_offset(skb) - 1; |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 5065 | } else if (skb_is_gso_v6(skb)) { |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5066 | ipv6_hdr(skb)->payload_len = 0; |
| 5067 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5068 | &ipv6_hdr(skb)->daddr, |
| 5069 | 0, IPPROTO_TCP, 0); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5070 | ipcse = 0; |
| 5071 | } |
| 5072 | ipcss = skb_network_offset(skb); |
| 5073 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
| 5074 | tucss = skb_transport_offset(skb); |
| 5075 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5076 | |
| 5077 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5078 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5079 | |
| 5080 | i = tx_ring->next_to_use; |
| 5081 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 5082 | buffer_info = &tx_ring->buffer_info[i]; |
| 5083 | |
| 5084 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 5085 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 5086 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 5087 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 5088 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
Bruce Allan | 70443ae | 2012-08-17 06:18:13 +0000 | [diff] [blame] | 5089 | context_desc->upper_setup.tcp_fields.tucse = 0; |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5090 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 5091 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 5092 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 5093 | |
| 5094 | buffer_info->time_stamp = jiffies; |
| 5095 | buffer_info->next_to_watch = i; |
| 5096 | |
| 5097 | i++; |
| 5098 | if (i == tx_ring->count) |
| 5099 | i = 0; |
| 5100 | tx_ring->next_to_use = i; |
| 5101 | |
| 5102 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5103 | } |
| 5104 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5105 | 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] | 5106 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5107 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5108 | struct e1000_context_desc *context_desc; |
| 5109 | struct e1000_buffer *buffer_info; |
| 5110 | unsigned int i; |
| 5111 | u8 css; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5112 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 5113 | __be16 protocol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5114 | |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5115 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 5116 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5117 | |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 5118 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) |
| 5119 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 5120 | else |
| 5121 | protocol = skb->protocol; |
| 5122 | |
Arthur Jones | 3f51839 | 2009-03-20 15:56:35 -0700 | [diff] [blame] | 5123 | switch (protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5124 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5125 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 5126 | cmd_len |= E1000_TXD_CMD_TCP; |
| 5127 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5128 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5129 | /* XXX not handling all IPV6 headers */ |
| 5130 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 5131 | cmd_len |= E1000_TXD_CMD_TCP; |
| 5132 | break; |
| 5133 | default: |
| 5134 | if (unlikely(net_ratelimit())) |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 5135 | e_warn("checksum_partial proto=%x!\n", |
| 5136 | be16_to_cpu(protocol)); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5137 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 5140 | css = skb_checksum_start_offset(skb); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5141 | |
| 5142 | i = tx_ring->next_to_use; |
| 5143 | buffer_info = &tx_ring->buffer_info[i]; |
| 5144 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 5145 | |
| 5146 | context_desc->lower_setup.ip_config = 0; |
| 5147 | context_desc->upper_setup.tcp_fields.tucss = css; |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5148 | context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5149 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 5150 | context_desc->tcp_seg_setup.data = 0; |
| 5151 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 5152 | |
| 5153 | buffer_info->time_stamp = jiffies; |
| 5154 | buffer_info->next_to_watch = i; |
| 5155 | |
| 5156 | i++; |
| 5157 | if (i == tx_ring->count) |
| 5158 | i = 0; |
| 5159 | tx_ring->next_to_use = i; |
| 5160 | |
| 5161 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5162 | } |
| 5163 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5164 | static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb, |
| 5165 | unsigned int first, unsigned int max_per_txd, |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5166 | unsigned int nr_frags) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5167 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5168 | struct e1000_adapter *adapter = tx_ring->adapter; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5169 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5170 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 5171 | unsigned int len = skb_headlen(skb); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5172 | unsigned int offset = 0, size, count = 0, i; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5173 | unsigned int f, bytecount, segs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5174 | |
| 5175 | i = tx_ring->next_to_use; |
| 5176 | |
| 5177 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5178 | buffer_info = &tx_ring->buffer_info[i]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5179 | size = min(len, max_per_txd); |
| 5180 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5181 | buffer_info->length = size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5182 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5183 | buffer_info->next_to_watch = i; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5184 | buffer_info->dma = dma_map_single(&pdev->dev, |
| 5185 | skb->data + offset, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5186 | size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5187 | buffer_info->mapped_as_page = false; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5188 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5189 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5190 | |
| 5191 | len -= size; |
| 5192 | offset += size; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5193 | count++; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5194 | |
| 5195 | if (len) { |
| 5196 | i++; |
| 5197 | if (i == tx_ring->count) |
| 5198 | i = 0; |
| 5199 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | for (f = 0; f < nr_frags; f++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5203 | const struct skb_frag_struct *frag; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5204 | |
| 5205 | frag = &skb_shinfo(skb)->frags[f]; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5206 | len = skb_frag_size(frag); |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 5207 | offset = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5208 | |
| 5209 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5210 | i++; |
| 5211 | if (i == tx_ring->count) |
| 5212 | i = 0; |
| 5213 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5214 | buffer_info = &tx_ring->buffer_info[i]; |
| 5215 | size = min(len, max_per_txd); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5216 | |
| 5217 | buffer_info->length = size; |
| 5218 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5219 | buffer_info->next_to_watch = i; |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 5220 | buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5221 | offset, size, |
| 5222 | DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5223 | buffer_info->mapped_as_page = true; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5224 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5225 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5226 | |
| 5227 | len -= size; |
| 5228 | offset += size; |
| 5229 | count++; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5230 | } |
| 5231 | } |
| 5232 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5233 | segs = skb_shinfo(skb)->gso_segs ? : 1; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5234 | /* multiply data chunks by size of headers */ |
| 5235 | bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len; |
| 5236 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5237 | tx_ring->buffer_info[i].skb = skb; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5238 | tx_ring->buffer_info[i].segs = segs; |
| 5239 | tx_ring->buffer_info[i].bytecount = bytecount; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5240 | tx_ring->buffer_info[first].next_to_watch = i; |
| 5241 | |
| 5242 | return count; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5243 | |
| 5244 | dma_error: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5245 | dev_err(&pdev->dev, "Tx DMA map failed\n"); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5246 | buffer_info->dma = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5247 | if (count) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5248 | count--; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5249 | |
| 5250 | while (count--) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5251 | if (i == 0) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5252 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5253 | i--; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5254 | buffer_info = &tx_ring->buffer_info[i]; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5255 | e1000_put_txbuf(tx_ring, buffer_info); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5256 | } |
| 5257 | |
| 5258 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5259 | } |
| 5260 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5261 | 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] | 5262 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5263 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5264 | struct e1000_tx_desc *tx_desc = NULL; |
| 5265 | struct e1000_buffer *buffer_info; |
| 5266 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 5267 | unsigned int i; |
| 5268 | |
| 5269 | if (tx_flags & E1000_TX_FLAGS_TSO) { |
| 5270 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5271 | E1000_TXD_CMD_TSE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5272 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 5273 | |
| 5274 | if (tx_flags & E1000_TX_FLAGS_IPV4) |
| 5275 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
| 5276 | } |
| 5277 | |
| 5278 | if (tx_flags & E1000_TX_FLAGS_CSUM) { |
| 5279 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 5280 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 5281 | } |
| 5282 | |
| 5283 | if (tx_flags & E1000_TX_FLAGS_VLAN) { |
| 5284 | txd_lower |= E1000_TXD_CMD_VLE; |
| 5285 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 5286 | } |
| 5287 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5288 | if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS)) |
| 5289 | txd_lower &= ~(E1000_TXD_CMD_IFCS); |
| 5290 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5291 | if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) { |
| 5292 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 5293 | txd_upper |= E1000_TXD_EXTCMD_TSTAMP; |
| 5294 | } |
| 5295 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5296 | i = tx_ring->next_to_use; |
| 5297 | |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 5298 | do { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5299 | buffer_info = &tx_ring->buffer_info[i]; |
| 5300 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 5301 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5302 | tx_desc->lower.data = cpu_to_le32(txd_lower | |
| 5303 | buffer_info->length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5304 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
| 5305 | |
| 5306 | i++; |
| 5307 | if (i == tx_ring->count) |
| 5308 | i = 0; |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 5309 | } while (--count > 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5310 | |
| 5311 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 5312 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5313 | /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */ |
| 5314 | if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS)) |
| 5315 | tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS)); |
| 5316 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5317 | /* Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5318 | * know there are new descriptors to fetch. (Only |
| 5319 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5320 | * such as IA-64). |
| 5321 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5322 | wmb(); |
| 5323 | |
| 5324 | tx_ring->next_to_use = i; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 5325 | |
| 5326 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5327 | e1000e_update_tdt_wa(tx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 5328 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 5329 | writel(i, tx_ring->tail); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 5330 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5331 | /* we need this if more than one processor can write to our tail |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5332 | * at a time, it synchronizes IO on IA64/Altix systems |
| 5333 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5334 | mmiowb(); |
| 5335 | } |
| 5336 | |
| 5337 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 5338 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 5339 | struct sk_buff *skb) |
| 5340 | { |
| 5341 | struct e1000_hw *hw = &adapter->hw; |
| 5342 | u16 length, offset; |
| 5343 | |
Bruce Allan | d60923c | 2012-12-05 06:26:56 +0000 | [diff] [blame] | 5344 | if (vlan_tx_tag_present(skb) && |
| 5345 | !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
| 5346 | (adapter->hw.mng_cookie.status & |
| 5347 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) |
| 5348 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5349 | |
| 5350 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) |
| 5351 | return 0; |
| 5352 | |
Bruce Allan | 53aa82d | 2013-02-20 04:06:06 +0000 | [diff] [blame^] | 5353 | if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5354 | return 0; |
| 5355 | |
| 5356 | { |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 5357 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5358 | struct udphdr *udp; |
| 5359 | |
| 5360 | if (ip->protocol != IPPROTO_UDP) |
| 5361 | return 0; |
| 5362 | |
| 5363 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 5364 | if (ntohs(udp->dest) != 67) |
| 5365 | return 0; |
| 5366 | |
| 5367 | offset = (u8 *)udp + 8 - skb->data; |
| 5368 | length = skb->len - offset; |
| 5369 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); |
| 5370 | } |
| 5371 | |
| 5372 | return 0; |
| 5373 | } |
| 5374 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5375 | 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] | 5376 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5377 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5378 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5379 | netif_stop_queue(adapter->netdev); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5380 | /* Herbert's original patch had: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5381 | * smp_mb__after_netif_stop_queue(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5382 | * but since that doesn't exist yet, just open code it. |
| 5383 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5384 | smp_mb(); |
| 5385 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5386 | /* We need to check again in a case another CPU has just |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5387 | * made room available. |
| 5388 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5389 | if (e1000_desc_unused(tx_ring) < size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5390 | return -EBUSY; |
| 5391 | |
| 5392 | /* A reprieve! */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5393 | netif_start_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5394 | ++adapter->restart_queue; |
| 5395 | return 0; |
| 5396 | } |
| 5397 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5398 | 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] | 5399 | { |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5400 | BUG_ON(size > tx_ring->count); |
| 5401 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5402 | if (e1000_desc_unused(tx_ring) >= size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5403 | return 0; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5404 | return __e1000_maybe_stop_tx(tx_ring, size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5405 | } |
| 5406 | |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 5407 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 5408 | struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5409 | { |
| 5410 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5411 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 5412 | unsigned int first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5413 | unsigned int tx_flags = 0; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5414 | unsigned int len = skb_headlen(skb); |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 5415 | unsigned int nr_frags; |
| 5416 | unsigned int mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5417 | int count = 0; |
| 5418 | int tso; |
| 5419 | unsigned int f; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5420 | |
| 5421 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 5422 | dev_kfree_skb_any(skb); |
| 5423 | return NETDEV_TX_OK; |
| 5424 | } |
| 5425 | |
| 5426 | if (skb->len <= 0) { |
| 5427 | dev_kfree_skb_any(skb); |
| 5428 | return NETDEV_TX_OK; |
| 5429 | } |
| 5430 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5431 | /* The minimum packet size with TCTL.PSP set is 17 bytes so |
Tushar Dave | 6e97c17 | 2012-09-14 02:21:37 +0000 | [diff] [blame] | 5432 | * pad skb in order to meet this minimum size requirement |
| 5433 | */ |
| 5434 | if (unlikely(skb->len < 17)) { |
| 5435 | if (skb_pad(skb, 17 - skb->len)) |
| 5436 | return NETDEV_TX_OK; |
| 5437 | skb->len = 17; |
| 5438 | skb_set_tail_pointer(skb, 17); |
| 5439 | } |
| 5440 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5441 | mss = skb_shinfo(skb)->gso_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5442 | if (mss) { |
| 5443 | u8 hdr_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5444 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5445 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5446 | * points to just header, pull a few bytes of payload from |
| 5447 | * frags into skb->data |
| 5448 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5449 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5450 | /* we do this workaround for ES2LAN, but it is un-necessary, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5451 | * avoiding it could save a lot of cycles |
| 5452 | */ |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 5453 | if (skb->data_len && (hdr_len == len)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5454 | unsigned int pull_size; |
| 5455 | |
Bruce Allan | a2a5b32 | 2012-01-31 06:37:17 +0000 | [diff] [blame] | 5456 | pull_size = min_t(unsigned int, 4, skb->data_len); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5457 | if (!__pskb_pull_tail(skb, pull_size)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5458 | e_err("__pskb_pull_tail failed.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5459 | dev_kfree_skb_any(skb); |
| 5460 | return NETDEV_TX_OK; |
| 5461 | } |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5462 | len = skb_headlen(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5463 | } |
| 5464 | } |
| 5465 | |
| 5466 | /* reserve a descriptor for the offload context */ |
| 5467 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5468 | count++; |
| 5469 | count++; |
| 5470 | |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5471 | count += DIV_ROUND_UP(len, adapter->tx_fifo_limit); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5472 | |
| 5473 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 5474 | for (f = 0; f < nr_frags; f++) |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5475 | count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]), |
| 5476 | adapter->tx_fifo_limit); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5477 | |
| 5478 | if (adapter->hw.mac.tx_pkt_filtering) |
| 5479 | e1000_transfer_dhcp_info(adapter, skb); |
| 5480 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5481 | /* need: count + 2 desc gap to keep tail from touching |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5482 | * head, otherwise try next time |
| 5483 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5484 | if (e1000_maybe_stop_tx(tx_ring, count + 2)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5485 | return NETDEV_TX_BUSY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5486 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 5487 | if (vlan_tx_tag_present(skb)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5488 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 5489 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 5490 | } |
| 5491 | |
| 5492 | first = tx_ring->next_to_use; |
| 5493 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5494 | tso = e1000_tso(tx_ring, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5495 | if (tso < 0) { |
| 5496 | dev_kfree_skb_any(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5497 | return NETDEV_TX_OK; |
| 5498 | } |
| 5499 | |
| 5500 | if (tso) |
| 5501 | tx_flags |= E1000_TX_FLAGS_TSO; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5502 | else if (e1000_tx_csum(tx_ring, skb)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5503 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 5504 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5505 | /* 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] | 5506 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5507 | * no longer assume, we must. |
| 5508 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5509 | if (skb->protocol == htons(ETH_P_IP)) |
| 5510 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 5511 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5512 | if (unlikely(skb->no_fcs)) |
| 5513 | tx_flags |= E1000_TX_FLAGS_NO_FCS; |
| 5514 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5515 | /* if count is 0 then mapping error has occurred */ |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5516 | count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit, |
| 5517 | nr_frags); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5518 | if (count) { |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5519 | if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 5520 | !adapter->tx_hwtstamp_skb)) { |
| 5521 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 5522 | tx_flags |= E1000_TX_FLAGS_HWTSTAMP; |
| 5523 | adapter->tx_hwtstamp_skb = skb_get(skb); |
| 5524 | schedule_work(&adapter->tx_hwtstamp_work); |
| 5525 | } else { |
| 5526 | skb_tx_timestamp(skb); |
| 5527 | } |
Willem de Bruijn | 80be312 | 2012-04-27 09:04:05 +0000 | [diff] [blame] | 5528 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 5529 | netdev_sent_queue(netdev, skb->len); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5530 | e1000_tx_queue(tx_ring, tx_flags, count); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5531 | /* Make sure there is space in the ring for the next send. */ |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5532 | e1000_maybe_stop_tx(tx_ring, |
| 5533 | (MAX_SKB_FRAGS * |
| 5534 | DIV_ROUND_UP(PAGE_SIZE, |
| 5535 | adapter->tx_fifo_limit) + 2)); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5536 | } else { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5537 | dev_kfree_skb_any(skb); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5538 | tx_ring->buffer_info[first].time_stamp = 0; |
| 5539 | tx_ring->next_to_use = first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5540 | } |
| 5541 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5542 | return NETDEV_TX_OK; |
| 5543 | } |
| 5544 | |
| 5545 | /** |
| 5546 | * e1000_tx_timeout - Respond to a Tx Hang |
| 5547 | * @netdev: network interface device structure |
| 5548 | **/ |
| 5549 | static void e1000_tx_timeout(struct net_device *netdev) |
| 5550 | { |
| 5551 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5552 | |
| 5553 | /* Do the reset outside of interrupt context */ |
| 5554 | adapter->tx_timeout_count++; |
| 5555 | schedule_work(&adapter->reset_task); |
| 5556 | } |
| 5557 | |
| 5558 | static void e1000_reset_task(struct work_struct *work) |
| 5559 | { |
| 5560 | struct e1000_adapter *adapter; |
| 5561 | adapter = container_of(work, struct e1000_adapter, reset_task); |
| 5562 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 5563 | /* don't run the task if already down */ |
| 5564 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 5565 | return; |
| 5566 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5567 | if (!(adapter->flags & FLAG_RESTART_NOW)) { |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 5568 | e1000e_dump(adapter); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5569 | e_err("Reset adapter unexpectedly\n"); |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 5570 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5571 | e1000e_reinit_locked(adapter); |
| 5572 | } |
| 5573 | |
| 5574 | /** |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5575 | * e1000_get_stats64 - Get System Network Statistics |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5576 | * @netdev: network interface device structure |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5577 | * @stats: rtnl_link_stats64 pointer |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5578 | * |
| 5579 | * Returns the address of the device statistics structure. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5580 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5581 | struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev, |
Bruce Allan | 66501f5 | 2013-02-20 04:05:55 +0000 | [diff] [blame] | 5582 | struct rtnl_link_stats64 *stats) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5583 | { |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5584 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5585 | |
| 5586 | memset(stats, 0, sizeof(struct rtnl_link_stats64)); |
| 5587 | spin_lock(&adapter->stats64_lock); |
| 5588 | e1000e_update_stats(adapter); |
| 5589 | /* Fill out the OS statistics structure */ |
| 5590 | stats->rx_bytes = adapter->stats.gorc; |
| 5591 | stats->rx_packets = adapter->stats.gprc; |
| 5592 | stats->tx_bytes = adapter->stats.gotc; |
| 5593 | stats->tx_packets = adapter->stats.gptc; |
| 5594 | stats->multicast = adapter->stats.mprc; |
| 5595 | stats->collisions = adapter->stats.colc; |
| 5596 | |
| 5597 | /* Rx Errors */ |
| 5598 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5599 | /* RLEC on some newer hardware can be incorrect so build |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5600 | * our own version based on RUC and ROC |
| 5601 | */ |
| 5602 | stats->rx_errors = adapter->stats.rxerrc + |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5603 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 5604 | adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr; |
| 5605 | stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc; |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5606 | stats->rx_crc_errors = adapter->stats.crcerrs; |
| 5607 | stats->rx_frame_errors = adapter->stats.algnerrc; |
| 5608 | stats->rx_missed_errors = adapter->stats.mpc; |
| 5609 | |
| 5610 | /* Tx Errors */ |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5611 | stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol; |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5612 | stats->tx_aborted_errors = adapter->stats.ecol; |
| 5613 | stats->tx_window_errors = adapter->stats.latecol; |
| 5614 | stats->tx_carrier_errors = adapter->stats.tncrs; |
| 5615 | |
| 5616 | /* Tx Dropped needs to be maintained elsewhere */ |
| 5617 | |
| 5618 | spin_unlock(&adapter->stats64_lock); |
| 5619 | return stats; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | /** |
| 5623 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 5624 | * @netdev: network interface device structure |
| 5625 | * @new_mtu: new value for maximum frame size |
| 5626 | * |
| 5627 | * Returns 0 on success, negative on failure |
| 5628 | **/ |
| 5629 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 5630 | { |
| 5631 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5632 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5633 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5634 | /* Jumbo frame support */ |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 5635 | if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) && |
| 5636 | !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
| 5637 | e_err("Jumbo Frames not supported.\n"); |
| 5638 | return -EINVAL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5639 | } |
| 5640 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5641 | /* Supported frame sizes */ |
| 5642 | if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) || |
| 5643 | (max_frame > adapter->max_hw_frame_size)) { |
| 5644 | e_err("Unsupported MTU setting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5645 | return -EINVAL; |
| 5646 | } |
| 5647 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 5648 | /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */ |
| 5649 | if ((adapter->hw.mac.type >= e1000_pch2lan) && |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 5650 | !(adapter->flags2 & FLAG2_CRC_STRIPPING) && |
| 5651 | (new_mtu > ETH_DATA_LEN)) { |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 5652 | e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n"); |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 5653 | return -EINVAL; |
| 5654 | } |
| 5655 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5656 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 5657 | usleep_range(1000, 2000); |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5658 | /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5659 | adapter->max_frame_size = max_frame; |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5660 | e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
| 5661 | netdev->mtu = new_mtu; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5662 | if (netif_running(netdev)) |
| 5663 | e1000e_down(adapter); |
| 5664 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5665 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5666 | * means we reserve 2 more, this pushes us to allocate from the next |
| 5667 | * larger slab size. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5668 | * i.e. RXBUFFER_2048 --> size-4096 slab |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5669 | * However with the new *_jumbo_rx* routines, jumbo receives will use |
| 5670 | * fragmented skbs |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5671 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5672 | |
Jesse Brandeburg | 9926146 | 2010-01-22 22:56:16 +0000 | [diff] [blame] | 5673 | if (max_frame <= 2048) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5674 | adapter->rx_buffer_len = 2048; |
| 5675 | else |
| 5676 | adapter->rx_buffer_len = 4096; |
| 5677 | |
| 5678 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
| 5679 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5680 | (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5681 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5682 | + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5683 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5684 | if (netif_running(netdev)) |
| 5685 | e1000e_up(adapter); |
| 5686 | else |
| 5687 | e1000e_reset(adapter); |
| 5688 | |
| 5689 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 5690 | |
| 5691 | return 0; |
| 5692 | } |
| 5693 | |
| 5694 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 5695 | int cmd) |
| 5696 | { |
| 5697 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5698 | struct mii_ioctl_data *data = if_mii(ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5699 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5700 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5701 | return -EOPNOTSUPP; |
| 5702 | |
| 5703 | switch (cmd) { |
| 5704 | case SIOCGMIIPHY: |
| 5705 | data->phy_id = adapter->hw.phy.addr; |
| 5706 | break; |
| 5707 | case SIOCGMIIREG: |
Bruce Allan | b16a002 | 2009-11-20 23:24:30 +0000 | [diff] [blame] | 5708 | e1000_phy_read_status(adapter); |
| 5709 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5710 | switch (data->reg_num & 0x1F) { |
| 5711 | case MII_BMCR: |
| 5712 | data->val_out = adapter->phy_regs.bmcr; |
| 5713 | break; |
| 5714 | case MII_BMSR: |
| 5715 | data->val_out = adapter->phy_regs.bmsr; |
| 5716 | break; |
| 5717 | case MII_PHYSID1: |
| 5718 | data->val_out = (adapter->hw.phy.id >> 16); |
| 5719 | break; |
| 5720 | case MII_PHYSID2: |
| 5721 | data->val_out = (adapter->hw.phy.id & 0xFFFF); |
| 5722 | break; |
| 5723 | case MII_ADVERTISE: |
| 5724 | data->val_out = adapter->phy_regs.advertise; |
| 5725 | break; |
| 5726 | case MII_LPA: |
| 5727 | data->val_out = adapter->phy_regs.lpa; |
| 5728 | break; |
| 5729 | case MII_EXPANSION: |
| 5730 | data->val_out = adapter->phy_regs.expansion; |
| 5731 | break; |
| 5732 | case MII_CTRL1000: |
| 5733 | data->val_out = adapter->phy_regs.ctrl1000; |
| 5734 | break; |
| 5735 | case MII_STAT1000: |
| 5736 | data->val_out = adapter->phy_regs.stat1000; |
| 5737 | break; |
| 5738 | case MII_ESTATUS: |
| 5739 | data->val_out = adapter->phy_regs.estatus; |
| 5740 | break; |
| 5741 | default: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5742 | return -EIO; |
| 5743 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5744 | break; |
| 5745 | case SIOCSMIIREG: |
| 5746 | default: |
| 5747 | return -EOPNOTSUPP; |
| 5748 | } |
| 5749 | return 0; |
| 5750 | } |
| 5751 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5752 | /** |
| 5753 | * e1000e_hwtstamp_ioctl - control hardware time stamping |
| 5754 | * @netdev: network interface device structure |
| 5755 | * @ifreq: interface request |
| 5756 | * |
| 5757 | * Outgoing time stamping can be enabled and disabled. Play nice and |
| 5758 | * disable it when requested, although it shouldn't cause any overhead |
| 5759 | * when no packet needs it. At most one packet in the queue may be |
| 5760 | * marked for time stamping, otherwise it would be impossible to tell |
| 5761 | * for sure to which packet the hardware time stamp belongs. |
| 5762 | * |
| 5763 | * Incoming time stamping has to be configured via the hardware filters. |
| 5764 | * Not all combinations are supported, in particular event type has to be |
| 5765 | * specified. Matching the kind of event packet is not supported, with the |
| 5766 | * exception of "all V2 events regardless of level 2 or 4". |
| 5767 | **/ |
| 5768 | static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr) |
| 5769 | { |
| 5770 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5771 | struct hwtstamp_config config; |
| 5772 | int ret_val; |
| 5773 | |
| 5774 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) |
| 5775 | return -EFAULT; |
| 5776 | |
| 5777 | adapter->hwtstamp_config = config; |
| 5778 | |
| 5779 | ret_val = e1000e_config_hwtstamp(adapter); |
| 5780 | if (ret_val) |
| 5781 | return ret_val; |
| 5782 | |
| 5783 | config = adapter->hwtstamp_config; |
| 5784 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 5785 | switch (config.rx_filter) { |
| 5786 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 5787 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 5788 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 5789 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 5790 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 5791 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 5792 | /* With V2 type filters which specify a Sync or Delay Request, |
| 5793 | * Path Delay Request/Response messages are also time stamped |
| 5794 | * by hardware so notify the caller the requested packets plus |
| 5795 | * some others are time stamped. |
| 5796 | */ |
| 5797 | config.rx_filter = HWTSTAMP_FILTER_SOME; |
| 5798 | break; |
| 5799 | default: |
| 5800 | break; |
| 5801 | } |
| 5802 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5803 | return copy_to_user(ifr->ifr_data, &config, |
| 5804 | sizeof(config)) ? -EFAULT : 0; |
| 5805 | } |
| 5806 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5807 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 5808 | { |
| 5809 | switch (cmd) { |
| 5810 | case SIOCGMIIPHY: |
| 5811 | case SIOCGMIIREG: |
| 5812 | case SIOCSMIIREG: |
| 5813 | return e1000_mii_ioctl(netdev, ifr, cmd); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5814 | case SIOCSHWTSTAMP: |
| 5815 | return e1000e_hwtstamp_ioctl(netdev, ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5816 | default: |
| 5817 | return -EOPNOTSUPP; |
| 5818 | } |
| 5819 | } |
| 5820 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5821 | static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) |
| 5822 | { |
| 5823 | struct e1000_hw *hw = &adapter->hw; |
| 5824 | u32 i, mac_reg; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5825 | u16 phy_reg, wuc_enable; |
Bruce Allan | 70806a7 | 2013-01-05 05:08:37 +0000 | [diff] [blame] | 5826 | int retval; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5827 | |
| 5828 | /* copy MAC RARs to PHY RARs */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 5829 | e1000_copy_rx_addrs_to_phy_ich8lan(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5830 | |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5831 | retval = hw->phy.ops.acquire(hw); |
| 5832 | if (retval) { |
| 5833 | e_err("Could not acquire PHY\n"); |
| 5834 | return retval; |
| 5835 | } |
| 5836 | |
| 5837 | /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */ |
| 5838 | retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
| 5839 | if (retval) |
Bruce Allan | 75ce153 | 2012-02-08 02:54:48 +0000 | [diff] [blame] | 5840 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5841 | |
| 5842 | /* copy MAC MTA to PHY MTA - only needed for pchlan */ |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5843 | for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { |
| 5844 | mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5845 | hw->phy.ops.write_reg_page(hw, BM_MTA(i), |
| 5846 | (u16)(mac_reg & 0xFFFF)); |
| 5847 | hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1, |
| 5848 | (u16)((mac_reg >> 16) & 0xFFFF)); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | /* configure PHY Rx Control register */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5852 | hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5853 | mac_reg = er32(RCTL); |
| 5854 | if (mac_reg & E1000_RCTL_UPE) |
| 5855 | phy_reg |= BM_RCTL_UPE; |
| 5856 | if (mac_reg & E1000_RCTL_MPE) |
| 5857 | phy_reg |= BM_RCTL_MPE; |
| 5858 | phy_reg &= ~(BM_RCTL_MO_MASK); |
| 5859 | if (mac_reg & E1000_RCTL_MO_3) |
| 5860 | phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5861 | << BM_RCTL_MO_SHIFT); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5862 | if (mac_reg & E1000_RCTL_BAM) |
| 5863 | phy_reg |= BM_RCTL_BAM; |
| 5864 | if (mac_reg & E1000_RCTL_PMCF) |
| 5865 | phy_reg |= BM_RCTL_PMCF; |
| 5866 | mac_reg = er32(CTRL); |
| 5867 | if (mac_reg & E1000_CTRL_RFCE) |
| 5868 | phy_reg |= BM_RCTL_RFCE; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5869 | hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5870 | |
| 5871 | /* enable PHY wakeup in MAC register */ |
| 5872 | ew32(WUFC, wufc); |
| 5873 | ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN); |
| 5874 | |
| 5875 | /* configure and enable PHY wakeup in PHY registers */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5876 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc); |
| 5877 | 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] | 5878 | |
| 5879 | /* activate PHY wakeup */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5880 | wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; |
| 5881 | retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5882 | if (retval) |
| 5883 | e_err("Could not set PHY Host Wakeup bit\n"); |
Bruce Allan | 75ce153 | 2012-02-08 02:54:48 +0000 | [diff] [blame] | 5884 | release: |
Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 5885 | hw->phy.ops.release(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5886 | |
| 5887 | return retval; |
| 5888 | } |
| 5889 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5890 | static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake, |
| 5891 | bool runtime) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5892 | { |
| 5893 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5894 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5895 | struct e1000_hw *hw = &adapter->hw; |
| 5896 | u32 ctrl, ctrl_ext, rctl, status; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5897 | /* Runtime suspend should only enable wakeup for link changes */ |
| 5898 | u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5899 | int retval = 0; |
| 5900 | |
| 5901 | netif_device_detach(netdev); |
| 5902 | |
| 5903 | if (netif_running(netdev)) { |
Bruce Allan | bb9e44d | 2012-03-21 00:39:12 +0000 | [diff] [blame] | 5904 | int count = E1000_CHECK_RESET_COUNT; |
| 5905 | |
| 5906 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) |
| 5907 | usleep_range(10000, 20000); |
| 5908 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5909 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 5910 | e1000e_down(adapter); |
| 5911 | e1000_free_irq(adapter); |
| 5912 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5913 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5914 | |
| 5915 | retval = pci_save_state(pdev); |
| 5916 | if (retval) |
| 5917 | return retval; |
| 5918 | |
| 5919 | status = er32(STATUS); |
| 5920 | if (status & E1000_STATUS_LU) |
| 5921 | wufc &= ~E1000_WUFC_LNKC; |
| 5922 | |
| 5923 | if (wufc) { |
| 5924 | e1000_setup_rctl(adapter); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 5925 | e1000e_set_rx_mode(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5926 | |
| 5927 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5928 | if (wufc & E1000_WUFC_MC) { |
| 5929 | rctl = er32(RCTL); |
| 5930 | rctl |= E1000_RCTL_MPE; |
| 5931 | ew32(RCTL, rctl); |
| 5932 | } |
| 5933 | |
| 5934 | ctrl = er32(CTRL); |
| 5935 | /* advertise wake from D3Cold */ |
| 5936 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5937 | /* phy power management enable */ |
| 5938 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5939 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 5940 | if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) |
| 5941 | ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5942 | ew32(CTRL, ctrl); |
| 5943 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5944 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
| 5945 | adapter->hw.phy.media_type == |
| 5946 | e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5947 | /* keep the laser running in D3 */ |
| 5948 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | 93a23f4 | 2009-12-08 07:27:41 +0000 | [diff] [blame] | 5949 | ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5950 | ew32(CTRL_EXT, ctrl_ext); |
| 5951 | } |
| 5952 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5953 | if (adapter->flags & FLAG_IS_ICH) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5954 | e1000_suspend_workarounds_ich8lan(&adapter->hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5955 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5956 | /* Allow time for pending master requests to run */ |
| 5957 | e1000e_disable_pcie_master(&adapter->hw); |
| 5958 | |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5959 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5960 | /* enable wakeup by the PHY */ |
| 5961 | retval = e1000_init_phy_wakeup(adapter, wufc); |
| 5962 | if (retval) |
| 5963 | return retval; |
| 5964 | } else { |
| 5965 | /* enable wakeup by the MAC */ |
| 5966 | ew32(WUFC, wufc); |
| 5967 | ew32(WUC, E1000_WUC_PME_EN); |
| 5968 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5969 | } else { |
| 5970 | ew32(WUC, 0); |
| 5971 | ew32(WUFC, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5972 | } |
| 5973 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5974 | *enable_wake = !!wufc; |
| 5975 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5976 | /* make sure adapter isn't asleep if manageability is enabled */ |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5977 | if ((adapter->flags & FLAG_MNG_PT_ENABLED) || |
| 5978 | (hw->mac.ops.check_mng_mode(hw))) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5979 | *enable_wake = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5980 | |
| 5981 | if (adapter->hw.phy.type == e1000_phy_igp_3) |
| 5982 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
| 5983 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5984 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5985 | * would have already happened in close and is redundant. |
| 5986 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5987 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5988 | |
| 5989 | pci_disable_device(pdev); |
| 5990 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5991 | return 0; |
| 5992 | } |
| 5993 | |
| 5994 | static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake) |
| 5995 | { |
| 5996 | if (sleep && wake) { |
| 5997 | pci_prepare_to_sleep(pdev); |
| 5998 | return; |
| 5999 | } |
| 6000 | |
| 6001 | pci_wake_from_d3(pdev, wake); |
| 6002 | pci_set_power_state(pdev, PCI_D3hot); |
| 6003 | } |
| 6004 | |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 6005 | static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, bool wake) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6006 | { |
| 6007 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6008 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6009 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6010 | /* The pci-e switch on some quad port adapters will report a |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6011 | * correctable error when the MAC transitions from D0 to D3. To |
| 6012 | * prevent this we need to mask off the correctable errors on the |
| 6013 | * downstream port of the pci-e switch. |
| 6014 | */ |
| 6015 | if (adapter->flags & FLAG_IS_QUAD_PORT) { |
| 6016 | struct pci_dev *us_dev = pdev->bus->self; |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6017 | u16 devctl; |
| 6018 | |
Jiang Liu | f8c0fca | 2012-08-20 13:30:43 -0600 | [diff] [blame] | 6019 | pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl); |
| 6020 | pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, |
| 6021 | (devctl & ~PCI_EXP_DEVCTL_CERE)); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6022 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6023 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6024 | |
Jiang Liu | f8c0fca | 2012-08-20 13:30:43 -0600 | [diff] [blame] | 6025 | pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6026 | } else { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6027 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6028 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6029 | } |
| 6030 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6031 | #ifdef CONFIG_PCIEASPM |
| 6032 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
| 6033 | { |
Yinghai Lu | 9f728f5 | 2011-05-12 17:11:47 -0700 | [diff] [blame] | 6034 | pci_disable_link_state_locked(pdev, state); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6035 | } |
| 6036 | #else |
| 6037 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 6038 | { |
Bjorn Helgaas | ffe0b2ff | 2012-12-06 06:40:07 +0000 | [diff] [blame] | 6039 | u16 aspm_ctl = 0; |
| 6040 | |
| 6041 | if (state & PCIE_LINK_STATE_L0S) |
| 6042 | aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S; |
| 6043 | if (state & PCIE_LINK_STATE_L1) |
| 6044 | aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1; |
| 6045 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6046 | /* Both device and parent should have the same ASPM setting. |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6047 | * Disable ASPM in downstream component first and then upstream. |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 6048 | */ |
Bjorn Helgaas | ffe0b2ff | 2012-12-06 06:40:07 +0000 | [diff] [blame] | 6049 | pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6050 | |
Jiang Liu | f8c0fca | 2012-08-20 13:30:43 -0600 | [diff] [blame] | 6051 | if (pdev->bus->self) |
| 6052 | pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL, |
Bjorn Helgaas | ffe0b2ff | 2012-12-06 06:40:07 +0000 | [diff] [blame] | 6053 | aspm_ctl); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6054 | } |
| 6055 | #endif |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6056 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6057 | { |
| 6058 | dev_info(&pdev->dev, "Disabling ASPM %s %s\n", |
| 6059 | (state & PCIE_LINK_STATE_L0S) ? "L0s" : "", |
| 6060 | (state & PCIE_LINK_STATE_L1) ? "L1" : ""); |
| 6061 | |
| 6062 | __e1000e_disable_aspm(pdev, state); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 6063 | } |
| 6064 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6065 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6066 | static bool e1000e_pm_ready(struct e1000_adapter *adapter) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6067 | { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6068 | return !!adapter->tx_ring->buffer_info; |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6069 | } |
| 6070 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6071 | static int __e1000_resume(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6072 | { |
| 6073 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6074 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6075 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6076 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6077 | u32 err; |
| 6078 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6079 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 6080 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
| 6081 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
| 6082 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 6083 | if (aspm_disable_flag) |
| 6084 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 6085 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6086 | pci_set_power_state(pdev, PCI_D0); |
| 6087 | pci_restore_state(pdev); |
Bruce Allan | 28b8f04 | 2010-01-07 16:30:56 +0000 | [diff] [blame] | 6088 | pci_save_state(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6089 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6090 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6091 | if (netif_running(netdev)) { |
| 6092 | err = e1000_request_irq(adapter); |
| 6093 | if (err) |
| 6094 | return err; |
| 6095 | } |
| 6096 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 6097 | if (hw->mac.type >= e1000_pch2lan) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 6098 | e1000_resume_workarounds_pchlan(&adapter->hw); |
| 6099 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6100 | e1000e_power_up_phy(adapter); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6101 | |
| 6102 | /* report the system wakeup cause from S3/S4 */ |
| 6103 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
| 6104 | u16 phy_data; |
| 6105 | |
| 6106 | e1e_rphy(&adapter->hw, BM_WUS, &phy_data); |
| 6107 | if (phy_data) { |
| 6108 | e_info("PHY Wakeup cause - %s\n", |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 6109 | phy_data & E1000_WUS_EX ? "Unicast Packet" : |
| 6110 | phy_data & E1000_WUS_MC ? "Multicast Packet" : |
| 6111 | phy_data & E1000_WUS_BC ? "Broadcast Packet" : |
| 6112 | phy_data & E1000_WUS_MAG ? "Magic Packet" : |
| 6113 | phy_data & E1000_WUS_LNKC ? |
| 6114 | "Link Status Change" : "other"); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6115 | } |
| 6116 | e1e_wphy(&adapter->hw, BM_WUS, ~0); |
| 6117 | } else { |
| 6118 | u32 wus = er32(WUS); |
| 6119 | if (wus) { |
| 6120 | e_info("MAC Wakeup cause - %s\n", |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 6121 | wus & E1000_WUS_EX ? "Unicast Packet" : |
| 6122 | wus & E1000_WUS_MC ? "Multicast Packet" : |
| 6123 | wus & E1000_WUS_BC ? "Broadcast Packet" : |
| 6124 | wus & E1000_WUS_MAG ? "Magic Packet" : |
| 6125 | wus & E1000_WUS_LNKC ? "Link Status Change" : |
| 6126 | "other"); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6127 | } |
| 6128 | ew32(WUS, ~0); |
| 6129 | } |
| 6130 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6131 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6132 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 6133 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6134 | |
| 6135 | if (netif_running(netdev)) |
| 6136 | e1000e_up(adapter); |
| 6137 | |
| 6138 | netif_device_attach(netdev); |
| 6139 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6140 | /* 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] | 6141 | * 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] | 6142 | * under the control of the driver. |
| 6143 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6144 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6145 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6146 | |
| 6147 | return 0; |
| 6148 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6149 | |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6150 | #ifdef CONFIG_PM_SLEEP |
| 6151 | static int e1000_suspend(struct device *dev) |
| 6152 | { |
| 6153 | struct pci_dev *pdev = to_pci_dev(dev); |
| 6154 | int retval; |
| 6155 | bool wake; |
| 6156 | |
| 6157 | retval = __e1000_shutdown(pdev, &wake, false); |
| 6158 | if (!retval) |
| 6159 | e1000_complete_shutdown(pdev, true, wake); |
| 6160 | |
| 6161 | return retval; |
| 6162 | } |
| 6163 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6164 | static int e1000_resume(struct device *dev) |
| 6165 | { |
| 6166 | struct pci_dev *pdev = to_pci_dev(dev); |
| 6167 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6168 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6169 | |
| 6170 | if (e1000e_pm_ready(adapter)) |
| 6171 | adapter->idle_check = true; |
| 6172 | |
| 6173 | return __e1000_resume(pdev); |
| 6174 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6175 | #endif /* CONFIG_PM_SLEEP */ |
| 6176 | |
| 6177 | #ifdef CONFIG_PM_RUNTIME |
| 6178 | static int e1000_runtime_suspend(struct device *dev) |
| 6179 | { |
| 6180 | struct pci_dev *pdev = to_pci_dev(dev); |
| 6181 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6182 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6183 | |
| 6184 | if (e1000e_pm_ready(adapter)) { |
| 6185 | bool wake; |
| 6186 | |
| 6187 | __e1000_shutdown(pdev, &wake, true); |
| 6188 | } |
| 6189 | |
| 6190 | return 0; |
| 6191 | } |
| 6192 | |
| 6193 | static int e1000_idle(struct device *dev) |
| 6194 | { |
| 6195 | struct pci_dev *pdev = to_pci_dev(dev); |
| 6196 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6197 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6198 | |
| 6199 | if (!e1000e_pm_ready(adapter)) |
| 6200 | return 0; |
| 6201 | |
| 6202 | if (adapter->idle_check) { |
| 6203 | adapter->idle_check = false; |
| 6204 | if (!e1000e_has_link(adapter)) |
| 6205 | pm_schedule_suspend(dev, MSEC_PER_SEC); |
| 6206 | } |
| 6207 | |
| 6208 | return -EBUSY; |
| 6209 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6210 | |
| 6211 | static int e1000_runtime_resume(struct device *dev) |
| 6212 | { |
| 6213 | struct pci_dev *pdev = to_pci_dev(dev); |
| 6214 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6215 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6216 | |
| 6217 | if (!e1000e_pm_ready(adapter)) |
| 6218 | return 0; |
| 6219 | |
| 6220 | adapter->idle_check = !dev->power.runtime_auto; |
| 6221 | return __e1000_resume(pdev); |
| 6222 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6223 | #endif /* CONFIG_PM_RUNTIME */ |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6224 | #endif /* CONFIG_PM */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6225 | |
| 6226 | static void e1000_shutdown(struct pci_dev *pdev) |
| 6227 | { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6228 | bool wake = false; |
| 6229 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6230 | __e1000_shutdown(pdev, &wake, false); |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6231 | |
| 6232 | if (system_state == SYSTEM_POWER_OFF) |
| 6233 | e1000_complete_shutdown(pdev, false, wake); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6234 | } |
| 6235 | |
| 6236 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 6237 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 6238 | static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data) |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 6239 | { |
| 6240 | struct net_device *netdev = data; |
| 6241 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 6242 | |
| 6243 | if (adapter->msix_entries) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 6244 | int vector, msix_irq; |
| 6245 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 6246 | vector = 0; |
| 6247 | msix_irq = adapter->msix_entries[vector].vector; |
| 6248 | disable_irq(msix_irq); |
| 6249 | e1000_intr_msix_rx(msix_irq, netdev); |
| 6250 | enable_irq(msix_irq); |
| 6251 | |
| 6252 | vector++; |
| 6253 | msix_irq = adapter->msix_entries[vector].vector; |
| 6254 | disable_irq(msix_irq); |
| 6255 | e1000_intr_msix_tx(msix_irq, netdev); |
| 6256 | enable_irq(msix_irq); |
| 6257 | |
| 6258 | vector++; |
| 6259 | msix_irq = adapter->msix_entries[vector].vector; |
| 6260 | disable_irq(msix_irq); |
| 6261 | e1000_msix_other(msix_irq, netdev); |
| 6262 | enable_irq(msix_irq); |
| 6263 | } |
| 6264 | |
| 6265 | return IRQ_HANDLED; |
| 6266 | } |
| 6267 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6268 | /** |
| 6269 | * e1000_netpoll |
| 6270 | * @netdev: network interface device structure |
| 6271 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6272 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 6273 | * without having to re-enable interrupts. It's not called while |
| 6274 | * the interrupt routine is executing. |
| 6275 | */ |
| 6276 | static void e1000_netpoll(struct net_device *netdev) |
| 6277 | { |
| 6278 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6279 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 6280 | switch (adapter->int_mode) { |
| 6281 | case E1000E_INT_MODE_MSIX: |
| 6282 | e1000_intr_msix(adapter->pdev->irq, netdev); |
| 6283 | break; |
| 6284 | case E1000E_INT_MODE_MSI: |
| 6285 | disable_irq(adapter->pdev->irq); |
| 6286 | e1000_intr_msi(adapter->pdev->irq, netdev); |
| 6287 | enable_irq(adapter->pdev->irq); |
| 6288 | break; |
| 6289 | default: /* E1000E_INT_MODE_LEGACY */ |
| 6290 | disable_irq(adapter->pdev->irq); |
| 6291 | e1000_intr(adapter->pdev->irq, netdev); |
| 6292 | enable_irq(adapter->pdev->irq); |
| 6293 | break; |
| 6294 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6295 | } |
| 6296 | #endif |
| 6297 | |
| 6298 | /** |
| 6299 | * e1000_io_error_detected - called when PCI error is detected |
| 6300 | * @pdev: Pointer to PCI device |
| 6301 | * @state: The current pci connection state |
| 6302 | * |
| 6303 | * This function is called after a PCI bus error affecting |
| 6304 | * this device has been detected. |
| 6305 | */ |
| 6306 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 6307 | pci_channel_state_t state) |
| 6308 | { |
| 6309 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6310 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6311 | |
| 6312 | netif_device_detach(netdev); |
| 6313 | |
Mike Mason | c93b5a7 | 2009-06-30 12:45:53 +0000 | [diff] [blame] | 6314 | if (state == pci_channel_io_perm_failure) |
| 6315 | return PCI_ERS_RESULT_DISCONNECT; |
| 6316 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6317 | if (netif_running(netdev)) |
| 6318 | e1000e_down(adapter); |
| 6319 | pci_disable_device(pdev); |
| 6320 | |
| 6321 | /* Request a slot slot reset. */ |
| 6322 | return PCI_ERS_RESULT_NEED_RESET; |
| 6323 | } |
| 6324 | |
| 6325 | /** |
| 6326 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 6327 | * @pdev: Pointer to PCI device |
| 6328 | * |
| 6329 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 6330 | * resembles the first-half of the e1000_resume routine. |
| 6331 | */ |
| 6332 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 6333 | { |
| 6334 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6335 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6336 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6337 | u16 aspm_disable_flag = 0; |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6338 | int err; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6339 | pci_ers_result_t result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6340 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6341 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 6342 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6343 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6344 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 6345 | if (aspm_disable_flag) |
| 6346 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 6347 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6348 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6349 | if (err) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6350 | dev_err(&pdev->dev, |
| 6351 | "Cannot re-enable PCI device after reset.\n"); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6352 | result = PCI_ERS_RESULT_DISCONNECT; |
| 6353 | } else { |
| 6354 | pci_set_master(pdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6355 | pdev->state_saved = true; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6356 | pci_restore_state(pdev); |
| 6357 | |
| 6358 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 6359 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 6360 | |
| 6361 | e1000e_reset(adapter); |
| 6362 | ew32(WUS, ~0); |
| 6363 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6364 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6365 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6366 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6367 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6368 | return result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6369 | } |
| 6370 | |
| 6371 | /** |
| 6372 | * e1000_io_resume - called when traffic can start flowing again. |
| 6373 | * @pdev: Pointer to PCI device |
| 6374 | * |
| 6375 | * This callback is called when the error recovery driver tells us that |
| 6376 | * its OK to resume normal operation. Implementation resembles the |
| 6377 | * second-half of the e1000_resume routine. |
| 6378 | */ |
| 6379 | static void e1000_io_resume(struct pci_dev *pdev) |
| 6380 | { |
| 6381 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6382 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6383 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 6384 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6385 | |
| 6386 | if (netif_running(netdev)) { |
| 6387 | if (e1000e_up(adapter)) { |
| 6388 | dev_err(&pdev->dev, |
| 6389 | "can't bring device back up after reset\n"); |
| 6390 | return; |
| 6391 | } |
| 6392 | } |
| 6393 | |
| 6394 | netif_device_attach(netdev); |
| 6395 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6396 | /* 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] | 6397 | * 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] | 6398 | * under the control of the driver. |
| 6399 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6400 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6401 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6402 | } |
| 6403 | |
| 6404 | static void e1000_print_device_info(struct e1000_adapter *adapter) |
| 6405 | { |
| 6406 | struct e1000_hw *hw = &adapter->hw; |
| 6407 | struct net_device *netdev = adapter->netdev; |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 6408 | u32 ret_val; |
| 6409 | u8 pba_str[E1000_PBANUM_LENGTH]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6410 | |
| 6411 | /* print bus type/speed/width info */ |
Bruce Allan | a5cc764 | 2011-03-19 00:31:23 +0000 | [diff] [blame] | 6412 | e_info("(PCI Express:2.5GT/s:%s) %pM\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6413 | /* bus width */ |
| 6414 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 6415 | "Width x1"), |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6416 | /* MAC address */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 6417 | netdev->dev_addr); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6418 | e_info("Intel(R) PRO/%s Network Connection\n", |
| 6419 | (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 6420 | ret_val = e1000_read_pba_string_generic(hw, pba_str, |
| 6421 | E1000_PBANUM_LENGTH); |
| 6422 | if (ret_val) |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 6423 | strlcpy((char *)pba_str, "Unknown", sizeof(pba_str)); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 6424 | e_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 6425 | hw->mac.type, hw->phy.type, pba_str); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6426 | } |
| 6427 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6428 | static void e1000_eeprom_checks(struct e1000_adapter *adapter) |
| 6429 | { |
| 6430 | struct e1000_hw *hw = &adapter->hw; |
| 6431 | int ret_val; |
| 6432 | u16 buf = 0; |
| 6433 | |
| 6434 | if (hw->mac.type != e1000_82573) |
| 6435 | return; |
| 6436 | |
| 6437 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 6438 | le16_to_cpus(&buf); |
| 6439 | if (!ret_val && (!(buf & (1 << 0)))) { |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6440 | /* Deep Smart Power Down (DSPD) */ |
Frans Pop | 6c2a9ef | 2008-09-22 14:52:22 -0700 | [diff] [blame] | 6441 | dev_warn(&adapter->pdev->dev, |
| 6442 | "Warning: detected DSPD enabled in EEPROM\n"); |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6443 | } |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6444 | } |
| 6445 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 6446 | static int e1000_set_features(struct net_device *netdev, |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 6447 | netdev_features_t features) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6448 | { |
| 6449 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 6450 | netdev_features_t changed = features ^ netdev->features; |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6451 | |
| 6452 | if (changed & (NETIF_F_TSO | NETIF_F_TSO6)) |
| 6453 | adapter->flags |= FLAG_TSO_FORCE; |
| 6454 | |
| 6455 | if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 6456 | NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS | |
| 6457 | NETIF_F_RXALL))) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6458 | return 0; |
| 6459 | |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 6460 | if (changed & NETIF_F_RXFCS) { |
| 6461 | if (features & NETIF_F_RXFCS) { |
| 6462 | adapter->flags2 &= ~FLAG2_CRC_STRIPPING; |
| 6463 | } else { |
| 6464 | /* We need to take it back to defaults, which might mean |
| 6465 | * stripping is still disabled at the adapter level. |
| 6466 | */ |
| 6467 | if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING) |
| 6468 | adapter->flags2 |= FLAG2_CRC_STRIPPING; |
| 6469 | else |
| 6470 | adapter->flags2 &= ~FLAG2_CRC_STRIPPING; |
| 6471 | } |
| 6472 | } |
| 6473 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 6474 | netdev->features = features; |
| 6475 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6476 | if (netif_running(netdev)) |
| 6477 | e1000e_reinit_locked(adapter); |
| 6478 | else |
| 6479 | e1000e_reset(adapter); |
| 6480 | |
| 6481 | return 0; |
| 6482 | } |
| 6483 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6484 | static const struct net_device_ops e1000e_netdev_ops = { |
| 6485 | .ndo_open = e1000_open, |
| 6486 | .ndo_stop = e1000_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 6487 | .ndo_start_xmit = e1000_xmit_frame, |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6488 | .ndo_get_stats64 = e1000e_get_stats64, |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 6489 | .ndo_set_rx_mode = e1000e_set_rx_mode, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6490 | .ndo_set_mac_address = e1000_set_mac, |
| 6491 | .ndo_change_mtu = e1000_change_mtu, |
| 6492 | .ndo_do_ioctl = e1000_ioctl, |
| 6493 | .ndo_tx_timeout = e1000_tx_timeout, |
| 6494 | .ndo_validate_addr = eth_validate_addr, |
| 6495 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6496 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 6497 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 6498 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6499 | .ndo_poll_controller = e1000_netpoll, |
| 6500 | #endif |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6501 | .ndo_set_features = e1000_set_features, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6502 | }; |
| 6503 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6504 | /** |
| 6505 | * e1000_probe - Device Initialization Routine |
| 6506 | * @pdev: PCI device information struct |
| 6507 | * @ent: entry in e1000_pci_tbl |
| 6508 | * |
| 6509 | * Returns 0 on success, negative on failure |
| 6510 | * |
| 6511 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 6512 | * The OS initialization, configuring of the adapter private structure, |
| 6513 | * and a hardware reset occur. |
| 6514 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 6515 | static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6516 | { |
| 6517 | struct net_device *netdev; |
| 6518 | struct e1000_adapter *adapter; |
| 6519 | struct e1000_hw *hw; |
| 6520 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; |
Becky Bruce | f47e81f | 2008-05-01 18:03:11 -0500 | [diff] [blame] | 6521 | resource_size_t mmio_start, mmio_len; |
| 6522 | resource_size_t flash_start, flash_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6523 | static int cards_found; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6524 | u16 aspm_disable_flag = 0; |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 6525 | int bars, i, err, pci_using_dac; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6526 | u16 eeprom_data = 0; |
| 6527 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
| 6528 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6529 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 6530 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6531 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6532 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 6533 | if (aspm_disable_flag) |
| 6534 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6535 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6536 | err = pci_enable_device_mem(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6537 | if (err) |
| 6538 | return err; |
| 6539 | |
| 6540 | pci_using_dac = 0; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6541 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6542 | if (!err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6543 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6544 | if (!err) |
| 6545 | pci_using_dac = 1; |
| 6546 | } else { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6547 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6548 | if (err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6549 | err = dma_set_coherent_mask(&pdev->dev, |
| 6550 | DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6551 | if (err) { |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 6552 | dev_err(&pdev->dev, |
| 6553 | "No usable DMA configuration, aborting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6554 | goto err_dma; |
| 6555 | } |
| 6556 | } |
| 6557 | } |
| 6558 | |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 6559 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 6560 | err = pci_request_selected_regions_exclusive(pdev, bars, |
| 6561 | e1000e_driver_name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6562 | if (err) |
| 6563 | goto err_pci_reg; |
| 6564 | |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 6565 | /* AER (Advanced Error Reporting) hooks */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6566 | pci_enable_pcie_error_reporting(pdev); |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 6567 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6568 | pci_set_master(pdev); |
Bruce Allan | 438b365 | 2008-11-21 16:51:33 -0800 | [diff] [blame] | 6569 | /* PCI config space info */ |
| 6570 | err = pci_save_state(pdev); |
| 6571 | if (err) |
| 6572 | goto err_alloc_etherdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6573 | |
| 6574 | err = -ENOMEM; |
| 6575 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
| 6576 | if (!netdev) |
| 6577 | goto err_alloc_etherdev; |
| 6578 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6579 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 6580 | |
Tom Herbert | f85e4df | 2010-05-05 14:03:32 +0000 | [diff] [blame] | 6581 | netdev->irq = pdev->irq; |
| 6582 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6583 | pci_set_drvdata(pdev, netdev); |
| 6584 | adapter = netdev_priv(netdev); |
| 6585 | hw = &adapter->hw; |
| 6586 | adapter->netdev = netdev; |
| 6587 | adapter->pdev = pdev; |
| 6588 | adapter->ei = ei; |
| 6589 | adapter->pba = ei->pba; |
| 6590 | adapter->flags = ei->flags; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 6591 | adapter->flags2 = ei->flags2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6592 | adapter->hw.adapter = adapter; |
| 6593 | adapter->hw.mac.type = ei->mac; |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 6594 | adapter->max_hw_frame_size = ei->max_hw_frame_size; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 6595 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6596 | |
| 6597 | mmio_start = pci_resource_start(pdev, 0); |
| 6598 | mmio_len = pci_resource_len(pdev, 0); |
| 6599 | |
| 6600 | err = -EIO; |
| 6601 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 6602 | if (!adapter->hw.hw_addr) |
| 6603 | goto err_ioremap; |
| 6604 | |
| 6605 | if ((adapter->flags & FLAG_HAS_FLASH) && |
| 6606 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
| 6607 | flash_start = pci_resource_start(pdev, 1); |
| 6608 | flash_len = pci_resource_len(pdev, 1); |
| 6609 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
| 6610 | if (!adapter->hw.flash_address) |
| 6611 | goto err_flashmap; |
| 6612 | } |
| 6613 | |
| 6614 | /* construct the net_device struct */ |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6615 | netdev->netdev_ops = &e1000e_netdev_ops; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6616 | e1000e_set_ethtool_ops(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6617 | netdev->watchdog_timeo = 5 * HZ; |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 6618 | netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64); |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 6619 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6620 | |
| 6621 | netdev->mem_start = mmio_start; |
| 6622 | netdev->mem_end = mmio_start + mmio_len; |
| 6623 | |
| 6624 | adapter->bd_number = cards_found++; |
| 6625 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6626 | e1000e_check_options(adapter); |
| 6627 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6628 | /* setup adapter struct */ |
| 6629 | err = e1000_sw_init(adapter); |
| 6630 | if (err) |
| 6631 | goto err_sw_init; |
| 6632 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6633 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 6634 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 6635 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 6636 | |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 6637 | err = ei->get_variants(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6638 | if (err) |
| 6639 | goto err_hw_init; |
| 6640 | |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 6641 | if ((adapter->flags & FLAG_IS_ICH) && |
| 6642 | (adapter->flags & FLAG_READ_ONLY_NVM)) |
| 6643 | e1000e_write_protect_nvm_ich8lan(&adapter->hw); |
| 6644 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6645 | hw->mac.ops.get_bus_info(&adapter->hw); |
| 6646 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6647 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6648 | |
| 6649 | /* Copper options */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6650 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6651 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
| 6652 | adapter->hw.phy.disable_polarity_correction = 0; |
| 6653 | adapter->hw.phy.ms_type = e1000_ms_hw_default; |
| 6654 | } |
| 6655 | |
Bruce Allan | 470a542 | 2012-05-26 06:08:48 +0000 | [diff] [blame] | 6656 | if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw)) |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 6657 | dev_info(&pdev->dev, |
| 6658 | "PHY reset is blocked due to SOL/IDER session.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6659 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6660 | /* Set initial default active device features */ |
| 6661 | netdev->features = (NETIF_F_SG | |
| 6662 | NETIF_F_HW_VLAN_RX | |
| 6663 | NETIF_F_HW_VLAN_TX | |
| 6664 | NETIF_F_TSO | |
| 6665 | NETIF_F_TSO6 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 6666 | NETIF_F_RXHASH | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6667 | NETIF_F_RXCSUM | |
| 6668 | NETIF_F_HW_CSUM); |
| 6669 | |
| 6670 | /* Set user-changeable features (subset of all device features) */ |
| 6671 | netdev->hw_features = netdev->features; |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 6672 | netdev->hw_features |= NETIF_F_RXFCS; |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 6673 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 6674 | netdev->hw_features |= NETIF_F_RXALL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6675 | |
| 6676 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
| 6677 | netdev->features |= NETIF_F_HW_VLAN_FILTER; |
| 6678 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6679 | netdev->vlan_features |= (NETIF_F_SG | |
| 6680 | NETIF_F_TSO | |
| 6681 | NETIF_F_TSO6 | |
| 6682 | NETIF_F_HW_CSUM); |
Jeff Kirsher | a5136e2 | 2008-06-05 04:07:28 -0700 | [diff] [blame] | 6683 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 6684 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 6685 | |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 6686 | if (pci_using_dac) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6687 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 6688 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 6689 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6690 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6691 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
| 6692 | adapter->flags |= FLAG_MNG_PT_ENABLED; |
| 6693 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6694 | /* before reading the NVM, reset the controller to |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6695 | * put the device in a known good starting state |
| 6696 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6697 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 6698 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6699 | /* systems with ASPM and others may see the checksum fail on the first |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6700 | * attempt. Let's give it a few tries |
| 6701 | */ |
| 6702 | for (i = 0;; i++) { |
| 6703 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) |
| 6704 | break; |
| 6705 | if (i == 2) { |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 6706 | dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6707 | err = -EIO; |
| 6708 | goto err_eeprom; |
| 6709 | } |
| 6710 | } |
| 6711 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6712 | e1000_eeprom_checks(adapter); |
| 6713 | |
Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 6714 | /* copy the MAC address */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6715 | if (e1000e_read_mac_addr(&adapter->hw)) |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 6716 | dev_err(&pdev->dev, |
| 6717 | "NVM Read Error while reading MAC address\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6718 | |
| 6719 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6720 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 6721 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 6722 | dev_err(&pdev->dev, "Invalid MAC Address: %pM\n", |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 6723 | netdev->dev_addr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6724 | err = -EIO; |
| 6725 | goto err_eeprom; |
| 6726 | } |
| 6727 | |
| 6728 | init_timer(&adapter->watchdog_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6729 | adapter->watchdog_timer.function = e1000_watchdog; |
Bruce Allan | 53aa82d | 2013-02-20 04:06:06 +0000 | [diff] [blame^] | 6730 | adapter->watchdog_timer.data = (unsigned long)adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6731 | |
| 6732 | init_timer(&adapter->phy_info_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6733 | adapter->phy_info_timer.function = e1000_update_phy_info; |
Bruce Allan | 53aa82d | 2013-02-20 04:06:06 +0000 | [diff] [blame^] | 6734 | adapter->phy_info_timer.data = (unsigned long)adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6735 | |
| 6736 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
| 6737 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 6738 | INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); |
| 6739 | INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6740 | INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6741 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6742 | /* Initialize link parameters. User can change them with ethtool */ |
| 6743 | adapter->hw.mac.autoneg = 1; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6744 | adapter->fc_autoneg = true; |
Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 6745 | adapter->hw.fc.requested_mode = e1000_fc_default; |
| 6746 | adapter->hw.fc.current_mode = e1000_fc_default; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6747 | adapter->hw.phy.autoneg_advertised = 0x2f; |
| 6748 | |
| 6749 | /* ring size defaults */ |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 6750 | adapter->rx_ring->count = E1000_DEFAULT_RXD; |
| 6751 | adapter->tx_ring->count = E1000_DEFAULT_TXD; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6752 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6753 | /* Initial Wake on LAN setting - If APM wake is enabled in |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6754 | * the EEPROM, enable the ACPI Magic Packet filter |
| 6755 | */ |
| 6756 | if (adapter->flags & FLAG_APME_IN_WUC) { |
| 6757 | /* APME bit in EEPROM is mapped to WUC.APME */ |
| 6758 | eeprom_data = er32(WUC); |
| 6759 | eeprom_apme_mask = E1000_WUC_APME; |
Bruce Allan | 4def99b | 2011-02-02 09:30:36 +0000 | [diff] [blame] | 6760 | if ((hw->mac.type > e1000_ich10lan) && |
| 6761 | (eeprom_data & E1000_WUC_PHY_WAKE)) |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6762 | adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6763 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
| 6764 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && |
| 6765 | (adapter->hw.bus.func == 1)) |
Bruce Allan | 3d3a167 | 2012-02-23 03:13:18 +0000 | [diff] [blame] | 6766 | e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B, |
| 6767 | 1, &eeprom_data); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6768 | else |
Bruce Allan | 3d3a167 | 2012-02-23 03:13:18 +0000 | [diff] [blame] | 6769 | e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A, |
| 6770 | 1, &eeprom_data); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6771 | } |
| 6772 | |
| 6773 | /* fetch WoL from EEPROM */ |
| 6774 | if (eeprom_data & eeprom_apme_mask) |
| 6775 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 6776 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6777 | /* now that we have the eeprom settings, apply the special cases |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6778 | * where the eeprom may be wrong or the board simply won't support |
| 6779 | * wake on lan on a particular port |
| 6780 | */ |
| 6781 | if (!(adapter->flags & FLAG_HAS_WOL)) |
| 6782 | adapter->eeprom_wol = 0; |
| 6783 | |
| 6784 | /* initialize the wol settings based on the eeprom settings */ |
| 6785 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | 6ff6802 | 2008-11-12 09:52:32 +0000 | [diff] [blame] | 6786 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6787 | |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 6788 | /* save off EEPROM version number */ |
| 6789 | e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); |
| 6790 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6791 | /* reset the hardware with the new settings */ |
| 6792 | e1000e_reset(adapter); |
| 6793 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6794 | /* 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] | 6795 | * 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] | 6796 | * under the control of the driver. |
| 6797 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6798 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6799 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6800 | |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 6801 | strlcpy(netdev->name, "eth%d", sizeof(netdev->name)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6802 | err = register_netdev(netdev); |
| 6803 | if (err) |
| 6804 | goto err_register; |
| 6805 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 6806 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 6807 | netif_carrier_off(netdev); |
| 6808 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 6809 | /* init PTP hardware clock */ |
| 6810 | e1000e_ptp_init(adapter); |
| 6811 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6812 | e1000_print_device_info(adapter); |
| 6813 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6814 | if (pci_dev_run_wake(pdev)) |
| 6815 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6816 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6817 | return 0; |
| 6818 | |
| 6819 | err_register: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6820 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6821 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6822 | err_eeprom: |
Bruce Allan | 470a542 | 2012-05-26 06:08:48 +0000 | [diff] [blame] | 6823 | if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6824 | e1000_phy_hw_reset(&adapter->hw); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6825 | err_hw_init: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6826 | kfree(adapter->tx_ring); |
| 6827 | kfree(adapter->rx_ring); |
| 6828 | err_sw_init: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6829 | if (adapter->hw.flash_address) |
| 6830 | iounmap(adapter->hw.flash_address); |
Jeff Kirsher | e82f54b | 2008-11-14 06:45:07 +0000 | [diff] [blame] | 6831 | e1000e_reset_interrupt_capability(adapter); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6832 | err_flashmap: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6833 | iounmap(adapter->hw.hw_addr); |
| 6834 | err_ioremap: |
| 6835 | free_netdev(netdev); |
| 6836 | err_alloc_etherdev: |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6837 | pci_release_selected_regions(pdev, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 6838 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6839 | err_pci_reg: |
| 6840 | err_dma: |
| 6841 | pci_disable_device(pdev); |
| 6842 | return err; |
| 6843 | } |
| 6844 | |
| 6845 | /** |
| 6846 | * e1000_remove - Device Removal Routine |
| 6847 | * @pdev: PCI device information struct |
| 6848 | * |
| 6849 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 6850 | * that it should release a PCI device. The could be caused by a |
| 6851 | * Hot-Plug event, or because the driver is going to be removed from |
| 6852 | * memory. |
| 6853 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 6854 | static void e1000_remove(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6855 | { |
| 6856 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6857 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6858 | bool down = test_bit(__E1000_DOWN, &adapter->state); |
| 6859 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 6860 | e1000e_ptp_remove(adapter); |
| 6861 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6862 | /* The timers may be rescheduled, so explicitly disable them |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 6863 | * from being rescheduled. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6864 | */ |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6865 | if (!down) |
| 6866 | set_bit(__E1000_DOWN, &adapter->state); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6867 | del_timer_sync(&adapter->watchdog_timer); |
| 6868 | del_timer_sync(&adapter->phy_info_timer); |
| 6869 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6870 | cancel_work_sync(&adapter->reset_task); |
| 6871 | cancel_work_sync(&adapter->watchdog_task); |
| 6872 | cancel_work_sync(&adapter->downshift_task); |
| 6873 | cancel_work_sync(&adapter->update_phy_task); |
| 6874 | cancel_work_sync(&adapter->print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6875 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6876 | if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) { |
| 6877 | cancel_work_sync(&adapter->tx_hwtstamp_work); |
| 6878 | if (adapter->tx_hwtstamp_skb) { |
| 6879 | dev_kfree_skb_any(adapter->tx_hwtstamp_skb); |
| 6880 | adapter->tx_hwtstamp_skb = NULL; |
| 6881 | } |
| 6882 | } |
| 6883 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6884 | if (!(netdev->flags & IFF_UP)) |
| 6885 | e1000_power_down_phy(adapter); |
| 6886 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6887 | /* Don't lie to e1000_close() down the road. */ |
| 6888 | if (!down) |
| 6889 | clear_bit(__E1000_DOWN, &adapter->state); |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6890 | unregister_netdev(netdev); |
| 6891 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6892 | if (pci_dev_run_wake(pdev)) |
| 6893 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6894 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6895 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6896 | * would have already happened in close and is redundant. |
| 6897 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6898 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6899 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6900 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6901 | kfree(adapter->tx_ring); |
| 6902 | kfree(adapter->rx_ring); |
| 6903 | |
| 6904 | iounmap(adapter->hw.hw_addr); |
| 6905 | if (adapter->hw.flash_address) |
| 6906 | iounmap(adapter->hw.flash_address); |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6907 | pci_release_selected_regions(pdev, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 6908 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6909 | |
| 6910 | free_netdev(netdev); |
| 6911 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6912 | /* AER disable */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6913 | pci_disable_pcie_error_reporting(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6914 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6915 | pci_disable_device(pdev); |
| 6916 | } |
| 6917 | |
| 6918 | /* PCI Error Recovery (ERS) */ |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 6919 | static const struct pci_error_handlers e1000_err_handler = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6920 | .error_detected = e1000_io_error_detected, |
| 6921 | .slot_reset = e1000_io_slot_reset, |
| 6922 | .resume = e1000_io_resume, |
| 6923 | }; |
| 6924 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 6925 | static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6926 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
| 6927 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, |
| 6928 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, |
Bruce Allan | c29c3ba | 2013-02-20 04:05:50 +0000 | [diff] [blame] | 6929 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), |
| 6930 | board_82571 }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6931 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
| 6932 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, |
Auke Kok | 040babf | 2007-10-31 15:22:05 -0700 | [diff] [blame] | 6933 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
| 6934 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, |
| 6935 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6936 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6937 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
| 6938 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, |
| 6939 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, |
| 6940 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6941 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6942 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
| 6943 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, |
| 6944 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6945 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6946 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, |
Bruce Allan | bef28b1 | 2009-03-24 23:28:02 -0700 | [diff] [blame] | 6947 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 6948 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6949 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6950 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
| 6951 | board_80003es2lan }, |
| 6952 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), |
| 6953 | board_80003es2lan }, |
| 6954 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), |
| 6955 | board_80003es2lan }, |
| 6956 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), |
| 6957 | board_80003es2lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6958 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6959 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
| 6960 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, |
| 6961 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, |
| 6962 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, |
| 6963 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, |
| 6964 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, |
| 6965 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, |
Bruce Allan | 9e135a2 | 2009-12-01 15:50:31 +0000 | [diff] [blame] | 6966 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6967 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6968 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
| 6969 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, |
| 6970 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, |
| 6971 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, |
| 6972 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, |
Bruce Allan | 2f15f9d | 2008-08-26 18:36:36 -0700 | [diff] [blame] | 6973 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6974 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, |
| 6975 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, |
| 6976 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, |
| 6977 | |
| 6978 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, |
| 6979 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, |
| 6980 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6981 | |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6982 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, |
| 6983 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, |
Bruce Allan | 10df0b9 | 2010-05-10 15:02:52 +0000 | [diff] [blame] | 6984 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan }, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6985 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6986 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, |
| 6987 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, |
| 6988 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, |
| 6989 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, |
| 6990 | |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 6991 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan }, |
| 6992 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan }, |
| 6993 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 6994 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt }, |
| 6995 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt }, |
Bruce Allan | 16e310a | 2012-10-09 01:11:26 +0000 | [diff] [blame] | 6996 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt }, |
| 6997 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt }, |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 6998 | |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 6999 | { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7000 | }; |
| 7001 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 7002 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 7003 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7004 | static const struct dev_pm_ops e1000_pm_ops = { |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 7005 | SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume) |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 7006 | SET_RUNTIME_PM_OPS(e1000_runtime_suspend, e1000_runtime_resume, |
| 7007 | e1000_idle) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7008 | }; |
David S. Miller | e50208a | 2010-03-16 23:36:24 -0700 | [diff] [blame] | 7009 | #endif |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7010 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7011 | /* PCI Device API Driver */ |
| 7012 | static struct pci_driver e1000_driver = { |
| 7013 | .name = e1000e_driver_name, |
| 7014 | .id_table = e1000_pci_tbl, |
| 7015 | .probe = e1000_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 7016 | .remove = e1000_remove, |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 7017 | #ifdef CONFIG_PM |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 7018 | .driver = { |
| 7019 | .pm = &e1000_pm_ops, |
| 7020 | }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7021 | #endif |
| 7022 | .shutdown = e1000_shutdown, |
| 7023 | .err_handler = &e1000_err_handler |
| 7024 | }; |
| 7025 | |
| 7026 | /** |
| 7027 | * e1000_init_module - Driver Registration Routine |
| 7028 | * |
| 7029 | * e1000_init_module is the first routine called when the driver is |
| 7030 | * loaded. All it does is register with the PCI subsystem. |
| 7031 | **/ |
| 7032 | static int __init e1000_init_module(void) |
| 7033 | { |
| 7034 | int ret; |
Bruce Allan | 8544b9f | 2010-03-24 12:55:30 +0000 | [diff] [blame] | 7035 | pr_info("Intel(R) PRO/1000 Network Driver - %s\n", |
| 7036 | e1000e_driver_version); |
Bruce Allan | bf67044 | 2013-01-01 16:00:01 +0000 | [diff] [blame] | 7037 | pr_info("Copyright(c) 1999 - 2013 Intel Corporation.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7038 | ret = pci_register_driver(&e1000_driver); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 7039 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7040 | return ret; |
| 7041 | } |
| 7042 | module_init(e1000_init_module); |
| 7043 | |
| 7044 | /** |
| 7045 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 7046 | * |
| 7047 | * e1000_exit_module is called just before the driver is removed |
| 7048 | * from memory. |
| 7049 | **/ |
| 7050 | static void __exit e1000_exit_module(void) |
| 7051 | { |
| 7052 | pci_unregister_driver(&e1000_driver); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7053 | } |
| 7054 | module_exit(e1000_exit_module); |
| 7055 | |
| 7056 | |
| 7057 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 7058 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 7059 | MODULE_LICENSE("GPL"); |
| 7060 | MODULE_VERSION(DRV_VERSION); |
| 7061 | |
Bruce Allan | 06c24b9 | 2012-02-23 03:13:13 +0000 | [diff] [blame] | 7062 | /* netdev.c */ |