dwc_gmac_var.h revision 1.1 1 /*-
2 * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Matt Thomas of 3am Software Foundry and Martin Husemann.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30
31 /*
32 * We could use 1024 DMA descriptors to fill up an 8k page (each is 16 byte).
33 * However, on TX we probably will not need that many, and on RX we allocate
34 * a full mbuf cluster for each, so secondary memory consumption will grow
35 * rapidly.
36 * So currently we waste half a page of dma memory and consume 512k Byte of
37 * RAM for mbuf clusters.
38 * XXX Maybe fine-tune later, or reconsider unsharing of RX/TX dmamap.
39 */
40 #define AWGE_RX_RING_COUNT 256
41 #define AWGE_TX_RING_COUNT 256
42 #define AWGE_TOTAL_RING_COUNT \
43 (AWGE_RX_RING_COUNT + AWGE_TX_RING_COUNT)
44
45 #define AWGE_MAX_PACKET (ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN)
46
47
48
49 struct dwc_gmac_rx_data {
50 bus_dmamap_t rd_map;
51 struct mbuf *rd_m;
52 };
53
54 struct dwc_gmac_tx_data {
55 bus_dmamap_t td_map;
56 bus_dmamap_t td_active;
57 struct mbuf *td_m;
58 };
59
60 struct dwc_gmac_tx_ring {
61 bus_addr_t t_physaddr; /* PA of TX ring start */
62 struct dwc_gmac_dev_dmadesc *t_desc; /* VA of TX ring start */
63 struct dwc_gmac_tx_data t_data[AWGE_TX_RING_COUNT];
64 int t_cur, t_next, t_queued;
65 };
66
67 struct dwc_gmac_rx_ring {
68 bus_addr_t r_physaddr; /* PA of RX ring start */
69 struct dwc_gmac_dev_dmadesc *r_desc; /* VA of RX ring start */
70 struct dwc_gmac_rx_data r_data[AWGE_RX_RING_COUNT];
71 int r_cur, r_next;
72 kmutex_t r_mtx;
73 };
74
75 struct dwc_gmac_softc {
76 device_t sc_dev;
77 bus_space_tag_t sc_bst;
78 bus_space_handle_t sc_bsh;
79 bus_dma_tag_t sc_dmat;
80 struct ethercom sc_ec;
81 struct mii_data sc_mii;
82 kmutex_t sc_mdio_lock;
83 bus_dmamap_t sc_dma_ring_map; /* common dma memory for RX */
84 bus_dma_segment_t sc_dma_ring_seg; /* and TX ring */
85 struct dwc_gmac_rx_ring sc_rxq;
86 struct dwc_gmac_tx_ring sc_txq;
87 };
88
89 void dwc_gmac_attach(struct dwc_gmac_softc*, uint8_t*);
90 int dwc_gmac_intr(struct dwc_gmac_softc*);
91