Home | History | Annotate | Line # | Download | only in ic
tulipvar.h revision 1.35
      1 /*	$NetBSD: tulipvar.h,v 1.35 2000/05/25 18:46:08 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 #ifndef _DEV_IC_TULIPVAR_H_
     41 #define	_DEV_IC_TULIPVAR_H_
     42 
     43 #include <sys/queue.h>
     44 #include <sys/callout.h>
     45 
     46 /*
     47  * Misc. definitions for the Digital Semiconductor ``Tulip'' (21x4x)
     48  * Ethernet controller family driver.
     49  */
     50 
     51 /*
     52  * Transmit descriptor list size.  This is arbitrary, but allocate
     53  * enough descriptors for 64 pending transmissions and 16 segments
     54  * per packet.  Since a descriptor holds 2 buffer addresses, that's
     55  * 8 descriptors per packet.  This MUST work out to a power of 2.
     56  */
     57 #define	TULIP_NTXSEGS		16
     58 
     59 #define	TULIP_TXQUEUELEN	64
     60 #define	TULIP_NTXDESC		(TULIP_TXQUEUELEN * TULIP_NTXSEGS)
     61 #define	TULIP_NTXDESC_MASK	(TULIP_NTXDESC - 1)
     62 #define	TULIP_NEXTTX(x)		((x + 1) & TULIP_NTXDESC_MASK)
     63 
     64 /*
     65  * Receive descriptor list size.  We have one Rx buffer per incoming
     66  * packet, so this logic is a little simpler.
     67  */
     68 #define	TULIP_NRXDESC		64
     69 #define	TULIP_NRXDESC_MASK	(TULIP_NRXDESC - 1)
     70 #define	TULIP_NEXTRX(x)		((x + 1) & TULIP_NRXDESC_MASK)
     71 
     72 /*
     73  * Control structures are DMA'd to the TULIP chip.  We allocate them in
     74  * a single clump that maps to a single DMA segment to make several things
     75  * easier.
     76  */
     77 struct tulip_control_data {
     78 	/*
     79 	 * The transmit descriptors.
     80 	 */
     81 	struct tulip_desc tcd_txdescs[TULIP_NTXDESC];
     82 
     83 	/*
     84 	 * The receive descriptors.
     85 	 */
     86 	struct tulip_desc tcd_rxdescs[TULIP_NRXDESC];
     87 
     88 	/*
     89 	 * The setup packet.
     90 	 */
     91 	u_int32_t tcd_setup_packet[TULIP_SETUP_PACKET_LEN / sizeof(u_int32_t)];
     92 };
     93 
     94 #define	TULIP_CDOFF(x)		offsetof(struct tulip_control_data, x)
     95 #define	TULIP_CDTXOFF(x)	TULIP_CDOFF(tcd_txdescs[(x)])
     96 #define	TULIP_CDRXOFF(x)	TULIP_CDOFF(tcd_rxdescs[(x)])
     97 #define	TULIP_CDSPOFF		TULIP_CDOFF(tcd_setup_packet)
     98 
     99 /*
    100  * Software state for transmit jobs.
    101  */
    102 struct tulip_txsoft {
    103 	struct mbuf *txs_mbuf;		/* head of our mbuf chain */
    104 	bus_dmamap_t txs_dmamap;	/* our DMA map */
    105 	int txs_firstdesc;		/* first descriptor in packet */
    106 	int txs_lastdesc;		/* last descriptor in packet */
    107 	int txs_ndescs;			/* number of descriptors */
    108 	SIMPLEQ_ENTRY(tulip_txsoft) txs_q;
    109 };
    110 
    111 SIMPLEQ_HEAD(tulip_txsq, tulip_txsoft);
    112 
    113 /*
    114  * Software state for receive jobs.
    115  */
    116 struct tulip_rxsoft {
    117 	struct mbuf *rxs_mbuf;		/* head of our mbuf chain */
    118 	bus_dmamap_t rxs_dmamap;	/* our DMA map */
    119 };
    120 
    121 /*
    122  * Type of Tulip chip we're dealing with.
    123  */
    124 typedef enum {
    125 	TULIP_CHIP_INVALID   = 0,	/* invalid chip type */
    126 	TULIP_CHIP_DE425     = 1,	/* DE-425 EISA */
    127 	TULIP_CHIP_21040     = 2,	/* DECchip 21040 */
    128 	TULIP_CHIP_21041     = 3,	/* DECchip 21041 */
    129 	TULIP_CHIP_21140     = 4,	/* DECchip 21140 */
    130 	TULIP_CHIP_21140A    = 5,	/* DECchip 21140A */
    131 	TULIP_CHIP_21142     = 6,	/* DECchip 21142 */
    132 	TULIP_CHIP_21143     = 7,	/* DECchip 21143 */
    133 	TULIP_CHIP_82C168    = 8,	/* Lite-On 82C168 PNIC */
    134 	TULIP_CHIP_82C169    = 9,	/* Lite-On 82C169 PNIC */
    135 	TULIP_CHIP_82C115    = 10,	/* Lite-On 82C115 PNIC II */
    136 	TULIP_CHIP_MX98713   = 11,	/* Macronix 98713 PMAC */
    137 	TULIP_CHIP_MX98713A  = 12,	/* Macronix 98713A PMAC */
    138 	TULIP_CHIP_MX98715   = 13,	/* Macronix 98715 PMAC */
    139 	TULIP_CHIP_MX98715A  = 14,	/* Macronix 98715A PMAC */
    140 	TULIP_CHIP_MX98725   = 15,	/* Macronix 98725 PMAC */
    141 	TULIP_CHIP_WB89C840F = 16,	/* Winbond 89C840F */
    142 	TULIP_CHIP_DM9102    = 17,	/* Davicom DM9102 */
    143 	TULIP_CHIP_AL981     = 18,	/* ADMtek AL981 */
    144 	TULIP_CHIP_AX88140   = 19,	/* ASIX AX88140 */
    145 	TULIP_CHIP_AX88141   = 20,	/* ASIX AX88141 */
    146 	TULIP_CHIP_X3201_3   = 21,	/* Xircom X3201-3 */
    147 } tulip_chip_t;
    148 
    149 #define	TULIP_CHIP_NAMES						\
    150 {									\
    151 	NULL,								\
    152 	"DE-425",							\
    153 	"DECchip 21040",						\
    154 	"DECchip 21041",						\
    155 	"DECchip 21140",						\
    156 	"DECchip 21140A",						\
    157 	"DECchip 21142",						\
    158 	"DECchip 21143",						\
    159 	"Lite-On 82C168",						\
    160 	"Lite-On 82C169",						\
    161 	"Lite-On 82C115",						\
    162 	"Macronix MX98713",						\
    163 	"Macronix MX98713A",						\
    164 	"Macronix MX98715",						\
    165 	"Macronix MX98715A",						\
    166 	"Macronix MX98725",						\
    167 	"Winbond 89C840F",						\
    168 	"Davicom DM9102",						\
    169 	"ADMtek AL981",							\
    170 	"ASIX AX88140",							\
    171 	"ASIX AX88141",							\
    172 	"Xircom X3201-3",						\
    173 }
    174 
    175 struct tulip_softc;
    176 
    177 /*
    178  * Media init, change, status function pointers.
    179  */
    180 struct tulip_mediasw {
    181 	void	(*tmsw_init) __P((struct tulip_softc *));
    182 	void	(*tmsw_get) __P((struct tulip_softc *, struct ifmediareq *));
    183 	int	(*tmsw_set) __P((struct tulip_softc *));
    184 };
    185 
    186 /*
    187  * Table which describes the transmit threshold mode.  We generally
    188  * start at index 0.  Whenever we get a transmit underrun, we increment
    189  * our index, falling back if we encounter the NULL terminator.
    190  */
    191 struct tulip_txthresh_tab {
    192 	u_int32_t txth_opmode;		/* OPMODE bits */
    193 	const char *txth_name;		/* name of mode */
    194 };
    195 
    196 #define	TLP_TXTHRESH_TAB_10 {						\
    197 	{ OPMODE_TR_72,		"72 bytes" },				\
    198 	{ OPMODE_TR_96,		"96 bytes" },				\
    199 	{ OPMODE_TR_128,	"128 bytes" },				\
    200 	{ OPMODE_TR_160,	"160 bytes" },				\
    201 	{ 0,			NULL },					\
    202 }
    203 
    204 #define	TLP_TXTHRESH_TAB_10_100 {					\
    205 	{ OPMODE_TR_72,		"72/128 bytes" },			\
    206 	{ OPMODE_TR_96,		"96/256 bytes" },			\
    207 	{ OPMODE_TR_128,	"128/512 bytes" },			\
    208 	{ OPMODE_TR_160,	"160/1024 bytes" },			\
    209 	{ OPMODE_SF,		"store and forward mode" },		\
    210 	{ 0,			NULL },					\
    211 }
    212 
    213 #define	TXTH_72			0
    214 #define	TXTH_96			1
    215 #define	TXTH_128		2
    216 #define	TXTH_160		3
    217 #define	TXTH_SF			4
    218 
    219 /*
    220  * The Winbond 89C840F does transmit threshold control totally
    221  * differently.  It simply has a 7-bit field which indicates
    222  * the threshold:
    223  *
    224  *	txth = ((OPMODE & OPMODE_WINB_TTH) >> OPMODE_WINB_TTH_SHIFT) * 16;
    225  *
    226  * However, we just do Store-and-Forward mode on these chips, since
    227  * the DMA engines seem to be flaky.
    228  */
    229 #define	TLP_TXTHRESH_TAB_WINB {						\
    230 	{ 0,			"store and forward mode" },		\
    231 	{ 0,			NULL },					\
    232 }
    233 
    234 #define	TXTH_WINB_SF		0
    235 
    236 /*
    237  * Settings for Tulip SIA media.
    238  */
    239 struct tulip_sia_media {
    240 	u_int32_t	tsm_siaconn;	/* CSR13 value */
    241 	u_int32_t	tsm_siatxrx;	/* CSR14 value */
    242 	u_int32_t	tsm_siagen;	/* CSR15 value */
    243 };
    244 
    245 /*
    246  * Description of 2x14x media.
    247  */
    248 struct tulip_21x4x_media {
    249 	int		tm_type;	/* type of media; see tulipreg.h */
    250 	const char	*tm_name;	/* name of media */
    251 
    252 	void		(*tm_get) __P((struct tulip_softc *,
    253 			    struct ifmediareq *));
    254 	int		(*tm_set) __P((struct tulip_softc *));
    255 
    256 	int		tm_phyno;	/* PHY # on MII */
    257 
    258 	int		tm_gp_length;	/* MII select sequence length */
    259 	int		tm_gp_offset;	/* MII select sequence offset */
    260 
    261 	int		tm_reset_length;/* MII reset sequence length */
    262 	int		tm_reset_offset;/* MII reset sequence offset */
    263 
    264 	u_int32_t	tm_opmode;	/* OPMODE bits for this media */
    265 	u_int32_t	tm_gpctl;	/* GPIO control bits for this media */
    266 	u_int32_t	tm_gpdata;	/* GPIO bits for this media */
    267 	u_int32_t	tm_actmask;	/* `active' bits for this data */
    268 	u_int32_t	tm_actdata;	/* active high/low info */
    269 
    270 	struct tulip_sia_media tm_sia;	/* SIA settings */
    271 #define	tm_siaconn	tm_sia.tsm_siaconn
    272 #define	tm_siatxrx	tm_sia.tsm_siatxrx
    273 #define	tm_siagen	tm_sia.tsm_siagen
    274 };
    275 
    276 /*
    277  * Table for converting Tulip SROM media info into ifmedia data.
    278  */
    279 struct tulip_srom_to_ifmedia {
    280 	u_int8_t	tsti_srom;	/* SROM media type */
    281 	int		tsti_subtype;	/* ifmedia subtype */
    282 	int		tsti_options;	/* ifmedia options */
    283 	const char	*tsti_name;	/* media name */
    284 
    285 	u_int32_t	tsti_opmode;	/* OPMODE bits for this media */
    286 
    287 	/*
    288 	 * Settings for 21040, 21041, and 21142/21143 SIA, in the event
    289 	 * the SROM doesn't have them.
    290 	 */
    291 	struct tulip_sia_media tsti_21040;
    292 	struct tulip_sia_media tsti_21041;
    293 	struct tulip_sia_media tsti_21142;
    294 };
    295 
    296 /*
    297  * Some misc. statics, useful for debugging.
    298  */
    299 struct tulip_stats {
    300 	u_long		ts_tx_uf;	/* transmit underflow errors */
    301 	u_long		ts_tx_to;	/* transmit jabber timeouts */
    302 	u_long		ts_tx_ec;	/* excessve collision count */
    303 	u_long		ts_tx_lc;	/* late collision count */
    304 };
    305 
    306 /*
    307  * Software state per device.
    308  */
    309 struct tulip_softc {
    310 	struct device sc_dev;		/* generic device information */
    311 	bus_space_tag_t sc_st;		/* bus space tag */
    312 	bus_space_handle_t sc_sh;	/* bus space handle */
    313 	bus_dma_tag_t sc_dmat;		/* bus DMA tag */
    314 	struct ethercom sc_ethercom;	/* ethernet common data */
    315 	void *sc_sdhook;		/* shutdown hook */
    316 	void *sc_powerhook;		/* power management hook */
    317 
    318 	struct tulip_stats sc_stats;	/* debugging stats */
    319 
    320 	/*
    321 	 * Contents of the SROM.
    322 	 */
    323 	u_int8_t *sc_srom;
    324 	int sc_srom_addrbits;
    325 
    326 	/*
    327 	 * Media access functions for this chip.
    328 	 */
    329 	const struct tulip_mediasw *sc_mediasw;
    330 	mii_bitbang_ops_t sc_bitbang_ops;
    331 
    332 	/*
    333 	 * For chips with built-in NWay blocks, these are state
    334 	 * variables required for autonegotiation.
    335 	 */
    336 	int		sc_nway_ticks;	/* tick counter */
    337 	struct ifmedia_entry *sc_nway_active; /* the active media */
    338 	struct callout	sc_nway_callout;
    339 
    340 	tulip_chip_t	sc_chip;	/* chip type */
    341 	int		sc_rev;		/* chip revision */
    342 	int		sc_flags;	/* misc flags. */
    343 	char		sc_name[16];	/* board name */
    344 	u_int32_t	sc_cacheline;	/* cache line size */
    345 	int		sc_devno;	/* PCI device # */
    346 
    347 	struct mii_data sc_mii;		/* MII/media information */
    348 
    349 	const struct tulip_txthresh_tab *sc_txth;
    350 	int		sc_txthresh;	/* current transmit threshold */
    351 
    352 	u_int8_t	sc_gp_dir;	/* GPIO pin direction bits (21140) */
    353 	int		sc_media_seen;	/* ISV media block types seen */
    354 	int		sc_tlp_minst;	/* Tulip internal media instance */
    355 
    356 	/* Reset function. */
    357 	void		(*sc_reset) __P((struct tulip_softc *));
    358 
    359 	/* Pre-init function. */
    360 	void		(*sc_preinit) __P((struct tulip_softc *));
    361 
    362 	/* Filter setup function. */
    363 	void		(*sc_filter_setup) __P((struct tulip_softc *));
    364 
    365 	/* Media status update function. */
    366 	void		(*sc_statchg) __P((struct device *));
    367 
    368 	/* Media tick function. */
    369 	void		(*sc_tick) __P((void *));
    370 	struct callout sc_tick_callout;
    371 
    372 	/* Power management hooks. */
    373 	int		(*sc_enable) __P((struct tulip_softc *));
    374 	void		(*sc_disable) __P((struct tulip_softc *));
    375 	void		(*sc_power) __P((struct tulip_softc *, int));
    376 
    377 	/*
    378 	 * The Winbond 89C840F places registers 4 bytes apart, instead
    379 	 * of 8.
    380 	 */
    381 	int		sc_regshift;
    382 
    383 	u_int32_t	sc_busmode;	/* copy of CSR_BUSMODE */
    384 	u_int32_t	sc_opmode;	/* copy of CSR_OPMODE */
    385 	u_int32_t	sc_inten;	/* copy of CSR_INTEN */
    386 
    387 	u_int32_t	sc_rxint_mask;	/* mask of Rx interrupts we want */
    388 	u_int32_t	sc_txint_mask;	/* mask of Tx interrupts we want */
    389 
    390 	u_int32_t	sc_filtmode;	/* filter mode we're using */
    391 
    392 	bus_dma_segment_t sc_cdseg;	/* control data memory */
    393 	int		sc_cdnseg;	/* number of segments */
    394 	bus_dmamap_t sc_cddmamap;	/* control data DMA map */
    395 #define	sc_cddma	sc_cddmamap->dm_segs[0].ds_addr
    396 
    397 	/*
    398 	 * Software state for transmit and receive descriptors.
    399 	 */
    400 	struct tulip_txsoft sc_txsoft[TULIP_TXQUEUELEN];
    401 	struct tulip_rxsoft sc_rxsoft[TULIP_NRXDESC];
    402 
    403 	/*
    404 	 * Control data structures.
    405 	 */
    406 	struct tulip_control_data *sc_control_data;
    407 #define	sc_txdescs	sc_control_data->tcd_txdescs
    408 #define	sc_rxdescs	sc_control_data->tcd_rxdescs
    409 #define	sc_setup_desc	sc_control_data->tcd_setup_desc
    410 
    411 	int	sc_txfree;		/* number of free Tx descriptors */
    412 	int	sc_txnext;		/* next ready Tx descriptor */
    413 	int	sc_ntxsegs;		/* number of transmit segs per pkt */
    414 
    415 	u_int32_t sc_tdctl_ch;		/* conditional desc chaining */
    416 	u_int32_t sc_tdctl_er;		/* conditional desc end-of-ring */
    417 
    418 	u_int32_t sc_setup_fsls;	/* FS|LS on setup descriptor */
    419 
    420 	struct tulip_txsq sc_txfreeq;	/* free Tx descsofts */
    421 	struct tulip_txsq sc_txdirtyq;	/* dirty Tx descsofts */
    422 
    423 	int	sc_rxptr;		/* next ready RX descriptor/descsoft */
    424 };
    425 
    426 /* sc_flags */
    427 #define	TULIPF_WANT_SETUP	0x00000001	/* want filter setup */
    428 #define	TULIPF_DOING_SETUP	0x00000002	/* doing multicast setup */
    429 #define	TULIPF_HAS_MII		0x00000004	/* has media on MII */
    430 #define	TULIPF_IC_FS		0x00000008	/* IC bit on first tx seg */
    431 #define	TULIPF_MRL		0x00000010	/* memory read line okay */
    432 #define	TULIPF_MRM		0x00000020	/* memory read multi okay */
    433 #define	TULIPF_MWI		0x00000040	/* memory write inval okay */
    434 #define	TULIPF_AUTOPOLL		0x00000080	/* chip supports auto-poll */
    435 #define	TULIPF_LINK_UP		0x00000100	/* link is up (non-MII) */
    436 #define	TULIPF_LINK_VALID	0x00000200	/* link state valid */
    437 #define	TULIPF_DOINGAUTO	0x00000400	/* doing autoneg (non-MII) */
    438 #define	TULIPF_ATTACHED		0x00000800	/* attach has succeeded */
    439 #define	TULIPF_ENABLED		0x00001000	/* chip is enabled */
    440 
    441 #define	TULIP_IS_ENABLED(sc)	((sc)->sc_flags & TULIPF_ENABLED)
    442 
    443 /*
    444  * This macro returns the current media entry for *non-MII* media.
    445  */
    446 #define	TULIP_CURRENT_MEDIA(sc)						\
    447 	(IFM_SUBTYPE((sc)->sc_mii.mii_media.ifm_cur->ifm_media) != IFM_AUTO ? \
    448 	 (sc)->sc_mii.mii_media.ifm_cur : (sc)->sc_nway_active)
    449 
    450 /*
    451  * This macro determines if a change to media-related OPMODE bits requires
    452  * a chip reset.
    453  */
    454 #define	TULIP_MEDIA_NEEDSRESET(sc, newbits)				\
    455 	(((sc)->sc_opmode & OPMODE_MEDIA_BITS) !=			\
    456 	 ((newbits) & OPMODE_MEDIA_BITS))
    457 
    458 #define	TULIP_CDTXADDR(sc, x)	((sc)->sc_cddma + TULIP_CDTXOFF((x)))
    459 #define	TULIP_CDRXADDR(sc, x)	((sc)->sc_cddma + TULIP_CDRXOFF((x)))
    460 
    461 #define	TULIP_CDSPADDR(sc)	((sc)->sc_cddma + TULIP_CDSPOFF)
    462 
    463 #define	TULIP_CDSP(sc)		((sc)->sc_control_data->tcd_setup_packet)
    464 
    465 #define	TULIP_CDTXSYNC(sc, x, n, ops)					\
    466 do {									\
    467 	int __x, __n;							\
    468 									\
    469 	__x = (x);							\
    470 	__n = (n);							\
    471 									\
    472 	/* If it will wrap around, sync to the end of the ring. */	\
    473 	if ((__x + __n) > TULIP_NTXDESC) {				\
    474 		bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,	\
    475 		    TULIP_CDTXOFF(__x), sizeof(struct tulip_desc) *	\
    476 		    (TULIP_NTXDESC - __x), (ops));			\
    477 		__n -= (TULIP_NTXDESC - __x);				\
    478 		__x = 0;						\
    479 	}								\
    480 									\
    481 	/* Now sync whatever is left. */				\
    482 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    483 	    TULIP_CDTXOFF(__x), sizeof(struct tulip_desc) * __n, (ops)); \
    484 } while (0)
    485 
    486 #define	TULIP_CDRXSYNC(sc, x, ops)					\
    487 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    488 	    TULIP_CDRXOFF((x)), sizeof(struct tulip_desc), (ops))
    489 
    490 #define	TULIP_CDSPSYNC(sc, ops)						\
    491 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    492 	    TULIP_CDSPOFF, TULIP_SETUP_PACKET_LEN, (ops))
    493 
    494 /*
    495  * Note we rely on MCLBYTES being a power of two.  Because the `length'
    496  * field is only 11 bits, we must subtract 1 from the length to avoid
    497  * having it truncated to 0!
    498  */
    499 #define	TULIP_INIT_RXDESC(sc, x)					\
    500 do {									\
    501 	struct tulip_rxsoft *__rxs = &sc->sc_rxsoft[(x)];		\
    502 	struct tulip_desc *__rxd = &sc->sc_rxdescs[(x)];		\
    503 	struct mbuf *__m = __rxs->rxs_mbuf;				\
    504 									\
    505 	__m->m_data = __m->m_ext.ext_buf;				\
    506 	__rxd->td_bufaddr1 =						\
    507 	    htole32(__rxs->rxs_dmamap->dm_segs[0].ds_addr);		\
    508 	__rxd->td_bufaddr2 =						\
    509 	    htole32(TULIP_CDRXADDR((sc), TULIP_NEXTRX((x))));		\
    510 	__rxd->td_ctl =							\
    511 	    htole32((((__m->m_ext.ext_size - 1) & ~0x3U)		\
    512 	    << TDCTL_SIZE1_SHIFT) | (sc)->sc_tdctl_ch |			\
    513 	    ((x) == (TULIP_NRXDESC - 1) ? sc->sc_tdctl_er : 0));	\
    514 	__rxd->td_status = htole32(TDSTAT_OWN|TDSTAT_Rx_FS|TDSTAT_Rx_LS); \
    515 	TULIP_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
    516 } while (0)
    517 
    518 /* CSR access */
    519 #define	TULIP_CSR_OFFSET(sc, csr)					\
    520 	(TULIP_CSR_INDEX(csr) << (sc)->sc_regshift)
    521 
    522 #define	TULIP_READ(sc, reg)						\
    523 	bus_space_read_4((sc)->sc_st, (sc)->sc_sh,			\
    524 	    TULIP_CSR_OFFSET((sc), (reg)))
    525 
    526 #define	TULIP_WRITE(sc, reg, val)					\
    527 	bus_space_write_4((sc)->sc_st, (sc)->sc_sh,			\
    528 	    TULIP_CSR_OFFSET((sc), (reg)), (val))
    529 
    530 #define	TULIP_SET(sc, reg, mask)					\
    531 	TULIP_WRITE((sc), (reg), TULIP_READ((sc), (reg)) | (mask))
    532 
    533 #define	TULIP_CLR(sc, reg, mask)					\
    534 	TULIP_WRITE((sc), (reg), TULIP_READ((sc), (reg)) & ~(mask))
    535 
    536 #define	TULIP_ISSET(sc, reg, mask)					\
    537 	(TULIP_READ((sc), (reg)) & (mask))
    538 
    539 #if BYTE_ORDER == BIG_ENDIAN
    540 #define	TULIP_SP_FIELD_C(x)	((x) << 16)
    541 #else
    542 #define	TULIP_SP_FIELD_C(x)	(x)
    543 #endif
    544 #define	TULIP_SP_FIELD(x, f)	TULIP_SP_FIELD_C(((u_int16_t *)(x))[(f)])
    545 
    546 #ifdef _KERNEL
    547 extern const char *tlp_chip_names[];
    548 
    549 extern const struct tulip_mediasw tlp_21040_mediasw;
    550 extern const struct tulip_mediasw tlp_21040_tp_mediasw;
    551 extern const struct tulip_mediasw tlp_21040_auibnc_mediasw;
    552 extern const struct tulip_mediasw tlp_21041_mediasw;
    553 extern const struct tulip_mediasw tlp_2114x_isv_mediasw;
    554 extern const struct tulip_mediasw tlp_sio_mii_mediasw;
    555 extern const struct tulip_mediasw tlp_pnic_mediasw;
    556 extern const struct tulip_mediasw tlp_pmac_mediasw;
    557 extern const struct tulip_mediasw tlp_al981_mediasw;
    558 
    559 void	tlp_attach __P((struct tulip_softc *, const u_int8_t *));
    560 int	tlp_activate __P((struct device *, enum devact));
    561 int	tlp_detach __P((struct tulip_softc *));
    562 int	tlp_intr __P((void *));
    563 int	tlp_read_srom __P((struct tulip_softc *));
    564 int	tlp_srom_crcok __P((const u_int8_t *));
    565 int	tlp_isv_srom __P((const u_int8_t *));
    566 int	tlp_isv_srom_enaddr __P((struct tulip_softc *, u_int8_t *));
    567 int	tlp_parse_old_srom __P((struct tulip_softc *, u_int8_t *));
    568 
    569 int	tlp_mediachange __P((struct ifnet *));
    570 void	tlp_mediastatus __P((struct ifnet *, struct ifmediareq *));
    571 #endif /* _KERNEL */
    572 
    573 #endif /* _DEV_IC_TULIPVAR_H_ */
    574