xref: /openbsd/sys/dev/usb/if_mosreg.h (revision ab0b1be7)
1 /*	$OpenBSD: if_mosreg.h,v 1.7 2013/04/15 09:23:01 mglocker Exp $	*/
2 
3 /*
4  * Copyright (c) 2008 Johann Christian Rode <jcrode@gmx.net>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /*
20  * Copyright (c) 1997, 1998, 1999, 2000-2003
21  *	Bill Paul <wpaul@windriver.com>.  All rights reserved.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  * 1. Redistributions of source code must retain the above copyright
27  *    notice, this list of conditions and the following disclaimer.
28  * 2. Redistributions in binary form must reproduce the above copyright
29  *    notice, this list of conditions and the following disclaimer in the
30  *    documentation and/or other materials provided with the distribution.
31  * 3. All advertising materials mentioning features or use of this software
32  *    must display the following acknowledgement:
33  *	This product includes software developed by Ravikanth.
34  * 4. Neither the name of the author nor the names of any co-contributors
35  *    may be used to endorse or promote products derived from this software
36  *    without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
39  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul, THE VOICES IN HIS HEAD OR
42  * THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
43  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
44  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
45  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
46  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
47  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
48  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49  *
50  */
51 
52 /*
53  * Register definitions for the Moschip MCS7x30 ethernet controller.
54  */
55 #define MOS_MCAST_TABLE 	0x00
56 #define MOS_IPG0		0x08
57 #define MOS_IPG1		0x09
58 #define MOS_PHY_DATA0		0x0a
59 #define MOS_PHY_DATA1		0x0b
60 #define MOS_PHY_CTL		0x0c
61 #define MOS_PHY_STS		0x0d
62 #define MOS_PHY_DATA		MOS_PHY_DATA0
63 #define MOS_CTL			0x0e
64 #define MOS_MAC0		0x0f
65 #define MOS_MAC1		0x10
66 #define MOS_MAC2		0x11
67 #define MOS_MAC3		0x12
68 #define MOS_MAC4		0x13
69 #define MOS_MAC5		0x14
70 #define MOS_MAC			MOS_MAC0
71 /* apparently only available on hardware rev. C */
72 #define MOS_FRAME_DROP_CNT	0x15
73 #define MOS_PAUSE_TRHD		0x16
74 
75 #define MOS_PHYCTL_PHYADDR	0x1f
76 #define MOS_PHYCTL_WRITE	0x20
77 #define MOS_PHYCTL_READ		0x40
78 
79 #define MOS_PHYSTS_PHYREG	0x1f
80 #define MOS_PHYSTS_READY	0x40
81 #define MOS_PHYSTS_PENDING	0x80
82 
83 #define MOS_CTL_RX_PROMISC	0x01
84 #define MOS_CTL_ALLMULTI	0x02
85 #define MOS_CTL_SLEEP		0x04
86 #define MOS_CTL_TX_ENB		0x08
87 /*
88  * The documentation calls this bit 'reserved', but in the FreeBSD driver
89  * provided by the vendor, this enables the receiver.
90  */
91 #define MOS_CTL_RX_ENB		0x10
92 #define MOS_CTL_FDX_ENB		0x20
93 /* 0 = 10 Mbps, 1 = 100 Mbps */
94 #define MOS_CTL_SPEEDSEL	0x40
95 /* 0 = PHY controls speed/duplex mode, 1 = bridge controls speed/duplex mode */
96 #define MOS_CTL_BS_ENB		0x80
97 
98 #define MOS_RXSTS_SHORT_FRAME	0x01
99 #define MOS_RXSTS_LENGTH_ERROR	0x02
100 #define MOS_RXSTS_ALIGN_ERROR	0x04
101 #define MOS_RXSTS_CRC_ERROR	0x08
102 #define MOS_RXSTS_LARGE_FRAME	0x10
103 #define MOS_RXSTS_VALID		0x20
104 /*
105  * The EtherType field of an Ethernet frame can contain values other than
106  * the frame length, hence length errors are ignored.
107  */
108 #define MOS_RXSTS_MASK		0x3d
109 
110 #define MOS_PAUSE_TRHD_DEFAULT	0
111 #define MOS_PAUSE_REWRITES	3
112 
113 #define MOS_TIMEOUT		1000
114 
115 #define MOS_RX_LIST_CNT		1
116 #define MOS_TX_LIST_CNT		1
117 
118 /* Maximum size of a fast ethernet frame plus one byte for the status */
119 #define MOS_BUFSZ	 	(ETHER_MAX_LEN+1)
120 
121 /*
122  * USB endpoints.
123  */
124 #define MOS_ENDPT_RX		0
125 #define MOS_ENDPT_TX		1
126 #define MOS_ENDPT_INTR		2
127 #define MOS_ENDPT_MAX		3
128 
129 /*
130  * USB vendor requests.
131  */
132 #define MOS_UR_READREG		0x0e
133 #define MOS_UR_WRITEREG		0x0d
134 
135 #define MOS_CONFIG_NO		1
136 #define MOS_IFACE_IDX		0
137 
138 struct mos_type {
139 	struct usb_devno	mos_dev;
140 	u_int16_t		mos_flags;
141 #define MCS7730	0x0001		/* MCS7730 */
142 #define MCS7830	0x0002		/* MCS7830 */
143 #define MCS7832	0x0004		/* MCS7832 */
144 };
145 
146 #define MOS_INC(x, y)           (x) = (x + 1) % y
147 
148 struct mos_softc;
149 
150 struct mos_chain {
151 	struct mos_softc	*mos_sc;
152 	struct usbd_xfer	*mos_xfer;
153 	char			*mos_buf;
154 	struct mbuf		*mos_mbuf;
155 	int			mos_accum;
156 	int			mos_idx;
157 };
158 
159 struct mos_cdata {
160 	struct mos_chain	mos_tx_chain[MOS_TX_LIST_CNT];
161 	struct mos_chain	mos_rx_chain[MOS_RX_LIST_CNT];
162 	int			mos_tx_prod;
163 	int			mos_tx_cons;
164 	int			mos_tx_cnt;
165 	int			mos_rx_prod;
166 };
167 
168 struct mos_softc {
169 	struct device		mos_dev;
170 #define GET_MII(sc) (&(sc)->mos_mii)
171 	struct arpcom		arpcom;
172 #define GET_IFP(sc) (&(sc)->arpcom.ac_if)
173 	struct mii_data		mos_mii;
174 	struct usbd_device	*mos_udev;
175 	struct usbd_interface	*mos_iface;
176 
177 	u_int16_t		mos_flags;
178 
179 	int			mos_ed[MOS_ENDPT_MAX];
180 	struct usbd_pipe	*mos_ep[MOS_ENDPT_MAX];
181 	int			mos_unit;
182 	struct mos_cdata	mos_cdata;
183 	struct timeout		mos_stat_ch;
184 
185 	int			mos_refcnt;
186 
187 	int			mos_link;
188 	unsigned char		mos_ipgs[2];
189 	unsigned char 		mos_phyaddrs[2];
190 	struct timeval		mos_rx_notice;
191 
192 	u_int16_t		mos_tspeed;
193 	u_int16_t		mos_maxpacket;
194 
195 	struct ifmedia		mos_ifmedia;
196 
197 	struct usb_task		mos_tick_task;
198 	struct usb_task		mos_stop_task;
199 
200 	struct rwlock		mos_mii_lock;
201 
202 	u_int			mos_bufsz;
203 };
204 
205