Home | History | Annotate | Line # | Download | only in usb
if_kuereg.h revision 1.1
      1 /*	$NetBSD: if_kuereg.h,v 1.1 2000/01/17 01:38:43 augustss Exp $	*/
      2 /*
      3  * Copyright (c) 1997, 1998, 1999, 2000
      4  *	Bill Paul <wpaul (at) ee.columbia.edu>.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Bill Paul.
     17  * 4. Neither the name of the author nor the names of any co-contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
     25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     31  * THE POSSIBILITY OF SUCH DAMAGE.
     32  *
     33  * $FreeBSD: src/sys/dev/usb/if_kuereg.h,v 1.2 2000/01/06 07:39:07 wpaul Exp $
     34  */
     35 
     36 /*
     37  * Definitions for the KLSI KL5KUSB101B USB to ethernet controller.
     38  * The KLSI part is controlled via vendor control requests, the structure
     39  * of which depend a bit on the firmware running on the internal
     40  * microcontroller. The one exception is the 'send scan data' command,
     41  * which is used to load the firmware.
     42  */
     43 
     44 #define KUE_CONFIG_NO		1
     45 #define KUE_IFACE_IDX		0
     46 
     47 #define KUE_CMD_GET_ETHER_DESCRIPTOR		0x00
     48 #define KUE_CMD_SET_MCAST_FILTERS		0x01
     49 #define KUE_CMD_SET_PKT_FILTER			0x02
     50 #define KUE_CMD_GET_ETHERSTATS			0x03
     51 #define KUE_CMD_GET_GPIO			0x04
     52 #define KUE_CMD_SET_GPIO			0x05
     53 #define KUE_CMD_SET_MAC				0x06
     54 #define KUE_CMD_GET_MAC				0x07
     55 #define KUE_CMD_SET_URB_SIZE			0x08
     56 #define KUE_CMD_SET_SOFS			0x09
     57 #define KUE_CMD_SET_EVEN_PKTS			0x0A
     58 #define KUE_CMD_SEND_SCAN			0xFF
     59 
     60 struct kue_ether_desc {
     61 	u_int8_t		kue_len;
     62 	u_int8_t		kue_rsvd0;
     63 	u_int8_t		kue_rsvd1;
     64 	u_int8_t		kue_macaddr[ETHER_ADDR_LEN];
     65 	u_int8_t		kue_etherstats[4];
     66 	u_int8_t		kue_maxseg[2];
     67 	u_int8_t		kue_mcastfilt[2];
     68 	u_int8_t		kue_rsvd2;
     69 };
     70 
     71 #define KUE_ETHERSTATS(x)	\
     72 	(*(u_int32_t *)&(x)->kue_desc.kue_etherstats)
     73 #define KUE_MAXSEG(x)		\
     74 	(*(u_int16_t *)&(x)->kue_desc.kue_maxseg)
     75 #define KUE_MCFILTCNT(x)	\
     76 	((*(u_int16_t *)&(x)->kue_desc.kue_mcastfilt) & 0x7FFF)
     77 #define KUE_MCFILT(x, y)	\
     78 	(char *)&(sc->kue_mcfilters[y * ETHER_ADDR_LEN])
     79 
     80 #define KUE_STAT_TX_OK			0x00000001
     81 #define KUE_STAT_RX_OK			0x00000002
     82 #define KUE_STAT_TX_ERR			0x00000004
     83 #define KUE_STAT_RX_ERR			0x00000008
     84 #define KUE_STAT_RX_NOBUF		0x00000010
     85 #define KUE_STAT_TX_UCAST_BYTES		0x00000020
     86 #define KUE_STAT_TX_UCAST_FRAMES	0x00000040
     87 #define KUE_STAT_TX_MCAST_BYTES		0x00000080
     88 #define KUE_STAT_TX_MCAST_FRAMES	0x00000100
     89 #define KUE_STAT_TX_BCAST_BYTES		0x00000200
     90 #define KUE_STAT_TX_BCAST_FRAMES	0x00000400
     91 #define KUE_STAT_RX_UCAST_BYTES		0x00000800
     92 #define KUE_STAT_RX_UCAST_FRAMES	0x00001000
     93 #define KUE_STAT_RX_MCAST_BYTES		0x00002000
     94 #define KUE_STAT_RX_MCAST_FRAMES	0x00004000
     95 #define KUE_STAT_RX_BCAST_BYTES		0x00008000
     96 #define KUE_STAT_RX_BCAST_FRAMES	0x00010000
     97 #define KUE_STAT_RX_CRCERR		0x00020000
     98 #define KUE_STAT_TX_QUEUE_LENGTH	0x00040000
     99 #define KUE_STAT_RX_ALIGNERR		0x00080000
    100 #define KUE_STAT_TX_SINGLECOLL		0x00100000
    101 #define KUE_STAT_TX_MULTICOLL		0x00200000
    102 #define KUE_STAT_TX_DEFERRED		0x00400000
    103 #define KUE_STAT_TX_MAXCOLLS		0x00800000
    104 #define KUE_STAT_RX_OVERRUN		0x01000000
    105 #define KUE_STAT_TX_UNDERRUN		0x02000000
    106 #define KUE_STAT_TX_SQE_ERR		0x04000000
    107 #define KUE_STAT_TX_CARRLOSS		0x08000000
    108 #define KUE_STAT_RX_LATECOLL		0x10000000
    109 
    110 #define KUE_RXFILT_PROMISC		0x0001
    111 #define KUE_RXFILT_ALLMULTI		0x0002
    112 #define KUE_RXFILT_UNICAST		0x0004
    113 #define KUE_RXFILT_BROADCAST		0x0008
    114 #define KUE_RXFILT_MULTICAST		0x0010
    115 
    116 #define KUE_TIMEOUT		1000
    117 #define ETHER_ALIGN		2
    118 #define KUE_BUFSZ		1536
    119 #define KUE_CUTOFF		1088
    120 #define KUE_MIN_FRAMELEN	60
    121 
    122 #define KUE_RX_LIST_CNT		1
    123 #define KUE_TX_LIST_CNT		1
    124 
    125 #define KUE_CTL_READ		0x01
    126 #define KUE_CTL_WRITE		0x02
    127 
    128 /*
    129  * The interrupt endpoint is currently unused
    130  * by the KLSI part.
    131  */
    132 #define KUE_ENDPT_RX		0x0
    133 #define KUE_ENDPT_TX		0x1
    134 #define KUE_ENDPT_INTR		0x2
    135 #define KUE_ENDPT_MAX		0x3
    136 
    137 struct kue_type {
    138 	u_int16_t		kue_vid;
    139 	u_int16_t		kue_did;
    140 };
    141 
    142 struct kue_softc;
    143 
    144 struct kue_chain {
    145 	struct kue_softc	*kue_sc;
    146 	usbd_xfer_handle	kue_xfer;
    147 	char			*kue_buf;
    148 	struct mbuf		*kue_mbuf;
    149 	int			kue_idx;
    150 };
    151 
    152 struct kue_cdata {
    153 	struct kue_chain	kue_tx_chain[KUE_TX_LIST_CNT];
    154 	struct kue_chain	kue_rx_chain[KUE_RX_LIST_CNT];
    155 	int			kue_tx_prod;
    156 	int			kue_tx_cons;
    157 	int			kue_tx_cnt;
    158 	int			kue_rx_prod;
    159 };
    160 
    161 #define KUE_INC(x, y)		(x) = (x + 1) % y
    162 
    163 struct kue_softc {
    164 	USBBASEDEVICE		kue_dev;
    165 
    166 #if defined(__FreeBSD__)
    167 	struct arpcom		arpcom;
    168 	struct callout_handle	kue_stat_ch;
    169 #define GET_IFP(sc) (&(sc)->arpcom.ac_if)
    170 #elif defined(__NetBSD__)
    171 	struct ethercom		kue_ec;
    172 	char			kue_dying;
    173 #define GET_IFP(sc) (&(sc)->kue_ec.ec_if)
    174 #endif
    175 
    176 	u_int16_t		kue_xfer_flags;
    177 
    178 	usbd_device_handle	kue_udev;
    179 	usbd_interface_handle	kue_iface;
    180 	u_int16_t		kue_vendor;
    181 	u_int16_t		kue_product;
    182 	struct kue_ether_desc	kue_desc;
    183 	int			kue_ed[KUE_ENDPT_MAX];
    184 	usbd_pipe_handle	kue_ep[KUE_ENDPT_MAX];
    185 	int			kue_if_flags;
    186 	u_int16_t		kue_rxfilt;
    187 	u_int8_t		*kue_mcfilters;
    188 	struct kue_cdata	kue_cdata;
    189 };
    190