fp@2407: /******************************************************************************* fp@2407: fp@2407: Intel PRO/1000 Linux driver fp@2407: Copyright(c) 1999 - 2011 Intel Corporation. fp@2407: fp@2407: This program is free software; you can redistribute it and/or modify it fp@2407: under the terms and conditions of the GNU General Public License, fp@2407: version 2, as published by the Free Software Foundation. fp@2407: fp@2407: This program is distributed in the hope it will be useful, but WITHOUT fp@2407: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or fp@2407: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for fp@2407: more details. fp@2407: fp@2407: You should have received a copy of the GNU General Public License along with fp@2407: this program; if not, write to the Free Software Foundation, Inc., fp@2407: 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. fp@2407: fp@2407: The full GNU General Public License is included in this distribution in fp@2407: the file called "COPYING". fp@2407: fp@2407: Contact Information: fp@2407: Linux NICS fp@2407: e1000-devel Mailing List fp@2407: Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 fp@2407: fp@2473: vim: noexpandtab fp@2473: fp@2407: *******************************************************************************/ fp@2407: fp@2407: #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt fp@2407: fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: #include fp@2407: fp@2407: #include "e1000-3.2-ethercat.h" fp@2407: fp@2407: #define DRV_EXTRAVERSION "-k-EtherCAT" fp@2407: fp@2407: #define DRV_VERSION "1.5.1" DRV_EXTRAVERSION fp@2407: char e1000e_driver_name[] = "ec_e1000e"; fp@2407: const char e1000e_driver_version[] = DRV_VERSION; fp@2407: fp@2407: static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state); fp@2407: fp@2407: static const struct e1000_info *e1000_info_tbl[] = { fp@2407: [board_82571] = &e1000_82571_info, fp@2407: [board_82572] = &e1000_82572_info, fp@2407: [board_82573] = &e1000_82573_info, fp@2407: [board_82574] = &e1000_82574_info, fp@2407: [board_82583] = &e1000_82583_info, fp@2407: [board_80003es2lan] = &e1000_es2_info, fp@2407: [board_ich8lan] = &e1000_ich8_info, fp@2407: [board_ich9lan] = &e1000_ich9_info, fp@2407: [board_ich10lan] = &e1000_ich10_info, fp@2407: [board_pchlan] = &e1000_pch_info, fp@2407: [board_pch2lan] = &e1000_pch2_info, fp@2407: }; fp@2407: fp@2407: struct e1000_reg_info { fp@2407: u32 ofs; fp@2407: char *name; fp@2407: }; fp@2407: fp@2407: #define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */ fp@2407: #define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */ fp@2407: #define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */ fp@2407: #define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */ fp@2407: #define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */ fp@2407: fp@2407: #define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */ fp@2407: #define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */ fp@2407: #define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */ fp@2407: #define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */ fp@2407: #define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */ fp@2407: fp@2407: static const struct e1000_reg_info e1000_reg_info_tbl[] = { fp@2407: fp@2407: /* General Registers */ fp@2407: {E1000_CTRL, "CTRL"}, fp@2407: {E1000_STATUS, "STATUS"}, fp@2407: {E1000_CTRL_EXT, "CTRL_EXT"}, fp@2407: fp@2407: /* Interrupt Registers */ fp@2407: {E1000_ICR, "ICR"}, fp@2407: fp@2407: /* Rx Registers */ fp@2407: {E1000_RCTL, "RCTL"}, fp@2407: {E1000_RDLEN, "RDLEN"}, fp@2407: {E1000_RDH, "RDH"}, fp@2407: {E1000_RDT, "RDT"}, fp@2407: {E1000_RDTR, "RDTR"}, fp@2407: {E1000_RXDCTL(0), "RXDCTL"}, fp@2407: {E1000_ERT, "ERT"}, fp@2407: {E1000_RDBAL, "RDBAL"}, fp@2407: {E1000_RDBAH, "RDBAH"}, fp@2407: {E1000_RDFH, "RDFH"}, fp@2407: {E1000_RDFT, "RDFT"}, fp@2407: {E1000_RDFHS, "RDFHS"}, fp@2407: {E1000_RDFTS, "RDFTS"}, fp@2407: {E1000_RDFPC, "RDFPC"}, fp@2407: fp@2407: /* Tx Registers */ fp@2407: {E1000_TCTL, "TCTL"}, fp@2407: {E1000_TDBAL, "TDBAL"}, fp@2407: {E1000_TDBAH, "TDBAH"}, fp@2407: {E1000_TDLEN, "TDLEN"}, fp@2407: {E1000_TDH, "TDH"}, fp@2407: {E1000_TDT, "TDT"}, fp@2407: {E1000_TIDV, "TIDV"}, fp@2407: {E1000_TXDCTL(0), "TXDCTL"}, fp@2407: {E1000_TADV, "TADV"}, fp@2407: {E1000_TARC(0), "TARC"}, fp@2407: {E1000_TDFH, "TDFH"}, fp@2407: {E1000_TDFT, "TDFT"}, fp@2407: {E1000_TDFHS, "TDFHS"}, fp@2407: {E1000_TDFTS, "TDFTS"}, fp@2407: {E1000_TDFPC, "TDFPC"}, fp@2407: fp@2407: /* List Terminator */ fp@2407: {} fp@2407: }; fp@2407: fp@2407: /* fp@2407: * e1000_regdump - register printout routine fp@2407: */ fp@2407: static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo) fp@2407: { fp@2407: int n = 0; fp@2407: char rname[16]; fp@2407: u32 regs[8]; fp@2407: fp@2407: switch (reginfo->ofs) { fp@2407: case E1000_RXDCTL(0): fp@2407: for (n = 0; n < 2; n++) fp@2407: regs[n] = __er32(hw, E1000_RXDCTL(n)); fp@2407: break; fp@2407: case E1000_TXDCTL(0): fp@2407: for (n = 0; n < 2; n++) fp@2407: regs[n] = __er32(hw, E1000_TXDCTL(n)); fp@2407: break; fp@2407: case E1000_TARC(0): fp@2407: for (n = 0; n < 2; n++) fp@2407: regs[n] = __er32(hw, E1000_TARC(n)); fp@2407: break; fp@2407: default: fp@2407: printk(KERN_INFO "%-15s %08x\n", fp@2407: reginfo->name, __er32(hw, reginfo->ofs)); fp@2407: return; fp@2407: } fp@2407: fp@2407: snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]"); fp@2407: printk(KERN_INFO "%-15s ", rname); fp@2407: for (n = 0; n < 2; n++) fp@2407: printk(KERN_CONT "%08x ", regs[n]); fp@2407: printk(KERN_CONT "\n"); fp@2407: } fp@2407: fp@2407: /* fp@2407: * e1000e_dump - Print registers, Tx-ring and Rx-ring fp@2407: */ fp@2407: static void e1000e_dump(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct e1000_reg_info *reginfo; fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: struct e1000_tx_desc *tx_desc; fp@2407: struct my_u0 { fp@2407: u64 a; fp@2407: u64 b; fp@2407: } *u0; fp@2407: struct e1000_buffer *buffer_info; fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: union e1000_rx_desc_packet_split *rx_desc_ps; fp@2407: union e1000_rx_desc_extended *rx_desc; fp@2407: struct my_u1 { fp@2407: u64 a; fp@2407: u64 b; fp@2407: u64 c; fp@2407: u64 d; fp@2407: } *u1; fp@2407: u32 staterr; fp@2407: int i = 0; fp@2407: fp@2407: if (!netif_msg_hw(adapter)) fp@2407: return; fp@2407: fp@2407: /* Print netdevice Info */ fp@2407: if (netdev) { fp@2407: dev_info(&adapter->pdev->dev, "Net device Info\n"); fp@2407: printk(KERN_INFO "Device Name state " fp@2407: "trans_start last_rx\n"); fp@2407: printk(KERN_INFO "%-15s %016lX %016lX %016lX\n", fp@2407: netdev->name, netdev->state, netdev->trans_start, fp@2407: netdev->last_rx); fp@2407: } fp@2407: fp@2407: /* Print Registers */ fp@2407: dev_info(&adapter->pdev->dev, "Register Dump\n"); fp@2407: printk(KERN_INFO " Register Name Value\n"); fp@2407: for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl; fp@2407: reginfo->name; reginfo++) { fp@2407: e1000_regdump(hw, reginfo); fp@2407: } fp@2407: fp@2407: /* Print Tx Ring Summary */ fp@2407: if (!netdev || !netif_running(netdev)) fp@2407: goto exit; fp@2407: fp@2407: dev_info(&adapter->pdev->dev, "Tx Ring Summary\n"); fp@2407: printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]" fp@2407: " leng ntw timestamp\n"); fp@2407: buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean]; fp@2407: printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n", fp@2407: 0, tx_ring->next_to_use, tx_ring->next_to_clean, fp@2407: (unsigned long long)buffer_info->dma, fp@2407: buffer_info->length, fp@2407: buffer_info->next_to_watch, fp@2407: (unsigned long long)buffer_info->time_stamp); fp@2407: fp@2407: /* Print Tx Ring */ fp@2407: if (!netif_msg_tx_done(adapter)) fp@2407: goto rx_ring_summary; fp@2407: fp@2407: dev_info(&adapter->pdev->dev, "Tx Ring Dump\n"); fp@2407: fp@2407: /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended) fp@2407: * fp@2407: * Legacy Transmit Descriptor fp@2407: * +--------------------------------------------------------------+ fp@2407: * 0 | Buffer Address [63:0] (Reserved on Write Back) | fp@2407: * +--------------------------------------------------------------+ fp@2407: * 8 | Special | CSS | Status | CMD | CSO | Length | fp@2407: * +--------------------------------------------------------------+ fp@2407: * 63 48 47 36 35 32 31 24 23 16 15 0 fp@2407: * fp@2407: * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload fp@2407: * 63 48 47 40 39 32 31 16 15 8 7 0 fp@2407: * +----------------------------------------------------------------+ fp@2407: * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS | fp@2407: * +----------------------------------------------------------------+ fp@2407: * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN | fp@2407: * +----------------------------------------------------------------+ fp@2407: * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 fp@2407: * fp@2407: * Extended Data Descriptor (DTYP=0x1) fp@2407: * +----------------------------------------------------------------+ fp@2407: * 0 | Buffer Address [63:0] | fp@2407: * +----------------------------------------------------------------+ fp@2407: * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN | fp@2407: * +----------------------------------------------------------------+ fp@2407: * 63 48 47 40 39 36 35 32 31 24 23 20 19 0 fp@2407: */ fp@2407: printk(KERN_INFO "Tl[desc] [address 63:0 ] [SpeCssSCmCsLen]" fp@2407: " [bi->dma ] leng ntw timestamp bi->skb " fp@2407: "<-- Legacy format\n"); fp@2407: printk(KERN_INFO "Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen]" fp@2407: " [bi->dma ] leng ntw timestamp bi->skb " fp@2407: "<-- Ext Context format\n"); fp@2407: printk(KERN_INFO "Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen]" fp@2407: " [bi->dma ] leng ntw timestamp bi->skb " fp@2407: "<-- Ext Data format\n"); fp@2407: for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { fp@2407: tx_desc = E1000_TX_DESC(*tx_ring, i); fp@2407: buffer_info = &tx_ring->buffer_info[i]; fp@2407: u0 = (struct my_u0 *)tx_desc; fp@2407: printk(KERN_INFO "T%c[0x%03X] %016llX %016llX %016llX " fp@2407: "%04X %3X %016llX %p", fp@2407: (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' : fp@2407: ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')), i, fp@2407: (unsigned long long)le64_to_cpu(u0->a), fp@2407: (unsigned long long)le64_to_cpu(u0->b), fp@2407: (unsigned long long)buffer_info->dma, fp@2407: buffer_info->length, buffer_info->next_to_watch, fp@2407: (unsigned long long)buffer_info->time_stamp, fp@2407: buffer_info->skb); fp@2407: if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean) fp@2407: printk(KERN_CONT " NTC/U\n"); fp@2407: else if (i == tx_ring->next_to_use) fp@2407: printk(KERN_CONT " NTU\n"); fp@2407: else if (i == tx_ring->next_to_clean) fp@2407: printk(KERN_CONT " NTC\n"); fp@2407: else fp@2407: printk(KERN_CONT "\n"); fp@2407: fp@2407: if (netif_msg_pktdata(adapter) && buffer_info->dma != 0) fp@2407: print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, fp@2407: 16, 1, phys_to_virt(buffer_info->dma), fp@2407: buffer_info->length, true); fp@2407: } fp@2407: fp@2407: /* Print Rx Ring Summary */ fp@2407: rx_ring_summary: fp@2407: dev_info(&adapter->pdev->dev, "Rx Ring Summary\n"); fp@2407: printk(KERN_INFO "Queue [NTU] [NTC]\n"); fp@2407: printk(KERN_INFO " %5d %5X %5X\n", 0, fp@2407: rx_ring->next_to_use, rx_ring->next_to_clean); fp@2407: fp@2407: /* Print Rx Ring */ fp@2407: if (!netif_msg_rx_status(adapter)) fp@2407: goto exit; fp@2407: fp@2407: dev_info(&adapter->pdev->dev, "Rx Ring Dump\n"); fp@2407: switch (adapter->rx_ps_pages) { fp@2407: case 1: fp@2407: case 2: fp@2407: case 3: fp@2407: /* [Extended] Packet Split Receive Descriptor Format fp@2407: * fp@2407: * +-----------------------------------------------------+ fp@2407: * 0 | Buffer Address 0 [63:0] | fp@2407: * +-----------------------------------------------------+ fp@2407: * 8 | Buffer Address 1 [63:0] | fp@2407: * +-----------------------------------------------------+ fp@2407: * 16 | Buffer Address 2 [63:0] | fp@2407: * +-----------------------------------------------------+ fp@2407: * 24 | Buffer Address 3 [63:0] | fp@2407: * +-----------------------------------------------------+ fp@2407: */ fp@2407: printk(KERN_INFO "R [desc] [buffer 0 63:0 ] " fp@2407: "[buffer 1 63:0 ] " fp@2407: "[buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] " fp@2407: "[bi->skb] <-- Ext Pkt Split format\n"); fp@2407: /* [Extended] Receive Descriptor (Write-Back) Format fp@2407: * fp@2407: * 63 48 47 32 31 13 12 8 7 4 3 0 fp@2407: * +------------------------------------------------------+ fp@2407: * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS | fp@2407: * | Checksum | Ident | | Queue | | Type | fp@2407: * +------------------------------------------------------+ fp@2407: * 8 | VLAN Tag | Length | Extended Error | Extended Status | fp@2407: * +------------------------------------------------------+ fp@2407: * 63 48 47 32 31 20 19 0 fp@2407: */ fp@2407: printk(KERN_INFO "RWB[desc] [ck ipid mrqhsh] " fp@2407: "[vl l0 ee es] " fp@2407: "[ l3 l2 l1 hs] [reserved ] ---------------- " fp@2407: "[bi->skb] <-- Ext Rx Write-Back format\n"); fp@2407: for (i = 0; i < rx_ring->count; i++) { fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i); fp@2407: u1 = (struct my_u1 *)rx_desc_ps; fp@2407: staterr = fp@2407: le32_to_cpu(rx_desc_ps->wb.middle.status_error); fp@2407: if (staterr & E1000_RXD_STAT_DD) { fp@2407: /* Descriptor Done */ fp@2407: printk(KERN_INFO "RWB[0x%03X] %016llX " fp@2407: "%016llX %016llX %016llX " fp@2407: "---------------- %p", i, fp@2407: (unsigned long long)le64_to_cpu(u1->a), fp@2407: (unsigned long long)le64_to_cpu(u1->b), fp@2407: (unsigned long long)le64_to_cpu(u1->c), fp@2407: (unsigned long long)le64_to_cpu(u1->d), fp@2407: buffer_info->skb); fp@2407: } else { fp@2407: printk(KERN_INFO "R [0x%03X] %016llX " fp@2407: "%016llX %016llX %016llX %016llX %p", i, fp@2407: (unsigned long long)le64_to_cpu(u1->a), fp@2407: (unsigned long long)le64_to_cpu(u1->b), fp@2407: (unsigned long long)le64_to_cpu(u1->c), fp@2407: (unsigned long long)le64_to_cpu(u1->d), fp@2407: (unsigned long long)buffer_info->dma, fp@2407: buffer_info->skb); fp@2407: fp@2407: if (netif_msg_pktdata(adapter)) fp@2407: print_hex_dump(KERN_INFO, "", fp@2407: DUMP_PREFIX_ADDRESS, 16, 1, fp@2407: phys_to_virt(buffer_info->dma), fp@2407: adapter->rx_ps_bsize0, true); fp@2407: } fp@2407: fp@2407: if (i == rx_ring->next_to_use) fp@2407: printk(KERN_CONT " NTU\n"); fp@2407: else if (i == rx_ring->next_to_clean) fp@2407: printk(KERN_CONT " NTC\n"); fp@2407: else fp@2407: printk(KERN_CONT "\n"); fp@2407: } fp@2407: break; fp@2407: default: fp@2407: case 0: fp@2407: /* Extended Receive Descriptor (Read) Format fp@2407: * fp@2407: * +-----------------------------------------------------+ fp@2407: * 0 | Buffer Address [63:0] | fp@2407: * +-----------------------------------------------------+ fp@2407: * 8 | Reserved | fp@2407: * +-----------------------------------------------------+ fp@2407: */ fp@2407: printk(KERN_INFO "R [desc] [buf addr 63:0 ] " fp@2407: "[reserved 63:0 ] [bi->dma ] " fp@2407: "[bi->skb] <-- Ext (Read) format\n"); fp@2407: /* Extended Receive Descriptor (Write-Back) Format fp@2407: * fp@2407: * 63 48 47 32 31 24 23 4 3 0 fp@2407: * +------------------------------------------------------+ fp@2407: * | RSS Hash | | | | fp@2407: * 0 +-------------------+ Rsvd | Reserved | MRQ RSS | fp@2407: * | Packet | IP | | | Type | fp@2407: * | Checksum | Ident | | | | fp@2407: * +------------------------------------------------------+ fp@2407: * 8 | VLAN Tag | Length | Extended Error | Extended Status | fp@2407: * +------------------------------------------------------+ fp@2407: * 63 48 47 32 31 20 19 0 fp@2407: */ fp@2407: printk(KERN_INFO "RWB[desc] [cs ipid mrq] " fp@2407: "[vt ln xe xs] " fp@2407: "[bi->skb] <-- Ext (Write-Back) format\n"); fp@2407: fp@2407: for (i = 0; i < rx_ring->count; i++) { fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); fp@2407: u1 = (struct my_u1 *)rx_desc; fp@2407: staterr = le32_to_cpu(rx_desc->wb.upper.status_error); fp@2407: if (staterr & E1000_RXD_STAT_DD) { fp@2407: /* Descriptor Done */ fp@2407: printk(KERN_INFO "RWB[0x%03X] %016llX " fp@2407: "%016llX ---------------- %p", i, fp@2407: (unsigned long long)le64_to_cpu(u1->a), fp@2407: (unsigned long long)le64_to_cpu(u1->b), fp@2407: buffer_info->skb); fp@2407: } else { fp@2407: printk(KERN_INFO "R [0x%03X] %016llX " fp@2407: "%016llX %016llX %p", i, fp@2407: (unsigned long long)le64_to_cpu(u1->a), fp@2407: (unsigned long long)le64_to_cpu(u1->b), fp@2407: (unsigned long long)buffer_info->dma, fp@2407: buffer_info->skb); fp@2407: fp@2407: if (netif_msg_pktdata(adapter)) fp@2407: print_hex_dump(KERN_INFO, "", fp@2407: DUMP_PREFIX_ADDRESS, 16, fp@2407: 1, fp@2407: phys_to_virt fp@2407: (buffer_info->dma), fp@2407: adapter->rx_buffer_len, fp@2407: true); fp@2407: } fp@2407: fp@2407: if (i == rx_ring->next_to_use) fp@2407: printk(KERN_CONT " NTU\n"); fp@2407: else if (i == rx_ring->next_to_clean) fp@2407: printk(KERN_CONT " NTC\n"); fp@2407: else fp@2407: printk(KERN_CONT "\n"); fp@2407: } fp@2407: } fp@2407: fp@2407: exit: fp@2407: return; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_desc_unused - calculate if we have unused descriptors fp@2407: **/ fp@2407: static int e1000_desc_unused(struct e1000_ring *ring) fp@2407: { fp@2407: if (ring->next_to_clean > ring->next_to_use) fp@2407: return ring->next_to_clean - ring->next_to_use - 1; fp@2407: fp@2407: return ring->count + ring->next_to_clean - ring->next_to_use - 1; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_receive_skb - helper function to handle Rx indications fp@2407: * @adapter: board private structure fp@2407: * @status: descriptor status field as written by hardware fp@2407: * @vlan: descriptor vlan field as written by hardware (no le/be conversion) fp@2407: * @skb: pointer to sk_buff to be indicated to stack fp@2407: **/ fp@2407: static void e1000_receive_skb(struct e1000_adapter *adapter, fp@2407: struct net_device *netdev, struct sk_buff *skb, fp@2407: u8 status, __le16 vlan) fp@2407: { fp@2407: u16 tag = le16_to_cpu(vlan); fp@2407: skb->protocol = eth_type_trans(skb, netdev); fp@2407: fp@2407: if (status & E1000_RXD_STAT_VP) fp@2407: __vlan_hwaccel_put_tag(skb, tag); fp@2407: fp@2407: napi_gro_receive(&adapter->napi, skb); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_rx_checksum - Receive Checksum Offload fp@2407: * @adapter: board private structure fp@2407: * @status_err: receive descriptor status and error fields fp@2407: * @csum: receive descriptor csum field fp@2407: * @sk_buff: socket buffer with received data fp@2407: **/ fp@2407: static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, fp@2407: u32 csum, struct sk_buff *skb) fp@2407: { fp@2407: u16 status = (u16)status_err; fp@2407: u8 errors = (u8)(status_err >> 24); fp@2407: fp@2407: skb_checksum_none_assert(skb); fp@2407: fp@2407: /* Ignore Checksum bit is set */ fp@2407: if (status & E1000_RXD_STAT_IXSM) fp@2407: return; fp@2407: /* TCP/UDP checksum error bit is set */ fp@2407: if (errors & E1000_RXD_ERR_TCPE) { fp@2407: /* let the stack verify checksum errors */ fp@2407: adapter->hw_csum_err++; fp@2407: return; fp@2407: } fp@2407: fp@2407: /* TCP/UDP Checksum has not been calculated */ fp@2407: if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) fp@2407: return; fp@2407: fp@2407: /* It must be a TCP or UDP packet with a valid checksum */ fp@2407: if (status & E1000_RXD_STAT_TCPCS) { fp@2407: /* TCP checksum is good */ fp@2407: skb->ip_summed = CHECKSUM_UNNECESSARY; fp@2407: } else { fp@2407: /* fp@2407: * IP fragment with UDP payload fp@2407: * Hardware complements the payload checksum, so we undo it fp@2407: * and then put the value in host order for further stack use. fp@2407: */ fp@2407: __sum16 sum = (__force __sum16)htons(csum); fp@2407: skb->csum = csum_unfold(~sum); fp@2407: skb->ip_summed = CHECKSUM_COMPLETE; fp@2407: } fp@2407: adapter->hw_csum_good++; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_update_tail_wa - helper function for e1000e_update_[rt]dt_wa() fp@2407: * @hw: pointer to the HW structure fp@2407: * @tail: address of tail descriptor register fp@2407: * @i: value to write to tail descriptor register fp@2407: * fp@2407: * When updating the tail register, the ME could be accessing Host CSR fp@2407: * registers at the same time. Normally, this is handled in h/w by an fp@2407: * arbiter but on some parts there is a bug that acknowledges Host accesses fp@2407: * later than it should which could result in the descriptor register to fp@2407: * have an incorrect value. Workaround this by checking the FWSM register fp@2407: * which has bit 24 set while ME is accessing Host CSR registers, wait fp@2407: * if it is set and try again a number of times. fp@2407: **/ fp@2407: static inline s32 e1000e_update_tail_wa(struct e1000_hw *hw, u8 __iomem * tail, fp@2407: unsigned int i) fp@2407: { fp@2407: unsigned int j = 0; fp@2407: fp@2407: while ((j++ < E1000_ICH_FWSM_PCIM2PCI_COUNT) && fp@2407: (er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI)) fp@2407: udelay(50); fp@2407: fp@2407: writel(i, tail); fp@2407: fp@2407: if ((j == E1000_ICH_FWSM_PCIM2PCI_COUNT) && (i != readl(tail))) fp@2407: return E1000_ERR_SWFW_SYNC; fp@2407: fp@2407: return 0; fp@2407: } fp@2407: fp@2407: static void e1000e_update_rdt_wa(struct e1000_adapter *adapter, unsigned int i) fp@2407: { fp@2407: u8 __iomem *tail = (adapter->hw.hw_addr + adapter->rx_ring->tail); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: fp@2407: if (e1000e_update_tail_wa(hw, tail, i)) { fp@2407: u32 rctl = er32(RCTL); fp@2407: ew32(RCTL, rctl & ~E1000_RCTL_EN); fp@2407: e_err("ME firmware caused invalid RDT - resetting\n"); fp@2407: schedule_work(&adapter->reset_task); fp@2407: } fp@2407: } fp@2407: fp@2407: static void e1000e_update_tdt_wa(struct e1000_adapter *adapter, unsigned int i) fp@2407: { fp@2407: u8 __iomem *tail = (adapter->hw.hw_addr + adapter->tx_ring->tail); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: fp@2407: if (e1000e_update_tail_wa(hw, tail, i)) { fp@2407: u32 tctl = er32(TCTL); fp@2407: ew32(TCTL, tctl & ~E1000_TCTL_EN); fp@2407: e_err("ME firmware caused invalid TDT - resetting\n"); fp@2407: schedule_work(&adapter->reset_task); fp@2407: } fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_alloc_rx_buffers - Replace used receive buffers fp@2407: * @adapter: address of board private structure fp@2407: **/ fp@2407: static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, fp@2407: int cleaned_count, gfp_t gfp) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: union e1000_rx_desc_extended *rx_desc; fp@2407: struct e1000_buffer *buffer_info; fp@2407: struct sk_buff *skb; fp@2407: unsigned int i; fp@2407: unsigned int bufsz = adapter->rx_buffer_len; fp@2407: fp@2407: i = rx_ring->next_to_use; fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: fp@2407: while (cleaned_count--) { fp@2407: skb = buffer_info->skb; fp@2407: if (skb) { fp@2407: skb_trim(skb, 0); fp@2407: goto map_skb; fp@2407: } fp@2407: fp@2407: skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); fp@2407: if (!skb) { fp@2407: /* Better luck next round */ fp@2407: adapter->alloc_rx_buff_failed++; fp@2407: break; fp@2407: } fp@2407: fp@2407: buffer_info->skb = skb; fp@2407: map_skb: fp@2407: buffer_info->dma = dma_map_single(&pdev->dev, skb->data, fp@2407: adapter->rx_buffer_len, fp@2407: DMA_FROM_DEVICE); fp@2407: if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { fp@2407: dev_err(&pdev->dev, "Rx DMA map failed\n"); fp@2407: adapter->rx_dma_failed++; fp@2407: break; fp@2407: } fp@2407: fp@2407: rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); fp@2407: rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); fp@2407: fp@2407: if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { fp@2407: /* fp@2407: * Force memory writes to complete before letting h/w fp@2407: * know there are new descriptors to fetch. (Only fp@2407: * applicable for weak-ordered memory model archs, fp@2407: * such as IA-64). fp@2407: */ fp@2407: wmb(); fp@2407: if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) fp@2407: e1000e_update_rdt_wa(adapter, i); fp@2407: else fp@2407: writel(i, adapter->hw.hw_addr + rx_ring->tail); fp@2407: } fp@2407: i++; fp@2407: if (i == rx_ring->count) fp@2407: i = 0; fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: } fp@2407: fp@2407: rx_ring->next_to_use = i; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split fp@2407: * @adapter: address of board private structure fp@2407: **/ fp@2407: static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, fp@2407: int cleaned_count, gfp_t gfp) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: union e1000_rx_desc_packet_split *rx_desc; fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: struct e1000_buffer *buffer_info; fp@2407: struct e1000_ps_page *ps_page; fp@2407: struct sk_buff *skb; fp@2407: unsigned int i, j; fp@2407: fp@2407: i = rx_ring->next_to_use; fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: fp@2407: while (cleaned_count--) { fp@2407: rx_desc = E1000_RX_DESC_PS(*rx_ring, i); fp@2407: fp@2407: for (j = 0; j < PS_PAGE_BUFFERS; j++) { fp@2407: ps_page = &buffer_info->ps_pages[j]; fp@2407: if (j >= adapter->rx_ps_pages) { fp@2407: /* all unused desc entries get hw null ptr */ fp@2407: rx_desc->read.buffer_addr[j + 1] = fp@2407: ~cpu_to_le64(0); fp@2407: continue; fp@2407: } fp@2407: if (!ps_page->page) { fp@2407: ps_page->page = alloc_page(gfp); fp@2407: if (!ps_page->page) { fp@2407: adapter->alloc_rx_buff_failed++; fp@2407: goto no_buffers; fp@2407: } fp@2407: ps_page->dma = dma_map_page(&pdev->dev, fp@2407: ps_page->page, fp@2407: 0, PAGE_SIZE, fp@2407: DMA_FROM_DEVICE); fp@2407: if (dma_mapping_error(&pdev->dev, fp@2407: ps_page->dma)) { fp@2407: dev_err(&adapter->pdev->dev, fp@2407: "Rx DMA page map failed\n"); fp@2407: adapter->rx_dma_failed++; fp@2407: goto no_buffers; fp@2407: } fp@2407: } fp@2407: /* fp@2407: * Refresh the desc even if buffer_addrs fp@2407: * didn't change because each write-back fp@2407: * erases this info. fp@2407: */ fp@2407: rx_desc->read.buffer_addr[j + 1] = fp@2407: cpu_to_le64(ps_page->dma); fp@2407: } fp@2407: fp@2407: skb = __netdev_alloc_skb_ip_align(netdev, fp@2407: adapter->rx_ps_bsize0, fp@2407: gfp); fp@2407: fp@2407: if (!skb) { fp@2407: adapter->alloc_rx_buff_failed++; fp@2407: break; fp@2407: } fp@2407: fp@2407: buffer_info->skb = skb; fp@2407: buffer_info->dma = dma_map_single(&pdev->dev, skb->data, fp@2407: adapter->rx_ps_bsize0, fp@2407: DMA_FROM_DEVICE); fp@2407: if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { fp@2407: dev_err(&pdev->dev, "Rx DMA map failed\n"); fp@2407: adapter->rx_dma_failed++; fp@2407: /* cleanup skb */ fp@2407: dev_kfree_skb_any(skb); fp@2407: buffer_info->skb = NULL; fp@2407: break; fp@2407: } fp@2407: fp@2407: rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); fp@2407: fp@2407: if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) { fp@2407: /* fp@2407: * Force memory writes to complete before letting h/w fp@2407: * know there are new descriptors to fetch. (Only fp@2407: * applicable for weak-ordered memory model archs, fp@2407: * such as IA-64). fp@2407: */ fp@2407: wmb(); fp@2407: if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) fp@2407: e1000e_update_rdt_wa(adapter, i << 1); fp@2407: else fp@2407: writel(i << 1, fp@2407: adapter->hw.hw_addr + rx_ring->tail); fp@2407: } fp@2407: fp@2407: i++; fp@2407: if (i == rx_ring->count) fp@2407: i = 0; fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: } fp@2407: fp@2407: no_buffers: fp@2407: rx_ring->next_to_use = i; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers fp@2407: * @adapter: address of board private structure fp@2407: * @cleaned_count: number of buffers to allocate this pass fp@2407: **/ fp@2407: fp@2407: static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, fp@2407: int cleaned_count, gfp_t gfp) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: union e1000_rx_desc_extended *rx_desc; fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: struct e1000_buffer *buffer_info; fp@2407: struct sk_buff *skb; fp@2407: unsigned int i; fp@2407: unsigned int bufsz = 256 - 16 /* for skb_reserve */; fp@2407: fp@2407: i = rx_ring->next_to_use; fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: fp@2407: while (cleaned_count--) { fp@2407: skb = buffer_info->skb; fp@2407: if (skb) { fp@2407: skb_trim(skb, 0); fp@2407: goto check_page; fp@2407: } fp@2407: fp@2407: skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp); fp@2407: if (unlikely(!skb)) { fp@2407: /* Better luck next round */ fp@2407: adapter->alloc_rx_buff_failed++; fp@2407: break; fp@2407: } fp@2407: fp@2407: buffer_info->skb = skb; fp@2407: check_page: fp@2407: /* allocate a new page if necessary */ fp@2407: if (!buffer_info->page) { fp@2407: buffer_info->page = alloc_page(gfp); fp@2407: if (unlikely(!buffer_info->page)) { fp@2407: adapter->alloc_rx_buff_failed++; fp@2407: break; fp@2407: } fp@2407: } fp@2407: fp@2407: if (!buffer_info->dma) fp@2407: buffer_info->dma = dma_map_page(&pdev->dev, fp@2407: buffer_info->page, 0, fp@2407: PAGE_SIZE, fp@2407: DMA_FROM_DEVICE); fp@2407: fp@2407: rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); fp@2407: rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); fp@2407: fp@2407: if (unlikely(++i == rx_ring->count)) fp@2407: i = 0; fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: } fp@2407: fp@2407: if (likely(rx_ring->next_to_use != i)) { fp@2407: rx_ring->next_to_use = i; fp@2407: if (unlikely(i-- == 0)) fp@2407: i = (rx_ring->count - 1); fp@2407: fp@2407: /* Force memory writes to complete before letting h/w fp@2407: * know there are new descriptors to fetch. (Only fp@2407: * applicable for weak-ordered memory model archs, fp@2407: * such as IA-64). */ fp@2407: wmb(); fp@2407: if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) fp@2407: e1000e_update_rdt_wa(adapter, i); fp@2407: else fp@2407: writel(i, adapter->hw.hw_addr + rx_ring->tail); fp@2407: } fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_clean_rx_irq - Send received data up the network stack; legacy fp@2407: * @adapter: board private structure fp@2407: * fp@2407: * the return value indicates whether actual cleaning was done, there fp@2407: * is no guarantee that everything was cleaned fp@2407: **/ fp@2407: static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, fp@2407: int *work_done, int work_to_do) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: union e1000_rx_desc_extended *rx_desc, *next_rxd; fp@2407: struct e1000_buffer *buffer_info, *next_buffer; fp@2407: u32 length, staterr; fp@2407: unsigned int i; fp@2407: int cleaned_count = 0; fp@2407: bool cleaned = 0; fp@2407: unsigned int total_rx_bytes = 0, total_rx_packets = 0; fp@2407: fp@2407: i = rx_ring->next_to_clean; fp@2407: rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); fp@2407: staterr = le32_to_cpu(rx_desc->wb.upper.status_error); fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: fp@2407: while (staterr & E1000_RXD_STAT_DD) { fp@2407: struct sk_buff *skb; fp@2407: fp@2407: if (*work_done >= work_to_do) fp@2407: break; fp@2407: (*work_done)++; fp@2407: rmb(); /* read descriptor and rx_buffer_info after status DD */ fp@2407: fp@2407: skb = buffer_info->skb; fp@2407: fp@2407: if (!adapter->ecdev) fp@2407: buffer_info->skb = NULL; fp@2407: fp@2407: prefetch(skb->data - NET_IP_ALIGN); fp@2407: fp@2407: i++; fp@2407: if (i == rx_ring->count) fp@2407: i = 0; fp@2407: next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); fp@2407: prefetch(next_rxd); fp@2407: fp@2407: next_buffer = &rx_ring->buffer_info[i]; fp@2407: fp@2407: cleaned = 1; fp@2407: cleaned_count++; fp@2407: dma_unmap_single(&pdev->dev, fp@2407: buffer_info->dma, fp@2407: adapter->rx_buffer_len, fp@2407: DMA_FROM_DEVICE); fp@2407: buffer_info->dma = 0; fp@2407: fp@2407: length = le16_to_cpu(rx_desc->wb.upper.length); fp@2407: fp@2407: /* fp@2407: * !EOP means multiple descriptors were used to store a single fp@2407: * packet, if that's the case we need to toss it. In fact, we fp@2407: * need to toss every packet with the EOP bit clear and the fp@2407: * next frame that _does_ have the EOP bit set, as it is by fp@2407: * definition only a frame fragment fp@2407: */ fp@2407: if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) fp@2407: adapter->flags2 |= FLAG2_IS_DISCARDING; fp@2407: fp@2407: if (adapter->flags2 & FLAG2_IS_DISCARDING) { fp@2407: /* All receives must fit into a single buffer */ fp@2407: e_dbg("Receive packet consumed multiple buffers\n"); fp@2407: /* recycle */ fp@2407: buffer_info->skb = skb; fp@2407: if (staterr & E1000_RXD_STAT_EOP) fp@2407: adapter->flags2 &= ~FLAG2_IS_DISCARDING; fp@2407: goto next_desc; fp@2407: } fp@2407: fp@2407: if (!adapter->ecdev && (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) { fp@2407: /* recycle */ fp@2407: buffer_info->skb = skb; fp@2407: goto next_desc; fp@2407: } fp@2407: fp@2407: /* adjust length to remove Ethernet CRC */ fp@2407: if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) fp@2407: length -= 4; fp@2407: fp@2407: total_rx_bytes += length; fp@2407: total_rx_packets++; fp@2407: fp@2407: /* fp@2407: * code added for copybreak, this should improve fp@2407: * performance for small packets with large amounts fp@2407: * of reassembly being done in the stack fp@2407: */ fp@2407: if (!adapter->ecdev && length < copybreak) { fp@2407: struct sk_buff *new_skb = fp@2407: netdev_alloc_skb_ip_align(netdev, length); fp@2407: if (new_skb) { fp@2407: skb_copy_to_linear_data_offset(new_skb, fp@2407: -NET_IP_ALIGN, fp@2407: (skb->data - fp@2407: NET_IP_ALIGN), fp@2407: (length + fp@2407: NET_IP_ALIGN)); fp@2407: /* save the skb in buffer_info as good */ fp@2407: buffer_info->skb = skb; fp@2407: skb = new_skb; fp@2407: } fp@2407: /* else just continue with the old one */ fp@2407: } fp@2407: /* end copybreak code */ fp@2407: skb_put(skb, length); fp@2407: fp@2407: /* Receive Checksum Offload */ fp@2407: e1000_rx_checksum(adapter, staterr, fp@2407: le16_to_cpu(rx_desc->wb.lower.hi_dword. fp@2407: csum_ip.csum), skb); fp@2407: fp@2407: if (adapter->ecdev) { fp@2407: ecdev_receive(adapter->ecdev, skb->data, length); fp@2407: adapter->ec_watchdog_jiffies = jiffies; fp@2407: } else { fp@2407: e1000_receive_skb(adapter, netdev, skb, staterr, fp@2407: rx_desc->wb.upper.vlan); fp@2473: } fp@2407: fp@2407: next_desc: fp@2407: rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); fp@2407: fp@2407: /* return some buffers to hardware, one at a time is too slow */ fp@2407: if (cleaned_count >= E1000_RX_BUFFER_WRITE) { fp@2407: adapter->alloc_rx_buf(adapter, cleaned_count, fp@2407: GFP_ATOMIC); fp@2407: cleaned_count = 0; fp@2407: } fp@2407: fp@2407: /* use prefetched values */ fp@2407: rx_desc = next_rxd; fp@2407: buffer_info = next_buffer; fp@2407: fp@2407: staterr = le32_to_cpu(rx_desc->wb.upper.status_error); fp@2407: } fp@2407: rx_ring->next_to_clean = i; fp@2407: fp@2407: cleaned_count = e1000_desc_unused(rx_ring); fp@2407: if (cleaned_count) fp@2407: adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); fp@2407: fp@2407: adapter->total_rx_bytes += total_rx_bytes; fp@2407: adapter->total_rx_packets += total_rx_packets; fp@2407: return cleaned; fp@2407: } fp@2407: fp@2407: static void e1000_put_txbuf(struct e1000_adapter *adapter, fp@2407: struct e1000_buffer *buffer_info) fp@2407: { fp@2407: if (adapter->ecdev) fp@2407: return; fp@2407: fp@2407: if (buffer_info->dma) { fp@2407: if (buffer_info->mapped_as_page) fp@2407: dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, fp@2407: buffer_info->length, DMA_TO_DEVICE); fp@2407: else fp@2407: dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, fp@2407: buffer_info->length, DMA_TO_DEVICE); fp@2407: buffer_info->dma = 0; fp@2407: } fp@2407: if (buffer_info->skb) { fp@2407: dev_kfree_skb_any(buffer_info->skb); fp@2407: buffer_info->skb = NULL; fp@2407: } fp@2407: buffer_info->time_stamp = 0; fp@2407: } fp@2407: fp@2407: static void e1000_print_hw_hang(struct work_struct *work) fp@2407: { fp@2407: struct e1000_adapter *adapter = container_of(work, fp@2407: struct e1000_adapter, fp@2407: print_hang_task); fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: unsigned int i = tx_ring->next_to_clean; fp@2407: unsigned int eop = tx_ring->buffer_info[i].next_to_watch; fp@2407: struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u16 phy_status, phy_1000t_status, phy_ext_status; fp@2407: u16 pci_status; fp@2407: fp@2407: if (test_bit(__E1000_DOWN, &adapter->state)) fp@2407: return; fp@2407: fp@2407: if (!adapter->tx_hang_recheck && fp@2407: (adapter->flags2 & FLAG2_DMA_BURST)) { fp@2407: /* May be block on write-back, flush and detect again fp@2407: * flush pending descriptor writebacks to memory fp@2407: */ fp@2407: ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); fp@2407: /* execute the writes immediately */ fp@2407: e1e_flush(); fp@2407: adapter->tx_hang_recheck = true; fp@2407: return; fp@2407: } fp@2407: /* Real hang detected */ fp@2407: adapter->tx_hang_recheck = false; fp@2473: if (!adapter->ecdev) { fp@2473: netif_stop_queue(netdev); fp@2473: } fp@2407: fp@2407: e1e_rphy(hw, PHY_STATUS, &phy_status); fp@2407: e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status); fp@2407: e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status); fp@2407: fp@2407: pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status); fp@2407: fp@2407: /* detected Hardware unit hang */ fp@2407: e_err("Detected Hardware Unit Hang:\n" fp@2407: " TDH <%x>\n" fp@2407: " TDT <%x>\n" fp@2407: " next_to_use <%x>\n" fp@2407: " next_to_clean <%x>\n" fp@2407: "buffer_info[next_to_clean]:\n" fp@2407: " time_stamp <%lx>\n" fp@2407: " next_to_watch <%x>\n" fp@2407: " jiffies <%lx>\n" fp@2407: " next_to_watch.status <%x>\n" fp@2407: "MAC Status <%x>\n" fp@2407: "PHY Status <%x>\n" fp@2407: "PHY 1000BASE-T Status <%x>\n" fp@2407: "PHY Extended Status <%x>\n" fp@2407: "PCI Status <%x>\n", fp@2407: readl(adapter->hw.hw_addr + tx_ring->head), fp@2407: readl(adapter->hw.hw_addr + tx_ring->tail), fp@2407: tx_ring->next_to_use, fp@2407: tx_ring->next_to_clean, fp@2407: tx_ring->buffer_info[eop].time_stamp, fp@2407: eop, fp@2407: jiffies, fp@2407: eop_desc->upper.fields.status, fp@2407: er32(STATUS), fp@2407: phy_status, fp@2407: phy_1000t_status, fp@2407: phy_ext_status, fp@2407: pci_status); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_clean_tx_irq - Reclaim resources after transmit completes fp@2407: * @adapter: board private structure fp@2407: * fp@2407: * the return value indicates whether actual cleaning was done, there fp@2407: * is no guarantee that everything was cleaned fp@2407: **/ fp@2407: static bool e1000_clean_tx_irq(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: struct e1000_tx_desc *tx_desc, *eop_desc; fp@2407: struct e1000_buffer *buffer_info; fp@2407: unsigned int i, eop; fp@2407: unsigned int count = 0; fp@2407: unsigned int total_tx_bytes = 0, total_tx_packets = 0; fp@2407: fp@2407: i = tx_ring->next_to_clean; fp@2407: eop = tx_ring->buffer_info[i].next_to_watch; fp@2407: eop_desc = E1000_TX_DESC(*tx_ring, eop); fp@2407: fp@2407: while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && fp@2407: (count < tx_ring->count)) { fp@2407: bool cleaned = false; fp@2407: rmb(); /* read buffer_info after eop_desc */ fp@2407: for (; !cleaned; count++) { fp@2407: tx_desc = E1000_TX_DESC(*tx_ring, i); fp@2407: buffer_info = &tx_ring->buffer_info[i]; fp@2407: cleaned = (i == eop); fp@2407: fp@2407: if (cleaned) { fp@2407: total_tx_packets += buffer_info->segs; fp@2407: total_tx_bytes += buffer_info->bytecount; fp@2407: } fp@2407: fp@2407: e1000_put_txbuf(adapter, buffer_info); fp@2407: tx_desc->upper.data = 0; fp@2407: fp@2407: i++; fp@2407: if (i == tx_ring->count) fp@2407: i = 0; fp@2407: } fp@2407: fp@2407: if (i == tx_ring->next_to_use) fp@2407: break; fp@2407: eop = tx_ring->buffer_info[i].next_to_watch; fp@2407: eop_desc = E1000_TX_DESC(*tx_ring, eop); fp@2407: } fp@2407: fp@2407: tx_ring->next_to_clean = i; fp@2407: fp@2407: #define TX_WAKE_THRESHOLD 32 fp@2407: if (!adapter->ecdev && count && netif_carrier_ok(netdev) && fp@2407: e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) { fp@2407: /* Make sure that anybody stopping the queue after this fp@2407: * sees the new next_to_clean. fp@2407: */ fp@2407: smp_mb(); fp@2407: fp@2407: if (netif_queue_stopped(netdev) && fp@2407: !(test_bit(__E1000_DOWN, &adapter->state))) { fp@2407: netif_wake_queue(netdev); fp@2407: ++adapter->restart_queue; fp@2407: } fp@2407: } fp@2407: fp@2407: if (!adapter->ecdev && adapter->detect_tx_hung) { fp@2407: /* fp@2407: * Detect a transmit hang in hardware, this serializes the fp@2407: * check with the clearing of time_stamp and movement of i fp@2407: */ fp@2407: adapter->detect_tx_hung = 0; fp@2407: if (tx_ring->buffer_info[i].time_stamp && fp@2407: time_after(jiffies, tx_ring->buffer_info[i].time_stamp fp@2407: + (adapter->tx_timeout_factor * HZ)) && fp@2407: !(er32(STATUS) & E1000_STATUS_TXOFF)) fp@2407: schedule_work(&adapter->print_hang_task); fp@2407: else fp@2407: adapter->tx_hang_recheck = false; fp@2407: } fp@2407: adapter->total_tx_bytes += total_tx_bytes; fp@2407: adapter->total_tx_packets += total_tx_packets; fp@2407: return count < tx_ring->count; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split fp@2407: * @adapter: board private structure fp@2407: * fp@2407: * the return value indicates whether actual cleaning was done, there fp@2407: * is no guarantee that everything was cleaned fp@2407: **/ fp@2407: static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, fp@2407: int *work_done, int work_to_do) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: union e1000_rx_desc_packet_split *rx_desc, *next_rxd; fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: struct e1000_buffer *buffer_info, *next_buffer; fp@2407: struct e1000_ps_page *ps_page; fp@2407: struct sk_buff *skb; fp@2407: unsigned int i, j; fp@2407: u32 length, staterr; fp@2407: int cleaned_count = 0; fp@2407: bool cleaned = 0; fp@2407: unsigned int total_rx_bytes = 0, total_rx_packets = 0; fp@2407: fp@2407: i = rx_ring->next_to_clean; fp@2407: rx_desc = E1000_RX_DESC_PS(*rx_ring, i); fp@2407: staterr = le32_to_cpu(rx_desc->wb.middle.status_error); fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: fp@2407: while (staterr & E1000_RXD_STAT_DD) { fp@2407: if (*work_done >= work_to_do) fp@2407: break; fp@2407: (*work_done)++; fp@2407: skb = buffer_info->skb; fp@2407: rmb(); /* read descriptor and rx_buffer_info after status DD */ fp@2407: fp@2407: /* in the packet split case this is header only */ fp@2407: prefetch(skb->data - NET_IP_ALIGN); fp@2407: fp@2407: i++; fp@2407: if (i == rx_ring->count) fp@2407: i = 0; fp@2407: next_rxd = E1000_RX_DESC_PS(*rx_ring, i); fp@2407: prefetch(next_rxd); fp@2407: fp@2407: next_buffer = &rx_ring->buffer_info[i]; fp@2407: fp@2407: cleaned = 1; fp@2407: cleaned_count++; fp@2407: dma_unmap_single(&pdev->dev, buffer_info->dma, fp@2407: adapter->rx_ps_bsize0, DMA_FROM_DEVICE); fp@2407: buffer_info->dma = 0; fp@2407: fp@2407: /* see !EOP comment in other Rx routine */ fp@2407: if (!(staterr & E1000_RXD_STAT_EOP)) fp@2407: adapter->flags2 |= FLAG2_IS_DISCARDING; fp@2407: fp@2407: if (adapter->flags2 & FLAG2_IS_DISCARDING) { fp@2407: e_dbg("Packet Split buffers didn't pick up the full " fp@2407: "packet\n"); fp@2407: if (!adapter->ecdev) dev_kfree_skb_irq(skb); fp@2407: if (staterr & E1000_RXD_STAT_EOP) fp@2407: adapter->flags2 &= ~FLAG2_IS_DISCARDING; fp@2407: goto next_desc; fp@2407: } fp@2407: fp@2407: if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { fp@2407: if (!adapter->ecdev) fp@2407: dev_kfree_skb_irq(skb); fp@2407: goto next_desc; fp@2407: } fp@2407: fp@2407: length = le16_to_cpu(rx_desc->wb.middle.length0); fp@2407: fp@2407: if (!length) { fp@2407: e_dbg("Last part of the packet spanning multiple " fp@2407: "descriptors\n"); fp@2407: if (!adapter->ecdev) fp@2407: dev_kfree_skb_irq(skb); fp@2407: goto next_desc; fp@2407: } fp@2407: fp@2407: /* Good Receive */ fp@2407: skb_put(skb, length); fp@2407: fp@2407: { fp@2407: /* fp@2407: * this looks ugly, but it seems compiler issues make it fp@2407: * more efficient than reusing j fp@2407: */ fp@2407: int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); fp@2407: fp@2407: /* fp@2407: * page alloc/put takes too long and effects small packet fp@2407: * throughput, so unsplit small packets and save the alloc/put fp@2407: * only valid in softirq (napi) context to call kmap_* fp@2407: */ fp@2407: if (l1 && (l1 <= copybreak) && fp@2407: ((length + l1) <= adapter->rx_ps_bsize0)) { fp@2407: u8 *vaddr; fp@2407: fp@2407: ps_page = &buffer_info->ps_pages[0]; fp@2407: fp@2407: /* fp@2407: * there is no documentation about how to call fp@2407: * kmap_atomic, so we can't hold the mapping fp@2407: * very long fp@2407: */ fp@2407: dma_sync_single_for_cpu(&pdev->dev, ps_page->dma, fp@2407: PAGE_SIZE, DMA_FROM_DEVICE); fp@2407: vaddr = kmap_atomic(ps_page->page, KM_SKB_DATA_SOFTIRQ); fp@2407: memcpy(skb_tail_pointer(skb), vaddr, l1); fp@2407: kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); fp@2407: dma_sync_single_for_device(&pdev->dev, ps_page->dma, fp@2407: PAGE_SIZE, DMA_FROM_DEVICE); fp@2407: fp@2407: /* remove the CRC */ fp@2407: if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) fp@2407: l1 -= 4; fp@2407: fp@2407: skb_put(skb, l1); fp@2407: goto copydone; fp@2407: } /* if */ fp@2407: } fp@2407: fp@2407: for (j = 0; j < PS_PAGE_BUFFERS; j++) { fp@2407: length = le16_to_cpu(rx_desc->wb.upper.length[j]); fp@2407: if (!length) fp@2407: break; fp@2407: fp@2407: ps_page = &buffer_info->ps_pages[j]; fp@2407: dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, fp@2407: DMA_FROM_DEVICE); fp@2407: ps_page->dma = 0; fp@2407: skb_fill_page_desc(skb, j, ps_page->page, 0, length); fp@2407: ps_page->page = NULL; fp@2407: skb->len += length; fp@2407: skb->data_len += length; fp@2407: skb->truesize += PAGE_SIZE; fp@2407: } fp@2407: fp@2407: /* strip the ethernet crc, problem is we're using pages now so fp@2407: * this whole operation can get a little cpu intensive fp@2407: */ fp@2407: if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) fp@2407: pskb_trim(skb, skb->len - 4); fp@2407: fp@2407: copydone: fp@2407: total_rx_bytes += skb->len; fp@2407: total_rx_packets++; fp@2407: fp@2407: e1000_rx_checksum(adapter, staterr, le16_to_cpu( fp@2407: rx_desc->wb.lower.hi_dword.csum_ip.csum), skb); fp@2407: fp@2407: if (rx_desc->wb.upper.header_status & fp@2407: cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)) fp@2407: adapter->rx_hdr_split++; fp@2407: fp@2407: if (adapter->ecdev) { fp@2407: ecdev_receive(adapter->ecdev, skb->data, length); fp@2407: adapter->ec_watchdog_jiffies = jiffies; fp@2407: } else { fp@2407: e1000_receive_skb(adapter, netdev, skb, fp@2407: staterr, rx_desc->wb.middle.vlan); fp@2407: } fp@2407: fp@2407: next_desc: fp@2407: rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); fp@2407: if (!adapter->ecdev) buffer_info->skb = NULL; fp@2407: fp@2407: /* return some buffers to hardware, one at a time is too slow */ fp@2407: if (cleaned_count >= E1000_RX_BUFFER_WRITE) { fp@2407: adapter->alloc_rx_buf(adapter, cleaned_count, fp@2407: GFP_ATOMIC); fp@2407: cleaned_count = 0; fp@2407: } fp@2407: fp@2407: /* use prefetched values */ fp@2407: rx_desc = next_rxd; fp@2407: buffer_info = next_buffer; fp@2407: fp@2407: staterr = le32_to_cpu(rx_desc->wb.middle.status_error); fp@2407: } fp@2407: rx_ring->next_to_clean = i; fp@2407: fp@2407: cleaned_count = e1000_desc_unused(rx_ring); fp@2407: if (cleaned_count) fp@2407: adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); fp@2407: fp@2407: adapter->total_rx_bytes += total_rx_bytes; fp@2407: adapter->total_rx_packets += total_rx_packets; fp@2407: return cleaned; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_consume_page - helper function fp@2407: **/ fp@2407: static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, fp@2407: u16 length) fp@2407: { fp@2407: bi->page = NULL; fp@2407: skb->len += length; fp@2407: skb->data_len += length; fp@2407: skb->truesize += PAGE_SIZE; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy fp@2407: * @adapter: board private structure fp@2407: * fp@2407: * the return value indicates whether actual cleaning was done, there fp@2407: * is no guarantee that everything was cleaned fp@2407: **/ fp@2407: fp@2407: static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, fp@2407: int *work_done, int work_to_do) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: union e1000_rx_desc_extended *rx_desc, *next_rxd; fp@2407: struct e1000_buffer *buffer_info, *next_buffer; fp@2407: u32 length, staterr; fp@2407: unsigned int i; fp@2407: int cleaned_count = 0; fp@2407: bool cleaned = false; fp@2407: unsigned int total_rx_bytes=0, total_rx_packets=0; fp@2407: fp@2407: i = rx_ring->next_to_clean; fp@2407: rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); fp@2407: staterr = le32_to_cpu(rx_desc->wb.upper.status_error); fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: fp@2407: while (staterr & E1000_RXD_STAT_DD) { fp@2407: struct sk_buff *skb; fp@2407: fp@2407: if (*work_done >= work_to_do) fp@2407: break; fp@2407: (*work_done)++; fp@2407: rmb(); /* read descriptor and rx_buffer_info after status DD */ fp@2407: fp@2407: skb = buffer_info->skb; fp@2407: fp@2407: if (!adapter->ecdev) fp@2407: buffer_info->skb = NULL; fp@2407: fp@2407: ++i; fp@2407: if (i == rx_ring->count) fp@2407: i = 0; fp@2407: next_rxd = E1000_RX_DESC_EXT(*rx_ring, i); fp@2407: prefetch(next_rxd); fp@2407: fp@2407: next_buffer = &rx_ring->buffer_info[i]; fp@2407: fp@2407: cleaned = true; fp@2407: cleaned_count++; fp@2407: dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE, fp@2407: DMA_FROM_DEVICE); fp@2407: buffer_info->dma = 0; fp@2407: fp@2407: length = le16_to_cpu(rx_desc->wb.upper.length); fp@2407: fp@2407: /* errors is only valid for DD + EOP descriptors */ fp@2407: if (!adapter->ecdev && (unlikely((staterr & E1000_RXD_STAT_EOP) && fp@2407: (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)))) { fp@2407: /* recycle both page and skb */ fp@2407: buffer_info->skb = skb; fp@2407: /* an error means any chain goes out the window too */ fp@2407: if (rx_ring->rx_skb_top) fp@2407: dev_kfree_skb_irq(rx_ring->rx_skb_top); fp@2407: rx_ring->rx_skb_top = NULL; fp@2407: goto next_desc; fp@2407: } fp@2407: fp@2407: #define rxtop (rx_ring->rx_skb_top) fp@2407: if (!(staterr & E1000_RXD_STAT_EOP)) { fp@2407: /* this descriptor is only the beginning (or middle) */ fp@2407: if (!rxtop) { fp@2407: /* this is the beginning of a chain */ fp@2407: rxtop = skb; fp@2407: skb_fill_page_desc(rxtop, 0, buffer_info->page, fp@2407: 0, length); fp@2407: } else { fp@2407: /* this is the middle of a chain */ fp@2407: skb_fill_page_desc(rxtop, fp@2407: skb_shinfo(rxtop)->nr_frags, fp@2407: buffer_info->page, 0, length); fp@2407: /* re-use the skb, only consumed the page */ fp@2407: buffer_info->skb = skb; fp@2407: } fp@2407: e1000_consume_page(buffer_info, rxtop, length); fp@2407: goto next_desc; fp@2407: } else { fp@2407: if (rxtop) { fp@2407: /* end of the chain */ fp@2407: skb_fill_page_desc(rxtop, fp@2407: skb_shinfo(rxtop)->nr_frags, fp@2407: buffer_info->page, 0, length); fp@2407: /* re-use the current skb, we only consumed the fp@2407: * page */ fp@2407: buffer_info->skb = skb; fp@2407: skb = rxtop; fp@2407: rxtop = NULL; fp@2407: e1000_consume_page(buffer_info, skb, length); fp@2407: } else { fp@2407: /* no chain, got EOP, this buf is the packet fp@2407: * copybreak to save the put_page/alloc_page */ fp@2407: if (length <= copybreak && fp@2407: skb_tailroom(skb) >= length) { fp@2407: u8 *vaddr; fp@2407: vaddr = kmap_atomic(buffer_info->page, fp@2407: KM_SKB_DATA_SOFTIRQ); fp@2407: memcpy(skb_tail_pointer(skb), vaddr, fp@2407: length); fp@2407: kunmap_atomic(vaddr, fp@2407: KM_SKB_DATA_SOFTIRQ); fp@2407: /* re-use the page, so don't erase fp@2407: * buffer_info->page */ fp@2407: skb_put(skb, length); fp@2407: } else { fp@2407: skb_fill_page_desc(skb, 0, fp@2407: buffer_info->page, 0, fp@2407: length); fp@2407: e1000_consume_page(buffer_info, skb, fp@2407: length); fp@2407: } fp@2407: } fp@2407: } fp@2407: fp@2407: /* Receive Checksum Offload XXX recompute due to CRC strip? */ fp@2407: e1000_rx_checksum(adapter, staterr, fp@2407: le16_to_cpu(rx_desc->wb.lower.hi_dword. fp@2407: csum_ip.csum), skb); fp@2407: fp@2407: /* probably a little skewed due to removing CRC */ fp@2407: total_rx_bytes += skb->len; fp@2407: total_rx_packets++; fp@2407: fp@2407: /* eth type trans needs skb->data to point to something */ fp@2407: if (!adapter->ecdev && !pskb_may_pull(skb, ETH_HLEN)) { fp@2407: e_err("pskb_may_pull failed.\n"); fp@2407: dev_kfree_skb_irq(skb); fp@2407: goto next_desc; fp@2407: } fp@2407: fp@2407: if (adapter->ecdev) { fp@2407: ecdev_receive(adapter->ecdev, skb->data, length); fp@2407: adapter->ec_watchdog_jiffies = jiffies; fp@2407: } else { fp@2407: e1000_receive_skb(adapter, netdev, skb, staterr, fp@2407: rx_desc->wb.upper.vlan); fp@2407: } fp@2407: fp@2407: fp@2407: next_desc: fp@2407: rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF); fp@2407: fp@2407: /* return some buffers to hardware, one at a time is too slow */ fp@2407: if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { fp@2407: adapter->alloc_rx_buf(adapter, cleaned_count, fp@2407: GFP_ATOMIC); fp@2407: cleaned_count = 0; fp@2407: } fp@2407: fp@2407: /* use prefetched values */ fp@2407: rx_desc = next_rxd; fp@2407: buffer_info = next_buffer; fp@2407: fp@2407: staterr = le32_to_cpu(rx_desc->wb.upper.status_error); fp@2407: } fp@2407: rx_ring->next_to_clean = i; fp@2407: fp@2407: cleaned_count = e1000_desc_unused(rx_ring); fp@2407: if (cleaned_count) fp@2407: adapter->alloc_rx_buf(adapter, cleaned_count, GFP_ATOMIC); fp@2407: fp@2407: adapter->total_rx_bytes += total_rx_bytes; fp@2407: adapter->total_rx_packets += total_rx_packets; fp@2407: return cleaned; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_clean_rx_ring - Free Rx Buffers per Queue fp@2407: * @adapter: board private structure fp@2407: **/ fp@2407: static void e1000_clean_rx_ring(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: struct e1000_buffer *buffer_info; fp@2407: struct e1000_ps_page *ps_page; fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: unsigned int i, j; fp@2407: fp@2407: /* Free all the Rx ring sk_buffs */ fp@2407: for (i = 0; i < rx_ring->count; i++) { fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: if (buffer_info->dma) { fp@2407: if (adapter->clean_rx == e1000_clean_rx_irq) fp@2407: dma_unmap_single(&pdev->dev, buffer_info->dma, fp@2407: adapter->rx_buffer_len, fp@2407: DMA_FROM_DEVICE); fp@2407: else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) fp@2407: dma_unmap_page(&pdev->dev, buffer_info->dma, fp@2407: PAGE_SIZE, fp@2407: DMA_FROM_DEVICE); fp@2407: else if (adapter->clean_rx == e1000_clean_rx_irq_ps) fp@2407: dma_unmap_single(&pdev->dev, buffer_info->dma, fp@2407: adapter->rx_ps_bsize0, fp@2407: DMA_FROM_DEVICE); fp@2407: buffer_info->dma = 0; fp@2407: } fp@2407: fp@2407: if (buffer_info->page) { fp@2407: put_page(buffer_info->page); fp@2407: buffer_info->page = NULL; fp@2407: } fp@2407: fp@2407: if (buffer_info->skb) { fp@2407: dev_kfree_skb(buffer_info->skb); fp@2407: buffer_info->skb = NULL; fp@2407: } fp@2407: fp@2407: for (j = 0; j < PS_PAGE_BUFFERS; j++) { fp@2407: ps_page = &buffer_info->ps_pages[j]; fp@2407: if (!ps_page->page) fp@2407: break; fp@2407: dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE, fp@2407: DMA_FROM_DEVICE); fp@2407: ps_page->dma = 0; fp@2407: put_page(ps_page->page); fp@2407: ps_page->page = NULL; fp@2407: } fp@2407: } fp@2407: fp@2407: /* there also may be some cached data from a chained receive */ fp@2407: if (rx_ring->rx_skb_top) { fp@2407: dev_kfree_skb(rx_ring->rx_skb_top); fp@2407: rx_ring->rx_skb_top = NULL; fp@2407: } fp@2407: fp@2407: /* Zero out the descriptor ring */ fp@2407: memset(rx_ring->desc, 0, rx_ring->size); fp@2407: fp@2407: rx_ring->next_to_clean = 0; fp@2407: rx_ring->next_to_use = 0; fp@2407: adapter->flags2 &= ~FLAG2_IS_DISCARDING; fp@2407: fp@2407: writel(0, adapter->hw.hw_addr + rx_ring->head); fp@2407: writel(0, adapter->hw.hw_addr + rx_ring->tail); fp@2407: } fp@2407: fp@2407: static void e1000e_downshift_workaround(struct work_struct *work) fp@2407: { fp@2407: struct e1000_adapter *adapter = container_of(work, fp@2407: struct e1000_adapter, downshift_task); fp@2407: fp@2407: if (test_bit(__E1000_DOWN, &adapter->state)) fp@2407: return; fp@2407: fp@2407: e1000e_gig_downshift_workaround_ich8lan(&adapter->hw); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_intr_msi - Interrupt Handler fp@2407: * @irq: interrupt number fp@2407: * @data: pointer to a network interface device structure fp@2407: **/ fp@2407: static irqreturn_t e1000_intr_msi(int irq, void *data) fp@2407: { fp@2407: struct net_device *netdev = data; fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 icr = er32(ICR); fp@2407: fp@2473: if (adapter->ecdev) { fp@2473: int ec_work_done = 0; fp@2473: adapter->clean_rx(adapter, &ec_work_done, 100); fp@2473: e1000_clean_tx_irq(adapter); fp@2407: return IRQ_HANDLED; fp@2407: } fp@2407: /* fp@2407: * read ICR disables interrupts using IAM fp@2407: */ fp@2407: fp@2407: if (icr & E1000_ICR_LSC) { fp@2407: hw->mac.get_link_status = 1; fp@2407: /* fp@2407: * ICH8 workaround-- Call gig speed drop workaround on cable fp@2407: * disconnect (LSC) before accessing any PHY registers fp@2407: */ fp@2407: if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && fp@2407: (!(er32(STATUS) & E1000_STATUS_LU))) fp@2407: schedule_work(&adapter->downshift_task); fp@2407: fp@2407: /* fp@2407: * 80003ES2LAN workaround-- For packet buffer work-around on fp@2407: * link down event; disable receives here in the ISR and reset fp@2407: * adapter in watchdog fp@2407: */ fp@2407: if (netif_carrier_ok(netdev) && fp@2407: adapter->flags & FLAG_RX_NEEDS_RESTART) { fp@2407: /* disable receives */ fp@2407: u32 rctl = er32(RCTL); fp@2407: ew32(RCTL, rctl & ~E1000_RCTL_EN); fp@2407: adapter->flags |= FLAG_RX_RESTART_NOW; fp@2407: } fp@2407: /* guard against interrupt when we're going down */ fp@2407: if (!test_bit(__E1000_DOWN, &adapter->state)) fp@2407: mod_timer(&adapter->watchdog_timer, jiffies + 1); fp@2407: } fp@2407: fp@2407: if (napi_schedule_prep(&adapter->napi)) { fp@2407: adapter->total_tx_bytes = 0; fp@2407: adapter->total_tx_packets = 0; fp@2407: adapter->total_rx_bytes = 0; fp@2407: adapter->total_rx_packets = 0; fp@2407: __napi_schedule(&adapter->napi); fp@2407: } fp@2407: fp@2407: return IRQ_HANDLED; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_intr - Interrupt Handler fp@2407: * @irq: interrupt number fp@2407: * @data: pointer to a network interface device structure fp@2407: **/ fp@2407: static irqreturn_t e1000_intr(int irq, void *data) fp@2407: { fp@2407: struct net_device *netdev = data; fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 rctl, icr = er32(ICR); fp@2407: fp@2407: if (!icr || test_bit(__E1000_DOWN, &adapter->state)) fp@2407: return IRQ_NONE; /* Not our interrupt */ fp@2407: fp@2407: /* fp@2407: * IMS will not auto-mask if INT_ASSERTED is not set, and if it is fp@2407: * not set, then the adapter didn't send an interrupt fp@2407: */ fp@2407: if (!adapter->ecdev && !(icr & E1000_ICR_INT_ASSERTED)) fp@2407: return IRQ_NONE; fp@2407: fp@2407: /* fp@2407: * Interrupt Auto-Mask...upon reading ICR, fp@2407: * interrupts are masked. No need for the fp@2407: * IMC write fp@2407: */ fp@2407: fp@2407: if (!adapter->ecdev && (icr & E1000_ICR_LSC)) { fp@2407: hw->mac.get_link_status = 1; fp@2407: /* fp@2407: * ICH8 workaround-- Call gig speed drop workaround on cable fp@2407: * disconnect (LSC) before accessing any PHY registers fp@2407: */ fp@2407: if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) && fp@2407: (!(er32(STATUS) & E1000_STATUS_LU))) fp@2407: schedule_work(&adapter->downshift_task); fp@2407: fp@2407: /* fp@2407: * 80003ES2LAN workaround-- fp@2407: * For packet buffer work-around on link down event; fp@2407: * disable receives here in the ISR and fp@2407: * reset adapter in watchdog fp@2407: */ fp@2407: if (netif_carrier_ok(netdev) && fp@2407: (adapter->flags & FLAG_RX_NEEDS_RESTART)) { fp@2407: /* disable receives */ fp@2407: rctl = er32(RCTL); fp@2407: ew32(RCTL, rctl & ~E1000_RCTL_EN); fp@2407: adapter->flags |= FLAG_RX_RESTART_NOW; fp@2407: } fp@2407: /* guard against interrupt when we're going down */ fp@2407: if (!test_bit(__E1000_DOWN, &adapter->state)) fp@2407: mod_timer(&adapter->watchdog_timer, jiffies + 1); fp@2407: } fp@2407: fp@2473: if (adapter->ecdev) { fp@2473: int ec_work_done = 0; fp@2473: adapter->clean_rx(adapter, &ec_work_done, 100); fp@2473: e1000_clean_tx_irq(adapter); fp@2407: return IRQ_HANDLED; fp@2407: } fp@2407: fp@2407: if (napi_schedule_prep(&adapter->napi)) { fp@2407: adapter->total_tx_bytes = 0; fp@2407: adapter->total_tx_packets = 0; fp@2407: adapter->total_rx_bytes = 0; fp@2407: adapter->total_rx_packets = 0; fp@2407: __napi_schedule(&adapter->napi); fp@2407: } fp@2407: fp@2407: return IRQ_HANDLED; fp@2407: } fp@2407: fp@2407: static irqreturn_t e1000_msix_other(int irq, void *data) fp@2407: { fp@2407: struct net_device *netdev = data; fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 icr = er32(ICR); fp@2407: fp@2407: if (!(icr & E1000_ICR_INT_ASSERTED)) { fp@2407: if (!test_bit(__E1000_DOWN, &adapter->state)) fp@2407: ew32(IMS, E1000_IMS_OTHER); fp@2407: return IRQ_NONE; fp@2407: } fp@2407: fp@2407: if (icr & adapter->eiac_mask) fp@2407: ew32(ICS, (icr & adapter->eiac_mask)); fp@2407: fp@2407: if (icr & E1000_ICR_OTHER) { fp@2407: if (!(icr & E1000_ICR_LSC)) fp@2407: goto no_link_interrupt; fp@2407: hw->mac.get_link_status = 1; fp@2407: /* guard against interrupt when we're going down */ fp@2407: if (!adapter->ecdev && !test_bit(__E1000_DOWN, &adapter->state)) fp@2407: mod_timer(&adapter->watchdog_timer, jiffies + 1); fp@2407: } fp@2407: fp@2407: no_link_interrupt: fp@2407: if (!test_bit(__E1000_DOWN, &adapter->state)) fp@2407: ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER); fp@2407: fp@2407: return IRQ_HANDLED; fp@2407: } fp@2407: fp@2407: fp@2407: static irqreturn_t e1000_intr_msix_tx(int irq, void *data) fp@2407: { fp@2407: struct net_device *netdev = data; fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: fp@2407: fp@2407: adapter->total_tx_bytes = 0; fp@2407: adapter->total_tx_packets = 0; fp@2407: fp@2407: if (!e1000_clean_tx_irq(adapter)) fp@2407: /* Ring was not completely cleaned, so fire another interrupt */ fp@2407: ew32(ICS, tx_ring->ims_val); fp@2407: fp@2407: return IRQ_HANDLED; fp@2407: } fp@2407: fp@2407: static irqreturn_t e1000_intr_msix_rx(int irq, void *data) fp@2407: { fp@2407: struct net_device *netdev = data; fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: /* Write the ITR value calculated at the end of the fp@2407: * previous interrupt. fp@2407: */ fp@2407: if (adapter->rx_ring->set_itr) { fp@2407: writel(1000000000 / (adapter->rx_ring->itr_val * 256), fp@2407: adapter->hw.hw_addr + adapter->rx_ring->itr_register); fp@2407: adapter->rx_ring->set_itr = 0; fp@2407: } fp@2407: fp@2473: if (adapter->ecdev) { fp@2473: int ec_work_done = 0; fp@2473: adapter->clean_rx(adapter, &ec_work_done, 100); fp@2407: } else { fp@2407: if (napi_schedule_prep(&adapter->napi)) { fp@2407: adapter->total_rx_bytes = 0; fp@2407: adapter->total_rx_packets = 0; fp@2407: __napi_schedule(&adapter->napi); fp@2407: } fp@2407: } fp@2407: return IRQ_HANDLED; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_configure_msix - Configure MSI-X hardware fp@2407: * fp@2407: * e1000_configure_msix sets up the hardware to properly fp@2407: * generate MSI-X interrupts. fp@2407: **/ fp@2407: static void e1000_configure_msix(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: int vector = 0; fp@2407: u32 ctrl_ext, ivar = 0; fp@2407: fp@2407: adapter->eiac_mask = 0; fp@2407: fp@2407: /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */ fp@2407: if (hw->mac.type == e1000_82574) { fp@2407: u32 rfctl = er32(RFCTL); fp@2407: rfctl |= E1000_RFCTL_ACK_DIS; fp@2407: ew32(RFCTL, rfctl); fp@2407: } fp@2407: fp@2407: #define E1000_IVAR_INT_ALLOC_VALID 0x8 fp@2407: /* Configure Rx vector */ fp@2407: rx_ring->ims_val = E1000_IMS_RXQ0; fp@2407: adapter->eiac_mask |= rx_ring->ims_val; fp@2407: if (rx_ring->itr_val) fp@2407: writel(1000000000 / (rx_ring->itr_val * 256), fp@2407: hw->hw_addr + rx_ring->itr_register); fp@2407: else fp@2407: writel(1, hw->hw_addr + rx_ring->itr_register); fp@2407: ivar = E1000_IVAR_INT_ALLOC_VALID | vector; fp@2407: fp@2407: /* Configure Tx vector */ fp@2407: tx_ring->ims_val = E1000_IMS_TXQ0; fp@2407: vector++; fp@2407: if (tx_ring->itr_val) fp@2407: writel(1000000000 / (tx_ring->itr_val * 256), fp@2407: hw->hw_addr + tx_ring->itr_register); fp@2407: else fp@2407: writel(1, hw->hw_addr + tx_ring->itr_register); fp@2407: adapter->eiac_mask |= tx_ring->ims_val; fp@2407: ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8); fp@2407: fp@2407: /* set vector for Other Causes, e.g. link changes */ fp@2407: vector++; fp@2407: ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16); fp@2407: if (rx_ring->itr_val) fp@2407: writel(1000000000 / (rx_ring->itr_val * 256), fp@2407: hw->hw_addr + E1000_EITR_82574(vector)); fp@2407: else fp@2407: writel(1, hw->hw_addr + E1000_EITR_82574(vector)); fp@2407: fp@2407: /* Cause Tx interrupts on every write back */ fp@2407: ivar |= (1 << 31); fp@2407: fp@2407: ew32(IVAR, ivar); fp@2407: fp@2407: /* enable MSI-X PBA support */ fp@2407: ctrl_ext = er32(CTRL_EXT); fp@2407: ctrl_ext |= E1000_CTRL_EXT_PBA_CLR; fp@2407: fp@2407: /* Auto-Mask Other interrupts upon ICR read */ fp@2407: #define E1000_EIAC_MASK_82574 0x01F00000 fp@2407: ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER); fp@2407: ctrl_ext |= E1000_CTRL_EXT_EIAME; fp@2407: ew32(CTRL_EXT, ctrl_ext); fp@2407: e1e_flush(); fp@2407: } fp@2407: fp@2407: void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter) fp@2407: { fp@2407: if (adapter->msix_entries) { fp@2407: pci_disable_msix(adapter->pdev); fp@2407: kfree(adapter->msix_entries); fp@2407: adapter->msix_entries = NULL; fp@2407: } else if (adapter->flags & FLAG_MSI_ENABLED) { fp@2407: pci_disable_msi(adapter->pdev); fp@2407: adapter->flags &= ~FLAG_MSI_ENABLED; fp@2407: } fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_set_interrupt_capability - set MSI or MSI-X if supported fp@2407: * fp@2407: * Attempt to configure interrupts using the best available fp@2407: * capabilities of the hardware and kernel. fp@2407: **/ fp@2407: void e1000e_set_interrupt_capability(struct e1000_adapter *adapter) fp@2407: { fp@2407: int err; fp@2407: int i; fp@2407: fp@2407: switch (adapter->int_mode) { fp@2407: case E1000E_INT_MODE_MSIX: fp@2407: if (adapter->flags & FLAG_HAS_MSIX) { fp@2407: adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */ fp@2407: adapter->msix_entries = kcalloc(adapter->num_vectors, fp@2407: sizeof(struct msix_entry), fp@2407: GFP_KERNEL); fp@2407: if (adapter->msix_entries) { fp@2407: for (i = 0; i < adapter->num_vectors; i++) fp@2407: adapter->msix_entries[i].entry = i; fp@2407: fp@2407: err = pci_enable_msix(adapter->pdev, fp@2407: adapter->msix_entries, fp@2407: adapter->num_vectors); fp@2407: if (err == 0) fp@2407: return; fp@2407: } fp@2407: /* MSI-X failed, so fall through and try MSI */ fp@2407: e_err("Failed to initialize MSI-X interrupts. " fp@2407: "Falling back to MSI interrupts.\n"); fp@2407: e1000e_reset_interrupt_capability(adapter); fp@2407: } fp@2407: adapter->int_mode = E1000E_INT_MODE_MSI; fp@2407: /* Fall through */ fp@2407: case E1000E_INT_MODE_MSI: fp@2407: if (!pci_enable_msi(adapter->pdev)) { fp@2407: adapter->flags |= FLAG_MSI_ENABLED; fp@2407: } else { fp@2407: adapter->int_mode = E1000E_INT_MODE_LEGACY; fp@2407: e_err("Failed to initialize MSI interrupts. Falling " fp@2407: "back to legacy interrupts.\n"); fp@2407: } fp@2407: /* Fall through */ fp@2407: case E1000E_INT_MODE_LEGACY: fp@2407: /* Don't do anything; this is the system default */ fp@2407: break; fp@2407: } fp@2407: fp@2407: /* store the number of vectors being used */ fp@2407: adapter->num_vectors = 1; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_request_msix - Initialize MSI-X interrupts fp@2407: * fp@2407: * e1000_request_msix allocates MSI-X vectors and requests interrupts from the fp@2407: * kernel. fp@2407: **/ fp@2407: static int e1000_request_msix(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: int err = 0, vector = 0; fp@2407: fp@2407: if (strlen(netdev->name) < (IFNAMSIZ - 5)) fp@2407: snprintf(adapter->rx_ring->name, fp@2407: sizeof(adapter->rx_ring->name) - 1, fp@2407: "%s-rx-0", netdev->name); fp@2407: else fp@2407: memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ); fp@2407: err = request_irq(adapter->msix_entries[vector].vector, fp@2407: e1000_intr_msix_rx, 0, adapter->rx_ring->name, fp@2407: netdev); fp@2407: if (err) fp@2407: goto out; fp@2407: adapter->rx_ring->itr_register = E1000_EITR_82574(vector); fp@2407: adapter->rx_ring->itr_val = adapter->itr; fp@2407: vector++; fp@2407: fp@2407: if (strlen(netdev->name) < (IFNAMSIZ - 5)) fp@2407: snprintf(adapter->tx_ring->name, fp@2407: sizeof(adapter->tx_ring->name) - 1, fp@2407: "%s-tx-0", netdev->name); fp@2407: else fp@2407: memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ); fp@2407: err = request_irq(adapter->msix_entries[vector].vector, fp@2407: e1000_intr_msix_tx, 0, adapter->tx_ring->name, fp@2407: netdev); fp@2407: if (err) fp@2407: goto out; fp@2407: adapter->tx_ring->itr_register = E1000_EITR_82574(vector); fp@2407: adapter->tx_ring->itr_val = adapter->itr; fp@2407: vector++; fp@2407: fp@2407: err = request_irq(adapter->msix_entries[vector].vector, fp@2407: e1000_msix_other, 0, netdev->name, netdev); fp@2407: if (err) fp@2407: goto out; fp@2407: fp@2407: e1000_configure_msix(adapter); fp@2407: return 0; fp@2407: out: fp@2407: return err; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_request_irq - initialize interrupts fp@2407: * fp@2407: * Attempts to configure interrupts using the best available fp@2407: * capabilities of the hardware and kernel. fp@2407: **/ fp@2407: static int e1000_request_irq(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: int err; fp@2407: fp@2407: if (adapter->ecdev) fp@2407: return 0; fp@2407: fp@2407: if (adapter->msix_entries) { fp@2407: err = e1000_request_msix(adapter); fp@2407: if (!err) fp@2407: return err; fp@2407: /* fall back to MSI */ fp@2407: e1000e_reset_interrupt_capability(adapter); fp@2407: adapter->int_mode = E1000E_INT_MODE_MSI; fp@2407: e1000e_set_interrupt_capability(adapter); fp@2407: } fp@2407: if (adapter->flags & FLAG_MSI_ENABLED) { fp@2407: err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0, fp@2407: netdev->name, netdev); fp@2407: if (!err) fp@2407: return err; fp@2407: fp@2407: /* fall back to legacy interrupt */ fp@2407: e1000e_reset_interrupt_capability(adapter); fp@2407: adapter->int_mode = E1000E_INT_MODE_LEGACY; fp@2407: } fp@2407: fp@2407: err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED, fp@2407: netdev->name, netdev); fp@2407: if (err) fp@2407: e_err("Unable to allocate interrupt, Error: %d\n", err); fp@2407: fp@2407: return err; fp@2407: } fp@2407: fp@2407: static void e1000_free_irq(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: fp@2407: if (adapter->ecdev) fp@2407: return; fp@2407: fp@2407: if (adapter->msix_entries) { fp@2407: int vector = 0; fp@2407: fp@2407: free_irq(adapter->msix_entries[vector].vector, netdev); fp@2407: vector++; fp@2407: fp@2407: free_irq(adapter->msix_entries[vector].vector, netdev); fp@2407: vector++; fp@2407: fp@2407: /* Other Causes interrupt vector */ fp@2407: free_irq(adapter->msix_entries[vector].vector, netdev); fp@2407: return; fp@2407: } fp@2407: fp@2407: free_irq(adapter->pdev->irq, netdev); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_irq_disable - Mask off interrupt generation on the NIC fp@2407: **/ fp@2407: static void e1000_irq_disable(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: fp@2407: if (adapter->ecdev) fp@2407: return; fp@2407: fp@2407: ew32(IMC, ~0); fp@2407: if (adapter->msix_entries) fp@2407: ew32(EIAC_82574, 0); fp@2407: e1e_flush(); fp@2407: fp@2407: if (adapter->msix_entries) { fp@2407: int i; fp@2407: for (i = 0; i < adapter->num_vectors; i++) fp@2407: synchronize_irq(adapter->msix_entries[i].vector); fp@2407: } else { fp@2407: synchronize_irq(adapter->pdev->irq); fp@2407: } fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_irq_enable - Enable default interrupt generation settings fp@2407: **/ fp@2407: static void e1000_irq_enable(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: fp@2407: if (adapter->ecdev) fp@2407: return; fp@2407: fp@2407: if (adapter->msix_entries) { fp@2407: ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574); fp@2407: ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC); fp@2407: } else { fp@2407: ew32(IMS, IMS_ENABLE_MASK); fp@2407: } fp@2407: e1e_flush(); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_get_hw_control - get control of the h/w from f/w fp@2407: * @adapter: address of board private structure fp@2407: * fp@2407: * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. fp@2407: * For ASF and Pass Through versions of f/w this means that fp@2407: * the driver is loaded. For AMT version (only with 82573) fp@2407: * of the f/w this means that the network i/f is open. fp@2407: **/ fp@2407: void e1000e_get_hw_control(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 ctrl_ext; fp@2407: u32 swsm; fp@2407: fp@2407: /* Let firmware know the driver has taken over */ fp@2407: if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { fp@2407: swsm = er32(SWSM); fp@2407: ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); fp@2407: } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { fp@2407: ctrl_ext = er32(CTRL_EXT); fp@2407: ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); fp@2407: } fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_release_hw_control - release control of the h/w to f/w fp@2407: * @adapter: address of board private structure fp@2407: * fp@2407: * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. fp@2407: * For ASF and Pass Through versions of f/w this means that the fp@2407: * driver is no longer loaded. For AMT version (only with 82573) i fp@2407: * of the f/w this means that the network i/f is closed. fp@2407: * fp@2407: **/ fp@2407: void e1000e_release_hw_control(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 ctrl_ext; fp@2407: u32 swsm; fp@2407: fp@2407: /* Let firmware taken over control of h/w */ fp@2407: if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) { fp@2407: swsm = er32(SWSM); fp@2407: ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); fp@2407: } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) { fp@2407: ctrl_ext = er32(CTRL_EXT); fp@2407: ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); fp@2407: } fp@2407: } fp@2407: fp@2407: /** fp@2407: * @e1000_alloc_ring - allocate memory for a ring structure fp@2407: **/ fp@2407: static int e1000_alloc_ring_dma(struct e1000_adapter *adapter, fp@2407: struct e1000_ring *ring) fp@2407: { fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: fp@2407: ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma, fp@2407: GFP_KERNEL); fp@2407: if (!ring->desc) fp@2407: return -ENOMEM; fp@2407: fp@2407: return 0; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_setup_tx_resources - allocate Tx resources (Descriptors) fp@2407: * @adapter: board private structure fp@2407: * fp@2407: * Return 0 on success, negative on failure fp@2407: **/ fp@2407: int e1000e_setup_tx_resources(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: int err = -ENOMEM, size; fp@2407: fp@2407: size = sizeof(struct e1000_buffer) * tx_ring->count; fp@2407: tx_ring->buffer_info = vzalloc(size); fp@2407: if (!tx_ring->buffer_info) fp@2407: goto err; fp@2407: fp@2407: /* round up to nearest 4K */ fp@2407: tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); fp@2407: tx_ring->size = ALIGN(tx_ring->size, 4096); fp@2407: fp@2407: err = e1000_alloc_ring_dma(adapter, tx_ring); fp@2407: if (err) fp@2407: goto err; fp@2407: fp@2407: tx_ring->next_to_use = 0; fp@2407: tx_ring->next_to_clean = 0; fp@2407: fp@2407: return 0; fp@2407: err: fp@2407: vfree(tx_ring->buffer_info); fp@2407: e_err("Unable to allocate memory for the transmit descriptor ring\n"); fp@2407: return err; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_setup_rx_resources - allocate Rx resources (Descriptors) fp@2407: * @adapter: board private structure fp@2407: * fp@2407: * Returns 0 on success, negative on failure fp@2407: **/ fp@2407: int e1000e_setup_rx_resources(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: struct e1000_buffer *buffer_info; fp@2407: int i, size, desc_len, err = -ENOMEM; fp@2407: fp@2407: size = sizeof(struct e1000_buffer) * rx_ring->count; fp@2407: rx_ring->buffer_info = vzalloc(size); fp@2407: if (!rx_ring->buffer_info) fp@2407: goto err; fp@2407: fp@2407: for (i = 0; i < rx_ring->count; i++) { fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS, fp@2407: sizeof(struct e1000_ps_page), fp@2407: GFP_KERNEL); fp@2407: if (!buffer_info->ps_pages) fp@2407: goto err_pages; fp@2407: } fp@2407: fp@2407: desc_len = sizeof(union e1000_rx_desc_packet_split); fp@2407: fp@2407: /* Round up to nearest 4K */ fp@2407: rx_ring->size = rx_ring->count * desc_len; fp@2407: rx_ring->size = ALIGN(rx_ring->size, 4096); fp@2407: fp@2407: err = e1000_alloc_ring_dma(adapter, rx_ring); fp@2407: if (err) fp@2407: goto err_pages; fp@2407: fp@2407: rx_ring->next_to_clean = 0; fp@2407: rx_ring->next_to_use = 0; fp@2407: rx_ring->rx_skb_top = NULL; fp@2407: fp@2407: return 0; fp@2407: fp@2407: err_pages: fp@2407: for (i = 0; i < rx_ring->count; i++) { fp@2407: buffer_info = &rx_ring->buffer_info[i]; fp@2407: kfree(buffer_info->ps_pages); fp@2407: } fp@2407: err: fp@2407: vfree(rx_ring->buffer_info); fp@2407: e_err("Unable to allocate memory for the receive descriptor ring\n"); fp@2407: return err; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_clean_tx_ring - Free Tx Buffers fp@2407: * @adapter: board private structure fp@2407: **/ fp@2407: static void e1000_clean_tx_ring(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: struct e1000_buffer *buffer_info; fp@2407: unsigned long size; fp@2407: unsigned int i; fp@2407: fp@2407: for (i = 0; i < tx_ring->count; i++) { fp@2407: buffer_info = &tx_ring->buffer_info[i]; fp@2407: e1000_put_txbuf(adapter, buffer_info); fp@2407: } fp@2407: fp@2407: size = sizeof(struct e1000_buffer) * tx_ring->count; fp@2407: memset(tx_ring->buffer_info, 0, size); fp@2407: fp@2407: memset(tx_ring->desc, 0, tx_ring->size); fp@2407: fp@2407: tx_ring->next_to_use = 0; fp@2407: tx_ring->next_to_clean = 0; fp@2407: fp@2407: writel(0, adapter->hw.hw_addr + tx_ring->head); fp@2407: writel(0, adapter->hw.hw_addr + tx_ring->tail); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_free_tx_resources - Free Tx Resources per Queue fp@2407: * @adapter: board private structure fp@2407: * fp@2407: * Free all transmit software resources fp@2407: **/ fp@2407: void e1000e_free_tx_resources(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: fp@2407: e1000_clean_tx_ring(adapter); fp@2407: fp@2407: vfree(tx_ring->buffer_info); fp@2407: tx_ring->buffer_info = NULL; fp@2407: fp@2407: dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, fp@2407: tx_ring->dma); fp@2407: tx_ring->desc = NULL; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_free_rx_resources - Free Rx Resources fp@2407: * @adapter: board private structure fp@2407: * fp@2407: * Free all receive software resources fp@2407: **/ fp@2407: fp@2407: void e1000e_free_rx_resources(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: int i; fp@2407: fp@2407: e1000_clean_rx_ring(adapter); fp@2407: fp@2407: for (i = 0; i < rx_ring->count; i++) fp@2407: kfree(rx_ring->buffer_info[i].ps_pages); fp@2407: fp@2407: vfree(rx_ring->buffer_info); fp@2407: rx_ring->buffer_info = NULL; fp@2407: fp@2407: dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, fp@2407: rx_ring->dma); fp@2407: rx_ring->desc = NULL; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_update_itr - update the dynamic ITR value based on statistics fp@2407: * @adapter: pointer to adapter fp@2407: * @itr_setting: current adapter->itr fp@2407: * @packets: the number of packets during this measurement interval fp@2407: * @bytes: the number of bytes during this measurement interval fp@2407: * fp@2407: * Stores a new ITR value based on packets and byte fp@2407: * counts during the last interrupt. The advantage of per interrupt fp@2407: * computation is faster updates and more accurate ITR for the current fp@2407: * traffic pattern. Constants in this function were computed fp@2407: * based on theoretical maximum wire speed and thresholds were set based fp@2407: * on testing data as well as attempting to minimize response time fp@2407: * while increasing bulk throughput. This functionality is controlled fp@2407: * by the InterruptThrottleRate module parameter. fp@2407: **/ fp@2407: static unsigned int e1000_update_itr(struct e1000_adapter *adapter, fp@2407: u16 itr_setting, int packets, fp@2407: int bytes) fp@2407: { fp@2407: unsigned int retval = itr_setting; fp@2407: fp@2407: if (packets == 0) fp@2407: goto update_itr_done; fp@2407: fp@2407: switch (itr_setting) { fp@2407: case lowest_latency: fp@2407: /* handle TSO and jumbo frames */ fp@2407: if (bytes/packets > 8000) fp@2407: retval = bulk_latency; fp@2407: else if ((packets < 5) && (bytes > 512)) fp@2407: retval = low_latency; fp@2407: break; fp@2407: case low_latency: /* 50 usec aka 20000 ints/s */ fp@2407: if (bytes > 10000) { fp@2407: /* this if handles the TSO accounting */ fp@2407: if (bytes/packets > 8000) fp@2407: retval = bulk_latency; fp@2407: else if ((packets < 10) || ((bytes/packets) > 1200)) fp@2407: retval = bulk_latency; fp@2407: else if ((packets > 35)) fp@2407: retval = lowest_latency; fp@2407: } else if (bytes/packets > 2000) { fp@2407: retval = bulk_latency; fp@2407: } else if (packets <= 2 && bytes < 512) { fp@2407: retval = lowest_latency; fp@2407: } fp@2407: break; fp@2407: case bulk_latency: /* 250 usec aka 4000 ints/s */ fp@2407: if (bytes > 25000) { fp@2407: if (packets > 35) fp@2407: retval = low_latency; fp@2407: } else if (bytes < 6000) { fp@2407: retval = low_latency; fp@2407: } fp@2407: break; fp@2407: } fp@2407: fp@2407: update_itr_done: fp@2407: return retval; fp@2407: } fp@2407: fp@2407: static void e1000_set_itr(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u16 current_itr; fp@2407: u32 new_itr = adapter->itr; fp@2407: fp@2407: /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ fp@2407: if (adapter->link_speed != SPEED_1000) { fp@2407: current_itr = 0; fp@2407: new_itr = 4000; fp@2407: goto set_itr_now; fp@2407: } fp@2407: fp@2407: if (adapter->flags2 & FLAG2_DISABLE_AIM) { fp@2407: new_itr = 0; fp@2407: goto set_itr_now; fp@2407: } fp@2407: fp@2407: adapter->tx_itr = e1000_update_itr(adapter, fp@2407: adapter->tx_itr, fp@2407: adapter->total_tx_packets, fp@2407: adapter->total_tx_bytes); fp@2407: /* conservative mode (itr 3) eliminates the lowest_latency setting */ fp@2407: if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) fp@2407: adapter->tx_itr = low_latency; fp@2407: fp@2407: adapter->rx_itr = e1000_update_itr(adapter, fp@2407: adapter->rx_itr, fp@2407: adapter->total_rx_packets, fp@2407: adapter->total_rx_bytes); fp@2407: /* conservative mode (itr 3) eliminates the lowest_latency setting */ fp@2407: if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) fp@2407: adapter->rx_itr = low_latency; fp@2407: fp@2407: current_itr = max(adapter->rx_itr, adapter->tx_itr); fp@2407: fp@2407: switch (current_itr) { fp@2407: /* counts and packets in update_itr are dependent on these numbers */ fp@2407: case lowest_latency: fp@2407: new_itr = 70000; fp@2407: break; fp@2407: case low_latency: fp@2407: new_itr = 20000; /* aka hwitr = ~200 */ fp@2407: break; fp@2407: case bulk_latency: fp@2407: new_itr = 4000; fp@2407: break; fp@2407: default: fp@2407: break; fp@2407: } fp@2407: fp@2407: set_itr_now: fp@2407: if (new_itr != adapter->itr) { fp@2407: /* fp@2407: * this attempts to bias the interrupt rate towards Bulk fp@2407: * by adding intermediate steps when interrupt rate is fp@2407: * increasing fp@2407: */ fp@2407: new_itr = new_itr > adapter->itr ? fp@2407: min(adapter->itr + (new_itr >> 2), new_itr) : fp@2407: new_itr; fp@2407: adapter->itr = new_itr; fp@2407: adapter->rx_ring->itr_val = new_itr; fp@2407: if (adapter->msix_entries) fp@2407: adapter->rx_ring->set_itr = 1; fp@2407: else fp@2407: if (new_itr) fp@2407: ew32(ITR, 1000000000 / (new_itr * 256)); fp@2407: else fp@2407: ew32(ITR, 0); fp@2407: } fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_alloc_queues - Allocate memory for all rings fp@2407: * @adapter: board private structure to initialize fp@2407: **/ fp@2407: static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) fp@2407: { fp@2407: adapter->tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); fp@2407: if (!adapter->tx_ring) fp@2407: goto err; fp@2407: fp@2407: adapter->rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL); fp@2407: if (!adapter->rx_ring) fp@2407: goto err; fp@2407: fp@2407: return 0; fp@2407: err: fp@2407: e_err("Unable to allocate memory for queues\n"); fp@2407: kfree(adapter->rx_ring); fp@2407: kfree(adapter->tx_ring); fp@2407: return -ENOMEM; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_clean - NAPI Rx polling callback fp@2407: * @napi: struct associated with this polling callback fp@2407: * @budget: amount of packets driver is allowed to process this poll fp@2407: **/ fp@2407: static int e1000_clean(struct napi_struct *napi, int budget) fp@2407: { fp@2407: struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct net_device *poll_dev = adapter->netdev; fp@2407: int tx_cleaned = 1, work_done = 0; fp@2407: fp@2407: adapter = netdev_priv(poll_dev); fp@2407: fp@2407: if (adapter->msix_entries && fp@2407: !(adapter->rx_ring->ims_val & adapter->tx_ring->ims_val)) fp@2407: goto clean_rx; fp@2407: fp@2407: tx_cleaned = e1000_clean_tx_irq(adapter); fp@2407: fp@2407: clean_rx: fp@2407: adapter->clean_rx(adapter, &work_done, budget); fp@2407: fp@2407: if (!tx_cleaned) fp@2407: work_done = budget; fp@2407: fp@2407: /* If budget not fully consumed, exit the polling mode */ fp@2407: if (work_done < budget) { fp@2407: if (adapter->itr_setting & 3) fp@2407: e1000_set_itr(adapter); fp@2407: napi_complete(napi); fp@2407: if (!test_bit(__E1000_DOWN, &adapter->state)) { fp@2407: if (adapter->msix_entries) fp@2407: ew32(IMS, adapter->rx_ring->ims_val); fp@2407: else fp@2407: e1000_irq_enable(adapter); fp@2407: } fp@2407: } fp@2407: fp@2407: return work_done; fp@2407: } fp@2407: fp@2407: static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 vfta, index; fp@2407: fp@2407: /* don't update vlan cookie if already programmed */ fp@2407: if ((adapter->hw.mng_cookie.status & fp@2407: E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && fp@2407: (vid == adapter->mng_vlan_id)) fp@2407: return; fp@2407: fp@2407: /* add VID to filter table */ fp@2407: if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { fp@2407: index = (vid >> 5) & 0x7F; fp@2407: vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); fp@2407: vfta |= (1 << (vid & 0x1F)); fp@2407: hw->mac.ops.write_vfta(hw, index, vfta); fp@2407: } fp@2407: fp@2407: set_bit(vid, adapter->active_vlans); fp@2407: } fp@2407: fp@2407: static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 vfta, index; fp@2407: fp@2407: if ((adapter->hw.mng_cookie.status & fp@2407: E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && fp@2407: (vid == adapter->mng_vlan_id)) { fp@2407: /* release control to f/w */ fp@2407: e1000e_release_hw_control(adapter); fp@2407: return; fp@2407: } fp@2407: fp@2407: /* remove VID from filter table */ fp@2407: if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { fp@2407: index = (vid >> 5) & 0x7F; fp@2407: vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index); fp@2407: vfta &= ~(1 << (vid & 0x1F)); fp@2407: hw->mac.ops.write_vfta(hw, index, vfta); fp@2407: } fp@2407: fp@2407: clear_bit(vid, adapter->active_vlans); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering fp@2407: * @adapter: board private structure to initialize fp@2407: **/ fp@2407: static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 rctl; fp@2407: fp@2407: if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { fp@2407: /* disable VLAN receive filtering */ fp@2407: rctl = er32(RCTL); fp@2407: rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN); fp@2407: ew32(RCTL, rctl); fp@2407: fp@2407: if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { fp@2407: e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); fp@2407: adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; fp@2407: } fp@2407: } fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering fp@2407: * @adapter: board private structure to initialize fp@2407: **/ fp@2407: static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 rctl; fp@2407: fp@2407: if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) { fp@2407: /* enable VLAN receive filtering */ fp@2407: rctl = er32(RCTL); fp@2407: rctl |= E1000_RCTL_VFE; fp@2407: rctl &= ~E1000_RCTL_CFIEN; fp@2407: ew32(RCTL, rctl); fp@2407: } fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping fp@2407: * @adapter: board private structure to initialize fp@2407: **/ fp@2407: static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 ctrl; fp@2407: fp@2407: /* disable VLAN tag insert/strip */ fp@2407: ctrl = er32(CTRL); fp@2407: ctrl &= ~E1000_CTRL_VME; fp@2407: ew32(CTRL, ctrl); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping fp@2407: * @adapter: board private structure to initialize fp@2407: **/ fp@2407: static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 ctrl; fp@2407: fp@2407: /* enable VLAN tag insert/strip */ fp@2407: ctrl = er32(CTRL); fp@2407: ctrl |= E1000_CTRL_VME; fp@2407: ew32(CTRL, ctrl); fp@2407: } fp@2407: fp@2407: static void e1000_update_mng_vlan(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: u16 vid = adapter->hw.mng_cookie.vlan_id; fp@2407: u16 old_vid = adapter->mng_vlan_id; fp@2407: fp@2407: if (adapter->hw.mng_cookie.status & fp@2407: E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { fp@2407: e1000_vlan_rx_add_vid(netdev, vid); fp@2407: adapter->mng_vlan_id = vid; fp@2407: } fp@2407: fp@2407: if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid)) fp@2407: e1000_vlan_rx_kill_vid(netdev, old_vid); fp@2407: } fp@2407: fp@2407: static void e1000_restore_vlan(struct e1000_adapter *adapter) fp@2407: { fp@2407: u16 vid; fp@2407: fp@2407: e1000_vlan_rx_add_vid(adapter->netdev, 0); fp@2407: fp@2407: for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) fp@2407: e1000_vlan_rx_add_vid(adapter->netdev, vid); fp@2407: } fp@2407: fp@2407: static void e1000_init_manageability_pt(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 manc, manc2h, mdef, i, j; fp@2407: fp@2407: if (!(adapter->flags & FLAG_MNG_PT_ENABLED)) fp@2407: return; fp@2407: fp@2407: manc = er32(MANC); fp@2407: fp@2407: /* fp@2407: * enable receiving management packets to the host. this will probably fp@2407: * generate destination unreachable messages from the host OS, but fp@2407: * the packets will be handled on SMBUS fp@2407: */ fp@2407: manc |= E1000_MANC_EN_MNG2HOST; fp@2407: manc2h = er32(MANC2H); fp@2407: fp@2407: switch (hw->mac.type) { fp@2407: default: fp@2407: manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664); fp@2407: break; fp@2407: case e1000_82574: fp@2407: case e1000_82583: fp@2407: /* fp@2407: * Check if IPMI pass-through decision filter already exists; fp@2407: * if so, enable it. fp@2407: */ fp@2407: for (i = 0, j = 0; i < 8; i++) { fp@2407: mdef = er32(MDEF(i)); fp@2407: fp@2407: /* Ignore filters with anything other than IPMI ports */ fp@2407: if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) fp@2407: continue; fp@2407: fp@2407: /* Enable this decision filter in MANC2H */ fp@2407: if (mdef) fp@2407: manc2h |= (1 << i); fp@2407: fp@2407: j |= mdef; fp@2407: } fp@2407: fp@2407: if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664)) fp@2407: break; fp@2407: fp@2407: /* Create new decision filter in an empty filter */ fp@2407: for (i = 0, j = 0; i < 8; i++) fp@2407: if (er32(MDEF(i)) == 0) { fp@2407: ew32(MDEF(i), (E1000_MDEF_PORT_623 | fp@2407: E1000_MDEF_PORT_664)); fp@2407: manc2h |= (1 << 1); fp@2407: j++; fp@2407: break; fp@2407: } fp@2407: fp@2407: if (!j) fp@2407: e_warn("Unable to create IPMI pass-through filter\n"); fp@2407: break; fp@2407: } fp@2407: fp@2407: ew32(MANC2H, manc2h); fp@2407: ew32(MANC, manc); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_configure_tx - Configure Transmit Unit after Reset fp@2407: * @adapter: board private structure fp@2407: * fp@2407: * Configure the Tx unit of the MAC after a reset. fp@2407: **/ fp@2407: static void e1000_configure_tx(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: u64 tdba; fp@2407: u32 tdlen, tctl, tipg, tarc; fp@2407: u32 ipgr1, ipgr2; fp@2407: fp@2407: /* Setup the HW Tx Head and Tail descriptor pointers */ fp@2407: tdba = tx_ring->dma; fp@2407: tdlen = tx_ring->count * sizeof(struct e1000_tx_desc); fp@2407: ew32(TDBAL, (tdba & DMA_BIT_MASK(32))); fp@2407: ew32(TDBAH, (tdba >> 32)); fp@2407: ew32(TDLEN, tdlen); fp@2407: ew32(TDH, 0); fp@2407: ew32(TDT, 0); fp@2407: tx_ring->head = E1000_TDH; fp@2407: tx_ring->tail = E1000_TDT; fp@2407: fp@2407: /* Set the default values for the Tx Inter Packet Gap timer */ fp@2407: tipg = DEFAULT_82543_TIPG_IPGT_COPPER; /* 8 */ fp@2407: ipgr1 = DEFAULT_82543_TIPG_IPGR1; /* 8 */ fp@2407: ipgr2 = DEFAULT_82543_TIPG_IPGR2; /* 6 */ fp@2407: fp@2407: if (adapter->flags & FLAG_TIPG_MEDIUM_FOR_80003ESLAN) fp@2407: ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; /* 7 */ fp@2407: fp@2407: tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; fp@2407: tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; fp@2407: ew32(TIPG, tipg); fp@2407: fp@2407: /* Set the Tx Interrupt Delay register */ fp@2407: ew32(TIDV, adapter->tx_int_delay); fp@2407: /* Tx irq moderation */ fp@2407: ew32(TADV, adapter->tx_abs_int_delay); fp@2407: fp@2407: if (adapter->flags2 & FLAG2_DMA_BURST) { fp@2407: u32 txdctl = er32(TXDCTL(0)); fp@2407: txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH | fp@2407: E1000_TXDCTL_WTHRESH); fp@2407: /* fp@2407: * set up some performance related parameters to encourage the fp@2407: * hardware to use the bus more efficiently in bursts, depends fp@2407: * on the tx_int_delay to be enabled, fp@2407: * wthresh = 5 ==> burst write a cacheline (64 bytes) at a time fp@2407: * hthresh = 1 ==> prefetch when one or more available fp@2407: * pthresh = 0x1f ==> prefetch if internal cache 31 or less fp@2407: * BEWARE: this seems to work but should be considered first if fp@2407: * there are Tx hangs or other Tx related bugs fp@2407: */ fp@2407: txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE; fp@2407: ew32(TXDCTL(0), txdctl); fp@2407: /* erratum work around: set txdctl the same for both queues */ fp@2407: ew32(TXDCTL(1), txdctl); fp@2407: } fp@2407: fp@2407: /* Program the Transmit Control Register */ fp@2407: tctl = er32(TCTL); fp@2407: tctl &= ~E1000_TCTL_CT; fp@2407: tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | fp@2407: (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); fp@2407: fp@2407: if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) { fp@2407: tarc = er32(TARC(0)); fp@2407: /* fp@2407: * set the speed mode bit, we'll clear it if we're not at fp@2407: * gigabit link later fp@2407: */ fp@2407: #define SPEED_MODE_BIT (1 << 21) fp@2407: tarc |= SPEED_MODE_BIT; fp@2407: ew32(TARC(0), tarc); fp@2407: } fp@2407: fp@2407: /* errata: program both queues to unweighted RR */ fp@2407: if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) { fp@2407: tarc = er32(TARC(0)); fp@2407: tarc |= 1; fp@2407: ew32(TARC(0), tarc); fp@2407: tarc = er32(TARC(1)); fp@2407: tarc |= 1; fp@2407: ew32(TARC(1), tarc); fp@2407: } fp@2407: fp@2407: /* Setup Transmit Descriptor Settings for eop descriptor */ fp@2407: adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; fp@2407: fp@2407: /* only set IDE if we are delaying interrupts using the timers */ fp@2407: if (adapter->tx_int_delay) fp@2407: adapter->txd_cmd |= E1000_TXD_CMD_IDE; fp@2407: fp@2407: /* enable Report Status bit */ fp@2407: adapter->txd_cmd |= E1000_TXD_CMD_RS; fp@2407: fp@2407: ew32(TCTL, tctl); fp@2407: fp@2407: e1000e_config_collision_dist(hw); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_setup_rctl - configure the receive control registers fp@2407: * @adapter: Board private structure fp@2407: **/ fp@2407: #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ fp@2407: (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) fp@2407: static void e1000_setup_rctl(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 rctl, rfctl; fp@2407: u32 pages = 0; fp@2407: fp@2407: /* Workaround Si errata on 82579 - configure jumbo frame flow */ fp@2407: if (hw->mac.type == e1000_pch2lan) { fp@2407: s32 ret_val __attribute__ ((unused)); fp@2407: fp@2407: if (adapter->netdev->mtu > ETH_DATA_LEN) fp@2407: ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true); fp@2407: else fp@2407: ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false); fp@2407: fp@2407: if (ret_val) fp@2407: e_dbg("failed to enable jumbo frame workaround mode\n"); fp@2407: } fp@2407: fp@2407: /* Program MC offset vector base */ fp@2407: rctl = er32(RCTL); fp@2407: rctl &= ~(3 << E1000_RCTL_MO_SHIFT); fp@2407: rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | fp@2407: E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | fp@2407: (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); fp@2407: fp@2407: /* Do not Store bad packets */ fp@2407: rctl &= ~E1000_RCTL_SBP; fp@2407: fp@2407: /* Enable Long Packet receive */ fp@2407: if (adapter->netdev->mtu <= ETH_DATA_LEN) fp@2407: rctl &= ~E1000_RCTL_LPE; fp@2407: else fp@2407: rctl |= E1000_RCTL_LPE; fp@2407: fp@2407: /* Some systems expect that the CRC is included in SMBUS traffic. The fp@2407: * hardware strips the CRC before sending to both SMBUS (BMC) and to fp@2407: * host memory when this is enabled fp@2407: */ fp@2407: if (adapter->flags2 & FLAG2_CRC_STRIPPING) fp@2407: rctl |= E1000_RCTL_SECRC; fp@2407: fp@2407: /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */ fp@2407: if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) { fp@2407: u16 phy_data; fp@2407: fp@2407: e1e_rphy(hw, PHY_REG(770, 26), &phy_data); fp@2407: phy_data &= 0xfff8; fp@2407: phy_data |= (1 << 2); fp@2407: e1e_wphy(hw, PHY_REG(770, 26), phy_data); fp@2407: fp@2407: e1e_rphy(hw, 22, &phy_data); fp@2407: phy_data &= 0x0fff; fp@2407: phy_data |= (1 << 14); fp@2407: e1e_wphy(hw, 0x10, 0x2823); fp@2407: e1e_wphy(hw, 0x11, 0x0003); fp@2407: e1e_wphy(hw, 22, phy_data); fp@2407: } fp@2407: fp@2407: /* Setup buffer sizes */ fp@2407: rctl &= ~E1000_RCTL_SZ_4096; fp@2407: rctl |= E1000_RCTL_BSEX; fp@2407: switch (adapter->rx_buffer_len) { fp@2407: case 2048: fp@2407: default: fp@2407: rctl |= E1000_RCTL_SZ_2048; fp@2407: rctl &= ~E1000_RCTL_BSEX; fp@2407: break; fp@2407: case 4096: fp@2407: rctl |= E1000_RCTL_SZ_4096; fp@2407: break; fp@2407: case 8192: fp@2407: rctl |= E1000_RCTL_SZ_8192; fp@2407: break; fp@2407: case 16384: fp@2407: rctl |= E1000_RCTL_SZ_16384; fp@2407: break; fp@2407: } fp@2407: fp@2407: /* Enable Extended Status in all Receive Descriptors */ fp@2407: rfctl = er32(RFCTL); fp@2407: rfctl |= E1000_RFCTL_EXTEN; fp@2407: fp@2407: /* fp@2407: * 82571 and greater support packet-split where the protocol fp@2407: * header is placed in skb->data and the packet data is fp@2407: * placed in pages hanging off of skb_shinfo(skb)->nr_frags. fp@2407: * In the case of a non-split, skb->data is linearly filled, fp@2407: * followed by the page buffers. Therefore, skb->data is fp@2407: * sized to hold the largest protocol header. fp@2407: * fp@2407: * allocations using alloc_page take too long for regular MTU fp@2407: * so only enable packet split for jumbo frames fp@2407: * fp@2407: * Using pages when the page size is greater than 16k wastes fp@2407: * a lot of memory, since we allocate 3 pages at all times fp@2407: * per packet. fp@2407: */ fp@2407: pages = PAGE_USE_COUNT(adapter->netdev->mtu); fp@2407: if (!(adapter->flags & FLAG_HAS_ERT) && (pages <= 3) && fp@2407: (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE)) fp@2407: adapter->rx_ps_pages = pages; fp@2407: else fp@2407: adapter->rx_ps_pages = 0; fp@2407: fp@2407: if (adapter->rx_ps_pages) { fp@2407: u32 psrctl = 0; fp@2407: fp@2407: /* fp@2407: * disable packet split support for IPv6 extension headers, fp@2407: * because some malformed IPv6 headers can hang the Rx fp@2407: */ fp@2407: rfctl |= (E1000_RFCTL_IPV6_EX_DIS | fp@2407: E1000_RFCTL_NEW_IPV6_EXT_DIS); fp@2407: fp@2407: /* Enable Packet split descriptors */ fp@2407: rctl |= E1000_RCTL_DTYP_PS; fp@2407: fp@2407: psrctl |= adapter->rx_ps_bsize0 >> fp@2407: E1000_PSRCTL_BSIZE0_SHIFT; fp@2407: fp@2407: switch (adapter->rx_ps_pages) { fp@2407: case 3: fp@2407: psrctl |= PAGE_SIZE << fp@2407: E1000_PSRCTL_BSIZE3_SHIFT; fp@2407: case 2: fp@2407: psrctl |= PAGE_SIZE << fp@2407: E1000_PSRCTL_BSIZE2_SHIFT; fp@2407: case 1: fp@2407: psrctl |= PAGE_SIZE >> fp@2407: E1000_PSRCTL_BSIZE1_SHIFT; fp@2407: break; fp@2407: } fp@2407: fp@2407: ew32(PSRCTL, psrctl); fp@2407: } fp@2407: fp@2407: ew32(RFCTL, rfctl); fp@2407: ew32(RCTL, rctl); fp@2407: /* just started the receive unit, no need to restart */ fp@2407: adapter->flags &= ~FLAG_RX_RESTART_NOW; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_configure_rx - Configure Receive Unit after Reset fp@2407: * @adapter: board private structure fp@2407: * fp@2407: * Configure the Rx unit of the MAC after a reset. fp@2407: **/ fp@2407: static void e1000_configure_rx(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct e1000_ring *rx_ring = adapter->rx_ring; fp@2407: u64 rdba; fp@2407: u32 rdlen, rctl, rxcsum, ctrl_ext; fp@2407: fp@2407: if (adapter->rx_ps_pages) { fp@2407: /* this is a 32 byte descriptor */ fp@2407: rdlen = rx_ring->count * fp@2407: sizeof(union e1000_rx_desc_packet_split); fp@2407: adapter->clean_rx = e1000_clean_rx_irq_ps; fp@2407: adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; fp@2407: } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) { fp@2407: rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); fp@2407: adapter->clean_rx = e1000_clean_jumbo_rx_irq; fp@2407: adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; fp@2407: } else { fp@2407: rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended); fp@2407: adapter->clean_rx = e1000_clean_rx_irq; fp@2407: adapter->alloc_rx_buf = e1000_alloc_rx_buffers; fp@2407: } fp@2407: fp@2407: /* disable receives while setting up the descriptors */ fp@2407: rctl = er32(RCTL); fp@2407: if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) fp@2407: ew32(RCTL, rctl & ~E1000_RCTL_EN); fp@2407: e1e_flush(); fp@2407: usleep_range(10000, 20000); fp@2407: fp@2407: if (adapter->flags2 & FLAG2_DMA_BURST) { fp@2407: /* fp@2407: * set the writeback threshold (only takes effect if the RDTR fp@2407: * is set). set GRAN=1 and write back up to 0x4 worth, and fp@2407: * enable prefetching of 0x20 Rx descriptors fp@2407: * granularity = 01 fp@2407: * wthresh = 04, fp@2407: * hthresh = 04, fp@2407: * pthresh = 0x20 fp@2407: */ fp@2407: ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE); fp@2407: ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE); fp@2407: fp@2407: /* fp@2407: * override the delay timers for enabling bursting, only if fp@2407: * the value was not set by the user via module options fp@2407: */ fp@2407: if (adapter->rx_int_delay == DEFAULT_RDTR) fp@2407: adapter->rx_int_delay = BURST_RDTR; fp@2407: if (adapter->rx_abs_int_delay == DEFAULT_RADV) fp@2407: adapter->rx_abs_int_delay = BURST_RADV; fp@2407: } fp@2407: fp@2407: /* set the Receive Delay Timer Register */ fp@2407: ew32(RDTR, adapter->rx_int_delay); fp@2407: fp@2407: /* irq moderation */ fp@2407: ew32(RADV, adapter->rx_abs_int_delay); fp@2407: if ((adapter->itr_setting != 0) && (adapter->itr != 0)) fp@2407: ew32(ITR, 1000000000 / (adapter->itr * 256)); fp@2407: fp@2407: ctrl_ext = er32(CTRL_EXT); fp@2407: /* Auto-Mask interrupts upon ICR access */ fp@2407: ctrl_ext |= E1000_CTRL_EXT_IAME; fp@2407: ew32(IAM, 0xffffffff); fp@2407: ew32(CTRL_EXT, ctrl_ext); fp@2407: e1e_flush(); fp@2407: fp@2407: /* fp@2407: * Setup the HW Rx Head and Tail Descriptor Pointers and fp@2407: * the Base and Length of the Rx Descriptor Ring fp@2407: */ fp@2407: rdba = rx_ring->dma; fp@2407: ew32(RDBAL, (rdba & DMA_BIT_MASK(32))); fp@2407: ew32(RDBAH, (rdba >> 32)); fp@2407: ew32(RDLEN, rdlen); fp@2407: ew32(RDH, 0); fp@2407: ew32(RDT, 0); fp@2407: rx_ring->head = E1000_RDH; fp@2407: rx_ring->tail = E1000_RDT; fp@2407: fp@2407: /* Enable Receive Checksum Offload for TCP and UDP */ fp@2407: rxcsum = er32(RXCSUM); fp@2407: if (adapter->netdev->features & NETIF_F_RXCSUM) { fp@2407: rxcsum |= E1000_RXCSUM_TUOFL; fp@2407: fp@2407: /* fp@2407: * IPv4 payload checksum for UDP fragments must be fp@2407: * used in conjunction with packet-split. fp@2407: */ fp@2407: if (adapter->rx_ps_pages) fp@2407: rxcsum |= E1000_RXCSUM_IPPCSE; fp@2407: } else { fp@2407: rxcsum &= ~E1000_RXCSUM_TUOFL; fp@2407: /* no need to clear IPPCSE as it defaults to 0 */ fp@2407: } fp@2407: ew32(RXCSUM, rxcsum); fp@2407: fp@2407: /* fp@2407: * Enable early receives on supported devices, only takes effect when fp@2407: * packet size is equal or larger than the specified value (in 8 byte fp@2407: * units), e.g. using jumbo frames when setting to E1000_ERT_2048 fp@2407: */ fp@2407: if ((adapter->flags & FLAG_HAS_ERT) || fp@2407: (adapter->hw.mac.type == e1000_pch2lan)) { fp@2407: if (adapter->netdev->mtu > ETH_DATA_LEN) { fp@2407: u32 rxdctl = er32(RXDCTL(0)); fp@2407: ew32(RXDCTL(0), rxdctl | 0x3); fp@2407: if (adapter->flags & FLAG_HAS_ERT) fp@2407: ew32(ERT, E1000_ERT_2048 | (1 << 13)); fp@2407: /* fp@2407: * With jumbo frames and early-receive enabled, fp@2407: * excessive C-state transition latencies result in fp@2407: * dropped transactions. fp@2407: */ fp@2407: pm_qos_update_request(&adapter->netdev->pm_qos_req, 55); fp@2407: } else { fp@2407: pm_qos_update_request(&adapter->netdev->pm_qos_req, fp@2407: PM_QOS_DEFAULT_VALUE); fp@2407: } fp@2407: } fp@2407: fp@2407: /* Enable Receives */ fp@2407: ew32(RCTL, rctl); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_update_mc_addr_list - Update Multicast addresses fp@2407: * @hw: pointer to the HW structure fp@2407: * @mc_addr_list: array of multicast addresses to program fp@2407: * @mc_addr_count: number of multicast addresses to program fp@2407: * fp@2407: * Updates the Multicast Table Array. fp@2407: * The caller must have a packed mc_addr_list of multicast addresses. fp@2407: **/ fp@2407: static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list, fp@2407: u32 mc_addr_count) fp@2407: { fp@2407: hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_set_multi - Multicast and Promiscuous mode set fp@2407: * @netdev: network interface device structure fp@2407: * fp@2407: * The set_multi entry point is called whenever the multicast address fp@2407: * list or the network interface flags are updated. This routine is fp@2407: * responsible for configuring the hardware for proper multicast, fp@2407: * promiscuous mode, and all-multi behavior. fp@2407: **/ fp@2407: static void e1000_set_multi(struct net_device *netdev) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct netdev_hw_addr *ha; fp@2407: u8 *mta_list; fp@2407: u32 rctl; fp@2407: fp@2407: /* Check for Promiscuous and All Multicast modes */ fp@2407: fp@2407: rctl = er32(RCTL); fp@2407: fp@2407: if (netdev->flags & IFF_PROMISC) { fp@2407: rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); fp@2407: rctl &= ~E1000_RCTL_VFE; fp@2407: /* Do not hardware filter VLANs in promisc mode */ fp@2407: e1000e_vlan_filter_disable(adapter); fp@2407: } else { fp@2407: if (netdev->flags & IFF_ALLMULTI) { fp@2407: rctl |= E1000_RCTL_MPE; fp@2407: rctl &= ~E1000_RCTL_UPE; fp@2407: } else { fp@2407: rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); fp@2407: } fp@2407: e1000e_vlan_filter_enable(adapter); fp@2407: } fp@2407: fp@2407: ew32(RCTL, rctl); fp@2407: fp@2407: if (!netdev_mc_empty(netdev)) { fp@2407: int i = 0; fp@2407: fp@2407: mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC); fp@2407: if (!mta_list) fp@2407: return; fp@2407: fp@2407: /* prepare a packed array of only addresses. */ fp@2407: netdev_for_each_mc_addr(ha, netdev) fp@2407: memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); fp@2407: fp@2407: e1000_update_mc_addr_list(hw, mta_list, i); fp@2407: kfree(mta_list); fp@2407: } else { fp@2407: /* fp@2407: * if we're called from probe, we might not have fp@2407: * anything to do here, so clear out the list fp@2407: */ fp@2407: e1000_update_mc_addr_list(hw, NULL, 0); fp@2407: } fp@2407: fp@2407: if (netdev->features & NETIF_F_HW_VLAN_RX) fp@2407: e1000e_vlan_strip_enable(adapter); fp@2407: else fp@2407: e1000e_vlan_strip_disable(adapter); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_configure - configure the hardware for Rx and Tx fp@2407: * @adapter: private board structure fp@2407: **/ fp@2407: static void e1000_configure(struct e1000_adapter *adapter) fp@2407: { fp@2407: e1000_set_multi(adapter->netdev); fp@2407: fp@2407: e1000_restore_vlan(adapter); fp@2407: e1000_init_manageability_pt(adapter); fp@2407: fp@2407: e1000_configure_tx(adapter); fp@2407: e1000_setup_rctl(adapter); fp@2407: e1000_configure_rx(adapter); fp@2407: if (adapter->ecdev) { fp@2407: adapter->alloc_rx_buf(adapter, adapter->rx_ring->count, GFP_KERNEL); fp@2407: } else { fp@2407: adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring), fp@2407: GFP_KERNEL); fp@2407: } fp@2407: fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_power_up_phy - restore link in case the phy was powered down fp@2407: * @adapter: address of board private structure fp@2407: * fp@2407: * The phy may be powered down to save power and turn off link when the fp@2407: * driver is unloaded and wake on lan is not enabled (among others) fp@2407: * *** this routine MUST be followed by a call to e1000e_reset *** fp@2407: **/ fp@2407: void e1000e_power_up_phy(struct e1000_adapter *adapter) fp@2407: { fp@2407: if (adapter->hw.phy.ops.power_up) fp@2407: adapter->hw.phy.ops.power_up(&adapter->hw); fp@2407: fp@2407: adapter->hw.mac.ops.setup_link(&adapter->hw); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_power_down_phy - Power down the PHY fp@2407: * fp@2407: * Power down the PHY so no link is implied when interface is down. fp@2407: * The PHY cannot be powered down if management or WoL is active. fp@2407: */ fp@2407: static void e1000_power_down_phy(struct e1000_adapter *adapter) fp@2407: { fp@2407: /* WoL is enabled */ fp@2407: if (adapter->wol) fp@2407: return; fp@2407: fp@2407: if (adapter->hw.phy.ops.power_down) fp@2407: adapter->hw.phy.ops.power_down(&adapter->hw); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_reset - bring the hardware into a known good state fp@2407: * fp@2407: * This function boots the hardware and enables some settings that fp@2407: * require a configuration cycle of the hardware - those cannot be fp@2407: * set/changed during runtime. After reset the device needs to be fp@2407: * properly configured for Rx, Tx etc. fp@2407: */ fp@2407: void e1000e_reset(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_mac_info *mac = &adapter->hw.mac; fp@2407: struct e1000_fc_info *fc = &adapter->hw.fc; fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 tx_space, min_tx_space, min_rx_space; fp@2407: u32 pba = adapter->pba; fp@2407: u16 hwm; fp@2407: fp@2407: /* reset Packet Buffer Allocation to default */ fp@2407: ew32(PBA, pba); fp@2407: fp@2407: if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { fp@2407: /* fp@2407: * To maintain wire speed transmits, the Tx FIFO should be fp@2407: * large enough to accommodate two full transmit packets, fp@2407: * rounded up to the next 1KB and expressed in KB. Likewise, fp@2407: * the Rx FIFO should be large enough to accommodate at least fp@2407: * one full receive packet and is similarly rounded up and fp@2407: * expressed in KB. fp@2407: */ fp@2407: pba = er32(PBA); fp@2407: /* upper 16 bits has Tx packet buffer allocation size in KB */ fp@2407: tx_space = pba >> 16; fp@2407: /* lower 16 bits has Rx packet buffer allocation size in KB */ fp@2407: pba &= 0xffff; fp@2407: /* fp@2407: * the Tx fifo also stores 16 bytes of information about the Tx fp@2407: * but don't include ethernet FCS because hardware appends it fp@2407: */ fp@2407: min_tx_space = (adapter->max_frame_size + fp@2407: sizeof(struct e1000_tx_desc) - fp@2407: ETH_FCS_LEN) * 2; fp@2407: min_tx_space = ALIGN(min_tx_space, 1024); fp@2407: min_tx_space >>= 10; fp@2407: /* software strips receive CRC, so leave room for it */ fp@2407: min_rx_space = adapter->max_frame_size; fp@2407: min_rx_space = ALIGN(min_rx_space, 1024); fp@2407: min_rx_space >>= 10; fp@2407: fp@2407: /* fp@2407: * If current Tx allocation is less than the min Tx FIFO size, fp@2407: * and the min Tx FIFO size is less than the current Rx FIFO fp@2407: * allocation, take space away from current Rx allocation fp@2407: */ fp@2407: if ((tx_space < min_tx_space) && fp@2407: ((min_tx_space - tx_space) < pba)) { fp@2407: pba -= min_tx_space - tx_space; fp@2407: fp@2407: /* fp@2407: * if short on Rx space, Rx wins and must trump Tx fp@2407: * adjustment or use Early Receive if available fp@2407: */ fp@2407: if ((pba < min_rx_space) && fp@2407: (!(adapter->flags & FLAG_HAS_ERT))) fp@2407: /* ERT enabled in e1000_configure_rx */ fp@2407: pba = min_rx_space; fp@2407: } fp@2407: fp@2407: ew32(PBA, pba); fp@2407: } fp@2407: fp@2407: /* fp@2407: * flow control settings fp@2407: * fp@2407: * The high water mark must be low enough to fit one full frame fp@2407: * (or the size used for early receive) above it in the Rx FIFO. fp@2407: * Set it to the lower of: fp@2407: * - 90% of the Rx FIFO size, and fp@2407: * - the full Rx FIFO size minus the early receive size (for parts fp@2407: * with ERT support assuming ERT set to E1000_ERT_2048), or fp@2407: * - the full Rx FIFO size minus one full frame fp@2407: */ fp@2407: if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME) fp@2407: fc->pause_time = 0xFFFF; fp@2407: else fp@2407: fc->pause_time = E1000_FC_PAUSE_TIME; fp@2407: fc->send_xon = 1; fp@2407: fc->current_mode = fc->requested_mode; fp@2407: fp@2407: switch (hw->mac.type) { fp@2407: default: fp@2407: if ((adapter->flags & FLAG_HAS_ERT) && fp@2407: (adapter->netdev->mtu > ETH_DATA_LEN)) fp@2407: hwm = min(((pba << 10) * 9 / 10), fp@2407: ((pba << 10) - (E1000_ERT_2048 << 3))); fp@2407: else fp@2407: hwm = min(((pba << 10) * 9 / 10), fp@2407: ((pba << 10) - adapter->max_frame_size)); fp@2407: fp@2407: fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */ fp@2407: fc->low_water = fc->high_water - 8; fp@2407: break; fp@2407: case e1000_pchlan: fp@2407: /* fp@2407: * Workaround PCH LOM adapter hangs with certain network fp@2407: * loads. If hangs persist, try disabling Tx flow control. fp@2407: */ fp@2407: if (adapter->netdev->mtu > ETH_DATA_LEN) { fp@2407: fc->high_water = 0x3500; fp@2407: fc->low_water = 0x1500; fp@2407: } else { fp@2407: fc->high_water = 0x5000; fp@2407: fc->low_water = 0x3000; fp@2407: } fp@2407: fc->refresh_time = 0x1000; fp@2407: break; fp@2407: case e1000_pch2lan: fp@2407: fc->high_water = 0x05C20; fp@2407: fc->low_water = 0x05048; fp@2407: fc->pause_time = 0x0650; fp@2407: fc->refresh_time = 0x0400; fp@2407: if (adapter->netdev->mtu > ETH_DATA_LEN) { fp@2407: pba = 14; fp@2407: ew32(PBA, pba); fp@2407: } fp@2407: break; fp@2407: } fp@2407: fp@2407: /* fp@2407: * Disable Adaptive Interrupt Moderation if 2 full packets cannot fp@2407: * fit in receive buffer and early-receive not supported. fp@2407: */ fp@2407: if (adapter->itr_setting & 0x3) { fp@2407: if (((adapter->max_frame_size * 2) > (pba << 10)) && fp@2407: !(adapter->flags & FLAG_HAS_ERT)) { fp@2407: if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) { fp@2407: dev_info(&adapter->pdev->dev, fp@2407: "Interrupt Throttle Rate turned off\n"); fp@2407: adapter->flags2 |= FLAG2_DISABLE_AIM; fp@2407: ew32(ITR, 0); fp@2407: } fp@2407: } else if (adapter->flags2 & FLAG2_DISABLE_AIM) { fp@2407: dev_info(&adapter->pdev->dev, fp@2407: "Interrupt Throttle Rate turned on\n"); fp@2407: adapter->flags2 &= ~FLAG2_DISABLE_AIM; fp@2407: adapter->itr = 20000; fp@2407: ew32(ITR, 1000000000 / (adapter->itr * 256)); fp@2407: } fp@2407: } fp@2407: fp@2407: /* Allow time for pending master requests to run */ fp@2407: mac->ops.reset_hw(hw); fp@2407: fp@2407: /* fp@2407: * For parts with AMT enabled, let the firmware know fp@2407: * that the network interface is in control fp@2407: */ fp@2407: if (adapter->flags & FLAG_HAS_AMT) fp@2407: e1000e_get_hw_control(adapter); fp@2407: fp@2407: ew32(WUC, 0); fp@2407: fp@2407: if (mac->ops.init_hw(hw)) fp@2407: e_err("Hardware Error\n"); fp@2407: fp@2407: e1000_update_mng_vlan(adapter); fp@2407: fp@2407: /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ fp@2407: ew32(VET, ETH_P_8021Q); fp@2407: fp@2407: e1000e_reset_adaptive(hw); fp@2407: fp@2407: if (!netif_running(adapter->netdev) && fp@2407: !test_bit(__E1000_TESTING, &adapter->state)) { fp@2407: e1000_power_down_phy(adapter); fp@2407: return; fp@2407: } fp@2407: fp@2407: e1000_get_phy_info(hw); fp@2407: fp@2407: if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && fp@2407: !(adapter->flags & FLAG_SMART_POWER_DOWN)) { fp@2407: u16 phy_data = 0; fp@2407: /* fp@2407: * speed up time to link by disabling smart power down, ignore fp@2407: * the return value of this function because there is nothing fp@2407: * different we would do if it failed fp@2407: */ fp@2407: e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); fp@2407: phy_data &= ~IGP02E1000_PM_SPD; fp@2407: e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); fp@2407: } fp@2407: } fp@2407: fp@2407: int e1000e_up(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: fp@2407: /* hardware has been reset, we need to reload some things */ fp@2407: e1000_configure(adapter); fp@2407: fp@2407: clear_bit(__E1000_DOWN, &adapter->state); fp@2407: fp@2407: if (!adapter->ecdev) { fp@2407: napi_enable(&adapter->napi); fp@2407: } fp@2496: fp@2407: if (adapter->msix_entries) fp@2407: e1000_configure_msix(adapter); fp@2496: fp@2407: if (!adapter->ecdev) { fp@2407: e1000_irq_enable(adapter); fp@2407: fp@2496: netif_start_queue(adapter->netdev); fp@2407: fp@2407: /* fire a link change interrupt to start the watchdog */ fp@2407: if (adapter->msix_entries) fp@2407: ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); fp@2407: else fp@2407: ew32(ICS, E1000_ICS_LSC); fp@2407: } fp@2407: fp@2407: return 0; fp@2407: } fp@2407: fp@2407: static void e1000e_flush_descriptors(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: fp@2407: if (!(adapter->flags2 & FLAG2_DMA_BURST)) fp@2407: return; fp@2407: fp@2407: /* flush pending descriptor writebacks to memory */ fp@2407: ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD); fp@2407: ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD); fp@2407: fp@2407: /* execute the writes immediately */ fp@2407: e1e_flush(); fp@2407: } fp@2407: fp@2407: static void e1000e_update_stats(struct e1000_adapter *adapter); fp@2407: fp@2407: void e1000e_down(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 tctl, rctl; fp@2407: fp@2407: /* fp@2407: * signal that we're down so the interrupt handler does not fp@2407: * reschedule our watchdog timer fp@2407: */ fp@2407: set_bit(__E1000_DOWN, &adapter->state); fp@2407: fp@2407: /* disable receives in the hardware */ fp@2407: rctl = er32(RCTL); fp@2407: if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) fp@2407: ew32(RCTL, rctl & ~E1000_RCTL_EN); fp@2407: /* flush and sleep below */ fp@2407: fp@2421: if (!adapter->ecdev) fp@2407: netif_stop_queue(netdev); fp@2407: fp@2407: /* disable transmits in the hardware */ fp@2407: tctl = er32(TCTL); fp@2407: tctl &= ~E1000_TCTL_EN; fp@2407: ew32(TCTL, tctl); fp@2407: fp@2407: /* flush both disables and wait for them to finish */ fp@2407: e1e_flush(); fp@2407: usleep_range(10000, 20000); fp@2407: fp@2407: if (!adapter->ecdev) { fp@2407: napi_disable(&adapter->napi); fp@2407: e1000_irq_disable(adapter); fp@2407: del_timer_sync(&adapter->watchdog_timer); fp@2407: del_timer_sync(&adapter->phy_info_timer); fp@2407: } fp@2407: fp@2407: if (adapter->ecdev) { fp@2407: ecdev_set_link(adapter->ecdev, 0); fp@2407: } else { fp@2407: netif_carrier_off(netdev); fp@2407: } fp@2407: spin_lock(&adapter->stats64_lock); fp@2407: e1000e_update_stats(adapter); fp@2407: spin_unlock(&adapter->stats64_lock); fp@2407: fp@2407: e1000e_flush_descriptors(adapter); fp@2407: e1000_clean_tx_ring(adapter); fp@2407: e1000_clean_rx_ring(adapter); fp@2407: fp@2407: adapter->link_speed = 0; fp@2407: adapter->link_duplex = 0; fp@2407: fp@2407: if (!pci_channel_offline(adapter->pdev)) fp@2407: e1000e_reset(adapter); fp@2407: fp@2407: /* fp@2407: * TODO: for power management, we could drop the link and fp@2407: * pci_disable_device here. fp@2407: */ fp@2407: } fp@2407: fp@2407: void e1000e_reinit_locked(struct e1000_adapter *adapter) fp@2407: { fp@2407: might_sleep(); fp@2407: while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) fp@2407: usleep_range(1000, 2000); fp@2407: e1000e_down(adapter); fp@2407: e1000e_up(adapter); fp@2407: clear_bit(__E1000_RESETTING, &adapter->state); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_sw_init - Initialize general software structures (struct e1000_adapter) fp@2407: * @adapter: board private structure to initialize fp@2407: * fp@2407: * e1000_sw_init initializes the Adapter private data structure. fp@2407: * Fields are initialized based on PCI device information and fp@2407: * OS network device settings (MTU size). fp@2407: **/ fp@2407: static int __devinit e1000_sw_init(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: fp@2407: adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN; fp@2407: adapter->rx_ps_bsize0 = 128; fp@2407: adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; fp@2407: adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; fp@2407: fp@2407: spin_lock_init(&adapter->stats64_lock); fp@2407: fp@2407: e1000e_set_interrupt_capability(adapter); fp@2407: fp@2407: if (e1000_alloc_queues(adapter)) fp@2407: return -ENOMEM; fp@2407: fp@2407: /* Explicitly disable IRQ since the NIC can be in any state. */ fp@2407: e1000_irq_disable(adapter); fp@2407: fp@2407: set_bit(__E1000_DOWN, &adapter->state); fp@2407: return 0; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_intr_msi_test - Interrupt Handler fp@2407: * @irq: interrupt number fp@2407: * @data: pointer to a network interface device structure fp@2407: **/ fp@2407: static irqreturn_t e1000_intr_msi_test(int irq, void *data) fp@2407: { fp@2407: struct net_device *netdev = data; fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 icr = er32(ICR); fp@2407: fp@2407: e_dbg("icr is %08X\n", icr); fp@2407: if (icr & E1000_ICR_RXSEQ) { fp@2407: adapter->flags &= ~FLAG_MSI_TEST_FAILED; fp@2407: wmb(); fp@2407: } fp@2407: fp@2407: return IRQ_HANDLED; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_test_msi_interrupt - Returns 0 for successful test fp@2407: * @adapter: board private struct fp@2407: * fp@2407: * code flow taken from tg3.c fp@2407: **/ fp@2407: static int e1000_test_msi_interrupt(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: int err; fp@2407: fp@2407: /* poll_enable hasn't been called yet, so don't need disable */ fp@2407: /* clear any pending events */ fp@2407: er32(ICR); fp@2407: fp@2407: /* free the real vector and request a test handler */ fp@2407: e1000_free_irq(adapter); fp@2407: e1000e_reset_interrupt_capability(adapter); fp@2407: fp@2407: /* Assume that the test fails, if it succeeds then the test fp@2407: * MSI irq handler will unset this flag */ fp@2407: adapter->flags |= FLAG_MSI_TEST_FAILED; fp@2407: fp@2407: err = pci_enable_msi(adapter->pdev); fp@2407: if (err) fp@2407: goto msi_test_failed; fp@2407: fp@2407: err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0, fp@2407: netdev->name, netdev); fp@2407: if (err) { fp@2407: pci_disable_msi(adapter->pdev); fp@2407: goto msi_test_failed; fp@2407: } fp@2407: fp@2407: wmb(); fp@2407: fp@2407: e1000_irq_enable(adapter); fp@2407: fp@2407: /* fire an unusual interrupt on the test handler */ fp@2407: ew32(ICS, E1000_ICS_RXSEQ); fp@2407: e1e_flush(); fp@2407: msleep(50); fp@2407: fp@2407: e1000_irq_disable(adapter); fp@2407: fp@2407: rmb(); fp@2407: fp@2407: if (adapter->flags & FLAG_MSI_TEST_FAILED) { fp@2407: adapter->int_mode = E1000E_INT_MODE_LEGACY; fp@2407: e_info("MSI interrupt test failed, using legacy interrupt.\n"); fp@2407: } else fp@2407: e_dbg("MSI interrupt test succeeded!\n"); fp@2407: fp@2407: free_irq(adapter->pdev->irq, netdev); fp@2407: pci_disable_msi(adapter->pdev); fp@2407: fp@2407: msi_test_failed: fp@2407: e1000e_set_interrupt_capability(adapter); fp@2407: return e1000_request_irq(adapter); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored fp@2407: * @adapter: board private struct fp@2407: * fp@2407: * code flow taken from tg3.c, called with e1000 interrupts disabled. fp@2407: **/ fp@2407: static int e1000_test_msi(struct e1000_adapter *adapter) fp@2407: { fp@2407: int err; fp@2407: u16 pci_cmd; fp@2407: fp@2407: if (!(adapter->flags & FLAG_MSI_ENABLED)) fp@2407: return 0; fp@2407: fp@2407: /* disable SERR in case the MSI write causes a master abort */ fp@2407: pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); fp@2407: if (pci_cmd & PCI_COMMAND_SERR) fp@2407: pci_write_config_word(adapter->pdev, PCI_COMMAND, fp@2407: pci_cmd & ~PCI_COMMAND_SERR); fp@2407: fp@2407: err = e1000_test_msi_interrupt(adapter); fp@2407: fp@2407: /* re-enable SERR */ fp@2407: if (pci_cmd & PCI_COMMAND_SERR) { fp@2407: pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd); fp@2407: pci_cmd |= PCI_COMMAND_SERR; fp@2407: pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd); fp@2407: } fp@2407: fp@2407: return err; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_open - Called when a network interface is made active fp@2407: * @netdev: network interface device structure fp@2407: * fp@2407: * Returns 0 on success, negative value on failure fp@2407: * fp@2407: * The open entry point is called when a network interface is made fp@2407: * active by the system (IFF_UP). At this point all resources needed fp@2407: * for transmit and receive operations are allocated, the interrupt fp@2407: * handler is registered with the OS, the watchdog timer is started, fp@2407: * and the stack is notified that the interface is ready. fp@2407: **/ fp@2407: static int e1000_open(struct net_device *netdev) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: int err; fp@2407: fp@2407: /* disallow open during test */ fp@2407: if (test_bit(__E1000_TESTING, &adapter->state)) fp@2407: return -EBUSY; fp@2407: fp@2407: pm_runtime_get_sync(&pdev->dev); fp@2407: fp@2407: if (adapter->ecdev) { fp@2407: ecdev_set_link(adapter->ecdev, 0); fp@2407: } else { fp@2407: netif_carrier_off(netdev); fp@2407: } fp@2407: fp@2407: /* allocate transmit descriptors */ fp@2407: err = e1000e_setup_tx_resources(adapter); fp@2407: if (err) fp@2407: goto err_setup_tx; fp@2407: fp@2407: /* allocate receive descriptors */ fp@2407: err = e1000e_setup_rx_resources(adapter); fp@2407: if (err) fp@2407: goto err_setup_rx; fp@2407: fp@2407: /* fp@2407: * If AMT is enabled, let the firmware know that the network fp@2407: * interface is now open and reset the part to a known state. fp@2407: */ fp@2407: if (adapter->flags & FLAG_HAS_AMT) { fp@2407: e1000e_get_hw_control(adapter); fp@2407: e1000e_reset(adapter); fp@2407: } fp@2407: fp@2407: e1000e_power_up_phy(adapter); fp@2407: fp@2407: adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; fp@2407: if ((adapter->hw.mng_cookie.status & fp@2407: E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) fp@2407: e1000_update_mng_vlan(adapter); fp@2407: fp@2407: /* DMA latency requirement to workaround early-receive/jumbo issue */ fp@2407: if ((adapter->flags & FLAG_HAS_ERT) || fp@2407: (adapter->hw.mac.type == e1000_pch2lan)) fp@2407: pm_qos_add_request(&adapter->netdev->pm_qos_req, fp@2407: PM_QOS_CPU_DMA_LATENCY, fp@2407: PM_QOS_DEFAULT_VALUE); fp@2407: fp@2407: /* fp@2407: * before we allocate an interrupt, we must be ready to handle it. fp@2407: * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt fp@2407: * as soon as we call pci_request_irq, so we have to setup our fp@2407: * clean_rx handler before we do so. fp@2407: */ fp@2407: e1000_configure(adapter); fp@2407: fp@2407: err = e1000_request_irq(adapter); fp@2407: if (err) fp@2407: goto err_req_irq; fp@2407: fp@2407: /* fp@2407: * Work around PCIe errata with MSI interrupts causing some chipsets to fp@2407: * ignore e1000e MSI messages, which means we need to test our MSI fp@2407: * interrupt now fp@2407: */ fp@2407: if (adapter->int_mode != E1000E_INT_MODE_LEGACY) { fp@2407: err = e1000_test_msi(adapter); fp@2407: if (err) { fp@2407: e_err("Interrupt allocation failed\n"); fp@2407: goto err_req_irq; fp@2407: } fp@2407: } fp@2407: fp@2407: /* From here on the code is the same as e1000e_up() */ fp@2407: clear_bit(__E1000_DOWN, &adapter->state); fp@2407: fp@2407: if (!adapter->ecdev) { fp@2407: napi_enable(&adapter->napi); fp@2407: fp@2407: e1000_irq_enable(adapter); fp@2473: } fp@2407: fp@2407: adapter->tx_hang_recheck = false; fp@2473: fp@2473: if (!adapter->ecdev) { fp@2407: netif_start_queue(netdev); fp@2473: } fp@2473: fp@2473: adapter->idle_check = true; fp@2473: pm_runtime_put(&pdev->dev); fp@2473: fp@2473: /* fire a link status change interrupt to start the watchdog */ fp@2473: if (adapter->msix_entries) fp@2473: ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER); fp@2473: else fp@2473: ew32(ICS, E1000_ICS_LSC); fp@2407: fp@2407: return 0; fp@2407: fp@2407: err_req_irq: fp@2407: e1000e_release_hw_control(adapter); fp@2407: e1000_power_down_phy(adapter); fp@2407: e1000e_free_rx_resources(adapter); fp@2407: err_setup_rx: fp@2407: e1000e_free_tx_resources(adapter); fp@2407: err_setup_tx: fp@2407: e1000e_reset(adapter); fp@2407: pm_runtime_put_sync(&pdev->dev); fp@2407: fp@2407: return err; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_close - Disables a network interface fp@2407: * @netdev: network interface device structure fp@2407: * fp@2407: * Returns 0, this is not allowed to fail fp@2407: * fp@2407: * The close entry point is called when an interface is de-activated fp@2407: * by the OS. The hardware is still under the drivers control, but fp@2407: * needs to be disabled. A global MAC reset is issued to stop the fp@2407: * hardware, and all transmit and receive resources are freed. fp@2407: **/ fp@2407: static int e1000_close(struct net_device *netdev) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: fp@2407: WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); fp@2407: fp@2407: pm_runtime_get_sync(&pdev->dev); fp@2407: fp@2407: if (!test_bit(__E1000_DOWN, &adapter->state)) { fp@2407: e1000e_down(adapter); fp@2407: e1000_free_irq(adapter); fp@2407: } fp@2407: e1000_power_down_phy(adapter); fp@2407: fp@2407: e1000e_free_tx_resources(adapter); fp@2407: e1000e_free_rx_resources(adapter); fp@2407: fp@2407: /* fp@2407: * kill manageability vlan ID if supported, but not if a vlan with fp@2407: * the same ID is registered on the host OS (let 8021q kill it) fp@2407: */ fp@2407: if (adapter->hw.mng_cookie.status & fp@2407: E1000_MNG_DHCP_COOKIE_STATUS_VLAN) fp@2407: e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); fp@2407: fp@2407: /* fp@2407: * If AMT is enabled, let the firmware know that the network fp@2407: * interface is now closed fp@2407: */ fp@2407: if ((adapter->flags & FLAG_HAS_AMT) && fp@2407: !test_bit(__E1000_TESTING, &adapter->state)) fp@2407: e1000e_release_hw_control(adapter); fp@2407: fp@2407: if ((adapter->flags & FLAG_HAS_ERT) || fp@2407: (adapter->hw.mac.type == e1000_pch2lan)) fp@2407: pm_qos_remove_request(&adapter->netdev->pm_qos_req); fp@2407: fp@2407: pm_runtime_put_sync(&pdev->dev); fp@2407: fp@2407: return 0; fp@2407: } fp@2407: /** fp@2407: * e1000_set_mac - Change the Ethernet Address of the NIC fp@2407: * @netdev: network interface device structure fp@2407: * @p: pointer to an address structure fp@2407: * fp@2407: * Returns 0 on success, negative on failure fp@2407: **/ fp@2407: static int e1000_set_mac(struct net_device *netdev, void *p) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct sockaddr *addr = p; fp@2407: fp@2407: if (!is_valid_ether_addr(addr->sa_data)) fp@2407: return -EADDRNOTAVAIL; fp@2407: fp@2407: memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); fp@2407: memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len); fp@2407: fp@2407: e1000e_rar_set(&adapter->hw, adapter->hw.mac.addr, 0); fp@2407: fp@2407: if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) { fp@2407: /* activate the work around */ fp@2407: e1000e_set_laa_state_82571(&adapter->hw, 1); fp@2407: fp@2407: /* fp@2407: * Hold a copy of the LAA in RAR[14] This is done so that fp@2407: * between the time RAR[0] gets clobbered and the time it fp@2407: * gets fixed (in e1000_watchdog), the actual LAA is in one fp@2407: * of the RARs and no incoming packets directed to this port fp@2407: * are dropped. Eventually the LAA will be in RAR[0] and fp@2407: * RAR[14] fp@2407: */ fp@2407: e1000e_rar_set(&adapter->hw, fp@2407: adapter->hw.mac.addr, fp@2407: adapter->hw.mac.rar_entry_count - 1); fp@2407: } fp@2407: fp@2407: return 0; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_update_phy_task - work thread to update phy fp@2407: * @work: pointer to our work struct fp@2407: * fp@2407: * this worker thread exists because we must acquire a fp@2407: * semaphore to read the phy, which we could msleep while fp@2407: * waiting for it, and we can't msleep in a timer. fp@2407: **/ fp@2407: static void e1000e_update_phy_task(struct work_struct *work) fp@2407: { fp@2407: struct e1000_adapter *adapter = container_of(work, fp@2407: struct e1000_adapter, update_phy_task); fp@2407: fp@2407: if (test_bit(__E1000_DOWN, &adapter->state)) fp@2407: return; fp@2407: fp@2407: e1000_get_phy_info(&adapter->hw); fp@2407: } fp@2407: fp@2407: /* fp@2407: * Need to wait a few seconds after link up to get diagnostic information from fp@2407: * the phy fp@2407: */ fp@2407: static void e1000_update_phy_info(unsigned long data) fp@2407: { fp@2407: struct e1000_adapter *adapter = (struct e1000_adapter *) data; fp@2407: fp@2407: if (test_bit(__E1000_DOWN, &adapter->state)) fp@2407: return; fp@2407: fp@2407: schedule_work(&adapter->update_phy_task); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_update_phy_stats - Update the PHY statistics counters fp@2407: * @adapter: board private structure fp@2407: * fp@2407: * Read/clear the upper 16-bit PHY registers and read/accumulate lower fp@2407: **/ fp@2407: static void e1000e_update_phy_stats(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: s32 ret_val; fp@2407: u16 phy_data; fp@2407: fp@2407: ret_val = hw->phy.ops.acquire(hw); fp@2407: if (ret_val) fp@2407: return; fp@2407: fp@2407: /* fp@2407: * A page set is expensive so check if already on desired page. fp@2407: * If not, set to the page with the PHY status registers. fp@2407: */ fp@2407: hw->phy.addr = 1; fp@2407: ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, fp@2407: &phy_data); fp@2407: if (ret_val) fp@2407: goto release; fp@2407: if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) { fp@2407: ret_val = hw->phy.ops.set_page(hw, fp@2407: HV_STATS_PAGE << IGP_PAGE_SHIFT); fp@2407: if (ret_val) fp@2407: goto release; fp@2407: } fp@2407: fp@2407: /* Single Collision Count */ fp@2407: hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data); fp@2407: ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data); fp@2407: if (!ret_val) fp@2407: adapter->stats.scc += phy_data; fp@2407: fp@2407: /* Excessive Collision Count */ fp@2407: hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data); fp@2407: ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data); fp@2407: if (!ret_val) fp@2407: adapter->stats.ecol += phy_data; fp@2407: fp@2407: /* Multiple Collision Count */ fp@2407: hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data); fp@2407: ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data); fp@2407: if (!ret_val) fp@2407: adapter->stats.mcc += phy_data; fp@2407: fp@2407: /* Late Collision Count */ fp@2407: hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data); fp@2407: ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data); fp@2407: if (!ret_val) fp@2407: adapter->stats.latecol += phy_data; fp@2407: fp@2407: /* Collision Count - also used for adaptive IFS */ fp@2407: hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data); fp@2407: ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data); fp@2407: if (!ret_val) fp@2407: hw->mac.collision_delta = phy_data; fp@2407: fp@2407: /* Defer Count */ fp@2407: hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data); fp@2407: ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data); fp@2407: if (!ret_val) fp@2407: adapter->stats.dc += phy_data; fp@2407: fp@2407: /* Transmit with no CRS */ fp@2407: hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data); fp@2407: ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data); fp@2407: if (!ret_val) fp@2407: adapter->stats.tncrs += phy_data; fp@2407: fp@2407: release: fp@2407: hw->phy.ops.release(hw); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000e_update_stats - Update the board statistics counters fp@2407: * @adapter: board private structure fp@2407: **/ fp@2407: static void e1000e_update_stats(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: fp@2407: /* fp@2407: * Prevent stats update while adapter is being reset, or if the pci fp@2407: * connection is down. fp@2407: */ fp@2407: if (adapter->link_speed == 0) fp@2407: return; fp@2407: if (pci_channel_offline(pdev)) fp@2407: return; fp@2407: fp@2407: adapter->stats.crcerrs += er32(CRCERRS); fp@2407: adapter->stats.gprc += er32(GPRC); fp@2407: adapter->stats.gorc += er32(GORCL); fp@2407: er32(GORCH); /* Clear gorc */ fp@2407: adapter->stats.bprc += er32(BPRC); fp@2407: adapter->stats.mprc += er32(MPRC); fp@2407: adapter->stats.roc += er32(ROC); fp@2407: fp@2407: adapter->stats.mpc += er32(MPC); fp@2407: fp@2407: /* Half-duplex statistics */ fp@2407: if (adapter->link_duplex == HALF_DUPLEX) { fp@2407: if (adapter->flags2 & FLAG2_HAS_PHY_STATS) { fp@2407: e1000e_update_phy_stats(adapter); fp@2407: } else { fp@2407: adapter->stats.scc += er32(SCC); fp@2407: adapter->stats.ecol += er32(ECOL); fp@2407: adapter->stats.mcc += er32(MCC); fp@2407: adapter->stats.latecol += er32(LATECOL); fp@2407: adapter->stats.dc += er32(DC); fp@2407: fp@2407: hw->mac.collision_delta = er32(COLC); fp@2407: fp@2407: if ((hw->mac.type != e1000_82574) && fp@2407: (hw->mac.type != e1000_82583)) fp@2407: adapter->stats.tncrs += er32(TNCRS); fp@2407: } fp@2407: adapter->stats.colc += hw->mac.collision_delta; fp@2407: } fp@2407: fp@2407: adapter->stats.xonrxc += er32(XONRXC); fp@2407: adapter->stats.xontxc += er32(XONTXC); fp@2407: adapter->stats.xoffrxc += er32(XOFFRXC); fp@2407: adapter->stats.xofftxc += er32(XOFFTXC); fp@2407: adapter->stats.gptc += er32(GPTC); fp@2407: adapter->stats.gotc += er32(GOTCL); fp@2407: er32(GOTCH); /* Clear gotc */ fp@2407: adapter->stats.rnbc += er32(RNBC); fp@2407: adapter->stats.ruc += er32(RUC); fp@2407: fp@2407: adapter->stats.mptc += er32(MPTC); fp@2407: adapter->stats.bptc += er32(BPTC); fp@2407: fp@2407: /* used for adaptive IFS */ fp@2407: fp@2407: hw->mac.tx_packet_delta = er32(TPT); fp@2407: adapter->stats.tpt += hw->mac.tx_packet_delta; fp@2407: fp@2407: adapter->stats.algnerrc += er32(ALGNERRC); fp@2407: adapter->stats.rxerrc += er32(RXERRC); fp@2407: adapter->stats.cexterr += er32(CEXTERR); fp@2407: adapter->stats.tsctc += er32(TSCTC); fp@2407: adapter->stats.tsctfc += er32(TSCTFC); fp@2407: fp@2407: /* Fill out the OS statistics structure */ fp@2407: netdev->stats.multicast = adapter->stats.mprc; fp@2407: netdev->stats.collisions = adapter->stats.colc; fp@2407: fp@2407: /* Rx Errors */ fp@2407: fp@2407: /* fp@2407: * RLEC on some newer hardware can be incorrect so build fp@2407: * our own version based on RUC and ROC fp@2407: */ fp@2407: netdev->stats.rx_errors = adapter->stats.rxerrc + fp@2407: adapter->stats.crcerrs + adapter->stats.algnerrc + fp@2407: adapter->stats.ruc + adapter->stats.roc + fp@2407: adapter->stats.cexterr; fp@2407: netdev->stats.rx_length_errors = adapter->stats.ruc + fp@2407: adapter->stats.roc; fp@2407: netdev->stats.rx_crc_errors = adapter->stats.crcerrs; fp@2407: netdev->stats.rx_frame_errors = adapter->stats.algnerrc; fp@2407: netdev->stats.rx_missed_errors = adapter->stats.mpc; fp@2407: fp@2407: /* Tx Errors */ fp@2407: netdev->stats.tx_errors = adapter->stats.ecol + fp@2407: adapter->stats.latecol; fp@2407: netdev->stats.tx_aborted_errors = adapter->stats.ecol; fp@2407: netdev->stats.tx_window_errors = adapter->stats.latecol; fp@2407: netdev->stats.tx_carrier_errors = adapter->stats.tncrs; fp@2407: fp@2407: /* Tx Dropped needs to be maintained elsewhere */ fp@2407: fp@2407: /* Management Stats */ fp@2407: adapter->stats.mgptc += er32(MGTPTC); fp@2407: adapter->stats.mgprc += er32(MGTPRC); fp@2407: adapter->stats.mgpdc += er32(MGTPDC); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_phy_read_status - Update the PHY register status snapshot fp@2407: * @adapter: board private structure fp@2407: **/ fp@2407: static void e1000_phy_read_status(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct e1000_phy_regs *phy = &adapter->phy_regs; fp@2407: fp@2407: if ((er32(STATUS) & E1000_STATUS_LU) && fp@2407: (adapter->hw.phy.media_type == e1000_media_type_copper)) { fp@2407: int ret_val; fp@2407: fp@2407: ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr); fp@2407: ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr); fp@2407: ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise); fp@2407: ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa); fp@2407: ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion); fp@2407: ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000); fp@2407: ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000); fp@2407: ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus); fp@2407: if (ret_val) fp@2407: e_warn("Error reading PHY register\n"); fp@2407: } else { fp@2407: /* fp@2407: * Do not read PHY registers if link is not up fp@2407: * Set values to typical power-on defaults fp@2407: */ fp@2407: phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX); fp@2407: phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | fp@2407: BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE | fp@2407: BMSR_ERCAP); fp@2407: phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP | fp@2407: ADVERTISE_ALL | ADVERTISE_CSMA); fp@2407: phy->lpa = 0; fp@2407: phy->expansion = EXPANSION_ENABLENPAGE; fp@2407: phy->ctrl1000 = ADVERTISE_1000FULL; fp@2407: phy->stat1000 = 0; fp@2407: phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF); fp@2407: } fp@2407: } fp@2407: fp@2407: static void e1000_print_link_info(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 ctrl = er32(CTRL); fp@2407: fp@2407: /* Link status message must follow this format for user tools */ fp@2407: printk(KERN_INFO "e1000e: %s NIC Link is Up %d Mbps %s, " fp@2407: "Flow Control: %s\n", fp@2407: adapter->netdev->name, fp@2407: adapter->link_speed, fp@2407: (adapter->link_duplex == FULL_DUPLEX) ? fp@2407: "Full Duplex" : "Half Duplex", fp@2407: ((ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE)) ? fp@2407: "Rx/Tx" : fp@2407: ((ctrl & E1000_CTRL_RFCE) ? "Rx" : fp@2407: ((ctrl & E1000_CTRL_TFCE) ? "Tx" : "None"))); fp@2407: } fp@2407: fp@2407: static bool e1000e_has_link(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: bool link_active = 0; fp@2407: s32 ret_val = 0; fp@2407: fp@2407: /* fp@2407: * get_link_status is set on LSC (link status) interrupt or fp@2407: * Rx sequence error interrupt. get_link_status will stay fp@2407: * false until the check_for_link establishes link fp@2407: * for copper adapters ONLY fp@2407: */ fp@2407: switch (hw->phy.media_type) { fp@2407: case e1000_media_type_copper: fp@2407: if (hw->mac.get_link_status) { fp@2407: ret_val = hw->mac.ops.check_for_link(hw); fp@2407: link_active = !hw->mac.get_link_status; fp@2407: } else { fp@2407: link_active = 1; fp@2407: } fp@2407: break; fp@2407: case e1000_media_type_fiber: fp@2407: ret_val = hw->mac.ops.check_for_link(hw); fp@2407: link_active = !!(er32(STATUS) & E1000_STATUS_LU); fp@2407: break; fp@2407: case e1000_media_type_internal_serdes: fp@2407: ret_val = hw->mac.ops.check_for_link(hw); fp@2407: link_active = adapter->hw.mac.serdes_has_link; fp@2407: break; fp@2407: default: fp@2407: case e1000_media_type_unknown: fp@2407: break; fp@2407: } fp@2407: fp@2407: if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) && fp@2407: (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { fp@2407: /* See e1000_kmrn_lock_loss_workaround_ich8lan() */ fp@2407: e_info("Gigabit has been disabled, downgrading speed\n"); fp@2407: } fp@2407: fp@2407: return link_active; fp@2407: } fp@2407: fp@2407: static void e1000e_enable_receives(struct e1000_adapter *adapter) fp@2407: { fp@2407: /* make sure the receive unit is started */ fp@2407: if ((adapter->flags & FLAG_RX_NEEDS_RESTART) && fp@2407: (adapter->flags & FLAG_RX_RESTART_NOW)) { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 rctl = er32(RCTL); fp@2407: ew32(RCTL, rctl | E1000_RCTL_EN); fp@2407: adapter->flags &= ~FLAG_RX_RESTART_NOW; fp@2407: } fp@2407: } fp@2407: fp@2407: static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: fp@2407: /* fp@2407: * With 82574 controllers, PHY needs to be checked periodically fp@2407: * for hung state and reset, if two calls return true fp@2407: */ fp@2407: if (e1000_check_phy_82574(hw)) fp@2407: adapter->phy_hang_count++; fp@2407: else fp@2407: adapter->phy_hang_count = 0; fp@2407: fp@2407: if (adapter->phy_hang_count > 1) { fp@2407: adapter->phy_hang_count = 0; fp@2407: schedule_work(&adapter->reset_task); fp@2407: } fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_watchdog - Timer Call-back fp@2407: * @data: pointer to adapter cast into an unsigned long fp@2407: **/ fp@2407: static void e1000_watchdog(unsigned long data) fp@2407: { fp@2407: struct e1000_adapter *adapter = (struct e1000_adapter *) data; fp@2407: fp@2407: /* Do the rest outside of interrupt context */ fp@2407: schedule_work(&adapter->watchdog_task); fp@2407: fp@2407: /* TODO: make this use queue_delayed_work() */ fp@2407: } fp@2407: fp@2407: static void e1000_watchdog_task(struct work_struct *work) fp@2407: { fp@2407: struct e1000_adapter *adapter = container_of(work, fp@2407: struct e1000_adapter, watchdog_task); fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: struct e1000_mac_info *mac = &adapter->hw.mac; fp@2407: struct e1000_phy_info *phy = &adapter->hw.phy; fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 link, tctl; fp@2407: fp@2407: if (test_bit(__E1000_DOWN, &adapter->state)) fp@2407: return; fp@2407: fp@2407: link = e1000e_has_link(adapter); fp@2407: if ((adapter->ecdev && (ecdev_get_link(adapter->ecdev)) && link) fp@2407: || (!adapter->ecdev && (netif_carrier_ok(netdev)) && link)) { fp@2407: if (!adapter->ecdev) { fp@2407: /* Cancel scheduled suspend requests. */ fp@2407: pm_runtime_resume(netdev->dev.parent); fp@2407: } fp@2407: fp@2407: e1000e_enable_receives(adapter); fp@2407: goto link_up; fp@2407: } fp@2407: fp@2407: if ((e1000e_enable_tx_pkt_filtering(hw)) && fp@2407: (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)) fp@2407: e1000_update_mng_vlan(adapter); fp@2407: fp@2407: if (link) { fp@2421: if ((adapter->ecdev && !ecdev_get_link(adapter->ecdev)) fp@2407: || (!adapter->ecdev && !netif_carrier_ok(netdev))) { fp@2407: bool txb2b = 1; fp@2407: fp@2407: /* Cancel scheduled suspend requests. */ fp@2407: pm_runtime_resume(netdev->dev.parent); fp@2407: fp@2407: /* update snapshot of PHY registers on LSC */ fp@2407: e1000_phy_read_status(adapter); fp@2407: mac->ops.get_link_up_info(&adapter->hw, fp@2407: &adapter->link_speed, fp@2407: &adapter->link_duplex); fp@2407: e1000_print_link_info(adapter); fp@2407: /* fp@2407: * On supported PHYs, check for duplex mismatch only fp@2407: * if link has autonegotiated at 10/100 half fp@2407: */ fp@2407: if ((hw->phy.type == e1000_phy_igp_3 || fp@2407: hw->phy.type == e1000_phy_bm) && fp@2407: (hw->mac.autoneg == true) && fp@2407: (adapter->link_speed == SPEED_10 || fp@2407: adapter->link_speed == SPEED_100) && fp@2407: (adapter->link_duplex == HALF_DUPLEX)) { fp@2407: u16 autoneg_exp; fp@2407: fp@2407: e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp); fp@2407: fp@2407: if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS)) fp@2407: e_info("Autonegotiated half duplex but" fp@2407: " link partner cannot autoneg. " fp@2407: " Try forcing full duplex if " fp@2407: "link gets many collisions.\n"); fp@2407: } fp@2407: fp@2407: /* adjust timeout factor according to speed/duplex */ fp@2407: adapter->tx_timeout_factor = 1; fp@2407: switch (adapter->link_speed) { fp@2407: case SPEED_10: fp@2407: txb2b = 0; fp@2407: adapter->tx_timeout_factor = 16; fp@2407: break; fp@2407: case SPEED_100: fp@2407: txb2b = 0; fp@2407: adapter->tx_timeout_factor = 10; fp@2407: break; fp@2407: } fp@2407: fp@2407: /* fp@2407: * workaround: re-program speed mode bit after fp@2407: * link-up event fp@2407: */ fp@2407: if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) && fp@2407: !txb2b) { fp@2407: u32 tarc0; fp@2407: tarc0 = er32(TARC(0)); fp@2407: tarc0 &= ~SPEED_MODE_BIT; fp@2407: ew32(TARC(0), tarc0); fp@2407: } fp@2407: fp@2407: /* fp@2407: * disable TSO for pcie and 10/100 speeds, to avoid fp@2407: * some hardware issues fp@2407: */ fp@2407: if (!(adapter->flags & FLAG_TSO_FORCE)) { fp@2407: switch (adapter->link_speed) { fp@2407: case SPEED_10: fp@2407: case SPEED_100: fp@2407: e_info("10/100 speed: disabling TSO\n"); fp@2407: netdev->features &= ~NETIF_F_TSO; fp@2407: netdev->features &= ~NETIF_F_TSO6; fp@2407: break; fp@2407: case SPEED_1000: fp@2407: netdev->features |= NETIF_F_TSO; fp@2407: netdev->features |= NETIF_F_TSO6; fp@2407: break; fp@2407: default: fp@2407: /* oops */ fp@2407: break; fp@2407: } fp@2407: } fp@2407: fp@2407: /* fp@2407: * enable transmits in the hardware, need to do this fp@2407: * after setting TARC(0) fp@2407: */ fp@2407: tctl = er32(TCTL); fp@2407: tctl |= E1000_TCTL_EN; fp@2407: ew32(TCTL, tctl); fp@2407: fp@2407: /* fp@2407: * Perform any post-link-up configuration before fp@2407: * reporting link up. fp@2407: */ fp@2407: if (phy->ops.cfg_on_link_up) fp@2407: phy->ops.cfg_on_link_up(hw); fp@2407: fp@2407: if (adapter->ecdev) fp@2407: ecdev_set_link(adapter->ecdev, 1); fp@2421: else fp@2407: netif_carrier_on(netdev); fp@2407: fp@2407: if (!adapter->ecdev && !test_bit(__E1000_DOWN, &adapter->state)) fp@2407: mod_timer(&adapter->phy_info_timer, fp@2407: round_jiffies(jiffies + 2 * HZ)); fp@2407: } fp@2407: } else { fp@2421: if ((adapter->ecdev && ecdev_get_link(adapter->ecdev)) fp@2407: || (!adapter->ecdev && netif_carrier_ok(netdev))) { fp@2407: adapter->link_speed = 0; fp@2407: adapter->link_duplex = 0; fp@2407: /* Link status message must follow this format */ fp@2407: printk(KERN_INFO "e1000e: %s NIC Link is Down\n", fp@2407: adapter->netdev->name); fp@2407: if (adapter->ecdev) fp@2407: ecdev_set_link(adapter->ecdev, 0); fp@2407: else fp@2407: netif_carrier_off(netdev); fp@2407: if (!adapter->ecdev && !test_bit(__E1000_DOWN, &adapter->state)) fp@2407: mod_timer(&adapter->phy_info_timer, fp@2407: round_jiffies(jiffies + 2 * HZ)); fp@2407: fp@2407: if (adapter->flags & FLAG_RX_NEEDS_RESTART) fp@2407: schedule_work(&adapter->reset_task); fp@2407: else fp@2407: pm_schedule_suspend(netdev->dev.parent, fp@2407: LINK_TIMEOUT); fp@2407: } fp@2407: } fp@2407: fp@2407: link_up: fp@2407: spin_lock(&adapter->stats64_lock); fp@2407: e1000e_update_stats(adapter); fp@2407: fp@2407: mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; fp@2407: adapter->tpt_old = adapter->stats.tpt; fp@2407: mac->collision_delta = adapter->stats.colc - adapter->colc_old; fp@2407: adapter->colc_old = adapter->stats.colc; fp@2407: fp@2407: adapter->gorc = adapter->stats.gorc - adapter->gorc_old; fp@2407: adapter->gorc_old = adapter->stats.gorc; fp@2407: adapter->gotc = adapter->stats.gotc - adapter->gotc_old; fp@2407: adapter->gotc_old = adapter->stats.gotc; fp@2407: spin_unlock(&adapter->stats64_lock); fp@2407: fp@2407: e1000e_update_adaptive(&adapter->hw); fp@2407: fp@2421: if ((adapter->ecdev && !ecdev_get_link(adapter->ecdev)) fp@2407: || (!adapter->ecdev && (!netif_carrier_ok(netdev) && fp@2407: (e1000_desc_unused(tx_ring) + 1 < tx_ring->count)))) { fp@2407: /* fp@2407: * We've lost link, so the controller stops DMA, fp@2407: * but we've got queued Tx work that's never going fp@2407: * to get done, so reset controller to flush Tx. fp@2407: * (Do the reset outside of interrupt context). fp@2407: */ fp@2407: schedule_work(&adapter->reset_task); fp@2407: /* return immediately since reset is imminent */ fp@2407: return; fp@2407: } fp@2407: fp@2407: /* Simple mode for Interrupt Throttle Rate (ITR) */ fp@2407: if (adapter->itr_setting == 4) { fp@2407: /* fp@2407: * Symmetric Tx/Rx gets a reduced ITR=2000; fp@2407: * Total asymmetrical Tx or Rx gets ITR=8000; fp@2407: * everyone else is between 2000-8000. fp@2407: */ fp@2407: u32 goc = (adapter->gotc + adapter->gorc) / 10000; fp@2407: u32 dif = (adapter->gotc > adapter->gorc ? fp@2407: adapter->gotc - adapter->gorc : fp@2407: adapter->gorc - adapter->gotc) / 10000; fp@2407: u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; fp@2407: fp@2407: ew32(ITR, 1000000000 / (itr * 256)); fp@2407: } fp@2407: fp@2407: /* Cause software interrupt to ensure Rx ring is cleaned */ fp@2407: if (adapter->msix_entries) fp@2407: ew32(ICS, adapter->rx_ring->ims_val); fp@2407: else fp@2407: ew32(ICS, E1000_ICS_RXDMT0); fp@2407: fp@2407: /* flush pending descriptors to memory before detecting Tx hang */ fp@2407: e1000e_flush_descriptors(adapter); fp@2407: fp@2407: /* Force detection of hung controller every watchdog period */ fp@2407: adapter->detect_tx_hung = 1; fp@2407: fp@2407: /* fp@2407: * With 82571 controllers, LAA may be overwritten due to controller fp@2407: * reset from the other port. Set the appropriate LAA in RAR[0] fp@2407: */ fp@2407: if (e1000e_get_laa_state_82571(hw)) fp@2407: e1000e_rar_set(hw, adapter->hw.mac.addr, 0); fp@2407: fp@2407: if (adapter->flags2 & FLAG2_CHECK_PHY_HANG) fp@2407: e1000e_check_82574_phy_workaround(adapter); fp@2407: fp@2407: /* Reset the timer */ fp@2407: if (!adapter->ecdev && !test_bit(__E1000_DOWN, &adapter->state)) fp@2407: mod_timer(&adapter->watchdog_timer, fp@2407: round_jiffies(jiffies + 2 * HZ)); fp@2407: } fp@2407: fp@2407: #define E1000_TX_FLAGS_CSUM 0x00000001 fp@2407: #define E1000_TX_FLAGS_VLAN 0x00000002 fp@2407: #define E1000_TX_FLAGS_TSO 0x00000004 fp@2407: #define E1000_TX_FLAGS_IPV4 0x00000008 fp@2407: #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 fp@2407: #define E1000_TX_FLAGS_VLAN_SHIFT 16 fp@2407: fp@2407: static int e1000_tso(struct e1000_adapter *adapter, fp@2407: struct sk_buff *skb) fp@2407: { fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: struct e1000_context_desc *context_desc; fp@2407: struct e1000_buffer *buffer_info; fp@2407: unsigned int i; fp@2407: u32 cmd_length = 0; fp@2407: u16 ipcse = 0, tucse, mss; fp@2407: u8 ipcss, ipcso, tucss, tucso, hdr_len; fp@2407: fp@2407: if (!skb_is_gso(skb)) fp@2407: return 0; fp@2407: fp@2407: if (skb_header_cloned(skb)) { fp@2407: int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); fp@2407: fp@2407: if (err) fp@2407: return err; fp@2407: } fp@2407: fp@2407: hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); fp@2407: mss = skb_shinfo(skb)->gso_size; fp@2407: if (skb->protocol == htons(ETH_P_IP)) { fp@2407: struct iphdr *iph = ip_hdr(skb); fp@2407: iph->tot_len = 0; fp@2407: iph->check = 0; fp@2407: tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, fp@2407: 0, IPPROTO_TCP, 0); fp@2407: cmd_length = E1000_TXD_CMD_IP; fp@2407: ipcse = skb_transport_offset(skb) - 1; fp@2407: } else if (skb_is_gso_v6(skb)) { fp@2407: ipv6_hdr(skb)->payload_len = 0; fp@2407: tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, fp@2407: &ipv6_hdr(skb)->daddr, fp@2407: 0, IPPROTO_TCP, 0); fp@2407: ipcse = 0; fp@2407: } fp@2407: ipcss = skb_network_offset(skb); fp@2407: ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; fp@2407: tucss = skb_transport_offset(skb); fp@2407: tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; fp@2407: tucse = 0; fp@2407: fp@2407: cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | fp@2407: E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); fp@2407: fp@2407: i = tx_ring->next_to_use; fp@2407: context_desc = E1000_CONTEXT_DESC(*tx_ring, i); fp@2407: buffer_info = &tx_ring->buffer_info[i]; fp@2407: fp@2407: context_desc->lower_setup.ip_fields.ipcss = ipcss; fp@2407: context_desc->lower_setup.ip_fields.ipcso = ipcso; fp@2407: context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); fp@2407: context_desc->upper_setup.tcp_fields.tucss = tucss; fp@2407: context_desc->upper_setup.tcp_fields.tucso = tucso; fp@2407: context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); fp@2407: context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); fp@2407: context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; fp@2407: context_desc->cmd_and_length = cpu_to_le32(cmd_length); fp@2407: fp@2407: buffer_info->time_stamp = jiffies; fp@2407: buffer_info->next_to_watch = i; fp@2407: fp@2407: i++; fp@2407: if (i == tx_ring->count) fp@2407: i = 0; fp@2407: tx_ring->next_to_use = i; fp@2407: fp@2407: return 1; fp@2407: } fp@2407: fp@2407: static bool e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb) fp@2407: { fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: struct e1000_context_desc *context_desc; fp@2407: struct e1000_buffer *buffer_info; fp@2407: unsigned int i; fp@2407: u8 css; fp@2407: u32 cmd_len = E1000_TXD_CMD_DEXT; fp@2407: __be16 protocol; fp@2407: fp@2407: if (skb->ip_summed != CHECKSUM_PARTIAL) fp@2407: return 0; fp@2407: fp@2407: if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) fp@2407: protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; fp@2407: else fp@2407: protocol = skb->protocol; fp@2407: fp@2407: switch (protocol) { fp@2407: case cpu_to_be16(ETH_P_IP): fp@2407: if (ip_hdr(skb)->protocol == IPPROTO_TCP) fp@2407: cmd_len |= E1000_TXD_CMD_TCP; fp@2407: break; fp@2407: case cpu_to_be16(ETH_P_IPV6): fp@2407: /* XXX not handling all IPV6 headers */ fp@2407: if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) fp@2407: cmd_len |= E1000_TXD_CMD_TCP; fp@2407: break; fp@2407: default: fp@2407: if (unlikely(net_ratelimit())) fp@2407: e_warn("checksum_partial proto=%x!\n", fp@2407: be16_to_cpu(protocol)); fp@2407: break; fp@2407: } fp@2407: fp@2407: css = skb_checksum_start_offset(skb); fp@2407: fp@2407: i = tx_ring->next_to_use; fp@2407: buffer_info = &tx_ring->buffer_info[i]; fp@2407: context_desc = E1000_CONTEXT_DESC(*tx_ring, i); fp@2407: fp@2407: context_desc->lower_setup.ip_config = 0; fp@2407: context_desc->upper_setup.tcp_fields.tucss = css; fp@2407: context_desc->upper_setup.tcp_fields.tucso = fp@2407: css + skb->csum_offset; fp@2407: context_desc->upper_setup.tcp_fields.tucse = 0; fp@2407: context_desc->tcp_seg_setup.data = 0; fp@2407: context_desc->cmd_and_length = cpu_to_le32(cmd_len); fp@2407: fp@2407: buffer_info->time_stamp = jiffies; fp@2407: buffer_info->next_to_watch = i; fp@2407: fp@2407: i++; fp@2407: if (i == tx_ring->count) fp@2407: i = 0; fp@2407: tx_ring->next_to_use = i; fp@2407: fp@2407: return 1; fp@2407: } fp@2407: fp@2407: #define E1000_MAX_PER_TXD 8192 fp@2407: #define E1000_MAX_TXD_PWR 12 fp@2407: fp@2407: static int e1000_tx_map(struct e1000_adapter *adapter, fp@2407: struct sk_buff *skb, unsigned int first, fp@2407: unsigned int max_per_txd, unsigned int nr_frags, fp@2407: unsigned int mss) fp@2407: { fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: struct pci_dev *pdev = adapter->pdev; fp@2407: struct e1000_buffer *buffer_info; fp@2407: unsigned int len = skb_headlen(skb); fp@2407: unsigned int offset = 0, size, count = 0, i; fp@2407: unsigned int f, bytecount, segs; fp@2407: fp@2407: i = tx_ring->next_to_use; fp@2407: fp@2407: while (len) { fp@2407: buffer_info = &tx_ring->buffer_info[i]; fp@2407: size = min(len, max_per_txd); fp@2407: fp@2407: buffer_info->length = size; fp@2407: buffer_info->time_stamp = jiffies; fp@2407: buffer_info->next_to_watch = i; fp@2407: buffer_info->dma = dma_map_single(&pdev->dev, fp@2407: skb->data + offset, fp@2407: size, DMA_TO_DEVICE); fp@2407: buffer_info->mapped_as_page = false; fp@2407: if (dma_mapping_error(&pdev->dev, buffer_info->dma)) fp@2407: goto dma_error; fp@2407: fp@2407: len -= size; fp@2407: offset += size; fp@2407: count++; fp@2407: fp@2407: if (len) { fp@2407: i++; fp@2407: if (i == tx_ring->count) fp@2407: i = 0; fp@2407: } fp@2407: } fp@2407: fp@2407: for (f = 0; f < nr_frags; f++) { fp@2407: const struct skb_frag_struct *frag; fp@2407: fp@2407: frag = &skb_shinfo(skb)->frags[f]; fp@2407: len = skb_frag_size(frag); fp@2407: offset = 0; fp@2407: fp@2407: while (len) { fp@2407: i++; fp@2407: if (i == tx_ring->count) fp@2407: i = 0; fp@2407: fp@2407: buffer_info = &tx_ring->buffer_info[i]; fp@2407: size = min(len, max_per_txd); fp@2407: fp@2407: buffer_info->length = size; fp@2407: buffer_info->time_stamp = jiffies; fp@2407: buffer_info->next_to_watch = i; fp@2407: buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag, fp@2407: offset, size, DMA_TO_DEVICE); fp@2407: buffer_info->mapped_as_page = true; fp@2407: if (dma_mapping_error(&pdev->dev, buffer_info->dma)) fp@2407: goto dma_error; fp@2407: fp@2407: len -= size; fp@2407: offset += size; fp@2407: count++; fp@2407: } fp@2407: } fp@2407: fp@2407: segs = skb_shinfo(skb)->gso_segs ? : 1; fp@2407: /* multiply data chunks by size of headers */ fp@2407: bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len; fp@2407: fp@2407: tx_ring->buffer_info[i].skb = skb; fp@2407: tx_ring->buffer_info[i].segs = segs; fp@2407: tx_ring->buffer_info[i].bytecount = bytecount; fp@2407: tx_ring->buffer_info[first].next_to_watch = i; fp@2407: fp@2407: return count; fp@2407: fp@2407: dma_error: fp@2407: dev_err(&pdev->dev, "Tx DMA map failed\n"); fp@2407: buffer_info->dma = 0; fp@2407: if (count) fp@2407: count--; fp@2407: fp@2407: while (count--) { fp@2407: if (i == 0) fp@2407: i += tx_ring->count; fp@2407: i--; fp@2407: buffer_info = &tx_ring->buffer_info[i]; fp@2407: e1000_put_txbuf(adapter, buffer_info); fp@2407: } fp@2407: fp@2407: return 0; fp@2407: } fp@2407: fp@2407: static void e1000_tx_queue(struct e1000_adapter *adapter, fp@2407: int tx_flags, int count) fp@2407: { fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: struct e1000_tx_desc *tx_desc = NULL; fp@2407: struct e1000_buffer *buffer_info; fp@2407: u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; fp@2407: unsigned int i; fp@2407: fp@2407: if (tx_flags & E1000_TX_FLAGS_TSO) { fp@2407: txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | fp@2407: E1000_TXD_CMD_TSE; fp@2407: txd_upper |= E1000_TXD_POPTS_TXSM << 8; fp@2407: fp@2407: if (tx_flags & E1000_TX_FLAGS_IPV4) fp@2407: txd_upper |= E1000_TXD_POPTS_IXSM << 8; fp@2407: } fp@2407: fp@2407: if (tx_flags & E1000_TX_FLAGS_CSUM) { fp@2407: txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; fp@2407: txd_upper |= E1000_TXD_POPTS_TXSM << 8; fp@2407: } fp@2407: fp@2407: if (tx_flags & E1000_TX_FLAGS_VLAN) { fp@2407: txd_lower |= E1000_TXD_CMD_VLE; fp@2407: txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); fp@2407: } fp@2407: fp@2407: i = tx_ring->next_to_use; fp@2407: fp@2407: do { fp@2407: buffer_info = &tx_ring->buffer_info[i]; fp@2407: tx_desc = E1000_TX_DESC(*tx_ring, i); fp@2407: tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); fp@2407: tx_desc->lower.data = fp@2407: cpu_to_le32(txd_lower | buffer_info->length); fp@2407: tx_desc->upper.data = cpu_to_le32(txd_upper); fp@2407: fp@2407: i++; fp@2407: if (i == tx_ring->count) fp@2407: i = 0; fp@2407: } while (--count > 0); fp@2407: fp@2407: tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); fp@2407: fp@2407: /* fp@2407: * Force memory writes to complete before letting h/w fp@2407: * know there are new descriptors to fetch. (Only fp@2407: * applicable for weak-ordered memory model archs, fp@2407: * such as IA-64). fp@2407: */ fp@2407: wmb(); fp@2407: fp@2407: tx_ring->next_to_use = i; fp@2407: fp@2407: if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) fp@2407: e1000e_update_tdt_wa(adapter, i); fp@2407: else fp@2407: writel(i, adapter->hw.hw_addr + tx_ring->tail); fp@2407: fp@2407: /* fp@2407: * we need this if more than one processor can write to our tail fp@2407: * at a time, it synchronizes IO on IA64/Altix systems fp@2407: */ fp@2407: mmiowb(); fp@2407: } fp@2407: fp@2407: #define MINIMUM_DHCP_PACKET_SIZE 282 fp@2407: static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, fp@2407: struct sk_buff *skb) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u16 length, offset; fp@2407: fp@2407: if (vlan_tx_tag_present(skb)) { fp@2407: if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && fp@2407: (adapter->hw.mng_cookie.status & fp@2407: E1000_MNG_DHCP_COOKIE_STATUS_VLAN))) fp@2407: return 0; fp@2407: } fp@2407: fp@2407: if (skb->len <= MINIMUM_DHCP_PACKET_SIZE) fp@2407: return 0; fp@2407: fp@2407: if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP)) fp@2407: return 0; fp@2407: fp@2407: { fp@2407: const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14); fp@2407: struct udphdr *udp; fp@2407: fp@2407: if (ip->protocol != IPPROTO_UDP) fp@2407: return 0; fp@2407: fp@2407: udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); fp@2407: if (ntohs(udp->dest) != 67) fp@2407: return 0; fp@2407: fp@2407: offset = (u8 *)udp + 8 - skb->data; fp@2407: length = skb->len - offset; fp@2407: return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length); fp@2407: } fp@2407: fp@2407: return 0; fp@2407: } fp@2407: fp@2407: static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2472: if (adapter->ecdev) { fp@2472: return -EBUSY; fp@2472: } fp@2472: fp@2407: netif_stop_queue(netdev); fp@2407: /* fp@2407: * Herbert's original patch had: fp@2407: * smp_mb__after_netif_stop_queue(); fp@2407: * but since that doesn't exist yet, just open code it. fp@2407: */ fp@2407: smp_mb(); fp@2407: fp@2407: /* fp@2407: * We need to check again in a case another CPU has just fp@2407: * made room available. fp@2407: */ fp@2407: if (e1000_desc_unused(adapter->tx_ring) < size) fp@2407: return -EBUSY; fp@2407: fp@2407: /* A reprieve! */ fp@2407: netif_start_queue(netdev); fp@2407: ++adapter->restart_queue; fp@2407: return 0; fp@2407: } fp@2407: fp@2407: static int e1000_maybe_stop_tx(struct net_device *netdev, int size) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: if (e1000_desc_unused(adapter->tx_ring) >= size) fp@2407: return 0; fp@2407: return __e1000_maybe_stop_tx(netdev, size); fp@2407: } fp@2407: fp@2407: #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) fp@2407: static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, fp@2407: struct net_device *netdev) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_ring *tx_ring = adapter->tx_ring; fp@2407: unsigned int first; fp@2407: unsigned int max_per_txd = E1000_MAX_PER_TXD; fp@2407: unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; fp@2407: unsigned int tx_flags = 0; fp@2407: unsigned int len = skb_headlen(skb); fp@2407: unsigned int nr_frags; fp@2407: unsigned int mss; fp@2407: int count = 0; fp@2407: int tso; fp@2407: unsigned int f; fp@2407: fp@2407: if (test_bit(__E1000_DOWN, &adapter->state)) { fp@2407: if (!adapter->ecdev) fp@2407: dev_kfree_skb_any(skb); fp@2407: return NETDEV_TX_OK; fp@2407: } fp@2407: fp@2407: if (skb->len <= 0) { fp@2407: if (!adapter->ecdev) fp@2407: dev_kfree_skb_any(skb); fp@2407: return NETDEV_TX_OK; fp@2407: } fp@2407: fp@2407: mss = skb_shinfo(skb)->gso_size; fp@2407: /* fp@2407: * The controller does a simple calculation to fp@2407: * make sure there is enough room in the FIFO before fp@2407: * initiating the DMA for each buffer. The calc is: fp@2407: * 4 = ceil(buffer len/mss). To make sure we don't fp@2407: * overrun the FIFO, adjust the max buffer len if mss fp@2407: * drops. fp@2407: */ fp@2407: if (mss) { fp@2407: u8 hdr_len; fp@2407: max_per_txd = min(mss << 2, max_per_txd); fp@2407: max_txd_pwr = fls(max_per_txd) - 1; fp@2407: fp@2407: /* fp@2407: * TSO Workaround for 82571/2/3 Controllers -- if skb->data fp@2407: * points to just header, pull a few bytes of payload from fp@2407: * frags into skb->data fp@2407: */ fp@2407: hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); fp@2407: /* fp@2407: * we do this workaround for ES2LAN, but it is un-necessary, fp@2407: * avoiding it could save a lot of cycles fp@2407: */ fp@2407: if (skb->data_len && (hdr_len == len)) { fp@2407: unsigned int pull_size; fp@2407: fp@2407: pull_size = min((unsigned int)4, skb->data_len); fp@2407: if (!__pskb_pull_tail(skb, pull_size)) { fp@2407: e_err("__pskb_pull_tail failed.\n"); fp@2407: if (!adapter->ecdev) fp@2407: dev_kfree_skb_any(skb); fp@2407: return NETDEV_TX_OK; fp@2407: } fp@2407: len = skb_headlen(skb); fp@2407: } fp@2407: } fp@2407: fp@2407: /* reserve a descriptor for the offload context */ fp@2407: if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) fp@2407: count++; fp@2407: count++; fp@2407: fp@2407: count += TXD_USE_COUNT(len, max_txd_pwr); fp@2407: fp@2407: nr_frags = skb_shinfo(skb)->nr_frags; fp@2407: for (f = 0; f < nr_frags; f++) fp@2407: count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]), fp@2407: max_txd_pwr); fp@2407: fp@2407: if (adapter->hw.mac.tx_pkt_filtering) fp@2407: e1000_transfer_dhcp_info(adapter, skb); fp@2407: fp@2407: /* fp@2407: * need: count + 2 desc gap to keep tail from touching fp@2407: * head, otherwise try next time fp@2407: */ fp@2407: if (!adapter->ecdev && e1000_maybe_stop_tx(netdev, count + 2)) fp@2407: return NETDEV_TX_BUSY; fp@2407: fp@2407: if (vlan_tx_tag_present(skb)) { fp@2407: tx_flags |= E1000_TX_FLAGS_VLAN; fp@2407: tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); fp@2407: } fp@2407: fp@2407: first = tx_ring->next_to_use; fp@2407: fp@2407: tso = e1000_tso(adapter, skb); fp@2407: if (tso < 0) { fp@2407: if (!adapter->ecdev) fp@2407: dev_kfree_skb_any(skb); fp@2407: return NETDEV_TX_OK; fp@2407: } fp@2407: fp@2407: if (tso) fp@2407: tx_flags |= E1000_TX_FLAGS_TSO; fp@2407: else if (e1000_tx_csum(adapter, skb)) fp@2407: tx_flags |= E1000_TX_FLAGS_CSUM; fp@2407: fp@2407: /* fp@2407: * Old method was to assume IPv4 packet by default if TSO was enabled. fp@2407: * 82571 hardware supports TSO capabilities for IPv6 as well... fp@2407: * no longer assume, we must. fp@2407: */ fp@2407: if (skb->protocol == htons(ETH_P_IP)) fp@2407: tx_flags |= E1000_TX_FLAGS_IPV4; fp@2407: fp@2407: /* if count is 0 then mapping error has occurred */ fp@2407: count = e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss); fp@2407: if (count) { fp@2407: e1000_tx_queue(adapter, tx_flags, count); fp@2407: /* Make sure there is space in the ring for the next send. */ fp@2407: if (!adapter->ecdev) fp@2407: e1000_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 2); fp@2407: fp@2407: } else { fp@2407: if (!adapter->ecdev) fp@2407: dev_kfree_skb_any(skb); fp@2407: tx_ring->buffer_info[first].time_stamp = 0; fp@2407: tx_ring->next_to_use = first; fp@2407: } fp@2407: fp@2407: return NETDEV_TX_OK; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_tx_timeout - Respond to a Tx Hang fp@2407: * @netdev: network interface device structure fp@2407: **/ fp@2407: static void e1000_tx_timeout(struct net_device *netdev) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: /* Do the reset outside of interrupt context */ fp@2407: adapter->tx_timeout_count++; fp@2407: schedule_work(&adapter->reset_task); fp@2407: } fp@2407: fp@2407: static void e1000_reset_task(struct work_struct *work) fp@2407: { fp@2407: struct e1000_adapter *adapter; fp@2407: adapter = container_of(work, struct e1000_adapter, reset_task); fp@2407: fp@2407: /* don't run the task if already down */ fp@2407: if (test_bit(__E1000_DOWN, &adapter->state)) fp@2407: return; fp@2407: fp@2407: if (!((adapter->flags & FLAG_RX_NEEDS_RESTART) && fp@2407: (adapter->flags & FLAG_RX_RESTART_NOW))) { fp@2407: e1000e_dump(adapter); fp@2407: e_err("Reset adapter\n"); fp@2407: } fp@2407: e1000e_reinit_locked(adapter); fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_get_stats64 - Get System Network Statistics fp@2407: * @netdev: network interface device structure fp@2407: * @stats: rtnl_link_stats64 pointer fp@2407: * fp@2407: * Returns the address of the device statistics structure. fp@2407: **/ fp@2407: struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev, fp@2407: struct rtnl_link_stats64 *stats) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: memset(stats, 0, sizeof(struct rtnl_link_stats64)); fp@2407: spin_lock(&adapter->stats64_lock); fp@2407: e1000e_update_stats(adapter); fp@2407: /* Fill out the OS statistics structure */ fp@2407: stats->rx_bytes = adapter->stats.gorc; fp@2407: stats->rx_packets = adapter->stats.gprc; fp@2407: stats->tx_bytes = adapter->stats.gotc; fp@2407: stats->tx_packets = adapter->stats.gptc; fp@2407: stats->multicast = adapter->stats.mprc; fp@2407: stats->collisions = adapter->stats.colc; fp@2407: fp@2407: /* Rx Errors */ fp@2407: fp@2407: /* fp@2407: * RLEC on some newer hardware can be incorrect so build fp@2407: * our own version based on RUC and ROC fp@2407: */ fp@2407: stats->rx_errors = adapter->stats.rxerrc + fp@2407: adapter->stats.crcerrs + adapter->stats.algnerrc + fp@2407: adapter->stats.ruc + adapter->stats.roc + fp@2407: adapter->stats.cexterr; fp@2407: stats->rx_length_errors = adapter->stats.ruc + fp@2407: adapter->stats.roc; fp@2407: stats->rx_crc_errors = adapter->stats.crcerrs; fp@2407: stats->rx_frame_errors = adapter->stats.algnerrc; fp@2407: stats->rx_missed_errors = adapter->stats.mpc; fp@2407: fp@2407: /* Tx Errors */ fp@2407: stats->tx_errors = adapter->stats.ecol + fp@2407: adapter->stats.latecol; fp@2407: stats->tx_aborted_errors = adapter->stats.ecol; fp@2407: stats->tx_window_errors = adapter->stats.latecol; fp@2407: stats->tx_carrier_errors = adapter->stats.tncrs; fp@2407: fp@2407: /* Tx Dropped needs to be maintained elsewhere */ fp@2407: fp@2407: spin_unlock(&adapter->stats64_lock); fp@2407: return stats; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_change_mtu - Change the Maximum Transfer Unit fp@2407: * @netdev: network interface device structure fp@2407: * @new_mtu: new value for maximum frame size fp@2407: * fp@2407: * Returns 0 on success, negative on failure fp@2407: **/ fp@2407: static int e1000_change_mtu(struct net_device *netdev, int new_mtu) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; fp@2407: fp@2407: if (adapter->ecdev) fp@2407: return -EBUSY; fp@2407: fp@2407: /* Jumbo frame support */ fp@2407: if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) && fp@2407: !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) { fp@2407: e_err("Jumbo Frames not supported.\n"); fp@2407: return -EINVAL; fp@2407: } fp@2407: fp@2407: /* Supported frame sizes */ fp@2407: if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) || fp@2407: (max_frame > adapter->max_hw_frame_size)) { fp@2407: e_err("Unsupported MTU setting\n"); fp@2407: return -EINVAL; fp@2407: } fp@2407: fp@2407: /* Jumbo frame workaround on 82579 requires CRC be stripped */ fp@2407: if ((adapter->hw.mac.type == e1000_pch2lan) && fp@2407: !(adapter->flags2 & FLAG2_CRC_STRIPPING) && fp@2407: (new_mtu > ETH_DATA_LEN)) { fp@2407: e_err("Jumbo Frames not supported on 82579 when CRC " fp@2407: "stripping is disabled.\n"); fp@2407: return -EINVAL; fp@2407: } fp@2407: fp@2407: /* 82573 Errata 17 */ fp@2407: if (((adapter->hw.mac.type == e1000_82573) || fp@2407: (adapter->hw.mac.type == e1000_82574)) && fp@2407: (max_frame > ETH_FRAME_LEN + ETH_FCS_LEN)) { fp@2407: adapter->flags2 |= FLAG2_DISABLE_ASPM_L1; fp@2407: e1000e_disable_aspm(adapter->pdev, PCIE_LINK_STATE_L1); fp@2407: } fp@2407: fp@2407: while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) fp@2407: usleep_range(1000, 2000); fp@2407: /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */ fp@2407: adapter->max_frame_size = max_frame; fp@2407: e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu); fp@2407: netdev->mtu = new_mtu; fp@2407: if (netif_running(netdev)) fp@2407: e1000e_down(adapter); fp@2407: fp@2407: /* fp@2407: * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN fp@2407: * means we reserve 2 more, this pushes us to allocate from the next fp@2407: * larger slab size. fp@2407: * i.e. RXBUFFER_2048 --> size-4096 slab fp@2407: * However with the new *_jumbo_rx* routines, jumbo receives will use fp@2407: * fragmented skbs fp@2407: */ fp@2407: fp@2407: if (max_frame <= 2048) fp@2407: adapter->rx_buffer_len = 2048; fp@2407: else fp@2407: adapter->rx_buffer_len = 4096; fp@2407: fp@2407: /* adjust allocation if LPE protects us, and we aren't using SBP */ fp@2407: if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || fp@2407: (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)) fp@2407: adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN fp@2407: + ETH_FCS_LEN; fp@2407: fp@2407: if (netif_running(netdev)) fp@2407: e1000e_up(adapter); fp@2407: else fp@2407: e1000e_reset(adapter); fp@2407: fp@2407: clear_bit(__E1000_RESETTING, &adapter->state); fp@2407: fp@2407: return 0; fp@2407: } fp@2407: fp@2407: static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, fp@2407: int cmd) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct mii_ioctl_data *data = if_mii(ifr); fp@2407: fp@2407: if (adapter->hw.phy.media_type != e1000_media_type_copper) fp@2407: return -EOPNOTSUPP; fp@2407: fp@2407: switch (cmd) { fp@2407: case SIOCGMIIPHY: fp@2407: data->phy_id = adapter->hw.phy.addr; fp@2407: break; fp@2407: case SIOCGMIIREG: fp@2407: e1000_phy_read_status(adapter); fp@2407: fp@2407: switch (data->reg_num & 0x1F) { fp@2407: case MII_BMCR: fp@2407: data->val_out = adapter->phy_regs.bmcr; fp@2407: break; fp@2407: case MII_BMSR: fp@2407: data->val_out = adapter->phy_regs.bmsr; fp@2407: break; fp@2407: case MII_PHYSID1: fp@2407: data->val_out = (adapter->hw.phy.id >> 16); fp@2407: break; fp@2407: case MII_PHYSID2: fp@2407: data->val_out = (adapter->hw.phy.id & 0xFFFF); fp@2407: break; fp@2407: case MII_ADVERTISE: fp@2407: data->val_out = adapter->phy_regs.advertise; fp@2407: break; fp@2407: case MII_LPA: fp@2407: data->val_out = adapter->phy_regs.lpa; fp@2407: break; fp@2407: case MII_EXPANSION: fp@2407: data->val_out = adapter->phy_regs.expansion; fp@2407: break; fp@2407: case MII_CTRL1000: fp@2407: data->val_out = adapter->phy_regs.ctrl1000; fp@2407: break; fp@2407: case MII_STAT1000: fp@2407: data->val_out = adapter->phy_regs.stat1000; fp@2407: break; fp@2407: case MII_ESTATUS: fp@2407: data->val_out = adapter->phy_regs.estatus; fp@2407: break; fp@2407: default: fp@2407: return -EIO; fp@2407: } fp@2407: break; fp@2407: case SIOCSMIIREG: fp@2407: default: fp@2407: return -EOPNOTSUPP; fp@2407: } fp@2407: return 0; fp@2407: } fp@2407: fp@2407: static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) fp@2407: { fp@2407: switch (cmd) { fp@2407: case SIOCGMIIPHY: fp@2407: case SIOCGMIIREG: fp@2407: case SIOCSMIIREG: fp@2407: return e1000_mii_ioctl(netdev, ifr, cmd); fp@2407: default: fp@2407: return -EOPNOTSUPP; fp@2407: } fp@2407: } fp@2407: fp@2407: static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 i, mac_reg; fp@2407: u16 phy_reg, wuc_enable; fp@2407: int retval = 0; fp@2407: fp@2407: /* copy MAC RARs to PHY RARs */ fp@2407: e1000_copy_rx_addrs_to_phy_ich8lan(hw); fp@2407: fp@2407: retval = hw->phy.ops.acquire(hw); fp@2407: if (retval) { fp@2407: e_err("Could not acquire PHY\n"); fp@2407: return retval; fp@2407: } fp@2407: fp@2407: /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */ fp@2407: retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable); fp@2407: if (retval) fp@2407: goto out; fp@2407: fp@2407: /* copy MAC MTA to PHY MTA - only needed for pchlan */ fp@2407: for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) { fp@2407: mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i); fp@2407: hw->phy.ops.write_reg_page(hw, BM_MTA(i), fp@2407: (u16)(mac_reg & 0xFFFF)); fp@2407: hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1, fp@2407: (u16)((mac_reg >> 16) & 0xFFFF)); fp@2407: } fp@2407: fp@2407: /* configure PHY Rx Control register */ fp@2407: hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg); fp@2407: mac_reg = er32(RCTL); fp@2407: if (mac_reg & E1000_RCTL_UPE) fp@2407: phy_reg |= BM_RCTL_UPE; fp@2407: if (mac_reg & E1000_RCTL_MPE) fp@2407: phy_reg |= BM_RCTL_MPE; fp@2407: phy_reg &= ~(BM_RCTL_MO_MASK); fp@2407: if (mac_reg & E1000_RCTL_MO_3) fp@2407: phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT) fp@2407: << BM_RCTL_MO_SHIFT); fp@2407: if (mac_reg & E1000_RCTL_BAM) fp@2407: phy_reg |= BM_RCTL_BAM; fp@2407: if (mac_reg & E1000_RCTL_PMCF) fp@2407: phy_reg |= BM_RCTL_PMCF; fp@2407: mac_reg = er32(CTRL); fp@2407: if (mac_reg & E1000_CTRL_RFCE) fp@2407: phy_reg |= BM_RCTL_RFCE; fp@2407: hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg); fp@2407: fp@2407: /* enable PHY wakeup in MAC register */ fp@2407: ew32(WUFC, wufc); fp@2407: ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN); fp@2407: fp@2407: /* configure and enable PHY wakeup in PHY registers */ fp@2407: hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc); fp@2407: hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN); fp@2407: fp@2407: /* activate PHY wakeup */ fp@2407: wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT; fp@2407: retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable); fp@2407: if (retval) fp@2407: e_err("Could not set PHY Host Wakeup bit\n"); fp@2407: out: fp@2407: hw->phy.ops.release(hw); fp@2407: fp@2407: return retval; fp@2407: } fp@2407: fp@2407: static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake, fp@2407: bool runtime) fp@2407: { fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u32 ctrl, ctrl_ext, rctl, status; fp@2407: /* Runtime suspend should only enable wakeup for link changes */ fp@2407: u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol; fp@2407: int retval = 0; fp@2407: fp@2407: netif_device_detach(netdev); fp@2407: fp@2407: if (netif_running(netdev)) { fp@2407: WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); fp@2407: e1000e_down(adapter); fp@2407: e1000_free_irq(adapter); fp@2407: } fp@2407: e1000e_reset_interrupt_capability(adapter); fp@2407: fp@2407: retval = pci_save_state(pdev); fp@2407: if (retval) fp@2407: return retval; fp@2407: fp@2407: status = er32(STATUS); fp@2407: if (status & E1000_STATUS_LU) fp@2407: wufc &= ~E1000_WUFC_LNKC; fp@2407: fp@2407: if (wufc) { fp@2407: e1000_setup_rctl(adapter); fp@2407: e1000_set_multi(netdev); fp@2407: fp@2407: /* turn on all-multi mode if wake on multicast is enabled */ fp@2407: if (wufc & E1000_WUFC_MC) { fp@2407: rctl = er32(RCTL); fp@2407: rctl |= E1000_RCTL_MPE; fp@2407: ew32(RCTL, rctl); fp@2407: } fp@2407: fp@2407: ctrl = er32(CTRL); fp@2407: /* advertise wake from D3Cold */ fp@2407: #define E1000_CTRL_ADVD3WUC 0x00100000 fp@2407: /* phy power management enable */ fp@2407: #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 fp@2407: ctrl |= E1000_CTRL_ADVD3WUC; fp@2407: if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP)) fp@2407: ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT; fp@2407: ew32(CTRL, ctrl); fp@2407: fp@2407: if (adapter->hw.phy.media_type == e1000_media_type_fiber || fp@2407: adapter->hw.phy.media_type == fp@2407: e1000_media_type_internal_serdes) { fp@2407: /* keep the laser running in D3 */ fp@2407: ctrl_ext = er32(CTRL_EXT); fp@2407: ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA; fp@2407: ew32(CTRL_EXT, ctrl_ext); fp@2407: } fp@2407: fp@2407: if (adapter->flags & FLAG_IS_ICH) fp@2407: e1000_suspend_workarounds_ich8lan(&adapter->hw); fp@2407: fp@2407: /* Allow time for pending master requests to run */ fp@2407: e1000e_disable_pcie_master(&adapter->hw); fp@2407: fp@2407: if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { fp@2407: /* enable wakeup by the PHY */ fp@2407: retval = e1000_init_phy_wakeup(adapter, wufc); fp@2407: if (retval) fp@2407: return retval; fp@2407: } else { fp@2407: /* enable wakeup by the MAC */ fp@2407: ew32(WUFC, wufc); fp@2407: ew32(WUC, E1000_WUC_PME_EN); fp@2407: } fp@2407: } else { fp@2407: ew32(WUC, 0); fp@2407: ew32(WUFC, 0); fp@2407: } fp@2407: fp@2407: *enable_wake = !!wufc; fp@2407: fp@2407: /* make sure adapter isn't asleep if manageability is enabled */ fp@2407: if ((adapter->flags & FLAG_MNG_PT_ENABLED) || fp@2407: (hw->mac.ops.check_mng_mode(hw))) fp@2407: *enable_wake = true; fp@2407: fp@2407: if (adapter->hw.phy.type == e1000_phy_igp_3) fp@2407: e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw); fp@2407: fp@2407: /* fp@2407: * Release control of h/w to f/w. If f/w is AMT enabled, this fp@2407: * would have already happened in close and is redundant. fp@2407: */ fp@2407: e1000e_release_hw_control(adapter); fp@2407: fp@2407: pci_disable_device(pdev); fp@2407: fp@2407: return 0; fp@2407: } fp@2407: fp@2407: static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake) fp@2407: { fp@2407: if (sleep && wake) { fp@2407: pci_prepare_to_sleep(pdev); fp@2407: return; fp@2407: } fp@2407: fp@2407: pci_wake_from_d3(pdev, wake); fp@2407: pci_set_power_state(pdev, PCI_D3hot); fp@2407: } fp@2407: fp@2407: static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, fp@2407: bool wake) fp@2407: { fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: /* fp@2407: * The pci-e switch on some quad port adapters will report a fp@2407: * correctable error when the MAC transitions from D0 to D3. To fp@2407: * prevent this we need to mask off the correctable errors on the fp@2407: * downstream port of the pci-e switch. fp@2407: */ fp@2407: if (adapter->flags & FLAG_IS_QUAD_PORT) { fp@2407: struct pci_dev *us_dev = pdev->bus->self; fp@2407: int pos = pci_pcie_cap(us_dev); fp@2407: u16 devctl; fp@2407: fp@2407: pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl); fp@2407: pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, fp@2407: (devctl & ~PCI_EXP_DEVCTL_CERE)); fp@2407: fp@2407: e1000_power_off(pdev, sleep, wake); fp@2407: fp@2407: pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl); fp@2407: } else { fp@2407: e1000_power_off(pdev, sleep, wake); fp@2407: } fp@2407: } fp@2407: fp@2407: #ifdef CONFIG_PCIEASPM fp@2407: static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) fp@2407: { fp@2407: pci_disable_link_state_locked(pdev, state); fp@2407: } fp@2407: #else fp@2407: static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) fp@2407: { fp@2407: int pos; fp@2407: u16 reg16; fp@2407: fp@2407: /* fp@2407: * Both device and parent should have the same ASPM setting. fp@2407: * Disable ASPM in downstream component first and then upstream. fp@2407: */ fp@2407: pos = pci_pcie_cap(pdev); fp@2407: pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16); fp@2407: reg16 &= ~state; fp@2407: pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16); fp@2407: fp@2407: if (!pdev->bus->self) fp@2407: return; fp@2407: fp@2407: pos = pci_pcie_cap(pdev->bus->self); fp@2407: pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, ®16); fp@2407: reg16 &= ~state; fp@2407: pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16); fp@2407: } fp@2407: #endif fp@2407: static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) fp@2407: { fp@2407: dev_info(&pdev->dev, "Disabling ASPM %s %s\n", fp@2407: (state & PCIE_LINK_STATE_L0S) ? "L0s" : "", fp@2407: (state & PCIE_LINK_STATE_L1) ? "L1" : ""); fp@2407: fp@2407: __e1000e_disable_aspm(pdev, state); fp@2407: } fp@2407: fp@2407: #ifdef CONFIG_PM fp@2407: static bool e1000e_pm_ready(struct e1000_adapter *adapter) fp@2407: { fp@2407: return !!adapter->tx_ring->buffer_info; fp@2407: } fp@2407: fp@2407: static int __e1000_resume(struct pci_dev *pdev) fp@2407: { fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u16 aspm_disable_flag = 0; fp@2407: u32 err; fp@2407: fp@2407: if (adapter->ecdev) fp@2407: return -EBUSY; fp@2407: fp@2407: if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) fp@2407: aspm_disable_flag = PCIE_LINK_STATE_L0S; fp@2407: if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) fp@2407: aspm_disable_flag |= PCIE_LINK_STATE_L1; fp@2407: if (aspm_disable_flag) fp@2407: e1000e_disable_aspm(pdev, aspm_disable_flag); fp@2407: fp@2407: pci_set_power_state(pdev, PCI_D0); fp@2407: pci_restore_state(pdev); fp@2407: pci_save_state(pdev); fp@2407: fp@2407: e1000e_set_interrupt_capability(adapter); fp@2407: if (netif_running(netdev)) { fp@2407: err = e1000_request_irq(adapter); fp@2407: if (err) fp@2407: return err; fp@2407: } fp@2407: fp@2407: if (hw->mac.type == e1000_pch2lan) fp@2407: e1000_resume_workarounds_pchlan(&adapter->hw); fp@2407: fp@2407: e1000e_power_up_phy(adapter); fp@2407: fp@2407: /* report the system wakeup cause from S3/S4 */ fp@2407: if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) { fp@2407: u16 phy_data; fp@2407: fp@2407: e1e_rphy(&adapter->hw, BM_WUS, &phy_data); fp@2407: if (phy_data) { fp@2407: e_info("PHY Wakeup cause - %s\n", fp@2407: phy_data & E1000_WUS_EX ? "Unicast Packet" : fp@2407: phy_data & E1000_WUS_MC ? "Multicast Packet" : fp@2407: phy_data & E1000_WUS_BC ? "Broadcast Packet" : fp@2407: phy_data & E1000_WUS_MAG ? "Magic Packet" : fp@2407: phy_data & E1000_WUS_LNKC ? "Link Status " fp@2407: " Change" : "other"); fp@2407: } fp@2407: e1e_wphy(&adapter->hw, BM_WUS, ~0); fp@2407: } else { fp@2407: u32 wus = er32(WUS); fp@2407: if (wus) { fp@2407: e_info("MAC Wakeup cause - %s\n", fp@2407: wus & E1000_WUS_EX ? "Unicast Packet" : fp@2407: wus & E1000_WUS_MC ? "Multicast Packet" : fp@2407: wus & E1000_WUS_BC ? "Broadcast Packet" : fp@2407: wus & E1000_WUS_MAG ? "Magic Packet" : fp@2407: wus & E1000_WUS_LNKC ? "Link Status Change" : fp@2407: "other"); fp@2407: } fp@2407: ew32(WUS, ~0); fp@2407: } fp@2407: fp@2407: e1000e_reset(adapter); fp@2407: fp@2407: e1000_init_manageability_pt(adapter); fp@2407: fp@2407: if (netif_running(netdev)) fp@2407: e1000e_up(adapter); fp@2407: fp@2407: netif_device_attach(netdev); fp@2407: fp@2407: /* fp@2407: * If the controller has AMT, do not set DRV_LOAD until the interface fp@2407: * is up. For all other cases, let the f/w know that the h/w is now fp@2407: * under the control of the driver. fp@2407: */ fp@2407: if (!(adapter->flags & FLAG_HAS_AMT)) fp@2407: e1000e_get_hw_control(adapter); fp@2407: fp@2407: return 0; fp@2407: } fp@2407: fp@2407: #ifdef CONFIG_PM_SLEEP fp@2407: static int e1000_suspend(struct device *dev) fp@2407: { fp@2407: struct pci_dev *pdev = to_pci_dev(dev); fp@2407: int retval; fp@2407: bool wake; fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: if (adapter->ecdev) fp@2407: return -EBUSY; fp@2407: fp@2407: retval = __e1000_shutdown(pdev, &wake, false); fp@2407: if (!retval) fp@2407: e1000_complete_shutdown(pdev, true, wake); fp@2407: fp@2407: return retval; fp@2407: } fp@2407: fp@2407: static int e1000_resume(struct device *dev) fp@2407: { fp@2407: struct pci_dev *pdev = to_pci_dev(dev); fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: if (e1000e_pm_ready(adapter)) fp@2407: adapter->idle_check = true; fp@2407: fp@2407: return __e1000_resume(pdev); fp@2407: } fp@2407: #endif /* CONFIG_PM_SLEEP */ fp@2407: fp@2407: #ifdef CONFIG_PM_RUNTIME fp@2407: static int e1000_runtime_suspend(struct device *dev) fp@2407: { fp@2407: struct pci_dev *pdev = to_pci_dev(dev); fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: if (e1000e_pm_ready(adapter)) { fp@2407: bool wake; fp@2407: fp@2407: __e1000_shutdown(pdev, &wake, true); fp@2407: } fp@2407: fp@2407: return 0; fp@2407: } fp@2407: fp@2407: static int e1000_idle(struct device *dev) fp@2407: { fp@2407: struct pci_dev *pdev = to_pci_dev(dev); fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: if (!e1000e_pm_ready(adapter)) fp@2407: return 0; fp@2407: fp@2407: if (adapter->idle_check) { fp@2407: adapter->idle_check = false; fp@2407: if (!e1000e_has_link(adapter)) fp@2407: pm_schedule_suspend(dev, MSEC_PER_SEC); fp@2407: } fp@2407: fp@2407: return -EBUSY; fp@2407: } fp@2407: fp@2407: static int e1000_runtime_resume(struct device *dev) fp@2407: { fp@2407: struct pci_dev *pdev = to_pci_dev(dev); fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: if (!e1000e_pm_ready(adapter)) fp@2407: return 0; fp@2407: fp@2407: adapter->idle_check = !dev->power.runtime_auto; fp@2407: return __e1000_resume(pdev); fp@2407: } fp@2407: #endif /* CONFIG_PM_RUNTIME */ fp@2407: #endif /* CONFIG_PM */ fp@2407: fp@2407: static void e1000_shutdown(struct pci_dev *pdev) fp@2407: { fp@2407: bool wake = false; fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2421: fp@2407: if (adapter->ecdev) fp@2407: return; fp@2407: fp@2407: __e1000_shutdown(pdev, &wake, false); fp@2407: fp@2407: if (system_state == SYSTEM_POWER_OFF) fp@2407: e1000_complete_shutdown(pdev, false, wake); fp@2407: } fp@2407: fp@2407: #ifdef CONFIG_NET_POLL_CONTROLLER fp@2407: fp@2407: static irqreturn_t e1000_intr_msix(int irq, void *data) fp@2407: { fp@2407: struct net_device *netdev = data; fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: if (adapter->msix_entries) { fp@2407: int vector, msix_irq; fp@2407: fp@2407: vector = 0; fp@2407: msix_irq = adapter->msix_entries[vector].vector; fp@2407: disable_irq(msix_irq); fp@2407: e1000_intr_msix_rx(msix_irq, netdev); fp@2407: enable_irq(msix_irq); fp@2407: fp@2407: vector++; fp@2407: msix_irq = adapter->msix_entries[vector].vector; fp@2407: disable_irq(msix_irq); fp@2407: e1000_intr_msix_tx(msix_irq, netdev); fp@2407: enable_irq(msix_irq); fp@2407: fp@2407: vector++; fp@2407: msix_irq = adapter->msix_entries[vector].vector; fp@2407: disable_irq(msix_irq); fp@2407: e1000_msix_other(msix_irq, netdev); fp@2407: enable_irq(msix_irq); fp@2407: } fp@2407: fp@2407: return IRQ_HANDLED; fp@2407: } fp@2407: fp@2407: /* fp@2407: * Polling 'interrupt' - used by things like netconsole to send skbs fp@2407: * without having to re-enable interrupts. It's not called while fp@2407: * the interrupt routine is executing. fp@2407: */ fp@2407: static void e1000_netpoll(struct net_device *netdev) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: switch (adapter->int_mode) { fp@2407: case E1000E_INT_MODE_MSIX: fp@2407: e1000_intr_msix(adapter->pdev->irq, netdev); fp@2407: break; fp@2407: case E1000E_INT_MODE_MSI: fp@2407: disable_irq(adapter->pdev->irq); fp@2407: e1000_intr_msi(adapter->pdev->irq, netdev); fp@2407: enable_irq(adapter->pdev->irq); fp@2407: break; fp@2407: default: /* E1000E_INT_MODE_LEGACY */ fp@2407: disable_irq(adapter->pdev->irq); fp@2407: e1000_intr(adapter->pdev->irq, netdev); fp@2407: enable_irq(adapter->pdev->irq); fp@2407: break; fp@2407: } fp@2407: } fp@2407: #endif fp@2407: fp@2407: /** fp@2407: * e1000_io_error_detected - called when PCI error is detected fp@2407: * @pdev: Pointer to PCI device fp@2407: * @state: The current pci connection state fp@2407: * fp@2407: * This function is called after a PCI bus error affecting fp@2407: * this device has been detected. fp@2407: */ fp@2407: static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, fp@2407: pci_channel_state_t state) fp@2407: { fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: netif_device_detach(netdev); fp@2407: fp@2407: if (state == pci_channel_io_perm_failure) fp@2407: return PCI_ERS_RESULT_DISCONNECT; fp@2407: fp@2407: if (netif_running(netdev)) fp@2407: e1000e_down(adapter); fp@2407: pci_disable_device(pdev); fp@2407: fp@2407: /* Request a slot slot reset. */ fp@2407: return PCI_ERS_RESULT_NEED_RESET; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_io_slot_reset - called after the pci bus has been reset. fp@2407: * @pdev: Pointer to PCI device fp@2407: * fp@2407: * Restart the card from scratch, as if from a cold-boot. Implementation fp@2407: * resembles the first-half of the e1000_resume routine. fp@2407: */ fp@2407: static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) fp@2407: { fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: u16 aspm_disable_flag = 0; fp@2407: int err; fp@2407: pci_ers_result_t result; fp@2407: fp@2407: if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S) fp@2407: aspm_disable_flag = PCIE_LINK_STATE_L0S; fp@2407: if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1) fp@2407: aspm_disable_flag |= PCIE_LINK_STATE_L1; fp@2407: if (aspm_disable_flag) fp@2407: e1000e_disable_aspm(pdev, aspm_disable_flag); fp@2407: fp@2407: err = pci_enable_device_mem(pdev); fp@2407: if (err) { fp@2407: dev_err(&pdev->dev, fp@2407: "Cannot re-enable PCI device after reset.\n"); fp@2407: result = PCI_ERS_RESULT_DISCONNECT; fp@2407: } else { fp@2407: pci_set_master(pdev); fp@2407: pdev->state_saved = true; fp@2407: pci_restore_state(pdev); fp@2407: fp@2407: pci_enable_wake(pdev, PCI_D3hot, 0); fp@2407: pci_enable_wake(pdev, PCI_D3cold, 0); fp@2407: fp@2407: e1000e_reset(adapter); fp@2407: ew32(WUS, ~0); fp@2407: result = PCI_ERS_RESULT_RECOVERED; fp@2407: } fp@2407: fp@2407: pci_cleanup_aer_uncorrect_error_status(pdev); fp@2407: fp@2407: return result; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_io_resume - called when traffic can start flowing again. fp@2407: * @pdev: Pointer to PCI device fp@2407: * fp@2407: * This callback is called when the error recovery driver tells us that fp@2407: * its OK to resume normal operation. Implementation resembles the fp@2407: * second-half of the e1000_resume routine. fp@2407: */ fp@2407: static void e1000_io_resume(struct pci_dev *pdev) fp@2407: { fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: e1000_init_manageability_pt(adapter); fp@2407: fp@2407: if (netif_running(netdev)) { fp@2407: if (e1000e_up(adapter)) { fp@2407: dev_err(&pdev->dev, fp@2407: "can't bring device back up after reset\n"); fp@2407: return; fp@2407: } fp@2407: } fp@2407: fp@2407: netif_device_attach(netdev); fp@2407: fp@2407: /* fp@2407: * If the controller has AMT, do not set DRV_LOAD until the interface fp@2407: * is up. For all other cases, let the f/w know that the h/w is now fp@2407: * under the control of the driver. fp@2407: */ fp@2407: if (!(adapter->flags & FLAG_HAS_AMT)) fp@2407: e1000e_get_hw_control(adapter); fp@2407: fp@2407: } fp@2407: fp@2407: static void e1000_print_device_info(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: struct net_device *netdev = adapter->netdev; fp@2407: u32 ret_val; fp@2407: u8 pba_str[E1000_PBANUM_LENGTH]; fp@2407: fp@2407: /* print bus type/speed/width info */ fp@2407: e_info("(PCI Express:2.5GT/s:%s) %pM\n", fp@2407: /* bus width */ fp@2407: ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : fp@2407: "Width x1"), fp@2407: /* MAC address */ fp@2407: netdev->dev_addr); fp@2407: e_info("Intel(R) PRO/%s Network Connection\n", fp@2407: (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000"); fp@2407: ret_val = e1000_read_pba_string_generic(hw, pba_str, fp@2407: E1000_PBANUM_LENGTH); fp@2407: if (ret_val) fp@2407: strncpy((char *)pba_str, "Unknown", sizeof(pba_str) - 1); fp@2407: e_info("MAC: %d, PHY: %d, PBA No: %s\n", fp@2407: hw->mac.type, hw->phy.type, pba_str); fp@2407: } fp@2407: fp@2407: static void e1000_eeprom_checks(struct e1000_adapter *adapter) fp@2407: { fp@2407: struct e1000_hw *hw = &adapter->hw; fp@2407: int ret_val; fp@2407: u16 buf = 0; fp@2407: fp@2407: if (hw->mac.type != e1000_82573) fp@2407: return; fp@2407: fp@2407: ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf); fp@2407: if (!ret_val && (!(le16_to_cpu(buf) & (1 << 0)))) { fp@2407: /* Deep Smart Power Down (DSPD) */ fp@2407: dev_warn(&adapter->pdev->dev, fp@2407: "Warning: detected DSPD enabled in EEPROM\n"); fp@2407: } fp@2407: } fp@2407: fp@2407: static int e1000_set_features(struct net_device *netdev, u32 features) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: u32 changed = features ^ netdev->features; fp@2407: fp@2407: if (changed & (NETIF_F_TSO | NETIF_F_TSO6)) fp@2407: adapter->flags |= FLAG_TSO_FORCE; fp@2407: fp@2407: if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX | fp@2407: NETIF_F_RXCSUM))) fp@2407: return 0; fp@2407: fp@2407: if (netif_running(netdev)) fp@2407: e1000e_reinit_locked(adapter); fp@2407: else fp@2407: e1000e_reset(adapter); fp@2407: fp@2407: return 0; fp@2407: } fp@2407: fp@2407: static const struct net_device_ops e1000e_netdev_ops = { fp@2407: .ndo_open = e1000_open, fp@2407: .ndo_stop = e1000_close, fp@2407: .ndo_start_xmit = e1000_xmit_frame, fp@2407: .ndo_get_stats64 = e1000e_get_stats64, fp@2407: .ndo_set_rx_mode = e1000_set_multi, fp@2407: .ndo_set_mac_address = e1000_set_mac, fp@2407: .ndo_change_mtu = e1000_change_mtu, fp@2407: .ndo_do_ioctl = e1000_ioctl, fp@2407: .ndo_tx_timeout = e1000_tx_timeout, fp@2407: .ndo_validate_addr = eth_validate_addr, fp@2407: fp@2407: .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, fp@2407: .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, fp@2407: #ifdef CONFIG_NET_POLL_CONTROLLER fp@2407: .ndo_poll_controller = e1000_netpoll, fp@2407: #endif fp@2407: .ndo_set_features = e1000_set_features, fp@2407: }; fp@2407: fp@2407: /** fp@2407: * ec_poll - Ethercat poll Routine fp@2407: * @netdev: net device structure fp@2407: * fp@2407: * This function can never fail. fp@2407: * fp@2407: **/ fp@2407: void ec_poll(struct net_device *netdev) fp@2407: { fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: fp@2407: if (jiffies - adapter->ec_watchdog_jiffies >= 2 * HZ) { fp@2407: e1000_watchdog((unsigned long) adapter); fp@2407: adapter->ec_watchdog_jiffies = jiffies; fp@2407: } fp@2407: fp@2407: #ifdef CONFIG_PCI_MSI fp@2407: e1000_intr_msi(0,netdev); fp@2407: #else fp@2407: e1000_intr(0,netdev); fp@2407: #endif fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_probe - Device Initialization Routine fp@2407: * @pdev: PCI device information struct fp@2407: * @ent: entry in e1000_pci_tbl fp@2407: * fp@2407: * Returns 0 on success, negative on failure fp@2407: * fp@2407: * e1000_probe initializes an adapter identified by a pci_dev structure. fp@2407: * The OS initialization, configuring of the adapter private structure, fp@2407: * and a hardware reset occur. fp@2407: **/ fp@2407: static int __devinit e1000_probe(struct pci_dev *pdev, fp@2407: const struct pci_device_id *ent) fp@2407: { fp@2407: struct net_device *netdev; fp@2407: struct e1000_adapter *adapter; fp@2407: struct e1000_hw *hw; fp@2407: const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; fp@2407: resource_size_t mmio_start, mmio_len; fp@2407: resource_size_t flash_start, flash_len; fp@2407: fp@2407: static int cards_found; fp@2407: u16 aspm_disable_flag = 0; fp@2407: int i, err, pci_using_dac; fp@2407: u16 eeprom_data = 0; fp@2407: u16 eeprom_apme_mask = E1000_EEPROM_APME; fp@2407: fp@2407: if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S) fp@2407: aspm_disable_flag = PCIE_LINK_STATE_L0S; fp@2407: if (ei->flags2 & FLAG2_DISABLE_ASPM_L1) fp@2407: aspm_disable_flag |= PCIE_LINK_STATE_L1; fp@2407: if (aspm_disable_flag) fp@2407: e1000e_disable_aspm(pdev, aspm_disable_flag); fp@2407: fp@2407: err = pci_enable_device_mem(pdev); fp@2407: if (err) fp@2407: return err; fp@2407: fp@2407: pci_using_dac = 0; fp@2407: err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); fp@2407: if (!err) { fp@2407: err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); fp@2407: if (!err) fp@2407: pci_using_dac = 1; fp@2407: } else { fp@2407: err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); fp@2407: if (err) { fp@2407: err = dma_set_coherent_mask(&pdev->dev, fp@2407: DMA_BIT_MASK(32)); fp@2407: if (err) { fp@2407: dev_err(&pdev->dev, "No usable DMA " fp@2407: "configuration, aborting\n"); fp@2407: goto err_dma; fp@2407: } fp@2407: } fp@2407: } fp@2407: fp@2407: err = pci_request_selected_regions_exclusive(pdev, fp@2407: pci_select_bars(pdev, IORESOURCE_MEM), fp@2407: e1000e_driver_name); fp@2407: if (err) fp@2407: goto err_pci_reg; fp@2407: fp@2407: /* AER (Advanced Error Reporting) hooks */ fp@2407: pci_enable_pcie_error_reporting(pdev); fp@2407: fp@2407: pci_set_master(pdev); fp@2407: /* PCI config space info */ fp@2407: err = pci_save_state(pdev); fp@2407: if (err) fp@2407: goto err_alloc_etherdev; fp@2407: fp@2407: err = -ENOMEM; fp@2407: netdev = alloc_etherdev(sizeof(struct e1000_adapter)); fp@2407: if (!netdev) fp@2407: goto err_alloc_etherdev; fp@2407: fp@2407: SET_NETDEV_DEV(netdev, &pdev->dev); fp@2407: fp@2407: netdev->irq = pdev->irq; fp@2407: fp@2407: pci_set_drvdata(pdev, netdev); fp@2407: adapter = netdev_priv(netdev); fp@2407: hw = &adapter->hw; fp@2407: adapter->netdev = netdev; fp@2407: adapter->pdev = pdev; fp@2407: adapter->ei = ei; fp@2407: adapter->pba = ei->pba; fp@2407: adapter->flags = ei->flags; fp@2407: adapter->flags2 = ei->flags2; fp@2407: adapter->hw.adapter = adapter; fp@2407: adapter->hw.mac.type = ei->mac; fp@2407: adapter->max_hw_frame_size = ei->max_hw_frame_size; fp@2407: adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1; fp@2407: fp@2407: mmio_start = pci_resource_start(pdev, 0); fp@2407: mmio_len = pci_resource_len(pdev, 0); fp@2407: fp@2407: err = -EIO; fp@2407: adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); fp@2407: if (!adapter->hw.hw_addr) fp@2407: goto err_ioremap; fp@2407: fp@2407: if ((adapter->flags & FLAG_HAS_FLASH) && fp@2407: (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { fp@2407: flash_start = pci_resource_start(pdev, 1); fp@2407: flash_len = pci_resource_len(pdev, 1); fp@2407: adapter->hw.flash_address = ioremap(flash_start, flash_len); fp@2407: if (!adapter->hw.flash_address) fp@2407: goto err_flashmap; fp@2407: } fp@2407: fp@2407: /* construct the net_device struct */ fp@2407: netdev->netdev_ops = &e1000e_netdev_ops; fp@2407: e1000e_set_ethtool_ops(netdev); fp@2407: netdev->watchdog_timeo = 5 * HZ; fp@2407: netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); fp@2407: strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); fp@2407: fp@2407: netdev->mem_start = mmio_start; fp@2407: netdev->mem_end = mmio_start + mmio_len; fp@2407: fp@2407: adapter->bd_number = cards_found++; fp@2407: fp@2407: e1000e_check_options(adapter); fp@2407: fp@2407: /* setup adapter struct */ fp@2407: err = e1000_sw_init(adapter); fp@2407: if (err) fp@2407: goto err_sw_init; fp@2407: fp@2407: memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); fp@2407: memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); fp@2407: memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); fp@2407: fp@2407: err = ei->get_variants(adapter); fp@2407: if (err) fp@2407: goto err_hw_init; fp@2407: fp@2407: if ((adapter->flags & FLAG_IS_ICH) && fp@2407: (adapter->flags & FLAG_READ_ONLY_NVM)) fp@2407: e1000e_write_protect_nvm_ich8lan(&adapter->hw); fp@2407: fp@2407: hw->mac.ops.get_bus_info(&adapter->hw); fp@2407: fp@2407: adapter->hw.phy.autoneg_wait_to_complete = 0; fp@2407: fp@2407: /* Copper options */ fp@2407: if (adapter->hw.phy.media_type == e1000_media_type_copper) { fp@2407: adapter->hw.phy.mdix = AUTO_ALL_MODES; fp@2407: adapter->hw.phy.disable_polarity_correction = 0; fp@2407: adapter->hw.phy.ms_type = e1000_ms_hw_default; fp@2407: } fp@2407: fp@2407: if (e1000_check_reset_block(&adapter->hw)) fp@2407: e_info("PHY reset is blocked due to SOL/IDER session.\n"); fp@2407: fp@2407: /* Set initial default active device features */ fp@2407: netdev->features = (NETIF_F_SG | fp@2407: NETIF_F_HW_VLAN_RX | fp@2407: NETIF_F_HW_VLAN_TX | fp@2407: NETIF_F_TSO | fp@2407: NETIF_F_TSO6 | fp@2407: NETIF_F_RXCSUM | fp@2407: NETIF_F_HW_CSUM); fp@2407: fp@2407: /* Set user-changeable features (subset of all device features) */ fp@2407: netdev->hw_features = netdev->features; fp@2407: fp@2407: if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) fp@2407: netdev->features |= NETIF_F_HW_VLAN_FILTER; fp@2407: fp@2407: netdev->vlan_features |= (NETIF_F_SG | fp@2407: NETIF_F_TSO | fp@2407: NETIF_F_TSO6 | fp@2407: NETIF_F_HW_CSUM); fp@2407: fp@2407: if (pci_using_dac) { fp@2407: netdev->features |= NETIF_F_HIGHDMA; fp@2407: netdev->vlan_features |= NETIF_F_HIGHDMA; fp@2407: } fp@2407: fp@2407: if (e1000e_enable_mng_pass_thru(&adapter->hw)) fp@2407: adapter->flags |= FLAG_MNG_PT_ENABLED; fp@2407: fp@2407: /* fp@2407: * before reading the NVM, reset the controller to fp@2407: * put the device in a known good starting state fp@2407: */ fp@2407: adapter->hw.mac.ops.reset_hw(&adapter->hw); fp@2407: fp@2407: /* fp@2407: * systems with ASPM and others may see the checksum fail on the first fp@2407: * attempt. Let's give it a few tries fp@2407: */ fp@2407: for (i = 0;; i++) { fp@2407: if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) fp@2407: break; fp@2407: if (i == 2) { fp@2407: e_err("The NVM Checksum Is Not Valid\n"); fp@2407: err = -EIO; fp@2407: goto err_eeprom; fp@2407: } fp@2407: } fp@2407: fp@2407: e1000_eeprom_checks(adapter); fp@2407: fp@2407: /* copy the MAC address */ fp@2407: if (e1000e_read_mac_addr(&adapter->hw)) fp@2407: e_err("NVM Read Error while reading MAC address\n"); fp@2407: fp@2407: memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); fp@2407: memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); fp@2407: fp@2407: if (!is_valid_ether_addr(netdev->perm_addr)) { fp@2407: e_err("Invalid MAC Address: %pM\n", netdev->perm_addr); fp@2407: err = -EIO; fp@2407: goto err_eeprom; fp@2407: } fp@2407: fp@2407: init_timer(&adapter->watchdog_timer); fp@2407: adapter->watchdog_timer.function = e1000_watchdog; fp@2407: adapter->watchdog_timer.data = (unsigned long) adapter; fp@2407: fp@2407: init_timer(&adapter->phy_info_timer); fp@2407: adapter->phy_info_timer.function = e1000_update_phy_info; fp@2407: adapter->phy_info_timer.data = (unsigned long) adapter; fp@2407: fp@2407: INIT_WORK(&adapter->reset_task, e1000_reset_task); fp@2407: INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); fp@2407: INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround); fp@2407: INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task); fp@2407: INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang); fp@2407: fp@2407: /* Initialize link parameters. User can change them with ethtool */ fp@2407: adapter->hw.mac.autoneg = 1; fp@2407: adapter->fc_autoneg = 1; fp@2407: adapter->hw.fc.requested_mode = e1000_fc_default; fp@2407: adapter->hw.fc.current_mode = e1000_fc_default; fp@2407: adapter->hw.phy.autoneg_advertised = 0x2f; fp@2407: fp@2407: /* ring size defaults */ fp@2407: adapter->rx_ring->count = 256; fp@2407: adapter->tx_ring->count = 256; fp@2407: fp@2407: /* fp@2407: * Initial Wake on LAN setting - If APM wake is enabled in fp@2407: * the EEPROM, enable the ACPI Magic Packet filter fp@2407: */ fp@2407: if (adapter->flags & FLAG_APME_IN_WUC) { fp@2407: /* APME bit in EEPROM is mapped to WUC.APME */ fp@2407: eeprom_data = er32(WUC); fp@2407: eeprom_apme_mask = E1000_WUC_APME; fp@2407: if ((hw->mac.type > e1000_ich10lan) && fp@2407: (eeprom_data & E1000_WUC_PHY_WAKE)) fp@2407: adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP; fp@2407: } else if (adapter->flags & FLAG_APME_IN_CTRL3) { fp@2407: if (adapter->flags & FLAG_APME_CHECK_PORT_B && fp@2407: (adapter->hw.bus.func == 1)) fp@2407: e1000_read_nvm(&adapter->hw, fp@2407: NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); fp@2407: else fp@2407: e1000_read_nvm(&adapter->hw, fp@2407: NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); fp@2407: } fp@2407: fp@2407: /* fetch WoL from EEPROM */ fp@2407: if (eeprom_data & eeprom_apme_mask) fp@2407: adapter->eeprom_wol |= E1000_WUFC_MAG; fp@2407: fp@2407: /* fp@2407: * now that we have the eeprom settings, apply the special cases fp@2407: * where the eeprom may be wrong or the board simply won't support fp@2407: * wake on lan on a particular port fp@2407: */ fp@2407: if (!(adapter->flags & FLAG_HAS_WOL)) fp@2407: adapter->eeprom_wol = 0; fp@2407: fp@2407: /* initialize the wol settings based on the eeprom settings */ fp@2407: adapter->wol = adapter->eeprom_wol; fp@2407: device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); fp@2407: fp@2407: /* save off EEPROM version number */ fp@2407: e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers); fp@2407: fp@2407: /* reset the hardware with the new settings */ fp@2407: e1000e_reset(adapter); fp@2407: fp@2407: /* fp@2407: * If the controller has AMT, do not set DRV_LOAD until the interface fp@2407: * is up. For all other cases, let the f/w know that the h/w is now fp@2407: * under the control of the driver. fp@2407: */ fp@2407: if (!(adapter->flags & FLAG_HAS_AMT)) fp@2407: e1000e_get_hw_control(adapter); fp@2407: fp@2407: adapter->ecdev = ecdev_offer(netdev, ec_poll, THIS_MODULE); fp@2407: if (adapter->ecdev) { fp@2407: if (ecdev_open(adapter->ecdev)) { fp@2407: ecdev_withdraw(adapter->ecdev); fp@2407: goto err_register; fp@2407: } fp@2407: } else { fp@2407: strncpy(netdev->name, "eth%d", sizeof(netdev->name) - 1); fp@2407: err = register_netdev(netdev); fp@2407: if (err) fp@2407: goto err_register; fp@2407: fp@2407: /* carrier off reporting is important to ethtool even BEFORE open */ fp@2407: netif_carrier_off(netdev); fp@2407: } fp@2407: fp@2407: e1000_print_device_info(adapter); fp@2407: fp@2407: if (pci_dev_run_wake(pdev)) fp@2407: pm_runtime_put_noidle(&pdev->dev); fp@2407: fp@2407: return 0; fp@2407: fp@2407: err_register: fp@2407: if (!(adapter->flags & FLAG_HAS_AMT)) fp@2407: e1000e_release_hw_control(adapter); fp@2407: err_eeprom: fp@2407: if (!e1000_check_reset_block(&adapter->hw)) fp@2407: e1000_phy_hw_reset(&adapter->hw); fp@2407: err_hw_init: fp@2407: kfree(adapter->tx_ring); fp@2407: kfree(adapter->rx_ring); fp@2407: err_sw_init: fp@2407: if (adapter->hw.flash_address) fp@2407: iounmap(adapter->hw.flash_address); fp@2407: e1000e_reset_interrupt_capability(adapter); fp@2407: err_flashmap: fp@2407: iounmap(adapter->hw.hw_addr); fp@2407: err_ioremap: fp@2407: free_netdev(netdev); fp@2407: err_alloc_etherdev: fp@2407: pci_release_selected_regions(pdev, fp@2407: pci_select_bars(pdev, IORESOURCE_MEM)); fp@2407: err_pci_reg: fp@2407: err_dma: fp@2407: pci_disable_device(pdev); fp@2407: return err; fp@2407: } fp@2407: fp@2407: /** fp@2407: * e1000_remove - Device Removal Routine fp@2407: * @pdev: PCI device information struct fp@2407: * fp@2407: * e1000_remove is called by the PCI subsystem to alert the driver fp@2407: * that it should release a PCI device. The could be caused by a fp@2407: * Hot-Plug event, or because the driver is going to be removed from fp@2407: * memory. fp@2407: **/ fp@2407: static void __devexit e1000_remove(struct pci_dev *pdev) fp@2407: { fp@2407: struct net_device *netdev = pci_get_drvdata(pdev); fp@2407: struct e1000_adapter *adapter = netdev_priv(netdev); fp@2407: bool down = test_bit(__E1000_DOWN, &adapter->state); fp@2407: fp@2407: /* fp@2407: * The timers may be rescheduled, so explicitly disable them fp@2407: * from being rescheduled. fp@2407: */ fp@2407: if (!down) fp@2407: set_bit(__E1000_DOWN, &adapter->state); fp@2407: del_timer_sync(&adapter->watchdog_timer); fp@2407: del_timer_sync(&adapter->phy_info_timer); fp@2407: fp@2407: cancel_work_sync(&adapter->reset_task); fp@2407: cancel_work_sync(&adapter->watchdog_task); fp@2407: cancel_work_sync(&adapter->downshift_task); fp@2407: cancel_work_sync(&adapter->update_phy_task); fp@2407: cancel_work_sync(&adapter->print_hang_task); fp@2407: fp@2407: if (!(netdev->flags & IFF_UP)) fp@2407: e1000_power_down_phy(adapter); fp@2407: fp@2407: /* Don't lie to e1000_close() down the road. */ fp@2407: if (!down) fp@2407: clear_bit(__E1000_DOWN, &adapter->state); fp@2407: fp@2407: if (adapter->ecdev) { fp@2407: ecdev_close(adapter->ecdev); fp@2407: ecdev_withdraw(adapter->ecdev); fp@2407: } else { fp@2407: unregister_netdev(netdev); fp@2407: } fp@2407: fp@2407: if (pci_dev_run_wake(pdev)) fp@2407: pm_runtime_get_noresume(&pdev->dev); fp@2407: fp@2407: /* fp@2407: * Release control of h/w to f/w. If f/w is AMT enabled, this fp@2407: * would have already happened in close and is redundant. fp@2407: */ fp@2407: e1000e_release_hw_control(adapter); fp@2407: fp@2407: e1000e_reset_interrupt_capability(adapter); fp@2407: kfree(adapter->tx_ring); fp@2407: kfree(adapter->rx_ring); fp@2407: fp@2407: iounmap(adapter->hw.hw_addr); fp@2407: if (adapter->hw.flash_address) fp@2407: iounmap(adapter->hw.flash_address); fp@2407: pci_release_selected_regions(pdev, fp@2407: pci_select_bars(pdev, IORESOURCE_MEM)); fp@2407: fp@2407: free_netdev(netdev); fp@2407: fp@2407: /* AER disable */ fp@2407: pci_disable_pcie_error_reporting(pdev); fp@2407: fp@2407: pci_disable_device(pdev); fp@2407: } fp@2407: fp@2407: /* PCI Error Recovery (ERS) */ fp@2407: static struct pci_error_handlers e1000_err_handler = { fp@2407: .error_detected = e1000_io_error_detected, fp@2407: .slot_reset = e1000_io_slot_reset, fp@2407: .resume = e1000_io_resume, fp@2407: }; fp@2407: fp@2407: static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = { fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 }, fp@2407: fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 }, fp@2407: fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 }, fp@2407: fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 }, fp@2407: fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT), fp@2407: board_80003es2lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT), fp@2407: board_80003es2lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT), fp@2407: board_80003es2lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT), fp@2407: board_80003es2lan }, fp@2407: fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan }, fp@2407: fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan }, fp@2407: fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan }, fp@2407: fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan }, fp@2407: fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan }, fp@2407: fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan }, fp@2407: { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan }, fp@2407: fp@2407: { } /* terminate list */ fp@2407: }; fp@2407: //MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); fp@2407: fp@2407: #ifdef CONFIG_PM fp@2407: static const struct dev_pm_ops e1000_pm_ops = { fp@2407: SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume) fp@2407: SET_RUNTIME_PM_OPS(e1000_runtime_suspend, fp@2407: e1000_runtime_resume, e1000_idle) fp@2407: }; fp@2407: #endif fp@2407: fp@2407: /* PCI Device API Driver */ fp@2407: static struct pci_driver e1000_driver = { fp@2407: .name = e1000e_driver_name, fp@2407: .id_table = e1000_pci_tbl, fp@2407: .probe = e1000_probe, fp@2407: .remove = __devexit_p(e1000_remove), fp@2407: #ifdef CONFIG_PM fp@2407: .driver.pm = &e1000_pm_ops, fp@2407: #endif fp@2407: .shutdown = e1000_shutdown, fp@2407: .err_handler = &e1000_err_handler fp@2407: }; fp@2407: fp@2407: /** fp@2407: * e1000_init_module - Driver Registration Routine fp@2407: * fp@2407: * e1000_init_module is the first routine called when the driver is fp@2407: * loaded. All it does is register with the PCI subsystem. fp@2407: **/ fp@2407: static int __init e1000_init_module(void) fp@2407: { fp@2407: int ret; fp@2407: pr_info("EtherCAT-capable Intel(R) PRO/1000 Network Driver - %s\n", fp@2407: e1000e_driver_version); fp@2407: pr_info("Copyright(c) 1999 - 2011 Intel Corporation.\n"); fp@2407: ret = pci_register_driver(&e1000_driver); fp@2407: fp@2407: return ret; fp@2407: } fp@2407: module_init(e1000_init_module); fp@2407: fp@2407: /** fp@2407: * e1000_exit_module - Driver Exit Cleanup Routine fp@2407: * fp@2407: * e1000_exit_module is called just before the driver is removed fp@2407: * from memory. fp@2407: **/ fp@2407: static void __exit e1000_exit_module(void) fp@2407: { fp@2407: pci_unregister_driver(&e1000_driver); fp@2407: } fp@2407: module_exit(e1000_exit_module); fp@2407: fp@2407: fp@2407: MODULE_AUTHOR("Intel Corporation, "); fp@2407: MODULE_DESCRIPTION("Ethercat-capable Intel(R) PRO/1000 Network Driver"); fp@2407: MODULE_LICENSE("GPL"); fp@2407: MODULE_VERSION(DRV_VERSION); fp@2407: fp@2407: /* e1000_main.c */