gemini_gmacvar.h revision 1.3.2.2 1 1.3.2.2 mjf /* $NetBSD: gemini_gmacvar.h,v 1.3.2.2 2009/01/17 13:27:52 mjf Exp $ */
2 1.3.2.2 mjf /*-
3 1.3.2.2 mjf * Copyright (c) 2008 The NetBSD Foundation, Inc.
4 1.3.2.2 mjf * All rights reserved.
5 1.3.2.2 mjf *
6 1.3.2.2 mjf * This code is derived from software contributed to The NetBSD Foundation
7 1.3.2.2 mjf * by Matt Thomas <matt (at) 3am-software.com>
8 1.3.2.2 mjf *
9 1.3.2.2 mjf * Redistribution and use in source and binary forms, with or without
10 1.3.2.2 mjf * modification, are permitted provided that the following conditions
11 1.3.2.2 mjf * are met:
12 1.3.2.2 mjf * 1. Redistributions of source code must retain the above copyright
13 1.3.2.2 mjf * notice, this list of conditions and the following disclaimer.
14 1.3.2.2 mjf * 2. Redistributions in binary form must reproduce the above copyright
15 1.3.2.2 mjf * notice, this list of conditions and the following disclaimer in the
16 1.3.2.2 mjf * documentation and/or other materials provided with the distribution.
17 1.3.2.2 mjf *
18 1.3.2.2 mjf * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 1.3.2.2 mjf * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.3.2.2 mjf * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.3.2.2 mjf * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 1.3.2.2 mjf * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.3.2.2 mjf * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.3.2.2 mjf * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.3.2.2 mjf * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.3.2.2 mjf * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.3.2.2 mjf * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.3.2.2 mjf * POSSIBILITY OF SUCH DAMAGE.
29 1.3.2.2 mjf */
30 1.3.2.2 mjf
31 1.3.2.2 mjf #ifndef _ARM_GEMINI_GEMINI_GMACVAR_H
32 1.3.2.2 mjf #define _ARM_GEMINI_GEMINI_GMACVAR_H
33 1.3.2.2 mjf
34 1.3.2.2 mjf #include <sys/device.h>
35 1.3.2.2 mjf #include <sys/queue.h>
36 1.3.2.2 mjf #include <net/if.h>
37 1.3.2.2 mjf #include <net/if_media.h>
38 1.3.2.2 mjf #include <dev/mii/mii.h>
39 1.3.2.2 mjf #include <dev/mii/miivar.h>
40 1.3.2.2 mjf
41 1.3.2.2 mjf #include <arm/gemini/gemini_gmacreg.h>
42 1.3.2.2 mjf
43 1.3.2.2 mjf typedef struct gmac_hwqueue gmac_hwqueue_t;
44 1.3.2.2 mjf typedef struct gmac_hwqmem gmac_hwqmem_t;
45 1.3.2.2 mjf typedef struct gmac_mapcache gmac_mapcache_t;
46 1.3.2.2 mjf
47 1.3.2.2 mjf #define MAX_TXMAPS 256
48 1.3.2.2 mjf #define MIN_TXMAPS 16
49 1.3.2.2 mjf #define MAX_RXMAPS 128
50 1.3.2.2 mjf #define MIN_RXMAPS 8
51 1.3.2.2 mjf
52 1.3.2.2 mjf #define RXQ_NDESCS 256
53 1.3.2.2 mjf #define TXQ_NDESCS 128
54 1.3.2.2 mjf
55 1.3.2.2 mjf struct gmac_mapcache {
56 1.3.2.2 mjf bus_dma_tag_t mc_dmat;
57 1.3.2.2 mjf bus_size_t mc_mapsize;
58 1.3.2.2 mjf size_t mc_nsegs;
59 1.3.2.2 mjf size_t mc_free;
60 1.3.2.2 mjf size_t mc_used;
61 1.3.2.2 mjf size_t mc_max;
62 1.3.2.2 mjf bus_dmamap_t mc_maps[0];
63 1.3.2.2 mjf };
64 1.3.2.2 mjf
65 1.3.2.2 mjf struct gmac_softc {
66 1.3.2.2 mjf device_t sc_dev;
67 1.3.2.2 mjf bus_space_tag_t sc_iot;
68 1.3.2.2 mjf bus_space_handle_t sc_ioh;
69 1.3.2.2 mjf bus_dma_tag_t sc_dmat;
70 1.3.2.2 mjf
71 1.3.2.2 mjf /*
72 1.3.2.2 mjf * MDIO state
73 1.3.2.2 mjf */
74 1.3.2.2 mjf kmutex_t sc_mdiolock;
75 1.3.2.2 mjf uint32_t sc_mdiobits;
76 1.3.2.2 mjf device_t sc_gpio_dev;
77 1.3.2.2 mjf uint8_t sc_gpio_mdclk;
78 1.3.2.2 mjf uint8_t sc_gpio_mdin;
79 1.3.2.2 mjf uint8_t sc_gpio_mdout;
80 1.3.2.2 mjf
81 1.3.2.2 mjf /*
82 1.3.2.2 mjf * What GMAC ports have attached?
83 1.3.2.2 mjf */
84 1.3.2.2 mjf uint8_t sc_ports;
85 1.3.2.2 mjf uint8_t sc_running;
86 1.3.2.2 mjf
87 1.3.2.2 mjf /*
88 1.3.2.2 mjf * The hardware free queue and software free queue are shared
89 1.3.2.2 mjf * resources. As are the dmamap caches.
90 1.3.2.2 mjf */
91 1.3.2.2 mjf gmac_hwqueue_t *sc_swfreeq;
92 1.3.2.2 mjf gmac_hwqueue_t *sc_hwfreeq;
93 1.3.2.2 mjf gmac_mapcache_t *sc_rxmaps;
94 1.3.2.2 mjf gmac_mapcache_t *sc_txmaps;
95 1.3.2.2 mjf size_t sc_swfree_min; /* min mbufs to keep on swfreeq */
96 1.3.2.2 mjf size_t sc_rxpkts_per_sec;
97 1.3.2.2 mjf
98 1.3.2.2 mjf /*
99 1.3.2.2 mjf * What interrupts are enabled for both ports?
100 1.3.2.2 mjf */
101 1.3.2.2 mjf uint32_t sc_int_enabled[5];
102 1.3.2.2 mjf uint32_t sc_int_select[5];
103 1.3.2.2 mjf };
104 1.3.2.2 mjf
105 1.3.2.2 mjf struct gmac_attach_args {
106 1.3.2.2 mjf bus_space_tag_t gma_iot;
107 1.3.2.2 mjf bus_space_handle_t gma_ioh;
108 1.3.2.2 mjf bus_dma_tag_t gma_dmat;
109 1.3.2.2 mjf
110 1.3.2.2 mjf int gma_port;
111 1.3.2.2 mjf int gma_phy;
112 1.3.2.2 mjf int gma_intr;
113 1.3.2.2 mjf
114 1.3.2.2 mjf mii_readreg_t gma_mii_readreg;
115 1.3.2.2 mjf mii_writereg_t gma_mii_writereg;
116 1.3.2.2 mjf };
117 1.3.2.2 mjf
118 1.3.2.2 mjf struct gmac_hwqmem {
119 1.3.2.2 mjf bus_dma_tag_t hqm_dmat;
120 1.3.2.2 mjf bus_dmamap_t hqm_dmamap;
121 1.3.2.2 mjf gmac_mapcache_t *hqm_mc;
122 1.3.2.2 mjf gmac_desc_t *hqm_base;
123 1.3.2.2 mjf bus_size_t hqm_memsize;
124 1.3.2.2 mjf bus_dma_segment_t hqm_segs[1];
125 1.3.2.2 mjf size_t hqm_ndesc;
126 1.3.2.2 mjf size_t hqm_nqueue;
127 1.3.2.2 mjf int hqm_nsegs;
128 1.3.2.2 mjf uint8_t hqm_refs;
129 1.3.2.2 mjf uint8_t hqm_flags;
130 1.3.2.2 mjf #define HQM_TX 0x0001
131 1.3.2.2 mjf #define HQM_RX 0x0000
132 1.3.2.2 mjf #define HQM_PRODUCER 0x0002
133 1.3.2.2 mjf #define HQM_CONSUMER 0x0000
134 1.3.2.2 mjf };
135 1.3.2.2 mjf
136 1.3.2.2 mjf struct gmac_hwqueue {
137 1.3.2.2 mjf gmac_desc_t *hwq_base;
138 1.3.2.2 mjf gmac_hwqmem_t *hwq_hqm;
139 1.3.2.2 mjf union {
140 1.3.2.2 mjf SLIST_ENTRY(gmac_hwqueue) qun_link;
141 1.3.2.2 mjf SLIST_HEAD(,gmac_hwqueue) qun_producers;
142 1.3.2.2 mjf struct gmac_hwqueue *qun_producer;
143 1.3.2.2 mjf } hwq_qun;
144 1.3.2.2 mjf #define hwq_link hwq_qun.qun_link
145 1.3.2.2 mjf #define hwq_producers hwq_qun.qun_producers
146 1.3.2.2 mjf #define hwq_producer hwq_qun.qun_producer
147 1.3.2.2 mjf struct ifnet *hwq_ifp;
148 1.3.2.2 mjf struct ifqueue hwq_ifq;
149 1.3.2.2 mjf struct mbuf *hwq_rxmbuf;
150 1.3.2.2 mjf struct mbuf **hwq_mp;
151 1.3.2.2 mjf bus_space_tag_t hwq_iot;
152 1.3.2.2 mjf bus_space_handle_t hwq_qrwptr_ioh;
153 1.3.2.2 mjf /*
154 1.3.2.2 mjf * These are in units of gmac_desc_t, not bytes.
155 1.3.2.2 mjf */
156 1.3.2.2 mjf size_t hwq_qoff; /* offset in descriptors to start */
157 1.3.2.2 mjf uint16_t hwq_wptr; /* next descriptor to write */
158 1.3.2.2 mjf uint16_t hwq_rptr; /* next descriptor to read */
159 1.3.2.2 mjf uint16_t hwq_free; /* descriptors can be produced */
160 1.3.2.2 mjf uint16_t hwq_size; /* total number of descriptors */
161 1.3.2.2 mjf uint8_t hwq_ref;
162 1.3.2.2 mjf };
163 1.3.2.2 mjf
164 1.3.2.2 mjf #ifdef _KERNEL
165 1.3.2.2 mjf gmac_hwqmem_t *
166 1.3.2.2 mjf gmac_hwqmem_create(gmac_mapcache_t *, size_t, size_t, int);
167 1.3.2.2 mjf void gmac_hwqmem_destroy(gmac_hwqmem_t *);
168 1.3.2.2 mjf
169 1.3.2.2 mjf void gmac_hwqueue_destroy(gmac_hwqueue_t *);
170 1.3.2.2 mjf gmac_hwqueue_t *
171 1.3.2.2 mjf gmac_hwqueue_create(gmac_hwqmem_t *, bus_space_tag_t,
172 1.3.2.2 mjf bus_space_handle_t, bus_size_t, bus_size_t, size_t);
173 1.3.2.2 mjf
174 1.3.2.2 mjf gmac_desc_t *
175 1.3.2.2 mjf gmac_hwqueue_desc(gmac_hwqueue_t *, size_t);
176 1.3.2.2 mjf void gmac_hwqueue_sync(gmac_hwqueue_t *);
177 1.3.2.2 mjf size_t gmac_hwqueue_consume(gmac_hwqueue_t *, size_t);
178 1.3.2.2 mjf void gmac_hwqueue_produce(gmac_hwqueue_t *, size_t);
179 1.3.2.2 mjf
180 1.3.2.2 mjf gmac_mapcache_t *
181 1.3.2.2 mjf gmac_mapcache_create(bus_dma_tag_t, size_t, bus_size_t, int);
182 1.3.2.2 mjf void gmac_mapcache_destroy(gmac_mapcache_t **);
183 1.3.2.2 mjf int gmac_mapcache_fill(gmac_mapcache_t *, size_t);
184 1.3.2.2 mjf bus_dmamap_t
185 1.3.2.2 mjf gmac_mapcache_get(gmac_mapcache_t *);
186 1.3.2.2 mjf void gmac_mapcache_put(gmac_mapcache_t *, bus_dmamap_t);
187 1.3.2.2 mjf
188 1.3.2.2 mjf size_t gmac_rxproduce(gmac_hwqueue_t *, size_t);
189 1.3.2.2 mjf void gmac_swfree_min_update(struct gmac_softc *);
190 1.3.2.2 mjf void gmac_intr_update(struct gmac_softc *);
191 1.3.2.2 mjf #endif
192 1.3.2.2 mjf
193 1.3.2.2 mjf #endif /* _ARM_GEMINI_GEMINI_GMACVAR_H */
194