Initial import of binutils 2.22 on the new vendor branch
[dragonfly.git] / sys / dev / netif / stge / if_stgevar.h
1 /*      $NetBSD: if_stgereg.h,v 1.3 2003/02/10 21:10:07 christos Exp $  */
2 /*      $FreeBSD: src/sys/dev/stge/if_stgereg.h,v 1.1 2006/07/25 00:37:09 yongari Exp $ */
3 /*      $DragonFly: src/sys/dev/netif/stge/if_stgevar.h,v 1.1 2006/11/16 13:43:55 sephe Exp $   */
4
5 /*-
6  * Copyright (c) 2001 The NetBSD Foundation, Inc.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to The NetBSD Foundation
10  * by Jason R. Thorpe.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *      This product includes software developed by the NetBSD
23  *      Foundation, Inc. and its contributors.
24  * 4. Neither the name of The NetBSD Foundation nor the names of its
25  *    contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40
41 /*
42  * Transmit descriptor list size.
43  */
44 #define STGE_TX_RING_CNT        256
45 #define STGE_TX_LOWAT           (STGE_TX_RING_CNT/32)
46 #define STGE_TX_HIWAT           (STGE_TX_RING_CNT - STGE_TX_LOWAT)
47
48 /*
49  * Receive descriptor list size.
50  */
51 #define STGE_RX_RING_CNT        256
52
53 #define STGE_MAXTXSEGS          STGE_NTXFRAGS
54 #define STGE_MAXSGSIZE          PAGE_SIZE
55
56 #define STGE_JUMBO_FRAMELEN     9022
57 #define STGE_JUMBO_MTU  \
58         (STGE_JUMBO_FRAMELEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
59
60 struct stge_txdesc {
61         struct mbuf *tx_m;              /* head of our mbuf chain */
62         bus_dmamap_t tx_dmamap;         /* our DMA map */
63         STAILQ_ENTRY(stge_txdesc) tx_q;
64 };
65
66 STAILQ_HEAD(stge_txdq, stge_txdesc);
67
68 struct stge_rxdesc {
69         struct mbuf *rx_m;
70         bus_dmamap_t rx_dmamap;
71 };
72
73 #define STGE_ADDR_LO(x)         ((u_int64_t) (x) & 0xffffffff)
74 #define STGE_ADDR_HI(x)         ((u_int64_t) (x) >> 32)
75
76 #define STGE_RING_ALIGN         8
77
78 struct stge_chain_data{
79         bus_dma_tag_t           stge_parent_tag;
80         bus_dma_tag_t           stge_tx_tag;
81         struct stge_txdesc      stge_txdesc[STGE_TX_RING_CNT];
82         struct stge_txdq        stge_txfreeq;
83         struct stge_txdq        stge_txbusyq;
84         bus_dma_tag_t           stge_rx_tag;
85         struct stge_rxdesc      stge_rxdesc[STGE_RX_RING_CNT];
86         bus_dma_tag_t           stge_tx_ring_tag;
87         bus_dmamap_t            stge_tx_ring_map;
88         bus_dma_tag_t           stge_rx_ring_tag;
89         bus_dmamap_t            stge_rx_ring_map;
90         bus_dmamap_t            stge_rx_sparemap;
91
92         int                     stge_tx_prod;
93         int                     stge_tx_cons;
94         int                     stge_tx_cnt;
95         int                     stge_rx_cons;
96 #ifdef DEVICE_POLLING
97         int                     stge_rxcycles;
98 #endif
99         int                     stge_rxlen;
100         struct mbuf             *stge_rxhead;
101         struct mbuf             *stge_rxtail;
102 };
103
104 struct stge_ring_data {
105         struct stge_tfd         *stge_tx_ring;
106         bus_addr_t              stge_tx_ring_paddr;
107         struct stge_rfd         *stge_rx_ring;
108         bus_addr_t              stge_rx_ring_paddr;
109 };
110
111 #define STGE_TX_RING_ADDR(sc, i)        \
112     ((sc)->sc_rdata.stge_tx_ring_paddr + sizeof(struct stge_tfd) * (i))
113 #define STGE_RX_RING_ADDR(sc, i)        \
114     ((sc)->sc_rdata.stge_rx_ring_paddr + sizeof(struct stge_rfd) * (i))
115
116 #define STGE_TX_RING_SZ         \
117     (sizeof(struct stge_tfd) * STGE_TX_RING_CNT)
118 #define STGE_RX_RING_SZ         \
119     (sizeof(struct stge_rfd) * STGE_RX_RING_CNT)
120
121 /*
122  * Software state per device.
123  */
124 struct stge_softc {
125         struct arpcom           arpcom;
126         device_t                sc_dev;
127         device_t                sc_miibus;
128
129         bus_space_handle_t      sc_bhandle;     /* bus space handle */
130         bus_space_tag_t         sc_btag;        /* bus space tag */
131         int                     sc_res_rid;
132         int                     sc_res_type;
133         struct resource         *sc_res;
134
135         int                     sc_irq_rid;
136         struct resource         *sc_irq;
137         void                    *sc_ih;         /* interrupt cookie */
138
139         int                     sc_rev;         /* silicon revision */
140
141         struct callout          sc_tick_ch;     /* tick callout */
142
143         struct stge_chain_data  sc_cdata;
144         struct stge_ring_data   sc_rdata;
145         int                     sc_if_flags;
146         int                     sc_if_framesize;
147         int                     sc_txthresh;    /* Tx threshold */
148         uint32_t                sc_usefiber:1;  /* if we're fiber */
149         uint32_t                sc_stge1023:1;  /* are we a 1023 */
150         uint32_t                sc_DMACtrl;     /* prototype DMACtrl reg. */
151         uint32_t                sc_MACCtrl;     /* prototype MacCtrl reg. */
152         uint16_t                sc_IntEnable;   /* prototype IntEnable reg. */
153         uint16_t                sc_led;         /* LED conf. from EEPROM */
154         uint8_t                 sc_PhyCtrl;     /* prototype PhyCtrl reg. */
155         int                     sc_suspended;
156         int                     sc_detach;
157
158         struct sysctl_ctx_list  sc_sysctl_ctx;
159         struct sysctl_oid       *sc_sysctl_tree;
160         int                     sc_rxint_nframe;
161         int                     sc_rxint_dmawait;
162         int                     sc_nerr;
163 };
164
165 #define STGE_MAXERR     5
166
167 #define STGE_RXCHAIN_RESET(_sc)                                         \
168 do {                                                                    \
169         (_sc)->sc_cdata.stge_rxhead = NULL;                             \
170         (_sc)->sc_cdata.stge_rxtail = NULL;                             \
171         (_sc)->sc_cdata.stge_rxlen = 0;                                 \
172 } while (/*CONSTCOND*/0)
173
174 #define STGE_TIMEOUT 1000
175
176 struct stge_mii_frame {
177         uint8_t mii_stdelim;
178         uint8_t mii_opcode;
179         uint8_t mii_phyaddr;
180         uint8_t mii_regaddr;
181         uint8_t mii_turnaround;
182         uint16_t mii_data;
183 };