#ifndef _BFE_H
#define _BFE_H
#define BFE_PCI_MEMLO 0x10
#define BFE_PCI_MEMHIGH 0x14
#define BFE_PCI_INTLINE 0x3C
#define BFE_DEVCTRL 0x00000000
#define BFE_PFE 0x00000080
#define BFE_IPP 0x00000400
#define BFE_EPR 0x00008000
#define BFE_PME 0x00001000
#define BFE_PMCE 0x00002000
#define BFE_PADDR 0x0007c000
#define BFE_PADDR_SHIFT 18
#define BFE_BIST_STAT 0x0000000C
#define BFE_WKUP_LEN 0x00000010
#define BFE_ISTAT 0x00000020
#define BFE_ISTAT_PME 0x00000040
#define BFE_ISTAT_TO 0x00000080
#define BFE_ISTAT_DSCE 0x00000400
#define BFE_ISTAT_DATAE 0x00000800
#define BFE_ISTAT_DPE 0x00001000
#define BFE_ISTAT_RDU 0x00002000
#define BFE_ISTAT_RFO 0x00004000
#define BFE_ISTAT_TFU 0x00008000
#define BFE_ISTAT_RX 0x00010000
#define BFE_ISTAT_TX 0x01000000
#define BFE_ISTAT_EMAC 0x04000000
#define BFE_ISTAT_MII_WRITE 0x08000000
#define BFE_ISTAT_MII_READ 0x10000000
#define BFE_ISTAT_ERRORS (BFE_ISTAT_DSCE | BFE_ISTAT_DATAE | BFE_ISTAT_DPE |\
BFE_ISTAT_RDU | BFE_ISTAT_RFO | BFE_ISTAT_TFU)
#define BFE_IMASK 0x00000024
#define BFE_IMASK_DEF (BFE_ISTAT_ERRORS | BFE_ISTAT_TO | BFE_ISTAT_RX | \
BFE_ISTAT_TX)
#define BFE_MAC_CTRL 0x000000A8
#define BFE_CTRL_CRC32_ENAB 0x00000001
#define BFE_CTRL_PDOWN 0x00000004
#define BFE_CTRL_EDET 0x00000008
#define BFE_CTRL_LED 0x000000e0
#define BFE_CTRL_LED_SHIFT 5
#define BFE_RCV_LAZY 0x00000100
#define BFE_LAZY_TO_MASK 0x00ffffff
#define BFE_LAZY_FC_MASK 0xff000000
#define BFE_LAZY_FC_SHIFT 24
#define BFE_DMATX_CTRL 0x00000200
#define BFE_TX_CTRL_ENABLE 0x00000001
#define BFE_TX_CTRL_SUSPEND 0x00000002
#define BFE_TX_CTRL_LPBACK 0x00000004
#define BFE_TX_CTRL_FAIRPRI 0x00000008
#define BFE_TX_CTRL_FLUSH 0x00000010
#define BFE_DMATX_ADDR 0x00000204
#define BFE_DMATX_PTR 0x00000208
#define BFE_DMATX_STAT 0x0000020C
#define BFE_STAT_CDMASK 0x00000fff
#define BFE_STAT_SMASK 0x0000f000
#define BFE_STAT_DISABLE 0x00000000
#define BFE_STAT_SACTIVE 0x00001000
#define BFE_STAT_SIDLE 0x00002000
#define BFE_STAT_STOPPED 0x00003000
#define BFE_STAT_SSUSP 0x00004000
#define BFE_STAT_EMASK 0x000f0000
#define BFE_STAT_ENONE 0x00000000
#define BFE_STAT_EDPE 0x00010000
#define BFE_STAT_EDFU 0x00020000
#define BFE_STAT_EBEBR 0x00030000
#define BFE_STAT_EBEDA 0x00040000
#define BFE_STAT_FLUSHED 0x00100000
#define BFE_DMARX_CTRL 0x00000210
#define BFE_RX_CTRL_ENABLE 0x00000001
#define BFE_RX_CTRL_ROMASK 0x000000fe
#define BFE_RX_CTRL_ROSHIFT 1
#define BFE_DMARX_ADDR 0x00000214
#define BFE_DMARX_PTR 0x00000218
#define BFE_DMARX_STAT 0x0000021C
#define BFE_RXCONF 0x00000400
#define BFE_RXCONF_DBCAST 0x00000001
#define BFE_RXCONF_ALLMULTI 0x00000002
#define BFE_RXCONF_NORXTX 0x00000004
#define BFE_RXCONF_PROMISC 0x00000008
#define BFE_RXCONF_LPBACK 0x00000010
#define BFE_RXCONF_FLOW 0x00000020
#define BFE_RXCONF_ACCEPT 0x00000040
#define BFE_RXCONF_RFILT 0x00000080
#define BFE_RXMAXLEN 0x00000404
#define BFE_TXMAXLEN 0x00000408
#define BFE_MDIO_CTRL 0x00000410
#define BFE_MDIO_MAXF_MASK 0x0000007f
#define BFE_MDIO_PREAMBLE 0x00000080
#define BFE_MDIO_DATA 0x00000414
#define BFE_MDIO_DATA_DATA 0x0000ffff
#define BFE_MDIO_TA_MASK 0x00030000
#define BFE_MDIO_TA_SHIFT 16
#define BFE_MDIO_TA_VALID 2
#define BFE_MDIO_RA_MASK 0x007c0000
#define BFE_MDIO_PMD_MASK 0x0f800000
#define BFE_MDIO_OP_MASK 0x30000000
#define BFE_MDIO_SB_MASK 0xc0000000
#define BFE_MDIO_SB_START 0x40000000
#define BFE_MDIO_RA_SHIFT 18
#define BFE_MDIO_PMD_SHIFT 23
#define BFE_MDIO_OP_SHIFT 28
#define BFE_MDIO_OP_WRITE 1
#define BFE_MDIO_OP_READ 2
#define BFE_MDIO_SB_SHIFT 30
#define BFE_EMAC_IMASK 0x00000418
#define BFE_EMAC_ISTAT 0x0000041C
#define BFE_EMAC_INT_MII 0x00000001
#define BFE_EMAC_INT_MIB 0x00000002
#define BFE_EMAC_INT_FLOW 0x00000003
#define BFE_CAM_DATA_LO 0x00000420
#define BFE_CAM_DATA_HI 0x00000424
#define BFE_CAM_HI_VALID 0x00010000
#define BFE_CAM_CTRL 0x00000428
#define BFE_CAM_ENABLE 0x00000001
#define BFE_CAM_MSEL 0x00000002
#define BFE_CAM_READ 0x00000004
#define BFE_CAM_WRITE 0x00000008
#define BFE_CAM_INDEX_MASK 0x003f0000
#define BFE_CAM_BUSY 0x80000000
#define BFE_CAM_INDEX_SHIFT 16
#define BFE_ENET_CTRL 0x0000042C
#define BFE_ENET_ENABLE 0x00000001
#define BFE_ENET_DISABLE 0x00000002
#define BFE_ENET_SRST 0x00000004
#define BFE_ENET_EPSEL 0x00000008
#define BFE_TX_CTRL 0x00000430
#define BFE_TX_DUPLEX 0x00000001
#define BFE_TX_FMODE 0x00000002
#define BFE_TX_SBENAB 0x00000004
#define BFE_TX_SMALL_SLOT 0x00000008
#define BFE_TX_WMARK 0x00000434
#define BFE_MIB_CTRL 0x00000438
#define BFE_MIB_CLR_ON_READ 0x00000001
#define BFE_TX_GOOD_O 0x00000500
#define BFE_TX_GOOD_P 0x00000504
#define BFE_TX_O 0x00000508
#define BFE_TX_P 0x0000050C
#define BFE_TX_BCAST 0x00000510
#define BFE_TX_MCAST 0x00000514
#define BFE_TX_64 0x00000518
#define BFE_TX_65_127 0x0000051C
#define BFE_TX_128_255 0x00000520
#define BFE_TX_256_511 0x00000524
#define BFE_TX_512_1023 0x00000528
#define BFE_TX_1024_MAX 0x0000052C
#define BFE_TX_JABBER 0x00000530
#define BFE_TX_OSIZE 0x00000534
#define BFE_TX_FRAG 0x00000538
#define BFE_TX_URUNS 0x0000053C
#define BFE_TX_TCOLS 0x00000540
#define BFE_TX_SCOLS 0x00000544
#define BFE_TX_MCOLS 0x00000548
#define BFE_TX_ECOLS 0x0000054C
#define BFE_TX_LCOLS 0x00000550
#define BFE_TX_DEFERED 0x00000554
#define BFE_TX_CLOST 0x00000558
#define BFE_TX_PAUSE 0x0000055C
#define BFE_RX_GOOD_O 0x00000580
#define BFE_RX_GOOD_P 0x00000584
#define BFE_RX_O 0x00000588
#define BFE_RX_P 0x0000058C
#define BFE_RX_BCAST 0x00000590
#define BFE_RX_MCAST 0x00000594
#define BFE_RX_64 0x00000598
#define BFE_RX_65_127 0x0000059C
#define BFE_RX_128_255 0x000005A0
#define BFE_RX_256_511 0x000005A4
#define BFE_RX_512_1023 0x000005A8
#define BFE_RX_1024_MAX 0x000005AC
#define BFE_RX_JABBER 0x000005B0
#define BFE_RX_OSIZE 0x000005B4
#define BFE_RX_FRAG 0x000005B8
#define BFE_RX_MISS 0x000005BC
#define BFE_RX_CRCA 0x000005C0
#define BFE_RX_USIZE 0x000005C4
#define BFE_RX_CRC 0x000005C8
#define BFE_RX_ALIGN 0x000005CC
#define BFE_RX_SYM 0x000005D0
#define BFE_RX_PAUSE 0x000005D4
#define BFE_RX_NPAUSE 0x000005D8
#define BFE_SBIMSTATE 0x00000F90
#define BFE_PC 0x0000000f
#define BFE_AP_MASK 0x00000030
#define BFE_AP_BOTH 0x00000000
#define BFE_AP_TS 0x00000010
#define BFE_AP_TK 0x00000020
#define BFE_AP_RSV 0x00000030
#define BFE_IBE 0x00020000
#define BFE_TO 0x00040000
#define BFE_SBINTVEC 0x00000F94
#define BFE_INTVEC_PCI 0x00000001
#define BFE_INTVEC_ENET0 0x00000002
#define BFE_INTVEC_ILINE20 0x00000004
#define BFE_INTVEC_CODEC 0x00000008
#define BFE_INTVEC_USB 0x00000010
#define BFE_INTVEC_EXTIF 0x00000020
#define BFE_INTVEC_ENET1 0x00000040
#define BFE_SBTMSLOW 0x00000F98
#define BFE_RESET 0x00000001
#define BFE_REJECT 0x00000002
#define BFE_CLOCK 0x00010000
#define BFE_FGC 0x00020000
#define BFE_PE 0x40000000
#define BFE_BE 0x80000000
#define BFE_SBTMSHIGH 0x00000F9C
#define BFE_SERR 0x00000001
#define BFE_INT 0x00000002
#define BFE_BUSY 0x00000004
#define BFE_GCR 0x20000000
#define BFE_BISTF 0x40000000
#define BFE_BISTD 0x80000000
#define BFE_SBBWA0 0x00000FA0
#define BFE_TAB0_MASK 0x0000ffff
#define BFE_TAB1_MASK 0xffff0000
#define BFE_TAB0_SHIFT 0
#define BFE_TAB1_SHIFT 16
#define BFE_SBIMCFGLOW 0x00000FA8
#define BFE_STO_MASK 0x00000003
#define BFE_RTO_MASK 0x00000030
#define BFE_CID_MASK 0x00ff0000
#define BFE_RTO_SHIFT 4
#define BFE_CID_SHIFT 16
#define BFE_SBIMCFGHIGH 0x00000FAC
#define BFE_IEM_MASK 0x0000000c
#define BFE_TEM_MASK 0x00000030
#define BFE_BEM_MASK 0x000000c0
#define BFE_TEM_SHIFT 4
#define BFE_BEM_SHIFT 6
#define BFE_SBTMCFGLOW 0x00000FB8
#define BFE_LOW_CD_MASK 0x000000ff
#define BFE_LOW_CO_MASK 0x0000f800
#define BFE_LOW_IF_MASK 0x00fc0000
#define BFE_LOW_IM_MASK 0x03000000
#define BFE_LOW_CO_SHIFT 11
#define BFE_LOW_IF_SHIFT 18
#define BFE_LOW_IM_SHIFT 24
#define BFE_SBTMCFGHIGH 0x00000FBC
#define BFE_HIGH_BM_MASK 0x00000003
#define BFE_HIGH_RM_MASK 0x0000000C
#define BFE_HIGH_SM_MASK 0x00000030
#define BFE_HIGH_EM_MASK 0x00000300
#define BFE_HIGH_IM_MASK 0x00000c00
#define BFE_HIGH_RM_SHIFT 2
#define BFE_HIGH_SM_SHIFT 4
#define BFE_HIGH_EM_SHIFT 8
#define BFE_HIGH_IM_SHIFT 10
#define BFE_SBBCFG 0x00000FC0
#define BFE_LAT_MASK 0x00000003
#define BFE_MAX0_MASK 0x000f0000
#define BFE_MAX1_MASK 0x00f00000
#define BFE_MAX0_SHIFT 16
#define BFE_MAX1_SHIFT 20
#define BFE_SBBSTATE 0x00000FC8
#define BFE_SBBSTATE_SRD 0x00000001
#define BFE_SBBSTATE_HRD 0x00000002
#define BFE_SBACTCNFG 0x00000FD8
#define BFE_SBFLAGST 0x00000FE8
#define BFE_SBIDLOW 0x00000FF8
#define BFE_CS_MASK 0x00000003
#define BFE_AR_MASK 0x00000038
#define BFE_SYNCH 0x00000040
#define BFE_INIT 0x00000080
#define BFE_MINLAT_MASK 0x00000f00
#define BFE_MAXLAT_MASK 0x0000f000
#define BFE_FIRST 0x00010000
#define BFE_CW_MASK 0x000c0000
#define BFE_TP_MASK 0x00f00000
#define BFE_IP_MASK 0x0f000000
#define BFE_AR_SHIFT 3
#define BFE_MINLAT_SHIFT 8
#define BFE_MAXLAT_SHIFT 12
#define BFE_CW_SHIFT 18
#define BFE_TP_SHIFT 20
#define BFE_IP_SHIFT 24
#define BFE_SBIDHIGH 0x00000FFC
#define BFE_RC_MASK 0x0000000f
#define BFE_CC_MASK 0x0000fff0
#define BFE_VC_MASK 0xffff0000
#define BFE_CC_SHIFT 4
#define BFE_VC_SHIFT 16
#define BFE_CORE_ILINE20 0x801
#define BFE_CORE_SDRAM 0x803
#define BFE_CORE_PCI 0x804
#define BFE_CORE_MIPS 0x805
#define BFE_CORE_ENET 0x806
#define BFE_CORE_CODEC 0x807
#define BFE_CORE_USB 0x808
#define BFE_CORE_ILINE100 0x80a
#define BFE_CORE_EXTIF 0x811
#define BFE_BAR0_WIN 0x80
#define BFE_BAR1_WIN 0x84
#define BFE_SPROM_CONTROL 0x88
#define BFE_BAR1_CONTROL 0x8c
#define BFE_SSB_CONTROL 0x00000000
#define BFE_SSB_ARBCONTROL 0x00000010
#define BFE_SSB_ISTAT 0x00000020
#define BFE_SSB_IMASK 0x00000024
#define BFE_SSB_MBOX 0x00000028
#define BFE_SSB_BCAST_ADDR 0x00000050
#define BFE_SSB_BCAST_DATA 0x00000054
#define BFE_SSB_PCI_TRANS_0 0x00000100
#define BFE_SSB_PCI_TRANS_1 0x00000104
#define BFE_SSB_PCI_TRANS_2 0x00000108
#define BFE_SSB_SPROM 0x00000800
#define BFE_SSB_PCI_MEM 0x00000000
#define BFE_SSB_PCI_IO 0x00000001
#define BFE_SSB_PCI_CFG0 0x00000002
#define BFE_SSB_PCI_CFG1 0x00000003
#define BFE_SSB_PCI_PREF 0x00000004
#define BFE_SSB_PCI_BURST 0x00000008
#define BFE_SSB_PCI_MASK0 0xfc000000
#define BFE_SSB_PCI_MASK1 0xfc000000
#define BFE_SSB_PCI_MASK2 0xc0000000
#define BFE_DESC_LEN 0x00001fff
#define BFE_DESC_CMASK 0x0ff00000
#define BFE_DESC_EOT 0x10000000
#define BFE_DESC_IOC 0x20000000
#define BFE_DESC_EOF 0x40000000
#define BFE_DESC_SOF 0x80000000
#define BFE_RX_CP_THRESHOLD 256
#define BFE_RX_HEADER_LEN 28
#define BFE_RX_FLAG_OFIFO 0x00000001
#define BFE_RX_FLAG_CRCERR 0x00000002
#define BFE_RX_FLAG_SERR 0x00000004
#define BFE_RX_FLAG_ODD 0x00000008
#define BFE_RX_FLAG_LARGE 0x00000010
#define BFE_RX_FLAG_MCAST 0x00000020
#define BFE_RX_FLAG_BCAST 0x00000040
#define BFE_RX_FLAG_MISS 0x00000080
#define BFE_RX_FLAG_LAST 0x00000800
#define BFE_RX_FLAG_ERRORS (BFE_RX_FLAG_ODD | BFE_RX_FLAG_SERR | \
BFE_RX_FLAG_CRCERR | BFE_RX_FLAG_OFIFO)
#define BFE_MCAST_TBL_SIZE 32
#define BFE_PCI_DMA 0x40000000
#define BFE_REG_PCI 0x18002000
#define BCOM_VENDORID 0x14E4
#define BCOM_DEVICEID_BCM4401 0x4401
#define PCI_SETBIT(dev, reg, x, s) \
pci_write_config(dev, reg, (pci_read_config(dev, reg, s) | (x)), s)
#define PCI_CLRBIT(dev, reg, x, s) \
pci_write_config(dev, reg, (pci_read_config(dev, reg, s) & ~(x)), s)
#define BFE_RX_RING_SIZE 512
#define BFE_TX_RING_SIZE 512
#define BFE_LINK_DOWN 5
#define BFE_TX_LIST_CNT 511
#define BFE_RX_LIST_CNT 64
#define BFE_TX_LIST_SIZE BFE_TX_LIST_CNT * sizeof(struct bfe_desc)
#define BFE_RX_LIST_SIZE BFE_RX_LIST_CNT * sizeof(struct bfe_desc)
#define BFE_RX_OFFSET 30
#define BFE_TX_QLEN 256
#define CSR_READ_4(sc, reg) \
OSReadLittleInt32((sc)->bfe_bhandle, reg)
#define CSR_WRITE_4(sc, reg, val) \
do { OSWriteLittleInt32((sc)->bfe_bhandle, reg, val); \
OSSynchronizeIO(); } while(0)
#define BFE_OR(sc, name, val) \
CSR_WRITE_4(sc, name, CSR_READ_4(sc, name) | val)
#define BFE_AND(sc, name, val) \
CSR_WRITE_4(sc, name, CSR_READ_4(sc, name) & val)
#ifdef __APPLE__
#define BFE_LOCK(scp)
#define BFE_UNLOCK(scp)
#else
#define BFE_LOCK(scp) mtx_lock(&sc->bfe_mtx)
#define BFE_UNLOCK(scp) mtx_unlock(&sc->bfe_mtx)
#endif
#define BFE_INC(x, y) (x) = ((x) == ((y)-1)) ? 0 : (x)+1
#ifndef __APPLE__
struct bfe_data {
struct mbuf *bfe_mbuf;
bus_dmamap_t bfe_map;
};
#endif
struct bfe_desc {
volatile u_int32_t bfe_ctrl;
volatile u_int32_t bfe_addr;
};
struct bfe_rxheader {
volatile u_int16_t len;
volatile u_int16_t flags;
volatile u_int16_t pad[12];
};
struct bfe_hw_stats {
u_int32_t tx_good_octets, tx_good_pkts, tx_octets;
u_int32_t tx_pkts, tx_broadcast_pkts, tx_multicast_pkts;
u_int32_t tx_len_64, tx_len_65_to_127, tx_len_128_to_255;
u_int32_t tx_len_256_to_511, tx_len_512_to_1023, tx_len_1024_to_max;
u_int32_t tx_jabber_pkts, tx_oversize_pkts, tx_fragment_pkts;
u_int32_t tx_underruns, tx_total_cols, tx_single_cols;
u_int32_t tx_multiple_cols, tx_excessive_cols, tx_late_cols;
u_int32_t tx_defered, tx_carrier_lost, tx_pause_pkts;
u_int32_t __pad1[8];
u_int32_t rx_good_octets, rx_good_pkts, rx_octets;
u_int32_t rx_pkts, rx_broadcast_pkts, rx_multicast_pkts;
u_int32_t rx_len_64, rx_len_65_to_127, rx_len_128_to_255;
u_int32_t rx_len_256_to_511, rx_len_512_to_1023, rx_len_1024_to_max;
u_int32_t rx_jabber_pkts, rx_oversize_pkts, rx_fragment_pkts;
u_int32_t rx_missed_pkts, rx_crc_align_errs, rx_undersize;
u_int32_t rx_crc_errs, rx_align_errs, rx_symbol_errs;
u_int32_t rx_pause_pkts, rx_nonpause_pkts;
};
#ifdef __APPLE__
struct bfe_softc
{
void * bfe_dev;
void * bfe_bhandle;
u_int32_t bfe_tx_dma;
u_int32_t bfe_rx_dma;
u_int8_t bfe_phyaddr;
u_int8_t bfe_mdc_port;
u_int8_t bfe_unit;
};
#else
struct bfe_softc
{
struct arpcom arpcom;
device_t bfe_dev;
device_t bfe_miibus;
bus_space_handle_t bfe_bhandle;
vm_offset_t bfe_vhandle;
bus_space_tag_t bfe_btag;
bus_dma_tag_t bfe_tag;
bus_dma_tag_t bfe_parent_tag;
bus_dma_tag_t bfe_tx_tag, bfe_rx_tag;
bus_dmamap_t bfe_tx_map, bfe_rx_map;
void *bfe_intrhand;
struct resource *bfe_irq;
struct resource *bfe_res;
struct callout_handle bfe_stat_ch;
struct bfe_hw_stats bfe_hwstats;
struct bfe_desc *bfe_tx_list, *bfe_rx_list;
struct bfe_data bfe_tx_ring[BFE_TX_LIST_CNT];
struct bfe_data bfe_rx_ring[BFE_RX_LIST_CNT];
struct mtx bfe_mtx;
u_int32_t bfe_flags;
u_int32_t bfe_imask;
u_int32_t bfe_dma_offset;
u_int32_t bfe_tx_cnt, bfe_tx_cons, bfe_tx_prod;
u_int32_t bfe_rx_cnt, bfe_rx_prod, bfe_rx_cons;
u_int32_t bfe_tx_dma, bfe_rx_dma;
u_int32_t bfe_link;
u_int8_t bfe_phyaddr;
u_int8_t bfe_mdc_port;
u_int8_t bfe_unit;
u_int8_t bfe_core_unit;
u_int8_t bfe_up;
int bfe_if_flags;
char *bfe_vpd_prodname;
char *bfe_vpd_readonly;
};
#endif
struct bfe_type
{
u_int16_t bfe_vid;
u_int16_t bfe_did;
char *bfe_name;
};
__private_extern__ void
bfe_chip_halt( struct bfe_softc * sc );
__private_extern__ void
bfe_chip_reset( struct bfe_softc * sc );
__private_extern__ void
bfe_cam_write( struct bfe_softc * sc, u_char * data, int index );
__private_extern__ int
bfe_readphy( struct bfe_softc * sc, u_int32_t reg, u_int32_t * val );
__private_extern__ int
bfe_writephy( struct bfe_softc * sc, u_int32_t reg, u_int32_t val );
__private_extern__ int
bfe_setupphy( struct bfe_softc * sc );
__private_extern__ void
bfe_chip_enable( struct bfe_softc * sc );
__private_extern__ void
bfe_enable_interrupts( struct bfe_softc * sc );
__private_extern__ void
bfe_disable_interrupts( struct bfe_softc * sc);
__private_extern__ int
pci_read_config( void * device, unsigned offset, unsigned size );
__private_extern__ void
pci_write_config( void * device, unsigned offset, unsigned value, unsigned size);
#define BFE_BUFFER_SIZE (1518+32)
#endif