if_udavreg.h revision 238466
1139823Simp/*	$NetBSD: if_udavreg.h,v 1.2 2003/09/04 15:17:39 tsutsui Exp $	*/
21541Srgrimes/*	$nabe: if_udavreg.h,v 1.2 2003/08/21 16:26:40 nabe Exp $	*/
31541Srgrimes/*	$FreeBSD: head/sys/dev/usb/net/if_udavreg.h 238466 2012-07-15 05:49:02Z rpaulo $	*/
41541Srgrimes/*-
51541Srgrimes * Copyright (c) 2003
61541Srgrimes *     Shingo WATANABE <nabe@nabechan.org>.  All rights reserved.
71541Srgrimes *
81541Srgrimes * Redistribution and use in source and binary forms, with or without
91541Srgrimes * modification, are permitted provided that the following conditions
101541Srgrimes * are met:
111541Srgrimes * 1. Redistributions of source code must retain the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer.
131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer in the
151541Srgrimes *    documentation and/or other materials provided with the distribution.
161541Srgrimes * 3. Neither the name of the author nor the names of any co-contributors
171541Srgrimes *    may be used to endorse or promote products derived from this software
181541Srgrimes *    without specific prior written permission.
191541Srgrimes *
201541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
211541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
241541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301541Srgrimes * SUCH DAMAGE.
311541Srgrimes *
32172467Ssilby */
33172467Ssilby
34172467Ssilby#define	UDAV_IFACE_INDEX	0
35261601Sglebius#define	UDAV_CONFIG_INDEX	0	/* config number 1 */
3655009Sshin
37113384Ssilby#define	UDAV_TX_TIMEOUT		1000
38178167Sqingli#define	UDAV_TIMEOUT		10000
39254889Smarkj
40188066Srrs#define	UDAV_TX_TIMEOUT		1000
41266421Sadrian#define	UDAV_TIMEOUT		10000
4230966Sjoerg
431541Srgrimes/* Packet length */
441549Srgrimes#define	UDAV_MIN_FRAME_LEN	60
4541990Sluigi
46286001Sae/* Request */
471541Srgrimes#define	UDAV_REQ_REG_READ	0x00	/* Read from register(s) */
481541Srgrimes#define	UDAV_REQ_REG_WRITE	0x01	/* Write to register(s) */
49164033Srwatson#define	UDAV_REQ_REG_WRITE1	0x03	/* Write to a register */
50175892Sbz
511541Srgrimes#define	UDAV_REQ_MEM_READ	0x02	/* Read from memory */
52286001Sae#define	UDAV_REQ_MEM_WRITE	0x05	/* Write to memory */
53254889Smarkj#define	UDAV_REQ_MEM_WRITE1	0x07	/* Write a byte to memory */
541541Srgrimes
551541Srgrimes/* Registers */
56112591Ssilby#define	UDAV_NCR		0x00	/* Network Control Register */
57175892Sbz#define	UDAV_NCR_EXT_PHY	(1<<7)	/* Select External PHY */
581541Srgrimes#define	UDAV_NCR_WAKEEN	(1<<6)		/* Wakeup Event Enable */
591541Srgrimes#define	UDAV_NCR_FCOL		(1<<4)	/* Force Collision Mode */
60257176Sglebius#define	UDAV_NCR_FDX		(1<<3)	/* Full-Duplex Mode (RO on Int. PHY) */
61196234Sqingli#define	UDAV_NCR_LBK1		(1<<2)	/* Lookback Mode */
62133920Sandre#define	UDAV_NCR_LBK0		(1<<1)	/* Lookback Mode */
63134383Sandre#define	UDAV_NCR_RST		(1<<0)	/* Software reset */
641541Srgrimes
65191259Skmacy#define	UDAV_RCR		0x05	/* RX Control Register */
66178167Sqingli#define	UDAV_RCR_WTDIS		(1<<6)	/* Watchdog Timer Disable */
67178167Sqingli#define	UDAV_RCR_DIS_LONG	(1<<5)	/* Discard Long Packet(over 1522Byte) */
68178167Sqingli#define	UDAV_RCR_DIS_CRC	(1<<4)	/* Discard CRC Error Packet */
69277331Sadrian#define	UDAV_RCR_ALL		(1<<3)	/* Pass All Multicast */
70185571Sbz#define	UDAV_RCR_RUNT		(1<<2)	/* Pass Runt Packet */
711541Srgrimes#define	UDAV_RCR_PRMSC		(1<<1)	/* Promiscuous Mode */
721541Srgrimes#define	UDAV_RCR_RXEN		(1<<0)	/* RX Enable */
73254889Smarkj
741541Srgrimes#define	UDAV_RSR		0x06	/* RX Status Register */
751541Srgrimes#define	UDAV_RSR_RF		(1<<7)	/* Runt Frame */
761541Srgrimes#define	UDAV_RSR_MF		(1<<6)	/* Multicast Frame */
77266421Sadrian#define	UDAV_RSR_LCS		(1<<5)	/* Late Collision Seen */
781541Srgrimes#define	UDAV_RSR_RWTO		(1<<4)	/* Receive Watchdog Time-Out */
791541Srgrimes#define	UDAV_RSR_PLE		(1<<3)	/* Physical Layer Error */
80152592Sandre#define	UDAV_RSR_AE		(1<<2)	/* Alignment Error */
81188066Srrs#define	UDAV_RSR_CE		(1<<1)	/* CRC Error */
82188066Srrs#define	UDAV_RSR_FOE		(1<<0)	/* FIFO Overflow Error */
83188066Srrs#define	UDAV_RSR_ERR		(UDAV_RSR_RF | UDAV_RSR_LCS |		\
84188066Srrs				    UDAV_RSR_RWTO | UDAV_RSR_PLE |	\
851541Srgrimes				    UDAV_RSR_AE | UDAV_RSR_CE | UDAV_RSR_FOE)
86315514Sae
87105199Ssam#define	UDAV_EPCR		0x0b	/* EEPROM & PHY Control Register */
88155179Sandre#define	UDAV_EPCR_REEP		(1<<5)	/* Reload EEPROM */
89155179Sandre#define	UDAV_EPCR_WEP		(1<<4)	/* Write EEPROM enable */
90163606Srwatson#define	UDAV_EPCR_EPOS		(1<<3)	/* EEPROM or PHY Operation Select */
91163606Srwatson#define	UDAV_EPCR_ERPRR		(1<<2)	/* EEPROM/PHY Register Read Command */
92113384Ssilby#define	UDAV_EPCR_ERPRW		(1<<1)	/* EEPROM/PHY Register Write Command */
93220619Sbz#define	UDAV_EPCR_ERRE		(1<<0)	/* EEPROM/PHY Access Status */
94112591Ssilby
95112591Ssilby#define	UDAV_EPAR		0x0c	/* EEPROM & PHY Control Register */
96112591Ssilby#define	UDAV_EPAR_PHY_ADR1	(1<<7)	/* PHY Address bit 1 */
97112591Ssilby#define	UDAV_EPAR_PHY_ADR0	(1<<6)	/* PHY Address bit 0 */
98286452Smelifaro#define	UDAV_EPAR_EROA		(1<<0)	/* EEPROM Word/PHY Register Address */
991541Srgrimes#define	UDAV_EPAR_EROA_MASK	(0x1f)	/* [5:0] */
10022531Sdarrenr
101189359Sbms#define	UDAV_EPDRL		0x0d	/* EEPROM & PHY Data Register */
10217072Sjulian#define	UDAV_EPDRH		0x0e	/* EEPROM & PHY Data Register */
10317072Sjulian
104286028Seri#define	UDAV_PAR0		0x10	/* Ethernet Address, load from EEPROM */
105286242Smarkj#define	UDAV_PAR1		0x11	/* Ethernet Address, load from EEPROM */
106286242Smarkj#define	UDAV_PAR2		0x12	/* Ethernet Address, load from EEPROM */
107286028Seri#define	UDAV_PAR3		0x13	/* Ethernet Address, load from EEPROM */
108286028Seri#define	UDAV_PAR4		0x14	/* Ethernet Address, load from EEPROM */
109286242Smarkj#define	UDAV_PAR5		0x15	/* Ethernet Address, load from EEPROM */
110286028Seri#define	UDAV_PAR		UDAV_PAR0
111286028Seri
112286028Seri#define	UDAV_MAR0		0x16	/* Multicast Register */
113286242Smarkj#define	UDAV_MAR1		0x17	/* Multicast Register */
114286028Seri#define	UDAV_MAR2		0x18	/* Multicast Register */
115286028Seri#define	UDAV_MAR3		0x19	/* Multicast Register */
116286028Seri#define	UDAV_MAR4		0x1a	/* Multicast Register */
117286028Seri#define	UDAV_MAR5		0x1b	/* Multicast Register */
118332513Skp#define	UDAV_MAR6		0x1c	/* Multicast Register */
119286242Smarkj#define	UDAV_MAR7		0x1d	/* Multicast Register */
120286028Seri#define	UDAV_MAR		UDAV_MAR0
121286028Seri
122286028Seri#define	UDAV_GPCR		0x1e	/* General purpose control register */
123286028Seri#define	UDAV_GPCR_GEP_CNTL6	(1<<6)	/* General purpose control 6 */
124286028Seri#define	UDAV_GPCR_GEP_CNTL5	(1<<5)	/* General purpose control 5 */
125286028Seri#define	UDAV_GPCR_GEP_CNTL4	(1<<4)	/* General purpose control 4 */
126286028Seri#define	UDAV_GPCR_GEP_CNTL3	(1<<3)	/* General purpose control 3 */
127286028Seri#define	UDAV_GPCR_GEP_CNTL2	(1<<2)	/* General purpose control 2 */
128286028Seri#define	UDAV_GPCR_GEP_CNTL1	(1<<1)	/* General purpose control 1 */
129286028Seri#define	UDAV_GPCR_GEP_CNTL0	(1<<0)	/* General purpose control 0 */
130286028Seri
131286028Seri#define	UDAV_GPR		0x1f	/* General purpose register */
132286028Seri#define	UDAV_GPR_GEPIO6		(1<<6)	/* General purpose 6 */
133286028Seri#define	UDAV_GPR_GEPIO5		(1<<5)	/* General purpose 5 */
134286028Seri#define	UDAV_GPR_GEPIO4		(1<<4)	/* General purpose 4 */
135286028Seri#define	UDAV_GPR_GEPIO3		(1<<3)	/* General purpose 3 */
136286028Seri#define	UDAV_GPR_GEPIO2		(1<<2)	/* General purpose 2 */
137286028Seri#define	UDAV_GPR_GEPIO1		(1<<1)	/* General purpose 1 */
138286028Seri#define	UDAV_GPR_GEPIO0		(1<<0)	/* General purpose 0 */
139286028Seri
140286028Seri#define	GET_MII(sc)		uether_getmii(&(sc)->sc_ue)
141286028Seri
142286028Seristruct udav_rxpkt {
143286028Seri	uint8_t	rxstat;
144286028Seri	uint16_t pktlen;
145286028Seri} __packed;
146286028Seri
147286028Serienum {
148286028Seri	UDAV_BULK_DT_WR,
149286028Seri	UDAV_BULK_DT_RD,
150286028Seri	UDAV_INTR_DT_RD,
151286028Seri	UDAV_N_TRANSFER,
152286028Seri};
153286028Seri
154286028Seristruct udav_softc {
155286028Seri	struct usb_ether	sc_ue;
156286028Seri	struct mtx		sc_mtx;
157286028Seri	struct usb_xfer	*sc_xfer[UDAV_N_TRANSFER];
158286028Seri
159286028Seri	int			sc_flags;
160286028Seri#define	UDAV_FLAG_LINK		0x0001
161286028Seri#define	UDAV_FLAG_EXT_PHY	0x0040
162286028Seri#define	UDAV_FLAG_NO_PHY	0x0080
163286028Seri};
164286028Seri
165286028Seri#define	UDAV_LOCK(_sc)			mtx_lock(&(_sc)->sc_mtx)
166286028Seri#define	UDAV_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
167286028Seri#define	UDAV_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->sc_mtx, t)
168286028Seri