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> |
Chen Yu | ccf8b94 | 2020-12-01 09:21:50 +0800 | [diff] [blame] | 28 | #include <linux/suspend.h> |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 29 | |
| 30 | #include "e1000.h" |
| 31 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 32 | char e1000e_driver_name[] = "e1000e"; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 33 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 34 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 35 | static int debug = -1; |
| 36 | module_param(debug, int, 0); |
| 37 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 38 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 39 | static const struct e1000_info *e1000_info_tbl[] = { |
| 40 | [board_82571] = &e1000_82571_info, |
| 41 | [board_82572] = &e1000_82572_info, |
| 42 | [board_82573] = &e1000_82573_info, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 43 | [board_82574] = &e1000_82574_info, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 44 | [board_82583] = &e1000_82583_info, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 45 | [board_80003es2lan] = &e1000_es2_info, |
| 46 | [board_ich8lan] = &e1000_ich8_info, |
| 47 | [board_ich9lan] = &e1000_ich9_info, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 48 | [board_ich10lan] = &e1000_ich10_info, |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 49 | [board_pchlan] = &e1000_pch_info, |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 50 | [board_pch2lan] = &e1000_pch2_info, |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 51 | [board_pch_lpt] = &e1000_pch_lpt_info, |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 52 | [board_pch_spt] = &e1000_pch_spt_info, |
Sasha Neftin | 3a3173b | 2017-04-06 10:26:32 +0300 | [diff] [blame] | 53 | [board_pch_cnp] = &e1000_pch_cnp_info, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 56 | struct e1000_reg_info { |
| 57 | u32 ofs; |
| 58 | char *name; |
| 59 | }; |
| 60 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 61 | static const struct e1000_reg_info e1000_reg_info_tbl[] = { |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 62 | /* General Registers */ |
| 63 | {E1000_CTRL, "CTRL"}, |
| 64 | {E1000_STATUS, "STATUS"}, |
| 65 | {E1000_CTRL_EXT, "CTRL_EXT"}, |
| 66 | |
| 67 | /* Interrupt Registers */ |
| 68 | {E1000_ICR, "ICR"}, |
| 69 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 70 | /* Rx Registers */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 71 | {E1000_RCTL, "RCTL"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 72 | {E1000_RDLEN(0), "RDLEN"}, |
| 73 | {E1000_RDH(0), "RDH"}, |
| 74 | {E1000_RDT(0), "RDT"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 75 | {E1000_RDTR, "RDTR"}, |
| 76 | {E1000_RXDCTL(0), "RXDCTL"}, |
| 77 | {E1000_ERT, "ERT"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 78 | {E1000_RDBAL(0), "RDBAL"}, |
| 79 | {E1000_RDBAH(0), "RDBAH"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 80 | {E1000_RDFH, "RDFH"}, |
| 81 | {E1000_RDFT, "RDFT"}, |
| 82 | {E1000_RDFHS, "RDFHS"}, |
| 83 | {E1000_RDFTS, "RDFTS"}, |
| 84 | {E1000_RDFPC, "RDFPC"}, |
| 85 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 86 | /* Tx Registers */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 87 | {E1000_TCTL, "TCTL"}, |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 88 | {E1000_TDBAL(0), "TDBAL"}, |
| 89 | {E1000_TDBAH(0), "TDBAH"}, |
| 90 | {E1000_TDLEN(0), "TDLEN"}, |
| 91 | {E1000_TDH(0), "TDH"}, |
| 92 | {E1000_TDT(0), "TDT"}, |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 93 | {E1000_TIDV, "TIDV"}, |
| 94 | {E1000_TXDCTL(0), "TXDCTL"}, |
| 95 | {E1000_TADV, "TADV"}, |
| 96 | {E1000_TARC(0), "TARC"}, |
| 97 | {E1000_TDFH, "TDFH"}, |
| 98 | {E1000_TDFT, "TDFT"}, |
| 99 | {E1000_TDFHS, "TDFHS"}, |
| 100 | {E1000_TDFTS, "TDFTS"}, |
| 101 | {E1000_TDFPC, "TDFPC"}, |
| 102 | |
| 103 | /* List Terminator */ |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 104 | {0, NULL} |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 107 | /** |
Andi Kleen | c6f3148 | 2014-05-20 08:22:45 +0000 | [diff] [blame] | 108 | * __ew32_prepare - prepare to write to MAC CSR register on certain parts |
| 109 | * @hw: pointer to the HW structure |
| 110 | * |
| 111 | * When updating the MAC CSR registers, the Manageability Engine (ME) could |
| 112 | * be accessing the registers at the same time. Normally, this is handled in |
| 113 | * h/w by an arbiter but on some parts there is a bug that acknowledges Host |
| 114 | * accesses later than it should which could result in the register to have |
| 115 | * an incorrect value. Workaround this by checking the FWSM register which |
| 116 | * has bit 24 set while ME is accessing MAC CSR registers, wait if it is set |
| 117 | * and try again a number of times. |
| 118 | **/ |
Punit Agrawal | d601afc | 2020-05-15 13:31:27 +0900 | [diff] [blame] | 119 | static void __ew32_prepare(struct e1000_hw *hw) |
Andi Kleen | c6f3148 | 2014-05-20 08:22:45 +0000 | [diff] [blame] | 120 | { |
| 121 | s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT; |
| 122 | |
| 123 | while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i) |
| 124 | udelay(50); |
Andi Kleen | c6f3148 | 2014-05-20 08:22:45 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val) |
| 128 | { |
| 129 | if (hw->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 130 | __ew32_prepare(hw); |
| 131 | |
| 132 | writel(val, hw->hw_addr + reg); |
| 133 | } |
| 134 | |
| 135 | /** |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 136 | * e1000_regdump - register printout routine |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 137 | * @hw: pointer to the HW structure |
| 138 | * @reginfo: pointer to the register info table |
| 139 | **/ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 140 | static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo) |
| 141 | { |
| 142 | int n = 0; |
| 143 | char rname[16]; |
| 144 | u32 regs[8]; |
| 145 | |
| 146 | switch (reginfo->ofs) { |
| 147 | case E1000_RXDCTL(0): |
| 148 | for (n = 0; n < 2; n++) |
| 149 | regs[n] = __er32(hw, E1000_RXDCTL(n)); |
| 150 | break; |
| 151 | case E1000_TXDCTL(0): |
| 152 | for (n = 0; n < 2; n++) |
| 153 | regs[n] = __er32(hw, E1000_TXDCTL(n)); |
| 154 | break; |
| 155 | case E1000_TARC(0): |
| 156 | for (n = 0; n < 2; n++) |
| 157 | regs[n] = __er32(hw, E1000_TARC(n)); |
| 158 | break; |
| 159 | default: |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 160 | pr_info("%-15s %08x\n", |
| 161 | reginfo->name, __er32(hw, reginfo->ofs)); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 162 | return; |
| 163 | } |
| 164 | |
| 165 | snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 166 | pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 169 | static void e1000e_dump_ps_pages(struct e1000_adapter *adapter, |
| 170 | struct e1000_buffer *bi) |
| 171 | { |
| 172 | int i; |
| 173 | struct e1000_ps_page *ps_page; |
| 174 | |
| 175 | for (i = 0; i < adapter->rx_ps_pages; i++) { |
| 176 | ps_page = &bi->ps_pages[i]; |
| 177 | |
| 178 | if (ps_page->page) { |
| 179 | pr_info("packet dump for ps_page %d:\n", i); |
| 180 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, |
| 181 | 16, 1, page_address(ps_page->page), |
| 182 | PAGE_SIZE, true); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 187 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 188 | * e1000e_dump - Print registers, Tx-ring and Rx-ring |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 189 | * @adapter: board private structure |
| 190 | **/ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 191 | static void e1000e_dump(struct e1000_adapter *adapter) |
| 192 | { |
| 193 | struct net_device *netdev = adapter->netdev; |
| 194 | struct e1000_hw *hw = &adapter->hw; |
| 195 | struct e1000_reg_info *reginfo; |
| 196 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 197 | struct e1000_tx_desc *tx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 198 | struct my_u0 { |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 199 | __le64 a; |
| 200 | __le64 b; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 201 | } *u0; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 202 | struct e1000_buffer *buffer_info; |
| 203 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 204 | union e1000_rx_desc_packet_split *rx_desc_ps; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 205 | union e1000_rx_desc_extended *rx_desc; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 206 | struct my_u1 { |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 207 | __le64 a; |
| 208 | __le64 b; |
| 209 | __le64 c; |
| 210 | __le64 d; |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 211 | } *u1; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 212 | u32 staterr; |
| 213 | int i = 0; |
| 214 | |
| 215 | if (!netif_msg_hw(adapter)) |
| 216 | return; |
| 217 | |
| 218 | /* Print netdevice Info */ |
| 219 | if (netdev) { |
| 220 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Tobias Klauser | 4a7c972 | 2017-01-18 17:45:01 +0100 | [diff] [blame] | 221 | pr_info("Device Name state trans_start\n"); |
| 222 | pr_info("%-15s %016lX %016lX\n", netdev->name, |
| 223 | netdev->state, dev_trans_start(netdev)); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /* Print Registers */ |
| 227 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 228 | pr_info(" Register Name Value\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 229 | for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl; |
| 230 | reginfo->name; reginfo++) { |
| 231 | e1000_regdump(hw, reginfo); |
| 232 | } |
| 233 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 234 | /* Print Tx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 235 | if (!netdev || !netif_running(netdev)) |
Bruce Allan | fe1e980 | 2012-01-31 06:37:54 +0000 | [diff] [blame] | 236 | return; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 237 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 238 | dev_info(&adapter->pdev->dev, "Tx Ring Summary\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 239 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 240 | buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean]; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 241 | pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n", |
| 242 | 0, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 243 | (unsigned long long)buffer_info->dma, |
| 244 | buffer_info->length, |
| 245 | buffer_info->next_to_watch, |
| 246 | (unsigned long long)buffer_info->time_stamp); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 247 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 248 | /* Print Tx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 249 | if (!netif_msg_tx_done(adapter)) |
| 250 | goto rx_ring_summary; |
| 251 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 252 | dev_info(&adapter->pdev->dev, "Tx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 253 | |
| 254 | /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended) |
| 255 | * |
| 256 | * Legacy Transmit Descriptor |
| 257 | * +--------------------------------------------------------------+ |
| 258 | * 0 | Buffer Address [63:0] (Reserved on Write Back) | |
| 259 | * +--------------------------------------------------------------+ |
| 260 | * 8 | Special | CSS | Status | CMD | CSO | Length | |
| 261 | * +--------------------------------------------------------------+ |
| 262 | * 63 48 47 36 35 32 31 24 23 16 15 0 |
| 263 | * |
| 264 | * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload |
| 265 | * 63 48 47 40 39 32 31 16 15 8 7 0 |
| 266 | * +----------------------------------------------------------------+ |
| 267 | * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS | |
| 268 | * +----------------------------------------------------------------+ |
| 269 | * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN | |
| 270 | * +----------------------------------------------------------------+ |
| 271 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 272 | * |
| 273 | * Extended Data Descriptor (DTYP=0x1) |
| 274 | * +----------------------------------------------------------------+ |
| 275 | * 0 | Buffer Address [63:0] | |
| 276 | * +----------------------------------------------------------------+ |
| 277 | * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN | |
| 278 | * +----------------------------------------------------------------+ |
| 279 | * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 |
| 280 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 281 | pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n"); |
| 282 | pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n"); |
| 283 | 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] | 284 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 285 | const char *next_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 286 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 287 | buffer_info = &tx_ring->buffer_info[i]; |
| 288 | u0 = (struct my_u0 *)tx_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 289 | 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] | 290 | next_desc = " NTC/U"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 291 | else if (i == tx_ring->next_to_use) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 292 | next_desc = " NTU"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 293 | else if (i == tx_ring->next_to_clean) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 294 | next_desc = " NTC"; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 295 | else |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 296 | next_desc = ""; |
| 297 | 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] | 298 | (!(le64_to_cpu(u0->b) & BIT(29)) ? 'l' : |
| 299 | ((le64_to_cpu(u0->b) & BIT(20)) ? 'd' : 'c')), |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 300 | i, |
| 301 | (unsigned long long)le64_to_cpu(u0->a), |
| 302 | (unsigned long long)le64_to_cpu(u0->b), |
| 303 | (unsigned long long)buffer_info->dma, |
| 304 | buffer_info->length, buffer_info->next_to_watch, |
| 305 | (unsigned long long)buffer_info->time_stamp, |
| 306 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 307 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 308 | if (netif_msg_pktdata(adapter) && buffer_info->skb) |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 309 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 310 | 16, 1, buffer_info->skb->data, |
| 311 | buffer_info->skb->len, true); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 314 | /* Print Rx Ring Summary */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 315 | rx_ring_summary: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 316 | dev_info(&adapter->pdev->dev, "Rx Ring Summary\n"); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 317 | pr_info("Queue [NTU] [NTC]\n"); |
| 318 | pr_info(" %5d %5X %5X\n", |
| 319 | 0, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 320 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 321 | /* Print Rx Ring */ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 322 | if (!netif_msg_rx_status(adapter)) |
Bruce Allan | fe1e980 | 2012-01-31 06:37:54 +0000 | [diff] [blame] | 323 | return; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 324 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 325 | dev_info(&adapter->pdev->dev, "Rx Ring Dump\n"); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 326 | switch (adapter->rx_ps_pages) { |
| 327 | case 1: |
| 328 | case 2: |
| 329 | case 3: |
| 330 | /* [Extended] Packet Split Receive Descriptor Format |
| 331 | * |
| 332 | * +-----------------------------------------------------+ |
| 333 | * 0 | Buffer Address 0 [63:0] | |
| 334 | * +-----------------------------------------------------+ |
| 335 | * 8 | Buffer Address 1 [63:0] | |
| 336 | * +-----------------------------------------------------+ |
| 337 | * 16 | Buffer Address 2 [63:0] | |
| 338 | * +-----------------------------------------------------+ |
| 339 | * 24 | Buffer Address 3 [63:0] | |
| 340 | * +-----------------------------------------------------+ |
| 341 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 342 | 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] | 343 | /* [Extended] Receive Descriptor (Write-Back) Format |
| 344 | * |
| 345 | * 63 48 47 32 31 13 12 8 7 4 3 0 |
| 346 | * +------------------------------------------------------+ |
| 347 | * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS | |
| 348 | * | Checksum | Ident | | Queue | | Type | |
| 349 | * +------------------------------------------------------+ |
| 350 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 351 | * +------------------------------------------------------+ |
| 352 | * 63 48 47 32 31 20 19 0 |
| 353 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 354 | 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] | 355 | for (i = 0; i < rx_ring->count; i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 356 | const char *next_desc; |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 357 | buffer_info = &rx_ring->buffer_info[i]; |
| 358 | rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i); |
| 359 | u1 = (struct my_u1 *)rx_desc_ps; |
| 360 | staterr = |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 361 | le32_to_cpu(rx_desc_ps->wb.middle.status_error); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 362 | |
| 363 | if (i == rx_ring->next_to_use) |
| 364 | next_desc = " NTU"; |
| 365 | else if (i == rx_ring->next_to_clean) |
| 366 | next_desc = " NTC"; |
| 367 | else |
| 368 | next_desc = ""; |
| 369 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 370 | if (staterr & E1000_RXD_STAT_DD) { |
| 371 | /* Descriptor Done */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 372 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n", |
| 373 | "RWB", i, |
| 374 | (unsigned long long)le64_to_cpu(u1->a), |
| 375 | (unsigned long long)le64_to_cpu(u1->b), |
| 376 | (unsigned long long)le64_to_cpu(u1->c), |
| 377 | (unsigned long long)le64_to_cpu(u1->d), |
| 378 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 379 | } else { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 380 | pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n", |
| 381 | "R ", i, |
| 382 | (unsigned long long)le64_to_cpu(u1->a), |
| 383 | (unsigned long long)le64_to_cpu(u1->b), |
| 384 | (unsigned long long)le64_to_cpu(u1->c), |
| 385 | (unsigned long long)le64_to_cpu(u1->d), |
| 386 | (unsigned long long)buffer_info->dma, |
| 387 | buffer_info->skb, next_desc); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 388 | |
| 389 | if (netif_msg_pktdata(adapter)) |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 390 | e1000e_dump_ps_pages(adapter, |
| 391 | buffer_info); |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 392 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 393 | } |
| 394 | break; |
| 395 | default: |
| 396 | case 0: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 397 | /* Extended Receive Descriptor (Read) Format |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 398 | * |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 399 | * +-----------------------------------------------------+ |
| 400 | * 0 | Buffer Address [63:0] | |
| 401 | * +-----------------------------------------------------+ |
| 402 | * 8 | Reserved | |
| 403 | * +-----------------------------------------------------+ |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 404 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 405 | 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] | 406 | /* Extended Receive Descriptor (Write-Back) Format |
| 407 | * |
| 408 | * 63 48 47 32 31 24 23 4 3 0 |
| 409 | * +------------------------------------------------------+ |
| 410 | * | RSS Hash | | | | |
| 411 | * 0 +-------------------+ Rsvd | Reserved | MRQ RSS | |
| 412 | * | Packet | IP | | | Type | |
| 413 | * | Checksum | Ident | | | | |
| 414 | * +------------------------------------------------------+ |
| 415 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 416 | * +------------------------------------------------------+ |
| 417 | * 63 48 47 32 31 20 19 0 |
| 418 | */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 419 | 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] | 420 | |
| 421 | for (i = 0; i < rx_ring->count; i++) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 422 | const char *next_desc; |
| 423 | |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 424 | buffer_info = &rx_ring->buffer_info[i]; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 425 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 426 | u1 = (struct my_u1 *)rx_desc; |
| 427 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 428 | |
| 429 | if (i == rx_ring->next_to_use) |
| 430 | next_desc = " NTU"; |
| 431 | else if (i == rx_ring->next_to_clean) |
| 432 | next_desc = " NTC"; |
| 433 | else |
| 434 | next_desc = ""; |
| 435 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 436 | if (staterr & E1000_RXD_STAT_DD) { |
| 437 | /* Descriptor Done */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 438 | pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n", |
| 439 | "RWB", i, |
| 440 | (unsigned long long)le64_to_cpu(u1->a), |
| 441 | (unsigned long long)le64_to_cpu(u1->b), |
| 442 | buffer_info->skb, next_desc); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 443 | } else { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 444 | pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n", |
| 445 | "R ", i, |
| 446 | (unsigned long long)le64_to_cpu(u1->a), |
| 447 | (unsigned long long)le64_to_cpu(u1->b), |
| 448 | (unsigned long long)buffer_info->dma, |
| 449 | buffer_info->skb, next_desc); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 450 | |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 451 | if (netif_msg_pktdata(adapter) && |
| 452 | buffer_info->skb) |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 453 | print_hex_dump(KERN_INFO, "", |
| 454 | DUMP_PREFIX_ADDRESS, 16, |
| 455 | 1, |
Emil Tantilov | f0c5dad | 2012-08-01 08:12:21 +0000 | [diff] [blame] | 456 | buffer_info->skb->data, |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 457 | adapter->rx_buffer_len, |
| 458 | true); |
| 459 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 460 | } |
| 461 | } |
Taku Izumi | 84f4ee9 | 2010-04-27 14:39:08 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 464 | /** |
| 465 | * e1000_desc_unused - calculate if we have unused descriptors |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 466 | * @ring: pointer to ring struct to perform calculation on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 467 | **/ |
| 468 | static int e1000_desc_unused(struct e1000_ring *ring) |
| 469 | { |
| 470 | if (ring->next_to_clean > ring->next_to_use) |
| 471 | return ring->next_to_clean - ring->next_to_use - 1; |
| 472 | |
| 473 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; |
| 474 | } |
| 475 | |
| 476 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 477 | * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp |
| 478 | * @adapter: board private structure |
| 479 | * @hwtstamps: time stamp structure to update |
| 480 | * @systim: unsigned 64bit system time value. |
| 481 | * |
| 482 | * Convert the system time value stored in the RX/TXSTMP registers into a |
| 483 | * hwtstamp which can be used by the upper level time stamping functions. |
| 484 | * |
| 485 | * The 'systim_lock' spinlock is used to protect the consistency of the |
| 486 | * system time value. This is needed because reading the 64 bit time |
| 487 | * value involves reading two 32 bit registers. The first read latches the |
| 488 | * value. |
| 489 | **/ |
| 490 | static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter, |
| 491 | struct skb_shared_hwtstamps *hwtstamps, |
| 492 | u64 systim) |
| 493 | { |
| 494 | u64 ns; |
| 495 | unsigned long flags; |
| 496 | |
| 497 | spin_lock_irqsave(&adapter->systim_lock, flags); |
| 498 | ns = timecounter_cyc2time(&adapter->tc, systim); |
| 499 | spin_unlock_irqrestore(&adapter->systim_lock, flags); |
| 500 | |
| 501 | memset(hwtstamps, 0, sizeof(*hwtstamps)); |
| 502 | hwtstamps->hwtstamp = ns_to_ktime(ns); |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp |
| 507 | * @adapter: board private structure |
| 508 | * @status: descriptor extended error and status field |
| 509 | * @skb: particular skb to include time stamp |
| 510 | * |
| 511 | * If the time stamp is valid, convert it into the timecounter ns value |
| 512 | * and store that result into the shhwtstamps structure which is passed |
| 513 | * up the network stack. |
| 514 | **/ |
| 515 | static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status, |
| 516 | struct sk_buff *skb) |
| 517 | { |
| 518 | struct e1000_hw *hw = &adapter->hw; |
| 519 | u64 rxstmp; |
| 520 | |
| 521 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) || |
| 522 | !(status & E1000_RXDEXT_STATERR_TST) || |
| 523 | !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) |
| 524 | return; |
| 525 | |
| 526 | /* The Rx time stamp registers contain the time stamp. No other |
| 527 | * received packet will be time stamped until the Rx time stamp |
| 528 | * registers are read. Because only one packet can be time stamped |
| 529 | * at a time, the register values must belong to this packet and |
| 530 | * therefore none of the other additional attributes need to be |
| 531 | * compared. |
| 532 | */ |
| 533 | rxstmp = (u64)er32(RXSTMPL); |
| 534 | rxstmp |= (u64)er32(RXSTMPH) << 32; |
| 535 | e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp); |
| 536 | |
| 537 | adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP; |
| 538 | } |
| 539 | |
| 540 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 541 | * e1000_receive_skb - helper function to handle Rx indications |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 542 | * @adapter: board private structure |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 543 | * @netdev: pointer to netdev struct |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 544 | * @staterr: descriptor extended error and status field as written by hardware |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 545 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
| 546 | * @skb: pointer to sk_buff to be indicated to stack |
| 547 | **/ |
| 548 | static void e1000_receive_skb(struct e1000_adapter *adapter, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 549 | struct net_device *netdev, struct sk_buff *skb, |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 550 | u32 staterr, __le16 vlan) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 551 | { |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 552 | u16 tag = le16_to_cpu(vlan); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 553 | |
| 554 | e1000e_rx_hwtstamp(adapter, staterr, skb); |
| 555 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 556 | skb->protocol = eth_type_trans(skb, netdev); |
| 557 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 558 | if (staterr & E1000_RXD_STAT_VP) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 559 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag); |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 560 | |
| 561 | napi_gro_receive(&adapter->napi, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 565 | * e1000_rx_checksum - Receive Checksum Offload |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 566 | * @adapter: board private structure |
| 567 | * @status_err: receive descriptor status and error fields |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 568 | * @skb: socket buffer with received data |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 569 | **/ |
| 570 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 571 | struct sk_buff *skb) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 572 | { |
| 573 | u16 status = (u16)status_err; |
| 574 | u8 errors = (u8)(status_err >> 24); |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 575 | |
| 576 | skb_checksum_none_assert(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 577 | |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 578 | /* Rx checksum disabled */ |
| 579 | if (!(adapter->netdev->features & NETIF_F_RXCSUM)) |
| 580 | return; |
| 581 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 582 | /* Ignore Checksum bit is set */ |
| 583 | if (status & E1000_RXD_STAT_IXSM) |
| 584 | return; |
Bruce Allan | afd1293 | 2012-01-05 00:34:05 +0000 | [diff] [blame] | 585 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 586 | /* TCP/UDP checksum error bit or IP checksum error bit is set */ |
| 587 | if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 588 | /* let the stack verify checksum errors */ |
| 589 | adapter->hw_csum_err++; |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | /* TCP/UDP Checksum has not been calculated */ |
| 594 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
| 595 | return; |
| 596 | |
| 597 | /* It must be a TCP or UDP packet with a valid checksum */ |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 598 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 599 | adapter->hw_csum_good++; |
| 600 | } |
| 601 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 602 | static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i) |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 603 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 604 | struct e1000_adapter *adapter = rx_ring->adapter; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 605 | struct e1000_hw *hw = &adapter->hw; |
| 606 | |
Punit Agrawal | d601afc | 2020-05-15 13:31:27 +0900 | [diff] [blame] | 607 | __ew32_prepare(hw); |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 608 | writel(i, rx_ring->tail); |
| 609 | |
Punit Agrawal | d601afc | 2020-05-15 13:31:27 +0900 | [diff] [blame] | 610 | if (unlikely(i != readl(rx_ring->tail))) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 611 | u32 rctl = er32(RCTL); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 612 | |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 613 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 614 | e_err("ME firmware caused invalid RDT - resetting\n"); |
| 615 | schedule_work(&adapter->reset_task); |
| 616 | } |
| 617 | } |
| 618 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 619 | 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] | 620 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 621 | struct e1000_adapter *adapter = tx_ring->adapter; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 622 | struct e1000_hw *hw = &adapter->hw; |
| 623 | |
Punit Agrawal | d601afc | 2020-05-15 13:31:27 +0900 | [diff] [blame] | 624 | __ew32_prepare(hw); |
Bruce Allan | bdc125f | 2012-03-20 03:47:52 +0000 | [diff] [blame] | 625 | writel(i, tx_ring->tail); |
| 626 | |
Punit Agrawal | d601afc | 2020-05-15 13:31:27 +0900 | [diff] [blame] | 627 | if (unlikely(i != readl(tx_ring->tail))) { |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 628 | u32 tctl = er32(TCTL); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 629 | |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 630 | ew32(TCTL, tctl & ~E1000_TCTL_EN); |
| 631 | e_err("ME firmware caused invalid TDT - resetting\n"); |
| 632 | schedule_work(&adapter->reset_task); |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | /** |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 637 | * e1000_alloc_rx_buffers - Replace used receive buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 638 | * @rx_ring: Rx descriptor ring |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 639 | * @cleaned_count: number to reallocate |
| 640 | * @gfp: flags for allocation |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 641 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 642 | static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 643 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 644 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 645 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 646 | struct net_device *netdev = adapter->netdev; |
| 647 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 648 | union e1000_rx_desc_extended *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 649 | struct e1000_buffer *buffer_info; |
| 650 | struct sk_buff *skb; |
| 651 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 652 | unsigned int bufsz = adapter->rx_buffer_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 653 | |
| 654 | i = rx_ring->next_to_use; |
| 655 | buffer_info = &rx_ring->buffer_info[i]; |
| 656 | |
| 657 | while (cleaned_count--) { |
| 658 | skb = buffer_info->skb; |
| 659 | if (skb) { |
| 660 | skb_trim(skb, 0); |
| 661 | goto map_skb; |
| 662 | } |
| 663 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 664 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 665 | if (!skb) { |
| 666 | /* Better luck next round */ |
| 667 | adapter->alloc_rx_buff_failed++; |
| 668 | break; |
| 669 | } |
| 670 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 671 | buffer_info->skb = skb; |
| 672 | map_skb: |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 673 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 674 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 675 | DMA_FROM_DEVICE); |
| 676 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 677 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 678 | adapter->rx_dma_failed++; |
| 679 | break; |
| 680 | } |
| 681 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 682 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 683 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 684 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 685 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 686 | /* Force memory writes to complete before letting h/w |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 687 | * know there are new descriptors to fetch. (Only |
| 688 | * applicable for weak-ordered memory model archs, |
| 689 | * such as IA-64). |
| 690 | */ |
| 691 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 692 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 693 | e1000e_update_rdt_wa(rx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 694 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 695 | writel(i, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 696 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 697 | i++; |
| 698 | if (i == rx_ring->count) |
| 699 | i = 0; |
| 700 | buffer_info = &rx_ring->buffer_info[i]; |
| 701 | } |
| 702 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 703 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | /** |
| 707 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 708 | * @rx_ring: Rx descriptor ring |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 709 | * @cleaned_count: number to reallocate |
| 710 | * @gfp: flags for allocation |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 711 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 712 | static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 713 | int cleaned_count, gfp_t gfp) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 714 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 715 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 716 | struct net_device *netdev = adapter->netdev; |
| 717 | struct pci_dev *pdev = adapter->pdev; |
| 718 | union e1000_rx_desc_packet_split *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 719 | struct e1000_buffer *buffer_info; |
| 720 | struct e1000_ps_page *ps_page; |
| 721 | struct sk_buff *skb; |
| 722 | unsigned int i, j; |
| 723 | |
| 724 | i = rx_ring->next_to_use; |
| 725 | buffer_info = &rx_ring->buffer_info[i]; |
| 726 | |
| 727 | while (cleaned_count--) { |
| 728 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 729 | |
| 730 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 731 | ps_page = &buffer_info->ps_pages[j]; |
| 732 | if (j >= adapter->rx_ps_pages) { |
| 733 | /* all unused desc entries get hw null ptr */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 734 | rx_desc->read.buffer_addr[j + 1] = |
| 735 | ~cpu_to_le64(0); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 736 | continue; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 737 | } |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 738 | if (!ps_page->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 739 | ps_page->page = alloc_page(gfp); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 740 | if (!ps_page->page) { |
| 741 | adapter->alloc_rx_buff_failed++; |
| 742 | goto no_buffers; |
| 743 | } |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 744 | ps_page->dma = dma_map_page(&pdev->dev, |
| 745 | ps_page->page, |
| 746 | 0, PAGE_SIZE, |
| 747 | DMA_FROM_DEVICE); |
| 748 | if (dma_mapping_error(&pdev->dev, |
| 749 | ps_page->dma)) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 750 | dev_err(&adapter->pdev->dev, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 751 | "Rx DMA page map failed\n"); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 752 | adapter->rx_dma_failed++; |
| 753 | goto no_buffers; |
| 754 | } |
| 755 | } |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 756 | /* Refresh the desc even if buffer_addrs |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 757 | * didn't change because each write-back |
| 758 | * erases this info. |
| 759 | */ |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 760 | rx_desc->read.buffer_addr[j + 1] = |
| 761 | cpu_to_le64(ps_page->dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 764 | skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 765 | gfp); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 766 | |
| 767 | if (!skb) { |
| 768 | adapter->alloc_rx_buff_failed++; |
| 769 | break; |
| 770 | } |
| 771 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 772 | buffer_info->skb = skb; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 773 | buffer_info->dma = dma_map_single(&pdev->dev, skb->data, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 774 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 775 | DMA_FROM_DEVICE); |
| 776 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 777 | dev_err(&pdev->dev, "Rx DMA map failed\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 778 | adapter->rx_dma_failed++; |
| 779 | /* cleanup skb */ |
| 780 | dev_kfree_skb_any(skb); |
| 781 | buffer_info->skb = NULL; |
| 782 | break; |
| 783 | } |
| 784 | |
| 785 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 786 | |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 787 | if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 788 | /* Force memory writes to complete before letting h/w |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 789 | * know there are new descriptors to fetch. (Only |
| 790 | * applicable for weak-ordered memory model archs, |
| 791 | * such as IA-64). |
| 792 | */ |
| 793 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 794 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 795 | e1000e_update_rdt_wa(rx_ring, i << 1); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 796 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 797 | writel(i << 1, rx_ring->tail); |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 800 | i++; |
| 801 | if (i == rx_ring->count) |
| 802 | i = 0; |
| 803 | buffer_info = &rx_ring->buffer_info[i]; |
| 804 | } |
| 805 | |
| 806 | no_buffers: |
Tom Herbert | 50849d7 | 2010-05-05 14:02:49 +0000 | [diff] [blame] | 807 | rx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | /** |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 811 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 812 | * @rx_ring: Rx descriptor ring |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 813 | * @cleaned_count: number of buffers to allocate this pass |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 814 | * @gfp: flags for allocation |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 815 | **/ |
| 816 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 817 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 818 | int cleaned_count, gfp_t gfp) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 819 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 820 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 821 | struct net_device *netdev = adapter->netdev; |
| 822 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 823 | union e1000_rx_desc_extended *rx_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 824 | struct e1000_buffer *buffer_info; |
| 825 | struct sk_buff *skb; |
| 826 | unsigned int i; |
Bruce Allan | 2a2293b | 2012-12-05 06:26:35 +0000 | [diff] [blame] | 827 | unsigned int bufsz = 256 - 16; /* for skb_reserve */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 828 | |
| 829 | i = rx_ring->next_to_use; |
| 830 | buffer_info = &rx_ring->buffer_info[i]; |
| 831 | |
| 832 | while (cleaned_count--) { |
| 833 | skb = buffer_info->skb; |
| 834 | if (skb) { |
| 835 | skb_trim(skb, 0); |
| 836 | goto check_page; |
| 837 | } |
| 838 | |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 839 | skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 840 | if (unlikely(!skb)) { |
| 841 | /* Better luck next round */ |
| 842 | adapter->alloc_rx_buff_failed++; |
| 843 | break; |
| 844 | } |
| 845 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 846 | buffer_info->skb = skb; |
| 847 | check_page: |
| 848 | /* allocate a new page if necessary */ |
| 849 | if (!buffer_info->page) { |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 850 | buffer_info->page = alloc_page(gfp); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 851 | if (unlikely(!buffer_info->page)) { |
| 852 | adapter->alloc_rx_buff_failed++; |
| 853 | break; |
| 854 | } |
| 855 | } |
| 856 | |
Christoph Paasch | 37287fae | 2013-03-20 08:59:46 +0000 | [diff] [blame] | 857 | if (!buffer_info->dma) { |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 858 | buffer_info->dma = dma_map_page(&pdev->dev, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 859 | buffer_info->page, 0, |
| 860 | PAGE_SIZE, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 861 | DMA_FROM_DEVICE); |
Christoph Paasch | 37287fae | 2013-03-20 08:59:46 +0000 | [diff] [blame] | 862 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
| 863 | adapter->alloc_rx_buff_failed++; |
| 864 | break; |
| 865 | } |
| 866 | } |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 867 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 868 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 869 | rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 870 | |
| 871 | if (unlikely(++i == rx_ring->count)) |
| 872 | i = 0; |
| 873 | buffer_info = &rx_ring->buffer_info[i]; |
| 874 | } |
| 875 | |
| 876 | if (likely(rx_ring->next_to_use != i)) { |
| 877 | rx_ring->next_to_use = i; |
| 878 | if (unlikely(i-- == 0)) |
| 879 | i = (rx_ring->count - 1); |
| 880 | |
| 881 | /* Force memory writes to complete before letting h/w |
| 882 | * know there are new descriptors to fetch. (Only |
| 883 | * applicable for weak-ordered memory model archs, |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 884 | * such as IA-64). |
| 885 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 886 | wmb(); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 887 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 888 | e1000e_update_rdt_wa(rx_ring, i); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 889 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 890 | writel(i, rx_ring->tail); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 894 | static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss, |
| 895 | struct sk_buff *skb) |
| 896 | { |
| 897 | if (netdev->features & NETIF_F_RXHASH) |
Tom Herbert | e25909b | 2013-12-18 16:46:48 +0000 | [diff] [blame] | 898 | skb_set_hash(skb, le32_to_cpu(rss), PKT_HASH_TYPE_L3); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 901 | /** |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 902 | * e1000_clean_rx_irq - Send received data up the network stack |
| 903 | * @rx_ring: Rx descriptor ring |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 904 | * @work_done: output parameter for indicating completed work |
| 905 | * @work_to_do: how many packets we can clean |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 906 | * |
| 907 | * the return value indicates whether actual cleaning was done, there |
| 908 | * is no guarantee that everything was cleaned |
| 909 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 910 | static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
| 911 | int work_to_do) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 912 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 913 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 914 | struct net_device *netdev = adapter->netdev; |
| 915 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 916 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 917 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 918 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 919 | u32 length, staterr; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 920 | unsigned int i; |
| 921 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 922 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 923 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 924 | |
| 925 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 926 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 927 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 928 | buffer_info = &rx_ring->buffer_info[i]; |
| 929 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 930 | while (staterr & E1000_RXD_STAT_DD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 931 | struct sk_buff *skb; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 932 | |
| 933 | if (*work_done >= work_to_do) |
| 934 | break; |
| 935 | (*work_done)++; |
Alexander Duyck | 837a1db | 2015-04-07 16:55:27 -0700 | [diff] [blame] | 936 | dma_rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 937 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 938 | skb = buffer_info->skb; |
| 939 | buffer_info->skb = NULL; |
| 940 | |
| 941 | prefetch(skb->data - NET_IP_ALIGN); |
| 942 | |
| 943 | i++; |
| 944 | if (i == rx_ring->count) |
| 945 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 946 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 947 | prefetch(next_rxd); |
| 948 | |
| 949 | next_buffer = &rx_ring->buffer_info[i]; |
| 950 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 951 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 952 | cleaned_count++; |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 953 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
| 954 | adapter->rx_buffer_len, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 955 | buffer_info->dma = 0; |
| 956 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 957 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 958 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 959 | /* !EOP means multiple descriptors were used to store a single |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 960 | * packet, if that's the case we need to toss it. In fact, we |
| 961 | * need to toss every packet with the EOP bit clear and the |
| 962 | * next frame that _does_ have the EOP bit set, as it is by |
| 963 | * definition only a frame fragment |
| 964 | */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 965 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 966 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 967 | |
| 968 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 969 | /* All receives must fit into a single buffer */ |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 970 | e_dbg("Receive packet consumed multiple buffers\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 971 | /* recycle */ |
| 972 | buffer_info->skb = skb; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 973 | if (staterr & E1000_RXD_STAT_EOP) |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 974 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 975 | goto next_desc; |
| 976 | } |
| 977 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 978 | if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 979 | !(netdev->features & NETIF_F_RXALL))) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 980 | /* recycle */ |
| 981 | buffer_info->skb = skb; |
| 982 | goto next_desc; |
| 983 | } |
| 984 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 985 | /* adjust length to remove Ethernet CRC */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 986 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 987 | /* If configured to store CRC, don't subtract FCS, |
| 988 | * but keep the FCS bytes out of the total_rx_bytes |
| 989 | * counter |
| 990 | */ |
| 991 | if (netdev->features & NETIF_F_RXFCS) |
| 992 | total_rx_bytes -= 4; |
| 993 | else |
| 994 | length -= 4; |
| 995 | } |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 996 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 997 | total_rx_bytes += length; |
| 998 | total_rx_packets++; |
| 999 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1000 | /* code added for copybreak, this should improve |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1001 | * performance for small packets with large amounts |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1002 | * of reassembly being done in the stack |
| 1003 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1004 | if (length < copybreak) { |
| 1005 | struct sk_buff *new_skb = |
Alexander Duyck | 67fd893 | 2014-12-09 19:40:56 -0800 | [diff] [blame] | 1006 | napi_alloc_skb(&adapter->napi, length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1007 | if (new_skb) { |
Bruce Allan | 808ff67 | 2008-08-08 18:35:56 -0700 | [diff] [blame] | 1008 | skb_copy_to_linear_data_offset(new_skb, |
| 1009 | -NET_IP_ALIGN, |
| 1010 | (skb->data - |
| 1011 | NET_IP_ALIGN), |
| 1012 | (length + |
| 1013 | NET_IP_ALIGN)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1014 | /* save the skb in buffer_info as good */ |
| 1015 | buffer_info->skb = skb; |
| 1016 | skb = new_skb; |
| 1017 | } |
| 1018 | /* else just continue with the old one */ |
| 1019 | } |
| 1020 | /* end copybreak code */ |
| 1021 | skb_put(skb, length); |
| 1022 | |
| 1023 | /* Receive Checksum Offload */ |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1024 | e1000_rx_checksum(adapter, staterr, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1025 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1026 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1027 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1028 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1029 | rx_desc->wb.upper.vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1030 | |
| 1031 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1032 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1033 | |
| 1034 | /* return some buffers to hardware, one at a time is too slow */ |
| 1035 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1036 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1037 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1038 | cleaned_count = 0; |
| 1039 | } |
| 1040 | |
| 1041 | /* use prefetched values */ |
| 1042 | rx_desc = next_rxd; |
| 1043 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1044 | |
| 1045 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1046 | } |
| 1047 | rx_ring->next_to_clean = i; |
| 1048 | |
| 1049 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1050 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1051 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1052 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1053 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1054 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1055 | return cleaned; |
| 1056 | } |
| 1057 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1058 | static void e1000_put_txbuf(struct e1000_ring *tx_ring, |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 1059 | struct e1000_buffer *buffer_info, |
| 1060 | bool drop) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1061 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1062 | struct e1000_adapter *adapter = tx_ring->adapter; |
| 1063 | |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1064 | if (buffer_info->dma) { |
| 1065 | if (buffer_info->mapped_as_page) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1066 | dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, |
| 1067 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1068 | else |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1069 | dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, |
| 1070 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 1071 | buffer_info->dma = 0; |
| 1072 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1073 | if (buffer_info->skb) { |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 1074 | if (drop) |
| 1075 | dev_kfree_skb_any(buffer_info->skb); |
| 1076 | else |
| 1077 | dev_consume_skb_any(buffer_info->skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1078 | buffer_info->skb = NULL; |
| 1079 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 1080 | buffer_info->time_stamp = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1083 | static void e1000_print_hw_hang(struct work_struct *work) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1084 | { |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1085 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1086 | struct e1000_adapter, |
| 1087 | print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1088 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1089 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1090 | unsigned int i = tx_ring->next_to_clean; |
| 1091 | unsigned int eop = tx_ring->buffer_info[i].next_to_watch; |
| 1092 | struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1093 | struct e1000_hw *hw = &adapter->hw; |
| 1094 | u16 phy_status, phy_1000t_status, phy_ext_status; |
| 1095 | u16 pci_status; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1096 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1097 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1098 | return; |
| 1099 | |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 1100 | if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1101 | /* May be block on write-back, flush and detect again |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1102 | * flush pending descriptor writebacks to memory |
| 1103 | */ |
| 1104 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 1105 | /* execute the writes immediately */ |
| 1106 | e1e_flush(); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1107 | /* Due to rare timing issues, write to TIDV again to ensure |
Matthew Vick | bf03085 | 2012-03-16 09:03:00 +0000 | [diff] [blame] | 1108 | * the write is successful |
| 1109 | */ |
| 1110 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 1111 | /* execute the writes immediately */ |
| 1112 | e1e_flush(); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1113 | adapter->tx_hang_recheck = true; |
| 1114 | return; |
| 1115 | } |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1116 | adapter->tx_hang_recheck = false; |
David Ertman | d9554e9 | 2014-01-08 01:07:55 +0000 | [diff] [blame] | 1117 | |
| 1118 | if (er32(TDH(0)) == er32(TDT(0))) { |
| 1119 | e_dbg("false hang detected, ignoring\n"); |
| 1120 | return; |
| 1121 | } |
| 1122 | |
| 1123 | /* Real hang detected */ |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1124 | netif_stop_queue(netdev); |
| 1125 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 1126 | e1e_rphy(hw, MII_BMSR, &phy_status); |
| 1127 | e1e_rphy(hw, MII_STAT1000, &phy_1000t_status); |
| 1128 | e1e_rphy(hw, MII_ESTATUS, &phy_ext_status); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1129 | |
| 1130 | pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status); |
| 1131 | |
| 1132 | /* detected Hardware unit hang */ |
| 1133 | e_err("Detected Hardware Unit Hang:\n" |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1134 | " TDH <%x>\n" |
| 1135 | " TDT <%x>\n" |
| 1136 | " next_to_use <%x>\n" |
| 1137 | " next_to_clean <%x>\n" |
| 1138 | "buffer_info[next_to_clean]:\n" |
| 1139 | " time_stamp <%lx>\n" |
| 1140 | " next_to_watch <%x>\n" |
| 1141 | " jiffies <%lx>\n" |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1142 | " next_to_watch.status <%x>\n" |
| 1143 | "MAC Status <%x>\n" |
| 1144 | "PHY Status <%x>\n" |
| 1145 | "PHY 1000BASE-T Status <%x>\n" |
| 1146 | "PHY Extended Status <%x>\n" |
| 1147 | "PCI Status <%x>\n", |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 1148 | readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use, |
| 1149 | tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp, |
| 1150 | eop, jiffies, eop_desc->upper.fields.status, er32(STATUS), |
| 1151 | phy_status, phy_1000t_status, phy_ext_status, pci_status); |
Bruce Allan | 7c0427e | 2012-03-20 03:48:08 +0000 | [diff] [blame] | 1152 | |
David Ertman | d9554e9 | 2014-01-08 01:07:55 +0000 | [diff] [blame] | 1153 | e1000e_dump(adapter); |
| 1154 | |
Bruce Allan | 7c0427e | 2012-03-20 03:48:08 +0000 | [diff] [blame] | 1155 | /* Suggest workaround for known h/w issue */ |
| 1156 | if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE)) |
| 1157 | e_err("Try turning off Tx pause (flow control) via ethtool\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1161 | * e1000e_tx_hwtstamp_work - check for Tx time stamp |
| 1162 | * @work: pointer to work struct |
| 1163 | * |
| 1164 | * This work function polls the TSYNCTXCTL valid bit to determine when a |
| 1165 | * timestamp has been taken for the current stored skb. The timestamp must |
| 1166 | * be for this skb because only one such packet is allowed in the queue. |
| 1167 | */ |
| 1168 | static void e1000e_tx_hwtstamp_work(struct work_struct *work) |
| 1169 | { |
| 1170 | struct e1000_adapter *adapter = container_of(work, struct e1000_adapter, |
| 1171 | tx_hwtstamp_work); |
| 1172 | struct e1000_hw *hw = &adapter->hw; |
| 1173 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1174 | if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) { |
Jacob Keller | 5012863 | 2017-05-03 10:28:50 -0700 | [diff] [blame] | 1175 | struct sk_buff *skb = adapter->tx_hwtstamp_skb; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1176 | struct skb_shared_hwtstamps shhwtstamps; |
| 1177 | u64 txstmp; |
| 1178 | |
| 1179 | txstmp = er32(TXSTMPL); |
| 1180 | txstmp |= (u64)er32(TXSTMPH) << 32; |
| 1181 | |
| 1182 | e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp); |
| 1183 | |
Jacob Keller | 5012863 | 2017-05-03 10:28:50 -0700 | [diff] [blame] | 1184 | /* Clear the global tx_hwtstamp_skb pointer and force writes |
| 1185 | * prior to notifying the stack of a Tx timestamp. |
| 1186 | */ |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1187 | adapter->tx_hwtstamp_skb = NULL; |
Jacob Keller | 5012863 | 2017-05-03 10:28:50 -0700 | [diff] [blame] | 1188 | wmb(); /* force write prior to skb_tstamp_tx */ |
| 1189 | |
| 1190 | skb_tstamp_tx(skb, &shhwtstamps); |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 1191 | dev_consume_skb_any(skb); |
Jakub Kicinski | 59c871c | 2014-03-15 14:55:00 +0000 | [diff] [blame] | 1192 | } else if (time_after(jiffies, adapter->tx_hwtstamp_start |
| 1193 | + adapter->tx_timeout_factor * HZ)) { |
| 1194 | dev_kfree_skb_any(adapter->tx_hwtstamp_skb); |
| 1195 | adapter->tx_hwtstamp_skb = NULL; |
| 1196 | adapter->tx_hwtstamp_timeouts++; |
Jakub Kicinski | c5ffe7e | 2014-04-02 10:33:22 +0000 | [diff] [blame] | 1197 | e_warn("clearing Tx timestamp hang\n"); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1198 | } else { |
| 1199 | /* reschedule to check later */ |
| 1200 | schedule_work(&adapter->tx_hwtstamp_work); |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1205 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1206 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1207 | * |
| 1208 | * the return value indicates whether actual cleaning was done, there |
| 1209 | * is no guarantee that everything was cleaned |
| 1210 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1211 | static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1212 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1213 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1214 | struct net_device *netdev = adapter->netdev; |
| 1215 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1216 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 1217 | struct e1000_buffer *buffer_info; |
| 1218 | unsigned int i, eop; |
| 1219 | unsigned int count = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1220 | unsigned int total_tx_bytes = 0, total_tx_packets = 0; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1221 | unsigned int bytes_compl = 0, pkts_compl = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1222 | |
| 1223 | i = tx_ring->next_to_clean; |
| 1224 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1225 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 1226 | |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1227 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 1228 | (count < tx_ring->count)) { |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1229 | bool cleaned = false; |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 1230 | |
Alexander Duyck | 837a1db | 2015-04-07 16:55:27 -0700 | [diff] [blame] | 1231 | dma_rmb(); /* read buffer_info after eop_desc */ |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1232 | for (; !cleaned; count++) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1233 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 1234 | buffer_info = &tx_ring->buffer_info[i]; |
| 1235 | cleaned = (i == eop); |
| 1236 | |
| 1237 | if (cleaned) { |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 1238 | total_tx_packets += buffer_info->segs; |
| 1239 | total_tx_bytes += buffer_info->bytecount; |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1240 | if (buffer_info->skb) { |
| 1241 | bytes_compl += buffer_info->skb->len; |
| 1242 | pkts_compl++; |
| 1243 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 1246 | e1000_put_txbuf(tx_ring, buffer_info, false); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1247 | tx_desc->upper.data = 0; |
| 1248 | |
| 1249 | i++; |
| 1250 | if (i == tx_ring->count) |
| 1251 | i = 0; |
| 1252 | } |
| 1253 | |
Terry Loftin | dac8761 | 2010-04-09 10:29:49 +0000 | [diff] [blame] | 1254 | if (i == tx_ring->next_to_use) |
| 1255 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1256 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1257 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | tx_ring->next_to_clean = i; |
| 1261 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 1262 | netdev_completed_queue(netdev, pkts_compl, bytes_compl); |
| 1263 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1264 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | a86043c | 2009-04-16 16:59:28 +0000 | [diff] [blame] | 1265 | if (count && netif_carrier_ok(netdev) && |
| 1266 | e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1267 | /* Make sure that anybody stopping the queue after this |
| 1268 | * sees the new next_to_clean. |
| 1269 | */ |
| 1270 | smp_mb(); |
| 1271 | |
| 1272 | if (netif_queue_stopped(netdev) && |
| 1273 | !(test_bit(__E1000_DOWN, &adapter->state))) { |
| 1274 | netif_wake_queue(netdev); |
| 1275 | ++adapter->restart_queue; |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | if (adapter->detect_tx_hung) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1280 | /* Detect a transmit hang in hardware, this serializes the |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1281 | * check with the clearing of time_stamp and movement of i |
| 1282 | */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1283 | adapter->detect_tx_hung = false; |
Alexander Duyck | 12d04a3 | 2009-03-25 22:05:03 +0000 | [diff] [blame] | 1284 | if (tx_ring->buffer_info[i].time_stamp && |
| 1285 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1286 | + (adapter->tx_timeout_factor * HZ)) && |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1287 | !(er32(STATUS) & E1000_STATUS_TXOFF)) |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 1288 | schedule_work(&adapter->print_hang_task); |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 1289 | else |
| 1290 | adapter->tx_hang_recheck = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1291 | } |
| 1292 | adapter->total_tx_bytes += total_tx_bytes; |
| 1293 | adapter->total_tx_packets += total_tx_packets; |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1294 | return count < tx_ring->count; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1298 | * 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] | 1299 | * @rx_ring: Rx descriptor ring |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 1300 | * @work_done: output parameter for indicating completed work |
| 1301 | * @work_to_do: how many packets we can clean |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1302 | * |
| 1303 | * the return value indicates whether actual cleaning was done, there |
| 1304 | * is no guarantee that everything was cleaned |
| 1305 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1306 | static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done, |
| 1307 | int work_to_do) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1308 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1309 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1310 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1311 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
| 1312 | struct net_device *netdev = adapter->netdev; |
| 1313 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1314 | struct e1000_buffer *buffer_info, *next_buffer; |
| 1315 | struct e1000_ps_page *ps_page; |
| 1316 | struct sk_buff *skb; |
| 1317 | unsigned int i, j; |
| 1318 | u32 length, staterr; |
| 1319 | int cleaned_count = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1320 | bool cleaned = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1321 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 1322 | |
| 1323 | i = rx_ring->next_to_clean; |
| 1324 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 1325 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1326 | buffer_info = &rx_ring->buffer_info[i]; |
| 1327 | |
| 1328 | while (staterr & E1000_RXD_STAT_DD) { |
| 1329 | if (*work_done >= work_to_do) |
| 1330 | break; |
| 1331 | (*work_done)++; |
| 1332 | skb = buffer_info->skb; |
Alexander Duyck | 837a1db | 2015-04-07 16:55:27 -0700 | [diff] [blame] | 1333 | dma_rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1334 | |
| 1335 | /* in the packet split case this is header only */ |
| 1336 | prefetch(skb->data - NET_IP_ALIGN); |
| 1337 | |
| 1338 | i++; |
| 1339 | if (i == rx_ring->count) |
| 1340 | i = 0; |
| 1341 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
| 1342 | prefetch(next_rxd); |
| 1343 | |
| 1344 | next_buffer = &rx_ring->buffer_info[i]; |
| 1345 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1346 | cleaned = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1347 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1348 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1349 | adapter->rx_ps_bsize0, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1350 | buffer_info->dma = 0; |
| 1351 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 1352 | /* see !EOP comment in other Rx routine */ |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1353 | if (!(staterr & E1000_RXD_STAT_EOP)) |
| 1354 | adapter->flags2 |= FLAG2_IS_DISCARDING; |
| 1355 | |
| 1356 | if (adapter->flags2 & FLAG2_IS_DISCARDING) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1357 | 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] | 1358 | dev_kfree_skb_irq(skb); |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1359 | if (staterr & E1000_RXD_STAT_EOP) |
| 1360 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1361 | goto next_desc; |
| 1362 | } |
| 1363 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 1364 | if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 1365 | !(netdev->features & NETIF_F_RXALL))) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1366 | dev_kfree_skb_irq(skb); |
| 1367 | goto next_desc; |
| 1368 | } |
| 1369 | |
| 1370 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 1371 | |
| 1372 | if (!length) { |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 1373 | e_dbg("Last part of the packet spanning multiple descriptors\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1374 | dev_kfree_skb_irq(skb); |
| 1375 | goto next_desc; |
| 1376 | } |
| 1377 | |
| 1378 | /* Good Receive */ |
| 1379 | skb_put(skb, length); |
| 1380 | |
| 1381 | { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1382 | /* this looks ugly, but it seems compiler issues make |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1383 | * it more efficient than reusing j |
| 1384 | */ |
| 1385 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1386 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1387 | /* page alloc/put takes too long and effects small |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1388 | * packet throughput, so unsplit small packets and |
| 1389 | * save the alloc/put only valid in softirq (napi) |
| 1390 | * context to call kmap_* |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1391 | */ |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1392 | if (l1 && (l1 <= copybreak) && |
| 1393 | ((length + l1) <= adapter->rx_ps_bsize0)) { |
| 1394 | u8 *vaddr; |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 1395 | |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1396 | ps_page = &buffer_info->ps_pages[0]; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1397 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1398 | /* there is no documentation about how to call |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1399 | * kmap_atomic, so we can't hold the mapping |
| 1400 | * very long |
| 1401 | */ |
| 1402 | dma_sync_single_for_cpu(&pdev->dev, |
| 1403 | ps_page->dma, |
| 1404 | PAGE_SIZE, |
| 1405 | DMA_FROM_DEVICE); |
Linus Torvalds | 9f39383 | 2012-03-21 09:40:26 -0700 | [diff] [blame] | 1406 | vaddr = kmap_atomic(ps_page->page); |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1407 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
Linus Torvalds | 9f39383 | 2012-03-21 09:40:26 -0700 | [diff] [blame] | 1408 | kunmap_atomic(vaddr); |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1409 | dma_sync_single_for_device(&pdev->dev, |
| 1410 | ps_page->dma, |
| 1411 | PAGE_SIZE, |
| 1412 | DMA_FROM_DEVICE); |
| 1413 | |
| 1414 | /* remove the CRC */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 1415 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 1416 | if (!(netdev->features & NETIF_F_RXFCS)) |
| 1417 | l1 -= 4; |
| 1418 | } |
Bruce Allan | 0e15df4 | 2012-01-31 06:37:11 +0000 | [diff] [blame] | 1419 | |
| 1420 | skb_put(skb, l1); |
| 1421 | goto copydone; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 1422 | } /* if */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
| 1426 | length = le16_to_cpu(rx_desc->wb.upper.length[j]); |
| 1427 | if (!length) |
| 1428 | break; |
| 1429 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1430 | ps_page = &buffer_info->ps_pages[j]; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1431 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1432 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1433 | ps_page->dma = 0; |
| 1434 | skb_fill_page_desc(skb, j, ps_page->page, 0, length); |
| 1435 | ps_page->page = NULL; |
| 1436 | skb->len += length; |
| 1437 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1438 | skb->truesize += PAGE_SIZE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1441 | /* strip the ethernet crc, problem is we're using pages now so |
| 1442 | * this whole operation can get a little cpu intensive |
| 1443 | */ |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 1444 | if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) { |
| 1445 | if (!(netdev->features & NETIF_F_RXFCS)) |
| 1446 | pskb_trim(skb, skb->len - 4); |
| 1447 | } |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 1448 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1449 | copydone: |
| 1450 | total_rx_bytes += skb->len; |
| 1451 | total_rx_packets++; |
| 1452 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1453 | e1000_rx_checksum(adapter, staterr, skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1454 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1455 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1456 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1457 | if (rx_desc->wb.upper.header_status & |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1458 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1459 | adapter->rx_hdr_split++; |
| 1460 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 1461 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1462 | rx_desc->wb.middle.vlan); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1463 | |
| 1464 | next_desc: |
| 1465 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
| 1466 | buffer_info->skb = NULL; |
| 1467 | |
| 1468 | /* return some buffers to hardware, one at a time is too slow */ |
| 1469 | if (cleaned_count >= E1000_RX_BUFFER_WRITE) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1470 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1471 | GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1472 | cleaned_count = 0; |
| 1473 | } |
| 1474 | |
| 1475 | /* use prefetched values */ |
| 1476 | rx_desc = next_rxd; |
| 1477 | buffer_info = next_buffer; |
| 1478 | |
| 1479 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
| 1480 | } |
| 1481 | rx_ring->next_to_clean = i; |
| 1482 | |
| 1483 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1484 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1485 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1486 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1487 | adapter->total_rx_bytes += total_rx_bytes; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 1488 | adapter->total_rx_packets += total_rx_packets; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1489 | return cleaned; |
| 1490 | } |
| 1491 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1492 | 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] | 1493 | u16 length) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1494 | { |
| 1495 | bi->page = NULL; |
| 1496 | skb->len += length; |
| 1497 | skb->data_len += length; |
Eric Dumazet | 98a045d | 2011-10-13 08:03:36 +0000 | [diff] [blame] | 1498 | skb->truesize += PAGE_SIZE; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | /** |
| 1502 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 1503 | * @rx_ring: Rx descriptor ring |
| 1504 | * @work_done: output parameter for indicating completed work |
| 1505 | * @work_to_do: how many packets we can clean |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1506 | * |
| 1507 | * the return value indicates whether actual cleaning was done, there |
| 1508 | * is no guarantee that everything was cleaned |
| 1509 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1510 | static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done, |
| 1511 | int work_to_do) |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1512 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1513 | struct e1000_adapter *adapter = rx_ring->adapter; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1514 | struct net_device *netdev = adapter->netdev; |
| 1515 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1516 | union e1000_rx_desc_extended *rx_desc, *next_rxd; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1517 | struct e1000_buffer *buffer_info, *next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1518 | u32 length, staterr; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1519 | unsigned int i; |
| 1520 | int cleaned_count = 0; |
| 1521 | bool cleaned = false; |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 1522 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1523 | struct skb_shared_info *shinfo; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1524 | |
| 1525 | i = rx_ring->next_to_clean; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1526 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 1527 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1528 | buffer_info = &rx_ring->buffer_info[i]; |
| 1529 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1530 | while (staterr & E1000_RXD_STAT_DD) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1531 | struct sk_buff *skb; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1532 | |
| 1533 | if (*work_done >= work_to_do) |
| 1534 | break; |
| 1535 | (*work_done)++; |
Alexander Duyck | 837a1db | 2015-04-07 16:55:27 -0700 | [diff] [blame] | 1536 | dma_rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1537 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1538 | skb = buffer_info->skb; |
| 1539 | buffer_info->skb = NULL; |
| 1540 | |
| 1541 | ++i; |
| 1542 | if (i == rx_ring->count) |
| 1543 | i = 0; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1544 | next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1545 | prefetch(next_rxd); |
| 1546 | |
| 1547 | next_buffer = &rx_ring->buffer_info[i]; |
| 1548 | |
| 1549 | cleaned = true; |
| 1550 | cleaned_count++; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1551 | dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE, |
| 1552 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1553 | buffer_info->dma = 0; |
| 1554 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1555 | length = le16_to_cpu(rx_desc->wb.upper.length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1556 | |
| 1557 | /* errors is only valid for DD + EOP descriptors */ |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1558 | if (unlikely((staterr & E1000_RXD_STAT_EOP) && |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 1559 | ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) && |
| 1560 | !(netdev->features & NETIF_F_RXALL)))) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1561 | /* recycle both page and skb */ |
| 1562 | buffer_info->skb = skb; |
| 1563 | /* an error means any chain goes out the window too */ |
| 1564 | if (rx_ring->rx_skb_top) |
| 1565 | dev_kfree_skb_irq(rx_ring->rx_skb_top); |
| 1566 | rx_ring->rx_skb_top = NULL; |
| 1567 | goto next_desc; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1568 | } |
Bruce Allan | f0f1a17 | 2010-12-11 05:53:32 +0000 | [diff] [blame] | 1569 | #define rxtop (rx_ring->rx_skb_top) |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1570 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1571 | /* this descriptor is only the beginning (or middle) */ |
| 1572 | if (!rxtop) { |
| 1573 | /* this is the beginning of a chain */ |
| 1574 | rxtop = skb; |
| 1575 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1576 | 0, length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1577 | } else { |
| 1578 | /* this is the middle of a chain */ |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1579 | shinfo = skb_shinfo(rxtop); |
| 1580 | skb_fill_page_desc(rxtop, shinfo->nr_frags, |
| 1581 | buffer_info->page, 0, |
| 1582 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1583 | /* re-use the skb, only consumed the page */ |
| 1584 | buffer_info->skb = skb; |
| 1585 | } |
| 1586 | e1000_consume_page(buffer_info, rxtop, length); |
| 1587 | goto next_desc; |
| 1588 | } else { |
| 1589 | if (rxtop) { |
| 1590 | /* end of the chain */ |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1591 | shinfo = skb_shinfo(rxtop); |
| 1592 | skb_fill_page_desc(rxtop, shinfo->nr_frags, |
| 1593 | buffer_info->page, 0, |
| 1594 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1595 | /* re-use the current skb, we only consumed the |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1596 | * page |
| 1597 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1598 | buffer_info->skb = skb; |
| 1599 | skb = rxtop; |
| 1600 | rxtop = NULL; |
| 1601 | e1000_consume_page(buffer_info, skb, length); |
| 1602 | } else { |
| 1603 | /* no chain, got EOP, this buf is the packet |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1604 | * copybreak to save the put_page/alloc_page |
| 1605 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1606 | if (length <= copybreak && |
| 1607 | skb_tailroom(skb) >= length) { |
| 1608 | u8 *vaddr; |
Cong Wang | 4679026 | 2011-11-25 23:14:23 +0800 | [diff] [blame] | 1609 | vaddr = kmap_atomic(buffer_info->page); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1610 | memcpy(skb_tail_pointer(skb), vaddr, |
| 1611 | length); |
Cong Wang | 4679026 | 2011-11-25 23:14:23 +0800 | [diff] [blame] | 1612 | kunmap_atomic(vaddr); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1613 | /* re-use the page, so don't erase |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1614 | * buffer_info->page |
| 1615 | */ |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1616 | skb_put(skb, length); |
| 1617 | } else { |
| 1618 | skb_fill_page_desc(skb, 0, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1619 | buffer_info->page, 0, |
| 1620 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1621 | e1000_consume_page(buffer_info, skb, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1622 | length); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1623 | } |
| 1624 | } |
| 1625 | } |
| 1626 | |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 1627 | /* Receive Checksum Offload */ |
| 1628 | e1000_rx_checksum(adapter, staterr, skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1629 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 1630 | e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb); |
| 1631 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1632 | /* probably a little skewed due to removing CRC */ |
| 1633 | total_rx_bytes += skb->len; |
| 1634 | total_rx_packets++; |
| 1635 | |
| 1636 | /* eth type trans needs skb->data to point to something */ |
| 1637 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1638 | e_err("pskb_may_pull failed.\n"); |
Bruce Allan | ef5ab89 | 2011-02-10 08:17:21 +0000 | [diff] [blame] | 1639 | dev_kfree_skb_irq(skb); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1640 | goto next_desc; |
| 1641 | } |
| 1642 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1643 | e1000_receive_skb(adapter, netdev, skb, staterr, |
| 1644 | rx_desc->wb.upper.vlan); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1645 | |
| 1646 | next_desc: |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1647 | rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1648 | |
| 1649 | /* return some buffers to hardware, one at a time is too slow */ |
| 1650 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1651 | adapter->alloc_rx_buf(rx_ring, cleaned_count, |
Jeff Kirsher | c2fed99 | 2011-07-12 16:10:12 +0000 | [diff] [blame] | 1652 | GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1653 | cleaned_count = 0; |
| 1654 | } |
| 1655 | |
| 1656 | /* use prefetched values */ |
| 1657 | rx_desc = next_rxd; |
| 1658 | buffer_info = next_buffer; |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1659 | |
| 1660 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1661 | } |
| 1662 | rx_ring->next_to_clean = i; |
| 1663 | |
| 1664 | cleaned_count = e1000_desc_unused(rx_ring); |
| 1665 | if (cleaned_count) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1666 | adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1667 | |
| 1668 | adapter->total_rx_bytes += total_rx_bytes; |
| 1669 | adapter->total_rx_packets += total_rx_packets; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1670 | return cleaned; |
| 1671 | } |
| 1672 | |
| 1673 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1674 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1675 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1676 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1677 | static void e1000_clean_rx_ring(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1678 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1679 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1680 | struct e1000_buffer *buffer_info; |
| 1681 | struct e1000_ps_page *ps_page; |
| 1682 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1683 | unsigned int i, j; |
| 1684 | |
| 1685 | /* Free all the Rx ring sk_buffs */ |
| 1686 | for (i = 0; i < rx_ring->count; i++) { |
| 1687 | buffer_info = &rx_ring->buffer_info[i]; |
| 1688 | if (buffer_info->dma) { |
| 1689 | if (adapter->clean_rx == e1000_clean_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1690 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1691 | adapter->rx_buffer_len, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1692 | DMA_FROM_DEVICE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1693 | else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1694 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1695 | PAGE_SIZE, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1696 | else if (adapter->clean_rx == e1000_clean_rx_irq_ps) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1697 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1698 | adapter->rx_ps_bsize0, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1699 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1700 | buffer_info->dma = 0; |
| 1701 | } |
| 1702 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1703 | if (buffer_info->page) { |
| 1704 | put_page(buffer_info->page); |
| 1705 | buffer_info->page = NULL; |
| 1706 | } |
| 1707 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1708 | if (buffer_info->skb) { |
| 1709 | dev_kfree_skb(buffer_info->skb); |
| 1710 | buffer_info->skb = NULL; |
| 1711 | } |
| 1712 | |
| 1713 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 1714 | ps_page = &buffer_info->ps_pages[j]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1715 | if (!ps_page->page) |
| 1716 | break; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1717 | dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, |
| 1718 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1719 | ps_page->dma = 0; |
| 1720 | put_page(ps_page->page); |
| 1721 | ps_page->page = NULL; |
| 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | /* there also may be some cached data from a chained receive */ |
| 1726 | if (rx_ring->rx_skb_top) { |
| 1727 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 1728 | rx_ring->rx_skb_top = NULL; |
| 1729 | } |
| 1730 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1731 | /* Zero out the descriptor ring */ |
| 1732 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1733 | |
| 1734 | rx_ring->next_to_clean = 0; |
| 1735 | rx_ring->next_to_use = 0; |
Jesse Brandeburg | b94b502 | 2010-01-19 14:15:59 +0000 | [diff] [blame] | 1736 | adapter->flags2 &= ~FLAG2_IS_DISCARDING; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1739 | static void e1000e_downshift_workaround(struct work_struct *work) |
| 1740 | { |
| 1741 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 1742 | struct e1000_adapter, |
| 1743 | downshift_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1744 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 1745 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 1746 | return; |
| 1747 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1748 | e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); |
| 1749 | } |
| 1750 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1751 | /** |
| 1752 | * e1000_intr_msi - Interrupt Handler |
| 1753 | * @irq: interrupt number |
| 1754 | * @data: pointer to a network interface device structure |
| 1755 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1756 | static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1757 | { |
| 1758 | struct net_device *netdev = data; |
| 1759 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1760 | struct e1000_hw *hw = &adapter->hw; |
| 1761 | u32 icr = er32(ICR); |
| 1762 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1763 | /* read ICR disables interrupts using IAM */ |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1764 | if (icr & E1000_ICR_LSC) { |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1765 | hw->mac.get_link_status = true; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1766 | /* ICH8 workaround-- Call gig speed drop workaround on cable |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1767 | * disconnect (LSC) before accessing any PHY registers |
| 1768 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1769 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1770 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1771 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1772 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1773 | /* 80003ES2LAN workaround-- For packet buffer work-around on |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1774 | * link down event; disable receives here in the ISR and reset |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1775 | * adapter in watchdog |
| 1776 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1777 | if (netif_carrier_ok(netdev) && |
| 1778 | adapter->flags & FLAG_RX_NEEDS_RESTART) { |
| 1779 | /* disable receives */ |
| 1780 | u32 rctl = er32(RCTL); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 1781 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1782 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 1783 | adapter->flags |= FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1784 | } |
| 1785 | /* guard against interrupt when we're going down */ |
| 1786 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 1787 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1790 | /* Reset on uncorrectable ECC error */ |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 1791 | if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) { |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1792 | u32 pbeccsts = er32(PBECCSTS); |
| 1793 | |
| 1794 | adapter->corr_errors += |
| 1795 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 1796 | adapter->uncorr_errors += |
| 1797 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 1798 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 1799 | |
| 1800 | /* Do the reset outside of interrupt context */ |
| 1801 | schedule_work(&adapter->reset_task); |
| 1802 | |
| 1803 | /* return immediately since reset is imminent */ |
| 1804 | return IRQ_HANDLED; |
| 1805 | } |
| 1806 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1807 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1808 | adapter->total_tx_bytes = 0; |
| 1809 | adapter->total_tx_packets = 0; |
| 1810 | adapter->total_rx_bytes = 0; |
| 1811 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1812 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | return IRQ_HANDLED; |
| 1816 | } |
| 1817 | |
| 1818 | /** |
| 1819 | * e1000_intr - Interrupt Handler |
| 1820 | * @irq: interrupt number |
| 1821 | * @data: pointer to a network interface device structure |
| 1822 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1823 | static irqreturn_t e1000_intr(int __always_unused irq, void *data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1824 | { |
| 1825 | struct net_device *netdev = data; |
| 1826 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1827 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1828 | u32 rctl, icr = er32(ICR); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1829 | |
Bruce Allan | a68ea77 | 2009-11-20 23:23:16 +0000 | [diff] [blame] | 1830 | if (!icr || test_bit(__E1000_DOWN, &adapter->state)) |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 1831 | return IRQ_NONE; /* Not our interrupt */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1832 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1833 | /* 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] | 1834 | * not set, then the adapter didn't send an interrupt |
| 1835 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1836 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 1837 | return IRQ_NONE; |
| 1838 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1839 | /* Interrupt Auto-Mask...upon reading ICR, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1840 | * interrupts are masked. No need for the |
| 1841 | * IMC write |
| 1842 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1843 | |
dave graham | 573cca8 | 2009-02-10 12:52:05 +0000 | [diff] [blame] | 1844 | if (icr & E1000_ICR_LSC) { |
Bruce Allan | f92518d | 2012-02-01 11:16:42 +0000 | [diff] [blame] | 1845 | hw->mac.get_link_status = true; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1846 | /* ICH8 workaround-- Call gig speed drop workaround on cable |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1847 | * disconnect (LSC) before accessing any PHY registers |
| 1848 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1849 | if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && |
| 1850 | (!(er32(STATUS) & E1000_STATUS_LU))) |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 1851 | schedule_work(&adapter->downshift_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1852 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1853 | /* 80003ES2LAN workaround-- |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1854 | * For packet buffer work-around on link down event; |
| 1855 | * disable receives here in the ISR and |
| 1856 | * reset adapter in watchdog |
| 1857 | */ |
| 1858 | if (netif_carrier_ok(netdev) && |
| 1859 | (adapter->flags & FLAG_RX_NEEDS_RESTART)) { |
| 1860 | /* disable receives */ |
| 1861 | rctl = er32(RCTL); |
| 1862 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 1863 | adapter->flags |= FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1864 | } |
| 1865 | /* guard against interrupt when we're going down */ |
| 1866 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 1867 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1870 | /* Reset on uncorrectable ECC error */ |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 1871 | if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) { |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 1872 | u32 pbeccsts = er32(PBECCSTS); |
| 1873 | |
| 1874 | adapter->corr_errors += |
| 1875 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 1876 | adapter->uncorr_errors += |
| 1877 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 1878 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 1879 | |
| 1880 | /* Do the reset outside of interrupt context */ |
| 1881 | schedule_work(&adapter->reset_task); |
| 1882 | |
| 1883 | /* return immediately since reset is imminent */ |
| 1884 | return IRQ_HANDLED; |
| 1885 | } |
| 1886 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1887 | if (napi_schedule_prep(&adapter->napi)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1888 | adapter->total_tx_bytes = 0; |
| 1889 | adapter->total_tx_packets = 0; |
| 1890 | adapter->total_rx_bytes = 0; |
| 1891 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1892 | __napi_schedule(&adapter->napi); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | return IRQ_HANDLED; |
| 1896 | } |
| 1897 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1898 | static irqreturn_t e1000_msix_other(int __always_unused irq, void *data) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1899 | { |
| 1900 | struct net_device *netdev = data; |
| 1901 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1902 | struct e1000_hw *hw = &adapter->hw; |
Benjamin Poirier | 116f4a6 | 2018-02-08 15:47:14 +0900 | [diff] [blame] | 1903 | u32 icr = er32(ICR); |
Benjamin Poirier | 745d0bd | 2018-01-31 16:26:27 +0900 | [diff] [blame] | 1904 | |
Benjamin Poirier | 361a954 | 2018-02-08 15:47:13 +0900 | [diff] [blame] | 1905 | if (icr & adapter->eiac_mask) |
| 1906 | ew32(ICS, (icr & adapter->eiac_mask)); |
| 1907 | |
Benjamin Poirier | 4aea7a5c | 2017-07-21 11:36:27 -0700 | [diff] [blame] | 1908 | if (icr & E1000_ICR_LSC) { |
Benjamin Poirier | 4aea7a5c | 2017-07-21 11:36:27 -0700 | [diff] [blame] | 1909 | hw->mac.get_link_status = true; |
| 1910 | /* guard against interrupt when we're going down */ |
| 1911 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 1912 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Benjamin Poirier | 4aea7a5c | 2017-07-21 11:36:27 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
Benjamin Poirier | 1f0ea19 | 2018-02-08 15:47:12 +0900 | [diff] [blame] | 1915 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
Benjamin Poirier | 116f4a6 | 2018-02-08 15:47:14 +0900 | [diff] [blame] | 1916 | ew32(IMS, E1000_IMS_OTHER | IMS_OTHER_MASK); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1917 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1918 | return IRQ_HANDLED; |
| 1919 | } |
| 1920 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1921 | 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] | 1922 | { |
| 1923 | struct net_device *netdev = data; |
| 1924 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1925 | struct e1000_hw *hw = &adapter->hw; |
| 1926 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1927 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1928 | adapter->total_tx_bytes = 0; |
| 1929 | adapter->total_tx_packets = 0; |
| 1930 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1931 | if (!e1000_clean_tx_irq(tx_ring)) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1932 | /* Ring was not completely cleaned, so fire another interrupt */ |
| 1933 | ew32(ICS, tx_ring->ims_val); |
| 1934 | |
Benjamin Poirier | 0a8047a | 2015-11-09 15:50:21 -0800 | [diff] [blame] | 1935 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 1936 | ew32(IMS, adapter->tx_ring->ims_val); |
| 1937 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1938 | return IRQ_HANDLED; |
| 1939 | } |
| 1940 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1941 | 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] | 1942 | { |
| 1943 | struct net_device *netdev = data; |
| 1944 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1945 | struct e1000_ring *rx_ring = adapter->rx_ring; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1946 | |
| 1947 | /* Write the ITR value calculated at the end of the |
| 1948 | * previous interrupt. |
| 1949 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1950 | if (rx_ring->set_itr) { |
Dmitry Fleytman | b77ac46 | 2015-10-13 12:48:18 +0300 | [diff] [blame] | 1951 | u32 itr = rx_ring->itr_val ? |
| 1952 | 1000000000 / (rx_ring->itr_val * 256) : 0; |
| 1953 | |
| 1954 | writel(itr, rx_ring->itr_register); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 1955 | rx_ring->set_itr = 0; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1958 | if (napi_schedule_prep(&adapter->napi)) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1959 | adapter->total_rx_bytes = 0; |
| 1960 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1961 | __napi_schedule(&adapter->napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1962 | } |
| 1963 | return IRQ_HANDLED; |
| 1964 | } |
| 1965 | |
| 1966 | /** |
| 1967 | * e1000_configure_msix - Configure MSI-X hardware |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 1968 | * @adapter: board private structure |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1969 | * |
| 1970 | * e1000_configure_msix sets up the hardware to properly |
| 1971 | * generate MSI-X interrupts. |
| 1972 | **/ |
| 1973 | static void e1000_configure_msix(struct e1000_adapter *adapter) |
| 1974 | { |
| 1975 | struct e1000_hw *hw = &adapter->hw; |
| 1976 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 1977 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 1978 | int vector = 0; |
| 1979 | u32 ctrl_ext, ivar = 0; |
| 1980 | |
| 1981 | adapter->eiac_mask = 0; |
| 1982 | |
| 1983 | /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ |
| 1984 | if (hw->mac.type == e1000_82574) { |
| 1985 | u32 rfctl = er32(RFCTL); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 1986 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1987 | rfctl |= E1000_RFCTL_ACK_DIS; |
| 1988 | ew32(RFCTL, rfctl); |
| 1989 | } |
| 1990 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1991 | /* Configure Rx vector */ |
| 1992 | rx_ring->ims_val = E1000_IMS_RXQ0; |
| 1993 | adapter->eiac_mask |= rx_ring->ims_val; |
| 1994 | if (rx_ring->itr_val) |
| 1995 | writel(1000000000 / (rx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1996 | rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1997 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 1998 | writel(1, rx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1999 | ivar = E1000_IVAR_INT_ALLOC_VALID | vector; |
| 2000 | |
| 2001 | /* Configure Tx vector */ |
| 2002 | tx_ring->ims_val = E1000_IMS_TXQ0; |
| 2003 | vector++; |
| 2004 | if (tx_ring->itr_val) |
| 2005 | writel(1000000000 / (tx_ring->itr_val * 256), |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2006 | tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2007 | else |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2008 | writel(1, tx_ring->itr_register); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2009 | adapter->eiac_mask |= tx_ring->ims_val; |
| 2010 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); |
| 2011 | |
| 2012 | /* set vector for Other Causes, e.g. link changes */ |
| 2013 | vector++; |
| 2014 | ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); |
| 2015 | if (rx_ring->itr_val) |
| 2016 | writel(1000000000 / (rx_ring->itr_val * 256), |
| 2017 | hw->hw_addr + E1000_EITR_82574(vector)); |
| 2018 | else |
| 2019 | writel(1, hw->hw_addr + E1000_EITR_82574(vector)); |
| 2020 | |
| 2021 | /* Cause Tx interrupts on every write back */ |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 2022 | ivar |= BIT(31); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2023 | |
| 2024 | ew32(IVAR, ivar); |
| 2025 | |
| 2026 | /* enable MSI-X PBA support */ |
Benjamin Poirier | 0a8047a | 2015-11-09 15:50:21 -0800 | [diff] [blame] | 2027 | ctrl_ext = er32(CTRL_EXT) & ~E1000_CTRL_EXT_IAME; |
| 2028 | ctrl_ext |= E1000_CTRL_EXT_PBA_CLR | E1000_CTRL_EXT_EIAME; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2029 | ew32(CTRL_EXT, ctrl_ext); |
| 2030 | e1e_flush(); |
| 2031 | } |
| 2032 | |
| 2033 | void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) |
| 2034 | { |
| 2035 | if (adapter->msix_entries) { |
| 2036 | pci_disable_msix(adapter->pdev); |
| 2037 | kfree(adapter->msix_entries); |
| 2038 | adapter->msix_entries = NULL; |
| 2039 | } else if (adapter->flags & FLAG_MSI_ENABLED) { |
| 2040 | pci_disable_msi(adapter->pdev); |
| 2041 | adapter->flags &= ~FLAG_MSI_ENABLED; |
| 2042 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | /** |
| 2046 | * e1000e_set_interrupt_capability - set MSI or MSI-X if supported |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 2047 | * @adapter: board private structure |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2048 | * |
| 2049 | * Attempt to configure interrupts using the best available |
| 2050 | * capabilities of the hardware and kernel. |
| 2051 | **/ |
| 2052 | void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) |
| 2053 | { |
| 2054 | int err; |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2055 | int i; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2056 | |
| 2057 | switch (adapter->int_mode) { |
| 2058 | case E1000E_INT_MODE_MSIX: |
| 2059 | if (adapter->flags & FLAG_HAS_MSIX) { |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2060 | adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */ |
| 2061 | adapter->msix_entries = kcalloc(adapter->num_vectors, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 2062 | sizeof(struct |
| 2063 | msix_entry), |
| 2064 | GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2065 | if (adapter->msix_entries) { |
Alexander Gordeev | 0cc7c95 | 2014-02-18 11:11:41 +0100 | [diff] [blame] | 2066 | struct e1000_adapter *a = adapter; |
| 2067 | |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2068 | for (i = 0; i < adapter->num_vectors; i++) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2069 | adapter->msix_entries[i].entry = i; |
| 2070 | |
Alexander Gordeev | 0cc7c95 | 2014-02-18 11:11:41 +0100 | [diff] [blame] | 2071 | err = pci_enable_msix_range(a->pdev, |
| 2072 | a->msix_entries, |
| 2073 | a->num_vectors, |
| 2074 | a->num_vectors); |
| 2075 | if (err > 0) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2076 | return; |
| 2077 | } |
| 2078 | /* MSI-X failed, so fall through and try MSI */ |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 2079 | 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] | 2080 | e1000e_reset_interrupt_capability(adapter); |
| 2081 | } |
| 2082 | adapter->int_mode = E1000E_INT_MODE_MSI; |
Jeff Kirsher | 5463fce6 | 2020-06-03 20:07:26 -0700 | [diff] [blame] | 2083 | fallthrough; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2084 | case E1000E_INT_MODE_MSI: |
| 2085 | if (!pci_enable_msi(adapter->pdev)) { |
| 2086 | adapter->flags |= FLAG_MSI_ENABLED; |
| 2087 | } else { |
| 2088 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 2089 | 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] | 2090 | } |
Jeff Kirsher | 5463fce6 | 2020-06-03 20:07:26 -0700 | [diff] [blame] | 2091 | fallthrough; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2092 | case E1000E_INT_MODE_LEGACY: |
| 2093 | /* Don't do anything; this is the system default */ |
| 2094 | break; |
| 2095 | } |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2096 | |
| 2097 | /* store the number of vectors being used */ |
| 2098 | adapter->num_vectors = 1; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | /** |
| 2102 | * e1000_request_msix - Initialize MSI-X interrupts |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 2103 | * @adapter: board private structure |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2104 | * |
| 2105 | * e1000_request_msix allocates MSI-X vectors and requests interrupts from the |
| 2106 | * kernel. |
| 2107 | **/ |
| 2108 | static int e1000_request_msix(struct e1000_adapter *adapter) |
| 2109 | { |
| 2110 | struct net_device *netdev = adapter->netdev; |
| 2111 | int err = 0, vector = 0; |
| 2112 | |
| 2113 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 2114 | snprintf(adapter->rx_ring->name, |
| 2115 | sizeof(adapter->rx_ring->name) - 1, |
Florian Fainelli | 135e724 | 2019-02-21 20:09:28 -0800 | [diff] [blame] | 2116 | "%.14s-rx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2117 | else |
| 2118 | memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); |
| 2119 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2120 | e1000_intr_msix_rx, 0, adapter->rx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2121 | netdev); |
| 2122 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2123 | return err; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2124 | adapter->rx_ring->itr_register = adapter->hw.hw_addr + |
| 2125 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2126 | adapter->rx_ring->itr_val = adapter->itr; |
| 2127 | vector++; |
| 2128 | |
| 2129 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Bruce Allan | 79f5e84 | 2011-01-19 04:20:59 +0000 | [diff] [blame] | 2130 | snprintf(adapter->tx_ring->name, |
| 2131 | sizeof(adapter->tx_ring->name) - 1, |
Florian Fainelli | 135e724 | 2019-02-21 20:09:28 -0800 | [diff] [blame] | 2132 | "%.14s-tx-0", netdev->name); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2133 | else |
| 2134 | memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); |
| 2135 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2136 | e1000_intr_msix_tx, 0, adapter->tx_ring->name, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2137 | netdev); |
| 2138 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2139 | return err; |
Bruce Allan | c5083cf | 2011-12-16 00:45:40 +0000 | [diff] [blame] | 2140 | adapter->tx_ring->itr_register = adapter->hw.hw_addr + |
| 2141 | E1000_EITR_82574(vector); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2142 | adapter->tx_ring->itr_val = adapter->itr; |
| 2143 | vector++; |
| 2144 | |
| 2145 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2146 | e1000_msix_other, 0, netdev->name, netdev); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2147 | if (err) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2148 | return err; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2149 | |
| 2150 | e1000_configure_msix(adapter); |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2151 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2152 | return 0; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2155 | /** |
| 2156 | * e1000_request_irq - initialize interrupts |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 2157 | * @adapter: board private structure |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2158 | * |
| 2159 | * Attempts to configure interrupts using the best available |
| 2160 | * capabilities of the hardware and kernel. |
| 2161 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2162 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 2163 | { |
| 2164 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2165 | int err; |
| 2166 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2167 | if (adapter->msix_entries) { |
| 2168 | err = e1000_request_msix(adapter); |
| 2169 | if (!err) |
| 2170 | return err; |
| 2171 | /* fall back to MSI */ |
| 2172 | e1000e_reset_interrupt_capability(adapter); |
| 2173 | adapter->int_mode = E1000E_INT_MODE_MSI; |
| 2174 | e1000e_set_interrupt_capability(adapter); |
| 2175 | } |
| 2176 | if (adapter->flags & FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2177 | err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2178 | netdev->name, netdev); |
| 2179 | if (!err) |
| 2180 | return err; |
| 2181 | |
| 2182 | /* fall back to legacy interrupt */ |
| 2183 | e1000e_reset_interrupt_capability(adapter); |
| 2184 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2187 | err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2188 | netdev->name, netdev); |
| 2189 | if (err) |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 2190 | e_err("Unable to allocate interrupt, Error: %d\n", err); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2191 | |
| 2192 | return err; |
| 2193 | } |
| 2194 | |
| 2195 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 2196 | { |
| 2197 | struct net_device *netdev = adapter->netdev; |
| 2198 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2199 | if (adapter->msix_entries) { |
| 2200 | int vector = 0; |
| 2201 | |
| 2202 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2203 | vector++; |
| 2204 | |
| 2205 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2206 | vector++; |
| 2207 | |
| 2208 | /* Other Causes interrupt vector */ |
| 2209 | free_irq(adapter->msix_entries[vector].vector, netdev); |
| 2210 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2211 | } |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2212 | |
| 2213 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | /** |
| 2217 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 2218 | * @adapter: board private structure |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2219 | **/ |
| 2220 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
| 2221 | { |
| 2222 | struct e1000_hw *hw = &adapter->hw; |
| 2223 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2224 | ew32(IMC, ~0); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2225 | if (adapter->msix_entries) |
| 2226 | ew32(EIAC_82574, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2227 | e1e_flush(); |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2228 | |
| 2229 | if (adapter->msix_entries) { |
| 2230 | int i; |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 2231 | |
Jeff Kirsher | 8e86acd | 2010-08-02 14:27:23 +0000 | [diff] [blame] | 2232 | for (i = 0; i < adapter->num_vectors; i++) |
| 2233 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2234 | } else { |
| 2235 | synchronize_irq(adapter->pdev->irq); |
| 2236 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | /** |
| 2240 | * e1000_irq_enable - Enable default interrupt generation settings |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 2241 | * @adapter: board private structure |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2242 | **/ |
| 2243 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
| 2244 | { |
| 2245 | struct e1000_hw *hw = &adapter->hw; |
| 2246 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2247 | if (adapter->msix_entries) { |
| 2248 | ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); |
Benjamin Poirier | 116f4a6 | 2018-02-08 15:47:14 +0900 | [diff] [blame] | 2249 | ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | |
| 2250 | IMS_OTHER_MASK); |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 2251 | } else if (hw->mac.type >= e1000_pch_lpt) { |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 2252 | ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2253 | } else { |
| 2254 | ew32(IMS, IMS_ENABLE_MASK); |
| 2255 | } |
Jesse Brandeburg | 74ef9c3 | 2008-03-21 11:06:52 -0700 | [diff] [blame] | 2256 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2260 | * 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] | 2261 | * @adapter: address of board private structure |
| 2262 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2263 | * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2264 | * For ASF and Pass Through versions of f/w this means that |
| 2265 | * the driver is loaded. For AMT version (only with 82573) |
| 2266 | * of the f/w this means that the network i/f is open. |
| 2267 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2268 | void e1000e_get_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2269 | { |
| 2270 | struct e1000_hw *hw = &adapter->hw; |
| 2271 | u32 ctrl_ext; |
| 2272 | u32 swsm; |
| 2273 | |
| 2274 | /* Let firmware know the driver has taken over */ |
| 2275 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2276 | swsm = er32(SWSM); |
| 2277 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
| 2278 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2279 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2280 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | /** |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2285 | * 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] | 2286 | * @adapter: address of board private structure |
| 2287 | * |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2288 | * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2289 | * For ASF and Pass Through versions of f/w this means that the |
| 2290 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 2291 | * of the f/w this means that the network i/f is closed. |
| 2292 | * |
| 2293 | **/ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2294 | void e1000e_release_hw_control(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2295 | { |
| 2296 | struct e1000_hw *hw = &adapter->hw; |
| 2297 | u32 ctrl_ext; |
| 2298 | u32 swsm; |
| 2299 | |
| 2300 | /* Let firmware taken over control of h/w */ |
| 2301 | if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { |
| 2302 | swsm = er32(SWSM); |
| 2303 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
| 2304 | } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { |
| 2305 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2306 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2307 | } |
| 2308 | } |
| 2309 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2310 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 2311 | * e1000_alloc_ring_dma - allocate memory for a ring structure |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 2312 | * @adapter: board private structure |
| 2313 | * @ring: ring struct for which to allocate dma |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2314 | **/ |
| 2315 | static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, |
| 2316 | struct e1000_ring *ring) |
| 2317 | { |
| 2318 | struct pci_dev *pdev = adapter->pdev; |
| 2319 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 2320 | ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, |
| 2321 | GFP_KERNEL); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2322 | if (!ring->desc) |
| 2323 | return -ENOMEM; |
| 2324 | |
| 2325 | return 0; |
| 2326 | } |
| 2327 | |
| 2328 | /** |
| 2329 | * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2330 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2331 | * |
| 2332 | * Return 0 on success, negative on failure |
| 2333 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2334 | int e1000e_setup_tx_resources(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2335 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2336 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2337 | int err = -ENOMEM, size; |
| 2338 | |
| 2339 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2340 | tx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2341 | if (!tx_ring->buffer_info) |
| 2342 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2343 | |
| 2344 | /* round up to nearest 4K */ |
| 2345 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
| 2346 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2347 | |
| 2348 | err = e1000_alloc_ring_dma(adapter, tx_ring); |
| 2349 | if (err) |
| 2350 | goto err; |
| 2351 | |
| 2352 | tx_ring->next_to_use = 0; |
| 2353 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2354 | |
| 2355 | return 0; |
| 2356 | err: |
| 2357 | vfree(tx_ring->buffer_info); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 2358 | e_err("Unable to allocate memory for the transmit descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2359 | return err; |
| 2360 | } |
| 2361 | |
| 2362 | /** |
| 2363 | * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2364 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2365 | * |
| 2366 | * Returns 0 on success, negative on failure |
| 2367 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2368 | int e1000e_setup_rx_resources(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2369 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2370 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2371 | struct e1000_buffer *buffer_info; |
| 2372 | int i, size, desc_len, err = -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2373 | |
| 2374 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2375 | rx_ring->buffer_info = vzalloc(size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2376 | if (!rx_ring->buffer_info) |
| 2377 | goto err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2378 | |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2379 | for (i = 0; i < rx_ring->count; i++) { |
| 2380 | buffer_info = &rx_ring->buffer_info[i]; |
| 2381 | buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, |
| 2382 | sizeof(struct e1000_ps_page), |
| 2383 | GFP_KERNEL); |
| 2384 | if (!buffer_info->ps_pages) |
| 2385 | goto err_pages; |
| 2386 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2387 | |
| 2388 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 2389 | |
| 2390 | /* Round up to nearest 4K */ |
| 2391 | rx_ring->size = rx_ring->count * desc_len; |
| 2392 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2393 | |
| 2394 | err = e1000_alloc_ring_dma(adapter, rx_ring); |
| 2395 | if (err) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2396 | goto err_pages; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2397 | |
| 2398 | rx_ring->next_to_clean = 0; |
| 2399 | rx_ring->next_to_use = 0; |
| 2400 | rx_ring->rx_skb_top = NULL; |
| 2401 | |
| 2402 | return 0; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2403 | |
| 2404 | err_pages: |
| 2405 | for (i = 0; i < rx_ring->count; i++) { |
| 2406 | buffer_info = &rx_ring->buffer_info[i]; |
| 2407 | kfree(buffer_info->ps_pages); |
| 2408 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2409 | err: |
| 2410 | vfree(rx_ring->buffer_info); |
Bruce Allan | e926244 | 2010-11-24 06:02:06 +0000 | [diff] [blame] | 2411 | e_err("Unable to allocate memory for the receive descriptor ring\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2412 | return err; |
| 2413 | } |
| 2414 | |
| 2415 | /** |
| 2416 | * e1000_clean_tx_ring - Free Tx Buffers |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2417 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2418 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2419 | static void e1000_clean_tx_ring(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2420 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2421 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2422 | struct e1000_buffer *buffer_info; |
| 2423 | unsigned long size; |
| 2424 | unsigned int i; |
| 2425 | |
| 2426 | for (i = 0; i < tx_ring->count; i++) { |
| 2427 | buffer_info = &tx_ring->buffer_info[i]; |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 2428 | e1000_put_txbuf(tx_ring, buffer_info, false); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 2431 | netdev_reset_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2432 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2433 | memset(tx_ring->buffer_info, 0, size); |
| 2434 | |
| 2435 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2436 | |
| 2437 | tx_ring->next_to_use = 0; |
| 2438 | tx_ring->next_to_clean = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | /** |
| 2442 | * e1000e_free_tx_resources - Free Tx Resources per Queue |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2443 | * @tx_ring: Tx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2444 | * |
| 2445 | * Free all transmit software resources |
| 2446 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2447 | void e1000e_free_tx_resources(struct e1000_ring *tx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2448 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2449 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2450 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2451 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2452 | e1000_clean_tx_ring(tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2453 | |
| 2454 | vfree(tx_ring->buffer_info); |
| 2455 | tx_ring->buffer_info = NULL; |
| 2456 | |
| 2457 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 2458 | tx_ring->dma); |
| 2459 | tx_ring->desc = NULL; |
| 2460 | } |
| 2461 | |
| 2462 | /** |
| 2463 | * e1000e_free_rx_resources - Free Rx Resources |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2464 | * @rx_ring: Rx descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2465 | * |
| 2466 | * Free all receive software resources |
| 2467 | **/ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2468 | void e1000e_free_rx_resources(struct e1000_ring *rx_ring) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2469 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2470 | struct e1000_adapter *adapter = rx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2471 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2472 | int i; |
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 | e1000_clean_rx_ring(rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2475 | |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2476 | for (i = 0; i < rx_ring->count; i++) |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2477 | kfree(rx_ring->buffer_info[i].ps_pages); |
Auke Kok | 47f44e4 | 2007-10-25 13:57:44 -0700 | [diff] [blame] | 2478 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2479 | vfree(rx_ring->buffer_info); |
| 2480 | rx_ring->buffer_info = NULL; |
| 2481 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2482 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 2483 | rx_ring->dma); |
| 2484 | rx_ring->desc = NULL; |
| 2485 | } |
| 2486 | |
| 2487 | /** |
| 2488 | * e1000_update_itr - update the dynamic ITR value based on statistics |
Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2489 | * @itr_setting: current adapter->itr |
| 2490 | * @packets: the number of packets during this measurement interval |
| 2491 | * @bytes: the number of bytes during this measurement interval |
| 2492 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2493 | * Stores a new ITR value based on packets and byte |
| 2494 | * counts during the last interrupt. The advantage of per interrupt |
| 2495 | * computation is faster updates and more accurate ITR for the current |
| 2496 | * traffic pattern. Constants in this function were computed |
| 2497 | * based on theoretical maximum wire speed and thresholds were set based |
| 2498 | * on testing data as well as attempting to minimize response time |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2499 | * while increasing bulk throughput. This functionality is controlled |
| 2500 | * by the InterruptThrottleRate module parameter. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2501 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2502 | 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] | 2503 | { |
| 2504 | unsigned int retval = itr_setting; |
| 2505 | |
| 2506 | if (packets == 0) |
Bruce Allan | 5015e53 | 2012-02-08 02:55:56 +0000 | [diff] [blame] | 2507 | return itr_setting; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2508 | |
| 2509 | switch (itr_setting) { |
| 2510 | case lowest_latency: |
| 2511 | /* handle TSO and jumbo frames */ |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2512 | if (bytes / packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2513 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2514 | else if ((packets < 5) && (bytes > 512)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2515 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2516 | break; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 2517 | case low_latency: /* 50 usec aka 20000 ints/s */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2518 | if (bytes > 10000) { |
| 2519 | /* this if handles the TSO accounting */ |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2520 | if (bytes / packets > 8000) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2521 | retval = bulk_latency; |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2522 | else if ((packets < 10) || ((bytes / packets) > 1200)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2523 | retval = bulk_latency; |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2524 | else if ((packets > 35)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2525 | retval = lowest_latency; |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 2526 | } else if (bytes / packets > 2000) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2527 | retval = bulk_latency; |
| 2528 | } else if (packets <= 2 && bytes < 512) { |
| 2529 | retval = lowest_latency; |
| 2530 | } |
| 2531 | break; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 2532 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2533 | if (bytes > 25000) { |
Bruce Allan | b1cdfea | 2010-12-11 05:53:47 +0000 | [diff] [blame] | 2534 | if (packets > 35) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2535 | retval = low_latency; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2536 | } else if (bytes < 6000) { |
| 2537 | retval = low_latency; |
| 2538 | } |
| 2539 | break; |
| 2540 | } |
| 2541 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2542 | return retval; |
| 2543 | } |
| 2544 | |
| 2545 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2546 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2547 | u16 current_itr; |
| 2548 | u32 new_itr = adapter->itr; |
| 2549 | |
| 2550 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2551 | if (adapter->link_speed != SPEED_1000) { |
| 2552 | current_itr = 0; |
| 2553 | new_itr = 4000; |
| 2554 | goto set_itr_now; |
| 2555 | } |
| 2556 | |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 2557 | if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 2558 | new_itr = 0; |
| 2559 | goto set_itr_now; |
| 2560 | } |
| 2561 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2562 | adapter->tx_itr = e1000_update_itr(adapter->tx_itr, |
| 2563 | adapter->total_tx_packets, |
| 2564 | adapter->total_tx_bytes); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2565 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2566 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2567 | adapter->tx_itr = low_latency; |
| 2568 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2569 | adapter->rx_itr = e1000_update_itr(adapter->rx_itr, |
| 2570 | adapter->total_rx_packets, |
| 2571 | adapter->total_rx_bytes); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2572 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2573 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2574 | adapter->rx_itr = low_latency; |
| 2575 | |
| 2576 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2577 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2578 | /* counts and packets in update_itr are dependent on these numbers */ |
Bruce Allan | 33550ce | 2013-02-20 04:06:16 +0000 | [diff] [blame] | 2579 | switch (current_itr) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2580 | case lowest_latency: |
| 2581 | new_itr = 70000; |
| 2582 | break; |
| 2583 | case low_latency: |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 2584 | new_itr = 20000; /* aka hwitr = ~200 */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2585 | break; |
| 2586 | case bulk_latency: |
| 2587 | new_itr = 4000; |
| 2588 | break; |
| 2589 | default: |
| 2590 | break; |
| 2591 | } |
| 2592 | |
| 2593 | set_itr_now: |
| 2594 | if (new_itr != adapter->itr) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2595 | /* this attempts to bias the interrupt rate towards Bulk |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2596 | * by adding intermediate steps when interrupt rate is |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2597 | * increasing |
| 2598 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2599 | new_itr = new_itr > adapter->itr ? |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 2600 | min(adapter->itr + (new_itr >> 2), new_itr) : new_itr; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2601 | adapter->itr = new_itr; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2602 | adapter->rx_ring->itr_val = new_itr; |
| 2603 | if (adapter->msix_entries) |
| 2604 | adapter->rx_ring->set_itr = 1; |
| 2605 | else |
Bruce Allan | e3d14b0 | 2012-12-05 06:26:51 +0000 | [diff] [blame] | 2606 | e1000e_write_itr(adapter, new_itr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | /** |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 2611 | * e1000e_write_itr - write the ITR value to the appropriate registers |
| 2612 | * @adapter: address of board private structure |
| 2613 | * @itr: new ITR value to program |
| 2614 | * |
| 2615 | * e1000e_write_itr determines if the adapter is in MSI-X mode |
| 2616 | * and, if so, writes the EITR registers with the ITR value. |
| 2617 | * Otherwise, it writes the ITR value into the ITR register. |
| 2618 | **/ |
| 2619 | void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr) |
| 2620 | { |
| 2621 | struct e1000_hw *hw = &adapter->hw; |
| 2622 | u32 new_itr = itr ? 1000000000 / (itr * 256) : 0; |
| 2623 | |
| 2624 | if (adapter->msix_entries) { |
| 2625 | int vector; |
| 2626 | |
| 2627 | for (vector = 0; vector < adapter->num_vectors; vector++) |
| 2628 | writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector)); |
| 2629 | } else { |
| 2630 | ew32(ITR, new_itr); |
| 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | /** |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2635 | * e1000_alloc_queues - Allocate memory for all rings |
| 2636 | * @adapter: board private structure to initialize |
| 2637 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 2638 | static int e1000_alloc_queues(struct e1000_adapter *adapter) |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2639 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2640 | int size = sizeof(struct e1000_ring); |
| 2641 | |
| 2642 | adapter->tx_ring = kzalloc(size, GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2643 | if (!adapter->tx_ring) |
| 2644 | goto err; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2645 | adapter->tx_ring->count = adapter->tx_ring_count; |
| 2646 | adapter->tx_ring->adapter = adapter; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2647 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2648 | adapter->rx_ring = kzalloc(size, GFP_KERNEL); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2649 | if (!adapter->rx_ring) |
| 2650 | goto err; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 2651 | adapter->rx_ring->count = adapter->rx_ring_count; |
| 2652 | adapter->rx_ring->adapter = adapter; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2653 | |
| 2654 | return 0; |
| 2655 | err: |
| 2656 | e_err("Unable to allocate memory for queues\n"); |
| 2657 | kfree(adapter->rx_ring); |
| 2658 | kfree(adapter->tx_ring); |
| 2659 | return -ENOMEM; |
| 2660 | } |
| 2661 | |
| 2662 | /** |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2663 | * e1000e_poll - NAPI Rx polling callback |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2664 | * @napi: struct associated with this polling callback |
Jesse Brandeburg | 0bcd952 | 2018-11-08 14:55:32 -0800 | [diff] [blame] | 2665 | * @budget: number of packets driver is allowed to process this poll |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2666 | **/ |
Jesse Brandeburg | 0bcd952 | 2018-11-08 14:55:32 -0800 | [diff] [blame] | 2667 | static int e1000e_poll(struct napi_struct *napi, int budget) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2668 | { |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2669 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, |
| 2670 | napi); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2671 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2672 | struct net_device *poll_dev = adapter->netdev; |
Andy Gospodarek | 679e8a0 | 2009-06-18 11:57:37 +0000 | [diff] [blame] | 2673 | int tx_cleaned = 1, work_done = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2674 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 2675 | adapter = netdev_priv(poll_dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2676 | |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 2677 | if (!adapter->msix_entries || |
| 2678 | (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) |
| 2679 | tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2680 | |
Jesse Brandeburg | 0bcd952 | 2018-11-08 14:55:32 -0800 | [diff] [blame] | 2681 | adapter->clean_rx(adapter->rx_ring, &work_done, budget); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2682 | |
Jesse Brandeburg | 0bcd952 | 2018-11-08 14:55:32 -0800 | [diff] [blame] | 2683 | if (!tx_cleaned || work_done == budget) |
| 2684 | return budget; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2685 | |
Jesse Brandeburg | 0bcd952 | 2018-11-08 14:55:32 -0800 | [diff] [blame] | 2686 | /* Exit the polling mode, but don't re-enable interrupts if stack might |
| 2687 | * poll us due to busy-polling |
| 2688 | */ |
| 2689 | if (likely(napi_complete_done(napi, work_done))) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2690 | if (adapter->itr_setting & 3) |
| 2691 | e1000_set_itr(adapter); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 2692 | if (!test_bit(__E1000_DOWN, &adapter->state)) { |
| 2693 | if (adapter->msix_entries) |
Benjamin Poirier | 1f0ea19 | 2018-02-08 15:47:12 +0900 | [diff] [blame] | 2694 | ew32(IMS, adapter->rx_ring->ims_val); |
Jesse Brandeburg | a3c69fe | 2009-03-25 22:05:41 +0000 | [diff] [blame] | 2695 | else |
| 2696 | e1000_irq_enable(adapter); |
| 2697 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | return work_done; |
| 2701 | } |
| 2702 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2703 | static int e1000_vlan_rx_add_vid(struct net_device *netdev, |
Bruce Allan | 603cdca | 2013-05-01 03:48:11 +0000 | [diff] [blame] | 2704 | __always_unused __be16 proto, u16 vid) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2705 | { |
| 2706 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2707 | struct e1000_hw *hw = &adapter->hw; |
| 2708 | u32 vfta, index; |
| 2709 | |
| 2710 | /* don't update vlan cookie if already programmed */ |
| 2711 | if ((adapter->hw.mng_cookie.status & |
| 2712 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2713 | (vid == adapter->mng_vlan_id)) |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2714 | return 0; |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2715 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2716 | /* add VID to filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2717 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2718 | index = (vid >> 5) & 0x7F; |
| 2719 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 2720 | vfta |= BIT((vid & 0x1F)); |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2721 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2722 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2723 | |
| 2724 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2725 | |
| 2726 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2729 | static int e1000_vlan_rx_kill_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 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2736 | if ((adapter->hw.mng_cookie.status & |
| 2737 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 2738 | (vid == adapter->mng_vlan_id)) { |
| 2739 | /* release control to f/w */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 2740 | e1000e_release_hw_control(adapter); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2741 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | /* remove VID from filter table */ |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2745 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2746 | index = (vid >> 5) & 0x7F; |
| 2747 | vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 2748 | vfta &= ~BIT((vid & 0x1F)); |
Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 2749 | hw->mac.ops.write_vfta(hw, index, vfta); |
| 2750 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2751 | |
| 2752 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 2753 | |
| 2754 | return 0; |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | /** |
| 2758 | * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering |
| 2759 | * @adapter: board private structure to initialize |
| 2760 | **/ |
| 2761 | static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter) |
| 2762 | { |
| 2763 | struct net_device *netdev = adapter->netdev; |
| 2764 | struct e1000_hw *hw = &adapter->hw; |
| 2765 | u32 rctl; |
| 2766 | |
| 2767 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2768 | /* disable VLAN receive filtering */ |
| 2769 | rctl = er32(RCTL); |
| 2770 | rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN); |
| 2771 | ew32(RCTL, rctl); |
| 2772 | |
| 2773 | if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2774 | e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), |
| 2775 | adapter->mng_vlan_id); |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2776 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 2777 | } |
| 2778 | } |
| 2779 | } |
| 2780 | |
| 2781 | /** |
| 2782 | * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering |
| 2783 | * @adapter: board private structure to initialize |
| 2784 | **/ |
| 2785 | static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter) |
| 2786 | { |
| 2787 | struct e1000_hw *hw = &adapter->hw; |
| 2788 | u32 rctl; |
| 2789 | |
| 2790 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { |
| 2791 | /* enable VLAN receive filtering */ |
| 2792 | rctl = er32(RCTL); |
| 2793 | rctl |= E1000_RCTL_VFE; |
| 2794 | rctl &= ~E1000_RCTL_CFIEN; |
| 2795 | ew32(RCTL, rctl); |
| 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | /** |
Jarod Wilson | 889ad45 | 2016-06-28 20:41:31 -0700 | [diff] [blame] | 2800 | * e1000e_vlan_strip_disable - helper to disable HW VLAN stripping |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2801 | * @adapter: board private structure to initialize |
| 2802 | **/ |
| 2803 | static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter) |
| 2804 | { |
| 2805 | struct e1000_hw *hw = &adapter->hw; |
| 2806 | u32 ctrl; |
| 2807 | |
| 2808 | /* disable VLAN tag insert/strip */ |
| 2809 | ctrl = er32(CTRL); |
| 2810 | ctrl &= ~E1000_CTRL_VME; |
| 2811 | ew32(CTRL, ctrl); |
| 2812 | } |
| 2813 | |
| 2814 | /** |
| 2815 | * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping |
| 2816 | * @adapter: board private structure to initialize |
| 2817 | **/ |
| 2818 | static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter) |
| 2819 | { |
| 2820 | struct e1000_hw *hw = &adapter->hw; |
| 2821 | u32 ctrl; |
| 2822 | |
| 2823 | /* enable VLAN tag insert/strip */ |
| 2824 | ctrl = er32(CTRL); |
| 2825 | ctrl |= E1000_CTRL_VME; |
| 2826 | ew32(CTRL, ctrl); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 2830 | { |
| 2831 | struct net_device *netdev = adapter->netdev; |
| 2832 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 2833 | u16 old_vid = adapter->mng_vlan_id; |
| 2834 | |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 2835 | if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2836 | e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2837 | adapter->mng_vlan_id = vid; |
| 2838 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2839 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2840 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid)) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2841 | e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2842 | } |
| 2843 | |
| 2844 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
| 2845 | { |
| 2846 | u16 vid; |
| 2847 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2848 | e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2849 | |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 2850 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 2851 | e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2854 | static void e1000_init_manageability_pt(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2855 | { |
| 2856 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2857 | u32 manc, manc2h, mdef, i, j; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2858 | |
| 2859 | if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) |
| 2860 | return; |
| 2861 | |
| 2862 | manc = er32(MANC); |
| 2863 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2864 | /* enable receiving management packets to the host. this will probably |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2865 | * generate destination unreachable messages from the host OS, but |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2866 | * the packets will be handled on SMBUS |
| 2867 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2868 | manc |= E1000_MANC_EN_MNG2HOST; |
| 2869 | manc2h = er32(MANC2H); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2870 | |
| 2871 | switch (hw->mac.type) { |
| 2872 | default: |
| 2873 | manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664); |
| 2874 | break; |
| 2875 | case e1000_82574: |
| 2876 | case e1000_82583: |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2877 | /* Check if IPMI pass-through decision filter already exists; |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2878 | * if so, enable it. |
| 2879 | */ |
| 2880 | for (i = 0, j = 0; i < 8; i++) { |
| 2881 | mdef = er32(MDEF(i)); |
| 2882 | |
| 2883 | /* Ignore filters with anything other than IPMI ports */ |
Dan Carpenter | 3b21b50 | 2010-06-02 13:43:15 +0000 | [diff] [blame] | 2884 | if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2885 | continue; |
| 2886 | |
| 2887 | /* Enable this decision filter in MANC2H */ |
| 2888 | if (mdef) |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 2889 | manc2h |= BIT(i); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2890 | |
| 2891 | j |= mdef; |
| 2892 | } |
| 2893 | |
| 2894 | if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) |
| 2895 | break; |
| 2896 | |
| 2897 | /* Create new decision filter in an empty filter */ |
| 2898 | for (i = 0, j = 0; i < 8; i++) |
| 2899 | if (er32(MDEF(i)) == 0) { |
| 2900 | ew32(MDEF(i), (E1000_MDEF_PORT_623 | |
| 2901 | E1000_MDEF_PORT_664)); |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 2902 | manc2h |= BIT(1); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 2903 | j++; |
| 2904 | break; |
| 2905 | } |
| 2906 | |
| 2907 | if (!j) |
| 2908 | e_warn("Unable to create IPMI pass-through filter\n"); |
| 2909 | break; |
| 2910 | } |
| 2911 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2912 | ew32(MANC2H, manc2h); |
| 2913 | ew32(MANC, manc); |
| 2914 | } |
| 2915 | |
| 2916 | /** |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2917 | * e1000_configure_tx - Configure Transmit Unit after Reset |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2918 | * @adapter: board private structure |
| 2919 | * |
| 2920 | * Configure the Tx unit of the MAC after a reset. |
| 2921 | **/ |
| 2922 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
| 2923 | { |
| 2924 | struct e1000_hw *hw = &adapter->hw; |
| 2925 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 2926 | u64 tdba; |
David Ertman | e7e834a | 2014-01-13 23:19:27 +0000 | [diff] [blame] | 2927 | u32 tdlen, tctl, tarc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2928 | |
| 2929 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 2930 | tdba = tx_ring->dma; |
| 2931 | tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 2932 | ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32))); |
| 2933 | ew32(TDBAH(0), (tdba >> 32)); |
| 2934 | ew32(TDLEN(0), tdlen); |
| 2935 | ew32(TDH(0), 0); |
| 2936 | ew32(TDT(0), 0); |
| 2937 | tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0); |
| 2938 | tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2939 | |
Jia-Ju Bai | 0845d45 | 2015-08-05 18:16:10 +0800 | [diff] [blame] | 2940 | writel(0, tx_ring->head); |
| 2941 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 2942 | e1000e_update_tdt_wa(tx_ring, 0); |
| 2943 | else |
| 2944 | writel(0, tx_ring->tail); |
| 2945 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2946 | /* Set the Tx Interrupt Delay register */ |
| 2947 | ew32(TIDV, adapter->tx_int_delay); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2948 | /* Tx irq moderation */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2949 | ew32(TADV, adapter->tx_abs_int_delay); |
| 2950 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2951 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
| 2952 | u32 txdctl = er32(TXDCTL(0)); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 2953 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2954 | txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH | |
| 2955 | E1000_TXDCTL_WTHRESH); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2956 | /* set up some performance related parameters to encourage the |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2957 | * hardware to use the bus more efficiently in bursts, depends |
| 2958 | * on the tx_int_delay to be enabled, |
Hiroaki SHIMODA | 8edc0e6 | 2012-10-10 15:34:20 +0000 | [diff] [blame] | 2959 | * wthresh = 1 ==> burst write is disabled to avoid Tx stalls |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2960 | * hthresh = 1 ==> prefetch when one or more available |
| 2961 | * pthresh = 0x1f ==> prefetch if internal cache 31 or less |
| 2962 | * BEWARE: this seems to work but should be considered first if |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 2963 | * there are Tx hangs or other Tx related bugs |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2964 | */ |
| 2965 | txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE; |
| 2966 | ew32(TXDCTL(0), txdctl); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2967 | } |
Bruce Allan | 56032be | 2011-12-16 00:46:01 +0000 | [diff] [blame] | 2968 | /* erratum work around: set txdctl the same for both queues */ |
| 2969 | ew32(TXDCTL(1), er32(TXDCTL(0))); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 2970 | |
David Ertman | e7e834a | 2014-01-13 23:19:27 +0000 | [diff] [blame] | 2971 | /* Program the Transmit Control Register */ |
| 2972 | tctl = er32(TCTL); |
| 2973 | tctl &= ~E1000_TCTL_CT; |
| 2974 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
| 2975 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 2976 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2977 | if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2978 | tarc = er32(TARC(0)); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 2979 | /* 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] | 2980 | * gigabit link later |
| 2981 | */ |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 2982 | #define SPEED_MODE_BIT BIT(21) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2983 | tarc |= SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2984 | ew32(TARC(0), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | /* errata: program both queues to unweighted RR */ |
| 2988 | if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2989 | tarc = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2990 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2991 | ew32(TARC(0), tarc); |
| 2992 | tarc = er32(TARC(1)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2993 | tarc |= 1; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 2994 | ew32(TARC(1), tarc); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2995 | } |
| 2996 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2997 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 2998 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 2999 | |
| 3000 | /* only set IDE if we are delaying interrupts using the timers */ |
| 3001 | if (adapter->tx_int_delay) |
| 3002 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
| 3003 | |
| 3004 | /* enable Report Status bit */ |
| 3005 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 3006 | |
David Ertman | e7e834a | 2014-01-13 23:19:27 +0000 | [diff] [blame] | 3007 | ew32(TCTL, tctl); |
| 3008 | |
Bruce Allan | 57cde76 | 2012-02-22 09:02:58 +0000 | [diff] [blame] | 3009 | hw->mac.ops.config_collision_dist(hw); |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 3010 | |
Sasha Neftin | b10effb | 2017-08-06 16:49:18 +0300 | [diff] [blame] | 3011 | /* SPT and KBL Si errata workaround to avoid data corruption */ |
| 3012 | if (hw->mac.type == e1000_pch_spt) { |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 3013 | u32 reg_val; |
| 3014 | |
| 3015 | reg_val = er32(IOSFPC); |
| 3016 | reg_val |= E1000_RCTL_RDMTS_HEX; |
| 3017 | ew32(IOSFPC, reg_val); |
| 3018 | |
| 3019 | reg_val = er32(TARC(0)); |
Sasha Neftin | c0f4b16 | 2017-11-06 08:31:59 +0200 | [diff] [blame] | 3020 | /* SPT and KBL Si errata workaround to avoid Tx hang. |
| 3021 | * Dropping the number of outstanding requests from |
| 3022 | * 3 to 2 in order to avoid a buffer overrun. |
| 3023 | */ |
| 3024 | reg_val &= ~E1000_TARC0_CB_MULTIQ_3_REQ; |
| 3025 | reg_val |= E1000_TARC0_CB_MULTIQ_2_REQ; |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 3026 | ew32(TARC(0), reg_val); |
| 3027 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3028 | } |
| 3029 | |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 3030 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 3031 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
| 3032 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3033 | /** |
| 3034 | * e1000_setup_rctl - configure the receive control registers |
| 3035 | * @adapter: Board private structure |
| 3036 | **/ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3037 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
| 3038 | { |
| 3039 | struct e1000_hw *hw = &adapter->hw; |
| 3040 | u32 rctl, rfctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3041 | u32 pages = 0; |
| 3042 | |
David Ertman | b20a774 | 2014-03-25 04:27:55 +0000 | [diff] [blame] | 3043 | /* Workaround Si errata on PCHx - configure jumbo frame flow. |
| 3044 | * If jumbo frames not set, program related MAC/PHY registers |
| 3045 | * to h/w defaults |
| 3046 | */ |
| 3047 | if (hw->mac.type >= e1000_pch2lan) { |
| 3048 | s32 ret_val; |
| 3049 | |
| 3050 | if (adapter->netdev->mtu > ETH_DATA_LEN) |
| 3051 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true); |
| 3052 | else |
| 3053 | ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false); |
| 3054 | |
| 3055 | if (ret_val) |
| 3056 | e_dbg("failed to enable|disable jumbo frame workaround mode\n"); |
| 3057 | } |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 3058 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3059 | /* Program MC offset vector base */ |
| 3060 | rctl = er32(RCTL); |
| 3061 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 3062 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 3063 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 3064 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3065 | |
| 3066 | /* Do not Store bad packets */ |
| 3067 | rctl &= ~E1000_RCTL_SBP; |
| 3068 | |
| 3069 | /* Enable Long Packet receive */ |
| 3070 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 3071 | rctl &= ~E1000_RCTL_LPE; |
| 3072 | else |
| 3073 | rctl |= E1000_RCTL_LPE; |
| 3074 | |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 3075 | /* Some systems expect that the CRC is included in SMBUS traffic. The |
| 3076 | * hardware strips the CRC before sending to both SMBUS (BMC) and to |
| 3077 | * host memory when this is enabled |
| 3078 | */ |
| 3079 | if (adapter->flags2 & FLAG2_CRC_STRIPPING) |
| 3080 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 5918bd8 | 2008-02-12 15:20:24 -0800 | [diff] [blame] | 3081 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3082 | /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ |
| 3083 | if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { |
| 3084 | u16 phy_data; |
| 3085 | |
| 3086 | e1e_rphy(hw, PHY_REG(770, 26), &phy_data); |
| 3087 | phy_data &= 0xfff8; |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 3088 | phy_data |= BIT(2); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3089 | e1e_wphy(hw, PHY_REG(770, 26), phy_data); |
| 3090 | |
| 3091 | e1e_rphy(hw, 22, &phy_data); |
| 3092 | phy_data &= 0x0fff; |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 3093 | phy_data |= BIT(14); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 3094 | e1e_wphy(hw, 0x10, 0x2823); |
| 3095 | e1e_wphy(hw, 0x11, 0x0003); |
| 3096 | e1e_wphy(hw, 22, phy_data); |
| 3097 | } |
| 3098 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3099 | /* Setup buffer sizes */ |
| 3100 | rctl &= ~E1000_RCTL_SZ_4096; |
| 3101 | rctl |= E1000_RCTL_BSEX; |
| 3102 | switch (adapter->rx_buffer_len) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3103 | case 2048: |
| 3104 | default: |
| 3105 | rctl |= E1000_RCTL_SZ_2048; |
| 3106 | rctl &= ~E1000_RCTL_BSEX; |
| 3107 | break; |
| 3108 | case 4096: |
| 3109 | rctl |= E1000_RCTL_SZ_4096; |
| 3110 | break; |
| 3111 | case 8192: |
| 3112 | rctl |= E1000_RCTL_SZ_8192; |
| 3113 | break; |
| 3114 | case 16384: |
| 3115 | rctl |= E1000_RCTL_SZ_16384; |
| 3116 | break; |
| 3117 | } |
| 3118 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3119 | /* Enable Extended Status in all Receive Descriptors */ |
| 3120 | rfctl = er32(RFCTL); |
| 3121 | rfctl |= E1000_RFCTL_EXTEN; |
Matthew Vick | f6bd557 | 2012-04-25 08:01:05 +0000 | [diff] [blame] | 3122 | ew32(RFCTL, rfctl); |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3123 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3124 | /* 82571 and greater support packet-split where the protocol |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3125 | * header is placed in skb->data and the packet data is |
| 3126 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 3127 | * In the case of a non-split, skb->data is linearly filled, |
| 3128 | * followed by the page buffers. Therefore, skb->data is |
| 3129 | * sized to hold the largest protocol header. |
| 3130 | * |
| 3131 | * allocations using alloc_page take too long for regular MTU |
| 3132 | * so only enable packet split for jumbo frames |
| 3133 | * |
| 3134 | * Using pages when the page size is greater than 16k wastes |
| 3135 | * a lot of memory, since we allocate 3 pages at all times |
| 3136 | * per packet. |
| 3137 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3138 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 3139 | if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3140 | adapter->rx_ps_pages = pages; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3141 | else |
| 3142 | adapter->rx_ps_pages = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3143 | |
| 3144 | if (adapter->rx_ps_pages) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 3145 | u32 psrctl = 0; |
| 3146 | |
Auke Kok | 140a748 | 2007-10-25 13:57:58 -0700 | [diff] [blame] | 3147 | /* Enable Packet split descriptors */ |
| 3148 | rctl |= E1000_RCTL_DTYP_PS; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3149 | |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 3150 | psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3151 | |
| 3152 | switch (adapter->rx_ps_pages) { |
| 3153 | case 3: |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 3154 | psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT; |
Jeff Kirsher | 5463fce6 | 2020-06-03 20:07:26 -0700 | [diff] [blame] | 3155 | fallthrough; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3156 | case 2: |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 3157 | psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT; |
Jeff Kirsher | 5463fce6 | 2020-06-03 20:07:26 -0700 | [diff] [blame] | 3158 | fallthrough; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3159 | case 1: |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 3160 | psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3161 | break; |
| 3162 | } |
| 3163 | |
| 3164 | ew32(PSRCTL, psrctl); |
| 3165 | } |
| 3166 | |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 3167 | /* This is useful for sniffing bad packets. */ |
| 3168 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 3169 | /* UPE and MPE will be handled by normal PROMISC logic |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3170 | * in e1000e_set_rx_mode |
| 3171 | */ |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 3172 | rctl |= (E1000_RCTL_SBP | /* Receive bad packets */ |
| 3173 | E1000_RCTL_BAM | /* RX All Bcast Pkts */ |
| 3174 | E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */ |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 3175 | |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 3176 | rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */ |
| 3177 | E1000_RCTL_DPF | /* Allow filtered pause */ |
| 3178 | E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */ |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 3179 | /* Do not mess with E1000_CTRL_VME, it affects transmit as well, |
| 3180 | * and that breaks VLANs. |
| 3181 | */ |
| 3182 | } |
| 3183 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3184 | ew32(RCTL, rctl); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3185 | /* just started the receive unit, no need to restart */ |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 3186 | adapter->flags &= ~FLAG_RESTART_NOW; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | /** |
| 3190 | * e1000_configure_rx - Configure Receive Unit after Reset |
| 3191 | * @adapter: board private structure |
| 3192 | * |
| 3193 | * Configure the Rx unit of the MAC after a reset. |
| 3194 | **/ |
| 3195 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
| 3196 | { |
| 3197 | struct e1000_hw *hw = &adapter->hw; |
| 3198 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 3199 | u64 rdba; |
| 3200 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
| 3201 | |
| 3202 | if (adapter->rx_ps_pages) { |
| 3203 | /* this is a 32 byte descriptor */ |
| 3204 | rdlen = rx_ring->count * |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 3205 | sizeof(union e1000_rx_desc_packet_split); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3206 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 3207 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3208 | } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3209 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3210 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 3211 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3212 | } else { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 3213 | rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3214 | adapter->clean_rx = e1000_clean_rx_irq; |
| 3215 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 3216 | } |
| 3217 | |
| 3218 | /* disable receives while setting up the descriptors */ |
| 3219 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 3220 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 3221 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3222 | e1e_flush(); |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 3223 | usleep_range(10000, 11000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3224 | |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3225 | if (adapter->flags2 & FLAG2_DMA_BURST) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3226 | /* set the writeback threshold (only takes effect if the RDTR |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3227 | * 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] | 3228 | * enable prefetching of 0x20 Rx descriptors |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3229 | * granularity = 01 |
| 3230 | * wthresh = 04, |
| 3231 | * hthresh = 04, |
| 3232 | * pthresh = 0x20 |
| 3233 | */ |
| 3234 | ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE); |
| 3235 | ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE); |
Jesse Brandeburg | 3a3b758 | 2010-09-29 21:38:49 +0000 | [diff] [blame] | 3236 | } |
| 3237 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3238 | /* set the Receive Delay Timer Register */ |
| 3239 | ew32(RDTR, adapter->rx_int_delay); |
| 3240 | |
| 3241 | /* irq moderation */ |
| 3242 | ew32(RADV, adapter->rx_abs_int_delay); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 3243 | if ((adapter->itr_setting != 0) && (adapter->itr != 0)) |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 3244 | e1000e_write_itr(adapter, adapter->itr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3245 | |
| 3246 | ctrl_ext = er32(CTRL_EXT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3247 | /* Auto-Mask interrupts upon ICR access */ |
| 3248 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 3249 | ew32(IAM, 0xffffffff); |
| 3250 | ew32(CTRL_EXT, ctrl_ext); |
| 3251 | e1e_flush(); |
| 3252 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3253 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3254 | * the Base and Length of the Rx Descriptor Ring |
| 3255 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3256 | rdba = rx_ring->dma; |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 3257 | ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32))); |
| 3258 | ew32(RDBAH(0), (rdba >> 32)); |
| 3259 | ew32(RDLEN(0), rdlen); |
| 3260 | ew32(RDH(0), 0); |
| 3261 | ew32(RDT(0), 0); |
| 3262 | rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0); |
| 3263 | rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3264 | |
Jia-Ju Bai | 0845d45 | 2015-08-05 18:16:10 +0800 | [diff] [blame] | 3265 | writel(0, rx_ring->head); |
| 3266 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 3267 | e1000e_update_rdt_wa(rx_ring, 0); |
| 3268 | else |
| 3269 | writel(0, rx_ring->tail); |
| 3270 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3271 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 3272 | rxcsum = er32(RXCSUM); |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 3273 | if (adapter->netdev->features & NETIF_F_RXCSUM) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3274 | rxcsum |= E1000_RXCSUM_TUOFL; |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 3275 | else |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3276 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3277 | ew32(RXCSUM, rxcsum); |
| 3278 | |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 3279 | /* With jumbo frames, excessive C-state transition latencies result |
| 3280 | * in dropped transactions. |
| 3281 | */ |
| 3282 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 3283 | u32 lat = |
| 3284 | ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 - |
| 3285 | adapter->max_frame_size) * 8 / 1000; |
| 3286 | |
| 3287 | if (adapter->flags & FLAG_IS_ICH) { |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3288 | u32 rxdctl = er32(RXDCTL(0)); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 3289 | |
Matt Turner | b701cac | 2017-11-07 14:13:30 -0800 | [diff] [blame] | 3290 | ew32(RXDCTL(0), rxdctl | 0x3 | BIT(8)); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 3291 | } |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 3292 | |
Matt Turner | 8299b00 | 2017-11-14 15:51:33 -0800 | [diff] [blame] | 3293 | dev_info(&adapter->pdev->dev, |
| 3294 | "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] | 3295 | cpu_latency_qos_update_request(&adapter->pm_qos_req, lat); |
Bruce Allan | 3e35d99 | 2013-01-12 07:25:22 +0000 | [diff] [blame] | 3296 | } else { |
Rafael J. Wysocki | 81e95ad | 2020-02-12 00:24:36 +0100 | [diff] [blame] | 3297 | cpu_latency_qos_update_request(&adapter->pm_qos_req, |
| 3298 | PM_QOS_DEFAULT_VALUE); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 3299 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3300 | |
| 3301 | /* Enable Receives */ |
| 3302 | ew32(RCTL, rctl); |
| 3303 | } |
| 3304 | |
| 3305 | /** |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3306 | * e1000e_write_mc_addr_list - write multicast addresses to MTA |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3307 | * @netdev: network interface device structure |
| 3308 | * |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3309 | * Writes multicast address list to the MTA hash table. |
| 3310 | * Returns: -ENOMEM on failure |
| 3311 | * 0 on no addresses written |
| 3312 | * X on writing X addresses to MTA |
| 3313 | */ |
| 3314 | static int e1000e_write_mc_addr_list(struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3315 | { |
| 3316 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3317 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3318 | struct netdev_hw_addr *ha; |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3319 | u8 *mta_list; |
| 3320 | int i; |
| 3321 | |
| 3322 | if (netdev_mc_empty(netdev)) { |
| 3323 | /* nothing to program, so clear mc list */ |
| 3324 | hw->mac.ops.update_mc_addr_list(hw, NULL, 0); |
| 3325 | return 0; |
| 3326 | } |
| 3327 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 3328 | mta_list = kcalloc(netdev_mc_count(netdev), ETH_ALEN, GFP_ATOMIC); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3329 | if (!mta_list) |
| 3330 | return -ENOMEM; |
| 3331 | |
| 3332 | /* update_mc_addr_list expects a packed array of only addresses. */ |
| 3333 | i = 0; |
| 3334 | netdev_for_each_mc_addr(ha, netdev) |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 3335 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3336 | |
| 3337 | hw->mac.ops.update_mc_addr_list(hw, mta_list, i); |
| 3338 | kfree(mta_list); |
| 3339 | |
| 3340 | return netdev_mc_count(netdev); |
| 3341 | } |
| 3342 | |
| 3343 | /** |
| 3344 | * e1000e_write_uc_addr_list - write unicast addresses to RAR table |
| 3345 | * @netdev: network interface device structure |
| 3346 | * |
| 3347 | * Writes unicast address list to the RAR table. |
| 3348 | * Returns: -ENOMEM on failure/insufficient address space |
| 3349 | * 0 on no addresses written |
| 3350 | * X on writing X addresses to the RAR table |
| 3351 | **/ |
| 3352 | static int e1000e_write_uc_addr_list(struct net_device *netdev) |
| 3353 | { |
| 3354 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3355 | struct e1000_hw *hw = &adapter->hw; |
David Ertman | b3e5bf1 | 2014-05-06 03:50:17 +0000 | [diff] [blame] | 3356 | unsigned int rar_entries; |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3357 | int count = 0; |
| 3358 | |
David Ertman | b3e5bf1 | 2014-05-06 03:50:17 +0000 | [diff] [blame] | 3359 | rar_entries = hw->mac.ops.rar_get_count(hw); |
| 3360 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3361 | /* save a rar entry for our hardware address */ |
| 3362 | rar_entries--; |
| 3363 | |
| 3364 | /* save a rar entry for the LAA workaround */ |
| 3365 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) |
| 3366 | rar_entries--; |
| 3367 | |
| 3368 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3369 | if (netdev_uc_count(netdev) > rar_entries) |
| 3370 | return -ENOMEM; |
| 3371 | |
| 3372 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3373 | struct netdev_hw_addr *ha; |
| 3374 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3375 | /* write the addresses in reverse order to avoid write |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3376 | * combining |
| 3377 | */ |
| 3378 | netdev_for_each_uc_addr(ha, netdev) { |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 3379 | int ret_val; |
David Ertman | b3e5bf1 | 2014-05-06 03:50:17 +0000 | [diff] [blame] | 3380 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3381 | if (!rar_entries) |
| 3382 | break; |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 3383 | ret_val = hw->mac.ops.rar_set(hw, ha->addr, rar_entries--); |
| 3384 | if (ret_val < 0) |
David Ertman | b3e5bf1 | 2014-05-06 03:50:17 +0000 | [diff] [blame] | 3385 | return -ENOMEM; |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3386 | count++; |
| 3387 | } |
| 3388 | } |
| 3389 | |
| 3390 | /* zero out the remaining RAR entries not used above */ |
| 3391 | for (; rar_entries > 0; rar_entries--) { |
| 3392 | ew32(RAH(rar_entries), 0); |
| 3393 | ew32(RAL(rar_entries), 0); |
| 3394 | } |
| 3395 | e1e_flush(); |
| 3396 | |
| 3397 | return count; |
| 3398 | } |
| 3399 | |
| 3400 | /** |
| 3401 | * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set |
| 3402 | * @netdev: network interface device structure |
| 3403 | * |
| 3404 | * The ndo_set_rx_mode entry point is called whenever the unicast or multicast |
| 3405 | * address list or the network interface flags are updated. This routine is |
| 3406 | * responsible for configuring the hardware for proper unicast, multicast, |
| 3407 | * promiscuous mode, and all-multi behavior. |
| 3408 | **/ |
| 3409 | static void e1000e_set_rx_mode(struct net_device *netdev) |
| 3410 | { |
| 3411 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3412 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3413 | u32 rctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3414 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 3415 | if (pm_runtime_suspended(netdev->dev.parent)) |
| 3416 | return; |
| 3417 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3418 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3419 | rctl = er32(RCTL); |
| 3420 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3421 | /* clear the affected bits */ |
| 3422 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 3423 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3424 | if (netdev->flags & IFF_PROMISC) { |
| 3425 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3426 | /* Do not hardware filter VLANs in promisc mode */ |
| 3427 | e1000e_vlan_filter_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3428 | } else { |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3429 | int count; |
Bruce Allan | 3d3a167 | 2012-02-23 03:13:18 +0000 | [diff] [blame] | 3430 | |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3431 | if (netdev->flags & IFF_ALLMULTI) { |
| 3432 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3433 | } else { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3434 | /* Write addresses to the MTA, if the attempt fails |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3435 | * then we should just turn on promiscuous mode so |
| 3436 | * that we can at least receive multicast traffic |
| 3437 | */ |
| 3438 | count = e1000e_write_mc_addr_list(netdev); |
| 3439 | if (count < 0) |
| 3440 | rctl |= E1000_RCTL_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3441 | } |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3442 | e1000e_vlan_filter_enable(adapter); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3443 | /* Write addresses to available RAR registers, if there is not |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3444 | * sufficient space to store all the addresses then enable |
| 3445 | * unicast promiscuous mode |
| 3446 | */ |
| 3447 | count = e1000e_write_uc_addr_list(netdev); |
| 3448 | if (count < 0) |
| 3449 | rctl |= E1000_RCTL_UPE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3450 | } |
| 3451 | |
| 3452 | ew32(RCTL, rctl); |
| 3453 | |
Jarod Wilson | 8380864 | 2016-06-09 19:50:13 -0400 | [diff] [blame] | 3454 | if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) |
Jeff Kirsher | 86d70e5 | 2011-03-25 16:01:01 +0000 | [diff] [blame] | 3455 | e1000e_vlan_strip_enable(adapter); |
| 3456 | else |
| 3457 | e1000e_vlan_strip_disable(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3458 | } |
| 3459 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3460 | static void e1000e_setup_rss_hash(struct e1000_adapter *adapter) |
| 3461 | { |
| 3462 | struct e1000_hw *hw = &adapter->hw; |
| 3463 | u32 mrqc, rxcsum; |
Eric Dumazet | 5c8d19d | 2014-11-16 06:23:11 -0800 | [diff] [blame] | 3464 | u32 rss_key[10]; |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3465 | int i; |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3466 | |
Eric Dumazet | 5c8d19d | 2014-11-16 06:23:11 -0800 | [diff] [blame] | 3467 | netdev_rss_key_fill(rss_key, sizeof(rss_key)); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3468 | for (i = 0; i < 10; i++) |
Eric Dumazet | 5c8d19d | 2014-11-16 06:23:11 -0800 | [diff] [blame] | 3469 | ew32(RSSRK(i), rss_key[i]); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3470 | |
| 3471 | /* Direct all traffic to queue 0 */ |
| 3472 | for (i = 0; i < 32; i++) |
| 3473 | ew32(RETA(i), 0); |
| 3474 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3475 | /* Disable raw packet checksumming so that RSS hash is placed in |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3476 | * descriptor on writeback. |
| 3477 | */ |
| 3478 | rxcsum = er32(RXCSUM); |
| 3479 | rxcsum |= E1000_RXCSUM_PCSD; |
| 3480 | |
| 3481 | ew32(RXCSUM, rxcsum); |
| 3482 | |
| 3483 | mrqc = (E1000_MRQC_RSS_FIELD_IPV4 | |
| 3484 | E1000_MRQC_RSS_FIELD_IPV4_TCP | |
| 3485 | E1000_MRQC_RSS_FIELD_IPV6 | |
| 3486 | E1000_MRQC_RSS_FIELD_IPV6_TCP | |
| 3487 | E1000_MRQC_RSS_FIELD_IPV6_TCP_EX); |
| 3488 | |
| 3489 | ew32(MRQC, mrqc); |
| 3490 | } |
| 3491 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3492 | /** |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3493 | * e1000e_get_base_timinca - get default SYSTIM time increment attributes |
| 3494 | * @adapter: board private structure |
| 3495 | * @timinca: pointer to returned time increment attributes |
| 3496 | * |
| 3497 | * Get attributes for incrementing the System Time Register SYSTIML/H at |
| 3498 | * the default base frequency, and set the cyclecounter shift value. |
| 3499 | **/ |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3500 | s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca) |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3501 | { |
| 3502 | struct e1000_hw *hw = &adapter->hw; |
| 3503 | u32 incvalue, incperiod, shift; |
| 3504 | |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 3505 | /* Make sure clock is enabled on I217/I218/I219 before checking |
| 3506 | * the frequency |
| 3507 | */ |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 3508 | if ((hw->mac.type >= e1000_pch_lpt) && |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3509 | !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) && |
| 3510 | !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) { |
| 3511 | u32 fextnvm7 = er32(FEXTNVM7); |
| 3512 | |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 3513 | if (!(fextnvm7 & BIT(0))) { |
| 3514 | ew32(FEXTNVM7, fextnvm7 | BIT(0)); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3515 | e1e_flush(); |
| 3516 | } |
| 3517 | } |
| 3518 | |
| 3519 | switch (hw->mac.type) { |
| 3520 | case e1000_pch2lan: |
Bernd Faust | 5313eec | 2017-02-16 19:42:07 +0100 | [diff] [blame] | 3521 | /* Stable 96MHz frequency */ |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3522 | incperiod = INCPERIOD_96MHZ; |
| 3523 | incvalue = INCVALUE_96MHZ; |
| 3524 | shift = INCVALUE_SHIFT_96MHZ; |
| 3525 | adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ; |
Bernd Faust | 5313eec | 2017-02-16 19:42:07 +0100 | [diff] [blame] | 3526 | break; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3527 | case e1000_pch_lpt: |
Yanir Lubetkin | 83129b3 | 2015-06-02 17:05:45 +0300 | [diff] [blame] | 3528 | if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) { |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3529 | /* Stable 96MHz frequency */ |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3530 | incperiod = INCPERIOD_96MHZ; |
| 3531 | incvalue = INCVALUE_96MHZ; |
| 3532 | shift = INCVALUE_SHIFT_96MHZ; |
| 3533 | adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ; |
Yanir Lubetkin | 83129b3 | 2015-06-02 17:05:45 +0300 | [diff] [blame] | 3534 | } else { |
| 3535 | /* Stable 25MHz frequency */ |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3536 | incperiod = INCPERIOD_25MHZ; |
| 3537 | incvalue = INCVALUE_25MHZ; |
| 3538 | shift = INCVALUE_SHIFT_25MHZ; |
Yanir Lubetkin | 83129b3 | 2015-06-02 17:05:45 +0300 | [diff] [blame] | 3539 | adapter->cc.shift = shift; |
| 3540 | } |
| 3541 | break; |
| 3542 | case e1000_pch_spt: |
Benjamin Poirier | fff200c | 2018-05-10 16:28:35 +0900 | [diff] [blame] | 3543 | /* Stable 24MHz frequency */ |
| 3544 | incperiod = INCPERIOD_24MHZ; |
| 3545 | incvalue = INCVALUE_24MHZ; |
| 3546 | shift = INCVALUE_SHIFT_24MHZ; |
| 3547 | adapter->cc.shift = shift; |
| 3548 | break; |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3549 | case e1000_pch_cnp: |
Sasha Neftin | fb776f5 | 2019-10-16 11:08:38 +0300 | [diff] [blame] | 3550 | case e1000_pch_tgp: |
Sasha Neftin | 59e4668 | 2020-01-19 13:57:13 +0200 | [diff] [blame] | 3551 | case e1000_pch_adp: |
Sasha Neftin | cc23f4f | 2020-08-13 11:34:06 +0300 | [diff] [blame] | 3552 | case e1000_pch_mtp: |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3553 | if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) { |
| 3554 | /* Stable 24MHz frequency */ |
| 3555 | incperiod = INCPERIOD_24MHZ; |
| 3556 | incvalue = INCVALUE_24MHZ; |
| 3557 | shift = INCVALUE_SHIFT_24MHZ; |
| 3558 | adapter->cc.shift = shift; |
| 3559 | } else { |
| 3560 | /* Stable 38400KHz frequency */ |
| 3561 | incperiod = INCPERIOD_38400KHZ; |
| 3562 | incvalue = INCVALUE_38400KHZ; |
| 3563 | shift = INCVALUE_SHIFT_38400KHZ; |
| 3564 | adapter->cc.shift = shift; |
| 3565 | } |
| 3566 | break; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3567 | case e1000_82574: |
| 3568 | case e1000_82583: |
| 3569 | /* Stable 25MHz frequency */ |
Sasha Neftin | 68fe1d5 | 2017-04-06 10:27:03 +0300 | [diff] [blame] | 3570 | incperiod = INCPERIOD_25MHZ; |
| 3571 | incvalue = INCVALUE_25MHZ; |
| 3572 | shift = INCVALUE_SHIFT_25MHZ; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3573 | adapter->cc.shift = shift; |
| 3574 | break; |
| 3575 | default: |
| 3576 | return -EINVAL; |
| 3577 | } |
| 3578 | |
| 3579 | *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) | |
| 3580 | ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK)); |
| 3581 | |
| 3582 | return 0; |
| 3583 | } |
| 3584 | |
| 3585 | /** |
| 3586 | * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable |
| 3587 | * @adapter: board private structure |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 3588 | * @config: timestamp configuration |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3589 | * |
| 3590 | * Outgoing time stamping can be enabled and disabled. Play nice and |
| 3591 | * disable it when requested, although it shouldn't cause any overhead |
| 3592 | * when no packet needs it. At most one packet in the queue may be |
| 3593 | * marked for time stamping, otherwise it would be impossible to tell |
| 3594 | * for sure to which packet the hardware time stamp belongs. |
| 3595 | * |
| 3596 | * Incoming time stamping has to be configured via the hardware filters. |
| 3597 | * Not all combinations are supported, in particular event type has to be |
| 3598 | * specified. Matching the kind of event packet is not supported, with the |
| 3599 | * exception of "all V2 events regardless of level 2 or 4". |
| 3600 | **/ |
Ben Hutchings | 62d7e3a | 2013-11-14 00:41:38 +0000 | [diff] [blame] | 3601 | static int e1000e_config_hwtstamp(struct e1000_adapter *adapter, |
| 3602 | struct hwtstamp_config *config) |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3603 | { |
| 3604 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3605 | u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED; |
| 3606 | u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3607 | u32 rxmtrl = 0; |
| 3608 | u16 rxudp = 0; |
| 3609 | bool is_l4 = false; |
| 3610 | bool is_l2 = false; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3611 | u32 regval; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3612 | |
| 3613 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) |
| 3614 | return -EINVAL; |
| 3615 | |
| 3616 | /* flags reserved for future extensions - must be zero */ |
| 3617 | if (config->flags) |
| 3618 | return -EINVAL; |
| 3619 | |
| 3620 | switch (config->tx_type) { |
| 3621 | case HWTSTAMP_TX_OFF: |
| 3622 | tsync_tx_ctl = 0; |
| 3623 | break; |
| 3624 | case HWTSTAMP_TX_ON: |
| 3625 | break; |
| 3626 | default: |
| 3627 | return -ERANGE; |
| 3628 | } |
| 3629 | |
| 3630 | switch (config->rx_filter) { |
| 3631 | case HWTSTAMP_FILTER_NONE: |
| 3632 | tsync_rx_ctl = 0; |
| 3633 | break; |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3634 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 3635 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
| 3636 | rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE; |
| 3637 | is_l4 = true; |
| 3638 | break; |
| 3639 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 3640 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
| 3641 | rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE; |
| 3642 | is_l4 = true; |
| 3643 | break; |
| 3644 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 3645 | /* Also time stamps V2 L2 Path Delay Request/Response */ |
| 3646 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2; |
| 3647 | rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE; |
| 3648 | is_l2 = true; |
| 3649 | break; |
| 3650 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 3651 | /* Also time stamps V2 L2 Path Delay Request/Response. */ |
| 3652 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2; |
| 3653 | rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE; |
| 3654 | is_l2 = true; |
| 3655 | break; |
| 3656 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
Jeff Kirsher | 5463fce6 | 2020-06-03 20:07:26 -0700 | [diff] [blame] | 3657 | /* Hardware cannot filter just V2 L4 Sync messages */ |
| 3658 | fallthrough; |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3659 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 3660 | /* Also time stamps V2 Path Delay Request/Response. */ |
| 3661 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
| 3662 | rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE; |
| 3663 | is_l2 = true; |
| 3664 | is_l4 = true; |
| 3665 | break; |
| 3666 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
Jeff Kirsher | 5463fce6 | 2020-06-03 20:07:26 -0700 | [diff] [blame] | 3667 | /* Hardware cannot filter just V2 L4 Delay Request messages */ |
| 3668 | fallthrough; |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3669 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 3670 | /* Also time stamps V2 Path Delay Request/Response. */ |
| 3671 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
| 3672 | rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE; |
| 3673 | is_l2 = true; |
| 3674 | is_l4 = true; |
| 3675 | break; |
| 3676 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 3677 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
Jeff Kirsher | 5463fce6 | 2020-06-03 20:07:26 -0700 | [diff] [blame] | 3678 | /* Hardware cannot filter just V2 L4 or L2 Event messages */ |
| 3679 | fallthrough; |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3680 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 3681 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2; |
| 3682 | config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
| 3683 | is_l2 = true; |
| 3684 | is_l4 = true; |
| 3685 | break; |
| 3686 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 3687 | /* For V1, the hardware can only filter Sync messages or |
| 3688 | * Delay Request messages but not both so fall-through to |
| 3689 | * time stamp all packets. |
| 3690 | */ |
Jeff Kirsher | 5463fce6 | 2020-06-03 20:07:26 -0700 | [diff] [blame] | 3691 | fallthrough; |
Miroslav Lichvar | e341257 | 2017-05-19 17:52:36 +0200 | [diff] [blame] | 3692 | case HWTSTAMP_FILTER_NTP_ALL: |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3693 | case HWTSTAMP_FILTER_ALL: |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3694 | is_l2 = true; |
| 3695 | is_l4 = true; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3696 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; |
| 3697 | config->rx_filter = HWTSTAMP_FILTER_ALL; |
| 3698 | break; |
| 3699 | default: |
| 3700 | return -ERANGE; |
| 3701 | } |
| 3702 | |
Ben Hutchings | 62d7e3a | 2013-11-14 00:41:38 +0000 | [diff] [blame] | 3703 | adapter->hwtstamp_config = *config; |
| 3704 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3705 | /* enable/disable Tx h/w time stamping */ |
| 3706 | regval = er32(TSYNCTXCTL); |
| 3707 | regval &= ~E1000_TSYNCTXCTL_ENABLED; |
| 3708 | regval |= tsync_tx_ctl; |
| 3709 | ew32(TSYNCTXCTL, regval); |
| 3710 | if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) != |
| 3711 | (regval & E1000_TSYNCTXCTL_ENABLED)) { |
| 3712 | e_err("Timesync Tx Control register not set as expected\n"); |
| 3713 | return -EAGAIN; |
| 3714 | } |
| 3715 | |
| 3716 | /* enable/disable Rx h/w time stamping */ |
| 3717 | regval = er32(TSYNCRXCTL); |
| 3718 | regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK); |
| 3719 | regval |= tsync_rx_ctl; |
| 3720 | ew32(TSYNCRXCTL, regval); |
| 3721 | if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED | |
| 3722 | E1000_TSYNCRXCTL_TYPE_MASK)) != |
| 3723 | (regval & (E1000_TSYNCRXCTL_ENABLED | |
| 3724 | E1000_TSYNCRXCTL_TYPE_MASK))) { |
| 3725 | e_err("Timesync Rx Control register not set as expected\n"); |
| 3726 | return -EAGAIN; |
| 3727 | } |
| 3728 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 3729 | /* L2: define ethertype filter for time stamped packets */ |
| 3730 | if (is_l2) |
| 3731 | rxmtrl |= ETH_P_1588; |
| 3732 | |
| 3733 | /* define which PTP packets get time stamped */ |
| 3734 | ew32(RXMTRL, rxmtrl); |
| 3735 | |
| 3736 | /* Filter by destination port */ |
| 3737 | if (is_l4) { |
| 3738 | rxudp = PTP_EV_PORT; |
| 3739 | cpu_to_be16s(&rxudp); |
| 3740 | } |
| 3741 | ew32(RXUDP, rxudp); |
| 3742 | |
| 3743 | e1e_flush(); |
| 3744 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3745 | /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */ |
Bruce Allan | 70806a7 | 2013-01-05 05:08:37 +0000 | [diff] [blame] | 3746 | er32(RXSTMPH); |
| 3747 | er32(TXSTMPH); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3748 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 3749 | return 0; |
| 3750 | } |
| 3751 | |
| 3752 | /** |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3753 | * e1000_configure - configure the hardware for Rx and Tx |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3754 | * @adapter: private board structure |
| 3755 | **/ |
| 3756 | static void e1000_configure(struct e1000_adapter *adapter) |
| 3757 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3758 | struct e1000_ring *rx_ring = adapter->rx_ring; |
| 3759 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 3760 | e1000e_set_rx_mode(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3761 | |
| 3762 | e1000_restore_vlan(adapter); |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 3763 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3764 | |
| 3765 | e1000_configure_tx(adapter); |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 3766 | |
| 3767 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 3768 | e1000e_setup_rss_hash(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3769 | e1000_setup_rctl(adapter); |
| 3770 | e1000_configure_rx(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 3771 | 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] | 3772 | } |
| 3773 | |
| 3774 | /** |
| 3775 | * e1000e_power_up_phy - restore link in case the phy was powered down |
| 3776 | * @adapter: address of board private structure |
| 3777 | * |
| 3778 | * The phy may be powered down to save power and turn off link when the |
| 3779 | * driver is unloaded and wake on lan is not enabled (among others) |
| 3780 | * *** this routine MUST be followed by a call to e1000e_reset *** |
| 3781 | **/ |
| 3782 | void e1000e_power_up_phy(struct e1000_adapter *adapter) |
| 3783 | { |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3784 | if (adapter->hw.phy.ops.power_up) |
| 3785 | adapter->hw.phy.ops.power_up(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3786 | |
| 3787 | adapter->hw.mac.ops.setup_link(&adapter->hw); |
| 3788 | } |
| 3789 | |
| 3790 | /** |
| 3791 | * e1000_power_down_phy - Power down the PHY |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 3792 | * @adapter: board private structure |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3793 | * |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3794 | * Power down the PHY so no link is implied when interface is down. |
| 3795 | * The PHY cannot be powered down if management or WoL is active. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3796 | */ |
| 3797 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 3798 | { |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 3799 | if (adapter->hw.phy.ops.power_down) |
| 3800 | adapter->hw.phy.ops.power_down(&adapter->hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | /** |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3804 | * e1000_flush_tx_ring - remove all descriptors from the tx_ring |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 3805 | * @adapter: board private structure |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3806 | * |
| 3807 | * We want to clear all pending descriptors from the TX ring. |
| 3808 | * zeroing happens when the HW reads the regs. We assign the ring itself as |
| 3809 | * the data of the next descriptor. We don't care about the data we are about |
| 3810 | * to reset the HW. |
| 3811 | */ |
| 3812 | static void e1000_flush_tx_ring(struct e1000_adapter *adapter) |
| 3813 | { |
| 3814 | struct e1000_hw *hw = &adapter->hw; |
| 3815 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 3816 | struct e1000_tx_desc *tx_desc = NULL; |
| 3817 | u32 tdt, tctl, txd_lower = E1000_TXD_CMD_IFCS; |
| 3818 | u16 size = 512; |
| 3819 | |
| 3820 | tctl = er32(TCTL); |
| 3821 | ew32(TCTL, tctl | E1000_TCTL_EN); |
| 3822 | tdt = er32(TDT(0)); |
| 3823 | BUG_ON(tdt != tx_ring->next_to_use); |
| 3824 | 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] | 3825 | tx_desc->buffer_addr = cpu_to_le64(tx_ring->dma); |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3826 | |
| 3827 | tx_desc->lower.data = cpu_to_le32(txd_lower | size); |
| 3828 | tx_desc->upper.data = 0; |
| 3829 | /* flush descriptors to memory before notifying the HW */ |
| 3830 | wmb(); |
| 3831 | tx_ring->next_to_use++; |
| 3832 | if (tx_ring->next_to_use == tx_ring->count) |
| 3833 | tx_ring->next_to_use = 0; |
| 3834 | ew32(TDT(0), tx_ring->next_to_use); |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3835 | usleep_range(200, 250); |
| 3836 | } |
| 3837 | |
| 3838 | /** |
| 3839 | * e1000_flush_rx_ring - remove all descriptors from the rx_ring |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 3840 | * @adapter: board private structure |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3841 | * |
| 3842 | * Mark all descriptors in the RX ring as consumed and disable the rx ring |
| 3843 | */ |
| 3844 | static void e1000_flush_rx_ring(struct e1000_adapter *adapter) |
| 3845 | { |
| 3846 | u32 rctl, rxdctl; |
| 3847 | struct e1000_hw *hw = &adapter->hw; |
| 3848 | |
| 3849 | rctl = er32(RCTL); |
| 3850 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 3851 | e1e_flush(); |
| 3852 | usleep_range(100, 150); |
| 3853 | |
| 3854 | rxdctl = er32(RXDCTL(0)); |
| 3855 | /* zero the lower 14 bits (prefetch and host thresholds) */ |
| 3856 | rxdctl &= 0xffffc000; |
| 3857 | |
| 3858 | /* update thresholds: prefetch threshold to 31, host threshold to 1 |
| 3859 | * and make sure the granularity is "descriptors" and not "cache lines" |
| 3860 | */ |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 3861 | rxdctl |= (0x1F | BIT(8) | E1000_RXDCTL_THRESH_UNIT_DESC); |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3862 | |
| 3863 | ew32(RXDCTL(0), rxdctl); |
| 3864 | /* momentarily enable the RX ring for the changes to take effect */ |
| 3865 | ew32(RCTL, rctl | E1000_RCTL_EN); |
| 3866 | e1e_flush(); |
| 3867 | usleep_range(100, 150); |
| 3868 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 3869 | } |
| 3870 | |
| 3871 | /** |
| 3872 | * e1000_flush_desc_rings - remove all descriptors from the descriptor rings |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 3873 | * @adapter: board private structure |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3874 | * |
| 3875 | * In i219, the descriptor rings must be emptied before resetting the HW |
| 3876 | * or before changing the device state to D3 during runtime (runtime PM). |
| 3877 | * |
| 3878 | * Failure to do this will cause the HW to enter a unit hang state which can |
| 3879 | * only be released by PCI reset on the device |
| 3880 | * |
| 3881 | */ |
| 3882 | |
| 3883 | static void e1000_flush_desc_rings(struct e1000_adapter *adapter) |
| 3884 | { |
Yanir Lubetkin | ff917429 | 2015-06-02 17:05:38 +0300 | [diff] [blame] | 3885 | u16 hang_state; |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3886 | u32 fext_nvm11, tdlen; |
| 3887 | struct e1000_hw *hw = &adapter->hw; |
| 3888 | |
| 3889 | /* First, disable MULR fix in FEXTNVM11 */ |
| 3890 | fext_nvm11 = er32(FEXTNVM11); |
| 3891 | fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX; |
| 3892 | ew32(FEXTNVM11, fext_nvm11); |
| 3893 | /* do nothing if we're not in faulty state, or if the queue is empty */ |
| 3894 | tdlen = er32(TDLEN(0)); |
Yanir Lubetkin | ff917429 | 2015-06-02 17:05:38 +0300 | [diff] [blame] | 3895 | pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS, |
| 3896 | &hang_state); |
| 3897 | if (!(hang_state & FLUSH_DESC_REQUIRED) || !tdlen) |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3898 | return; |
| 3899 | e1000_flush_tx_ring(adapter); |
| 3900 | /* recheck, maybe the fault is caused by the rx ring */ |
Yanir Lubetkin | ff917429 | 2015-06-02 17:05:38 +0300 | [diff] [blame] | 3901 | pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS, |
| 3902 | &hang_state); |
| 3903 | if (hang_state & FLUSH_DESC_REQUIRED) |
Yanir Lubetkin | ad851fb | 2015-04-14 02:20:21 +0300 | [diff] [blame] | 3904 | e1000_flush_rx_ring(adapter); |
| 3905 | } |
| 3906 | |
| 3907 | /** |
Jacob Keller | aa524b6 | 2016-04-20 11:36:42 -0700 | [diff] [blame] | 3908 | * e1000e_systim_reset - reset the timesync registers after a hardware reset |
| 3909 | * @adapter: board private structure |
| 3910 | * |
| 3911 | * When the MAC is reset, all hardware bits for timesync will be reset to the |
| 3912 | * default values. This function will restore the settings last in place. |
| 3913 | * Since the clock SYSTIME registers are reset, we will simply restore the |
| 3914 | * cyclecounter to the kernel real clock time. |
| 3915 | **/ |
| 3916 | static void e1000e_systim_reset(struct e1000_adapter *adapter) |
| 3917 | { |
| 3918 | struct ptp_clock_info *info = &adapter->ptp_clock_info; |
| 3919 | struct e1000_hw *hw = &adapter->hw; |
| 3920 | unsigned long flags; |
| 3921 | u32 timinca; |
| 3922 | s32 ret_val; |
| 3923 | |
| 3924 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) |
| 3925 | return; |
| 3926 | |
| 3927 | if (info->adjfreq) { |
| 3928 | /* restore the previous ptp frequency delta */ |
| 3929 | ret_val = info->adjfreq(info, adapter->ptp_delta); |
| 3930 | } else { |
| 3931 | /* set the default base frequency if no adjustment possible */ |
| 3932 | ret_val = e1000e_get_base_timinca(adapter, &timinca); |
| 3933 | if (!ret_val) |
| 3934 | ew32(TIMINCA, timinca); |
| 3935 | } |
| 3936 | |
| 3937 | if (ret_val) { |
| 3938 | dev_warn(&adapter->pdev->dev, |
| 3939 | "Failed to restore TIMINCA clock rate delta: %d\n", |
| 3940 | ret_val); |
| 3941 | return; |
| 3942 | } |
| 3943 | |
| 3944 | /* reset the systim ns time counter */ |
| 3945 | spin_lock_irqsave(&adapter->systim_lock, flags); |
| 3946 | timecounter_init(&adapter->tc, &adapter->cc, |
| 3947 | ktime_to_ns(ktime_get_real())); |
| 3948 | spin_unlock_irqrestore(&adapter->systim_lock, flags); |
| 3949 | |
| 3950 | /* restore the previous hwtstamp configuration settings */ |
| 3951 | e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config); |
| 3952 | } |
| 3953 | |
| 3954 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3955 | * e1000e_reset - bring the hardware into a known good state |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 3956 | * @adapter: board private structure |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3957 | * |
| 3958 | * This function boots the hardware and enables some settings that |
| 3959 | * require a configuration cycle of the hardware - those cannot be |
| 3960 | * set/changed during runtime. After reset the device needs to be |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3961 | * properly configured for Rx, Tx etc. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3962 | */ |
| 3963 | void e1000e_reset(struct e1000_adapter *adapter) |
| 3964 | { |
| 3965 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3966 | struct e1000_fc_info *fc = &adapter->hw.fc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3967 | struct e1000_hw *hw = &adapter->hw; |
| 3968 | u32 tx_space, min_tx_space, min_rx_space; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3969 | u32 pba = adapter->pba; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3970 | u16 hwm; |
| 3971 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3972 | /* reset Packet Buffer Allocation to default */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3973 | ew32(PBA, pba); |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3974 | |
Alexander Duyck | 8084b86 | 2015-05-02 00:52:00 -0700 | [diff] [blame] | 3975 | if (adapter->max_frame_size > (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3976 | /* To maintain wire speed transmits, the Tx FIFO should be |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3977 | * large enough to accommodate two full transmit packets, |
| 3978 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 3979 | * the Rx FIFO should be large enough to accommodate at least |
| 3980 | * one full receive packet and is similarly rounded up and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3981 | * expressed in KB. |
| 3982 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3983 | pba = er32(PBA); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3984 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3985 | tx_space = pba >> 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3986 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 3987 | pba &= 0xffff; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 3988 | /* the Tx fifo also stores 16 bytes of information about the Tx |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 3989 | * but don't include ethernet FCS because hardware appends it |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3990 | */ |
| 3991 | min_tx_space = (adapter->max_frame_size + |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 3992 | sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3993 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 3994 | min_tx_space >>= 10; |
| 3995 | /* software strips receive CRC, so leave room for it */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 3996 | min_rx_space = adapter->max_frame_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 3997 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 3998 | min_rx_space >>= 10; |
| 3999 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4000 | /* If current Tx allocation is less than the min Tx FIFO size, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4001 | * 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] | 4002 | * allocation, take space away from current Rx allocation |
| 4003 | */ |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 4004 | if ((tx_space < min_tx_space) && |
| 4005 | ((min_tx_space - tx_space) < pba)) { |
| 4006 | pba -= min_tx_space - tx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4007 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4008 | /* if short on Rx space, Rx wins and must trump Tx |
Bruce Allan | 419e551 | 2012-08-17 06:18:02 +0000 | [diff] [blame] | 4009 | * adjustment |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4010 | */ |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4011 | if (pba < min_rx_space) |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 4012 | pba = min_rx_space; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4013 | } |
Auke Kok | df76246 | 2007-10-25 13:57:53 -0700 | [diff] [blame] | 4014 | |
| 4015 | ew32(PBA, pba); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4016 | } |
| 4017 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4018 | /* flow control settings |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4019 | * |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4020 | * 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] | 4021 | * (or the size used for early receive) above it in the Rx FIFO. |
| 4022 | * Set it to the lower of: |
| 4023 | * - 90% of the Rx FIFO size, and |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4024 | * - the full Rx FIFO size minus one full frame |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4025 | */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4026 | if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) |
| 4027 | fc->pause_time = 0xFFFF; |
| 4028 | else |
| 4029 | fc->pause_time = E1000_FC_PAUSE_TIME; |
Bruce Allan | b20caa8 | 2012-02-22 09:03:03 +0000 | [diff] [blame] | 4030 | fc->send_xon = true; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4031 | fc->current_mode = fc->requested_mode; |
| 4032 | |
| 4033 | switch (hw->mac.type) { |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4034 | case e1000_ich9lan: |
| 4035 | case e1000_ich10lan: |
| 4036 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 4037 | pba = 14; |
| 4038 | ew32(PBA, pba); |
| 4039 | fc->high_water = 0x2800; |
| 4040 | fc->low_water = fc->high_water - 8; |
| 4041 | break; |
| 4042 | } |
Jeff Kirsher | 5463fce6 | 2020-06-03 20:07:26 -0700 | [diff] [blame] | 4043 | fallthrough; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4044 | default: |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4045 | hwm = min(((pba << 10) * 9 / 10), |
| 4046 | ((pba << 10) - adapter->max_frame_size)); |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4047 | |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 4048 | fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4049 | fc->low_water = fc->high_water - 8; |
| 4050 | break; |
| 4051 | case e1000_pchlan: |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4052 | /* Workaround PCH LOM adapter hangs with certain network |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4053 | * loads. If hangs persist, try disabling Tx flow control. |
| 4054 | */ |
| 4055 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 4056 | fc->high_water = 0x3500; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 4057 | fc->low_water = 0x1500; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4058 | } else { |
| 4059 | fc->high_water = 0x5000; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 4060 | fc->low_water = 0x3000; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4061 | } |
Bruce Allan | a305595 | 2010-05-10 15:02:12 +0000 | [diff] [blame] | 4062 | fc->refresh_time = 0x1000; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4063 | break; |
| 4064 | case e1000_pch2lan: |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 4065 | case e1000_pch_lpt: |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 4066 | case e1000_pch_spt: |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 4067 | case e1000_pch_cnp: |
Sasha Neftin | fb776f5 | 2019-10-16 11:08:38 +0300 | [diff] [blame] | 4068 | case e1000_pch_tgp: |
Sasha Neftin | 59e4668 | 2020-01-19 13:57:13 +0200 | [diff] [blame] | 4069 | case e1000_pch_adp: |
Sasha Neftin | cc23f4f | 2020-08-13 11:34:06 +0300 | [diff] [blame] | 4070 | case e1000_pch_mtp: |
Miguel Bernal Marin | f74dc88 | 2017-03-27 16:01:56 -0600 | [diff] [blame] | 4071 | fc->refresh_time = 0xFFFF; |
| 4072 | fc->pause_time = 0xFFFF; |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 4073 | |
| 4074 | if (adapter->netdev->mtu <= ETH_DATA_LEN) { |
| 4075 | fc->high_water = 0x05C20; |
| 4076 | fc->low_water = 0x05048; |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 4077 | break; |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4078 | } |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 4079 | |
Bruce Allan | ce345e0 | 2013-06-21 09:07:07 +0000 | [diff] [blame] | 4080 | pba = 14; |
| 4081 | ew32(PBA, pba); |
Bruce Allan | 347b520 | 2012-12-08 00:35:35 +0000 | [diff] [blame] | 4082 | fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH; |
| 4083 | fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 4084 | break; |
Bruce Allan | 38eb394 | 2009-11-19 12:34:20 +0000 | [diff] [blame] | 4085 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4086 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4087 | /* Alignment of Tx data is on an arbitrary byte boundary with the |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 4088 | * maximum size per Tx descriptor limited only to the transmit |
| 4089 | * allocation of the packet buffer minus 96 bytes with an upper |
| 4090 | * limit of 24KB due to receive synchronization limitations. |
| 4091 | */ |
| 4092 | adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96, |
| 4093 | 24 << 10); |
| 4094 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4095 | /* Disable Adaptive Interrupt Moderation if 2 full packets cannot |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4096 | * fit in receive buffer. |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4097 | */ |
| 4098 | if (adapter->itr_setting & 0x3) { |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4099 | if ((adapter->max_frame_size * 2) > (pba << 10)) { |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4100 | if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) { |
| 4101 | dev_info(&adapter->pdev->dev, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 4102 | "Interrupt Throttle Rate off\n"); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4103 | adapter->flags2 |= FLAG2_DISABLE_AIM; |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 4104 | e1000e_write_itr(adapter, 0); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4105 | } |
| 4106 | } else if (adapter->flags2 & FLAG2_DISABLE_AIM) { |
| 4107 | dev_info(&adapter->pdev->dev, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 4108 | "Interrupt Throttle Rate on\n"); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4109 | adapter->flags2 &= ~FLAG2_DISABLE_AIM; |
| 4110 | adapter->itr = 20000; |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 4111 | e1000e_write_itr(adapter, adapter->itr); |
Bruce Allan | 828bac8 | 2010-09-29 21:39:37 +0000 | [diff] [blame] | 4112 | } |
| 4113 | } |
| 4114 | |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 4115 | if (hw->mac.type >= e1000_pch_spt) |
Yanir Lubetkin | 0ffc564 | 2015-04-22 04:15:01 +0300 | [diff] [blame] | 4116 | e1000_flush_desc_rings(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4117 | /* Allow time for pending master requests to run */ |
| 4118 | mac->ops.reset_hw(hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 4119 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4120 | /* For parts with AMT enabled, let the firmware know |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 4121 | * that the network interface is in control |
| 4122 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 4123 | if (adapter->flags & FLAG_HAS_AMT) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4124 | e1000e_get_hw_control(adapter); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 4125 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4126 | ew32(WUC, 0); |
| 4127 | |
| 4128 | if (mac->ops.init_hw(hw)) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 4129 | e_err("Hardware Error\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4130 | |
| 4131 | e1000_update_mng_vlan(adapter); |
| 4132 | |
| 4133 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 4134 | ew32(VET, ETH_P_8021Q); |
| 4135 | |
| 4136 | e1000e_reset_adaptive(hw); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4137 | |
Jacob Keller | aa524b6 | 2016-04-20 11:36:42 -0700 | [diff] [blame] | 4138 | /* restore systim and hwtstamp settings */ |
| 4139 | e1000e_systim_reset(adapter); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4140 | |
Bruce Allan | d495bcb | 2013-03-20 07:23:11 +0000 | [diff] [blame] | 4141 | /* Set EEE advertisement as appropriate */ |
| 4142 | if (adapter->flags2 & FLAG2_HAS_EEE) { |
| 4143 | s32 ret_val; |
| 4144 | u16 adv_addr; |
| 4145 | |
| 4146 | switch (hw->phy.type) { |
| 4147 | case e1000_phy_82579: |
| 4148 | adv_addr = I82579_EEE_ADVERTISEMENT; |
| 4149 | break; |
| 4150 | case e1000_phy_i217: |
| 4151 | adv_addr = I217_EEE_ADVERTISEMENT; |
| 4152 | break; |
| 4153 | default: |
| 4154 | dev_err(&adapter->pdev->dev, |
| 4155 | "Invalid PHY type setting EEE advertisement\n"); |
| 4156 | return; |
| 4157 | } |
| 4158 | |
| 4159 | ret_val = hw->phy.ops.acquire(hw); |
| 4160 | if (ret_val) { |
| 4161 | dev_err(&adapter->pdev->dev, |
| 4162 | "EEE advertisement - unable to acquire PHY\n"); |
| 4163 | return; |
| 4164 | } |
| 4165 | |
| 4166 | e1000_write_emi_reg_locked(hw, adv_addr, |
| 4167 | hw->dev_spec.ich8lan.eee_disable ? |
| 4168 | 0 : adapter->eee_advert); |
| 4169 | |
| 4170 | hw->phy.ops.release(hw); |
| 4171 | } |
| 4172 | |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4173 | if (!netif_running(adapter->netdev) && |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 4174 | !test_bit(__E1000_TESTING, &adapter->state)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4175 | e1000_power_down_phy(adapter); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4176 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4177 | e1000_get_phy_info(hw); |
| 4178 | |
Bruce Allan | 918d719 | 2009-06-02 11:28:20 +0000 | [diff] [blame] | 4179 | if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && |
| 4180 | !(adapter->flags & FLAG_SMART_POWER_DOWN)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4181 | u16 phy_data = 0; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4182 | /* speed up time to link by disabling smart power down, ignore |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4183 | * the return value of this function because there is nothing |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4184 | * different we would do if it failed |
| 4185 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4186 | e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
| 4187 | phy_data &= ~IGP02E1000_PM_SPD; |
| 4188 | e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 4189 | } |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 4190 | if (hw->mac.type >= e1000_pch_spt && adapter->int_mode == 0) { |
Yanir Lubetkin | ec945cf | 2015-06-02 17:05:42 +0300 | [diff] [blame] | 4191 | u32 reg; |
| 4192 | |
| 4193 | /* Fextnvm7 @ 0xe4[2] = 1 */ |
| 4194 | reg = er32(FEXTNVM7); |
| 4195 | reg |= E1000_FEXTNVM7_SIDE_CLK_UNGATE; |
| 4196 | ew32(FEXTNVM7, reg); |
| 4197 | /* Fextnvm9 @ 0x5bb4[13:12] = 11 */ |
| 4198 | reg = er32(FEXTNVM9); |
| 4199 | reg |= E1000_FEXTNVM9_IOSFSB_CLKGATE_DIS | |
| 4200 | E1000_FEXTNVM9_IOSFSB_CLKREQ_DIS; |
| 4201 | ew32(FEXTNVM9, reg); |
| 4202 | } |
| 4203 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
Benjamin Poirier | a61cfe4 | 2015-11-09 15:50:20 -0800 | [diff] [blame] | 4206 | /** |
| 4207 | * e1000e_trigger_lsc - trigger an LSC interrupt |
| 4208 | * @adapter: |
| 4209 | * |
| 4210 | * Fire a link status change interrupt to start the watchdog. |
| 4211 | **/ |
| 4212 | static void e1000e_trigger_lsc(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4213 | { |
| 4214 | struct e1000_hw *hw = &adapter->hw; |
| 4215 | |
Benjamin Poirier | a61cfe4 | 2015-11-09 15:50:20 -0800 | [diff] [blame] | 4216 | if (adapter->msix_entries) |
Benjamin Poirier | 4aea7a5c | 2017-07-21 11:36:27 -0700 | [diff] [blame] | 4217 | ew32(ICS, E1000_ICS_LSC | E1000_ICS_OTHER); |
Benjamin Poirier | a61cfe4 | 2015-11-09 15:50:20 -0800 | [diff] [blame] | 4218 | else |
| 4219 | ew32(ICS, E1000_ICS_LSC); |
| 4220 | } |
| 4221 | |
| 4222 | void e1000e_up(struct e1000_adapter *adapter) |
| 4223 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4224 | /* hardware has been reset, we need to reload some things */ |
| 4225 | e1000_configure(adapter); |
| 4226 | |
| 4227 | clear_bit(__E1000_DOWN, &adapter->state); |
| 4228 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4229 | if (adapter->msix_entries) |
| 4230 | e1000_configure_msix(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4231 | e1000_irq_enable(adapter); |
| 4232 | |
Konstantin Khlebnikov | d17ba0f | 2019-04-17 11:13:20 +0300 | [diff] [blame] | 4233 | /* Tx queue started by watchdog timer when link is up */ |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 4234 | |
Benjamin Poirier | a61cfe4 | 2015-11-09 15:50:20 -0800 | [diff] [blame] | 4235 | e1000e_trigger_lsc(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4236 | } |
| 4237 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4238 | static void e1000e_flush_descriptors(struct e1000_adapter *adapter) |
| 4239 | { |
| 4240 | struct e1000_hw *hw = &adapter->hw; |
| 4241 | |
| 4242 | if (!(adapter->flags2 & FLAG2_DMA_BURST)) |
| 4243 | return; |
| 4244 | |
| 4245 | /* flush pending descriptor writebacks to memory */ |
| 4246 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 4247 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 4248 | |
| 4249 | /* execute the writes immediately */ |
| 4250 | e1e_flush(); |
Matthew Vick | bf03085 | 2012-03-16 09:03:00 +0000 | [diff] [blame] | 4251 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4252 | /* 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] | 4253 | * write is successful |
| 4254 | */ |
| 4255 | ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); |
| 4256 | ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); |
| 4257 | |
| 4258 | /* execute the writes immediately */ |
| 4259 | e1e_flush(); |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 4260 | } |
| 4261 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4262 | static void e1000e_update_stats(struct e1000_adapter *adapter); |
| 4263 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 4264 | /** |
| 4265 | * e1000e_down - quiesce the device and optionally reset the hardware |
| 4266 | * @adapter: board private structure |
| 4267 | * @reset: boolean flag to reset the hardware or not |
| 4268 | */ |
| 4269 | void e1000e_down(struct e1000_adapter *adapter, bool reset) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4270 | { |
| 4271 | struct net_device *netdev = adapter->netdev; |
| 4272 | struct e1000_hw *hw = &adapter->hw; |
| 4273 | u32 tctl, rctl; |
| 4274 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4275 | /* signal that we're down so the interrupt handler does not |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4276 | * reschedule our watchdog timer |
| 4277 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4278 | set_bit(__E1000_DOWN, &adapter->state); |
| 4279 | |
Eliezer Tamir | a60a132 | 2015-03-20 17:41:52 -0700 | [diff] [blame] | 4280 | netif_carrier_off(netdev); |
| 4281 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4282 | /* disable receives in the hardware */ |
| 4283 | rctl = er32(RCTL); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 4284 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 4285 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4286 | /* flush and sleep below */ |
| 4287 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 4288 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4289 | |
| 4290 | /* disable transmits in the hardware */ |
| 4291 | tctl = er32(TCTL); |
| 4292 | tctl &= ~E1000_TCTL_EN; |
| 4293 | ew32(TCTL, tctl); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 4294 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4295 | /* flush both disables and wait for them to finish */ |
| 4296 | e1e_flush(); |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 4297 | usleep_range(10000, 11000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4298 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4299 | e1000_irq_disable(adapter); |
| 4300 | |
Bruce Allan | a3b87a4 | 2013-04-20 05:37:29 +0000 | [diff] [blame] | 4301 | napi_synchronize(&adapter->napi); |
| 4302 | |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 4303 | del_timer_sync(&adapter->watchdog_timer); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4304 | del_timer_sync(&adapter->phy_info_timer); |
| 4305 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4306 | spin_lock(&adapter->stats64_lock); |
| 4307 | e1000e_update_stats(adapter); |
| 4308 | spin_unlock(&adapter->stats64_lock); |
| 4309 | |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 4310 | e1000e_flush_descriptors(adapter); |
Bruce Allan | 400484f | 2011-05-13 07:20:03 +0000 | [diff] [blame] | 4311 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4312 | adapter->link_speed = 0; |
| 4313 | adapter->link_duplex = 0; |
| 4314 | |
Bruce Allan | da1e2046 | 2013-06-21 09:07:02 +0000 | [diff] [blame] | 4315 | /* Disable Si errata workaround on PCHx for jumbo frame flow */ |
| 4316 | if ((hw->mac.type >= e1000_pch2lan) && |
| 4317 | (adapter->netdev->mtu > ETH_DATA_LEN) && |
| 4318 | e1000_lv_jumbo_workaround_ich8lan(hw, false)) |
| 4319 | e_dbg("failed to disable jumbo frame workaround mode\n"); |
| 4320 | |
Yanir Lubetkin | 0ffc564 | 2015-04-22 04:15:01 +0300 | [diff] [blame] | 4321 | if (!pci_channel_offline(adapter->pdev)) { |
| 4322 | if (reset) |
| 4323 | e1000e_reset(adapter); |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 4324 | else if (hw->mac.type >= e1000_pch_spt) |
Yanir Lubetkin | 0ffc564 | 2015-04-22 04:15:01 +0300 | [diff] [blame] | 4325 | e1000_flush_desc_rings(adapter); |
| 4326 | } |
| 4327 | e1000_clean_tx_ring(adapter->tx_ring); |
| 4328 | e1000_clean_rx_ring(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | void e1000e_reinit_locked(struct e1000_adapter *adapter) |
| 4332 | { |
| 4333 | might_sleep(); |
| 4334 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 4335 | usleep_range(1000, 1100); |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 4336 | e1000e_down(adapter, true); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4337 | e1000e_up(adapter); |
| 4338 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 4339 | } |
| 4340 | |
| 4341 | /** |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4342 | * e1000e_sanitize_systim - sanitize raw cycle counter reads |
| 4343 | * @hw: pointer to the HW structure |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4344 | * @systim: PHC time value read, sanitized and returned |
| 4345 | * @sts: structure to hold system time before and after reading SYSTIML, |
| 4346 | * may be NULL |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4347 | * |
| 4348 | * Errata for 82574/82583 possible bad bits read from SYSTIMH/L: |
| 4349 | * check to see that the time is incrementing at a reasonable |
| 4350 | * rate and is a multiple of incvalue. |
| 4351 | **/ |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4352 | static u64 e1000e_sanitize_systim(struct e1000_hw *hw, u64 systim, |
| 4353 | struct ptp_system_timestamp *sts) |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4354 | { |
| 4355 | u64 time_delta, rem, temp; |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 4356 | u64 systim_next; |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4357 | u32 incvalue; |
| 4358 | int i; |
| 4359 | |
| 4360 | incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK; |
| 4361 | for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) { |
| 4362 | /* latch SYSTIMH on read of SYSTIML */ |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4363 | ptp_read_system_prets(sts); |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 4364 | systim_next = (u64)er32(SYSTIML); |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4365 | ptp_read_system_postts(sts); |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 4366 | systim_next |= (u64)er32(SYSTIMH) << 32; |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4367 | |
| 4368 | time_delta = systim_next - systim; |
| 4369 | temp = time_delta; |
| 4370 | /* VMWare users have seen incvalue of zero, don't div / 0 */ |
| 4371 | rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0); |
| 4372 | |
| 4373 | systim = systim_next; |
| 4374 | |
| 4375 | if ((time_delta < E1000_82574_SYSTIM_EPSILON) && (rem == 0)) |
| 4376 | break; |
| 4377 | } |
| 4378 | |
| 4379 | return systim; |
| 4380 | } |
| 4381 | |
| 4382 | /** |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4383 | * e1000e_read_systim - read SYSTIM register |
| 4384 | * @adapter: board private structure |
| 4385 | * @sts: structure which will contain system time before and after reading |
| 4386 | * SYSTIML, may be NULL |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4387 | **/ |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4388 | u64 e1000e_read_systim(struct e1000_adapter *adapter, |
| 4389 | struct ptp_system_timestamp *sts) |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4390 | { |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4391 | struct e1000_hw *hw = &adapter->hw; |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4392 | u32 systimel, systimel_2, systimeh; |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 4393 | u64 systim; |
Raanan Avargil | 37b12910 | 2015-07-19 16:33:20 +0300 | [diff] [blame] | 4394 | /* SYSTIMH latching upon SYSTIML read does not work well. |
| 4395 | * This means that if SYSTIML overflows after we read it but before |
| 4396 | * we read SYSTIMH, the value of SYSTIMH has been incremented and we |
| 4397 | * will experience a huge non linear increment in the systime value |
| 4398 | * 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] | 4399 | */ |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4400 | ptp_read_system_prets(sts); |
Denys Vlasenko | ab507c9 | 2016-04-20 17:45:56 +0200 | [diff] [blame] | 4401 | systimel = er32(SYSTIML); |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4402 | ptp_read_system_postts(sts); |
Raanan Avargil | 37b12910 | 2015-07-19 16:33:20 +0300 | [diff] [blame] | 4403 | systimeh = er32(SYSTIMH); |
Denys Vlasenko | ab507c9 | 2016-04-20 17:45:56 +0200 | [diff] [blame] | 4404 | /* Is systimel is so large that overflow is possible? */ |
| 4405 | if (systimel >= (u32)0xffffffff - E1000_TIMINCA_INCVALUE_MASK) { |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4406 | ptp_read_system_prets(sts); |
| 4407 | systimel_2 = er32(SYSTIML); |
| 4408 | ptp_read_system_postts(sts); |
Denys Vlasenko | ab507c9 | 2016-04-20 17:45:56 +0200 | [diff] [blame] | 4409 | if (systimel > systimel_2) { |
| 4410 | /* There was an overflow, read again SYSTIMH, and use |
| 4411 | * systimel_2 |
| 4412 | */ |
| 4413 | systimeh = er32(SYSTIMH); |
| 4414 | systimel = systimel_2; |
| 4415 | } |
Raanan Avargil | 37b12910 | 2015-07-19 16:33:20 +0300 | [diff] [blame] | 4416 | } |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 4417 | systim = (u64)systimel; |
| 4418 | systim |= (u64)systimeh << 32; |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4419 | |
Jarod Wilson | 0be5b96 | 2016-07-26 14:25:34 -0400 | [diff] [blame] | 4420 | if (adapter->flags2 & FLAG2_CHECK_SYSTIM_OVERFLOW) |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4421 | systim = e1000e_sanitize_systim(hw, systim, sts); |
Todd Fujinaka | 5e7ff97 | 2014-05-03 06:41:37 +0000 | [diff] [blame] | 4422 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4423 | return systim; |
| 4424 | } |
| 4425 | |
| 4426 | /** |
Miroslav Lichvar | 98942d7 | 2018-11-09 11:14:46 +0100 | [diff] [blame] | 4427 | * e1000e_cyclecounter_read - read raw cycle counter (used by time counter) |
| 4428 | * @cc: cyclecounter structure |
| 4429 | **/ |
| 4430 | static u64 e1000e_cyclecounter_read(const struct cyclecounter *cc) |
| 4431 | { |
| 4432 | struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter, |
| 4433 | cc); |
| 4434 | |
| 4435 | return e1000e_read_systim(adapter, NULL); |
| 4436 | } |
| 4437 | |
| 4438 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4439 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 4440 | * @adapter: board private structure to initialize |
| 4441 | * |
| 4442 | * e1000_sw_init initializes the Adapter private data structure. |
| 4443 | * Fields are initialized based on PCI device information and |
| 4444 | * OS network device settings (MTU size). |
| 4445 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 4446 | static int e1000_sw_init(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4447 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4448 | struct net_device *netdev = adapter->netdev; |
| 4449 | |
Alexander Duyck | 8084b86 | 2015-05-02 00:52:00 -0700 | [diff] [blame] | 4450 | adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4451 | adapter->rx_ps_bsize0 = 128; |
Alexander Duyck | 8084b86 | 2015-05-02 00:52:00 -0700 | [diff] [blame] | 4452 | adapter->max_frame_size = netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 4453 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4454 | adapter->tx_ring_count = E1000_DEFAULT_TXD; |
| 4455 | adapter->rx_ring_count = E1000_DEFAULT_RXD; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4456 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4457 | spin_lock_init(&adapter->stats64_lock); |
| 4458 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4459 | e1000e_set_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4460 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4461 | if (e1000_alloc_queues(adapter)) |
| 4462 | return -ENOMEM; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4463 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4464 | /* Setup hardware time stamping cyclecounter */ |
| 4465 | if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) { |
| 4466 | adapter->cc.read = e1000e_cyclecounter_read; |
Richard Cochran | 4d045b4 | 2015-01-02 20:22:05 +0100 | [diff] [blame] | 4467 | adapter->cc.mask = CYCLECOUNTER_MASK(64); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 4468 | adapter->cc.mult = 1; |
| 4469 | /* cc.shift set in e1000e_get_base_tininca() */ |
| 4470 | |
| 4471 | spin_lock_init(&adapter->systim_lock); |
| 4472 | INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work); |
| 4473 | } |
| 4474 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4475 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4476 | e1000_irq_disable(adapter); |
| 4477 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4478 | set_bit(__E1000_DOWN, &adapter->state); |
| 4479 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | /** |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4483 | * e1000_intr_msi_test - Interrupt Handler |
| 4484 | * @irq: interrupt number |
| 4485 | * @data: pointer to a network interface device structure |
| 4486 | **/ |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 4487 | 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] | 4488 | { |
| 4489 | struct net_device *netdev = data; |
| 4490 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4491 | struct e1000_hw *hw = &adapter->hw; |
| 4492 | u32 icr = er32(ICR); |
| 4493 | |
Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 4494 | e_dbg("icr is %08X\n", icr); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4495 | if (icr & E1000_ICR_RXSEQ) { |
| 4496 | adapter->flags &= ~FLAG_MSI_TEST_FAILED; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4497 | /* Force memory writes to complete before acknowledging the |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4498 | * interrupt is handled. |
| 4499 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4500 | wmb(); |
| 4501 | } |
| 4502 | |
| 4503 | return IRQ_HANDLED; |
| 4504 | } |
| 4505 | |
| 4506 | /** |
| 4507 | * e1000_test_msi_interrupt - Returns 0 for successful test |
| 4508 | * @adapter: board private struct |
| 4509 | * |
| 4510 | * code flow taken from tg3.c |
| 4511 | **/ |
| 4512 | static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) |
| 4513 | { |
| 4514 | struct net_device *netdev = adapter->netdev; |
| 4515 | struct e1000_hw *hw = &adapter->hw; |
| 4516 | int err; |
| 4517 | |
| 4518 | /* poll_enable hasn't been called yet, so don't need disable */ |
| 4519 | /* clear any pending events */ |
| 4520 | er32(ICR); |
| 4521 | |
| 4522 | /* free the real vector and request a test handler */ |
| 4523 | e1000_free_irq(adapter); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4524 | e1000e_reset_interrupt_capability(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4525 | |
| 4526 | /* Assume that the test fails, if it succeeds then the test |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4527 | * MSI irq handler will unset this flag |
| 4528 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4529 | adapter->flags |= FLAG_MSI_TEST_FAILED; |
| 4530 | |
| 4531 | err = pci_enable_msi(adapter->pdev); |
| 4532 | if (err) |
| 4533 | goto msi_test_failed; |
| 4534 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 4535 | err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4536 | netdev->name, netdev); |
| 4537 | if (err) { |
| 4538 | pci_disable_msi(adapter->pdev); |
| 4539 | goto msi_test_failed; |
| 4540 | } |
| 4541 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4542 | /* Force memory writes to complete before enabling and firing an |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4543 | * interrupt. |
| 4544 | */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4545 | wmb(); |
| 4546 | |
| 4547 | e1000_irq_enable(adapter); |
| 4548 | |
| 4549 | /* fire an unusual interrupt on the test handler */ |
| 4550 | ew32(ICS, E1000_ICS_RXSEQ); |
| 4551 | e1e_flush(); |
Prasanna S Panchamukhi | 569a3af | 2012-04-19 17:01:00 +0000 | [diff] [blame] | 4552 | msleep(100); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4553 | |
| 4554 | e1000_irq_disable(adapter); |
| 4555 | |
Bruce Allan | bc76329 | 2012-08-17 06:18:07 +0000 | [diff] [blame] | 4556 | rmb(); /* read flags after interrupt has been fired */ |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4557 | |
| 4558 | if (adapter->flags & FLAG_MSI_TEST_FAILED) { |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4559 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4560 | e_info("MSI interrupt test failed, using legacy interrupt.\n"); |
Bruce Allan | 24b706b | 2012-01-31 06:37:22 +0000 | [diff] [blame] | 4561 | } else { |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4562 | e_dbg("MSI interrupt test succeeded!\n"); |
Bruce Allan | 24b706b | 2012-01-31 06:37:22 +0000 | [diff] [blame] | 4563 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4564 | |
| 4565 | free_irq(adapter->pdev->irq, netdev); |
| 4566 | pci_disable_msi(adapter->pdev); |
| 4567 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4568 | msi_test_failed: |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4569 | e1000e_set_interrupt_capability(adapter); |
Jean Delvare | 068e8a3 | 2010-09-12 22:45:39 +0000 | [diff] [blame] | 4570 | return e1000_request_irq(adapter); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4571 | } |
| 4572 | |
| 4573 | /** |
| 4574 | * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored |
| 4575 | * @adapter: board private struct |
| 4576 | * |
| 4577 | * code flow taken from tg3.c, called with e1000 interrupts disabled. |
| 4578 | **/ |
| 4579 | static int e1000_test_msi(struct e1000_adapter *adapter) |
| 4580 | { |
| 4581 | int err; |
| 4582 | u16 pci_cmd; |
| 4583 | |
| 4584 | if (!(adapter->flags & FLAG_MSI_ENABLED)) |
| 4585 | return 0; |
| 4586 | |
| 4587 | /* disable SERR in case the MSI write causes a master abort */ |
| 4588 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 4589 | if (pci_cmd & PCI_COMMAND_SERR) |
| 4590 | pci_write_config_word(adapter->pdev, PCI_COMMAND, |
| 4591 | pci_cmd & ~PCI_COMMAND_SERR); |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4592 | |
| 4593 | err = e1000_test_msi_interrupt(adapter); |
| 4594 | |
Dean Nelson | 36f2407 | 2010-06-29 18:12:05 +0000 | [diff] [blame] | 4595 | /* re-enable SERR */ |
| 4596 | if (pci_cmd & PCI_COMMAND_SERR) { |
| 4597 | pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); |
| 4598 | pci_cmd |= PCI_COMMAND_SERR; |
| 4599 | pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); |
| 4600 | } |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4601 | |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4602 | return err; |
| 4603 | } |
| 4604 | |
| 4605 | /** |
Stefan Assmann | d5ea45d | 2016-02-03 09:20:52 +0100 | [diff] [blame] | 4606 | * e1000e_open - Called when a network interface is made active |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4607 | * @netdev: network interface device structure |
| 4608 | * |
| 4609 | * Returns 0 on success, negative value on failure |
| 4610 | * |
| 4611 | * The open entry point is called when a network interface is made |
| 4612 | * active by the system (IFF_UP). At this point all resources needed |
| 4613 | * for transmit and receive operations are allocated, the interrupt |
| 4614 | * handler is registered with the OS, the watchdog timer is started, |
| 4615 | * and the stack is notified that the interface is ready. |
| 4616 | **/ |
Stefan Assmann | d5ea45d | 2016-02-03 09:20:52 +0100 | [diff] [blame] | 4617 | int e1000e_open(struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4618 | { |
| 4619 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 4620 | struct e1000_hw *hw = &adapter->hw; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4621 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4622 | int err; |
| 4623 | |
| 4624 | /* disallow open during test */ |
| 4625 | if (test_bit(__E1000_TESTING, &adapter->state)) |
| 4626 | return -EBUSY; |
| 4627 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4628 | pm_runtime_get_sync(&pdev->dev); |
| 4629 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 4630 | netif_carrier_off(netdev); |
Konstantin Khlebnikov | d17ba0f | 2019-04-17 11:13:20 +0300 | [diff] [blame] | 4631 | netif_stop_queue(netdev); |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 4632 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4633 | /* allocate transmit descriptors */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4634 | err = e1000e_setup_tx_resources(adapter->tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4635 | if (err) |
| 4636 | goto err_setup_tx; |
| 4637 | |
| 4638 | /* allocate receive descriptors */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4639 | err = e1000e_setup_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4640 | if (err) |
| 4641 | goto err_setup_rx; |
| 4642 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4643 | /* If AMT is enabled, let the firmware know that the network |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 4644 | * interface is now open and reset the part to a known state. |
| 4645 | */ |
| 4646 | if (adapter->flags & FLAG_HAS_AMT) { |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4647 | e1000e_get_hw_control(adapter); |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 4648 | e1000e_reset(adapter); |
| 4649 | } |
| 4650 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4651 | e1000e_power_up_phy(adapter); |
| 4652 | |
| 4653 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 4654 | if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4655 | e1000_update_mng_vlan(adapter); |
| 4656 | |
Bruce Allan | 79d4e90 | 2011-12-16 00:46:27 +0000 | [diff] [blame] | 4657 | /* DMA latency requirement to workaround jumbo issue */ |
Rafael J. Wysocki | 81e95ad | 2020-02-12 00:24:36 +0100 | [diff] [blame] | 4658 | 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] | 4659 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4660 | /* before we allocate an interrupt, we must be ready to handle it. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4661 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 4662 | * 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] | 4663 | * clean_rx handler before we do so. |
| 4664 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4665 | e1000_configure(adapter); |
| 4666 | |
| 4667 | err = e1000_request_irq(adapter); |
| 4668 | if (err) |
| 4669 | goto err_req_irq; |
| 4670 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4671 | /* Work around PCIe errata with MSI interrupts causing some chipsets to |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4672 | * ignore e1000e MSI messages, which means we need to test our MSI |
| 4673 | * interrupt now |
| 4674 | */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 4675 | if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { |
Bruce Allan | f8d59f7 | 2008-08-08 18:36:11 -0700 | [diff] [blame] | 4676 | err = e1000_test_msi(adapter); |
| 4677 | if (err) { |
| 4678 | e_err("Interrupt allocation failed\n"); |
| 4679 | goto err_req_irq; |
| 4680 | } |
| 4681 | } |
| 4682 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4683 | /* From here on the code is the same as e1000e_up() */ |
| 4684 | clear_bit(__E1000_DOWN, &adapter->state); |
| 4685 | |
| 4686 | napi_enable(&adapter->napi); |
| 4687 | |
| 4688 | e1000_irq_enable(adapter); |
| 4689 | |
Jeff Kirsher | 09357b0 | 2011-11-18 14:25:00 +0000 | [diff] [blame] | 4690 | adapter->tx_hang_recheck = false; |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4691 | |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 4692 | hw->mac.get_link_status = true; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4693 | pm_runtime_put(&pdev->dev); |
| 4694 | |
Benjamin Poirier | a61cfe4 | 2015-11-09 15:50:20 -0800 | [diff] [blame] | 4695 | e1000e_trigger_lsc(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4696 | |
| 4697 | return 0; |
| 4698 | |
| 4699 | err_req_irq: |
Rafael J. Wysocki | 81e95ad | 2020-02-12 00:24:36 +0100 | [diff] [blame] | 4700 | cpu_latency_qos_remove_request(&adapter->pm_qos_req); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4701 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4702 | e1000_power_down_phy(adapter); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4703 | e1000e_free_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4704 | err_setup_rx: |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4705 | e1000e_free_tx_resources(adapter->tx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4706 | err_setup_tx: |
| 4707 | e1000e_reset(adapter); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4708 | pm_runtime_put_sync(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4709 | |
| 4710 | return err; |
| 4711 | } |
| 4712 | |
| 4713 | /** |
Stefan Assmann | d5ea45d | 2016-02-03 09:20:52 +0100 | [diff] [blame] | 4714 | * e1000e_close - Disables a network interface |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4715 | * @netdev: network interface device structure |
| 4716 | * |
| 4717 | * Returns 0, this is not allowed to fail |
| 4718 | * |
| 4719 | * The close entry point is called when an interface is de-activated |
| 4720 | * by the OS. The hardware is still under the drivers control, but |
| 4721 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4722 | * hardware, and all transmit and receive resources are freed. |
| 4723 | **/ |
Stefan Assmann | d5ea45d | 2016-02-03 09:20:52 +0100 | [diff] [blame] | 4724 | int e1000e_close(struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4725 | { |
| 4726 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4727 | struct pci_dev *pdev = adapter->pdev; |
Bruce Allan | bb9e44d | 2012-03-21 00:39:12 +0000 | [diff] [blame] | 4728 | int count = E1000_CHECK_RESET_COUNT; |
| 4729 | |
| 4730 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 4731 | usleep_range(10000, 11000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4732 | |
| 4733 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4734 | |
| 4735 | pm_runtime_get_sync(&pdev->dev); |
| 4736 | |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 4737 | if (netif_device_present(netdev)) { |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 4738 | e1000e_down(adapter, true); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4739 | e1000_free_irq(adapter); |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 4740 | |
| 4741 | /* Link status message must follow this format */ |
Alexander Duyck | c557a4b | 2019-10-31 09:58:51 -0700 | [diff] [blame] | 4742 | netdev_info(netdev, "NIC Link is Down\n"); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4743 | } |
Bruce Allan | a3b87a4 | 2013-04-20 05:37:29 +0000 | [diff] [blame] | 4744 | |
| 4745 | napi_disable(&adapter->napi); |
| 4746 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 4747 | e1000e_free_tx_resources(adapter->tx_ring); |
| 4748 | e1000e_free_rx_resources(adapter->rx_ring); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4749 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4750 | /* kill manageability vlan ID if supported, but not if a vlan with |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4751 | * the same ID is registered on the host OS (let 8021q kill it) |
| 4752 | */ |
Bruce Allan | e5fe254 | 2013-02-20 04:06:27 +0000 | [diff] [blame] | 4753 | if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4754 | e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), |
| 4755 | adapter->mng_vlan_id); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4756 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4757 | /* If AMT is enabled, let the firmware know that the network |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4758 | * interface is now closed |
| 4759 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 4760 | if ((adapter->flags & FLAG_HAS_AMT) && |
| 4761 | !test_bit(__E1000_TESTING, &adapter->state)) |
| 4762 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4763 | |
Rafael J. Wysocki | 81e95ad | 2020-02-12 00:24:36 +0100 | [diff] [blame] | 4764 | cpu_latency_qos_remove_request(&adapter->pm_qos_req); |
Florian Mickler | c128ec2 | 2010-08-02 14:27:00 +0000 | [diff] [blame] | 4765 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 4766 | pm_runtime_put_sync(&pdev->dev); |
| 4767 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4768 | return 0; |
| 4769 | } |
Bruce Allan | fc830b7 | 2013-02-20 04:06:11 +0000 | [diff] [blame] | 4770 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4771 | /** |
| 4772 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 4773 | * @netdev: network interface device structure |
| 4774 | * @p: pointer to an address structure |
| 4775 | * |
| 4776 | * Returns 0 on success, negative on failure |
| 4777 | **/ |
| 4778 | static int e1000_set_mac(struct net_device *netdev, void *p) |
| 4779 | { |
| 4780 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4781 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4782 | struct sockaddr *addr = p; |
| 4783 | |
| 4784 | if (!is_valid_ether_addr(addr->sa_data)) |
| 4785 | return -EADDRNOTAVAIL; |
| 4786 | |
| 4787 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 4788 | memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 4789 | |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4790 | hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4791 | |
| 4792 | if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { |
| 4793 | /* activate the work around */ |
| 4794 | e1000e_set_laa_state_82571(&adapter->hw, 1); |
| 4795 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4796 | /* 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] | 4797 | * between the time RAR[0] gets clobbered and the time it |
| 4798 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
| 4799 | * of the RARs and no incoming packets directed to this port |
| 4800 | * are dropped. Eventually the LAA will be in RAR[0] and |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4801 | * RAR[14] |
| 4802 | */ |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 4803 | hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, |
| 4804 | adapter->hw.mac.rar_entry_count - 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | return 0; |
| 4808 | } |
| 4809 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4810 | /** |
| 4811 | * e1000e_update_phy_task - work thread to update phy |
| 4812 | * @work: pointer to our work struct |
| 4813 | * |
| 4814 | * this worker thread exists because we must acquire a |
| 4815 | * semaphore to read the phy, which we could msleep while |
| 4816 | * waiting for it, and we can't msleep in a timer. |
| 4817 | **/ |
| 4818 | static void e1000e_update_phy_task(struct work_struct *work) |
| 4819 | { |
| 4820 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 4821 | struct e1000_adapter, |
| 4822 | update_phy_task); |
David Ertman | a03206e | 2014-01-24 23:07:48 +0000 | [diff] [blame] | 4823 | struct e1000_hw *hw = &adapter->hw; |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4824 | |
| 4825 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4826 | return; |
| 4827 | |
David Ertman | a03206e | 2014-01-24 23:07:48 +0000 | [diff] [blame] | 4828 | e1000_get_phy_info(hw); |
| 4829 | |
| 4830 | /* Enable EEE on 82579 after link up */ |
David Ertman | 50844bb | 2014-05-13 00:06:26 +0000 | [diff] [blame] | 4831 | if (hw->phy.type >= e1000_phy_82579) |
David Ertman | a03206e | 2014-01-24 23:07:48 +0000 | [diff] [blame] | 4832 | e1000_set_eee_pchlan(hw); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4833 | } |
| 4834 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4835 | /** |
| 4836 | * e1000_update_phy_info - timre call-back to update PHY info |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 4837 | * @t: pointer to timer_list containing private info adapter |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4838 | * |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 4839 | * Need to wait a few seconds after link up to get diagnostic information from |
| 4840 | * the phy |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4841 | **/ |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 4842 | static void e1000_update_phy_info(struct timer_list *t) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4843 | { |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 4844 | struct e1000_adapter *adapter = from_timer(adapter, t, phy_info_timer); |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 4845 | |
| 4846 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 4847 | return; |
| 4848 | |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 4849 | schedule_work(&adapter->update_phy_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4850 | } |
| 4851 | |
| 4852 | /** |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4853 | * e1000e_update_phy_stats - Update the PHY statistics counters |
| 4854 | * @adapter: board private structure |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4855 | * |
| 4856 | * Read/clear the upper 16-bit PHY registers and read/accumulate lower |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4857 | **/ |
| 4858 | static void e1000e_update_phy_stats(struct e1000_adapter *adapter) |
| 4859 | { |
| 4860 | struct e1000_hw *hw = &adapter->hw; |
| 4861 | s32 ret_val; |
| 4862 | u16 phy_data; |
| 4863 | |
| 4864 | ret_val = hw->phy.ops.acquire(hw); |
| 4865 | if (ret_val) |
| 4866 | return; |
| 4867 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4868 | /* A page set is expensive so check if already on desired page. |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4869 | * If not, set to the page with the PHY status registers. |
| 4870 | */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4871 | hw->phy.addr = 1; |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4872 | ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 4873 | &phy_data); |
| 4874 | if (ret_val) |
| 4875 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4876 | if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) { |
| 4877 | ret_val = hw->phy.ops.set_page(hw, |
| 4878 | HV_STATS_PAGE << IGP_PAGE_SHIFT); |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4879 | if (ret_val) |
| 4880 | goto release; |
| 4881 | } |
| 4882 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4883 | /* Single Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4884 | hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data); |
| 4885 | 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] | 4886 | if (!ret_val) |
| 4887 | adapter->stats.scc += phy_data; |
| 4888 | |
| 4889 | /* Excessive Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4890 | hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data); |
| 4891 | 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] | 4892 | if (!ret_val) |
| 4893 | adapter->stats.ecol += phy_data; |
| 4894 | |
| 4895 | /* Multiple Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4896 | hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data); |
| 4897 | 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] | 4898 | if (!ret_val) |
| 4899 | adapter->stats.mcc += phy_data; |
| 4900 | |
| 4901 | /* Late Collision Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4902 | hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data); |
| 4903 | 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] | 4904 | if (!ret_val) |
| 4905 | adapter->stats.latecol += phy_data; |
| 4906 | |
| 4907 | /* Collision Count - also used for adaptive IFS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4908 | hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data); |
| 4909 | 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] | 4910 | if (!ret_val) |
| 4911 | hw->mac.collision_delta = phy_data; |
| 4912 | |
| 4913 | /* Defer Count */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4914 | hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data); |
| 4915 | 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] | 4916 | if (!ret_val) |
| 4917 | adapter->stats.dc += phy_data; |
| 4918 | |
| 4919 | /* Transmit with no CRS */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 4920 | hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data); |
| 4921 | 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] | 4922 | if (!ret_val) |
| 4923 | adapter->stats.tncrs += phy_data; |
| 4924 | |
| 4925 | release: |
| 4926 | hw->phy.ops.release(hw); |
| 4927 | } |
| 4928 | |
| 4929 | /** |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4930 | * e1000e_update_stats - Update the board statistics counters |
| 4931 | * @adapter: board private structure |
| 4932 | **/ |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 4933 | static void e1000e_update_stats(struct e1000_adapter *adapter) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4934 | { |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 4935 | struct net_device *netdev = adapter->netdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4936 | struct e1000_hw *hw = &adapter->hw; |
| 4937 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4938 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 4939 | /* Prevent stats update while adapter is being reset, or if the pci |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4940 | * connection is down. |
| 4941 | */ |
| 4942 | if (adapter->link_speed == 0) |
| 4943 | return; |
| 4944 | if (pci_channel_offline(pdev)) |
| 4945 | return; |
| 4946 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4947 | adapter->stats.crcerrs += er32(CRCERRS); |
| 4948 | adapter->stats.gprc += er32(GPRC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4949 | adapter->stats.gorc += er32(GORCL); |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 4950 | er32(GORCH); /* Clear gorc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4951 | adapter->stats.bprc += er32(BPRC); |
| 4952 | adapter->stats.mprc += er32(MPRC); |
| 4953 | adapter->stats.roc += er32(ROC); |
| 4954 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4955 | adapter->stats.mpc += er32(MPC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4956 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4957 | /* Half-duplex statistics */ |
| 4958 | if (adapter->link_duplex == HALF_DUPLEX) { |
| 4959 | if (adapter->flags2 & FLAG2_HAS_PHY_STATS) { |
| 4960 | e1000e_update_phy_stats(adapter); |
| 4961 | } else { |
| 4962 | adapter->stats.scc += er32(SCC); |
| 4963 | adapter->stats.ecol += er32(ECOL); |
| 4964 | adapter->stats.mcc += er32(MCC); |
| 4965 | adapter->stats.latecol += er32(LATECOL); |
| 4966 | adapter->stats.dc += er32(DC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4967 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4968 | hw->mac.collision_delta = er32(COLC); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4969 | |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4970 | if ((hw->mac.type != e1000_82574) && |
| 4971 | (hw->mac.type != e1000_82583)) |
| 4972 | adapter->stats.tncrs += er32(TNCRS); |
| 4973 | } |
| 4974 | adapter->stats.colc += hw->mac.collision_delta; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 4975 | } |
Bruce Allan | 8c7bbb9 | 2010-06-16 13:26:41 +0000 | [diff] [blame] | 4976 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4977 | adapter->stats.xonrxc += er32(XONRXC); |
| 4978 | adapter->stats.xontxc += er32(XONTXC); |
| 4979 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 4980 | adapter->stats.xofftxc += er32(XOFFTXC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4981 | adapter->stats.gptc += er32(GPTC); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 4982 | adapter->stats.gotc += er32(GOTCL); |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 4983 | er32(GOTCH); /* Clear gotc */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4984 | adapter->stats.rnbc += er32(RNBC); |
| 4985 | adapter->stats.ruc += er32(RUC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4986 | |
| 4987 | adapter->stats.mptc += er32(MPTC); |
| 4988 | adapter->stats.bptc += er32(BPTC); |
| 4989 | |
| 4990 | /* used for adaptive IFS */ |
| 4991 | |
| 4992 | hw->mac.tx_packet_delta = er32(TPT); |
| 4993 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4994 | |
| 4995 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 4996 | adapter->stats.rxerrc += er32(RXERRC); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 4997 | adapter->stats.cexterr += er32(CEXTERR); |
| 4998 | adapter->stats.tsctc += er32(TSCTC); |
| 4999 | adapter->stats.tsctfc += er32(TSCTFC); |
| 5000 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5001 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 5002 | netdev->stats.multicast = adapter->stats.mprc; |
| 5003 | netdev->stats.collisions = adapter->stats.colc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5004 | |
| 5005 | /* Rx Errors */ |
| 5006 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5007 | /* RLEC on some newer hardware can be incorrect so build |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5008 | * our own version based on RUC and ROC |
| 5009 | */ |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 5010 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5011 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 5012 | adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 5013 | netdev->stats.rx_length_errors = adapter->stats.ruc + |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5014 | adapter->stats.roc; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 5015 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 5016 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; |
| 5017 | netdev->stats.rx_missed_errors = adapter->stats.mpc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5018 | |
| 5019 | /* Tx Errors */ |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5020 | netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol; |
Ajit Khaparde | 7274c20 | 2009-10-07 02:44:26 +0000 | [diff] [blame] | 5021 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
| 5022 | netdev->stats.tx_window_errors = adapter->stats.latecol; |
| 5023 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5024 | |
| 5025 | /* Tx Dropped needs to be maintained elsewhere */ |
| 5026 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5027 | /* Management Stats */ |
| 5028 | adapter->stats.mgptc += er32(MGTPTC); |
| 5029 | adapter->stats.mgprc += er32(MGTPRC); |
| 5030 | adapter->stats.mgpdc += er32(MGTPDC); |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 5031 | |
| 5032 | /* Correctable ECC Errors */ |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 5033 | if (hw->mac.type >= e1000_pch_lpt) { |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 5034 | u32 pbeccsts = er32(PBECCSTS); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 5035 | |
Bruce Allan | 94fb848 | 2013-01-23 09:00:03 +0000 | [diff] [blame] | 5036 | adapter->corr_errors += |
| 5037 | pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK; |
| 5038 | adapter->uncorr_errors += |
| 5039 | (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >> |
| 5040 | E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT; |
| 5041 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5042 | } |
| 5043 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5044 | /** |
| 5045 | * e1000_phy_read_status - Update the PHY register status snapshot |
| 5046 | * @adapter: board private structure |
| 5047 | **/ |
| 5048 | static void e1000_phy_read_status(struct e1000_adapter *adapter) |
| 5049 | { |
| 5050 | struct e1000_hw *hw = &adapter->hw; |
| 5051 | struct e1000_phy_regs *phy = &adapter->phy_regs; |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5052 | |
Bruce Allan | 97390ab | 2013-06-29 07:42:25 +0000 | [diff] [blame] | 5053 | if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) && |
| 5054 | (er32(STATUS) & E1000_STATUS_LU) && |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5055 | (adapter->hw.phy.media_type == e1000_media_type_copper)) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 5056 | int ret_val; |
| 5057 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 5058 | ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr); |
| 5059 | ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr); |
| 5060 | ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise); |
| 5061 | ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa); |
| 5062 | ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion); |
| 5063 | ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000); |
| 5064 | ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000); |
| 5065 | ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5066 | if (ret_val) |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5067 | e_warn("Error reading PHY register\n"); |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5068 | } else { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5069 | /* Do not read PHY registers if link is not up |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5070 | * Set values to typical power-on defaults |
| 5071 | */ |
| 5072 | phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); |
| 5073 | phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | |
| 5074 | BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | |
| 5075 | BMSR_ERCAP); |
| 5076 | phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | |
| 5077 | ADVERTISE_ALL | ADVERTISE_CSMA); |
| 5078 | phy->lpa = 0; |
| 5079 | phy->expansion = EXPANSION_ENABLENPAGE; |
| 5080 | phy->ctrl1000 = ADVERTISE_1000FULL; |
| 5081 | phy->stat1000 = 0; |
| 5082 | phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); |
| 5083 | } |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5086 | static void e1000_print_link_info(struct e1000_adapter *adapter) |
| 5087 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5088 | struct e1000_hw *hw = &adapter->hw; |
| 5089 | u32 ctrl = er32(CTRL); |
| 5090 | |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 5091 | /* Link status message must follow this format for user tools */ |
Alexander Duyck | c557a4b | 2019-10-31 09:58:51 -0700 | [diff] [blame] | 5092 | netdev_info(adapter->netdev, |
| 5093 | "NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n", |
| 5094 | adapter->link_speed, |
| 5095 | adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half", |
| 5096 | (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" : |
| 5097 | (ctrl & E1000_CTRL_RFCE) ? "Rx" : |
| 5098 | (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5099 | } |
| 5100 | |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 5101 | static bool e1000e_has_link(struct e1000_adapter *adapter) |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5102 | { |
| 5103 | struct e1000_hw *hw = &adapter->hw; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5104 | bool link_active = false; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5105 | s32 ret_val = 0; |
| 5106 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5107 | /* get_link_status is set on LSC (link status) interrupt or |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5108 | * Rx sequence error interrupt. get_link_status will stay |
Benjamin Poirier | 65a29da | 2017-07-21 11:36:24 -0700 | [diff] [blame] | 5109 | * true until the check_for_link establishes link |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5110 | * for copper adapters ONLY |
| 5111 | */ |
| 5112 | switch (hw->phy.media_type) { |
| 5113 | case e1000_media_type_copper: |
| 5114 | if (hw->mac.get_link_status) { |
| 5115 | ret_val = hw->mac.ops.check_for_link(hw); |
Benjamin Poirier | 3016e0a | 2018-03-06 10:55:52 +0900 | [diff] [blame] | 5116 | link_active = !hw->mac.get_link_status; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5117 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5118 | link_active = true; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5119 | } |
| 5120 | break; |
| 5121 | case e1000_media_type_fiber: |
| 5122 | ret_val = hw->mac.ops.check_for_link(hw); |
| 5123 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 5124 | break; |
| 5125 | case e1000_media_type_internal_serdes: |
| 5126 | ret_val = hw->mac.ops.check_for_link(hw); |
Benjamin Poirier | 65a29da | 2017-07-21 11:36:24 -0700 | [diff] [blame] | 5127 | link_active = hw->mac.serdes_has_link; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5128 | break; |
| 5129 | default: |
| 5130 | case e1000_media_type_unknown: |
| 5131 | break; |
| 5132 | } |
| 5133 | |
Benjamin Poirier | d3509f8 | 2017-07-21 11:36:25 -0700 | [diff] [blame] | 5134 | 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] | 5135 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 5136 | /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5137 | e_info("Gigabit has been disabled, downgrading speed\n"); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | return link_active; |
| 5141 | } |
| 5142 | |
| 5143 | static void e1000e_enable_receives(struct e1000_adapter *adapter) |
| 5144 | { |
| 5145 | /* make sure the receive unit is started */ |
| 5146 | if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5147 | (adapter->flags & FLAG_RESTART_NOW)) { |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5148 | struct e1000_hw *hw = &adapter->hw; |
| 5149 | u32 rctl = er32(RCTL); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 5150 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5151 | ew32(RCTL, rctl | E1000_RCTL_EN); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5152 | adapter->flags &= ~FLAG_RESTART_NOW; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5153 | } |
| 5154 | } |
| 5155 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 5156 | static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter) |
| 5157 | { |
| 5158 | struct e1000_hw *hw = &adapter->hw; |
| 5159 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5160 | /* With 82574 controllers, PHY needs to be checked periodically |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 5161 | * for hung state and reset, if two calls return true |
| 5162 | */ |
| 5163 | if (e1000_check_phy_82574(hw)) |
| 5164 | adapter->phy_hang_count++; |
| 5165 | else |
| 5166 | adapter->phy_hang_count = 0; |
| 5167 | |
| 5168 | if (adapter->phy_hang_count > 1) { |
| 5169 | adapter->phy_hang_count = 0; |
David Ertman | d9554e9 | 2014-01-08 01:07:55 +0000 | [diff] [blame] | 5170 | e_dbg("PHY appears hung - resetting\n"); |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 5171 | schedule_work(&adapter->reset_task); |
| 5172 | } |
| 5173 | } |
| 5174 | |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 5175 | /** |
| 5176 | * e1000_watchdog - Timer Call-back |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 5177 | * @t: pointer to timer_list containing private info adapter |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 5178 | **/ |
| 5179 | static void e1000_watchdog(struct timer_list *t) |
| 5180 | { |
| 5181 | struct e1000_adapter *adapter = from_timer(adapter, t, watchdog_timer); |
| 5182 | |
| 5183 | /* Do the rest outside of interrupt context */ |
| 5184 | schedule_work(&adapter->watchdog_task); |
| 5185 | |
| 5186 | /* TODO: make this use queue_delayed_work() */ |
| 5187 | } |
| 5188 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5189 | static void e1000_watchdog_task(struct work_struct *work) |
| 5190 | { |
| 5191 | struct e1000_adapter *adapter = container_of(work, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5192 | struct e1000_adapter, |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 5193 | watchdog_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5194 | struct net_device *netdev = adapter->netdev; |
| 5195 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 5196 | struct e1000_phy_info *phy = &adapter->hw.phy; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5197 | struct e1000_ring *tx_ring = adapter->tx_ring; |
Vitaly Lifshits | def4ec6 | 2019-06-25 17:39:11 +0300 | [diff] [blame] | 5198 | u32 dmoff_exit_timeout = 100, tries = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5199 | struct e1000_hw *hw = &adapter->hw; |
Vitaly Lifshits | def4ec6 | 2019-06-25 17:39:11 +0300 | [diff] [blame] | 5200 | u32 link, tctl, pcim_state; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5201 | |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 5202 | if (test_bit(__E1000_DOWN, &adapter->state)) |
| 5203 | return; |
| 5204 | |
David S. Miller | b405e8d | 2010-02-04 22:31:41 -0800 | [diff] [blame] | 5205 | link = e1000e_has_link(adapter); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5206 | if ((netif_carrier_ok(netdev)) && link) { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5207 | /* Cancel scheduled suspend requests. */ |
| 5208 | pm_runtime_resume(netdev->dev.parent); |
| 5209 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5210 | e1000e_enable_receives(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5211 | goto link_up; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | if ((e1000e_enable_tx_pkt_filtering(hw)) && |
| 5215 | (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) |
| 5216 | e1000_update_mng_vlan(adapter); |
| 5217 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5218 | if (link) { |
| 5219 | if (!netif_carrier_ok(netdev)) { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5220 | bool txb2b = true; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5221 | |
| 5222 | /* Cancel scheduled suspend requests. */ |
| 5223 | pm_runtime_resume(netdev->dev.parent); |
| 5224 | |
Vitaly Lifshits | def4ec6 | 2019-06-25 17:39:11 +0300 | [diff] [blame] | 5225 | /* Checking if MAC is in DMoff state*/ |
Sasha Neftin | 2e7256f | 2021-06-24 12:02:48 -0700 | [diff] [blame] | 5226 | if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) { |
Vitaly Lifshits | def4ec6 | 2019-06-25 17:39:11 +0300 | [diff] [blame] | 5227 | pcim_state = er32(STATUS); |
Sasha Neftin | 2e7256f | 2021-06-24 12:02:48 -0700 | [diff] [blame] | 5228 | while (pcim_state & E1000_STATUS_PCIM_STATE) { |
| 5229 | if (tries++ == dmoff_exit_timeout) { |
| 5230 | e_dbg("Error in exiting dmoff\n"); |
| 5231 | break; |
| 5232 | } |
| 5233 | usleep_range(10000, 20000); |
| 5234 | pcim_state = er32(STATUS); |
Vitaly Lifshits | def4ec6 | 2019-06-25 17:39:11 +0300 | [diff] [blame] | 5235 | |
Sasha Neftin | 2e7256f | 2021-06-24 12:02:48 -0700 | [diff] [blame] | 5236 | /* Checking if MAC exited DMoff state */ |
| 5237 | if (!(pcim_state & E1000_STATUS_PCIM_STATE)) |
| 5238 | e1000_phy_hw_reset(&adapter->hw); |
| 5239 | } |
Vitaly Lifshits | def4ec6 | 2019-06-25 17:39:11 +0300 | [diff] [blame] | 5240 | } |
| 5241 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 5242 | /* update snapshot of PHY registers on LSC */ |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5243 | e1000_phy_read_status(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5244 | mac->ops.get_link_up_info(&adapter->hw, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5245 | &adapter->link_speed, |
| 5246 | &adapter->link_duplex); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5247 | e1000_print_link_info(adapter); |
Koki Sanagi | e792cd9 | 2013-02-03 14:03:55 +0000 | [diff] [blame] | 5248 | |
| 5249 | /* check if SmartSpeed worked */ |
| 5250 | e1000e_check_downshift(hw); |
| 5251 | if (phy->speed_downgraded) |
| 5252 | netdev_warn(netdev, |
| 5253 | "Link Speed was downgraded by SmartSpeed\n"); |
| 5254 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5255 | /* On supported PHYs, check for duplex mismatch only |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 5256 | * if link has autonegotiated at 10/100 half |
| 5257 | */ |
| 5258 | if ((hw->phy.type == e1000_phy_igp_3 || |
| 5259 | hw->phy.type == e1000_phy_bm) && |
David Ertman | 138953b | 2013-08-30 05:45:25 +0000 | [diff] [blame] | 5260 | hw->mac.autoneg && |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 5261 | (adapter->link_speed == SPEED_10 || |
| 5262 | adapter->link_speed == SPEED_100) && |
| 5263 | (adapter->link_duplex == HALF_DUPLEX)) { |
| 5264 | u16 autoneg_exp; |
| 5265 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 5266 | e1e_rphy(hw, MII_EXPANSION, &autoneg_exp); |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 5267 | |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 5268 | if (!(autoneg_exp & EXPANSION_NWAY)) |
Jeff Kirsher | ef456f8 | 2011-11-03 11:40:28 +0000 | [diff] [blame] | 5269 | 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] | 5270 | } |
| 5271 | |
Emil Tantilov | f49c57e | 2010-03-24 12:55:02 +0000 | [diff] [blame] | 5272 | /* adjust timeout factor according to speed/duplex */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5273 | adapter->tx_timeout_factor = 1; |
| 5274 | switch (adapter->link_speed) { |
| 5275 | case SPEED_10: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5276 | txb2b = false; |
Bruce Allan | 10f1b49 | 2008-08-08 18:36:01 -0700 | [diff] [blame] | 5277 | adapter->tx_timeout_factor = 16; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5278 | break; |
| 5279 | case SPEED_100: |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5280 | txb2b = false; |
Bruce Allan | 4c86e0b | 2009-11-19 12:35:26 +0000 | [diff] [blame] | 5281 | adapter->tx_timeout_factor = 10; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5282 | break; |
| 5283 | } |
| 5284 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5285 | /* workaround: re-program speed mode bit after |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5286 | * link-up event |
| 5287 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5288 | if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && |
| 5289 | !txb2b) { |
| 5290 | u32 tarc0; |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 5291 | |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 5292 | tarc0 = er32(TARC(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5293 | tarc0 &= ~SPEED_MODE_BIT; |
Jeff Kirsher | e9ec2c0 | 2008-04-02 13:48:13 -0700 | [diff] [blame] | 5294 | ew32(TARC(0), tarc0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5295 | } |
| 5296 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5297 | /* disable TSO for pcie and 10/100 speeds, to avoid |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5298 | * some hardware issues |
| 5299 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5300 | if (!(adapter->flags & FLAG_TSO_FORCE)) { |
| 5301 | switch (adapter->link_speed) { |
| 5302 | case SPEED_10: |
| 5303 | case SPEED_100: |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5304 | e_info("10/100 speed: disabling TSO\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5305 | netdev->features &= ~NETIF_F_TSO; |
| 5306 | netdev->features &= ~NETIF_F_TSO6; |
| 5307 | break; |
| 5308 | case SPEED_1000: |
| 5309 | netdev->features |= NETIF_F_TSO; |
| 5310 | netdev->features |= NETIF_F_TSO6; |
| 5311 | break; |
| 5312 | default: |
| 5313 | /* oops */ |
| 5314 | break; |
| 5315 | } |
Kai-Heng Feng | f298010 | 2020-05-07 22:21:07 +0800 | [diff] [blame] | 5316 | if (hw->mac.type == e1000_pch_spt) { |
| 5317 | netdev->features &= ~NETIF_F_TSO; |
| 5318 | netdev->features &= ~NETIF_F_TSO6; |
| 5319 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5320 | } |
| 5321 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5322 | /* enable transmits in the hardware, need to do this |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5323 | * after setting TARC(0) |
| 5324 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5325 | tctl = er32(TCTL); |
| 5326 | tctl |= E1000_TCTL_EN; |
| 5327 | ew32(TCTL, tctl); |
| 5328 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5329 | /* Perform any post-link-up configuration before |
Bruce Allan | 75eb0fa | 2008-11-21 16:53:51 -0800 | [diff] [blame] | 5330 | * reporting link up. |
| 5331 | */ |
| 5332 | if (phy->ops.cfg_on_link_up) |
| 5333 | phy->ops.cfg_on_link_up(hw); |
| 5334 | |
Konstantin Khlebnikov | d17ba0f | 2019-04-17 11:13:20 +0300 | [diff] [blame] | 5335 | netif_wake_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5336 | netif_carrier_on(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5337 | |
| 5338 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 5339 | mod_timer(&adapter->phy_info_timer, |
| 5340 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5341 | } |
| 5342 | } else { |
| 5343 | if (netif_carrier_ok(netdev)) { |
| 5344 | adapter->link_speed = 0; |
| 5345 | adapter->link_duplex = 0; |
Bruce Allan | 8f12fe8 | 2008-11-21 16:54:43 -0800 | [diff] [blame] | 5346 | /* Link status message must follow this format */ |
Alexander Duyck | c557a4b | 2019-10-31 09:58:51 -0700 | [diff] [blame] | 5347 | netdev_info(netdev, "NIC Link is Down\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5348 | netif_carrier_off(netdev); |
Konstantin Khlebnikov | d17ba0f | 2019-04-17 11:13:20 +0300 | [diff] [blame] | 5349 | netif_stop_queue(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5350 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
| 5351 | mod_timer(&adapter->phy_info_timer, |
| 5352 | round_jiffies(jiffies + 2 * HZ)); |
| 5353 | |
David Ertman | d9554e9 | 2014-01-08 01:07:55 +0000 | [diff] [blame] | 5354 | /* 8000ES2LAN requires a Rx packet buffer work-around |
| 5355 | * on link down event; reset the controller to flush |
| 5356 | * the Rx packet buffer. |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5357 | */ |
Konstantin Khlebnikov | caff422 | 2019-04-17 11:13:16 +0300 | [diff] [blame] | 5358 | if (adapter->flags & FLAG_RX_NEEDS_RESTART) |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5359 | adapter->flags |= FLAG_RESTART_NOW; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 5360 | else |
| 5361 | pm_schedule_suspend(netdev->dev.parent, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5362 | LINK_TIMEOUT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5363 | } |
| 5364 | } |
| 5365 | |
| 5366 | link_up: |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5367 | spin_lock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5368 | e1000e_update_stats(adapter); |
| 5369 | |
| 5370 | mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 5371 | adapter->tpt_old = adapter->stats.tpt; |
| 5372 | mac->collision_delta = adapter->stats.colc - adapter->colc_old; |
| 5373 | adapter->colc_old = adapter->stats.colc; |
| 5374 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 5375 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
| 5376 | adapter->gorc_old = adapter->stats.gorc; |
| 5377 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; |
| 5378 | adapter->gotc_old = adapter->stats.gotc; |
Flavio Leitner | 2084b11 | 2011-04-05 04:27:43 +0000 | [diff] [blame] | 5379 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5380 | |
Konstantin Khlebnikov | caff422 | 2019-04-17 11:13:16 +0300 | [diff] [blame] | 5381 | /* If the link is lost the controller stops DMA, but |
| 5382 | * if there is queued Tx work it cannot be done. So |
| 5383 | * reset the controller to flush the Tx packet buffers. |
| 5384 | */ |
| 5385 | if (!netif_carrier_ok(netdev) && |
| 5386 | (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)) |
| 5387 | adapter->flags |= FLAG_RESTART_NOW; |
| 5388 | |
David Ertman | d9554e9 | 2014-01-08 01:07:55 +0000 | [diff] [blame] | 5389 | /* If reset is necessary, do it outside of interrupt context. */ |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5390 | if (adapter->flags & FLAG_RESTART_NOW) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 5391 | schedule_work(&adapter->reset_task); |
| 5392 | /* return immediately since reset is imminent */ |
| 5393 | return; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5394 | } |
| 5395 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5396 | e1000e_update_adaptive(&adapter->hw); |
| 5397 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 5398 | /* Simple mode for Interrupt Throttle Rate (ITR) */ |
| 5399 | if (adapter->itr_setting == 4) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5400 | /* Symmetric Tx/Rx gets a reduced ITR=2000; |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 5401 | * Total asymmetrical Tx or Rx gets ITR=8000; |
| 5402 | * everyone else is between 2000-8000. |
| 5403 | */ |
| 5404 | u32 goc = (adapter->gotc + adapter->gorc) / 10000; |
| 5405 | u32 dif = (adapter->gotc > adapter->gorc ? |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5406 | adapter->gotc - adapter->gorc : |
| 5407 | adapter->gorc - adapter->gotc) / 10000; |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 5408 | u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 5409 | |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 5410 | e1000e_write_itr(adapter, itr); |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 5411 | } |
| 5412 | |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5413 | /* Cause software interrupt to ensure Rx ring is cleaned */ |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 5414 | if (adapter->msix_entries) |
| 5415 | ew32(ICS, adapter->rx_ring->ims_val); |
| 5416 | else |
| 5417 | ew32(ICS, E1000_ICS_RXDMT0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5418 | |
Jesse Brandeburg | 713b3c9 | 2011-02-02 10:19:50 +0000 | [diff] [blame] | 5419 | /* flush pending descriptors to memory before detecting Tx hang */ |
| 5420 | e1000e_flush_descriptors(adapter); |
| 5421 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5422 | /* Force detection of hung controller every watchdog period */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5423 | adapter->detect_tx_hung = true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5424 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5425 | /* With 82571 controllers, LAA may be overwritten due to controller |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5426 | * reset from the other port. Set the appropriate LAA in RAR[0] |
| 5427 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5428 | if (e1000e_get_laa_state_82571(hw)) |
Bruce Allan | 69e1e01 | 2012-04-14 03:28:50 +0000 | [diff] [blame] | 5429 | hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5430 | |
Carolyn Wyborny | ff10e13 | 2010-10-28 00:59:53 +0000 | [diff] [blame] | 5431 | if (adapter->flags2 & FLAG2_CHECK_PHY_HANG) |
| 5432 | e1000e_check_82574_phy_workaround(adapter); |
| 5433 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5434 | /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */ |
| 5435 | if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) { |
| 5436 | if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) && |
| 5437 | (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) { |
| 5438 | er32(RXSTMPH); |
| 5439 | adapter->rx_hwtstamp_cleared++; |
| 5440 | } else { |
| 5441 | adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP; |
| 5442 | } |
| 5443 | } |
| 5444 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5445 | /* Reset the timer */ |
| 5446 | if (!test_bit(__E1000_DOWN, &adapter->state)) |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 5447 | mod_timer(&adapter->watchdog_timer, |
| 5448 | round_jiffies(jiffies + 2 * HZ)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 5452 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 5453 | #define E1000_TX_FLAGS_TSO 0x00000004 |
| 5454 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5455 | #define E1000_TX_FLAGS_NO_FCS 0x00000010 |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5456 | #define E1000_TX_FLAGS_HWTSTAMP 0x00000020 |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5457 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 5458 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 5459 | |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5460 | static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb, |
| 5461 | __be16 protocol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5462 | { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5463 | struct e1000_context_desc *context_desc; |
| 5464 | struct e1000_buffer *buffer_info; |
| 5465 | unsigned int i; |
| 5466 | u32 cmd_length = 0; |
Bruce Allan | 70443ae | 2012-08-17 06:18:13 +0000 | [diff] [blame] | 5467 | u16 ipcse = 0, mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5468 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Francois Romieu | bcf1f57 | 2014-03-30 03:14:43 +0000 | [diff] [blame] | 5469 | int err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5470 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5471 | if (!skb_is_gso(skb)) |
| 5472 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5473 | |
Francois Romieu | bcf1f57 | 2014-03-30 03:14:43 +0000 | [diff] [blame] | 5474 | err = skb_cow_head(skb, 0); |
| 5475 | if (err < 0) |
| 5476 | return err; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5477 | |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5478 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 5479 | mss = skb_shinfo(skb)->gso_size; |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5480 | if (protocol == htons(ETH_P_IP)) { |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5481 | struct iphdr *iph = ip_hdr(skb); |
| 5482 | iph->tot_len = 0; |
| 5483 | iph->check = 0; |
| 5484 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5485 | 0, IPPROTO_TCP, 0); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5486 | cmd_length = E1000_TXD_CMD_IP; |
| 5487 | ipcse = skb_transport_offset(skb) - 1; |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 5488 | } else if (skb_is_gso_v6(skb)) { |
Heiner Kallweit | 2b316fbc | 2020-02-18 21:05:02 +0100 | [diff] [blame] | 5489 | tcp_v6_gso_csum_prep(skb); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5490 | ipcse = 0; |
| 5491 | } |
| 5492 | ipcss = skb_network_offset(skb); |
| 5493 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
| 5494 | tucss = skb_transport_offset(skb); |
| 5495 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5496 | |
| 5497 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5498 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5499 | |
| 5500 | i = tx_ring->next_to_use; |
| 5501 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 5502 | buffer_info = &tx_ring->buffer_info[i]; |
| 5503 | |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 5504 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 5505 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 5506 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5507 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 5508 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
Bruce Allan | 70443ae | 2012-08-17 06:18:13 +0000 | [diff] [blame] | 5509 | context_desc->upper_setup.tcp_fields.tucse = 0; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 5510 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
Bruce Allan | 3d5e33c | 2009-11-20 23:27:03 +0000 | [diff] [blame] | 5511 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 5512 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 5513 | |
| 5514 | buffer_info->time_stamp = jiffies; |
| 5515 | buffer_info->next_to_watch = i; |
| 5516 | |
| 5517 | i++; |
| 5518 | if (i == tx_ring->count) |
| 5519 | i = 0; |
| 5520 | tx_ring->next_to_use = i; |
| 5521 | |
| 5522 | return 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5523 | } |
| 5524 | |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5525 | static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb, |
| 5526 | __be16 protocol) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5527 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5528 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5529 | struct e1000_context_desc *context_desc; |
| 5530 | struct e1000_buffer *buffer_info; |
| 5531 | unsigned int i; |
| 5532 | u8 css; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5533 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5534 | |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5535 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
David Ertman | 3992c8e | 2014-04-05 03:36:15 +0000 | [diff] [blame] | 5536 | return false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5537 | |
Arthur Jones | 3f51839 | 2009-03-20 15:56:35 -0700 | [diff] [blame] | 5538 | switch (protocol) { |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5539 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5540 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 5541 | cmd_len |= E1000_TXD_CMD_TCP; |
| 5542 | break; |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5543 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5544 | /* XXX not handling all IPV6 headers */ |
| 5545 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 5546 | cmd_len |= E1000_TXD_CMD_TCP; |
| 5547 | break; |
| 5548 | default: |
| 5549 | if (unlikely(net_ratelimit())) |
Arthur Jones | 5f66f20 | 2009-03-19 01:13:08 +0000 | [diff] [blame] | 5550 | e_warn("checksum_partial proto=%x!\n", |
| 5551 | be16_to_cpu(protocol)); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5552 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5553 | } |
| 5554 | |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 5555 | css = skb_checksum_start_offset(skb); |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5556 | |
| 5557 | i = tx_ring->next_to_use; |
| 5558 | buffer_info = &tx_ring->buffer_info[i]; |
| 5559 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 5560 | |
| 5561 | context_desc->lower_setup.ip_config = 0; |
| 5562 | context_desc->upper_setup.tcp_fields.tucss = css; |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5563 | context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset; |
Dave Graham | af807c8 | 2008-10-09 14:28:58 -0700 | [diff] [blame] | 5564 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 5565 | context_desc->tcp_seg_setup.data = 0; |
| 5566 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 5567 | |
| 5568 | buffer_info->time_stamp = jiffies; |
| 5569 | buffer_info->next_to_watch = i; |
| 5570 | |
| 5571 | i++; |
| 5572 | if (i == tx_ring->count) |
| 5573 | i = 0; |
| 5574 | tx_ring->next_to_use = i; |
| 5575 | |
David Ertman | 3992c8e | 2014-04-05 03:36:15 +0000 | [diff] [blame] | 5576 | return true; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5577 | } |
| 5578 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5579 | static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb, |
| 5580 | unsigned int first, unsigned int max_per_txd, |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5581 | unsigned int nr_frags) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5582 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5583 | struct e1000_adapter *adapter = tx_ring->adapter; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5584 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5585 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | 8ddc951 | 2009-03-02 16:02:53 -0800 | [diff] [blame] | 5586 | unsigned int len = skb_headlen(skb); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5587 | unsigned int offset = 0, size, count = 0, i; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5588 | unsigned int f, bytecount, segs; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5589 | |
| 5590 | i = tx_ring->next_to_use; |
| 5591 | |
| 5592 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5593 | buffer_info = &tx_ring->buffer_info[i]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5594 | size = min(len, max_per_txd); |
| 5595 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5596 | buffer_info->length = size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5597 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5598 | buffer_info->next_to_watch = i; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5599 | buffer_info->dma = dma_map_single(&pdev->dev, |
| 5600 | skb->data + offset, |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5601 | size, DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5602 | buffer_info->mapped_as_page = false; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5603 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5604 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5605 | |
| 5606 | len -= size; |
| 5607 | offset += size; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5608 | count++; |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5609 | |
| 5610 | if (len) { |
| 5611 | i++; |
| 5612 | if (i == tx_ring->count) |
| 5613 | i = 0; |
| 5614 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5615 | } |
| 5616 | |
| 5617 | for (f = 0; f < nr_frags; f++) { |
Matthew Wilcox (Oracle) | d784097 | 2019-07-22 20:08:25 -0700 | [diff] [blame] | 5618 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[f]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5619 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5620 | len = skb_frag_size(frag); |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 5621 | offset = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5622 | |
| 5623 | while (len) { |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5624 | i++; |
| 5625 | if (i == tx_ring->count) |
| 5626 | i = 0; |
| 5627 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5628 | buffer_info = &tx_ring->buffer_info[i]; |
| 5629 | size = min(len, max_per_txd); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5630 | |
| 5631 | buffer_info->length = size; |
| 5632 | buffer_info->time_stamp = jiffies; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5633 | buffer_info->next_to_watch = i; |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 5634 | buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag, |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 5635 | offset, size, |
| 5636 | DMA_TO_DEVICE); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5637 | buffer_info->mapped_as_page = true; |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 5638 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5639 | goto dma_error; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5640 | |
| 5641 | len -= size; |
| 5642 | offset += size; |
| 5643 | count++; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5644 | } |
| 5645 | } |
| 5646 | |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5647 | segs = skb_shinfo(skb)->gso_segs ? : 1; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5648 | /* multiply data chunks by size of headers */ |
| 5649 | bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len; |
| 5650 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5651 | tx_ring->buffer_info[i].skb = skb; |
Tom Herbert | 9ed318d | 2010-05-05 14:02:27 +0000 | [diff] [blame] | 5652 | tx_ring->buffer_info[i].segs = segs; |
| 5653 | tx_ring->buffer_info[i].bytecount = bytecount; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5654 | tx_ring->buffer_info[first].next_to_watch = i; |
| 5655 | |
| 5656 | return count; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5657 | |
| 5658 | dma_error: |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5659 | dev_err(&pdev->dev, "Tx DMA map failed\n"); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5660 | buffer_info->dma = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5661 | if (count) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5662 | count--; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5663 | |
| 5664 | while (count--) { |
Bruce Allan | af667a2 | 2010-12-31 06:10:01 +0000 | [diff] [blame] | 5665 | if (i == 0) |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5666 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5667 | i--; |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5668 | buffer_info = &tx_ring->buffer_info[i]; |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 5669 | e1000_put_txbuf(tx_ring, buffer_info, true); |
Alexander Duyck | 03b1320 | 2009-12-02 16:45:31 +0000 | [diff] [blame] | 5670 | } |
| 5671 | |
| 5672 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5673 | } |
| 5674 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5675 | 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] | 5676 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5677 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5678 | struct e1000_tx_desc *tx_desc = NULL; |
| 5679 | struct e1000_buffer *buffer_info; |
| 5680 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 5681 | unsigned int i; |
| 5682 | |
| 5683 | if (tx_flags & E1000_TX_FLAGS_TSO) { |
| 5684 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5685 | E1000_TXD_CMD_TSE; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5686 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 5687 | |
| 5688 | if (tx_flags & E1000_TX_FLAGS_IPV4) |
| 5689 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
| 5690 | } |
| 5691 | |
| 5692 | if (tx_flags & E1000_TX_FLAGS_CSUM) { |
| 5693 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 5694 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 5695 | } |
| 5696 | |
| 5697 | if (tx_flags & E1000_TX_FLAGS_VLAN) { |
| 5698 | txd_lower |= E1000_TXD_CMD_VLE; |
| 5699 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 5700 | } |
| 5701 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5702 | if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS)) |
| 5703 | txd_lower &= ~(E1000_TXD_CMD_IFCS); |
| 5704 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5705 | if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) { |
| 5706 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 5707 | txd_upper |= E1000_TXD_EXTCMD_TSTAMP; |
| 5708 | } |
| 5709 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5710 | i = tx_ring->next_to_use; |
| 5711 | |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 5712 | do { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5713 | buffer_info = &tx_ring->buffer_info[i]; |
| 5714 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 5715 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 5716 | tx_desc->lower.data = cpu_to_le32(txd_lower | |
| 5717 | buffer_info->length); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5718 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
| 5719 | |
| 5720 | i++; |
| 5721 | if (i == tx_ring->count) |
| 5722 | i = 0; |
Bruce Allan | 36b973d | 2010-11-24 07:42:43 +0000 | [diff] [blame] | 5723 | } while (--count > 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5724 | |
| 5725 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 5726 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5727 | /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */ |
| 5728 | if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS)) |
| 5729 | tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS)); |
| 5730 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5731 | /* Force memory writes to complete before letting h/w |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5732 | * know there are new descriptors to fetch. (Only |
| 5733 | * applicable for weak-ordered memory model archs, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5734 | * such as IA-64). |
| 5735 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5736 | wmb(); |
| 5737 | |
| 5738 | tx_ring->next_to_use = i; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5739 | } |
| 5740 | |
| 5741 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 5742 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 5743 | struct sk_buff *skb) |
| 5744 | { |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 5745 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5746 | u16 length, offset; |
| 5747 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 5748 | if (skb_vlan_tag_present(skb) && |
| 5749 | !((skb_vlan_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
Bruce Allan | d60923c | 2012-12-05 06:26:56 +0000 | [diff] [blame] | 5750 | (adapter->hw.mng_cookie.status & |
| 5751 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) |
| 5752 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5753 | |
| 5754 | if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) |
| 5755 | return 0; |
| 5756 | |
Bruce Allan | 53aa82d | 2013-02-20 04:06:06 +0000 | [diff] [blame] | 5757 | if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5758 | return 0; |
| 5759 | |
| 5760 | { |
Bruce Allan | 362e20c | 2013-02-20 04:05:45 +0000 | [diff] [blame] | 5761 | const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5762 | struct udphdr *udp; |
| 5763 | |
| 5764 | if (ip->protocol != IPPROTO_UDP) |
| 5765 | return 0; |
| 5766 | |
| 5767 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 5768 | if (ntohs(udp->dest) != 67) |
| 5769 | return 0; |
| 5770 | |
| 5771 | offset = (u8 *)udp + 8 - skb->data; |
| 5772 | length = skb->len - offset; |
| 5773 | return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); |
| 5774 | } |
| 5775 | |
| 5776 | return 0; |
| 5777 | } |
| 5778 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5779 | 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] | 5780 | { |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5781 | struct e1000_adapter *adapter = tx_ring->adapter; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5782 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5783 | netif_stop_queue(adapter->netdev); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5784 | /* Herbert's original patch had: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5785 | * smp_mb__after_netif_stop_queue(); |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5786 | * but since that doesn't exist yet, just open code it. |
| 5787 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5788 | smp_mb(); |
| 5789 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5790 | /* We need to check again in a case another CPU has just |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5791 | * made room available. |
| 5792 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5793 | if (e1000_desc_unused(tx_ring) < size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5794 | return -EBUSY; |
| 5795 | |
| 5796 | /* A reprieve! */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5797 | netif_start_queue(adapter->netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5798 | ++adapter->restart_queue; |
| 5799 | return 0; |
| 5800 | } |
| 5801 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5802 | 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] | 5803 | { |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5804 | BUG_ON(size > tx_ring->count); |
| 5805 | |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5806 | if (e1000_desc_unused(tx_ring) >= size) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5807 | return 0; |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5808 | return __e1000_maybe_stop_tx(tx_ring, size); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5809 | } |
| 5810 | |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 5811 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 5812 | struct net_device *netdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5813 | { |
| 5814 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5815 | struct e1000_ring *tx_ring = adapter->tx_ring; |
| 5816 | unsigned int first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5817 | unsigned int tx_flags = 0; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5818 | unsigned int len = skb_headlen(skb); |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 5819 | unsigned int nr_frags; |
| 5820 | unsigned int mss; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5821 | int count = 0; |
| 5822 | int tso; |
| 5823 | unsigned int f; |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5824 | __be16 protocol = vlan_get_protocol(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5825 | |
| 5826 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 5827 | dev_kfree_skb_any(skb); |
| 5828 | return NETDEV_TX_OK; |
| 5829 | } |
| 5830 | |
| 5831 | if (skb->len <= 0) { |
| 5832 | dev_kfree_skb_any(skb); |
| 5833 | return NETDEV_TX_OK; |
| 5834 | } |
| 5835 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5836 | /* The minimum packet size with TCTL.PSP set is 17 bytes so |
Tushar Dave | 6e97c17 | 2012-09-14 02:21:37 +0000 | [diff] [blame] | 5837 | * pad skb in order to meet this minimum size requirement |
| 5838 | */ |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 5839 | if (skb_put_padto(skb, 17)) |
| 5840 | return NETDEV_TX_OK; |
Tushar Dave | 6e97c17 | 2012-09-14 02:21:37 +0000 | [diff] [blame] | 5841 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5842 | mss = skb_shinfo(skb)->gso_size; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5843 | if (mss) { |
| 5844 | u8 hdr_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5845 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5846 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5847 | * points to just header, pull a few bytes of payload from |
| 5848 | * frags into skb->data |
| 5849 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5850 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5851 | /* we do this workaround for ES2LAN, but it is un-necessary, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5852 | * avoiding it could save a lot of cycles |
| 5853 | */ |
Auke Kok | 4e6c709 | 2007-10-05 14:15:23 -0700 | [diff] [blame] | 5854 | if (skb->data_len && (hdr_len == len)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5855 | unsigned int pull_size; |
| 5856 | |
Bruce Allan | a2a5b32 | 2012-01-31 06:37:17 +0000 | [diff] [blame] | 5857 | pull_size = min_t(unsigned int, 4, skb->data_len); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5858 | if (!__pskb_pull_tail(skb, pull_size)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 5859 | e_err("__pskb_pull_tail failed.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5860 | dev_kfree_skb_any(skb); |
| 5861 | return NETDEV_TX_OK; |
| 5862 | } |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 5863 | len = skb_headlen(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5864 | } |
| 5865 | } |
| 5866 | |
| 5867 | /* reserve a descriptor for the offload context */ |
| 5868 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5869 | count++; |
| 5870 | count++; |
| 5871 | |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5872 | count += DIV_ROUND_UP(len, adapter->tx_fifo_limit); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5873 | |
| 5874 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 5875 | for (f = 0; f < nr_frags; f++) |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5876 | count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]), |
| 5877 | adapter->tx_fifo_limit); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5878 | |
| 5879 | if (adapter->hw.mac.tx_pkt_filtering) |
| 5880 | e1000_transfer_dhcp_info(adapter, skb); |
| 5881 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5882 | /* need: count + 2 desc gap to keep tail from touching |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5883 | * head, otherwise try next time |
| 5884 | */ |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5885 | if (e1000_maybe_stop_tx(tx_ring, count + 2)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5886 | return NETDEV_TX_BUSY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5887 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 5888 | if (skb_vlan_tag_present(skb)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5889 | tx_flags |= E1000_TX_FLAGS_VLAN; |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 5890 | tx_flags |= (skb_vlan_tag_get(skb) << |
| 5891 | E1000_TX_FLAGS_VLAN_SHIFT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | first = tx_ring->next_to_use; |
| 5895 | |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5896 | tso = e1000_tso(tx_ring, skb, protocol); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5897 | if (tso < 0) { |
| 5898 | dev_kfree_skb_any(skb); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5899 | return NETDEV_TX_OK; |
| 5900 | } |
| 5901 | |
| 5902 | if (tso) |
| 5903 | tx_flags |= E1000_TX_FLAGS_TSO; |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5904 | else if (e1000_tx_csum(tx_ring, skb, protocol)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5905 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 5906 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 5907 | /* 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] | 5908 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 5909 | * no longer assume, we must. |
| 5910 | */ |
Vlad Yasevich | 47ccd1e | 2014-08-25 10:34:48 -0400 | [diff] [blame] | 5911 | if (protocol == htons(ETH_P_IP)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5912 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 5913 | |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 5914 | if (unlikely(skb->no_fcs)) |
| 5915 | tx_flags |= E1000_TX_FLAGS_NO_FCS; |
| 5916 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5917 | /* if count is 0 then mapping error has occurred */ |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5918 | count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit, |
| 5919 | nr_frags); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5920 | if (count) { |
Mathias Koehrer | 6930895 | 2014-08-07 18:51:53 +0000 | [diff] [blame] | 5921 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
Jacob Keller | cff5714 | 2017-05-03 10:28:57 -0700 | [diff] [blame] | 5922 | (adapter->flags & FLAG_HAS_HW_TIMESTAMP)) { |
| 5923 | if (!adapter->tx_hwtstamp_skb) { |
| 5924 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 5925 | tx_flags |= E1000_TX_FLAGS_HWTSTAMP; |
| 5926 | adapter->tx_hwtstamp_skb = skb_get(skb); |
| 5927 | adapter->tx_hwtstamp_start = jiffies; |
| 5928 | schedule_work(&adapter->tx_hwtstamp_work); |
| 5929 | } else { |
| 5930 | adapter->tx_hwtstamp_skipped++; |
| 5931 | } |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 5932 | } |
Willem de Bruijn | 80be312 | 2012-04-27 09:04:05 +0000 | [diff] [blame] | 5933 | |
Miroslav Lichvar | 74abc9b1 | 2017-05-19 17:52:41 +0200 | [diff] [blame] | 5934 | skb_tx_timestamp(skb); |
| 5935 | |
Tom Herbert | 3f0cfa3 | 2011-11-28 16:33:16 +0000 | [diff] [blame] | 5936 | netdev_sent_queue(netdev, skb->len); |
Bruce Allan | 55aa698 | 2011-12-16 00:45:45 +0000 | [diff] [blame] | 5937 | e1000_tx_queue(tx_ring, tx_flags, count); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5938 | /* Make sure there is space in the ring for the next send. */ |
Bruce Allan | d821a4c | 2012-08-24 20:38:11 +0000 | [diff] [blame] | 5939 | e1000_maybe_stop_tx(tx_ring, |
| 5940 | (MAX_SKB_FRAGS * |
| 5941 | DIV_ROUND_UP(PAGE_SIZE, |
| 5942 | adapter->tx_fifo_limit) + 2)); |
Florian Westphal | 472f31f | 2015-01-09 09:26:14 +0000 | [diff] [blame] | 5943 | |
Florian Westphal | 6b16f9e | 2019-04-01 16:42:14 +0200 | [diff] [blame] | 5944 | if (!netdev_xmit_more() || |
Florian Westphal | 472f31f | 2015-01-09 09:26:14 +0000 | [diff] [blame] | 5945 | netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) { |
| 5946 | if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) |
| 5947 | e1000e_update_tdt_wa(tx_ring, |
| 5948 | tx_ring->next_to_use); |
| 5949 | else |
| 5950 | writel(tx_ring->next_to_use, tx_ring->tail); |
Florian Westphal | 472f31f | 2015-01-09 09:26:14 +0000 | [diff] [blame] | 5951 | } |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5952 | } else { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5953 | dev_kfree_skb_any(skb); |
Alexander Duyck | 1b7719c | 2009-03-19 01:12:50 +0000 | [diff] [blame] | 5954 | tx_ring->buffer_info[first].time_stamp = 0; |
| 5955 | tx_ring->next_to_use = first; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5956 | } |
| 5957 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5958 | return NETDEV_TX_OK; |
| 5959 | } |
| 5960 | |
| 5961 | /** |
| 5962 | * e1000_tx_timeout - Respond to a Tx Hang |
| 5963 | * @netdev: network interface device structure |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 5964 | * @txqueue: index of the hung queue (unused) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5965 | **/ |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 5966 | static void e1000_tx_timeout(struct net_device *netdev, unsigned int __always_unused txqueue) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5967 | { |
| 5968 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 5969 | |
| 5970 | /* Do the reset outside of interrupt context */ |
| 5971 | adapter->tx_timeout_count++; |
| 5972 | schedule_work(&adapter->reset_task); |
| 5973 | } |
| 5974 | |
| 5975 | static void e1000_reset_task(struct work_struct *work) |
| 5976 | { |
| 5977 | struct e1000_adapter *adapter; |
| 5978 | adapter = container_of(work, struct e1000_adapter, reset_task); |
| 5979 | |
Vitaly Lifshits | 21f857f | 2020-10-21 14:59:37 +0300 | [diff] [blame] | 5980 | rtnl_lock(); |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 5981 | /* don't run the task if already down */ |
Vitaly Lifshits | 21f857f | 2020-10-21 14:59:37 +0300 | [diff] [blame] | 5982 | if (test_bit(__E1000_DOWN, &adapter->state)) { |
| 5983 | rtnl_unlock(); |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 5984 | return; |
Vitaly Lifshits | 21f857f | 2020-10-21 14:59:37 +0300 | [diff] [blame] | 5985 | } |
Jesse Brandeburg | 615b32a | 2011-02-02 10:19:45 +0000 | [diff] [blame] | 5986 | |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5987 | if (!(adapter->flags & FLAG_RESTART_NOW)) { |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 5988 | e1000e_dump(adapter); |
Bruce Allan | 12d43f7 | 2012-12-05 06:26:14 +0000 | [diff] [blame] | 5989 | e_err("Reset adapter unexpectedly\n"); |
Carolyn Wyborny | affa9df | 2010-10-28 00:59:55 +0000 | [diff] [blame] | 5990 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5991 | e1000e_reinit_locked(adapter); |
Vitaly Lifshits | 21f857f | 2020-10-21 14:59:37 +0300 | [diff] [blame] | 5992 | rtnl_unlock(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5993 | } |
| 5994 | |
| 5995 | /** |
Sasha Neftin | 39da2ca | 2021-03-14 15:59:20 +0200 | [diff] [blame] | 5996 | * e1000e_get_stats64 - Get System Network Statistics |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5997 | * @netdev: network interface device structure |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 5998 | * @stats: rtnl_link_stats64 pointer |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 5999 | * |
| 6000 | * Returns the address of the device statistics structure. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6001 | **/ |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 6002 | void e1000e_get_stats64(struct net_device *netdev, |
| 6003 | struct rtnl_link_stats64 *stats) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6004 | { |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6005 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6006 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6007 | spin_lock(&adapter->stats64_lock); |
| 6008 | e1000e_update_stats(adapter); |
| 6009 | /* Fill out the OS statistics structure */ |
| 6010 | stats->rx_bytes = adapter->stats.gorc; |
| 6011 | stats->rx_packets = adapter->stats.gprc; |
| 6012 | stats->tx_bytes = adapter->stats.gotc; |
| 6013 | stats->tx_packets = adapter->stats.gptc; |
| 6014 | stats->multicast = adapter->stats.mprc; |
| 6015 | stats->collisions = adapter->stats.colc; |
| 6016 | |
| 6017 | /* Rx Errors */ |
| 6018 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6019 | /* RLEC on some newer hardware can be incorrect so build |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6020 | * our own version based on RUC and ROC |
| 6021 | */ |
| 6022 | stats->rx_errors = adapter->stats.rxerrc + |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 6023 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 6024 | adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr; |
| 6025 | stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc; |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6026 | stats->rx_crc_errors = adapter->stats.crcerrs; |
| 6027 | stats->rx_frame_errors = adapter->stats.algnerrc; |
| 6028 | stats->rx_missed_errors = adapter->stats.mpc; |
| 6029 | |
| 6030 | /* Tx Errors */ |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 6031 | stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol; |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 6032 | stats->tx_aborted_errors = adapter->stats.ecol; |
| 6033 | stats->tx_window_errors = adapter->stats.latecol; |
| 6034 | stats->tx_carrier_errors = adapter->stats.tncrs; |
| 6035 | |
| 6036 | /* Tx Dropped needs to be maintained elsewhere */ |
| 6037 | |
| 6038 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6039 | } |
| 6040 | |
| 6041 | /** |
| 6042 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 6043 | * @netdev: network interface device structure |
| 6044 | * @new_mtu: new value for maximum frame size |
| 6045 | * |
| 6046 | * Returns 0 on success, negative on failure |
| 6047 | **/ |
| 6048 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 6049 | { |
| 6050 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 8084b86 | 2015-05-02 00:52:00 -0700 | [diff] [blame] | 6051 | int max_frame = new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6052 | |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 6053 | /* Jumbo frame support */ |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 6054 | if ((new_mtu > ETH_DATA_LEN) && |
Bruce Allan | 2e1706f | 2012-06-30 20:02:42 +0000 | [diff] [blame] | 6055 | !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { |
| 6056 | e_err("Jumbo Frames not supported.\n"); |
| 6057 | return -EINVAL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6058 | } |
| 6059 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 6060 | /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */ |
| 6061 | if ((adapter->hw.mac.type >= e1000_pch2lan) && |
Bruce Allan | a1ce647 | 2010-09-22 17:16:40 +0000 | [diff] [blame] | 6062 | !(adapter->flags2 & FLAG2_CRC_STRIPPING) && |
| 6063 | (new_mtu > ETH_DATA_LEN)) { |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 6064 | 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] | 6065 | return -EINVAL; |
| 6066 | } |
| 6067 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6068 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 6069 | usleep_range(1000, 1100); |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 6070 | /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6071 | adapter->max_frame_size = max_frame; |
Florian Fainelli | 1229913 | 2019-11-07 14:35:36 -0800 | [diff] [blame] | 6072 | netdev_dbg(netdev, "changing MTU from %d to %d\n", |
| 6073 | netdev->mtu, new_mtu); |
Bruce Allan | 610c992 | 2009-11-19 12:35:45 +0000 | [diff] [blame] | 6074 | netdev->mtu = new_mtu; |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 6075 | |
| 6076 | pm_runtime_get_sync(netdev->dev.parent); |
| 6077 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6078 | if (netif_running(netdev)) |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6079 | e1000e_down(adapter, true); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6080 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6081 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6082 | * means we reserve 2 more, this pushes us to allocate from the next |
| 6083 | * larger slab size. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6084 | * i.e. RXBUFFER_2048 --> size-4096 slab |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6085 | * However with the new *_jumbo_rx* routines, jumbo receives will use |
| 6086 | * fragmented skbs |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 6087 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6088 | |
Jesse Brandeburg | 9926146 | 2010-01-22 22:56:16 +0000 | [diff] [blame] | 6089 | if (max_frame <= 2048) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6090 | adapter->rx_buffer_len = 2048; |
| 6091 | else |
| 6092 | adapter->rx_buffer_len = 4096; |
| 6093 | |
| 6094 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
Alexander Duyck | 8084b86 | 2015-05-02 00:52:00 -0700 | [diff] [blame] | 6095 | if (max_frame <= (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 6096 | adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6097 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6098 | if (netif_running(netdev)) |
| 6099 | e1000e_up(adapter); |
| 6100 | else |
| 6101 | e1000e_reset(adapter); |
| 6102 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 6103 | pm_runtime_put_sync(netdev->dev.parent); |
| 6104 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6105 | clear_bit(__E1000_RESETTING, &adapter->state); |
| 6106 | |
| 6107 | return 0; |
| 6108 | } |
| 6109 | |
| 6110 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 6111 | int cmd) |
| 6112 | { |
| 6113 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6114 | struct mii_ioctl_data *data = if_mii(ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6115 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6116 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6117 | return -EOPNOTSUPP; |
| 6118 | |
| 6119 | switch (cmd) { |
| 6120 | case SIOCGMIIPHY: |
| 6121 | data->phy_id = adapter->hw.phy.addr; |
| 6122 | break; |
| 6123 | case SIOCGMIIREG: |
Bruce Allan | b16a002 | 2009-11-20 23:24:30 +0000 | [diff] [blame] | 6124 | e1000_phy_read_status(adapter); |
| 6125 | |
Bruce Allan | 7c25769 | 2008-04-23 11:09:00 -0700 | [diff] [blame] | 6126 | switch (data->reg_num & 0x1F) { |
| 6127 | case MII_BMCR: |
| 6128 | data->val_out = adapter->phy_regs.bmcr; |
| 6129 | break; |
| 6130 | case MII_BMSR: |
| 6131 | data->val_out = adapter->phy_regs.bmsr; |
| 6132 | break; |
| 6133 | case MII_PHYSID1: |
| 6134 | data->val_out = (adapter->hw.phy.id >> 16); |
| 6135 | break; |
| 6136 | case MII_PHYSID2: |
| 6137 | data->val_out = (adapter->hw.phy.id & 0xFFFF); |
| 6138 | break; |
| 6139 | case MII_ADVERTISE: |
| 6140 | data->val_out = adapter->phy_regs.advertise; |
| 6141 | break; |
| 6142 | case MII_LPA: |
| 6143 | data->val_out = adapter->phy_regs.lpa; |
| 6144 | break; |
| 6145 | case MII_EXPANSION: |
| 6146 | data->val_out = adapter->phy_regs.expansion; |
| 6147 | break; |
| 6148 | case MII_CTRL1000: |
| 6149 | data->val_out = adapter->phy_regs.ctrl1000; |
| 6150 | break; |
| 6151 | case MII_STAT1000: |
| 6152 | data->val_out = adapter->phy_regs.stat1000; |
| 6153 | break; |
| 6154 | case MII_ESTATUS: |
| 6155 | data->val_out = adapter->phy_regs.estatus; |
| 6156 | break; |
| 6157 | default: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6158 | return -EIO; |
| 6159 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6160 | break; |
| 6161 | case SIOCSMIIREG: |
| 6162 | default: |
| 6163 | return -EOPNOTSUPP; |
| 6164 | } |
| 6165 | return 0; |
| 6166 | } |
| 6167 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6168 | /** |
Sasha Neftin | 39da2ca | 2021-03-14 15:59:20 +0200 | [diff] [blame] | 6169 | * e1000e_hwtstamp_set - control hardware time stamping |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6170 | * @netdev: network interface device structure |
Jesse Brandeburg | b50f7bc | 2020-09-25 15:24:37 -0700 | [diff] [blame] | 6171 | * @ifr: interface request |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6172 | * |
| 6173 | * Outgoing time stamping can be enabled and disabled. Play nice and |
| 6174 | * disable it when requested, although it shouldn't cause any overhead |
| 6175 | * when no packet needs it. At most one packet in the queue may be |
| 6176 | * marked for time stamping, otherwise it would be impossible to tell |
| 6177 | * for sure to which packet the hardware time stamp belongs. |
| 6178 | * |
| 6179 | * Incoming time stamping has to be configured via the hardware filters. |
| 6180 | * Not all combinations are supported, in particular event type has to be |
| 6181 | * specified. Matching the kind of event packet is not supported, with the |
| 6182 | * exception of "all V2 events regardless of level 2 or 4". |
| 6183 | **/ |
Ben Hutchings | 4e8cff6 | 2013-11-18 23:07:16 +0000 | [diff] [blame] | 6184 | static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr) |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6185 | { |
| 6186 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6187 | struct hwtstamp_config config; |
| 6188 | int ret_val; |
| 6189 | |
| 6190 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) |
| 6191 | return -EFAULT; |
| 6192 | |
Ben Hutchings | 62d7e3a | 2013-11-14 00:41:38 +0000 | [diff] [blame] | 6193 | ret_val = e1000e_config_hwtstamp(adapter, &config); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6194 | if (ret_val) |
| 6195 | return ret_val; |
| 6196 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 6197 | switch (config.rx_filter) { |
| 6198 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 6199 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 6200 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 6201 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 6202 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 6203 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 6204 | /* With V2 type filters which specify a Sync or Delay Request, |
| 6205 | * Path Delay Request/Response messages are also time stamped |
| 6206 | * by hardware so notify the caller the requested packets plus |
| 6207 | * some others are time stamped. |
| 6208 | */ |
| 6209 | config.rx_filter = HWTSTAMP_FILTER_SOME; |
| 6210 | break; |
| 6211 | default: |
| 6212 | break; |
| 6213 | } |
| 6214 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6215 | return copy_to_user(ifr->ifr_data, &config, |
| 6216 | sizeof(config)) ? -EFAULT : 0; |
| 6217 | } |
| 6218 | |
Ben Hutchings | 4e8cff6 | 2013-11-18 23:07:16 +0000 | [diff] [blame] | 6219 | static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr) |
| 6220 | { |
| 6221 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6222 | |
| 6223 | return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config, |
| 6224 | sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0; |
| 6225 | } |
| 6226 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6227 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 6228 | { |
| 6229 | switch (cmd) { |
| 6230 | case SIOCGMIIPHY: |
| 6231 | case SIOCGMIIREG: |
| 6232 | case SIOCSMIIREG: |
| 6233 | return e1000_mii_ioctl(netdev, ifr, cmd); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 6234 | case SIOCSHWTSTAMP: |
Ben Hutchings | 4e8cff6 | 2013-11-18 23:07:16 +0000 | [diff] [blame] | 6235 | return e1000e_hwtstamp_set(netdev, ifr); |
| 6236 | case SIOCGHWTSTAMP: |
| 6237 | return e1000e_hwtstamp_get(netdev, ifr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6238 | default: |
| 6239 | return -EOPNOTSUPP; |
| 6240 | } |
| 6241 | } |
| 6242 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6243 | static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) |
| 6244 | { |
| 6245 | struct e1000_hw *hw = &adapter->hw; |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6246 | u32 i, mac_reg, wuc; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6247 | u16 phy_reg, wuc_enable; |
Bruce Allan | 70806a7 | 2013-01-05 05:08:37 +0000 | [diff] [blame] | 6248 | int retval; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6249 | |
| 6250 | /* copy MAC RARs to PHY RARs */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 6251 | e1000_copy_rx_addrs_to_phy_ich8lan(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6252 | |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6253 | retval = hw->phy.ops.acquire(hw); |
| 6254 | if (retval) { |
| 6255 | e_err("Could not acquire PHY\n"); |
| 6256 | return retval; |
| 6257 | } |
| 6258 | |
| 6259 | /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */ |
| 6260 | retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
| 6261 | if (retval) |
Bruce Allan | 75ce153 | 2012-02-08 02:54:48 +0000 | [diff] [blame] | 6262 | goto release; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6263 | |
| 6264 | /* copy MAC MTA to PHY MTA - only needed for pchlan */ |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6265 | for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { |
| 6266 | mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6267 | hw->phy.ops.write_reg_page(hw, BM_MTA(i), |
| 6268 | (u16)(mac_reg & 0xFFFF)); |
| 6269 | hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1, |
| 6270 | (u16)((mac_reg >> 16) & 0xFFFF)); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6271 | } |
| 6272 | |
| 6273 | /* configure PHY Rx Control register */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6274 | hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6275 | mac_reg = er32(RCTL); |
| 6276 | if (mac_reg & E1000_RCTL_UPE) |
| 6277 | phy_reg |= BM_RCTL_UPE; |
| 6278 | if (mac_reg & E1000_RCTL_MPE) |
| 6279 | phy_reg |= BM_RCTL_MPE; |
| 6280 | phy_reg &= ~(BM_RCTL_MO_MASK); |
| 6281 | if (mac_reg & E1000_RCTL_MO_3) |
| 6282 | phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 6283 | << BM_RCTL_MO_SHIFT); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6284 | if (mac_reg & E1000_RCTL_BAM) |
| 6285 | phy_reg |= BM_RCTL_BAM; |
| 6286 | if (mac_reg & E1000_RCTL_PMCF) |
| 6287 | phy_reg |= BM_RCTL_PMCF; |
| 6288 | mac_reg = er32(CTRL); |
| 6289 | if (mac_reg & E1000_CTRL_RFCE) |
| 6290 | phy_reg |= BM_RCTL_RFCE; |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6291 | hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6292 | |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6293 | wuc = E1000_WUC_PME_EN; |
| 6294 | if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC)) |
| 6295 | wuc |= E1000_WUC_APME; |
| 6296 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6297 | /* enable PHY wakeup in MAC register */ |
| 6298 | ew32(WUFC, wufc); |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6299 | ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME | |
| 6300 | E1000_WUC_PME_STATUS | wuc)); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6301 | |
| 6302 | /* configure and enable PHY wakeup in PHY registers */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6303 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc); |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6304 | hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6305 | |
| 6306 | /* activate PHY wakeup */ |
Bruce Allan | 2b6b168 | 2011-05-13 07:20:09 +0000 | [diff] [blame] | 6307 | wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; |
| 6308 | retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6309 | if (retval) |
| 6310 | e_err("Could not set PHY Host Wakeup bit\n"); |
Bruce Allan | 75ce153 | 2012-02-08 02:54:48 +0000 | [diff] [blame] | 6311 | release: |
Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 6312 | hw->phy.ops.release(hw); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6313 | |
| 6314 | return retval; |
| 6315 | } |
| 6316 | |
David Ertman | 2a7e19a | 2014-07-11 06:21:31 +0000 | [diff] [blame] | 6317 | static void e1000e_flush_lpic(struct pci_dev *pdev) |
| 6318 | { |
| 6319 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6320 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6321 | struct e1000_hw *hw = &adapter->hw; |
| 6322 | u32 ret_val; |
| 6323 | |
| 6324 | pm_runtime_get_sync(netdev->dev.parent); |
| 6325 | |
| 6326 | ret_val = hw->phy.ops.acquire(hw); |
| 6327 | if (ret_val) |
| 6328 | goto fl_out; |
| 6329 | |
| 6330 | pr_info("EEE TX LPI TIMER: %08X\n", |
| 6331 | er32(LPIC) >> E1000_LPIC_LPIET_SHIFT); |
| 6332 | |
| 6333 | hw->phy.ops.release(hw); |
| 6334 | |
| 6335 | fl_out: |
| 6336 | pm_runtime_put_sync(netdev->dev.parent); |
| 6337 | } |
| 6338 | |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6339 | /* S0ix implementation */ |
| 6340 | static void e1000e_s0ix_entry_flow(struct e1000_adapter *adapter) |
| 6341 | { |
| 6342 | struct e1000_hw *hw = &adapter->hw; |
| 6343 | u32 mac_data; |
| 6344 | u16 phy_data; |
| 6345 | |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6346 | if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) { |
| 6347 | /* Request ME configure the device for S0ix */ |
| 6348 | mac_data = er32(H2ME); |
| 6349 | mac_data |= E1000_H2ME_START_DPG; |
| 6350 | mac_data &= ~E1000_H2ME_EXIT_DPG; |
| 6351 | ew32(H2ME, mac_data); |
| 6352 | } else { |
| 6353 | /* Request driver configure the device to S0ix */ |
| 6354 | /* Disable the periodic inband message, |
| 6355 | * don't request PCIe clock in K1 page770_17[10:9] = 10b |
| 6356 | */ |
| 6357 | e1e_rphy(hw, HV_PM_CTRL, &phy_data); |
| 6358 | phy_data &= ~HV_PM_CTRL_K1_CLK_REQ; |
| 6359 | phy_data |= BIT(10); |
| 6360 | e1e_wphy(hw, HV_PM_CTRL, phy_data); |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6361 | |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6362 | /* Make sure we don't exit K1 every time a new packet arrives |
| 6363 | * 772_29[5] = 1 CS_Mode_Stay_In_K1 |
| 6364 | */ |
| 6365 | e1e_rphy(hw, I217_CGFREG, &phy_data); |
| 6366 | phy_data |= BIT(5); |
| 6367 | e1e_wphy(hw, I217_CGFREG, phy_data); |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6368 | |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6369 | /* Change the MAC/PHY interface to SMBus |
| 6370 | * Force the SMBus in PHY page769_23[0] = 1 |
| 6371 | * Force the SMBus in MAC CTRL_EXT[11] = 1 |
| 6372 | */ |
| 6373 | e1e_rphy(hw, CV_SMB_CTRL, &phy_data); |
| 6374 | phy_data |= CV_SMB_CTRL_FORCE_SMBUS; |
| 6375 | e1e_wphy(hw, CV_SMB_CTRL, phy_data); |
| 6376 | mac_data = er32(CTRL_EXT); |
| 6377 | mac_data |= E1000_CTRL_EXT_FORCE_SMBUS; |
| 6378 | ew32(CTRL_EXT, mac_data); |
| 6379 | |
| 6380 | /* DFT control: PHY bit: page769_20[0] = 1 |
| 6381 | * Gate PPW via EXTCNF_CTRL - set 0x0F00[7] = 1 |
| 6382 | */ |
| 6383 | e1e_rphy(hw, I82579_DFT_CTRL, &phy_data); |
| 6384 | phy_data |= BIT(0); |
| 6385 | e1e_wphy(hw, I82579_DFT_CTRL, phy_data); |
| 6386 | |
| 6387 | mac_data = er32(EXTCNF_CTRL); |
| 6388 | mac_data |= E1000_EXTCNF_CTRL_GATE_PHY_CFG; |
| 6389 | ew32(EXTCNF_CTRL, mac_data); |
| 6390 | |
| 6391 | /* Enable the Dynamic Power Gating in the MAC */ |
| 6392 | mac_data = er32(FEXTNVM7); |
| 6393 | mac_data |= BIT(22); |
| 6394 | ew32(FEXTNVM7, mac_data); |
| 6395 | |
| 6396 | /* Disable disconnected cable conditioning for Power Gating */ |
| 6397 | mac_data = er32(DPGFR); |
| 6398 | mac_data |= BIT(2); |
| 6399 | ew32(DPGFR, mac_data); |
| 6400 | |
| 6401 | /* Don't wake from dynamic Power Gating with clock request */ |
| 6402 | mac_data = er32(FEXTNVM12); |
| 6403 | mac_data |= BIT(12); |
| 6404 | ew32(FEXTNVM12, mac_data); |
| 6405 | |
| 6406 | /* Ungate PGCB clock */ |
| 6407 | mac_data = er32(FEXTNVM9); |
| 6408 | mac_data &= ~BIT(28); |
| 6409 | ew32(FEXTNVM9, mac_data); |
| 6410 | |
| 6411 | /* Enable K1 off to enable mPHY Power Gating */ |
| 6412 | mac_data = er32(FEXTNVM6); |
| 6413 | mac_data |= BIT(31); |
| 6414 | ew32(FEXTNVM6, mac_data); |
| 6415 | |
| 6416 | /* Enable mPHY power gating for any link and speed */ |
| 6417 | mac_data = er32(FEXTNVM8); |
| 6418 | mac_data |= BIT(9); |
| 6419 | ew32(FEXTNVM8, mac_data); |
| 6420 | |
| 6421 | /* Enable the Dynamic Clock Gating in the DMA and MAC */ |
| 6422 | mac_data = er32(CTRL_EXT); |
| 6423 | mac_data |= E1000_CTRL_EXT_DMA_DYN_CLK_EN; |
| 6424 | ew32(CTRL_EXT, mac_data); |
| 6425 | |
| 6426 | /* No MAC DPG gating SLP_S0 in modern standby |
| 6427 | * Switch the logic of the lanphypc to use PMC counter |
| 6428 | */ |
| 6429 | mac_data = er32(FEXTNVM5); |
| 6430 | mac_data |= BIT(7); |
| 6431 | ew32(FEXTNVM5, mac_data); |
| 6432 | } |
| 6433 | |
| 6434 | /* Disable the time synchronization clock */ |
| 6435 | mac_data = er32(FEXTNVM7); |
| 6436 | mac_data |= BIT(31); |
| 6437 | mac_data &= ~BIT(0); |
| 6438 | ew32(FEXTNVM7, mac_data); |
| 6439 | |
| 6440 | /* Dynamic Power Gating Enable */ |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6441 | mac_data = er32(CTRL_EXT); |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6442 | mac_data |= BIT(3); |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6443 | ew32(CTRL_EXT, mac_data); |
| 6444 | |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6445 | /* Check MAC Tx/Rx packet buffer pointers. |
| 6446 | * Reset MAC Tx/Rx packet buffer pointers to suppress any |
| 6447 | * pending traffic indication that would prevent power gating. |
| 6448 | */ |
| 6449 | mac_data = er32(TDFH); |
| 6450 | if (mac_data) |
| 6451 | ew32(TDFH, 0); |
| 6452 | mac_data = er32(TDFT); |
| 6453 | if (mac_data) |
| 6454 | ew32(TDFT, 0); |
| 6455 | mac_data = er32(TDFHS); |
| 6456 | if (mac_data) |
| 6457 | ew32(TDFHS, 0); |
| 6458 | mac_data = er32(TDFTS); |
| 6459 | if (mac_data) |
| 6460 | ew32(TDFTS, 0); |
| 6461 | mac_data = er32(TDFPC); |
| 6462 | if (mac_data) |
| 6463 | ew32(TDFPC, 0); |
| 6464 | mac_data = er32(RDFH); |
| 6465 | if (mac_data) |
| 6466 | ew32(RDFH, 0); |
| 6467 | mac_data = er32(RDFT); |
| 6468 | if (mac_data) |
| 6469 | ew32(RDFT, 0); |
| 6470 | mac_data = er32(RDFHS); |
| 6471 | if (mac_data) |
| 6472 | ew32(RDFHS, 0); |
| 6473 | mac_data = er32(RDFTS); |
| 6474 | if (mac_data) |
| 6475 | ew32(RDFTS, 0); |
| 6476 | mac_data = er32(RDFPC); |
| 6477 | if (mac_data) |
| 6478 | ew32(RDFPC, 0); |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6479 | } |
| 6480 | |
| 6481 | static void e1000e_s0ix_exit_flow(struct e1000_adapter *adapter) |
| 6482 | { |
| 6483 | struct e1000_hw *hw = &adapter->hw; |
| 6484 | u32 mac_data; |
| 6485 | u16 phy_data; |
| 6486 | |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6487 | if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) { |
| 6488 | /* Request ME unconfigure the device from S0ix */ |
| 6489 | mac_data = er32(H2ME); |
| 6490 | mac_data &= ~E1000_H2ME_START_DPG; |
| 6491 | mac_data |= E1000_H2ME_EXIT_DPG; |
| 6492 | ew32(H2ME, mac_data); |
| 6493 | } else { |
| 6494 | /* Request driver unconfigure the device from S0ix */ |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6495 | |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6496 | /* Disable the Dynamic Power Gating in the MAC */ |
| 6497 | mac_data = er32(FEXTNVM7); |
| 6498 | mac_data &= 0xFFBFFFFF; |
| 6499 | ew32(FEXTNVM7, mac_data); |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6500 | |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6501 | /* Disable mPHY power gating for any link and speed */ |
| 6502 | mac_data = er32(FEXTNVM8); |
| 6503 | mac_data &= ~BIT(9); |
| 6504 | ew32(FEXTNVM8, mac_data); |
Vitaly Lifshits | 632fbd5 | 2020-03-12 13:57:07 +0200 | [diff] [blame] | 6505 | |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6506 | /* Disable K1 off */ |
| 6507 | mac_data = er32(FEXTNVM6); |
| 6508 | mac_data &= ~BIT(31); |
| 6509 | ew32(FEXTNVM6, mac_data); |
Vitaly Lifshits | 632fbd5 | 2020-03-12 13:57:07 +0200 | [diff] [blame] | 6510 | |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6511 | /* Disable Ungate PGCB clock */ |
| 6512 | mac_data = er32(FEXTNVM9); |
| 6513 | mac_data |= BIT(28); |
| 6514 | ew32(FEXTNVM9, mac_data); |
Vitaly Lifshits | 632fbd5 | 2020-03-12 13:57:07 +0200 | [diff] [blame] | 6515 | |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6516 | /* Cancel not waking from dynamic |
| 6517 | * Power Gating with clock request |
| 6518 | */ |
| 6519 | mac_data = er32(FEXTNVM12); |
| 6520 | mac_data &= ~BIT(12); |
| 6521 | ew32(FEXTNVM12, mac_data); |
Vitaly Lifshits | 632fbd5 | 2020-03-12 13:57:07 +0200 | [diff] [blame] | 6522 | |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6523 | /* Cancel disable disconnected cable conditioning |
| 6524 | * for Power Gating |
| 6525 | */ |
| 6526 | mac_data = er32(DPGFR); |
| 6527 | mac_data &= ~BIT(2); |
| 6528 | ew32(DPGFR, mac_data); |
| 6529 | |
| 6530 | /* Disable the Dynamic Clock Gating in the DMA and MAC */ |
| 6531 | mac_data = er32(CTRL_EXT); |
| 6532 | mac_data &= 0xFFF7FFFF; |
| 6533 | ew32(CTRL_EXT, mac_data); |
| 6534 | |
| 6535 | /* Revert the lanphypc logic to use the internal Gbe counter |
| 6536 | * and not the PMC counter |
| 6537 | */ |
| 6538 | mac_data = er32(FEXTNVM5); |
| 6539 | mac_data &= 0xFFFFFF7F; |
| 6540 | ew32(FEXTNVM5, mac_data); |
| 6541 | |
| 6542 | /* Enable the periodic inband message, |
| 6543 | * Request PCIe clock in K1 page770_17[10:9] =01b |
| 6544 | */ |
| 6545 | e1e_rphy(hw, HV_PM_CTRL, &phy_data); |
| 6546 | phy_data &= 0xFBFF; |
| 6547 | phy_data |= HV_PM_CTRL_K1_CLK_REQ; |
| 6548 | e1e_wphy(hw, HV_PM_CTRL, phy_data); |
| 6549 | |
| 6550 | /* Return back configuration |
| 6551 | * 772_29[5] = 0 CS_Mode_Stay_In_K1 |
| 6552 | */ |
| 6553 | e1e_rphy(hw, I217_CGFREG, &phy_data); |
| 6554 | phy_data &= 0xFFDF; |
| 6555 | e1e_wphy(hw, I217_CGFREG, phy_data); |
| 6556 | |
| 6557 | /* Change the MAC/PHY interface to Kumeran |
| 6558 | * Unforce the SMBus in PHY page769_23[0] = 0 |
| 6559 | * Unforce the SMBus in MAC CTRL_EXT[11] = 0 |
| 6560 | */ |
| 6561 | e1e_rphy(hw, CV_SMB_CTRL, &phy_data); |
| 6562 | phy_data &= ~CV_SMB_CTRL_FORCE_SMBUS; |
| 6563 | e1e_wphy(hw, CV_SMB_CTRL, phy_data); |
| 6564 | mac_data = er32(CTRL_EXT); |
| 6565 | mac_data &= ~E1000_CTRL_EXT_FORCE_SMBUS; |
| 6566 | ew32(CTRL_EXT, mac_data); |
| 6567 | } |
Vitaly Lifshits | 632fbd5 | 2020-03-12 13:57:07 +0200 | [diff] [blame] | 6568 | |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6569 | /* Disable Dynamic Power Gating */ |
| 6570 | mac_data = er32(CTRL_EXT); |
| 6571 | mac_data &= 0xFFFFFFF7; |
| 6572 | ew32(CTRL_EXT, mac_data); |
| 6573 | |
Sasha Neftin | 3e55d23 | 2021-06-24 11:18:27 +0300 | [diff] [blame^] | 6574 | /* Enable the time synchronization clock */ |
| 6575 | mac_data = er32(FEXTNVM7); |
| 6576 | mac_data &= ~BIT(31); |
| 6577 | mac_data |= BIT(0); |
| 6578 | ew32(FEXTNVM7, mac_data); |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6579 | } |
| 6580 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6581 | static int e1000e_pm_freeze(struct device *dev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6582 | { |
Chuhong Yuan | ee2e80c | 2019-07-23 22:15:13 +0800 | [diff] [blame] | 6583 | struct net_device *netdev = dev_get_drvdata(dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6584 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 6585 | bool present; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6586 | |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 6587 | rtnl_lock(); |
| 6588 | |
| 6589 | present = netif_device_present(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6590 | netif_device_detach(netdev); |
| 6591 | |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 6592 | if (present && netif_running(netdev)) { |
Bruce Allan | bb9e44d | 2012-03-21 00:39:12 +0000 | [diff] [blame] | 6593 | int count = E1000_CHECK_RESET_COUNT; |
| 6594 | |
| 6595 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 6596 | usleep_range(10000, 11000); |
Bruce Allan | bb9e44d | 2012-03-21 00:39:12 +0000 | [diff] [blame] | 6597 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6598 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6599 | |
| 6600 | /* Quiesce the device without resetting the hardware */ |
| 6601 | e1000e_down(adapter, false); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6602 | e1000_free_irq(adapter); |
| 6603 | } |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 6604 | rtnl_unlock(); |
| 6605 | |
Jeff Kirsher | 9f47a48 | 2017-03-23 20:47:15 -0700 | [diff] [blame] | 6606 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6607 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6608 | /* Allow time for pending master requests to run */ |
| 6609 | e1000e_disable_pcie_master(&adapter->hw); |
| 6610 | |
| 6611 | return 0; |
| 6612 | } |
| 6613 | |
| 6614 | static int __e1000_shutdown(struct pci_dev *pdev, bool runtime) |
| 6615 | { |
| 6616 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6617 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6618 | struct e1000_hw *hw = &adapter->hw; |
Chen Yu | 6bf6be1 | 2020-05-22 01:59:00 +0800 | [diff] [blame] | 6619 | u32 ctrl, ctrl_ext, rctl, status, wufc; |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6620 | int retval = 0; |
| 6621 | |
Chen Yu | 6bf6be1 | 2020-05-22 01:59:00 +0800 | [diff] [blame] | 6622 | /* Runtime suspend should only enable wakeup for link changes */ |
| 6623 | if (runtime) |
| 6624 | wufc = E1000_WUFC_LNKC; |
| 6625 | else if (device_may_wakeup(&pdev->dev)) |
| 6626 | wufc = adapter->wol; |
| 6627 | else |
| 6628 | wufc = 0; |
| 6629 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6630 | status = er32(STATUS); |
| 6631 | if (status & E1000_STATUS_LU) |
| 6632 | wufc &= ~E1000_WUFC_LNKC; |
| 6633 | |
| 6634 | if (wufc) { |
| 6635 | e1000_setup_rctl(adapter); |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 6636 | e1000e_set_rx_mode(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6637 | |
| 6638 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 6639 | if (wufc & E1000_WUFC_MC) { |
| 6640 | rctl = er32(RCTL); |
| 6641 | rctl |= E1000_RCTL_MPE; |
| 6642 | ew32(RCTL, rctl); |
| 6643 | } |
| 6644 | |
| 6645 | ctrl = er32(CTRL); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6646 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 6647 | if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) |
| 6648 | ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6649 | ew32(CTRL, ctrl); |
| 6650 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 6651 | if (adapter->hw.phy.media_type == e1000_media_type_fiber || |
| 6652 | adapter->hw.phy.media_type == |
| 6653 | e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6654 | /* keep the laser running in D3 */ |
| 6655 | ctrl_ext = er32(CTRL_EXT); |
Bruce Allan | 93a23f4 | 2009-12-08 07:27:41 +0000 | [diff] [blame] | 6656 | ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6657 | ew32(CTRL_EXT, ctrl_ext); |
| 6658 | } |
| 6659 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 6660 | if (!runtime) |
| 6661 | e1000e_power_up_phy(adapter); |
| 6662 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6663 | if (adapter->flags & FLAG_IS_ICH) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 6664 | e1000_suspend_workarounds_ich8lan(&adapter->hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 6665 | |
Bruce Allan | 82776a4 | 2009-08-14 14:35:33 +0000 | [diff] [blame] | 6666 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6667 | /* enable wakeup by the PHY */ |
| 6668 | retval = e1000_init_phy_wakeup(adapter, wufc); |
| 6669 | if (retval) |
| 6670 | return retval; |
| 6671 | } else { |
| 6672 | /* enable wakeup by the MAC */ |
| 6673 | ew32(WUFC, wufc); |
| 6674 | ew32(WUC, E1000_WUC_PME_EN); |
| 6675 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6676 | } else { |
| 6677 | ew32(WUC, 0); |
| 6678 | ew32(WUFC, 0); |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6679 | |
| 6680 | e1000_power_down_phy(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6681 | } |
| 6682 | |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6683 | if (adapter->hw.phy.type == e1000_phy_igp_3) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6684 | e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); |
Sasha Neftin | c8744f4 | 2017-04-06 10:26:47 +0300 | [diff] [blame] | 6685 | } else if (hw->mac.type >= e1000_pch_lpt) { |
Chen Yu | 6bf6be1 | 2020-05-22 01:59:00 +0800 | [diff] [blame] | 6686 | if (wufc && !(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC))) |
David Ertman | 74f350e | 2014-02-22 03:15:17 +0000 | [diff] [blame] | 6687 | /* ULP does not support wake from unicast, multicast |
| 6688 | * or broadcast. |
| 6689 | */ |
| 6690 | retval = e1000_enable_ulp_lpt_lp(hw, !runtime); |
| 6691 | |
| 6692 | if (retval) |
| 6693 | return retval; |
| 6694 | } |
| 6695 | |
Raanan Avargil | f5ac744 | 2015-07-06 16:48:00 +0300 | [diff] [blame] | 6696 | /* Ensure that the appropriate bits are set in LPI_CTRL |
| 6697 | * for EEE in Sx |
| 6698 | */ |
| 6699 | if ((hw->phy.type >= e1000_phy_i217) && |
| 6700 | adapter->eee_advert && hw->dev_spec.ich8lan.eee_lp_ability) { |
| 6701 | u16 lpi_ctrl = 0; |
| 6702 | |
| 6703 | retval = hw->phy.ops.acquire(hw); |
| 6704 | if (!retval) { |
| 6705 | retval = e1e_rphy_locked(hw, I82579_LPI_CTRL, |
| 6706 | &lpi_ctrl); |
| 6707 | if (!retval) { |
| 6708 | if (adapter->eee_advert & |
| 6709 | hw->dev_spec.ich8lan.eee_lp_ability & |
| 6710 | I82579_EEE_100_SUPPORTED) |
| 6711 | lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE; |
| 6712 | if (adapter->eee_advert & |
| 6713 | hw->dev_spec.ich8lan.eee_lp_ability & |
| 6714 | I82579_EEE_1000_SUPPORTED) |
| 6715 | lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE; |
| 6716 | |
| 6717 | retval = e1e_wphy_locked(hw, I82579_LPI_CTRL, |
| 6718 | lpi_ctrl); |
| 6719 | } |
| 6720 | } |
| 6721 | hw->phy.ops.release(hw); |
| 6722 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6723 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6724 | /* 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] | 6725 | * would have already happened in close and is redundant. |
| 6726 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6727 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6728 | |
Dean Nelson | 24b41c9 | 2013-06-13 03:55:44 +0000 | [diff] [blame] | 6729 | pci_clear_master(pdev); |
| 6730 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6731 | /* The pci-e switch on some quad port adapters will report a |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6732 | * correctable error when the MAC transitions from D0 to D3. To |
| 6733 | * prevent this we need to mask off the correctable errors on the |
| 6734 | * downstream port of the pci-e switch. |
Li Zhang | e8c254c | 2013-08-13 18:42:58 +0000 | [diff] [blame] | 6735 | * |
| 6736 | * We don't have the associated upstream bridge while assigning |
| 6737 | * the PCI device into guest. For example, the KVM on power is |
| 6738 | * one of the cases. |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6739 | */ |
| 6740 | if (adapter->flags & FLAG_IS_QUAD_PORT) { |
| 6741 | struct pci_dev *us_dev = pdev->bus->self; |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6742 | u16 devctl; |
| 6743 | |
Li Zhang | e8c254c | 2013-08-13 18:42:58 +0000 | [diff] [blame] | 6744 | if (!us_dev) |
| 6745 | return 0; |
| 6746 | |
Jiang Liu | f8c0fca | 2012-08-20 13:30:43 -0600 | [diff] [blame] | 6747 | pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl); |
| 6748 | pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, |
| 6749 | (devctl & ~PCI_EXP_DEVCTL_CERE)); |
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 | pci_save_state(pdev); |
| 6752 | pci_prepare_to_sleep(pdev); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6753 | |
Jiang Liu | f8c0fca | 2012-08-20 13:30:43 -0600 | [diff] [blame] | 6754 | pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl); |
Alexander Duyck | 005cbdf | 2008-11-21 16:49:10 -0800 | [diff] [blame] | 6755 | } |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 6756 | |
| 6757 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6758 | } |
| 6759 | |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6760 | /** |
Yanir Lubetkin | beb0a15 | 2015-06-10 01:15:05 +0300 | [diff] [blame] | 6761 | * __e1000e_disable_aspm - Disable ASPM states |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6762 | * @pdev: pointer to PCI device struct |
| 6763 | * @state: bit-mask of ASPM states to disable |
Yanir Lubetkin | beb0a15 | 2015-06-10 01:15:05 +0300 | [diff] [blame] | 6764 | * @locked: indication if this context holds pci_bus_sem locked. |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6765 | * |
| 6766 | * Some devices *must* have certain ASPM states disabled per hardware errata. |
| 6767 | **/ |
Yanir Lubetkin | beb0a15 | 2015-06-10 01:15:05 +0300 | [diff] [blame] | 6768 | 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] | 6769 | { |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6770 | struct pci_dev *parent = pdev->bus->self; |
| 6771 | u16 aspm_dis_mask = 0; |
| 6772 | u16 pdev_aspmc, parent_aspmc; |
Bjorn Helgaas | ffe0b2ff | 2012-12-06 06:40:07 +0000 | [diff] [blame] | 6773 | |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6774 | switch (state) { |
| 6775 | case PCIE_LINK_STATE_L0S: |
| 6776 | case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1: |
| 6777 | aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S; |
Jeff Kirsher | 5463fce6 | 2020-06-03 20:07:26 -0700 | [diff] [blame] | 6778 | fallthrough; /* can't have L1 without L0s */ |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6779 | case PCIE_LINK_STATE_L1: |
| 6780 | aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1; |
| 6781 | break; |
| 6782 | default: |
| 6783 | return; |
| 6784 | } |
| 6785 | |
| 6786 | pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc); |
| 6787 | pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC; |
| 6788 | |
| 6789 | if (parent) { |
| 6790 | pcie_capability_read_word(parent, PCI_EXP_LNKCTL, |
| 6791 | &parent_aspmc); |
| 6792 | parent_aspmc &= PCI_EXP_LNKCTL_ASPMC; |
| 6793 | } |
| 6794 | |
| 6795 | /* Nothing to do if the ASPM states to be disabled already are */ |
| 6796 | if (!(pdev_aspmc & aspm_dis_mask) && |
| 6797 | (!parent || !(parent_aspmc & aspm_dis_mask))) |
| 6798 | return; |
| 6799 | |
| 6800 | dev_info(&pdev->dev, "Disabling ASPM %s %s\n", |
| 6801 | (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ? |
| 6802 | "L0s" : "", |
| 6803 | (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ? |
| 6804 | "L1" : ""); |
| 6805 | |
| 6806 | #ifdef CONFIG_PCIEASPM |
Yanir Lubetkin | beb0a15 | 2015-06-10 01:15:05 +0300 | [diff] [blame] | 6807 | if (locked) |
| 6808 | pci_disable_link_state_locked(pdev, state); |
| 6809 | else |
| 6810 | pci_disable_link_state(pdev, state); |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6811 | |
| 6812 | /* Double-check ASPM control. If not disabled by the above, the |
| 6813 | * BIOS is preventing that from happening (or CONFIG_PCIEASPM is |
| 6814 | * not enabled); override by writing PCI config space directly. |
| 6815 | */ |
| 6816 | pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc); |
| 6817 | pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC; |
| 6818 | |
| 6819 | if (!(aspm_dis_mask & pdev_aspmc)) |
| 6820 | return; |
| 6821 | #endif |
Bjorn Helgaas | ffe0b2ff | 2012-12-06 06:40:07 +0000 | [diff] [blame] | 6822 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6823 | /* Both device and parent should have the same ASPM setting. |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6824 | * Disable ASPM in downstream component first and then upstream. |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 6825 | */ |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6826 | pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask); |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 6827 | |
Carolyn Wyborny | 13129d9 | 2013-08-03 01:53:54 +0000 | [diff] [blame] | 6828 | if (parent) |
| 6829 | pcie_capability_clear_word(parent, PCI_EXP_LNKCTL, |
| 6830 | aspm_dis_mask); |
Auke Kok | 1eae4eb | 2007-10-31 15:22:00 -0700 | [diff] [blame] | 6831 | } |
| 6832 | |
Yanir Lubetkin | beb0a15 | 2015-06-10 01:15:05 +0300 | [diff] [blame] | 6833 | /** |
| 6834 | * e1000e_disable_aspm - Disable ASPM states. |
| 6835 | * @pdev: pointer to PCI device struct |
| 6836 | * @state: bit-mask of ASPM states to disable |
| 6837 | * |
| 6838 | * This function acquires the pci_bus_sem! |
| 6839 | * Some devices *must* have certain ASPM states disabled per hardware errata. |
| 6840 | **/ |
| 6841 | static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) |
| 6842 | { |
| 6843 | __e1000e_disable_aspm(pdev, state, 0); |
| 6844 | } |
| 6845 | |
| 6846 | /** |
Sasha Neftin | 39da2ca | 2021-03-14 15:59:20 +0200 | [diff] [blame] | 6847 | * e1000e_disable_aspm_locked - Disable ASPM states. |
Yanir Lubetkin | beb0a15 | 2015-06-10 01:15:05 +0300 | [diff] [blame] | 6848 | * @pdev: pointer to PCI device struct |
| 6849 | * @state: bit-mask of ASPM states to disable |
| 6850 | * |
| 6851 | * This function must be called with pci_bus_sem acquired! |
| 6852 | * Some devices *must* have certain ASPM states disabled per hardware errata. |
| 6853 | **/ |
| 6854 | static void e1000e_disable_aspm_locked(struct pci_dev *pdev, u16 state) |
| 6855 | { |
| 6856 | __e1000e_disable_aspm(pdev, state, 1); |
| 6857 | } |
| 6858 | |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 6859 | static int e1000e_pm_thaw(struct device *dev) |
| 6860 | { |
| 6861 | struct net_device *netdev = dev_get_drvdata(dev); |
| 6862 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6863 | int rc = 0; |
| 6864 | |
| 6865 | e1000e_set_interrupt_capability(adapter); |
| 6866 | |
| 6867 | rtnl_lock(); |
| 6868 | if (netif_running(netdev)) { |
| 6869 | rc = e1000_request_irq(adapter); |
| 6870 | if (rc) |
| 6871 | goto err_irq; |
| 6872 | |
| 6873 | e1000e_up(adapter); |
| 6874 | } |
| 6875 | |
| 6876 | netif_device_attach(netdev); |
| 6877 | err_irq: |
| 6878 | rtnl_unlock(); |
| 6879 | |
| 6880 | return rc; |
| 6881 | } |
| 6882 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6883 | static int __e1000_resume(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6884 | { |
| 6885 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6886 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 6887 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6888 | u16 aspm_disable_flag = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6889 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6890 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 6891 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
| 6892 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
| 6893 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 6894 | if (aspm_disable_flag) |
Raanan Avargil | 2758f9e | 2015-07-06 17:57:36 +0300 | [diff] [blame] | 6895 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 6896 | |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 6897 | pci_set_master(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 6898 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 6899 | if (hw->mac.type >= e1000_pch2lan) |
Bruce Allan | 99730e4 | 2011-05-13 07:19:48 +0000 | [diff] [blame] | 6900 | e1000_resume_workarounds_pchlan(&adapter->hw); |
| 6901 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6902 | e1000e_power_up_phy(adapter); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6903 | |
| 6904 | /* report the system wakeup cause from S3/S4 */ |
| 6905 | if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { |
| 6906 | u16 phy_data; |
| 6907 | |
| 6908 | e1e_rphy(&adapter->hw, BM_WUS, &phy_data); |
| 6909 | if (phy_data) { |
| 6910 | e_info("PHY Wakeup cause - %s\n", |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 6911 | phy_data & E1000_WUS_EX ? "Unicast Packet" : |
| 6912 | phy_data & E1000_WUS_MC ? "Multicast Packet" : |
| 6913 | phy_data & E1000_WUS_BC ? "Broadcast Packet" : |
| 6914 | phy_data & E1000_WUS_MAG ? "Magic Packet" : |
| 6915 | phy_data & E1000_WUS_LNKC ? |
| 6916 | "Link Status Change" : "other"); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6917 | } |
| 6918 | e1e_wphy(&adapter->hw, BM_WUS, ~0); |
| 6919 | } else { |
| 6920 | u32 wus = er32(WUS); |
David Ertman | 6cf08d1 | 2014-04-05 06:07:00 +0000 | [diff] [blame] | 6921 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6922 | if (wus) { |
| 6923 | e_info("MAC Wakeup cause - %s\n", |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 6924 | wus & E1000_WUS_EX ? "Unicast Packet" : |
| 6925 | wus & E1000_WUS_MC ? "Multicast Packet" : |
| 6926 | wus & E1000_WUS_BC ? "Broadcast Packet" : |
| 6927 | wus & E1000_WUS_MAG ? "Magic Packet" : |
| 6928 | wus & E1000_WUS_LNKC ? "Link Status Change" : |
| 6929 | "other"); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 6930 | } |
| 6931 | ew32(WUS, ~0); |
| 6932 | } |
| 6933 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6934 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6935 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 6936 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6937 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 6938 | /* 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] | 6939 | * 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] | 6940 | * under the control of the driver. |
| 6941 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 6942 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 6943 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 6944 | |
| 6945 | return 0; |
| 6946 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6947 | |
Wei Yongjun | f2d75b1 | 2021-03-17 14:52:34 +0000 | [diff] [blame] | 6948 | static __maybe_unused int e1000e_pm_prepare(struct device *dev) |
Chen Yu | ccf8b94 | 2020-12-01 09:21:50 +0800 | [diff] [blame] | 6949 | { |
| 6950 | return pm_runtime_suspended(dev) && |
| 6951 | pm_suspend_via_firmware(); |
| 6952 | } |
| 6953 | |
Arnd Bergmann | 880e626 | 2020-05-27 15:47:00 +0200 | [diff] [blame] | 6954 | static __maybe_unused int e1000e_pm_suspend(struct device *dev) |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6955 | { |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6956 | struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev)); |
| 6957 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6958 | struct pci_dev *pdev = to_pci_dev(dev); |
Chris Wilson | 833521e | 2017-05-31 18:50:43 +0300 | [diff] [blame] | 6959 | int rc; |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6960 | |
David Ertman | 2a7e19a | 2014-07-11 06:21:31 +0000 | [diff] [blame] | 6961 | e1000e_flush_lpic(pdev); |
| 6962 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6963 | e1000e_pm_freeze(dev); |
| 6964 | |
Chris Wilson | 833521e | 2017-05-31 18:50:43 +0300 | [diff] [blame] | 6965 | rc = __e1000_shutdown(pdev, false); |
Mario Limonciello | 808e0d8 | 2020-12-14 13:29:32 -0600 | [diff] [blame] | 6966 | if (rc) { |
Chris Wilson | 833521e | 2017-05-31 18:50:43 +0300 | [diff] [blame] | 6967 | e1000e_pm_thaw(dev); |
Mario Limonciello | 808e0d8 | 2020-12-14 13:29:32 -0600 | [diff] [blame] | 6968 | } else { |
| 6969 | /* Introduce S0ix implementation */ |
Mario Limonciello | 3c98cbf | 2020-12-14 13:29:35 -0600 | [diff] [blame] | 6970 | if (adapter->flags2 & FLAG2_ENABLE_S0IX_FLOWS) |
Mario Limonciello | 808e0d8 | 2020-12-14 13:29:32 -0600 | [diff] [blame] | 6971 | e1000e_s0ix_entry_flow(adapter); |
| 6972 | } |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6973 | |
Chris Wilson | 833521e | 2017-05-31 18:50:43 +0300 | [diff] [blame] | 6974 | return rc; |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6975 | } |
| 6976 | |
Arnd Bergmann | 880e626 | 2020-05-27 15:47:00 +0200 | [diff] [blame] | 6977 | static __maybe_unused int e1000e_pm_resume(struct device *dev) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6978 | { |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6979 | struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev)); |
| 6980 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6981 | struct pci_dev *pdev = to_pci_dev(dev); |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6982 | int rc; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6983 | |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6984 | /* Introduce S0ix implementation */ |
Mario Limonciello | 3c98cbf | 2020-12-14 13:29:35 -0600 | [diff] [blame] | 6985 | if (adapter->flags2 & FLAG2_ENABLE_S0IX_FLOWS) |
Sasha Neftin | f15bb6d | 2019-09-16 09:52:40 +0300 | [diff] [blame] | 6986 | e1000e_s0ix_exit_flow(adapter); |
| 6987 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6988 | rc = __e1000_resume(pdev); |
| 6989 | if (rc) |
| 6990 | return rc; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6991 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 6992 | return e1000e_pm_thaw(dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 6993 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6994 | |
Arnd Bergmann | 880e626 | 2020-05-27 15:47:00 +0200 | [diff] [blame] | 6995 | static __maybe_unused int e1000e_pm_runtime_idle(struct device *dev) |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6996 | { |
Chuhong Yuan | ee2e80c | 2019-07-23 22:15:13 +0800 | [diff] [blame] | 6997 | struct net_device *netdev = dev_get_drvdata(dev); |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 6998 | struct e1000_adapter *adapter = netdev_priv(netdev); |
David Ertman | 2116bc25 | 2014-07-11 06:21:23 +0000 | [diff] [blame] | 6999 | u16 eee_lp; |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 7000 | |
David Ertman | 2116bc25 | 2014-07-11 06:21:23 +0000 | [diff] [blame] | 7001 | eee_lp = adapter->hw.dev_spec.ich8lan.eee_lp_ability; |
| 7002 | |
| 7003 | if (!e1000e_has_link(adapter)) { |
| 7004 | adapter->hw.dev_spec.ich8lan.eee_lp_ability = eee_lp; |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7005 | pm_schedule_suspend(dev, 5 * MSEC_PER_SEC); |
David Ertman | 2116bc25 | 2014-07-11 06:21:23 +0000 | [diff] [blame] | 7006 | } |
Rafael J. Wysocki | a034016 | 2010-03-17 23:12:24 -0700 | [diff] [blame] | 7007 | |
| 7008 | return -EBUSY; |
| 7009 | } |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7010 | |
Arnd Bergmann | 880e626 | 2020-05-27 15:47:00 +0200 | [diff] [blame] | 7011 | static __maybe_unused int e1000e_pm_runtime_resume(struct device *dev) |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7012 | { |
| 7013 | struct pci_dev *pdev = to_pci_dev(dev); |
| 7014 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7015 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7016 | int rc; |
| 7017 | |
| 7018 | rc = __e1000_resume(pdev); |
| 7019 | if (rc) |
| 7020 | return rc; |
| 7021 | |
| 7022 | if (netdev->flags & IFF_UP) |
Alexander Duyck | 386164d | 2015-10-27 16:59:31 -0700 | [diff] [blame] | 7023 | e1000e_up(adapter); |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7024 | |
| 7025 | return rc; |
| 7026 | } |
| 7027 | |
Arnd Bergmann | 880e626 | 2020-05-27 15:47:00 +0200 | [diff] [blame] | 7028 | static __maybe_unused int e1000e_pm_runtime_suspend(struct device *dev) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7029 | { |
| 7030 | struct pci_dev *pdev = to_pci_dev(dev); |
| 7031 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7032 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7033 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7034 | if (netdev->flags & IFF_UP) { |
| 7035 | int count = E1000_CHECK_RESET_COUNT; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7036 | |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7037 | while (test_bit(__E1000_RESETTING, &adapter->state) && count--) |
Arjan van de Ven | ab6973a | 2019-06-14 17:29:35 -0700 | [diff] [blame] | 7038 | usleep_range(10000, 11000); |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7039 | |
| 7040 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); |
| 7041 | |
| 7042 | /* Down the device without resetting the hardware */ |
| 7043 | e1000e_down(adapter, false); |
| 7044 | } |
| 7045 | |
| 7046 | if (__e1000_shutdown(pdev, true)) { |
| 7047 | e1000e_pm_runtime_resume(dev); |
| 7048 | return -EBUSY; |
| 7049 | } |
| 7050 | |
| 7051 | return 0; |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7052 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7053 | |
| 7054 | static void e1000_shutdown(struct pci_dev *pdev) |
| 7055 | { |
David Ertman | 2a7e19a | 2014-07-11 06:21:31 +0000 | [diff] [blame] | 7056 | e1000e_flush_lpic(pdev); |
| 7057 | |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 7058 | e1000e_pm_freeze(&pdev->dev); |
| 7059 | |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 7060 | __e1000_shutdown(pdev, false); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7061 | } |
| 7062 | |
| 7063 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7064 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 7065 | static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data) |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7066 | { |
| 7067 | struct net_device *netdev = data; |
| 7068 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7069 | |
| 7070 | if (adapter->msix_entries) { |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 7071 | int vector, msix_irq; |
| 7072 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7073 | vector = 0; |
| 7074 | msix_irq = adapter->msix_entries[vector].vector; |
Konstantin Khlebnikov | fd8e597 | 2017-05-19 10:18:49 +0300 | [diff] [blame] | 7075 | if (disable_hardirq(msix_irq)) |
| 7076 | e1000_intr_msix_rx(msix_irq, netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7077 | enable_irq(msix_irq); |
| 7078 | |
| 7079 | vector++; |
| 7080 | msix_irq = adapter->msix_entries[vector].vector; |
Konstantin Khlebnikov | fd8e597 | 2017-05-19 10:18:49 +0300 | [diff] [blame] | 7081 | if (disable_hardirq(msix_irq)) |
| 7082 | e1000_intr_msix_tx(msix_irq, netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7083 | enable_irq(msix_irq); |
| 7084 | |
| 7085 | vector++; |
| 7086 | msix_irq = adapter->msix_entries[vector].vector; |
Konstantin Khlebnikov | fd8e597 | 2017-05-19 10:18:49 +0300 | [diff] [blame] | 7087 | if (disable_hardirq(msix_irq)) |
| 7088 | e1000_msix_other(msix_irq, netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7089 | enable_irq(msix_irq); |
| 7090 | } |
| 7091 | |
| 7092 | return IRQ_HANDLED; |
| 7093 | } |
| 7094 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7095 | /** |
| 7096 | * e1000_netpoll |
| 7097 | * @netdev: network interface device structure |
| 7098 | * |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7099 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 7100 | * without having to re-enable interrupts. It's not called while |
| 7101 | * the interrupt routine is executing. |
| 7102 | */ |
| 7103 | static void e1000_netpoll(struct net_device *netdev) |
| 7104 | { |
| 7105 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7106 | |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7107 | switch (adapter->int_mode) { |
| 7108 | case E1000E_INT_MODE_MSIX: |
| 7109 | e1000_intr_msix(adapter->pdev->irq, netdev); |
| 7110 | break; |
| 7111 | case E1000E_INT_MODE_MSI: |
WANG Cong | 3111912 | 2016-12-10 14:22:42 -0800 | [diff] [blame] | 7112 | if (disable_hardirq(adapter->pdev->irq)) |
| 7113 | e1000_intr_msi(adapter->pdev->irq, netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7114 | enable_irq(adapter->pdev->irq); |
| 7115 | break; |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 7116 | default: /* E1000E_INT_MODE_LEGACY */ |
WANG Cong | 3111912 | 2016-12-10 14:22:42 -0800 | [diff] [blame] | 7117 | if (disable_hardirq(adapter->pdev->irq)) |
| 7118 | e1000_intr(adapter->pdev->irq, netdev); |
Dongdong Deng | 147b2c8 | 2010-11-16 19:50:15 -0800 | [diff] [blame] | 7119 | enable_irq(adapter->pdev->irq); |
| 7120 | break; |
| 7121 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7122 | } |
| 7123 | #endif |
| 7124 | |
| 7125 | /** |
| 7126 | * e1000_io_error_detected - called when PCI error is detected |
| 7127 | * @pdev: Pointer to PCI device |
| 7128 | * @state: The current pci connection state |
| 7129 | * |
| 7130 | * This function is called after a PCI bus error affecting |
| 7131 | * this device has been detected. |
| 7132 | */ |
| 7133 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 7134 | pci_channel_state_t state) |
| 7135 | { |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 7136 | e1000e_pm_freeze(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7137 | |
Mike Mason | c93b5a7 | 2009-06-30 12:45:53 +0000 | [diff] [blame] | 7138 | if (state == pci_channel_io_perm_failure) |
| 7139 | return PCI_ERS_RESULT_DISCONNECT; |
| 7140 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7141 | pci_disable_device(pdev); |
| 7142 | |
Hao Chen | 800b74a | 2021-05-19 14:14:44 +0800 | [diff] [blame] | 7143 | /* Request a slot reset. */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7144 | return PCI_ERS_RESULT_NEED_RESET; |
| 7145 | } |
| 7146 | |
| 7147 | /** |
| 7148 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 7149 | * @pdev: Pointer to PCI device |
| 7150 | * |
| 7151 | * Restart the card from scratch, as if from a cold-boot. Implementation |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 7152 | * resembles the first-half of the e1000e_pm_resume routine. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7153 | */ |
| 7154 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 7155 | { |
| 7156 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7157 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7158 | struct e1000_hw *hw = &adapter->hw; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7159 | u16 aspm_disable_flag = 0; |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 7160 | int err; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7161 | pci_ers_result_t result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7162 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7163 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 7164 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 7165 | if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7166 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 7167 | if (aspm_disable_flag) |
Raanan Avargil | 2758f9e | 2015-07-06 17:57:36 +0300 | [diff] [blame] | 7168 | e1000e_disable_aspm_locked(pdev, aspm_disable_flag); |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7169 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 7170 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 7171 | if (err) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7172 | dev_err(&pdev->dev, |
| 7173 | "Cannot re-enable PCI device after reset.\n"); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7174 | result = PCI_ERS_RESULT_DISCONNECT; |
| 7175 | } else { |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7176 | pdev->state_saved = true; |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7177 | pci_restore_state(pdev); |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 7178 | pci_set_master(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7179 | |
| 7180 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 7181 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 7182 | |
| 7183 | e1000e_reset(adapter); |
| 7184 | ew32(WUS, ~0); |
| 7185 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7186 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7187 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7188 | return result; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7189 | } |
| 7190 | |
| 7191 | /** |
| 7192 | * e1000_io_resume - called when traffic can start flowing again. |
| 7193 | * @pdev: Pointer to PCI device |
| 7194 | * |
| 7195 | * This callback is called when the error recovery driver tells us that |
| 7196 | * its OK to resume normal operation. Implementation resembles the |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 7197 | * second-half of the e1000e_pm_resume routine. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7198 | */ |
| 7199 | static void e1000_io_resume(struct pci_dev *pdev) |
| 7200 | { |
| 7201 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7202 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7203 | |
Bruce Allan | cd79161 | 2010-05-10 14:59:51 +0000 | [diff] [blame] | 7204 | e1000_init_manageability_pt(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7205 | |
Alexander Duyck | a702381 | 2019-10-11 08:34:52 -0700 | [diff] [blame] | 7206 | e1000e_pm_thaw(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7207 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7208 | /* 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] | 7209 | * 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] | 7210 | * under the control of the driver. |
| 7211 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7212 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 7213 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7214 | } |
| 7215 | |
| 7216 | static void e1000_print_device_info(struct e1000_adapter *adapter) |
| 7217 | { |
| 7218 | struct e1000_hw *hw = &adapter->hw; |
| 7219 | struct net_device *netdev = adapter->netdev; |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 7220 | u32 ret_val; |
| 7221 | u8 pba_str[E1000_PBANUM_LENGTH]; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7222 | |
| 7223 | /* print bus type/speed/width info */ |
Bruce Allan | a5cc764 | 2011-03-19 00:31:23 +0000 | [diff] [blame] | 7224 | e_info("(PCI Express:2.5GT/s:%s) %pM\n", |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 7225 | /* bus width */ |
| 7226 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 7227 | "Width x1"), |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 7228 | /* MAC address */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 7229 | netdev->dev_addr); |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 7230 | e_info("Intel(R) PRO/%s Network Connection\n", |
| 7231 | (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 7232 | ret_val = e1000_read_pba_string_generic(hw, pba_str, |
| 7233 | E1000_PBANUM_LENGTH); |
| 7234 | if (ret_val) |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 7235 | strlcpy((char *)pba_str, "Unknown", sizeof(pba_str)); |
Bruce Allan | 073287c | 2010-11-24 06:01:51 +0000 | [diff] [blame] | 7236 | e_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 7237 | hw->mac.type, hw->phy.type, pba_str); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7238 | } |
| 7239 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 7240 | static void e1000_eeprom_checks(struct e1000_adapter *adapter) |
| 7241 | { |
| 7242 | struct e1000_hw *hw = &adapter->hw; |
| 7243 | int ret_val; |
| 7244 | u16 buf = 0; |
| 7245 | |
| 7246 | if (hw->mac.type != e1000_82573) |
| 7247 | return; |
| 7248 | |
| 7249 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 7250 | le16_to_cpus(&buf); |
Jacob Keller | 18dd239 | 2016-04-13 16:08:32 -0700 | [diff] [blame] | 7251 | if (!ret_val && (!(buf & BIT(0)))) { |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 7252 | /* Deep Smart Power Down (DSPD) */ |
Frans Pop | 6c2a9ef | 2008-09-22 14:52:22 -0700 | [diff] [blame] | 7253 | dev_warn(&adapter->pdev->dev, |
| 7254 | "Warning: detected DSPD enabled in EEPROM\n"); |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 7255 | } |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 7256 | } |
| 7257 | |
Alexander Duyck | 55e7fe5 | 2015-05-02 01:09:59 -0700 | [diff] [blame] | 7258 | static netdev_features_t e1000_fix_features(struct net_device *netdev, |
| 7259 | netdev_features_t features) |
| 7260 | { |
| 7261 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 7262 | struct e1000_hw *hw = &adapter->hw; |
| 7263 | |
| 7264 | /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */ |
| 7265 | if ((hw->mac.type >= e1000_pch2lan) && (netdev->mtu > ETH_DATA_LEN)) |
| 7266 | features &= ~NETIF_F_RXFCS; |
| 7267 | |
Jarod Wilson | 8380864 | 2016-06-09 19:50:13 -0400 | [diff] [blame] | 7268 | /* Since there is no support for separate Rx/Tx vlan accel |
| 7269 | * enable/disable make sure Tx flag is always in same state as Rx. |
| 7270 | */ |
| 7271 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 7272 | features |= NETIF_F_HW_VLAN_CTAG_TX; |
| 7273 | else |
| 7274 | features &= ~NETIF_F_HW_VLAN_CTAG_TX; |
| 7275 | |
Alexander Duyck | 55e7fe5 | 2015-05-02 01:09:59 -0700 | [diff] [blame] | 7276 | return features; |
| 7277 | } |
| 7278 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7279 | static int e1000_set_features(struct net_device *netdev, |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 7280 | netdev_features_t features) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7281 | { |
| 7282 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7283 | netdev_features_t changed = features ^ netdev->features; |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7284 | |
| 7285 | if (changed & (NETIF_F_TSO | NETIF_F_TSO6)) |
| 7286 | adapter->flags |= FLAG_TSO_FORCE; |
| 7287 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7288 | 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] | 7289 | NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS | |
| 7290 | NETIF_F_RXALL))) |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7291 | return 0; |
| 7292 | |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 7293 | if (changed & NETIF_F_RXFCS) { |
| 7294 | if (features & NETIF_F_RXFCS) { |
| 7295 | adapter->flags2 &= ~FLAG2_CRC_STRIPPING; |
| 7296 | } else { |
| 7297 | /* We need to take it back to defaults, which might mean |
| 7298 | * stripping is still disabled at the adapter level. |
| 7299 | */ |
| 7300 | if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING) |
| 7301 | adapter->flags2 |= FLAG2_CRC_STRIPPING; |
| 7302 | else |
| 7303 | adapter->flags2 &= ~FLAG2_CRC_STRIPPING; |
| 7304 | } |
| 7305 | } |
| 7306 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 7307 | netdev->features = features; |
| 7308 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7309 | if (netif_running(netdev)) |
| 7310 | e1000e_reinit_locked(adapter); |
| 7311 | else |
| 7312 | e1000e_reset(adapter); |
| 7313 | |
Serhey Popovych | b0ddfe2 | 2018-03-29 17:51:36 +0300 | [diff] [blame] | 7314 | return 1; |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7315 | } |
| 7316 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 7317 | static const struct net_device_ops e1000e_netdev_ops = { |
Stefan Assmann | d5ea45d | 2016-02-03 09:20:52 +0100 | [diff] [blame] | 7318 | .ndo_open = e1000e_open, |
| 7319 | .ndo_stop = e1000e_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 7320 | .ndo_start_xmit = e1000_xmit_frame, |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 7321 | .ndo_get_stats64 = e1000e_get_stats64, |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 7322 | .ndo_set_rx_mode = e1000e_set_rx_mode, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 7323 | .ndo_set_mac_address = e1000_set_mac, |
| 7324 | .ndo_change_mtu = e1000_change_mtu, |
| 7325 | .ndo_do_ioctl = e1000_ioctl, |
| 7326 | .ndo_tx_timeout = e1000_tx_timeout, |
| 7327 | .ndo_validate_addr = eth_validate_addr, |
| 7328 | |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 7329 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 7330 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 7331 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7332 | .ndo_poll_controller = e1000_netpoll, |
| 7333 | #endif |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7334 | .ndo_set_features = e1000_set_features, |
Alexander Duyck | 55e7fe5 | 2015-05-02 01:09:59 -0700 | [diff] [blame] | 7335 | .ndo_fix_features = e1000_fix_features, |
Toshiaki Makita | f2701b1 | 2015-08-06 17:57:29 +0900 | [diff] [blame] | 7336 | .ndo_features_check = passthru_features_check, |
Stephen Hemminger | 651c246 | 2008-11-19 21:57:48 -0800 | [diff] [blame] | 7337 | }; |
| 7338 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7339 | /** |
| 7340 | * e1000_probe - Device Initialization Routine |
| 7341 | * @pdev: PCI device information struct |
| 7342 | * @ent: entry in e1000_pci_tbl |
| 7343 | * |
| 7344 | * Returns 0 on success, negative on failure |
| 7345 | * |
| 7346 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 7347 | * The OS initialization, configuring of the adapter private structure, |
| 7348 | * and a hardware reset occur. |
| 7349 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 7350 | 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] | 7351 | { |
| 7352 | struct net_device *netdev; |
| 7353 | struct e1000_adapter *adapter; |
| 7354 | struct e1000_hw *hw; |
| 7355 | const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; |
Becky Bruce | f47e81f | 2008-05-01 18:03:11 -0500 | [diff] [blame] | 7356 | resource_size_t mmio_start, mmio_len; |
| 7357 | resource_size_t flash_start, flash_len; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7358 | static int cards_found; |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7359 | u16 aspm_disable_flag = 0; |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 7360 | int bars, i, err, pci_using_dac; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7361 | u16 eeprom_data = 0; |
| 7362 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 7363 | s32 ret_val = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7364 | |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7365 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S) |
| 7366 | aspm_disable_flag = PCIE_LINK_STATE_L0S; |
Bruce Allan | 6f461f6 | 2010-04-27 03:33:04 +0000 | [diff] [blame] | 7367 | if (ei->flags2 & FLAG2_DISABLE_ASPM_L1) |
Bruce Allan | 78cd29d | 2011-03-24 03:09:03 +0000 | [diff] [blame] | 7368 | aspm_disable_flag |= PCIE_LINK_STATE_L1; |
| 7369 | if (aspm_disable_flag) |
| 7370 | e1000e_disable_aspm(pdev, aspm_disable_flag); |
Taku Izumi | 6e4f6f6 | 2008-06-20 11:57:02 +0900 | [diff] [blame] | 7371 | |
Bruce Allan | f0f422e | 2008-08-04 17:21:53 -0700 | [diff] [blame] | 7372 | err = pci_enable_device_mem(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7373 | if (err) |
| 7374 | return err; |
| 7375 | |
| 7376 | pci_using_dac = 0; |
Russell King | 718a39e | 2013-06-10 12:22:30 +0100 | [diff] [blame] | 7377 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
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 | pci_using_dac = 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7380 | } else { |
Russell King | 718a39e | 2013-06-10 12:22:30 +0100 | [diff] [blame] | 7381 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7382 | if (err) { |
Russell King | 718a39e | 2013-06-10 12:22:30 +0100 | [diff] [blame] | 7383 | dev_err(&pdev->dev, |
| 7384 | "No usable DMA configuration, aborting\n"); |
| 7385 | goto err_dma; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7386 | } |
| 7387 | } |
| 7388 | |
Bruce Allan | 17e813e | 2013-02-20 04:06:01 +0000 | [diff] [blame] | 7389 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 7390 | err = pci_request_selected_regions_exclusive(pdev, bars, |
| 7391 | e1000e_driver_name); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7392 | if (err) |
| 7393 | goto err_pci_reg; |
| 7394 | |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 7395 | /* AER (Advanced Error Reporting) hooks */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7396 | pci_enable_pcie_error_reporting(pdev); |
Xiaotian Feng | 68eac46 | 2009-08-14 14:35:52 +0000 | [diff] [blame] | 7397 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7398 | pci_set_master(pdev); |
Bruce Allan | 438b365 | 2008-11-21 16:51:33 -0800 | [diff] [blame] | 7399 | /* PCI config space info */ |
| 7400 | err = pci_save_state(pdev); |
| 7401 | if (err) |
| 7402 | goto err_alloc_etherdev; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7403 | |
| 7404 | err = -ENOMEM; |
| 7405 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
| 7406 | if (!netdev) |
| 7407 | goto err_alloc_etherdev; |
| 7408 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7409 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7410 | |
Tom Herbert | f85e4df | 2010-05-05 14:03:32 +0000 | [diff] [blame] | 7411 | netdev->irq = pdev->irq; |
| 7412 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7413 | pci_set_drvdata(pdev, netdev); |
| 7414 | adapter = netdev_priv(netdev); |
| 7415 | hw = &adapter->hw; |
| 7416 | adapter->netdev = netdev; |
| 7417 | adapter->pdev = pdev; |
| 7418 | adapter->ei = ei; |
| 7419 | adapter->pba = ei->pba; |
| 7420 | adapter->flags = ei->flags; |
Jeff Kirsher | eb7c3ad | 2008-11-14 06:45:23 +0000 | [diff] [blame] | 7421 | adapter->flags2 = ei->flags2; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7422 | adapter->hw.adapter = adapter; |
| 7423 | adapter->hw.mac.type = ei->mac; |
Bruce Allan | 2adc55c | 2009-06-02 11:28:58 +0000 | [diff] [blame] | 7424 | adapter->max_hw_frame_size = ei->max_hw_frame_size; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 7425 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7426 | |
| 7427 | mmio_start = pci_resource_start(pdev, 0); |
| 7428 | mmio_len = pci_resource_len(pdev, 0); |
| 7429 | |
| 7430 | err = -EIO; |
| 7431 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 7432 | if (!adapter->hw.hw_addr) |
| 7433 | goto err_ioremap; |
| 7434 | |
| 7435 | if ((adapter->flags & FLAG_HAS_FLASH) && |
Yanir Lubetkin | 1103a63 | 2015-02-28 10:10:06 +0000 | [diff] [blame] | 7436 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM) && |
| 7437 | (hw->mac.type < e1000_pch_spt)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7438 | flash_start = pci_resource_start(pdev, 1); |
| 7439 | flash_len = pci_resource_len(pdev, 1); |
| 7440 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
| 7441 | if (!adapter->hw.flash_address) |
| 7442 | goto err_flashmap; |
| 7443 | } |
| 7444 | |
Bruce Allan | d495bcb | 2013-03-20 07:23:11 +0000 | [diff] [blame] | 7445 | /* Set default EEE advertisement */ |
| 7446 | if (adapter->flags2 & FLAG2_HAS_EEE) |
| 7447 | adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T; |
| 7448 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7449 | /* construct the net_device struct */ |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 7450 | netdev->netdev_ops = &e1000e_netdev_ops; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7451 | e1000e_set_ethtool_ops(netdev); |
Bruce Allan | e80bd1d | 2013-05-01 01:19:46 +0000 | [diff] [blame] | 7452 | netdev->watchdog_timeo = 5 * HZ; |
Bruce Allan | c58c8a7 | 2012-03-20 03:48:19 +0000 | [diff] [blame] | 7453 | netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64); |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 7454 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7455 | |
| 7456 | netdev->mem_start = mmio_start; |
| 7457 | netdev->mem_end = mmio_start + mmio_len; |
| 7458 | |
| 7459 | adapter->bd_number = cards_found++; |
| 7460 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 7461 | e1000e_check_options(adapter); |
| 7462 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7463 | /* setup adapter struct */ |
| 7464 | err = e1000_sw_init(adapter); |
| 7465 | if (err) |
| 7466 | goto err_sw_init; |
| 7467 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7468 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 7469 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 7470 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 7471 | |
Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 7472 | err = ei->get_variants(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7473 | if (err) |
| 7474 | goto err_hw_init; |
| 7475 | |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 7476 | if ((adapter->flags & FLAG_IS_ICH) && |
Yanir Lubetkin | 152c0a9 | 2015-03-20 17:41:53 -0700 | [diff] [blame] | 7477 | (adapter->flags & FLAG_READ_ONLY_NVM) && |
| 7478 | (hw->mac.type < e1000_pch_spt)) |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 7479 | e1000e_write_protect_nvm_ich8lan(&adapter->hw); |
| 7480 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7481 | hw->mac.ops.get_bus_info(&adapter->hw); |
| 7482 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 7483 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7484 | |
| 7485 | /* Copper options */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 7486 | if (adapter->hw.phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7487 | adapter->hw.phy.mdix = AUTO_ALL_MODES; |
| 7488 | adapter->hw.phy.disable_polarity_correction = 0; |
| 7489 | adapter->hw.phy.ms_type = e1000_ms_hw_default; |
| 7490 | } |
| 7491 | |
Bruce Allan | 470a542 | 2012-05-26 06:08:48 +0000 | [diff] [blame] | 7492 | 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] | 7493 | dev_info(&pdev->dev, |
| 7494 | "PHY reset is blocked due to SOL/IDER session.\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7495 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7496 | /* Set initial default active device features */ |
| 7497 | netdev->features = (NETIF_F_SG | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7498 | NETIF_F_HW_VLAN_CTAG_RX | |
| 7499 | NETIF_F_HW_VLAN_CTAG_TX | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7500 | NETIF_F_TSO | |
| 7501 | NETIF_F_TSO6 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 7502 | NETIF_F_RXHASH | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7503 | NETIF_F_RXCSUM | |
| 7504 | NETIF_F_HW_CSUM); |
| 7505 | |
| 7506 | /* Set user-changeable features (subset of all device features) */ |
| 7507 | netdev->hw_features = netdev->features; |
Ben Greear | 0184039 | 2012-02-11 15:39:25 +0000 | [diff] [blame] | 7508 | netdev->hw_features |= NETIF_F_RXFCS; |
Ben Greear | 943146d | 2012-02-11 15:39:40 +0000 | [diff] [blame] | 7509 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Ben Greear | cf955e6 | 2012-02-11 15:39:51 +0000 | [diff] [blame] | 7510 | netdev->hw_features |= NETIF_F_RXALL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7511 | |
| 7512 | if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7513 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7514 | |
Bruce Allan | dc22129 | 2011-08-19 03:23:48 +0000 | [diff] [blame] | 7515 | netdev->vlan_features |= (NETIF_F_SG | |
| 7516 | NETIF_F_TSO | |
| 7517 | NETIF_F_TSO6 | |
| 7518 | NETIF_F_HW_CSUM); |
Jeff Kirsher | a5136e2 | 2008-06-05 04:07:28 -0700 | [diff] [blame] | 7519 | |
Jesse Brandeburg | ef9b965 | 2011-11-04 05:47:06 +0000 | [diff] [blame] | 7520 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 7521 | |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7522 | if (pci_using_dac) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7523 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7524 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 7525 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7526 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 7527 | /* MTU range: 68 - max_hw_frame_size */ |
| 7528 | netdev->min_mtu = ETH_MIN_MTU; |
| 7529 | netdev->max_mtu = adapter->max_hw_frame_size - |
| 7530 | (VLAN_ETH_HLEN + ETH_FCS_LEN); |
| 7531 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7532 | if (e1000e_enable_mng_pass_thru(&adapter->hw)) |
| 7533 | adapter->flags |= FLAG_MNG_PT_ENABLED; |
| 7534 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7535 | /* before reading the NVM, reset the controller to |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7536 | * put the device in a known good starting state |
| 7537 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7538 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 7539 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7540 | /* 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] | 7541 | * attempt. Let's give it a few tries |
| 7542 | */ |
| 7543 | for (i = 0;; i++) { |
| 7544 | if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) |
| 7545 | break; |
| 7546 | if (i == 2) { |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 7547 | dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7548 | err = -EIO; |
| 7549 | goto err_eeprom; |
| 7550 | } |
| 7551 | } |
| 7552 | |
Auke Kok | 10aa4c0 | 2008-08-04 17:21:20 -0700 | [diff] [blame] | 7553 | e1000_eeprom_checks(adapter); |
| 7554 | |
Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 7555 | /* copy the MAC address */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7556 | if (e1000e_read_mac_addr(&adapter->hw)) |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 7557 | dev_err(&pdev->dev, |
| 7558 | "NVM Read Error while reading MAC address\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7559 | |
| 7560 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7561 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 7562 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Bruce Allan | 185095f | 2012-06-07 02:23:37 +0000 | [diff] [blame] | 7563 | dev_err(&pdev->dev, "Invalid MAC Address: %pM\n", |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 7564 | netdev->dev_addr); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7565 | err = -EIO; |
| 7566 | goto err_eeprom; |
| 7567 | } |
| 7568 | |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 7569 | timer_setup(&adapter->watchdog_timer, e1000_watchdog, 0); |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 7570 | timer_setup(&adapter->phy_info_timer, e1000_update_phy_info, 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7571 | |
| 7572 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 7573 | INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); |
Jesse Brandeburg | a8f88ff | 2008-10-02 16:33:25 -0700 | [diff] [blame] | 7574 | INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); |
| 7575 | INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 7576 | INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7577 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7578 | /* Initialize link parameters. User can change them with ethtool */ |
| 7579 | adapter->hw.mac.autoneg = 1; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 7580 | adapter->fc_autoneg = true; |
Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 7581 | adapter->hw.fc.requested_mode = e1000_fc_default; |
| 7582 | adapter->hw.fc.current_mode = e1000_fc_default; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7583 | adapter->hw.phy.autoneg_advertised = 0x2f; |
| 7584 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7585 | /* Initial Wake on LAN setting - If APM wake is enabled in |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7586 | * the EEPROM, enable the ACPI Magic Packet filter |
| 7587 | */ |
| 7588 | if (adapter->flags & FLAG_APME_IN_WUC) { |
| 7589 | /* APME bit in EEPROM is mapped to WUC.APME */ |
| 7590 | eeprom_data = er32(WUC); |
| 7591 | eeprom_apme_mask = E1000_WUC_APME; |
Bruce Allan | 4def99b | 2011-02-02 09:30:36 +0000 | [diff] [blame] | 7592 | if ((hw->mac.type > e1000_ich10lan) && |
| 7593 | (eeprom_data & E1000_WUC_PHY_WAKE)) |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 7594 | adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7595 | } else if (adapter->flags & FLAG_APME_IN_CTRL3) { |
| 7596 | if (adapter->flags & FLAG_APME_CHECK_PORT_B && |
| 7597 | (adapter->hw.bus.func == 1)) |
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_B, |
| 7600 | 1, &eeprom_data); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7601 | else |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 7602 | ret_val = e1000_read_nvm(&adapter->hw, |
David Ertman | 491a04d | 2014-07-09 16:07:42 +0000 | [diff] [blame] | 7603 | NVM_INIT_CONTROL3_PORT_A, |
| 7604 | 1, &eeprom_data); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7605 | } |
| 7606 | |
| 7607 | /* fetch WoL from EEPROM */ |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 7608 | if (ret_val) |
| 7609 | 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] | 7610 | else if (eeprom_data & eeprom_apme_mask) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7611 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 7612 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7613 | /* now that we have the eeprom settings, apply the special cases |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7614 | * where the eeprom may be wrong or the board simply won't support |
| 7615 | * wake on lan on a particular port |
| 7616 | */ |
| 7617 | if (!(adapter->flags & FLAG_HAS_WOL)) |
| 7618 | adapter->eeprom_wol = 0; |
| 7619 | |
| 7620 | /* initialize the wol settings based on the eeprom settings */ |
| 7621 | adapter->wol = adapter->eeprom_wol; |
Konstantin Khlebnikov | 66148ba | 2013-03-05 09:43:04 +0000 | [diff] [blame] | 7622 | |
| 7623 | /* make sure adapter isn't asleep if manageability is enabled */ |
| 7624 | if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) || |
| 7625 | (hw->mac.ops.check_mng_mode(hw))) |
| 7626 | device_wakeup_enable(&pdev->dev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7627 | |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 7628 | /* save off EEPROM version number */ |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 7629 | ret_val = e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); |
David Ertman | 491a04d | 2014-07-09 16:07:42 +0000 | [diff] [blame] | 7630 | |
Brian Walsh | 847042a | 2016-04-12 23:22:30 -0400 | [diff] [blame] | 7631 | if (ret_val) { |
| 7632 | e_dbg("NVM read error getting EEPROM version: %d\n", ret_val); |
David Ertman | 491a04d | 2014-07-09 16:07:42 +0000 | [diff] [blame] | 7633 | adapter->eeprom_vers = 0; |
| 7634 | } |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 7635 | |
Jacob Keller | aa524b6 | 2016-04-20 11:36:42 -0700 | [diff] [blame] | 7636 | /* init PTP hardware clock */ |
| 7637 | e1000e_ptp_init(adapter); |
| 7638 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7639 | /* reset the hardware with the new settings */ |
| 7640 | e1000e_reset(adapter); |
| 7641 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7642 | /* 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] | 7643 | * 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] | 7644 | * under the control of the driver. |
| 7645 | */ |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7646 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 7647 | e1000e_get_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7648 | |
Mario Limonciello | 3c98cbf | 2020-12-14 13:29:35 -0600 | [diff] [blame] | 7649 | if (hw->mac.type >= e1000_pch_cnp) |
| 7650 | adapter->flags2 |= FLAG2_ENABLE_S0IX_FLOWS; |
| 7651 | |
Bruce Allan | f2315bf | 2011-12-16 00:46:59 +0000 | [diff] [blame] | 7652 | strlcpy(netdev->name, "eth%d", sizeof(netdev->name)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7653 | err = register_netdev(netdev); |
| 7654 | if (err) |
| 7655 | goto err_register; |
| 7656 | |
Jesse Brandeburg | 9c563d2 | 2009-04-17 20:44:34 +0000 | [diff] [blame] | 7657 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 7658 | netif_carrier_off(netdev); |
| 7659 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7660 | e1000_print_device_info(adapter); |
| 7661 | |
Chen Yu | ccf8b94 | 2020-12-01 09:21:50 +0800 | [diff] [blame] | 7662 | dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_SMART_PREPARE); |
Kai-Heng Feng | 59f5870 | 2018-12-11 15:59:37 +0800 | [diff] [blame] | 7663 | |
Chen Yu | 3335369 | 2020-12-01 09:22:09 +0800 | [diff] [blame] | 7664 | if (pci_dev_run_wake(pdev) && hw->mac.type != e1000_pch_cnp) |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 7665 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7666 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7667 | return 0; |
| 7668 | |
| 7669 | err_register: |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7670 | if (!(adapter->flags & FLAG_HAS_AMT)) |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 7671 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7672 | err_eeprom: |
Bruce Allan | 470a542 | 2012-05-26 06:08:48 +0000 | [diff] [blame] | 7673 | 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] | 7674 | e1000_phy_hw_reset(&adapter->hw); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7675 | err_hw_init: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7676 | kfree(adapter->tx_ring); |
| 7677 | kfree(adapter->rx_ring); |
| 7678 | err_sw_init: |
Yanir Lubetkin | 1103a63 | 2015-02-28 10:10:06 +0000 | [diff] [blame] | 7679 | if ((adapter->hw.flash_address) && (hw->mac.type < e1000_pch_spt)) |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7680 | iounmap(adapter->hw.flash_address); |
Jeff Kirsher | e82f54b | 2008-11-14 06:45:07 +0000 | [diff] [blame] | 7681 | e1000e_reset_interrupt_capability(adapter); |
Jesse Brandeburg | c43bc57e | 2008-08-04 17:21:40 -0700 | [diff] [blame] | 7682 | err_flashmap: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7683 | iounmap(adapter->hw.hw_addr); |
| 7684 | err_ioremap: |
| 7685 | free_netdev(netdev); |
| 7686 | err_alloc_etherdev: |
Christophe JAILLET | 4589075 | 2021-06-16 07:05:53 +0200 | [diff] [blame] | 7687 | pci_disable_pcie_error_reporting(pdev); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 7688 | pci_release_mem_regions(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7689 | err_pci_reg: |
| 7690 | err_dma: |
| 7691 | pci_disable_device(pdev); |
| 7692 | return err; |
| 7693 | } |
| 7694 | |
| 7695 | /** |
| 7696 | * e1000_remove - Device Removal Routine |
| 7697 | * @pdev: PCI device information struct |
| 7698 | * |
| 7699 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 7700 | * that it should release a PCI device. The could be caused by a |
| 7701 | * Hot-Plug event, or because the driver is going to be removed from |
| 7702 | * memory. |
| 7703 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 7704 | static void e1000_remove(struct pci_dev *pdev) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7705 | { |
| 7706 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7707 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7708 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 7709 | e1000e_ptp_remove(adapter); |
| 7710 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7711 | /* The timers may be rescheduled, so explicitly disable them |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 7712 | * from being rescheduled. |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7713 | */ |
Alexander Duyck | daee559 | 2019-10-11 08:34:59 -0700 | [diff] [blame] | 7714 | set_bit(__E1000_DOWN, &adapter->state); |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 7715 | del_timer_sync(&adapter->watchdog_timer); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7716 | del_timer_sync(&adapter->phy_info_timer); |
| 7717 | |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 7718 | cancel_work_sync(&adapter->reset_task); |
Jeff Kirsher | d5ad7a6 | 2020-01-04 23:29:22 -0800 | [diff] [blame] | 7719 | cancel_work_sync(&adapter->watchdog_task); |
Bruce Allan | 41cec6f | 2009-11-20 23:28:56 +0000 | [diff] [blame] | 7720 | cancel_work_sync(&adapter->downshift_task); |
| 7721 | cancel_work_sync(&adapter->update_phy_task); |
| 7722 | cancel_work_sync(&adapter->print_hang_task); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7723 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 7724 | if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) { |
| 7725 | cancel_work_sync(&adapter->tx_hwtstamp_work); |
| 7726 | if (adapter->tx_hwtstamp_skb) { |
Florian Fainelli | 377b627 | 2017-08-25 18:14:24 -0700 | [diff] [blame] | 7727 | dev_consume_skb_any(adapter->tx_hwtstamp_skb); |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 7728 | adapter->tx_hwtstamp_skb = NULL; |
| 7729 | } |
| 7730 | } |
| 7731 | |
Bruce Allan | 17f208d | 2009-12-01 15:47:22 +0000 | [diff] [blame] | 7732 | unregister_netdev(netdev); |
| 7733 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 7734 | if (pci_dev_run_wake(pdev)) |
| 7735 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7736 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 7737 | /* 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] | 7738 | * would have already happened in close and is redundant. |
| 7739 | */ |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 7740 | e1000e_release_hw_control(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7741 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 7742 | e1000e_reset_interrupt_capability(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7743 | kfree(adapter->tx_ring); |
| 7744 | kfree(adapter->rx_ring); |
| 7745 | |
| 7746 | iounmap(adapter->hw.hw_addr); |
Yanir Lubetkin | 1103a63 | 2015-02-28 10:10:06 +0000 | [diff] [blame] | 7747 | if ((adapter->hw.flash_address) && |
| 7748 | (adapter->hw.mac.type < e1000_pch_spt)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7749 | iounmap(adapter->hw.flash_address); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 7750 | pci_release_mem_regions(pdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7751 | |
| 7752 | free_netdev(netdev); |
| 7753 | |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7754 | /* AER disable */ |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7755 | pci_disable_pcie_error_reporting(pdev); |
Jesse Brandeburg | 111b9dc | 2009-02-10 12:51:20 +0000 | [diff] [blame] | 7756 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7757 | pci_disable_device(pdev); |
| 7758 | } |
| 7759 | |
| 7760 | /* PCI Error Recovery (ERS) */ |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 7761 | static const struct pci_error_handlers e1000_err_handler = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7762 | .error_detected = e1000_io_error_detected, |
| 7763 | .slot_reset = e1000_io_slot_reset, |
| 7764 | .resume = e1000_io_resume, |
| 7765 | }; |
| 7766 | |
David Ertman | 0e8e842 | 2014-04-08 22:10:31 +0000 | [diff] [blame] | 7767 | static const struct pci_device_id e1000_pci_tbl[] = { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7768 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, |
| 7769 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, |
| 7770 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, |
Bruce Allan | c29c3ba | 2013-02-20 04:05:50 +0000 | [diff] [blame] | 7771 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), |
| 7772 | board_82571 }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7773 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, |
| 7774 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, |
Auke Kok | 040babf | 2007-10-31 15:22:05 -0700 | [diff] [blame] | 7775 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, |
| 7776 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, |
| 7777 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7778 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7779 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, |
| 7780 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, |
| 7781 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, |
| 7782 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7783 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7784 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, |
| 7785 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, |
| 7786 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7787 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 7788 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, |
Bruce Allan | bef28b1 | 2009-03-24 23:28:02 -0700 | [diff] [blame] | 7789 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, |
Alexander Duyck | 8c81c9c | 2009-03-19 01:12:27 +0000 | [diff] [blame] | 7790 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 7791 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7792 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), |
| 7793 | board_80003es2lan }, |
| 7794 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), |
| 7795 | board_80003es2lan }, |
| 7796 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), |
| 7797 | board_80003es2lan }, |
| 7798 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), |
| 7799 | board_80003es2lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7800 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7801 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, |
| 7802 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, |
| 7803 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, |
| 7804 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, |
| 7805 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, |
| 7806 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, |
| 7807 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, |
Bruce Allan | 9e135a2 | 2009-12-01 15:50:31 +0000 | [diff] [blame] | 7808 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan }, |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 7809 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7810 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, |
| 7811 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, |
| 7812 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, |
| 7813 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, |
| 7814 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, |
Bruce Allan | 2f15f9d | 2008-08-26 18:36:36 -0700 | [diff] [blame] | 7815 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 7816 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, |
| 7817 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, |
| 7818 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, |
| 7819 | |
| 7820 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, |
| 7821 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, |
| 7822 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7823 | |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 7824 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, |
| 7825 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, |
Bruce Allan | 10df0b9 | 2010-05-10 15:02:52 +0000 | [diff] [blame] | 7826 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan }, |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 7827 | |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 7828 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, |
| 7829 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, |
| 7830 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, |
| 7831 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, |
| 7832 | |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 7833 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan }, |
| 7834 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan }, |
| 7835 | |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 7836 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt }, |
| 7837 | { 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] | 7838 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt }, |
| 7839 | { 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] | 7840 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt }, |
| 7841 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt }, |
| 7842 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt }, |
| 7843 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt }, |
David Ertman | 79849eb | 2015-02-10 09:10:43 +0000 | [diff] [blame] | 7844 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM), board_pch_spt }, |
| 7845 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V), board_pch_spt }, |
| 7846 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM2), board_pch_spt }, |
| 7847 | { 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] | 7848 | { 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] | 7849 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM4), board_pch_spt }, |
| 7850 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V4), board_pch_spt }, |
| 7851 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM5), board_pch_spt }, |
| 7852 | { 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] | 7853 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM6), board_pch_cnp }, |
| 7854 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V6), board_pch_cnp }, |
| 7855 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM7), board_pch_cnp }, |
| 7856 | { 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] | 7857 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM8), board_pch_cnp }, |
| 7858 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V8), board_pch_cnp }, |
| 7859 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM9), board_pch_cnp }, |
| 7860 | { 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] | 7861 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM10), board_pch_cnp }, |
| 7862 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V10), board_pch_cnp }, |
| 7863 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM11), board_pch_cnp }, |
| 7864 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_V11), board_pch_cnp }, |
| 7865 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CMP_I219_LM12), board_pch_spt }, |
| 7866 | { 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] | 7867 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM13), board_pch_cnp }, |
| 7868 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V13), board_pch_cnp }, |
| 7869 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_LM14), board_pch_cnp }, |
| 7870 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_TGP_I219_V14), board_pch_cnp }, |
| 7871 | { 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] | 7872 | { 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] | 7873 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM16), board_pch_cnp }, |
| 7874 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V16), board_pch_cnp }, |
| 7875 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_LM17), board_pch_cnp }, |
| 7876 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ADP_I219_V17), board_pch_cnp }, |
Sasha Neftin | cc23f4f | 2020-08-13 11:34:06 +0300 | [diff] [blame] | 7877 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_LM18), board_pch_cnp }, |
| 7878 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_V18), board_pch_cnp }, |
| 7879 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_LM19), board_pch_cnp }, |
| 7880 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_MTP_I219_V19), board_pch_cnp }, |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 7881 | |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 7882 | { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7883 | }; |
| 7884 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 7885 | |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7886 | static const struct dev_pm_ops e1000_pm_ops = { |
Kevin Hao | 72f72dc | 2014-03-18 00:26:49 -0700 | [diff] [blame] | 7887 | #ifdef CONFIG_PM_SLEEP |
Chen Yu | ccf8b94 | 2020-12-01 09:21:50 +0800 | [diff] [blame] | 7888 | .prepare = e1000e_pm_prepare, |
David Ertman | 2800209 | 2014-02-14 07:16:41 +0000 | [diff] [blame] | 7889 | .suspend = e1000e_pm_suspend, |
| 7890 | .resume = e1000e_pm_resume, |
| 7891 | .freeze = e1000e_pm_freeze, |
| 7892 | .thaw = e1000e_pm_thaw, |
| 7893 | .poweroff = e1000e_pm_suspend, |
| 7894 | .restore = e1000e_pm_resume, |
Kevin Hao | 72f72dc | 2014-03-18 00:26:49 -0700 | [diff] [blame] | 7895 | #endif |
David Ertman | 63eb48f | 2014-02-14 07:16:46 +0000 | [diff] [blame] | 7896 | SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume, |
| 7897 | e1000e_pm_runtime_idle) |
Rafael J. Wysocki | 23606cf | 2010-03-14 14:35:17 +0000 | [diff] [blame] | 7898 | }; |
| 7899 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7900 | /* PCI Device API Driver */ |
| 7901 | static struct pci_driver e1000_driver = { |
| 7902 | .name = e1000e_driver_name, |
| 7903 | .id_table = e1000_pci_tbl, |
| 7904 | .probe = e1000_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 7905 | .remove = e1000_remove, |
Bruce Allan | f36bb6c | 2012-01-31 06:38:04 +0000 | [diff] [blame] | 7906 | .driver = { |
| 7907 | .pm = &e1000_pm_ops, |
| 7908 | }, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7909 | .shutdown = e1000_shutdown, |
| 7910 | .err_handler = &e1000_err_handler |
| 7911 | }; |
| 7912 | |
| 7913 | /** |
| 7914 | * e1000_init_module - Driver Registration Routine |
| 7915 | * |
| 7916 | * e1000_init_module is the first routine called when the driver is |
| 7917 | * loaded. All it does is register with the PCI subsystem. |
| 7918 | **/ |
| 7919 | static int __init e1000_init_module(void) |
| 7920 | { |
Jeff Kirsher | 34a2a3b8 | 2020-05-29 00:18:33 -0700 | [diff] [blame] | 7921 | pr_info("Intel(R) PRO/1000 Network Driver\n"); |
Yanir Lubetkin | 529498c | 2015-06-02 17:05:50 +0300 | [diff] [blame] | 7922 | pr_info("Copyright(c) 1999 - 2015 Intel Corporation.\n"); |
Bruce Allan | 53ec549 | 2009-11-20 23:27:40 +0000 | [diff] [blame] | 7923 | |
Jean Sacren | 5a5e889 | 2015-09-19 05:08:42 -0600 | [diff] [blame] | 7924 | return pci_register_driver(&e1000_driver); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7925 | } |
| 7926 | module_init(e1000_init_module); |
| 7927 | |
| 7928 | /** |
| 7929 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 7930 | * |
| 7931 | * e1000_exit_module is called just before the driver is removed |
| 7932 | * from memory. |
| 7933 | **/ |
| 7934 | static void __exit e1000_exit_module(void) |
| 7935 | { |
| 7936 | pci_unregister_driver(&e1000_driver); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7937 | } |
| 7938 | module_exit(e1000_exit_module); |
| 7939 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7940 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 7941 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
Jesse Brandeburg | 98674eb | 2018-09-14 17:37:57 -0700 | [diff] [blame] | 7942 | MODULE_LICENSE("GPL v2"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 7943 | |
Bruce Allan | 06c24b9 | 2012-02-23 03:13:13 +0000 | [diff] [blame] | 7944 | /* netdev.c */ |