Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1 | /* |
| 2 | * New driver for Marvell Yukon chipset and SysKonnect Gigabit |
| 3 | * Ethernet adapters. Based on earlier sk98lin, e100 and |
| 4 | * FreeBSD if_sk drivers. |
| 5 | * |
| 6 | * This driver intentionally does not support all the features |
| 7 | * of the original driver such as link fail-over and link management because |
| 8 | * those should be done at higher levels. |
| 9 | * |
Stephen Hemminger | 747802a | 2005-06-27 11:33:16 -0700 | [diff] [blame] | 10 | * Copyright (C) 2004, 2005 Stephen Hemminger <shemminger@osdl.org> |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
Stephen Hemminger | 798b6b1 | 2006-10-22 20:16:57 -0700 | [diff] [blame] | 14 | * the Free Software Foundation; either version 2 of the License. |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | */ |
| 25 | |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 26 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 27 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 28 | #include <linux/in.h> |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/moduleparam.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/etherdevice.h> |
| 34 | #include <linux/ethtool.h> |
| 35 | #include <linux/pci.h> |
| 36 | #include <linux/if_vlan.h> |
| 37 | #include <linux/ip.h> |
| 38 | #include <linux/delay.h> |
| 39 | #include <linux/crc32.h> |
Al Viro | 4075400 | 2005-04-03 09:15:52 +0100 | [diff] [blame] | 40 | #include <linux/dma-mapping.h> |
Stephen Hemminger | 678aa1f | 2007-10-16 12:15:54 -0700 | [diff] [blame] | 41 | #include <linux/debugfs.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 42 | #include <linux/sched.h> |
Stephen Hemminger | 678aa1f | 2007-10-16 12:15:54 -0700 | [diff] [blame] | 43 | #include <linux/seq_file.h> |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 44 | #include <linux/mii.h> |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 45 | #include <asm/irq.h> |
| 46 | |
| 47 | #include "skge.h" |
| 48 | |
| 49 | #define DRV_NAME "skge" |
Stephen Hemminger | bf9f56d | 2007-11-26 11:54:53 -0800 | [diff] [blame] | 50 | #define DRV_VERSION "1.13" |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 51 | |
| 52 | #define DEFAULT_TX_RING_SIZE 128 |
| 53 | #define DEFAULT_RX_RING_SIZE 512 |
| 54 | #define MAX_TX_RING_SIZE 1024 |
Stephen Hemminger | 9db9647 | 2006-06-06 10:11:12 -0700 | [diff] [blame] | 55 | #define TX_LOW_WATER (MAX_SKB_FRAGS + 1) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 56 | #define MAX_RX_RING_SIZE 4096 |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 57 | #define RX_COPY_THRESHOLD 128 |
| 58 | #define RX_BUF_SIZE 1536 |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 59 | #define PHY_RETRIES 1000 |
| 60 | #define ETH_JUMBO_MTU 9000 |
| 61 | #define TX_WATCHDOG (5 * HZ) |
| 62 | #define NAPI_WEIGHT 64 |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 63 | #define BLINK_MS 250 |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 64 | #define LINK_HZ HZ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 65 | |
Stephen Hemminger | afa151b | 2007-10-16 12:15:53 -0700 | [diff] [blame] | 66 | #define SKGE_EEPROM_MAGIC 0x9933aabb |
| 67 | |
| 68 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 69 | MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver"); |
Stephen Hemminger | 65ebe634 | 2007-01-23 11:38:57 -0800 | [diff] [blame] | 70 | MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 71 | MODULE_LICENSE("GPL"); |
| 72 | MODULE_VERSION(DRV_VERSION); |
| 73 | |
| 74 | static const u32 default_msg |
| 75 | = NETIF_MSG_DRV| NETIF_MSG_PROBE| NETIF_MSG_LINK |
| 76 | | NETIF_MSG_IFUP| NETIF_MSG_IFDOWN; |
| 77 | |
| 78 | static int debug = -1; /* defaults above */ |
| 79 | module_param(debug, int, 0); |
| 80 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 81 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 82 | static DEFINE_PCI_DEVICE_TABLE(skge_id_table) = { |
Stephen Hemminger | 275834d | 2005-06-27 11:33:03 -0700 | [diff] [blame] | 83 | { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940) }, |
| 84 | { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B) }, |
| 85 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) }, |
| 86 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) }, |
Stephen Hemminger | f19841f | 2007-02-23 14:04:54 -0800 | [diff] [blame] | 87 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T) }, |
Stephen Hemminger | 2d2a387 | 2006-05-17 14:37:04 -0700 | [diff] [blame] | 88 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) }, /* DGE-530T */ |
Stephen Hemminger | 275834d | 2005-06-27 11:33:03 -0700 | [diff] [blame] | 89 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) }, |
| 90 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */ |
| 91 | { PCI_DEVICE(PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD) }, |
Stephen Hemminger | 275834d | 2005-06-27 11:33:03 -0700 | [diff] [blame] | 92 | { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1064) }, |
Stephen Hemminger | f19841f | 2007-02-23 14:04:54 -0800 | [diff] [blame] | 93 | { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015 }, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 94 | { 0 } |
| 95 | }; |
| 96 | MODULE_DEVICE_TABLE(pci, skge_id_table); |
| 97 | |
| 98 | static int skge_up(struct net_device *dev); |
| 99 | static int skge_down(struct net_device *dev); |
Stephen Hemminger | ee294dc | 2005-12-14 15:47:44 -0800 | [diff] [blame] | 100 | static void skge_phy_reset(struct skge_port *skge); |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 101 | static void skge_tx_clean(struct net_device *dev); |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 102 | static int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val); |
| 103 | static int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 104 | static void genesis_get_stats(struct skge_port *skge, u64 *data); |
| 105 | static void yukon_get_stats(struct skge_port *skge, u64 *data); |
| 106 | static void yukon_init(struct skge_hw *hw, int port); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 107 | static void genesis_mac_init(struct skge_hw *hw, int port); |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 108 | static void genesis_link_up(struct skge_port *skge); |
Stephen Hemminger | f80d032 | 2008-11-19 22:01:26 -0800 | [diff] [blame] | 109 | static void skge_set_multicast(struct net_device *dev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 110 | |
Stephen Hemminger | 7e676d9 | 2005-06-27 11:33:13 -0700 | [diff] [blame] | 111 | /* Avoid conditionals by using array */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 112 | static const int txqaddr[] = { Q_XA1, Q_XA2 }; |
| 113 | static const int rxqaddr[] = { Q_R1, Q_R2 }; |
| 114 | static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F }; |
| 115 | static const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F }; |
Stephen Hemminger | 4ebabfc | 2007-03-16 14:01:27 -0700 | [diff] [blame] | 116 | static const u32 napimask[] = { IS_R1_F|IS_XA1_F, IS_R2_F|IS_XA2_F }; |
| 117 | static const u32 portmask[] = { IS_PORT_1, IS_PORT_2 }; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 118 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 119 | static int skge_get_regs_len(struct net_device *dev) |
| 120 | { |
Stephen Hemminger | c3f8be9 | 2005-09-19 15:37:34 -0700 | [diff] [blame] | 121 | return 0x4000; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /* |
Stephen Hemminger | c3f8be9 | 2005-09-19 15:37:34 -0700 | [diff] [blame] | 125 | * Returns copy of whole control register region |
| 126 | * Note: skip RAM address register because accessing it will |
| 127 | * cause bus hangs! |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 128 | */ |
| 129 | static void skge_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 130 | void *p) |
| 131 | { |
| 132 | const struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 133 | const void __iomem *io = skge->hw->regs; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 134 | |
| 135 | regs->version = 1; |
Stephen Hemminger | c3f8be9 | 2005-09-19 15:37:34 -0700 | [diff] [blame] | 136 | memset(p, 0, regs->len); |
| 137 | memcpy_fromio(p, io, B3_RAM_ADDR); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 138 | |
Stephen Hemminger | c3f8be9 | 2005-09-19 15:37:34 -0700 | [diff] [blame] | 139 | memcpy_fromio(p + B3_RI_WTO_R1, io + B3_RI_WTO_R1, |
| 140 | regs->len - B3_RI_WTO_R1); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Stephen Hemminger | 8f3f819 | 2005-11-08 10:33:45 -0800 | [diff] [blame] | 143 | /* Wake on Lan only supported on Yukon chips with rev 1 or above */ |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 144 | static u32 wol_supported(const struct skge_hw *hw) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 145 | { |
Stephen Hemminger | d17ecb2 | 2007-05-07 11:01:55 -0700 | [diff] [blame] | 146 | if (hw->chip_id == CHIP_ID_GENESIS) |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 147 | return 0; |
Stephen Hemminger | d17ecb2 | 2007-05-07 11:01:55 -0700 | [diff] [blame] | 148 | |
| 149 | if (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0) |
| 150 | return 0; |
| 151 | |
| 152 | return WAKE_MAGIC | WAKE_PHY; |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 155 | static void skge_wol_init(struct skge_port *skge) |
| 156 | { |
| 157 | struct skge_hw *hw = skge->hw; |
| 158 | int port = skge->port; |
Stephen Hemminger | 692412b | 2007-04-09 15:32:45 -0700 | [diff] [blame] | 159 | u16 ctrl; |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 160 | |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 161 | skge_write16(hw, B0_CTST, CS_RST_CLR); |
| 162 | skge_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR); |
| 163 | |
Stephen Hemminger | 692412b | 2007-04-09 15:32:45 -0700 | [diff] [blame] | 164 | /* Turn on Vaux */ |
| 165 | skge_write8(hw, B0_POWER_CTRL, |
| 166 | PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_ON | PC_VCC_OFF); |
| 167 | |
| 168 | /* WA code for COMA mode -- clear PHY reset */ |
| 169 | if (hw->chip_id == CHIP_ID_YUKON_LITE && |
| 170 | hw->chip_rev >= CHIP_REV_YU_LITE_A3) { |
| 171 | u32 reg = skge_read32(hw, B2_GP_IO); |
| 172 | reg |= GP_DIR_9; |
| 173 | reg &= ~GP_IO_9; |
| 174 | skge_write32(hw, B2_GP_IO, reg); |
| 175 | } |
| 176 | |
| 177 | skge_write32(hw, SK_REG(port, GPHY_CTRL), |
| 178 | GPC_DIS_SLEEP | |
| 179 | GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 | |
| 180 | GPC_ANEG_1 | GPC_RST_SET); |
| 181 | |
| 182 | skge_write32(hw, SK_REG(port, GPHY_CTRL), |
| 183 | GPC_DIS_SLEEP | |
| 184 | GPC_HWCFG_M_3 | GPC_HWCFG_M_2 | GPC_HWCFG_M_1 | GPC_HWCFG_M_0 | |
| 185 | GPC_ANEG_1 | GPC_RST_CLR); |
| 186 | |
| 187 | skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR); |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 188 | |
| 189 | /* Force to 10/100 skge_reset will re-enable on resume */ |
Stephen Hemminger | 692412b | 2007-04-09 15:32:45 -0700 | [diff] [blame] | 190 | gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, |
| 191 | PHY_AN_100FULL | PHY_AN_100HALF | |
| 192 | PHY_AN_10FULL | PHY_AN_10HALF| PHY_AN_CSMA); |
| 193 | /* no 1000 HD/FD */ |
| 194 | gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, 0); |
| 195 | gm_phy_write(hw, port, PHY_MARV_CTRL, |
| 196 | PHY_CT_RESET | PHY_CT_SPS_LSB | PHY_CT_ANE | |
| 197 | PHY_CT_RE_CFG | PHY_CT_DUP_MD); |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 198 | |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 199 | |
| 200 | /* Set GMAC to no flow control and auto update for speed/duplex */ |
| 201 | gma_write16(hw, port, GM_GP_CTRL, |
| 202 | GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA| |
| 203 | GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS); |
| 204 | |
| 205 | /* Set WOL address */ |
| 206 | memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR), |
| 207 | skge->netdev->dev_addr, ETH_ALEN); |
| 208 | |
| 209 | /* Turn on appropriate WOL control bits */ |
| 210 | skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT); |
| 211 | ctrl = 0; |
| 212 | if (skge->wol & WAKE_PHY) |
| 213 | ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT; |
| 214 | else |
| 215 | ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT; |
| 216 | |
| 217 | if (skge->wol & WAKE_MAGIC) |
| 218 | ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT; |
| 219 | else |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 220 | ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT; |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 221 | |
| 222 | ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT; |
| 223 | skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl); |
| 224 | |
| 225 | /* block receiver */ |
| 226 | skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | static void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 230 | { |
| 231 | struct skge_port *skge = netdev_priv(dev); |
| 232 | |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 233 | wol->supported = wol_supported(skge->hw); |
| 234 | wol->wolopts = skge->wol; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 238 | { |
| 239 | struct skge_port *skge = netdev_priv(dev); |
| 240 | struct skge_hw *hw = skge->hw; |
| 241 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 242 | if ((wol->wolopts & ~wol_supported(hw)) || |
| 243 | !device_can_wakeup(&hw->pdev->dev)) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 244 | return -EOPNOTSUPP; |
| 245 | |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 246 | skge->wol = wol->wolopts; |
Rafael J. Wysocki | 5177b32 | 2008-10-29 14:22:14 -0700 | [diff] [blame] | 247 | |
| 248 | device_set_wakeup_enable(&hw->pdev->dev, skge->wol); |
| 249 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 250 | return 0; |
| 251 | } |
| 252 | |
Stephen Hemminger | 8f3f819 | 2005-11-08 10:33:45 -0800 | [diff] [blame] | 253 | /* Determine supported/advertised modes based on hardware. |
| 254 | * Note: ethtool ADVERTISED_xxx == SUPPORTED_xxx |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 255 | */ |
| 256 | static u32 skge_supported_modes(const struct skge_hw *hw) |
| 257 | { |
| 258 | u32 supported; |
| 259 | |
Stephen Hemminger | 5e1705d | 2005-08-16 14:00:58 -0700 | [diff] [blame] | 260 | if (hw->copper) { |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 261 | supported = SUPPORTED_10baseT_Half |
| 262 | | SUPPORTED_10baseT_Full |
| 263 | | SUPPORTED_100baseT_Half |
| 264 | | SUPPORTED_100baseT_Full |
| 265 | | SUPPORTED_1000baseT_Half |
| 266 | | SUPPORTED_1000baseT_Full |
| 267 | | SUPPORTED_Autoneg| SUPPORTED_TP; |
| 268 | |
| 269 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 270 | supported &= ~(SUPPORTED_10baseT_Half |
| 271 | | SUPPORTED_10baseT_Full |
| 272 | | SUPPORTED_100baseT_Half |
| 273 | | SUPPORTED_100baseT_Full); |
| 274 | |
| 275 | else if (hw->chip_id == CHIP_ID_YUKON) |
| 276 | supported &= ~SUPPORTED_1000baseT_Half; |
| 277 | } else |
Stephen Hemminger | 4b67be9 | 2006-10-05 15:49:51 -0700 | [diff] [blame] | 278 | supported = SUPPORTED_1000baseT_Full | SUPPORTED_1000baseT_Half |
| 279 | | SUPPORTED_FIBRE | SUPPORTED_Autoneg; |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 280 | |
| 281 | return supported; |
| 282 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 283 | |
| 284 | static int skge_get_settings(struct net_device *dev, |
| 285 | struct ethtool_cmd *ecmd) |
| 286 | { |
| 287 | struct skge_port *skge = netdev_priv(dev); |
| 288 | struct skge_hw *hw = skge->hw; |
| 289 | |
| 290 | ecmd->transceiver = XCVR_INTERNAL; |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 291 | ecmd->supported = skge_supported_modes(hw); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 292 | |
Stephen Hemminger | 5e1705d | 2005-08-16 14:00:58 -0700 | [diff] [blame] | 293 | if (hw->copper) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 294 | ecmd->port = PORT_TP; |
| 295 | ecmd->phy_address = hw->phy_addr; |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 296 | } else |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 297 | ecmd->port = PORT_FIBRE; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 298 | |
| 299 | ecmd->advertising = skge->advertising; |
| 300 | ecmd->autoneg = skge->autoneg; |
| 301 | ecmd->speed = skge->speed; |
| 302 | ecmd->duplex = skge->duplex; |
| 303 | return 0; |
| 304 | } |
| 305 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 306 | static int skge_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 307 | { |
| 308 | struct skge_port *skge = netdev_priv(dev); |
| 309 | const struct skge_hw *hw = skge->hw; |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 310 | u32 supported = skge_supported_modes(hw); |
Xiaoming.Zhang | 9ac1353 | 2008-09-25 20:28:05 +0000 | [diff] [blame] | 311 | int err = 0; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 312 | |
| 313 | if (ecmd->autoneg == AUTONEG_ENABLE) { |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 314 | ecmd->advertising = supported; |
| 315 | skge->duplex = -1; |
| 316 | skge->speed = -1; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 317 | } else { |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 318 | u32 setting; |
| 319 | |
Stephen Hemminger | 2c66851 | 2005-07-22 16:26:07 -0700 | [diff] [blame] | 320 | switch (ecmd->speed) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 321 | case SPEED_1000: |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 322 | if (ecmd->duplex == DUPLEX_FULL) |
| 323 | setting = SUPPORTED_1000baseT_Full; |
| 324 | else if (ecmd->duplex == DUPLEX_HALF) |
| 325 | setting = SUPPORTED_1000baseT_Half; |
| 326 | else |
| 327 | return -EINVAL; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 328 | break; |
| 329 | case SPEED_100: |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 330 | if (ecmd->duplex == DUPLEX_FULL) |
| 331 | setting = SUPPORTED_100baseT_Full; |
| 332 | else if (ecmd->duplex == DUPLEX_HALF) |
| 333 | setting = SUPPORTED_100baseT_Half; |
| 334 | else |
| 335 | return -EINVAL; |
| 336 | break; |
| 337 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 338 | case SPEED_10: |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 339 | if (ecmd->duplex == DUPLEX_FULL) |
| 340 | setting = SUPPORTED_10baseT_Full; |
| 341 | else if (ecmd->duplex == DUPLEX_HALF) |
| 342 | setting = SUPPORTED_10baseT_Half; |
| 343 | else |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 344 | return -EINVAL; |
| 345 | break; |
| 346 | default: |
| 347 | return -EINVAL; |
| 348 | } |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 349 | |
| 350 | if ((setting & supported) == 0) |
| 351 | return -EINVAL; |
| 352 | |
| 353 | skge->speed = ecmd->speed; |
| 354 | skge->duplex = ecmd->duplex; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | skge->autoneg = ecmd->autoneg; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 358 | skge->advertising = ecmd->advertising; |
| 359 | |
Xiaoming.Zhang | 9ac1353 | 2008-09-25 20:28:05 +0000 | [diff] [blame] | 360 | if (netif_running(dev)) { |
| 361 | skge_down(dev); |
| 362 | err = skge_up(dev); |
| 363 | if (err) { |
| 364 | dev_close(dev); |
| 365 | return err; |
| 366 | } |
| 367 | } |
Stephen Hemminger | ee294dc | 2005-12-14 15:47:44 -0800 | [diff] [blame] | 368 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 369 | return (0); |
| 370 | } |
| 371 | |
| 372 | static void skge_get_drvinfo(struct net_device *dev, |
| 373 | struct ethtool_drvinfo *info) |
| 374 | { |
| 375 | struct skge_port *skge = netdev_priv(dev); |
| 376 | |
| 377 | strcpy(info->driver, DRV_NAME); |
| 378 | strcpy(info->version, DRV_VERSION); |
| 379 | strcpy(info->fw_version, "N/A"); |
| 380 | strcpy(info->bus_info, pci_name(skge->hw->pdev)); |
| 381 | } |
| 382 | |
| 383 | static const struct skge_stat { |
| 384 | char name[ETH_GSTRING_LEN]; |
| 385 | u16 xmac_offset; |
| 386 | u16 gma_offset; |
| 387 | } skge_stats[] = { |
| 388 | { "tx_bytes", XM_TXO_OK_HI, GM_TXO_OK_HI }, |
| 389 | { "rx_bytes", XM_RXO_OK_HI, GM_RXO_OK_HI }, |
| 390 | |
| 391 | { "tx_broadcast", XM_TXF_BC_OK, GM_TXF_BC_OK }, |
| 392 | { "rx_broadcast", XM_RXF_BC_OK, GM_RXF_BC_OK }, |
| 393 | { "tx_multicast", XM_TXF_MC_OK, GM_TXF_MC_OK }, |
| 394 | { "rx_multicast", XM_RXF_MC_OK, GM_RXF_MC_OK }, |
| 395 | { "tx_unicast", XM_TXF_UC_OK, GM_TXF_UC_OK }, |
| 396 | { "rx_unicast", XM_RXF_UC_OK, GM_RXF_UC_OK }, |
| 397 | { "tx_mac_pause", XM_TXF_MPAUSE, GM_TXF_MPAUSE }, |
| 398 | { "rx_mac_pause", XM_RXF_MPAUSE, GM_RXF_MPAUSE }, |
| 399 | |
| 400 | { "collisions", XM_TXF_SNG_COL, GM_TXF_SNG_COL }, |
| 401 | { "multi_collisions", XM_TXF_MUL_COL, GM_TXF_MUL_COL }, |
| 402 | { "aborted", XM_TXF_ABO_COL, GM_TXF_ABO_COL }, |
| 403 | { "late_collision", XM_TXF_LAT_COL, GM_TXF_LAT_COL }, |
| 404 | { "fifo_underrun", XM_TXE_FIFO_UR, GM_TXE_FIFO_UR }, |
| 405 | { "fifo_overflow", XM_RXE_FIFO_OV, GM_RXE_FIFO_OV }, |
| 406 | |
| 407 | { "rx_toolong", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR }, |
| 408 | { "rx_jabber", XM_RXF_JAB_PKT, GM_RXF_JAB_PKT }, |
| 409 | { "rx_runt", XM_RXE_RUNT, GM_RXE_FRAG }, |
| 410 | { "rx_too_long", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR }, |
| 411 | { "rx_fcs_error", XM_RXF_FCS_ERR, GM_RXF_FCS_ERR }, |
| 412 | }; |
| 413 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 414 | static int skge_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 415 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 416 | switch (sset) { |
| 417 | case ETH_SS_STATS: |
| 418 | return ARRAY_SIZE(skge_stats); |
| 419 | default: |
| 420 | return -EOPNOTSUPP; |
| 421 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | static void skge_get_ethtool_stats(struct net_device *dev, |
| 425 | struct ethtool_stats *stats, u64 *data) |
| 426 | { |
| 427 | struct skge_port *skge = netdev_priv(dev); |
| 428 | |
| 429 | if (skge->hw->chip_id == CHIP_ID_GENESIS) |
| 430 | genesis_get_stats(skge, data); |
| 431 | else |
| 432 | yukon_get_stats(skge, data); |
| 433 | } |
| 434 | |
| 435 | /* Use hardware MIB variables for critical path statistics and |
| 436 | * transmit feedback not reported at interrupt. |
| 437 | * Other errors are accounted for in interrupt handler. |
| 438 | */ |
| 439 | static struct net_device_stats *skge_get_stats(struct net_device *dev) |
| 440 | { |
| 441 | struct skge_port *skge = netdev_priv(dev); |
| 442 | u64 data[ARRAY_SIZE(skge_stats)]; |
| 443 | |
| 444 | if (skge->hw->chip_id == CHIP_ID_GENESIS) |
| 445 | genesis_get_stats(skge, data); |
| 446 | else |
| 447 | yukon_get_stats(skge, data); |
| 448 | |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 449 | dev->stats.tx_bytes = data[0]; |
| 450 | dev->stats.rx_bytes = data[1]; |
| 451 | dev->stats.tx_packets = data[2] + data[4] + data[6]; |
| 452 | dev->stats.rx_packets = data[3] + data[5] + data[7]; |
| 453 | dev->stats.multicast = data[3] + data[5]; |
| 454 | dev->stats.collisions = data[10]; |
| 455 | dev->stats.tx_aborted_errors = data[12]; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 456 | |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 457 | return &dev->stats; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static void skge_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 461 | { |
| 462 | int i; |
| 463 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 464 | switch (stringset) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 465 | case ETH_SS_STATS: |
| 466 | for (i = 0; i < ARRAY_SIZE(skge_stats); i++) |
| 467 | memcpy(data + i * ETH_GSTRING_LEN, |
| 468 | skge_stats[i].name, ETH_GSTRING_LEN); |
| 469 | break; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | static void skge_get_ring_param(struct net_device *dev, |
| 474 | struct ethtool_ringparam *p) |
| 475 | { |
| 476 | struct skge_port *skge = netdev_priv(dev); |
| 477 | |
| 478 | p->rx_max_pending = MAX_RX_RING_SIZE; |
| 479 | p->tx_max_pending = MAX_TX_RING_SIZE; |
| 480 | p->rx_mini_max_pending = 0; |
| 481 | p->rx_jumbo_max_pending = 0; |
| 482 | |
| 483 | p->rx_pending = skge->rx_ring.count; |
| 484 | p->tx_pending = skge->tx_ring.count; |
| 485 | p->rx_mini_pending = 0; |
| 486 | p->rx_jumbo_pending = 0; |
| 487 | } |
| 488 | |
| 489 | static int skge_set_ring_param(struct net_device *dev, |
| 490 | struct ethtool_ringparam *p) |
| 491 | { |
| 492 | struct skge_port *skge = netdev_priv(dev); |
Wang Chen | e824b3e | 2008-09-26 16:20:32 +0800 | [diff] [blame] | 493 | int err = 0; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 494 | |
| 495 | if (p->rx_pending == 0 || p->rx_pending > MAX_RX_RING_SIZE || |
Stephen Hemminger | 9db9647 | 2006-06-06 10:11:12 -0700 | [diff] [blame] | 496 | p->tx_pending < TX_LOW_WATER || p->tx_pending > MAX_TX_RING_SIZE) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 497 | return -EINVAL; |
| 498 | |
| 499 | skge->rx_ring.count = p->rx_pending; |
| 500 | skge->tx_ring.count = p->tx_pending; |
| 501 | |
| 502 | if (netif_running(dev)) { |
| 503 | skge_down(dev); |
Stephen Hemminger | 3b8bb47 | 2005-12-14 15:47:48 -0800 | [diff] [blame] | 504 | err = skge_up(dev); |
| 505 | if (err) |
| 506 | dev_close(dev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 507 | } |
| 508 | |
Wang Chen | e824b3e | 2008-09-26 16:20:32 +0800 | [diff] [blame] | 509 | return err; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | static u32 skge_get_msglevel(struct net_device *netdev) |
| 513 | { |
| 514 | struct skge_port *skge = netdev_priv(netdev); |
| 515 | return skge->msg_enable; |
| 516 | } |
| 517 | |
| 518 | static void skge_set_msglevel(struct net_device *netdev, u32 value) |
| 519 | { |
| 520 | struct skge_port *skge = netdev_priv(netdev); |
| 521 | skge->msg_enable = value; |
| 522 | } |
| 523 | |
| 524 | static int skge_nway_reset(struct net_device *dev) |
| 525 | { |
| 526 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 527 | |
| 528 | if (skge->autoneg != AUTONEG_ENABLE || !netif_running(dev)) |
| 529 | return -EINVAL; |
| 530 | |
Stephen Hemminger | ee294dc | 2005-12-14 15:47:44 -0800 | [diff] [blame] | 531 | skge_phy_reset(skge); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 532 | return 0; |
| 533 | } |
| 534 | |
| 535 | static int skge_set_sg(struct net_device *dev, u32 data) |
| 536 | { |
| 537 | struct skge_port *skge = netdev_priv(dev); |
| 538 | struct skge_hw *hw = skge->hw; |
| 539 | |
| 540 | if (hw->chip_id == CHIP_ID_GENESIS && data) |
| 541 | return -EOPNOTSUPP; |
| 542 | return ethtool_op_set_sg(dev, data); |
| 543 | } |
| 544 | |
| 545 | static int skge_set_tx_csum(struct net_device *dev, u32 data) |
| 546 | { |
| 547 | struct skge_port *skge = netdev_priv(dev); |
| 548 | struct skge_hw *hw = skge->hw; |
| 549 | |
| 550 | if (hw->chip_id == CHIP_ID_GENESIS && data) |
| 551 | return -EOPNOTSUPP; |
| 552 | |
| 553 | return ethtool_op_set_tx_csum(dev, data); |
| 554 | } |
| 555 | |
| 556 | static u32 skge_get_rx_csum(struct net_device *dev) |
| 557 | { |
| 558 | struct skge_port *skge = netdev_priv(dev); |
| 559 | |
| 560 | return skge->rx_csum; |
| 561 | } |
| 562 | |
| 563 | /* Only Yukon supports checksum offload. */ |
| 564 | static int skge_set_rx_csum(struct net_device *dev, u32 data) |
| 565 | { |
| 566 | struct skge_port *skge = netdev_priv(dev); |
| 567 | |
| 568 | if (skge->hw->chip_id == CHIP_ID_GENESIS && data) |
| 569 | return -EOPNOTSUPP; |
| 570 | |
| 571 | skge->rx_csum = data; |
| 572 | return 0; |
| 573 | } |
| 574 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 575 | static void skge_get_pauseparam(struct net_device *dev, |
| 576 | struct ethtool_pauseparam *ecmd) |
| 577 | { |
| 578 | struct skge_port *skge = netdev_priv(dev); |
| 579 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 580 | ecmd->rx_pause = ((skge->flow_control == FLOW_MODE_SYMMETRIC) || |
| 581 | (skge->flow_control == FLOW_MODE_SYM_OR_REM)); |
| 582 | ecmd->tx_pause = (ecmd->rx_pause || |
| 583 | (skge->flow_control == FLOW_MODE_LOC_SEND)); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 584 | |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 585 | ecmd->autoneg = ecmd->rx_pause || ecmd->tx_pause; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | static int skge_set_pauseparam(struct net_device *dev, |
| 589 | struct ethtool_pauseparam *ecmd) |
| 590 | { |
| 591 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 592 | struct ethtool_pauseparam old; |
Xiaoming.Zhang | 9ac1353 | 2008-09-25 20:28:05 +0000 | [diff] [blame] | 593 | int err = 0; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 594 | |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 595 | skge_get_pauseparam(dev, &old); |
| 596 | |
| 597 | if (ecmd->autoneg != old.autoneg) |
| 598 | skge->flow_control = ecmd->autoneg ? FLOW_MODE_NONE : FLOW_MODE_SYMMETRIC; |
| 599 | else { |
| 600 | if (ecmd->rx_pause && ecmd->tx_pause) |
| 601 | skge->flow_control = FLOW_MODE_SYMMETRIC; |
| 602 | else if (ecmd->rx_pause && !ecmd->tx_pause) |
| 603 | skge->flow_control = FLOW_MODE_SYM_OR_REM; |
| 604 | else if (!ecmd->rx_pause && ecmd->tx_pause) |
| 605 | skge->flow_control = FLOW_MODE_LOC_SEND; |
| 606 | else |
| 607 | skge->flow_control = FLOW_MODE_NONE; |
| 608 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 609 | |
Xiaoming.Zhang | 9ac1353 | 2008-09-25 20:28:05 +0000 | [diff] [blame] | 610 | if (netif_running(dev)) { |
| 611 | skge_down(dev); |
| 612 | err = skge_up(dev); |
| 613 | if (err) { |
| 614 | dev_close(dev); |
| 615 | return err; |
| 616 | } |
| 617 | } |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 618 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | /* Chip internal frequency for clock calculations */ |
| 623 | static inline u32 hwkhz(const struct skge_hw *hw) |
| 624 | { |
Stephen Hemminger | 187ff3b | 2006-07-19 14:08:42 -0700 | [diff] [blame] | 625 | return (hw->chip_id == CHIP_ID_GENESIS) ? 53125 : 78125; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 626 | } |
| 627 | |
Stephen Hemminger | 8f3f819 | 2005-11-08 10:33:45 -0800 | [diff] [blame] | 628 | /* Chip HZ to microseconds */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 629 | static inline u32 skge_clk2usec(const struct skge_hw *hw, u32 ticks) |
| 630 | { |
| 631 | return (ticks * 1000) / hwkhz(hw); |
| 632 | } |
| 633 | |
Stephen Hemminger | 8f3f819 | 2005-11-08 10:33:45 -0800 | [diff] [blame] | 634 | /* Microseconds to chip HZ */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 635 | static inline u32 skge_usecs2clk(const struct skge_hw *hw, u32 usec) |
| 636 | { |
| 637 | return hwkhz(hw) * usec / 1000; |
| 638 | } |
| 639 | |
| 640 | static int skge_get_coalesce(struct net_device *dev, |
| 641 | struct ethtool_coalesce *ecmd) |
| 642 | { |
| 643 | struct skge_port *skge = netdev_priv(dev); |
| 644 | struct skge_hw *hw = skge->hw; |
| 645 | int port = skge->port; |
| 646 | |
| 647 | ecmd->rx_coalesce_usecs = 0; |
| 648 | ecmd->tx_coalesce_usecs = 0; |
| 649 | |
| 650 | if (skge_read32(hw, B2_IRQM_CTRL) & TIM_START) { |
| 651 | u32 delay = skge_clk2usec(hw, skge_read32(hw, B2_IRQM_INI)); |
| 652 | u32 msk = skge_read32(hw, B2_IRQM_MSK); |
| 653 | |
| 654 | if (msk & rxirqmask[port]) |
| 655 | ecmd->rx_coalesce_usecs = delay; |
| 656 | if (msk & txirqmask[port]) |
| 657 | ecmd->tx_coalesce_usecs = delay; |
| 658 | } |
| 659 | |
| 660 | return 0; |
| 661 | } |
| 662 | |
| 663 | /* Note: interrupt timer is per board, but can turn on/off per port */ |
| 664 | static int skge_set_coalesce(struct net_device *dev, |
| 665 | struct ethtool_coalesce *ecmd) |
| 666 | { |
| 667 | struct skge_port *skge = netdev_priv(dev); |
| 668 | struct skge_hw *hw = skge->hw; |
| 669 | int port = skge->port; |
| 670 | u32 msk = skge_read32(hw, B2_IRQM_MSK); |
| 671 | u32 delay = 25; |
| 672 | |
| 673 | if (ecmd->rx_coalesce_usecs == 0) |
| 674 | msk &= ~rxirqmask[port]; |
| 675 | else if (ecmd->rx_coalesce_usecs < 25 || |
| 676 | ecmd->rx_coalesce_usecs > 33333) |
| 677 | return -EINVAL; |
| 678 | else { |
| 679 | msk |= rxirqmask[port]; |
| 680 | delay = ecmd->rx_coalesce_usecs; |
| 681 | } |
| 682 | |
| 683 | if (ecmd->tx_coalesce_usecs == 0) |
| 684 | msk &= ~txirqmask[port]; |
| 685 | else if (ecmd->tx_coalesce_usecs < 25 || |
| 686 | ecmd->tx_coalesce_usecs > 33333) |
| 687 | return -EINVAL; |
| 688 | else { |
| 689 | msk |= txirqmask[port]; |
| 690 | delay = min(delay, ecmd->rx_coalesce_usecs); |
| 691 | } |
| 692 | |
| 693 | skge_write32(hw, B2_IRQM_MSK, msk); |
| 694 | if (msk == 0) |
| 695 | skge_write32(hw, B2_IRQM_CTRL, TIM_STOP); |
| 696 | else { |
| 697 | skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, delay)); |
| 698 | skge_write32(hw, B2_IRQM_CTRL, TIM_START); |
| 699 | } |
| 700 | return 0; |
| 701 | } |
| 702 | |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 703 | enum led_mode { LED_MODE_OFF, LED_MODE_ON, LED_MODE_TST }; |
| 704 | static void skge_led(struct skge_port *skge, enum led_mode mode) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 705 | { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 706 | struct skge_hw *hw = skge->hw; |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 707 | int port = skge->port; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 708 | |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 709 | spin_lock_bh(&hw->phy_lock); |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 710 | if (hw->chip_id == CHIP_ID_GENESIS) { |
| 711 | switch (mode) { |
| 712 | case LED_MODE_OFF: |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 713 | if (hw->phy_type == SK_PHY_BCOM) |
| 714 | xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF); |
| 715 | else { |
| 716 | skge_write32(hw, SK_REG(port, TX_LED_VAL), 0); |
| 717 | skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_T_OFF); |
| 718 | } |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 719 | skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF); |
| 720 | skge_write32(hw, SK_REG(port, RX_LED_VAL), 0); |
| 721 | skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF); |
| 722 | break; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 723 | |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 724 | case LED_MODE_ON: |
| 725 | skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON); |
| 726 | skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON); |
| 727 | |
| 728 | skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START); |
| 729 | skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START); |
| 730 | |
| 731 | break; |
| 732 | |
| 733 | case LED_MODE_TST: |
| 734 | skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON); |
| 735 | skge_write32(hw, SK_REG(port, RX_LED_VAL), 100); |
| 736 | skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START); |
| 737 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 738 | if (hw->phy_type == SK_PHY_BCOM) |
| 739 | xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON); |
| 740 | else { |
| 741 | skge_write8(hw, SK_REG(port, TX_LED_TST), LED_T_ON); |
| 742 | skge_write32(hw, SK_REG(port, TX_LED_VAL), 100); |
| 743 | skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START); |
| 744 | } |
| 745 | |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 746 | } |
| 747 | } else { |
| 748 | switch (mode) { |
| 749 | case LED_MODE_OFF: |
| 750 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); |
| 751 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, |
| 752 | PHY_M_LED_MO_DUP(MO_LED_OFF) | |
| 753 | PHY_M_LED_MO_10(MO_LED_OFF) | |
| 754 | PHY_M_LED_MO_100(MO_LED_OFF) | |
| 755 | PHY_M_LED_MO_1000(MO_LED_OFF) | |
| 756 | PHY_M_LED_MO_RX(MO_LED_OFF)); |
| 757 | break; |
| 758 | case LED_MODE_ON: |
| 759 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, |
| 760 | PHY_M_LED_PULS_DUR(PULS_170MS) | |
| 761 | PHY_M_LED_BLINK_RT(BLINK_84MS) | |
| 762 | PHY_M_LEDC_TX_CTRL | |
| 763 | PHY_M_LEDC_DP_CTRL); |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 764 | |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 765 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, |
| 766 | PHY_M_LED_MO_RX(MO_LED_OFF) | |
| 767 | (skge->speed == SPEED_100 ? |
| 768 | PHY_M_LED_MO_100(MO_LED_ON) : 0)); |
| 769 | break; |
| 770 | case LED_MODE_TST: |
| 771 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); |
| 772 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, |
| 773 | PHY_M_LED_MO_DUP(MO_LED_ON) | |
| 774 | PHY_M_LED_MO_10(MO_LED_ON) | |
| 775 | PHY_M_LED_MO_100(MO_LED_ON) | |
| 776 | PHY_M_LED_MO_1000(MO_LED_ON) | |
| 777 | PHY_M_LED_MO_RX(MO_LED_ON)); |
| 778 | } |
| 779 | } |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 780 | spin_unlock_bh(&hw->phy_lock); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | /* blink LED's for finding board */ |
| 784 | static int skge_phys_id(struct net_device *dev, u32 data) |
| 785 | { |
| 786 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 787 | unsigned long ms; |
| 788 | enum led_mode mode = LED_MODE_TST; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 789 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 790 | if (!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ)) |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 791 | ms = jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT / HZ) * 1000; |
| 792 | else |
| 793 | ms = data * 1000; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 794 | |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 795 | while (ms > 0) { |
| 796 | skge_led(skge, mode); |
| 797 | mode ^= LED_MODE_TST; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 798 | |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 799 | if (msleep_interruptible(BLINK_MS)) |
| 800 | break; |
| 801 | ms -= BLINK_MS; |
| 802 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 803 | |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 804 | /* back to regular LED state */ |
| 805 | skge_led(skge, netif_running(dev) ? LED_MODE_ON : LED_MODE_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 806 | |
| 807 | return 0; |
| 808 | } |
| 809 | |
Stephen Hemminger | afa151b | 2007-10-16 12:15:53 -0700 | [diff] [blame] | 810 | static int skge_get_eeprom_len(struct net_device *dev) |
| 811 | { |
| 812 | struct skge_port *skge = netdev_priv(dev); |
| 813 | u32 reg2; |
| 814 | |
| 815 | pci_read_config_dword(skge->hw->pdev, PCI_DEV_REG2, ®2); |
| 816 | return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8); |
| 817 | } |
| 818 | |
| 819 | static u32 skge_vpd_read(struct pci_dev *pdev, int cap, u16 offset) |
| 820 | { |
| 821 | u32 val; |
| 822 | |
| 823 | pci_write_config_word(pdev, cap + PCI_VPD_ADDR, offset); |
| 824 | |
| 825 | do { |
| 826 | pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset); |
| 827 | } while (!(offset & PCI_VPD_ADDR_F)); |
| 828 | |
| 829 | pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &val); |
| 830 | return val; |
| 831 | } |
| 832 | |
| 833 | static void skge_vpd_write(struct pci_dev *pdev, int cap, u16 offset, u32 val) |
| 834 | { |
| 835 | pci_write_config_dword(pdev, cap + PCI_VPD_DATA, val); |
| 836 | pci_write_config_word(pdev, cap + PCI_VPD_ADDR, |
| 837 | offset | PCI_VPD_ADDR_F); |
| 838 | |
| 839 | do { |
| 840 | pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset); |
| 841 | } while (offset & PCI_VPD_ADDR_F); |
| 842 | } |
| 843 | |
| 844 | static int skge_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, |
| 845 | u8 *data) |
| 846 | { |
| 847 | struct skge_port *skge = netdev_priv(dev); |
| 848 | struct pci_dev *pdev = skge->hw->pdev; |
| 849 | int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD); |
| 850 | int length = eeprom->len; |
| 851 | u16 offset = eeprom->offset; |
| 852 | |
| 853 | if (!cap) |
| 854 | return -EINVAL; |
| 855 | |
| 856 | eeprom->magic = SKGE_EEPROM_MAGIC; |
| 857 | |
| 858 | while (length > 0) { |
| 859 | u32 val = skge_vpd_read(pdev, cap, offset); |
| 860 | int n = min_t(int, length, sizeof(val)); |
| 861 | |
| 862 | memcpy(data, &val, n); |
| 863 | length -= n; |
| 864 | data += n; |
| 865 | offset += n; |
| 866 | } |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | static int skge_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, |
| 871 | u8 *data) |
| 872 | { |
| 873 | struct skge_port *skge = netdev_priv(dev); |
| 874 | struct pci_dev *pdev = skge->hw->pdev; |
| 875 | int cap = pci_find_capability(pdev, PCI_CAP_ID_VPD); |
| 876 | int length = eeprom->len; |
| 877 | u16 offset = eeprom->offset; |
| 878 | |
| 879 | if (!cap) |
| 880 | return -EINVAL; |
| 881 | |
| 882 | if (eeprom->magic != SKGE_EEPROM_MAGIC) |
| 883 | return -EINVAL; |
| 884 | |
| 885 | while (length > 0) { |
| 886 | u32 val; |
| 887 | int n = min_t(int, length, sizeof(val)); |
| 888 | |
| 889 | if (n < sizeof(val)) |
| 890 | val = skge_vpd_read(pdev, cap, offset); |
| 891 | memcpy(&val, data, n); |
| 892 | |
| 893 | skge_vpd_write(pdev, cap, offset, val); |
| 894 | |
| 895 | length -= n; |
| 896 | data += n; |
| 897 | offset += n; |
| 898 | } |
| 899 | return 0; |
| 900 | } |
| 901 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 902 | static const struct ethtool_ops skge_ethtool_ops = { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 903 | .get_settings = skge_get_settings, |
| 904 | .set_settings = skge_set_settings, |
| 905 | .get_drvinfo = skge_get_drvinfo, |
| 906 | .get_regs_len = skge_get_regs_len, |
| 907 | .get_regs = skge_get_regs, |
| 908 | .get_wol = skge_get_wol, |
| 909 | .set_wol = skge_set_wol, |
| 910 | .get_msglevel = skge_get_msglevel, |
| 911 | .set_msglevel = skge_set_msglevel, |
| 912 | .nway_reset = skge_nway_reset, |
| 913 | .get_link = ethtool_op_get_link, |
Stephen Hemminger | afa151b | 2007-10-16 12:15:53 -0700 | [diff] [blame] | 914 | .get_eeprom_len = skge_get_eeprom_len, |
| 915 | .get_eeprom = skge_get_eeprom, |
| 916 | .set_eeprom = skge_set_eeprom, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 917 | .get_ringparam = skge_get_ring_param, |
| 918 | .set_ringparam = skge_set_ring_param, |
| 919 | .get_pauseparam = skge_get_pauseparam, |
| 920 | .set_pauseparam = skge_set_pauseparam, |
| 921 | .get_coalesce = skge_get_coalesce, |
| 922 | .set_coalesce = skge_set_coalesce, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 923 | .set_sg = skge_set_sg, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 924 | .set_tx_csum = skge_set_tx_csum, |
| 925 | .get_rx_csum = skge_get_rx_csum, |
| 926 | .set_rx_csum = skge_set_rx_csum, |
| 927 | .get_strings = skge_get_strings, |
| 928 | .phys_id = skge_phys_id, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 929 | .get_sset_count = skge_get_sset_count, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 930 | .get_ethtool_stats = skge_get_ethtool_stats, |
| 931 | }; |
| 932 | |
| 933 | /* |
| 934 | * Allocate ring elements and chain them together |
| 935 | * One-to-one association of board descriptors with ring elements |
| 936 | */ |
Stephen Hemminger | c3da144 | 2006-03-21 10:57:01 -0800 | [diff] [blame] | 937 | static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u32 base) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 938 | { |
| 939 | struct skge_tx_desc *d; |
| 940 | struct skge_element *e; |
| 941 | int i; |
| 942 | |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 943 | ring->start = kcalloc(ring->count, sizeof(*e), GFP_KERNEL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 944 | if (!ring->start) |
| 945 | return -ENOMEM; |
| 946 | |
| 947 | for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) { |
| 948 | e->desc = d; |
| 949 | if (i == ring->count - 1) { |
| 950 | e->next = ring->start; |
| 951 | d->next_offset = base; |
| 952 | } else { |
| 953 | e->next = e + 1; |
| 954 | d->next_offset = base + (i+1) * sizeof(*d); |
| 955 | } |
| 956 | } |
| 957 | ring->to_use = ring->to_clean = ring->start; |
| 958 | |
| 959 | return 0; |
| 960 | } |
| 961 | |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 962 | /* Allocate and setup a new buffer for receiving */ |
| 963 | static void skge_rx_setup(struct skge_port *skge, struct skge_element *e, |
| 964 | struct sk_buff *skb, unsigned int bufsize) |
| 965 | { |
| 966 | struct skge_rx_desc *rd = e->desc; |
| 967 | u64 map; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 968 | |
| 969 | map = pci_map_single(skge->hw->pdev, skb->data, bufsize, |
| 970 | PCI_DMA_FROMDEVICE); |
| 971 | |
| 972 | rd->dma_lo = map; |
| 973 | rd->dma_hi = map >> 32; |
| 974 | e->skb = skb; |
| 975 | rd->csum1_start = ETH_HLEN; |
| 976 | rd->csum2_start = ETH_HLEN; |
| 977 | rd->csum1 = 0; |
| 978 | rd->csum2 = 0; |
| 979 | |
| 980 | wmb(); |
| 981 | |
| 982 | rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize; |
| 983 | pci_unmap_addr_set(e, mapaddr, map); |
| 984 | pci_unmap_len_set(e, maplen, bufsize); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 985 | } |
| 986 | |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 987 | /* Resume receiving using existing skb, |
| 988 | * Note: DMA address is not changed by chip. |
| 989 | * MTU not changed while receiver active. |
| 990 | */ |
Stephen Hemminger | 5a01144 | 2006-03-23 11:07:25 -0800 | [diff] [blame] | 991 | static inline void skge_rx_reuse(struct skge_element *e, unsigned int size) |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 992 | { |
| 993 | struct skge_rx_desc *rd = e->desc; |
| 994 | |
| 995 | rd->csum2 = 0; |
| 996 | rd->csum2_start = ETH_HLEN; |
| 997 | |
| 998 | wmb(); |
| 999 | |
| 1000 | rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | size; |
| 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | /* Free all buffers in receive ring, assumes receiver stopped */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1005 | static void skge_rx_clean(struct skge_port *skge) |
| 1006 | { |
| 1007 | struct skge_hw *hw = skge->hw; |
| 1008 | struct skge_ring *ring = &skge->rx_ring; |
| 1009 | struct skge_element *e; |
| 1010 | |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 1011 | e = ring->start; |
| 1012 | do { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1013 | struct skge_rx_desc *rd = e->desc; |
| 1014 | rd->control = 0; |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 1015 | if (e->skb) { |
| 1016 | pci_unmap_single(hw->pdev, |
| 1017 | pci_unmap_addr(e, mapaddr), |
| 1018 | pci_unmap_len(e, maplen), |
| 1019 | PCI_DMA_FROMDEVICE); |
| 1020 | dev_kfree_skb(e->skb); |
| 1021 | e->skb = NULL; |
| 1022 | } |
| 1023 | } while ((e = e->next) != ring->start); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1024 | } |
| 1025 | |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 1026 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1027 | /* Allocate buffers for receive ring |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 1028 | * For receive: to_clean is next received frame. |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1029 | */ |
Stephen Hemminger | c54f976 | 2006-09-01 15:53:47 -0700 | [diff] [blame] | 1030 | static int skge_rx_fill(struct net_device *dev) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1031 | { |
Stephen Hemminger | c54f976 | 2006-09-01 15:53:47 -0700 | [diff] [blame] | 1032 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1033 | struct skge_ring *ring = &skge->rx_ring; |
| 1034 | struct skge_element *e; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1035 | |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 1036 | e = ring->start; |
| 1037 | do { |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 1038 | struct sk_buff *skb; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1039 | |
Stephen Hemminger | c54f976 | 2006-09-01 15:53:47 -0700 | [diff] [blame] | 1040 | skb = __netdev_alloc_skb(dev, skge->rx_buf_size + NET_IP_ALIGN, |
| 1041 | GFP_KERNEL); |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 1042 | if (!skb) |
| 1043 | return -ENOMEM; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1044 | |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 1045 | skb_reserve(skb, NET_IP_ALIGN); |
| 1046 | skge_rx_setup(skge, e, skb, skge->rx_buf_size); |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 1047 | } while ( (e = e->next) != ring->start); |
| 1048 | |
| 1049 | ring->to_clean = ring->start; |
| 1050 | return 0; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1051 | } |
| 1052 | |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 1053 | static const char *skge_pause(enum pause_status status) |
| 1054 | { |
| 1055 | switch(status) { |
| 1056 | case FLOW_STAT_NONE: |
| 1057 | return "none"; |
| 1058 | case FLOW_STAT_REM_SEND: |
| 1059 | return "rx only"; |
| 1060 | case FLOW_STAT_LOC_SEND: |
| 1061 | return "tx_only"; |
| 1062 | case FLOW_STAT_SYMMETRIC: /* Both station may send PAUSE */ |
| 1063 | return "both"; |
| 1064 | default: |
| 1065 | return "indeterminated"; |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1070 | static void skge_link_up(struct skge_port *skge) |
| 1071 | { |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 1072 | skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), |
Stephen Hemminger | 54cfb5a | 2005-08-16 14:01:05 -0700 | [diff] [blame] | 1073 | LED_BLK_OFF|LED_SYNC_OFF|LED_ON); |
| 1074 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1075 | netif_carrier_on(skge->netdev); |
Stephen Hemminger | 29b4e88 | 2006-03-23 11:07:28 -0800 | [diff] [blame] | 1076 | netif_wake_queue(skge->netdev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1077 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 1078 | netif_info(skge, link, skge->netdev, |
| 1079 | "Link is up at %d Mbps, %s duplex, flow control %s\n", |
| 1080 | skge->speed, |
| 1081 | skge->duplex == DUPLEX_FULL ? "full" : "half", |
| 1082 | skge_pause(skge->flow_status)); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | static void skge_link_down(struct skge_port *skge) |
| 1086 | { |
Stephen Hemminger | 54cfb5a | 2005-08-16 14:01:05 -0700 | [diff] [blame] | 1087 | skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1088 | netif_carrier_off(skge->netdev); |
| 1089 | netif_stop_queue(skge->netdev); |
| 1090 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 1091 | netif_info(skge, link, skge->netdev, "Link is down\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1092 | } |
| 1093 | |
Stephen Hemminger | a1bc9b8 | 2006-10-05 15:49:50 -0700 | [diff] [blame] | 1094 | |
| 1095 | static void xm_link_down(struct skge_hw *hw, int port) |
| 1096 | { |
| 1097 | struct net_device *dev = hw->dev[port]; |
| 1098 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | a1bc9b8 | 2006-10-05 15:49:50 -0700 | [diff] [blame] | 1099 | |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1100 | xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE); |
Stephen Hemminger | a1bc9b8 | 2006-10-05 15:49:50 -0700 | [diff] [blame] | 1101 | |
Stephen Hemminger | a1bc9b8 | 2006-10-05 15:49:50 -0700 | [diff] [blame] | 1102 | if (netif_carrier_ok(dev)) |
| 1103 | skge_link_down(skge); |
| 1104 | } |
| 1105 | |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 1106 | static int __xm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1107 | { |
| 1108 | int i; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1109 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1110 | xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr); |
Stephen Hemminger | 0781191 | 2006-02-22 10:28:34 -0800 | [diff] [blame] | 1111 | *val = xm_read16(hw, port, XM_PHY_DATA); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1112 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1113 | if (hw->phy_type == SK_PHY_XMAC) |
| 1114 | goto ready; |
| 1115 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame] | 1116 | for (i = 0; i < PHY_RETRIES; i++) { |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 1117 | if (xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_RDY) |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame] | 1118 | goto ready; |
Stephen Hemminger | 0781191 | 2006-02-22 10:28:34 -0800 | [diff] [blame] | 1119 | udelay(1); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1120 | } |
| 1121 | |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 1122 | return -ETIMEDOUT; |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame] | 1123 | ready: |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 1124 | *val = xm_read16(hw, port, XM_PHY_DATA); |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame] | 1125 | |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | static u16 xm_phy_read(struct skge_hw *hw, int port, u16 reg) |
| 1130 | { |
| 1131 | u16 v = 0; |
| 1132 | if (__xm_phy_read(hw, port, reg, &v)) |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 1133 | pr_warning("%s: phy read timed out\n", hw->dev[port]->name); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1134 | return v; |
| 1135 | } |
| 1136 | |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 1137 | static int xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1138 | { |
| 1139 | int i; |
| 1140 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1141 | xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1142 | for (i = 0; i < PHY_RETRIES; i++) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1143 | if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY)) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1144 | goto ready; |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame] | 1145 | udelay(1); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1146 | } |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 1147 | return -EIO; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1148 | |
| 1149 | ready: |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1150 | xm_write16(hw, port, XM_PHY_DATA, val); |
Stephen Hemminger | 0781191 | 2006-02-22 10:28:34 -0800 | [diff] [blame] | 1151 | for (i = 0; i < PHY_RETRIES; i++) { |
| 1152 | if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY)) |
| 1153 | return 0; |
| 1154 | udelay(1); |
| 1155 | } |
| 1156 | return -ETIMEDOUT; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | static void genesis_init(struct skge_hw *hw) |
| 1160 | { |
| 1161 | /* set blink source counter */ |
| 1162 | skge_write32(hw, B2_BSC_INI, (SK_BLK_DUR * SK_FACT_53) / 100); |
| 1163 | skge_write8(hw, B2_BSC_CTRL, BSC_START); |
| 1164 | |
| 1165 | /* configure mac arbiter */ |
| 1166 | skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR); |
| 1167 | |
| 1168 | /* configure mac arbiter timeout values */ |
| 1169 | skge_write8(hw, B3_MA_TOINI_RX1, SK_MAC_TO_53); |
| 1170 | skge_write8(hw, B3_MA_TOINI_RX2, SK_MAC_TO_53); |
| 1171 | skge_write8(hw, B3_MA_TOINI_TX1, SK_MAC_TO_53); |
| 1172 | skge_write8(hw, B3_MA_TOINI_TX2, SK_MAC_TO_53); |
| 1173 | |
| 1174 | skge_write8(hw, B3_MA_RCINI_RX1, 0); |
| 1175 | skge_write8(hw, B3_MA_RCINI_RX2, 0); |
| 1176 | skge_write8(hw, B3_MA_RCINI_TX1, 0); |
| 1177 | skge_write8(hw, B3_MA_RCINI_TX2, 0); |
| 1178 | |
| 1179 | /* configure packet arbiter timeout */ |
| 1180 | skge_write16(hw, B3_PA_CTRL, PA_RST_CLR); |
| 1181 | skge_write16(hw, B3_PA_TOINI_RX1, SK_PKT_TO_MAX); |
| 1182 | skge_write16(hw, B3_PA_TOINI_TX1, SK_PKT_TO_MAX); |
| 1183 | skge_write16(hw, B3_PA_TOINI_RX2, SK_PKT_TO_MAX); |
| 1184 | skge_write16(hw, B3_PA_TOINI_TX2, SK_PKT_TO_MAX); |
| 1185 | } |
| 1186 | |
| 1187 | static void genesis_reset(struct skge_hw *hw, int port) |
| 1188 | { |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1189 | const u8 zero[8] = { 0 }; |
Stephen Hemminger | 21d7f67 | 2007-11-26 11:54:51 -0800 | [diff] [blame] | 1190 | u32 reg; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1191 | |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 1192 | skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0); |
| 1193 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1194 | /* reset the statistics module */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1195 | xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT); |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1196 | xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1197 | xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */ |
| 1198 | xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */ |
| 1199 | xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1200 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame] | 1201 | /* disable Broadcom PHY IRQ */ |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1202 | if (hw->phy_type == SK_PHY_BCOM) |
| 1203 | xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1204 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1205 | xm_outhash(hw, port, XM_HSM, zero); |
Stephen Hemminger | 21d7f67 | 2007-11-26 11:54:51 -0800 | [diff] [blame] | 1206 | |
| 1207 | /* Flush TX and RX fifo */ |
| 1208 | reg = xm_read32(hw, port, XM_MODE); |
| 1209 | xm_write32(hw, port, XM_MODE, reg | XM_MD_FTF); |
| 1210 | xm_write32(hw, port, XM_MODE, reg | XM_MD_FRF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1214 | /* Convert mode to MII values */ |
| 1215 | static const u16 phy_pause_map[] = { |
| 1216 | [FLOW_MODE_NONE] = 0, |
| 1217 | [FLOW_MODE_LOC_SEND] = PHY_AN_PAUSE_ASYM, |
| 1218 | [FLOW_MODE_SYMMETRIC] = PHY_AN_PAUSE_CAP, |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 1219 | [FLOW_MODE_SYM_OR_REM] = PHY_AN_PAUSE_CAP | PHY_AN_PAUSE_ASYM, |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1220 | }; |
| 1221 | |
Stephen Hemminger | 4b67be9 | 2006-10-05 15:49:51 -0700 | [diff] [blame] | 1222 | /* special defines for FIBER (88E1011S only) */ |
| 1223 | static const u16 fiber_pause_map[] = { |
| 1224 | [FLOW_MODE_NONE] = PHY_X_P_NO_PAUSE, |
| 1225 | [FLOW_MODE_LOC_SEND] = PHY_X_P_ASYM_MD, |
| 1226 | [FLOW_MODE_SYMMETRIC] = PHY_X_P_SYM_MD, |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 1227 | [FLOW_MODE_SYM_OR_REM] = PHY_X_P_BOTH_MD, |
Stephen Hemminger | 4b67be9 | 2006-10-05 15:49:51 -0700 | [diff] [blame] | 1228 | }; |
| 1229 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1230 | |
| 1231 | /* Check status of Broadcom phy link */ |
| 1232 | static void bcom_check_link(struct skge_hw *hw, int port) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1233 | { |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1234 | struct net_device *dev = hw->dev[port]; |
| 1235 | struct skge_port *skge = netdev_priv(dev); |
| 1236 | u16 status; |
| 1237 | |
| 1238 | /* read twice because of latch */ |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1239 | xm_phy_read(hw, port, PHY_BCOM_STAT); |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1240 | status = xm_phy_read(hw, port, PHY_BCOM_STAT); |
| 1241 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1242 | if ((status & PHY_ST_LSYNC) == 0) { |
Stephen Hemminger | a1bc9b8 | 2006-10-05 15:49:50 -0700 | [diff] [blame] | 1243 | xm_link_down(hw, port); |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1244 | return; |
| 1245 | } |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1246 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1247 | if (skge->autoneg == AUTONEG_ENABLE) { |
| 1248 | u16 lpa, aux; |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1249 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1250 | if (!(status & PHY_ST_AN_OVER)) |
| 1251 | return; |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1252 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1253 | lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP); |
| 1254 | if (lpa & PHY_B_AN_RF) { |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 1255 | netdev_notice(dev, "remote fault\n"); |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1256 | return; |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1259 | aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT); |
| 1260 | |
| 1261 | /* Check Duplex mismatch */ |
| 1262 | switch (aux & PHY_B_AS_AN_RES_MSK) { |
| 1263 | case PHY_B_RES_1000FD: |
| 1264 | skge->duplex = DUPLEX_FULL; |
| 1265 | break; |
| 1266 | case PHY_B_RES_1000HD: |
| 1267 | skge->duplex = DUPLEX_HALF; |
| 1268 | break; |
| 1269 | default: |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 1270 | netdev_notice(dev, "duplex mismatch\n"); |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1271 | return; |
| 1272 | } |
| 1273 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1274 | /* We are using IEEE 802.3z/D5.0 Table 37-4 */ |
| 1275 | switch (aux & PHY_B_AS_PAUSE_MSK) { |
| 1276 | case PHY_B_AS_PAUSE_MSK: |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 1277 | skge->flow_status = FLOW_STAT_SYMMETRIC; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1278 | break; |
| 1279 | case PHY_B_AS_PRR: |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 1280 | skge->flow_status = FLOW_STAT_REM_SEND; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1281 | break; |
| 1282 | case PHY_B_AS_PRT: |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 1283 | skge->flow_status = FLOW_STAT_LOC_SEND; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1284 | break; |
| 1285 | default: |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 1286 | skge->flow_status = FLOW_STAT_NONE; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1287 | } |
| 1288 | skge->speed = SPEED_1000; |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1289 | } |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1290 | |
| 1291 | if (!netif_carrier_ok(dev)) |
| 1292 | genesis_link_up(skge); |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | /* Broadcom 5400 only supports giagabit! SysKonnect did not put an additional |
| 1296 | * Phy on for 100 or 10Mbit operation |
| 1297 | */ |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1298 | static void bcom_phy_init(struct skge_port *skge) |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1299 | { |
| 1300 | struct skge_hw *hw = skge->hw; |
| 1301 | int port = skge->port; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1302 | int i; |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1303 | u16 id1, r, ext, ctl; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1304 | |
| 1305 | /* magic workaround patterns for Broadcom */ |
| 1306 | static const struct { |
| 1307 | u16 reg; |
| 1308 | u16 val; |
| 1309 | } A1hack[] = { |
| 1310 | { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1104 }, |
| 1311 | { 0x17, 0x0013 }, { 0x15, 0x0404 }, { 0x17, 0x8006 }, |
| 1312 | { 0x15, 0x0132 }, { 0x17, 0x8006 }, { 0x15, 0x0232 }, |
| 1313 | { 0x17, 0x800D }, { 0x15, 0x000F }, { 0x18, 0x0420 }, |
| 1314 | }, C0hack[] = { |
| 1315 | { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1204 }, |
| 1316 | { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 }, |
| 1317 | }; |
| 1318 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1319 | /* read Id from external PHY (all have the same address) */ |
| 1320 | id1 = xm_phy_read(hw, port, PHY_XMAC_ID1); |
| 1321 | |
| 1322 | /* Optimize MDIO transfer by suppressing preamble. */ |
| 1323 | r = xm_read16(hw, port, XM_MMU_CMD); |
| 1324 | r |= XM_MMU_NO_PRE; |
| 1325 | xm_write16(hw, port, XM_MMU_CMD,r); |
| 1326 | |
Stephen Hemminger | 2c66851 | 2005-07-22 16:26:07 -0700 | [diff] [blame] | 1327 | switch (id1) { |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1328 | case PHY_BCOM_ID1_C0: |
| 1329 | /* |
| 1330 | * Workaround BCOM Errata for the C0 type. |
| 1331 | * Write magic patterns to reserved registers. |
| 1332 | */ |
| 1333 | for (i = 0; i < ARRAY_SIZE(C0hack); i++) |
| 1334 | xm_phy_write(hw, port, |
| 1335 | C0hack[i].reg, C0hack[i].val); |
| 1336 | |
| 1337 | break; |
| 1338 | case PHY_BCOM_ID1_A1: |
| 1339 | /* |
| 1340 | * Workaround BCOM Errata for the A1 type. |
| 1341 | * Write magic patterns to reserved registers. |
| 1342 | */ |
| 1343 | for (i = 0; i < ARRAY_SIZE(A1hack); i++) |
| 1344 | xm_phy_write(hw, port, |
| 1345 | A1hack[i].reg, A1hack[i].val); |
| 1346 | break; |
| 1347 | } |
| 1348 | |
| 1349 | /* |
| 1350 | * Workaround BCOM Errata (#10523) for all BCom PHYs. |
| 1351 | * Disable Power Management after reset. |
| 1352 | */ |
| 1353 | r = xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL); |
| 1354 | r |= PHY_B_AC_DIS_PM; |
| 1355 | xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r); |
| 1356 | |
| 1357 | /* Dummy read */ |
| 1358 | xm_read16(hw, port, XM_ISRC); |
| 1359 | |
| 1360 | ext = PHY_B_PEC_EN_LTR; /* enable tx led */ |
| 1361 | ctl = PHY_CT_SP1000; /* always 1000mbit */ |
| 1362 | |
| 1363 | if (skge->autoneg == AUTONEG_ENABLE) { |
| 1364 | /* |
| 1365 | * Workaround BCOM Errata #1 for the C5 type. |
| 1366 | * 1000Base-T Link Acquisition Failure in Slave Mode |
| 1367 | * Set Repeater/DTE bit 10 of the 1000Base-T Control Register |
| 1368 | */ |
| 1369 | u16 adv = PHY_B_1000C_RD; |
| 1370 | if (skge->advertising & ADVERTISED_1000baseT_Half) |
| 1371 | adv |= PHY_B_1000C_AHD; |
| 1372 | if (skge->advertising & ADVERTISED_1000baseT_Full) |
| 1373 | adv |= PHY_B_1000C_AFD; |
| 1374 | xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, adv); |
| 1375 | |
| 1376 | ctl |= PHY_CT_ANE | PHY_CT_RE_CFG; |
| 1377 | } else { |
| 1378 | if (skge->duplex == DUPLEX_FULL) |
| 1379 | ctl |= PHY_CT_DUP_MD; |
| 1380 | /* Force to slave */ |
| 1381 | xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, PHY_B_1000C_MSE); |
| 1382 | } |
| 1383 | |
| 1384 | /* Set autonegotiation pause parameters */ |
| 1385 | xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV, |
| 1386 | phy_pause_map[skge->flow_control] | PHY_AN_CSMA); |
| 1387 | |
| 1388 | /* Handle Jumbo frames */ |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1389 | if (hw->dev[port]->mtu > ETH_DATA_LEN) { |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1390 | xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, |
| 1391 | PHY_B_AC_TX_TST | PHY_B_AC_LONG_PACK); |
| 1392 | |
| 1393 | ext |= PHY_B_PEC_HIGH_LA; |
| 1394 | |
| 1395 | } |
| 1396 | |
| 1397 | xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ext); |
| 1398 | xm_phy_write(hw, port, PHY_BCOM_CTRL, ctl); |
| 1399 | |
Stephen Hemminger | 8f3f819 | 2005-11-08 10:33:45 -0800 | [diff] [blame] | 1400 | /* Use link status change interrupt */ |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1401 | xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK); |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1402 | } |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1403 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1404 | static void xm_phy_init(struct skge_port *skge) |
| 1405 | { |
| 1406 | struct skge_hw *hw = skge->hw; |
| 1407 | int port = skge->port; |
| 1408 | u16 ctrl = 0; |
| 1409 | |
| 1410 | if (skge->autoneg == AUTONEG_ENABLE) { |
| 1411 | if (skge->advertising & ADVERTISED_1000baseT_Half) |
| 1412 | ctrl |= PHY_X_AN_HD; |
| 1413 | if (skge->advertising & ADVERTISED_1000baseT_Full) |
| 1414 | ctrl |= PHY_X_AN_FD; |
| 1415 | |
Stephen Hemminger | 4b67be9 | 2006-10-05 15:49:51 -0700 | [diff] [blame] | 1416 | ctrl |= fiber_pause_map[skge->flow_control]; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1417 | |
| 1418 | xm_phy_write(hw, port, PHY_XMAC_AUNE_ADV, ctrl); |
| 1419 | |
| 1420 | /* Restart Auto-negotiation */ |
| 1421 | ctrl = PHY_CT_ANE | PHY_CT_RE_CFG; |
| 1422 | } else { |
| 1423 | /* Set DuplexMode in Config register */ |
| 1424 | if (skge->duplex == DUPLEX_FULL) |
| 1425 | ctrl |= PHY_CT_DUP_MD; |
| 1426 | /* |
| 1427 | * Do NOT enable Auto-negotiation here. This would hold |
| 1428 | * the link down because no IDLEs are transmitted |
| 1429 | */ |
| 1430 | } |
| 1431 | |
| 1432 | xm_phy_write(hw, port, PHY_XMAC_CTRL, ctrl); |
| 1433 | |
| 1434 | /* Poll PHY for status changes */ |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 1435 | mod_timer(&skge->link_timer, jiffies + LINK_HZ); |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1438 | static int xm_check_link(struct net_device *dev) |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1439 | { |
| 1440 | struct skge_port *skge = netdev_priv(dev); |
| 1441 | struct skge_hw *hw = skge->hw; |
| 1442 | int port = skge->port; |
| 1443 | u16 status; |
| 1444 | |
| 1445 | /* read twice because of latch */ |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1446 | xm_phy_read(hw, port, PHY_XMAC_STAT); |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1447 | status = xm_phy_read(hw, port, PHY_XMAC_STAT); |
| 1448 | |
| 1449 | if ((status & PHY_ST_LSYNC) == 0) { |
Stephen Hemminger | a1bc9b8 | 2006-10-05 15:49:50 -0700 | [diff] [blame] | 1450 | xm_link_down(hw, port); |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1451 | return 0; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | if (skge->autoneg == AUTONEG_ENABLE) { |
| 1455 | u16 lpa, res; |
| 1456 | |
| 1457 | if (!(status & PHY_ST_AN_OVER)) |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1458 | return 0; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1459 | |
| 1460 | lpa = xm_phy_read(hw, port, PHY_XMAC_AUNE_LP); |
| 1461 | if (lpa & PHY_B_AN_RF) { |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 1462 | netdev_notice(dev, "remote fault\n"); |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1463 | return 0; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | res = xm_phy_read(hw, port, PHY_XMAC_RES_ABI); |
| 1467 | |
| 1468 | /* Check Duplex mismatch */ |
| 1469 | switch (res & (PHY_X_RS_HD | PHY_X_RS_FD)) { |
| 1470 | case PHY_X_RS_FD: |
| 1471 | skge->duplex = DUPLEX_FULL; |
| 1472 | break; |
| 1473 | case PHY_X_RS_HD: |
| 1474 | skge->duplex = DUPLEX_HALF; |
| 1475 | break; |
| 1476 | default: |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 1477 | netdev_notice(dev, "duplex mismatch\n"); |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1478 | return 0; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | /* We are using IEEE 802.3z/D5.0 Table 37-4 */ |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 1482 | if ((skge->flow_control == FLOW_MODE_SYMMETRIC || |
| 1483 | skge->flow_control == FLOW_MODE_SYM_OR_REM) && |
| 1484 | (lpa & PHY_X_P_SYM_MD)) |
| 1485 | skge->flow_status = FLOW_STAT_SYMMETRIC; |
| 1486 | else if (skge->flow_control == FLOW_MODE_SYM_OR_REM && |
| 1487 | (lpa & PHY_X_RS_PAUSE) == PHY_X_P_ASYM_MD) |
| 1488 | /* Enable PAUSE receive, disable PAUSE transmit */ |
| 1489 | skge->flow_status = FLOW_STAT_REM_SEND; |
| 1490 | else if (skge->flow_control == FLOW_MODE_LOC_SEND && |
| 1491 | (lpa & PHY_X_RS_PAUSE) == PHY_X_P_BOTH_MD) |
| 1492 | /* Disable PAUSE receive, enable PAUSE transmit */ |
| 1493 | skge->flow_status = FLOW_STAT_LOC_SEND; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1494 | else |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 1495 | skge->flow_status = FLOW_STAT_NONE; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1496 | |
| 1497 | skge->speed = SPEED_1000; |
| 1498 | } |
| 1499 | |
| 1500 | if (!netif_carrier_ok(dev)) |
| 1501 | genesis_link_up(skge); |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1502 | return 1; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | /* Poll to check for link coming up. |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1506 | * |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1507 | * Since internal PHY is wired to a level triggered pin, can't |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1508 | * get an interrupt when carrier is detected, need to poll for |
| 1509 | * link coming up. |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1510 | */ |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 1511 | static void xm_link_timer(unsigned long arg) |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1512 | { |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 1513 | struct skge_port *skge = (struct skge_port *) arg; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1514 | struct net_device *dev = skge->netdev; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1515 | struct skge_hw *hw = skge->hw; |
| 1516 | int port = skge->port; |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1517 | int i; |
| 1518 | unsigned long flags; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1519 | |
| 1520 | if (!netif_running(dev)) |
| 1521 | return; |
| 1522 | |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1523 | spin_lock_irqsave(&hw->phy_lock, flags); |
| 1524 | |
| 1525 | /* |
| 1526 | * Verify that the link by checking GPIO register three times. |
| 1527 | * This pin has the signal from the link_sync pin connected to it. |
| 1528 | */ |
| 1529 | for (i = 0; i < 3; i++) { |
| 1530 | if (xm_read16(hw, port, XM_GP_PORT) & XM_GP_INP_ASS) |
| 1531 | goto link_down; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1534 | /* Re-enable interrupt to detect link down */ |
| 1535 | if (xm_check_link(dev)) { |
| 1536 | u16 msk = xm_read16(hw, port, XM_IMSK); |
| 1537 | msk &= ~XM_IS_INP_ASS; |
| 1538 | xm_write16(hw, port, XM_IMSK, msk); |
| 1539 | xm_read16(hw, port, XM_ISRC); |
| 1540 | } else { |
| 1541 | link_down: |
| 1542 | mod_timer(&skge->link_timer, |
| 1543 | round_jiffies(jiffies + LINK_HZ)); |
| 1544 | } |
| 1545 | spin_unlock_irqrestore(&hw->phy_lock, flags); |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | static void genesis_mac_init(struct skge_hw *hw, int port) |
| 1549 | { |
| 1550 | struct net_device *dev = hw->dev[port]; |
| 1551 | struct skge_port *skge = netdev_priv(dev); |
| 1552 | int jumbo = hw->dev[port]->mtu > ETH_DATA_LEN; |
| 1553 | int i; |
| 1554 | u32 r; |
| 1555 | const u8 zero[6] = { 0 }; |
| 1556 | |
Stephen Hemminger | 0781191 | 2006-02-22 10:28:34 -0800 | [diff] [blame] | 1557 | for (i = 0; i < 10; i++) { |
| 1558 | skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), |
| 1559 | MFF_SET_MAC_RST); |
| 1560 | if (skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST) |
| 1561 | goto reset_ok; |
| 1562 | udelay(1); |
| 1563 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1564 | |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 1565 | netdev_warn(dev, "genesis reset failed\n"); |
Stephen Hemminger | 0781191 | 2006-02-22 10:28:34 -0800 | [diff] [blame] | 1566 | |
| 1567 | reset_ok: |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1568 | /* Unreset the XMAC. */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1569 | skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1570 | |
| 1571 | /* |
| 1572 | * Perform additional initialization for external PHYs, |
| 1573 | * namely for the 1000baseTX cards that use the XMAC's |
| 1574 | * GMII mode. |
| 1575 | */ |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1576 | if (hw->phy_type != SK_PHY_XMAC) { |
| 1577 | /* Take external Phy out of reset */ |
| 1578 | r = skge_read32(hw, B2_GP_IO); |
| 1579 | if (port == 0) |
| 1580 | r |= GP_DIR_0|GP_IO_0; |
| 1581 | else |
| 1582 | r |= GP_DIR_2|GP_IO_2; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1583 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1584 | skge_write32(hw, B2_GP_IO, r); |
| 1585 | |
| 1586 | /* Enable GMII interface */ |
| 1587 | xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD); |
| 1588 | } |
Stephen Hemminger | 0781191 | 2006-02-22 10:28:34 -0800 | [diff] [blame] | 1589 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1590 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1591 | switch(hw->phy_type) { |
| 1592 | case SK_PHY_XMAC: |
| 1593 | xm_phy_init(skge); |
| 1594 | break; |
| 1595 | case SK_PHY_BCOM: |
| 1596 | bcom_phy_init(skge); |
| 1597 | bcom_check_link(hw, port); |
| 1598 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1599 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1600 | /* Set Station Address */ |
| 1601 | xm_outaddr(hw, port, XM_SA, dev->dev_addr); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1602 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1603 | /* We don't use match addresses so clear */ |
| 1604 | for (i = 1; i < 16; i++) |
| 1605 | xm_outaddr(hw, port, XM_EXM(i), zero); |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame] | 1606 | |
Stephen Hemminger | 0781191 | 2006-02-22 10:28:34 -0800 | [diff] [blame] | 1607 | /* Clear MIB counters */ |
| 1608 | xm_write16(hw, port, XM_STAT_CMD, |
| 1609 | XM_SC_CLR_RXC | XM_SC_CLR_TXC); |
| 1610 | /* Clear two times according to Errata #3 */ |
| 1611 | xm_write16(hw, port, XM_STAT_CMD, |
| 1612 | XM_SC_CLR_RXC | XM_SC_CLR_TXC); |
| 1613 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1614 | /* configure Rx High Water Mark (XM_RX_HI_WM) */ |
| 1615 | xm_write16(hw, port, XM_RX_HI_WM, 1450); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1616 | |
| 1617 | /* We don't need the FCS appended to the packet. */ |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1618 | r = XM_RX_LENERR_OK | XM_RX_STRIP_FCS; |
| 1619 | if (jumbo) |
| 1620 | r |= XM_RX_BIG_PK_OK; |
| 1621 | |
| 1622 | if (skge->duplex == DUPLEX_HALF) { |
| 1623 | /* |
| 1624 | * If in manual half duplex mode the other side might be in |
| 1625 | * full duplex mode, so ignore if a carrier extension is not seen |
| 1626 | * on frames received |
| 1627 | */ |
| 1628 | r |= XM_RX_DIS_CEXT; |
| 1629 | } |
| 1630 | xm_write16(hw, port, XM_RX_CMD, r); |
| 1631 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1632 | /* We want short frames padded to 60 bytes. */ |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1633 | xm_write16(hw, port, XM_TX_CMD, XM_TX_AUTO_PAD); |
| 1634 | |
Stephen Hemminger | 485982a | 2007-11-26 11:54:52 -0800 | [diff] [blame] | 1635 | /* Increase threshold for jumbo frames on dual port */ |
| 1636 | if (hw->ports > 1 && jumbo) |
| 1637 | xm_write16(hw, port, XM_TX_THR, 1020); |
| 1638 | else |
| 1639 | xm_write16(hw, port, XM_TX_THR, 512); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1640 | |
| 1641 | /* |
| 1642 | * Enable the reception of all error frames. This is is |
| 1643 | * a necessary evil due to the design of the XMAC. The |
| 1644 | * XMAC's receive FIFO is only 8K in size, however jumbo |
| 1645 | * frames can be up to 9000 bytes in length. When bad |
| 1646 | * frame filtering is enabled, the XMAC's RX FIFO operates |
| 1647 | * in 'store and forward' mode. For this to work, the |
| 1648 | * entire frame has to fit into the FIFO, but that means |
| 1649 | * that jumbo frames larger than 8192 bytes will be |
| 1650 | * truncated. Disabling all bad frame filtering causes |
| 1651 | * the RX FIFO to operate in streaming mode, in which |
Stephen Hemminger | 8f3f819 | 2005-11-08 10:33:45 -0800 | [diff] [blame] | 1652 | * case the XMAC will start transferring frames out of the |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1653 | * RX FIFO as soon as the FIFO threshold is reached. |
| 1654 | */ |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1655 | xm_write32(hw, port, XM_MODE, XM_DEF_MODE); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1656 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1657 | |
| 1658 | /* |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1659 | * Initialize the Receive Counter Event Mask (XM_RX_EV_MSK) |
| 1660 | * - Enable all bits excepting 'Octets Rx OK Low CntOv' |
| 1661 | * and 'Octets Rx OK Hi Cnt Ov'. |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1662 | */ |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1663 | xm_write32(hw, port, XM_RX_EV_MSK, XMR_DEF_MSK); |
| 1664 | |
| 1665 | /* |
| 1666 | * Initialize the Transmit Counter Event Mask (XM_TX_EV_MSK) |
| 1667 | * - Enable all bits excepting 'Octets Tx OK Low CntOv' |
| 1668 | * and 'Octets Tx OK Hi Cnt Ov'. |
| 1669 | */ |
| 1670 | xm_write32(hw, port, XM_TX_EV_MSK, XMT_DEF_MSK); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1671 | |
| 1672 | /* Configure MAC arbiter */ |
| 1673 | skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR); |
| 1674 | |
| 1675 | /* configure timeout values */ |
| 1676 | skge_write8(hw, B3_MA_TOINI_RX1, 72); |
| 1677 | skge_write8(hw, B3_MA_TOINI_RX2, 72); |
| 1678 | skge_write8(hw, B3_MA_TOINI_TX1, 72); |
| 1679 | skge_write8(hw, B3_MA_TOINI_TX2, 72); |
| 1680 | |
| 1681 | skge_write8(hw, B3_MA_RCINI_RX1, 0); |
| 1682 | skge_write8(hw, B3_MA_RCINI_RX2, 0); |
| 1683 | skge_write8(hw, B3_MA_RCINI_TX1, 0); |
| 1684 | skge_write8(hw, B3_MA_RCINI_TX2, 0); |
| 1685 | |
| 1686 | /* Configure Rx MAC FIFO */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1687 | skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_CLR); |
| 1688 | skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT); |
| 1689 | skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_ENA_OP_MD); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1690 | |
| 1691 | /* Configure Tx MAC FIFO */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1692 | skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_CLR); |
| 1693 | skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF); |
| 1694 | skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_ENA_OP_MD); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1695 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1696 | if (jumbo) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1697 | /* Enable frame flushing if jumbo frames used */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1698 | skge_write16(hw, SK_REG(port,RX_MFF_CTRL1), MFF_ENA_FLUSH); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1699 | } else { |
| 1700 | /* enable timeout timers if normal frames */ |
| 1701 | skge_write16(hw, B3_PA_CTRL, |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1702 | (port == 0) ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1703 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | static void genesis_stop(struct skge_port *skge) |
| 1707 | { |
| 1708 | struct skge_hw *hw = skge->hw; |
| 1709 | int port = skge->port; |
Stephen Hemminger | 799b21d | 2007-11-26 11:54:50 -0800 | [diff] [blame] | 1710 | unsigned retries = 1000; |
Stephen Hemminger | 21d7f67 | 2007-11-26 11:54:51 -0800 | [diff] [blame] | 1711 | u16 cmd; |
| 1712 | |
| 1713 | /* Disable Tx and Rx */ |
| 1714 | cmd = xm_read16(hw, port, XM_MMU_CMD); |
| 1715 | cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX); |
| 1716 | xm_write16(hw, port, XM_MMU_CMD, cmd); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1717 | |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 1718 | genesis_reset(hw, port); |
| 1719 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1720 | /* Clear Tx packet arbiter timeout IRQ */ |
| 1721 | skge_write16(hw, B3_PA_CTRL, |
| 1722 | port == 0 ? PA_CLR_TO_TX1 : PA_CLR_TO_TX2); |
| 1723 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1724 | /* Reset the MAC */ |
Stephen Hemminger | 799b21d | 2007-11-26 11:54:50 -0800 | [diff] [blame] | 1725 | skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST); |
| 1726 | do { |
| 1727 | skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST); |
| 1728 | if (!(skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST)) |
| 1729 | break; |
| 1730 | } while (--retries > 0); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1731 | |
| 1732 | /* For external PHYs there must be special handling */ |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1733 | if (hw->phy_type != SK_PHY_XMAC) { |
Stephen Hemminger | 799b21d | 2007-11-26 11:54:50 -0800 | [diff] [blame] | 1734 | u32 reg = skge_read32(hw, B2_GP_IO); |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1735 | if (port == 0) { |
| 1736 | reg |= GP_DIR_0; |
| 1737 | reg &= ~GP_IO_0; |
| 1738 | } else { |
| 1739 | reg |= GP_DIR_2; |
| 1740 | reg &= ~GP_IO_2; |
| 1741 | } |
| 1742 | skge_write32(hw, B2_GP_IO, reg); |
| 1743 | skge_read32(hw, B2_GP_IO); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1744 | } |
| 1745 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1746 | xm_write16(hw, port, XM_MMU_CMD, |
| 1747 | xm_read16(hw, port, XM_MMU_CMD) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1748 | & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX)); |
| 1749 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1750 | xm_read16(hw, port, XM_MMU_CMD); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | |
| 1754 | static void genesis_get_stats(struct skge_port *skge, u64 *data) |
| 1755 | { |
| 1756 | struct skge_hw *hw = skge->hw; |
| 1757 | int port = skge->port; |
| 1758 | int i; |
| 1759 | unsigned long timeout = jiffies + HZ; |
| 1760 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1761 | xm_write16(hw, port, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1762 | XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC); |
| 1763 | |
| 1764 | /* wait for update to complete */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1765 | while (xm_read16(hw, port, XM_STAT_CMD) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1766 | & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) { |
| 1767 | if (time_after(jiffies, timeout)) |
| 1768 | break; |
| 1769 | udelay(10); |
| 1770 | } |
| 1771 | |
| 1772 | /* special case for 64 bit octet counter */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1773 | data[0] = (u64) xm_read32(hw, port, XM_TXO_OK_HI) << 32 |
| 1774 | | xm_read32(hw, port, XM_TXO_OK_LO); |
| 1775 | data[1] = (u64) xm_read32(hw, port, XM_RXO_OK_HI) << 32 |
| 1776 | | xm_read32(hw, port, XM_RXO_OK_LO); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1777 | |
| 1778 | for (i = 2; i < ARRAY_SIZE(skge_stats); i++) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1779 | data[i] = xm_read32(hw, port, skge_stats[i].xmac_offset); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | static void genesis_mac_intr(struct skge_hw *hw, int port) |
| 1783 | { |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 1784 | struct net_device *dev = hw->dev[port]; |
| 1785 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1786 | u16 status = xm_read16(hw, port, XM_ISRC); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1787 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 1788 | netif_printk(skge, intr, KERN_DEBUG, skge->netdev, |
| 1789 | "mac interrupt status 0x%x\n", status); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1790 | |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1791 | if (hw->phy_type == SK_PHY_XMAC && (status & XM_IS_INP_ASS)) { |
| 1792 | xm_link_down(hw, port); |
| 1793 | mod_timer(&skge->link_timer, jiffies + 1); |
| 1794 | } |
Stephen Hemminger | a1bc9b8 | 2006-10-05 15:49:50 -0700 | [diff] [blame] | 1795 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1796 | if (status & XM_IS_TXF_UR) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1797 | xm_write32(hw, port, XM_MODE, XM_MD_FTF); |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 1798 | ++dev->stats.tx_fifo_errors; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1799 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1800 | } |
| 1801 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1802 | static void genesis_link_up(struct skge_port *skge) |
| 1803 | { |
| 1804 | struct skge_hw *hw = skge->hw; |
| 1805 | int port = skge->port; |
Stephen Hemminger | a1bc9b8 | 2006-10-05 15:49:50 -0700 | [diff] [blame] | 1806 | u16 cmd, msk; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1807 | u32 mode; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1808 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1809 | cmd = xm_read16(hw, port, XM_MMU_CMD); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1810 | |
| 1811 | /* |
| 1812 | * enabling pause frame reception is required for 1000BT |
| 1813 | * because the XMAC is not reset if the link is going down |
| 1814 | */ |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 1815 | if (skge->flow_status == FLOW_STAT_NONE || |
| 1816 | skge->flow_status == FLOW_STAT_LOC_SEND) |
Stephen Hemminger | 7e676d9 | 2005-06-27 11:33:13 -0700 | [diff] [blame] | 1817 | /* Disable Pause Frame Reception */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1818 | cmd |= XM_MMU_IGN_PF; |
| 1819 | else |
| 1820 | /* Enable Pause Frame Reception */ |
| 1821 | cmd &= ~XM_MMU_IGN_PF; |
| 1822 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1823 | xm_write16(hw, port, XM_MMU_CMD, cmd); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1824 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1825 | mode = xm_read32(hw, port, XM_MODE); |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 1826 | if (skge->flow_status== FLOW_STAT_SYMMETRIC || |
| 1827 | skge->flow_status == FLOW_STAT_LOC_SEND) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1828 | /* |
| 1829 | * Configure Pause Frame Generation |
| 1830 | * Use internal and external Pause Frame Generation. |
| 1831 | * Sending pause frames is edge triggered. |
| 1832 | * Send a Pause frame with the maximum pause time if |
| 1833 | * internal oder external FIFO full condition occurs. |
| 1834 | * Send a zero pause time frame to re-start transmission. |
| 1835 | */ |
| 1836 | /* XM_PAUSE_DA = '010000C28001' (default) */ |
| 1837 | /* XM_MAC_PTIME = 0xffff (maximum) */ |
| 1838 | /* remember this value is defined in big endian (!) */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1839 | xm_write16(hw, port, XM_MAC_PTIME, 0xffff); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1840 | |
| 1841 | mode |= XM_PAUSE_MODE; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1842 | skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1843 | } else { |
| 1844 | /* |
| 1845 | * disable pause frame generation is required for 1000BT |
| 1846 | * because the XMAC is not reset if the link is going down |
| 1847 | */ |
| 1848 | /* Disable Pause Mode in Mode Register */ |
| 1849 | mode &= ~XM_PAUSE_MODE; |
| 1850 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1851 | skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1852 | } |
| 1853 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1854 | xm_write32(hw, port, XM_MODE, mode); |
Stephen Hemminger | a1bc9b8 | 2006-10-05 15:49:50 -0700 | [diff] [blame] | 1855 | |
Stephen Hemminger | d08b9bd | 2007-11-26 11:54:49 -0800 | [diff] [blame] | 1856 | /* Turn on detection of Tx underrun */ |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1857 | msk = xm_read16(hw, port, XM_IMSK); |
Stephen Hemminger | d08b9bd | 2007-11-26 11:54:49 -0800 | [diff] [blame] | 1858 | msk &= ~XM_IS_TXF_UR; |
Stephen Hemminger | a1bc9b8 | 2006-10-05 15:49:50 -0700 | [diff] [blame] | 1859 | xm_write16(hw, port, XM_IMSK, msk); |
Stephen Hemminger | 501fb72 | 2007-10-16 12:15:51 -0700 | [diff] [blame] | 1860 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1861 | xm_read16(hw, port, XM_ISRC); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1862 | |
| 1863 | /* get MMU Command Reg. */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1864 | cmd = xm_read16(hw, port, XM_MMU_CMD); |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1865 | if (hw->phy_type != SK_PHY_XMAC && skge->duplex == DUPLEX_FULL) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1866 | cmd |= XM_MMU_GMII_FD; |
| 1867 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame] | 1868 | /* |
| 1869 | * Workaround BCOM Errata (#10523) for all BCom Phys |
| 1870 | * Enable Power Management after link up |
| 1871 | */ |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 1872 | if (hw->phy_type == SK_PHY_BCOM) { |
| 1873 | xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, |
| 1874 | xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL) |
| 1875 | & ~PHY_B_AC_DIS_PM); |
| 1876 | xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK); |
| 1877 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1878 | |
| 1879 | /* enable Rx/Tx */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1880 | xm_write16(hw, port, XM_MMU_CMD, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1881 | cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX); |
| 1882 | skge_link_up(skge); |
| 1883 | } |
| 1884 | |
| 1885 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1886 | static inline void bcom_phy_intr(struct skge_port *skge) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1887 | { |
| 1888 | struct skge_hw *hw = skge->hw; |
| 1889 | int port = skge->port; |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1890 | u16 isrc; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1891 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1892 | isrc = xm_phy_read(hw, port, PHY_BCOM_INT_STAT); |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 1893 | netif_printk(skge, intr, KERN_DEBUG, skge->netdev, |
| 1894 | "phy interrupt status 0x%x\n", isrc); |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1895 | |
| 1896 | if (isrc & PHY_B_IS_PSE) |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 1897 | pr_err("%s: uncorrectable pair swap error\n", |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1898 | hw->dev[port]->name); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1899 | |
| 1900 | /* Workaround BCom Errata: |
| 1901 | * enable and disable loopback mode if "NO HCD" occurs. |
| 1902 | */ |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1903 | if (isrc & PHY_B_IS_NO_HDCL) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1904 | u16 ctrl = xm_phy_read(hw, port, PHY_BCOM_CTRL); |
| 1905 | xm_phy_write(hw, port, PHY_BCOM_CTRL, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1906 | ctrl | PHY_CT_LOOP); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1907 | xm_phy_write(hw, port, PHY_BCOM_CTRL, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1908 | ctrl & ~PHY_CT_LOOP); |
| 1909 | } |
| 1910 | |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 1911 | if (isrc & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE)) |
| 1912 | bcom_check_link(hw, port); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1913 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1914 | } |
| 1915 | |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 1916 | static int gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val) |
| 1917 | { |
| 1918 | int i; |
| 1919 | |
| 1920 | gma_write16(hw, port, GM_SMI_DATA, val); |
| 1921 | gma_write16(hw, port, GM_SMI_CTRL, |
| 1922 | GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg)); |
| 1923 | for (i = 0; i < PHY_RETRIES; i++) { |
| 1924 | udelay(1); |
| 1925 | |
| 1926 | if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY)) |
| 1927 | return 0; |
| 1928 | } |
| 1929 | |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 1930 | pr_warning("%s: phy write timeout\n", hw->dev[port]->name); |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 1931 | return -EIO; |
| 1932 | } |
| 1933 | |
| 1934 | static int __gm_phy_read(struct skge_hw *hw, int port, u16 reg, u16 *val) |
| 1935 | { |
| 1936 | int i; |
| 1937 | |
| 1938 | gma_write16(hw, port, GM_SMI_CTRL, |
| 1939 | GM_SMI_CT_PHY_AD(hw->phy_addr) |
| 1940 | | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD); |
| 1941 | |
| 1942 | for (i = 0; i < PHY_RETRIES; i++) { |
| 1943 | udelay(1); |
| 1944 | if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL) |
| 1945 | goto ready; |
| 1946 | } |
| 1947 | |
| 1948 | return -ETIMEDOUT; |
| 1949 | ready: |
| 1950 | *val = gma_read16(hw, port, GM_SMI_DATA); |
| 1951 | return 0; |
| 1952 | } |
| 1953 | |
| 1954 | static u16 gm_phy_read(struct skge_hw *hw, int port, u16 reg) |
| 1955 | { |
| 1956 | u16 v = 0; |
| 1957 | if (__gm_phy_read(hw, port, reg, &v)) |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 1958 | pr_warning("%s: phy read timeout\n", hw->dev[port]->name); |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 1959 | return v; |
| 1960 | } |
| 1961 | |
Stephen Hemminger | 8f3f819 | 2005-11-08 10:33:45 -0800 | [diff] [blame] | 1962 | /* Marvell Phy Initialization */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1963 | static void yukon_init(struct skge_hw *hw, int port) |
| 1964 | { |
| 1965 | struct skge_port *skge = netdev_priv(hw->dev[port]); |
| 1966 | u16 ctrl, ct1000, adv; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1967 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1968 | if (skge->autoneg == AUTONEG_ENABLE) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1969 | u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1970 | |
| 1971 | ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK | |
| 1972 | PHY_M_EC_MAC_S_MSK); |
| 1973 | ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ); |
| 1974 | |
Stephen Hemminger | c506a50 | 2005-06-27 11:33:09 -0700 | [diff] [blame] | 1975 | ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1976 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1977 | gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1978 | } |
| 1979 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1980 | ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1981 | if (skge->autoneg == AUTONEG_DISABLE) |
| 1982 | ctrl &= ~PHY_CT_ANE; |
| 1983 | |
| 1984 | ctrl |= PHY_CT_RESET; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1985 | gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1986 | |
| 1987 | ctrl = 0; |
| 1988 | ct1000 = 0; |
Stephen Hemminger | b18f209 | 2005-06-27 11:33:08 -0700 | [diff] [blame] | 1989 | adv = PHY_AN_CSMA; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1990 | |
| 1991 | if (skge->autoneg == AUTONEG_ENABLE) { |
Stephen Hemminger | 5e1705d | 2005-08-16 14:00:58 -0700 | [diff] [blame] | 1992 | if (hw->copper) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1993 | if (skge->advertising & ADVERTISED_1000baseT_Full) |
| 1994 | ct1000 |= PHY_M_1000C_AFD; |
| 1995 | if (skge->advertising & ADVERTISED_1000baseT_Half) |
| 1996 | ct1000 |= PHY_M_1000C_AHD; |
| 1997 | if (skge->advertising & ADVERTISED_100baseT_Full) |
| 1998 | adv |= PHY_M_AN_100_FD; |
| 1999 | if (skge->advertising & ADVERTISED_100baseT_Half) |
| 2000 | adv |= PHY_M_AN_100_HD; |
| 2001 | if (skge->advertising & ADVERTISED_10baseT_Full) |
| 2002 | adv |= PHY_M_AN_10_FD; |
| 2003 | if (skge->advertising & ADVERTISED_10baseT_Half) |
| 2004 | adv |= PHY_M_AN_10_HD; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2005 | |
Stephen Hemminger | 4b67be9 | 2006-10-05 15:49:51 -0700 | [diff] [blame] | 2006 | /* Set Flow-control capabilities */ |
| 2007 | adv |= phy_pause_map[skge->flow_control]; |
| 2008 | } else { |
| 2009 | if (skge->advertising & ADVERTISED_1000baseT_Full) |
| 2010 | adv |= PHY_M_AN_1000X_AFD; |
| 2011 | if (skge->advertising & ADVERTISED_1000baseT_Half) |
| 2012 | adv |= PHY_M_AN_1000X_AHD; |
| 2013 | |
| 2014 | adv |= fiber_pause_map[skge->flow_control]; |
| 2015 | } |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 2016 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2017 | /* Restart Auto-negotiation */ |
| 2018 | ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG; |
| 2019 | } else { |
| 2020 | /* forced speed/duplex settings */ |
| 2021 | ct1000 = PHY_M_1000C_MSE; |
| 2022 | |
| 2023 | if (skge->duplex == DUPLEX_FULL) |
| 2024 | ctrl |= PHY_CT_DUP_MD; |
| 2025 | |
| 2026 | switch (skge->speed) { |
| 2027 | case SPEED_1000: |
| 2028 | ctrl |= PHY_CT_SP1000; |
| 2029 | break; |
| 2030 | case SPEED_100: |
| 2031 | ctrl |= PHY_CT_SP100; |
| 2032 | break; |
| 2033 | } |
| 2034 | |
| 2035 | ctrl |= PHY_CT_RESET; |
| 2036 | } |
| 2037 | |
Stephen Hemminger | c506a50 | 2005-06-27 11:33:09 -0700 | [diff] [blame] | 2038 | gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2039 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2040 | gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv); |
| 2041 | gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2042 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2043 | /* Enable phy interrupt on autonegotiation complete (or link up) */ |
| 2044 | if (skge->autoneg == AUTONEG_ENABLE) |
Stephen Hemminger | 4cde06e | 2005-07-22 16:26:09 -0700 | [diff] [blame] | 2045 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_MSK); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2046 | else |
Stephen Hemminger | 4cde06e | 2005-07-22 16:26:09 -0700 | [diff] [blame] | 2047 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | static void yukon_reset(struct skge_hw *hw, int port) |
| 2051 | { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2052 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */ |
| 2053 | gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */ |
| 2054 | gma_write16(hw, port, GM_MC_ADDR_H2, 0); |
| 2055 | gma_write16(hw, port, GM_MC_ADDR_H3, 0); |
| 2056 | gma_write16(hw, port, GM_MC_ADDR_H4, 0); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2057 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2058 | gma_write16(hw, port, GM_RX_CTRL, |
| 2059 | gma_read16(hw, port, GM_RX_CTRL) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2060 | | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); |
| 2061 | } |
| 2062 | |
Stephen Hemminger | c886861 | 2005-09-23 09:08:30 -0700 | [diff] [blame] | 2063 | /* Apparently, early versions of Yukon-Lite had wrong chip_id? */ |
| 2064 | static int is_yukon_lite_a0(struct skge_hw *hw) |
| 2065 | { |
| 2066 | u32 reg; |
| 2067 | int ret; |
| 2068 | |
| 2069 | if (hw->chip_id != CHIP_ID_YUKON) |
| 2070 | return 0; |
| 2071 | |
| 2072 | reg = skge_read32(hw, B2_FAR); |
| 2073 | skge_write8(hw, B2_FAR + 3, 0xff); |
| 2074 | ret = (skge_read8(hw, B2_FAR + 3) != 0); |
| 2075 | skge_write32(hw, B2_FAR, reg); |
| 2076 | return ret; |
| 2077 | } |
| 2078 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2079 | static void yukon_mac_init(struct skge_hw *hw, int port) |
| 2080 | { |
| 2081 | struct skge_port *skge = netdev_priv(hw->dev[port]); |
| 2082 | int i; |
| 2083 | u32 reg; |
| 2084 | const u8 *addr = hw->dev[port]->dev_addr; |
| 2085 | |
| 2086 | /* WA code for COMA mode -- set PHY reset */ |
| 2087 | if (hw->chip_id == CHIP_ID_YUKON_LITE && |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 2088 | hw->chip_rev >= CHIP_REV_YU_LITE_A3) { |
| 2089 | reg = skge_read32(hw, B2_GP_IO); |
| 2090 | reg |= GP_DIR_9 | GP_IO_9; |
| 2091 | skge_write32(hw, B2_GP_IO, reg); |
| 2092 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2093 | |
| 2094 | /* hard reset */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2095 | skge_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); |
| 2096 | skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2097 | |
| 2098 | /* WA code for COMA mode -- clear PHY reset */ |
| 2099 | if (hw->chip_id == CHIP_ID_YUKON_LITE && |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 2100 | hw->chip_rev >= CHIP_REV_YU_LITE_A3) { |
| 2101 | reg = skge_read32(hw, B2_GP_IO); |
| 2102 | reg |= GP_DIR_9; |
| 2103 | reg &= ~GP_IO_9; |
| 2104 | skge_write32(hw, B2_GP_IO, reg); |
| 2105 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2106 | |
| 2107 | /* Set hardware config mode */ |
| 2108 | reg = GPC_INT_POL_HI | GPC_DIS_FC | GPC_DIS_SLEEP | |
| 2109 | GPC_ENA_XC | GPC_ANEG_ADV_ALL_M | GPC_ENA_PAUSE; |
Stephen Hemminger | 5e1705d | 2005-08-16 14:00:58 -0700 | [diff] [blame] | 2110 | reg |= hw->copper ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2111 | |
| 2112 | /* Clear GMC reset */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2113 | skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_SET); |
| 2114 | skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_CLR); |
| 2115 | skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR); |
Stephen Hemminger | 564f9ab | 2006-02-13 15:46:48 -0800 | [diff] [blame] | 2116 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2117 | if (skge->autoneg == AUTONEG_DISABLE) { |
| 2118 | reg = GM_GPCR_AU_ALL_DIS; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2119 | gma_write16(hw, port, GM_GP_CTRL, |
| 2120 | gma_read16(hw, port, GM_GP_CTRL) | reg); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2121 | |
| 2122 | switch (skge->speed) { |
| 2123 | case SPEED_1000: |
Stephen Hemminger | 564f9ab | 2006-02-13 15:46:48 -0800 | [diff] [blame] | 2124 | reg &= ~GM_GPCR_SPEED_100; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2125 | reg |= GM_GPCR_SPEED_1000; |
Stephen Hemminger | 564f9ab | 2006-02-13 15:46:48 -0800 | [diff] [blame] | 2126 | break; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2127 | case SPEED_100: |
Stephen Hemminger | 564f9ab | 2006-02-13 15:46:48 -0800 | [diff] [blame] | 2128 | reg &= ~GM_GPCR_SPEED_1000; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2129 | reg |= GM_GPCR_SPEED_100; |
Stephen Hemminger | 564f9ab | 2006-02-13 15:46:48 -0800 | [diff] [blame] | 2130 | break; |
| 2131 | case SPEED_10: |
| 2132 | reg &= ~(GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100); |
| 2133 | break; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | if (skge->duplex == DUPLEX_FULL) |
| 2137 | reg |= GM_GPCR_DUP_FULL; |
| 2138 | } else |
| 2139 | reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL; |
Stephen Hemminger | 564f9ab | 2006-02-13 15:46:48 -0800 | [diff] [blame] | 2140 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2141 | switch (skge->flow_control) { |
| 2142 | case FLOW_MODE_NONE: |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2143 | skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2144 | reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; |
| 2145 | break; |
| 2146 | case FLOW_MODE_LOC_SEND: |
| 2147 | /* disable Rx flow-control */ |
| 2148 | reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 2149 | break; |
| 2150 | case FLOW_MODE_SYMMETRIC: |
| 2151 | case FLOW_MODE_SYM_OR_REM: |
| 2152 | /* enable Tx & Rx flow-control */ |
| 2153 | break; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2154 | } |
| 2155 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2156 | gma_write16(hw, port, GM_GP_CTRL, reg); |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 2157 | skge_read16(hw, SK_REG(port, GMAC_IRQ_SRC)); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2158 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2159 | yukon_init(hw, port); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2160 | |
| 2161 | /* MIB clear */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2162 | reg = gma_read16(hw, port, GM_PHY_ADDR); |
| 2163 | gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2164 | |
| 2165 | for (i = 0; i < GM_MIB_CNT_SIZE; i++) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2166 | gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i); |
| 2167 | gma_write16(hw, port, GM_PHY_ADDR, reg); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2168 | |
| 2169 | /* transmit control */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2170 | gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF)); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2171 | |
| 2172 | /* receive control reg: unicast + multicast + no FCS */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2173 | gma_write16(hw, port, GM_RX_CTRL, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2174 | GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA); |
| 2175 | |
| 2176 | /* transmit flow control */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2177 | gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2178 | |
| 2179 | /* transmit parameter */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2180 | gma_write16(hw, port, GM_TX_PARAM, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2181 | TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) | |
| 2182 | TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) | |
| 2183 | TX_IPG_JAM_DATA(TX_IPG_JAM_DEF)); |
| 2184 | |
Stephen Hemminger | 44c7fcc | 2007-11-28 14:23:01 -0800 | [diff] [blame] | 2185 | /* configure the Serial Mode Register */ |
| 2186 | reg = DATA_BLIND_VAL(DATA_BLIND_DEF) |
| 2187 | | GM_SMOD_VLAN_ENA |
| 2188 | | IPG_DATA_VAL(IPG_DATA_DEF); |
| 2189 | |
| 2190 | if (hw->dev[port]->mtu > ETH_DATA_LEN) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2191 | reg |= GM_SMOD_JUMBO_ENA; |
| 2192 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2193 | gma_write16(hw, port, GM_SERIAL_MODE, reg); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2194 | |
| 2195 | /* physical address: used for pause frames */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2196 | gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2197 | /* virtual address for data */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2198 | gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2199 | |
| 2200 | /* enable interrupt mask for counter overflows */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2201 | gma_write16(hw, port, GM_TX_IRQ_MSK, 0); |
| 2202 | gma_write16(hw, port, GM_RX_IRQ_MSK, 0); |
| 2203 | gma_write16(hw, port, GM_TR_IRQ_MSK, 0); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2204 | |
| 2205 | /* Initialize Mac Fifo */ |
| 2206 | |
| 2207 | /* Configure Rx MAC FIFO */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2208 | skge_write16(hw, SK_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2209 | reg = GMF_OPER_ON | GMF_RX_F_FL_ON; |
Stephen Hemminger | c886861 | 2005-09-23 09:08:30 -0700 | [diff] [blame] | 2210 | |
| 2211 | /* disable Rx GMAC FIFO Flush for YUKON-Lite Rev. A0 only */ |
| 2212 | if (is_yukon_lite_a0(hw)) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2213 | reg &= ~GMF_RX_F_FL_ON; |
Stephen Hemminger | c886861 | 2005-09-23 09:08:30 -0700 | [diff] [blame] | 2214 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2215 | skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); |
| 2216 | skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg); |
Stephen Hemminger | c592308 | 2005-08-16 14:01:02 -0700 | [diff] [blame] | 2217 | /* |
| 2218 | * because Pause Packet Truncation in GMAC is not working |
| 2219 | * we have to increase the Flush Threshold to 64 bytes |
| 2220 | * in order to flush pause packets in Rx FIFO on Yukon-1 |
| 2221 | */ |
| 2222 | skge_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF+1); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2223 | |
| 2224 | /* Configure Tx MAC FIFO */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2225 | skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR); |
| 2226 | skge_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2227 | } |
| 2228 | |
Stephen Hemminger | 355ec57 | 2005-11-08 10:33:43 -0800 | [diff] [blame] | 2229 | /* Go into power down mode */ |
| 2230 | static void yukon_suspend(struct skge_hw *hw, int port) |
| 2231 | { |
| 2232 | u16 ctrl; |
| 2233 | |
| 2234 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); |
| 2235 | ctrl |= PHY_M_PC_POL_R_DIS; |
| 2236 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); |
| 2237 | |
| 2238 | ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL); |
| 2239 | ctrl |= PHY_CT_RESET; |
| 2240 | gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); |
| 2241 | |
| 2242 | /* switch IEEE compatible power down mode on */ |
| 2243 | ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL); |
| 2244 | ctrl |= PHY_CT_PDOWN; |
| 2245 | gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); |
| 2246 | } |
| 2247 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2248 | static void yukon_stop(struct skge_port *skge) |
| 2249 | { |
| 2250 | struct skge_hw *hw = skge->hw; |
| 2251 | int port = skge->port; |
| 2252 | |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 2253 | skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0); |
| 2254 | yukon_reset(hw, port); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2255 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2256 | gma_write16(hw, port, GM_GP_CTRL, |
| 2257 | gma_read16(hw, port, GM_GP_CTRL) |
Stephen Hemminger | 0eedf4a | 2005-07-22 16:26:04 -0700 | [diff] [blame] | 2258 | & ~(GM_GPCR_TX_ENA|GM_GPCR_RX_ENA)); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2259 | gma_read16(hw, port, GM_GP_CTRL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2260 | |
Stephen Hemminger | 355ec57 | 2005-11-08 10:33:43 -0800 | [diff] [blame] | 2261 | yukon_suspend(hw, port); |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 2262 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2263 | /* set GPHY Control reset */ |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 2264 | skge_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); |
| 2265 | skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | static void yukon_get_stats(struct skge_port *skge, u64 *data) |
| 2269 | { |
| 2270 | struct skge_hw *hw = skge->hw; |
| 2271 | int port = skge->port; |
| 2272 | int i; |
| 2273 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2274 | data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32 |
| 2275 | | gma_read32(hw, port, GM_TXO_OK_LO); |
| 2276 | data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32 |
| 2277 | | gma_read32(hw, port, GM_RXO_OK_LO); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2278 | |
| 2279 | for (i = 2; i < ARRAY_SIZE(skge_stats); i++) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2280 | data[i] = gma_read32(hw, port, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2281 | skge_stats[i].gma_offset); |
| 2282 | } |
| 2283 | |
| 2284 | static void yukon_mac_intr(struct skge_hw *hw, int port) |
| 2285 | { |
Stephen Hemminger | 7e676d9 | 2005-06-27 11:33:13 -0700 | [diff] [blame] | 2286 | struct net_device *dev = hw->dev[port]; |
| 2287 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2288 | u8 status = skge_read8(hw, SK_REG(port, GMAC_IRQ_SRC)); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2289 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 2290 | netif_printk(skge, intr, KERN_DEBUG, skge->netdev, |
| 2291 | "mac interrupt status 0x%x\n", status); |
Stephen Hemminger | 7e676d9 | 2005-06-27 11:33:13 -0700 | [diff] [blame] | 2292 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2293 | if (status & GM_IS_RX_FF_OR) { |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 2294 | ++dev->stats.rx_fifo_errors; |
Stephen Hemminger | d8a0994 | 2005-07-22 16:26:08 -0700 | [diff] [blame] | 2295 | skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2296 | } |
Stephen Hemminger | d8a0994 | 2005-07-22 16:26:08 -0700 | [diff] [blame] | 2297 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2298 | if (status & GM_IS_TX_FF_UR) { |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 2299 | ++dev->stats.tx_fifo_errors; |
Stephen Hemminger | d8a0994 | 2005-07-22 16:26:08 -0700 | [diff] [blame] | 2300 | skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | } |
| 2304 | |
| 2305 | static u16 yukon_speed(const struct skge_hw *hw, u16 aux) |
| 2306 | { |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 2307 | switch (aux & PHY_M_PS_SPEED_MSK) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2308 | case PHY_M_PS_SPEED_1000: |
| 2309 | return SPEED_1000; |
| 2310 | case PHY_M_PS_SPEED_100: |
| 2311 | return SPEED_100; |
| 2312 | default: |
| 2313 | return SPEED_10; |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | static void yukon_link_up(struct skge_port *skge) |
| 2318 | { |
| 2319 | struct skge_hw *hw = skge->hw; |
| 2320 | int port = skge->port; |
| 2321 | u16 reg; |
| 2322 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2323 | /* Enable Transmit FIFO Underrun */ |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 2324 | skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2325 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2326 | reg = gma_read16(hw, port, GM_GP_CTRL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2327 | if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE) |
| 2328 | reg |= GM_GPCR_DUP_FULL; |
| 2329 | |
| 2330 | /* enable Rx/Tx */ |
| 2331 | reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2332 | gma_write16(hw, port, GM_GP_CTRL, reg); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2333 | |
Stephen Hemminger | 4cde06e | 2005-07-22 16:26:09 -0700 | [diff] [blame] | 2334 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2335 | skge_link_up(skge); |
| 2336 | } |
| 2337 | |
| 2338 | static void yukon_link_down(struct skge_port *skge) |
| 2339 | { |
| 2340 | struct skge_hw *hw = skge->hw; |
| 2341 | int port = skge->port; |
Stephen Hemminger | d8a0994 | 2005-07-22 16:26:08 -0700 | [diff] [blame] | 2342 | u16 ctrl; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2343 | |
Stephen Hemminger | d8a0994 | 2005-07-22 16:26:08 -0700 | [diff] [blame] | 2344 | ctrl = gma_read16(hw, port, GM_GP_CTRL); |
| 2345 | ctrl &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA); |
| 2346 | gma_write16(hw, port, GM_GP_CTRL, ctrl); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2347 | |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 2348 | if (skge->flow_status == FLOW_STAT_REM_SEND) { |
| 2349 | ctrl = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV); |
| 2350 | ctrl |= PHY_M_AN_ASP; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2351 | /* restore Asymmetric Pause bit */ |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 2352 | gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, ctrl); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2353 | } |
| 2354 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2355 | skge_link_down(skge); |
| 2356 | |
| 2357 | yukon_init(hw, port); |
| 2358 | } |
| 2359 | |
| 2360 | static void yukon_phy_intr(struct skge_port *skge) |
| 2361 | { |
| 2362 | struct skge_hw *hw = skge->hw; |
| 2363 | int port = skge->port; |
| 2364 | const char *reason = NULL; |
| 2365 | u16 istatus, phystat; |
| 2366 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2367 | istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT); |
| 2368 | phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT); |
Stephen Hemminger | 7e676d9 | 2005-06-27 11:33:13 -0700 | [diff] [blame] | 2369 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 2370 | netif_printk(skge, intr, KERN_DEBUG, skge->netdev, |
| 2371 | "phy interrupt status 0x%x 0x%x\n", istatus, phystat); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2372 | |
| 2373 | if (istatus & PHY_M_IS_AN_COMPL) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2374 | if (gm_phy_read(hw, port, PHY_MARV_AUNE_LP) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2375 | & PHY_M_AN_RF) { |
| 2376 | reason = "remote fault"; |
| 2377 | goto failed; |
| 2378 | } |
| 2379 | |
Stephen Hemminger | c506a50 | 2005-06-27 11:33:09 -0700 | [diff] [blame] | 2380 | if (gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2381 | reason = "master/slave fault"; |
| 2382 | goto failed; |
| 2383 | } |
| 2384 | |
| 2385 | if (!(phystat & PHY_M_PS_SPDUP_RES)) { |
| 2386 | reason = "speed/duplex"; |
| 2387 | goto failed; |
| 2388 | } |
| 2389 | |
| 2390 | skge->duplex = (phystat & PHY_M_PS_FULL_DUP) |
| 2391 | ? DUPLEX_FULL : DUPLEX_HALF; |
| 2392 | skge->speed = yukon_speed(hw, phystat); |
| 2393 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2394 | /* We are using IEEE 802.3z/D5.0 Table 37-4 */ |
| 2395 | switch (phystat & PHY_M_PS_PAUSE_MSK) { |
| 2396 | case PHY_M_PS_PAUSE_MSK: |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 2397 | skge->flow_status = FLOW_STAT_SYMMETRIC; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2398 | break; |
| 2399 | case PHY_M_PS_RX_P_EN: |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 2400 | skge->flow_status = FLOW_STAT_REM_SEND; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2401 | break; |
| 2402 | case PHY_M_PS_TX_P_EN: |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 2403 | skge->flow_status = FLOW_STAT_LOC_SEND; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2404 | break; |
| 2405 | default: |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 2406 | skge->flow_status = FLOW_STAT_NONE; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2407 | } |
| 2408 | |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 2409 | if (skge->flow_status == FLOW_STAT_NONE || |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2410 | (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF)) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2411 | skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2412 | else |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2413 | skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2414 | yukon_link_up(skge); |
| 2415 | return; |
| 2416 | } |
| 2417 | |
| 2418 | if (istatus & PHY_M_IS_LSP_CHANGE) |
| 2419 | skge->speed = yukon_speed(hw, phystat); |
| 2420 | |
| 2421 | if (istatus & PHY_M_IS_DUP_CHANGE) |
| 2422 | skge->duplex = (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; |
| 2423 | if (istatus & PHY_M_IS_LST_CHANGE) { |
| 2424 | if (phystat & PHY_M_PS_LINK_UP) |
| 2425 | yukon_link_up(skge); |
| 2426 | else |
| 2427 | yukon_link_down(skge); |
| 2428 | } |
| 2429 | return; |
| 2430 | failed: |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 2431 | pr_err("%s: autonegotiation failed (%s)\n", skge->netdev->name, reason); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2432 | |
| 2433 | /* XXX restart autonegotiation? */ |
| 2434 | } |
| 2435 | |
Stephen Hemminger | ee294dc | 2005-12-14 15:47:44 -0800 | [diff] [blame] | 2436 | static void skge_phy_reset(struct skge_port *skge) |
| 2437 | { |
| 2438 | struct skge_hw *hw = skge->hw; |
| 2439 | int port = skge->port; |
Jeff Garzik | aae343d | 2006-12-02 07:14:39 -0500 | [diff] [blame] | 2440 | struct net_device *dev = hw->dev[port]; |
Stephen Hemminger | ee294dc | 2005-12-14 15:47:44 -0800 | [diff] [blame] | 2441 | |
| 2442 | netif_stop_queue(skge->netdev); |
| 2443 | netif_carrier_off(skge->netdev); |
| 2444 | |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 2445 | spin_lock_bh(&hw->phy_lock); |
Stephen Hemminger | ee294dc | 2005-12-14 15:47:44 -0800 | [diff] [blame] | 2446 | if (hw->chip_id == CHIP_ID_GENESIS) { |
| 2447 | genesis_reset(hw, port); |
| 2448 | genesis_mac_init(hw, port); |
| 2449 | } else { |
| 2450 | yukon_reset(hw, port); |
| 2451 | yukon_init(hw, port); |
| 2452 | } |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 2453 | spin_unlock_bh(&hw->phy_lock); |
Stephen Hemminger | 7581409 | 2006-12-01 11:41:08 -0800 | [diff] [blame] | 2454 | |
Stephen Hemminger | f80d032 | 2008-11-19 22:01:26 -0800 | [diff] [blame] | 2455 | skge_set_multicast(dev); |
Stephen Hemminger | ee294dc | 2005-12-14 15:47:44 -0800 | [diff] [blame] | 2456 | } |
| 2457 | |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 2458 | /* Basic MII support */ |
| 2459 | static int skge_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 2460 | { |
| 2461 | struct mii_ioctl_data *data = if_mii(ifr); |
| 2462 | struct skge_port *skge = netdev_priv(dev); |
| 2463 | struct skge_hw *hw = skge->hw; |
| 2464 | int err = -EOPNOTSUPP; |
| 2465 | |
| 2466 | if (!netif_running(dev)) |
| 2467 | return -ENODEV; /* Phy still in reset */ |
| 2468 | |
| 2469 | switch(cmd) { |
| 2470 | case SIOCGMIIPHY: |
| 2471 | data->phy_id = hw->phy_addr; |
| 2472 | |
| 2473 | /* fallthru */ |
| 2474 | case SIOCGMIIREG: { |
| 2475 | u16 val = 0; |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 2476 | spin_lock_bh(&hw->phy_lock); |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 2477 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 2478 | err = __xm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val); |
| 2479 | else |
| 2480 | err = __gm_phy_read(hw, skge->port, data->reg_num & 0x1f, &val); |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 2481 | spin_unlock_bh(&hw->phy_lock); |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 2482 | data->val_out = val; |
| 2483 | break; |
| 2484 | } |
| 2485 | |
| 2486 | case SIOCSMIIREG: |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 2487 | spin_lock_bh(&hw->phy_lock); |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 2488 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 2489 | err = xm_phy_write(hw, skge->port, data->reg_num & 0x1f, |
| 2490 | data->val_in); |
| 2491 | else |
| 2492 | err = gm_phy_write(hw, skge->port, data->reg_num & 0x1f, |
| 2493 | data->val_in); |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 2494 | spin_unlock_bh(&hw->phy_lock); |
Stephen Hemminger | 2cd8e5d | 2005-11-08 10:33:42 -0800 | [diff] [blame] | 2495 | break; |
| 2496 | } |
| 2497 | return err; |
| 2498 | } |
| 2499 | |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 2500 | static void skge_ramset(struct skge_hw *hw, u16 q, u32 start, size_t len) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2501 | { |
| 2502 | u32 end; |
| 2503 | |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 2504 | start /= 8; |
| 2505 | len /= 8; |
| 2506 | end = start + len - 1; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2507 | |
| 2508 | skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR); |
| 2509 | skge_write32(hw, RB_ADDR(q, RB_START), start); |
| 2510 | skge_write32(hw, RB_ADDR(q, RB_WP), start); |
| 2511 | skge_write32(hw, RB_ADDR(q, RB_RP), start); |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 2512 | skge_write32(hw, RB_ADDR(q, RB_END), end); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2513 | |
| 2514 | if (q == Q_R1 || q == Q_R2) { |
| 2515 | /* Set thresholds on receive queue's */ |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 2516 | skge_write32(hw, RB_ADDR(q, RB_RX_UTPP), |
| 2517 | start + (2*len)/3); |
| 2518 | skge_write32(hw, RB_ADDR(q, RB_RX_LTPP), |
| 2519 | start + (len/3)); |
| 2520 | } else { |
| 2521 | /* Enable store & forward on Tx queue's because |
| 2522 | * Tx FIFO is only 4K on Genesis and 1K on Yukon |
| 2523 | */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2524 | skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD); |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 2525 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2526 | |
| 2527 | skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD); |
| 2528 | } |
| 2529 | |
| 2530 | /* Setup Bus Memory Interface */ |
| 2531 | static void skge_qset(struct skge_port *skge, u16 q, |
| 2532 | const struct skge_element *e) |
| 2533 | { |
| 2534 | struct skge_hw *hw = skge->hw; |
| 2535 | u32 watermark = 0x600; |
| 2536 | u64 base = skge->dma + (e->desc - skge->mem); |
| 2537 | |
| 2538 | /* optimization to reduce window on 32bit/33mhz */ |
| 2539 | if ((skge_read16(hw, B0_CTST) & (CS_BUS_CLOCK | CS_BUS_SLOT_SZ)) == 0) |
| 2540 | watermark /= 2; |
| 2541 | |
| 2542 | skge_write32(hw, Q_ADDR(q, Q_CSR), CSR_CLR_RESET); |
| 2543 | skge_write32(hw, Q_ADDR(q, Q_F), watermark); |
| 2544 | skge_write32(hw, Q_ADDR(q, Q_DA_H), (u32)(base >> 32)); |
| 2545 | skge_write32(hw, Q_ADDR(q, Q_DA_L), (u32)base); |
| 2546 | } |
| 2547 | |
| 2548 | static int skge_up(struct net_device *dev) |
| 2549 | { |
| 2550 | struct skge_port *skge = netdev_priv(dev); |
| 2551 | struct skge_hw *hw = skge->hw; |
| 2552 | int port = skge->port; |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 2553 | u32 chunk, ram_addr; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2554 | size_t rx_size, tx_size; |
| 2555 | int err; |
| 2556 | |
Stephen Hemminger | fae8759 | 2007-02-02 08:22:51 -0800 | [diff] [blame] | 2557 | if (!is_valid_ether_addr(dev->dev_addr)) |
| 2558 | return -EINVAL; |
| 2559 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 2560 | netif_info(skge, ifup, skge->netdev, "enabling interface\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2561 | |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 2562 | if (dev->mtu > RX_BUF_SIZE) |
Stephen Hemminger | 901ccef | 2006-03-23 11:07:23 -0800 | [diff] [blame] | 2563 | skge->rx_buf_size = dev->mtu + ETH_HLEN; |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 2564 | else |
| 2565 | skge->rx_buf_size = RX_BUF_SIZE; |
| 2566 | |
| 2567 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2568 | rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc); |
| 2569 | tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc); |
| 2570 | skge->mem_size = tx_size + rx_size; |
| 2571 | skge->mem = pci_alloc_consistent(hw->pdev, skge->mem_size, &skge->dma); |
| 2572 | if (!skge->mem) |
| 2573 | return -ENOMEM; |
| 2574 | |
Stephen Hemminger | c3da144 | 2006-03-21 10:57:01 -0800 | [diff] [blame] | 2575 | BUG_ON(skge->dma & 7); |
| 2576 | |
| 2577 | if ((u64)skge->dma >> 32 != ((u64) skge->dma + skge->mem_size) >> 32) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 2578 | dev_err(&hw->pdev->dev, "pci_alloc_consistent region crosses 4G boundary\n"); |
Stephen Hemminger | c3da144 | 2006-03-21 10:57:01 -0800 | [diff] [blame] | 2579 | err = -EINVAL; |
| 2580 | goto free_pci_mem; |
| 2581 | } |
| 2582 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2583 | memset(skge->mem, 0, skge->mem_size); |
| 2584 | |
Stephen Hemminger | 203babb | 2006-03-21 10:57:05 -0800 | [diff] [blame] | 2585 | err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma); |
| 2586 | if (err) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2587 | goto free_pci_mem; |
| 2588 | |
Stephen Hemminger | c54f976 | 2006-09-01 15:53:47 -0700 | [diff] [blame] | 2589 | err = skge_rx_fill(dev); |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 2590 | if (err) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2591 | goto free_rx_ring; |
| 2592 | |
Stephen Hemminger | 203babb | 2006-03-21 10:57:05 -0800 | [diff] [blame] | 2593 | err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size, |
| 2594 | skge->dma + rx_size); |
| 2595 | if (err) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2596 | goto free_rx_ring; |
| 2597 | |
Stephen Hemminger | 8f3f819 | 2005-11-08 10:33:45 -0800 | [diff] [blame] | 2598 | /* Initialize MAC */ |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 2599 | spin_lock_bh(&hw->phy_lock); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2600 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 2601 | genesis_mac_init(hw, port); |
| 2602 | else |
| 2603 | yukon_mac_init(hw, port); |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 2604 | spin_unlock_bh(&hw->phy_lock); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2605 | |
Stephen Hemminger | 29816d9 | 2007-11-26 11:54:48 -0800 | [diff] [blame] | 2606 | /* Configure RAMbuffers - equally between ports and tx/rx */ |
| 2607 | chunk = (hw->ram_size - hw->ram_offset) / (hw->ports * 2); |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 2608 | ram_addr = hw->ram_offset + 2 * chunk * port; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2609 | |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 2610 | skge_ramset(hw, rxqaddr[port], ram_addr, chunk); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2611 | skge_qset(skge, rxqaddr[port], skge->rx_ring.to_clean); |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 2612 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2613 | BUG_ON(skge->tx_ring.to_use != skge->tx_ring.to_clean); |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 2614 | skge_ramset(hw, txqaddr[port], ram_addr+chunk, chunk); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2615 | skge_qset(skge, txqaddr[port], skge->tx_ring.to_use); |
| 2616 | |
| 2617 | /* Start receiver BMU */ |
| 2618 | wmb(); |
| 2619 | skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F); |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 2620 | skge_led(skge, LED_MODE_ON); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2621 | |
Stephen Hemminger | 4ebabfc | 2007-03-16 14:01:27 -0700 | [diff] [blame] | 2622 | spin_lock_irq(&hw->hw_lock); |
| 2623 | hw->intr_mask |= portmask[port]; |
| 2624 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
| 2625 | spin_unlock_irq(&hw->hw_lock); |
| 2626 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2627 | napi_enable(&skge->napi); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2628 | return 0; |
| 2629 | |
| 2630 | free_rx_ring: |
| 2631 | skge_rx_clean(skge); |
| 2632 | kfree(skge->rx_ring.start); |
| 2633 | free_pci_mem: |
| 2634 | pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma); |
Stephen Hemminger | 7731a4e | 2005-12-14 15:47:46 -0800 | [diff] [blame] | 2635 | skge->mem = NULL; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2636 | |
| 2637 | return err; |
| 2638 | } |
| 2639 | |
Stephen Hemminger | 60b24b5 | 2007-10-16 12:15:50 -0700 | [diff] [blame] | 2640 | /* stop receiver */ |
| 2641 | static void skge_rx_stop(struct skge_hw *hw, int port) |
| 2642 | { |
| 2643 | skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_STOP); |
| 2644 | skge_write32(hw, RB_ADDR(port ? Q_R2 : Q_R1, RB_CTRL), |
| 2645 | RB_RST_SET|RB_DIS_OP_MD); |
| 2646 | skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET); |
| 2647 | } |
| 2648 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2649 | static int skge_down(struct net_device *dev) |
| 2650 | { |
| 2651 | struct skge_port *skge = netdev_priv(dev); |
| 2652 | struct skge_hw *hw = skge->hw; |
| 2653 | int port = skge->port; |
| 2654 | |
Stephen Hemminger | 7731a4e | 2005-12-14 15:47:46 -0800 | [diff] [blame] | 2655 | if (skge->mem == NULL) |
| 2656 | return 0; |
| 2657 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 2658 | netif_info(skge, ifdown, skge->netdev, "disabling interface\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2659 | |
Michal Schmidt | d119b39 | 2009-04-14 15:16:55 -0700 | [diff] [blame] | 2660 | netif_tx_disable(dev); |
Stephen Hemminger | 692412b | 2007-04-09 15:32:45 -0700 | [diff] [blame] | 2661 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 2662 | if (hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC) |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 2663 | del_timer_sync(&skge->link_timer); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2664 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2665 | napi_disable(&skge->napi); |
Stephen Hemminger | 692412b | 2007-04-09 15:32:45 -0700 | [diff] [blame] | 2666 | netif_carrier_off(dev); |
Stephen Hemminger | 4ebabfc | 2007-03-16 14:01:27 -0700 | [diff] [blame] | 2667 | |
| 2668 | spin_lock_irq(&hw->hw_lock); |
| 2669 | hw->intr_mask &= ~portmask[port]; |
| 2670 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
| 2671 | spin_unlock_irq(&hw->hw_lock); |
| 2672 | |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 2673 | skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF); |
| 2674 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 2675 | genesis_stop(skge); |
| 2676 | else |
| 2677 | yukon_stop(skge); |
| 2678 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2679 | /* Stop transmitter */ |
| 2680 | skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP); |
| 2681 | skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), |
| 2682 | RB_RST_SET|RB_DIS_OP_MD); |
| 2683 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2684 | |
| 2685 | /* Disable Force Sync bit and Enable Alloc bit */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2686 | skge_write8(hw, SK_REG(port, TXA_CTRL), |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2687 | TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC); |
| 2688 | |
| 2689 | /* Stop Interval Timer and Limit Counter of Tx Arbiter */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2690 | skge_write32(hw, SK_REG(port, TXA_ITI_INI), 0L); |
| 2691 | skge_write32(hw, SK_REG(port, TXA_LIM_INI), 0L); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2692 | |
| 2693 | /* Reset PCI FIFO */ |
| 2694 | skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET); |
| 2695 | skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET); |
| 2696 | |
| 2697 | /* Reset the RAM Buffer async Tx queue */ |
| 2698 | skge_write8(hw, RB_ADDR(port == 0 ? Q_XA1 : Q_XA2, RB_CTRL), RB_RST_SET); |
Stephen Hemminger | 60b24b5 | 2007-10-16 12:15:50 -0700 | [diff] [blame] | 2699 | |
| 2700 | skge_rx_stop(hw, port); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2701 | |
| 2702 | if (hw->chip_id == CHIP_ID_GENESIS) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2703 | skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET); |
| 2704 | skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2705 | } else { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2706 | skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); |
| 2707 | skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2708 | } |
| 2709 | |
Stephen Hemminger | 6abebb5 | 2005-07-22 16:26:10 -0700 | [diff] [blame] | 2710 | skge_led(skge, LED_MODE_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2711 | |
Stephen Hemminger | e3a1b99 | 2007-03-16 14:01:26 -0700 | [diff] [blame] | 2712 | netif_tx_lock_bh(dev); |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 2713 | skge_tx_clean(dev); |
Stephen Hemminger | e3a1b99 | 2007-03-16 14:01:26 -0700 | [diff] [blame] | 2714 | netif_tx_unlock_bh(dev); |
| 2715 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2716 | skge_rx_clean(skge); |
| 2717 | |
| 2718 | kfree(skge->rx_ring.start); |
| 2719 | kfree(skge->tx_ring.start); |
| 2720 | pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma); |
Stephen Hemminger | 7731a4e | 2005-12-14 15:47:46 -0800 | [diff] [blame] | 2721 | skge->mem = NULL; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2722 | return 0; |
| 2723 | } |
| 2724 | |
Stephen Hemminger | 29b4e88 | 2006-03-23 11:07:28 -0800 | [diff] [blame] | 2725 | static inline int skge_avail(const struct skge_ring *ring) |
| 2726 | { |
Stephen Hemminger | 992c962 | 2007-03-16 14:01:30 -0700 | [diff] [blame] | 2727 | smp_mb(); |
Stephen Hemminger | 29b4e88 | 2006-03-23 11:07:28 -0800 | [diff] [blame] | 2728 | return ((ring->to_clean > ring->to_use) ? 0 : ring->count) |
| 2729 | + (ring->to_clean - ring->to_use) - 1; |
| 2730 | } |
| 2731 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 2732 | static netdev_tx_t skge_xmit_frame(struct sk_buff *skb, |
| 2733 | struct net_device *dev) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2734 | { |
| 2735 | struct skge_port *skge = netdev_priv(dev); |
| 2736 | struct skge_hw *hw = skge->hw; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2737 | struct skge_element *e; |
| 2738 | struct skge_tx_desc *td; |
| 2739 | int i; |
| 2740 | u32 control, len; |
| 2741 | u64 map; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2742 | |
Herbert Xu | 5b057c6 | 2006-06-23 02:06:41 -0700 | [diff] [blame] | 2743 | if (skb_padto(skb, ETH_ZLEN)) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2744 | return NETDEV_TX_OK; |
| 2745 | |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 2746 | if (unlikely(skge_avail(&skge->tx_ring) < skb_shinfo(skb)->nr_frags + 1)) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2747 | return NETDEV_TX_BUSY; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2748 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2749 | e = skge->tx_ring.to_use; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2750 | td = e->desc; |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2751 | BUG_ON(td->control & BMU_OWN); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2752 | e->skb = skb; |
| 2753 | len = skb_headlen(skb); |
| 2754 | map = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE); |
| 2755 | pci_unmap_addr_set(e, mapaddr, map); |
| 2756 | pci_unmap_len_set(e, maplen, len); |
| 2757 | |
| 2758 | td->dma_lo = map; |
| 2759 | td->dma_hi = map >> 32; |
| 2760 | |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 2761 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2762 | const int offset = skb_transport_offset(skb); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2763 | |
| 2764 | /* This seems backwards, but it is what the sk98lin |
| 2765 | * does. Looks like hardware is wrong? |
| 2766 | */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 2767 | if (ipip_hdr(skb)->protocol == IPPROTO_UDP && |
| 2768 | hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2769 | control = BMU_TCP_CHECK; |
| 2770 | else |
| 2771 | control = BMU_UDP_CHECK; |
| 2772 | |
| 2773 | td->csum_offs = 0; |
| 2774 | td->csum_start = offset; |
Al Viro | ff1dcad | 2006-11-20 18:07:29 -0800 | [diff] [blame] | 2775 | td->csum_write = offset + skb->csum_offset; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2776 | } else |
| 2777 | control = BMU_CHECK; |
| 2778 | |
| 2779 | if (!skb_shinfo(skb)->nr_frags) /* single buffer i.e. no fragments */ |
| 2780 | control |= BMU_EOF| BMU_IRQ_EOF; |
| 2781 | else { |
| 2782 | struct skge_tx_desc *tf = td; |
| 2783 | |
| 2784 | control |= BMU_STFWD; |
| 2785 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 2786 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 2787 | |
| 2788 | map = pci_map_page(hw->pdev, frag->page, frag->page_offset, |
| 2789 | frag->size, PCI_DMA_TODEVICE); |
| 2790 | |
| 2791 | e = e->next; |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2792 | e->skb = skb; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2793 | tf = e->desc; |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2794 | BUG_ON(tf->control & BMU_OWN); |
| 2795 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2796 | tf->dma_lo = map; |
| 2797 | tf->dma_hi = (u64) map >> 32; |
| 2798 | pci_unmap_addr_set(e, mapaddr, map); |
| 2799 | pci_unmap_len_set(e, maplen, frag->size); |
| 2800 | |
| 2801 | tf->control = BMU_OWN | BMU_SW | control | frag->size; |
| 2802 | } |
| 2803 | tf->control |= BMU_EOF | BMU_IRQ_EOF; |
| 2804 | } |
| 2805 | /* Make sure all the descriptors written */ |
| 2806 | wmb(); |
| 2807 | td->control = BMU_OWN | BMU_SW | BMU_STF | control | len; |
| 2808 | wmb(); |
| 2809 | |
| 2810 | skge_write8(hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_START); |
| 2811 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 2812 | netif_printk(skge, tx_queued, KERN_DEBUG, skge->netdev, |
| 2813 | "tx queued, slot %td, len %d\n", |
| 2814 | e - skge->tx_ring.start, skb->len); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2815 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2816 | skge->tx_ring.to_use = e->next; |
Stephen Hemminger | 992c962 | 2007-03-16 14:01:30 -0700 | [diff] [blame] | 2817 | smp_wmb(); |
| 2818 | |
Stephen Hemminger | 9db9647 | 2006-06-06 10:11:12 -0700 | [diff] [blame] | 2819 | if (skge_avail(&skge->tx_ring) <= TX_LOW_WATER) { |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 2820 | netdev_dbg(dev, "transmit queue full\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2821 | netif_stop_queue(dev); |
| 2822 | } |
| 2823 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2824 | return NETDEV_TX_OK; |
| 2825 | } |
| 2826 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2827 | |
| 2828 | /* Free resources associated with this reing element */ |
| 2829 | static void skge_tx_free(struct skge_port *skge, struct skge_element *e, |
| 2830 | u32 control) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2831 | { |
Stephen Hemminger | 866b4f3 | 2006-03-23 11:07:27 -0800 | [diff] [blame] | 2832 | struct pci_dev *pdev = skge->hw->pdev; |
Stephen Hemminger | 866b4f3 | 2006-03-23 11:07:27 -0800 | [diff] [blame] | 2833 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2834 | /* skb header vs. fragment */ |
| 2835 | if (control & BMU_STF) |
Stephen Hemminger | 866b4f3 | 2006-03-23 11:07:27 -0800 | [diff] [blame] | 2836 | pci_unmap_single(pdev, pci_unmap_addr(e, mapaddr), |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2837 | pci_unmap_len(e, maplen), |
| 2838 | PCI_DMA_TODEVICE); |
| 2839 | else |
| 2840 | pci_unmap_page(pdev, pci_unmap_addr(e, mapaddr), |
| 2841 | pci_unmap_len(e, maplen), |
| 2842 | PCI_DMA_TODEVICE); |
Stephen Hemminger | 866b4f3 | 2006-03-23 11:07:27 -0800 | [diff] [blame] | 2843 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2844 | if (control & BMU_EOF) { |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 2845 | netif_printk(skge, tx_done, KERN_DEBUG, skge->netdev, |
| 2846 | "tx done slot %td\n", e - skge->tx_ring.start); |
Stephen Hemminger | 866b4f3 | 2006-03-23 11:07:27 -0800 | [diff] [blame] | 2847 | |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 2848 | dev_kfree_skb(e->skb); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2849 | } |
| 2850 | } |
| 2851 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2852 | /* Free all buffers in transmit ring */ |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 2853 | static void skge_tx_clean(struct net_device *dev) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2854 | { |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 2855 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2856 | struct skge_element *e; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2857 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 2858 | for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) { |
| 2859 | struct skge_tx_desc *td = e->desc; |
| 2860 | skge_tx_free(skge, e, td->control); |
| 2861 | td->control = 0; |
| 2862 | } |
| 2863 | |
| 2864 | skge->tx_ring.to_clean = e; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | static void skge_tx_timeout(struct net_device *dev) |
| 2868 | { |
| 2869 | struct skge_port *skge = netdev_priv(dev); |
| 2870 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 2871 | netif_printk(skge, timer, KERN_DEBUG, skge->netdev, "tx timeout\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2872 | |
| 2873 | skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_STOP); |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 2874 | skge_tx_clean(dev); |
Michal Schmidt | d119b39 | 2009-04-14 15:16:55 -0700 | [diff] [blame] | 2875 | netif_wake_queue(dev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2876 | } |
| 2877 | |
| 2878 | static int skge_change_mtu(struct net_device *dev, int new_mtu) |
| 2879 | { |
Stephen Hemminger | 7731a4e | 2005-12-14 15:47:46 -0800 | [diff] [blame] | 2880 | int err; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2881 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 2882 | if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2883 | return -EINVAL; |
| 2884 | |
Stephen Hemminger | 7731a4e | 2005-12-14 15:47:46 -0800 | [diff] [blame] | 2885 | if (!netif_running(dev)) { |
| 2886 | dev->mtu = new_mtu; |
| 2887 | return 0; |
| 2888 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2889 | |
Stephen Hemminger | 1a8098b | 2007-11-28 14:25:05 -0800 | [diff] [blame] | 2890 | skge_down(dev); |
Stephen Hemminger | 7731a4e | 2005-12-14 15:47:46 -0800 | [diff] [blame] | 2891 | |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 2892 | dev->mtu = new_mtu; |
Stephen Hemminger | 7731a4e | 2005-12-14 15:47:46 -0800 | [diff] [blame] | 2893 | |
Stephen Hemminger | 1a8098b | 2007-11-28 14:25:05 -0800 | [diff] [blame] | 2894 | err = skge_up(dev); |
Stephen Hemminger | 7731a4e | 2005-12-14 15:47:46 -0800 | [diff] [blame] | 2895 | if (err) |
| 2896 | dev_close(dev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2897 | |
| 2898 | return err; |
| 2899 | } |
| 2900 | |
Stephen Hemminger | c4cd29d | 2007-02-23 14:03:00 -0800 | [diff] [blame] | 2901 | static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 }; |
| 2902 | |
| 2903 | static void genesis_add_filter(u8 filter[8], const u8 *addr) |
| 2904 | { |
| 2905 | u32 crc, bit; |
| 2906 | |
| 2907 | crc = ether_crc_le(ETH_ALEN, addr); |
| 2908 | bit = ~crc & 0x3f; |
| 2909 | filter[bit/8] |= 1 << (bit%8); |
| 2910 | } |
| 2911 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2912 | static void genesis_set_multicast(struct net_device *dev) |
| 2913 | { |
| 2914 | struct skge_port *skge = netdev_priv(dev); |
| 2915 | struct skge_hw *hw = skge->hw; |
| 2916 | int port = skge->port; |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 2917 | int i, count = netdev_mc_count(dev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2918 | struct dev_mc_list *list = dev->mc_list; |
| 2919 | u32 mode; |
| 2920 | u8 filter[8]; |
| 2921 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2922 | mode = xm_read32(hw, port, XM_MODE); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2923 | mode |= XM_MD_ENA_HASH; |
| 2924 | if (dev->flags & IFF_PROMISC) |
| 2925 | mode |= XM_MD_ENA_PROM; |
| 2926 | else |
| 2927 | mode &= ~XM_MD_ENA_PROM; |
| 2928 | |
| 2929 | if (dev->flags & IFF_ALLMULTI) |
| 2930 | memset(filter, 0xff, sizeof(filter)); |
| 2931 | else { |
| 2932 | memset(filter, 0, sizeof(filter)); |
Stephen Hemminger | c4cd29d | 2007-02-23 14:03:00 -0800 | [diff] [blame] | 2933 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 2934 | if (skge->flow_status == FLOW_STAT_REM_SEND || |
| 2935 | skge->flow_status == FLOW_STAT_SYMMETRIC) |
Stephen Hemminger | c4cd29d | 2007-02-23 14:03:00 -0800 | [diff] [blame] | 2936 | genesis_add_filter(filter, pause_mc_addr); |
| 2937 | |
| 2938 | for (i = 0; list && i < count; i++, list = list->next) |
| 2939 | genesis_add_filter(filter, list->dmi_addr); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2940 | } |
| 2941 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2942 | xm_write32(hw, port, XM_MODE, mode); |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 2943 | xm_outhash(hw, port, XM_HSM, filter); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2944 | } |
| 2945 | |
Stephen Hemminger | c4cd29d | 2007-02-23 14:03:00 -0800 | [diff] [blame] | 2946 | static void yukon_add_filter(u8 filter[8], const u8 *addr) |
| 2947 | { |
| 2948 | u32 bit = ether_crc(ETH_ALEN, addr) & 0x3f; |
| 2949 | filter[bit/8] |= 1 << (bit%8); |
| 2950 | } |
| 2951 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2952 | static void yukon_set_multicast(struct net_device *dev) |
| 2953 | { |
| 2954 | struct skge_port *skge = netdev_priv(dev); |
| 2955 | struct skge_hw *hw = skge->hw; |
| 2956 | int port = skge->port; |
| 2957 | struct dev_mc_list *list = dev->mc_list; |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 2958 | int rx_pause = (skge->flow_status == FLOW_STAT_REM_SEND || |
| 2959 | skge->flow_status == FLOW_STAT_SYMMETRIC); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2960 | u16 reg; |
| 2961 | u8 filter[8]; |
| 2962 | |
| 2963 | memset(filter, 0, sizeof(filter)); |
| 2964 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2965 | reg = gma_read16(hw, port, GM_RX_CTRL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2966 | reg |= GM_RXCR_UCF_ENA; |
| 2967 | |
Stephen Hemminger | 8f3f819 | 2005-11-08 10:33:45 -0800 | [diff] [blame] | 2968 | if (dev->flags & IFF_PROMISC) /* promiscuous */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2969 | reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); |
| 2970 | else if (dev->flags & IFF_ALLMULTI) /* all multicast */ |
| 2971 | memset(filter, 0xff, sizeof(filter)); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 2972 | else if (netdev_mc_empty(dev) && !rx_pause)/* no multicast */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2973 | reg &= ~GM_RXCR_MCF_ENA; |
| 2974 | else { |
| 2975 | int i; |
| 2976 | reg |= GM_RXCR_MCF_ENA; |
| 2977 | |
Stephen Hemminger | c4cd29d | 2007-02-23 14:03:00 -0800 | [diff] [blame] | 2978 | if (rx_pause) |
| 2979 | yukon_add_filter(filter, pause_mc_addr); |
| 2980 | |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 2981 | for (i = 0; list && i < netdev_mc_count(dev); i++, list = list->next) |
Stephen Hemminger | c4cd29d | 2007-02-23 14:03:00 -0800 | [diff] [blame] | 2982 | yukon_add_filter(filter, list->dmi_addr); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2986 | gma_write16(hw, port, GM_MC_ADDR_H1, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2987 | (u16)filter[0] | ((u16)filter[1] << 8)); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2988 | gma_write16(hw, port, GM_MC_ADDR_H2, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2989 | (u16)filter[2] | ((u16)filter[3] << 8)); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2990 | gma_write16(hw, port, GM_MC_ADDR_H3, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2991 | (u16)filter[4] | ((u16)filter[5] << 8)); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2992 | gma_write16(hw, port, GM_MC_ADDR_H4, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2993 | (u16)filter[6] | ((u16)filter[7] << 8)); |
| 2994 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2995 | gma_write16(hw, port, GM_RX_CTRL, reg); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2996 | } |
| 2997 | |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 2998 | static inline u16 phy_length(const struct skge_hw *hw, u32 status) |
| 2999 | { |
| 3000 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 3001 | return status >> XMR_FS_LEN_SHIFT; |
| 3002 | else |
| 3003 | return status >> GMR_FS_LEN_SHIFT; |
| 3004 | } |
| 3005 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3006 | static inline int bad_phy_status(const struct skge_hw *hw, u32 status) |
| 3007 | { |
| 3008 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 3009 | return (status & (XMR_FS_ERR | XMR_FS_2L_VLAN)) != 0; |
| 3010 | else |
| 3011 | return (status & GMR_FS_ANY_ERR) || |
| 3012 | (status & GMR_FS_RX_OK) == 0; |
| 3013 | } |
| 3014 | |
Stephen Hemminger | f80d032 | 2008-11-19 22:01:26 -0800 | [diff] [blame] | 3015 | static void skge_set_multicast(struct net_device *dev) |
| 3016 | { |
| 3017 | struct skge_port *skge = netdev_priv(dev); |
| 3018 | struct skge_hw *hw = skge->hw; |
| 3019 | |
| 3020 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 3021 | genesis_set_multicast(dev); |
| 3022 | else |
| 3023 | yukon_set_multicast(dev); |
| 3024 | |
| 3025 | } |
| 3026 | |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3027 | |
| 3028 | /* Get receive buffer from descriptor. |
| 3029 | * Handles copy of small buffers and reallocation failures |
| 3030 | */ |
Stephen Hemminger | c54f976 | 2006-09-01 15:53:47 -0700 | [diff] [blame] | 3031 | static struct sk_buff *skge_rx_get(struct net_device *dev, |
| 3032 | struct skge_element *e, |
| 3033 | u32 control, u32 status, u16 csum) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3034 | { |
Stephen Hemminger | c54f976 | 2006-09-01 15:53:47 -0700 | [diff] [blame] | 3035 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3036 | struct sk_buff *skb; |
| 3037 | u16 len = control & BMU_BBC; |
| 3038 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 3039 | netif_printk(skge, rx_status, KERN_DEBUG, skge->netdev, |
| 3040 | "rx slot %td status 0x%x len %d\n", |
| 3041 | e - skge->rx_ring.start, status, len); |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3042 | |
| 3043 | if (len > skge->rx_buf_size) |
| 3044 | goto error; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3045 | |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3046 | if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF)) |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3047 | goto error; |
| 3048 | |
| 3049 | if (bad_phy_status(skge->hw, status)) |
| 3050 | goto error; |
| 3051 | |
| 3052 | if (phy_length(skge->hw, status) != len) |
| 3053 | goto error; |
| 3054 | |
| 3055 | if (len < RX_COPY_THRESHOLD) { |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 3056 | skb = netdev_alloc_skb_ip_align(dev, len); |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3057 | if (!skb) |
| 3058 | goto resubmit; |
| 3059 | |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3060 | pci_dma_sync_single_for_cpu(skge->hw->pdev, |
| 3061 | pci_unmap_addr(e, mapaddr), |
| 3062 | len, PCI_DMA_FROMDEVICE); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 3063 | skb_copy_from_linear_data(e->skb, skb->data, len); |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3064 | pci_dma_sync_single_for_device(skge->hw->pdev, |
| 3065 | pci_unmap_addr(e, mapaddr), |
| 3066 | len, PCI_DMA_FROMDEVICE); |
| 3067 | skge_rx_reuse(e, skge->rx_buf_size); |
| 3068 | } else { |
| 3069 | struct sk_buff *nskb; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 3070 | |
| 3071 | nskb = netdev_alloc_skb_ip_align(dev, skge->rx_buf_size); |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3072 | if (!nskb) |
| 3073 | goto resubmit; |
| 3074 | |
| 3075 | pci_unmap_single(skge->hw->pdev, |
| 3076 | pci_unmap_addr(e, mapaddr), |
| 3077 | pci_unmap_len(e, maplen), |
| 3078 | PCI_DMA_FROMDEVICE); |
| 3079 | skb = e->skb; |
| 3080 | prefetch(skb->data); |
| 3081 | skge_rx_setup(skge, e, nskb, skge->rx_buf_size); |
| 3082 | } |
| 3083 | |
| 3084 | skb_put(skb, len); |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3085 | if (skge->rx_csum) { |
| 3086 | skb->csum = csum; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 3087 | skb->ip_summed = CHECKSUM_COMPLETE; |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3088 | } |
| 3089 | |
Stephen Hemminger | c54f976 | 2006-09-01 15:53:47 -0700 | [diff] [blame] | 3090 | skb->protocol = eth_type_trans(skb, dev); |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3091 | |
| 3092 | return skb; |
| 3093 | error: |
| 3094 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 3095 | netif_printk(skge, rx_err, KERN_DEBUG, skge->netdev, |
| 3096 | "rx err, slot %td control 0x%x status 0x%x\n", |
| 3097 | e - skge->rx_ring.start, control, status); |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3098 | |
| 3099 | if (skge->hw->chip_id == CHIP_ID_GENESIS) { |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3100 | if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR)) |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 3101 | dev->stats.rx_length_errors++; |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3102 | if (status & XMR_FS_FRA_ERR) |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 3103 | dev->stats.rx_frame_errors++; |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3104 | if (status & XMR_FS_FCS_ERR) |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 3105 | dev->stats.rx_crc_errors++; |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3106 | } else { |
| 3107 | if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE)) |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 3108 | dev->stats.rx_length_errors++; |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3109 | if (status & GMR_FS_FRAGMENT) |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 3110 | dev->stats.rx_frame_errors++; |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3111 | if (status & GMR_FS_CRC_ERR) |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 3112 | dev->stats.rx_crc_errors++; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3113 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3114 | |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3115 | resubmit: |
| 3116 | skge_rx_reuse(e, skge->rx_buf_size); |
| 3117 | return NULL; |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3118 | } |
| 3119 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3120 | /* Free all buffers in Tx ring which are no longer owned by device */ |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 3121 | static void skge_tx_done(struct net_device *dev) |
Stephen Hemminger | 00a6cae | 2006-03-21 10:56:59 -0800 | [diff] [blame] | 3122 | { |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3123 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | 00a6cae | 2006-03-21 10:56:59 -0800 | [diff] [blame] | 3124 | struct skge_ring *ring = &skge->tx_ring; |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3125 | struct skge_element *e; |
| 3126 | |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 3127 | skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F); |
Stephen Hemminger | 00a6cae | 2006-03-21 10:56:59 -0800 | [diff] [blame] | 3128 | |
Stephen Hemminger | 866b4f3 | 2006-03-23 11:07:27 -0800 | [diff] [blame] | 3129 | for (e = ring->to_clean; e != ring->to_use; e = e->next) { |
Stephen Hemminger | 992c962 | 2007-03-16 14:01:30 -0700 | [diff] [blame] | 3130 | u32 control = ((const struct skge_tx_desc *) e->desc)->control; |
Stephen Hemminger | 00a6cae | 2006-03-21 10:56:59 -0800 | [diff] [blame] | 3131 | |
Stephen Hemminger | 992c962 | 2007-03-16 14:01:30 -0700 | [diff] [blame] | 3132 | if (control & BMU_OWN) |
Stephen Hemminger | 00a6cae | 2006-03-21 10:56:59 -0800 | [diff] [blame] | 3133 | break; |
| 3134 | |
Stephen Hemminger | 992c962 | 2007-03-16 14:01:30 -0700 | [diff] [blame] | 3135 | skge_tx_free(skge, e, control); |
Stephen Hemminger | 00a6cae | 2006-03-21 10:56:59 -0800 | [diff] [blame] | 3136 | } |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3137 | skge->tx_ring.to_clean = e; |
Stephen Hemminger | 866b4f3 | 2006-03-23 11:07:27 -0800 | [diff] [blame] | 3138 | |
Stephen Hemminger | 992c962 | 2007-03-16 14:01:30 -0700 | [diff] [blame] | 3139 | /* Can run lockless until we need to synchronize to restart queue. */ |
| 3140 | smp_mb(); |
Stephen Hemminger | 00a6cae | 2006-03-21 10:56:59 -0800 | [diff] [blame] | 3141 | |
Stephen Hemminger | 992c962 | 2007-03-16 14:01:30 -0700 | [diff] [blame] | 3142 | if (unlikely(netif_queue_stopped(dev) && |
| 3143 | skge_avail(&skge->tx_ring) > TX_LOW_WATER)) { |
| 3144 | netif_tx_lock(dev); |
| 3145 | if (unlikely(netif_queue_stopped(dev) && |
| 3146 | skge_avail(&skge->tx_ring) > TX_LOW_WATER)) { |
| 3147 | netif_wake_queue(dev); |
| 3148 | |
| 3149 | } |
| 3150 | netif_tx_unlock(dev); |
| 3151 | } |
Stephen Hemminger | 00a6cae | 2006-03-21 10:56:59 -0800 | [diff] [blame] | 3152 | } |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3153 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3154 | static int skge_poll(struct napi_struct *napi, int to_do) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3155 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3156 | struct skge_port *skge = container_of(napi, struct skge_port, napi); |
| 3157 | struct net_device *dev = skge->netdev; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3158 | struct skge_hw *hw = skge->hw; |
| 3159 | struct skge_ring *ring = &skge->rx_ring; |
| 3160 | struct skge_element *e; |
Stephen Hemminger | 00a6cae | 2006-03-21 10:56:59 -0800 | [diff] [blame] | 3161 | int work_done = 0; |
| 3162 | |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 3163 | skge_tx_done(dev); |
| 3164 | |
| 3165 | skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F); |
| 3166 | |
Stephen Hemminger | 1631aef | 2005-11-08 10:33:44 -0800 | [diff] [blame] | 3167 | for (e = ring->to_clean; prefetch(e->next), work_done < to_do; e = e->next) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3168 | struct skge_rx_desc *rd = e->desc; |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3169 | struct sk_buff *skb; |
Stephen Hemminger | 383181a | 2005-09-19 15:37:16 -0700 | [diff] [blame] | 3170 | u32 control; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3171 | |
| 3172 | rmb(); |
| 3173 | control = rd->control; |
| 3174 | if (control & BMU_OWN) |
| 3175 | break; |
| 3176 | |
Stephen Hemminger | c54f976 | 2006-09-01 15:53:47 -0700 | [diff] [blame] | 3177 | skb = skge_rx_get(dev, e, control, rd->status, rd->csum2); |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3178 | if (likely(skb)) { |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3179 | netif_receive_skb(skb); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3180 | |
Stephen Hemminger | 19a33d4 | 2005-06-27 11:33:15 -0700 | [diff] [blame] | 3181 | ++work_done; |
Stephen Hemminger | 5a01144 | 2006-03-23 11:07:25 -0800 | [diff] [blame] | 3182 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3183 | } |
| 3184 | ring->to_clean = e; |
| 3185 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3186 | /* restart receiver */ |
| 3187 | wmb(); |
Stephen Hemminger | a9cdab8 | 2006-02-22 10:28:33 -0800 | [diff] [blame] | 3188 | skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), CSR_START); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3189 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3190 | if (work_done < to_do) { |
Marin Mitov | 6ef2977 | 2008-03-23 10:20:09 +0200 | [diff] [blame] | 3191 | unsigned long flags; |
Jeff Garzik | f0c88f9 | 2008-03-25 23:53:24 -0400 | [diff] [blame] | 3192 | |
Marin Mitov | 6ef2977 | 2008-03-23 10:20:09 +0200 | [diff] [blame] | 3193 | spin_lock_irqsave(&hw->hw_lock, flags); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3194 | __napi_complete(napi); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3195 | hw->intr_mask |= napimask[skge->port]; |
| 3196 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
| 3197 | skge_read32(hw, B0_IMSK); |
Marin Mitov | 6ef2977 | 2008-03-23 10:20:09 +0200 | [diff] [blame] | 3198 | spin_unlock_irqrestore(&hw->hw_lock, flags); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3199 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3200 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3201 | return work_done; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3202 | } |
| 3203 | |
Stephen Hemminger | f6620ca | 2005-07-22 16:26:02 -0700 | [diff] [blame] | 3204 | /* Parity errors seem to happen when Genesis is connected to a switch |
| 3205 | * with no other ports present. Heartbeat error?? |
| 3206 | */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3207 | static void skge_mac_parity(struct skge_hw *hw, int port) |
| 3208 | { |
Stephen Hemminger | f6620ca | 2005-07-22 16:26:02 -0700 | [diff] [blame] | 3209 | struct net_device *dev = hw->dev[port]; |
| 3210 | |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 3211 | ++dev->stats.tx_heartbeat_errors; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3212 | |
| 3213 | if (hw->chip_id == CHIP_ID_GENESIS) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 3214 | skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3215 | MFF_CLR_PERR); |
| 3216 | else |
| 3217 | /* HW-Bug #8: cleared by GMF_CLI_TX_FC instead of GMF_CLI_TX_PE */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 3218 | skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 3219 | (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3220 | ? GMF_CLI_TX_FC : GMF_CLI_TX_PE); |
| 3221 | } |
| 3222 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3223 | static void skge_mac_intr(struct skge_hw *hw, int port) |
| 3224 | { |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 3225 | if (hw->chip_id == CHIP_ID_GENESIS) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3226 | genesis_mac_intr(hw, port); |
| 3227 | else |
| 3228 | yukon_mac_intr(hw, port); |
| 3229 | } |
| 3230 | |
| 3231 | /* Handle device specific framing and timeout interrupts */ |
| 3232 | static void skge_error_irq(struct skge_hw *hw) |
| 3233 | { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3234 | struct pci_dev *pdev = hw->pdev; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3235 | u32 hwstatus = skge_read32(hw, B0_HWE_ISRC); |
| 3236 | |
| 3237 | if (hw->chip_id == CHIP_ID_GENESIS) { |
| 3238 | /* clear xmac errors */ |
| 3239 | if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1)) |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 3240 | skge_write16(hw, RX_MFF_CTRL1, MFF_CLR_INSTAT); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3241 | if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2)) |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 3242 | skge_write16(hw, RX_MFF_CTRL2, MFF_CLR_INSTAT); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3243 | } else { |
| 3244 | /* Timestamp (unused) overflow */ |
| 3245 | if (hwstatus & IS_IRQ_TIST_OV) |
| 3246 | skge_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | if (hwstatus & IS_RAM_RD_PAR) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3250 | dev_err(&pdev->dev, "Ram read data parity error\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3251 | skge_write16(hw, B3_RI_CTRL, RI_CLR_RD_PERR); |
| 3252 | } |
| 3253 | |
| 3254 | if (hwstatus & IS_RAM_WR_PAR) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3255 | dev_err(&pdev->dev, "Ram write data parity error\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3256 | skge_write16(hw, B3_RI_CTRL, RI_CLR_WR_PERR); |
| 3257 | } |
| 3258 | |
| 3259 | if (hwstatus & IS_M1_PAR_ERR) |
| 3260 | skge_mac_parity(hw, 0); |
| 3261 | |
| 3262 | if (hwstatus & IS_M2_PAR_ERR) |
| 3263 | skge_mac_parity(hw, 1); |
| 3264 | |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3265 | if (hwstatus & IS_R1_PAR_ERR) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3266 | dev_err(&pdev->dev, "%s: receive queue parity error\n", |
| 3267 | hw->dev[0]->name); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3268 | skge_write32(hw, B0_R1_CSR, CSR_IRQ_CL_P); |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3269 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3270 | |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3271 | if (hwstatus & IS_R2_PAR_ERR) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3272 | dev_err(&pdev->dev, "%s: receive queue parity error\n", |
| 3273 | hw->dev[1]->name); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3274 | skge_write32(hw, B0_R2_CSR, CSR_IRQ_CL_P); |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3275 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3276 | |
| 3277 | if (hwstatus & (IS_IRQ_MST_ERR|IS_IRQ_STAT)) { |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3278 | u16 pci_status, pci_cmd; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3279 | |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3280 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 3281 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3282 | |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3283 | dev_err(&pdev->dev, "PCI error cmd=%#x status=%#x\n", |
| 3284 | pci_cmd, pci_status); |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3285 | |
| 3286 | /* Write the error bits back to clear them. */ |
| 3287 | pci_status &= PCI_STATUS_ERROR_BITS; |
| 3288 | skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3289 | pci_write_config_word(pdev, PCI_COMMAND, |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3290 | pci_cmd | PCI_COMMAND_SERR | PCI_COMMAND_PARITY); |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3291 | pci_write_config_word(pdev, PCI_STATUS, pci_status); |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3292 | skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3293 | |
Stephen Hemminger | 050ec18 | 2005-08-16 14:00:54 -0700 | [diff] [blame] | 3294 | /* if error still set then just ignore it */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3295 | hwstatus = skge_read32(hw, B0_HWE_ISRC); |
| 3296 | if (hwstatus & IS_IRQ_STAT) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3297 | dev_warn(&hw->pdev->dev, "unable to clear error (so ignoring them)\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3298 | hw->intr_mask &= ~IS_HW_ERR; |
| 3299 | } |
| 3300 | } |
| 3301 | } |
| 3302 | |
| 3303 | /* |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3304 | * Interrupt from PHY are handled in tasklet (softirq) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3305 | * because accessing phy registers requires spin wait which might |
| 3306 | * cause excess interrupt latency. |
| 3307 | */ |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3308 | static void skge_extirq(unsigned long arg) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3309 | { |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3310 | struct skge_hw *hw = (struct skge_hw *) arg; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3311 | int port; |
| 3312 | |
Stephen Hemminger | cfc3ed7 | 2006-03-21 10:57:00 -0800 | [diff] [blame] | 3313 | for (port = 0; port < hw->ports; port++) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3314 | struct net_device *dev = hw->dev[port]; |
| 3315 | |
Stephen Hemminger | cfc3ed7 | 2006-03-21 10:57:00 -0800 | [diff] [blame] | 3316 | if (netif_running(dev)) { |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3317 | struct skge_port *skge = netdev_priv(dev); |
| 3318 | |
| 3319 | spin_lock(&hw->phy_lock); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3320 | if (hw->chip_id != CHIP_ID_GENESIS) |
| 3321 | yukon_phy_intr(skge); |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 3322 | else if (hw->phy_type == SK_PHY_BCOM) |
Stephen Hemminger | 45bada6 | 2005-06-27 11:33:12 -0700 | [diff] [blame] | 3323 | bcom_phy_intr(skge); |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3324 | spin_unlock(&hw->phy_lock); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3325 | } |
| 3326 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3327 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3328 | spin_lock_irq(&hw->hw_lock); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3329 | hw->intr_mask |= IS_EXT_REG; |
| 3330 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
Stephen Hemminger | 78bc218 | 2006-08-28 16:19:36 -0700 | [diff] [blame] | 3331 | skge_read32(hw, B0_IMSK); |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3332 | spin_unlock_irq(&hw->hw_lock); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3333 | } |
| 3334 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3335 | static irqreturn_t skge_intr(int irq, void *dev_id) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3336 | { |
| 3337 | struct skge_hw *hw = dev_id; |
Stephen Hemminger | cfc3ed7 | 2006-03-21 10:57:00 -0800 | [diff] [blame] | 3338 | u32 status; |
Stephen Hemminger | 29365c9 | 2006-09-01 15:53:48 -0700 | [diff] [blame] | 3339 | int handled = 0; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3340 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3341 | spin_lock(&hw->hw_lock); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3342 | /* Reading this register masks IRQ */ |
| 3343 | status = skge_read32(hw, B0_SP_ISRC); |
Stephen Hemminger | 0486a8c | 2006-09-06 11:06:10 -0700 | [diff] [blame] | 3344 | if (status == 0 || status == ~0) |
Stephen Hemminger | 29365c9 | 2006-09-01 15:53:48 -0700 | [diff] [blame] | 3345 | goto out; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3346 | |
Stephen Hemminger | 29365c9 | 2006-09-01 15:53:48 -0700 | [diff] [blame] | 3347 | handled = 1; |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3348 | status &= hw->intr_mask; |
Stephen Hemminger | cfc3ed7 | 2006-03-21 10:57:00 -0800 | [diff] [blame] | 3349 | if (status & IS_EXT_REG) { |
| 3350 | hw->intr_mask &= ~IS_EXT_REG; |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3351 | tasklet_schedule(&hw->phy_task); |
Stephen Hemminger | cfc3ed7 | 2006-03-21 10:57:00 -0800 | [diff] [blame] | 3352 | } |
| 3353 | |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 3354 | if (status & (IS_XA1_F|IS_R1_F)) { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3355 | struct skge_port *skge = netdev_priv(hw->dev[0]); |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 3356 | hw->intr_mask &= ~(IS_XA1_F|IS_R1_F); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3357 | napi_schedule(&skge->napi); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3358 | } |
| 3359 | |
Stephen Hemminger | d25f5a6 | 2005-06-27 11:33:14 -0700 | [diff] [blame] | 3360 | if (status & IS_PA_TO_TX1) |
| 3361 | skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX1); |
| 3362 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3363 | if (status & IS_PA_TO_RX1) { |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 3364 | ++hw->dev[0]->stats.rx_over_errors; |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3365 | skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX1); |
| 3366 | } |
| 3367 | |
Stephen Hemminger | d25f5a6 | 2005-06-27 11:33:14 -0700 | [diff] [blame] | 3368 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3369 | if (status & IS_MAC1) |
| 3370 | skge_mac_intr(hw, 0); |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 3371 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3372 | if (hw->dev[1]) { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3373 | struct skge_port *skge = netdev_priv(hw->dev[1]); |
| 3374 | |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 3375 | if (status & (IS_XA2_F|IS_R2_F)) { |
| 3376 | hw->intr_mask &= ~(IS_XA2_F|IS_R2_F); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3377 | napi_schedule(&skge->napi); |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | if (status & IS_PA_TO_RX2) { |
Stephen Hemminger | da00772 | 2007-10-16 12:15:52 -0700 | [diff] [blame] | 3381 | ++hw->dev[1]->stats.rx_over_errors; |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3382 | skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX2); |
| 3383 | } |
| 3384 | |
| 3385 | if (status & IS_PA_TO_TX2) |
| 3386 | skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX2); |
| 3387 | |
| 3388 | if (status & IS_MAC2) |
| 3389 | skge_mac_intr(hw, 1); |
| 3390 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3391 | |
| 3392 | if (status & IS_HW_ERR) |
| 3393 | skge_error_irq(hw); |
| 3394 | |
Stephen Hemminger | 7e676d9 | 2005-06-27 11:33:13 -0700 | [diff] [blame] | 3395 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
Stephen Hemminger | 78bc218 | 2006-08-28 16:19:36 -0700 | [diff] [blame] | 3396 | skge_read32(hw, B0_IMSK); |
Stephen Hemminger | 29365c9 | 2006-09-01 15:53:48 -0700 | [diff] [blame] | 3397 | out: |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 3398 | spin_unlock(&hw->hw_lock); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3399 | |
Stephen Hemminger | 29365c9 | 2006-09-01 15:53:48 -0700 | [diff] [blame] | 3400 | return IRQ_RETVAL(handled); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3404 | static void skge_netpoll(struct net_device *dev) |
| 3405 | { |
| 3406 | struct skge_port *skge = netdev_priv(dev); |
| 3407 | |
| 3408 | disable_irq(dev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3409 | skge_intr(dev->irq, skge->hw); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3410 | enable_irq(dev->irq); |
| 3411 | } |
| 3412 | #endif |
| 3413 | |
| 3414 | static int skge_set_mac_address(struct net_device *dev, void *p) |
| 3415 | { |
| 3416 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | c2681dd | 2005-10-03 12:03:13 -0700 | [diff] [blame] | 3417 | struct skge_hw *hw = skge->hw; |
| 3418 | unsigned port = skge->port; |
| 3419 | const struct sockaddr *addr = p; |
Stephen Hemminger | 2eb3e62 | 2007-03-12 15:16:26 -0700 | [diff] [blame] | 3420 | u16 ctrl; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3421 | |
| 3422 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3423 | return -EADDRNOTAVAIL; |
| 3424 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3425 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); |
Stephen Hemminger | c2681dd | 2005-10-03 12:03:13 -0700 | [diff] [blame] | 3426 | |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3427 | if (!netif_running(dev)) { |
| 3428 | memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN); |
| 3429 | memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN); |
| 3430 | } else { |
| 3431 | /* disable Rx */ |
| 3432 | spin_lock_bh(&hw->phy_lock); |
| 3433 | ctrl = gma_read16(hw, port, GM_GP_CTRL); |
| 3434 | gma_write16(hw, port, GM_GP_CTRL, ctrl & ~GM_GPCR_RX_ENA); |
Stephen Hemminger | 2eb3e62 | 2007-03-12 15:16:26 -0700 | [diff] [blame] | 3435 | |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3436 | memcpy_toio(hw->regs + B2_MAC_1 + port*8, dev->dev_addr, ETH_ALEN); |
| 3437 | memcpy_toio(hw->regs + B2_MAC_2 + port*8, dev->dev_addr, ETH_ALEN); |
Stephen Hemminger | 2eb3e62 | 2007-03-12 15:16:26 -0700 | [diff] [blame] | 3438 | |
Stephen Hemminger | 2eb3e62 | 2007-03-12 15:16:26 -0700 | [diff] [blame] | 3439 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 3440 | xm_outaddr(hw, port, XM_SA, dev->dev_addr); |
| 3441 | else { |
| 3442 | gma_set_addr(hw, port, GM_SRC_ADDR_1L, dev->dev_addr); |
| 3443 | gma_set_addr(hw, port, GM_SRC_ADDR_2L, dev->dev_addr); |
| 3444 | } |
Stephen Hemminger | 2eb3e62 | 2007-03-12 15:16:26 -0700 | [diff] [blame] | 3445 | |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3446 | gma_write16(hw, port, GM_GP_CTRL, ctrl); |
| 3447 | spin_unlock_bh(&hw->phy_lock); |
| 3448 | } |
Stephen Hemminger | c2681dd | 2005-10-03 12:03:13 -0700 | [diff] [blame] | 3449 | |
| 3450 | return 0; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3451 | } |
| 3452 | |
| 3453 | static const struct { |
| 3454 | u8 id; |
| 3455 | const char *name; |
| 3456 | } skge_chips[] = { |
| 3457 | { CHIP_ID_GENESIS, "Genesis" }, |
| 3458 | { CHIP_ID_YUKON, "Yukon" }, |
| 3459 | { CHIP_ID_YUKON_LITE, "Yukon-Lite"}, |
| 3460 | { CHIP_ID_YUKON_LP, "Yukon-LP"}, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3461 | }; |
| 3462 | |
| 3463 | static const char *skge_board_name(const struct skge_hw *hw) |
| 3464 | { |
| 3465 | int i; |
| 3466 | static char buf[16]; |
| 3467 | |
| 3468 | for (i = 0; i < ARRAY_SIZE(skge_chips); i++) |
| 3469 | if (skge_chips[i].id == hw->chip_id) |
| 3470 | return skge_chips[i].name; |
| 3471 | |
| 3472 | snprintf(buf, sizeof buf, "chipid 0x%x", hw->chip_id); |
| 3473 | return buf; |
| 3474 | } |
| 3475 | |
| 3476 | |
| 3477 | /* |
| 3478 | * Setup the board data structure, but don't bring up |
| 3479 | * the port(s) |
| 3480 | */ |
| 3481 | static int skge_reset(struct skge_hw *hw) |
| 3482 | { |
Stephen Hemminger | adba9e2 | 2005-11-08 10:33:40 -0800 | [diff] [blame] | 3483 | u32 reg; |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3484 | u16 ctst, pci_status; |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 3485 | u8 t8, mac_cfg, pmd_type; |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 3486 | int i; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3487 | |
| 3488 | ctst = skge_read16(hw, B0_CTST); |
| 3489 | |
| 3490 | /* do a SW reset */ |
| 3491 | skge_write8(hw, B0_CTST, CS_RST_SET); |
| 3492 | skge_write8(hw, B0_CTST, CS_RST_CLR); |
| 3493 | |
| 3494 | /* clear PCI errors, if any */ |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3495 | skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
| 3496 | skge_write8(hw, B2_TST_CTRL2, 0); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3497 | |
Stephen Hemminger | b9d64ac | 2006-03-21 10:57:06 -0800 | [diff] [blame] | 3498 | pci_read_config_word(hw->pdev, PCI_STATUS, &pci_status); |
| 3499 | pci_write_config_word(hw->pdev, PCI_STATUS, |
| 3500 | pci_status | PCI_STATUS_ERROR_BITS); |
| 3501 | skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3502 | skge_write8(hw, B0_CTST, CS_MRST_CLR); |
| 3503 | |
| 3504 | /* restore CLK_RUN bits (for Yukon-Lite) */ |
| 3505 | skge_write16(hw, B0_CTST, |
| 3506 | ctst & (CS_CLK_RUN_HOT|CS_CLK_RUN_RST|CS_CLK_RUN_ENA)); |
| 3507 | |
| 3508 | hw->chip_id = skge_read8(hw, B2_CHIP_ID); |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 3509 | hw->phy_type = skge_read8(hw, B2_E_1) & 0xf; |
Stephen Hemminger | 5e1705d | 2005-08-16 14:00:58 -0700 | [diff] [blame] | 3510 | pmd_type = skge_read8(hw, B2_PMD_TYP); |
| 3511 | hw->copper = (pmd_type == 'T' || pmd_type == '1'); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3512 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 3513 | switch (hw->chip_id) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3514 | case CHIP_ID_GENESIS: |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 3515 | switch (hw->phy_type) { |
| 3516 | case SK_PHY_XMAC: |
| 3517 | hw->phy_addr = PHY_ADDR_XMAC; |
| 3518 | break; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3519 | case SK_PHY_BCOM: |
| 3520 | hw->phy_addr = PHY_ADDR_BCOM; |
| 3521 | break; |
| 3522 | default: |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3523 | dev_err(&hw->pdev->dev, "unsupported phy type 0x%x\n", |
| 3524 | hw->phy_type); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3525 | return -EOPNOTSUPP; |
| 3526 | } |
| 3527 | break; |
| 3528 | |
| 3529 | case CHIP_ID_YUKON: |
| 3530 | case CHIP_ID_YUKON_LITE: |
| 3531 | case CHIP_ID_YUKON_LP: |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 3532 | if (hw->phy_type < SK_PHY_MARV_COPPER && pmd_type != 'S') |
Stephen Hemminger | 5e1705d | 2005-08-16 14:00:58 -0700 | [diff] [blame] | 3533 | hw->copper = 1; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3534 | |
| 3535 | hw->phy_addr = PHY_ADDR_MARV; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3536 | break; |
| 3537 | |
| 3538 | default: |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3539 | dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n", |
| 3540 | hw->chip_id); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3541 | return -EOPNOTSUPP; |
| 3542 | } |
| 3543 | |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 3544 | mac_cfg = skge_read8(hw, B2_MAC_CFG); |
| 3545 | hw->ports = (mac_cfg & CFG_SNG_MAC) ? 1 : 2; |
| 3546 | hw->chip_rev = (mac_cfg & CFG_CHIP_R_MSK) >> 4; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3547 | |
| 3548 | /* read the adapters RAM size */ |
| 3549 | t8 = skge_read8(hw, B2_E_0); |
| 3550 | if (hw->chip_id == CHIP_ID_GENESIS) { |
| 3551 | if (t8 == 3) { |
| 3552 | /* special case: 4 x 64k x 36, offset = 0x80000 */ |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 3553 | hw->ram_size = 0x100000; |
| 3554 | hw->ram_offset = 0x80000; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3555 | } else |
| 3556 | hw->ram_size = t8 * 512; |
Linus Torvalds | 279e1da | 2007-11-15 08:44:36 -0800 | [diff] [blame] | 3557 | } |
| 3558 | else if (t8 == 0) |
| 3559 | hw->ram_size = 0x20000; |
| 3560 | else |
| 3561 | hw->ram_size = t8 * 4096; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3562 | |
Stephen Hemminger | 4ebabfc | 2007-03-16 14:01:27 -0700 | [diff] [blame] | 3563 | hw->intr_mask = IS_HW_ERR; |
Stephen Hemminger | cfc3ed7 | 2006-03-21 10:57:00 -0800 | [diff] [blame] | 3564 | |
Stephen Hemminger | 4ebabfc | 2007-03-16 14:01:27 -0700 | [diff] [blame] | 3565 | /* Use PHY IRQ for all but fiber based Genesis board */ |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 3566 | if (!(hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC)) |
| 3567 | hw->intr_mask |= IS_EXT_REG; |
| 3568 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3569 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 3570 | genesis_init(hw); |
| 3571 | else { |
| 3572 | /* switch power to VCC (WA for VAUX problem) */ |
| 3573 | skge_write8(hw, B0_POWER_CTRL, |
| 3574 | PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON); |
Stephen Hemminger | adba9e2 | 2005-11-08 10:33:40 -0800 | [diff] [blame] | 3575 | |
Stephen Hemminger | 050ec18 | 2005-08-16 14:00:54 -0700 | [diff] [blame] | 3576 | /* avoid boards with stuck Hardware error bits */ |
| 3577 | if ((skge_read32(hw, B0_ISRC) & IS_HW_ERR) && |
| 3578 | (skge_read32(hw, B0_HWE_ISRC) & IS_IRQ_SENSOR)) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3579 | dev_warn(&hw->pdev->dev, "stuck hardware sensor bit\n"); |
Stephen Hemminger | 050ec18 | 2005-08-16 14:00:54 -0700 | [diff] [blame] | 3580 | hw->intr_mask &= ~IS_HW_ERR; |
| 3581 | } |
| 3582 | |
Stephen Hemminger | adba9e2 | 2005-11-08 10:33:40 -0800 | [diff] [blame] | 3583 | /* Clear PHY COMA */ |
| 3584 | skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
| 3585 | pci_read_config_dword(hw->pdev, PCI_DEV_REG1, ®); |
| 3586 | reg &= ~PCI_PHY_COMA; |
| 3587 | pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg); |
| 3588 | skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
| 3589 | |
| 3590 | |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 3591 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 3592 | skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET); |
| 3593 | skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3594 | } |
| 3595 | } |
| 3596 | |
| 3597 | /* turn off hardware timer (unused) */ |
| 3598 | skge_write8(hw, B2_TI_CTRL, TIM_STOP); |
| 3599 | skge_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ); |
| 3600 | skge_write8(hw, B0_LED, LED_STAT_ON); |
| 3601 | |
| 3602 | /* enable the Tx Arbiters */ |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 3603 | for (i = 0; i < hw->ports; i++) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 3604 | skge_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3605 | |
| 3606 | /* Initialize ram interface */ |
| 3607 | skge_write16(hw, B3_RI_CTRL, RI_RST_CLR); |
| 3608 | |
| 3609 | skge_write8(hw, B3_RI_WTO_R1, SK_RI_TO_53); |
| 3610 | skge_write8(hw, B3_RI_WTO_XA1, SK_RI_TO_53); |
| 3611 | skge_write8(hw, B3_RI_WTO_XS1, SK_RI_TO_53); |
| 3612 | skge_write8(hw, B3_RI_RTO_R1, SK_RI_TO_53); |
| 3613 | skge_write8(hw, B3_RI_RTO_XA1, SK_RI_TO_53); |
| 3614 | skge_write8(hw, B3_RI_RTO_XS1, SK_RI_TO_53); |
| 3615 | skge_write8(hw, B3_RI_WTO_R2, SK_RI_TO_53); |
| 3616 | skge_write8(hw, B3_RI_WTO_XA2, SK_RI_TO_53); |
| 3617 | skge_write8(hw, B3_RI_WTO_XS2, SK_RI_TO_53); |
| 3618 | skge_write8(hw, B3_RI_RTO_R2, SK_RI_TO_53); |
| 3619 | skge_write8(hw, B3_RI_RTO_XA2, SK_RI_TO_53); |
| 3620 | skge_write8(hw, B3_RI_RTO_XS2, SK_RI_TO_53); |
| 3621 | |
| 3622 | skge_write32(hw, B0_HWE_IMSK, IS_ERR_MSK); |
| 3623 | |
| 3624 | /* Set interrupt moderation for Transmit only |
| 3625 | * Receive interrupts avoided by NAPI |
| 3626 | */ |
| 3627 | skge_write32(hw, B2_IRQM_MSK, IS_XA1_F|IS_XA2_F); |
| 3628 | skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100)); |
| 3629 | skge_write32(hw, B2_IRQM_CTRL, TIM_START); |
| 3630 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3631 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
| 3632 | |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 3633 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3634 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 3635 | genesis_reset(hw, i); |
| 3636 | else |
| 3637 | yukon_reset(hw, i); |
| 3638 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3639 | |
| 3640 | return 0; |
| 3641 | } |
| 3642 | |
Stephen Hemminger | 678aa1f | 2007-10-16 12:15:54 -0700 | [diff] [blame] | 3643 | |
| 3644 | #ifdef CONFIG_SKGE_DEBUG |
| 3645 | |
| 3646 | static struct dentry *skge_debug; |
| 3647 | |
| 3648 | static int skge_debug_show(struct seq_file *seq, void *v) |
| 3649 | { |
| 3650 | struct net_device *dev = seq->private; |
| 3651 | const struct skge_port *skge = netdev_priv(dev); |
| 3652 | const struct skge_hw *hw = skge->hw; |
| 3653 | const struct skge_element *e; |
| 3654 | |
| 3655 | if (!netif_running(dev)) |
| 3656 | return -ENETDOWN; |
| 3657 | |
| 3658 | seq_printf(seq, "IRQ src=%x mask=%x\n", skge_read32(hw, B0_ISRC), |
| 3659 | skge_read32(hw, B0_IMSK)); |
| 3660 | |
| 3661 | seq_printf(seq, "Tx Ring: (%d)\n", skge_avail(&skge->tx_ring)); |
| 3662 | for (e = skge->tx_ring.to_clean; e != skge->tx_ring.to_use; e = e->next) { |
| 3663 | const struct skge_tx_desc *t = e->desc; |
| 3664 | seq_printf(seq, "%#x dma=%#x%08x %#x csum=%#x/%x/%x\n", |
| 3665 | t->control, t->dma_hi, t->dma_lo, t->status, |
| 3666 | t->csum_offs, t->csum_write, t->csum_start); |
| 3667 | } |
| 3668 | |
| 3669 | seq_printf(seq, "\nRx Ring: \n"); |
| 3670 | for (e = skge->rx_ring.to_clean; ; e = e->next) { |
| 3671 | const struct skge_rx_desc *r = e->desc; |
| 3672 | |
| 3673 | if (r->control & BMU_OWN) |
| 3674 | break; |
| 3675 | |
| 3676 | seq_printf(seq, "%#x dma=%#x%08x %#x %#x csum=%#x/%x\n", |
| 3677 | r->control, r->dma_hi, r->dma_lo, r->status, |
| 3678 | r->timestamp, r->csum1, r->csum1_start); |
| 3679 | } |
| 3680 | |
| 3681 | return 0; |
| 3682 | } |
| 3683 | |
| 3684 | static int skge_debug_open(struct inode *inode, struct file *file) |
| 3685 | { |
| 3686 | return single_open(file, skge_debug_show, inode->i_private); |
| 3687 | } |
| 3688 | |
| 3689 | static const struct file_operations skge_debug_fops = { |
| 3690 | .owner = THIS_MODULE, |
| 3691 | .open = skge_debug_open, |
| 3692 | .read = seq_read, |
| 3693 | .llseek = seq_lseek, |
| 3694 | .release = single_release, |
| 3695 | }; |
| 3696 | |
| 3697 | /* |
| 3698 | * Use network device events to create/remove/rename |
| 3699 | * debugfs file entries |
| 3700 | */ |
| 3701 | static int skge_device_event(struct notifier_block *unused, |
| 3702 | unsigned long event, void *ptr) |
| 3703 | { |
| 3704 | struct net_device *dev = ptr; |
| 3705 | struct skge_port *skge; |
| 3706 | struct dentry *d; |
| 3707 | |
Stephen Hemminger | f80d032 | 2008-11-19 22:01:26 -0800 | [diff] [blame] | 3708 | if (dev->netdev_ops->ndo_open != &skge_up || !skge_debug) |
Stephen Hemminger | 678aa1f | 2007-10-16 12:15:54 -0700 | [diff] [blame] | 3709 | goto done; |
| 3710 | |
| 3711 | skge = netdev_priv(dev); |
| 3712 | switch(event) { |
| 3713 | case NETDEV_CHANGENAME: |
| 3714 | if (skge->debugfs) { |
| 3715 | d = debugfs_rename(skge_debug, skge->debugfs, |
| 3716 | skge_debug, dev->name); |
| 3717 | if (d) |
| 3718 | skge->debugfs = d; |
| 3719 | else { |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 3720 | netdev_info(dev, "rename failed\n"); |
Stephen Hemminger | 678aa1f | 2007-10-16 12:15:54 -0700 | [diff] [blame] | 3721 | debugfs_remove(skge->debugfs); |
| 3722 | } |
| 3723 | } |
| 3724 | break; |
| 3725 | |
| 3726 | case NETDEV_GOING_DOWN: |
| 3727 | if (skge->debugfs) { |
| 3728 | debugfs_remove(skge->debugfs); |
| 3729 | skge->debugfs = NULL; |
| 3730 | } |
| 3731 | break; |
| 3732 | |
| 3733 | case NETDEV_UP: |
| 3734 | d = debugfs_create_file(dev->name, S_IRUGO, |
| 3735 | skge_debug, dev, |
| 3736 | &skge_debug_fops); |
| 3737 | if (!d || IS_ERR(d)) |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 3738 | netdev_info(dev, "debugfs create failed\n"); |
Stephen Hemminger | 678aa1f | 2007-10-16 12:15:54 -0700 | [diff] [blame] | 3739 | else |
| 3740 | skge->debugfs = d; |
| 3741 | break; |
| 3742 | } |
| 3743 | |
| 3744 | done: |
| 3745 | return NOTIFY_DONE; |
| 3746 | } |
| 3747 | |
| 3748 | static struct notifier_block skge_notifier = { |
| 3749 | .notifier_call = skge_device_event, |
| 3750 | }; |
| 3751 | |
| 3752 | |
| 3753 | static __init void skge_debug_init(void) |
| 3754 | { |
| 3755 | struct dentry *ent; |
| 3756 | |
| 3757 | ent = debugfs_create_dir("skge", NULL); |
| 3758 | if (!ent || IS_ERR(ent)) { |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 3759 | pr_info("debugfs create directory failed\n"); |
Stephen Hemminger | 678aa1f | 2007-10-16 12:15:54 -0700 | [diff] [blame] | 3760 | return; |
| 3761 | } |
| 3762 | |
| 3763 | skge_debug = ent; |
| 3764 | register_netdevice_notifier(&skge_notifier); |
| 3765 | } |
| 3766 | |
| 3767 | static __exit void skge_debug_cleanup(void) |
| 3768 | { |
| 3769 | if (skge_debug) { |
| 3770 | unregister_netdevice_notifier(&skge_notifier); |
| 3771 | debugfs_remove(skge_debug); |
| 3772 | skge_debug = NULL; |
| 3773 | } |
| 3774 | } |
| 3775 | |
| 3776 | #else |
| 3777 | #define skge_debug_init() |
| 3778 | #define skge_debug_cleanup() |
| 3779 | #endif |
| 3780 | |
Stephen Hemminger | f80d032 | 2008-11-19 22:01:26 -0800 | [diff] [blame] | 3781 | static const struct net_device_ops skge_netdev_ops = { |
| 3782 | .ndo_open = skge_up, |
| 3783 | .ndo_stop = skge_down, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 3784 | .ndo_start_xmit = skge_xmit_frame, |
Stephen Hemminger | f80d032 | 2008-11-19 22:01:26 -0800 | [diff] [blame] | 3785 | .ndo_do_ioctl = skge_ioctl, |
| 3786 | .ndo_get_stats = skge_get_stats, |
| 3787 | .ndo_tx_timeout = skge_tx_timeout, |
| 3788 | .ndo_change_mtu = skge_change_mtu, |
| 3789 | .ndo_validate_addr = eth_validate_addr, |
| 3790 | .ndo_set_multicast_list = skge_set_multicast, |
| 3791 | .ndo_set_mac_address = skge_set_mac_address, |
| 3792 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3793 | .ndo_poll_controller = skge_netpoll, |
| 3794 | #endif |
| 3795 | }; |
| 3796 | |
| 3797 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3798 | /* Initialize network device */ |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 3799 | static struct net_device *skge_devinit(struct skge_hw *hw, int port, |
| 3800 | int highmem) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3801 | { |
| 3802 | struct skge_port *skge; |
| 3803 | struct net_device *dev = alloc_etherdev(sizeof(*skge)); |
| 3804 | |
| 3805 | if (!dev) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3806 | dev_err(&hw->pdev->dev, "etherdev alloc failed\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3807 | return NULL; |
| 3808 | } |
| 3809 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3810 | SET_NETDEV_DEV(dev, &hw->pdev->dev); |
Stephen Hemminger | f80d032 | 2008-11-19 22:01:26 -0800 | [diff] [blame] | 3811 | dev->netdev_ops = &skge_netdev_ops; |
| 3812 | dev->ethtool_ops = &skge_ethtool_ops; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3813 | dev->watchdog_timeo = TX_WATCHDOG; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3814 | dev->irq = hw->pdev->irq; |
Stephen Hemminger | 513f533 | 2006-09-01 15:53:49 -0700 | [diff] [blame] | 3815 | |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 3816 | if (highmem) |
| 3817 | dev->features |= NETIF_F_HIGHDMA; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3818 | |
| 3819 | skge = netdev_priv(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3820 | netif_napi_add(dev, &skge->napi, skge_poll, NAPI_WEIGHT); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3821 | skge->netdev = dev; |
| 3822 | skge->hw = hw; |
| 3823 | skge->msg_enable = netif_msg_init(debug, default_msg); |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3824 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3825 | skge->tx_ring.count = DEFAULT_TX_RING_SIZE; |
| 3826 | skge->rx_ring.count = DEFAULT_RX_RING_SIZE; |
| 3827 | |
| 3828 | /* Auto speed and flow control */ |
| 3829 | skge->autoneg = AUTONEG_ENABLE; |
Stephen Hemminger | 5d5c8e0 | 2006-10-05 15:49:52 -0700 | [diff] [blame] | 3830 | skge->flow_control = FLOW_MODE_SYM_OR_REM; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3831 | skge->duplex = -1; |
| 3832 | skge->speed = -1; |
Stephen Hemminger | 31b619c | 2005-06-27 11:33:11 -0700 | [diff] [blame] | 3833 | skge->advertising = skge_supported_modes(hw); |
Stephen Hemminger | 5b982c5 | 2007-05-08 13:36:20 -0700 | [diff] [blame] | 3834 | |
Rafael J. Wysocki | 7b55a4a | 2009-07-22 02:58:55 +0000 | [diff] [blame] | 3835 | if (device_can_wakeup(&hw->pdev->dev)) { |
Stephen Hemminger | 5b982c5 | 2007-05-08 13:36:20 -0700 | [diff] [blame] | 3836 | skge->wol = wol_supported(hw) & WAKE_MAGIC; |
Rafael J. Wysocki | 7b55a4a | 2009-07-22 02:58:55 +0000 | [diff] [blame] | 3837 | device_set_wakeup_enable(&hw->pdev->dev, skge->wol); |
| 3838 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3839 | |
| 3840 | hw->dev[port] = dev; |
| 3841 | |
| 3842 | skge->port = port; |
| 3843 | |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 3844 | /* Only used for Genesis XMAC */ |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3845 | setup_timer(&skge->link_timer, xm_link_timer, (unsigned long) skge); |
Stephen Hemminger | 64f6b64 | 2006-09-23 21:25:28 -0700 | [diff] [blame] | 3846 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3847 | if (hw->chip_id != CHIP_ID_GENESIS) { |
| 3848 | dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG; |
| 3849 | skge->rx_csum = 1; |
| 3850 | } |
| 3851 | |
| 3852 | /* read the mac address */ |
| 3853 | memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port*8, ETH_ALEN); |
John W. Linville | 56230d5 | 2005-09-12 10:48:57 -0400 | [diff] [blame] | 3854 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3855 | |
| 3856 | /* device is off until link detection */ |
| 3857 | netif_carrier_off(dev); |
| 3858 | netif_stop_queue(dev); |
| 3859 | |
| 3860 | return dev; |
| 3861 | } |
| 3862 | |
| 3863 | static void __devinit skge_show_addr(struct net_device *dev) |
| 3864 | { |
| 3865 | const struct skge_port *skge = netdev_priv(dev); |
| 3866 | |
Joe Perches | d707204 | 2010-02-09 11:49:53 +0000 | [diff] [blame] | 3867 | netif_info(skge, probe, skge->netdev, "addr %pM\n", dev->dev_addr); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3868 | } |
| 3869 | |
| 3870 | static int __devinit skge_probe(struct pci_dev *pdev, |
| 3871 | const struct pci_device_id *ent) |
| 3872 | { |
| 3873 | struct net_device *dev, *dev1; |
| 3874 | struct skge_hw *hw; |
| 3875 | int err, using_dac = 0; |
| 3876 | |
Stephen Hemminger | 203babb | 2006-03-21 10:57:05 -0800 | [diff] [blame] | 3877 | err = pci_enable_device(pdev); |
| 3878 | if (err) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3879 | dev_err(&pdev->dev, "cannot enable PCI device\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3880 | goto err_out; |
| 3881 | } |
| 3882 | |
Stephen Hemminger | 203babb | 2006-03-21 10:57:05 -0800 | [diff] [blame] | 3883 | err = pci_request_regions(pdev, DRV_NAME); |
| 3884 | if (err) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3885 | dev_err(&pdev->dev, "cannot obtain PCI resources\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3886 | goto err_out_disable_pdev; |
| 3887 | } |
| 3888 | |
| 3889 | pci_set_master(pdev); |
| 3890 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 3891 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3892 | using_dac = 1; |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 3893 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3894 | } else if (!(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) { |
Stephen Hemminger | 93aea71 | 2006-03-21 10:57:02 -0800 | [diff] [blame] | 3895 | using_dac = 0; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3896 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Stephen Hemminger | 93aea71 | 2006-03-21 10:57:02 -0800 | [diff] [blame] | 3897 | } |
| 3898 | |
| 3899 | if (err) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3900 | dev_err(&pdev->dev, "no usable DMA configuration\n"); |
Stephen Hemminger | 93aea71 | 2006-03-21 10:57:02 -0800 | [diff] [blame] | 3901 | goto err_out_free_regions; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | #ifdef __BIG_ENDIAN |
Stephen Hemminger | 8f3f819 | 2005-11-08 10:33:45 -0800 | [diff] [blame] | 3905 | /* byte swap descriptors in hardware */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3906 | { |
| 3907 | u32 reg; |
| 3908 | |
| 3909 | pci_read_config_dword(pdev, PCI_DEV_REG2, ®); |
| 3910 | reg |= PCI_REV_DESC; |
| 3911 | pci_write_config_dword(pdev, PCI_DEV_REG2, reg); |
| 3912 | } |
| 3913 | #endif |
| 3914 | |
| 3915 | err = -ENOMEM; |
Michal Schmidt | 415e69e | 2009-10-01 08:13:23 +0000 | [diff] [blame] | 3916 | /* space for skge@pci:0000:04:00.0 */ |
| 3917 | hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:" ) |
| 3918 | + strlen(pci_name(pdev)) + 1, GFP_KERNEL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3919 | if (!hw) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3920 | dev_err(&pdev->dev, "cannot allocate hardware struct\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3921 | goto err_out_free_regions; |
| 3922 | } |
Michal Schmidt | 415e69e | 2009-10-01 08:13:23 +0000 | [diff] [blame] | 3923 | sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev)); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3924 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3925 | hw->pdev = pdev; |
Stephen Hemminger | d38efdd | 2006-08-28 16:19:35 -0700 | [diff] [blame] | 3926 | spin_lock_init(&hw->hw_lock); |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 3927 | spin_lock_init(&hw->phy_lock); |
Joe Perches | 164165d | 2009-11-19 09:30:10 +0000 | [diff] [blame] | 3928 | tasklet_init(&hw->phy_task, skge_extirq, (unsigned long) hw); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3929 | |
| 3930 | hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000); |
| 3931 | if (!hw->regs) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3932 | dev_err(&pdev->dev, "cannot map device registers\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3933 | goto err_out_free_hw; |
| 3934 | } |
| 3935 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3936 | err = skge_reset(hw); |
| 3937 | if (err) |
Stephen Hemminger | ccdaa2a | 2006-08-28 16:19:38 -0700 | [diff] [blame] | 3938 | goto err_out_iounmap; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3939 | |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 3940 | pr_info("%s addr 0x%llx irq %d chip %s rev %d\n", |
| 3941 | DRV_VERSION, |
| 3942 | (unsigned long long)pci_resource_start(pdev, 0), pdev->irq, |
| 3943 | skge_board_name(hw), hw->chip_rev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3944 | |
Stephen Hemminger | ccdaa2a | 2006-08-28 16:19:38 -0700 | [diff] [blame] | 3945 | dev = skge_devinit(hw, 0, using_dac); |
| 3946 | if (!dev) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3947 | goto err_out_led_off; |
| 3948 | |
Stephen Hemminger | fae8759 | 2007-02-02 08:22:51 -0800 | [diff] [blame] | 3949 | /* Some motherboards are broken and has zero in ROM. */ |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3950 | if (!is_valid_ether_addr(dev->dev_addr)) |
| 3951 | dev_warn(&pdev->dev, "bad (zero?) ethernet address in rom\n"); |
Stephen Hemminger | 631ae32 | 2006-06-06 10:11:14 -0700 | [diff] [blame] | 3952 | |
Stephen Hemminger | 203babb | 2006-03-21 10:57:05 -0800 | [diff] [blame] | 3953 | err = register_netdev(dev); |
| 3954 | if (err) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3955 | dev_err(&pdev->dev, "cannot register net device\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3956 | goto err_out_free_netdev; |
| 3957 | } |
| 3958 | |
Michal Schmidt | 415e69e | 2009-10-01 08:13:23 +0000 | [diff] [blame] | 3959 | err = request_irq(pdev->irq, skge_intr, IRQF_SHARED, hw->irq_name, hw); |
Stephen Hemminger | ccdaa2a | 2006-08-28 16:19:38 -0700 | [diff] [blame] | 3960 | if (err) { |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3961 | dev_err(&pdev->dev, "%s: cannot assign irq %d\n", |
Stephen Hemminger | ccdaa2a | 2006-08-28 16:19:38 -0700 | [diff] [blame] | 3962 | dev->name, pdev->irq); |
| 3963 | goto err_out_unregister; |
| 3964 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3965 | skge_show_addr(dev); |
| 3966 | |
Mike McCormack | f191422 | 2009-09-23 03:50:36 +0000 | [diff] [blame] | 3967 | if (hw->ports > 1) { |
| 3968 | dev1 = skge_devinit(hw, 1, using_dac); |
| 3969 | if (dev1 && register_netdev(dev1) == 0) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3970 | skge_show_addr(dev1); |
| 3971 | else { |
| 3972 | /* Failure to register second port need not be fatal */ |
Stephen Hemminger | 1479d13 | 2007-02-02 08:22:52 -0800 | [diff] [blame] | 3973 | dev_warn(&pdev->dev, "register of second port failed\n"); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3974 | hw->dev[1] = NULL; |
Mike McCormack | f191422 | 2009-09-23 03:50:36 +0000 | [diff] [blame] | 3975 | hw->ports = 1; |
| 3976 | if (dev1) |
| 3977 | free_netdev(dev1); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3978 | } |
| 3979 | } |
Stephen Hemminger | ccdaa2a | 2006-08-28 16:19:38 -0700 | [diff] [blame] | 3980 | pci_set_drvdata(pdev, hw); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3981 | |
| 3982 | return 0; |
| 3983 | |
Stephen Hemminger | ccdaa2a | 2006-08-28 16:19:38 -0700 | [diff] [blame] | 3984 | err_out_unregister: |
| 3985 | unregister_netdev(dev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3986 | err_out_free_netdev: |
| 3987 | free_netdev(dev); |
| 3988 | err_out_led_off: |
| 3989 | skge_write16(hw, B0_LED, LED_STAT_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3990 | err_out_iounmap: |
| 3991 | iounmap(hw->regs); |
| 3992 | err_out_free_hw: |
| 3993 | kfree(hw); |
| 3994 | err_out_free_regions: |
| 3995 | pci_release_regions(pdev); |
| 3996 | err_out_disable_pdev: |
| 3997 | pci_disable_device(pdev); |
| 3998 | pci_set_drvdata(pdev, NULL); |
| 3999 | err_out: |
| 4000 | return err; |
| 4001 | } |
| 4002 | |
| 4003 | static void __devexit skge_remove(struct pci_dev *pdev) |
| 4004 | { |
| 4005 | struct skge_hw *hw = pci_get_drvdata(pdev); |
| 4006 | struct net_device *dev0, *dev1; |
| 4007 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 4008 | if (!hw) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4009 | return; |
| 4010 | |
Stephen Hemminger | 208491d8 | 2007-02-16 15:37:39 -0800 | [diff] [blame] | 4011 | flush_scheduled_work(); |
| 4012 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4013 | if ((dev1 = hw->dev[1])) |
| 4014 | unregister_netdev(dev1); |
| 4015 | dev0 = hw->dev[0]; |
| 4016 | unregister_netdev(dev0); |
| 4017 | |
Stephen Hemminger | 9cbe330 | 2007-03-16 14:01:28 -0700 | [diff] [blame] | 4018 | tasklet_disable(&hw->phy_task); |
| 4019 | |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 4020 | spin_lock_irq(&hw->hw_lock); |
| 4021 | hw->intr_mask = 0; |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 4022 | skge_write32(hw, B0_IMSK, 0); |
Stephen Hemminger | 78bc218 | 2006-08-28 16:19:36 -0700 | [diff] [blame] | 4023 | skge_read32(hw, B0_IMSK); |
Stephen Hemminger | 7c442fa | 2006-06-06 10:11:13 -0700 | [diff] [blame] | 4024 | spin_unlock_irq(&hw->hw_lock); |
| 4025 | |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 4026 | skge_write16(hw, B0_LED, LED_STAT_OFF); |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 4027 | skge_write8(hw, B0_CTST, CS_RST_SET); |
| 4028 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4029 | free_irq(pdev->irq, hw); |
| 4030 | pci_release_regions(pdev); |
| 4031 | pci_disable_device(pdev); |
| 4032 | if (dev1) |
| 4033 | free_netdev(dev1); |
| 4034 | free_netdev(dev0); |
Stephen Hemminger | 46a60f2 | 2005-09-09 12:54:56 -0700 | [diff] [blame] | 4035 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4036 | iounmap(hw->regs); |
| 4037 | kfree(hw); |
| 4038 | pci_set_drvdata(pdev, NULL); |
| 4039 | } |
| 4040 | |
| 4041 | #ifdef CONFIG_PM |
Pavel Machek | 2a56957 | 2005-07-07 17:56:40 -0700 | [diff] [blame] | 4042 | static int skge_suspend(struct pci_dev *pdev, pm_message_t state) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4043 | { |
| 4044 | struct skge_hw *hw = pci_get_drvdata(pdev); |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 4045 | int i, err, wol = 0; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4046 | |
Stephen Hemminger | e3b7df1 | 2007-05-11 11:21:45 -0700 | [diff] [blame] | 4047 | if (!hw) |
| 4048 | return 0; |
| 4049 | |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 4050 | err = pci_save_state(pdev); |
| 4051 | if (err) |
| 4052 | return err; |
| 4053 | |
Stephen Hemminger | d38efdd | 2006-08-28 16:19:35 -0700 | [diff] [blame] | 4054 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4055 | struct net_device *dev = hw->dev[i]; |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 4056 | struct skge_port *skge = netdev_priv(dev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4057 | |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 4058 | if (netif_running(dev)) |
| 4059 | skge_down(dev); |
| 4060 | if (skge->wol) |
| 4061 | skge_wol_init(skge); |
Stephen Hemminger | d38efdd | 2006-08-28 16:19:35 -0700 | [diff] [blame] | 4062 | |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 4063 | wol |= skge->wol; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4064 | } |
| 4065 | |
Stephen Hemminger | d38efdd | 2006-08-28 16:19:35 -0700 | [diff] [blame] | 4066 | skge_write32(hw, B0_IMSK, 0); |
Rafael J. Wysocki | 5177b32 | 2008-10-29 14:22:14 -0700 | [diff] [blame] | 4067 | |
| 4068 | pci_prepare_to_sleep(pdev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4069 | |
| 4070 | return 0; |
| 4071 | } |
| 4072 | |
| 4073 | static int skge_resume(struct pci_dev *pdev) |
| 4074 | { |
| 4075 | struct skge_hw *hw = pci_get_drvdata(pdev); |
Stephen Hemminger | d38efdd | 2006-08-28 16:19:35 -0700 | [diff] [blame] | 4076 | int i, err; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4077 | |
Stephen Hemminger | e3b7df1 | 2007-05-11 11:21:45 -0700 | [diff] [blame] | 4078 | if (!hw) |
| 4079 | return 0; |
| 4080 | |
Rafael J. Wysocki | 5177b32 | 2008-10-29 14:22:14 -0700 | [diff] [blame] | 4081 | err = pci_back_from_sleep(pdev); |
Stephen Hemminger | a504e64 | 2007-02-02 08:22:53 -0800 | [diff] [blame] | 4082 | if (err) |
| 4083 | goto out; |
| 4084 | |
| 4085 | err = pci_restore_state(pdev); |
| 4086 | if (err) |
| 4087 | goto out; |
| 4088 | |
Stephen Hemminger | d38efdd | 2006-08-28 16:19:35 -0700 | [diff] [blame] | 4089 | err = skge_reset(hw); |
| 4090 | if (err) |
| 4091 | goto out; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4092 | |
Stephen Hemminger | d38efdd | 2006-08-28 16:19:35 -0700 | [diff] [blame] | 4093 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4094 | struct net_device *dev = hw->dev[i]; |
Stephen Hemminger | d38efdd | 2006-08-28 16:19:35 -0700 | [diff] [blame] | 4095 | |
Stephen Hemminger | d38efdd | 2006-08-28 16:19:35 -0700 | [diff] [blame] | 4096 | if (netif_running(dev)) { |
| 4097 | err = skge_up(dev); |
| 4098 | |
| 4099 | if (err) { |
Joe Perches | f15063c | 2010-02-17 15:01:57 +0000 | [diff] [blame^] | 4100 | netdev_err(dev, "could not up: %d\n", err); |
Stephen Hemminger | edd702e | 2005-12-15 12:18:00 -0800 | [diff] [blame] | 4101 | dev_close(dev); |
Stephen Hemminger | d38efdd | 2006-08-28 16:19:35 -0700 | [diff] [blame] | 4102 | goto out; |
| 4103 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4104 | } |
| 4105 | } |
Stephen Hemminger | d38efdd | 2006-08-28 16:19:35 -0700 | [diff] [blame] | 4106 | out: |
| 4107 | return err; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4108 | } |
| 4109 | #endif |
| 4110 | |
Stephen Hemminger | 692412b | 2007-04-09 15:32:45 -0700 | [diff] [blame] | 4111 | static void skge_shutdown(struct pci_dev *pdev) |
| 4112 | { |
| 4113 | struct skge_hw *hw = pci_get_drvdata(pdev); |
| 4114 | int i, wol = 0; |
| 4115 | |
Stephen Hemminger | e3b7df1 | 2007-05-11 11:21:45 -0700 | [diff] [blame] | 4116 | if (!hw) |
| 4117 | return; |
| 4118 | |
Stephen Hemminger | 692412b | 2007-04-09 15:32:45 -0700 | [diff] [blame] | 4119 | for (i = 0; i < hw->ports; i++) { |
| 4120 | struct net_device *dev = hw->dev[i]; |
| 4121 | struct skge_port *skge = netdev_priv(dev); |
| 4122 | |
| 4123 | if (skge->wol) |
| 4124 | skge_wol_init(skge); |
| 4125 | wol |= skge->wol; |
| 4126 | } |
| 4127 | |
Rafael J. Wysocki | 5177b32 | 2008-10-29 14:22:14 -0700 | [diff] [blame] | 4128 | if (pci_enable_wake(pdev, PCI_D3cold, wol)) |
| 4129 | pci_enable_wake(pdev, PCI_D3hot, wol); |
Stephen Hemminger | 692412b | 2007-04-09 15:32:45 -0700 | [diff] [blame] | 4130 | |
| 4131 | pci_disable_device(pdev); |
| 4132 | pci_set_power_state(pdev, PCI_D3hot); |
| 4133 | |
| 4134 | } |
| 4135 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4136 | static struct pci_driver skge_driver = { |
| 4137 | .name = DRV_NAME, |
| 4138 | .id_table = skge_id_table, |
| 4139 | .probe = skge_probe, |
| 4140 | .remove = __devexit_p(skge_remove), |
| 4141 | #ifdef CONFIG_PM |
| 4142 | .suspend = skge_suspend, |
| 4143 | .resume = skge_resume, |
| 4144 | #endif |
Stephen Hemminger | 692412b | 2007-04-09 15:32:45 -0700 | [diff] [blame] | 4145 | .shutdown = skge_shutdown, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4146 | }; |
| 4147 | |
| 4148 | static int __init skge_init_module(void) |
| 4149 | { |
Stephen Hemminger | 678aa1f | 2007-10-16 12:15:54 -0700 | [diff] [blame] | 4150 | skge_debug_init(); |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 4151 | return pci_register_driver(&skge_driver); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | static void __exit skge_cleanup_module(void) |
| 4155 | { |
| 4156 | pci_unregister_driver(&skge_driver); |
Stephen Hemminger | 678aa1f | 2007-10-16 12:15:54 -0700 | [diff] [blame] | 4157 | skge_debug_cleanup(); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 4158 | } |
| 4159 | |
| 4160 | module_init(skge_init_module); |
| 4161 | module_exit(skge_cleanup_module); |