diff options
Diffstat (limited to 'drivers/net/sky2.c')
| -rw-r--r-- | drivers/net/sky2.c | 3262 |
1 files changed, 3262 insertions, 0 deletions
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c new file mode 100644 index 000000000000..f5d697c0c031 --- /dev/null +++ b/drivers/net/sky2.c | |||
| @@ -0,0 +1,3262 @@ | |||
| 1 | /* | ||
| 2 | * New driver for Marvell Yukon 2 chipset. | ||
| 3 | * Based on earlier sk98lin, and skge driver. | ||
| 4 | * | ||
| 5 | * This driver intentionally does not support all the features | ||
| 6 | * of the original driver such as link fail-over and link management because | ||
| 7 | * those should be done at higher levels. | ||
| 8 | * | ||
| 9 | * Copyright (C) 2005 Stephen Hemminger <shemminger@osdl.org> | ||
| 10 | * | ||
| 11 | * This program is free software; you can redistribute it and/or modify | ||
| 12 | * it under the terms of the GNU General Public License as published by | ||
| 13 | * the Free Software Foundation; either version 2 of the License, or | ||
| 14 | * (at your option) any later version. | ||
| 15 | * | ||
| 16 | * This program is distributed in the hope that it will be useful, | ||
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | * GNU General Public License for more details. | ||
| 20 | * | ||
| 21 | * You should have received a copy of the GNU General Public License | ||
| 22 | * along with this program; if not, write to the Free Software | ||
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 24 | */ | ||
| 25 | |||
| 26 | /* | ||
| 27 | * TOTEST | ||
| 28 | * - speed setting | ||
| 29 | * - suspend/resume | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include <linux/config.h> | ||
| 33 | #include <linux/crc32.h> | ||
| 34 | #include <linux/kernel.h> | ||
| 35 | #include <linux/version.h> | ||
| 36 | #include <linux/module.h> | ||
| 37 | #include <linux/netdevice.h> | ||
| 38 | #include <linux/dma-mapping.h> | ||
| 39 | #include <linux/etherdevice.h> | ||
| 40 | #include <linux/ethtool.h> | ||
| 41 | #include <linux/pci.h> | ||
| 42 | #include <linux/ip.h> | ||
| 43 | #include <linux/tcp.h> | ||
| 44 | #include <linux/in.h> | ||
| 45 | #include <linux/delay.h> | ||
| 46 | #include <linux/workqueue.h> | ||
| 47 | #include <linux/if_vlan.h> | ||
| 48 | #include <linux/prefetch.h> | ||
| 49 | #include <linux/mii.h> | ||
| 50 | |||
| 51 | #include <asm/irq.h> | ||
| 52 | |||
| 53 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) | ||
| 54 | #define SKY2_VLAN_TAG_USED 1 | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #include "sky2.h" | ||
| 58 | |||
| 59 | #define DRV_NAME "sky2" | ||
| 60 | #define DRV_VERSION "0.11" | ||
| 61 | #define PFX DRV_NAME " " | ||
| 62 | |||
| 63 | /* | ||
| 64 | * The Yukon II chipset takes 64 bit command blocks (called list elements) | ||
| 65 | * that are organized into three (receive, transmit, status) different rings | ||
| 66 | * similar to Tigon3. A transmit can require several elements; | ||
| 67 | * a receive requires one (or two if using 64 bit dma). | ||
| 68 | */ | ||
| 69 | |||
| 70 | #define is_ec_a1(hw) \ | ||
| 71 | unlikely((hw)->chip_id == CHIP_ID_YUKON_EC && \ | ||
| 72 | (hw)->chip_rev == CHIP_REV_YU_EC_A1) | ||
| 73 | |||
| 74 | #define RX_LE_SIZE 512 | ||
| 75 | #define RX_LE_BYTES (RX_LE_SIZE*sizeof(struct sky2_rx_le)) | ||
| 76 | #define RX_MAX_PENDING (RX_LE_SIZE/2 - 2) | ||
| 77 | #define RX_DEF_PENDING RX_MAX_PENDING | ||
| 78 | |||
| 79 | #define TX_RING_SIZE 512 | ||
| 80 | #define TX_DEF_PENDING (TX_RING_SIZE - 1) | ||
| 81 | #define TX_MIN_PENDING 64 | ||
| 82 | #define MAX_SKB_TX_LE (4 + 2*MAX_SKB_FRAGS) | ||
| 83 | |||
| 84 | #define STATUS_RING_SIZE 2048 /* 2 ports * (TX + 2*RX) */ | ||
| 85 | #define STATUS_LE_BYTES (STATUS_RING_SIZE*sizeof(struct sky2_status_le)) | ||
| 86 | #define ETH_JUMBO_MTU 9000 | ||
| 87 | #define TX_WATCHDOG (5 * HZ) | ||
| 88 | #define NAPI_WEIGHT 64 | ||
| 89 | #define PHY_RETRIES 1000 | ||
| 90 | |||
| 91 | static const u32 default_msg = | ||
| 92 | NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | ||
| 93 | | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR | ||
| 94 | | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN | NETIF_MSG_INTR; | ||
| 95 | |||
| 96 | static int debug = -1; /* defaults above */ | ||
| 97 | module_param(debug, int, 0); | ||
| 98 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); | ||
| 99 | |||
| 100 | static int copybreak __read_mostly = 256; | ||
| 101 | module_param(copybreak, int, 0); | ||
| 102 | MODULE_PARM_DESC(copybreak, "Receive copy threshold"); | ||
| 103 | |||
| 104 | static const struct pci_device_id sky2_id_table[] = { | ||
| 105 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) }, | ||
| 106 | { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, | ||
| 107 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) }, | ||
| 108 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) }, | ||
| 109 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) }, | ||
| 110 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) }, | ||
| 111 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) }, | ||
| 112 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4343) }, | ||
| 113 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4344) }, | ||
| 114 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4345) }, | ||
| 115 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4346) }, | ||
| 116 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4347) }, | ||
| 117 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4350) }, | ||
| 118 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4351) }, | ||
| 119 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4352) }, | ||
| 120 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4360) }, | ||
| 121 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) }, | ||
| 122 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4362) }, | ||
| 123 | { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4363) }, | ||
| 124 | { 0 } | ||
| 125 | }; | ||
| 126 | |||
| 127 | MODULE_DEVICE_TABLE(pci, sky2_id_table); | ||
| 128 | |||
| 129 | /* Avoid conditionals by using array */ | ||
| 130 | static const unsigned txqaddr[] = { Q_XA1, Q_XA2 }; | ||
| 131 | static const unsigned rxqaddr[] = { Q_R1, Q_R2 }; | ||
| 132 | |||
| 133 | /* This driver supports yukon2 chipset only */ | ||
| 134 | static const char *yukon2_name[] = { | ||
| 135 | "XL", /* 0xb3 */ | ||
| 136 | "EC Ultra", /* 0xb4 */ | ||
| 137 | "UNKNOWN", /* 0xb5 */ | ||
| 138 | "EC", /* 0xb6 */ | ||
| 139 | "FE", /* 0xb7 */ | ||
| 140 | }; | ||
| 141 | |||
| 142 | /* Access to external PHY */ | ||
| 143 | static int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val) | ||
| 144 | { | ||
| 145 | int i; | ||
| 146 | |||
| 147 | gma_write16(hw, port, GM_SMI_DATA, val); | ||
| 148 | gma_write16(hw, port, GM_SMI_CTRL, | ||
| 149 | GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) | GM_SMI_CT_REG_AD(reg)); | ||
| 150 | |||
| 151 | for (i = 0; i < PHY_RETRIES; i++) { | ||
| 152 | if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY)) | ||
| 153 | return 0; | ||
| 154 | udelay(1); | ||
| 155 | } | ||
| 156 | |||
| 157 | printk(KERN_WARNING PFX "%s: phy write timeout\n", hw->dev[port]->name); | ||
| 158 | return -ETIMEDOUT; | ||
| 159 | } | ||
| 160 | |||
| 161 | static int __gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg, u16 *val) | ||
| 162 | { | ||
| 163 | int i; | ||
| 164 | |||
| 165 | gma_write16(hw, port, GM_SMI_CTRL, GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) | ||
| 166 | | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD); | ||
| 167 | |||
| 168 | for (i = 0; i < PHY_RETRIES; i++) { | ||
| 169 | if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL) { | ||
| 170 | *val = gma_read16(hw, port, GM_SMI_DATA); | ||
| 171 | return 0; | ||
| 172 | } | ||
| 173 | |||
| 174 | udelay(1); | ||
| 175 | } | ||
| 176 | |||
| 177 | return -ETIMEDOUT; | ||
| 178 | } | ||
| 179 | |||
| 180 | static u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg) | ||
| 181 | { | ||
| 182 | u16 v; | ||
| 183 | |||
| 184 | if (__gm_phy_read(hw, port, reg, &v) != 0) | ||
| 185 | printk(KERN_WARNING PFX "%s: phy read timeout\n", hw->dev[port]->name); | ||
| 186 | return v; | ||
| 187 | } | ||
| 188 | |||
| 189 | static int sky2_set_power_state(struct sky2_hw *hw, pci_power_t state) | ||
| 190 | { | ||
| 191 | u16 power_control; | ||
| 192 | u32 reg1; | ||
| 193 | int vaux; | ||
| 194 | int ret = 0; | ||
| 195 | |||
| 196 | pr_debug("sky2_set_power_state %d\n", state); | ||
| 197 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); | ||
| 198 | |||
| 199 | pci_read_config_word(hw->pdev, hw->pm_cap + PCI_PM_PMC, &power_control); | ||
| 200 | vaux = (sky2_read8(hw, B0_CTST) & Y2_VAUX_AVAIL) && | ||
| 201 | (power_control & PCI_PM_CAP_PME_D3cold); | ||
| 202 | |||
| 203 | pci_read_config_word(hw->pdev, hw->pm_cap + PCI_PM_CTRL, &power_control); | ||
| 204 | |||
| 205 | power_control |= PCI_PM_CTRL_PME_STATUS; | ||
| 206 | power_control &= ~(PCI_PM_CTRL_STATE_MASK); | ||
| 207 | |||
| 208 | switch (state) { | ||
| 209 | case PCI_D0: | ||
| 210 | /* switch power to VCC (WA for VAUX problem) */ | ||
| 211 | sky2_write8(hw, B0_POWER_CTRL, | ||
| 212 | PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON); | ||
| 213 | |||
| 214 | /* disable Core Clock Division, */ | ||
| 215 | sky2_write32(hw, B2_Y2_CLK_CTRL, Y2_CLK_DIV_DIS); | ||
| 216 | |||
| 217 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) | ||
| 218 | /* enable bits are inverted */ | ||
| 219 | sky2_write8(hw, B2_Y2_CLK_GATE, | ||
| 220 | Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS | | ||
| 221 | Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS | | ||
| 222 | Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS); | ||
| 223 | else | ||
| 224 | sky2_write8(hw, B2_Y2_CLK_GATE, 0); | ||
| 225 | |||
| 226 | /* Turn off phy power saving */ | ||
| 227 | pci_read_config_dword(hw->pdev, PCI_DEV_REG1, ®1); | ||
| 228 | reg1 &= ~(PCI_Y2_PHY1_POWD | PCI_Y2_PHY2_POWD); | ||
| 229 | |||
| 230 | /* looks like this XL is back asswards .. */ | ||
| 231 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) { | ||
| 232 | reg1 |= PCI_Y2_PHY1_COMA; | ||
| 233 | if (hw->ports > 1) | ||
| 234 | reg1 |= PCI_Y2_PHY2_COMA; | ||
| 235 | } | ||
| 236 | pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg1); | ||
| 237 | break; | ||
| 238 | |||
| 239 | case PCI_D3hot: | ||
| 240 | case PCI_D3cold: | ||
| 241 | /* Turn on phy power saving */ | ||
| 242 | pci_read_config_dword(hw->pdev, PCI_DEV_REG1, ®1); | ||
| 243 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) | ||
| 244 | reg1 &= ~(PCI_Y2_PHY1_POWD | PCI_Y2_PHY2_POWD); | ||
| 245 | else | ||
| 246 | reg1 |= (PCI_Y2_PHY1_POWD | PCI_Y2_PHY2_POWD); | ||
| 247 | pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg1); | ||
| 248 | |||
| 249 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) | ||
| 250 | sky2_write8(hw, B2_Y2_CLK_GATE, 0); | ||
| 251 | else | ||
| 252 | /* enable bits are inverted */ | ||
| 253 | sky2_write8(hw, B2_Y2_CLK_GATE, | ||
| 254 | Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS | | ||
| 255 | Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS | | ||
| 256 | Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS); | ||
| 257 | |||
| 258 | /* switch power to VAUX */ | ||
| 259 | if (vaux && state != PCI_D3cold) | ||
| 260 | sky2_write8(hw, B0_POWER_CTRL, | ||
| 261 | (PC_VAUX_ENA | PC_VCC_ENA | | ||
| 262 | PC_VAUX_ON | PC_VCC_OFF)); | ||
| 263 | break; | ||
| 264 | default: | ||
| 265 | printk(KERN_ERR PFX "Unknown power state %d\n", state); | ||
| 266 | ret = -1; | ||
| 267 | } | ||
| 268 | |||
| 269 | pci_write_config_byte(hw->pdev, hw->pm_cap + PCI_PM_CTRL, power_control); | ||
| 270 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); | ||
| 271 | return ret; | ||
| 272 | } | ||
| 273 | |||
| 274 | static void sky2_phy_reset(struct sky2_hw *hw, unsigned port) | ||
| 275 | { | ||
| 276 | u16 reg; | ||
| 277 | |||
| 278 | /* disable all GMAC IRQ's */ | ||
| 279 | sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0); | ||
| 280 | /* disable PHY IRQs */ | ||
| 281 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0); | ||
| 282 | |||
| 283 | gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */ | ||
| 284 | gma_write16(hw, port, GM_MC_ADDR_H2, 0); | ||
| 285 | gma_write16(hw, port, GM_MC_ADDR_H3, 0); | ||
| 286 | gma_write16(hw, port, GM_MC_ADDR_H4, 0); | ||
| 287 | |||
| 288 | reg = gma_read16(hw, port, GM_RX_CTRL); | ||
| 289 | reg |= GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA; | ||
| 290 | gma_write16(hw, port, GM_RX_CTRL, reg); | ||
| 291 | } | ||
| 292 | |||
| 293 | static void sky2_phy_init(struct sky2_hw *hw, unsigned port) | ||
| 294 | { | ||
| 295 | struct sky2_port *sky2 = netdev_priv(hw->dev[port]); | ||
| 296 | u16 ctrl, ct1000, adv, pg, ledctrl, ledover; | ||
| 297 | |||
| 298 | if (sky2->autoneg == AUTONEG_ENABLE && hw->chip_id != CHIP_ID_YUKON_XL) { | ||
| 299 | u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL); | ||
| 300 | |||
| 301 | ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK | | ||
| 302 | PHY_M_EC_MAC_S_MSK); | ||
| 303 | ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ); | ||
| 304 | |||
| 305 | if (hw->chip_id == CHIP_ID_YUKON_EC) | ||
| 306 | ectrl |= PHY_M_EC_DSC_2(2) | PHY_M_EC_DOWN_S_ENA; | ||
| 307 | else | ||
| 308 | ectrl |= PHY_M_EC_M_DSC(2) | PHY_M_EC_S_DSC(3); | ||
| 309 | |||
| 310 | gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl); | ||
| 311 | } | ||
| 312 | |||
| 313 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); | ||
| 314 | if (hw->copper) { | ||
| 315 | if (hw->chip_id == CHIP_ID_YUKON_FE) { | ||
| 316 | /* enable automatic crossover */ | ||
| 317 | ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO) >> 1; | ||
| 318 | } else { | ||
| 319 | /* disable energy detect */ | ||
| 320 | ctrl &= ~PHY_M_PC_EN_DET_MSK; | ||
| 321 | |||
| 322 | /* enable automatic crossover */ | ||
| 323 | ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO); | ||
| 324 | |||
| 325 | if (sky2->autoneg == AUTONEG_ENABLE && | ||
| 326 | hw->chip_id == CHIP_ID_YUKON_XL) { | ||
| 327 | ctrl &= ~PHY_M_PC_DSC_MSK; | ||
| 328 | ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA; | ||
| 329 | } | ||
| 330 | } | ||
| 331 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); | ||
| 332 | } else { | ||
| 333 | /* workaround for deviation #4.88 (CRC errors) */ | ||
| 334 | /* disable Automatic Crossover */ | ||
| 335 | |||
| 336 | ctrl &= ~PHY_M_PC_MDIX_MSK; | ||
| 337 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); | ||
| 338 | |||
| 339 | if (hw->chip_id == CHIP_ID_YUKON_XL) { | ||
| 340 | /* Fiber: select 1000BASE-X only mode MAC Specific Ctrl Reg. */ | ||
| 341 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 2); | ||
| 342 | ctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); | ||
| 343 | ctrl &= ~PHY_M_MAC_MD_MSK; | ||
| 344 | ctrl |= PHY_M_MAC_MODE_SEL(PHY_M_MAC_MD_1000BX); | ||
| 345 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ctrl); | ||
| 346 | |||
| 347 | /* select page 1 to access Fiber registers */ | ||
| 348 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 1); | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 352 | ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL); | ||
| 353 | if (sky2->autoneg == AUTONEG_DISABLE) | ||
| 354 | ctrl &= ~PHY_CT_ANE; | ||
| 355 | else | ||
| 356 | ctrl |= PHY_CT_ANE; | ||
| 357 | |||
| 358 | ctrl |= PHY_CT_RESET; | ||
| 359 | gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); | ||
| 360 | |||
| 361 | ctrl = 0; | ||
| 362 | ct1000 = 0; | ||
| 363 | adv = PHY_AN_CSMA; | ||
| 364 | |||
| 365 | if (sky2->autoneg == AUTONEG_ENABLE) { | ||
| 366 | if (hw->copper) { | ||
| 367 | if (sky2->advertising & ADVERTISED_1000baseT_Full) | ||
| 368 | ct1000 |= PHY_M_1000C_AFD; | ||
| 369 | if (sky2->advertising & ADVERTISED_1000baseT_Half) | ||
| 370 | ct1000 |= PHY_M_1000C_AHD; | ||
| 371 | if (sky2->advertising & ADVERTISED_100baseT_Full) | ||
| 372 | adv |= PHY_M_AN_100_FD; | ||
| 373 | if (sky2->advertising & ADVERTISED_100baseT_Half) | ||
| 374 | adv |= PHY_M_AN_100_HD; | ||
| 375 | if (sky2->advertising & ADVERTISED_10baseT_Full) | ||
| 376 | adv |= PHY_M_AN_10_FD; | ||
| 377 | if (sky2->advertising & ADVERTISED_10baseT_Half) | ||
| 378 | adv |= PHY_M_AN_10_HD; | ||
| 379 | } else /* special defines for FIBER (88E1011S only) */ | ||
| 380 | adv |= PHY_M_AN_1000X_AHD | PHY_M_AN_1000X_AFD; | ||
| 381 | |||
| 382 | /* Set Flow-control capabilities */ | ||
| 383 | if (sky2->tx_pause && sky2->rx_pause) | ||
| 384 | adv |= PHY_AN_PAUSE_CAP; /* symmetric */ | ||
| 385 | else if (sky2->rx_pause && !sky2->tx_pause) | ||
| 386 | adv |= PHY_AN_PAUSE_ASYM | PHY_AN_PAUSE_CAP; | ||
| 387 | else if (!sky2->rx_pause && sky2->tx_pause) | ||
| 388 | adv |= PHY_AN_PAUSE_ASYM; /* local */ | ||
| 389 | |||
| 390 | /* Restart Auto-negotiation */ | ||
| 391 | ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG; | ||
| 392 | } else { | ||
| 393 | /* forced speed/duplex settings */ | ||
| 394 | ct1000 = PHY_M_1000C_MSE; | ||
| 395 | |||
| 396 | if (sky2->duplex == DUPLEX_FULL) | ||
| 397 | ctrl |= PHY_CT_DUP_MD; | ||
| 398 | |||
| 399 | switch (sky2->speed) { | ||
| 400 | case SPEED_1000: | ||
| 401 | ctrl |= PHY_CT_SP1000; | ||
| 402 | break; | ||
| 403 | case SPEED_100: | ||
| 404 | ctrl |= PHY_CT_SP100; | ||
| 405 | break; | ||
| 406 | } | ||
| 407 | |||
| 408 | ctrl |= PHY_CT_RESET; | ||
| 409 | } | ||
| 410 | |||
| 411 | if (hw->chip_id != CHIP_ID_YUKON_FE) | ||
| 412 | gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000); | ||
| 413 | |||
| 414 | gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv); | ||
| 415 | gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); | ||
| 416 | |||
| 417 | /* Setup Phy LED's */ | ||
| 418 | ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS); | ||
| 419 | ledover = 0; | ||
| 420 | |||
| 421 | switch (hw->chip_id) { | ||
| 422 | case CHIP_ID_YUKON_FE: | ||
| 423 | /* on 88E3082 these bits are at 11..9 (shifted left) */ | ||
| 424 | ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) << 1; | ||
| 425 | |||
| 426 | ctrl = gm_phy_read(hw, port, PHY_MARV_FE_LED_PAR); | ||
| 427 | |||
| 428 | /* delete ACT LED control bits */ | ||
| 429 | ctrl &= ~PHY_M_FELP_LED1_MSK; | ||
| 430 | /* change ACT LED control to blink mode */ | ||
| 431 | ctrl |= PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_ACT_BL); | ||
| 432 | gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR, ctrl); | ||
| 433 | break; | ||
| 434 | |||
| 435 | case CHIP_ID_YUKON_XL: | ||
| 436 | pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); | ||
| 437 | |||
| 438 | /* select page 3 to access LED control register */ | ||
| 439 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); | ||
| 440 | |||
| 441 | /* set LED Function Control register */ | ||
| 442 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, (PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */ | ||
| 443 | PHY_M_LEDC_INIT_CTRL(7) | /* 10 Mbps */ | ||
| 444 | PHY_M_LEDC_STA1_CTRL(7) | /* 100 Mbps */ | ||
| 445 | PHY_M_LEDC_STA0_CTRL(7))); /* 1000 Mbps */ | ||
| 446 | |||
| 447 | /* set Polarity Control register */ | ||
| 448 | gm_phy_write(hw, port, PHY_MARV_PHY_STAT, | ||
| 449 | (PHY_M_POLC_LS1_P_MIX(4) | | ||
| 450 | PHY_M_POLC_IS0_P_MIX(4) | | ||
| 451 | PHY_M_POLC_LOS_CTRL(2) | | ||
| 452 | PHY_M_POLC_INIT_CTRL(2) | | ||
| 453 | PHY_M_POLC_STA1_CTRL(2) | | ||
| 454 | PHY_M_POLC_STA0_CTRL(2))); | ||
| 455 | |||
| 456 | /* restore page register */ | ||
| 457 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); | ||
| 458 | break; | ||
| 459 | |||
| 460 | default: | ||
| 461 | /* set Tx LED (LED_TX) to blink mode on Rx OR Tx activity */ | ||
| 462 | ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL; | ||
| 463 | /* turn off the Rx LED (LED_RX) */ | ||
| 464 | ledover |= PHY_M_LED_MO_RX(MO_LED_OFF); | ||
| 465 | } | ||
| 466 | |||
| 467 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl); | ||
| 468 | |||
| 469 | if (sky2->autoneg == AUTONEG_DISABLE || sky2->speed == SPEED_100) { | ||
| 470 | /* turn on 100 Mbps LED (LED_LINK100) */ | ||
| 471 | ledover |= PHY_M_LED_MO_100(MO_LED_ON); | ||
| 472 | } | ||
| 473 | |||
| 474 | if (ledover) | ||
| 475 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover); | ||
| 476 | |||
| 477 | /* Enable phy interrupt on auto-negotiation complete (or link up) */ | ||
| 478 | if (sky2->autoneg == AUTONEG_ENABLE) | ||
| 479 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL); | ||
| 480 | else | ||
| 481 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); | ||
| 482 | } | ||
| 483 | |||
| 484 | /* Force a renegotiation */ | ||
| 485 | static void sky2_phy_reinit(struct sky2_port *sky2) | ||
| 486 | { | ||
| 487 | down(&sky2->phy_sema); | ||
| 488 | sky2_phy_init(sky2->hw, sky2->port); | ||
| 489 | up(&sky2->phy_sema); | ||
| 490 | } | ||
| 491 | |||
| 492 | static void sky2_mac_init(struct sky2_hw *hw, unsigned port) | ||
| 493 | { | ||
| 494 | struct sky2_port *sky2 = netdev_priv(hw->dev[port]); | ||
| 495 | u16 reg; | ||
| 496 | int i; | ||
| 497 | const u8 *addr = hw->dev[port]->dev_addr; | ||
| 498 | |||
| 499 | sky2_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); | ||
| 500 | sky2_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR|GPC_ENA_PAUSE); | ||
| 501 | |||
| 502 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR); | ||
| 503 | |||
| 504 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 && port == 1) { | ||
| 505 | /* WA DEV_472 -- looks like crossed wires on port 2 */ | ||
| 506 | /* clear GMAC 1 Control reset */ | ||
| 507 | sky2_write8(hw, SK_REG(0, GMAC_CTRL), GMC_RST_CLR); | ||
| 508 | do { | ||
| 509 | sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_SET); | ||
| 510 | sky2_write8(hw, SK_REG(1, GMAC_CTRL), GMC_RST_CLR); | ||
| 511 | } while (gm_phy_read(hw, 1, PHY_MARV_ID0) != PHY_MARV_ID0_VAL || | ||
| 512 | gm_phy_read(hw, 1, PHY_MARV_ID1) != PHY_MARV_ID1_Y2 || | ||
| 513 | gm_phy_read(hw, 1, PHY_MARV_INT_MASK) != 0); | ||
| 514 | } | ||
| 515 | |||
| 516 | if (sky2->autoneg == AUTONEG_DISABLE) { | ||
| 517 | reg = gma_read16(hw, port, GM_GP_CTRL); | ||
| 518 | reg |= GM_GPCR_AU_ALL_DIS; | ||
| 519 | gma_write16(hw, port, GM_GP_CTRL, reg); | ||
| 520 | gma_read16(hw, port, GM_GP_CTRL); | ||
| 521 | |||
| 522 | switch (sky2->speed) { | ||
| 523 | case SPEED_1000: | ||
| 524 | reg |= GM_GPCR_SPEED_1000; | ||
| 525 | /* fallthru */ | ||
| 526 | case SPEED_100: | ||
| 527 | reg |= GM_GPCR_SPEED_100; | ||
| 528 | } | ||
| 529 | |||
| 530 | if (sky2->duplex == DUPLEX_FULL) | ||
| 531 | reg |= GM_GPCR_DUP_FULL; | ||
| 532 | } else | ||
| 533 | reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL; | ||
| 534 | |||
| 535 | if (!sky2->tx_pause && !sky2->rx_pause) { | ||
| 536 | sky2_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); | ||
| 537 | reg |= | ||
| 538 | GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; | ||
| 539 | } else if (sky2->tx_pause && !sky2->rx_pause) { | ||
| 540 | /* disable Rx flow-control */ | ||
| 541 | reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; | ||
| 542 | } | ||
| 543 | |||
| 544 | gma_write16(hw, port, GM_GP_CTRL, reg); | ||
| 545 | |||
| 546 | sky2_read16(hw, SK_REG(port, GMAC_IRQ_SRC)); | ||
| 547 | |||
| 548 | down(&sky2->phy_sema); | ||
| 549 | sky2_phy_init(hw, port); | ||
| 550 | up(&sky2->phy_sema); | ||
| 551 | |||
| 552 | /* MIB clear */ | ||
| 553 | reg = gma_read16(hw, port, GM_PHY_ADDR); | ||
| 554 | gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR); | ||
| 555 | |||
| 556 | for (i = 0; i < GM_MIB_CNT_SIZE; i++) | ||
| 557 | gma_read16(hw, port, GM_MIB_CNT_BASE + 8 * i); | ||
| 558 | gma_write16(hw, port, GM_PHY_ADDR, reg); | ||
| 559 | |||
| 560 | /* transmit control */ | ||
| 561 | gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF)); | ||
| 562 | |||
| 563 | /* receive control reg: unicast + multicast + no FCS */ | ||
| 564 | gma_write16(hw, port, GM_RX_CTRL, | ||
| 565 | GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA); | ||
| 566 | |||
| 567 | /* transmit flow control */ | ||
| 568 | gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff); | ||
| 569 | |||
| 570 | /* transmit parameter */ | ||
| 571 | gma_write16(hw, port, GM_TX_PARAM, | ||
| 572 | TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) | | ||
| 573 | TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) | | ||
| 574 | TX_IPG_JAM_DATA(TX_IPG_JAM_DEF) | | ||
| 575 | TX_BACK_OFF_LIM(TX_BOF_LIM_DEF)); | ||
| 576 | |||
| 577 | /* serial mode register */ | ||
| 578 | reg = DATA_BLIND_VAL(DATA_BLIND_DEF) | | ||
| 579 | GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF); | ||
| 580 | |||
| 581 | if (hw->dev[port]->mtu > ETH_DATA_LEN) | ||
| 582 | reg |= GM_SMOD_JUMBO_ENA; | ||
| 583 | |||
| 584 | gma_write16(hw, port, GM_SERIAL_MODE, reg); | ||
| 585 | |||
| 586 | /* virtual address for data */ | ||
| 587 | gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr); | ||
| 588 | |||
| 589 | /* physical address: used for pause frames */ | ||
| 590 | gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr); | ||
| 591 | |||
| 592 | /* ignore counter overflows */ | ||
| 593 | gma_write16(hw, port, GM_TX_IRQ_MSK, 0); | ||
| 594 | gma_write16(hw, port, GM_RX_IRQ_MSK, 0); | ||
| 595 | gma_write16(hw, port, GM_TR_IRQ_MSK, 0); | ||
| 596 | |||
| 597 | /* Configure Rx MAC FIFO */ | ||
| 598 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); | ||
| 599 | sky2_write16(hw, SK_REG(port, RX_GMF_CTRL_T), | ||
| 600 | GMF_RX_CTRL_DEF); | ||
| 601 | |||
| 602 | /* Flush Rx MAC FIFO on any flow control or error */ | ||
| 603 | sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR); | ||
| 604 | |||
| 605 | /* Set threshold to 0xa (64 bytes) | ||
| 606 | * ASF disabled so no need to do WA dev #4.30 | ||
| 607 | */ | ||
| 608 | sky2_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF); | ||
| 609 | |||
| 610 | /* Configure Tx MAC FIFO */ | ||
| 611 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR); | ||
| 612 | sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON); | ||
| 613 | |||
| 614 | if (hw->chip_id == CHIP_ID_YUKON_EC_U) { | ||
| 615 | sky2_write8(hw, SK_REG(port, RX_GMF_LP_THR), 768/8); | ||
| 616 | sky2_write8(hw, SK_REG(port, RX_GMF_UP_THR), 1024/8); | ||
| 617 | if (hw->dev[port]->mtu > ETH_DATA_LEN) { | ||
| 618 | /* set Tx GMAC FIFO Almost Empty Threshold */ | ||
| 619 | sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR), 0x180); | ||
| 620 | /* Disable Store & Forward mode for TX */ | ||
| 621 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_DIS); | ||
| 622 | } | ||
| 623 | } | ||
| 624 | |||
| 625 | } | ||
| 626 | |||
| 627 | static void sky2_ramset(struct sky2_hw *hw, u16 q, u32 start, size_t len) | ||
| 628 | { | ||
| 629 | u32 end; | ||
| 630 | |||
| 631 | start /= 8; | ||
| 632 | len /= 8; | ||
| 633 | end = start + len - 1; | ||
| 634 | |||
| 635 | sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR); | ||
| 636 | sky2_write32(hw, RB_ADDR(q, RB_START), start); | ||
| 637 | sky2_write32(hw, RB_ADDR(q, RB_END), end); | ||
| 638 | sky2_write32(hw, RB_ADDR(q, RB_WP), start); | ||
| 639 | sky2_write32(hw, RB_ADDR(q, RB_RP), start); | ||
| 640 | |||
| 641 | if (q == Q_R1 || q == Q_R2) { | ||
| 642 | u32 rxup, rxlo; | ||
| 643 | |||
| 644 | rxlo = len/2; | ||
| 645 | rxup = rxlo + len/4; | ||
| 646 | |||
| 647 | /* Set thresholds on receive queue's */ | ||
| 648 | sky2_write32(hw, RB_ADDR(q, RB_RX_UTPP), rxup); | ||
| 649 | sky2_write32(hw, RB_ADDR(q, RB_RX_LTPP), rxlo); | ||
| 650 | } else { | ||
| 651 | /* Enable store & forward on Tx queue's because | ||
| 652 | * Tx FIFO is only 1K on Yukon | ||
| 653 | */ | ||
| 654 | sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_STFWD); | ||
| 655 | } | ||
| 656 | |||
| 657 | sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_ENA_OP_MD); | ||
| 658 | sky2_read8(hw, RB_ADDR(q, RB_CTRL)); | ||
| 659 | } | ||
| 660 | |||
| 661 | /* Setup Bus Memory Interface */ | ||
| 662 | static void sky2_qset(struct sky2_hw *hw, u16 q) | ||
| 663 | { | ||
| 664 | sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_RESET); | ||
| 665 | sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_OPER_INIT); | ||
| 666 | sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_FIFO_OP_ON); | ||
| 667 | sky2_write32(hw, Q_ADDR(q, Q_WM), BMU_WM_DEFAULT); | ||
| 668 | } | ||
| 669 | |||
| 670 | /* Setup prefetch unit registers. This is the interface between | ||
| 671 | * hardware and driver list elements | ||
| 672 | */ | ||
| 673 | static void sky2_prefetch_init(struct sky2_hw *hw, u32 qaddr, | ||
| 674 | u64 addr, u32 last) | ||
| 675 | { | ||
| 676 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); | ||
| 677 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_RST_CLR); | ||
| 678 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_HI), addr >> 32); | ||
| 679 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_ADDR_LO), (u32) addr); | ||
| 680 | sky2_write16(hw, Y2_QADDR(qaddr, PREF_UNIT_LAST_IDX), last); | ||
| 681 | sky2_write32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL), PREF_UNIT_OP_ON); | ||
| 682 | |||
| 683 | sky2_read32(hw, Y2_QADDR(qaddr, PREF_UNIT_CTRL)); | ||
| 684 | } | ||
| 685 | |||
| 686 | static inline struct sky2_tx_le *get_tx_le(struct sky2_port *sky2) | ||
| 687 | { | ||
| 688 | struct sky2_tx_le *le = sky2->tx_le + sky2->tx_prod; | ||
| 689 | |||
| 690 | sky2->tx_prod = (sky2->tx_prod + 1) % TX_RING_SIZE; | ||
| 691 | return le; | ||
| 692 | } | ||
| 693 | |||
| 694 | /* | ||
| 695 | * This is a workaround code taken from SysKonnect sk98lin driver | ||
| 696 | * to deal with chip bug on Yukon EC rev 0 in the wraparound case. | ||
| 697 | */ | ||
| 698 | static inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, | ||
| 699 | u16 idx, u16 *last, u16 size) | ||
| 700 | { | ||
| 701 | if (is_ec_a1(hw) && idx < *last) { | ||
| 702 | u16 hwget = sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_GET_IDX)); | ||
| 703 | |||
| 704 | if (hwget == 0) { | ||
| 705 | /* Start prefetching again */ | ||
| 706 | sky2_write8(hw, Y2_QADDR(q, PREF_UNIT_FIFO_WM), 0xe0); | ||
| 707 | goto setnew; | ||
| 708 | } | ||
| 709 | |||
| 710 | if (hwget == size - 1) { | ||
| 711 | /* set watermark to one list element */ | ||
| 712 | sky2_write8(hw, Y2_QADDR(q, PREF_UNIT_FIFO_WM), 8); | ||
| 713 | |||
| 714 | /* set put index to first list element */ | ||
| 715 | sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), 0); | ||
| 716 | } else /* have hardware go to end of list */ | ||
| 717 | sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), | ||
| 718 | size - 1); | ||
| 719 | } else { | ||
| 720 | setnew: | ||
| 721 | sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx); | ||
| 722 | } | ||
| 723 | *last = idx; | ||
| 724 | } | ||
| 725 | |||
| 726 | |||
| 727 | static inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2) | ||
| 728 | { | ||
| 729 | struct sky2_rx_le *le = sky2->rx_le + sky2->rx_put; | ||
| 730 | sky2->rx_put = (sky2->rx_put + 1) % RX_LE_SIZE; | ||
| 731 | return le; | ||
| 732 | } | ||
| 733 | |||
| 734 | /* Return high part of DMA address (could be 32 or 64 bit) */ | ||
| 735 | static inline u32 high32(dma_addr_t a) | ||
| 736 | { | ||
| 737 | return (a >> 16) >> 16; | ||
| 738 | } | ||
| 739 | |||
| 740 | /* Build description to hardware about buffer */ | ||
| 741 | static inline void sky2_rx_add(struct sky2_port *sky2, dma_addr_t map) | ||
| 742 | { | ||
| 743 | struct sky2_rx_le *le; | ||
| 744 | u32 hi = high32(map); | ||
| 745 | u16 len = sky2->rx_bufsize; | ||
| 746 | |||
| 747 | if (sky2->rx_addr64 != hi) { | ||
| 748 | le = sky2_next_rx(sky2); | ||
| 749 | le->addr = cpu_to_le32(hi); | ||
| 750 | le->ctrl = 0; | ||
| 751 | le->opcode = OP_ADDR64 | HW_OWNER; | ||
| 752 | sky2->rx_addr64 = high32(map + len); | ||
| 753 | } | ||
| 754 | |||
| 755 | le = sky2_next_rx(sky2); | ||
| 756 | le->addr = cpu_to_le32((u32) map); | ||
| 757 | le->length = cpu_to_le16(len); | ||
| 758 | le->ctrl = 0; | ||
| 759 | le->opcode = OP_PACKET | HW_OWNER; | ||
| 760 | } | ||
| 761 | |||
| 762 | |||
| 763 | /* Tell chip where to start receive checksum. | ||
| 764 | * Actually has two checksums, but set both same to avoid possible byte | ||
| 765 | * order problems. | ||
| 766 | */ | ||
| 767 | static void rx_set_checksum(struct sky2_port *sky2) | ||
| 768 | { | ||
| 769 | struct sky2_rx_le *le; | ||
| 770 | |||
| 771 | le = sky2_next_rx(sky2); | ||
| 772 | le->addr = (ETH_HLEN << 16) | ETH_HLEN; | ||
| 773 | le->ctrl = 0; | ||
| 774 | le->opcode = OP_TCPSTART | HW_OWNER; | ||
| 775 | |||
| 776 | sky2_write32(sky2->hw, | ||
| 777 | Q_ADDR(rxqaddr[sky2->port], Q_CSR), | ||
| 778 | sky2->rx_csum ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM); | ||
| 779 | |||
| 780 | } | ||
| 781 | |||
| 782 | /* | ||
| 783 | * The RX Stop command will not work for Yukon-2 if the BMU does not | ||
| 784 | * reach the end of packet and since we can't make sure that we have | ||
| 785 | * incoming data, we must reset the BMU while it is not doing a DMA | ||
| 786 | * transfer. Since it is possible that the RX path is still active, | ||
| 787 | * the RX RAM buffer will be stopped first, so any possible incoming | ||
| 788 | * data will not trigger a DMA. After the RAM buffer is stopped, the | ||
| 789 | * BMU is polled until any DMA in progress is ended and only then it | ||
| 790 | * will be reset. | ||
| 791 | */ | ||
| 792 | static void sky2_rx_stop(struct sky2_port *sky2) | ||
| 793 | { | ||
| 794 | struct sky2_hw *hw = sky2->hw; | ||
| 795 | unsigned rxq = rxqaddr[sky2->port]; | ||
| 796 | int i; | ||
| 797 | |||
| 798 | /* disable the RAM Buffer receive queue */ | ||
| 799 | sky2_write8(hw, RB_ADDR(rxq, RB_CTRL), RB_DIS_OP_MD); | ||
| 800 | |||
| 801 | for (i = 0; i < 0xffff; i++) | ||
| 802 | if (sky2_read8(hw, RB_ADDR(rxq, Q_RSL)) | ||
| 803 | == sky2_read8(hw, RB_ADDR(rxq, Q_RL))) | ||
| 804 | goto stopped; | ||
| 805 | |||
| 806 | printk(KERN_WARNING PFX "%s: receiver stop failed\n", | ||
| 807 | sky2->netdev->name); | ||
| 808 | stopped: | ||
| 809 | sky2_write32(hw, Q_ADDR(rxq, Q_CSR), BMU_RST_SET | BMU_FIFO_RST); | ||
| 810 | |||
| 811 | /* reset the Rx prefetch unit */ | ||
| 812 | sky2_write32(hw, Y2_QADDR(rxq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); | ||
| 813 | } | ||
| 814 | |||
| 815 | /* Clean out receive buffer area, assumes receiver hardware stopped */ | ||
| 816 | static void sky2_rx_clean(struct sky2_port *sky2) | ||
| 817 | { | ||
| 818 | unsigned i; | ||
| 819 | |||
| 820 | memset(sky2->rx_le, 0, RX_LE_BYTES); | ||
| 821 | for (i = 0; i < sky2->rx_pending; i++) { | ||
| 822 | struct ring_info *re = sky2->rx_ring + i; | ||
| 823 | |||
| 824 | if (re->skb) { | ||
| 825 | pci_unmap_single(sky2->hw->pdev, | ||
| 826 | re->mapaddr, sky2->rx_bufsize, | ||
| 827 | PCI_DMA_FROMDEVICE); | ||
| 828 | kfree_skb(re->skb); | ||
| 829 | re->skb = NULL; | ||
| 830 | } | ||
| 831 | } | ||
| 832 | } | ||
| 833 | |||
| 834 | /* Basic MII support */ | ||
| 835 | static int sky2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) | ||
| 836 | { | ||
| 837 | struct mii_ioctl_data *data = if_mii(ifr); | ||
| 838 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 839 | struct sky2_hw *hw = sky2->hw; | ||
| 840 | int err = -EOPNOTSUPP; | ||
| 841 | |||
| 842 | if (!netif_running(dev)) | ||
| 843 | return -ENODEV; /* Phy still in reset */ | ||
| 844 | |||
| 845 | switch(cmd) { | ||
| 846 | case SIOCGMIIPHY: | ||
| 847 | data->phy_id = PHY_ADDR_MARV; | ||
| 848 | |||
| 849 | /* fallthru */ | ||
| 850 | case SIOCGMIIREG: { | ||
| 851 | u16 val = 0; | ||
| 852 | |||
| 853 | down(&sky2->phy_sema); | ||
| 854 | err = __gm_phy_read(hw, sky2->port, data->reg_num & 0x1f, &val); | ||
| 855 | up(&sky2->phy_sema); | ||
| 856 | |||
| 857 | data->val_out = val; | ||
| 858 | break; | ||
| 859 | } | ||
| 860 | |||
| 861 | case SIOCSMIIREG: | ||
| 862 | if (!capable(CAP_NET_ADMIN)) | ||
| 863 | return -EPERM; | ||
| 864 | |||
| 865 | down(&sky2->phy_sema); | ||
| 866 | err = gm_phy_write(hw, sky2->port, data->reg_num & 0x1f, | ||
| 867 | data->val_in); | ||
| 868 | up(&sky2->phy_sema); | ||
| 869 | break; | ||
| 870 | } | ||
| 871 | return err; | ||
| 872 | } | ||
| 873 | |||
| 874 | #ifdef SKY2_VLAN_TAG_USED | ||
| 875 | static void sky2_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) | ||
| 876 | { | ||
| 877 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 878 | struct sky2_hw *hw = sky2->hw; | ||
| 879 | u16 port = sky2->port; | ||
| 880 | |||
| 881 | spin_lock(&sky2->tx_lock); | ||
| 882 | |||
| 883 | sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_ON); | ||
| 884 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_ON); | ||
| 885 | sky2->vlgrp = grp; | ||
| 886 | |||
| 887 | spin_unlock(&sky2->tx_lock); | ||
| 888 | } | ||
| 889 | |||
| 890 | static void sky2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) | ||
| 891 | { | ||
| 892 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 893 | struct sky2_hw *hw = sky2->hw; | ||
| 894 | u16 port = sky2->port; | ||
| 895 | |||
| 896 | spin_lock(&sky2->tx_lock); | ||
| 897 | |||
| 898 | sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_OFF); | ||
| 899 | sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_OFF); | ||
| 900 | if (sky2->vlgrp) | ||
| 901 | sky2->vlgrp->vlan_devices[vid] = NULL; | ||
| 902 | |||
| 903 | spin_unlock(&sky2->tx_lock); | ||
| 904 | } | ||
| 905 | #endif | ||
| 906 | |||
| 907 | /* | ||
| 908 | * Allocate and setup receiver buffer pool. | ||
| 909 | * In case of 64 bit dma, there are 2X as many list elements | ||
| 910 | * available as ring entries | ||
| 911 | * and need to reserve one list element so we don't wrap around. | ||
| 912 | * | ||
| 913 | * It appears the hardware has a bug in the FIFO logic that | ||
| 914 | * cause it to hang if the FIFO gets overrun and the receive buffer | ||
| 915 | * is not aligned. This means we can't use skb_reserve to align | ||
| 916 | * the IP header. | ||
| 917 | */ | ||
| 918 | static int sky2_rx_start(struct sky2_port *sky2) | ||
| 919 | { | ||
| 920 | struct sky2_hw *hw = sky2->hw; | ||
| 921 | unsigned rxq = rxqaddr[sky2->port]; | ||
| 922 | int i; | ||
| 923 | |||
| 924 | sky2->rx_put = sky2->rx_next = 0; | ||
| 925 | sky2_qset(hw, rxq); | ||
| 926 | sky2_prefetch_init(hw, rxq, sky2->rx_le_map, RX_LE_SIZE - 1); | ||
| 927 | |||
| 928 | rx_set_checksum(sky2); | ||
| 929 | for (i = 0; i < sky2->rx_pending; i++) { | ||
| 930 | struct ring_info *re = sky2->rx_ring + i; | ||
| 931 | |||
| 932 | re->skb = dev_alloc_skb(sky2->rx_bufsize); | ||
| 933 | if (!re->skb) | ||
| 934 | goto nomem; | ||
| 935 | |||
| 936 | re->mapaddr = pci_map_single(hw->pdev, re->skb->data, | ||
| 937 | sky2->rx_bufsize, PCI_DMA_FROMDEVICE); | ||
| 938 | sky2_rx_add(sky2, re->mapaddr); | ||
| 939 | } | ||
| 940 | |||
| 941 | /* Tell chip about available buffers */ | ||
| 942 | sky2_write16(hw, Y2_QADDR(rxq, PREF_UNIT_PUT_IDX), sky2->rx_put); | ||
| 943 | sky2->rx_last_put = sky2_read16(hw, Y2_QADDR(rxq, PREF_UNIT_PUT_IDX)); | ||
| 944 | return 0; | ||
| 945 | nomem: | ||
| 946 | sky2_rx_clean(sky2); | ||
| 947 | return -ENOMEM; | ||
| 948 | } | ||
| 949 | |||
| 950 | /* Bring up network interface. */ | ||
| 951 | static int sky2_up(struct net_device *dev) | ||
| 952 | { | ||
| 953 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 954 | struct sky2_hw *hw = sky2->hw; | ||
| 955 | unsigned port = sky2->port; | ||
| 956 | u32 ramsize, rxspace; | ||
| 957 | int err = -ENOMEM; | ||
| 958 | |||
| 959 | if (netif_msg_ifup(sky2)) | ||
| 960 | printk(KERN_INFO PFX "%s: enabling interface\n", dev->name); | ||
| 961 | |||
| 962 | /* must be power of 2 */ | ||
| 963 | sky2->tx_le = pci_alloc_consistent(hw->pdev, | ||
| 964 | TX_RING_SIZE * | ||
| 965 | sizeof(struct sky2_tx_le), | ||
| 966 | &sky2->tx_le_map); | ||
| 967 | if (!sky2->tx_le) | ||
| 968 | goto err_out; | ||
| 969 | |||
| 970 | sky2->tx_ring = kcalloc(TX_RING_SIZE, sizeof(struct tx_ring_info), | ||
| 971 | GFP_KERNEL); | ||
| 972 | if (!sky2->tx_ring) | ||
| 973 | goto err_out; | ||
| 974 | sky2->tx_prod = sky2->tx_cons = 0; | ||
| 975 | |||
| 976 | sky2->rx_le = pci_alloc_consistent(hw->pdev, RX_LE_BYTES, | ||
| 977 | &sky2->rx_le_map); | ||
| 978 | if (!sky2->rx_le) | ||
| 979 | goto err_out; | ||
| 980 | memset(sky2->rx_le, 0, RX_LE_BYTES); | ||
| 981 | |||
| 982 | sky2->rx_ring = kcalloc(sky2->rx_pending, sizeof(struct ring_info), | ||
| 983 | GFP_KERNEL); | ||
| 984 | if (!sky2->rx_ring) | ||
| 985 | goto err_out; | ||
| 986 | |||
| 987 | sky2_mac_init(hw, port); | ||
| 988 | |||
| 989 | /* Configure RAM buffers */ | ||
| 990 | if (hw->chip_id == CHIP_ID_YUKON_FE || | ||
| 991 | (hw->chip_id == CHIP_ID_YUKON_EC && hw->chip_rev == 2)) | ||
| 992 | ramsize = 4096; | ||
| 993 | else { | ||
| 994 | u8 e0 = sky2_read8(hw, B2_E_0); | ||
| 995 | ramsize = (e0 == 0) ? (128 * 1024) : (e0 * 4096); | ||
| 996 | } | ||
| 997 | |||
| 998 | /* 2/3 for Rx */ | ||
| 999 | rxspace = (2 * ramsize) / 3; | ||
| 1000 | sky2_ramset(hw, rxqaddr[port], 0, rxspace); | ||
| 1001 | sky2_ramset(hw, txqaddr[port], rxspace, ramsize - rxspace); | ||
| 1002 | |||
| 1003 | /* Make sure SyncQ is disabled */ | ||
| 1004 | sky2_write8(hw, RB_ADDR(port == 0 ? Q_XS1 : Q_XS2, RB_CTRL), | ||
| 1005 | RB_RST_SET); | ||
| 1006 | |||
| 1007 | sky2_qset(hw, txqaddr[port]); | ||
| 1008 | if (hw->chip_id == CHIP_ID_YUKON_EC_U) | ||
| 1009 | sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), 0x1a0); | ||
| 1010 | |||
| 1011 | |||
| 1012 | sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map, | ||
| 1013 | TX_RING_SIZE - 1); | ||
| 1014 | |||
| 1015 | err = sky2_rx_start(sky2); | ||
| 1016 | if (err) | ||
| 1017 | goto err_out; | ||
| 1018 | |||
| 1019 | /* Enable interrupts from phy/mac for port */ | ||
| 1020 | hw->intr_mask |= (port == 0) ? Y2_IS_PORT_1 : Y2_IS_PORT_2; | ||
| 1021 | sky2_write32(hw, B0_IMSK, hw->intr_mask); | ||
| 1022 | return 0; | ||
| 1023 | |||
| 1024 | err_out: | ||
| 1025 | if (sky2->rx_le) { | ||
| 1026 | pci_free_consistent(hw->pdev, RX_LE_BYTES, | ||
| 1027 | sky2->rx_le, sky2->rx_le_map); | ||
| 1028 | sky2->rx_le = NULL; | ||
| 1029 | } | ||
| 1030 | if (sky2->tx_le) { | ||
| 1031 | pci_free_consistent(hw->pdev, | ||
| 1032 | TX_RING_SIZE * sizeof(struct sky2_tx_le), | ||
| 1033 | sky2->tx_le, sky2->tx_le_map); | ||
| 1034 | sky2->tx_le = NULL; | ||
| 1035 | } | ||
| 1036 | kfree(sky2->tx_ring); | ||
| 1037 | kfree(sky2->rx_ring); | ||
| 1038 | |||
| 1039 | sky2->tx_ring = NULL; | ||
| 1040 | sky2->rx_ring = NULL; | ||
| 1041 | return err; | ||
| 1042 | } | ||
| 1043 | |||
| 1044 | /* Modular subtraction in ring */ | ||
| 1045 | static inline int tx_dist(unsigned tail, unsigned head) | ||
| 1046 | { | ||
| 1047 | return (head - tail) % TX_RING_SIZE; | ||
| 1048 | } | ||
| 1049 | |||
| 1050 | /* Number of list elements available for next tx */ | ||
| 1051 | static inline int tx_avail(const struct sky2_port *sky2) | ||
| 1052 | { | ||
| 1053 | return sky2->tx_pending - tx_dist(sky2->tx_cons, sky2->tx_prod); | ||
| 1054 | } | ||
| 1055 | |||
| 1056 | /* Estimate of number of transmit list elements required */ | ||
| 1057 | static inline unsigned tx_le_req(const struct sk_buff *skb) | ||
| 1058 | { | ||
| 1059 | unsigned count; | ||
| 1060 | |||
| 1061 | count = sizeof(dma_addr_t) / sizeof(u32); | ||
| 1062 | count += skb_shinfo(skb)->nr_frags * count; | ||
| 1063 | |||
| 1064 | if (skb_shinfo(skb)->tso_size) | ||
| 1065 | ++count; | ||
| 1066 | |||
| 1067 | if (skb->ip_summed == CHECKSUM_HW) | ||
| 1068 | ++count; | ||
| 1069 | |||
| 1070 | return count; | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | /* | ||
| 1074 | * Put one packet in ring for transmit. | ||
| 1075 | * A single packet can generate multiple list elements, and | ||
| 1076 | * the number of ring elements will probably be less than the number | ||
| 1077 | * of list elements used. | ||
| 1078 | * | ||
| 1079 | * No BH disabling for tx_lock here (like tg3) | ||
| 1080 | */ | ||
| 1081 | static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev) | ||
| 1082 | { | ||
| 1083 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 1084 | struct sky2_hw *hw = sky2->hw; | ||
| 1085 | struct sky2_tx_le *le = NULL; | ||
| 1086 | struct tx_ring_info *re; | ||
| 1087 | unsigned i, len; | ||
| 1088 | dma_addr_t mapping; | ||
| 1089 | u32 addr64; | ||
| 1090 | u16 mss; | ||
| 1091 | u8 ctrl; | ||
| 1092 | |||
| 1093 | if (!spin_trylock(&sky2->tx_lock)) | ||
| 1094 | return NETDEV_TX_LOCKED; | ||
| 1095 | |||
| 1096 | if (unlikely(tx_avail(sky2) < tx_le_req(skb))) { | ||
| 1097 | /* There is a known but harmless race with lockless tx | ||
| 1098 | * and netif_stop_queue. | ||
| 1099 | */ | ||
| 1100 | if (!netif_queue_stopped(dev)) { | ||
| 1101 | netif_stop_queue(dev); | ||
| 1102 | printk(KERN_WARNING PFX "%s: ring full when queue awake!\n", | ||
| 1103 | dev->name); | ||
| 1104 | } | ||
| 1105 | spin_unlock(&sky2->tx_lock); | ||
| 1106 | |||
| 1107 | return NETDEV_TX_BUSY; | ||
| 1108 | } | ||
| 1109 | |||
| 1110 | if (unlikely(netif_msg_tx_queued(sky2))) | ||
| 1111 | printk(KERN_DEBUG "%s: tx queued, slot %u, len %d\n", | ||
| 1112 | dev->name, sky2->tx_prod, skb->len); | ||
| 1113 | |||
| 1114 | len = skb_headlen(skb); | ||
| 1115 | mapping = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE); | ||
| 1116 | addr64 = high32(mapping); | ||
| 1117 | |||
| 1118 | re = sky2->tx_ring + sky2->tx_prod; | ||
| 1119 | |||
| 1120 | /* Send high bits if changed or crosses boundary */ | ||
| 1121 | if (addr64 != sky2->tx_addr64 || high32(mapping + len) != sky2->tx_addr64) { | ||
| 1122 | le = get_tx_le(sky2); | ||
| 1123 | le->tx.addr = cpu_to_le32(addr64); | ||
| 1124 | le->ctrl = 0; | ||
| 1125 | le->opcode = OP_ADDR64 | HW_OWNER; | ||
| 1126 | sky2->tx_addr64 = high32(mapping + len); | ||
| 1127 | } | ||
| 1128 | |||
| 1129 | /* Check for TCP Segmentation Offload */ | ||
| 1130 | mss = skb_shinfo(skb)->tso_size; | ||
| 1131 | if (mss != 0) { | ||
| 1132 | /* just drop the packet if non-linear expansion fails */ | ||
| 1133 | if (skb_header_cloned(skb) && | ||
| 1134 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { | ||
| 1135 | dev_kfree_skb_any(skb); | ||
| 1136 | goto out_unlock; | ||
| 1137 | } | ||
| 1138 | |||
| 1139 | mss += ((skb->h.th->doff - 5) * 4); /* TCP options */ | ||
| 1140 | mss += (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr); | ||
| 1141 | mss += ETH_HLEN; | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | if (mss != sky2->tx_last_mss) { | ||
| 1145 | le = get_tx_le(sky2); | ||
| 1146 | le->tx.tso.size = cpu_to_le16(mss); | ||
| 1147 | le->tx.tso.rsvd = 0; | ||
| 1148 | le->opcode = OP_LRGLEN | HW_OWNER; | ||
| 1149 | le->ctrl = 0; | ||
| 1150 | sky2->tx_last_mss = mss; | ||
| 1151 | } | ||
| 1152 | |||
| 1153 | ctrl = 0; | ||
| 1154 | #ifdef SKY2_VLAN_TAG_USED | ||
| 1155 | /* Add VLAN tag, can piggyback on LRGLEN or ADDR64 */ | ||
| 1156 | if (sky2->vlgrp && vlan_tx_tag_present(skb)) { | ||
| 1157 | if (!le) { | ||
| 1158 | le = get_tx_le(sky2); | ||
| 1159 | le->tx.addr = 0; | ||
| 1160 | le->opcode = OP_VLAN|HW_OWNER; | ||
| 1161 | le->ctrl = 0; | ||
| 1162 | } else | ||
| 1163 | le->opcode |= OP_VLAN; | ||
| 1164 | le->length = cpu_to_be16(vlan_tx_tag_get(skb)); | ||
| 1165 | ctrl |= INS_VLAN; | ||
| 1166 | } | ||
| 1167 | #endif | ||
| 1168 | |||
| 1169 | /* Handle TCP checksum offload */ | ||
| 1170 | if (skb->ip_summed == CHECKSUM_HW) { | ||
| 1171 | u16 hdr = skb->h.raw - skb->data; | ||
| 1172 | u16 offset = hdr + skb->csum; | ||
| 1173 | |||
| 1174 | ctrl = CALSUM | WR_SUM | INIT_SUM | LOCK_SUM; | ||
| 1175 | if (skb->nh.iph->protocol == IPPROTO_UDP) | ||
| 1176 | ctrl |= UDPTCP; | ||
| 1177 | |||
| 1178 | le = get_tx_le(sky2); | ||
| 1179 | le->tx.csum.start = cpu_to_le16(hdr); | ||
| 1180 | le->tx.csum.offset = cpu_to_le16(offset); | ||
| 1181 | le->length = 0; /* initial checksum value */ | ||
| 1182 | le->ctrl = 1; /* one packet */ | ||
| 1183 | le->opcode = OP_TCPLISW | HW_OWNER; | ||
| 1184 | } | ||
| 1185 | |||
| 1186 | le = get_tx_le(sky2); | ||
| 1187 | le->tx.addr = cpu_to_le32((u32) mapping); | ||
| 1188 | le->length = cpu_to_le16(len); | ||
| 1189 | le->ctrl = ctrl; | ||
| 1190 | le->opcode = mss ? (OP_LARGESEND | HW_OWNER) : (OP_PACKET | HW_OWNER); | ||
| 1191 | |||
| 1192 | /* Record the transmit mapping info */ | ||
| 1193 | re->skb = skb; | ||
| 1194 | pci_unmap_addr_set(re, mapaddr, mapping); | ||
| 1195 | |||
| 1196 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | ||
| 1197 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | ||
| 1198 | struct tx_ring_info *fre; | ||
| 1199 | |||
| 1200 | mapping = pci_map_page(hw->pdev, frag->page, frag->page_offset, | ||
| 1201 | frag->size, PCI_DMA_TODEVICE); | ||
| 1202 | addr64 = (mapping >> 16) >> 16; | ||
| 1203 | if (addr64 != sky2->tx_addr64) { | ||
| 1204 | le = get_tx_le(sky2); | ||
| 1205 | le->tx.addr = cpu_to_le32(addr64); | ||
| 1206 | le->ctrl = 0; | ||
| 1207 | le->opcode = OP_ADDR64 | HW_OWNER; | ||
| 1208 | sky2->tx_addr64 = addr64; | ||
| 1209 | } | ||
| 1210 | |||
| 1211 | le = get_tx_le(sky2); | ||
| 1212 | le->tx.addr = cpu_to_le32((u32) mapping); | ||
| 1213 | le->length = cpu_to_le16(frag->size); | ||
| 1214 | le->ctrl = ctrl; | ||
| 1215 | le->opcode = OP_BUFFER | HW_OWNER; | ||
| 1216 | |||
| 1217 | fre = sky2->tx_ring | ||
| 1218 | + ((re - sky2->tx_ring) + i + 1) % TX_RING_SIZE; | ||
| 1219 | pci_unmap_addr_set(fre, mapaddr, mapping); | ||
| 1220 | } | ||
| 1221 | |||
| 1222 | re->idx = sky2->tx_prod; | ||
| 1223 | le->ctrl |= EOP; | ||
| 1224 | |||
| 1225 | sky2_put_idx(hw, txqaddr[sky2->port], sky2->tx_prod, | ||
| 1226 | &sky2->tx_last_put, TX_RING_SIZE); | ||
| 1227 | |||
| 1228 | if (tx_avail(sky2) <= MAX_SKB_TX_LE) | ||
| 1229 | netif_stop_queue(dev); | ||
| 1230 | |||
| 1231 | out_unlock: | ||
| 1232 | mmiowb(); | ||
| 1233 | spin_unlock(&sky2->tx_lock); | ||
| 1234 | |||
| 1235 | dev->trans_start = jiffies; | ||
| 1236 | return NETDEV_TX_OK; | ||
| 1237 | } | ||
| 1238 | |||
| 1239 | /* | ||
| 1240 | * Free ring elements from starting at tx_cons until "done" | ||
| 1241 | * | ||
| 1242 | * NB: the hardware will tell us about partial completion of multi-part | ||
| 1243 | * buffers; these are deferred until completion. | ||
| 1244 | */ | ||
| 1245 | static void sky2_tx_complete(struct sky2_port *sky2, u16 done) | ||
| 1246 | { | ||
| 1247 | struct net_device *dev = sky2->netdev; | ||
| 1248 | struct pci_dev *pdev = sky2->hw->pdev; | ||
| 1249 | u16 nxt, put; | ||
| 1250 | unsigned i; | ||
| 1251 | |||
| 1252 | BUG_ON(done >= TX_RING_SIZE); | ||
| 1253 | |||
| 1254 | if (unlikely(netif_msg_tx_done(sky2))) | ||
| 1255 | printk(KERN_DEBUG "%s: tx done, up to %u\n", | ||
| 1256 | dev->name, done); | ||
| 1257 | |||
| 1258 | for (put = sky2->tx_cons; put != done; put = nxt) { | ||
| 1259 | struct tx_ring_info *re = sky2->tx_ring + put; | ||
| 1260 | struct sk_buff *skb = re->skb; | ||
| 1261 | |||
| 1262 | nxt = re->idx; | ||
| 1263 | BUG_ON(nxt >= TX_RING_SIZE); | ||
| 1264 | prefetch(sky2->tx_ring + nxt); | ||
| 1265 | |||
| 1266 | /* Check for partial status */ | ||
| 1267 | if (tx_dist(put, done) < tx_dist(put, nxt)) | ||
| 1268 | break; | ||
| 1269 | |||
| 1270 | skb = re->skb; | ||
| 1271 | pci_unmap_single(pdev, pci_unmap_addr(re, mapaddr), | ||
| 1272 | skb_headlen(skb), PCI_DMA_TODEVICE); | ||
| 1273 | |||
| 1274 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | ||
| 1275 | struct tx_ring_info *fre; | ||
| 1276 | fre = sky2->tx_ring + (put + i + 1) % TX_RING_SIZE; | ||
| 1277 | pci_unmap_page(pdev, pci_unmap_addr(fre, mapaddr), | ||
| 1278 | skb_shinfo(skb)->frags[i].size, | ||
| 1279 | PCI_DMA_TODEVICE); | ||
| 1280 | } | ||
| 1281 | |||
| 1282 | dev_kfree_skb_any(skb); | ||
| 1283 | } | ||
| 1284 | |||
| 1285 | spin_lock(&sky2->tx_lock); | ||
| 1286 | sky2->tx_cons = put; | ||
| 1287 | if (netif_queue_stopped(dev) && tx_avail(sky2) > MAX_SKB_TX_LE) | ||
| 1288 | netif_wake_queue(dev); | ||
| 1289 | spin_unlock(&sky2->tx_lock); | ||
| 1290 | } | ||
| 1291 | |||
| 1292 | /* Cleanup all untransmitted buffers, assume transmitter not running */ | ||
| 1293 | static void sky2_tx_clean(struct sky2_port *sky2) | ||
| 1294 | { | ||
| 1295 | sky2_tx_complete(sky2, sky2->tx_prod); | ||
| 1296 | } | ||
| 1297 | |||
| 1298 | /* Network shutdown */ | ||
| 1299 | static int sky2_down(struct net_device *dev) | ||
| 1300 | { | ||
| 1301 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 1302 | struct sky2_hw *hw = sky2->hw; | ||
| 1303 | unsigned port = sky2->port; | ||
| 1304 | u16 ctrl; | ||
| 1305 | |||
| 1306 | /* Never really got started! */ | ||
| 1307 | if (!sky2->tx_le) | ||
| 1308 | return 0; | ||
| 1309 | |||
| 1310 | if (netif_msg_ifdown(sky2)) | ||
| 1311 | printk(KERN_INFO PFX "%s: disabling interface\n", dev->name); | ||
| 1312 | |||
| 1313 | /* Stop more packets from being queued */ | ||
| 1314 | netif_stop_queue(dev); | ||
| 1315 | |||
| 1316 | /* Disable port IRQ */ | ||
| 1317 | local_irq_disable(); | ||
| 1318 | hw->intr_mask &= ~((sky2->port == 0) ? Y2_IS_IRQ_PHY1 : Y2_IS_IRQ_PHY2); | ||
| 1319 | sky2_write32(hw, B0_IMSK, hw->intr_mask); | ||
| 1320 | local_irq_enable(); | ||
| 1321 | |||
| 1322 | flush_scheduled_work(); | ||
| 1323 | |||
| 1324 | sky2_phy_reset(hw, port); | ||
| 1325 | |||
| 1326 | /* Stop transmitter */ | ||
| 1327 | sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_STOP); | ||
| 1328 | sky2_read32(hw, Q_ADDR(txqaddr[port], Q_CSR)); | ||
| 1329 | |||
| 1330 | sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), | ||
| 1331 | RB_RST_SET | RB_DIS_OP_MD); | ||
| 1332 | |||
| 1333 | ctrl = gma_read16(hw, port, GM_GP_CTRL); | ||
| 1334 | ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA); | ||
| 1335 | gma_write16(hw, port, GM_GP_CTRL, ctrl); | ||
| 1336 | |||
| 1337 | sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET); | ||
| 1338 | |||
| 1339 | /* Workaround shared GMAC reset */ | ||
| 1340 | if (!(hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0 | ||
| 1341 | && port == 0 && hw->dev[1] && netif_running(hw->dev[1]))) | ||
| 1342 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET); | ||
| 1343 | |||
| 1344 | /* Disable Force Sync bit and Enable Alloc bit */ | ||
| 1345 | sky2_write8(hw, SK_REG(port, TXA_CTRL), | ||
| 1346 | TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC); | ||
| 1347 | |||
| 1348 | /* Stop Interval Timer and Limit Counter of Tx Arbiter */ | ||
| 1349 | sky2_write32(hw, SK_REG(port, TXA_ITI_INI), 0L); | ||
| 1350 | sky2_write32(hw, SK_REG(port, TXA_LIM_INI), 0L); | ||
| 1351 | |||
| 1352 | /* Reset the PCI FIFO of the async Tx queue */ | ||
| 1353 | sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), | ||
| 1354 | BMU_RST_SET | BMU_FIFO_RST); | ||
| 1355 | |||
| 1356 | /* Reset the Tx prefetch units */ | ||
| 1357 | sky2_write32(hw, Y2_QADDR(txqaddr[port], PREF_UNIT_CTRL), | ||
| 1358 | PREF_UNIT_RST_SET); | ||
| 1359 | |||
| 1360 | sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET); | ||
| 1361 | |||
| 1362 | sky2_rx_stop(sky2); | ||
| 1363 | |||
| 1364 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); | ||
| 1365 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); | ||
| 1366 | |||
| 1367 | /* turn off LED's */ | ||
| 1368 | sky2_write16(hw, B0_Y2LED, LED_STAT_OFF); | ||
| 1369 | |||
| 1370 | synchronize_irq(hw->pdev->irq); | ||
| 1371 | |||
| 1372 | sky2_tx_clean(sky2); | ||
| 1373 | sky2_rx_clean(sky2); | ||
| 1374 | |||
| 1375 | pci_free_consistent(hw->pdev, RX_LE_BYTES, | ||
| 1376 | sky2->rx_le, sky2->rx_le_map); | ||
| 1377 | kfree(sky2->rx_ring); | ||
| 1378 | |||
| 1379 | pci_free_consistent(hw->pdev, | ||
| 1380 | TX_RING_SIZE * sizeof(struct sky2_tx_le), | ||
| 1381 | sky2->tx_le, sky2->tx_le_map); | ||
| 1382 | kfree(sky2->tx_ring); | ||
| 1383 | |||
| 1384 | sky2->tx_le = NULL; | ||
| 1385 | sky2->rx_le = NULL; | ||
| 1386 | |||
| 1387 | sky2->rx_ring = NULL; | ||
| 1388 | sky2->tx_ring = NULL; | ||
| 1389 | |||
| 1390 | return 0; | ||
| 1391 | } | ||
| 1392 | |||
| 1393 | static u16 sky2_phy_speed(const struct sky2_hw *hw, u16 aux) | ||
| 1394 | { | ||
| 1395 | if (!hw->copper) | ||
| 1396 | return SPEED_1000; | ||
| 1397 | |||
| 1398 | if (hw->chip_id == CHIP_ID_YUKON_FE) | ||
| 1399 | return (aux & PHY_M_PS_SPEED_100) ? SPEED_100 : SPEED_10; | ||
| 1400 | |||
| 1401 | switch (aux & PHY_M_PS_SPEED_MSK) { | ||
| 1402 | case PHY_M_PS_SPEED_1000: | ||
| 1403 | return SPEED_1000; | ||
| 1404 | case PHY_M_PS_SPEED_100: | ||
| 1405 | return SPEED_100; | ||
| 1406 | default: | ||
| 1407 | return SPEED_10; | ||
| 1408 | } | ||
| 1409 | } | ||
| 1410 | |||
| 1411 | static void sky2_link_up(struct sky2_port *sky2) | ||
| 1412 | { | ||
| 1413 | struct sky2_hw *hw = sky2->hw; | ||
| 1414 | unsigned port = sky2->port; | ||
| 1415 | u16 reg; | ||
| 1416 | |||
| 1417 | /* Enable Transmit FIFO Underrun */ | ||
| 1418 | sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), GMAC_DEF_MSK); | ||
| 1419 | |||
| 1420 | reg = gma_read16(hw, port, GM_GP_CTRL); | ||
| 1421 | if (sky2->duplex == DUPLEX_FULL || sky2->autoneg == AUTONEG_ENABLE) | ||
| 1422 | reg |= GM_GPCR_DUP_FULL; | ||
| 1423 | |||
| 1424 | /* enable Rx/Tx */ | ||
| 1425 | reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA; | ||
| 1426 | gma_write16(hw, port, GM_GP_CTRL, reg); | ||
| 1427 | gma_read16(hw, port, GM_GP_CTRL); | ||
| 1428 | |||
| 1429 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); | ||
| 1430 | |||
| 1431 | netif_carrier_on(sky2->netdev); | ||
| 1432 | netif_wake_queue(sky2->netdev); | ||
| 1433 | |||
| 1434 | /* Turn on link LED */ | ||
| 1435 | sky2_write8(hw, SK_REG(port, LNK_LED_REG), | ||
| 1436 | LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF); | ||
| 1437 | |||
| 1438 | if (hw->chip_id == CHIP_ID_YUKON_XL) { | ||
| 1439 | u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); | ||
| 1440 | |||
| 1441 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); | ||
| 1442 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, PHY_M_LEDC_LOS_CTRL(1) | /* LINK/ACT */ | ||
| 1443 | PHY_M_LEDC_INIT_CTRL(sky2->speed == | ||
| 1444 | SPEED_10 ? 7 : 0) | | ||
| 1445 | PHY_M_LEDC_STA1_CTRL(sky2->speed == | ||
| 1446 | SPEED_100 ? 7 : 0) | | ||
| 1447 | PHY_M_LEDC_STA0_CTRL(sky2->speed == | ||
| 1448 | SPEED_1000 ? 7 : 0)); | ||
| 1449 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); | ||
| 1450 | } | ||
| 1451 | |||
| 1452 | if (netif_msg_link(sky2)) | ||
| 1453 | printk(KERN_INFO PFX | ||
| 1454 | "%s: Link is up at %d Mbps, %s duplex, flow control %s\n", | ||
| 1455 | sky2->netdev->name, sky2->speed, | ||
| 1456 | sky2->duplex == DUPLEX_FULL ? "full" : "half", | ||
| 1457 | (sky2->tx_pause && sky2->rx_pause) ? "both" : | ||
| 1458 | sky2->tx_pause ? "tx" : sky2->rx_pause ? "rx" : "none"); | ||
| 1459 | } | ||
| 1460 | |||
| 1461 | static void sky2_link_down(struct sky2_port *sky2) | ||
| 1462 | { | ||
| 1463 | struct sky2_hw *hw = sky2->hw; | ||
| 1464 | unsigned port = sky2->port; | ||
| 1465 | u16 reg; | ||
| 1466 | |||
| 1467 | gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0); | ||
| 1468 | |||
| 1469 | reg = gma_read16(hw, port, GM_GP_CTRL); | ||
| 1470 | reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA); | ||
| 1471 | gma_write16(hw, port, GM_GP_CTRL, reg); | ||
| 1472 | gma_read16(hw, port, GM_GP_CTRL); /* PCI post */ | ||
| 1473 | |||
| 1474 | if (sky2->rx_pause && !sky2->tx_pause) { | ||
| 1475 | /* restore Asymmetric Pause bit */ | ||
| 1476 | gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, | ||
| 1477 | gm_phy_read(hw, port, PHY_MARV_AUNE_ADV) | ||
| 1478 | | PHY_M_AN_ASP); | ||
| 1479 | } | ||
| 1480 | |||
| 1481 | netif_carrier_off(sky2->netdev); | ||
| 1482 | netif_stop_queue(sky2->netdev); | ||
| 1483 | |||
| 1484 | /* Turn on link LED */ | ||
| 1485 | sky2_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF); | ||
| 1486 | |||
| 1487 | if (netif_msg_link(sky2)) | ||
| 1488 | printk(KERN_INFO PFX "%s: Link is down.\n", sky2->netdev->name); | ||
| 1489 | sky2_phy_init(hw, port); | ||
| 1490 | } | ||
| 1491 | |||
| 1492 | static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux) | ||
| 1493 | { | ||
| 1494 | struct sky2_hw *hw = sky2->hw; | ||
| 1495 | unsigned port = sky2->port; | ||
| 1496 | u16 lpa; | ||
| 1497 | |||
| 1498 | lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP); | ||
| 1499 | |||
| 1500 | if (lpa & PHY_M_AN_RF) { | ||
| 1501 | printk(KERN_ERR PFX "%s: remote fault", sky2->netdev->name); | ||
| 1502 | return -1; | ||
| 1503 | } | ||
| 1504 | |||
| 1505 | if (hw->chip_id != CHIP_ID_YUKON_FE && | ||
| 1506 | gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) { | ||
| 1507 | printk(KERN_ERR PFX "%s: master/slave fault", | ||
| 1508 | sky2->netdev->name); | ||
| 1509 | return -1; | ||
| 1510 | } | ||
| 1511 | |||
| 1512 | if (!(aux & PHY_M_PS_SPDUP_RES)) { | ||
| 1513 | printk(KERN_ERR PFX "%s: speed/duplex mismatch", | ||
| 1514 | sky2->netdev->name); | ||
| 1515 | return -1; | ||
| 1516 | } | ||
| 1517 | |||
| 1518 | sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; | ||
| 1519 | |||
| 1520 | sky2->speed = sky2_phy_speed(hw, aux); | ||
| 1521 | |||
| 1522 | /* Pause bits are offset (9..8) */ | ||
| 1523 | if (hw->chip_id == CHIP_ID_YUKON_XL) | ||
| 1524 | aux >>= 6; | ||
| 1525 | |||
| 1526 | sky2->rx_pause = (aux & PHY_M_PS_RX_P_EN) != 0; | ||
| 1527 | sky2->tx_pause = (aux & PHY_M_PS_TX_P_EN) != 0; | ||
| 1528 | |||
| 1529 | if ((sky2->tx_pause || sky2->rx_pause) | ||
| 1530 | && !(sky2->speed < SPEED_1000 && sky2->duplex == DUPLEX_HALF)) | ||
| 1531 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); | ||
| 1532 | else | ||
| 1533 | sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); | ||
| 1534 | |||
| 1535 | return 0; | ||
| 1536 | } | ||
| 1537 | |||
| 1538 | /* | ||
| 1539 | * Interrupt from PHY are handled outside of interrupt context | ||
| 1540 | * because accessing phy registers requires spin wait which might | ||
| 1541 | * cause excess interrupt latency. | ||
| 1542 | */ | ||
| 1543 | static void sky2_phy_task(void *arg) | ||
| 1544 | { | ||
| 1545 | struct sky2_port *sky2 = arg; | ||
| 1546 | struct sky2_hw *hw = sky2->hw; | ||
| 1547 | u16 istatus, phystat; | ||
| 1548 | |||
| 1549 | down(&sky2->phy_sema); | ||
| 1550 | istatus = gm_phy_read(hw, sky2->port, PHY_MARV_INT_STAT); | ||
| 1551 | phystat = gm_phy_read(hw, sky2->port, PHY_MARV_PHY_STAT); | ||
| 1552 | |||
| 1553 | if (netif_msg_intr(sky2)) | ||
| 1554 | printk(KERN_INFO PFX "%s: phy interrupt status 0x%x 0x%x\n", | ||
| 1555 | sky2->netdev->name, istatus, phystat); | ||
| 1556 | |||
| 1557 | if (istatus & PHY_M_IS_AN_COMPL) { | ||
| 1558 | if (sky2_autoneg_done(sky2, phystat) == 0) | ||
| 1559 | sky2_link_up(sky2); | ||
| 1560 | goto out; | ||
| 1561 | } | ||
| 1562 | |||
| 1563 | if (istatus & PHY_M_IS_LSP_CHANGE) | ||
| 1564 | sky2->speed = sky2_phy_speed(hw, phystat); | ||
| 1565 | |||
| 1566 | if (istatus & PHY_M_IS_DUP_CHANGE) | ||
| 1567 | sky2->duplex = | ||
| 1568 | (phystat & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; | ||
| 1569 | |||
| 1570 | if (istatus & PHY_M_IS_LST_CHANGE) { | ||
| 1571 | if (phystat & PHY_M_PS_LINK_UP) | ||
| 1572 | sky2_link_up(sky2); | ||
| 1573 | else | ||
| 1574 | sky2_link_down(sky2); | ||
| 1575 | } | ||
| 1576 | out: | ||
| 1577 | up(&sky2->phy_sema); | ||
| 1578 | |||
| 1579 | local_irq_disable(); | ||
| 1580 | hw->intr_mask |= (sky2->port == 0) ? Y2_IS_IRQ_PHY1 : Y2_IS_IRQ_PHY2; | ||
| 1581 | sky2_write32(hw, B0_IMSK, hw->intr_mask); | ||
| 1582 | local_irq_enable(); | ||
| 1583 | } | ||
| 1584 | |||
| 1585 | static void sky2_tx_timeout(struct net_device *dev) | ||
| 1586 | { | ||
| 1587 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 1588 | struct sky2_hw *hw = sky2->hw; | ||
| 1589 | unsigned txq = txqaddr[sky2->port]; | ||
| 1590 | |||
| 1591 | if (netif_msg_timer(sky2)) | ||
| 1592 | printk(KERN_ERR PFX "%s: tx timeout\n", dev->name); | ||
| 1593 | |||
| 1594 | netif_stop_queue(dev); | ||
| 1595 | |||
| 1596 | sky2_write32(hw, Q_ADDR(txq, Q_CSR), BMU_STOP); | ||
| 1597 | sky2_read32(hw, Q_ADDR(txq, Q_CSR)); | ||
| 1598 | |||
| 1599 | sky2_write32(hw, Y2_QADDR(txq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); | ||
| 1600 | |||
| 1601 | sky2_tx_clean(sky2); | ||
| 1602 | |||
| 1603 | sky2_qset(hw, txq); | ||
| 1604 | sky2_prefetch_init(hw, txq, sky2->tx_le_map, TX_RING_SIZE - 1); | ||
| 1605 | |||
| 1606 | netif_wake_queue(dev); | ||
| 1607 | } | ||
| 1608 | |||
| 1609 | |||
| 1610 | #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) | ||
| 1611 | /* Want receive buffer size to be multiple of 64 bits, and incl room for vlan */ | ||
| 1612 | static inline unsigned sky2_buf_size(int mtu) | ||
| 1613 | { | ||
| 1614 | return roundup(mtu + ETH_HLEN + 4, 8); | ||
| 1615 | } | ||
| 1616 | |||
| 1617 | static int sky2_change_mtu(struct net_device *dev, int new_mtu) | ||
| 1618 | { | ||
| 1619 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 1620 | struct sky2_hw *hw = sky2->hw; | ||
| 1621 | int err; | ||
| 1622 | u16 ctl, mode; | ||
| 1623 | |||
| 1624 | if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) | ||
| 1625 | return -EINVAL; | ||
| 1626 | |||
| 1627 | if (hw->chip_id == CHIP_ID_YUKON_EC_U && new_mtu > ETH_DATA_LEN) | ||
| 1628 | return -EINVAL; | ||
| 1629 | |||
| 1630 | if (!netif_running(dev)) { | ||
| 1631 | dev->mtu = new_mtu; | ||
| 1632 | return 0; | ||
| 1633 | } | ||
| 1634 | |||
| 1635 | sky2_write32(hw, B0_IMSK, 0); | ||
| 1636 | |||
| 1637 | dev->trans_start = jiffies; /* prevent tx timeout */ | ||
| 1638 | netif_stop_queue(dev); | ||
| 1639 | netif_poll_disable(hw->dev[0]); | ||
| 1640 | |||
| 1641 | ctl = gma_read16(hw, sky2->port, GM_GP_CTRL); | ||
| 1642 | gma_write16(hw, sky2->port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA); | ||
| 1643 | sky2_rx_stop(sky2); | ||
| 1644 | sky2_rx_clean(sky2); | ||
| 1645 | |||
| 1646 | dev->mtu = new_mtu; | ||
| 1647 | sky2->rx_bufsize = sky2_buf_size(new_mtu); | ||
| 1648 | mode = DATA_BLIND_VAL(DATA_BLIND_DEF) | | ||
| 1649 | GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF); | ||
| 1650 | |||
| 1651 | if (dev->mtu > ETH_DATA_LEN) | ||
| 1652 | mode |= GM_SMOD_JUMBO_ENA; | ||
| 1653 | |||
| 1654 | gma_write16(hw, sky2->port, GM_SERIAL_MODE, mode); | ||
| 1655 | |||
| 1656 | sky2_write8(hw, RB_ADDR(rxqaddr[sky2->port], RB_CTRL), RB_ENA_OP_MD); | ||
| 1657 | |||
| 1658 | err = sky2_rx_start(sky2); | ||
| 1659 | sky2_write32(hw, B0_IMSK, hw->intr_mask); | ||
| 1660 | |||
| 1661 | if (err) | ||
| 1662 | dev_close(dev); | ||
| 1663 | else { | ||
| 1664 | gma_write16(hw, sky2->port, GM_GP_CTRL, ctl); | ||
| 1665 | |||
| 1666 | netif_poll_enable(hw->dev[0]); | ||
| 1667 | netif_wake_queue(dev); | ||
| 1668 | } | ||
| 1669 | |||
| 1670 | return err; | ||
| 1671 | } | ||
| 1672 | |||
| 1673 | /* | ||
| 1674 | * Receive one packet. | ||
| 1675 | * For small packets or errors, just reuse existing skb. | ||
| 1676 | * For larger packets, get new buffer. | ||
| 1677 | */ | ||
| 1678 | static struct sk_buff *sky2_receive(struct sky2_port *sky2, | ||
| 1679 | u16 length, u32 status) | ||
| 1680 | { | ||
| 1681 | struct ring_info *re = sky2->rx_ring + sky2->rx_next; | ||
| 1682 | struct sk_buff *skb = NULL; | ||
| 1683 | |||
| 1684 | if (unlikely(netif_msg_rx_status(sky2))) | ||
| 1685 | printk(KERN_DEBUG PFX "%s: rx slot %u status 0x%x len %d\n", | ||
| 1686 | sky2->netdev->name, sky2->rx_next, status, length); | ||
| 1687 | |||
| 1688 | sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending; | ||
| 1689 | prefetch(sky2->rx_ring + sky2->rx_next); | ||
| 1690 | |||
| 1691 | if (status & GMR_FS_ANY_ERR) | ||
| 1692 | goto error; | ||
| 1693 | |||
| 1694 | if (!(status & GMR_FS_RX_OK)) | ||
| 1695 | goto resubmit; | ||
| 1696 | |||
| 1697 | if ((status >> 16) != length || length > sky2->rx_bufsize) | ||
| 1698 | goto oversize; | ||
| 1699 | |||
| 1700 | if (length < copybreak) { | ||
| 1701 | skb = alloc_skb(length + 2, GFP_ATOMIC); | ||
| 1702 | if (!skb) | ||
| 1703 | goto resubmit; | ||
| 1704 | |||
| 1705 | skb_reserve(skb, 2); | ||
| 1706 | pci_dma_sync_single_for_cpu(sky2->hw->pdev, re->mapaddr, | ||
| 1707 | length, PCI_DMA_FROMDEVICE); | ||
| 1708 | memcpy(skb->data, re->skb->data, length); | ||
| 1709 | skb->ip_summed = re->skb->ip_summed; | ||
| 1710 | skb->csum = re->skb->csum; | ||
| 1711 | pci_dma_sync_single_for_device(sky2->hw->pdev, re->mapaddr, | ||
| 1712 | length, PCI_DMA_FROMDEVICE); | ||
| 1713 | } else { | ||
| 1714 | struct sk_buff *nskb; | ||
| 1715 | |||
| 1716 | nskb = dev_alloc_skb(sky2->rx_bufsize); | ||
| 1717 | if (!nskb) | ||
| 1718 | goto resubmit; | ||
| 1719 | |||
| 1720 | skb = re->skb; | ||
| 1721 | re->skb = nskb; | ||
| 1722 | pci_unmap_single(sky2->hw->pdev, re->mapaddr, | ||
| 1723 | sky2->rx_bufsize, PCI_DMA_FROMDEVICE); | ||
| 1724 | prefetch(skb->data); | ||
| 1725 | |||
| 1726 | re->mapaddr = pci_map_single(sky2->hw->pdev, nskb->data, | ||
| 1727 | sky2->rx_bufsize, PCI_DMA_FROMDEVICE); | ||
| 1728 | } | ||
| 1729 | |||
| 1730 | skb_put(skb, length); | ||
| 1731 | resubmit: | ||
| 1732 | re->skb->ip_summed = CHECKSUM_NONE; | ||
| 1733 | sky2_rx_add(sky2, re->mapaddr); | ||
| 1734 | |||
| 1735 | /* Tell receiver about new buffers. */ | ||
| 1736 | sky2_put_idx(sky2->hw, rxqaddr[sky2->port], sky2->rx_put, | ||
| 1737 | &sky2->rx_last_put, RX_LE_SIZE); | ||
| 1738 | |||
| 1739 | return skb; | ||
| 1740 | |||
| 1741 | oversize: | ||
| 1742 | ++sky2->net_stats.rx_over_errors; | ||
| 1743 | goto resubmit; | ||
| 1744 | |||
| 1745 | error: | ||
| 1746 | ++sky2->net_stats.rx_errors; | ||
| 1747 | |||
| 1748 | if (netif_msg_rx_err(sky2)) | ||
| 1749 | printk(KERN_INFO PFX "%s: rx error, status 0x%x length %d\n", | ||
| 1750 | sky2->netdev->name, status, length); | ||
| 1751 | |||
| 1752 | if (status & (GMR_FS_LONG_ERR | GMR_FS_UN_SIZE)) | ||
| 1753 | sky2->net_stats.rx_length_errors++; | ||
| 1754 | if (status & GMR_FS_FRAGMENT) | ||
| 1755 | sky2->net_stats.rx_frame_errors++; | ||
| 1756 | if (status & GMR_FS_CRC_ERR) | ||
| 1757 | sky2->net_stats.rx_crc_errors++; | ||
| 1758 | if (status & GMR_FS_RX_FF_OV) | ||
| 1759 | sky2->net_stats.rx_fifo_errors++; | ||
| 1760 | |||
| 1761 | goto resubmit; | ||
| 1762 | } | ||
| 1763 | |||
| 1764 | /* | ||
| 1765 | * Check for transmit complete | ||
| 1766 | */ | ||
| 1767 | #define TX_NO_STATUS 0xffff | ||
| 1768 | |||
| 1769 | static inline void sky2_tx_check(struct sky2_hw *hw, int port, u16 last) | ||
| 1770 | { | ||
| 1771 | if (last != TX_NO_STATUS) { | ||
| 1772 | struct net_device *dev = hw->dev[port]; | ||
| 1773 | if (dev && netif_running(dev)) { | ||
| 1774 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 1775 | sky2_tx_complete(sky2, last); | ||
| 1776 | } | ||
| 1777 | } | ||
| 1778 | } | ||
| 1779 | |||
| 1780 | /* | ||
| 1781 | * Both ports share the same status interrupt, therefore there is only | ||
| 1782 | * one poll routine. | ||
| 1783 | */ | ||
| 1784 | static int sky2_poll(struct net_device *dev0, int *budget) | ||
| 1785 | { | ||
| 1786 | struct sky2_hw *hw = ((struct sky2_port *) netdev_priv(dev0))->hw; | ||
| 1787 | unsigned int to_do = min(dev0->quota, *budget); | ||
| 1788 | unsigned int work_done = 0; | ||
| 1789 | u16 hwidx; | ||
| 1790 | u16 tx_done[2] = { TX_NO_STATUS, TX_NO_STATUS }; | ||
| 1791 | |||
| 1792 | hwidx = sky2_read16(hw, STAT_PUT_IDX); | ||
| 1793 | BUG_ON(hwidx >= STATUS_RING_SIZE); | ||
| 1794 | rmb(); | ||
| 1795 | |||
| 1796 | while (hwidx != hw->st_idx) { | ||
| 1797 | struct sky2_status_le *le = hw->st_le + hw->st_idx; | ||
| 1798 | struct net_device *dev; | ||
| 1799 | struct sky2_port *sky2; | ||
| 1800 | struct sk_buff *skb; | ||
| 1801 | u32 status; | ||
| 1802 | u16 length; | ||
| 1803 | u8 op; | ||
| 1804 | |||
| 1805 | le = hw->st_le + hw->st_idx; | ||
| 1806 | hw->st_idx = (hw->st_idx + 1) % STATUS_RING_SIZE; | ||
| 1807 | prefetch(hw->st_le + hw->st_idx); | ||
| 1808 | |||
| 1809 | BUG_ON(le->link >= 2); | ||
| 1810 | dev = hw->dev[le->link]; | ||
| 1811 | if (dev == NULL || !netif_running(dev)) | ||
| 1812 | continue; | ||
| 1813 | |||
| 1814 | sky2 = netdev_priv(dev); | ||
| 1815 | status = le32_to_cpu(le->status); | ||
| 1816 | length = le16_to_cpu(le->length); | ||
| 1817 | op = le->opcode & ~HW_OWNER; | ||
| 1818 | le->opcode = 0; | ||
| 1819 | |||
| 1820 | switch (op) { | ||
| 1821 | case OP_RXSTAT: | ||
| 1822 | skb = sky2_receive(sky2, length, status); | ||
| 1823 | if (!skb) | ||
| 1824 | break; | ||
| 1825 | |||
| 1826 | skb->dev = dev; | ||
| 1827 | skb->protocol = eth_type_trans(skb, dev); | ||
| 1828 | dev->last_rx = jiffies; | ||
| 1829 | |||
| 1830 | #ifdef SKY2_VLAN_TAG_USED | ||
| 1831 | if (sky2->vlgrp && (status & GMR_FS_VLAN)) { | ||
| 1832 | vlan_hwaccel_receive_skb(skb, | ||
| 1833 | sky2->vlgrp, | ||
| 1834 | be16_to_cpu(sky2->rx_tag)); | ||
| 1835 | } else | ||
| 1836 | #endif | ||
| 1837 | netif_receive_skb(skb); | ||
| 1838 | |||
| 1839 | if (++work_done >= to_do) | ||
| 1840 | goto exit_loop; | ||
| 1841 | break; | ||
| 1842 | |||
| 1843 | #ifdef SKY2_VLAN_TAG_USED | ||
| 1844 | case OP_RXVLAN: | ||
| 1845 | sky2->rx_tag = length; | ||
| 1846 | break; | ||
| 1847 | |||
| 1848 | case OP_RXCHKSVLAN: | ||
| 1849 | sky2->rx_tag = length; | ||
| 1850 | /* fall through */ | ||
| 1851 | #endif | ||
| 1852 | case OP_RXCHKS: | ||
| 1853 | skb = sky2->rx_ring[sky2->rx_next].skb; | ||
| 1854 | skb->ip_summed = CHECKSUM_HW; | ||
| 1855 | skb->csum = le16_to_cpu(status); | ||
| 1856 | break; | ||
| 1857 | |||
| 1858 | case OP_TXINDEXLE: | ||
| 1859 | /* TX index reports status for both ports */ | ||
| 1860 | tx_done[0] = status & 0xffff; | ||
| 1861 | tx_done[1] = ((status >> 24) & 0xff) | ||
| 1862 | | (u16)(length & 0xf) << 8; | ||
| 1863 | break; | ||
| 1864 | |||
| 1865 | default: | ||
| 1866 | if (net_ratelimit()) | ||
| 1867 | printk(KERN_WARNING PFX | ||
| 1868 | "unknown status opcode 0x%x\n", op); | ||
| 1869 | break; | ||
| 1870 | } | ||
| 1871 | } | ||
| 1872 | |||
| 1873 | exit_loop: | ||
| 1874 | sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ); | ||
| 1875 | mmiowb(); | ||
| 1876 | |||
| 1877 | sky2_tx_check(hw, 0, tx_done[0]); | ||
| 1878 | sky2_tx_check(hw, 1, tx_done[1]); | ||
| 1879 | |||
| 1880 | if (sky2_read16(hw, STAT_PUT_IDX) == hw->st_idx) { | ||
| 1881 | /* need to restart TX timer */ | ||
| 1882 | if (is_ec_a1(hw)) { | ||
| 1883 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP); | ||
| 1884 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START); | ||
| 1885 | } | ||
| 1886 | |||
| 1887 | netif_rx_complete(dev0); | ||
| 1888 | hw->intr_mask |= Y2_IS_STAT_BMU; | ||
| 1889 | sky2_write32(hw, B0_IMSK, hw->intr_mask); | ||
| 1890 | mmiowb(); | ||
| 1891 | return 0; | ||
| 1892 | } else { | ||
| 1893 | *budget -= work_done; | ||
| 1894 | dev0->quota -= work_done; | ||
| 1895 | return 1; | ||
| 1896 | } | ||
| 1897 | } | ||
| 1898 | |||
| 1899 | static void sky2_hw_error(struct sky2_hw *hw, unsigned port, u32 status) | ||
| 1900 | { | ||
| 1901 | struct net_device *dev = hw->dev[port]; | ||
| 1902 | |||
| 1903 | printk(KERN_INFO PFX "%s: hw error interrupt status 0x%x\n", | ||
| 1904 | dev->name, status); | ||
| 1905 | |||
| 1906 | if (status & Y2_IS_PAR_RD1) { | ||
| 1907 | printk(KERN_ERR PFX "%s: ram data read parity error\n", | ||
| 1908 | dev->name); | ||
| 1909 | /* Clear IRQ */ | ||
| 1910 | sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_RD_PERR); | ||
| 1911 | } | ||
| 1912 | |||
| 1913 | if (status & Y2_IS_PAR_WR1) { | ||
| 1914 | printk(KERN_ERR PFX "%s: ram data write parity error\n", | ||
| 1915 | dev->name); | ||
| 1916 | |||
| 1917 | sky2_write16(hw, RAM_BUFFER(port, B3_RI_CTRL), RI_CLR_WR_PERR); | ||
| 1918 | } | ||
| 1919 | |||
| 1920 | if (status & Y2_IS_PAR_MAC1) { | ||
| 1921 | printk(KERN_ERR PFX "%s: MAC parity error\n", dev->name); | ||
| 1922 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_PE); | ||
| 1923 | } | ||
| 1924 | |||
| 1925 | if (status & Y2_IS_PAR_RX1) { | ||
| 1926 | printk(KERN_ERR PFX "%s: RX parity error\n", dev->name); | ||
| 1927 | sky2_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), BMU_CLR_IRQ_PAR); | ||
| 1928 | } | ||
| 1929 | |||
| 1930 | if (status & Y2_IS_TCP_TXA1) { | ||
| 1931 | printk(KERN_ERR PFX "%s: TCP segmentation error\n", dev->name); | ||
| 1932 | sky2_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), BMU_CLR_IRQ_TCP); | ||
| 1933 | } | ||
| 1934 | } | ||
| 1935 | |||
| 1936 | static void sky2_hw_intr(struct sky2_hw *hw) | ||
| 1937 | { | ||
| 1938 | u32 status = sky2_read32(hw, B0_HWE_ISRC); | ||
| 1939 | |||
| 1940 | if (status & Y2_IS_TIST_OV) | ||
| 1941 | sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ); | ||
| 1942 | |||
| 1943 | if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) { | ||
| 1944 | u16 pci_err; | ||
| 1945 | |||
| 1946 | pci_read_config_word(hw->pdev, PCI_STATUS, &pci_err); | ||
| 1947 | printk(KERN_ERR PFX "%s: pci hw error (0x%x)\n", | ||
| 1948 | pci_name(hw->pdev), pci_err); | ||
| 1949 | |||
| 1950 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); | ||
| 1951 | pci_write_config_word(hw->pdev, PCI_STATUS, | ||
| 1952 | pci_err | PCI_STATUS_ERROR_BITS); | ||
| 1953 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); | ||
| 1954 | } | ||
| 1955 | |||
| 1956 | if (status & Y2_IS_PCI_EXP) { | ||
| 1957 | /* PCI-Express uncorrectable Error occurred */ | ||
| 1958 | u32 pex_err; | ||
| 1959 | |||
| 1960 | pci_read_config_dword(hw->pdev, PEX_UNC_ERR_STAT, &pex_err); | ||
| 1961 | |||
| 1962 | printk(KERN_ERR PFX "%s: pci express error (0x%x)\n", | ||
| 1963 | pci_name(hw->pdev), pex_err); | ||
| 1964 | |||
| 1965 | /* clear the interrupt */ | ||
| 1966 | sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); | ||
| 1967 | pci_write_config_dword(hw->pdev, PEX_UNC_ERR_STAT, | ||
| 1968 | 0xffffffffUL); | ||
| 1969 | sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); | ||
| 1970 | |||
| 1971 | if (pex_err & PEX_FATAL_ERRORS) { | ||
| 1972 | u32 hwmsk = sky2_read32(hw, B0_HWE_IMSK); | ||
| 1973 | hwmsk &= ~Y2_IS_PCI_EXP; | ||
| 1974 | sky2_write32(hw, B0_HWE_IMSK, hwmsk); | ||
| 1975 | } | ||
| 1976 | } | ||
| 1977 | |||
| 1978 | if (status & Y2_HWE_L1_MASK) | ||
| 1979 | sky2_hw_error(hw, 0, status); | ||
| 1980 | status >>= 8; | ||
| 1981 | if (status & Y2_HWE_L1_MASK) | ||
| 1982 | sky2_hw_error(hw, 1, status); | ||
| 1983 | } | ||
| 1984 | |||
| 1985 | static void sky2_mac_intr(struct sky2_hw *hw, unsigned port) | ||
| 1986 | { | ||
| 1987 | struct net_device *dev = hw->dev[port]; | ||
| 1988 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 1989 | u8 status = sky2_read8(hw, SK_REG(port, GMAC_IRQ_SRC)); | ||
| 1990 | |||
| 1991 | if (netif_msg_intr(sky2)) | ||
| 1992 | printk(KERN_INFO PFX "%s: mac interrupt status 0x%x\n", | ||
| 1993 | dev->name, status); | ||
| 1994 | |||
| 1995 | if (status & GM_IS_RX_FF_OR) { | ||
| 1996 | ++sky2->net_stats.rx_fifo_errors; | ||
| 1997 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO); | ||
| 1998 | } | ||
| 1999 | |||
| 2000 | if (status & GM_IS_TX_FF_UR) { | ||
| 2001 | ++sky2->net_stats.tx_fifo_errors; | ||
| 2002 | sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU); | ||
| 2003 | } | ||
| 2004 | } | ||
| 2005 | |||
| 2006 | static void sky2_phy_intr(struct sky2_hw *hw, unsigned port) | ||
| 2007 | { | ||
| 2008 | struct net_device *dev = hw->dev[port]; | ||
| 2009 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2010 | |||
| 2011 | hw->intr_mask &= ~(port == 0 ? Y2_IS_IRQ_PHY1 : Y2_IS_IRQ_PHY2); | ||
| 2012 | sky2_write32(hw, B0_IMSK, hw->intr_mask); | ||
| 2013 | schedule_work(&sky2->phy_task); | ||
| 2014 | } | ||
| 2015 | |||
| 2016 | static irqreturn_t sky2_intr(int irq, void *dev_id, struct pt_regs *regs) | ||
| 2017 | { | ||
| 2018 | struct sky2_hw *hw = dev_id; | ||
| 2019 | struct net_device *dev0 = hw->dev[0]; | ||
| 2020 | u32 status; | ||
| 2021 | |||
| 2022 | status = sky2_read32(hw, B0_Y2_SP_ISRC2); | ||
| 2023 | if (status == 0 || status == ~0) | ||
| 2024 | return IRQ_NONE; | ||
| 2025 | |||
| 2026 | if (status & Y2_IS_HW_ERR) | ||
| 2027 | sky2_hw_intr(hw); | ||
| 2028 | |||
| 2029 | /* Do NAPI for Rx and Tx status */ | ||
| 2030 | if (status & Y2_IS_STAT_BMU) { | ||
| 2031 | hw->intr_mask &= ~Y2_IS_STAT_BMU; | ||
| 2032 | sky2_write32(hw, B0_IMSK, hw->intr_mask); | ||
| 2033 | |||
| 2034 | if (likely(__netif_rx_schedule_prep(dev0))) { | ||
| 2035 | prefetch(&hw->st_le[hw->st_idx]); | ||
| 2036 | __netif_rx_schedule(dev0); | ||
| 2037 | } | ||
| 2038 | } | ||
| 2039 | |||
| 2040 | if (status & Y2_IS_IRQ_PHY1) | ||
| 2041 | sky2_phy_intr(hw, 0); | ||
| 2042 | |||
| 2043 | if (status & Y2_IS_IRQ_PHY2) | ||
| 2044 | sky2_phy_intr(hw, 1); | ||
| 2045 | |||
| 2046 | if (status & Y2_IS_IRQ_MAC1) | ||
| 2047 | sky2_mac_intr(hw, 0); | ||
| 2048 | |||
| 2049 | if (status & Y2_IS_IRQ_MAC2) | ||
| 2050 | sky2_mac_intr(hw, 1); | ||
| 2051 | |||
| 2052 | sky2_write32(hw, B0_Y2_SP_ICR, 2); | ||
| 2053 | |||
| 2054 | sky2_read32(hw, B0_IMSK); | ||
| 2055 | |||
| 2056 | return IRQ_HANDLED; | ||
| 2057 | } | ||
| 2058 | |||
| 2059 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
| 2060 | static void sky2_netpoll(struct net_device *dev) | ||
| 2061 | { | ||
| 2062 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2063 | |||
| 2064 | sky2_intr(sky2->hw->pdev->irq, sky2->hw, NULL); | ||
| 2065 | } | ||
| 2066 | #endif | ||
| 2067 | |||
| 2068 | /* Chip internal frequency for clock calculations */ | ||
| 2069 | static inline u32 sky2_mhz(const struct sky2_hw *hw) | ||
| 2070 | { | ||
| 2071 | switch (hw->chip_id) { | ||
| 2072 | case CHIP_ID_YUKON_EC: | ||
| 2073 | case CHIP_ID_YUKON_EC_U: | ||
| 2074 | return 125; /* 125 Mhz */ | ||
| 2075 | case CHIP_ID_YUKON_FE: | ||
| 2076 | return 100; /* 100 Mhz */ | ||
| 2077 | default: /* YUKON_XL */ | ||
| 2078 | return 156; /* 156 Mhz */ | ||
| 2079 | } | ||
| 2080 | } | ||
| 2081 | |||
| 2082 | static inline u32 sky2_us2clk(const struct sky2_hw *hw, u32 us) | ||
| 2083 | { | ||
| 2084 | return sky2_mhz(hw) * us; | ||
| 2085 | } | ||
| 2086 | |||
| 2087 | static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk) | ||
| 2088 | { | ||
| 2089 | return clk / sky2_mhz(hw); | ||
| 2090 | } | ||
| 2091 | |||
| 2092 | |||
| 2093 | static int sky2_reset(struct sky2_hw *hw) | ||
| 2094 | { | ||
| 2095 | u32 ctst; | ||
| 2096 | u16 status; | ||
| 2097 | u8 t8, pmd_type; | ||
| 2098 | int i; | ||
| 2099 | |||
| 2100 | ctst = sky2_read32(hw, B0_CTST); | ||
| 2101 | |||
| 2102 | sky2_write8(hw, B0_CTST, CS_RST_CLR); | ||
| 2103 | hw->chip_id = sky2_read8(hw, B2_CHIP_ID); | ||
| 2104 | if (hw->chip_id < CHIP_ID_YUKON_XL || hw->chip_id > CHIP_ID_YUKON_FE) { | ||
| 2105 | printk(KERN_ERR PFX "%s: unsupported chip type 0x%x\n", | ||
| 2106 | pci_name(hw->pdev), hw->chip_id); | ||
| 2107 | return -EOPNOTSUPP; | ||
| 2108 | } | ||
| 2109 | |||
| 2110 | /* ring for status responses */ | ||
| 2111 | hw->st_le = pci_alloc_consistent(hw->pdev, STATUS_LE_BYTES, | ||
| 2112 | &hw->st_dma); | ||
| 2113 | if (!hw->st_le) | ||
| 2114 | return -ENOMEM; | ||
| 2115 | |||
| 2116 | /* disable ASF */ | ||
| 2117 | if (hw->chip_id <= CHIP_ID_YUKON_EC) { | ||
| 2118 | sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET); | ||
| 2119 | sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE); | ||
| 2120 | } | ||
| 2121 | |||
| 2122 | /* do a SW reset */ | ||
| 2123 | sky2_write8(hw, B0_CTST, CS_RST_SET); | ||
| 2124 | sky2_write8(hw, B0_CTST, CS_RST_CLR); | ||
| 2125 | |||
| 2126 | /* clear PCI errors, if any */ | ||
| 2127 | pci_read_config_word(hw->pdev, PCI_STATUS, &status); | ||
| 2128 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); | ||
| 2129 | pci_write_config_word(hw->pdev, PCI_STATUS, | ||
| 2130 | status | PCI_STATUS_ERROR_BITS); | ||
| 2131 | |||
| 2132 | sky2_write8(hw, B0_CTST, CS_MRST_CLR); | ||
| 2133 | |||
| 2134 | /* clear any PEX errors */ | ||
| 2135 | if (is_pciex(hw)) { | ||
| 2136 | u16 lstat; | ||
| 2137 | pci_write_config_dword(hw->pdev, PEX_UNC_ERR_STAT, | ||
| 2138 | 0xffffffffUL); | ||
| 2139 | pci_read_config_word(hw->pdev, PEX_LNK_STAT, &lstat); | ||
| 2140 | } | ||
| 2141 | |||
| 2142 | pmd_type = sky2_read8(hw, B2_PMD_TYP); | ||
| 2143 | hw->copper = !(pmd_type == 'L' || pmd_type == 'S'); | ||
| 2144 | |||
| 2145 | hw->ports = 1; | ||
| 2146 | t8 = sky2_read8(hw, B2_Y2_HW_RES); | ||
| 2147 | if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) { | ||
| 2148 | if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC)) | ||
| 2149 | ++hw->ports; | ||
| 2150 | } | ||
| 2151 | hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4; | ||
| 2152 | |||
| 2153 | sky2_set_power_state(hw, PCI_D0); | ||
| 2154 | |||
| 2155 | for (i = 0; i < hw->ports; i++) { | ||
| 2156 | sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET); | ||
| 2157 | sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR); | ||
| 2158 | } | ||
| 2159 | |||
| 2160 | sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); | ||
| 2161 | |||
| 2162 | /* Clear I2C IRQ noise */ | ||
| 2163 | sky2_write32(hw, B2_I2C_IRQ, 1); | ||
| 2164 | |||
| 2165 | /* turn off hardware timer (unused) */ | ||
| 2166 | sky2_write8(hw, B2_TI_CTRL, TIM_STOP); | ||
| 2167 | sky2_write8(hw, B2_TI_CTRL, TIM_CLR_IRQ); | ||
| 2168 | |||
| 2169 | sky2_write8(hw, B0_Y2LED, LED_STAT_ON); | ||
| 2170 | |||
| 2171 | /* Turn off descriptor polling */ | ||
| 2172 | sky2_write32(hw, B28_DPT_CTRL, DPT_STOP); | ||
| 2173 | |||
| 2174 | /* Turn off receive timestamp */ | ||
| 2175 | sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_STOP); | ||
| 2176 | sky2_write8(hw, GMAC_TI_ST_CTRL, GMT_ST_CLR_IRQ); | ||
| 2177 | |||
| 2178 | /* enable the Tx Arbiters */ | ||
| 2179 | for (i = 0; i < hw->ports; i++) | ||
| 2180 | sky2_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB); | ||
| 2181 | |||
| 2182 | /* Initialize ram interface */ | ||
| 2183 | for (i = 0; i < hw->ports; i++) { | ||
| 2184 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_CTRL), RI_RST_CLR); | ||
| 2185 | |||
| 2186 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R1), SK_RI_TO_53); | ||
| 2187 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA1), SK_RI_TO_53); | ||
| 2188 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS1), SK_RI_TO_53); | ||
| 2189 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R1), SK_RI_TO_53); | ||
| 2190 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA1), SK_RI_TO_53); | ||
| 2191 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS1), SK_RI_TO_53); | ||
| 2192 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_R2), SK_RI_TO_53); | ||
| 2193 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XA2), SK_RI_TO_53); | ||
| 2194 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_WTO_XS2), SK_RI_TO_53); | ||
| 2195 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_R2), SK_RI_TO_53); | ||
| 2196 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XA2), SK_RI_TO_53); | ||
| 2197 | sky2_write8(hw, RAM_BUFFER(i, B3_RI_RTO_XS2), SK_RI_TO_53); | ||
| 2198 | } | ||
| 2199 | |||
| 2200 | sky2_write32(hw, B0_HWE_IMSK, Y2_HWE_ALL_MASK); | ||
| 2201 | |||
| 2202 | for (i = 0; i < hw->ports; i++) | ||
| 2203 | sky2_phy_reset(hw, i); | ||
| 2204 | |||
| 2205 | memset(hw->st_le, 0, STATUS_LE_BYTES); | ||
| 2206 | hw->st_idx = 0; | ||
| 2207 | |||
| 2208 | sky2_write32(hw, STAT_CTRL, SC_STAT_RST_SET); | ||
| 2209 | sky2_write32(hw, STAT_CTRL, SC_STAT_RST_CLR); | ||
| 2210 | |||
| 2211 | sky2_write32(hw, STAT_LIST_ADDR_LO, hw->st_dma); | ||
| 2212 | sky2_write32(hw, STAT_LIST_ADDR_HI, (u64) hw->st_dma >> 32); | ||
| 2213 | |||
| 2214 | /* Set the list last index */ | ||
| 2215 | sky2_write16(hw, STAT_LAST_IDX, STATUS_RING_SIZE - 1); | ||
| 2216 | |||
| 2217 | /* These status setup values are copied from SysKonnect's driver */ | ||
| 2218 | if (is_ec_a1(hw)) { | ||
| 2219 | /* WA for dev. #4.3 */ | ||
| 2220 | sky2_write16(hw, STAT_TX_IDX_TH, 0xfff); /* Tx Threshold */ | ||
| 2221 | |||
| 2222 | /* set Status-FIFO watermark */ | ||
| 2223 | sky2_write8(hw, STAT_FIFO_WM, 0x21); /* WA for dev. #4.18 */ | ||
| 2224 | |||
| 2225 | /* set Status-FIFO ISR watermark */ | ||
| 2226 | sky2_write8(hw, STAT_FIFO_ISR_WM, 0x07); /* WA for dev. #4.18 */ | ||
| 2227 | sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 10000)); | ||
| 2228 | } else { | ||
| 2229 | sky2_write16(hw, STAT_TX_IDX_TH, 10); | ||
| 2230 | sky2_write8(hw, STAT_FIFO_WM, 16); | ||
| 2231 | |||
| 2232 | /* set Status-FIFO ISR watermark */ | ||
| 2233 | if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev == 0) | ||
| 2234 | sky2_write8(hw, STAT_FIFO_ISR_WM, 4); | ||
| 2235 | else | ||
| 2236 | sky2_write8(hw, STAT_FIFO_ISR_WM, 16); | ||
| 2237 | |||
| 2238 | sky2_write32(hw, STAT_TX_TIMER_INI, sky2_us2clk(hw, 1000)); | ||
| 2239 | sky2_write32(hw, STAT_LEV_TIMER_INI, sky2_us2clk(hw, 100)); | ||
| 2240 | sky2_write32(hw, STAT_ISR_TIMER_INI, sky2_us2clk(hw, 20)); | ||
| 2241 | } | ||
| 2242 | |||
| 2243 | /* enable status unit */ | ||
| 2244 | sky2_write32(hw, STAT_CTRL, SC_STAT_OP_ON); | ||
| 2245 | |||
| 2246 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START); | ||
| 2247 | sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START); | ||
| 2248 | sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START); | ||
| 2249 | |||
| 2250 | return 0; | ||
| 2251 | } | ||
| 2252 | |||
| 2253 | static inline u32 sky2_supported_modes(const struct sky2_hw *hw) | ||
| 2254 | { | ||
| 2255 | u32 modes; | ||
| 2256 | if (hw->copper) { | ||
| 2257 | modes = SUPPORTED_10baseT_Half | ||
| 2258 | | SUPPORTED_10baseT_Full | ||
| 2259 | | SUPPORTED_100baseT_Half | ||
| 2260 | | SUPPORTED_100baseT_Full | ||
| 2261 | | SUPPORTED_Autoneg | SUPPORTED_TP; | ||
| 2262 | |||
| 2263 | if (hw->chip_id != CHIP_ID_YUKON_FE) | ||
| 2264 | modes |= SUPPORTED_1000baseT_Half | ||
| 2265 | | SUPPORTED_1000baseT_Full; | ||
| 2266 | } else | ||
| 2267 | modes = SUPPORTED_1000baseT_Full | SUPPORTED_FIBRE | ||
| 2268 | | SUPPORTED_Autoneg; | ||
| 2269 | return modes; | ||
| 2270 | } | ||
| 2271 | |||
| 2272 | static int sky2_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | ||
| 2273 | { | ||
| 2274 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2275 | struct sky2_hw *hw = sky2->hw; | ||
| 2276 | |||
| 2277 | ecmd->transceiver = XCVR_INTERNAL; | ||
| 2278 | ecmd->supported = sky2_supported_modes(hw); | ||
| 2279 | ecmd->phy_address = PHY_ADDR_MARV; | ||
| 2280 | if (hw->copper) { | ||
| 2281 | ecmd->supported = SUPPORTED_10baseT_Half | ||
| 2282 | | SUPPORTED_10baseT_Full | ||
| 2283 | | SUPPORTED_100baseT_Half | ||
| 2284 | | SUPPORTED_100baseT_Full | ||
| 2285 | | SUPPORTED_1000baseT_Half | ||
| 2286 | | SUPPORTED_1000baseT_Full | ||
| 2287 | | SUPPORTED_Autoneg | SUPPORTED_TP; | ||
| 2288 | ecmd->port = PORT_TP; | ||
| 2289 | } else | ||
| 2290 | ecmd->port = PORT_FIBRE; | ||
| 2291 | |||
| 2292 | ecmd->advertising = sky2->advertising; | ||
| 2293 | ecmd->autoneg = sky2->autoneg; | ||
| 2294 | ecmd->speed = sky2->speed; | ||
| 2295 | ecmd->duplex = sky2->duplex; | ||
| 2296 | return 0; | ||
| 2297 | } | ||
| 2298 | |||
| 2299 | static int sky2_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | ||
| 2300 | { | ||
| 2301 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2302 | const struct sky2_hw *hw = sky2->hw; | ||
| 2303 | u32 supported = sky2_supported_modes(hw); | ||
| 2304 | |||
| 2305 | if (ecmd->autoneg == AUTONEG_ENABLE) { | ||
| 2306 | ecmd->advertising = supported; | ||
| 2307 | sky2->duplex = -1; | ||
| 2308 | sky2->speed = -1; | ||
| 2309 | } else { | ||
| 2310 | u32 setting; | ||
| 2311 | |||
| 2312 | switch (ecmd->speed) { | ||
| 2313 | case SPEED_1000: | ||
| 2314 | if (ecmd->duplex == DUPLEX_FULL) | ||
| 2315 | setting = SUPPORTED_1000baseT_Full; | ||
| 2316 | else if (ecmd->duplex == DUPLEX_HALF) | ||
| 2317 | setting = SUPPORTED_1000baseT_Half; | ||
| 2318 | else | ||
| 2319 | return -EINVAL; | ||
| 2320 | break; | ||
| 2321 | case SPEED_100: | ||
| 2322 | if (ecmd->duplex == DUPLEX_FULL) | ||
| 2323 | setting = SUPPORTED_100baseT_Full; | ||
| 2324 | else if (ecmd->duplex == DUPLEX_HALF) | ||
| 2325 | setting = SUPPORTED_100baseT_Half; | ||
| 2326 | else | ||
| 2327 | return -EINVAL; | ||
| 2328 | break; | ||
| 2329 | |||
| 2330 | case SPEED_10: | ||
| 2331 | if (ecmd->duplex == DUPLEX_FULL) | ||
| 2332 | setting = SUPPORTED_10baseT_Full; | ||
| 2333 | else if (ecmd->duplex == DUPLEX_HALF) | ||
| 2334 | setting = SUPPORTED_10baseT_Half; | ||
| 2335 | else | ||
| 2336 | return -EINVAL; | ||
| 2337 | break; | ||
| 2338 | default: | ||
| 2339 | return -EINVAL; | ||
| 2340 | } | ||
| 2341 | |||
| 2342 | if ((setting & supported) == 0) | ||
| 2343 | return -EINVAL; | ||
| 2344 | |||
| 2345 | sky2->speed = ecmd->speed; | ||
| 2346 | sky2->duplex = ecmd->duplex; | ||
| 2347 | } | ||
| 2348 | |||
| 2349 | sky2->autoneg = ecmd->autoneg; | ||
| 2350 | sky2->advertising = ecmd->advertising; | ||
| 2351 | |||
| 2352 | if (netif_running(dev)) | ||
| 2353 | sky2_phy_reinit(sky2); | ||
| 2354 | |||
| 2355 | return 0; | ||
| 2356 | } | ||
| 2357 | |||
| 2358 | static void sky2_get_drvinfo(struct net_device *dev, | ||
| 2359 | struct ethtool_drvinfo *info) | ||
| 2360 | { | ||
| 2361 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2362 | |||
| 2363 | strcpy(info->driver, DRV_NAME); | ||
| 2364 | strcpy(info->version, DRV_VERSION); | ||
| 2365 | strcpy(info->fw_version, "N/A"); | ||
| 2366 | strcpy(info->bus_info, pci_name(sky2->hw->pdev)); | ||
| 2367 | } | ||
| 2368 | |||
| 2369 | static const struct sky2_stat { | ||
| 2370 | char name[ETH_GSTRING_LEN]; | ||
| 2371 | u16 offset; | ||
| 2372 | } sky2_stats[] = { | ||
| 2373 | { "tx_bytes", GM_TXO_OK_HI }, | ||
| 2374 | { "rx_bytes", GM_RXO_OK_HI }, | ||
| 2375 | { "tx_broadcast", GM_TXF_BC_OK }, | ||
| 2376 | { "rx_broadcast", GM_RXF_BC_OK }, | ||
| 2377 | { "tx_multicast", GM_TXF_MC_OK }, | ||
| 2378 | { "rx_multicast", GM_RXF_MC_OK }, | ||
| 2379 | { "tx_unicast", GM_TXF_UC_OK }, | ||
| 2380 | { "rx_unicast", GM_RXF_UC_OK }, | ||
| 2381 | { "tx_mac_pause", GM_TXF_MPAUSE }, | ||
| 2382 | { "rx_mac_pause", GM_RXF_MPAUSE }, | ||
| 2383 | { "collisions", GM_TXF_SNG_COL }, | ||
| 2384 | { "late_collision",GM_TXF_LAT_COL }, | ||
| 2385 | { "aborted", GM_TXF_ABO_COL }, | ||
| 2386 | { "multi_collisions", GM_TXF_MUL_COL }, | ||
| 2387 | { "fifo_underrun", GM_TXE_FIFO_UR }, | ||
| 2388 | { "fifo_overflow", GM_RXE_FIFO_OV }, | ||
| 2389 | { "rx_toolong", GM_RXF_LNG_ERR }, | ||
| 2390 | { "rx_jabber", GM_RXF_JAB_PKT }, | ||
| 2391 | { "rx_runt", GM_RXE_FRAG }, | ||
| 2392 | { "rx_too_long", GM_RXF_LNG_ERR }, | ||
| 2393 | { "rx_fcs_error", GM_RXF_FCS_ERR }, | ||
| 2394 | }; | ||
| 2395 | |||
| 2396 | static u32 sky2_get_rx_csum(struct net_device *dev) | ||
| 2397 | { | ||
| 2398 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2399 | |||
| 2400 | return sky2->rx_csum; | ||
| 2401 | } | ||
| 2402 | |||
| 2403 | static int sky2_set_rx_csum(struct net_device *dev, u32 data) | ||
| 2404 | { | ||
| 2405 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2406 | |||
| 2407 | sky2->rx_csum = data; | ||
| 2408 | |||
| 2409 | sky2_write32(sky2->hw, Q_ADDR(rxqaddr[sky2->port], Q_CSR), | ||
| 2410 | data ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM); | ||
| 2411 | |||
| 2412 | return 0; | ||
| 2413 | } | ||
| 2414 | |||
| 2415 | static u32 sky2_get_msglevel(struct net_device *netdev) | ||
| 2416 | { | ||
| 2417 | struct sky2_port *sky2 = netdev_priv(netdev); | ||
| 2418 | return sky2->msg_enable; | ||
| 2419 | } | ||
| 2420 | |||
| 2421 | static int sky2_nway_reset(struct net_device *dev) | ||
| 2422 | { | ||
| 2423 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2424 | |||
| 2425 | if (sky2->autoneg != AUTONEG_ENABLE) | ||
| 2426 | return -EINVAL; | ||
| 2427 | |||
| 2428 | sky2_phy_reinit(sky2); | ||
| 2429 | |||
| 2430 | return 0; | ||
| 2431 | } | ||
| 2432 | |||
| 2433 | static void sky2_phy_stats(struct sky2_port *sky2, u64 * data, unsigned count) | ||
| 2434 | { | ||
| 2435 | struct sky2_hw *hw = sky2->hw; | ||
| 2436 | unsigned port = sky2->port; | ||
| 2437 | int i; | ||
| 2438 | |||
| 2439 | data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32 | ||
| 2440 | | (u64) gma_read32(hw, port, GM_TXO_OK_LO); | ||
| 2441 | data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32 | ||
| 2442 | | (u64) gma_read32(hw, port, GM_RXO_OK_LO); | ||
| 2443 | |||
| 2444 | for (i = 2; i < count; i++) | ||
| 2445 | data[i] = (u64) gma_read32(hw, port, sky2_stats[i].offset); | ||
| 2446 | } | ||
| 2447 | |||
| 2448 | static void sky2_set_msglevel(struct net_device *netdev, u32 value) | ||
| 2449 | { | ||
| 2450 | struct sky2_port *sky2 = netdev_priv(netdev); | ||
| 2451 | sky2->msg_enable = value; | ||
| 2452 | } | ||
| 2453 | |||
| 2454 | static int sky2_get_stats_count(struct net_device *dev) | ||
| 2455 | { | ||
| 2456 | return ARRAY_SIZE(sky2_stats); | ||
| 2457 | } | ||
| 2458 | |||
| 2459 | static void sky2_get_ethtool_stats(struct net_device *dev, | ||
| 2460 | struct ethtool_stats *stats, u64 * data) | ||
| 2461 | { | ||
| 2462 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2463 | |||
| 2464 | sky2_phy_stats(sky2, data, ARRAY_SIZE(sky2_stats)); | ||
| 2465 | } | ||
| 2466 | |||
| 2467 | static void sky2_get_strings(struct net_device *dev, u32 stringset, u8 * data) | ||
| 2468 | { | ||
| 2469 | int i; | ||
| 2470 | |||
| 2471 | switch (stringset) { | ||
| 2472 | case ETH_SS_STATS: | ||
| 2473 | for (i = 0; i < ARRAY_SIZE(sky2_stats); i++) | ||
| 2474 | memcpy(data + i * ETH_GSTRING_LEN, | ||
| 2475 | sky2_stats[i].name, ETH_GSTRING_LEN); | ||
| 2476 | break; | ||
| 2477 | } | ||
| 2478 | } | ||
| 2479 | |||
| 2480 | /* Use hardware MIB variables for critical path statistics and | ||
| 2481 | * transmit feedback not reported at interrupt. | ||
| 2482 | * Other errors are accounted for in interrupt handler. | ||
| 2483 | */ | ||
| 2484 | static struct net_device_stats *sky2_get_stats(struct net_device *dev) | ||
| 2485 | { | ||
| 2486 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2487 | u64 data[13]; | ||
| 2488 | |||
| 2489 | sky2_phy_stats(sky2, data, ARRAY_SIZE(data)); | ||
| 2490 | |||
| 2491 | sky2->net_stats.tx_bytes = data[0]; | ||
| 2492 | sky2->net_stats.rx_bytes = data[1]; | ||
| 2493 | sky2->net_stats.tx_packets = data[2] + data[4] + data[6]; | ||
| 2494 | sky2->net_stats.rx_packets = data[3] + data[5] + data[7]; | ||
| 2495 | sky2->net_stats.multicast = data[5] + data[7]; | ||
| 2496 | sky2->net_stats.collisions = data[10]; | ||
| 2497 | sky2->net_stats.tx_aborted_errors = data[12]; | ||
| 2498 | |||
| 2499 | return &sky2->net_stats; | ||
| 2500 | } | ||
| 2501 | |||
| 2502 | static int sky2_set_mac_address(struct net_device *dev, void *p) | ||
| 2503 | { | ||
| 2504 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2505 | struct sockaddr *addr = p; | ||
| 2506 | |||
| 2507 | if (!is_valid_ether_addr(addr->sa_data)) | ||
| 2508 | return -EADDRNOTAVAIL; | ||
| 2509 | |||
| 2510 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); | ||
| 2511 | memcpy_toio(sky2->hw->regs + B2_MAC_1 + sky2->port * 8, | ||
| 2512 | dev->dev_addr, ETH_ALEN); | ||
| 2513 | memcpy_toio(sky2->hw->regs + B2_MAC_2 + sky2->port * 8, | ||
| 2514 | dev->dev_addr, ETH_ALEN); | ||
| 2515 | |||
| 2516 | if (netif_running(dev)) | ||
| 2517 | sky2_phy_reinit(sky2); | ||
| 2518 | |||
| 2519 | return 0; | ||
| 2520 | } | ||
| 2521 | |||
| 2522 | static void sky2_set_multicast(struct net_device *dev) | ||
| 2523 | { | ||
| 2524 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2525 | struct sky2_hw *hw = sky2->hw; | ||
| 2526 | unsigned port = sky2->port; | ||
| 2527 | struct dev_mc_list *list = dev->mc_list; | ||
| 2528 | u16 reg; | ||
| 2529 | u8 filter[8]; | ||
| 2530 | |||
| 2531 | memset(filter, 0, sizeof(filter)); | ||
| 2532 | |||
| 2533 | reg = gma_read16(hw, port, GM_RX_CTRL); | ||
| 2534 | reg |= GM_RXCR_UCF_ENA; | ||
| 2535 | |||
| 2536 | if (dev->flags & IFF_PROMISC) /* promiscuous */ | ||
| 2537 | reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); | ||
| 2538 | else if ((dev->flags & IFF_ALLMULTI) || dev->mc_count > 16) /* all multicast */ | ||
| 2539 | memset(filter, 0xff, sizeof(filter)); | ||
| 2540 | else if (dev->mc_count == 0) /* no multicast */ | ||
| 2541 | reg &= ~GM_RXCR_MCF_ENA; | ||
| 2542 | else { | ||
| 2543 | int i; | ||
| 2544 | reg |= GM_RXCR_MCF_ENA; | ||
| 2545 | |||
| 2546 | for (i = 0; list && i < dev->mc_count; i++, list = list->next) { | ||
| 2547 | u32 bit = ether_crc(ETH_ALEN, list->dmi_addr) & 0x3f; | ||
| 2548 | filter[bit / 8] |= 1 << (bit % 8); | ||
| 2549 | } | ||
| 2550 | } | ||
| 2551 | |||
| 2552 | gma_write16(hw, port, GM_MC_ADDR_H1, | ||
| 2553 | (u16) filter[0] | ((u16) filter[1] << 8)); | ||
| 2554 | gma_write16(hw, port, GM_MC_ADDR_H2, | ||
| 2555 | (u16) filter[2] | ((u16) filter[3] << 8)); | ||
| 2556 | gma_write16(hw, port, GM_MC_ADDR_H3, | ||
| 2557 | (u16) filter[4] | ((u16) filter[5] << 8)); | ||
| 2558 | gma_write16(hw, port, GM_MC_ADDR_H4, | ||
| 2559 | (u16) filter[6] | ((u16) filter[7] << 8)); | ||
| 2560 | |||
| 2561 | gma_write16(hw, port, GM_RX_CTRL, reg); | ||
| 2562 | } | ||
| 2563 | |||
| 2564 | /* Can have one global because blinking is controlled by | ||
| 2565 | * ethtool and that is always under RTNL mutex | ||
| 2566 | */ | ||
| 2567 | static void sky2_led(struct sky2_hw *hw, unsigned port, int on) | ||
| 2568 | { | ||
| 2569 | u16 pg; | ||
| 2570 | |||
| 2571 | switch (hw->chip_id) { | ||
| 2572 | case CHIP_ID_YUKON_XL: | ||
| 2573 | pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); | ||
| 2574 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); | ||
| 2575 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, | ||
| 2576 | on ? (PHY_M_LEDC_LOS_CTRL(1) | | ||
| 2577 | PHY_M_LEDC_INIT_CTRL(7) | | ||
| 2578 | PHY_M_LEDC_STA1_CTRL(7) | | ||
| 2579 | PHY_M_LEDC_STA0_CTRL(7)) | ||
| 2580 | : 0); | ||
| 2581 | |||
| 2582 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); | ||
| 2583 | break; | ||
| 2584 | |||
| 2585 | default: | ||
| 2586 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); | ||
| 2587 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, | ||
| 2588 | on ? PHY_M_LED_MO_DUP(MO_LED_ON) | | ||
| 2589 | PHY_M_LED_MO_10(MO_LED_ON) | | ||
| 2590 | PHY_M_LED_MO_100(MO_LED_ON) | | ||
| 2591 | PHY_M_LED_MO_1000(MO_LED_ON) | | ||
| 2592 | PHY_M_LED_MO_RX(MO_LED_ON) | ||
| 2593 | : PHY_M_LED_MO_DUP(MO_LED_OFF) | | ||
| 2594 | PHY_M_LED_MO_10(MO_LED_OFF) | | ||
| 2595 | PHY_M_LED_MO_100(MO_LED_OFF) | | ||
| 2596 | PHY_M_LED_MO_1000(MO_LED_OFF) | | ||
| 2597 | PHY_M_LED_MO_RX(MO_LED_OFF)); | ||
| 2598 | |||
| 2599 | } | ||
| 2600 | } | ||
| 2601 | |||
| 2602 | /* blink LED's for finding board */ | ||
| 2603 | static int sky2_phys_id(struct net_device *dev, u32 data) | ||
| 2604 | { | ||
| 2605 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2606 | struct sky2_hw *hw = sky2->hw; | ||
| 2607 | unsigned port = sky2->port; | ||
| 2608 | u16 ledctrl, ledover = 0; | ||
| 2609 | long ms; | ||
| 2610 | int interrupted; | ||
| 2611 | int onoff = 1; | ||
| 2612 | |||
| 2613 | if (!data || data > (u32) (MAX_SCHEDULE_TIMEOUT / HZ)) | ||
| 2614 | ms = jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT); | ||
| 2615 | else | ||
| 2616 | ms = data * 1000; | ||
| 2617 | |||
| 2618 | /* save initial values */ | ||
| 2619 | down(&sky2->phy_sema); | ||
| 2620 | if (hw->chip_id == CHIP_ID_YUKON_XL) { | ||
| 2621 | u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); | ||
| 2622 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); | ||
| 2623 | ledctrl = gm_phy_read(hw, port, PHY_MARV_PHY_CTRL); | ||
| 2624 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); | ||
| 2625 | } else { | ||
| 2626 | ledctrl = gm_phy_read(hw, port, PHY_MARV_LED_CTRL); | ||
| 2627 | ledover = gm_phy_read(hw, port, PHY_MARV_LED_OVER); | ||
| 2628 | } | ||
| 2629 | |||
| 2630 | interrupted = 0; | ||
| 2631 | while (!interrupted && ms > 0) { | ||
| 2632 | sky2_led(hw, port, onoff); | ||
| 2633 | onoff = !onoff; | ||
| 2634 | |||
| 2635 | up(&sky2->phy_sema); | ||
| 2636 | interrupted = msleep_interruptible(250); | ||
| 2637 | down(&sky2->phy_sema); | ||
| 2638 | |||
| 2639 | ms -= 250; | ||
| 2640 | } | ||
| 2641 | |||
| 2642 | /* resume regularly scheduled programming */ | ||
| 2643 | if (hw->chip_id == CHIP_ID_YUKON_XL) { | ||
| 2644 | u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR); | ||
| 2645 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3); | ||
| 2646 | gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, ledctrl); | ||
| 2647 | gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); | ||
| 2648 | } else { | ||
| 2649 | gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl); | ||
| 2650 | gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover); | ||
| 2651 | } | ||
| 2652 | up(&sky2->phy_sema); | ||
| 2653 | |||
| 2654 | return 0; | ||
| 2655 | } | ||
| 2656 | |||
| 2657 | static void sky2_get_pauseparam(struct net_device *dev, | ||
| 2658 | struct ethtool_pauseparam *ecmd) | ||
| 2659 | { | ||
| 2660 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2661 | |||
| 2662 | ecmd->tx_pause = sky2->tx_pause; | ||
| 2663 | ecmd->rx_pause = sky2->rx_pause; | ||
| 2664 | ecmd->autoneg = sky2->autoneg; | ||
| 2665 | } | ||
| 2666 | |||
| 2667 | static int sky2_set_pauseparam(struct net_device *dev, | ||
| 2668 | struct ethtool_pauseparam *ecmd) | ||
| 2669 | { | ||
| 2670 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2671 | int err = 0; | ||
| 2672 | |||
| 2673 | sky2->autoneg = ecmd->autoneg; | ||
| 2674 | sky2->tx_pause = ecmd->tx_pause != 0; | ||
| 2675 | sky2->rx_pause = ecmd->rx_pause != 0; | ||
| 2676 | |||
| 2677 | sky2_phy_reinit(sky2); | ||
| 2678 | |||
| 2679 | return err; | ||
| 2680 | } | ||
| 2681 | |||
| 2682 | #ifdef CONFIG_PM | ||
| 2683 | static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | ||
| 2684 | { | ||
| 2685 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2686 | |||
| 2687 | wol->supported = WAKE_MAGIC; | ||
| 2688 | wol->wolopts = sky2->wol ? WAKE_MAGIC : 0; | ||
| 2689 | } | ||
| 2690 | |||
| 2691 | static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | ||
| 2692 | { | ||
| 2693 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2694 | struct sky2_hw *hw = sky2->hw; | ||
| 2695 | |||
| 2696 | if (wol->wolopts != WAKE_MAGIC && wol->wolopts != 0) | ||
| 2697 | return -EOPNOTSUPP; | ||
| 2698 | |||
| 2699 | sky2->wol = wol->wolopts == WAKE_MAGIC; | ||
| 2700 | |||
| 2701 | if (sky2->wol) { | ||
| 2702 | memcpy_toio(hw->regs + WOL_MAC_ADDR, dev->dev_addr, ETH_ALEN); | ||
| 2703 | |||
| 2704 | sky2_write16(hw, WOL_CTRL_STAT, | ||
| 2705 | WOL_CTL_ENA_PME_ON_MAGIC_PKT | | ||
| 2706 | WOL_CTL_ENA_MAGIC_PKT_UNIT); | ||
| 2707 | } else | ||
| 2708 | sky2_write16(hw, WOL_CTRL_STAT, WOL_CTL_DEFAULT); | ||
| 2709 | |||
| 2710 | return 0; | ||
| 2711 | } | ||
| 2712 | #endif | ||
| 2713 | |||
| 2714 | static int sky2_get_coalesce(struct net_device *dev, | ||
| 2715 | struct ethtool_coalesce *ecmd) | ||
| 2716 | { | ||
| 2717 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2718 | struct sky2_hw *hw = sky2->hw; | ||
| 2719 | |||
| 2720 | if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_STOP) | ||
| 2721 | ecmd->tx_coalesce_usecs = 0; | ||
| 2722 | else { | ||
| 2723 | u32 clks = sky2_read32(hw, STAT_TX_TIMER_INI); | ||
| 2724 | ecmd->tx_coalesce_usecs = sky2_clk2us(hw, clks); | ||
| 2725 | } | ||
| 2726 | ecmd->tx_max_coalesced_frames = sky2_read16(hw, STAT_TX_IDX_TH); | ||
| 2727 | |||
| 2728 | if (sky2_read8(hw, STAT_LEV_TIMER_CTRL) == TIM_STOP) | ||
| 2729 | ecmd->rx_coalesce_usecs = 0; | ||
| 2730 | else { | ||
| 2731 | u32 clks = sky2_read32(hw, STAT_LEV_TIMER_INI); | ||
| 2732 | ecmd->rx_coalesce_usecs = sky2_clk2us(hw, clks); | ||
| 2733 | } | ||
| 2734 | ecmd->rx_max_coalesced_frames = sky2_read8(hw, STAT_FIFO_WM); | ||
| 2735 | |||
| 2736 | if (sky2_read8(hw, STAT_ISR_TIMER_CTRL) == TIM_STOP) | ||
| 2737 | ecmd->rx_coalesce_usecs_irq = 0; | ||
| 2738 | else { | ||
| 2739 | u32 clks = sky2_read32(hw, STAT_ISR_TIMER_INI); | ||
| 2740 | ecmd->rx_coalesce_usecs_irq = sky2_clk2us(hw, clks); | ||
| 2741 | } | ||
| 2742 | |||
| 2743 | ecmd->rx_max_coalesced_frames_irq = sky2_read8(hw, STAT_FIFO_ISR_WM); | ||
| 2744 | |||
| 2745 | return 0; | ||
| 2746 | } | ||
| 2747 | |||
| 2748 | /* Note: this affect both ports */ | ||
| 2749 | static int sky2_set_coalesce(struct net_device *dev, | ||
| 2750 | struct ethtool_coalesce *ecmd) | ||
| 2751 | { | ||
| 2752 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2753 | struct sky2_hw *hw = sky2->hw; | ||
| 2754 | const u32 tmin = sky2_clk2us(hw, 1); | ||
| 2755 | const u32 tmax = 5000; | ||
| 2756 | |||
| 2757 | if (ecmd->tx_coalesce_usecs != 0 && | ||
| 2758 | (ecmd->tx_coalesce_usecs < tmin || ecmd->tx_coalesce_usecs > tmax)) | ||
| 2759 | return -EINVAL; | ||
| 2760 | |||
| 2761 | if (ecmd->rx_coalesce_usecs != 0 && | ||
| 2762 | (ecmd->rx_coalesce_usecs < tmin || ecmd->rx_coalesce_usecs > tmax)) | ||
| 2763 | return -EINVAL; | ||
| 2764 | |||
| 2765 | if (ecmd->rx_coalesce_usecs_irq != 0 && | ||
| 2766 | (ecmd->rx_coalesce_usecs_irq < tmin || ecmd->rx_coalesce_usecs_irq > tmax)) | ||
| 2767 | return -EINVAL; | ||
| 2768 | |||
| 2769 | if (ecmd->tx_max_coalesced_frames > 0xffff) | ||
| 2770 | return -EINVAL; | ||
| 2771 | if (ecmd->rx_max_coalesced_frames > 0xff) | ||
| 2772 | return -EINVAL; | ||
| 2773 | if (ecmd->rx_max_coalesced_frames_irq > 0xff) | ||
| 2774 | return -EINVAL; | ||
| 2775 | |||
| 2776 | if (ecmd->tx_coalesce_usecs == 0) | ||
| 2777 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP); | ||
| 2778 | else { | ||
| 2779 | sky2_write32(hw, STAT_TX_TIMER_INI, | ||
| 2780 | sky2_us2clk(hw, ecmd->tx_coalesce_usecs)); | ||
| 2781 | sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START); | ||
| 2782 | } | ||
| 2783 | sky2_write16(hw, STAT_TX_IDX_TH, ecmd->tx_max_coalesced_frames); | ||
| 2784 | |||
| 2785 | if (ecmd->rx_coalesce_usecs == 0) | ||
| 2786 | sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_STOP); | ||
| 2787 | else { | ||
| 2788 | sky2_write32(hw, STAT_LEV_TIMER_INI, | ||
| 2789 | sky2_us2clk(hw, ecmd->rx_coalesce_usecs)); | ||
| 2790 | sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START); | ||
| 2791 | } | ||
| 2792 | sky2_write8(hw, STAT_FIFO_WM, ecmd->rx_max_coalesced_frames); | ||
| 2793 | |||
| 2794 | if (ecmd->rx_coalesce_usecs_irq == 0) | ||
| 2795 | sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_STOP); | ||
| 2796 | else { | ||
| 2797 | sky2_write32(hw, STAT_TX_TIMER_INI, | ||
| 2798 | sky2_us2clk(hw, ecmd->rx_coalesce_usecs_irq)); | ||
| 2799 | sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START); | ||
| 2800 | } | ||
| 2801 | sky2_write8(hw, STAT_FIFO_ISR_WM, ecmd->rx_max_coalesced_frames_irq); | ||
| 2802 | return 0; | ||
| 2803 | } | ||
| 2804 | |||
| 2805 | static void sky2_get_ringparam(struct net_device *dev, | ||
| 2806 | struct ethtool_ringparam *ering) | ||
| 2807 | { | ||
| 2808 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2809 | |||
| 2810 | ering->rx_max_pending = RX_MAX_PENDING; | ||
| 2811 | ering->rx_mini_max_pending = 0; | ||
| 2812 | ering->rx_jumbo_max_pending = 0; | ||
| 2813 | ering->tx_max_pending = TX_RING_SIZE - 1; | ||
| 2814 | |||
| 2815 | ering->rx_pending = sky2->rx_pending; | ||
| 2816 | ering->rx_mini_pending = 0; | ||
| 2817 | ering->rx_jumbo_pending = 0; | ||
| 2818 | ering->tx_pending = sky2->tx_pending; | ||
| 2819 | } | ||
| 2820 | |||
| 2821 | static int sky2_set_ringparam(struct net_device *dev, | ||
| 2822 | struct ethtool_ringparam *ering) | ||
| 2823 | { | ||
| 2824 | struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2825 | int err = 0; | ||
| 2826 | |||
| 2827 | if (ering->rx_pending > RX_MAX_PENDING || | ||
| 2828 | ering->rx_pending < 8 || | ||
| 2829 | ering->tx_pending < MAX_SKB_TX_LE || | ||
| 2830 | ering->tx_pending > TX_RING_SIZE - 1) | ||
| 2831 | return -EINVAL; | ||
| 2832 | |||
| 2833 | if (netif_running(dev)) | ||
| 2834 | sky2_down(dev); | ||
| 2835 | |||
| 2836 | sky2->rx_pending = ering->rx_pending; | ||
| 2837 | sky2->tx_pending = ering->tx_pending; | ||
| 2838 | |||
| 2839 | if (netif_running(dev)) { | ||
| 2840 | err = sky2_up(dev); | ||
| 2841 | if (err) | ||
| 2842 | dev_close(dev); | ||
| 2843 | else | ||
| 2844 | sky2_set_multicast(dev); | ||
| 2845 | } | ||
| 2846 | |||
| 2847 | return err; | ||
| 2848 | } | ||
| 2849 | |||
| 2850 | static int sky2_get_regs_len(struct net_device *dev) | ||
| 2851 | { | ||
| 2852 | return 0x4000; | ||
| 2853 | } | ||
| 2854 | |||
| 2855 | /* | ||
| 2856 | * Returns copy of control register region | ||
| 2857 | * Note: access to the RAM address register set will cause timeouts. | ||
| 2858 | */ | ||
| 2859 | static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs, | ||
| 2860 | void *p) | ||
| 2861 | { | ||
| 2862 | const struct sky2_port *sky2 = netdev_priv(dev); | ||
| 2863 | const void __iomem *io = sky2->hw->regs; | ||
| 2864 | |||
| 2865 | BUG_ON(regs->len < B3_RI_WTO_R1); | ||
| 2866 | regs->version = 1; | ||
| 2867 | memset(p, 0, regs->len); | ||
| 2868 | |||
| 2869 | memcpy_fromio(p, io, B3_RAM_ADDR); | ||
| 2870 | |||
| 2871 | memcpy_fromio(p + B3_RI_WTO_R1, | ||
| 2872 | io + B3_RI_WTO_R1, | ||
| 2873 | regs->len - B3_RI_WTO_R1); | ||
| 2874 | } | ||
| 2875 | |||
| 2876 | static struct ethtool_ops sky2_ethtool_ops = { | ||
| 2877 | .get_settings = sky2_get_settings, | ||
| 2878 | .set_settings = sky2_set_settings, | ||
| 2879 | .get_drvinfo = sky2_get_drvinfo, | ||
| 2880 | .get_msglevel = sky2_get_msglevel, | ||
| 2881 | .set_msglevel = sky2_set_msglevel, | ||
| 2882 | .nway_reset = sky2_nway_reset, | ||
| 2883 | .get_regs_len = sky2_get_regs_len, | ||
| 2884 | .get_regs = sky2_get_regs, | ||
| 2885 | .get_link = ethtool_op_get_link, | ||
| 2886 | .get_sg = ethtool_op_get_sg, | ||
| 2887 | .set_sg = ethtool_op_set_sg, | ||
| 2888 | .get_tx_csum = ethtool_op_get_tx_csum, | ||
| 2889 | .set_tx_csum = ethtool_op_set_tx_csum, | ||
| 2890 | .get_tso = ethtool_op_get_tso, | ||
| 2891 | .set_tso = ethtool_op_set_tso, | ||
| 2892 | .get_rx_csum = sky2_get_rx_csum, | ||
| 2893 | .set_rx_csum = sky2_set_rx_csum, | ||
| 2894 | .get_strings = sky2_get_strings, | ||
| 2895 | .get_coalesce = sky2_get_coalesce, | ||
| 2896 | .set_coalesce = sky2_set_coalesce, | ||
| 2897 | .get_ringparam = sky2_get_ringparam, | ||
| 2898 | .set_ringparam = sky2_set_ringparam, | ||
| 2899 | .get_pauseparam = sky2_get_pauseparam, | ||
| 2900 | .set_pauseparam = sky2_set_pauseparam, | ||
| 2901 | #ifdef CONFIG_PM | ||
| 2902 | .get_wol = sky2_get_wol, | ||
| 2903 | .set_wol = sky2_set_wol, | ||
| 2904 | #endif | ||
| 2905 | .phys_id = sky2_phys_id, | ||
| 2906 | .get_stats_count = sky2_get_stats_count, | ||
| 2907 | .get_ethtool_stats = sky2_get_ethtool_stats, | ||
| 2908 | .get_perm_addr = ethtool_op_get_perm_addr, | ||
| 2909 | }; | ||
| 2910 | |||
| 2911 | /* Initialize network device */ | ||
| 2912 | static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw, | ||
| 2913 | unsigned port, int highmem) | ||
| 2914 | { | ||
| 2915 | struct sky2_port *sky2; | ||
| 2916 | struct net_device *dev = alloc_etherdev(sizeof(*sky2)); | ||
| 2917 | |||
| 2918 | if (!dev) { | ||
| 2919 | printk(KERN_ERR "sky2 etherdev alloc failed"); | ||
| 2920 | return NULL; | ||
| 2921 | } | ||
| 2922 | |||
| 2923 | SET_MODULE_OWNER(dev); | ||
| 2924 | SET_NETDEV_DEV(dev, &hw->pdev->dev); | ||
| 2925 | dev->irq = hw->pdev->irq; | ||
| 2926 | dev->open = sky2_up; | ||
| 2927 | dev->stop = sky2_down; | ||
| 2928 | dev->do_ioctl = sky2_ioctl; | ||
| 2929 | dev->hard_start_xmit = sky2_xmit_frame; | ||
| 2930 | dev->get_stats = sky2_get_stats; | ||
| 2931 | dev->set_multicast_list = sky2_set_multicast; | ||
| 2932 | dev->set_mac_address = sky2_set_mac_address; | ||
| 2933 | dev->change_mtu = sky2_change_mtu; | ||
| 2934 | SET_ETHTOOL_OPS(dev, &sky2_ethtool_ops); | ||
| 2935 | dev->tx_timeout = sky2_tx_timeout; | ||
| 2936 | dev->watchdog_timeo = TX_WATCHDOG; | ||
| 2937 | if (port == 0) | ||
| 2938 | dev->poll = sky2_poll; | ||
| 2939 | dev->weight = NAPI_WEIGHT; | ||
| 2940 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
| 2941 | dev->poll_controller = sky2_netpoll; | ||
| 2942 | #endif | ||
| 2943 | |||
| 2944 | sky2 = netdev_priv(dev); | ||
| 2945 | sky2->netdev = dev; | ||
| 2946 | sky2->hw = hw; | ||
| 2947 | sky2->msg_enable = netif_msg_init(debug, default_msg); | ||
| 2948 | |||
| 2949 | spin_lock_init(&sky2->tx_lock); | ||
| 2950 | /* Auto speed and flow control */ | ||
| 2951 | sky2->autoneg = AUTONEG_ENABLE; | ||
| 2952 | sky2->tx_pause = 1; | ||
| 2953 | sky2->rx_pause = 1; | ||
| 2954 | sky2->duplex = -1; | ||
| 2955 | sky2->speed = -1; | ||
| 2956 | sky2->advertising = sky2_supported_modes(hw); | ||
| 2957 | |||
| 2958 | /* Receive checksum disabled for Yukon XL | ||
| 2959 | * because of observed problems with incorrect | ||
| 2960 | * values when multiple packets are received in one interrupt | ||
| 2961 | */ | ||
| 2962 | sky2->rx_csum = (hw->chip_id != CHIP_ID_YUKON_XL); | ||
| 2963 | |||
| 2964 | INIT_WORK(&sky2->phy_task, sky2_phy_task, sky2); | ||
| 2965 | init_MUTEX(&sky2->phy_sema); | ||
| 2966 | sky2->tx_pending = TX_DEF_PENDING; | ||
| 2967 | sky2->rx_pending = is_ec_a1(hw) ? 8 : RX_DEF_PENDING; | ||
| 2968 | sky2->rx_bufsize = sky2_buf_size(ETH_DATA_LEN); | ||
| 2969 | |||
| 2970 | hw->dev[port] = dev; | ||
| 2971 | |||
| 2972 | sky2->port = port; | ||
| 2973 | |||
| 2974 | dev->features |= NETIF_F_LLTX; | ||
| 2975 | if (hw->chip_id != CHIP_ID_YUKON_EC_U) | ||
| 2976 | dev->features |= NETIF_F_TSO; | ||
| 2977 | if (highmem) | ||
| 2978 | dev->features |= NETIF_F_HIGHDMA; | ||
| 2979 | dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG; | ||
| 2980 | |||
| 2981 | #ifdef SKY2_VLAN_TAG_USED | ||
| 2982 | dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; | ||
| 2983 | dev->vlan_rx_register = sky2_vlan_rx_register; | ||
| 2984 | dev->vlan_rx_kill_vid = sky2_vlan_rx_kill_vid; | ||
| 2985 | #endif | ||
| 2986 | |||
| 2987 | /* read the mac address */ | ||
| 2988 | memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8, ETH_ALEN); | ||
| 2989 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); | ||
| 2990 | |||
| 2991 | /* device is off until link detection */ | ||
| 2992 | netif_carrier_off(dev); | ||
| 2993 | netif_stop_queue(dev); | ||
| 2994 | |||
| 2995 | return dev; | ||
| 2996 | } | ||
| 2997 | |||
| 2998 | static inline void sky2_show_addr(struct net_device *dev) | ||
| 2999 | { | ||
| 3000 | const struct sky2_port *sky2 = netdev_priv(dev); | ||
| 3001 | |||
| 3002 | if (netif_msg_probe(sky2)) | ||
| 3003 | printk(KERN_INFO PFX "%s: addr %02x:%02x:%02x:%02x:%02x:%02x\n", | ||
| 3004 | dev->name, | ||
| 3005 | dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], | ||
| 3006 | dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); | ||
| 3007 | } | ||
| 3008 | |||
| 3009 | static int __devinit sky2_probe(struct pci_dev *pdev, | ||
| 3010 | const struct pci_device_id *ent) | ||
| 3011 | { | ||
| 3012 | struct net_device *dev, *dev1 = NULL; | ||
| 3013 | struct sky2_hw *hw; | ||
| 3014 | int err, pm_cap, using_dac = 0; | ||
| 3015 | |||
| 3016 | err = pci_enable_device(pdev); | ||
| 3017 | if (err) { | ||
| 3018 | printk(KERN_ERR PFX "%s cannot enable PCI device\n", | ||
| 3019 | pci_name(pdev)); | ||
| 3020 | goto err_out; | ||
| 3021 | } | ||
| 3022 | |||
| 3023 | err = pci_request_regions(pdev, DRV_NAME); | ||
| 3024 | if (err) { | ||
| 3025 | printk(KERN_ERR PFX "%s cannot obtain PCI resources\n", | ||
| 3026 | pci_name(pdev)); | ||
| 3027 | goto err_out; | ||
| 3028 | } | ||
| 3029 | |||
| 3030 | pci_set_master(pdev); | ||
| 3031 | |||
| 3032 | /* Find power-management capability. */ | ||
| 3033 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); | ||
| 3034 | if (pm_cap == 0) { | ||
| 3035 | printk(KERN_ERR PFX "Cannot find PowerManagement capability, " | ||
| 3036 | "aborting.\n"); | ||
| 3037 | err = -EIO; | ||
| 3038 | goto err_out_free_regions; | ||
| 3039 | } | ||
| 3040 | |||
| 3041 | if (sizeof(dma_addr_t) > sizeof(u32)) { | ||
| 3042 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); | ||
| 3043 | if (!err) | ||
| 3044 | using_dac = 1; | ||
| 3045 | } | ||
| 3046 | |||
| 3047 | if (!using_dac) { | ||
| 3048 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); | ||
| 3049 | if (err) { | ||
| 3050 | printk(KERN_ERR PFX "%s no usable DMA configuration\n", | ||
| 3051 | pci_name(pdev)); | ||
| 3052 | goto err_out_free_regions; | ||
| 3053 | } | ||
| 3054 | } | ||
| 3055 | #ifdef __BIG_ENDIAN | ||
| 3056 | /* byte swap descriptors in hardware */ | ||
| 3057 | { | ||
| 3058 | u32 reg; | ||
| 3059 | |||
| 3060 | pci_read_config_dword(pdev, PCI_DEV_REG2, ®); | ||
| 3061 | reg |= PCI_REV_DESC; | ||
| 3062 | pci_write_config_dword(pdev, PCI_DEV_REG2, reg); | ||
| 3063 | } | ||
| 3064 | #endif | ||
| 3065 | |||
| 3066 | err = -ENOMEM; | ||
| 3067 | hw = kmalloc(sizeof(*hw), GFP_KERNEL); | ||
| 3068 | if (!hw) { | ||
| 3069 | printk(KERN_ERR PFX "%s: cannot allocate hardware struct\n", | ||
| 3070 | pci_name(pdev)); | ||
| 3071 | goto err_out_free_regions; | ||
| 3072 | } | ||
| 3073 | |||
| 3074 | memset(hw, 0, sizeof(*hw)); | ||
| 3075 | hw->pdev = pdev; | ||
| 3076 | |||
| 3077 | hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000); | ||
| 3078 | if (!hw->regs) { | ||
| 3079 | printk(KERN_ERR PFX "%s: cannot map device registers\n", | ||
| 3080 | pci_name(pdev)); | ||
| 3081 | goto err_out_free_hw; | ||
| 3082 | } | ||
| 3083 | hw->pm_cap = pm_cap; | ||
| 3084 | |||
| 3085 | err = sky2_reset(hw); | ||
| 3086 | if (err) | ||
| 3087 | goto err_out_iounmap; | ||
| 3088 | |||
| 3089 | printk(KERN_INFO PFX "v%s addr 0x%lx irq %d Yukon-%s (0x%x) rev %d\n", | ||
| 3090 | DRV_VERSION, pci_resource_start(pdev, 0), pdev->irq, | ||
| 3091 | yukon2_name[hw->chip_id - CHIP_ID_YUKON_XL], | ||
| 3092 | hw->chip_id, hw->chip_rev); | ||
| 3093 | |||
| 3094 | dev = sky2_init_netdev(hw, 0, using_dac); | ||
| 3095 | if (!dev) | ||
| 3096 | goto err_out_free_pci; | ||
| 3097 | |||
| 3098 | err = register_netdev(dev); | ||
| 3099 | if (err) { | ||
| 3100 | printk(KERN_ERR PFX "%s: cannot register net device\n", | ||
| 3101 | pci_name(pdev)); | ||
| 3102 | goto err_out_free_netdev; | ||
| 3103 | } | ||
| 3104 | |||
| 3105 | sky2_show_addr(dev); | ||
| 3106 | |||
| 3107 | if (hw->ports > 1 && (dev1 = sky2_init_netdev(hw, 1, using_dac))) { | ||
| 3108 | if (register_netdev(dev1) == 0) | ||
| 3109 | sky2_show_addr(dev1); | ||
| 3110 | else { | ||
| 3111 | /* Failure to register second port need not be fatal */ | ||
| 3112 | printk(KERN_WARNING PFX | ||
| 3113 | "register of second port failed\n"); | ||
| 3114 | hw->dev[1] = NULL; | ||
| 3115 | free_netdev(dev1); | ||
| 3116 | } | ||
| 3117 | } | ||
| 3118 | |||
| 3119 | err = request_irq(pdev->irq, sky2_intr, SA_SHIRQ, DRV_NAME, hw); | ||
| 3120 | if (err) { | ||
| 3121 | printk(KERN_ERR PFX "%s: cannot assign irq %d\n", | ||
| 3122 | pci_name(pdev), pdev->irq); | ||
| 3123 | goto err_out_unregister; | ||
| 3124 | } | ||
| 3125 | |||
| 3126 | hw->intr_mask = Y2_IS_BASE; | ||
| 3127 | sky2_write32(hw, B0_IMSK, hw->intr_mask); | ||
| 3128 | |||
| 3129 | pci_set_drvdata(pdev, hw); | ||
| 3130 | |||
| 3131 | return 0; | ||
| 3132 | |||
| 3133 | err_out_unregister: | ||
| 3134 | if (dev1) { | ||
| 3135 | unregister_netdev(dev1); | ||
| 3136 | free_netdev(dev1); | ||
| 3137 | } | ||
| 3138 | unregister_netdev(dev); | ||
| 3139 | err_out_free_netdev: | ||
| 3140 | free_netdev(dev); | ||
| 3141 | err_out_free_pci: | ||
| 3142 | sky2_write8(hw, B0_CTST, CS_RST_SET); | ||
| 3143 | pci_free_consistent(hw->pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma); | ||
| 3144 | err_out_iounmap: | ||
| 3145 | iounmap(hw->regs); | ||
| 3146 | err_out_free_hw: | ||
| 3147 | kfree(hw); | ||
| 3148 | err_out_free_regions: | ||
| 3149 | pci_release_regions(pdev); | ||
| 3150 | pci_disable_device(pdev); | ||
| 3151 | err_out: | ||
| 3152 | return err; | ||
| 3153 | } | ||
| 3154 | |||
| 3155 | static void __devexit sky2_remove(struct pci_dev *pdev) | ||
| 3156 | { | ||
| 3157 | struct sky2_hw *hw = pci_get_drvdata(pdev); | ||
| 3158 | struct net_device *dev0, *dev1; | ||
| 3159 | |||
| 3160 | if (!hw) | ||
| 3161 | return; | ||
| 3162 | |||
| 3163 | dev0 = hw->dev[0]; | ||
| 3164 | dev1 = hw->dev[1]; | ||
| 3165 | if (dev1) | ||
| 3166 | unregister_netdev(dev1); | ||
| 3167 | unregister_netdev(dev0); | ||
| 3168 | |||
| 3169 | sky2_write32(hw, B0_IMSK, 0); | ||
| 3170 | sky2_set_power_state(hw, PCI_D3hot); | ||
| 3171 | sky2_write16(hw, B0_Y2LED, LED_STAT_OFF); | ||
| 3172 | sky2_write8(hw, B0_CTST, CS_RST_SET); | ||
| 3173 | sky2_read8(hw, B0_CTST); | ||
| 3174 | |||
| 3175 | free_irq(pdev->irq, hw); | ||
| 3176 | pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma); | ||
| 3177 | pci_release_regions(pdev); | ||
| 3178 | pci_disable_device(pdev); | ||
| 3179 | |||
| 3180 | if (dev1) | ||
| 3181 | free_netdev(dev1); | ||
| 3182 | free_netdev(dev0); | ||
| 3183 | iounmap(hw->regs); | ||
| 3184 | kfree(hw); | ||
| 3185 | |||
| 3186 | pci_set_drvdata(pdev, NULL); | ||
| 3187 | } | ||
| 3188 | |||
| 3189 | #ifdef CONFIG_PM | ||
| 3190 | static int sky2_suspend(struct pci_dev *pdev, pm_message_t state) | ||
| 3191 | { | ||
| 3192 | struct sky2_hw *hw = pci_get_drvdata(pdev); | ||
| 3193 | int i; | ||
| 3194 | |||
| 3195 | for (i = 0; i < 2; i++) { | ||
| 3196 | struct net_device *dev = hw->dev[i]; | ||
| 3197 | |||
| 3198 | if (dev) { | ||
| 3199 | if (!netif_running(dev)) | ||
| 3200 | continue; | ||
| 3201 | |||
| 3202 | sky2_down(dev); | ||
| 3203 | netif_device_detach(dev); | ||
| 3204 | } | ||
| 3205 | } | ||
| 3206 | |||
| 3207 | return sky2_set_power_state(hw, pci_choose_state(pdev, state)); | ||
| 3208 | } | ||
| 3209 | |||
| 3210 | static int sky2_resume(struct pci_dev *pdev) | ||
| 3211 | { | ||
| 3212 | struct sky2_hw *hw = pci_get_drvdata(pdev); | ||
| 3213 | int i; | ||
| 3214 | |||
| 3215 | pci_restore_state(pdev); | ||
| 3216 | pci_enable_wake(pdev, PCI_D0, 0); | ||
| 3217 | sky2_set_power_state(hw, PCI_D0); | ||
| 3218 | |||
| 3219 | sky2_reset(hw); | ||
| 3220 | |||
| 3221 | for (i = 0; i < 2; i++) { | ||
| 3222 | struct net_device *dev = hw->dev[i]; | ||
| 3223 | if (dev) { | ||
| 3224 | if (netif_running(dev)) { | ||
| 3225 | netif_device_attach(dev); | ||
| 3226 | if (sky2_up(dev)) | ||
| 3227 | dev_close(dev); | ||
| 3228 | } | ||
| 3229 | } | ||
| 3230 | } | ||
| 3231 | return 0; | ||
| 3232 | } | ||
| 3233 | #endif | ||
| 3234 | |||
| 3235 | static struct pci_driver sky2_driver = { | ||
| 3236 | .name = DRV_NAME, | ||
| 3237 | .id_table = sky2_id_table, | ||
| 3238 | .probe = sky2_probe, | ||
| 3239 | .remove = __devexit_p(sky2_remove), | ||
| 3240 | #ifdef CONFIG_PM | ||
| 3241 | .suspend = sky2_suspend, | ||
| 3242 | .resume = sky2_resume, | ||
| 3243 | #endif | ||
| 3244 | }; | ||
| 3245 | |||
| 3246 | static int __init sky2_init_module(void) | ||
| 3247 | { | ||
| 3248 | return pci_register_driver(&sky2_driver); | ||
| 3249 | } | ||
| 3250 | |||
| 3251 | static void __exit sky2_cleanup_module(void) | ||
| 3252 | { | ||
| 3253 | pci_unregister_driver(&sky2_driver); | ||
| 3254 | } | ||
| 3255 | |||
| 3256 | module_init(sky2_init_module); | ||
| 3257 | module_exit(sky2_cleanup_module); | ||
| 3258 | |||
| 3259 | MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver"); | ||
| 3260 | MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); | ||
| 3261 | MODULE_LICENSE("GPL"); | ||
| 3262 | MODULE_VERSION(DRV_VERSION); | ||
