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