xref: /netbsd-src/sys/dev/usb/if_smscreg.h (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /*	$NetBSD: if_smscreg.h,v 1.4 2014/06/09 14:18:28 mlelstv Exp $	*/
2 
3 /*	$OpenBSD: if_smscreg.h,v 1.2 2012/09/27 12:38:11 jsg Exp $	*/
4 /*-
5  * Copyright (c) 2012
6  *	Ben Gray <bgray@freebsd.org>.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD: src/sys/dev/usb/net/if_smscreg.h,v 1.1 2012/08/15 04:03:55 gonzo Exp $
31  */
32 #ifndef _IF_SMSCREG_H_
33 #define _IF_SMSCREG_H_
34 
35 /*
36  * Definitions for the SMSC LAN9514 and LAN9514 USB to ethernet controllers.
37  *
38  * This information was gleaned from the SMSC driver in the linux kernel, where
39  * it is Copyrighted (C) 2007-2008 SMSC.
40  *
41  */
42 
43 /*
44  * TRANSMIT FRAMES
45  * ---------------
46  *   Tx frames are prefixed with an 8-byte header which describes the frame
47  *
48  *         4 bytes      4 bytes           variable
49  *      +------------+------------+--- . . . . . . . . . . . . ---+
50  *      | TX_CTRL_0  | TX_CTRL_1  |  Ethernet frame data          |
51  *      +------------+------------+--- . . . . . . . . . . . . ---+
52  *
53  *   Where the headers have the following fields:
54  *
55  *      TX_CTRL_0 <20:16>  Data offset
56  *      TX_CTRL_0 <13>     First segment of frame indicator
57  *      TX_CTRL_0 <12>     Last segment of frame indicator
58  *      TX_CTRL_0 <10:0>   Buffer size (?)
59  *
60  *      TX_CTRL_1 <14>     Perform H/W checksuming on IP packets
61  *      TX_CTRL_1 <13>     Disable automatic ethernet CRC generation
62  *      TX_CTRL_1 <12>     Disable padding (?)
63  *      TX_CTRL_1 <10:0>   Packet byte length
64  *
65  */
66 #define SMSC_TX_CTRL_0_OFFSET(x)	(((x) & 0x1FUL) << 16)
67 #define SMSC_TX_CTRL_0_FIRST_SEG	(0x1UL << 13)
68 #define SMSC_TX_CTRL_0_LAST_SEG		(0x1UL << 12)
69 #define SMSC_TX_CTRL_0_BUF_SIZE(x)	((x) & 0x000007FFUL)
70 
71 #define SMSC_TX_CTRL_1_CSUM_ENABLE	(0x1UL << 14)
72 #define SMSC_TX_CTRL_1_CRC_DISABLE	(0x1UL << 13)
73 #define SMSC_TX_CTRL_1_PADDING_DISABLE	(0x1UL << 12)
74 #define SMSC_TX_CTRL_1_PKT_LENGTH(x)	((x) & 0x000007FFUL)
75 
76 /*
77  * RECEIVE FRAMES
78  * --------------
79  *   Rx frames are prefixed with an 4-byte status header which describes any
80  *   errors with the frame as well as things like the length
81  *
82  *         4 bytes             variable
83  *      +------------+--- . . . . . . . . . . . . ---+
84  *      |   RX_STAT  |  Ethernet frame data          |
85  *      +------------+--- . . . . . . . . . . . . ---+
86  *
87  *   Where the status header has the following fields:
88  *
89  *      RX_STAT   <30>     Filter Fail
90  *      RX_STAT   <29:16>  Frame Length
91  *      RX_STAT   <15>     Error Summary
92  *      RX_STAT   <13>     Broadcast Frame
93  *      RX_STAT   <12>     Length Error
94  *      RX_STAT   <11>     Runt Frame
95  *      RX_STAT   <10>     Multicast Frame
96  *      RX_STAT   <7>      Frame too long
97  *      RX_STAT   <6>      Collision Seen
98  *      RX_STAT   <5>      Frame Type
99  *      RX_STAT   <4>      Receive Watchdog
100  *      RX_STAT   <3>      Mii Error
101  *      RX_STAT   <2>      Dribbling
102  *      RX_STAT   <1>      CRC Error
103  *
104  */
105 #define SMSC_RX_STAT_FILTER_FAIL	(0x1UL << 30)
106 #define SMSC_RX_STAT_FRM_LENGTH(x)	(((x) >> 16) & 0x3FFFUL)
107 #define SMSC_RX_STAT_ERROR		(0x1UL << 15)
108 #define SMSC_RX_STAT_BROADCAST		(0x1UL << 13)
109 #define SMSC_RX_STAT_LENGTH_ERROR	(0x1UL << 12)
110 #define SMSC_RX_STAT_RUNT		(0x1UL << 11)
111 #define SMSC_RX_STAT_MULTICAST		(0x1UL << 10)
112 #define SMSC_RX_STAT_FRM_TOO_LONG	(0x1UL << 7)
113 #define SMSC_RX_STAT_COLLISION		(0x1UL << 6)
114 #define SMSC_RX_STAT_FRM_TYPE		(0x1UL << 5)
115 #define SMSC_RX_STAT_WATCHDOG		(0x1UL << 4)
116 #define SMSC_RX_STAT_MII_ERROR		(0x1UL << 3)
117 #define SMSC_RX_STAT_DRIBBLING		(0x1UL << 2)
118 #define SMSC_RX_STAT_CRC_ERROR		(0x1UL << 1)
119 
120 /*
121  * REGISTERS
122  */
123 #define SMSC_ID_REV		0x000
124 #define SMSC_INTR_STATUS	0x008
125 #define SMSC_RX_CFG		0x00C
126 #define SMSC_TX_CFG		0x010
127 #define SMSC_HW_CFG		0x014
128 #define SMSC_PM_CTRL		0x020
129 #define SMSC_LED_GPIO_CFG	0x024
130 #define SMSC_GPIO_CFG		0x028
131 #define SMSC_AFC_CFG		0x02C
132 #define SMSC_EEPROM_CMD		0x030
133 #define SMSC_EEPROM_DATA	0x034
134 #define SMSC_BURST_CAP		0x038
135 #define SMSC_GPIO_WAKE		0x064
136 #define SMSC_INTR_CFG		0x068
137 #define SMSC_BULK_IN_DLY	0x06C
138 #define SMSC_MAC_CSR		0x100
139 #define SMSC_MAC_ADDRH		0x104
140 #define SMSC_MAC_ADDRL		0x108
141 #define SMSC_HASHH		0x10C
142 #define SMSC_HASHL		0x110
143 #define SMSC_MII_ADDR		0x114
144 #define SMSC_MII_DATA		0x118
145 #define SMSC_FLOW		0x11C
146 #define SMSC_VLAN1		0x120
147 #define SMSC_VLAN2		0x124
148 #define SMSC_WUFF		0x128
149 #define SMSC_WUCSR		0x12C
150 #define SMSC_COE_CTRL		0x130
151 
152 /* ID / Revision register */
153 #define SMSC_ID_REV_CHIP_ID_MASK	0xFFFF0000UL
154 #define SMSC_ID_REV_CHIP_REV_MASK	0x0000FFFFUL
155 
156 #define SMSC_RX_FIFO_FLUSH		(0x1UL << 0)
157 
158 #define SMSC_TX_CFG_ON			(0x1UL << 2)
159 #define SMSC_TX_CFG_STOP		(0x1UL << 1)
160 #define SMSC_TX_CFG_FIFO_FLUSH		(0x1UL << 0)
161 
162 #define SMSC_HW_CFG_BIR			(0x1UL << 12)
163 #define SMSC_HW_CFG_LEDB		(0x1UL << 11)
164 #define SMSC_HW_CFG_RXDOFF_SHIFT	(9)
165 #define SMSC_HW_CFG_RXDOFF		(0x3UL << 9)    /* RX pkt alignment */
166 #define SMSC_HW_CFG_DRP			(0x1UL << 6)
167 #define SMSC_HW_CFG_MEF			(0x1UL << 5)
168 #define SMSC_HW_CFG_LRST		(0x1UL << 3)    /* Lite reset */
169 #define SMSC_HW_CFG_PSEL		(0x1UL << 2)
170 #define SMSC_HW_CFG_BCE			(0x1UL << 1)
171 #define SMSC_HW_CFG_SRST		(0x1UL << 0)
172 
173 #define SMSC_PM_CTRL_PHY_RST		(0x1UL << 4)    /* PHY reset */
174 
175 #define SMSC_LED_GPIO_CFG_SPD_LED	(0x1UL << 24)
176 #define SMSC_LED_GPIO_CFG_LNK_LED	(0x1UL << 20)
177 #define SMSC_LED_GPIO_CFG_FDX_LED	(0x1UL << 16)
178 
179 /* Hi watermark = 15.5Kb (~10 mtu pkts) */
180 /* low watermark = 3k (~2 mtu pkts) */
181 /* backpressure duration = ~ 350us */
182 /* Apply FC on any frame. */
183 #define AFC_CFG_DEFAULT			(0x00F830A1)
184 
185 #define SMSC_EEPROM_CMD_BUSY		(0x1UL << 31)
186 #define SMSC_EEPROM_CMD_MASK		(0x7UL << 28)
187 #define SMSC_EEPROM_CMD_READ		(0x0UL << 28)
188 #define SMSC_EEPROM_CMD_WRITE		(0x3UL << 28)
189 #define SMSC_EEPROM_CMD_ERASE		(0x5UL << 28)
190 #define SMSC_EEPROM_CMD_RELOAD		(0x7UL << 28)
191 #define SMSC_EEPROM_CMD_TIMEOUT		(0x1UL << 10)
192 #define SMSC_EEPROM_CMD_ADDR_MASK	0x000001FFUL
193 
194 /* MAC Control and Status Register */
195 #define SMSC_MAC_CSR_RCVOWN		(0x1UL << 23)  /* Half duplex */
196 #define SMSC_MAC_CSR_LOOPBK		(0x1UL << 21)  /* Loopback */
197 #define SMSC_MAC_CSR_FDPX		(0x1UL << 20)  /* Full duplex */
198 #define SMSC_MAC_CSR_MCPAS		(0x1UL << 19)  /* Multicast mode */
199 #define SMSC_MAC_CSR_PRMS		(0x1UL << 18)  /* Promiscuous mode */
200 #define SMSC_MAC_CSR_INVFILT		(0x1UL << 17)  /* Inverse filtering */
201 #define SMSC_MAC_CSR_PASSBAD		(0x1UL << 16)  /* Pass on bad frames */
202 #define SMSC_MAC_CSR_HPFILT		(0x1UL << 13)  /* Hash filtering */
203 #define SMSC_MAC_CSR_BCAST		(0x1UL << 11)  /* Broadcast */
204 #define SMSC_MAC_CSR_DISRTY		(0x1UL << 10)  /* Disable Retry */
205 #define SMSC_MAC_CSR_PADSTR		(0x1UL << 8)   /* PAD stripping */
206 #define SMSC_MAC_CSR_TXEN		(0x1UL << 3)   /* TX enable */
207 #define SMSC_MAC_CSR_RXEN		(0x1UL << 2)   /* RX enable */
208 
209 /* Interrupt control register */
210 #define SMSC_INTR_NTEP			(0x1UL << 31)
211 #define SMSC_INTR_MACRTO		(0x1UL << 19)
212 #define SMSC_INTR_TX_STOP		(0x1UL << 17)
213 #define SMSC_INTR_RX_STOP		(0x1UL << 16)
214 #define SMSC_INTR_PHY_INT		(0x1UL << 15)
215 #define SMSC_INTR_TXE			(0x1UL << 14)
216 #define SMSC_INTR_TDFU			(0x1UL << 13)
217 #define SMSC_INTR_TDFO			(0x1UL << 12)
218 #define SMSC_INTR_RXDF			(0x1UL << 11)
219 #define SMSC_INTR_GPIOS			0x000007FFUL
220 
221 /* Phy MII interface register */
222 #define SMSC_MII_WRITE			(0x1UL << 1)
223 #define SMSC_MII_READ			(0x0UL << 1)
224 #define SMSC_MII_BUSY			(0x1UL << 0)
225 
226 /* H/W checksum register */
227 #define SMSC_COE_CTRL_TX_EN		(0x1UL << 16)  /* Tx H/W csum enable */
228 #define SMSC_COE_CTRL_RX_MODE		(0x1UL << 1)
229 #define SMSC_COE_CTRL_RX_EN		(0x1UL << 0)   /* Rx H/W csum enable */
230 
231 /* Registers on the phy, accessed via MII/MDIO */
232 #define SMSC_PHY_INTR_STAT		(29)
233 #define SMSC_PHY_INTR_MASK		(30)
234 
235 #define SMSC_PHY_INTR_ENERGY_ON		(0x1U << 7)
236 #define SMSC_PHY_INTR_ANEG_COMP		(0x1U << 6)
237 #define SMSC_PHY_INTR_REMOTE_FAULT	(0x1U << 5)
238 #define SMSC_PHY_INTR_LINK_DOWN		(0x1U << 4)
239 
240 /* USB Vendor Requests */
241 #define SMSC_UR_WRITE_REG	0xA0
242 #define SMSC_UR_READ_REG	0xA1
243 #define SMSC_UR_GET_STATS	0xA2
244 
245 #define SMSC_RX_LIST_CNT	1
246 #define SMSC_TX_LIST_CNT	1
247 
248 #define	SMSC_CONFIG_INDEX	1	/* config number 1 */
249 #define	SMSC_IFACE_IDX		0
250 
251 #define SMSC_ENDPT_RX		0
252 #define SMSC_ENDPT_TX		1
253 #define SMSC_ENDPT_INTR		2
254 #define SMSC_ENDPT_MAX		3
255 
256 #define SMSC_MIN_BUFSZ		2048
257 #define SMSC_MAX_BUFSZ		18944
258 
259 #endif  /* _IF_SMSCREG_H_ */
260