if_axereg.h revision 1.1 1 /* $NetBSD: if_axereg.h,v 1.1 2004/10/23 13:38:26 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1997, 1998, 1999, 2000-2003
5 * Bill Paul <wpaul (at) windriver.com>. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Bill Paul.
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 * $FreeBSD: src/sys/dev/usb/if_axereg.h,v 1.2 2003/06/15 21:45:43 wpaul Exp $
35 */
36
37 /*
38 * Definitions for the ASIX Electronics AX88172 to ethernet controller.
39 */
40
41
42 /*
43 * Vendor specific commands
44 * ASIX conveniently doesn't document the 'set NODEID' command in their
45 * datasheet (thanks a lot guys).
46 * To make handling these commands easier, I added some extra data
47 * which is decided by the axe_cmd() routine. Commands are encoded
48 * in 16 bites, with the format: LDCC. L and D are both nibbles in
49 * the high byte. L represents the data length (0 to 15) and D
50 * represents the direction (0 for vendor read, 1 for vendor write).
51 * CC is the command byte, as specified in the manual.
52 */
53
54 #define AXE_CMD_DIR(x) (((x) & 0x0F00) >> 8)
55 #define AXE_CMD_LEN(x) (((x) & 0xF000) >> 12)
56 #define AXE_CMD_CMD(x) ((x) & 0x00FF)
57
58 #define AXE_CMD_READ_RXTX_SRAM 0x2002
59 #define AXE_CMD_WRITE_RX_SRAM 0x0103
60 #define AXE_CMD_WRITE_TX_SRAM 0x0104
61 #define AXE_CMD_MII_OPMODE_SW 0x0106
62 #define AXE_CMD_MII_READ_REG 0x2007
63 #define AXE_CMD_MII_WRITE_REG 0x2108
64 #define AXE_CMD_MII_READ_OPMODE 0x1009
65 #define AXE_CMD_MII_OPMODE_HW 0x010A
66 #define AXE_CMD_SROM_READ 0x200B
67 #define AXE_CMD_SROM_WRITE 0x010C
68 #define AXE_CMD_SROM_WR_ENABLE 0x010D
69 #define AXE_CMD_SROM_WR_DISABLE 0x010E
70 #define AXE_CMD_RXCTL_READ 0x200F
71 #define AXE_CMD_RXCTL_WRITE 0x0110
72 #define AXE_CMD_READ_IPG012 0x3011
73 #define AXE_CMD_WRITE_IPG0 0x0112
74 #define AXE_CMD_WRITE_IPG1 0x0113
75 #define AXE_CMD_WRITE_IPG2 0x0114
76 #define AXE_CMD_READ_MCAST 0x8015
77 #define AXE_CMD_WRITE_MCAST 0x8116
78 #define AXE_CMD_READ_NODEID 0x6017
79 #define AXE_CMD_WRITE_NODEID 0x6118
80 #define AXE_CMD_READ_PHYID 0x2019
81 #define AXE_CMD_READ_MEDIA 0x101A
82 #define AXE_CMD_WRITE_MEDIA 0x011B
83 #define AXE_CMD_READ_MONITOR_MODE 0x101C
84 #define AXE_CMD_WRITE_MONITOR_MODE 0x011D
85 #define AXE_CMD_READ_GPIO 0x101E
86 #define AXE_CMD_WRITE_GPIO 0x011F
87
88 #define AXE_RXCMD_PROMISC 0x0001
89 #define AXE_RXCMD_ALLMULTI 0x0002
90 #define AXE_RXCMD_UNICAST 0x0004
91 #define AXE_RXCMD_BROADCAST 0x0008
92 #define AXE_RXCMD_MULTICAST 0x0010
93 #define AXE_RXCMD_ENABLE 0x0080
94
95 #define AXE_NOPHY 0xE0
96
97 #define AXE_TIMEOUT 1000
98 #define AXE_BUFSZ 1536
99 #define AXE_MIN_FRAMELEN 60
100 #define AXE_RX_FRAMES 1
101 #define AXE_TX_FRAMES 1
102
103 #define AXE_RX_LIST_CNT 1
104 #define AXE_TX_LIST_CNT 1
105
106 #define AXE_CTL_READ 0x01
107 #define AXE_CTL_WRITE 0x02
108
109 #define AXE_CONFIG_NO 1
110 #define AXE_IFACE_IDX 0
111
112 /*
113 * The interrupt endpoint is currently unused
114 * by the ASIX part.
115 */
116 #define AXE_ENDPT_RX 0x0
117 #define AXE_ENDPT_TX 0x1
118 #define AXE_ENDPT_INTR 0x2
119 #define AXE_ENDPT_MAX 0x3
120
121 struct axe_type {
122 struct usb_devno axe_dev;
123 u_int16_t axe_flags;
124 /* XXX No flags so far */
125 };
126
127 struct axe_softc;
128
129 struct axe_chain {
130 struct axe_softc *axe_sc;
131 usbd_xfer_handle axe_xfer;
132 char *axe_buf;
133 struct mbuf *axe_mbuf;
134 int axe_accum;
135 int axe_idx;
136 };
137
138 struct axe_cdata {
139 struct axe_chain axe_tx_chain[AXE_TX_LIST_CNT];
140 struct axe_chain axe_rx_chain[AXE_RX_LIST_CNT];
141 int axe_tx_prod;
142 int axe_tx_cons;
143 int axe_tx_cnt;
144 int axe_rx_prod;
145 };
146
147 #define AXE_INC(x, y) (x) = (x + 1) % y
148
149 struct axe_softc {
150 USBBASEDEVICE axe_dev;
151 #if defined(__FreeBSD__)
152 struct arpcom arpcom;
153 device_t axe_miibus;
154 #define GET_IFP(sc) (&(sc)->arpcom.ac_if)
155 #define GET_MII(sc) (device_get_softc((sc)->axe_miibus))
156 #elif defined(__NetBSD__)
157 struct ethercom axe_ec;
158 struct mii_data axe_mii;
159 #if NRND > 0
160 rndsource_element_t rnd_source;
161 #endif
162 #define GET_IFP(sc) (&(sc)->axe_ec.ec_if)
163 #define GET_MII(sc) (&(sc)->axe_mii)
164 #elif defined(__OpenBSD__)
165 struct arpcom arpcom;
166 struct mii_data axe_mii;
167 #if NRND > 0
168 rndsource_element_t rnd_source;
169 #endif
170 #define GET_IFP(sc) (&(sc)->arpcom.ac_if)
171 #define GET_MII(sc) (&(sc)->axe_mii)
172 #endif
173 usbd_device_handle axe_udev;
174 usbd_interface_handle axe_iface;
175
176 u_int16_t axe_vendor;
177 u_int16_t axe_product;
178
179 int axe_ed[AXE_ENDPT_MAX];
180 usbd_pipe_handle axe_ep[AXE_ENDPT_MAX];
181 int axe_if_flags;
182 struct axe_cdata axe_cdata;
183 usb_callout_t axe_stat_ch;
184
185 int axe_refcnt;
186 char axe_dying;
187 char axe_attached;
188
189 struct usb_task axe_tick_task;
190 struct usb_task axe_stop_task;
191
192 struct lock axe_mii_lock;
193
194 int axe_link;
195 unsigned char axe_ipgs[3];
196 unsigned char axe_phyaddrs[2];
197 struct timeval axe_rx_notice;
198 };
199
200 #if 0
201 #define AXE_LOCK(_sc) mtx_lock(&(_sc)->axe_mtx)
202 #define AXE_UNLOCK(_sc) mtx_unlock(&(_sc)->axe_mtx)
203 #else
204 #define AXE_LOCK(_sc)
205 #define AXE_UNLOCK(_sc)
206 #endif
207
208 #define ETHER_ALIGN 2
209