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 | * |
| 10 | * Copyright (C) 2004, Stephen Hemminger <shemminger@osdl.org> |
| 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 |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | */ |
| 26 | |
| 27 | #include <linux/config.h> |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/moduleparam.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/etherdevice.h> |
| 33 | #include <linux/ethtool.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/if_vlan.h> |
| 36 | #include <linux/ip.h> |
| 37 | #include <linux/delay.h> |
| 38 | #include <linux/crc32.h> |
Al Viro | 4075400 | 2005-04-03 09:15:52 +0100 | [diff] [blame] | 39 | #include <linux/dma-mapping.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" |
| 45 | #define DRV_VERSION "0.6" |
| 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 |
| 51 | #define MAX_RX_RING_SIZE 4096 |
| 52 | #define PHY_RETRIES 1000 |
| 53 | #define ETH_JUMBO_MTU 9000 |
| 54 | #define TX_WATCHDOG (5 * HZ) |
| 55 | #define NAPI_WEIGHT 64 |
| 56 | #define BLINK_HZ (HZ/4) |
| 57 | #define LINK_POLL_HZ (HZ/10) |
| 58 | |
| 59 | MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver"); |
| 60 | MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); |
| 61 | MODULE_LICENSE("GPL"); |
| 62 | MODULE_VERSION(DRV_VERSION); |
| 63 | |
| 64 | static const u32 default_msg |
| 65 | = NETIF_MSG_DRV| NETIF_MSG_PROBE| NETIF_MSG_LINK |
| 66 | | NETIF_MSG_IFUP| NETIF_MSG_IFDOWN; |
| 67 | |
| 68 | static int debug = -1; /* defaults above */ |
| 69 | module_param(debug, int, 0); |
| 70 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 71 | |
| 72 | static const struct pci_device_id skge_id_table[] = { |
Stephen Hemminger | 275834d | 2005-06-27 11:33:03 -0700 | [diff] [blame] | 73 | { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940) }, |
| 74 | { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B) }, |
| 75 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) }, |
| 76 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) }, |
| 77 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, /* SK-9Exx */ |
| 78 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T), }, |
| 79 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) }, |
| 80 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */ |
| 81 | { PCI_DEVICE(PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD) }, |
| 82 | { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1032) }, |
| 83 | { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1064) }, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 84 | { 0 } |
| 85 | }; |
| 86 | MODULE_DEVICE_TABLE(pci, skge_id_table); |
| 87 | |
| 88 | static int skge_up(struct net_device *dev); |
| 89 | static int skge_down(struct net_device *dev); |
| 90 | static void skge_tx_clean(struct skge_port *skge); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 91 | static void xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val); |
| 92 | static void 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] | 93 | static void genesis_get_stats(struct skge_port *skge, u64 *data); |
| 94 | static void yukon_get_stats(struct skge_port *skge, u64 *data); |
| 95 | static void yukon_init(struct skge_hw *hw, int port); |
| 96 | static void yukon_reset(struct skge_hw *hw, int port); |
| 97 | static void genesis_mac_init(struct skge_hw *hw, int port); |
| 98 | static void genesis_reset(struct skge_hw *hw, int port); |
| 99 | |
| 100 | static const int txqaddr[] = { Q_XA1, Q_XA2 }; |
| 101 | static const int rxqaddr[] = { Q_R1, Q_R2 }; |
| 102 | static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F }; |
| 103 | static const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F }; |
| 104 | |
| 105 | /* Don't need to look at whole 16K. |
| 106 | * last interesting register is descriptor poll timer. |
| 107 | */ |
| 108 | #define SKGE_REGS_LEN (29*128) |
| 109 | |
| 110 | static int skge_get_regs_len(struct net_device *dev) |
| 111 | { |
| 112 | return SKGE_REGS_LEN; |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | * Returns copy of control register region |
| 117 | * I/O region is divided into banks and certain regions are unreadable |
| 118 | */ |
| 119 | static void skge_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 120 | void *p) |
| 121 | { |
| 122 | const struct skge_port *skge = netdev_priv(dev); |
| 123 | unsigned long offs; |
| 124 | const void __iomem *io = skge->hw->regs; |
| 125 | static const unsigned long bankmap |
| 126 | = (1<<0) | (1<<2) | (1<<8) | (1<<9) |
| 127 | | (1<<12) | (1<<13) | (1<<14) | (1<<15) | (1<<16) |
| 128 | | (1<<17) | (1<<20) | (1<<21) | (1<<22) | (1<<23) |
| 129 | | (1<<24) | (1<<25) | (1<<26) | (1<<27) | (1<<28); |
| 130 | |
| 131 | regs->version = 1; |
| 132 | for (offs = 0; offs < regs->len; offs += 128) { |
| 133 | u32 len = min_t(u32, 128, regs->len - offs); |
| 134 | |
| 135 | if (bankmap & (1<<(offs/128))) |
| 136 | memcpy_fromio(p + offs, io + offs, len); |
| 137 | else |
| 138 | memset(p + offs, 0, len); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /* Wake on Lan only supported on Yukon chps with rev 1 or above */ |
| 143 | static int wol_supported(const struct skge_hw *hw) |
| 144 | { |
| 145 | return !((hw->chip_id == CHIP_ID_GENESIS || |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 146 | (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0))); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 150 | { |
| 151 | struct skge_port *skge = netdev_priv(dev); |
| 152 | |
| 153 | wol->supported = wol_supported(skge->hw) ? WAKE_MAGIC : 0; |
| 154 | wol->wolopts = skge->wol ? WAKE_MAGIC : 0; |
| 155 | } |
| 156 | |
| 157 | static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 158 | { |
| 159 | struct skge_port *skge = netdev_priv(dev); |
| 160 | struct skge_hw *hw = skge->hw; |
| 161 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 162 | if (wol->wolopts != WAKE_MAGIC && wol->wolopts != 0) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 163 | return -EOPNOTSUPP; |
| 164 | |
| 165 | if (wol->wolopts == WAKE_MAGIC && !wol_supported(hw)) |
| 166 | return -EOPNOTSUPP; |
| 167 | |
| 168 | skge->wol = wol->wolopts == WAKE_MAGIC; |
| 169 | |
| 170 | if (skge->wol) { |
| 171 | memcpy_toio(hw->regs + WOL_MAC_ADDR, dev->dev_addr, ETH_ALEN); |
| 172 | |
| 173 | skge_write16(hw, WOL_CTRL_STAT, |
| 174 | WOL_CTL_ENA_PME_ON_MAGIC_PKT | |
| 175 | WOL_CTL_ENA_MAGIC_PKT_UNIT); |
| 176 | } else |
| 177 | skge_write16(hw, WOL_CTRL_STAT, WOL_CTL_DEFAULT); |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | |
| 183 | static int skge_get_settings(struct net_device *dev, |
| 184 | struct ethtool_cmd *ecmd) |
| 185 | { |
| 186 | struct skge_port *skge = netdev_priv(dev); |
| 187 | struct skge_hw *hw = skge->hw; |
| 188 | |
| 189 | ecmd->transceiver = XCVR_INTERNAL; |
| 190 | |
| 191 | if (iscopper(hw)) { |
| 192 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 193 | ecmd->supported = SUPPORTED_1000baseT_Full |
| 194 | | SUPPORTED_1000baseT_Half |
| 195 | | SUPPORTED_Autoneg | SUPPORTED_TP; |
| 196 | else { |
| 197 | ecmd->supported = SUPPORTED_10baseT_Half |
| 198 | | SUPPORTED_10baseT_Full |
| 199 | | SUPPORTED_100baseT_Half |
| 200 | | SUPPORTED_100baseT_Full |
| 201 | | SUPPORTED_1000baseT_Half |
| 202 | | SUPPORTED_1000baseT_Full |
| 203 | | SUPPORTED_Autoneg| SUPPORTED_TP; |
| 204 | |
| 205 | if (hw->chip_id == CHIP_ID_YUKON) |
| 206 | ecmd->supported &= ~SUPPORTED_1000baseT_Half; |
| 207 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | ecmd->port = PORT_TP; |
| 211 | ecmd->phy_address = hw->phy_addr; |
| 212 | } else { |
| 213 | ecmd->supported = SUPPORTED_1000baseT_Full |
| 214 | | SUPPORTED_FIBRE |
| 215 | | SUPPORTED_Autoneg; |
| 216 | |
| 217 | ecmd->port = PORT_FIBRE; |
| 218 | } |
| 219 | |
| 220 | ecmd->advertising = skge->advertising; |
| 221 | ecmd->autoneg = skge->autoneg; |
| 222 | ecmd->speed = skge->speed; |
| 223 | ecmd->duplex = skge->duplex; |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | static u32 skge_modes(const struct skge_hw *hw) |
| 228 | { |
| 229 | u32 modes = ADVERTISED_Autoneg |
| 230 | | ADVERTISED_1000baseT_Full | ADVERTISED_1000baseT_Half |
| 231 | | ADVERTISED_100baseT_Full | ADVERTISED_100baseT_Half |
| 232 | | ADVERTISED_10baseT_Full | ADVERTISED_10baseT_Half; |
| 233 | |
| 234 | if (iscopper(hw)) { |
| 235 | modes |= ADVERTISED_TP; |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 236 | switch (hw->chip_id) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 237 | case CHIP_ID_GENESIS: |
| 238 | modes &= ~(ADVERTISED_100baseT_Full |
| 239 | | ADVERTISED_100baseT_Half |
| 240 | | ADVERTISED_10baseT_Full |
| 241 | | ADVERTISED_10baseT_Half); |
| 242 | break; |
| 243 | |
| 244 | case CHIP_ID_YUKON: |
| 245 | modes &= ~ADVERTISED_1000baseT_Half; |
| 246 | break; |
| 247 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 248 | } |
| 249 | } else { |
| 250 | modes |= ADVERTISED_FIBRE; |
| 251 | modes &= ~ADVERTISED_1000baseT_Half; |
| 252 | } |
| 253 | return modes; |
| 254 | } |
| 255 | |
| 256 | static int skge_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 257 | { |
| 258 | struct skge_port *skge = netdev_priv(dev); |
| 259 | const struct skge_hw *hw = skge->hw; |
| 260 | |
| 261 | if (ecmd->autoneg == AUTONEG_ENABLE) { |
| 262 | if (ecmd->advertising & skge_modes(hw)) |
| 263 | return -EINVAL; |
| 264 | } else { |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 265 | switch (ecmd->speed) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 266 | case SPEED_1000: |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 267 | break; |
| 268 | case SPEED_100: |
| 269 | case SPEED_10: |
| 270 | if (iscopper(hw) || hw->chip_id == CHIP_ID_GENESIS) |
| 271 | return -EINVAL; |
| 272 | break; |
| 273 | default: |
| 274 | return -EINVAL; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | skge->autoneg = ecmd->autoneg; |
| 279 | skge->speed = ecmd->speed; |
| 280 | skge->duplex = ecmd->duplex; |
| 281 | skge->advertising = ecmd->advertising; |
| 282 | |
| 283 | if (netif_running(dev)) { |
| 284 | skge_down(dev); |
| 285 | skge_up(dev); |
| 286 | } |
| 287 | return (0); |
| 288 | } |
| 289 | |
| 290 | static void skge_get_drvinfo(struct net_device *dev, |
| 291 | struct ethtool_drvinfo *info) |
| 292 | { |
| 293 | struct skge_port *skge = netdev_priv(dev); |
| 294 | |
| 295 | strcpy(info->driver, DRV_NAME); |
| 296 | strcpy(info->version, DRV_VERSION); |
| 297 | strcpy(info->fw_version, "N/A"); |
| 298 | strcpy(info->bus_info, pci_name(skge->hw->pdev)); |
| 299 | } |
| 300 | |
| 301 | static const struct skge_stat { |
| 302 | char name[ETH_GSTRING_LEN]; |
| 303 | u16 xmac_offset; |
| 304 | u16 gma_offset; |
| 305 | } skge_stats[] = { |
| 306 | { "tx_bytes", XM_TXO_OK_HI, GM_TXO_OK_HI }, |
| 307 | { "rx_bytes", XM_RXO_OK_HI, GM_RXO_OK_HI }, |
| 308 | |
| 309 | { "tx_broadcast", XM_TXF_BC_OK, GM_TXF_BC_OK }, |
| 310 | { "rx_broadcast", XM_RXF_BC_OK, GM_RXF_BC_OK }, |
| 311 | { "tx_multicast", XM_TXF_MC_OK, GM_TXF_MC_OK }, |
| 312 | { "rx_multicast", XM_RXF_MC_OK, GM_RXF_MC_OK }, |
| 313 | { "tx_unicast", XM_TXF_UC_OK, GM_TXF_UC_OK }, |
| 314 | { "rx_unicast", XM_RXF_UC_OK, GM_RXF_UC_OK }, |
| 315 | { "tx_mac_pause", XM_TXF_MPAUSE, GM_TXF_MPAUSE }, |
| 316 | { "rx_mac_pause", XM_RXF_MPAUSE, GM_RXF_MPAUSE }, |
| 317 | |
| 318 | { "collisions", XM_TXF_SNG_COL, GM_TXF_SNG_COL }, |
| 319 | { "multi_collisions", XM_TXF_MUL_COL, GM_TXF_MUL_COL }, |
| 320 | { "aborted", XM_TXF_ABO_COL, GM_TXF_ABO_COL }, |
| 321 | { "late_collision", XM_TXF_LAT_COL, GM_TXF_LAT_COL }, |
| 322 | { "fifo_underrun", XM_TXE_FIFO_UR, GM_TXE_FIFO_UR }, |
| 323 | { "fifo_overflow", XM_RXE_FIFO_OV, GM_RXE_FIFO_OV }, |
| 324 | |
| 325 | { "rx_toolong", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR }, |
| 326 | { "rx_jabber", XM_RXF_JAB_PKT, GM_RXF_JAB_PKT }, |
| 327 | { "rx_runt", XM_RXE_RUNT, GM_RXE_FRAG }, |
| 328 | { "rx_too_long", XM_RXF_LNG_ERR, GM_RXF_LNG_ERR }, |
| 329 | { "rx_fcs_error", XM_RXF_FCS_ERR, GM_RXF_FCS_ERR }, |
| 330 | }; |
| 331 | |
| 332 | static int skge_get_stats_count(struct net_device *dev) |
| 333 | { |
| 334 | return ARRAY_SIZE(skge_stats); |
| 335 | } |
| 336 | |
| 337 | static void skge_get_ethtool_stats(struct net_device *dev, |
| 338 | struct ethtool_stats *stats, u64 *data) |
| 339 | { |
| 340 | struct skge_port *skge = netdev_priv(dev); |
| 341 | |
| 342 | if (skge->hw->chip_id == CHIP_ID_GENESIS) |
| 343 | genesis_get_stats(skge, data); |
| 344 | else |
| 345 | yukon_get_stats(skge, data); |
| 346 | } |
| 347 | |
| 348 | /* Use hardware MIB variables for critical path statistics and |
| 349 | * transmit feedback not reported at interrupt. |
| 350 | * Other errors are accounted for in interrupt handler. |
| 351 | */ |
| 352 | static struct net_device_stats *skge_get_stats(struct net_device *dev) |
| 353 | { |
| 354 | struct skge_port *skge = netdev_priv(dev); |
| 355 | u64 data[ARRAY_SIZE(skge_stats)]; |
| 356 | |
| 357 | if (skge->hw->chip_id == CHIP_ID_GENESIS) |
| 358 | genesis_get_stats(skge, data); |
| 359 | else |
| 360 | yukon_get_stats(skge, data); |
| 361 | |
| 362 | skge->net_stats.tx_bytes = data[0]; |
| 363 | skge->net_stats.rx_bytes = data[1]; |
| 364 | skge->net_stats.tx_packets = data[2] + data[4] + data[6]; |
| 365 | skge->net_stats.rx_packets = data[3] + data[5] + data[7]; |
| 366 | skge->net_stats.multicast = data[5] + data[7]; |
| 367 | skge->net_stats.collisions = data[10]; |
| 368 | skge->net_stats.tx_aborted_errors = data[12]; |
| 369 | |
| 370 | return &skge->net_stats; |
| 371 | } |
| 372 | |
| 373 | static void skge_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 374 | { |
| 375 | int i; |
| 376 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 377 | switch (stringset) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 378 | case ETH_SS_STATS: |
| 379 | for (i = 0; i < ARRAY_SIZE(skge_stats); i++) |
| 380 | memcpy(data + i * ETH_GSTRING_LEN, |
| 381 | skge_stats[i].name, ETH_GSTRING_LEN); |
| 382 | break; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | static void skge_get_ring_param(struct net_device *dev, |
| 387 | struct ethtool_ringparam *p) |
| 388 | { |
| 389 | struct skge_port *skge = netdev_priv(dev); |
| 390 | |
| 391 | p->rx_max_pending = MAX_RX_RING_SIZE; |
| 392 | p->tx_max_pending = MAX_TX_RING_SIZE; |
| 393 | p->rx_mini_max_pending = 0; |
| 394 | p->rx_jumbo_max_pending = 0; |
| 395 | |
| 396 | p->rx_pending = skge->rx_ring.count; |
| 397 | p->tx_pending = skge->tx_ring.count; |
| 398 | p->rx_mini_pending = 0; |
| 399 | p->rx_jumbo_pending = 0; |
| 400 | } |
| 401 | |
| 402 | static int skge_set_ring_param(struct net_device *dev, |
| 403 | struct ethtool_ringparam *p) |
| 404 | { |
| 405 | struct skge_port *skge = netdev_priv(dev); |
| 406 | |
| 407 | if (p->rx_pending == 0 || p->rx_pending > MAX_RX_RING_SIZE || |
| 408 | p->tx_pending == 0 || p->tx_pending > MAX_TX_RING_SIZE) |
| 409 | return -EINVAL; |
| 410 | |
| 411 | skge->rx_ring.count = p->rx_pending; |
| 412 | skge->tx_ring.count = p->tx_pending; |
| 413 | |
| 414 | if (netif_running(dev)) { |
| 415 | skge_down(dev); |
| 416 | skge_up(dev); |
| 417 | } |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static u32 skge_get_msglevel(struct net_device *netdev) |
| 423 | { |
| 424 | struct skge_port *skge = netdev_priv(netdev); |
| 425 | return skge->msg_enable; |
| 426 | } |
| 427 | |
| 428 | static void skge_set_msglevel(struct net_device *netdev, u32 value) |
| 429 | { |
| 430 | struct skge_port *skge = netdev_priv(netdev); |
| 431 | skge->msg_enable = value; |
| 432 | } |
| 433 | |
| 434 | static int skge_nway_reset(struct net_device *dev) |
| 435 | { |
| 436 | struct skge_port *skge = netdev_priv(dev); |
| 437 | struct skge_hw *hw = skge->hw; |
| 438 | int port = skge->port; |
| 439 | |
| 440 | if (skge->autoneg != AUTONEG_ENABLE || !netif_running(dev)) |
| 441 | return -EINVAL; |
| 442 | |
| 443 | spin_lock_bh(&hw->phy_lock); |
| 444 | if (hw->chip_id == CHIP_ID_GENESIS) { |
| 445 | genesis_reset(hw, port); |
| 446 | genesis_mac_init(hw, port); |
| 447 | } else { |
| 448 | yukon_reset(hw, port); |
| 449 | yukon_init(hw, port); |
| 450 | } |
| 451 | spin_unlock_bh(&hw->phy_lock); |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static int skge_set_sg(struct net_device *dev, u32 data) |
| 456 | { |
| 457 | struct skge_port *skge = netdev_priv(dev); |
| 458 | struct skge_hw *hw = skge->hw; |
| 459 | |
| 460 | if (hw->chip_id == CHIP_ID_GENESIS && data) |
| 461 | return -EOPNOTSUPP; |
| 462 | return ethtool_op_set_sg(dev, data); |
| 463 | } |
| 464 | |
| 465 | static int skge_set_tx_csum(struct net_device *dev, u32 data) |
| 466 | { |
| 467 | struct skge_port *skge = netdev_priv(dev); |
| 468 | struct skge_hw *hw = skge->hw; |
| 469 | |
| 470 | if (hw->chip_id == CHIP_ID_GENESIS && data) |
| 471 | return -EOPNOTSUPP; |
| 472 | |
| 473 | return ethtool_op_set_tx_csum(dev, data); |
| 474 | } |
| 475 | |
| 476 | static u32 skge_get_rx_csum(struct net_device *dev) |
| 477 | { |
| 478 | struct skge_port *skge = netdev_priv(dev); |
| 479 | |
| 480 | return skge->rx_csum; |
| 481 | } |
| 482 | |
| 483 | /* Only Yukon supports checksum offload. */ |
| 484 | static int skge_set_rx_csum(struct net_device *dev, u32 data) |
| 485 | { |
| 486 | struct skge_port *skge = netdev_priv(dev); |
| 487 | |
| 488 | if (skge->hw->chip_id == CHIP_ID_GENESIS && data) |
| 489 | return -EOPNOTSUPP; |
| 490 | |
| 491 | skge->rx_csum = data; |
| 492 | return 0; |
| 493 | } |
| 494 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 495 | static void skge_get_pauseparam(struct net_device *dev, |
| 496 | struct ethtool_pauseparam *ecmd) |
| 497 | { |
| 498 | struct skge_port *skge = netdev_priv(dev); |
| 499 | |
| 500 | ecmd->tx_pause = (skge->flow_control == FLOW_MODE_LOC_SEND) |
| 501 | || (skge->flow_control == FLOW_MODE_SYMMETRIC); |
| 502 | ecmd->rx_pause = (skge->flow_control == FLOW_MODE_REM_SEND) |
| 503 | || (skge->flow_control == FLOW_MODE_SYMMETRIC); |
| 504 | |
| 505 | ecmd->autoneg = skge->autoneg; |
| 506 | } |
| 507 | |
| 508 | static int skge_set_pauseparam(struct net_device *dev, |
| 509 | struct ethtool_pauseparam *ecmd) |
| 510 | { |
| 511 | struct skge_port *skge = netdev_priv(dev); |
| 512 | |
| 513 | skge->autoneg = ecmd->autoneg; |
| 514 | if (ecmd->rx_pause && ecmd->tx_pause) |
| 515 | skge->flow_control = FLOW_MODE_SYMMETRIC; |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 516 | else if (ecmd->rx_pause && !ecmd->tx_pause) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 517 | skge->flow_control = FLOW_MODE_REM_SEND; |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 518 | else if (!ecmd->rx_pause && ecmd->tx_pause) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 519 | skge->flow_control = FLOW_MODE_LOC_SEND; |
| 520 | else |
| 521 | skge->flow_control = FLOW_MODE_NONE; |
| 522 | |
| 523 | if (netif_running(dev)) { |
| 524 | skge_down(dev); |
| 525 | skge_up(dev); |
| 526 | } |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | /* Chip internal frequency for clock calculations */ |
| 531 | static inline u32 hwkhz(const struct skge_hw *hw) |
| 532 | { |
| 533 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 534 | return 53215; /* or: 53.125 MHz */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 535 | else |
| 536 | return 78215; /* or: 78.125 MHz */ |
| 537 | } |
| 538 | |
| 539 | /* Chip hz to microseconds */ |
| 540 | static inline u32 skge_clk2usec(const struct skge_hw *hw, u32 ticks) |
| 541 | { |
| 542 | return (ticks * 1000) / hwkhz(hw); |
| 543 | } |
| 544 | |
| 545 | /* Microseconds to chip hz */ |
| 546 | static inline u32 skge_usecs2clk(const struct skge_hw *hw, u32 usec) |
| 547 | { |
| 548 | return hwkhz(hw) * usec / 1000; |
| 549 | } |
| 550 | |
| 551 | static int skge_get_coalesce(struct net_device *dev, |
| 552 | struct ethtool_coalesce *ecmd) |
| 553 | { |
| 554 | struct skge_port *skge = netdev_priv(dev); |
| 555 | struct skge_hw *hw = skge->hw; |
| 556 | int port = skge->port; |
| 557 | |
| 558 | ecmd->rx_coalesce_usecs = 0; |
| 559 | ecmd->tx_coalesce_usecs = 0; |
| 560 | |
| 561 | if (skge_read32(hw, B2_IRQM_CTRL) & TIM_START) { |
| 562 | u32 delay = skge_clk2usec(hw, skge_read32(hw, B2_IRQM_INI)); |
| 563 | u32 msk = skge_read32(hw, B2_IRQM_MSK); |
| 564 | |
| 565 | if (msk & rxirqmask[port]) |
| 566 | ecmd->rx_coalesce_usecs = delay; |
| 567 | if (msk & txirqmask[port]) |
| 568 | ecmd->tx_coalesce_usecs = delay; |
| 569 | } |
| 570 | |
| 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | /* Note: interrupt timer is per board, but can turn on/off per port */ |
| 575 | static int skge_set_coalesce(struct net_device *dev, |
| 576 | struct ethtool_coalesce *ecmd) |
| 577 | { |
| 578 | struct skge_port *skge = netdev_priv(dev); |
| 579 | struct skge_hw *hw = skge->hw; |
| 580 | int port = skge->port; |
| 581 | u32 msk = skge_read32(hw, B2_IRQM_MSK); |
| 582 | u32 delay = 25; |
| 583 | |
| 584 | if (ecmd->rx_coalesce_usecs == 0) |
| 585 | msk &= ~rxirqmask[port]; |
| 586 | else if (ecmd->rx_coalesce_usecs < 25 || |
| 587 | ecmd->rx_coalesce_usecs > 33333) |
| 588 | return -EINVAL; |
| 589 | else { |
| 590 | msk |= rxirqmask[port]; |
| 591 | delay = ecmd->rx_coalesce_usecs; |
| 592 | } |
| 593 | |
| 594 | if (ecmd->tx_coalesce_usecs == 0) |
| 595 | msk &= ~txirqmask[port]; |
| 596 | else if (ecmd->tx_coalesce_usecs < 25 || |
| 597 | ecmd->tx_coalesce_usecs > 33333) |
| 598 | return -EINVAL; |
| 599 | else { |
| 600 | msk |= txirqmask[port]; |
| 601 | delay = min(delay, ecmd->rx_coalesce_usecs); |
| 602 | } |
| 603 | |
| 604 | skge_write32(hw, B2_IRQM_MSK, msk); |
| 605 | if (msk == 0) |
| 606 | skge_write32(hw, B2_IRQM_CTRL, TIM_STOP); |
| 607 | else { |
| 608 | skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, delay)); |
| 609 | skge_write32(hw, B2_IRQM_CTRL, TIM_START); |
| 610 | } |
| 611 | return 0; |
| 612 | } |
| 613 | |
| 614 | static void skge_led_on(struct skge_hw *hw, int port) |
| 615 | { |
| 616 | if (hw->chip_id == CHIP_ID_GENESIS) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 617 | skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 618 | skge_write8(hw, B0_LED, LED_STAT_ON); |
| 619 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 620 | skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON); |
| 621 | skge_write32(hw, SK_REG(port, RX_LED_VAL), 100); |
| 622 | skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 623 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 624 | /* For Broadcom Phy only */ |
| 625 | xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 626 | } else { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 627 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); |
| 628 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 629 | PHY_M_LED_MO_DUP(MO_LED_ON) | |
| 630 | PHY_M_LED_MO_10(MO_LED_ON) | |
| 631 | PHY_M_LED_MO_100(MO_LED_ON) | |
| 632 | PHY_M_LED_MO_1000(MO_LED_ON) | |
| 633 | PHY_M_LED_MO_RX(MO_LED_ON)); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | static void skge_led_off(struct skge_hw *hw, int port) |
| 638 | { |
| 639 | if (hw->chip_id == CHIP_ID_GENESIS) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 640 | skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 641 | skge_write8(hw, B0_LED, LED_STAT_OFF); |
| 642 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 643 | skge_write32(hw, SK_REG(port, RX_LED_VAL), 0); |
| 644 | skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 645 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 646 | /* Broadcom only */ |
| 647 | xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 648 | } else { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 649 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); |
| 650 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 651 | PHY_M_LED_MO_DUP(MO_LED_OFF) | |
| 652 | PHY_M_LED_MO_10(MO_LED_OFF) | |
| 653 | PHY_M_LED_MO_100(MO_LED_OFF) | |
| 654 | PHY_M_LED_MO_1000(MO_LED_OFF) | |
| 655 | PHY_M_LED_MO_RX(MO_LED_OFF)); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | static void skge_blink_timer(unsigned long data) |
| 660 | { |
| 661 | struct skge_port *skge = (struct skge_port *) data; |
| 662 | struct skge_hw *hw = skge->hw; |
| 663 | unsigned long flags; |
| 664 | |
| 665 | spin_lock_irqsave(&hw->phy_lock, flags); |
| 666 | if (skge->blink_on) |
| 667 | skge_led_on(hw, skge->port); |
| 668 | else |
| 669 | skge_led_off(hw, skge->port); |
| 670 | spin_unlock_irqrestore(&hw->phy_lock, flags); |
| 671 | |
| 672 | skge->blink_on = !skge->blink_on; |
| 673 | mod_timer(&skge->led_blink, jiffies + BLINK_HZ); |
| 674 | } |
| 675 | |
| 676 | /* blink LED's for finding board */ |
| 677 | static int skge_phys_id(struct net_device *dev, u32 data) |
| 678 | { |
| 679 | struct skge_port *skge = netdev_priv(dev); |
| 680 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 681 | if (!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ)) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 682 | data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ); |
| 683 | |
| 684 | /* start blinking */ |
| 685 | skge->blink_on = 1; |
| 686 | mod_timer(&skge->led_blink, jiffies+1); |
| 687 | |
| 688 | msleep_interruptible(data * 1000); |
| 689 | del_timer_sync(&skge->led_blink); |
| 690 | |
| 691 | skge_led_off(skge->hw, skge->port); |
| 692 | |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | static struct ethtool_ops skge_ethtool_ops = { |
| 697 | .get_settings = skge_get_settings, |
| 698 | .set_settings = skge_set_settings, |
| 699 | .get_drvinfo = skge_get_drvinfo, |
| 700 | .get_regs_len = skge_get_regs_len, |
| 701 | .get_regs = skge_get_regs, |
| 702 | .get_wol = skge_get_wol, |
| 703 | .set_wol = skge_set_wol, |
| 704 | .get_msglevel = skge_get_msglevel, |
| 705 | .set_msglevel = skge_set_msglevel, |
| 706 | .nway_reset = skge_nway_reset, |
| 707 | .get_link = ethtool_op_get_link, |
| 708 | .get_ringparam = skge_get_ring_param, |
| 709 | .set_ringparam = skge_set_ring_param, |
| 710 | .get_pauseparam = skge_get_pauseparam, |
| 711 | .set_pauseparam = skge_set_pauseparam, |
| 712 | .get_coalesce = skge_get_coalesce, |
| 713 | .set_coalesce = skge_set_coalesce, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 714 | .get_sg = ethtool_op_get_sg, |
| 715 | .set_sg = skge_set_sg, |
| 716 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 717 | .set_tx_csum = skge_set_tx_csum, |
| 718 | .get_rx_csum = skge_get_rx_csum, |
| 719 | .set_rx_csum = skge_set_rx_csum, |
| 720 | .get_strings = skge_get_strings, |
| 721 | .phys_id = skge_phys_id, |
| 722 | .get_stats_count = skge_get_stats_count, |
| 723 | .get_ethtool_stats = skge_get_ethtool_stats, |
| 724 | }; |
| 725 | |
| 726 | /* |
| 727 | * Allocate ring elements and chain them together |
| 728 | * One-to-one association of board descriptors with ring elements |
| 729 | */ |
| 730 | static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u64 base) |
| 731 | { |
| 732 | struct skge_tx_desc *d; |
| 733 | struct skge_element *e; |
| 734 | int i; |
| 735 | |
| 736 | ring->start = kmalloc(sizeof(*e)*ring->count, GFP_KERNEL); |
| 737 | if (!ring->start) |
| 738 | return -ENOMEM; |
| 739 | |
| 740 | for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) { |
| 741 | e->desc = d; |
| 742 | if (i == ring->count - 1) { |
| 743 | e->next = ring->start; |
| 744 | d->next_offset = base; |
| 745 | } else { |
| 746 | e->next = e + 1; |
| 747 | d->next_offset = base + (i+1) * sizeof(*d); |
| 748 | } |
| 749 | } |
| 750 | ring->to_use = ring->to_clean = ring->start; |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | /* Setup buffer for receiving */ |
| 756 | static inline int skge_rx_alloc(struct skge_port *skge, |
| 757 | struct skge_element *e) |
| 758 | { |
| 759 | unsigned long bufsize = skge->netdev->mtu + ETH_HLEN; /* VLAN? */ |
| 760 | struct skge_rx_desc *rd = e->desc; |
| 761 | struct sk_buff *skb; |
| 762 | u64 map; |
| 763 | |
| 764 | skb = dev_alloc_skb(bufsize + NET_IP_ALIGN); |
| 765 | if (unlikely(!skb)) { |
| 766 | printk(KERN_DEBUG PFX "%s: out of memory for receive\n", |
| 767 | skge->netdev->name); |
| 768 | return -ENOMEM; |
| 769 | } |
| 770 | |
| 771 | skb->dev = skge->netdev; |
| 772 | skb_reserve(skb, NET_IP_ALIGN); |
| 773 | |
| 774 | map = pci_map_single(skge->hw->pdev, skb->data, bufsize, |
| 775 | PCI_DMA_FROMDEVICE); |
| 776 | |
| 777 | rd->dma_lo = map; |
| 778 | rd->dma_hi = map >> 32; |
| 779 | e->skb = skb; |
| 780 | rd->csum1_start = ETH_HLEN; |
| 781 | rd->csum2_start = ETH_HLEN; |
| 782 | rd->csum1 = 0; |
| 783 | rd->csum2 = 0; |
| 784 | |
| 785 | wmb(); |
| 786 | |
| 787 | rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize; |
| 788 | pci_unmap_addr_set(e, mapaddr, map); |
| 789 | pci_unmap_len_set(e, maplen, bufsize); |
| 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | /* Free all unused buffers in receive ring, assumes receiver stopped */ |
| 794 | static void skge_rx_clean(struct skge_port *skge) |
| 795 | { |
| 796 | struct skge_hw *hw = skge->hw; |
| 797 | struct skge_ring *ring = &skge->rx_ring; |
| 798 | struct skge_element *e; |
| 799 | |
| 800 | for (e = ring->to_clean; e != ring->to_use; e = e->next) { |
| 801 | struct skge_rx_desc *rd = e->desc; |
| 802 | rd->control = 0; |
| 803 | |
| 804 | pci_unmap_single(hw->pdev, |
| 805 | pci_unmap_addr(e, mapaddr), |
| 806 | pci_unmap_len(e, maplen), |
| 807 | PCI_DMA_FROMDEVICE); |
| 808 | dev_kfree_skb(e->skb); |
| 809 | e->skb = NULL; |
| 810 | } |
| 811 | ring->to_clean = e; |
| 812 | } |
| 813 | |
| 814 | /* Allocate buffers for receive ring |
| 815 | * For receive: to_use is refill location |
| 816 | * to_clean is next received frame. |
| 817 | * |
| 818 | * if (to_use == to_clean) |
| 819 | * then ring all frames in ring need buffers |
| 820 | * if (to_use->next == to_clean) |
| 821 | * then ring all frames in ring have buffers |
| 822 | */ |
| 823 | static int skge_rx_fill(struct skge_port *skge) |
| 824 | { |
| 825 | struct skge_ring *ring = &skge->rx_ring; |
| 826 | struct skge_element *e; |
| 827 | int ret = 0; |
| 828 | |
| 829 | for (e = ring->to_use; e->next != ring->to_clean; e = e->next) { |
| 830 | if (skge_rx_alloc(skge, e)) { |
| 831 | ret = 1; |
| 832 | break; |
| 833 | } |
| 834 | |
| 835 | } |
| 836 | ring->to_use = e; |
| 837 | |
| 838 | return ret; |
| 839 | } |
| 840 | |
| 841 | static void skge_link_up(struct skge_port *skge) |
| 842 | { |
| 843 | netif_carrier_on(skge->netdev); |
| 844 | if (skge->tx_avail > MAX_SKB_FRAGS + 1) |
| 845 | netif_wake_queue(skge->netdev); |
| 846 | |
| 847 | if (netif_msg_link(skge)) |
| 848 | printk(KERN_INFO PFX |
| 849 | "%s: Link is up at %d Mbps, %s duplex, flow control %s\n", |
| 850 | skge->netdev->name, skge->speed, |
| 851 | skge->duplex == DUPLEX_FULL ? "full" : "half", |
| 852 | (skge->flow_control == FLOW_MODE_NONE) ? "none" : |
| 853 | (skge->flow_control == FLOW_MODE_LOC_SEND) ? "tx only" : |
| 854 | (skge->flow_control == FLOW_MODE_REM_SEND) ? "rx only" : |
| 855 | (skge->flow_control == FLOW_MODE_SYMMETRIC) ? "tx and rx" : |
| 856 | "unknown"); |
| 857 | } |
| 858 | |
| 859 | static void skge_link_down(struct skge_port *skge) |
| 860 | { |
| 861 | netif_carrier_off(skge->netdev); |
| 862 | netif_stop_queue(skge->netdev); |
| 863 | |
| 864 | if (netif_msg_link(skge)) |
| 865 | printk(KERN_INFO PFX "%s: Link is down.\n", skge->netdev->name); |
| 866 | } |
| 867 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 868 | static u16 xm_phy_read(struct skge_hw *hw, int port, u16 reg) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 869 | { |
| 870 | int i; |
| 871 | u16 v; |
| 872 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 873 | xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr); |
| 874 | v = xm_read16(hw, port, XM_PHY_DATA); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 875 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 876 | /* Need to wait for external PHY */ |
| 877 | for (i = 0; i < PHY_RETRIES; i++) { |
| 878 | udelay(1); |
| 879 | if (xm_read16(hw, port, XM_MMU_CMD) |
| 880 | & XM_MMU_PHY_RDY) |
| 881 | goto ready; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 882 | } |
| 883 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 884 | printk(KERN_WARNING PFX "%s: phy read timed out\n", |
| 885 | hw->dev[port]->name); |
| 886 | return 0; |
| 887 | ready: |
| 888 | v = xm_read16(hw, port, XM_PHY_DATA); |
| 889 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 890 | return v; |
| 891 | } |
| 892 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 893 | static void 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] | 894 | { |
| 895 | int i; |
| 896 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 897 | xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 898 | for (i = 0; i < PHY_RETRIES; i++) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 899 | if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY)) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 900 | goto ready; |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 901 | udelay(1); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 902 | } |
| 903 | printk(KERN_WARNING PFX "%s: phy write failed to come ready\n", |
| 904 | hw->dev[port]->name); |
| 905 | |
| 906 | |
| 907 | ready: |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 908 | xm_write16(hw, port, XM_PHY_DATA, val); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 909 | for (i = 0; i < PHY_RETRIES; i++) { |
| 910 | udelay(1); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 911 | if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY)) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 912 | return; |
| 913 | } |
| 914 | printk(KERN_WARNING PFX "%s: phy write timed out\n", |
| 915 | hw->dev[port]->name); |
| 916 | } |
| 917 | |
| 918 | static void genesis_init(struct skge_hw *hw) |
| 919 | { |
| 920 | /* set blink source counter */ |
| 921 | skge_write32(hw, B2_BSC_INI, (SK_BLK_DUR * SK_FACT_53) / 100); |
| 922 | skge_write8(hw, B2_BSC_CTRL, BSC_START); |
| 923 | |
| 924 | /* configure mac arbiter */ |
| 925 | skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR); |
| 926 | |
| 927 | /* configure mac arbiter timeout values */ |
| 928 | skge_write8(hw, B3_MA_TOINI_RX1, SK_MAC_TO_53); |
| 929 | skge_write8(hw, B3_MA_TOINI_RX2, SK_MAC_TO_53); |
| 930 | skge_write8(hw, B3_MA_TOINI_TX1, SK_MAC_TO_53); |
| 931 | skge_write8(hw, B3_MA_TOINI_TX2, SK_MAC_TO_53); |
| 932 | |
| 933 | skge_write8(hw, B3_MA_RCINI_RX1, 0); |
| 934 | skge_write8(hw, B3_MA_RCINI_RX2, 0); |
| 935 | skge_write8(hw, B3_MA_RCINI_TX1, 0); |
| 936 | skge_write8(hw, B3_MA_RCINI_TX2, 0); |
| 937 | |
| 938 | /* configure packet arbiter timeout */ |
| 939 | skge_write16(hw, B3_PA_CTRL, PA_RST_CLR); |
| 940 | skge_write16(hw, B3_PA_TOINI_RX1, SK_PKT_TO_MAX); |
| 941 | skge_write16(hw, B3_PA_TOINI_TX1, SK_PKT_TO_MAX); |
| 942 | skge_write16(hw, B3_PA_TOINI_RX2, SK_PKT_TO_MAX); |
| 943 | skge_write16(hw, B3_PA_TOINI_TX2, SK_PKT_TO_MAX); |
| 944 | } |
| 945 | |
| 946 | static void genesis_reset(struct skge_hw *hw, int port) |
| 947 | { |
| 948 | int i; |
| 949 | u64 zero = 0; |
| 950 | |
| 951 | /* reset the statistics module */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 952 | xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT); |
| 953 | xm_write16(hw, port, XM_IMSK, 0xffff); /* disable XMAC IRQs */ |
| 954 | xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */ |
| 955 | xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */ |
| 956 | xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 957 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 958 | /* disable Broadcom PHY IRQ */ |
| 959 | xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 960 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 961 | xm_outhash(hw, port, XM_HSM, (u8 *) &zero); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 962 | for (i = 0; i < 15; i++) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 963 | xm_outaddr(hw, port, XM_EXM(i), (u8 *) &zero); |
| 964 | xm_outhash(hw, port, XM_SRC_CHK, (u8 *) &zero); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | |
| 968 | static void genesis_mac_init(struct skge_hw *hw, int port) |
| 969 | { |
| 970 | struct skge_port *skge = netdev_priv(hw->dev[port]); |
| 971 | int i; |
| 972 | u32 r; |
| 973 | u16 id1; |
| 974 | u16 ctrl1, ctrl2, ctrl3, ctrl4, ctrl5; |
| 975 | |
| 976 | /* magic workaround patterns for Broadcom */ |
| 977 | static const struct { |
| 978 | u16 reg; |
| 979 | u16 val; |
| 980 | } A1hack[] = { |
| 981 | { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1104 }, |
| 982 | { 0x17, 0x0013 }, { 0x15, 0x0404 }, { 0x17, 0x8006 }, |
| 983 | { 0x15, 0x0132 }, { 0x17, 0x8006 }, { 0x15, 0x0232 }, |
| 984 | { 0x17, 0x800D }, { 0x15, 0x000F }, { 0x18, 0x0420 }, |
| 985 | }, C0hack[] = { |
| 986 | { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1204 }, |
| 987 | { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 }, |
| 988 | }; |
| 989 | |
| 990 | |
| 991 | /* initialize Rx, Tx and Link LED */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 992 | skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON); |
| 993 | skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 994 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 995 | skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START); |
| 996 | skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 997 | |
| 998 | /* Unreset the XMAC. */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 999 | 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] | 1000 | |
| 1001 | /* |
| 1002 | * Perform additional initialization for external PHYs, |
| 1003 | * namely for the 1000baseTX cards that use the XMAC's |
| 1004 | * GMII mode. |
| 1005 | */ |
| 1006 | spin_lock_bh(&hw->phy_lock); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1007 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1008 | /* External Phy Handling */ |
| 1009 | /* Take PHY out of reset. */ |
| 1010 | r = skge_read32(hw, B2_GP_IO); |
| 1011 | if (port == 0) |
| 1012 | r |= GP_DIR_0|GP_IO_0; |
| 1013 | else |
| 1014 | r |= GP_DIR_2|GP_IO_2; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1015 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1016 | skge_write32(hw, B2_GP_IO, r); |
| 1017 | skge_read32(hw, B2_GP_IO); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1018 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1019 | /* Enable GMII mode on the XMAC. */ |
| 1020 | xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1021 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1022 | id1 = xm_phy_read(hw, port, PHY_XMAC_ID1); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1023 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1024 | /* Optimize MDIO transfer by suppressing preamble. */ |
| 1025 | xm_write16(hw, port, XM_MMU_CMD, |
| 1026 | xm_read16(hw, port, XM_MMU_CMD) |
| 1027 | | XM_MMU_NO_PRE); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1028 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1029 | if (id1 == PHY_BCOM_ID1_C0) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1030 | /* |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1031 | * Workaround BCOM Errata for the C0 type. |
| 1032 | * Write magic patterns to reserved registers. |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1033 | */ |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1034 | for (i = 0; i < ARRAY_SIZE(C0hack); i++) |
| 1035 | xm_phy_write(hw, port, |
| 1036 | C0hack[i].reg, C0hack[i].val); |
| 1037 | |
| 1038 | } else if (id1 == PHY_BCOM_ID1_A1) { |
| 1039 | /* |
| 1040 | * Workaround BCOM Errata for the A1 type. |
| 1041 | * Write magic patterns to reserved registers. |
| 1042 | */ |
| 1043 | for (i = 0; i < ARRAY_SIZE(A1hack); i++) |
| 1044 | xm_phy_write(hw, port, |
| 1045 | A1hack[i].reg, A1hack[i].val); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1046 | } |
| 1047 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1048 | /* |
| 1049 | * Workaround BCOM Errata (#10523) for all BCom PHYs. |
| 1050 | * Disable Power Management after reset. |
| 1051 | */ |
| 1052 | r = xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL); |
| 1053 | xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r | PHY_B_AC_DIS_PM); |
| 1054 | |
| 1055 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1056 | /* Dummy read */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1057 | xm_read16(hw, port, XM_ISRC); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1058 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1059 | r = xm_read32(hw, port, XM_MODE); |
| 1060 | xm_write32(hw, port, XM_MODE, r|XM_MD_CSA); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1061 | |
| 1062 | /* We don't need the FCS appended to the packet. */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1063 | r = xm_read16(hw, port, XM_RX_CMD); |
| 1064 | xm_write16(hw, port, XM_RX_CMD, r | XM_RX_STRIP_FCS); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1065 | |
| 1066 | /* We want short frames padded to 60 bytes. */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1067 | r = xm_read16(hw, port, XM_TX_CMD); |
| 1068 | xm_write16(hw, port, XM_TX_CMD, r | XM_TX_AUTO_PAD); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1069 | |
| 1070 | /* |
| 1071 | * Enable the reception of all error frames. This is is |
| 1072 | * a necessary evil due to the design of the XMAC. The |
| 1073 | * XMAC's receive FIFO is only 8K in size, however jumbo |
| 1074 | * frames can be up to 9000 bytes in length. When bad |
| 1075 | * frame filtering is enabled, the XMAC's RX FIFO operates |
| 1076 | * in 'store and forward' mode. For this to work, the |
| 1077 | * entire frame has to fit into the FIFO, but that means |
| 1078 | * that jumbo frames larger than 8192 bytes will be |
| 1079 | * truncated. Disabling all bad frame filtering causes |
| 1080 | * the RX FIFO to operate in streaming mode, in which |
| 1081 | * case the XMAC will start transfering frames out of the |
| 1082 | * RX FIFO as soon as the FIFO threshold is reached. |
| 1083 | */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1084 | r = xm_read32(hw, port, XM_MODE); |
| 1085 | xm_write32(hw, port, XM_MODE, |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1086 | XM_MD_RX_CRCE|XM_MD_RX_LONG|XM_MD_RX_RUNT| |
| 1087 | XM_MD_RX_ERR|XM_MD_RX_IRLE); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1088 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1089 | xm_outaddr(hw, port, XM_SA, hw->dev[port]->dev_addr); |
| 1090 | xm_outaddr(hw, port, XM_EXM(0), hw->dev[port]->dev_addr); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1091 | |
| 1092 | /* |
| 1093 | * Bump up the transmit threshold. This helps hold off transmit |
| 1094 | * underruns when we're blasting traffic from both ports at once. |
| 1095 | */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1096 | xm_write16(hw, port, XM_TX_THR, 512); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1097 | |
| 1098 | /* Configure MAC arbiter */ |
| 1099 | skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR); |
| 1100 | |
| 1101 | /* configure timeout values */ |
| 1102 | skge_write8(hw, B3_MA_TOINI_RX1, 72); |
| 1103 | skge_write8(hw, B3_MA_TOINI_RX2, 72); |
| 1104 | skge_write8(hw, B3_MA_TOINI_TX1, 72); |
| 1105 | skge_write8(hw, B3_MA_TOINI_TX2, 72); |
| 1106 | |
| 1107 | skge_write8(hw, B3_MA_RCINI_RX1, 0); |
| 1108 | skge_write8(hw, B3_MA_RCINI_RX2, 0); |
| 1109 | skge_write8(hw, B3_MA_RCINI_TX1, 0); |
| 1110 | skge_write8(hw, B3_MA_RCINI_TX2, 0); |
| 1111 | |
| 1112 | /* Configure Rx MAC FIFO */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1113 | skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_CLR); |
| 1114 | skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT); |
| 1115 | 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] | 1116 | |
| 1117 | /* Configure Tx MAC FIFO */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1118 | skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_CLR); |
| 1119 | skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF); |
| 1120 | 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] | 1121 | |
| 1122 | if (hw->dev[port]->mtu > ETH_DATA_LEN) { |
| 1123 | /* Enable frame flushing if jumbo frames used */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1124 | skge_write16(hw, SK_REG(port,RX_MFF_CTRL1), MFF_ENA_FLUSH); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1125 | } else { |
| 1126 | /* enable timeout timers if normal frames */ |
| 1127 | skge_write16(hw, B3_PA_CTRL, |
| 1128 | port == 0 ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2); |
| 1129 | } |
| 1130 | |
| 1131 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1132 | r = xm_read16(hw, port, XM_RX_CMD); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1133 | if (hw->dev[port]->mtu > ETH_DATA_LEN) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1134 | xm_write16(hw, port, XM_RX_CMD, r | XM_RX_BIG_PK_OK); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1135 | else |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1136 | xm_write16(hw, port, XM_RX_CMD, r & ~(XM_RX_BIG_PK_OK)); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1137 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1138 | /* Broadcom phy initialization */ |
| 1139 | ctrl1 = PHY_CT_SP1000; |
| 1140 | ctrl2 = 0; |
| 1141 | ctrl3 = PHY_AN_CSMA; |
| 1142 | ctrl4 = PHY_B_PEC_EN_LTR; |
| 1143 | ctrl5 = PHY_B_AC_TX_TST; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1144 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1145 | if (skge->autoneg == AUTONEG_ENABLE) { |
| 1146 | /* |
| 1147 | * Workaround BCOM Errata #1 for the C5 type. |
| 1148 | * 1000Base-T Link Acquisition Failure in Slave Mode |
| 1149 | * Set Repeater/DTE bit 10 of the 1000Base-T Control Register |
| 1150 | */ |
| 1151 | ctrl2 |= PHY_B_1000C_RD; |
| 1152 | if (skge->advertising & ADVERTISED_1000baseT_Half) |
| 1153 | ctrl2 |= PHY_B_1000C_AHD; |
| 1154 | if (skge->advertising & ADVERTISED_1000baseT_Full) |
| 1155 | ctrl2 |= PHY_B_1000C_AFD; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1156 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1157 | /* Set Flow-control capabilities */ |
| 1158 | switch (skge->flow_control) { |
| 1159 | case FLOW_MODE_NONE: |
| 1160 | ctrl3 |= PHY_B_P_NO_PAUSE; |
| 1161 | break; |
| 1162 | case FLOW_MODE_LOC_SEND: |
| 1163 | ctrl3 |= PHY_B_P_ASYM_MD; |
| 1164 | break; |
| 1165 | case FLOW_MODE_SYMMETRIC: |
| 1166 | ctrl3 |= PHY_B_P_SYM_MD; |
| 1167 | break; |
| 1168 | case FLOW_MODE_REM_SEND: |
| 1169 | ctrl3 |= PHY_B_P_BOTH_MD; |
| 1170 | break; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1171 | } |
| 1172 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1173 | /* Restart Auto-negotiation */ |
| 1174 | ctrl1 |= PHY_CT_ANE | PHY_CT_RE_CFG; |
| 1175 | } else { |
| 1176 | if (skge->duplex == DUPLEX_FULL) |
| 1177 | ctrl1 |= PHY_CT_DUP_MD; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1178 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1179 | ctrl2 |= PHY_B_1000C_MSE; /* set it to Slave */ |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1180 | } |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1181 | |
| 1182 | xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, ctrl2); |
| 1183 | xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV, ctrl3); |
| 1184 | |
| 1185 | if (skge->netdev->mtu > ETH_DATA_LEN) { |
| 1186 | ctrl4 |= PHY_B_PEC_HIGH_LA; |
| 1187 | ctrl5 |= PHY_B_AC_LONG_PACK; |
| 1188 | |
| 1189 | xm_phy_write(hw, port,PHY_BCOM_AUX_CTRL, ctrl5); |
| 1190 | } |
| 1191 | |
| 1192 | xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ctrl4); |
| 1193 | xm_phy_write(hw, port, PHY_BCOM_CTRL, ctrl1); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1194 | spin_unlock_bh(&hw->phy_lock); |
| 1195 | |
| 1196 | /* Clear MIB counters */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1197 | xm_write16(hw, port, XM_STAT_CMD, |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1198 | XM_SC_CLR_RXC | XM_SC_CLR_TXC); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1199 | /* Clear two times according to Errata #3 */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1200 | xm_write16(hw, port, XM_STAT_CMD, |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1201 | XM_SC_CLR_RXC | XM_SC_CLR_TXC); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1202 | |
| 1203 | /* Start polling for link status */ |
| 1204 | mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ); |
| 1205 | } |
| 1206 | |
| 1207 | static void genesis_stop(struct skge_port *skge) |
| 1208 | { |
| 1209 | struct skge_hw *hw = skge->hw; |
| 1210 | int port = skge->port; |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1211 | u32 reg; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1212 | |
| 1213 | /* Clear Tx packet arbiter timeout IRQ */ |
| 1214 | skge_write16(hw, B3_PA_CTRL, |
| 1215 | port == 0 ? PA_CLR_TO_TX1 : PA_CLR_TO_TX2); |
| 1216 | |
| 1217 | /* |
| 1218 | * If the transfer stucks at the MAC the STOP command will not |
| 1219 | * terminate if we don't flush the XMAC's transmit FIFO ! |
| 1220 | */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1221 | xm_write32(hw, port, XM_MODE, |
| 1222 | xm_read32(hw, port, XM_MODE)|XM_MD_FTF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1223 | |
| 1224 | |
| 1225 | /* Reset the MAC */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1226 | 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] | 1227 | |
| 1228 | /* For external PHYs there must be special handling */ |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1229 | reg = skge_read32(hw, B2_GP_IO); |
| 1230 | if (port == 0) { |
| 1231 | reg |= GP_DIR_0; |
| 1232 | reg &= ~GP_IO_0; |
| 1233 | } else { |
| 1234 | reg |= GP_DIR_2; |
| 1235 | reg &= ~GP_IO_2; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1236 | } |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1237 | skge_write32(hw, B2_GP_IO, reg); |
| 1238 | skge_read32(hw, B2_GP_IO); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1239 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1240 | xm_write16(hw, port, XM_MMU_CMD, |
| 1241 | xm_read16(hw, port, XM_MMU_CMD) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1242 | & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX)); |
| 1243 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1244 | xm_read16(hw, port, XM_MMU_CMD); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | |
| 1248 | static void genesis_get_stats(struct skge_port *skge, u64 *data) |
| 1249 | { |
| 1250 | struct skge_hw *hw = skge->hw; |
| 1251 | int port = skge->port; |
| 1252 | int i; |
| 1253 | unsigned long timeout = jiffies + HZ; |
| 1254 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1255 | xm_write16(hw, port, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1256 | XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC); |
| 1257 | |
| 1258 | /* wait for update to complete */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1259 | while (xm_read16(hw, port, XM_STAT_CMD) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1260 | & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) { |
| 1261 | if (time_after(jiffies, timeout)) |
| 1262 | break; |
| 1263 | udelay(10); |
| 1264 | } |
| 1265 | |
| 1266 | /* special case for 64 bit octet counter */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1267 | data[0] = (u64) xm_read32(hw, port, XM_TXO_OK_HI) << 32 |
| 1268 | | xm_read32(hw, port, XM_TXO_OK_LO); |
| 1269 | data[1] = (u64) xm_read32(hw, port, XM_RXO_OK_HI) << 32 |
| 1270 | | xm_read32(hw, port, XM_RXO_OK_LO); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1271 | |
| 1272 | for (i = 2; i < ARRAY_SIZE(skge_stats); i++) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1273 | data[i] = xm_read32(hw, port, skge_stats[i].xmac_offset); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | static void genesis_mac_intr(struct skge_hw *hw, int port) |
| 1277 | { |
| 1278 | struct skge_port *skge = netdev_priv(hw->dev[port]); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1279 | u16 status = xm_read16(hw, port, XM_ISRC); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1280 | |
| 1281 | pr_debug("genesis_intr status %x\n", status); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1282 | |
| 1283 | if (status & XM_IS_TXF_UR) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1284 | xm_write32(hw, port, XM_MODE, XM_MD_FTF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1285 | ++skge->net_stats.tx_fifo_errors; |
| 1286 | } |
| 1287 | if (status & XM_IS_RXF_OV) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1288 | xm_write32(hw, port, XM_MODE, XM_MD_FRF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1289 | ++skge->net_stats.rx_fifo_errors; |
| 1290 | } |
| 1291 | } |
| 1292 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1293 | static void 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] | 1294 | { |
| 1295 | int i; |
| 1296 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1297 | gma_write16(hw, port, GM_SMI_DATA, val); |
| 1298 | gma_write16(hw, port, GM_SMI_CTRL, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1299 | GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg)); |
| 1300 | for (i = 0; i < PHY_RETRIES; i++) { |
| 1301 | udelay(1); |
| 1302 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1303 | if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY)) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1304 | break; |
| 1305 | } |
| 1306 | } |
| 1307 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1308 | static u16 gm_phy_read(struct skge_hw *hw, int port, u16 reg) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1309 | { |
| 1310 | int i; |
| 1311 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1312 | gma_write16(hw, port, GM_SMI_CTRL, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1313 | GM_SMI_CT_PHY_AD(hw->phy_addr) |
| 1314 | | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD); |
| 1315 | |
| 1316 | for (i = 0; i < PHY_RETRIES; i++) { |
| 1317 | udelay(1); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1318 | if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1319 | goto ready; |
| 1320 | } |
| 1321 | |
| 1322 | printk(KERN_WARNING PFX "%s: phy read timeout\n", |
| 1323 | hw->dev[port]->name); |
| 1324 | return 0; |
| 1325 | ready: |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1326 | return gma_read16(hw, port, GM_SMI_DATA); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | static void genesis_link_down(struct skge_port *skge) |
| 1330 | { |
| 1331 | struct skge_hw *hw = skge->hw; |
| 1332 | int port = skge->port; |
| 1333 | |
| 1334 | pr_debug("genesis_link_down\n"); |
| 1335 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1336 | xm_write16(hw, port, XM_MMU_CMD, |
| 1337 | xm_read16(hw, port, XM_MMU_CMD) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1338 | & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX)); |
| 1339 | |
| 1340 | /* dummy read to ensure writing */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1341 | (void) xm_read16(hw, port, XM_MMU_CMD); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1342 | |
| 1343 | skge_link_down(skge); |
| 1344 | } |
| 1345 | |
| 1346 | static void genesis_link_up(struct skge_port *skge) |
| 1347 | { |
| 1348 | struct skge_hw *hw = skge->hw; |
| 1349 | int port = skge->port; |
| 1350 | u16 cmd; |
| 1351 | u32 mode, msk; |
| 1352 | |
| 1353 | pr_debug("genesis_link_up\n"); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1354 | cmd = xm_read16(hw, port, XM_MMU_CMD); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1355 | |
| 1356 | /* |
| 1357 | * enabling pause frame reception is required for 1000BT |
| 1358 | * because the XMAC is not reset if the link is going down |
| 1359 | */ |
| 1360 | if (skge->flow_control == FLOW_MODE_NONE || |
| 1361 | skge->flow_control == FLOW_MODE_LOC_SEND) |
| 1362 | cmd |= XM_MMU_IGN_PF; |
| 1363 | else |
| 1364 | /* Enable Pause Frame Reception */ |
| 1365 | cmd &= ~XM_MMU_IGN_PF; |
| 1366 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1367 | xm_write16(hw, port, XM_MMU_CMD, cmd); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1368 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1369 | mode = xm_read32(hw, port, XM_MODE); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1370 | if (skge->flow_control == FLOW_MODE_SYMMETRIC || |
| 1371 | skge->flow_control == FLOW_MODE_LOC_SEND) { |
| 1372 | /* |
| 1373 | * Configure Pause Frame Generation |
| 1374 | * Use internal and external Pause Frame Generation. |
| 1375 | * Sending pause frames is edge triggered. |
| 1376 | * Send a Pause frame with the maximum pause time if |
| 1377 | * internal oder external FIFO full condition occurs. |
| 1378 | * Send a zero pause time frame to re-start transmission. |
| 1379 | */ |
| 1380 | /* XM_PAUSE_DA = '010000C28001' (default) */ |
| 1381 | /* XM_MAC_PTIME = 0xffff (maximum) */ |
| 1382 | /* remember this value is defined in big endian (!) */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1383 | xm_write16(hw, port, XM_MAC_PTIME, 0xffff); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1384 | |
| 1385 | mode |= XM_PAUSE_MODE; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1386 | skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1387 | } else { |
| 1388 | /* |
| 1389 | * disable pause frame generation is required for 1000BT |
| 1390 | * because the XMAC is not reset if the link is going down |
| 1391 | */ |
| 1392 | /* Disable Pause Mode in Mode Register */ |
| 1393 | mode &= ~XM_PAUSE_MODE; |
| 1394 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1395 | skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1396 | } |
| 1397 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1398 | xm_write32(hw, port, XM_MODE, mode); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1399 | |
| 1400 | msk = XM_DEF_MSK; |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1401 | /* disable GP0 interrupt bit for external Phy */ |
| 1402 | msk |= XM_IS_INP_ASS; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1403 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1404 | xm_write16(hw, port, XM_IMSK, msk); |
| 1405 | xm_read16(hw, port, XM_ISRC); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1406 | |
| 1407 | /* get MMU Command Reg. */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1408 | cmd = xm_read16(hw, port, XM_MMU_CMD); |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1409 | if (skge->duplex == DUPLEX_FULL) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1410 | cmd |= XM_MMU_GMII_FD; |
| 1411 | |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1412 | /* |
| 1413 | * Workaround BCOM Errata (#10523) for all BCom Phys |
| 1414 | * Enable Power Management after link up |
| 1415 | */ |
| 1416 | xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, |
| 1417 | xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL) |
| 1418 | & ~PHY_B_AC_DIS_PM); |
| 1419 | xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1420 | |
| 1421 | /* enable Rx/Tx */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1422 | xm_write16(hw, port, XM_MMU_CMD, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1423 | cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX); |
| 1424 | skge_link_up(skge); |
| 1425 | } |
| 1426 | |
| 1427 | |
| 1428 | static void genesis_bcom_intr(struct skge_port *skge) |
| 1429 | { |
| 1430 | struct skge_hw *hw = skge->hw; |
| 1431 | int port = skge->port; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1432 | u16 stat = xm_phy_read(hw, port, PHY_BCOM_INT_STAT); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1433 | |
| 1434 | pr_debug("genesis_bcom intr stat=%x\n", stat); |
| 1435 | |
| 1436 | /* Workaround BCom Errata: |
| 1437 | * enable and disable loopback mode if "NO HCD" occurs. |
| 1438 | */ |
| 1439 | if (stat & PHY_B_IS_NO_HDCL) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1440 | u16 ctrl = xm_phy_read(hw, port, PHY_BCOM_CTRL); |
| 1441 | xm_phy_write(hw, port, PHY_BCOM_CTRL, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1442 | ctrl | PHY_CT_LOOP); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1443 | xm_phy_write(hw, port, PHY_BCOM_CTRL, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1444 | ctrl & ~PHY_CT_LOOP); |
| 1445 | } |
| 1446 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1447 | stat = xm_phy_read(hw, port, PHY_BCOM_STAT); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1448 | if (stat & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE)) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1449 | u16 aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1450 | if ( !(aux & PHY_B_AS_LS) && netif_carrier_ok(skge->netdev)) |
| 1451 | genesis_link_down(skge); |
| 1452 | |
| 1453 | else if (stat & PHY_B_IS_LST_CHANGE) { |
| 1454 | if (aux & PHY_B_AS_AN_C) { |
| 1455 | switch (aux & PHY_B_AS_AN_RES_MSK) { |
| 1456 | case PHY_B_RES_1000FD: |
| 1457 | skge->duplex = DUPLEX_FULL; |
| 1458 | break; |
| 1459 | case PHY_B_RES_1000HD: |
| 1460 | skge->duplex = DUPLEX_HALF; |
| 1461 | break; |
| 1462 | } |
| 1463 | |
| 1464 | switch (aux & PHY_B_AS_PAUSE_MSK) { |
| 1465 | case PHY_B_AS_PAUSE_MSK: |
| 1466 | skge->flow_control = FLOW_MODE_SYMMETRIC; |
| 1467 | break; |
| 1468 | case PHY_B_AS_PRR: |
| 1469 | skge->flow_control = FLOW_MODE_REM_SEND; |
| 1470 | break; |
| 1471 | case PHY_B_AS_PRT: |
| 1472 | skge->flow_control = FLOW_MODE_LOC_SEND; |
| 1473 | break; |
| 1474 | default: |
| 1475 | skge->flow_control = FLOW_MODE_NONE; |
| 1476 | } |
| 1477 | skge->speed = SPEED_1000; |
| 1478 | } |
| 1479 | genesis_link_up(skge); |
| 1480 | } |
| 1481 | else |
| 1482 | mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ); |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | /* Perodic poll of phy status to check for link transistion */ |
| 1487 | static void skge_link_timer(unsigned long __arg) |
| 1488 | { |
| 1489 | struct skge_port *skge = (struct skge_port *) __arg; |
| 1490 | struct skge_hw *hw = skge->hw; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1491 | |
| 1492 | if (hw->chip_id != CHIP_ID_GENESIS || !netif_running(skge->netdev)) |
| 1493 | return; |
| 1494 | |
| 1495 | spin_lock_bh(&hw->phy_lock); |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 1496 | genesis_bcom_intr(skge); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1497 | spin_unlock_bh(&hw->phy_lock); |
| 1498 | } |
| 1499 | |
| 1500 | /* Marvell Phy Initailization */ |
| 1501 | static void yukon_init(struct skge_hw *hw, int port) |
| 1502 | { |
| 1503 | struct skge_port *skge = netdev_priv(hw->dev[port]); |
| 1504 | u16 ctrl, ct1000, adv; |
| 1505 | u16 ledctrl, ledover; |
| 1506 | |
| 1507 | pr_debug("yukon_init\n"); |
| 1508 | if (skge->autoneg == AUTONEG_ENABLE) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1509 | u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1510 | |
| 1511 | ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK | |
| 1512 | PHY_M_EC_MAC_S_MSK); |
| 1513 | ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ); |
| 1514 | |
Stephen Hemminger | c506a50 | 2005-06-27 11:33:09 -0700 | [diff] [blame] | 1515 | 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] | 1516 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1517 | gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1518 | } |
| 1519 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1520 | ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1521 | if (skge->autoneg == AUTONEG_DISABLE) |
| 1522 | ctrl &= ~PHY_CT_ANE; |
| 1523 | |
| 1524 | ctrl |= PHY_CT_RESET; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1525 | gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1526 | |
| 1527 | ctrl = 0; |
| 1528 | ct1000 = 0; |
Stephen Hemminger | b18f209 | 2005-06-27 11:33:08 -0700 | [diff] [blame] | 1529 | adv = PHY_AN_CSMA; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1530 | |
| 1531 | if (skge->autoneg == AUTONEG_ENABLE) { |
| 1532 | if (iscopper(hw)) { |
| 1533 | if (skge->advertising & ADVERTISED_1000baseT_Full) |
| 1534 | ct1000 |= PHY_M_1000C_AFD; |
| 1535 | if (skge->advertising & ADVERTISED_1000baseT_Half) |
| 1536 | ct1000 |= PHY_M_1000C_AHD; |
| 1537 | if (skge->advertising & ADVERTISED_100baseT_Full) |
| 1538 | adv |= PHY_M_AN_100_FD; |
| 1539 | if (skge->advertising & ADVERTISED_100baseT_Half) |
| 1540 | adv |= PHY_M_AN_100_HD; |
| 1541 | if (skge->advertising & ADVERTISED_10baseT_Full) |
| 1542 | adv |= PHY_M_AN_10_FD; |
| 1543 | if (skge->advertising & ADVERTISED_10baseT_Half) |
| 1544 | adv |= PHY_M_AN_10_HD; |
| 1545 | |
| 1546 | /* Set Flow-control capabilities */ |
| 1547 | switch (skge->flow_control) { |
| 1548 | case FLOW_MODE_NONE: |
| 1549 | adv |= PHY_B_P_NO_PAUSE; |
| 1550 | break; |
| 1551 | case FLOW_MODE_LOC_SEND: |
| 1552 | adv |= PHY_B_P_ASYM_MD; |
| 1553 | break; |
| 1554 | case FLOW_MODE_SYMMETRIC: |
| 1555 | adv |= PHY_B_P_SYM_MD; |
| 1556 | break; |
| 1557 | case FLOW_MODE_REM_SEND: |
| 1558 | adv |= PHY_B_P_BOTH_MD; |
| 1559 | break; |
| 1560 | } |
| 1561 | } else { /* special defines for FIBER (88E1011S only) */ |
| 1562 | adv |= PHY_M_AN_1000X_AHD | PHY_M_AN_1000X_AFD; |
| 1563 | |
| 1564 | /* Set Flow-control capabilities */ |
| 1565 | switch (skge->flow_control) { |
| 1566 | case FLOW_MODE_NONE: |
| 1567 | adv |= PHY_M_P_NO_PAUSE_X; |
| 1568 | break; |
| 1569 | case FLOW_MODE_LOC_SEND: |
| 1570 | adv |= PHY_M_P_ASYM_MD_X; |
| 1571 | break; |
| 1572 | case FLOW_MODE_SYMMETRIC: |
| 1573 | adv |= PHY_M_P_SYM_MD_X; |
| 1574 | break; |
| 1575 | case FLOW_MODE_REM_SEND: |
| 1576 | adv |= PHY_M_P_BOTH_MD_X; |
| 1577 | break; |
| 1578 | } |
| 1579 | } |
| 1580 | /* Restart Auto-negotiation */ |
| 1581 | ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG; |
| 1582 | } else { |
| 1583 | /* forced speed/duplex settings */ |
| 1584 | ct1000 = PHY_M_1000C_MSE; |
| 1585 | |
| 1586 | if (skge->duplex == DUPLEX_FULL) |
| 1587 | ctrl |= PHY_CT_DUP_MD; |
| 1588 | |
| 1589 | switch (skge->speed) { |
| 1590 | case SPEED_1000: |
| 1591 | ctrl |= PHY_CT_SP1000; |
| 1592 | break; |
| 1593 | case SPEED_100: |
| 1594 | ctrl |= PHY_CT_SP100; |
| 1595 | break; |
| 1596 | } |
| 1597 | |
| 1598 | ctrl |= PHY_CT_RESET; |
| 1599 | } |
| 1600 | |
Stephen Hemminger | c506a50 | 2005-06-27 11:33:09 -0700 | [diff] [blame] | 1601 | gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1602 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1603 | gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv); |
| 1604 | gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1605 | |
| 1606 | /* Setup Phy LED's */ |
| 1607 | ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS); |
| 1608 | ledover = 0; |
| 1609 | |
Stephen Hemminger | c506a50 | 2005-06-27 11:33:09 -0700 | [diff] [blame] | 1610 | ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1611 | |
Stephen Hemminger | c506a50 | 2005-06-27 11:33:09 -0700 | [diff] [blame] | 1612 | /* turn off the Rx LED (LED_RX) */ |
| 1613 | ledover |= PHY_M_LED_MO_RX(MO_LED_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1614 | |
| 1615 | /* disable blink mode (LED_DUPLEX) on collisions */ |
| 1616 | ctrl |= PHY_M_LEDC_DP_CTRL; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1617 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1618 | |
| 1619 | if (skge->autoneg == AUTONEG_DISABLE || skge->speed == SPEED_100) { |
| 1620 | /* turn on 100 Mbps LED (LED_LINK100) */ |
| 1621 | ledover |= PHY_M_LED_MO_100(MO_LED_ON); |
| 1622 | } |
| 1623 | |
| 1624 | if (ledover) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1625 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1626 | |
| 1627 | /* Enable phy interrupt on autonegotiation complete (or link up) */ |
| 1628 | if (skge->autoneg == AUTONEG_ENABLE) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1629 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1630 | else |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1631 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | static void yukon_reset(struct skge_hw *hw, int port) |
| 1635 | { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1636 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */ |
| 1637 | gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */ |
| 1638 | gma_write16(hw, port, GM_MC_ADDR_H2, 0); |
| 1639 | gma_write16(hw, port, GM_MC_ADDR_H3, 0); |
| 1640 | gma_write16(hw, port, GM_MC_ADDR_H4, 0); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1641 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1642 | gma_write16(hw, port, GM_RX_CTRL, |
| 1643 | gma_read16(hw, port, GM_RX_CTRL) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1644 | | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); |
| 1645 | } |
| 1646 | |
| 1647 | static void yukon_mac_init(struct skge_hw *hw, int port) |
| 1648 | { |
| 1649 | struct skge_port *skge = netdev_priv(hw->dev[port]); |
| 1650 | int i; |
| 1651 | u32 reg; |
| 1652 | const u8 *addr = hw->dev[port]->dev_addr; |
| 1653 | |
| 1654 | /* WA code for COMA mode -- set PHY reset */ |
| 1655 | if (hw->chip_id == CHIP_ID_YUKON_LITE && |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 1656 | hw->chip_rev == CHIP_REV_YU_LITE_A3) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1657 | skge_write32(hw, B2_GP_IO, |
| 1658 | (skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9)); |
| 1659 | |
| 1660 | /* hard reset */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1661 | skge_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); |
| 1662 | skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1663 | |
| 1664 | /* WA code for COMA mode -- clear PHY reset */ |
| 1665 | if (hw->chip_id == CHIP_ID_YUKON_LITE && |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 1666 | hw->chip_rev == CHIP_REV_YU_LITE_A3) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1667 | skge_write32(hw, B2_GP_IO, |
| 1668 | (skge_read32(hw, B2_GP_IO) | GP_DIR_9) |
| 1669 | & ~GP_IO_9); |
| 1670 | |
| 1671 | /* Set hardware config mode */ |
| 1672 | reg = GPC_INT_POL_HI | GPC_DIS_FC | GPC_DIS_SLEEP | |
| 1673 | GPC_ENA_XC | GPC_ANEG_ADV_ALL_M | GPC_ENA_PAUSE; |
| 1674 | reg |= iscopper(hw) ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB; |
| 1675 | |
| 1676 | /* Clear GMC reset */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1677 | skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_SET); |
| 1678 | skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_CLR); |
| 1679 | skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1680 | if (skge->autoneg == AUTONEG_DISABLE) { |
| 1681 | reg = GM_GPCR_AU_ALL_DIS; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1682 | gma_write16(hw, port, GM_GP_CTRL, |
| 1683 | gma_read16(hw, port, GM_GP_CTRL) | reg); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1684 | |
| 1685 | switch (skge->speed) { |
| 1686 | case SPEED_1000: |
| 1687 | reg |= GM_GPCR_SPEED_1000; |
| 1688 | /* fallthru */ |
| 1689 | case SPEED_100: |
| 1690 | reg |= GM_GPCR_SPEED_100; |
| 1691 | } |
| 1692 | |
| 1693 | if (skge->duplex == DUPLEX_FULL) |
| 1694 | reg |= GM_GPCR_DUP_FULL; |
| 1695 | } else |
| 1696 | reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL; |
| 1697 | switch (skge->flow_control) { |
| 1698 | case FLOW_MODE_NONE: |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1699 | skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1700 | reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; |
| 1701 | break; |
| 1702 | case FLOW_MODE_LOC_SEND: |
| 1703 | /* disable Rx flow-control */ |
| 1704 | reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; |
| 1705 | } |
| 1706 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1707 | gma_write16(hw, port, GM_GP_CTRL, reg); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1708 | skge_read16(hw, GMAC_IRQ_SRC); |
| 1709 | |
| 1710 | spin_lock_bh(&hw->phy_lock); |
| 1711 | yukon_init(hw, port); |
| 1712 | spin_unlock_bh(&hw->phy_lock); |
| 1713 | |
| 1714 | /* MIB clear */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1715 | reg = gma_read16(hw, port, GM_PHY_ADDR); |
| 1716 | gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1717 | |
| 1718 | for (i = 0; i < GM_MIB_CNT_SIZE; i++) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1719 | gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i); |
| 1720 | gma_write16(hw, port, GM_PHY_ADDR, reg); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1721 | |
| 1722 | /* transmit control */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1723 | 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] | 1724 | |
| 1725 | /* receive control reg: unicast + multicast + no FCS */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1726 | gma_write16(hw, port, GM_RX_CTRL, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1727 | GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA); |
| 1728 | |
| 1729 | /* transmit flow control */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1730 | gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1731 | |
| 1732 | /* transmit parameter */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1733 | gma_write16(hw, port, GM_TX_PARAM, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1734 | TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) | |
| 1735 | TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) | |
| 1736 | TX_IPG_JAM_DATA(TX_IPG_JAM_DEF)); |
| 1737 | |
| 1738 | /* serial mode register */ |
| 1739 | reg = GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF); |
| 1740 | if (hw->dev[port]->mtu > 1500) |
| 1741 | reg |= GM_SMOD_JUMBO_ENA; |
| 1742 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1743 | gma_write16(hw, port, GM_SERIAL_MODE, reg); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1744 | |
| 1745 | /* physical address: used for pause frames */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1746 | gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1747 | /* virtual address for data */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1748 | gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1749 | |
| 1750 | /* enable interrupt mask for counter overflows */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1751 | gma_write16(hw, port, GM_TX_IRQ_MSK, 0); |
| 1752 | gma_write16(hw, port, GM_RX_IRQ_MSK, 0); |
| 1753 | gma_write16(hw, port, GM_TR_IRQ_MSK, 0); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1754 | |
| 1755 | /* Initialize Mac Fifo */ |
| 1756 | |
| 1757 | /* Configure Rx MAC FIFO */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1758 | 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] | 1759 | reg = GMF_OPER_ON | GMF_RX_F_FL_ON; |
| 1760 | if (hw->chip_id == CHIP_ID_YUKON_LITE && |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 1761 | hw->chip_rev == CHIP_REV_YU_LITE_A3) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1762 | reg &= ~GMF_RX_F_FL_ON; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1763 | skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); |
| 1764 | skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg); |
| 1765 | skge_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1766 | |
| 1767 | /* Configure Tx MAC FIFO */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1768 | skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR); |
| 1769 | 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] | 1770 | } |
| 1771 | |
| 1772 | static void yukon_stop(struct skge_port *skge) |
| 1773 | { |
| 1774 | struct skge_hw *hw = skge->hw; |
| 1775 | int port = skge->port; |
| 1776 | |
| 1777 | if (hw->chip_id == CHIP_ID_YUKON_LITE && |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 1778 | hw->chip_rev == CHIP_REV_YU_LITE_A3) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1779 | skge_write32(hw, B2_GP_IO, |
| 1780 | skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9); |
| 1781 | } |
| 1782 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1783 | gma_write16(hw, port, GM_GP_CTRL, |
| 1784 | gma_read16(hw, port, GM_GP_CTRL) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1785 | & ~(GM_GPCR_RX_ENA|GM_GPCR_RX_ENA)); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1786 | gma_read16(hw, port, GM_GP_CTRL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1787 | |
| 1788 | /* set GPHY Control reset */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1789 | gma_write32(hw, port, GPHY_CTRL, GPC_RST_SET); |
| 1790 | gma_write32(hw, port, GMAC_CTRL, GMC_RST_SET); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | static void yukon_get_stats(struct skge_port *skge, u64 *data) |
| 1794 | { |
| 1795 | struct skge_hw *hw = skge->hw; |
| 1796 | int port = skge->port; |
| 1797 | int i; |
| 1798 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1799 | data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32 |
| 1800 | | gma_read32(hw, port, GM_TXO_OK_LO); |
| 1801 | data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32 |
| 1802 | | gma_read32(hw, port, GM_RXO_OK_LO); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1803 | |
| 1804 | for (i = 2; i < ARRAY_SIZE(skge_stats); i++) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1805 | data[i] = gma_read32(hw, port, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1806 | skge_stats[i].gma_offset); |
| 1807 | } |
| 1808 | |
| 1809 | static void yukon_mac_intr(struct skge_hw *hw, int port) |
| 1810 | { |
| 1811 | struct skge_port *skge = netdev_priv(hw->dev[port]); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1812 | u8 status = skge_read8(hw, SK_REG(port, GMAC_IRQ_SRC)); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1813 | |
| 1814 | pr_debug("yukon_intr status %x\n", status); |
| 1815 | if (status & GM_IS_RX_FF_OR) { |
| 1816 | ++skge->net_stats.rx_fifo_errors; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1817 | gma_write8(hw, port, RX_GMF_CTRL_T, GMF_CLI_RX_FO); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1818 | } |
| 1819 | if (status & GM_IS_TX_FF_UR) { |
| 1820 | ++skge->net_stats.tx_fifo_errors; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1821 | gma_write8(hw, port, TX_GMF_CTRL_T, GMF_CLI_TX_FU); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | } |
| 1825 | |
| 1826 | static u16 yukon_speed(const struct skge_hw *hw, u16 aux) |
| 1827 | { |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 1828 | switch (aux & PHY_M_PS_SPEED_MSK) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1829 | case PHY_M_PS_SPEED_1000: |
| 1830 | return SPEED_1000; |
| 1831 | case PHY_M_PS_SPEED_100: |
| 1832 | return SPEED_100; |
| 1833 | default: |
| 1834 | return SPEED_10; |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | static void yukon_link_up(struct skge_port *skge) |
| 1839 | { |
| 1840 | struct skge_hw *hw = skge->hw; |
| 1841 | int port = skge->port; |
| 1842 | u16 reg; |
| 1843 | |
| 1844 | pr_debug("yukon_link_up\n"); |
| 1845 | |
| 1846 | /* Enable Transmit FIFO Underrun */ |
| 1847 | skge_write8(hw, GMAC_IRQ_MSK, GMAC_DEF_MSK); |
| 1848 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1849 | reg = gma_read16(hw, port, GM_GP_CTRL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1850 | if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE) |
| 1851 | reg |= GM_GPCR_DUP_FULL; |
| 1852 | |
| 1853 | /* enable Rx/Tx */ |
| 1854 | reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA; |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1855 | gma_write16(hw, port, GM_GP_CTRL, reg); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1856 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1857 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1858 | skge_link_up(skge); |
| 1859 | } |
| 1860 | |
| 1861 | static void yukon_link_down(struct skge_port *skge) |
| 1862 | { |
| 1863 | struct skge_hw *hw = skge->hw; |
| 1864 | int port = skge->port; |
| 1865 | |
| 1866 | pr_debug("yukon_link_down\n"); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1867 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0); |
| 1868 | gm_phy_write(hw, port, GM_GP_CTRL, |
| 1869 | gm_phy_read(hw, port, GM_GP_CTRL) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1870 | & ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA)); |
| 1871 | |
Stephen Hemminger | c506a50 | 2005-06-27 11:33:09 -0700 | [diff] [blame] | 1872 | if (skge->flow_control == FLOW_MODE_REM_SEND) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1873 | /* restore Asymmetric Pause bit */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1874 | gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, |
| 1875 | gm_phy_read(hw, port, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1876 | PHY_MARV_AUNE_ADV) |
| 1877 | | PHY_M_AN_ASP); |
| 1878 | |
| 1879 | } |
| 1880 | |
| 1881 | yukon_reset(hw, port); |
| 1882 | skge_link_down(skge); |
| 1883 | |
| 1884 | yukon_init(hw, port); |
| 1885 | } |
| 1886 | |
| 1887 | static void yukon_phy_intr(struct skge_port *skge) |
| 1888 | { |
| 1889 | struct skge_hw *hw = skge->hw; |
| 1890 | int port = skge->port; |
| 1891 | const char *reason = NULL; |
| 1892 | u16 istatus, phystat; |
| 1893 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1894 | istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT); |
| 1895 | phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1896 | pr_debug("yukon phy intr istat=%x phy_stat=%x\n", istatus, phystat); |
| 1897 | |
| 1898 | if (istatus & PHY_M_IS_AN_COMPL) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1899 | if (gm_phy_read(hw, port, PHY_MARV_AUNE_LP) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1900 | & PHY_M_AN_RF) { |
| 1901 | reason = "remote fault"; |
| 1902 | goto failed; |
| 1903 | } |
| 1904 | |
Stephen Hemminger | c506a50 | 2005-06-27 11:33:09 -0700 | [diff] [blame] | 1905 | 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] | 1906 | reason = "master/slave fault"; |
| 1907 | goto failed; |
| 1908 | } |
| 1909 | |
| 1910 | if (!(phystat & PHY_M_PS_SPDUP_RES)) { |
| 1911 | reason = "speed/duplex"; |
| 1912 | goto failed; |
| 1913 | } |
| 1914 | |
| 1915 | skge->duplex = (phystat & PHY_M_PS_FULL_DUP) |
| 1916 | ? DUPLEX_FULL : DUPLEX_HALF; |
| 1917 | skge->speed = yukon_speed(hw, phystat); |
| 1918 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1919 | /* We are using IEEE 802.3z/D5.0 Table 37-4 */ |
| 1920 | switch (phystat & PHY_M_PS_PAUSE_MSK) { |
| 1921 | case PHY_M_PS_PAUSE_MSK: |
| 1922 | skge->flow_control = FLOW_MODE_SYMMETRIC; |
| 1923 | break; |
| 1924 | case PHY_M_PS_RX_P_EN: |
| 1925 | skge->flow_control = FLOW_MODE_REM_SEND; |
| 1926 | break; |
| 1927 | case PHY_M_PS_TX_P_EN: |
| 1928 | skge->flow_control = FLOW_MODE_LOC_SEND; |
| 1929 | break; |
| 1930 | default: |
| 1931 | skge->flow_control = FLOW_MODE_NONE; |
| 1932 | } |
| 1933 | |
| 1934 | if (skge->flow_control == FLOW_MODE_NONE || |
| 1935 | (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF)) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1936 | skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1937 | else |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 1938 | skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 1939 | yukon_link_up(skge); |
| 1940 | return; |
| 1941 | } |
| 1942 | |
| 1943 | if (istatus & PHY_M_IS_LSP_CHANGE) |
| 1944 | skge->speed = yukon_speed(hw, phystat); |
| 1945 | |
| 1946 | if (istatus & PHY_M_IS_DUP_CHANGE) |
| 1947 | skge->duplex = (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; |
| 1948 | if (istatus & PHY_M_IS_LST_CHANGE) { |
| 1949 | if (phystat & PHY_M_PS_LINK_UP) |
| 1950 | yukon_link_up(skge); |
| 1951 | else |
| 1952 | yukon_link_down(skge); |
| 1953 | } |
| 1954 | return; |
| 1955 | failed: |
| 1956 | printk(KERN_ERR PFX "%s: autonegotiation failed (%s)\n", |
| 1957 | skge->netdev->name, reason); |
| 1958 | |
| 1959 | /* XXX restart autonegotiation? */ |
| 1960 | } |
| 1961 | |
| 1962 | static void skge_ramset(struct skge_hw *hw, u16 q, u32 start, size_t len) |
| 1963 | { |
| 1964 | u32 end; |
| 1965 | |
| 1966 | start /= 8; |
| 1967 | len /= 8; |
| 1968 | end = start + len - 1; |
| 1969 | |
| 1970 | skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR); |
| 1971 | skge_write32(hw, RB_ADDR(q, RB_START), start); |
| 1972 | skge_write32(hw, RB_ADDR(q, RB_WP), start); |
| 1973 | skge_write32(hw, RB_ADDR(q, RB_RP), start); |
| 1974 | skge_write32(hw, RB_ADDR(q, RB_END), end); |
| 1975 | |
| 1976 | if (q == Q_R1 || q == Q_R2) { |
| 1977 | /* Set thresholds on receive queue's */ |
| 1978 | skge_write32(hw, RB_ADDR(q, RB_RX_UTPP), |
| 1979 | start + (2*len)/3); |
| 1980 | skge_write32(hw, RB_ADDR(q, RB_RX_LTPP), |
| 1981 | start + (len/3)); |
| 1982 | } else { |
| 1983 | /* Enable store & forward on Tx queue's because |
| 1984 | * Tx FIFO is only 4K on Genesis and 1K on Yukon |
| 1985 | */ |
| 1986 | skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD); |
| 1987 | } |
| 1988 | |
| 1989 | skge_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD); |
| 1990 | } |
| 1991 | |
| 1992 | /* Setup Bus Memory Interface */ |
| 1993 | static void skge_qset(struct skge_port *skge, u16 q, |
| 1994 | const struct skge_element *e) |
| 1995 | { |
| 1996 | struct skge_hw *hw = skge->hw; |
| 1997 | u32 watermark = 0x600; |
| 1998 | u64 base = skge->dma + (e->desc - skge->mem); |
| 1999 | |
| 2000 | /* optimization to reduce window on 32bit/33mhz */ |
| 2001 | if ((skge_read16(hw, B0_CTST) & (CS_BUS_CLOCK | CS_BUS_SLOT_SZ)) == 0) |
| 2002 | watermark /= 2; |
| 2003 | |
| 2004 | skge_write32(hw, Q_ADDR(q, Q_CSR), CSR_CLR_RESET); |
| 2005 | skge_write32(hw, Q_ADDR(q, Q_F), watermark); |
| 2006 | skge_write32(hw, Q_ADDR(q, Q_DA_H), (u32)(base >> 32)); |
| 2007 | skge_write32(hw, Q_ADDR(q, Q_DA_L), (u32)base); |
| 2008 | } |
| 2009 | |
| 2010 | static int skge_up(struct net_device *dev) |
| 2011 | { |
| 2012 | struct skge_port *skge = netdev_priv(dev); |
| 2013 | struct skge_hw *hw = skge->hw; |
| 2014 | int port = skge->port; |
| 2015 | u32 chunk, ram_addr; |
| 2016 | size_t rx_size, tx_size; |
| 2017 | int err; |
| 2018 | |
| 2019 | if (netif_msg_ifup(skge)) |
| 2020 | printk(KERN_INFO PFX "%s: enabling interface\n", dev->name); |
| 2021 | |
| 2022 | rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc); |
| 2023 | tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc); |
| 2024 | skge->mem_size = tx_size + rx_size; |
| 2025 | skge->mem = pci_alloc_consistent(hw->pdev, skge->mem_size, &skge->dma); |
| 2026 | if (!skge->mem) |
| 2027 | return -ENOMEM; |
| 2028 | |
| 2029 | memset(skge->mem, 0, skge->mem_size); |
| 2030 | |
| 2031 | if ((err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma))) |
| 2032 | goto free_pci_mem; |
| 2033 | |
| 2034 | if (skge_rx_fill(skge)) |
| 2035 | goto free_rx_ring; |
| 2036 | |
| 2037 | if ((err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size, |
| 2038 | skge->dma + rx_size))) |
| 2039 | goto free_rx_ring; |
| 2040 | |
| 2041 | skge->tx_avail = skge->tx_ring.count - 1; |
| 2042 | |
| 2043 | /* Initialze MAC */ |
| 2044 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 2045 | genesis_mac_init(hw, port); |
| 2046 | else |
| 2047 | yukon_mac_init(hw, port); |
| 2048 | |
| 2049 | /* Configure RAMbuffers */ |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 2050 | chunk = hw->ram_size / ((hw->ports + 1)*2); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2051 | ram_addr = hw->ram_offset + 2 * chunk * port; |
| 2052 | |
| 2053 | skge_ramset(hw, rxqaddr[port], ram_addr, chunk); |
| 2054 | skge_qset(skge, rxqaddr[port], skge->rx_ring.to_clean); |
| 2055 | |
| 2056 | BUG_ON(skge->tx_ring.to_use != skge->tx_ring.to_clean); |
| 2057 | skge_ramset(hw, txqaddr[port], ram_addr+chunk, chunk); |
| 2058 | skge_qset(skge, txqaddr[port], skge->tx_ring.to_use); |
| 2059 | |
| 2060 | /* Start receiver BMU */ |
| 2061 | wmb(); |
| 2062 | skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F); |
| 2063 | |
| 2064 | pr_debug("skge_up completed\n"); |
| 2065 | return 0; |
| 2066 | |
| 2067 | free_rx_ring: |
| 2068 | skge_rx_clean(skge); |
| 2069 | kfree(skge->rx_ring.start); |
| 2070 | free_pci_mem: |
| 2071 | pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma); |
| 2072 | |
| 2073 | return err; |
| 2074 | } |
| 2075 | |
| 2076 | static int skge_down(struct net_device *dev) |
| 2077 | { |
| 2078 | struct skge_port *skge = netdev_priv(dev); |
| 2079 | struct skge_hw *hw = skge->hw; |
| 2080 | int port = skge->port; |
| 2081 | |
| 2082 | if (netif_msg_ifdown(skge)) |
| 2083 | printk(KERN_INFO PFX "%s: disabling interface\n", dev->name); |
| 2084 | |
| 2085 | netif_stop_queue(dev); |
| 2086 | |
| 2087 | del_timer_sync(&skge->led_blink); |
| 2088 | del_timer_sync(&skge->link_check); |
| 2089 | |
| 2090 | /* Stop transmitter */ |
| 2091 | skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP); |
| 2092 | skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), |
| 2093 | RB_RST_SET|RB_DIS_OP_MD); |
| 2094 | |
| 2095 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 2096 | genesis_stop(skge); |
| 2097 | else |
| 2098 | yukon_stop(skge); |
| 2099 | |
| 2100 | /* Disable Force Sync bit and Enable Alloc bit */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2101 | skge_write8(hw, SK_REG(port, TXA_CTRL), |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2102 | TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC); |
| 2103 | |
| 2104 | /* Stop Interval Timer and Limit Counter of Tx Arbiter */ |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2105 | skge_write32(hw, SK_REG(port, TXA_ITI_INI), 0L); |
| 2106 | skge_write32(hw, SK_REG(port, TXA_LIM_INI), 0L); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2107 | |
| 2108 | /* Reset PCI FIFO */ |
| 2109 | skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET); |
| 2110 | skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET); |
| 2111 | |
| 2112 | /* Reset the RAM Buffer async Tx queue */ |
| 2113 | skge_write8(hw, RB_ADDR(port == 0 ? Q_XA1 : Q_XA2, RB_CTRL), RB_RST_SET); |
| 2114 | /* stop receiver */ |
| 2115 | skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_STOP); |
| 2116 | skge_write32(hw, RB_ADDR(port ? Q_R2 : Q_R1, RB_CTRL), |
| 2117 | RB_RST_SET|RB_DIS_OP_MD); |
| 2118 | skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET); |
| 2119 | |
| 2120 | if (hw->chip_id == CHIP_ID_GENESIS) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2121 | skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET); |
| 2122 | skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET); |
| 2123 | skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_STOP); |
| 2124 | skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_STOP); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2125 | } else { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2126 | skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); |
| 2127 | 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] | 2128 | } |
| 2129 | |
| 2130 | /* turn off led's */ |
| 2131 | skge_write16(hw, B0_LED, LED_STAT_OFF); |
| 2132 | |
| 2133 | skge_tx_clean(skge); |
| 2134 | skge_rx_clean(skge); |
| 2135 | |
| 2136 | kfree(skge->rx_ring.start); |
| 2137 | kfree(skge->tx_ring.start); |
| 2138 | pci_free_consistent(hw->pdev, skge->mem_size, skge->mem, skge->dma); |
| 2139 | return 0; |
| 2140 | } |
| 2141 | |
| 2142 | static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev) |
| 2143 | { |
| 2144 | struct skge_port *skge = netdev_priv(dev); |
| 2145 | struct skge_hw *hw = skge->hw; |
| 2146 | struct skge_ring *ring = &skge->tx_ring; |
| 2147 | struct skge_element *e; |
| 2148 | struct skge_tx_desc *td; |
| 2149 | int i; |
| 2150 | u32 control, len; |
| 2151 | u64 map; |
| 2152 | unsigned long flags; |
| 2153 | |
| 2154 | skb = skb_padto(skb, ETH_ZLEN); |
| 2155 | if (!skb) |
| 2156 | return NETDEV_TX_OK; |
| 2157 | |
| 2158 | local_irq_save(flags); |
| 2159 | if (!spin_trylock(&skge->tx_lock)) { |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 2160 | /* Collision - tell upper layer to requeue */ |
| 2161 | local_irq_restore(flags); |
| 2162 | return NETDEV_TX_LOCKED; |
| 2163 | } |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2164 | |
| 2165 | if (unlikely(skge->tx_avail < skb_shinfo(skb)->nr_frags +1)) { |
| 2166 | netif_stop_queue(dev); |
| 2167 | spin_unlock_irqrestore(&skge->tx_lock, flags); |
| 2168 | |
| 2169 | printk(KERN_WARNING PFX "%s: ring full when queue awake!\n", |
| 2170 | dev->name); |
| 2171 | return NETDEV_TX_BUSY; |
| 2172 | } |
| 2173 | |
| 2174 | e = ring->to_use; |
| 2175 | td = e->desc; |
| 2176 | e->skb = skb; |
| 2177 | len = skb_headlen(skb); |
| 2178 | map = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE); |
| 2179 | pci_unmap_addr_set(e, mapaddr, map); |
| 2180 | pci_unmap_len_set(e, maplen, len); |
| 2181 | |
| 2182 | td->dma_lo = map; |
| 2183 | td->dma_hi = map >> 32; |
| 2184 | |
| 2185 | if (skb->ip_summed == CHECKSUM_HW) { |
| 2186 | const struct iphdr *ip |
| 2187 | = (const struct iphdr *) (skb->data + ETH_HLEN); |
| 2188 | int offset = skb->h.raw - skb->data; |
| 2189 | |
| 2190 | /* This seems backwards, but it is what the sk98lin |
| 2191 | * does. Looks like hardware is wrong? |
| 2192 | */ |
| 2193 | if (ip->protocol == IPPROTO_UDP |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 2194 | && hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2195 | control = BMU_TCP_CHECK; |
| 2196 | else |
| 2197 | control = BMU_UDP_CHECK; |
| 2198 | |
| 2199 | td->csum_offs = 0; |
| 2200 | td->csum_start = offset; |
| 2201 | td->csum_write = offset + skb->csum; |
| 2202 | } else |
| 2203 | control = BMU_CHECK; |
| 2204 | |
| 2205 | if (!skb_shinfo(skb)->nr_frags) /* single buffer i.e. no fragments */ |
| 2206 | control |= BMU_EOF| BMU_IRQ_EOF; |
| 2207 | else { |
| 2208 | struct skge_tx_desc *tf = td; |
| 2209 | |
| 2210 | control |= BMU_STFWD; |
| 2211 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 2212 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 2213 | |
| 2214 | map = pci_map_page(hw->pdev, frag->page, frag->page_offset, |
| 2215 | frag->size, PCI_DMA_TODEVICE); |
| 2216 | |
| 2217 | e = e->next; |
| 2218 | e->skb = NULL; |
| 2219 | tf = e->desc; |
| 2220 | tf->dma_lo = map; |
| 2221 | tf->dma_hi = (u64) map >> 32; |
| 2222 | pci_unmap_addr_set(e, mapaddr, map); |
| 2223 | pci_unmap_len_set(e, maplen, frag->size); |
| 2224 | |
| 2225 | tf->control = BMU_OWN | BMU_SW | control | frag->size; |
| 2226 | } |
| 2227 | tf->control |= BMU_EOF | BMU_IRQ_EOF; |
| 2228 | } |
| 2229 | /* Make sure all the descriptors written */ |
| 2230 | wmb(); |
| 2231 | td->control = BMU_OWN | BMU_SW | BMU_STF | control | len; |
| 2232 | wmb(); |
| 2233 | |
| 2234 | skge_write8(hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_START); |
| 2235 | |
| 2236 | if (netif_msg_tx_queued(skge)) |
Al Viro | 0b2d7fe | 2005-04-03 09:15:52 +0100 | [diff] [blame] | 2237 | printk(KERN_DEBUG "%s: tx queued, slot %td, len %d\n", |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2238 | dev->name, e - ring->start, skb->len); |
| 2239 | |
| 2240 | ring->to_use = e->next; |
| 2241 | skge->tx_avail -= skb_shinfo(skb)->nr_frags + 1; |
| 2242 | if (skge->tx_avail <= MAX_SKB_FRAGS + 1) { |
| 2243 | pr_debug("%s: transmit queue full\n", dev->name); |
| 2244 | netif_stop_queue(dev); |
| 2245 | } |
| 2246 | |
| 2247 | dev->trans_start = jiffies; |
| 2248 | spin_unlock_irqrestore(&skge->tx_lock, flags); |
| 2249 | |
| 2250 | return NETDEV_TX_OK; |
| 2251 | } |
| 2252 | |
| 2253 | static inline void skge_tx_free(struct skge_hw *hw, struct skge_element *e) |
| 2254 | { |
| 2255 | if (e->skb) { |
| 2256 | pci_unmap_single(hw->pdev, |
| 2257 | pci_unmap_addr(e, mapaddr), |
| 2258 | pci_unmap_len(e, maplen), |
| 2259 | PCI_DMA_TODEVICE); |
| 2260 | dev_kfree_skb_any(e->skb); |
| 2261 | e->skb = NULL; |
| 2262 | } else { |
| 2263 | pci_unmap_page(hw->pdev, |
| 2264 | pci_unmap_addr(e, mapaddr), |
| 2265 | pci_unmap_len(e, maplen), |
| 2266 | PCI_DMA_TODEVICE); |
| 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | static void skge_tx_clean(struct skge_port *skge) |
| 2271 | { |
| 2272 | struct skge_ring *ring = &skge->tx_ring; |
| 2273 | struct skge_element *e; |
| 2274 | unsigned long flags; |
| 2275 | |
| 2276 | spin_lock_irqsave(&skge->tx_lock, flags); |
| 2277 | for (e = ring->to_clean; e != ring->to_use; e = e->next) { |
| 2278 | ++skge->tx_avail; |
| 2279 | skge_tx_free(skge->hw, e); |
| 2280 | } |
| 2281 | ring->to_clean = e; |
| 2282 | spin_unlock_irqrestore(&skge->tx_lock, flags); |
| 2283 | } |
| 2284 | |
| 2285 | static void skge_tx_timeout(struct net_device *dev) |
| 2286 | { |
| 2287 | struct skge_port *skge = netdev_priv(dev); |
| 2288 | |
| 2289 | if (netif_msg_timer(skge)) |
| 2290 | printk(KERN_DEBUG PFX "%s: tx timeout\n", dev->name); |
| 2291 | |
| 2292 | skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_STOP); |
| 2293 | skge_tx_clean(skge); |
| 2294 | } |
| 2295 | |
| 2296 | static int skge_change_mtu(struct net_device *dev, int new_mtu) |
| 2297 | { |
| 2298 | int err = 0; |
| 2299 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 2300 | if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2301 | return -EINVAL; |
| 2302 | |
| 2303 | dev->mtu = new_mtu; |
| 2304 | |
| 2305 | if (netif_running(dev)) { |
| 2306 | skge_down(dev); |
| 2307 | skge_up(dev); |
| 2308 | } |
| 2309 | |
| 2310 | return err; |
| 2311 | } |
| 2312 | |
| 2313 | static void genesis_set_multicast(struct net_device *dev) |
| 2314 | { |
| 2315 | struct skge_port *skge = netdev_priv(dev); |
| 2316 | struct skge_hw *hw = skge->hw; |
| 2317 | int port = skge->port; |
| 2318 | int i, count = dev->mc_count; |
| 2319 | struct dev_mc_list *list = dev->mc_list; |
| 2320 | u32 mode; |
| 2321 | u8 filter[8]; |
| 2322 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2323 | mode = xm_read32(hw, port, XM_MODE); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2324 | mode |= XM_MD_ENA_HASH; |
| 2325 | if (dev->flags & IFF_PROMISC) |
| 2326 | mode |= XM_MD_ENA_PROM; |
| 2327 | else |
| 2328 | mode &= ~XM_MD_ENA_PROM; |
| 2329 | |
| 2330 | if (dev->flags & IFF_ALLMULTI) |
| 2331 | memset(filter, 0xff, sizeof(filter)); |
| 2332 | else { |
| 2333 | memset(filter, 0, sizeof(filter)); |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 2334 | for (i = 0; list && i < count; i++, list = list->next) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2335 | u32 crc = crc32_le(~0, list->dmi_addr, ETH_ALEN); |
| 2336 | u8 bit = 63 - (crc & 63); |
| 2337 | |
| 2338 | filter[bit/8] |= 1 << (bit%8); |
| 2339 | } |
| 2340 | } |
| 2341 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2342 | xm_outhash(hw, port, XM_HSM, filter); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2343 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2344 | xm_write32(hw, port, XM_MODE, mode); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | static void yukon_set_multicast(struct net_device *dev) |
| 2348 | { |
| 2349 | struct skge_port *skge = netdev_priv(dev); |
| 2350 | struct skge_hw *hw = skge->hw; |
| 2351 | int port = skge->port; |
| 2352 | struct dev_mc_list *list = dev->mc_list; |
| 2353 | u16 reg; |
| 2354 | u8 filter[8]; |
| 2355 | |
| 2356 | memset(filter, 0, sizeof(filter)); |
| 2357 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2358 | reg = gma_read16(hw, port, GM_RX_CTRL); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2359 | reg |= GM_RXCR_UCF_ENA; |
| 2360 | |
| 2361 | if (dev->flags & IFF_PROMISC) /* promiscious */ |
| 2362 | reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); |
| 2363 | else if (dev->flags & IFF_ALLMULTI) /* all multicast */ |
| 2364 | memset(filter, 0xff, sizeof(filter)); |
| 2365 | else if (dev->mc_count == 0) /* no multicast */ |
| 2366 | reg &= ~GM_RXCR_MCF_ENA; |
| 2367 | else { |
| 2368 | int i; |
| 2369 | reg |= GM_RXCR_MCF_ENA; |
| 2370 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 2371 | for (i = 0; list && i < dev->mc_count; i++, list = list->next) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2372 | u32 bit = ether_crc(ETH_ALEN, list->dmi_addr) & 0x3f; |
| 2373 | filter[bit/8] |= 1 << (bit%8); |
| 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2378 | gma_write16(hw, port, GM_MC_ADDR_H1, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2379 | (u16)filter[0] | ((u16)filter[1] << 8)); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2380 | gma_write16(hw, port, GM_MC_ADDR_H2, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2381 | (u16)filter[2] | ((u16)filter[3] << 8)); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2382 | gma_write16(hw, port, GM_MC_ADDR_H3, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2383 | (u16)filter[4] | ((u16)filter[5] << 8)); |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2384 | gma_write16(hw, port, GM_MC_ADDR_H4, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2385 | (u16)filter[6] | ((u16)filter[7] << 8)); |
| 2386 | |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2387 | gma_write16(hw, port, GM_RX_CTRL, reg); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | static inline int bad_phy_status(const struct skge_hw *hw, u32 status) |
| 2391 | { |
| 2392 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 2393 | return (status & (XMR_FS_ERR | XMR_FS_2L_VLAN)) != 0; |
| 2394 | else |
| 2395 | return (status & GMR_FS_ANY_ERR) || |
| 2396 | (status & GMR_FS_RX_OK) == 0; |
| 2397 | } |
| 2398 | |
| 2399 | static void skge_rx_error(struct skge_port *skge, int slot, |
| 2400 | u32 control, u32 status) |
| 2401 | { |
| 2402 | if (netif_msg_rx_err(skge)) |
| 2403 | printk(KERN_DEBUG PFX "%s: rx err, slot %d control 0x%x status 0x%x\n", |
| 2404 | skge->netdev->name, slot, control, status); |
| 2405 | |
| 2406 | if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF) |
| 2407 | || (control & BMU_BBC) > skge->netdev->mtu + VLAN_ETH_HLEN) |
| 2408 | skge->net_stats.rx_length_errors++; |
| 2409 | else { |
| 2410 | if (skge->hw->chip_id == CHIP_ID_GENESIS) { |
| 2411 | if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR)) |
| 2412 | skge->net_stats.rx_length_errors++; |
| 2413 | if (status & XMR_FS_FRA_ERR) |
| 2414 | skge->net_stats.rx_frame_errors++; |
| 2415 | if (status & XMR_FS_FCS_ERR) |
| 2416 | skge->net_stats.rx_crc_errors++; |
| 2417 | } else { |
| 2418 | if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE)) |
| 2419 | skge->net_stats.rx_length_errors++; |
| 2420 | if (status & GMR_FS_FRAGMENT) |
| 2421 | skge->net_stats.rx_frame_errors++; |
| 2422 | if (status & GMR_FS_CRC_ERR) |
| 2423 | skge->net_stats.rx_crc_errors++; |
| 2424 | } |
| 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | static int skge_poll(struct net_device *dev, int *budget) |
| 2429 | { |
| 2430 | struct skge_port *skge = netdev_priv(dev); |
| 2431 | struct skge_hw *hw = skge->hw; |
| 2432 | struct skge_ring *ring = &skge->rx_ring; |
| 2433 | struct skge_element *e; |
| 2434 | unsigned int to_do = min(dev->quota, *budget); |
| 2435 | unsigned int work_done = 0; |
| 2436 | int done; |
| 2437 | static const u32 irqmask[] = { IS_PORT_1, IS_PORT_2 }; |
| 2438 | |
| 2439 | for (e = ring->to_clean; e != ring->to_use && work_done < to_do; |
| 2440 | e = e->next) { |
| 2441 | struct skge_rx_desc *rd = e->desc; |
| 2442 | struct sk_buff *skb = e->skb; |
| 2443 | u32 control, len, status; |
| 2444 | |
| 2445 | rmb(); |
| 2446 | control = rd->control; |
| 2447 | if (control & BMU_OWN) |
| 2448 | break; |
| 2449 | |
| 2450 | len = control & BMU_BBC; |
| 2451 | e->skb = NULL; |
| 2452 | |
| 2453 | pci_unmap_single(hw->pdev, |
| 2454 | pci_unmap_addr(e, mapaddr), |
| 2455 | pci_unmap_len(e, maplen), |
| 2456 | PCI_DMA_FROMDEVICE); |
| 2457 | |
| 2458 | status = rd->status; |
| 2459 | if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF) |
| 2460 | || len > dev->mtu + VLAN_ETH_HLEN |
| 2461 | || bad_phy_status(hw, status)) { |
| 2462 | skge_rx_error(skge, e - ring->start, control, status); |
| 2463 | dev_kfree_skb(skb); |
| 2464 | continue; |
| 2465 | } |
| 2466 | |
| 2467 | if (netif_msg_rx_status(skge)) |
Al Viro | 0b2d7fe | 2005-04-03 09:15:52 +0100 | [diff] [blame] | 2468 | printk(KERN_DEBUG PFX "%s: rx slot %td status 0x%x len %d\n", |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2469 | dev->name, e - ring->start, rd->status, len); |
| 2470 | |
| 2471 | skb_put(skb, len); |
| 2472 | skb->protocol = eth_type_trans(skb, dev); |
| 2473 | |
| 2474 | if (skge->rx_csum) { |
| 2475 | skb->csum = le16_to_cpu(rd->csum2); |
| 2476 | skb->ip_summed = CHECKSUM_HW; |
| 2477 | } |
| 2478 | |
| 2479 | dev->last_rx = jiffies; |
| 2480 | netif_receive_skb(skb); |
| 2481 | |
| 2482 | ++work_done; |
| 2483 | } |
| 2484 | ring->to_clean = e; |
| 2485 | |
| 2486 | *budget -= work_done; |
| 2487 | dev->quota -= work_done; |
| 2488 | done = work_done < to_do; |
| 2489 | |
| 2490 | if (skge_rx_fill(skge)) |
| 2491 | done = 0; |
| 2492 | |
| 2493 | /* restart receiver */ |
| 2494 | wmb(); |
| 2495 | skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), |
| 2496 | CSR_START | CSR_IRQ_CL_F); |
| 2497 | |
| 2498 | if (done) { |
| 2499 | local_irq_disable(); |
| 2500 | hw->intr_mask |= irqmask[skge->port]; |
| 2501 | /* Order is important since data can get interrupted */ |
| 2502 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
| 2503 | __netif_rx_complete(dev); |
| 2504 | local_irq_enable(); |
| 2505 | } |
| 2506 | |
| 2507 | return !done; |
| 2508 | } |
| 2509 | |
| 2510 | static inline void skge_tx_intr(struct net_device *dev) |
| 2511 | { |
| 2512 | struct skge_port *skge = netdev_priv(dev); |
| 2513 | struct skge_hw *hw = skge->hw; |
| 2514 | struct skge_ring *ring = &skge->tx_ring; |
| 2515 | struct skge_element *e; |
| 2516 | |
| 2517 | spin_lock(&skge->tx_lock); |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 2518 | for (e = ring->to_clean; e != ring->to_use; e = e->next) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2519 | struct skge_tx_desc *td = e->desc; |
| 2520 | u32 control; |
| 2521 | |
| 2522 | rmb(); |
| 2523 | control = td->control; |
| 2524 | if (control & BMU_OWN) |
| 2525 | break; |
| 2526 | |
| 2527 | if (unlikely(netif_msg_tx_done(skge))) |
Al Viro | 0b2d7fe | 2005-04-03 09:15:52 +0100 | [diff] [blame] | 2528 | printk(KERN_DEBUG PFX "%s: tx done slot %td status 0x%x\n", |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2529 | dev->name, e - ring->start, td->status); |
| 2530 | |
| 2531 | skge_tx_free(hw, e); |
| 2532 | e->skb = NULL; |
| 2533 | ++skge->tx_avail; |
| 2534 | } |
| 2535 | ring->to_clean = e; |
| 2536 | skge_write8(hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F); |
| 2537 | |
| 2538 | if (skge->tx_avail > MAX_SKB_FRAGS + 1) |
| 2539 | netif_wake_queue(dev); |
| 2540 | |
| 2541 | spin_unlock(&skge->tx_lock); |
| 2542 | } |
| 2543 | |
| 2544 | static void skge_mac_parity(struct skge_hw *hw, int port) |
| 2545 | { |
| 2546 | printk(KERN_ERR PFX "%s: mac data parity error\n", |
| 2547 | hw->dev[port] ? hw->dev[port]->name |
| 2548 | : (port == 0 ? "(port A)": "(port B")); |
| 2549 | |
| 2550 | if (hw->chip_id == CHIP_ID_GENESIS) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2551 | skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2552 | MFF_CLR_PERR); |
| 2553 | else |
| 2554 | /* 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] | 2555 | skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 2556 | (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2557 | ? GMF_CLI_TX_FC : GMF_CLI_TX_PE); |
| 2558 | } |
| 2559 | |
| 2560 | static void skge_pci_clear(struct skge_hw *hw) |
| 2561 | { |
| 2562 | u16 status; |
| 2563 | |
Stephen Hemminger | 467b341 | 2005-06-27 11:33:05 -0700 | [diff] [blame] | 2564 | pci_read_config_word(hw->pdev, PCI_STATUS, &status); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2565 | skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); |
Stephen Hemminger | 467b341 | 2005-06-27 11:33:05 -0700 | [diff] [blame] | 2566 | pci_write_config_word(hw->pdev, PCI_STATUS, |
| 2567 | status | PCI_STATUS_ERROR_BITS); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2568 | skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); |
| 2569 | } |
| 2570 | |
| 2571 | static void skge_mac_intr(struct skge_hw *hw, int port) |
| 2572 | { |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 2573 | if (hw->chip_id == CHIP_ID_GENESIS) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2574 | genesis_mac_intr(hw, port); |
| 2575 | else |
| 2576 | yukon_mac_intr(hw, port); |
| 2577 | } |
| 2578 | |
| 2579 | /* Handle device specific framing and timeout interrupts */ |
| 2580 | static void skge_error_irq(struct skge_hw *hw) |
| 2581 | { |
| 2582 | u32 hwstatus = skge_read32(hw, B0_HWE_ISRC); |
| 2583 | |
| 2584 | if (hw->chip_id == CHIP_ID_GENESIS) { |
| 2585 | /* clear xmac errors */ |
| 2586 | if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1)) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2587 | skge_write16(hw, SK_REG(0, RX_MFF_CTRL1), MFF_CLR_INSTAT); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2588 | if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2)) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2589 | skge_write16(hw, SK_REG(0, RX_MFF_CTRL2), MFF_CLR_INSTAT); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2590 | } else { |
| 2591 | /* Timestamp (unused) overflow */ |
| 2592 | if (hwstatus & IS_IRQ_TIST_OV) |
| 2593 | skge_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ); |
| 2594 | |
| 2595 | if (hwstatus & IS_IRQ_SENSOR) { |
| 2596 | /* no sensors on 32-bit Yukon */ |
| 2597 | if (!(skge_read16(hw, B0_CTST) & CS_BUS_SLOT_SZ)) { |
| 2598 | printk(KERN_ERR PFX "ignoring bogus sensor interrups\n"); |
| 2599 | skge_write32(hw, B0_HWE_IMSK, |
| 2600 | IS_ERR_MSK & ~IS_IRQ_SENSOR); |
| 2601 | } else |
| 2602 | printk(KERN_WARNING PFX "sensor interrupt\n"); |
| 2603 | } |
| 2604 | |
| 2605 | |
| 2606 | } |
| 2607 | |
| 2608 | if (hwstatus & IS_RAM_RD_PAR) { |
| 2609 | printk(KERN_ERR PFX "Ram read data parity error\n"); |
| 2610 | skge_write16(hw, B3_RI_CTRL, RI_CLR_RD_PERR); |
| 2611 | } |
| 2612 | |
| 2613 | if (hwstatus & IS_RAM_WR_PAR) { |
| 2614 | printk(KERN_ERR PFX "Ram write data parity error\n"); |
| 2615 | skge_write16(hw, B3_RI_CTRL, RI_CLR_WR_PERR); |
| 2616 | } |
| 2617 | |
| 2618 | if (hwstatus & IS_M1_PAR_ERR) |
| 2619 | skge_mac_parity(hw, 0); |
| 2620 | |
| 2621 | if (hwstatus & IS_M2_PAR_ERR) |
| 2622 | skge_mac_parity(hw, 1); |
| 2623 | |
| 2624 | if (hwstatus & IS_R1_PAR_ERR) |
| 2625 | skge_write32(hw, B0_R1_CSR, CSR_IRQ_CL_P); |
| 2626 | |
| 2627 | if (hwstatus & IS_R2_PAR_ERR) |
| 2628 | skge_write32(hw, B0_R2_CSR, CSR_IRQ_CL_P); |
| 2629 | |
| 2630 | if (hwstatus & (IS_IRQ_MST_ERR|IS_IRQ_STAT)) { |
| 2631 | printk(KERN_ERR PFX "hardware error detected (status 0x%x)\n", |
| 2632 | hwstatus); |
| 2633 | |
| 2634 | skge_pci_clear(hw); |
| 2635 | |
| 2636 | hwstatus = skge_read32(hw, B0_HWE_ISRC); |
| 2637 | if (hwstatus & IS_IRQ_STAT) { |
| 2638 | printk(KERN_WARNING PFX "IRQ status %x: still set ignoring hardware errors\n", |
| 2639 | hwstatus); |
| 2640 | hw->intr_mask &= ~IS_HW_ERR; |
| 2641 | } |
| 2642 | } |
| 2643 | } |
| 2644 | |
| 2645 | /* |
| 2646 | * Interrrupt from PHY are handled in tasklet (soft irq) |
| 2647 | * because accessing phy registers requires spin wait which might |
| 2648 | * cause excess interrupt latency. |
| 2649 | */ |
| 2650 | static void skge_extirq(unsigned long data) |
| 2651 | { |
| 2652 | struct skge_hw *hw = (struct skge_hw *) data; |
| 2653 | int port; |
| 2654 | |
| 2655 | spin_lock(&hw->phy_lock); |
| 2656 | for (port = 0; port < 2; port++) { |
| 2657 | struct net_device *dev = hw->dev[port]; |
| 2658 | |
| 2659 | if (dev && netif_running(dev)) { |
| 2660 | struct skge_port *skge = netdev_priv(dev); |
| 2661 | |
| 2662 | if (hw->chip_id != CHIP_ID_GENESIS) |
| 2663 | yukon_phy_intr(skge); |
Stephen Hemminger | 89bf5f2 | 2005-06-27 11:33:10 -0700 | [diff] [blame^] | 2664 | else |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2665 | genesis_bcom_intr(skge); |
| 2666 | } |
| 2667 | } |
| 2668 | spin_unlock(&hw->phy_lock); |
| 2669 | |
| 2670 | local_irq_disable(); |
| 2671 | hw->intr_mask |= IS_EXT_REG; |
| 2672 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
| 2673 | local_irq_enable(); |
| 2674 | } |
| 2675 | |
| 2676 | static irqreturn_t skge_intr(int irq, void *dev_id, struct pt_regs *regs) |
| 2677 | { |
| 2678 | struct skge_hw *hw = dev_id; |
| 2679 | u32 status = skge_read32(hw, B0_SP_ISRC); |
| 2680 | |
| 2681 | if (status == 0 || status == ~0) /* hotplug or shared irq */ |
| 2682 | return IRQ_NONE; |
| 2683 | |
| 2684 | status &= hw->intr_mask; |
| 2685 | |
| 2686 | if ((status & IS_R1_F) && netif_rx_schedule_prep(hw->dev[0])) { |
| 2687 | status &= ~IS_R1_F; |
| 2688 | hw->intr_mask &= ~IS_R1_F; |
| 2689 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
| 2690 | __netif_rx_schedule(hw->dev[0]); |
| 2691 | } |
| 2692 | |
| 2693 | if ((status & IS_R2_F) && netif_rx_schedule_prep(hw->dev[1])) { |
| 2694 | status &= ~IS_R2_F; |
| 2695 | hw->intr_mask &= ~IS_R2_F; |
| 2696 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
| 2697 | __netif_rx_schedule(hw->dev[1]); |
| 2698 | } |
| 2699 | |
| 2700 | if (status & IS_XA1_F) |
| 2701 | skge_tx_intr(hw->dev[0]); |
| 2702 | |
| 2703 | if (status & IS_XA2_F) |
| 2704 | skge_tx_intr(hw->dev[1]); |
| 2705 | |
| 2706 | if (status & IS_MAC1) |
| 2707 | skge_mac_intr(hw, 0); |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 2708 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2709 | if (status & IS_MAC2) |
| 2710 | skge_mac_intr(hw, 1); |
| 2711 | |
| 2712 | if (status & IS_HW_ERR) |
| 2713 | skge_error_irq(hw); |
| 2714 | |
| 2715 | if (status & IS_EXT_REG) { |
| 2716 | hw->intr_mask &= ~IS_EXT_REG; |
| 2717 | tasklet_schedule(&hw->ext_tasklet); |
| 2718 | } |
| 2719 | |
| 2720 | if (status) |
| 2721 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
| 2722 | |
| 2723 | return IRQ_HANDLED; |
| 2724 | } |
| 2725 | |
| 2726 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2727 | static void skge_netpoll(struct net_device *dev) |
| 2728 | { |
| 2729 | struct skge_port *skge = netdev_priv(dev); |
| 2730 | |
| 2731 | disable_irq(dev->irq); |
| 2732 | skge_intr(dev->irq, skge->hw, NULL); |
| 2733 | enable_irq(dev->irq); |
| 2734 | } |
| 2735 | #endif |
| 2736 | |
| 2737 | static int skge_set_mac_address(struct net_device *dev, void *p) |
| 2738 | { |
| 2739 | struct skge_port *skge = netdev_priv(dev); |
| 2740 | struct sockaddr *addr = p; |
| 2741 | int err = 0; |
| 2742 | |
| 2743 | if (!is_valid_ether_addr(addr->sa_data)) |
| 2744 | return -EADDRNOTAVAIL; |
| 2745 | |
| 2746 | skge_down(dev); |
| 2747 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); |
| 2748 | memcpy_toio(skge->hw->regs + B2_MAC_1 + skge->port*8, |
| 2749 | dev->dev_addr, ETH_ALEN); |
| 2750 | memcpy_toio(skge->hw->regs + B2_MAC_2 + skge->port*8, |
| 2751 | dev->dev_addr, ETH_ALEN); |
| 2752 | if (dev->flags & IFF_UP) |
| 2753 | err = skge_up(dev); |
| 2754 | return err; |
| 2755 | } |
| 2756 | |
| 2757 | static const struct { |
| 2758 | u8 id; |
| 2759 | const char *name; |
| 2760 | } skge_chips[] = { |
| 2761 | { CHIP_ID_GENESIS, "Genesis" }, |
| 2762 | { CHIP_ID_YUKON, "Yukon" }, |
| 2763 | { CHIP_ID_YUKON_LITE, "Yukon-Lite"}, |
| 2764 | { CHIP_ID_YUKON_LP, "Yukon-LP"}, |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2765 | }; |
| 2766 | |
| 2767 | static const char *skge_board_name(const struct skge_hw *hw) |
| 2768 | { |
| 2769 | int i; |
| 2770 | static char buf[16]; |
| 2771 | |
| 2772 | for (i = 0; i < ARRAY_SIZE(skge_chips); i++) |
| 2773 | if (skge_chips[i].id == hw->chip_id) |
| 2774 | return skge_chips[i].name; |
| 2775 | |
| 2776 | snprintf(buf, sizeof buf, "chipid 0x%x", hw->chip_id); |
| 2777 | return buf; |
| 2778 | } |
| 2779 | |
| 2780 | |
| 2781 | /* |
| 2782 | * Setup the board data structure, but don't bring up |
| 2783 | * the port(s) |
| 2784 | */ |
| 2785 | static int skge_reset(struct skge_hw *hw) |
| 2786 | { |
| 2787 | u16 ctst; |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 2788 | u8 t8, mac_cfg; |
| 2789 | int i; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2790 | |
| 2791 | ctst = skge_read16(hw, B0_CTST); |
| 2792 | |
| 2793 | /* do a SW reset */ |
| 2794 | skge_write8(hw, B0_CTST, CS_RST_SET); |
| 2795 | skge_write8(hw, B0_CTST, CS_RST_CLR); |
| 2796 | |
| 2797 | /* clear PCI errors, if any */ |
| 2798 | skge_pci_clear(hw); |
| 2799 | |
| 2800 | skge_write8(hw, B0_CTST, CS_MRST_CLR); |
| 2801 | |
| 2802 | /* restore CLK_RUN bits (for Yukon-Lite) */ |
| 2803 | skge_write16(hw, B0_CTST, |
| 2804 | ctst & (CS_CLK_RUN_HOT|CS_CLK_RUN_RST|CS_CLK_RUN_ENA)); |
| 2805 | |
| 2806 | hw->chip_id = skge_read8(hw, B2_CHIP_ID); |
| 2807 | hw->phy_type = skge_read8(hw, B2_E_1) & 0xf; |
| 2808 | hw->pmd_type = skge_read8(hw, B2_PMD_TYP); |
| 2809 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 2810 | switch (hw->chip_id) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2811 | case CHIP_ID_GENESIS: |
| 2812 | switch (hw->phy_type) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2813 | case SK_PHY_BCOM: |
| 2814 | hw->phy_addr = PHY_ADDR_BCOM; |
| 2815 | break; |
| 2816 | default: |
| 2817 | printk(KERN_ERR PFX "%s: unsupported phy type 0x%x\n", |
| 2818 | pci_name(hw->pdev), hw->phy_type); |
| 2819 | return -EOPNOTSUPP; |
| 2820 | } |
| 2821 | break; |
| 2822 | |
| 2823 | case CHIP_ID_YUKON: |
| 2824 | case CHIP_ID_YUKON_LITE: |
| 2825 | case CHIP_ID_YUKON_LP: |
| 2826 | if (hw->phy_type < SK_PHY_MARV_COPPER && hw->pmd_type != 'S') |
| 2827 | hw->phy_type = SK_PHY_MARV_COPPER; |
| 2828 | |
| 2829 | hw->phy_addr = PHY_ADDR_MARV; |
| 2830 | if (!iscopper(hw)) |
| 2831 | hw->phy_type = SK_PHY_MARV_FIBER; |
| 2832 | |
| 2833 | break; |
| 2834 | |
| 2835 | default: |
| 2836 | printk(KERN_ERR PFX "%s: unsupported chip type 0x%x\n", |
| 2837 | pci_name(hw->pdev), hw->chip_id); |
| 2838 | return -EOPNOTSUPP; |
| 2839 | } |
| 2840 | |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 2841 | mac_cfg = skge_read8(hw, B2_MAC_CFG); |
| 2842 | hw->ports = (mac_cfg & CFG_SNG_MAC) ? 1 : 2; |
| 2843 | hw->chip_rev = (mac_cfg & CFG_CHIP_R_MSK) >> 4; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2844 | |
| 2845 | /* read the adapters RAM size */ |
| 2846 | t8 = skge_read8(hw, B2_E_0); |
| 2847 | if (hw->chip_id == CHIP_ID_GENESIS) { |
| 2848 | if (t8 == 3) { |
| 2849 | /* special case: 4 x 64k x 36, offset = 0x80000 */ |
| 2850 | hw->ram_size = 0x100000; |
| 2851 | hw->ram_offset = 0x80000; |
| 2852 | } else |
| 2853 | hw->ram_size = t8 * 512; |
| 2854 | } |
| 2855 | else if (t8 == 0) |
| 2856 | hw->ram_size = 0x20000; |
| 2857 | else |
| 2858 | hw->ram_size = t8 * 4096; |
| 2859 | |
| 2860 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 2861 | genesis_init(hw); |
| 2862 | else { |
| 2863 | /* switch power to VCC (WA for VAUX problem) */ |
| 2864 | skge_write8(hw, B0_POWER_CTRL, |
| 2865 | PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON); |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 2866 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2867 | skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET); |
| 2868 | skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2869 | } |
| 2870 | } |
| 2871 | |
| 2872 | /* turn off hardware timer (unused) */ |
| 2873 | skge_write8(hw, B2_TI_CTRL, TIM_STOP); |
| 2874 | skge_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ); |
| 2875 | skge_write8(hw, B0_LED, LED_STAT_ON); |
| 2876 | |
| 2877 | /* enable the Tx Arbiters */ |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 2878 | for (i = 0; i < hw->ports; i++) |
Stephen Hemminger | 6b0c148 | 2005-06-27 11:33:04 -0700 | [diff] [blame] | 2879 | skge_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2880 | |
| 2881 | /* Initialize ram interface */ |
| 2882 | skge_write16(hw, B3_RI_CTRL, RI_RST_CLR); |
| 2883 | |
| 2884 | skge_write8(hw, B3_RI_WTO_R1, SK_RI_TO_53); |
| 2885 | skge_write8(hw, B3_RI_WTO_XA1, SK_RI_TO_53); |
| 2886 | skge_write8(hw, B3_RI_WTO_XS1, SK_RI_TO_53); |
| 2887 | skge_write8(hw, B3_RI_RTO_R1, SK_RI_TO_53); |
| 2888 | skge_write8(hw, B3_RI_RTO_XA1, SK_RI_TO_53); |
| 2889 | skge_write8(hw, B3_RI_RTO_XS1, SK_RI_TO_53); |
| 2890 | skge_write8(hw, B3_RI_WTO_R2, SK_RI_TO_53); |
| 2891 | skge_write8(hw, B3_RI_WTO_XA2, SK_RI_TO_53); |
| 2892 | skge_write8(hw, B3_RI_WTO_XS2, SK_RI_TO_53); |
| 2893 | skge_write8(hw, B3_RI_RTO_R2, SK_RI_TO_53); |
| 2894 | skge_write8(hw, B3_RI_RTO_XA2, SK_RI_TO_53); |
| 2895 | skge_write8(hw, B3_RI_RTO_XS2, SK_RI_TO_53); |
| 2896 | |
| 2897 | skge_write32(hw, B0_HWE_IMSK, IS_ERR_MSK); |
| 2898 | |
| 2899 | /* Set interrupt moderation for Transmit only |
| 2900 | * Receive interrupts avoided by NAPI |
| 2901 | */ |
| 2902 | skge_write32(hw, B2_IRQM_MSK, IS_XA1_F|IS_XA2_F); |
| 2903 | skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100)); |
| 2904 | skge_write32(hw, B2_IRQM_CTRL, TIM_START); |
| 2905 | |
| 2906 | hw->intr_mask = IS_HW_ERR | IS_EXT_REG | IS_PORT_1; |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 2907 | if (hw->ports > 1) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2908 | hw->intr_mask |= IS_PORT_2; |
| 2909 | skge_write32(hw, B0_IMSK, hw->intr_mask); |
| 2910 | |
| 2911 | if (hw->chip_id != CHIP_ID_GENESIS) |
| 2912 | skge_write8(hw, GMAC_IRQ_MSK, 0); |
| 2913 | |
| 2914 | spin_lock_bh(&hw->phy_lock); |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 2915 | for (i = 0; i < hw->ports; i++) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2916 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 2917 | genesis_reset(hw, i); |
| 2918 | else |
| 2919 | yukon_reset(hw, i); |
| 2920 | } |
| 2921 | spin_unlock_bh(&hw->phy_lock); |
| 2922 | |
| 2923 | return 0; |
| 2924 | } |
| 2925 | |
| 2926 | /* Initialize network device */ |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 2927 | static struct net_device *skge_devinit(struct skge_hw *hw, int port, |
| 2928 | int highmem) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2929 | { |
| 2930 | struct skge_port *skge; |
| 2931 | struct net_device *dev = alloc_etherdev(sizeof(*skge)); |
| 2932 | |
| 2933 | if (!dev) { |
| 2934 | printk(KERN_ERR "skge etherdev alloc failed"); |
| 2935 | return NULL; |
| 2936 | } |
| 2937 | |
| 2938 | SET_MODULE_OWNER(dev); |
| 2939 | SET_NETDEV_DEV(dev, &hw->pdev->dev); |
| 2940 | dev->open = skge_up; |
| 2941 | dev->stop = skge_down; |
| 2942 | dev->hard_start_xmit = skge_xmit_frame; |
| 2943 | dev->get_stats = skge_get_stats; |
| 2944 | if (hw->chip_id == CHIP_ID_GENESIS) |
| 2945 | dev->set_multicast_list = genesis_set_multicast; |
| 2946 | else |
| 2947 | dev->set_multicast_list = yukon_set_multicast; |
| 2948 | |
| 2949 | dev->set_mac_address = skge_set_mac_address; |
| 2950 | dev->change_mtu = skge_change_mtu; |
| 2951 | SET_ETHTOOL_OPS(dev, &skge_ethtool_ops); |
| 2952 | dev->tx_timeout = skge_tx_timeout; |
| 2953 | dev->watchdog_timeo = TX_WATCHDOG; |
| 2954 | dev->poll = skge_poll; |
| 2955 | dev->weight = NAPI_WEIGHT; |
| 2956 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2957 | dev->poll_controller = skge_netpoll; |
| 2958 | #endif |
| 2959 | dev->irq = hw->pdev->irq; |
| 2960 | dev->features = NETIF_F_LLTX; |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 2961 | if (highmem) |
| 2962 | dev->features |= NETIF_F_HIGHDMA; |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 2963 | |
| 2964 | skge = netdev_priv(dev); |
| 2965 | skge->netdev = dev; |
| 2966 | skge->hw = hw; |
| 2967 | skge->msg_enable = netif_msg_init(debug, default_msg); |
| 2968 | skge->tx_ring.count = DEFAULT_TX_RING_SIZE; |
| 2969 | skge->rx_ring.count = DEFAULT_RX_RING_SIZE; |
| 2970 | |
| 2971 | /* Auto speed and flow control */ |
| 2972 | skge->autoneg = AUTONEG_ENABLE; |
| 2973 | skge->flow_control = FLOW_MODE_SYMMETRIC; |
| 2974 | skge->duplex = -1; |
| 2975 | skge->speed = -1; |
| 2976 | skge->advertising = skge_modes(hw); |
| 2977 | |
| 2978 | hw->dev[port] = dev; |
| 2979 | |
| 2980 | skge->port = port; |
| 2981 | |
| 2982 | spin_lock_init(&skge->tx_lock); |
| 2983 | |
| 2984 | init_timer(&skge->link_check); |
| 2985 | skge->link_check.function = skge_link_timer; |
| 2986 | skge->link_check.data = (unsigned long) skge; |
| 2987 | |
| 2988 | init_timer(&skge->led_blink); |
| 2989 | skge->led_blink.function = skge_blink_timer; |
| 2990 | skge->led_blink.data = (unsigned long) skge; |
| 2991 | |
| 2992 | if (hw->chip_id != CHIP_ID_GENESIS) { |
| 2993 | dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG; |
| 2994 | skge->rx_csum = 1; |
| 2995 | } |
| 2996 | |
| 2997 | /* read the mac address */ |
| 2998 | memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port*8, ETH_ALEN); |
| 2999 | |
| 3000 | /* device is off until link detection */ |
| 3001 | netif_carrier_off(dev); |
| 3002 | netif_stop_queue(dev); |
| 3003 | |
| 3004 | return dev; |
| 3005 | } |
| 3006 | |
| 3007 | static void __devinit skge_show_addr(struct net_device *dev) |
| 3008 | { |
| 3009 | const struct skge_port *skge = netdev_priv(dev); |
| 3010 | |
| 3011 | if (netif_msg_probe(skge)) |
| 3012 | printk(KERN_INFO PFX "%s: addr %02x:%02x:%02x:%02x:%02x:%02x\n", |
| 3013 | dev->name, |
| 3014 | dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], |
| 3015 | dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); |
| 3016 | } |
| 3017 | |
| 3018 | static int __devinit skge_probe(struct pci_dev *pdev, |
| 3019 | const struct pci_device_id *ent) |
| 3020 | { |
| 3021 | struct net_device *dev, *dev1; |
| 3022 | struct skge_hw *hw; |
| 3023 | int err, using_dac = 0; |
| 3024 | |
| 3025 | if ((err = pci_enable_device(pdev))) { |
| 3026 | printk(KERN_ERR PFX "%s cannot enable PCI device\n", |
| 3027 | pci_name(pdev)); |
| 3028 | goto err_out; |
| 3029 | } |
| 3030 | |
| 3031 | if ((err = pci_request_regions(pdev, DRV_NAME))) { |
| 3032 | printk(KERN_ERR PFX "%s cannot obtain PCI resources\n", |
| 3033 | pci_name(pdev)); |
| 3034 | goto err_out_disable_pdev; |
| 3035 | } |
| 3036 | |
| 3037 | pci_set_master(pdev); |
| 3038 | |
| 3039 | if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) |
| 3040 | using_dac = 1; |
| 3041 | else if (!(err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) { |
| 3042 | printk(KERN_ERR PFX "%s no usable DMA configuration\n", |
| 3043 | pci_name(pdev)); |
| 3044 | goto err_out_free_regions; |
| 3045 | } |
| 3046 | |
| 3047 | #ifdef __BIG_ENDIAN |
| 3048 | /* byte swap decriptors in hardware */ |
| 3049 | { |
| 3050 | u32 reg; |
| 3051 | |
| 3052 | pci_read_config_dword(pdev, PCI_DEV_REG2, ®); |
| 3053 | reg |= PCI_REV_DESC; |
| 3054 | pci_write_config_dword(pdev, PCI_DEV_REG2, reg); |
| 3055 | } |
| 3056 | #endif |
| 3057 | |
| 3058 | err = -ENOMEM; |
| 3059 | hw = kmalloc(sizeof(*hw), GFP_KERNEL); |
| 3060 | if (!hw) { |
| 3061 | printk(KERN_ERR PFX "%s: cannot allocate hardware struct\n", |
| 3062 | pci_name(pdev)); |
| 3063 | goto err_out_free_regions; |
| 3064 | } |
| 3065 | |
| 3066 | memset(hw, 0, sizeof(*hw)); |
| 3067 | hw->pdev = pdev; |
| 3068 | spin_lock_init(&hw->phy_lock); |
| 3069 | tasklet_init(&hw->ext_tasklet, skge_extirq, (unsigned long) hw); |
| 3070 | |
| 3071 | hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000); |
| 3072 | if (!hw->regs) { |
| 3073 | printk(KERN_ERR PFX "%s: cannot map device registers\n", |
| 3074 | pci_name(pdev)); |
| 3075 | goto err_out_free_hw; |
| 3076 | } |
| 3077 | |
| 3078 | if ((err = request_irq(pdev->irq, skge_intr, SA_SHIRQ, DRV_NAME, hw))) { |
| 3079 | printk(KERN_ERR PFX "%s: cannot assign irq %d\n", |
| 3080 | pci_name(pdev), pdev->irq); |
| 3081 | goto err_out_iounmap; |
| 3082 | } |
| 3083 | pci_set_drvdata(pdev, hw); |
| 3084 | |
| 3085 | err = skge_reset(hw); |
| 3086 | if (err) |
| 3087 | goto err_out_free_irq; |
| 3088 | |
| 3089 | printk(KERN_INFO PFX "addr 0x%lx irq %d chip %s rev %d\n", |
| 3090 | pci_resource_start(pdev, 0), pdev->irq, |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 3091 | skge_board_name(hw), hw->chip_rev); |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3092 | |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 3093 | if ((dev = skge_devinit(hw, 0, using_dac)) == NULL) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3094 | goto err_out_led_off; |
| 3095 | |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3096 | if ((err = register_netdev(dev))) { |
| 3097 | printk(KERN_ERR PFX "%s: cannot register net device\n", |
| 3098 | pci_name(pdev)); |
| 3099 | goto err_out_free_netdev; |
| 3100 | } |
| 3101 | |
| 3102 | skge_show_addr(dev); |
| 3103 | |
Stephen Hemminger | 981d037 | 2005-06-27 11:33:06 -0700 | [diff] [blame] | 3104 | if (hw->ports > 1 && (dev1 = skge_devinit(hw, 1, using_dac))) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3105 | if (register_netdev(dev1) == 0) |
| 3106 | skge_show_addr(dev1); |
| 3107 | else { |
| 3108 | /* Failure to register second port need not be fatal */ |
| 3109 | printk(KERN_WARNING PFX "register of second port failed\n"); |
| 3110 | hw->dev[1] = NULL; |
| 3111 | free_netdev(dev1); |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | return 0; |
| 3116 | |
| 3117 | err_out_free_netdev: |
| 3118 | free_netdev(dev); |
| 3119 | err_out_led_off: |
| 3120 | skge_write16(hw, B0_LED, LED_STAT_OFF); |
| 3121 | err_out_free_irq: |
| 3122 | free_irq(pdev->irq, hw); |
| 3123 | err_out_iounmap: |
| 3124 | iounmap(hw->regs); |
| 3125 | err_out_free_hw: |
| 3126 | kfree(hw); |
| 3127 | err_out_free_regions: |
| 3128 | pci_release_regions(pdev); |
| 3129 | err_out_disable_pdev: |
| 3130 | pci_disable_device(pdev); |
| 3131 | pci_set_drvdata(pdev, NULL); |
| 3132 | err_out: |
| 3133 | return err; |
| 3134 | } |
| 3135 | |
| 3136 | static void __devexit skge_remove(struct pci_dev *pdev) |
| 3137 | { |
| 3138 | struct skge_hw *hw = pci_get_drvdata(pdev); |
| 3139 | struct net_device *dev0, *dev1; |
| 3140 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 3141 | if (!hw) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3142 | return; |
| 3143 | |
| 3144 | if ((dev1 = hw->dev[1])) |
| 3145 | unregister_netdev(dev1); |
| 3146 | dev0 = hw->dev[0]; |
| 3147 | unregister_netdev(dev0); |
| 3148 | |
| 3149 | tasklet_kill(&hw->ext_tasklet); |
| 3150 | |
| 3151 | free_irq(pdev->irq, hw); |
| 3152 | pci_release_regions(pdev); |
| 3153 | pci_disable_device(pdev); |
| 3154 | if (dev1) |
| 3155 | free_netdev(dev1); |
| 3156 | free_netdev(dev0); |
| 3157 | skge_write16(hw, B0_LED, LED_STAT_OFF); |
| 3158 | iounmap(hw->regs); |
| 3159 | kfree(hw); |
| 3160 | pci_set_drvdata(pdev, NULL); |
| 3161 | } |
| 3162 | |
| 3163 | #ifdef CONFIG_PM |
| 3164 | static int skge_suspend(struct pci_dev *pdev, u32 state) |
| 3165 | { |
| 3166 | struct skge_hw *hw = pci_get_drvdata(pdev); |
| 3167 | int i, wol = 0; |
| 3168 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 3169 | for (i = 0; i < 2; i++) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3170 | struct net_device *dev = hw->dev[i]; |
| 3171 | |
| 3172 | if (dev) { |
| 3173 | struct skge_port *skge = netdev_priv(dev); |
| 3174 | if (netif_running(dev)) { |
| 3175 | netif_carrier_off(dev); |
| 3176 | skge_down(dev); |
| 3177 | } |
| 3178 | netif_device_detach(dev); |
| 3179 | wol |= skge->wol; |
| 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | pci_save_state(pdev); |
| 3184 | pci_enable_wake(pdev, state, wol); |
| 3185 | pci_disable_device(pdev); |
| 3186 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 3187 | |
| 3188 | return 0; |
| 3189 | } |
| 3190 | |
| 3191 | static int skge_resume(struct pci_dev *pdev) |
| 3192 | { |
| 3193 | struct skge_hw *hw = pci_get_drvdata(pdev); |
| 3194 | int i; |
| 3195 | |
| 3196 | pci_set_power_state(pdev, PCI_D0); |
| 3197 | pci_restore_state(pdev); |
| 3198 | pci_enable_wake(pdev, PCI_D0, 0); |
| 3199 | |
| 3200 | skge_reset(hw); |
| 3201 | |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 3202 | for (i = 0; i < 2; i++) { |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3203 | struct net_device *dev = hw->dev[i]; |
| 3204 | if (dev) { |
| 3205 | netif_device_attach(dev); |
Stephen Hemminger | 9556606 | 2005-06-27 11:33:02 -0700 | [diff] [blame] | 3206 | if (netif_running(dev)) |
Stephen Hemminger | baef58b | 2005-05-12 20:14:36 -0400 | [diff] [blame] | 3207 | skge_up(dev); |
| 3208 | } |
| 3209 | } |
| 3210 | return 0; |
| 3211 | } |
| 3212 | #endif |
| 3213 | |
| 3214 | static struct pci_driver skge_driver = { |
| 3215 | .name = DRV_NAME, |
| 3216 | .id_table = skge_id_table, |
| 3217 | .probe = skge_probe, |
| 3218 | .remove = __devexit_p(skge_remove), |
| 3219 | #ifdef CONFIG_PM |
| 3220 | .suspend = skge_suspend, |
| 3221 | .resume = skge_resume, |
| 3222 | #endif |
| 3223 | }; |
| 3224 | |
| 3225 | static int __init skge_init_module(void) |
| 3226 | { |
| 3227 | return pci_module_init(&skge_driver); |
| 3228 | } |
| 3229 | |
| 3230 | static void __exit skge_cleanup_module(void) |
| 3231 | { |
| 3232 | pci_unregister_driver(&skge_driver); |
| 3233 | } |
| 3234 | |
| 3235 | module_init(skge_init_module); |
| 3236 | module_exit(skge_cleanup_module); |