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