Home | History | Annotate | Line # | Download | only in dev
if_snvar.h revision 1.8
      1 /*	$NetBSD: if_snvar.h,v 1.8 1997/04/25 03:40:09 briggs Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1991   Algorithmics Ltd (http://www.algor.co.uk)
      5  * You may use, copy, and modify this program so long as you retain the
      6  * copyright line.
      7  */
      8 
      9 /*
     10  * if_snvar.h -- National Semiconductor DP83932BVF (SONIC) NetBSD/mac68k vars
     11  */
     12 
     13 /*
     14  * Memory access macros. Since we handle SONIC in 16 bit mode (PB5X0)
     15  * and 32 bit mode (everything else) using a single GENERIC kernel
     16  * binary, all structures have to be accessed using macros which can
     17  * adjust the offsets appropriately.
     18  */
     19 #define	SWO(m, a, o, x)	(m ? (*(u_int32_t *)((u_int32_t *)a + o) = (x)) : \
     20 			     (*(u_int16_t *)((u_int16_t *)a + o) = (x)))
     21 #define	SRO(m, a, o)	(m ? (*(u_int32_t *)((u_int32_t *)a + o) & 0xffff) : \
     22 			     (*(u_int16_t *)((u_int16_t *)a + o) & 0xffff))
     23 
     24 /*
     25  * Register access macros. We use bus_space_* to talk to the Sonic
     26  * registers. A mapping table is used in case a particular configuration
     27  * hooked the regs up at non-word offsets.
     28  */
     29 #define	NIC_GET(sc, reg)	(bus_space_read_2((sc)->sc_regt,	\
     30 					(sc)->sc_regh,			\
     31 					((sc)->sc_reg_map[reg])))
     32 #define	NIC_PUT(sc, reg, val)	(bus_space_write_2((sc)->sc_regt,	\
     33 					(sc)->sc_regh,			\
     34 					((sc)->sc_reg_map[reg]),	\
     35 					(val)))
     36 #define	SN_REGSIZE	SN_NREGS*4
     37 
     38 /* mac68k does not have any write buffers to flush... */
     39 #define	wbflush()
     40 
     41 /*
     42  * buffer sizes in 32 bit mode
     43  * 1 TXpkt is 4 hdr words + (3 * FRAGMAX) + 1 link word == 23 words == 92 bytes
     44  *
     45  * 1 RxPkt is 7 words == 28 bytes
     46  * 1 Rda   is 4 words == 16 bytes
     47  *
     48  * The CDA is 17 words == 68 bytes
     49  *
     50  * total space in page 0 = NTDA * 92 + NRRA * 16 + NRDA * 28 + 68
     51  */
     52 
     53 #define NRBA    8		/* # receive buffers < NRRA */
     54 #define RBAMASK (NRBA-1)
     55 #define NRDA    146
     56 #define NTDA    8		/* # transmit descriptors */
     57 #define NRRA    16		/* # receive resource descriptors */
     58 #define RRAMASK (NRRA-1)	/* the reason why NRRA must be power of two */
     59 
     60 #define FCSSIZE 4		/* size of FCS appended to packets */
     61 
     62 /*
     63  * maximum receive packet size plus 2 byte pad to make each
     64  * one aligned. 4 byte slop (required for eobc)
     65  */
     66 #define RBASIZE(sc)	(sizeof(struct ether_header) + ETHERMTU + FCSSIZE + \
     67 			 ((sc)->bitmode ? 6 : 2))
     68 
     69 /*
     70  * transmit buffer area
     71  */
     72 #define NTXB	NTDA	/* Number of xmit buffers */
     73 #define TXBSIZE	1536	/* 6*2^8 -- the same size as the 8390 TXBUF */
     74 
     75 #define	SN_NPAGES	2 + 8 + 4
     76 
     77 /*
     78  * Statistics collected over time
     79  */
     80 struct sn_stats {
     81 	int	ls_opacks;	/* packets transmitted */
     82 	int	ls_ipacks;	/* packets received */
     83 	int	ls_tdr;		/* contents of tdr after collision */
     84 	int	ls_tdef;	/* packets where had to wait */
     85 	int	ls_tone;	/* packets with one retry */
     86 	int	ls_tmore;	/* packets with more than one retry */
     87 	int	ls_tbuff;	/* transmit buff errors */
     88 	int	ls_tuflo;	/*    "     uflo   "    */
     89 	int	ls_tlcol;
     90 	int	ls_tlcar;
     91 	int	ls_trtry;
     92 	int	ls_rbuff;	/* receive buff errors */
     93 	int	ls_rfram;	/* framing     */
     94 	int	ls_roflo;	/* overflow    */
     95 	int	ls_rcrc;
     96 	int	ls_rrng;	/* rx ring sequence error */
     97 	int	ls_babl;	/* chip babl error */
     98 	int	ls_cerr;	/* collision error */
     99 	int	ls_miss;	/* missed packet */
    100 	int	ls_merr;	/* memory error */
    101 	int	ls_copies;	/* copies due to out of range mbufs */
    102 	int	ls_maxmbufs;	/* max mbufs on transmit */
    103 	int	ls_maxslots;	/* max ring slots on transmit */
    104 };
    105 
    106 typedef struct mtd {
    107 	void		*mtd_txp;
    108 	int		mtd_vtxp;
    109 	unsigned char	*mtd_buf;
    110 } mtd_t;
    111 
    112 /*
    113  * The sn_softc for Mac68k if_sn.
    114  */
    115 typedef struct sn_softc {
    116 	struct	device sc_dev;
    117 	struct	ethercom sc_ethercom;
    118 #define	sc_if		sc_ethercom.ec_if	/* network visible interface */
    119 
    120 	bus_space_tag_t		sc_regt;
    121 	bus_space_handle_t	sc_regh;
    122 
    123 	struct sn_stats	sc_sum;
    124 	short		sc_iflags;
    125 	unsigned short	bitmode;	/* 32 bit mode == 1, 16 == 0 */
    126 	bus_size_t	sc_reg_map[SN_NREGS];	/* register offsets */
    127 
    128 	u_int16_t	snr_dcr;	/* DCR for this instance */
    129 	u_int16_t	snr_dcr2;	/* DCR2 for this instance */
    130 	int	slotno;			/* Slot number */
    131 
    132 	int	sc_rxmark;		/* pos. in rx ring for reading buffs */
    133 	int	sc_rramark;		/* index into p_rra of wp */
    134 	void *p_rra[NRRA];		/* RX resource descs */
    135 	int	v_rra[NRRA];		/* DMA addresses of p_rra */
    136 	int	v_rea;			/* ptr to the end of the rra space */
    137 
    138 	int	sc_rdamark;
    139 	void *p_rda[NRDA];
    140 	int	v_rda[NRDA];
    141 
    142 	caddr_t	rbuf[NRBA];
    143 
    144 	int	sc_missed;		/* missed packet counter */
    145 
    146 	int	txb_cnt;		/* total number of xmit buffers */
    147 	int	txb_inuse;		/* number of active xmit buffers */
    148 	int	txb_new;		/* index of next open slot. */
    149 
    150 	struct mtd	mtda[NTDA];
    151 	int		mtd_hw;		/* idx of first mtd given to hw */
    152 	int		mtd_prev;	/* idx of last mtd given to hardware */
    153 	int		mtd_free;	/* next free mtd to use */
    154 	int		mtd_tlinko;	/*
    155 					 * offset of tlink of last txp given
    156 					 * to SONIC. Need to clear EOL on
    157 					 * this word to add a desc.
    158 					 */
    159 
    160 	caddr_t		tbuf[NTXB];
    161 	int		vtbuf[NTXB];	/* DMA address of tbuf */
    162 
    163 	void		*p_cda;
    164 	int		v_cda;
    165 
    166 	unsigned char	*space;
    167 } sn_softc_t;
    168 
    169 /*
    170  * Accessing SONIC data structures and registers as 32 bit values
    171  * makes code endianess independent.  The SONIC is however always in
    172  * bigendian mode so it is necessary to ensure that data structures shared
    173  * between the CPU and the SONIC are always in bigendian order.
    174  */
    175 
    176 /*
    177  * Receive Resource Descriptor
    178  * This structure describes the buffers into which packets
    179  * will be received.  Note that more than one packet may be
    180  * packed into a single buffer if constraints permit.
    181  */
    182 #define	RXRSRC_PTRLO	0	/* buffer address LO */
    183 #define	RXRSRC_PTRHI	1	/* buffer address HI */
    184 #define	RXRSRC_WCLO	2	/* buffer size (16bit words) LO */
    185 #define	RXRSRC_WCHI	3	/* buffer size (16bit words) HI */
    186 
    187 #define	RXRSRC_SIZE(sc)	(sc->bitmode ? (4 * 4) : (4 * 2))
    188 
    189 /*
    190  * Receive Descriptor
    191  * This structure holds information about packets received.
    192  */
    193 #define	RXPKT_STATUS	0
    194 #define	RXPKT_BYTEC	1
    195 #define	RXPKT_PTRLO	2
    196 #define	RXPKT_PTRHI	3
    197 #define	RXPKT_SEQNO	4
    198 #define	RXPKT_RLINK	5
    199 #define	RXPKT_INUSE	6
    200 #define	RXPKT_SIZE(sc)	(sc->bitmode ? (7 * 4) : (7 * 2))
    201 
    202 #define RBASEQ(x) (((x)>>8)&0xff)
    203 #define PSNSEQ(x) ((x) & 0xff)
    204 
    205 /*
    206  * Transmit Descriptor
    207  * This structure holds information about packets to be transmitted.
    208  */
    209 #define FRAGMAX	8		/* maximum number of fragments in a packet */
    210 
    211 #define	TXP_STATUS	0	/* + transmitted packet status */
    212 #define	TXP_CONFIG	1	/* transmission configuration */
    213 #define	TXP_PKTSIZE	2	/* entire packet size in bytes */
    214 #define	TXP_FRAGCNT	3	/* # fragments in packet */
    215 
    216 #define	TXP_FRAGOFF	4	/* offset to first fragment */
    217 #define	TXP_FRAGSIZE	3	/* size of each fragment desc */
    218 #define	TXP_FPTRLO	0	/* ptr to packet fragment LO */
    219 #define	TXP_FPTRHI	1	/* ptr to packet fragment HI */
    220 #define	TXP_FSIZE	2	/* fragment size */
    221 
    222 #define	TXP_WORDS	TXP_FRAGOFF + (FRAGMAX*TXP_FRAGSIZE) + 1	/* 1 for tlink */
    223 #define	TXP_SIZE(sc)	((sc->bitmode) ? (TXP_WORDS*4) : (TXP_WORDS*2))
    224 
    225 #define EOL	0x0001		/* end of list marker for link fields */
    226 
    227 /*
    228  * CDA, the CAM descriptor area. The SONIC has a 16 entry CAM to
    229  * match incoming addresses against. It is programmed via DMA
    230  * from a memory region.
    231  */
    232 #define MAXCAM	16	/* number of user entries in CAM */
    233 #define	CDA_CAMDESC	4	/* # words i na descriptor */
    234 #define	CDA_CAMEP	0	/* CAM Address Port 0 xx-xx-xx-xx-YY-YY */
    235 #define	CDA_CAMAP0	1	/* CAM Address Port 1 xx-xx-YY-YY-xx-xx */
    236 #define	CDA_CAMAP1	2	/* CAM Address Port 2 YY-YY-xx-xx-xx-xx */
    237 #define	CDA_CAMAP2	3
    238 #define	CDA_ENABLE	64	/* mask enabling CAM entries */
    239 #define	CDA_SIZE(sc)	((4*16 + 1) * ((sc->bitmode) ? 4 : 2))
    240 
    241 int	snsetup __P((struct sn_softc *sc, u_int8_t *));
    242 void	snintr __P((void *, int));
    243 void	sn_get_enaddr __P((bus_space_tag_t t, bus_space_handle_t h,
    244 	    vm_offset_t o, u_char *dst));
    245