Ticket #1590: broadcom-patch.diff

File broadcom-patch.diff, 41.9 KB (added by Adek336, 16 years ago)

works, needs minor changes

  • build/jam/HaikuImage

     
    136136    $(X86_ONLY)via_rhine wb840 $(X86_ONLY)ipro100 $(X86_ONLY)nforce
    137137    #vlance
    138138    $(X86_ONLY)marvell_yukon $(X86_ONLY)syskonnect usb_ecm
    139     $(GPL_ONLY)bcm440x $(GPL_ONLY)bcm570x
     139    $(GPL_ONLY)bcm440x $(GPL_ONLY)bcm570x broadcom_bcm570x
    140140;
    141141#BEOS_ADD_ONS_DRIVERS_ACPI = $(X86_ONLY)acpi_button ;
    142142BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)ps2 $(X86_ONLY)isa ide scsi
  • src/add-ons/kernel/drivers/network/broadcom_bcm570x/dev/bge/if_bgereg.h

     
    3030 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
    3131 * THE POSSIBILITY OF SUCH DAMAGE.
    3232 *
    33  * $FreeBSD: src/sys/dev/bge/if_bgereg.h,v 1.73 2007/05/22 19:22:58 jkim Exp $
     33 * $FreeBSD: src/sys/dev/bge/if_bgereg.h,v 1.73.2.4 2008/06/27 03:24:54 jhb Exp $
    3434 */
    3535
    3636/*
     
    277277#define BGE_CHIPID_BCM5755_A0       0xa0000000
    278278#define BGE_CHIPID_BCM5755_A1       0xa0010000
    279279#define BGE_CHIPID_BCM5755_A2       0xa0020000
     280#define BGE_CHIPID_BCM5722_A0           0xa2000000
    280281#define BGE_CHIPID_BCM5754_A0       0xb0000000
    281282#define BGE_CHIPID_BCM5754_A1       0xb0010000
    282283#define BGE_CHIPID_BCM5754_A2       0xb0020000
    283284#define BGE_CHIPID_BCM5787_A0       0xb0000000
    284285#define BGE_CHIPID_BCM5787_A1       0xb0010000
    285286#define BGE_CHIPID_BCM5787_A2       0xb0020000
     287#define BGE_CHIPID_BCM5906_A1           0xc0010000
     288#define BGE_CHIPID_BCM5906_A2           0xc0020000
    286289
    287290/* shorthand one */
    288291#define BGE_ASICREV(x)          ((x) >> 28)
     
    299302#define BGE_ASICREV_BCM5755     0x0a
    300303#define BGE_ASICREV_BCM5754     0x0b
    301304#define BGE_ASICREV_BCM5787     0x0b
     305#define BGE_ASICREV_BCM5906             0x0c
    302306
    303307/* chip revisions */
    304308#define BGE_CHIPREV(x)          ((x) >> 24)
     
    14381442#define BGE_RXCPUSTAT_MA_REQ_FIFOOFLOW  0x40000000
    14391443#define BGE_RXCPUSTAT_BLOCKING_READ 0x80000000
    14401444
     1445/*
     1446 * V? CPU registers
     1447 */
     1448#define BGE_VCPU_STATUS                 0x5100
     1449#define BGE_VCPU_EXT_CTRL               0x6890
    14411450
     1451#define BGE_VCPU_STATUS_INIT_DONE       0x04000000
     1452#define BGE_VCPU_STATUS_DRV_RESET       0x08000000
     1453
     1454#define BGE_VCPU_EXT_CTRL_HALT_CPU      0x00400000
     1455#define BGE_VCPU_EXT_CTRL_DISABLE_WOL   0x20000000
     1456
    14421457/*
    14431458 * TX CPU registers
    14441459 */
     
    16841699#define BGE_EE_DELAY            0x6848
    16851700#define BGE_FASTBOOT_PC         0x6894
    16861701
     1702/*
     1703 * NVRAM Control registers
     1704 */
     1705#define BGE_NVRAM_CMD                   0x7000
     1706#define BGE_NVRAM_STAT                  0x7004
     1707#define BGE_NVRAM_WRDATA                0x7008
     1708#define BGE_NVRAM_ADDR                  0x700c
     1709#define BGE_NVRAM_RDDATA                0x7010
     1710#define BGE_NVRAM_CFG1                  0x7014
     1711#define BGE_NVRAM_CFG2                  0x7018
     1712#define BGE_NVRAM_CFG3                  0x701c
     1713#define BGE_NVRAM_SWARB                 0x7020
     1714#define BGE_NVRAM_ACCESS                0x7024
     1715#define BGE_NVRAM_WRITE1                0x7028
     1716
     1717#define BGE_NVRAMCMD_RESET              0x00000001
     1718#define BGE_NVRAMCMD_DONE               0x00000008
     1719#define BGE_NVRAMCMD_START              0x00000010
     1720#define BGE_NVRAMCMD_WR                 0x00000020 /* 1 = wr, 0 = rd */
     1721#define BGE_NVRAMCMD_ERASE              0x00000040
     1722#define BGE_NVRAMCMD_FIRST              0x00000080
     1723#define BGE_NVRAMCMD_LAST               0x00000100
     1724
     1725#define BGE_NVRAM_READCMD \
     1726        (BGE_NVRAMCMD_FIRST|BGE_NVRAMCMD_LAST| \
     1727        BGE_NVRAMCMD_START|BGE_NVRAMCMD_DONE)
     1728#define BGE_NVRAM_WRITECMD \
     1729        (BGE_NVRAMCMD_FIRST|BGE_NVRAMCMD_LAST| \
     1730        BGE_NVRAMCMD_START|BGE_NVRAMCMD_DONE|BGE_NVRAMCMD_WR)
     1731
     1732#define BGE_NVRAMSWARB_SET0             0x00000001
     1733#define BGE_NVRAMSWARB_SET1             0x00000002
     1734#define BGE_NVRAMSWARB_SET2             0x00000003
     1735#define BGE_NVRAMSWARB_SET3             0x00000004
     1736#define BGE_NVRAMSWARB_CLR0             0x00000010
     1737#define BGE_NVRAMSWARB_CLR1             0x00000020
     1738#define BGE_NVRAMSWARB_CLR2             0x00000040
     1739#define BGE_NVRAMSWARB_CLR3             0x00000080
     1740#define BGE_NVRAMSWARB_GNT0             0x00000100
     1741#define BGE_NVRAMSWARB_GNT1             0x00000200
     1742#define BGE_NVRAMSWARB_GNT2             0x00000400
     1743#define BGE_NVRAMSWARB_GNT3             0x00000800
     1744#define BGE_NVRAMSWARB_REQ0             0x00001000
     1745#define BGE_NVRAMSWARB_REQ1             0x00002000
     1746#define BGE_NVRAMSWARB_REQ2             0x00004000
     1747#define BGE_NVRAMSWARB_REQ3             0x00008000
     1748
     1749#define BGE_NVRAMACC_ENABLE             0x00000001
     1750#define BGE_NVRAMACC_WRENABLE           0x00000002
     1751
    16871752/* Mode control register */
    16881753#define BGE_MODECTL_INT_SNDCOAL_ONLY    0x00000001
    16891754#define BGE_MODECTL_BYTESWAP_NONFRAME   0x00000002
     
    17111776/* Misc. config register */
    17121777#define BGE_MISCCFG_RESET_CORE_CLOCKS   0x00000001
    17131778#define BGE_MISCCFG_TIMER_PRESCALER 0x000000FE
     1779#define BGE_MISCCFG_BOARD_ID            0x0001E000
     1780#define BGE_MISCCFG_BOARD_ID_5788       0x00010000
     1781#define BGE_MISCCFG_BOARD_ID_5788M      0x00018000
     1782#define BGE_MISCCFG_EPHY_IDDQ           0x00200000
    17141783
    17151784#define BGE_32BITTIME_66MHZ     (0x41 << 1)
    17161785
     
    20112080#define BCOM_DEVICEID_BCM5715S      0x1679
    20122081#define BCOM_DEVICEID_BCM5720       0x1658
    20132082#define BCOM_DEVICEID_BCM5721       0x1659
     2083#define BCOM_DEVICEID_BCM5722           0x165A
    20142084#define BCOM_DEVICEID_BCM5750       0x1676
    20152085#define BCOM_DEVICEID_BCM5750M      0x167C
    20162086#define BCOM_DEVICEID_BCM5751       0x1677
     
    20372107#define BCOM_DEVICEID_BCM5901       0x170D
    20382108#define BCOM_DEVICEID_BCM5901A2     0x170E
    20392109#define BCOM_DEVICEID_BCM5903M      0x16FF
     2110#define BCOM_DEVICEID_BCM5906           0x1712
     2111#define BCOM_DEVICEID_BCM5906M          0x1713
    20402112
    20412113/*
    20422114 * Alteon AceNIC PCI vendor/device ID.
     
    20902162 * Offset of MAC address inside EEPROM.
    20912163 */
    20922164#define BGE_EE_MAC_OFFSET       0x7C
     2165#define BGE_EE_MAC_OFFSET_5906          0x10
    20932166#define BGE_EE_HWCFG_OFFSET     0xC8
    20942167
    20952168#define BGE_HWCFG_VOLTAGE       0x00000003
     
    24582531    uint32_t        bge_flags;
    24592532#define BGE_FLAG_TBI        0x00000001
    24602533#define BGE_FLAG_JUMBO      0x00000002
    2461 #define BGE_FLAG_EEPROM     0x00000004
     2534#define BGE_FLAG_WIRESPEED      0x00000004
     2535#define BGE_FLAG_EADDR          0x00000008
    24622536#define BGE_FLAG_MSI        0x00000100
    24632537#define BGE_FLAG_PCIX       0x00000200
    24642538#define BGE_FLAG_PCIE       0x00000400
     
    24742548#define BGE_FLAG_BER_BUG    0x02000000
    24752549#define BGE_FLAG_ADJUST_TRIM    0x04000000
    24762550#define BGE_FLAG_CRC_BUG    0x08000000
     2551#define BGE_FLAG_5788           0x20000000
    24772552    uint32_t        bge_chipid;
    24782553    uint8_t         bge_asicrev;
    24792554    uint8_t         bge_chiprev;
     
    25062581#ifdef DEVICE_POLLING
    25072582    int         rxcycles;
    25082583#endif /* DEVICE_POLLING */
     2584    u_int32_t   bge_intr_status;
     2585    int         transmitting;
    25092586};
    25102587
    25112588#define BGE_LOCK_INIT(_sc, _name) \
     
    25142591#define BGE_LOCK_ASSERT(_sc)    mtx_assert(&(_sc)->bge_mtx, MA_OWNED)
    25152592#define BGE_UNLOCK(_sc)     mtx_unlock(&(_sc)->bge_mtx)
    25162593#define BGE_LOCK_DESTROY(_sc)   mtx_destroy(&(_sc)->bge_mtx)
     2594
  • src/add-ons/kernel/drivers/network/broadcom_bcm570x/dev/bge/if_bge.c

     
    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);
     381//bge_writembx() used in glue.c
     382void bge_writembx(struct bge_softc *, int, int);
    362383#ifdef notdef
    363384static uint32_t bge_readreg_ind(struct bge_softc *, int);
    364385#endif
     
    378399static void bge_sig_legacy(struct bge_softc *, int);
    379400static void bge_sig_pre_reset(struct bge_softc *, int);
    380401static int bge_reset(struct bge_softc *);
    381 static void bge_link_upd(struct bge_softc *);
     402/*static*/ void bge_link_upd(struct bge_softc *);
    382403
    383404/*
    384405 * The BGE_REGISTER_DEBUG option is only for low-level debugging.  It may
     
    425446DRIVER_MODULE(bge, pci, bge_driver, bge_devclass, 0, 0);
    426447DRIVER_MODULE(miibus, bge, miibus_driver, miibus_devclass, 0, 0);
    427448
    428 static int bge_allow_asf = 1;
     449static int bge_allow_asf = 0;
    429450
    430451TUNABLE_INT("hw.bge.allow_asf", &bge_allow_asf);
    431452
     
    440461#define SPARC64_OFW_SUBVENDOR       "subsystem-vendor-id"
    441462
    442463static int
    443 bge_has_eeprom(struct bge_softc *sc)
     464bge_has_eaddr(struct bge_softc *sc)
    444465{
    445466#ifdef __sparc64__
    446467    char buf[sizeof(SPARC64_BLADE_1500_PATH_BGE)];
     
    533554    CSR_WRITE_4(sc, off, val);
    534555}
    535556
     557void
     558bge_writembx(struct bge_softc *sc, int off, int val)
     559{
     560    if (sc->bge_asicrev == BGE_ASICREV_BCM5906)
     561        off += BGE_LPMBX_IRQ0_HI - BGE_MBX_IRQ0_HI;
     562
     563    CSR_WRITE_4(sc, off, val);
     564}
     565
    536566/*
    537567 * Map a single buffer address.
    538568 */
     
    555585    ctx->bge_busaddr = segs->ds_addr;
    556586}
    557587
     588static uint8_t
     589bge_nvram_getbyte(struct bge_softc *sc, int addr, uint8_t *dest)
     590{
     591    uint32_t access, byte = 0;
     592    int i;
     593
     594    /* Lock. */
     595    CSR_WRITE_4(sc, BGE_NVRAM_SWARB, BGE_NVRAMSWARB_SET1);
     596    for (i = 0; i < 8000; i++) {
     597        if (CSR_READ_4(sc, BGE_NVRAM_SWARB) & BGE_NVRAMSWARB_GNT1)
     598            break;
     599        DELAY(20);
     600    }
     601    if (i == 8000)
     602        return (1);
     603
     604    /* Enable access. */
     605    access = CSR_READ_4(sc, BGE_NVRAM_ACCESS);
     606    CSR_WRITE_4(sc, BGE_NVRAM_ACCESS, access | BGE_NVRAMACC_ENABLE);
     607
     608    CSR_WRITE_4(sc, BGE_NVRAM_ADDR, addr & 0xfffffffc);
     609    CSR_WRITE_4(sc, BGE_NVRAM_CMD, BGE_NVRAM_READCMD);
     610    for (i = 0; i < BGE_TIMEOUT * 10; i++) {
     611        DELAY(10);
     612        if (CSR_READ_4(sc, BGE_NVRAM_CMD) & BGE_NVRAMCMD_DONE) {
     613            DELAY(10);
     614            break;
     615        }
     616    }
     617
     618    if (i == BGE_TIMEOUT * 10) {
     619        if_printf(sc->bge_ifp, "nvram read timed out\n");
     620        return (1);
     621    }
     622
     623    /* Get result. */
     624    byte = CSR_READ_4(sc, BGE_NVRAM_RDDATA);
     625
     626    *dest = (bswap32(byte) >> ((addr % 4) * 8)) & 0xFF;
     627
     628    /* Disable access. */
     629    CSR_WRITE_4(sc, BGE_NVRAM_ACCESS, access);
     630
     631    /* Unlock. */
     632    CSR_WRITE_4(sc, BGE_NVRAM_SWARB, BGE_NVRAMSWARB_CLR1);
     633    CSR_READ_4(sc, BGE_NVRAM_SWARB);
     634
     635    return (0);
     636}
     637
    558638/*
     639 * Read a sequence of bytes from NVRAM.
     640 */
     641static int
     642bge_read_nvram(struct bge_softc *sc, caddr_t dest, int off, int cnt)
     643{
     644    int err = 0, i;
     645    uint8_t byte = 0;
     646
     647    if (sc->bge_asicrev != BGE_ASICREV_BCM5906)
     648        return (1);
     649
     650    for (i = 0; i < cnt; i++) {
     651        err = bge_nvram_getbyte(sc, off + i, &byte);
     652        if (err)
     653            break;
     654        *(dest + i) = byte;
     655    }
     656
     657    return (err ? 1 : 0);
     658}
     659
     660/*
    559661 * Read a byte of data stored in the EEPROM at address 'addr.' The
    560662 * BCM570x supports both the traditional bitbang interface and an
    561663 * auto access interface for reading the EEPROM. We use the auto
     
    659761    }
    660762
    661763    if (i == BGE_TIMEOUT) {
    662         device_printf(sc->bge_dev, "PHY read timed out\n");
     764        device_printf(sc->bge_dev,
     765            "PHY read timed out (phy %d, reg %d, val 0x%08x)\n",
     766            phy, reg, val);
    663767        val = 0;
    664768        goto done;
    665769    }
    666770
     771    DELAY(5);
    667772    val = CSR_READ_4(sc, BGE_MI_COMM);
    668773
    669774done:
     
    687792
    688793    sc = device_get_softc(dev);
    689794
     795    if (sc->bge_asicrev == BGE_ASICREV_BCM5906 &&
     796        (reg == BRGPHY_MII_1000CTL || reg == BRGPHY_MII_AUXCTL))
     797        return(0);
     798
    690799    /* Reading with autopolling on may trigger PCI errors */
    691800    autopoll = CSR_READ_4(sc, BGE_MI_MODE);
    692801    if (autopoll & BGE_MIMODE_AUTOPOLL) {
     
    699808
    700809    for (i = 0; i < BGE_TIMEOUT; i++) {
    701810        DELAY(10);
    702         if (!(CSR_READ_4(sc, BGE_MI_COMM) & BGE_MICOMM_BUSY))
     811        if (!(CSR_READ_4(sc, BGE_MI_COMM) & BGE_MICOMM_BUSY)) {
     812            DELAY(5);
     813            CSR_READ_4(sc, BGE_MI_COMM); /* dummy read */
    703814            break;
    704815    }
     816    }
    705817
    706818    if (i == BGE_TIMEOUT) {
    707         device_printf(sc->bge_dev, "PHY write timed out\n");
     819        device_printf(sc->bge_dev,
     820            "PHY write timed out (phy %d, reg %d, val %d)\n",
     821            phy, reg, val);
    708822        return (0);
    709823    }
    710824
     
    8871001        BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
    8881002
    8891003    sc->bge_std = i - 1;
    890     CSR_WRITE_4(sc, BGE_MBX_RX_STD_PROD_LO, sc->bge_std);
     1004    bge_writembx(sc, BGE_MBX_RX_STD_PROD_LO, sc->bge_std);
    8911005
    8921006    return (0);
    8931007}
     
    9341048                    BGE_RCB_FLAG_USE_EXT_RX_BD);
    9351049    CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags);
    9361050
    937     CSR_WRITE_4(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
     1051    bge_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
    9381052
    9391053    return (0);
    9401054}
     
    9901104
    9911105    /* Initialize transmit producer index for host-memory send ring. */
    9921106    sc->bge_tx_prodidx = 0;
    993     CSR_WRITE_4(sc, BGE_MBX_TX_HOST_PROD0_LO, sc->bge_tx_prodidx);
     1107    bge_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, sc->bge_tx_prodidx);
    9941108
    9951109    /* 5700 b2 errata */
    9961110    if (sc->bge_chiprev == BGE_CHIPREV_5700_BX)
    997         CSR_WRITE_4(sc, BGE_MBX_TX_HOST_PROD0_LO, sc->bge_tx_prodidx);
     1111        bge_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, sc->bge_tx_prodidx);
    9981112
    9991113    /* NIC-memory send ring not used; initialize to zero. */
    1000     CSR_WRITE_4(sc, BGE_MBX_TX_NIC_PROD0_LO, 0);
     1114    bge_writembx(sc, BGE_MBX_TX_NIC_PROD0_LO, 0);
    10011115    /* 5700 b2 errata */
    10021116    if (sc->bge_chiprev == BGE_CHIPREV_5700_BX)
    1003         CSR_WRITE_4(sc, BGE_MBX_TX_NIC_PROD0_LO, 0);
     1117        bge_writembx(sc, BGE_MBX_TX_NIC_PROD0_LO, 0);
    10041118
    10051119    return (0);
    10061120}
     
    11681282    /*
    11691283     * Check the 'ROM failed' bit on the RX CPU to see if
    11701284     * self-tests passed. Skip this check when there's no
    1171      * EEPROM fitted, since in that case it will always
    1172      * fail.
     1285     * chip containing the Ethernet address fitted, since
     1286     * in that case it will always fail.
    11731287     */
    1174     if ((sc->bge_flags & BGE_FLAG_EEPROM) &&
     1288    if ((sc->bge_flags & BGE_FLAG_EADDR) &&
    11751289        CSR_READ_4(sc, BGE_RXCPU_MODE) & BGE_RXCPUMODE_ROMFAIL) {
    11761290        device_printf(sc->bge_dev, "RX CPU self-diagnostics failed!\n");
    11771291        return (ENODEV);
     
    12711385    /* Set the timer prescaler (always 66Mhz) */
    12721386    CSR_WRITE_4(sc, BGE_MISC_CFG, BGE_32BITTIME_66MHZ);
    12731387
     1388    /* XXX: The Linux tg3 driver does this at the start of brgphy_reset. */
     1389    if (sc->bge_asicrev == BGE_ASICREV_BCM5906) {
     1390        DELAY(40);  /* XXX */
     1391
     1392        /* Put PHY into ready state */
     1393        BGE_CLRBIT(sc, BGE_MISC_CFG, BGE_MISCCFG_EPHY_IDDQ);
     1394        CSR_READ_4(sc, BGE_MISC_CFG); /* Flush */
     1395        DELAY(40);
     1396    }
     1397
    12741398    return (0);
    12751399}
    12761400
     
    13081432    }
    13091433
    13101434    /* Configure mbuf pool watermarks */
    1311     if (!(BGE_IS_5705_PLUS(sc))) {
     1435    if (!BGE_IS_5705_PLUS(sc)) {
     1436        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x50);
     1437        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x20);
     1438        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x60);
     1439    } else if (sc->bge_asicrev == BGE_ASICREV_BCM5906) {
    13121440        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0);
     1441        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x04);
     1442        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x10);
     1443    } else {
     1444        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x0);
    13131445        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x10);
    1314     } else {
    1315         CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_READDMA_LOWAT, 0x50);
    1316         CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_MACRX_LOWAT, 0x20);
     1446        CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x60);
    13171447    }
    1318     CSR_WRITE_4(sc, BGE_BMAN_MBUFPOOL_HIWAT, 0x60);
    13191448
    13201449    /* Configure DMA resource watermarks */
    13211450    CSR_WRITE_4(sc, BGE_BMAN_DMA_DESCPOOL_LOWAT, 5);
     
    14211550     * requirement of all 575x family chips.  The Linux driver sets
    14221551     * the lower threshold for all 5705 family chips as well, but there
    14231552     * are reports that it might not need to be so strict.
     1553     *
     1554     * XXX Linux does some extra fiddling here for the 5906 parts as
     1555     * well.
    14241556     */
    14251557    if (BGE_IS_5705_PLUS(sc))
    14261558        val = 8;
     
    14621594            BGE_RCB_MAXLEN_FLAGS(sc->bge_return_ring_cnt,
    14631595            BGE_RCB_FLAG_RING_DISABLED));
    14641596        RCB_WRITE_4(sc, vrcb, bge_nicaddr, 0);
    1465         CSR_WRITE_4(sc, BGE_MBX_RX_CONS0_LO +
     1597        bge_writembx(sc, BGE_MBX_RX_CONS0_LO +
    14661598            (i * (sizeof(uint64_t))), 0);
    14671599        vrcb += sizeof(struct bge_rcb);
    14681600    }
    14691601
    14701602    /* 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);
     1603    bge_writembx(sc, BGE_MBX_RX_STD_PROD_LO, 0);
     1604    bge_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, 0);
     1605    bge_writembx(sc, BGE_MBX_RX_MINI_PROD_LO, 0);
    14741606
    14751607    /*
    14761608     * Set up RX return ring 0
     
    16791811const struct bge_revision *
    16801812bge_lookup_rev(uint32_t chipid)
    16811813{
    1682     const struct bge_revision *br;
     1814const struct bge_revision *br;
    16831815
    16841816    for (br = bge_revisions; br->br_name != NULL; br++) {
    16851817        if (br->br_chipid == chipid)
     
    16971829const struct bge_vendor *
    16981830bge_lookup_vendor(uint16_t vid)
    16991831{
    1700     const struct bge_vendor *v;
     1832const struct bge_vendor *v;
    17011833
    17021834    for (v = bge_vendors; v->v_name != NULL; v++)
    17031835        if (v->v_id == vid)
     
    17301862    while(t->bge_vid != 0) {
    17311863        if ((vid == t->bge_vid) && (did == t->bge_did)) {
    17321864            char model[64], buf[96];
    1733             const struct bge_revision *br;
    1734             const struct bge_vendor *v;
     1865const struct bge_revision *br;
     1866const struct bge_vendor *v;
    17351867            uint32_t id;
    17361868
    17371869            id = pci_read_config(dev, BGE_PCI_MISC_CTL, 4) &
     
    17401872            v = bge_lookup_vendor(vid);
    17411873            {
    17421874#if __FreeBSD_version > 700024
    1743                 const char *pname;
     1875const char *pname;
    17441876
    17451877                if (pci_get_vpd_ident(dev, &pname) == 0)
    17461878                    snprintf(model, 64, "%s", pname);
     
    18922024    /*
    18932025     * Allocate the parent bus DMA tag appropriate for PCI.
    18942026     */
    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);
     2027    error = bus_dma_tag_create(bus_get_dma_tag(sc->bge_dev),
     2028        1, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
     2029        NULL, BUS_SPACE_MAXSIZE_32BIT, 0, BUS_SPACE_MAXSIZE_32BIT,
     2030        0, NULL, NULL, &sc->bge_cdata.bge_parent_tag);
    19052031
    19062032    if (error != 0) {
    19072033        device_printf(sc->bge_dev,
     
    19102036    }
    19112037
    19122038    /*
    1913      * Create tag for RX mbufs.
     2039     * Create tag for mbufs.
    19142040     */
    19152041    error = bus_dma_tag_create(sc->bge_cdata.bge_parent_tag, 1,
    19162042        0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
     
    22292355{
    22302356    struct ifnet *ifp;
    22312357    struct bge_softc *sc;
    2232     uint32_t hwcfg = 0;
    2233     uint32_t mac_tmp = 0;
     2358    uint32_t hwcfg = 0, misccfg;
    22342359    u_char eaddr[ETHER_ADDR_LEN];
    22352360    int error, reg, rid, trys;
    22362361
    22372362    sc = device_get_softc(dev);
    22382363    sc->bge_dev = dev;
     2364    sc->transmitting = 0;
    22392365
    22402366    /*
    22412367     * Map control/status registers.
     
    22632389    sc->bge_asicrev = BGE_ASICREV(sc->bge_chipid);
    22642390    sc->bge_chiprev = BGE_CHIPREV(sc->bge_chipid);
    22652391
    2266     if (bge_has_eeprom(sc))
    2267         sc->bge_flags |= BGE_FLAG_EEPROM;
     2392    /*
     2393     * Don't enable Ethernet@WireSpeed for the 5700, 5906, or the
     2394     * 5705 A0 and A1 chips.
     2395     */
     2396    if (sc->bge_asicrev != BGE_ASICREV_BCM5700 &&
     2397        sc->bge_asicrev != BGE_ASICREV_BCM5906 &&
     2398        sc->bge_chipid != BGE_CHIPID_BCM5705_A0 &&
     2399        sc->bge_chipid != BGE_CHIPID_BCM5705_A1)
     2400        sc->bge_flags |= BGE_FLAG_WIRESPEED;
    22682401
     2402    if (bge_has_eaddr(sc))
     2403        sc->bge_flags |= BGE_FLAG_EADDR;
     2404
    22692405    /* Save chipset family. */
    22702406    switch (sc->bge_asicrev) {
    22712407    case BGE_ASICREV_BCM5700:
     
    22832419    case BGE_ASICREV_BCM5752:
    22842420    case BGE_ASICREV_BCM5755:
    22852421    case BGE_ASICREV_BCM5787:
     2422    case BGE_ASICREV_BCM5906:
    22862423        sc->bge_flags |= BGE_FLAG_575X_PLUS;
    22872424        /* FALLTHRU */
    22882425    case BGE_ASICREV_BCM5705:
     
    23022439    if (BGE_IS_5705_PLUS(sc) &&
    23032440        !(sc->bge_flags & BGE_FLAG_ADJUST_TRIM)) {
    23042441        if (sc->bge_asicrev == BGE_ASICREV_BCM5755 ||
    2305             sc->bge_asicrev == BGE_ASICREV_BCM5787)
     2442            sc->bge_asicrev == BGE_ASICREV_BCM5787) {
     2443            if (sc->bge_chipid != BGE_CHIPID_BCM5722_A0)
    23062444            sc->bge_flags |= BGE_FLAG_JITTER_BUG;
    2307         else
     2445        } else if (sc->bge_asicrev != BGE_ASICREV_BCM5906)
    23082446            sc->bge_flags |= BGE_FLAG_BER_BUG;
    23092447    }
    23102448
     2449
    23112450    /*
     2451     * We could possibly check for BCOM_DEVICEID_BCM5788 in bge_probe()
     2452     * but I do not know the DEVICEID for the 5788M.
     2453     */
     2454    misccfg = CSR_READ_4(sc, BGE_MISC_CFG) & BGE_MISCCFG_BOARD_ID;
     2455    if (misccfg == BGE_MISCCFG_BOARD_ID_5788 ||
     2456        misccfg == BGE_MISCCFG_BOARD_ID_5788M)
     2457        sc->bge_flags |= BGE_FLAG_5788;
     2458
     2459    /*
    23122460     * Check if this is a PCI-X or PCI Express device.
    23132461     */
    23142462#if __FreeBSD_version > 602101
     
    24142562        goto fail;
    24152563    }
    24162564
    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)) {
     2565    error = bge_get_eaddr(sc, eaddr);
     2566    if (error) {
    24342567            device_printf(sc->bge_dev,
    24352568                "failed to read station address\n");
    24362569            error = ENXIO;
    24372570            goto fail;
    24382571        }
    2439     }
    24402572
    24412573    /* 5705 limits RX return ring to 512 entries. */
    24422574    if (BGE_IS_5705_PLUS(sc))
     
    25072639     */
    25082640    if (bge_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_SIG) == BGE_MAGIC_NUMBER)
    25092641        hwcfg = bge_readmem_ind(sc, BGE_SOFTWARE_GENCOMM_NICCFG);
    2510     else if (sc->bge_flags & BGE_FLAG_EEPROM) {
     2642    else if ((sc->bge_flags & BGE_FLAG_EADDR) &&
     2643        (sc->bge_asicrev != BGE_ASICREV_BCM5906)) {
    25112644        if (bge_read_eeprom(sc, (caddr_t)&hwcfg, BGE_EE_HWCFG_OFFSET,
    25122645            sizeof(hwcfg))) {
    25132646            device_printf(sc->bge_dev, "failed to read EEPROM\n");
     
    26822815bge_reset(struct bge_softc *sc)
    26832816{
    26842817    device_t dev;
    2685     uint32_t cachesize, command, pcistate, reset;
     2818    uint32_t cachesize, command, pcistate, reset, val;
    26862819    void (*write_op)(struct bge_softc *, int, int);
    2687     int i, val = 0;
     2820    int i;
    26882821
    26892822    dev = sc->bge_dev;
    26902823
    2691     if (BGE_IS_575X_PLUS(sc) && !BGE_IS_5714_FAMILY(sc)) {
     2824    if (BGE_IS_575X_PLUS(sc) && !BGE_IS_5714_FAMILY(sc) &&
     2825        (sc->bge_asicrev != BGE_ASICREV_BCM5906)) {
    26922826        if (sc->bge_flags & BGE_FLAG_PCIE)
    26932827            write_op = bge_writemem_direct;
    26942828        else
     
    27442878    /* Issue global reset */
    27452879    write_op(sc, BGE_MISC_CFG, reset);
    27462880
     2881    if (sc->bge_asicrev == BGE_ASICREV_BCM5906) {
     2882        val = CSR_READ_4(sc, BGE_VCPU_STATUS);
     2883        CSR_WRITE_4(sc, BGE_VCPU_STATUS,
     2884            val | BGE_VCPU_STATUS_DRV_RESET);
     2885        val = CSR_READ_4(sc, BGE_VCPU_EXT_CTRL);
     2886        CSR_WRITE_4(sc, BGE_VCPU_EXT_CTRL,
     2887            val & ~BGE_VCPU_EXT_CTRL_HALT_CPU);
     2888    }
     2889
    27472890    DELAY(1000);
    27482891
    27492892    /* XXX: Broadcom Linux driver. */
    27502893    if (sc->bge_flags & BGE_FLAG_PCIE) {
    27512894        if (sc->bge_chipid == BGE_CHIPID_BCM5750_A0) {
    2752             uint32_t v;
    2753 
    27542895            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);
     2896            val = pci_read_config(dev, 0xC4, 4);
     2897            pci_write_config(dev, 0xC4, val | (1 << 15), 4);
    27572898        }
    27582899        /*
    27592900         * Set PCIE max payload size to 128 bytes and clear error
     
    27722913
    27732914    /* Re-enable MSI, if neccesary, and enable the memory arbiter. */
    27742915    if (BGE_IS_5714_FAMILY(sc)) {
    2775         uint32_t val;
    2776 
    27772916        /* This chip disables MSI on reset. */
    27782917        if (sc->bge_flags & BGE_FLAG_MSI) {
    27792918            val = pci_read_config(dev, BGE_PCI_MSI_CTL, 2);
     
    27882927    } else
    27892928        CSR_WRITE_4(sc, BGE_MARB_MODE, BGE_MARBMODE_ENABLE);
    27902929
     2930    if (sc->bge_asicrev == BGE_ASICREV_BCM5906) {
     2931        for (i = 0; i < BGE_TIMEOUT; i++) {
     2932            val = CSR_READ_4(sc, BGE_VCPU_STATUS);
     2933            if (val & BGE_VCPU_STATUS_INIT_DONE)
     2934                break;
     2935            DELAY(100);
     2936        }
     2937        if (i == BGE_TIMEOUT) {
     2938            device_printf(sc->bge_dev, "reset timed out\n");
     2939            return (1);
     2940        }
     2941    } else {
    27912942    /*
    27922943     * Poll until we see the 1's complement of the magic number.
    27932944     * This indicates that the firmware initialization is complete.
    2794      * We expect this to fail if no EEPROM is fitted though.
     2945         * We expect this to fail if no chip containing the Ethernet
     2946         * address is fitted though.
    27952947     */
    27962948    for (i = 0; i < BGE_TIMEOUT; i++) {
    27972949        DELAY(10);
     
    28002952            break;
    28012953    }
    28022954
    2803     if ((sc->bge_flags & BGE_FLAG_EEPROM) && i == BGE_TIMEOUT)
     2955        if ((sc->bge_flags & BGE_FLAG_EADDR) && i == BGE_TIMEOUT)
    28042956        device_printf(sc->bge_dev, "firmware handshake timed out, "
    28052957            "found 0x%08x\n", val);
     2958    }
    28062959
    28072960    /*
    28082961     * XXX Wait for the value of the PCISTATE register to
     
    28402993     */
    28412994    if (sc->bge_asicrev == BGE_ASICREV_BCM5704 &&
    28422995        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);
     2996        val = CSR_READ_4(sc, BGE_SERDES_CFG);
     2997        val = (val & ~0xFFF) | 0x880;
     2998        CSR_WRITE_4(sc, BGE_SERDES_CFG, val);
    28482999    }
    28493000
    28503001    /* XXX: Broadcom Linux driver. */
    28513002    if (sc->bge_flags & BGE_FLAG_PCIE &&
    28523003        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));
     3004        val = CSR_READ_4(sc, 0x7C00);
     3005        CSR_WRITE_4(sc, 0x7C00, val | (1 << 25));
    28573006    }
    28583007    DELAY(10000);
    28593008
     
    30223171        bus_dmamap_sync(sc->bge_cdata.bge_rx_jumbo_ring_tag,
    30233172            sc->bge_cdata.bge_rx_jumbo_ring_map, BUS_DMASYNC_PREWRITE);
    30243173
    3025     CSR_WRITE_4(sc, BGE_MBX_RX_CONS0_LO, sc->bge_rx_saved_considx);
     3174    bge_writembx(sc, BGE_MBX_RX_CONS0_LO, sc->bge_rx_saved_considx);
    30263175    if (stdcnt)
    3027         CSR_WRITE_4(sc, BGE_MBX_RX_STD_PROD_LO, sc->bge_std);
     3176        bge_writembx(sc, BGE_MBX_RX_STD_PROD_LO, sc->bge_std);
    30283177    if (jumbocnt)
    3029         CSR_WRITE_4(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
     3178        bge_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
    30303179#ifdef notyet
    30313180    /*
    30323181     * This register wraps very quickly under heavy packet drops.
     
    31683317     * the status check).  So toggling would probably be a pessimization
    31693318     * even with MSI.  It would only be needed for using a task queue.
    31703319     */
    3171     CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 0);
     3320#ifndef __HAIKU__
     3321    bge_writembx(sc, BGE_MBX_IRQ0_LO, 0);
     3322#endif
    31723323
    31733324    /*
    31743325     * Do the mandatory PCI flush as well as get the link status.
    31753326     */
    3176     statusword = CSR_READ_4(sc, BGE_MAC_STS) & BGE_MACSTAT_LINK_CHANGED;
     3327#ifndef __HAIKU__
     3328        statusword = CSR_READ_4(sc, BGE_MAC_STS) & BGE_MACSTAT_LINK_CHANGED;
     3329#else
     3330        /* Get the statusword as saved in __haiku_disable_interrupts
     3331         * and clear the saved value */
     3332        statusword = atomic_and((int32 *)&sc->bge_intr_status, 0) & BGE_MACSTAT_LINK_CHANGED;
     3333#endif
    31773334
    31783335    /* Make sure the descriptor ring indexes are coherent. */
    31793336    bus_dmamap_sync(sc->bge_cdata.bge_status_tag,
     
    31813338    bus_dmamap_sync(sc->bge_cdata.bge_status_tag,
    31823339        sc->bge_cdata.bge_status_map, BUS_DMASYNC_PREREAD);
    31833340
    3184     if ((sc->bge_asicrev == BGE_ASICREV_BCM5700 &&
    3185         sc->bge_chipid != BGE_CHIPID_BCM5700_B2) ||
    3186         statusword || sc->bge_link_evt)
    3187         bge_link_upd(sc);
     3341        /* TODO: bge_link_upd is probably not correct with interrupt changes
     3342         * May need to also use the saved statusword... */
     3343//QQQ
     3344    //if ((sc->bge_asicrev == BGE_ASICREV_BCM5700 &&
     3345    //    sc->bge_chipid != BGE_CHIPID_BCM5700_B2) ||
     3346    //    statusword || sc->bge_link_evt)
     3347    //  bge_link_upd(sc);
    31883348
    31893349    if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
    31903350        /* Check RX return ring producer/consumer. */
     
    32553415#endif
    32563416        {
    32573417        sc->bge_link_evt++;
     3418        if (sc->bge_asicrev == BGE_ASICREV_BCM5700 ||
     3419            sc->bge_flags & BGE_FLAG_5788)
    32583420        BGE_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET);
     3421        else
     3422            BGE_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW);
    32593423        }
    32603424    }
    32613425
     
    33903554    error = bus_dmamap_load_mbuf_sg(sc->bge_cdata.bge_mtag, map, m, segs,
    33913555        &nsegs, BUS_DMA_NOWAIT);
    33923556    if (error == EFBIG) {
    3393         m = m_defrag(m, M_DONTWAIT);
     3557        //m = m_collapse(m, M_DONTWAIT, BGE_NSEG_NEW);
     3558        panic("m_collapse not implemented");
    33943559        if (m == NULL) {
    33953560            m_freem(*m_head);
    33963561            *m_head = NULL;
     
    34823647
    34833648    sc = ifp->if_softc;
    34843649
    3485     if (!sc->bge_link || IFQ_DRV_IS_EMPTY(&ifp->if_snd))
     3650    //if (!sc->bge_link || IFQ_DRV_IS_EMPTY(&ifp->if_snd))
     3651    if (IFQ_DRV_IS_EMPTY(&ifp->if_snd))
    34863652        return;
    34873653
    34883654    prodidx = sc->bge_tx_prodidx;
     
    35443710        /* No packets were dequeued. */
    35453711        return;
    35463712
     3713    sc -> transmitting = 1;
    35473714    /* Transmit. */
    3548     CSR_WRITE_4(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
     3715    bge_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
    35493716    /* 5700 b2 errata */
    35503717    if (sc->bge_chiprev == BGE_CHIPREV_5700_BX)
    3551         CSR_WRITE_4(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
     3718        bge_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
    35523719
    35533720    sc->bge_tx_prodidx = prodidx;
    35543721
     
    36753842    if (ifp->if_capenable & IFCAP_POLLING) {
    36763843        BGE_SETBIT(sc, BGE_PCI_MISC_CTL,
    36773844            BGE_PCIMISCCTL_MASK_PCI_INTR);
    3678         CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 1);
     3845        bge_writembx(sc, BGE_MBX_IRQ0_LO, 1);
    36793846    } else
    36803847#endif
    36813848
    36823849    /* Enable host interrupts. */
     3850//QQQ
    36833851    {
    36843852    BGE_SETBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_CLEAR_INTA);
    36853853    BGE_CLRBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_MASK_PCI_INTR);
    3686     CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 0);
     3854    bge_writembx(sc, BGE_MBX_IRQ0_LO, 0);
    36873855    }
    36883856   
    36893857    bge_ifmedia_upd_locked(ifp);
     
    37833951    }
    37843952    mii_mediachg(mii);
    37853953
     3954    /*
     3955     * Force an interrupt so that we will call bge_link_upd
     3956     * if needed and clear any pending link state attention.
     3957     * Without this we are not getting any further interrupts
     3958     * for link state changes and thus will not UP the link and
     3959     * not be able to send in bge_start_locked. The only
     3960     * way to get things working was to receive a packet and
     3961     * get an RX intr.
     3962     * bge_tick should help for fiber cards and we might not
     3963     * need to do this here if BGE_FLAG_TBI is set but as
     3964     * we poll for fiber anyway it should not harm.
     3965     */
     3966    if (sc->bge_asicrev == BGE_ASICREV_BCM5700 ||
     3967        sc->bge_flags & BGE_FLAG_5788)
     3968        BGE_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET);
     3969    else
     3970        BGE_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW);
     3971
    37863972    return (0);
    37873973}
    37883974
     
    39064092                BGE_LOCK(sc);
    39074093                BGE_SETBIT(sc, BGE_PCI_MISC_CTL,
    39084094                    BGE_PCIMISCCTL_MASK_PCI_INTR);
    3909                 CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 1);
     4095                bge_writembx(sc, BGE_MBX_IRQ0_LO, 1);
    39104096                ifp->if_capenable |= IFCAP_POLLING;
    39114097                BGE_UNLOCK(sc);
    39124098            } else {
     
    39154101                BGE_LOCK(sc);
    39164102                BGE_CLRBIT(sc, BGE_PCI_MISC_CTL,
    39174103                    BGE_PCIMISCCTL_MASK_PCI_INTR);
    3918                 CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 0);
     4104                bge_writembx(sc, BGE_MBX_IRQ0_LO, 0);
    39194105                ifp->if_capenable &= ~IFCAP_POLLING;
    39204106                BGE_UNLOCK(sc);
    39214107            }
     
    40404226
    40414227    /* Disable host interrupts. */
    40424228    BGE_SETBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_MASK_PCI_INTR);
    4043     CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 1);
     4229    bge_writembx(sc, BGE_MBX_IRQ0_LO, 1);
    40444230
    40454231    /*
    40464232     * Tell firmware we're shutting down.
     
    40834269         */
    40844270        if (mii != NULL) {
    40854271            ifm = mii->mii_media.ifm_cur;
     4272            if (ifm == NULL)
     4273            {
     4274                panic("bge_stop: ifm == NULL");
     4275                return ;
     4276            }
    40864277            mtmp = ifm->ifm_media;
    40874278            ifm->ifm_media = IFM_ETHER | IFM_NONE;
    40884279            mii_mediachg(mii);
     
    41504341    return (0);
    41514342}
    41524343
    4153 static void
     4344/*static*/ void
    41544345bge_link_upd(struct bge_softc *sc)
    41554346{
    41564347    struct mii_data *mii;
    41574348    uint32_t link, status;
    41584349
     4350
    41594351    BGE_LOCK_ASSERT(sc);
    41604352
    41614353    /* Clear 'pending link event' flag. */
     
    42324424         * in status word always set. Workaround this bug by reading
    42334425         * PHY link status directly.
    42344426         */
     4427#define lnDbg do {printf("%s: %s: %d\n", __FILE__,__func__, __LINE__); } while(0)
     4428        lnDbg;
    42354429        link = (CSR_READ_4(sc, BGE_MI_STS) & BGE_MISTS_LINK) ? 1 : 0;
    42364430
    42374431        if (link != sc->bge_link ||
    42384432            sc->bge_asicrev == BGE_ASICREV_BCM5700) {
     4433        lnDbg;
    42394434            mii = device_get_softc(sc->bge_miibus);
    42404435            mii_pollstat(mii);
    42414436            if (!sc->bge_link &&
    42424437                mii->mii_media_status & IFM_ACTIVE &&
    42434438                IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
     4439        lnDbg;
    42444440                sc->bge_link++;
    42454441                if (bootverbose)
    42464442                    if_printf(sc->bge_ifp, "link UP\n");
     
    42634459    CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED |
    42644460        BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE |
    42654461        BGE_MACSTAT_LINK_CHANGED);
     4462
     4463    dprintf("bge_link_upd, sc->bge_link=0x%x\n", sc->bge_link);
    42664464}
    42674465
    42684466#define BGE_SYSCTL_STAT(sc, ctx, desc, parent, node, oid) \
     
    42954493
    42964494#endif
    42974495
     4496    if (BGE_IS_5705_PLUS(sc))
     4497        return;
     4498
    42984499    tree = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", CTLFLAG_RD,
    42994500        NULL, "BGE Statistics");
    43004501    schildren = children = SYSCTL_CHILDREN(tree);
     
    44174618{
    44184619    struct bge_softc *sc;
    44194620    uint32_t result;
    4420     int base, offset;
     4621    int offset;
    44214622
    44224623    sc = (struct bge_softc *)arg1;
    44234624    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));
     4625    result = CSR_READ_4(sc, BGE_MEMWIN_START + BGE_STATS_BLOCK + offset +
     4626        offsetof(bge_hostaddr, bge_addr_lo));
    44304627    return (sysctl_handle_int(oidp, &result, 0, req));
    44314628}
    44324629
     
    45374734    return (error);
    45384735}
    45394736#endif
     4737
     4738static int
     4739bge_get_eaddr_fw(struct bge_softc *sc, uint8_t ether_addr[])
     4740{
     4741
     4742    if (sc->bge_flags & BGE_FLAG_EADDR)
     4743        return (1);
     4744
     4745#ifdef __sparc64__
     4746    OF_getetheraddr(sc->bge_dev, ether_addr);
     4747    return (0);
     4748#endif
     4749    return (1);
     4750}
     4751
     4752static int
     4753bge_get_eaddr_mem(struct bge_softc *sc, uint8_t ether_addr[])
     4754{
     4755    uint32_t mac_addr;
     4756
     4757    mac_addr = bge_readmem_ind(sc, 0x0c14);
     4758    if ((mac_addr >> 16) == 0x484b) {
     4759        ether_addr[0] = (uint8_t)(mac_addr >> 8);
     4760        ether_addr[1] = (uint8_t)mac_addr;
     4761        mac_addr = bge_readmem_ind(sc, 0x0c18);
     4762        ether_addr[2] = (uint8_t)(mac_addr >> 24);
     4763        ether_addr[3] = (uint8_t)(mac_addr >> 16);
     4764        ether_addr[4] = (uint8_t)(mac_addr >> 8);
     4765        ether_addr[5] = (uint8_t)mac_addr;
     4766        return (0);
     4767    }
     4768    return (1);
     4769}
     4770
     4771static int
     4772bge_get_eaddr_nvram(struct bge_softc *sc, uint8_t ether_addr[])
     4773{
     4774    int mac_offset = BGE_EE_MAC_OFFSET;
     4775
     4776    if (sc->bge_asicrev == BGE_ASICREV_BCM5906)
     4777        mac_offset = BGE_EE_MAC_OFFSET_5906;
     4778
     4779    return (bge_read_nvram(sc, ether_addr, mac_offset + 2,
     4780        ETHER_ADDR_LEN));
     4781}
     4782
     4783static int
     4784bge_get_eaddr_eeprom(struct bge_softc *sc, uint8_t ether_addr[])
     4785{
     4786
     4787    if (sc->bge_asicrev == BGE_ASICREV_BCM5906)
     4788        return (1);
     4789
     4790    return (bge_read_eeprom(sc, ether_addr, BGE_EE_MAC_OFFSET + 2,
     4791       ETHER_ADDR_LEN));
     4792}
     4793
     4794static int
     4795bge_get_eaddr(struct bge_softc *sc, uint8_t eaddr[])
     4796{
     4797static const bge_eaddr_fcn_t bge_eaddr_funcs[] = {
     4798        /* NOTE: Order is critical */
     4799        bge_get_eaddr_fw,
     4800        bge_get_eaddr_mem,
     4801        bge_get_eaddr_nvram,
     4802        bge_get_eaddr_eeprom,
     4803        NULL
     4804    };
     4805const bge_eaddr_fcn_t *func;
     4806
     4807    for (func = bge_eaddr_funcs; *func != NULL; ++func) {
     4808        if ((*func)(sc, eaddr) == 0)
     4809            break;
     4810    }
     4811    return (*func == NULL ? ENXIO : 0);
     4812}
  • src/add-ons/kernel/drivers/network/broadcom_bcm570x/dev/bge/glue.c

     
    55
    66
    77#include <sys/bus.h>
     8#include "if_bgereg.h"
    89
    910
    1011HAIKU_FBSD_DRIVER_GLUE(broadcom_bcm570x, bge, pci);
     
    2526    return __haiku_probe_miibus(dev, drivers);
    2627}
    2728
     29int
     30__haiku_disable_interrupts(device_t dev)
     31{
     32        struct bge_softc *sc = device_get_softc(dev);
     33 
     34        // Obtain the status and return 0 if the bge did not set the intr
     35        u_int32_t status = CSR_READ_4(sc, BGE_MAC_STS);
     36    // status & 0x1000 for media change, sc->transmitting if sending a packet
     37    // use BGE_PCI_PCISTATE to check interrupt source like in the Linux driver
     38    if ( ((status & 0x1000)==0)&&(sc->transmitting==0) && ((pci_read_config(sc->bge_dev, BGE_PCI_PCISTATE,4) & BGE_PCISTATE_INTR_STATE) != 0)) {
     39                return 0;
     40        }
     41    sc->transmitting=0;
     42 
     43        // Clear the interrupt, the bge intr handler will take care of it
     44        BGE_SETBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_MASK_PCI_INTR);
     45        bge_writembx(sc, BGE_MBX_IRQ0_LO, 1);
     46 
     47        // save the status for the interrupt handler
     48        atomic_or((int32 *)&sc->bge_intr_status, status);
     49// ***
     50    if ((sc->bge_asicrev == BGE_ASICREV_BCM5700 &&
     51        sc->bge_chipid != BGE_CHIPID_BCM5700_B2) ||
     52        (status&0x1000) || sc->bge_link_evt)
     53        bge_link_upd(sc);
     54// ***
     55        return 1;
     56}
     57 
     58 
     59void
     60__haiku_reenable_interrupts(device_t dev)
     61{
     62        struct bge_softc *sc = device_get_softc(dev);
     63        BGE_SETBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_CLEAR_INTA);
     64        BGE_CLRBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_MASK_PCI_INTR);
     65        bge_writembx(sc, BGE_MBX_IRQ0_LO, 0);
     66}
  • src/libs/compat/freebsd_network/compat/sys/mbuf.h

     
    8282
    8383#define M_BCAST         0x00000200
    8484#define M_MCAST         0x00000400
     85#define M_FRAG          0x00000800
     86#define M_FIRSTFRAG     0x00001000
     87#define M_LASTFRAG      0x00002000
    8588#define M_VLANTAG       0x00010000
    8689
    8790#define CSUM_IP         0x0001
     
    124127struct mbuf *m_get(int how, short type);
    125128struct mbuf *m_gethdr(int how, short type);
    126129void m_clget(struct mbuf *m, int how);
     130void * m_cljget(struct mbuf *m, int how, int size);
    127131
    128132void m_extadd(struct mbuf *m, caddr_t buffer, u_int size,
    129133    void (*freeHook)(void *, void *), void *args, int flags, int type);
  • src/libs/compat/freebsd_network/fbsd_mii_physubr.c

     
    510510    }
    511511
    512512    if (sc->mii_capabilities & BMSR_ANEG) {
    513         ADD(IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, sc->mii_inst),
    514             MII_NMEDIA);    /* intentionally invalid index */
     513        dprintf("don't know how to handle sc->mii_capabilities & BMSR_ANEG\n");
     514        //ADD(IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, sc->mii_inst),
     515            //MII_NMEDIA);  /* intentionally invalid index */
    515516        PRINT("auto");
    516517    }
    517518#undef ADD
  • src/libs/compat/freebsd_network/mbuf.c

     
    150150    construct_ext_mbuf(m, how);
    151151}
    152152
     153    /*
     154     * Comment from the freebsd (mbuf.h):
     155     * m_cljget() is different from m_clget() as it can allocate clusters without
     156     * attaching them to an mbuf.  In that case the return value is the pointer
     157     * to the cluster of the requested size.  If an mbuf was specified, it gets
     158     * the cluster attached to it and the return value can be safely ignored.
     159     * For size it takes MCLBYTES, MJUMPAGESIZE, MJUM9BYTES, MJUM16BYTES.
     160     */
     161    void *
     162    m_cljget(struct mbuf *m, int how, int size)
     163    {
     164            // TODO: implement this
     165            panic("m_cljget not yet implemented");
     166            return (void *) NULL;
     167     
     168    /*
     169    //      This is the freebsd code
     170            uma_zone_t zone;
     171     
     172            if (m && m->m_flags & M_EXT)
     173                    printf("%s: %p mbuf already has cluster\n", __func__, m);
     174            if (m != NULL)
     175                    m->m_ext.ext_buf = NULL;
     176     
     177            zone = m_getzone(size);
     178            return (uma_zalloc_arg(zone, m, how));
     179    */
     180    }
     181     
     182     
    153183
    154184void
    155185m_freem(struct mbuf *mb)