18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * New driver for Marvell Yukon chipset and SysKonnect Gigabit 48c2ecf20Sopenharmony_ci * Ethernet adapters. Based on earlier sk98lin, e100 and 58c2ecf20Sopenharmony_ci * FreeBSD if_sk drivers. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * This driver intentionally does not support all the features 88c2ecf20Sopenharmony_ci * of the original driver such as link fail-over and link management because 98c2ecf20Sopenharmony_ci * those should be done at higher levels. 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Copyright (C) 2004, 2005 Stephen Hemminger <shemminger@osdl.org> 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <linux/in.h> 178c2ecf20Sopenharmony_ci#include <linux/kernel.h> 188c2ecf20Sopenharmony_ci#include <linux/module.h> 198c2ecf20Sopenharmony_ci#include <linux/moduleparam.h> 208c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 218c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 228c2ecf20Sopenharmony_ci#include <linux/ethtool.h> 238c2ecf20Sopenharmony_ci#include <linux/pci.h> 248c2ecf20Sopenharmony_ci#include <linux/if_vlan.h> 258c2ecf20Sopenharmony_ci#include <linux/ip.h> 268c2ecf20Sopenharmony_ci#include <linux/delay.h> 278c2ecf20Sopenharmony_ci#include <linux/crc32.h> 288c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h> 298c2ecf20Sopenharmony_ci#include <linux/debugfs.h> 308c2ecf20Sopenharmony_ci#include <linux/sched.h> 318c2ecf20Sopenharmony_ci#include <linux/seq_file.h> 328c2ecf20Sopenharmony_ci#include <linux/mii.h> 338c2ecf20Sopenharmony_ci#include <linux/slab.h> 348c2ecf20Sopenharmony_ci#include <linux/dmi.h> 358c2ecf20Sopenharmony_ci#include <linux/prefetch.h> 368c2ecf20Sopenharmony_ci#include <asm/irq.h> 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include "skge.h" 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define DRV_NAME "skge" 418c2ecf20Sopenharmony_ci#define DRV_VERSION "1.14" 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define DEFAULT_TX_RING_SIZE 128 448c2ecf20Sopenharmony_ci#define DEFAULT_RX_RING_SIZE 512 458c2ecf20Sopenharmony_ci#define MAX_TX_RING_SIZE 1024 468c2ecf20Sopenharmony_ci#define TX_LOW_WATER (MAX_SKB_FRAGS + 1) 478c2ecf20Sopenharmony_ci#define MAX_RX_RING_SIZE 4096 488c2ecf20Sopenharmony_ci#define RX_COPY_THRESHOLD 128 498c2ecf20Sopenharmony_ci#define RX_BUF_SIZE 1536 508c2ecf20Sopenharmony_ci#define PHY_RETRIES 1000 518c2ecf20Sopenharmony_ci#define ETH_JUMBO_MTU 9000 528c2ecf20Sopenharmony_ci#define TX_WATCHDOG (5 * HZ) 538c2ecf20Sopenharmony_ci#define NAPI_WEIGHT 64 548c2ecf20Sopenharmony_ci#define BLINK_MS 250 558c2ecf20Sopenharmony_ci#define LINK_HZ HZ 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define SKGE_EEPROM_MAGIC 0x9933aabb 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver"); 618c2ecf20Sopenharmony_ciMODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>"); 628c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 638c2ecf20Sopenharmony_ciMODULE_VERSION(DRV_VERSION); 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic const u32 default_msg = (NETIF_MSG_DRV | NETIF_MSG_PROBE | 668c2ecf20Sopenharmony_ci NETIF_MSG_LINK | NETIF_MSG_IFUP | 678c2ecf20Sopenharmony_ci NETIF_MSG_IFDOWN); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic int debug = -1; /* defaults above */ 708c2ecf20Sopenharmony_cimodule_param(debug, int, 0); 718c2ecf20Sopenharmony_ciMODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistatic const struct pci_device_id skge_id_table[] = { 748c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_3COM, 0x1700) }, /* 3Com 3C940 */ 758c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_3COM, 0x80EB) }, /* 3Com 3C940B */ 768c2ecf20Sopenharmony_ci#ifdef CONFIG_SKGE_GENESIS 778c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x4300) }, /* SK-9xx */ 788c2ecf20Sopenharmony_ci#endif 798c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x4320) }, /* SK-98xx V2.0 */ 808c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) }, /* D-Link DGE-530T (rev.B) */ 818c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4c00) }, /* D-Link DGE-530T */ 828c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302) }, /* D-Link DGE-530T Rev C1 */ 838c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) }, /* Marvell Yukon 88E8001/8003/8010 */ 848c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */ 858c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_CNET, 0x434E) }, /* CNet PowerG-2000 */ 868c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, 0x1064) }, /* Linksys EG1064 v2 */ 878c2ecf20Sopenharmony_ci { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015 }, /* Linksys EG1032 v2 */ 888c2ecf20Sopenharmony_ci { 0 } 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, skge_id_table); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistatic int skge_up(struct net_device *dev); 938c2ecf20Sopenharmony_cistatic int skge_down(struct net_device *dev); 948c2ecf20Sopenharmony_cistatic void skge_phy_reset(struct skge_port *skge); 958c2ecf20Sopenharmony_cistatic void skge_tx_clean(struct net_device *dev); 968c2ecf20Sopenharmony_cistatic int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val); 978c2ecf20Sopenharmony_cistatic int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val); 988c2ecf20Sopenharmony_cistatic void genesis_get_stats(struct skge_port *skge, u64 *data); 998c2ecf20Sopenharmony_cistatic void yukon_get_stats(struct skge_port *skge, u64 *data); 1008c2ecf20Sopenharmony_cistatic void yukon_init(struct skge_hw *hw, int port); 1018c2ecf20Sopenharmony_cistatic void genesis_mac_init(struct skge_hw *hw, int port); 1028c2ecf20Sopenharmony_cistatic void genesis_link_up(struct skge_port *skge); 1038c2ecf20Sopenharmony_cistatic void skge_set_multicast(struct net_device *dev); 1048c2ecf20Sopenharmony_cistatic irqreturn_t skge_intr(int irq, void *dev_id); 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/* Avoid conditionals by using array */ 1078c2ecf20Sopenharmony_cistatic const int txqaddr[] = { Q_XA1, Q_XA2 }; 1088c2ecf20Sopenharmony_cistatic const int rxqaddr[] = { Q_R1, Q_R2 }; 1098c2ecf20Sopenharmony_cistatic const u32 rxirqmask[] = { IS_R1_F, IS_R2_F }; 1108c2ecf20Sopenharmony_cistatic const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F }; 1118c2ecf20Sopenharmony_cistatic const u32 napimask[] = { IS_R1_F|IS_XA1_F, IS_R2_F|IS_XA2_F }; 1128c2ecf20Sopenharmony_cistatic const u32 portmask[] = { IS_PORT_1, IS_PORT_2 }; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistatic inline bool is_genesis(const struct skge_hw *hw) 1158c2ecf20Sopenharmony_ci{ 1168c2ecf20Sopenharmony_ci#ifdef CONFIG_SKGE_GENESIS 1178c2ecf20Sopenharmony_ci return hw->chip_id == CHIP_ID_GENESIS; 1188c2ecf20Sopenharmony_ci#else 1198c2ecf20Sopenharmony_ci return false; 1208c2ecf20Sopenharmony_ci#endif 1218c2ecf20Sopenharmony_ci} 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistatic int skge_get_regs_len(struct net_device *dev) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci return 0x4000; 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci/* 1298c2ecf20Sopenharmony_ci * Returns copy of whole control register region 1308c2ecf20Sopenharmony_ci * Note: skip RAM address register because accessing it will 1318c2ecf20Sopenharmony_ci * cause bus hangs! 1328c2ecf20Sopenharmony_ci */ 1338c2ecf20Sopenharmony_cistatic void skge_get_regs(struct net_device *dev, struct ethtool_regs *regs, 1348c2ecf20Sopenharmony_ci void *p) 1358c2ecf20Sopenharmony_ci{ 1368c2ecf20Sopenharmony_ci const struct skge_port *skge = netdev_priv(dev); 1378c2ecf20Sopenharmony_ci const void __iomem *io = skge->hw->regs; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci regs->version = 1; 1408c2ecf20Sopenharmony_ci memset(p, 0, regs->len); 1418c2ecf20Sopenharmony_ci memcpy_fromio(p, io, B3_RAM_ADDR); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci if (regs->len > B3_RI_WTO_R1) { 1448c2ecf20Sopenharmony_ci memcpy_fromio(p + B3_RI_WTO_R1, io + B3_RI_WTO_R1, 1458c2ecf20Sopenharmony_ci regs->len - B3_RI_WTO_R1); 1468c2ecf20Sopenharmony_ci } 1478c2ecf20Sopenharmony_ci} 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* Wake on Lan only supported on Yukon chips with rev 1 or above */ 1508c2ecf20Sopenharmony_cistatic u32 wol_supported(const struct skge_hw *hw) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci if (is_genesis(hw)) 1538c2ecf20Sopenharmony_ci return 0; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0) 1568c2ecf20Sopenharmony_ci return 0; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci return WAKE_MAGIC | WAKE_PHY; 1598c2ecf20Sopenharmony_ci} 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cistatic void skge_wol_init(struct skge_port *skge) 1628c2ecf20Sopenharmony_ci{ 1638c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 1648c2ecf20Sopenharmony_ci int port = skge->port; 1658c2ecf20Sopenharmony_ci u16 ctrl; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci skge_write16(hw, B0_CTST, CS_RST_CLR); 1688c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci /* Turn on Vaux */ 1718c2ecf20Sopenharmony_ci skge_write8(hw, B0_POWER_CTRL, 1728c2ecf20Sopenharmony_ci PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_ON | PC_VCC_OFF); 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci /* WA code for COMA mode -- clear PHY reset */ 1758c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_LITE && 1768c2ecf20Sopenharmony_ci hw->chip_rev >= CHIP_REV_YU_LITE_A3) { 1778c2ecf20Sopenharmony_ci u32 reg = skge_read32(hw, B2_GP_IO); 1788c2ecf20Sopenharmony_ci reg |= GP_DIR_9; 1798c2ecf20Sopenharmony_ci reg &= ~GP_IO_9; 1808c2ecf20Sopenharmony_ci skge_write32(hw, B2_GP_IO, reg); 1818c2ecf20Sopenharmony_ci } 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, GPHY_CTRL), 1848c2ecf20Sopenharmony_ci GPC_DIS_SLEEP | 1858c2ecf20Sopenharmony_ci GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 | 1868c2ecf20Sopenharmony_ci GPC_ANEG_1 | GPC_RST_SET); 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, GPHY_CTRL), 1898c2ecf20Sopenharmony_ci GPC_DIS_SLEEP | 1908c2ecf20Sopenharmony_ci GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 | 1918c2ecf20Sopenharmony_ci GPC_ANEG_1 | GPC_RST_CLR); 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR); 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci /* Force to 10/100 skge_reset will re-enable on resume */ 1968c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, 1978c2ecf20Sopenharmony_ci (PHY_AN_100FULL | PHY_AN_100HALF | 1988c2ecf20Sopenharmony_ci PHY_AN_10FULL | PHY_AN_10HALF | PHY_AN_CSMA)); 1998c2ecf20Sopenharmony_ci /* no 1000 HD/FD */ 2008c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, 0); 2018c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_CTRL, 2028c2ecf20Sopenharmony_ci PHY_CT_RESET | PHY_CT_SPS_LSB | PHY_CT_ANE | 2038c2ecf20Sopenharmony_ci PHY_CT_RE_CFG | PHY_CT_DUP_MD); 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci /* Set GMAC to no flow control and auto update for speed/duplex */ 2078c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, 2088c2ecf20Sopenharmony_ci GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA| 2098c2ecf20Sopenharmony_ci GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS); 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci /* Set WOL address */ 2128c2ecf20Sopenharmony_ci memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR), 2138c2ecf20Sopenharmony_ci skge->netdev->dev_addr, ETH_ALEN); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci /* Turn on appropriate WOL control bits */ 2168c2ecf20Sopenharmony_ci skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT); 2178c2ecf20Sopenharmony_ci ctrl = 0; 2188c2ecf20Sopenharmony_ci if (skge->wol & WAKE_PHY) 2198c2ecf20Sopenharmony_ci ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT; 2208c2ecf20Sopenharmony_ci else 2218c2ecf20Sopenharmony_ci ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci if (skge->wol & WAKE_MAGIC) 2248c2ecf20Sopenharmony_ci ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT; 2258c2ecf20Sopenharmony_ci else 2268c2ecf20Sopenharmony_ci ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT; 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT; 2298c2ecf20Sopenharmony_ci skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl); 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci /* block receiver */ 2328c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); 2338c2ecf20Sopenharmony_ci} 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_cistatic void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 2368c2ecf20Sopenharmony_ci{ 2378c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci wol->supported = wol_supported(skge->hw); 2408c2ecf20Sopenharmony_ci wol->wolopts = skge->wol; 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 2468c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci if ((wol->wolopts & ~wol_supported(hw)) || 2498c2ecf20Sopenharmony_ci !device_can_wakeup(&hw->pdev->dev)) 2508c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci skge->wol = wol->wolopts; 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci device_set_wakeup_enable(&hw->pdev->dev, skge->wol); 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci return 0; 2578c2ecf20Sopenharmony_ci} 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci/* Determine supported/advertised modes based on hardware. 2608c2ecf20Sopenharmony_ci * Note: ethtool ADVERTISED_xxx == SUPPORTED_xxx 2618c2ecf20Sopenharmony_ci */ 2628c2ecf20Sopenharmony_cistatic u32 skge_supported_modes(const struct skge_hw *hw) 2638c2ecf20Sopenharmony_ci{ 2648c2ecf20Sopenharmony_ci u32 supported; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci if (hw->copper) { 2678c2ecf20Sopenharmony_ci supported = (SUPPORTED_10baseT_Half | 2688c2ecf20Sopenharmony_ci SUPPORTED_10baseT_Full | 2698c2ecf20Sopenharmony_ci SUPPORTED_100baseT_Half | 2708c2ecf20Sopenharmony_ci SUPPORTED_100baseT_Full | 2718c2ecf20Sopenharmony_ci SUPPORTED_1000baseT_Half | 2728c2ecf20Sopenharmony_ci SUPPORTED_1000baseT_Full | 2738c2ecf20Sopenharmony_ci SUPPORTED_Autoneg | 2748c2ecf20Sopenharmony_ci SUPPORTED_TP); 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci if (is_genesis(hw)) 2778c2ecf20Sopenharmony_ci supported &= ~(SUPPORTED_10baseT_Half | 2788c2ecf20Sopenharmony_ci SUPPORTED_10baseT_Full | 2798c2ecf20Sopenharmony_ci SUPPORTED_100baseT_Half | 2808c2ecf20Sopenharmony_ci SUPPORTED_100baseT_Full); 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci else if (hw->chip_id == CHIP_ID_YUKON) 2838c2ecf20Sopenharmony_ci supported &= ~SUPPORTED_1000baseT_Half; 2848c2ecf20Sopenharmony_ci } else 2858c2ecf20Sopenharmony_ci supported = (SUPPORTED_1000baseT_Full | 2868c2ecf20Sopenharmony_ci SUPPORTED_1000baseT_Half | 2878c2ecf20Sopenharmony_ci SUPPORTED_FIBRE | 2888c2ecf20Sopenharmony_ci SUPPORTED_Autoneg); 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci return supported; 2918c2ecf20Sopenharmony_ci} 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_cistatic int skge_get_link_ksettings(struct net_device *dev, 2948c2ecf20Sopenharmony_ci struct ethtool_link_ksettings *cmd) 2958c2ecf20Sopenharmony_ci{ 2968c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 2978c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 2988c2ecf20Sopenharmony_ci u32 supported, advertising; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci supported = skge_supported_modes(hw); 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci if (hw->copper) { 3038c2ecf20Sopenharmony_ci cmd->base.port = PORT_TP; 3048c2ecf20Sopenharmony_ci cmd->base.phy_address = hw->phy_addr; 3058c2ecf20Sopenharmony_ci } else 3068c2ecf20Sopenharmony_ci cmd->base.port = PORT_FIBRE; 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci advertising = skge->advertising; 3098c2ecf20Sopenharmony_ci cmd->base.autoneg = skge->autoneg; 3108c2ecf20Sopenharmony_ci cmd->base.speed = skge->speed; 3118c2ecf20Sopenharmony_ci cmd->base.duplex = skge->duplex; 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, 3148c2ecf20Sopenharmony_ci supported); 3158c2ecf20Sopenharmony_ci ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, 3168c2ecf20Sopenharmony_ci advertising); 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci return 0; 3198c2ecf20Sopenharmony_ci} 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_cistatic int skge_set_link_ksettings(struct net_device *dev, 3228c2ecf20Sopenharmony_ci const struct ethtool_link_ksettings *cmd) 3238c2ecf20Sopenharmony_ci{ 3248c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 3258c2ecf20Sopenharmony_ci const struct skge_hw *hw = skge->hw; 3268c2ecf20Sopenharmony_ci u32 supported = skge_supported_modes(hw); 3278c2ecf20Sopenharmony_ci int err = 0; 3288c2ecf20Sopenharmony_ci u32 advertising; 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci ethtool_convert_link_mode_to_legacy_u32(&advertising, 3318c2ecf20Sopenharmony_ci cmd->link_modes.advertising); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci if (cmd->base.autoneg == AUTONEG_ENABLE) { 3348c2ecf20Sopenharmony_ci advertising = supported; 3358c2ecf20Sopenharmony_ci skge->duplex = -1; 3368c2ecf20Sopenharmony_ci skge->speed = -1; 3378c2ecf20Sopenharmony_ci } else { 3388c2ecf20Sopenharmony_ci u32 setting; 3398c2ecf20Sopenharmony_ci u32 speed = cmd->base.speed; 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci switch (speed) { 3428c2ecf20Sopenharmony_ci case SPEED_1000: 3438c2ecf20Sopenharmony_ci if (cmd->base.duplex == DUPLEX_FULL) 3448c2ecf20Sopenharmony_ci setting = SUPPORTED_1000baseT_Full; 3458c2ecf20Sopenharmony_ci else if (cmd->base.duplex == DUPLEX_HALF) 3468c2ecf20Sopenharmony_ci setting = SUPPORTED_1000baseT_Half; 3478c2ecf20Sopenharmony_ci else 3488c2ecf20Sopenharmony_ci return -EINVAL; 3498c2ecf20Sopenharmony_ci break; 3508c2ecf20Sopenharmony_ci case SPEED_100: 3518c2ecf20Sopenharmony_ci if (cmd->base.duplex == DUPLEX_FULL) 3528c2ecf20Sopenharmony_ci setting = SUPPORTED_100baseT_Full; 3538c2ecf20Sopenharmony_ci else if (cmd->base.duplex == DUPLEX_HALF) 3548c2ecf20Sopenharmony_ci setting = SUPPORTED_100baseT_Half; 3558c2ecf20Sopenharmony_ci else 3568c2ecf20Sopenharmony_ci return -EINVAL; 3578c2ecf20Sopenharmony_ci break; 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci case SPEED_10: 3608c2ecf20Sopenharmony_ci if (cmd->base.duplex == DUPLEX_FULL) 3618c2ecf20Sopenharmony_ci setting = SUPPORTED_10baseT_Full; 3628c2ecf20Sopenharmony_ci else if (cmd->base.duplex == DUPLEX_HALF) 3638c2ecf20Sopenharmony_ci setting = SUPPORTED_10baseT_Half; 3648c2ecf20Sopenharmony_ci else 3658c2ecf20Sopenharmony_ci return -EINVAL; 3668c2ecf20Sopenharmony_ci break; 3678c2ecf20Sopenharmony_ci default: 3688c2ecf20Sopenharmony_ci return -EINVAL; 3698c2ecf20Sopenharmony_ci } 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci if ((setting & supported) == 0) 3728c2ecf20Sopenharmony_ci return -EINVAL; 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci skge->speed = speed; 3758c2ecf20Sopenharmony_ci skge->duplex = cmd->base.duplex; 3768c2ecf20Sopenharmony_ci } 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci skge->autoneg = cmd->base.autoneg; 3798c2ecf20Sopenharmony_ci skge->advertising = advertising; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci if (netif_running(dev)) { 3828c2ecf20Sopenharmony_ci skge_down(dev); 3838c2ecf20Sopenharmony_ci err = skge_up(dev); 3848c2ecf20Sopenharmony_ci if (err) { 3858c2ecf20Sopenharmony_ci dev_close(dev); 3868c2ecf20Sopenharmony_ci return err; 3878c2ecf20Sopenharmony_ci } 3888c2ecf20Sopenharmony_ci } 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci return 0; 3918c2ecf20Sopenharmony_ci} 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_cistatic void skge_get_drvinfo(struct net_device *dev, 3948c2ecf20Sopenharmony_ci struct ethtool_drvinfo *info) 3958c2ecf20Sopenharmony_ci{ 3968c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); 3998c2ecf20Sopenharmony_ci strlcpy(info->version, DRV_VERSION, sizeof(info->version)); 4008c2ecf20Sopenharmony_ci strlcpy(info->bus_info, pci_name(skge->hw->pdev), 4018c2ecf20Sopenharmony_ci sizeof(info->bus_info)); 4028c2ecf20Sopenharmony_ci} 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_cistatic const struct skge_stat { 4058c2ecf20Sopenharmony_ci char name[ETH_GSTRING_LEN]; 4068c2ecf20Sopenharmony_ci u16 xmac_offset; 4078c2ecf20Sopenharmony_ci u16 gma_offset; 4088c2ecf20Sopenharmony_ci} skge_stats[] = { 4098c2ecf20Sopenharmony_ci { "tx_bytes", XM_TXO_OK_HI, GM_TXO_OK_HI }, 4108c2ecf20Sopenharmony_ci { "rx_bytes", XM_RXO_OK_HI, GM_RXO_OK_HI }, 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci { "tx_broadcast", XM_TXF_BC_OK, GM_TXF_BC_OK }, 4138c2ecf20Sopenharmony_ci { "rx_broadcast", XM_RXF_BC_OK, GM_RXF_BC_OK }, 4148c2ecf20Sopenharmony_ci { "tx_multicast", XM_TXF_MC_OK, GM_TXF_MC_OK }, 4158c2ecf20Sopenharmony_ci { "rx_multicast", XM_RXF_MC_OK, GM_RXF_MC_OK }, 4168c2ecf20Sopenharmony_ci { "tx_unicast", XM_TXF_UC_OK, GM_TXF_UC_OK }, 4178c2ecf20Sopenharmony_ci { "rx_unicast", XM_RXF_UC_OK, GM_RXF_UC_OK }, 4188c2ecf20Sopenharmony_ci { "tx_mac_pause", XM_TXF_MPAUSE, GM_TXF_MPAUSE }, 4198c2ecf20Sopenharmony_ci { "rx_mac_pause", XM_RXF_MPAUSE, GM_RXF_MPAUSE }, 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci { "collisions", XM_TXF_SNG_COL, GM_TXF_SNG_COL }, 4228c2ecf20Sopenharmony_ci { "multi_collisions", XM_TXF_MUL_COL, GM_TXF_MUL_COL }, 4238c2ecf20Sopenharmony_ci { "aborted", XM_TXF_ABO_COL, GM_TXF_ABO_COL }, 4248c2ecf20Sopenharmony_ci { "late_collision", XM_TXF_LAT_COL, GM_TXF_LAT_COL }, 4258c2ecf20Sopenharmony_ci { "fifo_underrun", XM_TXE_FIFO_UR, GM_TXE_FIFO_UR }, 4268c2ecf20Sopenharmony_ci { "fifo_overflow", XM_RXE_FIFO_OV, GM_RXE_FIFO_OV }, 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci { "rx_toolong", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR }, 4298c2ecf20Sopenharmony_ci { "rx_jabber", XM_RXF_JAB_PKT, GM_RXF_JAB_PKT }, 4308c2ecf20Sopenharmony_ci { "rx_runt", XM_RXE_RUNT, GM_RXE_FRAG }, 4318c2ecf20Sopenharmony_ci { "rx_too_long", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR }, 4328c2ecf20Sopenharmony_ci { "rx_fcs_error", XM_RXF_FCS_ERR, GM_RXF_FCS_ERR }, 4338c2ecf20Sopenharmony_ci}; 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_cistatic int skge_get_sset_count(struct net_device *dev, int sset) 4368c2ecf20Sopenharmony_ci{ 4378c2ecf20Sopenharmony_ci switch (sset) { 4388c2ecf20Sopenharmony_ci case ETH_SS_STATS: 4398c2ecf20Sopenharmony_ci return ARRAY_SIZE(skge_stats); 4408c2ecf20Sopenharmony_ci default: 4418c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 4428c2ecf20Sopenharmony_ci } 4438c2ecf20Sopenharmony_ci} 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_cistatic void skge_get_ethtool_stats(struct net_device *dev, 4468c2ecf20Sopenharmony_ci struct ethtool_stats *stats, u64 *data) 4478c2ecf20Sopenharmony_ci{ 4488c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci if (is_genesis(skge->hw)) 4518c2ecf20Sopenharmony_ci genesis_get_stats(skge, data); 4528c2ecf20Sopenharmony_ci else 4538c2ecf20Sopenharmony_ci yukon_get_stats(skge, data); 4548c2ecf20Sopenharmony_ci} 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci/* Use hardware MIB variables for critical path statistics and 4578c2ecf20Sopenharmony_ci * transmit feedback not reported at interrupt. 4588c2ecf20Sopenharmony_ci * Other errors are accounted for in interrupt handler. 4598c2ecf20Sopenharmony_ci */ 4608c2ecf20Sopenharmony_cistatic struct net_device_stats *skge_get_stats(struct net_device *dev) 4618c2ecf20Sopenharmony_ci{ 4628c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 4638c2ecf20Sopenharmony_ci u64 data[ARRAY_SIZE(skge_stats)]; 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci if (is_genesis(skge->hw)) 4668c2ecf20Sopenharmony_ci genesis_get_stats(skge, data); 4678c2ecf20Sopenharmony_ci else 4688c2ecf20Sopenharmony_ci yukon_get_stats(skge, data); 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_ci dev->stats.tx_bytes = data[0]; 4718c2ecf20Sopenharmony_ci dev->stats.rx_bytes = data[1]; 4728c2ecf20Sopenharmony_ci dev->stats.tx_packets = data[2] + data[4] + data[6]; 4738c2ecf20Sopenharmony_ci dev->stats.rx_packets = data[3] + data[5] + data[7]; 4748c2ecf20Sopenharmony_ci dev->stats.multicast = data[3] + data[5]; 4758c2ecf20Sopenharmony_ci dev->stats.collisions = data[10]; 4768c2ecf20Sopenharmony_ci dev->stats.tx_aborted_errors = data[12]; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci return &dev->stats; 4798c2ecf20Sopenharmony_ci} 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_cistatic void skge_get_strings(struct net_device *dev, u32 stringset, u8 *data) 4828c2ecf20Sopenharmony_ci{ 4838c2ecf20Sopenharmony_ci int i; 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci switch (stringset) { 4868c2ecf20Sopenharmony_ci case ETH_SS_STATS: 4878c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(skge_stats); i++) 4888c2ecf20Sopenharmony_ci memcpy(data + i * ETH_GSTRING_LEN, 4898c2ecf20Sopenharmony_ci skge_stats[i].name, ETH_GSTRING_LEN); 4908c2ecf20Sopenharmony_ci break; 4918c2ecf20Sopenharmony_ci } 4928c2ecf20Sopenharmony_ci} 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_cistatic void skge_get_ring_param(struct net_device *dev, 4958c2ecf20Sopenharmony_ci struct ethtool_ringparam *p) 4968c2ecf20Sopenharmony_ci{ 4978c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci p->rx_max_pending = MAX_RX_RING_SIZE; 5008c2ecf20Sopenharmony_ci p->tx_max_pending = MAX_TX_RING_SIZE; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci p->rx_pending = skge->rx_ring.count; 5038c2ecf20Sopenharmony_ci p->tx_pending = skge->tx_ring.count; 5048c2ecf20Sopenharmony_ci} 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_cistatic int skge_set_ring_param(struct net_device *dev, 5078c2ecf20Sopenharmony_ci struct ethtool_ringparam *p) 5088c2ecf20Sopenharmony_ci{ 5098c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 5108c2ecf20Sopenharmony_ci int err = 0; 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci if (p->rx_pending == 0 || p->rx_pending > MAX_RX_RING_SIZE || 5138c2ecf20Sopenharmony_ci p->tx_pending < TX_LOW_WATER || p->tx_pending > MAX_TX_RING_SIZE) 5148c2ecf20Sopenharmony_ci return -EINVAL; 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci skge->rx_ring.count = p->rx_pending; 5178c2ecf20Sopenharmony_ci skge->tx_ring.count = p->tx_pending; 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci if (netif_running(dev)) { 5208c2ecf20Sopenharmony_ci skge_down(dev); 5218c2ecf20Sopenharmony_ci err = skge_up(dev); 5228c2ecf20Sopenharmony_ci if (err) 5238c2ecf20Sopenharmony_ci dev_close(dev); 5248c2ecf20Sopenharmony_ci } 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci return err; 5278c2ecf20Sopenharmony_ci} 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_cistatic u32 skge_get_msglevel(struct net_device *netdev) 5308c2ecf20Sopenharmony_ci{ 5318c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(netdev); 5328c2ecf20Sopenharmony_ci return skge->msg_enable; 5338c2ecf20Sopenharmony_ci} 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_cistatic void skge_set_msglevel(struct net_device *netdev, u32 value) 5368c2ecf20Sopenharmony_ci{ 5378c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(netdev); 5388c2ecf20Sopenharmony_ci skge->msg_enable = value; 5398c2ecf20Sopenharmony_ci} 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_cistatic int skge_nway_reset(struct net_device *dev) 5428c2ecf20Sopenharmony_ci{ 5438c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci if (skge->autoneg != AUTONEG_ENABLE || !netif_running(dev)) 5468c2ecf20Sopenharmony_ci return -EINVAL; 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci skge_phy_reset(skge); 5498c2ecf20Sopenharmony_ci return 0; 5508c2ecf20Sopenharmony_ci} 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_cistatic void skge_get_pauseparam(struct net_device *dev, 5538c2ecf20Sopenharmony_ci struct ethtool_pauseparam *ecmd) 5548c2ecf20Sopenharmony_ci{ 5558c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci ecmd->rx_pause = ((skge->flow_control == FLOW_MODE_SYMMETRIC) || 5588c2ecf20Sopenharmony_ci (skge->flow_control == FLOW_MODE_SYM_OR_REM)); 5598c2ecf20Sopenharmony_ci ecmd->tx_pause = (ecmd->rx_pause || 5608c2ecf20Sopenharmony_ci (skge->flow_control == FLOW_MODE_LOC_SEND)); 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci ecmd->autoneg = ecmd->rx_pause || ecmd->tx_pause; 5638c2ecf20Sopenharmony_ci} 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_cistatic int skge_set_pauseparam(struct net_device *dev, 5668c2ecf20Sopenharmony_ci struct ethtool_pauseparam *ecmd) 5678c2ecf20Sopenharmony_ci{ 5688c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 5698c2ecf20Sopenharmony_ci struct ethtool_pauseparam old; 5708c2ecf20Sopenharmony_ci int err = 0; 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci skge_get_pauseparam(dev, &old); 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci if (ecmd->autoneg != old.autoneg) 5758c2ecf20Sopenharmony_ci skge->flow_control = ecmd->autoneg ? FLOW_MODE_NONE : FLOW_MODE_SYMMETRIC; 5768c2ecf20Sopenharmony_ci else { 5778c2ecf20Sopenharmony_ci if (ecmd->rx_pause && ecmd->tx_pause) 5788c2ecf20Sopenharmony_ci skge->flow_control = FLOW_MODE_SYMMETRIC; 5798c2ecf20Sopenharmony_ci else if (ecmd->rx_pause && !ecmd->tx_pause) 5808c2ecf20Sopenharmony_ci skge->flow_control = FLOW_MODE_SYM_OR_REM; 5818c2ecf20Sopenharmony_ci else if (!ecmd->rx_pause && ecmd->tx_pause) 5828c2ecf20Sopenharmony_ci skge->flow_control = FLOW_MODE_LOC_SEND; 5838c2ecf20Sopenharmony_ci else 5848c2ecf20Sopenharmony_ci skge->flow_control = FLOW_MODE_NONE; 5858c2ecf20Sopenharmony_ci } 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci if (netif_running(dev)) { 5888c2ecf20Sopenharmony_ci skge_down(dev); 5898c2ecf20Sopenharmony_ci err = skge_up(dev); 5908c2ecf20Sopenharmony_ci if (err) { 5918c2ecf20Sopenharmony_ci dev_close(dev); 5928c2ecf20Sopenharmony_ci return err; 5938c2ecf20Sopenharmony_ci } 5948c2ecf20Sopenharmony_ci } 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci return 0; 5978c2ecf20Sopenharmony_ci} 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci/* Chip internal frequency for clock calculations */ 6008c2ecf20Sopenharmony_cistatic inline u32 hwkhz(const struct skge_hw *hw) 6018c2ecf20Sopenharmony_ci{ 6028c2ecf20Sopenharmony_ci return is_genesis(hw) ? 53125 : 78125; 6038c2ecf20Sopenharmony_ci} 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci/* Chip HZ to microseconds */ 6068c2ecf20Sopenharmony_cistatic inline u32 skge_clk2usec(const struct skge_hw *hw, u32 ticks) 6078c2ecf20Sopenharmony_ci{ 6088c2ecf20Sopenharmony_ci return (ticks * 1000) / hwkhz(hw); 6098c2ecf20Sopenharmony_ci} 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci/* Microseconds to chip HZ */ 6128c2ecf20Sopenharmony_cistatic inline u32 skge_usecs2clk(const struct skge_hw *hw, u32 usec) 6138c2ecf20Sopenharmony_ci{ 6148c2ecf20Sopenharmony_ci return hwkhz(hw) * usec / 1000; 6158c2ecf20Sopenharmony_ci} 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_cistatic int skge_get_coalesce(struct net_device *dev, 6188c2ecf20Sopenharmony_ci struct ethtool_coalesce *ecmd) 6198c2ecf20Sopenharmony_ci{ 6208c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 6218c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 6228c2ecf20Sopenharmony_ci int port = skge->port; 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_ci ecmd->rx_coalesce_usecs = 0; 6258c2ecf20Sopenharmony_ci ecmd->tx_coalesce_usecs = 0; 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_ci if (skge_read32(hw, B2_IRQM_CTRL) & TIM_START) { 6288c2ecf20Sopenharmony_ci u32 delay = skge_clk2usec(hw, skge_read32(hw, B2_IRQM_INI)); 6298c2ecf20Sopenharmony_ci u32 msk = skge_read32(hw, B2_IRQM_MSK); 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci if (msk & rxirqmask[port]) 6328c2ecf20Sopenharmony_ci ecmd->rx_coalesce_usecs = delay; 6338c2ecf20Sopenharmony_ci if (msk & txirqmask[port]) 6348c2ecf20Sopenharmony_ci ecmd->tx_coalesce_usecs = delay; 6358c2ecf20Sopenharmony_ci } 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci return 0; 6388c2ecf20Sopenharmony_ci} 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci/* Note: interrupt timer is per board, but can turn on/off per port */ 6418c2ecf20Sopenharmony_cistatic int skge_set_coalesce(struct net_device *dev, 6428c2ecf20Sopenharmony_ci struct ethtool_coalesce *ecmd) 6438c2ecf20Sopenharmony_ci{ 6448c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 6458c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 6468c2ecf20Sopenharmony_ci int port = skge->port; 6478c2ecf20Sopenharmony_ci u32 msk = skge_read32(hw, B2_IRQM_MSK); 6488c2ecf20Sopenharmony_ci u32 delay = 25; 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci if (ecmd->rx_coalesce_usecs == 0) 6518c2ecf20Sopenharmony_ci msk &= ~rxirqmask[port]; 6528c2ecf20Sopenharmony_ci else if (ecmd->rx_coalesce_usecs < 25 || 6538c2ecf20Sopenharmony_ci ecmd->rx_coalesce_usecs > 33333) 6548c2ecf20Sopenharmony_ci return -EINVAL; 6558c2ecf20Sopenharmony_ci else { 6568c2ecf20Sopenharmony_ci msk |= rxirqmask[port]; 6578c2ecf20Sopenharmony_ci delay = ecmd->rx_coalesce_usecs; 6588c2ecf20Sopenharmony_ci } 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci if (ecmd->tx_coalesce_usecs == 0) 6618c2ecf20Sopenharmony_ci msk &= ~txirqmask[port]; 6628c2ecf20Sopenharmony_ci else if (ecmd->tx_coalesce_usecs < 25 || 6638c2ecf20Sopenharmony_ci ecmd->tx_coalesce_usecs > 33333) 6648c2ecf20Sopenharmony_ci return -EINVAL; 6658c2ecf20Sopenharmony_ci else { 6668c2ecf20Sopenharmony_ci msk |= txirqmask[port]; 6678c2ecf20Sopenharmony_ci delay = min(delay, ecmd->rx_coalesce_usecs); 6688c2ecf20Sopenharmony_ci } 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci skge_write32(hw, B2_IRQM_MSK, msk); 6718c2ecf20Sopenharmony_ci if (msk == 0) 6728c2ecf20Sopenharmony_ci skge_write32(hw, B2_IRQM_CTRL, TIM_STOP); 6738c2ecf20Sopenharmony_ci else { 6748c2ecf20Sopenharmony_ci skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, delay)); 6758c2ecf20Sopenharmony_ci skge_write32(hw, B2_IRQM_CTRL, TIM_START); 6768c2ecf20Sopenharmony_ci } 6778c2ecf20Sopenharmony_ci return 0; 6788c2ecf20Sopenharmony_ci} 6798c2ecf20Sopenharmony_ci 6808c2ecf20Sopenharmony_cienum led_mode { LED_MODE_OFF, LED_MODE_ON, LED_MODE_TST }; 6818c2ecf20Sopenharmony_cistatic void skge_led(struct skge_port *skge, enum led_mode mode) 6828c2ecf20Sopenharmony_ci{ 6838c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 6848c2ecf20Sopenharmony_ci int port = skge->port; 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci spin_lock_bh(&hw->phy_lock); 6878c2ecf20Sopenharmony_ci if (is_genesis(hw)) { 6888c2ecf20Sopenharmony_ci switch (mode) { 6898c2ecf20Sopenharmony_ci case LED_MODE_OFF: 6908c2ecf20Sopenharmony_ci if (hw->phy_type == SK_PHY_BCOM) 6918c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF); 6928c2ecf20Sopenharmony_ci else { 6938c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, TX_LED_VAL), 0); 6948c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_T_OFF); 6958c2ecf20Sopenharmony_ci } 6968c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF); 6978c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, RX_LED_VAL), 0); 6988c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF); 6998c2ecf20Sopenharmony_ci break; 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci case LED_MODE_ON: 7028c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON); 7038c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON); 7048c2ecf20Sopenharmony_ci 7058c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START); 7068c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START); 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci break; 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci case LED_MODE_TST: 7118c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON); 7128c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, RX_LED_VAL), 100); 7138c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START); 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci if (hw->phy_type == SK_PHY_BCOM) 7168c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON); 7178c2ecf20Sopenharmony_ci else { 7188c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TX_LED_TST), LED_T_ON); 7198c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, TX_LED_VAL), 100); 7208c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START); 7218c2ecf20Sopenharmony_ci } 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci } 7248c2ecf20Sopenharmony_ci } else { 7258c2ecf20Sopenharmony_ci switch (mode) { 7268c2ecf20Sopenharmony_ci case LED_MODE_OFF: 7278c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); 7288c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_LED_OVER, 7298c2ecf20Sopenharmony_ci PHY_M_LED_MO_DUP(MO_LED_OFF) | 7308c2ecf20Sopenharmony_ci PHY_M_LED_MO_10(MO_LED_OFF) | 7318c2ecf20Sopenharmony_ci PHY_M_LED_MO_100(MO_LED_OFF) | 7328c2ecf20Sopenharmony_ci PHY_M_LED_MO_1000(MO_LED_OFF) | 7338c2ecf20Sopenharmony_ci PHY_M_LED_MO_RX(MO_LED_OFF)); 7348c2ecf20Sopenharmony_ci break; 7358c2ecf20Sopenharmony_ci case LED_MODE_ON: 7368c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 7378c2ecf20Sopenharmony_ci PHY_M_LED_PULS_DUR(PULS_170MS) | 7388c2ecf20Sopenharmony_ci PHY_M_LED_BLINK_RT(BLINK_84MS) | 7398c2ecf20Sopenharmony_ci PHY_M_LEDC_TX_CTRL | 7408c2ecf20Sopenharmony_ci PHY_M_LEDC_DP_CTRL); 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_LED_OVER, 7438c2ecf20Sopenharmony_ci PHY_M_LED_MO_RX(MO_LED_OFF) | 7448c2ecf20Sopenharmony_ci (skge->speed == SPEED_100 ? 7458c2ecf20Sopenharmony_ci PHY_M_LED_MO_100(MO_LED_ON) : 0)); 7468c2ecf20Sopenharmony_ci break; 7478c2ecf20Sopenharmony_ci case LED_MODE_TST: 7488c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); 7498c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_LED_OVER, 7508c2ecf20Sopenharmony_ci PHY_M_LED_MO_DUP(MO_LED_ON) | 7518c2ecf20Sopenharmony_ci PHY_M_LED_MO_10(MO_LED_ON) | 7528c2ecf20Sopenharmony_ci PHY_M_LED_MO_100(MO_LED_ON) | 7538c2ecf20Sopenharmony_ci PHY_M_LED_MO_1000(MO_LED_ON) | 7548c2ecf20Sopenharmony_ci PHY_M_LED_MO_RX(MO_LED_ON)); 7558c2ecf20Sopenharmony_ci } 7568c2ecf20Sopenharmony_ci } 7578c2ecf20Sopenharmony_ci spin_unlock_bh(&hw->phy_lock); 7588c2ecf20Sopenharmony_ci} 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ci/* blink LED's for finding board */ 7618c2ecf20Sopenharmony_cistatic int skge_set_phys_id(struct net_device *dev, 7628c2ecf20Sopenharmony_ci enum ethtool_phys_id_state state) 7638c2ecf20Sopenharmony_ci{ 7648c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci switch (state) { 7678c2ecf20Sopenharmony_ci case ETHTOOL_ID_ACTIVE: 7688c2ecf20Sopenharmony_ci return 2; /* cycle on/off twice per second */ 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci case ETHTOOL_ID_ON: 7718c2ecf20Sopenharmony_ci skge_led(skge, LED_MODE_TST); 7728c2ecf20Sopenharmony_ci break; 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_ci case ETHTOOL_ID_OFF: 7758c2ecf20Sopenharmony_ci skge_led(skge, LED_MODE_OFF); 7768c2ecf20Sopenharmony_ci break; 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci case ETHTOOL_ID_INACTIVE: 7798c2ecf20Sopenharmony_ci /* back to regular LED state */ 7808c2ecf20Sopenharmony_ci skge_led(skge, netif_running(dev) ? LED_MODE_ON : LED_MODE_OFF); 7818c2ecf20Sopenharmony_ci } 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci return 0; 7848c2ecf20Sopenharmony_ci} 7858c2ecf20Sopenharmony_ci 7868c2ecf20Sopenharmony_cistatic int skge_get_eeprom_len(struct net_device *dev) 7878c2ecf20Sopenharmony_ci{ 7888c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 7898c2ecf20Sopenharmony_ci u32 reg2; 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_ci pci_read_config_dword(skge->hw->pdev, PCI_DEV_REG2, ®2); 7928c2ecf20Sopenharmony_ci return 1 << (((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8); 7938c2ecf20Sopenharmony_ci} 7948c2ecf20Sopenharmony_ci 7958c2ecf20Sopenharmony_cistatic u32 skge_vpd_read(struct pci_dev *pdev, int cap, u16 offset) 7968c2ecf20Sopenharmony_ci{ 7978c2ecf20Sopenharmony_ci u32 val; 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_ci pci_write_config_word(pdev, cap + PCI_VPD_ADDR, offset); 8008c2ecf20Sopenharmony_ci 8018c2ecf20Sopenharmony_ci do { 8028c2ecf20Sopenharmony_ci pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset); 8038c2ecf20Sopenharmony_ci } while (!(offset & PCI_VPD_ADDR_F)); 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &val); 8068c2ecf20Sopenharmony_ci return val; 8078c2ecf20Sopenharmony_ci} 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_cistatic void skge_vpd_write(struct pci_dev *pdev, int cap, u16 offset, u32 val) 8108c2ecf20Sopenharmony_ci{ 8118c2ecf20Sopenharmony_ci pci_write_config_dword(pdev, cap + PCI_VPD_DATA, val); 8128c2ecf20Sopenharmony_ci pci_write_config_word(pdev, cap + PCI_VPD_ADDR, 8138c2ecf20Sopenharmony_ci offset | PCI_VPD_ADDR_F); 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_ci do { 8168c2ecf20Sopenharmony_ci pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset); 8178c2ecf20Sopenharmony_ci } while (offset & PCI_VPD_ADDR_F); 8188c2ecf20Sopenharmony_ci} 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_cistatic int skge_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, 8218c2ecf20Sopenharmony_ci u8 *data) 8228c2ecf20Sopenharmony_ci{ 8238c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 8248c2ecf20Sopenharmony_ci struct pci_dev *pdev = skge->hw->pdev; 8258c2ecf20Sopenharmony_ci int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD); 8268c2ecf20Sopenharmony_ci int length = eeprom->len; 8278c2ecf20Sopenharmony_ci u16 offset = eeprom->offset; 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_ci if (!cap) 8308c2ecf20Sopenharmony_ci return -EINVAL; 8318c2ecf20Sopenharmony_ci 8328c2ecf20Sopenharmony_ci eeprom->magic = SKGE_EEPROM_MAGIC; 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_ci while (length > 0) { 8358c2ecf20Sopenharmony_ci u32 val = skge_vpd_read(pdev, cap, offset); 8368c2ecf20Sopenharmony_ci int n = min_t(int, length, sizeof(val)); 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci memcpy(data, &val, n); 8398c2ecf20Sopenharmony_ci length -= n; 8408c2ecf20Sopenharmony_ci data += n; 8418c2ecf20Sopenharmony_ci offset += n; 8428c2ecf20Sopenharmony_ci } 8438c2ecf20Sopenharmony_ci return 0; 8448c2ecf20Sopenharmony_ci} 8458c2ecf20Sopenharmony_ci 8468c2ecf20Sopenharmony_cistatic int skge_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, 8478c2ecf20Sopenharmony_ci u8 *data) 8488c2ecf20Sopenharmony_ci{ 8498c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 8508c2ecf20Sopenharmony_ci struct pci_dev *pdev = skge->hw->pdev; 8518c2ecf20Sopenharmony_ci int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD); 8528c2ecf20Sopenharmony_ci int length = eeprom->len; 8538c2ecf20Sopenharmony_ci u16 offset = eeprom->offset; 8548c2ecf20Sopenharmony_ci 8558c2ecf20Sopenharmony_ci if (!cap) 8568c2ecf20Sopenharmony_ci return -EINVAL; 8578c2ecf20Sopenharmony_ci 8588c2ecf20Sopenharmony_ci if (eeprom->magic != SKGE_EEPROM_MAGIC) 8598c2ecf20Sopenharmony_ci return -EINVAL; 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ci while (length > 0) { 8628c2ecf20Sopenharmony_ci u32 val; 8638c2ecf20Sopenharmony_ci int n = min_t(int, length, sizeof(val)); 8648c2ecf20Sopenharmony_ci 8658c2ecf20Sopenharmony_ci if (n < sizeof(val)) 8668c2ecf20Sopenharmony_ci val = skge_vpd_read(pdev, cap, offset); 8678c2ecf20Sopenharmony_ci memcpy(&val, data, n); 8688c2ecf20Sopenharmony_ci 8698c2ecf20Sopenharmony_ci skge_vpd_write(pdev, cap, offset, val); 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci length -= n; 8728c2ecf20Sopenharmony_ci data += n; 8738c2ecf20Sopenharmony_ci offset += n; 8748c2ecf20Sopenharmony_ci } 8758c2ecf20Sopenharmony_ci return 0; 8768c2ecf20Sopenharmony_ci} 8778c2ecf20Sopenharmony_ci 8788c2ecf20Sopenharmony_cistatic const struct ethtool_ops skge_ethtool_ops = { 8798c2ecf20Sopenharmony_ci .supported_coalesce_params = ETHTOOL_COALESCE_USECS, 8808c2ecf20Sopenharmony_ci .get_drvinfo = skge_get_drvinfo, 8818c2ecf20Sopenharmony_ci .get_regs_len = skge_get_regs_len, 8828c2ecf20Sopenharmony_ci .get_regs = skge_get_regs, 8838c2ecf20Sopenharmony_ci .get_wol = skge_get_wol, 8848c2ecf20Sopenharmony_ci .set_wol = skge_set_wol, 8858c2ecf20Sopenharmony_ci .get_msglevel = skge_get_msglevel, 8868c2ecf20Sopenharmony_ci .set_msglevel = skge_set_msglevel, 8878c2ecf20Sopenharmony_ci .nway_reset = skge_nway_reset, 8888c2ecf20Sopenharmony_ci .get_link = ethtool_op_get_link, 8898c2ecf20Sopenharmony_ci .get_eeprom_len = skge_get_eeprom_len, 8908c2ecf20Sopenharmony_ci .get_eeprom = skge_get_eeprom, 8918c2ecf20Sopenharmony_ci .set_eeprom = skge_set_eeprom, 8928c2ecf20Sopenharmony_ci .get_ringparam = skge_get_ring_param, 8938c2ecf20Sopenharmony_ci .set_ringparam = skge_set_ring_param, 8948c2ecf20Sopenharmony_ci .get_pauseparam = skge_get_pauseparam, 8958c2ecf20Sopenharmony_ci .set_pauseparam = skge_set_pauseparam, 8968c2ecf20Sopenharmony_ci .get_coalesce = skge_get_coalesce, 8978c2ecf20Sopenharmony_ci .set_coalesce = skge_set_coalesce, 8988c2ecf20Sopenharmony_ci .get_strings = skge_get_strings, 8998c2ecf20Sopenharmony_ci .set_phys_id = skge_set_phys_id, 9008c2ecf20Sopenharmony_ci .get_sset_count = skge_get_sset_count, 9018c2ecf20Sopenharmony_ci .get_ethtool_stats = skge_get_ethtool_stats, 9028c2ecf20Sopenharmony_ci .get_link_ksettings = skge_get_link_ksettings, 9038c2ecf20Sopenharmony_ci .set_link_ksettings = skge_set_link_ksettings, 9048c2ecf20Sopenharmony_ci}; 9058c2ecf20Sopenharmony_ci 9068c2ecf20Sopenharmony_ci/* 9078c2ecf20Sopenharmony_ci * Allocate ring elements and chain them together 9088c2ecf20Sopenharmony_ci * One-to-one association of board descriptors with ring elements 9098c2ecf20Sopenharmony_ci */ 9108c2ecf20Sopenharmony_cistatic int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u32 base) 9118c2ecf20Sopenharmony_ci{ 9128c2ecf20Sopenharmony_ci struct skge_tx_desc *d; 9138c2ecf20Sopenharmony_ci struct skge_element *e; 9148c2ecf20Sopenharmony_ci int i; 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_ci ring->start = kcalloc(ring->count, sizeof(*e), GFP_KERNEL); 9178c2ecf20Sopenharmony_ci if (!ring->start) 9188c2ecf20Sopenharmony_ci return -ENOMEM; 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_ci for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) { 9218c2ecf20Sopenharmony_ci e->desc = d; 9228c2ecf20Sopenharmony_ci if (i == ring->count - 1) { 9238c2ecf20Sopenharmony_ci e->next = ring->start; 9248c2ecf20Sopenharmony_ci d->next_offset = base; 9258c2ecf20Sopenharmony_ci } else { 9268c2ecf20Sopenharmony_ci e->next = e + 1; 9278c2ecf20Sopenharmony_ci d->next_offset = base + (i+1) * sizeof(*d); 9288c2ecf20Sopenharmony_ci } 9298c2ecf20Sopenharmony_ci } 9308c2ecf20Sopenharmony_ci ring->to_use = ring->to_clean = ring->start; 9318c2ecf20Sopenharmony_ci 9328c2ecf20Sopenharmony_ci return 0; 9338c2ecf20Sopenharmony_ci} 9348c2ecf20Sopenharmony_ci 9358c2ecf20Sopenharmony_ci/* Allocate and setup a new buffer for receiving */ 9368c2ecf20Sopenharmony_cistatic int skge_rx_setup(struct skge_port *skge, struct skge_element *e, 9378c2ecf20Sopenharmony_ci struct sk_buff *skb, unsigned int bufsize) 9388c2ecf20Sopenharmony_ci{ 9398c2ecf20Sopenharmony_ci struct skge_rx_desc *rd = e->desc; 9408c2ecf20Sopenharmony_ci dma_addr_t map; 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_ci map = dma_map_single(&skge->hw->pdev->dev, skb->data, bufsize, 9438c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 9448c2ecf20Sopenharmony_ci 9458c2ecf20Sopenharmony_ci if (dma_mapping_error(&skge->hw->pdev->dev, map)) 9468c2ecf20Sopenharmony_ci return -1; 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci rd->dma_lo = lower_32_bits(map); 9498c2ecf20Sopenharmony_ci rd->dma_hi = upper_32_bits(map); 9508c2ecf20Sopenharmony_ci e->skb = skb; 9518c2ecf20Sopenharmony_ci rd->csum1_start = ETH_HLEN; 9528c2ecf20Sopenharmony_ci rd->csum2_start = ETH_HLEN; 9538c2ecf20Sopenharmony_ci rd->csum1 = 0; 9548c2ecf20Sopenharmony_ci rd->csum2 = 0; 9558c2ecf20Sopenharmony_ci 9568c2ecf20Sopenharmony_ci wmb(); 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_ci rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize; 9598c2ecf20Sopenharmony_ci dma_unmap_addr_set(e, mapaddr, map); 9608c2ecf20Sopenharmony_ci dma_unmap_len_set(e, maplen, bufsize); 9618c2ecf20Sopenharmony_ci return 0; 9628c2ecf20Sopenharmony_ci} 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ci/* Resume receiving using existing skb, 9658c2ecf20Sopenharmony_ci * Note: DMA address is not changed by chip. 9668c2ecf20Sopenharmony_ci * MTU not changed while receiver active. 9678c2ecf20Sopenharmony_ci */ 9688c2ecf20Sopenharmony_cistatic inline void skge_rx_reuse(struct skge_element *e, unsigned int size) 9698c2ecf20Sopenharmony_ci{ 9708c2ecf20Sopenharmony_ci struct skge_rx_desc *rd = e->desc; 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci rd->csum2 = 0; 9738c2ecf20Sopenharmony_ci rd->csum2_start = ETH_HLEN; 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_ci wmb(); 9768c2ecf20Sopenharmony_ci 9778c2ecf20Sopenharmony_ci rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | size; 9788c2ecf20Sopenharmony_ci} 9798c2ecf20Sopenharmony_ci 9808c2ecf20Sopenharmony_ci 9818c2ecf20Sopenharmony_ci/* Free all buffers in receive ring, assumes receiver stopped */ 9828c2ecf20Sopenharmony_cistatic void skge_rx_clean(struct skge_port *skge) 9838c2ecf20Sopenharmony_ci{ 9848c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 9858c2ecf20Sopenharmony_ci struct skge_ring *ring = &skge->rx_ring; 9868c2ecf20Sopenharmony_ci struct skge_element *e; 9878c2ecf20Sopenharmony_ci 9888c2ecf20Sopenharmony_ci e = ring->start; 9898c2ecf20Sopenharmony_ci do { 9908c2ecf20Sopenharmony_ci struct skge_rx_desc *rd = e->desc; 9918c2ecf20Sopenharmony_ci rd->control = 0; 9928c2ecf20Sopenharmony_ci if (e->skb) { 9938c2ecf20Sopenharmony_ci dma_unmap_single(&hw->pdev->dev, 9948c2ecf20Sopenharmony_ci dma_unmap_addr(e, mapaddr), 9958c2ecf20Sopenharmony_ci dma_unmap_len(e, maplen), 9968c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 9978c2ecf20Sopenharmony_ci dev_kfree_skb(e->skb); 9988c2ecf20Sopenharmony_ci e->skb = NULL; 9998c2ecf20Sopenharmony_ci } 10008c2ecf20Sopenharmony_ci } while ((e = e->next) != ring->start); 10018c2ecf20Sopenharmony_ci} 10028c2ecf20Sopenharmony_ci 10038c2ecf20Sopenharmony_ci 10048c2ecf20Sopenharmony_ci/* Allocate buffers for receive ring 10058c2ecf20Sopenharmony_ci * For receive: to_clean is next received frame. 10068c2ecf20Sopenharmony_ci */ 10078c2ecf20Sopenharmony_cistatic int skge_rx_fill(struct net_device *dev) 10088c2ecf20Sopenharmony_ci{ 10098c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 10108c2ecf20Sopenharmony_ci struct skge_ring *ring = &skge->rx_ring; 10118c2ecf20Sopenharmony_ci struct skge_element *e; 10128c2ecf20Sopenharmony_ci 10138c2ecf20Sopenharmony_ci e = ring->start; 10148c2ecf20Sopenharmony_ci do { 10158c2ecf20Sopenharmony_ci struct sk_buff *skb; 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ci skb = __netdev_alloc_skb(dev, skge->rx_buf_size + NET_IP_ALIGN, 10188c2ecf20Sopenharmony_ci GFP_KERNEL); 10198c2ecf20Sopenharmony_ci if (!skb) 10208c2ecf20Sopenharmony_ci return -ENOMEM; 10218c2ecf20Sopenharmony_ci 10228c2ecf20Sopenharmony_ci skb_reserve(skb, NET_IP_ALIGN); 10238c2ecf20Sopenharmony_ci if (skge_rx_setup(skge, e, skb, skge->rx_buf_size) < 0) { 10248c2ecf20Sopenharmony_ci dev_kfree_skb(skb); 10258c2ecf20Sopenharmony_ci return -EIO; 10268c2ecf20Sopenharmony_ci } 10278c2ecf20Sopenharmony_ci } while ((e = e->next) != ring->start); 10288c2ecf20Sopenharmony_ci 10298c2ecf20Sopenharmony_ci ring->to_clean = ring->start; 10308c2ecf20Sopenharmony_ci return 0; 10318c2ecf20Sopenharmony_ci} 10328c2ecf20Sopenharmony_ci 10338c2ecf20Sopenharmony_cistatic const char *skge_pause(enum pause_status status) 10348c2ecf20Sopenharmony_ci{ 10358c2ecf20Sopenharmony_ci switch (status) { 10368c2ecf20Sopenharmony_ci case FLOW_STAT_NONE: 10378c2ecf20Sopenharmony_ci return "none"; 10388c2ecf20Sopenharmony_ci case FLOW_STAT_REM_SEND: 10398c2ecf20Sopenharmony_ci return "rx only"; 10408c2ecf20Sopenharmony_ci case FLOW_STAT_LOC_SEND: 10418c2ecf20Sopenharmony_ci return "tx_only"; 10428c2ecf20Sopenharmony_ci case FLOW_STAT_SYMMETRIC: /* Both station may send PAUSE */ 10438c2ecf20Sopenharmony_ci return "both"; 10448c2ecf20Sopenharmony_ci default: 10458c2ecf20Sopenharmony_ci return "indeterminated"; 10468c2ecf20Sopenharmony_ci } 10478c2ecf20Sopenharmony_ci} 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci 10508c2ecf20Sopenharmony_cistatic void skge_link_up(struct skge_port *skge) 10518c2ecf20Sopenharmony_ci{ 10528c2ecf20Sopenharmony_ci skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), 10538c2ecf20Sopenharmony_ci LED_BLK_OFF|LED_SYNC_OFF|LED_REG_ON); 10548c2ecf20Sopenharmony_ci 10558c2ecf20Sopenharmony_ci netif_carrier_on(skge->netdev); 10568c2ecf20Sopenharmony_ci netif_wake_queue(skge->netdev); 10578c2ecf20Sopenharmony_ci 10588c2ecf20Sopenharmony_ci netif_info(skge, link, skge->netdev, 10598c2ecf20Sopenharmony_ci "Link is up at %d Mbps, %s duplex, flow control %s\n", 10608c2ecf20Sopenharmony_ci skge->speed, 10618c2ecf20Sopenharmony_ci skge->duplex == DUPLEX_FULL ? "full" : "half", 10628c2ecf20Sopenharmony_ci skge_pause(skge->flow_status)); 10638c2ecf20Sopenharmony_ci} 10648c2ecf20Sopenharmony_ci 10658c2ecf20Sopenharmony_cistatic void skge_link_down(struct skge_port *skge) 10668c2ecf20Sopenharmony_ci{ 10678c2ecf20Sopenharmony_ci skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_REG_OFF); 10688c2ecf20Sopenharmony_ci netif_carrier_off(skge->netdev); 10698c2ecf20Sopenharmony_ci netif_stop_queue(skge->netdev); 10708c2ecf20Sopenharmony_ci 10718c2ecf20Sopenharmony_ci netif_info(skge, link, skge->netdev, "Link is down\n"); 10728c2ecf20Sopenharmony_ci} 10738c2ecf20Sopenharmony_ci 10748c2ecf20Sopenharmony_cistatic void xm_link_down(struct skge_hw *hw, int port) 10758c2ecf20Sopenharmony_ci{ 10768c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 10778c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 10788c2ecf20Sopenharmony_ci 10798c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE); 10808c2ecf20Sopenharmony_ci 10818c2ecf20Sopenharmony_ci if (netif_carrier_ok(dev)) 10828c2ecf20Sopenharmony_ci skge_link_down(skge); 10838c2ecf20Sopenharmony_ci} 10848c2ecf20Sopenharmony_ci 10858c2ecf20Sopenharmony_cistatic int __xm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val) 10868c2ecf20Sopenharmony_ci{ 10878c2ecf20Sopenharmony_ci int i; 10888c2ecf20Sopenharmony_ci 10898c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr); 10908c2ecf20Sopenharmony_ci *val = xm_read16(hw, port, XM_PHY_DATA); 10918c2ecf20Sopenharmony_ci 10928c2ecf20Sopenharmony_ci if (hw->phy_type == SK_PHY_XMAC) 10938c2ecf20Sopenharmony_ci goto ready; 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci for (i = 0; i < PHY_RETRIES; i++) { 10968c2ecf20Sopenharmony_ci if (xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_RDY) 10978c2ecf20Sopenharmony_ci goto ready; 10988c2ecf20Sopenharmony_ci udelay(1); 10998c2ecf20Sopenharmony_ci } 11008c2ecf20Sopenharmony_ci 11018c2ecf20Sopenharmony_ci return -ETIMEDOUT; 11028c2ecf20Sopenharmony_ci ready: 11038c2ecf20Sopenharmony_ci *val = xm_read16(hw, port, XM_PHY_DATA); 11048c2ecf20Sopenharmony_ci 11058c2ecf20Sopenharmony_ci return 0; 11068c2ecf20Sopenharmony_ci} 11078c2ecf20Sopenharmony_ci 11088c2ecf20Sopenharmony_cistatic u16 xm_phy_read(struct skge_hw *hw, int port, u16 reg) 11098c2ecf20Sopenharmony_ci{ 11108c2ecf20Sopenharmony_ci u16 v = 0; 11118c2ecf20Sopenharmony_ci if (__xm_phy_read(hw, port, reg, &v)) 11128c2ecf20Sopenharmony_ci pr_warn("%s: phy read timed out\n", hw->dev[port]->name); 11138c2ecf20Sopenharmony_ci return v; 11148c2ecf20Sopenharmony_ci} 11158c2ecf20Sopenharmony_ci 11168c2ecf20Sopenharmony_cistatic int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val) 11178c2ecf20Sopenharmony_ci{ 11188c2ecf20Sopenharmony_ci int i; 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr); 11218c2ecf20Sopenharmony_ci for (i = 0; i < PHY_RETRIES; i++) { 11228c2ecf20Sopenharmony_ci if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY)) 11238c2ecf20Sopenharmony_ci goto ready; 11248c2ecf20Sopenharmony_ci udelay(1); 11258c2ecf20Sopenharmony_ci } 11268c2ecf20Sopenharmony_ci return -EIO; 11278c2ecf20Sopenharmony_ci 11288c2ecf20Sopenharmony_ci ready: 11298c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_PHY_DATA, val); 11308c2ecf20Sopenharmony_ci for (i = 0; i < PHY_RETRIES; i++) { 11318c2ecf20Sopenharmony_ci if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY)) 11328c2ecf20Sopenharmony_ci return 0; 11338c2ecf20Sopenharmony_ci udelay(1); 11348c2ecf20Sopenharmony_ci } 11358c2ecf20Sopenharmony_ci return -ETIMEDOUT; 11368c2ecf20Sopenharmony_ci} 11378c2ecf20Sopenharmony_ci 11388c2ecf20Sopenharmony_cistatic void genesis_init(struct skge_hw *hw) 11398c2ecf20Sopenharmony_ci{ 11408c2ecf20Sopenharmony_ci /* set blink source counter */ 11418c2ecf20Sopenharmony_ci skge_write32(hw, B2_BSC_INI, (SK_BLK_DUR * SK_FACT_53) / 100); 11428c2ecf20Sopenharmony_ci skge_write8(hw, B2_BSC_CTRL, BSC_START); 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci /* configure mac arbiter */ 11458c2ecf20Sopenharmony_ci skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR); 11468c2ecf20Sopenharmony_ci 11478c2ecf20Sopenharmony_ci /* configure mac arbiter timeout values */ 11488c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_TOINI_RX1, SK_MAC_TO_53); 11498c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_TOINI_RX2, SK_MAC_TO_53); 11508c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_TOINI_TX1, SK_MAC_TO_53); 11518c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_TOINI_TX2, SK_MAC_TO_53); 11528c2ecf20Sopenharmony_ci 11538c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_RCINI_RX1, 0); 11548c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_RCINI_RX2, 0); 11558c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_RCINI_TX1, 0); 11568c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_RCINI_TX2, 0); 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci /* configure packet arbiter timeout */ 11598c2ecf20Sopenharmony_ci skge_write16(hw, B3_PA_CTRL, PA_RST_CLR); 11608c2ecf20Sopenharmony_ci skge_write16(hw, B3_PA_TOINI_RX1, SK_PKT_TO_MAX); 11618c2ecf20Sopenharmony_ci skge_write16(hw, B3_PA_TOINI_TX1, SK_PKT_TO_MAX); 11628c2ecf20Sopenharmony_ci skge_write16(hw, B3_PA_TOINI_RX2, SK_PKT_TO_MAX); 11638c2ecf20Sopenharmony_ci skge_write16(hw, B3_PA_TOINI_TX2, SK_PKT_TO_MAX); 11648c2ecf20Sopenharmony_ci} 11658c2ecf20Sopenharmony_ci 11668c2ecf20Sopenharmony_cistatic void genesis_reset(struct skge_hw *hw, int port) 11678c2ecf20Sopenharmony_ci{ 11688c2ecf20Sopenharmony_ci static const u8 zero[8] = { 0 }; 11698c2ecf20Sopenharmony_ci u32 reg; 11708c2ecf20Sopenharmony_ci 11718c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0); 11728c2ecf20Sopenharmony_ci 11738c2ecf20Sopenharmony_ci /* reset the statistics module */ 11748c2ecf20Sopenharmony_ci xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT); 11758c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE); 11768c2ecf20Sopenharmony_ci xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */ 11778c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */ 11788c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */ 11798c2ecf20Sopenharmony_ci 11808c2ecf20Sopenharmony_ci /* disable Broadcom PHY IRQ */ 11818c2ecf20Sopenharmony_ci if (hw->phy_type == SK_PHY_BCOM) 11828c2ecf20Sopenharmony_ci xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff); 11838c2ecf20Sopenharmony_ci 11848c2ecf20Sopenharmony_ci xm_outhash(hw, port, XM_HSM, zero); 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_ci /* Flush TX and RX fifo */ 11878c2ecf20Sopenharmony_ci reg = xm_read32(hw, port, XM_MODE); 11888c2ecf20Sopenharmony_ci xm_write32(hw, port, XM_MODE, reg | XM_MD_FTF); 11898c2ecf20Sopenharmony_ci xm_write32(hw, port, XM_MODE, reg | XM_MD_FRF); 11908c2ecf20Sopenharmony_ci} 11918c2ecf20Sopenharmony_ci 11928c2ecf20Sopenharmony_ci/* Convert mode to MII values */ 11938c2ecf20Sopenharmony_cistatic const u16 phy_pause_map[] = { 11948c2ecf20Sopenharmony_ci [FLOW_MODE_NONE] = 0, 11958c2ecf20Sopenharmony_ci [FLOW_MODE_LOC_SEND] = PHY_AN_PAUSE_ASYM, 11968c2ecf20Sopenharmony_ci [FLOW_MODE_SYMMETRIC] = PHY_AN_PAUSE_CAP, 11978c2ecf20Sopenharmony_ci [FLOW_MODE_SYM_OR_REM] = PHY_AN_PAUSE_CAP | PHY_AN_PAUSE_ASYM, 11988c2ecf20Sopenharmony_ci}; 11998c2ecf20Sopenharmony_ci 12008c2ecf20Sopenharmony_ci/* special defines for FIBER (88E1011S only) */ 12018c2ecf20Sopenharmony_cistatic const u16 fiber_pause_map[] = { 12028c2ecf20Sopenharmony_ci [FLOW_MODE_NONE] = PHY_X_P_NO_PAUSE, 12038c2ecf20Sopenharmony_ci [FLOW_MODE_LOC_SEND] = PHY_X_P_ASYM_MD, 12048c2ecf20Sopenharmony_ci [FLOW_MODE_SYMMETRIC] = PHY_X_P_SYM_MD, 12058c2ecf20Sopenharmony_ci [FLOW_MODE_SYM_OR_REM] = PHY_X_P_BOTH_MD, 12068c2ecf20Sopenharmony_ci}; 12078c2ecf20Sopenharmony_ci 12088c2ecf20Sopenharmony_ci 12098c2ecf20Sopenharmony_ci/* Check status of Broadcom phy link */ 12108c2ecf20Sopenharmony_cistatic void bcom_check_link(struct skge_hw *hw, int port) 12118c2ecf20Sopenharmony_ci{ 12128c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 12138c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 12148c2ecf20Sopenharmony_ci u16 status; 12158c2ecf20Sopenharmony_ci 12168c2ecf20Sopenharmony_ci /* read twice because of latch */ 12178c2ecf20Sopenharmony_ci xm_phy_read(hw, port, PHY_BCOM_STAT); 12188c2ecf20Sopenharmony_ci status = xm_phy_read(hw, port, PHY_BCOM_STAT); 12198c2ecf20Sopenharmony_ci 12208c2ecf20Sopenharmony_ci if ((status & PHY_ST_LSYNC) == 0) { 12218c2ecf20Sopenharmony_ci xm_link_down(hw, port); 12228c2ecf20Sopenharmony_ci return; 12238c2ecf20Sopenharmony_ci } 12248c2ecf20Sopenharmony_ci 12258c2ecf20Sopenharmony_ci if (skge->autoneg == AUTONEG_ENABLE) { 12268c2ecf20Sopenharmony_ci u16 lpa, aux; 12278c2ecf20Sopenharmony_ci 12288c2ecf20Sopenharmony_ci if (!(status & PHY_ST_AN_OVER)) 12298c2ecf20Sopenharmony_ci return; 12308c2ecf20Sopenharmony_ci 12318c2ecf20Sopenharmony_ci lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP); 12328c2ecf20Sopenharmony_ci if (lpa & PHY_B_AN_RF) { 12338c2ecf20Sopenharmony_ci netdev_notice(dev, "remote fault\n"); 12348c2ecf20Sopenharmony_ci return; 12358c2ecf20Sopenharmony_ci } 12368c2ecf20Sopenharmony_ci 12378c2ecf20Sopenharmony_ci aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT); 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_ci /* Check Duplex mismatch */ 12408c2ecf20Sopenharmony_ci switch (aux & PHY_B_AS_AN_RES_MSK) { 12418c2ecf20Sopenharmony_ci case PHY_B_RES_1000FD: 12428c2ecf20Sopenharmony_ci skge->duplex = DUPLEX_FULL; 12438c2ecf20Sopenharmony_ci break; 12448c2ecf20Sopenharmony_ci case PHY_B_RES_1000HD: 12458c2ecf20Sopenharmony_ci skge->duplex = DUPLEX_HALF; 12468c2ecf20Sopenharmony_ci break; 12478c2ecf20Sopenharmony_ci default: 12488c2ecf20Sopenharmony_ci netdev_notice(dev, "duplex mismatch\n"); 12498c2ecf20Sopenharmony_ci return; 12508c2ecf20Sopenharmony_ci } 12518c2ecf20Sopenharmony_ci 12528c2ecf20Sopenharmony_ci /* We are using IEEE 802.3z/D5.0 Table 37-4 */ 12538c2ecf20Sopenharmony_ci switch (aux & PHY_B_AS_PAUSE_MSK) { 12548c2ecf20Sopenharmony_ci case PHY_B_AS_PAUSE_MSK: 12558c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_SYMMETRIC; 12568c2ecf20Sopenharmony_ci break; 12578c2ecf20Sopenharmony_ci case PHY_B_AS_PRR: 12588c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_REM_SEND; 12598c2ecf20Sopenharmony_ci break; 12608c2ecf20Sopenharmony_ci case PHY_B_AS_PRT: 12618c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_LOC_SEND; 12628c2ecf20Sopenharmony_ci break; 12638c2ecf20Sopenharmony_ci default: 12648c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_NONE; 12658c2ecf20Sopenharmony_ci } 12668c2ecf20Sopenharmony_ci skge->speed = SPEED_1000; 12678c2ecf20Sopenharmony_ci } 12688c2ecf20Sopenharmony_ci 12698c2ecf20Sopenharmony_ci if (!netif_carrier_ok(dev)) 12708c2ecf20Sopenharmony_ci genesis_link_up(skge); 12718c2ecf20Sopenharmony_ci} 12728c2ecf20Sopenharmony_ci 12738c2ecf20Sopenharmony_ci/* Broadcom 5400 only supports giagabit! SysKonnect did not put an additional 12748c2ecf20Sopenharmony_ci * Phy on for 100 or 10Mbit operation 12758c2ecf20Sopenharmony_ci */ 12768c2ecf20Sopenharmony_cistatic void bcom_phy_init(struct skge_port *skge) 12778c2ecf20Sopenharmony_ci{ 12788c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 12798c2ecf20Sopenharmony_ci int port = skge->port; 12808c2ecf20Sopenharmony_ci int i; 12818c2ecf20Sopenharmony_ci u16 id1, r, ext, ctl; 12828c2ecf20Sopenharmony_ci 12838c2ecf20Sopenharmony_ci /* magic workaround patterns for Broadcom */ 12848c2ecf20Sopenharmony_ci static const struct { 12858c2ecf20Sopenharmony_ci u16 reg; 12868c2ecf20Sopenharmony_ci u16 val; 12878c2ecf20Sopenharmony_ci } A1hack[] = { 12888c2ecf20Sopenharmony_ci { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1104 }, 12898c2ecf20Sopenharmony_ci { 0x17, 0x0013 }, { 0x15, 0x0404 }, { 0x17, 0x8006 }, 12908c2ecf20Sopenharmony_ci { 0x15, 0x0132 }, { 0x17, 0x8006 }, { 0x15, 0x0232 }, 12918c2ecf20Sopenharmony_ci { 0x17, 0x800D }, { 0x15, 0x000F }, { 0x18, 0x0420 }, 12928c2ecf20Sopenharmony_ci }, C0hack[] = { 12938c2ecf20Sopenharmony_ci { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1204 }, 12948c2ecf20Sopenharmony_ci { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 }, 12958c2ecf20Sopenharmony_ci }; 12968c2ecf20Sopenharmony_ci 12978c2ecf20Sopenharmony_ci /* read Id from external PHY (all have the same address) */ 12988c2ecf20Sopenharmony_ci id1 = xm_phy_read(hw, port, PHY_XMAC_ID1); 12998c2ecf20Sopenharmony_ci 13008c2ecf20Sopenharmony_ci /* Optimize MDIO transfer by suppressing preamble. */ 13018c2ecf20Sopenharmony_ci r = xm_read16(hw, port, XM_MMU_CMD); 13028c2ecf20Sopenharmony_ci r |= XM_MMU_NO_PRE; 13038c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_MMU_CMD, r); 13048c2ecf20Sopenharmony_ci 13058c2ecf20Sopenharmony_ci switch (id1) { 13068c2ecf20Sopenharmony_ci case PHY_BCOM_ID1_C0: 13078c2ecf20Sopenharmony_ci /* 13088c2ecf20Sopenharmony_ci * Workaround BCOM Errata for the C0 type. 13098c2ecf20Sopenharmony_ci * Write magic patterns to reserved registers. 13108c2ecf20Sopenharmony_ci */ 13118c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(C0hack); i++) 13128c2ecf20Sopenharmony_ci xm_phy_write(hw, port, 13138c2ecf20Sopenharmony_ci C0hack[i].reg, C0hack[i].val); 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_ci break; 13168c2ecf20Sopenharmony_ci case PHY_BCOM_ID1_A1: 13178c2ecf20Sopenharmony_ci /* 13188c2ecf20Sopenharmony_ci * Workaround BCOM Errata for the A1 type. 13198c2ecf20Sopenharmony_ci * Write magic patterns to reserved registers. 13208c2ecf20Sopenharmony_ci */ 13218c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(A1hack); i++) 13228c2ecf20Sopenharmony_ci xm_phy_write(hw, port, 13238c2ecf20Sopenharmony_ci A1hack[i].reg, A1hack[i].val); 13248c2ecf20Sopenharmony_ci break; 13258c2ecf20Sopenharmony_ci } 13268c2ecf20Sopenharmony_ci 13278c2ecf20Sopenharmony_ci /* 13288c2ecf20Sopenharmony_ci * Workaround BCOM Errata (#10523) for all BCom PHYs. 13298c2ecf20Sopenharmony_ci * Disable Power Management after reset. 13308c2ecf20Sopenharmony_ci */ 13318c2ecf20Sopenharmony_ci r = xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL); 13328c2ecf20Sopenharmony_ci r |= PHY_B_AC_DIS_PM; 13338c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r); 13348c2ecf20Sopenharmony_ci 13358c2ecf20Sopenharmony_ci /* Dummy read */ 13368c2ecf20Sopenharmony_ci xm_read16(hw, port, XM_ISRC); 13378c2ecf20Sopenharmony_ci 13388c2ecf20Sopenharmony_ci ext = PHY_B_PEC_EN_LTR; /* enable tx led */ 13398c2ecf20Sopenharmony_ci ctl = PHY_CT_SP1000; /* always 1000mbit */ 13408c2ecf20Sopenharmony_ci 13418c2ecf20Sopenharmony_ci if (skge->autoneg == AUTONEG_ENABLE) { 13428c2ecf20Sopenharmony_ci /* 13438c2ecf20Sopenharmony_ci * Workaround BCOM Errata #1 for the C5 type. 13448c2ecf20Sopenharmony_ci * 1000Base-T Link Acquisition Failure in Slave Mode 13458c2ecf20Sopenharmony_ci * Set Repeater/DTE bit 10 of the 1000Base-T Control Register 13468c2ecf20Sopenharmony_ci */ 13478c2ecf20Sopenharmony_ci u16 adv = PHY_B_1000C_RD; 13488c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_1000baseT_Half) 13498c2ecf20Sopenharmony_ci adv |= PHY_B_1000C_AHD; 13508c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_1000baseT_Full) 13518c2ecf20Sopenharmony_ci adv |= PHY_B_1000C_AFD; 13528c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, adv); 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_ci ctl |= PHY_CT_ANE | PHY_CT_RE_CFG; 13558c2ecf20Sopenharmony_ci } else { 13568c2ecf20Sopenharmony_ci if (skge->duplex == DUPLEX_FULL) 13578c2ecf20Sopenharmony_ci ctl |= PHY_CT_DUP_MD; 13588c2ecf20Sopenharmony_ci /* Force to slave */ 13598c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, PHY_B_1000C_MSE); 13608c2ecf20Sopenharmony_ci } 13618c2ecf20Sopenharmony_ci 13628c2ecf20Sopenharmony_ci /* Set autonegotiation pause parameters */ 13638c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV, 13648c2ecf20Sopenharmony_ci phy_pause_map[skge->flow_control] | PHY_AN_CSMA); 13658c2ecf20Sopenharmony_ci 13668c2ecf20Sopenharmony_ci /* Handle Jumbo frames */ 13678c2ecf20Sopenharmony_ci if (hw->dev[port]->mtu > ETH_DATA_LEN) { 13688c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, 13698c2ecf20Sopenharmony_ci PHY_B_AC_TX_TST | PHY_B_AC_LONG_PACK); 13708c2ecf20Sopenharmony_ci 13718c2ecf20Sopenharmony_ci ext |= PHY_B_PEC_HIGH_LA; 13728c2ecf20Sopenharmony_ci 13738c2ecf20Sopenharmony_ci } 13748c2ecf20Sopenharmony_ci 13758c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ext); 13768c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_CTRL, ctl); 13778c2ecf20Sopenharmony_ci 13788c2ecf20Sopenharmony_ci /* Use link status change interrupt */ 13798c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK); 13808c2ecf20Sopenharmony_ci} 13818c2ecf20Sopenharmony_ci 13828c2ecf20Sopenharmony_cistatic void xm_phy_init(struct skge_port *skge) 13838c2ecf20Sopenharmony_ci{ 13848c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 13858c2ecf20Sopenharmony_ci int port = skge->port; 13868c2ecf20Sopenharmony_ci u16 ctrl = 0; 13878c2ecf20Sopenharmony_ci 13888c2ecf20Sopenharmony_ci if (skge->autoneg == AUTONEG_ENABLE) { 13898c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_1000baseT_Half) 13908c2ecf20Sopenharmony_ci ctrl |= PHY_X_AN_HD; 13918c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_1000baseT_Full) 13928c2ecf20Sopenharmony_ci ctrl |= PHY_X_AN_FD; 13938c2ecf20Sopenharmony_ci 13948c2ecf20Sopenharmony_ci ctrl |= fiber_pause_map[skge->flow_control]; 13958c2ecf20Sopenharmony_ci 13968c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_XMAC_AUNE_ADV, ctrl); 13978c2ecf20Sopenharmony_ci 13988c2ecf20Sopenharmony_ci /* Restart Auto-negotiation */ 13998c2ecf20Sopenharmony_ci ctrl = PHY_CT_ANE | PHY_CT_RE_CFG; 14008c2ecf20Sopenharmony_ci } else { 14018c2ecf20Sopenharmony_ci /* Set DuplexMode in Config register */ 14028c2ecf20Sopenharmony_ci if (skge->duplex == DUPLEX_FULL) 14038c2ecf20Sopenharmony_ci ctrl |= PHY_CT_DUP_MD; 14048c2ecf20Sopenharmony_ci /* 14058c2ecf20Sopenharmony_ci * Do NOT enable Auto-negotiation here. This would hold 14068c2ecf20Sopenharmony_ci * the link down because no IDLEs are transmitted 14078c2ecf20Sopenharmony_ci */ 14088c2ecf20Sopenharmony_ci } 14098c2ecf20Sopenharmony_ci 14108c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_XMAC_CTRL, ctrl); 14118c2ecf20Sopenharmony_ci 14128c2ecf20Sopenharmony_ci /* Poll PHY for status changes */ 14138c2ecf20Sopenharmony_ci mod_timer(&skge->link_timer, jiffies + LINK_HZ); 14148c2ecf20Sopenharmony_ci} 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_cistatic int xm_check_link(struct net_device *dev) 14178c2ecf20Sopenharmony_ci{ 14188c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 14198c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 14208c2ecf20Sopenharmony_ci int port = skge->port; 14218c2ecf20Sopenharmony_ci u16 status; 14228c2ecf20Sopenharmony_ci 14238c2ecf20Sopenharmony_ci /* read twice because of latch */ 14248c2ecf20Sopenharmony_ci xm_phy_read(hw, port, PHY_XMAC_STAT); 14258c2ecf20Sopenharmony_ci status = xm_phy_read(hw, port, PHY_XMAC_STAT); 14268c2ecf20Sopenharmony_ci 14278c2ecf20Sopenharmony_ci if ((status & PHY_ST_LSYNC) == 0) { 14288c2ecf20Sopenharmony_ci xm_link_down(hw, port); 14298c2ecf20Sopenharmony_ci return 0; 14308c2ecf20Sopenharmony_ci } 14318c2ecf20Sopenharmony_ci 14328c2ecf20Sopenharmony_ci if (skge->autoneg == AUTONEG_ENABLE) { 14338c2ecf20Sopenharmony_ci u16 lpa, res; 14348c2ecf20Sopenharmony_ci 14358c2ecf20Sopenharmony_ci if (!(status & PHY_ST_AN_OVER)) 14368c2ecf20Sopenharmony_ci return 0; 14378c2ecf20Sopenharmony_ci 14388c2ecf20Sopenharmony_ci lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP); 14398c2ecf20Sopenharmony_ci if (lpa & PHY_B_AN_RF) { 14408c2ecf20Sopenharmony_ci netdev_notice(dev, "remote fault\n"); 14418c2ecf20Sopenharmony_ci return 0; 14428c2ecf20Sopenharmony_ci } 14438c2ecf20Sopenharmony_ci 14448c2ecf20Sopenharmony_ci res = xm_phy_read(hw, port, PHY_XMAC_RES_ABI); 14458c2ecf20Sopenharmony_ci 14468c2ecf20Sopenharmony_ci /* Check Duplex mismatch */ 14478c2ecf20Sopenharmony_ci switch (res & (PHY_X_RS_HD | PHY_X_RS_FD)) { 14488c2ecf20Sopenharmony_ci case PHY_X_RS_FD: 14498c2ecf20Sopenharmony_ci skge->duplex = DUPLEX_FULL; 14508c2ecf20Sopenharmony_ci break; 14518c2ecf20Sopenharmony_ci case PHY_X_RS_HD: 14528c2ecf20Sopenharmony_ci skge->duplex = DUPLEX_HALF; 14538c2ecf20Sopenharmony_ci break; 14548c2ecf20Sopenharmony_ci default: 14558c2ecf20Sopenharmony_ci netdev_notice(dev, "duplex mismatch\n"); 14568c2ecf20Sopenharmony_ci return 0; 14578c2ecf20Sopenharmony_ci } 14588c2ecf20Sopenharmony_ci 14598c2ecf20Sopenharmony_ci /* We are using IEEE 802.3z/D5.0 Table 37-4 */ 14608c2ecf20Sopenharmony_ci if ((skge->flow_control == FLOW_MODE_SYMMETRIC || 14618c2ecf20Sopenharmony_ci skge->flow_control == FLOW_MODE_SYM_OR_REM) && 14628c2ecf20Sopenharmony_ci (lpa & PHY_X_P_SYM_MD)) 14638c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_SYMMETRIC; 14648c2ecf20Sopenharmony_ci else if (skge->flow_control == FLOW_MODE_SYM_OR_REM && 14658c2ecf20Sopenharmony_ci (lpa & PHY_X_RS_PAUSE) == PHY_X_P_ASYM_MD) 14668c2ecf20Sopenharmony_ci /* Enable PAUSE receive, disable PAUSE transmit */ 14678c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_REM_SEND; 14688c2ecf20Sopenharmony_ci else if (skge->flow_control == FLOW_MODE_LOC_SEND && 14698c2ecf20Sopenharmony_ci (lpa & PHY_X_RS_PAUSE) == PHY_X_P_BOTH_MD) 14708c2ecf20Sopenharmony_ci /* Disable PAUSE receive, enable PAUSE transmit */ 14718c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_LOC_SEND; 14728c2ecf20Sopenharmony_ci else 14738c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_NONE; 14748c2ecf20Sopenharmony_ci 14758c2ecf20Sopenharmony_ci skge->speed = SPEED_1000; 14768c2ecf20Sopenharmony_ci } 14778c2ecf20Sopenharmony_ci 14788c2ecf20Sopenharmony_ci if (!netif_carrier_ok(dev)) 14798c2ecf20Sopenharmony_ci genesis_link_up(skge); 14808c2ecf20Sopenharmony_ci return 1; 14818c2ecf20Sopenharmony_ci} 14828c2ecf20Sopenharmony_ci 14838c2ecf20Sopenharmony_ci/* Poll to check for link coming up. 14848c2ecf20Sopenharmony_ci * 14858c2ecf20Sopenharmony_ci * Since internal PHY is wired to a level triggered pin, can't 14868c2ecf20Sopenharmony_ci * get an interrupt when carrier is detected, need to poll for 14878c2ecf20Sopenharmony_ci * link coming up. 14888c2ecf20Sopenharmony_ci */ 14898c2ecf20Sopenharmony_cistatic void xm_link_timer(struct timer_list *t) 14908c2ecf20Sopenharmony_ci{ 14918c2ecf20Sopenharmony_ci struct skge_port *skge = from_timer(skge, t, link_timer); 14928c2ecf20Sopenharmony_ci struct net_device *dev = skge->netdev; 14938c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 14948c2ecf20Sopenharmony_ci int port = skge->port; 14958c2ecf20Sopenharmony_ci int i; 14968c2ecf20Sopenharmony_ci unsigned long flags; 14978c2ecf20Sopenharmony_ci 14988c2ecf20Sopenharmony_ci if (!netif_running(dev)) 14998c2ecf20Sopenharmony_ci return; 15008c2ecf20Sopenharmony_ci 15018c2ecf20Sopenharmony_ci spin_lock_irqsave(&hw->phy_lock, flags); 15028c2ecf20Sopenharmony_ci 15038c2ecf20Sopenharmony_ci /* 15048c2ecf20Sopenharmony_ci * Verify that the link by checking GPIO register three times. 15058c2ecf20Sopenharmony_ci * This pin has the signal from the link_sync pin connected to it. 15068c2ecf20Sopenharmony_ci */ 15078c2ecf20Sopenharmony_ci for (i = 0; i < 3; i++) { 15088c2ecf20Sopenharmony_ci if (xm_read16(hw, port, XM_GP_PORT) & XM_GP_INP_ASS) 15098c2ecf20Sopenharmony_ci goto link_down; 15108c2ecf20Sopenharmony_ci } 15118c2ecf20Sopenharmony_ci 15128c2ecf20Sopenharmony_ci /* Re-enable interrupt to detect link down */ 15138c2ecf20Sopenharmony_ci if (xm_check_link(dev)) { 15148c2ecf20Sopenharmony_ci u16 msk = xm_read16(hw, port, XM_IMSK); 15158c2ecf20Sopenharmony_ci msk &= ~XM_IS_INP_ASS; 15168c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_IMSK, msk); 15178c2ecf20Sopenharmony_ci xm_read16(hw, port, XM_ISRC); 15188c2ecf20Sopenharmony_ci } else { 15198c2ecf20Sopenharmony_cilink_down: 15208c2ecf20Sopenharmony_ci mod_timer(&skge->link_timer, 15218c2ecf20Sopenharmony_ci round_jiffies(jiffies + LINK_HZ)); 15228c2ecf20Sopenharmony_ci } 15238c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hw->phy_lock, flags); 15248c2ecf20Sopenharmony_ci} 15258c2ecf20Sopenharmony_ci 15268c2ecf20Sopenharmony_cistatic void genesis_mac_init(struct skge_hw *hw, int port) 15278c2ecf20Sopenharmony_ci{ 15288c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 15298c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 15308c2ecf20Sopenharmony_ci int jumbo = hw->dev[port]->mtu > ETH_DATA_LEN; 15318c2ecf20Sopenharmony_ci int i; 15328c2ecf20Sopenharmony_ci u32 r; 15338c2ecf20Sopenharmony_ci static const u8 zero[6] = { 0 }; 15348c2ecf20Sopenharmony_ci 15358c2ecf20Sopenharmony_ci for (i = 0; i < 10; i++) { 15368c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), 15378c2ecf20Sopenharmony_ci MFF_SET_MAC_RST); 15388c2ecf20Sopenharmony_ci if (skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST) 15398c2ecf20Sopenharmony_ci goto reset_ok; 15408c2ecf20Sopenharmony_ci udelay(1); 15418c2ecf20Sopenharmony_ci } 15428c2ecf20Sopenharmony_ci 15438c2ecf20Sopenharmony_ci netdev_warn(dev, "genesis reset failed\n"); 15448c2ecf20Sopenharmony_ci 15458c2ecf20Sopenharmony_ci reset_ok: 15468c2ecf20Sopenharmony_ci /* Unreset the XMAC. */ 15478c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST); 15488c2ecf20Sopenharmony_ci 15498c2ecf20Sopenharmony_ci /* 15508c2ecf20Sopenharmony_ci * Perform additional initialization for external PHYs, 15518c2ecf20Sopenharmony_ci * namely for the 1000baseTX cards that use the XMAC's 15528c2ecf20Sopenharmony_ci * GMII mode. 15538c2ecf20Sopenharmony_ci */ 15548c2ecf20Sopenharmony_ci if (hw->phy_type != SK_PHY_XMAC) { 15558c2ecf20Sopenharmony_ci /* Take external Phy out of reset */ 15568c2ecf20Sopenharmony_ci r = skge_read32(hw, B2_GP_IO); 15578c2ecf20Sopenharmony_ci if (port == 0) 15588c2ecf20Sopenharmony_ci r |= GP_DIR_0|GP_IO_0; 15598c2ecf20Sopenharmony_ci else 15608c2ecf20Sopenharmony_ci r |= GP_DIR_2|GP_IO_2; 15618c2ecf20Sopenharmony_ci 15628c2ecf20Sopenharmony_ci skge_write32(hw, B2_GP_IO, r); 15638c2ecf20Sopenharmony_ci 15648c2ecf20Sopenharmony_ci /* Enable GMII interface */ 15658c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD); 15668c2ecf20Sopenharmony_ci } 15678c2ecf20Sopenharmony_ci 15688c2ecf20Sopenharmony_ci 15698c2ecf20Sopenharmony_ci switch (hw->phy_type) { 15708c2ecf20Sopenharmony_ci case SK_PHY_XMAC: 15718c2ecf20Sopenharmony_ci xm_phy_init(skge); 15728c2ecf20Sopenharmony_ci break; 15738c2ecf20Sopenharmony_ci case SK_PHY_BCOM: 15748c2ecf20Sopenharmony_ci bcom_phy_init(skge); 15758c2ecf20Sopenharmony_ci bcom_check_link(hw, port); 15768c2ecf20Sopenharmony_ci } 15778c2ecf20Sopenharmony_ci 15788c2ecf20Sopenharmony_ci /* Set Station Address */ 15798c2ecf20Sopenharmony_ci xm_outaddr(hw, port, XM_SA, dev->dev_addr); 15808c2ecf20Sopenharmony_ci 15818c2ecf20Sopenharmony_ci /* We don't use match addresses so clear */ 15828c2ecf20Sopenharmony_ci for (i = 1; i < 16; i++) 15838c2ecf20Sopenharmony_ci xm_outaddr(hw, port, XM_EXM(i), zero); 15848c2ecf20Sopenharmony_ci 15858c2ecf20Sopenharmony_ci /* Clear MIB counters */ 15868c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_STAT_CMD, 15878c2ecf20Sopenharmony_ci XM_SC_CLR_RXC | XM_SC_CLR_TXC); 15888c2ecf20Sopenharmony_ci /* Clear two times according to Errata #3 */ 15898c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_STAT_CMD, 15908c2ecf20Sopenharmony_ci XM_SC_CLR_RXC | XM_SC_CLR_TXC); 15918c2ecf20Sopenharmony_ci 15928c2ecf20Sopenharmony_ci /* configure Rx High Water Mark (XM_RX_HI_WM) */ 15938c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_RX_HI_WM, 1450); 15948c2ecf20Sopenharmony_ci 15958c2ecf20Sopenharmony_ci /* We don't need the FCS appended to the packet. */ 15968c2ecf20Sopenharmony_ci r = XM_RX_LENERR_OK | XM_RX_STRIP_FCS; 15978c2ecf20Sopenharmony_ci if (jumbo) 15988c2ecf20Sopenharmony_ci r |= XM_RX_BIG_PK_OK; 15998c2ecf20Sopenharmony_ci 16008c2ecf20Sopenharmony_ci if (skge->duplex == DUPLEX_HALF) { 16018c2ecf20Sopenharmony_ci /* 16028c2ecf20Sopenharmony_ci * If in manual half duplex mode the other side might be in 16038c2ecf20Sopenharmony_ci * full duplex mode, so ignore if a carrier extension is not seen 16048c2ecf20Sopenharmony_ci * on frames received 16058c2ecf20Sopenharmony_ci */ 16068c2ecf20Sopenharmony_ci r |= XM_RX_DIS_CEXT; 16078c2ecf20Sopenharmony_ci } 16088c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_RX_CMD, r); 16098c2ecf20Sopenharmony_ci 16108c2ecf20Sopenharmony_ci /* We want short frames padded to 60 bytes. */ 16118c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_TX_CMD, XM_TX_AUTO_PAD); 16128c2ecf20Sopenharmony_ci 16138c2ecf20Sopenharmony_ci /* Increase threshold for jumbo frames on dual port */ 16148c2ecf20Sopenharmony_ci if (hw->ports > 1 && jumbo) 16158c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_TX_THR, 1020); 16168c2ecf20Sopenharmony_ci else 16178c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_TX_THR, 512); 16188c2ecf20Sopenharmony_ci 16198c2ecf20Sopenharmony_ci /* 16208c2ecf20Sopenharmony_ci * Enable the reception of all error frames. This is is 16218c2ecf20Sopenharmony_ci * a necessary evil due to the design of the XMAC. The 16228c2ecf20Sopenharmony_ci * XMAC's receive FIFO is only 8K in size, however jumbo 16238c2ecf20Sopenharmony_ci * frames can be up to 9000 bytes in length. When bad 16248c2ecf20Sopenharmony_ci * frame filtering is enabled, the XMAC's RX FIFO operates 16258c2ecf20Sopenharmony_ci * in 'store and forward' mode. For this to work, the 16268c2ecf20Sopenharmony_ci * entire frame has to fit into the FIFO, but that means 16278c2ecf20Sopenharmony_ci * that jumbo frames larger than 8192 bytes will be 16288c2ecf20Sopenharmony_ci * truncated. Disabling all bad frame filtering causes 16298c2ecf20Sopenharmony_ci * the RX FIFO to operate in streaming mode, in which 16308c2ecf20Sopenharmony_ci * case the XMAC will start transferring frames out of the 16318c2ecf20Sopenharmony_ci * RX FIFO as soon as the FIFO threshold is reached. 16328c2ecf20Sopenharmony_ci */ 16338c2ecf20Sopenharmony_ci xm_write32(hw, port, XM_MODE, XM_DEF_MODE); 16348c2ecf20Sopenharmony_ci 16358c2ecf20Sopenharmony_ci 16368c2ecf20Sopenharmony_ci /* 16378c2ecf20Sopenharmony_ci * Initialize the Receive Counter Event Mask (XM_RX_EV_MSK) 16388c2ecf20Sopenharmony_ci * - Enable all bits excepting 'Octets Rx OK Low CntOv' 16398c2ecf20Sopenharmony_ci * and 'Octets Rx OK Hi Cnt Ov'. 16408c2ecf20Sopenharmony_ci */ 16418c2ecf20Sopenharmony_ci xm_write32(hw, port, XM_RX_EV_MSK, XMR_DEF_MSK); 16428c2ecf20Sopenharmony_ci 16438c2ecf20Sopenharmony_ci /* 16448c2ecf20Sopenharmony_ci * Initialize the Transmit Counter Event Mask (XM_TX_EV_MSK) 16458c2ecf20Sopenharmony_ci * - Enable all bits excepting 'Octets Tx OK Low CntOv' 16468c2ecf20Sopenharmony_ci * and 'Octets Tx OK Hi Cnt Ov'. 16478c2ecf20Sopenharmony_ci */ 16488c2ecf20Sopenharmony_ci xm_write32(hw, port, XM_TX_EV_MSK, XMT_DEF_MSK); 16498c2ecf20Sopenharmony_ci 16508c2ecf20Sopenharmony_ci /* Configure MAC arbiter */ 16518c2ecf20Sopenharmony_ci skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR); 16528c2ecf20Sopenharmony_ci 16538c2ecf20Sopenharmony_ci /* configure timeout values */ 16548c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_TOINI_RX1, 72); 16558c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_TOINI_RX2, 72); 16568c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_TOINI_TX1, 72); 16578c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_TOINI_TX2, 72); 16588c2ecf20Sopenharmony_ci 16598c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_RCINI_RX1, 0); 16608c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_RCINI_RX2, 0); 16618c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_RCINI_TX1, 0); 16628c2ecf20Sopenharmony_ci skge_write8(hw, B3_MA_RCINI_TX2, 0); 16638c2ecf20Sopenharmony_ci 16648c2ecf20Sopenharmony_ci /* Configure Rx MAC FIFO */ 16658c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_CLR); 16668c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT); 16678c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_ENA_OP_MD); 16688c2ecf20Sopenharmony_ci 16698c2ecf20Sopenharmony_ci /* Configure Tx MAC FIFO */ 16708c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_CLR); 16718c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF); 16728c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_ENA_OP_MD); 16738c2ecf20Sopenharmony_ci 16748c2ecf20Sopenharmony_ci if (jumbo) { 16758c2ecf20Sopenharmony_ci /* Enable frame flushing if jumbo frames used */ 16768c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_FLUSH); 16778c2ecf20Sopenharmony_ci } else { 16788c2ecf20Sopenharmony_ci /* enable timeout timers if normal frames */ 16798c2ecf20Sopenharmony_ci skge_write16(hw, B3_PA_CTRL, 16808c2ecf20Sopenharmony_ci (port == 0) ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2); 16818c2ecf20Sopenharmony_ci } 16828c2ecf20Sopenharmony_ci} 16838c2ecf20Sopenharmony_ci 16848c2ecf20Sopenharmony_cistatic void genesis_stop(struct skge_port *skge) 16858c2ecf20Sopenharmony_ci{ 16868c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 16878c2ecf20Sopenharmony_ci int port = skge->port; 16888c2ecf20Sopenharmony_ci unsigned retries = 1000; 16898c2ecf20Sopenharmony_ci u16 cmd; 16908c2ecf20Sopenharmony_ci 16918c2ecf20Sopenharmony_ci /* Disable Tx and Rx */ 16928c2ecf20Sopenharmony_ci cmd = xm_read16(hw, port, XM_MMU_CMD); 16938c2ecf20Sopenharmony_ci cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX); 16948c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_MMU_CMD, cmd); 16958c2ecf20Sopenharmony_ci 16968c2ecf20Sopenharmony_ci genesis_reset(hw, port); 16978c2ecf20Sopenharmony_ci 16988c2ecf20Sopenharmony_ci /* Clear Tx packet arbiter timeout IRQ */ 16998c2ecf20Sopenharmony_ci skge_write16(hw, B3_PA_CTRL, 17008c2ecf20Sopenharmony_ci port == 0 ? PA_CLR_TO_TX1 : PA_CLR_TO_TX2); 17018c2ecf20Sopenharmony_ci 17028c2ecf20Sopenharmony_ci /* Reset the MAC */ 17038c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST); 17048c2ecf20Sopenharmony_ci do { 17058c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST); 17068c2ecf20Sopenharmony_ci if (!(skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST)) 17078c2ecf20Sopenharmony_ci break; 17088c2ecf20Sopenharmony_ci } while (--retries > 0); 17098c2ecf20Sopenharmony_ci 17108c2ecf20Sopenharmony_ci /* For external PHYs there must be special handling */ 17118c2ecf20Sopenharmony_ci if (hw->phy_type != SK_PHY_XMAC) { 17128c2ecf20Sopenharmony_ci u32 reg = skge_read32(hw, B2_GP_IO); 17138c2ecf20Sopenharmony_ci if (port == 0) { 17148c2ecf20Sopenharmony_ci reg |= GP_DIR_0; 17158c2ecf20Sopenharmony_ci reg &= ~GP_IO_0; 17168c2ecf20Sopenharmony_ci } else { 17178c2ecf20Sopenharmony_ci reg |= GP_DIR_2; 17188c2ecf20Sopenharmony_ci reg &= ~GP_IO_2; 17198c2ecf20Sopenharmony_ci } 17208c2ecf20Sopenharmony_ci skge_write32(hw, B2_GP_IO, reg); 17218c2ecf20Sopenharmony_ci skge_read32(hw, B2_GP_IO); 17228c2ecf20Sopenharmony_ci } 17238c2ecf20Sopenharmony_ci 17248c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_MMU_CMD, 17258c2ecf20Sopenharmony_ci xm_read16(hw, port, XM_MMU_CMD) 17268c2ecf20Sopenharmony_ci & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX)); 17278c2ecf20Sopenharmony_ci 17288c2ecf20Sopenharmony_ci xm_read16(hw, port, XM_MMU_CMD); 17298c2ecf20Sopenharmony_ci} 17308c2ecf20Sopenharmony_ci 17318c2ecf20Sopenharmony_ci 17328c2ecf20Sopenharmony_cistatic void genesis_get_stats(struct skge_port *skge, u64 *data) 17338c2ecf20Sopenharmony_ci{ 17348c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 17358c2ecf20Sopenharmony_ci int port = skge->port; 17368c2ecf20Sopenharmony_ci int i; 17378c2ecf20Sopenharmony_ci unsigned long timeout = jiffies + HZ; 17388c2ecf20Sopenharmony_ci 17398c2ecf20Sopenharmony_ci xm_write16(hw, port, 17408c2ecf20Sopenharmony_ci XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC); 17418c2ecf20Sopenharmony_ci 17428c2ecf20Sopenharmony_ci /* wait for update to complete */ 17438c2ecf20Sopenharmony_ci while (xm_read16(hw, port, XM_STAT_CMD) 17448c2ecf20Sopenharmony_ci & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) { 17458c2ecf20Sopenharmony_ci if (time_after(jiffies, timeout)) 17468c2ecf20Sopenharmony_ci break; 17478c2ecf20Sopenharmony_ci udelay(10); 17488c2ecf20Sopenharmony_ci } 17498c2ecf20Sopenharmony_ci 17508c2ecf20Sopenharmony_ci /* special case for 64 bit octet counter */ 17518c2ecf20Sopenharmony_ci data[0] = (u64) xm_read32(hw, port, XM_TXO_OK_HI) << 32 17528c2ecf20Sopenharmony_ci | xm_read32(hw, port, XM_TXO_OK_LO); 17538c2ecf20Sopenharmony_ci data[1] = (u64) xm_read32(hw, port, XM_RXO_OK_HI) << 32 17548c2ecf20Sopenharmony_ci | xm_read32(hw, port, XM_RXO_OK_LO); 17558c2ecf20Sopenharmony_ci 17568c2ecf20Sopenharmony_ci for (i = 2; i < ARRAY_SIZE(skge_stats); i++) 17578c2ecf20Sopenharmony_ci data[i] = xm_read32(hw, port, skge_stats[i].xmac_offset); 17588c2ecf20Sopenharmony_ci} 17598c2ecf20Sopenharmony_ci 17608c2ecf20Sopenharmony_cistatic void genesis_mac_intr(struct skge_hw *hw, int port) 17618c2ecf20Sopenharmony_ci{ 17628c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 17638c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 17648c2ecf20Sopenharmony_ci u16 status = xm_read16(hw, port, XM_ISRC); 17658c2ecf20Sopenharmony_ci 17668c2ecf20Sopenharmony_ci netif_printk(skge, intr, KERN_DEBUG, skge->netdev, 17678c2ecf20Sopenharmony_ci "mac interrupt status 0x%x\n", status); 17688c2ecf20Sopenharmony_ci 17698c2ecf20Sopenharmony_ci if (hw->phy_type == SK_PHY_XMAC && (status & XM_IS_INP_ASS)) { 17708c2ecf20Sopenharmony_ci xm_link_down(hw, port); 17718c2ecf20Sopenharmony_ci mod_timer(&skge->link_timer, jiffies + 1); 17728c2ecf20Sopenharmony_ci } 17738c2ecf20Sopenharmony_ci 17748c2ecf20Sopenharmony_ci if (status & XM_IS_TXF_UR) { 17758c2ecf20Sopenharmony_ci xm_write32(hw, port, XM_MODE, XM_MD_FTF); 17768c2ecf20Sopenharmony_ci ++dev->stats.tx_fifo_errors; 17778c2ecf20Sopenharmony_ci } 17788c2ecf20Sopenharmony_ci} 17798c2ecf20Sopenharmony_ci 17808c2ecf20Sopenharmony_cistatic void genesis_link_up(struct skge_port *skge) 17818c2ecf20Sopenharmony_ci{ 17828c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 17838c2ecf20Sopenharmony_ci int port = skge->port; 17848c2ecf20Sopenharmony_ci u16 cmd, msk; 17858c2ecf20Sopenharmony_ci u32 mode; 17868c2ecf20Sopenharmony_ci 17878c2ecf20Sopenharmony_ci cmd = xm_read16(hw, port, XM_MMU_CMD); 17888c2ecf20Sopenharmony_ci 17898c2ecf20Sopenharmony_ci /* 17908c2ecf20Sopenharmony_ci * enabling pause frame reception is required for 1000BT 17918c2ecf20Sopenharmony_ci * because the XMAC is not reset if the link is going down 17928c2ecf20Sopenharmony_ci */ 17938c2ecf20Sopenharmony_ci if (skge->flow_status == FLOW_STAT_NONE || 17948c2ecf20Sopenharmony_ci skge->flow_status == FLOW_STAT_LOC_SEND) 17958c2ecf20Sopenharmony_ci /* Disable Pause Frame Reception */ 17968c2ecf20Sopenharmony_ci cmd |= XM_MMU_IGN_PF; 17978c2ecf20Sopenharmony_ci else 17988c2ecf20Sopenharmony_ci /* Enable Pause Frame Reception */ 17998c2ecf20Sopenharmony_ci cmd &= ~XM_MMU_IGN_PF; 18008c2ecf20Sopenharmony_ci 18018c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_MMU_CMD, cmd); 18028c2ecf20Sopenharmony_ci 18038c2ecf20Sopenharmony_ci mode = xm_read32(hw, port, XM_MODE); 18048c2ecf20Sopenharmony_ci if (skge->flow_status == FLOW_STAT_SYMMETRIC || 18058c2ecf20Sopenharmony_ci skge->flow_status == FLOW_STAT_LOC_SEND) { 18068c2ecf20Sopenharmony_ci /* 18078c2ecf20Sopenharmony_ci * Configure Pause Frame Generation 18088c2ecf20Sopenharmony_ci * Use internal and external Pause Frame Generation. 18098c2ecf20Sopenharmony_ci * Sending pause frames is edge triggered. 18108c2ecf20Sopenharmony_ci * Send a Pause frame with the maximum pause time if 18118c2ecf20Sopenharmony_ci * internal oder external FIFO full condition occurs. 18128c2ecf20Sopenharmony_ci * Send a zero pause time frame to re-start transmission. 18138c2ecf20Sopenharmony_ci */ 18148c2ecf20Sopenharmony_ci /* XM_PAUSE_DA = '010000C28001' (default) */ 18158c2ecf20Sopenharmony_ci /* XM_MAC_PTIME = 0xffff (maximum) */ 18168c2ecf20Sopenharmony_ci /* remember this value is defined in big endian (!) */ 18178c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_MAC_PTIME, 0xffff); 18188c2ecf20Sopenharmony_ci 18198c2ecf20Sopenharmony_ci mode |= XM_PAUSE_MODE; 18208c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE); 18218c2ecf20Sopenharmony_ci } else { 18228c2ecf20Sopenharmony_ci /* 18238c2ecf20Sopenharmony_ci * disable pause frame generation is required for 1000BT 18248c2ecf20Sopenharmony_ci * because the XMAC is not reset if the link is going down 18258c2ecf20Sopenharmony_ci */ 18268c2ecf20Sopenharmony_ci /* Disable Pause Mode in Mode Register */ 18278c2ecf20Sopenharmony_ci mode &= ~XM_PAUSE_MODE; 18288c2ecf20Sopenharmony_ci 18298c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE); 18308c2ecf20Sopenharmony_ci } 18318c2ecf20Sopenharmony_ci 18328c2ecf20Sopenharmony_ci xm_write32(hw, port, XM_MODE, mode); 18338c2ecf20Sopenharmony_ci 18348c2ecf20Sopenharmony_ci /* Turn on detection of Tx underrun */ 18358c2ecf20Sopenharmony_ci msk = xm_read16(hw, port, XM_IMSK); 18368c2ecf20Sopenharmony_ci msk &= ~XM_IS_TXF_UR; 18378c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_IMSK, msk); 18388c2ecf20Sopenharmony_ci 18398c2ecf20Sopenharmony_ci xm_read16(hw, port, XM_ISRC); 18408c2ecf20Sopenharmony_ci 18418c2ecf20Sopenharmony_ci /* get MMU Command Reg. */ 18428c2ecf20Sopenharmony_ci cmd = xm_read16(hw, port, XM_MMU_CMD); 18438c2ecf20Sopenharmony_ci if (hw->phy_type != SK_PHY_XMAC && skge->duplex == DUPLEX_FULL) 18448c2ecf20Sopenharmony_ci cmd |= XM_MMU_GMII_FD; 18458c2ecf20Sopenharmony_ci 18468c2ecf20Sopenharmony_ci /* 18478c2ecf20Sopenharmony_ci * Workaround BCOM Errata (#10523) for all BCom Phys 18488c2ecf20Sopenharmony_ci * Enable Power Management after link up 18498c2ecf20Sopenharmony_ci */ 18508c2ecf20Sopenharmony_ci if (hw->phy_type == SK_PHY_BCOM) { 18518c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, 18528c2ecf20Sopenharmony_ci xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL) 18538c2ecf20Sopenharmony_ci & ~PHY_B_AC_DIS_PM); 18548c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK); 18558c2ecf20Sopenharmony_ci } 18568c2ecf20Sopenharmony_ci 18578c2ecf20Sopenharmony_ci /* enable Rx/Tx */ 18588c2ecf20Sopenharmony_ci xm_write16(hw, port, XM_MMU_CMD, 18598c2ecf20Sopenharmony_ci cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX); 18608c2ecf20Sopenharmony_ci skge_link_up(skge); 18618c2ecf20Sopenharmony_ci} 18628c2ecf20Sopenharmony_ci 18638c2ecf20Sopenharmony_ci 18648c2ecf20Sopenharmony_cistatic inline void bcom_phy_intr(struct skge_port *skge) 18658c2ecf20Sopenharmony_ci{ 18668c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 18678c2ecf20Sopenharmony_ci int port = skge->port; 18688c2ecf20Sopenharmony_ci u16 isrc; 18698c2ecf20Sopenharmony_ci 18708c2ecf20Sopenharmony_ci isrc = xm_phy_read(hw, port, PHY_BCOM_INT_STAT); 18718c2ecf20Sopenharmony_ci netif_printk(skge, intr, KERN_DEBUG, skge->netdev, 18728c2ecf20Sopenharmony_ci "phy interrupt status 0x%x\n", isrc); 18738c2ecf20Sopenharmony_ci 18748c2ecf20Sopenharmony_ci if (isrc & PHY_B_IS_PSE) 18758c2ecf20Sopenharmony_ci pr_err("%s: uncorrectable pair swap error\n", 18768c2ecf20Sopenharmony_ci hw->dev[port]->name); 18778c2ecf20Sopenharmony_ci 18788c2ecf20Sopenharmony_ci /* Workaround BCom Errata: 18798c2ecf20Sopenharmony_ci * enable and disable loopback mode if "NO HCD" occurs. 18808c2ecf20Sopenharmony_ci */ 18818c2ecf20Sopenharmony_ci if (isrc & PHY_B_IS_NO_HDCL) { 18828c2ecf20Sopenharmony_ci u16 ctrl = xm_phy_read(hw, port, PHY_BCOM_CTRL); 18838c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_CTRL, 18848c2ecf20Sopenharmony_ci ctrl | PHY_CT_LOOP); 18858c2ecf20Sopenharmony_ci xm_phy_write(hw, port, PHY_BCOM_CTRL, 18868c2ecf20Sopenharmony_ci ctrl & ~PHY_CT_LOOP); 18878c2ecf20Sopenharmony_ci } 18888c2ecf20Sopenharmony_ci 18898c2ecf20Sopenharmony_ci if (isrc & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE)) 18908c2ecf20Sopenharmony_ci bcom_check_link(hw, port); 18918c2ecf20Sopenharmony_ci 18928c2ecf20Sopenharmony_ci} 18938c2ecf20Sopenharmony_ci 18948c2ecf20Sopenharmony_cistatic int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val) 18958c2ecf20Sopenharmony_ci{ 18968c2ecf20Sopenharmony_ci int i; 18978c2ecf20Sopenharmony_ci 18988c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_SMI_DATA, val); 18998c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_SMI_CTRL, 19008c2ecf20Sopenharmony_ci GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg)); 19018c2ecf20Sopenharmony_ci for (i = 0; i < PHY_RETRIES; i++) { 19028c2ecf20Sopenharmony_ci udelay(1); 19038c2ecf20Sopenharmony_ci 19048c2ecf20Sopenharmony_ci if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY)) 19058c2ecf20Sopenharmony_ci return 0; 19068c2ecf20Sopenharmony_ci } 19078c2ecf20Sopenharmony_ci 19088c2ecf20Sopenharmony_ci pr_warn("%s: phy write timeout\n", hw->dev[port]->name); 19098c2ecf20Sopenharmony_ci return -EIO; 19108c2ecf20Sopenharmony_ci} 19118c2ecf20Sopenharmony_ci 19128c2ecf20Sopenharmony_cistatic int __gm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val) 19138c2ecf20Sopenharmony_ci{ 19148c2ecf20Sopenharmony_ci int i; 19158c2ecf20Sopenharmony_ci 19168c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_SMI_CTRL, 19178c2ecf20Sopenharmony_ci GM_SMI_CT_PHY_AD(hw->phy_addr) 19188c2ecf20Sopenharmony_ci | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD); 19198c2ecf20Sopenharmony_ci 19208c2ecf20Sopenharmony_ci for (i = 0; i < PHY_RETRIES; i++) { 19218c2ecf20Sopenharmony_ci udelay(1); 19228c2ecf20Sopenharmony_ci if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL) 19238c2ecf20Sopenharmony_ci goto ready; 19248c2ecf20Sopenharmony_ci } 19258c2ecf20Sopenharmony_ci 19268c2ecf20Sopenharmony_ci return -ETIMEDOUT; 19278c2ecf20Sopenharmony_ci ready: 19288c2ecf20Sopenharmony_ci *val = gma_read16(hw, port, GM_SMI_DATA); 19298c2ecf20Sopenharmony_ci return 0; 19308c2ecf20Sopenharmony_ci} 19318c2ecf20Sopenharmony_ci 19328c2ecf20Sopenharmony_cistatic u16 gm_phy_read(struct skge_hw *hw, int port, u16 reg) 19338c2ecf20Sopenharmony_ci{ 19348c2ecf20Sopenharmony_ci u16 v = 0; 19358c2ecf20Sopenharmony_ci if (__gm_phy_read(hw, port, reg, &v)) 19368c2ecf20Sopenharmony_ci pr_warn("%s: phy read timeout\n", hw->dev[port]->name); 19378c2ecf20Sopenharmony_ci return v; 19388c2ecf20Sopenharmony_ci} 19398c2ecf20Sopenharmony_ci 19408c2ecf20Sopenharmony_ci/* Marvell Phy Initialization */ 19418c2ecf20Sopenharmony_cistatic void yukon_init(struct skge_hw *hw, int port) 19428c2ecf20Sopenharmony_ci{ 19438c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(hw->dev[port]); 19448c2ecf20Sopenharmony_ci u16 ctrl, ct1000, adv; 19458c2ecf20Sopenharmony_ci 19468c2ecf20Sopenharmony_ci if (skge->autoneg == AUTONEG_ENABLE) { 19478c2ecf20Sopenharmony_ci u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL); 19488c2ecf20Sopenharmony_ci 19498c2ecf20Sopenharmony_ci ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK | 19508c2ecf20Sopenharmony_ci PHY_M_EC_MAC_S_MSK); 19518c2ecf20Sopenharmony_ci ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ); 19528c2ecf20Sopenharmony_ci 19538c2ecf20Sopenharmony_ci ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1); 19548c2ecf20Sopenharmony_ci 19558c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl); 19568c2ecf20Sopenharmony_ci } 19578c2ecf20Sopenharmony_ci 19588c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL); 19598c2ecf20Sopenharmony_ci if (skge->autoneg == AUTONEG_DISABLE) 19608c2ecf20Sopenharmony_ci ctrl &= ~PHY_CT_ANE; 19618c2ecf20Sopenharmony_ci 19628c2ecf20Sopenharmony_ci ctrl |= PHY_CT_RESET; 19638c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); 19648c2ecf20Sopenharmony_ci 19658c2ecf20Sopenharmony_ci ctrl = 0; 19668c2ecf20Sopenharmony_ci ct1000 = 0; 19678c2ecf20Sopenharmony_ci adv = PHY_AN_CSMA; 19688c2ecf20Sopenharmony_ci 19698c2ecf20Sopenharmony_ci if (skge->autoneg == AUTONEG_ENABLE) { 19708c2ecf20Sopenharmony_ci if (hw->copper) { 19718c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_1000baseT_Full) 19728c2ecf20Sopenharmony_ci ct1000 |= PHY_M_1000C_AFD; 19738c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_1000baseT_Half) 19748c2ecf20Sopenharmony_ci ct1000 |= PHY_M_1000C_AHD; 19758c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_100baseT_Full) 19768c2ecf20Sopenharmony_ci adv |= PHY_M_AN_100_FD; 19778c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_100baseT_Half) 19788c2ecf20Sopenharmony_ci adv |= PHY_M_AN_100_HD; 19798c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_10baseT_Full) 19808c2ecf20Sopenharmony_ci adv |= PHY_M_AN_10_FD; 19818c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_10baseT_Half) 19828c2ecf20Sopenharmony_ci adv |= PHY_M_AN_10_HD; 19838c2ecf20Sopenharmony_ci 19848c2ecf20Sopenharmony_ci /* Set Flow-control capabilities */ 19858c2ecf20Sopenharmony_ci adv |= phy_pause_map[skge->flow_control]; 19868c2ecf20Sopenharmony_ci } else { 19878c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_1000baseT_Full) 19888c2ecf20Sopenharmony_ci adv |= PHY_M_AN_1000X_AFD; 19898c2ecf20Sopenharmony_ci if (skge->advertising & ADVERTISED_1000baseT_Half) 19908c2ecf20Sopenharmony_ci adv |= PHY_M_AN_1000X_AHD; 19918c2ecf20Sopenharmony_ci 19928c2ecf20Sopenharmony_ci adv |= fiber_pause_map[skge->flow_control]; 19938c2ecf20Sopenharmony_ci } 19948c2ecf20Sopenharmony_ci 19958c2ecf20Sopenharmony_ci /* Restart Auto-negotiation */ 19968c2ecf20Sopenharmony_ci ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG; 19978c2ecf20Sopenharmony_ci } else { 19988c2ecf20Sopenharmony_ci /* forced speed/duplex settings */ 19998c2ecf20Sopenharmony_ci ct1000 = PHY_M_1000C_MSE; 20008c2ecf20Sopenharmony_ci 20018c2ecf20Sopenharmony_ci if (skge->duplex == DUPLEX_FULL) 20028c2ecf20Sopenharmony_ci ctrl |= PHY_CT_DUP_MD; 20038c2ecf20Sopenharmony_ci 20048c2ecf20Sopenharmony_ci switch (skge->speed) { 20058c2ecf20Sopenharmony_ci case SPEED_1000: 20068c2ecf20Sopenharmony_ci ctrl |= PHY_CT_SP1000; 20078c2ecf20Sopenharmony_ci break; 20088c2ecf20Sopenharmony_ci case SPEED_100: 20098c2ecf20Sopenharmony_ci ctrl |= PHY_CT_SP100; 20108c2ecf20Sopenharmony_ci break; 20118c2ecf20Sopenharmony_ci } 20128c2ecf20Sopenharmony_ci 20138c2ecf20Sopenharmony_ci ctrl |= PHY_CT_RESET; 20148c2ecf20Sopenharmony_ci } 20158c2ecf20Sopenharmony_ci 20168c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000); 20178c2ecf20Sopenharmony_ci 20188c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv); 20198c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); 20208c2ecf20Sopenharmony_ci 20218c2ecf20Sopenharmony_ci /* Enable phy interrupt on autonegotiation complete (or link up) */ 20228c2ecf20Sopenharmony_ci if (skge->autoneg == AUTONEG_ENABLE) 20238c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_MSK); 20248c2ecf20Sopenharmony_ci else 20258c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK); 20268c2ecf20Sopenharmony_ci} 20278c2ecf20Sopenharmony_ci 20288c2ecf20Sopenharmony_cistatic void yukon_reset(struct skge_hw *hw, int port) 20298c2ecf20Sopenharmony_ci{ 20308c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */ 20318c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */ 20328c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H2, 0); 20338c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H3, 0); 20348c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H4, 0); 20358c2ecf20Sopenharmony_ci 20368c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_RX_CTRL, 20378c2ecf20Sopenharmony_ci gma_read16(hw, port, GM_RX_CTRL) 20388c2ecf20Sopenharmony_ci | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); 20398c2ecf20Sopenharmony_ci} 20408c2ecf20Sopenharmony_ci 20418c2ecf20Sopenharmony_ci/* Apparently, early versions of Yukon-Lite had wrong chip_id? */ 20428c2ecf20Sopenharmony_cistatic int is_yukon_lite_a0(struct skge_hw *hw) 20438c2ecf20Sopenharmony_ci{ 20448c2ecf20Sopenharmony_ci u32 reg; 20458c2ecf20Sopenharmony_ci int ret; 20468c2ecf20Sopenharmony_ci 20478c2ecf20Sopenharmony_ci if (hw->chip_id != CHIP_ID_YUKON) 20488c2ecf20Sopenharmony_ci return 0; 20498c2ecf20Sopenharmony_ci 20508c2ecf20Sopenharmony_ci reg = skge_read32(hw, B2_FAR); 20518c2ecf20Sopenharmony_ci skge_write8(hw, B2_FAR + 3, 0xff); 20528c2ecf20Sopenharmony_ci ret = (skge_read8(hw, B2_FAR + 3) != 0); 20538c2ecf20Sopenharmony_ci skge_write32(hw, B2_FAR, reg); 20548c2ecf20Sopenharmony_ci return ret; 20558c2ecf20Sopenharmony_ci} 20568c2ecf20Sopenharmony_ci 20578c2ecf20Sopenharmony_cistatic void yukon_mac_init(struct skge_hw *hw, int port) 20588c2ecf20Sopenharmony_ci{ 20598c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(hw->dev[port]); 20608c2ecf20Sopenharmony_ci int i; 20618c2ecf20Sopenharmony_ci u32 reg; 20628c2ecf20Sopenharmony_ci const u8 *addr = hw->dev[port]->dev_addr; 20638c2ecf20Sopenharmony_ci 20648c2ecf20Sopenharmony_ci /* WA code for COMA mode -- set PHY reset */ 20658c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_LITE && 20668c2ecf20Sopenharmony_ci hw->chip_rev >= CHIP_REV_YU_LITE_A3) { 20678c2ecf20Sopenharmony_ci reg = skge_read32(hw, B2_GP_IO); 20688c2ecf20Sopenharmony_ci reg |= GP_DIR_9 | GP_IO_9; 20698c2ecf20Sopenharmony_ci skge_write32(hw, B2_GP_IO, reg); 20708c2ecf20Sopenharmony_ci } 20718c2ecf20Sopenharmony_ci 20728c2ecf20Sopenharmony_ci /* hard reset */ 20738c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); 20748c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET); 20758c2ecf20Sopenharmony_ci 20768c2ecf20Sopenharmony_ci /* WA code for COMA mode -- clear PHY reset */ 20778c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_LITE && 20788c2ecf20Sopenharmony_ci hw->chip_rev >= CHIP_REV_YU_LITE_A3) { 20798c2ecf20Sopenharmony_ci reg = skge_read32(hw, B2_GP_IO); 20808c2ecf20Sopenharmony_ci reg |= GP_DIR_9; 20818c2ecf20Sopenharmony_ci reg &= ~GP_IO_9; 20828c2ecf20Sopenharmony_ci skge_write32(hw, B2_GP_IO, reg); 20838c2ecf20Sopenharmony_ci } 20848c2ecf20Sopenharmony_ci 20858c2ecf20Sopenharmony_ci /* Set hardware config mode */ 20868c2ecf20Sopenharmony_ci reg = GPC_INT_POL_HI | GPC_DIS_FC | GPC_DIS_SLEEP | 20878c2ecf20Sopenharmony_ci GPC_ENA_XC | GPC_ANEG_ADV_ALL_M | GPC_ENA_PAUSE; 20888c2ecf20Sopenharmony_ci reg |= hw->copper ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB; 20898c2ecf20Sopenharmony_ci 20908c2ecf20Sopenharmony_ci /* Clear GMC reset */ 20918c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_SET); 20928c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_CLR); 20938c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR); 20948c2ecf20Sopenharmony_ci 20958c2ecf20Sopenharmony_ci if (skge->autoneg == AUTONEG_DISABLE) { 20968c2ecf20Sopenharmony_ci reg = GM_GPCR_AU_ALL_DIS; 20978c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, 20988c2ecf20Sopenharmony_ci gma_read16(hw, port, GM_GP_CTRL) | reg); 20998c2ecf20Sopenharmony_ci 21008c2ecf20Sopenharmony_ci switch (skge->speed) { 21018c2ecf20Sopenharmony_ci case SPEED_1000: 21028c2ecf20Sopenharmony_ci reg &= ~GM_GPCR_SPEED_100; 21038c2ecf20Sopenharmony_ci reg |= GM_GPCR_SPEED_1000; 21048c2ecf20Sopenharmony_ci break; 21058c2ecf20Sopenharmony_ci case SPEED_100: 21068c2ecf20Sopenharmony_ci reg &= ~GM_GPCR_SPEED_1000; 21078c2ecf20Sopenharmony_ci reg |= GM_GPCR_SPEED_100; 21088c2ecf20Sopenharmony_ci break; 21098c2ecf20Sopenharmony_ci case SPEED_10: 21108c2ecf20Sopenharmony_ci reg &= ~(GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100); 21118c2ecf20Sopenharmony_ci break; 21128c2ecf20Sopenharmony_ci } 21138c2ecf20Sopenharmony_ci 21148c2ecf20Sopenharmony_ci if (skge->duplex == DUPLEX_FULL) 21158c2ecf20Sopenharmony_ci reg |= GM_GPCR_DUP_FULL; 21168c2ecf20Sopenharmony_ci } else 21178c2ecf20Sopenharmony_ci reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL; 21188c2ecf20Sopenharmony_ci 21198c2ecf20Sopenharmony_ci switch (skge->flow_control) { 21208c2ecf20Sopenharmony_ci case FLOW_MODE_NONE: 21218c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); 21228c2ecf20Sopenharmony_ci reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; 21238c2ecf20Sopenharmony_ci break; 21248c2ecf20Sopenharmony_ci case FLOW_MODE_LOC_SEND: 21258c2ecf20Sopenharmony_ci /* disable Rx flow-control */ 21268c2ecf20Sopenharmony_ci reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; 21278c2ecf20Sopenharmony_ci break; 21288c2ecf20Sopenharmony_ci case FLOW_MODE_SYMMETRIC: 21298c2ecf20Sopenharmony_ci case FLOW_MODE_SYM_OR_REM: 21308c2ecf20Sopenharmony_ci /* enable Tx & Rx flow-control */ 21318c2ecf20Sopenharmony_ci break; 21328c2ecf20Sopenharmony_ci } 21338c2ecf20Sopenharmony_ci 21348c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, reg); 21358c2ecf20Sopenharmony_ci skge_read16(hw, SK_REG(port, GMAC_IRQ_SRC)); 21368c2ecf20Sopenharmony_ci 21378c2ecf20Sopenharmony_ci yukon_init(hw, port); 21388c2ecf20Sopenharmony_ci 21398c2ecf20Sopenharmony_ci /* MIB clear */ 21408c2ecf20Sopenharmony_ci reg = gma_read16(hw, port, GM_PHY_ADDR); 21418c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR); 21428c2ecf20Sopenharmony_ci 21438c2ecf20Sopenharmony_ci for (i = 0; i < GM_MIB_CNT_SIZE; i++) 21448c2ecf20Sopenharmony_ci gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i); 21458c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_PHY_ADDR, reg); 21468c2ecf20Sopenharmony_ci 21478c2ecf20Sopenharmony_ci /* transmit control */ 21488c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF)); 21498c2ecf20Sopenharmony_ci 21508c2ecf20Sopenharmony_ci /* receive control reg: unicast + multicast + no FCS */ 21518c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_RX_CTRL, 21528c2ecf20Sopenharmony_ci GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA); 21538c2ecf20Sopenharmony_ci 21548c2ecf20Sopenharmony_ci /* transmit flow control */ 21558c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff); 21568c2ecf20Sopenharmony_ci 21578c2ecf20Sopenharmony_ci /* transmit parameter */ 21588c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_TX_PARAM, 21598c2ecf20Sopenharmony_ci TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) | 21608c2ecf20Sopenharmony_ci TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) | 21618c2ecf20Sopenharmony_ci TX_IPG_JAM_DATA(TX_IPG_JAM_DEF)); 21628c2ecf20Sopenharmony_ci 21638c2ecf20Sopenharmony_ci /* configure the Serial Mode Register */ 21648c2ecf20Sopenharmony_ci reg = DATA_BLIND_VAL(DATA_BLIND_DEF) 21658c2ecf20Sopenharmony_ci | GM_SMOD_VLAN_ENA 21668c2ecf20Sopenharmony_ci | IPG_DATA_VAL(IPG_DATA_DEF); 21678c2ecf20Sopenharmony_ci 21688c2ecf20Sopenharmony_ci if (hw->dev[port]->mtu > ETH_DATA_LEN) 21698c2ecf20Sopenharmony_ci reg |= GM_SMOD_JUMBO_ENA; 21708c2ecf20Sopenharmony_ci 21718c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_SERIAL_MODE, reg); 21728c2ecf20Sopenharmony_ci 21738c2ecf20Sopenharmony_ci /* physical address: used for pause frames */ 21748c2ecf20Sopenharmony_ci gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr); 21758c2ecf20Sopenharmony_ci /* virtual address for data */ 21768c2ecf20Sopenharmony_ci gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr); 21778c2ecf20Sopenharmony_ci 21788c2ecf20Sopenharmony_ci /* enable interrupt mask for counter overflows */ 21798c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_TX_IRQ_MSK, 0); 21808c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_RX_IRQ_MSK, 0); 21818c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_TR_IRQ_MSK, 0); 21828c2ecf20Sopenharmony_ci 21838c2ecf20Sopenharmony_ci /* Initialize Mac Fifo */ 21848c2ecf20Sopenharmony_ci 21858c2ecf20Sopenharmony_ci /* Configure Rx MAC FIFO */ 21868c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK); 21878c2ecf20Sopenharmony_ci reg = GMF_OPER_ON | GMF_RX_F_FL_ON; 21888c2ecf20Sopenharmony_ci 21898c2ecf20Sopenharmony_ci /* disable Rx GMAC FIFO Flush for YUKON-Lite Rev. A0 only */ 21908c2ecf20Sopenharmony_ci if (is_yukon_lite_a0(hw)) 21918c2ecf20Sopenharmony_ci reg &= ~GMF_RX_F_FL_ON; 21928c2ecf20Sopenharmony_ci 21938c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); 21948c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg); 21958c2ecf20Sopenharmony_ci /* 21968c2ecf20Sopenharmony_ci * because Pause Packet Truncation in GMAC is not working 21978c2ecf20Sopenharmony_ci * we have to increase the Flush Threshold to 64 bytes 21988c2ecf20Sopenharmony_ci * in order to flush pause packets in Rx FIFO on Yukon-1 21998c2ecf20Sopenharmony_ci */ 22008c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF+1); 22018c2ecf20Sopenharmony_ci 22028c2ecf20Sopenharmony_ci /* Configure Tx MAC FIFO */ 22038c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR); 22048c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON); 22058c2ecf20Sopenharmony_ci} 22068c2ecf20Sopenharmony_ci 22078c2ecf20Sopenharmony_ci/* Go into power down mode */ 22088c2ecf20Sopenharmony_cistatic void yukon_suspend(struct skge_hw *hw, int port) 22098c2ecf20Sopenharmony_ci{ 22108c2ecf20Sopenharmony_ci u16 ctrl; 22118c2ecf20Sopenharmony_ci 22128c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); 22138c2ecf20Sopenharmony_ci ctrl |= PHY_M_PC_POL_R_DIS; 22148c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); 22158c2ecf20Sopenharmony_ci 22168c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL); 22178c2ecf20Sopenharmony_ci ctrl |= PHY_CT_RESET; 22188c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); 22198c2ecf20Sopenharmony_ci 22208c2ecf20Sopenharmony_ci /* switch IEEE compatible power down mode on */ 22218c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL); 22228c2ecf20Sopenharmony_ci ctrl |= PHY_CT_PDOWN; 22238c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); 22248c2ecf20Sopenharmony_ci} 22258c2ecf20Sopenharmony_ci 22268c2ecf20Sopenharmony_cistatic void yukon_stop(struct skge_port *skge) 22278c2ecf20Sopenharmony_ci{ 22288c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 22298c2ecf20Sopenharmony_ci int port = skge->port; 22308c2ecf20Sopenharmony_ci 22318c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0); 22328c2ecf20Sopenharmony_ci yukon_reset(hw, port); 22338c2ecf20Sopenharmony_ci 22348c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, 22358c2ecf20Sopenharmony_ci gma_read16(hw, port, GM_GP_CTRL) 22368c2ecf20Sopenharmony_ci & ~(GM_GPCR_TX_ENA|GM_GPCR_RX_ENA)); 22378c2ecf20Sopenharmony_ci gma_read16(hw, port, GM_GP_CTRL); 22388c2ecf20Sopenharmony_ci 22398c2ecf20Sopenharmony_ci yukon_suspend(hw, port); 22408c2ecf20Sopenharmony_ci 22418c2ecf20Sopenharmony_ci /* set GPHY Control reset */ 22428c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); 22438c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET); 22448c2ecf20Sopenharmony_ci} 22458c2ecf20Sopenharmony_ci 22468c2ecf20Sopenharmony_cistatic void yukon_get_stats(struct skge_port *skge, u64 *data) 22478c2ecf20Sopenharmony_ci{ 22488c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 22498c2ecf20Sopenharmony_ci int port = skge->port; 22508c2ecf20Sopenharmony_ci int i; 22518c2ecf20Sopenharmony_ci 22528c2ecf20Sopenharmony_ci data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32 22538c2ecf20Sopenharmony_ci | gma_read32(hw, port, GM_TXO_OK_LO); 22548c2ecf20Sopenharmony_ci data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32 22558c2ecf20Sopenharmony_ci | gma_read32(hw, port, GM_RXO_OK_LO); 22568c2ecf20Sopenharmony_ci 22578c2ecf20Sopenharmony_ci for (i = 2; i < ARRAY_SIZE(skge_stats); i++) 22588c2ecf20Sopenharmony_ci data[i] = gma_read32(hw, port, 22598c2ecf20Sopenharmony_ci skge_stats[i].gma_offset); 22608c2ecf20Sopenharmony_ci} 22618c2ecf20Sopenharmony_ci 22628c2ecf20Sopenharmony_cistatic void yukon_mac_intr(struct skge_hw *hw, int port) 22638c2ecf20Sopenharmony_ci{ 22648c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 22658c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 22668c2ecf20Sopenharmony_ci u8 status = skge_read8(hw, SK_REG(port, GMAC_IRQ_SRC)); 22678c2ecf20Sopenharmony_ci 22688c2ecf20Sopenharmony_ci netif_printk(skge, intr, KERN_DEBUG, skge->netdev, 22698c2ecf20Sopenharmony_ci "mac interrupt status 0x%x\n", status); 22708c2ecf20Sopenharmony_ci 22718c2ecf20Sopenharmony_ci if (status & GM_IS_RX_FF_OR) { 22728c2ecf20Sopenharmony_ci ++dev->stats.rx_fifo_errors; 22738c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO); 22748c2ecf20Sopenharmony_ci } 22758c2ecf20Sopenharmony_ci 22768c2ecf20Sopenharmony_ci if (status & GM_IS_TX_FF_UR) { 22778c2ecf20Sopenharmony_ci ++dev->stats.tx_fifo_errors; 22788c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU); 22798c2ecf20Sopenharmony_ci } 22808c2ecf20Sopenharmony_ci 22818c2ecf20Sopenharmony_ci} 22828c2ecf20Sopenharmony_ci 22838c2ecf20Sopenharmony_cistatic u16 yukon_speed(const struct skge_hw *hw, u16 aux) 22848c2ecf20Sopenharmony_ci{ 22858c2ecf20Sopenharmony_ci switch (aux & PHY_M_PS_SPEED_MSK) { 22868c2ecf20Sopenharmony_ci case PHY_M_PS_SPEED_1000: 22878c2ecf20Sopenharmony_ci return SPEED_1000; 22888c2ecf20Sopenharmony_ci case PHY_M_PS_SPEED_100: 22898c2ecf20Sopenharmony_ci return SPEED_100; 22908c2ecf20Sopenharmony_ci default: 22918c2ecf20Sopenharmony_ci return SPEED_10; 22928c2ecf20Sopenharmony_ci } 22938c2ecf20Sopenharmony_ci} 22948c2ecf20Sopenharmony_ci 22958c2ecf20Sopenharmony_cistatic void yukon_link_up(struct skge_port *skge) 22968c2ecf20Sopenharmony_ci{ 22978c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 22988c2ecf20Sopenharmony_ci int port = skge->port; 22998c2ecf20Sopenharmony_ci u16 reg; 23008c2ecf20Sopenharmony_ci 23018c2ecf20Sopenharmony_ci /* Enable Transmit FIFO Underrun */ 23028c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK); 23038c2ecf20Sopenharmony_ci 23048c2ecf20Sopenharmony_ci reg = gma_read16(hw, port, GM_GP_CTRL); 23058c2ecf20Sopenharmony_ci if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE) 23068c2ecf20Sopenharmony_ci reg |= GM_GPCR_DUP_FULL; 23078c2ecf20Sopenharmony_ci 23088c2ecf20Sopenharmony_ci /* enable Rx/Tx */ 23098c2ecf20Sopenharmony_ci reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA; 23108c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, reg); 23118c2ecf20Sopenharmony_ci 23128c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK); 23138c2ecf20Sopenharmony_ci skge_link_up(skge); 23148c2ecf20Sopenharmony_ci} 23158c2ecf20Sopenharmony_ci 23168c2ecf20Sopenharmony_cistatic void yukon_link_down(struct skge_port *skge) 23178c2ecf20Sopenharmony_ci{ 23188c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 23198c2ecf20Sopenharmony_ci int port = skge->port; 23208c2ecf20Sopenharmony_ci u16 ctrl; 23218c2ecf20Sopenharmony_ci 23228c2ecf20Sopenharmony_ci ctrl = gma_read16(hw, port, GM_GP_CTRL); 23238c2ecf20Sopenharmony_ci ctrl &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA); 23248c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, ctrl); 23258c2ecf20Sopenharmony_ci 23268c2ecf20Sopenharmony_ci if (skge->flow_status == FLOW_STAT_REM_SEND) { 23278c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV); 23288c2ecf20Sopenharmony_ci ctrl |= PHY_M_AN_ASP; 23298c2ecf20Sopenharmony_ci /* restore Asymmetric Pause bit */ 23308c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, ctrl); 23318c2ecf20Sopenharmony_ci } 23328c2ecf20Sopenharmony_ci 23338c2ecf20Sopenharmony_ci skge_link_down(skge); 23348c2ecf20Sopenharmony_ci 23358c2ecf20Sopenharmony_ci yukon_init(hw, port); 23368c2ecf20Sopenharmony_ci} 23378c2ecf20Sopenharmony_ci 23388c2ecf20Sopenharmony_cistatic void yukon_phy_intr(struct skge_port *skge) 23398c2ecf20Sopenharmony_ci{ 23408c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 23418c2ecf20Sopenharmony_ci int port = skge->port; 23428c2ecf20Sopenharmony_ci const char *reason = NULL; 23438c2ecf20Sopenharmony_ci u16 istatus, phystat; 23448c2ecf20Sopenharmony_ci 23458c2ecf20Sopenharmony_ci istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT); 23468c2ecf20Sopenharmony_ci phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT); 23478c2ecf20Sopenharmony_ci 23488c2ecf20Sopenharmony_ci netif_printk(skge, intr, KERN_DEBUG, skge->netdev, 23498c2ecf20Sopenharmony_ci "phy interrupt status 0x%x 0x%x\n", istatus, phystat); 23508c2ecf20Sopenharmony_ci 23518c2ecf20Sopenharmony_ci if (istatus & PHY_M_IS_AN_COMPL) { 23528c2ecf20Sopenharmony_ci if (gm_phy_read(hw, port, PHY_MARV_AUNE_LP) 23538c2ecf20Sopenharmony_ci & PHY_M_AN_RF) { 23548c2ecf20Sopenharmony_ci reason = "remote fault"; 23558c2ecf20Sopenharmony_ci goto failed; 23568c2ecf20Sopenharmony_ci } 23578c2ecf20Sopenharmony_ci 23588c2ecf20Sopenharmony_ci if (gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) { 23598c2ecf20Sopenharmony_ci reason = "master/slave fault"; 23608c2ecf20Sopenharmony_ci goto failed; 23618c2ecf20Sopenharmony_ci } 23628c2ecf20Sopenharmony_ci 23638c2ecf20Sopenharmony_ci if (!(phystat & PHY_M_PS_SPDUP_RES)) { 23648c2ecf20Sopenharmony_ci reason = "speed/duplex"; 23658c2ecf20Sopenharmony_ci goto failed; 23668c2ecf20Sopenharmony_ci } 23678c2ecf20Sopenharmony_ci 23688c2ecf20Sopenharmony_ci skge->duplex = (phystat & PHY_M_PS_FULL_DUP) 23698c2ecf20Sopenharmony_ci ? DUPLEX_FULL : DUPLEX_HALF; 23708c2ecf20Sopenharmony_ci skge->speed = yukon_speed(hw, phystat); 23718c2ecf20Sopenharmony_ci 23728c2ecf20Sopenharmony_ci /* We are using IEEE 802.3z/D5.0 Table 37-4 */ 23738c2ecf20Sopenharmony_ci switch (phystat & PHY_M_PS_PAUSE_MSK) { 23748c2ecf20Sopenharmony_ci case PHY_M_PS_PAUSE_MSK: 23758c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_SYMMETRIC; 23768c2ecf20Sopenharmony_ci break; 23778c2ecf20Sopenharmony_ci case PHY_M_PS_RX_P_EN: 23788c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_REM_SEND; 23798c2ecf20Sopenharmony_ci break; 23808c2ecf20Sopenharmony_ci case PHY_M_PS_TX_P_EN: 23818c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_LOC_SEND; 23828c2ecf20Sopenharmony_ci break; 23838c2ecf20Sopenharmony_ci default: 23848c2ecf20Sopenharmony_ci skge->flow_status = FLOW_STAT_NONE; 23858c2ecf20Sopenharmony_ci } 23868c2ecf20Sopenharmony_ci 23878c2ecf20Sopenharmony_ci if (skge->flow_status == FLOW_STAT_NONE || 23888c2ecf20Sopenharmony_ci (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF)) 23898c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); 23908c2ecf20Sopenharmony_ci else 23918c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); 23928c2ecf20Sopenharmony_ci yukon_link_up(skge); 23938c2ecf20Sopenharmony_ci return; 23948c2ecf20Sopenharmony_ci } 23958c2ecf20Sopenharmony_ci 23968c2ecf20Sopenharmony_ci if (istatus & PHY_M_IS_LSP_CHANGE) 23978c2ecf20Sopenharmony_ci skge->speed = yukon_speed(hw, phystat); 23988c2ecf20Sopenharmony_ci 23998c2ecf20Sopenharmony_ci if (istatus & PHY_M_IS_DUP_CHANGE) 24008c2ecf20Sopenharmony_ci skge->duplex = (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; 24018c2ecf20Sopenharmony_ci if (istatus & PHY_M_IS_LST_CHANGE) { 24028c2ecf20Sopenharmony_ci if (phystat & PHY_M_PS_LINK_UP) 24038c2ecf20Sopenharmony_ci yukon_link_up(skge); 24048c2ecf20Sopenharmony_ci else 24058c2ecf20Sopenharmony_ci yukon_link_down(skge); 24068c2ecf20Sopenharmony_ci } 24078c2ecf20Sopenharmony_ci return; 24088c2ecf20Sopenharmony_ci failed: 24098c2ecf20Sopenharmony_ci pr_err("%s: autonegotiation failed (%s)\n", skge->netdev->name, reason); 24108c2ecf20Sopenharmony_ci 24118c2ecf20Sopenharmony_ci /* XXX restart autonegotiation? */ 24128c2ecf20Sopenharmony_ci} 24138c2ecf20Sopenharmony_ci 24148c2ecf20Sopenharmony_cistatic void skge_phy_reset(struct skge_port *skge) 24158c2ecf20Sopenharmony_ci{ 24168c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 24178c2ecf20Sopenharmony_ci int port = skge->port; 24188c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 24198c2ecf20Sopenharmony_ci 24208c2ecf20Sopenharmony_ci netif_stop_queue(skge->netdev); 24218c2ecf20Sopenharmony_ci netif_carrier_off(skge->netdev); 24228c2ecf20Sopenharmony_ci 24238c2ecf20Sopenharmony_ci spin_lock_bh(&hw->phy_lock); 24248c2ecf20Sopenharmony_ci if (is_genesis(hw)) { 24258c2ecf20Sopenharmony_ci genesis_reset(hw, port); 24268c2ecf20Sopenharmony_ci genesis_mac_init(hw, port); 24278c2ecf20Sopenharmony_ci } else { 24288c2ecf20Sopenharmony_ci yukon_reset(hw, port); 24298c2ecf20Sopenharmony_ci yukon_init(hw, port); 24308c2ecf20Sopenharmony_ci } 24318c2ecf20Sopenharmony_ci spin_unlock_bh(&hw->phy_lock); 24328c2ecf20Sopenharmony_ci 24338c2ecf20Sopenharmony_ci skge_set_multicast(dev); 24348c2ecf20Sopenharmony_ci} 24358c2ecf20Sopenharmony_ci 24368c2ecf20Sopenharmony_ci/* Basic MII support */ 24378c2ecf20Sopenharmony_cistatic int skge_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 24388c2ecf20Sopenharmony_ci{ 24398c2ecf20Sopenharmony_ci struct mii_ioctl_data *data = if_mii(ifr); 24408c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 24418c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 24428c2ecf20Sopenharmony_ci int err = -EOPNOTSUPP; 24438c2ecf20Sopenharmony_ci 24448c2ecf20Sopenharmony_ci if (!netif_running(dev)) 24458c2ecf20Sopenharmony_ci return -ENODEV; /* Phy still in reset */ 24468c2ecf20Sopenharmony_ci 24478c2ecf20Sopenharmony_ci switch (cmd) { 24488c2ecf20Sopenharmony_ci case SIOCGMIIPHY: 24498c2ecf20Sopenharmony_ci data->phy_id = hw->phy_addr; 24508c2ecf20Sopenharmony_ci 24518c2ecf20Sopenharmony_ci fallthrough; 24528c2ecf20Sopenharmony_ci case SIOCGMIIREG: { 24538c2ecf20Sopenharmony_ci u16 val = 0; 24548c2ecf20Sopenharmony_ci spin_lock_bh(&hw->phy_lock); 24558c2ecf20Sopenharmony_ci 24568c2ecf20Sopenharmony_ci if (is_genesis(hw)) 24578c2ecf20Sopenharmony_ci err = __xm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val); 24588c2ecf20Sopenharmony_ci else 24598c2ecf20Sopenharmony_ci err = __gm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val); 24608c2ecf20Sopenharmony_ci spin_unlock_bh(&hw->phy_lock); 24618c2ecf20Sopenharmony_ci data->val_out = val; 24628c2ecf20Sopenharmony_ci break; 24638c2ecf20Sopenharmony_ci } 24648c2ecf20Sopenharmony_ci 24658c2ecf20Sopenharmony_ci case SIOCSMIIREG: 24668c2ecf20Sopenharmony_ci spin_lock_bh(&hw->phy_lock); 24678c2ecf20Sopenharmony_ci if (is_genesis(hw)) 24688c2ecf20Sopenharmony_ci err = xm_phy_write(hw, skge->port, data->reg_num & 0x1f, 24698c2ecf20Sopenharmony_ci data->val_in); 24708c2ecf20Sopenharmony_ci else 24718c2ecf20Sopenharmony_ci err = gm_phy_write(hw, skge->port, data->reg_num & 0x1f, 24728c2ecf20Sopenharmony_ci data->val_in); 24738c2ecf20Sopenharmony_ci spin_unlock_bh(&hw->phy_lock); 24748c2ecf20Sopenharmony_ci break; 24758c2ecf20Sopenharmony_ci } 24768c2ecf20Sopenharmony_ci return err; 24778c2ecf20Sopenharmony_ci} 24788c2ecf20Sopenharmony_ci 24798c2ecf20Sopenharmony_cistatic void skge_ramset(struct skge_hw *hw, u16 q, u32 start, size_t len) 24808c2ecf20Sopenharmony_ci{ 24818c2ecf20Sopenharmony_ci u32 end; 24828c2ecf20Sopenharmony_ci 24838c2ecf20Sopenharmony_ci start /= 8; 24848c2ecf20Sopenharmony_ci len /= 8; 24858c2ecf20Sopenharmony_ci end = start + len - 1; 24868c2ecf20Sopenharmony_ci 24878c2ecf20Sopenharmony_ci skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR); 24888c2ecf20Sopenharmony_ci skge_write32(hw, RB_ADDR(q, RB_START), start); 24898c2ecf20Sopenharmony_ci skge_write32(hw, RB_ADDR(q, RB_WP), start); 24908c2ecf20Sopenharmony_ci skge_write32(hw, RB_ADDR(q, RB_RP), start); 24918c2ecf20Sopenharmony_ci skge_write32(hw, RB_ADDR(q, RB_END), end); 24928c2ecf20Sopenharmony_ci 24938c2ecf20Sopenharmony_ci if (q == Q_R1 || q == Q_R2) { 24948c2ecf20Sopenharmony_ci /* Set thresholds on receive queue's */ 24958c2ecf20Sopenharmony_ci skge_write32(hw, RB_ADDR(q, RB_RX_UTPP), 24968c2ecf20Sopenharmony_ci start + (2*len)/3); 24978c2ecf20Sopenharmony_ci skge_write32(hw, RB_ADDR(q, RB_RX_LTPP), 24988c2ecf20Sopenharmony_ci start + (len/3)); 24998c2ecf20Sopenharmony_ci } else { 25008c2ecf20Sopenharmony_ci /* Enable store & forward on Tx queue's because 25018c2ecf20Sopenharmony_ci * Tx FIFO is only 4K on Genesis and 1K on Yukon 25028c2ecf20Sopenharmony_ci */ 25038c2ecf20Sopenharmony_ci skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD); 25048c2ecf20Sopenharmony_ci } 25058c2ecf20Sopenharmony_ci 25068c2ecf20Sopenharmony_ci skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD); 25078c2ecf20Sopenharmony_ci} 25088c2ecf20Sopenharmony_ci 25098c2ecf20Sopenharmony_ci/* Setup Bus Memory Interface */ 25108c2ecf20Sopenharmony_cistatic void skge_qset(struct skge_port *skge, u16 q, 25118c2ecf20Sopenharmony_ci const struct skge_element *e) 25128c2ecf20Sopenharmony_ci{ 25138c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 25148c2ecf20Sopenharmony_ci u32 watermark = 0x600; 25158c2ecf20Sopenharmony_ci u64 base = skge->dma + (e->desc - skge->mem); 25168c2ecf20Sopenharmony_ci 25178c2ecf20Sopenharmony_ci /* optimization to reduce window on 32bit/33mhz */ 25188c2ecf20Sopenharmony_ci if ((skge_read16(hw, B0_CTST) & (CS_BUS_CLOCK | CS_BUS_SLOT_SZ)) == 0) 25198c2ecf20Sopenharmony_ci watermark /= 2; 25208c2ecf20Sopenharmony_ci 25218c2ecf20Sopenharmony_ci skge_write32(hw, Q_ADDR(q, Q_CSR), CSR_CLR_RESET); 25228c2ecf20Sopenharmony_ci skge_write32(hw, Q_ADDR(q, Q_F), watermark); 25238c2ecf20Sopenharmony_ci skge_write32(hw, Q_ADDR(q, Q_DA_H), (u32)(base >> 32)); 25248c2ecf20Sopenharmony_ci skge_write32(hw, Q_ADDR(q, Q_DA_L), (u32)base); 25258c2ecf20Sopenharmony_ci} 25268c2ecf20Sopenharmony_ci 25278c2ecf20Sopenharmony_cistatic int skge_up(struct net_device *dev) 25288c2ecf20Sopenharmony_ci{ 25298c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 25308c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 25318c2ecf20Sopenharmony_ci int port = skge->port; 25328c2ecf20Sopenharmony_ci u32 chunk, ram_addr; 25338c2ecf20Sopenharmony_ci size_t rx_size, tx_size; 25348c2ecf20Sopenharmony_ci int err; 25358c2ecf20Sopenharmony_ci 25368c2ecf20Sopenharmony_ci if (!is_valid_ether_addr(dev->dev_addr)) 25378c2ecf20Sopenharmony_ci return -EINVAL; 25388c2ecf20Sopenharmony_ci 25398c2ecf20Sopenharmony_ci netif_info(skge, ifup, skge->netdev, "enabling interface\n"); 25408c2ecf20Sopenharmony_ci 25418c2ecf20Sopenharmony_ci if (dev->mtu > RX_BUF_SIZE) 25428c2ecf20Sopenharmony_ci skge->rx_buf_size = dev->mtu + ETH_HLEN; 25438c2ecf20Sopenharmony_ci else 25448c2ecf20Sopenharmony_ci skge->rx_buf_size = RX_BUF_SIZE; 25458c2ecf20Sopenharmony_ci 25468c2ecf20Sopenharmony_ci 25478c2ecf20Sopenharmony_ci rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc); 25488c2ecf20Sopenharmony_ci tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc); 25498c2ecf20Sopenharmony_ci skge->mem_size = tx_size + rx_size; 25508c2ecf20Sopenharmony_ci skge->mem = dma_alloc_coherent(&hw->pdev->dev, skge->mem_size, 25518c2ecf20Sopenharmony_ci &skge->dma, GFP_KERNEL); 25528c2ecf20Sopenharmony_ci if (!skge->mem) 25538c2ecf20Sopenharmony_ci return -ENOMEM; 25548c2ecf20Sopenharmony_ci 25558c2ecf20Sopenharmony_ci BUG_ON(skge->dma & 7); 25568c2ecf20Sopenharmony_ci 25578c2ecf20Sopenharmony_ci if (upper_32_bits(skge->dma) != upper_32_bits(skge->dma + skge->mem_size)) { 25588c2ecf20Sopenharmony_ci dev_err(&hw->pdev->dev, "dma_alloc_coherent region crosses 4G boundary\n"); 25598c2ecf20Sopenharmony_ci err = -EINVAL; 25608c2ecf20Sopenharmony_ci goto free_pci_mem; 25618c2ecf20Sopenharmony_ci } 25628c2ecf20Sopenharmony_ci 25638c2ecf20Sopenharmony_ci err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma); 25648c2ecf20Sopenharmony_ci if (err) 25658c2ecf20Sopenharmony_ci goto free_pci_mem; 25668c2ecf20Sopenharmony_ci 25678c2ecf20Sopenharmony_ci err = skge_rx_fill(dev); 25688c2ecf20Sopenharmony_ci if (err) 25698c2ecf20Sopenharmony_ci goto free_rx_ring; 25708c2ecf20Sopenharmony_ci 25718c2ecf20Sopenharmony_ci err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size, 25728c2ecf20Sopenharmony_ci skge->dma + rx_size); 25738c2ecf20Sopenharmony_ci if (err) 25748c2ecf20Sopenharmony_ci goto free_rx_ring; 25758c2ecf20Sopenharmony_ci 25768c2ecf20Sopenharmony_ci if (hw->ports == 1) { 25778c2ecf20Sopenharmony_ci err = request_irq(hw->pdev->irq, skge_intr, IRQF_SHARED, 25788c2ecf20Sopenharmony_ci dev->name, hw); 25798c2ecf20Sopenharmony_ci if (err) { 25808c2ecf20Sopenharmony_ci netdev_err(dev, "Unable to allocate interrupt %d error: %d\n", 25818c2ecf20Sopenharmony_ci hw->pdev->irq, err); 25828c2ecf20Sopenharmony_ci goto free_tx_ring; 25838c2ecf20Sopenharmony_ci } 25848c2ecf20Sopenharmony_ci } 25858c2ecf20Sopenharmony_ci 25868c2ecf20Sopenharmony_ci /* Initialize MAC */ 25878c2ecf20Sopenharmony_ci netif_carrier_off(dev); 25888c2ecf20Sopenharmony_ci spin_lock_bh(&hw->phy_lock); 25898c2ecf20Sopenharmony_ci if (is_genesis(hw)) 25908c2ecf20Sopenharmony_ci genesis_mac_init(hw, port); 25918c2ecf20Sopenharmony_ci else 25928c2ecf20Sopenharmony_ci yukon_mac_init(hw, port); 25938c2ecf20Sopenharmony_ci spin_unlock_bh(&hw->phy_lock); 25948c2ecf20Sopenharmony_ci 25958c2ecf20Sopenharmony_ci /* Configure RAMbuffers - equally between ports and tx/rx */ 25968c2ecf20Sopenharmony_ci chunk = (hw->ram_size - hw->ram_offset) / (hw->ports * 2); 25978c2ecf20Sopenharmony_ci ram_addr = hw->ram_offset + 2 * chunk * port; 25988c2ecf20Sopenharmony_ci 25998c2ecf20Sopenharmony_ci skge_ramset(hw, rxqaddr[port], ram_addr, chunk); 26008c2ecf20Sopenharmony_ci skge_qset(skge, rxqaddr[port], skge->rx_ring.to_clean); 26018c2ecf20Sopenharmony_ci 26028c2ecf20Sopenharmony_ci BUG_ON(skge->tx_ring.to_use != skge->tx_ring.to_clean); 26038c2ecf20Sopenharmony_ci skge_ramset(hw, txqaddr[port], ram_addr+chunk, chunk); 26048c2ecf20Sopenharmony_ci skge_qset(skge, txqaddr[port], skge->tx_ring.to_use); 26058c2ecf20Sopenharmony_ci 26068c2ecf20Sopenharmony_ci /* Start receiver BMU */ 26078c2ecf20Sopenharmony_ci wmb(); 26088c2ecf20Sopenharmony_ci skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F); 26098c2ecf20Sopenharmony_ci skge_led(skge, LED_MODE_ON); 26108c2ecf20Sopenharmony_ci 26118c2ecf20Sopenharmony_ci spin_lock_irq(&hw->hw_lock); 26128c2ecf20Sopenharmony_ci hw->intr_mask |= portmask[port]; 26138c2ecf20Sopenharmony_ci skge_write32(hw, B0_IMSK, hw->intr_mask); 26148c2ecf20Sopenharmony_ci skge_read32(hw, B0_IMSK); 26158c2ecf20Sopenharmony_ci spin_unlock_irq(&hw->hw_lock); 26168c2ecf20Sopenharmony_ci 26178c2ecf20Sopenharmony_ci napi_enable(&skge->napi); 26188c2ecf20Sopenharmony_ci 26198c2ecf20Sopenharmony_ci skge_set_multicast(dev); 26208c2ecf20Sopenharmony_ci 26218c2ecf20Sopenharmony_ci return 0; 26228c2ecf20Sopenharmony_ci 26238c2ecf20Sopenharmony_ci free_tx_ring: 26248c2ecf20Sopenharmony_ci kfree(skge->tx_ring.start); 26258c2ecf20Sopenharmony_ci free_rx_ring: 26268c2ecf20Sopenharmony_ci skge_rx_clean(skge); 26278c2ecf20Sopenharmony_ci kfree(skge->rx_ring.start); 26288c2ecf20Sopenharmony_ci free_pci_mem: 26298c2ecf20Sopenharmony_ci dma_free_coherent(&hw->pdev->dev, skge->mem_size, skge->mem, 26308c2ecf20Sopenharmony_ci skge->dma); 26318c2ecf20Sopenharmony_ci skge->mem = NULL; 26328c2ecf20Sopenharmony_ci 26338c2ecf20Sopenharmony_ci return err; 26348c2ecf20Sopenharmony_ci} 26358c2ecf20Sopenharmony_ci 26368c2ecf20Sopenharmony_ci/* stop receiver */ 26378c2ecf20Sopenharmony_cistatic void skge_rx_stop(struct skge_hw *hw, int port) 26388c2ecf20Sopenharmony_ci{ 26398c2ecf20Sopenharmony_ci skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_STOP); 26408c2ecf20Sopenharmony_ci skge_write32(hw, RB_ADDR(port ? Q_R2 : Q_R1, RB_CTRL), 26418c2ecf20Sopenharmony_ci RB_RST_SET|RB_DIS_OP_MD); 26428c2ecf20Sopenharmony_ci skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET); 26438c2ecf20Sopenharmony_ci} 26448c2ecf20Sopenharmony_ci 26458c2ecf20Sopenharmony_cistatic int skge_down(struct net_device *dev) 26468c2ecf20Sopenharmony_ci{ 26478c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 26488c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 26498c2ecf20Sopenharmony_ci int port = skge->port; 26508c2ecf20Sopenharmony_ci 26518c2ecf20Sopenharmony_ci if (!skge->mem) 26528c2ecf20Sopenharmony_ci return 0; 26538c2ecf20Sopenharmony_ci 26548c2ecf20Sopenharmony_ci netif_info(skge, ifdown, skge->netdev, "disabling interface\n"); 26558c2ecf20Sopenharmony_ci 26568c2ecf20Sopenharmony_ci netif_tx_disable(dev); 26578c2ecf20Sopenharmony_ci 26588c2ecf20Sopenharmony_ci if (is_genesis(hw) && hw->phy_type == SK_PHY_XMAC) 26598c2ecf20Sopenharmony_ci del_timer_sync(&skge->link_timer); 26608c2ecf20Sopenharmony_ci 26618c2ecf20Sopenharmony_ci napi_disable(&skge->napi); 26628c2ecf20Sopenharmony_ci netif_carrier_off(dev); 26638c2ecf20Sopenharmony_ci 26648c2ecf20Sopenharmony_ci spin_lock_irq(&hw->hw_lock); 26658c2ecf20Sopenharmony_ci hw->intr_mask &= ~portmask[port]; 26668c2ecf20Sopenharmony_ci skge_write32(hw, B0_IMSK, (hw->ports == 1) ? 0 : hw->intr_mask); 26678c2ecf20Sopenharmony_ci skge_read32(hw, B0_IMSK); 26688c2ecf20Sopenharmony_ci spin_unlock_irq(&hw->hw_lock); 26698c2ecf20Sopenharmony_ci 26708c2ecf20Sopenharmony_ci if (hw->ports == 1) 26718c2ecf20Sopenharmony_ci free_irq(hw->pdev->irq, hw); 26728c2ecf20Sopenharmony_ci 26738c2ecf20Sopenharmony_ci skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_REG_OFF); 26748c2ecf20Sopenharmony_ci if (is_genesis(hw)) 26758c2ecf20Sopenharmony_ci genesis_stop(skge); 26768c2ecf20Sopenharmony_ci else 26778c2ecf20Sopenharmony_ci yukon_stop(skge); 26788c2ecf20Sopenharmony_ci 26798c2ecf20Sopenharmony_ci /* Stop transmitter */ 26808c2ecf20Sopenharmony_ci skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP); 26818c2ecf20Sopenharmony_ci skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), 26828c2ecf20Sopenharmony_ci RB_RST_SET|RB_DIS_OP_MD); 26838c2ecf20Sopenharmony_ci 26848c2ecf20Sopenharmony_ci 26858c2ecf20Sopenharmony_ci /* Disable Force Sync bit and Enable Alloc bit */ 26868c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TXA_CTRL), 26878c2ecf20Sopenharmony_ci TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC); 26888c2ecf20Sopenharmony_ci 26898c2ecf20Sopenharmony_ci /* Stop Interval Timer and Limit Counter of Tx Arbiter */ 26908c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, TXA_ITI_INI), 0L); 26918c2ecf20Sopenharmony_ci skge_write32(hw, SK_REG(port, TXA_LIM_INI), 0L); 26928c2ecf20Sopenharmony_ci 26938c2ecf20Sopenharmony_ci /* Reset PCI FIFO */ 26948c2ecf20Sopenharmony_ci skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET); 26958c2ecf20Sopenharmony_ci skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET); 26968c2ecf20Sopenharmony_ci 26978c2ecf20Sopenharmony_ci /* Reset the RAM Buffer async Tx queue */ 26988c2ecf20Sopenharmony_ci skge_write8(hw, RB_ADDR(port == 0 ? Q_XA1 : Q_XA2, RB_CTRL), RB_RST_SET); 26998c2ecf20Sopenharmony_ci 27008c2ecf20Sopenharmony_ci skge_rx_stop(hw, port); 27018c2ecf20Sopenharmony_ci 27028c2ecf20Sopenharmony_ci if (is_genesis(hw)) { 27038c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET); 27048c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET); 27058c2ecf20Sopenharmony_ci } else { 27068c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); 27078c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); 27088c2ecf20Sopenharmony_ci } 27098c2ecf20Sopenharmony_ci 27108c2ecf20Sopenharmony_ci skge_led(skge, LED_MODE_OFF); 27118c2ecf20Sopenharmony_ci 27128c2ecf20Sopenharmony_ci netif_tx_lock_bh(dev); 27138c2ecf20Sopenharmony_ci skge_tx_clean(dev); 27148c2ecf20Sopenharmony_ci netif_tx_unlock_bh(dev); 27158c2ecf20Sopenharmony_ci 27168c2ecf20Sopenharmony_ci skge_rx_clean(skge); 27178c2ecf20Sopenharmony_ci 27188c2ecf20Sopenharmony_ci kfree(skge->rx_ring.start); 27198c2ecf20Sopenharmony_ci kfree(skge->tx_ring.start); 27208c2ecf20Sopenharmony_ci dma_free_coherent(&hw->pdev->dev, skge->mem_size, skge->mem, 27218c2ecf20Sopenharmony_ci skge->dma); 27228c2ecf20Sopenharmony_ci skge->mem = NULL; 27238c2ecf20Sopenharmony_ci return 0; 27248c2ecf20Sopenharmony_ci} 27258c2ecf20Sopenharmony_ci 27268c2ecf20Sopenharmony_cistatic inline int skge_avail(const struct skge_ring *ring) 27278c2ecf20Sopenharmony_ci{ 27288c2ecf20Sopenharmony_ci smp_mb(); 27298c2ecf20Sopenharmony_ci return ((ring->to_clean > ring->to_use) ? 0 : ring->count) 27308c2ecf20Sopenharmony_ci + (ring->to_clean - ring->to_use) - 1; 27318c2ecf20Sopenharmony_ci} 27328c2ecf20Sopenharmony_ci 27338c2ecf20Sopenharmony_cistatic netdev_tx_t skge_xmit_frame(struct sk_buff *skb, 27348c2ecf20Sopenharmony_ci struct net_device *dev) 27358c2ecf20Sopenharmony_ci{ 27368c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 27378c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 27388c2ecf20Sopenharmony_ci struct skge_element *e; 27398c2ecf20Sopenharmony_ci struct skge_tx_desc *td; 27408c2ecf20Sopenharmony_ci int i; 27418c2ecf20Sopenharmony_ci u32 control, len; 27428c2ecf20Sopenharmony_ci dma_addr_t map; 27438c2ecf20Sopenharmony_ci 27448c2ecf20Sopenharmony_ci if (skb_padto(skb, ETH_ZLEN)) 27458c2ecf20Sopenharmony_ci return NETDEV_TX_OK; 27468c2ecf20Sopenharmony_ci 27478c2ecf20Sopenharmony_ci if (unlikely(skge_avail(&skge->tx_ring) < skb_shinfo(skb)->nr_frags + 1)) 27488c2ecf20Sopenharmony_ci return NETDEV_TX_BUSY; 27498c2ecf20Sopenharmony_ci 27508c2ecf20Sopenharmony_ci e = skge->tx_ring.to_use; 27518c2ecf20Sopenharmony_ci td = e->desc; 27528c2ecf20Sopenharmony_ci BUG_ON(td->control & BMU_OWN); 27538c2ecf20Sopenharmony_ci e->skb = skb; 27548c2ecf20Sopenharmony_ci len = skb_headlen(skb); 27558c2ecf20Sopenharmony_ci map = dma_map_single(&hw->pdev->dev, skb->data, len, DMA_TO_DEVICE); 27568c2ecf20Sopenharmony_ci if (dma_mapping_error(&hw->pdev->dev, map)) 27578c2ecf20Sopenharmony_ci goto mapping_error; 27588c2ecf20Sopenharmony_ci 27598c2ecf20Sopenharmony_ci dma_unmap_addr_set(e, mapaddr, map); 27608c2ecf20Sopenharmony_ci dma_unmap_len_set(e, maplen, len); 27618c2ecf20Sopenharmony_ci 27628c2ecf20Sopenharmony_ci td->dma_lo = lower_32_bits(map); 27638c2ecf20Sopenharmony_ci td->dma_hi = upper_32_bits(map); 27648c2ecf20Sopenharmony_ci 27658c2ecf20Sopenharmony_ci if (skb->ip_summed == CHECKSUM_PARTIAL) { 27668c2ecf20Sopenharmony_ci const int offset = skb_checksum_start_offset(skb); 27678c2ecf20Sopenharmony_ci 27688c2ecf20Sopenharmony_ci /* This seems backwards, but it is what the sk98lin 27698c2ecf20Sopenharmony_ci * does. Looks like hardware is wrong? 27708c2ecf20Sopenharmony_ci */ 27718c2ecf20Sopenharmony_ci if (ipip_hdr(skb)->protocol == IPPROTO_UDP && 27728c2ecf20Sopenharmony_ci hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON) 27738c2ecf20Sopenharmony_ci control = BMU_TCP_CHECK; 27748c2ecf20Sopenharmony_ci else 27758c2ecf20Sopenharmony_ci control = BMU_UDP_CHECK; 27768c2ecf20Sopenharmony_ci 27778c2ecf20Sopenharmony_ci td->csum_offs = 0; 27788c2ecf20Sopenharmony_ci td->csum_start = offset; 27798c2ecf20Sopenharmony_ci td->csum_write = offset + skb->csum_offset; 27808c2ecf20Sopenharmony_ci } else 27818c2ecf20Sopenharmony_ci control = BMU_CHECK; 27828c2ecf20Sopenharmony_ci 27838c2ecf20Sopenharmony_ci if (!skb_shinfo(skb)->nr_frags) /* single buffer i.e. no fragments */ 27848c2ecf20Sopenharmony_ci control |= BMU_EOF | BMU_IRQ_EOF; 27858c2ecf20Sopenharmony_ci else { 27868c2ecf20Sopenharmony_ci struct skge_tx_desc *tf = td; 27878c2ecf20Sopenharmony_ci 27888c2ecf20Sopenharmony_ci control |= BMU_STFWD; 27898c2ecf20Sopenharmony_ci for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 27908c2ecf20Sopenharmony_ci const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 27918c2ecf20Sopenharmony_ci 27928c2ecf20Sopenharmony_ci map = skb_frag_dma_map(&hw->pdev->dev, frag, 0, 27938c2ecf20Sopenharmony_ci skb_frag_size(frag), DMA_TO_DEVICE); 27948c2ecf20Sopenharmony_ci if (dma_mapping_error(&hw->pdev->dev, map)) 27958c2ecf20Sopenharmony_ci goto mapping_unwind; 27968c2ecf20Sopenharmony_ci 27978c2ecf20Sopenharmony_ci e = e->next; 27988c2ecf20Sopenharmony_ci e->skb = skb; 27998c2ecf20Sopenharmony_ci tf = e->desc; 28008c2ecf20Sopenharmony_ci BUG_ON(tf->control & BMU_OWN); 28018c2ecf20Sopenharmony_ci 28028c2ecf20Sopenharmony_ci tf->dma_lo = lower_32_bits(map); 28038c2ecf20Sopenharmony_ci tf->dma_hi = upper_32_bits(map); 28048c2ecf20Sopenharmony_ci dma_unmap_addr_set(e, mapaddr, map); 28058c2ecf20Sopenharmony_ci dma_unmap_len_set(e, maplen, skb_frag_size(frag)); 28068c2ecf20Sopenharmony_ci 28078c2ecf20Sopenharmony_ci tf->control = BMU_OWN | BMU_SW | control | skb_frag_size(frag); 28088c2ecf20Sopenharmony_ci } 28098c2ecf20Sopenharmony_ci tf->control |= BMU_EOF | BMU_IRQ_EOF; 28108c2ecf20Sopenharmony_ci } 28118c2ecf20Sopenharmony_ci /* Make sure all the descriptors written */ 28128c2ecf20Sopenharmony_ci wmb(); 28138c2ecf20Sopenharmony_ci td->control = BMU_OWN | BMU_SW | BMU_STF | control | len; 28148c2ecf20Sopenharmony_ci wmb(); 28158c2ecf20Sopenharmony_ci 28168c2ecf20Sopenharmony_ci netdev_sent_queue(dev, skb->len); 28178c2ecf20Sopenharmony_ci 28188c2ecf20Sopenharmony_ci skge_write8(hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_START); 28198c2ecf20Sopenharmony_ci 28208c2ecf20Sopenharmony_ci netif_printk(skge, tx_queued, KERN_DEBUG, skge->netdev, 28218c2ecf20Sopenharmony_ci "tx queued, slot %td, len %d\n", 28228c2ecf20Sopenharmony_ci e - skge->tx_ring.start, skb->len); 28238c2ecf20Sopenharmony_ci 28248c2ecf20Sopenharmony_ci skge->tx_ring.to_use = e->next; 28258c2ecf20Sopenharmony_ci smp_wmb(); 28268c2ecf20Sopenharmony_ci 28278c2ecf20Sopenharmony_ci if (skge_avail(&skge->tx_ring) <= TX_LOW_WATER) { 28288c2ecf20Sopenharmony_ci netdev_dbg(dev, "transmit queue full\n"); 28298c2ecf20Sopenharmony_ci netif_stop_queue(dev); 28308c2ecf20Sopenharmony_ci } 28318c2ecf20Sopenharmony_ci 28328c2ecf20Sopenharmony_ci return NETDEV_TX_OK; 28338c2ecf20Sopenharmony_ci 28348c2ecf20Sopenharmony_cimapping_unwind: 28358c2ecf20Sopenharmony_ci e = skge->tx_ring.to_use; 28368c2ecf20Sopenharmony_ci dma_unmap_single(&hw->pdev->dev, dma_unmap_addr(e, mapaddr), 28378c2ecf20Sopenharmony_ci dma_unmap_len(e, maplen), DMA_TO_DEVICE); 28388c2ecf20Sopenharmony_ci while (i-- > 0) { 28398c2ecf20Sopenharmony_ci e = e->next; 28408c2ecf20Sopenharmony_ci dma_unmap_page(&hw->pdev->dev, dma_unmap_addr(e, mapaddr), 28418c2ecf20Sopenharmony_ci dma_unmap_len(e, maplen), DMA_TO_DEVICE); 28428c2ecf20Sopenharmony_ci } 28438c2ecf20Sopenharmony_ci 28448c2ecf20Sopenharmony_cimapping_error: 28458c2ecf20Sopenharmony_ci if (net_ratelimit()) 28468c2ecf20Sopenharmony_ci dev_warn(&hw->pdev->dev, "%s: tx mapping error\n", dev->name); 28478c2ecf20Sopenharmony_ci dev_kfree_skb_any(skb); 28488c2ecf20Sopenharmony_ci return NETDEV_TX_OK; 28498c2ecf20Sopenharmony_ci} 28508c2ecf20Sopenharmony_ci 28518c2ecf20Sopenharmony_ci 28528c2ecf20Sopenharmony_ci/* Free resources associated with this reing element */ 28538c2ecf20Sopenharmony_cistatic inline void skge_tx_unmap(struct pci_dev *pdev, struct skge_element *e, 28548c2ecf20Sopenharmony_ci u32 control) 28558c2ecf20Sopenharmony_ci{ 28568c2ecf20Sopenharmony_ci /* skb header vs. fragment */ 28578c2ecf20Sopenharmony_ci if (control & BMU_STF) 28588c2ecf20Sopenharmony_ci dma_unmap_single(&pdev->dev, dma_unmap_addr(e, mapaddr), 28598c2ecf20Sopenharmony_ci dma_unmap_len(e, maplen), DMA_TO_DEVICE); 28608c2ecf20Sopenharmony_ci else 28618c2ecf20Sopenharmony_ci dma_unmap_page(&pdev->dev, dma_unmap_addr(e, mapaddr), 28628c2ecf20Sopenharmony_ci dma_unmap_len(e, maplen), DMA_TO_DEVICE); 28638c2ecf20Sopenharmony_ci} 28648c2ecf20Sopenharmony_ci 28658c2ecf20Sopenharmony_ci/* Free all buffers in transmit ring */ 28668c2ecf20Sopenharmony_cistatic void skge_tx_clean(struct net_device *dev) 28678c2ecf20Sopenharmony_ci{ 28688c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 28698c2ecf20Sopenharmony_ci struct skge_element *e; 28708c2ecf20Sopenharmony_ci 28718c2ecf20Sopenharmony_ci for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) { 28728c2ecf20Sopenharmony_ci struct skge_tx_desc *td = e->desc; 28738c2ecf20Sopenharmony_ci 28748c2ecf20Sopenharmony_ci skge_tx_unmap(skge->hw->pdev, e, td->control); 28758c2ecf20Sopenharmony_ci 28768c2ecf20Sopenharmony_ci if (td->control & BMU_EOF) 28778c2ecf20Sopenharmony_ci dev_kfree_skb(e->skb); 28788c2ecf20Sopenharmony_ci td->control = 0; 28798c2ecf20Sopenharmony_ci } 28808c2ecf20Sopenharmony_ci 28818c2ecf20Sopenharmony_ci netdev_reset_queue(dev); 28828c2ecf20Sopenharmony_ci skge->tx_ring.to_clean = e; 28838c2ecf20Sopenharmony_ci} 28848c2ecf20Sopenharmony_ci 28858c2ecf20Sopenharmony_cistatic void skge_tx_timeout(struct net_device *dev, unsigned int txqueue) 28868c2ecf20Sopenharmony_ci{ 28878c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 28888c2ecf20Sopenharmony_ci 28898c2ecf20Sopenharmony_ci netif_printk(skge, timer, KERN_DEBUG, skge->netdev, "tx timeout\n"); 28908c2ecf20Sopenharmony_ci 28918c2ecf20Sopenharmony_ci skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_STOP); 28928c2ecf20Sopenharmony_ci skge_tx_clean(dev); 28938c2ecf20Sopenharmony_ci netif_wake_queue(dev); 28948c2ecf20Sopenharmony_ci} 28958c2ecf20Sopenharmony_ci 28968c2ecf20Sopenharmony_cistatic int skge_change_mtu(struct net_device *dev, int new_mtu) 28978c2ecf20Sopenharmony_ci{ 28988c2ecf20Sopenharmony_ci int err; 28998c2ecf20Sopenharmony_ci 29008c2ecf20Sopenharmony_ci if (!netif_running(dev)) { 29018c2ecf20Sopenharmony_ci dev->mtu = new_mtu; 29028c2ecf20Sopenharmony_ci return 0; 29038c2ecf20Sopenharmony_ci } 29048c2ecf20Sopenharmony_ci 29058c2ecf20Sopenharmony_ci skge_down(dev); 29068c2ecf20Sopenharmony_ci 29078c2ecf20Sopenharmony_ci dev->mtu = new_mtu; 29088c2ecf20Sopenharmony_ci 29098c2ecf20Sopenharmony_ci err = skge_up(dev); 29108c2ecf20Sopenharmony_ci if (err) 29118c2ecf20Sopenharmony_ci dev_close(dev); 29128c2ecf20Sopenharmony_ci 29138c2ecf20Sopenharmony_ci return err; 29148c2ecf20Sopenharmony_ci} 29158c2ecf20Sopenharmony_ci 29168c2ecf20Sopenharmony_cistatic const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 }; 29178c2ecf20Sopenharmony_ci 29188c2ecf20Sopenharmony_cistatic void genesis_add_filter(u8 filter[8], const u8 *addr) 29198c2ecf20Sopenharmony_ci{ 29208c2ecf20Sopenharmony_ci u32 crc, bit; 29218c2ecf20Sopenharmony_ci 29228c2ecf20Sopenharmony_ci crc = ether_crc_le(ETH_ALEN, addr); 29238c2ecf20Sopenharmony_ci bit = ~crc & 0x3f; 29248c2ecf20Sopenharmony_ci filter[bit/8] |= 1 << (bit%8); 29258c2ecf20Sopenharmony_ci} 29268c2ecf20Sopenharmony_ci 29278c2ecf20Sopenharmony_cistatic void genesis_set_multicast(struct net_device *dev) 29288c2ecf20Sopenharmony_ci{ 29298c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 29308c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 29318c2ecf20Sopenharmony_ci int port = skge->port; 29328c2ecf20Sopenharmony_ci struct netdev_hw_addr *ha; 29338c2ecf20Sopenharmony_ci u32 mode; 29348c2ecf20Sopenharmony_ci u8 filter[8]; 29358c2ecf20Sopenharmony_ci 29368c2ecf20Sopenharmony_ci mode = xm_read32(hw, port, XM_MODE); 29378c2ecf20Sopenharmony_ci mode |= XM_MD_ENA_HASH; 29388c2ecf20Sopenharmony_ci if (dev->flags & IFF_PROMISC) 29398c2ecf20Sopenharmony_ci mode |= XM_MD_ENA_PROM; 29408c2ecf20Sopenharmony_ci else 29418c2ecf20Sopenharmony_ci mode &= ~XM_MD_ENA_PROM; 29428c2ecf20Sopenharmony_ci 29438c2ecf20Sopenharmony_ci if (dev->flags & IFF_ALLMULTI) 29448c2ecf20Sopenharmony_ci memset(filter, 0xff, sizeof(filter)); 29458c2ecf20Sopenharmony_ci else { 29468c2ecf20Sopenharmony_ci memset(filter, 0, sizeof(filter)); 29478c2ecf20Sopenharmony_ci 29488c2ecf20Sopenharmony_ci if (skge->flow_status == FLOW_STAT_REM_SEND || 29498c2ecf20Sopenharmony_ci skge->flow_status == FLOW_STAT_SYMMETRIC) 29508c2ecf20Sopenharmony_ci genesis_add_filter(filter, pause_mc_addr); 29518c2ecf20Sopenharmony_ci 29528c2ecf20Sopenharmony_ci netdev_for_each_mc_addr(ha, dev) 29538c2ecf20Sopenharmony_ci genesis_add_filter(filter, ha->addr); 29548c2ecf20Sopenharmony_ci } 29558c2ecf20Sopenharmony_ci 29568c2ecf20Sopenharmony_ci xm_write32(hw, port, XM_MODE, mode); 29578c2ecf20Sopenharmony_ci xm_outhash(hw, port, XM_HSM, filter); 29588c2ecf20Sopenharmony_ci} 29598c2ecf20Sopenharmony_ci 29608c2ecf20Sopenharmony_cistatic void yukon_add_filter(u8 filter[8], const u8 *addr) 29618c2ecf20Sopenharmony_ci{ 29628c2ecf20Sopenharmony_ci u32 bit = ether_crc(ETH_ALEN, addr) & 0x3f; 29638c2ecf20Sopenharmony_ci filter[bit/8] |= 1 << (bit%8); 29648c2ecf20Sopenharmony_ci} 29658c2ecf20Sopenharmony_ci 29668c2ecf20Sopenharmony_cistatic void yukon_set_multicast(struct net_device *dev) 29678c2ecf20Sopenharmony_ci{ 29688c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 29698c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 29708c2ecf20Sopenharmony_ci int port = skge->port; 29718c2ecf20Sopenharmony_ci struct netdev_hw_addr *ha; 29728c2ecf20Sopenharmony_ci int rx_pause = (skge->flow_status == FLOW_STAT_REM_SEND || 29738c2ecf20Sopenharmony_ci skge->flow_status == FLOW_STAT_SYMMETRIC); 29748c2ecf20Sopenharmony_ci u16 reg; 29758c2ecf20Sopenharmony_ci u8 filter[8]; 29768c2ecf20Sopenharmony_ci 29778c2ecf20Sopenharmony_ci memset(filter, 0, sizeof(filter)); 29788c2ecf20Sopenharmony_ci 29798c2ecf20Sopenharmony_ci reg = gma_read16(hw, port, GM_RX_CTRL); 29808c2ecf20Sopenharmony_ci reg |= GM_RXCR_UCF_ENA; 29818c2ecf20Sopenharmony_ci 29828c2ecf20Sopenharmony_ci if (dev->flags & IFF_PROMISC) /* promiscuous */ 29838c2ecf20Sopenharmony_ci reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); 29848c2ecf20Sopenharmony_ci else if (dev->flags & IFF_ALLMULTI) /* all multicast */ 29858c2ecf20Sopenharmony_ci memset(filter, 0xff, sizeof(filter)); 29868c2ecf20Sopenharmony_ci else if (netdev_mc_empty(dev) && !rx_pause)/* no multicast */ 29878c2ecf20Sopenharmony_ci reg &= ~GM_RXCR_MCF_ENA; 29888c2ecf20Sopenharmony_ci else { 29898c2ecf20Sopenharmony_ci reg |= GM_RXCR_MCF_ENA; 29908c2ecf20Sopenharmony_ci 29918c2ecf20Sopenharmony_ci if (rx_pause) 29928c2ecf20Sopenharmony_ci yukon_add_filter(filter, pause_mc_addr); 29938c2ecf20Sopenharmony_ci 29948c2ecf20Sopenharmony_ci netdev_for_each_mc_addr(ha, dev) 29958c2ecf20Sopenharmony_ci yukon_add_filter(filter, ha->addr); 29968c2ecf20Sopenharmony_ci } 29978c2ecf20Sopenharmony_ci 29988c2ecf20Sopenharmony_ci 29998c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H1, 30008c2ecf20Sopenharmony_ci (u16)filter[0] | ((u16)filter[1] << 8)); 30018c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H2, 30028c2ecf20Sopenharmony_ci (u16)filter[2] | ((u16)filter[3] << 8)); 30038c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H3, 30048c2ecf20Sopenharmony_ci (u16)filter[4] | ((u16)filter[5] << 8)); 30058c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H4, 30068c2ecf20Sopenharmony_ci (u16)filter[6] | ((u16)filter[7] << 8)); 30078c2ecf20Sopenharmony_ci 30088c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_RX_CTRL, reg); 30098c2ecf20Sopenharmony_ci} 30108c2ecf20Sopenharmony_ci 30118c2ecf20Sopenharmony_cistatic inline u16 phy_length(const struct skge_hw *hw, u32 status) 30128c2ecf20Sopenharmony_ci{ 30138c2ecf20Sopenharmony_ci if (is_genesis(hw)) 30148c2ecf20Sopenharmony_ci return status >> XMR_FS_LEN_SHIFT; 30158c2ecf20Sopenharmony_ci else 30168c2ecf20Sopenharmony_ci return status >> GMR_FS_LEN_SHIFT; 30178c2ecf20Sopenharmony_ci} 30188c2ecf20Sopenharmony_ci 30198c2ecf20Sopenharmony_cistatic inline int bad_phy_status(const struct skge_hw *hw, u32 status) 30208c2ecf20Sopenharmony_ci{ 30218c2ecf20Sopenharmony_ci if (is_genesis(hw)) 30228c2ecf20Sopenharmony_ci return (status & (XMR_FS_ERR | XMR_FS_2L_VLAN)) != 0; 30238c2ecf20Sopenharmony_ci else 30248c2ecf20Sopenharmony_ci return (status & GMR_FS_ANY_ERR) || 30258c2ecf20Sopenharmony_ci (status & GMR_FS_RX_OK) == 0; 30268c2ecf20Sopenharmony_ci} 30278c2ecf20Sopenharmony_ci 30288c2ecf20Sopenharmony_cistatic void skge_set_multicast(struct net_device *dev) 30298c2ecf20Sopenharmony_ci{ 30308c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 30318c2ecf20Sopenharmony_ci 30328c2ecf20Sopenharmony_ci if (is_genesis(skge->hw)) 30338c2ecf20Sopenharmony_ci genesis_set_multicast(dev); 30348c2ecf20Sopenharmony_ci else 30358c2ecf20Sopenharmony_ci yukon_set_multicast(dev); 30368c2ecf20Sopenharmony_ci 30378c2ecf20Sopenharmony_ci} 30388c2ecf20Sopenharmony_ci 30398c2ecf20Sopenharmony_ci 30408c2ecf20Sopenharmony_ci/* Get receive buffer from descriptor. 30418c2ecf20Sopenharmony_ci * Handles copy of small buffers and reallocation failures 30428c2ecf20Sopenharmony_ci */ 30438c2ecf20Sopenharmony_cistatic struct sk_buff *skge_rx_get(struct net_device *dev, 30448c2ecf20Sopenharmony_ci struct skge_element *e, 30458c2ecf20Sopenharmony_ci u32 control, u32 status, u16 csum) 30468c2ecf20Sopenharmony_ci{ 30478c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 30488c2ecf20Sopenharmony_ci struct sk_buff *skb; 30498c2ecf20Sopenharmony_ci u16 len = control & BMU_BBC; 30508c2ecf20Sopenharmony_ci 30518c2ecf20Sopenharmony_ci netif_printk(skge, rx_status, KERN_DEBUG, skge->netdev, 30528c2ecf20Sopenharmony_ci "rx slot %td status 0x%x len %d\n", 30538c2ecf20Sopenharmony_ci e - skge->rx_ring.start, status, len); 30548c2ecf20Sopenharmony_ci 30558c2ecf20Sopenharmony_ci if (len > skge->rx_buf_size) 30568c2ecf20Sopenharmony_ci goto error; 30578c2ecf20Sopenharmony_ci 30588c2ecf20Sopenharmony_ci if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF)) 30598c2ecf20Sopenharmony_ci goto error; 30608c2ecf20Sopenharmony_ci 30618c2ecf20Sopenharmony_ci if (bad_phy_status(skge->hw, status)) 30628c2ecf20Sopenharmony_ci goto error; 30638c2ecf20Sopenharmony_ci 30648c2ecf20Sopenharmony_ci if (phy_length(skge->hw, status) != len) 30658c2ecf20Sopenharmony_ci goto error; 30668c2ecf20Sopenharmony_ci 30678c2ecf20Sopenharmony_ci if (len < RX_COPY_THRESHOLD) { 30688c2ecf20Sopenharmony_ci skb = netdev_alloc_skb_ip_align(dev, len); 30698c2ecf20Sopenharmony_ci if (!skb) 30708c2ecf20Sopenharmony_ci goto resubmit; 30718c2ecf20Sopenharmony_ci 30728c2ecf20Sopenharmony_ci dma_sync_single_for_cpu(&skge->hw->pdev->dev, 30738c2ecf20Sopenharmony_ci dma_unmap_addr(e, mapaddr), 30748c2ecf20Sopenharmony_ci dma_unmap_len(e, maplen), 30758c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 30768c2ecf20Sopenharmony_ci skb_copy_from_linear_data(e->skb, skb->data, len); 30778c2ecf20Sopenharmony_ci dma_sync_single_for_device(&skge->hw->pdev->dev, 30788c2ecf20Sopenharmony_ci dma_unmap_addr(e, mapaddr), 30798c2ecf20Sopenharmony_ci dma_unmap_len(e, maplen), 30808c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 30818c2ecf20Sopenharmony_ci skge_rx_reuse(e, skge->rx_buf_size); 30828c2ecf20Sopenharmony_ci } else { 30838c2ecf20Sopenharmony_ci struct skge_element ee; 30848c2ecf20Sopenharmony_ci struct sk_buff *nskb; 30858c2ecf20Sopenharmony_ci 30868c2ecf20Sopenharmony_ci nskb = netdev_alloc_skb_ip_align(dev, skge->rx_buf_size); 30878c2ecf20Sopenharmony_ci if (!nskb) 30888c2ecf20Sopenharmony_ci goto resubmit; 30898c2ecf20Sopenharmony_ci 30908c2ecf20Sopenharmony_ci ee = *e; 30918c2ecf20Sopenharmony_ci 30928c2ecf20Sopenharmony_ci skb = ee.skb; 30938c2ecf20Sopenharmony_ci prefetch(skb->data); 30948c2ecf20Sopenharmony_ci 30958c2ecf20Sopenharmony_ci if (skge_rx_setup(skge, e, nskb, skge->rx_buf_size) < 0) { 30968c2ecf20Sopenharmony_ci dev_kfree_skb(nskb); 30978c2ecf20Sopenharmony_ci goto resubmit; 30988c2ecf20Sopenharmony_ci } 30998c2ecf20Sopenharmony_ci 31008c2ecf20Sopenharmony_ci dma_unmap_single(&skge->hw->pdev->dev, 31018c2ecf20Sopenharmony_ci dma_unmap_addr(&ee, mapaddr), 31028c2ecf20Sopenharmony_ci dma_unmap_len(&ee, maplen), DMA_FROM_DEVICE); 31038c2ecf20Sopenharmony_ci } 31048c2ecf20Sopenharmony_ci 31058c2ecf20Sopenharmony_ci skb_put(skb, len); 31068c2ecf20Sopenharmony_ci 31078c2ecf20Sopenharmony_ci if (dev->features & NETIF_F_RXCSUM) { 31088c2ecf20Sopenharmony_ci skb->csum = le16_to_cpu(csum); 31098c2ecf20Sopenharmony_ci skb->ip_summed = CHECKSUM_COMPLETE; 31108c2ecf20Sopenharmony_ci } 31118c2ecf20Sopenharmony_ci 31128c2ecf20Sopenharmony_ci skb->protocol = eth_type_trans(skb, dev); 31138c2ecf20Sopenharmony_ci 31148c2ecf20Sopenharmony_ci return skb; 31158c2ecf20Sopenharmony_cierror: 31168c2ecf20Sopenharmony_ci 31178c2ecf20Sopenharmony_ci netif_printk(skge, rx_err, KERN_DEBUG, skge->netdev, 31188c2ecf20Sopenharmony_ci "rx err, slot %td control 0x%x status 0x%x\n", 31198c2ecf20Sopenharmony_ci e - skge->rx_ring.start, control, status); 31208c2ecf20Sopenharmony_ci 31218c2ecf20Sopenharmony_ci if (is_genesis(skge->hw)) { 31228c2ecf20Sopenharmony_ci if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR)) 31238c2ecf20Sopenharmony_ci dev->stats.rx_length_errors++; 31248c2ecf20Sopenharmony_ci if (status & XMR_FS_FRA_ERR) 31258c2ecf20Sopenharmony_ci dev->stats.rx_frame_errors++; 31268c2ecf20Sopenharmony_ci if (status & XMR_FS_FCS_ERR) 31278c2ecf20Sopenharmony_ci dev->stats.rx_crc_errors++; 31288c2ecf20Sopenharmony_ci } else { 31298c2ecf20Sopenharmony_ci if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE)) 31308c2ecf20Sopenharmony_ci dev->stats.rx_length_errors++; 31318c2ecf20Sopenharmony_ci if (status & GMR_FS_FRAGMENT) 31328c2ecf20Sopenharmony_ci dev->stats.rx_frame_errors++; 31338c2ecf20Sopenharmony_ci if (status & GMR_FS_CRC_ERR) 31348c2ecf20Sopenharmony_ci dev->stats.rx_crc_errors++; 31358c2ecf20Sopenharmony_ci } 31368c2ecf20Sopenharmony_ci 31378c2ecf20Sopenharmony_ciresubmit: 31388c2ecf20Sopenharmony_ci skge_rx_reuse(e, skge->rx_buf_size); 31398c2ecf20Sopenharmony_ci return NULL; 31408c2ecf20Sopenharmony_ci} 31418c2ecf20Sopenharmony_ci 31428c2ecf20Sopenharmony_ci/* Free all buffers in Tx ring which are no longer owned by device */ 31438c2ecf20Sopenharmony_cistatic void skge_tx_done(struct net_device *dev) 31448c2ecf20Sopenharmony_ci{ 31458c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 31468c2ecf20Sopenharmony_ci struct skge_ring *ring = &skge->tx_ring; 31478c2ecf20Sopenharmony_ci struct skge_element *e; 31488c2ecf20Sopenharmony_ci unsigned int bytes_compl = 0, pkts_compl = 0; 31498c2ecf20Sopenharmony_ci 31508c2ecf20Sopenharmony_ci skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F); 31518c2ecf20Sopenharmony_ci 31528c2ecf20Sopenharmony_ci for (e = ring->to_clean; e != ring->to_use; e = e->next) { 31538c2ecf20Sopenharmony_ci u32 control = ((const struct skge_tx_desc *) e->desc)->control; 31548c2ecf20Sopenharmony_ci 31558c2ecf20Sopenharmony_ci if (control & BMU_OWN) 31568c2ecf20Sopenharmony_ci break; 31578c2ecf20Sopenharmony_ci 31588c2ecf20Sopenharmony_ci skge_tx_unmap(skge->hw->pdev, e, control); 31598c2ecf20Sopenharmony_ci 31608c2ecf20Sopenharmony_ci if (control & BMU_EOF) { 31618c2ecf20Sopenharmony_ci netif_printk(skge, tx_done, KERN_DEBUG, skge->netdev, 31628c2ecf20Sopenharmony_ci "tx done slot %td\n", 31638c2ecf20Sopenharmony_ci e - skge->tx_ring.start); 31648c2ecf20Sopenharmony_ci 31658c2ecf20Sopenharmony_ci pkts_compl++; 31668c2ecf20Sopenharmony_ci bytes_compl += e->skb->len; 31678c2ecf20Sopenharmony_ci 31688c2ecf20Sopenharmony_ci dev_consume_skb_any(e->skb); 31698c2ecf20Sopenharmony_ci } 31708c2ecf20Sopenharmony_ci } 31718c2ecf20Sopenharmony_ci netdev_completed_queue(dev, pkts_compl, bytes_compl); 31728c2ecf20Sopenharmony_ci skge->tx_ring.to_clean = e; 31738c2ecf20Sopenharmony_ci 31748c2ecf20Sopenharmony_ci /* Can run lockless until we need to synchronize to restart queue. */ 31758c2ecf20Sopenharmony_ci smp_mb(); 31768c2ecf20Sopenharmony_ci 31778c2ecf20Sopenharmony_ci if (unlikely(netif_queue_stopped(dev) && 31788c2ecf20Sopenharmony_ci skge_avail(&skge->tx_ring) > TX_LOW_WATER)) { 31798c2ecf20Sopenharmony_ci netif_tx_lock(dev); 31808c2ecf20Sopenharmony_ci if (unlikely(netif_queue_stopped(dev) && 31818c2ecf20Sopenharmony_ci skge_avail(&skge->tx_ring) > TX_LOW_WATER)) { 31828c2ecf20Sopenharmony_ci netif_wake_queue(dev); 31838c2ecf20Sopenharmony_ci 31848c2ecf20Sopenharmony_ci } 31858c2ecf20Sopenharmony_ci netif_tx_unlock(dev); 31868c2ecf20Sopenharmony_ci } 31878c2ecf20Sopenharmony_ci} 31888c2ecf20Sopenharmony_ci 31898c2ecf20Sopenharmony_cistatic int skge_poll(struct napi_struct *napi, int budget) 31908c2ecf20Sopenharmony_ci{ 31918c2ecf20Sopenharmony_ci struct skge_port *skge = container_of(napi, struct skge_port, napi); 31928c2ecf20Sopenharmony_ci struct net_device *dev = skge->netdev; 31938c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 31948c2ecf20Sopenharmony_ci struct skge_ring *ring = &skge->rx_ring; 31958c2ecf20Sopenharmony_ci struct skge_element *e; 31968c2ecf20Sopenharmony_ci int work_done = 0; 31978c2ecf20Sopenharmony_ci 31988c2ecf20Sopenharmony_ci skge_tx_done(dev); 31998c2ecf20Sopenharmony_ci 32008c2ecf20Sopenharmony_ci skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F); 32018c2ecf20Sopenharmony_ci 32028c2ecf20Sopenharmony_ci for (e = ring->to_clean; prefetch(e->next), work_done < budget; e = e->next) { 32038c2ecf20Sopenharmony_ci struct skge_rx_desc *rd = e->desc; 32048c2ecf20Sopenharmony_ci struct sk_buff *skb; 32058c2ecf20Sopenharmony_ci u32 control; 32068c2ecf20Sopenharmony_ci 32078c2ecf20Sopenharmony_ci rmb(); 32088c2ecf20Sopenharmony_ci control = rd->control; 32098c2ecf20Sopenharmony_ci if (control & BMU_OWN) 32108c2ecf20Sopenharmony_ci break; 32118c2ecf20Sopenharmony_ci 32128c2ecf20Sopenharmony_ci skb = skge_rx_get(dev, e, control, rd->status, rd->csum2); 32138c2ecf20Sopenharmony_ci if (likely(skb)) { 32148c2ecf20Sopenharmony_ci napi_gro_receive(napi, skb); 32158c2ecf20Sopenharmony_ci ++work_done; 32168c2ecf20Sopenharmony_ci } 32178c2ecf20Sopenharmony_ci } 32188c2ecf20Sopenharmony_ci ring->to_clean = e; 32198c2ecf20Sopenharmony_ci 32208c2ecf20Sopenharmony_ci /* restart receiver */ 32218c2ecf20Sopenharmony_ci wmb(); 32228c2ecf20Sopenharmony_ci skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_START); 32238c2ecf20Sopenharmony_ci 32248c2ecf20Sopenharmony_ci if (work_done < budget && napi_complete_done(napi, work_done)) { 32258c2ecf20Sopenharmony_ci unsigned long flags; 32268c2ecf20Sopenharmony_ci 32278c2ecf20Sopenharmony_ci spin_lock_irqsave(&hw->hw_lock, flags); 32288c2ecf20Sopenharmony_ci hw->intr_mask |= napimask[skge->port]; 32298c2ecf20Sopenharmony_ci skge_write32(hw, B0_IMSK, hw->intr_mask); 32308c2ecf20Sopenharmony_ci skge_read32(hw, B0_IMSK); 32318c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hw->hw_lock, flags); 32328c2ecf20Sopenharmony_ci } 32338c2ecf20Sopenharmony_ci 32348c2ecf20Sopenharmony_ci return work_done; 32358c2ecf20Sopenharmony_ci} 32368c2ecf20Sopenharmony_ci 32378c2ecf20Sopenharmony_ci/* Parity errors seem to happen when Genesis is connected to a switch 32388c2ecf20Sopenharmony_ci * with no other ports present. Heartbeat error?? 32398c2ecf20Sopenharmony_ci */ 32408c2ecf20Sopenharmony_cistatic void skge_mac_parity(struct skge_hw *hw, int port) 32418c2ecf20Sopenharmony_ci{ 32428c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 32438c2ecf20Sopenharmony_ci 32448c2ecf20Sopenharmony_ci ++dev->stats.tx_heartbeat_errors; 32458c2ecf20Sopenharmony_ci 32468c2ecf20Sopenharmony_ci if (is_genesis(hw)) 32478c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), 32488c2ecf20Sopenharmony_ci MFF_CLR_PERR); 32498c2ecf20Sopenharmony_ci else 32508c2ecf20Sopenharmony_ci /* HW-Bug #8: cleared by GMF_CLI_TX_FC instead of GMF_CLI_TX_PE */ 32518c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), 32528c2ecf20Sopenharmony_ci (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0) 32538c2ecf20Sopenharmony_ci ? GMF_CLI_TX_FC : GMF_CLI_TX_PE); 32548c2ecf20Sopenharmony_ci} 32558c2ecf20Sopenharmony_ci 32568c2ecf20Sopenharmony_cistatic void skge_mac_intr(struct skge_hw *hw, int port) 32578c2ecf20Sopenharmony_ci{ 32588c2ecf20Sopenharmony_ci if (is_genesis(hw)) 32598c2ecf20Sopenharmony_ci genesis_mac_intr(hw, port); 32608c2ecf20Sopenharmony_ci else 32618c2ecf20Sopenharmony_ci yukon_mac_intr(hw, port); 32628c2ecf20Sopenharmony_ci} 32638c2ecf20Sopenharmony_ci 32648c2ecf20Sopenharmony_ci/* Handle device specific framing and timeout interrupts */ 32658c2ecf20Sopenharmony_cistatic void skge_error_irq(struct skge_hw *hw) 32668c2ecf20Sopenharmony_ci{ 32678c2ecf20Sopenharmony_ci struct pci_dev *pdev = hw->pdev; 32688c2ecf20Sopenharmony_ci u32 hwstatus = skge_read32(hw, B0_HWE_ISRC); 32698c2ecf20Sopenharmony_ci 32708c2ecf20Sopenharmony_ci if (is_genesis(hw)) { 32718c2ecf20Sopenharmony_ci /* clear xmac errors */ 32728c2ecf20Sopenharmony_ci if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1)) 32738c2ecf20Sopenharmony_ci skge_write16(hw, RX_MFF_CTRL1, MFF_CLR_INSTAT); 32748c2ecf20Sopenharmony_ci if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2)) 32758c2ecf20Sopenharmony_ci skge_write16(hw, RX_MFF_CTRL2, MFF_CLR_INSTAT); 32768c2ecf20Sopenharmony_ci } else { 32778c2ecf20Sopenharmony_ci /* Timestamp (unused) overflow */ 32788c2ecf20Sopenharmony_ci if (hwstatus & IS_IRQ_TIST_OV) 32798c2ecf20Sopenharmony_ci skge_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ); 32808c2ecf20Sopenharmony_ci } 32818c2ecf20Sopenharmony_ci 32828c2ecf20Sopenharmony_ci if (hwstatus & IS_RAM_RD_PAR) { 32838c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "Ram read data parity error\n"); 32848c2ecf20Sopenharmony_ci skge_write16(hw, B3_RI_CTRL, RI_CLR_RD_PERR); 32858c2ecf20Sopenharmony_ci } 32868c2ecf20Sopenharmony_ci 32878c2ecf20Sopenharmony_ci if (hwstatus & IS_RAM_WR_PAR) { 32888c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "Ram write data parity error\n"); 32898c2ecf20Sopenharmony_ci skge_write16(hw, B3_RI_CTRL, RI_CLR_WR_PERR); 32908c2ecf20Sopenharmony_ci } 32918c2ecf20Sopenharmony_ci 32928c2ecf20Sopenharmony_ci if (hwstatus & IS_M1_PAR_ERR) 32938c2ecf20Sopenharmony_ci skge_mac_parity(hw, 0); 32948c2ecf20Sopenharmony_ci 32958c2ecf20Sopenharmony_ci if (hwstatus & IS_M2_PAR_ERR) 32968c2ecf20Sopenharmony_ci skge_mac_parity(hw, 1); 32978c2ecf20Sopenharmony_ci 32988c2ecf20Sopenharmony_ci if (hwstatus & IS_R1_PAR_ERR) { 32998c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "%s: receive queue parity error\n", 33008c2ecf20Sopenharmony_ci hw->dev[0]->name); 33018c2ecf20Sopenharmony_ci skge_write32(hw, B0_R1_CSR, CSR_IRQ_CL_P); 33028c2ecf20Sopenharmony_ci } 33038c2ecf20Sopenharmony_ci 33048c2ecf20Sopenharmony_ci if (hwstatus & IS_R2_PAR_ERR) { 33058c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "%s: receive queue parity error\n", 33068c2ecf20Sopenharmony_ci hw->dev[1]->name); 33078c2ecf20Sopenharmony_ci skge_write32(hw, B0_R2_CSR, CSR_IRQ_CL_P); 33088c2ecf20Sopenharmony_ci } 33098c2ecf20Sopenharmony_ci 33108c2ecf20Sopenharmony_ci if (hwstatus & (IS_IRQ_MST_ERR|IS_IRQ_STAT)) { 33118c2ecf20Sopenharmony_ci u16 pci_status, pci_cmd; 33128c2ecf20Sopenharmony_ci 33138c2ecf20Sopenharmony_ci pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); 33148c2ecf20Sopenharmony_ci pci_read_config_word(pdev, PCI_STATUS, &pci_status); 33158c2ecf20Sopenharmony_ci 33168c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "PCI error cmd=%#x status=%#x\n", 33178c2ecf20Sopenharmony_ci pci_cmd, pci_status); 33188c2ecf20Sopenharmony_ci 33198c2ecf20Sopenharmony_ci /* Write the error bits back to clear them. */ 33208c2ecf20Sopenharmony_ci pci_status &= PCI_STATUS_ERROR_BITS; 33218c2ecf20Sopenharmony_ci skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 33228c2ecf20Sopenharmony_ci pci_write_config_word(pdev, PCI_COMMAND, 33238c2ecf20Sopenharmony_ci pci_cmd | PCI_COMMAND_SERR | PCI_COMMAND_PARITY); 33248c2ecf20Sopenharmony_ci pci_write_config_word(pdev, PCI_STATUS, pci_status); 33258c2ecf20Sopenharmony_ci skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 33268c2ecf20Sopenharmony_ci 33278c2ecf20Sopenharmony_ci /* if error still set then just ignore it */ 33288c2ecf20Sopenharmony_ci hwstatus = skge_read32(hw, B0_HWE_ISRC); 33298c2ecf20Sopenharmony_ci if (hwstatus & IS_IRQ_STAT) { 33308c2ecf20Sopenharmony_ci dev_warn(&hw->pdev->dev, "unable to clear error (so ignoring them)\n"); 33318c2ecf20Sopenharmony_ci hw->intr_mask &= ~IS_HW_ERR; 33328c2ecf20Sopenharmony_ci } 33338c2ecf20Sopenharmony_ci } 33348c2ecf20Sopenharmony_ci} 33358c2ecf20Sopenharmony_ci 33368c2ecf20Sopenharmony_ci/* 33378c2ecf20Sopenharmony_ci * Interrupt from PHY are handled in tasklet (softirq) 33388c2ecf20Sopenharmony_ci * because accessing phy registers requires spin wait which might 33398c2ecf20Sopenharmony_ci * cause excess interrupt latency. 33408c2ecf20Sopenharmony_ci */ 33418c2ecf20Sopenharmony_cistatic void skge_extirq(struct tasklet_struct *t) 33428c2ecf20Sopenharmony_ci{ 33438c2ecf20Sopenharmony_ci struct skge_hw *hw = from_tasklet(hw, t, phy_task); 33448c2ecf20Sopenharmony_ci int port; 33458c2ecf20Sopenharmony_ci 33468c2ecf20Sopenharmony_ci for (port = 0; port < hw->ports; port++) { 33478c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 33488c2ecf20Sopenharmony_ci 33498c2ecf20Sopenharmony_ci if (netif_running(dev)) { 33508c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 33518c2ecf20Sopenharmony_ci 33528c2ecf20Sopenharmony_ci spin_lock(&hw->phy_lock); 33538c2ecf20Sopenharmony_ci if (!is_genesis(hw)) 33548c2ecf20Sopenharmony_ci yukon_phy_intr(skge); 33558c2ecf20Sopenharmony_ci else if (hw->phy_type == SK_PHY_BCOM) 33568c2ecf20Sopenharmony_ci bcom_phy_intr(skge); 33578c2ecf20Sopenharmony_ci spin_unlock(&hw->phy_lock); 33588c2ecf20Sopenharmony_ci } 33598c2ecf20Sopenharmony_ci } 33608c2ecf20Sopenharmony_ci 33618c2ecf20Sopenharmony_ci spin_lock_irq(&hw->hw_lock); 33628c2ecf20Sopenharmony_ci hw->intr_mask |= IS_EXT_REG; 33638c2ecf20Sopenharmony_ci skge_write32(hw, B0_IMSK, hw->intr_mask); 33648c2ecf20Sopenharmony_ci skge_read32(hw, B0_IMSK); 33658c2ecf20Sopenharmony_ci spin_unlock_irq(&hw->hw_lock); 33668c2ecf20Sopenharmony_ci} 33678c2ecf20Sopenharmony_ci 33688c2ecf20Sopenharmony_cistatic irqreturn_t skge_intr(int irq, void *dev_id) 33698c2ecf20Sopenharmony_ci{ 33708c2ecf20Sopenharmony_ci struct skge_hw *hw = dev_id; 33718c2ecf20Sopenharmony_ci u32 status; 33728c2ecf20Sopenharmony_ci int handled = 0; 33738c2ecf20Sopenharmony_ci 33748c2ecf20Sopenharmony_ci spin_lock(&hw->hw_lock); 33758c2ecf20Sopenharmony_ci /* Reading this register masks IRQ */ 33768c2ecf20Sopenharmony_ci status = skge_read32(hw, B0_SP_ISRC); 33778c2ecf20Sopenharmony_ci if (status == 0 || status == ~0) 33788c2ecf20Sopenharmony_ci goto out; 33798c2ecf20Sopenharmony_ci 33808c2ecf20Sopenharmony_ci handled = 1; 33818c2ecf20Sopenharmony_ci status &= hw->intr_mask; 33828c2ecf20Sopenharmony_ci if (status & IS_EXT_REG) { 33838c2ecf20Sopenharmony_ci hw->intr_mask &= ~IS_EXT_REG; 33848c2ecf20Sopenharmony_ci tasklet_schedule(&hw->phy_task); 33858c2ecf20Sopenharmony_ci } 33868c2ecf20Sopenharmony_ci 33878c2ecf20Sopenharmony_ci if (status & (IS_XA1_F|IS_R1_F)) { 33888c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(hw->dev[0]); 33898c2ecf20Sopenharmony_ci hw->intr_mask &= ~(IS_XA1_F|IS_R1_F); 33908c2ecf20Sopenharmony_ci napi_schedule(&skge->napi); 33918c2ecf20Sopenharmony_ci } 33928c2ecf20Sopenharmony_ci 33938c2ecf20Sopenharmony_ci if (status & IS_PA_TO_TX1) 33948c2ecf20Sopenharmony_ci skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX1); 33958c2ecf20Sopenharmony_ci 33968c2ecf20Sopenharmony_ci if (status & IS_PA_TO_RX1) { 33978c2ecf20Sopenharmony_ci ++hw->dev[0]->stats.rx_over_errors; 33988c2ecf20Sopenharmony_ci skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX1); 33998c2ecf20Sopenharmony_ci } 34008c2ecf20Sopenharmony_ci 34018c2ecf20Sopenharmony_ci 34028c2ecf20Sopenharmony_ci if (status & IS_MAC1) 34038c2ecf20Sopenharmony_ci skge_mac_intr(hw, 0); 34048c2ecf20Sopenharmony_ci 34058c2ecf20Sopenharmony_ci if (hw->dev[1]) { 34068c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(hw->dev[1]); 34078c2ecf20Sopenharmony_ci 34088c2ecf20Sopenharmony_ci if (status & (IS_XA2_F|IS_R2_F)) { 34098c2ecf20Sopenharmony_ci hw->intr_mask &= ~(IS_XA2_F|IS_R2_F); 34108c2ecf20Sopenharmony_ci napi_schedule(&skge->napi); 34118c2ecf20Sopenharmony_ci } 34128c2ecf20Sopenharmony_ci 34138c2ecf20Sopenharmony_ci if (status & IS_PA_TO_RX2) { 34148c2ecf20Sopenharmony_ci ++hw->dev[1]->stats.rx_over_errors; 34158c2ecf20Sopenharmony_ci skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX2); 34168c2ecf20Sopenharmony_ci } 34178c2ecf20Sopenharmony_ci 34188c2ecf20Sopenharmony_ci if (status & IS_PA_TO_TX2) 34198c2ecf20Sopenharmony_ci skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX2); 34208c2ecf20Sopenharmony_ci 34218c2ecf20Sopenharmony_ci if (status & IS_MAC2) 34228c2ecf20Sopenharmony_ci skge_mac_intr(hw, 1); 34238c2ecf20Sopenharmony_ci } 34248c2ecf20Sopenharmony_ci 34258c2ecf20Sopenharmony_ci if (status & IS_HW_ERR) 34268c2ecf20Sopenharmony_ci skge_error_irq(hw); 34278c2ecf20Sopenharmony_ciout: 34288c2ecf20Sopenharmony_ci skge_write32(hw, B0_IMSK, hw->intr_mask); 34298c2ecf20Sopenharmony_ci skge_read32(hw, B0_IMSK); 34308c2ecf20Sopenharmony_ci spin_unlock(&hw->hw_lock); 34318c2ecf20Sopenharmony_ci 34328c2ecf20Sopenharmony_ci return IRQ_RETVAL(handled); 34338c2ecf20Sopenharmony_ci} 34348c2ecf20Sopenharmony_ci 34358c2ecf20Sopenharmony_ci#ifdef CONFIG_NET_POLL_CONTROLLER 34368c2ecf20Sopenharmony_cistatic void skge_netpoll(struct net_device *dev) 34378c2ecf20Sopenharmony_ci{ 34388c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 34398c2ecf20Sopenharmony_ci 34408c2ecf20Sopenharmony_ci disable_irq(dev->irq); 34418c2ecf20Sopenharmony_ci skge_intr(dev->irq, skge->hw); 34428c2ecf20Sopenharmony_ci enable_irq(dev->irq); 34438c2ecf20Sopenharmony_ci} 34448c2ecf20Sopenharmony_ci#endif 34458c2ecf20Sopenharmony_ci 34468c2ecf20Sopenharmony_cistatic int skge_set_mac_address(struct net_device *dev, void *p) 34478c2ecf20Sopenharmony_ci{ 34488c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 34498c2ecf20Sopenharmony_ci struct skge_hw *hw = skge->hw; 34508c2ecf20Sopenharmony_ci unsigned port = skge->port; 34518c2ecf20Sopenharmony_ci const struct sockaddr *addr = p; 34528c2ecf20Sopenharmony_ci u16 ctrl; 34538c2ecf20Sopenharmony_ci 34548c2ecf20Sopenharmony_ci if (!is_valid_ether_addr(addr->sa_data)) 34558c2ecf20Sopenharmony_ci return -EADDRNOTAVAIL; 34568c2ecf20Sopenharmony_ci 34578c2ecf20Sopenharmony_ci memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); 34588c2ecf20Sopenharmony_ci 34598c2ecf20Sopenharmony_ci if (!netif_running(dev)) { 34608c2ecf20Sopenharmony_ci memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN); 34618c2ecf20Sopenharmony_ci memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN); 34628c2ecf20Sopenharmony_ci } else { 34638c2ecf20Sopenharmony_ci /* disable Rx */ 34648c2ecf20Sopenharmony_ci spin_lock_bh(&hw->phy_lock); 34658c2ecf20Sopenharmony_ci ctrl = gma_read16(hw, port, GM_GP_CTRL); 34668c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, ctrl & ~GM_GPCR_RX_ENA); 34678c2ecf20Sopenharmony_ci 34688c2ecf20Sopenharmony_ci memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN); 34698c2ecf20Sopenharmony_ci memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN); 34708c2ecf20Sopenharmony_ci 34718c2ecf20Sopenharmony_ci if (is_genesis(hw)) 34728c2ecf20Sopenharmony_ci xm_outaddr(hw, port, XM_SA, dev->dev_addr); 34738c2ecf20Sopenharmony_ci else { 34748c2ecf20Sopenharmony_ci gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr); 34758c2ecf20Sopenharmony_ci gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr); 34768c2ecf20Sopenharmony_ci } 34778c2ecf20Sopenharmony_ci 34788c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, ctrl); 34798c2ecf20Sopenharmony_ci spin_unlock_bh(&hw->phy_lock); 34808c2ecf20Sopenharmony_ci } 34818c2ecf20Sopenharmony_ci 34828c2ecf20Sopenharmony_ci return 0; 34838c2ecf20Sopenharmony_ci} 34848c2ecf20Sopenharmony_ci 34858c2ecf20Sopenharmony_cistatic const struct { 34868c2ecf20Sopenharmony_ci u8 id; 34878c2ecf20Sopenharmony_ci const char *name; 34888c2ecf20Sopenharmony_ci} skge_chips[] = { 34898c2ecf20Sopenharmony_ci { CHIP_ID_GENESIS, "Genesis" }, 34908c2ecf20Sopenharmony_ci { CHIP_ID_YUKON, "Yukon" }, 34918c2ecf20Sopenharmony_ci { CHIP_ID_YUKON_LITE, "Yukon-Lite"}, 34928c2ecf20Sopenharmony_ci { CHIP_ID_YUKON_LP, "Yukon-LP"}, 34938c2ecf20Sopenharmony_ci}; 34948c2ecf20Sopenharmony_ci 34958c2ecf20Sopenharmony_cistatic const char *skge_board_name(const struct skge_hw *hw) 34968c2ecf20Sopenharmony_ci{ 34978c2ecf20Sopenharmony_ci int i; 34988c2ecf20Sopenharmony_ci static char buf[16]; 34998c2ecf20Sopenharmony_ci 35008c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(skge_chips); i++) 35018c2ecf20Sopenharmony_ci if (skge_chips[i].id == hw->chip_id) 35028c2ecf20Sopenharmony_ci return skge_chips[i].name; 35038c2ecf20Sopenharmony_ci 35048c2ecf20Sopenharmony_ci snprintf(buf, sizeof(buf), "chipid 0x%x", hw->chip_id); 35058c2ecf20Sopenharmony_ci return buf; 35068c2ecf20Sopenharmony_ci} 35078c2ecf20Sopenharmony_ci 35088c2ecf20Sopenharmony_ci 35098c2ecf20Sopenharmony_ci/* 35108c2ecf20Sopenharmony_ci * Setup the board data structure, but don't bring up 35118c2ecf20Sopenharmony_ci * the port(s) 35128c2ecf20Sopenharmony_ci */ 35138c2ecf20Sopenharmony_cistatic int skge_reset(struct skge_hw *hw) 35148c2ecf20Sopenharmony_ci{ 35158c2ecf20Sopenharmony_ci u32 reg; 35168c2ecf20Sopenharmony_ci u16 ctst, pci_status; 35178c2ecf20Sopenharmony_ci u8 t8, mac_cfg, pmd_type; 35188c2ecf20Sopenharmony_ci int i; 35198c2ecf20Sopenharmony_ci 35208c2ecf20Sopenharmony_ci ctst = skge_read16(hw, B0_CTST); 35218c2ecf20Sopenharmony_ci 35228c2ecf20Sopenharmony_ci /* do a SW reset */ 35238c2ecf20Sopenharmony_ci skge_write8(hw, B0_CTST, CS_RST_SET); 35248c2ecf20Sopenharmony_ci skge_write8(hw, B0_CTST, CS_RST_CLR); 35258c2ecf20Sopenharmony_ci 35268c2ecf20Sopenharmony_ci /* clear PCI errors, if any */ 35278c2ecf20Sopenharmony_ci skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 35288c2ecf20Sopenharmony_ci skge_write8(hw, B2_TST_CTRL2, 0); 35298c2ecf20Sopenharmony_ci 35308c2ecf20Sopenharmony_ci pci_read_config_word(hw->pdev, PCI_STATUS, &pci_status); 35318c2ecf20Sopenharmony_ci pci_write_config_word(hw->pdev, PCI_STATUS, 35328c2ecf20Sopenharmony_ci pci_status | PCI_STATUS_ERROR_BITS); 35338c2ecf20Sopenharmony_ci skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 35348c2ecf20Sopenharmony_ci skge_write8(hw, B0_CTST, CS_MRST_CLR); 35358c2ecf20Sopenharmony_ci 35368c2ecf20Sopenharmony_ci /* restore CLK_RUN bits (for Yukon-Lite) */ 35378c2ecf20Sopenharmony_ci skge_write16(hw, B0_CTST, 35388c2ecf20Sopenharmony_ci ctst & (CS_CLK_RUN_HOT|CS_CLK_RUN_RST|CS_CLK_RUN_ENA)); 35398c2ecf20Sopenharmony_ci 35408c2ecf20Sopenharmony_ci hw->chip_id = skge_read8(hw, B2_CHIP_ID); 35418c2ecf20Sopenharmony_ci hw->phy_type = skge_read8(hw, B2_E_1) & 0xf; 35428c2ecf20Sopenharmony_ci pmd_type = skge_read8(hw, B2_PMD_TYP); 35438c2ecf20Sopenharmony_ci hw->copper = (pmd_type == 'T' || pmd_type == '1'); 35448c2ecf20Sopenharmony_ci 35458c2ecf20Sopenharmony_ci switch (hw->chip_id) { 35468c2ecf20Sopenharmony_ci case CHIP_ID_GENESIS: 35478c2ecf20Sopenharmony_ci#ifdef CONFIG_SKGE_GENESIS 35488c2ecf20Sopenharmony_ci switch (hw->phy_type) { 35498c2ecf20Sopenharmony_ci case SK_PHY_XMAC: 35508c2ecf20Sopenharmony_ci hw->phy_addr = PHY_ADDR_XMAC; 35518c2ecf20Sopenharmony_ci break; 35528c2ecf20Sopenharmony_ci case SK_PHY_BCOM: 35538c2ecf20Sopenharmony_ci hw->phy_addr = PHY_ADDR_BCOM; 35548c2ecf20Sopenharmony_ci break; 35558c2ecf20Sopenharmony_ci default: 35568c2ecf20Sopenharmony_ci dev_err(&hw->pdev->dev, "unsupported phy type 0x%x\n", 35578c2ecf20Sopenharmony_ci hw->phy_type); 35588c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 35598c2ecf20Sopenharmony_ci } 35608c2ecf20Sopenharmony_ci break; 35618c2ecf20Sopenharmony_ci#else 35628c2ecf20Sopenharmony_ci dev_err(&hw->pdev->dev, "Genesis chip detected but not configured\n"); 35638c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 35648c2ecf20Sopenharmony_ci#endif 35658c2ecf20Sopenharmony_ci 35668c2ecf20Sopenharmony_ci case CHIP_ID_YUKON: 35678c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_LITE: 35688c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_LP: 35698c2ecf20Sopenharmony_ci if (hw->phy_type < SK_PHY_MARV_COPPER && pmd_type != 'S') 35708c2ecf20Sopenharmony_ci hw->copper = 1; 35718c2ecf20Sopenharmony_ci 35728c2ecf20Sopenharmony_ci hw->phy_addr = PHY_ADDR_MARV; 35738c2ecf20Sopenharmony_ci break; 35748c2ecf20Sopenharmony_ci 35758c2ecf20Sopenharmony_ci default: 35768c2ecf20Sopenharmony_ci dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n", 35778c2ecf20Sopenharmony_ci hw->chip_id); 35788c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 35798c2ecf20Sopenharmony_ci } 35808c2ecf20Sopenharmony_ci 35818c2ecf20Sopenharmony_ci mac_cfg = skge_read8(hw, B2_MAC_CFG); 35828c2ecf20Sopenharmony_ci hw->ports = (mac_cfg & CFG_SNG_MAC) ? 1 : 2; 35838c2ecf20Sopenharmony_ci hw->chip_rev = (mac_cfg & CFG_CHIP_R_MSK) >> 4; 35848c2ecf20Sopenharmony_ci 35858c2ecf20Sopenharmony_ci /* read the adapters RAM size */ 35868c2ecf20Sopenharmony_ci t8 = skge_read8(hw, B2_E_0); 35878c2ecf20Sopenharmony_ci if (is_genesis(hw)) { 35888c2ecf20Sopenharmony_ci if (t8 == 3) { 35898c2ecf20Sopenharmony_ci /* special case: 4 x 64k x 36, offset = 0x80000 */ 35908c2ecf20Sopenharmony_ci hw->ram_size = 0x100000; 35918c2ecf20Sopenharmony_ci hw->ram_offset = 0x80000; 35928c2ecf20Sopenharmony_ci } else 35938c2ecf20Sopenharmony_ci hw->ram_size = t8 * 512; 35948c2ecf20Sopenharmony_ci } else if (t8 == 0) 35958c2ecf20Sopenharmony_ci hw->ram_size = 0x20000; 35968c2ecf20Sopenharmony_ci else 35978c2ecf20Sopenharmony_ci hw->ram_size = t8 * 4096; 35988c2ecf20Sopenharmony_ci 35998c2ecf20Sopenharmony_ci hw->intr_mask = IS_HW_ERR; 36008c2ecf20Sopenharmony_ci 36018c2ecf20Sopenharmony_ci /* Use PHY IRQ for all but fiber based Genesis board */ 36028c2ecf20Sopenharmony_ci if (!(is_genesis(hw) && hw->phy_type == SK_PHY_XMAC)) 36038c2ecf20Sopenharmony_ci hw->intr_mask |= IS_EXT_REG; 36048c2ecf20Sopenharmony_ci 36058c2ecf20Sopenharmony_ci if (is_genesis(hw)) 36068c2ecf20Sopenharmony_ci genesis_init(hw); 36078c2ecf20Sopenharmony_ci else { 36088c2ecf20Sopenharmony_ci /* switch power to VCC (WA for VAUX problem) */ 36098c2ecf20Sopenharmony_ci skge_write8(hw, B0_POWER_CTRL, 36108c2ecf20Sopenharmony_ci PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON); 36118c2ecf20Sopenharmony_ci 36128c2ecf20Sopenharmony_ci /* avoid boards with stuck Hardware error bits */ 36138c2ecf20Sopenharmony_ci if ((skge_read32(hw, B0_ISRC) & IS_HW_ERR) && 36148c2ecf20Sopenharmony_ci (skge_read32(hw, B0_HWE_ISRC) & IS_IRQ_SENSOR)) { 36158c2ecf20Sopenharmony_ci dev_warn(&hw->pdev->dev, "stuck hardware sensor bit\n"); 36168c2ecf20Sopenharmony_ci hw->intr_mask &= ~IS_HW_ERR; 36178c2ecf20Sopenharmony_ci } 36188c2ecf20Sopenharmony_ci 36198c2ecf20Sopenharmony_ci /* Clear PHY COMA */ 36208c2ecf20Sopenharmony_ci skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 36218c2ecf20Sopenharmony_ci pci_read_config_dword(hw->pdev, PCI_DEV_REG1, ®); 36228c2ecf20Sopenharmony_ci reg &= ~PCI_PHY_COMA; 36238c2ecf20Sopenharmony_ci pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg); 36248c2ecf20Sopenharmony_ci skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 36258c2ecf20Sopenharmony_ci 36268c2ecf20Sopenharmony_ci 36278c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 36288c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET); 36298c2ecf20Sopenharmony_ci skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR); 36308c2ecf20Sopenharmony_ci } 36318c2ecf20Sopenharmony_ci } 36328c2ecf20Sopenharmony_ci 36338c2ecf20Sopenharmony_ci /* turn off hardware timer (unused) */ 36348c2ecf20Sopenharmony_ci skge_write8(hw, B2_TI_CTRL, TIM_STOP); 36358c2ecf20Sopenharmony_ci skge_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ); 36368c2ecf20Sopenharmony_ci skge_write8(hw, B0_LED, LED_STAT_ON); 36378c2ecf20Sopenharmony_ci 36388c2ecf20Sopenharmony_ci /* enable the Tx Arbiters */ 36398c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) 36408c2ecf20Sopenharmony_ci skge_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB); 36418c2ecf20Sopenharmony_ci 36428c2ecf20Sopenharmony_ci /* Initialize ram interface */ 36438c2ecf20Sopenharmony_ci skge_write16(hw, B3_RI_CTRL, RI_RST_CLR); 36448c2ecf20Sopenharmony_ci 36458c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_WTO_R1, SK_RI_TO_53); 36468c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_WTO_XA1, SK_RI_TO_53); 36478c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_WTO_XS1, SK_RI_TO_53); 36488c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_RTO_R1, SK_RI_TO_53); 36498c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_RTO_XA1, SK_RI_TO_53); 36508c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_RTO_XS1, SK_RI_TO_53); 36518c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_WTO_R2, SK_RI_TO_53); 36528c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_WTO_XA2, SK_RI_TO_53); 36538c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_WTO_XS2, SK_RI_TO_53); 36548c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_RTO_R2, SK_RI_TO_53); 36558c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_RTO_XA2, SK_RI_TO_53); 36568c2ecf20Sopenharmony_ci skge_write8(hw, B3_RI_RTO_XS2, SK_RI_TO_53); 36578c2ecf20Sopenharmony_ci 36588c2ecf20Sopenharmony_ci skge_write32(hw, B0_HWE_IMSK, IS_ERR_MSK); 36598c2ecf20Sopenharmony_ci 36608c2ecf20Sopenharmony_ci /* Set interrupt moderation for Transmit only 36618c2ecf20Sopenharmony_ci * Receive interrupts avoided by NAPI 36628c2ecf20Sopenharmony_ci */ 36638c2ecf20Sopenharmony_ci skge_write32(hw, B2_IRQM_MSK, IS_XA1_F|IS_XA2_F); 36648c2ecf20Sopenharmony_ci skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100)); 36658c2ecf20Sopenharmony_ci skge_write32(hw, B2_IRQM_CTRL, TIM_START); 36668c2ecf20Sopenharmony_ci 36678c2ecf20Sopenharmony_ci /* Leave irq disabled until first port is brought up. */ 36688c2ecf20Sopenharmony_ci skge_write32(hw, B0_IMSK, 0); 36698c2ecf20Sopenharmony_ci 36708c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 36718c2ecf20Sopenharmony_ci if (is_genesis(hw)) 36728c2ecf20Sopenharmony_ci genesis_reset(hw, i); 36738c2ecf20Sopenharmony_ci else 36748c2ecf20Sopenharmony_ci yukon_reset(hw, i); 36758c2ecf20Sopenharmony_ci } 36768c2ecf20Sopenharmony_ci 36778c2ecf20Sopenharmony_ci return 0; 36788c2ecf20Sopenharmony_ci} 36798c2ecf20Sopenharmony_ci 36808c2ecf20Sopenharmony_ci 36818c2ecf20Sopenharmony_ci#ifdef CONFIG_SKGE_DEBUG 36828c2ecf20Sopenharmony_ci 36838c2ecf20Sopenharmony_cistatic struct dentry *skge_debug; 36848c2ecf20Sopenharmony_ci 36858c2ecf20Sopenharmony_cistatic int skge_debug_show(struct seq_file *seq, void *v) 36868c2ecf20Sopenharmony_ci{ 36878c2ecf20Sopenharmony_ci struct net_device *dev = seq->private; 36888c2ecf20Sopenharmony_ci const struct skge_port *skge = netdev_priv(dev); 36898c2ecf20Sopenharmony_ci const struct skge_hw *hw = skge->hw; 36908c2ecf20Sopenharmony_ci const struct skge_element *e; 36918c2ecf20Sopenharmony_ci 36928c2ecf20Sopenharmony_ci if (!netif_running(dev)) 36938c2ecf20Sopenharmony_ci return -ENETDOWN; 36948c2ecf20Sopenharmony_ci 36958c2ecf20Sopenharmony_ci seq_printf(seq, "IRQ src=%x mask=%x\n", skge_read32(hw, B0_ISRC), 36968c2ecf20Sopenharmony_ci skge_read32(hw, B0_IMSK)); 36978c2ecf20Sopenharmony_ci 36988c2ecf20Sopenharmony_ci seq_printf(seq, "Tx Ring: (%d)\n", skge_avail(&skge->tx_ring)); 36998c2ecf20Sopenharmony_ci for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) { 37008c2ecf20Sopenharmony_ci const struct skge_tx_desc *t = e->desc; 37018c2ecf20Sopenharmony_ci seq_printf(seq, "%#x dma=%#x%08x %#x csum=%#x/%x/%x\n", 37028c2ecf20Sopenharmony_ci t->control, t->dma_hi, t->dma_lo, t->status, 37038c2ecf20Sopenharmony_ci t->csum_offs, t->csum_write, t->csum_start); 37048c2ecf20Sopenharmony_ci } 37058c2ecf20Sopenharmony_ci 37068c2ecf20Sopenharmony_ci seq_puts(seq, "\nRx Ring:\n"); 37078c2ecf20Sopenharmony_ci for (e = skge->rx_ring.to_clean; ; e = e->next) { 37088c2ecf20Sopenharmony_ci const struct skge_rx_desc *r = e->desc; 37098c2ecf20Sopenharmony_ci 37108c2ecf20Sopenharmony_ci if (r->control & BMU_OWN) 37118c2ecf20Sopenharmony_ci break; 37128c2ecf20Sopenharmony_ci 37138c2ecf20Sopenharmony_ci seq_printf(seq, "%#x dma=%#x%08x %#x %#x csum=%#x/%x\n", 37148c2ecf20Sopenharmony_ci r->control, r->dma_hi, r->dma_lo, r->status, 37158c2ecf20Sopenharmony_ci r->timestamp, r->csum1, r->csum1_start); 37168c2ecf20Sopenharmony_ci } 37178c2ecf20Sopenharmony_ci 37188c2ecf20Sopenharmony_ci return 0; 37198c2ecf20Sopenharmony_ci} 37208c2ecf20Sopenharmony_ciDEFINE_SHOW_ATTRIBUTE(skge_debug); 37218c2ecf20Sopenharmony_ci 37228c2ecf20Sopenharmony_ci/* 37238c2ecf20Sopenharmony_ci * Use network device events to create/remove/rename 37248c2ecf20Sopenharmony_ci * debugfs file entries 37258c2ecf20Sopenharmony_ci */ 37268c2ecf20Sopenharmony_cistatic int skge_device_event(struct notifier_block *unused, 37278c2ecf20Sopenharmony_ci unsigned long event, void *ptr) 37288c2ecf20Sopenharmony_ci{ 37298c2ecf20Sopenharmony_ci struct net_device *dev = netdev_notifier_info_to_dev(ptr); 37308c2ecf20Sopenharmony_ci struct skge_port *skge; 37318c2ecf20Sopenharmony_ci 37328c2ecf20Sopenharmony_ci if (dev->netdev_ops->ndo_open != &skge_up || !skge_debug) 37338c2ecf20Sopenharmony_ci goto done; 37348c2ecf20Sopenharmony_ci 37358c2ecf20Sopenharmony_ci skge = netdev_priv(dev); 37368c2ecf20Sopenharmony_ci switch (event) { 37378c2ecf20Sopenharmony_ci case NETDEV_CHANGENAME: 37388c2ecf20Sopenharmony_ci if (skge->debugfs) 37398c2ecf20Sopenharmony_ci skge->debugfs = debugfs_rename(skge_debug, 37408c2ecf20Sopenharmony_ci skge->debugfs, 37418c2ecf20Sopenharmony_ci skge_debug, dev->name); 37428c2ecf20Sopenharmony_ci break; 37438c2ecf20Sopenharmony_ci 37448c2ecf20Sopenharmony_ci case NETDEV_GOING_DOWN: 37458c2ecf20Sopenharmony_ci debugfs_remove(skge->debugfs); 37468c2ecf20Sopenharmony_ci skge->debugfs = NULL; 37478c2ecf20Sopenharmony_ci break; 37488c2ecf20Sopenharmony_ci 37498c2ecf20Sopenharmony_ci case NETDEV_UP: 37508c2ecf20Sopenharmony_ci skge->debugfs = debugfs_create_file(dev->name, 0444, skge_debug, 37518c2ecf20Sopenharmony_ci dev, &skge_debug_fops); 37528c2ecf20Sopenharmony_ci break; 37538c2ecf20Sopenharmony_ci } 37548c2ecf20Sopenharmony_ci 37558c2ecf20Sopenharmony_cidone: 37568c2ecf20Sopenharmony_ci return NOTIFY_DONE; 37578c2ecf20Sopenharmony_ci} 37588c2ecf20Sopenharmony_ci 37598c2ecf20Sopenharmony_cistatic struct notifier_block skge_notifier = { 37608c2ecf20Sopenharmony_ci .notifier_call = skge_device_event, 37618c2ecf20Sopenharmony_ci}; 37628c2ecf20Sopenharmony_ci 37638c2ecf20Sopenharmony_ci 37648c2ecf20Sopenharmony_cistatic __init void skge_debug_init(void) 37658c2ecf20Sopenharmony_ci{ 37668c2ecf20Sopenharmony_ci skge_debug = debugfs_create_dir("skge", NULL); 37678c2ecf20Sopenharmony_ci 37688c2ecf20Sopenharmony_ci register_netdevice_notifier(&skge_notifier); 37698c2ecf20Sopenharmony_ci} 37708c2ecf20Sopenharmony_ci 37718c2ecf20Sopenharmony_cistatic __exit void skge_debug_cleanup(void) 37728c2ecf20Sopenharmony_ci{ 37738c2ecf20Sopenharmony_ci if (skge_debug) { 37748c2ecf20Sopenharmony_ci unregister_netdevice_notifier(&skge_notifier); 37758c2ecf20Sopenharmony_ci debugfs_remove(skge_debug); 37768c2ecf20Sopenharmony_ci skge_debug = NULL; 37778c2ecf20Sopenharmony_ci } 37788c2ecf20Sopenharmony_ci} 37798c2ecf20Sopenharmony_ci 37808c2ecf20Sopenharmony_ci#else 37818c2ecf20Sopenharmony_ci#define skge_debug_init() 37828c2ecf20Sopenharmony_ci#define skge_debug_cleanup() 37838c2ecf20Sopenharmony_ci#endif 37848c2ecf20Sopenharmony_ci 37858c2ecf20Sopenharmony_cistatic const struct net_device_ops skge_netdev_ops = { 37868c2ecf20Sopenharmony_ci .ndo_open = skge_up, 37878c2ecf20Sopenharmony_ci .ndo_stop = skge_down, 37888c2ecf20Sopenharmony_ci .ndo_start_xmit = skge_xmit_frame, 37898c2ecf20Sopenharmony_ci .ndo_do_ioctl = skge_ioctl, 37908c2ecf20Sopenharmony_ci .ndo_get_stats = skge_get_stats, 37918c2ecf20Sopenharmony_ci .ndo_tx_timeout = skge_tx_timeout, 37928c2ecf20Sopenharmony_ci .ndo_change_mtu = skge_change_mtu, 37938c2ecf20Sopenharmony_ci .ndo_validate_addr = eth_validate_addr, 37948c2ecf20Sopenharmony_ci .ndo_set_rx_mode = skge_set_multicast, 37958c2ecf20Sopenharmony_ci .ndo_set_mac_address = skge_set_mac_address, 37968c2ecf20Sopenharmony_ci#ifdef CONFIG_NET_POLL_CONTROLLER 37978c2ecf20Sopenharmony_ci .ndo_poll_controller = skge_netpoll, 37988c2ecf20Sopenharmony_ci#endif 37998c2ecf20Sopenharmony_ci}; 38008c2ecf20Sopenharmony_ci 38018c2ecf20Sopenharmony_ci 38028c2ecf20Sopenharmony_ci/* Initialize network device */ 38038c2ecf20Sopenharmony_cistatic struct net_device *skge_devinit(struct skge_hw *hw, int port, 38048c2ecf20Sopenharmony_ci int highmem) 38058c2ecf20Sopenharmony_ci{ 38068c2ecf20Sopenharmony_ci struct skge_port *skge; 38078c2ecf20Sopenharmony_ci struct net_device *dev = alloc_etherdev(sizeof(*skge)); 38088c2ecf20Sopenharmony_ci 38098c2ecf20Sopenharmony_ci if (!dev) 38108c2ecf20Sopenharmony_ci return NULL; 38118c2ecf20Sopenharmony_ci 38128c2ecf20Sopenharmony_ci SET_NETDEV_DEV(dev, &hw->pdev->dev); 38138c2ecf20Sopenharmony_ci dev->netdev_ops = &skge_netdev_ops; 38148c2ecf20Sopenharmony_ci dev->ethtool_ops = &skge_ethtool_ops; 38158c2ecf20Sopenharmony_ci dev->watchdog_timeo = TX_WATCHDOG; 38168c2ecf20Sopenharmony_ci dev->irq = hw->pdev->irq; 38178c2ecf20Sopenharmony_ci 38188c2ecf20Sopenharmony_ci /* MTU range: 60 - 9000 */ 38198c2ecf20Sopenharmony_ci dev->min_mtu = ETH_ZLEN; 38208c2ecf20Sopenharmony_ci dev->max_mtu = ETH_JUMBO_MTU; 38218c2ecf20Sopenharmony_ci 38228c2ecf20Sopenharmony_ci if (highmem) 38238c2ecf20Sopenharmony_ci dev->features |= NETIF_F_HIGHDMA; 38248c2ecf20Sopenharmony_ci 38258c2ecf20Sopenharmony_ci skge = netdev_priv(dev); 38268c2ecf20Sopenharmony_ci netif_napi_add(dev, &skge->napi, skge_poll, NAPI_WEIGHT); 38278c2ecf20Sopenharmony_ci skge->netdev = dev; 38288c2ecf20Sopenharmony_ci skge->hw = hw; 38298c2ecf20Sopenharmony_ci skge->msg_enable = netif_msg_init(debug, default_msg); 38308c2ecf20Sopenharmony_ci 38318c2ecf20Sopenharmony_ci skge->tx_ring.count = DEFAULT_TX_RING_SIZE; 38328c2ecf20Sopenharmony_ci skge->rx_ring.count = DEFAULT_RX_RING_SIZE; 38338c2ecf20Sopenharmony_ci 38348c2ecf20Sopenharmony_ci /* Auto speed and flow control */ 38358c2ecf20Sopenharmony_ci skge->autoneg = AUTONEG_ENABLE; 38368c2ecf20Sopenharmony_ci skge->flow_control = FLOW_MODE_SYM_OR_REM; 38378c2ecf20Sopenharmony_ci skge->duplex = -1; 38388c2ecf20Sopenharmony_ci skge->speed = -1; 38398c2ecf20Sopenharmony_ci skge->advertising = skge_supported_modes(hw); 38408c2ecf20Sopenharmony_ci 38418c2ecf20Sopenharmony_ci if (device_can_wakeup(&hw->pdev->dev)) { 38428c2ecf20Sopenharmony_ci skge->wol = wol_supported(hw) & WAKE_MAGIC; 38438c2ecf20Sopenharmony_ci device_set_wakeup_enable(&hw->pdev->dev, skge->wol); 38448c2ecf20Sopenharmony_ci } 38458c2ecf20Sopenharmony_ci 38468c2ecf20Sopenharmony_ci hw->dev[port] = dev; 38478c2ecf20Sopenharmony_ci 38488c2ecf20Sopenharmony_ci skge->port = port; 38498c2ecf20Sopenharmony_ci 38508c2ecf20Sopenharmony_ci /* Only used for Genesis XMAC */ 38518c2ecf20Sopenharmony_ci if (is_genesis(hw)) 38528c2ecf20Sopenharmony_ci timer_setup(&skge->link_timer, xm_link_timer, 0); 38538c2ecf20Sopenharmony_ci else { 38548c2ecf20Sopenharmony_ci dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG | 38558c2ecf20Sopenharmony_ci NETIF_F_RXCSUM; 38568c2ecf20Sopenharmony_ci dev->features |= dev->hw_features; 38578c2ecf20Sopenharmony_ci } 38588c2ecf20Sopenharmony_ci 38598c2ecf20Sopenharmony_ci /* read the mac address */ 38608c2ecf20Sopenharmony_ci memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port*8, ETH_ALEN); 38618c2ecf20Sopenharmony_ci 38628c2ecf20Sopenharmony_ci return dev; 38638c2ecf20Sopenharmony_ci} 38648c2ecf20Sopenharmony_ci 38658c2ecf20Sopenharmony_cistatic void skge_show_addr(struct net_device *dev) 38668c2ecf20Sopenharmony_ci{ 38678c2ecf20Sopenharmony_ci const struct skge_port *skge = netdev_priv(dev); 38688c2ecf20Sopenharmony_ci 38698c2ecf20Sopenharmony_ci netif_info(skge, probe, skge->netdev, "addr %pM\n", dev->dev_addr); 38708c2ecf20Sopenharmony_ci} 38718c2ecf20Sopenharmony_ci 38728c2ecf20Sopenharmony_cistatic int only_32bit_dma; 38738c2ecf20Sopenharmony_ci 38748c2ecf20Sopenharmony_cistatic int skge_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 38758c2ecf20Sopenharmony_ci{ 38768c2ecf20Sopenharmony_ci struct net_device *dev, *dev1; 38778c2ecf20Sopenharmony_ci struct skge_hw *hw; 38788c2ecf20Sopenharmony_ci int err, using_dac = 0; 38798c2ecf20Sopenharmony_ci 38808c2ecf20Sopenharmony_ci err = pci_enable_device(pdev); 38818c2ecf20Sopenharmony_ci if (err) { 38828c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot enable PCI device\n"); 38838c2ecf20Sopenharmony_ci goto err_out; 38848c2ecf20Sopenharmony_ci } 38858c2ecf20Sopenharmony_ci 38868c2ecf20Sopenharmony_ci err = pci_request_regions(pdev, DRV_NAME); 38878c2ecf20Sopenharmony_ci if (err) { 38888c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot obtain PCI resources\n"); 38898c2ecf20Sopenharmony_ci goto err_out_disable_pdev; 38908c2ecf20Sopenharmony_ci } 38918c2ecf20Sopenharmony_ci 38928c2ecf20Sopenharmony_ci pci_set_master(pdev); 38938c2ecf20Sopenharmony_ci 38948c2ecf20Sopenharmony_ci if (!only_32bit_dma && !dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) { 38958c2ecf20Sopenharmony_ci using_dac = 1; 38968c2ecf20Sopenharmony_ci err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); 38978c2ecf20Sopenharmony_ci } else if (!(err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)))) { 38988c2ecf20Sopenharmony_ci using_dac = 0; 38998c2ecf20Sopenharmony_ci err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); 39008c2ecf20Sopenharmony_ci } 39018c2ecf20Sopenharmony_ci 39028c2ecf20Sopenharmony_ci if (err) { 39038c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "no usable DMA configuration\n"); 39048c2ecf20Sopenharmony_ci goto err_out_free_regions; 39058c2ecf20Sopenharmony_ci } 39068c2ecf20Sopenharmony_ci 39078c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN 39088c2ecf20Sopenharmony_ci /* byte swap descriptors in hardware */ 39098c2ecf20Sopenharmony_ci { 39108c2ecf20Sopenharmony_ci u32 reg; 39118c2ecf20Sopenharmony_ci 39128c2ecf20Sopenharmony_ci pci_read_config_dword(pdev, PCI_DEV_REG2, ®); 39138c2ecf20Sopenharmony_ci reg |= PCI_REV_DESC; 39148c2ecf20Sopenharmony_ci pci_write_config_dword(pdev, PCI_DEV_REG2, reg); 39158c2ecf20Sopenharmony_ci } 39168c2ecf20Sopenharmony_ci#endif 39178c2ecf20Sopenharmony_ci 39188c2ecf20Sopenharmony_ci err = -ENOMEM; 39198c2ecf20Sopenharmony_ci /* space for skge@pci:0000:04:00.0 */ 39208c2ecf20Sopenharmony_ci hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:") 39218c2ecf20Sopenharmony_ci + strlen(pci_name(pdev)) + 1, GFP_KERNEL); 39228c2ecf20Sopenharmony_ci if (!hw) 39238c2ecf20Sopenharmony_ci goto err_out_free_regions; 39248c2ecf20Sopenharmony_ci 39258c2ecf20Sopenharmony_ci sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev)); 39268c2ecf20Sopenharmony_ci 39278c2ecf20Sopenharmony_ci hw->pdev = pdev; 39288c2ecf20Sopenharmony_ci spin_lock_init(&hw->hw_lock); 39298c2ecf20Sopenharmony_ci spin_lock_init(&hw->phy_lock); 39308c2ecf20Sopenharmony_ci tasklet_setup(&hw->phy_task, skge_extirq); 39318c2ecf20Sopenharmony_ci 39328c2ecf20Sopenharmony_ci hw->regs = ioremap(pci_resource_start(pdev, 0), 0x4000); 39338c2ecf20Sopenharmony_ci if (!hw->regs) { 39348c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot map device registers\n"); 39358c2ecf20Sopenharmony_ci goto err_out_free_hw; 39368c2ecf20Sopenharmony_ci } 39378c2ecf20Sopenharmony_ci 39388c2ecf20Sopenharmony_ci err = skge_reset(hw); 39398c2ecf20Sopenharmony_ci if (err) 39408c2ecf20Sopenharmony_ci goto err_out_iounmap; 39418c2ecf20Sopenharmony_ci 39428c2ecf20Sopenharmony_ci pr_info("%s addr 0x%llx irq %d chip %s rev %d\n", 39438c2ecf20Sopenharmony_ci DRV_VERSION, 39448c2ecf20Sopenharmony_ci (unsigned long long)pci_resource_start(pdev, 0), pdev->irq, 39458c2ecf20Sopenharmony_ci skge_board_name(hw), hw->chip_rev); 39468c2ecf20Sopenharmony_ci 39478c2ecf20Sopenharmony_ci dev = skge_devinit(hw, 0, using_dac); 39488c2ecf20Sopenharmony_ci if (!dev) { 39498c2ecf20Sopenharmony_ci err = -ENOMEM; 39508c2ecf20Sopenharmony_ci goto err_out_led_off; 39518c2ecf20Sopenharmony_ci } 39528c2ecf20Sopenharmony_ci 39538c2ecf20Sopenharmony_ci /* Some motherboards are broken and has zero in ROM. */ 39548c2ecf20Sopenharmony_ci if (!is_valid_ether_addr(dev->dev_addr)) 39558c2ecf20Sopenharmony_ci dev_warn(&pdev->dev, "bad (zero?) ethernet address in rom\n"); 39568c2ecf20Sopenharmony_ci 39578c2ecf20Sopenharmony_ci err = register_netdev(dev); 39588c2ecf20Sopenharmony_ci if (err) { 39598c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot register net device\n"); 39608c2ecf20Sopenharmony_ci goto err_out_free_netdev; 39618c2ecf20Sopenharmony_ci } 39628c2ecf20Sopenharmony_ci 39638c2ecf20Sopenharmony_ci skge_show_addr(dev); 39648c2ecf20Sopenharmony_ci 39658c2ecf20Sopenharmony_ci if (hw->ports > 1) { 39668c2ecf20Sopenharmony_ci dev1 = skge_devinit(hw, 1, using_dac); 39678c2ecf20Sopenharmony_ci if (!dev1) { 39688c2ecf20Sopenharmony_ci err = -ENOMEM; 39698c2ecf20Sopenharmony_ci goto err_out_unregister; 39708c2ecf20Sopenharmony_ci } 39718c2ecf20Sopenharmony_ci 39728c2ecf20Sopenharmony_ci err = register_netdev(dev1); 39738c2ecf20Sopenharmony_ci if (err) { 39748c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot register second net device\n"); 39758c2ecf20Sopenharmony_ci goto err_out_free_dev1; 39768c2ecf20Sopenharmony_ci } 39778c2ecf20Sopenharmony_ci 39788c2ecf20Sopenharmony_ci err = request_irq(pdev->irq, skge_intr, IRQF_SHARED, 39798c2ecf20Sopenharmony_ci hw->irq_name, hw); 39808c2ecf20Sopenharmony_ci if (err) { 39818c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot assign irq %d\n", 39828c2ecf20Sopenharmony_ci pdev->irq); 39838c2ecf20Sopenharmony_ci goto err_out_unregister_dev1; 39848c2ecf20Sopenharmony_ci } 39858c2ecf20Sopenharmony_ci 39868c2ecf20Sopenharmony_ci skge_show_addr(dev1); 39878c2ecf20Sopenharmony_ci } 39888c2ecf20Sopenharmony_ci pci_set_drvdata(pdev, hw); 39898c2ecf20Sopenharmony_ci 39908c2ecf20Sopenharmony_ci return 0; 39918c2ecf20Sopenharmony_ci 39928c2ecf20Sopenharmony_cierr_out_unregister_dev1: 39938c2ecf20Sopenharmony_ci unregister_netdev(dev1); 39948c2ecf20Sopenharmony_cierr_out_free_dev1: 39958c2ecf20Sopenharmony_ci free_netdev(dev1); 39968c2ecf20Sopenharmony_cierr_out_unregister: 39978c2ecf20Sopenharmony_ci unregister_netdev(dev); 39988c2ecf20Sopenharmony_cierr_out_free_netdev: 39998c2ecf20Sopenharmony_ci free_netdev(dev); 40008c2ecf20Sopenharmony_cierr_out_led_off: 40018c2ecf20Sopenharmony_ci skge_write16(hw, B0_LED, LED_STAT_OFF); 40028c2ecf20Sopenharmony_cierr_out_iounmap: 40038c2ecf20Sopenharmony_ci iounmap(hw->regs); 40048c2ecf20Sopenharmony_cierr_out_free_hw: 40058c2ecf20Sopenharmony_ci kfree(hw); 40068c2ecf20Sopenharmony_cierr_out_free_regions: 40078c2ecf20Sopenharmony_ci pci_release_regions(pdev); 40088c2ecf20Sopenharmony_cierr_out_disable_pdev: 40098c2ecf20Sopenharmony_ci pci_disable_device(pdev); 40108c2ecf20Sopenharmony_cierr_out: 40118c2ecf20Sopenharmony_ci return err; 40128c2ecf20Sopenharmony_ci} 40138c2ecf20Sopenharmony_ci 40148c2ecf20Sopenharmony_cistatic void skge_remove(struct pci_dev *pdev) 40158c2ecf20Sopenharmony_ci{ 40168c2ecf20Sopenharmony_ci struct skge_hw *hw = pci_get_drvdata(pdev); 40178c2ecf20Sopenharmony_ci struct net_device *dev0, *dev1; 40188c2ecf20Sopenharmony_ci 40198c2ecf20Sopenharmony_ci if (!hw) 40208c2ecf20Sopenharmony_ci return; 40218c2ecf20Sopenharmony_ci 40228c2ecf20Sopenharmony_ci dev1 = hw->dev[1]; 40238c2ecf20Sopenharmony_ci if (dev1) 40248c2ecf20Sopenharmony_ci unregister_netdev(dev1); 40258c2ecf20Sopenharmony_ci dev0 = hw->dev[0]; 40268c2ecf20Sopenharmony_ci unregister_netdev(dev0); 40278c2ecf20Sopenharmony_ci 40288c2ecf20Sopenharmony_ci tasklet_kill(&hw->phy_task); 40298c2ecf20Sopenharmony_ci 40308c2ecf20Sopenharmony_ci spin_lock_irq(&hw->hw_lock); 40318c2ecf20Sopenharmony_ci hw->intr_mask = 0; 40328c2ecf20Sopenharmony_ci 40338c2ecf20Sopenharmony_ci if (hw->ports > 1) { 40348c2ecf20Sopenharmony_ci skge_write32(hw, B0_IMSK, 0); 40358c2ecf20Sopenharmony_ci skge_read32(hw, B0_IMSK); 40368c2ecf20Sopenharmony_ci } 40378c2ecf20Sopenharmony_ci spin_unlock_irq(&hw->hw_lock); 40388c2ecf20Sopenharmony_ci 40398c2ecf20Sopenharmony_ci skge_write16(hw, B0_LED, LED_STAT_OFF); 40408c2ecf20Sopenharmony_ci skge_write8(hw, B0_CTST, CS_RST_SET); 40418c2ecf20Sopenharmony_ci 40428c2ecf20Sopenharmony_ci if (hw->ports > 1) 40438c2ecf20Sopenharmony_ci free_irq(pdev->irq, hw); 40448c2ecf20Sopenharmony_ci pci_release_regions(pdev); 40458c2ecf20Sopenharmony_ci pci_disable_device(pdev); 40468c2ecf20Sopenharmony_ci if (dev1) 40478c2ecf20Sopenharmony_ci free_netdev(dev1); 40488c2ecf20Sopenharmony_ci free_netdev(dev0); 40498c2ecf20Sopenharmony_ci 40508c2ecf20Sopenharmony_ci iounmap(hw->regs); 40518c2ecf20Sopenharmony_ci kfree(hw); 40528c2ecf20Sopenharmony_ci} 40538c2ecf20Sopenharmony_ci 40548c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 40558c2ecf20Sopenharmony_cistatic int skge_suspend(struct device *dev) 40568c2ecf20Sopenharmony_ci{ 40578c2ecf20Sopenharmony_ci struct skge_hw *hw = dev_get_drvdata(dev); 40588c2ecf20Sopenharmony_ci int i; 40598c2ecf20Sopenharmony_ci 40608c2ecf20Sopenharmony_ci if (!hw) 40618c2ecf20Sopenharmony_ci return 0; 40628c2ecf20Sopenharmony_ci 40638c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 40648c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[i]; 40658c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 40668c2ecf20Sopenharmony_ci 40678c2ecf20Sopenharmony_ci if (netif_running(dev)) 40688c2ecf20Sopenharmony_ci skge_down(dev); 40698c2ecf20Sopenharmony_ci 40708c2ecf20Sopenharmony_ci if (skge->wol) 40718c2ecf20Sopenharmony_ci skge_wol_init(skge); 40728c2ecf20Sopenharmony_ci } 40738c2ecf20Sopenharmony_ci 40748c2ecf20Sopenharmony_ci skge_write32(hw, B0_IMSK, 0); 40758c2ecf20Sopenharmony_ci 40768c2ecf20Sopenharmony_ci return 0; 40778c2ecf20Sopenharmony_ci} 40788c2ecf20Sopenharmony_ci 40798c2ecf20Sopenharmony_cistatic int skge_resume(struct device *dev) 40808c2ecf20Sopenharmony_ci{ 40818c2ecf20Sopenharmony_ci struct skge_hw *hw = dev_get_drvdata(dev); 40828c2ecf20Sopenharmony_ci int i, err; 40838c2ecf20Sopenharmony_ci 40848c2ecf20Sopenharmony_ci if (!hw) 40858c2ecf20Sopenharmony_ci return 0; 40868c2ecf20Sopenharmony_ci 40878c2ecf20Sopenharmony_ci err = skge_reset(hw); 40888c2ecf20Sopenharmony_ci if (err) 40898c2ecf20Sopenharmony_ci goto out; 40908c2ecf20Sopenharmony_ci 40918c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 40928c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[i]; 40938c2ecf20Sopenharmony_ci 40948c2ecf20Sopenharmony_ci if (netif_running(dev)) { 40958c2ecf20Sopenharmony_ci err = skge_up(dev); 40968c2ecf20Sopenharmony_ci 40978c2ecf20Sopenharmony_ci if (err) { 40988c2ecf20Sopenharmony_ci netdev_err(dev, "could not up: %d\n", err); 40998c2ecf20Sopenharmony_ci dev_close(dev); 41008c2ecf20Sopenharmony_ci goto out; 41018c2ecf20Sopenharmony_ci } 41028c2ecf20Sopenharmony_ci } 41038c2ecf20Sopenharmony_ci } 41048c2ecf20Sopenharmony_ciout: 41058c2ecf20Sopenharmony_ci return err; 41068c2ecf20Sopenharmony_ci} 41078c2ecf20Sopenharmony_ci 41088c2ecf20Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(skge_pm_ops, skge_suspend, skge_resume); 41098c2ecf20Sopenharmony_ci#define SKGE_PM_OPS (&skge_pm_ops) 41108c2ecf20Sopenharmony_ci 41118c2ecf20Sopenharmony_ci#else 41128c2ecf20Sopenharmony_ci 41138c2ecf20Sopenharmony_ci#define SKGE_PM_OPS NULL 41148c2ecf20Sopenharmony_ci#endif /* CONFIG_PM_SLEEP */ 41158c2ecf20Sopenharmony_ci 41168c2ecf20Sopenharmony_cistatic void skge_shutdown(struct pci_dev *pdev) 41178c2ecf20Sopenharmony_ci{ 41188c2ecf20Sopenharmony_ci struct skge_hw *hw = pci_get_drvdata(pdev); 41198c2ecf20Sopenharmony_ci int i; 41208c2ecf20Sopenharmony_ci 41218c2ecf20Sopenharmony_ci if (!hw) 41228c2ecf20Sopenharmony_ci return; 41238c2ecf20Sopenharmony_ci 41248c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 41258c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[i]; 41268c2ecf20Sopenharmony_ci struct skge_port *skge = netdev_priv(dev); 41278c2ecf20Sopenharmony_ci 41288c2ecf20Sopenharmony_ci if (skge->wol) 41298c2ecf20Sopenharmony_ci skge_wol_init(skge); 41308c2ecf20Sopenharmony_ci } 41318c2ecf20Sopenharmony_ci 41328c2ecf20Sopenharmony_ci pci_wake_from_d3(pdev, device_may_wakeup(&pdev->dev)); 41338c2ecf20Sopenharmony_ci pci_set_power_state(pdev, PCI_D3hot); 41348c2ecf20Sopenharmony_ci} 41358c2ecf20Sopenharmony_ci 41368c2ecf20Sopenharmony_cistatic struct pci_driver skge_driver = { 41378c2ecf20Sopenharmony_ci .name = DRV_NAME, 41388c2ecf20Sopenharmony_ci .id_table = skge_id_table, 41398c2ecf20Sopenharmony_ci .probe = skge_probe, 41408c2ecf20Sopenharmony_ci .remove = skge_remove, 41418c2ecf20Sopenharmony_ci .shutdown = skge_shutdown, 41428c2ecf20Sopenharmony_ci .driver.pm = SKGE_PM_OPS, 41438c2ecf20Sopenharmony_ci}; 41448c2ecf20Sopenharmony_ci 41458c2ecf20Sopenharmony_cistatic const struct dmi_system_id skge_32bit_dma_boards[] = { 41468c2ecf20Sopenharmony_ci { 41478c2ecf20Sopenharmony_ci .ident = "Gigabyte nForce boards", 41488c2ecf20Sopenharmony_ci .matches = { 41498c2ecf20Sopenharmony_ci DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co"), 41508c2ecf20Sopenharmony_ci DMI_MATCH(DMI_BOARD_NAME, "nForce"), 41518c2ecf20Sopenharmony_ci }, 41528c2ecf20Sopenharmony_ci }, 41538c2ecf20Sopenharmony_ci { 41548c2ecf20Sopenharmony_ci .ident = "ASUS P5NSLI", 41558c2ecf20Sopenharmony_ci .matches = { 41568c2ecf20Sopenharmony_ci DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), 41578c2ecf20Sopenharmony_ci DMI_MATCH(DMI_BOARD_NAME, "P5NSLI") 41588c2ecf20Sopenharmony_ci }, 41598c2ecf20Sopenharmony_ci }, 41608c2ecf20Sopenharmony_ci { 41618c2ecf20Sopenharmony_ci .ident = "FUJITSU SIEMENS A8NE-FM", 41628c2ecf20Sopenharmony_ci .matches = { 41638c2ecf20Sopenharmony_ci DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."), 41648c2ecf20Sopenharmony_ci DMI_MATCH(DMI_BOARD_NAME, "A8NE-FM") 41658c2ecf20Sopenharmony_ci }, 41668c2ecf20Sopenharmony_ci }, 41678c2ecf20Sopenharmony_ci {} 41688c2ecf20Sopenharmony_ci}; 41698c2ecf20Sopenharmony_ci 41708c2ecf20Sopenharmony_cistatic int __init skge_init_module(void) 41718c2ecf20Sopenharmony_ci{ 41728c2ecf20Sopenharmony_ci if (dmi_check_system(skge_32bit_dma_boards)) 41738c2ecf20Sopenharmony_ci only_32bit_dma = 1; 41748c2ecf20Sopenharmony_ci skge_debug_init(); 41758c2ecf20Sopenharmony_ci return pci_register_driver(&skge_driver); 41768c2ecf20Sopenharmony_ci} 41778c2ecf20Sopenharmony_ci 41788c2ecf20Sopenharmony_cistatic void __exit skge_cleanup_module(void) 41798c2ecf20Sopenharmony_ci{ 41808c2ecf20Sopenharmony_ci pci_unregister_driver(&skge_driver); 41818c2ecf20Sopenharmony_ci skge_debug_cleanup(); 41828c2ecf20Sopenharmony_ci} 41838c2ecf20Sopenharmony_ci 41848c2ecf20Sopenharmony_cimodule_init(skge_init_module); 41858c2ecf20Sopenharmony_cimodule_exit(skge_cleanup_module); 4186