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