1 /* $NetBSD: gemini_gmacvar.h,v 1.2 2008/12/15 04:44:27 matt Exp $ */
3 * Copyright (c) 2008 The NetBSD Foundation, Inc.
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Matt Thomas <matt@3am-software.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #ifndef _ARM_GEMINI_GEMINI_GMACVAR_H
32 #define _ARM_GEMINI_GEMINI_GMACVAR_H
34 #include <sys/device.h>
35 #include <sys/queue.h>
37 #include <net/if_media.h>
38 #include <dev/mii/mii.h>
39 #include <dev/mii/miivar.h>
41 #include <arm/gemini/gemini_gmacreg.h>
43 typedef struct gmac_hwqueue gmac_hwqueue_t
;
44 typedef struct gmac_hwqmem gmac_hwqmem_t
;
45 typedef struct gmac_mapcache gmac_mapcache_t
;
47 #define MAX_TXMAPS 256
49 #define MAX_RXMAPS 128
52 #define RXQ_NDESCS 256
53 #define TXQ_NDESCS 128
55 struct gmac_mapcache
{
56 bus_dma_tag_t mc_dmat
;
57 bus_size_t mc_mapsize
;
62 bus_dmamap_t mc_maps
[0];
67 bus_space_tag_t sc_iot
;
68 bus_space_handle_t sc_ioh
;
69 bus_dma_tag_t sc_dmat
;
77 uint8_t sc_gpio_mdclk
;
79 uint8_t sc_gpio_mdout
;
82 * What GMAC ports have attached?
88 * The hardware free queue and software free queue are shared
89 * resources. As are the dmamap caches.
91 gmac_hwqueue_t
*sc_swfreeq
;
92 gmac_hwqueue_t
*sc_hwfreeq
;
93 gmac_mapcache_t
*sc_rxmaps
;
94 gmac_mapcache_t
*sc_txmaps
;
95 size_t sc_swfree_min
; /* min mbufs to keep on swfreeq */
96 size_t sc_rxpkts_per_sec
;
99 * What interrupts are enabled for both ports?
101 uint32_t sc_int_enabled
[5];
102 uint32_t sc_int_select
[5];
105 struct gmac_attach_args
{
106 bus_space_tag_t gma_iot
;
107 bus_space_handle_t gma_ioh
;
108 bus_dma_tag_t gma_dmat
;
114 mii_readreg_t gma_mii_readreg
;
115 mii_writereg_t gma_mii_writereg
;
119 bus_dma_tag_t hqm_dmat
;
120 bus_dmamap_t hqm_dmamap
;
121 gmac_mapcache_t
*hqm_mc
;
122 gmac_desc_t
*hqm_base
;
123 bus_size_t hqm_memsize
;
124 bus_dma_segment_t hqm_segs
[1];
130 #define HQM_TX 0x0001
131 #define HQM_RX 0x0000
132 #define HQM_PRODUCER 0x0002
133 #define HQM_CONSUMER 0x0000
136 struct gmac_hwqueue
{
137 gmac_desc_t
*hwq_base
;
138 gmac_hwqmem_t
*hwq_hqm
;
140 SLIST_ENTRY(gmac_hwqueue
) qun_link
;
141 SLIST_HEAD(,gmac_hwqueue
) qun_producers
;
142 struct gmac_hwqueue
*qun_producer
;
144 #define hwq_link hwq_qun.qun_link
145 #define hwq_producers hwq_qun.qun_producers
146 #define hwq_producer hwq_qun.qun_producer
147 struct ifnet
*hwq_ifp
;
148 struct ifqueue hwq_ifq
;
149 struct mbuf
*hwq_rxmbuf
;
150 struct mbuf
**hwq_mp
;
151 bus_space_tag_t hwq_iot
;
152 bus_space_handle_t hwq_qrwptr_ioh
;
154 * These are in units of gmac_desc_t, not bytes.
156 size_t hwq_qoff
; /* offset in descriptors to start */
157 uint16_t hwq_wptr
; /* next descriptor to write */
158 uint16_t hwq_rptr
; /* next descriptor to read */
159 uint16_t hwq_free
; /* descriptors can be produced */
160 uint16_t hwq_size
; /* total number of descriptors */
166 gmac_hwqmem_create(gmac_mapcache_t
*, size_t, size_t, int);
167 void gmac_hwqmem_destroy(gmac_hwqmem_t
*);
169 void gmac_hwqueue_destroy(gmac_hwqueue_t
*);
171 gmac_hwqueue_create(gmac_hwqmem_t
*, bus_space_tag_t
,
172 bus_space_handle_t
, bus_size_t
, bus_size_t
, size_t);
175 gmac_hwqueue_desc(gmac_hwqueue_t
*, size_t);
176 void gmac_hwqueue_sync(gmac_hwqueue_t
*);
177 size_t gmac_hwqueue_consume(gmac_hwqueue_t
*, size_t);
178 void gmac_hwqueue_produce(gmac_hwqueue_t
*, size_t);
181 gmac_mapcache_create(bus_dma_tag_t
, size_t, bus_size_t
, int);
182 void gmac_mapcache_destroy(gmac_mapcache_t
**);
183 int gmac_mapcache_fill(gmac_mapcache_t
*, size_t);
185 gmac_mapcache_get(gmac_mapcache_t
*);
186 void gmac_mapcache_put(gmac_mapcache_t
*, bus_dmamap_t
);
188 size_t gmac_rxproduce(gmac_hwqueue_t
*, size_t);
189 void gmac_swfree_min_update(struct gmac_softc
*);
190 void gmac_intr_update(struct gmac_softc
*);
193 #endif /* _ARM_GEMINI_GEMINI_GMACVAR_H */