Change mbug allocation flags from M_ to MB_ to avoid confusion with malloc
[dragonfly.git] / sys / dev / netif / pdq_layer / pdqvar.h
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. The name of the author may not be used to endorse or promote products
11 * derived from this software withough specific prior written permission
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * $FreeBSD: src/sys/dev/pdq/pdqvar.h,v 1.3.2.1 2002/05/14 21:02:11 gallatin Exp $
74f1caca 25 * $DragonFly: src/sys/dev/netif/pdq_layer/Attic/pdqvar.h,v 1.6 2004/06/02 14:42:53 eirikn Exp $
984263bc
MD
26 *
27 */
28
29/*
30 * DEC PDQ FDDI Controller; PDQ O/S dependent definitions
31 *
32 * Written by Matt Thomas
33 *
34 */
35
36#ifndef _PDQ_OS_H
37#define _PDQ_OS_H
38
39#define PDQ_OS_TX_TIMEOUT 5 /* seconds */
40
41typedef struct _pdq_t pdq_t;
42typedef struct _pdq_csrs_t pdq_csrs_t;
43typedef struct _pdq_pci_csrs_t pdq_pci_csrs_t;
44typedef struct _pdq_lanaddr_t pdq_lanaddr_t;
45typedef unsigned int pdq_uint32_t;
46typedef unsigned short pdq_uint16_t;
47typedef unsigned char pdq_uint8_t;
48typedef enum _pdq_boolean_t pdq_boolean_t;
49typedef enum _pdq_type_t pdq_type_t;
50typedef enum _pdq_state_t pdq_state_t;
51
52enum _pdq_type_t {
53 PDQ_DEFPA, /* PCI-bus */
54 PDQ_DEFEA, /* EISA-bus */
55 PDQ_DEFTA, /* TurboChannel */
56 PDQ_DEFAA, /* FutureBus+ */
57 PDQ_DEFQA /* Q-bus */
58};
59
60#if defined(PDQTEST)
61#include <pdq_os_test.h>
929783d0 62#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__bsdi__) || defined(__NetBSD__)
984263bc
MD
63
64#include <sys/param.h>
65#include <sys/systm.h>
66#ifndef M_MCAST
67#include <sys/mbuf.h>
68#endif /* M_CAST */
69#include <sys/malloc.h>
70#include <vm/vm.h>
71#include <vm/vm_kern.h>
72
73#define PDQ_USE_MBUFS
74#if defined(__NetBSD__)
75#define PDQ_OS_PREFIX "%s: "
76#define PDQ_OS_PREFIX_ARGS pdq->pdq_os_name
77#else
78#define PDQ_OS_PREFIX "%s%d: "
79#define PDQ_OS_PREFIX_ARGS pdq->pdq_os_name, pdq->pdq_unit
80#endif
929783d0 81#if defined(__DragonFly__) || (defined(__FreeBSD__) && BSD >= 199506)
984263bc
MD
82#define PDQ_OS_PAGESIZE PAGE_SIZE
83#else
84#define PDQ_OS_PAGESIZE NBPG
85#endif
86#define PDQ_OS_USEC_DELAY(n) DELAY(n)
87#define PDQ_OS_MEMZERO(p, n) bzero((caddr_t)(p), (n))
88#if defined(__NetBSD__) && defined(__alpha__)
89#define PDQ_OS_VA_TO_PA(pdq, p) (vtophys((vm_offset_t)p) | (pdq->pdq_type == PDQ_DEFTA ? 0 : 0x40000000))
929783d0 90#elif (defined(__DragonFly__) || defined(__FreeBSD__)) && defined(__alpha__)
984263bc
MD
91#define PDQ_OS_VA_TO_PA(pdq, p) (vtophys((vm_offset_t)p) | (pdq->pdq_type == PDQ_DEFTA ? 0 : alpha_XXX_dmamap_or))
92#else
93#define PDQ_OS_VA_TO_PA(pdq, p) vtophys(p)
94#endif
c5541aee 95#define PDQ_OS_MEMALLOC(n) malloc(n, M_DEVBUF, M_WAITOK)
984263bc 96#define PDQ_OS_MEMFREE(p, n) free((void *) p, M_DEVBUF)
929783d0 97#if defined(__DragonFly__) || defined(__FreeBSD__)
984263bc
MD
98#define PDQ_OS_MEMALLOC_CONTIG(n) vm_page_alloc_contig(n, 0, 0xffffffff, PAGE_SIZE)
99#define PDQ_OS_MEMFREE_CONTIG(p, n) kmem_free(kernel_map, (vm_offset_t) p, n)
100#else
101#define PDQ_OS_MEMALLOC_CONTIG(n) kmem_alloc(kernel_map, round_page(n))
102#define PDQ_OS_MEMFREE_CONTIG(p, n) kmem_free(kernel_map, (vm_offset_t) p, n)
103#endif /* __FreeBSD__ */
104
929783d0 105#if defined(__DragonFly__) || defined(__FreeBSD__)
984263bc
MD
106#include <vm/pmap.h>
107#include <vm/vm_extern.h>
108#include <machine/bus.h>
109#include <machine/cpufunc.h>
110#include <machine/clock.h>
111typedef void ifnet_ret_t;
112typedef u_long ioctl_cmd_t;
113typedef enum { PDQ_BUS_EISA, PDQ_BUS_PCI } pdq_bus_t;
114typedef u_int16_t pdq_bus_ioport_t;
115typedef volatile pdq_uint32_t *pdq_bus_memaddr_t;
116typedef pdq_bus_memaddr_t pdq_bus_memoffset_t;
929783d0 117#if defined(__DragonFly__) || BSD >= 199506 /* __FreeBSD__ */
984263bc
MD
118#define PDQ_BPF_MTAP(sc, m) bpf_mtap(&(sc)->sc_if, m)
119#define PDQ_BPFATTACH(sc, t, s) bpfattach(&(sc)->sc_if, t, s)
120#endif
121
122
123#elif defined(__bsdi__)
124#include <machine/inline.h>
125typedef int ifnet_ret_t;
126typedef int ioctl_cmd_t;
127typedef enum { PDQ_BUS_EISA, PDQ_BUS_PCI } pdq_bus_t;
128typedef u_int16_t pdq_bus_ioport_t;
129typedef volatile pdq_uint32_t *pdq_bus_memaddr_t;
130typedef pdq_bus_memaddr_t pdq_bus_memoffset_t;
131
132
133#elif defined(__NetBSD__)
134#include <machine/bus.h>
135#include <machine/intr.h>
136#define PDQ_OS_PTR_FMT "%p"
137typedef void ifnet_ret_t;
138typedef u_long ioctl_cmd_t;
139typedef bus_chipset_tag_t pdq_bus_t;
140typedef bus_io_handle_t pdq_bus_ioport_t;
141#if defined(PDQ_IOMAPPED)
142typedef bus_io_handle_t pdq_bus_memaddr_t;
143#else
144typedef bus_mem_handle_t pdq_bus_memaddr_t;
145#endif
146typedef pdq_uint32_t pdq_bus_memoffset_t;
147#define PDQ_OS_IOMEM
148#define PDQ_OS_IORD_32(t, base, offset) bus_io_read_4 (t, base, offset)
149#define PDQ_OS_IOWR_32(t, base, offset, data) bus_io_write_4 (t, base, offset, data)
150#define PDQ_OS_IORD_8(t, base, offset) bus_io_read_1 (t, base, offset)
151#define PDQ_OS_IOWR_8(t, base, offset, data) bus_io_write_1 (t, base, offset, data)
152#define PDQ_OS_MEMRD_32(t, base, offset) bus_mem_read_4(t, base, offset)
153#define PDQ_OS_MEMWR_32(t, base, offset, data) bus_mem_write_4(t, base, offset, data)
154#define PDQ_CSR_OFFSET(base, offset) (0 + (offset)*sizeof(pdq_uint32_t))
155
156#if defined(PDQ_IOMAPPED)
157#define PDQ_CSR_WRITE(csr, name, data) PDQ_OS_IOWR_32((csr)->csr_bus, (csr)->csr_base, (csr)->name, data)
158#define PDQ_CSR_READ(csr, name) PDQ_OS_IORD_32((csr)->csr_bus, (csr)->csr_base, (csr)->name)
159#else
160#define PDQ_CSR_WRITE(csr, name, data) PDQ_OS_MEMWR_32((csr)->csr_bus, (csr)->csr_base, (csr)->name, data)
161#define PDQ_CSR_READ(csr, name) PDQ_OS_MEMRD_32((csr)->csr_bus, (csr)->csr_base, (csr)->name)
162#endif
163
164#endif
165
166#if !defined(PDQ_BPF_MTAP)
167#define PDQ_BPF_MTAP(sc, m) bpf_mtap((sc)->sc_bpf, m)
168#endif
169
170#if !defined(PDQ_BPFATTACH)
171#define PDQ_BPFATTACH(sc, t, s) bpfattach(&(sc)->sc_bpf, &(sc)->sc_if, t, s)
172#endif
173
174#if !defined(PDQ_OS_PTR_FMT)
175#define PDQ_OS_PTR_FMT "0x%x"
176#endif
177
178#if !defined(PDQ_OS_IOMEM)
179#define PDQ_OS_IORD_32(t, base, offset) inl((base) + (offset))
180#define PDQ_OS_IOWR_32(t, base, offset, data) outl((base) + (offset), data)
181#define PDQ_OS_IORD_8(t, base, offset) inb((base) + (offset))
182#define PDQ_OS_IOWR_8(t, base, offset, data) outb((base) + (offset), data)
183#define PDQ_OS_MEMRD_32(t, base, offset) readl((base) + (offset))
184#define PDQ_OS_MEMWR_32(t, base, offset, data) writel((base) + (offset), data)
185#endif
186#ifndef PDQ_CSR_OFFSET
187#define PDQ_CSR_OFFSET(base, offset) (0 + (base) + (offset))
188#endif
189
190#ifndef PDQ_CSR_WRITE
191#define PDQ_CSR_WRITE(csr, name, data) PDQ_OS_MEMWR_32((csr)->csr_bus, (csr)->name, 0, data)
192#define PDQ_CSR_READ(csr, name) PDQ_OS_MEMRD_32((csr)->csr_bus, (csr)->name, 0)
193#endif
194
195#if !defined(PDQ_HWSUPPORT)
196
197typedef struct {
198#if defined(__bsdi__)
199 struct device sc_dev; /* base device */
200 struct isadev sc_id; /* ISA device */
201 struct intrhand sc_ih; /* interrupt vectoring */
202 struct atshutdown sc_ats; /* shutdown routine */
203#elif defined(__NetBSD__)
204 struct device sc_dev; /* base device */
205 void *sc_ih; /* interrupt vectoring */
206 void *sc_ats; /* shutdown hook */
929783d0 207#elif defined(__DragonFly__) || defined(__FreeBSD__)
984263bc
MD
208 struct kern_devconf *sc_kdc; /* freebsd cruft */
209#endif
210 struct arpcom sc_ac;
211#define sc_if sc_ac.ac_if
212 pdq_t *sc_pdq;
213#if defined(__alpha__) || defined(__i386__)
214 pdq_bus_ioport_t sc_iobase;
215#endif
216#ifdef PDQ_IOMAPPED
217#define sc_membase sc_iobase
218#else
219 pdq_bus_memaddr_t sc_membase;
220#endif
221 pdq_bus_t sc_bc;
222#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
223#define sc_bpf sc_if.if_bpf
224#else
225 caddr_t sc_bpf;
226#endif
227} pdq_softc_t;
228
229
230extern void pdq_ifreset(pdq_softc_t *sc);
231extern void pdq_ifinit(pdq_softc_t *sc);
232extern void pdq_ifwatchdog(struct ifnet *ifp);
233extern ifnet_ret_t pdq_ifstart(struct ifnet *ifp);
9974b71d
JS
234extern int pdq_ifioctl(struct ifnet *ifp, ioctl_cmd_t cmd, caddr_t data,
235 struct ucred *cr);
984263bc
MD
236extern void pdq_ifattach(pdq_softc_t *sc, ifnet_ret_t (*ifwatchdog)(int unit));
237#endif /* !PDQ_HWSUPPORT */
238
239
240#elif defined(DLPI_PDQ)
241#include <sys/param.h>
242#include <sys/kmem.h>
243#include <sys/ddi.h>
244#include <sys/stream.h>
245
246#define PDQ_USE_STREAMS
247#define PDQ_OS_PREFIX "%s board %d "
248#define PDQ_OS_PREFIX_ARGS pdq->pdq_os_name, pdq->pdq_unit
249
250#define PDQ_OS_PAGESIZE PAGESIZE
251#define PDQ_OS_USEC_DELAY(n) drv_usecwait(n)
252#define PDQ_OS_MEMZERO(p, n) bzero((caddr_t)(p), (n))
253#define PDQ_OS_VA_TO_PA(pdq, p) vtop((caddr_t)p, NULL)
254#define PDQ_OS_MEMALLOC(n) kmem_zalloc(n, KM_NOSLEEP)
255#define PDQ_OS_MEMFREE(p, n) kmem_free((caddr_t) p, n)
256#define PDQ_OS_MEMALLOC_CONTIG(n) kmem_zalloc_physreq(n, decfddiphysreq_db, KM_NOSLEEP)
257#define PDQ_OS_MEMFREE_CONTIG(p, n) PDQ_OS_MEMFREE(p, n)
258
259extern physreq_t *decfddiphysreq_db;
260extern physreq_t *decfddiphysreq_mblk;
261
262#define PDQ_OS_DATABUF_ALLOC(b) ((void) (((b) = allocb_physreq(PDQ_OS_DATABUF_SIZE, BPRI_MED, decfddiphysreq_mblk)) && ((b)->b_wptr = (b)->b_rptr + PDQ_OS_DATABUF_SIZE)))
263
264#define PDQ_OS_IORD_8(port) inb(port)
265#define PDQ_OS_IOWR_8(port, data) outb(port, data)
266#endif
267
268
269#ifdef PDQ_USE_MBUFS
270#define PDQ_OS_DATABUF_SIZE (MCLBYTES)
271#define PDQ_OS_DATABUF_FREE(b) (m_freem(b))
272#define PDQ_OS_DATABUF_NEXT(b) ((b)->m_next)
273#define PDQ_OS_DATABUF_NEXT_SET(b, b1) ((b)->m_next = (b1))
274#define PDQ_OS_DATABUF_NEXTPKT(b) ((b)->m_nextpkt)
275#define PDQ_OS_DATABUF_NEXTPKT_SET(b, b1) ((b)->m_nextpkt = (b1))
276#define PDQ_OS_DATABUF_LEN(b) ((b)->m_len)
277#define PDQ_OS_DATABUF_LEN_SET(b, n) ((b)->m_len = (n))
278/* #define PDQ_OS_DATABUF_LEN_ADJ(b, n) ((b)->m_len += (n)) */
279#define PDQ_OS_DATABUF_PTR(b) (mtod((b), pdq_uint8_t *))
280#define PDQ_OS_DATABUF_ADJ(b, n) ((b)->m_data += (n), (b)->m_len -= (n))
281typedef struct mbuf PDQ_OS_DATABUF_T;
282
283#define PDQ_OS_DATABUF_ALLOC(b) do { \
284 PDQ_OS_DATABUF_T *x_m0; \
74f1caca 285 MGETHDR(x_m0, MB_DONTWAIT, MT_DATA); \
984263bc 286 if (x_m0 != NULL) { \
74f1caca 287 MCLGET(x_m0, MB_DONTWAIT); \
984263bc
MD
288 if ((x_m0->m_flags & M_EXT) == 0) { \
289 m_free(x_m0); \
290 (b) = NULL; \
291 } else { \
292 (b) = x_m0; \
293 x_m0->m_len = PDQ_OS_DATABUF_SIZE; \
294 } \
295 } else { \
296 (b) = NULL; \
297 } \
298} while (0)
299#define PDQ_OS_DATABUF_RESET(b) ((b)->m_data = (b)->m_ext.ext_buf, (b)->m_len = MCLBYTES)
300#endif /* PDQ_USE_MBUFS */
301
302#ifdef PDQ_USE_STREAMS
303#define PDQ_OS_DATABUF_SIZE (2048)
304#define PDQ_OS_DATABUF_FREE(b) (freemsg(b))
305#define PDQ_OS_DATABUF_NEXT(b) ((b)->b_cont)
306#define PDQ_OS_DATABUF_NEXT_SET(b, b1) ((b)->b_cont = (b1))
307#define PDQ_OS_DATABUF_NEXTPKT(b) ((b)->b_next)
308#define PDQ_OS_DATABUF_NEXTPKT_SET(b, b1) ((b)->b_next = (b1))
309#define PDQ_OS_DATABUF_LEN(b) ((b)->b_wptr - (b)->b_rptr)
310#define PDQ_OS_DATABUF_LEN_SET(b, n) ((b)->b_wptr = (b)->b_rptr + (n))
311/*#define PDQ_OS_DATABUF_LEN_ADJ(b, n) ((b)->b_wptr += (n))*/
312#define PDQ_OS_DATABUF_PTR(b) ((pdq_uint8_t *) (b)->b_rptr)
313#define PDQ_OS_DATABUF_ADJ(b, n) ((b)->b_rptr += (n))
314typedef mblk_t PDQ_OS_DATABUF_T;
315
316#ifndef PDQ_OS_DATABUF_ALLOC
317#define PDQ_OS_DATABUF_ALLOC(b) ((void) (((b) = allocb(PDQ_OS_DATABUF_SIZE, BPRI_MED)) && ((b)->b_wptr = (b)->b_rptr + PDQ_OS_DATABUF_SIZE)))
318#endif /* PDQ_OS_DATABUF_ALLOC */
319#endif /* PDQ_USE_STREAMS */
320
321#define PDQ_OS_TX_TRANSMIT 5
322
323#define PDQ_OS_DATABUF_ENQUEUE(q, b) do { \
324 PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
325 if ((q)->q_tail == NULL) \
326 (q)->q_head = (b); \
327 else \
328 PDQ_OS_DATABUF_NEXTPKT_SET(((PDQ_OS_DATABUF_T *)(q)->q_tail), b); \
329 (q)->q_tail = (b); \
330} while (0)
331
332#define PDQ_OS_DATABUF_DEQUEUE(q, b) do { \
333 if (((b) = (PDQ_OS_DATABUF_T *) (q)->q_head) != NULL) { \
334 if (((q)->q_head = PDQ_OS_DATABUF_NEXTPKT(b)) == NULL) \
335 (q)->q_tail = NULL; \
336 PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
337 } \
338} while (0)
339
340extern void pdq_os_addr_fill(pdq_t *pdq, pdq_lanaddr_t *addrs, size_t numaddrs);
341extern void pdq_os_receive_pdu(pdq_t *, PDQ_OS_DATABUF_T *pdu, size_t pdulen);
342extern void pdq_os_restart_transmitter(pdq_t *pdq);
343extern void pdq_os_transmit_done(pdq_t *pdq, PDQ_OS_DATABUF_T *pdu);
344
345extern pdq_boolean_t pdq_queue_transmit_data(pdq_t *pdq, PDQ_OS_DATABUF_T *pdu);
346extern void pdq_flush_transmitter(pdq_t *pdq);
347
348extern void pdq_run(pdq_t *pdq);
349extern pdq_state_t pdq_stop(pdq_t *pdq);
350extern void pdq_hwreset(pdq_t *pdq);
351
352extern int pdq_interrupt(pdq_t *pdq);
353extern pdq_t *pdq_initialize(pdq_bus_t bus, pdq_bus_memaddr_t csr_va,
354 const char *name, int unit,
355 void *ctx, pdq_type_t type);
356#endif /* _PDQ_OS_H */