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