Do a major clean-up of the BUSDMA architecture. A large number of
[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 $
1f7ab7c9 25 * $DragonFly: src/sys/dev/netif/pdq_layer/Attic/pdqvar.h,v 1.11 2006/10/25 20:55:58 dillon 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>
1f7ab7c9
MD
70#include <sys/bus.h>
71
984263bc
MD
72#include <vm/vm.h>
73#include <vm/vm_kern.h>
74
75#define PDQ_USE_MBUFS
76#if defined(__NetBSD__)
77#define PDQ_OS_PREFIX "%s: "
78#define PDQ_OS_PREFIX_ARGS pdq->pdq_os_name
79#else
80#define PDQ_OS_PREFIX "%s%d: "
81#define PDQ_OS_PREFIX_ARGS pdq->pdq_os_name, pdq->pdq_unit
82#endif
929783d0 83#if defined(__DragonFly__) || (defined(__FreeBSD__) && BSD >= 199506)
984263bc
MD
84#define PDQ_OS_PAGESIZE PAGE_SIZE
85#else
86#define PDQ_OS_PAGESIZE NBPG
87#endif
88#define PDQ_OS_USEC_DELAY(n) DELAY(n)
89#define PDQ_OS_MEMZERO(p, n) bzero((caddr_t)(p), (n))
984263bc 90#define PDQ_OS_VA_TO_PA(pdq, p) vtophys(p)
77652cad
MD
91#define PDQ_OS_MEMALLOC(n) kmalloc(n, M_DEVBUF, M_WAITOK)
92#define PDQ_OS_MEMFREE(p, n) kfree((void *) p, M_DEVBUF)
929783d0 93#if defined(__DragonFly__) || defined(__FreeBSD__)
984263bc
MD
94#define PDQ_OS_MEMALLOC_CONTIG(n) vm_page_alloc_contig(n, 0, 0xffffffff, PAGE_SIZE)
95#define PDQ_OS_MEMFREE_CONTIG(p, n) kmem_free(kernel_map, (vm_offset_t) p, n)
96#else
97#define PDQ_OS_MEMALLOC_CONTIG(n) kmem_alloc(kernel_map, round_page(n))
98#define PDQ_OS_MEMFREE_CONTIG(p, n) kmem_free(kernel_map, (vm_offset_t) p, n)
99#endif /* __FreeBSD__ */
100
984263bc
MD
101#include <vm/pmap.h>
102#include <vm/vm_extern.h>
984263bc
MD
103#include <machine/cpufunc.h>
104#include <machine/clock.h>
1f7ab7c9 105
984263bc
MD
106typedef void ifnet_ret_t;
107typedef u_long ioctl_cmd_t;
108typedef enum { PDQ_BUS_EISA, PDQ_BUS_PCI } pdq_bus_t;
109typedef u_int16_t pdq_bus_ioport_t;
110typedef volatile pdq_uint32_t *pdq_bus_memaddr_t;
111typedef pdq_bus_memaddr_t pdq_bus_memoffset_t;
984263bc 112
984263bc
MD
113#if !defined(PDQ_OS_PTR_FMT)
114#define PDQ_OS_PTR_FMT "0x%x"
115#endif
116
117#if !defined(PDQ_OS_IOMEM)
118#define PDQ_OS_IORD_32(t, base, offset) inl((base) + (offset))
119#define PDQ_OS_IOWR_32(t, base, offset, data) outl((base) + (offset), data)
120#define PDQ_OS_IORD_8(t, base, offset) inb((base) + (offset))
121#define PDQ_OS_IOWR_8(t, base, offset, data) outb((base) + (offset), data)
122#define PDQ_OS_MEMRD_32(t, base, offset) readl((base) + (offset))
123#define PDQ_OS_MEMWR_32(t, base, offset, data) writel((base) + (offset), data)
124#endif
125#ifndef PDQ_CSR_OFFSET
126#define PDQ_CSR_OFFSET(base, offset) (0 + (base) + (offset))
127#endif
128
129#ifndef PDQ_CSR_WRITE
130#define PDQ_CSR_WRITE(csr, name, data) PDQ_OS_MEMWR_32((csr)->csr_bus, (csr)->name, 0, data)
131#define PDQ_CSR_READ(csr, name) PDQ_OS_MEMRD_32((csr)->csr_bus, (csr)->name, 0)
132#endif
133
134#if !defined(PDQ_HWSUPPORT)
135
136typedef struct {
137#if defined(__bsdi__)
138 struct device sc_dev; /* base device */
139 struct isadev sc_id; /* ISA device */
140 struct intrhand sc_ih; /* interrupt vectoring */
141 struct atshutdown sc_ats; /* shutdown routine */
142#elif defined(__NetBSD__)
143 struct device sc_dev; /* base device */
144 void *sc_ih; /* interrupt vectoring */
145 void *sc_ats; /* shutdown hook */
929783d0 146#elif defined(__DragonFly__) || defined(__FreeBSD__)
984263bc
MD
147 struct kern_devconf *sc_kdc; /* freebsd cruft */
148#endif
149 struct arpcom sc_ac;
150#define sc_if sc_ac.ac_if
151 pdq_t *sc_pdq;
469ac2dc 152#if defined(__i386__)
984263bc
MD
153 pdq_bus_ioport_t sc_iobase;
154#endif
155#ifdef PDQ_IOMAPPED
156#define sc_membase sc_iobase
157#else
158 pdq_bus_memaddr_t sc_membase;
159#endif
160 pdq_bus_t sc_bc;
984263bc
MD
161} pdq_softc_t;
162
163
164extern void pdq_ifreset(pdq_softc_t *sc);
165extern void pdq_ifinit(pdq_softc_t *sc);
166extern void pdq_ifwatchdog(struct ifnet *ifp);
167extern ifnet_ret_t pdq_ifstart(struct ifnet *ifp);
9974b71d
JS
168extern int pdq_ifioctl(struct ifnet *ifp, ioctl_cmd_t cmd, caddr_t data,
169 struct ucred *cr);
984263bc
MD
170extern void pdq_ifattach(pdq_softc_t *sc, ifnet_ret_t (*ifwatchdog)(int unit));
171#endif /* !PDQ_HWSUPPORT */
172
173
174#elif defined(DLPI_PDQ)
175#include <sys/param.h>
176#include <sys/kmem.h>
177#include <sys/ddi.h>
178#include <sys/stream.h>
179
180#define PDQ_USE_STREAMS
181#define PDQ_OS_PREFIX "%s board %d "
182#define PDQ_OS_PREFIX_ARGS pdq->pdq_os_name, pdq->pdq_unit
183
184#define PDQ_OS_PAGESIZE PAGESIZE
185#define PDQ_OS_USEC_DELAY(n) drv_usecwait(n)
186#define PDQ_OS_MEMZERO(p, n) bzero((caddr_t)(p), (n))
187#define PDQ_OS_VA_TO_PA(pdq, p) vtop((caddr_t)p, NULL)
188#define PDQ_OS_MEMALLOC(n) kmem_zalloc(n, KM_NOSLEEP)
189#define PDQ_OS_MEMFREE(p, n) kmem_free((caddr_t) p, n)
190#define PDQ_OS_MEMALLOC_CONTIG(n) kmem_zalloc_physreq(n, decfddiphysreq_db, KM_NOSLEEP)
191#define PDQ_OS_MEMFREE_CONTIG(p, n) PDQ_OS_MEMFREE(p, n)
192
193extern physreq_t *decfddiphysreq_db;
194extern physreq_t *decfddiphysreq_mblk;
195
196#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)))
197
198#define PDQ_OS_IORD_8(port) inb(port)
199#define PDQ_OS_IOWR_8(port, data) outb(port, data)
200#endif
201
202
203#ifdef PDQ_USE_MBUFS
204#define PDQ_OS_DATABUF_SIZE (MCLBYTES)
205#define PDQ_OS_DATABUF_FREE(b) (m_freem(b))
206#define PDQ_OS_DATABUF_NEXT(b) ((b)->m_next)
207#define PDQ_OS_DATABUF_NEXT_SET(b, b1) ((b)->m_next = (b1))
208#define PDQ_OS_DATABUF_NEXTPKT(b) ((b)->m_nextpkt)
209#define PDQ_OS_DATABUF_NEXTPKT_SET(b, b1) ((b)->m_nextpkt = (b1))
210#define PDQ_OS_DATABUF_LEN(b) ((b)->m_len)
211#define PDQ_OS_DATABUF_LEN_SET(b, n) ((b)->m_len = (n))
212/* #define PDQ_OS_DATABUF_LEN_ADJ(b, n) ((b)->m_len += (n)) */
213#define PDQ_OS_DATABUF_PTR(b) (mtod((b), pdq_uint8_t *))
214#define PDQ_OS_DATABUF_ADJ(b, n) ((b)->m_data += (n), (b)->m_len -= (n))
215typedef struct mbuf PDQ_OS_DATABUF_T;
216
217#define PDQ_OS_DATABUF_ALLOC(b) do { \
218 PDQ_OS_DATABUF_T *x_m0; \
74f1caca 219 MGETHDR(x_m0, MB_DONTWAIT, MT_DATA); \
984263bc 220 if (x_m0 != NULL) { \
74f1caca 221 MCLGET(x_m0, MB_DONTWAIT); \
984263bc
MD
222 if ((x_m0->m_flags & M_EXT) == 0) { \
223 m_free(x_m0); \
224 (b) = NULL; \
225 } else { \
226 (b) = x_m0; \
227 x_m0->m_len = PDQ_OS_DATABUF_SIZE; \
228 } \
229 } else { \
230 (b) = NULL; \
231 } \
232} while (0)
233#define PDQ_OS_DATABUF_RESET(b) ((b)->m_data = (b)->m_ext.ext_buf, (b)->m_len = MCLBYTES)
234#endif /* PDQ_USE_MBUFS */
235
236#ifdef PDQ_USE_STREAMS
237#define PDQ_OS_DATABUF_SIZE (2048)
238#define PDQ_OS_DATABUF_FREE(b) (freemsg(b))
239#define PDQ_OS_DATABUF_NEXT(b) ((b)->b_cont)
240#define PDQ_OS_DATABUF_NEXT_SET(b, b1) ((b)->b_cont = (b1))
241#define PDQ_OS_DATABUF_NEXTPKT(b) ((b)->b_next)
242#define PDQ_OS_DATABUF_NEXTPKT_SET(b, b1) ((b)->b_next = (b1))
243#define PDQ_OS_DATABUF_LEN(b) ((b)->b_wptr - (b)->b_rptr)
244#define PDQ_OS_DATABUF_LEN_SET(b, n) ((b)->b_wptr = (b)->b_rptr + (n))
245/*#define PDQ_OS_DATABUF_LEN_ADJ(b, n) ((b)->b_wptr += (n))*/
246#define PDQ_OS_DATABUF_PTR(b) ((pdq_uint8_t *) (b)->b_rptr)
247#define PDQ_OS_DATABUF_ADJ(b, n) ((b)->b_rptr += (n))
248typedef mblk_t PDQ_OS_DATABUF_T;
249
250#ifndef PDQ_OS_DATABUF_ALLOC
251#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)))
252#endif /* PDQ_OS_DATABUF_ALLOC */
253#endif /* PDQ_USE_STREAMS */
254
255#define PDQ_OS_TX_TRANSMIT 5
256
257#define PDQ_OS_DATABUF_ENQUEUE(q, b) do { \
258 PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
259 if ((q)->q_tail == NULL) \
260 (q)->q_head = (b); \
261 else \
262 PDQ_OS_DATABUF_NEXTPKT_SET(((PDQ_OS_DATABUF_T *)(q)->q_tail), b); \
263 (q)->q_tail = (b); \
264} while (0)
265
266#define PDQ_OS_DATABUF_DEQUEUE(q, b) do { \
267 if (((b) = (PDQ_OS_DATABUF_T *) (q)->q_head) != NULL) { \
268 if (((q)->q_head = PDQ_OS_DATABUF_NEXTPKT(b)) == NULL) \
269 (q)->q_tail = NULL; \
270 PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
271 } \
272} while (0)
273
274extern void pdq_os_addr_fill(pdq_t *pdq, pdq_lanaddr_t *addrs, size_t numaddrs);
275extern void pdq_os_receive_pdu(pdq_t *, PDQ_OS_DATABUF_T *pdu, size_t pdulen);
276extern void pdq_os_restart_transmitter(pdq_t *pdq);
277extern void pdq_os_transmit_done(pdq_t *pdq, PDQ_OS_DATABUF_T *pdu);
278
8a2d8ee2 279pdq_boolean_t pdq_queue_transmit_data(struct ifnet *, pdq_t *, PDQ_OS_DATABUF_T *);
984263bc
MD
280extern void pdq_flush_transmitter(pdq_t *pdq);
281
282extern void pdq_run(pdq_t *pdq);
283extern pdq_state_t pdq_stop(pdq_t *pdq);
284extern void pdq_hwreset(pdq_t *pdq);
285
286extern int pdq_interrupt(pdq_t *pdq);
287extern pdq_t *pdq_initialize(pdq_bus_t bus, pdq_bus_memaddr_t csr_va,
288 const char *name, int unit,
289 void *ctx, pdq_type_t type);
290#endif /* _PDQ_OS_H */