Home | History | Annotate | Line # | Download | only in usb
if_udavreg.h revision 1.1
      1 /*	$NetBSD: if_udavreg.h,v 1.1 2003/08/22 05:13:29 itojun Exp $	*/
      2 /*	$nabe: if_udavreg.h,v 1.2 2003/08/21 16:26:40 nabe Exp $	*/
      3 /*
      4  * Copyright (c) 2003
      5  *     Shingo WATANABE <nabe (at) nabechan.org>.  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  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Shingo WATANABE.
     18  * 4. Neither the name of the author nor the names of any co-contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  */
     35 
     36 #define	UDAV_IFACE_INDEX	0
     37 #define	UDAV_CONFIG_NO		1
     38 
     39 #define	UDAV_TX_LIST_CNT	1
     40 #define	UDAV_RX_LIST_CNT	1
     41 
     42 #define	UDAV_TX_TIMEOUT		1000
     43 #define	UDAV_TIMEOUT		10000
     44 
     45 #define	ETHER_ALIGN		2
     46 
     47 
     48 /* Packet length */
     49 #define	UDAV_MAX_MTU		1536 /* XXX: max frame size is unknown */
     50 #define	UDAV_MIN_FRAME_LEN	60
     51 #define	UDAV_BUFSZ		UDAV_MAX_MTU
     52 
     53 /* Request */
     54 #define	UDAV_REQ_REG_READ	0x00 /* Read from register(s) */
     55 #define	UDAV_REQ_REG_WRITE	0x01 /* Write to register(s) */
     56 #define	UDAV_REQ_REG_WRITE1	0x03 /* Write to a register */
     57 
     58 #define	UDAV_REQ_MEM_READ	0x02 /* Read from memory */
     59 #define	UDAV_REQ_MEM_WRITE	0x05 /* Write to memory */
     60 #define	UDAV_REQ_MEM_WRITE1	0x07 /* Write a byte to memory */
     61 
     62 /* Registers */
     63 #define	UDAV_NCR		0x00 /* Network Control Register */
     64 #define	 UDAV_NCR_EXT_PHY	(1<<7) /* Select External PHY */
     65 #define	 UDAV_NCR_WAKEEN	(1<<6) /* Wakeup Event Enable */
     66 #define	 UDAV_NCR_FCOL		(1<<4) /* Force Collision Mode */
     67 #define	 UDAV_NCR_FDX		(1<<3) /* Full-Duplex Mode (RO on Int. PHY) */
     68 #define	 UDAV_NCR_LBK1		(1<<2) /* Lookback Mode */
     69 #define	 UDAV_NCR_LBK0		(1<<1) /* Lookback Mode */
     70 #define	 UDAV_NCR_RST		(1<<0) /* Software reset */
     71 
     72 #define	UDAV_RCR		0x05 /* RX Control Register */
     73 #define	 UDAV_RCR_WTDIS		(1<<6) /* Watchdog Timer Disable */
     74 #define	 UDAV_RCR_DIS_LONG	(1<<5) /* Discard Long Packet(over 1522Byte) */
     75 #define	 UDAV_RCR_DIS_CRC	(1<<4) /* Discard CRC Error Packet */
     76 #define	 UDAV_RCR_ALL		(1<<3) /* Pass All Multicast */
     77 #define	 UDAV_RCR_RUNT		(1<<2) /* Pass Runt Packet */
     78 #define	 UDAV_RCR_PRMSC		(1<<1) /* Promiscuous Mode */
     79 #define	 UDAV_RCR_RXEN		(1<<0) /* RX Enable */
     80 
     81 #define	UDAV_RSR		0x06 /* RX Status Register */
     82 #define	 UDAV_RSR_RF		(1<<7) /* Runt Frame */
     83 #define	 UDAV_RSR_MF		(1<<6) /* Multicast Frame */
     84 #define	 UDAV_RSR_LCS		(1<<5) /* Late Collision Seen */
     85 #define	 UDAV_RSR_RWTO		(1<<4) /* Receive Watchdog Time-Out */
     86 #define	 UDAV_RSR_PLE		(1<<3) /* Physical Layer Error */
     87 #define	 UDAV_RSR_AE		(1<<2) /* Alignment Error */
     88 #define	 UDAV_RSR_CE		(1<<1) /* CRC Error */
     89 #define	 UDAV_RSR_FOE		(1<<0) /* FIFO Overflow Error */
     90 #define	 UDAV_RSR_ERR		(UDAV_RSR_RF | UDAV_RSR_LCS | UDAV_RSR_RWTO |\
     91 				UDAV_RSR_PLE | UDAV_RSR_AE | UDAV_RSR_CE |\
     92 				UDAV_RSR_FOE)
     93 
     94 #define	UDAV_EPCR		0x0b /* EEPROM & PHY Control Register */
     95 #define	 UDAV_EPCR_REEP		(1<<5) /* Reload EEPROM */
     96 #define	 UDAV_EPCR_WEP		(1<<4) /* Write EEPROM enable */
     97 #define	 UDAV_EPCR_EPOS		(1<<3) /* EEPROM or PHY Operation Select */
     98 #define	 UDAV_EPCR_ERPRR	(1<<2) /* EEPROM/PHY Register Read Command */
     99 #define	 UDAV_EPCR_ERPRW	(1<<1) /* EEPROM/PHY Register Write Command */
    100 #define	 UDAV_EPCR_ERRE		(1<<0) /* EEPROM/PHY Access Status */
    101 
    102 #define	UDAV_EPAR		0x0c /* EEPROM & PHY Control Register */
    103 #define	 UDAV_EPAR_PHY_ADR1	(1<<7) /* PHY Address bit 1 */
    104 #define	 UDAV_EPAR_PHY_ADR0	(1<<6) /* PHY Address bit 0 */
    105 #define	 UDAV_EPAR_EROA		(1<<0) /* EEPROM Word/PHY Register Address */
    106 #define	 UDAV_EPAR_EROA_MASK	(0x1f) /* [5:0] */
    107 
    108 #define	UDAV_EPDRL		0x0d /* EEPROM & PHY Data Register */
    109 #define	UDAV_EPDRH		0x0e /* EEPROM & PHY Data Register */
    110 
    111 #define	UDAV_PAR0		0x10 /* Ethernet Address, load from EEPROM */
    112 #define	UDAV_PAR1		0x11 /* Ethernet Address, load from EEPROM */
    113 #define	UDAV_PAR2		0x12 /* Ethernet Address, load from EEPROM */
    114 #define	UDAV_PAR3		0x13 /* Ethernet Address, load from EEPROM */
    115 #define	UDAV_PAR4		0x14 /* Ethernet Address, load from EEPROM */
    116 #define	UDAV_PAR5		0x15 /* Ethernet Address, load from EEPROM */
    117 #define	UDAV_PAR		UDAV_PAR0
    118 
    119 #define	UDAV_MAR0		0x16 /* Multicast Register */
    120 #define	UDAV_MAR1		0x17 /* Multicast Register */
    121 #define	UDAV_MAR2		0x18 /* Multicast Register */
    122 #define	UDAV_MAR3		0x19 /* Multicast Register */
    123 #define	UDAV_MAR4		0x1a /* Multicast Register */
    124 #define	UDAV_MAR5		0x1b /* Multicast Register */
    125 #define	UDAV_MAR6		0x1c /* Multicast Register */
    126 #define	UDAV_MAR7		0x1d /* Multicast Register */
    127 #define	UDAV_MAR		UDAV_MAR0
    128 
    129 #define	UDAV_GPCR		0x1e /* General purpose control register */
    130 #define	 UDAV_GPCR_GEP_CNTL6	(1<<6) /* General purpose control 6 */
    131 #define	 UDAV_GPCR_GEP_CNTL5	(1<<5) /* General purpose control 5 */
    132 #define	 UDAV_GPCR_GEP_CNTL4	(1<<4) /* General purpose control 4 */
    133 #define	 UDAV_GPCR_GEP_CNTL3	(1<<3) /* General purpose control 3 */
    134 #define	 UDAV_GPCR_GEP_CNTL2	(1<<2) /* General purpose control 2 */
    135 #define	 UDAV_GPCR_GEP_CNTL1	(1<<1) /* General purpose control 1 */
    136 #define	 UDAV_GPCR_GEP_CNTL0	(1<<0) /* General purpose control 0 */
    137 
    138 #define	UDAV_GPR		0x1f /* General purpose register */
    139 #define	 UDAV_GPR_GEPIO6	(1<<6) /* General purpose 6 */
    140 #define	 UDAV_GPR_GEPIO5	(1<<5) /* General purpose 5 */
    141 #define	 UDAV_GPR_GEPIO4	(1<<4) /* General purpose 4 */
    142 #define	 UDAV_GPR_GEPIO3	(1<<3) /* General purpose 3 */
    143 #define	 UDAV_GPR_GEPIO2	(1<<2) /* General purpose 2 */
    144 #define	 UDAV_GPR_GEPIO1	(1<<1) /* General purpose 1 */
    145 #define	 UDAV_GPR_GEPIO0	(1<<0) /* General purpose 0 */
    146 
    147 #define	GET_IFP(sc)		(&(sc)->sc_ec.ec_if)
    148 #define	GET_MII(sc)		(&(sc)->sc_mii)
    149 
    150 struct udav_chain {
    151 	struct udav_softc	*udav_sc;
    152 	usbd_xfer_handle	udav_xfer;
    153 	char			*udav_buf;
    154 	struct mbuf		*udav_mbuf;
    155 	int			udav_idx;
    156 };
    157 
    158 struct udav_cdata {
    159 	struct udav_chain	udav_tx_chain[UDAV_TX_LIST_CNT];
    160 	struct udav_chain	udav_rx_chain[UDAV_TX_LIST_CNT];
    161 #if 0
    162 	/* XXX: Intrrupt Endpoint is not yet supported! */
    163 	struct udav_intrpkg	udav_ibuf;
    164 #endif
    165 	int			udav_tx_prod;
    166 	int			udav_tx_cons;
    167 	int			udav_tx_cnt;
    168 	int			udav_rx_prod;
    169 };
    170 
    171 struct udav_softc {
    172 	USBBASEDEVICE		sc_dev;	/* base device */
    173 	usbd_device_handle	sc_udev;
    174 
    175 	/* USB */
    176 	usbd_interface_handle	sc_ctl_iface;
    177 	/* int			sc_ctl_iface_no; */
    178 	int			sc_bulkin_no; /* bulk in endpoint */
    179 	int			sc_bulkout_no; /* bulk out endpoint */
    180 	int			sc_intrin_no; /* intr in endpoint */
    181 	usbd_pipe_handle	sc_pipe_rx;
    182 	usbd_pipe_handle	sc_pipe_tx;
    183 	usbd_pipe_handle	sc_pipe_intr;
    184 	usb_callout_t		sc_stat_ch;
    185 	u_int			sc_rx_errs;
    186 	/* u_int		sc_intr_errs; */
    187 	struct timeval		sc_rx_notice;
    188 
    189 	/* Ethernet */
    190 	struct ethercom		sc_ec; /* ethernet common */
    191 	struct mii_data		sc_mii;
    192 	struct lock		sc_mii_lock;
    193 	int			sc_link;
    194 #define	sc_media udav_mii.mii_media
    195 #if NRND > 0
    196 	rndsource_element_t	rnd_source;
    197 #endif
    198 	struct udav_cdata	sc_cdata;
    199 
    200 	int                     sc_attached;
    201 	int			sc_dying;
    202         int                     sc_refcnt;
    203 
    204 	struct usb_task		sc_tick_task;
    205 	struct usb_task		sc_stop_task;
    206 
    207 	u_int16_t		sc_flags;
    208 };
    209