18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* Copyright(c) 1999 - 2006 Intel Corporation. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci/* 58c2ecf20Sopenharmony_ci * e100.c: Intel(R) PRO/100 ethernet driver 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * (Re)written 2003 by scott.feldman@intel.com. Based loosely on 88c2ecf20Sopenharmony_ci * original e100 driver, but better described as a munging of 98c2ecf20Sopenharmony_ci * e100, e1000, eepro100, tg3, 8139cp, and other drivers. 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * References: 128c2ecf20Sopenharmony_ci * Intel 8255x 10/100 Mbps Ethernet Controller Family, 138c2ecf20Sopenharmony_ci * Open Source Software Developers Manual, 148c2ecf20Sopenharmony_ci * http://sourceforge.net/projects/e1000 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * 178c2ecf20Sopenharmony_ci * Theory of Operation 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * I. General 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * The driver supports Intel(R) 10/100 Mbps PCI Fast Ethernet 228c2ecf20Sopenharmony_ci * controller family, which includes the 82557, 82558, 82559, 82550, 238c2ecf20Sopenharmony_ci * 82551, and 82562 devices. 82558 and greater controllers 248c2ecf20Sopenharmony_ci * integrate the Intel 82555 PHY. The controllers are used in 258c2ecf20Sopenharmony_ci * server and client network interface cards, as well as in 268c2ecf20Sopenharmony_ci * LAN-On-Motherboard (LOM), CardBus, MiniPCI, and ICHx 278c2ecf20Sopenharmony_ci * configurations. 8255x supports a 32-bit linear addressing 288c2ecf20Sopenharmony_ci * mode and operates at 33Mhz PCI clock rate. 298c2ecf20Sopenharmony_ci * 308c2ecf20Sopenharmony_ci * II. Driver Operation 318c2ecf20Sopenharmony_ci * 328c2ecf20Sopenharmony_ci * Memory-mapped mode is used exclusively to access the device's 338c2ecf20Sopenharmony_ci * shared-memory structure, the Control/Status Registers (CSR). All 348c2ecf20Sopenharmony_ci * setup, configuration, and control of the device, including queuing 358c2ecf20Sopenharmony_ci * of Tx, Rx, and configuration commands is through the CSR. 368c2ecf20Sopenharmony_ci * cmd_lock serializes accesses to the CSR command register. cb_lock 378c2ecf20Sopenharmony_ci * protects the shared Command Block List (CBL). 388c2ecf20Sopenharmony_ci * 398c2ecf20Sopenharmony_ci * 8255x is highly MII-compliant and all access to the PHY go 408c2ecf20Sopenharmony_ci * through the Management Data Interface (MDI). Consequently, the 418c2ecf20Sopenharmony_ci * driver leverages the mii.c library shared with other MII-compliant 428c2ecf20Sopenharmony_ci * devices. 438c2ecf20Sopenharmony_ci * 448c2ecf20Sopenharmony_ci * Big- and Little-Endian byte order as well as 32- and 64-bit 458c2ecf20Sopenharmony_ci * archs are supported. Weak-ordered memory and non-cache-coherent 468c2ecf20Sopenharmony_ci * archs are supported. 478c2ecf20Sopenharmony_ci * 488c2ecf20Sopenharmony_ci * III. Transmit 498c2ecf20Sopenharmony_ci * 508c2ecf20Sopenharmony_ci * A Tx skb is mapped and hangs off of a TCB. TCBs are linked 518c2ecf20Sopenharmony_ci * together in a fixed-size ring (CBL) thus forming the flexible mode 528c2ecf20Sopenharmony_ci * memory structure. A TCB marked with the suspend-bit indicates 538c2ecf20Sopenharmony_ci * the end of the ring. The last TCB processed suspends the 548c2ecf20Sopenharmony_ci * controller, and the controller can be restarted by issue a CU 558c2ecf20Sopenharmony_ci * resume command to continue from the suspend point, or a CU start 568c2ecf20Sopenharmony_ci * command to start at a given position in the ring. 578c2ecf20Sopenharmony_ci * 588c2ecf20Sopenharmony_ci * Non-Tx commands (config, multicast setup, etc) are linked 598c2ecf20Sopenharmony_ci * into the CBL ring along with Tx commands. The common structure 608c2ecf20Sopenharmony_ci * used for both Tx and non-Tx commands is the Command Block (CB). 618c2ecf20Sopenharmony_ci * 628c2ecf20Sopenharmony_ci * cb_to_use is the next CB to use for queuing a command; cb_to_clean 638c2ecf20Sopenharmony_ci * is the next CB to check for completion; cb_to_send is the first 648c2ecf20Sopenharmony_ci * CB to start on in case of a previous failure to resume. CB clean 658c2ecf20Sopenharmony_ci * up happens in interrupt context in response to a CU interrupt. 668c2ecf20Sopenharmony_ci * cbs_avail keeps track of number of free CB resources available. 678c2ecf20Sopenharmony_ci * 688c2ecf20Sopenharmony_ci * Hardware padding of short packets to minimum packet size is 698c2ecf20Sopenharmony_ci * enabled. 82557 pads with 7Eh, while the later controllers pad 708c2ecf20Sopenharmony_ci * with 00h. 718c2ecf20Sopenharmony_ci * 728c2ecf20Sopenharmony_ci * IV. Receive 738c2ecf20Sopenharmony_ci * 748c2ecf20Sopenharmony_ci * The Receive Frame Area (RFA) comprises a ring of Receive Frame 758c2ecf20Sopenharmony_ci * Descriptors (RFD) + data buffer, thus forming the simplified mode 768c2ecf20Sopenharmony_ci * memory structure. Rx skbs are allocated to contain both the RFD 778c2ecf20Sopenharmony_ci * and the data buffer, but the RFD is pulled off before the skb is 788c2ecf20Sopenharmony_ci * indicated. The data buffer is aligned such that encapsulated 798c2ecf20Sopenharmony_ci * protocol headers are u32-aligned. Since the RFD is part of the 808c2ecf20Sopenharmony_ci * mapped shared memory, and completion status is contained within 818c2ecf20Sopenharmony_ci * the RFD, the RFD must be dma_sync'ed to maintain a consistent 828c2ecf20Sopenharmony_ci * view from software and hardware. 838c2ecf20Sopenharmony_ci * 848c2ecf20Sopenharmony_ci * In order to keep updates to the RFD link field from colliding with 858c2ecf20Sopenharmony_ci * hardware writes to mark packets complete, we use the feature that 868c2ecf20Sopenharmony_ci * hardware will not write to a size 0 descriptor and mark the previous 878c2ecf20Sopenharmony_ci * packet as end-of-list (EL). After updating the link, we remove EL 888c2ecf20Sopenharmony_ci * and only then restore the size such that hardware may use the 898c2ecf20Sopenharmony_ci * previous-to-end RFD. 908c2ecf20Sopenharmony_ci * 918c2ecf20Sopenharmony_ci * Under typical operation, the receive unit (RU) is start once, 928c2ecf20Sopenharmony_ci * and the controller happily fills RFDs as frames arrive. If 938c2ecf20Sopenharmony_ci * replacement RFDs cannot be allocated, or the RU goes non-active, 948c2ecf20Sopenharmony_ci * the RU must be restarted. Frame arrival generates an interrupt, 958c2ecf20Sopenharmony_ci * and Rx indication and re-allocation happen in the same context, 968c2ecf20Sopenharmony_ci * therefore no locking is required. A software-generated interrupt 978c2ecf20Sopenharmony_ci * is generated from the watchdog to recover from a failed allocation 988c2ecf20Sopenharmony_ci * scenario where all Rx resources have been indicated and none re- 998c2ecf20Sopenharmony_ci * placed. 1008c2ecf20Sopenharmony_ci * 1018c2ecf20Sopenharmony_ci * V. Miscellaneous 1028c2ecf20Sopenharmony_ci * 1038c2ecf20Sopenharmony_ci * VLAN offloading of tagging, stripping and filtering is not 1048c2ecf20Sopenharmony_ci * supported, but driver will accommodate the extra 4-byte VLAN tag 1058c2ecf20Sopenharmony_ci * for processing by upper layers. Tx/Rx Checksum offloading is not 1068c2ecf20Sopenharmony_ci * supported. Tx Scatter/Gather is not supported. Jumbo Frames is 1078c2ecf20Sopenharmony_ci * not supported (hardware limitation). 1088c2ecf20Sopenharmony_ci * 1098c2ecf20Sopenharmony_ci * MagicPacket(tm) WoL support is enabled/disabled via ethtool. 1108c2ecf20Sopenharmony_ci * 1118c2ecf20Sopenharmony_ci * Thanks to JC (jchapman@katalix.com) for helping with 1128c2ecf20Sopenharmony_ci * testing/troubleshooting the development driver. 1138c2ecf20Sopenharmony_ci * 1148c2ecf20Sopenharmony_ci * TODO: 1158c2ecf20Sopenharmony_ci * o several entry points race with dev->close 1168c2ecf20Sopenharmony_ci * o check for tx-no-resources/stop Q races with tx clean/wake Q 1178c2ecf20Sopenharmony_ci * 1188c2ecf20Sopenharmony_ci * FIXES: 1198c2ecf20Sopenharmony_ci * 2005/12/02 - Michael O'Donnell <Michael.ODonnell at stratus dot com> 1208c2ecf20Sopenharmony_ci * - Stratus87247: protect MDI control register manipulations 1218c2ecf20Sopenharmony_ci * 2009/06/01 - Andreas Mohr <andi at lisas dot de> 1228c2ecf20Sopenharmony_ci * - add clean lowlevel I/O emulation for cards with MII-lacking PHYs 1238c2ecf20Sopenharmony_ci */ 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#include <linux/hardirq.h> 1288c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 1298c2ecf20Sopenharmony_ci#include <linux/module.h> 1308c2ecf20Sopenharmony_ci#include <linux/moduleparam.h> 1318c2ecf20Sopenharmony_ci#include <linux/kernel.h> 1328c2ecf20Sopenharmony_ci#include <linux/types.h> 1338c2ecf20Sopenharmony_ci#include <linux/sched.h> 1348c2ecf20Sopenharmony_ci#include <linux/slab.h> 1358c2ecf20Sopenharmony_ci#include <linux/delay.h> 1368c2ecf20Sopenharmony_ci#include <linux/init.h> 1378c2ecf20Sopenharmony_ci#include <linux/pci.h> 1388c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h> 1398c2ecf20Sopenharmony_ci#include <linux/dmapool.h> 1408c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 1418c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 1428c2ecf20Sopenharmony_ci#include <linux/mii.h> 1438c2ecf20Sopenharmony_ci#include <linux/if_vlan.h> 1448c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 1458c2ecf20Sopenharmony_ci#include <linux/ethtool.h> 1468c2ecf20Sopenharmony_ci#include <linux/string.h> 1478c2ecf20Sopenharmony_ci#include <linux/firmware.h> 1488c2ecf20Sopenharmony_ci#include <linux/rtnetlink.h> 1498c2ecf20Sopenharmony_ci#include <asm/unaligned.h> 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci#define DRV_NAME "e100" 1538c2ecf20Sopenharmony_ci#define DRV_DESCRIPTION "Intel(R) PRO/100 Network Driver" 1548c2ecf20Sopenharmony_ci#define DRV_COPYRIGHT "Copyright(c) 1999-2006 Intel Corporation" 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci#define E100_WATCHDOG_PERIOD (2 * HZ) 1578c2ecf20Sopenharmony_ci#define E100_NAPI_WEIGHT 16 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci#define FIRMWARE_D101M "e100/d101m_ucode.bin" 1608c2ecf20Sopenharmony_ci#define FIRMWARE_D101S "e100/d101s_ucode.bin" 1618c2ecf20Sopenharmony_ci#define FIRMWARE_D102E "e100/d102e_ucode.bin" 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ciMODULE_DESCRIPTION(DRV_DESCRIPTION); 1648c2ecf20Sopenharmony_ciMODULE_AUTHOR(DRV_COPYRIGHT); 1658c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 1668c2ecf20Sopenharmony_ciMODULE_FIRMWARE(FIRMWARE_D101M); 1678c2ecf20Sopenharmony_ciMODULE_FIRMWARE(FIRMWARE_D101S); 1688c2ecf20Sopenharmony_ciMODULE_FIRMWARE(FIRMWARE_D102E); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_cistatic int debug = 3; 1718c2ecf20Sopenharmony_cistatic int eeprom_bad_csum_allow = 0; 1728c2ecf20Sopenharmony_cistatic int use_io = 0; 1738c2ecf20Sopenharmony_cimodule_param(debug, int, 0); 1748c2ecf20Sopenharmony_cimodule_param(eeprom_bad_csum_allow, int, 0); 1758c2ecf20Sopenharmony_cimodule_param(use_io, int, 0); 1768c2ecf20Sopenharmony_ciMODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 1778c2ecf20Sopenharmony_ciMODULE_PARM_DESC(eeprom_bad_csum_allow, "Allow bad eeprom checksums"); 1788c2ecf20Sopenharmony_ciMODULE_PARM_DESC(use_io, "Force use of i/o access mode"); 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci#define INTEL_8255X_ETHERNET_DEVICE(device_id, ich) {\ 1818c2ecf20Sopenharmony_ci PCI_VENDOR_ID_INTEL, device_id, PCI_ANY_ID, PCI_ANY_ID, \ 1828c2ecf20Sopenharmony_ci PCI_CLASS_NETWORK_ETHERNET << 8, 0xFFFF00, ich } 1838c2ecf20Sopenharmony_cistatic const struct pci_device_id e100_id_table[] = { 1848c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1029, 0), 1858c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1030, 0), 1868c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1031, 3), 1878c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1032, 3), 1888c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1033, 3), 1898c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1034, 3), 1908c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1038, 3), 1918c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1039, 4), 1928c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x103A, 4), 1938c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x103B, 4), 1948c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x103C, 4), 1958c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x103D, 4), 1968c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x103E, 4), 1978c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1050, 5), 1988c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1051, 5), 1998c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1052, 5), 2008c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1053, 5), 2018c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1054, 5), 2028c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1055, 5), 2038c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1056, 5), 2048c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1057, 5), 2058c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1059, 0), 2068c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1064, 6), 2078c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1065, 6), 2088c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1066, 6), 2098c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1067, 6), 2108c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1068, 6), 2118c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1069, 6), 2128c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x106A, 6), 2138c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x106B, 6), 2148c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1091, 7), 2158c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1092, 7), 2168c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1093, 7), 2178c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1094, 7), 2188c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1095, 7), 2198c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x10fe, 7), 2208c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1209, 0), 2218c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x1229, 0), 2228c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x2449, 2), 2238c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x2459, 2), 2248c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x245D, 2), 2258c2ecf20Sopenharmony_ci INTEL_8255X_ETHERNET_DEVICE(0x27DC, 7), 2268c2ecf20Sopenharmony_ci { 0, } 2278c2ecf20Sopenharmony_ci}; 2288c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, e100_id_table); 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_cienum mac { 2318c2ecf20Sopenharmony_ci mac_82557_D100_A = 0, 2328c2ecf20Sopenharmony_ci mac_82557_D100_B = 1, 2338c2ecf20Sopenharmony_ci mac_82557_D100_C = 2, 2348c2ecf20Sopenharmony_ci mac_82558_D101_A4 = 4, 2358c2ecf20Sopenharmony_ci mac_82558_D101_B0 = 5, 2368c2ecf20Sopenharmony_ci mac_82559_D101M = 8, 2378c2ecf20Sopenharmony_ci mac_82559_D101S = 9, 2388c2ecf20Sopenharmony_ci mac_82550_D102 = 12, 2398c2ecf20Sopenharmony_ci mac_82550_D102_C = 13, 2408c2ecf20Sopenharmony_ci mac_82551_E = 14, 2418c2ecf20Sopenharmony_ci mac_82551_F = 15, 2428c2ecf20Sopenharmony_ci mac_82551_10 = 16, 2438c2ecf20Sopenharmony_ci mac_unknown = 0xFF, 2448c2ecf20Sopenharmony_ci}; 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_cienum phy { 2478c2ecf20Sopenharmony_ci phy_100a = 0x000003E0, 2488c2ecf20Sopenharmony_ci phy_100c = 0x035002A8, 2498c2ecf20Sopenharmony_ci phy_82555_tx = 0x015002A8, 2508c2ecf20Sopenharmony_ci phy_nsc_tx = 0x5C002000, 2518c2ecf20Sopenharmony_ci phy_82562_et = 0x033002A8, 2528c2ecf20Sopenharmony_ci phy_82562_em = 0x032002A8, 2538c2ecf20Sopenharmony_ci phy_82562_ek = 0x031002A8, 2548c2ecf20Sopenharmony_ci phy_82562_eh = 0x017002A8, 2558c2ecf20Sopenharmony_ci phy_82552_v = 0xd061004d, 2568c2ecf20Sopenharmony_ci phy_unknown = 0xFFFFFFFF, 2578c2ecf20Sopenharmony_ci}; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci/* CSR (Control/Status Registers) */ 2608c2ecf20Sopenharmony_cistruct csr { 2618c2ecf20Sopenharmony_ci struct { 2628c2ecf20Sopenharmony_ci u8 status; 2638c2ecf20Sopenharmony_ci u8 stat_ack; 2648c2ecf20Sopenharmony_ci u8 cmd_lo; 2658c2ecf20Sopenharmony_ci u8 cmd_hi; 2668c2ecf20Sopenharmony_ci u32 gen_ptr; 2678c2ecf20Sopenharmony_ci } scb; 2688c2ecf20Sopenharmony_ci u32 port; 2698c2ecf20Sopenharmony_ci u16 flash_ctrl; 2708c2ecf20Sopenharmony_ci u8 eeprom_ctrl_lo; 2718c2ecf20Sopenharmony_ci u8 eeprom_ctrl_hi; 2728c2ecf20Sopenharmony_ci u32 mdi_ctrl; 2738c2ecf20Sopenharmony_ci u32 rx_dma_count; 2748c2ecf20Sopenharmony_ci}; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_cienum scb_status { 2778c2ecf20Sopenharmony_ci rus_no_res = 0x08, 2788c2ecf20Sopenharmony_ci rus_ready = 0x10, 2798c2ecf20Sopenharmony_ci rus_mask = 0x3C, 2808c2ecf20Sopenharmony_ci}; 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_cienum ru_state { 2838c2ecf20Sopenharmony_ci RU_SUSPENDED = 0, 2848c2ecf20Sopenharmony_ci RU_RUNNING = 1, 2858c2ecf20Sopenharmony_ci RU_UNINITIALIZED = -1, 2868c2ecf20Sopenharmony_ci}; 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_cienum scb_stat_ack { 2898c2ecf20Sopenharmony_ci stat_ack_not_ours = 0x00, 2908c2ecf20Sopenharmony_ci stat_ack_sw_gen = 0x04, 2918c2ecf20Sopenharmony_ci stat_ack_rnr = 0x10, 2928c2ecf20Sopenharmony_ci stat_ack_cu_idle = 0x20, 2938c2ecf20Sopenharmony_ci stat_ack_frame_rx = 0x40, 2948c2ecf20Sopenharmony_ci stat_ack_cu_cmd_done = 0x80, 2958c2ecf20Sopenharmony_ci stat_ack_not_present = 0xFF, 2968c2ecf20Sopenharmony_ci stat_ack_rx = (stat_ack_sw_gen | stat_ack_rnr | stat_ack_frame_rx), 2978c2ecf20Sopenharmony_ci stat_ack_tx = (stat_ack_cu_idle | stat_ack_cu_cmd_done), 2988c2ecf20Sopenharmony_ci}; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_cienum scb_cmd_hi { 3018c2ecf20Sopenharmony_ci irq_mask_none = 0x00, 3028c2ecf20Sopenharmony_ci irq_mask_all = 0x01, 3038c2ecf20Sopenharmony_ci irq_sw_gen = 0x02, 3048c2ecf20Sopenharmony_ci}; 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_cienum scb_cmd_lo { 3078c2ecf20Sopenharmony_ci cuc_nop = 0x00, 3088c2ecf20Sopenharmony_ci ruc_start = 0x01, 3098c2ecf20Sopenharmony_ci ruc_load_base = 0x06, 3108c2ecf20Sopenharmony_ci cuc_start = 0x10, 3118c2ecf20Sopenharmony_ci cuc_resume = 0x20, 3128c2ecf20Sopenharmony_ci cuc_dump_addr = 0x40, 3138c2ecf20Sopenharmony_ci cuc_dump_stats = 0x50, 3148c2ecf20Sopenharmony_ci cuc_load_base = 0x60, 3158c2ecf20Sopenharmony_ci cuc_dump_reset = 0x70, 3168c2ecf20Sopenharmony_ci}; 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_cienum cuc_dump { 3198c2ecf20Sopenharmony_ci cuc_dump_complete = 0x0000A005, 3208c2ecf20Sopenharmony_ci cuc_dump_reset_complete = 0x0000A007, 3218c2ecf20Sopenharmony_ci}; 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_cienum port { 3248c2ecf20Sopenharmony_ci software_reset = 0x0000, 3258c2ecf20Sopenharmony_ci selftest = 0x0001, 3268c2ecf20Sopenharmony_ci selective_reset = 0x0002, 3278c2ecf20Sopenharmony_ci}; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_cienum eeprom_ctrl_lo { 3308c2ecf20Sopenharmony_ci eesk = 0x01, 3318c2ecf20Sopenharmony_ci eecs = 0x02, 3328c2ecf20Sopenharmony_ci eedi = 0x04, 3338c2ecf20Sopenharmony_ci eedo = 0x08, 3348c2ecf20Sopenharmony_ci}; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_cienum mdi_ctrl { 3378c2ecf20Sopenharmony_ci mdi_write = 0x04000000, 3388c2ecf20Sopenharmony_ci mdi_read = 0x08000000, 3398c2ecf20Sopenharmony_ci mdi_ready = 0x10000000, 3408c2ecf20Sopenharmony_ci}; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_cienum eeprom_op { 3438c2ecf20Sopenharmony_ci op_write = 0x05, 3448c2ecf20Sopenharmony_ci op_read = 0x06, 3458c2ecf20Sopenharmony_ci op_ewds = 0x10, 3468c2ecf20Sopenharmony_ci op_ewen = 0x13, 3478c2ecf20Sopenharmony_ci}; 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_cienum eeprom_offsets { 3508c2ecf20Sopenharmony_ci eeprom_cnfg_mdix = 0x03, 3518c2ecf20Sopenharmony_ci eeprom_phy_iface = 0x06, 3528c2ecf20Sopenharmony_ci eeprom_id = 0x0A, 3538c2ecf20Sopenharmony_ci eeprom_config_asf = 0x0D, 3548c2ecf20Sopenharmony_ci eeprom_smbus_addr = 0x90, 3558c2ecf20Sopenharmony_ci}; 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_cienum eeprom_cnfg_mdix { 3588c2ecf20Sopenharmony_ci eeprom_mdix_enabled = 0x0080, 3598c2ecf20Sopenharmony_ci}; 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_cienum eeprom_phy_iface { 3628c2ecf20Sopenharmony_ci NoSuchPhy = 0, 3638c2ecf20Sopenharmony_ci I82553AB, 3648c2ecf20Sopenharmony_ci I82553C, 3658c2ecf20Sopenharmony_ci I82503, 3668c2ecf20Sopenharmony_ci DP83840, 3678c2ecf20Sopenharmony_ci S80C240, 3688c2ecf20Sopenharmony_ci S80C24, 3698c2ecf20Sopenharmony_ci I82555, 3708c2ecf20Sopenharmony_ci DP83840A = 10, 3718c2ecf20Sopenharmony_ci}; 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_cienum eeprom_id { 3748c2ecf20Sopenharmony_ci eeprom_id_wol = 0x0020, 3758c2ecf20Sopenharmony_ci}; 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_cienum eeprom_config_asf { 3788c2ecf20Sopenharmony_ci eeprom_asf = 0x8000, 3798c2ecf20Sopenharmony_ci eeprom_gcl = 0x4000, 3808c2ecf20Sopenharmony_ci}; 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_cienum cb_status { 3838c2ecf20Sopenharmony_ci cb_complete = 0x8000, 3848c2ecf20Sopenharmony_ci cb_ok = 0x2000, 3858c2ecf20Sopenharmony_ci}; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci/* 3888c2ecf20Sopenharmony_ci * cb_command - Command Block flags 3898c2ecf20Sopenharmony_ci * @cb_tx_nc: 0: controller does CRC (normal), 1: CRC from skb memory 3908c2ecf20Sopenharmony_ci */ 3918c2ecf20Sopenharmony_cienum cb_command { 3928c2ecf20Sopenharmony_ci cb_nop = 0x0000, 3938c2ecf20Sopenharmony_ci cb_iaaddr = 0x0001, 3948c2ecf20Sopenharmony_ci cb_config = 0x0002, 3958c2ecf20Sopenharmony_ci cb_multi = 0x0003, 3968c2ecf20Sopenharmony_ci cb_tx = 0x0004, 3978c2ecf20Sopenharmony_ci cb_ucode = 0x0005, 3988c2ecf20Sopenharmony_ci cb_dump = 0x0006, 3998c2ecf20Sopenharmony_ci cb_tx_sf = 0x0008, 4008c2ecf20Sopenharmony_ci cb_tx_nc = 0x0010, 4018c2ecf20Sopenharmony_ci cb_cid = 0x1f00, 4028c2ecf20Sopenharmony_ci cb_i = 0x2000, 4038c2ecf20Sopenharmony_ci cb_s = 0x4000, 4048c2ecf20Sopenharmony_ci cb_el = 0x8000, 4058c2ecf20Sopenharmony_ci}; 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_cistruct rfd { 4088c2ecf20Sopenharmony_ci __le16 status; 4098c2ecf20Sopenharmony_ci __le16 command; 4108c2ecf20Sopenharmony_ci __le32 link; 4118c2ecf20Sopenharmony_ci __le32 rbd; 4128c2ecf20Sopenharmony_ci __le16 actual_size; 4138c2ecf20Sopenharmony_ci __le16 size; 4148c2ecf20Sopenharmony_ci}; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_cistruct rx { 4178c2ecf20Sopenharmony_ci struct rx *next, *prev; 4188c2ecf20Sopenharmony_ci struct sk_buff *skb; 4198c2ecf20Sopenharmony_ci dma_addr_t dma_addr; 4208c2ecf20Sopenharmony_ci}; 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci#if defined(__BIG_ENDIAN_BITFIELD) 4238c2ecf20Sopenharmony_ci#define X(a,b) b,a 4248c2ecf20Sopenharmony_ci#else 4258c2ecf20Sopenharmony_ci#define X(a,b) a,b 4268c2ecf20Sopenharmony_ci#endif 4278c2ecf20Sopenharmony_cistruct config { 4288c2ecf20Sopenharmony_ci/*0*/ u8 X(byte_count:6, pad0:2); 4298c2ecf20Sopenharmony_ci/*1*/ u8 X(X(rx_fifo_limit:4, tx_fifo_limit:3), pad1:1); 4308c2ecf20Sopenharmony_ci/*2*/ u8 adaptive_ifs; 4318c2ecf20Sopenharmony_ci/*3*/ u8 X(X(X(X(mwi_enable:1, type_enable:1), read_align_enable:1), 4328c2ecf20Sopenharmony_ci term_write_cache_line:1), pad3:4); 4338c2ecf20Sopenharmony_ci/*4*/ u8 X(rx_dma_max_count:7, pad4:1); 4348c2ecf20Sopenharmony_ci/*5*/ u8 X(tx_dma_max_count:7, dma_max_count_enable:1); 4358c2ecf20Sopenharmony_ci/*6*/ u8 X(X(X(X(X(X(X(late_scb_update:1, direct_rx_dma:1), 4368c2ecf20Sopenharmony_ci tno_intr:1), cna_intr:1), standard_tcb:1), standard_stat_counter:1), 4378c2ecf20Sopenharmony_ci rx_save_overruns : 1), rx_save_bad_frames : 1); 4388c2ecf20Sopenharmony_ci/*7*/ u8 X(X(X(X(X(rx_discard_short_frames:1, tx_underrun_retry:2), 4398c2ecf20Sopenharmony_ci pad7:2), rx_extended_rfd:1), tx_two_frames_in_fifo:1), 4408c2ecf20Sopenharmony_ci tx_dynamic_tbd:1); 4418c2ecf20Sopenharmony_ci/*8*/ u8 X(X(mii_mode:1, pad8:6), csma_disabled:1); 4428c2ecf20Sopenharmony_ci/*9*/ u8 X(X(X(X(X(rx_tcpudp_checksum:1, pad9:3), vlan_arp_tco:1), 4438c2ecf20Sopenharmony_ci link_status_wake:1), arp_wake:1), mcmatch_wake:1); 4448c2ecf20Sopenharmony_ci/*10*/ u8 X(X(X(pad10:3, no_source_addr_insertion:1), preamble_length:2), 4458c2ecf20Sopenharmony_ci loopback:2); 4468c2ecf20Sopenharmony_ci/*11*/ u8 X(linear_priority:3, pad11:5); 4478c2ecf20Sopenharmony_ci/*12*/ u8 X(X(linear_priority_mode:1, pad12:3), ifs:4); 4488c2ecf20Sopenharmony_ci/*13*/ u8 ip_addr_lo; 4498c2ecf20Sopenharmony_ci/*14*/ u8 ip_addr_hi; 4508c2ecf20Sopenharmony_ci/*15*/ u8 X(X(X(X(X(X(X(promiscuous_mode:1, broadcast_disabled:1), 4518c2ecf20Sopenharmony_ci wait_after_win:1), pad15_1:1), ignore_ul_bit:1), crc_16_bit:1), 4528c2ecf20Sopenharmony_ci pad15_2:1), crs_or_cdt:1); 4538c2ecf20Sopenharmony_ci/*16*/ u8 fc_delay_lo; 4548c2ecf20Sopenharmony_ci/*17*/ u8 fc_delay_hi; 4558c2ecf20Sopenharmony_ci/*18*/ u8 X(X(X(X(X(rx_stripping:1, tx_padding:1), rx_crc_transfer:1), 4568c2ecf20Sopenharmony_ci rx_long_ok:1), fc_priority_threshold:3), pad18:1); 4578c2ecf20Sopenharmony_ci/*19*/ u8 X(X(X(X(X(X(X(addr_wake:1, magic_packet_disable:1), 4588c2ecf20Sopenharmony_ci fc_disable:1), fc_restop:1), fc_restart:1), fc_reject:1), 4598c2ecf20Sopenharmony_ci full_duplex_force:1), full_duplex_pin:1); 4608c2ecf20Sopenharmony_ci/*20*/ u8 X(X(X(pad20_1:5, fc_priority_location:1), multi_ia:1), pad20_2:1); 4618c2ecf20Sopenharmony_ci/*21*/ u8 X(X(pad21_1:3, multicast_all:1), pad21_2:4); 4628c2ecf20Sopenharmony_ci/*22*/ u8 X(X(rx_d102_mode:1, rx_vlan_drop:1), pad22:6); 4638c2ecf20Sopenharmony_ci u8 pad_d102[9]; 4648c2ecf20Sopenharmony_ci}; 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci#define E100_MAX_MULTICAST_ADDRS 64 4678c2ecf20Sopenharmony_cistruct multi { 4688c2ecf20Sopenharmony_ci __le16 count; 4698c2ecf20Sopenharmony_ci u8 addr[E100_MAX_MULTICAST_ADDRS * ETH_ALEN + 2/*pad*/]; 4708c2ecf20Sopenharmony_ci}; 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci/* Important: keep total struct u32-aligned */ 4738c2ecf20Sopenharmony_ci#define UCODE_SIZE 134 4748c2ecf20Sopenharmony_cistruct cb { 4758c2ecf20Sopenharmony_ci __le16 status; 4768c2ecf20Sopenharmony_ci __le16 command; 4778c2ecf20Sopenharmony_ci __le32 link; 4788c2ecf20Sopenharmony_ci union { 4798c2ecf20Sopenharmony_ci u8 iaaddr[ETH_ALEN]; 4808c2ecf20Sopenharmony_ci __le32 ucode[UCODE_SIZE]; 4818c2ecf20Sopenharmony_ci struct config config; 4828c2ecf20Sopenharmony_ci struct multi multi; 4838c2ecf20Sopenharmony_ci struct { 4848c2ecf20Sopenharmony_ci u32 tbd_array; 4858c2ecf20Sopenharmony_ci u16 tcb_byte_count; 4868c2ecf20Sopenharmony_ci u8 threshold; 4878c2ecf20Sopenharmony_ci u8 tbd_count; 4888c2ecf20Sopenharmony_ci struct { 4898c2ecf20Sopenharmony_ci __le32 buf_addr; 4908c2ecf20Sopenharmony_ci __le16 size; 4918c2ecf20Sopenharmony_ci u16 eol; 4928c2ecf20Sopenharmony_ci } tbd; 4938c2ecf20Sopenharmony_ci } tcb; 4948c2ecf20Sopenharmony_ci __le32 dump_buffer_addr; 4958c2ecf20Sopenharmony_ci } u; 4968c2ecf20Sopenharmony_ci struct cb *next, *prev; 4978c2ecf20Sopenharmony_ci dma_addr_t dma_addr; 4988c2ecf20Sopenharmony_ci struct sk_buff *skb; 4998c2ecf20Sopenharmony_ci}; 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_cienum loopback { 5028c2ecf20Sopenharmony_ci lb_none = 0, lb_mac = 1, lb_phy = 3, 5038c2ecf20Sopenharmony_ci}; 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_cistruct stats { 5068c2ecf20Sopenharmony_ci __le32 tx_good_frames, tx_max_collisions, tx_late_collisions, 5078c2ecf20Sopenharmony_ci tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions, 5088c2ecf20Sopenharmony_ci tx_multiple_collisions, tx_total_collisions; 5098c2ecf20Sopenharmony_ci __le32 rx_good_frames, rx_crc_errors, rx_alignment_errors, 5108c2ecf20Sopenharmony_ci rx_resource_errors, rx_overrun_errors, rx_cdt_errors, 5118c2ecf20Sopenharmony_ci rx_short_frame_errors; 5128c2ecf20Sopenharmony_ci __le32 fc_xmt_pause, fc_rcv_pause, fc_rcv_unsupported; 5138c2ecf20Sopenharmony_ci __le16 xmt_tco_frames, rcv_tco_frames; 5148c2ecf20Sopenharmony_ci __le32 complete; 5158c2ecf20Sopenharmony_ci}; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_cistruct mem { 5188c2ecf20Sopenharmony_ci struct { 5198c2ecf20Sopenharmony_ci u32 signature; 5208c2ecf20Sopenharmony_ci u32 result; 5218c2ecf20Sopenharmony_ci } selftest; 5228c2ecf20Sopenharmony_ci struct stats stats; 5238c2ecf20Sopenharmony_ci u8 dump_buf[596]; 5248c2ecf20Sopenharmony_ci}; 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_cistruct param_range { 5278c2ecf20Sopenharmony_ci u32 min; 5288c2ecf20Sopenharmony_ci u32 max; 5298c2ecf20Sopenharmony_ci u32 count; 5308c2ecf20Sopenharmony_ci}; 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_cistruct params { 5338c2ecf20Sopenharmony_ci struct param_range rfds; 5348c2ecf20Sopenharmony_ci struct param_range cbs; 5358c2ecf20Sopenharmony_ci}; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_cistruct nic { 5388c2ecf20Sopenharmony_ci /* Begin: frequently used values: keep adjacent for cache effect */ 5398c2ecf20Sopenharmony_ci u32 msg_enable ____cacheline_aligned; 5408c2ecf20Sopenharmony_ci struct net_device *netdev; 5418c2ecf20Sopenharmony_ci struct pci_dev *pdev; 5428c2ecf20Sopenharmony_ci u16 (*mdio_ctrl)(struct nic *nic, u32 addr, u32 dir, u32 reg, u16 data); 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci struct rx *rxs ____cacheline_aligned; 5458c2ecf20Sopenharmony_ci struct rx *rx_to_use; 5468c2ecf20Sopenharmony_ci struct rx *rx_to_clean; 5478c2ecf20Sopenharmony_ci struct rfd blank_rfd; 5488c2ecf20Sopenharmony_ci enum ru_state ru_running; 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci spinlock_t cb_lock ____cacheline_aligned; 5518c2ecf20Sopenharmony_ci spinlock_t cmd_lock; 5528c2ecf20Sopenharmony_ci struct csr __iomem *csr; 5538c2ecf20Sopenharmony_ci enum scb_cmd_lo cuc_cmd; 5548c2ecf20Sopenharmony_ci unsigned int cbs_avail; 5558c2ecf20Sopenharmony_ci struct napi_struct napi; 5568c2ecf20Sopenharmony_ci struct cb *cbs; 5578c2ecf20Sopenharmony_ci struct cb *cb_to_use; 5588c2ecf20Sopenharmony_ci struct cb *cb_to_send; 5598c2ecf20Sopenharmony_ci struct cb *cb_to_clean; 5608c2ecf20Sopenharmony_ci __le16 tx_command; 5618c2ecf20Sopenharmony_ci /* End: frequently used values: keep adjacent for cache effect */ 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci enum { 5648c2ecf20Sopenharmony_ci ich = (1 << 0), 5658c2ecf20Sopenharmony_ci promiscuous = (1 << 1), 5668c2ecf20Sopenharmony_ci multicast_all = (1 << 2), 5678c2ecf20Sopenharmony_ci wol_magic = (1 << 3), 5688c2ecf20Sopenharmony_ci ich_10h_workaround = (1 << 4), 5698c2ecf20Sopenharmony_ci } flags ____cacheline_aligned; 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci enum mac mac; 5728c2ecf20Sopenharmony_ci enum phy phy; 5738c2ecf20Sopenharmony_ci struct params params; 5748c2ecf20Sopenharmony_ci struct timer_list watchdog; 5758c2ecf20Sopenharmony_ci struct mii_if_info mii; 5768c2ecf20Sopenharmony_ci struct work_struct tx_timeout_task; 5778c2ecf20Sopenharmony_ci enum loopback loopback; 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci struct mem *mem; 5808c2ecf20Sopenharmony_ci dma_addr_t dma_addr; 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci struct dma_pool *cbs_pool; 5838c2ecf20Sopenharmony_ci dma_addr_t cbs_dma_addr; 5848c2ecf20Sopenharmony_ci u8 adaptive_ifs; 5858c2ecf20Sopenharmony_ci u8 tx_threshold; 5868c2ecf20Sopenharmony_ci u32 tx_frames; 5878c2ecf20Sopenharmony_ci u32 tx_collisions; 5888c2ecf20Sopenharmony_ci u32 tx_deferred; 5898c2ecf20Sopenharmony_ci u32 tx_single_collisions; 5908c2ecf20Sopenharmony_ci u32 tx_multiple_collisions; 5918c2ecf20Sopenharmony_ci u32 tx_fc_pause; 5928c2ecf20Sopenharmony_ci u32 tx_tco_frames; 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci u32 rx_fc_pause; 5958c2ecf20Sopenharmony_ci u32 rx_fc_unsupported; 5968c2ecf20Sopenharmony_ci u32 rx_tco_frames; 5978c2ecf20Sopenharmony_ci u32 rx_short_frame_errors; 5988c2ecf20Sopenharmony_ci u32 rx_over_length_errors; 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci u16 eeprom_wc; 6018c2ecf20Sopenharmony_ci __le16 eeprom[256]; 6028c2ecf20Sopenharmony_ci spinlock_t mdio_lock; 6038c2ecf20Sopenharmony_ci const struct firmware *fw; 6048c2ecf20Sopenharmony_ci}; 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_cistatic inline void e100_write_flush(struct nic *nic) 6078c2ecf20Sopenharmony_ci{ 6088c2ecf20Sopenharmony_ci /* Flush previous PCI writes through intermediate bridges 6098c2ecf20Sopenharmony_ci * by doing a benign read */ 6108c2ecf20Sopenharmony_ci (void)ioread8(&nic->csr->scb.status); 6118c2ecf20Sopenharmony_ci} 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_cistatic void e100_enable_irq(struct nic *nic) 6148c2ecf20Sopenharmony_ci{ 6158c2ecf20Sopenharmony_ci unsigned long flags; 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci spin_lock_irqsave(&nic->cmd_lock, flags); 6188c2ecf20Sopenharmony_ci iowrite8(irq_mask_none, &nic->csr->scb.cmd_hi); 6198c2ecf20Sopenharmony_ci e100_write_flush(nic); 6208c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&nic->cmd_lock, flags); 6218c2ecf20Sopenharmony_ci} 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_cistatic void e100_disable_irq(struct nic *nic) 6248c2ecf20Sopenharmony_ci{ 6258c2ecf20Sopenharmony_ci unsigned long flags; 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_ci spin_lock_irqsave(&nic->cmd_lock, flags); 6288c2ecf20Sopenharmony_ci iowrite8(irq_mask_all, &nic->csr->scb.cmd_hi); 6298c2ecf20Sopenharmony_ci e100_write_flush(nic); 6308c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&nic->cmd_lock, flags); 6318c2ecf20Sopenharmony_ci} 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_cistatic void e100_hw_reset(struct nic *nic) 6348c2ecf20Sopenharmony_ci{ 6358c2ecf20Sopenharmony_ci /* Put CU and RU into idle with a selective reset to get 6368c2ecf20Sopenharmony_ci * device off of PCI bus */ 6378c2ecf20Sopenharmony_ci iowrite32(selective_reset, &nic->csr->port); 6388c2ecf20Sopenharmony_ci e100_write_flush(nic); udelay(20); 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci /* Now fully reset device */ 6418c2ecf20Sopenharmony_ci iowrite32(software_reset, &nic->csr->port); 6428c2ecf20Sopenharmony_ci e100_write_flush(nic); udelay(20); 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ci /* Mask off our interrupt line - it's unmasked after reset */ 6458c2ecf20Sopenharmony_ci e100_disable_irq(nic); 6468c2ecf20Sopenharmony_ci} 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_cistatic int e100_self_test(struct nic *nic) 6498c2ecf20Sopenharmony_ci{ 6508c2ecf20Sopenharmony_ci u32 dma_addr = nic->dma_addr + offsetof(struct mem, selftest); 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_ci /* Passing the self-test is a pretty good indication 6538c2ecf20Sopenharmony_ci * that the device can DMA to/from host memory */ 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_ci nic->mem->selftest.signature = 0; 6568c2ecf20Sopenharmony_ci nic->mem->selftest.result = 0xFFFFFFFF; 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci iowrite32(selftest | dma_addr, &nic->csr->port); 6598c2ecf20Sopenharmony_ci e100_write_flush(nic); 6608c2ecf20Sopenharmony_ci /* Wait 10 msec for self-test to complete */ 6618c2ecf20Sopenharmony_ci msleep(10); 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci /* Interrupts are enabled after self-test */ 6648c2ecf20Sopenharmony_ci e100_disable_irq(nic); 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ci /* Check results of self-test */ 6678c2ecf20Sopenharmony_ci if (nic->mem->selftest.result != 0) { 6688c2ecf20Sopenharmony_ci netif_err(nic, hw, nic->netdev, 6698c2ecf20Sopenharmony_ci "Self-test failed: result=0x%08X\n", 6708c2ecf20Sopenharmony_ci nic->mem->selftest.result); 6718c2ecf20Sopenharmony_ci return -ETIMEDOUT; 6728c2ecf20Sopenharmony_ci } 6738c2ecf20Sopenharmony_ci if (nic->mem->selftest.signature == 0) { 6748c2ecf20Sopenharmony_ci netif_err(nic, hw, nic->netdev, "Self-test failed: timed out\n"); 6758c2ecf20Sopenharmony_ci return -ETIMEDOUT; 6768c2ecf20Sopenharmony_ci } 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci return 0; 6798c2ecf20Sopenharmony_ci} 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_cistatic void e100_eeprom_write(struct nic *nic, u16 addr_len, u16 addr, __le16 data) 6828c2ecf20Sopenharmony_ci{ 6838c2ecf20Sopenharmony_ci u32 cmd_addr_data[3]; 6848c2ecf20Sopenharmony_ci u8 ctrl; 6858c2ecf20Sopenharmony_ci int i, j; 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_ci /* Three cmds: write/erase enable, write data, write/erase disable */ 6888c2ecf20Sopenharmony_ci cmd_addr_data[0] = op_ewen << (addr_len - 2); 6898c2ecf20Sopenharmony_ci cmd_addr_data[1] = (((op_write << addr_len) | addr) << 16) | 6908c2ecf20Sopenharmony_ci le16_to_cpu(data); 6918c2ecf20Sopenharmony_ci cmd_addr_data[2] = op_ewds << (addr_len - 2); 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci /* Bit-bang cmds to write word to eeprom */ 6948c2ecf20Sopenharmony_ci for (j = 0; j < 3; j++) { 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_ci /* Chip select */ 6978c2ecf20Sopenharmony_ci iowrite8(eecs | eesk, &nic->csr->eeprom_ctrl_lo); 6988c2ecf20Sopenharmony_ci e100_write_flush(nic); udelay(4); 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci for (i = 31; i >= 0; i--) { 7018c2ecf20Sopenharmony_ci ctrl = (cmd_addr_data[j] & (1 << i)) ? 7028c2ecf20Sopenharmony_ci eecs | eedi : eecs; 7038c2ecf20Sopenharmony_ci iowrite8(ctrl, &nic->csr->eeprom_ctrl_lo); 7048c2ecf20Sopenharmony_ci e100_write_flush(nic); udelay(4); 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci iowrite8(ctrl | eesk, &nic->csr->eeprom_ctrl_lo); 7078c2ecf20Sopenharmony_ci e100_write_flush(nic); udelay(4); 7088c2ecf20Sopenharmony_ci } 7098c2ecf20Sopenharmony_ci /* Wait 10 msec for cmd to complete */ 7108c2ecf20Sopenharmony_ci msleep(10); 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci /* Chip deselect */ 7138c2ecf20Sopenharmony_ci iowrite8(0, &nic->csr->eeprom_ctrl_lo); 7148c2ecf20Sopenharmony_ci e100_write_flush(nic); udelay(4); 7158c2ecf20Sopenharmony_ci } 7168c2ecf20Sopenharmony_ci}; 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_ci/* General technique stolen from the eepro100 driver - very clever */ 7198c2ecf20Sopenharmony_cistatic __le16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr) 7208c2ecf20Sopenharmony_ci{ 7218c2ecf20Sopenharmony_ci u32 cmd_addr_data; 7228c2ecf20Sopenharmony_ci u16 data = 0; 7238c2ecf20Sopenharmony_ci u8 ctrl; 7248c2ecf20Sopenharmony_ci int i; 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci cmd_addr_data = ((op_read << *addr_len) | addr) << 16; 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci /* Chip select */ 7298c2ecf20Sopenharmony_ci iowrite8(eecs | eesk, &nic->csr->eeprom_ctrl_lo); 7308c2ecf20Sopenharmony_ci e100_write_flush(nic); udelay(4); 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci /* Bit-bang to read word from eeprom */ 7338c2ecf20Sopenharmony_ci for (i = 31; i >= 0; i--) { 7348c2ecf20Sopenharmony_ci ctrl = (cmd_addr_data & (1 << i)) ? eecs | eedi : eecs; 7358c2ecf20Sopenharmony_ci iowrite8(ctrl, &nic->csr->eeprom_ctrl_lo); 7368c2ecf20Sopenharmony_ci e100_write_flush(nic); udelay(4); 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci iowrite8(ctrl | eesk, &nic->csr->eeprom_ctrl_lo); 7398c2ecf20Sopenharmony_ci e100_write_flush(nic); udelay(4); 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci /* Eeprom drives a dummy zero to EEDO after receiving 7428c2ecf20Sopenharmony_ci * complete address. Use this to adjust addr_len. */ 7438c2ecf20Sopenharmony_ci ctrl = ioread8(&nic->csr->eeprom_ctrl_lo); 7448c2ecf20Sopenharmony_ci if (!(ctrl & eedo) && i > 16) { 7458c2ecf20Sopenharmony_ci *addr_len -= (i - 16); 7468c2ecf20Sopenharmony_ci i = 17; 7478c2ecf20Sopenharmony_ci } 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_ci data = (data << 1) | (ctrl & eedo ? 1 : 0); 7508c2ecf20Sopenharmony_ci } 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci /* Chip deselect */ 7538c2ecf20Sopenharmony_ci iowrite8(0, &nic->csr->eeprom_ctrl_lo); 7548c2ecf20Sopenharmony_ci e100_write_flush(nic); udelay(4); 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci return cpu_to_le16(data); 7578c2ecf20Sopenharmony_ci}; 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_ci/* Load entire EEPROM image into driver cache and validate checksum */ 7608c2ecf20Sopenharmony_cistatic int e100_eeprom_load(struct nic *nic) 7618c2ecf20Sopenharmony_ci{ 7628c2ecf20Sopenharmony_ci u16 addr, addr_len = 8, checksum = 0; 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci /* Try reading with an 8-bit addr len to discover actual addr len */ 7658c2ecf20Sopenharmony_ci e100_eeprom_read(nic, &addr_len, 0); 7668c2ecf20Sopenharmony_ci nic->eeprom_wc = 1 << addr_len; 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci for (addr = 0; addr < nic->eeprom_wc; addr++) { 7698c2ecf20Sopenharmony_ci nic->eeprom[addr] = e100_eeprom_read(nic, &addr_len, addr); 7708c2ecf20Sopenharmony_ci if (addr < nic->eeprom_wc - 1) 7718c2ecf20Sopenharmony_ci checksum += le16_to_cpu(nic->eeprom[addr]); 7728c2ecf20Sopenharmony_ci } 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_ci /* The checksum, stored in the last word, is calculated such that 7758c2ecf20Sopenharmony_ci * the sum of words should be 0xBABA */ 7768c2ecf20Sopenharmony_ci if (cpu_to_le16(0xBABA - checksum) != nic->eeprom[nic->eeprom_wc - 1]) { 7778c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "EEPROM corrupted\n"); 7788c2ecf20Sopenharmony_ci if (!eeprom_bad_csum_allow) 7798c2ecf20Sopenharmony_ci return -EAGAIN; 7808c2ecf20Sopenharmony_ci } 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci return 0; 7838c2ecf20Sopenharmony_ci} 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci/* Save (portion of) driver EEPROM cache to device and update checksum */ 7868c2ecf20Sopenharmony_cistatic int e100_eeprom_save(struct nic *nic, u16 start, u16 count) 7878c2ecf20Sopenharmony_ci{ 7888c2ecf20Sopenharmony_ci u16 addr, addr_len = 8, checksum = 0; 7898c2ecf20Sopenharmony_ci 7908c2ecf20Sopenharmony_ci /* Try reading with an 8-bit addr len to discover actual addr len */ 7918c2ecf20Sopenharmony_ci e100_eeprom_read(nic, &addr_len, 0); 7928c2ecf20Sopenharmony_ci nic->eeprom_wc = 1 << addr_len; 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci if (start + count >= nic->eeprom_wc) 7958c2ecf20Sopenharmony_ci return -EINVAL; 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci for (addr = start; addr < start + count; addr++) 7988c2ecf20Sopenharmony_ci e100_eeprom_write(nic, addr_len, addr, nic->eeprom[addr]); 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci /* The checksum, stored in the last word, is calculated such that 8018c2ecf20Sopenharmony_ci * the sum of words should be 0xBABA */ 8028c2ecf20Sopenharmony_ci for (addr = 0; addr < nic->eeprom_wc - 1; addr++) 8038c2ecf20Sopenharmony_ci checksum += le16_to_cpu(nic->eeprom[addr]); 8048c2ecf20Sopenharmony_ci nic->eeprom[nic->eeprom_wc - 1] = cpu_to_le16(0xBABA - checksum); 8058c2ecf20Sopenharmony_ci e100_eeprom_write(nic, addr_len, nic->eeprom_wc - 1, 8068c2ecf20Sopenharmony_ci nic->eeprom[nic->eeprom_wc - 1]); 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_ci return 0; 8098c2ecf20Sopenharmony_ci} 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci#define E100_WAIT_SCB_TIMEOUT 20000 /* we might have to wait 100ms!!! */ 8128c2ecf20Sopenharmony_ci#define E100_WAIT_SCB_FAST 20 /* delay like the old code */ 8138c2ecf20Sopenharmony_cistatic int e100_exec_cmd(struct nic *nic, u8 cmd, dma_addr_t dma_addr) 8148c2ecf20Sopenharmony_ci{ 8158c2ecf20Sopenharmony_ci unsigned long flags; 8168c2ecf20Sopenharmony_ci unsigned int i; 8178c2ecf20Sopenharmony_ci int err = 0; 8188c2ecf20Sopenharmony_ci 8198c2ecf20Sopenharmony_ci spin_lock_irqsave(&nic->cmd_lock, flags); 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_ci /* Previous command is accepted when SCB clears */ 8228c2ecf20Sopenharmony_ci for (i = 0; i < E100_WAIT_SCB_TIMEOUT; i++) { 8238c2ecf20Sopenharmony_ci if (likely(!ioread8(&nic->csr->scb.cmd_lo))) 8248c2ecf20Sopenharmony_ci break; 8258c2ecf20Sopenharmony_ci cpu_relax(); 8268c2ecf20Sopenharmony_ci if (unlikely(i > E100_WAIT_SCB_FAST)) 8278c2ecf20Sopenharmony_ci udelay(5); 8288c2ecf20Sopenharmony_ci } 8298c2ecf20Sopenharmony_ci if (unlikely(i == E100_WAIT_SCB_TIMEOUT)) { 8308c2ecf20Sopenharmony_ci err = -EAGAIN; 8318c2ecf20Sopenharmony_ci goto err_unlock; 8328c2ecf20Sopenharmony_ci } 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_ci if (unlikely(cmd != cuc_resume)) 8358c2ecf20Sopenharmony_ci iowrite32(dma_addr, &nic->csr->scb.gen_ptr); 8368c2ecf20Sopenharmony_ci iowrite8(cmd, &nic->csr->scb.cmd_lo); 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_cierr_unlock: 8398c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&nic->cmd_lock, flags); 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci return err; 8428c2ecf20Sopenharmony_ci} 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_cistatic int e100_exec_cb(struct nic *nic, struct sk_buff *skb, 8458c2ecf20Sopenharmony_ci int (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *)) 8468c2ecf20Sopenharmony_ci{ 8478c2ecf20Sopenharmony_ci struct cb *cb; 8488c2ecf20Sopenharmony_ci unsigned long flags; 8498c2ecf20Sopenharmony_ci int err; 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_ci spin_lock_irqsave(&nic->cb_lock, flags); 8528c2ecf20Sopenharmony_ci 8538c2ecf20Sopenharmony_ci if (unlikely(!nic->cbs_avail)) { 8548c2ecf20Sopenharmony_ci err = -ENOMEM; 8558c2ecf20Sopenharmony_ci goto err_unlock; 8568c2ecf20Sopenharmony_ci } 8578c2ecf20Sopenharmony_ci 8588c2ecf20Sopenharmony_ci cb = nic->cb_to_use; 8598c2ecf20Sopenharmony_ci nic->cb_to_use = cb->next; 8608c2ecf20Sopenharmony_ci nic->cbs_avail--; 8618c2ecf20Sopenharmony_ci cb->skb = skb; 8628c2ecf20Sopenharmony_ci 8638c2ecf20Sopenharmony_ci err = cb_prepare(nic, cb, skb); 8648c2ecf20Sopenharmony_ci if (err) 8658c2ecf20Sopenharmony_ci goto err_unlock; 8668c2ecf20Sopenharmony_ci 8678c2ecf20Sopenharmony_ci if (unlikely(!nic->cbs_avail)) 8688c2ecf20Sopenharmony_ci err = -ENOSPC; 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci /* Order is important otherwise we'll be in a race with h/w: 8728c2ecf20Sopenharmony_ci * set S-bit in current first, then clear S-bit in previous. */ 8738c2ecf20Sopenharmony_ci cb->command |= cpu_to_le16(cb_s); 8748c2ecf20Sopenharmony_ci dma_wmb(); 8758c2ecf20Sopenharmony_ci cb->prev->command &= cpu_to_le16(~cb_s); 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci while (nic->cb_to_send != nic->cb_to_use) { 8788c2ecf20Sopenharmony_ci if (unlikely(e100_exec_cmd(nic, nic->cuc_cmd, 8798c2ecf20Sopenharmony_ci nic->cb_to_send->dma_addr))) { 8808c2ecf20Sopenharmony_ci /* Ok, here's where things get sticky. It's 8818c2ecf20Sopenharmony_ci * possible that we can't schedule the command 8828c2ecf20Sopenharmony_ci * because the controller is too busy, so 8838c2ecf20Sopenharmony_ci * let's just queue the command and try again 8848c2ecf20Sopenharmony_ci * when another command is scheduled. */ 8858c2ecf20Sopenharmony_ci if (err == -ENOSPC) { 8868c2ecf20Sopenharmony_ci //request a reset 8878c2ecf20Sopenharmony_ci schedule_work(&nic->tx_timeout_task); 8888c2ecf20Sopenharmony_ci } 8898c2ecf20Sopenharmony_ci break; 8908c2ecf20Sopenharmony_ci } else { 8918c2ecf20Sopenharmony_ci nic->cuc_cmd = cuc_resume; 8928c2ecf20Sopenharmony_ci nic->cb_to_send = nic->cb_to_send->next; 8938c2ecf20Sopenharmony_ci } 8948c2ecf20Sopenharmony_ci } 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_cierr_unlock: 8978c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&nic->cb_lock, flags); 8988c2ecf20Sopenharmony_ci 8998c2ecf20Sopenharmony_ci return err; 9008c2ecf20Sopenharmony_ci} 9018c2ecf20Sopenharmony_ci 9028c2ecf20Sopenharmony_cistatic int mdio_read(struct net_device *netdev, int addr, int reg) 9038c2ecf20Sopenharmony_ci{ 9048c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 9058c2ecf20Sopenharmony_ci return nic->mdio_ctrl(nic, addr, mdi_read, reg, 0); 9068c2ecf20Sopenharmony_ci} 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_cistatic void mdio_write(struct net_device *netdev, int addr, int reg, int data) 9098c2ecf20Sopenharmony_ci{ 9108c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 9118c2ecf20Sopenharmony_ci 9128c2ecf20Sopenharmony_ci nic->mdio_ctrl(nic, addr, mdi_write, reg, data); 9138c2ecf20Sopenharmony_ci} 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_ci/* the standard mdio_ctrl() function for usual MII-compliant hardware */ 9168c2ecf20Sopenharmony_cistatic u16 mdio_ctrl_hw(struct nic *nic, u32 addr, u32 dir, u32 reg, u16 data) 9178c2ecf20Sopenharmony_ci{ 9188c2ecf20Sopenharmony_ci u32 data_out = 0; 9198c2ecf20Sopenharmony_ci unsigned int i; 9208c2ecf20Sopenharmony_ci unsigned long flags; 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci /* 9248c2ecf20Sopenharmony_ci * Stratus87247: we shouldn't be writing the MDI control 9258c2ecf20Sopenharmony_ci * register until the Ready bit shows True. Also, since 9268c2ecf20Sopenharmony_ci * manipulation of the MDI control registers is a multi-step 9278c2ecf20Sopenharmony_ci * procedure it should be done under lock. 9288c2ecf20Sopenharmony_ci */ 9298c2ecf20Sopenharmony_ci spin_lock_irqsave(&nic->mdio_lock, flags); 9308c2ecf20Sopenharmony_ci for (i = 100; i; --i) { 9318c2ecf20Sopenharmony_ci if (ioread32(&nic->csr->mdi_ctrl) & mdi_ready) 9328c2ecf20Sopenharmony_ci break; 9338c2ecf20Sopenharmony_ci udelay(20); 9348c2ecf20Sopenharmony_ci } 9358c2ecf20Sopenharmony_ci if (unlikely(!i)) { 9368c2ecf20Sopenharmony_ci netdev_err(nic->netdev, "e100.mdio_ctrl won't go Ready\n"); 9378c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&nic->mdio_lock, flags); 9388c2ecf20Sopenharmony_ci return 0; /* No way to indicate timeout error */ 9398c2ecf20Sopenharmony_ci } 9408c2ecf20Sopenharmony_ci iowrite32((reg << 16) | (addr << 21) | dir | data, &nic->csr->mdi_ctrl); 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_ci for (i = 0; i < 100; i++) { 9438c2ecf20Sopenharmony_ci udelay(20); 9448c2ecf20Sopenharmony_ci if ((data_out = ioread32(&nic->csr->mdi_ctrl)) & mdi_ready) 9458c2ecf20Sopenharmony_ci break; 9468c2ecf20Sopenharmony_ci } 9478c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&nic->mdio_lock, flags); 9488c2ecf20Sopenharmony_ci netif_printk(nic, hw, KERN_DEBUG, nic->netdev, 9498c2ecf20Sopenharmony_ci "%s:addr=%d, reg=%d, data_in=0x%04X, data_out=0x%04X\n", 9508c2ecf20Sopenharmony_ci dir == mdi_read ? "READ" : "WRITE", 9518c2ecf20Sopenharmony_ci addr, reg, data, data_out); 9528c2ecf20Sopenharmony_ci return (u16)data_out; 9538c2ecf20Sopenharmony_ci} 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_ci/* slightly tweaked mdio_ctrl() function for phy_82552_v specifics */ 9568c2ecf20Sopenharmony_cistatic u16 mdio_ctrl_phy_82552_v(struct nic *nic, 9578c2ecf20Sopenharmony_ci u32 addr, 9588c2ecf20Sopenharmony_ci u32 dir, 9598c2ecf20Sopenharmony_ci u32 reg, 9608c2ecf20Sopenharmony_ci u16 data) 9618c2ecf20Sopenharmony_ci{ 9628c2ecf20Sopenharmony_ci if ((reg == MII_BMCR) && (dir == mdi_write)) { 9638c2ecf20Sopenharmony_ci if (data & (BMCR_ANRESTART | BMCR_ANENABLE)) { 9648c2ecf20Sopenharmony_ci u16 advert = mdio_read(nic->netdev, nic->mii.phy_id, 9658c2ecf20Sopenharmony_ci MII_ADVERTISE); 9668c2ecf20Sopenharmony_ci 9678c2ecf20Sopenharmony_ci /* 9688c2ecf20Sopenharmony_ci * Workaround Si issue where sometimes the part will not 9698c2ecf20Sopenharmony_ci * autoneg to 100Mbps even when advertised. 9708c2ecf20Sopenharmony_ci */ 9718c2ecf20Sopenharmony_ci if (advert & ADVERTISE_100FULL) 9728c2ecf20Sopenharmony_ci data |= BMCR_SPEED100 | BMCR_FULLDPLX; 9738c2ecf20Sopenharmony_ci else if (advert & ADVERTISE_100HALF) 9748c2ecf20Sopenharmony_ci data |= BMCR_SPEED100; 9758c2ecf20Sopenharmony_ci } 9768c2ecf20Sopenharmony_ci } 9778c2ecf20Sopenharmony_ci return mdio_ctrl_hw(nic, addr, dir, reg, data); 9788c2ecf20Sopenharmony_ci} 9798c2ecf20Sopenharmony_ci 9808c2ecf20Sopenharmony_ci/* Fully software-emulated mdio_ctrl() function for cards without 9818c2ecf20Sopenharmony_ci * MII-compliant PHYs. 9828c2ecf20Sopenharmony_ci * For now, this is mainly geared towards 80c24 support; in case of further 9838c2ecf20Sopenharmony_ci * requirements for other types (i82503, ...?) either extend this mechanism 9848c2ecf20Sopenharmony_ci * or split it, whichever is cleaner. 9858c2ecf20Sopenharmony_ci */ 9868c2ecf20Sopenharmony_cistatic u16 mdio_ctrl_phy_mii_emulated(struct nic *nic, 9878c2ecf20Sopenharmony_ci u32 addr, 9888c2ecf20Sopenharmony_ci u32 dir, 9898c2ecf20Sopenharmony_ci u32 reg, 9908c2ecf20Sopenharmony_ci u16 data) 9918c2ecf20Sopenharmony_ci{ 9928c2ecf20Sopenharmony_ci /* might need to allocate a netdev_priv'ed register array eventually 9938c2ecf20Sopenharmony_ci * to be able to record state changes, but for now 9948c2ecf20Sopenharmony_ci * some fully hardcoded register handling ought to be ok I guess. */ 9958c2ecf20Sopenharmony_ci 9968c2ecf20Sopenharmony_ci if (dir == mdi_read) { 9978c2ecf20Sopenharmony_ci switch (reg) { 9988c2ecf20Sopenharmony_ci case MII_BMCR: 9998c2ecf20Sopenharmony_ci /* Auto-negotiation, right? */ 10008c2ecf20Sopenharmony_ci return BMCR_ANENABLE | 10018c2ecf20Sopenharmony_ci BMCR_FULLDPLX; 10028c2ecf20Sopenharmony_ci case MII_BMSR: 10038c2ecf20Sopenharmony_ci return BMSR_LSTATUS /* for mii_link_ok() */ | 10048c2ecf20Sopenharmony_ci BMSR_ANEGCAPABLE | 10058c2ecf20Sopenharmony_ci BMSR_10FULL; 10068c2ecf20Sopenharmony_ci case MII_ADVERTISE: 10078c2ecf20Sopenharmony_ci /* 80c24 is a "combo card" PHY, right? */ 10088c2ecf20Sopenharmony_ci return ADVERTISE_10HALF | 10098c2ecf20Sopenharmony_ci ADVERTISE_10FULL; 10108c2ecf20Sopenharmony_ci default: 10118c2ecf20Sopenharmony_ci netif_printk(nic, hw, KERN_DEBUG, nic->netdev, 10128c2ecf20Sopenharmony_ci "%s:addr=%d, reg=%d, data=0x%04X: unimplemented emulation!\n", 10138c2ecf20Sopenharmony_ci dir == mdi_read ? "READ" : "WRITE", 10148c2ecf20Sopenharmony_ci addr, reg, data); 10158c2ecf20Sopenharmony_ci return 0xFFFF; 10168c2ecf20Sopenharmony_ci } 10178c2ecf20Sopenharmony_ci } else { 10188c2ecf20Sopenharmony_ci switch (reg) { 10198c2ecf20Sopenharmony_ci default: 10208c2ecf20Sopenharmony_ci netif_printk(nic, hw, KERN_DEBUG, nic->netdev, 10218c2ecf20Sopenharmony_ci "%s:addr=%d, reg=%d, data=0x%04X: unimplemented emulation!\n", 10228c2ecf20Sopenharmony_ci dir == mdi_read ? "READ" : "WRITE", 10238c2ecf20Sopenharmony_ci addr, reg, data); 10248c2ecf20Sopenharmony_ci return 0xFFFF; 10258c2ecf20Sopenharmony_ci } 10268c2ecf20Sopenharmony_ci } 10278c2ecf20Sopenharmony_ci} 10288c2ecf20Sopenharmony_cistatic inline int e100_phy_supports_mii(struct nic *nic) 10298c2ecf20Sopenharmony_ci{ 10308c2ecf20Sopenharmony_ci /* for now, just check it by comparing whether we 10318c2ecf20Sopenharmony_ci are using MII software emulation. 10328c2ecf20Sopenharmony_ci */ 10338c2ecf20Sopenharmony_ci return (nic->mdio_ctrl != mdio_ctrl_phy_mii_emulated); 10348c2ecf20Sopenharmony_ci} 10358c2ecf20Sopenharmony_ci 10368c2ecf20Sopenharmony_cistatic void e100_get_defaults(struct nic *nic) 10378c2ecf20Sopenharmony_ci{ 10388c2ecf20Sopenharmony_ci struct param_range rfds = { .min = 16, .max = 256, .count = 256 }; 10398c2ecf20Sopenharmony_ci struct param_range cbs = { .min = 64, .max = 256, .count = 128 }; 10408c2ecf20Sopenharmony_ci 10418c2ecf20Sopenharmony_ci /* MAC type is encoded as rev ID; exception: ICH is treated as 82559 */ 10428c2ecf20Sopenharmony_ci nic->mac = (nic->flags & ich) ? mac_82559_D101M : nic->pdev->revision; 10438c2ecf20Sopenharmony_ci if (nic->mac == mac_unknown) 10448c2ecf20Sopenharmony_ci nic->mac = mac_82557_D100_A; 10458c2ecf20Sopenharmony_ci 10468c2ecf20Sopenharmony_ci nic->params.rfds = rfds; 10478c2ecf20Sopenharmony_ci nic->params.cbs = cbs; 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci /* Quadwords to DMA into FIFO before starting frame transmit */ 10508c2ecf20Sopenharmony_ci nic->tx_threshold = 0xE0; 10518c2ecf20Sopenharmony_ci 10528c2ecf20Sopenharmony_ci /* no interrupt for every tx completion, delay = 256us if not 557 */ 10538c2ecf20Sopenharmony_ci nic->tx_command = cpu_to_le16(cb_tx | cb_tx_sf | 10548c2ecf20Sopenharmony_ci ((nic->mac >= mac_82558_D101_A4) ? cb_cid : cb_i)); 10558c2ecf20Sopenharmony_ci 10568c2ecf20Sopenharmony_ci /* Template for a freshly allocated RFD */ 10578c2ecf20Sopenharmony_ci nic->blank_rfd.command = 0; 10588c2ecf20Sopenharmony_ci nic->blank_rfd.rbd = cpu_to_le32(0xFFFFFFFF); 10598c2ecf20Sopenharmony_ci nic->blank_rfd.size = cpu_to_le16(VLAN_ETH_FRAME_LEN + ETH_FCS_LEN); 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci /* MII setup */ 10628c2ecf20Sopenharmony_ci nic->mii.phy_id_mask = 0x1F; 10638c2ecf20Sopenharmony_ci nic->mii.reg_num_mask = 0x1F; 10648c2ecf20Sopenharmony_ci nic->mii.dev = nic->netdev; 10658c2ecf20Sopenharmony_ci nic->mii.mdio_read = mdio_read; 10668c2ecf20Sopenharmony_ci nic->mii.mdio_write = mdio_write; 10678c2ecf20Sopenharmony_ci} 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_cistatic int e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb) 10708c2ecf20Sopenharmony_ci{ 10718c2ecf20Sopenharmony_ci struct config *config = &cb->u.config; 10728c2ecf20Sopenharmony_ci u8 *c = (u8 *)config; 10738c2ecf20Sopenharmony_ci struct net_device *netdev = nic->netdev; 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_ci cb->command = cpu_to_le16(cb_config); 10768c2ecf20Sopenharmony_ci 10778c2ecf20Sopenharmony_ci memset(config, 0, sizeof(struct config)); 10788c2ecf20Sopenharmony_ci 10798c2ecf20Sopenharmony_ci config->byte_count = 0x16; /* bytes in this struct */ 10808c2ecf20Sopenharmony_ci config->rx_fifo_limit = 0x8; /* bytes in FIFO before DMA */ 10818c2ecf20Sopenharmony_ci config->direct_rx_dma = 0x1; /* reserved */ 10828c2ecf20Sopenharmony_ci config->standard_tcb = 0x1; /* 1=standard, 0=extended */ 10838c2ecf20Sopenharmony_ci config->standard_stat_counter = 0x1; /* 1=standard, 0=extended */ 10848c2ecf20Sopenharmony_ci config->rx_discard_short_frames = 0x1; /* 1=discard, 0=pass */ 10858c2ecf20Sopenharmony_ci config->tx_underrun_retry = 0x3; /* # of underrun retries */ 10868c2ecf20Sopenharmony_ci if (e100_phy_supports_mii(nic)) 10878c2ecf20Sopenharmony_ci config->mii_mode = 1; /* 1=MII mode, 0=i82503 mode */ 10888c2ecf20Sopenharmony_ci config->pad10 = 0x6; 10898c2ecf20Sopenharmony_ci config->no_source_addr_insertion = 0x1; /* 1=no, 0=yes */ 10908c2ecf20Sopenharmony_ci config->preamble_length = 0x2; /* 0=1, 1=3, 2=7, 3=15 bytes */ 10918c2ecf20Sopenharmony_ci config->ifs = 0x6; /* x16 = inter frame spacing */ 10928c2ecf20Sopenharmony_ci config->ip_addr_hi = 0xF2; /* ARP IP filter - not used */ 10938c2ecf20Sopenharmony_ci config->pad15_1 = 0x1; 10948c2ecf20Sopenharmony_ci config->pad15_2 = 0x1; 10958c2ecf20Sopenharmony_ci config->crs_or_cdt = 0x0; /* 0=CRS only, 1=CRS or CDT */ 10968c2ecf20Sopenharmony_ci config->fc_delay_hi = 0x40; /* time delay for fc frame */ 10978c2ecf20Sopenharmony_ci config->tx_padding = 0x1; /* 1=pad short frames */ 10988c2ecf20Sopenharmony_ci config->fc_priority_threshold = 0x7; /* 7=priority fc disabled */ 10998c2ecf20Sopenharmony_ci config->pad18 = 0x1; 11008c2ecf20Sopenharmony_ci config->full_duplex_pin = 0x1; /* 1=examine FDX# pin */ 11018c2ecf20Sopenharmony_ci config->pad20_1 = 0x1F; 11028c2ecf20Sopenharmony_ci config->fc_priority_location = 0x1; /* 1=byte#31, 0=byte#19 */ 11038c2ecf20Sopenharmony_ci config->pad21_1 = 0x5; 11048c2ecf20Sopenharmony_ci 11058c2ecf20Sopenharmony_ci config->adaptive_ifs = nic->adaptive_ifs; 11068c2ecf20Sopenharmony_ci config->loopback = nic->loopback; 11078c2ecf20Sopenharmony_ci 11088c2ecf20Sopenharmony_ci if (nic->mii.force_media && nic->mii.full_duplex) 11098c2ecf20Sopenharmony_ci config->full_duplex_force = 0x1; /* 1=force, 0=auto */ 11108c2ecf20Sopenharmony_ci 11118c2ecf20Sopenharmony_ci if (nic->flags & promiscuous || nic->loopback) { 11128c2ecf20Sopenharmony_ci config->rx_save_bad_frames = 0x1; /* 1=save, 0=discard */ 11138c2ecf20Sopenharmony_ci config->rx_discard_short_frames = 0x0; /* 1=discard, 0=save */ 11148c2ecf20Sopenharmony_ci config->promiscuous_mode = 0x1; /* 1=on, 0=off */ 11158c2ecf20Sopenharmony_ci } 11168c2ecf20Sopenharmony_ci 11178c2ecf20Sopenharmony_ci if (unlikely(netdev->features & NETIF_F_RXFCS)) 11188c2ecf20Sopenharmony_ci config->rx_crc_transfer = 0x1; /* 1=save, 0=discard */ 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_ci if (nic->flags & multicast_all) 11218c2ecf20Sopenharmony_ci config->multicast_all = 0x1; /* 1=accept, 0=no */ 11228c2ecf20Sopenharmony_ci 11238c2ecf20Sopenharmony_ci /* disable WoL when up */ 11248c2ecf20Sopenharmony_ci if (netif_running(nic->netdev) || !(nic->flags & wol_magic)) 11258c2ecf20Sopenharmony_ci config->magic_packet_disable = 0x1; /* 1=off, 0=on */ 11268c2ecf20Sopenharmony_ci 11278c2ecf20Sopenharmony_ci if (nic->mac >= mac_82558_D101_A4) { 11288c2ecf20Sopenharmony_ci config->fc_disable = 0x1; /* 1=Tx fc off, 0=Tx fc on */ 11298c2ecf20Sopenharmony_ci config->mwi_enable = 0x1; /* 1=enable, 0=disable */ 11308c2ecf20Sopenharmony_ci config->standard_tcb = 0x0; /* 1=standard, 0=extended */ 11318c2ecf20Sopenharmony_ci config->rx_long_ok = 0x1; /* 1=VLANs ok, 0=standard */ 11328c2ecf20Sopenharmony_ci if (nic->mac >= mac_82559_D101M) { 11338c2ecf20Sopenharmony_ci config->tno_intr = 0x1; /* TCO stats enable */ 11348c2ecf20Sopenharmony_ci /* Enable TCO in extended config */ 11358c2ecf20Sopenharmony_ci if (nic->mac >= mac_82551_10) { 11368c2ecf20Sopenharmony_ci config->byte_count = 0x20; /* extended bytes */ 11378c2ecf20Sopenharmony_ci config->rx_d102_mode = 0x1; /* GMRC for TCO */ 11388c2ecf20Sopenharmony_ci } 11398c2ecf20Sopenharmony_ci } else { 11408c2ecf20Sopenharmony_ci config->standard_stat_counter = 0x0; 11418c2ecf20Sopenharmony_ci } 11428c2ecf20Sopenharmony_ci } 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci if (netdev->features & NETIF_F_RXALL) { 11458c2ecf20Sopenharmony_ci config->rx_save_overruns = 0x1; /* 1=save, 0=discard */ 11468c2ecf20Sopenharmony_ci config->rx_save_bad_frames = 0x1; /* 1=save, 0=discard */ 11478c2ecf20Sopenharmony_ci config->rx_discard_short_frames = 0x0; /* 1=discard, 0=save */ 11488c2ecf20Sopenharmony_ci } 11498c2ecf20Sopenharmony_ci 11508c2ecf20Sopenharmony_ci netif_printk(nic, hw, KERN_DEBUG, nic->netdev, "[00-07]=%8ph\n", 11518c2ecf20Sopenharmony_ci c + 0); 11528c2ecf20Sopenharmony_ci netif_printk(nic, hw, KERN_DEBUG, nic->netdev, "[08-15]=%8ph\n", 11538c2ecf20Sopenharmony_ci c + 8); 11548c2ecf20Sopenharmony_ci netif_printk(nic, hw, KERN_DEBUG, nic->netdev, "[16-23]=%8ph\n", 11558c2ecf20Sopenharmony_ci c + 16); 11568c2ecf20Sopenharmony_ci return 0; 11578c2ecf20Sopenharmony_ci} 11588c2ecf20Sopenharmony_ci 11598c2ecf20Sopenharmony_ci/************************************************************************* 11608c2ecf20Sopenharmony_ci* CPUSaver parameters 11618c2ecf20Sopenharmony_ci* 11628c2ecf20Sopenharmony_ci* All CPUSaver parameters are 16-bit literals that are part of a 11638c2ecf20Sopenharmony_ci* "move immediate value" instruction. By changing the value of 11648c2ecf20Sopenharmony_ci* the literal in the instruction before the code is loaded, the 11658c2ecf20Sopenharmony_ci* driver can change the algorithm. 11668c2ecf20Sopenharmony_ci* 11678c2ecf20Sopenharmony_ci* INTDELAY - This loads the dead-man timer with its initial value. 11688c2ecf20Sopenharmony_ci* When this timer expires the interrupt is asserted, and the 11698c2ecf20Sopenharmony_ci* timer is reset each time a new packet is received. (see 11708c2ecf20Sopenharmony_ci* BUNDLEMAX below to set the limit on number of chained packets) 11718c2ecf20Sopenharmony_ci* The current default is 0x600 or 1536. Experiments show that 11728c2ecf20Sopenharmony_ci* the value should probably stay within the 0x200 - 0x1000. 11738c2ecf20Sopenharmony_ci* 11748c2ecf20Sopenharmony_ci* BUNDLEMAX - 11758c2ecf20Sopenharmony_ci* This sets the maximum number of frames that will be bundled. In 11768c2ecf20Sopenharmony_ci* some situations, such as the TCP windowing algorithm, it may be 11778c2ecf20Sopenharmony_ci* better to limit the growth of the bundle size than let it go as 11788c2ecf20Sopenharmony_ci* high as it can, because that could cause too much added latency. 11798c2ecf20Sopenharmony_ci* The default is six, because this is the number of packets in the 11808c2ecf20Sopenharmony_ci* default TCP window size. A value of 1 would make CPUSaver indicate 11818c2ecf20Sopenharmony_ci* an interrupt for every frame received. If you do not want to put 11828c2ecf20Sopenharmony_ci* a limit on the bundle size, set this value to xFFFF. 11838c2ecf20Sopenharmony_ci* 11848c2ecf20Sopenharmony_ci* BUNDLESMALL - 11858c2ecf20Sopenharmony_ci* This contains a bit-mask describing the minimum size frame that 11868c2ecf20Sopenharmony_ci* will be bundled. The default masks the lower 7 bits, which means 11878c2ecf20Sopenharmony_ci* that any frame less than 128 bytes in length will not be bundled, 11888c2ecf20Sopenharmony_ci* but will instead immediately generate an interrupt. This does 11898c2ecf20Sopenharmony_ci* not affect the current bundle in any way. Any frame that is 128 11908c2ecf20Sopenharmony_ci* bytes or large will be bundled normally. This feature is meant 11918c2ecf20Sopenharmony_ci* to provide immediate indication of ACK frames in a TCP environment. 11928c2ecf20Sopenharmony_ci* Customers were seeing poor performance when a machine with CPUSaver 11938c2ecf20Sopenharmony_ci* enabled was sending but not receiving. The delay introduced when 11948c2ecf20Sopenharmony_ci* the ACKs were received was enough to reduce total throughput, because 11958c2ecf20Sopenharmony_ci* the sender would sit idle until the ACK was finally seen. 11968c2ecf20Sopenharmony_ci* 11978c2ecf20Sopenharmony_ci* The current default is 0xFF80, which masks out the lower 7 bits. 11988c2ecf20Sopenharmony_ci* This means that any frame which is x7F (127) bytes or smaller 11998c2ecf20Sopenharmony_ci* will cause an immediate interrupt. Because this value must be a 12008c2ecf20Sopenharmony_ci* bit mask, there are only a few valid values that can be used. To 12018c2ecf20Sopenharmony_ci* turn this feature off, the driver can write the value xFFFF to the 12028c2ecf20Sopenharmony_ci* lower word of this instruction (in the same way that the other 12038c2ecf20Sopenharmony_ci* parameters are used). Likewise, a value of 0xF800 (2047) would 12048c2ecf20Sopenharmony_ci* cause an interrupt to be generated for every frame, because all 12058c2ecf20Sopenharmony_ci* standard Ethernet frames are <= 2047 bytes in length. 12068c2ecf20Sopenharmony_ci*************************************************************************/ 12078c2ecf20Sopenharmony_ci 12088c2ecf20Sopenharmony_ci/* if you wish to disable the ucode functionality, while maintaining the 12098c2ecf20Sopenharmony_ci * workarounds it provides, set the following defines to: 12108c2ecf20Sopenharmony_ci * BUNDLESMALL 0 12118c2ecf20Sopenharmony_ci * BUNDLEMAX 1 12128c2ecf20Sopenharmony_ci * INTDELAY 1 12138c2ecf20Sopenharmony_ci */ 12148c2ecf20Sopenharmony_ci#define BUNDLESMALL 1 12158c2ecf20Sopenharmony_ci#define BUNDLEMAX (u16)6 12168c2ecf20Sopenharmony_ci#define INTDELAY (u16)1536 /* 0x600 */ 12178c2ecf20Sopenharmony_ci 12188c2ecf20Sopenharmony_ci/* Initialize firmware */ 12198c2ecf20Sopenharmony_cistatic const struct firmware *e100_request_firmware(struct nic *nic) 12208c2ecf20Sopenharmony_ci{ 12218c2ecf20Sopenharmony_ci const char *fw_name; 12228c2ecf20Sopenharmony_ci const struct firmware *fw = nic->fw; 12238c2ecf20Sopenharmony_ci u8 timer, bundle, min_size; 12248c2ecf20Sopenharmony_ci int err = 0; 12258c2ecf20Sopenharmony_ci bool required = false; 12268c2ecf20Sopenharmony_ci 12278c2ecf20Sopenharmony_ci /* do not load u-code for ICH devices */ 12288c2ecf20Sopenharmony_ci if (nic->flags & ich) 12298c2ecf20Sopenharmony_ci return NULL; 12308c2ecf20Sopenharmony_ci 12318c2ecf20Sopenharmony_ci /* Search for ucode match against h/w revision 12328c2ecf20Sopenharmony_ci * 12338c2ecf20Sopenharmony_ci * Based on comments in the source code for the FreeBSD fxp 12348c2ecf20Sopenharmony_ci * driver, the FIRMWARE_D102E ucode includes both CPUSaver and 12358c2ecf20Sopenharmony_ci * 12368c2ecf20Sopenharmony_ci * "fixes for bugs in the B-step hardware (specifically, bugs 12378c2ecf20Sopenharmony_ci * with Inline Receive)." 12388c2ecf20Sopenharmony_ci * 12398c2ecf20Sopenharmony_ci * So we must fail if it cannot be loaded. 12408c2ecf20Sopenharmony_ci * 12418c2ecf20Sopenharmony_ci * The other microcode files are only required for the optional 12428c2ecf20Sopenharmony_ci * CPUSaver feature. Nice to have, but no reason to fail. 12438c2ecf20Sopenharmony_ci */ 12448c2ecf20Sopenharmony_ci if (nic->mac == mac_82559_D101M) { 12458c2ecf20Sopenharmony_ci fw_name = FIRMWARE_D101M; 12468c2ecf20Sopenharmony_ci } else if (nic->mac == mac_82559_D101S) { 12478c2ecf20Sopenharmony_ci fw_name = FIRMWARE_D101S; 12488c2ecf20Sopenharmony_ci } else if (nic->mac == mac_82551_F || nic->mac == mac_82551_10) { 12498c2ecf20Sopenharmony_ci fw_name = FIRMWARE_D102E; 12508c2ecf20Sopenharmony_ci required = true; 12518c2ecf20Sopenharmony_ci } else { /* No ucode on other devices */ 12528c2ecf20Sopenharmony_ci return NULL; 12538c2ecf20Sopenharmony_ci } 12548c2ecf20Sopenharmony_ci 12558c2ecf20Sopenharmony_ci /* If the firmware has not previously been loaded, request a pointer 12568c2ecf20Sopenharmony_ci * to it. If it was previously loaded, we are reinitializing the 12578c2ecf20Sopenharmony_ci * adapter, possibly in a resume from hibernate, in which case 12588c2ecf20Sopenharmony_ci * request_firmware() cannot be used. 12598c2ecf20Sopenharmony_ci */ 12608c2ecf20Sopenharmony_ci if (!fw) 12618c2ecf20Sopenharmony_ci err = request_firmware(&fw, fw_name, &nic->pdev->dev); 12628c2ecf20Sopenharmony_ci 12638c2ecf20Sopenharmony_ci if (err) { 12648c2ecf20Sopenharmony_ci if (required) { 12658c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, 12668c2ecf20Sopenharmony_ci "Failed to load firmware \"%s\": %d\n", 12678c2ecf20Sopenharmony_ci fw_name, err); 12688c2ecf20Sopenharmony_ci return ERR_PTR(err); 12698c2ecf20Sopenharmony_ci } else { 12708c2ecf20Sopenharmony_ci netif_info(nic, probe, nic->netdev, 12718c2ecf20Sopenharmony_ci "CPUSaver disabled. Needs \"%s\": %d\n", 12728c2ecf20Sopenharmony_ci fw_name, err); 12738c2ecf20Sopenharmony_ci return NULL; 12748c2ecf20Sopenharmony_ci } 12758c2ecf20Sopenharmony_ci } 12768c2ecf20Sopenharmony_ci 12778c2ecf20Sopenharmony_ci /* Firmware should be precisely UCODE_SIZE (words) plus three bytes 12788c2ecf20Sopenharmony_ci indicating the offsets for BUNDLESMALL, BUNDLEMAX, INTDELAY */ 12798c2ecf20Sopenharmony_ci if (fw->size != UCODE_SIZE * 4 + 3) { 12808c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, 12818c2ecf20Sopenharmony_ci "Firmware \"%s\" has wrong size %zu\n", 12828c2ecf20Sopenharmony_ci fw_name, fw->size); 12838c2ecf20Sopenharmony_ci release_firmware(fw); 12848c2ecf20Sopenharmony_ci return ERR_PTR(-EINVAL); 12858c2ecf20Sopenharmony_ci } 12868c2ecf20Sopenharmony_ci 12878c2ecf20Sopenharmony_ci /* Read timer, bundle and min_size from end of firmware blob */ 12888c2ecf20Sopenharmony_ci timer = fw->data[UCODE_SIZE * 4]; 12898c2ecf20Sopenharmony_ci bundle = fw->data[UCODE_SIZE * 4 + 1]; 12908c2ecf20Sopenharmony_ci min_size = fw->data[UCODE_SIZE * 4 + 2]; 12918c2ecf20Sopenharmony_ci 12928c2ecf20Sopenharmony_ci if (timer >= UCODE_SIZE || bundle >= UCODE_SIZE || 12938c2ecf20Sopenharmony_ci min_size >= UCODE_SIZE) { 12948c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, 12958c2ecf20Sopenharmony_ci "\"%s\" has bogus offset values (0x%x,0x%x,0x%x)\n", 12968c2ecf20Sopenharmony_ci fw_name, timer, bundle, min_size); 12978c2ecf20Sopenharmony_ci release_firmware(fw); 12988c2ecf20Sopenharmony_ci return ERR_PTR(-EINVAL); 12998c2ecf20Sopenharmony_ci } 13008c2ecf20Sopenharmony_ci 13018c2ecf20Sopenharmony_ci /* OK, firmware is validated and ready to use. Save a pointer 13028c2ecf20Sopenharmony_ci * to it in the nic */ 13038c2ecf20Sopenharmony_ci nic->fw = fw; 13048c2ecf20Sopenharmony_ci return fw; 13058c2ecf20Sopenharmony_ci} 13068c2ecf20Sopenharmony_ci 13078c2ecf20Sopenharmony_cistatic int e100_setup_ucode(struct nic *nic, struct cb *cb, 13088c2ecf20Sopenharmony_ci struct sk_buff *skb) 13098c2ecf20Sopenharmony_ci{ 13108c2ecf20Sopenharmony_ci const struct firmware *fw = (void *)skb; 13118c2ecf20Sopenharmony_ci u8 timer, bundle, min_size; 13128c2ecf20Sopenharmony_ci 13138c2ecf20Sopenharmony_ci /* It's not a real skb; we just abused the fact that e100_exec_cb 13148c2ecf20Sopenharmony_ci will pass it through to here... */ 13158c2ecf20Sopenharmony_ci cb->skb = NULL; 13168c2ecf20Sopenharmony_ci 13178c2ecf20Sopenharmony_ci /* firmware is stored as little endian already */ 13188c2ecf20Sopenharmony_ci memcpy(cb->u.ucode, fw->data, UCODE_SIZE * 4); 13198c2ecf20Sopenharmony_ci 13208c2ecf20Sopenharmony_ci /* Read timer, bundle and min_size from end of firmware blob */ 13218c2ecf20Sopenharmony_ci timer = fw->data[UCODE_SIZE * 4]; 13228c2ecf20Sopenharmony_ci bundle = fw->data[UCODE_SIZE * 4 + 1]; 13238c2ecf20Sopenharmony_ci min_size = fw->data[UCODE_SIZE * 4 + 2]; 13248c2ecf20Sopenharmony_ci 13258c2ecf20Sopenharmony_ci /* Insert user-tunable settings in cb->u.ucode */ 13268c2ecf20Sopenharmony_ci cb->u.ucode[timer] &= cpu_to_le32(0xFFFF0000); 13278c2ecf20Sopenharmony_ci cb->u.ucode[timer] |= cpu_to_le32(INTDELAY); 13288c2ecf20Sopenharmony_ci cb->u.ucode[bundle] &= cpu_to_le32(0xFFFF0000); 13298c2ecf20Sopenharmony_ci cb->u.ucode[bundle] |= cpu_to_le32(BUNDLEMAX); 13308c2ecf20Sopenharmony_ci cb->u.ucode[min_size] &= cpu_to_le32(0xFFFF0000); 13318c2ecf20Sopenharmony_ci cb->u.ucode[min_size] |= cpu_to_le32((BUNDLESMALL) ? 0xFFFF : 0xFF80); 13328c2ecf20Sopenharmony_ci 13338c2ecf20Sopenharmony_ci cb->command = cpu_to_le16(cb_ucode | cb_el); 13348c2ecf20Sopenharmony_ci return 0; 13358c2ecf20Sopenharmony_ci} 13368c2ecf20Sopenharmony_ci 13378c2ecf20Sopenharmony_cistatic inline int e100_load_ucode_wait(struct nic *nic) 13388c2ecf20Sopenharmony_ci{ 13398c2ecf20Sopenharmony_ci const struct firmware *fw; 13408c2ecf20Sopenharmony_ci int err = 0, counter = 50; 13418c2ecf20Sopenharmony_ci struct cb *cb = nic->cb_to_clean; 13428c2ecf20Sopenharmony_ci 13438c2ecf20Sopenharmony_ci fw = e100_request_firmware(nic); 13448c2ecf20Sopenharmony_ci /* If it's NULL, then no ucode is required */ 13458c2ecf20Sopenharmony_ci if (IS_ERR_OR_NULL(fw)) 13468c2ecf20Sopenharmony_ci return PTR_ERR_OR_ZERO(fw); 13478c2ecf20Sopenharmony_ci 13488c2ecf20Sopenharmony_ci if ((err = e100_exec_cb(nic, (void *)fw, e100_setup_ucode))) 13498c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, 13508c2ecf20Sopenharmony_ci "ucode cmd failed with error %d\n", err); 13518c2ecf20Sopenharmony_ci 13528c2ecf20Sopenharmony_ci /* must restart cuc */ 13538c2ecf20Sopenharmony_ci nic->cuc_cmd = cuc_start; 13548c2ecf20Sopenharmony_ci 13558c2ecf20Sopenharmony_ci /* wait for completion */ 13568c2ecf20Sopenharmony_ci e100_write_flush(nic); 13578c2ecf20Sopenharmony_ci udelay(10); 13588c2ecf20Sopenharmony_ci 13598c2ecf20Sopenharmony_ci /* wait for possibly (ouch) 500ms */ 13608c2ecf20Sopenharmony_ci while (!(cb->status & cpu_to_le16(cb_complete))) { 13618c2ecf20Sopenharmony_ci msleep(10); 13628c2ecf20Sopenharmony_ci if (!--counter) break; 13638c2ecf20Sopenharmony_ci } 13648c2ecf20Sopenharmony_ci 13658c2ecf20Sopenharmony_ci /* ack any interrupts, something could have been set */ 13668c2ecf20Sopenharmony_ci iowrite8(~0, &nic->csr->scb.stat_ack); 13678c2ecf20Sopenharmony_ci 13688c2ecf20Sopenharmony_ci /* if the command failed, or is not OK, notify and return */ 13698c2ecf20Sopenharmony_ci if (!counter || !(cb->status & cpu_to_le16(cb_ok))) { 13708c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "ucode load failed\n"); 13718c2ecf20Sopenharmony_ci err = -EPERM; 13728c2ecf20Sopenharmony_ci } 13738c2ecf20Sopenharmony_ci 13748c2ecf20Sopenharmony_ci return err; 13758c2ecf20Sopenharmony_ci} 13768c2ecf20Sopenharmony_ci 13778c2ecf20Sopenharmony_cistatic int e100_setup_iaaddr(struct nic *nic, struct cb *cb, 13788c2ecf20Sopenharmony_ci struct sk_buff *skb) 13798c2ecf20Sopenharmony_ci{ 13808c2ecf20Sopenharmony_ci cb->command = cpu_to_le16(cb_iaaddr); 13818c2ecf20Sopenharmony_ci memcpy(cb->u.iaaddr, nic->netdev->dev_addr, ETH_ALEN); 13828c2ecf20Sopenharmony_ci return 0; 13838c2ecf20Sopenharmony_ci} 13848c2ecf20Sopenharmony_ci 13858c2ecf20Sopenharmony_cistatic int e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb) 13868c2ecf20Sopenharmony_ci{ 13878c2ecf20Sopenharmony_ci cb->command = cpu_to_le16(cb_dump); 13888c2ecf20Sopenharmony_ci cb->u.dump_buffer_addr = cpu_to_le32(nic->dma_addr + 13898c2ecf20Sopenharmony_ci offsetof(struct mem, dump_buf)); 13908c2ecf20Sopenharmony_ci return 0; 13918c2ecf20Sopenharmony_ci} 13928c2ecf20Sopenharmony_ci 13938c2ecf20Sopenharmony_cistatic int e100_phy_check_without_mii(struct nic *nic) 13948c2ecf20Sopenharmony_ci{ 13958c2ecf20Sopenharmony_ci u8 phy_type; 13968c2ecf20Sopenharmony_ci int without_mii; 13978c2ecf20Sopenharmony_ci 13988c2ecf20Sopenharmony_ci phy_type = (le16_to_cpu(nic->eeprom[eeprom_phy_iface]) >> 8) & 0x0f; 13998c2ecf20Sopenharmony_ci 14008c2ecf20Sopenharmony_ci switch (phy_type) { 14018c2ecf20Sopenharmony_ci case NoSuchPhy: /* Non-MII PHY; UNTESTED! */ 14028c2ecf20Sopenharmony_ci case I82503: /* Non-MII PHY; UNTESTED! */ 14038c2ecf20Sopenharmony_ci case S80C24: /* Non-MII PHY; tested and working */ 14048c2ecf20Sopenharmony_ci /* paragraph from the FreeBSD driver, "FXP_PHY_80C24": 14058c2ecf20Sopenharmony_ci * The Seeq 80c24 AutoDUPLEX(tm) Ethernet Interface Adapter 14068c2ecf20Sopenharmony_ci * doesn't have a programming interface of any sort. The 14078c2ecf20Sopenharmony_ci * media is sensed automatically based on how the link partner 14088c2ecf20Sopenharmony_ci * is configured. This is, in essence, manual configuration. 14098c2ecf20Sopenharmony_ci */ 14108c2ecf20Sopenharmony_ci netif_info(nic, probe, nic->netdev, 14118c2ecf20Sopenharmony_ci "found MII-less i82503 or 80c24 or other PHY\n"); 14128c2ecf20Sopenharmony_ci 14138c2ecf20Sopenharmony_ci nic->mdio_ctrl = mdio_ctrl_phy_mii_emulated; 14148c2ecf20Sopenharmony_ci nic->mii.phy_id = 0; /* is this ok for an MII-less PHY? */ 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_ci /* these might be needed for certain MII-less cards... 14178c2ecf20Sopenharmony_ci * nic->flags |= ich; 14188c2ecf20Sopenharmony_ci * nic->flags |= ich_10h_workaround; */ 14198c2ecf20Sopenharmony_ci 14208c2ecf20Sopenharmony_ci without_mii = 1; 14218c2ecf20Sopenharmony_ci break; 14228c2ecf20Sopenharmony_ci default: 14238c2ecf20Sopenharmony_ci without_mii = 0; 14248c2ecf20Sopenharmony_ci break; 14258c2ecf20Sopenharmony_ci } 14268c2ecf20Sopenharmony_ci return without_mii; 14278c2ecf20Sopenharmony_ci} 14288c2ecf20Sopenharmony_ci 14298c2ecf20Sopenharmony_ci#define NCONFIG_AUTO_SWITCH 0x0080 14308c2ecf20Sopenharmony_ci#define MII_NSC_CONG MII_RESV1 14318c2ecf20Sopenharmony_ci#define NSC_CONG_ENABLE 0x0100 14328c2ecf20Sopenharmony_ci#define NSC_CONG_TXREADY 0x0400 14338c2ecf20Sopenharmony_ci#define ADVERTISE_FC_SUPPORTED 0x0400 14348c2ecf20Sopenharmony_cistatic int e100_phy_init(struct nic *nic) 14358c2ecf20Sopenharmony_ci{ 14368c2ecf20Sopenharmony_ci struct net_device *netdev = nic->netdev; 14378c2ecf20Sopenharmony_ci u32 addr; 14388c2ecf20Sopenharmony_ci u16 bmcr, stat, id_lo, id_hi, cong; 14398c2ecf20Sopenharmony_ci 14408c2ecf20Sopenharmony_ci /* Discover phy addr by searching addrs in order {1,0,2,..., 31} */ 14418c2ecf20Sopenharmony_ci for (addr = 0; addr < 32; addr++) { 14428c2ecf20Sopenharmony_ci nic->mii.phy_id = (addr == 0) ? 1 : (addr == 1) ? 0 : addr; 14438c2ecf20Sopenharmony_ci bmcr = mdio_read(netdev, nic->mii.phy_id, MII_BMCR); 14448c2ecf20Sopenharmony_ci stat = mdio_read(netdev, nic->mii.phy_id, MII_BMSR); 14458c2ecf20Sopenharmony_ci stat = mdio_read(netdev, nic->mii.phy_id, MII_BMSR); 14468c2ecf20Sopenharmony_ci if (!((bmcr == 0xFFFF) || ((stat == 0) && (bmcr == 0)))) 14478c2ecf20Sopenharmony_ci break; 14488c2ecf20Sopenharmony_ci } 14498c2ecf20Sopenharmony_ci if (addr == 32) { 14508c2ecf20Sopenharmony_ci /* uhoh, no PHY detected: check whether we seem to be some 14518c2ecf20Sopenharmony_ci * weird, rare variant which is *known* to not have any MII. 14528c2ecf20Sopenharmony_ci * But do this AFTER MII checking only, since this does 14538c2ecf20Sopenharmony_ci * lookup of EEPROM values which may easily be unreliable. */ 14548c2ecf20Sopenharmony_ci if (e100_phy_check_without_mii(nic)) 14558c2ecf20Sopenharmony_ci return 0; /* simply return and hope for the best */ 14568c2ecf20Sopenharmony_ci else { 14578c2ecf20Sopenharmony_ci /* for unknown cases log a fatal error */ 14588c2ecf20Sopenharmony_ci netif_err(nic, hw, nic->netdev, 14598c2ecf20Sopenharmony_ci "Failed to locate any known PHY, aborting\n"); 14608c2ecf20Sopenharmony_ci return -EAGAIN; 14618c2ecf20Sopenharmony_ci } 14628c2ecf20Sopenharmony_ci } else 14638c2ecf20Sopenharmony_ci netif_printk(nic, hw, KERN_DEBUG, nic->netdev, 14648c2ecf20Sopenharmony_ci "phy_addr = %d\n", nic->mii.phy_id); 14658c2ecf20Sopenharmony_ci 14668c2ecf20Sopenharmony_ci /* Get phy ID */ 14678c2ecf20Sopenharmony_ci id_lo = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID1); 14688c2ecf20Sopenharmony_ci id_hi = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID2); 14698c2ecf20Sopenharmony_ci nic->phy = (u32)id_hi << 16 | (u32)id_lo; 14708c2ecf20Sopenharmony_ci netif_printk(nic, hw, KERN_DEBUG, nic->netdev, 14718c2ecf20Sopenharmony_ci "phy ID = 0x%08X\n", nic->phy); 14728c2ecf20Sopenharmony_ci 14738c2ecf20Sopenharmony_ci /* Select the phy and isolate the rest */ 14748c2ecf20Sopenharmony_ci for (addr = 0; addr < 32; addr++) { 14758c2ecf20Sopenharmony_ci if (addr != nic->mii.phy_id) { 14768c2ecf20Sopenharmony_ci mdio_write(netdev, addr, MII_BMCR, BMCR_ISOLATE); 14778c2ecf20Sopenharmony_ci } else if (nic->phy != phy_82552_v) { 14788c2ecf20Sopenharmony_ci bmcr = mdio_read(netdev, addr, MII_BMCR); 14798c2ecf20Sopenharmony_ci mdio_write(netdev, addr, MII_BMCR, 14808c2ecf20Sopenharmony_ci bmcr & ~BMCR_ISOLATE); 14818c2ecf20Sopenharmony_ci } 14828c2ecf20Sopenharmony_ci } 14838c2ecf20Sopenharmony_ci /* 14848c2ecf20Sopenharmony_ci * Workaround for 82552: 14858c2ecf20Sopenharmony_ci * Clear the ISOLATE bit on selected phy_id last (mirrored on all 14868c2ecf20Sopenharmony_ci * other phy_id's) using bmcr value from addr discovery loop above. 14878c2ecf20Sopenharmony_ci */ 14888c2ecf20Sopenharmony_ci if (nic->phy == phy_82552_v) 14898c2ecf20Sopenharmony_ci mdio_write(netdev, nic->mii.phy_id, MII_BMCR, 14908c2ecf20Sopenharmony_ci bmcr & ~BMCR_ISOLATE); 14918c2ecf20Sopenharmony_ci 14928c2ecf20Sopenharmony_ci /* Handle National tx phys */ 14938c2ecf20Sopenharmony_ci#define NCS_PHY_MODEL_MASK 0xFFF0FFFF 14948c2ecf20Sopenharmony_ci if ((nic->phy & NCS_PHY_MODEL_MASK) == phy_nsc_tx) { 14958c2ecf20Sopenharmony_ci /* Disable congestion control */ 14968c2ecf20Sopenharmony_ci cong = mdio_read(netdev, nic->mii.phy_id, MII_NSC_CONG); 14978c2ecf20Sopenharmony_ci cong |= NSC_CONG_TXREADY; 14988c2ecf20Sopenharmony_ci cong &= ~NSC_CONG_ENABLE; 14998c2ecf20Sopenharmony_ci mdio_write(netdev, nic->mii.phy_id, MII_NSC_CONG, cong); 15008c2ecf20Sopenharmony_ci } 15018c2ecf20Sopenharmony_ci 15028c2ecf20Sopenharmony_ci if (nic->phy == phy_82552_v) { 15038c2ecf20Sopenharmony_ci u16 advert = mdio_read(netdev, nic->mii.phy_id, MII_ADVERTISE); 15048c2ecf20Sopenharmony_ci 15058c2ecf20Sopenharmony_ci /* assign special tweaked mdio_ctrl() function */ 15068c2ecf20Sopenharmony_ci nic->mdio_ctrl = mdio_ctrl_phy_82552_v; 15078c2ecf20Sopenharmony_ci 15088c2ecf20Sopenharmony_ci /* Workaround Si not advertising flow-control during autoneg */ 15098c2ecf20Sopenharmony_ci advert |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; 15108c2ecf20Sopenharmony_ci mdio_write(netdev, nic->mii.phy_id, MII_ADVERTISE, advert); 15118c2ecf20Sopenharmony_ci 15128c2ecf20Sopenharmony_ci /* Reset for the above changes to take effect */ 15138c2ecf20Sopenharmony_ci bmcr = mdio_read(netdev, nic->mii.phy_id, MII_BMCR); 15148c2ecf20Sopenharmony_ci bmcr |= BMCR_RESET; 15158c2ecf20Sopenharmony_ci mdio_write(netdev, nic->mii.phy_id, MII_BMCR, bmcr); 15168c2ecf20Sopenharmony_ci } else if ((nic->mac >= mac_82550_D102) || ((nic->flags & ich) && 15178c2ecf20Sopenharmony_ci (mdio_read(netdev, nic->mii.phy_id, MII_TPISTATUS) & 0x8000) && 15188c2ecf20Sopenharmony_ci (le16_to_cpu(nic->eeprom[eeprom_cnfg_mdix]) & eeprom_mdix_enabled))) { 15198c2ecf20Sopenharmony_ci /* enable/disable MDI/MDI-X auto-switching. */ 15208c2ecf20Sopenharmony_ci mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG, 15218c2ecf20Sopenharmony_ci nic->mii.force_media ? 0 : NCONFIG_AUTO_SWITCH); 15228c2ecf20Sopenharmony_ci } 15238c2ecf20Sopenharmony_ci 15248c2ecf20Sopenharmony_ci return 0; 15258c2ecf20Sopenharmony_ci} 15268c2ecf20Sopenharmony_ci 15278c2ecf20Sopenharmony_cistatic int e100_hw_init(struct nic *nic) 15288c2ecf20Sopenharmony_ci{ 15298c2ecf20Sopenharmony_ci int err = 0; 15308c2ecf20Sopenharmony_ci 15318c2ecf20Sopenharmony_ci e100_hw_reset(nic); 15328c2ecf20Sopenharmony_ci 15338c2ecf20Sopenharmony_ci netif_err(nic, hw, nic->netdev, "e100_hw_init\n"); 15348c2ecf20Sopenharmony_ci if ((err = e100_self_test(nic))) 15358c2ecf20Sopenharmony_ci return err; 15368c2ecf20Sopenharmony_ci 15378c2ecf20Sopenharmony_ci if ((err = e100_phy_init(nic))) 15388c2ecf20Sopenharmony_ci return err; 15398c2ecf20Sopenharmony_ci if ((err = e100_exec_cmd(nic, cuc_load_base, 0))) 15408c2ecf20Sopenharmony_ci return err; 15418c2ecf20Sopenharmony_ci if ((err = e100_exec_cmd(nic, ruc_load_base, 0))) 15428c2ecf20Sopenharmony_ci return err; 15438c2ecf20Sopenharmony_ci if ((err = e100_load_ucode_wait(nic))) 15448c2ecf20Sopenharmony_ci return err; 15458c2ecf20Sopenharmony_ci if ((err = e100_exec_cb(nic, NULL, e100_configure))) 15468c2ecf20Sopenharmony_ci return err; 15478c2ecf20Sopenharmony_ci if ((err = e100_exec_cb(nic, NULL, e100_setup_iaaddr))) 15488c2ecf20Sopenharmony_ci return err; 15498c2ecf20Sopenharmony_ci if ((err = e100_exec_cmd(nic, cuc_dump_addr, 15508c2ecf20Sopenharmony_ci nic->dma_addr + offsetof(struct mem, stats)))) 15518c2ecf20Sopenharmony_ci return err; 15528c2ecf20Sopenharmony_ci if ((err = e100_exec_cmd(nic, cuc_dump_reset, 0))) 15538c2ecf20Sopenharmony_ci return err; 15548c2ecf20Sopenharmony_ci 15558c2ecf20Sopenharmony_ci e100_disable_irq(nic); 15568c2ecf20Sopenharmony_ci 15578c2ecf20Sopenharmony_ci return 0; 15588c2ecf20Sopenharmony_ci} 15598c2ecf20Sopenharmony_ci 15608c2ecf20Sopenharmony_cistatic int e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb) 15618c2ecf20Sopenharmony_ci{ 15628c2ecf20Sopenharmony_ci struct net_device *netdev = nic->netdev; 15638c2ecf20Sopenharmony_ci struct netdev_hw_addr *ha; 15648c2ecf20Sopenharmony_ci u16 i, count = min(netdev_mc_count(netdev), E100_MAX_MULTICAST_ADDRS); 15658c2ecf20Sopenharmony_ci 15668c2ecf20Sopenharmony_ci cb->command = cpu_to_le16(cb_multi); 15678c2ecf20Sopenharmony_ci cb->u.multi.count = cpu_to_le16(count * ETH_ALEN); 15688c2ecf20Sopenharmony_ci i = 0; 15698c2ecf20Sopenharmony_ci netdev_for_each_mc_addr(ha, netdev) { 15708c2ecf20Sopenharmony_ci if (i == count) 15718c2ecf20Sopenharmony_ci break; 15728c2ecf20Sopenharmony_ci memcpy(&cb->u.multi.addr[i++ * ETH_ALEN], &ha->addr, 15738c2ecf20Sopenharmony_ci ETH_ALEN); 15748c2ecf20Sopenharmony_ci } 15758c2ecf20Sopenharmony_ci return 0; 15768c2ecf20Sopenharmony_ci} 15778c2ecf20Sopenharmony_ci 15788c2ecf20Sopenharmony_cistatic void e100_set_multicast_list(struct net_device *netdev) 15798c2ecf20Sopenharmony_ci{ 15808c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 15818c2ecf20Sopenharmony_ci 15828c2ecf20Sopenharmony_ci netif_printk(nic, hw, KERN_DEBUG, nic->netdev, 15838c2ecf20Sopenharmony_ci "mc_count=%d, flags=0x%04X\n", 15848c2ecf20Sopenharmony_ci netdev_mc_count(netdev), netdev->flags); 15858c2ecf20Sopenharmony_ci 15868c2ecf20Sopenharmony_ci if (netdev->flags & IFF_PROMISC) 15878c2ecf20Sopenharmony_ci nic->flags |= promiscuous; 15888c2ecf20Sopenharmony_ci else 15898c2ecf20Sopenharmony_ci nic->flags &= ~promiscuous; 15908c2ecf20Sopenharmony_ci 15918c2ecf20Sopenharmony_ci if (netdev->flags & IFF_ALLMULTI || 15928c2ecf20Sopenharmony_ci netdev_mc_count(netdev) > E100_MAX_MULTICAST_ADDRS) 15938c2ecf20Sopenharmony_ci nic->flags |= multicast_all; 15948c2ecf20Sopenharmony_ci else 15958c2ecf20Sopenharmony_ci nic->flags &= ~multicast_all; 15968c2ecf20Sopenharmony_ci 15978c2ecf20Sopenharmony_ci e100_exec_cb(nic, NULL, e100_configure); 15988c2ecf20Sopenharmony_ci e100_exec_cb(nic, NULL, e100_multi); 15998c2ecf20Sopenharmony_ci} 16008c2ecf20Sopenharmony_ci 16018c2ecf20Sopenharmony_cistatic void e100_update_stats(struct nic *nic) 16028c2ecf20Sopenharmony_ci{ 16038c2ecf20Sopenharmony_ci struct net_device *dev = nic->netdev; 16048c2ecf20Sopenharmony_ci struct net_device_stats *ns = &dev->stats; 16058c2ecf20Sopenharmony_ci struct stats *s = &nic->mem->stats; 16068c2ecf20Sopenharmony_ci __le32 *complete = (nic->mac < mac_82558_D101_A4) ? &s->fc_xmt_pause : 16078c2ecf20Sopenharmony_ci (nic->mac < mac_82559_D101M) ? (__le32 *)&s->xmt_tco_frames : 16088c2ecf20Sopenharmony_ci &s->complete; 16098c2ecf20Sopenharmony_ci 16108c2ecf20Sopenharmony_ci /* Device's stats reporting may take several microseconds to 16118c2ecf20Sopenharmony_ci * complete, so we're always waiting for results of the 16128c2ecf20Sopenharmony_ci * previous command. */ 16138c2ecf20Sopenharmony_ci 16148c2ecf20Sopenharmony_ci if (*complete == cpu_to_le32(cuc_dump_reset_complete)) { 16158c2ecf20Sopenharmony_ci *complete = 0; 16168c2ecf20Sopenharmony_ci nic->tx_frames = le32_to_cpu(s->tx_good_frames); 16178c2ecf20Sopenharmony_ci nic->tx_collisions = le32_to_cpu(s->tx_total_collisions); 16188c2ecf20Sopenharmony_ci ns->tx_aborted_errors += le32_to_cpu(s->tx_max_collisions); 16198c2ecf20Sopenharmony_ci ns->tx_window_errors += le32_to_cpu(s->tx_late_collisions); 16208c2ecf20Sopenharmony_ci ns->tx_carrier_errors += le32_to_cpu(s->tx_lost_crs); 16218c2ecf20Sopenharmony_ci ns->tx_fifo_errors += le32_to_cpu(s->tx_underruns); 16228c2ecf20Sopenharmony_ci ns->collisions += nic->tx_collisions; 16238c2ecf20Sopenharmony_ci ns->tx_errors += le32_to_cpu(s->tx_max_collisions) + 16248c2ecf20Sopenharmony_ci le32_to_cpu(s->tx_lost_crs); 16258c2ecf20Sopenharmony_ci nic->rx_short_frame_errors += 16268c2ecf20Sopenharmony_ci le32_to_cpu(s->rx_short_frame_errors); 16278c2ecf20Sopenharmony_ci ns->rx_length_errors = nic->rx_short_frame_errors + 16288c2ecf20Sopenharmony_ci nic->rx_over_length_errors; 16298c2ecf20Sopenharmony_ci ns->rx_crc_errors += le32_to_cpu(s->rx_crc_errors); 16308c2ecf20Sopenharmony_ci ns->rx_frame_errors += le32_to_cpu(s->rx_alignment_errors); 16318c2ecf20Sopenharmony_ci ns->rx_over_errors += le32_to_cpu(s->rx_overrun_errors); 16328c2ecf20Sopenharmony_ci ns->rx_fifo_errors += le32_to_cpu(s->rx_overrun_errors); 16338c2ecf20Sopenharmony_ci ns->rx_missed_errors += le32_to_cpu(s->rx_resource_errors); 16348c2ecf20Sopenharmony_ci ns->rx_errors += le32_to_cpu(s->rx_crc_errors) + 16358c2ecf20Sopenharmony_ci le32_to_cpu(s->rx_alignment_errors) + 16368c2ecf20Sopenharmony_ci le32_to_cpu(s->rx_short_frame_errors) + 16378c2ecf20Sopenharmony_ci le32_to_cpu(s->rx_cdt_errors); 16388c2ecf20Sopenharmony_ci nic->tx_deferred += le32_to_cpu(s->tx_deferred); 16398c2ecf20Sopenharmony_ci nic->tx_single_collisions += 16408c2ecf20Sopenharmony_ci le32_to_cpu(s->tx_single_collisions); 16418c2ecf20Sopenharmony_ci nic->tx_multiple_collisions += 16428c2ecf20Sopenharmony_ci le32_to_cpu(s->tx_multiple_collisions); 16438c2ecf20Sopenharmony_ci if (nic->mac >= mac_82558_D101_A4) { 16448c2ecf20Sopenharmony_ci nic->tx_fc_pause += le32_to_cpu(s->fc_xmt_pause); 16458c2ecf20Sopenharmony_ci nic->rx_fc_pause += le32_to_cpu(s->fc_rcv_pause); 16468c2ecf20Sopenharmony_ci nic->rx_fc_unsupported += 16478c2ecf20Sopenharmony_ci le32_to_cpu(s->fc_rcv_unsupported); 16488c2ecf20Sopenharmony_ci if (nic->mac >= mac_82559_D101M) { 16498c2ecf20Sopenharmony_ci nic->tx_tco_frames += 16508c2ecf20Sopenharmony_ci le16_to_cpu(s->xmt_tco_frames); 16518c2ecf20Sopenharmony_ci nic->rx_tco_frames += 16528c2ecf20Sopenharmony_ci le16_to_cpu(s->rcv_tco_frames); 16538c2ecf20Sopenharmony_ci } 16548c2ecf20Sopenharmony_ci } 16558c2ecf20Sopenharmony_ci } 16568c2ecf20Sopenharmony_ci 16578c2ecf20Sopenharmony_ci 16588c2ecf20Sopenharmony_ci if (e100_exec_cmd(nic, cuc_dump_reset, 0)) 16598c2ecf20Sopenharmony_ci netif_printk(nic, tx_err, KERN_DEBUG, nic->netdev, 16608c2ecf20Sopenharmony_ci "exec cuc_dump_reset failed\n"); 16618c2ecf20Sopenharmony_ci} 16628c2ecf20Sopenharmony_ci 16638c2ecf20Sopenharmony_cistatic void e100_adjust_adaptive_ifs(struct nic *nic, int speed, int duplex) 16648c2ecf20Sopenharmony_ci{ 16658c2ecf20Sopenharmony_ci /* Adjust inter-frame-spacing (IFS) between two transmits if 16668c2ecf20Sopenharmony_ci * we're getting collisions on a half-duplex connection. */ 16678c2ecf20Sopenharmony_ci 16688c2ecf20Sopenharmony_ci if (duplex == DUPLEX_HALF) { 16698c2ecf20Sopenharmony_ci u32 prev = nic->adaptive_ifs; 16708c2ecf20Sopenharmony_ci u32 min_frames = (speed == SPEED_100) ? 1000 : 100; 16718c2ecf20Sopenharmony_ci 16728c2ecf20Sopenharmony_ci if ((nic->tx_frames / 32 < nic->tx_collisions) && 16738c2ecf20Sopenharmony_ci (nic->tx_frames > min_frames)) { 16748c2ecf20Sopenharmony_ci if (nic->adaptive_ifs < 60) 16758c2ecf20Sopenharmony_ci nic->adaptive_ifs += 5; 16768c2ecf20Sopenharmony_ci } else if (nic->tx_frames < min_frames) { 16778c2ecf20Sopenharmony_ci if (nic->adaptive_ifs >= 5) 16788c2ecf20Sopenharmony_ci nic->adaptive_ifs -= 5; 16798c2ecf20Sopenharmony_ci } 16808c2ecf20Sopenharmony_ci if (nic->adaptive_ifs != prev) 16818c2ecf20Sopenharmony_ci e100_exec_cb(nic, NULL, e100_configure); 16828c2ecf20Sopenharmony_ci } 16838c2ecf20Sopenharmony_ci} 16848c2ecf20Sopenharmony_ci 16858c2ecf20Sopenharmony_cistatic void e100_watchdog(struct timer_list *t) 16868c2ecf20Sopenharmony_ci{ 16878c2ecf20Sopenharmony_ci struct nic *nic = from_timer(nic, t, watchdog); 16888c2ecf20Sopenharmony_ci struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET }; 16898c2ecf20Sopenharmony_ci u32 speed; 16908c2ecf20Sopenharmony_ci 16918c2ecf20Sopenharmony_ci netif_printk(nic, timer, KERN_DEBUG, nic->netdev, 16928c2ecf20Sopenharmony_ci "right now = %ld\n", jiffies); 16938c2ecf20Sopenharmony_ci 16948c2ecf20Sopenharmony_ci /* mii library handles link maintenance tasks */ 16958c2ecf20Sopenharmony_ci 16968c2ecf20Sopenharmony_ci mii_ethtool_gset(&nic->mii, &cmd); 16978c2ecf20Sopenharmony_ci speed = ethtool_cmd_speed(&cmd); 16988c2ecf20Sopenharmony_ci 16998c2ecf20Sopenharmony_ci if (mii_link_ok(&nic->mii) && !netif_carrier_ok(nic->netdev)) { 17008c2ecf20Sopenharmony_ci netdev_info(nic->netdev, "NIC Link is Up %u Mbps %s Duplex\n", 17018c2ecf20Sopenharmony_ci speed == SPEED_100 ? 100 : 10, 17028c2ecf20Sopenharmony_ci cmd.duplex == DUPLEX_FULL ? "Full" : "Half"); 17038c2ecf20Sopenharmony_ci } else if (!mii_link_ok(&nic->mii) && netif_carrier_ok(nic->netdev)) { 17048c2ecf20Sopenharmony_ci netdev_info(nic->netdev, "NIC Link is Down\n"); 17058c2ecf20Sopenharmony_ci } 17068c2ecf20Sopenharmony_ci 17078c2ecf20Sopenharmony_ci mii_check_link(&nic->mii); 17088c2ecf20Sopenharmony_ci 17098c2ecf20Sopenharmony_ci /* Software generated interrupt to recover from (rare) Rx 17108c2ecf20Sopenharmony_ci * allocation failure. 17118c2ecf20Sopenharmony_ci * Unfortunately have to use a spinlock to not re-enable interrupts 17128c2ecf20Sopenharmony_ci * accidentally, due to hardware that shares a register between the 17138c2ecf20Sopenharmony_ci * interrupt mask bit and the SW Interrupt generation bit */ 17148c2ecf20Sopenharmony_ci spin_lock_irq(&nic->cmd_lock); 17158c2ecf20Sopenharmony_ci iowrite8(ioread8(&nic->csr->scb.cmd_hi) | irq_sw_gen,&nic->csr->scb.cmd_hi); 17168c2ecf20Sopenharmony_ci e100_write_flush(nic); 17178c2ecf20Sopenharmony_ci spin_unlock_irq(&nic->cmd_lock); 17188c2ecf20Sopenharmony_ci 17198c2ecf20Sopenharmony_ci e100_update_stats(nic); 17208c2ecf20Sopenharmony_ci e100_adjust_adaptive_ifs(nic, speed, cmd.duplex); 17218c2ecf20Sopenharmony_ci 17228c2ecf20Sopenharmony_ci if (nic->mac <= mac_82557_D100_C) 17238c2ecf20Sopenharmony_ci /* Issue a multicast command to workaround a 557 lock up */ 17248c2ecf20Sopenharmony_ci e100_set_multicast_list(nic->netdev); 17258c2ecf20Sopenharmony_ci 17268c2ecf20Sopenharmony_ci if (nic->flags & ich && speed == SPEED_10 && cmd.duplex == DUPLEX_HALF) 17278c2ecf20Sopenharmony_ci /* Need SW workaround for ICH[x] 10Mbps/half duplex Tx hang. */ 17288c2ecf20Sopenharmony_ci nic->flags |= ich_10h_workaround; 17298c2ecf20Sopenharmony_ci else 17308c2ecf20Sopenharmony_ci nic->flags &= ~ich_10h_workaround; 17318c2ecf20Sopenharmony_ci 17328c2ecf20Sopenharmony_ci mod_timer(&nic->watchdog, 17338c2ecf20Sopenharmony_ci round_jiffies(jiffies + E100_WATCHDOG_PERIOD)); 17348c2ecf20Sopenharmony_ci} 17358c2ecf20Sopenharmony_ci 17368c2ecf20Sopenharmony_cistatic int e100_xmit_prepare(struct nic *nic, struct cb *cb, 17378c2ecf20Sopenharmony_ci struct sk_buff *skb) 17388c2ecf20Sopenharmony_ci{ 17398c2ecf20Sopenharmony_ci dma_addr_t dma_addr; 17408c2ecf20Sopenharmony_ci cb->command = nic->tx_command; 17418c2ecf20Sopenharmony_ci 17428c2ecf20Sopenharmony_ci dma_addr = dma_map_single(&nic->pdev->dev, skb->data, skb->len, 17438c2ecf20Sopenharmony_ci DMA_TO_DEVICE); 17448c2ecf20Sopenharmony_ci /* If we can't map the skb, have the upper layer try later */ 17458c2ecf20Sopenharmony_ci if (dma_mapping_error(&nic->pdev->dev, dma_addr)) 17468c2ecf20Sopenharmony_ci return -ENOMEM; 17478c2ecf20Sopenharmony_ci 17488c2ecf20Sopenharmony_ci /* 17498c2ecf20Sopenharmony_ci * Use the last 4 bytes of the SKB payload packet as the CRC, used for 17508c2ecf20Sopenharmony_ci * testing, ie sending frames with bad CRC. 17518c2ecf20Sopenharmony_ci */ 17528c2ecf20Sopenharmony_ci if (unlikely(skb->no_fcs)) 17538c2ecf20Sopenharmony_ci cb->command |= cpu_to_le16(cb_tx_nc); 17548c2ecf20Sopenharmony_ci else 17558c2ecf20Sopenharmony_ci cb->command &= ~cpu_to_le16(cb_tx_nc); 17568c2ecf20Sopenharmony_ci 17578c2ecf20Sopenharmony_ci /* interrupt every 16 packets regardless of delay */ 17588c2ecf20Sopenharmony_ci if ((nic->cbs_avail & ~15) == nic->cbs_avail) 17598c2ecf20Sopenharmony_ci cb->command |= cpu_to_le16(cb_i); 17608c2ecf20Sopenharmony_ci cb->u.tcb.tbd_array = cb->dma_addr + offsetof(struct cb, u.tcb.tbd); 17618c2ecf20Sopenharmony_ci cb->u.tcb.tcb_byte_count = 0; 17628c2ecf20Sopenharmony_ci cb->u.tcb.threshold = nic->tx_threshold; 17638c2ecf20Sopenharmony_ci cb->u.tcb.tbd_count = 1; 17648c2ecf20Sopenharmony_ci cb->u.tcb.tbd.buf_addr = cpu_to_le32(dma_addr); 17658c2ecf20Sopenharmony_ci cb->u.tcb.tbd.size = cpu_to_le16(skb->len); 17668c2ecf20Sopenharmony_ci skb_tx_timestamp(skb); 17678c2ecf20Sopenharmony_ci return 0; 17688c2ecf20Sopenharmony_ci} 17698c2ecf20Sopenharmony_ci 17708c2ecf20Sopenharmony_cistatic netdev_tx_t e100_xmit_frame(struct sk_buff *skb, 17718c2ecf20Sopenharmony_ci struct net_device *netdev) 17728c2ecf20Sopenharmony_ci{ 17738c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 17748c2ecf20Sopenharmony_ci int err; 17758c2ecf20Sopenharmony_ci 17768c2ecf20Sopenharmony_ci if (nic->flags & ich_10h_workaround) { 17778c2ecf20Sopenharmony_ci /* SW workaround for ICH[x] 10Mbps/half duplex Tx hang. 17788c2ecf20Sopenharmony_ci Issue a NOP command followed by a 1us delay before 17798c2ecf20Sopenharmony_ci issuing the Tx command. */ 17808c2ecf20Sopenharmony_ci if (e100_exec_cmd(nic, cuc_nop, 0)) 17818c2ecf20Sopenharmony_ci netif_printk(nic, tx_err, KERN_DEBUG, nic->netdev, 17828c2ecf20Sopenharmony_ci "exec cuc_nop failed\n"); 17838c2ecf20Sopenharmony_ci udelay(1); 17848c2ecf20Sopenharmony_ci } 17858c2ecf20Sopenharmony_ci 17868c2ecf20Sopenharmony_ci err = e100_exec_cb(nic, skb, e100_xmit_prepare); 17878c2ecf20Sopenharmony_ci 17888c2ecf20Sopenharmony_ci switch (err) { 17898c2ecf20Sopenharmony_ci case -ENOSPC: 17908c2ecf20Sopenharmony_ci /* We queued the skb, but now we're out of space. */ 17918c2ecf20Sopenharmony_ci netif_printk(nic, tx_err, KERN_DEBUG, nic->netdev, 17928c2ecf20Sopenharmony_ci "No space for CB\n"); 17938c2ecf20Sopenharmony_ci netif_stop_queue(netdev); 17948c2ecf20Sopenharmony_ci break; 17958c2ecf20Sopenharmony_ci case -ENOMEM: 17968c2ecf20Sopenharmony_ci /* This is a hard error - log it. */ 17978c2ecf20Sopenharmony_ci netif_printk(nic, tx_err, KERN_DEBUG, nic->netdev, 17988c2ecf20Sopenharmony_ci "Out of Tx resources, returning skb\n"); 17998c2ecf20Sopenharmony_ci netif_stop_queue(netdev); 18008c2ecf20Sopenharmony_ci return NETDEV_TX_BUSY; 18018c2ecf20Sopenharmony_ci } 18028c2ecf20Sopenharmony_ci 18038c2ecf20Sopenharmony_ci return NETDEV_TX_OK; 18048c2ecf20Sopenharmony_ci} 18058c2ecf20Sopenharmony_ci 18068c2ecf20Sopenharmony_cistatic int e100_tx_clean(struct nic *nic) 18078c2ecf20Sopenharmony_ci{ 18088c2ecf20Sopenharmony_ci struct net_device *dev = nic->netdev; 18098c2ecf20Sopenharmony_ci struct cb *cb; 18108c2ecf20Sopenharmony_ci int tx_cleaned = 0; 18118c2ecf20Sopenharmony_ci 18128c2ecf20Sopenharmony_ci spin_lock(&nic->cb_lock); 18138c2ecf20Sopenharmony_ci 18148c2ecf20Sopenharmony_ci /* Clean CBs marked complete */ 18158c2ecf20Sopenharmony_ci for (cb = nic->cb_to_clean; 18168c2ecf20Sopenharmony_ci cb->status & cpu_to_le16(cb_complete); 18178c2ecf20Sopenharmony_ci cb = nic->cb_to_clean = cb->next) { 18188c2ecf20Sopenharmony_ci dma_rmb(); /* read skb after status */ 18198c2ecf20Sopenharmony_ci netif_printk(nic, tx_done, KERN_DEBUG, nic->netdev, 18208c2ecf20Sopenharmony_ci "cb[%d]->status = 0x%04X\n", 18218c2ecf20Sopenharmony_ci (int)(((void*)cb - (void*)nic->cbs)/sizeof(struct cb)), 18228c2ecf20Sopenharmony_ci cb->status); 18238c2ecf20Sopenharmony_ci 18248c2ecf20Sopenharmony_ci if (likely(cb->skb != NULL)) { 18258c2ecf20Sopenharmony_ci dev->stats.tx_packets++; 18268c2ecf20Sopenharmony_ci dev->stats.tx_bytes += cb->skb->len; 18278c2ecf20Sopenharmony_ci 18288c2ecf20Sopenharmony_ci dma_unmap_single(&nic->pdev->dev, 18298c2ecf20Sopenharmony_ci le32_to_cpu(cb->u.tcb.tbd.buf_addr), 18308c2ecf20Sopenharmony_ci le16_to_cpu(cb->u.tcb.tbd.size), 18318c2ecf20Sopenharmony_ci DMA_TO_DEVICE); 18328c2ecf20Sopenharmony_ci dev_kfree_skb_any(cb->skb); 18338c2ecf20Sopenharmony_ci cb->skb = NULL; 18348c2ecf20Sopenharmony_ci tx_cleaned = 1; 18358c2ecf20Sopenharmony_ci } 18368c2ecf20Sopenharmony_ci cb->status = 0; 18378c2ecf20Sopenharmony_ci nic->cbs_avail++; 18388c2ecf20Sopenharmony_ci } 18398c2ecf20Sopenharmony_ci 18408c2ecf20Sopenharmony_ci spin_unlock(&nic->cb_lock); 18418c2ecf20Sopenharmony_ci 18428c2ecf20Sopenharmony_ci /* Recover from running out of Tx resources in xmit_frame */ 18438c2ecf20Sopenharmony_ci if (unlikely(tx_cleaned && netif_queue_stopped(nic->netdev))) 18448c2ecf20Sopenharmony_ci netif_wake_queue(nic->netdev); 18458c2ecf20Sopenharmony_ci 18468c2ecf20Sopenharmony_ci return tx_cleaned; 18478c2ecf20Sopenharmony_ci} 18488c2ecf20Sopenharmony_ci 18498c2ecf20Sopenharmony_cistatic void e100_clean_cbs(struct nic *nic) 18508c2ecf20Sopenharmony_ci{ 18518c2ecf20Sopenharmony_ci if (nic->cbs) { 18528c2ecf20Sopenharmony_ci while (nic->cbs_avail != nic->params.cbs.count) { 18538c2ecf20Sopenharmony_ci struct cb *cb = nic->cb_to_clean; 18548c2ecf20Sopenharmony_ci if (cb->skb) { 18558c2ecf20Sopenharmony_ci dma_unmap_single(&nic->pdev->dev, 18568c2ecf20Sopenharmony_ci le32_to_cpu(cb->u.tcb.tbd.buf_addr), 18578c2ecf20Sopenharmony_ci le16_to_cpu(cb->u.tcb.tbd.size), 18588c2ecf20Sopenharmony_ci DMA_TO_DEVICE); 18598c2ecf20Sopenharmony_ci dev_kfree_skb(cb->skb); 18608c2ecf20Sopenharmony_ci } 18618c2ecf20Sopenharmony_ci nic->cb_to_clean = nic->cb_to_clean->next; 18628c2ecf20Sopenharmony_ci nic->cbs_avail++; 18638c2ecf20Sopenharmony_ci } 18648c2ecf20Sopenharmony_ci dma_pool_free(nic->cbs_pool, nic->cbs, nic->cbs_dma_addr); 18658c2ecf20Sopenharmony_ci nic->cbs = NULL; 18668c2ecf20Sopenharmony_ci nic->cbs_avail = 0; 18678c2ecf20Sopenharmony_ci } 18688c2ecf20Sopenharmony_ci nic->cuc_cmd = cuc_start; 18698c2ecf20Sopenharmony_ci nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = 18708c2ecf20Sopenharmony_ci nic->cbs; 18718c2ecf20Sopenharmony_ci} 18728c2ecf20Sopenharmony_ci 18738c2ecf20Sopenharmony_cistatic int e100_alloc_cbs(struct nic *nic) 18748c2ecf20Sopenharmony_ci{ 18758c2ecf20Sopenharmony_ci struct cb *cb; 18768c2ecf20Sopenharmony_ci unsigned int i, count = nic->params.cbs.count; 18778c2ecf20Sopenharmony_ci 18788c2ecf20Sopenharmony_ci nic->cuc_cmd = cuc_start; 18798c2ecf20Sopenharmony_ci nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = NULL; 18808c2ecf20Sopenharmony_ci nic->cbs_avail = 0; 18818c2ecf20Sopenharmony_ci 18828c2ecf20Sopenharmony_ci nic->cbs = dma_pool_zalloc(nic->cbs_pool, GFP_KERNEL, 18838c2ecf20Sopenharmony_ci &nic->cbs_dma_addr); 18848c2ecf20Sopenharmony_ci if (!nic->cbs) 18858c2ecf20Sopenharmony_ci return -ENOMEM; 18868c2ecf20Sopenharmony_ci 18878c2ecf20Sopenharmony_ci for (cb = nic->cbs, i = 0; i < count; cb++, i++) { 18888c2ecf20Sopenharmony_ci cb->next = (i + 1 < count) ? cb + 1 : nic->cbs; 18898c2ecf20Sopenharmony_ci cb->prev = (i == 0) ? nic->cbs + count - 1 : cb - 1; 18908c2ecf20Sopenharmony_ci 18918c2ecf20Sopenharmony_ci cb->dma_addr = nic->cbs_dma_addr + i * sizeof(struct cb); 18928c2ecf20Sopenharmony_ci cb->link = cpu_to_le32(nic->cbs_dma_addr + 18938c2ecf20Sopenharmony_ci ((i+1) % count) * sizeof(struct cb)); 18948c2ecf20Sopenharmony_ci } 18958c2ecf20Sopenharmony_ci 18968c2ecf20Sopenharmony_ci nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = nic->cbs; 18978c2ecf20Sopenharmony_ci nic->cbs_avail = count; 18988c2ecf20Sopenharmony_ci 18998c2ecf20Sopenharmony_ci return 0; 19008c2ecf20Sopenharmony_ci} 19018c2ecf20Sopenharmony_ci 19028c2ecf20Sopenharmony_cistatic inline void e100_start_receiver(struct nic *nic, struct rx *rx) 19038c2ecf20Sopenharmony_ci{ 19048c2ecf20Sopenharmony_ci if (!nic->rxs) return; 19058c2ecf20Sopenharmony_ci if (RU_SUSPENDED != nic->ru_running) return; 19068c2ecf20Sopenharmony_ci 19078c2ecf20Sopenharmony_ci /* handle init time starts */ 19088c2ecf20Sopenharmony_ci if (!rx) rx = nic->rxs; 19098c2ecf20Sopenharmony_ci 19108c2ecf20Sopenharmony_ci /* (Re)start RU if suspended or idle and RFA is non-NULL */ 19118c2ecf20Sopenharmony_ci if (rx->skb) { 19128c2ecf20Sopenharmony_ci e100_exec_cmd(nic, ruc_start, rx->dma_addr); 19138c2ecf20Sopenharmony_ci nic->ru_running = RU_RUNNING; 19148c2ecf20Sopenharmony_ci } 19158c2ecf20Sopenharmony_ci} 19168c2ecf20Sopenharmony_ci 19178c2ecf20Sopenharmony_ci#define RFD_BUF_LEN (sizeof(struct rfd) + VLAN_ETH_FRAME_LEN + ETH_FCS_LEN) 19188c2ecf20Sopenharmony_cistatic int e100_rx_alloc_skb(struct nic *nic, struct rx *rx) 19198c2ecf20Sopenharmony_ci{ 19208c2ecf20Sopenharmony_ci if (!(rx->skb = netdev_alloc_skb_ip_align(nic->netdev, RFD_BUF_LEN))) 19218c2ecf20Sopenharmony_ci return -ENOMEM; 19228c2ecf20Sopenharmony_ci 19238c2ecf20Sopenharmony_ci /* Init, and map the RFD. */ 19248c2ecf20Sopenharmony_ci skb_copy_to_linear_data(rx->skb, &nic->blank_rfd, sizeof(struct rfd)); 19258c2ecf20Sopenharmony_ci rx->dma_addr = dma_map_single(&nic->pdev->dev, rx->skb->data, 19268c2ecf20Sopenharmony_ci RFD_BUF_LEN, DMA_BIDIRECTIONAL); 19278c2ecf20Sopenharmony_ci 19288c2ecf20Sopenharmony_ci if (dma_mapping_error(&nic->pdev->dev, rx->dma_addr)) { 19298c2ecf20Sopenharmony_ci dev_kfree_skb_any(rx->skb); 19308c2ecf20Sopenharmony_ci rx->skb = NULL; 19318c2ecf20Sopenharmony_ci rx->dma_addr = 0; 19328c2ecf20Sopenharmony_ci return -ENOMEM; 19338c2ecf20Sopenharmony_ci } 19348c2ecf20Sopenharmony_ci 19358c2ecf20Sopenharmony_ci /* Link the RFD to end of RFA by linking previous RFD to 19368c2ecf20Sopenharmony_ci * this one. We are safe to touch the previous RFD because 19378c2ecf20Sopenharmony_ci * it is protected by the before last buffer's el bit being set */ 19388c2ecf20Sopenharmony_ci if (rx->prev->skb) { 19398c2ecf20Sopenharmony_ci struct rfd *prev_rfd = (struct rfd *)rx->prev->skb->data; 19408c2ecf20Sopenharmony_ci put_unaligned_le32(rx->dma_addr, &prev_rfd->link); 19418c2ecf20Sopenharmony_ci dma_sync_single_for_device(&nic->pdev->dev, 19428c2ecf20Sopenharmony_ci rx->prev->dma_addr, 19438c2ecf20Sopenharmony_ci sizeof(struct rfd), 19448c2ecf20Sopenharmony_ci DMA_BIDIRECTIONAL); 19458c2ecf20Sopenharmony_ci } 19468c2ecf20Sopenharmony_ci 19478c2ecf20Sopenharmony_ci return 0; 19488c2ecf20Sopenharmony_ci} 19498c2ecf20Sopenharmony_ci 19508c2ecf20Sopenharmony_cistatic int e100_rx_indicate(struct nic *nic, struct rx *rx, 19518c2ecf20Sopenharmony_ci unsigned int *work_done, unsigned int work_to_do) 19528c2ecf20Sopenharmony_ci{ 19538c2ecf20Sopenharmony_ci struct net_device *dev = nic->netdev; 19548c2ecf20Sopenharmony_ci struct sk_buff *skb = rx->skb; 19558c2ecf20Sopenharmony_ci struct rfd *rfd = (struct rfd *)skb->data; 19568c2ecf20Sopenharmony_ci u16 rfd_status, actual_size; 19578c2ecf20Sopenharmony_ci u16 fcs_pad = 0; 19588c2ecf20Sopenharmony_ci 19598c2ecf20Sopenharmony_ci if (unlikely(work_done && *work_done >= work_to_do)) 19608c2ecf20Sopenharmony_ci return -EAGAIN; 19618c2ecf20Sopenharmony_ci 19628c2ecf20Sopenharmony_ci /* Need to sync before taking a peek at cb_complete bit */ 19638c2ecf20Sopenharmony_ci dma_sync_single_for_cpu(&nic->pdev->dev, rx->dma_addr, 19648c2ecf20Sopenharmony_ci sizeof(struct rfd), DMA_BIDIRECTIONAL); 19658c2ecf20Sopenharmony_ci rfd_status = le16_to_cpu(rfd->status); 19668c2ecf20Sopenharmony_ci 19678c2ecf20Sopenharmony_ci netif_printk(nic, rx_status, KERN_DEBUG, nic->netdev, 19688c2ecf20Sopenharmony_ci "status=0x%04X\n", rfd_status); 19698c2ecf20Sopenharmony_ci dma_rmb(); /* read size after status bit */ 19708c2ecf20Sopenharmony_ci 19718c2ecf20Sopenharmony_ci /* If data isn't ready, nothing to indicate */ 19728c2ecf20Sopenharmony_ci if (unlikely(!(rfd_status & cb_complete))) { 19738c2ecf20Sopenharmony_ci /* If the next buffer has the el bit, but we think the receiver 19748c2ecf20Sopenharmony_ci * is still running, check to see if it really stopped while 19758c2ecf20Sopenharmony_ci * we had interrupts off. 19768c2ecf20Sopenharmony_ci * This allows for a fast restart without re-enabling 19778c2ecf20Sopenharmony_ci * interrupts */ 19788c2ecf20Sopenharmony_ci if ((le16_to_cpu(rfd->command) & cb_el) && 19798c2ecf20Sopenharmony_ci (RU_RUNNING == nic->ru_running)) 19808c2ecf20Sopenharmony_ci 19818c2ecf20Sopenharmony_ci if (ioread8(&nic->csr->scb.status) & rus_no_res) 19828c2ecf20Sopenharmony_ci nic->ru_running = RU_SUSPENDED; 19838c2ecf20Sopenharmony_ci dma_sync_single_for_device(&nic->pdev->dev, rx->dma_addr, 19848c2ecf20Sopenharmony_ci sizeof(struct rfd), 19858c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 19868c2ecf20Sopenharmony_ci return -ENODATA; 19878c2ecf20Sopenharmony_ci } 19888c2ecf20Sopenharmony_ci 19898c2ecf20Sopenharmony_ci /* Get actual data size */ 19908c2ecf20Sopenharmony_ci if (unlikely(dev->features & NETIF_F_RXFCS)) 19918c2ecf20Sopenharmony_ci fcs_pad = 4; 19928c2ecf20Sopenharmony_ci actual_size = le16_to_cpu(rfd->actual_size) & 0x3FFF; 19938c2ecf20Sopenharmony_ci if (unlikely(actual_size > RFD_BUF_LEN - sizeof(struct rfd))) 19948c2ecf20Sopenharmony_ci actual_size = RFD_BUF_LEN - sizeof(struct rfd); 19958c2ecf20Sopenharmony_ci 19968c2ecf20Sopenharmony_ci /* Get data */ 19978c2ecf20Sopenharmony_ci dma_unmap_single(&nic->pdev->dev, rx->dma_addr, RFD_BUF_LEN, 19988c2ecf20Sopenharmony_ci DMA_BIDIRECTIONAL); 19998c2ecf20Sopenharmony_ci 20008c2ecf20Sopenharmony_ci /* If this buffer has the el bit, but we think the receiver 20018c2ecf20Sopenharmony_ci * is still running, check to see if it really stopped while 20028c2ecf20Sopenharmony_ci * we had interrupts off. 20038c2ecf20Sopenharmony_ci * This allows for a fast restart without re-enabling interrupts. 20048c2ecf20Sopenharmony_ci * This can happen when the RU sees the size change but also sees 20058c2ecf20Sopenharmony_ci * the el bit set. */ 20068c2ecf20Sopenharmony_ci if ((le16_to_cpu(rfd->command) & cb_el) && 20078c2ecf20Sopenharmony_ci (RU_RUNNING == nic->ru_running)) { 20088c2ecf20Sopenharmony_ci 20098c2ecf20Sopenharmony_ci if (ioread8(&nic->csr->scb.status) & rus_no_res) 20108c2ecf20Sopenharmony_ci nic->ru_running = RU_SUSPENDED; 20118c2ecf20Sopenharmony_ci } 20128c2ecf20Sopenharmony_ci 20138c2ecf20Sopenharmony_ci /* Pull off the RFD and put the actual data (minus eth hdr) */ 20148c2ecf20Sopenharmony_ci skb_reserve(skb, sizeof(struct rfd)); 20158c2ecf20Sopenharmony_ci skb_put(skb, actual_size); 20168c2ecf20Sopenharmony_ci skb->protocol = eth_type_trans(skb, nic->netdev); 20178c2ecf20Sopenharmony_ci 20188c2ecf20Sopenharmony_ci /* If we are receiving all frames, then don't bother 20198c2ecf20Sopenharmony_ci * checking for errors. 20208c2ecf20Sopenharmony_ci */ 20218c2ecf20Sopenharmony_ci if (unlikely(dev->features & NETIF_F_RXALL)) { 20228c2ecf20Sopenharmony_ci if (actual_size > ETH_DATA_LEN + VLAN_ETH_HLEN + fcs_pad) 20238c2ecf20Sopenharmony_ci /* Received oversized frame, but keep it. */ 20248c2ecf20Sopenharmony_ci nic->rx_over_length_errors++; 20258c2ecf20Sopenharmony_ci goto process_skb; 20268c2ecf20Sopenharmony_ci } 20278c2ecf20Sopenharmony_ci 20288c2ecf20Sopenharmony_ci if (unlikely(!(rfd_status & cb_ok))) { 20298c2ecf20Sopenharmony_ci /* Don't indicate if hardware indicates errors */ 20308c2ecf20Sopenharmony_ci dev_kfree_skb_any(skb); 20318c2ecf20Sopenharmony_ci } else if (actual_size > ETH_DATA_LEN + VLAN_ETH_HLEN + fcs_pad) { 20328c2ecf20Sopenharmony_ci /* Don't indicate oversized frames */ 20338c2ecf20Sopenharmony_ci nic->rx_over_length_errors++; 20348c2ecf20Sopenharmony_ci dev_kfree_skb_any(skb); 20358c2ecf20Sopenharmony_ci } else { 20368c2ecf20Sopenharmony_ciprocess_skb: 20378c2ecf20Sopenharmony_ci dev->stats.rx_packets++; 20388c2ecf20Sopenharmony_ci dev->stats.rx_bytes += (actual_size - fcs_pad); 20398c2ecf20Sopenharmony_ci netif_receive_skb(skb); 20408c2ecf20Sopenharmony_ci if (work_done) 20418c2ecf20Sopenharmony_ci (*work_done)++; 20428c2ecf20Sopenharmony_ci } 20438c2ecf20Sopenharmony_ci 20448c2ecf20Sopenharmony_ci rx->skb = NULL; 20458c2ecf20Sopenharmony_ci 20468c2ecf20Sopenharmony_ci return 0; 20478c2ecf20Sopenharmony_ci} 20488c2ecf20Sopenharmony_ci 20498c2ecf20Sopenharmony_cistatic void e100_rx_clean(struct nic *nic, unsigned int *work_done, 20508c2ecf20Sopenharmony_ci unsigned int work_to_do) 20518c2ecf20Sopenharmony_ci{ 20528c2ecf20Sopenharmony_ci struct rx *rx; 20538c2ecf20Sopenharmony_ci int restart_required = 0, err = 0; 20548c2ecf20Sopenharmony_ci struct rx *old_before_last_rx, *new_before_last_rx; 20558c2ecf20Sopenharmony_ci struct rfd *old_before_last_rfd, *new_before_last_rfd; 20568c2ecf20Sopenharmony_ci 20578c2ecf20Sopenharmony_ci /* Indicate newly arrived packets */ 20588c2ecf20Sopenharmony_ci for (rx = nic->rx_to_clean; rx->skb; rx = nic->rx_to_clean = rx->next) { 20598c2ecf20Sopenharmony_ci err = e100_rx_indicate(nic, rx, work_done, work_to_do); 20608c2ecf20Sopenharmony_ci /* Hit quota or no more to clean */ 20618c2ecf20Sopenharmony_ci if (-EAGAIN == err || -ENODATA == err) 20628c2ecf20Sopenharmony_ci break; 20638c2ecf20Sopenharmony_ci } 20648c2ecf20Sopenharmony_ci 20658c2ecf20Sopenharmony_ci 20668c2ecf20Sopenharmony_ci /* On EAGAIN, hit quota so have more work to do, restart once 20678c2ecf20Sopenharmony_ci * cleanup is complete. 20688c2ecf20Sopenharmony_ci * Else, are we already rnr? then pay attention!!! this ensures that 20698c2ecf20Sopenharmony_ci * the state machine progression never allows a start with a 20708c2ecf20Sopenharmony_ci * partially cleaned list, avoiding a race between hardware 20718c2ecf20Sopenharmony_ci * and rx_to_clean when in NAPI mode */ 20728c2ecf20Sopenharmony_ci if (-EAGAIN != err && RU_SUSPENDED == nic->ru_running) 20738c2ecf20Sopenharmony_ci restart_required = 1; 20748c2ecf20Sopenharmony_ci 20758c2ecf20Sopenharmony_ci old_before_last_rx = nic->rx_to_use->prev->prev; 20768c2ecf20Sopenharmony_ci old_before_last_rfd = (struct rfd *)old_before_last_rx->skb->data; 20778c2ecf20Sopenharmony_ci 20788c2ecf20Sopenharmony_ci /* Alloc new skbs to refill list */ 20798c2ecf20Sopenharmony_ci for (rx = nic->rx_to_use; !rx->skb; rx = nic->rx_to_use = rx->next) { 20808c2ecf20Sopenharmony_ci if (unlikely(e100_rx_alloc_skb(nic, rx))) 20818c2ecf20Sopenharmony_ci break; /* Better luck next time (see watchdog) */ 20828c2ecf20Sopenharmony_ci } 20838c2ecf20Sopenharmony_ci 20848c2ecf20Sopenharmony_ci new_before_last_rx = nic->rx_to_use->prev->prev; 20858c2ecf20Sopenharmony_ci if (new_before_last_rx != old_before_last_rx) { 20868c2ecf20Sopenharmony_ci /* Set the el-bit on the buffer that is before the last buffer. 20878c2ecf20Sopenharmony_ci * This lets us update the next pointer on the last buffer 20888c2ecf20Sopenharmony_ci * without worrying about hardware touching it. 20898c2ecf20Sopenharmony_ci * We set the size to 0 to prevent hardware from touching this 20908c2ecf20Sopenharmony_ci * buffer. 20918c2ecf20Sopenharmony_ci * When the hardware hits the before last buffer with el-bit 20928c2ecf20Sopenharmony_ci * and size of 0, it will RNR interrupt, the RUS will go into 20938c2ecf20Sopenharmony_ci * the No Resources state. It will not complete nor write to 20948c2ecf20Sopenharmony_ci * this buffer. */ 20958c2ecf20Sopenharmony_ci new_before_last_rfd = 20968c2ecf20Sopenharmony_ci (struct rfd *)new_before_last_rx->skb->data; 20978c2ecf20Sopenharmony_ci new_before_last_rfd->size = 0; 20988c2ecf20Sopenharmony_ci new_before_last_rfd->command |= cpu_to_le16(cb_el); 20998c2ecf20Sopenharmony_ci dma_sync_single_for_device(&nic->pdev->dev, 21008c2ecf20Sopenharmony_ci new_before_last_rx->dma_addr, 21018c2ecf20Sopenharmony_ci sizeof(struct rfd), 21028c2ecf20Sopenharmony_ci DMA_BIDIRECTIONAL); 21038c2ecf20Sopenharmony_ci 21048c2ecf20Sopenharmony_ci /* Now that we have a new stopping point, we can clear the old 21058c2ecf20Sopenharmony_ci * stopping point. We must sync twice to get the proper 21068c2ecf20Sopenharmony_ci * ordering on the hardware side of things. */ 21078c2ecf20Sopenharmony_ci old_before_last_rfd->command &= ~cpu_to_le16(cb_el); 21088c2ecf20Sopenharmony_ci dma_sync_single_for_device(&nic->pdev->dev, 21098c2ecf20Sopenharmony_ci old_before_last_rx->dma_addr, 21108c2ecf20Sopenharmony_ci sizeof(struct rfd), 21118c2ecf20Sopenharmony_ci DMA_BIDIRECTIONAL); 21128c2ecf20Sopenharmony_ci old_before_last_rfd->size = cpu_to_le16(VLAN_ETH_FRAME_LEN 21138c2ecf20Sopenharmony_ci + ETH_FCS_LEN); 21148c2ecf20Sopenharmony_ci dma_sync_single_for_device(&nic->pdev->dev, 21158c2ecf20Sopenharmony_ci old_before_last_rx->dma_addr, 21168c2ecf20Sopenharmony_ci sizeof(struct rfd), 21178c2ecf20Sopenharmony_ci DMA_BIDIRECTIONAL); 21188c2ecf20Sopenharmony_ci } 21198c2ecf20Sopenharmony_ci 21208c2ecf20Sopenharmony_ci if (restart_required) { 21218c2ecf20Sopenharmony_ci // ack the rnr? 21228c2ecf20Sopenharmony_ci iowrite8(stat_ack_rnr, &nic->csr->scb.stat_ack); 21238c2ecf20Sopenharmony_ci e100_start_receiver(nic, nic->rx_to_clean); 21248c2ecf20Sopenharmony_ci if (work_done) 21258c2ecf20Sopenharmony_ci (*work_done)++; 21268c2ecf20Sopenharmony_ci } 21278c2ecf20Sopenharmony_ci} 21288c2ecf20Sopenharmony_ci 21298c2ecf20Sopenharmony_cistatic void e100_rx_clean_list(struct nic *nic) 21308c2ecf20Sopenharmony_ci{ 21318c2ecf20Sopenharmony_ci struct rx *rx; 21328c2ecf20Sopenharmony_ci unsigned int i, count = nic->params.rfds.count; 21338c2ecf20Sopenharmony_ci 21348c2ecf20Sopenharmony_ci nic->ru_running = RU_UNINITIALIZED; 21358c2ecf20Sopenharmony_ci 21368c2ecf20Sopenharmony_ci if (nic->rxs) { 21378c2ecf20Sopenharmony_ci for (rx = nic->rxs, i = 0; i < count; rx++, i++) { 21388c2ecf20Sopenharmony_ci if (rx->skb) { 21398c2ecf20Sopenharmony_ci dma_unmap_single(&nic->pdev->dev, 21408c2ecf20Sopenharmony_ci rx->dma_addr, RFD_BUF_LEN, 21418c2ecf20Sopenharmony_ci DMA_BIDIRECTIONAL); 21428c2ecf20Sopenharmony_ci dev_kfree_skb(rx->skb); 21438c2ecf20Sopenharmony_ci } 21448c2ecf20Sopenharmony_ci } 21458c2ecf20Sopenharmony_ci kfree(nic->rxs); 21468c2ecf20Sopenharmony_ci nic->rxs = NULL; 21478c2ecf20Sopenharmony_ci } 21488c2ecf20Sopenharmony_ci 21498c2ecf20Sopenharmony_ci nic->rx_to_use = nic->rx_to_clean = NULL; 21508c2ecf20Sopenharmony_ci} 21518c2ecf20Sopenharmony_ci 21528c2ecf20Sopenharmony_cistatic int e100_rx_alloc_list(struct nic *nic) 21538c2ecf20Sopenharmony_ci{ 21548c2ecf20Sopenharmony_ci struct rx *rx; 21558c2ecf20Sopenharmony_ci unsigned int i, count = nic->params.rfds.count; 21568c2ecf20Sopenharmony_ci struct rfd *before_last; 21578c2ecf20Sopenharmony_ci 21588c2ecf20Sopenharmony_ci nic->rx_to_use = nic->rx_to_clean = NULL; 21598c2ecf20Sopenharmony_ci nic->ru_running = RU_UNINITIALIZED; 21608c2ecf20Sopenharmony_ci 21618c2ecf20Sopenharmony_ci if (!(nic->rxs = kcalloc(count, sizeof(struct rx), GFP_KERNEL))) 21628c2ecf20Sopenharmony_ci return -ENOMEM; 21638c2ecf20Sopenharmony_ci 21648c2ecf20Sopenharmony_ci for (rx = nic->rxs, i = 0; i < count; rx++, i++) { 21658c2ecf20Sopenharmony_ci rx->next = (i + 1 < count) ? rx + 1 : nic->rxs; 21668c2ecf20Sopenharmony_ci rx->prev = (i == 0) ? nic->rxs + count - 1 : rx - 1; 21678c2ecf20Sopenharmony_ci if (e100_rx_alloc_skb(nic, rx)) { 21688c2ecf20Sopenharmony_ci e100_rx_clean_list(nic); 21698c2ecf20Sopenharmony_ci return -ENOMEM; 21708c2ecf20Sopenharmony_ci } 21718c2ecf20Sopenharmony_ci } 21728c2ecf20Sopenharmony_ci /* Set the el-bit on the buffer that is before the last buffer. 21738c2ecf20Sopenharmony_ci * This lets us update the next pointer on the last buffer without 21748c2ecf20Sopenharmony_ci * worrying about hardware touching it. 21758c2ecf20Sopenharmony_ci * We set the size to 0 to prevent hardware from touching this buffer. 21768c2ecf20Sopenharmony_ci * When the hardware hits the before last buffer with el-bit and size 21778c2ecf20Sopenharmony_ci * of 0, it will RNR interrupt, the RU will go into the No Resources 21788c2ecf20Sopenharmony_ci * state. It will not complete nor write to this buffer. */ 21798c2ecf20Sopenharmony_ci rx = nic->rxs->prev->prev; 21808c2ecf20Sopenharmony_ci before_last = (struct rfd *)rx->skb->data; 21818c2ecf20Sopenharmony_ci before_last->command |= cpu_to_le16(cb_el); 21828c2ecf20Sopenharmony_ci before_last->size = 0; 21838c2ecf20Sopenharmony_ci dma_sync_single_for_device(&nic->pdev->dev, rx->dma_addr, 21848c2ecf20Sopenharmony_ci sizeof(struct rfd), DMA_BIDIRECTIONAL); 21858c2ecf20Sopenharmony_ci 21868c2ecf20Sopenharmony_ci nic->rx_to_use = nic->rx_to_clean = nic->rxs; 21878c2ecf20Sopenharmony_ci nic->ru_running = RU_SUSPENDED; 21888c2ecf20Sopenharmony_ci 21898c2ecf20Sopenharmony_ci return 0; 21908c2ecf20Sopenharmony_ci} 21918c2ecf20Sopenharmony_ci 21928c2ecf20Sopenharmony_cistatic irqreturn_t e100_intr(int irq, void *dev_id) 21938c2ecf20Sopenharmony_ci{ 21948c2ecf20Sopenharmony_ci struct net_device *netdev = dev_id; 21958c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 21968c2ecf20Sopenharmony_ci u8 stat_ack = ioread8(&nic->csr->scb.stat_ack); 21978c2ecf20Sopenharmony_ci 21988c2ecf20Sopenharmony_ci netif_printk(nic, intr, KERN_DEBUG, nic->netdev, 21998c2ecf20Sopenharmony_ci "stat_ack = 0x%02X\n", stat_ack); 22008c2ecf20Sopenharmony_ci 22018c2ecf20Sopenharmony_ci if (stat_ack == stat_ack_not_ours || /* Not our interrupt */ 22028c2ecf20Sopenharmony_ci stat_ack == stat_ack_not_present) /* Hardware is ejected */ 22038c2ecf20Sopenharmony_ci return IRQ_NONE; 22048c2ecf20Sopenharmony_ci 22058c2ecf20Sopenharmony_ci /* Ack interrupt(s) */ 22068c2ecf20Sopenharmony_ci iowrite8(stat_ack, &nic->csr->scb.stat_ack); 22078c2ecf20Sopenharmony_ci 22088c2ecf20Sopenharmony_ci /* We hit Receive No Resource (RNR); restart RU after cleaning */ 22098c2ecf20Sopenharmony_ci if (stat_ack & stat_ack_rnr) 22108c2ecf20Sopenharmony_ci nic->ru_running = RU_SUSPENDED; 22118c2ecf20Sopenharmony_ci 22128c2ecf20Sopenharmony_ci if (likely(napi_schedule_prep(&nic->napi))) { 22138c2ecf20Sopenharmony_ci e100_disable_irq(nic); 22148c2ecf20Sopenharmony_ci __napi_schedule(&nic->napi); 22158c2ecf20Sopenharmony_ci } 22168c2ecf20Sopenharmony_ci 22178c2ecf20Sopenharmony_ci return IRQ_HANDLED; 22188c2ecf20Sopenharmony_ci} 22198c2ecf20Sopenharmony_ci 22208c2ecf20Sopenharmony_cistatic int e100_poll(struct napi_struct *napi, int budget) 22218c2ecf20Sopenharmony_ci{ 22228c2ecf20Sopenharmony_ci struct nic *nic = container_of(napi, struct nic, napi); 22238c2ecf20Sopenharmony_ci unsigned int work_done = 0; 22248c2ecf20Sopenharmony_ci 22258c2ecf20Sopenharmony_ci e100_rx_clean(nic, &work_done, budget); 22268c2ecf20Sopenharmony_ci e100_tx_clean(nic); 22278c2ecf20Sopenharmony_ci 22288c2ecf20Sopenharmony_ci /* If budget fully consumed, continue polling */ 22298c2ecf20Sopenharmony_ci if (work_done == budget) 22308c2ecf20Sopenharmony_ci return budget; 22318c2ecf20Sopenharmony_ci 22328c2ecf20Sopenharmony_ci /* only re-enable interrupt if stack agrees polling is really done */ 22338c2ecf20Sopenharmony_ci if (likely(napi_complete_done(napi, work_done))) 22348c2ecf20Sopenharmony_ci e100_enable_irq(nic); 22358c2ecf20Sopenharmony_ci 22368c2ecf20Sopenharmony_ci return work_done; 22378c2ecf20Sopenharmony_ci} 22388c2ecf20Sopenharmony_ci 22398c2ecf20Sopenharmony_ci#ifdef CONFIG_NET_POLL_CONTROLLER 22408c2ecf20Sopenharmony_cistatic void e100_netpoll(struct net_device *netdev) 22418c2ecf20Sopenharmony_ci{ 22428c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 22438c2ecf20Sopenharmony_ci 22448c2ecf20Sopenharmony_ci e100_disable_irq(nic); 22458c2ecf20Sopenharmony_ci e100_intr(nic->pdev->irq, netdev); 22468c2ecf20Sopenharmony_ci e100_tx_clean(nic); 22478c2ecf20Sopenharmony_ci e100_enable_irq(nic); 22488c2ecf20Sopenharmony_ci} 22498c2ecf20Sopenharmony_ci#endif 22508c2ecf20Sopenharmony_ci 22518c2ecf20Sopenharmony_cistatic int e100_set_mac_address(struct net_device *netdev, void *p) 22528c2ecf20Sopenharmony_ci{ 22538c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 22548c2ecf20Sopenharmony_ci struct sockaddr *addr = p; 22558c2ecf20Sopenharmony_ci 22568c2ecf20Sopenharmony_ci if (!is_valid_ether_addr(addr->sa_data)) 22578c2ecf20Sopenharmony_ci return -EADDRNOTAVAIL; 22588c2ecf20Sopenharmony_ci 22598c2ecf20Sopenharmony_ci memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); 22608c2ecf20Sopenharmony_ci e100_exec_cb(nic, NULL, e100_setup_iaaddr); 22618c2ecf20Sopenharmony_ci 22628c2ecf20Sopenharmony_ci return 0; 22638c2ecf20Sopenharmony_ci} 22648c2ecf20Sopenharmony_ci 22658c2ecf20Sopenharmony_cistatic int e100_asf(struct nic *nic) 22668c2ecf20Sopenharmony_ci{ 22678c2ecf20Sopenharmony_ci /* ASF can be enabled from eeprom */ 22688c2ecf20Sopenharmony_ci return (nic->pdev->device >= 0x1050) && (nic->pdev->device <= 0x1057) && 22698c2ecf20Sopenharmony_ci (le16_to_cpu(nic->eeprom[eeprom_config_asf]) & eeprom_asf) && 22708c2ecf20Sopenharmony_ci !(le16_to_cpu(nic->eeprom[eeprom_config_asf]) & eeprom_gcl) && 22718c2ecf20Sopenharmony_ci ((le16_to_cpu(nic->eeprom[eeprom_smbus_addr]) & 0xFF) != 0xFE); 22728c2ecf20Sopenharmony_ci} 22738c2ecf20Sopenharmony_ci 22748c2ecf20Sopenharmony_cistatic int e100_up(struct nic *nic) 22758c2ecf20Sopenharmony_ci{ 22768c2ecf20Sopenharmony_ci int err; 22778c2ecf20Sopenharmony_ci 22788c2ecf20Sopenharmony_ci if ((err = e100_rx_alloc_list(nic))) 22798c2ecf20Sopenharmony_ci return err; 22808c2ecf20Sopenharmony_ci if ((err = e100_alloc_cbs(nic))) 22818c2ecf20Sopenharmony_ci goto err_rx_clean_list; 22828c2ecf20Sopenharmony_ci if ((err = e100_hw_init(nic))) 22838c2ecf20Sopenharmony_ci goto err_clean_cbs; 22848c2ecf20Sopenharmony_ci e100_set_multicast_list(nic->netdev); 22858c2ecf20Sopenharmony_ci e100_start_receiver(nic, NULL); 22868c2ecf20Sopenharmony_ci mod_timer(&nic->watchdog, jiffies); 22878c2ecf20Sopenharmony_ci if ((err = request_irq(nic->pdev->irq, e100_intr, IRQF_SHARED, 22888c2ecf20Sopenharmony_ci nic->netdev->name, nic->netdev))) 22898c2ecf20Sopenharmony_ci goto err_no_irq; 22908c2ecf20Sopenharmony_ci netif_wake_queue(nic->netdev); 22918c2ecf20Sopenharmony_ci napi_enable(&nic->napi); 22928c2ecf20Sopenharmony_ci /* enable ints _after_ enabling poll, preventing a race between 22938c2ecf20Sopenharmony_ci * disable ints+schedule */ 22948c2ecf20Sopenharmony_ci e100_enable_irq(nic); 22958c2ecf20Sopenharmony_ci return 0; 22968c2ecf20Sopenharmony_ci 22978c2ecf20Sopenharmony_cierr_no_irq: 22988c2ecf20Sopenharmony_ci del_timer_sync(&nic->watchdog); 22998c2ecf20Sopenharmony_cierr_clean_cbs: 23008c2ecf20Sopenharmony_ci e100_clean_cbs(nic); 23018c2ecf20Sopenharmony_cierr_rx_clean_list: 23028c2ecf20Sopenharmony_ci e100_rx_clean_list(nic); 23038c2ecf20Sopenharmony_ci return err; 23048c2ecf20Sopenharmony_ci} 23058c2ecf20Sopenharmony_ci 23068c2ecf20Sopenharmony_cistatic void e100_down(struct nic *nic) 23078c2ecf20Sopenharmony_ci{ 23088c2ecf20Sopenharmony_ci /* wait here for poll to complete */ 23098c2ecf20Sopenharmony_ci napi_disable(&nic->napi); 23108c2ecf20Sopenharmony_ci netif_stop_queue(nic->netdev); 23118c2ecf20Sopenharmony_ci e100_hw_reset(nic); 23128c2ecf20Sopenharmony_ci free_irq(nic->pdev->irq, nic->netdev); 23138c2ecf20Sopenharmony_ci del_timer_sync(&nic->watchdog); 23148c2ecf20Sopenharmony_ci netif_carrier_off(nic->netdev); 23158c2ecf20Sopenharmony_ci e100_clean_cbs(nic); 23168c2ecf20Sopenharmony_ci e100_rx_clean_list(nic); 23178c2ecf20Sopenharmony_ci} 23188c2ecf20Sopenharmony_ci 23198c2ecf20Sopenharmony_cistatic void e100_tx_timeout(struct net_device *netdev, unsigned int txqueue) 23208c2ecf20Sopenharmony_ci{ 23218c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 23228c2ecf20Sopenharmony_ci 23238c2ecf20Sopenharmony_ci /* Reset outside of interrupt context, to avoid request_irq 23248c2ecf20Sopenharmony_ci * in interrupt context */ 23258c2ecf20Sopenharmony_ci schedule_work(&nic->tx_timeout_task); 23268c2ecf20Sopenharmony_ci} 23278c2ecf20Sopenharmony_ci 23288c2ecf20Sopenharmony_cistatic void e100_tx_timeout_task(struct work_struct *work) 23298c2ecf20Sopenharmony_ci{ 23308c2ecf20Sopenharmony_ci struct nic *nic = container_of(work, struct nic, tx_timeout_task); 23318c2ecf20Sopenharmony_ci struct net_device *netdev = nic->netdev; 23328c2ecf20Sopenharmony_ci 23338c2ecf20Sopenharmony_ci netif_printk(nic, tx_err, KERN_DEBUG, nic->netdev, 23348c2ecf20Sopenharmony_ci "scb.status=0x%02X\n", ioread8(&nic->csr->scb.status)); 23358c2ecf20Sopenharmony_ci 23368c2ecf20Sopenharmony_ci rtnl_lock(); 23378c2ecf20Sopenharmony_ci if (netif_running(netdev)) { 23388c2ecf20Sopenharmony_ci e100_down(netdev_priv(netdev)); 23398c2ecf20Sopenharmony_ci e100_up(netdev_priv(netdev)); 23408c2ecf20Sopenharmony_ci } 23418c2ecf20Sopenharmony_ci rtnl_unlock(); 23428c2ecf20Sopenharmony_ci} 23438c2ecf20Sopenharmony_ci 23448c2ecf20Sopenharmony_cistatic int e100_loopback_test(struct nic *nic, enum loopback loopback_mode) 23458c2ecf20Sopenharmony_ci{ 23468c2ecf20Sopenharmony_ci int err; 23478c2ecf20Sopenharmony_ci struct sk_buff *skb; 23488c2ecf20Sopenharmony_ci 23498c2ecf20Sopenharmony_ci /* Use driver resources to perform internal MAC or PHY 23508c2ecf20Sopenharmony_ci * loopback test. A single packet is prepared and transmitted 23518c2ecf20Sopenharmony_ci * in loopback mode, and the test passes if the received 23528c2ecf20Sopenharmony_ci * packet compares byte-for-byte to the transmitted packet. */ 23538c2ecf20Sopenharmony_ci 23548c2ecf20Sopenharmony_ci if ((err = e100_rx_alloc_list(nic))) 23558c2ecf20Sopenharmony_ci return err; 23568c2ecf20Sopenharmony_ci if ((err = e100_alloc_cbs(nic))) 23578c2ecf20Sopenharmony_ci goto err_clean_rx; 23588c2ecf20Sopenharmony_ci 23598c2ecf20Sopenharmony_ci /* ICH PHY loopback is broken so do MAC loopback instead */ 23608c2ecf20Sopenharmony_ci if (nic->flags & ich && loopback_mode == lb_phy) 23618c2ecf20Sopenharmony_ci loopback_mode = lb_mac; 23628c2ecf20Sopenharmony_ci 23638c2ecf20Sopenharmony_ci nic->loopback = loopback_mode; 23648c2ecf20Sopenharmony_ci if ((err = e100_hw_init(nic))) 23658c2ecf20Sopenharmony_ci goto err_loopback_none; 23668c2ecf20Sopenharmony_ci 23678c2ecf20Sopenharmony_ci if (loopback_mode == lb_phy) 23688c2ecf20Sopenharmony_ci mdio_write(nic->netdev, nic->mii.phy_id, MII_BMCR, 23698c2ecf20Sopenharmony_ci BMCR_LOOPBACK); 23708c2ecf20Sopenharmony_ci 23718c2ecf20Sopenharmony_ci e100_start_receiver(nic, NULL); 23728c2ecf20Sopenharmony_ci 23738c2ecf20Sopenharmony_ci if (!(skb = netdev_alloc_skb(nic->netdev, ETH_DATA_LEN))) { 23748c2ecf20Sopenharmony_ci err = -ENOMEM; 23758c2ecf20Sopenharmony_ci goto err_loopback_none; 23768c2ecf20Sopenharmony_ci } 23778c2ecf20Sopenharmony_ci skb_put(skb, ETH_DATA_LEN); 23788c2ecf20Sopenharmony_ci memset(skb->data, 0xFF, ETH_DATA_LEN); 23798c2ecf20Sopenharmony_ci e100_xmit_frame(skb, nic->netdev); 23808c2ecf20Sopenharmony_ci 23818c2ecf20Sopenharmony_ci msleep(10); 23828c2ecf20Sopenharmony_ci 23838c2ecf20Sopenharmony_ci dma_sync_single_for_cpu(&nic->pdev->dev, nic->rx_to_clean->dma_addr, 23848c2ecf20Sopenharmony_ci RFD_BUF_LEN, DMA_BIDIRECTIONAL); 23858c2ecf20Sopenharmony_ci 23868c2ecf20Sopenharmony_ci if (memcmp(nic->rx_to_clean->skb->data + sizeof(struct rfd), 23878c2ecf20Sopenharmony_ci skb->data, ETH_DATA_LEN)) 23888c2ecf20Sopenharmony_ci err = -EAGAIN; 23898c2ecf20Sopenharmony_ci 23908c2ecf20Sopenharmony_cierr_loopback_none: 23918c2ecf20Sopenharmony_ci mdio_write(nic->netdev, nic->mii.phy_id, MII_BMCR, 0); 23928c2ecf20Sopenharmony_ci nic->loopback = lb_none; 23938c2ecf20Sopenharmony_ci e100_clean_cbs(nic); 23948c2ecf20Sopenharmony_ci e100_hw_reset(nic); 23958c2ecf20Sopenharmony_cierr_clean_rx: 23968c2ecf20Sopenharmony_ci e100_rx_clean_list(nic); 23978c2ecf20Sopenharmony_ci return err; 23988c2ecf20Sopenharmony_ci} 23998c2ecf20Sopenharmony_ci 24008c2ecf20Sopenharmony_ci#define MII_LED_CONTROL 0x1B 24018c2ecf20Sopenharmony_ci#define E100_82552_LED_OVERRIDE 0x19 24028c2ecf20Sopenharmony_ci#define E100_82552_LED_ON 0x000F /* LEDTX and LED_RX both on */ 24038c2ecf20Sopenharmony_ci#define E100_82552_LED_OFF 0x000A /* LEDTX and LED_RX both off */ 24048c2ecf20Sopenharmony_ci 24058c2ecf20Sopenharmony_cistatic int e100_get_link_ksettings(struct net_device *netdev, 24068c2ecf20Sopenharmony_ci struct ethtool_link_ksettings *cmd) 24078c2ecf20Sopenharmony_ci{ 24088c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 24098c2ecf20Sopenharmony_ci 24108c2ecf20Sopenharmony_ci mii_ethtool_get_link_ksettings(&nic->mii, cmd); 24118c2ecf20Sopenharmony_ci 24128c2ecf20Sopenharmony_ci return 0; 24138c2ecf20Sopenharmony_ci} 24148c2ecf20Sopenharmony_ci 24158c2ecf20Sopenharmony_cistatic int e100_set_link_ksettings(struct net_device *netdev, 24168c2ecf20Sopenharmony_ci const struct ethtool_link_ksettings *cmd) 24178c2ecf20Sopenharmony_ci{ 24188c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 24198c2ecf20Sopenharmony_ci int err; 24208c2ecf20Sopenharmony_ci 24218c2ecf20Sopenharmony_ci mdio_write(netdev, nic->mii.phy_id, MII_BMCR, BMCR_RESET); 24228c2ecf20Sopenharmony_ci err = mii_ethtool_set_link_ksettings(&nic->mii, cmd); 24238c2ecf20Sopenharmony_ci e100_exec_cb(nic, NULL, e100_configure); 24248c2ecf20Sopenharmony_ci 24258c2ecf20Sopenharmony_ci return err; 24268c2ecf20Sopenharmony_ci} 24278c2ecf20Sopenharmony_ci 24288c2ecf20Sopenharmony_cistatic void e100_get_drvinfo(struct net_device *netdev, 24298c2ecf20Sopenharmony_ci struct ethtool_drvinfo *info) 24308c2ecf20Sopenharmony_ci{ 24318c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 24328c2ecf20Sopenharmony_ci strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); 24338c2ecf20Sopenharmony_ci strlcpy(info->bus_info, pci_name(nic->pdev), 24348c2ecf20Sopenharmony_ci sizeof(info->bus_info)); 24358c2ecf20Sopenharmony_ci} 24368c2ecf20Sopenharmony_ci 24378c2ecf20Sopenharmony_ci#define E100_PHY_REGS 0x1D 24388c2ecf20Sopenharmony_cistatic int e100_get_regs_len(struct net_device *netdev) 24398c2ecf20Sopenharmony_ci{ 24408c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 24418c2ecf20Sopenharmony_ci 24428c2ecf20Sopenharmony_ci /* We know the number of registers, and the size of the dump buffer. 24438c2ecf20Sopenharmony_ci * Calculate the total size in bytes. 24448c2ecf20Sopenharmony_ci */ 24458c2ecf20Sopenharmony_ci return (1 + E100_PHY_REGS) * sizeof(u32) + sizeof(nic->mem->dump_buf); 24468c2ecf20Sopenharmony_ci} 24478c2ecf20Sopenharmony_ci 24488c2ecf20Sopenharmony_cistatic void e100_get_regs(struct net_device *netdev, 24498c2ecf20Sopenharmony_ci struct ethtool_regs *regs, void *p) 24508c2ecf20Sopenharmony_ci{ 24518c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 24528c2ecf20Sopenharmony_ci u32 *buff = p; 24538c2ecf20Sopenharmony_ci int i; 24548c2ecf20Sopenharmony_ci 24558c2ecf20Sopenharmony_ci regs->version = (1 << 24) | nic->pdev->revision; 24568c2ecf20Sopenharmony_ci buff[0] = ioread8(&nic->csr->scb.cmd_hi) << 24 | 24578c2ecf20Sopenharmony_ci ioread8(&nic->csr->scb.cmd_lo) << 16 | 24588c2ecf20Sopenharmony_ci ioread16(&nic->csr->scb.status); 24598c2ecf20Sopenharmony_ci for (i = 0; i < E100_PHY_REGS; i++) 24608c2ecf20Sopenharmony_ci /* Note that we read the registers in reverse order. This 24618c2ecf20Sopenharmony_ci * ordering is the ABI apparently used by ethtool and other 24628c2ecf20Sopenharmony_ci * applications. 24638c2ecf20Sopenharmony_ci */ 24648c2ecf20Sopenharmony_ci buff[1 + i] = mdio_read(netdev, nic->mii.phy_id, 24658c2ecf20Sopenharmony_ci E100_PHY_REGS - 1 - i); 24668c2ecf20Sopenharmony_ci memset(nic->mem->dump_buf, 0, sizeof(nic->mem->dump_buf)); 24678c2ecf20Sopenharmony_ci e100_exec_cb(nic, NULL, e100_dump); 24688c2ecf20Sopenharmony_ci msleep(10); 24698c2ecf20Sopenharmony_ci memcpy(&buff[1 + E100_PHY_REGS], nic->mem->dump_buf, 24708c2ecf20Sopenharmony_ci sizeof(nic->mem->dump_buf)); 24718c2ecf20Sopenharmony_ci} 24728c2ecf20Sopenharmony_ci 24738c2ecf20Sopenharmony_cistatic void e100_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 24748c2ecf20Sopenharmony_ci{ 24758c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 24768c2ecf20Sopenharmony_ci wol->supported = (nic->mac >= mac_82558_D101_A4) ? WAKE_MAGIC : 0; 24778c2ecf20Sopenharmony_ci wol->wolopts = (nic->flags & wol_magic) ? WAKE_MAGIC : 0; 24788c2ecf20Sopenharmony_ci} 24798c2ecf20Sopenharmony_ci 24808c2ecf20Sopenharmony_cistatic int e100_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 24818c2ecf20Sopenharmony_ci{ 24828c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 24838c2ecf20Sopenharmony_ci 24848c2ecf20Sopenharmony_ci if ((wol->wolopts && wol->wolopts != WAKE_MAGIC) || 24858c2ecf20Sopenharmony_ci !device_can_wakeup(&nic->pdev->dev)) 24868c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 24878c2ecf20Sopenharmony_ci 24888c2ecf20Sopenharmony_ci if (wol->wolopts) 24898c2ecf20Sopenharmony_ci nic->flags |= wol_magic; 24908c2ecf20Sopenharmony_ci else 24918c2ecf20Sopenharmony_ci nic->flags &= ~wol_magic; 24928c2ecf20Sopenharmony_ci 24938c2ecf20Sopenharmony_ci device_set_wakeup_enable(&nic->pdev->dev, wol->wolopts); 24948c2ecf20Sopenharmony_ci 24958c2ecf20Sopenharmony_ci e100_exec_cb(nic, NULL, e100_configure); 24968c2ecf20Sopenharmony_ci 24978c2ecf20Sopenharmony_ci return 0; 24988c2ecf20Sopenharmony_ci} 24998c2ecf20Sopenharmony_ci 25008c2ecf20Sopenharmony_cistatic u32 e100_get_msglevel(struct net_device *netdev) 25018c2ecf20Sopenharmony_ci{ 25028c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 25038c2ecf20Sopenharmony_ci return nic->msg_enable; 25048c2ecf20Sopenharmony_ci} 25058c2ecf20Sopenharmony_ci 25068c2ecf20Sopenharmony_cistatic void e100_set_msglevel(struct net_device *netdev, u32 value) 25078c2ecf20Sopenharmony_ci{ 25088c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 25098c2ecf20Sopenharmony_ci nic->msg_enable = value; 25108c2ecf20Sopenharmony_ci} 25118c2ecf20Sopenharmony_ci 25128c2ecf20Sopenharmony_cistatic int e100_nway_reset(struct net_device *netdev) 25138c2ecf20Sopenharmony_ci{ 25148c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 25158c2ecf20Sopenharmony_ci return mii_nway_restart(&nic->mii); 25168c2ecf20Sopenharmony_ci} 25178c2ecf20Sopenharmony_ci 25188c2ecf20Sopenharmony_cistatic u32 e100_get_link(struct net_device *netdev) 25198c2ecf20Sopenharmony_ci{ 25208c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 25218c2ecf20Sopenharmony_ci return mii_link_ok(&nic->mii); 25228c2ecf20Sopenharmony_ci} 25238c2ecf20Sopenharmony_ci 25248c2ecf20Sopenharmony_cistatic int e100_get_eeprom_len(struct net_device *netdev) 25258c2ecf20Sopenharmony_ci{ 25268c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 25278c2ecf20Sopenharmony_ci return nic->eeprom_wc << 1; 25288c2ecf20Sopenharmony_ci} 25298c2ecf20Sopenharmony_ci 25308c2ecf20Sopenharmony_ci#define E100_EEPROM_MAGIC 0x1234 25318c2ecf20Sopenharmony_cistatic int e100_get_eeprom(struct net_device *netdev, 25328c2ecf20Sopenharmony_ci struct ethtool_eeprom *eeprom, u8 *bytes) 25338c2ecf20Sopenharmony_ci{ 25348c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 25358c2ecf20Sopenharmony_ci 25368c2ecf20Sopenharmony_ci eeprom->magic = E100_EEPROM_MAGIC; 25378c2ecf20Sopenharmony_ci memcpy(bytes, &((u8 *)nic->eeprom)[eeprom->offset], eeprom->len); 25388c2ecf20Sopenharmony_ci 25398c2ecf20Sopenharmony_ci return 0; 25408c2ecf20Sopenharmony_ci} 25418c2ecf20Sopenharmony_ci 25428c2ecf20Sopenharmony_cistatic int e100_set_eeprom(struct net_device *netdev, 25438c2ecf20Sopenharmony_ci struct ethtool_eeprom *eeprom, u8 *bytes) 25448c2ecf20Sopenharmony_ci{ 25458c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 25468c2ecf20Sopenharmony_ci 25478c2ecf20Sopenharmony_ci if (eeprom->magic != E100_EEPROM_MAGIC) 25488c2ecf20Sopenharmony_ci return -EINVAL; 25498c2ecf20Sopenharmony_ci 25508c2ecf20Sopenharmony_ci memcpy(&((u8 *)nic->eeprom)[eeprom->offset], bytes, eeprom->len); 25518c2ecf20Sopenharmony_ci 25528c2ecf20Sopenharmony_ci return e100_eeprom_save(nic, eeprom->offset >> 1, 25538c2ecf20Sopenharmony_ci (eeprom->len >> 1) + 1); 25548c2ecf20Sopenharmony_ci} 25558c2ecf20Sopenharmony_ci 25568c2ecf20Sopenharmony_cistatic void e100_get_ringparam(struct net_device *netdev, 25578c2ecf20Sopenharmony_ci struct ethtool_ringparam *ring) 25588c2ecf20Sopenharmony_ci{ 25598c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 25608c2ecf20Sopenharmony_ci struct param_range *rfds = &nic->params.rfds; 25618c2ecf20Sopenharmony_ci struct param_range *cbs = &nic->params.cbs; 25628c2ecf20Sopenharmony_ci 25638c2ecf20Sopenharmony_ci ring->rx_max_pending = rfds->max; 25648c2ecf20Sopenharmony_ci ring->tx_max_pending = cbs->max; 25658c2ecf20Sopenharmony_ci ring->rx_pending = rfds->count; 25668c2ecf20Sopenharmony_ci ring->tx_pending = cbs->count; 25678c2ecf20Sopenharmony_ci} 25688c2ecf20Sopenharmony_ci 25698c2ecf20Sopenharmony_cistatic int e100_set_ringparam(struct net_device *netdev, 25708c2ecf20Sopenharmony_ci struct ethtool_ringparam *ring) 25718c2ecf20Sopenharmony_ci{ 25728c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 25738c2ecf20Sopenharmony_ci struct param_range *rfds = &nic->params.rfds; 25748c2ecf20Sopenharmony_ci struct param_range *cbs = &nic->params.cbs; 25758c2ecf20Sopenharmony_ci 25768c2ecf20Sopenharmony_ci if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) 25778c2ecf20Sopenharmony_ci return -EINVAL; 25788c2ecf20Sopenharmony_ci 25798c2ecf20Sopenharmony_ci if (netif_running(netdev)) 25808c2ecf20Sopenharmony_ci e100_down(nic); 25818c2ecf20Sopenharmony_ci rfds->count = max(ring->rx_pending, rfds->min); 25828c2ecf20Sopenharmony_ci rfds->count = min(rfds->count, rfds->max); 25838c2ecf20Sopenharmony_ci cbs->count = max(ring->tx_pending, cbs->min); 25848c2ecf20Sopenharmony_ci cbs->count = min(cbs->count, cbs->max); 25858c2ecf20Sopenharmony_ci netif_info(nic, drv, nic->netdev, "Ring Param settings: rx: %d, tx %d\n", 25868c2ecf20Sopenharmony_ci rfds->count, cbs->count); 25878c2ecf20Sopenharmony_ci if (netif_running(netdev)) 25888c2ecf20Sopenharmony_ci e100_up(nic); 25898c2ecf20Sopenharmony_ci 25908c2ecf20Sopenharmony_ci return 0; 25918c2ecf20Sopenharmony_ci} 25928c2ecf20Sopenharmony_ci 25938c2ecf20Sopenharmony_cistatic const char e100_gstrings_test[][ETH_GSTRING_LEN] = { 25948c2ecf20Sopenharmony_ci "Link test (on/offline)", 25958c2ecf20Sopenharmony_ci "Eeprom test (on/offline)", 25968c2ecf20Sopenharmony_ci "Self test (offline)", 25978c2ecf20Sopenharmony_ci "Mac loopback (offline)", 25988c2ecf20Sopenharmony_ci "Phy loopback (offline)", 25998c2ecf20Sopenharmony_ci}; 26008c2ecf20Sopenharmony_ci#define E100_TEST_LEN ARRAY_SIZE(e100_gstrings_test) 26018c2ecf20Sopenharmony_ci 26028c2ecf20Sopenharmony_cistatic void e100_diag_test(struct net_device *netdev, 26038c2ecf20Sopenharmony_ci struct ethtool_test *test, u64 *data) 26048c2ecf20Sopenharmony_ci{ 26058c2ecf20Sopenharmony_ci struct ethtool_cmd cmd; 26068c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 26078c2ecf20Sopenharmony_ci int i; 26088c2ecf20Sopenharmony_ci 26098c2ecf20Sopenharmony_ci memset(data, 0, E100_TEST_LEN * sizeof(u64)); 26108c2ecf20Sopenharmony_ci data[0] = !mii_link_ok(&nic->mii); 26118c2ecf20Sopenharmony_ci data[1] = e100_eeprom_load(nic); 26128c2ecf20Sopenharmony_ci if (test->flags & ETH_TEST_FL_OFFLINE) { 26138c2ecf20Sopenharmony_ci 26148c2ecf20Sopenharmony_ci /* save speed, duplex & autoneg settings */ 26158c2ecf20Sopenharmony_ci mii_ethtool_gset(&nic->mii, &cmd); 26168c2ecf20Sopenharmony_ci 26178c2ecf20Sopenharmony_ci if (netif_running(netdev)) 26188c2ecf20Sopenharmony_ci e100_down(nic); 26198c2ecf20Sopenharmony_ci data[2] = e100_self_test(nic); 26208c2ecf20Sopenharmony_ci data[3] = e100_loopback_test(nic, lb_mac); 26218c2ecf20Sopenharmony_ci data[4] = e100_loopback_test(nic, lb_phy); 26228c2ecf20Sopenharmony_ci 26238c2ecf20Sopenharmony_ci /* restore speed, duplex & autoneg settings */ 26248c2ecf20Sopenharmony_ci mii_ethtool_sset(&nic->mii, &cmd); 26258c2ecf20Sopenharmony_ci 26268c2ecf20Sopenharmony_ci if (netif_running(netdev)) 26278c2ecf20Sopenharmony_ci e100_up(nic); 26288c2ecf20Sopenharmony_ci } 26298c2ecf20Sopenharmony_ci for (i = 0; i < E100_TEST_LEN; i++) 26308c2ecf20Sopenharmony_ci test->flags |= data[i] ? ETH_TEST_FL_FAILED : 0; 26318c2ecf20Sopenharmony_ci 26328c2ecf20Sopenharmony_ci msleep_interruptible(4 * 1000); 26338c2ecf20Sopenharmony_ci} 26348c2ecf20Sopenharmony_ci 26358c2ecf20Sopenharmony_cistatic int e100_set_phys_id(struct net_device *netdev, 26368c2ecf20Sopenharmony_ci enum ethtool_phys_id_state state) 26378c2ecf20Sopenharmony_ci{ 26388c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 26398c2ecf20Sopenharmony_ci enum led_state { 26408c2ecf20Sopenharmony_ci led_on = 0x01, 26418c2ecf20Sopenharmony_ci led_off = 0x04, 26428c2ecf20Sopenharmony_ci led_on_559 = 0x05, 26438c2ecf20Sopenharmony_ci led_on_557 = 0x07, 26448c2ecf20Sopenharmony_ci }; 26458c2ecf20Sopenharmony_ci u16 led_reg = (nic->phy == phy_82552_v) ? E100_82552_LED_OVERRIDE : 26468c2ecf20Sopenharmony_ci MII_LED_CONTROL; 26478c2ecf20Sopenharmony_ci u16 leds = 0; 26488c2ecf20Sopenharmony_ci 26498c2ecf20Sopenharmony_ci switch (state) { 26508c2ecf20Sopenharmony_ci case ETHTOOL_ID_ACTIVE: 26518c2ecf20Sopenharmony_ci return 2; 26528c2ecf20Sopenharmony_ci 26538c2ecf20Sopenharmony_ci case ETHTOOL_ID_ON: 26548c2ecf20Sopenharmony_ci leds = (nic->phy == phy_82552_v) ? E100_82552_LED_ON : 26558c2ecf20Sopenharmony_ci (nic->mac < mac_82559_D101M) ? led_on_557 : led_on_559; 26568c2ecf20Sopenharmony_ci break; 26578c2ecf20Sopenharmony_ci 26588c2ecf20Sopenharmony_ci case ETHTOOL_ID_OFF: 26598c2ecf20Sopenharmony_ci leds = (nic->phy == phy_82552_v) ? E100_82552_LED_OFF : led_off; 26608c2ecf20Sopenharmony_ci break; 26618c2ecf20Sopenharmony_ci 26628c2ecf20Sopenharmony_ci case ETHTOOL_ID_INACTIVE: 26638c2ecf20Sopenharmony_ci break; 26648c2ecf20Sopenharmony_ci } 26658c2ecf20Sopenharmony_ci 26668c2ecf20Sopenharmony_ci mdio_write(netdev, nic->mii.phy_id, led_reg, leds); 26678c2ecf20Sopenharmony_ci return 0; 26688c2ecf20Sopenharmony_ci} 26698c2ecf20Sopenharmony_ci 26708c2ecf20Sopenharmony_cistatic const char e100_gstrings_stats[][ETH_GSTRING_LEN] = { 26718c2ecf20Sopenharmony_ci "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors", 26728c2ecf20Sopenharmony_ci "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions", 26738c2ecf20Sopenharmony_ci "rx_length_errors", "rx_over_errors", "rx_crc_errors", 26748c2ecf20Sopenharmony_ci "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors", 26758c2ecf20Sopenharmony_ci "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors", 26768c2ecf20Sopenharmony_ci "tx_heartbeat_errors", "tx_window_errors", 26778c2ecf20Sopenharmony_ci /* device-specific stats */ 26788c2ecf20Sopenharmony_ci "tx_deferred", "tx_single_collisions", "tx_multi_collisions", 26798c2ecf20Sopenharmony_ci "tx_flow_control_pause", "rx_flow_control_pause", 26808c2ecf20Sopenharmony_ci "rx_flow_control_unsupported", "tx_tco_packets", "rx_tco_packets", 26818c2ecf20Sopenharmony_ci "rx_short_frame_errors", "rx_over_length_errors", 26828c2ecf20Sopenharmony_ci}; 26838c2ecf20Sopenharmony_ci#define E100_NET_STATS_LEN 21 26848c2ecf20Sopenharmony_ci#define E100_STATS_LEN ARRAY_SIZE(e100_gstrings_stats) 26858c2ecf20Sopenharmony_ci 26868c2ecf20Sopenharmony_cistatic int e100_get_sset_count(struct net_device *netdev, int sset) 26878c2ecf20Sopenharmony_ci{ 26888c2ecf20Sopenharmony_ci switch (sset) { 26898c2ecf20Sopenharmony_ci case ETH_SS_TEST: 26908c2ecf20Sopenharmony_ci return E100_TEST_LEN; 26918c2ecf20Sopenharmony_ci case ETH_SS_STATS: 26928c2ecf20Sopenharmony_ci return E100_STATS_LEN; 26938c2ecf20Sopenharmony_ci default: 26948c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 26958c2ecf20Sopenharmony_ci } 26968c2ecf20Sopenharmony_ci} 26978c2ecf20Sopenharmony_ci 26988c2ecf20Sopenharmony_cistatic void e100_get_ethtool_stats(struct net_device *netdev, 26998c2ecf20Sopenharmony_ci struct ethtool_stats *stats, u64 *data) 27008c2ecf20Sopenharmony_ci{ 27018c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 27028c2ecf20Sopenharmony_ci int i; 27038c2ecf20Sopenharmony_ci 27048c2ecf20Sopenharmony_ci for (i = 0; i < E100_NET_STATS_LEN; i++) 27058c2ecf20Sopenharmony_ci data[i] = ((unsigned long *)&netdev->stats)[i]; 27068c2ecf20Sopenharmony_ci 27078c2ecf20Sopenharmony_ci data[i++] = nic->tx_deferred; 27088c2ecf20Sopenharmony_ci data[i++] = nic->tx_single_collisions; 27098c2ecf20Sopenharmony_ci data[i++] = nic->tx_multiple_collisions; 27108c2ecf20Sopenharmony_ci data[i++] = nic->tx_fc_pause; 27118c2ecf20Sopenharmony_ci data[i++] = nic->rx_fc_pause; 27128c2ecf20Sopenharmony_ci data[i++] = nic->rx_fc_unsupported; 27138c2ecf20Sopenharmony_ci data[i++] = nic->tx_tco_frames; 27148c2ecf20Sopenharmony_ci data[i++] = nic->rx_tco_frames; 27158c2ecf20Sopenharmony_ci data[i++] = nic->rx_short_frame_errors; 27168c2ecf20Sopenharmony_ci data[i++] = nic->rx_over_length_errors; 27178c2ecf20Sopenharmony_ci} 27188c2ecf20Sopenharmony_ci 27198c2ecf20Sopenharmony_cistatic void e100_get_strings(struct net_device *netdev, u32 stringset, u8 *data) 27208c2ecf20Sopenharmony_ci{ 27218c2ecf20Sopenharmony_ci switch (stringset) { 27228c2ecf20Sopenharmony_ci case ETH_SS_TEST: 27238c2ecf20Sopenharmony_ci memcpy(data, *e100_gstrings_test, sizeof(e100_gstrings_test)); 27248c2ecf20Sopenharmony_ci break; 27258c2ecf20Sopenharmony_ci case ETH_SS_STATS: 27268c2ecf20Sopenharmony_ci memcpy(data, *e100_gstrings_stats, sizeof(e100_gstrings_stats)); 27278c2ecf20Sopenharmony_ci break; 27288c2ecf20Sopenharmony_ci } 27298c2ecf20Sopenharmony_ci} 27308c2ecf20Sopenharmony_ci 27318c2ecf20Sopenharmony_cistatic const struct ethtool_ops e100_ethtool_ops = { 27328c2ecf20Sopenharmony_ci .get_drvinfo = e100_get_drvinfo, 27338c2ecf20Sopenharmony_ci .get_regs_len = e100_get_regs_len, 27348c2ecf20Sopenharmony_ci .get_regs = e100_get_regs, 27358c2ecf20Sopenharmony_ci .get_wol = e100_get_wol, 27368c2ecf20Sopenharmony_ci .set_wol = e100_set_wol, 27378c2ecf20Sopenharmony_ci .get_msglevel = e100_get_msglevel, 27388c2ecf20Sopenharmony_ci .set_msglevel = e100_set_msglevel, 27398c2ecf20Sopenharmony_ci .nway_reset = e100_nway_reset, 27408c2ecf20Sopenharmony_ci .get_link = e100_get_link, 27418c2ecf20Sopenharmony_ci .get_eeprom_len = e100_get_eeprom_len, 27428c2ecf20Sopenharmony_ci .get_eeprom = e100_get_eeprom, 27438c2ecf20Sopenharmony_ci .set_eeprom = e100_set_eeprom, 27448c2ecf20Sopenharmony_ci .get_ringparam = e100_get_ringparam, 27458c2ecf20Sopenharmony_ci .set_ringparam = e100_set_ringparam, 27468c2ecf20Sopenharmony_ci .self_test = e100_diag_test, 27478c2ecf20Sopenharmony_ci .get_strings = e100_get_strings, 27488c2ecf20Sopenharmony_ci .set_phys_id = e100_set_phys_id, 27498c2ecf20Sopenharmony_ci .get_ethtool_stats = e100_get_ethtool_stats, 27508c2ecf20Sopenharmony_ci .get_sset_count = e100_get_sset_count, 27518c2ecf20Sopenharmony_ci .get_ts_info = ethtool_op_get_ts_info, 27528c2ecf20Sopenharmony_ci .get_link_ksettings = e100_get_link_ksettings, 27538c2ecf20Sopenharmony_ci .set_link_ksettings = e100_set_link_ksettings, 27548c2ecf20Sopenharmony_ci}; 27558c2ecf20Sopenharmony_ci 27568c2ecf20Sopenharmony_cistatic int e100_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) 27578c2ecf20Sopenharmony_ci{ 27588c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 27598c2ecf20Sopenharmony_ci 27608c2ecf20Sopenharmony_ci return generic_mii_ioctl(&nic->mii, if_mii(ifr), cmd, NULL); 27618c2ecf20Sopenharmony_ci} 27628c2ecf20Sopenharmony_ci 27638c2ecf20Sopenharmony_cistatic int e100_alloc(struct nic *nic) 27648c2ecf20Sopenharmony_ci{ 27658c2ecf20Sopenharmony_ci nic->mem = dma_alloc_coherent(&nic->pdev->dev, sizeof(struct mem), 27668c2ecf20Sopenharmony_ci &nic->dma_addr, GFP_KERNEL); 27678c2ecf20Sopenharmony_ci return nic->mem ? 0 : -ENOMEM; 27688c2ecf20Sopenharmony_ci} 27698c2ecf20Sopenharmony_ci 27708c2ecf20Sopenharmony_cistatic void e100_free(struct nic *nic) 27718c2ecf20Sopenharmony_ci{ 27728c2ecf20Sopenharmony_ci if (nic->mem) { 27738c2ecf20Sopenharmony_ci dma_free_coherent(&nic->pdev->dev, sizeof(struct mem), 27748c2ecf20Sopenharmony_ci nic->mem, nic->dma_addr); 27758c2ecf20Sopenharmony_ci nic->mem = NULL; 27768c2ecf20Sopenharmony_ci } 27778c2ecf20Sopenharmony_ci} 27788c2ecf20Sopenharmony_ci 27798c2ecf20Sopenharmony_cistatic int e100_open(struct net_device *netdev) 27808c2ecf20Sopenharmony_ci{ 27818c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 27828c2ecf20Sopenharmony_ci int err = 0; 27838c2ecf20Sopenharmony_ci 27848c2ecf20Sopenharmony_ci netif_carrier_off(netdev); 27858c2ecf20Sopenharmony_ci if ((err = e100_up(nic))) 27868c2ecf20Sopenharmony_ci netif_err(nic, ifup, nic->netdev, "Cannot open interface, aborting\n"); 27878c2ecf20Sopenharmony_ci return err; 27888c2ecf20Sopenharmony_ci} 27898c2ecf20Sopenharmony_ci 27908c2ecf20Sopenharmony_cistatic int e100_close(struct net_device *netdev) 27918c2ecf20Sopenharmony_ci{ 27928c2ecf20Sopenharmony_ci e100_down(netdev_priv(netdev)); 27938c2ecf20Sopenharmony_ci return 0; 27948c2ecf20Sopenharmony_ci} 27958c2ecf20Sopenharmony_ci 27968c2ecf20Sopenharmony_cistatic int e100_set_features(struct net_device *netdev, 27978c2ecf20Sopenharmony_ci netdev_features_t features) 27988c2ecf20Sopenharmony_ci{ 27998c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 28008c2ecf20Sopenharmony_ci netdev_features_t changed = features ^ netdev->features; 28018c2ecf20Sopenharmony_ci 28028c2ecf20Sopenharmony_ci if (!(changed & (NETIF_F_RXFCS | NETIF_F_RXALL))) 28038c2ecf20Sopenharmony_ci return 0; 28048c2ecf20Sopenharmony_ci 28058c2ecf20Sopenharmony_ci netdev->features = features; 28068c2ecf20Sopenharmony_ci e100_exec_cb(nic, NULL, e100_configure); 28078c2ecf20Sopenharmony_ci return 1; 28088c2ecf20Sopenharmony_ci} 28098c2ecf20Sopenharmony_ci 28108c2ecf20Sopenharmony_cistatic const struct net_device_ops e100_netdev_ops = { 28118c2ecf20Sopenharmony_ci .ndo_open = e100_open, 28128c2ecf20Sopenharmony_ci .ndo_stop = e100_close, 28138c2ecf20Sopenharmony_ci .ndo_start_xmit = e100_xmit_frame, 28148c2ecf20Sopenharmony_ci .ndo_validate_addr = eth_validate_addr, 28158c2ecf20Sopenharmony_ci .ndo_set_rx_mode = e100_set_multicast_list, 28168c2ecf20Sopenharmony_ci .ndo_set_mac_address = e100_set_mac_address, 28178c2ecf20Sopenharmony_ci .ndo_do_ioctl = e100_do_ioctl, 28188c2ecf20Sopenharmony_ci .ndo_tx_timeout = e100_tx_timeout, 28198c2ecf20Sopenharmony_ci#ifdef CONFIG_NET_POLL_CONTROLLER 28208c2ecf20Sopenharmony_ci .ndo_poll_controller = e100_netpoll, 28218c2ecf20Sopenharmony_ci#endif 28228c2ecf20Sopenharmony_ci .ndo_set_features = e100_set_features, 28238c2ecf20Sopenharmony_ci}; 28248c2ecf20Sopenharmony_ci 28258c2ecf20Sopenharmony_cistatic int e100_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 28268c2ecf20Sopenharmony_ci{ 28278c2ecf20Sopenharmony_ci struct net_device *netdev; 28288c2ecf20Sopenharmony_ci struct nic *nic; 28298c2ecf20Sopenharmony_ci int err; 28308c2ecf20Sopenharmony_ci 28318c2ecf20Sopenharmony_ci if (!(netdev = alloc_etherdev(sizeof(struct nic)))) 28328c2ecf20Sopenharmony_ci return -ENOMEM; 28338c2ecf20Sopenharmony_ci 28348c2ecf20Sopenharmony_ci netdev->hw_features |= NETIF_F_RXFCS; 28358c2ecf20Sopenharmony_ci netdev->priv_flags |= IFF_SUPP_NOFCS; 28368c2ecf20Sopenharmony_ci netdev->hw_features |= NETIF_F_RXALL; 28378c2ecf20Sopenharmony_ci 28388c2ecf20Sopenharmony_ci netdev->netdev_ops = &e100_netdev_ops; 28398c2ecf20Sopenharmony_ci netdev->ethtool_ops = &e100_ethtool_ops; 28408c2ecf20Sopenharmony_ci netdev->watchdog_timeo = E100_WATCHDOG_PERIOD; 28418c2ecf20Sopenharmony_ci strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); 28428c2ecf20Sopenharmony_ci 28438c2ecf20Sopenharmony_ci nic = netdev_priv(netdev); 28448c2ecf20Sopenharmony_ci netif_napi_add(netdev, &nic->napi, e100_poll, E100_NAPI_WEIGHT); 28458c2ecf20Sopenharmony_ci nic->netdev = netdev; 28468c2ecf20Sopenharmony_ci nic->pdev = pdev; 28478c2ecf20Sopenharmony_ci nic->msg_enable = (1 << debug) - 1; 28488c2ecf20Sopenharmony_ci nic->mdio_ctrl = mdio_ctrl_hw; 28498c2ecf20Sopenharmony_ci pci_set_drvdata(pdev, netdev); 28508c2ecf20Sopenharmony_ci 28518c2ecf20Sopenharmony_ci if ((err = pci_enable_device(pdev))) { 28528c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "Cannot enable PCI device, aborting\n"); 28538c2ecf20Sopenharmony_ci goto err_out_free_dev; 28548c2ecf20Sopenharmony_ci } 28558c2ecf20Sopenharmony_ci 28568c2ecf20Sopenharmony_ci if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { 28578c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "Cannot find proper PCI device base address, aborting\n"); 28588c2ecf20Sopenharmony_ci err = -ENODEV; 28598c2ecf20Sopenharmony_ci goto err_out_disable_pdev; 28608c2ecf20Sopenharmony_ci } 28618c2ecf20Sopenharmony_ci 28628c2ecf20Sopenharmony_ci if ((err = pci_request_regions(pdev, DRV_NAME))) { 28638c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "Cannot obtain PCI resources, aborting\n"); 28648c2ecf20Sopenharmony_ci goto err_out_disable_pdev; 28658c2ecf20Sopenharmony_ci } 28668c2ecf20Sopenharmony_ci 28678c2ecf20Sopenharmony_ci if ((err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)))) { 28688c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "No usable DMA configuration, aborting\n"); 28698c2ecf20Sopenharmony_ci goto err_out_free_res; 28708c2ecf20Sopenharmony_ci } 28718c2ecf20Sopenharmony_ci 28728c2ecf20Sopenharmony_ci SET_NETDEV_DEV(netdev, &pdev->dev); 28738c2ecf20Sopenharmony_ci 28748c2ecf20Sopenharmony_ci if (use_io) 28758c2ecf20Sopenharmony_ci netif_info(nic, probe, nic->netdev, "using i/o access mode\n"); 28768c2ecf20Sopenharmony_ci 28778c2ecf20Sopenharmony_ci nic->csr = pci_iomap(pdev, (use_io ? 1 : 0), sizeof(struct csr)); 28788c2ecf20Sopenharmony_ci if (!nic->csr) { 28798c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "Cannot map device registers, aborting\n"); 28808c2ecf20Sopenharmony_ci err = -ENOMEM; 28818c2ecf20Sopenharmony_ci goto err_out_free_res; 28828c2ecf20Sopenharmony_ci } 28838c2ecf20Sopenharmony_ci 28848c2ecf20Sopenharmony_ci if (ent->driver_data) 28858c2ecf20Sopenharmony_ci nic->flags |= ich; 28868c2ecf20Sopenharmony_ci else 28878c2ecf20Sopenharmony_ci nic->flags &= ~ich; 28888c2ecf20Sopenharmony_ci 28898c2ecf20Sopenharmony_ci e100_get_defaults(nic); 28908c2ecf20Sopenharmony_ci 28918c2ecf20Sopenharmony_ci /* D100 MAC doesn't allow rx of vlan packets with normal MTU */ 28928c2ecf20Sopenharmony_ci if (nic->mac < mac_82558_D101_A4) 28938c2ecf20Sopenharmony_ci netdev->features |= NETIF_F_VLAN_CHALLENGED; 28948c2ecf20Sopenharmony_ci 28958c2ecf20Sopenharmony_ci /* locks must be initialized before calling hw_reset */ 28968c2ecf20Sopenharmony_ci spin_lock_init(&nic->cb_lock); 28978c2ecf20Sopenharmony_ci spin_lock_init(&nic->cmd_lock); 28988c2ecf20Sopenharmony_ci spin_lock_init(&nic->mdio_lock); 28998c2ecf20Sopenharmony_ci 29008c2ecf20Sopenharmony_ci /* Reset the device before pci_set_master() in case device is in some 29018c2ecf20Sopenharmony_ci * funky state and has an interrupt pending - hint: we don't have the 29028c2ecf20Sopenharmony_ci * interrupt handler registered yet. */ 29038c2ecf20Sopenharmony_ci e100_hw_reset(nic); 29048c2ecf20Sopenharmony_ci 29058c2ecf20Sopenharmony_ci pci_set_master(pdev); 29068c2ecf20Sopenharmony_ci 29078c2ecf20Sopenharmony_ci timer_setup(&nic->watchdog, e100_watchdog, 0); 29088c2ecf20Sopenharmony_ci 29098c2ecf20Sopenharmony_ci INIT_WORK(&nic->tx_timeout_task, e100_tx_timeout_task); 29108c2ecf20Sopenharmony_ci 29118c2ecf20Sopenharmony_ci if ((err = e100_alloc(nic))) { 29128c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "Cannot alloc driver memory, aborting\n"); 29138c2ecf20Sopenharmony_ci goto err_out_iounmap; 29148c2ecf20Sopenharmony_ci } 29158c2ecf20Sopenharmony_ci 29168c2ecf20Sopenharmony_ci if ((err = e100_eeprom_load(nic))) 29178c2ecf20Sopenharmony_ci goto err_out_free; 29188c2ecf20Sopenharmony_ci 29198c2ecf20Sopenharmony_ci e100_phy_init(nic); 29208c2ecf20Sopenharmony_ci 29218c2ecf20Sopenharmony_ci memcpy(netdev->dev_addr, nic->eeprom, ETH_ALEN); 29228c2ecf20Sopenharmony_ci if (!is_valid_ether_addr(netdev->dev_addr)) { 29238c2ecf20Sopenharmony_ci if (!eeprom_bad_csum_allow) { 29248c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "Invalid MAC address from EEPROM, aborting\n"); 29258c2ecf20Sopenharmony_ci err = -EAGAIN; 29268c2ecf20Sopenharmony_ci goto err_out_free; 29278c2ecf20Sopenharmony_ci } else { 29288c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "Invalid MAC address from EEPROM, you MUST configure one.\n"); 29298c2ecf20Sopenharmony_ci } 29308c2ecf20Sopenharmony_ci } 29318c2ecf20Sopenharmony_ci 29328c2ecf20Sopenharmony_ci /* Wol magic packet can be enabled from eeprom */ 29338c2ecf20Sopenharmony_ci if ((nic->mac >= mac_82558_D101_A4) && 29348c2ecf20Sopenharmony_ci (le16_to_cpu(nic->eeprom[eeprom_id]) & eeprom_id_wol)) { 29358c2ecf20Sopenharmony_ci nic->flags |= wol_magic; 29368c2ecf20Sopenharmony_ci device_set_wakeup_enable(&pdev->dev, true); 29378c2ecf20Sopenharmony_ci } 29388c2ecf20Sopenharmony_ci 29398c2ecf20Sopenharmony_ci /* ack any pending wake events, disable PME */ 29408c2ecf20Sopenharmony_ci pci_pme_active(pdev, false); 29418c2ecf20Sopenharmony_ci 29428c2ecf20Sopenharmony_ci strcpy(netdev->name, "eth%d"); 29438c2ecf20Sopenharmony_ci if ((err = register_netdev(netdev))) { 29448c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "Cannot register net device, aborting\n"); 29458c2ecf20Sopenharmony_ci goto err_out_free; 29468c2ecf20Sopenharmony_ci } 29478c2ecf20Sopenharmony_ci nic->cbs_pool = dma_pool_create(netdev->name, 29488c2ecf20Sopenharmony_ci &nic->pdev->dev, 29498c2ecf20Sopenharmony_ci nic->params.cbs.max * sizeof(struct cb), 29508c2ecf20Sopenharmony_ci sizeof(u32), 29518c2ecf20Sopenharmony_ci 0); 29528c2ecf20Sopenharmony_ci if (!nic->cbs_pool) { 29538c2ecf20Sopenharmony_ci netif_err(nic, probe, nic->netdev, "Cannot create DMA pool, aborting\n"); 29548c2ecf20Sopenharmony_ci err = -ENOMEM; 29558c2ecf20Sopenharmony_ci goto err_out_pool; 29568c2ecf20Sopenharmony_ci } 29578c2ecf20Sopenharmony_ci netif_info(nic, probe, nic->netdev, 29588c2ecf20Sopenharmony_ci "addr 0x%llx, irq %d, MAC addr %pM\n", 29598c2ecf20Sopenharmony_ci (unsigned long long)pci_resource_start(pdev, use_io ? 1 : 0), 29608c2ecf20Sopenharmony_ci pdev->irq, netdev->dev_addr); 29618c2ecf20Sopenharmony_ci 29628c2ecf20Sopenharmony_ci return 0; 29638c2ecf20Sopenharmony_ci 29648c2ecf20Sopenharmony_cierr_out_pool: 29658c2ecf20Sopenharmony_ci unregister_netdev(netdev); 29668c2ecf20Sopenharmony_cierr_out_free: 29678c2ecf20Sopenharmony_ci e100_free(nic); 29688c2ecf20Sopenharmony_cierr_out_iounmap: 29698c2ecf20Sopenharmony_ci pci_iounmap(pdev, nic->csr); 29708c2ecf20Sopenharmony_cierr_out_free_res: 29718c2ecf20Sopenharmony_ci pci_release_regions(pdev); 29728c2ecf20Sopenharmony_cierr_out_disable_pdev: 29738c2ecf20Sopenharmony_ci pci_disable_device(pdev); 29748c2ecf20Sopenharmony_cierr_out_free_dev: 29758c2ecf20Sopenharmony_ci free_netdev(netdev); 29768c2ecf20Sopenharmony_ci return err; 29778c2ecf20Sopenharmony_ci} 29788c2ecf20Sopenharmony_ci 29798c2ecf20Sopenharmony_cistatic void e100_remove(struct pci_dev *pdev) 29808c2ecf20Sopenharmony_ci{ 29818c2ecf20Sopenharmony_ci struct net_device *netdev = pci_get_drvdata(pdev); 29828c2ecf20Sopenharmony_ci 29838c2ecf20Sopenharmony_ci if (netdev) { 29848c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 29858c2ecf20Sopenharmony_ci unregister_netdev(netdev); 29868c2ecf20Sopenharmony_ci e100_free(nic); 29878c2ecf20Sopenharmony_ci pci_iounmap(pdev, nic->csr); 29888c2ecf20Sopenharmony_ci dma_pool_destroy(nic->cbs_pool); 29898c2ecf20Sopenharmony_ci free_netdev(netdev); 29908c2ecf20Sopenharmony_ci pci_release_regions(pdev); 29918c2ecf20Sopenharmony_ci pci_disable_device(pdev); 29928c2ecf20Sopenharmony_ci } 29938c2ecf20Sopenharmony_ci} 29948c2ecf20Sopenharmony_ci 29958c2ecf20Sopenharmony_ci#define E100_82552_SMARTSPEED 0x14 /* SmartSpeed Ctrl register */ 29968c2ecf20Sopenharmony_ci#define E100_82552_REV_ANEG 0x0200 /* Reverse auto-negotiation */ 29978c2ecf20Sopenharmony_ci#define E100_82552_ANEG_NOW 0x0400 /* Auto-negotiate now */ 29988c2ecf20Sopenharmony_cistatic void __e100_shutdown(struct pci_dev *pdev, bool *enable_wake) 29998c2ecf20Sopenharmony_ci{ 30008c2ecf20Sopenharmony_ci struct net_device *netdev = pci_get_drvdata(pdev); 30018c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 30028c2ecf20Sopenharmony_ci 30038c2ecf20Sopenharmony_ci netif_device_detach(netdev); 30048c2ecf20Sopenharmony_ci 30058c2ecf20Sopenharmony_ci if (netif_running(netdev)) 30068c2ecf20Sopenharmony_ci e100_down(nic); 30078c2ecf20Sopenharmony_ci 30088c2ecf20Sopenharmony_ci if ((nic->flags & wol_magic) | e100_asf(nic)) { 30098c2ecf20Sopenharmony_ci /* enable reverse auto-negotiation */ 30108c2ecf20Sopenharmony_ci if (nic->phy == phy_82552_v) { 30118c2ecf20Sopenharmony_ci u16 smartspeed = mdio_read(netdev, nic->mii.phy_id, 30128c2ecf20Sopenharmony_ci E100_82552_SMARTSPEED); 30138c2ecf20Sopenharmony_ci 30148c2ecf20Sopenharmony_ci mdio_write(netdev, nic->mii.phy_id, 30158c2ecf20Sopenharmony_ci E100_82552_SMARTSPEED, smartspeed | 30168c2ecf20Sopenharmony_ci E100_82552_REV_ANEG | E100_82552_ANEG_NOW); 30178c2ecf20Sopenharmony_ci } 30188c2ecf20Sopenharmony_ci *enable_wake = true; 30198c2ecf20Sopenharmony_ci } else { 30208c2ecf20Sopenharmony_ci *enable_wake = false; 30218c2ecf20Sopenharmony_ci } 30228c2ecf20Sopenharmony_ci 30238c2ecf20Sopenharmony_ci pci_disable_device(pdev); 30248c2ecf20Sopenharmony_ci} 30258c2ecf20Sopenharmony_ci 30268c2ecf20Sopenharmony_cistatic int __e100_power_off(struct pci_dev *pdev, bool wake) 30278c2ecf20Sopenharmony_ci{ 30288c2ecf20Sopenharmony_ci if (wake) 30298c2ecf20Sopenharmony_ci return pci_prepare_to_sleep(pdev); 30308c2ecf20Sopenharmony_ci 30318c2ecf20Sopenharmony_ci pci_wake_from_d3(pdev, false); 30328c2ecf20Sopenharmony_ci pci_set_power_state(pdev, PCI_D3hot); 30338c2ecf20Sopenharmony_ci 30348c2ecf20Sopenharmony_ci return 0; 30358c2ecf20Sopenharmony_ci} 30368c2ecf20Sopenharmony_ci 30378c2ecf20Sopenharmony_cistatic int __maybe_unused e100_suspend(struct device *dev_d) 30388c2ecf20Sopenharmony_ci{ 30398c2ecf20Sopenharmony_ci bool wake; 30408c2ecf20Sopenharmony_ci 30418c2ecf20Sopenharmony_ci __e100_shutdown(to_pci_dev(dev_d), &wake); 30428c2ecf20Sopenharmony_ci 30438c2ecf20Sopenharmony_ci return 0; 30448c2ecf20Sopenharmony_ci} 30458c2ecf20Sopenharmony_ci 30468c2ecf20Sopenharmony_cistatic int __maybe_unused e100_resume(struct device *dev_d) 30478c2ecf20Sopenharmony_ci{ 30488c2ecf20Sopenharmony_ci struct net_device *netdev = dev_get_drvdata(dev_d); 30498c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 30508c2ecf20Sopenharmony_ci int err; 30518c2ecf20Sopenharmony_ci 30528c2ecf20Sopenharmony_ci err = pci_enable_device(to_pci_dev(dev_d)); 30538c2ecf20Sopenharmony_ci if (err) { 30548c2ecf20Sopenharmony_ci netdev_err(netdev, "Resume cannot enable PCI device, aborting\n"); 30558c2ecf20Sopenharmony_ci return err; 30568c2ecf20Sopenharmony_ci } 30578c2ecf20Sopenharmony_ci pci_set_master(to_pci_dev(dev_d)); 30588c2ecf20Sopenharmony_ci 30598c2ecf20Sopenharmony_ci /* disable reverse auto-negotiation */ 30608c2ecf20Sopenharmony_ci if (nic->phy == phy_82552_v) { 30618c2ecf20Sopenharmony_ci u16 smartspeed = mdio_read(netdev, nic->mii.phy_id, 30628c2ecf20Sopenharmony_ci E100_82552_SMARTSPEED); 30638c2ecf20Sopenharmony_ci 30648c2ecf20Sopenharmony_ci mdio_write(netdev, nic->mii.phy_id, 30658c2ecf20Sopenharmony_ci E100_82552_SMARTSPEED, 30668c2ecf20Sopenharmony_ci smartspeed & ~(E100_82552_REV_ANEG)); 30678c2ecf20Sopenharmony_ci } 30688c2ecf20Sopenharmony_ci 30698c2ecf20Sopenharmony_ci if (netif_running(netdev)) 30708c2ecf20Sopenharmony_ci e100_up(nic); 30718c2ecf20Sopenharmony_ci 30728c2ecf20Sopenharmony_ci netif_device_attach(netdev); 30738c2ecf20Sopenharmony_ci 30748c2ecf20Sopenharmony_ci return 0; 30758c2ecf20Sopenharmony_ci} 30768c2ecf20Sopenharmony_ci 30778c2ecf20Sopenharmony_cistatic void e100_shutdown(struct pci_dev *pdev) 30788c2ecf20Sopenharmony_ci{ 30798c2ecf20Sopenharmony_ci bool wake; 30808c2ecf20Sopenharmony_ci __e100_shutdown(pdev, &wake); 30818c2ecf20Sopenharmony_ci if (system_state == SYSTEM_POWER_OFF) 30828c2ecf20Sopenharmony_ci __e100_power_off(pdev, wake); 30838c2ecf20Sopenharmony_ci} 30848c2ecf20Sopenharmony_ci 30858c2ecf20Sopenharmony_ci/* ------------------ PCI Error Recovery infrastructure -------------- */ 30868c2ecf20Sopenharmony_ci/** 30878c2ecf20Sopenharmony_ci * e100_io_error_detected - called when PCI error is detected. 30888c2ecf20Sopenharmony_ci * @pdev: Pointer to PCI device 30898c2ecf20Sopenharmony_ci * @state: The current pci connection state 30908c2ecf20Sopenharmony_ci */ 30918c2ecf20Sopenharmony_cistatic pci_ers_result_t e100_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) 30928c2ecf20Sopenharmony_ci{ 30938c2ecf20Sopenharmony_ci struct net_device *netdev = pci_get_drvdata(pdev); 30948c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 30958c2ecf20Sopenharmony_ci 30968c2ecf20Sopenharmony_ci netif_device_detach(netdev); 30978c2ecf20Sopenharmony_ci 30988c2ecf20Sopenharmony_ci if (state == pci_channel_io_perm_failure) 30998c2ecf20Sopenharmony_ci return PCI_ERS_RESULT_DISCONNECT; 31008c2ecf20Sopenharmony_ci 31018c2ecf20Sopenharmony_ci if (netif_running(netdev)) 31028c2ecf20Sopenharmony_ci e100_down(nic); 31038c2ecf20Sopenharmony_ci pci_disable_device(pdev); 31048c2ecf20Sopenharmony_ci 31058c2ecf20Sopenharmony_ci /* Request a slot reset. */ 31068c2ecf20Sopenharmony_ci return PCI_ERS_RESULT_NEED_RESET; 31078c2ecf20Sopenharmony_ci} 31088c2ecf20Sopenharmony_ci 31098c2ecf20Sopenharmony_ci/** 31108c2ecf20Sopenharmony_ci * e100_io_slot_reset - called after the pci bus has been reset. 31118c2ecf20Sopenharmony_ci * @pdev: Pointer to PCI device 31128c2ecf20Sopenharmony_ci * 31138c2ecf20Sopenharmony_ci * Restart the card from scratch. 31148c2ecf20Sopenharmony_ci */ 31158c2ecf20Sopenharmony_cistatic pci_ers_result_t e100_io_slot_reset(struct pci_dev *pdev) 31168c2ecf20Sopenharmony_ci{ 31178c2ecf20Sopenharmony_ci struct net_device *netdev = pci_get_drvdata(pdev); 31188c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 31198c2ecf20Sopenharmony_ci 31208c2ecf20Sopenharmony_ci if (pci_enable_device(pdev)) { 31218c2ecf20Sopenharmony_ci pr_err("Cannot re-enable PCI device after reset\n"); 31228c2ecf20Sopenharmony_ci return PCI_ERS_RESULT_DISCONNECT; 31238c2ecf20Sopenharmony_ci } 31248c2ecf20Sopenharmony_ci pci_set_master(pdev); 31258c2ecf20Sopenharmony_ci 31268c2ecf20Sopenharmony_ci /* Only one device per card can do a reset */ 31278c2ecf20Sopenharmony_ci if (0 != PCI_FUNC(pdev->devfn)) 31288c2ecf20Sopenharmony_ci return PCI_ERS_RESULT_RECOVERED; 31298c2ecf20Sopenharmony_ci e100_hw_reset(nic); 31308c2ecf20Sopenharmony_ci e100_phy_init(nic); 31318c2ecf20Sopenharmony_ci 31328c2ecf20Sopenharmony_ci return PCI_ERS_RESULT_RECOVERED; 31338c2ecf20Sopenharmony_ci} 31348c2ecf20Sopenharmony_ci 31358c2ecf20Sopenharmony_ci/** 31368c2ecf20Sopenharmony_ci * e100_io_resume - resume normal operations 31378c2ecf20Sopenharmony_ci * @pdev: Pointer to PCI device 31388c2ecf20Sopenharmony_ci * 31398c2ecf20Sopenharmony_ci * Resume normal operations after an error recovery 31408c2ecf20Sopenharmony_ci * sequence has been completed. 31418c2ecf20Sopenharmony_ci */ 31428c2ecf20Sopenharmony_cistatic void e100_io_resume(struct pci_dev *pdev) 31438c2ecf20Sopenharmony_ci{ 31448c2ecf20Sopenharmony_ci struct net_device *netdev = pci_get_drvdata(pdev); 31458c2ecf20Sopenharmony_ci struct nic *nic = netdev_priv(netdev); 31468c2ecf20Sopenharmony_ci 31478c2ecf20Sopenharmony_ci /* ack any pending wake events, disable PME */ 31488c2ecf20Sopenharmony_ci pci_enable_wake(pdev, PCI_D0, 0); 31498c2ecf20Sopenharmony_ci 31508c2ecf20Sopenharmony_ci netif_device_attach(netdev); 31518c2ecf20Sopenharmony_ci if (netif_running(netdev)) { 31528c2ecf20Sopenharmony_ci e100_open(netdev); 31538c2ecf20Sopenharmony_ci mod_timer(&nic->watchdog, jiffies); 31548c2ecf20Sopenharmony_ci } 31558c2ecf20Sopenharmony_ci} 31568c2ecf20Sopenharmony_ci 31578c2ecf20Sopenharmony_cistatic const struct pci_error_handlers e100_err_handler = { 31588c2ecf20Sopenharmony_ci .error_detected = e100_io_error_detected, 31598c2ecf20Sopenharmony_ci .slot_reset = e100_io_slot_reset, 31608c2ecf20Sopenharmony_ci .resume = e100_io_resume, 31618c2ecf20Sopenharmony_ci}; 31628c2ecf20Sopenharmony_ci 31638c2ecf20Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(e100_pm_ops, e100_suspend, e100_resume); 31648c2ecf20Sopenharmony_ci 31658c2ecf20Sopenharmony_cistatic struct pci_driver e100_driver = { 31668c2ecf20Sopenharmony_ci .name = DRV_NAME, 31678c2ecf20Sopenharmony_ci .id_table = e100_id_table, 31688c2ecf20Sopenharmony_ci .probe = e100_probe, 31698c2ecf20Sopenharmony_ci .remove = e100_remove, 31708c2ecf20Sopenharmony_ci 31718c2ecf20Sopenharmony_ci /* Power Management hooks */ 31728c2ecf20Sopenharmony_ci .driver.pm = &e100_pm_ops, 31738c2ecf20Sopenharmony_ci 31748c2ecf20Sopenharmony_ci .shutdown = e100_shutdown, 31758c2ecf20Sopenharmony_ci .err_handler = &e100_err_handler, 31768c2ecf20Sopenharmony_ci}; 31778c2ecf20Sopenharmony_ci 31788c2ecf20Sopenharmony_cistatic int __init e100_init_module(void) 31798c2ecf20Sopenharmony_ci{ 31808c2ecf20Sopenharmony_ci if (((1 << debug) - 1) & NETIF_MSG_DRV) { 31818c2ecf20Sopenharmony_ci pr_info("%s\n", DRV_DESCRIPTION); 31828c2ecf20Sopenharmony_ci pr_info("%s\n", DRV_COPYRIGHT); 31838c2ecf20Sopenharmony_ci } 31848c2ecf20Sopenharmony_ci return pci_register_driver(&e100_driver); 31858c2ecf20Sopenharmony_ci} 31868c2ecf20Sopenharmony_ci 31878c2ecf20Sopenharmony_cistatic void __exit e100_cleanup_module(void) 31888c2ecf20Sopenharmony_ci{ 31898c2ecf20Sopenharmony_ci pci_unregister_driver(&e100_driver); 31908c2ecf20Sopenharmony_ci} 31918c2ecf20Sopenharmony_ci 31928c2ecf20Sopenharmony_cimodule_init(e100_init_module); 31938c2ecf20Sopenharmony_cimodule_exit(e100_cleanup_module); 3194