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