18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * New driver for Marvell Yukon 2 chipset. 48c2ecf20Sopenharmony_ci * Based on earlier sk98lin, and skge driver. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This driver intentionally does not support all the features 78c2ecf20Sopenharmony_ci * of the original driver such as link fail-over and link management because 88c2ecf20Sopenharmony_ci * those should be done at higher levels. 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Copyright (C) 2005 Stephen Hemminger <shemminger@osdl.org> 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/crc32.h> 168c2ecf20Sopenharmony_ci#include <linux/kernel.h> 178c2ecf20Sopenharmony_ci#include <linux/module.h> 188c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 198c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h> 208c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 218c2ecf20Sopenharmony_ci#include <linux/ethtool.h> 228c2ecf20Sopenharmony_ci#include <linux/pci.h> 238c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 248c2ecf20Sopenharmony_ci#include <linux/ip.h> 258c2ecf20Sopenharmony_ci#include <linux/slab.h> 268c2ecf20Sopenharmony_ci#include <net/ip.h> 278c2ecf20Sopenharmony_ci#include <linux/tcp.h> 288c2ecf20Sopenharmony_ci#include <linux/in.h> 298c2ecf20Sopenharmony_ci#include <linux/delay.h> 308c2ecf20Sopenharmony_ci#include <linux/workqueue.h> 318c2ecf20Sopenharmony_ci#include <linux/if_vlan.h> 328c2ecf20Sopenharmony_ci#include <linux/prefetch.h> 338c2ecf20Sopenharmony_ci#include <linux/debugfs.h> 348c2ecf20Sopenharmony_ci#include <linux/mii.h> 358c2ecf20Sopenharmony_ci#include <linux/of_device.h> 368c2ecf20Sopenharmony_ci#include <linux/of_net.h> 378c2ecf20Sopenharmony_ci#include <linux/dmi.h> 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#include <asm/irq.h> 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#include "sky2.h" 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define DRV_NAME "sky2" 448c2ecf20Sopenharmony_ci#define DRV_VERSION "1.30" 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/* 478c2ecf20Sopenharmony_ci * The Yukon II chipset takes 64 bit command blocks (called list elements) 488c2ecf20Sopenharmony_ci * that are organized into three (receive, transmit, status) different rings 498c2ecf20Sopenharmony_ci * similar to Tigon3. 508c2ecf20Sopenharmony_ci */ 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define RX_LE_SIZE 1024 538c2ecf20Sopenharmony_ci#define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le)) 548c2ecf20Sopenharmony_ci#define RX_MAX_PENDING (RX_LE_SIZE/6 - 2) 558c2ecf20Sopenharmony_ci#define RX_DEF_PENDING RX_MAX_PENDING 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/* This is the worst case number of transmit list elements for a single skb: 588c2ecf20Sopenharmony_ci VLAN:GSO + CKSUM + Data + skb_frags * DMA */ 598c2ecf20Sopenharmony_ci#define MAX_SKB_TX_LE (2 + (sizeof(dma_addr_t)/sizeof(u32))*(MAX_SKB_FRAGS+1)) 608c2ecf20Sopenharmony_ci#define TX_MIN_PENDING (MAX_SKB_TX_LE+1) 618c2ecf20Sopenharmony_ci#define TX_MAX_PENDING 1024 628c2ecf20Sopenharmony_ci#define TX_DEF_PENDING 63 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define TX_WATCHDOG (5 * HZ) 658c2ecf20Sopenharmony_ci#define NAPI_WEIGHT 64 668c2ecf20Sopenharmony_ci#define PHY_RETRIES 1000 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci#define SKY2_EEPROM_MAGIC 0x9955aabb 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define RING_NEXT(x, s) (((x)+1) & ((s)-1)) 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic const u32 default_msg = 738c2ecf20Sopenharmony_ci NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK 748c2ecf20Sopenharmony_ci | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR 758c2ecf20Sopenharmony_ci | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic int debug = -1; /* defaults above */ 788c2ecf20Sopenharmony_cimodule_param(debug, int, 0); 798c2ecf20Sopenharmony_ciMODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistatic int copybreak __read_mostly = 128; 828c2ecf20Sopenharmony_cimodule_param(copybreak, int, 0); 838c2ecf20Sopenharmony_ciMODULE_PARM_DESC(copybreak, "Receive copy threshold"); 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_cistatic int disable_msi = -1; 868c2ecf20Sopenharmony_cimodule_param(disable_msi, int, 0); 878c2ecf20Sopenharmony_ciMODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)"); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_cistatic int legacy_pme = 0; 908c2ecf20Sopenharmony_cimodule_param(legacy_pme, int, 0); 918c2ecf20Sopenharmony_ciMODULE_PARM_DESC(legacy_pme, "Legacy power management"); 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistatic const struct pci_device_id sky2_id_table[] = { 948c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) }, /* SK-9Sxx */ 958c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, /* SK-9Exx */ 968c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E01) }, /* SK-9E21M */ 978c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) }, /* DGE-560T */ 988c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4001) }, /* DGE-550SX */ 998c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B02) }, /* DGE-560SX */ 1008c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B03) }, /* DGE-550T */ 1018c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) }, /* 88E8021 */ 1028c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) }, /* 88E8022 */ 1038c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) }, /* 88E8061 */ 1048c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4343) }, /* 88E8062 */ 1058c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4344) }, /* 88E8021 */ 1068c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4345) }, /* 88E8022 */ 1078c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4346) }, /* 88E8061 */ 1088c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4347) }, /* 88E8062 */ 1098c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4350) }, /* 88E8035 */ 1108c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4351) }, /* 88E8036 */ 1118c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4352) }, /* 88E8038 */ 1128c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4353) }, /* 88E8039 */ 1138c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4354) }, /* 88E8040 */ 1148c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4355) }, /* 88E8040T */ 1158c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4356) }, /* 88EC033 */ 1168c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4357) }, /* 88E8042 */ 1178c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x435A) }, /* 88E8048 */ 1188c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4360) }, /* 88E8052 */ 1198c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) }, /* 88E8050 */ 1208c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4362) }, /* 88E8053 */ 1218c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4363) }, /* 88E8055 */ 1228c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4364) }, /* 88E8056 */ 1238c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4365) }, /* 88E8070 */ 1248c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4366) }, /* 88EC036 */ 1258c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4367) }, /* 88EC032 */ 1268c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4368) }, /* 88EC034 */ 1278c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4369) }, /* 88EC042 */ 1288c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436A) }, /* 88E8058 */ 1298c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436B) }, /* 88E8071 */ 1308c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436C) }, /* 88E8072 */ 1318c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436D) }, /* 88E8055 */ 1328c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4370) }, /* 88E8075 */ 1338c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4380) }, /* 88E8057 */ 1348c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4381) }, /* 88E8059 */ 1358c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4382) }, /* 88E8079 */ 1368c2ecf20Sopenharmony_ci { 0 } 1378c2ecf20Sopenharmony_ci}; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, sky2_id_table); 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci/* Avoid conditionals by using array */ 1428c2ecf20Sopenharmony_cistatic const unsigned txqaddr[] = { Q_XA1, Q_XA2 }; 1438c2ecf20Sopenharmony_cistatic const unsigned rxqaddr[] = { Q_R1, Q_R2 }; 1448c2ecf20Sopenharmony_cistatic const u32 portirq_msk[] = { Y2_IS_PORT_1, Y2_IS_PORT_2 }; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_cistatic void sky2_set_multicast(struct net_device *dev); 1478c2ecf20Sopenharmony_cistatic irqreturn_t sky2_intr(int irq, void *dev_id); 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* Access to PHY via serial interconnect */ 1508c2ecf20Sopenharmony_cistatic int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci int i; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_SMI_DATA, val); 1558c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_SMI_CTRL, 1568c2ecf20Sopenharmony_ci GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) | GM_SMI_CT_REG_AD(reg)); 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci for (i = 0; i < PHY_RETRIES; i++) { 1598c2ecf20Sopenharmony_ci u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL); 1608c2ecf20Sopenharmony_ci if (ctrl == 0xffff) 1618c2ecf20Sopenharmony_ci goto io_error; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci if (!(ctrl & GM_SMI_CT_BUSY)) 1648c2ecf20Sopenharmony_ci return 0; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci udelay(10); 1678c2ecf20Sopenharmony_ci } 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci dev_warn(&hw->pdev->dev, "%s: phy write timeout\n", hw->dev[port]->name); 1708c2ecf20Sopenharmony_ci return -ETIMEDOUT; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ciio_error: 1738c2ecf20Sopenharmony_ci dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name); 1748c2ecf20Sopenharmony_ci return -EIO; 1758c2ecf20Sopenharmony_ci} 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_cistatic int __gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg, u16 *val) 1788c2ecf20Sopenharmony_ci{ 1798c2ecf20Sopenharmony_ci int i; 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_SMI_CTRL, GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) 1828c2ecf20Sopenharmony_ci | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD); 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci for (i = 0; i < PHY_RETRIES; i++) { 1858c2ecf20Sopenharmony_ci u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL); 1868c2ecf20Sopenharmony_ci if (ctrl == 0xffff) 1878c2ecf20Sopenharmony_ci goto io_error; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci if (ctrl & GM_SMI_CT_RD_VAL) { 1908c2ecf20Sopenharmony_ci *val = gma_read16(hw, port, GM_SMI_DATA); 1918c2ecf20Sopenharmony_ci return 0; 1928c2ecf20Sopenharmony_ci } 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci udelay(10); 1958c2ecf20Sopenharmony_ci } 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci dev_warn(&hw->pdev->dev, "%s: phy read timeout\n", hw->dev[port]->name); 1988c2ecf20Sopenharmony_ci return -ETIMEDOUT; 1998c2ecf20Sopenharmony_ciio_error: 2008c2ecf20Sopenharmony_ci dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name); 2018c2ecf20Sopenharmony_ci return -EIO; 2028c2ecf20Sopenharmony_ci} 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cistatic inline u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg) 2058c2ecf20Sopenharmony_ci{ 2068c2ecf20Sopenharmony_ci u16 v = 0; 2078c2ecf20Sopenharmony_ci __gm_phy_read(hw, port, reg, &v); 2088c2ecf20Sopenharmony_ci return v; 2098c2ecf20Sopenharmony_ci} 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_cistatic void sky2_power_on(struct sky2_hw *hw) 2138c2ecf20Sopenharmony_ci{ 2148c2ecf20Sopenharmony_ci /* switch power to VCC (WA for VAUX problem) */ 2158c2ecf20Sopenharmony_ci sky2_write8(hw, B0_POWER_CTRL, 2168c2ecf20Sopenharmony_ci PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON); 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci /* disable Core Clock Division, */ 2198c2ecf20Sopenharmony_ci sky2_write32(hw, B2_Y2_CLK_CTRL, Y2_CLK_DIV_DIS); 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > CHIP_REV_YU_XL_A1) 2228c2ecf20Sopenharmony_ci /* enable bits are inverted */ 2238c2ecf20Sopenharmony_ci sky2_write8(hw, B2_Y2_CLK_GATE, 2248c2ecf20Sopenharmony_ci Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS | 2258c2ecf20Sopenharmony_ci Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS | 2268c2ecf20Sopenharmony_ci Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS); 2278c2ecf20Sopenharmony_ci else 2288c2ecf20Sopenharmony_ci sky2_write8(hw, B2_Y2_CLK_GATE, 0); 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_ADV_POWER_CTL) { 2318c2ecf20Sopenharmony_ci u32 reg; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci sky2_pci_write32(hw, PCI_DEV_REG3, 0); 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci reg = sky2_pci_read32(hw, PCI_DEV_REG4); 2368c2ecf20Sopenharmony_ci /* set all bits to 0 except bits 15..12 and 8 */ 2378c2ecf20Sopenharmony_ci reg &= P_ASPM_CONTROL_MSK; 2388c2ecf20Sopenharmony_ci sky2_pci_write32(hw, PCI_DEV_REG4, reg); 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci reg = sky2_pci_read32(hw, PCI_DEV_REG5); 2418c2ecf20Sopenharmony_ci /* set all bits to 0 except bits 28 & 27 */ 2428c2ecf20Sopenharmony_ci reg &= P_CTL_TIM_VMAIN_AV_MSK; 2438c2ecf20Sopenharmony_ci sky2_pci_write32(hw, PCI_DEV_REG5, reg); 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci sky2_pci_write32(hw, PCI_CFG_REG_1, 0); 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci sky2_write16(hw, B0_CTST, Y2_HW_WOL_ON); 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */ 2508c2ecf20Sopenharmony_ci reg = sky2_read32(hw, B2_GP_IO); 2518c2ecf20Sopenharmony_ci reg |= GLB_GPIO_STAT_RACE_DIS; 2528c2ecf20Sopenharmony_ci sky2_write32(hw, B2_GP_IO, reg); 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci sky2_read32(hw, B2_GP_IO); 2558c2ecf20Sopenharmony_ci } 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci /* Turn on "driver loaded" LED */ 2588c2ecf20Sopenharmony_ci sky2_write16(hw, B0_CTST, Y2_LED_STAT_ON); 2598c2ecf20Sopenharmony_ci} 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_cistatic void sky2_power_aux(struct sky2_hw *hw) 2628c2ecf20Sopenharmony_ci{ 2638c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > CHIP_REV_YU_XL_A1) 2648c2ecf20Sopenharmony_ci sky2_write8(hw, B2_Y2_CLK_GATE, 0); 2658c2ecf20Sopenharmony_ci else 2668c2ecf20Sopenharmony_ci /* enable bits are inverted */ 2678c2ecf20Sopenharmony_ci sky2_write8(hw, B2_Y2_CLK_GATE, 2688c2ecf20Sopenharmony_ci Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS | 2698c2ecf20Sopenharmony_ci Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS | 2708c2ecf20Sopenharmony_ci Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS); 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci /* switch power to VAUX if supported and PME from D3cold */ 2738c2ecf20Sopenharmony_ci if ( (sky2_read32(hw, B0_CTST) & Y2_VAUX_AVAIL) && 2748c2ecf20Sopenharmony_ci pci_pme_capable(hw->pdev, PCI_D3cold)) 2758c2ecf20Sopenharmony_ci sky2_write8(hw, B0_POWER_CTRL, 2768c2ecf20Sopenharmony_ci (PC_VAUX_ENA | PC_VCC_ENA | 2778c2ecf20Sopenharmony_ci PC_VAUX_ON | PC_VCC_OFF)); 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci /* turn off "driver loaded LED" */ 2808c2ecf20Sopenharmony_ci sky2_write16(hw, B0_CTST, Y2_LED_STAT_OFF); 2818c2ecf20Sopenharmony_ci} 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_cistatic void sky2_gmac_reset(struct sky2_hw *hw, unsigned port) 2848c2ecf20Sopenharmony_ci{ 2858c2ecf20Sopenharmony_ci u16 reg; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci /* disable all GMAC IRQ's */ 2888c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0); 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */ 2918c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H2, 0); 2928c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H3, 0); 2938c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H4, 0); 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci reg = gma_read16(hw, port, GM_RX_CTRL); 2968c2ecf20Sopenharmony_ci reg |= GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA; 2978c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_RX_CTRL, reg); 2988c2ecf20Sopenharmony_ci} 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci/* flow control to advertise bits */ 3018c2ecf20Sopenharmony_cistatic const u16 copper_fc_adv[] = { 3028c2ecf20Sopenharmony_ci [FC_NONE] = 0, 3038c2ecf20Sopenharmony_ci [FC_TX] = PHY_M_AN_ASP, 3048c2ecf20Sopenharmony_ci [FC_RX] = PHY_M_AN_PC, 3058c2ecf20Sopenharmony_ci [FC_BOTH] = PHY_M_AN_PC | PHY_M_AN_ASP, 3068c2ecf20Sopenharmony_ci}; 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci/* flow control to advertise bits when using 1000BaseX */ 3098c2ecf20Sopenharmony_cistatic const u16 fiber_fc_adv[] = { 3108c2ecf20Sopenharmony_ci [FC_NONE] = PHY_M_P_NO_PAUSE_X, 3118c2ecf20Sopenharmony_ci [FC_TX] = PHY_M_P_ASYM_MD_X, 3128c2ecf20Sopenharmony_ci [FC_RX] = PHY_M_P_SYM_MD_X, 3138c2ecf20Sopenharmony_ci [FC_BOTH] = PHY_M_P_BOTH_MD_X, 3148c2ecf20Sopenharmony_ci}; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci/* flow control to GMA disable bits */ 3178c2ecf20Sopenharmony_cistatic const u16 gm_fc_disable[] = { 3188c2ecf20Sopenharmony_ci [FC_NONE] = GM_GPCR_FC_RX_DIS | GM_GPCR_FC_TX_DIS, 3198c2ecf20Sopenharmony_ci [FC_TX] = GM_GPCR_FC_RX_DIS, 3208c2ecf20Sopenharmony_ci [FC_RX] = GM_GPCR_FC_TX_DIS, 3218c2ecf20Sopenharmony_ci [FC_BOTH] = 0, 3228c2ecf20Sopenharmony_ci}; 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_cistatic void sky2_phy_init(struct sky2_hw *hw, unsigned port) 3268c2ecf20Sopenharmony_ci{ 3278c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(hw->dev[port]); 3288c2ecf20Sopenharmony_ci u16 ctrl, ct1000, adv, pg, ledctrl, ledover, reg; 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci if ( (sky2->flags & SKY2_FLAG_AUTO_SPEED) && 3318c2ecf20Sopenharmony_ci !(hw->flags & SKY2_HW_NEWER_PHY)) { 3328c2ecf20Sopenharmony_ci u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL); 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK | 3358c2ecf20Sopenharmony_ci PHY_M_EC_MAC_S_MSK); 3368c2ecf20Sopenharmony_ci ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ); 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci /* on PHY 88E1040 Rev.D0 (and newer) downshift control changed */ 3398c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EC) 3408c2ecf20Sopenharmony_ci /* set downshift counter to 3x and enable downshift */ 3418c2ecf20Sopenharmony_ci ectrl |= PHY_M_EC_DSC_2(2) | PHY_M_EC_DOWN_S_ENA; 3428c2ecf20Sopenharmony_ci else 3438c2ecf20Sopenharmony_ci /* set master & slave downshift counter to 1x */ 3448c2ecf20Sopenharmony_ci ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1); 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl); 3478c2ecf20Sopenharmony_ci } 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); 3508c2ecf20Sopenharmony_ci if (sky2_is_copper(hw)) { 3518c2ecf20Sopenharmony_ci if (!(hw->flags & SKY2_HW_GIGABIT)) { 3528c2ecf20Sopenharmony_ci /* enable automatic crossover */ 3538c2ecf20Sopenharmony_ci ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO) >> 1; 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_FE_P && 3568c2ecf20Sopenharmony_ci hw->chip_rev == CHIP_REV_YU_FE2_A0) { 3578c2ecf20Sopenharmony_ci u16 spec; 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci /* Enable Class A driver for FE+ A0 */ 3608c2ecf20Sopenharmony_ci spec = gm_phy_read(hw, port, PHY_MARV_FE_SPEC_2); 3618c2ecf20Sopenharmony_ci spec |= PHY_M_FESC_SEL_CL_A; 3628c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_FE_SPEC_2, spec); 3638c2ecf20Sopenharmony_ci } 3648c2ecf20Sopenharmony_ci } else { 3658c2ecf20Sopenharmony_ci /* disable energy detect */ 3668c2ecf20Sopenharmony_ci ctrl &= ~PHY_M_PC_EN_DET_MSK; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci /* enable automatic crossover */ 3698c2ecf20Sopenharmony_ci ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO); 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci /* downshift on PHY 88E1112 and 88E1149 is changed */ 3728c2ecf20Sopenharmony_ci if ( (sky2->flags & SKY2_FLAG_AUTO_SPEED) && 3738c2ecf20Sopenharmony_ci (hw->flags & SKY2_HW_NEWER_PHY)) { 3748c2ecf20Sopenharmony_ci /* set downshift counter to 3x and enable downshift */ 3758c2ecf20Sopenharmony_ci ctrl &= ~PHY_M_PC_DSC_MSK; 3768c2ecf20Sopenharmony_ci ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA; 3778c2ecf20Sopenharmony_ci } 3788c2ecf20Sopenharmony_ci } 3798c2ecf20Sopenharmony_ci } else { 3808c2ecf20Sopenharmony_ci /* workaround for deviation #4.88 (CRC errors) */ 3818c2ecf20Sopenharmony_ci /* disable Automatic Crossover */ 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci ctrl &= ~PHY_M_PC_MDIX_MSK; 3848c2ecf20Sopenharmony_ci } 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci /* special setup for PHY 88E1112 Fiber */ 3898c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_XL && (hw->flags & SKY2_HW_FIBRE_PHY)) { 3908c2ecf20Sopenharmony_ci pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci /* Fiber: select 1000BASE-X only mode MAC Specific Ctrl Reg. */ 3938c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2); 3948c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); 3958c2ecf20Sopenharmony_ci ctrl &= ~PHY_M_MAC_MD_MSK; 3968c2ecf20Sopenharmony_ci ctrl |= PHY_M_MAC_MODE_SEL(PHY_M_MAC_MD_1000BX); 3978c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci if (hw->pmd_type == 'P') { 4008c2ecf20Sopenharmony_ci /* select page 1 to access Fiber registers */ 4018c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 1); 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci /* for SFP-module set SIGDET polarity to low */ 4048c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); 4058c2ecf20Sopenharmony_ci ctrl |= PHY_M_FIB_SIGD_POL; 4068c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); 4078c2ecf20Sopenharmony_ci } 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); 4108c2ecf20Sopenharmony_ci } 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci ctrl = PHY_CT_RESET; 4138c2ecf20Sopenharmony_ci ct1000 = 0; 4148c2ecf20Sopenharmony_ci adv = PHY_AN_CSMA; 4158c2ecf20Sopenharmony_ci reg = 0; 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci if (sky2->flags & SKY2_FLAG_AUTO_SPEED) { 4188c2ecf20Sopenharmony_ci if (sky2_is_copper(hw)) { 4198c2ecf20Sopenharmony_ci if (sky2->advertising & ADVERTISED_1000baseT_Full) 4208c2ecf20Sopenharmony_ci ct1000 |= PHY_M_1000C_AFD; 4218c2ecf20Sopenharmony_ci if (sky2->advertising & ADVERTISED_1000baseT_Half) 4228c2ecf20Sopenharmony_ci ct1000 |= PHY_M_1000C_AHD; 4238c2ecf20Sopenharmony_ci if (sky2->advertising & ADVERTISED_100baseT_Full) 4248c2ecf20Sopenharmony_ci adv |= PHY_M_AN_100_FD; 4258c2ecf20Sopenharmony_ci if (sky2->advertising & ADVERTISED_100baseT_Half) 4268c2ecf20Sopenharmony_ci adv |= PHY_M_AN_100_HD; 4278c2ecf20Sopenharmony_ci if (sky2->advertising & ADVERTISED_10baseT_Full) 4288c2ecf20Sopenharmony_ci adv |= PHY_M_AN_10_FD; 4298c2ecf20Sopenharmony_ci if (sky2->advertising & ADVERTISED_10baseT_Half) 4308c2ecf20Sopenharmony_ci adv |= PHY_M_AN_10_HD; 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci } else { /* special defines for FIBER (88E1040S only) */ 4338c2ecf20Sopenharmony_ci if (sky2->advertising & ADVERTISED_1000baseT_Full) 4348c2ecf20Sopenharmony_ci adv |= PHY_M_AN_1000X_AFD; 4358c2ecf20Sopenharmony_ci if (sky2->advertising & ADVERTISED_1000baseT_Half) 4368c2ecf20Sopenharmony_ci adv |= PHY_M_AN_1000X_AHD; 4378c2ecf20Sopenharmony_ci } 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci /* Restart Auto-negotiation */ 4408c2ecf20Sopenharmony_ci ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG; 4418c2ecf20Sopenharmony_ci } else { 4428c2ecf20Sopenharmony_ci /* forced speed/duplex settings */ 4438c2ecf20Sopenharmony_ci ct1000 = PHY_M_1000C_MSE; 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci /* Disable auto update for duplex flow control and duplex */ 4468c2ecf20Sopenharmony_ci reg |= GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_SPD_DIS; 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci switch (sky2->speed) { 4498c2ecf20Sopenharmony_ci case SPEED_1000: 4508c2ecf20Sopenharmony_ci ctrl |= PHY_CT_SP1000; 4518c2ecf20Sopenharmony_ci reg |= GM_GPCR_SPEED_1000; 4528c2ecf20Sopenharmony_ci break; 4538c2ecf20Sopenharmony_ci case SPEED_100: 4548c2ecf20Sopenharmony_ci ctrl |= PHY_CT_SP100; 4558c2ecf20Sopenharmony_ci reg |= GM_GPCR_SPEED_100; 4568c2ecf20Sopenharmony_ci break; 4578c2ecf20Sopenharmony_ci } 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci if (sky2->duplex == DUPLEX_FULL) { 4608c2ecf20Sopenharmony_ci reg |= GM_GPCR_DUP_FULL; 4618c2ecf20Sopenharmony_ci ctrl |= PHY_CT_DUP_MD; 4628c2ecf20Sopenharmony_ci } else if (sky2->speed < SPEED_1000) 4638c2ecf20Sopenharmony_ci sky2->flow_mode = FC_NONE; 4648c2ecf20Sopenharmony_ci } 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci if (sky2->flags & SKY2_FLAG_AUTO_PAUSE) { 4678c2ecf20Sopenharmony_ci if (sky2_is_copper(hw)) 4688c2ecf20Sopenharmony_ci adv |= copper_fc_adv[sky2->flow_mode]; 4698c2ecf20Sopenharmony_ci else 4708c2ecf20Sopenharmony_ci adv |= fiber_fc_adv[sky2->flow_mode]; 4718c2ecf20Sopenharmony_ci } else { 4728c2ecf20Sopenharmony_ci reg |= GM_GPCR_AU_FCT_DIS; 4738c2ecf20Sopenharmony_ci reg |= gm_fc_disable[sky2->flow_mode]; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci /* Forward pause packets to GMAC? */ 4768c2ecf20Sopenharmony_ci if (sky2->flow_mode & FC_RX) 4778c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); 4788c2ecf20Sopenharmony_ci else 4798c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); 4808c2ecf20Sopenharmony_ci } 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, reg); 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_GIGABIT) 4858c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000); 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv); 4888c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci /* Setup Phy LED's */ 4918c2ecf20Sopenharmony_ci ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS); 4928c2ecf20Sopenharmony_ci ledover = 0; 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci switch (hw->chip_id) { 4958c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_FE: 4968c2ecf20Sopenharmony_ci /* on 88E3082 these bits are at 11..9 (shifted left) */ 4978c2ecf20Sopenharmony_ci ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) << 1; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_FE_LED_PAR); 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci /* delete ACT LED control bits */ 5028c2ecf20Sopenharmony_ci ctrl &= ~PHY_M_FELP_LED1_MSK; 5038c2ecf20Sopenharmony_ci /* change ACT LED control to blink mode */ 5048c2ecf20Sopenharmony_ci ctrl |= PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_ACT_BL); 5058c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl); 5068c2ecf20Sopenharmony_ci break; 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_FE_P: 5098c2ecf20Sopenharmony_ci /* Enable Link Partner Next Page */ 5108c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); 5118c2ecf20Sopenharmony_ci ctrl |= PHY_M_PC_ENA_LIP_NP; 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci /* disable Energy Detect and enable scrambler */ 5148c2ecf20Sopenharmony_ci ctrl &= ~(PHY_M_PC_ENA_ENE_DT | PHY_M_PC_DIS_SCRAMB); 5158c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci /* set LED2 -> ACT, LED1 -> LINK, LED0 -> SPEED */ 5188c2ecf20Sopenharmony_ci ctrl = PHY_M_FELP_LED2_CTRL(LED_PAR_CTRL_ACT_BL) | 5198c2ecf20Sopenharmony_ci PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_LINK) | 5208c2ecf20Sopenharmony_ci PHY_M_FELP_LED0_CTRL(LED_PAR_CTRL_SPEED); 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl); 5238c2ecf20Sopenharmony_ci break; 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_XL: 5268c2ecf20Sopenharmony_ci pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci /* select page 3 to access LED control register */ 5298c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci /* set LED Function Control register */ 5328c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, 5338c2ecf20Sopenharmony_ci (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */ 5348c2ecf20Sopenharmony_ci PHY_M_LEDC_INIT_CTRL(7) | /* 10 Mbps */ 5358c2ecf20Sopenharmony_ci PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */ 5368c2ecf20Sopenharmony_ci PHY_M_LEDC_STA0_CTRL(7))); /* 1000 Mbps */ 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci /* set Polarity Control register */ 5398c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_STAT, 5408c2ecf20Sopenharmony_ci (PHY_M_POLC_LS1_P_MIX(4) | 5418c2ecf20Sopenharmony_ci PHY_M_POLC_IS0_P_MIX(4) | 5428c2ecf20Sopenharmony_ci PHY_M_POLC_LOS_CTRL(2) | 5438c2ecf20Sopenharmony_ci PHY_M_POLC_INIT_CTRL(2) | 5448c2ecf20Sopenharmony_ci PHY_M_POLC_STA1_CTRL(2) | 5458c2ecf20Sopenharmony_ci PHY_M_POLC_STA0_CTRL(2))); 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci /* restore page register */ 5488c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); 5498c2ecf20Sopenharmony_ci break; 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_EC_U: 5528c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_EX: 5538c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_SUPR: 5548c2ecf20Sopenharmony_ci pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci /* select page 3 to access LED control register */ 5578c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci /* set LED Function Control register */ 5608c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, 5618c2ecf20Sopenharmony_ci (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */ 5628c2ecf20Sopenharmony_ci PHY_M_LEDC_INIT_CTRL(8) | /* 10 Mbps */ 5638c2ecf20Sopenharmony_ci PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */ 5648c2ecf20Sopenharmony_ci PHY_M_LEDC_STA0_CTRL(7)));/* 1000 Mbps */ 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci /* set Blink Rate in LED Timer Control Register */ 5678c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_INT_MASK, 5688c2ecf20Sopenharmony_ci ledctrl | PHY_M_LED_BLINK_RT(BLINK_84MS)); 5698c2ecf20Sopenharmony_ci /* restore page register */ 5708c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); 5718c2ecf20Sopenharmony_ci break; 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci default: 5748c2ecf20Sopenharmony_ci /* set Tx LED (LED_TX) to blink mode on Rx OR Tx activity */ 5758c2ecf20Sopenharmony_ci ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL; 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci /* turn off the Rx LED (LED_RX) */ 5788c2ecf20Sopenharmony_ci ledover |= PHY_M_LED_MO_RX(MO_LED_OFF); 5798c2ecf20Sopenharmony_ci } 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_UL_2) { 5828c2ecf20Sopenharmony_ci /* apply fixes in PHY AFE */ 5838c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 255); 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci /* increase differential signal amplitude in 10BASE-T */ 5868c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 0x18, 0xaa99); 5878c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 0x17, 0x2011); 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EC_U) { 5908c2ecf20Sopenharmony_ci /* fix for IEEE A/B Symmetry failure in 1000BASE-T */ 5918c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 0x18, 0xa204); 5928c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 0x17, 0x2002); 5938c2ecf20Sopenharmony_ci } 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci /* set page register to 0 */ 5968c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0); 5978c2ecf20Sopenharmony_ci } else if (hw->chip_id == CHIP_ID_YUKON_FE_P && 5988c2ecf20Sopenharmony_ci hw->chip_rev == CHIP_REV_YU_FE2_A0) { 5998c2ecf20Sopenharmony_ci /* apply workaround for integrated resistors calibration */ 6008c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PAGE_ADDR, 17); 6018c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PAGE_DATA, 0x3f60); 6028c2ecf20Sopenharmony_ci } else if (hw->chip_id == CHIP_ID_YUKON_OPT && hw->chip_rev == 0) { 6038c2ecf20Sopenharmony_ci /* apply fixes in PHY AFE */ 6048c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0x00ff); 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci /* apply RDAC termination workaround */ 6078c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 24, 0x2800); 6088c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 23, 0x2001); 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci /* set page register back to 0 */ 6118c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0); 6128c2ecf20Sopenharmony_ci } else if (hw->chip_id != CHIP_ID_YUKON_EX && 6138c2ecf20Sopenharmony_ci hw->chip_id < CHIP_ID_YUKON_SUPR) { 6148c2ecf20Sopenharmony_ci /* no effect on Yukon-XL */ 6158c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl); 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci if (!(sky2->flags & SKY2_FLAG_AUTO_SPEED) || 6188c2ecf20Sopenharmony_ci sky2->speed == SPEED_100) { 6198c2ecf20Sopenharmony_ci /* turn on 100 Mbps LED (LED_LINK100) */ 6208c2ecf20Sopenharmony_ci ledover |= PHY_M_LED_MO_100(MO_LED_ON); 6218c2ecf20Sopenharmony_ci } 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ci if (ledover) 6248c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover); 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci } else if (hw->chip_id == CHIP_ID_YUKON_PRM && 6278c2ecf20Sopenharmony_ci (sky2_read8(hw, B2_MAC_CFG) & 0xf) == 0x7) { 6288c2ecf20Sopenharmony_ci int i; 6298c2ecf20Sopenharmony_ci /* This a phy register setup workaround copied from vendor driver. */ 6308c2ecf20Sopenharmony_ci static const struct { 6318c2ecf20Sopenharmony_ci u16 reg, val; 6328c2ecf20Sopenharmony_ci } eee_afe[] = { 6338c2ecf20Sopenharmony_ci { 0x156, 0x58ce }, 6348c2ecf20Sopenharmony_ci { 0x153, 0x99eb }, 6358c2ecf20Sopenharmony_ci { 0x141, 0x8064 }, 6368c2ecf20Sopenharmony_ci /* { 0x155, 0x130b },*/ 6378c2ecf20Sopenharmony_ci { 0x000, 0x0000 }, 6388c2ecf20Sopenharmony_ci { 0x151, 0x8433 }, 6398c2ecf20Sopenharmony_ci { 0x14b, 0x8c44 }, 6408c2ecf20Sopenharmony_ci { 0x14c, 0x0f90 }, 6418c2ecf20Sopenharmony_ci { 0x14f, 0x39aa }, 6428c2ecf20Sopenharmony_ci /* { 0x154, 0x2f39 },*/ 6438c2ecf20Sopenharmony_ci { 0x14d, 0xba33 }, 6448c2ecf20Sopenharmony_ci { 0x144, 0x0048 }, 6458c2ecf20Sopenharmony_ci { 0x152, 0x2010 }, 6468c2ecf20Sopenharmony_ci /* { 0x158, 0x1223 },*/ 6478c2ecf20Sopenharmony_ci { 0x140, 0x4444 }, 6488c2ecf20Sopenharmony_ci { 0x154, 0x2f3b }, 6498c2ecf20Sopenharmony_ci { 0x158, 0xb203 }, 6508c2ecf20Sopenharmony_ci { 0x157, 0x2029 }, 6518c2ecf20Sopenharmony_ci }; 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci /* Start Workaround for OptimaEEE Rev.Z0 */ 6548c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0x00fb); 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 1, 0x4099); 6578c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 3, 0x1120); 6588c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 11, 0x113c); 6598c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 14, 0x8100); 6608c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 15, 0x112a); 6618c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 17, 0x1008); 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0x00fc); 6648c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 1, 0x20b0); 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0x00ff); 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(eee_afe); i++) { 6698c2ecf20Sopenharmony_ci /* apply AFE settings */ 6708c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 17, eee_afe[i].val); 6718c2ecf20Sopenharmony_ci gm_phy_write(hw, port, 16, eee_afe[i].reg | 1u<<13); 6728c2ecf20Sopenharmony_ci } 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci /* End Workaround for OptimaEEE */ 6758c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0); 6768c2ecf20Sopenharmony_ci 6778c2ecf20Sopenharmony_ci /* Enable 10Base-Te (EEE) */ 6788c2ecf20Sopenharmony_ci if (hw->chip_id >= CHIP_ID_YUKON_PRM) { 6798c2ecf20Sopenharmony_ci reg = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL); 6808c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, 6818c2ecf20Sopenharmony_ci reg | PHY_M_10B_TE_ENABLE); 6828c2ecf20Sopenharmony_ci } 6838c2ecf20Sopenharmony_ci } 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ci /* Enable phy interrupt on auto-negotiation complete (or link up) */ 6868c2ecf20Sopenharmony_ci if (sky2->flags & SKY2_FLAG_AUTO_SPEED) 6878c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL); 6888c2ecf20Sopenharmony_ci else 6898c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); 6908c2ecf20Sopenharmony_ci} 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_cistatic const u32 phy_power[] = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD }; 6938c2ecf20Sopenharmony_cistatic const u32 coma_mode[] = { PCI_Y2_PHY1_COMA, PCI_Y2_PHY2_COMA }; 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_cistatic void sky2_phy_power_up(struct sky2_hw *hw, unsigned port) 6968c2ecf20Sopenharmony_ci{ 6978c2ecf20Sopenharmony_ci u32 reg1; 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 7008c2ecf20Sopenharmony_ci reg1 = sky2_pci_read32(hw, PCI_DEV_REG1); 7018c2ecf20Sopenharmony_ci reg1 &= ~phy_power[port]; 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > CHIP_REV_YU_XL_A1) 7048c2ecf20Sopenharmony_ci reg1 |= coma_mode[port]; 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci sky2_pci_write32(hw, PCI_DEV_REG1, reg1); 7078c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 7088c2ecf20Sopenharmony_ci sky2_pci_read32(hw, PCI_DEV_REG1); 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_FE) 7118c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_CTRL, PHY_CT_ANE); 7128c2ecf20Sopenharmony_ci else if (hw->flags & SKY2_HW_ADV_POWER_CTL) 7138c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR); 7148c2ecf20Sopenharmony_ci} 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_cistatic void sky2_phy_power_down(struct sky2_hw *hw, unsigned port) 7178c2ecf20Sopenharmony_ci{ 7188c2ecf20Sopenharmony_ci u32 reg1; 7198c2ecf20Sopenharmony_ci u16 ctrl; 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_ci /* release GPHY Control reset */ 7228c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR); 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_ci /* release GMAC reset */ 7258c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR); 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_NEWER_PHY) { 7288c2ecf20Sopenharmony_ci /* select page 2 to access MAC control register */ 7298c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2); 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); 7328c2ecf20Sopenharmony_ci /* allow GMII Power Down */ 7338c2ecf20Sopenharmony_ci ctrl &= ~PHY_M_MAC_GMIF_PUP; 7348c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ci /* set page register back to 0 */ 7378c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0); 7388c2ecf20Sopenharmony_ci } 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci /* setup General Purpose Control Register */ 7418c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, 7428c2ecf20Sopenharmony_ci GM_GPCR_FL_PASS | GM_GPCR_SPEED_100 | 7438c2ecf20Sopenharmony_ci GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_FCT_DIS | 7448c2ecf20Sopenharmony_ci GM_GPCR_AU_SPD_DIS); 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci if (hw->chip_id != CHIP_ID_YUKON_EC) { 7478c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EC_U) { 7488c2ecf20Sopenharmony_ci /* select page 2 to access MAC control register */ 7498c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2); 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); 7528c2ecf20Sopenharmony_ci /* enable Power Down */ 7538c2ecf20Sopenharmony_ci ctrl |= PHY_M_PC_POW_D_ENA; 7548c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci /* set page register back to 0 */ 7578c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0); 7588c2ecf20Sopenharmony_ci } 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ci /* set IEEE compatible Power Down Mode (dev. #4.99) */ 7618c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_CTRL, PHY_CT_PDOWN); 7628c2ecf20Sopenharmony_ci } 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 7658c2ecf20Sopenharmony_ci reg1 = sky2_pci_read32(hw, PCI_DEV_REG1); 7668c2ecf20Sopenharmony_ci reg1 |= phy_power[port]; /* set PHY to PowerDown/COMA Mode */ 7678c2ecf20Sopenharmony_ci sky2_pci_write32(hw, PCI_DEV_REG1, reg1); 7688c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 7698c2ecf20Sopenharmony_ci} 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci/* configure IPG according to used link speed */ 7728c2ecf20Sopenharmony_cistatic void sky2_set_ipg(struct sky2_port *sky2) 7738c2ecf20Sopenharmony_ci{ 7748c2ecf20Sopenharmony_ci u16 reg; 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci reg = gma_read16(sky2->hw, sky2->port, GM_SERIAL_MODE); 7778c2ecf20Sopenharmony_ci reg &= ~GM_SMOD_IPG_MSK; 7788c2ecf20Sopenharmony_ci if (sky2->speed > SPEED_100) 7798c2ecf20Sopenharmony_ci reg |= IPG_DATA_VAL(IPG_DATA_DEF_1000); 7808c2ecf20Sopenharmony_ci else 7818c2ecf20Sopenharmony_ci reg |= IPG_DATA_VAL(IPG_DATA_DEF_10_100); 7828c2ecf20Sopenharmony_ci gma_write16(sky2->hw, sky2->port, GM_SERIAL_MODE, reg); 7838c2ecf20Sopenharmony_ci} 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci/* Enable Rx/Tx */ 7868c2ecf20Sopenharmony_cistatic void sky2_enable_rx_tx(struct sky2_port *sky2) 7878c2ecf20Sopenharmony_ci{ 7888c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 7898c2ecf20Sopenharmony_ci unsigned port = sky2->port; 7908c2ecf20Sopenharmony_ci u16 reg; 7918c2ecf20Sopenharmony_ci 7928c2ecf20Sopenharmony_ci reg = gma_read16(hw, port, GM_GP_CTRL); 7938c2ecf20Sopenharmony_ci reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA; 7948c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, reg); 7958c2ecf20Sopenharmony_ci} 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci/* Force a renegotiation */ 7988c2ecf20Sopenharmony_cistatic void sky2_phy_reinit(struct sky2_port *sky2) 7998c2ecf20Sopenharmony_ci{ 8008c2ecf20Sopenharmony_ci spin_lock_bh(&sky2->phy_lock); 8018c2ecf20Sopenharmony_ci sky2_phy_init(sky2->hw, sky2->port); 8028c2ecf20Sopenharmony_ci sky2_enable_rx_tx(sky2); 8038c2ecf20Sopenharmony_ci spin_unlock_bh(&sky2->phy_lock); 8048c2ecf20Sopenharmony_ci} 8058c2ecf20Sopenharmony_ci 8068c2ecf20Sopenharmony_ci/* Put device in state to listen for Wake On Lan */ 8078c2ecf20Sopenharmony_cistatic void sky2_wol_init(struct sky2_port *sky2) 8088c2ecf20Sopenharmony_ci{ 8098c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 8108c2ecf20Sopenharmony_ci unsigned port = sky2->port; 8118c2ecf20Sopenharmony_ci enum flow_control save_mode; 8128c2ecf20Sopenharmony_ci u16 ctrl; 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci /* Bring hardware out of reset */ 8158c2ecf20Sopenharmony_ci sky2_write16(hw, B0_CTST, CS_RST_CLR); 8168c2ecf20Sopenharmony_ci sky2_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR); 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR); 8198c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR); 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_ci /* Force to 10/100 8228c2ecf20Sopenharmony_ci * sky2_reset will re-enable on resume 8238c2ecf20Sopenharmony_ci */ 8248c2ecf20Sopenharmony_ci save_mode = sky2->flow_mode; 8258c2ecf20Sopenharmony_ci ctrl = sky2->advertising; 8268c2ecf20Sopenharmony_ci 8278c2ecf20Sopenharmony_ci sky2->advertising &= ~(ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full); 8288c2ecf20Sopenharmony_ci sky2->flow_mode = FC_NONE; 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci spin_lock_bh(&sky2->phy_lock); 8318c2ecf20Sopenharmony_ci sky2_phy_power_up(hw, port); 8328c2ecf20Sopenharmony_ci sky2_phy_init(hw, port); 8338c2ecf20Sopenharmony_ci spin_unlock_bh(&sky2->phy_lock); 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci sky2->flow_mode = save_mode; 8368c2ecf20Sopenharmony_ci sky2->advertising = ctrl; 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci /* Set GMAC to no flow control and auto update for speed/duplex */ 8398c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, 8408c2ecf20Sopenharmony_ci GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA| 8418c2ecf20Sopenharmony_ci GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS); 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ci /* Set WOL address */ 8448c2ecf20Sopenharmony_ci memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR), 8458c2ecf20Sopenharmony_ci sky2->netdev->dev_addr, ETH_ALEN); 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ci /* Turn on appropriate WOL control bits */ 8488c2ecf20Sopenharmony_ci sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT); 8498c2ecf20Sopenharmony_ci ctrl = 0; 8508c2ecf20Sopenharmony_ci if (sky2->wol & WAKE_PHY) 8518c2ecf20Sopenharmony_ci ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT; 8528c2ecf20Sopenharmony_ci else 8538c2ecf20Sopenharmony_ci ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT; 8548c2ecf20Sopenharmony_ci 8558c2ecf20Sopenharmony_ci if (sky2->wol & WAKE_MAGIC) 8568c2ecf20Sopenharmony_ci ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT; 8578c2ecf20Sopenharmony_ci else 8588c2ecf20Sopenharmony_ci ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT; 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ci ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT; 8618c2ecf20Sopenharmony_ci sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl); 8628c2ecf20Sopenharmony_ci 8638c2ecf20Sopenharmony_ci /* Disable PiG firmware */ 8648c2ecf20Sopenharmony_ci sky2_write16(hw, B0_CTST, Y2_HW_WOL_OFF); 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_ci /* Needed by some broken BIOSes, use PCI rather than PCI-e for WOL */ 8678c2ecf20Sopenharmony_ci if (legacy_pme) { 8688c2ecf20Sopenharmony_ci u32 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1); 8698c2ecf20Sopenharmony_ci reg1 |= PCI_Y2_PME_LEGACY; 8708c2ecf20Sopenharmony_ci sky2_pci_write32(hw, PCI_DEV_REG1, reg1); 8718c2ecf20Sopenharmony_ci } 8728c2ecf20Sopenharmony_ci 8738c2ecf20Sopenharmony_ci /* block receiver */ 8748c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); 8758c2ecf20Sopenharmony_ci sky2_read32(hw, B0_CTST); 8768c2ecf20Sopenharmony_ci} 8778c2ecf20Sopenharmony_ci 8788c2ecf20Sopenharmony_cistatic void sky2_set_tx_stfwd(struct sky2_hw *hw, unsigned port) 8798c2ecf20Sopenharmony_ci{ 8808c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci if ( (hw->chip_id == CHIP_ID_YUKON_EX && 8838c2ecf20Sopenharmony_ci hw->chip_rev != CHIP_REV_YU_EX_A0) || 8848c2ecf20Sopenharmony_ci hw->chip_id >= CHIP_ID_YUKON_FE_P) { 8858c2ecf20Sopenharmony_ci /* Yukon-Extreme B0 and further Extreme devices */ 8868c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA); 8878c2ecf20Sopenharmony_ci } else if (dev->mtu > ETH_DATA_LEN) { 8888c2ecf20Sopenharmony_ci /* set Tx GMAC FIFO Almost Empty Threshold */ 8898c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR), 8908c2ecf20Sopenharmony_ci (ECU_JUMBO_WM << 16) | ECU_AE_THR); 8918c2ecf20Sopenharmony_ci 8928c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_DIS); 8938c2ecf20Sopenharmony_ci } else 8948c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_ENA); 8958c2ecf20Sopenharmony_ci} 8968c2ecf20Sopenharmony_ci 8978c2ecf20Sopenharmony_cistatic void sky2_mac_init(struct sky2_hw *hw, unsigned port) 8988c2ecf20Sopenharmony_ci{ 8998c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(hw->dev[port]); 9008c2ecf20Sopenharmony_ci u16 reg; 9018c2ecf20Sopenharmony_ci u32 rx_reg; 9028c2ecf20Sopenharmony_ci int i; 9038c2ecf20Sopenharmony_ci const u8 *addr = hw->dev[port]->dev_addr; 9048c2ecf20Sopenharmony_ci 9058c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); 9068c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR); 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR); 9098c2ecf20Sopenharmony_ci 9108c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_XL && 9118c2ecf20Sopenharmony_ci hw->chip_rev == CHIP_REV_YU_XL_A0 && 9128c2ecf20Sopenharmony_ci port == 1) { 9138c2ecf20Sopenharmony_ci /* WA DEV_472 -- looks like crossed wires on port 2 */ 9148c2ecf20Sopenharmony_ci /* clear GMAC 1 Control reset */ 9158c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(0, GMAC_CTRL), GMC_RST_CLR); 9168c2ecf20Sopenharmony_ci do { 9178c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_SET); 9188c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_CLR); 9198c2ecf20Sopenharmony_ci } while (gm_phy_read(hw, 1, PHY_MARV_ID0) != PHY_MARV_ID0_VAL || 9208c2ecf20Sopenharmony_ci gm_phy_read(hw, 1, PHY_MARV_ID1) != PHY_MARV_ID1_Y2 || 9218c2ecf20Sopenharmony_ci gm_phy_read(hw, 1, PHY_MARV_INT_MASK) != 0); 9228c2ecf20Sopenharmony_ci } 9238c2ecf20Sopenharmony_ci 9248c2ecf20Sopenharmony_ci sky2_read16(hw, SK_REG(port, GMAC_IRQ_SRC)); 9258c2ecf20Sopenharmony_ci 9268c2ecf20Sopenharmony_ci /* Enable Transmit FIFO Underrun */ 9278c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK); 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci spin_lock_bh(&sky2->phy_lock); 9308c2ecf20Sopenharmony_ci sky2_phy_power_up(hw, port); 9318c2ecf20Sopenharmony_ci sky2_phy_init(hw, port); 9328c2ecf20Sopenharmony_ci spin_unlock_bh(&sky2->phy_lock); 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_ci /* MIB clear */ 9358c2ecf20Sopenharmony_ci reg = gma_read16(hw, port, GM_PHY_ADDR); 9368c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR); 9378c2ecf20Sopenharmony_ci 9388c2ecf20Sopenharmony_ci for (i = GM_MIB_CNT_BASE; i <= GM_MIB_CNT_END; i += 4) 9398c2ecf20Sopenharmony_ci gma_read16(hw, port, i); 9408c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_PHY_ADDR, reg); 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_ci /* transmit control */ 9438c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF)); 9448c2ecf20Sopenharmony_ci 9458c2ecf20Sopenharmony_ci /* receive control reg: unicast + multicast + no FCS */ 9468c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_RX_CTRL, 9478c2ecf20Sopenharmony_ci GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA); 9488c2ecf20Sopenharmony_ci 9498c2ecf20Sopenharmony_ci /* transmit flow control */ 9508c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff); 9518c2ecf20Sopenharmony_ci 9528c2ecf20Sopenharmony_ci /* transmit parameter */ 9538c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_TX_PARAM, 9548c2ecf20Sopenharmony_ci TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) | 9558c2ecf20Sopenharmony_ci TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) | 9568c2ecf20Sopenharmony_ci TX_IPG_JAM_DATA(TX_IPG_JAM_DEF) | 9578c2ecf20Sopenharmony_ci TX_BACK_OFF_LIM(TX_BOF_LIM_DEF)); 9588c2ecf20Sopenharmony_ci 9598c2ecf20Sopenharmony_ci /* serial mode register */ 9608c2ecf20Sopenharmony_ci reg = DATA_BLIND_VAL(DATA_BLIND_DEF) | 9618c2ecf20Sopenharmony_ci GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF_1000); 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci if (hw->dev[port]->mtu > ETH_DATA_LEN) 9648c2ecf20Sopenharmony_ci reg |= GM_SMOD_JUMBO_ENA; 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EC_U && 9678c2ecf20Sopenharmony_ci hw->chip_rev == CHIP_REV_YU_EC_U_B1) 9688c2ecf20Sopenharmony_ci reg |= GM_NEW_FLOW_CTRL; 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_SERIAL_MODE, reg); 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci /* virtual address for data */ 9738c2ecf20Sopenharmony_ci gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr); 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_ci /* physical address: used for pause frames */ 9768c2ecf20Sopenharmony_ci gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr); 9778c2ecf20Sopenharmony_ci 9788c2ecf20Sopenharmony_ci /* ignore counter overflows */ 9798c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_TX_IRQ_MSK, 0); 9808c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_RX_IRQ_MSK, 0); 9818c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_TR_IRQ_MSK, 0); 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_ci /* Configure Rx MAC FIFO */ 9848c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); 9858c2ecf20Sopenharmony_ci rx_reg = GMF_OPER_ON | GMF_RX_F_FL_ON; 9868c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EX || 9878c2ecf20Sopenharmony_ci hw->chip_id == CHIP_ID_YUKON_FE_P) 9888c2ecf20Sopenharmony_ci rx_reg |= GMF_RX_OVER_ON; 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), rx_reg); 9918c2ecf20Sopenharmony_ci 9928c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_XL) { 9938c2ecf20Sopenharmony_ci /* Hardware errata - clear flush mask */ 9948c2ecf20Sopenharmony_ci sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), 0); 9958c2ecf20Sopenharmony_ci } else { 9968c2ecf20Sopenharmony_ci /* Flush Rx MAC FIFO on any flow control or error */ 9978c2ecf20Sopenharmony_ci sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR); 9988c2ecf20Sopenharmony_ci } 9998c2ecf20Sopenharmony_ci 10008c2ecf20Sopenharmony_ci /* Set threshold to 0xa (64 bytes) + 1 to workaround pause bug */ 10018c2ecf20Sopenharmony_ci reg = RX_GMF_FL_THR_DEF + 1; 10028c2ecf20Sopenharmony_ci /* Another magic mystery workaround from sk98lin */ 10038c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_FE_P && 10048c2ecf20Sopenharmony_ci hw->chip_rev == CHIP_REV_YU_FE2_A0) 10058c2ecf20Sopenharmony_ci reg = 0x178; 10068c2ecf20Sopenharmony_ci sky2_write16(hw, SK_REG(port, RX_GMF_FL_THR), reg); 10078c2ecf20Sopenharmony_ci 10088c2ecf20Sopenharmony_ci /* Configure Tx MAC FIFO */ 10098c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR); 10108c2ecf20Sopenharmony_ci sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON); 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_ci /* On chips without ram buffer, pause is controlled by MAC level */ 10138c2ecf20Sopenharmony_ci if (!(hw->flags & SKY2_HW_RAM_BUFFER)) { 10148c2ecf20Sopenharmony_ci /* Pause threshold is scaled by 8 in bytes */ 10158c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_FE_P && 10168c2ecf20Sopenharmony_ci hw->chip_rev == CHIP_REV_YU_FE2_A0) 10178c2ecf20Sopenharmony_ci reg = 1568 / 8; 10188c2ecf20Sopenharmony_ci else 10198c2ecf20Sopenharmony_ci reg = 1024 / 8; 10208c2ecf20Sopenharmony_ci sky2_write16(hw, SK_REG(port, RX_GMF_UP_THR), reg); 10218c2ecf20Sopenharmony_ci sky2_write16(hw, SK_REG(port, RX_GMF_LP_THR), 768 / 8); 10228c2ecf20Sopenharmony_ci 10238c2ecf20Sopenharmony_ci sky2_set_tx_stfwd(hw, port); 10248c2ecf20Sopenharmony_ci } 10258c2ecf20Sopenharmony_ci 10268c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_FE_P && 10278c2ecf20Sopenharmony_ci hw->chip_rev == CHIP_REV_YU_FE2_A0) { 10288c2ecf20Sopenharmony_ci /* disable dynamic watermark */ 10298c2ecf20Sopenharmony_ci reg = sky2_read16(hw, SK_REG(port, TX_GMF_EA)); 10308c2ecf20Sopenharmony_ci reg &= ~TX_DYN_WM_ENA; 10318c2ecf20Sopenharmony_ci sky2_write16(hw, SK_REG(port, TX_GMF_EA), reg); 10328c2ecf20Sopenharmony_ci } 10338c2ecf20Sopenharmony_ci} 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci/* Assign Ram Buffer allocation to queue */ 10368c2ecf20Sopenharmony_cistatic void sky2_ramset(struct sky2_hw *hw, u16 q, u32 start, u32 space) 10378c2ecf20Sopenharmony_ci{ 10388c2ecf20Sopenharmony_ci u32 end; 10398c2ecf20Sopenharmony_ci 10408c2ecf20Sopenharmony_ci /* convert from K bytes to qwords used for hw register */ 10418c2ecf20Sopenharmony_ci start *= 1024/8; 10428c2ecf20Sopenharmony_ci space *= 1024/8; 10438c2ecf20Sopenharmony_ci end = start + space - 1; 10448c2ecf20Sopenharmony_ci 10458c2ecf20Sopenharmony_ci sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR); 10468c2ecf20Sopenharmony_ci sky2_write32(hw, RB_ADDR(q, RB_START), start); 10478c2ecf20Sopenharmony_ci sky2_write32(hw, RB_ADDR(q, RB_END), end); 10488c2ecf20Sopenharmony_ci sky2_write32(hw, RB_ADDR(q, RB_WP), start); 10498c2ecf20Sopenharmony_ci sky2_write32(hw, RB_ADDR(q, RB_RP), start); 10508c2ecf20Sopenharmony_ci 10518c2ecf20Sopenharmony_ci if (q == Q_R1 || q == Q_R2) { 10528c2ecf20Sopenharmony_ci u32 tp = space - space/4; 10538c2ecf20Sopenharmony_ci 10548c2ecf20Sopenharmony_ci /* On receive queue's set the thresholds 10558c2ecf20Sopenharmony_ci * give receiver priority when > 3/4 full 10568c2ecf20Sopenharmony_ci * send pause when down to 2K 10578c2ecf20Sopenharmony_ci */ 10588c2ecf20Sopenharmony_ci sky2_write32(hw, RB_ADDR(q, RB_RX_UTHP), tp); 10598c2ecf20Sopenharmony_ci sky2_write32(hw, RB_ADDR(q, RB_RX_LTHP), space/2); 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci tp = space - 8192/8; 10628c2ecf20Sopenharmony_ci sky2_write32(hw, RB_ADDR(q, RB_RX_UTPP), tp); 10638c2ecf20Sopenharmony_ci sky2_write32(hw, RB_ADDR(q, RB_RX_LTPP), space/4); 10648c2ecf20Sopenharmony_ci } else { 10658c2ecf20Sopenharmony_ci /* Enable store & forward on Tx queue's because 10668c2ecf20Sopenharmony_ci * Tx FIFO is only 1K on Yukon 10678c2ecf20Sopenharmony_ci */ 10688c2ecf20Sopenharmony_ci sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD); 10698c2ecf20Sopenharmony_ci } 10708c2ecf20Sopenharmony_ci 10718c2ecf20Sopenharmony_ci sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD); 10728c2ecf20Sopenharmony_ci sky2_read8(hw, RB_ADDR(q, RB_CTRL)); 10738c2ecf20Sopenharmony_ci} 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_ci/* Setup Bus Memory Interface */ 10768c2ecf20Sopenharmony_cistatic void sky2_qset(struct sky2_hw *hw, u16 q) 10778c2ecf20Sopenharmony_ci{ 10788c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_RESET); 10798c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_OPER_INIT); 10808c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_FIFO_OP_ON); 10818c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(q, Q_WM), BMU_WM_DEFAULT); 10828c2ecf20Sopenharmony_ci} 10838c2ecf20Sopenharmony_ci 10848c2ecf20Sopenharmony_ci/* Setup prefetch unit registers. This is the interface between 10858c2ecf20Sopenharmony_ci * hardware and driver list elements 10868c2ecf20Sopenharmony_ci */ 10878c2ecf20Sopenharmony_cistatic void sky2_prefetch_init(struct sky2_hw *hw, u32 qaddr, 10888c2ecf20Sopenharmony_ci dma_addr_t addr, u32 last) 10898c2ecf20Sopenharmony_ci{ 10908c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); 10918c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_CLR); 10928c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_HI), upper_32_bits(addr)); 10938c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_LO), lower_32_bits(addr)); 10948c2ecf20Sopenharmony_ci sky2_write16(hw, Y2_QADDR(qaddr, PREF_UNIT_LAST_IDX), last); 10958c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_OP_ON); 10968c2ecf20Sopenharmony_ci 10978c2ecf20Sopenharmony_ci sky2_read32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL)); 10988c2ecf20Sopenharmony_ci} 10998c2ecf20Sopenharmony_ci 11008c2ecf20Sopenharmony_cistatic inline struct sky2_tx_le *get_tx_le(struct sky2_port *sky2, u16 *slot) 11018c2ecf20Sopenharmony_ci{ 11028c2ecf20Sopenharmony_ci struct sky2_tx_le *le = sky2->tx_le + *slot; 11038c2ecf20Sopenharmony_ci 11048c2ecf20Sopenharmony_ci *slot = RING_NEXT(*slot, sky2->tx_ring_size); 11058c2ecf20Sopenharmony_ci le->ctrl = 0; 11068c2ecf20Sopenharmony_ci return le; 11078c2ecf20Sopenharmony_ci} 11088c2ecf20Sopenharmony_ci 11098c2ecf20Sopenharmony_cistatic void tx_init(struct sky2_port *sky2) 11108c2ecf20Sopenharmony_ci{ 11118c2ecf20Sopenharmony_ci struct sky2_tx_le *le; 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_ci sky2->tx_prod = sky2->tx_cons = 0; 11148c2ecf20Sopenharmony_ci sky2->tx_tcpsum = 0; 11158c2ecf20Sopenharmony_ci sky2->tx_last_mss = 0; 11168c2ecf20Sopenharmony_ci netdev_reset_queue(sky2->netdev); 11178c2ecf20Sopenharmony_ci 11188c2ecf20Sopenharmony_ci le = get_tx_le(sky2, &sky2->tx_prod); 11198c2ecf20Sopenharmony_ci le->addr = 0; 11208c2ecf20Sopenharmony_ci le->opcode = OP_ADDR64 | HW_OWNER; 11218c2ecf20Sopenharmony_ci sky2->tx_last_upper = 0; 11228c2ecf20Sopenharmony_ci} 11238c2ecf20Sopenharmony_ci 11248c2ecf20Sopenharmony_ci/* Update chip's next pointer */ 11258c2ecf20Sopenharmony_cistatic inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, u16 idx) 11268c2ecf20Sopenharmony_ci{ 11278c2ecf20Sopenharmony_ci /* Make sure write' to descriptors are complete before we tell hardware */ 11288c2ecf20Sopenharmony_ci wmb(); 11298c2ecf20Sopenharmony_ci sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx); 11308c2ecf20Sopenharmony_ci} 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_ci 11338c2ecf20Sopenharmony_cistatic inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2) 11348c2ecf20Sopenharmony_ci{ 11358c2ecf20Sopenharmony_ci struct sky2_rx_le *le = sky2->rx_le + sky2->rx_put; 11368c2ecf20Sopenharmony_ci sky2->rx_put = RING_NEXT(sky2->rx_put, RX_LE_SIZE); 11378c2ecf20Sopenharmony_ci le->ctrl = 0; 11388c2ecf20Sopenharmony_ci return le; 11398c2ecf20Sopenharmony_ci} 11408c2ecf20Sopenharmony_ci 11418c2ecf20Sopenharmony_cistatic unsigned sky2_get_rx_threshold(struct sky2_port *sky2) 11428c2ecf20Sopenharmony_ci{ 11438c2ecf20Sopenharmony_ci unsigned size; 11448c2ecf20Sopenharmony_ci 11458c2ecf20Sopenharmony_ci /* Space needed for frame data + headers rounded up */ 11468c2ecf20Sopenharmony_ci size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8); 11478c2ecf20Sopenharmony_ci 11488c2ecf20Sopenharmony_ci /* Stopping point for hardware truncation */ 11498c2ecf20Sopenharmony_ci return (size - 8) / sizeof(u32); 11508c2ecf20Sopenharmony_ci} 11518c2ecf20Sopenharmony_ci 11528c2ecf20Sopenharmony_cistatic unsigned sky2_get_rx_data_size(struct sky2_port *sky2) 11538c2ecf20Sopenharmony_ci{ 11548c2ecf20Sopenharmony_ci struct rx_ring_info *re; 11558c2ecf20Sopenharmony_ci unsigned size; 11568c2ecf20Sopenharmony_ci 11578c2ecf20Sopenharmony_ci /* Space needed for frame data + headers rounded up */ 11588c2ecf20Sopenharmony_ci size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8); 11598c2ecf20Sopenharmony_ci 11608c2ecf20Sopenharmony_ci sky2->rx_nfrags = size >> PAGE_SHIFT; 11618c2ecf20Sopenharmony_ci BUG_ON(sky2->rx_nfrags > ARRAY_SIZE(re->frag_addr)); 11628c2ecf20Sopenharmony_ci 11638c2ecf20Sopenharmony_ci /* Compute residue after pages */ 11648c2ecf20Sopenharmony_ci size -= sky2->rx_nfrags << PAGE_SHIFT; 11658c2ecf20Sopenharmony_ci 11668c2ecf20Sopenharmony_ci /* Optimize to handle small packets and headers */ 11678c2ecf20Sopenharmony_ci if (size < copybreak) 11688c2ecf20Sopenharmony_ci size = copybreak; 11698c2ecf20Sopenharmony_ci if (size < ETH_HLEN) 11708c2ecf20Sopenharmony_ci size = ETH_HLEN; 11718c2ecf20Sopenharmony_ci 11728c2ecf20Sopenharmony_ci return size; 11738c2ecf20Sopenharmony_ci} 11748c2ecf20Sopenharmony_ci 11758c2ecf20Sopenharmony_ci/* Build description to hardware for one receive segment */ 11768c2ecf20Sopenharmony_cistatic void sky2_rx_add(struct sky2_port *sky2, u8 op, 11778c2ecf20Sopenharmony_ci dma_addr_t map, unsigned len) 11788c2ecf20Sopenharmony_ci{ 11798c2ecf20Sopenharmony_ci struct sky2_rx_le *le; 11808c2ecf20Sopenharmony_ci 11818c2ecf20Sopenharmony_ci if (sizeof(dma_addr_t) > sizeof(u32)) { 11828c2ecf20Sopenharmony_ci le = sky2_next_rx(sky2); 11838c2ecf20Sopenharmony_ci le->addr = cpu_to_le32(upper_32_bits(map)); 11848c2ecf20Sopenharmony_ci le->opcode = OP_ADDR64 | HW_OWNER; 11858c2ecf20Sopenharmony_ci } 11868c2ecf20Sopenharmony_ci 11878c2ecf20Sopenharmony_ci le = sky2_next_rx(sky2); 11888c2ecf20Sopenharmony_ci le->addr = cpu_to_le32(lower_32_bits(map)); 11898c2ecf20Sopenharmony_ci le->length = cpu_to_le16(len); 11908c2ecf20Sopenharmony_ci le->opcode = op | HW_OWNER; 11918c2ecf20Sopenharmony_ci} 11928c2ecf20Sopenharmony_ci 11938c2ecf20Sopenharmony_ci/* Build description to hardware for one possibly fragmented skb */ 11948c2ecf20Sopenharmony_cistatic void sky2_rx_submit(struct sky2_port *sky2, 11958c2ecf20Sopenharmony_ci const struct rx_ring_info *re) 11968c2ecf20Sopenharmony_ci{ 11978c2ecf20Sopenharmony_ci int i; 11988c2ecf20Sopenharmony_ci 11998c2ecf20Sopenharmony_ci sky2_rx_add(sky2, OP_PACKET, re->data_addr, sky2->rx_data_size); 12008c2ecf20Sopenharmony_ci 12018c2ecf20Sopenharmony_ci for (i = 0; i < skb_shinfo(re->skb)->nr_frags; i++) 12028c2ecf20Sopenharmony_ci sky2_rx_add(sky2, OP_BUFFER, re->frag_addr[i], PAGE_SIZE); 12038c2ecf20Sopenharmony_ci} 12048c2ecf20Sopenharmony_ci 12058c2ecf20Sopenharmony_ci 12068c2ecf20Sopenharmony_cistatic int sky2_rx_map_skb(struct pci_dev *pdev, struct rx_ring_info *re, 12078c2ecf20Sopenharmony_ci unsigned size) 12088c2ecf20Sopenharmony_ci{ 12098c2ecf20Sopenharmony_ci struct sk_buff *skb = re->skb; 12108c2ecf20Sopenharmony_ci int i; 12118c2ecf20Sopenharmony_ci 12128c2ecf20Sopenharmony_ci re->data_addr = dma_map_single(&pdev->dev, skb->data, size, 12138c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 12148c2ecf20Sopenharmony_ci if (dma_mapping_error(&pdev->dev, re->data_addr)) 12158c2ecf20Sopenharmony_ci goto mapping_error; 12168c2ecf20Sopenharmony_ci 12178c2ecf20Sopenharmony_ci dma_unmap_len_set(re, data_size, size); 12188c2ecf20Sopenharmony_ci 12198c2ecf20Sopenharmony_ci for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 12208c2ecf20Sopenharmony_ci const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 12218c2ecf20Sopenharmony_ci 12228c2ecf20Sopenharmony_ci re->frag_addr[i] = skb_frag_dma_map(&pdev->dev, frag, 0, 12238c2ecf20Sopenharmony_ci skb_frag_size(frag), 12248c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 12258c2ecf20Sopenharmony_ci 12268c2ecf20Sopenharmony_ci if (dma_mapping_error(&pdev->dev, re->frag_addr[i])) 12278c2ecf20Sopenharmony_ci goto map_page_error; 12288c2ecf20Sopenharmony_ci } 12298c2ecf20Sopenharmony_ci return 0; 12308c2ecf20Sopenharmony_ci 12318c2ecf20Sopenharmony_cimap_page_error: 12328c2ecf20Sopenharmony_ci while (--i >= 0) { 12338c2ecf20Sopenharmony_ci dma_unmap_page(&pdev->dev, re->frag_addr[i], 12348c2ecf20Sopenharmony_ci skb_frag_size(&skb_shinfo(skb)->frags[i]), 12358c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 12368c2ecf20Sopenharmony_ci } 12378c2ecf20Sopenharmony_ci 12388c2ecf20Sopenharmony_ci dma_unmap_single(&pdev->dev, re->data_addr, 12398c2ecf20Sopenharmony_ci dma_unmap_len(re, data_size), DMA_FROM_DEVICE); 12408c2ecf20Sopenharmony_ci 12418c2ecf20Sopenharmony_cimapping_error: 12428c2ecf20Sopenharmony_ci if (net_ratelimit()) 12438c2ecf20Sopenharmony_ci dev_warn(&pdev->dev, "%s: rx mapping error\n", 12448c2ecf20Sopenharmony_ci skb->dev->name); 12458c2ecf20Sopenharmony_ci return -EIO; 12468c2ecf20Sopenharmony_ci} 12478c2ecf20Sopenharmony_ci 12488c2ecf20Sopenharmony_cistatic void sky2_rx_unmap_skb(struct pci_dev *pdev, struct rx_ring_info *re) 12498c2ecf20Sopenharmony_ci{ 12508c2ecf20Sopenharmony_ci struct sk_buff *skb = re->skb; 12518c2ecf20Sopenharmony_ci int i; 12528c2ecf20Sopenharmony_ci 12538c2ecf20Sopenharmony_ci dma_unmap_single(&pdev->dev, re->data_addr, 12548c2ecf20Sopenharmony_ci dma_unmap_len(re, data_size), DMA_FROM_DEVICE); 12558c2ecf20Sopenharmony_ci 12568c2ecf20Sopenharmony_ci for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) 12578c2ecf20Sopenharmony_ci dma_unmap_page(&pdev->dev, re->frag_addr[i], 12588c2ecf20Sopenharmony_ci skb_frag_size(&skb_shinfo(skb)->frags[i]), 12598c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 12608c2ecf20Sopenharmony_ci} 12618c2ecf20Sopenharmony_ci 12628c2ecf20Sopenharmony_ci/* Tell chip where to start receive checksum. 12638c2ecf20Sopenharmony_ci * Actually has two checksums, but set both same to avoid possible byte 12648c2ecf20Sopenharmony_ci * order problems. 12658c2ecf20Sopenharmony_ci */ 12668c2ecf20Sopenharmony_cistatic void rx_set_checksum(struct sky2_port *sky2) 12678c2ecf20Sopenharmony_ci{ 12688c2ecf20Sopenharmony_ci struct sky2_rx_le *le = sky2_next_rx(sky2); 12698c2ecf20Sopenharmony_ci 12708c2ecf20Sopenharmony_ci le->addr = cpu_to_le32((ETH_HLEN << 16) | ETH_HLEN); 12718c2ecf20Sopenharmony_ci le->ctrl = 0; 12728c2ecf20Sopenharmony_ci le->opcode = OP_TCPSTART | HW_OWNER; 12738c2ecf20Sopenharmony_ci 12748c2ecf20Sopenharmony_ci sky2_write32(sky2->hw, 12758c2ecf20Sopenharmony_ci Q_ADDR(rxqaddr[sky2->port], Q_CSR), 12768c2ecf20Sopenharmony_ci (sky2->netdev->features & NETIF_F_RXCSUM) 12778c2ecf20Sopenharmony_ci ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM); 12788c2ecf20Sopenharmony_ci} 12798c2ecf20Sopenharmony_ci 12808c2ecf20Sopenharmony_ci/* Enable/disable receive hash calculation (RSS) */ 12818c2ecf20Sopenharmony_cistatic void rx_set_rss(struct net_device *dev, netdev_features_t features) 12828c2ecf20Sopenharmony_ci{ 12838c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 12848c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 12858c2ecf20Sopenharmony_ci int i, nkeys = 4; 12868c2ecf20Sopenharmony_ci 12878c2ecf20Sopenharmony_ci /* Supports IPv6 and other modes */ 12888c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_NEW_LE) { 12898c2ecf20Sopenharmony_ci nkeys = 10; 12908c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(sky2->port, RSS_CFG), HASH_ALL); 12918c2ecf20Sopenharmony_ci } 12928c2ecf20Sopenharmony_ci 12938c2ecf20Sopenharmony_ci /* Program RSS initial values */ 12948c2ecf20Sopenharmony_ci if (features & NETIF_F_RXHASH) { 12958c2ecf20Sopenharmony_ci u32 rss_key[10]; 12968c2ecf20Sopenharmony_ci 12978c2ecf20Sopenharmony_ci netdev_rss_key_fill(rss_key, sizeof(rss_key)); 12988c2ecf20Sopenharmony_ci for (i = 0; i < nkeys; i++) 12998c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(sky2->port, RSS_KEY + i * 4), 13008c2ecf20Sopenharmony_ci rss_key[i]); 13018c2ecf20Sopenharmony_ci 13028c2ecf20Sopenharmony_ci /* Need to turn on (undocumented) flag to make hashing work */ 13038c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), 13048c2ecf20Sopenharmony_ci RX_STFW_ENA); 13058c2ecf20Sopenharmony_ci 13068c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR), 13078c2ecf20Sopenharmony_ci BMU_ENA_RX_RSS_HASH); 13088c2ecf20Sopenharmony_ci } else 13098c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR), 13108c2ecf20Sopenharmony_ci BMU_DIS_RX_RSS_HASH); 13118c2ecf20Sopenharmony_ci} 13128c2ecf20Sopenharmony_ci 13138c2ecf20Sopenharmony_ci/* 13148c2ecf20Sopenharmony_ci * The RX Stop command will not work for Yukon-2 if the BMU does not 13158c2ecf20Sopenharmony_ci * reach the end of packet and since we can't make sure that we have 13168c2ecf20Sopenharmony_ci * incoming data, we must reset the BMU while it is not doing a DMA 13178c2ecf20Sopenharmony_ci * transfer. Since it is possible that the RX path is still active, 13188c2ecf20Sopenharmony_ci * the RX RAM buffer will be stopped first, so any possible incoming 13198c2ecf20Sopenharmony_ci * data will not trigger a DMA. After the RAM buffer is stopped, the 13208c2ecf20Sopenharmony_ci * BMU is polled until any DMA in progress is ended and only then it 13218c2ecf20Sopenharmony_ci * will be reset. 13228c2ecf20Sopenharmony_ci */ 13238c2ecf20Sopenharmony_cistatic void sky2_rx_stop(struct sky2_port *sky2) 13248c2ecf20Sopenharmony_ci{ 13258c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 13268c2ecf20Sopenharmony_ci unsigned rxq = rxqaddr[sky2->port]; 13278c2ecf20Sopenharmony_ci int i; 13288c2ecf20Sopenharmony_ci 13298c2ecf20Sopenharmony_ci /* disable the RAM Buffer receive queue */ 13308c2ecf20Sopenharmony_ci sky2_write8(hw, RB_ADDR(rxq, RB_CTRL), RB_DIS_OP_MD); 13318c2ecf20Sopenharmony_ci 13328c2ecf20Sopenharmony_ci for (i = 0; i < 0xffff; i++) 13338c2ecf20Sopenharmony_ci if (sky2_read8(hw, RB_ADDR(rxq, Q_RSL)) 13348c2ecf20Sopenharmony_ci == sky2_read8(hw, RB_ADDR(rxq, Q_RL))) 13358c2ecf20Sopenharmony_ci goto stopped; 13368c2ecf20Sopenharmony_ci 13378c2ecf20Sopenharmony_ci netdev_warn(sky2->netdev, "receiver stop failed\n"); 13388c2ecf20Sopenharmony_cistopped: 13398c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(rxq, Q_CSR), BMU_RST_SET | BMU_FIFO_RST); 13408c2ecf20Sopenharmony_ci 13418c2ecf20Sopenharmony_ci /* reset the Rx prefetch unit */ 13428c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_QADDR(rxq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); 13438c2ecf20Sopenharmony_ci} 13448c2ecf20Sopenharmony_ci 13458c2ecf20Sopenharmony_ci/* Clean out receive buffer area, assumes receiver hardware stopped */ 13468c2ecf20Sopenharmony_cistatic void sky2_rx_clean(struct sky2_port *sky2) 13478c2ecf20Sopenharmony_ci{ 13488c2ecf20Sopenharmony_ci unsigned i; 13498c2ecf20Sopenharmony_ci 13508c2ecf20Sopenharmony_ci if (sky2->rx_le) 13518c2ecf20Sopenharmony_ci memset(sky2->rx_le, 0, RX_LE_BYTES); 13528c2ecf20Sopenharmony_ci 13538c2ecf20Sopenharmony_ci for (i = 0; i < sky2->rx_pending; i++) { 13548c2ecf20Sopenharmony_ci struct rx_ring_info *re = sky2->rx_ring + i; 13558c2ecf20Sopenharmony_ci 13568c2ecf20Sopenharmony_ci if (re->skb) { 13578c2ecf20Sopenharmony_ci sky2_rx_unmap_skb(sky2->hw->pdev, re); 13588c2ecf20Sopenharmony_ci kfree_skb(re->skb); 13598c2ecf20Sopenharmony_ci re->skb = NULL; 13608c2ecf20Sopenharmony_ci } 13618c2ecf20Sopenharmony_ci } 13628c2ecf20Sopenharmony_ci} 13638c2ecf20Sopenharmony_ci 13648c2ecf20Sopenharmony_ci/* Basic MII support */ 13658c2ecf20Sopenharmony_cistatic int sky2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 13668c2ecf20Sopenharmony_ci{ 13678c2ecf20Sopenharmony_ci struct mii_ioctl_data *data = if_mii(ifr); 13688c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 13698c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 13708c2ecf20Sopenharmony_ci int err = -EOPNOTSUPP; 13718c2ecf20Sopenharmony_ci 13728c2ecf20Sopenharmony_ci if (!netif_running(dev)) 13738c2ecf20Sopenharmony_ci return -ENODEV; /* Phy still in reset */ 13748c2ecf20Sopenharmony_ci 13758c2ecf20Sopenharmony_ci switch (cmd) { 13768c2ecf20Sopenharmony_ci case SIOCGMIIPHY: 13778c2ecf20Sopenharmony_ci data->phy_id = PHY_ADDR_MARV; 13788c2ecf20Sopenharmony_ci 13798c2ecf20Sopenharmony_ci fallthrough; 13808c2ecf20Sopenharmony_ci case SIOCGMIIREG: { 13818c2ecf20Sopenharmony_ci u16 val = 0; 13828c2ecf20Sopenharmony_ci 13838c2ecf20Sopenharmony_ci spin_lock_bh(&sky2->phy_lock); 13848c2ecf20Sopenharmony_ci err = __gm_phy_read(hw, sky2->port, data->reg_num & 0x1f, &val); 13858c2ecf20Sopenharmony_ci spin_unlock_bh(&sky2->phy_lock); 13868c2ecf20Sopenharmony_ci 13878c2ecf20Sopenharmony_ci data->val_out = val; 13888c2ecf20Sopenharmony_ci break; 13898c2ecf20Sopenharmony_ci } 13908c2ecf20Sopenharmony_ci 13918c2ecf20Sopenharmony_ci case SIOCSMIIREG: 13928c2ecf20Sopenharmony_ci spin_lock_bh(&sky2->phy_lock); 13938c2ecf20Sopenharmony_ci err = gm_phy_write(hw, sky2->port, data->reg_num & 0x1f, 13948c2ecf20Sopenharmony_ci data->val_in); 13958c2ecf20Sopenharmony_ci spin_unlock_bh(&sky2->phy_lock); 13968c2ecf20Sopenharmony_ci break; 13978c2ecf20Sopenharmony_ci } 13988c2ecf20Sopenharmony_ci return err; 13998c2ecf20Sopenharmony_ci} 14008c2ecf20Sopenharmony_ci 14018c2ecf20Sopenharmony_ci#define SKY2_VLAN_OFFLOADS (NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO) 14028c2ecf20Sopenharmony_ci 14038c2ecf20Sopenharmony_cistatic void sky2_vlan_mode(struct net_device *dev, netdev_features_t features) 14048c2ecf20Sopenharmony_ci{ 14058c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 14068c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 14078c2ecf20Sopenharmony_ci u16 port = sky2->port; 14088c2ecf20Sopenharmony_ci 14098c2ecf20Sopenharmony_ci if (features & NETIF_F_HW_VLAN_CTAG_RX) 14108c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), 14118c2ecf20Sopenharmony_ci RX_VLAN_STRIP_ON); 14128c2ecf20Sopenharmony_ci else 14138c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), 14148c2ecf20Sopenharmony_ci RX_VLAN_STRIP_OFF); 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_ci if (features & NETIF_F_HW_VLAN_CTAG_TX) { 14178c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), 14188c2ecf20Sopenharmony_ci TX_VLAN_TAG_ON); 14198c2ecf20Sopenharmony_ci 14208c2ecf20Sopenharmony_ci dev->vlan_features |= SKY2_VLAN_OFFLOADS; 14218c2ecf20Sopenharmony_ci } else { 14228c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), 14238c2ecf20Sopenharmony_ci TX_VLAN_TAG_OFF); 14248c2ecf20Sopenharmony_ci 14258c2ecf20Sopenharmony_ci /* Can't do transmit offload of vlan without hw vlan */ 14268c2ecf20Sopenharmony_ci dev->vlan_features &= ~SKY2_VLAN_OFFLOADS; 14278c2ecf20Sopenharmony_ci } 14288c2ecf20Sopenharmony_ci} 14298c2ecf20Sopenharmony_ci 14308c2ecf20Sopenharmony_ci/* Amount of required worst case padding in rx buffer */ 14318c2ecf20Sopenharmony_cistatic inline unsigned sky2_rx_pad(const struct sky2_hw *hw) 14328c2ecf20Sopenharmony_ci{ 14338c2ecf20Sopenharmony_ci return (hw->flags & SKY2_HW_RAM_BUFFER) ? 8 : 2; 14348c2ecf20Sopenharmony_ci} 14358c2ecf20Sopenharmony_ci 14368c2ecf20Sopenharmony_ci/* 14378c2ecf20Sopenharmony_ci * Allocate an skb for receiving. If the MTU is large enough 14388c2ecf20Sopenharmony_ci * make the skb non-linear with a fragment list of pages. 14398c2ecf20Sopenharmony_ci */ 14408c2ecf20Sopenharmony_cistatic struct sk_buff *sky2_rx_alloc(struct sky2_port *sky2, gfp_t gfp) 14418c2ecf20Sopenharmony_ci{ 14428c2ecf20Sopenharmony_ci struct sk_buff *skb; 14438c2ecf20Sopenharmony_ci int i; 14448c2ecf20Sopenharmony_ci 14458c2ecf20Sopenharmony_ci skb = __netdev_alloc_skb(sky2->netdev, 14468c2ecf20Sopenharmony_ci sky2->rx_data_size + sky2_rx_pad(sky2->hw), 14478c2ecf20Sopenharmony_ci gfp); 14488c2ecf20Sopenharmony_ci if (!skb) 14498c2ecf20Sopenharmony_ci goto nomem; 14508c2ecf20Sopenharmony_ci 14518c2ecf20Sopenharmony_ci if (sky2->hw->flags & SKY2_HW_RAM_BUFFER) { 14528c2ecf20Sopenharmony_ci unsigned char *start; 14538c2ecf20Sopenharmony_ci /* 14548c2ecf20Sopenharmony_ci * Workaround for a bug in FIFO that cause hang 14558c2ecf20Sopenharmony_ci * if the FIFO if the receive buffer is not 64 byte aligned. 14568c2ecf20Sopenharmony_ci * The buffer returned from netdev_alloc_skb is 14578c2ecf20Sopenharmony_ci * aligned except if slab debugging is enabled. 14588c2ecf20Sopenharmony_ci */ 14598c2ecf20Sopenharmony_ci start = PTR_ALIGN(skb->data, 8); 14608c2ecf20Sopenharmony_ci skb_reserve(skb, start - skb->data); 14618c2ecf20Sopenharmony_ci } else 14628c2ecf20Sopenharmony_ci skb_reserve(skb, NET_IP_ALIGN); 14638c2ecf20Sopenharmony_ci 14648c2ecf20Sopenharmony_ci for (i = 0; i < sky2->rx_nfrags; i++) { 14658c2ecf20Sopenharmony_ci struct page *page = alloc_page(gfp); 14668c2ecf20Sopenharmony_ci 14678c2ecf20Sopenharmony_ci if (!page) 14688c2ecf20Sopenharmony_ci goto free_partial; 14698c2ecf20Sopenharmony_ci skb_fill_page_desc(skb, i, page, 0, PAGE_SIZE); 14708c2ecf20Sopenharmony_ci } 14718c2ecf20Sopenharmony_ci 14728c2ecf20Sopenharmony_ci return skb; 14738c2ecf20Sopenharmony_cifree_partial: 14748c2ecf20Sopenharmony_ci kfree_skb(skb); 14758c2ecf20Sopenharmony_cinomem: 14768c2ecf20Sopenharmony_ci return NULL; 14778c2ecf20Sopenharmony_ci} 14788c2ecf20Sopenharmony_ci 14798c2ecf20Sopenharmony_cistatic inline void sky2_rx_update(struct sky2_port *sky2, unsigned rxq) 14808c2ecf20Sopenharmony_ci{ 14818c2ecf20Sopenharmony_ci sky2_put_idx(sky2->hw, rxq, sky2->rx_put); 14828c2ecf20Sopenharmony_ci} 14838c2ecf20Sopenharmony_ci 14848c2ecf20Sopenharmony_cistatic int sky2_alloc_rx_skbs(struct sky2_port *sky2) 14858c2ecf20Sopenharmony_ci{ 14868c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 14878c2ecf20Sopenharmony_ci unsigned i; 14888c2ecf20Sopenharmony_ci 14898c2ecf20Sopenharmony_ci sky2->rx_data_size = sky2_get_rx_data_size(sky2); 14908c2ecf20Sopenharmony_ci 14918c2ecf20Sopenharmony_ci /* Fill Rx ring */ 14928c2ecf20Sopenharmony_ci for (i = 0; i < sky2->rx_pending; i++) { 14938c2ecf20Sopenharmony_ci struct rx_ring_info *re = sky2->rx_ring + i; 14948c2ecf20Sopenharmony_ci 14958c2ecf20Sopenharmony_ci re->skb = sky2_rx_alloc(sky2, GFP_KERNEL); 14968c2ecf20Sopenharmony_ci if (!re->skb) 14978c2ecf20Sopenharmony_ci return -ENOMEM; 14988c2ecf20Sopenharmony_ci 14998c2ecf20Sopenharmony_ci if (sky2_rx_map_skb(hw->pdev, re, sky2->rx_data_size)) { 15008c2ecf20Sopenharmony_ci dev_kfree_skb(re->skb); 15018c2ecf20Sopenharmony_ci re->skb = NULL; 15028c2ecf20Sopenharmony_ci return -ENOMEM; 15038c2ecf20Sopenharmony_ci } 15048c2ecf20Sopenharmony_ci } 15058c2ecf20Sopenharmony_ci return 0; 15068c2ecf20Sopenharmony_ci} 15078c2ecf20Sopenharmony_ci 15088c2ecf20Sopenharmony_ci/* 15098c2ecf20Sopenharmony_ci * Setup receiver buffer pool. 15108c2ecf20Sopenharmony_ci * Normal case this ends up creating one list element for skb 15118c2ecf20Sopenharmony_ci * in the receive ring. Worst case if using large MTU and each 15128c2ecf20Sopenharmony_ci * allocation falls on a different 64 bit region, that results 15138c2ecf20Sopenharmony_ci * in 6 list elements per ring entry. 15148c2ecf20Sopenharmony_ci * One element is used for checksum enable/disable, and one 15158c2ecf20Sopenharmony_ci * extra to avoid wrap. 15168c2ecf20Sopenharmony_ci */ 15178c2ecf20Sopenharmony_cistatic void sky2_rx_start(struct sky2_port *sky2) 15188c2ecf20Sopenharmony_ci{ 15198c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 15208c2ecf20Sopenharmony_ci struct rx_ring_info *re; 15218c2ecf20Sopenharmony_ci unsigned rxq = rxqaddr[sky2->port]; 15228c2ecf20Sopenharmony_ci unsigned i, thresh; 15238c2ecf20Sopenharmony_ci 15248c2ecf20Sopenharmony_ci sky2->rx_put = sky2->rx_next = 0; 15258c2ecf20Sopenharmony_ci sky2_qset(hw, rxq); 15268c2ecf20Sopenharmony_ci 15278c2ecf20Sopenharmony_ci /* On PCI express lowering the watermark gives better performance */ 15288c2ecf20Sopenharmony_ci if (pci_is_pcie(hw->pdev)) 15298c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(rxq, Q_WM), BMU_WM_PEX); 15308c2ecf20Sopenharmony_ci 15318c2ecf20Sopenharmony_ci /* These chips have no ram buffer? 15328c2ecf20Sopenharmony_ci * MAC Rx RAM Read is controlled by hardware */ 15338c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EC_U && 15348c2ecf20Sopenharmony_ci hw->chip_rev > CHIP_REV_YU_EC_U_A0) 15358c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(rxq, Q_TEST), F_M_RX_RAM_DIS); 15368c2ecf20Sopenharmony_ci 15378c2ecf20Sopenharmony_ci sky2_prefetch_init(hw, rxq, sky2->rx_le_map, RX_LE_SIZE - 1); 15388c2ecf20Sopenharmony_ci 15398c2ecf20Sopenharmony_ci if (!(hw->flags & SKY2_HW_NEW_LE)) 15408c2ecf20Sopenharmony_ci rx_set_checksum(sky2); 15418c2ecf20Sopenharmony_ci 15428c2ecf20Sopenharmony_ci if (!(hw->flags & SKY2_HW_RSS_BROKEN)) 15438c2ecf20Sopenharmony_ci rx_set_rss(sky2->netdev, sky2->netdev->features); 15448c2ecf20Sopenharmony_ci 15458c2ecf20Sopenharmony_ci /* submit Rx ring */ 15468c2ecf20Sopenharmony_ci for (i = 0; i < sky2->rx_pending; i++) { 15478c2ecf20Sopenharmony_ci re = sky2->rx_ring + i; 15488c2ecf20Sopenharmony_ci sky2_rx_submit(sky2, re); 15498c2ecf20Sopenharmony_ci } 15508c2ecf20Sopenharmony_ci 15518c2ecf20Sopenharmony_ci /* 15528c2ecf20Sopenharmony_ci * The receiver hangs if it receives frames larger than the 15538c2ecf20Sopenharmony_ci * packet buffer. As a workaround, truncate oversize frames, but 15548c2ecf20Sopenharmony_ci * the register is limited to 9 bits, so if you do frames > 2052 15558c2ecf20Sopenharmony_ci * you better get the MTU right! 15568c2ecf20Sopenharmony_ci */ 15578c2ecf20Sopenharmony_ci thresh = sky2_get_rx_threshold(sky2); 15588c2ecf20Sopenharmony_ci if (thresh > 0x1ff) 15598c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_OFF); 15608c2ecf20Sopenharmony_ci else { 15618c2ecf20Sopenharmony_ci sky2_write16(hw, SK_REG(sky2->port, RX_GMF_TR_THR), thresh); 15628c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_TRUNC_ON); 15638c2ecf20Sopenharmony_ci } 15648c2ecf20Sopenharmony_ci 15658c2ecf20Sopenharmony_ci /* Tell chip about available buffers */ 15668c2ecf20Sopenharmony_ci sky2_rx_update(sky2, rxq); 15678c2ecf20Sopenharmony_ci 15688c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EX || 15698c2ecf20Sopenharmony_ci hw->chip_id == CHIP_ID_YUKON_SUPR) { 15708c2ecf20Sopenharmony_ci /* 15718c2ecf20Sopenharmony_ci * Disable flushing of non ASF packets; 15728c2ecf20Sopenharmony_ci * must be done after initializing the BMUs; 15738c2ecf20Sopenharmony_ci * drivers without ASF support should do this too, otherwise 15748c2ecf20Sopenharmony_ci * it may happen that they cannot run on ASF devices; 15758c2ecf20Sopenharmony_ci * remember that the MAC FIFO isn't reset during initialization. 15768c2ecf20Sopenharmony_ci */ 15778c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), RX_MACSEC_FLUSH_OFF); 15788c2ecf20Sopenharmony_ci } 15798c2ecf20Sopenharmony_ci 15808c2ecf20Sopenharmony_ci if (hw->chip_id >= CHIP_ID_YUKON_SUPR) { 15818c2ecf20Sopenharmony_ci /* Enable RX Home Address & Routing Header checksum fix */ 15828c2ecf20Sopenharmony_ci sky2_write16(hw, SK_REG(sky2->port, RX_GMF_FL_CTRL), 15838c2ecf20Sopenharmony_ci RX_IPV6_SA_MOB_ENA | RX_IPV6_DA_MOB_ENA); 15848c2ecf20Sopenharmony_ci 15858c2ecf20Sopenharmony_ci /* Enable TX Home Address & Routing Header checksum fix */ 15868c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(txqaddr[sky2->port], Q_TEST), 15878c2ecf20Sopenharmony_ci TBMU_TEST_HOME_ADD_FIX_EN | TBMU_TEST_ROUTING_ADD_FIX_EN); 15888c2ecf20Sopenharmony_ci } 15898c2ecf20Sopenharmony_ci} 15908c2ecf20Sopenharmony_ci 15918c2ecf20Sopenharmony_cistatic int sky2_alloc_buffers(struct sky2_port *sky2) 15928c2ecf20Sopenharmony_ci{ 15938c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 15948c2ecf20Sopenharmony_ci 15958c2ecf20Sopenharmony_ci /* must be power of 2 */ 15968c2ecf20Sopenharmony_ci sky2->tx_le = dma_alloc_coherent(&hw->pdev->dev, 15978c2ecf20Sopenharmony_ci sky2->tx_ring_size * sizeof(struct sky2_tx_le), 15988c2ecf20Sopenharmony_ci &sky2->tx_le_map, GFP_KERNEL); 15998c2ecf20Sopenharmony_ci if (!sky2->tx_le) 16008c2ecf20Sopenharmony_ci goto nomem; 16018c2ecf20Sopenharmony_ci 16028c2ecf20Sopenharmony_ci sky2->tx_ring = kcalloc(sky2->tx_ring_size, sizeof(struct tx_ring_info), 16038c2ecf20Sopenharmony_ci GFP_KERNEL); 16048c2ecf20Sopenharmony_ci if (!sky2->tx_ring) 16058c2ecf20Sopenharmony_ci goto nomem; 16068c2ecf20Sopenharmony_ci 16078c2ecf20Sopenharmony_ci sky2->rx_le = dma_alloc_coherent(&hw->pdev->dev, RX_LE_BYTES, 16088c2ecf20Sopenharmony_ci &sky2->rx_le_map, GFP_KERNEL); 16098c2ecf20Sopenharmony_ci if (!sky2->rx_le) 16108c2ecf20Sopenharmony_ci goto nomem; 16118c2ecf20Sopenharmony_ci 16128c2ecf20Sopenharmony_ci sky2->rx_ring = kcalloc(sky2->rx_pending, sizeof(struct rx_ring_info), 16138c2ecf20Sopenharmony_ci GFP_KERNEL); 16148c2ecf20Sopenharmony_ci if (!sky2->rx_ring) 16158c2ecf20Sopenharmony_ci goto nomem; 16168c2ecf20Sopenharmony_ci 16178c2ecf20Sopenharmony_ci return sky2_alloc_rx_skbs(sky2); 16188c2ecf20Sopenharmony_cinomem: 16198c2ecf20Sopenharmony_ci return -ENOMEM; 16208c2ecf20Sopenharmony_ci} 16218c2ecf20Sopenharmony_ci 16228c2ecf20Sopenharmony_cistatic void sky2_free_buffers(struct sky2_port *sky2) 16238c2ecf20Sopenharmony_ci{ 16248c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 16258c2ecf20Sopenharmony_ci 16268c2ecf20Sopenharmony_ci sky2_rx_clean(sky2); 16278c2ecf20Sopenharmony_ci 16288c2ecf20Sopenharmony_ci if (sky2->rx_le) { 16298c2ecf20Sopenharmony_ci dma_free_coherent(&hw->pdev->dev, RX_LE_BYTES, sky2->rx_le, 16308c2ecf20Sopenharmony_ci sky2->rx_le_map); 16318c2ecf20Sopenharmony_ci sky2->rx_le = NULL; 16328c2ecf20Sopenharmony_ci } 16338c2ecf20Sopenharmony_ci if (sky2->tx_le) { 16348c2ecf20Sopenharmony_ci dma_free_coherent(&hw->pdev->dev, 16358c2ecf20Sopenharmony_ci sky2->tx_ring_size * sizeof(struct sky2_tx_le), 16368c2ecf20Sopenharmony_ci sky2->tx_le, sky2->tx_le_map); 16378c2ecf20Sopenharmony_ci sky2->tx_le = NULL; 16388c2ecf20Sopenharmony_ci } 16398c2ecf20Sopenharmony_ci kfree(sky2->tx_ring); 16408c2ecf20Sopenharmony_ci kfree(sky2->rx_ring); 16418c2ecf20Sopenharmony_ci 16428c2ecf20Sopenharmony_ci sky2->tx_ring = NULL; 16438c2ecf20Sopenharmony_ci sky2->rx_ring = NULL; 16448c2ecf20Sopenharmony_ci} 16458c2ecf20Sopenharmony_ci 16468c2ecf20Sopenharmony_cistatic void sky2_hw_up(struct sky2_port *sky2) 16478c2ecf20Sopenharmony_ci{ 16488c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 16498c2ecf20Sopenharmony_ci unsigned port = sky2->port; 16508c2ecf20Sopenharmony_ci u32 ramsize; 16518c2ecf20Sopenharmony_ci int cap; 16528c2ecf20Sopenharmony_ci struct net_device *otherdev = hw->dev[sky2->port^1]; 16538c2ecf20Sopenharmony_ci 16548c2ecf20Sopenharmony_ci tx_init(sky2); 16558c2ecf20Sopenharmony_ci 16568c2ecf20Sopenharmony_ci /* 16578c2ecf20Sopenharmony_ci * On dual port PCI-X card, there is an problem where status 16588c2ecf20Sopenharmony_ci * can be received out of order due to split transactions 16598c2ecf20Sopenharmony_ci */ 16608c2ecf20Sopenharmony_ci if (otherdev && netif_running(otherdev) && 16618c2ecf20Sopenharmony_ci (cap = pci_find_capability(hw->pdev, PCI_CAP_ID_PCIX))) { 16628c2ecf20Sopenharmony_ci u16 cmd; 16638c2ecf20Sopenharmony_ci 16648c2ecf20Sopenharmony_ci cmd = sky2_pci_read16(hw, cap + PCI_X_CMD); 16658c2ecf20Sopenharmony_ci cmd &= ~PCI_X_CMD_MAX_SPLIT; 16668c2ecf20Sopenharmony_ci sky2_pci_write16(hw, cap + PCI_X_CMD, cmd); 16678c2ecf20Sopenharmony_ci } 16688c2ecf20Sopenharmony_ci 16698c2ecf20Sopenharmony_ci sky2_mac_init(hw, port); 16708c2ecf20Sopenharmony_ci 16718c2ecf20Sopenharmony_ci /* Register is number of 4K blocks on internal RAM buffer. */ 16728c2ecf20Sopenharmony_ci ramsize = sky2_read8(hw, B2_E_0) * 4; 16738c2ecf20Sopenharmony_ci if (ramsize > 0) { 16748c2ecf20Sopenharmony_ci u32 rxspace; 16758c2ecf20Sopenharmony_ci 16768c2ecf20Sopenharmony_ci netdev_dbg(sky2->netdev, "ram buffer %dK\n", ramsize); 16778c2ecf20Sopenharmony_ci if (ramsize < 16) 16788c2ecf20Sopenharmony_ci rxspace = ramsize / 2; 16798c2ecf20Sopenharmony_ci else 16808c2ecf20Sopenharmony_ci rxspace = 8 + (2*(ramsize - 16))/3; 16818c2ecf20Sopenharmony_ci 16828c2ecf20Sopenharmony_ci sky2_ramset(hw, rxqaddr[port], 0, rxspace); 16838c2ecf20Sopenharmony_ci sky2_ramset(hw, txqaddr[port], rxspace, ramsize - rxspace); 16848c2ecf20Sopenharmony_ci 16858c2ecf20Sopenharmony_ci /* Make sure SyncQ is disabled */ 16868c2ecf20Sopenharmony_ci sky2_write8(hw, RB_ADDR(port == 0 ? Q_XS1 : Q_XS2, RB_CTRL), 16878c2ecf20Sopenharmony_ci RB_RST_SET); 16888c2ecf20Sopenharmony_ci } 16898c2ecf20Sopenharmony_ci 16908c2ecf20Sopenharmony_ci sky2_qset(hw, txqaddr[port]); 16918c2ecf20Sopenharmony_ci 16928c2ecf20Sopenharmony_ci /* This is copied from sk98lin 10.0.5.3; no one tells me about erratta's */ 16938c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EX && hw->chip_rev == CHIP_REV_YU_EX_B0) 16948c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(txqaddr[port], Q_TEST), F_TX_CHK_AUTO_OFF); 16958c2ecf20Sopenharmony_ci 16968c2ecf20Sopenharmony_ci /* Set almost empty threshold */ 16978c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EC_U && 16988c2ecf20Sopenharmony_ci hw->chip_rev == CHIP_REV_YU_EC_U_A0) 16998c2ecf20Sopenharmony_ci sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), ECU_TXFF_LEV); 17008c2ecf20Sopenharmony_ci 17018c2ecf20Sopenharmony_ci sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map, 17028c2ecf20Sopenharmony_ci sky2->tx_ring_size - 1); 17038c2ecf20Sopenharmony_ci 17048c2ecf20Sopenharmony_ci sky2_vlan_mode(sky2->netdev, sky2->netdev->features); 17058c2ecf20Sopenharmony_ci netdev_update_features(sky2->netdev); 17068c2ecf20Sopenharmony_ci 17078c2ecf20Sopenharmony_ci sky2_rx_start(sky2); 17088c2ecf20Sopenharmony_ci} 17098c2ecf20Sopenharmony_ci 17108c2ecf20Sopenharmony_ci/* Setup device IRQ and enable napi to process */ 17118c2ecf20Sopenharmony_cistatic int sky2_setup_irq(struct sky2_hw *hw, const char *name) 17128c2ecf20Sopenharmony_ci{ 17138c2ecf20Sopenharmony_ci struct pci_dev *pdev = hw->pdev; 17148c2ecf20Sopenharmony_ci int err; 17158c2ecf20Sopenharmony_ci 17168c2ecf20Sopenharmony_ci err = request_irq(pdev->irq, sky2_intr, 17178c2ecf20Sopenharmony_ci (hw->flags & SKY2_HW_USE_MSI) ? 0 : IRQF_SHARED, 17188c2ecf20Sopenharmony_ci name, hw); 17198c2ecf20Sopenharmony_ci if (err) 17208c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq); 17218c2ecf20Sopenharmony_ci else { 17228c2ecf20Sopenharmony_ci hw->flags |= SKY2_HW_IRQ_SETUP; 17238c2ecf20Sopenharmony_ci 17248c2ecf20Sopenharmony_ci napi_enable(&hw->napi); 17258c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, Y2_IS_BASE); 17268c2ecf20Sopenharmony_ci sky2_read32(hw, B0_IMSK); 17278c2ecf20Sopenharmony_ci } 17288c2ecf20Sopenharmony_ci 17298c2ecf20Sopenharmony_ci return err; 17308c2ecf20Sopenharmony_ci} 17318c2ecf20Sopenharmony_ci 17328c2ecf20Sopenharmony_ci 17338c2ecf20Sopenharmony_ci/* Bring up network interface. */ 17348c2ecf20Sopenharmony_cistatic int sky2_open(struct net_device *dev) 17358c2ecf20Sopenharmony_ci{ 17368c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 17378c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 17388c2ecf20Sopenharmony_ci unsigned port = sky2->port; 17398c2ecf20Sopenharmony_ci u32 imask; 17408c2ecf20Sopenharmony_ci int err; 17418c2ecf20Sopenharmony_ci 17428c2ecf20Sopenharmony_ci netif_carrier_off(dev); 17438c2ecf20Sopenharmony_ci 17448c2ecf20Sopenharmony_ci err = sky2_alloc_buffers(sky2); 17458c2ecf20Sopenharmony_ci if (err) 17468c2ecf20Sopenharmony_ci goto err_out; 17478c2ecf20Sopenharmony_ci 17488c2ecf20Sopenharmony_ci /* With single port, IRQ is setup when device is brought up */ 17498c2ecf20Sopenharmony_ci if (hw->ports == 1 && (err = sky2_setup_irq(hw, dev->name))) 17508c2ecf20Sopenharmony_ci goto err_out; 17518c2ecf20Sopenharmony_ci 17528c2ecf20Sopenharmony_ci sky2_hw_up(sky2); 17538c2ecf20Sopenharmony_ci 17548c2ecf20Sopenharmony_ci /* Enable interrupts from phy/mac for port */ 17558c2ecf20Sopenharmony_ci imask = sky2_read32(hw, B0_IMSK); 17568c2ecf20Sopenharmony_ci 17578c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_OPT || 17588c2ecf20Sopenharmony_ci hw->chip_id == CHIP_ID_YUKON_PRM || 17598c2ecf20Sopenharmony_ci hw->chip_id == CHIP_ID_YUKON_OP_2) 17608c2ecf20Sopenharmony_ci imask |= Y2_IS_PHY_QLNK; /* enable PHY Quick Link */ 17618c2ecf20Sopenharmony_ci 17628c2ecf20Sopenharmony_ci imask |= portirq_msk[port]; 17638c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, imask); 17648c2ecf20Sopenharmony_ci sky2_read32(hw, B0_IMSK); 17658c2ecf20Sopenharmony_ci 17668c2ecf20Sopenharmony_ci netif_info(sky2, ifup, dev, "enabling interface\n"); 17678c2ecf20Sopenharmony_ci 17688c2ecf20Sopenharmony_ci return 0; 17698c2ecf20Sopenharmony_ci 17708c2ecf20Sopenharmony_cierr_out: 17718c2ecf20Sopenharmony_ci sky2_free_buffers(sky2); 17728c2ecf20Sopenharmony_ci return err; 17738c2ecf20Sopenharmony_ci} 17748c2ecf20Sopenharmony_ci 17758c2ecf20Sopenharmony_ci/* Modular subtraction in ring */ 17768c2ecf20Sopenharmony_cistatic inline int tx_inuse(const struct sky2_port *sky2) 17778c2ecf20Sopenharmony_ci{ 17788c2ecf20Sopenharmony_ci return (sky2->tx_prod - sky2->tx_cons) & (sky2->tx_ring_size - 1); 17798c2ecf20Sopenharmony_ci} 17808c2ecf20Sopenharmony_ci 17818c2ecf20Sopenharmony_ci/* Number of list elements available for next tx */ 17828c2ecf20Sopenharmony_cistatic inline int tx_avail(const struct sky2_port *sky2) 17838c2ecf20Sopenharmony_ci{ 17848c2ecf20Sopenharmony_ci return sky2->tx_pending - tx_inuse(sky2); 17858c2ecf20Sopenharmony_ci} 17868c2ecf20Sopenharmony_ci 17878c2ecf20Sopenharmony_ci/* Estimate of number of transmit list elements required */ 17888c2ecf20Sopenharmony_cistatic unsigned tx_le_req(const struct sk_buff *skb) 17898c2ecf20Sopenharmony_ci{ 17908c2ecf20Sopenharmony_ci unsigned count; 17918c2ecf20Sopenharmony_ci 17928c2ecf20Sopenharmony_ci count = (skb_shinfo(skb)->nr_frags + 1) 17938c2ecf20Sopenharmony_ci * (sizeof(dma_addr_t) / sizeof(u32)); 17948c2ecf20Sopenharmony_ci 17958c2ecf20Sopenharmony_ci if (skb_is_gso(skb)) 17968c2ecf20Sopenharmony_ci ++count; 17978c2ecf20Sopenharmony_ci else if (sizeof(dma_addr_t) == sizeof(u32)) 17988c2ecf20Sopenharmony_ci ++count; /* possible vlan */ 17998c2ecf20Sopenharmony_ci 18008c2ecf20Sopenharmony_ci if (skb->ip_summed == CHECKSUM_PARTIAL) 18018c2ecf20Sopenharmony_ci ++count; 18028c2ecf20Sopenharmony_ci 18038c2ecf20Sopenharmony_ci return count; 18048c2ecf20Sopenharmony_ci} 18058c2ecf20Sopenharmony_ci 18068c2ecf20Sopenharmony_cistatic void sky2_tx_unmap(struct pci_dev *pdev, struct tx_ring_info *re) 18078c2ecf20Sopenharmony_ci{ 18088c2ecf20Sopenharmony_ci if (re->flags & TX_MAP_SINGLE) 18098c2ecf20Sopenharmony_ci dma_unmap_single(&pdev->dev, dma_unmap_addr(re, mapaddr), 18108c2ecf20Sopenharmony_ci dma_unmap_len(re, maplen), DMA_TO_DEVICE); 18118c2ecf20Sopenharmony_ci else if (re->flags & TX_MAP_PAGE) 18128c2ecf20Sopenharmony_ci dma_unmap_page(&pdev->dev, dma_unmap_addr(re, mapaddr), 18138c2ecf20Sopenharmony_ci dma_unmap_len(re, maplen), DMA_TO_DEVICE); 18148c2ecf20Sopenharmony_ci re->flags = 0; 18158c2ecf20Sopenharmony_ci} 18168c2ecf20Sopenharmony_ci 18178c2ecf20Sopenharmony_ci/* 18188c2ecf20Sopenharmony_ci * Put one packet in ring for transmit. 18198c2ecf20Sopenharmony_ci * A single packet can generate multiple list elements, and 18208c2ecf20Sopenharmony_ci * the number of ring elements will probably be less than the number 18218c2ecf20Sopenharmony_ci * of list elements used. 18228c2ecf20Sopenharmony_ci */ 18238c2ecf20Sopenharmony_cistatic netdev_tx_t sky2_xmit_frame(struct sk_buff *skb, 18248c2ecf20Sopenharmony_ci struct net_device *dev) 18258c2ecf20Sopenharmony_ci{ 18268c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 18278c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 18288c2ecf20Sopenharmony_ci struct sky2_tx_le *le = NULL; 18298c2ecf20Sopenharmony_ci struct tx_ring_info *re; 18308c2ecf20Sopenharmony_ci unsigned i, len; 18318c2ecf20Sopenharmony_ci dma_addr_t mapping; 18328c2ecf20Sopenharmony_ci u32 upper; 18338c2ecf20Sopenharmony_ci u16 slot; 18348c2ecf20Sopenharmony_ci u16 mss; 18358c2ecf20Sopenharmony_ci u8 ctrl; 18368c2ecf20Sopenharmony_ci 18378c2ecf20Sopenharmony_ci if (unlikely(tx_avail(sky2) < tx_le_req(skb))) 18388c2ecf20Sopenharmony_ci return NETDEV_TX_BUSY; 18398c2ecf20Sopenharmony_ci 18408c2ecf20Sopenharmony_ci len = skb_headlen(skb); 18418c2ecf20Sopenharmony_ci mapping = dma_map_single(&hw->pdev->dev, skb->data, len, 18428c2ecf20Sopenharmony_ci DMA_TO_DEVICE); 18438c2ecf20Sopenharmony_ci 18448c2ecf20Sopenharmony_ci if (dma_mapping_error(&hw->pdev->dev, mapping)) 18458c2ecf20Sopenharmony_ci goto mapping_error; 18468c2ecf20Sopenharmony_ci 18478c2ecf20Sopenharmony_ci slot = sky2->tx_prod; 18488c2ecf20Sopenharmony_ci netif_printk(sky2, tx_queued, KERN_DEBUG, dev, 18498c2ecf20Sopenharmony_ci "tx queued, slot %u, len %d\n", slot, skb->len); 18508c2ecf20Sopenharmony_ci 18518c2ecf20Sopenharmony_ci /* Send high bits if needed */ 18528c2ecf20Sopenharmony_ci upper = upper_32_bits(mapping); 18538c2ecf20Sopenharmony_ci if (upper != sky2->tx_last_upper) { 18548c2ecf20Sopenharmony_ci le = get_tx_le(sky2, &slot); 18558c2ecf20Sopenharmony_ci le->addr = cpu_to_le32(upper); 18568c2ecf20Sopenharmony_ci sky2->tx_last_upper = upper; 18578c2ecf20Sopenharmony_ci le->opcode = OP_ADDR64 | HW_OWNER; 18588c2ecf20Sopenharmony_ci } 18598c2ecf20Sopenharmony_ci 18608c2ecf20Sopenharmony_ci /* Check for TCP Segmentation Offload */ 18618c2ecf20Sopenharmony_ci mss = skb_shinfo(skb)->gso_size; 18628c2ecf20Sopenharmony_ci if (mss != 0) { 18638c2ecf20Sopenharmony_ci 18648c2ecf20Sopenharmony_ci if (!(hw->flags & SKY2_HW_NEW_LE)) 18658c2ecf20Sopenharmony_ci mss += ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb); 18668c2ecf20Sopenharmony_ci 18678c2ecf20Sopenharmony_ci if (mss != sky2->tx_last_mss) { 18688c2ecf20Sopenharmony_ci le = get_tx_le(sky2, &slot); 18698c2ecf20Sopenharmony_ci le->addr = cpu_to_le32(mss); 18708c2ecf20Sopenharmony_ci 18718c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_NEW_LE) 18728c2ecf20Sopenharmony_ci le->opcode = OP_MSS | HW_OWNER; 18738c2ecf20Sopenharmony_ci else 18748c2ecf20Sopenharmony_ci le->opcode = OP_LRGLEN | HW_OWNER; 18758c2ecf20Sopenharmony_ci sky2->tx_last_mss = mss; 18768c2ecf20Sopenharmony_ci } 18778c2ecf20Sopenharmony_ci } 18788c2ecf20Sopenharmony_ci 18798c2ecf20Sopenharmony_ci ctrl = 0; 18808c2ecf20Sopenharmony_ci 18818c2ecf20Sopenharmony_ci /* Add VLAN tag, can piggyback on LRGLEN or ADDR64 */ 18828c2ecf20Sopenharmony_ci if (skb_vlan_tag_present(skb)) { 18838c2ecf20Sopenharmony_ci if (!le) { 18848c2ecf20Sopenharmony_ci le = get_tx_le(sky2, &slot); 18858c2ecf20Sopenharmony_ci le->addr = 0; 18868c2ecf20Sopenharmony_ci le->opcode = OP_VLAN|HW_OWNER; 18878c2ecf20Sopenharmony_ci } else 18888c2ecf20Sopenharmony_ci le->opcode |= OP_VLAN; 18898c2ecf20Sopenharmony_ci le->length = cpu_to_be16(skb_vlan_tag_get(skb)); 18908c2ecf20Sopenharmony_ci ctrl |= INS_VLAN; 18918c2ecf20Sopenharmony_ci } 18928c2ecf20Sopenharmony_ci 18938c2ecf20Sopenharmony_ci /* Handle TCP checksum offload */ 18948c2ecf20Sopenharmony_ci if (skb->ip_summed == CHECKSUM_PARTIAL) { 18958c2ecf20Sopenharmony_ci /* On Yukon EX (some versions) encoding change. */ 18968c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_AUTO_TX_SUM) 18978c2ecf20Sopenharmony_ci ctrl |= CALSUM; /* auto checksum */ 18988c2ecf20Sopenharmony_ci else { 18998c2ecf20Sopenharmony_ci const unsigned offset = skb_transport_offset(skb); 19008c2ecf20Sopenharmony_ci u32 tcpsum; 19018c2ecf20Sopenharmony_ci 19028c2ecf20Sopenharmony_ci tcpsum = offset << 16; /* sum start */ 19038c2ecf20Sopenharmony_ci tcpsum |= offset + skb->csum_offset; /* sum write */ 19048c2ecf20Sopenharmony_ci 19058c2ecf20Sopenharmony_ci ctrl |= CALSUM | WR_SUM | INIT_SUM | LOCK_SUM; 19068c2ecf20Sopenharmony_ci if (ip_hdr(skb)->protocol == IPPROTO_UDP) 19078c2ecf20Sopenharmony_ci ctrl |= UDPTCP; 19088c2ecf20Sopenharmony_ci 19098c2ecf20Sopenharmony_ci if (tcpsum != sky2->tx_tcpsum) { 19108c2ecf20Sopenharmony_ci sky2->tx_tcpsum = tcpsum; 19118c2ecf20Sopenharmony_ci 19128c2ecf20Sopenharmony_ci le = get_tx_le(sky2, &slot); 19138c2ecf20Sopenharmony_ci le->addr = cpu_to_le32(tcpsum); 19148c2ecf20Sopenharmony_ci le->length = 0; /* initial checksum value */ 19158c2ecf20Sopenharmony_ci le->ctrl = 1; /* one packet */ 19168c2ecf20Sopenharmony_ci le->opcode = OP_TCPLISW | HW_OWNER; 19178c2ecf20Sopenharmony_ci } 19188c2ecf20Sopenharmony_ci } 19198c2ecf20Sopenharmony_ci } 19208c2ecf20Sopenharmony_ci 19218c2ecf20Sopenharmony_ci re = sky2->tx_ring + slot; 19228c2ecf20Sopenharmony_ci re->flags = TX_MAP_SINGLE; 19238c2ecf20Sopenharmony_ci dma_unmap_addr_set(re, mapaddr, mapping); 19248c2ecf20Sopenharmony_ci dma_unmap_len_set(re, maplen, len); 19258c2ecf20Sopenharmony_ci 19268c2ecf20Sopenharmony_ci le = get_tx_le(sky2, &slot); 19278c2ecf20Sopenharmony_ci le->addr = cpu_to_le32(lower_32_bits(mapping)); 19288c2ecf20Sopenharmony_ci le->length = cpu_to_le16(len); 19298c2ecf20Sopenharmony_ci le->ctrl = ctrl; 19308c2ecf20Sopenharmony_ci le->opcode = mss ? (OP_LARGESEND | HW_OWNER) : (OP_PACKET | HW_OWNER); 19318c2ecf20Sopenharmony_ci 19328c2ecf20Sopenharmony_ci 19338c2ecf20Sopenharmony_ci for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 19348c2ecf20Sopenharmony_ci const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 19358c2ecf20Sopenharmony_ci 19368c2ecf20Sopenharmony_ci mapping = skb_frag_dma_map(&hw->pdev->dev, frag, 0, 19378c2ecf20Sopenharmony_ci skb_frag_size(frag), DMA_TO_DEVICE); 19388c2ecf20Sopenharmony_ci 19398c2ecf20Sopenharmony_ci if (dma_mapping_error(&hw->pdev->dev, mapping)) 19408c2ecf20Sopenharmony_ci goto mapping_unwind; 19418c2ecf20Sopenharmony_ci 19428c2ecf20Sopenharmony_ci upper = upper_32_bits(mapping); 19438c2ecf20Sopenharmony_ci if (upper != sky2->tx_last_upper) { 19448c2ecf20Sopenharmony_ci le = get_tx_le(sky2, &slot); 19458c2ecf20Sopenharmony_ci le->addr = cpu_to_le32(upper); 19468c2ecf20Sopenharmony_ci sky2->tx_last_upper = upper; 19478c2ecf20Sopenharmony_ci le->opcode = OP_ADDR64 | HW_OWNER; 19488c2ecf20Sopenharmony_ci } 19498c2ecf20Sopenharmony_ci 19508c2ecf20Sopenharmony_ci re = sky2->tx_ring + slot; 19518c2ecf20Sopenharmony_ci re->flags = TX_MAP_PAGE; 19528c2ecf20Sopenharmony_ci dma_unmap_addr_set(re, mapaddr, mapping); 19538c2ecf20Sopenharmony_ci dma_unmap_len_set(re, maplen, skb_frag_size(frag)); 19548c2ecf20Sopenharmony_ci 19558c2ecf20Sopenharmony_ci le = get_tx_le(sky2, &slot); 19568c2ecf20Sopenharmony_ci le->addr = cpu_to_le32(lower_32_bits(mapping)); 19578c2ecf20Sopenharmony_ci le->length = cpu_to_le16(skb_frag_size(frag)); 19588c2ecf20Sopenharmony_ci le->ctrl = ctrl; 19598c2ecf20Sopenharmony_ci le->opcode = OP_BUFFER | HW_OWNER; 19608c2ecf20Sopenharmony_ci } 19618c2ecf20Sopenharmony_ci 19628c2ecf20Sopenharmony_ci re->skb = skb; 19638c2ecf20Sopenharmony_ci le->ctrl |= EOP; 19648c2ecf20Sopenharmony_ci 19658c2ecf20Sopenharmony_ci sky2->tx_prod = slot; 19668c2ecf20Sopenharmony_ci 19678c2ecf20Sopenharmony_ci if (tx_avail(sky2) <= MAX_SKB_TX_LE) 19688c2ecf20Sopenharmony_ci netif_stop_queue(dev); 19698c2ecf20Sopenharmony_ci 19708c2ecf20Sopenharmony_ci netdev_sent_queue(dev, skb->len); 19718c2ecf20Sopenharmony_ci sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod); 19728c2ecf20Sopenharmony_ci 19738c2ecf20Sopenharmony_ci return NETDEV_TX_OK; 19748c2ecf20Sopenharmony_ci 19758c2ecf20Sopenharmony_cimapping_unwind: 19768c2ecf20Sopenharmony_ci for (i = sky2->tx_prod; i != slot; i = RING_NEXT(i, sky2->tx_ring_size)) { 19778c2ecf20Sopenharmony_ci re = sky2->tx_ring + i; 19788c2ecf20Sopenharmony_ci 19798c2ecf20Sopenharmony_ci sky2_tx_unmap(hw->pdev, re); 19808c2ecf20Sopenharmony_ci } 19818c2ecf20Sopenharmony_ci 19828c2ecf20Sopenharmony_cimapping_error: 19838c2ecf20Sopenharmony_ci if (net_ratelimit()) 19848c2ecf20Sopenharmony_ci dev_warn(&hw->pdev->dev, "%s: tx mapping error\n", dev->name); 19858c2ecf20Sopenharmony_ci dev_kfree_skb_any(skb); 19868c2ecf20Sopenharmony_ci return NETDEV_TX_OK; 19878c2ecf20Sopenharmony_ci} 19888c2ecf20Sopenharmony_ci 19898c2ecf20Sopenharmony_ci/* 19908c2ecf20Sopenharmony_ci * Free ring elements from starting at tx_cons until "done" 19918c2ecf20Sopenharmony_ci * 19928c2ecf20Sopenharmony_ci * NB: 19938c2ecf20Sopenharmony_ci * 1. The hardware will tell us about partial completion of multi-part 19948c2ecf20Sopenharmony_ci * buffers so make sure not to free skb to early. 19958c2ecf20Sopenharmony_ci * 2. This may run in parallel start_xmit because the it only 19968c2ecf20Sopenharmony_ci * looks at the tail of the queue of FIFO (tx_cons), not 19978c2ecf20Sopenharmony_ci * the head (tx_prod) 19988c2ecf20Sopenharmony_ci */ 19998c2ecf20Sopenharmony_cistatic void sky2_tx_complete(struct sky2_port *sky2, u16 done) 20008c2ecf20Sopenharmony_ci{ 20018c2ecf20Sopenharmony_ci struct net_device *dev = sky2->netdev; 20028c2ecf20Sopenharmony_ci u16 idx; 20038c2ecf20Sopenharmony_ci unsigned int bytes_compl = 0, pkts_compl = 0; 20048c2ecf20Sopenharmony_ci 20058c2ecf20Sopenharmony_ci BUG_ON(done >= sky2->tx_ring_size); 20068c2ecf20Sopenharmony_ci 20078c2ecf20Sopenharmony_ci for (idx = sky2->tx_cons; idx != done; 20088c2ecf20Sopenharmony_ci idx = RING_NEXT(idx, sky2->tx_ring_size)) { 20098c2ecf20Sopenharmony_ci struct tx_ring_info *re = sky2->tx_ring + idx; 20108c2ecf20Sopenharmony_ci struct sk_buff *skb = re->skb; 20118c2ecf20Sopenharmony_ci 20128c2ecf20Sopenharmony_ci sky2_tx_unmap(sky2->hw->pdev, re); 20138c2ecf20Sopenharmony_ci 20148c2ecf20Sopenharmony_ci if (skb) { 20158c2ecf20Sopenharmony_ci netif_printk(sky2, tx_done, KERN_DEBUG, dev, 20168c2ecf20Sopenharmony_ci "tx done %u\n", idx); 20178c2ecf20Sopenharmony_ci 20188c2ecf20Sopenharmony_ci pkts_compl++; 20198c2ecf20Sopenharmony_ci bytes_compl += skb->len; 20208c2ecf20Sopenharmony_ci 20218c2ecf20Sopenharmony_ci re->skb = NULL; 20228c2ecf20Sopenharmony_ci dev_kfree_skb_any(skb); 20238c2ecf20Sopenharmony_ci 20248c2ecf20Sopenharmony_ci sky2->tx_next = RING_NEXT(idx, sky2->tx_ring_size); 20258c2ecf20Sopenharmony_ci } 20268c2ecf20Sopenharmony_ci } 20278c2ecf20Sopenharmony_ci 20288c2ecf20Sopenharmony_ci sky2->tx_cons = idx; 20298c2ecf20Sopenharmony_ci smp_mb(); 20308c2ecf20Sopenharmony_ci 20318c2ecf20Sopenharmony_ci netdev_completed_queue(dev, pkts_compl, bytes_compl); 20328c2ecf20Sopenharmony_ci 20338c2ecf20Sopenharmony_ci u64_stats_update_begin(&sky2->tx_stats.syncp); 20348c2ecf20Sopenharmony_ci sky2->tx_stats.packets += pkts_compl; 20358c2ecf20Sopenharmony_ci sky2->tx_stats.bytes += bytes_compl; 20368c2ecf20Sopenharmony_ci u64_stats_update_end(&sky2->tx_stats.syncp); 20378c2ecf20Sopenharmony_ci} 20388c2ecf20Sopenharmony_ci 20398c2ecf20Sopenharmony_cistatic void sky2_tx_reset(struct sky2_hw *hw, unsigned port) 20408c2ecf20Sopenharmony_ci{ 20418c2ecf20Sopenharmony_ci /* Disable Force Sync bit and Enable Alloc bit */ 20428c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, TXA_CTRL), 20438c2ecf20Sopenharmony_ci TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC); 20448c2ecf20Sopenharmony_ci 20458c2ecf20Sopenharmony_ci /* Stop Interval Timer and Limit Counter of Tx Arbiter */ 20468c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(port, TXA_ITI_INI), 0L); 20478c2ecf20Sopenharmony_ci sky2_write32(hw, SK_REG(port, TXA_LIM_INI), 0L); 20488c2ecf20Sopenharmony_ci 20498c2ecf20Sopenharmony_ci /* Reset the PCI FIFO of the async Tx queue */ 20508c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), 20518c2ecf20Sopenharmony_ci BMU_RST_SET | BMU_FIFO_RST); 20528c2ecf20Sopenharmony_ci 20538c2ecf20Sopenharmony_ci /* Reset the Tx prefetch units */ 20548c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_QADDR(txqaddr[port], PREF_UNIT_CTRL), 20558c2ecf20Sopenharmony_ci PREF_UNIT_RST_SET); 20568c2ecf20Sopenharmony_ci 20578c2ecf20Sopenharmony_ci sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET); 20588c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); 20598c2ecf20Sopenharmony_ci 20608c2ecf20Sopenharmony_ci sky2_read32(hw, B0_CTST); 20618c2ecf20Sopenharmony_ci} 20628c2ecf20Sopenharmony_ci 20638c2ecf20Sopenharmony_cistatic void sky2_hw_down(struct sky2_port *sky2) 20648c2ecf20Sopenharmony_ci{ 20658c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 20668c2ecf20Sopenharmony_ci unsigned port = sky2->port; 20678c2ecf20Sopenharmony_ci u16 ctrl; 20688c2ecf20Sopenharmony_ci 20698c2ecf20Sopenharmony_ci /* Force flow control off */ 20708c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); 20718c2ecf20Sopenharmony_ci 20728c2ecf20Sopenharmony_ci /* Stop transmitter */ 20738c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_STOP); 20748c2ecf20Sopenharmony_ci sky2_read32(hw, Q_ADDR(txqaddr[port], Q_CSR)); 20758c2ecf20Sopenharmony_ci 20768c2ecf20Sopenharmony_ci sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), 20778c2ecf20Sopenharmony_ci RB_RST_SET | RB_DIS_OP_MD); 20788c2ecf20Sopenharmony_ci 20798c2ecf20Sopenharmony_ci ctrl = gma_read16(hw, port, GM_GP_CTRL); 20808c2ecf20Sopenharmony_ci ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA); 20818c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, ctrl); 20828c2ecf20Sopenharmony_ci 20838c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); 20848c2ecf20Sopenharmony_ci 20858c2ecf20Sopenharmony_ci /* Workaround shared GMAC reset */ 20868c2ecf20Sopenharmony_ci if (!(hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 && 20878c2ecf20Sopenharmony_ci port == 0 && hw->dev[1] && netif_running(hw->dev[1]))) 20888c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET); 20898c2ecf20Sopenharmony_ci 20908c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); 20918c2ecf20Sopenharmony_ci 20928c2ecf20Sopenharmony_ci /* Force any delayed status interrupt and NAPI */ 20938c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_LEV_TIMER_CNT, 0); 20948c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_TX_TIMER_CNT, 0); 20958c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_ISR_TIMER_CNT, 0); 20968c2ecf20Sopenharmony_ci sky2_read8(hw, STAT_ISR_TIMER_CTRL); 20978c2ecf20Sopenharmony_ci 20988c2ecf20Sopenharmony_ci sky2_rx_stop(sky2); 20998c2ecf20Sopenharmony_ci 21008c2ecf20Sopenharmony_ci spin_lock_bh(&sky2->phy_lock); 21018c2ecf20Sopenharmony_ci sky2_phy_power_down(hw, port); 21028c2ecf20Sopenharmony_ci spin_unlock_bh(&sky2->phy_lock); 21038c2ecf20Sopenharmony_ci 21048c2ecf20Sopenharmony_ci sky2_tx_reset(hw, port); 21058c2ecf20Sopenharmony_ci 21068c2ecf20Sopenharmony_ci /* Free any pending frames stuck in HW queue */ 21078c2ecf20Sopenharmony_ci sky2_tx_complete(sky2, sky2->tx_prod); 21088c2ecf20Sopenharmony_ci} 21098c2ecf20Sopenharmony_ci 21108c2ecf20Sopenharmony_ci/* Network shutdown */ 21118c2ecf20Sopenharmony_cistatic int sky2_close(struct net_device *dev) 21128c2ecf20Sopenharmony_ci{ 21138c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 21148c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 21158c2ecf20Sopenharmony_ci 21168c2ecf20Sopenharmony_ci /* Never really got started! */ 21178c2ecf20Sopenharmony_ci if (!sky2->tx_le) 21188c2ecf20Sopenharmony_ci return 0; 21198c2ecf20Sopenharmony_ci 21208c2ecf20Sopenharmony_ci netif_info(sky2, ifdown, dev, "disabling interface\n"); 21218c2ecf20Sopenharmony_ci 21228c2ecf20Sopenharmony_ci if (hw->ports == 1) { 21238c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, 0); 21248c2ecf20Sopenharmony_ci sky2_read32(hw, B0_IMSK); 21258c2ecf20Sopenharmony_ci 21268c2ecf20Sopenharmony_ci napi_disable(&hw->napi); 21278c2ecf20Sopenharmony_ci free_irq(hw->pdev->irq, hw); 21288c2ecf20Sopenharmony_ci hw->flags &= ~SKY2_HW_IRQ_SETUP; 21298c2ecf20Sopenharmony_ci } else { 21308c2ecf20Sopenharmony_ci u32 imask; 21318c2ecf20Sopenharmony_ci 21328c2ecf20Sopenharmony_ci /* Disable port IRQ */ 21338c2ecf20Sopenharmony_ci imask = sky2_read32(hw, B0_IMSK); 21348c2ecf20Sopenharmony_ci imask &= ~portirq_msk[sky2->port]; 21358c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, imask); 21368c2ecf20Sopenharmony_ci sky2_read32(hw, B0_IMSK); 21378c2ecf20Sopenharmony_ci 21388c2ecf20Sopenharmony_ci synchronize_irq(hw->pdev->irq); 21398c2ecf20Sopenharmony_ci napi_synchronize(&hw->napi); 21408c2ecf20Sopenharmony_ci } 21418c2ecf20Sopenharmony_ci 21428c2ecf20Sopenharmony_ci sky2_hw_down(sky2); 21438c2ecf20Sopenharmony_ci 21448c2ecf20Sopenharmony_ci sky2_free_buffers(sky2); 21458c2ecf20Sopenharmony_ci 21468c2ecf20Sopenharmony_ci return 0; 21478c2ecf20Sopenharmony_ci} 21488c2ecf20Sopenharmony_ci 21498c2ecf20Sopenharmony_cistatic u16 sky2_phy_speed(const struct sky2_hw *hw, u16 aux) 21508c2ecf20Sopenharmony_ci{ 21518c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_FIBRE_PHY) 21528c2ecf20Sopenharmony_ci return SPEED_1000; 21538c2ecf20Sopenharmony_ci 21548c2ecf20Sopenharmony_ci if (!(hw->flags & SKY2_HW_GIGABIT)) { 21558c2ecf20Sopenharmony_ci if (aux & PHY_M_PS_SPEED_100) 21568c2ecf20Sopenharmony_ci return SPEED_100; 21578c2ecf20Sopenharmony_ci else 21588c2ecf20Sopenharmony_ci return SPEED_10; 21598c2ecf20Sopenharmony_ci } 21608c2ecf20Sopenharmony_ci 21618c2ecf20Sopenharmony_ci switch (aux & PHY_M_PS_SPEED_MSK) { 21628c2ecf20Sopenharmony_ci case PHY_M_PS_SPEED_1000: 21638c2ecf20Sopenharmony_ci return SPEED_1000; 21648c2ecf20Sopenharmony_ci case PHY_M_PS_SPEED_100: 21658c2ecf20Sopenharmony_ci return SPEED_100; 21668c2ecf20Sopenharmony_ci default: 21678c2ecf20Sopenharmony_ci return SPEED_10; 21688c2ecf20Sopenharmony_ci } 21698c2ecf20Sopenharmony_ci} 21708c2ecf20Sopenharmony_ci 21718c2ecf20Sopenharmony_cistatic void sky2_link_up(struct sky2_port *sky2) 21728c2ecf20Sopenharmony_ci{ 21738c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 21748c2ecf20Sopenharmony_ci unsigned port = sky2->port; 21758c2ecf20Sopenharmony_ci static const char *fc_name[] = { 21768c2ecf20Sopenharmony_ci [FC_NONE] = "none", 21778c2ecf20Sopenharmony_ci [FC_TX] = "tx", 21788c2ecf20Sopenharmony_ci [FC_RX] = "rx", 21798c2ecf20Sopenharmony_ci [FC_BOTH] = "both", 21808c2ecf20Sopenharmony_ci }; 21818c2ecf20Sopenharmony_ci 21828c2ecf20Sopenharmony_ci sky2_set_ipg(sky2); 21838c2ecf20Sopenharmony_ci 21848c2ecf20Sopenharmony_ci sky2_enable_rx_tx(sky2); 21858c2ecf20Sopenharmony_ci 21868c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); 21878c2ecf20Sopenharmony_ci 21888c2ecf20Sopenharmony_ci netif_carrier_on(sky2->netdev); 21898c2ecf20Sopenharmony_ci 21908c2ecf20Sopenharmony_ci mod_timer(&hw->watchdog_timer, jiffies + 1); 21918c2ecf20Sopenharmony_ci 21928c2ecf20Sopenharmony_ci /* Turn on link LED */ 21938c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, LNK_LED_REG), 21948c2ecf20Sopenharmony_ci LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF); 21958c2ecf20Sopenharmony_ci 21968c2ecf20Sopenharmony_ci netif_info(sky2, link, sky2->netdev, 21978c2ecf20Sopenharmony_ci "Link is up at %d Mbps, %s duplex, flow control %s\n", 21988c2ecf20Sopenharmony_ci sky2->speed, 21998c2ecf20Sopenharmony_ci sky2->duplex == DUPLEX_FULL ? "full" : "half", 22008c2ecf20Sopenharmony_ci fc_name[sky2->flow_status]); 22018c2ecf20Sopenharmony_ci} 22028c2ecf20Sopenharmony_ci 22038c2ecf20Sopenharmony_cistatic void sky2_link_down(struct sky2_port *sky2) 22048c2ecf20Sopenharmony_ci{ 22058c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 22068c2ecf20Sopenharmony_ci unsigned port = sky2->port; 22078c2ecf20Sopenharmony_ci u16 reg; 22088c2ecf20Sopenharmony_ci 22098c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0); 22108c2ecf20Sopenharmony_ci 22118c2ecf20Sopenharmony_ci reg = gma_read16(hw, port, GM_GP_CTRL); 22128c2ecf20Sopenharmony_ci reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA); 22138c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, reg); 22148c2ecf20Sopenharmony_ci 22158c2ecf20Sopenharmony_ci netif_carrier_off(sky2->netdev); 22168c2ecf20Sopenharmony_ci 22178c2ecf20Sopenharmony_ci /* Turn off link LED */ 22188c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF); 22198c2ecf20Sopenharmony_ci 22208c2ecf20Sopenharmony_ci netif_info(sky2, link, sky2->netdev, "Link is down\n"); 22218c2ecf20Sopenharmony_ci 22228c2ecf20Sopenharmony_ci sky2_phy_init(hw, port); 22238c2ecf20Sopenharmony_ci} 22248c2ecf20Sopenharmony_ci 22258c2ecf20Sopenharmony_cistatic enum flow_control sky2_flow(int rx, int tx) 22268c2ecf20Sopenharmony_ci{ 22278c2ecf20Sopenharmony_ci if (rx) 22288c2ecf20Sopenharmony_ci return tx ? FC_BOTH : FC_RX; 22298c2ecf20Sopenharmony_ci else 22308c2ecf20Sopenharmony_ci return tx ? FC_TX : FC_NONE; 22318c2ecf20Sopenharmony_ci} 22328c2ecf20Sopenharmony_ci 22338c2ecf20Sopenharmony_cistatic int sky2_autoneg_done(struct sky2_port *sky2, u16 aux) 22348c2ecf20Sopenharmony_ci{ 22358c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 22368c2ecf20Sopenharmony_ci unsigned port = sky2->port; 22378c2ecf20Sopenharmony_ci u16 advert, lpa; 22388c2ecf20Sopenharmony_ci 22398c2ecf20Sopenharmony_ci advert = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV); 22408c2ecf20Sopenharmony_ci lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP); 22418c2ecf20Sopenharmony_ci if (lpa & PHY_M_AN_RF) { 22428c2ecf20Sopenharmony_ci netdev_err(sky2->netdev, "remote fault\n"); 22438c2ecf20Sopenharmony_ci return -1; 22448c2ecf20Sopenharmony_ci } 22458c2ecf20Sopenharmony_ci 22468c2ecf20Sopenharmony_ci if (!(aux & PHY_M_PS_SPDUP_RES)) { 22478c2ecf20Sopenharmony_ci netdev_err(sky2->netdev, "speed/duplex mismatch\n"); 22488c2ecf20Sopenharmony_ci return -1; 22498c2ecf20Sopenharmony_ci } 22508c2ecf20Sopenharmony_ci 22518c2ecf20Sopenharmony_ci sky2->speed = sky2_phy_speed(hw, aux); 22528c2ecf20Sopenharmony_ci sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; 22538c2ecf20Sopenharmony_ci 22548c2ecf20Sopenharmony_ci /* Since the pause result bits seem to in different positions on 22558c2ecf20Sopenharmony_ci * different chips. look at registers. 22568c2ecf20Sopenharmony_ci */ 22578c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_FIBRE_PHY) { 22588c2ecf20Sopenharmony_ci /* Shift for bits in fiber PHY */ 22598c2ecf20Sopenharmony_ci advert &= ~(ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM); 22608c2ecf20Sopenharmony_ci lpa &= ~(LPA_PAUSE_CAP|LPA_PAUSE_ASYM); 22618c2ecf20Sopenharmony_ci 22628c2ecf20Sopenharmony_ci if (advert & ADVERTISE_1000XPAUSE) 22638c2ecf20Sopenharmony_ci advert |= ADVERTISE_PAUSE_CAP; 22648c2ecf20Sopenharmony_ci if (advert & ADVERTISE_1000XPSE_ASYM) 22658c2ecf20Sopenharmony_ci advert |= ADVERTISE_PAUSE_ASYM; 22668c2ecf20Sopenharmony_ci if (lpa & LPA_1000XPAUSE) 22678c2ecf20Sopenharmony_ci lpa |= LPA_PAUSE_CAP; 22688c2ecf20Sopenharmony_ci if (lpa & LPA_1000XPAUSE_ASYM) 22698c2ecf20Sopenharmony_ci lpa |= LPA_PAUSE_ASYM; 22708c2ecf20Sopenharmony_ci } 22718c2ecf20Sopenharmony_ci 22728c2ecf20Sopenharmony_ci sky2->flow_status = FC_NONE; 22738c2ecf20Sopenharmony_ci if (advert & ADVERTISE_PAUSE_CAP) { 22748c2ecf20Sopenharmony_ci if (lpa & LPA_PAUSE_CAP) 22758c2ecf20Sopenharmony_ci sky2->flow_status = FC_BOTH; 22768c2ecf20Sopenharmony_ci else if (advert & ADVERTISE_PAUSE_ASYM) 22778c2ecf20Sopenharmony_ci sky2->flow_status = FC_RX; 22788c2ecf20Sopenharmony_ci } else if (advert & ADVERTISE_PAUSE_ASYM) { 22798c2ecf20Sopenharmony_ci if ((lpa & LPA_PAUSE_CAP) && (lpa & LPA_PAUSE_ASYM)) 22808c2ecf20Sopenharmony_ci sky2->flow_status = FC_TX; 22818c2ecf20Sopenharmony_ci } 22828c2ecf20Sopenharmony_ci 22838c2ecf20Sopenharmony_ci if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000 && 22848c2ecf20Sopenharmony_ci !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX)) 22858c2ecf20Sopenharmony_ci sky2->flow_status = FC_NONE; 22868c2ecf20Sopenharmony_ci 22878c2ecf20Sopenharmony_ci if (sky2->flow_status & FC_TX) 22888c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); 22898c2ecf20Sopenharmony_ci else 22908c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); 22918c2ecf20Sopenharmony_ci 22928c2ecf20Sopenharmony_ci return 0; 22938c2ecf20Sopenharmony_ci} 22948c2ecf20Sopenharmony_ci 22958c2ecf20Sopenharmony_ci/* Interrupt from PHY */ 22968c2ecf20Sopenharmony_cistatic void sky2_phy_intr(struct sky2_hw *hw, unsigned port) 22978c2ecf20Sopenharmony_ci{ 22988c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 22998c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 23008c2ecf20Sopenharmony_ci u16 istatus, phystat; 23018c2ecf20Sopenharmony_ci 23028c2ecf20Sopenharmony_ci if (!netif_running(dev)) 23038c2ecf20Sopenharmony_ci return; 23048c2ecf20Sopenharmony_ci 23058c2ecf20Sopenharmony_ci spin_lock(&sky2->phy_lock); 23068c2ecf20Sopenharmony_ci istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT); 23078c2ecf20Sopenharmony_ci phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT); 23088c2ecf20Sopenharmony_ci 23098c2ecf20Sopenharmony_ci netif_info(sky2, intr, sky2->netdev, "phy interrupt status 0x%x 0x%x\n", 23108c2ecf20Sopenharmony_ci istatus, phystat); 23118c2ecf20Sopenharmony_ci 23128c2ecf20Sopenharmony_ci if (istatus & PHY_M_IS_AN_COMPL) { 23138c2ecf20Sopenharmony_ci if (sky2_autoneg_done(sky2, phystat) == 0 && 23148c2ecf20Sopenharmony_ci !netif_carrier_ok(dev)) 23158c2ecf20Sopenharmony_ci sky2_link_up(sky2); 23168c2ecf20Sopenharmony_ci goto out; 23178c2ecf20Sopenharmony_ci } 23188c2ecf20Sopenharmony_ci 23198c2ecf20Sopenharmony_ci if (istatus & PHY_M_IS_LSP_CHANGE) 23208c2ecf20Sopenharmony_ci sky2->speed = sky2_phy_speed(hw, phystat); 23218c2ecf20Sopenharmony_ci 23228c2ecf20Sopenharmony_ci if (istatus & PHY_M_IS_DUP_CHANGE) 23238c2ecf20Sopenharmony_ci sky2->duplex = 23248c2ecf20Sopenharmony_ci (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; 23258c2ecf20Sopenharmony_ci 23268c2ecf20Sopenharmony_ci if (istatus & PHY_M_IS_LST_CHANGE) { 23278c2ecf20Sopenharmony_ci if (phystat & PHY_M_PS_LINK_UP) 23288c2ecf20Sopenharmony_ci sky2_link_up(sky2); 23298c2ecf20Sopenharmony_ci else 23308c2ecf20Sopenharmony_ci sky2_link_down(sky2); 23318c2ecf20Sopenharmony_ci } 23328c2ecf20Sopenharmony_ciout: 23338c2ecf20Sopenharmony_ci spin_unlock(&sky2->phy_lock); 23348c2ecf20Sopenharmony_ci} 23358c2ecf20Sopenharmony_ci 23368c2ecf20Sopenharmony_ci/* Special quick link interrupt (Yukon-2 Optima only) */ 23378c2ecf20Sopenharmony_cistatic void sky2_qlink_intr(struct sky2_hw *hw) 23388c2ecf20Sopenharmony_ci{ 23398c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(hw->dev[0]); 23408c2ecf20Sopenharmony_ci u32 imask; 23418c2ecf20Sopenharmony_ci u16 phy; 23428c2ecf20Sopenharmony_ci 23438c2ecf20Sopenharmony_ci /* disable irq */ 23448c2ecf20Sopenharmony_ci imask = sky2_read32(hw, B0_IMSK); 23458c2ecf20Sopenharmony_ci imask &= ~Y2_IS_PHY_QLNK; 23468c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, imask); 23478c2ecf20Sopenharmony_ci 23488c2ecf20Sopenharmony_ci /* reset PHY Link Detect */ 23498c2ecf20Sopenharmony_ci phy = sky2_pci_read16(hw, PSM_CONFIG_REG4); 23508c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 23518c2ecf20Sopenharmony_ci sky2_pci_write16(hw, PSM_CONFIG_REG4, phy | 1); 23528c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 23538c2ecf20Sopenharmony_ci 23548c2ecf20Sopenharmony_ci sky2_link_up(sky2); 23558c2ecf20Sopenharmony_ci} 23568c2ecf20Sopenharmony_ci 23578c2ecf20Sopenharmony_ci/* Transmit timeout is only called if we are running, carrier is up 23588c2ecf20Sopenharmony_ci * and tx queue is full (stopped). 23598c2ecf20Sopenharmony_ci */ 23608c2ecf20Sopenharmony_cistatic void sky2_tx_timeout(struct net_device *dev, unsigned int txqueue) 23618c2ecf20Sopenharmony_ci{ 23628c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 23638c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 23648c2ecf20Sopenharmony_ci 23658c2ecf20Sopenharmony_ci netif_err(sky2, timer, dev, "tx timeout\n"); 23668c2ecf20Sopenharmony_ci 23678c2ecf20Sopenharmony_ci netdev_printk(KERN_DEBUG, dev, "transmit ring %u .. %u report=%u done=%u\n", 23688c2ecf20Sopenharmony_ci sky2->tx_cons, sky2->tx_prod, 23698c2ecf20Sopenharmony_ci sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX), 23708c2ecf20Sopenharmony_ci sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE))); 23718c2ecf20Sopenharmony_ci 23728c2ecf20Sopenharmony_ci /* can't restart safely under softirq */ 23738c2ecf20Sopenharmony_ci schedule_work(&hw->restart_work); 23748c2ecf20Sopenharmony_ci} 23758c2ecf20Sopenharmony_ci 23768c2ecf20Sopenharmony_cistatic int sky2_change_mtu(struct net_device *dev, int new_mtu) 23778c2ecf20Sopenharmony_ci{ 23788c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 23798c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 23808c2ecf20Sopenharmony_ci unsigned port = sky2->port; 23818c2ecf20Sopenharmony_ci int err; 23828c2ecf20Sopenharmony_ci u16 ctl, mode; 23838c2ecf20Sopenharmony_ci u32 imask; 23848c2ecf20Sopenharmony_ci 23858c2ecf20Sopenharmony_ci if (!netif_running(dev)) { 23868c2ecf20Sopenharmony_ci dev->mtu = new_mtu; 23878c2ecf20Sopenharmony_ci netdev_update_features(dev); 23888c2ecf20Sopenharmony_ci return 0; 23898c2ecf20Sopenharmony_ci } 23908c2ecf20Sopenharmony_ci 23918c2ecf20Sopenharmony_ci imask = sky2_read32(hw, B0_IMSK); 23928c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, 0); 23938c2ecf20Sopenharmony_ci sky2_read32(hw, B0_IMSK); 23948c2ecf20Sopenharmony_ci 23958c2ecf20Sopenharmony_ci netif_trans_update(dev); /* prevent tx timeout */ 23968c2ecf20Sopenharmony_ci napi_disable(&hw->napi); 23978c2ecf20Sopenharmony_ci netif_tx_disable(dev); 23988c2ecf20Sopenharmony_ci 23998c2ecf20Sopenharmony_ci synchronize_irq(hw->pdev->irq); 24008c2ecf20Sopenharmony_ci 24018c2ecf20Sopenharmony_ci if (!(hw->flags & SKY2_HW_RAM_BUFFER)) 24028c2ecf20Sopenharmony_ci sky2_set_tx_stfwd(hw, port); 24038c2ecf20Sopenharmony_ci 24048c2ecf20Sopenharmony_ci ctl = gma_read16(hw, port, GM_GP_CTRL); 24058c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA); 24068c2ecf20Sopenharmony_ci sky2_rx_stop(sky2); 24078c2ecf20Sopenharmony_ci sky2_rx_clean(sky2); 24088c2ecf20Sopenharmony_ci 24098c2ecf20Sopenharmony_ci dev->mtu = new_mtu; 24108c2ecf20Sopenharmony_ci netdev_update_features(dev); 24118c2ecf20Sopenharmony_ci 24128c2ecf20Sopenharmony_ci mode = DATA_BLIND_VAL(DATA_BLIND_DEF) | GM_SMOD_VLAN_ENA; 24138c2ecf20Sopenharmony_ci if (sky2->speed > SPEED_100) 24148c2ecf20Sopenharmony_ci mode |= IPG_DATA_VAL(IPG_DATA_DEF_1000); 24158c2ecf20Sopenharmony_ci else 24168c2ecf20Sopenharmony_ci mode |= IPG_DATA_VAL(IPG_DATA_DEF_10_100); 24178c2ecf20Sopenharmony_ci 24188c2ecf20Sopenharmony_ci if (dev->mtu > ETH_DATA_LEN) 24198c2ecf20Sopenharmony_ci mode |= GM_SMOD_JUMBO_ENA; 24208c2ecf20Sopenharmony_ci 24218c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_SERIAL_MODE, mode); 24228c2ecf20Sopenharmony_ci 24238c2ecf20Sopenharmony_ci sky2_write8(hw, RB_ADDR(rxqaddr[port], RB_CTRL), RB_ENA_OP_MD); 24248c2ecf20Sopenharmony_ci 24258c2ecf20Sopenharmony_ci err = sky2_alloc_rx_skbs(sky2); 24268c2ecf20Sopenharmony_ci if (!err) 24278c2ecf20Sopenharmony_ci sky2_rx_start(sky2); 24288c2ecf20Sopenharmony_ci else 24298c2ecf20Sopenharmony_ci sky2_rx_clean(sky2); 24308c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, imask); 24318c2ecf20Sopenharmony_ci 24328c2ecf20Sopenharmony_ci sky2_read32(hw, B0_Y2_SP_LISR); 24338c2ecf20Sopenharmony_ci napi_enable(&hw->napi); 24348c2ecf20Sopenharmony_ci 24358c2ecf20Sopenharmony_ci if (err) 24368c2ecf20Sopenharmony_ci dev_close(dev); 24378c2ecf20Sopenharmony_ci else { 24388c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_GP_CTRL, ctl); 24398c2ecf20Sopenharmony_ci 24408c2ecf20Sopenharmony_ci netif_wake_queue(dev); 24418c2ecf20Sopenharmony_ci } 24428c2ecf20Sopenharmony_ci 24438c2ecf20Sopenharmony_ci return err; 24448c2ecf20Sopenharmony_ci} 24458c2ecf20Sopenharmony_ci 24468c2ecf20Sopenharmony_cistatic inline bool needs_copy(const struct rx_ring_info *re, 24478c2ecf20Sopenharmony_ci unsigned length) 24488c2ecf20Sopenharmony_ci{ 24498c2ecf20Sopenharmony_ci#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 24508c2ecf20Sopenharmony_ci /* Some architectures need the IP header to be aligned */ 24518c2ecf20Sopenharmony_ci if (!IS_ALIGNED(re->data_addr + ETH_HLEN, sizeof(u32))) 24528c2ecf20Sopenharmony_ci return true; 24538c2ecf20Sopenharmony_ci#endif 24548c2ecf20Sopenharmony_ci return length < copybreak; 24558c2ecf20Sopenharmony_ci} 24568c2ecf20Sopenharmony_ci 24578c2ecf20Sopenharmony_ci/* For small just reuse existing skb for next receive */ 24588c2ecf20Sopenharmony_cistatic struct sk_buff *receive_copy(struct sky2_port *sky2, 24598c2ecf20Sopenharmony_ci const struct rx_ring_info *re, 24608c2ecf20Sopenharmony_ci unsigned length) 24618c2ecf20Sopenharmony_ci{ 24628c2ecf20Sopenharmony_ci struct sk_buff *skb; 24638c2ecf20Sopenharmony_ci 24648c2ecf20Sopenharmony_ci skb = netdev_alloc_skb_ip_align(sky2->netdev, length); 24658c2ecf20Sopenharmony_ci if (likely(skb)) { 24668c2ecf20Sopenharmony_ci dma_sync_single_for_cpu(&sky2->hw->pdev->dev, re->data_addr, 24678c2ecf20Sopenharmony_ci length, DMA_FROM_DEVICE); 24688c2ecf20Sopenharmony_ci skb_copy_from_linear_data(re->skb, skb->data, length); 24698c2ecf20Sopenharmony_ci skb->ip_summed = re->skb->ip_summed; 24708c2ecf20Sopenharmony_ci skb->csum = re->skb->csum; 24718c2ecf20Sopenharmony_ci skb_copy_hash(skb, re->skb); 24728c2ecf20Sopenharmony_ci __vlan_hwaccel_copy_tag(skb, re->skb); 24738c2ecf20Sopenharmony_ci 24748c2ecf20Sopenharmony_ci dma_sync_single_for_device(&sky2->hw->pdev->dev, 24758c2ecf20Sopenharmony_ci re->data_addr, length, 24768c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 24778c2ecf20Sopenharmony_ci __vlan_hwaccel_clear_tag(re->skb); 24788c2ecf20Sopenharmony_ci skb_clear_hash(re->skb); 24798c2ecf20Sopenharmony_ci re->skb->ip_summed = CHECKSUM_NONE; 24808c2ecf20Sopenharmony_ci skb_put(skb, length); 24818c2ecf20Sopenharmony_ci } 24828c2ecf20Sopenharmony_ci return skb; 24838c2ecf20Sopenharmony_ci} 24848c2ecf20Sopenharmony_ci 24858c2ecf20Sopenharmony_ci/* Adjust length of skb with fragments to match received data */ 24868c2ecf20Sopenharmony_cistatic void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space, 24878c2ecf20Sopenharmony_ci unsigned int length) 24888c2ecf20Sopenharmony_ci{ 24898c2ecf20Sopenharmony_ci int i, num_frags; 24908c2ecf20Sopenharmony_ci unsigned int size; 24918c2ecf20Sopenharmony_ci 24928c2ecf20Sopenharmony_ci /* put header into skb */ 24938c2ecf20Sopenharmony_ci size = min(length, hdr_space); 24948c2ecf20Sopenharmony_ci skb->tail += size; 24958c2ecf20Sopenharmony_ci skb->len += size; 24968c2ecf20Sopenharmony_ci length -= size; 24978c2ecf20Sopenharmony_ci 24988c2ecf20Sopenharmony_ci num_frags = skb_shinfo(skb)->nr_frags; 24998c2ecf20Sopenharmony_ci for (i = 0; i < num_frags; i++) { 25008c2ecf20Sopenharmony_ci skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 25018c2ecf20Sopenharmony_ci 25028c2ecf20Sopenharmony_ci if (length == 0) { 25038c2ecf20Sopenharmony_ci /* don't need this page */ 25048c2ecf20Sopenharmony_ci __skb_frag_unref(frag); 25058c2ecf20Sopenharmony_ci --skb_shinfo(skb)->nr_frags; 25068c2ecf20Sopenharmony_ci } else { 25078c2ecf20Sopenharmony_ci size = min(length, (unsigned) PAGE_SIZE); 25088c2ecf20Sopenharmony_ci 25098c2ecf20Sopenharmony_ci skb_frag_size_set(frag, size); 25108c2ecf20Sopenharmony_ci skb->data_len += size; 25118c2ecf20Sopenharmony_ci skb->truesize += PAGE_SIZE; 25128c2ecf20Sopenharmony_ci skb->len += size; 25138c2ecf20Sopenharmony_ci length -= size; 25148c2ecf20Sopenharmony_ci } 25158c2ecf20Sopenharmony_ci } 25168c2ecf20Sopenharmony_ci} 25178c2ecf20Sopenharmony_ci 25188c2ecf20Sopenharmony_ci/* Normal packet - take skb from ring element and put in a new one */ 25198c2ecf20Sopenharmony_cistatic struct sk_buff *receive_new(struct sky2_port *sky2, 25208c2ecf20Sopenharmony_ci struct rx_ring_info *re, 25218c2ecf20Sopenharmony_ci unsigned int length) 25228c2ecf20Sopenharmony_ci{ 25238c2ecf20Sopenharmony_ci struct sk_buff *skb; 25248c2ecf20Sopenharmony_ci struct rx_ring_info nre; 25258c2ecf20Sopenharmony_ci unsigned hdr_space = sky2->rx_data_size; 25268c2ecf20Sopenharmony_ci 25278c2ecf20Sopenharmony_ci nre.skb = sky2_rx_alloc(sky2, GFP_ATOMIC); 25288c2ecf20Sopenharmony_ci if (unlikely(!nre.skb)) 25298c2ecf20Sopenharmony_ci goto nobuf; 25308c2ecf20Sopenharmony_ci 25318c2ecf20Sopenharmony_ci if (sky2_rx_map_skb(sky2->hw->pdev, &nre, hdr_space)) 25328c2ecf20Sopenharmony_ci goto nomap; 25338c2ecf20Sopenharmony_ci 25348c2ecf20Sopenharmony_ci skb = re->skb; 25358c2ecf20Sopenharmony_ci sky2_rx_unmap_skb(sky2->hw->pdev, re); 25368c2ecf20Sopenharmony_ci prefetch(skb->data); 25378c2ecf20Sopenharmony_ci *re = nre; 25388c2ecf20Sopenharmony_ci 25398c2ecf20Sopenharmony_ci if (skb_shinfo(skb)->nr_frags) 25408c2ecf20Sopenharmony_ci skb_put_frags(skb, hdr_space, length); 25418c2ecf20Sopenharmony_ci else 25428c2ecf20Sopenharmony_ci skb_put(skb, length); 25438c2ecf20Sopenharmony_ci return skb; 25448c2ecf20Sopenharmony_ci 25458c2ecf20Sopenharmony_cinomap: 25468c2ecf20Sopenharmony_ci dev_kfree_skb(nre.skb); 25478c2ecf20Sopenharmony_cinobuf: 25488c2ecf20Sopenharmony_ci return NULL; 25498c2ecf20Sopenharmony_ci} 25508c2ecf20Sopenharmony_ci 25518c2ecf20Sopenharmony_ci/* 25528c2ecf20Sopenharmony_ci * Receive one packet. 25538c2ecf20Sopenharmony_ci * For larger packets, get new buffer. 25548c2ecf20Sopenharmony_ci */ 25558c2ecf20Sopenharmony_cistatic struct sk_buff *sky2_receive(struct net_device *dev, 25568c2ecf20Sopenharmony_ci u16 length, u32 status) 25578c2ecf20Sopenharmony_ci{ 25588c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 25598c2ecf20Sopenharmony_ci struct rx_ring_info *re = sky2->rx_ring + sky2->rx_next; 25608c2ecf20Sopenharmony_ci struct sk_buff *skb = NULL; 25618c2ecf20Sopenharmony_ci u16 count = (status & GMR_FS_LEN) >> 16; 25628c2ecf20Sopenharmony_ci 25638c2ecf20Sopenharmony_ci netif_printk(sky2, rx_status, KERN_DEBUG, dev, 25648c2ecf20Sopenharmony_ci "rx slot %u status 0x%x len %d\n", 25658c2ecf20Sopenharmony_ci sky2->rx_next, status, length); 25668c2ecf20Sopenharmony_ci 25678c2ecf20Sopenharmony_ci sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending; 25688c2ecf20Sopenharmony_ci prefetch(sky2->rx_ring + sky2->rx_next); 25698c2ecf20Sopenharmony_ci 25708c2ecf20Sopenharmony_ci if (skb_vlan_tag_present(re->skb)) 25718c2ecf20Sopenharmony_ci count -= VLAN_HLEN; /* Account for vlan tag */ 25728c2ecf20Sopenharmony_ci 25738c2ecf20Sopenharmony_ci /* This chip has hardware problems that generates bogus status. 25748c2ecf20Sopenharmony_ci * So do only marginal checking and expect higher level protocols 25758c2ecf20Sopenharmony_ci * to handle crap frames. 25768c2ecf20Sopenharmony_ci */ 25778c2ecf20Sopenharmony_ci if (sky2->hw->chip_id == CHIP_ID_YUKON_FE_P && 25788c2ecf20Sopenharmony_ci sky2->hw->chip_rev == CHIP_REV_YU_FE2_A0 && 25798c2ecf20Sopenharmony_ci length != count) 25808c2ecf20Sopenharmony_ci goto okay; 25818c2ecf20Sopenharmony_ci 25828c2ecf20Sopenharmony_ci if (status & GMR_FS_ANY_ERR) 25838c2ecf20Sopenharmony_ci goto error; 25848c2ecf20Sopenharmony_ci 25858c2ecf20Sopenharmony_ci if (!(status & GMR_FS_RX_OK)) 25868c2ecf20Sopenharmony_ci goto resubmit; 25878c2ecf20Sopenharmony_ci 25888c2ecf20Sopenharmony_ci /* if length reported by DMA does not match PHY, packet was truncated */ 25898c2ecf20Sopenharmony_ci if (length != count) 25908c2ecf20Sopenharmony_ci goto error; 25918c2ecf20Sopenharmony_ci 25928c2ecf20Sopenharmony_ciokay: 25938c2ecf20Sopenharmony_ci if (needs_copy(re, length)) 25948c2ecf20Sopenharmony_ci skb = receive_copy(sky2, re, length); 25958c2ecf20Sopenharmony_ci else 25968c2ecf20Sopenharmony_ci skb = receive_new(sky2, re, length); 25978c2ecf20Sopenharmony_ci 25988c2ecf20Sopenharmony_ci dev->stats.rx_dropped += (skb == NULL); 25998c2ecf20Sopenharmony_ci 26008c2ecf20Sopenharmony_ciresubmit: 26018c2ecf20Sopenharmony_ci sky2_rx_submit(sky2, re); 26028c2ecf20Sopenharmony_ci 26038c2ecf20Sopenharmony_ci return skb; 26048c2ecf20Sopenharmony_ci 26058c2ecf20Sopenharmony_cierror: 26068c2ecf20Sopenharmony_ci ++dev->stats.rx_errors; 26078c2ecf20Sopenharmony_ci 26088c2ecf20Sopenharmony_ci if (net_ratelimit()) 26098c2ecf20Sopenharmony_ci netif_info(sky2, rx_err, dev, 26108c2ecf20Sopenharmony_ci "rx error, status 0x%x length %d\n", status, length); 26118c2ecf20Sopenharmony_ci 26128c2ecf20Sopenharmony_ci goto resubmit; 26138c2ecf20Sopenharmony_ci} 26148c2ecf20Sopenharmony_ci 26158c2ecf20Sopenharmony_ci/* Transmit complete */ 26168c2ecf20Sopenharmony_cistatic inline void sky2_tx_done(struct net_device *dev, u16 last) 26178c2ecf20Sopenharmony_ci{ 26188c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 26198c2ecf20Sopenharmony_ci 26208c2ecf20Sopenharmony_ci if (netif_running(dev)) { 26218c2ecf20Sopenharmony_ci sky2_tx_complete(sky2, last); 26228c2ecf20Sopenharmony_ci 26238c2ecf20Sopenharmony_ci /* Wake unless it's detached, and called e.g. from sky2_close() */ 26248c2ecf20Sopenharmony_ci if (tx_avail(sky2) > MAX_SKB_TX_LE + 4) 26258c2ecf20Sopenharmony_ci netif_wake_queue(dev); 26268c2ecf20Sopenharmony_ci } 26278c2ecf20Sopenharmony_ci} 26288c2ecf20Sopenharmony_ci 26298c2ecf20Sopenharmony_cistatic inline void sky2_skb_rx(const struct sky2_port *sky2, 26308c2ecf20Sopenharmony_ci struct sk_buff *skb) 26318c2ecf20Sopenharmony_ci{ 26328c2ecf20Sopenharmony_ci if (skb->ip_summed == CHECKSUM_NONE) 26338c2ecf20Sopenharmony_ci netif_receive_skb(skb); 26348c2ecf20Sopenharmony_ci else 26358c2ecf20Sopenharmony_ci napi_gro_receive(&sky2->hw->napi, skb); 26368c2ecf20Sopenharmony_ci} 26378c2ecf20Sopenharmony_ci 26388c2ecf20Sopenharmony_cistatic inline void sky2_rx_done(struct sky2_hw *hw, unsigned port, 26398c2ecf20Sopenharmony_ci unsigned packets, unsigned bytes) 26408c2ecf20Sopenharmony_ci{ 26418c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 26428c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 26438c2ecf20Sopenharmony_ci 26448c2ecf20Sopenharmony_ci if (packets == 0) 26458c2ecf20Sopenharmony_ci return; 26468c2ecf20Sopenharmony_ci 26478c2ecf20Sopenharmony_ci u64_stats_update_begin(&sky2->rx_stats.syncp); 26488c2ecf20Sopenharmony_ci sky2->rx_stats.packets += packets; 26498c2ecf20Sopenharmony_ci sky2->rx_stats.bytes += bytes; 26508c2ecf20Sopenharmony_ci u64_stats_update_end(&sky2->rx_stats.syncp); 26518c2ecf20Sopenharmony_ci 26528c2ecf20Sopenharmony_ci sky2->last_rx = jiffies; 26538c2ecf20Sopenharmony_ci sky2_rx_update(netdev_priv(dev), rxqaddr[port]); 26548c2ecf20Sopenharmony_ci} 26558c2ecf20Sopenharmony_ci 26568c2ecf20Sopenharmony_cistatic void sky2_rx_checksum(struct sky2_port *sky2, u32 status) 26578c2ecf20Sopenharmony_ci{ 26588c2ecf20Sopenharmony_ci /* If this happens then driver assuming wrong format for chip type */ 26598c2ecf20Sopenharmony_ci BUG_ON(sky2->hw->flags & SKY2_HW_NEW_LE); 26608c2ecf20Sopenharmony_ci 26618c2ecf20Sopenharmony_ci /* Both checksum counters are programmed to start at 26628c2ecf20Sopenharmony_ci * the same offset, so unless there is a problem they 26638c2ecf20Sopenharmony_ci * should match. This failure is an early indication that 26648c2ecf20Sopenharmony_ci * hardware receive checksumming won't work. 26658c2ecf20Sopenharmony_ci */ 26668c2ecf20Sopenharmony_ci if (likely((u16)(status >> 16) == (u16)status)) { 26678c2ecf20Sopenharmony_ci struct sk_buff *skb = sky2->rx_ring[sky2->rx_next].skb; 26688c2ecf20Sopenharmony_ci skb->ip_summed = CHECKSUM_COMPLETE; 26698c2ecf20Sopenharmony_ci skb->csum = le16_to_cpu(status); 26708c2ecf20Sopenharmony_ci } else { 26718c2ecf20Sopenharmony_ci dev_notice(&sky2->hw->pdev->dev, 26728c2ecf20Sopenharmony_ci "%s: receive checksum problem (status = %#x)\n", 26738c2ecf20Sopenharmony_ci sky2->netdev->name, status); 26748c2ecf20Sopenharmony_ci 26758c2ecf20Sopenharmony_ci /* Disable checksum offload 26768c2ecf20Sopenharmony_ci * It will be reenabled on next ndo_set_features, but if it's 26778c2ecf20Sopenharmony_ci * really broken, will get disabled again 26788c2ecf20Sopenharmony_ci */ 26798c2ecf20Sopenharmony_ci sky2->netdev->features &= ~NETIF_F_RXCSUM; 26808c2ecf20Sopenharmony_ci sky2_write32(sky2->hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR), 26818c2ecf20Sopenharmony_ci BMU_DIS_RX_CHKSUM); 26828c2ecf20Sopenharmony_ci } 26838c2ecf20Sopenharmony_ci} 26848c2ecf20Sopenharmony_ci 26858c2ecf20Sopenharmony_cistatic void sky2_rx_tag(struct sky2_port *sky2, u16 length) 26868c2ecf20Sopenharmony_ci{ 26878c2ecf20Sopenharmony_ci struct sk_buff *skb; 26888c2ecf20Sopenharmony_ci 26898c2ecf20Sopenharmony_ci skb = sky2->rx_ring[sky2->rx_next].skb; 26908c2ecf20Sopenharmony_ci __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), be16_to_cpu(length)); 26918c2ecf20Sopenharmony_ci} 26928c2ecf20Sopenharmony_ci 26938c2ecf20Sopenharmony_cistatic void sky2_rx_hash(struct sky2_port *sky2, u32 status) 26948c2ecf20Sopenharmony_ci{ 26958c2ecf20Sopenharmony_ci struct sk_buff *skb; 26968c2ecf20Sopenharmony_ci 26978c2ecf20Sopenharmony_ci skb = sky2->rx_ring[sky2->rx_next].skb; 26988c2ecf20Sopenharmony_ci skb_set_hash(skb, le32_to_cpu(status), PKT_HASH_TYPE_L3); 26998c2ecf20Sopenharmony_ci} 27008c2ecf20Sopenharmony_ci 27018c2ecf20Sopenharmony_ci/* Process status response ring */ 27028c2ecf20Sopenharmony_cistatic int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx) 27038c2ecf20Sopenharmony_ci{ 27048c2ecf20Sopenharmony_ci int work_done = 0; 27058c2ecf20Sopenharmony_ci unsigned int total_bytes[2] = { 0 }; 27068c2ecf20Sopenharmony_ci unsigned int total_packets[2] = { 0 }; 27078c2ecf20Sopenharmony_ci 27088c2ecf20Sopenharmony_ci if (to_do <= 0) 27098c2ecf20Sopenharmony_ci return work_done; 27108c2ecf20Sopenharmony_ci 27118c2ecf20Sopenharmony_ci rmb(); 27128c2ecf20Sopenharmony_ci do { 27138c2ecf20Sopenharmony_ci struct sky2_port *sky2; 27148c2ecf20Sopenharmony_ci struct sky2_status_le *le = hw->st_le + hw->st_idx; 27158c2ecf20Sopenharmony_ci unsigned port; 27168c2ecf20Sopenharmony_ci struct net_device *dev; 27178c2ecf20Sopenharmony_ci struct sk_buff *skb; 27188c2ecf20Sopenharmony_ci u32 status; 27198c2ecf20Sopenharmony_ci u16 length; 27208c2ecf20Sopenharmony_ci u8 opcode = le->opcode; 27218c2ecf20Sopenharmony_ci 27228c2ecf20Sopenharmony_ci if (!(opcode & HW_OWNER)) 27238c2ecf20Sopenharmony_ci break; 27248c2ecf20Sopenharmony_ci 27258c2ecf20Sopenharmony_ci hw->st_idx = RING_NEXT(hw->st_idx, hw->st_size); 27268c2ecf20Sopenharmony_ci 27278c2ecf20Sopenharmony_ci port = le->css & CSS_LINK_BIT; 27288c2ecf20Sopenharmony_ci dev = hw->dev[port]; 27298c2ecf20Sopenharmony_ci sky2 = netdev_priv(dev); 27308c2ecf20Sopenharmony_ci length = le16_to_cpu(le->length); 27318c2ecf20Sopenharmony_ci status = le32_to_cpu(le->status); 27328c2ecf20Sopenharmony_ci 27338c2ecf20Sopenharmony_ci le->opcode = 0; 27348c2ecf20Sopenharmony_ci switch (opcode & ~HW_OWNER) { 27358c2ecf20Sopenharmony_ci case OP_RXSTAT: 27368c2ecf20Sopenharmony_ci total_packets[port]++; 27378c2ecf20Sopenharmony_ci total_bytes[port] += length; 27388c2ecf20Sopenharmony_ci 27398c2ecf20Sopenharmony_ci skb = sky2_receive(dev, length, status); 27408c2ecf20Sopenharmony_ci if (!skb) 27418c2ecf20Sopenharmony_ci break; 27428c2ecf20Sopenharmony_ci 27438c2ecf20Sopenharmony_ci /* This chip reports checksum status differently */ 27448c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_NEW_LE) { 27458c2ecf20Sopenharmony_ci if ((dev->features & NETIF_F_RXCSUM) && 27468c2ecf20Sopenharmony_ci (le->css & (CSS_ISIPV4 | CSS_ISIPV6)) && 27478c2ecf20Sopenharmony_ci (le->css & CSS_TCPUDPCSOK)) 27488c2ecf20Sopenharmony_ci skb->ip_summed = CHECKSUM_UNNECESSARY; 27498c2ecf20Sopenharmony_ci else 27508c2ecf20Sopenharmony_ci skb->ip_summed = CHECKSUM_NONE; 27518c2ecf20Sopenharmony_ci } 27528c2ecf20Sopenharmony_ci 27538c2ecf20Sopenharmony_ci skb->protocol = eth_type_trans(skb, dev); 27548c2ecf20Sopenharmony_ci sky2_skb_rx(sky2, skb); 27558c2ecf20Sopenharmony_ci 27568c2ecf20Sopenharmony_ci /* Stop after net poll weight */ 27578c2ecf20Sopenharmony_ci if (++work_done >= to_do) 27588c2ecf20Sopenharmony_ci goto exit_loop; 27598c2ecf20Sopenharmony_ci break; 27608c2ecf20Sopenharmony_ci 27618c2ecf20Sopenharmony_ci case OP_RXVLAN: 27628c2ecf20Sopenharmony_ci sky2_rx_tag(sky2, length); 27638c2ecf20Sopenharmony_ci break; 27648c2ecf20Sopenharmony_ci 27658c2ecf20Sopenharmony_ci case OP_RXCHKSVLAN: 27668c2ecf20Sopenharmony_ci sky2_rx_tag(sky2, length); 27678c2ecf20Sopenharmony_ci fallthrough; 27688c2ecf20Sopenharmony_ci case OP_RXCHKS: 27698c2ecf20Sopenharmony_ci if (likely(dev->features & NETIF_F_RXCSUM)) 27708c2ecf20Sopenharmony_ci sky2_rx_checksum(sky2, status); 27718c2ecf20Sopenharmony_ci break; 27728c2ecf20Sopenharmony_ci 27738c2ecf20Sopenharmony_ci case OP_RSS_HASH: 27748c2ecf20Sopenharmony_ci sky2_rx_hash(sky2, status); 27758c2ecf20Sopenharmony_ci break; 27768c2ecf20Sopenharmony_ci 27778c2ecf20Sopenharmony_ci case OP_TXINDEXLE: 27788c2ecf20Sopenharmony_ci /* TX index reports status for both ports */ 27798c2ecf20Sopenharmony_ci sky2_tx_done(hw->dev[0], status & 0xfff); 27808c2ecf20Sopenharmony_ci if (hw->dev[1]) 27818c2ecf20Sopenharmony_ci sky2_tx_done(hw->dev[1], 27828c2ecf20Sopenharmony_ci ((status >> 24) & 0xff) 27838c2ecf20Sopenharmony_ci | (u16)(length & 0xf) << 8); 27848c2ecf20Sopenharmony_ci break; 27858c2ecf20Sopenharmony_ci 27868c2ecf20Sopenharmony_ci default: 27878c2ecf20Sopenharmony_ci if (net_ratelimit()) 27888c2ecf20Sopenharmony_ci pr_warn("unknown status opcode 0x%x\n", opcode); 27898c2ecf20Sopenharmony_ci } 27908c2ecf20Sopenharmony_ci } while (hw->st_idx != idx); 27918c2ecf20Sopenharmony_ci 27928c2ecf20Sopenharmony_ci /* Fully processed status ring so clear irq */ 27938c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ); 27948c2ecf20Sopenharmony_ci 27958c2ecf20Sopenharmony_ciexit_loop: 27968c2ecf20Sopenharmony_ci sky2_rx_done(hw, 0, total_packets[0], total_bytes[0]); 27978c2ecf20Sopenharmony_ci sky2_rx_done(hw, 1, total_packets[1], total_bytes[1]); 27988c2ecf20Sopenharmony_ci 27998c2ecf20Sopenharmony_ci return work_done; 28008c2ecf20Sopenharmony_ci} 28018c2ecf20Sopenharmony_ci 28028c2ecf20Sopenharmony_cistatic void sky2_hw_error(struct sky2_hw *hw, unsigned port, u32 status) 28038c2ecf20Sopenharmony_ci{ 28048c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 28058c2ecf20Sopenharmony_ci 28068c2ecf20Sopenharmony_ci if (net_ratelimit()) 28078c2ecf20Sopenharmony_ci netdev_info(dev, "hw error interrupt status 0x%x\n", status); 28088c2ecf20Sopenharmony_ci 28098c2ecf20Sopenharmony_ci if (status & Y2_IS_PAR_RD1) { 28108c2ecf20Sopenharmony_ci if (net_ratelimit()) 28118c2ecf20Sopenharmony_ci netdev_err(dev, "ram data read parity error\n"); 28128c2ecf20Sopenharmony_ci /* Clear IRQ */ 28138c2ecf20Sopenharmony_ci sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_RD_PERR); 28148c2ecf20Sopenharmony_ci } 28158c2ecf20Sopenharmony_ci 28168c2ecf20Sopenharmony_ci if (status & Y2_IS_PAR_WR1) { 28178c2ecf20Sopenharmony_ci if (net_ratelimit()) 28188c2ecf20Sopenharmony_ci netdev_err(dev, "ram data write parity error\n"); 28198c2ecf20Sopenharmony_ci 28208c2ecf20Sopenharmony_ci sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_WR_PERR); 28218c2ecf20Sopenharmony_ci } 28228c2ecf20Sopenharmony_ci 28238c2ecf20Sopenharmony_ci if (status & Y2_IS_PAR_MAC1) { 28248c2ecf20Sopenharmony_ci if (net_ratelimit()) 28258c2ecf20Sopenharmony_ci netdev_err(dev, "MAC parity error\n"); 28268c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_PE); 28278c2ecf20Sopenharmony_ci } 28288c2ecf20Sopenharmony_ci 28298c2ecf20Sopenharmony_ci if (status & Y2_IS_PAR_RX1) { 28308c2ecf20Sopenharmony_ci if (net_ratelimit()) 28318c2ecf20Sopenharmony_ci netdev_err(dev, "RX parity error\n"); 28328c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), BMU_CLR_IRQ_PAR); 28338c2ecf20Sopenharmony_ci } 28348c2ecf20Sopenharmony_ci 28358c2ecf20Sopenharmony_ci if (status & Y2_IS_TCP_TXA1) { 28368c2ecf20Sopenharmony_ci if (net_ratelimit()) 28378c2ecf20Sopenharmony_ci netdev_err(dev, "TCP segmentation error\n"); 28388c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_CLR_IRQ_TCP); 28398c2ecf20Sopenharmony_ci } 28408c2ecf20Sopenharmony_ci} 28418c2ecf20Sopenharmony_ci 28428c2ecf20Sopenharmony_cistatic void sky2_hw_intr(struct sky2_hw *hw) 28438c2ecf20Sopenharmony_ci{ 28448c2ecf20Sopenharmony_ci struct pci_dev *pdev = hw->pdev; 28458c2ecf20Sopenharmony_ci u32 status = sky2_read32(hw, B0_HWE_ISRC); 28468c2ecf20Sopenharmony_ci u32 hwmsk = sky2_read32(hw, B0_HWE_IMSK); 28478c2ecf20Sopenharmony_ci 28488c2ecf20Sopenharmony_ci status &= hwmsk; 28498c2ecf20Sopenharmony_ci 28508c2ecf20Sopenharmony_ci if (status & Y2_IS_TIST_OV) 28518c2ecf20Sopenharmony_ci sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ); 28528c2ecf20Sopenharmony_ci 28538c2ecf20Sopenharmony_ci if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) { 28548c2ecf20Sopenharmony_ci u16 pci_err; 28558c2ecf20Sopenharmony_ci 28568c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 28578c2ecf20Sopenharmony_ci pci_err = sky2_pci_read16(hw, PCI_STATUS); 28588c2ecf20Sopenharmony_ci if (net_ratelimit()) 28598c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "PCI hardware error (0x%x)\n", 28608c2ecf20Sopenharmony_ci pci_err); 28618c2ecf20Sopenharmony_ci 28628c2ecf20Sopenharmony_ci sky2_pci_write16(hw, PCI_STATUS, 28638c2ecf20Sopenharmony_ci pci_err | PCI_STATUS_ERROR_BITS); 28648c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 28658c2ecf20Sopenharmony_ci } 28668c2ecf20Sopenharmony_ci 28678c2ecf20Sopenharmony_ci if (status & Y2_IS_PCI_EXP) { 28688c2ecf20Sopenharmony_ci /* PCI-Express uncorrectable Error occurred */ 28698c2ecf20Sopenharmony_ci u32 err; 28708c2ecf20Sopenharmony_ci 28718c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 28728c2ecf20Sopenharmony_ci err = sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS); 28738c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS, 28748c2ecf20Sopenharmony_ci 0xfffffffful); 28758c2ecf20Sopenharmony_ci if (net_ratelimit()) 28768c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "PCI Express error (0x%x)\n", err); 28778c2ecf20Sopenharmony_ci 28788c2ecf20Sopenharmony_ci sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS); 28798c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 28808c2ecf20Sopenharmony_ci } 28818c2ecf20Sopenharmony_ci 28828c2ecf20Sopenharmony_ci if (status & Y2_HWE_L1_MASK) 28838c2ecf20Sopenharmony_ci sky2_hw_error(hw, 0, status); 28848c2ecf20Sopenharmony_ci status >>= 8; 28858c2ecf20Sopenharmony_ci if (status & Y2_HWE_L1_MASK) 28868c2ecf20Sopenharmony_ci sky2_hw_error(hw, 1, status); 28878c2ecf20Sopenharmony_ci} 28888c2ecf20Sopenharmony_ci 28898c2ecf20Sopenharmony_cistatic void sky2_mac_intr(struct sky2_hw *hw, unsigned port) 28908c2ecf20Sopenharmony_ci{ 28918c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 28928c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 28938c2ecf20Sopenharmony_ci u8 status = sky2_read8(hw, SK_REG(port, GMAC_IRQ_SRC)); 28948c2ecf20Sopenharmony_ci 28958c2ecf20Sopenharmony_ci netif_info(sky2, intr, dev, "mac interrupt status 0x%x\n", status); 28968c2ecf20Sopenharmony_ci 28978c2ecf20Sopenharmony_ci if (status & GM_IS_RX_CO_OV) 28988c2ecf20Sopenharmony_ci gma_read16(hw, port, GM_RX_IRQ_SRC); 28998c2ecf20Sopenharmony_ci 29008c2ecf20Sopenharmony_ci if (status & GM_IS_TX_CO_OV) 29018c2ecf20Sopenharmony_ci gma_read16(hw, port, GM_TX_IRQ_SRC); 29028c2ecf20Sopenharmony_ci 29038c2ecf20Sopenharmony_ci if (status & GM_IS_RX_FF_OR) { 29048c2ecf20Sopenharmony_ci ++dev->stats.rx_fifo_errors; 29058c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO); 29068c2ecf20Sopenharmony_ci } 29078c2ecf20Sopenharmony_ci 29088c2ecf20Sopenharmony_ci if (status & GM_IS_TX_FF_UR) { 29098c2ecf20Sopenharmony_ci ++dev->stats.tx_fifo_errors; 29108c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU); 29118c2ecf20Sopenharmony_ci } 29128c2ecf20Sopenharmony_ci} 29138c2ecf20Sopenharmony_ci 29148c2ecf20Sopenharmony_ci/* This should never happen it is a bug. */ 29158c2ecf20Sopenharmony_cistatic void sky2_le_error(struct sky2_hw *hw, unsigned port, u16 q) 29168c2ecf20Sopenharmony_ci{ 29178c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[port]; 29188c2ecf20Sopenharmony_ci u16 idx = sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_GET_IDX)); 29198c2ecf20Sopenharmony_ci 29208c2ecf20Sopenharmony_ci dev_err(&hw->pdev->dev, "%s: descriptor error q=%#x get=%u put=%u\n", 29218c2ecf20Sopenharmony_ci dev->name, (unsigned) q, (unsigned) idx, 29228c2ecf20Sopenharmony_ci (unsigned) sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX))); 29238c2ecf20Sopenharmony_ci 29248c2ecf20Sopenharmony_ci sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_IRQ_CHK); 29258c2ecf20Sopenharmony_ci} 29268c2ecf20Sopenharmony_ci 29278c2ecf20Sopenharmony_cistatic int sky2_rx_hung(struct net_device *dev) 29288c2ecf20Sopenharmony_ci{ 29298c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 29308c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 29318c2ecf20Sopenharmony_ci unsigned port = sky2->port; 29328c2ecf20Sopenharmony_ci unsigned rxq = rxqaddr[port]; 29338c2ecf20Sopenharmony_ci u32 mac_rp = sky2_read32(hw, SK_REG(port, RX_GMF_RP)); 29348c2ecf20Sopenharmony_ci u8 mac_lev = sky2_read8(hw, SK_REG(port, RX_GMF_RLEV)); 29358c2ecf20Sopenharmony_ci u8 fifo_rp = sky2_read8(hw, Q_ADDR(rxq, Q_RP)); 29368c2ecf20Sopenharmony_ci u8 fifo_lev = sky2_read8(hw, Q_ADDR(rxq, Q_RL)); 29378c2ecf20Sopenharmony_ci 29388c2ecf20Sopenharmony_ci /* If idle and MAC or PCI is stuck */ 29398c2ecf20Sopenharmony_ci if (sky2->check.last == sky2->last_rx && 29408c2ecf20Sopenharmony_ci ((mac_rp == sky2->check.mac_rp && 29418c2ecf20Sopenharmony_ci mac_lev != 0 && mac_lev >= sky2->check.mac_lev) || 29428c2ecf20Sopenharmony_ci /* Check if the PCI RX hang */ 29438c2ecf20Sopenharmony_ci (fifo_rp == sky2->check.fifo_rp && 29448c2ecf20Sopenharmony_ci fifo_lev != 0 && fifo_lev >= sky2->check.fifo_lev))) { 29458c2ecf20Sopenharmony_ci netdev_printk(KERN_DEBUG, dev, 29468c2ecf20Sopenharmony_ci "hung mac %d:%d fifo %d (%d:%d)\n", 29478c2ecf20Sopenharmony_ci mac_lev, mac_rp, fifo_lev, 29488c2ecf20Sopenharmony_ci fifo_rp, sky2_read8(hw, Q_ADDR(rxq, Q_WP))); 29498c2ecf20Sopenharmony_ci return 1; 29508c2ecf20Sopenharmony_ci } else { 29518c2ecf20Sopenharmony_ci sky2->check.last = sky2->last_rx; 29528c2ecf20Sopenharmony_ci sky2->check.mac_rp = mac_rp; 29538c2ecf20Sopenharmony_ci sky2->check.mac_lev = mac_lev; 29548c2ecf20Sopenharmony_ci sky2->check.fifo_rp = fifo_rp; 29558c2ecf20Sopenharmony_ci sky2->check.fifo_lev = fifo_lev; 29568c2ecf20Sopenharmony_ci return 0; 29578c2ecf20Sopenharmony_ci } 29588c2ecf20Sopenharmony_ci} 29598c2ecf20Sopenharmony_ci 29608c2ecf20Sopenharmony_cistatic void sky2_watchdog(struct timer_list *t) 29618c2ecf20Sopenharmony_ci{ 29628c2ecf20Sopenharmony_ci struct sky2_hw *hw = from_timer(hw, t, watchdog_timer); 29638c2ecf20Sopenharmony_ci 29648c2ecf20Sopenharmony_ci /* Check for lost IRQ once a second */ 29658c2ecf20Sopenharmony_ci if (sky2_read32(hw, B0_ISRC)) { 29668c2ecf20Sopenharmony_ci napi_schedule(&hw->napi); 29678c2ecf20Sopenharmony_ci } else { 29688c2ecf20Sopenharmony_ci int i, active = 0; 29698c2ecf20Sopenharmony_ci 29708c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 29718c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[i]; 29728c2ecf20Sopenharmony_ci if (!netif_running(dev)) 29738c2ecf20Sopenharmony_ci continue; 29748c2ecf20Sopenharmony_ci ++active; 29758c2ecf20Sopenharmony_ci 29768c2ecf20Sopenharmony_ci /* For chips with Rx FIFO, check if stuck */ 29778c2ecf20Sopenharmony_ci if ((hw->flags & SKY2_HW_RAM_BUFFER) && 29788c2ecf20Sopenharmony_ci sky2_rx_hung(dev)) { 29798c2ecf20Sopenharmony_ci netdev_info(dev, "receiver hang detected\n"); 29808c2ecf20Sopenharmony_ci schedule_work(&hw->restart_work); 29818c2ecf20Sopenharmony_ci return; 29828c2ecf20Sopenharmony_ci } 29838c2ecf20Sopenharmony_ci } 29848c2ecf20Sopenharmony_ci 29858c2ecf20Sopenharmony_ci if (active == 0) 29868c2ecf20Sopenharmony_ci return; 29878c2ecf20Sopenharmony_ci } 29888c2ecf20Sopenharmony_ci 29898c2ecf20Sopenharmony_ci mod_timer(&hw->watchdog_timer, round_jiffies(jiffies + HZ)); 29908c2ecf20Sopenharmony_ci} 29918c2ecf20Sopenharmony_ci 29928c2ecf20Sopenharmony_ci/* Hardware/software error handling */ 29938c2ecf20Sopenharmony_cistatic void sky2_err_intr(struct sky2_hw *hw, u32 status) 29948c2ecf20Sopenharmony_ci{ 29958c2ecf20Sopenharmony_ci if (net_ratelimit()) 29968c2ecf20Sopenharmony_ci dev_warn(&hw->pdev->dev, "error interrupt status=%#x\n", status); 29978c2ecf20Sopenharmony_ci 29988c2ecf20Sopenharmony_ci if (status & Y2_IS_HW_ERR) 29998c2ecf20Sopenharmony_ci sky2_hw_intr(hw); 30008c2ecf20Sopenharmony_ci 30018c2ecf20Sopenharmony_ci if (status & Y2_IS_IRQ_MAC1) 30028c2ecf20Sopenharmony_ci sky2_mac_intr(hw, 0); 30038c2ecf20Sopenharmony_ci 30048c2ecf20Sopenharmony_ci if (status & Y2_IS_IRQ_MAC2) 30058c2ecf20Sopenharmony_ci sky2_mac_intr(hw, 1); 30068c2ecf20Sopenharmony_ci 30078c2ecf20Sopenharmony_ci if (status & Y2_IS_CHK_RX1) 30088c2ecf20Sopenharmony_ci sky2_le_error(hw, 0, Q_R1); 30098c2ecf20Sopenharmony_ci 30108c2ecf20Sopenharmony_ci if (status & Y2_IS_CHK_RX2) 30118c2ecf20Sopenharmony_ci sky2_le_error(hw, 1, Q_R2); 30128c2ecf20Sopenharmony_ci 30138c2ecf20Sopenharmony_ci if (status & Y2_IS_CHK_TXA1) 30148c2ecf20Sopenharmony_ci sky2_le_error(hw, 0, Q_XA1); 30158c2ecf20Sopenharmony_ci 30168c2ecf20Sopenharmony_ci if (status & Y2_IS_CHK_TXA2) 30178c2ecf20Sopenharmony_ci sky2_le_error(hw, 1, Q_XA2); 30188c2ecf20Sopenharmony_ci} 30198c2ecf20Sopenharmony_ci 30208c2ecf20Sopenharmony_cistatic int sky2_poll(struct napi_struct *napi, int work_limit) 30218c2ecf20Sopenharmony_ci{ 30228c2ecf20Sopenharmony_ci struct sky2_hw *hw = container_of(napi, struct sky2_hw, napi); 30238c2ecf20Sopenharmony_ci u32 status = sky2_read32(hw, B0_Y2_SP_EISR); 30248c2ecf20Sopenharmony_ci int work_done = 0; 30258c2ecf20Sopenharmony_ci u16 idx; 30268c2ecf20Sopenharmony_ci 30278c2ecf20Sopenharmony_ci if (unlikely(status & Y2_IS_ERROR)) 30288c2ecf20Sopenharmony_ci sky2_err_intr(hw, status); 30298c2ecf20Sopenharmony_ci 30308c2ecf20Sopenharmony_ci if (status & Y2_IS_IRQ_PHY1) 30318c2ecf20Sopenharmony_ci sky2_phy_intr(hw, 0); 30328c2ecf20Sopenharmony_ci 30338c2ecf20Sopenharmony_ci if (status & Y2_IS_IRQ_PHY2) 30348c2ecf20Sopenharmony_ci sky2_phy_intr(hw, 1); 30358c2ecf20Sopenharmony_ci 30368c2ecf20Sopenharmony_ci if (status & Y2_IS_PHY_QLNK) 30378c2ecf20Sopenharmony_ci sky2_qlink_intr(hw); 30388c2ecf20Sopenharmony_ci 30398c2ecf20Sopenharmony_ci while ((idx = sky2_read16(hw, STAT_PUT_IDX)) != hw->st_idx) { 30408c2ecf20Sopenharmony_ci work_done += sky2_status_intr(hw, work_limit - work_done, idx); 30418c2ecf20Sopenharmony_ci 30428c2ecf20Sopenharmony_ci if (work_done >= work_limit) 30438c2ecf20Sopenharmony_ci goto done; 30448c2ecf20Sopenharmony_ci } 30458c2ecf20Sopenharmony_ci 30468c2ecf20Sopenharmony_ci napi_complete_done(napi, work_done); 30478c2ecf20Sopenharmony_ci sky2_read32(hw, B0_Y2_SP_LISR); 30488c2ecf20Sopenharmony_cidone: 30498c2ecf20Sopenharmony_ci 30508c2ecf20Sopenharmony_ci return work_done; 30518c2ecf20Sopenharmony_ci} 30528c2ecf20Sopenharmony_ci 30538c2ecf20Sopenharmony_cistatic irqreturn_t sky2_intr(int irq, void *dev_id) 30548c2ecf20Sopenharmony_ci{ 30558c2ecf20Sopenharmony_ci struct sky2_hw *hw = dev_id; 30568c2ecf20Sopenharmony_ci u32 status; 30578c2ecf20Sopenharmony_ci 30588c2ecf20Sopenharmony_ci /* Reading this mask interrupts as side effect */ 30598c2ecf20Sopenharmony_ci status = sky2_read32(hw, B0_Y2_SP_ISRC2); 30608c2ecf20Sopenharmony_ci if (status == 0 || status == ~0) { 30618c2ecf20Sopenharmony_ci sky2_write32(hw, B0_Y2_SP_ICR, 2); 30628c2ecf20Sopenharmony_ci return IRQ_NONE; 30638c2ecf20Sopenharmony_ci } 30648c2ecf20Sopenharmony_ci 30658c2ecf20Sopenharmony_ci prefetch(&hw->st_le[hw->st_idx]); 30668c2ecf20Sopenharmony_ci 30678c2ecf20Sopenharmony_ci napi_schedule(&hw->napi); 30688c2ecf20Sopenharmony_ci 30698c2ecf20Sopenharmony_ci return IRQ_HANDLED; 30708c2ecf20Sopenharmony_ci} 30718c2ecf20Sopenharmony_ci 30728c2ecf20Sopenharmony_ci#ifdef CONFIG_NET_POLL_CONTROLLER 30738c2ecf20Sopenharmony_cistatic void sky2_netpoll(struct net_device *dev) 30748c2ecf20Sopenharmony_ci{ 30758c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 30768c2ecf20Sopenharmony_ci 30778c2ecf20Sopenharmony_ci napi_schedule(&sky2->hw->napi); 30788c2ecf20Sopenharmony_ci} 30798c2ecf20Sopenharmony_ci#endif 30808c2ecf20Sopenharmony_ci 30818c2ecf20Sopenharmony_ci/* Chip internal frequency for clock calculations */ 30828c2ecf20Sopenharmony_cistatic u32 sky2_mhz(const struct sky2_hw *hw) 30838c2ecf20Sopenharmony_ci{ 30848c2ecf20Sopenharmony_ci switch (hw->chip_id) { 30858c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_EC: 30868c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_EC_U: 30878c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_EX: 30888c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_SUPR: 30898c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_UL_2: 30908c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_OPT: 30918c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_PRM: 30928c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_OP_2: 30938c2ecf20Sopenharmony_ci return 125; 30948c2ecf20Sopenharmony_ci 30958c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_FE: 30968c2ecf20Sopenharmony_ci return 100; 30978c2ecf20Sopenharmony_ci 30988c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_FE_P: 30998c2ecf20Sopenharmony_ci return 50; 31008c2ecf20Sopenharmony_ci 31018c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_XL: 31028c2ecf20Sopenharmony_ci return 156; 31038c2ecf20Sopenharmony_ci 31048c2ecf20Sopenharmony_ci default: 31058c2ecf20Sopenharmony_ci BUG(); 31068c2ecf20Sopenharmony_ci } 31078c2ecf20Sopenharmony_ci} 31088c2ecf20Sopenharmony_ci 31098c2ecf20Sopenharmony_cistatic inline u32 sky2_us2clk(const struct sky2_hw *hw, u32 us) 31108c2ecf20Sopenharmony_ci{ 31118c2ecf20Sopenharmony_ci return sky2_mhz(hw) * us; 31128c2ecf20Sopenharmony_ci} 31138c2ecf20Sopenharmony_ci 31148c2ecf20Sopenharmony_cistatic inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk) 31158c2ecf20Sopenharmony_ci{ 31168c2ecf20Sopenharmony_ci return clk / sky2_mhz(hw); 31178c2ecf20Sopenharmony_ci} 31188c2ecf20Sopenharmony_ci 31198c2ecf20Sopenharmony_ci 31208c2ecf20Sopenharmony_cistatic int sky2_init(struct sky2_hw *hw) 31218c2ecf20Sopenharmony_ci{ 31228c2ecf20Sopenharmony_ci u8 t8; 31238c2ecf20Sopenharmony_ci 31248c2ecf20Sopenharmony_ci /* Enable all clocks and check for bad PCI access */ 31258c2ecf20Sopenharmony_ci sky2_pci_write32(hw, PCI_DEV_REG3, 0); 31268c2ecf20Sopenharmony_ci 31278c2ecf20Sopenharmony_ci sky2_write8(hw, B0_CTST, CS_RST_CLR); 31288c2ecf20Sopenharmony_ci 31298c2ecf20Sopenharmony_ci hw->chip_id = sky2_read8(hw, B2_CHIP_ID); 31308c2ecf20Sopenharmony_ci hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4; 31318c2ecf20Sopenharmony_ci 31328c2ecf20Sopenharmony_ci switch (hw->chip_id) { 31338c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_XL: 31348c2ecf20Sopenharmony_ci hw->flags = SKY2_HW_GIGABIT | SKY2_HW_NEWER_PHY; 31358c2ecf20Sopenharmony_ci if (hw->chip_rev < CHIP_REV_YU_XL_A2) 31368c2ecf20Sopenharmony_ci hw->flags |= SKY2_HW_RSS_BROKEN; 31378c2ecf20Sopenharmony_ci break; 31388c2ecf20Sopenharmony_ci 31398c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_EC_U: 31408c2ecf20Sopenharmony_ci hw->flags = SKY2_HW_GIGABIT 31418c2ecf20Sopenharmony_ci | SKY2_HW_NEWER_PHY 31428c2ecf20Sopenharmony_ci | SKY2_HW_ADV_POWER_CTL; 31438c2ecf20Sopenharmony_ci break; 31448c2ecf20Sopenharmony_ci 31458c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_EX: 31468c2ecf20Sopenharmony_ci hw->flags = SKY2_HW_GIGABIT 31478c2ecf20Sopenharmony_ci | SKY2_HW_NEWER_PHY 31488c2ecf20Sopenharmony_ci | SKY2_HW_NEW_LE 31498c2ecf20Sopenharmony_ci | SKY2_HW_ADV_POWER_CTL 31508c2ecf20Sopenharmony_ci | SKY2_HW_RSS_CHKSUM; 31518c2ecf20Sopenharmony_ci 31528c2ecf20Sopenharmony_ci /* New transmit checksum */ 31538c2ecf20Sopenharmony_ci if (hw->chip_rev != CHIP_REV_YU_EX_B0) 31548c2ecf20Sopenharmony_ci hw->flags |= SKY2_HW_AUTO_TX_SUM; 31558c2ecf20Sopenharmony_ci break; 31568c2ecf20Sopenharmony_ci 31578c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_EC: 31588c2ecf20Sopenharmony_ci /* This rev is really old, and requires untested workarounds */ 31598c2ecf20Sopenharmony_ci if (hw->chip_rev == CHIP_REV_YU_EC_A1) { 31608c2ecf20Sopenharmony_ci dev_err(&hw->pdev->dev, "unsupported revision Yukon-EC rev A1\n"); 31618c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 31628c2ecf20Sopenharmony_ci } 31638c2ecf20Sopenharmony_ci hw->flags = SKY2_HW_GIGABIT | SKY2_HW_RSS_BROKEN; 31648c2ecf20Sopenharmony_ci break; 31658c2ecf20Sopenharmony_ci 31668c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_FE: 31678c2ecf20Sopenharmony_ci hw->flags = SKY2_HW_RSS_BROKEN; 31688c2ecf20Sopenharmony_ci break; 31698c2ecf20Sopenharmony_ci 31708c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_FE_P: 31718c2ecf20Sopenharmony_ci hw->flags = SKY2_HW_NEWER_PHY 31728c2ecf20Sopenharmony_ci | SKY2_HW_NEW_LE 31738c2ecf20Sopenharmony_ci | SKY2_HW_AUTO_TX_SUM 31748c2ecf20Sopenharmony_ci | SKY2_HW_ADV_POWER_CTL; 31758c2ecf20Sopenharmony_ci 31768c2ecf20Sopenharmony_ci /* The workaround for status conflicts VLAN tag detection. */ 31778c2ecf20Sopenharmony_ci if (hw->chip_rev == CHIP_REV_YU_FE2_A0) 31788c2ecf20Sopenharmony_ci hw->flags |= SKY2_HW_VLAN_BROKEN | SKY2_HW_RSS_CHKSUM; 31798c2ecf20Sopenharmony_ci break; 31808c2ecf20Sopenharmony_ci 31818c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_SUPR: 31828c2ecf20Sopenharmony_ci hw->flags = SKY2_HW_GIGABIT 31838c2ecf20Sopenharmony_ci | SKY2_HW_NEWER_PHY 31848c2ecf20Sopenharmony_ci | SKY2_HW_NEW_LE 31858c2ecf20Sopenharmony_ci | SKY2_HW_AUTO_TX_SUM 31868c2ecf20Sopenharmony_ci | SKY2_HW_ADV_POWER_CTL; 31878c2ecf20Sopenharmony_ci 31888c2ecf20Sopenharmony_ci if (hw->chip_rev == CHIP_REV_YU_SU_A0) 31898c2ecf20Sopenharmony_ci hw->flags |= SKY2_HW_RSS_CHKSUM; 31908c2ecf20Sopenharmony_ci break; 31918c2ecf20Sopenharmony_ci 31928c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_UL_2: 31938c2ecf20Sopenharmony_ci hw->flags = SKY2_HW_GIGABIT 31948c2ecf20Sopenharmony_ci | SKY2_HW_ADV_POWER_CTL; 31958c2ecf20Sopenharmony_ci break; 31968c2ecf20Sopenharmony_ci 31978c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_OPT: 31988c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_PRM: 31998c2ecf20Sopenharmony_ci case CHIP_ID_YUKON_OP_2: 32008c2ecf20Sopenharmony_ci hw->flags = SKY2_HW_GIGABIT 32018c2ecf20Sopenharmony_ci | SKY2_HW_NEW_LE 32028c2ecf20Sopenharmony_ci | SKY2_HW_ADV_POWER_CTL; 32038c2ecf20Sopenharmony_ci break; 32048c2ecf20Sopenharmony_ci 32058c2ecf20Sopenharmony_ci default: 32068c2ecf20Sopenharmony_ci dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n", 32078c2ecf20Sopenharmony_ci hw->chip_id); 32088c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 32098c2ecf20Sopenharmony_ci } 32108c2ecf20Sopenharmony_ci 32118c2ecf20Sopenharmony_ci hw->pmd_type = sky2_read8(hw, B2_PMD_TYP); 32128c2ecf20Sopenharmony_ci if (hw->pmd_type == 'L' || hw->pmd_type == 'S' || hw->pmd_type == 'P') 32138c2ecf20Sopenharmony_ci hw->flags |= SKY2_HW_FIBRE_PHY; 32148c2ecf20Sopenharmony_ci 32158c2ecf20Sopenharmony_ci hw->ports = 1; 32168c2ecf20Sopenharmony_ci t8 = sky2_read8(hw, B2_Y2_HW_RES); 32178c2ecf20Sopenharmony_ci if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) { 32188c2ecf20Sopenharmony_ci if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC)) 32198c2ecf20Sopenharmony_ci ++hw->ports; 32208c2ecf20Sopenharmony_ci } 32218c2ecf20Sopenharmony_ci 32228c2ecf20Sopenharmony_ci if (sky2_read8(hw, B2_E_0)) 32238c2ecf20Sopenharmony_ci hw->flags |= SKY2_HW_RAM_BUFFER; 32248c2ecf20Sopenharmony_ci 32258c2ecf20Sopenharmony_ci return 0; 32268c2ecf20Sopenharmony_ci} 32278c2ecf20Sopenharmony_ci 32288c2ecf20Sopenharmony_cistatic void sky2_reset(struct sky2_hw *hw) 32298c2ecf20Sopenharmony_ci{ 32308c2ecf20Sopenharmony_ci struct pci_dev *pdev = hw->pdev; 32318c2ecf20Sopenharmony_ci u16 status; 32328c2ecf20Sopenharmony_ci int i; 32338c2ecf20Sopenharmony_ci u32 hwe_mask = Y2_HWE_ALL_MASK; 32348c2ecf20Sopenharmony_ci 32358c2ecf20Sopenharmony_ci /* disable ASF */ 32368c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EX 32378c2ecf20Sopenharmony_ci || hw->chip_id == CHIP_ID_YUKON_SUPR) { 32388c2ecf20Sopenharmony_ci sky2_write32(hw, CPU_WDOG, 0); 32398c2ecf20Sopenharmony_ci status = sky2_read16(hw, HCU_CCSR); 32408c2ecf20Sopenharmony_ci status &= ~(HCU_CCSR_AHB_RST | HCU_CCSR_CPU_RST_MODE | 32418c2ecf20Sopenharmony_ci HCU_CCSR_UC_STATE_MSK); 32428c2ecf20Sopenharmony_ci /* 32438c2ecf20Sopenharmony_ci * CPU clock divider shouldn't be used because 32448c2ecf20Sopenharmony_ci * - ASF firmware may malfunction 32458c2ecf20Sopenharmony_ci * - Yukon-Supreme: Parallel FLASH doesn't support divided clocks 32468c2ecf20Sopenharmony_ci */ 32478c2ecf20Sopenharmony_ci status &= ~HCU_CCSR_CPU_CLK_DIVIDE_MSK; 32488c2ecf20Sopenharmony_ci sky2_write16(hw, HCU_CCSR, status); 32498c2ecf20Sopenharmony_ci sky2_write32(hw, CPU_WDOG, 0); 32508c2ecf20Sopenharmony_ci } else 32518c2ecf20Sopenharmony_ci sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET); 32528c2ecf20Sopenharmony_ci sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE); 32538c2ecf20Sopenharmony_ci 32548c2ecf20Sopenharmony_ci /* do a SW reset */ 32558c2ecf20Sopenharmony_ci sky2_write8(hw, B0_CTST, CS_RST_SET); 32568c2ecf20Sopenharmony_ci sky2_write8(hw, B0_CTST, CS_RST_CLR); 32578c2ecf20Sopenharmony_ci 32588c2ecf20Sopenharmony_ci /* allow writes to PCI config */ 32598c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 32608c2ecf20Sopenharmony_ci 32618c2ecf20Sopenharmony_ci /* clear PCI errors, if any */ 32628c2ecf20Sopenharmony_ci status = sky2_pci_read16(hw, PCI_STATUS); 32638c2ecf20Sopenharmony_ci status |= PCI_STATUS_ERROR_BITS; 32648c2ecf20Sopenharmony_ci sky2_pci_write16(hw, PCI_STATUS, status); 32658c2ecf20Sopenharmony_ci 32668c2ecf20Sopenharmony_ci sky2_write8(hw, B0_CTST, CS_MRST_CLR); 32678c2ecf20Sopenharmony_ci 32688c2ecf20Sopenharmony_ci if (pci_is_pcie(pdev)) { 32698c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS, 32708c2ecf20Sopenharmony_ci 0xfffffffful); 32718c2ecf20Sopenharmony_ci 32728c2ecf20Sopenharmony_ci /* If error bit is stuck on ignore it */ 32738c2ecf20Sopenharmony_ci if (sky2_read32(hw, B0_HWE_ISRC) & Y2_IS_PCI_EXP) 32748c2ecf20Sopenharmony_ci dev_info(&pdev->dev, "ignoring stuck error report bit\n"); 32758c2ecf20Sopenharmony_ci else 32768c2ecf20Sopenharmony_ci hwe_mask |= Y2_IS_PCI_EXP; 32778c2ecf20Sopenharmony_ci } 32788c2ecf20Sopenharmony_ci 32798c2ecf20Sopenharmony_ci sky2_power_on(hw); 32808c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 32818c2ecf20Sopenharmony_ci 32828c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 32838c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET); 32848c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR); 32858c2ecf20Sopenharmony_ci 32868c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EX || 32878c2ecf20Sopenharmony_ci hw->chip_id == CHIP_ID_YUKON_SUPR) 32888c2ecf20Sopenharmony_ci sky2_write16(hw, SK_REG(i, GMAC_CTRL), 32898c2ecf20Sopenharmony_ci GMC_BYP_MACSECRX_ON | GMC_BYP_MACSECTX_ON 32908c2ecf20Sopenharmony_ci | GMC_BYP_RETR_ON); 32918c2ecf20Sopenharmony_ci 32928c2ecf20Sopenharmony_ci } 32938c2ecf20Sopenharmony_ci 32948c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_SUPR && hw->chip_rev > CHIP_REV_YU_SU_B0) { 32958c2ecf20Sopenharmony_ci /* enable MACSec clock gating */ 32968c2ecf20Sopenharmony_ci sky2_pci_write32(hw, PCI_DEV_REG3, P_CLK_MACSEC_DIS); 32978c2ecf20Sopenharmony_ci } 32988c2ecf20Sopenharmony_ci 32998c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_OPT || 33008c2ecf20Sopenharmony_ci hw->chip_id == CHIP_ID_YUKON_PRM || 33018c2ecf20Sopenharmony_ci hw->chip_id == CHIP_ID_YUKON_OP_2) { 33028c2ecf20Sopenharmony_ci u16 reg; 33038c2ecf20Sopenharmony_ci 33048c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_OPT && hw->chip_rev == 0) { 33058c2ecf20Sopenharmony_ci /* disable PCI-E PHY power down (set PHY reg 0x80, bit 7 */ 33068c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_PEX_PHY_DATA, (0x80UL << 16) | (1 << 7)); 33078c2ecf20Sopenharmony_ci 33088c2ecf20Sopenharmony_ci /* set PHY Link Detect Timer to 1.1 second (11x 100ms) */ 33098c2ecf20Sopenharmony_ci reg = 10; 33108c2ecf20Sopenharmony_ci 33118c2ecf20Sopenharmony_ci /* re-enable PEX PM in PEX PHY debug reg. 8 (clear bit 12) */ 33128c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_PEX_PHY_DATA, PEX_DB_ACCESS | (0x08UL << 16)); 33138c2ecf20Sopenharmony_ci } else { 33148c2ecf20Sopenharmony_ci /* set PHY Link Detect Timer to 0.4 second (4x 100ms) */ 33158c2ecf20Sopenharmony_ci reg = 3; 33168c2ecf20Sopenharmony_ci } 33178c2ecf20Sopenharmony_ci 33188c2ecf20Sopenharmony_ci reg <<= PSM_CONFIG_REG4_TIMER_PHY_LINK_DETECT_BASE; 33198c2ecf20Sopenharmony_ci reg |= PSM_CONFIG_REG4_RST_PHY_LINK_DETECT; 33208c2ecf20Sopenharmony_ci 33218c2ecf20Sopenharmony_ci /* reset PHY Link Detect */ 33228c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 33238c2ecf20Sopenharmony_ci sky2_pci_write16(hw, PSM_CONFIG_REG4, reg); 33248c2ecf20Sopenharmony_ci 33258c2ecf20Sopenharmony_ci /* check if PSMv2 was running before */ 33268c2ecf20Sopenharmony_ci reg = sky2_pci_read16(hw, PSM_CONFIG_REG3); 33278c2ecf20Sopenharmony_ci if (reg & PCI_EXP_LNKCTL_ASPMC) 33288c2ecf20Sopenharmony_ci /* restore the PCIe Link Control register */ 33298c2ecf20Sopenharmony_ci sky2_pci_write16(hw, pdev->pcie_cap + PCI_EXP_LNKCTL, 33308c2ecf20Sopenharmony_ci reg); 33318c2ecf20Sopenharmony_ci 33328c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_PRM && 33338c2ecf20Sopenharmony_ci hw->chip_rev == CHIP_REV_YU_PRM_A0) { 33348c2ecf20Sopenharmony_ci /* change PHY Interrupt polarity to low active */ 33358c2ecf20Sopenharmony_ci reg = sky2_read16(hw, GPHY_CTRL); 33368c2ecf20Sopenharmony_ci sky2_write16(hw, GPHY_CTRL, reg | GPC_INTPOL); 33378c2ecf20Sopenharmony_ci 33388c2ecf20Sopenharmony_ci /* adapt HW for low active PHY Interrupt */ 33398c2ecf20Sopenharmony_ci reg = sky2_read16(hw, Y2_CFG_SPC + PCI_LDO_CTRL); 33408c2ecf20Sopenharmony_ci sky2_write16(hw, Y2_CFG_SPC + PCI_LDO_CTRL, reg | PHY_M_UNDOC1); 33418c2ecf20Sopenharmony_ci } 33428c2ecf20Sopenharmony_ci 33438c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 33448c2ecf20Sopenharmony_ci 33458c2ecf20Sopenharmony_ci /* re-enable PEX PM in PEX PHY debug reg. 8 (clear bit 12) */ 33468c2ecf20Sopenharmony_ci sky2_write32(hw, Y2_PEX_PHY_DATA, PEX_DB_ACCESS | (0x08UL << 16)); 33478c2ecf20Sopenharmony_ci } 33488c2ecf20Sopenharmony_ci 33498c2ecf20Sopenharmony_ci /* Clear I2C IRQ noise */ 33508c2ecf20Sopenharmony_ci sky2_write32(hw, B2_I2C_IRQ, 1); 33518c2ecf20Sopenharmony_ci 33528c2ecf20Sopenharmony_ci /* turn off hardware timer (unused) */ 33538c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TI_CTRL, TIM_STOP); 33548c2ecf20Sopenharmony_ci sky2_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ); 33558c2ecf20Sopenharmony_ci 33568c2ecf20Sopenharmony_ci /* Turn off descriptor polling */ 33578c2ecf20Sopenharmony_ci sky2_write32(hw, B28_DPT_CTRL, DPT_STOP); 33588c2ecf20Sopenharmony_ci 33598c2ecf20Sopenharmony_ci /* Turn off receive timestamp */ 33608c2ecf20Sopenharmony_ci sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_STOP); 33618c2ecf20Sopenharmony_ci sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ); 33628c2ecf20Sopenharmony_ci 33638c2ecf20Sopenharmony_ci /* enable the Tx Arbiters */ 33648c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) 33658c2ecf20Sopenharmony_ci sky2_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB); 33668c2ecf20Sopenharmony_ci 33678c2ecf20Sopenharmony_ci /* Initialize ram interface */ 33688c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 33698c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_CTRL), RI_RST_CLR); 33708c2ecf20Sopenharmony_ci 33718c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R1), SK_RI_TO_53); 33728c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA1), SK_RI_TO_53); 33738c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS1), SK_RI_TO_53); 33748c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R1), SK_RI_TO_53); 33758c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA1), SK_RI_TO_53); 33768c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS1), SK_RI_TO_53); 33778c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R2), SK_RI_TO_53); 33788c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA2), SK_RI_TO_53); 33798c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS2), SK_RI_TO_53); 33808c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R2), SK_RI_TO_53); 33818c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA2), SK_RI_TO_53); 33828c2ecf20Sopenharmony_ci sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS2), SK_RI_TO_53); 33838c2ecf20Sopenharmony_ci } 33848c2ecf20Sopenharmony_ci 33858c2ecf20Sopenharmony_ci sky2_write32(hw, B0_HWE_IMSK, hwe_mask); 33868c2ecf20Sopenharmony_ci 33878c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) 33888c2ecf20Sopenharmony_ci sky2_gmac_reset(hw, i); 33898c2ecf20Sopenharmony_ci 33908c2ecf20Sopenharmony_ci memset(hw->st_le, 0, hw->st_size * sizeof(struct sky2_status_le)); 33918c2ecf20Sopenharmony_ci hw->st_idx = 0; 33928c2ecf20Sopenharmony_ci 33938c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_CTRL, SC_STAT_RST_SET); 33948c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_CTRL, SC_STAT_RST_CLR); 33958c2ecf20Sopenharmony_ci 33968c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_LIST_ADDR_LO, hw->st_dma); 33978c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_LIST_ADDR_HI, (u64) hw->st_dma >> 32); 33988c2ecf20Sopenharmony_ci 33998c2ecf20Sopenharmony_ci /* Set the list last index */ 34008c2ecf20Sopenharmony_ci sky2_write16(hw, STAT_LAST_IDX, hw->st_size - 1); 34018c2ecf20Sopenharmony_ci 34028c2ecf20Sopenharmony_ci sky2_write16(hw, STAT_TX_IDX_TH, 10); 34038c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_FIFO_WM, 16); 34048c2ecf20Sopenharmony_ci 34058c2ecf20Sopenharmony_ci /* set Status-FIFO ISR watermark */ 34068c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0) 34078c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_FIFO_ISR_WM, 4); 34088c2ecf20Sopenharmony_ci else 34098c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_FIFO_ISR_WM, 16); 34108c2ecf20Sopenharmony_ci 34118c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 1000)); 34128c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_ISR_TIMER_INI, sky2_us2clk(hw, 20)); 34138c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_LEV_TIMER_INI, sky2_us2clk(hw, 100)); 34148c2ecf20Sopenharmony_ci 34158c2ecf20Sopenharmony_ci /* enable status unit */ 34168c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_CTRL, SC_STAT_OP_ON); 34178c2ecf20Sopenharmony_ci 34188c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START); 34198c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START); 34208c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START); 34218c2ecf20Sopenharmony_ci} 34228c2ecf20Sopenharmony_ci 34238c2ecf20Sopenharmony_ci/* Take device down (offline). 34248c2ecf20Sopenharmony_ci * Equivalent to doing dev_stop() but this does not 34258c2ecf20Sopenharmony_ci * inform upper layers of the transition. 34268c2ecf20Sopenharmony_ci */ 34278c2ecf20Sopenharmony_cistatic void sky2_detach(struct net_device *dev) 34288c2ecf20Sopenharmony_ci{ 34298c2ecf20Sopenharmony_ci if (netif_running(dev)) { 34308c2ecf20Sopenharmony_ci netif_tx_lock(dev); 34318c2ecf20Sopenharmony_ci netif_device_detach(dev); /* stop txq */ 34328c2ecf20Sopenharmony_ci netif_tx_unlock(dev); 34338c2ecf20Sopenharmony_ci sky2_close(dev); 34348c2ecf20Sopenharmony_ci } 34358c2ecf20Sopenharmony_ci} 34368c2ecf20Sopenharmony_ci 34378c2ecf20Sopenharmony_ci/* Bring device back after doing sky2_detach */ 34388c2ecf20Sopenharmony_cistatic int sky2_reattach(struct net_device *dev) 34398c2ecf20Sopenharmony_ci{ 34408c2ecf20Sopenharmony_ci int err = 0; 34418c2ecf20Sopenharmony_ci 34428c2ecf20Sopenharmony_ci if (netif_running(dev)) { 34438c2ecf20Sopenharmony_ci err = sky2_open(dev); 34448c2ecf20Sopenharmony_ci if (err) { 34458c2ecf20Sopenharmony_ci netdev_info(dev, "could not restart %d\n", err); 34468c2ecf20Sopenharmony_ci dev_close(dev); 34478c2ecf20Sopenharmony_ci } else { 34488c2ecf20Sopenharmony_ci netif_device_attach(dev); 34498c2ecf20Sopenharmony_ci sky2_set_multicast(dev); 34508c2ecf20Sopenharmony_ci } 34518c2ecf20Sopenharmony_ci } 34528c2ecf20Sopenharmony_ci 34538c2ecf20Sopenharmony_ci return err; 34548c2ecf20Sopenharmony_ci} 34558c2ecf20Sopenharmony_ci 34568c2ecf20Sopenharmony_cistatic void sky2_all_down(struct sky2_hw *hw) 34578c2ecf20Sopenharmony_ci{ 34588c2ecf20Sopenharmony_ci int i; 34598c2ecf20Sopenharmony_ci 34608c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_IRQ_SETUP) { 34618c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, 0); 34628c2ecf20Sopenharmony_ci sky2_read32(hw, B0_IMSK); 34638c2ecf20Sopenharmony_ci 34648c2ecf20Sopenharmony_ci synchronize_irq(hw->pdev->irq); 34658c2ecf20Sopenharmony_ci napi_disable(&hw->napi); 34668c2ecf20Sopenharmony_ci } 34678c2ecf20Sopenharmony_ci 34688c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 34698c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[i]; 34708c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 34718c2ecf20Sopenharmony_ci 34728c2ecf20Sopenharmony_ci if (!netif_running(dev)) 34738c2ecf20Sopenharmony_ci continue; 34748c2ecf20Sopenharmony_ci 34758c2ecf20Sopenharmony_ci netif_carrier_off(dev); 34768c2ecf20Sopenharmony_ci netif_tx_disable(dev); 34778c2ecf20Sopenharmony_ci sky2_hw_down(sky2); 34788c2ecf20Sopenharmony_ci } 34798c2ecf20Sopenharmony_ci} 34808c2ecf20Sopenharmony_ci 34818c2ecf20Sopenharmony_cistatic void sky2_all_up(struct sky2_hw *hw) 34828c2ecf20Sopenharmony_ci{ 34838c2ecf20Sopenharmony_ci u32 imask = Y2_IS_BASE; 34848c2ecf20Sopenharmony_ci int i; 34858c2ecf20Sopenharmony_ci 34868c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 34878c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[i]; 34888c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 34898c2ecf20Sopenharmony_ci 34908c2ecf20Sopenharmony_ci if (!netif_running(dev)) 34918c2ecf20Sopenharmony_ci continue; 34928c2ecf20Sopenharmony_ci 34938c2ecf20Sopenharmony_ci sky2_hw_up(sky2); 34948c2ecf20Sopenharmony_ci sky2_set_multicast(dev); 34958c2ecf20Sopenharmony_ci imask |= portirq_msk[i]; 34968c2ecf20Sopenharmony_ci netif_wake_queue(dev); 34978c2ecf20Sopenharmony_ci } 34988c2ecf20Sopenharmony_ci 34998c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_IRQ_SETUP) { 35008c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, imask); 35018c2ecf20Sopenharmony_ci sky2_read32(hw, B0_IMSK); 35028c2ecf20Sopenharmony_ci sky2_read32(hw, B0_Y2_SP_LISR); 35038c2ecf20Sopenharmony_ci napi_enable(&hw->napi); 35048c2ecf20Sopenharmony_ci } 35058c2ecf20Sopenharmony_ci} 35068c2ecf20Sopenharmony_ci 35078c2ecf20Sopenharmony_cistatic void sky2_restart(struct work_struct *work) 35088c2ecf20Sopenharmony_ci{ 35098c2ecf20Sopenharmony_ci struct sky2_hw *hw = container_of(work, struct sky2_hw, restart_work); 35108c2ecf20Sopenharmony_ci 35118c2ecf20Sopenharmony_ci rtnl_lock(); 35128c2ecf20Sopenharmony_ci 35138c2ecf20Sopenharmony_ci sky2_all_down(hw); 35148c2ecf20Sopenharmony_ci sky2_reset(hw); 35158c2ecf20Sopenharmony_ci sky2_all_up(hw); 35168c2ecf20Sopenharmony_ci 35178c2ecf20Sopenharmony_ci rtnl_unlock(); 35188c2ecf20Sopenharmony_ci} 35198c2ecf20Sopenharmony_ci 35208c2ecf20Sopenharmony_cistatic inline u8 sky2_wol_supported(const struct sky2_hw *hw) 35218c2ecf20Sopenharmony_ci{ 35228c2ecf20Sopenharmony_ci return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0; 35238c2ecf20Sopenharmony_ci} 35248c2ecf20Sopenharmony_ci 35258c2ecf20Sopenharmony_cistatic void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 35268c2ecf20Sopenharmony_ci{ 35278c2ecf20Sopenharmony_ci const struct sky2_port *sky2 = netdev_priv(dev); 35288c2ecf20Sopenharmony_ci 35298c2ecf20Sopenharmony_ci wol->supported = sky2_wol_supported(sky2->hw); 35308c2ecf20Sopenharmony_ci wol->wolopts = sky2->wol; 35318c2ecf20Sopenharmony_ci} 35328c2ecf20Sopenharmony_ci 35338c2ecf20Sopenharmony_cistatic int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 35348c2ecf20Sopenharmony_ci{ 35358c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 35368c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 35378c2ecf20Sopenharmony_ci bool enable_wakeup = false; 35388c2ecf20Sopenharmony_ci int i; 35398c2ecf20Sopenharmony_ci 35408c2ecf20Sopenharmony_ci if ((wol->wolopts & ~sky2_wol_supported(sky2->hw)) || 35418c2ecf20Sopenharmony_ci !device_can_wakeup(&hw->pdev->dev)) 35428c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 35438c2ecf20Sopenharmony_ci 35448c2ecf20Sopenharmony_ci sky2->wol = wol->wolopts; 35458c2ecf20Sopenharmony_ci 35468c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 35478c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[i]; 35488c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 35498c2ecf20Sopenharmony_ci 35508c2ecf20Sopenharmony_ci if (sky2->wol) 35518c2ecf20Sopenharmony_ci enable_wakeup = true; 35528c2ecf20Sopenharmony_ci } 35538c2ecf20Sopenharmony_ci device_set_wakeup_enable(&hw->pdev->dev, enable_wakeup); 35548c2ecf20Sopenharmony_ci 35558c2ecf20Sopenharmony_ci return 0; 35568c2ecf20Sopenharmony_ci} 35578c2ecf20Sopenharmony_ci 35588c2ecf20Sopenharmony_cistatic u32 sky2_supported_modes(const struct sky2_hw *hw) 35598c2ecf20Sopenharmony_ci{ 35608c2ecf20Sopenharmony_ci if (sky2_is_copper(hw)) { 35618c2ecf20Sopenharmony_ci u32 modes = SUPPORTED_10baseT_Half 35628c2ecf20Sopenharmony_ci | SUPPORTED_10baseT_Full 35638c2ecf20Sopenharmony_ci | SUPPORTED_100baseT_Half 35648c2ecf20Sopenharmony_ci | SUPPORTED_100baseT_Full; 35658c2ecf20Sopenharmony_ci 35668c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_GIGABIT) 35678c2ecf20Sopenharmony_ci modes |= SUPPORTED_1000baseT_Half 35688c2ecf20Sopenharmony_ci | SUPPORTED_1000baseT_Full; 35698c2ecf20Sopenharmony_ci return modes; 35708c2ecf20Sopenharmony_ci } else 35718c2ecf20Sopenharmony_ci return SUPPORTED_1000baseT_Half 35728c2ecf20Sopenharmony_ci | SUPPORTED_1000baseT_Full; 35738c2ecf20Sopenharmony_ci} 35748c2ecf20Sopenharmony_ci 35758c2ecf20Sopenharmony_cistatic int sky2_get_link_ksettings(struct net_device *dev, 35768c2ecf20Sopenharmony_ci struct ethtool_link_ksettings *cmd) 35778c2ecf20Sopenharmony_ci{ 35788c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 35798c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 35808c2ecf20Sopenharmony_ci u32 supported, advertising; 35818c2ecf20Sopenharmony_ci 35828c2ecf20Sopenharmony_ci supported = sky2_supported_modes(hw); 35838c2ecf20Sopenharmony_ci cmd->base.phy_address = PHY_ADDR_MARV; 35848c2ecf20Sopenharmony_ci if (sky2_is_copper(hw)) { 35858c2ecf20Sopenharmony_ci cmd->base.port = PORT_TP; 35868c2ecf20Sopenharmony_ci cmd->base.speed = sky2->speed; 35878c2ecf20Sopenharmony_ci supported |= SUPPORTED_Autoneg | SUPPORTED_TP; 35888c2ecf20Sopenharmony_ci } else { 35898c2ecf20Sopenharmony_ci cmd->base.speed = SPEED_1000; 35908c2ecf20Sopenharmony_ci cmd->base.port = PORT_FIBRE; 35918c2ecf20Sopenharmony_ci supported |= SUPPORTED_Autoneg | SUPPORTED_FIBRE; 35928c2ecf20Sopenharmony_ci } 35938c2ecf20Sopenharmony_ci 35948c2ecf20Sopenharmony_ci advertising = sky2->advertising; 35958c2ecf20Sopenharmony_ci cmd->base.autoneg = (sky2->flags & SKY2_FLAG_AUTO_SPEED) 35968c2ecf20Sopenharmony_ci ? AUTONEG_ENABLE : AUTONEG_DISABLE; 35978c2ecf20Sopenharmony_ci cmd->base.duplex = sky2->duplex; 35988c2ecf20Sopenharmony_ci 35998c2ecf20Sopenharmony_ci ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, 36008c2ecf20Sopenharmony_ci supported); 36018c2ecf20Sopenharmony_ci ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, 36028c2ecf20Sopenharmony_ci advertising); 36038c2ecf20Sopenharmony_ci 36048c2ecf20Sopenharmony_ci return 0; 36058c2ecf20Sopenharmony_ci} 36068c2ecf20Sopenharmony_ci 36078c2ecf20Sopenharmony_cistatic int sky2_set_link_ksettings(struct net_device *dev, 36088c2ecf20Sopenharmony_ci const struct ethtool_link_ksettings *cmd) 36098c2ecf20Sopenharmony_ci{ 36108c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 36118c2ecf20Sopenharmony_ci const struct sky2_hw *hw = sky2->hw; 36128c2ecf20Sopenharmony_ci u32 supported = sky2_supported_modes(hw); 36138c2ecf20Sopenharmony_ci u32 new_advertising; 36148c2ecf20Sopenharmony_ci 36158c2ecf20Sopenharmony_ci ethtool_convert_link_mode_to_legacy_u32(&new_advertising, 36168c2ecf20Sopenharmony_ci cmd->link_modes.advertising); 36178c2ecf20Sopenharmony_ci 36188c2ecf20Sopenharmony_ci if (cmd->base.autoneg == AUTONEG_ENABLE) { 36198c2ecf20Sopenharmony_ci if (new_advertising & ~supported) 36208c2ecf20Sopenharmony_ci return -EINVAL; 36218c2ecf20Sopenharmony_ci 36228c2ecf20Sopenharmony_ci if (sky2_is_copper(hw)) 36238c2ecf20Sopenharmony_ci sky2->advertising = new_advertising | 36248c2ecf20Sopenharmony_ci ADVERTISED_TP | 36258c2ecf20Sopenharmony_ci ADVERTISED_Autoneg; 36268c2ecf20Sopenharmony_ci else 36278c2ecf20Sopenharmony_ci sky2->advertising = new_advertising | 36288c2ecf20Sopenharmony_ci ADVERTISED_FIBRE | 36298c2ecf20Sopenharmony_ci ADVERTISED_Autoneg; 36308c2ecf20Sopenharmony_ci 36318c2ecf20Sopenharmony_ci sky2->flags |= SKY2_FLAG_AUTO_SPEED; 36328c2ecf20Sopenharmony_ci sky2->duplex = -1; 36338c2ecf20Sopenharmony_ci sky2->speed = -1; 36348c2ecf20Sopenharmony_ci } else { 36358c2ecf20Sopenharmony_ci u32 setting; 36368c2ecf20Sopenharmony_ci u32 speed = cmd->base.speed; 36378c2ecf20Sopenharmony_ci 36388c2ecf20Sopenharmony_ci switch (speed) { 36398c2ecf20Sopenharmony_ci case SPEED_1000: 36408c2ecf20Sopenharmony_ci if (cmd->base.duplex == DUPLEX_FULL) 36418c2ecf20Sopenharmony_ci setting = SUPPORTED_1000baseT_Full; 36428c2ecf20Sopenharmony_ci else if (cmd->base.duplex == DUPLEX_HALF) 36438c2ecf20Sopenharmony_ci setting = SUPPORTED_1000baseT_Half; 36448c2ecf20Sopenharmony_ci else 36458c2ecf20Sopenharmony_ci return -EINVAL; 36468c2ecf20Sopenharmony_ci break; 36478c2ecf20Sopenharmony_ci case SPEED_100: 36488c2ecf20Sopenharmony_ci if (cmd->base.duplex == DUPLEX_FULL) 36498c2ecf20Sopenharmony_ci setting = SUPPORTED_100baseT_Full; 36508c2ecf20Sopenharmony_ci else if (cmd->base.duplex == DUPLEX_HALF) 36518c2ecf20Sopenharmony_ci setting = SUPPORTED_100baseT_Half; 36528c2ecf20Sopenharmony_ci else 36538c2ecf20Sopenharmony_ci return -EINVAL; 36548c2ecf20Sopenharmony_ci break; 36558c2ecf20Sopenharmony_ci 36568c2ecf20Sopenharmony_ci case SPEED_10: 36578c2ecf20Sopenharmony_ci if (cmd->base.duplex == DUPLEX_FULL) 36588c2ecf20Sopenharmony_ci setting = SUPPORTED_10baseT_Full; 36598c2ecf20Sopenharmony_ci else if (cmd->base.duplex == DUPLEX_HALF) 36608c2ecf20Sopenharmony_ci setting = SUPPORTED_10baseT_Half; 36618c2ecf20Sopenharmony_ci else 36628c2ecf20Sopenharmony_ci return -EINVAL; 36638c2ecf20Sopenharmony_ci break; 36648c2ecf20Sopenharmony_ci default: 36658c2ecf20Sopenharmony_ci return -EINVAL; 36668c2ecf20Sopenharmony_ci } 36678c2ecf20Sopenharmony_ci 36688c2ecf20Sopenharmony_ci if ((setting & supported) == 0) 36698c2ecf20Sopenharmony_ci return -EINVAL; 36708c2ecf20Sopenharmony_ci 36718c2ecf20Sopenharmony_ci sky2->speed = speed; 36728c2ecf20Sopenharmony_ci sky2->duplex = cmd->base.duplex; 36738c2ecf20Sopenharmony_ci sky2->flags &= ~SKY2_FLAG_AUTO_SPEED; 36748c2ecf20Sopenharmony_ci } 36758c2ecf20Sopenharmony_ci 36768c2ecf20Sopenharmony_ci if (netif_running(dev)) { 36778c2ecf20Sopenharmony_ci sky2_phy_reinit(sky2); 36788c2ecf20Sopenharmony_ci sky2_set_multicast(dev); 36798c2ecf20Sopenharmony_ci } 36808c2ecf20Sopenharmony_ci 36818c2ecf20Sopenharmony_ci return 0; 36828c2ecf20Sopenharmony_ci} 36838c2ecf20Sopenharmony_ci 36848c2ecf20Sopenharmony_cistatic void sky2_get_drvinfo(struct net_device *dev, 36858c2ecf20Sopenharmony_ci struct ethtool_drvinfo *info) 36868c2ecf20Sopenharmony_ci{ 36878c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 36888c2ecf20Sopenharmony_ci 36898c2ecf20Sopenharmony_ci strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); 36908c2ecf20Sopenharmony_ci strlcpy(info->version, DRV_VERSION, sizeof(info->version)); 36918c2ecf20Sopenharmony_ci strlcpy(info->bus_info, pci_name(sky2->hw->pdev), 36928c2ecf20Sopenharmony_ci sizeof(info->bus_info)); 36938c2ecf20Sopenharmony_ci} 36948c2ecf20Sopenharmony_ci 36958c2ecf20Sopenharmony_cistatic const struct sky2_stat { 36968c2ecf20Sopenharmony_ci char name[ETH_GSTRING_LEN]; 36978c2ecf20Sopenharmony_ci u16 offset; 36988c2ecf20Sopenharmony_ci} sky2_stats[] = { 36998c2ecf20Sopenharmony_ci { "tx_bytes", GM_TXO_OK_HI }, 37008c2ecf20Sopenharmony_ci { "rx_bytes", GM_RXO_OK_HI }, 37018c2ecf20Sopenharmony_ci { "tx_broadcast", GM_TXF_BC_OK }, 37028c2ecf20Sopenharmony_ci { "rx_broadcast", GM_RXF_BC_OK }, 37038c2ecf20Sopenharmony_ci { "tx_multicast", GM_TXF_MC_OK }, 37048c2ecf20Sopenharmony_ci { "rx_multicast", GM_RXF_MC_OK }, 37058c2ecf20Sopenharmony_ci { "tx_unicast", GM_TXF_UC_OK }, 37068c2ecf20Sopenharmony_ci { "rx_unicast", GM_RXF_UC_OK }, 37078c2ecf20Sopenharmony_ci { "tx_mac_pause", GM_TXF_MPAUSE }, 37088c2ecf20Sopenharmony_ci { "rx_mac_pause", GM_RXF_MPAUSE }, 37098c2ecf20Sopenharmony_ci { "collisions", GM_TXF_COL }, 37108c2ecf20Sopenharmony_ci { "late_collision",GM_TXF_LAT_COL }, 37118c2ecf20Sopenharmony_ci { "aborted", GM_TXF_ABO_COL }, 37128c2ecf20Sopenharmony_ci { "single_collisions", GM_TXF_SNG_COL }, 37138c2ecf20Sopenharmony_ci { "multi_collisions", GM_TXF_MUL_COL }, 37148c2ecf20Sopenharmony_ci 37158c2ecf20Sopenharmony_ci { "rx_short", GM_RXF_SHT }, 37168c2ecf20Sopenharmony_ci { "rx_runt", GM_RXE_FRAG }, 37178c2ecf20Sopenharmony_ci { "rx_64_byte_packets", GM_RXF_64B }, 37188c2ecf20Sopenharmony_ci { "rx_65_to_127_byte_packets", GM_RXF_127B }, 37198c2ecf20Sopenharmony_ci { "rx_128_to_255_byte_packets", GM_RXF_255B }, 37208c2ecf20Sopenharmony_ci { "rx_256_to_511_byte_packets", GM_RXF_511B }, 37218c2ecf20Sopenharmony_ci { "rx_512_to_1023_byte_packets", GM_RXF_1023B }, 37228c2ecf20Sopenharmony_ci { "rx_1024_to_1518_byte_packets", GM_RXF_1518B }, 37238c2ecf20Sopenharmony_ci { "rx_1518_to_max_byte_packets", GM_RXF_MAX_SZ }, 37248c2ecf20Sopenharmony_ci { "rx_too_long", GM_RXF_LNG_ERR }, 37258c2ecf20Sopenharmony_ci { "rx_fifo_overflow", GM_RXE_FIFO_OV }, 37268c2ecf20Sopenharmony_ci { "rx_jabber", GM_RXF_JAB_PKT }, 37278c2ecf20Sopenharmony_ci { "rx_fcs_error", GM_RXF_FCS_ERR }, 37288c2ecf20Sopenharmony_ci 37298c2ecf20Sopenharmony_ci { "tx_64_byte_packets", GM_TXF_64B }, 37308c2ecf20Sopenharmony_ci { "tx_65_to_127_byte_packets", GM_TXF_127B }, 37318c2ecf20Sopenharmony_ci { "tx_128_to_255_byte_packets", GM_TXF_255B }, 37328c2ecf20Sopenharmony_ci { "tx_256_to_511_byte_packets", GM_TXF_511B }, 37338c2ecf20Sopenharmony_ci { "tx_512_to_1023_byte_packets", GM_TXF_1023B }, 37348c2ecf20Sopenharmony_ci { "tx_1024_to_1518_byte_packets", GM_TXF_1518B }, 37358c2ecf20Sopenharmony_ci { "tx_1519_to_max_byte_packets", GM_TXF_MAX_SZ }, 37368c2ecf20Sopenharmony_ci { "tx_fifo_underrun", GM_TXE_FIFO_UR }, 37378c2ecf20Sopenharmony_ci}; 37388c2ecf20Sopenharmony_ci 37398c2ecf20Sopenharmony_cistatic u32 sky2_get_msglevel(struct net_device *netdev) 37408c2ecf20Sopenharmony_ci{ 37418c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(netdev); 37428c2ecf20Sopenharmony_ci return sky2->msg_enable; 37438c2ecf20Sopenharmony_ci} 37448c2ecf20Sopenharmony_ci 37458c2ecf20Sopenharmony_cistatic int sky2_nway_reset(struct net_device *dev) 37468c2ecf20Sopenharmony_ci{ 37478c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 37488c2ecf20Sopenharmony_ci 37498c2ecf20Sopenharmony_ci if (!netif_running(dev) || !(sky2->flags & SKY2_FLAG_AUTO_SPEED)) 37508c2ecf20Sopenharmony_ci return -EINVAL; 37518c2ecf20Sopenharmony_ci 37528c2ecf20Sopenharmony_ci sky2_phy_reinit(sky2); 37538c2ecf20Sopenharmony_ci sky2_set_multicast(dev); 37548c2ecf20Sopenharmony_ci 37558c2ecf20Sopenharmony_ci return 0; 37568c2ecf20Sopenharmony_ci} 37578c2ecf20Sopenharmony_ci 37588c2ecf20Sopenharmony_cistatic void sky2_phy_stats(struct sky2_port *sky2, u64 * data, unsigned count) 37598c2ecf20Sopenharmony_ci{ 37608c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 37618c2ecf20Sopenharmony_ci unsigned port = sky2->port; 37628c2ecf20Sopenharmony_ci int i; 37638c2ecf20Sopenharmony_ci 37648c2ecf20Sopenharmony_ci data[0] = get_stats64(hw, port, GM_TXO_OK_LO); 37658c2ecf20Sopenharmony_ci data[1] = get_stats64(hw, port, GM_RXO_OK_LO); 37668c2ecf20Sopenharmony_ci 37678c2ecf20Sopenharmony_ci for (i = 2; i < count; i++) 37688c2ecf20Sopenharmony_ci data[i] = get_stats32(hw, port, sky2_stats[i].offset); 37698c2ecf20Sopenharmony_ci} 37708c2ecf20Sopenharmony_ci 37718c2ecf20Sopenharmony_cistatic void sky2_set_msglevel(struct net_device *netdev, u32 value) 37728c2ecf20Sopenharmony_ci{ 37738c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(netdev); 37748c2ecf20Sopenharmony_ci sky2->msg_enable = value; 37758c2ecf20Sopenharmony_ci} 37768c2ecf20Sopenharmony_ci 37778c2ecf20Sopenharmony_cistatic int sky2_get_sset_count(struct net_device *dev, int sset) 37788c2ecf20Sopenharmony_ci{ 37798c2ecf20Sopenharmony_ci switch (sset) { 37808c2ecf20Sopenharmony_ci case ETH_SS_STATS: 37818c2ecf20Sopenharmony_ci return ARRAY_SIZE(sky2_stats); 37828c2ecf20Sopenharmony_ci default: 37838c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 37848c2ecf20Sopenharmony_ci } 37858c2ecf20Sopenharmony_ci} 37868c2ecf20Sopenharmony_ci 37878c2ecf20Sopenharmony_cistatic void sky2_get_ethtool_stats(struct net_device *dev, 37888c2ecf20Sopenharmony_ci struct ethtool_stats *stats, u64 * data) 37898c2ecf20Sopenharmony_ci{ 37908c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 37918c2ecf20Sopenharmony_ci 37928c2ecf20Sopenharmony_ci sky2_phy_stats(sky2, data, ARRAY_SIZE(sky2_stats)); 37938c2ecf20Sopenharmony_ci} 37948c2ecf20Sopenharmony_ci 37958c2ecf20Sopenharmony_cistatic void sky2_get_strings(struct net_device *dev, u32 stringset, u8 * data) 37968c2ecf20Sopenharmony_ci{ 37978c2ecf20Sopenharmony_ci int i; 37988c2ecf20Sopenharmony_ci 37998c2ecf20Sopenharmony_ci switch (stringset) { 38008c2ecf20Sopenharmony_ci case ETH_SS_STATS: 38018c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(sky2_stats); i++) 38028c2ecf20Sopenharmony_ci memcpy(data + i * ETH_GSTRING_LEN, 38038c2ecf20Sopenharmony_ci sky2_stats[i].name, ETH_GSTRING_LEN); 38048c2ecf20Sopenharmony_ci break; 38058c2ecf20Sopenharmony_ci } 38068c2ecf20Sopenharmony_ci} 38078c2ecf20Sopenharmony_ci 38088c2ecf20Sopenharmony_cistatic int sky2_set_mac_address(struct net_device *dev, void *p) 38098c2ecf20Sopenharmony_ci{ 38108c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 38118c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 38128c2ecf20Sopenharmony_ci unsigned port = sky2->port; 38138c2ecf20Sopenharmony_ci const struct sockaddr *addr = p; 38148c2ecf20Sopenharmony_ci 38158c2ecf20Sopenharmony_ci if (!is_valid_ether_addr(addr->sa_data)) 38168c2ecf20Sopenharmony_ci return -EADDRNOTAVAIL; 38178c2ecf20Sopenharmony_ci 38188c2ecf20Sopenharmony_ci memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); 38198c2ecf20Sopenharmony_ci memcpy_toio(hw->regs + B2_MAC_1 + port * 8, 38208c2ecf20Sopenharmony_ci dev->dev_addr, ETH_ALEN); 38218c2ecf20Sopenharmony_ci memcpy_toio(hw->regs + B2_MAC_2 + port * 8, 38228c2ecf20Sopenharmony_ci dev->dev_addr, ETH_ALEN); 38238c2ecf20Sopenharmony_ci 38248c2ecf20Sopenharmony_ci /* virtual address for data */ 38258c2ecf20Sopenharmony_ci gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr); 38268c2ecf20Sopenharmony_ci 38278c2ecf20Sopenharmony_ci /* physical address: used for pause frames */ 38288c2ecf20Sopenharmony_ci gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr); 38298c2ecf20Sopenharmony_ci 38308c2ecf20Sopenharmony_ci return 0; 38318c2ecf20Sopenharmony_ci} 38328c2ecf20Sopenharmony_ci 38338c2ecf20Sopenharmony_cistatic inline void sky2_add_filter(u8 filter[8], const u8 *addr) 38348c2ecf20Sopenharmony_ci{ 38358c2ecf20Sopenharmony_ci u32 bit; 38368c2ecf20Sopenharmony_ci 38378c2ecf20Sopenharmony_ci bit = ether_crc(ETH_ALEN, addr) & 63; 38388c2ecf20Sopenharmony_ci filter[bit >> 3] |= 1 << (bit & 7); 38398c2ecf20Sopenharmony_ci} 38408c2ecf20Sopenharmony_ci 38418c2ecf20Sopenharmony_cistatic void sky2_set_multicast(struct net_device *dev) 38428c2ecf20Sopenharmony_ci{ 38438c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 38448c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 38458c2ecf20Sopenharmony_ci unsigned port = sky2->port; 38468c2ecf20Sopenharmony_ci struct netdev_hw_addr *ha; 38478c2ecf20Sopenharmony_ci u16 reg; 38488c2ecf20Sopenharmony_ci u8 filter[8]; 38498c2ecf20Sopenharmony_ci int rx_pause; 38508c2ecf20Sopenharmony_ci static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 }; 38518c2ecf20Sopenharmony_ci 38528c2ecf20Sopenharmony_ci rx_pause = (sky2->flow_status == FC_RX || sky2->flow_status == FC_BOTH); 38538c2ecf20Sopenharmony_ci memset(filter, 0, sizeof(filter)); 38548c2ecf20Sopenharmony_ci 38558c2ecf20Sopenharmony_ci reg = gma_read16(hw, port, GM_RX_CTRL); 38568c2ecf20Sopenharmony_ci reg |= GM_RXCR_UCF_ENA; 38578c2ecf20Sopenharmony_ci 38588c2ecf20Sopenharmony_ci if (dev->flags & IFF_PROMISC) /* promiscuous */ 38598c2ecf20Sopenharmony_ci reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); 38608c2ecf20Sopenharmony_ci else if (dev->flags & IFF_ALLMULTI) 38618c2ecf20Sopenharmony_ci memset(filter, 0xff, sizeof(filter)); 38628c2ecf20Sopenharmony_ci else if (netdev_mc_empty(dev) && !rx_pause) 38638c2ecf20Sopenharmony_ci reg &= ~GM_RXCR_MCF_ENA; 38648c2ecf20Sopenharmony_ci else { 38658c2ecf20Sopenharmony_ci reg |= GM_RXCR_MCF_ENA; 38668c2ecf20Sopenharmony_ci 38678c2ecf20Sopenharmony_ci if (rx_pause) 38688c2ecf20Sopenharmony_ci sky2_add_filter(filter, pause_mc_addr); 38698c2ecf20Sopenharmony_ci 38708c2ecf20Sopenharmony_ci netdev_for_each_mc_addr(ha, dev) 38718c2ecf20Sopenharmony_ci sky2_add_filter(filter, ha->addr); 38728c2ecf20Sopenharmony_ci } 38738c2ecf20Sopenharmony_ci 38748c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H1, 38758c2ecf20Sopenharmony_ci (u16) filter[0] | ((u16) filter[1] << 8)); 38768c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H2, 38778c2ecf20Sopenharmony_ci (u16) filter[2] | ((u16) filter[3] << 8)); 38788c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H3, 38798c2ecf20Sopenharmony_ci (u16) filter[4] | ((u16) filter[5] << 8)); 38808c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_MC_ADDR_H4, 38818c2ecf20Sopenharmony_ci (u16) filter[6] | ((u16) filter[7] << 8)); 38828c2ecf20Sopenharmony_ci 38838c2ecf20Sopenharmony_ci gma_write16(hw, port, GM_RX_CTRL, reg); 38848c2ecf20Sopenharmony_ci} 38858c2ecf20Sopenharmony_ci 38868c2ecf20Sopenharmony_cistatic void sky2_get_stats(struct net_device *dev, 38878c2ecf20Sopenharmony_ci struct rtnl_link_stats64 *stats) 38888c2ecf20Sopenharmony_ci{ 38898c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 38908c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 38918c2ecf20Sopenharmony_ci unsigned port = sky2->port; 38928c2ecf20Sopenharmony_ci unsigned int start; 38938c2ecf20Sopenharmony_ci u64 _bytes, _packets; 38948c2ecf20Sopenharmony_ci 38958c2ecf20Sopenharmony_ci do { 38968c2ecf20Sopenharmony_ci start = u64_stats_fetch_begin_irq(&sky2->rx_stats.syncp); 38978c2ecf20Sopenharmony_ci _bytes = sky2->rx_stats.bytes; 38988c2ecf20Sopenharmony_ci _packets = sky2->rx_stats.packets; 38998c2ecf20Sopenharmony_ci } while (u64_stats_fetch_retry_irq(&sky2->rx_stats.syncp, start)); 39008c2ecf20Sopenharmony_ci 39018c2ecf20Sopenharmony_ci stats->rx_packets = _packets; 39028c2ecf20Sopenharmony_ci stats->rx_bytes = _bytes; 39038c2ecf20Sopenharmony_ci 39048c2ecf20Sopenharmony_ci do { 39058c2ecf20Sopenharmony_ci start = u64_stats_fetch_begin_irq(&sky2->tx_stats.syncp); 39068c2ecf20Sopenharmony_ci _bytes = sky2->tx_stats.bytes; 39078c2ecf20Sopenharmony_ci _packets = sky2->tx_stats.packets; 39088c2ecf20Sopenharmony_ci } while (u64_stats_fetch_retry_irq(&sky2->tx_stats.syncp, start)); 39098c2ecf20Sopenharmony_ci 39108c2ecf20Sopenharmony_ci stats->tx_packets = _packets; 39118c2ecf20Sopenharmony_ci stats->tx_bytes = _bytes; 39128c2ecf20Sopenharmony_ci 39138c2ecf20Sopenharmony_ci stats->multicast = get_stats32(hw, port, GM_RXF_MC_OK) 39148c2ecf20Sopenharmony_ci + get_stats32(hw, port, GM_RXF_BC_OK); 39158c2ecf20Sopenharmony_ci 39168c2ecf20Sopenharmony_ci stats->collisions = get_stats32(hw, port, GM_TXF_COL); 39178c2ecf20Sopenharmony_ci 39188c2ecf20Sopenharmony_ci stats->rx_length_errors = get_stats32(hw, port, GM_RXF_LNG_ERR); 39198c2ecf20Sopenharmony_ci stats->rx_crc_errors = get_stats32(hw, port, GM_RXF_FCS_ERR); 39208c2ecf20Sopenharmony_ci stats->rx_frame_errors = get_stats32(hw, port, GM_RXF_SHT) 39218c2ecf20Sopenharmony_ci + get_stats32(hw, port, GM_RXE_FRAG); 39228c2ecf20Sopenharmony_ci stats->rx_over_errors = get_stats32(hw, port, GM_RXE_FIFO_OV); 39238c2ecf20Sopenharmony_ci 39248c2ecf20Sopenharmony_ci stats->rx_dropped = dev->stats.rx_dropped; 39258c2ecf20Sopenharmony_ci stats->rx_fifo_errors = dev->stats.rx_fifo_errors; 39268c2ecf20Sopenharmony_ci stats->tx_fifo_errors = dev->stats.tx_fifo_errors; 39278c2ecf20Sopenharmony_ci} 39288c2ecf20Sopenharmony_ci 39298c2ecf20Sopenharmony_ci/* Can have one global because blinking is controlled by 39308c2ecf20Sopenharmony_ci * ethtool and that is always under RTNL mutex 39318c2ecf20Sopenharmony_ci */ 39328c2ecf20Sopenharmony_cistatic void sky2_led(struct sky2_port *sky2, enum led_mode mode) 39338c2ecf20Sopenharmony_ci{ 39348c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 39358c2ecf20Sopenharmony_ci unsigned port = sky2->port; 39368c2ecf20Sopenharmony_ci 39378c2ecf20Sopenharmony_ci spin_lock_bh(&sky2->phy_lock); 39388c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_EC_U || 39398c2ecf20Sopenharmony_ci hw->chip_id == CHIP_ID_YUKON_EX || 39408c2ecf20Sopenharmony_ci hw->chip_id == CHIP_ID_YUKON_SUPR) { 39418c2ecf20Sopenharmony_ci u16 pg; 39428c2ecf20Sopenharmony_ci pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); 39438c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); 39448c2ecf20Sopenharmony_ci 39458c2ecf20Sopenharmony_ci switch (mode) { 39468c2ecf20Sopenharmony_ci case MO_LED_OFF: 39478c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, 39488c2ecf20Sopenharmony_ci PHY_M_LEDC_LOS_CTRL(8) | 39498c2ecf20Sopenharmony_ci PHY_M_LEDC_INIT_CTRL(8) | 39508c2ecf20Sopenharmony_ci PHY_M_LEDC_STA1_CTRL(8) | 39518c2ecf20Sopenharmony_ci PHY_M_LEDC_STA0_CTRL(8)); 39528c2ecf20Sopenharmony_ci break; 39538c2ecf20Sopenharmony_ci case MO_LED_ON: 39548c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, 39558c2ecf20Sopenharmony_ci PHY_M_LEDC_LOS_CTRL(9) | 39568c2ecf20Sopenharmony_ci PHY_M_LEDC_INIT_CTRL(9) | 39578c2ecf20Sopenharmony_ci PHY_M_LEDC_STA1_CTRL(9) | 39588c2ecf20Sopenharmony_ci PHY_M_LEDC_STA0_CTRL(9)); 39598c2ecf20Sopenharmony_ci break; 39608c2ecf20Sopenharmony_ci case MO_LED_BLINK: 39618c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, 39628c2ecf20Sopenharmony_ci PHY_M_LEDC_LOS_CTRL(0xa) | 39638c2ecf20Sopenharmony_ci PHY_M_LEDC_INIT_CTRL(0xa) | 39648c2ecf20Sopenharmony_ci PHY_M_LEDC_STA1_CTRL(0xa) | 39658c2ecf20Sopenharmony_ci PHY_M_LEDC_STA0_CTRL(0xa)); 39668c2ecf20Sopenharmony_ci break; 39678c2ecf20Sopenharmony_ci case MO_LED_NORM: 39688c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, 39698c2ecf20Sopenharmony_ci PHY_M_LEDC_LOS_CTRL(1) | 39708c2ecf20Sopenharmony_ci PHY_M_LEDC_INIT_CTRL(8) | 39718c2ecf20Sopenharmony_ci PHY_M_LEDC_STA1_CTRL(7) | 39728c2ecf20Sopenharmony_ci PHY_M_LEDC_STA0_CTRL(7)); 39738c2ecf20Sopenharmony_ci } 39748c2ecf20Sopenharmony_ci 39758c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); 39768c2ecf20Sopenharmony_ci } else 39778c2ecf20Sopenharmony_ci gm_phy_write(hw, port, PHY_MARV_LED_OVER, 39788c2ecf20Sopenharmony_ci PHY_M_LED_MO_DUP(mode) | 39798c2ecf20Sopenharmony_ci PHY_M_LED_MO_10(mode) | 39808c2ecf20Sopenharmony_ci PHY_M_LED_MO_100(mode) | 39818c2ecf20Sopenharmony_ci PHY_M_LED_MO_1000(mode) | 39828c2ecf20Sopenharmony_ci PHY_M_LED_MO_RX(mode) | 39838c2ecf20Sopenharmony_ci PHY_M_LED_MO_TX(mode)); 39848c2ecf20Sopenharmony_ci 39858c2ecf20Sopenharmony_ci spin_unlock_bh(&sky2->phy_lock); 39868c2ecf20Sopenharmony_ci} 39878c2ecf20Sopenharmony_ci 39888c2ecf20Sopenharmony_ci/* blink LED's for finding board */ 39898c2ecf20Sopenharmony_cistatic int sky2_set_phys_id(struct net_device *dev, 39908c2ecf20Sopenharmony_ci enum ethtool_phys_id_state state) 39918c2ecf20Sopenharmony_ci{ 39928c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 39938c2ecf20Sopenharmony_ci 39948c2ecf20Sopenharmony_ci switch (state) { 39958c2ecf20Sopenharmony_ci case ETHTOOL_ID_ACTIVE: 39968c2ecf20Sopenharmony_ci return 1; /* cycle on/off once per second */ 39978c2ecf20Sopenharmony_ci case ETHTOOL_ID_INACTIVE: 39988c2ecf20Sopenharmony_ci sky2_led(sky2, MO_LED_NORM); 39998c2ecf20Sopenharmony_ci break; 40008c2ecf20Sopenharmony_ci case ETHTOOL_ID_ON: 40018c2ecf20Sopenharmony_ci sky2_led(sky2, MO_LED_ON); 40028c2ecf20Sopenharmony_ci break; 40038c2ecf20Sopenharmony_ci case ETHTOOL_ID_OFF: 40048c2ecf20Sopenharmony_ci sky2_led(sky2, MO_LED_OFF); 40058c2ecf20Sopenharmony_ci break; 40068c2ecf20Sopenharmony_ci } 40078c2ecf20Sopenharmony_ci 40088c2ecf20Sopenharmony_ci return 0; 40098c2ecf20Sopenharmony_ci} 40108c2ecf20Sopenharmony_ci 40118c2ecf20Sopenharmony_cistatic void sky2_get_pauseparam(struct net_device *dev, 40128c2ecf20Sopenharmony_ci struct ethtool_pauseparam *ecmd) 40138c2ecf20Sopenharmony_ci{ 40148c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 40158c2ecf20Sopenharmony_ci 40168c2ecf20Sopenharmony_ci switch (sky2->flow_mode) { 40178c2ecf20Sopenharmony_ci case FC_NONE: 40188c2ecf20Sopenharmony_ci ecmd->tx_pause = ecmd->rx_pause = 0; 40198c2ecf20Sopenharmony_ci break; 40208c2ecf20Sopenharmony_ci case FC_TX: 40218c2ecf20Sopenharmony_ci ecmd->tx_pause = 1, ecmd->rx_pause = 0; 40228c2ecf20Sopenharmony_ci break; 40238c2ecf20Sopenharmony_ci case FC_RX: 40248c2ecf20Sopenharmony_ci ecmd->tx_pause = 0, ecmd->rx_pause = 1; 40258c2ecf20Sopenharmony_ci break; 40268c2ecf20Sopenharmony_ci case FC_BOTH: 40278c2ecf20Sopenharmony_ci ecmd->tx_pause = ecmd->rx_pause = 1; 40288c2ecf20Sopenharmony_ci } 40298c2ecf20Sopenharmony_ci 40308c2ecf20Sopenharmony_ci ecmd->autoneg = (sky2->flags & SKY2_FLAG_AUTO_PAUSE) 40318c2ecf20Sopenharmony_ci ? AUTONEG_ENABLE : AUTONEG_DISABLE; 40328c2ecf20Sopenharmony_ci} 40338c2ecf20Sopenharmony_ci 40348c2ecf20Sopenharmony_cistatic int sky2_set_pauseparam(struct net_device *dev, 40358c2ecf20Sopenharmony_ci struct ethtool_pauseparam *ecmd) 40368c2ecf20Sopenharmony_ci{ 40378c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 40388c2ecf20Sopenharmony_ci 40398c2ecf20Sopenharmony_ci if (ecmd->autoneg == AUTONEG_ENABLE) 40408c2ecf20Sopenharmony_ci sky2->flags |= SKY2_FLAG_AUTO_PAUSE; 40418c2ecf20Sopenharmony_ci else 40428c2ecf20Sopenharmony_ci sky2->flags &= ~SKY2_FLAG_AUTO_PAUSE; 40438c2ecf20Sopenharmony_ci 40448c2ecf20Sopenharmony_ci sky2->flow_mode = sky2_flow(ecmd->rx_pause, ecmd->tx_pause); 40458c2ecf20Sopenharmony_ci 40468c2ecf20Sopenharmony_ci if (netif_running(dev)) 40478c2ecf20Sopenharmony_ci sky2_phy_reinit(sky2); 40488c2ecf20Sopenharmony_ci 40498c2ecf20Sopenharmony_ci return 0; 40508c2ecf20Sopenharmony_ci} 40518c2ecf20Sopenharmony_ci 40528c2ecf20Sopenharmony_cistatic int sky2_get_coalesce(struct net_device *dev, 40538c2ecf20Sopenharmony_ci struct ethtool_coalesce *ecmd) 40548c2ecf20Sopenharmony_ci{ 40558c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 40568c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 40578c2ecf20Sopenharmony_ci 40588c2ecf20Sopenharmony_ci if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_STOP) 40598c2ecf20Sopenharmony_ci ecmd->tx_coalesce_usecs = 0; 40608c2ecf20Sopenharmony_ci else { 40618c2ecf20Sopenharmony_ci u32 clks = sky2_read32(hw, STAT_TX_TIMER_INI); 40628c2ecf20Sopenharmony_ci ecmd->tx_coalesce_usecs = sky2_clk2us(hw, clks); 40638c2ecf20Sopenharmony_ci } 40648c2ecf20Sopenharmony_ci ecmd->tx_max_coalesced_frames = sky2_read16(hw, STAT_TX_IDX_TH); 40658c2ecf20Sopenharmony_ci 40668c2ecf20Sopenharmony_ci if (sky2_read8(hw, STAT_LEV_TIMER_CTRL) == TIM_STOP) 40678c2ecf20Sopenharmony_ci ecmd->rx_coalesce_usecs = 0; 40688c2ecf20Sopenharmony_ci else { 40698c2ecf20Sopenharmony_ci u32 clks = sky2_read32(hw, STAT_LEV_TIMER_INI); 40708c2ecf20Sopenharmony_ci ecmd->rx_coalesce_usecs = sky2_clk2us(hw, clks); 40718c2ecf20Sopenharmony_ci } 40728c2ecf20Sopenharmony_ci ecmd->rx_max_coalesced_frames = sky2_read8(hw, STAT_FIFO_WM); 40738c2ecf20Sopenharmony_ci 40748c2ecf20Sopenharmony_ci if (sky2_read8(hw, STAT_ISR_TIMER_CTRL) == TIM_STOP) 40758c2ecf20Sopenharmony_ci ecmd->rx_coalesce_usecs_irq = 0; 40768c2ecf20Sopenharmony_ci else { 40778c2ecf20Sopenharmony_ci u32 clks = sky2_read32(hw, STAT_ISR_TIMER_INI); 40788c2ecf20Sopenharmony_ci ecmd->rx_coalesce_usecs_irq = sky2_clk2us(hw, clks); 40798c2ecf20Sopenharmony_ci } 40808c2ecf20Sopenharmony_ci 40818c2ecf20Sopenharmony_ci ecmd->rx_max_coalesced_frames_irq = sky2_read8(hw, STAT_FIFO_ISR_WM); 40828c2ecf20Sopenharmony_ci 40838c2ecf20Sopenharmony_ci return 0; 40848c2ecf20Sopenharmony_ci} 40858c2ecf20Sopenharmony_ci 40868c2ecf20Sopenharmony_ci/* Note: this affect both ports */ 40878c2ecf20Sopenharmony_cistatic int sky2_set_coalesce(struct net_device *dev, 40888c2ecf20Sopenharmony_ci struct ethtool_coalesce *ecmd) 40898c2ecf20Sopenharmony_ci{ 40908c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 40918c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 40928c2ecf20Sopenharmony_ci const u32 tmax = sky2_clk2us(hw, 0x0ffffff); 40938c2ecf20Sopenharmony_ci 40948c2ecf20Sopenharmony_ci if (ecmd->tx_coalesce_usecs > tmax || 40958c2ecf20Sopenharmony_ci ecmd->rx_coalesce_usecs > tmax || 40968c2ecf20Sopenharmony_ci ecmd->rx_coalesce_usecs_irq > tmax) 40978c2ecf20Sopenharmony_ci return -EINVAL; 40988c2ecf20Sopenharmony_ci 40998c2ecf20Sopenharmony_ci if (ecmd->tx_max_coalesced_frames >= sky2->tx_ring_size-1) 41008c2ecf20Sopenharmony_ci return -EINVAL; 41018c2ecf20Sopenharmony_ci if (ecmd->rx_max_coalesced_frames > RX_MAX_PENDING) 41028c2ecf20Sopenharmony_ci return -EINVAL; 41038c2ecf20Sopenharmony_ci if (ecmd->rx_max_coalesced_frames_irq > RX_MAX_PENDING) 41048c2ecf20Sopenharmony_ci return -EINVAL; 41058c2ecf20Sopenharmony_ci 41068c2ecf20Sopenharmony_ci if (ecmd->tx_coalesce_usecs == 0) 41078c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP); 41088c2ecf20Sopenharmony_ci else { 41098c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_TX_TIMER_INI, 41108c2ecf20Sopenharmony_ci sky2_us2clk(hw, ecmd->tx_coalesce_usecs)); 41118c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START); 41128c2ecf20Sopenharmony_ci } 41138c2ecf20Sopenharmony_ci sky2_write16(hw, STAT_TX_IDX_TH, ecmd->tx_max_coalesced_frames); 41148c2ecf20Sopenharmony_ci 41158c2ecf20Sopenharmony_ci if (ecmd->rx_coalesce_usecs == 0) 41168c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_STOP); 41178c2ecf20Sopenharmony_ci else { 41188c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_LEV_TIMER_INI, 41198c2ecf20Sopenharmony_ci sky2_us2clk(hw, ecmd->rx_coalesce_usecs)); 41208c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START); 41218c2ecf20Sopenharmony_ci } 41228c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_FIFO_WM, ecmd->rx_max_coalesced_frames); 41238c2ecf20Sopenharmony_ci 41248c2ecf20Sopenharmony_ci if (ecmd->rx_coalesce_usecs_irq == 0) 41258c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_STOP); 41268c2ecf20Sopenharmony_ci else { 41278c2ecf20Sopenharmony_ci sky2_write32(hw, STAT_ISR_TIMER_INI, 41288c2ecf20Sopenharmony_ci sky2_us2clk(hw, ecmd->rx_coalesce_usecs_irq)); 41298c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START); 41308c2ecf20Sopenharmony_ci } 41318c2ecf20Sopenharmony_ci sky2_write8(hw, STAT_FIFO_ISR_WM, ecmd->rx_max_coalesced_frames_irq); 41328c2ecf20Sopenharmony_ci return 0; 41338c2ecf20Sopenharmony_ci} 41348c2ecf20Sopenharmony_ci 41358c2ecf20Sopenharmony_ci/* 41368c2ecf20Sopenharmony_ci * Hardware is limited to min of 128 and max of 2048 for ring size 41378c2ecf20Sopenharmony_ci * and rounded up to next power of two 41388c2ecf20Sopenharmony_ci * to avoid division in modulus calclation 41398c2ecf20Sopenharmony_ci */ 41408c2ecf20Sopenharmony_cistatic unsigned long roundup_ring_size(unsigned long pending) 41418c2ecf20Sopenharmony_ci{ 41428c2ecf20Sopenharmony_ci return max(128ul, roundup_pow_of_two(pending+1)); 41438c2ecf20Sopenharmony_ci} 41448c2ecf20Sopenharmony_ci 41458c2ecf20Sopenharmony_cistatic void sky2_get_ringparam(struct net_device *dev, 41468c2ecf20Sopenharmony_ci struct ethtool_ringparam *ering) 41478c2ecf20Sopenharmony_ci{ 41488c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 41498c2ecf20Sopenharmony_ci 41508c2ecf20Sopenharmony_ci ering->rx_max_pending = RX_MAX_PENDING; 41518c2ecf20Sopenharmony_ci ering->tx_max_pending = TX_MAX_PENDING; 41528c2ecf20Sopenharmony_ci 41538c2ecf20Sopenharmony_ci ering->rx_pending = sky2->rx_pending; 41548c2ecf20Sopenharmony_ci ering->tx_pending = sky2->tx_pending; 41558c2ecf20Sopenharmony_ci} 41568c2ecf20Sopenharmony_ci 41578c2ecf20Sopenharmony_cistatic int sky2_set_ringparam(struct net_device *dev, 41588c2ecf20Sopenharmony_ci struct ethtool_ringparam *ering) 41598c2ecf20Sopenharmony_ci{ 41608c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 41618c2ecf20Sopenharmony_ci 41628c2ecf20Sopenharmony_ci if (ering->rx_pending > RX_MAX_PENDING || 41638c2ecf20Sopenharmony_ci ering->rx_pending < 8 || 41648c2ecf20Sopenharmony_ci ering->tx_pending < TX_MIN_PENDING || 41658c2ecf20Sopenharmony_ci ering->tx_pending > TX_MAX_PENDING) 41668c2ecf20Sopenharmony_ci return -EINVAL; 41678c2ecf20Sopenharmony_ci 41688c2ecf20Sopenharmony_ci sky2_detach(dev); 41698c2ecf20Sopenharmony_ci 41708c2ecf20Sopenharmony_ci sky2->rx_pending = ering->rx_pending; 41718c2ecf20Sopenharmony_ci sky2->tx_pending = ering->tx_pending; 41728c2ecf20Sopenharmony_ci sky2->tx_ring_size = roundup_ring_size(sky2->tx_pending); 41738c2ecf20Sopenharmony_ci 41748c2ecf20Sopenharmony_ci return sky2_reattach(dev); 41758c2ecf20Sopenharmony_ci} 41768c2ecf20Sopenharmony_ci 41778c2ecf20Sopenharmony_cistatic int sky2_get_regs_len(struct net_device *dev) 41788c2ecf20Sopenharmony_ci{ 41798c2ecf20Sopenharmony_ci return 0x4000; 41808c2ecf20Sopenharmony_ci} 41818c2ecf20Sopenharmony_ci 41828c2ecf20Sopenharmony_cistatic int sky2_reg_access_ok(struct sky2_hw *hw, unsigned int b) 41838c2ecf20Sopenharmony_ci{ 41848c2ecf20Sopenharmony_ci /* This complicated switch statement is to make sure and 41858c2ecf20Sopenharmony_ci * only access regions that are unreserved. 41868c2ecf20Sopenharmony_ci * Some blocks are only valid on dual port cards. 41878c2ecf20Sopenharmony_ci */ 41888c2ecf20Sopenharmony_ci switch (b) { 41898c2ecf20Sopenharmony_ci /* second port */ 41908c2ecf20Sopenharmony_ci case 5: /* Tx Arbiter 2 */ 41918c2ecf20Sopenharmony_ci case 9: /* RX2 */ 41928c2ecf20Sopenharmony_ci case 14 ... 15: /* TX2 */ 41938c2ecf20Sopenharmony_ci case 17: case 19: /* Ram Buffer 2 */ 41948c2ecf20Sopenharmony_ci case 22 ... 23: /* Tx Ram Buffer 2 */ 41958c2ecf20Sopenharmony_ci case 25: /* Rx MAC Fifo 1 */ 41968c2ecf20Sopenharmony_ci case 27: /* Tx MAC Fifo 2 */ 41978c2ecf20Sopenharmony_ci case 31: /* GPHY 2 */ 41988c2ecf20Sopenharmony_ci case 40 ... 47: /* Pattern Ram 2 */ 41998c2ecf20Sopenharmony_ci case 52: case 54: /* TCP Segmentation 2 */ 42008c2ecf20Sopenharmony_ci case 112 ... 116: /* GMAC 2 */ 42018c2ecf20Sopenharmony_ci return hw->ports > 1; 42028c2ecf20Sopenharmony_ci 42038c2ecf20Sopenharmony_ci case 0: /* Control */ 42048c2ecf20Sopenharmony_ci case 2: /* Mac address */ 42058c2ecf20Sopenharmony_ci case 4: /* Tx Arbiter 1 */ 42068c2ecf20Sopenharmony_ci case 7: /* PCI express reg */ 42078c2ecf20Sopenharmony_ci case 8: /* RX1 */ 42088c2ecf20Sopenharmony_ci case 12 ... 13: /* TX1 */ 42098c2ecf20Sopenharmony_ci case 16: case 18:/* Rx Ram Buffer 1 */ 42108c2ecf20Sopenharmony_ci case 20 ... 21: /* Tx Ram Buffer 1 */ 42118c2ecf20Sopenharmony_ci case 24: /* Rx MAC Fifo 1 */ 42128c2ecf20Sopenharmony_ci case 26: /* Tx MAC Fifo 1 */ 42138c2ecf20Sopenharmony_ci case 28 ... 29: /* Descriptor and status unit */ 42148c2ecf20Sopenharmony_ci case 30: /* GPHY 1*/ 42158c2ecf20Sopenharmony_ci case 32 ... 39: /* Pattern Ram 1 */ 42168c2ecf20Sopenharmony_ci case 48: case 50: /* TCP Segmentation 1 */ 42178c2ecf20Sopenharmony_ci case 56 ... 60: /* PCI space */ 42188c2ecf20Sopenharmony_ci case 80 ... 84: /* GMAC 1 */ 42198c2ecf20Sopenharmony_ci return 1; 42208c2ecf20Sopenharmony_ci 42218c2ecf20Sopenharmony_ci default: 42228c2ecf20Sopenharmony_ci return 0; 42238c2ecf20Sopenharmony_ci } 42248c2ecf20Sopenharmony_ci} 42258c2ecf20Sopenharmony_ci 42268c2ecf20Sopenharmony_ci/* 42278c2ecf20Sopenharmony_ci * Returns copy of control register region 42288c2ecf20Sopenharmony_ci * Note: ethtool_get_regs always provides full size (16k) buffer 42298c2ecf20Sopenharmony_ci */ 42308c2ecf20Sopenharmony_cistatic void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs, 42318c2ecf20Sopenharmony_ci void *p) 42328c2ecf20Sopenharmony_ci{ 42338c2ecf20Sopenharmony_ci const struct sky2_port *sky2 = netdev_priv(dev); 42348c2ecf20Sopenharmony_ci const void __iomem *io = sky2->hw->regs; 42358c2ecf20Sopenharmony_ci unsigned int b; 42368c2ecf20Sopenharmony_ci 42378c2ecf20Sopenharmony_ci regs->version = 1; 42388c2ecf20Sopenharmony_ci 42398c2ecf20Sopenharmony_ci for (b = 0; b < 128; b++) { 42408c2ecf20Sopenharmony_ci /* skip poisonous diagnostic ram region in block 3 */ 42418c2ecf20Sopenharmony_ci if (b == 3) 42428c2ecf20Sopenharmony_ci memcpy_fromio(p + 0x10, io + 0x10, 128 - 0x10); 42438c2ecf20Sopenharmony_ci else if (sky2_reg_access_ok(sky2->hw, b)) 42448c2ecf20Sopenharmony_ci memcpy_fromio(p, io, 128); 42458c2ecf20Sopenharmony_ci else 42468c2ecf20Sopenharmony_ci memset(p, 0, 128); 42478c2ecf20Sopenharmony_ci 42488c2ecf20Sopenharmony_ci p += 128; 42498c2ecf20Sopenharmony_ci io += 128; 42508c2ecf20Sopenharmony_ci } 42518c2ecf20Sopenharmony_ci} 42528c2ecf20Sopenharmony_ci 42538c2ecf20Sopenharmony_cistatic int sky2_get_eeprom_len(struct net_device *dev) 42548c2ecf20Sopenharmony_ci{ 42558c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 42568c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 42578c2ecf20Sopenharmony_ci u16 reg2; 42588c2ecf20Sopenharmony_ci 42598c2ecf20Sopenharmony_ci reg2 = sky2_pci_read16(hw, PCI_DEV_REG2); 42608c2ecf20Sopenharmony_ci return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8); 42618c2ecf20Sopenharmony_ci} 42628c2ecf20Sopenharmony_ci 42638c2ecf20Sopenharmony_cistatic int sky2_vpd_wait(const struct sky2_hw *hw, int cap, u16 busy) 42648c2ecf20Sopenharmony_ci{ 42658c2ecf20Sopenharmony_ci unsigned long start = jiffies; 42668c2ecf20Sopenharmony_ci 42678c2ecf20Sopenharmony_ci while ( (sky2_pci_read16(hw, cap + PCI_VPD_ADDR) & PCI_VPD_ADDR_F) == busy) { 42688c2ecf20Sopenharmony_ci /* Can take up to 10.6 ms for write */ 42698c2ecf20Sopenharmony_ci if (time_after(jiffies, start + HZ/4)) { 42708c2ecf20Sopenharmony_ci dev_err(&hw->pdev->dev, "VPD cycle timed out\n"); 42718c2ecf20Sopenharmony_ci return -ETIMEDOUT; 42728c2ecf20Sopenharmony_ci } 42738c2ecf20Sopenharmony_ci msleep(1); 42748c2ecf20Sopenharmony_ci } 42758c2ecf20Sopenharmony_ci 42768c2ecf20Sopenharmony_ci return 0; 42778c2ecf20Sopenharmony_ci} 42788c2ecf20Sopenharmony_ci 42798c2ecf20Sopenharmony_cistatic int sky2_vpd_read(struct sky2_hw *hw, int cap, void *data, 42808c2ecf20Sopenharmony_ci u16 offset, size_t length) 42818c2ecf20Sopenharmony_ci{ 42828c2ecf20Sopenharmony_ci int rc = 0; 42838c2ecf20Sopenharmony_ci 42848c2ecf20Sopenharmony_ci while (length > 0) { 42858c2ecf20Sopenharmony_ci u32 val; 42868c2ecf20Sopenharmony_ci 42878c2ecf20Sopenharmony_ci sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset); 42888c2ecf20Sopenharmony_ci rc = sky2_vpd_wait(hw, cap, 0); 42898c2ecf20Sopenharmony_ci if (rc) 42908c2ecf20Sopenharmony_ci break; 42918c2ecf20Sopenharmony_ci 42928c2ecf20Sopenharmony_ci val = sky2_pci_read32(hw, cap + PCI_VPD_DATA); 42938c2ecf20Sopenharmony_ci 42948c2ecf20Sopenharmony_ci memcpy(data, &val, min(sizeof(val), length)); 42958c2ecf20Sopenharmony_ci offset += sizeof(u32); 42968c2ecf20Sopenharmony_ci data += sizeof(u32); 42978c2ecf20Sopenharmony_ci length -= sizeof(u32); 42988c2ecf20Sopenharmony_ci } 42998c2ecf20Sopenharmony_ci 43008c2ecf20Sopenharmony_ci return rc; 43018c2ecf20Sopenharmony_ci} 43028c2ecf20Sopenharmony_ci 43038c2ecf20Sopenharmony_cistatic int sky2_vpd_write(struct sky2_hw *hw, int cap, const void *data, 43048c2ecf20Sopenharmony_ci u16 offset, unsigned int length) 43058c2ecf20Sopenharmony_ci{ 43068c2ecf20Sopenharmony_ci unsigned int i; 43078c2ecf20Sopenharmony_ci int rc = 0; 43088c2ecf20Sopenharmony_ci 43098c2ecf20Sopenharmony_ci for (i = 0; i < length; i += sizeof(u32)) { 43108c2ecf20Sopenharmony_ci u32 val = *(u32 *)(data + i); 43118c2ecf20Sopenharmony_ci 43128c2ecf20Sopenharmony_ci sky2_pci_write32(hw, cap + PCI_VPD_DATA, val); 43138c2ecf20Sopenharmony_ci sky2_pci_write32(hw, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F); 43148c2ecf20Sopenharmony_ci 43158c2ecf20Sopenharmony_ci rc = sky2_vpd_wait(hw, cap, PCI_VPD_ADDR_F); 43168c2ecf20Sopenharmony_ci if (rc) 43178c2ecf20Sopenharmony_ci break; 43188c2ecf20Sopenharmony_ci } 43198c2ecf20Sopenharmony_ci return rc; 43208c2ecf20Sopenharmony_ci} 43218c2ecf20Sopenharmony_ci 43228c2ecf20Sopenharmony_cistatic int sky2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, 43238c2ecf20Sopenharmony_ci u8 *data) 43248c2ecf20Sopenharmony_ci{ 43258c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 43268c2ecf20Sopenharmony_ci int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD); 43278c2ecf20Sopenharmony_ci 43288c2ecf20Sopenharmony_ci if (!cap) 43298c2ecf20Sopenharmony_ci return -EINVAL; 43308c2ecf20Sopenharmony_ci 43318c2ecf20Sopenharmony_ci eeprom->magic = SKY2_EEPROM_MAGIC; 43328c2ecf20Sopenharmony_ci 43338c2ecf20Sopenharmony_ci return sky2_vpd_read(sky2->hw, cap, data, eeprom->offset, eeprom->len); 43348c2ecf20Sopenharmony_ci} 43358c2ecf20Sopenharmony_ci 43368c2ecf20Sopenharmony_cistatic int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, 43378c2ecf20Sopenharmony_ci u8 *data) 43388c2ecf20Sopenharmony_ci{ 43398c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 43408c2ecf20Sopenharmony_ci int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD); 43418c2ecf20Sopenharmony_ci 43428c2ecf20Sopenharmony_ci if (!cap) 43438c2ecf20Sopenharmony_ci return -EINVAL; 43448c2ecf20Sopenharmony_ci 43458c2ecf20Sopenharmony_ci if (eeprom->magic != SKY2_EEPROM_MAGIC) 43468c2ecf20Sopenharmony_ci return -EINVAL; 43478c2ecf20Sopenharmony_ci 43488c2ecf20Sopenharmony_ci /* Partial writes not supported */ 43498c2ecf20Sopenharmony_ci if ((eeprom->offset & 3) || (eeprom->len & 3)) 43508c2ecf20Sopenharmony_ci return -EINVAL; 43518c2ecf20Sopenharmony_ci 43528c2ecf20Sopenharmony_ci return sky2_vpd_write(sky2->hw, cap, data, eeprom->offset, eeprom->len); 43538c2ecf20Sopenharmony_ci} 43548c2ecf20Sopenharmony_ci 43558c2ecf20Sopenharmony_cistatic netdev_features_t sky2_fix_features(struct net_device *dev, 43568c2ecf20Sopenharmony_ci netdev_features_t features) 43578c2ecf20Sopenharmony_ci{ 43588c2ecf20Sopenharmony_ci const struct sky2_port *sky2 = netdev_priv(dev); 43598c2ecf20Sopenharmony_ci const struct sky2_hw *hw = sky2->hw; 43608c2ecf20Sopenharmony_ci 43618c2ecf20Sopenharmony_ci /* In order to do Jumbo packets on these chips, need to turn off the 43628c2ecf20Sopenharmony_ci * transmit store/forward. Therefore checksum offload won't work. 43638c2ecf20Sopenharmony_ci */ 43648c2ecf20Sopenharmony_ci if (dev->mtu > ETH_DATA_LEN && hw->chip_id == CHIP_ID_YUKON_EC_U) { 43658c2ecf20Sopenharmony_ci netdev_info(dev, "checksum offload not possible with jumbo frames\n"); 43668c2ecf20Sopenharmony_ci features &= ~(NETIF_F_TSO | NETIF_F_SG | NETIF_F_CSUM_MASK); 43678c2ecf20Sopenharmony_ci } 43688c2ecf20Sopenharmony_ci 43698c2ecf20Sopenharmony_ci /* Some hardware requires receive checksum for RSS to work. */ 43708c2ecf20Sopenharmony_ci if ( (features & NETIF_F_RXHASH) && 43718c2ecf20Sopenharmony_ci !(features & NETIF_F_RXCSUM) && 43728c2ecf20Sopenharmony_ci (sky2->hw->flags & SKY2_HW_RSS_CHKSUM)) { 43738c2ecf20Sopenharmony_ci netdev_info(dev, "receive hashing forces receive checksum\n"); 43748c2ecf20Sopenharmony_ci features |= NETIF_F_RXCSUM; 43758c2ecf20Sopenharmony_ci } 43768c2ecf20Sopenharmony_ci 43778c2ecf20Sopenharmony_ci return features; 43788c2ecf20Sopenharmony_ci} 43798c2ecf20Sopenharmony_ci 43808c2ecf20Sopenharmony_cistatic int sky2_set_features(struct net_device *dev, netdev_features_t features) 43818c2ecf20Sopenharmony_ci{ 43828c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 43838c2ecf20Sopenharmony_ci netdev_features_t changed = dev->features ^ features; 43848c2ecf20Sopenharmony_ci 43858c2ecf20Sopenharmony_ci if ((changed & NETIF_F_RXCSUM) && 43868c2ecf20Sopenharmony_ci !(sky2->hw->flags & SKY2_HW_NEW_LE)) { 43878c2ecf20Sopenharmony_ci sky2_write32(sky2->hw, 43888c2ecf20Sopenharmony_ci Q_ADDR(rxqaddr[sky2->port], Q_CSR), 43898c2ecf20Sopenharmony_ci (features & NETIF_F_RXCSUM) 43908c2ecf20Sopenharmony_ci ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM); 43918c2ecf20Sopenharmony_ci } 43928c2ecf20Sopenharmony_ci 43938c2ecf20Sopenharmony_ci if (changed & NETIF_F_RXHASH) 43948c2ecf20Sopenharmony_ci rx_set_rss(dev, features); 43958c2ecf20Sopenharmony_ci 43968c2ecf20Sopenharmony_ci if (changed & (NETIF_F_HW_VLAN_CTAG_TX|NETIF_F_HW_VLAN_CTAG_RX)) 43978c2ecf20Sopenharmony_ci sky2_vlan_mode(dev, features); 43988c2ecf20Sopenharmony_ci 43998c2ecf20Sopenharmony_ci return 0; 44008c2ecf20Sopenharmony_ci} 44018c2ecf20Sopenharmony_ci 44028c2ecf20Sopenharmony_cistatic const struct ethtool_ops sky2_ethtool_ops = { 44038c2ecf20Sopenharmony_ci .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 44048c2ecf20Sopenharmony_ci ETHTOOL_COALESCE_MAX_FRAMES | 44058c2ecf20Sopenharmony_ci ETHTOOL_COALESCE_RX_USECS_IRQ | 44068c2ecf20Sopenharmony_ci ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ, 44078c2ecf20Sopenharmony_ci .get_drvinfo = sky2_get_drvinfo, 44088c2ecf20Sopenharmony_ci .get_wol = sky2_get_wol, 44098c2ecf20Sopenharmony_ci .set_wol = sky2_set_wol, 44108c2ecf20Sopenharmony_ci .get_msglevel = sky2_get_msglevel, 44118c2ecf20Sopenharmony_ci .set_msglevel = sky2_set_msglevel, 44128c2ecf20Sopenharmony_ci .nway_reset = sky2_nway_reset, 44138c2ecf20Sopenharmony_ci .get_regs_len = sky2_get_regs_len, 44148c2ecf20Sopenharmony_ci .get_regs = sky2_get_regs, 44158c2ecf20Sopenharmony_ci .get_link = ethtool_op_get_link, 44168c2ecf20Sopenharmony_ci .get_eeprom_len = sky2_get_eeprom_len, 44178c2ecf20Sopenharmony_ci .get_eeprom = sky2_get_eeprom, 44188c2ecf20Sopenharmony_ci .set_eeprom = sky2_set_eeprom, 44198c2ecf20Sopenharmony_ci .get_strings = sky2_get_strings, 44208c2ecf20Sopenharmony_ci .get_coalesce = sky2_get_coalesce, 44218c2ecf20Sopenharmony_ci .set_coalesce = sky2_set_coalesce, 44228c2ecf20Sopenharmony_ci .get_ringparam = sky2_get_ringparam, 44238c2ecf20Sopenharmony_ci .set_ringparam = sky2_set_ringparam, 44248c2ecf20Sopenharmony_ci .get_pauseparam = sky2_get_pauseparam, 44258c2ecf20Sopenharmony_ci .set_pauseparam = sky2_set_pauseparam, 44268c2ecf20Sopenharmony_ci .set_phys_id = sky2_set_phys_id, 44278c2ecf20Sopenharmony_ci .get_sset_count = sky2_get_sset_count, 44288c2ecf20Sopenharmony_ci .get_ethtool_stats = sky2_get_ethtool_stats, 44298c2ecf20Sopenharmony_ci .get_link_ksettings = sky2_get_link_ksettings, 44308c2ecf20Sopenharmony_ci .set_link_ksettings = sky2_set_link_ksettings, 44318c2ecf20Sopenharmony_ci}; 44328c2ecf20Sopenharmony_ci 44338c2ecf20Sopenharmony_ci#ifdef CONFIG_SKY2_DEBUG 44348c2ecf20Sopenharmony_ci 44358c2ecf20Sopenharmony_cistatic struct dentry *sky2_debug; 44368c2ecf20Sopenharmony_ci 44378c2ecf20Sopenharmony_ci 44388c2ecf20Sopenharmony_ci/* 44398c2ecf20Sopenharmony_ci * Read and parse the first part of Vital Product Data 44408c2ecf20Sopenharmony_ci */ 44418c2ecf20Sopenharmony_ci#define VPD_SIZE 128 44428c2ecf20Sopenharmony_ci#define VPD_MAGIC 0x82 44438c2ecf20Sopenharmony_ci 44448c2ecf20Sopenharmony_cistatic const struct vpd_tag { 44458c2ecf20Sopenharmony_ci char tag[2]; 44468c2ecf20Sopenharmony_ci char *label; 44478c2ecf20Sopenharmony_ci} vpd_tags[] = { 44488c2ecf20Sopenharmony_ci { "PN", "Part Number" }, 44498c2ecf20Sopenharmony_ci { "EC", "Engineering Level" }, 44508c2ecf20Sopenharmony_ci { "MN", "Manufacturer" }, 44518c2ecf20Sopenharmony_ci { "SN", "Serial Number" }, 44528c2ecf20Sopenharmony_ci { "YA", "Asset Tag" }, 44538c2ecf20Sopenharmony_ci { "VL", "First Error Log Message" }, 44548c2ecf20Sopenharmony_ci { "VF", "Second Error Log Message" }, 44558c2ecf20Sopenharmony_ci { "VB", "Boot Agent ROM Configuration" }, 44568c2ecf20Sopenharmony_ci { "VE", "EFI UNDI Configuration" }, 44578c2ecf20Sopenharmony_ci}; 44588c2ecf20Sopenharmony_ci 44598c2ecf20Sopenharmony_cistatic void sky2_show_vpd(struct seq_file *seq, struct sky2_hw *hw) 44608c2ecf20Sopenharmony_ci{ 44618c2ecf20Sopenharmony_ci size_t vpd_size; 44628c2ecf20Sopenharmony_ci loff_t offs; 44638c2ecf20Sopenharmony_ci u8 len; 44648c2ecf20Sopenharmony_ci unsigned char *buf; 44658c2ecf20Sopenharmony_ci u16 reg2; 44668c2ecf20Sopenharmony_ci 44678c2ecf20Sopenharmony_ci reg2 = sky2_pci_read16(hw, PCI_DEV_REG2); 44688c2ecf20Sopenharmony_ci vpd_size = 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8); 44698c2ecf20Sopenharmony_ci 44708c2ecf20Sopenharmony_ci seq_printf(seq, "%s Product Data\n", pci_name(hw->pdev)); 44718c2ecf20Sopenharmony_ci buf = kmalloc(vpd_size, GFP_KERNEL); 44728c2ecf20Sopenharmony_ci if (!buf) { 44738c2ecf20Sopenharmony_ci seq_puts(seq, "no memory!\n"); 44748c2ecf20Sopenharmony_ci return; 44758c2ecf20Sopenharmony_ci } 44768c2ecf20Sopenharmony_ci 44778c2ecf20Sopenharmony_ci if (pci_read_vpd(hw->pdev, 0, vpd_size, buf) < 0) { 44788c2ecf20Sopenharmony_ci seq_puts(seq, "VPD read failed\n"); 44798c2ecf20Sopenharmony_ci goto out; 44808c2ecf20Sopenharmony_ci } 44818c2ecf20Sopenharmony_ci 44828c2ecf20Sopenharmony_ci if (buf[0] != VPD_MAGIC) { 44838c2ecf20Sopenharmony_ci seq_printf(seq, "VPD tag mismatch: %#x\n", buf[0]); 44848c2ecf20Sopenharmony_ci goto out; 44858c2ecf20Sopenharmony_ci } 44868c2ecf20Sopenharmony_ci len = buf[1]; 44878c2ecf20Sopenharmony_ci if (len == 0 || len > vpd_size - 4) { 44888c2ecf20Sopenharmony_ci seq_printf(seq, "Invalid id length: %d\n", len); 44898c2ecf20Sopenharmony_ci goto out; 44908c2ecf20Sopenharmony_ci } 44918c2ecf20Sopenharmony_ci 44928c2ecf20Sopenharmony_ci seq_printf(seq, "%.*s\n", len, buf + 3); 44938c2ecf20Sopenharmony_ci offs = len + 3; 44948c2ecf20Sopenharmony_ci 44958c2ecf20Sopenharmony_ci while (offs < vpd_size - 4) { 44968c2ecf20Sopenharmony_ci int i; 44978c2ecf20Sopenharmony_ci 44988c2ecf20Sopenharmony_ci if (!memcmp("RW", buf + offs, 2)) /* end marker */ 44998c2ecf20Sopenharmony_ci break; 45008c2ecf20Sopenharmony_ci len = buf[offs + 2]; 45018c2ecf20Sopenharmony_ci if (offs + len + 3 >= vpd_size) 45028c2ecf20Sopenharmony_ci break; 45038c2ecf20Sopenharmony_ci 45048c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(vpd_tags); i++) { 45058c2ecf20Sopenharmony_ci if (!memcmp(vpd_tags[i].tag, buf + offs, 2)) { 45068c2ecf20Sopenharmony_ci seq_printf(seq, " %s: %.*s\n", 45078c2ecf20Sopenharmony_ci vpd_tags[i].label, len, buf + offs + 3); 45088c2ecf20Sopenharmony_ci break; 45098c2ecf20Sopenharmony_ci } 45108c2ecf20Sopenharmony_ci } 45118c2ecf20Sopenharmony_ci offs += len + 3; 45128c2ecf20Sopenharmony_ci } 45138c2ecf20Sopenharmony_ciout: 45148c2ecf20Sopenharmony_ci kfree(buf); 45158c2ecf20Sopenharmony_ci} 45168c2ecf20Sopenharmony_ci 45178c2ecf20Sopenharmony_cistatic int sky2_debug_show(struct seq_file *seq, void *v) 45188c2ecf20Sopenharmony_ci{ 45198c2ecf20Sopenharmony_ci struct net_device *dev = seq->private; 45208c2ecf20Sopenharmony_ci const struct sky2_port *sky2 = netdev_priv(dev); 45218c2ecf20Sopenharmony_ci struct sky2_hw *hw = sky2->hw; 45228c2ecf20Sopenharmony_ci unsigned port = sky2->port; 45238c2ecf20Sopenharmony_ci unsigned idx, last; 45248c2ecf20Sopenharmony_ci int sop; 45258c2ecf20Sopenharmony_ci 45268c2ecf20Sopenharmony_ci sky2_show_vpd(seq, hw); 45278c2ecf20Sopenharmony_ci 45288c2ecf20Sopenharmony_ci seq_printf(seq, "\nIRQ src=%x mask=%x control=%x\n", 45298c2ecf20Sopenharmony_ci sky2_read32(hw, B0_ISRC), 45308c2ecf20Sopenharmony_ci sky2_read32(hw, B0_IMSK), 45318c2ecf20Sopenharmony_ci sky2_read32(hw, B0_Y2_SP_ICR)); 45328c2ecf20Sopenharmony_ci 45338c2ecf20Sopenharmony_ci if (!netif_running(dev)) { 45348c2ecf20Sopenharmony_ci seq_puts(seq, "network not running\n"); 45358c2ecf20Sopenharmony_ci return 0; 45368c2ecf20Sopenharmony_ci } 45378c2ecf20Sopenharmony_ci 45388c2ecf20Sopenharmony_ci napi_disable(&hw->napi); 45398c2ecf20Sopenharmony_ci last = sky2_read16(hw, STAT_PUT_IDX); 45408c2ecf20Sopenharmony_ci 45418c2ecf20Sopenharmony_ci seq_printf(seq, "Status ring %u\n", hw->st_size); 45428c2ecf20Sopenharmony_ci if (hw->st_idx == last) 45438c2ecf20Sopenharmony_ci seq_puts(seq, "Status ring (empty)\n"); 45448c2ecf20Sopenharmony_ci else { 45458c2ecf20Sopenharmony_ci seq_puts(seq, "Status ring\n"); 45468c2ecf20Sopenharmony_ci for (idx = hw->st_idx; idx != last && idx < hw->st_size; 45478c2ecf20Sopenharmony_ci idx = RING_NEXT(idx, hw->st_size)) { 45488c2ecf20Sopenharmony_ci const struct sky2_status_le *le = hw->st_le + idx; 45498c2ecf20Sopenharmony_ci seq_printf(seq, "[%d] %#x %d %#x\n", 45508c2ecf20Sopenharmony_ci idx, le->opcode, le->length, le->status); 45518c2ecf20Sopenharmony_ci } 45528c2ecf20Sopenharmony_ci seq_puts(seq, "\n"); 45538c2ecf20Sopenharmony_ci } 45548c2ecf20Sopenharmony_ci 45558c2ecf20Sopenharmony_ci seq_printf(seq, "Tx ring pending=%u...%u report=%d done=%d\n", 45568c2ecf20Sopenharmony_ci sky2->tx_cons, sky2->tx_prod, 45578c2ecf20Sopenharmony_ci sky2_read16(hw, port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX), 45588c2ecf20Sopenharmony_ci sky2_read16(hw, Q_ADDR(txqaddr[port], Q_DONE))); 45598c2ecf20Sopenharmony_ci 45608c2ecf20Sopenharmony_ci /* Dump contents of tx ring */ 45618c2ecf20Sopenharmony_ci sop = 1; 45628c2ecf20Sopenharmony_ci for (idx = sky2->tx_next; idx != sky2->tx_prod && idx < sky2->tx_ring_size; 45638c2ecf20Sopenharmony_ci idx = RING_NEXT(idx, sky2->tx_ring_size)) { 45648c2ecf20Sopenharmony_ci const struct sky2_tx_le *le = sky2->tx_le + idx; 45658c2ecf20Sopenharmony_ci u32 a = le32_to_cpu(le->addr); 45668c2ecf20Sopenharmony_ci 45678c2ecf20Sopenharmony_ci if (sop) 45688c2ecf20Sopenharmony_ci seq_printf(seq, "%u:", idx); 45698c2ecf20Sopenharmony_ci sop = 0; 45708c2ecf20Sopenharmony_ci 45718c2ecf20Sopenharmony_ci switch (le->opcode & ~HW_OWNER) { 45728c2ecf20Sopenharmony_ci case OP_ADDR64: 45738c2ecf20Sopenharmony_ci seq_printf(seq, " %#x:", a); 45748c2ecf20Sopenharmony_ci break; 45758c2ecf20Sopenharmony_ci case OP_LRGLEN: 45768c2ecf20Sopenharmony_ci seq_printf(seq, " mtu=%d", a); 45778c2ecf20Sopenharmony_ci break; 45788c2ecf20Sopenharmony_ci case OP_VLAN: 45798c2ecf20Sopenharmony_ci seq_printf(seq, " vlan=%d", be16_to_cpu(le->length)); 45808c2ecf20Sopenharmony_ci break; 45818c2ecf20Sopenharmony_ci case OP_TCPLISW: 45828c2ecf20Sopenharmony_ci seq_printf(seq, " csum=%#x", a); 45838c2ecf20Sopenharmony_ci break; 45848c2ecf20Sopenharmony_ci case OP_LARGESEND: 45858c2ecf20Sopenharmony_ci seq_printf(seq, " tso=%#x(%d)", a, le16_to_cpu(le->length)); 45868c2ecf20Sopenharmony_ci break; 45878c2ecf20Sopenharmony_ci case OP_PACKET: 45888c2ecf20Sopenharmony_ci seq_printf(seq, " %#x(%d)", a, le16_to_cpu(le->length)); 45898c2ecf20Sopenharmony_ci break; 45908c2ecf20Sopenharmony_ci case OP_BUFFER: 45918c2ecf20Sopenharmony_ci seq_printf(seq, " frag=%#x(%d)", a, le16_to_cpu(le->length)); 45928c2ecf20Sopenharmony_ci break; 45938c2ecf20Sopenharmony_ci default: 45948c2ecf20Sopenharmony_ci seq_printf(seq, " op=%#x,%#x(%d)", le->opcode, 45958c2ecf20Sopenharmony_ci a, le16_to_cpu(le->length)); 45968c2ecf20Sopenharmony_ci } 45978c2ecf20Sopenharmony_ci 45988c2ecf20Sopenharmony_ci if (le->ctrl & EOP) { 45998c2ecf20Sopenharmony_ci seq_putc(seq, '\n'); 46008c2ecf20Sopenharmony_ci sop = 1; 46018c2ecf20Sopenharmony_ci } 46028c2ecf20Sopenharmony_ci } 46038c2ecf20Sopenharmony_ci 46048c2ecf20Sopenharmony_ci seq_printf(seq, "\nRx ring hw get=%d put=%d last=%d\n", 46058c2ecf20Sopenharmony_ci sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_GET_IDX)), 46068c2ecf20Sopenharmony_ci sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_PUT_IDX)), 46078c2ecf20Sopenharmony_ci sky2_read16(hw, Y2_QADDR(rxqaddr[port], PREF_UNIT_LAST_IDX))); 46088c2ecf20Sopenharmony_ci 46098c2ecf20Sopenharmony_ci sky2_read32(hw, B0_Y2_SP_LISR); 46108c2ecf20Sopenharmony_ci napi_enable(&hw->napi); 46118c2ecf20Sopenharmony_ci return 0; 46128c2ecf20Sopenharmony_ci} 46138c2ecf20Sopenharmony_ciDEFINE_SHOW_ATTRIBUTE(sky2_debug); 46148c2ecf20Sopenharmony_ci 46158c2ecf20Sopenharmony_ci/* 46168c2ecf20Sopenharmony_ci * Use network device events to create/remove/rename 46178c2ecf20Sopenharmony_ci * debugfs file entries 46188c2ecf20Sopenharmony_ci */ 46198c2ecf20Sopenharmony_cistatic int sky2_device_event(struct notifier_block *unused, 46208c2ecf20Sopenharmony_ci unsigned long event, void *ptr) 46218c2ecf20Sopenharmony_ci{ 46228c2ecf20Sopenharmony_ci struct net_device *dev = netdev_notifier_info_to_dev(ptr); 46238c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 46248c2ecf20Sopenharmony_ci 46258c2ecf20Sopenharmony_ci if (dev->netdev_ops->ndo_open != sky2_open || !sky2_debug) 46268c2ecf20Sopenharmony_ci return NOTIFY_DONE; 46278c2ecf20Sopenharmony_ci 46288c2ecf20Sopenharmony_ci switch (event) { 46298c2ecf20Sopenharmony_ci case NETDEV_CHANGENAME: 46308c2ecf20Sopenharmony_ci if (sky2->debugfs) { 46318c2ecf20Sopenharmony_ci sky2->debugfs = debugfs_rename(sky2_debug, sky2->debugfs, 46328c2ecf20Sopenharmony_ci sky2_debug, dev->name); 46338c2ecf20Sopenharmony_ci } 46348c2ecf20Sopenharmony_ci break; 46358c2ecf20Sopenharmony_ci 46368c2ecf20Sopenharmony_ci case NETDEV_GOING_DOWN: 46378c2ecf20Sopenharmony_ci if (sky2->debugfs) { 46388c2ecf20Sopenharmony_ci netdev_printk(KERN_DEBUG, dev, "remove debugfs\n"); 46398c2ecf20Sopenharmony_ci debugfs_remove(sky2->debugfs); 46408c2ecf20Sopenharmony_ci sky2->debugfs = NULL; 46418c2ecf20Sopenharmony_ci } 46428c2ecf20Sopenharmony_ci break; 46438c2ecf20Sopenharmony_ci 46448c2ecf20Sopenharmony_ci case NETDEV_UP: 46458c2ecf20Sopenharmony_ci sky2->debugfs = debugfs_create_file(dev->name, 0444, 46468c2ecf20Sopenharmony_ci sky2_debug, dev, 46478c2ecf20Sopenharmony_ci &sky2_debug_fops); 46488c2ecf20Sopenharmony_ci if (IS_ERR(sky2->debugfs)) 46498c2ecf20Sopenharmony_ci sky2->debugfs = NULL; 46508c2ecf20Sopenharmony_ci } 46518c2ecf20Sopenharmony_ci 46528c2ecf20Sopenharmony_ci return NOTIFY_DONE; 46538c2ecf20Sopenharmony_ci} 46548c2ecf20Sopenharmony_ci 46558c2ecf20Sopenharmony_cistatic struct notifier_block sky2_notifier = { 46568c2ecf20Sopenharmony_ci .notifier_call = sky2_device_event, 46578c2ecf20Sopenharmony_ci}; 46588c2ecf20Sopenharmony_ci 46598c2ecf20Sopenharmony_ci 46608c2ecf20Sopenharmony_cistatic __init void sky2_debug_init(void) 46618c2ecf20Sopenharmony_ci{ 46628c2ecf20Sopenharmony_ci struct dentry *ent; 46638c2ecf20Sopenharmony_ci 46648c2ecf20Sopenharmony_ci ent = debugfs_create_dir("sky2", NULL); 46658c2ecf20Sopenharmony_ci if (!ent || IS_ERR(ent)) 46668c2ecf20Sopenharmony_ci return; 46678c2ecf20Sopenharmony_ci 46688c2ecf20Sopenharmony_ci sky2_debug = ent; 46698c2ecf20Sopenharmony_ci register_netdevice_notifier(&sky2_notifier); 46708c2ecf20Sopenharmony_ci} 46718c2ecf20Sopenharmony_ci 46728c2ecf20Sopenharmony_cistatic __exit void sky2_debug_cleanup(void) 46738c2ecf20Sopenharmony_ci{ 46748c2ecf20Sopenharmony_ci if (sky2_debug) { 46758c2ecf20Sopenharmony_ci unregister_netdevice_notifier(&sky2_notifier); 46768c2ecf20Sopenharmony_ci debugfs_remove(sky2_debug); 46778c2ecf20Sopenharmony_ci sky2_debug = NULL; 46788c2ecf20Sopenharmony_ci } 46798c2ecf20Sopenharmony_ci} 46808c2ecf20Sopenharmony_ci 46818c2ecf20Sopenharmony_ci#else 46828c2ecf20Sopenharmony_ci#define sky2_debug_init() 46838c2ecf20Sopenharmony_ci#define sky2_debug_cleanup() 46848c2ecf20Sopenharmony_ci#endif 46858c2ecf20Sopenharmony_ci 46868c2ecf20Sopenharmony_ci/* Two copies of network device operations to handle special case of 46878c2ecf20Sopenharmony_ci not allowing netpoll on second port */ 46888c2ecf20Sopenharmony_cistatic const struct net_device_ops sky2_netdev_ops[2] = { 46898c2ecf20Sopenharmony_ci { 46908c2ecf20Sopenharmony_ci .ndo_open = sky2_open, 46918c2ecf20Sopenharmony_ci .ndo_stop = sky2_close, 46928c2ecf20Sopenharmony_ci .ndo_start_xmit = sky2_xmit_frame, 46938c2ecf20Sopenharmony_ci .ndo_do_ioctl = sky2_ioctl, 46948c2ecf20Sopenharmony_ci .ndo_validate_addr = eth_validate_addr, 46958c2ecf20Sopenharmony_ci .ndo_set_mac_address = sky2_set_mac_address, 46968c2ecf20Sopenharmony_ci .ndo_set_rx_mode = sky2_set_multicast, 46978c2ecf20Sopenharmony_ci .ndo_change_mtu = sky2_change_mtu, 46988c2ecf20Sopenharmony_ci .ndo_fix_features = sky2_fix_features, 46998c2ecf20Sopenharmony_ci .ndo_set_features = sky2_set_features, 47008c2ecf20Sopenharmony_ci .ndo_tx_timeout = sky2_tx_timeout, 47018c2ecf20Sopenharmony_ci .ndo_get_stats64 = sky2_get_stats, 47028c2ecf20Sopenharmony_ci#ifdef CONFIG_NET_POLL_CONTROLLER 47038c2ecf20Sopenharmony_ci .ndo_poll_controller = sky2_netpoll, 47048c2ecf20Sopenharmony_ci#endif 47058c2ecf20Sopenharmony_ci }, 47068c2ecf20Sopenharmony_ci { 47078c2ecf20Sopenharmony_ci .ndo_open = sky2_open, 47088c2ecf20Sopenharmony_ci .ndo_stop = sky2_close, 47098c2ecf20Sopenharmony_ci .ndo_start_xmit = sky2_xmit_frame, 47108c2ecf20Sopenharmony_ci .ndo_do_ioctl = sky2_ioctl, 47118c2ecf20Sopenharmony_ci .ndo_validate_addr = eth_validate_addr, 47128c2ecf20Sopenharmony_ci .ndo_set_mac_address = sky2_set_mac_address, 47138c2ecf20Sopenharmony_ci .ndo_set_rx_mode = sky2_set_multicast, 47148c2ecf20Sopenharmony_ci .ndo_change_mtu = sky2_change_mtu, 47158c2ecf20Sopenharmony_ci .ndo_fix_features = sky2_fix_features, 47168c2ecf20Sopenharmony_ci .ndo_set_features = sky2_set_features, 47178c2ecf20Sopenharmony_ci .ndo_tx_timeout = sky2_tx_timeout, 47188c2ecf20Sopenharmony_ci .ndo_get_stats64 = sky2_get_stats, 47198c2ecf20Sopenharmony_ci }, 47208c2ecf20Sopenharmony_ci}; 47218c2ecf20Sopenharmony_ci 47228c2ecf20Sopenharmony_ci/* Initialize network device */ 47238c2ecf20Sopenharmony_cistatic struct net_device *sky2_init_netdev(struct sky2_hw *hw, unsigned port, 47248c2ecf20Sopenharmony_ci int highmem, int wol) 47258c2ecf20Sopenharmony_ci{ 47268c2ecf20Sopenharmony_ci struct sky2_port *sky2; 47278c2ecf20Sopenharmony_ci struct net_device *dev = alloc_etherdev(sizeof(*sky2)); 47288c2ecf20Sopenharmony_ci const void *iap; 47298c2ecf20Sopenharmony_ci 47308c2ecf20Sopenharmony_ci if (!dev) 47318c2ecf20Sopenharmony_ci return NULL; 47328c2ecf20Sopenharmony_ci 47338c2ecf20Sopenharmony_ci SET_NETDEV_DEV(dev, &hw->pdev->dev); 47348c2ecf20Sopenharmony_ci dev->irq = hw->pdev->irq; 47358c2ecf20Sopenharmony_ci dev->ethtool_ops = &sky2_ethtool_ops; 47368c2ecf20Sopenharmony_ci dev->watchdog_timeo = TX_WATCHDOG; 47378c2ecf20Sopenharmony_ci dev->netdev_ops = &sky2_netdev_ops[port]; 47388c2ecf20Sopenharmony_ci 47398c2ecf20Sopenharmony_ci sky2 = netdev_priv(dev); 47408c2ecf20Sopenharmony_ci sky2->netdev = dev; 47418c2ecf20Sopenharmony_ci sky2->hw = hw; 47428c2ecf20Sopenharmony_ci sky2->msg_enable = netif_msg_init(debug, default_msg); 47438c2ecf20Sopenharmony_ci 47448c2ecf20Sopenharmony_ci u64_stats_init(&sky2->tx_stats.syncp); 47458c2ecf20Sopenharmony_ci u64_stats_init(&sky2->rx_stats.syncp); 47468c2ecf20Sopenharmony_ci 47478c2ecf20Sopenharmony_ci /* Auto speed and flow control */ 47488c2ecf20Sopenharmony_ci sky2->flags = SKY2_FLAG_AUTO_SPEED | SKY2_FLAG_AUTO_PAUSE; 47498c2ecf20Sopenharmony_ci if (hw->chip_id != CHIP_ID_YUKON_XL) 47508c2ecf20Sopenharmony_ci dev->hw_features |= NETIF_F_RXCSUM; 47518c2ecf20Sopenharmony_ci 47528c2ecf20Sopenharmony_ci sky2->flow_mode = FC_BOTH; 47538c2ecf20Sopenharmony_ci 47548c2ecf20Sopenharmony_ci sky2->duplex = -1; 47558c2ecf20Sopenharmony_ci sky2->speed = -1; 47568c2ecf20Sopenharmony_ci sky2->advertising = sky2_supported_modes(hw); 47578c2ecf20Sopenharmony_ci sky2->wol = wol; 47588c2ecf20Sopenharmony_ci 47598c2ecf20Sopenharmony_ci spin_lock_init(&sky2->phy_lock); 47608c2ecf20Sopenharmony_ci 47618c2ecf20Sopenharmony_ci sky2->tx_pending = TX_DEF_PENDING; 47628c2ecf20Sopenharmony_ci sky2->tx_ring_size = roundup_ring_size(TX_DEF_PENDING); 47638c2ecf20Sopenharmony_ci sky2->rx_pending = RX_DEF_PENDING; 47648c2ecf20Sopenharmony_ci 47658c2ecf20Sopenharmony_ci hw->dev[port] = dev; 47668c2ecf20Sopenharmony_ci 47678c2ecf20Sopenharmony_ci sky2->port = port; 47688c2ecf20Sopenharmony_ci 47698c2ecf20Sopenharmony_ci dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO; 47708c2ecf20Sopenharmony_ci 47718c2ecf20Sopenharmony_ci if (highmem) 47728c2ecf20Sopenharmony_ci dev->features |= NETIF_F_HIGHDMA; 47738c2ecf20Sopenharmony_ci 47748c2ecf20Sopenharmony_ci /* Enable receive hashing unless hardware is known broken */ 47758c2ecf20Sopenharmony_ci if (!(hw->flags & SKY2_HW_RSS_BROKEN)) 47768c2ecf20Sopenharmony_ci dev->hw_features |= NETIF_F_RXHASH; 47778c2ecf20Sopenharmony_ci 47788c2ecf20Sopenharmony_ci if (!(hw->flags & SKY2_HW_VLAN_BROKEN)) { 47798c2ecf20Sopenharmony_ci dev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX | 47808c2ecf20Sopenharmony_ci NETIF_F_HW_VLAN_CTAG_RX; 47818c2ecf20Sopenharmony_ci dev->vlan_features |= SKY2_VLAN_OFFLOADS; 47828c2ecf20Sopenharmony_ci } 47838c2ecf20Sopenharmony_ci 47848c2ecf20Sopenharmony_ci dev->features |= dev->hw_features; 47858c2ecf20Sopenharmony_ci 47868c2ecf20Sopenharmony_ci /* MTU range: 60 - 1500 or 9000 */ 47878c2ecf20Sopenharmony_ci dev->min_mtu = ETH_ZLEN; 47888c2ecf20Sopenharmony_ci if (hw->chip_id == CHIP_ID_YUKON_FE || 47898c2ecf20Sopenharmony_ci hw->chip_id == CHIP_ID_YUKON_FE_P) 47908c2ecf20Sopenharmony_ci dev->max_mtu = ETH_DATA_LEN; 47918c2ecf20Sopenharmony_ci else 47928c2ecf20Sopenharmony_ci dev->max_mtu = ETH_JUMBO_MTU; 47938c2ecf20Sopenharmony_ci 47948c2ecf20Sopenharmony_ci /* try to get mac address in the following order: 47958c2ecf20Sopenharmony_ci * 1) from device tree data 47968c2ecf20Sopenharmony_ci * 2) from internal registers set by bootloader 47978c2ecf20Sopenharmony_ci */ 47988c2ecf20Sopenharmony_ci iap = of_get_mac_address(hw->pdev->dev.of_node); 47998c2ecf20Sopenharmony_ci if (!IS_ERR(iap)) 48008c2ecf20Sopenharmony_ci ether_addr_copy(dev->dev_addr, iap); 48018c2ecf20Sopenharmony_ci else 48028c2ecf20Sopenharmony_ci memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8, 48038c2ecf20Sopenharmony_ci ETH_ALEN); 48048c2ecf20Sopenharmony_ci 48058c2ecf20Sopenharmony_ci /* if the address is invalid, use a random value */ 48068c2ecf20Sopenharmony_ci if (!is_valid_ether_addr(dev->dev_addr)) { 48078c2ecf20Sopenharmony_ci struct sockaddr sa = { AF_UNSPEC }; 48088c2ecf20Sopenharmony_ci 48098c2ecf20Sopenharmony_ci netdev_warn(dev, 48108c2ecf20Sopenharmony_ci "Invalid MAC address, defaulting to random\n"); 48118c2ecf20Sopenharmony_ci eth_hw_addr_random(dev); 48128c2ecf20Sopenharmony_ci memcpy(sa.sa_data, dev->dev_addr, ETH_ALEN); 48138c2ecf20Sopenharmony_ci if (sky2_set_mac_address(dev, &sa)) 48148c2ecf20Sopenharmony_ci netdev_warn(dev, "Failed to set MAC address.\n"); 48158c2ecf20Sopenharmony_ci } 48168c2ecf20Sopenharmony_ci 48178c2ecf20Sopenharmony_ci return dev; 48188c2ecf20Sopenharmony_ci} 48198c2ecf20Sopenharmony_ci 48208c2ecf20Sopenharmony_cistatic void sky2_show_addr(struct net_device *dev) 48218c2ecf20Sopenharmony_ci{ 48228c2ecf20Sopenharmony_ci const struct sky2_port *sky2 = netdev_priv(dev); 48238c2ecf20Sopenharmony_ci 48248c2ecf20Sopenharmony_ci netif_info(sky2, probe, dev, "addr %pM\n", dev->dev_addr); 48258c2ecf20Sopenharmony_ci} 48268c2ecf20Sopenharmony_ci 48278c2ecf20Sopenharmony_ci/* Handle software interrupt used during MSI test */ 48288c2ecf20Sopenharmony_cistatic irqreturn_t sky2_test_intr(int irq, void *dev_id) 48298c2ecf20Sopenharmony_ci{ 48308c2ecf20Sopenharmony_ci struct sky2_hw *hw = dev_id; 48318c2ecf20Sopenharmony_ci u32 status = sky2_read32(hw, B0_Y2_SP_ISRC2); 48328c2ecf20Sopenharmony_ci 48338c2ecf20Sopenharmony_ci if (status == 0) 48348c2ecf20Sopenharmony_ci return IRQ_NONE; 48358c2ecf20Sopenharmony_ci 48368c2ecf20Sopenharmony_ci if (status & Y2_IS_IRQ_SW) { 48378c2ecf20Sopenharmony_ci hw->flags |= SKY2_HW_USE_MSI; 48388c2ecf20Sopenharmony_ci wake_up(&hw->msi_wait); 48398c2ecf20Sopenharmony_ci sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ); 48408c2ecf20Sopenharmony_ci } 48418c2ecf20Sopenharmony_ci sky2_write32(hw, B0_Y2_SP_ICR, 2); 48428c2ecf20Sopenharmony_ci 48438c2ecf20Sopenharmony_ci return IRQ_HANDLED; 48448c2ecf20Sopenharmony_ci} 48458c2ecf20Sopenharmony_ci 48468c2ecf20Sopenharmony_ci/* Test interrupt path by forcing a a software IRQ */ 48478c2ecf20Sopenharmony_cistatic int sky2_test_msi(struct sky2_hw *hw) 48488c2ecf20Sopenharmony_ci{ 48498c2ecf20Sopenharmony_ci struct pci_dev *pdev = hw->pdev; 48508c2ecf20Sopenharmony_ci int err; 48518c2ecf20Sopenharmony_ci 48528c2ecf20Sopenharmony_ci init_waitqueue_head(&hw->msi_wait); 48538c2ecf20Sopenharmony_ci 48548c2ecf20Sopenharmony_ci err = request_irq(pdev->irq, sky2_test_intr, 0, DRV_NAME, hw); 48558c2ecf20Sopenharmony_ci if (err) { 48568c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq); 48578c2ecf20Sopenharmony_ci return err; 48588c2ecf20Sopenharmony_ci } 48598c2ecf20Sopenharmony_ci 48608c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, Y2_IS_IRQ_SW); 48618c2ecf20Sopenharmony_ci 48628c2ecf20Sopenharmony_ci sky2_write8(hw, B0_CTST, CS_ST_SW_IRQ); 48638c2ecf20Sopenharmony_ci sky2_read8(hw, B0_CTST); 48648c2ecf20Sopenharmony_ci 48658c2ecf20Sopenharmony_ci wait_event_timeout(hw->msi_wait, (hw->flags & SKY2_HW_USE_MSI), HZ/10); 48668c2ecf20Sopenharmony_ci 48678c2ecf20Sopenharmony_ci if (!(hw->flags & SKY2_HW_USE_MSI)) { 48688c2ecf20Sopenharmony_ci /* MSI test failed, go back to INTx mode */ 48698c2ecf20Sopenharmony_ci dev_info(&pdev->dev, "No interrupt generated using MSI, " 48708c2ecf20Sopenharmony_ci "switching to INTx mode.\n"); 48718c2ecf20Sopenharmony_ci 48728c2ecf20Sopenharmony_ci err = -EOPNOTSUPP; 48738c2ecf20Sopenharmony_ci sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ); 48748c2ecf20Sopenharmony_ci } 48758c2ecf20Sopenharmony_ci 48768c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, 0); 48778c2ecf20Sopenharmony_ci sky2_read32(hw, B0_IMSK); 48788c2ecf20Sopenharmony_ci 48798c2ecf20Sopenharmony_ci free_irq(pdev->irq, hw); 48808c2ecf20Sopenharmony_ci 48818c2ecf20Sopenharmony_ci return err; 48828c2ecf20Sopenharmony_ci} 48838c2ecf20Sopenharmony_ci 48848c2ecf20Sopenharmony_ci/* This driver supports yukon2 chipset only */ 48858c2ecf20Sopenharmony_cistatic const char *sky2_name(u8 chipid, char *buf, int sz) 48868c2ecf20Sopenharmony_ci{ 48878c2ecf20Sopenharmony_ci const char *name[] = { 48888c2ecf20Sopenharmony_ci "XL", /* 0xb3 */ 48898c2ecf20Sopenharmony_ci "EC Ultra", /* 0xb4 */ 48908c2ecf20Sopenharmony_ci "Extreme", /* 0xb5 */ 48918c2ecf20Sopenharmony_ci "EC", /* 0xb6 */ 48928c2ecf20Sopenharmony_ci "FE", /* 0xb7 */ 48938c2ecf20Sopenharmony_ci "FE+", /* 0xb8 */ 48948c2ecf20Sopenharmony_ci "Supreme", /* 0xb9 */ 48958c2ecf20Sopenharmony_ci "UL 2", /* 0xba */ 48968c2ecf20Sopenharmony_ci "Unknown", /* 0xbb */ 48978c2ecf20Sopenharmony_ci "Optima", /* 0xbc */ 48988c2ecf20Sopenharmony_ci "OptimaEEE", /* 0xbd */ 48998c2ecf20Sopenharmony_ci "Optima 2", /* 0xbe */ 49008c2ecf20Sopenharmony_ci }; 49018c2ecf20Sopenharmony_ci 49028c2ecf20Sopenharmony_ci if (chipid >= CHIP_ID_YUKON_XL && chipid <= CHIP_ID_YUKON_OP_2) 49038c2ecf20Sopenharmony_ci strncpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz); 49048c2ecf20Sopenharmony_ci else 49058c2ecf20Sopenharmony_ci snprintf(buf, sz, "(chip %#x)", chipid); 49068c2ecf20Sopenharmony_ci return buf; 49078c2ecf20Sopenharmony_ci} 49088c2ecf20Sopenharmony_ci 49098c2ecf20Sopenharmony_cistatic const struct dmi_system_id msi_blacklist[] = { 49108c2ecf20Sopenharmony_ci { 49118c2ecf20Sopenharmony_ci .ident = "Dell Inspiron 1545", 49128c2ecf20Sopenharmony_ci .matches = { 49138c2ecf20Sopenharmony_ci DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 49148c2ecf20Sopenharmony_ci DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1545"), 49158c2ecf20Sopenharmony_ci }, 49168c2ecf20Sopenharmony_ci }, 49178c2ecf20Sopenharmony_ci { 49188c2ecf20Sopenharmony_ci .ident = "Gateway P-79", 49198c2ecf20Sopenharmony_ci .matches = { 49208c2ecf20Sopenharmony_ci DMI_MATCH(DMI_SYS_VENDOR, "Gateway"), 49218c2ecf20Sopenharmony_ci DMI_MATCH(DMI_PRODUCT_NAME, "P-79"), 49228c2ecf20Sopenharmony_ci }, 49238c2ecf20Sopenharmony_ci }, 49248c2ecf20Sopenharmony_ci { 49258c2ecf20Sopenharmony_ci .ident = "ASUS P5W DH Deluxe", 49268c2ecf20Sopenharmony_ci .matches = { 49278c2ecf20Sopenharmony_ci DMI_MATCH(DMI_SYS_VENDOR, "ASUSTEK COMPUTER INC"), 49288c2ecf20Sopenharmony_ci DMI_MATCH(DMI_PRODUCT_NAME, "P5W DH Deluxe"), 49298c2ecf20Sopenharmony_ci }, 49308c2ecf20Sopenharmony_ci }, 49318c2ecf20Sopenharmony_ci { 49328c2ecf20Sopenharmony_ci .ident = "ASUS P6T", 49338c2ecf20Sopenharmony_ci .matches = { 49348c2ecf20Sopenharmony_ci DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), 49358c2ecf20Sopenharmony_ci DMI_MATCH(DMI_BOARD_NAME, "P6T"), 49368c2ecf20Sopenharmony_ci }, 49378c2ecf20Sopenharmony_ci }, 49388c2ecf20Sopenharmony_ci { 49398c2ecf20Sopenharmony_ci .ident = "ASUS P6X", 49408c2ecf20Sopenharmony_ci .matches = { 49418c2ecf20Sopenharmony_ci DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), 49428c2ecf20Sopenharmony_ci DMI_MATCH(DMI_BOARD_NAME, "P6X"), 49438c2ecf20Sopenharmony_ci }, 49448c2ecf20Sopenharmony_ci }, 49458c2ecf20Sopenharmony_ci {} 49468c2ecf20Sopenharmony_ci}; 49478c2ecf20Sopenharmony_ci 49488c2ecf20Sopenharmony_cistatic int sky2_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 49498c2ecf20Sopenharmony_ci{ 49508c2ecf20Sopenharmony_ci struct net_device *dev, *dev1; 49518c2ecf20Sopenharmony_ci struct sky2_hw *hw; 49528c2ecf20Sopenharmony_ci int err, using_dac = 0, wol_default; 49538c2ecf20Sopenharmony_ci u32 reg; 49548c2ecf20Sopenharmony_ci char buf1[16]; 49558c2ecf20Sopenharmony_ci 49568c2ecf20Sopenharmony_ci err = pci_enable_device(pdev); 49578c2ecf20Sopenharmony_ci if (err) { 49588c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot enable PCI device\n"); 49598c2ecf20Sopenharmony_ci goto err_out; 49608c2ecf20Sopenharmony_ci } 49618c2ecf20Sopenharmony_ci 49628c2ecf20Sopenharmony_ci /* Get configuration information 49638c2ecf20Sopenharmony_ci * Note: only regular PCI config access once to test for HW issues 49648c2ecf20Sopenharmony_ci * other PCI access through shared memory for speed and to 49658c2ecf20Sopenharmony_ci * avoid MMCONFIG problems. 49668c2ecf20Sopenharmony_ci */ 49678c2ecf20Sopenharmony_ci err = pci_read_config_dword(pdev, PCI_DEV_REG2, ®); 49688c2ecf20Sopenharmony_ci if (err) { 49698c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "PCI read config failed\n"); 49708c2ecf20Sopenharmony_ci goto err_out_disable; 49718c2ecf20Sopenharmony_ci } 49728c2ecf20Sopenharmony_ci 49738c2ecf20Sopenharmony_ci if (~reg == 0) { 49748c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "PCI configuration read error\n"); 49758c2ecf20Sopenharmony_ci err = -EIO; 49768c2ecf20Sopenharmony_ci goto err_out_disable; 49778c2ecf20Sopenharmony_ci } 49788c2ecf20Sopenharmony_ci 49798c2ecf20Sopenharmony_ci err = pci_request_regions(pdev, DRV_NAME); 49808c2ecf20Sopenharmony_ci if (err) { 49818c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot obtain PCI resources\n"); 49828c2ecf20Sopenharmony_ci goto err_out_disable; 49838c2ecf20Sopenharmony_ci } 49848c2ecf20Sopenharmony_ci 49858c2ecf20Sopenharmony_ci pci_set_master(pdev); 49868c2ecf20Sopenharmony_ci 49878c2ecf20Sopenharmony_ci if (sizeof(dma_addr_t) > sizeof(u32) && 49888c2ecf20Sopenharmony_ci !(err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)))) { 49898c2ecf20Sopenharmony_ci using_dac = 1; 49908c2ecf20Sopenharmony_ci err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); 49918c2ecf20Sopenharmony_ci if (err < 0) { 49928c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "unable to obtain 64 bit DMA " 49938c2ecf20Sopenharmony_ci "for consistent allocations\n"); 49948c2ecf20Sopenharmony_ci goto err_out_free_regions; 49958c2ecf20Sopenharmony_ci } 49968c2ecf20Sopenharmony_ci } else { 49978c2ecf20Sopenharmony_ci err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); 49988c2ecf20Sopenharmony_ci if (err) { 49998c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "no usable DMA configuration\n"); 50008c2ecf20Sopenharmony_ci goto err_out_free_regions; 50018c2ecf20Sopenharmony_ci } 50028c2ecf20Sopenharmony_ci } 50038c2ecf20Sopenharmony_ci 50048c2ecf20Sopenharmony_ci 50058c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN 50068c2ecf20Sopenharmony_ci /* The sk98lin vendor driver uses hardware byte swapping but 50078c2ecf20Sopenharmony_ci * this driver uses software swapping. 50088c2ecf20Sopenharmony_ci */ 50098c2ecf20Sopenharmony_ci reg &= ~PCI_REV_DESC; 50108c2ecf20Sopenharmony_ci err = pci_write_config_dword(pdev, PCI_DEV_REG2, reg); 50118c2ecf20Sopenharmony_ci if (err) { 50128c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "PCI write config failed\n"); 50138c2ecf20Sopenharmony_ci goto err_out_free_regions; 50148c2ecf20Sopenharmony_ci } 50158c2ecf20Sopenharmony_ci#endif 50168c2ecf20Sopenharmony_ci 50178c2ecf20Sopenharmony_ci wol_default = device_may_wakeup(&pdev->dev) ? WAKE_MAGIC : 0; 50188c2ecf20Sopenharmony_ci 50198c2ecf20Sopenharmony_ci err = -ENOMEM; 50208c2ecf20Sopenharmony_ci 50218c2ecf20Sopenharmony_ci hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:") 50228c2ecf20Sopenharmony_ci + strlen(pci_name(pdev)) + 1, GFP_KERNEL); 50238c2ecf20Sopenharmony_ci if (!hw) 50248c2ecf20Sopenharmony_ci goto err_out_free_regions; 50258c2ecf20Sopenharmony_ci 50268c2ecf20Sopenharmony_ci hw->pdev = pdev; 50278c2ecf20Sopenharmony_ci sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev)); 50288c2ecf20Sopenharmony_ci 50298c2ecf20Sopenharmony_ci hw->regs = ioremap(pci_resource_start(pdev, 0), 0x4000); 50308c2ecf20Sopenharmony_ci if (!hw->regs) { 50318c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot map device registers\n"); 50328c2ecf20Sopenharmony_ci goto err_out_free_hw; 50338c2ecf20Sopenharmony_ci } 50348c2ecf20Sopenharmony_ci 50358c2ecf20Sopenharmony_ci err = sky2_init(hw); 50368c2ecf20Sopenharmony_ci if (err) 50378c2ecf20Sopenharmony_ci goto err_out_iounmap; 50388c2ecf20Sopenharmony_ci 50398c2ecf20Sopenharmony_ci /* ring for status responses */ 50408c2ecf20Sopenharmony_ci hw->st_size = hw->ports * roundup_pow_of_two(3*RX_MAX_PENDING + TX_MAX_PENDING); 50418c2ecf20Sopenharmony_ci hw->st_le = dma_alloc_coherent(&pdev->dev, 50428c2ecf20Sopenharmony_ci hw->st_size * sizeof(struct sky2_status_le), 50438c2ecf20Sopenharmony_ci &hw->st_dma, GFP_KERNEL); 50448c2ecf20Sopenharmony_ci if (!hw->st_le) { 50458c2ecf20Sopenharmony_ci err = -ENOMEM; 50468c2ecf20Sopenharmony_ci goto err_out_reset; 50478c2ecf20Sopenharmony_ci } 50488c2ecf20Sopenharmony_ci 50498c2ecf20Sopenharmony_ci dev_info(&pdev->dev, "Yukon-2 %s chip revision %d\n", 50508c2ecf20Sopenharmony_ci sky2_name(hw->chip_id, buf1, sizeof(buf1)), hw->chip_rev); 50518c2ecf20Sopenharmony_ci 50528c2ecf20Sopenharmony_ci sky2_reset(hw); 50538c2ecf20Sopenharmony_ci 50548c2ecf20Sopenharmony_ci dev = sky2_init_netdev(hw, 0, using_dac, wol_default); 50558c2ecf20Sopenharmony_ci if (!dev) { 50568c2ecf20Sopenharmony_ci err = -ENOMEM; 50578c2ecf20Sopenharmony_ci goto err_out_free_pci; 50588c2ecf20Sopenharmony_ci } 50598c2ecf20Sopenharmony_ci 50608c2ecf20Sopenharmony_ci if (disable_msi == -1) 50618c2ecf20Sopenharmony_ci disable_msi = !!dmi_check_system(msi_blacklist); 50628c2ecf20Sopenharmony_ci 50638c2ecf20Sopenharmony_ci if (!disable_msi && pci_enable_msi(pdev) == 0) { 50648c2ecf20Sopenharmony_ci err = sky2_test_msi(hw); 50658c2ecf20Sopenharmony_ci if (err) { 50668c2ecf20Sopenharmony_ci pci_disable_msi(pdev); 50678c2ecf20Sopenharmony_ci if (err != -EOPNOTSUPP) 50688c2ecf20Sopenharmony_ci goto err_out_free_netdev; 50698c2ecf20Sopenharmony_ci } 50708c2ecf20Sopenharmony_ci } 50718c2ecf20Sopenharmony_ci 50728c2ecf20Sopenharmony_ci netif_napi_add(dev, &hw->napi, sky2_poll, NAPI_WEIGHT); 50738c2ecf20Sopenharmony_ci 50748c2ecf20Sopenharmony_ci err = register_netdev(dev); 50758c2ecf20Sopenharmony_ci if (err) { 50768c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot register net device\n"); 50778c2ecf20Sopenharmony_ci goto err_out_free_netdev; 50788c2ecf20Sopenharmony_ci } 50798c2ecf20Sopenharmony_ci 50808c2ecf20Sopenharmony_ci netif_carrier_off(dev); 50818c2ecf20Sopenharmony_ci 50828c2ecf20Sopenharmony_ci sky2_show_addr(dev); 50838c2ecf20Sopenharmony_ci 50848c2ecf20Sopenharmony_ci if (hw->ports > 1) { 50858c2ecf20Sopenharmony_ci dev1 = sky2_init_netdev(hw, 1, using_dac, wol_default); 50868c2ecf20Sopenharmony_ci if (!dev1) { 50878c2ecf20Sopenharmony_ci err = -ENOMEM; 50888c2ecf20Sopenharmony_ci goto err_out_unregister; 50898c2ecf20Sopenharmony_ci } 50908c2ecf20Sopenharmony_ci 50918c2ecf20Sopenharmony_ci err = register_netdev(dev1); 50928c2ecf20Sopenharmony_ci if (err) { 50938c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "cannot register second net device\n"); 50948c2ecf20Sopenharmony_ci goto err_out_free_dev1; 50958c2ecf20Sopenharmony_ci } 50968c2ecf20Sopenharmony_ci 50978c2ecf20Sopenharmony_ci err = sky2_setup_irq(hw, hw->irq_name); 50988c2ecf20Sopenharmony_ci if (err) 50998c2ecf20Sopenharmony_ci goto err_out_unregister_dev1; 51008c2ecf20Sopenharmony_ci 51018c2ecf20Sopenharmony_ci sky2_show_addr(dev1); 51028c2ecf20Sopenharmony_ci } 51038c2ecf20Sopenharmony_ci 51048c2ecf20Sopenharmony_ci timer_setup(&hw->watchdog_timer, sky2_watchdog, 0); 51058c2ecf20Sopenharmony_ci INIT_WORK(&hw->restart_work, sky2_restart); 51068c2ecf20Sopenharmony_ci 51078c2ecf20Sopenharmony_ci pci_set_drvdata(pdev, hw); 51088c2ecf20Sopenharmony_ci pdev->d3hot_delay = 300; 51098c2ecf20Sopenharmony_ci 51108c2ecf20Sopenharmony_ci return 0; 51118c2ecf20Sopenharmony_ci 51128c2ecf20Sopenharmony_cierr_out_unregister_dev1: 51138c2ecf20Sopenharmony_ci unregister_netdev(dev1); 51148c2ecf20Sopenharmony_cierr_out_free_dev1: 51158c2ecf20Sopenharmony_ci free_netdev(dev1); 51168c2ecf20Sopenharmony_cierr_out_unregister: 51178c2ecf20Sopenharmony_ci unregister_netdev(dev); 51188c2ecf20Sopenharmony_cierr_out_free_netdev: 51198c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_USE_MSI) 51208c2ecf20Sopenharmony_ci pci_disable_msi(pdev); 51218c2ecf20Sopenharmony_ci free_netdev(dev); 51228c2ecf20Sopenharmony_cierr_out_free_pci: 51238c2ecf20Sopenharmony_ci dma_free_coherent(&pdev->dev, 51248c2ecf20Sopenharmony_ci hw->st_size * sizeof(struct sky2_status_le), 51258c2ecf20Sopenharmony_ci hw->st_le, hw->st_dma); 51268c2ecf20Sopenharmony_cierr_out_reset: 51278c2ecf20Sopenharmony_ci sky2_write8(hw, B0_CTST, CS_RST_SET); 51288c2ecf20Sopenharmony_cierr_out_iounmap: 51298c2ecf20Sopenharmony_ci iounmap(hw->regs); 51308c2ecf20Sopenharmony_cierr_out_free_hw: 51318c2ecf20Sopenharmony_ci kfree(hw); 51328c2ecf20Sopenharmony_cierr_out_free_regions: 51338c2ecf20Sopenharmony_ci pci_release_regions(pdev); 51348c2ecf20Sopenharmony_cierr_out_disable: 51358c2ecf20Sopenharmony_ci pci_disable_device(pdev); 51368c2ecf20Sopenharmony_cierr_out: 51378c2ecf20Sopenharmony_ci return err; 51388c2ecf20Sopenharmony_ci} 51398c2ecf20Sopenharmony_ci 51408c2ecf20Sopenharmony_cistatic void sky2_remove(struct pci_dev *pdev) 51418c2ecf20Sopenharmony_ci{ 51428c2ecf20Sopenharmony_ci struct sky2_hw *hw = pci_get_drvdata(pdev); 51438c2ecf20Sopenharmony_ci int i; 51448c2ecf20Sopenharmony_ci 51458c2ecf20Sopenharmony_ci if (!hw) 51468c2ecf20Sopenharmony_ci return; 51478c2ecf20Sopenharmony_ci 51488c2ecf20Sopenharmony_ci del_timer_sync(&hw->watchdog_timer); 51498c2ecf20Sopenharmony_ci cancel_work_sync(&hw->restart_work); 51508c2ecf20Sopenharmony_ci 51518c2ecf20Sopenharmony_ci for (i = hw->ports-1; i >= 0; --i) 51528c2ecf20Sopenharmony_ci unregister_netdev(hw->dev[i]); 51538c2ecf20Sopenharmony_ci 51548c2ecf20Sopenharmony_ci sky2_write32(hw, B0_IMSK, 0); 51558c2ecf20Sopenharmony_ci sky2_read32(hw, B0_IMSK); 51568c2ecf20Sopenharmony_ci 51578c2ecf20Sopenharmony_ci sky2_power_aux(hw); 51588c2ecf20Sopenharmony_ci 51598c2ecf20Sopenharmony_ci sky2_write8(hw, B0_CTST, CS_RST_SET); 51608c2ecf20Sopenharmony_ci sky2_read8(hw, B0_CTST); 51618c2ecf20Sopenharmony_ci 51628c2ecf20Sopenharmony_ci if (hw->ports > 1) { 51638c2ecf20Sopenharmony_ci napi_disable(&hw->napi); 51648c2ecf20Sopenharmony_ci free_irq(pdev->irq, hw); 51658c2ecf20Sopenharmony_ci } 51668c2ecf20Sopenharmony_ci 51678c2ecf20Sopenharmony_ci if (hw->flags & SKY2_HW_USE_MSI) 51688c2ecf20Sopenharmony_ci pci_disable_msi(pdev); 51698c2ecf20Sopenharmony_ci dma_free_coherent(&pdev->dev, 51708c2ecf20Sopenharmony_ci hw->st_size * sizeof(struct sky2_status_le), 51718c2ecf20Sopenharmony_ci hw->st_le, hw->st_dma); 51728c2ecf20Sopenharmony_ci pci_release_regions(pdev); 51738c2ecf20Sopenharmony_ci pci_disable_device(pdev); 51748c2ecf20Sopenharmony_ci 51758c2ecf20Sopenharmony_ci for (i = hw->ports-1; i >= 0; --i) 51768c2ecf20Sopenharmony_ci free_netdev(hw->dev[i]); 51778c2ecf20Sopenharmony_ci 51788c2ecf20Sopenharmony_ci iounmap(hw->regs); 51798c2ecf20Sopenharmony_ci kfree(hw); 51808c2ecf20Sopenharmony_ci} 51818c2ecf20Sopenharmony_ci 51828c2ecf20Sopenharmony_cistatic int sky2_suspend(struct device *dev) 51838c2ecf20Sopenharmony_ci{ 51848c2ecf20Sopenharmony_ci struct sky2_hw *hw = dev_get_drvdata(dev); 51858c2ecf20Sopenharmony_ci int i; 51868c2ecf20Sopenharmony_ci 51878c2ecf20Sopenharmony_ci if (!hw) 51888c2ecf20Sopenharmony_ci return 0; 51898c2ecf20Sopenharmony_ci 51908c2ecf20Sopenharmony_ci del_timer_sync(&hw->watchdog_timer); 51918c2ecf20Sopenharmony_ci cancel_work_sync(&hw->restart_work); 51928c2ecf20Sopenharmony_ci 51938c2ecf20Sopenharmony_ci rtnl_lock(); 51948c2ecf20Sopenharmony_ci 51958c2ecf20Sopenharmony_ci sky2_all_down(hw); 51968c2ecf20Sopenharmony_ci for (i = 0; i < hw->ports; i++) { 51978c2ecf20Sopenharmony_ci struct net_device *dev = hw->dev[i]; 51988c2ecf20Sopenharmony_ci struct sky2_port *sky2 = netdev_priv(dev); 51998c2ecf20Sopenharmony_ci 52008c2ecf20Sopenharmony_ci if (sky2->wol) 52018c2ecf20Sopenharmony_ci sky2_wol_init(sky2); 52028c2ecf20Sopenharmony_ci } 52038c2ecf20Sopenharmony_ci 52048c2ecf20Sopenharmony_ci sky2_power_aux(hw); 52058c2ecf20Sopenharmony_ci rtnl_unlock(); 52068c2ecf20Sopenharmony_ci 52078c2ecf20Sopenharmony_ci return 0; 52088c2ecf20Sopenharmony_ci} 52098c2ecf20Sopenharmony_ci 52108c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 52118c2ecf20Sopenharmony_cistatic int sky2_resume(struct device *dev) 52128c2ecf20Sopenharmony_ci{ 52138c2ecf20Sopenharmony_ci struct pci_dev *pdev = to_pci_dev(dev); 52148c2ecf20Sopenharmony_ci struct sky2_hw *hw = pci_get_drvdata(pdev); 52158c2ecf20Sopenharmony_ci int err; 52168c2ecf20Sopenharmony_ci 52178c2ecf20Sopenharmony_ci if (!hw) 52188c2ecf20Sopenharmony_ci return 0; 52198c2ecf20Sopenharmony_ci 52208c2ecf20Sopenharmony_ci /* Re-enable all clocks */ 52218c2ecf20Sopenharmony_ci err = pci_write_config_dword(pdev, PCI_DEV_REG3, 0); 52228c2ecf20Sopenharmony_ci if (err) { 52238c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "PCI write config failed\n"); 52248c2ecf20Sopenharmony_ci goto out; 52258c2ecf20Sopenharmony_ci } 52268c2ecf20Sopenharmony_ci 52278c2ecf20Sopenharmony_ci rtnl_lock(); 52288c2ecf20Sopenharmony_ci sky2_reset(hw); 52298c2ecf20Sopenharmony_ci sky2_all_up(hw); 52308c2ecf20Sopenharmony_ci rtnl_unlock(); 52318c2ecf20Sopenharmony_ci 52328c2ecf20Sopenharmony_ci return 0; 52338c2ecf20Sopenharmony_ciout: 52348c2ecf20Sopenharmony_ci 52358c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "resume failed (%d)\n", err); 52368c2ecf20Sopenharmony_ci pci_disable_device(pdev); 52378c2ecf20Sopenharmony_ci return err; 52388c2ecf20Sopenharmony_ci} 52398c2ecf20Sopenharmony_ci 52408c2ecf20Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(sky2_pm_ops, sky2_suspend, sky2_resume); 52418c2ecf20Sopenharmony_ci#define SKY2_PM_OPS (&sky2_pm_ops) 52428c2ecf20Sopenharmony_ci 52438c2ecf20Sopenharmony_ci#else 52448c2ecf20Sopenharmony_ci 52458c2ecf20Sopenharmony_ci#define SKY2_PM_OPS NULL 52468c2ecf20Sopenharmony_ci#endif 52478c2ecf20Sopenharmony_ci 52488c2ecf20Sopenharmony_cistatic void sky2_shutdown(struct pci_dev *pdev) 52498c2ecf20Sopenharmony_ci{ 52508c2ecf20Sopenharmony_ci struct sky2_hw *hw = pci_get_drvdata(pdev); 52518c2ecf20Sopenharmony_ci int port; 52528c2ecf20Sopenharmony_ci 52538c2ecf20Sopenharmony_ci for (port = 0; port < hw->ports; port++) { 52548c2ecf20Sopenharmony_ci struct net_device *ndev = hw->dev[port]; 52558c2ecf20Sopenharmony_ci 52568c2ecf20Sopenharmony_ci rtnl_lock(); 52578c2ecf20Sopenharmony_ci if (netif_running(ndev)) { 52588c2ecf20Sopenharmony_ci dev_close(ndev); 52598c2ecf20Sopenharmony_ci netif_device_detach(ndev); 52608c2ecf20Sopenharmony_ci } 52618c2ecf20Sopenharmony_ci rtnl_unlock(); 52628c2ecf20Sopenharmony_ci } 52638c2ecf20Sopenharmony_ci sky2_suspend(&pdev->dev); 52648c2ecf20Sopenharmony_ci pci_wake_from_d3(pdev, device_may_wakeup(&pdev->dev)); 52658c2ecf20Sopenharmony_ci pci_set_power_state(pdev, PCI_D3hot); 52668c2ecf20Sopenharmony_ci} 52678c2ecf20Sopenharmony_ci 52688c2ecf20Sopenharmony_cistatic struct pci_driver sky2_driver = { 52698c2ecf20Sopenharmony_ci .name = DRV_NAME, 52708c2ecf20Sopenharmony_ci .id_table = sky2_id_table, 52718c2ecf20Sopenharmony_ci .probe = sky2_probe, 52728c2ecf20Sopenharmony_ci .remove = sky2_remove, 52738c2ecf20Sopenharmony_ci .shutdown = sky2_shutdown, 52748c2ecf20Sopenharmony_ci .driver.pm = SKY2_PM_OPS, 52758c2ecf20Sopenharmony_ci}; 52768c2ecf20Sopenharmony_ci 52778c2ecf20Sopenharmony_cistatic int __init sky2_init_module(void) 52788c2ecf20Sopenharmony_ci{ 52798c2ecf20Sopenharmony_ci pr_info("driver version " DRV_VERSION "\n"); 52808c2ecf20Sopenharmony_ci 52818c2ecf20Sopenharmony_ci sky2_debug_init(); 52828c2ecf20Sopenharmony_ci return pci_register_driver(&sky2_driver); 52838c2ecf20Sopenharmony_ci} 52848c2ecf20Sopenharmony_ci 52858c2ecf20Sopenharmony_cistatic void __exit sky2_cleanup_module(void) 52868c2ecf20Sopenharmony_ci{ 52878c2ecf20Sopenharmony_ci pci_unregister_driver(&sky2_driver); 52888c2ecf20Sopenharmony_ci sky2_debug_cleanup(); 52898c2ecf20Sopenharmony_ci} 52908c2ecf20Sopenharmony_ci 52918c2ecf20Sopenharmony_cimodule_init(sky2_init_module); 52928c2ecf20Sopenharmony_cimodule_exit(sky2_cleanup_module); 52938c2ecf20Sopenharmony_ci 52948c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver"); 52958c2ecf20Sopenharmony_ciMODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>"); 52968c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 52978c2ecf20Sopenharmony_ciMODULE_VERSION(DRV_VERSION); 5298