diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2013-02-22 01:26:56 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2013-02-22 01:26:56 +0000 |
commit | c0f2d68756f5482cd2ec899848d6855afd9ada74 (patch) | |
tree | 3d3cc54f8a7b0d66e8b3d5a5ed0e914933764011 | |
parent | 28111057c651d1bc9e403860f892b391da90928c (diff) |
bring back 5718/5719/5720 support again. deraadt pointed out that
the problems i had on the xserve g5 are mostly likely specific to
that machine and im inclined to agree. we're going to see a lot
more machines with the new chips than people with xserve g5s.
this also includes fixes for ip checksum handling compared to the
code i put in before.
tested by various people again.
sthen@ and claudio@ have agreed to babysit this. they can back it
out if im not around.
ok deraadt@
-rw-r--r-- | sys/dev/pci/if_bge.c | 1012 | ||||
-rw-r--r-- | sys/dev/pci/if_bgereg.h | 148 |
2 files changed, 970 insertions, 190 deletions
diff --git a/sys/dev/pci/if_bge.c b/sys/dev/pci/if_bge.c index 8551cb08869..92005302c1c 100644 --- a/sys/dev/pci/if_bge.c +++ b/sys/dev/pci/if_bge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bge.c,v 1.318 2013/02/09 23:39:37 brad Exp $ */ +/* $OpenBSD: if_bge.c,v 1.319 2013/02/22 01:26:55 dlg Exp $ */ /* * Copyright (c) 2001 Wind River Systems @@ -138,6 +138,7 @@ struct cfdriver bge_cd = { }; void bge_txeof(struct bge_softc *); +void bge_rxcsum(struct bge_softc *, struct bge_rx_bd *, struct mbuf *); void bge_rxeof(struct bge_softc *); void bge_tick(void *); @@ -180,6 +181,7 @@ int bge_init_tx_ring(struct bge_softc *); void bge_chipinit(struct bge_softc *); int bge_blockinit(struct bge_softc *); +u_int32_t bge_dma_swap_options(struct bge_softc *); int bge_phy_addr(struct bge_softc *); u_int32_t bge_readmem_ind(struct bge_softc *, int); @@ -191,9 +193,23 @@ int bge_miibus_readreg(struct device *, int, int); void bge_miibus_writereg(struct device *, int, int, int); void bge_miibus_statchg(struct device *); +#define BGE_RESET_SHUTDOWN 0 +#define BGE_RESET_START 1 +#define BGE_RESET_SUSPEND 2 +void bge_sig_post_reset(struct bge_softc *, int); +void bge_sig_legacy(struct bge_softc *, int); +void bge_sig_pre_reset(struct bge_softc *, int); +void bge_stop_fw(struct bge_softc *, int); void bge_reset(struct bge_softc *); void bge_link_upd(struct bge_softc *); +void bge_ape_lock_init(struct bge_softc *); +void bge_ape_read_fw_ver(struct bge_softc *); +int bge_ape_lock(struct bge_softc *, int); +void bge_ape_unlock(struct bge_softc *, int); +void bge_ape_send_event(struct bge_softc *, uint32_t); +void bge_ape_driver_state_change(struct bge_softc *, int); + #ifdef BGE_DEBUG #define DPRINTF(x) do { if (bgedebug) printf x; } while (0) #define DPRINTFN(n,x) do { if (bgedebug >= (n)) printf x; } while (0) @@ -242,6 +258,8 @@ const struct pci_matchid bge_devices[] = { { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5715S }, { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5717 }, { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5718 }, + { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5719 }, + { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5720 }, { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5721 }, { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5722 }, { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM5723 }, @@ -421,9 +439,16 @@ u_int32_t bge_readmem_ind(struct bge_softc *sc, int off) { struct pci_attach_args *pa = &(sc->bge_pa); + u_int32_t val; + + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5906 && + off >= BGE_STATS_BLOCK && off < BGE_SEND_RING_1_TO_4) + return (0); pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_MEMWIN_BASEADDR, off); - return (pci_conf_read(pa->pa_pc, pa->pa_tag, BGE_PCI_MEMWIN_DATA)); + val = pci_conf_read(pa->pa_pc, pa->pa_tag, BGE_PCI_MEMWIN_DATA); + pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_MEMWIN_BASEADDR, 0); + return (val); } void @@ -431,8 +456,13 @@ bge_writemem_ind(struct bge_softc *sc, int off, int val) { struct pci_attach_args *pa = &(sc->bge_pa); + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5906 && + off >= BGE_STATS_BLOCK && off < BGE_SEND_RING_1_TO_4) + return; + pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_MEMWIN_BASEADDR, off); pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_MEMWIN_DATA, val); + pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_MEMWIN_BASEADDR, 0); } void @@ -453,6 +483,324 @@ bge_writembx(struct bge_softc *sc, int off, int val) CSR_WRITE_4(sc, off, val); } +/* + * Clear all stale locks and select the lock for this driver instance. + */ +void +bge_ape_lock_init(struct bge_softc *sc) +{ + struct pci_attach_args *pa = &(sc->bge_pa); + uint32_t bit, regbase; + int i; + + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5761) + regbase = BGE_APE_LOCK_GRANT; + else + regbase = BGE_APE_PER_LOCK_GRANT; + + /* Clear any stale locks. */ + for (i = BGE_APE_LOCK_PHY0; i <= BGE_APE_LOCK_GPIO; i++) { + switch (i) { + case BGE_APE_LOCK_PHY0: + case BGE_APE_LOCK_PHY1: + case BGE_APE_LOCK_PHY2: + case BGE_APE_LOCK_PHY3: + bit = BGE_APE_LOCK_GRANT_DRIVER0; + break; + default: + if (pa->pa_function != 0) + bit = BGE_APE_LOCK_GRANT_DRIVER0; + else + bit = (1 << pa->pa_function); + } + APE_WRITE_4(sc, regbase + 4 * i, bit); + } + + /* Select the PHY lock based on the device's function number. */ + switch (pa->pa_function) { + case 0: + sc->bge_phy_ape_lock = BGE_APE_LOCK_PHY0; + break; + case 1: + sc->bge_phy_ape_lock = BGE_APE_LOCK_PHY1; + break; + case 2: + sc->bge_phy_ape_lock = BGE_APE_LOCK_PHY2; + break; + case 3: + sc->bge_phy_ape_lock = BGE_APE_LOCK_PHY3; + break; + default: + printf("%s: PHY lock not supported on function %d\n", + sc->bge_dev.dv_xname); + break; + } +} + +/* + * Check for APE firmware, set flags, and print version info. + */ +void +bge_ape_read_fw_ver(struct bge_softc *sc) +{ + const char *fwtype; + uint32_t apedata, features; + + /* Check for a valid APE signature in shared memory. */ + apedata = APE_READ_4(sc, BGE_APE_SEG_SIG); + if (apedata != BGE_APE_SEG_SIG_MAGIC) { + sc->bge_mfw_flags &= ~ BGE_MFW_ON_APE; + return; + } + + /* Check if APE firmware is running. */ + apedata = APE_READ_4(sc, BGE_APE_FW_STATUS); + if ((apedata & BGE_APE_FW_STATUS_READY) == 0) { + printf("%s: APE signature found but FW status not ready! " + "0x%08x\n", sc->bge_dev.dv_xname, apedata); + return; + } + + sc->bge_mfw_flags |= BGE_MFW_ON_APE; + + /* Fetch the APE firwmare type and version. */ + apedata = APE_READ_4(sc, BGE_APE_FW_VERSION); + features = APE_READ_4(sc, BGE_APE_FW_FEATURES); + if ((features & BGE_APE_FW_FEATURE_NCSI) != 0) { + sc->bge_mfw_flags |= BGE_MFW_TYPE_NCSI; + fwtype = "NCSI"; + } else if ((features & BGE_APE_FW_FEATURE_DASH) != 0) { + sc->bge_mfw_flags |= BGE_MFW_TYPE_DASH; + fwtype = "DASH"; + } else + fwtype = "UNKN"; + + /* Print the APE firmware version. */ + printf(", APE firmware %s %d.%d.%d.%d", fwtype, + (apedata & BGE_APE_FW_VERSION_MAJMSK) >> BGE_APE_FW_VERSION_MAJSFT, + (apedata & BGE_APE_FW_VERSION_MINMSK) >> BGE_APE_FW_VERSION_MINSFT, + (apedata & BGE_APE_FW_VERSION_REVMSK) >> BGE_APE_FW_VERSION_REVSFT, + (apedata & BGE_APE_FW_VERSION_BLDMSK)); +} + +int +bge_ape_lock(struct bge_softc *sc, int locknum) +{ + struct pci_attach_args *pa = &(sc->bge_pa); + uint32_t bit, gnt, req, status; + int i, off; + + if ((sc->bge_mfw_flags & BGE_MFW_ON_APE) == 0) + return (0); + + /* Lock request/grant registers have different bases. */ + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5761) { + req = BGE_APE_LOCK_REQ; + gnt = BGE_APE_LOCK_GRANT; + } else { + req = BGE_APE_PER_LOCK_REQ; + gnt = BGE_APE_PER_LOCK_GRANT; + } + + off = 4 * locknum; + + switch (locknum) { + case BGE_APE_LOCK_GPIO: + /* Lock required when using GPIO. */ + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5761) + return (0); + if (pa->pa_function == 0) + bit = BGE_APE_LOCK_REQ_DRIVER0; + else + bit = (1 << pa->pa_function); + break; + case BGE_APE_LOCK_GRC: + /* Lock required to reset the device. */ + if (pa->pa_function == 0) + bit = BGE_APE_LOCK_REQ_DRIVER0; + else + bit = (1 << pa->pa_function); + break; + case BGE_APE_LOCK_MEM: + /* Lock required when accessing certain APE memory. */ + if (pa->pa_function == 0) + bit = BGE_APE_LOCK_REQ_DRIVER0; + else + bit = (1 << pa->pa_function); + break; + case BGE_APE_LOCK_PHY0: + case BGE_APE_LOCK_PHY1: + case BGE_APE_LOCK_PHY2: + case BGE_APE_LOCK_PHY3: + /* Lock required when accessing PHYs. */ + bit = BGE_APE_LOCK_REQ_DRIVER0; + break; + default: + return (EINVAL); + } + + /* Request a lock. */ + APE_WRITE_4(sc, req + off, bit); + + /* Wait up to 1 second to acquire lock. */ + for (i = 0; i < 20000; i++) { + status = APE_READ_4(sc, gnt + off); + if (status == bit) + break; + DELAY(50); + } + + /* Handle any errors. */ + if (status != bit) { + printf("%s: APE lock %d request failed! " + "request = 0x%04x[0x%04x], status = 0x%04x[0x%04x]\n", + sc->bge_dev.dv_xname, + locknum, req + off, bit & 0xFFFF, gnt + off, + status & 0xFFFF); + /* Revoke the lock request. */ + APE_WRITE_4(sc, gnt + off, bit); + return (EBUSY); + } + + return (0); +} + +void +bge_ape_unlock(struct bge_softc *sc, int locknum) +{ + struct pci_attach_args *pa = &(sc->bge_pa); + uint32_t bit, gnt; + int off; + + if ((sc->bge_mfw_flags & BGE_MFW_ON_APE) == 0) + return; + + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5761) + gnt = BGE_APE_LOCK_GRANT; + else + gnt = BGE_APE_PER_LOCK_GRANT; + + off = 4 * locknum; + + switch (locknum) { + case BGE_APE_LOCK_GPIO: + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5761) + return; + if (pa->pa_function == 0) + bit = BGE_APE_LOCK_GRANT_DRIVER0; + else + bit = (1 << pa->pa_function); + break; + case BGE_APE_LOCK_GRC: + if (pa->pa_function == 0) + bit = BGE_APE_LOCK_GRANT_DRIVER0; + else + bit = (1 << pa->pa_function); + break; + case BGE_APE_LOCK_MEM: + if (pa->pa_function == 0) + bit = BGE_APE_LOCK_GRANT_DRIVER0; + else + bit = (1 << pa->pa_function); + break; + case BGE_APE_LOCK_PHY0: + case BGE_APE_LOCK_PHY1: + case BGE_APE_LOCK_PHY2: + case BGE_APE_LOCK_PHY3: + bit = BGE_APE_LOCK_GRANT_DRIVER0; + break; + default: + return; + } + + APE_WRITE_4(sc, gnt + off, bit); +} + +/* + * Send an event to the APE firmware. + */ +void +bge_ape_send_event(struct bge_softc *sc, uint32_t event) +{ + uint32_t apedata; + int i; + + /* NCSI does not support APE events. */ + if ((sc->bge_mfw_flags & BGE_MFW_ON_APE) == 0) + return; + + /* Wait up to 1ms for APE to service previous event. */ + for (i = 10; i > 0; i--) { + if (bge_ape_lock(sc, BGE_APE_LOCK_MEM) != 0) + break; + apedata = APE_READ_4(sc, BGE_APE_EVENT_STATUS); + if ((apedata & BGE_APE_EVENT_STATUS_EVENT_PENDING) == 0) { + APE_WRITE_4(sc, BGE_APE_EVENT_STATUS, event | + BGE_APE_EVENT_STATUS_EVENT_PENDING); + bge_ape_unlock(sc, BGE_APE_LOCK_MEM); + APE_WRITE_4(sc, BGE_APE_EVENT, BGE_APE_EVENT_1); + break; + } + bge_ape_unlock(sc, BGE_APE_LOCK_MEM); + DELAY(100); + } + if (i == 0) { + printf("%s: APE event 0x%08x send timed out\n", + sc->bge_dev.dv_xname, event); + } +} + +void +bge_ape_driver_state_change(struct bge_softc *sc, int kind) +{ + uint32_t apedata, event; + + if ((sc->bge_mfw_flags & BGE_MFW_ON_APE) == 0) + return; + + switch (kind) { + case BGE_RESET_START: + /* If this is the first load, clear the load counter. */ + apedata = APE_READ_4(sc, BGE_APE_HOST_SEG_SIG); + if (apedata != BGE_APE_HOST_SEG_SIG_MAGIC) + APE_WRITE_4(sc, BGE_APE_HOST_INIT_COUNT, 0); + else { + apedata = APE_READ_4(sc, BGE_APE_HOST_INIT_COUNT); + APE_WRITE_4(sc, BGE_APE_HOST_INIT_COUNT, ++apedata); + } + APE_WRITE_4(sc, BGE_APE_HOST_SEG_SIG, + BGE_APE_HOST_SEG_SIG_MAGIC); + APE_WRITE_4(sc, BGE_APE_HOST_SEG_LEN, + BGE_APE_HOST_SEG_LEN_MAGIC); + + /* Add some version info if bge(4) supports it. */ + APE_WRITE_4(sc, BGE_APE_HOST_DRIVER_ID, + BGE_APE_HOST_DRIVER_ID_MAGIC(1, 0)); + APE_WRITE_4(sc, BGE_APE_HOST_BEHAVIOR, + BGE_APE_HOST_BEHAV_NO_PHYLOCK); + APE_WRITE_4(sc, BGE_APE_HOST_HEARTBEAT_INT_MS, + BGE_APE_HOST_HEARTBEAT_INT_DISABLE); + APE_WRITE_4(sc, BGE_APE_HOST_DRVR_STATE, + BGE_APE_HOST_DRVR_STATE_START); + event = BGE_APE_EVENT_STATUS_STATE_START; + break; + case BGE_RESET_SHUTDOWN: + APE_WRITE_4(sc, BGE_APE_HOST_DRVR_STATE, + BGE_APE_HOST_DRVR_STATE_UNLOAD); + event = BGE_APE_EVENT_STATUS_STATE_UNLOAD; + break; + case BGE_RESET_SUSPEND: + event = BGE_APE_EVENT_STATUS_STATE_SUSPEND; + break; + default: + return; + } + + bge_ape_send_event(sc, event | BGE_APE_EVENT_STATUS_DRIVER_EVNT | + BGE_APE_EVENT_STATUS_STATE_CHNGE); +} + + u_int8_t bge_nvram_getbyte(struct bge_softc *sc, int addr, u_int8_t *dest) { @@ -598,12 +946,15 @@ bge_miibus_readreg(struct device *dev, int phy, int reg) u_int32_t val, autopoll; int i; + if (bge_ape_lock(sc, sc->bge_phy_ape_lock) != 0) + return (0); + /* Reading with autopolling on may trigger PCI errors */ autopoll = CSR_READ_4(sc, BGE_MI_MODE); if (autopoll & BGE_MIMODE_AUTOPOLL) { BGE_STS_CLRBIT(sc, BGE_STS_AUTOPOLL); BGE_CLRBIT(sc, BGE_MI_MODE, BGE_MIMODE_AUTOPOLL); - DELAY(40); + DELAY(80); } CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_READ|BGE_MICOMM_BUSY| @@ -629,9 +980,11 @@ done: if (autopoll & BGE_MIMODE_AUTOPOLL) { BGE_STS_SETBIT(sc, BGE_STS_AUTOPOLL); BGE_SETBIT(sc, BGE_MI_MODE, BGE_MIMODE_AUTOPOLL); - DELAY(40); + DELAY(80); } + bge_ape_unlock(sc, sc->bge_phy_ape_lock); + if (val & BGE_MICOMM_READFAIL) return (0); @@ -645,13 +998,20 @@ bge_miibus_writereg(struct device *dev, int phy, int reg, int val) u_int32_t autopoll; int i; + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5906 && + (reg == BRGPHY_MII_1000CTL || reg == BRGPHY_MII_AUXCTL)) + return; + + if (bge_ape_lock(sc, sc->bge_phy_ape_lock) != 0) + return; + /* Reading with autopolling on may trigger PCI errors */ autopoll = CSR_READ_4(sc, BGE_MI_MODE); if (autopoll & BGE_MIMODE_AUTOPOLL) { DELAY(40); BGE_STS_CLRBIT(sc, BGE_STS_AUTOPOLL); BGE_CLRBIT(sc, BGE_MI_MODE, BGE_MIMODE_AUTOPOLL); - DELAY(10); /* 40 usec is supposed to be adequate */ + DELAY(40); /* 40 usec is supposed to be adequate */ } CSR_WRITE_4(sc, BGE_MI_COMM, BGE_MICMD_WRITE|BGE_MICOMM_BUSY| @@ -670,6 +1030,8 @@ bge_miibus_writereg(struct device *dev, int phy, int reg, int val) DELAY(40); } + bge_ape_unlock(sc, sc->bge_phy_ape_lock); + if (i == 200) { printf("%s: PHY read timed out\n", sc->bge_dev.dv_xname); } @@ -680,6 +1042,7 @@ bge_miibus_statchg(struct device *dev) { struct bge_softc *sc = (struct bge_softc *)dev; struct mii_data *mii = &sc->bge_mii; + u_int32_t mac_mode, rx_mode, tx_mode; /* * Get flow control negotiation result. @@ -690,30 +1053,33 @@ bge_miibus_statchg(struct device *dev) mii->mii_media_active &= ~IFM_ETH_FMASK; } - BGE_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_PORTMODE); + /* Set the port mode (MII/GMII) to match the link speed. */ + mac_mode = CSR_READ_4(sc, BGE_MAC_MODE) & + ~(BGE_MACMODE_PORTMODE | BGE_MACMODE_HALF_DUPLEX); + tx_mode = CSR_READ_4(sc, BGE_TX_MODE); + rx_mode = CSR_READ_4(sc, BGE_RX_MODE); + if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T || IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX) - BGE_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_GMII); - else - BGE_SETBIT(sc, BGE_MAC_MODE, BGE_PORTMODE_MII); - - if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) - BGE_CLRBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX); - else - BGE_SETBIT(sc, BGE_MAC_MODE, BGE_MACMODE_HALF_DUPLEX); - - /* - * 802.3x flow control - */ - if (sc->bge_flowflags & IFM_ETH_RXPAUSE) - BGE_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_FLOWCTL_ENABLE); + mac_mode |= BGE_PORTMODE_GMII; else - BGE_CLRBIT(sc, BGE_RX_MODE, BGE_RXMODE_FLOWCTL_ENABLE); + mac_mode |= BGE_PORTMODE_MII; + + /* Set MAC flow control behavior to match link flow control settings. */ + tx_mode &= ~BGE_TXMODE_FLOWCTL_ENABLE; + rx_mode &= ~BGE_RXMODE_FLOWCTL_ENABLE; + if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) { + if (sc->bge_flowflags & IFM_ETH_TXPAUSE) + tx_mode |= BGE_TXMODE_FLOWCTL_ENABLE; + if (sc->bge_flowflags & IFM_ETH_RXPAUSE) + rx_mode |= BGE_RXMODE_FLOWCTL_ENABLE; + } else + mac_mode |= BGE_MACMODE_HALF_DUPLEX; - if (sc->bge_flowflags & IFM_ETH_TXPAUSE) - BGE_SETBIT(sc, BGE_TX_MODE, BGE_TXMODE_FLOWCTL_ENABLE); - else - BGE_CLRBIT(sc, BGE_TX_MODE, BGE_TXMODE_FLOWCTL_ENABLE); + CSR_WRITE_4(sc, BGE_MAC_MODE, mac_mode); + DELAY(40); + CSR_WRITE_4(sc, BGE_TX_MODE, tx_mode); + CSR_WRITE_4(sc, BGE_RX_MODE, rx_mode); } /* @@ -1169,6 +1535,50 @@ bge_iff(struct bge_softc *sc) CSR_WRITE_4(sc, BGE_RX_MODE, rxmode); } +void +bge_sig_pre_reset(struct bge_softc *sc, int type) +{ + /* no bge_asf_mode. */ + + if (type == BGE_RESET_START || type == BGE_RESET_SUSPEND) + bge_ape_driver_state_change(sc, type); +} + +void +bge_sig_post_reset(struct bge_softc *sc, int type) +{ + /* no bge_asf_mode. */ + + if (type == BGE_RESET_SHUTDOWN) + bge_ape_driver_state_change(sc, type); +} + +void +bge_sig_legacy(struct bge_softc *sc, int type) +{ + /* no bge_asf_mode. */ +} + +void +bge_stop_fw(struct bge_softc *sc, int type) +{ + /* no bge_asf_mode. */ +} + +u_int32_t +bge_dma_swap_options(struct bge_softc *sc) +{ + u_int32_t dma_options = BGE_DMA_SWAP_OPTIONS; + + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5720) { + dma_options |= BGE_MODECTL_BYTESWAP_B2HRX_DATA | + BGE_MODECTL_WORDSWAP_B2HRX_DATA | BGE_MODECTL_B2HRX_ENABLE | + BGE_MODECTL_HTX2B_ENABLE; + } + + return (dma_options); +} + int bge_phy_addr(struct bge_softc *sc) { @@ -1199,16 +1609,13 @@ void bge_chipinit(struct bge_softc *sc) { struct pci_attach_args *pa = &(sc->bge_pa); - u_int32_t dma_rw_ctl; + u_int32_t dma_rw_ctl, mode_ctl; int i; /* Set endianness before we access any non-PCI registers. */ pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_MISC_CTL, BGE_INIT); - /* Clear the MAC control register */ - CSR_WRITE_4(sc, BGE_MAC_MODE, 0); - /* * Clear the MAC statistics block in the NIC's * internal memory. @@ -1279,19 +1686,41 @@ bge_chipinit(struct bge_softc *sc) BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5701) dma_rw_ctl |= BGE_PCIDMARWCTL_USE_MRM | BGE_PCIDMARWCTL_ASRT_ALL_BE; - + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5703 || BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5704) dma_rw_ctl &= ~BGE_PCIDMARWCTL_MINDMA; + if (BGE_IS_5717_PLUS(sc)) { + dma_rw_ctl &= ~BGE_PCIDMARWCTL_DIS_CACHE_ALIGNMENT; + if (sc->bge_chipid == BGE_CHIPID_BCM57765_A0) + dma_rw_ctl &= ~BGE_PCIDMARWCTL_CRDRDR_RDMA_MRRS_MSK; + + /* + * Enable HW workaround for controllers that misinterpret + * a status tag update and leave interrupts permanently + * disabled. + */ + if (BGE_ASICREV(sc->bge_chipid) != BGE_ASICREV_BCM5717 && + BGE_ASICREV(sc->bge_chipid) != BGE_ASICREV_BCM57765) + dma_rw_ctl |= BGE_PCIDMARWCTL_TAGGED_STATUS_WA; + } + pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_DMA_RW_CTL, dma_rw_ctl); /* * Set up general mode register. */ - CSR_WRITE_4(sc, BGE_MODE_CTL, BGE_DMA_SWAP_OPTIONS| - BGE_MODECTL_MAC_ATTN_INTR|BGE_MODECTL_HOST_SEND_BDS| - BGE_MODECTL_TX_NO_PHDR_CSUM); + mode_ctl = bge_dma_swap_options(sc); + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5720) { + /* Retain Host-2-BMC settings written by APE firmware. */ + mode_ctl |= CSR_READ_4(sc, BGE_MODE_CTL) & + (BGE_MODECTL_BYTESWAP_B2HRX_DATA | + BGE_MODECTL_WORDSWAP_B2HRX_DATA | + BGE_MODECTL_B2HRX_ENABLE | BGE_MODECTL_HTX2B_ENABLE); + } + mode_ctl |= BGE_MODECTL_MAC_ATTN_INTR | BGE_MODECTL_HOST_SEND_BDS | + BGE_MODECTL_TX_NO_PHDR_CSUM; /* * BCM5701 B5 have a bug causing data corruption when using @@ -1301,7 +1730,9 @@ bge_chipinit(struct bge_softc *sc) */ if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5701 && sc->bge_chipid == BGE_CHIPID_BCM5701_B5) - BGE_SETBIT(sc, BGE_MODE_CTL, BGE_MODECTL_FORCE_PCI32); + mode_ctl |= BGE_MODECTL_FORCE_PCI32; + + CSR_WRITE_4(sc, BGE_MODE_CTL, mode_ctl); /* * Disable memory write invalidate. Apparently it is not supported @@ -1341,7 +1772,7 @@ bge_blockinit(struct bge_softc *sc) vaddr_t rcb_addr; int i; bge_hostaddr taddr; - u_int32_t val; + u_int32_t dmactl, val; /* * Initialize the memory window pointer register so that @@ -1352,7 +1783,7 @@ bge_blockinit(struct bge_softc *sc) CSR_WRITE_4(sc, BGE_PCI_MEMWIN_BASEADDR, 0); /* Configure mbuf memory pool */ - if (BGE_IS_5700_FAMILY(sc)) { + if (!BGE_IS_5705_PLUS(sc)) { CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_BASEADDR, BGE_BUFFPOOL_1); @@ -1394,8 +1825,16 @@ bge_blockinit(struct bge_softc *sc) CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_HIWAT, 10); /* Enable buffer manager */ - CSR_WRITE_4(sc, BGE_BMAN_MODE, - BGE_BMANMODE_ENABLE|BGE_BMANMODE_LOMBUF_ATTN); + val = BGE_BMANMODE_ENABLE | BGE_BMANMODE_LOMBUF_ATTN; + /* + * Change the arbitration algorithm of TXMBUF read request to + * round-robin instead of priority based for BCM5719. When + * TXFIFO is almost empty, RDMA will hold its request until + * TXFIFO is not almost empty. + */ + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5719) + val |= BGE_BMANMODE_NO_TX_UNDERRUN; + CSR_WRITE_4(sc, BGE_BMAN_MODE, val); /* Poll for buffer manager start indication */ for (i = 0; i < 2000; i++) { @@ -1438,7 +1877,13 @@ bge_blockinit(struct bge_softc *sc) else rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(ETHER_MAX_DIX_LEN, 0); - rcb->bge_nicaddr = BGE_STD_RX_RINGS; + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5717 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5719 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5720) + rcb->bge_nicaddr = BGE_STD_RX_RINGS_5717; + else + rcb->bge_nicaddr = BGE_STD_RX_RINGS; + CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_HI, rcb->bge_hostaddr.bge_addr_hi); CSR_WRITE_4(sc, BGE_RX_STD_RCB_HADDR_LO, rcb->bge_hostaddr.bge_addr_lo); CSR_WRITE_4(sc, BGE_RX_STD_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags); @@ -1457,28 +1902,42 @@ bge_blockinit(struct bge_softc *sc) BGE_RING_DMA_ADDR(sc, bge_rx_jumbo_ring)); rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(0, BGE_RCB_FLAG_USE_EXT_RX_BD | BGE_RCB_FLAG_RING_DISABLED); - rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS; + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5717 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5719 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5720) + rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS_5717; + else + rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS; CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_HI, rcb->bge_hostaddr.bge_addr_hi); CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_LO, rcb->bge_hostaddr.bge_addr_lo); + /* Program the jumbo receive producer ring RCB parameters. */ CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags); - CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_NICADDR, - rcb->bge_nicaddr); + CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_NICADDR, rcb->bge_nicaddr); + /* Reset the jumbo receive producer ring producer index. */ + bge_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, 0); + } + /* Disable the mini receive producer ring RCB. */ + if (BGE_IS_5700_FAMILY(sc)) { /* Set up dummy disabled mini ring RCB */ rcb = &sc->bge_rdata->bge_info.bge_mini_rx_rcb; rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(0, BGE_RCB_FLAG_RING_DISABLED); CSR_WRITE_4(sc, BGE_RX_MINI_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags); + /* Reset the mini receive producer ring producer index. */ + bge_writembx(sc, BGE_MBX_RX_MINI_PROD_LO, 0); + /* XXX why? */ bus_dmamap_sync(sc->bge_dmatag, sc->bge_ring_map, offsetof(struct bge_ring_data, bge_info), sizeof (struct bge_gib), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); + } /* Choose de-pipeline mode for BCM5906 A0, A1 and A2. */ @@ -1523,7 +1982,12 @@ bge_blockinit(struct bge_softc *sc) BGE_HOSTADDR(taddr, BGE_RING_DMA_ADDR(sc, bge_tx_ring)); RCB_WRITE_4(sc, rcb_addr, bge_hostaddr.bge_addr_hi, taddr.bge_addr_hi); RCB_WRITE_4(sc, rcb_addr, bge_hostaddr.bge_addr_lo, taddr.bge_addr_lo); - RCB_WRITE_4(sc, rcb_addr, bge_nicaddr, + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5717 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5719 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5720) + RCB_WRITE_4(sc, rcb_addr, bge_nicaddr, BGE_SEND_RING_5717); + else + RCB_WRITE_4(sc, rcb_addr, bge_nicaddr, BGE_NIC_TXRING_ADDR(0, BGE_TX_RING_CNT)); if (BGE_IS_5700_FAMILY(sc)) RCB_WRITE_4(sc, rcb_addr, bge_maxlen_flags, @@ -1543,11 +2007,6 @@ bge_blockinit(struct bge_softc *sc) rcb_addr += sizeof(struct bge_rcb); } - /* Initialize RX ring indexes */ - bge_writembx(sc, BGE_MBX_RX_STD_PROD_LO, 0); - bge_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, 0); - bge_writembx(sc, BGE_MBX_RX_MINI_PROD_LO, 0); - /* * Set up RX return ring 0 * Note that the NIC address for RX return rings is 0x00000000. @@ -1570,7 +2029,11 @@ bge_blockinit(struct bge_softc *sc) BGE_TX_BACKOFF_SEED_MASK); /* Set inter-packet gap */ - CSR_WRITE_4(sc, BGE_TX_LENGTHS, 0x2620); + val = 0x2620; + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5720) + val |= CSR_READ_4(sc, BGE_TX_LENGTHS) & + (BGE_TXLEN_JMB_FRM_LEN_MSK | BGE_TXLEN_CNT_DN_VAL_MSK); + CSR_WRITE_4(sc, BGE_TX_LENGTHS, val); /* * Specify which ring to use for packets that don't match @@ -1585,7 +2048,7 @@ bge_blockinit(struct bge_softc *sc) CSR_WRITE_4(sc, BGE_RXLP_CFG, 0x181); /* Inialize RX list placement stats mask. */ - CSR_WRITE_4(sc, BGE_RXLP_STATS_ENABLE_MASK, 0x007FFFFF); + CSR_WRITE_4(sc, BGE_RXLP_STATS_ENABLE_MASK, 0x007BFFFF); CSR_WRITE_4(sc, BGE_RXLP_STATS_CTL, 0x1); /* Disable host coalescing until we get it set up */ @@ -1609,7 +2072,7 @@ bge_blockinit(struct bge_softc *sc) CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS, sc->bge_tx_coal_ticks); CSR_WRITE_4(sc, BGE_HCC_RX_MAX_COAL_BDS, sc->bge_rx_max_coal_bds); CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS, sc->bge_tx_max_coal_bds); - if (BGE_IS_5700_FAMILY(sc)) { + if (!(BGE_IS_5705_PLUS(sc))) { CSR_WRITE_4(sc, BGE_HCC_RX_COAL_TICKS_INT, 0); CSR_WRITE_4(sc, BGE_HCC_TX_COAL_TICKS_INT, 0); } @@ -1617,7 +2080,7 @@ bge_blockinit(struct bge_softc *sc) CSR_WRITE_4(sc, BGE_HCC_TX_MAX_COAL_BDS_INT, 0); /* Set up address of statistics block */ - if (BGE_IS_5700_FAMILY(sc)) { + if (!(BGE_IS_5705_PLUS(sc))) { CSR_WRITE_4(sc, BGE_HCC_STATS_ADDR_HI, 0); CSR_WRITE_4(sc, BGE_HCC_STATS_ADDR_LO, BGE_RING_DMA_ADDR(sc, bge_info.bge_stats)); @@ -1635,8 +2098,18 @@ bge_blockinit(struct bge_softc *sc) sc->bge_rdata->bge_status_block.bge_idx[0].bge_rx_prod_idx = 0; sc->bge_rdata->bge_status_block.bge_idx[0].bge_tx_cons_idx = 0; + /* Set up status block size. */ + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5700 && + sc->bge_chipid != BGE_CHIPID_BCM5700_C0) { + val = BGE_STATBLKSZ_FULL; + bzero(&sc->bge_rdata->bge_status_block, BGE_STATUS_BLK_SZ); + } else { + val = BGE_STATBLKSZ_32BYTE; + bzero(&sc->bge_rdata->bge_status_block, 32); + } + /* Turn on host coalescing state machine */ - CSR_WRITE_4(sc, BGE_HCC_MODE, BGE_HCCMODE_ENABLE); + CSR_WRITE_4(sc, BGE_HCC_MODE, val | BGE_HCCMODE_ENABLE); /* Turn on RX BD completion state machine and enable attentions */ CSR_WRITE_4(sc, BGE_RBDC_MODE, @@ -1646,7 +2119,7 @@ bge_blockinit(struct bge_softc *sc) CSR_WRITE_4(sc, BGE_RXLP_MODE, BGE_RXLPMODE_ENABLE); /* Turn on RX list selector state machine. */ - if (BGE_IS_5700_FAMILY(sc)) + if (!(BGE_IS_5705_PLUS(sc))) CSR_WRITE_4(sc, BGE_RXLS_MODE, BGE_RXLSMODE_ENABLE); val = BGE_MACMODE_TXDMA_ENB | BGE_MACMODE_RXDMA_ENB | @@ -1661,8 +2134,13 @@ bge_blockinit(struct bge_softc *sc) else val |= BGE_PORTMODE_MII; + /* Allow APE to send/receive frames. */ + if ((sc->bge_mfw_flags & BGE_MFW_ON_APE) != 0) + val |= BGE_MACMODE_APE_RX_EN | BGE_MACMODE_APE_TX_EN; + /* Turn on DMA, clear stats */ CSR_WRITE_4(sc, BGE_MAC_MODE, val); + DELAY(40); /* Set misc. local control, enable interrupts on attentions */ CSR_WRITE_4(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_ONATTN); @@ -1676,7 +2154,7 @@ bge_blockinit(struct bge_softc *sc) #endif /* Turn on DMA completion state machine */ - if (BGE_IS_5700_FAMILY(sc)) + if (!(BGE_IS_5705_PLUS(sc))) CSR_WRITE_4(sc, BGE_DMAC_MODE, BGE_DMACMODE_ENABLE); val = BGE_WDMAMODE_ENABLE|BGE_WDMAMODE_ALL_ATTNS; @@ -1690,6 +2168,7 @@ bge_blockinit(struct bge_softc *sc) /* Turn on write DMA state machine */ CSR_WRITE_4(sc, BGE_WDMA_MODE, val); + DELAY(40); val = BGE_RDMAMODE_ENABLE|BGE_RDMAMODE_ALL_ATTNS; @@ -1706,8 +2185,62 @@ bge_blockinit(struct bge_softc *sc) if (sc->bge_flags & BGE_PCIE) val |= BGE_RDMAMODE_FIFO_LONG_BURST; - /* Turn on read DMA state machine */ + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5720) { + val |= CSR_READ_4(sc, BGE_RDMA_MODE) & + BGE_RDMAMODE_H2BNC_VLAN_DET; + /* + * Allow multiple outstanding read requests from + * non-LSO read DMA engine. + */ + val &= ~BGE_RDMAMODE_MULT_DMA_RD_DIS; + } + + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5761 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5784 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5785 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM57780 || + BGE_IS_5717_PLUS(sc)) { + dmactl = CSR_READ_4(sc, BGE_RDMA_RSRVCTRL); + /* + * Adjust tx margin to prevent TX data corruption and + * fix internal FIFO overflow. + */ + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5719 || + sc->bge_chipid == BGE_CHIPID_BCM5719_A0) { + dmactl &= ~(BGE_RDMA_RSRVCTRL_FIFO_LWM_MASK | + BGE_RDMA_RSRVCTRL_FIFO_HWM_MASK | + BGE_RDMA_RSRVCTRL_TXMRGN_MASK); + dmactl |= BGE_RDMA_RSRVCTRL_FIFO_LWM_1_5K | + BGE_RDMA_RSRVCTRL_FIFO_HWM_1_5K | + BGE_RDMA_RSRVCTRL_TXMRGN_320B; + } + /* + * Enable fix for read DMA FIFO overruns. + * The fix is to limit the number of RX BDs + * the hardware would fetch at a fime. + */ + CSR_WRITE_4(sc, BGE_RDMA_RSRVCTRL, dmactl | + BGE_RDMA_RSRVCTRL_FIFO_OFLW_FIX); + } + + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5719) { + CSR_WRITE_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL, + CSR_READ_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL) | + BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_4K | + BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K); + } else if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5720) { + /* + * Allow 4KB burst length reads for non-LSO frames. + * Enable 512B burst length reads for buffer descriptors. + */ + CSR_WRITE_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL, + CSR_READ_4(sc, BGE_RDMA_LSO_CRPTEN_CTRL) | + BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_BD_512 | + BGE_RDMA_LSO_CRPTEN_CTRL_BLEN_LSO_4K); + } + CSR_WRITE_4(sc, BGE_RDMA_MODE, val); + DELAY(40); /* Turn on RX data completion state machine */ CSR_WRITE_4(sc, BGE_RDC_MODE, BGE_RDCMODE_ENABLE); @@ -1719,12 +2252,13 @@ bge_blockinit(struct bge_softc *sc) CSR_WRITE_4(sc, BGE_RDBDI_MODE, BGE_RDBDIMODE_ENABLE); /* Turn on Mbuf cluster free state machine */ - if (BGE_IS_5700_FAMILY(sc)) + if (!BGE_IS_5705_PLUS(sc)) CSR_WRITE_4(sc, BGE_MBCF_MODE, BGE_MBCFMODE_ENABLE); /* Turn on send BD completion state machine */ CSR_WRITE_4(sc, BGE_SBDC_MODE, BGE_SBDCMODE_ENABLE); + /* Turn on send data completion state machine */ val = BGE_SDCMODE_ENABLE; if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5761) @@ -1742,13 +2276,13 @@ bge_blockinit(struct bge_softc *sc) /* Turn on send BD selector state machine */ CSR_WRITE_4(sc, BGE_SRS_MODE, BGE_SRSMODE_ENABLE); - CSR_WRITE_4(sc, BGE_SDI_STATS_ENABLE_MASK, 0x007FFFFF); + CSR_WRITE_4(sc, BGE_SDI_STATS_ENABLE_MASK, 0x007BFFFF); CSR_WRITE_4(sc, BGE_SDI_STATS_CTL, BGE_SDISTATSCTL_ENABLE|BGE_SDISTATSCTL_FASTER); /* ack/clear link change events */ - CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED| - BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE| + CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED | + BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE | BGE_MACSTAT_LINK_CHANGED); /* Enable PHY auto polling (for MII/GMII only) */ @@ -1821,7 +2355,7 @@ bge_attach(struct device *parent, struct device *self, void *aux) pcireg_t pm_ctl, memtype, subid, reg; pci_intr_handle_t ih; const char *intrstr = NULL; - bus_size_t size; + bus_size_t size, apesize; bus_dma_segment_t seg; int rseg, gotenaddr = 0, aspm_off; u_int32_t hwcfg = 0; @@ -1991,24 +2525,6 @@ bge_attach(struct device *parent, struct device *self, void *aux) break; } - /* Identify chips with APE processor. */ - switch (BGE_ASICREV(sc->bge_chipid)) { - case BGE_ASICREV_BCM5717: - case BGE_ASICREV_BCM5719: - case BGE_ASICREV_BCM5720: - case BGE_ASICREV_BCM5761: - sc->bge_flags |= BGE_APE; - break; - } - - /* Identify the chips that use an CPMU. */ - if (BGE_IS_5717_PLUS(sc) || - BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5784 || - BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5761 || - BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5785 || - BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM57780) - sc->bge_flags |= BGE_CPMU_PRESENT; - /* * When using the BCM5701 in PCI-X mode, data corruption has * been observed in the first few bytes of some received packets. @@ -2085,10 +2601,55 @@ bge_attach(struct device *parent, struct device *self, void *aux) sc->bge_flags |= BGE_PHY_BER_BUG; } + /* Identify chips with APE processor. */ + switch (BGE_ASICREV(sc->bge_chipid)) { + case BGE_ASICREV_BCM5717: + case BGE_ASICREV_BCM5719: + case BGE_ASICREV_BCM5720: + case BGE_ASICREV_BCM5761: + sc->bge_flags |= BGE_APE; + break; + } + + /* Chips with APE need BAR2 access for APE registers/memory. */ + if ((sc->bge_flags & BGE_APE) != 0) { + memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, BGE_PCI_BAR2); + if (pci_mapreg_map(pa, BGE_PCI_BAR2, memtype, 0, + &sc->bge_apetag, &sc->bge_apehandle, NULL, &apesize, 0)) { + printf(": couldn't map BAR2 memory\n"); + goto fail_1; + } + + /* Enable APE register/memory access by host driver. */ + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, BGE_PCI_PCISTATE); + reg |= BGE_PCISTATE_ALLOW_APE_CTLSPC_WR | + BGE_PCISTATE_ALLOW_APE_SHMEM_WR | + BGE_PCISTATE_ALLOW_APE_PSPACE_WR; + pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_PCISTATE, reg); + + bge_ape_lock_init(sc); + bge_ape_read_fw_ver(sc); + } + + /* Identify the chips that use an CPMU. */ + if (BGE_IS_5717_PLUS(sc) || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5784 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5761 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5785 || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM57780) + sc->bge_flags |= BGE_CPMU_PRESENT; + + if ((sc->bge_flags & BGE_CPMU_PRESENT) != 0) + BGE_SETBIT(sc, BGE_MI_MODE, BGE_MIMODE_500KHZ_CONST); + /* Try to reset the chip. */ DPRINTFN(5, ("bge_reset\n")); + bge_sig_pre_reset(sc, BGE_RESET_START); bge_reset(sc); + bge_sig_legacy(sc, BGE_RESET_START); + bge_sig_post_reset(sc, BGE_RESET_START); + bge_chipinit(sc); #ifdef __sparc64__ @@ -2142,7 +2703,7 @@ bge_attach(struct device *parent, struct device *self, void *aux) if (!gotenaddr) { printf(": failed to read station address\n"); - goto fail_1; + goto fail_2; } /* Allocate the general information block and ring buffers. */ @@ -2151,7 +2712,7 @@ bge_attach(struct device *parent, struct device *self, void *aux) if (bus_dmamem_alloc(sc->bge_dmatag, sizeof(struct bge_ring_data), PAGE_SIZE, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) { printf(": can't alloc rx buffers\n"); - goto fail_1; + goto fail_2; } DPRINTFN(5, ("bus_dmamem_map\n")); if (bus_dmamem_map(sc->bge_dmatag, &seg, rseg, @@ -2159,20 +2720,20 @@ bge_attach(struct device *parent, struct device *self, void *aux) BUS_DMA_NOWAIT)) { printf(": can't map dma buffers (%lu bytes)\n", sizeof(struct bge_ring_data)); - goto fail_2; + goto fail_3; } DPRINTFN(5, ("bus_dmamem_create\n")); if (bus_dmamap_create(sc->bge_dmatag, sizeof(struct bge_ring_data), 1, sizeof(struct bge_ring_data), 0, BUS_DMA_NOWAIT, &sc->bge_ring_map)) { printf(": can't create dma map\n"); - goto fail_3; + goto fail_4; } DPRINTFN(5, ("bus_dmamem_load\n")); if (bus_dmamap_load(sc->bge_dmatag, sc->bge_ring_map, kva, sizeof(struct bge_ring_data), NULL, BUS_DMA_NOWAIT)) { - goto fail_4; + goto fail_5; } DPRINTFN(5, ("bzero\n")); @@ -2187,11 +2748,13 @@ bge_attach(struct device *parent, struct device *self, void *aux) sc->bge_tx_coal_ticks = 300; sc->bge_tx_max_coal_bds = 400; - /* BCM5705+ limits RX return ring to 512 entries. */ - if (BGE_IS_5700_FAMILY(sc) || BGE_IS_5717_PLUS(sc)) + /* 5705 limits RX return ring to 512 entries. */ + if (BGE_IS_5717_PLUS(sc)) sc->bge_return_ring_cnt = BGE_RETURN_RING_CNT; - else + else if (BGE_IS_5705_PLUS(sc)) sc->bge_return_ring_cnt = BGE_RETURN_RING_CNT_5705; + else + sc->bge_return_ring_cnt = BGE_RETURN_RING_CNT; /* Set up ifnet structure */ ifp = &sc->arpcom.ac_if; @@ -2252,7 +2815,7 @@ bge_attach(struct device *parent, struct device *self, void *aux) if (bge_read_eeprom(sc, (caddr_t)&hwcfg, BGE_EE_HWCFG_OFFSET, sizeof(hwcfg))) { printf(": failed to read media type\n"); - goto fail_5; + goto fail_6; } hwcfg = ntohl(hwcfg); } @@ -2275,7 +2838,7 @@ bge_attach(struct device *parent, struct device *self, void *aux) if (intrstr != NULL) printf(" at %s", intrstr); printf("\n"); - goto fail_5; + goto fail_6; } /* @@ -2328,19 +2891,23 @@ bge_attach(struct device *parent, struct device *self, void *aux) timeout_set(&sc->bge_rxtimeout, bge_rxtick, sc); return; -fail_5: +fail_6: bus_dmamap_unload(sc->bge_dmatag, sc->bge_ring_map); -fail_4: +fail_5: bus_dmamap_destroy(sc->bge_dmatag, sc->bge_ring_map); -fail_3: +fail_4: bus_dmamem_unmap(sc->bge_dmatag, kva, sizeof(struct bge_ring_data)); -fail_2: +fail_3: bus_dmamem_free(sc->bge_dmatag, &seg, rseg); +fail_2: + if ((sc->bge_flags & BGE_APE) != 0) + bus_space_unmap(sc->bge_apetag, sc->bge_apehandle, apesize); + fail_1: bus_space_unmap(sc->bge_btag, sc->bge_bhandle, size); } @@ -2374,30 +2941,57 @@ void bge_reset(struct bge_softc *sc) { struct pci_attach_args *pa = &sc->bge_pa; - pcireg_t cachesize, command, pcistate, new_pcistate; - u_int32_t reset; - int i, val = 0; + pcireg_t cachesize, command; + u_int32_t reset, mac_mode, mac_mode_mask, val; + void (*write_op)(struct bge_softc *, int, int); + int i; + + mac_mode_mask = BGE_MACMODE_HALF_DUPLEX | BGE_MACMODE_PORTMODE; + if ((sc->bge_mfw_flags & BGE_MFW_ON_APE) != 0) + mac_mode_mask |= BGE_MACMODE_APE_RX_EN | BGE_MACMODE_APE_TX_EN; + mac_mode = CSR_READ_4(sc, BGE_MAC_MODE) & mac_mode_mask; + + if (BGE_IS_575X_PLUS(sc) && !BGE_IS_5714_FAMILY(sc) && + BGE_ASICREV(sc->bge_chipid) != BGE_ASICREV_BCM5906) { + if (sc->bge_flags & BGE_PCIE) + write_op = bge_writembx; + else + write_op = bge_writemem_ind; + } else + write_op = bge_writereg_ind; + + /* Take APE lock when performing reset. */ + bge_ape_lock(sc, BGE_APE_LOCK_GRC); /* Save some important PCI state. */ cachesize = pci_conf_read(pa->pa_pc, pa->pa_tag, BGE_PCI_CACHESZ); command = pci_conf_read(pa->pa_pc, pa->pa_tag, BGE_PCI_CMD); - pcistate = pci_conf_read(pa->pa_pc, pa->pa_tag, BGE_PCI_PCISTATE); pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_MISC_CTL, - BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR| - BGE_PCIMISCCTL_ENDIAN_WORDSWAP|BGE_PCIMISCCTL_PCISTATE_RW); + BGE_PCIMISCCTL_INDIRECT_ACCESS | BGE_PCIMISCCTL_MASK_PCI_INTR | + BGE_PCIMISCCTL_ENDIAN_WORDSWAP | BGE_PCIMISCCTL_PCISTATE_RW); /* Disable fastboot on controllers that support it. */ if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5752 || BGE_IS_5755_PLUS(sc)) CSR_WRITE_4(sc, BGE_FASTBOOT_PC, 0); - reset = BGE_MISCCFG_RESET_CORE_CLOCKS|(65<<1); + /* + * Write the magic number to SRAM at offset 0xB50. + * When firmware finishes its initialization it will + * write ~BGE_SRAM_FW_MB_MAGIC to the same location. + */ + bge_writemem_ind(sc, BGE_SOFTWARE_GENCOMM, BGE_MAGIC_NUMBER); + + reset = BGE_MISCCFG_RESET_CORE_CLOCKS | BGE_32BITTIME_66MHZ; if (sc->bge_flags & BGE_PCIE) { - if (CSR_READ_4(sc, 0x7e2c) == 0x60) { - /* PCI Express 1.0 system */ - CSR_WRITE_4(sc, 0x7e2c, 0x20); + if (BGE_ASICREV(sc->bge_chipid != BGE_ASICREV_BCM5785) && + !BGE_IS_5717_PLUS(sc)) { + if (CSR_READ_4(sc, 0x7e2c) == 0x60) { + /* PCI Express 1.0 system */ + CSR_WRITE_4(sc, 0x7e2c, 0x20); + } } if (sc->bge_chipid != BGE_CHIPID_BCM5750_A0) { /* @@ -2413,11 +3007,17 @@ bge_reset(struct bge_softc *sc) * Set GPHY Power Down Override to leave GPHY * powered up in D0 uninitialized. */ - if (BGE_IS_5705_PLUS(sc)) + if (BGE_IS_5705_PLUS(sc) && + (sc->bge_flags & BGE_CPMU_PRESENT) == 0) reset |= BGE_MISCCFG_KEEP_GPHY_POWER; /* Issue global reset */ - bge_writereg_ind(sc, BGE_MISC_CFG, reset); + write_op(sc, BGE_MISC_CFG, reset); + + if (sc->bge_flags & BGE_PCIE) + DELAY(100 * 1000); + else + DELAY(1000); if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5906) { u_int32_t status, ctrl; @@ -2432,8 +3032,6 @@ bge_reset(struct bge_softc *sc) sc->bge_flags |= BGE_NO_EEPROM; } - DELAY(1000); - if (sc->bge_flags & BGE_PCIE) { if (sc->bge_chipid == BGE_CHIPID_BCM5750_A0) { pcireg_t v; @@ -2453,26 +3051,36 @@ bge_reset(struct bge_softc *sc) /* Reset some of the PCI state that got zapped by reset */ pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_MISC_CTL, - BGE_PCIMISCCTL_INDIRECT_ACCESS|BGE_PCIMISCCTL_MASK_PCI_INTR| - BGE_PCIMISCCTL_ENDIAN_WORDSWAP|BGE_PCIMISCCTL_PCISTATE_RW); + BGE_PCIMISCCTL_INDIRECT_ACCESS | BGE_PCIMISCCTL_MASK_PCI_INTR | + BGE_PCIMISCCTL_ENDIAN_WORDSWAP | BGE_PCIMISCCTL_PCISTATE_RW); + val = BGE_PCISTATE_ROM_ENABLE | BGE_PCISTATE_ROM_RETRY_ENABLE; + if (sc->bge_chipid == BGE_CHIPID_BCM5704_A0 && + (sc->bge_flags & BGE_PCIX) != 0) + val |= BGE_PCISTATE_RETRY_SAME_DMA; + if ((sc->bge_mfw_flags & BGE_MFW_ON_APE) != 0) + val |= BGE_PCISTATE_ALLOW_APE_CTLSPC_WR | + BGE_PCISTATE_ALLOW_APE_SHMEM_WR | + BGE_PCISTATE_ALLOW_APE_PSPACE_WR; + pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_PCISTATE, val); pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_CACHESZ, cachesize); pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_CMD, command); - bge_writereg_ind(sc, BGE_MISC_CFG, (65 << 1)); /* Enable memory arbiter. */ if (BGE_IS_5714_FAMILY(sc)) { - u_int32_t val; - val = CSR_READ_4(sc, BGE_MARB_MODE); CSR_WRITE_4(sc, BGE_MARB_MODE, BGE_MARBMODE_ENABLE | val); } else CSR_WRITE_4(sc, BGE_MARB_MODE, BGE_MARBMODE_ENABLE); - /* - * Prevent PXE restart: write a magic number to the - * general communications memory at 0xB50. - */ - bge_writemem_ind(sc, BGE_SOFTWARE_GENCOMM, BGE_MAGIC_NUMBER); + /* Fix up byte swapping */ + CSR_WRITE_4(sc, BGE_MODE_CTL, bge_dma_swap_options(sc)); + + val = CSR_READ_4(sc, BGE_MAC_MODE); + val = (val & ~mac_mode_mask) | mac_mode; + CSR_WRITE_4(sc, BGE_MAC_MODE, val); + DELAY(40); + + bge_ape_unlock(sc, BGE_APE_LOCK_GRC); if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5906) { for (i = 0; i < BGE_TIMEOUT; i++) { @@ -2501,36 +3109,12 @@ bge_reset(struct bge_softc *sc) if (i >= BGE_TIMEOUT && (!(sc->bge_flags & BGE_NO_EEPROM))) printf("%s: firmware handshake timed out\n", sc->bge_dev.dv_xname); + /* BCM57765 A0 needs additional time before accessing. */ + if (sc->bge_chipid == BGE_CHIPID_BCM57765_A0) + DELAY(10 * 1000); /* XXX */ } /* - * XXX Wait for the value of the PCISTATE register to - * return to its original pre-reset state. This is a - * fairly good indicator of reset completion. If we don't - * wait for the reset to fully complete, trying to read - * from the device's non-PCI registers may yield garbage - * results. - */ - for (i = 0; i < BGE_TIMEOUT; i++) { - new_pcistate = pci_conf_read(pa->pa_pc, pa->pa_tag, - BGE_PCI_PCISTATE); - if ((new_pcistate & ~BGE_PCISTATE_RESERVED) == - (pcistate & ~BGE_PCISTATE_RESERVED)) - break; - DELAY(10); - } - if ((new_pcistate & ~BGE_PCISTATE_RESERVED) != - (pcistate & ~BGE_PCISTATE_RESERVED)) { - DPRINTFN(5, ("%s: pcistate failed to revert\n", - sc->bge_dev.dv_xname)); - } - - /* Fix up byte swapping */ - CSR_WRITE_4(sc, BGE_MODE_CTL, BGE_DMA_SWAP_OPTIONS); - - CSR_WRITE_4(sc, BGE_MAC_MODE, 0); - - /* * The 5704 in TBI mode apparently needs some special * adjustment to insure the SERDES drive level is set * to 1.2V. @@ -2554,7 +3138,10 @@ bge_reset(struct bge_softc *sc) v = CSR_READ_4(sc, 0x7c00); CSR_WRITE_4(sc, 0x7c00, v | (1<<25)); } - DELAY(10000); + + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5720) + BGE_CLRBIT(sc, BGE_CPMU_CLCK_ORIDE, + CPMU_CLCK_ORIDE_MAC_ORIDE_EN); } /* @@ -2664,29 +3251,10 @@ bge_rxeof(struct bge_softc *sc) m->m_data += ETHER_ALIGN; } #endif - m->m_pkthdr.len = m->m_len = cur_rx->bge_len - ETHER_CRC_LEN; + m->m_pkthdr.len = m->m_len = cur_rx->bge_len - ETHER_CRC_LEN; m->m_pkthdr.rcvif = ifp; - /* - * 5700 B0 chips do not support checksumming correctly due - * to hardware bugs. - */ - if (sc->bge_chipid != BGE_CHIPID_BCM5700_B0) { - if (cur_rx->bge_flags & BGE_RXBDFLAG_IP_CSUM) { - if (cur_rx->bge_ip_csum == 0xFFFF) - m->m_pkthdr.csum_flags |= - M_IPV4_CSUM_IN_OK; - else - m->m_pkthdr.csum_flags |= - M_IPV4_CSUM_IN_BAD; - } - if (cur_rx->bge_flags & BGE_RXBDFLAG_TCP_UDP_CSUM && - m->m_pkthdr.len >= ETHER_MIN_NOPAD) { - if (cur_rx->bge_tcp_udp_csum == 0xFFFF) - m->m_pkthdr.csum_flags |= - M_TCP_CSUM_IN_OK|M_UDP_CSUM_IN_OK; - } - } + bge_rxcsum(sc, cur_rx, m); #if NVLAN > 0 if (cur_rx->bge_flags & BGE_RXBDFLAG_VLAN_TAG) { @@ -2715,6 +3283,41 @@ bge_rxeof(struct bge_softc *sc) } void +bge_rxcsum(struct bge_softc *sc, struct bge_rx_bd *cur_rx, struct mbuf *m) +{ + if (sc->bge_chipid == BGE_CHIPID_BCM5700_B0) { + /* + * 5700 B0 chips do not support checksumming correctly due + * to hardware bugs. + */ + return; + } else if (BGE_IS_5717_PLUS(sc)) { + if ((cur_rx->bge_flags & BGE_RXBDFLAG_IPV6) == 0) { + if (cur_rx->bge_flags & BGE_RXBDFLAG_IP_CSUM && + (cur_rx->bge_error_flag & + BGE_RXERRFLAG_IP_CSUM_NOK) == 0) + m->m_pkthdr.csum_flags |= M_IPV4_CSUM_IN_OK; + + if (cur_rx->bge_flags & BGE_RXBDFLAG_TCP_UDP_CSUM) { + m->m_pkthdr.csum_flags |= + M_TCP_CSUM_IN_OK|M_UDP_CSUM_IN_OK; + } + } + } else { + if (cur_rx->bge_flags & BGE_RXBDFLAG_IP_CSUM && + cur_rx->bge_ip_csum == 0xFFFF) + m->m_pkthdr.csum_flags |= M_IPV4_CSUM_IN_OK; + + if (cur_rx->bge_flags & BGE_RXBDFLAG_TCP_UDP_CSUM && + m->m_pkthdr.len >= ETHER_MIN_NOPAD && + cur_rx->bge_tcp_udp_csum == 0xFFFF) { + m->m_pkthdr.csum_flags |= + M_TCP_CSUM_IN_OK|M_UDP_CSUM_IN_OK; + } + } +} + +void bge_txeof(struct bge_softc *sc) { struct bge_tx_bd *cur_tx = NULL; @@ -2795,10 +3398,14 @@ bge_intr(void *xsc) struct bge_softc *sc; struct ifnet *ifp; u_int32_t statusword; + u_int32_t intrmask = BGE_PCISTATE_INTR_NOT_ACTIVE; sc = xsc; ifp = &sc->arpcom.ac_if; + if (BGE_IS_5717_PLUS(sc)) + intrmask = 0; + /* It is possible for the interrupt to arrive before * the status block is updated prior to the interrupt. * Reading the PCI State register will confirm whether the @@ -2806,10 +3413,15 @@ bge_intr(void *xsc) */ /* read status word from status block */ + bus_dmamap_sync(sc->bge_dmatag, sc->bge_ring_map, + offsetof(struct bge_ring_data, bge_status_block), + sizeof (struct bge_status_block), + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); + statusword = sc->bge_rdata->bge_status_block.bge_status; if ((statusword & BGE_STATFLAG_UPDATED) || - (!(CSR_READ_4(sc, BGE_PCI_PCISTATE) & BGE_PCISTATE_INTR_NOT_ACTIVE))) { + (~CSR_READ_4(sc, BGE_PCI_PCISTATE) & intrmask)) { /* Ack interrupt and stop others from occurring. */ bge_writembx(sc, BGE_MBX_IRQ0_LO, 1); @@ -2817,6 +3429,11 @@ bge_intr(void *xsc) /* clear status word */ sc->bge_rdata->bge_status_block.bge_status = 0; + bus_dmamap_sync(sc->bge_dmatag, sc->bge_ring_map, + offsetof(struct bge_ring_data, bge_status_block), + sizeof (struct bge_status_block), + BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5700 || statusword & BGE_STATFLAG_LINKSTATE_CHANGED || BGE_STS_BIT(sc, BGE_STS_LINK_EVT)) @@ -2870,7 +3487,7 @@ bge_tick(void *xsc) */ if (!BGE_STS_BIT(sc, BGE_STS_LINK)) mii_tick(mii); - } + } timeout_add_sec(&sc->bge_timeout, 1); @@ -2885,11 +3502,12 @@ bge_stats_update_regs(struct bge_softc *sc) ifp->if_collisions += CSR_READ_4(sc, BGE_MAC_STATS + offsetof(struct bge_mac_stats_regs, etherStatsCollisions)); - ifp->if_ierrors += CSR_READ_4(sc, BGE_RXLP_LOCSTAT_IFIN_DROPS); - - ifp->if_ierrors += CSR_READ_4(sc, BGE_RXLP_LOCSTAT_IFIN_ERRORS); + sc->bge_rx_discards += CSR_READ_4(sc, BGE_RXLP_LOCSTAT_IFIN_DROPS); + sc->bge_rx_inerrors += CSR_READ_4(sc, BGE_RXLP_LOCSTAT_IFIN_ERRORS); + sc->bge_rx_overruns += CSR_READ_4(sc, BGE_RXLP_LOCSTAT_OUT_OF_BDS); - ifp->if_ierrors += CSR_READ_4(sc, BGE_RXLP_LOCSTAT_OUT_OF_BDS); + ifp->if_ierrors = sc->bge_rx_discards + sc->bge_rx_inerrors + + sc->bge_rx_overruns; } void @@ -3239,7 +3857,7 @@ bge_init(void *xsc) struct bge_softc *sc = xsc; struct ifnet *ifp; u_int16_t *m; - u_int32_t rxmode; + u_int32_t mode; int s; s = splnet(); @@ -3248,7 +3866,11 @@ bge_init(void *xsc) /* Cancel pending I/O and flush buffers. */ bge_stop(sc); + bge_sig_pre_reset(sc, BGE_RESET_START); bge_reset(sc); + bge_sig_legacy(sc, BGE_RESET_START); + bge_sig_post_reset(sc, BGE_RESET_START); + bge_chipinit(sc); /* @@ -3320,16 +3942,28 @@ bge_init(void *xsc) /* Init TX ring. */ bge_init_tx_ring(sc); - /* Turn on transmitter */ - BGE_SETBIT(sc, BGE_TX_MODE, BGE_TXMODE_ENABLE); + /* Enable TX MAC state machine lockup fix. */ + mode = CSR_READ_4(sc, BGE_TX_MODE); + if (BGE_IS_5755_PLUS(sc) || + BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5906) + mode |= BGE_TXMODE_MBUF_LOCKUP_FIX; + if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5720) { + mode &= ~(BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE); + mode |= CSR_READ_4(sc, BGE_TX_MODE) & + (BGE_TXMODE_JMB_FRM_LEN | BGE_TXMODE_CNT_DN_MODE); + } - rxmode = BGE_RXMODE_ENABLE; + /* Turn on transmitter */ + CSR_WRITE_4(sc, BGE_TX_MODE, mode | BGE_TXMODE_ENABLE); + DELAY(100); + mode = CSR_READ_4(sc, BGE_RX_MODE); if (BGE_IS_5755_PLUS(sc)) - rxmode |= BGE_RXMODE_RX_IPV6_CSUM_ENABLE; + mode |= BGE_RXMODE_IPV6_ENABLE; /* Turn on receiver */ - BGE_SETBIT(sc, BGE_RX_MODE, rxmode); + CSR_WRITE_4(sc, BGE_RX_MODE, mode | BGE_RXMODE_ENABLE); + DELAY(10); CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 2); @@ -3387,6 +4021,7 @@ bge_ifmedia_upd(struct ifnet *ifp) CSR_WRITE_4(sc, BGE_SGDIG_CFG, sgdig); } } + DELAY(40); break; case IFM_1000_SX: if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) { @@ -3591,6 +4226,13 @@ bge_stop(struct bge_softc *sc) ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); /* + * Tell firmware we're shutting down. + */ + /* bge_stop_fw(sc); */ + bge_sig_pre_reset(sc, BGE_RESET_SHUTDOWN); + + + /* * Disable all of the receiver blocks */ bge_stop_block(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE); @@ -3626,14 +4268,14 @@ bge_stop(struct bge_softc *sc) CSR_WRITE_4(sc, BGE_FTQ_RESET, 0xFFFFFFFF); CSR_WRITE_4(sc, BGE_FTQ_RESET, 0); - if (BGE_IS_5700_FAMILY(sc)) { + if (!BGE_IS_5705_PLUS(sc)) { bge_stop_block(sc, BGE_BMAN_MODE, BGE_BMANMODE_ENABLE); bge_stop_block(sc, BGE_MARB_MODE, BGE_MARBMODE_ENABLE); } - /* Disable host interrupts. */ - BGE_SETBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_MASK_PCI_INTR); - bge_writembx(sc, BGE_MBX_IRQ0_LO, 1); + bge_reset(sc); + bge_sig_legacy(sc, BGE_RESET_SHUTDOWN); + bge_sig_post_reset(sc, BGE_RESET_SHUTDOWN); /* * Tell firmware we're shutting down. @@ -3719,7 +4361,7 @@ bge_link_upd(struct bge_softc *sc) BRGPHY_MII_IMR, BRGPHY_INTRS); } return; - } + } if (sc->bge_flags & BGE_PHY_FIBER_TBI) { status = CSR_READ_4(sc, BGE_MAC_STS); @@ -3744,13 +4386,13 @@ bge_link_upd(struct bge_softc *sc) if_link_state_change(ifp); ifp->if_baudrate = 0; } - /* + /* * Discard link events for MII/GMII cards if MI auto-polling disabled. * This should not happen since mii callouts are locked now, but * we keep this check for debug. */ } else if (BGE_STS_BIT(sc, BGE_STS_AUTOPOLL)) { - /* + /* * Some broken BCM chips have BGE_STATFLAG_LINKSTATE_CHANGED bit * in status word always set. Workaround this bug by reading * PHY link status directly. diff --git a/sys/dev/pci/if_bgereg.h b/sys/dev/pci/if_bgereg.h index 634c1aba783..a6846bc1cbe 100644 --- a/sys/dev/pci/if_bgereg.h +++ b/sys/dev/pci/if_bgereg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bgereg.h,v 1.112 2013/02/09 23:39:38 brad Exp $ */ +/* $OpenBSD: if_bgereg.h,v 1.113 2013/02/22 01:26:55 dlg Exp $ */ /* * Copyright (c) 2001 Wind River Systems @@ -156,6 +156,7 @@ #define BGE_PCI_BIST 0x0F #define BGE_PCI_BAR0 0x10 #define BGE_PCI_BAR1 0x14 +#define BGE_PCI_BAR2 0x18 #define BGE_PCI_SUBSYS 0x2C #define BGE_PCI_SUBVID 0x2E #define BGE_PCI_ROMBASE 0x30 @@ -409,11 +410,14 @@ #define BGE_PCISTATE_PCI_BUSMODE 0x00000004 /* 1 = PCI, 0 = PCI-X */ #define BGE_PCISTATE_PCI_BUSSPEED 0x00000008 /* 1 = 66/133, 0 = 33/66 */ #define BGE_PCISTATE_32BIT_BUS 0x00000010 /* 1 = 32bit, 0 = 64bit */ -#define BGE_PCISTATE_WANT_EXPROM 0x00000020 -#define BGE_PCISTATE_EXPROM_RETRY 0x00000040 +#define BGE_PCISTATE_ROM_ENABLE 0x00000020 +#define BGE_PCISTATE_ROM_RETRY_ENABLE 0x00000040 #define BGE_PCISTATE_FLATVIEW_MODE 0x00000100 -#define BGE_PCISTATE_RETRY_SAME_DMA 0x00002000 #define BGE_PCISTATE_PCI_TGT_RETRY_MAX 0x00000E00 +#define BGE_PCISTATE_RETRY_SAME_DMA 0x00002000 +#define BGE_PCISTATE_ALLOW_APE_CTLSPC_WR 0x00010000 +#define BGE_PCISTATE_ALLOW_APE_SHMEM_WR 0x00020000 +#define BGE_PCISTATE_ALLOW_APE_PSPACE_WR 0x00040000 /* * The following bits in PCI state register are reserved. @@ -678,6 +682,8 @@ #define BGE_MACMODE_TXDMA_ENB 0x00200000 #define BGE_MACMODE_RXDMA_ENB 0x00400000 #define BGE_MACMODE_FRMHDR_DMA_ENB 0x00800000 +#define BGE_MACMODE_APE_RX_EN 0x08000000 +#define BGE_MACMODE_APE_TX_EN 0x10000000 #define BGE_PORTMODE_NONE 0x00000000 #define BGE_PORTMODE_MII 0x00000004 @@ -765,7 +771,7 @@ #define BGE_RXMODE_RX_PROMISC 0x00000100 #define BGE_RXMODE_RX_NO_CRC_CHECK 0x00000200 #define BGE_RXMODE_RX_KEEP_VLAN_DIAG 0x00000400 -#define BGE_RXMODE_RX_IPV6_CSUM_ENABLE 0x01000000 +#define BGE_RXMODE_IPV6_ENABLE 0x01000000 /* Receive MAC status register */ #define BGE_RXSTAT_REMOTE_XOFFED 0x00000001 @@ -2132,6 +2138,112 @@ #define BGE_MEMWIN_START 0x00008000 #define BGE_MEMWIN_END 0x0000FFFF +/* BAR1 (APE) Register Definitions */ + +#define BGE_APE_GPIO_MSG 0x0008 +#define BGE_APE_EVENT 0x000C +#define BGE_APE_LOCK_REQ 0x002C +#define BGE_APE_LOCK_GRANT 0x004C + +#define BGE_APE_GPIO_MSG_SHIFT 4 + +#define BGE_APE_EVENT_1 0x00000001 + +#define BGE_APE_LOCK_REQ_DRIVER0 0x00001000 + +#define BGE_APE_LOCK_GRANT_DRIVER0 0x00001000 + +/* APE Shared Memory block (writable by APE only) */ +#define BGE_APE_SEG_SIG 0x4000 +#define BGE_APE_FW_STATUS 0x400C +#define BGE_APE_FW_FEATURES 0x4010 +#define BGE_APE_FW_BEHAVIOR 0x4014 +#define BGE_APE_FW_VERSION 0x4018 +#define BGE_APE_FW_HEARTBEAT_INTERVAL 0x4024 +#define BGE_APE_FW_HEARTBEAT 0x4028 +#define BGE_APE_FW_ERROR_FLAGS 0x4074 + +#define BGE_APE_SEG_SIG_MAGIC 0x41504521 + +#define BGE_APE_FW_STATUS_READY 0x00000100 + +#define BGE_APE_FW_FEATURE_DASH 0x00000001 +#define BGE_APE_FW_FEATURE_NCSI 0x00000002 + +#define BGE_APE_FW_VERSION_MAJMSK 0xFF000000 +#define BGE_APE_FW_VERSION_MAJSFT 24 +#define BGE_APE_FW_VERSION_MINMSK 0x00FF0000 +#define BGE_APE_FW_VERSION_MINSFT 16 +#define BGE_APE_FW_VERSION_REVMSK 0x0000FF00 +#define BGE_APE_FW_VERSION_REVSFT 8 +#define BGE_APE_FW_VERSION_BLDMSK 0x000000FF + +/* Host Shared Memory block (writable by host only) */ +#define BGE_APE_HOST_SEG_SIG 0x4200 +#define BGE_APE_HOST_SEG_LEN 0x4204 +#define BGE_APE_HOST_INIT_COUNT 0x4208 +#define BGE_APE_HOST_DRIVER_ID 0x420C +#define BGE_APE_HOST_BEHAVIOR 0x4210 +#define BGE_APE_HOST_HEARTBEAT_INT_MS 0x4214 +#define BGE_APE_HOST_HEARTBEAT_COUNT 0x4218 +#define BGE_APE_HOST_DRVR_STATE 0x421C +#define BGE_APE_HOST_WOL_SPEED 0x4224 + +#define BGE_APE_HOST_SEG_SIG_MAGIC 0x484F5354 + +#define BGE_APE_HOST_SEG_LEN_MAGIC 0x00000020 + +#define BGE_APE_HOST_DRIVER_ID_FBSD 0xF6000000 +#define BGE_APE_HOST_DRIVER_ID_MAGIC(maj, min) \ + (BGE_APE_HOST_DRIVER_ID_FBSD | \ + ((maj) & 0xffd) << 16 | ((min) & 0xff) << 8) + +#define BGE_APE_HOST_BEHAV_NO_PHYLOCK 0x00000001 + +#define BGE_APE_HOST_HEARTBEAT_INT_DISABLE 0 +#define BGE_APE_HOST_HEARTBEAT_INT_5SEC 5000 + +#define BGE_APE_HOST_DRVR_STATE_START 0x00000001 +#define BGE_APE_HOST_DRVR_STATE_UNLOAD 0x00000002 +#define BGE_APE_HOST_DRVR_STATE_WOL 0x00000003 +#define BGE_APE_HOST_DRVR_STATE_SUSPEND 0x00000004 + +#define BGE_APE_HOST_WOL_SPEED_AUTO 0x00008000 + +#define BGE_APE_EVENT_STATUS 0x4300 + +#define BGE_APE_EVENT_STATUS_DRIVER_EVNT 0x00000010 +#define BGE_APE_EVENT_STATUS_STATE_CHNGE 0x00000500 +#define BGE_APE_EVENT_STATUS_STATE_START 0x00010000 +#define BGE_APE_EVENT_STATUS_STATE_UNLOAD 0x00020000 +#define BGE_APE_EVENT_STATUS_STATE_WOL 0x00030000 +#define BGE_APE_EVENT_STATUS_STATE_SUSPEND 0x00040000 +#define BGE_APE_EVENT_STATUS_EVENT_PENDING 0x80000000 + +#define BGE_APE_DEBUG_LOG 0x4E00 +#define BGE_APE_DEBUG_LOG_LEN 0x0100 + +#define BGE_APE_PER_LOCK_REQ 0x8400 +#define BGE_APE_PER_LOCK_GRANT 0x8420 + +#define BGE_APE_LOCK_PER_REQ_DRIVER0 0x00001000 +#define BGE_APE_LOCK_PER_REQ_DRIVER1 0x00000002 +#define BGE_APE_LOCK_PER_REQ_DRIVER2 0x00000004 +#define BGE_APE_LOCK_PER_REQ_DRIVER3 0x00000008 + +#define BGE_APE_PER_LOCK_GRANT_DRIVER0 0x00001000 +#define BGE_APE_PER_LOCK_GRANT_DRIVER1 0x00000002 +#define BGE_APE_PER_LOCK_GRANT_DRIVER2 0x00000004 +#define BGE_APE_PER_LOCK_GRANT_DRIVER3 0x00000008 + +/* APE Mutex Resources */ +#define BGE_APE_LOCK_PHY0 0 +#define BGE_APE_LOCK_GRC 1 +#define BGE_APE_LOCK_PHY1 2 +#define BGE_APE_LOCK_PHY2 3 +#define BGE_APE_LOCK_MEM 4 +#define BGE_APE_LOCK_PHY3 5 +#define BGE_APE_LOCK_GPIO 7 #define BGE_MEMWIN_READ(pc, tag, x, val) \ do { \ @@ -2273,6 +2385,7 @@ struct bge_ext_rx_bd { #define BGE_RXBDFLAG_IP_CSUM 0x1000 #define BGE_RXBDFLAG_TCP_UDP_CSUM 0x2000 #define BGE_RXBDFLAG_TCP_UDP_IS_TCP 0x4000 +#define BGE_RXBDFLAG_IPV6 0x8000 #define BGE_RXERRFLAG_BAD_CRC 0x0001 #define BGE_RXERRFLAG_COLL_DETECT 0x0002 @@ -2282,6 +2395,7 @@ struct bge_ext_rx_bd { #define BGE_RXERRFLAG_RUNT 0x0020 #define BGE_RXERRFLAG_TRUNC_NO_RSRCS 0x0040 #define BGE_RXERRFLAG_GIANT 0x0080 +#define BGE_RXERRFLAG_IP_CSUM_NOK 0x1000 /* 5717 */ struct bge_sts_idx { #if BYTE_ORDER == LITTLE_ENDIAN @@ -2588,6 +2702,18 @@ struct bge_gib { #define BGE_CLRBIT(sc, reg, x) \ CSR_WRITE_4(sc, reg, (CSR_READ_4(sc, reg) & ~(x))) +/* BAR2 APE register access macros. */ +#define APE_WRITE_4(sc, reg, val) \ + bus_space_write_4(sc->bge_apetag, sc->bge_apehandle, reg, val) + +#define APE_READ_4(sc, reg) \ + bus_space_read_4(sc->bge_apetag, sc->bge_apehandle, reg) + +#define APE_SETBIT(sc, reg, x) \ + APE_WRITE_4(sc, reg, (APE_READ_4(sc, reg) | (x))) +#define APE_CLRBIT(sc, reg, x) \ + APE_WRITE_4(sc, reg, (APE_READ_4(sc, reg) & ~(x))) + #define PCI_SETBIT(pc, tag, reg, x) \ pci_conf_write(pc, tag, reg, (pci_conf_read(pc, tag, reg) | (x))) #define PCI_CLRBIT(pc, tag, reg, x) \ @@ -2641,6 +2767,10 @@ struct bge_ring_data { #define BGE_NTXSEG 31 #endif +#define BGE_STATUS_BLK_SZ sizeof (struct bge_status_block) + +#define BGE_STATS_SZ sizeof (struct bge_stats) + /* * Mbuf pointers. We need these to keep track of the virtual addresses * of our mbuf chains since we can only convert from physical to virtual, @@ -2679,6 +2809,8 @@ struct bge_softc { struct arpcom arpcom; /* interface info */ bus_space_handle_t bge_bhandle; bus_space_tag_t bge_btag; + bus_space_handle_t bge_apehandle; + bus_space_tag_t bge_apetag; void *bge_intrhand; struct pci_attach_args bge_pa; struct mii_data bge_mii; @@ -2716,6 +2848,12 @@ struct bge_softc { #define BGE_CPMU_PRESENT 0x20000000 bus_dma_tag_t bge_dmatag; + u_int32_t bge_mfw_flags; /* Management F/W flags */ +#define BGE_MFW_ON_RXCPU 0x00000001 +#define BGE_MFW_ON_APE 0x00000002 +#define BGE_MFW_TYPE_NCSI 0x00000004 +#define BGE_MFW_TYPE_DASH 0x00000008 + int bge_phy_ape_lock; int bge_phy_addr; u_int32_t bge_chipid; struct bge_ring_data *bge_rdata; /* rings */ |