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