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 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 89 | #define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */ |
| 90 | #define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */ |
| 91 | #define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */ |
| 92 | #define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */ |
| 93 | #define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 94 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 95 | #define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */ |
| 96 | #define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */ |
| 97 | #define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */ |
| 98 | #define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */ |
| 99 | #define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 100 | |
| 101 | static const struct e1000_reg_info e1000_reg_info_tbl[] = { |
| 102 | |
| 103 | /* General Registers */ |
| 104 | {E1000_CTRL, "CTRL"}, |
| 105 | {E1000_STATUS, "STATUS"}, |
| 106 | {E1000_CTRL_EXT, "CTRL_EXT"}, |
| 107 | |
| 108 | /* Interrupt Registers */ |
| 109 | {E1000_ICR, "ICR"}, |
| 110 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 111 | /* Rx Registers */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 112 | {E1000_RCTL, "RCTL"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 113 | {E1000_RDLEN(0), "RDLEN"}, |
| 114 | {E1000_RDH(0), "RDH"}, |
| 115 | {E1000_RDT(0), "RDT"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 116 | {E1000_RDTR, "RDTR"}, |
| 117 | {E1000_RXDCTL(0), "RXDCTL"}, |
| 118 | {E1000_ERT, "ERT"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 119 | {E1000_RDBAL(0), "RDBAL"}, |
| 120 | {E1000_RDBAH(0), "RDBAH"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 121 | {E1000_RDFH, "RDFH"}, |
| 122 | {E1000_RDFT, "RDFT"}, |
| 123 | {E1000_RDFHS, "RDFHS"}, |
| 124 | {E1000_RDFTS, "RDFTS"}, |
| 125 | {E1000_RDFPC, "RDFPC"}, |
| 126 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 127 | /* Tx Registers */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 128 | {E1000_TCTL, "TCTL"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 129 | {E1000_TDBAL(0), "TDBAL"}, |
| 130 | {E1000_TDBAH(0), "TDBAH"}, |
| 131 | {E1000_TDLEN(0), "TDLEN"}, |
| 132 | {E1000_TDH(0), "TDH"}, |
| 133 | {E1000_TDT(0), "TDT"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 134 | {E1000_TIDV, "TIDV"}, |
| 135 | {E1000_TXDCTL(0), "TXDCTL"}, |
| 136 | {E1000_TADV, "TADV"}, |
| 137 | {E1000_TARC(0), "TARC"}, |
| 138 | {E1000_TDFH, "TDFH"}, |
| 139 | {E1000_TDFT, "TDFT"}, |
| 140 | {E1000_TDFHS, "TDFHS"}, |
| 141 | {E1000_TDFTS, "TDFTS"}, |
| 142 | {E1000_TDFPC, "TDFPC"}, |
| 143 | |
| 144 | /* List Terminator */ |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 145 | {0, NULL} |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 146 | }; |
| 147 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 148 | /** |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 149 | * e1000_regdump - register printout routine |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 150 | * @hw: pointer to the HW structure |
| 151 | * @reginfo: pointer to the register info table |
| 152 | **/ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 153 | static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo) |
| 154 | { |
| 155 | int n = 0; |
| 156 | char rname[16]; |
| 157 | u32 regs[8]; |
| 158 | |
| 159 | switch (reginfo->ofs) { |
| 160 | case E1000_RXDCTL(0): |
| 161 | for (n = 0; n < 2; n++) |
| 162 | regs[n] = __er32(hw, E1000_RXDCTL(n)); |
| 163 | break; |
| 164 | case E1000_TXDCTL(0): |
| 165 | for (n = 0; n < 2; n++) |
| 166 | regs[n] = __er32(hw, E1000_TXDCTL(n)); |
| 167 | break; |
| 168 | case E1000_TARC(0): |
| 169 | for (n = 0; n < 2; n++) |
| 170 | regs[n] = __er32(hw, E1000_TARC(n)); |
| 171 | break; |
| 172 | default: |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 173 | pr_info("%-15s %08x\n", |
| 174 | reginfo->name, __er32(hw, reginfo->ofs)); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 175 | return; |
| 176 | } |
| 177 | |
| 178 | snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 179 | pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 182 | static void e1000e_dump_ps_pages(struct e1000_adapter *adapter, |
| 183 | struct e1000_buffer *bi) |
| 184 | { |
| 185 | int i; |
| 186 | struct e1000_ps_page *ps_page; |
| 187 | |
| 188 | for (i = 0; i < adapter->rx_ps_pages; i++) { |
| 189 | ps_page = &bi->ps_pages[i]; |
| 190 | |
| 191 | if (ps_page->page) { |
| 192 | pr_info("packet dump for ps_page %d:\n", i); |
| 193 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, |
| 194 | 16, 1, page_address(ps_page->page), |
| 195 | PAGE_SIZE, true); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 200 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 201 | * e1000e_dump - Print registers, Tx-ring and Rx-ring |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 202 | * @adapter: board private structure |
| 203 | **/ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 204 | static void e1000e_dump(struct e1000_adapter *adapter) |
| 205 | { |
| 206 | struct net_device *netdev = adapter->netdev; |
| 207 | struct e1000_hw *hw = &adapter->hw; |
| 208 | struct e1000_reg_info *reginfo; |
| 209 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 210 | struct e1000_tx_desc *tx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 211 | struct my_u0 { |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 212 | __le64 a; |
| 213 | __le64 b; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 214 | } *u0; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 215 | struct e1000_buffer *buffer_info; |
| 216 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 217 | union e1000_rx_desc_packet_split *rx_desc_ps; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 218 | union e1000_rx_desc_extended *rx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 219 | struct my_u1 { |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 220 | __le64 a; |
| 221 | __le64 b; |
| 222 | __le64 c; |
| 223 | __le64 d; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 224 | } *u1; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 225 | u32 staterr; |
| 226 | int i = 0; |
| 227 | |
| 228 | if (!netif_msg_hw(adapter)) |
| 229 | return; |
| 230 | |
| 231 | /* Print netdevice Info */ |
| 232 | if (netdev) { |
| 233 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 234 | pr_info("Device Name state trans_start last_rx\n"); |
| 235 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 236 | netdev->name, netdev->state, netdev->trans_start, |
| 237 | netdev->last_rx); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /* Print Registers */ |
| 241 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 242 | pr_info(" Register Name Value\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 243 | for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl; |
| 244 | reginfo->name; reginfo++) { |
| 245 | e1000_regdump(hw, reginfo); |
| 246 | } |
| 247 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 248 | /* Print Tx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 249 | if (!netdev || !netif_running(netdev)) |
Bruce Allan | fe1e980 | 2012-01-31 06:37:54 +0000 | [diff] [blame] | 250 | return; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 251 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 252 | dev_info(&adapter->pdev->dev, "Tx Ring Summary\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 253 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 254 | buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean]; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 255 | pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n", |
| 256 | 0, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 257 | (unsigned long long)buffer_info->dma, |
| 258 | buffer_info->length, |
| 259 | buffer_info->next_to_watch, |
| 260 | (unsigned long long)buffer_info->time_stamp); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 261 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 262 | /* Print Tx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 263 | if (!netif_msg_tx_done(adapter)) |
| 264 | goto rx_ring_summary; |
| 265 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 266 | dev_info(&adapter->pdev->dev, "Tx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 267 | |
| 268 | /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended) |
| 269 | * |
| 270 | * Legacy Transmit Descriptor |
| 271 | * +--------------------------------------------------------------+ |
| 272 | * 0 | Buffer Address [63:0] (Reserved on Write Back) | |
| 273 | * +--------------------------------------------------------------+ |
| 274 | * 8 | Special | CSS | Status | CMD | CSO | Length | |
| 275 | * +--------------------------------------------------------------+ |
| 276 | * 63 48 47 36 35 32 31 24 23 16 15 0 |
| 277 | * |
| 278 | * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload |
| 279 | * 63 48 47 40 39 32 31 16 15 8 7 0 |
| 280 | * +----------------------------------------------------------------+ |
| 281 | * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS | |
| 282 | * +----------------------------------------------------------------+ |
| 283 | * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN | |
| 284 | * +----------------------------------------------------------------+ |
| 285 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 286 | * |
| 287 | * Extended Data Descriptor (DTYP=0x1) |
| 288 | * +----------------------------------------------------------------+ |
| 289 | * 0 | Buffer Address [63:0] | |
| 290 | * +----------------------------------------------------------------+ |
| 291 | * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN | |
| 292 | * +----------------------------------------------------------------+ |
| 293 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 294 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 295 | pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n"); |
| 296 | pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n"); |
| 297 | 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] | 298 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 299 | const char *next_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 300 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 301 | buffer_info = &tx_ring->buffer_info[i]; |
| 302 | u0 = (struct my_u0 *)tx_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 303 | 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] | 304 | next_desc = " NTC/U"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 305 | else if (i == tx_ring->next_to_use) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 306 | next_desc = " NTU"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 307 | else if (i == tx_ring->next_to_clean) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 308 | next_desc = " NTC"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 309 | else |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 310 | next_desc = ""; |
| 311 | pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n", |
| 312 | (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' : |
| 313 | ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), |
| 314 | i, |
| 315 | (unsigned long long)le64_to_cpu(u0->a), |
| 316 | (unsigned long long)le64_to_cpu(u0->b), |
| 317 | (unsigned long long)buffer_info->dma, |
| 318 | buffer_info->length, buffer_info->next_to_watch, |
| 319 | (unsigned long long)buffer_info->time_stamp, |
| 320 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 321 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 322 | if (netif_msg_pktdata(adapter) && buffer_info->skb) |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 323 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 324 | 16, 1, buffer_info->skb->data, |
| 325 | buffer_info->skb->len, true); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 328 | /* Print Rx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 329 | rx_ring_summary: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 330 | dev_info(&adapter->pdev->dev, "Rx Ring Summary\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 331 | pr_info("Queue [NTU] [NTC]\n"); |
| 332 | pr_info(" %5d %5X %5X\n", |
| 333 | 0, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 334 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 335 | /* Print Rx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 336 | if (!netif_msg_rx_status(adapter)) |
Bruce Allan | fe1e980 | 2012-01-31 06:37:54 +0000 | [diff] [blame] | 337 | return; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 338 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 339 | dev_info(&adapter->pdev->dev, "Rx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 340 | switch (adapter->rx_ps_pages) { |
| 341 | case 1: |
| 342 | case 2: |
| 343 | case 3: |
| 344 | /* [Extended] Packet Split Receive Descriptor Format |
| 345 | * |
| 346 | * +-----------------------------------------------------+ |
| 347 | * 0 | Buffer Address 0 [63:0] | |
| 348 | * +-----------------------------------------------------+ |
| 349 | * 8 | Buffer Address 1 [63:0] | |
| 350 | * +-----------------------------------------------------+ |
| 351 | * 16 | Buffer Address 2 [63:0] | |
| 352 | * +-----------------------------------------------------+ |
| 353 | * 24 | Buffer Address 3 [63:0] | |
| 354 | * +-----------------------------------------------------+ |
| 355 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 356 | 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] | 357 | /* [Extended] Receive Descriptor (Write-Back) Format |
| 358 | * |
| 359 | * 63 48 47 32 31 13 12 8 7 4 3 0 |
| 360 | * +------------------------------------------------------+ |
| 361 | * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS | |
| 362 | * | Checksum | Ident | | Queue | | Type | |
| 363 | * +------------------------------------------------------+ |
| 364 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 365 | * +------------------------------------------------------+ |
| 366 | * 63 48 47 32 31 20 19 0 |
| 367 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 368 | 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] | 369 | for (i = 0; i < rx_ring->count; i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 370 | const char *next_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 371 | buffer_info = &rx_ring->buffer_info[i]; |
| 372 | rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i); |
| 373 | u1 = (struct my_u1 *)rx_desc_ps; |
| 374 | staterr = |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 375 | le32_to_cpu(rx_desc_ps->wb.middle.status_error); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 376 | |
| 377 | if (i == rx_ring->next_to_use) |
| 378 | next_desc = " NTU"; |
| 379 | else if (i == rx_ring->next_to_clean) |
| 380 | next_desc = " NTC"; |
| 381 | else |
| 382 | next_desc = ""; |
| 383 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 384 | if (staterr & E1000_RXD_STAT_DD) { |
| 385 | /* Descriptor Done */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 386 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n", |
| 387 | "RWB", i, |
| 388 | (unsigned long long)le64_to_cpu(u1->a), |
| 389 | (unsigned long long)le64_to_cpu(u1->b), |
| 390 | (unsigned long long)le64_to_cpu(u1->c), |
| 391 | (unsigned long long)le64_to_cpu(u1->d), |
| 392 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 393 | } else { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 394 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n", |
| 395 | "R ", i, |
| 396 | (unsigned long long)le64_to_cpu(u1->a), |
| 397 | (unsigned long long)le64_to_cpu(u1->b), |
| 398 | (unsigned long long)le64_to_cpu(u1->c), |
| 399 | (unsigned long long)le64_to_cpu(u1->d), |
| 400 | (unsigned long long)buffer_info->dma, |
| 401 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 402 | |
| 403 | if (netif_msg_pktdata(adapter)) |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 404 | e1000e_dump_ps_pages(adapter, |
| 405 | buffer_info); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 406 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 407 | } |
| 408 | break; |
| 409 | default: |
| 410 | case 0: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 411 | /* Extended Receive Descriptor (Read) Format |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 412 | * |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 413 | * +-----------------------------------------------------+ |
| 414 | * 0 | Buffer Address [63:0] | |
| 415 | * +-----------------------------------------------------+ |
| 416 | * 8 | Reserved | |
| 417 | * +-----------------------------------------------------+ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 418 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 419 | 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] | 420 | /* Extended Receive Descriptor (Write-Back) Format |
| 421 | * |
| 422 | * 63 48 47 32 31 24 23 4 3 0 |
| 423 | * +------------------------------------------------------+ |
| 424 | * | RSS Hash | | | | |
| 425 | * 0 +-------------------+ Rsvd | Reserved | MRQ RSS | |
| 426 | * | Packet | IP | | | Type | |
| 427 | * | Checksum | Ident | | | | |
| 428 | * +------------------------------------------------------+ |
| 429 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 430 | * +------------------------------------------------------+ |
| 431 | * 63 48 47 32 31 20 19 0 |
| 432 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 433 | 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] | 434 | |
| 435 | for (i = 0; i < rx_ring->count; i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 436 | const char *next_desc; |
| 437 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 438 | buffer_info = &rx_ring->buffer_info[i]; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 439 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 440 | u1 = (struct my_u1 *)rx_desc; |
| 441 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 442 | |
| 443 | if (i == rx_ring->next_to_use) |
| 444 | next_desc = " NTU"; |
| 445 | else if (i == rx_ring->next_to_clean) |
| 446 | next_desc = " NTC"; |
| 447 | else |
| 448 | next_desc = ""; |
| 449 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 450 | if (staterr & E1000_RXD_STAT_DD) { |
| 451 | /* Descriptor Done */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 452 | pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n", |
| 453 | "RWB", i, |
| 454 | (unsigned long long)le64_to_cpu(u1->a), |
| 455 | (unsigned long long)le64_to_cpu(u1->b), |
| 456 | buffer_info->skb, next_desc); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 457 | } else { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 458 | pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n", |
| 459 | "R ", i, |
| 460 | (unsigned long long)le64_to_cpu(u1->a), |
| 461 | (unsigned long long)le64_to_cpu(u1->b), |
| 462 | (unsigned long long)buffer_info->dma, |
| 463 | buffer_info->skb, next_desc); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 464 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 465 | if (netif_msg_pktdata(adapter) && |
| 466 | buffer_info->skb) |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 467 | print_hex_dump(KERN_INFO, "", |
| 468 | DUMP_PREFIX_ADDRESS, 16, |
| 469 | 1, |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 470 | buffer_info->skb->data, |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 471 | adapter->rx_buffer_len, |
| 472 | true); |
| 473 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 474 | } |
| 475 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 476 | } |
| 477 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 478 | /** |
| 479 | * e1000_desc_unused - calculate if we have unused descriptors |
| 480 | **/ |
| 481 | static int e1000_desc_unused(struct e1000_ring *ring) |
| 482 | { |
| 483 | if (ring->next_to_clean > ring->next_to_use) |
| 484 | return ring->next_to_clean - ring->next_to_use - 1; |
| 485 | |
| 486 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; |
| 487 | } |
| 488 | |
| 489 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 490 | * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp |
| 491 | * @adapter: board private structure |
| 492 | * @hwtstamps: time stamp structure to update |
| 493 | * @systim: unsigned 64bit system time value. |
| 494 | * |
| 495 | * Convert the system time value stored in the RX/TXSTMP registers into a |
| 496 | * hwtstamp which can be used by the upper level time stamping functions. |
| 497 | * |
| 498 | * The 'systim_lock' spinlock is used to protect the consistency of the |
| 499 | * system time value. This is needed because reading the 64 bit time |
| 500 | * value involves reading two 32 bit registers. The first read latches the |
| 501 | * value. |
| 502 | **/ |
| 503 | static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter, |
| 504 | struct skb_shared_hwtstamps *hwtstamps, |
| 505 | u64 systim) |
| 506 | { |
| 507 | u64 ns; |
| 508 | unsigned long flags; |
| 509 | |
| 510 | spin_lock_irqsave(&adapter->systim_lock, flags); |
| 511 | ns = timecounter_cyc2time(&adapter->tc, systim); |
| 512 | spin_unlock_irqrestore(&adapter->systim_lock, flags); |
| 513 | |
| 514 | memset(hwtstamps, 0, sizeof(*hwtstamps)); |
| 515 | hwtstamps->hwtstamp = ns_to_ktime(ns); |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp |
| 520 | * @adapter: board private structure |
| 521 | * @status: descriptor extended error and status field |
| 522 | * @skb: particular skb to include time stamp |
| 523 | * |
| 524 | * If the time stamp is valid, convert it into the timecounter ns value |
| 525 | * and store that result into the shhwtstamps structure which is passed |
| 526 | * up the network stack. |
| 527 | **/ |
| 528 | static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status, |
| 529 | struct sk_buff *skb) |
| 530 | { |
| 531 | struct e1000_hw *hw = &adapter->hw; |
| 532 | u64 rxstmp; |
| 533 | |
| 534 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) || |
| 535 | !(status & E1000_RXDEXT_STATERR_TST) || |
| 536 | !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) |
| 537 | return; |
| 538 | |
| 539 | /* The Rx time stamp registers contain the time stamp. No other |
| 540 | * received packet will be time stamped until the Rx time stamp |
| 541 | * registers are read. Because only one packet can be time stamped |
| 542 | * at a time, the register values must belong to this packet and |
| 543 | * therefore none of the other additional attributes need to be |
| 544 | * compared. |
| 545 | */ |
| 546 | rxstmp = (u64)er32(RXSTMPL); |
| 547 | rxstmp |= (u64)er32(RXSTMPH) << 32; |
| 548 | e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp); |
| 549 | |
| 550 | adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP; |
| 551 | } |
| 552 | |
| 553 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 554 | * e1000_receive_skb - helper function to handle Rx indications |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 555 | * @adapter: board private structure |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 556 | * @staterr: descriptor extended error and status field as written by hardware |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 557 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
| 558 | * @skb: pointer to sk_buff to be indicated to stack |
| 559 | **/ |
| 560 | static void e1000_receive_skb(struct e1000_adapter *adapter, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 561 | struct net_device *netdev, struct sk_buff *skb, |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 562 | u32 staterr, __le16 vlan) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 563 | { |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 564 | u16 tag = le16_to_cpu(vlan); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 565 | |
| 566 | e1000e_rx_hwtstamp(adapter, staterr, skb); |
| 567 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 568 | skb->protocol = eth_type_trans(skb, netdev); |
| 569 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 570 | if (staterr & E1000_RXD_STAT_VP) |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 571 | __vlan_hwaccel_put_tag(skb, tag); |
| 572 | |
| 573 | napi_gro_receive(&adapter->napi, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 577 | * e1000_rx_checksum - Receive Checksum Offload |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 578 | * @adapter: board private structure |
| 579 | * @status_err: receive descriptor status and error fields |
| 580 | * @csum: receive descriptor csum field |
| 581 | * @sk_buff: socket buffer with received data |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 582 | **/ |
| 583 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 584 | struct sk_buff *skb) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 585 | { |
| 586 | u16 status = (u16)status_err; |
| 587 | u8 errors = (u8)(status_err >> 24); |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 588 | |
| 589 | skb_checksum_none_assert(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 590 | |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 591 | /* Rx checksum disabled */ |
| 592 | if (!(adapter->netdev->features & NETIF_F_RXCSUM)) |
| 593 | return; |
| 594 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 595 | /* Ignore Checksum bit is set */ |
| 596 | if (status & E1000_RXD_STAT_IXSM) |
| 597 | return; |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 598 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 599 | /* TCP/UDP checksum error bit or IP checksum error bit is set */ |
| 600 | if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 601 | /* let the stack verify checksum errors */ |
| 602 | adapter->hw_csum_err++; |
| 603 | return; |
| 604 | } |
| 605 | |
| 606 | /* TCP/UDP Checksum has not been calculated */ |
| 607 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
| 608 | return; |
| 609 | |
| 610 | /* It must be a TCP or UDP packet with a valid checksum */ |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 611 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 612 | adapter->hw_csum_good++; |
| 613 | } |
| 614 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 615 | 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] | 616 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 617 | struct e1000_adapter *adapter = rx_ring->adapter; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 618 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 619 | s32 ret_val = __ew32_prepare(hw); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 620 | |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 621 | writel(i, rx_ring->tail); |
| 622 | |
| 623 | if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 624 | u32 rctl = er32(RCTL); |
| 625 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 626 | e_err("ME firmware caused invalid RDT - resetting\n"); |
| 627 | schedule_work(&adapter->reset_task); |
| 628 | } |
| 629 | } |
| 630 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 631 | 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] | 632 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 633 | struct e1000_adapter *adapter = tx_ring->adapter; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 634 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 635 | s32 ret_val = __ew32_prepare(hw); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 636 | |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 637 | writel(i, tx_ring->tail); |
| 638 | |
| 639 | if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 640 | u32 tctl = er32(TCTL); |
| 641 | ew32(TCTL, tctl & ~E1000_TCTL_EN); |
| 642 | e_err("ME firmware caused invalid TDT - resetting\n"); |
| 643 | schedule_work(&adapter->reset_task); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | /** |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 648 | * e1000_alloc_rx_buffers - Replace used receive buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 649 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 650 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 651 | static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 652 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 653 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 654 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 655 | struct net_device *netdev = adapter->netdev; |
| 656 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 657 | union e1000_rx_desc_extended *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 658 | struct e1000_buffer *buffer_info; |
| 659 | struct sk_buff *skb; |
| 660 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 661 | unsigned int bufsz = adapter->rx_buffer_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 662 | |
| 663 | i = rx_ring->next_to_use; |
| 664 | buffer_info = &rx_ring->buffer_info[i]; |
| 665 | |
| 666 | while (cleaned_count--) { |
| 667 | skb = buffer_info->skb; |
| 668 | if (skb) { |
| 669 | skb_trim(skb, 0); |
| 670 | goto map_skb; |
| 671 | } |
| 672 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 673 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 674 | if (!skb) { |
| 675 | /* Better luck next round */ |
| 676 | adapter->alloc_rx_buff_failed++; |
| 677 | break; |
| 678 | } |
| 679 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 680 | buffer_info->skb = skb; |
| 681 | map_skb: |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 682 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 683 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 684 | DMA_FROM_DEVICE); |
| 685 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 686 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 687 | adapter->rx_dma_failed++; |
| 688 | break; |
| 689 | } |
| 690 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 691 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 692 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 693 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 694 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 695 | /* Force memory writes to complete before letting h/w |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 696 | * know there are new descriptors to fetch. (Only |
| 697 | * applicable for weak-ordered memory model archs, |
| 698 | * such as IA-64). |
| 699 | */ |
| 700 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 701 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 702 | e1000e_update_rdt_wa(rx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 703 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 704 | writel(i, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 705 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 706 | i++; |
| 707 | if (i == rx_ring->count) |
| 708 | i = 0; |
| 709 | buffer_info = &rx_ring->buffer_info[i]; |
| 710 | } |
| 711 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 712 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | /** |
| 716 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 717 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 718 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 719 | static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 720 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 721 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 722 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 723 | struct net_device *netdev = adapter->netdev; |
| 724 | struct pci_dev *pdev = adapter->pdev; |
| 725 | union e1000_rx_desc_packet_split *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 726 | struct e1000_buffer *buffer_info; |
| 727 | struct e1000_ps_page *ps_page; |
| 728 | struct sk_buff *skb; |
| 729 | unsigned int i, j; |
| 730 | |
| 731 | i = rx_ring->next_to_use; |
| 732 | buffer_info = &rx_ring->buffer_info[i]; |
| 733 | |
| 734 | while (cleaned_count--) { |
| 735 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 736 | |
| 737 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 738 | ps_page = &buffer_info->ps_pages[j]; |
| 739 | if (j >= adapter->rx_ps_pages) { |
| 740 | /* all unused desc entries get hw null ptr */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 741 | rx_desc->read.buffer_addr[j + 1] = |
| 742 | ~cpu_to_le64(0); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 743 | continue; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 744 | } |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 745 | if (!ps_page->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 746 | ps_page->page = alloc_page(gfp); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 747 | if (!ps_page->page) { |
| 748 | adapter->alloc_rx_buff_failed++; |
| 749 | goto no_buffers; |
| 750 | } |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 751 | ps_page->dma = dma_map_page(&pdev->dev, |
| 752 | ps_page->page, |
| 753 | 0, PAGE_SIZE, |
| 754 | DMA_FROM_DEVICE); |
| 755 | if (dma_mapping_error(&pdev->dev, |
| 756 | ps_page->dma)) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 757 | dev_err(&adapter->pdev->dev, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 758 | "Rx DMA page map failed\n"); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 759 | adapter->rx_dma_failed++; |
| 760 | goto no_buffers; |
| 761 | } |
| 762 | } |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 763 | /* Refresh the desc even if buffer_addrs |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 764 | * didn't change because each write-back |
| 765 | * erases this info. |
| 766 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 767 | rx_desc->read.buffer_addr[j + 1] = |
| 768 | cpu_to_le64(ps_page->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 771 | skb = __netdev_alloc_skb_ip_align(netdev, |
| 772 | adapter->rx_ps_bsize0, |
| 773 | gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 774 | |
| 775 | if (!skb) { |
| 776 | adapter->alloc_rx_buff_failed++; |
| 777 | break; |
| 778 | } |
| 779 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 780 | buffer_info->skb = skb; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 781 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 782 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 783 | DMA_FROM_DEVICE); |
| 784 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 785 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 786 | adapter->rx_dma_failed++; |
| 787 | /* cleanup skb */ |
| 788 | dev_kfree_skb_any(skb); |
| 789 | buffer_info->skb = NULL; |
| 790 | break; |
| 791 | } |
| 792 | |
| 793 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 794 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 795 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 796 | /* Force memory writes to complete before letting h/w |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 797 | * know there are new descriptors to fetch. (Only |
| 798 | * applicable for weak-ordered memory model archs, |
| 799 | * such as IA-64). |
| 800 | */ |
| 801 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 802 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 803 | e1000e_update_rdt_wa(rx_ring, i << 1); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 804 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 805 | writel(i << 1, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 806 | } |
| 807 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 808 | i++; |
| 809 | if (i == rx_ring->count) |
| 810 | i = 0; |
| 811 | buffer_info = &rx_ring->buffer_info[i]; |
| 812 | } |
| 813 | |
| 814 | no_buffers: |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 815 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 819 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 820 | * @rx_ring: Rx descriptor ring |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 821 | * @cleaned_count: number of buffers to allocate this pass |
| 822 | **/ |
| 823 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 824 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 825 | int cleaned_count, gfp_t gfp) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 826 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 827 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 828 | struct net_device *netdev = adapter->netdev; |
| 829 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 830 | union e1000_rx_desc_extended *rx_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 831 | struct e1000_buffer *buffer_info; |
| 832 | struct sk_buff *skb; |
| 833 | unsigned int i; |
Bruce Allan | 2a2293b | 2012-12-05 06:26:35 +0000 | [diff] [blame] | 834 | unsigned int bufsz = 256 - 16; /* for skb_reserve */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 835 | |
| 836 | i = rx_ring->next_to_use; |
| 837 | buffer_info = &rx_ring->buffer_info[i]; |
| 838 | |
| 839 | while (cleaned_count--) { |
| 840 | skb = buffer_info->skb; |
| 841 | if (skb) { |
| 842 | skb_trim(skb, 0); |
| 843 | goto check_page; |
| 844 | } |
| 845 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 846 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 847 | if (unlikely(!skb)) { |
| 848 | /* Better luck next round */ |
| 849 | adapter->alloc_rx_buff_failed++; |
| 850 | break; |
| 851 | } |
| 852 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 853 | buffer_info->skb = skb; |
| 854 | check_page: |
| 855 | /* allocate a new page if necessary */ |
| 856 | if (!buffer_info->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 857 | buffer_info->page = alloc_page(gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 858 | if (unlikely(!buffer_info->page)) { |
| 859 | adapter->alloc_rx_buff_failed++; |
| 860 | break; |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | if (!buffer_info->dma) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 865 | buffer_info->dma = dma_map_page(&pdev->dev, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 866 | buffer_info->page, 0, |
| 867 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 868 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 869 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 870 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 871 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 872 | |
| 873 | if (unlikely(++i == rx_ring->count)) |
| 874 | i = 0; |
| 875 | buffer_info = &rx_ring->buffer_info[i]; |
| 876 | } |
| 877 | |
| 878 | if (likely(rx_ring->next_to_use != i)) { |
| 879 | rx_ring->next_to_use = i; |
| 880 | if (unlikely(i-- == 0)) |
| 881 | i = (rx_ring->count - 1); |
| 882 | |
| 883 | /* Force memory writes to complete before letting h/w |
| 884 | * know there are new descriptors to fetch. (Only |
| 885 | * applicable for weak-ordered memory model archs, |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 886 | * such as IA-64). |
| 887 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 888 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 889 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 890 | e1000e_update_rdt_wa(rx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 891 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 892 | writel(i, rx_ring->tail); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 896 | static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss, |
| 897 | struct sk_buff *skb) |
| 898 | { |
| 899 | if (netdev->features & NETIF_F_RXHASH) |
| 900 | skb->rxhash = le32_to_cpu(rss); |
| 901 | } |
| 902 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 903 | /** |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 904 | * e1000_clean_rx_irq - Send received data up the network stack |
| 905 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 906 | * |
| 907 | * the return value indicates whether actual cleaning was done, there |
| 908 | * is no guarantee that everything was cleaned |
| 909 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 910 | static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
| 911 | int work_to_do) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 912 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 913 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 914 | struct net_device *netdev = adapter->netdev; |
| 915 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 916 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 917 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 918 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 919 | u32 length, staterr; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 920 | unsigned int i; |
| 921 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 922 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 923 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 924 | |
| 925 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 926 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 927 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 928 | buffer_info = &rx_ring->buffer_info[i]; |
| 929 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 930 | while (staterr & E1000_RXD_STAT_DD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 931 | struct sk_buff *skb; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 932 | |
| 933 | if (*work_done >= work_to_do) |
| 934 | break; |
| 935 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 936 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 937 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 938 | skb = buffer_info->skb; |
| 939 | buffer_info->skb = NULL; |
| 940 | |
| 941 | prefetch(skb->data - NET_IP_ALIGN); |
| 942 | |
| 943 | i++; |
| 944 | if (i == rx_ring->count) |
| 945 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 946 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 947 | prefetch(next_rxd); |
| 948 | |
| 949 | next_buffer = &rx_ring->buffer_info[i]; |
| 950 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 951 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 952 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 953 | dma_unmap_single(&pdev->dev, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 954 | buffer_info->dma, |
| 955 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 956 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 957 | buffer_info->dma = 0; |
| 958 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 959 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 960 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 961 | /* !EOP means multiple descriptors were used to store a single |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 962 | * packet, if that's the case we need to toss it. In fact, we |
| 963 | * need to toss every packet with the EOP bit clear and the |
| 964 | * next frame that _does_ have the EOP bit set, as it is by |
| 965 | * definition only a frame fragment |
| 966 | */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 967 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 968 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 969 | |
| 970 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 971 | /* All receives must fit into a single buffer */ |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 972 | e_dbg("Receive packet consumed multiple buffers\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 973 | /* recycle */ |
| 974 | buffer_info->skb = skb; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 975 | if (staterr & E1000_RXD_STAT_EOP) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 976 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 977 | goto next_desc; |
| 978 | } |
| 979 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 980 | if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 981 | !(netdev->features & NETIF_F_RXALL))) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 982 | /* recycle */ |
| 983 | buffer_info->skb = skb; |
| 984 | goto next_desc; |
| 985 | } |
| 986 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 987 | /* adjust length to remove Ethernet CRC */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 988 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 989 | /* If configured to store CRC, don't subtract FCS, |
| 990 | * but keep the FCS bytes out of the total_rx_bytes |
| 991 | * counter |
| 992 | */ |
| 993 | if (netdev->features & NETIF_F_RXFCS) |
| 994 | total_rx_bytes -= 4; |
| 995 | else |
| 996 | length -= 4; |
| 997 | } |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 998 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 999 | total_rx_bytes += length; |
| 1000 | total_rx_packets++; |
| 1001 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1002 | /* code added for copybreak, this should improve |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1003 | * performance for small packets with large amounts |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1004 | * of reassembly being done in the stack |
| 1005 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1006 | if (length < copybreak) { |
| 1007 | struct sk_buff *new_skb = |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 1008 | netdev_alloc_skb_ip_align(netdev, length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1009 | if (new_skb) { |
Bruce Allan | 808ff67 | 2008-08-08 18:35:56 -0700 | [diff] [blame] | 1010 | skb_copy_to_linear_data_offset(new_skb, |
| 1011 | -NET_IP_ALIGN, |
| 1012 | (skb->data - |
| 1013 | NET_IP_ALIGN), |
| 1014 | (length + |
| 1015 | NET_IP_ALIGN)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1016 | /* save the skb in buffer_info as good */ |
| 1017 | buffer_info->skb = skb; |
| 1018 | skb = new_skb; |
| 1019 | } |
| 1020 | /* else just continue with the old one */ |
| 1021 | } |
| 1022 | /* end copybreak code */ |
| 1023 | skb_put(skb, length); |
| 1024 | |
| 1025 | /* Receive Checksum Offload */ |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1026 | e1000_rx_checksum(adapter, staterr, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1027 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1028 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1029 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1030 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1031 | rx_desc->wb.upper.vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1032 | |
| 1033 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1034 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1035 | |
| 1036 | /* return some buffers to hardware, one at a time is too slow */ |
| 1037 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1038 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1039 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1040 | cleaned_count = 0; |
| 1041 | } |
| 1042 | |
| 1043 | /* use prefetched values */ |
| 1044 | rx_desc = next_rxd; |
| 1045 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1046 | |
| 1047 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1048 | } |
| 1049 | rx_ring->next_to_clean = i; |
| 1050 | |
| 1051 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1052 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1053 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1054 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1055 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1056 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1057 | return cleaned; |
| 1058 | } |
| 1059 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1060 | static void e1000_put_txbuf(struct e1000_ring *tx_ring, |
| 1061 | struct e1000_buffer *buffer_info) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1062 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1063 | struct e1000_adapter *adapter = tx_ring->adapter; |
| 1064 | |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1065 | if (buffer_info->dma) { |
| 1066 | if (buffer_info->mapped_as_page) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1067 | dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, |
| 1068 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1069 | else |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1070 | dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, |
| 1071 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1072 | buffer_info->dma = 0; |
| 1073 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1074 | if (buffer_info->skb) { |
| 1075 | dev_kfree_skb_any(buffer_info->skb); |
| 1076 | buffer_info->skb = NULL; |
| 1077 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 1078 | buffer_info->time_stamp = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1081 | static void e1000_print_hw_hang(struct work_struct *work) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1082 | { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1083 | struct e1000_adapter *adapter = container_of(work, |
| 1084 | struct e1000_adapter, |
| 1085 | print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1086 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1087 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1088 | unsigned int i = tx_ring->next_to_clean; |
| 1089 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; |
| 1090 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1091 | struct e1000_hw *hw = &adapter->hw; |
| 1092 | u16 phy_status, phy_1000t_status, phy_ext_status; |
| 1093 | u16 pci_status; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1094 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1095 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1096 | return; |
| 1097 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1098 | if (!adapter->tx_hang_recheck && |
| 1099 | (adapter->flags2 & FLAG2_DMA_BURST)) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1100 | /* May be block on write-back, flush and detect again |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1101 | * flush pending descriptor writebacks to memory |
| 1102 | */ |
| 1103 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 1104 | /* execute the writes immediately */ |
| 1105 | e1e_flush(); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1106 | /* Due to rare timing issues, write to TIDV again to ensure |
Matthew Vick | bf03085 | 2012-03-16 09:03:00 +0000 | [diff] [blame] | 1107 | * the write is successful |
| 1108 | */ |
| 1109 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 1110 | /* execute the writes immediately */ |
| 1111 | e1e_flush(); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1112 | adapter->tx_hang_recheck = true; |
| 1113 | return; |
| 1114 | } |
| 1115 | /* Real hang detected */ |
| 1116 | adapter->tx_hang_recheck = false; |
| 1117 | netif_stop_queue(netdev); |
| 1118 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame^] | 1119 | e1e_rphy(hw, MII_BMSR, &phy_status); |
| 1120 | e1e_rphy(hw, MII_STAT1000, &phy_1000t_status); |
| 1121 | e1e_rphy(hw, MII_ESTATUS, &phy_ext_status); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1122 | |
| 1123 | pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status); |
| 1124 | |
| 1125 | /* detected Hardware unit hang */ |
| 1126 | e_err("Detected Hardware Unit Hang:\n" |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1127 | " TDH <%x>\n" |
| 1128 | " TDT <%x>\n" |
| 1129 | " next_to_use <%x>\n" |
| 1130 | " next_to_clean <%x>\n" |
| 1131 | "buffer_info[next_to_clean]:\n" |
| 1132 | " time_stamp <%lx>\n" |
| 1133 | " next_to_watch <%x>\n" |
| 1134 | " jiffies <%lx>\n" |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1135 | " next_to_watch.status <%x>\n" |
| 1136 | "MAC Status <%x>\n" |
| 1137 | "PHY Status <%x>\n" |
| 1138 | "PHY 1000BASE-T Status <%x>\n" |
| 1139 | "PHY Extended Status <%x>\n" |
| 1140 | "PCI Status <%x>\n", |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1141 | readl(tx_ring->head), |
| 1142 | readl(tx_ring->tail), |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1143 | tx_ring->next_to_use, |
| 1144 | tx_ring->next_to_clean, |
| 1145 | tx_ring->buffer_info[eop].time_stamp, |
| 1146 | eop, |
| 1147 | jiffies, |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1148 | eop_desc->upper.fields.status, |
| 1149 | er32(STATUS), |
| 1150 | phy_status, |
| 1151 | phy_1000t_status, |
| 1152 | phy_ext_status, |
| 1153 | pci_status); |
Bruce Allan | 7c0427e | 2012-03-20 03:48:08 +0000 | [diff] [blame] | 1154 | |
| 1155 | /* Suggest workaround for known h/w issue */ |
| 1156 | if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE)) |
| 1157 | e_err("Try turning off Tx pause (flow control) via ethtool\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1161 | * e1000e_tx_hwtstamp_work - check for Tx time stamp |
| 1162 | * @work: pointer to work struct |
| 1163 | * |
| 1164 | * This work function polls the TSYNCTXCTL valid bit to determine when a |
| 1165 | * timestamp has been taken for the current stored skb. The timestamp must |
| 1166 | * be for this skb because only one such packet is allowed in the queue. |
| 1167 | */ |
| 1168 | static void e1000e_tx_hwtstamp_work(struct work_struct *work) |
| 1169 | { |
| 1170 | struct e1000_adapter *adapter = container_of(work, struct e1000_adapter, |
| 1171 | tx_hwtstamp_work); |
| 1172 | struct e1000_hw *hw = &adapter->hw; |
| 1173 | |
| 1174 | if (!adapter->tx_hwtstamp_skb) |
| 1175 | return; |
| 1176 | |
| 1177 | if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) { |
| 1178 | struct skb_shared_hwtstamps shhwtstamps; |
| 1179 | u64 txstmp; |
| 1180 | |
| 1181 | txstmp = er32(TXSTMPL); |
| 1182 | txstmp |= (u64)er32(TXSTMPH) << 32; |
| 1183 | |
| 1184 | e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp); |
| 1185 | |
| 1186 | skb_tstamp_tx(adapter->tx_hwtstamp_skb, &shhwtstamps); |
| 1187 | dev_kfree_skb_any(adapter->tx_hwtstamp_skb); |
| 1188 | adapter->tx_hwtstamp_skb = NULL; |
| 1189 | } else { |
| 1190 | /* reschedule to check later */ |
| 1191 | schedule_work(&adapter->tx_hwtstamp_work); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1196 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1197 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1198 | * |
| 1199 | * the return value indicates whether actual cleaning was done, there |
| 1200 | * is no guarantee that everything was cleaned |
| 1201 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1202 | static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1203 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1204 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1205 | struct net_device *netdev = adapter->netdev; |
| 1206 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1207 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 1208 | struct e1000_buffer *buffer_info; |
| 1209 | unsigned int i, eop; |
| 1210 | unsigned int count = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1211 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1212 | unsigned int bytes_compl = 0, pkts_compl = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1213 | |
| 1214 | i = tx_ring->next_to_clean; |
| 1215 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1216 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 1217 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1218 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 1219 | (count < tx_ring->count)) { |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1220 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1221 | rmb(); /* read buffer_info after eop_desc */ |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1222 | for (; !cleaned; count++) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1223 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 1224 | buffer_info = &tx_ring->buffer_info[i]; |
| 1225 | cleaned = (i == eop); |
| 1226 | |
| 1227 | if (cleaned) { |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 1228 | total_tx_packets += buffer_info->segs; |
| 1229 | total_tx_bytes += buffer_info->bytecount; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1230 | if (buffer_info->skb) { |
| 1231 | bytes_compl += buffer_info->skb->len; |
| 1232 | pkts_compl++; |
| 1233 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1236 | e1000_put_txbuf(tx_ring, buffer_info); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1237 | tx_desc->upper.data = 0; |
| 1238 | |
| 1239 | i++; |
| 1240 | if (i == tx_ring->count) |
| 1241 | i = 0; |
| 1242 | } |
| 1243 | |
Terry Loftin | dac8761 | 2010-04-09 10:29:49 +0000 | [diff] [blame] | 1244 | if (i == tx_ring->next_to_use) |
| 1245 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1246 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1247 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | tx_ring->next_to_clean = i; |
| 1251 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1252 | netdev_completed_queue(netdev, pkts_compl, bytes_compl); |
| 1253 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1254 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1255 | if (count && netif_carrier_ok(netdev) && |
| 1256 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1257 | /* Make sure that anybody stopping the queue after this |
| 1258 | * sees the new next_to_clean. |
| 1259 | */ |
| 1260 | smp_mb(); |
| 1261 | |
| 1262 | if (netif_queue_stopped(netdev) && |
| 1263 | !(test_bit(__E1000_DOWN, &adapter->state))) { |
| 1264 | netif_wake_queue(netdev); |
| 1265 | ++adapter->restart_queue; |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | if (adapter->detect_tx_hung) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1270 | /* Detect a transmit hang in hardware, this serializes the |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1271 | * check with the clearing of time_stamp and movement of i |
| 1272 | */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1273 | adapter->detect_tx_hung = false; |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1274 | if (tx_ring->buffer_info[i].time_stamp && |
| 1275 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1276 | + (adapter->tx_timeout_factor * HZ)) && |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1277 | !(er32(STATUS) & E1000_STATUS_TXOFF)) |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1278 | schedule_work(&adapter->print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1279 | else |
| 1280 | adapter->tx_hang_recheck = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1281 | } |
| 1282 | adapter->total_tx_bytes += total_tx_bytes; |
| 1283 | adapter->total_tx_packets += total_tx_packets; |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1284 | return count < tx_ring->count; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1288 | * 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] | 1289 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1290 | * |
| 1291 | * the return value indicates whether actual cleaning was done, there |
| 1292 | * is no guarantee that everything was cleaned |
| 1293 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1294 | static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done, |
| 1295 | int work_to_do) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1296 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1297 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1298 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1299 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
| 1300 | struct net_device *netdev = adapter->netdev; |
| 1301 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1302 | struct e1000_buffer *buffer_info, *next_buffer; |
| 1303 | struct e1000_ps_page *ps_page; |
| 1304 | struct sk_buff *skb; |
| 1305 | unsigned int i, j; |
| 1306 | u32 length, staterr; |
| 1307 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1308 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1309 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 1310 | |
| 1311 | i = rx_ring->next_to_clean; |
| 1312 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 1313 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1314 | buffer_info = &rx_ring->buffer_info[i]; |
| 1315 | |
| 1316 | while (staterr & E1000_RXD_STAT_DD) { |
| 1317 | if (*work_done >= work_to_do) |
| 1318 | break; |
| 1319 | (*work_done)++; |
| 1320 | skb = buffer_info->skb; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1321 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1322 | |
| 1323 | /* in the packet split case this is header only */ |
| 1324 | prefetch(skb->data - NET_IP_ALIGN); |
| 1325 | |
| 1326 | i++; |
| 1327 | if (i == rx_ring->count) |
| 1328 | i = 0; |
| 1329 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
| 1330 | prefetch(next_rxd); |
| 1331 | |
| 1332 | next_buffer = &rx_ring->buffer_info[i]; |
| 1333 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1334 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1335 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1336 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1337 | adapter->rx_ps_bsize0, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1338 | buffer_info->dma = 0; |
| 1339 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1340 | /* see !EOP comment in other Rx routine */ |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1341 | if (!(staterr & E1000_RXD_STAT_EOP)) |
| 1342 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 1343 | |
| 1344 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1345 | 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] | 1346 | dev_kfree_skb_irq(skb); |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1347 | if (staterr & E1000_RXD_STAT_EOP) |
| 1348 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1349 | goto next_desc; |
| 1350 | } |
| 1351 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 1352 | if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 1353 | !(netdev->features & NETIF_F_RXALL))) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1354 | dev_kfree_skb_irq(skb); |
| 1355 | goto next_desc; |
| 1356 | } |
| 1357 | |
| 1358 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 1359 | |
| 1360 | if (!length) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1361 | e_dbg("Last part of the packet spanning multiple descriptors\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1362 | dev_kfree_skb_irq(skb); |
| 1363 | goto next_desc; |
| 1364 | } |
| 1365 | |
| 1366 | /* Good Receive */ |
| 1367 | skb_put(skb, length); |
| 1368 | |
| 1369 | { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1370 | /* this looks ugly, but it seems compiler issues make |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1371 | * it more efficient than reusing j |
| 1372 | */ |
| 1373 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1374 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1375 | /* page alloc/put takes too long and effects small |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1376 | * packet throughput, so unsplit small packets and |
| 1377 | * save the alloc/put only valid in softirq (napi) |
| 1378 | * context to call kmap_* |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1379 | */ |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1380 | if (l1 && (l1 <= copybreak) && |
| 1381 | ((length + l1) <= adapter->rx_ps_bsize0)) { |
| 1382 | u8 *vaddr; |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 1383 | |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1384 | ps_page = &buffer_info->ps_pages[0]; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1385 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1386 | /* there is no documentation about how to call |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1387 | * kmap_atomic, so we can't hold the mapping |
| 1388 | * very long |
| 1389 | */ |
| 1390 | dma_sync_single_for_cpu(&pdev->dev, |
| 1391 | ps_page->dma, |
| 1392 | PAGE_SIZE, |
| 1393 | DMA_FROM_DEVICE); |
Linus Torvalds | 9f39383 | 2012-03-21 09:40:26 -0700 | [diff] [blame] | 1394 | vaddr = kmap_atomic(ps_page->page); |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1395 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
Linus Torvalds | 9f39383 | 2012-03-21 09:40:26 -0700 | [diff] [blame] | 1396 | kunmap_atomic(vaddr); |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1397 | dma_sync_single_for_device(&pdev->dev, |
| 1398 | ps_page->dma, |
| 1399 | PAGE_SIZE, |
| 1400 | DMA_FROM_DEVICE); |
| 1401 | |
| 1402 | /* remove the CRC */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 1403 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 1404 | if (!(netdev->features & NETIF_F_RXFCS)) |
| 1405 | l1 -= 4; |
| 1406 | } |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1407 | |
| 1408 | skb_put(skb, l1); |
| 1409 | goto copydone; |
| 1410 | } /* if */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
| 1414 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); |
| 1415 | if (!length) |
| 1416 | break; |
| 1417 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1418 | ps_page = &buffer_info->ps_pages[j]; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1419 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1420 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1421 | ps_page->dma = 0; |
| 1422 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); |
| 1423 | ps_page->page = NULL; |
| 1424 | skb->len += length; |
| 1425 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1426 | skb->truesize += PAGE_SIZE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1429 | /* strip the ethernet crc, problem is we're using pages now so |
| 1430 | * this whole operation can get a little cpu intensive |
| 1431 | */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 1432 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 1433 | if (!(netdev->features & NETIF_F_RXFCS)) |
| 1434 | pskb_trim(skb, skb->len - 4); |
| 1435 | } |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1436 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1437 | copydone: |
| 1438 | total_rx_bytes += skb->len; |
| 1439 | total_rx_packets++; |
| 1440 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1441 | e1000_rx_checksum(adapter, staterr, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1442 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1443 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1444 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1445 | if (rx_desc->wb.upper.header_status & |
| 1446 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) |
| 1447 | adapter->rx_hdr_split++; |
| 1448 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1449 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1450 | rx_desc->wb.middle.vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1451 | |
| 1452 | next_desc: |
| 1453 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
| 1454 | buffer_info->skb = NULL; |
| 1455 | |
| 1456 | /* return some buffers to hardware, one at a time is too slow */ |
| 1457 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1458 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1459 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1460 | cleaned_count = 0; |
| 1461 | } |
| 1462 | |
| 1463 | /* use prefetched values */ |
| 1464 | rx_desc = next_rxd; |
| 1465 | buffer_info = next_buffer; |
| 1466 | |
| 1467 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1468 | } |
| 1469 | rx_ring->next_to_clean = i; |
| 1470 | |
| 1471 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1472 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1473 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1474 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1475 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1476 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1477 | return cleaned; |
| 1478 | } |
| 1479 | |
| 1480 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1481 | * e1000_consume_page - helper function |
| 1482 | **/ |
| 1483 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
| 1484 | u16 length) |
| 1485 | { |
| 1486 | bi->page = NULL; |
| 1487 | skb->len += length; |
| 1488 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1489 | skb->truesize += PAGE_SIZE; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | /** |
| 1493 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 1494 | * @adapter: board private structure |
| 1495 | * |
| 1496 | * the return value indicates whether actual cleaning was done, there |
| 1497 | * is no guarantee that everything was cleaned |
| 1498 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1499 | static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
| 1500 | int work_to_do) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1501 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1502 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1503 | struct net_device *netdev = adapter->netdev; |
| 1504 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1505 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1506 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1507 | u32 length, staterr; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1508 | unsigned int i; |
| 1509 | int cleaned_count = 0; |
| 1510 | bool cleaned = false; |
| 1511 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
| 1512 | |
| 1513 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1514 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 1515 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1516 | buffer_info = &rx_ring->buffer_info[i]; |
| 1517 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1518 | while (staterr & E1000_RXD_STAT_DD) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1519 | struct sk_buff *skb; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1520 | |
| 1521 | if (*work_done >= work_to_do) |
| 1522 | break; |
| 1523 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 1524 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1525 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1526 | skb = buffer_info->skb; |
| 1527 | buffer_info->skb = NULL; |
| 1528 | |
| 1529 | ++i; |
| 1530 | if (i == rx_ring->count) |
| 1531 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1532 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1533 | prefetch(next_rxd); |
| 1534 | |
| 1535 | next_buffer = &rx_ring->buffer_info[i]; |
| 1536 | |
| 1537 | cleaned = true; |
| 1538 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1539 | dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE, |
| 1540 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1541 | buffer_info->dma = 0; |
| 1542 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1543 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1544 | |
| 1545 | /* errors is only valid for DD + EOP descriptors */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1546 | if (unlikely((staterr & E1000_RXD_STAT_EOP) && |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 1547 | ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 1548 | !(netdev->features & NETIF_F_RXALL)))) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1549 | /* recycle both page and skb */ |
| 1550 | buffer_info->skb = skb; |
| 1551 | /* an error means any chain goes out the window too */ |
| 1552 | if (rx_ring->rx_skb_top) |
| 1553 | dev_kfree_skb_irq(rx_ring->rx_skb_top); |
| 1554 | rx_ring->rx_skb_top = NULL; |
| 1555 | goto next_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
Bruce Allan | f0f1a17 | 2010-12-11 05:53:32 +0000 | [diff] [blame] | 1558 | #define rxtop (rx_ring->rx_skb_top) |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1559 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1560 | /* this descriptor is only the beginning (or middle) */ |
| 1561 | if (!rxtop) { |
| 1562 | /* this is the beginning of a chain */ |
| 1563 | rxtop = skb; |
| 1564 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
| 1565 | 0, length); |
| 1566 | } else { |
| 1567 | /* this is the middle of a chain */ |
| 1568 | skb_fill_page_desc(rxtop, |
| 1569 | skb_shinfo(rxtop)->nr_frags, |
| 1570 | buffer_info->page, 0, length); |
| 1571 | /* re-use the skb, only consumed the page */ |
| 1572 | buffer_info->skb = skb; |
| 1573 | } |
| 1574 | e1000_consume_page(buffer_info, rxtop, length); |
| 1575 | goto next_desc; |
| 1576 | } else { |
| 1577 | if (rxtop) { |
| 1578 | /* end of the chain */ |
| 1579 | skb_fill_page_desc(rxtop, |
| 1580 | skb_shinfo(rxtop)->nr_frags, |
| 1581 | buffer_info->page, 0, length); |
| 1582 | /* re-use the current skb, we only consumed the |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1583 | * page |
| 1584 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1585 | buffer_info->skb = skb; |
| 1586 | skb = rxtop; |
| 1587 | rxtop = NULL; |
| 1588 | e1000_consume_page(buffer_info, skb, length); |
| 1589 | } else { |
| 1590 | /* no chain, got EOP, this buf is the packet |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1591 | * copybreak to save the put_page/alloc_page |
| 1592 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1593 | if (length <= copybreak && |
| 1594 | skb_tailroom(skb) >= length) { |
| 1595 | u8 *vaddr; |
Cong Wang | 4679026 | 2011-11-25 23:14:23 +0800 | [diff] [blame] | 1596 | vaddr = kmap_atomic(buffer_info->page); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1597 | memcpy(skb_tail_pointer(skb), vaddr, |
| 1598 | length); |
Cong Wang | 4679026 | 2011-11-25 23:14:23 +0800 | [diff] [blame] | 1599 | kunmap_atomic(vaddr); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1600 | /* re-use the page, so don't erase |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1601 | * buffer_info->page |
| 1602 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1603 | skb_put(skb, length); |
| 1604 | } else { |
| 1605 | skb_fill_page_desc(skb, 0, |
| 1606 | buffer_info->page, 0, |
| 1607 | length); |
| 1608 | e1000_consume_page(buffer_info, skb, |
| 1609 | length); |
| 1610 | } |
| 1611 | } |
| 1612 | } |
| 1613 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1614 | /* Receive Checksum Offload */ |
| 1615 | e1000_rx_checksum(adapter, staterr, skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1616 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1617 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1618 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1619 | /* probably a little skewed due to removing CRC */ |
| 1620 | total_rx_bytes += skb->len; |
| 1621 | total_rx_packets++; |
| 1622 | |
| 1623 | /* eth type trans needs skb->data to point to something */ |
| 1624 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1625 | e_err("pskb_may_pull failed.\n"); |
Bruce Allan | ef5ab89 | 2011-02-10 08:17:21 +0000 | [diff] [blame] | 1626 | dev_kfree_skb_irq(skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1627 | goto next_desc; |
| 1628 | } |
| 1629 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1630 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1631 | rx_desc->wb.upper.vlan); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1632 | |
| 1633 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1634 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1635 | |
| 1636 | /* return some buffers to hardware, one at a time is too slow */ |
| 1637 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1638 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1639 | GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1640 | cleaned_count = 0; |
| 1641 | } |
| 1642 | |
| 1643 | /* use prefetched values */ |
| 1644 | rx_desc = next_rxd; |
| 1645 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1646 | |
| 1647 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1648 | } |
| 1649 | rx_ring->next_to_clean = i; |
| 1650 | |
| 1651 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1652 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1653 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1654 | |
| 1655 | adapter->total_rx_bytes += total_rx_bytes; |
| 1656 | adapter->total_rx_packets += total_rx_packets; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1657 | return cleaned; |
| 1658 | } |
| 1659 | |
| 1660 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1661 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1662 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1663 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1664 | static void e1000_clean_rx_ring(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1665 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1666 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1667 | struct e1000_buffer *buffer_info; |
| 1668 | struct e1000_ps_page *ps_page; |
| 1669 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1670 | unsigned int i, j; |
| 1671 | |
| 1672 | /* Free all the Rx ring sk_buffs */ |
| 1673 | for (i = 0; i < rx_ring->count; i++) { |
| 1674 | buffer_info = &rx_ring->buffer_info[i]; |
| 1675 | if (buffer_info->dma) { |
| 1676 | if (adapter->clean_rx == e1000_clean_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1677 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1678 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1679 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1680 | else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1681 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1682 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1683 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1684 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1685 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1686 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1687 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1688 | buffer_info->dma = 0; |
| 1689 | } |
| 1690 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1691 | if (buffer_info->page) { |
| 1692 | put_page(buffer_info->page); |
| 1693 | buffer_info->page = NULL; |
| 1694 | } |
| 1695 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1696 | if (buffer_info->skb) { |
| 1697 | dev_kfree_skb(buffer_info->skb); |
| 1698 | buffer_info->skb = NULL; |
| 1699 | } |
| 1700 | |
| 1701 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1702 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1703 | if (!ps_page->page) |
| 1704 | break; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1705 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1706 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1707 | ps_page->dma = 0; |
| 1708 | put_page(ps_page->page); |
| 1709 | ps_page->page = NULL; |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | /* there also may be some cached data from a chained receive */ |
| 1714 | if (rx_ring->rx_skb_top) { |
| 1715 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 1716 | rx_ring->rx_skb_top = NULL; |
| 1717 | } |
| 1718 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1719 | /* Zero out the descriptor ring */ |
| 1720 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1721 | |
| 1722 | rx_ring->next_to_clean = 0; |
| 1723 | rx_ring->next_to_use = 0; |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1724 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1725 | |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1726 | writel(0, rx_ring->head); |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 1727 | if (rx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 1728 | e1000e_update_rdt_wa(rx_ring, 0); |
| 1729 | else |
| 1730 | writel(0, rx_ring->tail); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1733 | static void e1000e_downshift_workaround(struct work_struct *work) |
| 1734 | { |
| 1735 | struct e1000_adapter *adapter = container_of(work, |
| 1736 | struct e1000_adapter, downshift_task); |
| 1737 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1738 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1739 | return; |
| 1740 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1741 | e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); |
| 1742 | } |
| 1743 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1744 | /** |
| 1745 | * e1000_intr_msi - Interrupt Handler |
| 1746 | * @irq: interrupt number |
| 1747 | * @data: pointer to a network interface device structure |
| 1748 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1749 | static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1750 | { |
| 1751 | struct net_device *netdev = data; |
| 1752 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1753 | struct e1000_hw *hw = &adapter->hw; |
| 1754 | u32 icr = er32(ICR); |
| 1755 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1756 | /* read ICR disables interrupts using IAM */ |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1757 | if (icr & E1000_ICR_LSC) { |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1758 | hw->mac.get_link_status = true; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1759 | /* ICH8 workaround-- Call gig speed drop workaround on cable |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1760 | * disconnect (LSC) before accessing any PHY registers |
| 1761 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1762 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1763 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1764 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1765 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1766 | /* 80003ES2LAN workaround-- For packet buffer work-around on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1767 | * link down event; disable receives here in the ISR and reset |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1768 | * adapter in watchdog |
| 1769 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1770 | if (netif_carrier_ok(netdev) && |
| 1771 | adapter->flags & FLAG_RX_NEEDS_RESTART) { |
| 1772 | /* disable receives */ |
| 1773 | u32 rctl = er32(RCTL); |
| 1774 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 1775 | adapter->flags |= FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1776 | } |
| 1777 | /* guard against interrupt when we're going down */ |
| 1778 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1779 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1780 | } |
| 1781 | |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1782 | /* Reset on uncorrectable ECC error */ |
| 1783 | if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) { |
| 1784 | u32 pbeccsts = er32(PBECCSTS); |
| 1785 | |
| 1786 | adapter->corr_errors += |
| 1787 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 1788 | adapter->uncorr_errors += |
| 1789 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 1790 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 1791 | |
| 1792 | /* Do the reset outside of interrupt context */ |
| 1793 | schedule_work(&adapter->reset_task); |
| 1794 | |
| 1795 | /* return immediately since reset is imminent */ |
| 1796 | return IRQ_HANDLED; |
| 1797 | } |
| 1798 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1799 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1800 | adapter->total_tx_bytes = 0; |
| 1801 | adapter->total_tx_packets = 0; |
| 1802 | adapter->total_rx_bytes = 0; |
| 1803 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1804 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | return IRQ_HANDLED; |
| 1808 | } |
| 1809 | |
| 1810 | /** |
| 1811 | * e1000_intr - Interrupt Handler |
| 1812 | * @irq: interrupt number |
| 1813 | * @data: pointer to a network interface device structure |
| 1814 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1815 | static irqreturn_t e1000_intr(int __always_unused irq, void *data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1816 | { |
| 1817 | struct net_device *netdev = data; |
| 1818 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1819 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1820 | u32 rctl, icr = er32(ICR); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1821 | |
Bruce Allan | a68ea77 | 2009-11-20 23:23:16 +0000 | [diff] [blame] | 1822 | if (!icr || test_bit(__E1000_DOWN, &adapter->state)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1823 | return IRQ_NONE; /* Not our interrupt */ |
| 1824 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1825 | /* 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] | 1826 | * not set, then the adapter didn't send an interrupt |
| 1827 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1828 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 1829 | return IRQ_NONE; |
| 1830 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1831 | /* Interrupt Auto-Mask...upon reading ICR, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1832 | * interrupts are masked. No need for the |
| 1833 | * IMC write |
| 1834 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1835 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1836 | if (icr & E1000_ICR_LSC) { |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1837 | hw->mac.get_link_status = true; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1838 | /* ICH8 workaround-- Call gig speed drop workaround on cable |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1839 | * disconnect (LSC) before accessing any PHY registers |
| 1840 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1841 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1842 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1843 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1844 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1845 | /* 80003ES2LAN workaround-- |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1846 | * For packet buffer work-around on link down event; |
| 1847 | * disable receives here in the ISR and |
| 1848 | * reset adapter in watchdog |
| 1849 | */ |
| 1850 | if (netif_carrier_ok(netdev) && |
| 1851 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { |
| 1852 | /* disable receives */ |
| 1853 | rctl = er32(RCTL); |
| 1854 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 1855 | adapter->flags |= FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1856 | } |
| 1857 | /* guard against interrupt when we're going down */ |
| 1858 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1859 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1860 | } |
| 1861 | |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1862 | /* Reset on uncorrectable ECC error */ |
| 1863 | if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) { |
| 1864 | u32 pbeccsts = er32(PBECCSTS); |
| 1865 | |
| 1866 | adapter->corr_errors += |
| 1867 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 1868 | adapter->uncorr_errors += |
| 1869 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 1870 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 1871 | |
| 1872 | /* Do the reset outside of interrupt context */ |
| 1873 | schedule_work(&adapter->reset_task); |
| 1874 | |
| 1875 | /* return immediately since reset is imminent */ |
| 1876 | return IRQ_HANDLED; |
| 1877 | } |
| 1878 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1879 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1880 | adapter->total_tx_bytes = 0; |
| 1881 | adapter->total_tx_packets = 0; |
| 1882 | adapter->total_rx_bytes = 0; |
| 1883 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1884 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | return IRQ_HANDLED; |
| 1888 | } |
| 1889 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1890 | static irqreturn_t e1000_msix_other(int __always_unused irq, void *data) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1891 | { |
| 1892 | struct net_device *netdev = data; |
| 1893 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1894 | struct e1000_hw *hw = &adapter->hw; |
| 1895 | u32 icr = er32(ICR); |
| 1896 | |
| 1897 | if (!(icr & E1000_ICR_INT_ASSERTED)) { |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1898 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1899 | ew32(IMS, E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1900 | return IRQ_NONE; |
| 1901 | } |
| 1902 | |
| 1903 | if (icr & adapter->eiac_mask) |
| 1904 | ew32(ICS, (icr & adapter->eiac_mask)); |
| 1905 | |
| 1906 | if (icr & E1000_ICR_OTHER) { |
| 1907 | if (!(icr & E1000_ICR_LSC)) |
| 1908 | goto no_link_interrupt; |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1909 | hw->mac.get_link_status = true; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1910 | /* guard against interrupt when we're going down */ |
| 1911 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1912 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 1913 | } |
| 1914 | |
| 1915 | no_link_interrupt: |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 1916 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1917 | ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1918 | |
| 1919 | return IRQ_HANDLED; |
| 1920 | } |
| 1921 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1922 | 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] | 1923 | { |
| 1924 | struct net_device *netdev = data; |
| 1925 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1926 | struct e1000_hw *hw = &adapter->hw; |
| 1927 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1928 | |
| 1929 | |
| 1930 | adapter->total_tx_bytes = 0; |
| 1931 | adapter->total_tx_packets = 0; |
| 1932 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1933 | if (!e1000_clean_tx_irq(tx_ring)) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1934 | /* Ring was not completely cleaned, so fire another interrupt */ |
| 1935 | ew32(ICS, tx_ring->ims_val); |
| 1936 | |
| 1937 | return IRQ_HANDLED; |
| 1938 | } |
| 1939 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1940 | 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] | 1941 | { |
| 1942 | struct net_device *netdev = data; |
| 1943 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1944 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1945 | |
| 1946 | /* Write the ITR value calculated at the end of the |
| 1947 | * previous interrupt. |
| 1948 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1949 | if (rx_ring->set_itr) { |
| 1950 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 1951 | rx_ring->itr_register); |
| 1952 | rx_ring->set_itr = 0; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1955 | if (napi_schedule_prep(&adapter->napi)) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1956 | adapter->total_rx_bytes = 0; |
| 1957 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1958 | __napi_schedule(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1959 | } |
| 1960 | return IRQ_HANDLED; |
| 1961 | } |
| 1962 | |
| 1963 | /** |
| 1964 | * e1000_configure_msix - Configure MSI-X hardware |
| 1965 | * |
| 1966 | * e1000_configure_msix sets up the hardware to properly |
| 1967 | * generate MSI-X interrupts. |
| 1968 | **/ |
| 1969 | static void e1000_configure_msix(struct e1000_adapter *adapter) |
| 1970 | { |
| 1971 | struct e1000_hw *hw = &adapter->hw; |
| 1972 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1973 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1974 | int vector = 0; |
| 1975 | u32 ctrl_ext, ivar = 0; |
| 1976 | |
| 1977 | adapter->eiac_mask = 0; |
| 1978 | |
| 1979 | /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ |
| 1980 | if (hw->mac.type == e1000_82574) { |
| 1981 | u32 rfctl = er32(RFCTL); |
| 1982 | rfctl |= E1000_RFCTL_ACK_DIS; |
| 1983 | ew32(RFCTL, rfctl); |
| 1984 | } |
| 1985 | |
| 1986 | #define E1000_IVAR_INT_ALLOC_VALID 0x8 |
| 1987 | /* Configure Rx vector */ |
| 1988 | rx_ring->ims_val = E1000_IMS_RXQ0; |
| 1989 | adapter->eiac_mask |= rx_ring->ims_val; |
| 1990 | if (rx_ring->itr_val) |
| 1991 | writel(1000000000 / (rx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1992 | rx_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, rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1995 | ivar = E1000_IVAR_INT_ALLOC_VALID | vector; |
| 1996 | |
| 1997 | /* Configure Tx vector */ |
| 1998 | tx_ring->ims_val = E1000_IMS_TXQ0; |
| 1999 | vector++; |
| 2000 | if (tx_ring->itr_val) |
| 2001 | writel(1000000000 / (tx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2002 | tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2003 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2004 | writel(1, tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2005 | adapter->eiac_mask |= tx_ring->ims_val; |
| 2006 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); |
| 2007 | |
| 2008 | /* set vector for Other Causes, e.g. link changes */ |
| 2009 | vector++; |
| 2010 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); |
| 2011 | if (rx_ring->itr_val) |
| 2012 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 2013 | hw->hw_addr + E1000_EITR_82574(vector)); |
| 2014 | else |
| 2015 | writel(1, hw->hw_addr + E1000_EITR_82574(vector)); |
| 2016 | |
| 2017 | /* Cause Tx interrupts on every write back */ |
| 2018 | ivar |= (1 << 31); |
| 2019 | |
| 2020 | ew32(IVAR, ivar); |
| 2021 | |
| 2022 | /* enable MSI-X PBA support */ |
| 2023 | ctrl_ext = er32(CTRL_EXT); |
| 2024 | ctrl_ext |= E1000_CTRL_EXT_PBA_CLR; |
| 2025 | |
| 2026 | /* Auto-Mask Other interrupts upon ICR read */ |
| 2027 | #define E1000_EIAC_MASK_82574 0x01F00000 |
| 2028 | ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER); |
| 2029 | ctrl_ext |= E1000_CTRL_EXT_EIAME; |
| 2030 | ew32(CTRL_EXT, ctrl_ext); |
| 2031 | e1e_flush(); |
| 2032 | } |
| 2033 | |
| 2034 | void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) |
| 2035 | { |
| 2036 | if (adapter->msix_entries) { |
| 2037 | pci_disable_msix(adapter->pdev); |
| 2038 | kfree(adapter->msix_entries); |
| 2039 | adapter->msix_entries = NULL; |
| 2040 | } else if (adapter->flags & FLAG_MSI_ENABLED) { |
| 2041 | pci_disable_msi(adapter->pdev); |
| 2042 | adapter->flags &= ~FLAG_MSI_ENABLED; |
| 2043 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | /** |
| 2047 | * e1000e_set_interrupt_capability - set MSI or MSI-X if supported |
| 2048 | * |
| 2049 | * Attempt to configure interrupts using the best available |
| 2050 | * capabilities of the hardware and kernel. |
| 2051 | **/ |
| 2052 | void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) |
| 2053 | { |
| 2054 | int err; |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2055 | int i; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2056 | |
| 2057 | switch (adapter->int_mode) { |
| 2058 | case E1000E_INT_MODE_MSIX: |
| 2059 | if (adapter->flags & FLAG_HAS_MSIX) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2060 | adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */ |
| 2061 | adapter->msix_entries = kcalloc(adapter->num_vectors, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2062 | sizeof(struct msix_entry), |
| 2063 | GFP_KERNEL); |
| 2064 | if (adapter->msix_entries) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2065 | for (i = 0; i < adapter->num_vectors; i++) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2066 | adapter->msix_entries[i].entry = i; |
| 2067 | |
| 2068 | err = pci_enable_msix(adapter->pdev, |
| 2069 | adapter->msix_entries, |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2070 | adapter->num_vectors); |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2071 | if (err == 0) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2072 | return; |
| 2073 | } |
| 2074 | /* MSI-X failed, so fall through and try MSI */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 2075 | 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] | 2076 | e1000e_reset_interrupt_capability(adapter); |
| 2077 | } |
| 2078 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 2079 | /* Fall through */ |
| 2080 | case E1000E_INT_MODE_MSI: |
| 2081 | if (!pci_enable_msi(adapter->pdev)) { |
| 2082 | adapter->flags |= FLAG_MSI_ENABLED; |
| 2083 | } else { |
| 2084 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 2085 | 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] | 2086 | } |
| 2087 | /* Fall through */ |
| 2088 | case E1000E_INT_MODE_LEGACY: |
| 2089 | /* Don't do anything; this is the system default */ |
| 2090 | break; |
| 2091 | } |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2092 | |
| 2093 | /* store the number of vectors being used */ |
| 2094 | adapter->num_vectors = 1; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | /** |
| 2098 | * e1000_request_msix - Initialize MSI-X interrupts |
| 2099 | * |
| 2100 | * e1000_request_msix allocates MSI-X vectors and requests interrupts from the |
| 2101 | * kernel. |
| 2102 | **/ |
| 2103 | static int e1000_request_msix(struct e1000_adapter *adapter) |
| 2104 | { |
| 2105 | struct net_device *netdev = adapter->netdev; |
| 2106 | int err = 0, vector = 0; |
| 2107 | |
| 2108 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 2109 | snprintf(adapter->rx_ring->name, |
| 2110 | sizeof(adapter->rx_ring->name) - 1, |
| 2111 | "%s-rx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2112 | else |
| 2113 | memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); |
| 2114 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2115 | e1000_intr_msix_rx, 0, adapter->rx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2116 | netdev); |
| 2117 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2118 | return err; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2119 | adapter->rx_ring->itr_register = adapter->hw.hw_addr + |
| 2120 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2121 | adapter->rx_ring->itr_val = adapter->itr; |
| 2122 | vector++; |
| 2123 | |
| 2124 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 2125 | snprintf(adapter->tx_ring->name, |
| 2126 | sizeof(adapter->tx_ring->name) - 1, |
| 2127 | "%s-tx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2128 | else |
| 2129 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); |
| 2130 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2131 | e1000_intr_msix_tx, 0, adapter->tx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2132 | netdev); |
| 2133 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2134 | return err; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2135 | adapter->tx_ring->itr_register = adapter->hw.hw_addr + |
| 2136 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2137 | adapter->tx_ring->itr_val = adapter->itr; |
| 2138 | vector++; |
| 2139 | |
| 2140 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2141 | e1000_msix_other, 0, netdev->name, netdev); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2142 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2143 | return err; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2144 | |
| 2145 | e1000_configure_msix(adapter); |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2146 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2147 | return 0; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2150 | /** |
| 2151 | * e1000_request_irq - initialize interrupts |
| 2152 | * |
| 2153 | * Attempts to configure interrupts using the best available |
| 2154 | * capabilities of the hardware and kernel. |
| 2155 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2156 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 2157 | { |
| 2158 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2159 | int err; |
| 2160 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2161 | if (adapter->msix_entries) { |
| 2162 | err = e1000_request_msix(adapter); |
| 2163 | if (!err) |
| 2164 | return err; |
| 2165 | /* fall back to MSI */ |
| 2166 | e1000e_reset_interrupt_capability(adapter); |
| 2167 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 2168 | e1000e_set_interrupt_capability(adapter); |
| 2169 | } |
| 2170 | if (adapter->flags & FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2171 | err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2172 | netdev->name, netdev); |
| 2173 | if (!err) |
| 2174 | return err; |
| 2175 | |
| 2176 | /* fall back to legacy interrupt */ |
| 2177 | e1000e_reset_interrupt_capability(adapter); |
| 2178 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2181 | err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2182 | netdev->name, netdev); |
| 2183 | if (err) |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2184 | e_err("Unable to allocate interrupt, Error: %d\n", err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2185 | |
| 2186 | return err; |
| 2187 | } |
| 2188 | |
| 2189 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 2190 | { |
| 2191 | struct net_device *netdev = adapter->netdev; |
| 2192 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2193 | if (adapter->msix_entries) { |
| 2194 | int vector = 0; |
| 2195 | |
| 2196 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2197 | vector++; |
| 2198 | |
| 2199 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2200 | vector++; |
| 2201 | |
| 2202 | /* Other Causes interrupt vector */ |
| 2203 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2204 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2205 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2206 | |
| 2207 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | /** |
| 2211 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 2212 | **/ |
| 2213 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
| 2214 | { |
| 2215 | struct e1000_hw *hw = &adapter->hw; |
| 2216 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2217 | ew32(IMC, ~0); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2218 | if (adapter->msix_entries) |
| 2219 | ew32(EIAC_82574, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2220 | e1e_flush(); |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2221 | |
| 2222 | if (adapter->msix_entries) { |
| 2223 | int i; |
| 2224 | for (i = 0; i < adapter->num_vectors; i++) |
| 2225 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2226 | } else { |
| 2227 | synchronize_irq(adapter->pdev->irq); |
| 2228 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | /** |
| 2232 | * e1000_irq_enable - Enable default interrupt generation settings |
| 2233 | **/ |
| 2234 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
| 2235 | { |
| 2236 | struct e1000_hw *hw = &adapter->hw; |
| 2237 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2238 | if (adapter->msix_entries) { |
| 2239 | ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); |
| 2240 | ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC); |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 2241 | } else if (hw->mac.type == e1000_pch_lpt) { |
| 2242 | ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2243 | } else { |
| 2244 | ew32(IMS, IMS_ENABLE_MASK); |
| 2245 | } |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 2246 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2250 | * 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] | 2251 | * @adapter: address of board private structure |
| 2252 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2253 | * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2254 | * For ASF and Pass Through versions of f/w this means that |
| 2255 | * the driver is loaded. For AMT version (only with 82573) |
| 2256 | * of the f/w this means that the network i/f is open. |
| 2257 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2258 | void e1000e_get_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2259 | { |
| 2260 | struct e1000_hw *hw = &adapter->hw; |
| 2261 | u32 ctrl_ext; |
| 2262 | u32 swsm; |
| 2263 | |
| 2264 | /* Let firmware know the driver has taken over */ |
| 2265 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2266 | swsm = er32(SWSM); |
| 2267 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
| 2268 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2269 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2270 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2275 | * 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] | 2276 | * @adapter: address of board private structure |
| 2277 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2278 | * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2279 | * For ASF and Pass Through versions of f/w this means that the |
| 2280 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 2281 | * of the f/w this means that the network i/f is closed. |
| 2282 | * |
| 2283 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2284 | void e1000e_release_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2285 | { |
| 2286 | struct e1000_hw *hw = &adapter->hw; |
| 2287 | u32 ctrl_ext; |
| 2288 | u32 swsm; |
| 2289 | |
| 2290 | /* Let firmware taken over control of h/w */ |
| 2291 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2292 | swsm = er32(SWSM); |
| 2293 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
| 2294 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2295 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2296 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2297 | } |
| 2298 | } |
| 2299 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2300 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 2301 | * e1000_alloc_ring_dma - allocate memory for a ring structure |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2302 | **/ |
| 2303 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, |
| 2304 | struct e1000_ring *ring) |
| 2305 | { |
| 2306 | struct pci_dev *pdev = adapter->pdev; |
| 2307 | |
| 2308 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, |
| 2309 | GFP_KERNEL); |
| 2310 | if (!ring->desc) |
| 2311 | return -ENOMEM; |
| 2312 | |
| 2313 | return 0; |
| 2314 | } |
| 2315 | |
| 2316 | /** |
| 2317 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2318 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2319 | * |
| 2320 | * Return 0 on success, negative on failure |
| 2321 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2322 | int e1000e_setup_tx_resources(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2323 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2324 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2325 | int err = -ENOMEM, size; |
| 2326 | |
| 2327 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2328 | tx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2329 | if (!tx_ring->buffer_info) |
| 2330 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2331 | |
| 2332 | /* round up to nearest 4K */ |
| 2333 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
| 2334 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2335 | |
| 2336 | err = e1000_alloc_ring_dma(adapter, tx_ring); |
| 2337 | if (err) |
| 2338 | goto err; |
| 2339 | |
| 2340 | tx_ring->next_to_use = 0; |
| 2341 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2342 | |
| 2343 | return 0; |
| 2344 | err: |
| 2345 | vfree(tx_ring->buffer_info); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 2346 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2347 | return err; |
| 2348 | } |
| 2349 | |
| 2350 | /** |
| 2351 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2352 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2353 | * |
| 2354 | * Returns 0 on success, negative on failure |
| 2355 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2356 | int e1000e_setup_rx_resources(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2357 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2358 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2359 | struct e1000_buffer *buffer_info; |
| 2360 | int i, size, desc_len, err = -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2361 | |
| 2362 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2363 | rx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2364 | if (!rx_ring->buffer_info) |
| 2365 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2366 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2367 | for (i = 0; i < rx_ring->count; i++) { |
| 2368 | buffer_info = &rx_ring->buffer_info[i]; |
| 2369 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, |
| 2370 | sizeof(struct e1000_ps_page), |
| 2371 | GFP_KERNEL); |
| 2372 | if (!buffer_info->ps_pages) |
| 2373 | goto err_pages; |
| 2374 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2375 | |
| 2376 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 2377 | |
| 2378 | /* Round up to nearest 4K */ |
| 2379 | rx_ring->size = rx_ring->count * desc_len; |
| 2380 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2381 | |
| 2382 | err = e1000_alloc_ring_dma(adapter, rx_ring); |
| 2383 | if (err) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2384 | goto err_pages; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2385 | |
| 2386 | rx_ring->next_to_clean = 0; |
| 2387 | rx_ring->next_to_use = 0; |
| 2388 | rx_ring->rx_skb_top = NULL; |
| 2389 | |
| 2390 | return 0; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2391 | |
| 2392 | err_pages: |
| 2393 | for (i = 0; i < rx_ring->count; i++) { |
| 2394 | buffer_info = &rx_ring->buffer_info[i]; |
| 2395 | kfree(buffer_info->ps_pages); |
| 2396 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2397 | err: |
| 2398 | vfree(rx_ring->buffer_info); |
Bruce Allan | e926244 | 2010-11-24 06:02:06 +0000 | [diff] [blame] | 2399 | e_err("Unable to allocate memory for the receive descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2400 | return err; |
| 2401 | } |
| 2402 | |
| 2403 | /** |
| 2404 | * e1000_clean_tx_ring - Free Tx Buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2405 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2406 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2407 | static void e1000_clean_tx_ring(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2408 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2409 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2410 | struct e1000_buffer *buffer_info; |
| 2411 | unsigned long size; |
| 2412 | unsigned int i; |
| 2413 | |
| 2414 | for (i = 0; i < tx_ring->count; i++) { |
| 2415 | buffer_info = &tx_ring->buffer_info[i]; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2416 | e1000_put_txbuf(tx_ring, buffer_info); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 2419 | netdev_reset_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2420 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2421 | memset(tx_ring->buffer_info, 0, size); |
| 2422 | |
| 2423 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2424 | |
| 2425 | tx_ring->next_to_use = 0; |
| 2426 | tx_ring->next_to_clean = 0; |
| 2427 | |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2428 | writel(0, tx_ring->head); |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 2429 | if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 2430 | e1000e_update_tdt_wa(tx_ring, 0); |
| 2431 | else |
| 2432 | writel(0, tx_ring->tail); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | /** |
| 2436 | * e1000e_free_tx_resources - Free Tx Resources per Queue |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2437 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2438 | * |
| 2439 | * Free all transmit software resources |
| 2440 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2441 | void e1000e_free_tx_resources(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2442 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2443 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2444 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2445 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2446 | e1000_clean_tx_ring(tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2447 | |
| 2448 | vfree(tx_ring->buffer_info); |
| 2449 | tx_ring->buffer_info = NULL; |
| 2450 | |
| 2451 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 2452 | tx_ring->dma); |
| 2453 | tx_ring->desc = NULL; |
| 2454 | } |
| 2455 | |
| 2456 | /** |
| 2457 | * e1000e_free_rx_resources - Free Rx Resources |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2458 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2459 | * |
| 2460 | * Free all receive software resources |
| 2461 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2462 | void e1000e_free_rx_resources(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2463 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2464 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2465 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2466 | int i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2467 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2468 | e1000_clean_rx_ring(rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2469 | |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2470 | for (i = 0; i < rx_ring->count; i++) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2471 | kfree(rx_ring->buffer_info[i].ps_pages); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2472 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2473 | vfree(rx_ring->buffer_info); |
| 2474 | rx_ring->buffer_info = NULL; |
| 2475 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2476 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 2477 | rx_ring->dma); |
| 2478 | rx_ring->desc = NULL; |
| 2479 | } |
| 2480 | |
| 2481 | /** |
| 2482 | * e1000_update_itr - update the dynamic ITR value based on statistics |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2483 | * @adapter: pointer to adapter |
| 2484 | * @itr_setting: current adapter->itr |
| 2485 | * @packets: the number of packets during this measurement interval |
| 2486 | * @bytes: the number of bytes during this measurement interval |
| 2487 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2488 | * Stores a new ITR value based on packets and byte |
| 2489 | * counts during the last interrupt. The advantage of per interrupt |
| 2490 | * computation is faster updates and more accurate ITR for the current |
| 2491 | * traffic pattern. Constants in this function were computed |
| 2492 | * based on theoretical maximum wire speed and thresholds were set based |
| 2493 | * on testing data as well as attempting to minimize response time |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2494 | * while increasing bulk throughput. This functionality is controlled |
| 2495 | * by the InterruptThrottleRate module parameter. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2496 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2497 | 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] | 2498 | { |
| 2499 | unsigned int retval = itr_setting; |
| 2500 | |
| 2501 | if (packets == 0) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2502 | return itr_setting; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2503 | |
| 2504 | switch (itr_setting) { |
| 2505 | case lowest_latency: |
| 2506 | /* handle TSO and jumbo frames */ |
| 2507 | if (bytes/packets > 8000) |
| 2508 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2509 | else if ((packets < 5) && (bytes > 512)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2510 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2511 | break; |
| 2512 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2513 | if (bytes > 10000) { |
| 2514 | /* this if handles the TSO accounting */ |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2515 | if (bytes/packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2516 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2517 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2518 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2519 | else if ((packets > 35)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2520 | retval = lowest_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2521 | } else if (bytes/packets > 2000) { |
| 2522 | retval = bulk_latency; |
| 2523 | } else if (packets <= 2 && bytes < 512) { |
| 2524 | retval = lowest_latency; |
| 2525 | } |
| 2526 | break; |
| 2527 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2528 | if (bytes > 25000) { |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2529 | if (packets > 35) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2530 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2531 | } else if (bytes < 6000) { |
| 2532 | retval = low_latency; |
| 2533 | } |
| 2534 | break; |
| 2535 | } |
| 2536 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2537 | return retval; |
| 2538 | } |
| 2539 | |
| 2540 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2541 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2542 | u16 current_itr; |
| 2543 | u32 new_itr = adapter->itr; |
| 2544 | |
| 2545 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2546 | if (adapter->link_speed != SPEED_1000) { |
| 2547 | current_itr = 0; |
| 2548 | new_itr = 4000; |
| 2549 | goto set_itr_now; |
| 2550 | } |
| 2551 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2552 | if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 2553 | new_itr = 0; |
| 2554 | goto set_itr_now; |
| 2555 | } |
| 2556 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2557 | adapter->tx_itr = e1000_update_itr(adapter->tx_itr, |
| 2558 | adapter->total_tx_packets, |
| 2559 | adapter->total_tx_bytes); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2560 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2561 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2562 | adapter->tx_itr = low_latency; |
| 2563 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2564 | adapter->rx_itr = e1000_update_itr(adapter->rx_itr, |
| 2565 | adapter->total_rx_packets, |
| 2566 | adapter->total_rx_bytes); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2567 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2568 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2569 | adapter->rx_itr = low_latency; |
| 2570 | |
| 2571 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2572 | |
| 2573 | switch (current_itr) { |
| 2574 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2575 | case lowest_latency: |
| 2576 | new_itr = 70000; |
| 2577 | break; |
| 2578 | case low_latency: |
| 2579 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2580 | break; |
| 2581 | case bulk_latency: |
| 2582 | new_itr = 4000; |
| 2583 | break; |
| 2584 | default: |
| 2585 | break; |
| 2586 | } |
| 2587 | |
| 2588 | set_itr_now: |
| 2589 | if (new_itr != adapter->itr) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2590 | /* this attempts to bias the interrupt rate towards Bulk |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2591 | * by adding intermediate steps when interrupt rate is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2592 | * increasing |
| 2593 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2594 | new_itr = new_itr > adapter->itr ? |
| 2595 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2596 | new_itr; |
| 2597 | adapter->itr = new_itr; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2598 | adapter->rx_ring->itr_val = new_itr; |
| 2599 | if (adapter->msix_entries) |
| 2600 | adapter->rx_ring->set_itr = 1; |
| 2601 | else |
Bruce Allan | e3d14b0 | 2012-12-05 06:26:51 +0000 | [diff] [blame] | 2602 | e1000e_write_itr(adapter, new_itr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2603 | } |
| 2604 | } |
| 2605 | |
| 2606 | /** |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 2607 | * e1000e_write_itr - write the ITR value to the appropriate registers |
| 2608 | * @adapter: address of board private structure |
| 2609 | * @itr: new ITR value to program |
| 2610 | * |
| 2611 | * e1000e_write_itr determines if the adapter is in MSI-X mode |
| 2612 | * and, if so, writes the EITR registers with the ITR value. |
| 2613 | * Otherwise, it writes the ITR value into the ITR register. |
| 2614 | **/ |
| 2615 | void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr) |
| 2616 | { |
| 2617 | struct e1000_hw *hw = &adapter->hw; |
| 2618 | u32 new_itr = itr ? 1000000000 / (itr * 256) : 0; |
| 2619 | |
| 2620 | if (adapter->msix_entries) { |
| 2621 | int vector; |
| 2622 | |
| 2623 | for (vector = 0; vector < adapter->num_vectors; vector++) |
| 2624 | writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector)); |
| 2625 | } else { |
| 2626 | ew32(ITR, new_itr); |
| 2627 | } |
| 2628 | } |
| 2629 | |
| 2630 | /** |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2631 | * e1000_alloc_queues - Allocate memory for all rings |
| 2632 | * @adapter: board private structure to initialize |
| 2633 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 2634 | static int e1000_alloc_queues(struct e1000_adapter *adapter) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2635 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2636 | int size = sizeof(struct e1000_ring); |
| 2637 | |
| 2638 | adapter->tx_ring = kzalloc(size, GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2639 | if (!adapter->tx_ring) |
| 2640 | goto err; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2641 | adapter->tx_ring->count = adapter->tx_ring_count; |
| 2642 | adapter->tx_ring->adapter = adapter; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2643 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2644 | adapter->rx_ring = kzalloc(size, GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2645 | if (!adapter->rx_ring) |
| 2646 | goto err; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2647 | adapter->rx_ring->count = adapter->rx_ring_count; |
| 2648 | adapter->rx_ring->adapter = adapter; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2649 | |
| 2650 | return 0; |
| 2651 | err: |
| 2652 | e_err("Unable to allocate memory for queues\n"); |
| 2653 | kfree(adapter->rx_ring); |
| 2654 | kfree(adapter->tx_ring); |
| 2655 | return -ENOMEM; |
| 2656 | } |
| 2657 | |
| 2658 | /** |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2659 | * e1000e_poll - NAPI Rx polling callback |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2660 | * @napi: struct associated with this polling callback |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2661 | * @weight: number of packets driver is allowed to process this poll |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2662 | **/ |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2663 | static int e1000e_poll(struct napi_struct *napi, int weight) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2664 | { |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2665 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, |
| 2666 | napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2667 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2668 | struct net_device *poll_dev = adapter->netdev; |
Andy Gospodarek | 679e8a0 | 2009-06-18 11:57:37 +0000 | [diff] [blame] | 2669 | int tx_cleaned = 1, work_done = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2670 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 2671 | adapter = netdev_priv(poll_dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2672 | |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2673 | if (!adapter->msix_entries || |
| 2674 | (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) |
| 2675 | tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2676 | |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2677 | adapter->clean_rx(adapter->rx_ring, &work_done, weight); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2678 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 2679 | if (!tx_cleaned) |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2680 | work_done = weight; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2681 | |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2682 | /* If weight not fully consumed, exit the polling mode */ |
| 2683 | if (work_done < weight) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2684 | if (adapter->itr_setting & 3) |
| 2685 | e1000_set_itr(adapter); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2686 | napi_complete(napi); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 2687 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 2688 | if (adapter->msix_entries) |
| 2689 | ew32(IMS, adapter->rx_ring->ims_val); |
| 2690 | else |
| 2691 | e1000_irq_enable(adapter); |
| 2692 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | return work_done; |
| 2696 | } |
| 2697 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2698 | 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] | 2699 | { |
| 2700 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2701 | struct e1000_hw *hw = &adapter->hw; |
| 2702 | u32 vfta, index; |
| 2703 | |
| 2704 | /* don't update vlan cookie if already programmed */ |
| 2705 | if ((adapter->hw.mng_cookie.status & |
| 2706 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2707 | (vid == adapter->mng_vlan_id)) |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2708 | return 0; |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2709 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2710 | /* add VID to filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2711 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2712 | index = (vid >> 5) & 0x7F; |
| 2713 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2714 | vfta |= (1 << (vid & 0x1F)); |
| 2715 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2716 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2717 | |
| 2718 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2719 | |
| 2720 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2723 | 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] | 2724 | { |
| 2725 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2726 | struct e1000_hw *hw = &adapter->hw; |
| 2727 | u32 vfta, index; |
| 2728 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2729 | if ((adapter->hw.mng_cookie.status & |
| 2730 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2731 | (vid == adapter->mng_vlan_id)) { |
| 2732 | /* release control to f/w */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2733 | e1000e_release_hw_control(adapter); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2734 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | /* remove VID from filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2738 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2739 | index = (vid >> 5) & 0x7F; |
| 2740 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
| 2741 | vfta &= ~(1 << (vid & 0x1F)); |
| 2742 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2743 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2744 | |
| 2745 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2746 | |
| 2747 | return 0; |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | /** |
| 2751 | * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering |
| 2752 | * @adapter: board private structure to initialize |
| 2753 | **/ |
| 2754 | static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter) |
| 2755 | { |
| 2756 | struct net_device *netdev = adapter->netdev; |
| 2757 | struct e1000_hw *hw = &adapter->hw; |
| 2758 | u32 rctl; |
| 2759 | |
| 2760 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2761 | /* disable VLAN receive filtering */ |
| 2762 | rctl = er32(RCTL); |
| 2763 | rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN); |
| 2764 | ew32(RCTL, rctl); |
| 2765 | |
| 2766 | if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { |
| 2767 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 2768 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 2769 | } |
| 2770 | } |
| 2771 | } |
| 2772 | |
| 2773 | /** |
| 2774 | * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering |
| 2775 | * @adapter: board private structure to initialize |
| 2776 | **/ |
| 2777 | static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter) |
| 2778 | { |
| 2779 | struct e1000_hw *hw = &adapter->hw; |
| 2780 | u32 rctl; |
| 2781 | |
| 2782 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2783 | /* enable VLAN receive filtering */ |
| 2784 | rctl = er32(RCTL); |
| 2785 | rctl |= E1000_RCTL_VFE; |
| 2786 | rctl &= ~E1000_RCTL_CFIEN; |
| 2787 | ew32(RCTL, rctl); |
| 2788 | } |
| 2789 | } |
| 2790 | |
| 2791 | /** |
| 2792 | * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping |
| 2793 | * @adapter: board private structure to initialize |
| 2794 | **/ |
| 2795 | static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter) |
| 2796 | { |
| 2797 | struct e1000_hw *hw = &adapter->hw; |
| 2798 | u32 ctrl; |
| 2799 | |
| 2800 | /* disable VLAN tag insert/strip */ |
| 2801 | ctrl = er32(CTRL); |
| 2802 | ctrl &= ~E1000_CTRL_VME; |
| 2803 | ew32(CTRL, ctrl); |
| 2804 | } |
| 2805 | |
| 2806 | /** |
| 2807 | * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping |
| 2808 | * @adapter: board private structure to initialize |
| 2809 | **/ |
| 2810 | static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter) |
| 2811 | { |
| 2812 | struct e1000_hw *hw = &adapter->hw; |
| 2813 | u32 ctrl; |
| 2814 | |
| 2815 | /* enable VLAN tag insert/strip */ |
| 2816 | ctrl = er32(CTRL); |
| 2817 | ctrl |= E1000_CTRL_VME; |
| 2818 | ew32(CTRL, ctrl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 2822 | { |
| 2823 | struct net_device *netdev = adapter->netdev; |
| 2824 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 2825 | u16 old_vid = adapter->mng_vlan_id; |
| 2826 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2827 | if (adapter->hw.mng_cookie.status & |
| 2828 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
| 2829 | e1000_vlan_rx_add_vid(netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2830 | adapter->mng_vlan_id = vid; |
| 2831 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2832 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2833 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid)) |
| 2834 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
| 2838 | { |
| 2839 | u16 vid; |
| 2840 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2841 | e1000_vlan_rx_add_vid(adapter->netdev, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2842 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2843 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2844 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2845 | } |
| 2846 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2847 | static void e1000_init_manageability_pt(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2848 | { |
| 2849 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2850 | u32 manc, manc2h, mdef, i, j; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2851 | |
| 2852 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) |
| 2853 | return; |
| 2854 | |
| 2855 | manc = er32(MANC); |
| 2856 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2857 | /* enable receiving management packets to the host. this will probably |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2858 | * generate destination unreachable messages from the host OS, but |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2859 | * the packets will be handled on SMBUS |
| 2860 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2861 | manc |= E1000_MANC_EN_MNG2HOST; |
| 2862 | manc2h = er32(MANC2H); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2863 | |
| 2864 | switch (hw->mac.type) { |
| 2865 | default: |
| 2866 | manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664); |
| 2867 | break; |
| 2868 | case e1000_82574: |
| 2869 | case e1000_82583: |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2870 | /* Check if IPMI pass-through decision filter already exists; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2871 | * if so, enable it. |
| 2872 | */ |
| 2873 | for (i = 0, j = 0; i < 8; i++) { |
| 2874 | mdef = er32(MDEF(i)); |
| 2875 | |
| 2876 | /* Ignore filters with anything other than IPMI ports */ |
Dan Carpenter | 3b21b50 | 2010-06-02 13:43:15 +0000 | [diff] [blame] | 2877 | if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2878 | continue; |
| 2879 | |
| 2880 | /* Enable this decision filter in MANC2H */ |
| 2881 | if (mdef) |
| 2882 | manc2h |= (1 << i); |
| 2883 | |
| 2884 | j |= mdef; |
| 2885 | } |
| 2886 | |
| 2887 | if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
| 2888 | break; |
| 2889 | |
| 2890 | /* Create new decision filter in an empty filter */ |
| 2891 | for (i = 0, j = 0; i < 8; i++) |
| 2892 | if (er32(MDEF(i)) == 0) { |
| 2893 | ew32(MDEF(i), (E1000_MDEF_PORT_623 | |
| 2894 | E1000_MDEF_PORT_664)); |
| 2895 | manc2h |= (1 << 1); |
| 2896 | j++; |
| 2897 | break; |
| 2898 | } |
| 2899 | |
| 2900 | if (!j) |
| 2901 | e_warn("Unable to create IPMI pass-through filter\n"); |
| 2902 | break; |
| 2903 | } |
| 2904 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2905 | ew32(MANC2H, manc2h); |
| 2906 | ew32(MANC, manc); |
| 2907 | } |
| 2908 | |
| 2909 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2910 | * e1000_configure_tx - Configure Transmit Unit after Reset |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2911 | * @adapter: board private structure |
| 2912 | * |
| 2913 | * Configure the Tx unit of the MAC after a reset. |
| 2914 | **/ |
| 2915 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
| 2916 | { |
| 2917 | struct e1000_hw *hw = &adapter->hw; |
| 2918 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2919 | u64 tdba; |
Bruce Allan | c550b12 | 2011-12-16 00:46:17 +0000 | [diff] [blame] | 2920 | u32 tdlen, tarc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2921 | |
| 2922 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 2923 | tdba = tx_ring->dma; |
| 2924 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 2925 | ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32))); |
| 2926 | ew32(TDBAH(0), (tdba >> 32)); |
| 2927 | ew32(TDLEN(0), tdlen); |
| 2928 | ew32(TDH(0), 0); |
| 2929 | ew32(TDT(0), 0); |
| 2930 | tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0); |
| 2931 | tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2932 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2933 | /* Set the Tx Interrupt Delay register */ |
| 2934 | ew32(TIDV, adapter->tx_int_delay); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2935 | /* Tx irq moderation */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2936 | ew32(TADV, adapter->tx_abs_int_delay); |
| 2937 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2938 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 2939 | u32 txdctl = er32(TXDCTL(0)); |
| 2940 | txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH | |
| 2941 | E1000_TXDCTL_WTHRESH); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2942 | /* set up some performance related parameters to encourage the |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2943 | * hardware to use the bus more efficiently in bursts, depends |
| 2944 | * on the tx_int_delay to be enabled, |
Hiroaki SHIMODA | 8edc0e6 | 2012-10-10 15:34:20 +0000 | [diff] [blame] | 2945 | * wthresh = 1 ==> burst write is disabled to avoid Tx stalls |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2946 | * hthresh = 1 ==> prefetch when one or more available |
| 2947 | * pthresh = 0x1f ==> prefetch if internal cache 31 or less |
| 2948 | * BEWARE: this seems to work but should be considered first if |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2949 | * there are Tx hangs or other Tx related bugs |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2950 | */ |
| 2951 | txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE; |
| 2952 | ew32(TXDCTL(0), txdctl); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2953 | } |
Bruce Allan | 56032be | 2011-12-16 00:46:01 +0000 | [diff] [blame] | 2954 | /* erratum work around: set txdctl the same for both queues */ |
| 2955 | ew32(TXDCTL(1), er32(TXDCTL(0))); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2956 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2957 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2958 | tarc = er32(TARC(0)); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2959 | /* 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] | 2960 | * gigabit link later |
| 2961 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2962 | #define SPEED_MODE_BIT (1 << 21) |
| 2963 | tarc |= SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2964 | ew32(TARC(0), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | /* errata: program both queues to unweighted RR */ |
| 2968 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2969 | tarc = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2970 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2971 | ew32(TARC(0), tarc); |
| 2972 | tarc = er32(TARC(1)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2973 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2974 | ew32(TARC(1), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2975 | } |
| 2976 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2977 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 2978 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 2979 | |
| 2980 | /* only set IDE if we are delaying interrupts using the timers */ |
| 2981 | if (adapter->tx_int_delay) |
| 2982 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
| 2983 | |
| 2984 | /* enable Report Status bit */ |
| 2985 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 2986 | |
Bruce Allan | 57cde76 | 2012-02-22 09:02:58 +0000 | [diff] [blame] | 2987 | hw->mac.ops.config_collision_dist(hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | /** |
| 2991 | * e1000_setup_rctl - configure the receive control registers |
| 2992 | * @adapter: Board private structure |
| 2993 | **/ |
| 2994 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 2995 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
| 2996 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
| 2997 | { |
| 2998 | struct e1000_hw *hw = &adapter->hw; |
| 2999 | u32 rctl, rfctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3000 | u32 pages = 0; |
| 3001 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 3002 | /* Workaround Si errata on PCHx - configure jumbo frame flow */ |
| 3003 | if (hw->mac.type >= e1000_pch2lan) { |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 3004 | s32 ret_val; |
| 3005 | |
| 3006 | if (adapter->netdev->mtu > ETH_DATA_LEN) |
| 3007 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true); |
| 3008 | else |
| 3009 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false); |
Bruce Allan | dd93f95 | 2011-01-06 14:29:48 +0000 | [diff] [blame] | 3010 | |
| 3011 | if (ret_val) |
| 3012 | e_dbg("failed to enable jumbo frame workaround mode\n"); |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 3013 | } |
| 3014 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3015 | /* Program MC offset vector base */ |
| 3016 | rctl = er32(RCTL); |
| 3017 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 3018 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 3019 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 3020 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 3021 | |
| 3022 | /* Do not Store bad packets */ |
| 3023 | rctl &= ~E1000_RCTL_SBP; |
| 3024 | |
| 3025 | /* Enable Long Packet receive */ |
| 3026 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 3027 | rctl &= ~E1000_RCTL_LPE; |
| 3028 | else |
| 3029 | rctl |= E1000_RCTL_LPE; |
| 3030 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 3031 | /* Some systems expect that the CRC is included in SMBUS traffic. The |
| 3032 | * hardware strips the CRC before sending to both SMBUS (BMC) and to |
| 3033 | * host memory when this is enabled |
| 3034 | */ |
| 3035 | if (adapter->flags2 & FLAG2_CRC_STRIPPING) |
| 3036 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 5918bd8 | 2008-02-12 15:20:24 -0800 | [diff] [blame] | 3037 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3038 | /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ |
| 3039 | if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { |
| 3040 | u16 phy_data; |
| 3041 | |
| 3042 | e1e_rphy(hw, PHY_REG(770, 26), &phy_data); |
| 3043 | phy_data &= 0xfff8; |
| 3044 | phy_data |= (1 << 2); |
| 3045 | e1e_wphy(hw, PHY_REG(770, 26), phy_data); |
| 3046 | |
| 3047 | e1e_rphy(hw, 22, &phy_data); |
| 3048 | phy_data &= 0x0fff; |
| 3049 | phy_data |= (1 << 14); |
| 3050 | e1e_wphy(hw, 0x10, 0x2823); |
| 3051 | e1e_wphy(hw, 0x11, 0x0003); |
| 3052 | e1e_wphy(hw, 22, phy_data); |
| 3053 | } |
| 3054 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3055 | /* Setup buffer sizes */ |
| 3056 | rctl &= ~E1000_RCTL_SZ_4096; |
| 3057 | rctl |= E1000_RCTL_BSEX; |
| 3058 | switch (adapter->rx_buffer_len) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3059 | case 2048: |
| 3060 | default: |
| 3061 | rctl |= E1000_RCTL_SZ_2048; |
| 3062 | rctl &= ~E1000_RCTL_BSEX; |
| 3063 | break; |
| 3064 | case 4096: |
| 3065 | rctl |= E1000_RCTL_SZ_4096; |
| 3066 | break; |
| 3067 | case 8192: |
| 3068 | rctl |= E1000_RCTL_SZ_8192; |
| 3069 | break; |
| 3070 | case 16384: |
| 3071 | rctl |= E1000_RCTL_SZ_16384; |
| 3072 | break; |
| 3073 | } |
| 3074 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3075 | /* Enable Extended Status in all Receive Descriptors */ |
| 3076 | rfctl = er32(RFCTL); |
| 3077 | rfctl |= E1000_RFCTL_EXTEN; |
Matthew Vick | f6bd557 | 2012-04-25 08:01:05 +0000 | [diff] [blame] | 3078 | ew32(RFCTL, rfctl); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3079 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3080 | /* 82571 and greater support packet-split where the protocol |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3081 | * header is placed in skb->data and the packet data is |
| 3082 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 3083 | * In the case of a non-split, skb->data is linearly filled, |
| 3084 | * followed by the page buffers. Therefore, skb->data is |
| 3085 | * sized to hold the largest protocol header. |
| 3086 | * |
| 3087 | * allocations using alloc_page take too long for regular MTU |
| 3088 | * so only enable packet split for jumbo frames |
| 3089 | * |
| 3090 | * Using pages when the page size is greater than 16k wastes |
| 3091 | * a lot of memory, since we allocate 3 pages at all times |
| 3092 | * per packet. |
| 3093 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3094 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3095 | if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3096 | adapter->rx_ps_pages = pages; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3097 | else |
| 3098 | adapter->rx_ps_pages = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3099 | |
| 3100 | if (adapter->rx_ps_pages) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 3101 | u32 psrctl = 0; |
| 3102 | |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 3103 | /* Enable Packet split descriptors */ |
| 3104 | rctl |= E1000_RCTL_DTYP_PS; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3105 | |
| 3106 | psrctl |= adapter->rx_ps_bsize0 >> |
| 3107 | E1000_PSRCTL_BSIZE0_SHIFT; |
| 3108 | |
| 3109 | switch (adapter->rx_ps_pages) { |
| 3110 | case 3: |
| 3111 | psrctl |= PAGE_SIZE << |
| 3112 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 3113 | case 2: |
| 3114 | psrctl |= PAGE_SIZE << |
| 3115 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 3116 | case 1: |
| 3117 | psrctl |= PAGE_SIZE >> |
| 3118 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 3119 | break; |
| 3120 | } |
| 3121 | |
| 3122 | ew32(PSRCTL, psrctl); |
| 3123 | } |
| 3124 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 3125 | /* This is useful for sniffing bad packets. */ |
| 3126 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 3127 | /* UPE and MPE will be handled by normal PROMISC logic |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3128 | * in e1000e_set_rx_mode |
| 3129 | */ |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 3130 | rctl |= (E1000_RCTL_SBP | /* Receive bad packets */ |
| 3131 | E1000_RCTL_BAM | /* RX All Bcast Pkts */ |
| 3132 | E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 3133 | |
| 3134 | rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */ |
| 3135 | E1000_RCTL_DPF | /* Allow filtered pause */ |
| 3136 | E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */ |
| 3137 | /* Do not mess with E1000_CTRL_VME, it affects transmit as well, |
| 3138 | * and that breaks VLANs. |
| 3139 | */ |
| 3140 | } |
| 3141 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3142 | ew32(RCTL, rctl); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3143 | /* just started the receive unit, no need to restart */ |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 3144 | adapter->flags &= ~FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | /** |
| 3148 | * e1000_configure_rx - Configure Receive Unit after Reset |
| 3149 | * @adapter: board private structure |
| 3150 | * |
| 3151 | * Configure the Rx unit of the MAC after a reset. |
| 3152 | **/ |
| 3153 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
| 3154 | { |
| 3155 | struct e1000_hw *hw = &adapter->hw; |
| 3156 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 3157 | u64 rdba; |
| 3158 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
| 3159 | |
| 3160 | if (adapter->rx_ps_pages) { |
| 3161 | /* this is a 32 byte descriptor */ |
| 3162 | rdlen = rx_ring->count * |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3163 | sizeof(union e1000_rx_desc_packet_split); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3164 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 3165 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3166 | } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3167 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3168 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 3169 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3170 | } else { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3171 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3172 | adapter->clean_rx = e1000_clean_rx_irq; |
| 3173 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 3174 | } |
| 3175 | |
| 3176 | /* disable receives while setting up the descriptors */ |
| 3177 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3178 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3179 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3180 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 3181 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3182 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3183 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3184 | /* set the writeback threshold (only takes effect if the RDTR |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3185 | * 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] | 3186 | * enable prefetching of 0x20 Rx descriptors |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3187 | * granularity = 01 |
| 3188 | * wthresh = 04, |
| 3189 | * hthresh = 04, |
| 3190 | * pthresh = 0x20 |
| 3191 | */ |
| 3192 | ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3193 | ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3194 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3195 | /* override the delay timers for enabling bursting, only if |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3196 | * the value was not set by the user via module options |
| 3197 | */ |
| 3198 | if (adapter->rx_int_delay == DEFAULT_RDTR) |
| 3199 | adapter->rx_int_delay = BURST_RDTR; |
| 3200 | if (adapter->rx_abs_int_delay == DEFAULT_RADV) |
| 3201 | adapter->rx_abs_int_delay = BURST_RADV; |
| 3202 | } |
| 3203 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3204 | /* set the Receive Delay Timer Register */ |
| 3205 | ew32(RDTR, adapter->rx_int_delay); |
| 3206 | |
| 3207 | /* irq moderation */ |
| 3208 | ew32(RADV, adapter->rx_abs_int_delay); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3209 | if ((adapter->itr_setting != 0) && (adapter->itr != 0)) |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 3210 | e1000e_write_itr(adapter, adapter->itr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3211 | |
| 3212 | ctrl_ext = er32(CTRL_EXT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3213 | /* Auto-Mask interrupts upon ICR access */ |
| 3214 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 3215 | ew32(IAM, 0xffffffff); |
| 3216 | ew32(CTRL_EXT, ctrl_ext); |
| 3217 | e1e_flush(); |
| 3218 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3219 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3220 | * the Base and Length of the Rx Descriptor Ring |
| 3221 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3222 | rdba = rx_ring->dma; |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 3223 | ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32))); |
| 3224 | ew32(RDBAH(0), (rdba >> 32)); |
| 3225 | ew32(RDLEN(0), rdlen); |
| 3226 | ew32(RDH(0), 0); |
| 3227 | ew32(RDT(0), 0); |
| 3228 | rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0); |
| 3229 | rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3230 | |
| 3231 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 3232 | rxcsum = er32(RXCSUM); |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 3233 | if (adapter->netdev->features & NETIF_F_RXCSUM) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3234 | rxcsum |= E1000_RXCSUM_TUOFL; |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 3235 | else |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3236 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3237 | ew32(RXCSUM, rxcsum); |
| 3238 | |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 3239 | /* With jumbo frames, excessive C-state transition latencies result |
| 3240 | * in dropped transactions. |
| 3241 | */ |
| 3242 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3243 | u32 lat = |
| 3244 | ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 - |
| 3245 | adapter->max_frame_size) * 8 / 1000; |
| 3246 | |
| 3247 | if (adapter->flags & FLAG_IS_ICH) { |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3248 | u32 rxdctl = er32(RXDCTL(0)); |
| 3249 | ew32(RXDCTL(0), rxdctl | 0x3); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3250 | } |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 3251 | |
| 3252 | pm_qos_update_request(&adapter->netdev->pm_qos_req, lat); |
| 3253 | } else { |
| 3254 | pm_qos_update_request(&adapter->netdev->pm_qos_req, |
| 3255 | PM_QOS_DEFAULT_VALUE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3256 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3257 | |
| 3258 | /* Enable Receives */ |
| 3259 | ew32(RCTL, rctl); |
| 3260 | } |
| 3261 | |
| 3262 | /** |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3263 | * e1000e_write_mc_addr_list - write multicast addresses to MTA |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3264 | * @netdev: network interface device structure |
| 3265 | * |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3266 | * Writes multicast address list to the MTA hash table. |
| 3267 | * Returns: -ENOMEM on failure |
| 3268 | * 0 on no addresses written |
| 3269 | * X on writing X addresses to MTA |
| 3270 | */ |
| 3271 | static int e1000e_write_mc_addr_list(struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3272 | { |
| 3273 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3274 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3275 | struct netdev_hw_addr *ha; |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3276 | u8 *mta_list; |
| 3277 | int i; |
| 3278 | |
| 3279 | if (netdev_mc_empty(netdev)) { |
| 3280 | /* nothing to program, so clear mc list */ |
| 3281 | hw->mac.ops.update_mc_addr_list(hw, NULL, 0); |
| 3282 | return 0; |
| 3283 | } |
| 3284 | |
| 3285 | mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC); |
| 3286 | if (!mta_list) |
| 3287 | return -ENOMEM; |
| 3288 | |
| 3289 | /* update_mc_addr_list expects a packed array of only addresses. */ |
| 3290 | i = 0; |
| 3291 | netdev_for_each_mc_addr(ha, netdev) |
| 3292 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
| 3293 | |
| 3294 | hw->mac.ops.update_mc_addr_list(hw, mta_list, i); |
| 3295 | kfree(mta_list); |
| 3296 | |
| 3297 | return netdev_mc_count(netdev); |
| 3298 | } |
| 3299 | |
| 3300 | /** |
| 3301 | * e1000e_write_uc_addr_list - write unicast addresses to RAR table |
| 3302 | * @netdev: network interface device structure |
| 3303 | * |
| 3304 | * Writes unicast address list to the RAR table. |
| 3305 | * Returns: -ENOMEM on failure/insufficient address space |
| 3306 | * 0 on no addresses written |
| 3307 | * X on writing X addresses to the RAR table |
| 3308 | **/ |
| 3309 | static int e1000e_write_uc_addr_list(struct net_device *netdev) |
| 3310 | { |
| 3311 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3312 | struct e1000_hw *hw = &adapter->hw; |
| 3313 | unsigned int rar_entries = hw->mac.rar_entry_count; |
| 3314 | int count = 0; |
| 3315 | |
| 3316 | /* save a rar entry for our hardware address */ |
| 3317 | rar_entries--; |
| 3318 | |
| 3319 | /* save a rar entry for the LAA workaround */ |
| 3320 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) |
| 3321 | rar_entries--; |
| 3322 | |
| 3323 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3324 | if (netdev_uc_count(netdev) > rar_entries) |
| 3325 | return -ENOMEM; |
| 3326 | |
| 3327 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3328 | struct netdev_hw_addr *ha; |
| 3329 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3330 | /* write the addresses in reverse order to avoid write |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3331 | * combining |
| 3332 | */ |
| 3333 | netdev_for_each_uc_addr(ha, netdev) { |
| 3334 | if (!rar_entries) |
| 3335 | break; |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 3336 | hw->mac.ops.rar_set(hw, ha->addr, rar_entries--); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3337 | count++; |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | /* zero out the remaining RAR entries not used above */ |
| 3342 | for (; rar_entries > 0; rar_entries--) { |
| 3343 | ew32(RAH(rar_entries), 0); |
| 3344 | ew32(RAL(rar_entries), 0); |
| 3345 | } |
| 3346 | e1e_flush(); |
| 3347 | |
| 3348 | return count; |
| 3349 | } |
| 3350 | |
| 3351 | /** |
| 3352 | * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set |
| 3353 | * @netdev: network interface device structure |
| 3354 | * |
| 3355 | * The ndo_set_rx_mode entry point is called whenever the unicast or multicast |
| 3356 | * address list or the network interface flags are updated. This routine is |
| 3357 | * responsible for configuring the hardware for proper unicast, multicast, |
| 3358 | * promiscuous mode, and all-multi behavior. |
| 3359 | **/ |
| 3360 | static void e1000e_set_rx_mode(struct net_device *netdev) |
| 3361 | { |
| 3362 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3363 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3364 | u32 rctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3365 | |
| 3366 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3367 | rctl = er32(RCTL); |
| 3368 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3369 | /* clear the affected bits */ |
| 3370 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 3371 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3372 | if (netdev->flags & IFF_PROMISC) { |
| 3373 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3374 | /* Do not hardware filter VLANs in promisc mode */ |
| 3375 | e1000e_vlan_filter_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3376 | } else { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3377 | int count; |
Bruce Allan | 3d3a167 | 2012-02-23 03:13:18 +0000 | [diff] [blame] | 3378 | |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3379 | if (netdev->flags & IFF_ALLMULTI) { |
| 3380 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3381 | } else { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3382 | /* Write addresses to the MTA, if the attempt fails |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3383 | * then we should just turn on promiscuous mode so |
| 3384 | * that we can at least receive multicast traffic |
| 3385 | */ |
| 3386 | count = e1000e_write_mc_addr_list(netdev); |
| 3387 | if (count < 0) |
| 3388 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3389 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3390 | e1000e_vlan_filter_enable(adapter); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3391 | /* Write addresses to available RAR registers, if there is not |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3392 | * sufficient space to store all the addresses then enable |
| 3393 | * unicast promiscuous mode |
| 3394 | */ |
| 3395 | count = e1000e_write_uc_addr_list(netdev); |
| 3396 | if (count < 0) |
| 3397 | rctl |= E1000_RCTL_UPE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | ew32(RCTL, rctl); |
| 3401 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3402 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3403 | e1000e_vlan_strip_enable(adapter); |
| 3404 | else |
| 3405 | e1000e_vlan_strip_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3406 | } |
| 3407 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3408 | static void e1000e_setup_rss_hash(struct e1000_adapter *adapter) |
| 3409 | { |
| 3410 | struct e1000_hw *hw = &adapter->hw; |
| 3411 | u32 mrqc, rxcsum; |
| 3412 | int i; |
| 3413 | static const u32 rsskey[10] = { |
| 3414 | 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0, |
| 3415 | 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe |
| 3416 | }; |
| 3417 | |
| 3418 | /* Fill out hash function seed */ |
| 3419 | for (i = 0; i < 10; i++) |
| 3420 | ew32(RSSRK(i), rsskey[i]); |
| 3421 | |
| 3422 | /* Direct all traffic to queue 0 */ |
| 3423 | for (i = 0; i < 32; i++) |
| 3424 | ew32(RETA(i), 0); |
| 3425 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3426 | /* Disable raw packet checksumming so that RSS hash is placed in |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3427 | * descriptor on writeback. |
| 3428 | */ |
| 3429 | rxcsum = er32(RXCSUM); |
| 3430 | rxcsum |= E1000_RXCSUM_PCSD; |
| 3431 | |
| 3432 | ew32(RXCSUM, rxcsum); |
| 3433 | |
| 3434 | mrqc = (E1000_MRQC_RSS_FIELD_IPV4 | |
| 3435 | E1000_MRQC_RSS_FIELD_IPV4_TCP | |
| 3436 | E1000_MRQC_RSS_FIELD_IPV6 | |
| 3437 | E1000_MRQC_RSS_FIELD_IPV6_TCP | |
| 3438 | E1000_MRQC_RSS_FIELD_IPV6_TCP_EX); |
| 3439 | |
| 3440 | ew32(MRQC, mrqc); |
| 3441 | } |
| 3442 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3443 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3444 | * e1000e_get_base_timinca - get default SYSTIM time increment attributes |
| 3445 | * @adapter: board private structure |
| 3446 | * @timinca: pointer to returned time increment attributes |
| 3447 | * |
| 3448 | * Get attributes for incrementing the System Time Register SYSTIML/H at |
| 3449 | * the default base frequency, and set the cyclecounter shift value. |
| 3450 | **/ |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3451 | s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca) |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3452 | { |
| 3453 | struct e1000_hw *hw = &adapter->hw; |
| 3454 | u32 incvalue, incperiod, shift; |
| 3455 | |
| 3456 | /* Make sure clock is enabled on I217 before checking the frequency */ |
| 3457 | if ((hw->mac.type == e1000_pch_lpt) && |
| 3458 | !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) && |
| 3459 | !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) { |
| 3460 | u32 fextnvm7 = er32(FEXTNVM7); |
| 3461 | |
| 3462 | if (!(fextnvm7 & (1 << 0))) { |
| 3463 | ew32(FEXTNVM7, fextnvm7 | (1 << 0)); |
| 3464 | e1e_flush(); |
| 3465 | } |
| 3466 | } |
| 3467 | |
| 3468 | switch (hw->mac.type) { |
| 3469 | case e1000_pch2lan: |
| 3470 | case e1000_pch_lpt: |
| 3471 | /* On I217, the clock frequency is 25MHz or 96MHz as |
| 3472 | * indicated by the System Clock Frequency Indication |
| 3473 | */ |
| 3474 | if ((hw->mac.type != e1000_pch_lpt) || |
| 3475 | (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) { |
| 3476 | /* Stable 96MHz frequency */ |
| 3477 | incperiod = INCPERIOD_96MHz; |
| 3478 | incvalue = INCVALUE_96MHz; |
| 3479 | shift = INCVALUE_SHIFT_96MHz; |
| 3480 | adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz; |
| 3481 | break; |
| 3482 | } |
| 3483 | /* fall-through */ |
| 3484 | case e1000_82574: |
| 3485 | case e1000_82583: |
| 3486 | /* Stable 25MHz frequency */ |
| 3487 | incperiod = INCPERIOD_25MHz; |
| 3488 | incvalue = INCVALUE_25MHz; |
| 3489 | shift = INCVALUE_SHIFT_25MHz; |
| 3490 | adapter->cc.shift = shift; |
| 3491 | break; |
| 3492 | default: |
| 3493 | return -EINVAL; |
| 3494 | } |
| 3495 | |
| 3496 | *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) | |
| 3497 | ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK)); |
| 3498 | |
| 3499 | return 0; |
| 3500 | } |
| 3501 | |
| 3502 | /** |
| 3503 | * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable |
| 3504 | * @adapter: board private structure |
| 3505 | * |
| 3506 | * Outgoing time stamping can be enabled and disabled. Play nice and |
| 3507 | * disable it when requested, although it shouldn't cause any overhead |
| 3508 | * when no packet needs it. At most one packet in the queue may be |
| 3509 | * marked for time stamping, otherwise it would be impossible to tell |
| 3510 | * for sure to which packet the hardware time stamp belongs. |
| 3511 | * |
| 3512 | * Incoming time stamping has to be configured via the hardware filters. |
| 3513 | * Not all combinations are supported, in particular event type has to be |
| 3514 | * specified. Matching the kind of event packet is not supported, with the |
| 3515 | * exception of "all V2 events regardless of level 2 or 4". |
| 3516 | **/ |
| 3517 | static int e1000e_config_hwtstamp(struct e1000_adapter *adapter) |
| 3518 | { |
| 3519 | struct e1000_hw *hw = &adapter->hw; |
| 3520 | struct hwtstamp_config *config = &adapter->hwtstamp_config; |
| 3521 | u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED; |
| 3522 | u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3523 | u32 rxmtrl = 0; |
| 3524 | u16 rxudp = 0; |
| 3525 | bool is_l4 = false; |
| 3526 | bool is_l2 = false; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3527 | u32 regval; |
| 3528 | s32 ret_val; |
| 3529 | |
| 3530 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) |
| 3531 | return -EINVAL; |
| 3532 | |
| 3533 | /* flags reserved for future extensions - must be zero */ |
| 3534 | if (config->flags) |
| 3535 | return -EINVAL; |
| 3536 | |
| 3537 | switch (config->tx_type) { |
| 3538 | case HWTSTAMP_TX_OFF: |
| 3539 | tsync_tx_ctl = 0; |
| 3540 | break; |
| 3541 | case HWTSTAMP_TX_ON: |
| 3542 | break; |
| 3543 | default: |
| 3544 | return -ERANGE; |
| 3545 | } |
| 3546 | |
| 3547 | switch (config->rx_filter) { |
| 3548 | case HWTSTAMP_FILTER_NONE: |
| 3549 | tsync_rx_ctl = 0; |
| 3550 | break; |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3551 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 3552 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
| 3553 | rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE; |
| 3554 | is_l4 = true; |
| 3555 | break; |
| 3556 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 3557 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
| 3558 | rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE; |
| 3559 | is_l4 = true; |
| 3560 | break; |
| 3561 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 3562 | /* Also time stamps V2 L2 Path Delay Request/Response */ |
| 3563 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2; |
| 3564 | rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE; |
| 3565 | is_l2 = true; |
| 3566 | break; |
| 3567 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 3568 | /* Also time stamps V2 L2 Path Delay Request/Response. */ |
| 3569 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2; |
| 3570 | rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE; |
| 3571 | is_l2 = true; |
| 3572 | break; |
| 3573 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 3574 | /* Hardware cannot filter just V2 L4 Sync messages; |
| 3575 | * fall-through to V2 (both L2 and L4) Sync. |
| 3576 | */ |
| 3577 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 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_SYNC_MESSAGE; |
| 3581 | is_l2 = true; |
| 3582 | is_l4 = true; |
| 3583 | break; |
| 3584 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 3585 | /* Hardware cannot filter just V2 L4 Delay Request messages; |
| 3586 | * fall-through to V2 (both L2 and L4) Delay Request. |
| 3587 | */ |
| 3588 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 3589 | /* Also time stamps V2 Path Delay Request/Response. */ |
| 3590 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
| 3591 | rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE; |
| 3592 | is_l2 = true; |
| 3593 | is_l4 = true; |
| 3594 | break; |
| 3595 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 3596 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 3597 | /* Hardware cannot filter just V2 L4 or L2 Event messages; |
| 3598 | * fall-through to all V2 (both L2 and L4) Events. |
| 3599 | */ |
| 3600 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 3601 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2; |
| 3602 | config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
| 3603 | is_l2 = true; |
| 3604 | is_l4 = true; |
| 3605 | break; |
| 3606 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 3607 | /* For V1, the hardware can only filter Sync messages or |
| 3608 | * Delay Request messages but not both so fall-through to |
| 3609 | * time stamp all packets. |
| 3610 | */ |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3611 | case HWTSTAMP_FILTER_ALL: |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3612 | is_l2 = true; |
| 3613 | is_l4 = true; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3614 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; |
| 3615 | config->rx_filter = HWTSTAMP_FILTER_ALL; |
| 3616 | break; |
| 3617 | default: |
| 3618 | return -ERANGE; |
| 3619 | } |
| 3620 | |
| 3621 | /* enable/disable Tx h/w time stamping */ |
| 3622 | regval = er32(TSYNCTXCTL); |
| 3623 | regval &= ~E1000_TSYNCTXCTL_ENABLED; |
| 3624 | regval |= tsync_tx_ctl; |
| 3625 | ew32(TSYNCTXCTL, regval); |
| 3626 | if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) != |
| 3627 | (regval & E1000_TSYNCTXCTL_ENABLED)) { |
| 3628 | e_err("Timesync Tx Control register not set as expected\n"); |
| 3629 | return -EAGAIN; |
| 3630 | } |
| 3631 | |
| 3632 | /* enable/disable Rx h/w time stamping */ |
| 3633 | regval = er32(TSYNCRXCTL); |
| 3634 | regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK); |
| 3635 | regval |= tsync_rx_ctl; |
| 3636 | ew32(TSYNCRXCTL, regval); |
| 3637 | if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED | |
| 3638 | E1000_TSYNCRXCTL_TYPE_MASK)) != |
| 3639 | (regval & (E1000_TSYNCRXCTL_ENABLED | |
| 3640 | E1000_TSYNCRXCTL_TYPE_MASK))) { |
| 3641 | e_err("Timesync Rx Control register not set as expected\n"); |
| 3642 | return -EAGAIN; |
| 3643 | } |
| 3644 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3645 | /* L2: define ethertype filter for time stamped packets */ |
| 3646 | if (is_l2) |
| 3647 | rxmtrl |= ETH_P_1588; |
| 3648 | |
| 3649 | /* define which PTP packets get time stamped */ |
| 3650 | ew32(RXMTRL, rxmtrl); |
| 3651 | |
| 3652 | /* Filter by destination port */ |
| 3653 | if (is_l4) { |
| 3654 | rxudp = PTP_EV_PORT; |
| 3655 | cpu_to_be16s(&rxudp); |
| 3656 | } |
| 3657 | ew32(RXUDP, rxudp); |
| 3658 | |
| 3659 | e1e_flush(); |
| 3660 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3661 | /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */ |
Bruce Allan | 70806a7 | 2013-01-05 05:08:37 +0000 | [diff] [blame] | 3662 | er32(RXSTMPH); |
| 3663 | er32(TXSTMPH); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3664 | |
| 3665 | /* Get and set the System Time Register SYSTIM base frequency */ |
| 3666 | ret_val = e1000e_get_base_timinca(adapter, ®val); |
| 3667 | if (ret_val) |
| 3668 | return ret_val; |
| 3669 | ew32(TIMINCA, regval); |
| 3670 | |
| 3671 | /* reset the ns time counter */ |
| 3672 | timecounter_init(&adapter->tc, &adapter->cc, |
| 3673 | ktime_to_ns(ktime_get_real())); |
| 3674 | |
| 3675 | return 0; |
| 3676 | } |
| 3677 | |
| 3678 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3679 | * e1000_configure - configure the hardware for Rx and Tx |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3680 | * @adapter: private board structure |
| 3681 | **/ |
| 3682 | static void e1000_configure(struct e1000_adapter *adapter) |
| 3683 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3684 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 3685 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3686 | e1000e_set_rx_mode(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3687 | |
| 3688 | e1000_restore_vlan(adapter); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 3689 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3690 | |
| 3691 | e1000_configure_tx(adapter); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3692 | |
| 3693 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 3694 | e1000e_setup_rss_hash(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3695 | e1000_setup_rctl(adapter); |
| 3696 | e1000_configure_rx(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3697 | 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] | 3698 | } |
| 3699 | |
| 3700 | /** |
| 3701 | * e1000e_power_up_phy - restore link in case the phy was powered down |
| 3702 | * @adapter: address of board private structure |
| 3703 | * |
| 3704 | * The phy may be powered down to save power and turn off link when the |
| 3705 | * driver is unloaded and wake on lan is not enabled (among others) |
| 3706 | * *** this routine MUST be followed by a call to e1000e_reset *** |
| 3707 | **/ |
| 3708 | void e1000e_power_up_phy(struct e1000_adapter *adapter) |
| 3709 | { |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3710 | if (adapter->hw.phy.ops.power_up) |
| 3711 | adapter->hw.phy.ops.power_up(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3712 | |
| 3713 | adapter->hw.mac.ops.setup_link(&adapter->hw); |
| 3714 | } |
| 3715 | |
| 3716 | /** |
| 3717 | * e1000_power_down_phy - Power down the PHY |
| 3718 | * |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3719 | * Power down the PHY so no link is implied when interface is down. |
| 3720 | * The PHY cannot be powered down if management or WoL is active. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3721 | */ |
| 3722 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 3723 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3724 | /* WoL is enabled */ |
Auke Kok | 23b66e2 | 2008-02-11 09:25:51 -0800 | [diff] [blame] | 3725 | if (adapter->wol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3726 | return; |
| 3727 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3728 | if (adapter->hw.phy.ops.power_down) |
| 3729 | adapter->hw.phy.ops.power_down(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | /** |
| 3733 | * e1000e_reset - bring the hardware into a known good state |
| 3734 | * |
| 3735 | * This function boots the hardware and enables some settings that |
| 3736 | * require a configuration cycle of the hardware - those cannot be |
| 3737 | * set/changed during runtime. After reset the device needs to be |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3738 | * properly configured for Rx, Tx etc. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3739 | */ |
| 3740 | void e1000e_reset(struct e1000_adapter *adapter) |
| 3741 | { |
| 3742 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3743 | struct e1000_fc_info *fc = &adapter->hw.fc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3744 | struct e1000_hw *hw = &adapter->hw; |
| 3745 | u32 tx_space, min_tx_space, min_rx_space; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3746 | u32 pba = adapter->pba; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3747 | u16 hwm; |
| 3748 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3749 | /* reset Packet Buffer Allocation to default */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3750 | ew32(PBA, pba); |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3751 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3752 | if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3753 | /* To maintain wire speed transmits, the Tx FIFO should be |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3754 | * large enough to accommodate two full transmit packets, |
| 3755 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 3756 | * the Rx FIFO should be large enough to accommodate at least |
| 3757 | * one full receive packet and is similarly rounded up and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3758 | * expressed in KB. |
| 3759 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3760 | pba = er32(PBA); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3761 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3762 | tx_space = pba >> 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3763 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3764 | pba &= 0xffff; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3765 | /* the Tx fifo also stores 16 bytes of information about the Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3766 | * but don't include ethernet FCS because hardware appends it |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3767 | */ |
| 3768 | min_tx_space = (adapter->max_frame_size + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3769 | sizeof(struct e1000_tx_desc) - |
| 3770 | ETH_FCS_LEN) * 2; |
| 3771 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 3772 | min_tx_space >>= 10; |
| 3773 | /* software strips receive CRC, so leave room for it */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3774 | min_rx_space = adapter->max_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3775 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 3776 | min_rx_space >>= 10; |
| 3777 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3778 | /* If current Tx allocation is less than the min Tx FIFO size, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3779 | * 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] | 3780 | * allocation, take space away from current Rx allocation |
| 3781 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3782 | if ((tx_space < min_tx_space) && |
| 3783 | ((min_tx_space - tx_space) < pba)) { |
| 3784 | pba -= min_tx_space - tx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3785 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3786 | /* if short on Rx space, Rx wins and must trump Tx |
Bruce Allan | 419e551 | 2012-08-17 06:18:02 +0000 | [diff] [blame] | 3787 | * adjustment |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3788 | */ |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3789 | if (pba < min_rx_space) |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3790 | pba = min_rx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3791 | } |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3792 | |
| 3793 | ew32(PBA, pba); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3794 | } |
| 3795 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3796 | /* flow control settings |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3797 | * |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3798 | * 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] | 3799 | * (or the size used for early receive) above it in the Rx FIFO. |
| 3800 | * Set it to the lower of: |
| 3801 | * - 90% of the Rx FIFO size, and |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3802 | * - the full Rx FIFO size minus one full frame |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3803 | */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3804 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
| 3805 | fc->pause_time = 0xFFFF; |
| 3806 | else |
| 3807 | fc->pause_time = E1000_FC_PAUSE_TIME; |
Bruce Allan | b20caa8 | 2012-02-22 09:03:03 +0000 | [diff] [blame] | 3808 | fc->send_xon = true; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3809 | fc->current_mode = fc->requested_mode; |
| 3810 | |
| 3811 | switch (hw->mac.type) { |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3812 | case e1000_ich9lan: |
| 3813 | case e1000_ich10lan: |
| 3814 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3815 | pba = 14; |
| 3816 | ew32(PBA, pba); |
| 3817 | fc->high_water = 0x2800; |
| 3818 | fc->low_water = fc->high_water - 8; |
| 3819 | break; |
| 3820 | } |
| 3821 | /* fall-through */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3822 | default: |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3823 | hwm = min(((pba << 10) * 9 / 10), |
| 3824 | ((pba << 10) - adapter->max_frame_size)); |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3825 | |
| 3826 | fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ |
| 3827 | fc->low_water = fc->high_water - 8; |
| 3828 | break; |
| 3829 | case e1000_pchlan: |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3830 | /* Workaround PCH LOM adapter hangs with certain network |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3831 | * loads. If hangs persist, try disabling Tx flow control. |
| 3832 | */ |
| 3833 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3834 | fc->high_water = 0x3500; |
| 3835 | fc->low_water = 0x1500; |
| 3836 | } else { |
| 3837 | fc->high_water = 0x5000; |
| 3838 | fc->low_water = 0x3000; |
| 3839 | } |
Bruce Allan | a305595 | 2010-05-10 15:02:12 +0000 | [diff] [blame] | 3840 | fc->refresh_time = 0x1000; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3841 | break; |
| 3842 | case e1000_pch2lan: |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 3843 | case e1000_pch_lpt: |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3844 | fc->refresh_time = 0x0400; |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 3845 | |
| 3846 | if (adapter->netdev->mtu <= ETH_DATA_LEN) { |
| 3847 | fc->high_water = 0x05C20; |
| 3848 | fc->low_water = 0x05048; |
| 3849 | fc->pause_time = 0x0650; |
| 3850 | break; |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3851 | } |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 3852 | |
| 3853 | fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH; |
| 3854 | fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 3855 | break; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 3856 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3857 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3858 | /* Alignment of Tx data is on an arbitrary byte boundary with the |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 3859 | * maximum size per Tx descriptor limited only to the transmit |
| 3860 | * allocation of the packet buffer minus 96 bytes with an upper |
| 3861 | * limit of 24KB due to receive synchronization limitations. |
| 3862 | */ |
| 3863 | adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96, |
| 3864 | 24 << 10); |
| 3865 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3866 | /* Disable Adaptive Interrupt Moderation if 2 full packets cannot |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3867 | * fit in receive buffer. |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3868 | */ |
| 3869 | if (adapter->itr_setting & 0x3) { |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3870 | if ((adapter->max_frame_size * 2) > (pba << 10)) { |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3871 | if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) { |
| 3872 | dev_info(&adapter->pdev->dev, |
| 3873 | "Interrupt Throttle Rate turned off\n"); |
| 3874 | adapter->flags2 |= FLAG2_DISABLE_AIM; |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 3875 | e1000e_write_itr(adapter, 0); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3876 | } |
| 3877 | } else if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 3878 | dev_info(&adapter->pdev->dev, |
| 3879 | "Interrupt Throttle Rate turned on\n"); |
| 3880 | adapter->flags2 &= ~FLAG2_DISABLE_AIM; |
| 3881 | adapter->itr = 20000; |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 3882 | e1000e_write_itr(adapter, adapter->itr); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3883 | } |
| 3884 | } |
| 3885 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3886 | /* Allow time for pending master requests to run */ |
| 3887 | mac->ops.reset_hw(hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3888 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3889 | /* For parts with AMT enabled, let the firmware know |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3890 | * that the network interface is in control |
| 3891 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 3892 | if (adapter->flags & FLAG_HAS_AMT) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3893 | e1000e_get_hw_control(adapter); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3894 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3895 | ew32(WUC, 0); |
| 3896 | |
| 3897 | if (mac->ops.init_hw(hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 3898 | e_err("Hardware Error\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3899 | |
| 3900 | e1000_update_mng_vlan(adapter); |
| 3901 | |
| 3902 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 3903 | ew32(VET, ETH_P_8021Q); |
| 3904 | |
| 3905 | e1000e_reset_adaptive(hw); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3906 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3907 | /* initialize systim and reset the ns time counter */ |
| 3908 | e1000e_config_hwtstamp(adapter); |
| 3909 | |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 3910 | if (!netif_running(adapter->netdev) && |
| 3911 | !test_bit(__E1000_TESTING, &adapter->state)) { |
| 3912 | e1000_power_down_phy(adapter); |
| 3913 | return; |
| 3914 | } |
| 3915 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3916 | e1000_get_phy_info(hw); |
| 3917 | |
Bruce Allan | 918d719 | 2009-06-02 11:28:20 +0000 | [diff] [blame] | 3918 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && |
| 3919 | !(adapter->flags & FLAG_SMART_POWER_DOWN)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3920 | u16 phy_data = 0; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3921 | /* speed up time to link by disabling smart power down, ignore |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3922 | * the return value of this function because there is nothing |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3923 | * different we would do if it failed |
| 3924 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3925 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
| 3926 | phy_data &= ~IGP02E1000_PM_SPD; |
| 3927 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 3928 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | int e1000e_up(struct e1000_adapter *adapter) |
| 3932 | { |
| 3933 | struct e1000_hw *hw = &adapter->hw; |
| 3934 | |
| 3935 | /* hardware has been reset, we need to reload some things */ |
| 3936 | e1000_configure(adapter); |
| 3937 | |
| 3938 | clear_bit(__E1000_DOWN, &adapter->state); |
| 3939 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 3940 | if (adapter->msix_entries) |
| 3941 | e1000_configure_msix(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3942 | e1000_irq_enable(adapter); |
| 3943 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 3944 | netif_start_queue(adapter->netdev); |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3945 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3946 | /* fire a link change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 3947 | if (adapter->msix_entries) |
| 3948 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 3949 | else |
| 3950 | ew32(ICS, E1000_ICS_LSC); |
| 3951 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3952 | return 0; |
| 3953 | } |
| 3954 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3955 | static void e1000e_flush_descriptors(struct e1000_adapter *adapter) |
| 3956 | { |
| 3957 | struct e1000_hw *hw = &adapter->hw; |
| 3958 | |
| 3959 | if (!(adapter->flags2 & FLAG2_DMA_BURST)) |
| 3960 | return; |
| 3961 | |
| 3962 | /* flush pending descriptor writebacks to memory */ |
| 3963 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 3964 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 3965 | |
| 3966 | /* execute the writes immediately */ |
| 3967 | e1e_flush(); |
Matthew Vick | bf03085 | 2012-03-16 09:03:00 +0000 | [diff] [blame] | 3968 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3969 | /* 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] | 3970 | * write is successful |
| 3971 | */ |
| 3972 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 3973 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 3974 | |
| 3975 | /* execute the writes immediately */ |
| 3976 | e1e_flush(); |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 3977 | } |
| 3978 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 3979 | static void e1000e_update_stats(struct e1000_adapter *adapter); |
| 3980 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3981 | void e1000e_down(struct e1000_adapter *adapter) |
| 3982 | { |
| 3983 | struct net_device *netdev = adapter->netdev; |
| 3984 | struct e1000_hw *hw = &adapter->hw; |
| 3985 | u32 tctl, rctl; |
| 3986 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3987 | /* signal that we're down so the interrupt handler does not |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3988 | * reschedule our watchdog timer |
| 3989 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3990 | set_bit(__E1000_DOWN, &adapter->state); |
| 3991 | |
| 3992 | /* disable receives in the hardware */ |
| 3993 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3994 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3995 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3996 | /* flush and sleep below */ |
| 3997 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 3998 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3999 | |
| 4000 | /* disable transmits in the hardware */ |
| 4001 | tctl = er32(TCTL); |
| 4002 | tctl &= ~E1000_TCTL_EN; |
| 4003 | ew32(TCTL, tctl); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 4004 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4005 | /* flush both disables and wait for them to finish */ |
| 4006 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 4007 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4008 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4009 | e1000_irq_disable(adapter); |
| 4010 | |
| 4011 | del_timer_sync(&adapter->watchdog_timer); |
| 4012 | del_timer_sync(&adapter->phy_info_timer); |
| 4013 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4014 | netif_carrier_off(netdev); |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4015 | |
| 4016 | spin_lock(&adapter->stats64_lock); |
| 4017 | e1000e_update_stats(adapter); |
| 4018 | spin_unlock(&adapter->stats64_lock); |
| 4019 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 4020 | e1000e_flush_descriptors(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4021 | e1000_clean_tx_ring(adapter->tx_ring); |
| 4022 | e1000_clean_rx_ring(adapter->rx_ring); |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 4023 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4024 | adapter->link_speed = 0; |
| 4025 | adapter->link_duplex = 0; |
| 4026 | |
Jeff Kirsher | 52cc308 | 2008-06-24 17:01:29 -0700 | [diff] [blame] | 4027 | if (!pci_channel_offline(adapter->pdev)) |
| 4028 | e1000e_reset(adapter); |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4029 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4030 | /* TODO: for power management, we could drop the link and |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4031 | * pci_disable_device here. |
| 4032 | */ |
| 4033 | } |
| 4034 | |
| 4035 | void e1000e_reinit_locked(struct e1000_adapter *adapter) |
| 4036 | { |
| 4037 | might_sleep(); |
| 4038 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 4039 | usleep_range(1000, 2000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4040 | e1000e_down(adapter); |
| 4041 | e1000e_up(adapter); |
| 4042 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 4043 | } |
| 4044 | |
| 4045 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4046 | * e1000e_cyclecounter_read - read raw cycle counter (used by time counter) |
| 4047 | * @cc: cyclecounter structure |
| 4048 | **/ |
| 4049 | static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc) |
| 4050 | { |
| 4051 | struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter, |
| 4052 | cc); |
| 4053 | struct e1000_hw *hw = &adapter->hw; |
| 4054 | cycle_t systim; |
| 4055 | |
| 4056 | /* latch SYSTIMH on read of SYSTIML */ |
| 4057 | systim = (cycle_t)er32(SYSTIML); |
| 4058 | systim |= (cycle_t)er32(SYSTIMH) << 32; |
| 4059 | |
| 4060 | return systim; |
| 4061 | } |
| 4062 | |
| 4063 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4064 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 4065 | * @adapter: board private structure to initialize |
| 4066 | * |
| 4067 | * e1000_sw_init initializes the Adapter private data structure. |
| 4068 | * Fields are initialized based on PCI device information and |
| 4069 | * OS network device settings (MTU size). |
| 4070 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 4071 | static int e1000_sw_init(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4072 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4073 | struct net_device *netdev = adapter->netdev; |
| 4074 | |
| 4075 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN; |
| 4076 | adapter->rx_ps_bsize0 = 128; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4077 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4078 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4079 | adapter->tx_ring_count = E1000_DEFAULT_TXD; |
| 4080 | adapter->rx_ring_count = E1000_DEFAULT_RXD; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4081 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4082 | spin_lock_init(&adapter->stats64_lock); |
| 4083 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4084 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4085 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4086 | if (e1000_alloc_queues(adapter)) |
| 4087 | return -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4088 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4089 | /* Setup hardware time stamping cyclecounter */ |
| 4090 | if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) { |
| 4091 | adapter->cc.read = e1000e_cyclecounter_read; |
| 4092 | adapter->cc.mask = CLOCKSOURCE_MASK(64); |
| 4093 | adapter->cc.mult = 1; |
| 4094 | /* cc.shift set in e1000e_get_base_tininca() */ |
| 4095 | |
| 4096 | spin_lock_init(&adapter->systim_lock); |
| 4097 | INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work); |
| 4098 | } |
| 4099 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4100 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4101 | e1000_irq_disable(adapter); |
| 4102 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4103 | set_bit(__E1000_DOWN, &adapter->state); |
| 4104 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4105 | } |
| 4106 | |
| 4107 | /** |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4108 | * e1000_intr_msi_test - Interrupt Handler |
| 4109 | * @irq: interrupt number |
| 4110 | * @data: pointer to a network interface device structure |
| 4111 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 4112 | 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] | 4113 | { |
| 4114 | struct net_device *netdev = data; |
| 4115 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4116 | struct e1000_hw *hw = &adapter->hw; |
| 4117 | u32 icr = er32(ICR); |
| 4118 | |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 4119 | e_dbg("icr is %08X\n", icr); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4120 | if (icr & E1000_ICR_RXSEQ) { |
| 4121 | adapter->flags &= ~FLAG_MSI_TEST_FAILED; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4122 | /* Force memory writes to complete before acknowledging the |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4123 | * interrupt is handled. |
| 4124 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4125 | wmb(); |
| 4126 | } |
| 4127 | |
| 4128 | return IRQ_HANDLED; |
| 4129 | } |
| 4130 | |
| 4131 | /** |
| 4132 | * e1000_test_msi_interrupt - Returns 0 for successful test |
| 4133 | * @adapter: board private struct |
| 4134 | * |
| 4135 | * code flow taken from tg3.c |
| 4136 | **/ |
| 4137 | static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) |
| 4138 | { |
| 4139 | struct net_device *netdev = adapter->netdev; |
| 4140 | struct e1000_hw *hw = &adapter->hw; |
| 4141 | int err; |
| 4142 | |
| 4143 | /* poll_enable hasn't been called yet, so don't need disable */ |
| 4144 | /* clear any pending events */ |
| 4145 | er32(ICR); |
| 4146 | |
| 4147 | /* free the real vector and request a test handler */ |
| 4148 | e1000_free_irq(adapter); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4149 | e1000e_reset_interrupt_capability(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4150 | |
| 4151 | /* Assume that the test fails, if it succeeds then the test |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4152 | * MSI irq handler will unset this flag |
| 4153 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4154 | adapter->flags |= FLAG_MSI_TEST_FAILED; |
| 4155 | |
| 4156 | err = pci_enable_msi(adapter->pdev); |
| 4157 | if (err) |
| 4158 | goto msi_test_failed; |
| 4159 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 4160 | err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4161 | netdev->name, netdev); |
| 4162 | if (err) { |
| 4163 | pci_disable_msi(adapter->pdev); |
| 4164 | goto msi_test_failed; |
| 4165 | } |
| 4166 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4167 | /* Force memory writes to complete before enabling and firing an |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4168 | * interrupt. |
| 4169 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4170 | wmb(); |
| 4171 | |
| 4172 | e1000_irq_enable(adapter); |
| 4173 | |
| 4174 | /* fire an unusual interrupt on the test handler */ |
| 4175 | ew32(ICS, E1000_ICS_RXSEQ); |
| 4176 | e1e_flush(); |
Prasanna S Panchamukhi | 569a3af | 2012-04-19 17:01:00 +0000 | [diff] [blame] | 4177 | msleep(100); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4178 | |
| 4179 | e1000_irq_disable(adapter); |
| 4180 | |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4181 | rmb(); /* read flags after interrupt has been fired */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4182 | |
| 4183 | if (adapter->flags & FLAG_MSI_TEST_FAILED) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4184 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4185 | e_info("MSI interrupt test failed, using legacy interrupt.\n"); |
Bruce Allan | 24b706b | 2012-01-31 06:37:22 +0000 | [diff] [blame] | 4186 | } else { |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4187 | e_dbg("MSI interrupt test succeeded!\n"); |
Bruce Allan | 24b706b | 2012-01-31 06:37:22 +0000 | [diff] [blame] | 4188 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4189 | |
| 4190 | free_irq(adapter->pdev->irq, netdev); |
| 4191 | pci_disable_msi(adapter->pdev); |
| 4192 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4193 | msi_test_failed: |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4194 | e1000e_set_interrupt_capability(adapter); |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4195 | return e1000_request_irq(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | /** |
| 4199 | * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored |
| 4200 | * @adapter: board private struct |
| 4201 | * |
| 4202 | * code flow taken from tg3.c, called with e1000 interrupts disabled. |
| 4203 | **/ |
| 4204 | static int e1000_test_msi(struct e1000_adapter *adapter) |
| 4205 | { |
| 4206 | int err; |
| 4207 | u16 pci_cmd; |
| 4208 | |
| 4209 | if (!(adapter->flags & FLAG_MSI_ENABLED)) |
| 4210 | return 0; |
| 4211 | |
| 4212 | /* disable SERR in case the MSI write causes a master abort */ |
| 4213 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 4214 | if (pci_cmd & PCI_COMMAND_SERR) |
| 4215 | pci_write_config_word(adapter->pdev, PCI_COMMAND, |
| 4216 | pci_cmd & ~PCI_COMMAND_SERR); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4217 | |
| 4218 | err = e1000_test_msi_interrupt(adapter); |
| 4219 | |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 4220 | /* re-enable SERR */ |
| 4221 | if (pci_cmd & PCI_COMMAND_SERR) { |
| 4222 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
| 4223 | pci_cmd |= PCI_COMMAND_SERR; |
| 4224 | pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); |
| 4225 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4226 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4227 | return err; |
| 4228 | } |
| 4229 | |
| 4230 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4231 | * e1000_open - Called when a network interface is made active |
| 4232 | * @netdev: network interface device structure |
| 4233 | * |
| 4234 | * Returns 0 on success, negative value on failure |
| 4235 | * |
| 4236 | * The open entry point is called when a network interface is made |
| 4237 | * active by the system (IFF_UP). At this point all resources needed |
| 4238 | * for transmit and receive operations are allocated, the interrupt |
| 4239 | * handler is registered with the OS, the watchdog timer is started, |
| 4240 | * and the stack is notified that the interface is ready. |
| 4241 | **/ |
| 4242 | static int e1000_open(struct net_device *netdev) |
| 4243 | { |
| 4244 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4245 | struct e1000_hw *hw = &adapter->hw; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4246 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4247 | int err; |
| 4248 | |
| 4249 | /* disallow open during test */ |
| 4250 | if (test_bit(__E1000_TESTING, &adapter->state)) |
| 4251 | return -EBUSY; |
| 4252 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4253 | pm_runtime_get_sync(&pdev->dev); |
| 4254 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 4255 | netif_carrier_off(netdev); |
| 4256 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4257 | /* allocate transmit descriptors */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4258 | err = e1000e_setup_tx_resources(adapter->tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4259 | if (err) |
| 4260 | goto err_setup_tx; |
| 4261 | |
| 4262 | /* allocate receive descriptors */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4263 | err = e1000e_setup_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4264 | if (err) |
| 4265 | goto err_setup_rx; |
| 4266 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4267 | /* If AMT is enabled, let the firmware know that the network |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 4268 | * interface is now open and reset the part to a known state. |
| 4269 | */ |
| 4270 | if (adapter->flags & FLAG_HAS_AMT) { |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4271 | e1000e_get_hw_control(adapter); |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 4272 | e1000e_reset(adapter); |
| 4273 | } |
| 4274 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4275 | e1000e_power_up_phy(adapter); |
| 4276 | |
| 4277 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 4278 | if ((adapter->hw.mng_cookie.status & |
| 4279 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
| 4280 | e1000_update_mng_vlan(adapter); |
| 4281 | |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4282 | /* DMA latency requirement to workaround jumbo issue */ |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 4283 | pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, |
| 4284 | PM_QOS_DEFAULT_VALUE); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 4285 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4286 | /* before we allocate an interrupt, we must be ready to handle it. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4287 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 4288 | * 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] | 4289 | * clean_rx handler before we do so. |
| 4290 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4291 | e1000_configure(adapter); |
| 4292 | |
| 4293 | err = e1000_request_irq(adapter); |
| 4294 | if (err) |
| 4295 | goto err_req_irq; |
| 4296 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4297 | /* Work around PCIe errata with MSI interrupts causing some chipsets to |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4298 | * ignore e1000e MSI messages, which means we need to test our MSI |
| 4299 | * interrupt now |
| 4300 | */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4301 | if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4302 | err = e1000_test_msi(adapter); |
| 4303 | if (err) { |
| 4304 | e_err("Interrupt allocation failed\n"); |
| 4305 | goto err_req_irq; |
| 4306 | } |
| 4307 | } |
| 4308 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4309 | /* From here on the code is the same as e1000e_up() */ |
| 4310 | clear_bit(__E1000_DOWN, &adapter->state); |
| 4311 | |
| 4312 | napi_enable(&adapter->napi); |
| 4313 | |
| 4314 | e1000_irq_enable(adapter); |
| 4315 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 4316 | adapter->tx_hang_recheck = false; |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 4317 | netif_start_queue(netdev); |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4318 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4319 | adapter->idle_check = true; |
| 4320 | pm_runtime_put(&pdev->dev); |
| 4321 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4322 | /* fire a link status change interrupt to start the watchdog */ |
Bruce Allan | 52a9b23 | 2010-05-10 15:00:10 +0000 | [diff] [blame] | 4323 | if (adapter->msix_entries) |
| 4324 | ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); |
| 4325 | else |
| 4326 | ew32(ICS, E1000_ICS_LSC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4327 | |
| 4328 | return 0; |
| 4329 | |
| 4330 | err_req_irq: |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4331 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4332 | e1000_power_down_phy(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4333 | e1000e_free_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4334 | err_setup_rx: |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4335 | e1000e_free_tx_resources(adapter->tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4336 | err_setup_tx: |
| 4337 | e1000e_reset(adapter); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4338 | pm_runtime_put_sync(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4339 | |
| 4340 | return err; |
| 4341 | } |
| 4342 | |
| 4343 | /** |
| 4344 | * e1000_close - Disables a network interface |
| 4345 | * @netdev: network interface device structure |
| 4346 | * |
| 4347 | * Returns 0, this is not allowed to fail |
| 4348 | * |
| 4349 | * The close entry point is called when an interface is de-activated |
| 4350 | * by the OS. The hardware is still under the drivers control, but |
| 4351 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4352 | * hardware, and all transmit and receive resources are freed. |
| 4353 | **/ |
| 4354 | static int e1000_close(struct net_device *netdev) |
| 4355 | { |
| 4356 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4357 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | bb9e44d | 2012-03-21 00:39:12 +0000 | [diff] [blame] | 4358 | int count = E1000_CHECK_RESET_COUNT; |
| 4359 | |
| 4360 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) |
| 4361 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4362 | |
| 4363 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4364 | |
| 4365 | pm_runtime_get_sync(&pdev->dev); |
| 4366 | |
Bruce Allan | 5f4a780 | 2011-11-29 08:09:19 +0000 | [diff] [blame] | 4367 | napi_disable(&adapter->napi); |
| 4368 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4369 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 4370 | e1000e_down(adapter); |
| 4371 | e1000_free_irq(adapter); |
| 4372 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4373 | e1000_power_down_phy(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4374 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4375 | e1000e_free_tx_resources(adapter->tx_ring); |
| 4376 | e1000e_free_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4377 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4378 | /* kill manageability vlan ID if supported, but not if a vlan with |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4379 | * the same ID is registered on the host OS (let 8021q kill it) |
| 4380 | */ |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 4381 | if (adapter->hw.mng_cookie.status & |
| 4382 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4383 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 4384 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4385 | /* If AMT is enabled, let the firmware know that the network |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4386 | * interface is now closed |
| 4387 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4388 | if ((adapter->flags & FLAG_HAS_AMT) && |
| 4389 | !test_bit(__E1000_TESTING, &adapter->state)) |
| 4390 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4391 | |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 4392 | pm_qos_remove_request(&adapter->netdev->pm_qos_req); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 4393 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4394 | pm_runtime_put_sync(&pdev->dev); |
| 4395 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4396 | return 0; |
| 4397 | } |
| 4398 | /** |
| 4399 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 4400 | * @netdev: network interface device structure |
| 4401 | * @p: pointer to an address structure |
| 4402 | * |
| 4403 | * Returns 0 on success, negative on failure |
| 4404 | **/ |
| 4405 | static int e1000_set_mac(struct net_device *netdev, void *p) |
| 4406 | { |
| 4407 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4408 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4409 | struct sockaddr *addr = p; |
| 4410 | |
| 4411 | if (!is_valid_ether_addr(addr->sa_data)) |
| 4412 | return -EADDRNOTAVAIL; |
| 4413 | |
| 4414 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 4415 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 4416 | |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4417 | hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4418 | |
| 4419 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { |
| 4420 | /* activate the work around */ |
| 4421 | e1000e_set_laa_state_82571(&adapter->hw, 1); |
| 4422 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4423 | /* 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] | 4424 | * between the time RAR[0] gets clobbered and the time it |
| 4425 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
| 4426 | * of the RARs and no incoming packets directed to this port |
| 4427 | * are dropped. Eventually the LAA will be in RAR[0] and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4428 | * RAR[14] |
| 4429 | */ |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4430 | hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, |
| 4431 | adapter->hw.mac.rar_entry_count - 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | return 0; |
| 4435 | } |
| 4436 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4437 | /** |
| 4438 | * e1000e_update_phy_task - work thread to update phy |
| 4439 | * @work: pointer to our work struct |
| 4440 | * |
| 4441 | * this worker thread exists because we must acquire a |
| 4442 | * semaphore to read the phy, which we could msleep while |
| 4443 | * waiting for it, and we can't msleep in a timer. |
| 4444 | **/ |
| 4445 | static void e1000e_update_phy_task(struct work_struct *work) |
| 4446 | { |
| 4447 | struct e1000_adapter *adapter = container_of(work, |
| 4448 | struct e1000_adapter, update_phy_task); |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4449 | |
| 4450 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4451 | return; |
| 4452 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4453 | e1000_get_phy_info(&adapter->hw); |
| 4454 | } |
| 4455 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4456 | /** |
| 4457 | * e1000_update_phy_info - timre call-back to update PHY info |
| 4458 | * @data: pointer to adapter cast into an unsigned long |
| 4459 | * |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4460 | * Need to wait a few seconds after link up to get diagnostic information from |
| 4461 | * the phy |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4462 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4463 | static void e1000_update_phy_info(unsigned long data) |
| 4464 | { |
| 4465 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4466 | |
| 4467 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4468 | return; |
| 4469 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4470 | schedule_work(&adapter->update_phy_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | /** |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4474 | * e1000e_update_phy_stats - Update the PHY statistics counters |
| 4475 | * @adapter: board private structure |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4476 | * |
| 4477 | * Read/clear the upper 16-bit PHY registers and read/accumulate lower |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4478 | **/ |
| 4479 | static void e1000e_update_phy_stats(struct e1000_adapter *adapter) |
| 4480 | { |
| 4481 | struct e1000_hw *hw = &adapter->hw; |
| 4482 | s32 ret_val; |
| 4483 | u16 phy_data; |
| 4484 | |
| 4485 | ret_val = hw->phy.ops.acquire(hw); |
| 4486 | if (ret_val) |
| 4487 | return; |
| 4488 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4489 | /* A page set is expensive so check if already on desired page. |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4490 | * If not, set to the page with the PHY status registers. |
| 4491 | */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4492 | hw->phy.addr = 1; |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4493 | ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 4494 | &phy_data); |
| 4495 | if (ret_val) |
| 4496 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4497 | if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) { |
| 4498 | ret_val = hw->phy.ops.set_page(hw, |
| 4499 | HV_STATS_PAGE << IGP_PAGE_SHIFT); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4500 | if (ret_val) |
| 4501 | goto release; |
| 4502 | } |
| 4503 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4504 | /* Single Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4505 | hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data); |
| 4506 | 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] | 4507 | if (!ret_val) |
| 4508 | adapter->stats.scc += phy_data; |
| 4509 | |
| 4510 | /* Excessive Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4511 | hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data); |
| 4512 | 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] | 4513 | if (!ret_val) |
| 4514 | adapter->stats.ecol += phy_data; |
| 4515 | |
| 4516 | /* Multiple Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4517 | hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data); |
| 4518 | 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] | 4519 | if (!ret_val) |
| 4520 | adapter->stats.mcc += phy_data; |
| 4521 | |
| 4522 | /* Late Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4523 | hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data); |
| 4524 | 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] | 4525 | if (!ret_val) |
| 4526 | adapter->stats.latecol += phy_data; |
| 4527 | |
| 4528 | /* Collision Count - also used for adaptive IFS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4529 | hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data); |
| 4530 | 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] | 4531 | if (!ret_val) |
| 4532 | hw->mac.collision_delta = phy_data; |
| 4533 | |
| 4534 | /* Defer Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4535 | hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data); |
| 4536 | 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] | 4537 | if (!ret_val) |
| 4538 | adapter->stats.dc += phy_data; |
| 4539 | |
| 4540 | /* Transmit with no CRS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4541 | hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data); |
| 4542 | 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] | 4543 | if (!ret_val) |
| 4544 | adapter->stats.tncrs += phy_data; |
| 4545 | |
| 4546 | release: |
| 4547 | hw->phy.ops.release(hw); |
| 4548 | } |
| 4549 | |
| 4550 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4551 | * e1000e_update_stats - Update the board statistics counters |
| 4552 | * @adapter: board private structure |
| 4553 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4554 | static void e1000e_update_stats(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4555 | { |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4556 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4557 | struct e1000_hw *hw = &adapter->hw; |
| 4558 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4559 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4560 | /* Prevent stats update while adapter is being reset, or if the pci |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4561 | * connection is down. |
| 4562 | */ |
| 4563 | if (adapter->link_speed == 0) |
| 4564 | return; |
| 4565 | if (pci_channel_offline(pdev)) |
| 4566 | return; |
| 4567 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4568 | adapter->stats.crcerrs += er32(CRCERRS); |
| 4569 | adapter->stats.gprc += er32(GPRC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4570 | adapter->stats.gorc += er32(GORCL); |
| 4571 | er32(GORCH); /* Clear gorc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4572 | adapter->stats.bprc += er32(BPRC); |
| 4573 | adapter->stats.mprc += er32(MPRC); |
| 4574 | adapter->stats.roc += er32(ROC); |
| 4575 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4576 | adapter->stats.mpc += er32(MPC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4577 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4578 | /* Half-duplex statistics */ |
| 4579 | if (adapter->link_duplex == HALF_DUPLEX) { |
| 4580 | if (adapter->flags2 & FLAG2_HAS_PHY_STATS) { |
| 4581 | e1000e_update_phy_stats(adapter); |
| 4582 | } else { |
| 4583 | adapter->stats.scc += er32(SCC); |
| 4584 | adapter->stats.ecol += er32(ECOL); |
| 4585 | adapter->stats.mcc += er32(MCC); |
| 4586 | adapter->stats.latecol += er32(LATECOL); |
| 4587 | adapter->stats.dc += er32(DC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4588 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4589 | hw->mac.collision_delta = er32(COLC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4590 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4591 | if ((hw->mac.type != e1000_82574) && |
| 4592 | (hw->mac.type != e1000_82583)) |
| 4593 | adapter->stats.tncrs += er32(TNCRS); |
| 4594 | } |
| 4595 | adapter->stats.colc += hw->mac.collision_delta; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4596 | } |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4597 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4598 | adapter->stats.xonrxc += er32(XONRXC); |
| 4599 | adapter->stats.xontxc += er32(XONTXC); |
| 4600 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 4601 | adapter->stats.xofftxc += er32(XOFFTXC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4602 | adapter->stats.gptc += er32(GPTC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4603 | adapter->stats.gotc += er32(GOTCL); |
| 4604 | er32(GOTCH); /* Clear gotc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4605 | adapter->stats.rnbc += er32(RNBC); |
| 4606 | adapter->stats.ruc += er32(RUC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4607 | |
| 4608 | adapter->stats.mptc += er32(MPTC); |
| 4609 | adapter->stats.bptc += er32(BPTC); |
| 4610 | |
| 4611 | /* used for adaptive IFS */ |
| 4612 | |
| 4613 | hw->mac.tx_packet_delta = er32(TPT); |
| 4614 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4615 | |
| 4616 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 4617 | adapter->stats.rxerrc += er32(RXERRC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4618 | adapter->stats.cexterr += er32(CEXTERR); |
| 4619 | adapter->stats.tsctc += er32(TSCTC); |
| 4620 | adapter->stats.tsctfc += er32(TSCTFC); |
| 4621 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4622 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4623 | netdev->stats.multicast = adapter->stats.mprc; |
| 4624 | netdev->stats.collisions = adapter->stats.colc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4625 | |
| 4626 | /* Rx Errors */ |
| 4627 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4628 | /* RLEC on some newer hardware can be incorrect so build |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4629 | * our own version based on RUC and ROC |
| 4630 | */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4631 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4632 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 4633 | adapter->stats.ruc + adapter->stats.roc + |
| 4634 | adapter->stats.cexterr; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4635 | netdev->stats.rx_length_errors = adapter->stats.ruc + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4636 | adapter->stats.roc; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4637 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4638 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; |
| 4639 | netdev->stats.rx_missed_errors = adapter->stats.mpc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4640 | |
| 4641 | /* Tx Errors */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4642 | netdev->stats.tx_errors = adapter->stats.ecol + |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4643 | adapter->stats.latecol; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4644 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
| 4645 | netdev->stats.tx_window_errors = adapter->stats.latecol; |
| 4646 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4647 | |
| 4648 | /* Tx Dropped needs to be maintained elsewhere */ |
| 4649 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4650 | /* Management Stats */ |
| 4651 | adapter->stats.mgptc += er32(MGTPTC); |
| 4652 | adapter->stats.mgprc += er32(MGTPRC); |
| 4653 | adapter->stats.mgpdc += er32(MGTPDC); |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 4654 | |
| 4655 | /* Correctable ECC Errors */ |
| 4656 | if (hw->mac.type == e1000_pch_lpt) { |
| 4657 | u32 pbeccsts = er32(PBECCSTS); |
| 4658 | adapter->corr_errors += |
| 4659 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 4660 | adapter->uncorr_errors += |
| 4661 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 4662 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 4663 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4664 | } |
| 4665 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4666 | /** |
| 4667 | * e1000_phy_read_status - Update the PHY register status snapshot |
| 4668 | * @adapter: board private structure |
| 4669 | **/ |
| 4670 | static void e1000_phy_read_status(struct e1000_adapter *adapter) |
| 4671 | { |
| 4672 | struct e1000_hw *hw = &adapter->hw; |
| 4673 | struct e1000_phy_regs *phy = &adapter->phy_regs; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4674 | |
| 4675 | if ((er32(STATUS) & E1000_STATUS_LU) && |
| 4676 | (adapter->hw.phy.media_type == e1000_media_type_copper)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4677 | int ret_val; |
| 4678 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame^] | 4679 | ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr); |
| 4680 | ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr); |
| 4681 | ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise); |
| 4682 | ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa); |
| 4683 | ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion); |
| 4684 | ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000); |
| 4685 | ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000); |
| 4686 | ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4687 | if (ret_val) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4688 | e_warn("Error reading PHY register\n"); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4689 | } else { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4690 | /* Do not read PHY registers if link is not up |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4691 | * Set values to typical power-on defaults |
| 4692 | */ |
| 4693 | phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); |
| 4694 | phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | |
| 4695 | BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | |
| 4696 | BMSR_ERCAP); |
| 4697 | phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | |
| 4698 | ADVERTISE_ALL | ADVERTISE_CSMA); |
| 4699 | phy->lpa = 0; |
| 4700 | phy->expansion = EXPANSION_ENABLENPAGE; |
| 4701 | phy->ctrl1000 = ADVERTISE_1000FULL; |
| 4702 | phy->stat1000 = 0; |
| 4703 | phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); |
| 4704 | } |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4705 | } |
| 4706 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4707 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
| 4708 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4709 | struct e1000_hw *hw = &adapter->hw; |
| 4710 | u32 ctrl = er32(CTRL); |
| 4711 | |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4712 | /* Link status message must follow this format for user tools */ |
Bruce Allan | 7dbc167 | 2013-01-12 03:11:25 +0000 | [diff] [blame] | 4713 | pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n", |
| 4714 | adapter->netdev->name, adapter->link_speed, |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 4715 | adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half", |
| 4716 | (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" : |
| 4717 | (ctrl & E1000_CTRL_RFCE) ? "Rx" : |
| 4718 | (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 4721 | static bool e1000e_has_link(struct e1000_adapter *adapter) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4722 | { |
| 4723 | struct e1000_hw *hw = &adapter->hw; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4724 | bool link_active = false; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4725 | s32 ret_val = 0; |
| 4726 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4727 | /* get_link_status is set on LSC (link status) interrupt or |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4728 | * Rx sequence error interrupt. get_link_status will stay |
| 4729 | * false until the check_for_link establishes link |
| 4730 | * for copper adapters ONLY |
| 4731 | */ |
| 4732 | switch (hw->phy.media_type) { |
| 4733 | case e1000_media_type_copper: |
| 4734 | if (hw->mac.get_link_status) { |
| 4735 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4736 | link_active = !hw->mac.get_link_status; |
| 4737 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4738 | link_active = true; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4739 | } |
| 4740 | break; |
| 4741 | case e1000_media_type_fiber: |
| 4742 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4743 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 4744 | break; |
| 4745 | case e1000_media_type_internal_serdes: |
| 4746 | ret_val = hw->mac.ops.check_for_link(hw); |
| 4747 | link_active = adapter->hw.mac.serdes_has_link; |
| 4748 | break; |
| 4749 | default: |
| 4750 | case e1000_media_type_unknown: |
| 4751 | break; |
| 4752 | } |
| 4753 | |
| 4754 | if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && |
| 4755 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 4756 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4757 | e_info("Gigabit has been disabled, downgrading speed\n"); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | return link_active; |
| 4761 | } |
| 4762 | |
| 4763 | static void e1000e_enable_receives(struct e1000_adapter *adapter) |
| 4764 | { |
| 4765 | /* make sure the receive unit is started */ |
| 4766 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 4767 | (adapter->flags & FLAG_RESTART_NOW)) { |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4768 | struct e1000_hw *hw = &adapter->hw; |
| 4769 | u32 rctl = er32(RCTL); |
| 4770 | ew32(RCTL, rctl | E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 4771 | adapter->flags &= ~FLAG_RESTART_NOW; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4772 | } |
| 4773 | } |
| 4774 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4775 | static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter) |
| 4776 | { |
| 4777 | struct e1000_hw *hw = &adapter->hw; |
| 4778 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4779 | /* With 82574 controllers, PHY needs to be checked periodically |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 4780 | * for hung state and reset, if two calls return true |
| 4781 | */ |
| 4782 | if (e1000_check_phy_82574(hw)) |
| 4783 | adapter->phy_hang_count++; |
| 4784 | else |
| 4785 | adapter->phy_hang_count = 0; |
| 4786 | |
| 4787 | if (adapter->phy_hang_count > 1) { |
| 4788 | adapter->phy_hang_count = 0; |
| 4789 | schedule_work(&adapter->reset_task); |
| 4790 | } |
| 4791 | } |
| 4792 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4793 | /** |
| 4794 | * e1000_watchdog - Timer Call-back |
| 4795 | * @data: pointer to adapter cast into an unsigned long |
| 4796 | **/ |
| 4797 | static void e1000_watchdog(unsigned long data) |
| 4798 | { |
| 4799 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 4800 | |
| 4801 | /* Do the rest outside of interrupt context */ |
| 4802 | schedule_work(&adapter->watchdog_task); |
| 4803 | |
| 4804 | /* TODO: make this use queue_delayed_work() */ |
| 4805 | } |
| 4806 | |
| 4807 | static void e1000_watchdog_task(struct work_struct *work) |
| 4808 | { |
| 4809 | struct e1000_adapter *adapter = container_of(work, |
| 4810 | struct e1000_adapter, watchdog_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4811 | struct net_device *netdev = adapter->netdev; |
| 4812 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4813 | struct e1000_phy_info *phy = &adapter->hw.phy; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4814 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 4815 | struct e1000_hw *hw = &adapter->hw; |
| 4816 | u32 link, tctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4817 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4818 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4819 | return; |
| 4820 | |
David S. Miller | b405e8d | 2010-02-04 22:31:41 -0800 | [diff] [blame] | 4821 | link = e1000e_has_link(adapter); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4822 | if ((netif_carrier_ok(netdev)) && link) { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4823 | /* Cancel scheduled suspend requests. */ |
| 4824 | pm_runtime_resume(netdev->dev.parent); |
| 4825 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4826 | e1000e_enable_receives(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4827 | goto link_up; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4828 | } |
| 4829 | |
| 4830 | if ((e1000e_enable_tx_pkt_filtering(hw)) && |
| 4831 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) |
| 4832 | e1000_update_mng_vlan(adapter); |
| 4833 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4834 | if (link) { |
| 4835 | if (!netif_carrier_ok(netdev)) { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4836 | bool txb2b = true; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4837 | |
| 4838 | /* Cancel scheduled suspend requests. */ |
| 4839 | pm_runtime_resume(netdev->dev.parent); |
| 4840 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4841 | /* update snapshot of PHY registers on LSC */ |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4842 | e1000_phy_read_status(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4843 | mac->ops.get_link_up_info(&adapter->hw, |
| 4844 | &adapter->link_speed, |
| 4845 | &adapter->link_duplex); |
| 4846 | e1000_print_link_info(adapter); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4847 | /* On supported PHYs, check for duplex mismatch only |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 4848 | * if link has autonegotiated at 10/100 half |
| 4849 | */ |
| 4850 | if ((hw->phy.type == e1000_phy_igp_3 || |
| 4851 | hw->phy.type == e1000_phy_bm) && |
| 4852 | (hw->mac.autoneg == true) && |
| 4853 | (adapter->link_speed == SPEED_10 || |
| 4854 | adapter->link_speed == SPEED_100) && |
| 4855 | (adapter->link_duplex == HALF_DUPLEX)) { |
| 4856 | u16 autoneg_exp; |
| 4857 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame^] | 4858 | e1e_rphy(hw, MII_EXPANSION, &autoneg_exp); |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 4859 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame^] | 4860 | if (!(autoneg_exp & EXPANSION_NWAY)) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 4861 | 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] | 4862 | } |
| 4863 | |
Emil Tantilov | f49c57e | 2010-03-24 12:55:02 +0000 | [diff] [blame] | 4864 | /* adjust timeout factor according to speed/duplex */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4865 | adapter->tx_timeout_factor = 1; |
| 4866 | switch (adapter->link_speed) { |
| 4867 | case SPEED_10: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4868 | txb2b = false; |
Bruce Allan | 10f1b49 | 2008-08-08 18:36:01 -0700 | [diff] [blame] | 4869 | adapter->tx_timeout_factor = 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4870 | break; |
| 4871 | case SPEED_100: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4872 | txb2b = false; |
Bruce Allan | 4c86e0b | 2009-11-19 12:35:26 +0000 | [diff] [blame] | 4873 | adapter->tx_timeout_factor = 10; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4874 | break; |
| 4875 | } |
| 4876 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4877 | /* workaround: re-program speed mode bit after |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4878 | * link-up event |
| 4879 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4880 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
| 4881 | !txb2b) { |
| 4882 | u32 tarc0; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4883 | tarc0 = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4884 | tarc0 &= ~SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 4885 | ew32(TARC(0), tarc0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4886 | } |
| 4887 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4888 | /* disable TSO for pcie and 10/100 speeds, to avoid |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4889 | * some hardware issues |
| 4890 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4891 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
| 4892 | switch (adapter->link_speed) { |
| 4893 | case SPEED_10: |
| 4894 | case SPEED_100: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4895 | e_info("10/100 speed: disabling TSO\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4896 | netdev->features &= ~NETIF_F_TSO; |
| 4897 | netdev->features &= ~NETIF_F_TSO6; |
| 4898 | break; |
| 4899 | case SPEED_1000: |
| 4900 | netdev->features |= NETIF_F_TSO; |
| 4901 | netdev->features |= NETIF_F_TSO6; |
| 4902 | break; |
| 4903 | default: |
| 4904 | /* oops */ |
| 4905 | break; |
| 4906 | } |
| 4907 | } |
| 4908 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4909 | /* enable transmits in the hardware, need to do this |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4910 | * after setting TARC(0) |
| 4911 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4912 | tctl = er32(TCTL); |
| 4913 | tctl |= E1000_TCTL_EN; |
| 4914 | ew32(TCTL, tctl); |
| 4915 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4916 | /* Perform any post-link-up configuration before |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 4917 | * reporting link up. |
| 4918 | */ |
| 4919 | if (phy->ops.cfg_on_link_up) |
| 4920 | phy->ops.cfg_on_link_up(hw); |
| 4921 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4922 | netif_carrier_on(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4923 | |
| 4924 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4925 | mod_timer(&adapter->phy_info_timer, |
| 4926 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4927 | } |
| 4928 | } else { |
| 4929 | if (netif_carrier_ok(netdev)) { |
| 4930 | adapter->link_speed = 0; |
| 4931 | adapter->link_duplex = 0; |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 4932 | /* Link status message must follow this format */ |
Bruce Allan | 7dbc167 | 2013-01-12 03:11:25 +0000 | [diff] [blame] | 4933 | pr_info("%s NIC Link is Down\n", adapter->netdev->name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4934 | netif_carrier_off(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4935 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 4936 | mod_timer(&adapter->phy_info_timer, |
| 4937 | round_jiffies(jiffies + 2 * HZ)); |
| 4938 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 4939 | /* The link is lost so the controller stops DMA. |
| 4940 | * If there is queued Tx work that cannot be done |
| 4941 | * or if on an 8000ES2LAN which requires a Rx packet |
| 4942 | * buffer work-around on link down event, reset the |
| 4943 | * controller to flush the Tx/Rx packet buffers. |
| 4944 | * (Do the reset outside of interrupt context). |
| 4945 | */ |
| 4946 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) || |
| 4947 | (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) |
| 4948 | adapter->flags |= FLAG_RESTART_NOW; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4949 | else |
| 4950 | pm_schedule_suspend(netdev->dev.parent, |
| 4951 | LINK_TIMEOUT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4952 | } |
| 4953 | } |
| 4954 | |
| 4955 | link_up: |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4956 | spin_lock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4957 | e1000e_update_stats(adapter); |
| 4958 | |
| 4959 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 4960 | adapter->tpt_old = adapter->stats.tpt; |
| 4961 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; |
| 4962 | adapter->colc_old = adapter->stats.colc; |
| 4963 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4964 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
| 4965 | adapter->gorc_old = adapter->stats.gorc; |
| 4966 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; |
| 4967 | adapter->gotc_old = adapter->stats.gotc; |
Flavio Leitner | 2084b11 | 2011-04-05 04:27:43 +0000 | [diff] [blame] | 4968 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4969 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 4970 | if (adapter->flags & FLAG_RESTART_NOW) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 4971 | schedule_work(&adapter->reset_task); |
| 4972 | /* return immediately since reset is imminent */ |
| 4973 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4974 | } |
| 4975 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 4976 | e1000e_update_adaptive(&adapter->hw); |
| 4977 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4978 | /* Simple mode for Interrupt Throttle Rate (ITR) */ |
| 4979 | if (adapter->itr_setting == 4) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4980 | /* Symmetric Tx/Rx gets a reduced ITR=2000; |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4981 | * Total asymmetrical Tx or Rx gets ITR=8000; |
| 4982 | * everyone else is between 2000-8000. |
| 4983 | */ |
| 4984 | u32 goc = (adapter->gotc + adapter->gorc) / 10000; |
| 4985 | u32 dif = (adapter->gotc > adapter->gorc ? |
| 4986 | adapter->gotc - adapter->gorc : |
| 4987 | adapter->gorc - adapter->gotc) / 10000; |
| 4988 | u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 4989 | |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 4990 | e1000e_write_itr(adapter, itr); |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 4991 | } |
| 4992 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4993 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4994 | if (adapter->msix_entries) |
| 4995 | ew32(ICS, adapter->rx_ring->ims_val); |
| 4996 | else |
| 4997 | ew32(ICS, E1000_ICS_RXDMT0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4998 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4999 | /* flush pending descriptors to memory before detecting Tx hang */ |
| 5000 | e1000e_flush_descriptors(adapter); |
| 5001 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5002 | /* Force detection of hung controller every watchdog period */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5003 | adapter->detect_tx_hung = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5004 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5005 | /* With 82571 controllers, LAA may be overwritten due to controller |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5006 | * reset from the other port. Set the appropriate LAA in RAR[0] |
| 5007 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5008 | if (e1000e_get_laa_state_82571(hw)) |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 5009 | hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5010 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 5011 | if (adapter->flags2 & FLAG2_CHECK_PHY_HANG) |
| 5012 | e1000e_check_82574_phy_workaround(adapter); |
| 5013 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5014 | /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */ |
| 5015 | if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) { |
| 5016 | if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) && |
| 5017 | (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) { |
| 5018 | er32(RXSTMPH); |
| 5019 | adapter->rx_hwtstamp_cleared++; |
| 5020 | } else { |
| 5021 | adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP; |
| 5022 | } |
| 5023 | } |
| 5024 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5025 | /* Reset the timer */ |
| 5026 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 5027 | mod_timer(&adapter->watchdog_timer, |
| 5028 | round_jiffies(jiffies + 2 * HZ)); |
| 5029 | } |
| 5030 | |
| 5031 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 5032 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 5033 | #define E1000_TX_FLAGS_TSO 0x00000004 |
| 5034 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5035 | #define E1000_TX_FLAGS_NO_FCS 0x00000010 |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5036 | #define E1000_TX_FLAGS_HWTSTAMP 0x00000020 |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5037 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 5038 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 5039 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5040 | 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] | 5041 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5042 | struct e1000_context_desc *context_desc; |
| 5043 | struct e1000_buffer *buffer_info; |
| 5044 | unsigned int i; |
| 5045 | u32 cmd_length = 0; |
Bruce Allan | 70443ae | 2012-08-17 06:18:13 +0000 | [diff] [blame] | 5046 | u16 ipcse = 0, mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5047 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5048 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5049 | if (!skb_is_gso(skb)) |
| 5050 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5051 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5052 | if (skb_header_cloned(skb)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 5053 | int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 5054 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5055 | if (err) |
| 5056 | return err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5057 | } |
| 5058 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5059 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 5060 | mss = skb_shinfo(skb)->gso_size; |
| 5061 | if (skb->protocol == htons(ETH_P_IP)) { |
| 5062 | struct iphdr *iph = ip_hdr(skb); |
| 5063 | iph->tot_len = 0; |
| 5064 | iph->check = 0; |
| 5065 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, |
| 5066 | 0, IPPROTO_TCP, 0); |
| 5067 | cmd_length = E1000_TXD_CMD_IP; |
| 5068 | ipcse = skb_transport_offset(skb) - 1; |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 5069 | } else if (skb_is_gso_v6(skb)) { |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5070 | ipv6_hdr(skb)->payload_len = 0; |
| 5071 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 5072 | &ipv6_hdr(skb)->daddr, |
| 5073 | 0, IPPROTO_TCP, 0); |
| 5074 | ipcse = 0; |
| 5075 | } |
| 5076 | ipcss = skb_network_offset(skb); |
| 5077 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
| 5078 | tucss = skb_transport_offset(skb); |
| 5079 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5080 | |
| 5081 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
| 5082 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
| 5083 | |
| 5084 | i = tx_ring->next_to_use; |
| 5085 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 5086 | buffer_info = &tx_ring->buffer_info[i]; |
| 5087 | |
| 5088 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 5089 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 5090 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 5091 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 5092 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
Bruce Allan | 70443ae | 2012-08-17 06:18:13 +0000 | [diff] [blame] | 5093 | context_desc->upper_setup.tcp_fields.tucse = 0; |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5094 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 5095 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 5096 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 5097 | |
| 5098 | buffer_info->time_stamp = jiffies; |
| 5099 | buffer_info->next_to_watch = i; |
| 5100 | |
| 5101 | i++; |
| 5102 | if (i == tx_ring->count) |
| 5103 | i = 0; |
| 5104 | tx_ring->next_to_use = i; |
| 5105 | |
| 5106 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5107 | } |
| 5108 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5109 | 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] | 5110 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5111 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5112 | struct e1000_context_desc *context_desc; |
| 5113 | struct e1000_buffer *buffer_info; |
| 5114 | unsigned int i; |
| 5115 | u8 css; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5116 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 5117 | __be16 protocol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5118 | |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5119 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 5120 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5121 | |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 5122 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) |
| 5123 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 5124 | else |
| 5125 | protocol = skb->protocol; |
| 5126 | |
Arthur Jones | 3f51839 | 2009-03-20 15:56:35 -0700 | [diff] [blame] | 5127 | switch (protocol) { |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5128 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5129 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 5130 | cmd_len |= E1000_TXD_CMD_TCP; |
| 5131 | break; |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5132 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5133 | /* XXX not handling all IPV6 headers */ |
| 5134 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 5135 | cmd_len |= E1000_TXD_CMD_TCP; |
| 5136 | break; |
| 5137 | default: |
| 5138 | if (unlikely(net_ratelimit())) |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 5139 | e_warn("checksum_partial proto=%x!\n", |
| 5140 | be16_to_cpu(protocol)); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5141 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5142 | } |
| 5143 | |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 5144 | css = skb_checksum_start_offset(skb); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5145 | |
| 5146 | i = tx_ring->next_to_use; |
| 5147 | buffer_info = &tx_ring->buffer_info[i]; |
| 5148 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 5149 | |
| 5150 | context_desc->lower_setup.ip_config = 0; |
| 5151 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 5152 | context_desc->upper_setup.tcp_fields.tucso = |
| 5153 | css + skb->csum_offset; |
| 5154 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 5155 | context_desc->tcp_seg_setup.data = 0; |
| 5156 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 5157 | |
| 5158 | buffer_info->time_stamp = jiffies; |
| 5159 | buffer_info->next_to_watch = i; |
| 5160 | |
| 5161 | i++; |
| 5162 | if (i == tx_ring->count) |
| 5163 | i = 0; |
| 5164 | tx_ring->next_to_use = i; |
| 5165 | |
| 5166 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5169 | static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb, |
| 5170 | unsigned int first, unsigned int max_per_txd, |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5171 | unsigned int nr_frags) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5172 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5173 | struct e1000_adapter *adapter = tx_ring->adapter; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5174 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5175 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 5176 | unsigned int len = skb_headlen(skb); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5177 | unsigned int offset = 0, size, count = 0, i; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5178 | unsigned int f, bytecount, segs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5179 | |
| 5180 | i = tx_ring->next_to_use; |
| 5181 | |
| 5182 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5183 | buffer_info = &tx_ring->buffer_info[i]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5184 | size = min(len, max_per_txd); |
| 5185 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5186 | buffer_info->length = size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5187 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5188 | buffer_info->next_to_watch = i; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5189 | buffer_info->dma = dma_map_single(&pdev->dev, |
| 5190 | skb->data + offset, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5191 | size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5192 | buffer_info->mapped_as_page = false; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5193 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5194 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5195 | |
| 5196 | len -= size; |
| 5197 | offset += size; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5198 | count++; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5199 | |
| 5200 | if (len) { |
| 5201 | i++; |
| 5202 | if (i == tx_ring->count) |
| 5203 | i = 0; |
| 5204 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5205 | } |
| 5206 | |
| 5207 | for (f = 0; f < nr_frags; f++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5208 | const struct skb_frag_struct *frag; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5209 | |
| 5210 | frag = &skb_shinfo(skb)->frags[f]; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5211 | len = skb_frag_size(frag); |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 5212 | offset = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5213 | |
| 5214 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5215 | i++; |
| 5216 | if (i == tx_ring->count) |
| 5217 | i = 0; |
| 5218 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5219 | buffer_info = &tx_ring->buffer_info[i]; |
| 5220 | size = min(len, max_per_txd); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5221 | |
| 5222 | buffer_info->length = size; |
| 5223 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5224 | buffer_info->next_to_watch = i; |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 5225 | buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag, |
| 5226 | offset, size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5227 | buffer_info->mapped_as_page = true; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5228 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5229 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5230 | |
| 5231 | len -= size; |
| 5232 | offset += size; |
| 5233 | count++; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5234 | } |
| 5235 | } |
| 5236 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5237 | segs = skb_shinfo(skb)->gso_segs ? : 1; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5238 | /* multiply data chunks by size of headers */ |
| 5239 | bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len; |
| 5240 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5241 | tx_ring->buffer_info[i].skb = skb; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5242 | tx_ring->buffer_info[i].segs = segs; |
| 5243 | tx_ring->buffer_info[i].bytecount = bytecount; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5244 | tx_ring->buffer_info[first].next_to_watch = i; |
| 5245 | |
| 5246 | return count; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5247 | |
| 5248 | dma_error: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5249 | dev_err(&pdev->dev, "Tx DMA map failed\n"); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5250 | buffer_info->dma = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5251 | if (count) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5252 | count--; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5253 | |
| 5254 | while (count--) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5255 | if (i == 0) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5256 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5257 | i--; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5258 | buffer_info = &tx_ring->buffer_info[i]; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5259 | e1000_put_txbuf(tx_ring, buffer_info); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5260 | } |
| 5261 | |
| 5262 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5263 | } |
| 5264 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5265 | 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] | 5266 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5267 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5268 | struct e1000_tx_desc *tx_desc = NULL; |
| 5269 | struct e1000_buffer *buffer_info; |
| 5270 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 5271 | unsigned int i; |
| 5272 | |
| 5273 | if (tx_flags & E1000_TX_FLAGS_TSO) { |
| 5274 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 5275 | E1000_TXD_CMD_TSE; |
| 5276 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 5277 | |
| 5278 | if (tx_flags & E1000_TX_FLAGS_IPV4) |
| 5279 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
| 5280 | } |
| 5281 | |
| 5282 | if (tx_flags & E1000_TX_FLAGS_CSUM) { |
| 5283 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 5284 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 5285 | } |
| 5286 | |
| 5287 | if (tx_flags & E1000_TX_FLAGS_VLAN) { |
| 5288 | txd_lower |= E1000_TXD_CMD_VLE; |
| 5289 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 5290 | } |
| 5291 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5292 | if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS)) |
| 5293 | txd_lower &= ~(E1000_TXD_CMD_IFCS); |
| 5294 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5295 | if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) { |
| 5296 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 5297 | txd_upper |= E1000_TXD_EXTCMD_TSTAMP; |
| 5298 | } |
| 5299 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5300 | i = tx_ring->next_to_use; |
| 5301 | |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 5302 | do { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5303 | buffer_info = &tx_ring->buffer_info[i]; |
| 5304 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 5305 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 5306 | tx_desc->lower.data = |
| 5307 | cpu_to_le32(txd_lower | buffer_info->length); |
| 5308 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
| 5309 | |
| 5310 | i++; |
| 5311 | if (i == tx_ring->count) |
| 5312 | i = 0; |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 5313 | } while (--count > 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5314 | |
| 5315 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 5316 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5317 | /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */ |
| 5318 | if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS)) |
| 5319 | tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS)); |
| 5320 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5321 | /* Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5322 | * know there are new descriptors to fetch. (Only |
| 5323 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5324 | * such as IA-64). |
| 5325 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5326 | wmb(); |
| 5327 | |
| 5328 | tx_ring->next_to_use = i; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 5329 | |
| 5330 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5331 | e1000e_update_tdt_wa(tx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 5332 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 5333 | writel(i, tx_ring->tail); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 5334 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5335 | /* 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] | 5336 | * at a time, it synchronizes IO on IA64/Altix systems |
| 5337 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5338 | mmiowb(); |
| 5339 | } |
| 5340 | |
| 5341 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 5342 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 5343 | struct sk_buff *skb) |
| 5344 | { |
| 5345 | struct e1000_hw *hw = &adapter->hw; |
| 5346 | u16 length, offset; |
| 5347 | |
Bruce Allan | d60923c | 2012-12-05 06:26:56 +0000 | [diff] [blame] | 5348 | if (vlan_tx_tag_present(skb) && |
| 5349 | !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
| 5350 | (adapter->hw.mng_cookie.status & |
| 5351 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) |
| 5352 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5353 | |
| 5354 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) |
| 5355 | return 0; |
| 5356 | |
| 5357 | if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP)) |
| 5358 | return 0; |
| 5359 | |
| 5360 | { |
| 5361 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14); |
| 5362 | struct udphdr *udp; |
| 5363 | |
| 5364 | if (ip->protocol != IPPROTO_UDP) |
| 5365 | return 0; |
| 5366 | |
| 5367 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 5368 | if (ntohs(udp->dest) != 67) |
| 5369 | return 0; |
| 5370 | |
| 5371 | offset = (u8 *)udp + 8 - skb->data; |
| 5372 | length = skb->len - offset; |
| 5373 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); |
| 5374 | } |
| 5375 | |
| 5376 | return 0; |
| 5377 | } |
| 5378 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5379 | 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] | 5380 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5381 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5382 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5383 | netif_stop_queue(adapter->netdev); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5384 | /* Herbert's original patch had: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5385 | * smp_mb__after_netif_stop_queue(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5386 | * but since that doesn't exist yet, just open code it. |
| 5387 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5388 | smp_mb(); |
| 5389 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5390 | /* We need to check again in a case another CPU has just |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5391 | * made room available. |
| 5392 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5393 | if (e1000_desc_unused(tx_ring) < size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5394 | return -EBUSY; |
| 5395 | |
| 5396 | /* A reprieve! */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5397 | netif_start_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5398 | ++adapter->restart_queue; |
| 5399 | return 0; |
| 5400 | } |
| 5401 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5402 | 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] | 5403 | { |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5404 | BUG_ON(size > tx_ring->count); |
| 5405 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5406 | if (e1000_desc_unused(tx_ring) >= size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5407 | return 0; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5408 | return __e1000_maybe_stop_tx(tx_ring, size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5409 | } |
| 5410 | |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 5411 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 5412 | struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5413 | { |
| 5414 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5415 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 5416 | unsigned int first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5417 | unsigned int tx_flags = 0; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5418 | unsigned int len = skb_headlen(skb); |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 5419 | unsigned int nr_frags; |
| 5420 | unsigned int mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5421 | int count = 0; |
| 5422 | int tso; |
| 5423 | unsigned int f; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5424 | |
| 5425 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 5426 | dev_kfree_skb_any(skb); |
| 5427 | return NETDEV_TX_OK; |
| 5428 | } |
| 5429 | |
| 5430 | if (skb->len <= 0) { |
| 5431 | dev_kfree_skb_any(skb); |
| 5432 | return NETDEV_TX_OK; |
| 5433 | } |
| 5434 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5435 | /* The minimum packet size with TCTL.PSP set is 17 bytes so |
Tushar Dave | 6e97c17 | 2012-09-14 02:21:37 +0000 | [diff] [blame] | 5436 | * pad skb in order to meet this minimum size requirement |
| 5437 | */ |
| 5438 | if (unlikely(skb->len < 17)) { |
| 5439 | if (skb_pad(skb, 17 - skb->len)) |
| 5440 | return NETDEV_TX_OK; |
| 5441 | skb->len = 17; |
| 5442 | skb_set_tail_pointer(skb, 17); |
| 5443 | } |
| 5444 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5445 | mss = skb_shinfo(skb)->gso_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5446 | if (mss) { |
| 5447 | u8 hdr_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5448 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5449 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5450 | * points to just header, pull a few bytes of payload from |
| 5451 | * frags into skb->data |
| 5452 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5453 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5454 | /* we do this workaround for ES2LAN, but it is un-necessary, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5455 | * avoiding it could save a lot of cycles |
| 5456 | */ |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 5457 | if (skb->data_len && (hdr_len == len)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5458 | unsigned int pull_size; |
| 5459 | |
Bruce Allan | a2a5b32 | 2012-01-31 06:37:17 +0000 | [diff] [blame] | 5460 | pull_size = min_t(unsigned int, 4, skb->data_len); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5461 | if (!__pskb_pull_tail(skb, pull_size)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5462 | e_err("__pskb_pull_tail failed.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5463 | dev_kfree_skb_any(skb); |
| 5464 | return NETDEV_TX_OK; |
| 5465 | } |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5466 | len = skb_headlen(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5467 | } |
| 5468 | } |
| 5469 | |
| 5470 | /* reserve a descriptor for the offload context */ |
| 5471 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5472 | count++; |
| 5473 | count++; |
| 5474 | |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5475 | count += DIV_ROUND_UP(len, adapter->tx_fifo_limit); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5476 | |
| 5477 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 5478 | for (f = 0; f < nr_frags; f++) |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5479 | count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]), |
| 5480 | adapter->tx_fifo_limit); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5481 | |
| 5482 | if (adapter->hw.mac.tx_pkt_filtering) |
| 5483 | e1000_transfer_dhcp_info(adapter, skb); |
| 5484 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5485 | /* need: count + 2 desc gap to keep tail from touching |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5486 | * head, otherwise try next time |
| 5487 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5488 | if (e1000_maybe_stop_tx(tx_ring, count + 2)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5489 | return NETDEV_TX_BUSY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5490 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 5491 | if (vlan_tx_tag_present(skb)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5492 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 5493 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 5494 | } |
| 5495 | |
| 5496 | first = tx_ring->next_to_use; |
| 5497 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5498 | tso = e1000_tso(tx_ring, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5499 | if (tso < 0) { |
| 5500 | dev_kfree_skb_any(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5501 | return NETDEV_TX_OK; |
| 5502 | } |
| 5503 | |
| 5504 | if (tso) |
| 5505 | tx_flags |= E1000_TX_FLAGS_TSO; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5506 | else if (e1000_tx_csum(tx_ring, skb)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5507 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 5508 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5509 | /* 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] | 5510 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5511 | * no longer assume, we must. |
| 5512 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5513 | if (skb->protocol == htons(ETH_P_IP)) |
| 5514 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 5515 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5516 | if (unlikely(skb->no_fcs)) |
| 5517 | tx_flags |= E1000_TX_FLAGS_NO_FCS; |
| 5518 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5519 | /* if count is 0 then mapping error has occurred */ |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5520 | count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit, |
| 5521 | nr_frags); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5522 | if (count) { |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5523 | if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 5524 | !adapter->tx_hwtstamp_skb)) { |
| 5525 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 5526 | tx_flags |= E1000_TX_FLAGS_HWTSTAMP; |
| 5527 | adapter->tx_hwtstamp_skb = skb_get(skb); |
| 5528 | schedule_work(&adapter->tx_hwtstamp_work); |
| 5529 | } else { |
| 5530 | skb_tx_timestamp(skb); |
| 5531 | } |
Willem de Bruijn | 80be312 | 2012-04-27 09:04:05 +0000 | [diff] [blame] | 5532 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 5533 | netdev_sent_queue(netdev, skb->len); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5534 | e1000_tx_queue(tx_ring, tx_flags, count); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5535 | /* Make sure there is space in the ring for the next send. */ |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5536 | e1000_maybe_stop_tx(tx_ring, |
| 5537 | (MAX_SKB_FRAGS * |
| 5538 | DIV_ROUND_UP(PAGE_SIZE, |
| 5539 | adapter->tx_fifo_limit) + 2)); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5540 | } else { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5541 | dev_kfree_skb_any(skb); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5542 | tx_ring->buffer_info[first].time_stamp = 0; |
| 5543 | tx_ring->next_to_use = first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5544 | } |
| 5545 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5546 | return NETDEV_TX_OK; |
| 5547 | } |
| 5548 | |
| 5549 | /** |
| 5550 | * e1000_tx_timeout - Respond to a Tx Hang |
| 5551 | * @netdev: network interface device structure |
| 5552 | **/ |
| 5553 | static void e1000_tx_timeout(struct net_device *netdev) |
| 5554 | { |
| 5555 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5556 | |
| 5557 | /* Do the reset outside of interrupt context */ |
| 5558 | adapter->tx_timeout_count++; |
| 5559 | schedule_work(&adapter->reset_task); |
| 5560 | } |
| 5561 | |
| 5562 | static void e1000_reset_task(struct work_struct *work) |
| 5563 | { |
| 5564 | struct e1000_adapter *adapter; |
| 5565 | adapter = container_of(work, struct e1000_adapter, reset_task); |
| 5566 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 5567 | /* don't run the task if already down */ |
| 5568 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 5569 | return; |
| 5570 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5571 | if (!(adapter->flags & FLAG_RESTART_NOW)) { |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 5572 | e1000e_dump(adapter); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5573 | e_err("Reset adapter unexpectedly\n"); |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 5574 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5575 | e1000e_reinit_locked(adapter); |
| 5576 | } |
| 5577 | |
| 5578 | /** |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5579 | * e1000_get_stats64 - Get System Network Statistics |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5580 | * @netdev: network interface device structure |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5581 | * @stats: rtnl_link_stats64 pointer |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5582 | * |
| 5583 | * Returns the address of the device statistics structure. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5584 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5585 | struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev, |
| 5586 | struct rtnl_link_stats64 *stats) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5587 | { |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5588 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5589 | |
| 5590 | memset(stats, 0, sizeof(struct rtnl_link_stats64)); |
| 5591 | spin_lock(&adapter->stats64_lock); |
| 5592 | e1000e_update_stats(adapter); |
| 5593 | /* Fill out the OS statistics structure */ |
| 5594 | stats->rx_bytes = adapter->stats.gorc; |
| 5595 | stats->rx_packets = adapter->stats.gprc; |
| 5596 | stats->tx_bytes = adapter->stats.gotc; |
| 5597 | stats->tx_packets = adapter->stats.gptc; |
| 5598 | stats->multicast = adapter->stats.mprc; |
| 5599 | stats->collisions = adapter->stats.colc; |
| 5600 | |
| 5601 | /* Rx Errors */ |
| 5602 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5603 | /* RLEC on some newer hardware can be incorrect so build |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5604 | * our own version based on RUC and ROC |
| 5605 | */ |
| 5606 | stats->rx_errors = adapter->stats.rxerrc + |
| 5607 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 5608 | adapter->stats.ruc + adapter->stats.roc + |
| 5609 | adapter->stats.cexterr; |
| 5610 | stats->rx_length_errors = adapter->stats.ruc + |
| 5611 | adapter->stats.roc; |
| 5612 | stats->rx_crc_errors = adapter->stats.crcerrs; |
| 5613 | stats->rx_frame_errors = adapter->stats.algnerrc; |
| 5614 | stats->rx_missed_errors = adapter->stats.mpc; |
| 5615 | |
| 5616 | /* Tx Errors */ |
| 5617 | stats->tx_errors = adapter->stats.ecol + |
| 5618 | adapter->stats.latecol; |
| 5619 | stats->tx_aborted_errors = adapter->stats.ecol; |
| 5620 | stats->tx_window_errors = adapter->stats.latecol; |
| 5621 | stats->tx_carrier_errors = adapter->stats.tncrs; |
| 5622 | |
| 5623 | /* Tx Dropped needs to be maintained elsewhere */ |
| 5624 | |
| 5625 | spin_unlock(&adapter->stats64_lock); |
| 5626 | return stats; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5627 | } |
| 5628 | |
| 5629 | /** |
| 5630 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 5631 | * @netdev: network interface device structure |
| 5632 | * @new_mtu: new value for maximum frame size |
| 5633 | * |
| 5634 | * Returns 0 on success, negative on failure |
| 5635 | **/ |
| 5636 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 5637 | { |
| 5638 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5639 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5640 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5641 | /* Jumbo frame support */ |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 5642 | if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) && |
| 5643 | !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
| 5644 | e_err("Jumbo Frames not supported.\n"); |
| 5645 | return -EINVAL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5646 | } |
| 5647 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 5648 | /* Supported frame sizes */ |
| 5649 | if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) || |
| 5650 | (max_frame > adapter->max_hw_frame_size)) { |
| 5651 | e_err("Unsupported MTU setting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5652 | return -EINVAL; |
| 5653 | } |
| 5654 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 5655 | /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */ |
| 5656 | if ((adapter->hw.mac.type >= e1000_pch2lan) && |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 5657 | !(adapter->flags2 & FLAG2_CRC_STRIPPING) && |
| 5658 | (new_mtu > ETH_DATA_LEN)) { |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 5659 | 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] | 5660 | return -EINVAL; |
| 5661 | } |
| 5662 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5663 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 5664 | usleep_range(1000, 2000); |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5665 | /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5666 | adapter->max_frame_size = max_frame; |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 5667 | e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
| 5668 | netdev->mtu = new_mtu; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5669 | if (netif_running(netdev)) |
| 5670 | e1000e_down(adapter); |
| 5671 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5672 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5673 | * means we reserve 2 more, this pushes us to allocate from the next |
| 5674 | * larger slab size. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5675 | * i.e. RXBUFFER_2048 --> size-4096 slab |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5676 | * However with the new *_jumbo_rx* routines, jumbo receives will use |
| 5677 | * fragmented skbs |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5678 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5679 | |
Jesse Brandeburg | 9926146 | 2010-01-22 22:56:16 +0000 | [diff] [blame] | 5680 | if (max_frame <= 2048) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5681 | adapter->rx_buffer_len = 2048; |
| 5682 | else |
| 5683 | adapter->rx_buffer_len = 4096; |
| 5684 | |
| 5685 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
| 5686 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || |
| 5687 | (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) |
| 5688 | adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5689 | + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5690 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5691 | if (netif_running(netdev)) |
| 5692 | e1000e_up(adapter); |
| 5693 | else |
| 5694 | e1000e_reset(adapter); |
| 5695 | |
| 5696 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 5697 | |
| 5698 | return 0; |
| 5699 | } |
| 5700 | |
| 5701 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 5702 | int cmd) |
| 5703 | { |
| 5704 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5705 | struct mii_ioctl_data *data = if_mii(ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5706 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5707 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5708 | return -EOPNOTSUPP; |
| 5709 | |
| 5710 | switch (cmd) { |
| 5711 | case SIOCGMIIPHY: |
| 5712 | data->phy_id = adapter->hw.phy.addr; |
| 5713 | break; |
| 5714 | case SIOCGMIIREG: |
Bruce Allan | b16a002 | 2009-11-20 23:24:30 +0000 | [diff] [blame] | 5715 | e1000_phy_read_status(adapter); |
| 5716 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5717 | switch (data->reg_num & 0x1F) { |
| 5718 | case MII_BMCR: |
| 5719 | data->val_out = adapter->phy_regs.bmcr; |
| 5720 | break; |
| 5721 | case MII_BMSR: |
| 5722 | data->val_out = adapter->phy_regs.bmsr; |
| 5723 | break; |
| 5724 | case MII_PHYSID1: |
| 5725 | data->val_out = (adapter->hw.phy.id >> 16); |
| 5726 | break; |
| 5727 | case MII_PHYSID2: |
| 5728 | data->val_out = (adapter->hw.phy.id & 0xFFFF); |
| 5729 | break; |
| 5730 | case MII_ADVERTISE: |
| 5731 | data->val_out = adapter->phy_regs.advertise; |
| 5732 | break; |
| 5733 | case MII_LPA: |
| 5734 | data->val_out = adapter->phy_regs.lpa; |
| 5735 | break; |
| 5736 | case MII_EXPANSION: |
| 5737 | data->val_out = adapter->phy_regs.expansion; |
| 5738 | break; |
| 5739 | case MII_CTRL1000: |
| 5740 | data->val_out = adapter->phy_regs.ctrl1000; |
| 5741 | break; |
| 5742 | case MII_STAT1000: |
| 5743 | data->val_out = adapter->phy_regs.stat1000; |
| 5744 | break; |
| 5745 | case MII_ESTATUS: |
| 5746 | data->val_out = adapter->phy_regs.estatus; |
| 5747 | break; |
| 5748 | default: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5749 | return -EIO; |
| 5750 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5751 | break; |
| 5752 | case SIOCSMIIREG: |
| 5753 | default: |
| 5754 | return -EOPNOTSUPP; |
| 5755 | } |
| 5756 | return 0; |
| 5757 | } |
| 5758 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5759 | /** |
| 5760 | * e1000e_hwtstamp_ioctl - control hardware time stamping |
| 5761 | * @netdev: network interface device structure |
| 5762 | * @ifreq: interface request |
| 5763 | * |
| 5764 | * Outgoing time stamping can be enabled and disabled. Play nice and |
| 5765 | * disable it when requested, although it shouldn't cause any overhead |
| 5766 | * when no packet needs it. At most one packet in the queue may be |
| 5767 | * marked for time stamping, otherwise it would be impossible to tell |
| 5768 | * for sure to which packet the hardware time stamp belongs. |
| 5769 | * |
| 5770 | * Incoming time stamping has to be configured via the hardware filters. |
| 5771 | * Not all combinations are supported, in particular event type has to be |
| 5772 | * specified. Matching the kind of event packet is not supported, with the |
| 5773 | * exception of "all V2 events regardless of level 2 or 4". |
| 5774 | **/ |
| 5775 | static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr) |
| 5776 | { |
| 5777 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5778 | struct hwtstamp_config config; |
| 5779 | int ret_val; |
| 5780 | |
| 5781 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) |
| 5782 | return -EFAULT; |
| 5783 | |
| 5784 | adapter->hwtstamp_config = config; |
| 5785 | |
| 5786 | ret_val = e1000e_config_hwtstamp(adapter); |
| 5787 | if (ret_val) |
| 5788 | return ret_val; |
| 5789 | |
| 5790 | config = adapter->hwtstamp_config; |
| 5791 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 5792 | switch (config.rx_filter) { |
| 5793 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 5794 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 5795 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 5796 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 5797 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 5798 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 5799 | /* With V2 type filters which specify a Sync or Delay Request, |
| 5800 | * Path Delay Request/Response messages are also time stamped |
| 5801 | * by hardware so notify the caller the requested packets plus |
| 5802 | * some others are time stamped. |
| 5803 | */ |
| 5804 | config.rx_filter = HWTSTAMP_FILTER_SOME; |
| 5805 | break; |
| 5806 | default: |
| 5807 | break; |
| 5808 | } |
| 5809 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5810 | return copy_to_user(ifr->ifr_data, &config, |
| 5811 | sizeof(config)) ? -EFAULT : 0; |
| 5812 | } |
| 5813 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5814 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 5815 | { |
| 5816 | switch (cmd) { |
| 5817 | case SIOCGMIIPHY: |
| 5818 | case SIOCGMIIREG: |
| 5819 | case SIOCSMIIREG: |
| 5820 | return e1000_mii_ioctl(netdev, ifr, cmd); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5821 | case SIOCSHWTSTAMP: |
| 5822 | return e1000e_hwtstamp_ioctl(netdev, ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5823 | default: |
| 5824 | return -EOPNOTSUPP; |
| 5825 | } |
| 5826 | } |
| 5827 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5828 | static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) |
| 5829 | { |
| 5830 | struct e1000_hw *hw = &adapter->hw; |
| 5831 | u32 i, mac_reg; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5832 | u16 phy_reg, wuc_enable; |
Bruce Allan | 70806a7 | 2013-01-05 05:08:37 +0000 | [diff] [blame] | 5833 | int retval; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5834 | |
| 5835 | /* copy MAC RARs to PHY RARs */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 5836 | e1000_copy_rx_addrs_to_phy_ich8lan(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5837 | |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5838 | retval = hw->phy.ops.acquire(hw); |
| 5839 | if (retval) { |
| 5840 | e_err("Could not acquire PHY\n"); |
| 5841 | return retval; |
| 5842 | } |
| 5843 | |
| 5844 | /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */ |
| 5845 | retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
| 5846 | if (retval) |
Bruce Allan | 75ce153 | 2012-02-08 02:54:48 +0000 | [diff] [blame] | 5847 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5848 | |
| 5849 | /* copy MAC MTA to PHY MTA - only needed for pchlan */ |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5850 | for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { |
| 5851 | mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5852 | hw->phy.ops.write_reg_page(hw, BM_MTA(i), |
| 5853 | (u16)(mac_reg & 0xFFFF)); |
| 5854 | hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1, |
| 5855 | (u16)((mac_reg >> 16) & 0xFFFF)); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5856 | } |
| 5857 | |
| 5858 | /* configure PHY Rx Control register */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5859 | hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5860 | mac_reg = er32(RCTL); |
| 5861 | if (mac_reg & E1000_RCTL_UPE) |
| 5862 | phy_reg |= BM_RCTL_UPE; |
| 5863 | if (mac_reg & E1000_RCTL_MPE) |
| 5864 | phy_reg |= BM_RCTL_MPE; |
| 5865 | phy_reg &= ~(BM_RCTL_MO_MASK); |
| 5866 | if (mac_reg & E1000_RCTL_MO_3) |
| 5867 | phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) |
| 5868 | << BM_RCTL_MO_SHIFT); |
| 5869 | if (mac_reg & E1000_RCTL_BAM) |
| 5870 | phy_reg |= BM_RCTL_BAM; |
| 5871 | if (mac_reg & E1000_RCTL_PMCF) |
| 5872 | phy_reg |= BM_RCTL_PMCF; |
| 5873 | mac_reg = er32(CTRL); |
| 5874 | if (mac_reg & E1000_CTRL_RFCE) |
| 5875 | phy_reg |= BM_RCTL_RFCE; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5876 | hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5877 | |
| 5878 | /* enable PHY wakeup in MAC register */ |
| 5879 | ew32(WUFC, wufc); |
| 5880 | ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN); |
| 5881 | |
| 5882 | /* configure and enable PHY wakeup in PHY registers */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5883 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc); |
| 5884 | 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] | 5885 | |
| 5886 | /* activate PHY wakeup */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 5887 | wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; |
| 5888 | retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5889 | if (retval) |
| 5890 | e_err("Could not set PHY Host Wakeup bit\n"); |
Bruce Allan | 75ce153 | 2012-02-08 02:54:48 +0000 | [diff] [blame] | 5891 | release: |
Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 5892 | hw->phy.ops.release(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5893 | |
| 5894 | return retval; |
| 5895 | } |
| 5896 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5897 | static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake, |
| 5898 | bool runtime) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5899 | { |
| 5900 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5901 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5902 | struct e1000_hw *hw = &adapter->hw; |
| 5903 | u32 ctrl, ctrl_ext, rctl, status; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5904 | /* Runtime suspend should only enable wakeup for link changes */ |
| 5905 | u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5906 | int retval = 0; |
| 5907 | |
| 5908 | netif_device_detach(netdev); |
| 5909 | |
| 5910 | if (netif_running(netdev)) { |
Bruce Allan | bb9e44d | 2012-03-21 00:39:12 +0000 | [diff] [blame] | 5911 | int count = E1000_CHECK_RESET_COUNT; |
| 5912 | |
| 5913 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) |
| 5914 | usleep_range(10000, 20000); |
| 5915 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5916 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 5917 | e1000e_down(adapter); |
| 5918 | e1000_free_irq(adapter); |
| 5919 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5920 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5921 | |
| 5922 | retval = pci_save_state(pdev); |
| 5923 | if (retval) |
| 5924 | return retval; |
| 5925 | |
| 5926 | status = er32(STATUS); |
| 5927 | if (status & E1000_STATUS_LU) |
| 5928 | wufc &= ~E1000_WUFC_LNKC; |
| 5929 | |
| 5930 | if (wufc) { |
| 5931 | e1000_setup_rctl(adapter); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 5932 | e1000e_set_rx_mode(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5933 | |
| 5934 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5935 | if (wufc & E1000_WUFC_MC) { |
| 5936 | rctl = er32(RCTL); |
| 5937 | rctl |= E1000_RCTL_MPE; |
| 5938 | ew32(RCTL, rctl); |
| 5939 | } |
| 5940 | |
| 5941 | ctrl = er32(CTRL); |
| 5942 | /* advertise wake from D3Cold */ |
| 5943 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5944 | /* phy power management enable */ |
| 5945 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5946 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 5947 | if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) |
| 5948 | ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5949 | ew32(CTRL, ctrl); |
| 5950 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5951 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
| 5952 | adapter->hw.phy.media_type == |
| 5953 | e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5954 | /* keep the laser running in D3 */ |
| 5955 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | 93a23f4 | 2009-12-08 07:27:41 +0000 | [diff] [blame] | 5956 | ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5957 | ew32(CTRL_EXT, ctrl_ext); |
| 5958 | } |
| 5959 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5960 | if (adapter->flags & FLAG_IS_ICH) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 5961 | e1000_suspend_workarounds_ich8lan(&adapter->hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 5962 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5963 | /* Allow time for pending master requests to run */ |
| 5964 | e1000e_disable_pcie_master(&adapter->hw); |
| 5965 | |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5966 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 5967 | /* enable wakeup by the PHY */ |
| 5968 | retval = e1000_init_phy_wakeup(adapter, wufc); |
| 5969 | if (retval) |
| 5970 | return retval; |
| 5971 | } else { |
| 5972 | /* enable wakeup by the MAC */ |
| 5973 | ew32(WUFC, wufc); |
| 5974 | ew32(WUC, E1000_WUC_PME_EN); |
| 5975 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5976 | } else { |
| 5977 | ew32(WUC, 0); |
| 5978 | ew32(WUFC, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5979 | } |
| 5980 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5981 | *enable_wake = !!wufc; |
| 5982 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5983 | /* make sure adapter isn't asleep if manageability is enabled */ |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 5984 | if ((adapter->flags & FLAG_MNG_PT_ENABLED) || |
| 5985 | (hw->mac.ops.check_mng_mode(hw))) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5986 | *enable_wake = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5987 | |
| 5988 | if (adapter->hw.phy.type == e1000_phy_igp_3) |
| 5989 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
| 5990 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5991 | /* 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] | 5992 | * would have already happened in close and is redundant. |
| 5993 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 5994 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5995 | |
| 5996 | pci_disable_device(pdev); |
| 5997 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 5998 | return 0; |
| 5999 | } |
| 6000 | |
| 6001 | static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake) |
| 6002 | { |
| 6003 | if (sleep && wake) { |
| 6004 | pci_prepare_to_sleep(pdev); |
| 6005 | return; |
| 6006 | } |
| 6007 | |
| 6008 | pci_wake_from_d3(pdev, wake); |
| 6009 | pci_set_power_state(pdev, PCI_D3hot); |
| 6010 | } |
| 6011 | |
| 6012 | static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, |
| 6013 | bool wake) |
| 6014 | { |
| 6015 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6016 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6017 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6018 | /* The pci-e switch on some quad port adapters will report a |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6019 | * correctable error when the MAC transitions from D0 to D3. To |
| 6020 | * prevent this we need to mask off the correctable errors on the |
| 6021 | * downstream port of the pci-e switch. |
| 6022 | */ |
| 6023 | if (adapter->flags & FLAG_IS_QUAD_PORT) { |
| 6024 | struct pci_dev *us_dev = pdev->bus->self; |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6025 | u16 devctl; |
| 6026 | |
Jiang Liu | f8c0fca | 2012-08-20 13:30:43 -0600 | [diff] [blame] | 6027 | pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl); |
| 6028 | pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, |
| 6029 | (devctl & ~PCI_EXP_DEVCTL_CERE)); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6030 | |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6031 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6032 | |
Jiang Liu | f8c0fca | 2012-08-20 13:30:43 -0600 | [diff] [blame] | 6033 | pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6034 | } else { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6035 | e1000_power_off(pdev, sleep, wake); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6036 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6037 | } |
| 6038 | |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6039 | #ifdef CONFIG_PCIEASPM |
| 6040 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
| 6041 | { |
Yinghai Lu | 9f728f5 | 2011-05-12 17:11:47 -0700 | [diff] [blame] | 6042 | pci_disable_link_state_locked(pdev, state); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6043 | } |
| 6044 | #else |
| 6045 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 6046 | { |
Bjorn Helgaas | ffe0b2ff | 2012-12-06 06:40:07 +0000 | [diff] [blame] | 6047 | u16 aspm_ctl = 0; |
| 6048 | |
| 6049 | if (state & PCIE_LINK_STATE_L0S) |
| 6050 | aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S; |
| 6051 | if (state & PCIE_LINK_STATE_L1) |
| 6052 | aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1; |
| 6053 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6054 | /* Both device and parent should have the same ASPM setting. |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6055 | * Disable ASPM in downstream component first and then upstream. |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 6056 | */ |
Bjorn Helgaas | ffe0b2ff | 2012-12-06 06:40:07 +0000 | [diff] [blame] | 6057 | pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6058 | |
Jiang Liu | f8c0fca | 2012-08-20 13:30:43 -0600 | [diff] [blame] | 6059 | if (pdev->bus->self) |
| 6060 | pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL, |
Bjorn Helgaas | ffe0b2ff | 2012-12-06 06:40:07 +0000 | [diff] [blame] | 6061 | aspm_ctl); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6062 | } |
| 6063 | #endif |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6064 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6065 | { |
| 6066 | dev_info(&pdev->dev, "Disabling ASPM %s %s\n", |
| 6067 | (state & PCIE_LINK_STATE_L0S) ? "L0s" : "", |
| 6068 | (state & PCIE_LINK_STATE_L1) ? "L1" : ""); |
| 6069 | |
| 6070 | __e1000e_disable_aspm(pdev, state); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 6071 | } |
| 6072 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6073 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6074 | static bool e1000e_pm_ready(struct e1000_adapter *adapter) |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6075 | { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6076 | return !!adapter->tx_ring->buffer_info; |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6077 | } |
| 6078 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6079 | static int __e1000_resume(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6080 | { |
| 6081 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6082 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6083 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6084 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6085 | u32 err; |
| 6086 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6087 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 6088 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
| 6089 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
| 6090 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 6091 | if (aspm_disable_flag) |
| 6092 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 6093 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6094 | pci_set_power_state(pdev, PCI_D0); |
| 6095 | pci_restore_state(pdev); |
Bruce Allan | 28b8f04 | 2010-01-07 16:30:56 +0000 | [diff] [blame] | 6096 | pci_save_state(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6097 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6098 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6099 | if (netif_running(netdev)) { |
| 6100 | err = e1000_request_irq(adapter); |
| 6101 | if (err) |
| 6102 | return err; |
| 6103 | } |
| 6104 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 6105 | if (hw->mac.type >= e1000_pch2lan) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 6106 | e1000_resume_workarounds_pchlan(&adapter->hw); |
| 6107 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6108 | e1000e_power_up_phy(adapter); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6109 | |
| 6110 | /* report the system wakeup cause from S3/S4 */ |
| 6111 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
| 6112 | u16 phy_data; |
| 6113 | |
| 6114 | e1e_rphy(&adapter->hw, BM_WUS, &phy_data); |
| 6115 | if (phy_data) { |
| 6116 | e_info("PHY Wakeup cause - %s\n", |
| 6117 | phy_data & E1000_WUS_EX ? "Unicast Packet" : |
| 6118 | phy_data & E1000_WUS_MC ? "Multicast Packet" : |
| 6119 | phy_data & E1000_WUS_BC ? "Broadcast Packet" : |
| 6120 | phy_data & E1000_WUS_MAG ? "Magic Packet" : |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 6121 | phy_data & E1000_WUS_LNKC ? |
| 6122 | "Link Status Change" : "other"); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6123 | } |
| 6124 | e1e_wphy(&adapter->hw, BM_WUS, ~0); |
| 6125 | } else { |
| 6126 | u32 wus = er32(WUS); |
| 6127 | if (wus) { |
| 6128 | e_info("MAC Wakeup cause - %s\n", |
| 6129 | wus & E1000_WUS_EX ? "Unicast Packet" : |
| 6130 | wus & E1000_WUS_MC ? "Multicast Packet" : |
| 6131 | wus & E1000_WUS_BC ? "Broadcast Packet" : |
| 6132 | wus & E1000_WUS_MAG ? "Magic Packet" : |
| 6133 | wus & E1000_WUS_LNKC ? "Link Status Change" : |
| 6134 | "other"); |
| 6135 | } |
| 6136 | ew32(WUS, ~0); |
| 6137 | } |
| 6138 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6139 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6140 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 6141 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6142 | |
| 6143 | if (netif_running(netdev)) |
| 6144 | e1000e_up(adapter); |
| 6145 | |
| 6146 | netif_device_attach(netdev); |
| 6147 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6148 | /* 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] | 6149 | * 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] | 6150 | * under the control of the driver. |
| 6151 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6152 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6153 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6154 | |
| 6155 | return 0; |
| 6156 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6157 | |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6158 | #ifdef CONFIG_PM_SLEEP |
| 6159 | static int e1000_suspend(struct device *dev) |
| 6160 | { |
| 6161 | struct pci_dev *pdev = to_pci_dev(dev); |
| 6162 | int retval; |
| 6163 | bool wake; |
| 6164 | |
| 6165 | retval = __e1000_shutdown(pdev, &wake, false); |
| 6166 | if (!retval) |
| 6167 | e1000_complete_shutdown(pdev, true, wake); |
| 6168 | |
| 6169 | return retval; |
| 6170 | } |
| 6171 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6172 | static int e1000_resume(struct device *dev) |
| 6173 | { |
| 6174 | struct pci_dev *pdev = to_pci_dev(dev); |
| 6175 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6176 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6177 | |
| 6178 | if (e1000e_pm_ready(adapter)) |
| 6179 | adapter->idle_check = true; |
| 6180 | |
| 6181 | return __e1000_resume(pdev); |
| 6182 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6183 | #endif /* CONFIG_PM_SLEEP */ |
| 6184 | |
| 6185 | #ifdef CONFIG_PM_RUNTIME |
| 6186 | static int e1000_runtime_suspend(struct device *dev) |
| 6187 | { |
| 6188 | struct pci_dev *pdev = to_pci_dev(dev); |
| 6189 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6190 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6191 | |
| 6192 | if (e1000e_pm_ready(adapter)) { |
| 6193 | bool wake; |
| 6194 | |
| 6195 | __e1000_shutdown(pdev, &wake, true); |
| 6196 | } |
| 6197 | |
| 6198 | return 0; |
| 6199 | } |
| 6200 | |
| 6201 | static int e1000_idle(struct device *dev) |
| 6202 | { |
| 6203 | struct pci_dev *pdev = to_pci_dev(dev); |
| 6204 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6205 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6206 | |
| 6207 | if (!e1000e_pm_ready(adapter)) |
| 6208 | return 0; |
| 6209 | |
| 6210 | if (adapter->idle_check) { |
| 6211 | adapter->idle_check = false; |
| 6212 | if (!e1000e_has_link(adapter)) |
| 6213 | pm_schedule_suspend(dev, MSEC_PER_SEC); |
| 6214 | } |
| 6215 | |
| 6216 | return -EBUSY; |
| 6217 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6218 | |
| 6219 | static int e1000_runtime_resume(struct device *dev) |
| 6220 | { |
| 6221 | struct pci_dev *pdev = to_pci_dev(dev); |
| 6222 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6223 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6224 | |
| 6225 | if (!e1000e_pm_ready(adapter)) |
| 6226 | return 0; |
| 6227 | |
| 6228 | adapter->idle_check = !dev->power.runtime_auto; |
| 6229 | return __e1000_resume(pdev); |
| 6230 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6231 | #endif /* CONFIG_PM_RUNTIME */ |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6232 | #endif /* CONFIG_PM */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6233 | |
| 6234 | static void e1000_shutdown(struct pci_dev *pdev) |
| 6235 | { |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6236 | bool wake = false; |
| 6237 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6238 | __e1000_shutdown(pdev, &wake, false); |
Rafael J. Wysocki | 4f9de72 | 2009-04-15 17:43:43 +0000 | [diff] [blame] | 6239 | |
| 6240 | if (system_state == SYSTEM_POWER_OFF) |
| 6241 | e1000_complete_shutdown(pdev, false, wake); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 6245 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 6246 | static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data) |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 6247 | { |
| 6248 | struct net_device *netdev = data; |
| 6249 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 6250 | |
| 6251 | if (adapter->msix_entries) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 6252 | int vector, msix_irq; |
| 6253 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 6254 | vector = 0; |
| 6255 | msix_irq = adapter->msix_entries[vector].vector; |
| 6256 | disable_irq(msix_irq); |
| 6257 | e1000_intr_msix_rx(msix_irq, netdev); |
| 6258 | enable_irq(msix_irq); |
| 6259 | |
| 6260 | vector++; |
| 6261 | msix_irq = adapter->msix_entries[vector].vector; |
| 6262 | disable_irq(msix_irq); |
| 6263 | e1000_intr_msix_tx(msix_irq, netdev); |
| 6264 | enable_irq(msix_irq); |
| 6265 | |
| 6266 | vector++; |
| 6267 | msix_irq = adapter->msix_entries[vector].vector; |
| 6268 | disable_irq(msix_irq); |
| 6269 | e1000_msix_other(msix_irq, netdev); |
| 6270 | enable_irq(msix_irq); |
| 6271 | } |
| 6272 | |
| 6273 | return IRQ_HANDLED; |
| 6274 | } |
| 6275 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6276 | /** |
| 6277 | * e1000_netpoll |
| 6278 | * @netdev: network interface device structure |
| 6279 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6280 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 6281 | * without having to re-enable interrupts. It's not called while |
| 6282 | * the interrupt routine is executing. |
| 6283 | */ |
| 6284 | static void e1000_netpoll(struct net_device *netdev) |
| 6285 | { |
| 6286 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6287 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 6288 | switch (adapter->int_mode) { |
| 6289 | case E1000E_INT_MODE_MSIX: |
| 6290 | e1000_intr_msix(adapter->pdev->irq, netdev); |
| 6291 | break; |
| 6292 | case E1000E_INT_MODE_MSI: |
| 6293 | disable_irq(adapter->pdev->irq); |
| 6294 | e1000_intr_msi(adapter->pdev->irq, netdev); |
| 6295 | enable_irq(adapter->pdev->irq); |
| 6296 | break; |
| 6297 | default: /* E1000E_INT_MODE_LEGACY */ |
| 6298 | disable_irq(adapter->pdev->irq); |
| 6299 | e1000_intr(adapter->pdev->irq, netdev); |
| 6300 | enable_irq(adapter->pdev->irq); |
| 6301 | break; |
| 6302 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6303 | } |
| 6304 | #endif |
| 6305 | |
| 6306 | /** |
| 6307 | * e1000_io_error_detected - called when PCI error is detected |
| 6308 | * @pdev: Pointer to PCI device |
| 6309 | * @state: The current pci connection state |
| 6310 | * |
| 6311 | * This function is called after a PCI bus error affecting |
| 6312 | * this device has been detected. |
| 6313 | */ |
| 6314 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 6315 | pci_channel_state_t state) |
| 6316 | { |
| 6317 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6318 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6319 | |
| 6320 | netif_device_detach(netdev); |
| 6321 | |
Mike Mason | c93b5a7 | 2009-06-30 12:45:53 +0000 | [diff] [blame] | 6322 | if (state == pci_channel_io_perm_failure) |
| 6323 | return PCI_ERS_RESULT_DISCONNECT; |
| 6324 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6325 | if (netif_running(netdev)) |
| 6326 | e1000e_down(adapter); |
| 6327 | pci_disable_device(pdev); |
| 6328 | |
| 6329 | /* Request a slot slot reset. */ |
| 6330 | return PCI_ERS_RESULT_NEED_RESET; |
| 6331 | } |
| 6332 | |
| 6333 | /** |
| 6334 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 6335 | * @pdev: Pointer to PCI device |
| 6336 | * |
| 6337 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 6338 | * resembles the first-half of the e1000_resume routine. |
| 6339 | */ |
| 6340 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 6341 | { |
| 6342 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6343 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6344 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6345 | u16 aspm_disable_flag = 0; |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6346 | int err; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6347 | pci_ers_result_t result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6348 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6349 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 6350 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6351 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6352 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 6353 | if (aspm_disable_flag) |
| 6354 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
| 6355 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6356 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6357 | if (err) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6358 | dev_err(&pdev->dev, |
| 6359 | "Cannot re-enable PCI device after reset.\n"); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6360 | result = PCI_ERS_RESULT_DISCONNECT; |
| 6361 | } else { |
| 6362 | pci_set_master(pdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6363 | pdev->state_saved = true; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6364 | pci_restore_state(pdev); |
| 6365 | |
| 6366 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 6367 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 6368 | |
| 6369 | e1000e_reset(adapter); |
| 6370 | ew32(WUS, ~0); |
| 6371 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6372 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6373 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6374 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6375 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6376 | return result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | /** |
| 6380 | * e1000_io_resume - called when traffic can start flowing again. |
| 6381 | * @pdev: Pointer to PCI device |
| 6382 | * |
| 6383 | * This callback is called when the error recovery driver tells us that |
| 6384 | * its OK to resume normal operation. Implementation resembles the |
| 6385 | * second-half of the e1000_resume routine. |
| 6386 | */ |
| 6387 | static void e1000_io_resume(struct pci_dev *pdev) |
| 6388 | { |
| 6389 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6390 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6391 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 6392 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6393 | |
| 6394 | if (netif_running(netdev)) { |
| 6395 | if (e1000e_up(adapter)) { |
| 6396 | dev_err(&pdev->dev, |
| 6397 | "can't bring device back up after reset\n"); |
| 6398 | return; |
| 6399 | } |
| 6400 | } |
| 6401 | |
| 6402 | netif_device_attach(netdev); |
| 6403 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6404 | /* 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] | 6405 | * 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] | 6406 | * under the control of the driver. |
| 6407 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6408 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6409 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6410 | |
| 6411 | } |
| 6412 | |
| 6413 | static void e1000_print_device_info(struct e1000_adapter *adapter) |
| 6414 | { |
| 6415 | struct e1000_hw *hw = &adapter->hw; |
| 6416 | struct net_device *netdev = adapter->netdev; |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 6417 | u32 ret_val; |
| 6418 | u8 pba_str[E1000_PBANUM_LENGTH]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6419 | |
| 6420 | /* print bus type/speed/width info */ |
Bruce Allan | a5cc764 | 2011-03-19 00:31:23 +0000 | [diff] [blame] | 6421 | e_info("(PCI Express:2.5GT/s:%s) %pM\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6422 | /* bus width */ |
| 6423 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
| 6424 | "Width x1"), |
| 6425 | /* MAC address */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 6426 | netdev->dev_addr); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 6427 | e_info("Intel(R) PRO/%s Network Connection\n", |
| 6428 | (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 6429 | ret_val = e1000_read_pba_string_generic(hw, pba_str, |
| 6430 | E1000_PBANUM_LENGTH); |
| 6431 | if (ret_val) |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 6432 | strlcpy((char *)pba_str, "Unknown", sizeof(pba_str)); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 6433 | e_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 6434 | hw->mac.type, hw->phy.type, pba_str); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6435 | } |
| 6436 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6437 | static void e1000_eeprom_checks(struct e1000_adapter *adapter) |
| 6438 | { |
| 6439 | struct e1000_hw *hw = &adapter->hw; |
| 6440 | int ret_val; |
| 6441 | u16 buf = 0; |
| 6442 | |
| 6443 | if (hw->mac.type != e1000_82573) |
| 6444 | return; |
| 6445 | |
| 6446 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 6447 | le16_to_cpus(&buf); |
| 6448 | if (!ret_val && (!(buf & (1 << 0)))) { |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6449 | /* Deep Smart Power Down (DSPD) */ |
Frans Pop | 6c2a9ef | 2008-09-22 14:52:22 -0700 | [diff] [blame] | 6450 | dev_warn(&adapter->pdev->dev, |
| 6451 | "Warning: detected DSPD enabled in EEPROM\n"); |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6452 | } |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6453 | } |
| 6454 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 6455 | static int e1000_set_features(struct net_device *netdev, |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 6456 | netdev_features_t features) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6457 | { |
| 6458 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 6459 | netdev_features_t changed = features ^ netdev->features; |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6460 | |
| 6461 | if (changed & (NETIF_F_TSO | NETIF_F_TSO6)) |
| 6462 | adapter->flags |= FLAG_TSO_FORCE; |
| 6463 | |
| 6464 | if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 6465 | NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS | |
| 6466 | NETIF_F_RXALL))) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6467 | return 0; |
| 6468 | |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 6469 | if (changed & NETIF_F_RXFCS) { |
| 6470 | if (features & NETIF_F_RXFCS) { |
| 6471 | adapter->flags2 &= ~FLAG2_CRC_STRIPPING; |
| 6472 | } else { |
| 6473 | /* We need to take it back to defaults, which might mean |
| 6474 | * stripping is still disabled at the adapter level. |
| 6475 | */ |
| 6476 | if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING) |
| 6477 | adapter->flags2 |= FLAG2_CRC_STRIPPING; |
| 6478 | else |
| 6479 | adapter->flags2 &= ~FLAG2_CRC_STRIPPING; |
| 6480 | } |
| 6481 | } |
| 6482 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 6483 | netdev->features = features; |
| 6484 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6485 | if (netif_running(netdev)) |
| 6486 | e1000e_reinit_locked(adapter); |
| 6487 | else |
| 6488 | e1000e_reset(adapter); |
| 6489 | |
| 6490 | return 0; |
| 6491 | } |
| 6492 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6493 | static const struct net_device_ops e1000e_netdev_ops = { |
| 6494 | .ndo_open = e1000_open, |
| 6495 | .ndo_stop = e1000_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 6496 | .ndo_start_xmit = e1000_xmit_frame, |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6497 | .ndo_get_stats64 = e1000e_get_stats64, |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 6498 | .ndo_set_rx_mode = e1000e_set_rx_mode, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6499 | .ndo_set_mac_address = e1000_set_mac, |
| 6500 | .ndo_change_mtu = e1000_change_mtu, |
| 6501 | .ndo_do_ioctl = e1000_ioctl, |
| 6502 | .ndo_tx_timeout = e1000_tx_timeout, |
| 6503 | .ndo_validate_addr = eth_validate_addr, |
| 6504 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6505 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 6506 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 6507 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6508 | .ndo_poll_controller = e1000_netpoll, |
| 6509 | #endif |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6510 | .ndo_set_features = e1000_set_features, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6511 | }; |
| 6512 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6513 | /** |
| 6514 | * e1000_probe - Device Initialization Routine |
| 6515 | * @pdev: PCI device information struct |
| 6516 | * @ent: entry in e1000_pci_tbl |
| 6517 | * |
| 6518 | * Returns 0 on success, negative on failure |
| 6519 | * |
| 6520 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 6521 | * The OS initialization, configuring of the adapter private structure, |
| 6522 | * and a hardware reset occur. |
| 6523 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 6524 | 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] | 6525 | { |
| 6526 | struct net_device *netdev; |
| 6527 | struct e1000_adapter *adapter; |
| 6528 | struct e1000_hw *hw; |
| 6529 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; |
Becky Bruce | f47e81f | 2008-05-01 18:03:11 -0500 | [diff] [blame] | 6530 | resource_size_t mmio_start, mmio_len; |
| 6531 | resource_size_t flash_start, flash_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6532 | static int cards_found; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6533 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6534 | int i, err, pci_using_dac; |
| 6535 | u16 eeprom_data = 0; |
| 6536 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
| 6537 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6538 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 6539 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6540 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6541 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 6542 | if (aspm_disable_flag) |
| 6543 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6544 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6545 | err = pci_enable_device_mem(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6546 | if (err) |
| 6547 | return err; |
| 6548 | |
| 6549 | pci_using_dac = 0; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6550 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6551 | if (!err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6552 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6553 | if (!err) |
| 6554 | pci_using_dac = 1; |
| 6555 | } else { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6556 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6557 | if (err) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 6558 | err = dma_set_coherent_mask(&pdev->dev, |
| 6559 | DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6560 | if (err) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 6561 | dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6562 | goto err_dma; |
| 6563 | } |
| 6564 | } |
| 6565 | } |
| 6566 | |
Arjan van de Ven | e8de148 | 2008-10-22 19:55:31 -0700 | [diff] [blame] | 6567 | err = pci_request_selected_regions_exclusive(pdev, |
Bruce Allan | 55c5f55 | 2013-01-12 07:28:24 +0000 | [diff] [blame] | 6568 | pci_select_bars(pdev, IORESOURCE_MEM), |
| 6569 | e1000e_driver_name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6570 | if (err) |
| 6571 | goto err_pci_reg; |
| 6572 | |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 6573 | /* AER (Advanced Error Reporting) hooks */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6574 | pci_enable_pcie_error_reporting(pdev); |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 6575 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6576 | pci_set_master(pdev); |
Bruce Allan | 438b365 | 2008-11-21 16:51:33 -0800 | [diff] [blame] | 6577 | /* PCI config space info */ |
| 6578 | err = pci_save_state(pdev); |
| 6579 | if (err) |
| 6580 | goto err_alloc_etherdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6581 | |
| 6582 | err = -ENOMEM; |
| 6583 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
| 6584 | if (!netdev) |
| 6585 | goto err_alloc_etherdev; |
| 6586 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6587 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 6588 | |
Tom Herbert | f85e4df | 2010-05-05 14:03:32 +0000 | [diff] [blame] | 6589 | netdev->irq = pdev->irq; |
| 6590 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6591 | pci_set_drvdata(pdev, netdev); |
| 6592 | adapter = netdev_priv(netdev); |
| 6593 | hw = &adapter->hw; |
| 6594 | adapter->netdev = netdev; |
| 6595 | adapter->pdev = pdev; |
| 6596 | adapter->ei = ei; |
| 6597 | adapter->pba = ei->pba; |
| 6598 | adapter->flags = ei->flags; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 6599 | adapter->flags2 = ei->flags2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6600 | adapter->hw.adapter = adapter; |
| 6601 | adapter->hw.mac.type = ei->mac; |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 6602 | adapter->max_hw_frame_size = ei->max_hw_frame_size; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 6603 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6604 | |
| 6605 | mmio_start = pci_resource_start(pdev, 0); |
| 6606 | mmio_len = pci_resource_len(pdev, 0); |
| 6607 | |
| 6608 | err = -EIO; |
| 6609 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 6610 | if (!adapter->hw.hw_addr) |
| 6611 | goto err_ioremap; |
| 6612 | |
| 6613 | if ((adapter->flags & FLAG_HAS_FLASH) && |
| 6614 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
| 6615 | flash_start = pci_resource_start(pdev, 1); |
| 6616 | flash_len = pci_resource_len(pdev, 1); |
| 6617 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
| 6618 | if (!adapter->hw.flash_address) |
| 6619 | goto err_flashmap; |
| 6620 | } |
| 6621 | |
| 6622 | /* construct the net_device struct */ |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 6623 | netdev->netdev_ops = &e1000e_netdev_ops; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6624 | e1000e_set_ethtool_ops(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6625 | netdev->watchdog_timeo = 5 * HZ; |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 6626 | netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64); |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 6627 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6628 | |
| 6629 | netdev->mem_start = mmio_start; |
| 6630 | netdev->mem_end = mmio_start + mmio_len; |
| 6631 | |
| 6632 | adapter->bd_number = cards_found++; |
| 6633 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6634 | e1000e_check_options(adapter); |
| 6635 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6636 | /* setup adapter struct */ |
| 6637 | err = e1000_sw_init(adapter); |
| 6638 | if (err) |
| 6639 | goto err_sw_init; |
| 6640 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6641 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 6642 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 6643 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 6644 | |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 6645 | err = ei->get_variants(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6646 | if (err) |
| 6647 | goto err_hw_init; |
| 6648 | |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 6649 | if ((adapter->flags & FLAG_IS_ICH) && |
| 6650 | (adapter->flags & FLAG_READ_ONLY_NVM)) |
| 6651 | e1000e_write_protect_nvm_ich8lan(&adapter->hw); |
| 6652 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6653 | hw->mac.ops.get_bus_info(&adapter->hw); |
| 6654 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6655 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6656 | |
| 6657 | /* Copper options */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6658 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6659 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
| 6660 | adapter->hw.phy.disable_polarity_correction = 0; |
| 6661 | adapter->hw.phy.ms_type = e1000_ms_hw_default; |
| 6662 | } |
| 6663 | |
Bruce Allan | 470a542 | 2012-05-26 06:08:48 +0000 | [diff] [blame] | 6664 | 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] | 6665 | dev_info(&pdev->dev, |
| 6666 | "PHY reset is blocked due to SOL/IDER session.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6667 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6668 | /* Set initial default active device features */ |
| 6669 | netdev->features = (NETIF_F_SG | |
| 6670 | NETIF_F_HW_VLAN_RX | |
| 6671 | NETIF_F_HW_VLAN_TX | |
| 6672 | NETIF_F_TSO | |
| 6673 | NETIF_F_TSO6 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 6674 | NETIF_F_RXHASH | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6675 | NETIF_F_RXCSUM | |
| 6676 | NETIF_F_HW_CSUM); |
| 6677 | |
| 6678 | /* Set user-changeable features (subset of all device features) */ |
| 6679 | netdev->hw_features = netdev->features; |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 6680 | netdev->hw_features |= NETIF_F_RXFCS; |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 6681 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 6682 | netdev->hw_features |= NETIF_F_RXALL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6683 | |
| 6684 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
| 6685 | netdev->features |= NETIF_F_HW_VLAN_FILTER; |
| 6686 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 6687 | netdev->vlan_features |= (NETIF_F_SG | |
| 6688 | NETIF_F_TSO | |
| 6689 | NETIF_F_TSO6 | |
| 6690 | NETIF_F_HW_CSUM); |
Jeff Kirsher | a5136e2 | 2008-06-05 04:07:28 -0700 | [diff] [blame] | 6691 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 6692 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 6693 | |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 6694 | if (pci_using_dac) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6695 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 6696 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 6697 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6698 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6699 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
| 6700 | adapter->flags |= FLAG_MNG_PT_ENABLED; |
| 6701 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6702 | /* before reading the NVM, reset the controller to |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6703 | * put the device in a known good starting state |
| 6704 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6705 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 6706 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6707 | /* 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] | 6708 | * attempt. Let's give it a few tries |
| 6709 | */ |
| 6710 | for (i = 0;; i++) { |
| 6711 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) |
| 6712 | break; |
| 6713 | if (i == 2) { |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 6714 | dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6715 | err = -EIO; |
| 6716 | goto err_eeprom; |
| 6717 | } |
| 6718 | } |
| 6719 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 6720 | e1000_eeprom_checks(adapter); |
| 6721 | |
Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 6722 | /* copy the MAC address */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6723 | if (e1000e_read_mac_addr(&adapter->hw)) |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 6724 | dev_err(&pdev->dev, |
| 6725 | "NVM Read Error while reading MAC address\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6726 | |
| 6727 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6728 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 6729 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 6730 | dev_err(&pdev->dev, "Invalid MAC Address: %pM\n", |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 6731 | netdev->dev_addr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6732 | err = -EIO; |
| 6733 | goto err_eeprom; |
| 6734 | } |
| 6735 | |
| 6736 | init_timer(&adapter->watchdog_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6737 | adapter->watchdog_timer.function = e1000_watchdog; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6738 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 6739 | |
| 6740 | init_timer(&adapter->phy_info_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 6741 | adapter->phy_info_timer.function = e1000_update_phy_info; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6742 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 6743 | |
| 6744 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
| 6745 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 6746 | INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); |
| 6747 | INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6748 | INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6749 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6750 | /* Initialize link parameters. User can change them with ethtool */ |
| 6751 | adapter->hw.mac.autoneg = 1; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6752 | adapter->fc_autoneg = true; |
Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 6753 | adapter->hw.fc.requested_mode = e1000_fc_default; |
| 6754 | adapter->hw.fc.current_mode = e1000_fc_default; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6755 | adapter->hw.phy.autoneg_advertised = 0x2f; |
| 6756 | |
| 6757 | /* ring size defaults */ |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 6758 | adapter->rx_ring->count = E1000_DEFAULT_RXD; |
| 6759 | adapter->tx_ring->count = E1000_DEFAULT_TXD; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6760 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6761 | /* Initial Wake on LAN setting - If APM wake is enabled in |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6762 | * the EEPROM, enable the ACPI Magic Packet filter |
| 6763 | */ |
| 6764 | if (adapter->flags & FLAG_APME_IN_WUC) { |
| 6765 | /* APME bit in EEPROM is mapped to WUC.APME */ |
| 6766 | eeprom_data = er32(WUC); |
| 6767 | eeprom_apme_mask = E1000_WUC_APME; |
Bruce Allan | 4def99b | 2011-02-02 09:30:36 +0000 | [diff] [blame] | 6768 | if ((hw->mac.type > e1000_ich10lan) && |
| 6769 | (eeprom_data & E1000_WUC_PHY_WAKE)) |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6770 | adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6771 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
| 6772 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && |
| 6773 | (adapter->hw.bus.func == 1)) |
Bruce Allan | 3d3a167 | 2012-02-23 03:13:18 +0000 | [diff] [blame] | 6774 | e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B, |
| 6775 | 1, &eeprom_data); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6776 | else |
Bruce Allan | 3d3a167 | 2012-02-23 03:13:18 +0000 | [diff] [blame] | 6777 | e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A, |
| 6778 | 1, &eeprom_data); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | /* fetch WoL from EEPROM */ |
| 6782 | if (eeprom_data & eeprom_apme_mask) |
| 6783 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 6784 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6785 | /* now that we have the eeprom settings, apply the special cases |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6786 | * where the eeprom may be wrong or the board simply won't support |
| 6787 | * wake on lan on a particular port |
| 6788 | */ |
| 6789 | if (!(adapter->flags & FLAG_HAS_WOL)) |
| 6790 | adapter->eeprom_wol = 0; |
| 6791 | |
| 6792 | /* initialize the wol settings based on the eeprom settings */ |
| 6793 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | 6ff6802 | 2008-11-12 09:52:32 +0000 | [diff] [blame] | 6794 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6795 | |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 6796 | /* save off EEPROM version number */ |
| 6797 | e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); |
| 6798 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6799 | /* reset the hardware with the new settings */ |
| 6800 | e1000e_reset(adapter); |
| 6801 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6802 | /* 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] | 6803 | * 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] | 6804 | * under the control of the driver. |
| 6805 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6806 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6807 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6808 | |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 6809 | strlcpy(netdev->name, "eth%d", sizeof(netdev->name)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6810 | err = register_netdev(netdev); |
| 6811 | if (err) |
| 6812 | goto err_register; |
| 6813 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 6814 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 6815 | netif_carrier_off(netdev); |
| 6816 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 6817 | /* init PTP hardware clock */ |
| 6818 | e1000e_ptp_init(adapter); |
| 6819 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6820 | e1000_print_device_info(adapter); |
| 6821 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6822 | if (pci_dev_run_wake(pdev)) |
| 6823 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6824 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6825 | return 0; |
| 6826 | |
| 6827 | err_register: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6828 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6829 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6830 | err_eeprom: |
Bruce Allan | 470a542 | 2012-05-26 06:08:48 +0000 | [diff] [blame] | 6831 | 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] | 6832 | e1000_phy_hw_reset(&adapter->hw); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6833 | err_hw_init: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6834 | kfree(adapter->tx_ring); |
| 6835 | kfree(adapter->rx_ring); |
| 6836 | err_sw_init: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6837 | if (adapter->hw.flash_address) |
| 6838 | iounmap(adapter->hw.flash_address); |
Jeff Kirsher | e82f54b | 2008-11-14 06:45:07 +0000 | [diff] [blame] | 6839 | e1000e_reset_interrupt_capability(adapter); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6840 | err_flashmap: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6841 | iounmap(adapter->hw.hw_addr); |
| 6842 | err_ioremap: |
| 6843 | free_netdev(netdev); |
| 6844 | err_alloc_etherdev: |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6845 | pci_release_selected_regions(pdev, |
| 6846 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6847 | err_pci_reg: |
| 6848 | err_dma: |
| 6849 | pci_disable_device(pdev); |
| 6850 | return err; |
| 6851 | } |
| 6852 | |
| 6853 | /** |
| 6854 | * e1000_remove - Device Removal Routine |
| 6855 | * @pdev: PCI device information struct |
| 6856 | * |
| 6857 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 6858 | * that it should release a PCI device. The could be caused by a |
| 6859 | * Hot-Plug event, or because the driver is going to be removed from |
| 6860 | * memory. |
| 6861 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 6862 | static void e1000_remove(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6863 | { |
| 6864 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6865 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6866 | bool down = test_bit(__E1000_DOWN, &adapter->state); |
| 6867 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 6868 | e1000e_ptp_remove(adapter); |
| 6869 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6870 | /* The timers may be rescheduled, so explicitly disable them |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 6871 | * from being rescheduled. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6872 | */ |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6873 | if (!down) |
| 6874 | set_bit(__E1000_DOWN, &adapter->state); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6875 | del_timer_sync(&adapter->watchdog_timer); |
| 6876 | del_timer_sync(&adapter->phy_info_timer); |
| 6877 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 6878 | cancel_work_sync(&adapter->reset_task); |
| 6879 | cancel_work_sync(&adapter->watchdog_task); |
| 6880 | cancel_work_sync(&adapter->downshift_task); |
| 6881 | cancel_work_sync(&adapter->update_phy_task); |
| 6882 | cancel_work_sync(&adapter->print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6883 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6884 | if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) { |
| 6885 | cancel_work_sync(&adapter->tx_hwtstamp_work); |
| 6886 | if (adapter->tx_hwtstamp_skb) { |
| 6887 | dev_kfree_skb_any(adapter->tx_hwtstamp_skb); |
| 6888 | adapter->tx_hwtstamp_skb = NULL; |
| 6889 | } |
| 6890 | } |
| 6891 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6892 | if (!(netdev->flags & IFF_UP)) |
| 6893 | e1000_power_down_phy(adapter); |
| 6894 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6895 | /* Don't lie to e1000_close() down the road. */ |
| 6896 | if (!down) |
| 6897 | clear_bit(__E1000_DOWN, &adapter->state); |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 6898 | unregister_netdev(netdev); |
| 6899 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 6900 | if (pci_dev_run_wake(pdev)) |
| 6901 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6902 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6903 | /* 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] | 6904 | * would have already happened in close and is redundant. |
| 6905 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6906 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6907 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6908 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6909 | kfree(adapter->tx_ring); |
| 6910 | kfree(adapter->rx_ring); |
| 6911 | |
| 6912 | iounmap(adapter->hw.hw_addr); |
| 6913 | if (adapter->hw.flash_address) |
| 6914 | iounmap(adapter->hw.flash_address); |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 6915 | pci_release_selected_regions(pdev, |
| 6916 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6917 | |
| 6918 | free_netdev(netdev); |
| 6919 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6920 | /* AER disable */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6921 | pci_disable_pcie_error_reporting(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 6922 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6923 | pci_disable_device(pdev); |
| 6924 | } |
| 6925 | |
| 6926 | /* PCI Error Recovery (ERS) */ |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 6927 | static const struct pci_error_handlers e1000_err_handler = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6928 | .error_detected = e1000_io_error_detected, |
| 6929 | .slot_reset = e1000_io_slot_reset, |
| 6930 | .resume = e1000_io_resume, |
| 6931 | }; |
| 6932 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 6933 | static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6934 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
| 6935 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, |
| 6936 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, |
| 6937 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 }, |
| 6938 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
| 6939 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, |
Auke Kok | 040babf | 2007-10-31 15:22:05 -0700 | [diff] [blame] | 6940 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
| 6941 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, |
| 6942 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6943 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6944 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
| 6945 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, |
| 6946 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, |
| 6947 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6948 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6949 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
| 6950 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, |
| 6951 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6952 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6953 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, |
Bruce Allan | bef28b1 | 2009-03-24 23:28:02 -0700 | [diff] [blame] | 6954 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 6955 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 6956 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6957 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
| 6958 | board_80003es2lan }, |
| 6959 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), |
| 6960 | board_80003es2lan }, |
| 6961 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), |
| 6962 | board_80003es2lan }, |
| 6963 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), |
| 6964 | board_80003es2lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6965 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6966 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
| 6967 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, |
| 6968 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, |
| 6969 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, |
| 6970 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, |
| 6971 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, |
| 6972 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, |
Bruce Allan | 9e135a2 | 2009-12-01 15:50:31 +0000 | [diff] [blame] | 6973 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6974 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6975 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
| 6976 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, |
| 6977 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, |
| 6978 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, |
| 6979 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, |
Bruce Allan | 2f15f9d | 2008-08-26 18:36:36 -0700 | [diff] [blame] | 6980 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6981 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, |
| 6982 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, |
| 6983 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, |
| 6984 | |
| 6985 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, |
| 6986 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, |
| 6987 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6988 | |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6989 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, |
| 6990 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, |
Bruce Allan | 10df0b9 | 2010-05-10 15:02:52 +0000 | [diff] [blame] | 6991 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan }, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 6992 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6993 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, |
| 6994 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, |
| 6995 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, |
| 6996 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, |
| 6997 | |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 6998 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan }, |
| 6999 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan }, |
| 7000 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 7001 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt }, |
| 7002 | { 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] | 7003 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt }, |
| 7004 | { 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] | 7005 | |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 7006 | { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7007 | }; |
| 7008 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 7009 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 7010 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7011 | static const struct dev_pm_ops e1000_pm_ops = { |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 7012 | SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume) |
| 7013 | SET_RUNTIME_PM_OPS(e1000_runtime_suspend, |
| 7014 | e1000_runtime_resume, e1000_idle) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7015 | }; |
David S. Miller | e50208a | 2010-03-16 23:36:24 -0700 | [diff] [blame] | 7016 | #endif |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7017 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7018 | /* PCI Device API Driver */ |
| 7019 | static struct pci_driver e1000_driver = { |
| 7020 | .name = e1000e_driver_name, |
| 7021 | .id_table = e1000_pci_tbl, |
| 7022 | .probe = e1000_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 7023 | .remove = e1000_remove, |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 7024 | #ifdef CONFIG_PM |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 7025 | .driver = { |
| 7026 | .pm = &e1000_pm_ops, |
| 7027 | }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7028 | #endif |
| 7029 | .shutdown = e1000_shutdown, |
| 7030 | .err_handler = &e1000_err_handler |
| 7031 | }; |
| 7032 | |
| 7033 | /** |
| 7034 | * e1000_init_module - Driver Registration Routine |
| 7035 | * |
| 7036 | * e1000_init_module is the first routine called when the driver is |
| 7037 | * loaded. All it does is register with the PCI subsystem. |
| 7038 | **/ |
| 7039 | static int __init e1000_init_module(void) |
| 7040 | { |
| 7041 | int ret; |
Bruce Allan | 8544b9f | 2010-03-24 12:55:30 +0000 | [diff] [blame] | 7042 | pr_info("Intel(R) PRO/1000 Network Driver - %s\n", |
| 7043 | e1000e_driver_version); |
Bruce Allan | bf67044 | 2013-01-01 16:00:01 +0000 | [diff] [blame] | 7044 | pr_info("Copyright(c) 1999 - 2013 Intel Corporation.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7045 | ret = pci_register_driver(&e1000_driver); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 7046 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7047 | return ret; |
| 7048 | } |
| 7049 | module_init(e1000_init_module); |
| 7050 | |
| 7051 | /** |
| 7052 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 7053 | * |
| 7054 | * e1000_exit_module is called just before the driver is removed |
| 7055 | * from memory. |
| 7056 | **/ |
| 7057 | static void __exit e1000_exit_module(void) |
| 7058 | { |
| 7059 | pci_unregister_driver(&e1000_driver); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7060 | } |
| 7061 | module_exit(e1000_exit_module); |
| 7062 | |
| 7063 | |
| 7064 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 7065 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 7066 | MODULE_LICENSE("GPL"); |
| 7067 | MODULE_VERSION(DRV_VERSION); |
| 7068 | |
Bruce Allan | 06c24b9 | 2012-02-23 03:13:13 +0000 | [diff] [blame] | 7069 | /* netdev.c */ |