pdq_freebsd.h revision 330897
1/*	$NetBSD: pdqvar.h,v 1.27 2000/05/03 19:17:54 thorpej Exp $	*/
2
3/*-
4 * SPDX-License-Identifier: BSD-2-Clause-NetBSD
5 *
6 * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Id: pdqvar.h,v 1.21 1997/03/21 21:16:04 thomas Exp
29 * $FreeBSD: stable/11/sys/dev/pdq/pdq_freebsd.h 330897 2018-03-14 03:19:51Z eadler $
30 *
31 */
32
33/*
34 * DEC PDQ FDDI Controller; PDQ O/S dependent definitions
35 *
36 * Written by Matt Thomas
37 *
38 */
39
40#if defined(PDQ_HWSUPPORT)
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/kernel.h>
44#include <sys/lock.h>
45#include <sys/mutex.h>
46#include <sys/malloc.h>
47#include <sys/socket.h>
48#include <sys/sockio.h>
49
50#include <sys/module.h>
51#include <sys/bus.h>
52
53#include <machine/bus.h>
54#include <machine/resource.h>
55#include <sys/rman.h>
56
57#include <net/if.h>
58#include <net/if_var.h>
59#include <net/if_arp.h>
60#include <net/if_dl.h>
61#include <net/if_media.h>
62#include <net/fddi.h>
63
64#include <net/bpf.h>
65
66#include <vm/vm.h>              /* for vtophys */
67#include <vm/pmap.h>            /* for vtophys */
68
69#endif	/* PDQ_HWSUPPORT */
70
71typedef struct _pdq_t pdq_t;
72typedef struct _pdq_csrs_t pdq_csrs_t;
73typedef struct _pdq_pci_csrs_t pdq_pci_csrs_t;
74typedef struct _pdq_lanaddr_t pdq_lanaddr_t;
75typedef unsigned int pdq_uint32_t;
76typedef unsigned short pdq_uint16_t;
77typedef unsigned char pdq_uint8_t;
78typedef enum _pdq_boolean_t pdq_boolean_t;
79typedef enum _pdq_type_t pdq_type_t;
80typedef enum _pdq_state_t pdq_state_t;
81typedef struct mbuf PDQ_OS_DATABUF_T;
82
83typedef bus_space_tag_t pdq_bus_t;
84typedef bus_space_handle_t pdq_bus_memaddr_t;
85typedef pdq_bus_memaddr_t pdq_bus_memoffset_t;
86
87extern devclass_t pdq_devclass;
88
89enum _pdq_type_t {
90    PDQ_DEFPA,		/* PCI-bus */
91    PDQ_DEFEA,		/* EISA-bus */
92    PDQ_DEFTA,		/* TurboChannel */
93    PDQ_DEFAA,		/* FutureBus+ */
94    PDQ_DEFQA		/* Q-bus */
95};
96
97#define	sc_ifmedia	ifmedia
98#if 0 /* ALTQ */
99#define	IFQ_DEQUEUE	IF_DEQUEUE
100#define	IFQ_IS_EMPTY(q)	((q)->ifq_len == 0)
101#endif
102
103typedef struct _pdq_os_ctx_t {
104	struct ifnet		*ifp;
105	struct ifmedia		ifmedia;
106	device_t		dev;
107	int			debug;
108
109	pdq_t *			sc_pdq;
110	int			sc_flags;
111#define	PDQIF_DOWNCALL		0x0001	/* active calling from if to pdq */
112
113	struct resource *	io;
114	int			io_rid;
115	int			io_type;
116	bus_space_handle_t	io_bsh;
117	bus_space_tag_t		io_bst;
118
119	struct resource *	mem;
120	int			mem_rid;
121	int			mem_type;
122	bus_space_handle_t	mem_bsh;
123	bus_space_tag_t		mem_bst;
124
125	struct resource *	irq;
126	int			irq_rid;
127	void *			irq_ih;
128
129	struct mtx		mtx;
130	struct callout		watchdog;
131	int			timer;
132} pdq_softc_t;
133
134#define PDQ_LOCK(_sc)		mtx_lock(&(_sc)->mtx)
135#define PDQ_UNLOCK(_sc)		mtx_unlock(&(_sc)->mtx)
136#define	PDQ_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->mtx, MA_OWNED)
137
138#define	PDQ_OS_HDR_OFFSET	PDQ_RX_FC_OFFSET
139
140#define	PDQ_OS_PAGESIZE		PAGE_SIZE
141#define	PDQ_OS_TX_TRANSMIT	5
142
143#define	PDQ_OS_IORD_32(bt, bh, off)		bus_space_read_4(bt, bh, off)
144#define	PDQ_OS_IOWR_32(bt, bh, off, data)	bus_space_write_4(bt, bh, off, data)
145#define	PDQ_OS_IORD_8(bt, bh, off)		bus_space_read_1(bt, bh, off)
146#define	PDQ_OS_IOWR_8(bt, bh, off, data)	bus_space_write_1(bt, bh, off, data)
147
148#define	PDQ_CSR_OFFSET(base, offset)		(0 + (offset)*sizeof(pdq_uint32_t))
149#define	PDQ_CSR_WRITE(csr, name, data)		PDQ_OS_IOWR_32((csr)->csr_bus, (csr)->csr_base, (csr)->name, data)
150#define	PDQ_CSR_READ(csr, name)			PDQ_OS_IORD_32((csr)->csr_bus, (csr)->csr_base, (csr)->name)
151
152#define	PDQ_OS_DATABUF_FREE(pdq, b)		(m_freem(b))
153
154#if defined(PDQ_OSSUPPORT)
155#define	PDQ_OS_TX_TIMEOUT		5	/* seconds */
156
157#define	PDQ_OS_IFP_TO_SOFTC(ifp)	((pdq_softc_t *) (ifp)->if_softc)
158#define	PDQ_BPF_MTAP(sc, m)		BPF_MTAP((sc)->ifp, m)
159#define PDQ_IFNET(sc)			((sc)->ifp)
160
161#endif	/* PDQ_OSSUPPORT */
162
163#if defined(PDQ_HWSUPPORT)
164
165#define	PDQ_OS_PREFIX			"%s: "
166#define	PDQ_OS_PREFIX_ARGS		pdq->pdq_os_name
167
168#define	PDQ_OS_PTR_FMT	"%p"
169#define	PDQ_OS_CSR_FMT	"0x%x"
170
171#define	PDQ_OS_USEC_DELAY(n)		DELAY(n)
172#define	PDQ_OS_VA_TO_BUSPA(pdq, p)	vtophys(p)
173
174#define	PDQ_OS_MEMALLOC(n)		malloc(n, M_DEVBUF, M_NOWAIT)
175#define	PDQ_OS_MEMFREE(p, n)		free((void *) p, M_DEVBUF)
176#define	PDQ_OS_MEMZERO(p, n)		bzero((caddr_t)(p), (n))
177#define	PDQ_OS_MEMALLOC_CONTIG(n)	contigmalloc(n, M_DEVBUF, M_NOWAIT, 0x800000, ~0, PAGE_SIZE, 0)
178#define PDQ_OS_MEMFREE_CONTIG(p, n)	contigfree(p, n, M_DEVBUF)
179
180#define	PDQ_OS_DATABUF_SIZE			(MCLBYTES)
181#define	PDQ_OS_DATABUF_NEXT(b)			((b)->m_next)
182#define	PDQ_OS_DATABUF_NEXT_SET(b, b1)		((b)->m_next = (b1))
183#define	PDQ_OS_DATABUF_NEXTPKT(b)		((b)->m_nextpkt)
184#define	PDQ_OS_DATABUF_NEXTPKT_SET(b, b1)	((b)->m_nextpkt = (b1))
185#define	PDQ_OS_DATABUF_LEN(b)			((b)->m_len)
186#define	PDQ_OS_DATABUF_LEN_SET(b, n)		((b)->m_len = (n))
187/* #define	PDQ_OS_DATABUF_LEN_ADJ(b, n)		((b)->m_len += (n)) */
188#define	PDQ_OS_DATABUF_PTR(b)			(mtod((b), pdq_uint8_t *))
189#define	PDQ_OS_DATABUF_ADJ(b, n)		((b)->m_data += (n), (b)->m_len -= (n))
190
191#define	PDQ_OS_DATABUF_ALLOC(pdq, b) do { \
192    PDQ_OS_DATABUF_T *x_m0; \
193    MGETHDR(x_m0, M_NOWAIT, MT_DATA); \
194    if (x_m0 != NULL) { \
195	if (!(MCLGET(x_m0, M_NOWAIT))) { \
196	    m_free(x_m0); \
197	    (b) = NULL; \
198	} else { \
199	    (b) = x_m0; \
200	    x_m0->m_len = PDQ_OS_DATABUF_SIZE; \
201	} \
202    } else { \
203	(b) = NULL; \
204    } \
205} while (0)
206
207#define	PDQ_OS_DATABUF_RESET(b)	((b)->m_data = (b)->m_ext.ext_buf, (b)->m_len = MCLBYTES)
208
209#define	PDQ_OS_DATABUF_ENQUEUE(q, b)	do { \
210    PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
211    if ((q)->q_tail == NULL) \
212	(q)->q_head = (b); \
213    else \
214	PDQ_OS_DATABUF_NEXTPKT_SET(((PDQ_OS_DATABUF_T *)(q)->q_tail), b); \
215    (q)->q_tail = (b); \
216} while (0)
217
218#define	PDQ_OS_DATABUF_DEQUEUE(q, b)	do { \
219    if (((b) = (PDQ_OS_DATABUF_T *) (q)->q_head) != NULL) { \
220	if (((q)->q_head = PDQ_OS_DATABUF_NEXTPKT(b)) == NULL) \
221	    (q)->q_tail = NULL; \
222	PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
223    } \
224} while (0)
225
226#define PDQ_OS_DATABUF_BUSPA(pdq, b)	PDQ_OS_VA_TO_BUSPA(pdq, PDQ_OS_DATABUF_PTR(b))
227
228#define	PDQ_OS_CONSUMER_PRESYNC(pdq)		do { } while(0)
229#define	PDQ_OS_CONSUMER_POSTSYNC(pdq)		do { } while(0)
230#define	PDQ_OS_DESC_PRESYNC(pdq, d, s)		do { } while(0)
231#define	PDQ_OS_DESC_POSTSYNC(pdq, d, s)		do { } while(0)
232#define	PDQ_OS_CMDRQST_PRESYNC(pdq, s)		do { } while(0)
233#define	PDQ_OS_CMDRQST_POSTSYNC(pdq, s)		do { } while(0)
234#define	PDQ_OS_CMDRSP_PRESYNC(pdq, s)		do { } while(0)
235#define	PDQ_OS_CMDRSP_POSTSYNC(pdq, s)		do { } while(0)
236#define PDQ_OS_RXPDU_PRESYNC(pdq, b, o, l)	do { } while(0)
237#define PDQ_OS_RXPDU_POSTSYNC(pdq, b, o, l)	do { } while(0)
238#define PDQ_OS_UNSOL_EVENT_PRESYNC(pdq, e)	do { } while(0)
239#define PDQ_OS_UNSOL_EVENT_POSTSYNC(pdq, e)	do { } while(0)
240
241#endif	/* PDQ_HWSUPPORT */
242
243/*
244 * OS dependent functions provided by pdq_ifsubr.c to pdq.c
245 */
246void	pdq_os_addr_fill (pdq_t *pdq, pdq_lanaddr_t *addrs, size_t numaddrs);
247void	pdq_os_receive_pdu (pdq_t *, PDQ_OS_DATABUF_T *, size_t, int);
248void	pdq_os_restart_transmitter (pdq_t *pdq);
249void	pdq_os_transmit_done (pdq_t *, PDQ_OS_DATABUF_T *);
250void	pdq_os_update_status (pdq_t *, const void *);
251
252/*
253 * Driver interfaces functions provided by pdq.c to pdq_ifsubr.c
254 */
255pdq_boolean_t	pdq_queue_transmit_data (pdq_t *pdq, PDQ_OS_DATABUF_T *pdu);
256void		pdq_run	 (pdq_t *pdq);
257pdq_state_t	pdq_stop (pdq_t *pdq);
258
259/*
260 * OS dependent functions provided by
261 * pdq_ifsubr.c or pdq.c to the bus front ends
262 */
263int		pdq_ifattach (pdq_softc_t *, const pdq_uint8_t *,
264			      pdq_type_t type);
265void		pdq_ifdetach (pdq_softc_t *);
266void		pdq_free (device_t);
267int		pdq_interrupt (pdq_t *pdq);
268void		pdq_hwreset (pdq_t *pdq);
269pdq_t *		pdq_initialize (pdq_bus_t bus, pdq_bus_memaddr_t csr_va,
270				const char *name, int unit,
271				void *ctx, pdq_type_t type);
272/*
273 * Misc prototypes.
274 */
275void		pdq_flush_transmitter(pdq_t *pdq);
276