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