1 /* $FreeBSD: src/sys/dev/snc/dp83932var.h,v 1.1.2.2 2003/02/11 08:52:00 nyan Exp $ */
2 /* $DragonFly: src/sys/dev/netif/snc/Attic/dp83932var.h,v 1.6 2005/06/12 16:32:52 joerg Exp $ */
3 /* $NecBSD: dp83932var.h,v 1.3 1999/01/24 01:39:51 kmatsuda Exp $ */
4 /* $NetBSD: if_snvar.h,v 1.12 1998/05/01 03:42:47 scottr Exp $ */
7 * [NetBSD for NEC PC-98 series]
8 * Copyright (c) 1997, 1998, 1999
9 * Kouichi Matsuda. All rights reserved.
12 * Copyright (c) 1991 Algorithmics Ltd (http://www.algor.co.uk)
13 * You may use, copy, and modify this program so long as you retain the
18 * if_snvar.h -- National Semiconductor DP8393X (SONIC) NetBSD/mac68k vars
21 * Modified for NetBSD/pc98 1.2.1 from NetBSD/mac68k 1.2D by Kouichi Matsuda.
22 * Make adapted for NEC PC-9801-83, 84, PC-9801-103, 104, PC-9801N-25 and
23 * PC-9801N-J02, J02R, which uses National Semiconductor DP83934AVQB as
24 * Ethernet Controller and National Semiconductor NS46C46 as
25 * (64 * 16 bits) Microwire Serial EEPROM.
28 /* borrow from arch/mac68k/dev/if_mcvar.h for debug. */
33 #define integrate static __inline
38 #define NBPG PAGE_SIZE
41 #define PGOFSET PAGE_MASK
43 typedef unsigned long ulong;
44 #define delay(x) DELAY(x)
51 * SONIC buffers need to be aligned 16 or 32 bit aligned.
52 * These macros calculate and verify alignment.
54 #define ROUNDUP(p, N) (((int) p + N - 1) & ~(N - 1))
56 #define SOALIGN(m, array) (m ? (ROUNDUP(array, 4)) : (ROUNDUP(array, 2)))
58 #define LOWER(x) ((unsigned)(x) & 0xffff)
59 #define UPPER(x) ((unsigned)(x) >> 16)
62 * Memory access macros. Since we handle SONIC in 16 bit mode (PB5X0)
63 * and 32 bit mode (everything else) using a single GENERIC kernel
64 * binary, all structures have to be accessed using macros which can
65 * adjust the offsets appropriately.
67 /* m is not sc->bitmode, we treat m as sc. */
68 #define SWO(m, a, o, x) (*(m)->sc_writetodesc)((m), (a), (o), (x))
69 #define SRO(m, a, o) (*(m)->sc_readfromdesc)((m), (a), (o))
72 * Register access macros. We use bus_space_* to talk to the Sonic
73 * registers. A mapping table is used in case a particular configuration
74 * hooked the regs up at non-word offsets.
76 #define NIC_GET(sc, reg) (*(sc)->sc_nic_get)(sc, reg)
77 #define NIC_PUT(sc, reg, val) (*(sc)->sc_nic_put)(sc, reg, val)
79 #define SONIC_GETDMA(p) (p)
81 /* pc98 does not have any write buffers to flush... */
85 * buffer sizes in 32 bit mode
86 * 1 TXpkt is 4 hdr words + (3 * FRAGMAX) + 1 link word == 23 words == 92 bytes
88 * 1 RxPkt is 7 words == 28 bytes
89 * 1 Rda is 4 words == 16 bytes
91 * The CDA is 17 words == 68 bytes
93 * total space in page 0 = NTDA * 92 + NRRA * 16 + NRDA * 28 + 68
96 #define NRBA 16 /* # receive buffers < NRRA */
97 #define RBAMASK (NRBA-1)
98 #define NTDA 16 /* # transmit descriptors */
99 #define NRRA 64 /* # receive resource descriptors */
100 #define RRAMASK (NRRA-1) /* the reason why NRRA must be power of two */
102 #define FCSSIZE 4 /* size of FCS appended to packets */
105 * maximum receive packet size plus 2 byte pad to make each
106 * one aligned. 4 byte slop (required for eobc)
108 #define RBASIZE(sc) (sizeof(struct ether_header) + ETHERMTU + FCSSIZE + \
109 ((sc)->bitmode ? 6 : 2))
112 * transmit buffer area
114 #define TXBSIZE 1536 /* 6*2^8 -- the same size as the 8390 TXBUF */
116 #define SN_NPAGES 2 + NRBA + (NTDA/2)
121 struct mbuf *mtd_mbuf;
125 * The snc_softc for PC-98 if_snc.
127 typedef struct snc_softc {
128 struct arpcom sc_ethercom;
129 #define sc_if sc_ethercom.ac_if /* network visible interface */
133 struct resource * ioport;
135 struct resource * iomem;
137 struct resource * irq;
141 bus_space_tag_t sc_iot; /* bus identifier for io */
142 bus_space_tag_t sc_memt; /* bus identifier for mem */
143 bus_space_handle_t sc_ioh; /* io handle */
144 bus_space_handle_t sc_memh; /* bus memory handle */
146 int bitmode; /* 32 bit mode == 1, 16 == 0 */
148 u_int16_t sncr_dcr; /* DCR for this instance */
149 u_int16_t sncr_dcr2; /* DCR2 for this instance */
151 int sc_rramark; /* index into v_rra of wp */
152 u_int32_t v_rra[NRRA]; /* DMA addresses of v_rra */
153 u_int32_t v_rea; /* ptr to the end of the rra space */
155 int sc_rxmark; /* current hw pos in rda ring */
156 int sc_rdamark; /* current sw pos in rda ring */
157 int sc_nrda; /* total number of RDAs */
160 u_int32_t rbuf[NRBA];
162 struct mtd mtda[NTDA];
163 int mtd_hw; /* idx of first mtd given to hw */
164 int mtd_prev; /* idx of last mtd given to hardware */
165 int mtd_free; /* next free mtd to use */
167 * offset of tlink of last txp given
168 * to SONIC. Need to clear EOL on
169 * this word to add a desc.
171 int mtd_pint; /* Counter to set TXP_PINT */
175 u_int8_t curbank; /* current window bank */
177 struct ifmedia sc_media; /* supported media information */
180 * NIC register access functions:
182 u_int16_t (*sc_nic_get)
183 (struct snc_softc *, u_int8_t);
185 (struct snc_softc *, u_int8_t, u_int16_t);
190 * copy to/from descriptor
191 * copy to/from buffer
192 * zero bytes in buffer
194 void (*sc_writetodesc)
195 (struct snc_softc *, u_int32_t, u_int32_t, u_int16_t);
196 u_int16_t (*sc_readfromdesc)
197 (struct snc_softc *, u_int32_t, u_int32_t);
199 (struct snc_softc *, void *, u_int32_t, size_t);
200 void (*sc_copyfrombuf)
201 (struct snc_softc *, void *, u_int32_t, size_t);
203 (struct snc_softc *, u_int32_t, size_t);
206 * Machine-dependent functions:
208 * hardware reset hook - may be NULL
209 * hardware init hook - may be NULL
210 * media change hook - may be NULL
212 void (*sc_hwreset) (struct snc_softc *);
213 void (*sc_hwinit) (struct snc_softc *);
214 int (*sc_mediachange) (struct snc_softc *);
215 void (*sc_mediastatus) (struct snc_softc *,
216 struct ifmediareq *);
218 int sc_enabled; /* boolean; power enabled on interface */
220 int (*sc_enable) (struct snc_softc *);
221 void (*sc_disable) (struct snc_softc *);
223 void *sc_sh; /* shutdownhook cookie */
227 rndsource_element_t rnd_source;
232 * Accessing SONIC data structures and registers as 32 bit values
233 * makes code endianess independent. The SONIC is however always in
234 * bigendian mode so it is necessary to ensure that data structures shared
235 * between the CPU and the SONIC are always in bigendian order.
239 * Receive Resource Descriptor
240 * This structure describes the buffers into which packets
241 * will be received. Note that more than one packet may be
242 * packed into a single buffer if constraints permit.
244 #define RXRSRC_PTRLO 0 /* buffer address LO */
245 #define RXRSRC_PTRHI 1 /* buffer address HI */
246 #define RXRSRC_WCLO 2 /* buffer size (16bit words) LO */
247 #define RXRSRC_WCHI 3 /* buffer size (16bit words) HI */
249 #define RXRSRC_SIZE(sc) (sc->bitmode ? (4 * 4) : (4 * 2))
253 * This structure holds information about packets received.
255 #define RXPKT_STATUS 0
256 #define RXPKT_BYTEC 1
257 #define RXPKT_PTRLO 2
258 #define RXPKT_PTRHI 3
259 #define RXPKT_SEQNO 4
260 #define RXPKT_RLINK 5
261 #define RXPKT_INUSE 6
262 #define RXPKT_SIZE(sc) (sc->bitmode ? (7 * 4) : (7 * 2))
264 #define RBASEQ(x) (((x)>>8)&0xff)
265 #define PSNSEQ(x) ((x) & 0xff)
268 * Transmit Descriptor
269 * This structure holds information about packets to be transmitted.
271 #define FRAGMAX 8 /* maximum number of fragments in a packet */
273 #define TXP_STATUS 0 /* + transmitted packet status */
274 #define TXP_CONFIG 1 /* transmission configuration */
275 #define TXP_PKTSIZE 2 /* entire packet size in bytes */
276 #define TXP_FRAGCNT 3 /* # fragments in packet */
278 #define TXP_FRAGOFF 4 /* offset to first fragment */
279 #define TXP_FRAGSIZE 3 /* size of each fragment desc */
280 #define TXP_FPTRLO 0 /* ptr to packet fragment LO */
281 #define TXP_FPTRHI 1 /* ptr to packet fragment HI */
282 #define TXP_FSIZE 2 /* fragment size */
284 #define TXP_WORDS (TXP_FRAGOFF + (FRAGMAX*TXP_FRAGSIZE) + 1) /* 1 for tlink */
285 #define TXP_SIZE(sc) ((sc->bitmode) ? (TXP_WORDS*4) : (TXP_WORDS*2))
287 #define EOL 0x0001 /* end of list marker for link fields */
290 * CDA, the CAM descriptor area. The SONIC has a 16 entry CAM to
291 * match incoming addresses against. It is programmed via DMA
292 * from a memory region.
294 #define MAXCAM 16 /* number of user entries in CAM */
295 #define CDA_CAMDESC 4 /* # words i na descriptor */
296 #define CDA_CAMEP 0 /* CAM Address Port 0 xx-xx-xx-xx-YY-YY */
297 #define CDA_CAMAP0 1 /* CAM Address Port 1 xx-xx-YY-YY-xx-xx */
298 #define CDA_CAMAP1 2 /* CAM Address Port 2 YY-YY-xx-xx-xx-xx */
300 #define CDA_ENABLE 64 /* mask enabling CAM entries */
301 #define CDA_SIZE(sc) ((4*16 + 1) * ((sc->bitmode) ? 4 : 2))
303 void sncconfig (struct snc_softc *, int *, int, int, u_int8_t *);
304 void sncintr (void *);
305 void sncshutdown (void *);