1 /*	$NetBSD: pdqvar.h,v 1.47 2012/10/27 17:18:22 chs Exp $	*/
2 
3 /*-
4  * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. The name of the author may not be used to endorse or promote products
13  *    derived from this software without specific prior written permission
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * Id: pdqvar.h,v 1.21 1997/03/21 21:16:04 thomas Exp
27  *
28  */
29 
30 /*
31  * DEC PDQ FDDI Controller; PDQ O/S dependent definitions
32  *
33  * Written by Matt Thomas
34  *
35  */
36 
37 #ifndef _PDQ_OS_H
38 #define	_PDQ_OS_H
39 
40 #define	PDQ_OS_TX_TIMEOUT		5	/* seconds */
41 
42 enum _pdq_boolean_t {
43     PDQ_FALSE=0,
44     PDQ_TRUE=1
45 };
46 
47 enum _pdq_type_t {
48     PDQ_DEFPA,		/* PCI-bus */
49     PDQ_DEFEA,		/* EISA-bus */
50     PDQ_DEFTA,		/* TurboChannel */
51     PDQ_DEFAA,		/* FutureBus+ */
52     PDQ_DEFQA		/* Q-bus */
53 };
54 
55 enum _pdq_state_t {
56     PDQS_RESET=0,
57     PDQS_UPGRADE=1,
58     PDQS_DMA_UNAVAILABLE=2,
59     PDQS_DMA_AVAILABLE=3,
60     PDQS_LINK_AVAILABLE=4,
61     PDQS_LINK_UNAVAILABLE=5,
62     PDQS_HALTED=6,
63     PDQS_RING_MEMBER=7
64 };
65 
66 typedef struct _pdq_t pdq_t;
67 typedef struct _pdq_csrs_t pdq_csrs_t;
68 typedef struct _pdq_pci_csrs_t pdq_pci_csrs_t;
69 typedef struct _pdq_lanaddr_t pdq_lanaddr_t;
70 typedef unsigned int pdq_uint32_t;
71 typedef unsigned short pdq_uint16_t;
72 typedef unsigned char pdq_uint8_t;
73 typedef enum _pdq_boolean_t pdq_boolean_t;
74 typedef enum _pdq_type_t pdq_type_t;
75 typedef enum _pdq_state_t pdq_state_t;
76 
77 #if defined(PDQTEST)
78 #include <pdq_os_test.h>
79 #elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__NetBSD__)
80 
81 #include <sys/param.h>
82 #include <sys/systm.h>
83 #ifndef M_MCAST
84 #include <sys/mbuf.h>
85 #endif /* M_CAST */
86 #include <sys/malloc.h>
87 
88 #define	PDQ_USE_MBUFS
89 #if defined(__NetBSD__)
90 #define	PDQ_OS_PREFIX			"%s: "
91 #define	PDQ_OS_PREFIX_ARGS		pdq->pdq_os_name
92 #else
93 #define	PDQ_OS_PREFIX			"%s%d: "
94 #define	PDQ_OS_PREFIX_ARGS		pdq->pdq_os_name, pdq->pdq_unit
95 #endif
96 #if (defined(__FreeBSD__) && BSD >= 199506) || defined(__NetBSD__)
97 #define	PDQ_OS_PAGESIZE			PAGE_SIZE
98 #else
99 #define	PDQ_OS_PAGESIZE			NBPG
100 #endif
101 #define	PDQ_OS_USEC_DELAY(n)		DELAY(n)
102 #define	PDQ_OS_MEMZERO(p, n)		memset((void *)(p), 0, (n))
103 #if defined(__NetBSD__) && !defined(PDQ_NO_BUS_DMA)
104 #define PDQ_BUS_DMA
105 #endif
106 #if !defined(PDQ_BUS_DMA)
107 #define	PDQ_OS_VA_TO_BUSPA(pdq, p)		vtophys(p)
108 #endif
109 #define	PDQ_OS_MEMALLOC(n)		malloc(n, M_DEVBUF, M_NOWAIT)
110 #define	PDQ_OS_MEMFREE(p, n)		free((void *) p, M_DEVBUF)
111 #ifdef __FreeBSD__
112 #define	PDQ_OS_MEMALLOC_CONTIG(n)	vm_page_alloc_contig(n, 0, 0xffffffff, PAGE_SIZE)
113 #define	PDQ_OS_MEMFREE_CONTIG(p, n)	kmem_free(kernel_map, (vaddr_t) p, n)
114 #else
115 #if !defined(PDQ_BUS_DMA)
116 #define	PDQ_OS_MEMALLOC_CONTIG(n)	uvm_km_alloc(kernel_map, round_page(n))
117 #define	PDQ_OS_MEMFREE_CONTIG(p, n)	uvm_km_free(kernel_map, (vaddr_t) p, n)
118 #endif
119 #endif /* __FreeBSD__ */
120 
121 #if defined(__FreeBSD__)
122 #include <vm/pmap.h>
123 #include <vm/vm_extern.h>
124 #include <machine/cpufunc.h>
125 #include <machine/clock.h>
126 #define	ifnet_ret_t void
127 typedef int ioctl_cmd_t;
128 typedef enum { PDQ_BUS_EISA, PDQ_BUS_PCI } pdq_bus_t;
129 typedef	u_int16_t pdq_bus_ioport_t;
130 typedef volatile pdq_uint32_t *pdq_bus_memaddr_t;
131 typedef pdq_bus_memaddr_t pdq_bus_memoffset_t;
132 #if BSD >= 199506	/* __FreeBSD__ */
133 #define	PDQ_BPF_MTAP(sc, m)	bpf_mtap(&(sc)->sc_if, m)
134 #define	PDQ_BPFATTACH(sc, t, s)	bpfattach(&(sc)->sc_if, t, s)
135 #endif
136 
137 #define	pdq_os_update_status(a, b)	((void) 0)
138 
139 #elif defined(__bsdi__)
140 #if !defined(PDQ_HWSUPPORT) && (_BSDI_VERSION >= 199701)
141 #include <net/if_media.h>
142 #endif
143 #include <machine/inline.h>
144 #define	ifnet_ret_t int
145 typedef int ioctl_cmd_t;
146 typedef enum { PDQ_BUS_EISA, PDQ_BUS_PCI } pdq_bus_t;
147 typedef	u_int16_t pdq_bus_ioport_t;
148 typedef volatile pdq_uint32_t *pdq_bus_memaddr_t;
149 typedef pdq_bus_memaddr_t pdq_bus_memoffset_t;
150 
151 
152 #elif defined(__NetBSD__)
153 #if !defined(PDQ_HWSUPPORT)
154 #include <net/if_media.h>
155 #endif
156 #include <sys/bus.h>
157 #include <sys/intr.h>
158 #define PDQ_OS_HDR_OFFSET	(PDQ_RX_FC_OFFSET-3)
159 #define	PDQ_OS_PTR_FMT		"%p"
160 #define	PDQ_OS_CSR_FMT		"0x%lx"
161 #define	ifnet_ret_t void
162 typedef u_long ioctl_cmd_t;
163 typedef	bus_space_tag_t pdq_bus_t;
164 typedef	bus_space_handle_t pdq_bus_ioport_t;
165 typedef	bus_space_handle_t pdq_bus_memaddr_t;
166 typedef bus_addr_t pdq_bus_memoffset_t;
167 #define	PDQ_OS_SPL_RAISE()	splnet()
168 #define	PDQ_OS_IOMEM
169 #define PDQ_OS_IORD_32(t, base, offset)		bus_space_read_4  (t, base, offset)
170 #define PDQ_OS_IOWR_32(t, base, offset, data)	bus_space_write_4 (t, base, offset, data)
171 #define PDQ_OS_IORD_8(t, base, offset)		bus_space_read_1  (t, base, offset)
172 #define PDQ_OS_IOWR_8(t, base, offset, data)	bus_space_write_1 (t, base, offset, data)
173 #define	PDQ_CSR_OFFSET(base, offset)		(0 + (offset)*sizeof(pdq_uint32_t))
174 
175 #ifdef PDQ_BUS_DMA
176 #define	PDQ_OS_UNSOL_EVENT_PRESYNC(pdq, event) \
177 	pdq_os_unsolicited_event_sync((pdq)->pdq_os_ctx, \
178 			(const u_int8_t *) (event) - \
179 				(const u_int8_t *) (pdq)->pdq_unsolicited_info.ui_events, \
180 			sizeof(*event), BUS_DMASYNC_PREREAD)
181 #define	PDQ_OS_UNSOL_EVENT_POSTSYNC(pdq, event) \
182 	pdq_os_unsolicited_event_sync((pdq)->pdq_os_ctx, \
183 			(const u_int8_t *) (event) - \
184 				(const u_int8_t *) (pdq)->pdq_unsolicited_info.ui_events, \
185 			sizeof(*event), BUS_DMASYNC_POSTREAD)
186 #define	PDQ_OS_DESCBLOCK_SYNC(pdq, what, length, why) \
187 	pdq_os_descriptor_block_sync((pdq)->pdq_os_ctx, \
188 			(u_int8_t *) (what) - (u_int8_t *) (pdq)->pdq_dbp, \
189 			(length), (why))
190 #define	PDQ_OS_CONSUMER_PRESYNC(pdq) \
191 	pdq_os_consumer_block_sync((pdq)->pdq_os_ctx, \
192 			      BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)
193 #define	PDQ_OS_CONSUMER_POSTSYNC(pdq) \
194 	pdq_os_consumer_block_sync((pdq)->pdq_os_ctx, \
195 			      BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)
196 #define	PDQ_OS_DESC_PRESYNC(pdq, d, s) \
197 	PDQ_OS_DESCBLOCK_SYNC((pdq), (d), (s), BUS_DMASYNC_PREWRITE)
198 #define	PDQ_OS_DESC_POSTSYNC(pdq, d, s) \
199 	PDQ_OS_DESCBLOCK_SYNC((pdq), (d), (s), BUS_DMASYNC_POSTWRITE)
200 #define	PDQ_OS_CMDRQST_PRESYNC(pdq, s) \
201 	PDQ_OS_DESCBLOCK_SYNC((pdq), \
202 			      (pdq)->pdq_command_info.ci_request_bufstart, \
203 			      (s), BUS_DMASYNC_PREWRITE)
204 #define	PDQ_OS_CMDRSP_PRESYNC(pdq, s) \
205 	PDQ_OS_DESCBLOCK_SYNC((pdq), \
206 			      (pdq)->pdq_command_info.ci_response_bufstart, \
207 			      (s), BUS_DMASYNC_PREREAD)
208 #define	PDQ_OS_CMDRQST_POSTSYNC(pdq, s) \
209 	PDQ_OS_DESCBLOCK_SYNC((pdq), \
210 			      (pdq)->pdq_command_info.ci_request_bufstart, \
211 			      (s), BUS_DMASYNC_POSTWRITE)
212 #define	PDQ_OS_CMDRSP_POSTSYNC(pdq, s) \
213 	PDQ_OS_DESCBLOCK_SYNC((pdq), \
214 			      (pdq)->pdq_command_info.ci_response_bufstart, \
215 			      (s), BUS_DMASYNC_POSTREAD)
216 #define	PDQ_OS_RXPDU_PRESYNC(pdq, b, o, l) \
217 	pdq_os_databuf_sync((pdq)->pdq_os_ctx, (b), (o), (l), \
218 			    BUS_DMASYNC_PREREAD)
219 #define	PDQ_OS_RXPDU_POSTSYNC(pdq, b, o, l) \
220 	pdq_os_databuf_sync((pdq)->pdq_os_ctx, (b), (o), (l), \
221 			    BUS_DMASYNC_POSTREAD)
222 #define	PDQ_OS_DATABUF_ALLOC(pdq, b)	((void)((b) = pdq_os_databuf_alloc((pdq)->pdq_os_ctx)))
223 #define	PDQ_OS_DATABUF_FREE(pdq, b)	pdq_os_databuf_free((pdq)->pdq_os_ctx, (b))
224 #define PDQ_OS_DATABUF_BUSPA(pdq, b)	(M_GETCTX((b), bus_dmamap_t)->dm_segs[0].ds_addr + 0)
225 struct _pdq_os_ctx_t;
226 extern void pdq_os_descriptor_block_sync(struct _pdq_os_ctx_t *, size_t,
227 					 size_t, int);
228 extern void pdq_os_consumer_block_sync(struct _pdq_os_ctx_t *, int);
229 extern void pdq_os_unsolicited_event_sync(struct _pdq_os_ctx_t *, size_t,
230 				 	  size_t, int);
231 extern struct mbuf *pdq_os_databuf_alloc(struct _pdq_os_ctx_t *);
232 extern void pdq_os_databuf_sync(struct _pdq_os_ctx_t *, struct mbuf *,
233 				size_t, size_t, int);
234 extern void pdq_os_databuf_free(struct _pdq_os_ctx_t *, struct mbuf *);
235 #define M_HASTXDMAMAP		M_LINK1
236 #define M_HASRXDMAMAP		M_LINK2
237 #endif
238 
239 #define	PDQ_CSR_WRITE(csr, name, data)		PDQ_OS_IOWR_32((csr)->csr_bus, (csr)->csr_base, (csr)->name, data)
240 #define	PDQ_CSR_READ(csr, name)			PDQ_OS_IORD_32((csr)->csr_bus, (csr)->csr_base, (csr)->name)
241 
242 #define	PDQ_OS_IFP_TO_SOFTC(ifp)		((pdq_softc_t *) (ifp)->if_softc)
243 #define	PDQ_ARP_IFINIT(sc, ifa)			arp_ifinit(&(sc)->sc_if, (ifa))
244 #define	PDQ_FDDICOM(sc)				(&(sc)->sc_ec)
245 #define	PDQ_LANADDR(sc)				CLLADDR((sc)->sc_if.if_sadl)
246 #define	PDQ_LANADDR_SIZE(sc)			((sc)->sc_if.if_sadl->sdl_alen)
247 #endif
248 
249 #if !defined(PDQ_BPF_MTAP)
250 #define	PDQ_BPF_MTAP(sc, m)	bpf_mtap3((sc)->sc_bpf, m)
251 #endif
252 
253 #if !defined(PDQ_BPFATTACH)
254 #define	PDQ_BPFATTACH(sc, t, s)	bpf_attach(&(sc)->sc_bpf, &(sc)->sc_if, t, s)
255 #endif
256 
257 #if !defined(PDQ_OS_SPL_RAISE)
258 #define	PDQ_OS_SPL_RAISE()	splimp()
259 #endif
260 
261 #if !defined(PDQ_OS_SPL_LOWER)
262 #define	PDQ_OS_SPL_LOWER(s)	splx(s)
263 #endif
264 
265 #if !defined(PDQ_FDDICOM)
266 #define	PDQ_FDDICOM(sc)		(&(sc)->sc_ac)
267 #endif
268 
269 #if !defined(PDQ_ARP_IFINIT)
270 #define	PDQ_ARP_IFINIT(sc, ifa)	arp_ifinit(&(sc)->sc_ac, (ifa))
271 #endif
272 
273 #if !defined(PDQ_OS_PTR_FMT)
274 #define	PDQ_OS_PTR_FMT	"0x%x"
275 #endif
276 
277 #if !defined(PDQ_OS_CSR_FMT)
278 #define	PDQ_OS_CSR_FMT	"0x%x"
279 #endif
280 
281 #if !defined(PDQ_LANADDR)
282 #define	PDQ_LANADDR(sc)		((sc)->sc_ac.ac_enaddr)
283 #define	PDQ_LANADDR_SIZE(sc)	(sizeof((sc)->sc_ac.ac_enaddr))
284 #endif
285 
286 #if !defined(PDQ_OS_IOMEM)
287 #define PDQ_OS_IORD_32(t, base, offset)		inl((base) + (offset))
288 #define PDQ_OS_IOWR_32(t, base, offset, data)	outl((base) + (offset), data)
289 #define PDQ_OS_IORD_8(t, base, offset)		inb((base) + (offset))
290 #define PDQ_OS_IOWR_8(t, base, offset, data)	outb((base) + (offset), data)
291 #define PDQ_OS_MEMRD_32(t, base, offset)	(0 + *((base) + (offset)))
292 #define PDQ_OS_MEMWR_32(t, base, offset, data)	do *((base) + (offset)) = (data); while (0)
293 #endif
294 #ifndef PDQ_CSR_OFFSET
295 #define	PDQ_CSR_OFFSET(base, offset)		(0 + (base) + (offset))
296 #endif
297 
298 #ifndef PDQ_CSR_WRITE
299 #define	PDQ_CSR_WRITE(csr, name, data)		PDQ_OS_MEMWR_32((csr)->csr_bus, (csr)->name, 0, data)
300 #define	PDQ_CSR_READ(csr, name)			PDQ_OS_MEMRD_32((csr)->csr_bus, (csr)->name, 0)
301 #endif
302 
303 #ifndef PDQ_OS_IFP_TO_SOFTC
304 #define	PDQ_OS_IFP_TO_SOFTC(ifp)	((pdq_softc_t *) ((void *) ifp - offsetof(pdq_softc_t, sc_ac.ac_if)))
305 #endif
306 
307 
308 #if !defined(PDQ_HWSUPPORT)
309 
310 typedef struct _pdq_os_ctx_t {
311 #if defined(__bsdi__)
312     struct device sc_dev;		/* base device */
313     struct isadev sc_id;		/* ISA device */
314     struct intrhand sc_ih;		/* interrupt vectoring */
315     struct atshutdown sc_ats;		/* shutdown routine */
316     struct arpcom sc_ac;
317 #define	sc_if		sc_ac.ac_if
318 #elif defined(__NetBSD__)
319     device_t sc_dev;		/* base device */
320     void *sc_ih;			/* interrupt vectoring */
321     void *sc_ats;			/* shutdown hook */
322     struct ethercom sc_ec;
323     bus_dma_tag_t sc_dmatag;
324     bool sc_csr_memmapped;
325 #define	sc_if		sc_ec.ec_if
326 #elif defined(__FreeBSD__)
327     struct kern_devconf *sc_kdc;	/* freebsd cruft */
328     struct arpcom sc_ac;
329 #define	sc_if		sc_ac.ac_if
330 #endif
331 #if defined(IFM_FDDI)
332     struct ifmedia sc_ifmedia;
333 #endif
334     int sc_flags;
335 #define	PDQIF_DOWNCALL		0x0001	/* active calling from if to pdq */
336     pdq_t *sc_pdq;
337 #if defined(__alpha__) || defined(__i386__)
338     pdq_bus_ioport_t sc_iobase;
339 #endif
340 #if defined(PDQ_IOMAPPED) && !defined(__NetBSD__)
341 #define	sc_membase	sc_iobase
342 #else
343     pdq_bus_memaddr_t sc_membase;
344 #endif
345     pdq_bus_t sc_iotag;
346     pdq_bus_t sc_csrtag;
347 #if !defined(__bsdi__) || _BSDI_VERSION >= 199401
348 #define	sc_bpf		sc_if.if_bpf
349 #else
350     struct bpf_if *sc_bpf;
351 #endif
352 #if defined(PDQ_BUS_DMA)
353 #if !defined(__NetBSD__)
354      bus_dma_tag_t sc_dmatag;
355 #endif
356      bus_dmamap_t sc_dbmap;		/* DMA map for descriptor block */
357      bus_dmamap_t sc_uimap;		/* DMA map for unsolicited events */
358      bus_dmamap_t sc_cbmap;		/* DMA map for consumer block */
359 #endif
360 } pdq_softc_t;
361 
362 
363 extern void pdq_ifreset(pdq_softc_t *);
364 extern void pdq_ifinit(pdq_softc_t *);
365 extern void pdq_ifwatchdog(struct ifnet *);
366 extern ifnet_ret_t pdq_ifstart(struct ifnet *);
367 extern int pdq_ifioctl(struct ifnet *, ioctl_cmd_t, void *);
368 extern void pdq_ifattach(pdq_softc_t *, ifnet_ret_t (*ifwatchdog)(int));
369 #endif /* !PDQ_HWSUPPORT */
370 
371 
372 #elif defined(DLPI_PDQ)
373 #include <sys/param.h>
374 #include <sys/kmem.h>
375 #include <sys/ddi.h>
376 #include <sys/stream.h>
377 
378 #define	PDQ_USE_STREAMS
379 #define	PDQ_OS_PREFIX			"%s board %d "
380 #define	PDQ_OS_PREFIX_ARGS		pdq->pdq_os_name, pdq->pdq_unit
381 
382 #define	PDQ_OS_PAGESIZE			PAGESIZE
383 #define	PDQ_OS_USEC_DELAY(n)		drv_usecwait(n)
384 #define	PDQ_OS_MEMZERO(p, n)		memset((void *)(p), 0, (n))
385 #define	PDQ_OS_VA_TO_BUSPA(pdq, p)		vtop((void *)p, NULL)
386 #define	PDQ_OS_MEMALLOC(n)		kmem_zalloc(n, KM_NOSLEEP)
387 #define	PDQ_OS_MEMFREE(p, n)		kmem_free((void *) p, n)
388 #define	PDQ_OS_MEMALLOC_CONTIG(n)	kmem_zalloc_physreq(n, decfddiphysreq_db, KM_NOSLEEP)
389 #define	PDQ_OS_MEMFREE_CONTIG(p, n)	PDQ_OS_MEMFREE(p, n)
390 
391 extern physreq_t *decfddiphysreq_db;
392 extern physreq_t *decfddiphysreq_mblk;
393 
394 #define	PDQ_OS_DATABUF_ALLOC(pdq, b)		((void) (((b) = allocb_physreq(PDQ_OS_DATABUF_SIZE, BPRI_MED, decfddiphysreq_mblk)) && ((b)->b_wptr = (b)->b_rptr + PDQ_OS_DATABUF_SIZE)))
395 
396 #define PDQ_OS_IORD_8(port)		inb(port)
397 #define PDQ_OS_IOWR_8(port, data)	outb(port, data)
398 #endif
399 
400 
401 #ifdef PDQ_USE_MBUFS
402 #define	PDQ_OS_DATABUF_SIZE			(MCLBYTES)
403 #ifndef PDQ_OS_DATABUF_FREE
404 #define	PDQ_OS_DATABUF_FREE(pdq, b)		(m_freem(b))
405 #endif
406 #define	PDQ_OS_DATABUF_NEXT(b)			((b)->m_next)
407 #define	PDQ_OS_DATABUF_NEXT_SET(b, b1)		((b)->m_next = (b1))
408 #define	PDQ_OS_DATABUF_NEXTPKT(b)		((b)->m_nextpkt)
409 #define	PDQ_OS_DATABUF_NEXTPKT_SET(b, b1)	((b)->m_nextpkt = (b1))
410 #define	PDQ_OS_DATABUF_LEN(b)			((b)->m_len)
411 #define	PDQ_OS_DATABUF_LEN_SET(b, n)		((b)->m_len = (n))
412 /* #define	PDQ_OS_DATABUF_LEN_ADJ(b, n)		((b)->m_len += (n)) */
413 #define	PDQ_OS_DATABUF_PTR(b)			(mtod((b), pdq_uint8_t *))
414 #define	PDQ_OS_DATABUF_ADJ(b, n)		((b)->m_data += (n), (b)->m_len -= (n))
415 typedef struct mbuf PDQ_OS_DATABUF_T;
416 
417 #ifndef PDQ_OS_DATABUF_ALLOC
418 #define	PDQ_OS_DATABUF_ALLOC(pdq, b) do { \
419     PDQ_OS_DATABUF_T *x_m0; \
420     MGETHDR(x_m0, M_DONTWAIT, MT_DATA); \
421     if (x_m0 != NULL) { \
422 	MCLGET(x_m0, M_DONTWAIT);	\
423 	if ((x_m0->m_flags & M_EXT) == 0) { \
424 	    m_free(x_m0); \
425 	    (b) = NULL; \
426 	} else { \
427 	    (b) = x_m0; \
428 	    x_m0->m_len = PDQ_OS_DATABUF_SIZE; \
429 	} \
430     } else { \
431 	(b) = NULL; \
432     } \
433 } while (0)
434 #endif
435 #define	PDQ_OS_DATABUF_RESET(b)	((b)->m_data = (b)->m_ext.ext_buf, (b)->m_len = MCLBYTES)
436 #endif /* PDQ_USE_MBUFS */
437 
438 #ifdef PDQ_USE_STREAMS
439 #define	PDQ_OS_DATABUF_SIZE			(2048)
440 #define	PDQ_OS_DATABUF_FREE(pdq, b)		(freemsg(b))
441 #define	PDQ_OS_DATABUF_NEXT(b)			((b)->b_cont)
442 #define	PDQ_OS_DATABUF_NEXT_SET(b, b1)		((b)->b_cont = (b1))
443 #define	PDQ_OS_DATABUF_NEXTPKT(b)		((b)->b_next)
444 #define	PDQ_OS_DATABUF_NEXTPKT_SET(b, b1)	((b)->b_next = (b1))
445 #define	PDQ_OS_DATABUF_LEN(b)			((b)->b_wptr - (b)->b_rptr)
446 #define	PDQ_OS_DATABUF_LEN_SET(b, n)		((b)->b_wptr = (b)->b_rptr + (n))
447 /*#define	PDQ_OS_DATABUF_LEN_ADJ(b, n)		((b)->b_wptr += (n))*/
448 #define	PDQ_OS_DATABUF_PTR(b)			((pdq_uint8_t *) (b)->b_rptr)
449 #define	PDQ_OS_DATABUF_ADJ(b, n)		((b)->b_rptr += (n))
450 typedef mblk_t PDQ_OS_DATABUF_T;
451 
452 #ifndef	PDQ_OS_DATABUF_ALLOC
453 #define	PDQ_OS_DATABUF_ALLOC(pdq, b)			((void) (((b) = allocb(PDQ_OS_DATABUF_SIZE, BPRI_MED)) && ((b)->b_wptr = (b)->b_rptr + PDQ_OS_DATABUF_SIZE)))
454 #endif /* PDQ_OS_DATABUF_ALLOC */
455 #endif /* PDQ_USE_STREAMS */
456 
457 #define	PDQ_OS_TX_TRANSMIT		5
458 
459 #define	PDQ_OS_DATABUF_ENQUEUE(q, b)	do { \
460     PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
461     if ((q)->q_tail == NULL) \
462 	(q)->q_head = (b); \
463     else \
464 	PDQ_OS_DATABUF_NEXTPKT_SET(((PDQ_OS_DATABUF_T *)(q)->q_tail), b); \
465     (q)->q_tail = (b); \
466 } while (0)
467 
468 #define	PDQ_OS_DATABUF_DEQUEUE(q, b)	do { \
469     if (((b) = (PDQ_OS_DATABUF_T *) (q)->q_head) != NULL) { \
470 	if (((q)->q_head = PDQ_OS_DATABUF_NEXTPKT(b)) == NULL) \
471 	    (q)->q_tail = NULL; \
472 	PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
473     } \
474 } while (0)
475 
476 #if !defined(PDQ_OS_CONSUMER_PRESYNC)
477 #define	PDQ_OS_CONSUMER_PRESYNC(pdq)		do { } while(0)
478 #define	PDQ_OS_CONSUMER_POSTSYNC(pdq)		do { } while(0)
479 #define	PDQ_OS_DESC_PRESYNC(pdq, d, s)		do { } while(0)
480 #define	PDQ_OS_DESC_POSTSYNC(pdq, d, s)		do { } while(0)
481 #define	PDQ_OS_CMDRQST_PRESYNC(pdq, s)		do { } while(0)
482 #define	PDQ_OS_CMDRQST_POSTSYNC(pdq, s)		do { } while(0)
483 #define	PDQ_OS_CMDRSP_PRESYNC(pdq, s)		do { } while(0)
484 #define	PDQ_OS_CMDRSP_POSTSYNC(pdq, s)		do { } while(0)
485 #define PDQ_OS_RXPDU_PRESYNC(pdq, b, o, l)	do { } while(0)
486 #define PDQ_OS_RXPDU_POSTSYNC(pdq, b, o, l)	do { } while(0)
487 #define PDQ_OS_UNSOL_EVENT_PRESYNC(pdq, e)	do { } while(0)
488 #define PDQ_OS_UNSOL_EVENT_POSTSYNC(pdq, e)	do { } while(0)
489 #endif
490 
491 #ifndef PDQ_OS_DATABUF_BUSPA
492 #define PDQ_OS_DATABUF_BUSPA(pdq, b)	PDQ_OS_VA_TO_BUSPA(pdq, PDQ_OS_DATABUF_PTR(b))
493 #endif
494 
495 #ifndef PDQ_OS_HDR_OFFSET
496 #define	PDQ_OS_HDR_OFFSET	PDQ_RX_FC_OFFSET
497 #endif
498 
499 extern void pdq_os_addr_fill(pdq_t *, pdq_lanaddr_t *, size_t);
500 extern void pdq_os_receive_pdu(pdq_t *, PDQ_OS_DATABUF_T *, size_t, int);
501 extern void pdq_os_restart_transmitter(pdq_t *);
502 extern void pdq_os_transmit_done(pdq_t *, PDQ_OS_DATABUF_T *);
503 #if !defined(pdq_os_update_status)
504 extern void pdq_os_update_status(pdq_t *, const void *);
505 #endif
506 #if !defined(PDQ_OS_MEMALLOC_CONTIG)
507 extern int pdq_os_memalloc_contig(pdq_t *);
508 #endif
509 extern pdq_boolean_t pdq_queue_transmit_data(pdq_t *, PDQ_OS_DATABUF_T *);
510 extern void pdq_flush_transmitter(pdq_t *);
511 
512 extern void pdq_run(pdq_t *);
513 extern pdq_state_t pdq_stop(pdq_t *);
514 extern void pdq_hwreset(pdq_t *);
515 
516 extern int pdq_interrupt(pdq_t *);
517 extern pdq_t *pdq_initialize(pdq_bus_t, pdq_bus_memaddr_t, const char *, int,
518 			     void *, pdq_type_t);
519 #endif /* _PDQ_OS_H */
520