if_snvar.h revision 1.3 1 /* $NetBSD: if_snvar.h,v 1.3 1997/03/17 04:57:58 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_sonic.h -- National Semiconductor DP83932BVF (SONIC)
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 * buffer sizes in 32 bit mode
26 * 1 TXpkt is 4 hdr words + (3 * FRAGMAX) + 1 link word
27 * FRAGMAX == 16 => 54 words == 216 bytes
28 *
29 * 1 RxPkt is 7 words == 28 bytes
30 * 1 Rda is 4 words == 16 bytes
31 */
32
33 #define NRBA 16 /* # receive buffers < NRRA */
34 #define RBAMASK 0x0f
35 #define NRDA NRBA
36 #define NTDA 4 /* # transmit descriptors */
37 #define NRRA 32 /* # receive resource descriptors */
38 #define RRAMASK 0x1f /* the reason why it must be power of two */
39
40 #define FCSSIZE 4 /* size of FCS appended to packets */
41
42 /*
43 * maximum receive packet size plus 2 byte pad to make each
44 * one aligned. 4 byte slop (required for eobc)
45 */
46 #define RBASIZE(sc) (sizeof(struct ether_header) + ETHERMTU + FCSSIZE + \
47 ((sc)->bitmode ? 6 : 2))
48
49 /*
50 * transmit buffer area
51 */
52 #define NTXB 10 /* Number of xmit buffers */
53 #define TXBSIZE 1536 /* 6*2^8 -- the same size as the 8390 TXBUF */
54
55 /*
56 * Statistics collected over time
57 */
58 struct sn_stats {
59 int ls_opacks; /* packets transmitted */
60 int ls_ipacks; /* packets received */
61 int ls_tdr; /* contents of tdr after collision */
62 int ls_tdef; /* packets where had to wait */
63 int ls_tone; /* packets with one retry */
64 int ls_tmore; /* packets with more than one retry */
65 int ls_tbuff; /* transmit buff errors */
66 int ls_tuflo; /* " uflo " */
67 int ls_tlcol;
68 int ls_tlcar;
69 int ls_trtry;
70 int ls_rbuff; /* receive buff errors */
71 int ls_rfram; /* framing */
72 int ls_roflo; /* overflow */
73 int ls_rcrc;
74 int ls_rrng; /* rx ring sequence error */
75 int ls_babl; /* chip babl error */
76 int ls_cerr; /* collision error */
77 int ls_miss; /* missed packet */
78 int ls_merr; /* memory error */
79 int ls_copies; /* copies due to out of range mbufs */
80 int ls_maxmbufs; /* max mbufs on transmit */
81 int ls_maxslots; /* max ring slots on transmit */
82 };
83
84 typedef struct mtd {
85 void *mtd_txp;
86 int mtd_vtxp;
87 unsigned char *mtd_buf;
88 } mtd_t;
89
90 /*
91 * The sn_softc for Mac68k if_sn.
92 */
93 typedef struct sn_softc {
94 struct device sc_dev;
95 struct ethercom sc_ethercom;
96 #define sc_if sc_ethercom.ec_if /* network visible interface */
97 u_int8_t sc_enaddr[6]; /* Keep MAC address here until we have multicast */
98
99 bus_space_tag_t sc_regt;
100 bus_space_handle_t sc_regh;
101
102 struct sn_stats sc_sum;
103 short sc_iflags;
104 unsigned short bitmode; /* 32 bit mode == 1, 16 == 0 */
105
106 unsigned int s_dcr; /* DCR for this instance */
107 int slotno; /* Slot number */
108 struct sonic_reg *sc_csr; /* hardware pointer */
109 int sc_rxmark; /* pos. in rx ring for reading buffs */
110
111 int sc_rramark; /* index into p_rra of wp */
112 void *p_rra[NRRA]; /* RX resource descs */
113 int v_rra[NRRA]; /* DMA addresses of p_rra */
114 int v_rea; /* ptr to the end of the rra space */
115
116 int sc_rdamark;
117 void *p_rda[NRDA];
118 int v_rda[NRDA];
119
120 caddr_t rbuf[NRBA];
121
122 int sc_txhead; /*XXX idx of first TDA passed to chip */
123 int sc_missed; /* missed packet counter */
124
125 int txb_cnt; /* total number of xmit buffers */
126 int txb_inuse; /* number of active xmit buffers */
127 int txb_new; /* index of next open slot. */
128
129 struct mtd mtda[NTDA];
130 int mtd_hw; /* idx of first mtd given to hw */
131 int mtd_prev; /* idx of last mtd given to hardware */
132 int mtd_free; /* next free mtd to use */
133 int mtd_tlinko; /*
134 * offset of tlink of last txp given
135 * to SONIC. Need to clear EOL on
136 * this word to add a desc.
137 */
138
139 caddr_t tbuf[NTXB];
140 int vtbuf[NTXB]; /* DMA address of tbuf */
141
142 void *p_cda;
143 int v_cda;
144
145 unsigned char space[(1 + 1 + 8 + 5) * NBPG];
146 } sn_softc_t;
147
148 /*
149 * Accessing SONIC data structures and registers as 32 bit values
150 * makes code endianess independent. The SONIC is however always in
151 * bigendian mode so it is necessary to ensure that data structures shared
152 * between the CPU and the SONIC are always in bigendian order.
153 */
154
155 /*
156 * Receive Resource Descriptor
157 * This structure describes the buffers into which packets
158 * will be received. Note that more than one packet may be
159 * packed into a single buffer if constraints permit.
160 */
161 #define RXRSRC_PTRLO 0 /* buffer address LO */
162 #define RXRSRC_PTRHI 1 /* buffer address HI */
163 #define RXRSRC_WCLO 2 /* buffer size (16bit words) LO */
164 #define RXRSRC_WCHI 3 /* buffer size (16bit words) HI */
165
166 #define RXRSRC_SIZE(sc) (sc->bitmode ? (4 * 4) : (4 * 2))
167
168 /*
169 * Receive Descriptor
170 * This structure holds information about packets received.
171 */
172 #define RXPKT_STATUS 0
173 #define RXPKT_BYTEC 1
174 #define RXPKT_PTRLO 2
175 #define RXPKT_PTRHI 3
176 #define RXPKT_SEQNO 4
177 #define RXPKT_RLINK 5
178 #define RXPKT_INUSE 6
179 #define RXPKT_SIZE(sc) (sc->bitmode ? (7 * 4) : (7 * 2))
180
181 #define RBASEQ(x) (((x)>>8)&0xff)
182 #define PSNSEQ(x) ((x) & 0xff)
183
184 /*
185 * Transmit Descriptor
186 * This structure holds information about packets to be transmitted.
187 */
188 #define FRAGMAX 16 /* maximum number of fragments in a packet */
189
190 #define TXP_STATUS 0 /* + transmitted packet status */
191 #define TXP_CONFIG 1 /* transmission configuration */
192 #define TXP_PKTSIZE 2 /* entire packet size in bytes */
193 #define TXP_FRAGCNT 3 /* # fragments in packet */
194
195 #define TXP_FRAGOFF 4 /* offset to first fragment */
196 #define TXP_FRAGSIZE 3 /* size of each fragment desc */
197 #define TXP_FPTRLO 0 /* ptr to packet fragment LO */
198 #define TXP_FPTRHI 1 /* ptr to packet fragment HI */
199 #define TXP_FSIZE 2 /* fragment size */
200
201 #define TXP_WORDS TXP_FRAGOFF + FRAGMAX*TXP_FSIZE + 1 /* 1 for tlink */
202 #define TXP_SIZE(sc) ((sc->bitmode) ? (TXP_WORDS*4) : (TXP_WORDS*2))
203
204 #define EOL 0x0001 /* end of list marker for link fields */
205
206 /*
207 * CDA, the CAM descriptor area. The SONIC has a 16 entry CAM to
208 * match incoming addresses against. It is programmed via DMA
209 * from a memory region.
210 */
211 #define MAXCAM 16 /* number of user entries in CAM */
212 #define CDA_CAMDESC 4 /* # words i na descriptor */
213 #define CDA_CAMEP 0 /* CAM Address Port 0 xx-xx-xx-xx-YY-YY */
214 #define CDA_CAMAP0 1 /* CAM Address Port 1 xx-xx-YY-YY-xx-xx */
215 #define CDA_CAMAP1 2 /* CAM Address Port 2 YY-YY-xx-xx-xx-xx */
216 #define CDA_CAMAP2 3
217 #define CDA_ENABLE 64 /* mask enabling CAM entries */
218 #define CDA_SIZE(sc) ((4*16 + 1) * ((sc->bitmode) ? 4 : 2))
219
220 void snsetup __P((struct sn_softc *sc, u_int8_t *));
221