if_snvar.h revision 1.9 1 /* $NetBSD: if_snvar.h,v 1.9 1997/06/15 20:20:13 scottr 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 DP8393X (SONIC) NetBSD/mac68k vars
11 */
12
13 /*
14 * Vendor types
15 */
16 #define SN_VENDOR_UNKNOWN 0xff /* Unknown */
17 #define SN_VENDOR_APPLE 0x00 /* Apple Computer/compatible */
18 #define SN_VENDOR_DAYNA 0x01 /* Dayna/Kinetics EtherPort */
19
20 /*
21 * Memory access macros. Since we handle SONIC in 16 bit mode (PB5X0)
22 * and 32 bit mode (everything else) using a single GENERIC kernel
23 * binary, all structures have to be accessed using macros which can
24 * adjust the offsets appropriately.
25 */
26 #define SWO(m, a, o, x) (m ? (*(u_int32_t *)((u_int32_t *)(a) + (o)) = (x)) : \
27 (*(u_int16_t *)((u_int16_t *)(a) + (o)) = (x)))
28 #define SRO(m, a, o) (m ? (*(u_int32_t *)((u_int32_t *)(a) + (o)) & 0xffff) : \
29 (*(u_int16_t *)((u_int16_t *)(a) + (o)) & 0xffff))
30
31 /*
32 * Register access macros. We use bus_space_* to talk to the Sonic
33 * registers. A mapping table is used in case a particular configuration
34 * hooked the regs up at non-word offsets.
35 */
36 #define NIC_GET(sc, reg) (bus_space_read_2((sc)->sc_regt, \
37 (sc)->sc_regh, \
38 ((sc)->sc_reg_map[(reg)])))
39 #define NIC_PUT(sc, reg, val) (bus_space_write_2((sc)->sc_regt, \
40 (sc)->sc_regh, \
41 ((sc)->sc_reg_map[reg]), \
42 (val)))
43
44 extern int kvtop(caddr_t addr);
45 #define SONIC_GETDMA(p) (u_int32_t)(kvtop((caddr_t)(p)))
46
47 #define SN_REGSIZE SN_NREGS*4
48
49 /* mac68k does not have any write buffers to flush... */
50 #define wbflush()
51
52 /*
53 * buffer sizes in 32 bit mode
54 * 1 TXpkt is 4 hdr words + (3 * FRAGMAX) + 1 link word == 23 words == 92 bytes
55 *
56 * 1 RxPkt is 7 words == 28 bytes
57 * 1 Rda is 4 words == 16 bytes
58 *
59 * The CDA is 17 words == 68 bytes
60 *
61 * total space in page 0 = NTDA * 92 + NRRA * 16 + NRDA * 28 + 68
62 */
63
64 #define NRBA 8 /* # receive buffers < NRRA */
65 #define RBAMASK (NRBA-1)
66 #define NTDA 8 /* # transmit descriptors */
67 #define NRRA 16 /* # receive resource descriptors */
68 #define RRAMASK (NRRA-1) /* the reason why NRRA must be power of two */
69
70 #define FCSSIZE 4 /* size of FCS appended to packets */
71
72 /*
73 * maximum receive packet size plus 2 byte pad to make each
74 * one aligned. 4 byte slop (required for eobc)
75 */
76 #define RBASIZE(sc) (sizeof(struct ether_header) + ETHERMTU + FCSSIZE + \
77 ((sc)->bitmode ? 6 : 2))
78
79 /*
80 * transmit buffer area
81 */
82 #define TXBSIZE 1536 /* 6*2^8 -- the same size as the 8390 TXBUF */
83
84 #define SN_NPAGES 2 + NRBA + (NTDA/2)
85
86 typedef struct mtd {
87 void *mtd_txp;
88 u_int32_t mtd_vtxp;
89 caddr_t mtd_buf;
90 u_int32_t mtd_vbuf;
91 struct mbuf *mtd_mbuf;
92 } mtd_t;
93
94 /*
95 * The sn_softc for Mac68k if_sn.
96 */
97 typedef struct sn_softc {
98 struct device sc_dev;
99 struct ethercom sc_ethercom;
100 #define sc_if sc_ethercom.ec_if /* network visible interface */
101
102 bus_space_tag_t sc_regt;
103 bus_space_handle_t sc_regh;
104
105 int bitmode; /* 32 bit mode == 1, 16 == 0 */
106 bus_size_t sc_reg_map[SN_NREGS]; /* register offsets */
107
108 u_int16_t snr_dcr; /* DCR for this instance */
109 u_int16_t snr_dcr2; /* DCR2 for this instance */
110 int slotno; /* Slot number */
111
112 int sc_rramark; /* index into p_rra of wp */
113 void *p_rra[NRRA]; /* RX resource descs */
114 u_int32_t v_rra[NRRA]; /* DMA addresses of p_rra */
115 u_int32_t v_rea; /* ptr to the end of the rra space */
116
117 int sc_rxmark; /* current hw pos in rda ring */
118 int sc_rdamark; /* current sw pos in rda ring */
119 int sc_nrda; /* total number of RDAs */
120 caddr_t p_rda;
121 u_int32_t v_rda;
122
123 caddr_t rbuf[NRBA];
124
125 struct mtd mtda[NTDA];
126 int mtd_hw; /* idx of first mtd given to hw */
127 int mtd_prev; /* idx of last mtd given to hardware */
128 int mtd_free; /* next free mtd to use */
129 int mtd_tlinko; /*
130 * offset of tlink of last txp given
131 * to SONIC. Need to clear EOL on
132 * this word to add a desc.
133 */
134 int mtd_pint; /* Counter to set TXP_PINT */
135
136 void *p_cda;
137 u_int32_t v_cda;
138
139 unsigned char *space;
140 } sn_softc_t;
141
142 /*
143 * Accessing SONIC data structures and registers as 32 bit values
144 * makes code endianess independent. The SONIC is however always in
145 * bigendian mode so it is necessary to ensure that data structures shared
146 * between the CPU and the SONIC are always in bigendian order.
147 */
148
149 /*
150 * Receive Resource Descriptor
151 * This structure describes the buffers into which packets
152 * will be received. Note that more than one packet may be
153 * packed into a single buffer if constraints permit.
154 */
155 #define RXRSRC_PTRLO 0 /* buffer address LO */
156 #define RXRSRC_PTRHI 1 /* buffer address HI */
157 #define RXRSRC_WCLO 2 /* buffer size (16bit words) LO */
158 #define RXRSRC_WCHI 3 /* buffer size (16bit words) HI */
159
160 #define RXRSRC_SIZE(sc) (sc->bitmode ? (4 * 4) : (4 * 2))
161
162 /*
163 * Receive Descriptor
164 * This structure holds information about packets received.
165 */
166 #define RXPKT_STATUS 0
167 #define RXPKT_BYTEC 1
168 #define RXPKT_PTRLO 2
169 #define RXPKT_PTRHI 3
170 #define RXPKT_SEQNO 4
171 #define RXPKT_RLINK 5
172 #define RXPKT_INUSE 6
173 #define RXPKT_SIZE(sc) (sc->bitmode ? (7 * 4) : (7 * 2))
174
175 #define RBASEQ(x) (((x)>>8)&0xff)
176 #define PSNSEQ(x) ((x) & 0xff)
177
178 /*
179 * Transmit Descriptor
180 * This structure holds information about packets to be transmitted.
181 */
182 #define FRAGMAX 8 /* maximum number of fragments in a packet */
183
184 #define TXP_STATUS 0 /* + transmitted packet status */
185 #define TXP_CONFIG 1 /* transmission configuration */
186 #define TXP_PKTSIZE 2 /* entire packet size in bytes */
187 #define TXP_FRAGCNT 3 /* # fragments in packet */
188
189 #define TXP_FRAGOFF 4 /* offset to first fragment */
190 #define TXP_FRAGSIZE 3 /* size of each fragment desc */
191 #define TXP_FPTRLO 0 /* ptr to packet fragment LO */
192 #define TXP_FPTRHI 1 /* ptr to packet fragment HI */
193 #define TXP_FSIZE 2 /* fragment size */
194
195 #define TXP_WORDS TXP_FRAGOFF + (FRAGMAX*TXP_FRAGSIZE) + 1 /* 1 for tlink */
196 #define TXP_SIZE(sc) ((sc->bitmode) ? (TXP_WORDS*4) : (TXP_WORDS*2))
197
198 #define EOL 0x0001 /* end of list marker for link fields */
199
200 /*
201 * CDA, the CAM descriptor area. The SONIC has a 16 entry CAM to
202 * match incoming addresses against. It is programmed via DMA
203 * from a memory region.
204 */
205 #define MAXCAM 16 /* number of user entries in CAM */
206 #define CDA_CAMDESC 4 /* # words i na descriptor */
207 #define CDA_CAMEP 0 /* CAM Address Port 0 xx-xx-xx-xx-YY-YY */
208 #define CDA_CAMAP0 1 /* CAM Address Port 1 xx-xx-YY-YY-xx-xx */
209 #define CDA_CAMAP1 2 /* CAM Address Port 2 YY-YY-xx-xx-xx-xx */
210 #define CDA_CAMAP2 3
211 #define CDA_ENABLE 64 /* mask enabling CAM entries */
212 #define CDA_SIZE(sc) ((4*16 + 1) * ((sc->bitmode) ? 4 : 2))
213
214 int snsetup __P((struct sn_softc *sc, u_int8_t *));
215 void snintr __P((void *, int));
216 void sn_get_enaddr __P((bus_space_tag_t t, bus_space_handle_t h,
217 vm_offset_t o, u_char *dst));
218