xref: /netbsd/sys/dev/qbus/if_uba.h (revision bf9ec67e)
1 /*	$NetBSD: if_uba.h,v 1.11 2001/08/16 14:56:30 ragge Exp $	*/
2 
3 /*
4  * Copyright (c) 1982, 1986 Regents of the University of California.
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. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	@(#)if_uba.h	7.4 (Berkeley) 6/28/90
36  */
37 
38 /*
39  * Structure and routine definitions
40  * for UNIBUS network interfaces.
41  */
42 
43 /*
44  * Each interface has structures giving information
45  * about UNIBUS resources held by the interface
46  * for each send and receive buffer.
47  *
48  * We hold IF_NUBAMR map registers for datagram data, starting
49  * at ifr_mr.  Map register ifr_mr[-1] maps the local network header
50  * ending on the page boundary.  Bdp's are reserved for read and for
51  * write, given by ifr_bdp.  The prototype of the map register for
52  * read and for write is saved in ifr_proto.
53  *
54  * When write transfers are not full pages on page boundaries we just
55  * copy the data into the pages mapped on the UNIBUS and start the
56  * transfer.  If a write transfer is of a (1024 byte) page on a page
57  * boundary, we swap in UNIBUS pte's to reference the pages, and then
58  * remap the initial pages (from ifu_wmap) when the transfer completes.
59  *
60  * When read transfers give whole pages of data to be input, we
61  * allocate page frames from a network page list and trade them
62  * with the pages already containing the data, mapping the allocated
63  * pages to replace the input pages for the next UNIBUS data input.
64  */
65 
66 /*
67  * Information per interface.
68  */
69 struct	ifubinfo {
70 	struct	uba_softc *iff_softc;		/* uba */
71 };
72 
73 /*
74  * Information per buffer.
75  */
76 struct ifrw {
77 	short	ifrw_bdp;			/* unibus bdp */
78 	short	ifrw_flags;			/* type, etc. */
79 #define	IFRW_MBUF	0x01			/* uses DMA from mbuf */
80 	bus_dmamap_t ifrw_map;			/* DMA map */
81 	struct	mbuf *ifrw_mbuf;
82 };
83 
84 /*
85  * Information per transmit buffer, including the above.
86  */
87 struct ifxmt {
88 	struct	ifrw ifrw;
89 	caddr_t	ifw_vaddr;			/* DMA memory virtual addr */
90 	int	ifw_size;			/* Size of this DMA block */
91 };
92 #define	ifrw_addr	ifrw_mbuf->m_data
93 #define ifrw_info	ifrw_map->dm_segs[0].ds_addr
94 #define	ifw_addr	ifrw.ifrw_addr
95 #define	ifw_bdp		ifrw.ifrw_bdp
96 #define	ifw_flags	ifrw.ifrw_flags
97 #define	ifw_info	ifrw.ifrw_info
98 #define	ifw_proto	ifrw.ifrw_proto
99 #define	ifw_mr		ifrw.ifrw_mr
100 #define	ifw_map		ifrw.ifrw_map
101 #define ifw_mbuf	ifrw.ifrw_mbuf
102 
103 /*
104  * Most interfaces have a single receive and a single transmit buffer,
105  * and use struct ifuba to store all of the unibus information.
106  */
107 struct ifuba {
108 	struct	ifubinfo ifu_info;
109 	struct	ifrw ifu_r;
110 	struct	ifxmt ifu_xmt;
111 };
112 
113 #define	ifu_softc	ifu_info.iff_softc
114 #define	ifu_hlen	ifu_info.iff_hlen
115 #define	ifu_uba		ifu_info.iff_uba
116 #define	ifu_ubamr	ifu_info.iff_ubamr
117 #define	ifu_flags	ifu_info.iff_flags
118 #define	ifu_w		ifu_xmt.ifrw
119 #define	ifu_xtofree	ifu_xmt.ifw_xtofree
120 
121 #ifdef 	_KERNEL
122 #define	if_ubainit(ifuba, uban, size) \
123 		if_ubaminit(&(ifuba)->ifu_info, uban, size, \
124 			&(ifuba)->ifu_r, 1, &(ifuba)->ifu_xmt, 1)
125 #define	if_rubaget(ifu, ifp, len) \
126 		if_ubaget(&(ifu)->ifu_info, &(ifu)->ifu_r, ifp, len)
127 #define	if_wubaput(ifu, m) \
128 		if_ubaput(&(ifu)->ifu_info, &(ifu)->ifu_xmt, m)
129 #define if_wubaend(ifu) \
130 		if_ubaend(&(ifu)->ifu_info, &(ifu)->ifu_xmt)
131 
132 /* Prototypes */
133 int if_ubaminit(struct ifubinfo *, struct uba_softc *, int,
134 	    struct ifrw *, int, struct ifxmt *, int);
135 int if_ubaput(struct ifubinfo *, struct ifxmt *, struct mbuf *);
136 struct mbuf *if_ubaget(struct ifubinfo *, struct ifrw *, struct ifnet *, int);
137 void if_ubaend(struct ifubinfo *ifu, struct ifxmt *);
138 #endif
139