Jeff Kirsher | ae06c70 | 2018-03-22 10:08:48 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jeff Kirsher | 51dce24 | 2018-04-26 08:08:09 -0700 | [diff] [blame] | 2 | /* Copyright(c) 1999 - 2018 Intel Corporation. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3 | |
Bruce Allan | 8544b9f | 2010-03-24 12:55:30 +0000 | [diff] [blame] | 4 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 5 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6 | #include <linux/module.h> |
| 7 | #include <linux/types.h> |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/pci.h> |
| 10 | #include <linux/vmalloc.h> |
| 11 | #include <linux/pagemap.h> |
| 12 | #include <linux/delay.h> |
| 13 | #include <linux/netdevice.h> |
Bruce Allan | 9fb7a5f | 2011-07-29 05:52:51 +0000 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 15 | #include <linux/tcp.h> |
| 16 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 18 | #include <net/checksum.h> |
| 19 | #include <net/ip6_checksum.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 20 | #include <linux/ethtool.h> |
| 21 | #include <linux/if_vlan.h> |
| 22 | #include <linux/cpu.h> |
| 23 | #include <linux/smp.h> |
Linus Torvalds | 7e0bb71 | 2011-10-25 15:18:39 +0200 | [diff] [blame] | 24 | #include <linux/pm_qos.h> |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 25 | #include <linux/pm_runtime.h> |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 26 | #include <linux/aer.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 27 | #include <linux/prefetch.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 28 | |
| 29 | #include "e1000.h" |
| 30 | |
Bruce Allan | b3ccf26 | 2011-05-19 01:53:41 +0000 | [diff] [blame] | 31 | #define DRV_EXTRAVERSION "-k" |
Bruce Allan | c14c643 | 2010-06-16 13:28:34 +0000 | [diff] [blame] | 32 | |
Raanan Avargil | d2d7d4e | 2015-07-19 16:33:21 +0300 | [diff] [blame] | 33 | #define DRV_VERSION "3.2.6" DRV_EXTRAVERSION |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 34 | char e1000e_driver_name[] = "e1000e"; |
| 35 | const char e1000e_driver_version[] = DRV_VERSION; |
| 36 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 37 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 38 | static int debug = -1; |
| 39 | module_param(debug, int, 0); |
| 40 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 41 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 42 | static const struct e1000_info *e1000_info_tbl[] = { |
| 43 | [board_82571] = &e1000_82571_info, |
| 44 | [board_82572] = &e1000_82572_info, |
| 45 | [board_82573] = &e1000_82573_info, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 46 | [board_82574] = &e1000_82574_info, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 47 | [board_82583] = &e1000_82583_info, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 48 | [board_80003es2lan] = &e1000_es2_info, |
| 49 | [board_ich8lan] = &e1000_ich8_info, |
| 50 | [board_ich9lan] = &e1000_ich9_info, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 51 | [board_ich10lan] = &e1000_ich10_info, |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 52 | [board_pchlan] = &e1000_pch_info, |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 53 | [board_pch2lan] = &e1000_pch2_info, |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 54 | [board_pch_lpt] = &e1000_pch_lpt_info, |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 55 | [board_pch_spt] = &e1000_pch_spt_info, |
Sasha Neftin | 3a3173b | 2017-04-06 10:26:32 +0300 | [diff] [blame] | 56 | [board_pch_cnp] = &e1000_pch_cnp_info, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 59 | struct e1000_reg_info { |
| 60 | u32 ofs; |
| 61 | char *name; |
| 62 | }; |
| 63 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 64 | static const struct e1000_reg_info e1000_reg_info_tbl[] = { |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 65 | /* General Registers */ |
| 66 | {E1000_CTRL, "CTRL"}, |
| 67 | {E1000_STATUS, "STATUS"}, |
| 68 | {E1000_CTRL_EXT, "CTRL_EXT"}, |
| 69 | |
| 70 | /* Interrupt Registers */ |
| 71 | {E1000_ICR, "ICR"}, |
| 72 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 73 | /* Rx Registers */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 74 | {E1000_RCTL, "RCTL"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 75 | {E1000_RDLEN(0), "RDLEN"}, |
| 76 | {E1000_RDH(0), "RDH"}, |
| 77 | {E1000_RDT(0), "RDT"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 78 | {E1000_RDTR, "RDTR"}, |
| 79 | {E1000_RXDCTL(0), "RXDCTL"}, |
| 80 | {E1000_ERT, "ERT"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 81 | {E1000_RDBAL(0), "RDBAL"}, |
| 82 | {E1000_RDBAH(0), "RDBAH"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 83 | {E1000_RDFH, "RDFH"}, |
| 84 | {E1000_RDFT, "RDFT"}, |
| 85 | {E1000_RDFHS, "RDFHS"}, |
| 86 | {E1000_RDFTS, "RDFTS"}, |
| 87 | {E1000_RDFPC, "RDFPC"}, |
| 88 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 89 | /* Tx Registers */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 90 | {E1000_TCTL, "TCTL"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 91 | {E1000_TDBAL(0), "TDBAL"}, |
| 92 | {E1000_TDBAH(0), "TDBAH"}, |
| 93 | {E1000_TDLEN(0), "TDLEN"}, |
| 94 | {E1000_TDH(0), "TDH"}, |
| 95 | {E1000_TDT(0), "TDT"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 96 | {E1000_TIDV, "TIDV"}, |
| 97 | {E1000_TXDCTL(0), "TXDCTL"}, |
| 98 | {E1000_TADV, "TADV"}, |
| 99 | {E1000_TARC(0), "TARC"}, |
| 100 | {E1000_TDFH, "TDFH"}, |
| 101 | {E1000_TDFT, "TDFT"}, |
| 102 | {E1000_TDFHS, "TDFHS"}, |
| 103 | {E1000_TDFTS, "TDFTS"}, |
| 104 | {E1000_TDFPC, "TDFPC"}, |
| 105 | |
| 106 | /* List Terminator */ |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 107 | {0, NULL} |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
Vitaly Lifshits | e086ba2 | 2020-05-07 20:14:06 +0300 | [diff] [blame] | 110 | struct e1000e_me_supported { |
| 111 | u16 device_id; /* supported device ID */ |
| 112 | }; |
| 113 | |
| 114 | static const struct e1000e_me_supported me_supported[] = { |
| 115 | {E1000_DEV_ID_PCH_LPT_I217_LM}, |
| 116 | {E1000_DEV_ID_PCH_LPTLP_I218_LM}, |
| 117 | {E1000_DEV_ID_PCH_I218_LM2}, |
| 118 | {E1000_DEV_ID_PCH_I218_LM3}, |
| 119 | {E1000_DEV_ID_PCH_SPT_I219_LM}, |
| 120 | {E1000_DEV_ID_PCH_SPT_I219_LM2}, |
| 121 | {E1000_DEV_ID_PCH_LBG_I219_LM3}, |
| 122 | {E1000_DEV_ID_PCH_SPT_I219_LM4}, |
| 123 | {E1000_DEV_ID_PCH_SPT_I219_LM5}, |
| 124 | {E1000_DEV_ID_PCH_CNP_I219_LM6}, |
| 125 | {E1000_DEV_ID_PCH_CNP_I219_LM7}, |
| 126 | {E1000_DEV_ID_PCH_ICP_I219_LM8}, |
| 127 | {E1000_DEV_ID_PCH_ICP_I219_LM9}, |
| 128 | {E1000_DEV_ID_PCH_CMP_I219_LM10}, |
| 129 | {E1000_DEV_ID_PCH_CMP_I219_LM11}, |
| 130 | {E1000_DEV_ID_PCH_CMP_I219_LM12}, |
| 131 | {E1000_DEV_ID_PCH_TGP_I219_LM13}, |
| 132 | {E1000_DEV_ID_PCH_TGP_I219_LM14}, |
| 133 | {E1000_DEV_ID_PCH_TGP_I219_LM15}, |
| 134 | {0} |
| 135 | }; |
| 136 | |
| 137 | static bool e1000e_check_me(u16 device_id) |
| 138 | { |
| 139 | struct e1000e_me_supported *id; |
| 140 | |
| 141 | for (id = (struct e1000e_me_supported *)me_supported; |
| 142 | id->device_id; id++) |
| 143 | if (device_id == id->device_id) |
| 144 | return true; |
| 145 | |
| 146 | return false; |
| 147 | } |
| 148 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 149 | /** |
Andi Kleen | c6f3148 | 2014-05-20 08:22:45 +0000 | [diff] [blame] | 150 | * __ew32_prepare - prepare to write to MAC CSR register on certain parts |
| 151 | * @hw: pointer to the HW structure |
| 152 | * |
| 153 | * When updating the MAC CSR registers, the Manageability Engine (ME) could |
| 154 | * be accessing the registers at the same time. Normally, this is handled in |
| 155 | * h/w by an arbiter but on some parts there is a bug that acknowledges Host |
| 156 | * accesses later than it should which could result in the register to have |
| 157 | * an incorrect value. Workaround this by checking the FWSM register which |
| 158 | * has bit 24 set while ME is accessing MAC CSR registers, wait if it is set |
| 159 | * and try again a number of times. |
| 160 | **/ |
Punit Agrawal | d601afc | 2020-05-15 13:31:27 +0900 | [diff] [blame] | 161 | static void __ew32_prepare(struct e1000_hw *hw) |
Andi Kleen | c6f3148 | 2014-05-20 08:22:45 +0000 | [diff] [blame] | 162 | { |
| 163 | s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT; |
| 164 | |
| 165 | while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i) |
| 166 | udelay(50); |
Andi Kleen | c6f3148 | 2014-05-20 08:22:45 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val) |
| 170 | { |
| 171 | if (hw->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 172 | __ew32_prepare(hw); |
| 173 | |
| 174 | writel(val, hw->hw_addr + reg); |
| 175 | } |
| 176 | |
| 177 | /** |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 178 | * e1000_regdump - register printout routine |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 179 | * @hw: pointer to the HW structure |
| 180 | * @reginfo: pointer to the register info table |
| 181 | **/ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 182 | static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo) |
| 183 | { |
| 184 | int n = 0; |
| 185 | char rname[16]; |
| 186 | u32 regs[8]; |
| 187 | |
| 188 | switch (reginfo->ofs) { |
| 189 | case E1000_RXDCTL(0): |
| 190 | for (n = 0; n < 2; n++) |
| 191 | regs[n] = __er32(hw, E1000_RXDCTL(n)); |
| 192 | break; |
| 193 | case E1000_TXDCTL(0): |
| 194 | for (n = 0; n < 2; n++) |
| 195 | regs[n] = __er32(hw, E1000_TXDCTL(n)); |
| 196 | break; |
| 197 | case E1000_TARC(0): |
| 198 | for (n = 0; n < 2; n++) |
| 199 | regs[n] = __er32(hw, E1000_TARC(n)); |
| 200 | break; |
| 201 | default: |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 202 | pr_info("%-15s %08x\n", |
| 203 | reginfo->name, __er32(hw, reginfo->ofs)); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 204 | return; |
| 205 | } |
| 206 | |
| 207 | snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 208 | pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 211 | static void e1000e_dump_ps_pages(struct e1000_adapter *adapter, |
| 212 | struct e1000_buffer *bi) |
| 213 | { |
| 214 | int i; |
| 215 | struct e1000_ps_page *ps_page; |
| 216 | |
| 217 | for (i = 0; i < adapter->rx_ps_pages; i++) { |
| 218 | ps_page = &bi->ps_pages[i]; |
| 219 | |
| 220 | if (ps_page->page) { |
| 221 | pr_info("packet dump for ps_page %d:\n", i); |
| 222 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, |
| 223 | 16, 1, page_address(ps_page->page), |
| 224 | PAGE_SIZE, true); |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 229 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 230 | * e1000e_dump - Print registers, Tx-ring and Rx-ring |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 231 | * @adapter: board private structure |
| 232 | **/ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 233 | static void e1000e_dump(struct e1000_adapter *adapter) |
| 234 | { |
| 235 | struct net_device *netdev = adapter->netdev; |
| 236 | struct e1000_hw *hw = &adapter->hw; |
| 237 | struct e1000_reg_info *reginfo; |
| 238 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 239 | struct e1000_tx_desc *tx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 240 | struct my_u0 { |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 241 | __le64 a; |
| 242 | __le64 b; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 243 | } *u0; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 244 | struct e1000_buffer *buffer_info; |
| 245 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 246 | union e1000_rx_desc_packet_split *rx_desc_ps; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 247 | union e1000_rx_desc_extended *rx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 248 | struct my_u1 { |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 249 | __le64 a; |
| 250 | __le64 b; |
| 251 | __le64 c; |
| 252 | __le64 d; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 253 | } *u1; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 254 | u32 staterr; |
| 255 | int i = 0; |
| 256 | |
| 257 | if (!netif_msg_hw(adapter)) |
| 258 | return; |
| 259 | |
| 260 | /* Print netdevice Info */ |
| 261 | if (netdev) { |
| 262 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Tobias Klauser | 4a7c972 | 2017-01-18 17:45:01 +0100 | [diff] [blame] | 263 | pr_info("Device Name state trans_start\n"); |
| 264 | pr_info("%-15s %016lX %016lX\n", netdev->name, |
| 265 | netdev->state, dev_trans_start(netdev)); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /* Print Registers */ |
| 269 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 270 | pr_info(" Register Name Value\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 271 | for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl; |
| 272 | reginfo->name; reginfo++) { |
| 273 | e1000_regdump(hw, reginfo); |
| 274 | } |
| 275 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 276 | /* Print Tx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 277 | if (!netdev || !netif_running(netdev)) |
Bruce Allan | fe1e980 | 2012-01-31 06:37:54 +0000 | [diff] [blame] | 278 | return; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 279 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 280 | dev_info(&adapter->pdev->dev, "Tx Ring Summary\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 281 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 282 | buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean]; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 283 | pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n", |
| 284 | 0, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 285 | (unsigned long long)buffer_info->dma, |
| 286 | buffer_info->length, |
| 287 | buffer_info->next_to_watch, |
| 288 | (unsigned long long)buffer_info->time_stamp); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 289 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 290 | /* Print Tx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 291 | if (!netif_msg_tx_done(adapter)) |
| 292 | goto rx_ring_summary; |
| 293 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 294 | dev_info(&adapter->pdev->dev, "Tx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 295 | |
| 296 | /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended) |
| 297 | * |
| 298 | * Legacy Transmit Descriptor |
| 299 | * +--------------------------------------------------------------+ |
| 300 | * 0 | Buffer Address [63:0] (Reserved on Write Back) | |
| 301 | * +--------------------------------------------------------------+ |
| 302 | * 8 | Special | CSS | Status | CMD | CSO | Length | |
| 303 | * +--------------------------------------------------------------+ |
| 304 | * 63 48 47 36 35 32 31 24 23 16 15 0 |
| 305 | * |
| 306 | * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload |
| 307 | * 63 48 47 40 39 32 31 16 15 8 7 0 |
| 308 | * +----------------------------------------------------------------+ |
| 309 | * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS | |
| 310 | * +----------------------------------------------------------------+ |
| 311 | * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN | |
| 312 | * +----------------------------------------------------------------+ |
| 313 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 314 | * |
| 315 | * Extended Data Descriptor (DTYP=0x1) |
| 316 | * +----------------------------------------------------------------+ |
| 317 | * 0 | Buffer Address [63:0] | |
| 318 | * +----------------------------------------------------------------+ |
| 319 | * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN | |
| 320 | * +----------------------------------------------------------------+ |
| 321 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 322 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 323 | pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n"); |
| 324 | pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n"); |
| 325 | 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] | 326 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 327 | const char *next_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 328 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 329 | buffer_info = &tx_ring->buffer_info[i]; |
| 330 | u0 = (struct my_u0 *)tx_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 331 | 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] | 332 | next_desc = " NTC/U"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 333 | else if (i == tx_ring->next_to_use) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 334 | next_desc = " NTU"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 335 | else if (i == tx_ring->next_to_clean) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 336 | next_desc = " NTC"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 337 | else |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 338 | next_desc = ""; |
| 339 | pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n", |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 340 | (!(le64_to_cpu(u0->b) & BIT(29)) ? 'l' : |
| 341 | ((le64_to_cpu(u0->b) & BIT(20)) ? 'd' : 'c')), |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 342 | i, |
| 343 | (unsigned long long)le64_to_cpu(u0->a), |
| 344 | (unsigned long long)le64_to_cpu(u0->b), |
| 345 | (unsigned long long)buffer_info->dma, |
| 346 | buffer_info->length, buffer_info->next_to_watch, |
| 347 | (unsigned long long)buffer_info->time_stamp, |
| 348 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 349 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 350 | if (netif_msg_pktdata(adapter) && buffer_info->skb) |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 351 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 352 | 16, 1, buffer_info->skb->data, |
| 353 | buffer_info->skb->len, true); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 356 | /* Print Rx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 357 | rx_ring_summary: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 358 | dev_info(&adapter->pdev->dev, "Rx Ring Summary\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 359 | pr_info("Queue [NTU] [NTC]\n"); |
| 360 | pr_info(" %5d %5X %5X\n", |
| 361 | 0, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 362 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 363 | /* Print Rx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 364 | if (!netif_msg_rx_status(adapter)) |
Bruce Allan | fe1e980 | 2012-01-31 06:37:54 +0000 | [diff] [blame] | 365 | return; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 366 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 367 | dev_info(&adapter->pdev->dev, "Rx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 368 | switch (adapter->rx_ps_pages) { |
| 369 | case 1: |
| 370 | case 2: |
| 371 | case 3: |
| 372 | /* [Extended] Packet Split Receive Descriptor Format |
| 373 | * |
| 374 | * +-----------------------------------------------------+ |
| 375 | * 0 | Buffer Address 0 [63:0] | |
| 376 | * +-----------------------------------------------------+ |
| 377 | * 8 | Buffer Address 1 [63:0] | |
| 378 | * +-----------------------------------------------------+ |
| 379 | * 16 | Buffer Address 2 [63:0] | |
| 380 | * +-----------------------------------------------------+ |
| 381 | * 24 | Buffer Address 3 [63:0] | |
| 382 | * +-----------------------------------------------------+ |
| 383 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 384 | 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] | 385 | /* [Extended] Receive Descriptor (Write-Back) Format |
| 386 | * |
| 387 | * 63 48 47 32 31 13 12 8 7 4 3 0 |
| 388 | * +------------------------------------------------------+ |
| 389 | * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS | |
| 390 | * | Checksum | Ident | | Queue | | Type | |
| 391 | * +------------------------------------------------------+ |
| 392 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 393 | * +------------------------------------------------------+ |
| 394 | * 63 48 47 32 31 20 19 0 |
| 395 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 396 | 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] | 397 | for (i = 0; i < rx_ring->count; i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 398 | const char *next_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 399 | buffer_info = &rx_ring->buffer_info[i]; |
| 400 | rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i); |
| 401 | u1 = (struct my_u1 *)rx_desc_ps; |
| 402 | staterr = |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 403 | le32_to_cpu(rx_desc_ps->wb.middle.status_error); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 404 | |
| 405 | if (i == rx_ring->next_to_use) |
| 406 | next_desc = " NTU"; |
| 407 | else if (i == rx_ring->next_to_clean) |
| 408 | next_desc = " NTC"; |
| 409 | else |
| 410 | next_desc = ""; |
| 411 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 412 | if (staterr & E1000_RXD_STAT_DD) { |
| 413 | /* Descriptor Done */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 414 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n", |
| 415 | "RWB", i, |
| 416 | (unsigned long long)le64_to_cpu(u1->a), |
| 417 | (unsigned long long)le64_to_cpu(u1->b), |
| 418 | (unsigned long long)le64_to_cpu(u1->c), |
| 419 | (unsigned long long)le64_to_cpu(u1->d), |
| 420 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 421 | } else { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 422 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n", |
| 423 | "R ", i, |
| 424 | (unsigned long long)le64_to_cpu(u1->a), |
| 425 | (unsigned long long)le64_to_cpu(u1->b), |
| 426 | (unsigned long long)le64_to_cpu(u1->c), |
| 427 | (unsigned long long)le64_to_cpu(u1->d), |
| 428 | (unsigned long long)buffer_info->dma, |
| 429 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 430 | |
| 431 | if (netif_msg_pktdata(adapter)) |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 432 | e1000e_dump_ps_pages(adapter, |
| 433 | buffer_info); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 434 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 435 | } |
| 436 | break; |
| 437 | default: |
| 438 | case 0: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 439 | /* Extended Receive Descriptor (Read) Format |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 440 | * |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 441 | * +-----------------------------------------------------+ |
| 442 | * 0 | Buffer Address [63:0] | |
| 443 | * +-----------------------------------------------------+ |
| 444 | * 8 | Reserved | |
| 445 | * +-----------------------------------------------------+ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 446 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 447 | 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] | 448 | /* Extended Receive Descriptor (Write-Back) Format |
| 449 | * |
| 450 | * 63 48 47 32 31 24 23 4 3 0 |
| 451 | * +------------------------------------------------------+ |
| 452 | * | RSS Hash | | | | |
| 453 | * 0 +-------------------+ Rsvd | Reserved | MRQ RSS | |
| 454 | * | Packet | IP | | | Type | |
| 455 | * | Checksum | Ident | | | | |
| 456 | * +------------------------------------------------------+ |
| 457 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 458 | * +------------------------------------------------------+ |
| 459 | * 63 48 47 32 31 20 19 0 |
| 460 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 461 | 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] | 462 | |
| 463 | for (i = 0; i < rx_ring->count; i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 464 | const char *next_desc; |
| 465 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 466 | buffer_info = &rx_ring->buffer_info[i]; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 467 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 468 | u1 = (struct my_u1 *)rx_desc; |
| 469 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 470 | |
| 471 | if (i == rx_ring->next_to_use) |
| 472 | next_desc = " NTU"; |
| 473 | else if (i == rx_ring->next_to_clean) |
| 474 | next_desc = " NTC"; |
| 475 | else |
| 476 | next_desc = ""; |
| 477 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 478 | if (staterr & E1000_RXD_STAT_DD) { |
| 479 | /* Descriptor Done */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 480 | pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n", |
| 481 | "RWB", i, |
| 482 | (unsigned long long)le64_to_cpu(u1->a), |
| 483 | (unsigned long long)le64_to_cpu(u1->b), |
| 484 | buffer_info->skb, next_desc); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 485 | } else { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 486 | pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n", |
| 487 | "R ", i, |
| 488 | (unsigned long long)le64_to_cpu(u1->a), |
| 489 | (unsigned long long)le64_to_cpu(u1->b), |
| 490 | (unsigned long long)buffer_info->dma, |
| 491 | buffer_info->skb, next_desc); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 492 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 493 | if (netif_msg_pktdata(adapter) && |
| 494 | buffer_info->skb) |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 495 | print_hex_dump(KERN_INFO, "", |
| 496 | DUMP_PREFIX_ADDRESS, 16, |
| 497 | 1, |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 498 | buffer_info->skb->data, |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 499 | adapter->rx_buffer_len, |
| 500 | true); |
| 501 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 502 | } |
| 503 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 506 | /** |
| 507 | * e1000_desc_unused - calculate if we have unused descriptors |
| 508 | **/ |
| 509 | static int e1000_desc_unused(struct e1000_ring *ring) |
| 510 | { |
| 511 | if (ring->next_to_clean > ring->next_to_use) |
| 512 | return ring->next_to_clean - ring->next_to_use - 1; |
| 513 | |
| 514 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; |
| 515 | } |
| 516 | |
| 517 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 518 | * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp |
| 519 | * @adapter: board private structure |
| 520 | * @hwtstamps: time stamp structure to update |
| 521 | * @systim: unsigned 64bit system time value. |
| 522 | * |
| 523 | * Convert the system time value stored in the RX/TXSTMP registers into a |
| 524 | * hwtstamp which can be used by the upper level time stamping functions. |
| 525 | * |
| 526 | * The 'systim_lock' spinlock is used to protect the consistency of the |
| 527 | * system time value. This is needed because reading the 64 bit time |
| 528 | * value involves reading two 32 bit registers. The first read latches the |
| 529 | * value. |
| 530 | **/ |
| 531 | static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter, |
| 532 | struct skb_shared_hwtstamps *hwtstamps, |
| 533 | u64 systim) |
| 534 | { |
| 535 | u64 ns; |
| 536 | unsigned long flags; |
| 537 | |
| 538 | spin_lock_irqsave(&adapter->systim_lock, flags); |
| 539 | ns = timecounter_cyc2time(&adapter->tc, systim); |
| 540 | spin_unlock_irqrestore(&adapter->systim_lock, flags); |
| 541 | |
| 542 | memset(hwtstamps, 0, sizeof(*hwtstamps)); |
| 543 | hwtstamps->hwtstamp = ns_to_ktime(ns); |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp |
| 548 | * @adapter: board private structure |
| 549 | * @status: descriptor extended error and status field |
| 550 | * @skb: particular skb to include time stamp |
| 551 | * |
| 552 | * If the time stamp is valid, convert it into the timecounter ns value |
| 553 | * and store that result into the shhwtstamps structure which is passed |
| 554 | * up the network stack. |
| 555 | **/ |
| 556 | static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status, |
| 557 | struct sk_buff *skb) |
| 558 | { |
| 559 | struct e1000_hw *hw = &adapter->hw; |
| 560 | u64 rxstmp; |
| 561 | |
| 562 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) || |
| 563 | !(status & E1000_RXDEXT_STATERR_TST) || |
| 564 | !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) |
| 565 | return; |
| 566 | |
| 567 | /* The Rx time stamp registers contain the time stamp. No other |
| 568 | * received packet will be time stamped until the Rx time stamp |
| 569 | * registers are read. Because only one packet can be time stamped |
| 570 | * at a time, the register values must belong to this packet and |
| 571 | * therefore none of the other additional attributes need to be |
| 572 | * compared. |
| 573 | */ |
| 574 | rxstmp = (u64)er32(RXSTMPL); |
| 575 | rxstmp |= (u64)er32(RXSTMPH) << 32; |
| 576 | e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp); |
| 577 | |
| 578 | adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP; |
| 579 | } |
| 580 | |
| 581 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 582 | * e1000_receive_skb - helper function to handle Rx indications |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 583 | * @adapter: board private structure |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 584 | * @staterr: descriptor extended error and status field as written by hardware |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 585 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
| 586 | * @skb: pointer to sk_buff to be indicated to stack |
| 587 | **/ |
| 588 | static void e1000_receive_skb(struct e1000_adapter *adapter, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 589 | struct net_device *netdev, struct sk_buff *skb, |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 590 | u32 staterr, __le16 vlan) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 591 | { |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 592 | u16 tag = le16_to_cpu(vlan); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 593 | |
| 594 | e1000e_rx_hwtstamp(adapter, staterr, skb); |
| 595 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 596 | skb->protocol = eth_type_trans(skb, netdev); |
| 597 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 598 | if (staterr & E1000_RXD_STAT_VP) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 599 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag); |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 600 | |
| 601 | napi_gro_receive(&adapter->napi, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 605 | * e1000_rx_checksum - Receive Checksum Offload |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 606 | * @adapter: board private structure |
| 607 | * @status_err: receive descriptor status and error fields |
| 608 | * @csum: receive descriptor csum field |
| 609 | * @sk_buff: socket buffer with received data |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 610 | **/ |
| 611 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 612 | struct sk_buff *skb) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 613 | { |
| 614 | u16 status = (u16)status_err; |
| 615 | u8 errors = (u8)(status_err >> 24); |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 616 | |
| 617 | skb_checksum_none_assert(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 618 | |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 619 | /* Rx checksum disabled */ |
| 620 | if (!(adapter->netdev->features & NETIF_F_RXCSUM)) |
| 621 | return; |
| 622 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 623 | /* Ignore Checksum bit is set */ |
| 624 | if (status & E1000_RXD_STAT_IXSM) |
| 625 | return; |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 626 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 627 | /* TCP/UDP checksum error bit or IP checksum error bit is set */ |
| 628 | if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 629 | /* let the stack verify checksum errors */ |
| 630 | adapter->hw_csum_err++; |
| 631 | return; |
| 632 | } |
| 633 | |
| 634 | /* TCP/UDP Checksum has not been calculated */ |
| 635 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
| 636 | return; |
| 637 | |
| 638 | /* It must be a TCP or UDP packet with a valid checksum */ |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 639 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 640 | adapter->hw_csum_good++; |
| 641 | } |
| 642 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 643 | 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] | 644 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 645 | struct e1000_adapter *adapter = rx_ring->adapter; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 646 | struct e1000_hw *hw = &adapter->hw; |
| 647 | |
Punit Agrawal | d601afc | 2020-05-15 13:31:27 +0900 | [diff] [blame] | 648 | __ew32_prepare(hw); |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 649 | writel(i, rx_ring->tail); |
| 650 | |
Punit Agrawal | d601afc | 2020-05-15 13:31:27 +0900 | [diff] [blame] | 651 | if (unlikely(i != readl(rx_ring->tail))) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 652 | u32 rctl = er32(RCTL); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 653 | |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 654 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 655 | e_err("ME firmware caused invalid RDT - resetting\n"); |
| 656 | schedule_work(&adapter->reset_task); |
| 657 | } |
| 658 | } |
| 659 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 660 | 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] | 661 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 662 | struct e1000_adapter *adapter = tx_ring->adapter; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 663 | struct e1000_hw *hw = &adapter->hw; |
| 664 | |
Punit Agrawal | d601afc | 2020-05-15 13:31:27 +0900 | [diff] [blame] | 665 | __ew32_prepare(hw); |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 666 | writel(i, tx_ring->tail); |
| 667 | |
Punit Agrawal | d601afc | 2020-05-15 13:31:27 +0900 | [diff] [blame] | 668 | if (unlikely(i != readl(tx_ring->tail))) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 669 | u32 tctl = er32(TCTL); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 670 | |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 671 | ew32(TCTL, tctl & ~E1000_TCTL_EN); |
| 672 | e_err("ME firmware caused invalid TDT - resetting\n"); |
| 673 | schedule_work(&adapter->reset_task); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | /** |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 678 | * e1000_alloc_rx_buffers - Replace used receive buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 679 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 680 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 681 | static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 682 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 683 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 684 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 685 | struct net_device *netdev = adapter->netdev; |
| 686 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 687 | union e1000_rx_desc_extended *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 688 | struct e1000_buffer *buffer_info; |
| 689 | struct sk_buff *skb; |
| 690 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 691 | unsigned int bufsz = adapter->rx_buffer_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 692 | |
| 693 | i = rx_ring->next_to_use; |
| 694 | buffer_info = &rx_ring->buffer_info[i]; |
| 695 | |
| 696 | while (cleaned_count--) { |
| 697 | skb = buffer_info->skb; |
| 698 | if (skb) { |
| 699 | skb_trim(skb, 0); |
| 700 | goto map_skb; |
| 701 | } |
| 702 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 703 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 704 | if (!skb) { |
| 705 | /* Better luck next round */ |
| 706 | adapter->alloc_rx_buff_failed++; |
| 707 | break; |
| 708 | } |
| 709 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 710 | buffer_info->skb = skb; |
| 711 | map_skb: |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 712 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 713 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 714 | DMA_FROM_DEVICE); |
| 715 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 716 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 717 | adapter->rx_dma_failed++; |
| 718 | break; |
| 719 | } |
| 720 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 721 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 722 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 723 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 724 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 725 | /* Force memory writes to complete before letting h/w |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 726 | * know there are new descriptors to fetch. (Only |
| 727 | * applicable for weak-ordered memory model archs, |
| 728 | * such as IA-64). |
| 729 | */ |
| 730 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 731 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 732 | e1000e_update_rdt_wa(rx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 733 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 734 | writel(i, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 735 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 736 | i++; |
| 737 | if (i == rx_ring->count) |
| 738 | i = 0; |
| 739 | buffer_info = &rx_ring->buffer_info[i]; |
| 740 | } |
| 741 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 742 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | /** |
| 746 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 747 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 748 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 749 | static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 750 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 751 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 752 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 753 | struct net_device *netdev = adapter->netdev; |
| 754 | struct pci_dev *pdev = adapter->pdev; |
| 755 | union e1000_rx_desc_packet_split *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 756 | struct e1000_buffer *buffer_info; |
| 757 | struct e1000_ps_page *ps_page; |
| 758 | struct sk_buff *skb; |
| 759 | unsigned int i, j; |
| 760 | |
| 761 | i = rx_ring->next_to_use; |
| 762 | buffer_info = &rx_ring->buffer_info[i]; |
| 763 | |
| 764 | while (cleaned_count--) { |
| 765 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 766 | |
| 767 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 768 | ps_page = &buffer_info->ps_pages[j]; |
| 769 | if (j >= adapter->rx_ps_pages) { |
| 770 | /* all unused desc entries get hw null ptr */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 771 | rx_desc->read.buffer_addr[j + 1] = |
| 772 | ~cpu_to_le64(0); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 773 | continue; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 774 | } |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 775 | if (!ps_page->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 776 | ps_page->page = alloc_page(gfp); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 777 | if (!ps_page->page) { |
| 778 | adapter->alloc_rx_buff_failed++; |
| 779 | goto no_buffers; |
| 780 | } |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 781 | ps_page->dma = dma_map_page(&pdev->dev, |
| 782 | ps_page->page, |
| 783 | 0, PAGE_SIZE, |
| 784 | DMA_FROM_DEVICE); |
| 785 | if (dma_mapping_error(&pdev->dev, |
| 786 | ps_page->dma)) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 787 | dev_err(&adapter->pdev->dev, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 788 | "Rx DMA page map failed\n"); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 789 | adapter->rx_dma_failed++; |
| 790 | goto no_buffers; |
| 791 | } |
| 792 | } |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 793 | /* Refresh the desc even if buffer_addrs |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 794 | * didn't change because each write-back |
| 795 | * erases this info. |
| 796 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 797 | rx_desc->read.buffer_addr[j + 1] = |
| 798 | cpu_to_le64(ps_page->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 801 | skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 802 | gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 803 | |
| 804 | if (!skb) { |
| 805 | adapter->alloc_rx_buff_failed++; |
| 806 | break; |
| 807 | } |
| 808 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 809 | buffer_info->skb = skb; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 810 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 811 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 812 | DMA_FROM_DEVICE); |
| 813 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 814 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 815 | adapter->rx_dma_failed++; |
| 816 | /* cleanup skb */ |
| 817 | dev_kfree_skb_any(skb); |
| 818 | buffer_info->skb = NULL; |
| 819 | break; |
| 820 | } |
| 821 | |
| 822 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 823 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 824 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 825 | /* Force memory writes to complete before letting h/w |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 826 | * know there are new descriptors to fetch. (Only |
| 827 | * applicable for weak-ordered memory model archs, |
| 828 | * such as IA-64). |
| 829 | */ |
| 830 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 831 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 832 | e1000e_update_rdt_wa(rx_ring, i << 1); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 833 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 834 | writel(i << 1, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 835 | } |
| 836 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 837 | i++; |
| 838 | if (i == rx_ring->count) |
| 839 | i = 0; |
| 840 | buffer_info = &rx_ring->buffer_info[i]; |
| 841 | } |
| 842 | |
| 843 | no_buffers: |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 844 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 848 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 849 | * @rx_ring: Rx descriptor ring |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 850 | * @cleaned_count: number of buffers to allocate this pass |
| 851 | **/ |
| 852 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 853 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 854 | int cleaned_count, gfp_t gfp) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 855 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 856 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 857 | struct net_device *netdev = adapter->netdev; |
| 858 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 859 | union e1000_rx_desc_extended *rx_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 860 | struct e1000_buffer *buffer_info; |
| 861 | struct sk_buff *skb; |
| 862 | unsigned int i; |
Bruce Allan | 2a2293b | 2012-12-05 06:26:35 +0000 | [diff] [blame] | 863 | unsigned int bufsz = 256 - 16; /* for skb_reserve */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 864 | |
| 865 | i = rx_ring->next_to_use; |
| 866 | buffer_info = &rx_ring->buffer_info[i]; |
| 867 | |
| 868 | while (cleaned_count--) { |
| 869 | skb = buffer_info->skb; |
| 870 | if (skb) { |
| 871 | skb_trim(skb, 0); |
| 872 | goto check_page; |
| 873 | } |
| 874 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 875 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 876 | if (unlikely(!skb)) { |
| 877 | /* Better luck next round */ |
| 878 | adapter->alloc_rx_buff_failed++; |
| 879 | break; |
| 880 | } |
| 881 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 882 | buffer_info->skb = skb; |
| 883 | check_page: |
| 884 | /* allocate a new page if necessary */ |
| 885 | if (!buffer_info->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 886 | buffer_info->page = alloc_page(gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 887 | if (unlikely(!buffer_info->page)) { |
| 888 | adapter->alloc_rx_buff_failed++; |
| 889 | break; |
| 890 | } |
| 891 | } |
| 892 | |
Christoph Paasch | 37287fae | 2013-03-20 08:59:46 +0000 | [diff] [blame] | 893 | if (!buffer_info->dma) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 894 | buffer_info->dma = dma_map_page(&pdev->dev, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 895 | buffer_info->page, 0, |
| 896 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 897 | DMA_FROM_DEVICE); |
Christoph Paasch | 37287fae | 2013-03-20 08:59:46 +0000 | [diff] [blame] | 898 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
| 899 | adapter->alloc_rx_buff_failed++; |
| 900 | break; |
| 901 | } |
| 902 | } |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 903 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 904 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 905 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 906 | |
| 907 | if (unlikely(++i == rx_ring->count)) |
| 908 | i = 0; |
| 909 | buffer_info = &rx_ring->buffer_info[i]; |
| 910 | } |
| 911 | |
| 912 | if (likely(rx_ring->next_to_use != i)) { |
| 913 | rx_ring->next_to_use = i; |
| 914 | if (unlikely(i-- == 0)) |
| 915 | i = (rx_ring->count - 1); |
| 916 | |
| 917 | /* Force memory writes to complete before letting h/w |
| 918 | * know there are new descriptors to fetch. (Only |
| 919 | * applicable for weak-ordered memory model archs, |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 920 | * such as IA-64). |
| 921 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 922 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 923 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 924 | e1000e_update_rdt_wa(rx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 925 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 926 | writel(i, rx_ring->tail); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 930 | static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss, |
| 931 | struct sk_buff *skb) |
| 932 | { |
| 933 | if (netdev->features & NETIF_F_RXHASH) |
Tom Herbert | e25909b | 2013-12-18 16:46:48 +0000 | [diff] [blame] | 934 | skb_set_hash(skb, le32_to_cpu(rss), PKT_HASH_TYPE_L3); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 935 | } |
| 936 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 937 | /** |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 938 | * e1000_clean_rx_irq - Send received data up the network stack |
| 939 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 940 | * |
| 941 | * the return value indicates whether actual cleaning was done, there |
| 942 | * is no guarantee that everything was cleaned |
| 943 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 944 | static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
| 945 | int work_to_do) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 946 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 947 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 948 | struct net_device *netdev = adapter->netdev; |
| 949 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 950 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 951 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 952 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 953 | u32 length, staterr; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 954 | unsigned int i; |
| 955 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 956 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 957 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 958 | |
| 959 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 960 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 961 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 962 | buffer_info = &rx_ring->buffer_info[i]; |
| 963 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 964 | while (staterr & E1000_RXD_STAT_DD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 965 | struct sk_buff *skb; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 966 | |
| 967 | if (*work_done >= work_to_do) |
| 968 | break; |
| 969 | (*work_done)++; |
Alexander Duyck | 837a1db | 2015-04-07 16:55:27 -0700 | [diff] [blame] | 970 | dma_rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 971 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 972 | skb = buffer_info->skb; |
| 973 | buffer_info->skb = NULL; |
| 974 | |
| 975 | prefetch(skb->data - NET_IP_ALIGN); |
| 976 | |
| 977 | i++; |
| 978 | if (i == rx_ring->count) |
| 979 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 980 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 981 | prefetch(next_rxd); |
| 982 | |
| 983 | next_buffer = &rx_ring->buffer_info[i]; |
| 984 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 985 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 986 | cleaned_count++; |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 987 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
| 988 | adapter->rx_buffer_len, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 989 | buffer_info->dma = 0; |
| 990 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 991 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 992 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 993 | /* !EOP means multiple descriptors were used to store a single |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 994 | * packet, if that's the case we need to toss it. In fact, we |
| 995 | * need to toss every packet with the EOP bit clear and the |
| 996 | * next frame that _does_ have the EOP bit set, as it is by |
| 997 | * definition only a frame fragment |
| 998 | */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 999 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1000 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 1001 | |
| 1002 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1003 | /* All receives must fit into a single buffer */ |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1004 | e_dbg("Receive packet consumed multiple buffers\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1005 | /* recycle */ |
| 1006 | buffer_info->skb = skb; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1007 | if (staterr & E1000_RXD_STAT_EOP) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1008 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1009 | goto next_desc; |
| 1010 | } |
| 1011 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 1012 | if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 1013 | !(netdev->features & NETIF_F_RXALL))) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1014 | /* recycle */ |
| 1015 | buffer_info->skb = skb; |
| 1016 | goto next_desc; |
| 1017 | } |
| 1018 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1019 | /* adjust length to remove Ethernet CRC */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 1020 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 1021 | /* If configured to store CRC, don't subtract FCS, |
| 1022 | * but keep the FCS bytes out of the total_rx_bytes |
| 1023 | * counter |
| 1024 | */ |
| 1025 | if (netdev->features & NETIF_F_RXFCS) |
| 1026 | total_rx_bytes -= 4; |
| 1027 | else |
| 1028 | length -= 4; |
| 1029 | } |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1030 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1031 | total_rx_bytes += length; |
| 1032 | total_rx_packets++; |
| 1033 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1034 | /* code added for copybreak, this should improve |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1035 | * performance for small packets with large amounts |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1036 | * of reassembly being done in the stack |
| 1037 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1038 | if (length < copybreak) { |
| 1039 | struct sk_buff *new_skb = |
Alexander Duyck | 67fd893 | 2014-12-09 19:40:56 -0800 | [diff] [blame] | 1040 | napi_alloc_skb(&adapter->napi, length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1041 | if (new_skb) { |
Bruce Allan | 808ff67 | 2008-08-08 18:35:56 -0700 | [diff] [blame] | 1042 | skb_copy_to_linear_data_offset(new_skb, |
| 1043 | -NET_IP_ALIGN, |
| 1044 | (skb->data - |
| 1045 | NET_IP_ALIGN), |
| 1046 | (length + |
| 1047 | NET_IP_ALIGN)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1048 | /* save the skb in buffer_info as good */ |
| 1049 | buffer_info->skb = skb; |
| 1050 | skb = new_skb; |
| 1051 | } |
| 1052 | /* else just continue with the old one */ |
| 1053 | } |
| 1054 | /* end copybreak code */ |
| 1055 | skb_put(skb, length); |
| 1056 | |
| 1057 | /* Receive Checksum Offload */ |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1058 | e1000_rx_checksum(adapter, staterr, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1059 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1060 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1061 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1062 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1063 | rx_desc->wb.upper.vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1064 | |
| 1065 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1066 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1067 | |
| 1068 | /* return some buffers to hardware, one at a time is too slow */ |
| 1069 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1070 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1071 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1072 | cleaned_count = 0; |
| 1073 | } |
| 1074 | |
| 1075 | /* use prefetched values */ |
| 1076 | rx_desc = next_rxd; |
| 1077 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1078 | |
| 1079 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1080 | } |
| 1081 | rx_ring->next_to_clean = i; |
| 1082 | |
| 1083 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1084 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1085 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1086 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1087 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1088 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1089 | return cleaned; |
| 1090 | } |
| 1091 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1092 | static void e1000_put_txbuf(struct e1000_ring *tx_ring, |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 1093 | struct e1000_buffer *buffer_info, |
| 1094 | bool drop) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1095 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1096 | struct e1000_adapter *adapter = tx_ring->adapter; |
| 1097 | |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1098 | if (buffer_info->dma) { |
| 1099 | if (buffer_info->mapped_as_page) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1100 | dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, |
| 1101 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1102 | else |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1103 | dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, |
| 1104 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1105 | buffer_info->dma = 0; |
| 1106 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1107 | if (buffer_info->skb) { |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 1108 | if (drop) |
| 1109 | dev_kfree_skb_any(buffer_info->skb); |
| 1110 | else |
| 1111 | dev_consume_skb_any(buffer_info->skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1112 | buffer_info->skb = NULL; |
| 1113 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 1114 | buffer_info->time_stamp = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1117 | static void e1000_print_hw_hang(struct work_struct *work) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1118 | { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1119 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1120 | struct e1000_adapter, |
| 1121 | print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1122 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1123 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1124 | unsigned int i = tx_ring->next_to_clean; |
| 1125 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; |
| 1126 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1127 | struct e1000_hw *hw = &adapter->hw; |
| 1128 | u16 phy_status, phy_1000t_status, phy_ext_status; |
| 1129 | u16 pci_status; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1130 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1131 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1132 | return; |
| 1133 | |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 1134 | if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1135 | /* May be block on write-back, flush and detect again |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1136 | * flush pending descriptor writebacks to memory |
| 1137 | */ |
| 1138 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 1139 | /* execute the writes immediately */ |
| 1140 | e1e_flush(); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1141 | /* Due to rare timing issues, write to TIDV again to ensure |
Matthew Vick | bf03085 | 2012-03-16 09:03:00 +0000 | [diff] [blame] | 1142 | * the write is successful |
| 1143 | */ |
| 1144 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 1145 | /* execute the writes immediately */ |
| 1146 | e1e_flush(); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1147 | adapter->tx_hang_recheck = true; |
| 1148 | return; |
| 1149 | } |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1150 | adapter->tx_hang_recheck = false; |
David Ertman | d9554e9 | 2014-01-08 01:07:55 +0000 | [diff] [blame] | 1151 | |
| 1152 | if (er32(TDH(0)) == er32(TDT(0))) { |
| 1153 | e_dbg("false hang detected, ignoring\n"); |
| 1154 | return; |
| 1155 | } |
| 1156 | |
| 1157 | /* Real hang detected */ |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1158 | netif_stop_queue(netdev); |
| 1159 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 1160 | e1e_rphy(hw, MII_BMSR, &phy_status); |
| 1161 | e1e_rphy(hw, MII_STAT1000, &phy_1000t_status); |
| 1162 | e1e_rphy(hw, MII_ESTATUS, &phy_ext_status); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1163 | |
| 1164 | pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status); |
| 1165 | |
| 1166 | /* detected Hardware unit hang */ |
| 1167 | e_err("Detected Hardware Unit Hang:\n" |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1168 | " TDH <%x>\n" |
| 1169 | " TDT <%x>\n" |
| 1170 | " next_to_use <%x>\n" |
| 1171 | " next_to_clean <%x>\n" |
| 1172 | "buffer_info[next_to_clean]:\n" |
| 1173 | " time_stamp <%lx>\n" |
| 1174 | " next_to_watch <%x>\n" |
| 1175 | " jiffies <%lx>\n" |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1176 | " next_to_watch.status <%x>\n" |
| 1177 | "MAC Status <%x>\n" |
| 1178 | "PHY Status <%x>\n" |
| 1179 | "PHY 1000BASE-T Status <%x>\n" |
| 1180 | "PHY Extended Status <%x>\n" |
| 1181 | "PCI Status <%x>\n", |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 1182 | readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use, |
| 1183 | tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp, |
| 1184 | eop, jiffies, eop_desc->upper.fields.status, er32(STATUS), |
| 1185 | phy_status, phy_1000t_status, phy_ext_status, pci_status); |
Bruce Allan | 7c0427e | 2012-03-20 03:48:08 +0000 | [diff] [blame] | 1186 | |
David Ertman | d9554e9 | 2014-01-08 01:07:55 +0000 | [diff] [blame] | 1187 | e1000e_dump(adapter); |
| 1188 | |
Bruce Allan | 7c0427e | 2012-03-20 03:48:08 +0000 | [diff] [blame] | 1189 | /* Suggest workaround for known h/w issue */ |
| 1190 | if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE)) |
| 1191 | e_err("Try turning off Tx pause (flow control) via ethtool\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1195 | * e1000e_tx_hwtstamp_work - check for Tx time stamp |
| 1196 | * @work: pointer to work struct |
| 1197 | * |
| 1198 | * This work function polls the TSYNCTXCTL valid bit to determine when a |
| 1199 | * timestamp has been taken for the current stored skb. The timestamp must |
| 1200 | * be for this skb because only one such packet is allowed in the queue. |
| 1201 | */ |
| 1202 | static void e1000e_tx_hwtstamp_work(struct work_struct *work) |
| 1203 | { |
| 1204 | struct e1000_adapter *adapter = container_of(work, struct e1000_adapter, |
| 1205 | tx_hwtstamp_work); |
| 1206 | struct e1000_hw *hw = &adapter->hw; |
| 1207 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1208 | if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) { |
Jacob Keller | 5012863 | 2017-05-03 10:28:50 -0700 | [diff] [blame] | 1209 | struct sk_buff *skb = adapter->tx_hwtstamp_skb; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1210 | struct skb_shared_hwtstamps shhwtstamps; |
| 1211 | u64 txstmp; |
| 1212 | |
| 1213 | txstmp = er32(TXSTMPL); |
| 1214 | txstmp |= (u64)er32(TXSTMPH) << 32; |
| 1215 | |
| 1216 | e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp); |
| 1217 | |
Jacob Keller | 5012863 | 2017-05-03 10:28:50 -0700 | [diff] [blame] | 1218 | /* Clear the global tx_hwtstamp_skb pointer and force writes |
| 1219 | * prior to notifying the stack of a Tx timestamp. |
| 1220 | */ |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1221 | adapter->tx_hwtstamp_skb = NULL; |
Jacob Keller | 5012863 | 2017-05-03 10:28:50 -0700 | [diff] [blame] | 1222 | wmb(); /* force write prior to skb_tstamp_tx */ |
| 1223 | |
| 1224 | skb_tstamp_tx(skb, &shhwtstamps); |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 1225 | dev_consume_skb_any(skb); |
Jakub Kicinski | 59c871c | 2014-03-15 14:55:00 +0000 | [diff] [blame] | 1226 | } else if (time_after(jiffies, adapter->tx_hwtstamp_start |
| 1227 | + adapter->tx_timeout_factor * HZ)) { |
| 1228 | dev_kfree_skb_any(adapter->tx_hwtstamp_skb); |
| 1229 | adapter->tx_hwtstamp_skb = NULL; |
| 1230 | adapter->tx_hwtstamp_timeouts++; |
Jakub Kicinski | c5ffe7e | 2014-04-02 10:33:22 +0000 | [diff] [blame] | 1231 | e_warn("clearing Tx timestamp hang\n"); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1232 | } else { |
| 1233 | /* reschedule to check later */ |
| 1234 | schedule_work(&adapter->tx_hwtstamp_work); |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1239 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1240 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1241 | * |
| 1242 | * the return value indicates whether actual cleaning was done, there |
| 1243 | * is no guarantee that everything was cleaned |
| 1244 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1245 | static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1246 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1247 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1248 | struct net_device *netdev = adapter->netdev; |
| 1249 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1250 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 1251 | struct e1000_buffer *buffer_info; |
| 1252 | unsigned int i, eop; |
| 1253 | unsigned int count = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1254 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1255 | unsigned int bytes_compl = 0, pkts_compl = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1256 | |
| 1257 | i = tx_ring->next_to_clean; |
| 1258 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1259 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 1260 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1261 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 1262 | (count < tx_ring->count)) { |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1263 | bool cleaned = false; |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 1264 | |
Alexander Duyck | 837a1db | 2015-04-07 16:55:27 -0700 | [diff] [blame] | 1265 | dma_rmb(); /* read buffer_info after eop_desc */ |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1266 | for (; !cleaned; count++) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1267 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 1268 | buffer_info = &tx_ring->buffer_info[i]; |
| 1269 | cleaned = (i == eop); |
| 1270 | |
| 1271 | if (cleaned) { |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 1272 | total_tx_packets += buffer_info->segs; |
| 1273 | total_tx_bytes += buffer_info->bytecount; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1274 | if (buffer_info->skb) { |
| 1275 | bytes_compl += buffer_info->skb->len; |
| 1276 | pkts_compl++; |
| 1277 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 1280 | e1000_put_txbuf(tx_ring, buffer_info, false); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1281 | tx_desc->upper.data = 0; |
| 1282 | |
| 1283 | i++; |
| 1284 | if (i == tx_ring->count) |
| 1285 | i = 0; |
| 1286 | } |
| 1287 | |
Terry Loftin | dac8761 | 2010-04-09 10:29:49 +0000 | [diff] [blame] | 1288 | if (i == tx_ring->next_to_use) |
| 1289 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1290 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1291 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | tx_ring->next_to_clean = i; |
| 1295 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1296 | netdev_completed_queue(netdev, pkts_compl, bytes_compl); |
| 1297 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1298 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1299 | if (count && netif_carrier_ok(netdev) && |
| 1300 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1301 | /* Make sure that anybody stopping the queue after this |
| 1302 | * sees the new next_to_clean. |
| 1303 | */ |
| 1304 | smp_mb(); |
| 1305 | |
| 1306 | if (netif_queue_stopped(netdev) && |
| 1307 | !(test_bit(__E1000_DOWN, &adapter->state))) { |
| 1308 | netif_wake_queue(netdev); |
| 1309 | ++adapter->restart_queue; |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | if (adapter->detect_tx_hung) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1314 | /* Detect a transmit hang in hardware, this serializes the |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1315 | * check with the clearing of time_stamp and movement of i |
| 1316 | */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1317 | adapter->detect_tx_hung = false; |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1318 | if (tx_ring->buffer_info[i].time_stamp && |
| 1319 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1320 | + (adapter->tx_timeout_factor * HZ)) && |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1321 | !(er32(STATUS) & E1000_STATUS_TXOFF)) |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1322 | schedule_work(&adapter->print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1323 | else |
| 1324 | adapter->tx_hang_recheck = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1325 | } |
| 1326 | adapter->total_tx_bytes += total_tx_bytes; |
| 1327 | adapter->total_tx_packets += total_tx_packets; |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1328 | return count < tx_ring->count; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1332 | * 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] | 1333 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1334 | * |
| 1335 | * the return value indicates whether actual cleaning was done, there |
| 1336 | * is no guarantee that everything was cleaned |
| 1337 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1338 | static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done, |
| 1339 | int work_to_do) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1340 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1341 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1342 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1343 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
| 1344 | struct net_device *netdev = adapter->netdev; |
| 1345 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1346 | struct e1000_buffer *buffer_info, *next_buffer; |
| 1347 | struct e1000_ps_page *ps_page; |
| 1348 | struct sk_buff *skb; |
| 1349 | unsigned int i, j; |
| 1350 | u32 length, staterr; |
| 1351 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1352 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1353 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 1354 | |
| 1355 | i = rx_ring->next_to_clean; |
| 1356 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 1357 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1358 | buffer_info = &rx_ring->buffer_info[i]; |
| 1359 | |
| 1360 | while (staterr & E1000_RXD_STAT_DD) { |
| 1361 | if (*work_done >= work_to_do) |
| 1362 | break; |
| 1363 | (*work_done)++; |
| 1364 | skb = buffer_info->skb; |
Alexander Duyck | 837a1db | 2015-04-07 16:55:27 -0700 | [diff] [blame] | 1365 | dma_rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1366 | |
| 1367 | /* in the packet split case this is header only */ |
| 1368 | prefetch(skb->data - NET_IP_ALIGN); |
| 1369 | |
| 1370 | i++; |
| 1371 | if (i == rx_ring->count) |
| 1372 | i = 0; |
| 1373 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
| 1374 | prefetch(next_rxd); |
| 1375 | |
| 1376 | next_buffer = &rx_ring->buffer_info[i]; |
| 1377 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1378 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1379 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1380 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1381 | adapter->rx_ps_bsize0, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1382 | buffer_info->dma = 0; |
| 1383 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1384 | /* see !EOP comment in other Rx routine */ |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1385 | if (!(staterr & E1000_RXD_STAT_EOP)) |
| 1386 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 1387 | |
| 1388 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1389 | 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] | 1390 | dev_kfree_skb_irq(skb); |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1391 | if (staterr & E1000_RXD_STAT_EOP) |
| 1392 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1393 | goto next_desc; |
| 1394 | } |
| 1395 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 1396 | if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 1397 | !(netdev->features & NETIF_F_RXALL))) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1398 | dev_kfree_skb_irq(skb); |
| 1399 | goto next_desc; |
| 1400 | } |
| 1401 | |
| 1402 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 1403 | |
| 1404 | if (!length) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1405 | e_dbg("Last part of the packet spanning multiple descriptors\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1406 | dev_kfree_skb_irq(skb); |
| 1407 | goto next_desc; |
| 1408 | } |
| 1409 | |
| 1410 | /* Good Receive */ |
| 1411 | skb_put(skb, length); |
| 1412 | |
| 1413 | { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1414 | /* this looks ugly, but it seems compiler issues make |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1415 | * it more efficient than reusing j |
| 1416 | */ |
| 1417 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1418 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1419 | /* page alloc/put takes too long and effects small |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1420 | * packet throughput, so unsplit small packets and |
| 1421 | * save the alloc/put only valid in softirq (napi) |
| 1422 | * context to call kmap_* |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1423 | */ |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1424 | if (l1 && (l1 <= copybreak) && |
| 1425 | ((length + l1) <= adapter->rx_ps_bsize0)) { |
| 1426 | u8 *vaddr; |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 1427 | |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1428 | ps_page = &buffer_info->ps_pages[0]; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1429 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1430 | /* there is no documentation about how to call |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1431 | * kmap_atomic, so we can't hold the mapping |
| 1432 | * very long |
| 1433 | */ |
| 1434 | dma_sync_single_for_cpu(&pdev->dev, |
| 1435 | ps_page->dma, |
| 1436 | PAGE_SIZE, |
| 1437 | DMA_FROM_DEVICE); |
Linus Torvalds | 9f39383 | 2012-03-21 09:40:26 -0700 | [diff] [blame] | 1438 | vaddr = kmap_atomic(ps_page->page); |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1439 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
Linus Torvalds | 9f39383 | 2012-03-21 09:40:26 -0700 | [diff] [blame] | 1440 | kunmap_atomic(vaddr); |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1441 | dma_sync_single_for_device(&pdev->dev, |
| 1442 | ps_page->dma, |
| 1443 | PAGE_SIZE, |
| 1444 | DMA_FROM_DEVICE); |
| 1445 | |
| 1446 | /* remove the CRC */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 1447 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 1448 | if (!(netdev->features & NETIF_F_RXFCS)) |
| 1449 | l1 -= 4; |
| 1450 | } |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1451 | |
| 1452 | skb_put(skb, l1); |
| 1453 | goto copydone; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 1454 | } /* if */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
| 1458 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); |
| 1459 | if (!length) |
| 1460 | break; |
| 1461 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1462 | ps_page = &buffer_info->ps_pages[j]; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1463 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1464 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1465 | ps_page->dma = 0; |
| 1466 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); |
| 1467 | ps_page->page = NULL; |
| 1468 | skb->len += length; |
| 1469 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1470 | skb->truesize += PAGE_SIZE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1471 | } |
| 1472 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1473 | /* strip the ethernet crc, problem is we're using pages now so |
| 1474 | * this whole operation can get a little cpu intensive |
| 1475 | */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 1476 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 1477 | if (!(netdev->features & NETIF_F_RXFCS)) |
| 1478 | pskb_trim(skb, skb->len - 4); |
| 1479 | } |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1480 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1481 | copydone: |
| 1482 | total_rx_bytes += skb->len; |
| 1483 | total_rx_packets++; |
| 1484 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1485 | e1000_rx_checksum(adapter, staterr, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1486 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1487 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1488 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1489 | if (rx_desc->wb.upper.header_status & |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1490 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1491 | adapter->rx_hdr_split++; |
| 1492 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1493 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1494 | rx_desc->wb.middle.vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1495 | |
| 1496 | next_desc: |
| 1497 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
| 1498 | buffer_info->skb = NULL; |
| 1499 | |
| 1500 | /* return some buffers to hardware, one at a time is too slow */ |
| 1501 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1502 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1503 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1504 | cleaned_count = 0; |
| 1505 | } |
| 1506 | |
| 1507 | /* use prefetched values */ |
| 1508 | rx_desc = next_rxd; |
| 1509 | buffer_info = next_buffer; |
| 1510 | |
| 1511 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1512 | } |
| 1513 | rx_ring->next_to_clean = i; |
| 1514 | |
| 1515 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1516 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1517 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1518 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1519 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1520 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1521 | return cleaned; |
| 1522 | } |
| 1523 | |
| 1524 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1525 | * e1000_consume_page - helper function |
| 1526 | **/ |
| 1527 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
Bruce Allan | 66501f5 | 2013-02-20 04:05:55 +0000 | [diff] [blame] | 1528 | u16 length) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1529 | { |
| 1530 | bi->page = NULL; |
| 1531 | skb->len += length; |
| 1532 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1533 | skb->truesize += PAGE_SIZE; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | /** |
| 1537 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 1538 | * @adapter: board private structure |
| 1539 | * |
| 1540 | * the return value indicates whether actual cleaning was done, there |
| 1541 | * is no guarantee that everything was cleaned |
| 1542 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1543 | static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
| 1544 | int work_to_do) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1545 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1546 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1547 | struct net_device *netdev = adapter->netdev; |
| 1548 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1549 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1550 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1551 | u32 length, staterr; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1552 | unsigned int i; |
| 1553 | int cleaned_count = 0; |
| 1554 | bool cleaned = false; |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 1555 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1556 | struct skb_shared_info *shinfo; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1557 | |
| 1558 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1559 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 1560 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1561 | buffer_info = &rx_ring->buffer_info[i]; |
| 1562 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1563 | while (staterr & E1000_RXD_STAT_DD) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1564 | struct sk_buff *skb; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1565 | |
| 1566 | if (*work_done >= work_to_do) |
| 1567 | break; |
| 1568 | (*work_done)++; |
Alexander Duyck | 837a1db | 2015-04-07 16:55:27 -0700 | [diff] [blame] | 1569 | dma_rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1570 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1571 | skb = buffer_info->skb; |
| 1572 | buffer_info->skb = NULL; |
| 1573 | |
| 1574 | ++i; |
| 1575 | if (i == rx_ring->count) |
| 1576 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1577 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1578 | prefetch(next_rxd); |
| 1579 | |
| 1580 | next_buffer = &rx_ring->buffer_info[i]; |
| 1581 | |
| 1582 | cleaned = true; |
| 1583 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1584 | dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE, |
| 1585 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1586 | buffer_info->dma = 0; |
| 1587 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1588 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1589 | |
| 1590 | /* errors is only valid for DD + EOP descriptors */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1591 | if (unlikely((staterr & E1000_RXD_STAT_EOP) && |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 1592 | ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 1593 | !(netdev->features & NETIF_F_RXALL)))) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1594 | /* recycle both page and skb */ |
| 1595 | buffer_info->skb = skb; |
| 1596 | /* an error means any chain goes out the window too */ |
| 1597 | if (rx_ring->rx_skb_top) |
| 1598 | dev_kfree_skb_irq(rx_ring->rx_skb_top); |
| 1599 | rx_ring->rx_skb_top = NULL; |
| 1600 | goto next_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1601 | } |
Bruce Allan | f0f1a17 | 2010-12-11 05:53:32 +0000 | [diff] [blame] | 1602 | #define rxtop (rx_ring->rx_skb_top) |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1603 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1604 | /* this descriptor is only the beginning (or middle) */ |
| 1605 | if (!rxtop) { |
| 1606 | /* this is the beginning of a chain */ |
| 1607 | rxtop = skb; |
| 1608 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1609 | 0, length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1610 | } else { |
| 1611 | /* this is the middle of a chain */ |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1612 | shinfo = skb_shinfo(rxtop); |
| 1613 | skb_fill_page_desc(rxtop, shinfo->nr_frags, |
| 1614 | buffer_info->page, 0, |
| 1615 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1616 | /* re-use the skb, only consumed the page */ |
| 1617 | buffer_info->skb = skb; |
| 1618 | } |
| 1619 | e1000_consume_page(buffer_info, rxtop, length); |
| 1620 | goto next_desc; |
| 1621 | } else { |
| 1622 | if (rxtop) { |
| 1623 | /* end of the chain */ |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1624 | shinfo = skb_shinfo(rxtop); |
| 1625 | skb_fill_page_desc(rxtop, shinfo->nr_frags, |
| 1626 | buffer_info->page, 0, |
| 1627 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1628 | /* re-use the current skb, we only consumed the |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1629 | * page |
| 1630 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1631 | buffer_info->skb = skb; |
| 1632 | skb = rxtop; |
| 1633 | rxtop = NULL; |
| 1634 | e1000_consume_page(buffer_info, skb, length); |
| 1635 | } else { |
| 1636 | /* no chain, got EOP, this buf is the packet |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1637 | * copybreak to save the put_page/alloc_page |
| 1638 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1639 | if (length <= copybreak && |
| 1640 | skb_tailroom(skb) >= length) { |
| 1641 | u8 *vaddr; |
Cong Wang | 4679026 | 2011-11-25 23:14:23 +0800 | [diff] [blame] | 1642 | vaddr = kmap_atomic(buffer_info->page); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1643 | memcpy(skb_tail_pointer(skb), vaddr, |
| 1644 | length); |
Cong Wang | 4679026 | 2011-11-25 23:14:23 +0800 | [diff] [blame] | 1645 | kunmap_atomic(vaddr); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1646 | /* re-use the page, so don't erase |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1647 | * buffer_info->page |
| 1648 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1649 | skb_put(skb, length); |
| 1650 | } else { |
| 1651 | skb_fill_page_desc(skb, 0, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1652 | buffer_info->page, 0, |
| 1653 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1654 | e1000_consume_page(buffer_info, skb, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1655 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1656 | } |
| 1657 | } |
| 1658 | } |
| 1659 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1660 | /* Receive Checksum Offload */ |
| 1661 | e1000_rx_checksum(adapter, staterr, skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1662 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1663 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1664 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1665 | /* probably a little skewed due to removing CRC */ |
| 1666 | total_rx_bytes += skb->len; |
| 1667 | total_rx_packets++; |
| 1668 | |
| 1669 | /* eth type trans needs skb->data to point to something */ |
| 1670 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1671 | e_err("pskb_may_pull failed.\n"); |
Bruce Allan | ef5ab89 | 2011-02-10 08:17:21 +0000 | [diff] [blame] | 1672 | dev_kfree_skb_irq(skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1673 | goto next_desc; |
| 1674 | } |
| 1675 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1676 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1677 | rx_desc->wb.upper.vlan); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1678 | |
| 1679 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1680 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1681 | |
| 1682 | /* return some buffers to hardware, one at a time is too slow */ |
| 1683 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1684 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1685 | GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1686 | cleaned_count = 0; |
| 1687 | } |
| 1688 | |
| 1689 | /* use prefetched values */ |
| 1690 | rx_desc = next_rxd; |
| 1691 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1692 | |
| 1693 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1694 | } |
| 1695 | rx_ring->next_to_clean = i; |
| 1696 | |
| 1697 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1698 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1699 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1700 | |
| 1701 | adapter->total_rx_bytes += total_rx_bytes; |
| 1702 | adapter->total_rx_packets += total_rx_packets; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1703 | return cleaned; |
| 1704 | } |
| 1705 | |
| 1706 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1707 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1708 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1709 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1710 | static void e1000_clean_rx_ring(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1711 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1712 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1713 | struct e1000_buffer *buffer_info; |
| 1714 | struct e1000_ps_page *ps_page; |
| 1715 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1716 | unsigned int i, j; |
| 1717 | |
| 1718 | /* Free all the Rx ring sk_buffs */ |
| 1719 | for (i = 0; i < rx_ring->count; i++) { |
| 1720 | buffer_info = &rx_ring->buffer_info[i]; |
| 1721 | if (buffer_info->dma) { |
| 1722 | if (adapter->clean_rx == e1000_clean_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1723 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1724 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1725 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1726 | else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1727 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1728 | PAGE_SIZE, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1729 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1730 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1731 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1732 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1733 | buffer_info->dma = 0; |
| 1734 | } |
| 1735 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1736 | if (buffer_info->page) { |
| 1737 | put_page(buffer_info->page); |
| 1738 | buffer_info->page = NULL; |
| 1739 | } |
| 1740 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1741 | if (buffer_info->skb) { |
| 1742 | dev_kfree_skb(buffer_info->skb); |
| 1743 | buffer_info->skb = NULL; |
| 1744 | } |
| 1745 | |
| 1746 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1747 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1748 | if (!ps_page->page) |
| 1749 | break; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1750 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1751 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1752 | ps_page->dma = 0; |
| 1753 | put_page(ps_page->page); |
| 1754 | ps_page->page = NULL; |
| 1755 | } |
| 1756 | } |
| 1757 | |
| 1758 | /* there also may be some cached data from a chained receive */ |
| 1759 | if (rx_ring->rx_skb_top) { |
| 1760 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 1761 | rx_ring->rx_skb_top = NULL; |
| 1762 | } |
| 1763 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1764 | /* Zero out the descriptor ring */ |
| 1765 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1766 | |
| 1767 | rx_ring->next_to_clean = 0; |
| 1768 | rx_ring->next_to_use = 0; |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1769 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1772 | static void e1000e_downshift_workaround(struct work_struct *work) |
| 1773 | { |
| 1774 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1775 | struct e1000_adapter, |
| 1776 | downshift_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1777 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1778 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1779 | return; |
| 1780 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1781 | e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); |
| 1782 | } |
| 1783 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1784 | /** |
| 1785 | * e1000_intr_msi - Interrupt Handler |
| 1786 | * @irq: interrupt number |
| 1787 | * @data: pointer to a network interface device structure |
| 1788 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1789 | static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1790 | { |
| 1791 | struct net_device *netdev = data; |
| 1792 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1793 | struct e1000_hw *hw = &adapter->hw; |
| 1794 | u32 icr = er32(ICR); |
| 1795 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1796 | /* read ICR disables interrupts using IAM */ |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1797 | if (icr & E1000_ICR_LSC) { |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1798 | hw->mac.get_link_status = true; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1799 | /* ICH8 workaround-- Call gig speed drop workaround on cable |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1800 | * disconnect (LSC) before accessing any PHY registers |
| 1801 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1802 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1803 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1804 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1805 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1806 | /* 80003ES2LAN workaround-- For packet buffer work-around on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1807 | * link down event; disable receives here in the ISR and reset |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1808 | * adapter in watchdog |
| 1809 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1810 | if (netif_carrier_ok(netdev) && |
| 1811 | adapter->flags & FLAG_RX_NEEDS_RESTART) { |
| 1812 | /* disable receives */ |
| 1813 | u32 rctl = er32(RCTL); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 1814 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1815 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 1816 | adapter->flags |= FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1817 | } |
| 1818 | /* guard against interrupt when we're going down */ |
| 1819 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 1820 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1823 | /* Reset on uncorrectable ECC error */ |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 1824 | if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) { |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1825 | u32 pbeccsts = er32(PBECCSTS); |
| 1826 | |
| 1827 | adapter->corr_errors += |
| 1828 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 1829 | adapter->uncorr_errors += |
| 1830 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 1831 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 1832 | |
| 1833 | /* Do the reset outside of interrupt context */ |
| 1834 | schedule_work(&adapter->reset_task); |
| 1835 | |
| 1836 | /* return immediately since reset is imminent */ |
| 1837 | return IRQ_HANDLED; |
| 1838 | } |
| 1839 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1840 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1841 | adapter->total_tx_bytes = 0; |
| 1842 | adapter->total_tx_packets = 0; |
| 1843 | adapter->total_rx_bytes = 0; |
| 1844 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1845 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | return IRQ_HANDLED; |
| 1849 | } |
| 1850 | |
| 1851 | /** |
| 1852 | * e1000_intr - Interrupt Handler |
| 1853 | * @irq: interrupt number |
| 1854 | * @data: pointer to a network interface device structure |
| 1855 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1856 | static irqreturn_t e1000_intr(int __always_unused irq, void *data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1857 | { |
| 1858 | struct net_device *netdev = data; |
| 1859 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1860 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1861 | u32 rctl, icr = er32(ICR); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1862 | |
Bruce Allan | a68ea77 | 2009-11-20 23:23:16 +0000 | [diff] [blame] | 1863 | if (!icr || test_bit(__E1000_DOWN, &adapter->state)) |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 1864 | return IRQ_NONE; /* Not our interrupt */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1865 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1866 | /* 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] | 1867 | * not set, then the adapter didn't send an interrupt |
| 1868 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1869 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 1870 | return IRQ_NONE; |
| 1871 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1872 | /* Interrupt Auto-Mask...upon reading ICR, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1873 | * interrupts are masked. No need for the |
| 1874 | * IMC write |
| 1875 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1876 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1877 | if (icr & E1000_ICR_LSC) { |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1878 | hw->mac.get_link_status = true; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1879 | /* ICH8 workaround-- Call gig speed drop workaround on cable |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1880 | * disconnect (LSC) before accessing any PHY registers |
| 1881 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1882 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1883 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1884 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1885 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1886 | /* 80003ES2LAN workaround-- |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1887 | * For packet buffer work-around on link down event; |
| 1888 | * disable receives here in the ISR and |
| 1889 | * reset adapter in watchdog |
| 1890 | */ |
| 1891 | if (netif_carrier_ok(netdev) && |
| 1892 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { |
| 1893 | /* disable receives */ |
| 1894 | rctl = er32(RCTL); |
| 1895 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 1896 | adapter->flags |= FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1897 | } |
| 1898 | /* guard against interrupt when we're going down */ |
| 1899 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 1900 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1903 | /* Reset on uncorrectable ECC error */ |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 1904 | if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) { |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1905 | u32 pbeccsts = er32(PBECCSTS); |
| 1906 | |
| 1907 | adapter->corr_errors += |
| 1908 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 1909 | adapter->uncorr_errors += |
| 1910 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 1911 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 1912 | |
| 1913 | /* Do the reset outside of interrupt context */ |
| 1914 | schedule_work(&adapter->reset_task); |
| 1915 | |
| 1916 | /* return immediately since reset is imminent */ |
| 1917 | return IRQ_HANDLED; |
| 1918 | } |
| 1919 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1920 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1921 | adapter->total_tx_bytes = 0; |
| 1922 | adapter->total_tx_packets = 0; |
| 1923 | adapter->total_rx_bytes = 0; |
| 1924 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1925 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | return IRQ_HANDLED; |
| 1929 | } |
| 1930 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1931 | static irqreturn_t e1000_msix_other(int __always_unused irq, void *data) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1932 | { |
| 1933 | struct net_device *netdev = data; |
| 1934 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1935 | struct e1000_hw *hw = &adapter->hw; |
Benjamin Poirier | 116f4a6 | 2018-02-08 15:47:14 +0900 | [diff] [blame] | 1936 | u32 icr = er32(ICR); |
Benjamin Poirier | 745d0bd | 2018-01-31 16:26:27 +0900 | [diff] [blame] | 1937 | |
Benjamin Poirier | 361a954 | 2018-02-08 15:47:13 +0900 | [diff] [blame] | 1938 | if (icr & adapter->eiac_mask) |
| 1939 | ew32(ICS, (icr & adapter->eiac_mask)); |
| 1940 | |
Benjamin Poirier | 4aea7a5c | 2017-07-21 11:36:27 -0700 | [diff] [blame] | 1941 | if (icr & E1000_ICR_LSC) { |
Benjamin Poirier | 4aea7a5c | 2017-07-21 11:36:27 -0700 | [diff] [blame] | 1942 | hw->mac.get_link_status = true; |
| 1943 | /* guard against interrupt when we're going down */ |
| 1944 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 1945 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Benjamin Poirier | 4aea7a5c | 2017-07-21 11:36:27 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
Benjamin Poirier | 1f0ea19 | 2018-02-08 15:47:12 +0900 | [diff] [blame] | 1948 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
Benjamin Poirier | 116f4a6 | 2018-02-08 15:47:14 +0900 | [diff] [blame] | 1949 | ew32(IMS, E1000_IMS_OTHER | IMS_OTHER_MASK); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1950 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1951 | return IRQ_HANDLED; |
| 1952 | } |
| 1953 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1954 | 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] | 1955 | { |
| 1956 | struct net_device *netdev = data; |
| 1957 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1958 | struct e1000_hw *hw = &adapter->hw; |
| 1959 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1960 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1961 | adapter->total_tx_bytes = 0; |
| 1962 | adapter->total_tx_packets = 0; |
| 1963 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1964 | if (!e1000_clean_tx_irq(tx_ring)) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1965 | /* Ring was not completely cleaned, so fire another interrupt */ |
| 1966 | ew32(ICS, tx_ring->ims_val); |
| 1967 | |
Benjamin Poirier | 0a8047a | 2015-11-09 15:50:21 -0800 | [diff] [blame] | 1968 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1969 | ew32(IMS, adapter->tx_ring->ims_val); |
| 1970 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1971 | return IRQ_HANDLED; |
| 1972 | } |
| 1973 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1974 | 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] | 1975 | { |
| 1976 | struct net_device *netdev = data; |
| 1977 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1978 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1979 | |
| 1980 | /* Write the ITR value calculated at the end of the |
| 1981 | * previous interrupt. |
| 1982 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1983 | if (rx_ring->set_itr) { |
Dmitry Fleytman | b77ac46 | 2015-10-13 12:48:18 +0300 | [diff] [blame] | 1984 | u32 itr = rx_ring->itr_val ? |
| 1985 | 1000000000 / (rx_ring->itr_val * 256) : 0; |
| 1986 | |
| 1987 | writel(itr, rx_ring->itr_register); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1988 | rx_ring->set_itr = 0; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1991 | if (napi_schedule_prep(&adapter->napi)) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1992 | adapter->total_rx_bytes = 0; |
| 1993 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1994 | __napi_schedule(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1995 | } |
| 1996 | return IRQ_HANDLED; |
| 1997 | } |
| 1998 | |
| 1999 | /** |
| 2000 | * e1000_configure_msix - Configure MSI-X hardware |
| 2001 | * |
| 2002 | * e1000_configure_msix sets up the hardware to properly |
| 2003 | * generate MSI-X interrupts. |
| 2004 | **/ |
| 2005 | static void e1000_configure_msix(struct e1000_adapter *adapter) |
| 2006 | { |
| 2007 | struct e1000_hw *hw = &adapter->hw; |
| 2008 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 2009 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2010 | int vector = 0; |
| 2011 | u32 ctrl_ext, ivar = 0; |
| 2012 | |
| 2013 | adapter->eiac_mask = 0; |
| 2014 | |
| 2015 | /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ |
| 2016 | if (hw->mac.type == e1000_82574) { |
| 2017 | u32 rfctl = er32(RFCTL); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 2018 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2019 | rfctl |= E1000_RFCTL_ACK_DIS; |
| 2020 | ew32(RFCTL, rfctl); |
| 2021 | } |
| 2022 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2023 | /* Configure Rx vector */ |
| 2024 | rx_ring->ims_val = E1000_IMS_RXQ0; |
| 2025 | adapter->eiac_mask |= rx_ring->ims_val; |
| 2026 | if (rx_ring->itr_val) |
| 2027 | writel(1000000000 / (rx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2028 | rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2029 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2030 | writel(1, rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2031 | ivar = E1000_IVAR_INT_ALLOC_VALID | vector; |
| 2032 | |
| 2033 | /* Configure Tx vector */ |
| 2034 | tx_ring->ims_val = E1000_IMS_TXQ0; |
| 2035 | vector++; |
| 2036 | if (tx_ring->itr_val) |
| 2037 | writel(1000000000 / (tx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2038 | tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2039 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2040 | writel(1, tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2041 | adapter->eiac_mask |= tx_ring->ims_val; |
| 2042 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); |
| 2043 | |
| 2044 | /* set vector for Other Causes, e.g. link changes */ |
| 2045 | vector++; |
| 2046 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); |
| 2047 | if (rx_ring->itr_val) |
| 2048 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 2049 | hw->hw_addr + E1000_EITR_82574(vector)); |
| 2050 | else |
| 2051 | writel(1, hw->hw_addr + E1000_EITR_82574(vector)); |
| 2052 | |
| 2053 | /* Cause Tx interrupts on every write back */ |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 2054 | ivar |= BIT(31); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2055 | |
| 2056 | ew32(IVAR, ivar); |
| 2057 | |
| 2058 | /* enable MSI-X PBA support */ |
Benjamin Poirier | 0a8047a | 2015-11-09 15:50:21 -0800 | [diff] [blame] | 2059 | ctrl_ext = er32(CTRL_EXT) & ~E1000_CTRL_EXT_IAME; |
| 2060 | ctrl_ext |= E1000_CTRL_EXT_PBA_CLR | E1000_CTRL_EXT_EIAME; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2061 | ew32(CTRL_EXT, ctrl_ext); |
| 2062 | e1e_flush(); |
| 2063 | } |
| 2064 | |
| 2065 | void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) |
| 2066 | { |
| 2067 | if (adapter->msix_entries) { |
| 2068 | pci_disable_msix(adapter->pdev); |
| 2069 | kfree(adapter->msix_entries); |
| 2070 | adapter->msix_entries = NULL; |
| 2071 | } else if (adapter->flags & FLAG_MSI_ENABLED) { |
| 2072 | pci_disable_msi(adapter->pdev); |
| 2073 | adapter->flags &= ~FLAG_MSI_ENABLED; |
| 2074 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | /** |
| 2078 | * e1000e_set_interrupt_capability - set MSI or MSI-X if supported |
| 2079 | * |
| 2080 | * Attempt to configure interrupts using the best available |
| 2081 | * capabilities of the hardware and kernel. |
| 2082 | **/ |
| 2083 | void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) |
| 2084 | { |
| 2085 | int err; |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2086 | int i; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2087 | |
| 2088 | switch (adapter->int_mode) { |
| 2089 | case E1000E_INT_MODE_MSIX: |
| 2090 | if (adapter->flags & FLAG_HAS_MSIX) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2091 | adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */ |
| 2092 | adapter->msix_entries = kcalloc(adapter->num_vectors, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 2093 | sizeof(struct |
| 2094 | msix_entry), |
| 2095 | GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2096 | if (adapter->msix_entries) { |
Alexander Gordeev | 0cc7c95 | 2014-02-18 11:11:41 +0100 | [diff] [blame] | 2097 | struct e1000_adapter *a = adapter; |
| 2098 | |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2099 | for (i = 0; i < adapter->num_vectors; i++) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2100 | adapter->msix_entries[i].entry = i; |
| 2101 | |
Alexander Gordeev | 0cc7c95 | 2014-02-18 11:11:41 +0100 | [diff] [blame] | 2102 | err = pci_enable_msix_range(a->pdev, |
| 2103 | a->msix_entries, |
| 2104 | a->num_vectors, |
| 2105 | a->num_vectors); |
| 2106 | if (err > 0) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2107 | return; |
| 2108 | } |
| 2109 | /* MSI-X failed, so fall through and try MSI */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 2110 | 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] | 2111 | e1000e_reset_interrupt_capability(adapter); |
| 2112 | } |
| 2113 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 2114 | /* Fall through */ |
| 2115 | case E1000E_INT_MODE_MSI: |
| 2116 | if (!pci_enable_msi(adapter->pdev)) { |
| 2117 | adapter->flags |= FLAG_MSI_ENABLED; |
| 2118 | } else { |
| 2119 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 2120 | 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] | 2121 | } |
| 2122 | /* Fall through */ |
| 2123 | case E1000E_INT_MODE_LEGACY: |
| 2124 | /* Don't do anything; this is the system default */ |
| 2125 | break; |
| 2126 | } |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2127 | |
| 2128 | /* store the number of vectors being used */ |
| 2129 | adapter->num_vectors = 1; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | /** |
| 2133 | * e1000_request_msix - Initialize MSI-X interrupts |
| 2134 | * |
| 2135 | * e1000_request_msix allocates MSI-X vectors and requests interrupts from the |
| 2136 | * kernel. |
| 2137 | **/ |
| 2138 | static int e1000_request_msix(struct e1000_adapter *adapter) |
| 2139 | { |
| 2140 | struct net_device *netdev = adapter->netdev; |
| 2141 | int err = 0, vector = 0; |
| 2142 | |
| 2143 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 2144 | snprintf(adapter->rx_ring->name, |
| 2145 | sizeof(adapter->rx_ring->name) - 1, |
Florian Fainelli | 135e724 | 2019-02-21 20:09:28 -0800 | [diff] [blame] | 2146 | "%.14s-rx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2147 | else |
| 2148 | memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); |
| 2149 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2150 | e1000_intr_msix_rx, 0, adapter->rx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2151 | netdev); |
| 2152 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2153 | return err; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2154 | adapter->rx_ring->itr_register = adapter->hw.hw_addr + |
| 2155 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2156 | adapter->rx_ring->itr_val = adapter->itr; |
| 2157 | vector++; |
| 2158 | |
| 2159 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 2160 | snprintf(adapter->tx_ring->name, |
| 2161 | sizeof(adapter->tx_ring->name) - 1, |
Florian Fainelli | 135e724 | 2019-02-21 20:09:28 -0800 | [diff] [blame] | 2162 | "%.14s-tx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2163 | else |
| 2164 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); |
| 2165 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2166 | e1000_intr_msix_tx, 0, adapter->tx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2167 | netdev); |
| 2168 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2169 | return err; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2170 | adapter->tx_ring->itr_register = adapter->hw.hw_addr + |
| 2171 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2172 | adapter->tx_ring->itr_val = adapter->itr; |
| 2173 | vector++; |
| 2174 | |
| 2175 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2176 | e1000_msix_other, 0, netdev->name, netdev); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2177 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2178 | return err; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2179 | |
| 2180 | e1000_configure_msix(adapter); |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2181 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2182 | return 0; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2183 | } |
| 2184 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2185 | /** |
| 2186 | * e1000_request_irq - initialize interrupts |
| 2187 | * |
| 2188 | * Attempts to configure interrupts using the best available |
| 2189 | * capabilities of the hardware and kernel. |
| 2190 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2191 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 2192 | { |
| 2193 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2194 | int err; |
| 2195 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2196 | if (adapter->msix_entries) { |
| 2197 | err = e1000_request_msix(adapter); |
| 2198 | if (!err) |
| 2199 | return err; |
| 2200 | /* fall back to MSI */ |
| 2201 | e1000e_reset_interrupt_capability(adapter); |
| 2202 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 2203 | e1000e_set_interrupt_capability(adapter); |
| 2204 | } |
| 2205 | if (adapter->flags & FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2206 | err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2207 | netdev->name, netdev); |
| 2208 | if (!err) |
| 2209 | return err; |
| 2210 | |
| 2211 | /* fall back to legacy interrupt */ |
| 2212 | e1000e_reset_interrupt_capability(adapter); |
| 2213 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2214 | } |
| 2215 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2216 | err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2217 | netdev->name, netdev); |
| 2218 | if (err) |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2219 | e_err("Unable to allocate interrupt, Error: %d\n", err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2220 | |
| 2221 | return err; |
| 2222 | } |
| 2223 | |
| 2224 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 2225 | { |
| 2226 | struct net_device *netdev = adapter->netdev; |
| 2227 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2228 | if (adapter->msix_entries) { |
| 2229 | int vector = 0; |
| 2230 | |
| 2231 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2232 | vector++; |
| 2233 | |
| 2234 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2235 | vector++; |
| 2236 | |
| 2237 | /* Other Causes interrupt vector */ |
| 2238 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2239 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2240 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2241 | |
| 2242 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2243 | } |
| 2244 | |
| 2245 | /** |
| 2246 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 2247 | **/ |
| 2248 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
| 2249 | { |
| 2250 | struct e1000_hw *hw = &adapter->hw; |
| 2251 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2252 | ew32(IMC, ~0); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2253 | if (adapter->msix_entries) |
| 2254 | ew32(EIAC_82574, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2255 | e1e_flush(); |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2256 | |
| 2257 | if (adapter->msix_entries) { |
| 2258 | int i; |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 2259 | |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2260 | for (i = 0; i < adapter->num_vectors; i++) |
| 2261 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2262 | } else { |
| 2263 | synchronize_irq(adapter->pdev->irq); |
| 2264 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | /** |
| 2268 | * e1000_irq_enable - Enable default interrupt generation settings |
| 2269 | **/ |
| 2270 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
| 2271 | { |
| 2272 | struct e1000_hw *hw = &adapter->hw; |
| 2273 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2274 | if (adapter->msix_entries) { |
| 2275 | ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); |
Benjamin Poirier | 116f4a6 | 2018-02-08 15:47:14 +0900 | [diff] [blame] | 2276 | ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | |
| 2277 | IMS_OTHER_MASK); |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 2278 | } else if (hw->mac.type >= e1000_pch_lpt) { |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 2279 | ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2280 | } else { |
| 2281 | ew32(IMS, IMS_ENABLE_MASK); |
| 2282 | } |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 2283 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2287 | * 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] | 2288 | * @adapter: address of board private structure |
| 2289 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2290 | * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2291 | * For ASF and Pass Through versions of f/w this means that |
| 2292 | * the driver is loaded. For AMT version (only with 82573) |
| 2293 | * of the f/w this means that the network i/f is open. |
| 2294 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2295 | void e1000e_get_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2296 | { |
| 2297 | struct e1000_hw *hw = &adapter->hw; |
| 2298 | u32 ctrl_ext; |
| 2299 | u32 swsm; |
| 2300 | |
| 2301 | /* Let firmware know the driver has taken over */ |
| 2302 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2303 | swsm = er32(SWSM); |
| 2304 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
| 2305 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2306 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2307 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2312 | * 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] | 2313 | * @adapter: address of board private structure |
| 2314 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2315 | * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2316 | * For ASF and Pass Through versions of f/w this means that the |
| 2317 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 2318 | * of the f/w this means that the network i/f is closed. |
| 2319 | * |
| 2320 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2321 | void e1000e_release_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2322 | { |
| 2323 | struct e1000_hw *hw = &adapter->hw; |
| 2324 | u32 ctrl_ext; |
| 2325 | u32 swsm; |
| 2326 | |
| 2327 | /* Let firmware taken over control of h/w */ |
| 2328 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2329 | swsm = er32(SWSM); |
| 2330 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
| 2331 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2332 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2333 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2334 | } |
| 2335 | } |
| 2336 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2337 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 2338 | * e1000_alloc_ring_dma - allocate memory for a ring structure |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2339 | **/ |
| 2340 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, |
| 2341 | struct e1000_ring *ring) |
| 2342 | { |
| 2343 | struct pci_dev *pdev = adapter->pdev; |
| 2344 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 2345 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, |
| 2346 | GFP_KERNEL); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2347 | if (!ring->desc) |
| 2348 | return -ENOMEM; |
| 2349 | |
| 2350 | return 0; |
| 2351 | } |
| 2352 | |
| 2353 | /** |
| 2354 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2355 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2356 | * |
| 2357 | * Return 0 on success, negative on failure |
| 2358 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2359 | int e1000e_setup_tx_resources(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2360 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2361 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2362 | int err = -ENOMEM, size; |
| 2363 | |
| 2364 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2365 | tx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2366 | if (!tx_ring->buffer_info) |
| 2367 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2368 | |
| 2369 | /* round up to nearest 4K */ |
| 2370 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
| 2371 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2372 | |
| 2373 | err = e1000_alloc_ring_dma(adapter, tx_ring); |
| 2374 | if (err) |
| 2375 | goto err; |
| 2376 | |
| 2377 | tx_ring->next_to_use = 0; |
| 2378 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2379 | |
| 2380 | return 0; |
| 2381 | err: |
| 2382 | vfree(tx_ring->buffer_info); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 2383 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2384 | return err; |
| 2385 | } |
| 2386 | |
| 2387 | /** |
| 2388 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2389 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2390 | * |
| 2391 | * Returns 0 on success, negative on failure |
| 2392 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2393 | int e1000e_setup_rx_resources(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2394 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2395 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2396 | struct e1000_buffer *buffer_info; |
| 2397 | int i, size, desc_len, err = -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2398 | |
| 2399 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2400 | rx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2401 | if (!rx_ring->buffer_info) |
| 2402 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2403 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2404 | for (i = 0; i < rx_ring->count; i++) { |
| 2405 | buffer_info = &rx_ring->buffer_info[i]; |
| 2406 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, |
| 2407 | sizeof(struct e1000_ps_page), |
| 2408 | GFP_KERNEL); |
| 2409 | if (!buffer_info->ps_pages) |
| 2410 | goto err_pages; |
| 2411 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2412 | |
| 2413 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 2414 | |
| 2415 | /* Round up to nearest 4K */ |
| 2416 | rx_ring->size = rx_ring->count * desc_len; |
| 2417 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2418 | |
| 2419 | err = e1000_alloc_ring_dma(adapter, rx_ring); |
| 2420 | if (err) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2421 | goto err_pages; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2422 | |
| 2423 | rx_ring->next_to_clean = 0; |
| 2424 | rx_ring->next_to_use = 0; |
| 2425 | rx_ring->rx_skb_top = NULL; |
| 2426 | |
| 2427 | return 0; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2428 | |
| 2429 | err_pages: |
| 2430 | for (i = 0; i < rx_ring->count; i++) { |
| 2431 | buffer_info = &rx_ring->buffer_info[i]; |
| 2432 | kfree(buffer_info->ps_pages); |
| 2433 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2434 | err: |
| 2435 | vfree(rx_ring->buffer_info); |
Bruce Allan | e926244 | 2010-11-24 06:02:06 +0000 | [diff] [blame] | 2436 | e_err("Unable to allocate memory for the receive descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2437 | return err; |
| 2438 | } |
| 2439 | |
| 2440 | /** |
| 2441 | * e1000_clean_tx_ring - Free Tx Buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2442 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2443 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2444 | static void e1000_clean_tx_ring(struct e1000_ring *tx_ring) |
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 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2447 | struct e1000_buffer *buffer_info; |
| 2448 | unsigned long size; |
| 2449 | unsigned int i; |
| 2450 | |
| 2451 | for (i = 0; i < tx_ring->count; i++) { |
| 2452 | buffer_info = &tx_ring->buffer_info[i]; |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 2453 | e1000_put_txbuf(tx_ring, buffer_info, false); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 2456 | netdev_reset_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2457 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2458 | memset(tx_ring->buffer_info, 0, size); |
| 2459 | |
| 2460 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2461 | |
| 2462 | tx_ring->next_to_use = 0; |
| 2463 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | /** |
| 2467 | * e1000e_free_tx_resources - Free Tx Resources per Queue |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2468 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2469 | * |
| 2470 | * Free all transmit software resources |
| 2471 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2472 | void e1000e_free_tx_resources(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2473 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2474 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2475 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2476 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2477 | e1000_clean_tx_ring(tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2478 | |
| 2479 | vfree(tx_ring->buffer_info); |
| 2480 | tx_ring->buffer_info = NULL; |
| 2481 | |
| 2482 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 2483 | tx_ring->dma); |
| 2484 | tx_ring->desc = NULL; |
| 2485 | } |
| 2486 | |
| 2487 | /** |
| 2488 | * e1000e_free_rx_resources - Free Rx Resources |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2489 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2490 | * |
| 2491 | * Free all receive software resources |
| 2492 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2493 | void e1000e_free_rx_resources(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2494 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2495 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2496 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2497 | int i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2498 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2499 | e1000_clean_rx_ring(rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2500 | |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2501 | for (i = 0; i < rx_ring->count; i++) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2502 | kfree(rx_ring->buffer_info[i].ps_pages); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2503 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2504 | vfree(rx_ring->buffer_info); |
| 2505 | rx_ring->buffer_info = NULL; |
| 2506 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2507 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 2508 | rx_ring->dma); |
| 2509 | rx_ring->desc = NULL; |
| 2510 | } |
| 2511 | |
| 2512 | /** |
| 2513 | * e1000_update_itr - update the dynamic ITR value based on statistics |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2514 | * @adapter: pointer to adapter |
| 2515 | * @itr_setting: current adapter->itr |
| 2516 | * @packets: the number of packets during this measurement interval |
| 2517 | * @bytes: the number of bytes during this measurement interval |
| 2518 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2519 | * Stores a new ITR value based on packets and byte |
| 2520 | * counts during the last interrupt. The advantage of per interrupt |
| 2521 | * computation is faster updates and more accurate ITR for the current |
| 2522 | * traffic pattern. Constants in this function were computed |
| 2523 | * based on theoretical maximum wire speed and thresholds were set based |
| 2524 | * on testing data as well as attempting to minimize response time |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2525 | * while increasing bulk throughput. This functionality is controlled |
| 2526 | * by the InterruptThrottleRate module parameter. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2527 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2528 | 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] | 2529 | { |
| 2530 | unsigned int retval = itr_setting; |
| 2531 | |
| 2532 | if (packets == 0) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2533 | return itr_setting; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2534 | |
| 2535 | switch (itr_setting) { |
| 2536 | case lowest_latency: |
| 2537 | /* handle TSO and jumbo frames */ |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2538 | if (bytes / packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2539 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2540 | else if ((packets < 5) && (bytes > 512)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2541 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2542 | break; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 2543 | case low_latency: /* 50 usec aka 20000 ints/s */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2544 | if (bytes > 10000) { |
| 2545 | /* this if handles the TSO accounting */ |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2546 | if (bytes / packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2547 | retval = bulk_latency; |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2548 | else if ((packets < 10) || ((bytes / packets) > 1200)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2549 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2550 | else if ((packets > 35)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2551 | retval = lowest_latency; |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2552 | } else if (bytes / packets > 2000) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2553 | retval = bulk_latency; |
| 2554 | } else if (packets <= 2 && bytes < 512) { |
| 2555 | retval = lowest_latency; |
| 2556 | } |
| 2557 | break; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 2558 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2559 | if (bytes > 25000) { |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2560 | if (packets > 35) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2561 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2562 | } else if (bytes < 6000) { |
| 2563 | retval = low_latency; |
| 2564 | } |
| 2565 | break; |
| 2566 | } |
| 2567 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2568 | return retval; |
| 2569 | } |
| 2570 | |
| 2571 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2572 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2573 | u16 current_itr; |
| 2574 | u32 new_itr = adapter->itr; |
| 2575 | |
| 2576 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2577 | if (adapter->link_speed != SPEED_1000) { |
| 2578 | current_itr = 0; |
| 2579 | new_itr = 4000; |
| 2580 | goto set_itr_now; |
| 2581 | } |
| 2582 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2583 | if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 2584 | new_itr = 0; |
| 2585 | goto set_itr_now; |
| 2586 | } |
| 2587 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2588 | adapter->tx_itr = e1000_update_itr(adapter->tx_itr, |
| 2589 | adapter->total_tx_packets, |
| 2590 | adapter->total_tx_bytes); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2591 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2592 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2593 | adapter->tx_itr = low_latency; |
| 2594 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2595 | adapter->rx_itr = e1000_update_itr(adapter->rx_itr, |
| 2596 | adapter->total_rx_packets, |
| 2597 | adapter->total_rx_bytes); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2598 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2599 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2600 | adapter->rx_itr = low_latency; |
| 2601 | |
| 2602 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2603 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2604 | /* counts and packets in update_itr are dependent on these numbers */ |
Bruce Allan | 33550ce | 2013-02-20 04:06:16 +0000 | [diff] [blame] | 2605 | switch (current_itr) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2606 | case lowest_latency: |
| 2607 | new_itr = 70000; |
| 2608 | break; |
| 2609 | case low_latency: |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 2610 | new_itr = 20000; /* aka hwitr = ~200 */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2611 | break; |
| 2612 | case bulk_latency: |
| 2613 | new_itr = 4000; |
| 2614 | break; |
| 2615 | default: |
| 2616 | break; |
| 2617 | } |
| 2618 | |
| 2619 | set_itr_now: |
| 2620 | if (new_itr != adapter->itr) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2621 | /* this attempts to bias the interrupt rate towards Bulk |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2622 | * by adding intermediate steps when interrupt rate is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2623 | * increasing |
| 2624 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2625 | new_itr = new_itr > adapter->itr ? |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 2626 | min(adapter->itr + (new_itr >> 2), new_itr) : new_itr; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2627 | adapter->itr = new_itr; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2628 | adapter->rx_ring->itr_val = new_itr; |
| 2629 | if (adapter->msix_entries) |
| 2630 | adapter->rx_ring->set_itr = 1; |
| 2631 | else |
Bruce Allan | e3d14b0 | 2012-12-05 06:26:51 +0000 | [diff] [blame] | 2632 | e1000e_write_itr(adapter, new_itr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | /** |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 2637 | * e1000e_write_itr - write the ITR value to the appropriate registers |
| 2638 | * @adapter: address of board private structure |
| 2639 | * @itr: new ITR value to program |
| 2640 | * |
| 2641 | * e1000e_write_itr determines if the adapter is in MSI-X mode |
| 2642 | * and, if so, writes the EITR registers with the ITR value. |
| 2643 | * Otherwise, it writes the ITR value into the ITR register. |
| 2644 | **/ |
| 2645 | void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr) |
| 2646 | { |
| 2647 | struct e1000_hw *hw = &adapter->hw; |
| 2648 | u32 new_itr = itr ? 1000000000 / (itr * 256) : 0; |
| 2649 | |
| 2650 | if (adapter->msix_entries) { |
| 2651 | int vector; |
| 2652 | |
| 2653 | for (vector = 0; vector < adapter->num_vectors; vector++) |
| 2654 | writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector)); |
| 2655 | } else { |
| 2656 | ew32(ITR, new_itr); |
| 2657 | } |
| 2658 | } |
| 2659 | |
| 2660 | /** |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2661 | * e1000_alloc_queues - Allocate memory for all rings |
| 2662 | * @adapter: board private structure to initialize |
| 2663 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 2664 | static int e1000_alloc_queues(struct e1000_adapter *adapter) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2665 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2666 | int size = sizeof(struct e1000_ring); |
| 2667 | |
| 2668 | adapter->tx_ring = kzalloc(size, GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2669 | if (!adapter->tx_ring) |
| 2670 | goto err; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2671 | adapter->tx_ring->count = adapter->tx_ring_count; |
| 2672 | adapter->tx_ring->adapter = adapter; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2673 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2674 | adapter->rx_ring = kzalloc(size, GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2675 | if (!adapter->rx_ring) |
| 2676 | goto err; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2677 | adapter->rx_ring->count = adapter->rx_ring_count; |
| 2678 | adapter->rx_ring->adapter = adapter; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2679 | |
| 2680 | return 0; |
| 2681 | err: |
| 2682 | e_err("Unable to allocate memory for queues\n"); |
| 2683 | kfree(adapter->rx_ring); |
| 2684 | kfree(adapter->tx_ring); |
| 2685 | return -ENOMEM; |
| 2686 | } |
| 2687 | |
| 2688 | /** |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2689 | * e1000e_poll - NAPI Rx polling callback |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2690 | * @napi: struct associated with this polling callback |
Jesse Brandeburg | 0bcd952 | 2018-11-08 14:55:32 -0800 | [diff] [blame] | 2691 | * @budget: number of packets driver is allowed to process this poll |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2692 | **/ |
Jesse Brandeburg | 0bcd952 | 2018-11-08 14:55:32 -0800 | [diff] [blame] | 2693 | static int e1000e_poll(struct napi_struct *napi, int budget) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2694 | { |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2695 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, |
| 2696 | napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2697 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2698 | struct net_device *poll_dev = adapter->netdev; |
Andy Gospodarek | 679e8a0 | 2009-06-18 11:57:37 +0000 | [diff] [blame] | 2699 | int tx_cleaned = 1, work_done = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2700 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 2701 | adapter = netdev_priv(poll_dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2702 | |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2703 | if (!adapter->msix_entries || |
| 2704 | (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) |
| 2705 | tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2706 | |
Jesse Brandeburg | 0bcd952 | 2018-11-08 14:55:32 -0800 | [diff] [blame] | 2707 | adapter->clean_rx(adapter->rx_ring, &work_done, budget); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2708 | |
Jesse Brandeburg | 0bcd952 | 2018-11-08 14:55:32 -0800 | [diff] [blame] | 2709 | if (!tx_cleaned || work_done == budget) |
| 2710 | return budget; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2711 | |
Jesse Brandeburg | 0bcd952 | 2018-11-08 14:55:32 -0800 | [diff] [blame] | 2712 | /* Exit the polling mode, but don't re-enable interrupts if stack might |
| 2713 | * poll us due to busy-polling |
| 2714 | */ |
| 2715 | if (likely(napi_complete_done(napi, work_done))) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2716 | if (adapter->itr_setting & 3) |
| 2717 | e1000_set_itr(adapter); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 2718 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 2719 | if (adapter->msix_entries) |
Benjamin Poirier | 1f0ea19 | 2018-02-08 15:47:12 +0900 | [diff] [blame] | 2720 | ew32(IMS, adapter->rx_ring->ims_val); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 2721 | else |
| 2722 | e1000_irq_enable(adapter); |
| 2723 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | return work_done; |
| 2727 | } |
| 2728 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2729 | static int e1000_vlan_rx_add_vid(struct net_device *netdev, |
Bruce Allan | 603cdca | 2013-05-01 03:48:11 +0000 | [diff] [blame] | 2730 | __always_unused __be16 proto, u16 vid) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2731 | { |
| 2732 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2733 | struct e1000_hw *hw = &adapter->hw; |
| 2734 | u32 vfta, index; |
| 2735 | |
| 2736 | /* don't update vlan cookie if already programmed */ |
| 2737 | if ((adapter->hw.mng_cookie.status & |
| 2738 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2739 | (vid == adapter->mng_vlan_id)) |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2740 | return 0; |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2741 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2742 | /* add VID to filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2743 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2744 | index = (vid >> 5) & 0x7F; |
| 2745 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 2746 | vfta |= BIT((vid & 0x1F)); |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2747 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2748 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2749 | |
| 2750 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2751 | |
| 2752 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2753 | } |
| 2754 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2755 | static int e1000_vlan_rx_kill_vid(struct net_device *netdev, |
Bruce Allan | 603cdca | 2013-05-01 03:48:11 +0000 | [diff] [blame] | 2756 | __always_unused __be16 proto, u16 vid) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2757 | { |
| 2758 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2759 | struct e1000_hw *hw = &adapter->hw; |
| 2760 | u32 vfta, index; |
| 2761 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2762 | if ((adapter->hw.mng_cookie.status & |
| 2763 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2764 | (vid == adapter->mng_vlan_id)) { |
| 2765 | /* release control to f/w */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2766 | e1000e_release_hw_control(adapter); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2767 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | /* remove VID from filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2771 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2772 | index = (vid >> 5) & 0x7F; |
| 2773 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 2774 | vfta &= ~BIT((vid & 0x1F)); |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2775 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2776 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2777 | |
| 2778 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2779 | |
| 2780 | return 0; |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | /** |
| 2784 | * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering |
| 2785 | * @adapter: board private structure to initialize |
| 2786 | **/ |
| 2787 | static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter) |
| 2788 | { |
| 2789 | struct net_device *netdev = adapter->netdev; |
| 2790 | struct e1000_hw *hw = &adapter->hw; |
| 2791 | u32 rctl; |
| 2792 | |
| 2793 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2794 | /* disable VLAN receive filtering */ |
| 2795 | rctl = er32(RCTL); |
| 2796 | rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN); |
| 2797 | ew32(RCTL, rctl); |
| 2798 | |
| 2799 | if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2800 | e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), |
| 2801 | adapter->mng_vlan_id); |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2802 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 2803 | } |
| 2804 | } |
| 2805 | } |
| 2806 | |
| 2807 | /** |
| 2808 | * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering |
| 2809 | * @adapter: board private structure to initialize |
| 2810 | **/ |
| 2811 | static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter) |
| 2812 | { |
| 2813 | struct e1000_hw *hw = &adapter->hw; |
| 2814 | u32 rctl; |
| 2815 | |
| 2816 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2817 | /* enable VLAN receive filtering */ |
| 2818 | rctl = er32(RCTL); |
| 2819 | rctl |= E1000_RCTL_VFE; |
| 2820 | rctl &= ~E1000_RCTL_CFIEN; |
| 2821 | ew32(RCTL, rctl); |
| 2822 | } |
| 2823 | } |
| 2824 | |
| 2825 | /** |
Jarod Wilson | 889ad45 | 2016-06-28 20:41:31 -0700 | [diff] [blame] | 2826 | * e1000e_vlan_strip_disable - helper to disable HW VLAN stripping |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2827 | * @adapter: board private structure to initialize |
| 2828 | **/ |
| 2829 | static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter) |
| 2830 | { |
| 2831 | struct e1000_hw *hw = &adapter->hw; |
| 2832 | u32 ctrl; |
| 2833 | |
| 2834 | /* disable VLAN tag insert/strip */ |
| 2835 | ctrl = er32(CTRL); |
| 2836 | ctrl &= ~E1000_CTRL_VME; |
| 2837 | ew32(CTRL, ctrl); |
| 2838 | } |
| 2839 | |
| 2840 | /** |
| 2841 | * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping |
| 2842 | * @adapter: board private structure to initialize |
| 2843 | **/ |
| 2844 | static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter) |
| 2845 | { |
| 2846 | struct e1000_hw *hw = &adapter->hw; |
| 2847 | u32 ctrl; |
| 2848 | |
| 2849 | /* enable VLAN tag insert/strip */ |
| 2850 | ctrl = er32(CTRL); |
| 2851 | ctrl |= E1000_CTRL_VME; |
| 2852 | ew32(CTRL, ctrl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 2856 | { |
| 2857 | struct net_device *netdev = adapter->netdev; |
| 2858 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 2859 | u16 old_vid = adapter->mng_vlan_id; |
| 2860 | |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 2861 | if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2862 | e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2863 | adapter->mng_vlan_id = vid; |
| 2864 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2865 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2866 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid)) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2867 | e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
| 2871 | { |
| 2872 | u16 vid; |
| 2873 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2874 | e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2875 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2876 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2877 | e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2878 | } |
| 2879 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2880 | static void e1000_init_manageability_pt(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2881 | { |
| 2882 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2883 | u32 manc, manc2h, mdef, i, j; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2884 | |
| 2885 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) |
| 2886 | return; |
| 2887 | |
| 2888 | manc = er32(MANC); |
| 2889 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2890 | /* enable receiving management packets to the host. this will probably |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2891 | * generate destination unreachable messages from the host OS, but |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2892 | * the packets will be handled on SMBUS |
| 2893 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2894 | manc |= E1000_MANC_EN_MNG2HOST; |
| 2895 | manc2h = er32(MANC2H); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2896 | |
| 2897 | switch (hw->mac.type) { |
| 2898 | default: |
| 2899 | manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664); |
| 2900 | break; |
| 2901 | case e1000_82574: |
| 2902 | case e1000_82583: |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2903 | /* Check if IPMI pass-through decision filter already exists; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2904 | * if so, enable it. |
| 2905 | */ |
| 2906 | for (i = 0, j = 0; i < 8; i++) { |
| 2907 | mdef = er32(MDEF(i)); |
| 2908 | |
| 2909 | /* Ignore filters with anything other than IPMI ports */ |
Dan Carpenter | 3b21b50 | 2010-06-02 13:43:15 +0000 | [diff] [blame] | 2910 | if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2911 | continue; |
| 2912 | |
| 2913 | /* Enable this decision filter in MANC2H */ |
| 2914 | if (mdef) |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 2915 | manc2h |= BIT(i); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2916 | |
| 2917 | j |= mdef; |
| 2918 | } |
| 2919 | |
| 2920 | if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
| 2921 | break; |
| 2922 | |
| 2923 | /* Create new decision filter in an empty filter */ |
| 2924 | for (i = 0, j = 0; i < 8; i++) |
| 2925 | if (er32(MDEF(i)) == 0) { |
| 2926 | ew32(MDEF(i), (E1000_MDEF_PORT_623 | |
| 2927 | E1000_MDEF_PORT_664)); |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 2928 | manc2h |= BIT(1); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2929 | j++; |
| 2930 | break; |
| 2931 | } |
| 2932 | |
| 2933 | if (!j) |
| 2934 | e_warn("Unable to create IPMI pass-through filter\n"); |
| 2935 | break; |
| 2936 | } |
| 2937 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2938 | ew32(MANC2H, manc2h); |
| 2939 | ew32(MANC, manc); |
| 2940 | } |
| 2941 | |
| 2942 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2943 | * e1000_configure_tx - Configure Transmit Unit after Reset |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2944 | * @adapter: board private structure |
| 2945 | * |
| 2946 | * Configure the Tx unit of the MAC after a reset. |
| 2947 | **/ |
| 2948 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
| 2949 | { |
| 2950 | struct e1000_hw *hw = &adapter->hw; |
| 2951 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2952 | u64 tdba; |
David Ertman | e7e834a | 2014-01-13 23:19:27 +0000 | [diff] [blame] | 2953 | u32 tdlen, tctl, tarc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2954 | |
| 2955 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 2956 | tdba = tx_ring->dma; |
| 2957 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 2958 | ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32))); |
| 2959 | ew32(TDBAH(0), (tdba >> 32)); |
| 2960 | ew32(TDLEN(0), tdlen); |
| 2961 | ew32(TDH(0), 0); |
| 2962 | ew32(TDT(0), 0); |
| 2963 | tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0); |
| 2964 | tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2965 | |
Jia-Ju Bai | 0845d45 | 2015-08-05 18:16:10 +0800 | [diff] [blame] | 2966 | writel(0, tx_ring->head); |
| 2967 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 2968 | e1000e_update_tdt_wa(tx_ring, 0); |
| 2969 | else |
| 2970 | writel(0, tx_ring->tail); |
| 2971 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2972 | /* Set the Tx Interrupt Delay register */ |
| 2973 | ew32(TIDV, adapter->tx_int_delay); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2974 | /* Tx irq moderation */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2975 | ew32(TADV, adapter->tx_abs_int_delay); |
| 2976 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2977 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 2978 | u32 txdctl = er32(TXDCTL(0)); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 2979 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2980 | txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH | |
| 2981 | E1000_TXDCTL_WTHRESH); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2982 | /* set up some performance related parameters to encourage the |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2983 | * hardware to use the bus more efficiently in bursts, depends |
| 2984 | * on the tx_int_delay to be enabled, |
Hiroaki SHIMODA | 8edc0e6 | 2012-10-10 15:34:20 +0000 | [diff] [blame] | 2985 | * wthresh = 1 ==> burst write is disabled to avoid Tx stalls |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2986 | * hthresh = 1 ==> prefetch when one or more available |
| 2987 | * pthresh = 0x1f ==> prefetch if internal cache 31 or less |
| 2988 | * BEWARE: this seems to work but should be considered first if |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2989 | * there are Tx hangs or other Tx related bugs |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2990 | */ |
| 2991 | txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE; |
| 2992 | ew32(TXDCTL(0), txdctl); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2993 | } |
Bruce Allan | 56032be | 2011-12-16 00:46:01 +0000 | [diff] [blame] | 2994 | /* erratum work around: set txdctl the same for both queues */ |
| 2995 | ew32(TXDCTL(1), er32(TXDCTL(0))); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2996 | |
David Ertman | e7e834a | 2014-01-13 23:19:27 +0000 | [diff] [blame] | 2997 | /* Program the Transmit Control Register */ |
| 2998 | tctl = er32(TCTL); |
| 2999 | tctl &= ~E1000_TCTL_CT; |
| 3000 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
| 3001 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 3002 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3003 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 3004 | tarc = er32(TARC(0)); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3005 | /* 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] | 3006 | * gigabit link later |
| 3007 | */ |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 3008 | #define SPEED_MODE_BIT BIT(21) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3009 | tarc |= SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 3010 | ew32(TARC(0), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | /* errata: program both queues to unweighted RR */ |
| 3014 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 3015 | tarc = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3016 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 3017 | ew32(TARC(0), tarc); |
| 3018 | tarc = er32(TARC(1)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3019 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 3020 | ew32(TARC(1), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3023 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 3024 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 3025 | |
| 3026 | /* only set IDE if we are delaying interrupts using the timers */ |
| 3027 | if (adapter->tx_int_delay) |
| 3028 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
| 3029 | |
| 3030 | /* enable Report Status bit */ |
| 3031 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 3032 | |
David Ertman | e7e834a | 2014-01-13 23:19:27 +0000 | [diff] [blame] | 3033 | ew32(TCTL, tctl); |
| 3034 | |
Bruce Allan | 57cde76 | 2012-02-22 09:02:58 +0000 | [diff] [blame] | 3035 | hw->mac.ops.config_collision_dist(hw); |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 3036 | |
Sasha Neftin | b10effb | 2017-08-06 16:49:18 +0300 | [diff] [blame] | 3037 | /* SPT and KBL Si errata workaround to avoid data corruption */ |
| 3038 | if (hw->mac.type == e1000_pch_spt) { |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 3039 | u32 reg_val; |
| 3040 | |
| 3041 | reg_val = er32(IOSFPC); |
| 3042 | reg_val |= E1000_RCTL_RDMTS_HEX; |
| 3043 | ew32(IOSFPC, reg_val); |
| 3044 | |
| 3045 | reg_val = er32(TARC(0)); |
Sasha Neftin | c0f4b16 | 2017-11-06 08:31:59 +0200 | [diff] [blame] | 3046 | /* SPT and KBL Si errata workaround to avoid Tx hang. |
| 3047 | * Dropping the number of outstanding requests from |
| 3048 | * 3 to 2 in order to avoid a buffer overrun. |
| 3049 | */ |
| 3050 | reg_val &= ~E1000_TARC0_CB_MULTIQ_3_REQ; |
| 3051 | reg_val |= E1000_TARC0_CB_MULTIQ_2_REQ; |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 3052 | ew32(TARC(0), reg_val); |
| 3053 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3054 | } |
| 3055 | |
| 3056 | /** |
| 3057 | * e1000_setup_rctl - configure the receive control registers |
| 3058 | * @adapter: Board private structure |
| 3059 | **/ |
| 3060 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 3061 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
| 3062 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
| 3063 | { |
| 3064 | struct e1000_hw *hw = &adapter->hw; |
| 3065 | u32 rctl, rfctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3066 | u32 pages = 0; |
| 3067 | |
David Ertman | b20a774 | 2014-03-25 04:27:55 +0000 | [diff] [blame] | 3068 | /* Workaround Si errata on PCHx - configure jumbo frame flow. |
| 3069 | * If jumbo frames not set, program related MAC/PHY registers |
| 3070 | * to h/w defaults |
| 3071 | */ |
| 3072 | if (hw->mac.type >= e1000_pch2lan) { |
| 3073 | s32 ret_val; |
| 3074 | |
| 3075 | if (adapter->netdev->mtu > ETH_DATA_LEN) |
| 3076 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true); |
| 3077 | else |
| 3078 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false); |
| 3079 | |
| 3080 | if (ret_val) |
| 3081 | e_dbg("failed to enable|disable jumbo frame workaround mode\n"); |
| 3082 | } |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 3083 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3084 | /* Program MC offset vector base */ |
| 3085 | rctl = er32(RCTL); |
| 3086 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 3087 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 3088 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 3089 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3090 | |
| 3091 | /* Do not Store bad packets */ |
| 3092 | rctl &= ~E1000_RCTL_SBP; |
| 3093 | |
| 3094 | /* Enable Long Packet receive */ |
| 3095 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 3096 | rctl &= ~E1000_RCTL_LPE; |
| 3097 | else |
| 3098 | rctl |= E1000_RCTL_LPE; |
| 3099 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 3100 | /* Some systems expect that the CRC is included in SMBUS traffic. The |
| 3101 | * hardware strips the CRC before sending to both SMBUS (BMC) and to |
| 3102 | * host memory when this is enabled |
| 3103 | */ |
| 3104 | if (adapter->flags2 & FLAG2_CRC_STRIPPING) |
| 3105 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 5918bd8 | 2008-02-12 15:20:24 -0800 | [diff] [blame] | 3106 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3107 | /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ |
| 3108 | if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { |
| 3109 | u16 phy_data; |
| 3110 | |
| 3111 | e1e_rphy(hw, PHY_REG(770, 26), &phy_data); |
| 3112 | phy_data &= 0xfff8; |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 3113 | phy_data |= BIT(2); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3114 | e1e_wphy(hw, PHY_REG(770, 26), phy_data); |
| 3115 | |
| 3116 | e1e_rphy(hw, 22, &phy_data); |
| 3117 | phy_data &= 0x0fff; |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 3118 | phy_data |= BIT(14); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3119 | e1e_wphy(hw, 0x10, 0x2823); |
| 3120 | e1e_wphy(hw, 0x11, 0x0003); |
| 3121 | e1e_wphy(hw, 22, phy_data); |
| 3122 | } |
| 3123 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3124 | /* Setup buffer sizes */ |
| 3125 | rctl &= ~E1000_RCTL_SZ_4096; |
| 3126 | rctl |= E1000_RCTL_BSEX; |
| 3127 | switch (adapter->rx_buffer_len) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3128 | case 2048: |
| 3129 | default: |
| 3130 | rctl |= E1000_RCTL_SZ_2048; |
| 3131 | rctl &= ~E1000_RCTL_BSEX; |
| 3132 | break; |
| 3133 | case 4096: |
| 3134 | rctl |= E1000_RCTL_SZ_4096; |
| 3135 | break; |
| 3136 | case 8192: |
| 3137 | rctl |= E1000_RCTL_SZ_8192; |
| 3138 | break; |
| 3139 | case 16384: |
| 3140 | rctl |= E1000_RCTL_SZ_16384; |
| 3141 | break; |
| 3142 | } |
| 3143 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3144 | /* Enable Extended Status in all Receive Descriptors */ |
| 3145 | rfctl = er32(RFCTL); |
| 3146 | rfctl |= E1000_RFCTL_EXTEN; |
Matthew Vick | f6bd557 | 2012-04-25 08:01:05 +0000 | [diff] [blame] | 3147 | ew32(RFCTL, rfctl); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3148 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3149 | /* 82571 and greater support packet-split where the protocol |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3150 | * header is placed in skb->data and the packet data is |
| 3151 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 3152 | * In the case of a non-split, skb->data is linearly filled, |
| 3153 | * followed by the page buffers. Therefore, skb->data is |
| 3154 | * sized to hold the largest protocol header. |
| 3155 | * |
| 3156 | * allocations using alloc_page take too long for regular MTU |
| 3157 | * so only enable packet split for jumbo frames |
| 3158 | * |
| 3159 | * Using pages when the page size is greater than 16k wastes |
| 3160 | * a lot of memory, since we allocate 3 pages at all times |
| 3161 | * per packet. |
| 3162 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3163 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3164 | if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3165 | adapter->rx_ps_pages = pages; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3166 | else |
| 3167 | adapter->rx_ps_pages = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3168 | |
| 3169 | if (adapter->rx_ps_pages) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 3170 | u32 psrctl = 0; |
| 3171 | |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 3172 | /* Enable Packet split descriptors */ |
| 3173 | rctl |= E1000_RCTL_DTYP_PS; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3174 | |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 3175 | psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3176 | |
| 3177 | switch (adapter->rx_ps_pages) { |
| 3178 | case 3: |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 3179 | psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT; |
| 3180 | /* fall-through */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3181 | case 2: |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 3182 | psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT; |
| 3183 | /* fall-through */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3184 | case 1: |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 3185 | psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3186 | break; |
| 3187 | } |
| 3188 | |
| 3189 | ew32(PSRCTL, psrctl); |
| 3190 | } |
| 3191 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 3192 | /* This is useful for sniffing bad packets. */ |
| 3193 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 3194 | /* UPE and MPE will be handled by normal PROMISC logic |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3195 | * in e1000e_set_rx_mode |
| 3196 | */ |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 3197 | rctl |= (E1000_RCTL_SBP | /* Receive bad packets */ |
| 3198 | E1000_RCTL_BAM | /* RX All Bcast Pkts */ |
| 3199 | E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */ |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 3200 | |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 3201 | rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */ |
| 3202 | E1000_RCTL_DPF | /* Allow filtered pause */ |
| 3203 | E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */ |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 3204 | /* Do not mess with E1000_CTRL_VME, it affects transmit as well, |
| 3205 | * and that breaks VLANs. |
| 3206 | */ |
| 3207 | } |
| 3208 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3209 | ew32(RCTL, rctl); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3210 | /* just started the receive unit, no need to restart */ |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 3211 | adapter->flags &= ~FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | /** |
| 3215 | * e1000_configure_rx - Configure Receive Unit after Reset |
| 3216 | * @adapter: board private structure |
| 3217 | * |
| 3218 | * Configure the Rx unit of the MAC after a reset. |
| 3219 | **/ |
| 3220 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
| 3221 | { |
| 3222 | struct e1000_hw *hw = &adapter->hw; |
| 3223 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 3224 | u64 rdba; |
| 3225 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
| 3226 | |
| 3227 | if (adapter->rx_ps_pages) { |
| 3228 | /* this is a 32 byte descriptor */ |
| 3229 | rdlen = rx_ring->count * |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3230 | sizeof(union e1000_rx_desc_packet_split); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3231 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 3232 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3233 | } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3234 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3235 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 3236 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3237 | } else { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3238 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3239 | adapter->clean_rx = e1000_clean_rx_irq; |
| 3240 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 3241 | } |
| 3242 | |
| 3243 | /* disable receives while setting up the descriptors */ |
| 3244 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3245 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3246 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3247 | e1e_flush(); |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 3248 | usleep_range(10000, 11000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3249 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3250 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3251 | /* set the writeback threshold (only takes effect if the RDTR |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3252 | * 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] | 3253 | * enable prefetching of 0x20 Rx descriptors |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3254 | * granularity = 01 |
| 3255 | * wthresh = 04, |
| 3256 | * hthresh = 04, |
| 3257 | * pthresh = 0x20 |
| 3258 | */ |
| 3259 | ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3260 | ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3261 | } |
| 3262 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3263 | /* set the Receive Delay Timer Register */ |
| 3264 | ew32(RDTR, adapter->rx_int_delay); |
| 3265 | |
| 3266 | /* irq moderation */ |
| 3267 | ew32(RADV, adapter->rx_abs_int_delay); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3268 | if ((adapter->itr_setting != 0) && (adapter->itr != 0)) |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 3269 | e1000e_write_itr(adapter, adapter->itr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3270 | |
| 3271 | ctrl_ext = er32(CTRL_EXT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3272 | /* Auto-Mask interrupts upon ICR access */ |
| 3273 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 3274 | ew32(IAM, 0xffffffff); |
| 3275 | ew32(CTRL_EXT, ctrl_ext); |
| 3276 | e1e_flush(); |
| 3277 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3278 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3279 | * the Base and Length of the Rx Descriptor Ring |
| 3280 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3281 | rdba = rx_ring->dma; |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 3282 | ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32))); |
| 3283 | ew32(RDBAH(0), (rdba >> 32)); |
| 3284 | ew32(RDLEN(0), rdlen); |
| 3285 | ew32(RDH(0), 0); |
| 3286 | ew32(RDT(0), 0); |
| 3287 | rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0); |
| 3288 | rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3289 | |
Jia-Ju Bai | 0845d45 | 2015-08-05 18:16:10 +0800 | [diff] [blame] | 3290 | writel(0, rx_ring->head); |
| 3291 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 3292 | e1000e_update_rdt_wa(rx_ring, 0); |
| 3293 | else |
| 3294 | writel(0, rx_ring->tail); |
| 3295 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3296 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 3297 | rxcsum = er32(RXCSUM); |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 3298 | if (adapter->netdev->features & NETIF_F_RXCSUM) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3299 | rxcsum |= E1000_RXCSUM_TUOFL; |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 3300 | else |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3301 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3302 | ew32(RXCSUM, rxcsum); |
| 3303 | |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 3304 | /* With jumbo frames, excessive C-state transition latencies result |
| 3305 | * in dropped transactions. |
| 3306 | */ |
| 3307 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3308 | u32 lat = |
| 3309 | ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 - |
| 3310 | adapter->max_frame_size) * 8 / 1000; |
| 3311 | |
| 3312 | if (adapter->flags & FLAG_IS_ICH) { |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3313 | u32 rxdctl = er32(RXDCTL(0)); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 3314 | |
Matt Turner | b701cac | 2017-11-07 14:13:30 -0800 | [diff] [blame] | 3315 | ew32(RXDCTL(0), rxdctl | 0x3 | BIT(8)); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3316 | } |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 3317 | |
Matt Turner | 8299b00 | 2017-11-14 15:51:33 -0800 | [diff] [blame] | 3318 | dev_info(&adapter->pdev->dev, |
| 3319 | "Some CPU C-states have been disabled in order to enable jumbo frames\n"); |
Rafael J. Wysocki | 81e95ad | 2020-02-12 00:24:36 +0100 | [diff] [blame] | 3320 | cpu_latency_qos_update_request(&adapter->pm_qos_req, lat); |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 3321 | } else { |
Rafael J. Wysocki | 81e95ad | 2020-02-12 00:24:36 +0100 | [diff] [blame] | 3322 | cpu_latency_qos_update_request(&adapter->pm_qos_req, |
| 3323 | PM_QOS_DEFAULT_VALUE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3324 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3325 | |
| 3326 | /* Enable Receives */ |
| 3327 | ew32(RCTL, rctl); |
| 3328 | } |
| 3329 | |
| 3330 | /** |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3331 | * e1000e_write_mc_addr_list - write multicast addresses to MTA |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3332 | * @netdev: network interface device structure |
| 3333 | * |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3334 | * Writes multicast address list to the MTA hash table. |
| 3335 | * Returns: -ENOMEM on failure |
| 3336 | * 0 on no addresses written |
| 3337 | * X on writing X addresses to MTA |
| 3338 | */ |
| 3339 | static int e1000e_write_mc_addr_list(struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3340 | { |
| 3341 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3342 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3343 | struct netdev_hw_addr *ha; |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3344 | u8 *mta_list; |
| 3345 | int i; |
| 3346 | |
| 3347 | if (netdev_mc_empty(netdev)) { |
| 3348 | /* nothing to program, so clear mc list */ |
| 3349 | hw->mac.ops.update_mc_addr_list(hw, NULL, 0); |
| 3350 | return 0; |
| 3351 | } |
| 3352 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 3353 | mta_list = kcalloc(netdev_mc_count(netdev), ETH_ALEN, GFP_ATOMIC); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3354 | if (!mta_list) |
| 3355 | return -ENOMEM; |
| 3356 | |
| 3357 | /* update_mc_addr_list expects a packed array of only addresses. */ |
| 3358 | i = 0; |
| 3359 | netdev_for_each_mc_addr(ha, netdev) |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 3360 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3361 | |
| 3362 | hw->mac.ops.update_mc_addr_list(hw, mta_list, i); |
| 3363 | kfree(mta_list); |
| 3364 | |
| 3365 | return netdev_mc_count(netdev); |
| 3366 | } |
| 3367 | |
| 3368 | /** |
| 3369 | * e1000e_write_uc_addr_list - write unicast addresses to RAR table |
| 3370 | * @netdev: network interface device structure |
| 3371 | * |
| 3372 | * Writes unicast address list to the RAR table. |
| 3373 | * Returns: -ENOMEM on failure/insufficient address space |
| 3374 | * 0 on no addresses written |
| 3375 | * X on writing X addresses to the RAR table |
| 3376 | **/ |
| 3377 | static int e1000e_write_uc_addr_list(struct net_device *netdev) |
| 3378 | { |
| 3379 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3380 | struct e1000_hw *hw = &adapter->hw; |
David Ertman | b3e5bf1 | 2014-05-06 03:50:17 +0000 | [diff] [blame] | 3381 | unsigned int rar_entries; |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3382 | int count = 0; |
| 3383 | |
David Ertman | b3e5bf1 | 2014-05-06 03:50:17 +0000 | [diff] [blame] | 3384 | rar_entries = hw->mac.ops.rar_get_count(hw); |
| 3385 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3386 | /* save a rar entry for our hardware address */ |
| 3387 | rar_entries--; |
| 3388 | |
| 3389 | /* save a rar entry for the LAA workaround */ |
| 3390 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) |
| 3391 | rar_entries--; |
| 3392 | |
| 3393 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3394 | if (netdev_uc_count(netdev) > rar_entries) |
| 3395 | return -ENOMEM; |
| 3396 | |
| 3397 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3398 | struct netdev_hw_addr *ha; |
| 3399 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3400 | /* write the addresses in reverse order to avoid write |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3401 | * combining |
| 3402 | */ |
| 3403 | netdev_for_each_uc_addr(ha, netdev) { |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 3404 | int ret_val; |
David Ertman | b3e5bf1 | 2014-05-06 03:50:17 +0000 | [diff] [blame] | 3405 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3406 | if (!rar_entries) |
| 3407 | break; |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 3408 | ret_val = hw->mac.ops.rar_set(hw, ha->addr, rar_entries--); |
| 3409 | if (ret_val < 0) |
David Ertman | b3e5bf1 | 2014-05-06 03:50:17 +0000 | [diff] [blame] | 3410 | return -ENOMEM; |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3411 | count++; |
| 3412 | } |
| 3413 | } |
| 3414 | |
| 3415 | /* zero out the remaining RAR entries not used above */ |
| 3416 | for (; rar_entries > 0; rar_entries--) { |
| 3417 | ew32(RAH(rar_entries), 0); |
| 3418 | ew32(RAL(rar_entries), 0); |
| 3419 | } |
| 3420 | e1e_flush(); |
| 3421 | |
| 3422 | return count; |
| 3423 | } |
| 3424 | |
| 3425 | /** |
| 3426 | * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set |
| 3427 | * @netdev: network interface device structure |
| 3428 | * |
| 3429 | * The ndo_set_rx_mode entry point is called whenever the unicast or multicast |
| 3430 | * address list or the network interface flags are updated. This routine is |
| 3431 | * responsible for configuring the hardware for proper unicast, multicast, |
| 3432 | * promiscuous mode, and all-multi behavior. |
| 3433 | **/ |
| 3434 | static void e1000e_set_rx_mode(struct net_device *netdev) |
| 3435 | { |
| 3436 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3437 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3438 | u32 rctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3439 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 3440 | if (pm_runtime_suspended(netdev->dev.parent)) |
| 3441 | return; |
| 3442 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3443 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3444 | rctl = er32(RCTL); |
| 3445 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3446 | /* clear the affected bits */ |
| 3447 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 3448 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3449 | if (netdev->flags & IFF_PROMISC) { |
| 3450 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3451 | /* Do not hardware filter VLANs in promisc mode */ |
| 3452 | e1000e_vlan_filter_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3453 | } else { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3454 | int count; |
Bruce Allan | 3d3a167 | 2012-02-23 03:13:18 +0000 | [diff] [blame] | 3455 | |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3456 | if (netdev->flags & IFF_ALLMULTI) { |
| 3457 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3458 | } else { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3459 | /* Write addresses to the MTA, if the attempt fails |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3460 | * then we should just turn on promiscuous mode so |
| 3461 | * that we can at least receive multicast traffic |
| 3462 | */ |
| 3463 | count = e1000e_write_mc_addr_list(netdev); |
| 3464 | if (count < 0) |
| 3465 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3466 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3467 | e1000e_vlan_filter_enable(adapter); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3468 | /* Write addresses to available RAR registers, if there is not |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3469 | * sufficient space to store all the addresses then enable |
| 3470 | * unicast promiscuous mode |
| 3471 | */ |
| 3472 | count = e1000e_write_uc_addr_list(netdev); |
| 3473 | if (count < 0) |
| 3474 | rctl |= E1000_RCTL_UPE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | ew32(RCTL, rctl); |
| 3478 | |
Jarod Wilson | 8380864 | 2016-06-09 19:50:13 -0400 | [diff] [blame] | 3479 | if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3480 | e1000e_vlan_strip_enable(adapter); |
| 3481 | else |
| 3482 | e1000e_vlan_strip_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3485 | static void e1000e_setup_rss_hash(struct e1000_adapter *adapter) |
| 3486 | { |
| 3487 | struct e1000_hw *hw = &adapter->hw; |
| 3488 | u32 mrqc, rxcsum; |
Eric Dumazet | 5c8d19d | 2014-11-16 06:23:11 -0800 | [diff] [blame] | 3489 | u32 rss_key[10]; |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3490 | int i; |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3491 | |
Eric Dumazet | 5c8d19d | 2014-11-16 06:23:11 -0800 | [diff] [blame] | 3492 | netdev_rss_key_fill(rss_key, sizeof(rss_key)); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3493 | for (i = 0; i < 10; i++) |
Eric Dumazet | 5c8d19d | 2014-11-16 06:23:11 -0800 | [diff] [blame] | 3494 | ew32(RSSRK(i), rss_key[i]); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3495 | |
| 3496 | /* Direct all traffic to queue 0 */ |
| 3497 | for (i = 0; i < 32; i++) |
| 3498 | ew32(RETA(i), 0); |
| 3499 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3500 | /* Disable raw packet checksumming so that RSS hash is placed in |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3501 | * descriptor on writeback. |
| 3502 | */ |
| 3503 | rxcsum = er32(RXCSUM); |
| 3504 | rxcsum |= E1000_RXCSUM_PCSD; |
| 3505 | |
| 3506 | ew32(RXCSUM, rxcsum); |
| 3507 | |
| 3508 | mrqc = (E1000_MRQC_RSS_FIELD_IPV4 | |
| 3509 | E1000_MRQC_RSS_FIELD_IPV4_TCP | |
| 3510 | E1000_MRQC_RSS_FIELD_IPV6 | |
| 3511 | E1000_MRQC_RSS_FIELD_IPV6_TCP | |
| 3512 | E1000_MRQC_RSS_FIELD_IPV6_TCP_EX); |
| 3513 | |
| 3514 | ew32(MRQC, mrqc); |
| 3515 | } |
| 3516 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3517 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3518 | * e1000e_get_base_timinca - get default SYSTIM time increment attributes |
| 3519 | * @adapter: board private structure |
| 3520 | * @timinca: pointer to returned time increment attributes |
| 3521 | * |
| 3522 | * Get attributes for incrementing the System Time Register SYSTIML/H at |
| 3523 | * the default base frequency, and set the cyclecounter shift value. |
| 3524 | **/ |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3525 | s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca) |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3526 | { |
| 3527 | struct e1000_hw *hw = &adapter->hw; |
| 3528 | u32 incvalue, incperiod, shift; |
| 3529 | |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 3530 | /* Make sure clock is enabled on I217/I218/I219 before checking |
| 3531 | * the frequency |
| 3532 | */ |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 3533 | if ((hw->mac.type >= e1000_pch_lpt) && |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3534 | !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) && |
| 3535 | !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) { |
| 3536 | u32 fextnvm7 = er32(FEXTNVM7); |
| 3537 | |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 3538 | if (!(fextnvm7 & BIT(0))) { |
| 3539 | ew32(FEXTNVM7, fextnvm7 | BIT(0)); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3540 | e1e_flush(); |
| 3541 | } |
| 3542 | } |
| 3543 | |
| 3544 | switch (hw->mac.type) { |
| 3545 | case e1000_pch2lan: |
Bernd Faust | 5313eec | 2017-02-16 19:42:07 +0100 | [diff] [blame] | 3546 | /* Stable 96MHz frequency */ |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3547 | incperiod = INCPERIOD_96MHZ; |
| 3548 | incvalue = INCVALUE_96MHZ; |
| 3549 | shift = INCVALUE_SHIFT_96MHZ; |
| 3550 | adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ; |
Bernd Faust | 5313eec | 2017-02-16 19:42:07 +0100 | [diff] [blame] | 3551 | break; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3552 | case e1000_pch_lpt: |
Yanir Lubetkin | 83129b3 | 2015-06-02 17:05:45 +0300 | [diff] [blame] | 3553 | if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) { |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3554 | /* Stable 96MHz frequency */ |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3555 | incperiod = INCPERIOD_96MHZ; |
| 3556 | incvalue = INCVALUE_96MHZ; |
| 3557 | shift = INCVALUE_SHIFT_96MHZ; |
| 3558 | adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ; |
Yanir Lubetkin | 83129b3 | 2015-06-02 17:05:45 +0300 | [diff] [blame] | 3559 | } else { |
| 3560 | /* Stable 25MHz frequency */ |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3561 | incperiod = INCPERIOD_25MHZ; |
| 3562 | incvalue = INCVALUE_25MHZ; |
| 3563 | shift = INCVALUE_SHIFT_25MHZ; |
Yanir Lubetkin | 83129b3 | 2015-06-02 17:05:45 +0300 | [diff] [blame] | 3564 | adapter->cc.shift = shift; |
| 3565 | } |
| 3566 | break; |
| 3567 | case e1000_pch_spt: |
Benjamin Poirier | fff200c | 2018-05-10 16:28:35 +0900 | [diff] [blame] | 3568 | /* Stable 24MHz frequency */ |
| 3569 | incperiod = INCPERIOD_24MHZ; |
| 3570 | incvalue = INCVALUE_24MHZ; |
| 3571 | shift = INCVALUE_SHIFT_24MHZ; |
| 3572 | adapter->cc.shift = shift; |
| 3573 | break; |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3574 | case e1000_pch_cnp: |
Sasha Neftin | fb776f5 | 2019-10-16 11:08:38 +0300 | [diff] [blame] | 3575 | case e1000_pch_tgp: |
Sasha Neftin | 59e4668 | 2020-01-19 13:57:13 +0200 | [diff] [blame] | 3576 | case e1000_pch_adp: |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3577 | if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) { |
| 3578 | /* Stable 24MHz frequency */ |
| 3579 | incperiod = INCPERIOD_24MHZ; |
| 3580 | incvalue = INCVALUE_24MHZ; |
| 3581 | shift = INCVALUE_SHIFT_24MHZ; |
| 3582 | adapter->cc.shift = shift; |
| 3583 | } else { |
| 3584 | /* Stable 38400KHz frequency */ |
| 3585 | incperiod = INCPERIOD_38400KHZ; |
| 3586 | incvalue = INCVALUE_38400KHZ; |
| 3587 | shift = INCVALUE_SHIFT_38400KHZ; |
| 3588 | adapter->cc.shift = shift; |
| 3589 | } |
| 3590 | break; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3591 | case e1000_82574: |
| 3592 | case e1000_82583: |
| 3593 | /* Stable 25MHz frequency */ |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3594 | incperiod = INCPERIOD_25MHZ; |
| 3595 | incvalue = INCVALUE_25MHZ; |
| 3596 | shift = INCVALUE_SHIFT_25MHZ; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3597 | adapter->cc.shift = shift; |
| 3598 | break; |
| 3599 | default: |
| 3600 | return -EINVAL; |
| 3601 | } |
| 3602 | |
| 3603 | *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) | |
| 3604 | ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK)); |
| 3605 | |
| 3606 | return 0; |
| 3607 | } |
| 3608 | |
| 3609 | /** |
| 3610 | * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable |
| 3611 | * @adapter: board private structure |
| 3612 | * |
| 3613 | * Outgoing time stamping can be enabled and disabled. Play nice and |
| 3614 | * disable it when requested, although it shouldn't cause any overhead |
| 3615 | * when no packet needs it. At most one packet in the queue may be |
| 3616 | * marked for time stamping, otherwise it would be impossible to tell |
| 3617 | * for sure to which packet the hardware time stamp belongs. |
| 3618 | * |
| 3619 | * Incoming time stamping has to be configured via the hardware filters. |
| 3620 | * Not all combinations are supported, in particular event type has to be |
| 3621 | * specified. Matching the kind of event packet is not supported, with the |
| 3622 | * exception of "all V2 events regardless of level 2 or 4". |
| 3623 | **/ |
Ben Hutchings | 62d7e3a | 2013-11-14 00:41:38 +0000 | [diff] [blame] | 3624 | static int e1000e_config_hwtstamp(struct e1000_adapter *adapter, |
| 3625 | struct hwtstamp_config *config) |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3626 | { |
| 3627 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3628 | u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED; |
| 3629 | u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3630 | u32 rxmtrl = 0; |
| 3631 | u16 rxudp = 0; |
| 3632 | bool is_l4 = false; |
| 3633 | bool is_l2 = false; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3634 | u32 regval; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3635 | |
| 3636 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) |
| 3637 | return -EINVAL; |
| 3638 | |
| 3639 | /* flags reserved for future extensions - must be zero */ |
| 3640 | if (config->flags) |
| 3641 | return -EINVAL; |
| 3642 | |
| 3643 | switch (config->tx_type) { |
| 3644 | case HWTSTAMP_TX_OFF: |
| 3645 | tsync_tx_ctl = 0; |
| 3646 | break; |
| 3647 | case HWTSTAMP_TX_ON: |
| 3648 | break; |
| 3649 | default: |
| 3650 | return -ERANGE; |
| 3651 | } |
| 3652 | |
| 3653 | switch (config->rx_filter) { |
| 3654 | case HWTSTAMP_FILTER_NONE: |
| 3655 | tsync_rx_ctl = 0; |
| 3656 | break; |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3657 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 3658 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
| 3659 | rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE; |
| 3660 | is_l4 = true; |
| 3661 | break; |
| 3662 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 3663 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
| 3664 | rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE; |
| 3665 | is_l4 = true; |
| 3666 | break; |
| 3667 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 3668 | /* Also time stamps V2 L2 Path Delay Request/Response */ |
| 3669 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2; |
| 3670 | rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE; |
| 3671 | is_l2 = true; |
| 3672 | break; |
| 3673 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 3674 | /* Also time stamps V2 L2 Path Delay Request/Response. */ |
| 3675 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2; |
| 3676 | rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE; |
| 3677 | is_l2 = true; |
| 3678 | break; |
| 3679 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 3680 | /* Hardware cannot filter just V2 L4 Sync messages; |
| 3681 | * fall-through to V2 (both L2 and L4) Sync. |
| 3682 | */ |
| 3683 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 3684 | /* Also time stamps V2 Path Delay Request/Response. */ |
| 3685 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
| 3686 | rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE; |
| 3687 | is_l2 = true; |
| 3688 | is_l4 = true; |
| 3689 | break; |
| 3690 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 3691 | /* Hardware cannot filter just V2 L4 Delay Request messages; |
| 3692 | * fall-through to V2 (both L2 and L4) Delay Request. |
| 3693 | */ |
| 3694 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 3695 | /* Also time stamps V2 Path Delay Request/Response. */ |
| 3696 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
| 3697 | rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE; |
| 3698 | is_l2 = true; |
| 3699 | is_l4 = true; |
| 3700 | break; |
| 3701 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 3702 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 3703 | /* Hardware cannot filter just V2 L4 or L2 Event messages; |
| 3704 | * fall-through to all V2 (both L2 and L4) Events. |
| 3705 | */ |
| 3706 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 3707 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2; |
| 3708 | config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
| 3709 | is_l2 = true; |
| 3710 | is_l4 = true; |
| 3711 | break; |
| 3712 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 3713 | /* For V1, the hardware can only filter Sync messages or |
| 3714 | * Delay Request messages but not both so fall-through to |
| 3715 | * time stamp all packets. |
| 3716 | */ |
Miroslav Lichvar | e341257 | 2017-05-19 17:52:36 +0200 | [diff] [blame] | 3717 | case HWTSTAMP_FILTER_NTP_ALL: |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3718 | case HWTSTAMP_FILTER_ALL: |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3719 | is_l2 = true; |
| 3720 | is_l4 = true; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3721 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; |
| 3722 | config->rx_filter = HWTSTAMP_FILTER_ALL; |
| 3723 | break; |
| 3724 | default: |
| 3725 | return -ERANGE; |
| 3726 | } |
| 3727 | |
Ben Hutchings | 62d7e3a | 2013-11-14 00:41:38 +0000 | [diff] [blame] | 3728 | adapter->hwtstamp_config = *config; |
| 3729 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3730 | /* enable/disable Tx h/w time stamping */ |
| 3731 | regval = er32(TSYNCTXCTL); |
| 3732 | regval &= ~E1000_TSYNCTXCTL_ENABLED; |
| 3733 | regval |= tsync_tx_ctl; |
| 3734 | ew32(TSYNCTXCTL, regval); |
| 3735 | if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) != |
| 3736 | (regval & E1000_TSYNCTXCTL_ENABLED)) { |
| 3737 | e_err("Timesync Tx Control register not set as expected\n"); |
| 3738 | return -EAGAIN; |
| 3739 | } |
| 3740 | |
| 3741 | /* enable/disable Rx h/w time stamping */ |
| 3742 | regval = er32(TSYNCRXCTL); |
| 3743 | regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK); |
| 3744 | regval |= tsync_rx_ctl; |
| 3745 | ew32(TSYNCRXCTL, regval); |
| 3746 | if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED | |
| 3747 | E1000_TSYNCRXCTL_TYPE_MASK)) != |
| 3748 | (regval & (E1000_TSYNCRXCTL_ENABLED | |
| 3749 | E1000_TSYNCRXCTL_TYPE_MASK))) { |
| 3750 | e_err("Timesync Rx Control register not set as expected\n"); |
| 3751 | return -EAGAIN; |
| 3752 | } |
| 3753 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3754 | /* L2: define ethertype filter for time stamped packets */ |
| 3755 | if (is_l2) |
| 3756 | rxmtrl |= ETH_P_1588; |
| 3757 | |
| 3758 | /* define which PTP packets get time stamped */ |
| 3759 | ew32(RXMTRL, rxmtrl); |
| 3760 | |
| 3761 | /* Filter by destination port */ |
| 3762 | if (is_l4) { |
| 3763 | rxudp = PTP_EV_PORT; |
| 3764 | cpu_to_be16s(&rxudp); |
| 3765 | } |
| 3766 | ew32(RXUDP, rxudp); |
| 3767 | |
| 3768 | e1e_flush(); |
| 3769 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3770 | /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */ |
Bruce Allan | 70806a7 | 2013-01-05 05:08:37 +0000 | [diff] [blame] | 3771 | er32(RXSTMPH); |
| 3772 | er32(TXSTMPH); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3773 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3774 | return 0; |
| 3775 | } |
| 3776 | |
| 3777 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3778 | * e1000_configure - configure the hardware for Rx and Tx |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3779 | * @adapter: private board structure |
| 3780 | **/ |
| 3781 | static void e1000_configure(struct e1000_adapter *adapter) |
| 3782 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3783 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 3784 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3785 | e1000e_set_rx_mode(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3786 | |
| 3787 | e1000_restore_vlan(adapter); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 3788 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3789 | |
| 3790 | e1000_configure_tx(adapter); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3791 | |
| 3792 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 3793 | e1000e_setup_rss_hash(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3794 | e1000_setup_rctl(adapter); |
| 3795 | e1000_configure_rx(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3796 | 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] | 3797 | } |
| 3798 | |
| 3799 | /** |
| 3800 | * e1000e_power_up_phy - restore link in case the phy was powered down |
| 3801 | * @adapter: address of board private structure |
| 3802 | * |
| 3803 | * The phy may be powered down to save power and turn off link when the |
| 3804 | * driver is unloaded and wake on lan is not enabled (among others) |
| 3805 | * *** this routine MUST be followed by a call to e1000e_reset *** |
| 3806 | **/ |
| 3807 | void e1000e_power_up_phy(struct e1000_adapter *adapter) |
| 3808 | { |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3809 | if (adapter->hw.phy.ops.power_up) |
| 3810 | adapter->hw.phy.ops.power_up(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3811 | |
| 3812 | adapter->hw.mac.ops.setup_link(&adapter->hw); |
| 3813 | } |
| 3814 | |
| 3815 | /** |
| 3816 | * e1000_power_down_phy - Power down the PHY |
| 3817 | * |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3818 | * Power down the PHY so no link is implied when interface is down. |
| 3819 | * The PHY cannot be powered down if management or WoL is active. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3820 | */ |
| 3821 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 3822 | { |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3823 | if (adapter->hw.phy.ops.power_down) |
| 3824 | adapter->hw.phy.ops.power_down(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | /** |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3828 | * e1000_flush_tx_ring - remove all descriptors from the tx_ring |
| 3829 | * |
| 3830 | * We want to clear all pending descriptors from the TX ring. |
| 3831 | * zeroing happens when the HW reads the regs. We assign the ring itself as |
| 3832 | * the data of the next descriptor. We don't care about the data we are about |
| 3833 | * to reset the HW. |
| 3834 | */ |
| 3835 | static void e1000_flush_tx_ring(struct e1000_adapter *adapter) |
| 3836 | { |
| 3837 | struct e1000_hw *hw = &adapter->hw; |
| 3838 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 3839 | struct e1000_tx_desc *tx_desc = NULL; |
| 3840 | u32 tdt, tctl, txd_lower = E1000_TXD_CMD_IFCS; |
| 3841 | u16 size = 512; |
| 3842 | |
| 3843 | tctl = er32(TCTL); |
| 3844 | ew32(TCTL, tctl | E1000_TCTL_EN); |
| 3845 | tdt = er32(TDT(0)); |
| 3846 | BUG_ON(tdt != tx_ring->next_to_use); |
| 3847 | tx_desc = E1000_TX_DESC(*tx_ring, tx_ring->next_to_use); |
Ben Dooks (Codethink) | 99fe61b | 2019-12-18 09:53:08 +0000 | [diff] [blame] | 3848 | tx_desc->buffer_addr = cpu_to_le64(tx_ring->dma); |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3849 | |
| 3850 | tx_desc->lower.data = cpu_to_le32(txd_lower | size); |
| 3851 | tx_desc->upper.data = 0; |
| 3852 | /* flush descriptors to memory before notifying the HW */ |
| 3853 | wmb(); |
| 3854 | tx_ring->next_to_use++; |
| 3855 | if (tx_ring->next_to_use == tx_ring->count) |
| 3856 | tx_ring->next_to_use = 0; |
| 3857 | ew32(TDT(0), tx_ring->next_to_use); |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3858 | usleep_range(200, 250); |
| 3859 | } |
| 3860 | |
| 3861 | /** |
| 3862 | * e1000_flush_rx_ring - remove all descriptors from the rx_ring |
| 3863 | * |
| 3864 | * Mark all descriptors in the RX ring as consumed and disable the rx ring |
| 3865 | */ |
| 3866 | static void e1000_flush_rx_ring(struct e1000_adapter *adapter) |
| 3867 | { |
| 3868 | u32 rctl, rxdctl; |
| 3869 | struct e1000_hw *hw = &adapter->hw; |
| 3870 | |
| 3871 | rctl = er32(RCTL); |
| 3872 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 3873 | e1e_flush(); |
| 3874 | usleep_range(100, 150); |
| 3875 | |
| 3876 | rxdctl = er32(RXDCTL(0)); |
| 3877 | /* zero the lower 14 bits (prefetch and host thresholds) */ |
| 3878 | rxdctl &= 0xffffc000; |
| 3879 | |
| 3880 | /* update thresholds: prefetch threshold to 31, host threshold to 1 |
| 3881 | * and make sure the granularity is "descriptors" and not "cache lines" |
| 3882 | */ |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 3883 | rxdctl |= (0x1F | BIT(8) | E1000_RXDCTL_THRESH_UNIT_DESC); |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3884 | |
| 3885 | ew32(RXDCTL(0), rxdctl); |
| 3886 | /* momentarily enable the RX ring for the changes to take effect */ |
| 3887 | ew32(RCTL, rctl | E1000_RCTL_EN); |
| 3888 | e1e_flush(); |
| 3889 | usleep_range(100, 150); |
| 3890 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 3891 | } |
| 3892 | |
| 3893 | /** |
| 3894 | * e1000_flush_desc_rings - remove all descriptors from the descriptor rings |
| 3895 | * |
| 3896 | * In i219, the descriptor rings must be emptied before resetting the HW |
| 3897 | * or before changing the device state to D3 during runtime (runtime PM). |
| 3898 | * |
| 3899 | * Failure to do this will cause the HW to enter a unit hang state which can |
| 3900 | * only be released by PCI reset on the device |
| 3901 | * |
| 3902 | */ |
| 3903 | |
| 3904 | static void e1000_flush_desc_rings(struct e1000_adapter *adapter) |
| 3905 | { |
Yanir Lubetkin | ff917429 | 2015-06-02 17:05:38 +0300 | [diff] [blame] | 3906 | u16 hang_state; |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3907 | u32 fext_nvm11, tdlen; |
| 3908 | struct e1000_hw *hw = &adapter->hw; |
| 3909 | |
| 3910 | /* First, disable MULR fix in FEXTNVM11 */ |
| 3911 | fext_nvm11 = er32(FEXTNVM11); |
| 3912 | fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX; |
| 3913 | ew32(FEXTNVM11, fext_nvm11); |
| 3914 | /* do nothing if we're not in faulty state, or if the queue is empty */ |
| 3915 | tdlen = er32(TDLEN(0)); |
Yanir Lubetkin | ff917429 | 2015-06-02 17:05:38 +0300 | [diff] [blame] | 3916 | pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS, |
| 3917 | &hang_state); |
| 3918 | if (!(hang_state & FLUSH_DESC_REQUIRED) || !tdlen) |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3919 | return; |
| 3920 | e1000_flush_tx_ring(adapter); |
| 3921 | /* recheck, maybe the fault is caused by the rx ring */ |
Yanir Lubetkin | ff917429 | 2015-06-02 17:05:38 +0300 | [diff] [blame] | 3922 | pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS, |
| 3923 | &hang_state); |
| 3924 | if (hang_state & FLUSH_DESC_REQUIRED) |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3925 | e1000_flush_rx_ring(adapter); |
| 3926 | } |
| 3927 | |
| 3928 | /** |
Jacob Keller | aa524b6 | 2016-04-20 11:36:42 -0700 | [diff] [blame] | 3929 | * e1000e_systim_reset - reset the timesync registers after a hardware reset |
| 3930 | * @adapter: board private structure |
| 3931 | * |
| 3932 | * When the MAC is reset, all hardware bits for timesync will be reset to the |
| 3933 | * default values. This function will restore the settings last in place. |
| 3934 | * Since the clock SYSTIME registers are reset, we will simply restore the |
| 3935 | * cyclecounter to the kernel real clock time. |
| 3936 | **/ |
| 3937 | static void e1000e_systim_reset(struct e1000_adapter *adapter) |
| 3938 | { |
| 3939 | struct ptp_clock_info *info = &adapter->ptp_clock_info; |
| 3940 | struct e1000_hw *hw = &adapter->hw; |
| 3941 | unsigned long flags; |
| 3942 | u32 timinca; |
| 3943 | s32 ret_val; |
| 3944 | |
| 3945 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) |
| 3946 | return; |
| 3947 | |
| 3948 | if (info->adjfreq) { |
| 3949 | /* restore the previous ptp frequency delta */ |
| 3950 | ret_val = info->adjfreq(info, adapter->ptp_delta); |
| 3951 | } else { |
| 3952 | /* set the default base frequency if no adjustment possible */ |
| 3953 | ret_val = e1000e_get_base_timinca(adapter, &timinca); |
| 3954 | if (!ret_val) |
| 3955 | ew32(TIMINCA, timinca); |
| 3956 | } |
| 3957 | |
| 3958 | if (ret_val) { |
| 3959 | dev_warn(&adapter->pdev->dev, |
| 3960 | "Failed to restore TIMINCA clock rate delta: %d\n", |
| 3961 | ret_val); |
| 3962 | return; |
| 3963 | } |
| 3964 | |
| 3965 | /* reset the systim ns time counter */ |
| 3966 | spin_lock_irqsave(&adapter->systim_lock, flags); |
| 3967 | timecounter_init(&adapter->tc, &adapter->cc, |
| 3968 | ktime_to_ns(ktime_get_real())); |
| 3969 | spin_unlock_irqrestore(&adapter->systim_lock, flags); |
| 3970 | |
| 3971 | /* restore the previous hwtstamp configuration settings */ |
| 3972 | e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config); |
| 3973 | } |
| 3974 | |
| 3975 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3976 | * e1000e_reset - bring the hardware into a known good state |
| 3977 | * |
| 3978 | * This function boots the hardware and enables some settings that |
| 3979 | * require a configuration cycle of the hardware - those cannot be |
| 3980 | * set/changed during runtime. After reset the device needs to be |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3981 | * properly configured for Rx, Tx etc. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3982 | */ |
| 3983 | void e1000e_reset(struct e1000_adapter *adapter) |
| 3984 | { |
| 3985 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3986 | struct e1000_fc_info *fc = &adapter->hw.fc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3987 | struct e1000_hw *hw = &adapter->hw; |
| 3988 | u32 tx_space, min_tx_space, min_rx_space; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3989 | u32 pba = adapter->pba; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3990 | u16 hwm; |
| 3991 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3992 | /* reset Packet Buffer Allocation to default */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3993 | ew32(PBA, pba); |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3994 | |
Alexander Duyck | 8084b86 | 2015-05-02 00:52:00 -0700 | [diff] [blame] | 3995 | if (adapter->max_frame_size > (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3996 | /* To maintain wire speed transmits, the Tx FIFO should be |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3997 | * large enough to accommodate two full transmit packets, |
| 3998 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 3999 | * the Rx FIFO should be large enough to accommodate at least |
| 4000 | * one full receive packet and is similarly rounded up and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4001 | * expressed in KB. |
| 4002 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 4003 | pba = er32(PBA); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4004 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 4005 | tx_space = pba >> 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4006 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 4007 | pba &= 0xffff; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4008 | /* the Tx fifo also stores 16 bytes of information about the Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4009 | * but don't include ethernet FCS because hardware appends it |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4010 | */ |
| 4011 | min_tx_space = (adapter->max_frame_size + |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 4012 | sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4013 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 4014 | min_tx_space >>= 10; |
| 4015 | /* software strips receive CRC, so leave room for it */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4016 | min_rx_space = adapter->max_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4017 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 4018 | min_rx_space >>= 10; |
| 4019 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4020 | /* If current Tx allocation is less than the min Tx FIFO size, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4021 | * 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] | 4022 | * allocation, take space away from current Rx allocation |
| 4023 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 4024 | if ((tx_space < min_tx_space) && |
| 4025 | ((min_tx_space - tx_space) < pba)) { |
| 4026 | pba -= min_tx_space - tx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4027 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4028 | /* if short on Rx space, Rx wins and must trump Tx |
Bruce Allan | 419e551 | 2012-08-17 06:18:02 +0000 | [diff] [blame] | 4029 | * adjustment |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4030 | */ |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4031 | if (pba < min_rx_space) |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 4032 | pba = min_rx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4033 | } |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 4034 | |
| 4035 | ew32(PBA, pba); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4036 | } |
| 4037 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4038 | /* flow control settings |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4039 | * |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4040 | * 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] | 4041 | * (or the size used for early receive) above it in the Rx FIFO. |
| 4042 | * Set it to the lower of: |
| 4043 | * - 90% of the Rx FIFO size, and |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4044 | * - the full Rx FIFO size minus one full frame |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4045 | */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4046 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
| 4047 | fc->pause_time = 0xFFFF; |
| 4048 | else |
| 4049 | fc->pause_time = E1000_FC_PAUSE_TIME; |
Bruce Allan | b20caa8 | 2012-02-22 09:03:03 +0000 | [diff] [blame] | 4050 | fc->send_xon = true; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4051 | fc->current_mode = fc->requested_mode; |
| 4052 | |
| 4053 | switch (hw->mac.type) { |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4054 | case e1000_ich9lan: |
| 4055 | case e1000_ich10lan: |
| 4056 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 4057 | pba = 14; |
| 4058 | ew32(PBA, pba); |
| 4059 | fc->high_water = 0x2800; |
| 4060 | fc->low_water = fc->high_water - 8; |
| 4061 | break; |
| 4062 | } |
| 4063 | /* fall-through */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4064 | default: |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4065 | hwm = min(((pba << 10) * 9 / 10), |
| 4066 | ((pba << 10) - adapter->max_frame_size)); |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4067 | |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 4068 | fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4069 | fc->low_water = fc->high_water - 8; |
| 4070 | break; |
| 4071 | case e1000_pchlan: |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4072 | /* Workaround PCH LOM adapter hangs with certain network |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4073 | * loads. If hangs persist, try disabling Tx flow control. |
| 4074 | */ |
| 4075 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 4076 | fc->high_water = 0x3500; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 4077 | fc->low_water = 0x1500; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4078 | } else { |
| 4079 | fc->high_water = 0x5000; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 4080 | fc->low_water = 0x3000; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4081 | } |
Bruce Allan | a305595 | 2010-05-10 15:02:12 +0000 | [diff] [blame] | 4082 | fc->refresh_time = 0x1000; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4083 | break; |
| 4084 | case e1000_pch2lan: |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 4085 | case e1000_pch_lpt: |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 4086 | case e1000_pch_spt: |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 4087 | case e1000_pch_cnp: |
Sasha Neftin | fb776f5 | 2019-10-16 11:08:38 +0300 | [diff] [blame] | 4088 | /* fall-through */ |
| 4089 | case e1000_pch_tgp: |
Sasha Neftin | 59e4668 | 2020-01-19 13:57:13 +0200 | [diff] [blame] | 4090 | case e1000_pch_adp: |
Miguel Bernal Marin | f74dc88 | 2017-03-27 16:01:56 -0600 | [diff] [blame] | 4091 | fc->refresh_time = 0xFFFF; |
| 4092 | fc->pause_time = 0xFFFF; |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 4093 | |
| 4094 | if (adapter->netdev->mtu <= ETH_DATA_LEN) { |
| 4095 | fc->high_water = 0x05C20; |
| 4096 | fc->low_water = 0x05048; |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 4097 | break; |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4098 | } |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 4099 | |
Bruce Allan | ce345e0 | 2013-06-21 09:07:07 +0000 | [diff] [blame] | 4100 | pba = 14; |
| 4101 | ew32(PBA, pba); |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 4102 | fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH; |
| 4103 | fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4104 | break; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4105 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4106 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4107 | /* Alignment of Tx data is on an arbitrary byte boundary with the |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 4108 | * maximum size per Tx descriptor limited only to the transmit |
| 4109 | * allocation of the packet buffer minus 96 bytes with an upper |
| 4110 | * limit of 24KB due to receive synchronization limitations. |
| 4111 | */ |
| 4112 | adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96, |
| 4113 | 24 << 10); |
| 4114 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4115 | /* Disable Adaptive Interrupt Moderation if 2 full packets cannot |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4116 | * fit in receive buffer. |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4117 | */ |
| 4118 | if (adapter->itr_setting & 0x3) { |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4119 | if ((adapter->max_frame_size * 2) > (pba << 10)) { |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4120 | if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) { |
| 4121 | dev_info(&adapter->pdev->dev, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 4122 | "Interrupt Throttle Rate off\n"); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4123 | adapter->flags2 |= FLAG2_DISABLE_AIM; |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 4124 | e1000e_write_itr(adapter, 0); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4125 | } |
| 4126 | } else if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 4127 | dev_info(&adapter->pdev->dev, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 4128 | "Interrupt Throttle Rate on\n"); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4129 | adapter->flags2 &= ~FLAG2_DISABLE_AIM; |
| 4130 | adapter->itr = 20000; |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 4131 | e1000e_write_itr(adapter, adapter->itr); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4132 | } |
| 4133 | } |
| 4134 | |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 4135 | if (hw->mac.type >= e1000_pch_spt) |
Yanir Lubetkin | 0ffc564 | 2015-04-22 04:15:01 +0300 | [diff] [blame] | 4136 | e1000_flush_desc_rings(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4137 | /* Allow time for pending master requests to run */ |
| 4138 | mac->ops.reset_hw(hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 4139 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4140 | /* For parts with AMT enabled, let the firmware know |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 4141 | * that the network interface is in control |
| 4142 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 4143 | if (adapter->flags & FLAG_HAS_AMT) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4144 | e1000e_get_hw_control(adapter); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 4145 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4146 | ew32(WUC, 0); |
| 4147 | |
| 4148 | if (mac->ops.init_hw(hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4149 | e_err("Hardware Error\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4150 | |
| 4151 | e1000_update_mng_vlan(adapter); |
| 4152 | |
| 4153 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 4154 | ew32(VET, ETH_P_8021Q); |
| 4155 | |
| 4156 | e1000e_reset_adaptive(hw); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4157 | |
Jacob Keller | aa524b6 | 2016-04-20 11:36:42 -0700 | [diff] [blame] | 4158 | /* restore systim and hwtstamp settings */ |
| 4159 | e1000e_systim_reset(adapter); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4160 | |
Bruce Allan | d495bcb | 2013-03-20 07:23:11 +0000 | [diff] [blame] | 4161 | /* Set EEE advertisement as appropriate */ |
| 4162 | if (adapter->flags2 & FLAG2_HAS_EEE) { |
| 4163 | s32 ret_val; |
| 4164 | u16 adv_addr; |
| 4165 | |
| 4166 | switch (hw->phy.type) { |
| 4167 | case e1000_phy_82579: |
| 4168 | adv_addr = I82579_EEE_ADVERTISEMENT; |
| 4169 | break; |
| 4170 | case e1000_phy_i217: |
| 4171 | adv_addr = I217_EEE_ADVERTISEMENT; |
| 4172 | break; |
| 4173 | default: |
| 4174 | dev_err(&adapter->pdev->dev, |
| 4175 | "Invalid PHY type setting EEE advertisement\n"); |
| 4176 | return; |
| 4177 | } |
| 4178 | |
| 4179 | ret_val = hw->phy.ops.acquire(hw); |
| 4180 | if (ret_val) { |
| 4181 | dev_err(&adapter->pdev->dev, |
| 4182 | "EEE advertisement - unable to acquire PHY\n"); |
| 4183 | return; |
| 4184 | } |
| 4185 | |
| 4186 | e1000_write_emi_reg_locked(hw, adv_addr, |
| 4187 | hw->dev_spec.ich8lan.eee_disable ? |
| 4188 | 0 : adapter->eee_advert); |
| 4189 | |
| 4190 | hw->phy.ops.release(hw); |
| 4191 | } |
| 4192 | |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4193 | if (!netif_running(adapter->netdev) && |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 4194 | !test_bit(__E1000_TESTING, &adapter->state)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4195 | e1000_power_down_phy(adapter); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4196 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4197 | e1000_get_phy_info(hw); |
| 4198 | |
Bruce Allan | 918d719 | 2009-06-02 11:28:20 +0000 | [diff] [blame] | 4199 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && |
| 4200 | !(adapter->flags & FLAG_SMART_POWER_DOWN)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4201 | u16 phy_data = 0; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4202 | /* speed up time to link by disabling smart power down, ignore |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4203 | * the return value of this function because there is nothing |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4204 | * different we would do if it failed |
| 4205 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4206 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
| 4207 | phy_data &= ~IGP02E1000_PM_SPD; |
| 4208 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 4209 | } |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 4210 | if (hw->mac.type >= e1000_pch_spt && adapter->int_mode == 0) { |
Yanir Lubetkin | ec945cf | 2015-06-02 17:05:42 +0300 | [diff] [blame] | 4211 | u32 reg; |
| 4212 | |
| 4213 | /* Fextnvm7 @ 0xe4[2] = 1 */ |
| 4214 | reg = er32(FEXTNVM7); |
| 4215 | reg |= E1000_FEXTNVM7_SIDE_CLK_UNGATE; |
| 4216 | ew32(FEXTNVM7, reg); |
| 4217 | /* Fextnvm9 @ 0x5bb4[13:12] = 11 */ |
| 4218 | reg = er32(FEXTNVM9); |
| 4219 | reg |= E1000_FEXTNVM9_IOSFSB_CLKGATE_DIS | |
| 4220 | E1000_FEXTNVM9_IOSFSB_CLKREQ_DIS; |
| 4221 | ew32(FEXTNVM9, reg); |
| 4222 | } |
| 4223 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4224 | } |
| 4225 | |
Benjamin Poirier | a61cfe4 | 2015-11-09 15:50:20 -0800 | [diff] [blame] | 4226 | /** |
| 4227 | * e1000e_trigger_lsc - trigger an LSC interrupt |
| 4228 | * @adapter: |
| 4229 | * |
| 4230 | * Fire a link status change interrupt to start the watchdog. |
| 4231 | **/ |
| 4232 | static void e1000e_trigger_lsc(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4233 | { |
| 4234 | struct e1000_hw *hw = &adapter->hw; |
| 4235 | |
Benjamin Poirier | a61cfe4 | 2015-11-09 15:50:20 -0800 | [diff] [blame] | 4236 | if (adapter->msix_entries) |
Benjamin Poirier | 4aea7a5c | 2017-07-21 11:36:27 -0700 | [diff] [blame] | 4237 | ew32(ICS, E1000_ICS_LSC | E1000_ICS_OTHER); |
Benjamin Poirier | a61cfe4 | 2015-11-09 15:50:20 -0800 | [diff] [blame] | 4238 | else |
| 4239 | ew32(ICS, E1000_ICS_LSC); |
| 4240 | } |
| 4241 | |
| 4242 | void e1000e_up(struct e1000_adapter *adapter) |
| 4243 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4244 | /* hardware has been reset, we need to reload some things */ |
| 4245 | e1000_configure(adapter); |
| 4246 | |
| 4247 | clear_bit(__E1000_DOWN, &adapter->state); |
| 4248 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4249 | if (adapter->msix_entries) |
| 4250 | e1000_configure_msix(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4251 | e1000_irq_enable(adapter); |
| 4252 | |
Konstantin Khlebnikov | d17ba0f | 2019-04-17 11:13:20 +0300 | [diff] [blame] | 4253 | /* Tx queue started by watchdog timer when link is up */ |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 4254 | |
Benjamin Poirier | a61cfe4 | 2015-11-09 15:50:20 -0800 | [diff] [blame] | 4255 | e1000e_trigger_lsc(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4256 | } |
| 4257 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4258 | static void e1000e_flush_descriptors(struct e1000_adapter *adapter) |
| 4259 | { |
| 4260 | struct e1000_hw *hw = &adapter->hw; |
| 4261 | |
| 4262 | if (!(adapter->flags2 & FLAG2_DMA_BURST)) |
| 4263 | return; |
| 4264 | |
| 4265 | /* flush pending descriptor writebacks to memory */ |
| 4266 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 4267 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 4268 | |
| 4269 | /* execute the writes immediately */ |
| 4270 | e1e_flush(); |
Matthew Vick | bf03085 | 2012-03-16 09:03:00 +0000 | [diff] [blame] | 4271 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4272 | /* 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] | 4273 | * write is successful |
| 4274 | */ |
| 4275 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 4276 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 4277 | |
| 4278 | /* execute the writes immediately */ |
| 4279 | e1e_flush(); |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4280 | } |
| 4281 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4282 | static void e1000e_update_stats(struct e1000_adapter *adapter); |
| 4283 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 4284 | /** |
| 4285 | * e1000e_down - quiesce the device and optionally reset the hardware |
| 4286 | * @adapter: board private structure |
| 4287 | * @reset: boolean flag to reset the hardware or not |
| 4288 | */ |
| 4289 | void e1000e_down(struct e1000_adapter *adapter, bool reset) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4290 | { |
| 4291 | struct net_device *netdev = adapter->netdev; |
| 4292 | struct e1000_hw *hw = &adapter->hw; |
| 4293 | u32 tctl, rctl; |
| 4294 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4295 | /* signal that we're down so the interrupt handler does not |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4296 | * reschedule our watchdog timer |
| 4297 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4298 | set_bit(__E1000_DOWN, &adapter->state); |
| 4299 | |
Eliezer Tamir | a60a132 | 2015-03-20 17:41:52 -0700 | [diff] [blame] | 4300 | netif_carrier_off(netdev); |
| 4301 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4302 | /* disable receives in the hardware */ |
| 4303 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 4304 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 4305 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4306 | /* flush and sleep below */ |
| 4307 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 4308 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4309 | |
| 4310 | /* disable transmits in the hardware */ |
| 4311 | tctl = er32(TCTL); |
| 4312 | tctl &= ~E1000_TCTL_EN; |
| 4313 | ew32(TCTL, tctl); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 4314 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4315 | /* flush both disables and wait for them to finish */ |
| 4316 | e1e_flush(); |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 4317 | usleep_range(10000, 11000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4318 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4319 | e1000_irq_disable(adapter); |
| 4320 | |
Bruce Allan | a3b87a4 | 2013-04-20 05:37:29 +0000 | [diff] [blame] | 4321 | napi_synchronize(&adapter->napi); |
| 4322 | |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 4323 | del_timer_sync(&adapter->watchdog_timer); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4324 | del_timer_sync(&adapter->phy_info_timer); |
| 4325 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4326 | spin_lock(&adapter->stats64_lock); |
| 4327 | e1000e_update_stats(adapter); |
| 4328 | spin_unlock(&adapter->stats64_lock); |
| 4329 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 4330 | e1000e_flush_descriptors(adapter); |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 4331 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4332 | adapter->link_speed = 0; |
| 4333 | adapter->link_duplex = 0; |
| 4334 | |
Bruce Allan | da1e2046 | 2013-06-21 09:07:02 +0000 | [diff] [blame] | 4335 | /* Disable Si errata workaround on PCHx for jumbo frame flow */ |
| 4336 | if ((hw->mac.type >= e1000_pch2lan) && |
| 4337 | (adapter->netdev->mtu > ETH_DATA_LEN) && |
| 4338 | e1000_lv_jumbo_workaround_ich8lan(hw, false)) |
| 4339 | e_dbg("failed to disable jumbo frame workaround mode\n"); |
| 4340 | |
Yanir Lubetkin | 0ffc564 | 2015-04-22 04:15:01 +0300 | [diff] [blame] | 4341 | if (!pci_channel_offline(adapter->pdev)) { |
| 4342 | if (reset) |
| 4343 | e1000e_reset(adapter); |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 4344 | else if (hw->mac.type >= e1000_pch_spt) |
Yanir Lubetkin | 0ffc564 | 2015-04-22 04:15:01 +0300 | [diff] [blame] | 4345 | e1000_flush_desc_rings(adapter); |
| 4346 | } |
| 4347 | e1000_clean_tx_ring(adapter->tx_ring); |
| 4348 | e1000_clean_rx_ring(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | void e1000e_reinit_locked(struct e1000_adapter *adapter) |
| 4352 | { |
| 4353 | might_sleep(); |
| 4354 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 4355 | usleep_range(1000, 1100); |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 4356 | e1000e_down(adapter, true); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4357 | e1000e_up(adapter); |
| 4358 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 4359 | } |
| 4360 | |
| 4361 | /** |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4362 | * e1000e_sanitize_systim - sanitize raw cycle counter reads |
| 4363 | * @hw: pointer to the HW structure |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4364 | * @systim: PHC time value read, sanitized and returned |
| 4365 | * @sts: structure to hold system time before and after reading SYSTIML, |
| 4366 | * may be NULL |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4367 | * |
| 4368 | * Errata for 82574/82583 possible bad bits read from SYSTIMH/L: |
| 4369 | * check to see that the time is incrementing at a reasonable |
| 4370 | * rate and is a multiple of incvalue. |
| 4371 | **/ |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4372 | static u64 e1000e_sanitize_systim(struct e1000_hw *hw, u64 systim, |
| 4373 | struct ptp_system_timestamp *sts) |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4374 | { |
| 4375 | u64 time_delta, rem, temp; |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 4376 | u64 systim_next; |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4377 | u32 incvalue; |
| 4378 | int i; |
| 4379 | |
| 4380 | incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK; |
| 4381 | for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) { |
| 4382 | /* latch SYSTIMH on read of SYSTIML */ |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4383 | ptp_read_system_prets(sts); |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 4384 | systim_next = (u64)er32(SYSTIML); |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4385 | ptp_read_system_postts(sts); |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 4386 | systim_next |= (u64)er32(SYSTIMH) << 32; |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4387 | |
| 4388 | time_delta = systim_next - systim; |
| 4389 | temp = time_delta; |
| 4390 | /* VMWare users have seen incvalue of zero, don't div / 0 */ |
| 4391 | rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0); |
| 4392 | |
| 4393 | systim = systim_next; |
| 4394 | |
| 4395 | if ((time_delta < E1000_82574_SYSTIM_EPSILON) && (rem == 0)) |
| 4396 | break; |
| 4397 | } |
| 4398 | |
| 4399 | return systim; |
| 4400 | } |
| 4401 | |
| 4402 | /** |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4403 | * e1000e_read_systim - read SYSTIM register |
| 4404 | * @adapter: board private structure |
| 4405 | * @sts: structure which will contain system time before and after reading |
| 4406 | * SYSTIML, may be NULL |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4407 | **/ |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4408 | u64 e1000e_read_systim(struct e1000_adapter *adapter, |
| 4409 | struct ptp_system_timestamp *sts) |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4410 | { |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4411 | struct e1000_hw *hw = &adapter->hw; |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4412 | u32 systimel, systimel_2, systimeh; |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 4413 | u64 systim; |
Raanan Avargil | 37b12910 | 2015-07-19 16:33:20 +0300 | [diff] [blame] | 4414 | /* SYSTIMH latching upon SYSTIML read does not work well. |
| 4415 | * This means that if SYSTIML overflows after we read it but before |
| 4416 | * we read SYSTIMH, the value of SYSTIMH has been incremented and we |
| 4417 | * will experience a huge non linear increment in the systime value |
| 4418 | * to fix that we test for overflow and if true, we re-read systime. |
Yanir Lubetkin | 83129b3 | 2015-06-02 17:05:45 +0300 | [diff] [blame] | 4419 | */ |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4420 | ptp_read_system_prets(sts); |
Denys Vlasenko | ab507c9 | 2016-04-20 17:45:56 +0200 | [diff] [blame] | 4421 | systimel = er32(SYSTIML); |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4422 | ptp_read_system_postts(sts); |
Raanan Avargil | 37b12910 | 2015-07-19 16:33:20 +0300 | [diff] [blame] | 4423 | systimeh = er32(SYSTIMH); |
Denys Vlasenko | ab507c9 | 2016-04-20 17:45:56 +0200 | [diff] [blame] | 4424 | /* Is systimel is so large that overflow is possible? */ |
| 4425 | if (systimel >= (u32)0xffffffff - E1000_TIMINCA_INCVALUE_MASK) { |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4426 | ptp_read_system_prets(sts); |
| 4427 | systimel_2 = er32(SYSTIML); |
| 4428 | ptp_read_system_postts(sts); |
Denys Vlasenko | ab507c9 | 2016-04-20 17:45:56 +0200 | [diff] [blame] | 4429 | if (systimel > systimel_2) { |
| 4430 | /* There was an overflow, read again SYSTIMH, and use |
| 4431 | * systimel_2 |
| 4432 | */ |
| 4433 | systimeh = er32(SYSTIMH); |
| 4434 | systimel = systimel_2; |
| 4435 | } |
Raanan Avargil | 37b12910 | 2015-07-19 16:33:20 +0300 | [diff] [blame] | 4436 | } |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 4437 | systim = (u64)systimel; |
| 4438 | systim |= (u64)systimeh << 32; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4439 | |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4440 | if (adapter->flags2 & FLAG2_CHECK_SYSTIM_OVERFLOW) |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4441 | systim = e1000e_sanitize_systim(hw, systim, sts); |
Todd Fujinaka | 5e7ff97 | 2014-05-03 06:41:37 +0000 | [diff] [blame] | 4442 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4443 | return systim; |
| 4444 | } |
| 4445 | |
| 4446 | /** |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4447 | * e1000e_cyclecounter_read - read raw cycle counter (used by time counter) |
| 4448 | * @cc: cyclecounter structure |
| 4449 | **/ |
| 4450 | static u64 e1000e_cyclecounter_read(const struct cyclecounter *cc) |
| 4451 | { |
| 4452 | struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter, |
| 4453 | cc); |
| 4454 | |
| 4455 | return e1000e_read_systim(adapter, NULL); |
| 4456 | } |
| 4457 | |
| 4458 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4459 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 4460 | * @adapter: board private structure to initialize |
| 4461 | * |
| 4462 | * e1000_sw_init initializes the Adapter private data structure. |
| 4463 | * Fields are initialized based on PCI device information and |
| 4464 | * OS network device settings (MTU size). |
| 4465 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 4466 | static int e1000_sw_init(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4467 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4468 | struct net_device *netdev = adapter->netdev; |
| 4469 | |
Alexander Duyck | 8084b86 | 2015-05-02 00:52:00 -0700 | [diff] [blame] | 4470 | adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4471 | adapter->rx_ps_bsize0 = 128; |
Alexander Duyck | 8084b86 | 2015-05-02 00:52:00 -0700 | [diff] [blame] | 4472 | adapter->max_frame_size = netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4473 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4474 | adapter->tx_ring_count = E1000_DEFAULT_TXD; |
| 4475 | adapter->rx_ring_count = E1000_DEFAULT_RXD; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4476 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4477 | spin_lock_init(&adapter->stats64_lock); |
| 4478 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4479 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4480 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4481 | if (e1000_alloc_queues(adapter)) |
| 4482 | return -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4483 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4484 | /* Setup hardware time stamping cyclecounter */ |
| 4485 | if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) { |
| 4486 | adapter->cc.read = e1000e_cyclecounter_read; |
Richard Cochran | 4d045b4 | 2015-01-02 20:22:05 +0100 | [diff] [blame] | 4487 | adapter->cc.mask = CYCLECOUNTER_MASK(64); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4488 | adapter->cc.mult = 1; |
| 4489 | /* cc.shift set in e1000e_get_base_tininca() */ |
| 4490 | |
| 4491 | spin_lock_init(&adapter->systim_lock); |
| 4492 | INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work); |
| 4493 | } |
| 4494 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4495 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4496 | e1000_irq_disable(adapter); |
| 4497 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4498 | set_bit(__E1000_DOWN, &adapter->state); |
| 4499 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4500 | } |
| 4501 | |
| 4502 | /** |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4503 | * e1000_intr_msi_test - Interrupt Handler |
| 4504 | * @irq: interrupt number |
| 4505 | * @data: pointer to a network interface device structure |
| 4506 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 4507 | 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] | 4508 | { |
| 4509 | struct net_device *netdev = data; |
| 4510 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4511 | struct e1000_hw *hw = &adapter->hw; |
| 4512 | u32 icr = er32(ICR); |
| 4513 | |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 4514 | e_dbg("icr is %08X\n", icr); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4515 | if (icr & E1000_ICR_RXSEQ) { |
| 4516 | adapter->flags &= ~FLAG_MSI_TEST_FAILED; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4517 | /* Force memory writes to complete before acknowledging the |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4518 | * interrupt is handled. |
| 4519 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4520 | wmb(); |
| 4521 | } |
| 4522 | |
| 4523 | return IRQ_HANDLED; |
| 4524 | } |
| 4525 | |
| 4526 | /** |
| 4527 | * e1000_test_msi_interrupt - Returns 0 for successful test |
| 4528 | * @adapter: board private struct |
| 4529 | * |
| 4530 | * code flow taken from tg3.c |
| 4531 | **/ |
| 4532 | static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) |
| 4533 | { |
| 4534 | struct net_device *netdev = adapter->netdev; |
| 4535 | struct e1000_hw *hw = &adapter->hw; |
| 4536 | int err; |
| 4537 | |
| 4538 | /* poll_enable hasn't been called yet, so don't need disable */ |
| 4539 | /* clear any pending events */ |
| 4540 | er32(ICR); |
| 4541 | |
| 4542 | /* free the real vector and request a test handler */ |
| 4543 | e1000_free_irq(adapter); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4544 | e1000e_reset_interrupt_capability(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4545 | |
| 4546 | /* Assume that the test fails, if it succeeds then the test |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4547 | * MSI irq handler will unset this flag |
| 4548 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4549 | adapter->flags |= FLAG_MSI_TEST_FAILED; |
| 4550 | |
| 4551 | err = pci_enable_msi(adapter->pdev); |
| 4552 | if (err) |
| 4553 | goto msi_test_failed; |
| 4554 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 4555 | err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4556 | netdev->name, netdev); |
| 4557 | if (err) { |
| 4558 | pci_disable_msi(adapter->pdev); |
| 4559 | goto msi_test_failed; |
| 4560 | } |
| 4561 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4562 | /* Force memory writes to complete before enabling and firing an |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4563 | * interrupt. |
| 4564 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4565 | wmb(); |
| 4566 | |
| 4567 | e1000_irq_enable(adapter); |
| 4568 | |
| 4569 | /* fire an unusual interrupt on the test handler */ |
| 4570 | ew32(ICS, E1000_ICS_RXSEQ); |
| 4571 | e1e_flush(); |
Prasanna S Panchamukhi | 569a3af | 2012-04-19 17:01:00 +0000 | [diff] [blame] | 4572 | msleep(100); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4573 | |
| 4574 | e1000_irq_disable(adapter); |
| 4575 | |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4576 | rmb(); /* read flags after interrupt has been fired */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4577 | |
| 4578 | if (adapter->flags & FLAG_MSI_TEST_FAILED) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4579 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4580 | e_info("MSI interrupt test failed, using legacy interrupt.\n"); |
Bruce Allan | 24b706b | 2012-01-31 06:37:22 +0000 | [diff] [blame] | 4581 | } else { |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4582 | e_dbg("MSI interrupt test succeeded!\n"); |
Bruce Allan | 24b706b | 2012-01-31 06:37:22 +0000 | [diff] [blame] | 4583 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4584 | |
| 4585 | free_irq(adapter->pdev->irq, netdev); |
| 4586 | pci_disable_msi(adapter->pdev); |
| 4587 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4588 | msi_test_failed: |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4589 | e1000e_set_interrupt_capability(adapter); |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4590 | return e1000_request_irq(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4591 | } |
| 4592 | |
| 4593 | /** |
| 4594 | * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored |
| 4595 | * @adapter: board private struct |
| 4596 | * |
| 4597 | * code flow taken from tg3.c, called with e1000 interrupts disabled. |
| 4598 | **/ |
| 4599 | static int e1000_test_msi(struct e1000_adapter *adapter) |
| 4600 | { |
| 4601 | int err; |
| 4602 | u16 pci_cmd; |
| 4603 | |
| 4604 | if (!(adapter->flags & FLAG_MSI_ENABLED)) |
| 4605 | return 0; |
| 4606 | |
| 4607 | /* disable SERR in case the MSI write causes a master abort */ |
| 4608 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 4609 | if (pci_cmd & PCI_COMMAND_SERR) |
| 4610 | pci_write_config_word(adapter->pdev, PCI_COMMAND, |
| 4611 | pci_cmd & ~PCI_COMMAND_SERR); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4612 | |
| 4613 | err = e1000_test_msi_interrupt(adapter); |
| 4614 | |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 4615 | /* re-enable SERR */ |
| 4616 | if (pci_cmd & PCI_COMMAND_SERR) { |
| 4617 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
| 4618 | pci_cmd |= PCI_COMMAND_SERR; |
| 4619 | pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); |
| 4620 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4621 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4622 | return err; |
| 4623 | } |
| 4624 | |
| 4625 | /** |
Stefan Assmann | d5ea45d | 2016-02-03 09:20:52 +0100 | [diff] [blame] | 4626 | * e1000e_open - Called when a network interface is made active |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4627 | * @netdev: network interface device structure |
| 4628 | * |
| 4629 | * Returns 0 on success, negative value on failure |
| 4630 | * |
| 4631 | * The open entry point is called when a network interface is made |
| 4632 | * active by the system (IFF_UP). At this point all resources needed |
| 4633 | * for transmit and receive operations are allocated, the interrupt |
| 4634 | * handler is registered with the OS, the watchdog timer is started, |
| 4635 | * and the stack is notified that the interface is ready. |
| 4636 | **/ |
Stefan Assmann | d5ea45d | 2016-02-03 09:20:52 +0100 | [diff] [blame] | 4637 | int e1000e_open(struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4638 | { |
| 4639 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4640 | struct e1000_hw *hw = &adapter->hw; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4641 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4642 | int err; |
| 4643 | |
| 4644 | /* disallow open during test */ |
| 4645 | if (test_bit(__E1000_TESTING, &adapter->state)) |
| 4646 | return -EBUSY; |
| 4647 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4648 | pm_runtime_get_sync(&pdev->dev); |
| 4649 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 4650 | netif_carrier_off(netdev); |
Konstantin Khlebnikov | d17ba0f | 2019-04-17 11:13:20 +0300 | [diff] [blame] | 4651 | netif_stop_queue(netdev); |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 4652 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4653 | /* allocate transmit descriptors */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4654 | err = e1000e_setup_tx_resources(adapter->tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4655 | if (err) |
| 4656 | goto err_setup_tx; |
| 4657 | |
| 4658 | /* allocate receive descriptors */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4659 | err = e1000e_setup_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4660 | if (err) |
| 4661 | goto err_setup_rx; |
| 4662 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4663 | /* If AMT is enabled, let the firmware know that the network |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 4664 | * interface is now open and reset the part to a known state. |
| 4665 | */ |
| 4666 | if (adapter->flags & FLAG_HAS_AMT) { |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4667 | e1000e_get_hw_control(adapter); |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 4668 | e1000e_reset(adapter); |
| 4669 | } |
| 4670 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4671 | e1000e_power_up_phy(adapter); |
| 4672 | |
| 4673 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 4674 | if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4675 | e1000_update_mng_vlan(adapter); |
| 4676 | |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4677 | /* DMA latency requirement to workaround jumbo issue */ |
Rafael J. Wysocki | 81e95ad | 2020-02-12 00:24:36 +0100 | [diff] [blame] | 4678 | cpu_latency_qos_add_request(&adapter->pm_qos_req, PM_QOS_DEFAULT_VALUE); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 4679 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4680 | /* before we allocate an interrupt, we must be ready to handle it. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4681 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 4682 | * 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] | 4683 | * clean_rx handler before we do so. |
| 4684 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4685 | e1000_configure(adapter); |
| 4686 | |
| 4687 | err = e1000_request_irq(adapter); |
| 4688 | if (err) |
| 4689 | goto err_req_irq; |
| 4690 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4691 | /* Work around PCIe errata with MSI interrupts causing some chipsets to |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4692 | * ignore e1000e MSI messages, which means we need to test our MSI |
| 4693 | * interrupt now |
| 4694 | */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4695 | if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4696 | err = e1000_test_msi(adapter); |
| 4697 | if (err) { |
| 4698 | e_err("Interrupt allocation failed\n"); |
| 4699 | goto err_req_irq; |
| 4700 | } |
| 4701 | } |
| 4702 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4703 | /* From here on the code is the same as e1000e_up() */ |
| 4704 | clear_bit(__E1000_DOWN, &adapter->state); |
| 4705 | |
| 4706 | napi_enable(&adapter->napi); |
| 4707 | |
| 4708 | e1000_irq_enable(adapter); |
| 4709 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 4710 | adapter->tx_hang_recheck = false; |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4711 | |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 4712 | hw->mac.get_link_status = true; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4713 | pm_runtime_put(&pdev->dev); |
| 4714 | |
Benjamin Poirier | a61cfe4 | 2015-11-09 15:50:20 -0800 | [diff] [blame] | 4715 | e1000e_trigger_lsc(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4716 | |
| 4717 | return 0; |
| 4718 | |
| 4719 | err_req_irq: |
Rafael J. Wysocki | 81e95ad | 2020-02-12 00:24:36 +0100 | [diff] [blame] | 4720 | cpu_latency_qos_remove_request(&adapter->pm_qos_req); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4721 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4722 | e1000_power_down_phy(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4723 | e1000e_free_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4724 | err_setup_rx: |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4725 | e1000e_free_tx_resources(adapter->tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4726 | err_setup_tx: |
| 4727 | e1000e_reset(adapter); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4728 | pm_runtime_put_sync(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4729 | |
| 4730 | return err; |
| 4731 | } |
| 4732 | |
| 4733 | /** |
Stefan Assmann | d5ea45d | 2016-02-03 09:20:52 +0100 | [diff] [blame] | 4734 | * e1000e_close - Disables a network interface |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4735 | * @netdev: network interface device structure |
| 4736 | * |
| 4737 | * Returns 0, this is not allowed to fail |
| 4738 | * |
| 4739 | * The close entry point is called when an interface is de-activated |
| 4740 | * by the OS. The hardware is still under the drivers control, but |
| 4741 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4742 | * hardware, and all transmit and receive resources are freed. |
| 4743 | **/ |
Stefan Assmann | d5ea45d | 2016-02-03 09:20:52 +0100 | [diff] [blame] | 4744 | int e1000e_close(struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4745 | { |
| 4746 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4747 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | bb9e44d | 2012-03-21 00:39:12 +0000 | [diff] [blame] | 4748 | int count = E1000_CHECK_RESET_COUNT; |
| 4749 | |
| 4750 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 4751 | usleep_range(10000, 11000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4752 | |
| 4753 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4754 | |
| 4755 | pm_runtime_get_sync(&pdev->dev); |
| 4756 | |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 4757 | if (netif_device_present(netdev)) { |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 4758 | e1000e_down(adapter, true); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4759 | e1000_free_irq(adapter); |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 4760 | |
| 4761 | /* Link status message must follow this format */ |
Alexander Duyck | c557a4b | 2019-10-31 09:58:51 -0700 | [diff] [blame] | 4762 | netdev_info(netdev, "NIC Link is Down\n"); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4763 | } |
Bruce Allan | a3b87a4 | 2013-04-20 05:37:29 +0000 | [diff] [blame] | 4764 | |
| 4765 | napi_disable(&adapter->napi); |
| 4766 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4767 | e1000e_free_tx_resources(adapter->tx_ring); |
| 4768 | e1000e_free_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4769 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4770 | /* kill manageability vlan ID if supported, but not if a vlan with |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4771 | * the same ID is registered on the host OS (let 8021q kill it) |
| 4772 | */ |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 4773 | if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4774 | e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), |
| 4775 | adapter->mng_vlan_id); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4776 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4777 | /* If AMT is enabled, let the firmware know that the network |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4778 | * interface is now closed |
| 4779 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4780 | if ((adapter->flags & FLAG_HAS_AMT) && |
| 4781 | !test_bit(__E1000_TESTING, &adapter->state)) |
| 4782 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4783 | |
Rafael J. Wysocki | 81e95ad | 2020-02-12 00:24:36 +0100 | [diff] [blame] | 4784 | cpu_latency_qos_remove_request(&adapter->pm_qos_req); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 4785 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4786 | pm_runtime_put_sync(&pdev->dev); |
| 4787 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4788 | return 0; |
| 4789 | } |
Bruce Allan | fc830b7 | 2013-02-20 04:06:11 +0000 | [diff] [blame] | 4790 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4791 | /** |
| 4792 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 4793 | * @netdev: network interface device structure |
| 4794 | * @p: pointer to an address structure |
| 4795 | * |
| 4796 | * Returns 0 on success, negative on failure |
| 4797 | **/ |
| 4798 | static int e1000_set_mac(struct net_device *netdev, void *p) |
| 4799 | { |
| 4800 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4801 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4802 | struct sockaddr *addr = p; |
| 4803 | |
| 4804 | if (!is_valid_ether_addr(addr->sa_data)) |
| 4805 | return -EADDRNOTAVAIL; |
| 4806 | |
| 4807 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 4808 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 4809 | |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4810 | hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4811 | |
| 4812 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { |
| 4813 | /* activate the work around */ |
| 4814 | e1000e_set_laa_state_82571(&adapter->hw, 1); |
| 4815 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4816 | /* 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] | 4817 | * between the time RAR[0] gets clobbered and the time it |
| 4818 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
| 4819 | * of the RARs and no incoming packets directed to this port |
| 4820 | * are dropped. Eventually the LAA will be in RAR[0] and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4821 | * RAR[14] |
| 4822 | */ |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4823 | hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, |
| 4824 | adapter->hw.mac.rar_entry_count - 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4825 | } |
| 4826 | |
| 4827 | return 0; |
| 4828 | } |
| 4829 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4830 | /** |
| 4831 | * e1000e_update_phy_task - work thread to update phy |
| 4832 | * @work: pointer to our work struct |
| 4833 | * |
| 4834 | * this worker thread exists because we must acquire a |
| 4835 | * semaphore to read the phy, which we could msleep while |
| 4836 | * waiting for it, and we can't msleep in a timer. |
| 4837 | **/ |
| 4838 | static void e1000e_update_phy_task(struct work_struct *work) |
| 4839 | { |
| 4840 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 4841 | struct e1000_adapter, |
| 4842 | update_phy_task); |
David Ertman | a03206e | 2014-01-24 23:07:48 +0000 | [diff] [blame] | 4843 | struct e1000_hw *hw = &adapter->hw; |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4844 | |
| 4845 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4846 | return; |
| 4847 | |
David Ertman | a03206e | 2014-01-24 23:07:48 +0000 | [diff] [blame] | 4848 | e1000_get_phy_info(hw); |
| 4849 | |
| 4850 | /* Enable EEE on 82579 after link up */ |
David Ertman | 50844bb | 2014-05-13 00:06:26 +0000 | [diff] [blame] | 4851 | if (hw->phy.type >= e1000_phy_82579) |
David Ertman | a03206e | 2014-01-24 23:07:48 +0000 | [diff] [blame] | 4852 | e1000_set_eee_pchlan(hw); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4853 | } |
| 4854 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4855 | /** |
| 4856 | * e1000_update_phy_info - timre call-back to update PHY info |
| 4857 | * @data: pointer to adapter cast into an unsigned long |
| 4858 | * |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4859 | * Need to wait a few seconds after link up to get diagnostic information from |
| 4860 | * the phy |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4861 | **/ |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 4862 | static void e1000_update_phy_info(struct timer_list *t) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4863 | { |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 4864 | struct e1000_adapter *adapter = from_timer(adapter, t, phy_info_timer); |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4865 | |
| 4866 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4867 | return; |
| 4868 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4869 | schedule_work(&adapter->update_phy_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4870 | } |
| 4871 | |
| 4872 | /** |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4873 | * e1000e_update_phy_stats - Update the PHY statistics counters |
| 4874 | * @adapter: board private structure |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4875 | * |
| 4876 | * Read/clear the upper 16-bit PHY registers and read/accumulate lower |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4877 | **/ |
| 4878 | static void e1000e_update_phy_stats(struct e1000_adapter *adapter) |
| 4879 | { |
| 4880 | struct e1000_hw *hw = &adapter->hw; |
| 4881 | s32 ret_val; |
| 4882 | u16 phy_data; |
| 4883 | |
| 4884 | ret_val = hw->phy.ops.acquire(hw); |
| 4885 | if (ret_val) |
| 4886 | return; |
| 4887 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4888 | /* A page set is expensive so check if already on desired page. |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4889 | * If not, set to the page with the PHY status registers. |
| 4890 | */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4891 | hw->phy.addr = 1; |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4892 | ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 4893 | &phy_data); |
| 4894 | if (ret_val) |
| 4895 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4896 | if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) { |
| 4897 | ret_val = hw->phy.ops.set_page(hw, |
| 4898 | HV_STATS_PAGE << IGP_PAGE_SHIFT); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4899 | if (ret_val) |
| 4900 | goto release; |
| 4901 | } |
| 4902 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4903 | /* Single Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4904 | hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data); |
| 4905 | 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] | 4906 | if (!ret_val) |
| 4907 | adapter->stats.scc += phy_data; |
| 4908 | |
| 4909 | /* Excessive Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4910 | hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data); |
| 4911 | 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] | 4912 | if (!ret_val) |
| 4913 | adapter->stats.ecol += phy_data; |
| 4914 | |
| 4915 | /* Multiple Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4916 | hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data); |
| 4917 | 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] | 4918 | if (!ret_val) |
| 4919 | adapter->stats.mcc += phy_data; |
| 4920 | |
| 4921 | /* Late Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4922 | hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data); |
| 4923 | 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] | 4924 | if (!ret_val) |
| 4925 | adapter->stats.latecol += phy_data; |
| 4926 | |
| 4927 | /* Collision Count - also used for adaptive IFS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4928 | hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data); |
| 4929 | 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] | 4930 | if (!ret_val) |
| 4931 | hw->mac.collision_delta = phy_data; |
| 4932 | |
| 4933 | /* Defer Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4934 | hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data); |
| 4935 | 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] | 4936 | if (!ret_val) |
| 4937 | adapter->stats.dc += phy_data; |
| 4938 | |
| 4939 | /* Transmit with no CRS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4940 | hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data); |
| 4941 | 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] | 4942 | if (!ret_val) |
| 4943 | adapter->stats.tncrs += phy_data; |
| 4944 | |
| 4945 | release: |
| 4946 | hw->phy.ops.release(hw); |
| 4947 | } |
| 4948 | |
| 4949 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4950 | * e1000e_update_stats - Update the board statistics counters |
| 4951 | * @adapter: board private structure |
| 4952 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4953 | static void e1000e_update_stats(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4954 | { |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4955 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4956 | struct e1000_hw *hw = &adapter->hw; |
| 4957 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4958 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4959 | /* Prevent stats update while adapter is being reset, or if the pci |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4960 | * connection is down. |
| 4961 | */ |
| 4962 | if (adapter->link_speed == 0) |
| 4963 | return; |
| 4964 | if (pci_channel_offline(pdev)) |
| 4965 | return; |
| 4966 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4967 | adapter->stats.crcerrs += er32(CRCERRS); |
| 4968 | adapter->stats.gprc += er32(GPRC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4969 | adapter->stats.gorc += er32(GORCL); |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 4970 | er32(GORCH); /* Clear gorc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4971 | adapter->stats.bprc += er32(BPRC); |
| 4972 | adapter->stats.mprc += er32(MPRC); |
| 4973 | adapter->stats.roc += er32(ROC); |
| 4974 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4975 | adapter->stats.mpc += er32(MPC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4976 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4977 | /* Half-duplex statistics */ |
| 4978 | if (adapter->link_duplex == HALF_DUPLEX) { |
| 4979 | if (adapter->flags2 & FLAG2_HAS_PHY_STATS) { |
| 4980 | e1000e_update_phy_stats(adapter); |
| 4981 | } else { |
| 4982 | adapter->stats.scc += er32(SCC); |
| 4983 | adapter->stats.ecol += er32(ECOL); |
| 4984 | adapter->stats.mcc += er32(MCC); |
| 4985 | adapter->stats.latecol += er32(LATECOL); |
| 4986 | adapter->stats.dc += er32(DC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4987 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4988 | hw->mac.collision_delta = er32(COLC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4989 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4990 | if ((hw->mac.type != e1000_82574) && |
| 4991 | (hw->mac.type != e1000_82583)) |
| 4992 | adapter->stats.tncrs += er32(TNCRS); |
| 4993 | } |
| 4994 | adapter->stats.colc += hw->mac.collision_delta; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4995 | } |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4996 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4997 | adapter->stats.xonrxc += er32(XONRXC); |
| 4998 | adapter->stats.xontxc += er32(XONTXC); |
| 4999 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 5000 | adapter->stats.xofftxc += er32(XOFFTXC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5001 | adapter->stats.gptc += er32(GPTC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5002 | adapter->stats.gotc += er32(GOTCL); |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 5003 | er32(GOTCH); /* Clear gotc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5004 | adapter->stats.rnbc += er32(RNBC); |
| 5005 | adapter->stats.ruc += er32(RUC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5006 | |
| 5007 | adapter->stats.mptc += er32(MPTC); |
| 5008 | adapter->stats.bptc += er32(BPTC); |
| 5009 | |
| 5010 | /* used for adaptive IFS */ |
| 5011 | |
| 5012 | hw->mac.tx_packet_delta = er32(TPT); |
| 5013 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5014 | |
| 5015 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 5016 | adapter->stats.rxerrc += er32(RXERRC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5017 | adapter->stats.cexterr += er32(CEXTERR); |
| 5018 | adapter->stats.tsctc += er32(TSCTC); |
| 5019 | adapter->stats.tsctfc += er32(TSCTFC); |
| 5020 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5021 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 5022 | netdev->stats.multicast = adapter->stats.mprc; |
| 5023 | netdev->stats.collisions = adapter->stats.colc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5024 | |
| 5025 | /* Rx Errors */ |
| 5026 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5027 | /* RLEC on some newer hardware can be incorrect so build |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5028 | * our own version based on RUC and ROC |
| 5029 | */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 5030 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5031 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 5032 | adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 5033 | netdev->stats.rx_length_errors = adapter->stats.ruc + |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5034 | adapter->stats.roc; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 5035 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 5036 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; |
| 5037 | netdev->stats.rx_missed_errors = adapter->stats.mpc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5038 | |
| 5039 | /* Tx Errors */ |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5040 | netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 5041 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
| 5042 | netdev->stats.tx_window_errors = adapter->stats.latecol; |
| 5043 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5044 | |
| 5045 | /* Tx Dropped needs to be maintained elsewhere */ |
| 5046 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5047 | /* Management Stats */ |
| 5048 | adapter->stats.mgptc += er32(MGTPTC); |
| 5049 | adapter->stats.mgprc += er32(MGTPRC); |
| 5050 | adapter->stats.mgpdc += er32(MGTPDC); |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 5051 | |
| 5052 | /* Correctable ECC Errors */ |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 5053 | if (hw->mac.type >= e1000_pch_lpt) { |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 5054 | u32 pbeccsts = er32(PBECCSTS); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 5055 | |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 5056 | adapter->corr_errors += |
| 5057 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 5058 | adapter->uncorr_errors += |
| 5059 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 5060 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 5061 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5062 | } |
| 5063 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5064 | /** |
| 5065 | * e1000_phy_read_status - Update the PHY register status snapshot |
| 5066 | * @adapter: board private structure |
| 5067 | **/ |
| 5068 | static void e1000_phy_read_status(struct e1000_adapter *adapter) |
| 5069 | { |
| 5070 | struct e1000_hw *hw = &adapter->hw; |
| 5071 | struct e1000_phy_regs *phy = &adapter->phy_regs; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5072 | |
Bruce Allan | 97390ab | 2013-06-29 07:42:25 +0000 | [diff] [blame] | 5073 | if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) && |
| 5074 | (er32(STATUS) & E1000_STATUS_LU) && |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5075 | (adapter->hw.phy.media_type == e1000_media_type_copper)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 5076 | int ret_val; |
| 5077 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 5078 | ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr); |
| 5079 | ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr); |
| 5080 | ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise); |
| 5081 | ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa); |
| 5082 | ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion); |
| 5083 | ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000); |
| 5084 | ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000); |
| 5085 | ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5086 | if (ret_val) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5087 | e_warn("Error reading PHY register\n"); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5088 | } else { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5089 | /* Do not read PHY registers if link is not up |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5090 | * Set values to typical power-on defaults |
| 5091 | */ |
| 5092 | phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); |
| 5093 | phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | |
| 5094 | BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | |
| 5095 | BMSR_ERCAP); |
| 5096 | phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | |
| 5097 | ADVERTISE_ALL | ADVERTISE_CSMA); |
| 5098 | phy->lpa = 0; |
| 5099 | phy->expansion = EXPANSION_ENABLENPAGE; |
| 5100 | phy->ctrl1000 = ADVERTISE_1000FULL; |
| 5101 | phy->stat1000 = 0; |
| 5102 | phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); |
| 5103 | } |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5104 | } |
| 5105 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5106 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
| 5107 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5108 | struct e1000_hw *hw = &adapter->hw; |
| 5109 | u32 ctrl = er32(CTRL); |
| 5110 | |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 5111 | /* Link status message must follow this format for user tools */ |
Alexander Duyck | c557a4b | 2019-10-31 09:58:51 -0700 | [diff] [blame] | 5112 | netdev_info(adapter->netdev, |
| 5113 | "NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n", |
| 5114 | adapter->link_speed, |
| 5115 | adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half", |
| 5116 | (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" : |
| 5117 | (ctrl & E1000_CTRL_RFCE) ? "Rx" : |
| 5118 | (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5119 | } |
| 5120 | |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 5121 | static bool e1000e_has_link(struct e1000_adapter *adapter) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5122 | { |
| 5123 | struct e1000_hw *hw = &adapter->hw; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5124 | bool link_active = false; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5125 | s32 ret_val = 0; |
| 5126 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5127 | /* get_link_status is set on LSC (link status) interrupt or |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5128 | * Rx sequence error interrupt. get_link_status will stay |
Benjamin Poirier | 65a29da | 2017-07-21 11:36:24 -0700 | [diff] [blame] | 5129 | * true until the check_for_link establishes link |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5130 | * for copper adapters ONLY |
| 5131 | */ |
| 5132 | switch (hw->phy.media_type) { |
| 5133 | case e1000_media_type_copper: |
| 5134 | if (hw->mac.get_link_status) { |
| 5135 | ret_val = hw->mac.ops.check_for_link(hw); |
Benjamin Poirier | 3016e0a | 2018-03-06 10:55:52 +0900 | [diff] [blame] | 5136 | link_active = !hw->mac.get_link_status; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5137 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5138 | link_active = true; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5139 | } |
| 5140 | break; |
| 5141 | case e1000_media_type_fiber: |
| 5142 | ret_val = hw->mac.ops.check_for_link(hw); |
| 5143 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 5144 | break; |
| 5145 | case e1000_media_type_internal_serdes: |
| 5146 | ret_val = hw->mac.ops.check_for_link(hw); |
Benjamin Poirier | 65a29da | 2017-07-21 11:36:24 -0700 | [diff] [blame] | 5147 | link_active = hw->mac.serdes_has_link; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5148 | break; |
| 5149 | default: |
| 5150 | case e1000_media_type_unknown: |
| 5151 | break; |
| 5152 | } |
| 5153 | |
Benjamin Poirier | d3509f8 | 2017-07-21 11:36:25 -0700 | [diff] [blame] | 5154 | if ((ret_val == -E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5155 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 5156 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5157 | e_info("Gigabit has been disabled, downgrading speed\n"); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | return link_active; |
| 5161 | } |
| 5162 | |
| 5163 | static void e1000e_enable_receives(struct e1000_adapter *adapter) |
| 5164 | { |
| 5165 | /* make sure the receive unit is started */ |
| 5166 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5167 | (adapter->flags & FLAG_RESTART_NOW)) { |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5168 | struct e1000_hw *hw = &adapter->hw; |
| 5169 | u32 rctl = er32(RCTL); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 5170 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5171 | ew32(RCTL, rctl | E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5172 | adapter->flags &= ~FLAG_RESTART_NOW; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5173 | } |
| 5174 | } |
| 5175 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 5176 | static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter) |
| 5177 | { |
| 5178 | struct e1000_hw *hw = &adapter->hw; |
| 5179 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5180 | /* With 82574 controllers, PHY needs to be checked periodically |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 5181 | * for hung state and reset, if two calls return true |
| 5182 | */ |
| 5183 | if (e1000_check_phy_82574(hw)) |
| 5184 | adapter->phy_hang_count++; |
| 5185 | else |
| 5186 | adapter->phy_hang_count = 0; |
| 5187 | |
| 5188 | if (adapter->phy_hang_count > 1) { |
| 5189 | adapter->phy_hang_count = 0; |
David Ertman | d9554e9 | 2014-01-08 01:07:55 +0000 | [diff] [blame] | 5190 | e_dbg("PHY appears hung - resetting\n"); |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 5191 | schedule_work(&adapter->reset_task); |
| 5192 | } |
| 5193 | } |
| 5194 | |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 5195 | /** |
| 5196 | * e1000_watchdog - Timer Call-back |
| 5197 | * @data: pointer to adapter cast into an unsigned long |
| 5198 | **/ |
| 5199 | static void e1000_watchdog(struct timer_list *t) |
| 5200 | { |
| 5201 | struct e1000_adapter *adapter = from_timer(adapter, t, watchdog_timer); |
| 5202 | |
| 5203 | /* Do the rest outside of interrupt context */ |
| 5204 | schedule_work(&adapter->watchdog_task); |
| 5205 | |
| 5206 | /* TODO: make this use queue_delayed_work() */ |
| 5207 | } |
| 5208 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5209 | static void e1000_watchdog_task(struct work_struct *work) |
| 5210 | { |
| 5211 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5212 | struct e1000_adapter, |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 5213 | watchdog_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5214 | struct net_device *netdev = adapter->netdev; |
| 5215 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 5216 | struct e1000_phy_info *phy = &adapter->hw.phy; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5217 | struct e1000_ring *tx_ring = adapter->tx_ring; |
Vitaly Lifshits | def4ec6 | 2019-06-25 17:39:11 +0300 | [diff] [blame] | 5218 | u32 dmoff_exit_timeout = 100, tries = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5219 | struct e1000_hw *hw = &adapter->hw; |
Vitaly Lifshits | def4ec6 | 2019-06-25 17:39:11 +0300 | [diff] [blame] | 5220 | u32 link, tctl, pcim_state; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5221 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 5222 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 5223 | return; |
| 5224 | |
David S. Miller | b405e8d | 2010-02-04 22:31:41 -0800 | [diff] [blame] | 5225 | link = e1000e_has_link(adapter); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5226 | if ((netif_carrier_ok(netdev)) && link) { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5227 | /* Cancel scheduled suspend requests. */ |
| 5228 | pm_runtime_resume(netdev->dev.parent); |
| 5229 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5230 | e1000e_enable_receives(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5231 | goto link_up; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5232 | } |
| 5233 | |
| 5234 | if ((e1000e_enable_tx_pkt_filtering(hw)) && |
| 5235 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) |
| 5236 | e1000_update_mng_vlan(adapter); |
| 5237 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5238 | if (link) { |
| 5239 | if (!netif_carrier_ok(netdev)) { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5240 | bool txb2b = true; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5241 | |
| 5242 | /* Cancel scheduled suspend requests. */ |
| 5243 | pm_runtime_resume(netdev->dev.parent); |
| 5244 | |
Vitaly Lifshits | def4ec6 | 2019-06-25 17:39:11 +0300 | [diff] [blame] | 5245 | /* Checking if MAC is in DMoff state*/ |
| 5246 | pcim_state = er32(STATUS); |
| 5247 | while (pcim_state & E1000_STATUS_PCIM_STATE) { |
| 5248 | if (tries++ == dmoff_exit_timeout) { |
| 5249 | e_dbg("Error in exiting dmoff\n"); |
| 5250 | break; |
| 5251 | } |
| 5252 | usleep_range(10000, 20000); |
| 5253 | pcim_state = er32(STATUS); |
| 5254 | |
| 5255 | /* Checking if MAC exited DMoff state */ |
| 5256 | if (!(pcim_state & E1000_STATUS_PCIM_STATE)) |
| 5257 | e1000_phy_hw_reset(&adapter->hw); |
| 5258 | } |
| 5259 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5260 | /* update snapshot of PHY registers on LSC */ |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5261 | e1000_phy_read_status(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5262 | mac->ops.get_link_up_info(&adapter->hw, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5263 | &adapter->link_speed, |
| 5264 | &adapter->link_duplex); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5265 | e1000_print_link_info(adapter); |
Koki Sanagi | e792cd9 | 2013-02-03 14:03:55 +0000 | [diff] [blame] | 5266 | |
| 5267 | /* check if SmartSpeed worked */ |
| 5268 | e1000e_check_downshift(hw); |
| 5269 | if (phy->speed_downgraded) |
| 5270 | netdev_warn(netdev, |
| 5271 | "Link Speed was downgraded by SmartSpeed\n"); |
| 5272 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5273 | /* On supported PHYs, check for duplex mismatch only |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 5274 | * if link has autonegotiated at 10/100 half |
| 5275 | */ |
| 5276 | if ((hw->phy.type == e1000_phy_igp_3 || |
| 5277 | hw->phy.type == e1000_phy_bm) && |
David Ertman | 138953b | 2013-08-30 05:45:25 +0000 | [diff] [blame] | 5278 | hw->mac.autoneg && |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 5279 | (adapter->link_speed == SPEED_10 || |
| 5280 | adapter->link_speed == SPEED_100) && |
| 5281 | (adapter->link_duplex == HALF_DUPLEX)) { |
| 5282 | u16 autoneg_exp; |
| 5283 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 5284 | e1e_rphy(hw, MII_EXPANSION, &autoneg_exp); |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 5285 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 5286 | if (!(autoneg_exp & EXPANSION_NWAY)) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 5287 | 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] | 5288 | } |
| 5289 | |
Emil Tantilov | f49c57e | 2010-03-24 12:55:02 +0000 | [diff] [blame] | 5290 | /* adjust timeout factor according to speed/duplex */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5291 | adapter->tx_timeout_factor = 1; |
| 5292 | switch (adapter->link_speed) { |
| 5293 | case SPEED_10: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5294 | txb2b = false; |
Bruce Allan | 10f1b49 | 2008-08-08 18:36:01 -0700 | [diff] [blame] | 5295 | adapter->tx_timeout_factor = 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5296 | break; |
| 5297 | case SPEED_100: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5298 | txb2b = false; |
Bruce Allan | 4c86e0b | 2009-11-19 12:35:26 +0000 | [diff] [blame] | 5299 | adapter->tx_timeout_factor = 10; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5300 | break; |
| 5301 | } |
| 5302 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5303 | /* workaround: re-program speed mode bit after |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5304 | * link-up event |
| 5305 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5306 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
| 5307 | !txb2b) { |
| 5308 | u32 tarc0; |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 5309 | |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 5310 | tarc0 = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5311 | tarc0 &= ~SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 5312 | ew32(TARC(0), tarc0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5313 | } |
| 5314 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5315 | /* disable TSO for pcie and 10/100 speeds, to avoid |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5316 | * some hardware issues |
| 5317 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5318 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
| 5319 | switch (adapter->link_speed) { |
| 5320 | case SPEED_10: |
| 5321 | case SPEED_100: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5322 | e_info("10/100 speed: disabling TSO\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5323 | netdev->features &= ~NETIF_F_TSO; |
| 5324 | netdev->features &= ~NETIF_F_TSO6; |
| 5325 | break; |
| 5326 | case SPEED_1000: |
| 5327 | netdev->features |= NETIF_F_TSO; |
| 5328 | netdev->features |= NETIF_F_TSO6; |
| 5329 | break; |
| 5330 | default: |
| 5331 | /* oops */ |
| 5332 | break; |
| 5333 | } |
Kai-Heng Feng | f298010 | 2020-05-07 22:21:07 +0800 | [diff] [blame] | 5334 | if (hw->mac.type == e1000_pch_spt) { |
| 5335 | netdev->features &= ~NETIF_F_TSO; |
| 5336 | netdev->features &= ~NETIF_F_TSO6; |
| 5337 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5338 | } |
| 5339 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5340 | /* enable transmits in the hardware, need to do this |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5341 | * after setting TARC(0) |
| 5342 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5343 | tctl = er32(TCTL); |
| 5344 | tctl |= E1000_TCTL_EN; |
| 5345 | ew32(TCTL, tctl); |
| 5346 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5347 | /* Perform any post-link-up configuration before |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 5348 | * reporting link up. |
| 5349 | */ |
| 5350 | if (phy->ops.cfg_on_link_up) |
| 5351 | phy->ops.cfg_on_link_up(hw); |
| 5352 | |
Konstantin Khlebnikov | d17ba0f | 2019-04-17 11:13:20 +0300 | [diff] [blame] | 5353 | netif_wake_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5354 | netif_carrier_on(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5355 | |
| 5356 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 5357 | mod_timer(&adapter->phy_info_timer, |
| 5358 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5359 | } |
| 5360 | } else { |
| 5361 | if (netif_carrier_ok(netdev)) { |
| 5362 | adapter->link_speed = 0; |
| 5363 | adapter->link_duplex = 0; |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 5364 | /* Link status message must follow this format */ |
Alexander Duyck | c557a4b | 2019-10-31 09:58:51 -0700 | [diff] [blame] | 5365 | netdev_info(netdev, "NIC Link is Down\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5366 | netif_carrier_off(netdev); |
Konstantin Khlebnikov | d17ba0f | 2019-04-17 11:13:20 +0300 | [diff] [blame] | 5367 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5368 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 5369 | mod_timer(&adapter->phy_info_timer, |
| 5370 | round_jiffies(jiffies + 2 * HZ)); |
| 5371 | |
David Ertman | d9554e9 | 2014-01-08 01:07:55 +0000 | [diff] [blame] | 5372 | /* 8000ES2LAN requires a Rx packet buffer work-around |
| 5373 | * on link down event; reset the controller to flush |
| 5374 | * the Rx packet buffer. |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5375 | */ |
Konstantin Khlebnikov | caff422 | 2019-04-17 11:13:16 +0300 | [diff] [blame] | 5376 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5377 | adapter->flags |= FLAG_RESTART_NOW; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5378 | else |
| 5379 | pm_schedule_suspend(netdev->dev.parent, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5380 | LINK_TIMEOUT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5381 | } |
| 5382 | } |
| 5383 | |
| 5384 | link_up: |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5385 | spin_lock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5386 | e1000e_update_stats(adapter); |
| 5387 | |
| 5388 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 5389 | adapter->tpt_old = adapter->stats.tpt; |
| 5390 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; |
| 5391 | adapter->colc_old = adapter->stats.colc; |
| 5392 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5393 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
| 5394 | adapter->gorc_old = adapter->stats.gorc; |
| 5395 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; |
| 5396 | adapter->gotc_old = adapter->stats.gotc; |
Flavio Leitner | 2084b11 | 2011-04-05 04:27:43 +0000 | [diff] [blame] | 5397 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5398 | |
Konstantin Khlebnikov | caff422 | 2019-04-17 11:13:16 +0300 | [diff] [blame] | 5399 | /* If the link is lost the controller stops DMA, but |
| 5400 | * if there is queued Tx work it cannot be done. So |
| 5401 | * reset the controller to flush the Tx packet buffers. |
| 5402 | */ |
| 5403 | if (!netif_carrier_ok(netdev) && |
| 5404 | (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) |
| 5405 | adapter->flags |= FLAG_RESTART_NOW; |
| 5406 | |
David Ertman | d9554e9 | 2014-01-08 01:07:55 +0000 | [diff] [blame] | 5407 | /* If reset is necessary, do it outside of interrupt context. */ |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5408 | if (adapter->flags & FLAG_RESTART_NOW) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 5409 | schedule_work(&adapter->reset_task); |
| 5410 | /* return immediately since reset is imminent */ |
| 5411 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5412 | } |
| 5413 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5414 | e1000e_update_adaptive(&adapter->hw); |
| 5415 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 5416 | /* Simple mode for Interrupt Throttle Rate (ITR) */ |
| 5417 | if (adapter->itr_setting == 4) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5418 | /* Symmetric Tx/Rx gets a reduced ITR=2000; |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 5419 | * Total asymmetrical Tx or Rx gets ITR=8000; |
| 5420 | * everyone else is between 2000-8000. |
| 5421 | */ |
| 5422 | u32 goc = (adapter->gotc + adapter->gorc) / 10000; |
| 5423 | u32 dif = (adapter->gotc > adapter->gorc ? |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5424 | adapter->gotc - adapter->gorc : |
| 5425 | adapter->gorc - adapter->gotc) / 10000; |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 5426 | u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 5427 | |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 5428 | e1000e_write_itr(adapter, itr); |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 5429 | } |
| 5430 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5431 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5432 | if (adapter->msix_entries) |
| 5433 | ew32(ICS, adapter->rx_ring->ims_val); |
| 5434 | else |
| 5435 | ew32(ICS, E1000_ICS_RXDMT0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5436 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 5437 | /* flush pending descriptors to memory before detecting Tx hang */ |
| 5438 | e1000e_flush_descriptors(adapter); |
| 5439 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5440 | /* Force detection of hung controller every watchdog period */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5441 | adapter->detect_tx_hung = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5442 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5443 | /* With 82571 controllers, LAA may be overwritten due to controller |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5444 | * reset from the other port. Set the appropriate LAA in RAR[0] |
| 5445 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5446 | if (e1000e_get_laa_state_82571(hw)) |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 5447 | hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5448 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 5449 | if (adapter->flags2 & FLAG2_CHECK_PHY_HANG) |
| 5450 | e1000e_check_82574_phy_workaround(adapter); |
| 5451 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5452 | /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */ |
| 5453 | if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) { |
| 5454 | if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) && |
| 5455 | (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) { |
| 5456 | er32(RXSTMPH); |
| 5457 | adapter->rx_hwtstamp_cleared++; |
| 5458 | } else { |
| 5459 | adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP; |
| 5460 | } |
| 5461 | } |
| 5462 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5463 | /* Reset the timer */ |
| 5464 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 5465 | mod_timer(&adapter->watchdog_timer, |
| 5466 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 5470 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 5471 | #define E1000_TX_FLAGS_TSO 0x00000004 |
| 5472 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5473 | #define E1000_TX_FLAGS_NO_FCS 0x00000010 |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5474 | #define E1000_TX_FLAGS_HWTSTAMP 0x00000020 |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5475 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 5476 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 5477 | |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5478 | static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb, |
| 5479 | __be16 protocol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5480 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5481 | struct e1000_context_desc *context_desc; |
| 5482 | struct e1000_buffer *buffer_info; |
| 5483 | unsigned int i; |
| 5484 | u32 cmd_length = 0; |
Bruce Allan | 70443ae | 2012-08-17 06:18:13 +0000 | [diff] [blame] | 5485 | u16 ipcse = 0, mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5486 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Francois Romieu | bcf1f57 | 2014-03-30 03:14:43 +0000 | [diff] [blame] | 5487 | int err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5488 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5489 | if (!skb_is_gso(skb)) |
| 5490 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5491 | |
Francois Romieu | bcf1f57 | 2014-03-30 03:14:43 +0000 | [diff] [blame] | 5492 | err = skb_cow_head(skb, 0); |
| 5493 | if (err < 0) |
| 5494 | return err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5495 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5496 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 5497 | mss = skb_shinfo(skb)->gso_size; |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5498 | if (protocol == htons(ETH_P_IP)) { |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5499 | struct iphdr *iph = ip_hdr(skb); |
| 5500 | iph->tot_len = 0; |
| 5501 | iph->check = 0; |
| 5502 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5503 | 0, IPPROTO_TCP, 0); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5504 | cmd_length = E1000_TXD_CMD_IP; |
| 5505 | ipcse = skb_transport_offset(skb) - 1; |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 5506 | } else if (skb_is_gso_v6(skb)) { |
Heiner Kallweit | 2b316fbc | 2020-02-18 21:05:02 +0100 | [diff] [blame] | 5507 | tcp_v6_gso_csum_prep(skb); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5508 | ipcse = 0; |
| 5509 | } |
| 5510 | ipcss = skb_network_offset(skb); |
| 5511 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
| 5512 | tucss = skb_transport_offset(skb); |
| 5513 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5514 | |
| 5515 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5516 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5517 | |
| 5518 | i = tx_ring->next_to_use; |
| 5519 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 5520 | buffer_info = &tx_ring->buffer_info[i]; |
| 5521 | |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 5522 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 5523 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 5524 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5525 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 5526 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
Bruce Allan | 70443ae | 2012-08-17 06:18:13 +0000 | [diff] [blame] | 5527 | context_desc->upper_setup.tcp_fields.tucse = 0; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 5528 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5529 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 5530 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 5531 | |
| 5532 | buffer_info->time_stamp = jiffies; |
| 5533 | buffer_info->next_to_watch = i; |
| 5534 | |
| 5535 | i++; |
| 5536 | if (i == tx_ring->count) |
| 5537 | i = 0; |
| 5538 | tx_ring->next_to_use = i; |
| 5539 | |
| 5540 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5541 | } |
| 5542 | |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5543 | static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb, |
| 5544 | __be16 protocol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5545 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5546 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5547 | struct e1000_context_desc *context_desc; |
| 5548 | struct e1000_buffer *buffer_info; |
| 5549 | unsigned int i; |
| 5550 | u8 css; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5551 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5552 | |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5553 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
David Ertman | 3992c8e | 2014-04-05 03:36:15 +0000 | [diff] [blame] | 5554 | return false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5555 | |
Arthur Jones | 3f51839 | 2009-03-20 15:56:35 -0700 | [diff] [blame] | 5556 | switch (protocol) { |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5557 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5558 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 5559 | cmd_len |= E1000_TXD_CMD_TCP; |
| 5560 | break; |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5561 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5562 | /* XXX not handling all IPV6 headers */ |
| 5563 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 5564 | cmd_len |= E1000_TXD_CMD_TCP; |
| 5565 | break; |
| 5566 | default: |
| 5567 | if (unlikely(net_ratelimit())) |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 5568 | e_warn("checksum_partial proto=%x!\n", |
| 5569 | be16_to_cpu(protocol)); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5570 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5571 | } |
| 5572 | |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 5573 | css = skb_checksum_start_offset(skb); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5574 | |
| 5575 | i = tx_ring->next_to_use; |
| 5576 | buffer_info = &tx_ring->buffer_info[i]; |
| 5577 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 5578 | |
| 5579 | context_desc->lower_setup.ip_config = 0; |
| 5580 | context_desc->upper_setup.tcp_fields.tucss = css; |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5581 | context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5582 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 5583 | context_desc->tcp_seg_setup.data = 0; |
| 5584 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 5585 | |
| 5586 | buffer_info->time_stamp = jiffies; |
| 5587 | buffer_info->next_to_watch = i; |
| 5588 | |
| 5589 | i++; |
| 5590 | if (i == tx_ring->count) |
| 5591 | i = 0; |
| 5592 | tx_ring->next_to_use = i; |
| 5593 | |
David Ertman | 3992c8e | 2014-04-05 03:36:15 +0000 | [diff] [blame] | 5594 | return true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5595 | } |
| 5596 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5597 | static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb, |
| 5598 | unsigned int first, unsigned int max_per_txd, |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5599 | unsigned int nr_frags) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5600 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5601 | struct e1000_adapter *adapter = tx_ring->adapter; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5602 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5603 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 5604 | unsigned int len = skb_headlen(skb); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5605 | unsigned int offset = 0, size, count = 0, i; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5606 | unsigned int f, bytecount, segs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5607 | |
| 5608 | i = tx_ring->next_to_use; |
| 5609 | |
| 5610 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5611 | buffer_info = &tx_ring->buffer_info[i]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5612 | size = min(len, max_per_txd); |
| 5613 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5614 | buffer_info->length = size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5615 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5616 | buffer_info->next_to_watch = i; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5617 | buffer_info->dma = dma_map_single(&pdev->dev, |
| 5618 | skb->data + offset, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5619 | size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5620 | buffer_info->mapped_as_page = false; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5621 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5622 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5623 | |
| 5624 | len -= size; |
| 5625 | offset += size; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5626 | count++; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5627 | |
| 5628 | if (len) { |
| 5629 | i++; |
| 5630 | if (i == tx_ring->count) |
| 5631 | i = 0; |
| 5632 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5633 | } |
| 5634 | |
| 5635 | for (f = 0; f < nr_frags; f++) { |
Matthew Wilcox (Oracle) | d784097 | 2019-07-22 20:08:25 -0700 | [diff] [blame] | 5636 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[f]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5637 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5638 | len = skb_frag_size(frag); |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 5639 | offset = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5640 | |
| 5641 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5642 | i++; |
| 5643 | if (i == tx_ring->count) |
| 5644 | i = 0; |
| 5645 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5646 | buffer_info = &tx_ring->buffer_info[i]; |
| 5647 | size = min(len, max_per_txd); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5648 | |
| 5649 | buffer_info->length = size; |
| 5650 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5651 | buffer_info->next_to_watch = i; |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 5652 | buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5653 | offset, size, |
| 5654 | DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5655 | buffer_info->mapped_as_page = true; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5656 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5657 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5658 | |
| 5659 | len -= size; |
| 5660 | offset += size; |
| 5661 | count++; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5662 | } |
| 5663 | } |
| 5664 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5665 | segs = skb_shinfo(skb)->gso_segs ? : 1; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5666 | /* multiply data chunks by size of headers */ |
| 5667 | bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len; |
| 5668 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5669 | tx_ring->buffer_info[i].skb = skb; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5670 | tx_ring->buffer_info[i].segs = segs; |
| 5671 | tx_ring->buffer_info[i].bytecount = bytecount; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5672 | tx_ring->buffer_info[first].next_to_watch = i; |
| 5673 | |
| 5674 | return count; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5675 | |
| 5676 | dma_error: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5677 | dev_err(&pdev->dev, "Tx DMA map failed\n"); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5678 | buffer_info->dma = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5679 | if (count) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5680 | count--; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5681 | |
| 5682 | while (count--) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5683 | if (i == 0) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5684 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5685 | i--; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5686 | buffer_info = &tx_ring->buffer_info[i]; |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 5687 | e1000_put_txbuf(tx_ring, buffer_info, true); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5691 | } |
| 5692 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5693 | 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] | 5694 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5695 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5696 | struct e1000_tx_desc *tx_desc = NULL; |
| 5697 | struct e1000_buffer *buffer_info; |
| 5698 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 5699 | unsigned int i; |
| 5700 | |
| 5701 | if (tx_flags & E1000_TX_FLAGS_TSO) { |
| 5702 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5703 | E1000_TXD_CMD_TSE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5704 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 5705 | |
| 5706 | if (tx_flags & E1000_TX_FLAGS_IPV4) |
| 5707 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
| 5708 | } |
| 5709 | |
| 5710 | if (tx_flags & E1000_TX_FLAGS_CSUM) { |
| 5711 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 5712 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 5713 | } |
| 5714 | |
| 5715 | if (tx_flags & E1000_TX_FLAGS_VLAN) { |
| 5716 | txd_lower |= E1000_TXD_CMD_VLE; |
| 5717 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 5718 | } |
| 5719 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5720 | if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS)) |
| 5721 | txd_lower &= ~(E1000_TXD_CMD_IFCS); |
| 5722 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5723 | if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) { |
| 5724 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 5725 | txd_upper |= E1000_TXD_EXTCMD_TSTAMP; |
| 5726 | } |
| 5727 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5728 | i = tx_ring->next_to_use; |
| 5729 | |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 5730 | do { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5731 | buffer_info = &tx_ring->buffer_info[i]; |
| 5732 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 5733 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5734 | tx_desc->lower.data = cpu_to_le32(txd_lower | |
| 5735 | buffer_info->length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5736 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
| 5737 | |
| 5738 | i++; |
| 5739 | if (i == tx_ring->count) |
| 5740 | i = 0; |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 5741 | } while (--count > 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5742 | |
| 5743 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 5744 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5745 | /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */ |
| 5746 | if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS)) |
| 5747 | tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS)); |
| 5748 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5749 | /* Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5750 | * know there are new descriptors to fetch. (Only |
| 5751 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5752 | * such as IA-64). |
| 5753 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5754 | wmb(); |
| 5755 | |
| 5756 | tx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5757 | } |
| 5758 | |
| 5759 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 5760 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 5761 | struct sk_buff *skb) |
| 5762 | { |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 5763 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5764 | u16 length, offset; |
| 5765 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 5766 | if (skb_vlan_tag_present(skb) && |
| 5767 | !((skb_vlan_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
Bruce Allan | d60923c | 2012-12-05 06:26:56 +0000 | [diff] [blame] | 5768 | (adapter->hw.mng_cookie.status & |
| 5769 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) |
| 5770 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5771 | |
| 5772 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) |
| 5773 | return 0; |
| 5774 | |
Bruce Allan | 53aa82d | 2013-02-20 04:06:06 +0000 | [diff] [blame] | 5775 | if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5776 | return 0; |
| 5777 | |
| 5778 | { |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 5779 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5780 | struct udphdr *udp; |
| 5781 | |
| 5782 | if (ip->protocol != IPPROTO_UDP) |
| 5783 | return 0; |
| 5784 | |
| 5785 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 5786 | if (ntohs(udp->dest) != 67) |
| 5787 | return 0; |
| 5788 | |
| 5789 | offset = (u8 *)udp + 8 - skb->data; |
| 5790 | length = skb->len - offset; |
| 5791 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); |
| 5792 | } |
| 5793 | |
| 5794 | return 0; |
| 5795 | } |
| 5796 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5797 | 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] | 5798 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5799 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5800 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5801 | netif_stop_queue(adapter->netdev); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5802 | /* Herbert's original patch had: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5803 | * smp_mb__after_netif_stop_queue(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5804 | * but since that doesn't exist yet, just open code it. |
| 5805 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5806 | smp_mb(); |
| 5807 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5808 | /* We need to check again in a case another CPU has just |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5809 | * made room available. |
| 5810 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5811 | if (e1000_desc_unused(tx_ring) < size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5812 | return -EBUSY; |
| 5813 | |
| 5814 | /* A reprieve! */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5815 | netif_start_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5816 | ++adapter->restart_queue; |
| 5817 | return 0; |
| 5818 | } |
| 5819 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5820 | 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] | 5821 | { |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5822 | BUG_ON(size > tx_ring->count); |
| 5823 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5824 | if (e1000_desc_unused(tx_ring) >= size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5825 | return 0; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5826 | return __e1000_maybe_stop_tx(tx_ring, size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5827 | } |
| 5828 | |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 5829 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 5830 | struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5831 | { |
| 5832 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5833 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 5834 | unsigned int first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5835 | unsigned int tx_flags = 0; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5836 | unsigned int len = skb_headlen(skb); |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 5837 | unsigned int nr_frags; |
| 5838 | unsigned int mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5839 | int count = 0; |
| 5840 | int tso; |
| 5841 | unsigned int f; |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5842 | __be16 protocol = vlan_get_protocol(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5843 | |
| 5844 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 5845 | dev_kfree_skb_any(skb); |
| 5846 | return NETDEV_TX_OK; |
| 5847 | } |
| 5848 | |
| 5849 | if (skb->len <= 0) { |
| 5850 | dev_kfree_skb_any(skb); |
| 5851 | return NETDEV_TX_OK; |
| 5852 | } |
| 5853 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5854 | /* The minimum packet size with TCTL.PSP set is 17 bytes so |
Tushar Dave | 6e97c17 | 2012-09-14 02:21:37 +0000 | [diff] [blame] | 5855 | * pad skb in order to meet this minimum size requirement |
| 5856 | */ |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 5857 | if (skb_put_padto(skb, 17)) |
| 5858 | return NETDEV_TX_OK; |
Tushar Dave | 6e97c17 | 2012-09-14 02:21:37 +0000 | [diff] [blame] | 5859 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5860 | mss = skb_shinfo(skb)->gso_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5861 | if (mss) { |
| 5862 | u8 hdr_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5863 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5864 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5865 | * points to just header, pull a few bytes of payload from |
| 5866 | * frags into skb->data |
| 5867 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5868 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5869 | /* we do this workaround for ES2LAN, but it is un-necessary, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5870 | * avoiding it could save a lot of cycles |
| 5871 | */ |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 5872 | if (skb->data_len && (hdr_len == len)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5873 | unsigned int pull_size; |
| 5874 | |
Bruce Allan | a2a5b32 | 2012-01-31 06:37:17 +0000 | [diff] [blame] | 5875 | pull_size = min_t(unsigned int, 4, skb->data_len); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5876 | if (!__pskb_pull_tail(skb, pull_size)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5877 | e_err("__pskb_pull_tail failed.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5878 | dev_kfree_skb_any(skb); |
| 5879 | return NETDEV_TX_OK; |
| 5880 | } |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5881 | len = skb_headlen(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5882 | } |
| 5883 | } |
| 5884 | |
| 5885 | /* reserve a descriptor for the offload context */ |
| 5886 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5887 | count++; |
| 5888 | count++; |
| 5889 | |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5890 | count += DIV_ROUND_UP(len, adapter->tx_fifo_limit); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5891 | |
| 5892 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 5893 | for (f = 0; f < nr_frags; f++) |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5894 | count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]), |
| 5895 | adapter->tx_fifo_limit); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5896 | |
| 5897 | if (adapter->hw.mac.tx_pkt_filtering) |
| 5898 | e1000_transfer_dhcp_info(adapter, skb); |
| 5899 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5900 | /* need: count + 2 desc gap to keep tail from touching |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5901 | * head, otherwise try next time |
| 5902 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5903 | if (e1000_maybe_stop_tx(tx_ring, count + 2)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5904 | return NETDEV_TX_BUSY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5905 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 5906 | if (skb_vlan_tag_present(skb)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5907 | tx_flags |= E1000_TX_FLAGS_VLAN; |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 5908 | tx_flags |= (skb_vlan_tag_get(skb) << |
| 5909 | E1000_TX_FLAGS_VLAN_SHIFT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5910 | } |
| 5911 | |
| 5912 | first = tx_ring->next_to_use; |
| 5913 | |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5914 | tso = e1000_tso(tx_ring, skb, protocol); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5915 | if (tso < 0) { |
| 5916 | dev_kfree_skb_any(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5917 | return NETDEV_TX_OK; |
| 5918 | } |
| 5919 | |
| 5920 | if (tso) |
| 5921 | tx_flags |= E1000_TX_FLAGS_TSO; |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5922 | else if (e1000_tx_csum(tx_ring, skb, protocol)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5923 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 5924 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5925 | /* 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] | 5926 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5927 | * no longer assume, we must. |
| 5928 | */ |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5929 | if (protocol == htons(ETH_P_IP)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5930 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 5931 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5932 | if (unlikely(skb->no_fcs)) |
| 5933 | tx_flags |= E1000_TX_FLAGS_NO_FCS; |
| 5934 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5935 | /* if count is 0 then mapping error has occurred */ |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5936 | count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit, |
| 5937 | nr_frags); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5938 | if (count) { |
Mathias Koehrer | 6930895 | 2014-08-07 18:51:53 +0000 | [diff] [blame] | 5939 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
Jacob Keller | cff5714 | 2017-05-03 10:28:57 -0700 | [diff] [blame] | 5940 | (adapter->flags & FLAG_HAS_HW_TIMESTAMP)) { |
| 5941 | if (!adapter->tx_hwtstamp_skb) { |
| 5942 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 5943 | tx_flags |= E1000_TX_FLAGS_HWTSTAMP; |
| 5944 | adapter->tx_hwtstamp_skb = skb_get(skb); |
| 5945 | adapter->tx_hwtstamp_start = jiffies; |
| 5946 | schedule_work(&adapter->tx_hwtstamp_work); |
| 5947 | } else { |
| 5948 | adapter->tx_hwtstamp_skipped++; |
| 5949 | } |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5950 | } |
Willem de Bruijn | 80be312 | 2012-04-27 09:04:05 +0000 | [diff] [blame] | 5951 | |
Miroslav Lichvar | 74abc9b1 | 2017-05-19 17:52:41 +0200 | [diff] [blame] | 5952 | skb_tx_timestamp(skb); |
| 5953 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 5954 | netdev_sent_queue(netdev, skb->len); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5955 | e1000_tx_queue(tx_ring, tx_flags, count); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5956 | /* Make sure there is space in the ring for the next send. */ |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5957 | e1000_maybe_stop_tx(tx_ring, |
| 5958 | (MAX_SKB_FRAGS * |
| 5959 | DIV_ROUND_UP(PAGE_SIZE, |
| 5960 | adapter->tx_fifo_limit) + 2)); |
Florian Westphal | 472f31f | 2015-01-09 09:26:14 +0000 | [diff] [blame] | 5961 | |
Florian Westphal | 6b16f9e | 2019-04-01 16:42:14 +0200 | [diff] [blame] | 5962 | if (!netdev_xmit_more() || |
Florian Westphal | 472f31f | 2015-01-09 09:26:14 +0000 | [diff] [blame] | 5963 | netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) { |
| 5964 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 5965 | e1000e_update_tdt_wa(tx_ring, |
| 5966 | tx_ring->next_to_use); |
| 5967 | else |
| 5968 | writel(tx_ring->next_to_use, tx_ring->tail); |
Florian Westphal | 472f31f | 2015-01-09 09:26:14 +0000 | [diff] [blame] | 5969 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5970 | } else { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5971 | dev_kfree_skb_any(skb); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5972 | tx_ring->buffer_info[first].time_stamp = 0; |
| 5973 | tx_ring->next_to_use = first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5974 | } |
| 5975 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5976 | return NETDEV_TX_OK; |
| 5977 | } |
| 5978 | |
| 5979 | /** |
| 5980 | * e1000_tx_timeout - Respond to a Tx Hang |
| 5981 | * @netdev: network interface device structure |
| 5982 | **/ |
Michael S. Tsirkin | 0290bd2 | 2019-12-10 09:23:51 -0500 | [diff] [blame] | 5983 | static void e1000_tx_timeout(struct net_device *netdev, unsigned int txqueue) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5984 | { |
| 5985 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5986 | |
| 5987 | /* Do the reset outside of interrupt context */ |
| 5988 | adapter->tx_timeout_count++; |
| 5989 | schedule_work(&adapter->reset_task); |
| 5990 | } |
| 5991 | |
| 5992 | static void e1000_reset_task(struct work_struct *work) |
| 5993 | { |
| 5994 | struct e1000_adapter *adapter; |
| 5995 | adapter = container_of(work, struct e1000_adapter, reset_task); |
| 5996 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 5997 | /* don't run the task if already down */ |
| 5998 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 5999 | return; |
| 6000 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 6001 | if (!(adapter->flags & FLAG_RESTART_NOW)) { |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 6002 | e1000e_dump(adapter); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 6003 | e_err("Reset adapter unexpectedly\n"); |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 6004 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6005 | e1000e_reinit_locked(adapter); |
| 6006 | } |
| 6007 | |
| 6008 | /** |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6009 | * e1000_get_stats64 - Get System Network Statistics |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6010 | * @netdev: network interface device structure |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6011 | * @stats: rtnl_link_stats64 pointer |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6012 | * |
| 6013 | * Returns the address of the device statistics structure. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6014 | **/ |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 6015 | void e1000e_get_stats64(struct net_device *netdev, |
| 6016 | struct rtnl_link_stats64 *stats) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6017 | { |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6018 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6019 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6020 | spin_lock(&adapter->stats64_lock); |
| 6021 | e1000e_update_stats(adapter); |
| 6022 | /* Fill out the OS statistics structure */ |
| 6023 | stats->rx_bytes = adapter->stats.gorc; |
| 6024 | stats->rx_packets = adapter->stats.gprc; |
| 6025 | stats->tx_bytes = adapter->stats.gotc; |
| 6026 | stats->tx_packets = adapter->stats.gptc; |
| 6027 | stats->multicast = adapter->stats.mprc; |
| 6028 | stats->collisions = adapter->stats.colc; |
| 6029 | |
| 6030 | /* Rx Errors */ |
| 6031 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6032 | /* RLEC on some newer hardware can be incorrect so build |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6033 | * our own version based on RUC and ROC |
| 6034 | */ |
| 6035 | stats->rx_errors = adapter->stats.rxerrc + |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 6036 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 6037 | adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr; |
| 6038 | stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc; |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6039 | stats->rx_crc_errors = adapter->stats.crcerrs; |
| 6040 | stats->rx_frame_errors = adapter->stats.algnerrc; |
| 6041 | stats->rx_missed_errors = adapter->stats.mpc; |
| 6042 | |
| 6043 | /* Tx Errors */ |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 6044 | stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol; |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6045 | stats->tx_aborted_errors = adapter->stats.ecol; |
| 6046 | stats->tx_window_errors = adapter->stats.latecol; |
| 6047 | stats->tx_carrier_errors = adapter->stats.tncrs; |
| 6048 | |
| 6049 | /* Tx Dropped needs to be maintained elsewhere */ |
| 6050 | |
| 6051 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6052 | } |
| 6053 | |
| 6054 | /** |
| 6055 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 6056 | * @netdev: network interface device structure |
| 6057 | * @new_mtu: new value for maximum frame size |
| 6058 | * |
| 6059 | * Returns 0 on success, negative on failure |
| 6060 | **/ |
| 6061 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 6062 | { |
| 6063 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 8084b86 | 2015-05-02 00:52:00 -0700 | [diff] [blame] | 6064 | int max_frame = new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6065 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 6066 | /* Jumbo frame support */ |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 6067 | if ((new_mtu > ETH_DATA_LEN) && |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 6068 | !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
| 6069 | e_err("Jumbo Frames not supported.\n"); |
| 6070 | return -EINVAL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6071 | } |
| 6072 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 6073 | /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */ |
| 6074 | if ((adapter->hw.mac.type >= e1000_pch2lan) && |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 6075 | !(adapter->flags2 & FLAG2_CRC_STRIPPING) && |
| 6076 | (new_mtu > ETH_DATA_LEN)) { |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 6077 | 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] | 6078 | return -EINVAL; |
| 6079 | } |
| 6080 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6081 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 6082 | usleep_range(1000, 1100); |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 6083 | /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6084 | adapter->max_frame_size = max_frame; |
Florian Fainelli | 1229913 | 2019-11-07 14:35:36 -0800 | [diff] [blame] | 6085 | netdev_dbg(netdev, "changing MTU from %d to %d\n", |
| 6086 | netdev->mtu, new_mtu); |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 6087 | netdev->mtu = new_mtu; |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 6088 | |
| 6089 | pm_runtime_get_sync(netdev->dev.parent); |
| 6090 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6091 | if (netif_running(netdev)) |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6092 | e1000e_down(adapter, true); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6093 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6094 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6095 | * means we reserve 2 more, this pushes us to allocate from the next |
| 6096 | * larger slab size. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6097 | * i.e. RXBUFFER_2048 --> size-4096 slab |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6098 | * However with the new *_jumbo_rx* routines, jumbo receives will use |
| 6099 | * fragmented skbs |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6100 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6101 | |
Jesse Brandeburg | 9926146 | 2010-01-22 22:56:16 +0000 | [diff] [blame] | 6102 | if (max_frame <= 2048) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6103 | adapter->rx_buffer_len = 2048; |
| 6104 | else |
| 6105 | adapter->rx_buffer_len = 4096; |
| 6106 | |
| 6107 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
Alexander Duyck | 8084b86 | 2015-05-02 00:52:00 -0700 | [diff] [blame] | 6108 | if (max_frame <= (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 6109 | adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6110 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6111 | if (netif_running(netdev)) |
| 6112 | e1000e_up(adapter); |
| 6113 | else |
| 6114 | e1000e_reset(adapter); |
| 6115 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 6116 | pm_runtime_put_sync(netdev->dev.parent); |
| 6117 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6118 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 6119 | |
| 6120 | return 0; |
| 6121 | } |
| 6122 | |
| 6123 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 6124 | int cmd) |
| 6125 | { |
| 6126 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6127 | struct mii_ioctl_data *data = if_mii(ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6128 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6129 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6130 | return -EOPNOTSUPP; |
| 6131 | |
| 6132 | switch (cmd) { |
| 6133 | case SIOCGMIIPHY: |
| 6134 | data->phy_id = adapter->hw.phy.addr; |
| 6135 | break; |
| 6136 | case SIOCGMIIREG: |
Bruce Allan | b16a002 | 2009-11-20 23:24:30 +0000 | [diff] [blame] | 6137 | e1000_phy_read_status(adapter); |
| 6138 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 6139 | switch (data->reg_num & 0x1F) { |
| 6140 | case MII_BMCR: |
| 6141 | data->val_out = adapter->phy_regs.bmcr; |
| 6142 | break; |
| 6143 | case MII_BMSR: |
| 6144 | data->val_out = adapter->phy_regs.bmsr; |
| 6145 | break; |
| 6146 | case MII_PHYSID1: |
| 6147 | data->val_out = (adapter->hw.phy.id >> 16); |
| 6148 | break; |
| 6149 | case MII_PHYSID2: |
| 6150 | data->val_out = (adapter->hw.phy.id & 0xFFFF); |
| 6151 | break; |
| 6152 | case MII_ADVERTISE: |
| 6153 | data->val_out = adapter->phy_regs.advertise; |
| 6154 | break; |
| 6155 | case MII_LPA: |
| 6156 | data->val_out = adapter->phy_regs.lpa; |
| 6157 | break; |
| 6158 | case MII_EXPANSION: |
| 6159 | data->val_out = adapter->phy_regs.expansion; |
| 6160 | break; |
| 6161 | case MII_CTRL1000: |
| 6162 | data->val_out = adapter->phy_regs.ctrl1000; |
| 6163 | break; |
| 6164 | case MII_STAT1000: |
| 6165 | data->val_out = adapter->phy_regs.stat1000; |
| 6166 | break; |
| 6167 | case MII_ESTATUS: |
| 6168 | data->val_out = adapter->phy_regs.estatus; |
| 6169 | break; |
| 6170 | default: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6171 | return -EIO; |
| 6172 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6173 | break; |
| 6174 | case SIOCSMIIREG: |
| 6175 | default: |
| 6176 | return -EOPNOTSUPP; |
| 6177 | } |
| 6178 | return 0; |
| 6179 | } |
| 6180 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6181 | /** |
| 6182 | * e1000e_hwtstamp_ioctl - control hardware time stamping |
| 6183 | * @netdev: network interface device structure |
| 6184 | * @ifreq: interface request |
| 6185 | * |
| 6186 | * Outgoing time stamping can be enabled and disabled. Play nice and |
| 6187 | * disable it when requested, although it shouldn't cause any overhead |
| 6188 | * when no packet needs it. At most one packet in the queue may be |
| 6189 | * marked for time stamping, otherwise it would be impossible to tell |
| 6190 | * for sure to which packet the hardware time stamp belongs. |
| 6191 | * |
| 6192 | * Incoming time stamping has to be configured via the hardware filters. |
| 6193 | * Not all combinations are supported, in particular event type has to be |
| 6194 | * specified. Matching the kind of event packet is not supported, with the |
| 6195 | * exception of "all V2 events regardless of level 2 or 4". |
| 6196 | **/ |
Ben Hutchings | 4e8cff6 | 2013-11-18 23:07:16 +0000 | [diff] [blame] | 6197 | static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr) |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6198 | { |
| 6199 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6200 | struct hwtstamp_config config; |
| 6201 | int ret_val; |
| 6202 | |
| 6203 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) |
| 6204 | return -EFAULT; |
| 6205 | |
Ben Hutchings | 62d7e3a | 2013-11-14 00:41:38 +0000 | [diff] [blame] | 6206 | ret_val = e1000e_config_hwtstamp(adapter, &config); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6207 | if (ret_val) |
| 6208 | return ret_val; |
| 6209 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 6210 | switch (config.rx_filter) { |
| 6211 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 6212 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 6213 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 6214 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 6215 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 6216 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 6217 | /* With V2 type filters which specify a Sync or Delay Request, |
| 6218 | * Path Delay Request/Response messages are also time stamped |
| 6219 | * by hardware so notify the caller the requested packets plus |
| 6220 | * some others are time stamped. |
| 6221 | */ |
| 6222 | config.rx_filter = HWTSTAMP_FILTER_SOME; |
| 6223 | break; |
| 6224 | default: |
| 6225 | break; |
| 6226 | } |
| 6227 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6228 | return copy_to_user(ifr->ifr_data, &config, |
| 6229 | sizeof(config)) ? -EFAULT : 0; |
| 6230 | } |
| 6231 | |
Ben Hutchings | 4e8cff6 | 2013-11-18 23:07:16 +0000 | [diff] [blame] | 6232 | static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr) |
| 6233 | { |
| 6234 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6235 | |
| 6236 | return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config, |
| 6237 | sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0; |
| 6238 | } |
| 6239 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6240 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 6241 | { |
| 6242 | switch (cmd) { |
| 6243 | case SIOCGMIIPHY: |
| 6244 | case SIOCGMIIREG: |
| 6245 | case SIOCSMIIREG: |
| 6246 | return e1000_mii_ioctl(netdev, ifr, cmd); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6247 | case SIOCSHWTSTAMP: |
Ben Hutchings | 4e8cff6 | 2013-11-18 23:07:16 +0000 | [diff] [blame] | 6248 | return e1000e_hwtstamp_set(netdev, ifr); |
| 6249 | case SIOCGHWTSTAMP: |
| 6250 | return e1000e_hwtstamp_get(netdev, ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6251 | default: |
| 6252 | return -EOPNOTSUPP; |
| 6253 | } |
| 6254 | } |
| 6255 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6256 | static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) |
| 6257 | { |
| 6258 | struct e1000_hw *hw = &adapter->hw; |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6259 | u32 i, mac_reg, wuc; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6260 | u16 phy_reg, wuc_enable; |
Bruce Allan | 70806a7 | 2013-01-05 05:08:37 +0000 | [diff] [blame] | 6261 | int retval; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6262 | |
| 6263 | /* copy MAC RARs to PHY RARs */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 6264 | e1000_copy_rx_addrs_to_phy_ich8lan(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6265 | |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6266 | retval = hw->phy.ops.acquire(hw); |
| 6267 | if (retval) { |
| 6268 | e_err("Could not acquire PHY\n"); |
| 6269 | return retval; |
| 6270 | } |
| 6271 | |
| 6272 | /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */ |
| 6273 | retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
| 6274 | if (retval) |
Bruce Allan | 75ce153 | 2012-02-08 02:54:48 +0000 | [diff] [blame] | 6275 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6276 | |
| 6277 | /* copy MAC MTA to PHY MTA - only needed for pchlan */ |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6278 | for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { |
| 6279 | mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6280 | hw->phy.ops.write_reg_page(hw, BM_MTA(i), |
| 6281 | (u16)(mac_reg & 0xFFFF)); |
| 6282 | hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1, |
| 6283 | (u16)((mac_reg >> 16) & 0xFFFF)); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6284 | } |
| 6285 | |
| 6286 | /* configure PHY Rx Control register */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6287 | hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6288 | mac_reg = er32(RCTL); |
| 6289 | if (mac_reg & E1000_RCTL_UPE) |
| 6290 | phy_reg |= BM_RCTL_UPE; |
| 6291 | if (mac_reg & E1000_RCTL_MPE) |
| 6292 | phy_reg |= BM_RCTL_MPE; |
| 6293 | phy_reg &= ~(BM_RCTL_MO_MASK); |
| 6294 | if (mac_reg & E1000_RCTL_MO_3) |
| 6295 | phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 6296 | << BM_RCTL_MO_SHIFT); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6297 | if (mac_reg & E1000_RCTL_BAM) |
| 6298 | phy_reg |= BM_RCTL_BAM; |
| 6299 | if (mac_reg & E1000_RCTL_PMCF) |
| 6300 | phy_reg |= BM_RCTL_PMCF; |
| 6301 | mac_reg = er32(CTRL); |
| 6302 | if (mac_reg & E1000_CTRL_RFCE) |
| 6303 | phy_reg |= BM_RCTL_RFCE; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6304 | hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6305 | |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6306 | wuc = E1000_WUC_PME_EN; |
| 6307 | if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC)) |
| 6308 | wuc |= E1000_WUC_APME; |
| 6309 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6310 | /* enable PHY wakeup in MAC register */ |
| 6311 | ew32(WUFC, wufc); |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6312 | ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME | |
| 6313 | E1000_WUC_PME_STATUS | wuc)); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6314 | |
| 6315 | /* configure and enable PHY wakeup in PHY registers */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6316 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc); |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6317 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6318 | |
| 6319 | /* activate PHY wakeup */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6320 | wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; |
| 6321 | retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6322 | if (retval) |
| 6323 | e_err("Could not set PHY Host Wakeup bit\n"); |
Bruce Allan | 75ce153 | 2012-02-08 02:54:48 +0000 | [diff] [blame] | 6324 | release: |
Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 6325 | hw->phy.ops.release(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6326 | |
| 6327 | return retval; |
| 6328 | } |
| 6329 | |
David Ertman | 2a7e19a | 2014-07-11 06:21:31 +0000 | [diff] [blame] | 6330 | static void e1000e_flush_lpic(struct pci_dev *pdev) |
| 6331 | { |
| 6332 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6333 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6334 | struct e1000_hw *hw = &adapter->hw; |
| 6335 | u32 ret_val; |
| 6336 | |
| 6337 | pm_runtime_get_sync(netdev->dev.parent); |
| 6338 | |
| 6339 | ret_val = hw->phy.ops.acquire(hw); |
| 6340 | if (ret_val) |
| 6341 | goto fl_out; |
| 6342 | |
| 6343 | pr_info("EEE TX LPI TIMER: %08X\n", |
| 6344 | er32(LPIC) >> E1000_LPIC_LPIET_SHIFT); |
| 6345 | |
| 6346 | hw->phy.ops.release(hw); |
| 6347 | |
| 6348 | fl_out: |
| 6349 | pm_runtime_put_sync(netdev->dev.parent); |
| 6350 | } |
| 6351 | |
Sasha Neftin | 203bddf | 2019-10-23 18:09:17 +0300 | [diff] [blame] | 6352 | #ifdef CONFIG_PM_SLEEP |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6353 | /* S0ix implementation */ |
| 6354 | static void e1000e_s0ix_entry_flow(struct e1000_adapter *adapter) |
| 6355 | { |
| 6356 | struct e1000_hw *hw = &adapter->hw; |
| 6357 | u32 mac_data; |
| 6358 | u16 phy_data; |
| 6359 | |
| 6360 | /* Disable the periodic inband message, |
| 6361 | * don't request PCIe clock in K1 page770_17[10:9] = 10b |
| 6362 | */ |
| 6363 | e1e_rphy(hw, HV_PM_CTRL, &phy_data); |
| 6364 | phy_data &= ~HV_PM_CTRL_K1_CLK_REQ; |
| 6365 | phy_data |= BIT(10); |
| 6366 | e1e_wphy(hw, HV_PM_CTRL, phy_data); |
| 6367 | |
| 6368 | /* Make sure we don't exit K1 every time a new packet arrives |
| 6369 | * 772_29[5] = 1 CS_Mode_Stay_In_K1 |
| 6370 | */ |
| 6371 | e1e_rphy(hw, I217_CGFREG, &phy_data); |
| 6372 | phy_data |= BIT(5); |
| 6373 | e1e_wphy(hw, I217_CGFREG, phy_data); |
| 6374 | |
| 6375 | /* Change the MAC/PHY interface to SMBus |
| 6376 | * Force the SMBus in PHY page769_23[0] = 1 |
| 6377 | * Force the SMBus in MAC CTRL_EXT[11] = 1 |
| 6378 | */ |
| 6379 | e1e_rphy(hw, CV_SMB_CTRL, &phy_data); |
| 6380 | phy_data |= CV_SMB_CTRL_FORCE_SMBUS; |
| 6381 | e1e_wphy(hw, CV_SMB_CTRL, phy_data); |
| 6382 | mac_data = er32(CTRL_EXT); |
| 6383 | mac_data |= E1000_CTRL_EXT_FORCE_SMBUS; |
| 6384 | ew32(CTRL_EXT, mac_data); |
| 6385 | |
| 6386 | /* DFT control: PHY bit: page769_20[0] = 1 |
| 6387 | * Gate PPW via EXTCNF_CTRL - set 0x0F00[7] = 1 |
| 6388 | */ |
| 6389 | e1e_rphy(hw, I82579_DFT_CTRL, &phy_data); |
| 6390 | phy_data |= BIT(0); |
| 6391 | e1e_wphy(hw, I82579_DFT_CTRL, phy_data); |
| 6392 | |
| 6393 | mac_data = er32(EXTCNF_CTRL); |
| 6394 | mac_data |= E1000_EXTCNF_CTRL_GATE_PHY_CFG; |
| 6395 | ew32(EXTCNF_CTRL, mac_data); |
| 6396 | |
| 6397 | /* Check MAC Tx/Rx packet buffer pointers. |
| 6398 | * Reset MAC Tx/Rx packet buffer pointers to suppress any |
| 6399 | * pending traffic indication that would prevent power gating. |
| 6400 | */ |
| 6401 | mac_data = er32(TDFH); |
| 6402 | if (mac_data) |
| 6403 | ew32(TDFH, 0); |
| 6404 | mac_data = er32(TDFT); |
| 6405 | if (mac_data) |
| 6406 | ew32(TDFT, 0); |
| 6407 | mac_data = er32(TDFHS); |
| 6408 | if (mac_data) |
| 6409 | ew32(TDFHS, 0); |
| 6410 | mac_data = er32(TDFTS); |
| 6411 | if (mac_data) |
| 6412 | ew32(TDFTS, 0); |
| 6413 | mac_data = er32(TDFPC); |
| 6414 | if (mac_data) |
| 6415 | ew32(TDFPC, 0); |
| 6416 | mac_data = er32(RDFH); |
| 6417 | if (mac_data) |
| 6418 | ew32(RDFH, 0); |
| 6419 | mac_data = er32(RDFT); |
| 6420 | if (mac_data) |
| 6421 | ew32(RDFT, 0); |
| 6422 | mac_data = er32(RDFHS); |
| 6423 | if (mac_data) |
| 6424 | ew32(RDFHS, 0); |
| 6425 | mac_data = er32(RDFTS); |
| 6426 | if (mac_data) |
| 6427 | ew32(RDFTS, 0); |
| 6428 | mac_data = er32(RDFPC); |
| 6429 | if (mac_data) |
| 6430 | ew32(RDFPC, 0); |
| 6431 | |
| 6432 | /* Enable the Dynamic Power Gating in the MAC */ |
| 6433 | mac_data = er32(FEXTNVM7); |
| 6434 | mac_data |= BIT(22); |
| 6435 | ew32(FEXTNVM7, mac_data); |
| 6436 | |
| 6437 | /* Disable the time synchronization clock */ |
| 6438 | mac_data = er32(FEXTNVM7); |
| 6439 | mac_data |= BIT(31); |
| 6440 | mac_data &= ~BIT(0); |
| 6441 | ew32(FEXTNVM7, mac_data); |
| 6442 | |
| 6443 | /* Dynamic Power Gating Enable */ |
| 6444 | mac_data = er32(CTRL_EXT); |
| 6445 | mac_data |= BIT(3); |
| 6446 | ew32(CTRL_EXT, mac_data); |
| 6447 | |
Vitaly Lifshits | 632fbd5 | 2020-03-12 13:57:07 +0200 | [diff] [blame] | 6448 | /* Disable disconnected cable conditioning for Power Gating */ |
| 6449 | mac_data = er32(DPGFR); |
| 6450 | mac_data |= BIT(2); |
| 6451 | ew32(DPGFR, mac_data); |
| 6452 | |
| 6453 | /* Don't wake from dynamic Power Gating with clock request */ |
| 6454 | mac_data = er32(FEXTNVM12); |
| 6455 | mac_data |= BIT(12); |
| 6456 | ew32(FEXTNVM12, mac_data); |
| 6457 | |
| 6458 | /* Ungate PGCB clock */ |
| 6459 | mac_data = er32(FEXTNVM9); |
| 6460 | mac_data |= BIT(28); |
| 6461 | ew32(FEXTNVM9, mac_data); |
| 6462 | |
| 6463 | /* Enable K1 off to enable mPHY Power Gating */ |
| 6464 | mac_data = er32(FEXTNVM6); |
| 6465 | mac_data |= BIT(31); |
| 6466 | ew32(FEXTNVM12, mac_data); |
| 6467 | |
| 6468 | /* Enable mPHY power gating for any link and speed */ |
| 6469 | mac_data = er32(FEXTNVM8); |
| 6470 | mac_data |= BIT(9); |
| 6471 | ew32(FEXTNVM8, mac_data); |
| 6472 | |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6473 | /* Enable the Dynamic Clock Gating in the DMA and MAC */ |
| 6474 | mac_data = er32(CTRL_EXT); |
| 6475 | mac_data |= E1000_CTRL_EXT_DMA_DYN_CLK_EN; |
| 6476 | ew32(CTRL_EXT, mac_data); |
| 6477 | |
| 6478 | /* No MAC DPG gating SLP_S0 in modern standby |
| 6479 | * Switch the logic of the lanphypc to use PMC counter |
| 6480 | */ |
| 6481 | mac_data = er32(FEXTNVM5); |
| 6482 | mac_data |= BIT(7); |
| 6483 | ew32(FEXTNVM5, mac_data); |
| 6484 | } |
| 6485 | |
| 6486 | static void e1000e_s0ix_exit_flow(struct e1000_adapter *adapter) |
| 6487 | { |
| 6488 | struct e1000_hw *hw = &adapter->hw; |
| 6489 | u32 mac_data; |
| 6490 | u16 phy_data; |
| 6491 | |
| 6492 | /* Disable the Dynamic Power Gating in the MAC */ |
| 6493 | mac_data = er32(FEXTNVM7); |
| 6494 | mac_data &= 0xFFBFFFFF; |
| 6495 | ew32(FEXTNVM7, mac_data); |
| 6496 | |
| 6497 | /* Enable the time synchronization clock */ |
| 6498 | mac_data = er32(FEXTNVM7); |
| 6499 | mac_data |= BIT(0); |
| 6500 | ew32(FEXTNVM7, mac_data); |
| 6501 | |
Vitaly Lifshits | 632fbd5 | 2020-03-12 13:57:07 +0200 | [diff] [blame] | 6502 | /* Disable mPHY power gating for any link and speed */ |
| 6503 | mac_data = er32(FEXTNVM8); |
| 6504 | mac_data &= ~BIT(9); |
| 6505 | ew32(FEXTNVM8, mac_data); |
| 6506 | |
| 6507 | /* Disable K1 off */ |
| 6508 | mac_data = er32(FEXTNVM6); |
| 6509 | mac_data &= ~BIT(31); |
| 6510 | ew32(FEXTNVM12, mac_data); |
| 6511 | |
| 6512 | /* Disable Ungate PGCB clock */ |
| 6513 | mac_data = er32(FEXTNVM9); |
| 6514 | mac_data &= ~BIT(28); |
| 6515 | ew32(FEXTNVM9, mac_data); |
| 6516 | |
| 6517 | /* Cancel not waking from dynamic |
| 6518 | * Power Gating with clock request |
| 6519 | */ |
| 6520 | mac_data = er32(FEXTNVM12); |
| 6521 | mac_data &= ~BIT(12); |
| 6522 | ew32(FEXTNVM12, mac_data); |
| 6523 | |
| 6524 | /* Cancel disable disconnected cable conditioning |
| 6525 | * for Power Gating |
| 6526 | */ |
| 6527 | mac_data = er32(DPGFR); |
| 6528 | mac_data &= ~BIT(2); |
| 6529 | ew32(DPGFR, mac_data); |
| 6530 | |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6531 | /* Disable Dynamic Power Gating */ |
| 6532 | mac_data = er32(CTRL_EXT); |
| 6533 | mac_data &= 0xFFFFFFF7; |
| 6534 | ew32(CTRL_EXT, mac_data); |
| 6535 | |
| 6536 | /* Disable the Dynamic Clock Gating in the DMA and MAC */ |
| 6537 | mac_data = er32(CTRL_EXT); |
| 6538 | mac_data &= 0xFFF7FFFF; |
| 6539 | ew32(CTRL_EXT, mac_data); |
| 6540 | |
| 6541 | /* Revert the lanphypc logic to use the internal Gbe counter |
| 6542 | * and not the PMC counter |
| 6543 | */ |
| 6544 | mac_data = er32(FEXTNVM5); |
| 6545 | mac_data &= 0xFFFFFF7F; |
| 6546 | ew32(FEXTNVM5, mac_data); |
| 6547 | |
| 6548 | /* Enable the periodic inband message, |
| 6549 | * Request PCIe clock in K1 page770_17[10:9] =01b |
| 6550 | */ |
| 6551 | e1e_rphy(hw, HV_PM_CTRL, &phy_data); |
| 6552 | phy_data &= 0xFBFF; |
| 6553 | phy_data |= HV_PM_CTRL_K1_CLK_REQ; |
| 6554 | e1e_wphy(hw, HV_PM_CTRL, phy_data); |
| 6555 | |
| 6556 | /* Return back configuration |
| 6557 | * 772_29[5] = 0 CS_Mode_Stay_In_K1 |
| 6558 | */ |
| 6559 | e1e_rphy(hw, I217_CGFREG, &phy_data); |
| 6560 | phy_data &= 0xFFDF; |
| 6561 | e1e_wphy(hw, I217_CGFREG, phy_data); |
| 6562 | |
| 6563 | /* Change the MAC/PHY interface to Kumeran |
| 6564 | * Unforce the SMBus in PHY page769_23[0] = 0 |
| 6565 | * Unforce the SMBus in MAC CTRL_EXT[11] = 0 |
| 6566 | */ |
| 6567 | e1e_rphy(hw, CV_SMB_CTRL, &phy_data); |
| 6568 | phy_data &= ~CV_SMB_CTRL_FORCE_SMBUS; |
| 6569 | e1e_wphy(hw, CV_SMB_CTRL, phy_data); |
| 6570 | mac_data = er32(CTRL_EXT); |
| 6571 | mac_data &= ~E1000_CTRL_EXT_FORCE_SMBUS; |
| 6572 | ew32(CTRL_EXT, mac_data); |
| 6573 | } |
Sasha Neftin | 203bddf | 2019-10-23 18:09:17 +0300 | [diff] [blame] | 6574 | #endif /* CONFIG_PM_SLEEP */ |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6575 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6576 | static int e1000e_pm_freeze(struct device *dev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6577 | { |
Chuhong Yuan | ee2e80c | 2019-07-23 22:15:13 +0800 | [diff] [blame] | 6578 | struct net_device *netdev = dev_get_drvdata(dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6579 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 6580 | bool present; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6581 | |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 6582 | rtnl_lock(); |
| 6583 | |
| 6584 | present = netif_device_present(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6585 | netif_device_detach(netdev); |
| 6586 | |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 6587 | if (present && netif_running(netdev)) { |
Bruce Allan | bb9e44d | 2012-03-21 00:39:12 +0000 | [diff] [blame] | 6588 | int count = E1000_CHECK_RESET_COUNT; |
| 6589 | |
| 6590 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 6591 | usleep_range(10000, 11000); |
Bruce Allan | bb9e44d | 2012-03-21 00:39:12 +0000 | [diff] [blame] | 6592 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6593 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6594 | |
| 6595 | /* Quiesce the device without resetting the hardware */ |
| 6596 | e1000e_down(adapter, false); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6597 | e1000_free_irq(adapter); |
| 6598 | } |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 6599 | rtnl_unlock(); |
| 6600 | |
Jeff Kirsher | 9f47a48 | 2017-03-23 20:47:15 -0700 | [diff] [blame] | 6601 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6602 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6603 | /* Allow time for pending master requests to run */ |
| 6604 | e1000e_disable_pcie_master(&adapter->hw); |
| 6605 | |
| 6606 | return 0; |
| 6607 | } |
| 6608 | |
| 6609 | static int __e1000_shutdown(struct pci_dev *pdev, bool runtime) |
| 6610 | { |
| 6611 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6612 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6613 | struct e1000_hw *hw = &adapter->hw; |
Chen Yu | 6bf6be1 | 2020-05-22 01:59:00 +0800 | [diff] [blame^] | 6614 | u32 ctrl, ctrl_ext, rctl, status, wufc; |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6615 | int retval = 0; |
| 6616 | |
Chen Yu | 6bf6be1 | 2020-05-22 01:59:00 +0800 | [diff] [blame^] | 6617 | /* Runtime suspend should only enable wakeup for link changes */ |
| 6618 | if (runtime) |
| 6619 | wufc = E1000_WUFC_LNKC; |
| 6620 | else if (device_may_wakeup(&pdev->dev)) |
| 6621 | wufc = adapter->wol; |
| 6622 | else |
| 6623 | wufc = 0; |
| 6624 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6625 | status = er32(STATUS); |
| 6626 | if (status & E1000_STATUS_LU) |
| 6627 | wufc &= ~E1000_WUFC_LNKC; |
| 6628 | |
| 6629 | if (wufc) { |
| 6630 | e1000_setup_rctl(adapter); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 6631 | e1000e_set_rx_mode(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6632 | |
| 6633 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 6634 | if (wufc & E1000_WUFC_MC) { |
| 6635 | rctl = er32(RCTL); |
| 6636 | rctl |= E1000_RCTL_MPE; |
| 6637 | ew32(RCTL, rctl); |
| 6638 | } |
| 6639 | |
| 6640 | ctrl = er32(CTRL); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6641 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 6642 | if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) |
| 6643 | ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6644 | ew32(CTRL, ctrl); |
| 6645 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6646 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
| 6647 | adapter->hw.phy.media_type == |
| 6648 | e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6649 | /* keep the laser running in D3 */ |
| 6650 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | 93a23f4 | 2009-12-08 07:27:41 +0000 | [diff] [blame] | 6651 | ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6652 | ew32(CTRL_EXT, ctrl_ext); |
| 6653 | } |
| 6654 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 6655 | if (!runtime) |
| 6656 | e1000e_power_up_phy(adapter); |
| 6657 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6658 | if (adapter->flags & FLAG_IS_ICH) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 6659 | e1000_suspend_workarounds_ich8lan(&adapter->hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6660 | |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 6661 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6662 | /* enable wakeup by the PHY */ |
| 6663 | retval = e1000_init_phy_wakeup(adapter, wufc); |
| 6664 | if (retval) |
| 6665 | return retval; |
| 6666 | } else { |
| 6667 | /* enable wakeup by the MAC */ |
| 6668 | ew32(WUFC, wufc); |
| 6669 | ew32(WUC, E1000_WUC_PME_EN); |
| 6670 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6671 | } else { |
| 6672 | ew32(WUC, 0); |
| 6673 | ew32(WUFC, 0); |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6674 | |
| 6675 | e1000_power_down_phy(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6676 | } |
| 6677 | |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6678 | if (adapter->hw.phy.type == e1000_phy_igp_3) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6679 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 6680 | } else if (hw->mac.type >= e1000_pch_lpt) { |
Chen Yu | 6bf6be1 | 2020-05-22 01:59:00 +0800 | [diff] [blame^] | 6681 | if (wufc && !(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC))) |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6682 | /* ULP does not support wake from unicast, multicast |
| 6683 | * or broadcast. |
| 6684 | */ |
| 6685 | retval = e1000_enable_ulp_lpt_lp(hw, !runtime); |
| 6686 | |
| 6687 | if (retval) |
| 6688 | return retval; |
| 6689 | } |
| 6690 | |
Raanan Avargil | f5ac744 | 2015-07-06 16:48:00 +0300 | [diff] [blame] | 6691 | /* Ensure that the appropriate bits are set in LPI_CTRL |
| 6692 | * for EEE in Sx |
| 6693 | */ |
| 6694 | if ((hw->phy.type >= e1000_phy_i217) && |
| 6695 | adapter->eee_advert && hw->dev_spec.ich8lan.eee_lp_ability) { |
| 6696 | u16 lpi_ctrl = 0; |
| 6697 | |
| 6698 | retval = hw->phy.ops.acquire(hw); |
| 6699 | if (!retval) { |
| 6700 | retval = e1e_rphy_locked(hw, I82579_LPI_CTRL, |
| 6701 | &lpi_ctrl); |
| 6702 | if (!retval) { |
| 6703 | if (adapter->eee_advert & |
| 6704 | hw->dev_spec.ich8lan.eee_lp_ability & |
| 6705 | I82579_EEE_100_SUPPORTED) |
| 6706 | lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE; |
| 6707 | if (adapter->eee_advert & |
| 6708 | hw->dev_spec.ich8lan.eee_lp_ability & |
| 6709 | I82579_EEE_1000_SUPPORTED) |
| 6710 | lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE; |
| 6711 | |
| 6712 | retval = e1e_wphy_locked(hw, I82579_LPI_CTRL, |
| 6713 | lpi_ctrl); |
| 6714 | } |
| 6715 | } |
| 6716 | hw->phy.ops.release(hw); |
| 6717 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6718 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6719 | /* 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] | 6720 | * would have already happened in close and is redundant. |
| 6721 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6722 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6723 | |
Dean Nelson | 24b41c9 | 2013-06-13 03:55:44 +0000 | [diff] [blame] | 6724 | pci_clear_master(pdev); |
| 6725 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6726 | /* The pci-e switch on some quad port adapters will report a |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6727 | * correctable error when the MAC transitions from D0 to D3. To |
| 6728 | * prevent this we need to mask off the correctable errors on the |
| 6729 | * downstream port of the pci-e switch. |
Li Zhang | e8c254c | 2013-08-13 18:42:58 +0000 | [diff] [blame] | 6730 | * |
| 6731 | * We don't have the associated upstream bridge while assigning |
| 6732 | * the PCI device into guest. For example, the KVM on power is |
| 6733 | * one of the cases. |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6734 | */ |
| 6735 | if (adapter->flags & FLAG_IS_QUAD_PORT) { |
| 6736 | struct pci_dev *us_dev = pdev->bus->self; |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6737 | u16 devctl; |
| 6738 | |
Li Zhang | e8c254c | 2013-08-13 18:42:58 +0000 | [diff] [blame] | 6739 | if (!us_dev) |
| 6740 | return 0; |
| 6741 | |
Jiang Liu | f8c0fca | 2012-08-20 13:30:43 -0600 | [diff] [blame] | 6742 | pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl); |
| 6743 | pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, |
| 6744 | (devctl & ~PCI_EXP_DEVCTL_CERE)); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6745 | |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 6746 | pci_save_state(pdev); |
| 6747 | pci_prepare_to_sleep(pdev); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6748 | |
Jiang Liu | f8c0fca | 2012-08-20 13:30:43 -0600 | [diff] [blame] | 6749 | pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6750 | } |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 6751 | |
| 6752 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6753 | } |
| 6754 | |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6755 | /** |
Yanir Lubetkin | beb0a15 | 2015-06-10 01:15:05 +0300 | [diff] [blame] | 6756 | * __e1000e_disable_aspm - Disable ASPM states |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6757 | * @pdev: pointer to PCI device struct |
| 6758 | * @state: bit-mask of ASPM states to disable |
Yanir Lubetkin | beb0a15 | 2015-06-10 01:15:05 +0300 | [diff] [blame] | 6759 | * @locked: indication if this context holds pci_bus_sem locked. |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6760 | * |
| 6761 | * Some devices *must* have certain ASPM states disabled per hardware errata. |
| 6762 | **/ |
Yanir Lubetkin | beb0a15 | 2015-06-10 01:15:05 +0300 | [diff] [blame] | 6763 | static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state, int locked) |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6764 | { |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6765 | struct pci_dev *parent = pdev->bus->self; |
| 6766 | u16 aspm_dis_mask = 0; |
| 6767 | u16 pdev_aspmc, parent_aspmc; |
Bjorn Helgaas | ffe0b2ff | 2012-12-06 06:40:07 +0000 | [diff] [blame] | 6768 | |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6769 | switch (state) { |
| 6770 | case PCIE_LINK_STATE_L0S: |
| 6771 | case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1: |
| 6772 | aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S; |
| 6773 | /* fall-through - can't have L1 without L0s */ |
| 6774 | case PCIE_LINK_STATE_L1: |
| 6775 | aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1; |
| 6776 | break; |
| 6777 | default: |
| 6778 | return; |
| 6779 | } |
| 6780 | |
| 6781 | pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc); |
| 6782 | pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC; |
| 6783 | |
| 6784 | if (parent) { |
| 6785 | pcie_capability_read_word(parent, PCI_EXP_LNKCTL, |
| 6786 | &parent_aspmc); |
| 6787 | parent_aspmc &= PCI_EXP_LNKCTL_ASPMC; |
| 6788 | } |
| 6789 | |
| 6790 | /* Nothing to do if the ASPM states to be disabled already are */ |
| 6791 | if (!(pdev_aspmc & aspm_dis_mask) && |
| 6792 | (!parent || !(parent_aspmc & aspm_dis_mask))) |
| 6793 | return; |
| 6794 | |
| 6795 | dev_info(&pdev->dev, "Disabling ASPM %s %s\n", |
| 6796 | (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ? |
| 6797 | "L0s" : "", |
| 6798 | (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ? |
| 6799 | "L1" : ""); |
| 6800 | |
| 6801 | #ifdef CONFIG_PCIEASPM |
Yanir Lubetkin | beb0a15 | 2015-06-10 01:15:05 +0300 | [diff] [blame] | 6802 | if (locked) |
| 6803 | pci_disable_link_state_locked(pdev, state); |
| 6804 | else |
| 6805 | pci_disable_link_state(pdev, state); |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6806 | |
| 6807 | /* Double-check ASPM control. If not disabled by the above, the |
| 6808 | * BIOS is preventing that from happening (or CONFIG_PCIEASPM is |
| 6809 | * not enabled); override by writing PCI config space directly. |
| 6810 | */ |
| 6811 | pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc); |
| 6812 | pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC; |
| 6813 | |
| 6814 | if (!(aspm_dis_mask & pdev_aspmc)) |
| 6815 | return; |
| 6816 | #endif |
Bjorn Helgaas | ffe0b2ff | 2012-12-06 06:40:07 +0000 | [diff] [blame] | 6817 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6818 | /* Both device and parent should have the same ASPM setting. |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6819 | * Disable ASPM in downstream component first and then upstream. |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 6820 | */ |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6821 | pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6822 | |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6823 | if (parent) |
| 6824 | pcie_capability_clear_word(parent, PCI_EXP_LNKCTL, |
| 6825 | aspm_dis_mask); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 6826 | } |
| 6827 | |
Yanir Lubetkin | beb0a15 | 2015-06-10 01:15:05 +0300 | [diff] [blame] | 6828 | /** |
| 6829 | * e1000e_disable_aspm - Disable ASPM states. |
| 6830 | * @pdev: pointer to PCI device struct |
| 6831 | * @state: bit-mask of ASPM states to disable |
| 6832 | * |
| 6833 | * This function acquires the pci_bus_sem! |
| 6834 | * Some devices *must* have certain ASPM states disabled per hardware errata. |
| 6835 | **/ |
| 6836 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
| 6837 | { |
| 6838 | __e1000e_disable_aspm(pdev, state, 0); |
| 6839 | } |
| 6840 | |
| 6841 | /** |
| 6842 | * e1000e_disable_aspm_locked Disable ASPM states. |
| 6843 | * @pdev: pointer to PCI device struct |
| 6844 | * @state: bit-mask of ASPM states to disable |
| 6845 | * |
| 6846 | * This function must be called with pci_bus_sem acquired! |
| 6847 | * Some devices *must* have certain ASPM states disabled per hardware errata. |
| 6848 | **/ |
| 6849 | static void e1000e_disable_aspm_locked(struct pci_dev *pdev, u16 state) |
| 6850 | { |
| 6851 | __e1000e_disable_aspm(pdev, state, 1); |
| 6852 | } |
| 6853 | |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 6854 | static int e1000e_pm_thaw(struct device *dev) |
| 6855 | { |
| 6856 | struct net_device *netdev = dev_get_drvdata(dev); |
| 6857 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6858 | int rc = 0; |
| 6859 | |
| 6860 | e1000e_set_interrupt_capability(adapter); |
| 6861 | |
| 6862 | rtnl_lock(); |
| 6863 | if (netif_running(netdev)) { |
| 6864 | rc = e1000_request_irq(adapter); |
| 6865 | if (rc) |
| 6866 | goto err_irq; |
| 6867 | |
| 6868 | e1000e_up(adapter); |
| 6869 | } |
| 6870 | |
| 6871 | netif_device_attach(netdev); |
| 6872 | err_irq: |
| 6873 | rtnl_unlock(); |
| 6874 | |
| 6875 | return rc; |
| 6876 | } |
| 6877 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 6878 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6879 | static int __e1000_resume(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6880 | { |
| 6881 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6882 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6883 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6884 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6885 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6886 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 6887 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
| 6888 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
| 6889 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 6890 | if (aspm_disable_flag) |
Raanan Avargil | 2758f9e | 2015-07-06 17:57:36 +0300 | [diff] [blame] | 6891 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6892 | |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 6893 | pci_set_master(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6894 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 6895 | if (hw->mac.type >= e1000_pch2lan) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 6896 | e1000_resume_workarounds_pchlan(&adapter->hw); |
| 6897 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6898 | e1000e_power_up_phy(adapter); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6899 | |
| 6900 | /* report the system wakeup cause from S3/S4 */ |
| 6901 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
| 6902 | u16 phy_data; |
| 6903 | |
| 6904 | e1e_rphy(&adapter->hw, BM_WUS, &phy_data); |
| 6905 | if (phy_data) { |
| 6906 | e_info("PHY Wakeup cause - %s\n", |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 6907 | phy_data & E1000_WUS_EX ? "Unicast Packet" : |
| 6908 | phy_data & E1000_WUS_MC ? "Multicast Packet" : |
| 6909 | phy_data & E1000_WUS_BC ? "Broadcast Packet" : |
| 6910 | phy_data & E1000_WUS_MAG ? "Magic Packet" : |
| 6911 | phy_data & E1000_WUS_LNKC ? |
| 6912 | "Link Status Change" : "other"); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6913 | } |
| 6914 | e1e_wphy(&adapter->hw, BM_WUS, ~0); |
| 6915 | } else { |
| 6916 | u32 wus = er32(WUS); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 6917 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6918 | if (wus) { |
| 6919 | e_info("MAC Wakeup cause - %s\n", |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 6920 | wus & E1000_WUS_EX ? "Unicast Packet" : |
| 6921 | wus & E1000_WUS_MC ? "Multicast Packet" : |
| 6922 | wus & E1000_WUS_BC ? "Broadcast Packet" : |
| 6923 | wus & E1000_WUS_MAG ? "Magic Packet" : |
| 6924 | wus & E1000_WUS_LNKC ? "Link Status Change" : |
| 6925 | "other"); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6926 | } |
| 6927 | ew32(WUS, ~0); |
| 6928 | } |
| 6929 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6930 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6931 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 6932 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6933 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6934 | /* 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] | 6935 | * 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] | 6936 | * under the control of the driver. |
| 6937 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6938 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6939 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6940 | |
| 6941 | return 0; |
| 6942 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6943 | |
Hiroaki SHIMODA | 3e7986f | 2014-04-15 08:20:19 +0000 | [diff] [blame] | 6944 | #ifdef CONFIG_PM_SLEEP |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6945 | static int e1000e_pm_suspend(struct device *dev) |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6946 | { |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6947 | struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev)); |
| 6948 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6949 | struct pci_dev *pdev = to_pci_dev(dev); |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6950 | struct e1000_hw *hw = &adapter->hw; |
Chris Wilson | 833521e | 2017-05-31 18:50:43 +0300 | [diff] [blame] | 6951 | int rc; |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6952 | |
David Ertman | 2a7e19a | 2014-07-11 06:21:31 +0000 | [diff] [blame] | 6953 | e1000e_flush_lpic(pdev); |
| 6954 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6955 | e1000e_pm_freeze(dev); |
| 6956 | |
Chris Wilson | 833521e | 2017-05-31 18:50:43 +0300 | [diff] [blame] | 6957 | rc = __e1000_shutdown(pdev, false); |
| 6958 | if (rc) |
| 6959 | e1000e_pm_thaw(dev); |
| 6960 | |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6961 | /* Introduce S0ix implementation */ |
Vitaly Lifshits | e086ba2 | 2020-05-07 20:14:06 +0300 | [diff] [blame] | 6962 | if (hw->mac.type >= e1000_pch_cnp && |
| 6963 | !e1000e_check_me(hw->adapter->pdev->device)) |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6964 | e1000e_s0ix_entry_flow(adapter); |
| 6965 | |
Chris Wilson | 833521e | 2017-05-31 18:50:43 +0300 | [diff] [blame] | 6966 | return rc; |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6967 | } |
| 6968 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6969 | static int e1000e_pm_resume(struct device *dev) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6970 | { |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6971 | struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev)); |
| 6972 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6973 | struct pci_dev *pdev = to_pci_dev(dev); |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6974 | struct e1000_hw *hw = &adapter->hw; |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6975 | int rc; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6976 | |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6977 | /* Introduce S0ix implementation */ |
Vitaly Lifshits | e086ba2 | 2020-05-07 20:14:06 +0300 | [diff] [blame] | 6978 | if (hw->mac.type >= e1000_pch_cnp && |
| 6979 | !e1000e_check_me(hw->adapter->pdev->device)) |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6980 | e1000e_s0ix_exit_flow(adapter); |
| 6981 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6982 | rc = __e1000_resume(pdev); |
| 6983 | if (rc) |
| 6984 | return rc; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6985 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6986 | return e1000e_pm_thaw(dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6987 | } |
Mika Westerberg | 38a529b | 2014-01-16 14:39:39 +0200 | [diff] [blame] | 6988 | #endif /* CONFIG_PM_SLEEP */ |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6989 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 6990 | static int e1000e_pm_runtime_idle(struct device *dev) |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6991 | { |
Chuhong Yuan | ee2e80c | 2019-07-23 22:15:13 +0800 | [diff] [blame] | 6992 | struct net_device *netdev = dev_get_drvdata(dev); |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6993 | struct e1000_adapter *adapter = netdev_priv(netdev); |
David Ertman | 2116bc25 | 2014-07-11 06:21:23 +0000 | [diff] [blame] | 6994 | u16 eee_lp; |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6995 | |
David Ertman | 2116bc25 | 2014-07-11 06:21:23 +0000 | [diff] [blame] | 6996 | eee_lp = adapter->hw.dev_spec.ich8lan.eee_lp_ability; |
| 6997 | |
| 6998 | if (!e1000e_has_link(adapter)) { |
| 6999 | adapter->hw.dev_spec.ich8lan.eee_lp_ability = eee_lp; |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7000 | pm_schedule_suspend(dev, 5 * MSEC_PER_SEC); |
David Ertman | 2116bc25 | 2014-07-11 06:21:23 +0000 | [diff] [blame] | 7001 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 7002 | |
| 7003 | return -EBUSY; |
| 7004 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7005 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7006 | static int e1000e_pm_runtime_resume(struct device *dev) |
| 7007 | { |
| 7008 | struct pci_dev *pdev = to_pci_dev(dev); |
| 7009 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7010 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7011 | int rc; |
| 7012 | |
| 7013 | rc = __e1000_resume(pdev); |
| 7014 | if (rc) |
| 7015 | return rc; |
| 7016 | |
| 7017 | if (netdev->flags & IFF_UP) |
Alexander Duyck | 386164d | 2015-10-27 16:59:31 -0700 | [diff] [blame] | 7018 | e1000e_up(adapter); |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7019 | |
| 7020 | return rc; |
| 7021 | } |
| 7022 | |
| 7023 | static int e1000e_pm_runtime_suspend(struct device *dev) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7024 | { |
| 7025 | struct pci_dev *pdev = to_pci_dev(dev); |
| 7026 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7027 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7028 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7029 | if (netdev->flags & IFF_UP) { |
| 7030 | int count = E1000_CHECK_RESET_COUNT; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7031 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7032 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 7033 | usleep_range(10000, 11000); |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7034 | |
| 7035 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 7036 | |
| 7037 | /* Down the device without resetting the hardware */ |
| 7038 | e1000e_down(adapter, false); |
| 7039 | } |
| 7040 | |
| 7041 | if (__e1000_shutdown(pdev, true)) { |
| 7042 | e1000e_pm_runtime_resume(dev); |
| 7043 | return -EBUSY; |
| 7044 | } |
| 7045 | |
| 7046 | return 0; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7047 | } |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 7048 | #endif /* CONFIG_PM */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7049 | |
| 7050 | static void e1000_shutdown(struct pci_dev *pdev) |
| 7051 | { |
David Ertman | 2a7e19a | 2014-07-11 06:21:31 +0000 | [diff] [blame] | 7052 | e1000e_flush_lpic(pdev); |
| 7053 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 7054 | e1000e_pm_freeze(&pdev->dev); |
| 7055 | |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 7056 | __e1000_shutdown(pdev, false); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7057 | } |
| 7058 | |
| 7059 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7060 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 7061 | static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data) |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7062 | { |
| 7063 | struct net_device *netdev = data; |
| 7064 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7065 | |
| 7066 | if (adapter->msix_entries) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 7067 | int vector, msix_irq; |
| 7068 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7069 | vector = 0; |
| 7070 | msix_irq = adapter->msix_entries[vector].vector; |
Konstantin Khlebnikov | fd8e597 | 2017-05-19 10:18:49 +0300 | [diff] [blame] | 7071 | if (disable_hardirq(msix_irq)) |
| 7072 | e1000_intr_msix_rx(msix_irq, netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7073 | enable_irq(msix_irq); |
| 7074 | |
| 7075 | vector++; |
| 7076 | msix_irq = adapter->msix_entries[vector].vector; |
Konstantin Khlebnikov | fd8e597 | 2017-05-19 10:18:49 +0300 | [diff] [blame] | 7077 | if (disable_hardirq(msix_irq)) |
| 7078 | e1000_intr_msix_tx(msix_irq, netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7079 | enable_irq(msix_irq); |
| 7080 | |
| 7081 | vector++; |
| 7082 | msix_irq = adapter->msix_entries[vector].vector; |
Konstantin Khlebnikov | fd8e597 | 2017-05-19 10:18:49 +0300 | [diff] [blame] | 7083 | if (disable_hardirq(msix_irq)) |
| 7084 | e1000_msix_other(msix_irq, netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7085 | enable_irq(msix_irq); |
| 7086 | } |
| 7087 | |
| 7088 | return IRQ_HANDLED; |
| 7089 | } |
| 7090 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7091 | /** |
| 7092 | * e1000_netpoll |
| 7093 | * @netdev: network interface device structure |
| 7094 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7095 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 7096 | * without having to re-enable interrupts. It's not called while |
| 7097 | * the interrupt routine is executing. |
| 7098 | */ |
| 7099 | static void e1000_netpoll(struct net_device *netdev) |
| 7100 | { |
| 7101 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7102 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7103 | switch (adapter->int_mode) { |
| 7104 | case E1000E_INT_MODE_MSIX: |
| 7105 | e1000_intr_msix(adapter->pdev->irq, netdev); |
| 7106 | break; |
| 7107 | case E1000E_INT_MODE_MSI: |
WANG Cong | 3111912 | 2016-12-10 14:22:42 -0800 | [diff] [blame] | 7108 | if (disable_hardirq(adapter->pdev->irq)) |
| 7109 | e1000_intr_msi(adapter->pdev->irq, netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7110 | enable_irq(adapter->pdev->irq); |
| 7111 | break; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 7112 | default: /* E1000E_INT_MODE_LEGACY */ |
WANG Cong | 3111912 | 2016-12-10 14:22:42 -0800 | [diff] [blame] | 7113 | if (disable_hardirq(adapter->pdev->irq)) |
| 7114 | e1000_intr(adapter->pdev->irq, netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7115 | enable_irq(adapter->pdev->irq); |
| 7116 | break; |
| 7117 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7118 | } |
| 7119 | #endif |
| 7120 | |
| 7121 | /** |
| 7122 | * e1000_io_error_detected - called when PCI error is detected |
| 7123 | * @pdev: Pointer to PCI device |
| 7124 | * @state: The current pci connection state |
| 7125 | * |
| 7126 | * This function is called after a PCI bus error affecting |
| 7127 | * this device has been detected. |
| 7128 | */ |
| 7129 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 7130 | pci_channel_state_t state) |
| 7131 | { |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 7132 | e1000e_pm_freeze(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7133 | |
Mike Mason | c93b5a7 | 2009-06-30 12:45:53 +0000 | [diff] [blame] | 7134 | if (state == pci_channel_io_perm_failure) |
| 7135 | return PCI_ERS_RESULT_DISCONNECT; |
| 7136 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7137 | pci_disable_device(pdev); |
| 7138 | |
| 7139 | /* Request a slot slot reset. */ |
| 7140 | return PCI_ERS_RESULT_NEED_RESET; |
| 7141 | } |
| 7142 | |
| 7143 | /** |
| 7144 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 7145 | * @pdev: Pointer to PCI device |
| 7146 | * |
| 7147 | * Restart the card from scratch, as if from a cold-boot. Implementation |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 7148 | * resembles the first-half of the e1000e_pm_resume routine. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7149 | */ |
| 7150 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 7151 | { |
| 7152 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7153 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7154 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7155 | u16 aspm_disable_flag = 0; |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 7156 | int err; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7157 | pci_ers_result_t result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7158 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7159 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 7160 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 7161 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7162 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 7163 | if (aspm_disable_flag) |
Raanan Avargil | 2758f9e | 2015-07-06 17:57:36 +0300 | [diff] [blame] | 7164 | e1000e_disable_aspm_locked(pdev, aspm_disable_flag); |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7165 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 7166 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 7167 | if (err) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7168 | dev_err(&pdev->dev, |
| 7169 | "Cannot re-enable PCI device after reset.\n"); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7170 | result = PCI_ERS_RESULT_DISCONNECT; |
| 7171 | } else { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7172 | pdev->state_saved = true; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7173 | pci_restore_state(pdev); |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 7174 | pci_set_master(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7175 | |
| 7176 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 7177 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 7178 | |
| 7179 | e1000e_reset(adapter); |
| 7180 | ew32(WUS, ~0); |
| 7181 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7182 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7183 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7184 | return result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7185 | } |
| 7186 | |
| 7187 | /** |
| 7188 | * e1000_io_resume - called when traffic can start flowing again. |
| 7189 | * @pdev: Pointer to PCI device |
| 7190 | * |
| 7191 | * This callback is called when the error recovery driver tells us that |
| 7192 | * its OK to resume normal operation. Implementation resembles the |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 7193 | * second-half of the e1000e_pm_resume routine. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7194 | */ |
| 7195 | static void e1000_io_resume(struct pci_dev *pdev) |
| 7196 | { |
| 7197 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7198 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7199 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 7200 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7201 | |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 7202 | e1000e_pm_thaw(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7203 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7204 | /* 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] | 7205 | * 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] | 7206 | * under the control of the driver. |
| 7207 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7208 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 7209 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7210 | } |
| 7211 | |
| 7212 | static void e1000_print_device_info(struct e1000_adapter *adapter) |
| 7213 | { |
| 7214 | struct e1000_hw *hw = &adapter->hw; |
| 7215 | struct net_device *netdev = adapter->netdev; |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 7216 | u32 ret_val; |
| 7217 | u8 pba_str[E1000_PBANUM_LENGTH]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7218 | |
| 7219 | /* print bus type/speed/width info */ |
Bruce Allan | a5cc764 | 2011-03-19 00:31:23 +0000 | [diff] [blame] | 7220 | e_info("(PCI Express:2.5GT/s:%s) %pM\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 7221 | /* bus width */ |
| 7222 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 7223 | "Width x1"), |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 7224 | /* MAC address */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 7225 | netdev->dev_addr); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 7226 | e_info("Intel(R) PRO/%s Network Connection\n", |
| 7227 | (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 7228 | ret_val = e1000_read_pba_string_generic(hw, pba_str, |
| 7229 | E1000_PBANUM_LENGTH); |
| 7230 | if (ret_val) |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 7231 | strlcpy((char *)pba_str, "Unknown", sizeof(pba_str)); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 7232 | e_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 7233 | hw->mac.type, hw->phy.type, pba_str); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7234 | } |
| 7235 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 7236 | static void e1000_eeprom_checks(struct e1000_adapter *adapter) |
| 7237 | { |
| 7238 | struct e1000_hw *hw = &adapter->hw; |
| 7239 | int ret_val; |
| 7240 | u16 buf = 0; |
| 7241 | |
| 7242 | if (hw->mac.type != e1000_82573) |
| 7243 | return; |
| 7244 | |
| 7245 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 7246 | le16_to_cpus(&buf); |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 7247 | if (!ret_val && (!(buf & BIT(0)))) { |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 7248 | /* Deep Smart Power Down (DSPD) */ |
Frans Pop | 6c2a9ef | 2008-09-22 14:52:22 -0700 | [diff] [blame] | 7249 | dev_warn(&adapter->pdev->dev, |
| 7250 | "Warning: detected DSPD enabled in EEPROM\n"); |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 7251 | } |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 7252 | } |
| 7253 | |
Alexander Duyck | 55e7fe5 | 2015-05-02 01:09:59 -0700 | [diff] [blame] | 7254 | static netdev_features_t e1000_fix_features(struct net_device *netdev, |
| 7255 | netdev_features_t features) |
| 7256 | { |
| 7257 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7258 | struct e1000_hw *hw = &adapter->hw; |
| 7259 | |
| 7260 | /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */ |
| 7261 | if ((hw->mac.type >= e1000_pch2lan) && (netdev->mtu > ETH_DATA_LEN)) |
| 7262 | features &= ~NETIF_F_RXFCS; |
| 7263 | |
Jarod Wilson | 8380864 | 2016-06-09 19:50:13 -0400 | [diff] [blame] | 7264 | /* Since there is no support for separate Rx/Tx vlan accel |
| 7265 | * enable/disable make sure Tx flag is always in same state as Rx. |
| 7266 | */ |
| 7267 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 7268 | features |= NETIF_F_HW_VLAN_CTAG_TX; |
| 7269 | else |
| 7270 | features &= ~NETIF_F_HW_VLAN_CTAG_TX; |
| 7271 | |
Alexander Duyck | 55e7fe5 | 2015-05-02 01:09:59 -0700 | [diff] [blame] | 7272 | return features; |
| 7273 | } |
| 7274 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7275 | static int e1000_set_features(struct net_device *netdev, |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 7276 | netdev_features_t features) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7277 | { |
| 7278 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7279 | netdev_features_t changed = features ^ netdev->features; |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7280 | |
| 7281 | if (changed & (NETIF_F_TSO | NETIF_F_TSO6)) |
| 7282 | adapter->flags |= FLAG_TSO_FORCE; |
| 7283 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7284 | if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 7285 | NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS | |
| 7286 | NETIF_F_RXALL))) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7287 | return 0; |
| 7288 | |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 7289 | if (changed & NETIF_F_RXFCS) { |
| 7290 | if (features & NETIF_F_RXFCS) { |
| 7291 | adapter->flags2 &= ~FLAG2_CRC_STRIPPING; |
| 7292 | } else { |
| 7293 | /* We need to take it back to defaults, which might mean |
| 7294 | * stripping is still disabled at the adapter level. |
| 7295 | */ |
| 7296 | if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING) |
| 7297 | adapter->flags2 |= FLAG2_CRC_STRIPPING; |
| 7298 | else |
| 7299 | adapter->flags2 &= ~FLAG2_CRC_STRIPPING; |
| 7300 | } |
| 7301 | } |
| 7302 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 7303 | netdev->features = features; |
| 7304 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7305 | if (netif_running(netdev)) |
| 7306 | e1000e_reinit_locked(adapter); |
| 7307 | else |
| 7308 | e1000e_reset(adapter); |
| 7309 | |
Serhey Popovych | b0ddfe2 | 2018-03-29 17:51:36 +0300 | [diff] [blame] | 7310 | return 1; |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7311 | } |
| 7312 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 7313 | static const struct net_device_ops e1000e_netdev_ops = { |
Stefan Assmann | d5ea45d | 2016-02-03 09:20:52 +0100 | [diff] [blame] | 7314 | .ndo_open = e1000e_open, |
| 7315 | .ndo_stop = e1000e_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 7316 | .ndo_start_xmit = e1000_xmit_frame, |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 7317 | .ndo_get_stats64 = e1000e_get_stats64, |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 7318 | .ndo_set_rx_mode = e1000e_set_rx_mode, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 7319 | .ndo_set_mac_address = e1000_set_mac, |
| 7320 | .ndo_change_mtu = e1000_change_mtu, |
| 7321 | .ndo_do_ioctl = e1000_ioctl, |
| 7322 | .ndo_tx_timeout = e1000_tx_timeout, |
| 7323 | .ndo_validate_addr = eth_validate_addr, |
| 7324 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 7325 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 7326 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 7327 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7328 | .ndo_poll_controller = e1000_netpoll, |
| 7329 | #endif |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7330 | .ndo_set_features = e1000_set_features, |
Alexander Duyck | 55e7fe5 | 2015-05-02 01:09:59 -0700 | [diff] [blame] | 7331 | .ndo_fix_features = e1000_fix_features, |
Toshiaki Makita | f2701b1 | 2015-08-06 17:57:29 +0900 | [diff] [blame] | 7332 | .ndo_features_check = passthru_features_check, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 7333 | }; |
| 7334 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7335 | /** |
| 7336 | * e1000_probe - Device Initialization Routine |
| 7337 | * @pdev: PCI device information struct |
| 7338 | * @ent: entry in e1000_pci_tbl |
| 7339 | * |
| 7340 | * Returns 0 on success, negative on failure |
| 7341 | * |
| 7342 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 7343 | * The OS initialization, configuring of the adapter private structure, |
| 7344 | * and a hardware reset occur. |
| 7345 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 7346 | 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] | 7347 | { |
| 7348 | struct net_device *netdev; |
| 7349 | struct e1000_adapter *adapter; |
| 7350 | struct e1000_hw *hw; |
| 7351 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; |
Becky Bruce | f47e81f | 2008-05-01 18:03:11 -0500 | [diff] [blame] | 7352 | resource_size_t mmio_start, mmio_len; |
| 7353 | resource_size_t flash_start, flash_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7354 | static int cards_found; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7355 | u16 aspm_disable_flag = 0; |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 7356 | int bars, i, err, pci_using_dac; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7357 | u16 eeprom_data = 0; |
| 7358 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 7359 | s32 ret_val = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7360 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7361 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 7362 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 7363 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7364 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 7365 | if (aspm_disable_flag) |
| 7366 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 7367 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 7368 | err = pci_enable_device_mem(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7369 | if (err) |
| 7370 | return err; |
| 7371 | |
| 7372 | pci_using_dac = 0; |
Russell King | 718a39e | 2013-06-10 12:22:30 +0100 | [diff] [blame] | 7373 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7374 | if (!err) { |
Russell King | 718a39e | 2013-06-10 12:22:30 +0100 | [diff] [blame] | 7375 | pci_using_dac = 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7376 | } else { |
Russell King | 718a39e | 2013-06-10 12:22:30 +0100 | [diff] [blame] | 7377 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7378 | if (err) { |
Russell King | 718a39e | 2013-06-10 12:22:30 +0100 | [diff] [blame] | 7379 | dev_err(&pdev->dev, |
| 7380 | "No usable DMA configuration, aborting\n"); |
| 7381 | goto err_dma; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7382 | } |
| 7383 | } |
| 7384 | |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 7385 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 7386 | err = pci_request_selected_regions_exclusive(pdev, bars, |
| 7387 | e1000e_driver_name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7388 | if (err) |
| 7389 | goto err_pci_reg; |
| 7390 | |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 7391 | /* AER (Advanced Error Reporting) hooks */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7392 | pci_enable_pcie_error_reporting(pdev); |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 7393 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7394 | pci_set_master(pdev); |
Bruce Allan | 438b365 | 2008-11-21 16:51:33 -0800 | [diff] [blame] | 7395 | /* PCI config space info */ |
| 7396 | err = pci_save_state(pdev); |
| 7397 | if (err) |
| 7398 | goto err_alloc_etherdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7399 | |
| 7400 | err = -ENOMEM; |
| 7401 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
| 7402 | if (!netdev) |
| 7403 | goto err_alloc_etherdev; |
| 7404 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7405 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7406 | |
Tom Herbert | f85e4df | 2010-05-05 14:03:32 +0000 | [diff] [blame] | 7407 | netdev->irq = pdev->irq; |
| 7408 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7409 | pci_set_drvdata(pdev, netdev); |
| 7410 | adapter = netdev_priv(netdev); |
| 7411 | hw = &adapter->hw; |
| 7412 | adapter->netdev = netdev; |
| 7413 | adapter->pdev = pdev; |
| 7414 | adapter->ei = ei; |
| 7415 | adapter->pba = ei->pba; |
| 7416 | adapter->flags = ei->flags; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 7417 | adapter->flags2 = ei->flags2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7418 | adapter->hw.adapter = adapter; |
| 7419 | adapter->hw.mac.type = ei->mac; |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 7420 | adapter->max_hw_frame_size = ei->max_hw_frame_size; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 7421 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7422 | |
| 7423 | mmio_start = pci_resource_start(pdev, 0); |
| 7424 | mmio_len = pci_resource_len(pdev, 0); |
| 7425 | |
| 7426 | err = -EIO; |
| 7427 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 7428 | if (!adapter->hw.hw_addr) |
| 7429 | goto err_ioremap; |
| 7430 | |
| 7431 | if ((adapter->flags & FLAG_HAS_FLASH) && |
Yanir Lubetkin | 1103a63 | 2015-02-28 10:10:06 +0000 | [diff] [blame] | 7432 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM) && |
| 7433 | (hw->mac.type < e1000_pch_spt)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7434 | flash_start = pci_resource_start(pdev, 1); |
| 7435 | flash_len = pci_resource_len(pdev, 1); |
| 7436 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
| 7437 | if (!adapter->hw.flash_address) |
| 7438 | goto err_flashmap; |
| 7439 | } |
| 7440 | |
Bruce Allan | d495bcb | 2013-03-20 07:23:11 +0000 | [diff] [blame] | 7441 | /* Set default EEE advertisement */ |
| 7442 | if (adapter->flags2 & FLAG2_HAS_EEE) |
| 7443 | adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T; |
| 7444 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7445 | /* construct the net_device struct */ |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 7446 | netdev->netdev_ops = &e1000e_netdev_ops; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7447 | e1000e_set_ethtool_ops(netdev); |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 7448 | netdev->watchdog_timeo = 5 * HZ; |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 7449 | netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64); |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 7450 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7451 | |
| 7452 | netdev->mem_start = mmio_start; |
| 7453 | netdev->mem_end = mmio_start + mmio_len; |
| 7454 | |
| 7455 | adapter->bd_number = cards_found++; |
| 7456 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 7457 | e1000e_check_options(adapter); |
| 7458 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7459 | /* setup adapter struct */ |
| 7460 | err = e1000_sw_init(adapter); |
| 7461 | if (err) |
| 7462 | goto err_sw_init; |
| 7463 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7464 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 7465 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 7466 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 7467 | |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 7468 | err = ei->get_variants(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7469 | if (err) |
| 7470 | goto err_hw_init; |
| 7471 | |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 7472 | if ((adapter->flags & FLAG_IS_ICH) && |
Yanir Lubetkin | 152c0a9 | 2015-03-20 17:41:53 -0700 | [diff] [blame] | 7473 | (adapter->flags & FLAG_READ_ONLY_NVM) && |
| 7474 | (hw->mac.type < e1000_pch_spt)) |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 7475 | e1000e_write_protect_nvm_ich8lan(&adapter->hw); |
| 7476 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7477 | hw->mac.ops.get_bus_info(&adapter->hw); |
| 7478 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 7479 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7480 | |
| 7481 | /* Copper options */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 7482 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7483 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
| 7484 | adapter->hw.phy.disable_polarity_correction = 0; |
| 7485 | adapter->hw.phy.ms_type = e1000_ms_hw_default; |
| 7486 | } |
| 7487 | |
Bruce Allan | 470a542 | 2012-05-26 06:08:48 +0000 | [diff] [blame] | 7488 | 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] | 7489 | dev_info(&pdev->dev, |
| 7490 | "PHY reset is blocked due to SOL/IDER session.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7491 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7492 | /* Set initial default active device features */ |
| 7493 | netdev->features = (NETIF_F_SG | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7494 | NETIF_F_HW_VLAN_CTAG_RX | |
| 7495 | NETIF_F_HW_VLAN_CTAG_TX | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7496 | NETIF_F_TSO | |
| 7497 | NETIF_F_TSO6 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 7498 | NETIF_F_RXHASH | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7499 | NETIF_F_RXCSUM | |
| 7500 | NETIF_F_HW_CSUM); |
| 7501 | |
| 7502 | /* Set user-changeable features (subset of all device features) */ |
| 7503 | netdev->hw_features = netdev->features; |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 7504 | netdev->hw_features |= NETIF_F_RXFCS; |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 7505 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 7506 | netdev->hw_features |= NETIF_F_RXALL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7507 | |
| 7508 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7509 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7510 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7511 | netdev->vlan_features |= (NETIF_F_SG | |
| 7512 | NETIF_F_TSO | |
| 7513 | NETIF_F_TSO6 | |
| 7514 | NETIF_F_HW_CSUM); |
Jeff Kirsher | a5136e2 | 2008-06-05 04:07:28 -0700 | [diff] [blame] | 7515 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 7516 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 7517 | |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7518 | if (pci_using_dac) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7519 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7520 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 7521 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7522 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 7523 | /* MTU range: 68 - max_hw_frame_size */ |
| 7524 | netdev->min_mtu = ETH_MIN_MTU; |
| 7525 | netdev->max_mtu = adapter->max_hw_frame_size - |
| 7526 | (VLAN_ETH_HLEN + ETH_FCS_LEN); |
| 7527 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7528 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
| 7529 | adapter->flags |= FLAG_MNG_PT_ENABLED; |
| 7530 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7531 | /* before reading the NVM, reset the controller to |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7532 | * put the device in a known good starting state |
| 7533 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7534 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 7535 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7536 | /* 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] | 7537 | * attempt. Let's give it a few tries |
| 7538 | */ |
| 7539 | for (i = 0;; i++) { |
| 7540 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) |
| 7541 | break; |
| 7542 | if (i == 2) { |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 7543 | dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7544 | err = -EIO; |
| 7545 | goto err_eeprom; |
| 7546 | } |
| 7547 | } |
| 7548 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 7549 | e1000_eeprom_checks(adapter); |
| 7550 | |
Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 7551 | /* copy the MAC address */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7552 | if (e1000e_read_mac_addr(&adapter->hw)) |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 7553 | dev_err(&pdev->dev, |
| 7554 | "NVM Read Error while reading MAC address\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7555 | |
| 7556 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7557 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 7558 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 7559 | dev_err(&pdev->dev, "Invalid MAC Address: %pM\n", |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 7560 | netdev->dev_addr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7561 | err = -EIO; |
| 7562 | goto err_eeprom; |
| 7563 | } |
| 7564 | |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 7565 | timer_setup(&adapter->watchdog_timer, e1000_watchdog, 0); |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 7566 | timer_setup(&adapter->phy_info_timer, e1000_update_phy_info, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7567 | |
| 7568 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 7569 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 7570 | INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); |
| 7571 | INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 7572 | INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7573 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7574 | /* Initialize link parameters. User can change them with ethtool */ |
| 7575 | adapter->hw.mac.autoneg = 1; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 7576 | adapter->fc_autoneg = true; |
Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 7577 | adapter->hw.fc.requested_mode = e1000_fc_default; |
| 7578 | adapter->hw.fc.current_mode = e1000_fc_default; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7579 | adapter->hw.phy.autoneg_advertised = 0x2f; |
| 7580 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7581 | /* Initial Wake on LAN setting - If APM wake is enabled in |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7582 | * the EEPROM, enable the ACPI Magic Packet filter |
| 7583 | */ |
| 7584 | if (adapter->flags & FLAG_APME_IN_WUC) { |
| 7585 | /* APME bit in EEPROM is mapped to WUC.APME */ |
| 7586 | eeprom_data = er32(WUC); |
| 7587 | eeprom_apme_mask = E1000_WUC_APME; |
Bruce Allan | 4def99b | 2011-02-02 09:30:36 +0000 | [diff] [blame] | 7588 | if ((hw->mac.type > e1000_ich10lan) && |
| 7589 | (eeprom_data & E1000_WUC_PHY_WAKE)) |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 7590 | adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7591 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
| 7592 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && |
| 7593 | (adapter->hw.bus.func == 1)) |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 7594 | ret_val = e1000_read_nvm(&adapter->hw, |
David Ertman | 491a04d | 2014-07-09 16:07:42 +0000 | [diff] [blame] | 7595 | NVM_INIT_CONTROL3_PORT_B, |
| 7596 | 1, &eeprom_data); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7597 | else |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 7598 | ret_val = e1000_read_nvm(&adapter->hw, |
David Ertman | 491a04d | 2014-07-09 16:07:42 +0000 | [diff] [blame] | 7599 | NVM_INIT_CONTROL3_PORT_A, |
| 7600 | 1, &eeprom_data); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7601 | } |
| 7602 | |
| 7603 | /* fetch WoL from EEPROM */ |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 7604 | if (ret_val) |
| 7605 | e_dbg("NVM read error getting WoL initial values: %d\n", ret_val); |
David Ertman | 491a04d | 2014-07-09 16:07:42 +0000 | [diff] [blame] | 7606 | else if (eeprom_data & eeprom_apme_mask) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7607 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 7608 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7609 | /* now that we have the eeprom settings, apply the special cases |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7610 | * where the eeprom may be wrong or the board simply won't support |
| 7611 | * wake on lan on a particular port |
| 7612 | */ |
| 7613 | if (!(adapter->flags & FLAG_HAS_WOL)) |
| 7614 | adapter->eeprom_wol = 0; |
| 7615 | |
| 7616 | /* initialize the wol settings based on the eeprom settings */ |
| 7617 | adapter->wol = adapter->eeprom_wol; |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 7618 | |
| 7619 | /* make sure adapter isn't asleep if manageability is enabled */ |
| 7620 | if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) || |
| 7621 | (hw->mac.ops.check_mng_mode(hw))) |
| 7622 | device_wakeup_enable(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7623 | |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 7624 | /* save off EEPROM version number */ |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 7625 | ret_val = e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); |
David Ertman | 491a04d | 2014-07-09 16:07:42 +0000 | [diff] [blame] | 7626 | |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 7627 | if (ret_val) { |
| 7628 | e_dbg("NVM read error getting EEPROM version: %d\n", ret_val); |
David Ertman | 491a04d | 2014-07-09 16:07:42 +0000 | [diff] [blame] | 7629 | adapter->eeprom_vers = 0; |
| 7630 | } |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 7631 | |
Jacob Keller | aa524b6 | 2016-04-20 11:36:42 -0700 | [diff] [blame] | 7632 | /* init PTP hardware clock */ |
| 7633 | e1000e_ptp_init(adapter); |
| 7634 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7635 | /* reset the hardware with the new settings */ |
| 7636 | e1000e_reset(adapter); |
| 7637 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7638 | /* 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] | 7639 | * 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] | 7640 | * under the control of the driver. |
| 7641 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7642 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 7643 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7644 | |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 7645 | strlcpy(netdev->name, "eth%d", sizeof(netdev->name)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7646 | err = register_netdev(netdev); |
| 7647 | if (err) |
| 7648 | goto err_register; |
| 7649 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 7650 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 7651 | netif_carrier_off(netdev); |
| 7652 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7653 | e1000_print_device_info(adapter); |
| 7654 | |
Rafael J. Wysocki | e075155 | 2020-04-18 18:53:01 +0200 | [diff] [blame] | 7655 | dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NO_DIRECT_COMPLETE); |
Kai-Heng Feng | 59f5870 | 2018-12-11 15:59:37 +0800 | [diff] [blame] | 7656 | |
Kai-Heng Feng | 459d69c | 2019-02-03 01:40:16 +0800 | [diff] [blame] | 7657 | if (pci_dev_run_wake(pdev) && hw->mac.type < e1000_pch_cnp) |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 7658 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7659 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7660 | return 0; |
| 7661 | |
| 7662 | err_register: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7663 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 7664 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7665 | err_eeprom: |
Bruce Allan | 470a542 | 2012-05-26 06:08:48 +0000 | [diff] [blame] | 7666 | 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] | 7667 | e1000_phy_hw_reset(&adapter->hw); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7668 | err_hw_init: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7669 | kfree(adapter->tx_ring); |
| 7670 | kfree(adapter->rx_ring); |
| 7671 | err_sw_init: |
Yanir Lubetkin | 1103a63 | 2015-02-28 10:10:06 +0000 | [diff] [blame] | 7672 | if ((adapter->hw.flash_address) && (hw->mac.type < e1000_pch_spt)) |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7673 | iounmap(adapter->hw.flash_address); |
Jeff Kirsher | e82f54b | 2008-11-14 06:45:07 +0000 | [diff] [blame] | 7674 | e1000e_reset_interrupt_capability(adapter); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7675 | err_flashmap: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7676 | iounmap(adapter->hw.hw_addr); |
| 7677 | err_ioremap: |
| 7678 | free_netdev(netdev); |
| 7679 | err_alloc_etherdev: |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 7680 | pci_release_mem_regions(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7681 | err_pci_reg: |
| 7682 | err_dma: |
| 7683 | pci_disable_device(pdev); |
| 7684 | return err; |
| 7685 | } |
| 7686 | |
| 7687 | /** |
| 7688 | * e1000_remove - Device Removal Routine |
| 7689 | * @pdev: PCI device information struct |
| 7690 | * |
| 7691 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 7692 | * that it should release a PCI device. The could be caused by a |
| 7693 | * Hot-Plug event, or because the driver is going to be removed from |
| 7694 | * memory. |
| 7695 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 7696 | static void e1000_remove(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7697 | { |
| 7698 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7699 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7700 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 7701 | e1000e_ptp_remove(adapter); |
| 7702 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7703 | /* The timers may be rescheduled, so explicitly disable them |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 7704 | * from being rescheduled. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7705 | */ |
Alexander Duyck | daee559 | 2019-10-11 08:34:59 -0700 | [diff] [blame] | 7706 | set_bit(__E1000_DOWN, &adapter->state); |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 7707 | del_timer_sync(&adapter->watchdog_timer); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7708 | del_timer_sync(&adapter->phy_info_timer); |
| 7709 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 7710 | cancel_work_sync(&adapter->reset_task); |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 7711 | cancel_work_sync(&adapter->watchdog_task); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 7712 | cancel_work_sync(&adapter->downshift_task); |
| 7713 | cancel_work_sync(&adapter->update_phy_task); |
| 7714 | cancel_work_sync(&adapter->print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7715 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 7716 | if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) { |
| 7717 | cancel_work_sync(&adapter->tx_hwtstamp_work); |
| 7718 | if (adapter->tx_hwtstamp_skb) { |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 7719 | dev_consume_skb_any(adapter->tx_hwtstamp_skb); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 7720 | adapter->tx_hwtstamp_skb = NULL; |
| 7721 | } |
| 7722 | } |
| 7723 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 7724 | unregister_netdev(netdev); |
| 7725 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 7726 | if (pci_dev_run_wake(pdev)) |
| 7727 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7728 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7729 | /* 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] | 7730 | * would have already happened in close and is redundant. |
| 7731 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 7732 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7733 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 7734 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7735 | kfree(adapter->tx_ring); |
| 7736 | kfree(adapter->rx_ring); |
| 7737 | |
| 7738 | iounmap(adapter->hw.hw_addr); |
Yanir Lubetkin | 1103a63 | 2015-02-28 10:10:06 +0000 | [diff] [blame] | 7739 | if ((adapter->hw.flash_address) && |
| 7740 | (adapter->hw.mac.type < e1000_pch_spt)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7741 | iounmap(adapter->hw.flash_address); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 7742 | pci_release_mem_regions(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7743 | |
| 7744 | free_netdev(netdev); |
| 7745 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7746 | /* AER disable */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7747 | pci_disable_pcie_error_reporting(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7748 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7749 | pci_disable_device(pdev); |
| 7750 | } |
| 7751 | |
| 7752 | /* PCI Error Recovery (ERS) */ |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 7753 | static const struct pci_error_handlers e1000_err_handler = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7754 | .error_detected = e1000_io_error_detected, |
| 7755 | .slot_reset = e1000_io_slot_reset, |
| 7756 | .resume = e1000_io_resume, |
| 7757 | }; |
| 7758 | |
David Ertman | 0e8e842 | 2014-04-08 22:10:31 +0000 | [diff] [blame] | 7759 | static const struct pci_device_id e1000_pci_tbl[] = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7760 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
| 7761 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, |
| 7762 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, |
Bruce Allan | c29c3ba | 2013-02-20 04:05:50 +0000 | [diff] [blame] | 7763 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), |
| 7764 | board_82571 }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7765 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
| 7766 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, |
Auke Kok | 040babf | 2007-10-31 15:22:05 -0700 | [diff] [blame] | 7767 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
| 7768 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, |
| 7769 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7770 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7771 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
| 7772 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, |
| 7773 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, |
| 7774 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7775 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7776 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
| 7777 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, |
| 7778 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7779 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 7780 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, |
Bruce Allan | bef28b1 | 2009-03-24 23:28:02 -0700 | [diff] [blame] | 7781 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 7782 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 7783 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7784 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
| 7785 | board_80003es2lan }, |
| 7786 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), |
| 7787 | board_80003es2lan }, |
| 7788 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), |
| 7789 | board_80003es2lan }, |
| 7790 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), |
| 7791 | board_80003es2lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7792 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7793 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
| 7794 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, |
| 7795 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, |
| 7796 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, |
| 7797 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, |
| 7798 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, |
| 7799 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, |
Bruce Allan | 9e135a2 | 2009-12-01 15:50:31 +0000 | [diff] [blame] | 7800 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7801 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7802 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
| 7803 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, |
| 7804 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, |
| 7805 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, |
| 7806 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, |
Bruce Allan | 2f15f9d | 2008-08-26 18:36:36 -0700 | [diff] [blame] | 7807 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 7808 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, |
| 7809 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, |
| 7810 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, |
| 7811 | |
| 7812 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, |
| 7813 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, |
| 7814 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7815 | |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 7816 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, |
| 7817 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, |
Bruce Allan | 10df0b9 | 2010-05-10 15:02:52 +0000 | [diff] [blame] | 7818 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan }, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 7819 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 7820 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, |
| 7821 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, |
| 7822 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, |
| 7823 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, |
| 7824 | |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 7825 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan }, |
| 7826 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan }, |
| 7827 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 7828 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt }, |
| 7829 | { 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] | 7830 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt }, |
| 7831 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt }, |
Bruce Allan | 91a3d82 | 2013-06-29 01:15:16 +0000 | [diff] [blame] | 7832 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt }, |
| 7833 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt }, |
| 7834 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt }, |
| 7835 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt }, |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 7836 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM), board_pch_spt }, |
| 7837 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V), board_pch_spt }, |
| 7838 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM2), board_pch_spt }, |
| 7839 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V2), board_pch_spt }, |
Raanan Avargil | f3ed935 | 2015-10-20 17:13:01 +0300 | [diff] [blame] | 7840 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LBG_I219_LM3), board_pch_spt }, |
Raanan Avargil | 9cd34b3 | 2015-12-22 15:35:05 +0200 | [diff] [blame] | 7841 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM4), board_pch_spt }, |
| 7842 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V4), board_pch_spt }, |
| 7843 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM5), board_pch_spt }, |
| 7844 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V5), board_pch_spt }, |
Sasha Neftin | 3a3173b | 2017-04-06 10:26:32 +0300 | [diff] [blame] | 7845 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM6), board_pch_cnp }, |
| 7846 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V6), board_pch_cnp }, |
| 7847 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM7), board_pch_cnp }, |
| 7848 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V7), board_pch_cnp }, |
Sasha Neftin | 48f76b68 | 2017-07-17 15:13:39 -0700 | [diff] [blame] | 7849 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM8), board_pch_cnp }, |
| 7850 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V8), board_pch_cnp }, |
| 7851 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM9), board_pch_cnp }, |
| 7852 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V9), board_pch_cnp }, |
Sasha Neftin | 914ee9c | 2019-10-10 13:15:39 +0300 | [diff] [blame] | 7853 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM10), board_pch_cnp }, |
| 7854 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V10), board_pch_cnp }, |
| 7855 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM11), board_pch_cnp }, |
| 7856 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V11), board_pch_cnp }, |
| 7857 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM12), board_pch_spt }, |
| 7858 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V12), board_pch_spt }, |
Sasha Neftin | fb776f5 | 2019-10-16 11:08:38 +0300 | [diff] [blame] | 7859 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM13), board_pch_cnp }, |
| 7860 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V13), board_pch_cnp }, |
| 7861 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM14), board_pch_cnp }, |
| 7862 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V14), board_pch_cnp }, |
| 7863 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM15), board_pch_cnp }, |
Vitaly Lifshits | 5632122 | 2020-01-21 15:46:28 -0800 | [diff] [blame] | 7864 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V15), board_pch_cnp }, |
Sasha Neftin | 59e4668 | 2020-01-19 13:57:13 +0200 | [diff] [blame] | 7865 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM16), board_pch_cnp }, |
| 7866 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V16), board_pch_cnp }, |
| 7867 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM17), board_pch_cnp }, |
| 7868 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V17), board_pch_cnp }, |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 7869 | |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 7870 | { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7871 | }; |
| 7872 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 7873 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7874 | static const struct dev_pm_ops e1000_pm_ops = { |
Kevin Hao | 72f72dc | 2014-03-18 00:26:49 -0700 | [diff] [blame] | 7875 | #ifdef CONFIG_PM_SLEEP |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 7876 | .suspend = e1000e_pm_suspend, |
| 7877 | .resume = e1000e_pm_resume, |
| 7878 | .freeze = e1000e_pm_freeze, |
| 7879 | .thaw = e1000e_pm_thaw, |
| 7880 | .poweroff = e1000e_pm_suspend, |
| 7881 | .restore = e1000e_pm_resume, |
Kevin Hao | 72f72dc | 2014-03-18 00:26:49 -0700 | [diff] [blame] | 7882 | #endif |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7883 | SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume, |
| 7884 | e1000e_pm_runtime_idle) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7885 | }; |
| 7886 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7887 | /* PCI Device API Driver */ |
| 7888 | static struct pci_driver e1000_driver = { |
| 7889 | .name = e1000e_driver_name, |
| 7890 | .id_table = e1000_pci_tbl, |
| 7891 | .probe = e1000_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 7892 | .remove = e1000_remove, |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 7893 | .driver = { |
| 7894 | .pm = &e1000_pm_ops, |
| 7895 | }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7896 | .shutdown = e1000_shutdown, |
| 7897 | .err_handler = &e1000_err_handler |
| 7898 | }; |
| 7899 | |
| 7900 | /** |
| 7901 | * e1000_init_module - Driver Registration Routine |
| 7902 | * |
| 7903 | * e1000_init_module is the first routine called when the driver is |
| 7904 | * loaded. All it does is register with the PCI subsystem. |
| 7905 | **/ |
| 7906 | static int __init e1000_init_module(void) |
| 7907 | { |
Bruce Allan | 8544b9f | 2010-03-24 12:55:30 +0000 | [diff] [blame] | 7908 | pr_info("Intel(R) PRO/1000 Network Driver - %s\n", |
| 7909 | e1000e_driver_version); |
Yanir Lubetkin | 529498c | 2015-06-02 17:05:50 +0300 | [diff] [blame] | 7910 | pr_info("Copyright(c) 1999 - 2015 Intel Corporation.\n"); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 7911 | |
Jean Sacren | 5a5e889 | 2015-09-19 05:08:42 -0600 | [diff] [blame] | 7912 | return pci_register_driver(&e1000_driver); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7913 | } |
| 7914 | module_init(e1000_init_module); |
| 7915 | |
| 7916 | /** |
| 7917 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 7918 | * |
| 7919 | * e1000_exit_module is called just before the driver is removed |
| 7920 | * from memory. |
| 7921 | **/ |
| 7922 | static void __exit e1000_exit_module(void) |
| 7923 | { |
| 7924 | pci_unregister_driver(&e1000_driver); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7925 | } |
| 7926 | module_exit(e1000_exit_module); |
| 7927 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7928 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 7929 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
Jesse Brandeburg | 98674eb | 2018-09-14 17:37:57 -0700 | [diff] [blame] | 7930 | MODULE_LICENSE("GPL v2"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7931 | MODULE_VERSION(DRV_VERSION); |
| 7932 | |
Bruce Allan | 06c24b9 | 2012-02-23 03:13:13 +0000 | [diff] [blame] | 7933 | /* netdev.c */ |