sqvar.h revision 1.2.8.2 1 1.2.8.2 nathanw /* $NetBSD: sqvar.h,v 1.2.8.2 2002/04/01 07:42:25 nathanw Exp $ */
2 1.2.8.2 nathanw
3 1.2.8.2 nathanw /*
4 1.2.8.2 nathanw * Copyright (c) 2001 Rafal K. Boni
5 1.2.8.2 nathanw * All rights reserved.
6 1.2.8.2 nathanw *
7 1.2.8.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.2.8.2 nathanw * modification, are permitted provided that the following conditions
9 1.2.8.2 nathanw * are met:
10 1.2.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.2.8.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.2.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.2.8.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.2.8.2 nathanw * 3. The name of the author may not be used to endorse or promote products
16 1.2.8.2 nathanw * derived from this software without specific prior written permission.
17 1.2.8.2 nathanw *
18 1.2.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.2.8.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.2.8.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.2.8.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.2.8.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.2.8.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.2.8.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.2.8.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.2.8.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.2.8.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.2.8.2 nathanw */
29 1.2.8.2 nathanw
30 1.2.8.2 nathanw #ifndef _ARCH_SGIMIPS_HPC_SQVAR_H_
31 1.2.8.2 nathanw #define _ARCH_SGIMIPS_HPC_SQVAR_H_
32 1.2.8.2 nathanw
33 1.2.8.2 nathanw #include "rnd.h"
34 1.2.8.2 nathanw
35 1.2.8.2 nathanw #include <sys/queue.h>
36 1.2.8.2 nathanw #include <sys/callout.h>
37 1.2.8.2 nathanw
38 1.2.8.2 nathanw #if NRND > 0
39 1.2.8.2 nathanw #include <sys/rnd.h>
40 1.2.8.2 nathanw #endif
41 1.2.8.2 nathanw
42 1.2.8.2 nathanw #include <sgimips/hpc/hpcvar.h>
43 1.2.8.2 nathanw #include <sgimips/hpc/hpcreg.h>
44 1.2.8.2 nathanw
45 1.2.8.2 nathanw /* Note, these must be powers of two for the magic NEXT/PREV macros to work */
46 1.2.8.2 nathanw #define SQ_NRXDESC 32
47 1.2.8.2 nathanw #define SQ_NTXDESC 16
48 1.2.8.2 nathanw
49 1.2.8.2 nathanw #define SQ_NRXDESC_MASK (SQ_NRXDESC - 1)
50 1.2.8.2 nathanw #define SQ_NEXTRX(x) ((x + 1) & SQ_NRXDESC_MASK)
51 1.2.8.2 nathanw #define SQ_PREVRX(x) ((x - 1) & SQ_NRXDESC_MASK)
52 1.2.8.2 nathanw
53 1.2.8.2 nathanw #define SQ_NTXDESC_MASK (SQ_NTXDESC - 1)
54 1.2.8.2 nathanw #define SQ_NEXTTX(x) ((x + 1) & SQ_NTXDESC_MASK)
55 1.2.8.2 nathanw #define SQ_PREVTX(x) ((x - 1) & SQ_NTXDESC_MASK)
56 1.2.8.2 nathanw
57 1.2.8.2 nathanw /*
58 1.2.8.2 nathanw * We pack all DMA control structures into one container so we can alloc just
59 1.2.8.2 nathanw * one chunk of DMA-safe memory and pack them into it. Otherwise, we'd have to
60 1.2.8.2 nathanw * allocate a page for each descriptor, since the bus_dmamem_alloc() interface
61 1.2.8.2 nathanw * does not allow us to allocate smaller chunks.
62 1.2.8.2 nathanw */
63 1.2.8.2 nathanw struct sq_control {
64 1.2.8.2 nathanw /* Receive descriptors */
65 1.2.8.2 nathanw struct hpc_dma_desc rx_desc[SQ_NRXDESC];
66 1.2.8.2 nathanw
67 1.2.8.2 nathanw /* Transmit descriptors */
68 1.2.8.2 nathanw struct hpc_dma_desc tx_desc[SQ_NTXDESC];
69 1.2.8.2 nathanw };
70 1.2.8.2 nathanw
71 1.2.8.2 nathanw #define SQ_CDOFF(x) offsetof(struct sq_control, x)
72 1.2.8.2 nathanw #define SQ_CDTXOFF(x) SQ_CDOFF(tx_desc[(x)])
73 1.2.8.2 nathanw #define SQ_CDRXOFF(x) SQ_CDOFF(rx_desc[(x)])
74 1.2.8.2 nathanw
75 1.2.8.2 nathanw #define SQ_TYPE_8003 0
76 1.2.8.2 nathanw #define SQ_TYPE_80C03 1
77 1.2.8.2 nathanw
78 1.2.8.2 nathanw struct sq_softc {
79 1.2.8.2 nathanw struct device sc_dev;
80 1.2.8.2 nathanw
81 1.2.8.2 nathanw /* HPC registers */
82 1.2.8.2 nathanw bus_space_tag_t sc_hpct;
83 1.2.8.2 nathanw bus_space_handle_t sc_hpch;
84 1.2.8.2 nathanw
85 1.2.8.2 nathanw
86 1.2.8.2 nathanw /* HPC external ethernet registers: aka Seeq 8003 registers */
87 1.2.8.2 nathanw bus_space_tag_t sc_regt;
88 1.2.8.2 nathanw bus_space_handle_t sc_regh;
89 1.2.8.2 nathanw
90 1.2.8.2 nathanw bus_dma_tag_t sc_dmat;
91 1.2.8.2 nathanw
92 1.2.8.2 nathanw struct ethercom sc_ethercom;
93 1.2.8.2 nathanw unsigned char sc_enaddr[ETHER_ADDR_LEN];
94 1.2.8.2 nathanw
95 1.2.8.2 nathanw int sc_type;
96 1.2.8.2 nathanw
97 1.2.8.2 nathanw struct sq_control* sc_control;
98 1.2.8.2 nathanw #define sc_rxdesc sc_control->rx_desc
99 1.2.8.2 nathanw #define sc_txdesc sc_control->tx_desc
100 1.2.8.2 nathanw
101 1.2.8.2 nathanw /* DMA structures for control data (DMA RX/TX descriptors) */
102 1.2.8.2 nathanw int sc_ncdseg;
103 1.2.8.2 nathanw bus_dma_segment_t sc_cdseg;
104 1.2.8.2 nathanw bus_dmamap_t sc_cdmap;
105 1.2.8.2 nathanw #define sc_cddma sc_cdmap->dm_segs[0].ds_addr
106 1.2.8.2 nathanw
107 1.2.8.2 nathanw int sc_nextrx;
108 1.2.8.2 nathanw
109 1.2.8.2 nathanw /* DMA structures for RX packet data */
110 1.2.8.2 nathanw bus_dma_segment_t sc_rxseg[SQ_NRXDESC];
111 1.2.8.2 nathanw bus_dmamap_t sc_rxmap[SQ_NRXDESC];
112 1.2.8.2 nathanw struct mbuf* sc_rxmbuf[SQ_NRXDESC];
113 1.2.8.2 nathanw
114 1.2.8.2 nathanw int sc_nexttx;
115 1.2.8.2 nathanw int sc_prevtx;
116 1.2.8.2 nathanw int sc_nfreetx;
117 1.2.8.2 nathanw
118 1.2.8.2 nathanw /* DMA structures for TX packet data */
119 1.2.8.2 nathanw bus_dma_segment_t sc_txseg[SQ_NTXDESC];
120 1.2.8.2 nathanw bus_dmamap_t sc_txmap[SQ_NTXDESC];
121 1.2.8.2 nathanw struct mbuf* sc_txmbuf[SQ_NTXDESC];
122 1.2.8.2 nathanw
123 1.2.8.2 nathanw u_int8_t sc_rxcmd; /* prototype rxcmd */
124 1.2.8.2 nathanw
125 1.2.8.2 nathanw #if NRND > 0
126 1.2.8.2 nathanw rndsource_element_t rnd_source; /* random source */
127 1.2.8.2 nathanw #endif
128 1.2.8.2 nathanw };
129 1.2.8.2 nathanw
130 1.2.8.2 nathanw #define SQ_CDTXADDR(sc, x) ((sc)->sc_cddma + SQ_CDTXOFF((x)))
131 1.2.8.2 nathanw #define SQ_CDRXADDR(sc, x) ((sc)->sc_cddma + SQ_CDRXOFF((x)))
132 1.2.8.2 nathanw
133 1.2.8.2 nathanw #define SQ_CDTXSYNC(sc, x, n, ops) \
134 1.2.8.2 nathanw do { \
135 1.2.8.2 nathanw int __x, __n; \
136 1.2.8.2 nathanw \
137 1.2.8.2 nathanw __x = (x); \
138 1.2.8.2 nathanw __n = (n); \
139 1.2.8.2 nathanw \
140 1.2.8.2 nathanw /* If it will wrap around, sync to the end of the ring. */ \
141 1.2.8.2 nathanw if ((__x + __n) > SQ_NTXDESC) { \
142 1.2.8.2 nathanw bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cdmap, \
143 1.2.8.2 nathanw SQ_CDTXOFF(__x), sizeof(struct hpc_dma_desc) * \
144 1.2.8.2 nathanw (SQ_NTXDESC - __x), (ops)); \
145 1.2.8.2 nathanw __n -= (SQ_NTXDESC - __x); \
146 1.2.8.2 nathanw __x = 0; \
147 1.2.8.2 nathanw } \
148 1.2.8.2 nathanw \
149 1.2.8.2 nathanw /* Now sync whatever is left. */ \
150 1.2.8.2 nathanw bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cdmap, \
151 1.2.8.2 nathanw SQ_CDTXOFF(__x), sizeof(struct hpc_dma_desc) * __n, (ops)); \
152 1.2.8.2 nathanw } while (0)
153 1.2.8.2 nathanw
154 1.2.8.2 nathanw #define SQ_CDRXSYNC(sc, x, ops) \
155 1.2.8.2 nathanw bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cdmap, \
156 1.2.8.2 nathanw SQ_CDRXOFF((x)), sizeof(struct hpc_dma_desc), (ops))
157 1.2.8.2 nathanw
158 1.2.8.2 nathanw #define SQ_INIT_RXDESC(sc, x) \
159 1.2.8.2 nathanw do { \
160 1.2.8.2 nathanw struct hpc_dma_desc* __rxd = &(sc)->sc_rxdesc[(x)]; \
161 1.2.8.2 nathanw struct mbuf *__m = (sc)->sc_rxmbuf[(x)]; \
162 1.2.8.2 nathanw \
163 1.2.8.2 nathanw __m->m_data = __m->m_ext.ext_buf; \
164 1.2.8.2 nathanw __rxd->hdd_bufptr = (sc)->sc_rxmap[(x)]->dm_segs[0].ds_addr; \
165 1.2.8.2 nathanw __rxd->hdd_descptr = SQ_CDRXADDR((sc), SQ_NEXTRX((x))); \
166 1.2.8.2 nathanw __rxd->hdd_ctl = \
167 1.2.8.2 nathanw __m->m_ext.ext_size | HDD_CTL_INTR | HDD_CTL_EOPACKET | \
168 1.2.8.2 nathanw HDD_CTL_OWN | ((x) == (SQ_NRXDESC - 1) ? \
169 1.2.8.2 nathanw HDD_CTL_EOCHAIN : 0); \
170 1.2.8.2 nathanw SQ_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);\
171 1.2.8.2 nathanw } while (0)
172 1.2.8.2 nathanw
173 1.2.8.2 nathanw #endif /* _ARCH_SGIMIPS_HPC_SQVAR_H_ */
174