Ticket #1590: if_bge.update.diff

File if_bge.update.diff, 27.6 KB (added by Adek336, 16 years ago)

update if_bge.c to 1.198.2.9

  • if_bge.

    old new  
    3232 */
    3333
    3434#include <sys/cdefs.h>
    35 __FBSDID("$FreeBSD: src/sys/dev/bge/if_bge.c,v 1.198 2007/09/30 11:05:14 marius Exp $");
     35__FBSDID("$FreeBSD: src/sys/dev/bge/if_bge.c,v 1.198.2.9 2008/06/27 03:24:54 jhb Exp $");
    3636
    3737/*
    3838 * Broadcom BCM570x family gigabit ethernet driver for FreeBSD.
     
    169169    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5715S },
    170170    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5720 },
    171171    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5721 },
     172    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5722 },
    172173    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5750 },
    173174    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5750M },
    174175    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5751 },
     
    195196    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5901 },
    196197    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5901A2 },
    197198    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5903M },
     199    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5906 },
     200    { BCOM_VENDORID,    BCOM_DEVICEID_BCM5906M },
    198201
    199202    { SK_VENDORID,      SK_DEVICEID_ALTIMA },
    200203
     
    205208
    206209static const struct bge_vendor {
    207210    uint16_t    v_id;
    208     const char  *v_name;
     211const char  *v_name;
    209212} bge_vendors[] = {
    210213    { ALTEON_VENDORID,  "Alteon" },
    211214    { ALTIMA_VENDORID,  "Altima" },
     
    219222   
    220223static const struct bge_revision {
    221224    uint32_t    br_chipid;
    222     const char  *br_name;
     225const char  *br_name;
    223226} bge_revisions[] = {
    224227    { BGE_CHIPID_BCM5700_A0,    "BCM5700 A0" },
    225228    { BGE_CHIPID_BCM5700_A1,    "BCM5700 A1" },
     
    267270    { BGE_CHIPID_BCM5755_A0,    "BCM5755 A0" },
    268271    { BGE_CHIPID_BCM5755_A1,    "BCM5755 A1" },
    269272    { BGE_CHIPID_BCM5755_A2,    "BCM5755 A2" },
     273    { BGE_CHIPID_BCM5722_A0,    "BCM5722 A0" },
    270274    /* 5754 and 5787 share the same ASIC ID */
    271275    { BGE_CHIPID_BCM5787_A0,    "BCM5754/5787 A0" },
    272276    { BGE_CHIPID_BCM5787_A1,    "BCM5754/5787 A1" },
    273277    { BGE_CHIPID_BCM5787_A2,    "BCM5754/5787 A2" },
     278    { BGE_CHIPID_BCM5906_A1,    "BCM5906 A1" },
     279    { BGE_CHIPID_BCM5906_A2,    "BCM5906 A2" },
    274280
    275281    { 0, NULL }
    276282};
     
    293299    { BGE_ASICREV_BCM5755,      "unknown BCM5755" },
    294300    /* 5754 and 5787 share the same ASIC ID */
    295301    { BGE_ASICREV_BCM5787,      "unknown BCM5754/5787" },
     302    { BGE_ASICREV_BCM5906,      "unknown BCM5906" },
    296303
    297304    { 0, NULL }
    298305};
     
    305312
    306313const struct bge_revision * bge_lookup_rev(uint32_t);
    307314const struct bge_vendor * bge_lookup_vendor(uint16_t);
     315
     316typedef int (*bge_eaddr_fcn_t)(struct bge_softc *, uint8_t[]);
     317
    308318static int bge_probe(device_t);
    309319static int bge_attach(device_t);
    310320static int bge_detach(device_t);
     
    315325static int bge_dma_alloc(device_t);
    316326static void bge_dma_free(struct bge_softc *);
    317327
     328static int bge_get_eaddr_fw(struct bge_softc *sc, uint8_t ether_addr[]);
     329static int bge_get_eaddr_mem(struct bge_softc *, uint8_t[]);
     330static int bge_get_eaddr_nvram(struct bge_softc *, uint8_t[]);
     331static int bge_get_eaddr_eeprom(struct bge_softc *, uint8_t[]);
     332static int bge_get_eaddr(struct bge_softc *, uint8_t[]);
     333
    318334static void bge_txeof(struct bge_softc *);
    319335static void bge_rxeof(struct bge_softc *);
    320336
     
    337353static int bge_ifmedia_upd(struct ifnet *);
    338354static void bge_ifmedia_sts(struct ifnet *, struct ifmediareq *);
    339355
     356static uint8_t bge_nvram_getbyte(struct bge_softc *, int, uint8_t *);
     357static int bge_read_nvram(struct bge_softc *, caddr_t, int, int);
     358
    340359static uint8_t bge_eeprom_getbyte(struct bge_softc *, int, uint8_t *);
    341360static int bge_read_eeprom(struct bge_softc *, caddr_t, int, int);
    342361
     
    356375static int bge_chipinit(struct bge_softc *);
    357376static int bge_blockinit(struct bge_softc *);
    358377
    359 static int bge_has_eeprom(struct bge_softc *);
     378static int bge_has_eaddr(struct bge_softc *);
    360379static uint32_t bge_readmem_ind(struct bge_softc *, int);
    361380static void bge_writemem_ind(struct bge_softc *, int, int);
     381static void bge_writembx(struct bge_softc *, int, int);
    362382#ifdef notdef
    363383static uint32_t bge_readreg_ind(struct bge_softc *, int);
    364384#endif
     
    425445DRIVER_MODULE(bge, pci, bge_driver, bge_devclass, 0, 0);
    426446DRIVER_MODULE(miibus, bge, miibus_driver, miibus_devclass, 0, 0);
    427447
    428 static int bge_allow_asf = 1;
     448static int bge_allow_asf = 0;
    429449
    430450TUNABLE_INT("hw.bge.allow_asf", &bge_allow_asf);
    431451
     
    440460#define SPARC64_OFW_SUBVENDOR       "subsystem-vendor-id"
    441461
    442462static int
    443 bge_has_eeprom(struct bge_softc *sc)
     463bge_has_eaddr(struct bge_softc *sc)
    444464{
    445465#ifdef __sparc64__
    446466    char buf[sizeof(SPARC64_BLADE_1500_PATH_BGE)];
     
    452472    /*
    453473     * The on-board BGEs found in sun4u machines aren't fitted with
    454474     * an EEPROM which means that we have to obtain the MAC address
    455      * via OFW and that some tests will always fail. We distinguish
     475     * via OFW and that some tests will always fail.  We distinguish
    456476     * such BGEs by the subvendor ID, which also has to be obtained
    457477     * from OFW instead of the PCI configuration space as the latter
    458478     * indicates Broadcom as the subvendor of the netboot interface.
     
    533553    CSR_WRITE_4(sc, off, val);
    534554}
    535555
     556static void
     557bge_writembx(struct bge_softc *sc, int off, int val)
     558{
     559    if (sc->bge_asicrev == BGE_ASICREV_BCM5906)
     560        off += BGE_LPMBX_IRQ0_HI - BGE_MBX_IRQ0_HI;
     561
     562    CSR_WRITE_4(sc, off, val);
     563}
     564
    536565/*
    537566 * Map a single buffer address.
    538567 */
     
    555584    ctx->bge_busaddr = segs->ds_addr;
    556585}
    557586
     587static uint8_t
     588bge_nvram_getbyte(struct bge_softc *sc, int addr, uint8_t *dest)
     589{
     590    uint32_t access, byte = 0;
     591    int i;
     592
     593    /* Lock. */
     594    CSR_WRITE_4(sc, BGE_NVRAM_SWARB, BGE_NVRAMSWARB_SET1);
     595    for (i = 0; i < 8000; i++) {
     596        if (CSR_READ_4(sc, BGE_NVRAM_SWARB) & BGE_NVRAMSWARB_GNT1)
     597            break;
     598        DELAY(20);
     599    }
     600    if (i == 8000)
     601        return (1);
     602
     603    /* Enable access. */
     604    access = CSR_READ_4(sc, BGE_NVRAM_ACCESS);
     605    CSR_WRITE_4(sc, BGE_NVRAM_ACCESS, access | BGE_NVRAMACC_ENABLE);
     606
     607    CSR_WRITE_4(sc, BGE_NVRAM_ADDR, addr & 0xfffffffc);
     608    CSR_WRITE_4(sc, BGE_NVRAM_CMD, BGE_NVRAM_READCMD);
     609    for (i = 0; i < BGE_TIMEOUT * 10; i++) {
     610        DELAY(10);
     611        if (CSR_READ_4(sc, BGE_NVRAM_CMD) & BGE_NVRAMCMD_DONE) {
     612            DELAY(10);
     613            break;
     614        }
     615    }
     616
     617    if (i == BGE_TIMEOUT * 10) {
     618        if_printf(sc->bge_ifp, "nvram read timed out\n");
     619        return (1);
     620    }
     621
     622    /* Get result. */
     623    byte = CSR_READ_4(sc, BGE_NVRAM_RDDATA);
     624
     625    *dest = (bswap32(byte) >> ((addr % 4) * 8)) & 0xFF;
     626
     627    /* Disable access. */
     628    CSR_WRITE_4(sc, BGE_NVRAM_ACCESS, access);
     629
     630    /* Unlock. */
     631    CSR_WRITE_4(sc, BGE_NVRAM_SWARB, BGE_NVRAMSWARB_CLR1);
     632    CSR_READ_4(sc, BGE_NVRAM_SWARB);
     633
     634    return (0);
     635}
     636
     637/*
     638 * Read a sequence of bytes from NVRAM.
     639 */
     640static int
     641bge_read_nvram(struct bge_softc *sc, caddr_t dest, int off, int cnt)
     642{
     643    int err = 0, i;
     644    uint8_t byte = 0;
     645
     646    if (sc->bge_asicrev != BGE_ASICREV_BCM5906)
     647        return (1);
     648
     649    for (i = 0; i < cnt; i++) {
     650        err = bge_nvram_getbyte(sc, off + i, &byte);
     651        if (err)
     652            break;
     653        *(dest + i) = byte;
     654    }
     655
     656    return (err ? 1 : 0);
     657}
     658
    558659/*
    559660 * Read a byte of data stored in the EEPROM at address 'addr.' The
    560661 * BCM570x supports both the traditional bitbang interface and an
     
    659760    }
    660761
    661762    if (i == BGE_TIMEOUT) {
    662         device_printf(sc->bge_dev, "PHY read timed out\n");
     763        device_printf(sc->bge_dev,
     764            "PHY read timed out (phy %d, reg %d, val 0x%08x)\n",
     765            phy, reg, val);
    663766        val = 0;
    664767        goto done;
    665768    }
    666769
     770    DELAY(5);
    667771    val = CSR_READ_4(sc, BGE_MI_COMM);
    668772
    669773done:
     
    687791
    688792    sc = device_get_softc(dev);
    689793
     794    if (sc->bge_asicrev == BGE_ASICREV_BCM5906 &&
     795        (reg == BRGPHY_MII_1000CTL || reg == BRGPHY_MII_AUXCTL))
     796        return(0);
     797
    690798    /* Reading with autopolling on may trigger PCI errors */
    691799    autopoll = CSR_READ_4(sc, BGE_MI_MODE);
    692800    if (autopoll & BGE_MIMODE_AUTOPOLL) {
     
    699807
    700808    for (i = 0; i < BGE_TIMEOUT; i++) {
    701809        DELAY(10);
    702         if (!(CSR_READ_4(sc, BGE_MI_COMM) & BGE_MICOMM_BUSY))
     810        if (!(CSR_READ_4(sc, BGE_MI_COMM) & BGE_MICOMM_BUSY)) {
     811            DELAY(5);
     812            CSR_READ_4(sc, BGE_MI_COMM); /* dummy read */
    703813            break;
     814        }
    704815    }
    705816
    706817    if (i == BGE_TIMEOUT) {
    707         device_printf(sc->bge_dev, "PHY write timed out\n");
     818        device_printf(sc->bge_dev,
     819            "PHY write timed out (phy %d, reg %d, val %d)\n",
     820            phy, reg, val);
    708821        return (0);
    709822    }
    710823
     
    8871000        BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
    8881001
    8891002    sc->bge_std = i - 1;
    890     CSR_WRITE_4(sc, BGE_MBX_RX_STD_PROD_LO, sc->bge_std);
     1003    bge_writembx(sc, BGE_MBX_RX_STD_PROD_LO, sc->bge_std);
    8911004
    8921005    return (0);
    8931006}
     
    9341047                    BGE_RCB_FLAG_USE_EXT_RX_BD);
    9351048    CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags);
    9361049
    937     CSR_WRITE_4(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
     1050    bge_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
    9381051
    9391052    return (0);
    9401053}
     
    9901103
    9911104    /* Initialize transmit producer index for host-memory send ring. */
    9921105    sc->bge_tx_prodidx = 0;
    993     CSR_WRITE_4(sc, BGE_MBX_TX_HOST_PROD0_LO, sc->bge_tx_prodidx);
     1106    bge_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, sc->bge_tx_prodidx);
    9941107
    9951108    /* 5700 b2 errata */
    9961109    if (sc->bge_chiprev == BGE_CHIPREV_5700_BX)
    997         CSR_WRITE_4(sc, BGE_MBX_TX_HOST_PROD0_LO, sc->bge_tx_prodidx);
     1110        bge_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, sc->bge_tx_prodidx);
    9981111
    9991112    /* NIC-memory send ring not used; initialize to zero. */
    1000     CSR_WRITE_4(sc, BGE_MBX_TX_NIC_PROD0_LO, 0);
     1113    bge_writembx(sc, BGE_MBX_TX_NIC_PROD0_LO, 0);
    10011114    /* 5700 b2 errata */
    10021115    if (sc->bge_chiprev == BGE_CHIPREV_5700_BX)
    1003         CSR_WRITE_4(sc, BGE_MBX_TX_NIC_PROD0_LO, 0);
     1116        bge_writembx(sc, BGE_MBX_TX_NIC_PROD0_LO, 0);
    10041117
    10051118    return (0);
    10061119}
     
    11681281    /*
    11691282     * Check the 'ROM failed' bit on the RX CPU to see if
    11701283     * self-tests passed. Skip this check when there's no
    1171      * EEPROM fitted, since in that case it will always
    1172      * fail.
     1284     * chip containing the Ethernet address fitted, since
     1285     * in that case it will always fail.
    11731286     */
    1174     if ((sc->bge_flags & BGE_FLAG_EEPROM) &&
     1287    if ((sc->bge_flags & BGE_FLAG_EADDR) &&
    11751288        CSR_READ_4(sc, BGE_RXCPU_MODE) & BGE_RXCPUMODE_ROMFAIL) {
    11761289        device_printf(sc->bge_dev, "RX CPU self-diagnostics failed!\n");
    11771290        return (ENODEV);
     
    12711384    /* Set the timer prescaler (always 66Mhz) */
    12721385    CSR_WRITE_4(sc, BGE_MISC_CFG, BGE_32BITTIME_66MHZ);
    12731386
     1387    /* XXX: The Linux tg3 driver does this at the start of brgphy_reset. */
     1388    if (sc->bge_asicrev == BGE_ASICREV_BCM5906) {
     1389        DELAY(40);  /* XXX */
     1390
     1391        /* Put PHY into ready state */
     1392        BGE_CLRBIT(sc, BGE_MISC_CFG, BGE_MISCCFG_EPHY_IDDQ);
     1393        CSR_READ_4(sc, BGE_MISC_CFG); /* Flush */
     1394        DELAY(40);
     1395    }
     1396
    12741397    return (0);
    12751398}
    12761399
     
    13081431    }
    13091432
    13101433    /* Configure mbuf pool watermarks */
    1311     if (!(BGE_IS_5705_PLUS(sc))) {
    1312         CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0);
    1313         CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x10);
    1314     } else {
     1434    if (!BGE_IS_5705_PLUS(sc)) {
    13151435        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x50);
    13161436        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x20);
     1437        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x60);
     1438    } else if (sc->bge_asicrev == BGE_ASICREV_BCM5906) {
     1439        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0);
     1440        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x04);
     1441        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x10);
     1442    } else {
     1443        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0);
     1444        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x10);
     1445        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x60);
    13171446    }
    1318     CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x60);
    13191447
    13201448    /* Configure DMA resource watermarks */
    13211449    CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_LOWAT, 5);
     
    14211549     * requirement of all 575x family chips.  The Linux driver sets
    14221550     * the lower threshold for all 5705 family chips as well, but there
    14231551     * are reports that it might not need to be so strict.
     1552     *
     1553     * XXX Linux does some extra fiddling here for the 5906 parts as
     1554     * well.
    14241555     */
    14251556    if (BGE_IS_5705_PLUS(sc))
    14261557        val = 8;
     
    14621593            BGE_RCB_MAXLEN_FLAGS(sc->bge_return_ring_cnt,
    14631594            BGE_RCB_FLAG_RING_DISABLED));
    14641595        RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0);
    1465         CSR_WRITE_4(sc, BGE_MBX_RX_CONS0_LO +
     1596        bge_writembx(sc, BGE_MBX_RX_CONS0_LO +
    14661597            (i * (sizeof(uint64_t))), 0);
    14671598        vrcb += sizeof(struct bge_rcb);
    14681599    }
    14691600
    14701601    /* Initialize RX ring indexes */
    1471     CSR_WRITE_4(sc, BGE_MBX_RX_STD_PROD_LO, 0);
    1472     CSR_WRITE_4(sc, BGE_MBX_RX_JUMBO_PROD_LO, 0);
    1473     CSR_WRITE_4(sc, BGE_MBX_RX_MINI_PROD_LO, 0);
     1602    bge_writembx(sc, BGE_MBX_RX_STD_PROD_LO, 0);
     1603    bge_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, 0);
     1604    bge_writembx(sc, BGE_MBX_RX_MINI_PROD_LO, 0);
    14741605
    14751606    /*
    14761607     * Set up RX return ring 0
     
    16791810const struct bge_revision *
    16801811bge_lookup_rev(uint32_t chipid)
    16811812{
    1682     const struct bge_revision *br;
     1813const struct bge_revision *br;
    16831814
    16841815    for (br = bge_revisions; br->br_name != NULL; br++) {
    16851816        if (br->br_chipid == chipid)
     
    16971828const struct bge_vendor *
    16981829bge_lookup_vendor(uint16_t vid)
    16991830{
    1700     const struct bge_vendor *v;
     1831const struct bge_vendor *v;
    17011832
    17021833    for (v = bge_vendors; v->v_name != NULL; v++)
    17031834        if (v->v_id == vid)
     
    17301861    while(t->bge_vid != 0) {
    17311862        if ((vid == t->bge_vid) && (did == t->bge_did)) {
    17321863            char model[64], buf[96];
    1733             const struct bge_revision *br;
    1734             const struct bge_vendor *v;
     1864const struct bge_revision *br;
     1865const struct bge_vendor *v;
    17351866            uint32_t id;
    17361867
    17371868            id = pci_read_config(dev, BGE_PCI_MISC_CTL, 4) &
     
    17401871            v = bge_lookup_vendor(vid);
    17411872            {
    17421873#if __FreeBSD_version > 700024
    1743                 const char *pname;
     1874const char *pname;
    17441875
    17451876                if (pci_get_vpd_ident(dev, &pname) == 0)
    17461877                    snprintf(model, 64, "%s", pname);
     
    18922023    /*
    18932024     * Allocate the parent bus DMA tag appropriate for PCI.
    18942025     */
    1895     error = bus_dma_tag_create(bus_get_dma_tag(sc->bge_dev), /* parent */
    1896             1, 0,           /* alignment, boundary */
    1897             BUS_SPACE_MAXADDR,  /* lowaddr */
    1898             BUS_SPACE_MAXADDR,  /* highaddr */
    1899             NULL, NULL,     /* filter, filterarg */
    1900             MAXBSIZE, BGE_NSEG_NEW, /* maxsize, nsegments */
    1901             BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
    1902             0,          /* flags */
    1903             NULL, NULL,     /* lockfunc, lockarg */
    1904             &sc->bge_cdata.bge_parent_tag);
     2026    error = bus_dma_tag_create(bus_get_dma_tag(sc->bge_dev),
     2027        1, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
     2028        NULL, BUS_SPACE_MAXSIZE_32BIT, 0, BUS_SPACE_MAXSIZE_32BIT,
     2029        0, NULL, NULL, &sc->bge_cdata.bge_parent_tag);
    19052030
    19062031    if (error != 0) {
    19072032        device_printf(sc->bge_dev,
     
    19102035    }
    19112036
    19122037    /*
    1913      * Create tag for RX mbufs.
     2038     * Create tag for mbufs.
    19142039     */
    19152040    error = bus_dma_tag_create(sc->bge_cdata.bge_parent_tag, 1,
    19162041        0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
     
    22292354{
    22302355    struct ifnet *ifp;
    22312356    struct bge_softc *sc;
    2232     uint32_t hwcfg = 0;
    2233     uint32_t mac_tmp = 0;
     2357    uint32_t hwcfg = 0, misccfg;
    22342358    u_char eaddr[ETHER_ADDR_LEN];
    22352359    int error, reg, rid, trys;
    22362360
     
    22632387    sc->bge_asicrev = BGE_ASICREV(sc->bge_chipid);
    22642388    sc->bge_chiprev = BGE_CHIPREV(sc->bge_chipid);
    22652389
    2266     if (bge_has_eeprom(sc))
    2267         sc->bge_flags |= BGE_FLAG_EEPROM;
     2390    /*
     2391     * Don't enable Ethernet@WireSpeed for the 5700, 5906, or the
     2392     * 5705 A0 and A1 chips.
     2393     */
     2394    if (sc->bge_asicrev != BGE_ASICREV_BCM5700 &&
     2395        sc->bge_asicrev != BGE_ASICREV_BCM5906 &&
     2396        sc->bge_chipid != BGE_CHIPID_BCM5705_A0 &&
     2397        sc->bge_chipid != BGE_CHIPID_BCM5705_A1)
     2398        sc->bge_flags |= BGE_FLAG_WIRESPEED;
     2399
     2400    if (bge_has_eaddr(sc))
     2401        sc->bge_flags |= BGE_FLAG_EADDR;
    22682402
    22692403    /* Save chipset family. */
    22702404    switch (sc->bge_asicrev) {
     
    22832417    case BGE_ASICREV_BCM5752:
    22842418    case BGE_ASICREV_BCM5755:
    22852419    case BGE_ASICREV_BCM5787:
     2420    case BGE_ASICREV_BCM5906:
    22862421        sc->bge_flags |= BGE_FLAG_575X_PLUS;
    22872422        /* FALLTHRU */
    22882423    case BGE_ASICREV_BCM5705:
     
    23022437    if (BGE_IS_5705_PLUS(sc) &&
    23032438        !(sc->bge_flags & BGE_FLAG_ADJUST_TRIM)) {
    23042439        if (sc->bge_asicrev == BGE_ASICREV_BCM5755 ||
    2305             sc->bge_asicrev == BGE_ASICREV_BCM5787)
    2306             sc->bge_flags |= BGE_FLAG_JITTER_BUG;
    2307         else
     2440            sc->bge_asicrev == BGE_ASICREV_BCM5787) {
     2441            if (sc->bge_chipid != BGE_CHIPID_BCM5722_A0)
     2442                sc->bge_flags |= BGE_FLAG_JITTER_BUG;
     2443        } else if (sc->bge_asicrev != BGE_ASICREV_BCM5906)
    23082444            sc->bge_flags |= BGE_FLAG_BER_BUG;
    23092445    }
    23102446
     2447
     2448    /*
     2449     * We could possibly check for BCOM_DEVICEID_BCM5788 in bge_probe()
     2450     * but I do not know the DEVICEID for the 5788M.
     2451     */
     2452    misccfg = CSR_READ_4(sc, BGE_MISC_CFG) & BGE_MISCCFG_BOARD_ID;
     2453    if (misccfg == BGE_MISCCFG_BOARD_ID_5788 ||
     2454        misccfg == BGE_MISCCFG_BOARD_ID_5788M)
     2455        sc->bge_flags |= BGE_FLAG_5788;
     2456
    23112457    /*
    23122458     * Check if this is a PCI-X or PCI Express device.
    23132459     */
     
    24142560        goto fail;
    24152561    }
    24162562
    2417 #ifdef __sparc64__
    2418     if ((sc->bge_flags & BGE_FLAG_EEPROM) == 0)
    2419         OF_getetheraddr(dev, eaddr);
    2420     else
    2421 #endif
    2422     {
    2423         mac_tmp = bge_readmem_ind(sc, 0x0C14);
    2424         if ((mac_tmp >> 16) == 0x484B) {
    2425             eaddr[0] = (u_char)(mac_tmp >> 8);
    2426             eaddr[1] = (u_char)mac_tmp;
    2427             mac_tmp = bge_readmem_ind(sc, 0x0C18);
    2428             eaddr[2] = (u_char)(mac_tmp >> 24);
    2429             eaddr[3] = (u_char)(mac_tmp >> 16);
    2430             eaddr[4] = (u_char)(mac_tmp >> 8);
    2431             eaddr[5] = (u_char)mac_tmp;
    2432         } else if (bge_read_eeprom(sc, eaddr,
    2433             BGE_EE_MAC_OFFSET + 2, ETHER_ADDR_LEN)) {
    2434             device_printf(sc->bge_dev,
    2435                 "failed to read station address\n");
    2436             error = ENXIO;
    2437             goto fail;
    2438         }
     2563    error = bge_get_eaddr(sc, eaddr);
     2564    if (error) {
     2565        device_printf(sc->bge_dev,
     2566            "failed to read station address\n");
     2567        error = ENXIO;
     2568        goto fail;
    24392569    }
    24402570
    24412571    /* 5705 limits RX return ring to 512 entries. */
     
    25072637     */
    25082638    if (bge_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_SIG) == BGE_MAGIC_NUMBER)
    25092639        hwcfg = bge_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_NICCFG);
    2510     else if (sc->bge_flags & BGE_FLAG_EEPROM) {
     2640    else if ((sc->bge_flags & BGE_FLAG_EADDR) &&
     2641        (sc->bge_asicrev != BGE_ASICREV_BCM5906)) {
    25112642        if (bge_read_eeprom(sc, (caddr_t)&hwcfg, BGE_EE_HWCFG_OFFSET,
    25122643            sizeof(hwcfg))) {
    25132644            device_printf(sc->bge_dev, "failed to read EEPROM\n");
     
    26822813bge_reset(struct bge_softc *sc)
    26832814{
    26842815    device_t dev;
    2685     uint32_t cachesize, command, pcistate, reset;
     2816    uint32_t cachesize, command, pcistate, reset, val;
    26862817    void (*write_op)(struct bge_softc *, int, int);
    2687     int i, val = 0;
     2818    int i;
    26882819
    26892820    dev = sc->bge_dev;
    26902821
    2691     if (BGE_IS_575X_PLUS(sc) && !BGE_IS_5714_FAMILY(sc)) {
     2822    if (BGE_IS_575X_PLUS(sc) && !BGE_IS_5714_FAMILY(sc) &&
     2823        (sc->bge_asicrev != BGE_ASICREV_BCM5906)) {
    26922824        if (sc->bge_flags & BGE_FLAG_PCIE)
    26932825            write_op = bge_writemem_direct;
    26942826        else
     
    27442876    /* Issue global reset */
    27452877    write_op(sc, BGE_MISC_CFG, reset);
    27462878
     2879    if (sc->bge_asicrev == BGE_ASICREV_BCM5906) {
     2880        val = CSR_READ_4(sc, BGE_VCPU_STATUS);
     2881        CSR_WRITE_4(sc, BGE_VCPU_STATUS,
     2882            val | BGE_VCPU_STATUS_DRV_RESET);
     2883        val = CSR_READ_4(sc, BGE_VCPU_EXT_CTRL);
     2884        CSR_WRITE_4(sc, BGE_VCPU_EXT_CTRL,
     2885            val & ~BGE_VCPU_EXT_CTRL_HALT_CPU);
     2886    }
     2887
    27472888    DELAY(1000);
    27482889
    27492890    /* XXX: Broadcom Linux driver. */
    27502891    if (sc->bge_flags & BGE_FLAG_PCIE) {
    27512892        if (sc->bge_chipid == BGE_CHIPID_BCM5750_A0) {
    2752             uint32_t v;
    2753 
    27542893            DELAY(500000); /* wait for link training to complete */
    2755             v = pci_read_config(dev, 0xC4, 4);
    2756             pci_write_config(dev, 0xC4, v | (1 << 15), 4);
     2894            val = pci_read_config(dev, 0xC4, 4);
     2895            pci_write_config(dev, 0xC4, val | (1 << 15), 4);
    27572896        }
    27582897        /*
    27592898         * Set PCIE max payload size to 128 bytes and clear error
     
    27722911
    27732912    /* Re-enable MSI, if neccesary, and enable the memory arbiter. */
    27742913    if (BGE_IS_5714_FAMILY(sc)) {
    2775         uint32_t val;
    2776 
    27772914        /* This chip disables MSI on reset. */
    27782915        if (sc->bge_flags & BGE_FLAG_MSI) {
    27792916            val = pci_read_config(dev, BGE_PCI_MSI_CTL, 2);
     
    27882925    } else
    27892926        CSR_WRITE_4(sc, BGE_MARB_MODE, BGE_MARBMODE_ENABLE);
    27902927
    2791     /*
    2792      * Poll until we see the 1's complement of the magic number.
    2793      * This indicates that the firmware initialization is complete.
    2794      * We expect this to fail if no EEPROM is fitted though.
    2795      */
    2796     for (i = 0; i < BGE_TIMEOUT; i++) {
    2797         DELAY(10);
    2798         val = bge_readmem_ind(sc, BGE_SOFTWARE_GENCOMM);
    2799         if (val == ~BGE_MAGIC_NUMBER)
    2800             break;
    2801     }
     2928    if (sc->bge_asicrev == BGE_ASICREV_BCM5906) {
     2929        for (i = 0; i < BGE_TIMEOUT; i++) {
     2930            val = CSR_READ_4(sc, BGE_VCPU_STATUS);
     2931            if (val & BGE_VCPU_STATUS_INIT_DONE)
     2932                break;
     2933            DELAY(100);
     2934        }
     2935        if (i == BGE_TIMEOUT) {
     2936            device_printf(sc->bge_dev, "reset timed out\n");
     2937            return (1);
     2938        }
     2939    } else {
     2940        /*
     2941         * Poll until we see the 1's complement of the magic number.
     2942         * This indicates that the firmware initialization is complete.
     2943         * We expect this to fail if no chip containing the Ethernet
     2944         * address is fitted though.
     2945         */
     2946        for (i = 0; i < BGE_TIMEOUT; i++) {
     2947            DELAY(10);
     2948            val = bge_readmem_ind(sc, BGE_SOFTWARE_GENCOMM);
     2949            if (val == ~BGE_MAGIC_NUMBER)
     2950                break;
     2951        }
    28022952
    2803     if ((sc->bge_flags & BGE_FLAG_EEPROM) && i == BGE_TIMEOUT)
    2804         device_printf(sc->bge_dev, "firmware handshake timed out, "
    2805             "found 0x%08x\n", val);
     2953        if ((sc->bge_flags & BGE_FLAG_EADDR) && i == BGE_TIMEOUT)
     2954            device_printf(sc->bge_dev, "firmware handshake timed out, "
     2955                "found 0x%08x\n", val);
     2956    }
    28062957
    28072958    /*
    28082959     * XXX Wait for the value of the PCISTATE register to
     
    28402991     */
    28412992    if (sc->bge_asicrev == BGE_ASICREV_BCM5704 &&
    28422993        sc->bge_flags & BGE_FLAG_TBI) {
    2843         uint32_t serdescfg;
    2844 
    2845         serdescfg = CSR_READ_4(sc, BGE_SERDES_CFG);
    2846         serdescfg = (serdescfg & ~0xFFF) | 0x880;
    2847         CSR_WRITE_4(sc, BGE_SERDES_CFG, serdescfg);
     2994        val = CSR_READ_4(sc, BGE_SERDES_CFG);
     2995        val = (val & ~0xFFF) | 0x880;
     2996        CSR_WRITE_4(sc, BGE_SERDES_CFG, val);
    28482997    }
    28492998
    28502999    /* XXX: Broadcom Linux driver. */
    28513000    if (sc->bge_flags & BGE_FLAG_PCIE &&
    28523001        sc->bge_chipid != BGE_CHIPID_BCM5750_A0) {
    2853         uint32_t v;
    2854 
    2855         v = CSR_READ_4(sc, 0x7C00);
    2856         CSR_WRITE_4(sc, 0x7C00, v | (1 << 25));
     3002        val = CSR_READ_4(sc, 0x7C00);
     3003        CSR_WRITE_4(sc, 0x7C00, val | (1 << 25));
    28573004    }
    28583005    DELAY(10000);
    28593006
     
    30223169        bus_dmamap_sync(sc->bge_cdata.bge_rx_jumbo_ring_tag,
    30233170            sc->bge_cdata.bge_rx_jumbo_ring_map, BUS_DMASYNC_PREWRITE);
    30243171
    3025     CSR_WRITE_4(sc, BGE_MBX_RX_CONS0_LO, sc->bge_rx_saved_considx);
     3172    bge_writembx(sc, BGE_MBX_RX_CONS0_LO, sc->bge_rx_saved_considx);
    30263173    if (stdcnt)
    3027         CSR_WRITE_4(sc, BGE_MBX_RX_STD_PROD_LO, sc->bge_std);
     3174        bge_writembx(sc, BGE_MBX_RX_STD_PROD_LO, sc->bge_std);
    30283175    if (jumbocnt)
    3029         CSR_WRITE_4(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
     3176        bge_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
    30303177#ifdef notyet
    30313178    /*
    30323179     * This register wraps very quickly under heavy packet drops.
     
    31683315     * the status check).  So toggling would probably be a pessimization
    31693316     * even with MSI.  It would only be needed for using a task queue.
    31703317     */
    3171     CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 0);
     3318    bge_writembx(sc, BGE_MBX_IRQ0_LO, 0);
    31723319
    31733320    /*
    31743321     * Do the mandatory PCI flush as well as get the link status.
     
    32553402#endif
    32563403        {
    32573404        sc->bge_link_evt++;
    3258         BGE_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET);
     3405        if (sc->bge_asicrev == BGE_ASICREV_BCM5700 ||
     3406            sc->bge_flags & BGE_FLAG_5788)
     3407            BGE_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET);
     3408        else
     3409            BGE_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW);
    32593410        }
    32603411    }
    32613412
     
    33903541    error = bus_dmamap_load_mbuf_sg(sc->bge_cdata.bge_mtag, map, m, segs,
    33913542        &nsegs, BUS_DMA_NOWAIT);
    33923543    if (error == EFBIG) {
    3393         m = m_defrag(m, M_DONTWAIT);
     3544        m = m_collapse(m, M_DONTWAIT, BGE_NSEG_NEW);
    33943545        if (m == NULL) {
    33953546            m_freem(*m_head);
    33963547            *m_head = NULL;
     
    35453696        return;
    35463697
    35473698    /* Transmit. */
    3548     CSR_WRITE_4(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
     3699    bge_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
    35493700    /* 5700 b2 errata */
    35503701    if (sc->bge_chiprev == BGE_CHIPREV_5700_BX)
    3551         CSR_WRITE_4(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
     3702        bge_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
    35523703
    35533704    sc->bge_tx_prodidx = prodidx;
    35543705
     
    36753826    if (ifp->if_capenable & IFCAP_POLLING) {
    36763827        BGE_SETBIT(sc, BGE_PCI_MISC_CTL,
    36773828            BGE_PCIMISCCTL_MASK_PCI_INTR);
    3678         CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 1);
     3829        bge_writembx(sc, BGE_MBX_IRQ0_LO, 1);
    36793830    } else
    36803831#endif
    36813832
     
    36833834    {
    36843835    BGE_SETBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_CLEAR_INTA);
    36853836    BGE_CLRBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_MASK_PCI_INTR);
    3686     CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 0);
     3837    bge_writembx(sc, BGE_MBX_IRQ0_LO, 0);
    36873838    }
    36883839   
    36893840    bge_ifmedia_upd_locked(ifp);
     
    37833934    }
    37843935    mii_mediachg(mii);
    37853936
     3937    /*
     3938     * Force an interrupt so that we will call bge_link_upd
     3939     * if needed and clear any pending link state attention.
     3940     * Without this we are not getting any further interrupts
     3941     * for link state changes and thus will not UP the link and
     3942     * not be able to send in bge_start_locked. The only
     3943     * way to get things working was to receive a packet and
     3944     * get an RX intr.
     3945     * bge_tick should help for fiber cards and we might not
     3946     * need to do this here if BGE_FLAG_TBI is set but as
     3947     * we poll for fiber anyway it should not harm.
     3948     */
     3949    if (sc->bge_asicrev == BGE_ASICREV_BCM5700 ||
     3950        sc->bge_flags & BGE_FLAG_5788)
     3951        BGE_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET);
     3952    else
     3953        BGE_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW);
     3954
    37863955    return (0);
    37873956}
    37883957
     
    39064075                BGE_LOCK(sc);
    39074076                BGE_SETBIT(sc, BGE_PCI_MISC_CTL,
    39084077                    BGE_PCIMISCCTL_MASK_PCI_INTR);
    3909                 CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 1);
     4078                bge_writembx(sc, BGE_MBX_IRQ0_LO, 1);
    39104079                ifp->if_capenable |= IFCAP_POLLING;
    39114080                BGE_UNLOCK(sc);
    39124081            } else {
     
    39154084                BGE_LOCK(sc);
    39164085                BGE_CLRBIT(sc, BGE_PCI_MISC_CTL,
    39174086                    BGE_PCIMISCCTL_MASK_PCI_INTR);
    3918                 CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 0);
     4087                bge_writembx(sc, BGE_MBX_IRQ0_LO, 0);
    39194088                ifp->if_capenable &= ~IFCAP_POLLING;
    39204089                BGE_UNLOCK(sc);
    39214090            }
     
    40404209
    40414210    /* Disable host interrupts. */
    40424211    BGE_SETBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_MASK_PCI_INTR);
    4043     CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 1);
     4212    bge_writembx(sc, BGE_MBX_IRQ0_LO, 1);
    40444213
    40454214    /*
    40464215     * Tell firmware we're shutting down.
     
    42954464
    42964465#endif
    42974466
     4467    if (BGE_IS_5705_PLUS(sc))
     4468        return;
     4469
    42984470    tree = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", CTLFLAG_RD,
    42994471        NULL, "BGE Statistics");
    43004472    schildren = children = SYSCTL_CHILDREN(tree);
     
    44174589{
    44184590    struct bge_softc *sc;
    44194591    uint32_t result;
    4420     int base, offset;
     4592    int offset;
    44214593
    44224594    sc = (struct bge_softc *)arg1;
    44234595    offset = arg2;
    4424     if (BGE_IS_5705_PLUS(sc))
    4425         base = BGE_MAC_STATS;
    4426     else
    4427         base = BGE_MEMWIN_START + BGE_STATS_BLOCK;
    4428     result = CSR_READ_4(sc, base + offset + offsetof(bge_hostaddr,
    4429         bge_addr_lo));
     4596    result = CSR_READ_4(sc, BGE_MEMWIN_START + BGE_STATS_BLOCK + offset +
     4597        offsetof(bge_hostaddr, bge_addr_lo));
    44304598    return (sysctl_handle_int(oidp, &result, 0, req));
    44314599}
    44324600
     
    45374705    return (error);
    45384706}
    45394707#endif
     4708
     4709static int
     4710bge_get_eaddr_fw(struct bge_softc *sc, uint8_t ether_addr[])
     4711{
     4712
     4713    if (sc->bge_flags & BGE_FLAG_EADDR)
     4714        return (1);
     4715
     4716#ifdef __sparc64__
     4717    OF_getetheraddr(sc->bge_dev, ether_addr);
     4718    return (0);
     4719#endif
     4720    return (1);
     4721}
     4722
     4723static int
     4724bge_get_eaddr_mem(struct bge_softc *sc, uint8_t ether_addr[])
     4725{
     4726    uint32_t mac_addr;
     4727
     4728    mac_addr = bge_readmem_ind(sc, 0x0c14);
     4729    if ((mac_addr >> 16) == 0x484b) {
     4730        ether_addr[0] = (uint8_t)(mac_addr >> 8);
     4731        ether_addr[1] = (uint8_t)mac_addr;
     4732        mac_addr = bge_readmem_ind(sc, 0x0c18);
     4733        ether_addr[2] = (uint8_t)(mac_addr >> 24);
     4734        ether_addr[3] = (uint8_t)(mac_addr >> 16);
     4735        ether_addr[4] = (uint8_t)(mac_addr >> 8);
     4736        ether_addr[5] = (uint8_t)mac_addr;
     4737        return (0);
     4738    }
     4739    return (1);
     4740}
     4741
     4742static int
     4743bge_get_eaddr_nvram(struct bge_softc *sc, uint8_t ether_addr[])
     4744{
     4745    int mac_offset = BGE_EE_MAC_OFFSET;
     4746
     4747    if (sc->bge_asicrev == BGE_ASICREV_BCM5906)
     4748        mac_offset = BGE_EE_MAC_OFFSET_5906;
     4749
     4750    return (bge_read_nvram(sc, ether_addr, mac_offset + 2,
     4751        ETHER_ADDR_LEN));
     4752}
     4753
     4754static int
     4755bge_get_eaddr_eeprom(struct bge_softc *sc, uint8_t ether_addr[])
     4756{
     4757
     4758    if (sc->bge_asicrev == BGE_ASICREV_BCM5906)
     4759        return (1);
     4760
     4761    return (bge_read_eeprom(sc, ether_addr, BGE_EE_MAC_OFFSET + 2,
     4762       ETHER_ADDR_LEN));
     4763}
     4764
     4765static int
     4766bge_get_eaddr(struct bge_softc *sc, uint8_t eaddr[])
     4767{
     4768static const bge_eaddr_fcn_t bge_eaddr_funcs[] = {
     4769        /* NOTE: Order is critical */
     4770        bge_get_eaddr_fw,
     4771        bge_get_eaddr_mem,
     4772        bge_get_eaddr_nvram,
     4773        bge_get_eaddr_eeprom,
     4774        NULL
     4775    };
     4776const bge_eaddr_fcn_t *func;
     4777
     4778    for (func = bge_eaddr_funcs; *func != NULL; ++func) {
     4779        if ((*func)(sc, eaddr) == 0)
     4780            break;
     4781    }
     4782    return (*func == NULL ? ENXIO : 0);
     4783}