c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * CDDL HEADER START
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * The contents of this file are subject to the terms of the
ba2e4443695ee6a6f420a35cd4fc3d3346d22932seb * Common Development and Distribution License (the "License").
ba2e4443695ee6a6f420a35cd4fc3d3346d22932seb * You may not use this file except in compliance with the License.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * See the License for the specific language governing permissions
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * and limitations under the License.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * When distributing Covered Code, include this CDDL HEADER in each
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * If applicable, add the following below this CDDL HEADER, with the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * fields enclosed by brackets "[]" replaced with your own identifying
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * information: Portions Copyright [yyyy] [name of copyright owner]
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * CDDL HEADER END
4bb4f326b9248e14f38bc18d91e54b7c70223f64Li-Zhen You * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Use is subject to license terms.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#define REG32(rgep, reg) ((uint32_t *)(rgep->io_regs+(reg)))
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#define REG16(rgep, reg) ((uint16_t *)(rgep->io_regs+(reg)))
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#define REG8(rgep, reg) ((uint8_t *)(rgep->io_regs+(reg)))
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#define PIO_ADDR(rgep, offset) ((void *)(rgep->io_regs+(offset)))
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Patchable globals:
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * rge_autorecover
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Enables/disables automatic recovery after fault detection
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * globals:
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#define RGE_DBG RGE_DBG_REGS /* debug flag for this code */
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing Chinastatic uint32_t rge_rx_watchdog_count = 1 << 3;
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Operating register get/set access routines
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic uint32_t rge_reg_get32(rge_t *rgep, uintptr_t regno);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_reg_get32)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_reg_put32(rge_t *rgep, uintptr_t regno, uint32_t data);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_reg_put32)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsrge_reg_put32(rge_t *rgep, uintptr_t regno, uint32_t data)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_reg_set32(rge_t *rgep, uintptr_t regno, uint32_t bits);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_reg_set32)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsrge_reg_set32(rge_t *rgep, uintptr_t regno, uint32_t bits)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_reg_clr32(rge_t *rgep, uintptr_t regno, uint32_t bits);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_reg_clr32)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsrge_reg_clr32(rge_t *rgep, uintptr_t regno, uint32_t bits)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic uint16_t rge_reg_get16(rge_t *rgep, uintptr_t regno);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_reg_get16)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_reg_put16(rge_t *rgep, uintptr_t regno, uint16_t data);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_reg_put16)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsrge_reg_put16(rge_t *rgep, uintptr_t regno, uint16_t data)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic uint8_t rge_reg_get8(rge_t *rgep, uintptr_t regno);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_reg_get8)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_reg_put8(rge_t *rgep, uintptr_t regno, uint8_t data);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_reg_put8)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_reg_set8(rge_t *rgep, uintptr_t regno, uint8_t bits);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_reg_set8)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_reg_clr8(rge_t *rgep, uintptr_t regno, uint8_t bits);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_reg_clr8)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Waiting for PHY reading OK
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs for (i = 0; i < PHY_RESET_LOOP; i++) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs RGE_REPORT((rgep, "rge_mii_get16(0x%x) fail, val = %x", mii, val32));
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs return ((uint16_t)~0u);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsvoid rge_mii_put16(rge_t *rgep, uintptr_t mii, uint16_t data);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Waiting for PHY writing OK
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs for (i = 0; i < PHY_RESET_LOOP; i++) {
aa81749390e332985277568edab1ee6132326b42gsvoid rge_ephy_put16(rge_t *rgep, uintptr_t emii, uint16_t data);
aa81749390e332985277568edab1ee6132326b42gsrge_ephy_put16(rge_t *rgep, uintptr_t emii, uint16_t data)
aa81749390e332985277568edab1ee6132326b42gs * Waiting for PHY writing OK
aa81749390e332985277568edab1ee6132326b42gs for (i = 0; i < PHY_RESET_LOOP; i++) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Atomically shift a 32-bit word left, returning
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * the value it had *before* the shift was applied
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic uint32_t rge_atomic_shl32(uint32_t *sp, uint_t count);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_mii_put16)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* ATOMICALLY */
75d94465dbafa487b716482dc36d5150a4ec9853Josef 'Jeff' Sipek } while (atomic_cas_32(sp, oldval, newval) != oldval);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * PHY operation routines
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs for (i = 0; i < 32; ++i) {
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "0x%04x %04x %04x %04x %04x %04x %04x %04x",
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#endif /* RGE_DEBUGGING */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * RTL8169S/8110S PHY has the "PCS bug". Need reset PHY
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * every 15 seconds whin link down & advertise is 1000.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Basic low-level function to reset the PHY.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Doesn't incorporate any special-case workarounds.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Returns TRUE on success, FALSE if the RESET bit doesn't clear
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Set the PHY RESET bit, then wait up to 5 ms for it to self-clear
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs rge_mii_put16(rgep, MII_CONTROL, control | MII_CONTROL_RESET);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs RGE_REPORT((rgep, "rge_phy_reset: FAILED, control now 0x%x", control));
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Synchronise the PHY's speed/duplex/autonegotiation capabilities
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * and advertisements with the required settings as specified by the various
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * param_* variables that can be poked via the NDD interface.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * We always reset the PHY and reprogram *all* the relevant registers,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * not just those changed. This should cause the link to go down, and then
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * back up again once the link is stable and autonegotiation (if enabled)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * is complete. We should get a link state change interrupt somewhere along
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * the way ...
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * NOTE: <genlock> must already be held by the caller
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "pause %d asym_pause %d "
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "1000fdx %d 1000hdx %d "
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "100fdx %d 100hdx %d "
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "10fdx %d 10hdx %d ",
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * PHY settings are normally based on the param_* variables,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * but if any loopback mode is in effect, that takes precedence.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * RGE supports MAC-internal loopback, PHY-internal loopback,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * and External loopback at a variety of speeds (with a special
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * cable). In all cases, autoneg is turned OFF, full-duplex
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * is turned ON, and the speed/mastership is forced.
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "pause %d asym_pause %d "
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "1000fdx %d 1000hdx %d "
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "100fdx %d 100hdx %d "
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx "10fdx %d 10hdx %d ",
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * We should have at least one technology capability set;
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * if not, we select a default of 1000Mb/s full-duplex
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Now transform the adv_* variables into the proper settings
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * of the PHY registers ...
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * If autonegotiation is (now) enabled, we want to trigger
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * a new autonegotiation cycle once the PHY has been
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * programmed with the capabilities to be advertised.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * RTL8169/8110 doesn't support 1000Mb/s half-duplex.
bdb9230ac765cb7af3fc1f4119caf2c5720dceb3Garrett D'Amore control |= MII_CONTROL_1GB|MII_CONTROL_FDUPLEX;
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Chipset limitation: need set other capabilities to true
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Munge in any other fixed bits we require ...
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Restart the PHY and write the new values. Note the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * time, so that we can say whether subsequent link state
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * changes can be attributed to our reprogramming the PHY
7f58d67b25a99a419dffb16c0ec6fb0537568c24gs /* power up PHY for RTL8168B chipset */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Below phy config steps are copied from the Programming Guide
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * (there's no detail comments for these steps.)
aa81749390e332985277568edab1ee6132326b42gs * Read and record MAC version
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China chip->is_pcie = pci_lcap_locate(rgep->cfg_handle,
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China PCI_CAP_ID_PCI_E, &val16) == DDI_SUCCESS;
5ca61e50c68a7a60dc35cd76831471faa4974d71Li-Zhen You * Workaround for 8101E_C
aa81749390e332985277568edab1ee6132326b42gs * Read and record PHY version
aa81749390e332985277568edab1ee6132326b42gs /* set pci latency timer */
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China chip->mac_ver == MAC_VER_8169S_E ||
aa81749390e332985277568edab1ee6132326b42gs pci_config_put8(rgep->cfg_handle, PCI_CONF_LATENCY_TIMER, 0x40);
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China rge_reg_put32(rgep, 0x7c, 0x000700ff);
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China rge_reg_put32(rgep, 0x7c, 0x0007ff00);
aa81749390e332985277568edab1ee6132326b42gs * PCIE chipset require the Rx buffer start address must be
aa81749390e332985277568edab1ee6132326b42gs * 8-byte alignment and the Rx buffer size must be multiple of 8.
aa81749390e332985277568edab1ee6132326b42gs * We'll just use bcopy in receive procedure for the PCIE chipset.
aa81749390e332985277568edab1ee6132326b42gs "for this PCIE chipset");
aa81749390e332985277568edab1ee6132326b42gs * Initialize other variables.
aa81749390e332985277568edab1ee6132326b42gs if (rgep->default_mtu < ETHERMTU || rgep->default_mtu > RGE_JUMBO_MTU)
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China /* interval to update statistics for polling mode */
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->tick_delta = drv_usectohz(1000*1000/CLK_TICK);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China /* ensure we are not in polling mode */
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->curr_tick = ddi_get_lbolt() - 2*rgep->tick_delta;
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Perform first-stage chip (re-)initialisation, using only config-space
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * accesses:
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * + Read the vendor/device/revision/subsystem/cache-line-size registers,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * returning the data in the structure pointed to by <idp>.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * + Enable Memory Space accesses.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * + Enable Bus Mastering according.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Save PCI cache line size and subsystem vendor ID
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs cidp->subven = pci_config_get16(handle, PCI_CONF_SUBVENID);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs cidp->subdev = pci_config_get16(handle, PCI_CONF_SUBSYSID);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs cidp->revision = pci_config_get8(handle, PCI_CONF_REVID);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs cidp->clsize = pci_config_get8(handle, PCI_CONF_CACHE_LINESZ);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs cidp->latency = pci_config_get8(handle, PCI_CONF_LATENCY_TIMER);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Turn on Master Enable (DMA) and IO Enable bits.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Enable PCI Memory Space accesses
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs RGE_DEBUG(("rge_chip_cfg_init: vendor 0x%x device 0x%x revision 0x%x",
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs RGE_DEBUG(("rge_chip_cfg_init: clsize %d latency %d command 0x%x",
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Chip should be in STOP state
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Disable interrupt
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Clear pended interrupt
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Reset chip
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Wait for reset success
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs for (i = 0; i < CHIP_RESET_LOOP; i++) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs return (0);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs return (-1);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China * Increase the threshold voltage of RX sensitivity
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (chip->mac_ver == MAC_VER_8168B_B ||
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China chip->mac_ver == MAC_VER_8168B_C ||
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_ephy_put16(rgep, 0x01, 0x1bd3);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (chip->mac_ver == MAC_VER_8168 ||
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China chip->mac_ver == MAC_VER_8168B_B) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_reg_put16(rgep, PHY_STATUS_REG, val16);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_reg_put32(rgep, RT_CSI_DATA_REG, 0x00021c01);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_reg_put32(rgep, RT_CSI_ACCESS_REG, 0x8000f088);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_reg_put32(rgep, RT_CSI_DATA_REG, 0x00004000);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_reg_put32(rgep, RT_CSI_ACCESS_REG, 0x8000f0b0);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_reg_put32(rgep, RT_CSI_ACCESS_REG, 0x0000f068);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China val32 = rge_reg_get32(rgep, RT_CSI_DATA_REG);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China val32 |= 0x7000;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China val32 &= 0xffff5fff;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_reg_put32(rgep, RT_CSI_DATA_REG, val32);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_reg_put32(rgep, RT_CSI_ACCESS_REG, 0x8000f068);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Config MII register
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Enable Rx checksum offload.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Then for vlan support, we must enable receive vlan de-tagging.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Otherwise, there'll be checksum error.
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China if (chip->mac_ver == MAC_VER_8169S_E ||
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China chip->mac_ver == MAC_VER_8169SC) {
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China val16 |= MUL_PCI_RW_ENABLE;
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Start transmit/receive before set tx/rx configuration register
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Set dump tally counter register
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Change to config register write enable mode
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs rge_reg_set8(rgep, RT_93c46_COMMOND_REG, RT_93c46_MODE_CONFIG);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Set Tx/Rx maximum packet size
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs rge_reg_put8(rgep, TX_MAX_PKTSIZE_REG, TX_PKTSIZE_JUMBO);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs rge_reg_put16(rgep, RX_MAX_PKTSIZE_REG, RX_PKTSIZE_JUMBO);
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx rge_reg_put8(rgep, TX_MAX_PKTSIZE_REG, TX_PKTSIZE_STD_8101E);
dfc2d53e07384b9eaca5466a2328c88a1ed96f32mx rge_reg_put16(rgep, RX_MAX_PKTSIZE_REG, RX_PKTSIZE_STD_8101E);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Set receive configuration register
aa81749390e332985277568edab1ee6132326b42gs rge_reg_put32(rgep, RX_CONFIG_REG, val32 | chip->rxconfig);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Set transmit configuration register
aa81749390e332985277568edab1ee6132326b42gs rge_reg_put32(rgep, TX_CONFIG_REG, val32 | chip->txconfig);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Set Tx/Rx descriptor register
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Suggested setting from Realtek
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Set multicast register
5927ab2b3c9b313d37a3417c6a5571fdf191b693KHF rge_reg_put32(rgep, MULTICAST_0_REG, RGE_BSWAP_32(hashp[0]));
5927ab2b3c9b313d37a3417c6a5571fdf191b693KHF rge_reg_put32(rgep, MULTICAST_4_REG, RGE_BSWAP_32(hashp[1]));
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Msic register setting:
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * -- Missed packet counter: clear it
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * -- TimerInt Register
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * -- Timer count register
368a5ef88e8811b10e03b912242c0faef12ce713Miles Xu, Sun Microsystems * disable the Unicast Wakeup Frame capability
368a5ef88e8811b10e03b912242c0faef12ce713Miles Xu, Sun Microsystems rge_reg_clr8(rgep, RT_CONFIG_5_REG, RT_UNI_WAKE_FRAME);
526431940871c58531fcb8622ff47caaac00f6aegs * Return to normal network/host communication mode
526431940871c58531fcb8622ff47caaac00f6aegs rge_reg_clr8(rgep, RT_93c46_COMMOND_REG, RT_93c46_MODE_CONFIG);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * rge_chip_start() -- start the chip transmitting and/or receiving,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * including enabling interrupts
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Clear statistics
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Enable interrupt
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (rgep->chipid.is_pcie) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->int_mask |= NO_TXDESC_INT;
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China rgep->rx_fifo_ovf = 0;
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China rgep->int_mask |= RX_FIFO_OVERFLOW_INT;
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * All done!
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * rge_chip_stop() -- stop board receiving
193974072f41a843678abf5f61979c748687e66bSherry Moore * Since this function is also invoked by rge_quiesce(), it
193974072f41a843678abf5f61979c748687e66bSherry Moore * must not block; also, no tracing or logging takes place
193974072f41a843678abf5f61979c748687e66bSherry Moore * when invoked by rge_quiesce().
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Disable interrupt
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Clear pended interrupt
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Stop the board and disable transmit/receive
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * rge_get_mac_addr() -- get the MAC address on NIC
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_get_mac_addr)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Read first 4-byte of mac address
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Read last 2-byte of mac address
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_set_mac_addr)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Change to config register write enable mode
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs rge_reg_set8(rgep, RT_93c46_COMMOND_REG, RT_93c46_MODE_CONFIG);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Get first 4 bytes of mac address
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Set first 4 bytes of mac address
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Get last 2 bytes of mac address
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Set last 2 bytes of mac address
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Return to normal network/host communication mode
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs rge_reg_clr8(rgep, RT_93c46_COMMOND_REG, RT_93c46_MODE_CONFIG);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_set_multi_addr)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
526431940871c58531fcb8622ff47caaac00f6aegs * Change to config register write enable mode
368a5ef88e8811b10e03b912242c0faef12ce713Miles Xu, Sun Microsystems if (rgep->chipid.mac_ver == MAC_VER_8169SC) {
526431940871c58531fcb8622ff47caaac00f6aegs rge_reg_set8(rgep, RT_93c46_COMMOND_REG, RT_93c46_MODE_CONFIG);
5927ab2b3c9b313d37a3417c6a5571fdf191b693KHF rge_reg_put32(rgep, MULTICAST_0_REG, RGE_BSWAP_32(hashp[0]));
5927ab2b3c9b313d37a3417c6a5571fdf191b693KHF rge_reg_put32(rgep, MULTICAST_4_REG, RGE_BSWAP_32(hashp[1]));
526431940871c58531fcb8622ff47caaac00f6aegs * Return to normal network/host communication mode
368a5ef88e8811b10e03b912242c0faef12ce713Miles Xu, Sun Microsystems if (rgep->chipid.mac_ver == MAC_VER_8169SC) {
526431940871c58531fcb8622ff47caaac00f6aegs rge_reg_clr8(rgep, RT_93c46_COMMOND_REG, RT_93c46_MODE_CONFIG);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_set_promisc)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * rge_chip_sync() -- program the chip with the unicast MAC address,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * the multicast hash table, the required level of promiscuity, and
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * the current loopback mode ...
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs switch (todo) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* Reprogram the unicast MAC address(es) ... */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* Reprogram the hashed multicast address table ... */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* Set or clear the PROMISCUOUS mode bit */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengvoid rge_chip_blank(void *arg, time_t ticks, uint_t count, int flag);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/* ARGSUSED */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengrge_chip_blank(void *arg, time_t ticks, uint_t count, int flag)
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_reg_put8(rgep, TX_RINGS_POLL_REG, NORMAL_TX_RING_POLL);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs int i = 0;
4bb4f326b9248e14f38bc18d91e54b7c70223f64Li-Zhen You regval = rge_reg_get32(rgep, DUMP_COUNTER_REG_0);
4bb4f326b9248e14f38bc18d91e54b7c70223f64Li-Zhen You regval = rge_reg_get32(rgep, DUMP_COUNTER_REG_0);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Start H/W statistics dump for RTL8169 chip
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * ========== Hardware interrupt handler ==========
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#define RGE_DBG RGE_DBG_INT /* debug flag for this code */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#pragma inline(rge_wake_factotum)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
aa81749390e332985277568edab1ee6132326b42gs (void) ddi_intr_trigger_softint(rgep->factotum_hdl, NULL);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * rge_intr() -- handle chip interrupts
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China uint32_t tx_pkts;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China uint32_t rx_pkts;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China uint32_t poll_rate;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China uint32_t opt_pkts;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China uint32_t opt_intrs;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China boolean_t update_int_mask = B_FALSE;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China uint32_t itimer;
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Was this interrupt caused by our device...
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* indicate it wasn't our interrupt */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Clear interrupt
aa81749390e332985277568edab1ee6132326b42gs * For PCIE chipset, we need disable interrupt first.
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (rgep->chipid.is_pcie) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China update_int_mask = B_TRUE;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China * Calculate optimal polling interval
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China now = ddi_get_lbolt();
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (now - rgep->curr_tick >= rgep->tick_delta &&
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China (rgep->param_link_speed == RGE_SPEED_1000M ||
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->param_link_speed == RGE_SPEED_100M)) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China /* number of rx and tx packets in the last tick */
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China tx_pkts = rgep->stats.opackets - rgep->last_opackets;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rx_pkts = rgep->stats.rpackets - rgep->last_rpackets;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->last_opackets = rgep->stats.opackets;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->last_rpackets = rgep->stats.rpackets;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China /* restore interrupt mask */
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->int_mask |= TX_OK_INT | RX_OK_INT;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (rgep->chipid.is_pcie) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->int_mask |= NO_TXDESC_INT;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China /* optimal number of packets in a tick */
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (rgep->param_link_speed == RGE_SPEED_1000M) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China opt_pkts = (1000*1000*1000/8)/ETHERMTU/CLK_TICK;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China opt_pkts = (100*1000*1000/8)/ETHERMTU/CLK_TICK;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China * calculate polling interval based on rx and tx packets
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China * in the last tick
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China poll_rate = 0;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (now - rgep->curr_tick < 2*rgep->tick_delta) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China opt_intrs = opt_pkts/TX_COALESC;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (tx_pkts > opt_intrs) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China poll_rate = max(tx_pkts/TX_COALESC, opt_intrs);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->int_mask &= ~(TX_OK_INT | NO_TXDESC_INT);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China opt_intrs = opt_pkts/RX_COALESC;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (rx_pkts > opt_intrs) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China opt_intrs = max(rx_pkts/RX_COALESC, opt_intrs);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China poll_rate = max(opt_intrs, poll_rate);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->int_mask &= ~RX_OK_INT;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China /* ensure poll_rate reasonable */
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China poll_rate = min(poll_rate, opt_pkts*4);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (poll_rate) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China /* move to polling mode */
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (rgep->chipid.is_pcie) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China itimer = (TIMER_CLK_PCIE/CLK_TICK)/poll_rate;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China itimer = (TIMER_CLK_PCI/CLK_TICK)/poll_rate;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China /* move to normal mode */
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China RGE_DEBUG(("%s: poll: itimer:%d int_mask:0x%x",
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China __func__, itimer, rgep->int_mask));
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_reg_put32(rgep, TIMER_INT_REG, itimer);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China /* update timestamp for statistics */
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->curr_tick = now;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China /* reset timer */
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China int_status |= TIME_OUT_INT;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China update_int_mask = B_TRUE;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (int_status & TIME_OUT_INT) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rge_reg_put32(rgep, TIMER_COUNT_REG, 0);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China /* flush post writes */
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China (void) rge_reg_get16(rgep, INT_STATUS_REG);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Cable link change interrupt
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China if (int_status & RX_FIFO_OVERFLOW_INT) {
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China /* start rx watchdog timeout detection */
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China rgep->rx_fifo_ovf = 1;
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China if (rgep->int_mask & RX_FIFO_OVERFLOW_INT) {
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China rgep->int_mask &= ~RX_FIFO_OVERFLOW_INT;
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China update_int_mask = B_TRUE;
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China } else if (int_status & RGE_RX_INT) {
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China /* stop rx watchdog timeout detection */
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China rgep->rx_fifo_ovf = 0;
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China if ((rgep->int_mask & RX_FIFO_OVERFLOW_INT) == 0) {
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China rgep->int_mask |= RX_FIFO_OVERFLOW_INT;
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China update_int_mask = B_TRUE;
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Receive interrupt
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China * Transmit interrupt
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (int_status & TX_ERR_INT) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China RGE_REPORT((rgep, "tx error happened, resetting the chip "));
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China mutex_enter(rgep->genlock);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China rgep->rge_chip_state = RGE_CHIP_ERROR;
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China mutex_exit(rgep->genlock);
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China } else if ((rgep->chipid.is_pcie && (int_status & NO_TXDESC_INT)) ||
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China ((int_status & TX_OK_INT) && rgep->tx_free < RGE_SEND_SLOTS/8)) {
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China (void) ddi_intr_trigger_softint(rgep->resched_hdl, NULL);
9e1a9180bec2232328687ae8e96007921a6ed05dLi-Zhen You * System error interrupt
9e1a9180bec2232328687ae8e96007921a6ed05dLi-Zhen You RGE_REPORT((rgep, "sys error happened, resetting the chip "));
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China * Re-enable interrupt for PCIE chipset or install new int_mask
3a84c50f71e0942a55e90913f6b44878d5062621Winson Wang - Sun Microsystems - Beijing China if (update_int_mask)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs return (DDI_INTR_CLAIMED); /* indicate it was our interrupt */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * ========== Factotum, implemented as a softint handler ==========
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#define RGE_DBG RGE_DBG_FACT /* debug flag for this code */
0d2a8e5eea8ac6ea0f5c517f0c481329b57d5459gd * Link change.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Factotum routine to check for Tx stall, using the 'watchdog' counter
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China * Specific check for RX stall ...
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China rgep->rx_fifo_ovf <<= 1;
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China if (rgep->rx_fifo_ovf > rge_rx_watchdog_count) {
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China RGE_REPORT((rgep, "rx_hang detected"));
7b114c4b72aa312e481641f6d76a0f0194877786Winson Wang - Sun Microsystems - Beijing China return (B_TRUE);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Specific check for Tx stall ...
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * The 'watchdog' counter is incremented whenever a packet
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * is queued, reset to 1 when some (but not all) buffers
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * are reclaimed, reset to 0 (disabled) when all buffers
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * are reclaimed, and shifted left here. If it exceeds the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * threshold value, the chip is assumed to have stalled and
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * is put into the ERROR state. The factotum will then reset
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * it on the next pass.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * All of which should ensure that we don't get into a state
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * where packets are left pending indefinitely!
aa81749390e332985277568edab1ee6132326b42gs (void) ddi_intr_trigger_softint(rgep->resched_hdl, NULL);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs RGE_REPORT((rgep, "Tx stall detected, watchdog code 0x%x", dogval));
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * The factotum is woken up when there's something to do that we'd rather
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * not do from inside a hardware interrupt handler or high-level cyclic.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Its two main tasks are:
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * reset & restart the chip after an error
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * check the link status whenever necessary
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Fault detected, time to reset ...
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * If an error is detected, stop the chip now, marking it as
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * faulty, so that it will be reset next time through ...
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * If the link state changed, tell the world about it.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Note: can't do this while still holding the mutex.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * High-level cyclic handler
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * This routine schedules a (low-level) softint callback to the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * factotum, and prods the chip to update the status block (which
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * will cause a hardware interrupt when complete).
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * ========== Ioctl subfunctions ==========
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#define RGE_DBG RGE_DBG_PPIO /* debug flag for this code */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_chip_peek_cfg(rge_t *rgep, rge_peekpoke_t *ppd);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_chip_poke_cfg(rge_t *rgep, rge_peekpoke_t *ppd);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_chip_peek_reg(rge_t *rgep, rge_peekpoke_t *ppd);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_chip_poke_reg(rge_t *rgep, rge_peekpoke_t *ppd);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_chip_peek_mii(rge_t *rgep, rge_peekpoke_t *ppd);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs ppd->pp_acc_data = rge_mii_get16(rgep, ppd->pp_acc_offset/2);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_chip_poke_mii(rge_t *rgep, rge_peekpoke_t *ppd);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs rge_mii_put16(rgep, ppd->pp_acc_offset/2, ppd->pp_acc_data);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_chip_peek_mem(rge_t *rgep, rge_peekpoke_t *ppd);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs RGE_DEBUG(("rge_chip_peek_mem($%p, $%p) peeked 0x%llx from $%p",
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void rge_chip_poke_mem(rge_t *rgep, rge_peekpoke_t *ppd);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic void
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs RGE_DEBUG(("rge_chip_poke_mem($%p, $%p) poking 0x%llx at $%p",
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic enum ioc_reply rge_pp_ioctl(rge_t *rgep, int cmd, mblk_t *mp,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsrge_pp_ioctl(rge_t *rgep, int cmd, mblk_t *mp, struct iocblk *iocp)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs switch (cmd) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* NOTREACHED */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Validate format of ioctl
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Validate request parameters
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Config space
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Memory-mapped I/O space
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * PHY's MII registers
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * NB: all PHY registers are two bytes, but the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * addresses increment in ones (word addressing).
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * So we scale the address here, then undo the
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * transformation inside the peek/poke functions.
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * RGE data structure!
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Various DMA_AREAs
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * All OK - go do it!
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic enum ioc_reply rge_diag_ioctl(rge_t *rgep, int cmd, mblk_t *mp,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsrge_diag_ioctl(rge_t *rgep, int cmd, mblk_t *mp, struct iocblk *iocp)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs switch (cmd) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* NOTREACHED */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs rge_error(rgep, "rge_diag_ioctl: invalid cmd 0x%x", cmd);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Currently a no-op
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Reset and reinitialise the 570x hardware
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* NOTREACHED */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#endif /* RGE_DEBUGGING || RGE_DO_PPIO */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsstatic enum ioc_reply rge_mii_ioctl(rge_t *rgep, int cmd, mblk_t *mp,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsrge_mii_ioctl(rge_t *rgep, int cmd, mblk_t *mp, struct iocblk *iocp)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Validate format of ioctl
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs * Validate request parameters ...
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs switch (cmd) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* NOTREACHED */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* NOTREACHED */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsenum ioc_reply rge_chip_ioctl(rge_t *rgep, queue_t *wq, mblk_t *mp,
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gsrge_chip_ioctl(rge_t *rgep, queue_t *wq, mblk_t *mp, struct iocblk *iocp)
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs switch (cmd) {
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* NOTREACHED */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs rge_error(rgep, "rge_chip_ioctl: invalid cmd 0x%x", cmd);
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs#endif /* RGE_DEBUGGING || RGE_DO_PPIO */
c7fd2ed091e4e4beb47e1da3a6197a2c38f29c02gs /* NOTREACHED */