Ticket #1590: broadcom570x.diff

File broadcom570x.diff, 43.3 KB (added by PieterPanman, 15 years ago)

diff adjusted for new location and name of driver. Also includes debugging output to generate above syslog

  • build/jam/HaikuImage

     
    142142    $(X86_ONLY)via_rhine wb840 $(X86_ONLY)ipro100 $(X86_ONLY)nforce
    143143    #vlance
    144144    $(X86_ONLY)marvell_yukon $(X86_ONLY)syskonnect usb_ecm
    145     $(GPL_ONLY)bcm440x $(GPL_ONLY)bcm570x
     145    $(GPL_ONLY)bcm440x $(GPL_ONLY)bcm570x broadcom570x
    146146;
    147147#BEOS_ADD_ONS_DRIVERS_ACPI = $(X86_ONLY)acpi_button ;
    148148BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)ps2 $(X86_ONLY)isa ide scsi
     
    161161    : generic_ide_pci it8211 legacy_sata silicon_image_3112 $(X86_ONLY)ide_isa ;
    162162AddFilesToHaikuImage beos system add-ons kernel busses scsi
    163163    : ahci ;
    164 AddFilesToHaikuImage beos system add-ons kernel busses usb
    165     : <usb>uhci <usb>ohci <usb>ehci ;
     164#AddFilesToHaikuImage beos system add-ons kernel busses usb
     165#   : <usb>uhci <usb>ohci <usb>ehci ;
    166166AddFilesToHaikuImage beos system add-ons kernel console : vga_text ;
    167167AddFilesToHaikuImage beos system add-ons kernel debugger
    168168    : $(X86_ONLY)<kdebug>disasm <kdebug>hangman <kdebug>invalidate_on_exit ;
     
    385385    $(PPC_ONLY)openpic
    386386    ide_adapter locked_pool scsi_periph
    387387    ahci generic_ide_pci it8211 legacy_sata silicon_image_3112 $(X86_ONLY)ide_isa
    388     <usb>uhci <usb>ohci <usb>ehci
     388#   <usb>uhci <usb>ohci <usb>ehci
    389389    scsi_cd scsi_disk usb_disk
    390390    intel
    391391    bfs
  • src/add-ons/kernel/drivers/network/broadcom570x/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/broadcom570x/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
     
    28823031        sc->bge_ldata.bge_status_block->bge_idx[0].bge_rx_prod_idx)
    28833032        return;
    28843033
     3034    dprintf("bge_rxeof\n");
     3035
    28853036    ifp = sc->bge_ifp;
    28863037
    28873038    bus_dmamap_sync(sc->bge_cdata.bge_rx_return_ring_tag,
     
    30223173        bus_dmamap_sync(sc->bge_cdata.bge_rx_jumbo_ring_tag,
    30233174            sc->bge_cdata.bge_rx_jumbo_ring_map, BUS_DMASYNC_PREWRITE);
    30243175
    3025     CSR_WRITE_4(sc, BGE_MBX_RX_CONS0_LO, sc->bge_rx_saved_considx);
     3176    bge_writembx(sc, BGE_MBX_RX_CONS0_LO, sc->bge_rx_saved_considx);
    30263177    if (stdcnt)
    3027         CSR_WRITE_4(sc, BGE_MBX_RX_STD_PROD_LO, sc->bge_std);
     3178        bge_writembx(sc, BGE_MBX_RX_STD_PROD_LO, sc->bge_std);
    30283179    if (jumbocnt)
    3029         CSR_WRITE_4(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
     3180        bge_writembx(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
    30303181#ifdef notyet
    30313182    /*
    30323183     * This register wraps very quickly under heavy packet drops.
     
    30503201        sc->bge_ldata.bge_status_block->bge_idx[0].bge_tx_cons_idx)
    30513202        return;
    30523203
     3204    dprintf("bge_txeof\n");
     3205
    30533206    ifp = sc->bge_ifp;
    30543207
    30553208    bus_dmamap_sync(sc->bge_cdata.bge_tx_ring_tag,
     
    31373290
    31383291    sc = xsc;
    31393292
     3293    dprintf("bge_intr, sc->bge_intr_status=0x%x\n", sc->bge_intr_status);
     3294
    31403295    BGE_LOCK(sc);
    31413296
    31423297    ifp = sc->bge_ifp;
     
    31683323     * the status check).  So toggling would probably be a pessimization
    31693324     * even with MSI.  It would only be needed for using a task queue.
    31703325     */
    3171     CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 0);
     3326#ifndef __HAIKU__
     3327    bge_writembx(sc, BGE_MBX_IRQ0_LO, 0);
     3328#endif
    31723329
    31733330    /*
    31743331     * Do the mandatory PCI flush as well as get the link status.
    31753332     */
    3176     statusword = CSR_READ_4(sc, BGE_MAC_STS) & BGE_MACSTAT_LINK_CHANGED;
     3333#ifndef __HAIKU__
     3334        statusword = CSR_READ_4(sc, BGE_MAC_STS) & BGE_MACSTAT_LINK_CHANGED;
     3335#else
     3336        /* Get the statusword as saved in __haiku_disable_interrupts
     3337         * and clear the saved value */
     3338        statusword = atomic_and((int32 *)&sc->bge_intr_status, 0) & BGE_MACSTAT_LINK_CHANGED;
     3339#endif
    31773340
    31783341    /* Make sure the descriptor ring indexes are coherent. */
    31793342    bus_dmamap_sync(sc->bge_cdata.bge_status_tag,
     
    31813344    bus_dmamap_sync(sc->bge_cdata.bge_status_tag,
    31823345        sc->bge_cdata.bge_status_map, BUS_DMASYNC_PREREAD);
    31833346
    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);
     3347        /* TODO: bge_link_upd is probably not correct with interrupt changes
     3348         * May need to also use the saved statusword... */
     3349//QQQ
     3350    //if ((sc->bge_asicrev == BGE_ASICREV_BCM5700 &&
     3351    //    sc->bge_chipid != BGE_CHIPID_BCM5700_B2) ||
     3352    //    statusword || sc->bge_link_evt)
     3353    //  bge_link_upd(sc);
    31883354
    31893355    if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
    31903356        /* Check RX return ring producer/consumer. */
     
    32553421#endif
    32563422        {
    32573423        sc->bge_link_evt++;
     3424        if (sc->bge_asicrev == BGE_ASICREV_BCM5700 ||
     3425            sc->bge_flags & BGE_FLAG_5788)
    32583426        BGE_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET);
     3427        else
     3428            BGE_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW);
    32593429        }
    32603430    }
    32613431
     
    33903560    error = bus_dmamap_load_mbuf_sg(sc->bge_cdata.bge_mtag, map, m, segs,
    33913561        &nsegs, BUS_DMA_NOWAIT);
    33923562    if (error == EFBIG) {
    3393         m = m_defrag(m, M_DONTWAIT);
     3563        //m = m_collapse(m, M_DONTWAIT, BGE_NSEG_NEW);
     3564        panic("m_collapse not implemented");
    33943565        if (m == NULL) {
    33953566            m_freem(*m_head);
    33963567            *m_head = NULL;
     
    34823653
    34833654    sc = ifp->if_softc;
    34843655
    3485     if (!sc->bge_link || IFQ_DRV_IS_EMPTY(&ifp->if_snd))
     3656    //if (!sc->bge_link || IFQ_DRV_IS_EMPTY(&ifp->if_snd))
     3657    if (IFQ_DRV_IS_EMPTY(&ifp->if_snd))
    34863658        return;
    34873659
    34883660    prodidx = sc->bge_tx_prodidx;
     
    35443716        /* No packets were dequeued. */
    35453717        return;
    35463718
     3719    sc -> transmitting = 1;
    35473720    /* Transmit. */
    3548     CSR_WRITE_4(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
     3721    bge_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
    35493722    /* 5700 b2 errata */
    35503723    if (sc->bge_chiprev == BGE_CHIPREV_5700_BX)
    3551         CSR_WRITE_4(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
     3724        bge_writembx(sc, BGE_MBX_TX_HOST_PROD0_LO, prodidx);
    35523725
    35533726    sc->bge_tx_prodidx = prodidx;
    35543727
     
    36753848    if (ifp->if_capenable & IFCAP_POLLING) {
    36763849        BGE_SETBIT(sc, BGE_PCI_MISC_CTL,
    36773850            BGE_PCIMISCCTL_MASK_PCI_INTR);
    3678         CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 1);
     3851        bge_writembx(sc, BGE_MBX_IRQ0_LO, 1);
    36793852    } else
    36803853#endif
    36813854
    36823855    /* Enable host interrupts. */
     3856//QQQ
    36833857    {
    36843858    BGE_SETBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_CLEAR_INTA);
    36853859    BGE_CLRBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_MASK_PCI_INTR);
    3686     CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 0);
     3860    bge_writembx(sc, BGE_MBX_IRQ0_LO, 0);
    36873861    }
    36883862   
    36893863    bge_ifmedia_upd_locked(ifp);
     
    37833957    }
    37843958    mii_mediachg(mii);
    37853959
     3960    /*
     3961     * Force an interrupt so that we will call bge_link_upd
     3962     * if needed and clear any pending link state attention.
     3963     * Without this we are not getting any further interrupts
     3964     * for link state changes and thus will not UP the link and
     3965     * not be able to send in bge_start_locked. The only
     3966     * way to get things working was to receive a packet and
     3967     * get an RX intr.
     3968     * bge_tick should help for fiber cards and we might not
     3969     * need to do this here if BGE_FLAG_TBI is set but as
     3970     * we poll for fiber anyway it should not harm.
     3971     */
     3972    if (sc->bge_asicrev == BGE_ASICREV_BCM5700 ||
     3973        sc->bge_flags & BGE_FLAG_5788)
     3974        BGE_SETBIT(sc, BGE_MISC_LOCAL_CTL, BGE_MLC_INTR_SET);
     3975    else
     3976        BGE_SETBIT(sc, BGE_HCC_MODE, BGE_HCCMODE_COAL_NOW);
     3977
    37863978    return (0);
    37873979}
    37883980
     
    39064098                BGE_LOCK(sc);
    39074099                BGE_SETBIT(sc, BGE_PCI_MISC_CTL,
    39084100                    BGE_PCIMISCCTL_MASK_PCI_INTR);
    3909                 CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 1);
     4101                bge_writembx(sc, BGE_MBX_IRQ0_LO, 1);
    39104102                ifp->if_capenable |= IFCAP_POLLING;
    39114103                BGE_UNLOCK(sc);
    39124104            } else {
     
    39154107                BGE_LOCK(sc);
    39164108                BGE_CLRBIT(sc, BGE_PCI_MISC_CTL,
    39174109                    BGE_PCIMISCCTL_MASK_PCI_INTR);
    3918                 CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 0);
     4110                bge_writembx(sc, BGE_MBX_IRQ0_LO, 0);
    39194111                ifp->if_capenable &= ~IFCAP_POLLING;
    39204112                BGE_UNLOCK(sc);
    39214113            }
     
    40404232
    40414233    /* Disable host interrupts. */
    40424234    BGE_SETBIT(sc, BGE_PCI_MISC_CTL, BGE_PCIMISCCTL_MASK_PCI_INTR);
    4043     CSR_WRITE_4(sc, BGE_MBX_IRQ0_LO, 1);
     4235    bge_writembx(sc, BGE_MBX_IRQ0_LO, 1);
    40444236
    40454237    /*
    40464238     * Tell firmware we're shutting down.
     
    40834275         */
    40844276        if (mii != NULL) {
    40854277            ifm = mii->mii_media.ifm_cur;
     4278            if (ifm == NULL)
     4279            {
     4280                panic("bge_stop: ifm == NULL");
     4281                return ;
     4282            }
    40864283            mtmp = ifm->ifm_media;
    40874284            ifm->ifm_media = IFM_ETHER | IFM_NONE;
    40884285            mii_mediachg(mii);
     
    41504347    return (0);
    41514348}
    41524349
    4153 static void
     4350/*static*/ void
    41544351bge_link_upd(struct bge_softc *sc)
    41554352{
    41564353    struct mii_data *mii;
    41574354    uint32_t link, status;
    41584355
     4356
    41594357    BGE_LOCK_ASSERT(sc);
    41604358
    41614359    /* Clear 'pending link event' flag. */
     
    42324430         * in status word always set. Workaround this bug by reading
    42334431         * PHY link status directly.
    42344432         */
     4433#define lnDbg do {printf("%s: %s: %d\n", __FILE__,__func__, __LINE__); } while(0)
     4434        lnDbg;
    42354435        link = (CSR_READ_4(sc, BGE_MI_STS) & BGE_MISTS_LINK) ? 1 : 0;
    42364436
    42374437        if (link != sc->bge_link ||
    42384438            sc->bge_asicrev == BGE_ASICREV_BCM5700) {
     4439        lnDbg;
    42394440            mii = device_get_softc(sc->bge_miibus);
    42404441            mii_pollstat(mii);
    42414442            if (!sc->bge_link &&
    42424443                mii->mii_media_status & IFM_ACTIVE &&
    42434444                IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
     4445        lnDbg;
    42444446                sc->bge_link++;
    42454447                if (bootverbose)
    42464448                    if_printf(sc->bge_ifp, "link UP\n");
     
    42634465    CSR_WRITE_4(sc, BGE_MAC_STS, BGE_MACSTAT_SYNC_CHANGED |
    42644466        BGE_MACSTAT_CFG_CHANGED | BGE_MACSTAT_MI_COMPLETE |
    42654467        BGE_MACSTAT_LINK_CHANGED);
     4468
     4469    dprintf("bge_link_upd, sc->bge_link=0x%x\n", sc->bge_link);
    42664470}
    42674471
    42684472#define BGE_SYSCTL_STAT(sc, ctx, desc, parent, node, oid) \
     
    42954499
    42964500#endif
    42974501
     4502    if (BGE_IS_5705_PLUS(sc))
     4503        return;
     4504
    42984505    tree = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", CTLFLAG_RD,
    42994506        NULL, "BGE Statistics");
    43004507    schildren = children = SYSCTL_CHILDREN(tree);
     
    44174624{
    44184625    struct bge_softc *sc;
    44194626    uint32_t result;
    4420     int base, offset;
     4627    int offset;
    44214628
    44224629    sc = (struct bge_softc *)arg1;
    44234630    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));
     4631    result = CSR_READ_4(sc, BGE_MEMWIN_START + BGE_STATS_BLOCK + offset +
     4632        offsetof(bge_hostaddr, bge_addr_lo));
    44304633    return (sysctl_handle_int(oidp, &result, 0, req));
    44314634}
    44324635
     
    45374740    return (error);
    45384741}
    45394742#endif
     4743
     4744static int
     4745bge_get_eaddr_fw(struct bge_softc *sc, uint8_t ether_addr[])
     4746{
     4747
     4748    if (sc->bge_flags & BGE_FLAG_EADDR)
     4749        return (1);
     4750
     4751#ifdef __sparc64__
     4752    OF_getetheraddr(sc->bge_dev, ether_addr);
     4753    return (0);
     4754#endif
     4755    return (1);
     4756}
     4757
     4758static int
     4759bge_get_eaddr_mem(struct bge_softc *sc, uint8_t ether_addr[])
     4760{
     4761    uint32_t mac_addr;
     4762
     4763    mac_addr = bge_readmem_ind(sc, 0x0c14);
     4764    if ((mac_addr >> 16) == 0x484b) {
     4765        ether_addr[0] = (uint8_t)(mac_addr >> 8);
     4766        ether_addr[1] = (uint8_t)mac_addr;
     4767        mac_addr = bge_readmem_ind(sc, 0x0c18);
     4768        ether_addr[2] = (uint8_t)(mac_addr >> 24);
     4769        ether_addr[3] = (uint8_t)(mac_addr >> 16);
     4770        ether_addr[4] = (uint8_t)(mac_addr >> 8);
     4771        ether_addr[5] = (uint8_t)mac_addr;
     4772        return (0);
     4773    }
     4774    return (1);
     4775}
     4776
     4777static int
     4778bge_get_eaddr_nvram(struct bge_softc *sc, uint8_t ether_addr[])
     4779{
     4780    int mac_offset = BGE_EE_MAC_OFFSET;
     4781
     4782    if (sc->bge_asicrev == BGE_ASICREV_BCM5906)
     4783        mac_offset = BGE_EE_MAC_OFFSET_5906;
     4784
     4785    return (bge_read_nvram(sc, ether_addr, mac_offset + 2,
     4786        ETHER_ADDR_LEN));
     4787}
     4788
     4789static int
     4790bge_get_eaddr_eeprom(struct bge_softc *sc, uint8_t ether_addr[])
     4791{
     4792
     4793    if (sc->bge_asicrev == BGE_ASICREV_BCM5906)
     4794        return (1);
     4795
     4796    return (bge_read_eeprom(sc, ether_addr, BGE_EE_MAC_OFFSET + 2,
     4797       ETHER_ADDR_LEN));
     4798}
     4799
     4800static int
     4801bge_get_eaddr(struct bge_softc *sc, uint8_t eaddr[])
     4802{
     4803static const bge_eaddr_fcn_t bge_eaddr_funcs[] = {
     4804        /* NOTE: Order is critical */
     4805        bge_get_eaddr_fw,
     4806        bge_get_eaddr_mem,
     4807        bge_get_eaddr_nvram,
     4808        bge_get_eaddr_eeprom,
     4809        NULL
     4810    };
     4811const bge_eaddr_fcn_t *func;
     4812
     4813    for (func = bge_eaddr_funcs; *func != NULL; ++func) {
     4814        if ((*func)(sc, eaddr) == 0)
     4815            break;
     4816    }
     4817    return (*func == NULL ? ENXIO : 0);
     4818}
  • src/add-ons/kernel/drivers/network/broadcom570x/dev/bge/glue.c

     
    55
    66
    77#include <sys/bus.h>
     8#include "if_bgereg.h"
    89
    910
    1011HAIKU_FBSD_DRIVER_GLUE(broadcom570x, 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
     
    125128struct mbuf *m_get(int how, short type);
    126129struct mbuf *m_gethdr(int how, short type);
    127130void m_clget(struct mbuf *m, int how);
     131void * m_cljget(struct mbuf *m, int how, int size);
    128132
    129133void m_extadd(struct mbuf *m, caddr_t buffer, u_int size,
    130134    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)