if_txvar.h revision 102138
1260684Skaiw/* $OpenBSD: if_txvar.h,v 1.7 1999/11/17 05:21:19 jason Exp $ */ 2260684Skaiw/* $FreeBSD: head/sys/dev/tx/if_txvar.h 102138 2002-08-19 20:36:08Z semenu $ */ 3260684Skaiw 4260684Skaiw/*- 5260684Skaiw * Copyright (c) 1997 Semen Ustimenko 6260684Skaiw * All rights reserved. 7260684Skaiw * 8260684Skaiw * Redistribution and use in source and binary forms, with or without 9260684Skaiw * modification, are permitted provided that the following conditions 10260684Skaiw * are met: 11260684Skaiw * 1. Redistributions of source code must retain the above copyright 12260684Skaiw * notice, this list of conditions and the following disclaimer. 13260684Skaiw * 2. Redistributions in binary form must reproduce the above copyright 14260684Skaiw * notice, this list of conditions and the following disclaimer in the 15260684Skaiw * documentation and/or other materials provided with the distribution. 16260684Skaiw * 17260684Skaiw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18260684Skaiw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19260684Skaiw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20260684Skaiw * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21260684Skaiw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22260684Skaiw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23260684Skaiw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24260684Skaiw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25260684Skaiw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26260684Skaiw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27260684Skaiw * SUCH DAMAGE. 28260684Skaiw */ 29260684Skaiw 30260684Skaiw/* 31260684Skaiw * Configuration 32260684Skaiw */ 33260684Skaiw/*#define EPIC_DEBUG 1*/ 34260684Skaiw/*#define EPIC_USEIOSPACE 1*/ 35260684Skaiw#define EPIC_EARLY_RX 1 36260684Skaiw 37260684Skaiw#ifndef ETHER_MAX_LEN 38260684Skaiw#define ETHER_MAX_LEN 1518 39260684Skaiw#endif 40260684Skaiw#ifndef ETHER_MIN_LEN 41260684Skaiw#define ETHER_MIN_LEN 64 42260684Skaiw#endif 43260684Skaiw#ifndef ETHER_CRC_LEN 44260684Skaiw#define ETHER_CRC_LEN 4 45260684Skaiw#endif 46260684Skaiw#define TX_RING_SIZE 16 /* Leave this a power of 2 */ 47260684Skaiw#define RX_RING_SIZE 16 /* And this too, to do not */ 48260684Skaiw /* confuse RX(TX)_RING_MASK */ 49260684Skaiw#define TX_RING_MASK (TX_RING_SIZE - 1) 50260684Skaiw#define RX_RING_MASK (RX_RING_SIZE - 1) 51260684Skaiw#define ETHER_MAX_FRAME_LEN (ETHER_MAX_LEN + ETHER_CRC_LEN) 52260684Skaiw 53260684Skaiw/* This is driver's structure to define EPIC descriptors */ 54260684Skaiwstruct epic_rx_buffer { 55260684Skaiw struct mbuf * mbuf; /* mbuf receiving packet */ 56260684Skaiw}; 57260684Skaiw 58260684Skaiwstruct epic_tx_buffer { 59260684Skaiw struct mbuf * mbuf; /* mbuf contained packet */ 60260684Skaiw}; 61260684Skaiw 62260684Skaiw/* PHY, known by tx driver */ 63#define EPIC_UNKN_PHY 0x0000 64#define EPIC_QS6612_PHY 0x0001 65#define EPIC_AC101_PHY 0x0002 66#define EPIC_LXT970_PHY 0x0003 67#define EPIC_SERIAL 0x0004 68 69/* Driver status structure */ 70typedef struct { 71 struct arpcom arpcom; 72#if defined(__OpenBSD__) 73 mii_data_t sc_mii; 74 struct device dev; 75#else /* __FreeBSD__ */ 76 struct resource *res; 77 struct resource *irq; 78 79 device_t miibus; 80 device_t dev; 81 struct callout_handle stat_ch; 82 83 u_int32_t unit; 84#endif 85 void *sc_ih; 86 bus_space_tag_t sc_st; 87 bus_space_handle_t sc_sh; 88 89 struct epic_rx_buffer rx_buffer[RX_RING_SIZE]; 90 struct epic_tx_buffer tx_buffer[TX_RING_SIZE]; 91 92 /* Each element of array MUST be aligned on dword */ 93 /* and bounded on PAGE_SIZE */ 94 struct epic_rx_desc *rx_desc; 95 struct epic_tx_desc *tx_desc; 96 struct epic_frag_list *tx_flist; 97 u_int32_t flags; 98 u_int32_t tx_threshold; 99 u_int32_t txcon; 100 u_int32_t miicfg; 101 u_int32_t cur_tx; 102 u_int32_t cur_rx; 103 u_int32_t dirty_tx; 104 u_int32_t pending_txs; 105 u_int16_t cardvend; 106 u_int16_t cardid; 107 struct mii_softc *physc; 108 u_int32_t phyid; 109 int serinst; 110} epic_softc_t; 111 112struct epic_type { 113 u_int16_t ven_id; 114 u_int16_t dev_id; 115 char *name; 116}; 117 118#if defined(EPIC_DEBUG) 119#define dprintf(a) printf a 120#else 121#define dprintf(a) 122#endif 123 124#if defined(__FreeBSD__) 125#define EPIC_FORMAT "tx%d" 126#define EPIC_ARGS(sc) (sc->unit) 127#define EPIC_BPFTAP_ARG(ifp) ifp 128#else /* __OpenBSD__ */ 129#define EPIC_FORMAT "%s" 130#define EPIC_ARGS(sc) (sc->sc_dev.dv_xname) 131#define EPIC_BPFTAP_ARG(ifp) (ifp)->if_bpf 132#endif 133 134#define sc_if arpcom.ac_if 135#define sc_macaddr arpcom.ac_enaddr 136 137#define CSR_WRITE_4(sc,reg,val) \ 138 bus_space_write_4( (sc)->sc_st, (sc)->sc_sh, (reg), (val) ) 139#define CSR_WRITE_2(sc,reg,val) \ 140 bus_space_write_2( (sc)->sc_st, (sc)->sc_sh, (reg), (val) ) 141#define CSR_WRITE_1(sc,reg,val) \ 142 bus_space_write_1( (sc)->sc_st, (sc)->sc_sh, (reg), (val) ) 143#define CSR_READ_4(sc,reg) \ 144 bus_space_read_4( (sc)->sc_st, (sc)->sc_sh, (reg) ) 145#define CSR_READ_2(sc,reg) \ 146 bus_space_read_2( (sc)->sc_st, (sc)->sc_sh, (reg) ) 147#define CSR_READ_1(sc,reg) \ 148 bus_space_read_1( (sc)->sc_st, (sc)->sc_sh, (reg) ) 149 150#define PHY_READ_2(sc,phy,reg) \ 151 epic_read_phy_reg((sc),(phy),(reg)) 152#define PHY_WRITE_2(sc,phy,reg,val) \ 153 epic_write_phy_reg((sc),(phy),(reg),(val)) 154 155/* Macro to get either mbuf cluster or nothing */ 156#define EPIC_MGETCLUSTER(m) \ 157 { MGETHDR((m),M_DONTWAIT,MT_DATA); \ 158 if (m) { \ 159 MCLGET((m),M_DONTWAIT); \ 160 if( 0 == ((m)->m_flags & M_EXT) ) { \ 161 m_freem(m); \ 162 (m) = NULL; \ 163 } \ 164 } \ 165 } 166 167