11553Srgrimes/*-
21553Srgrimes * Copyright (c) 1997, 1998, 1999, 2000
31553Srgrimes *	Bill Paul <wpaul@ee.columbia.edu>.  All rights reserved.
41553Srgrimes *
51553Srgrimes * Redistribution and use in source and binary forms, with or without
61553Srgrimes * modification, are permitted provided that the following conditions
71553Srgrimes * are met:
81553Srgrimes * 1. Redistributions of source code must retain the above copyright
91553Srgrimes *    notice, this list of conditions and the following disclaimer.
101553Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111553Srgrimes *    notice, this list of conditions and the following disclaimer in the
121553Srgrimes *    documentation and/or other materials provided with the distribution.
131553Srgrimes * 3. All advertising materials mentioning features or use of this software
141553Srgrimes *    must display the following acknowledgement:
151553Srgrimes *	This product includes software developed by Bill Paul.
161553Srgrimes * 4. Neither the name of the author nor the names of any co-contributors
171553Srgrimes *    may be used to endorse or promote products derived from this software
181553Srgrimes *    without specific prior written permission.
191553Srgrimes *
201553Srgrimes * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
211553Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221553Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231553Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
241553Srgrimes * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
251553Srgrimes * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
261553Srgrimes * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
271553Srgrimes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
281553Srgrimes * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2950479Speter * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
301553Srgrimes * THE POSSIBILITY OF SUCH DAMAGE.
31241473Seadler *
321553Srgrimes * $FreeBSD$
331553Srgrimes */
341553Srgrimes
351553Srgrimes/*
361553Srgrimes * Definitions for the KLSI KL5KUSB101B USB to ethernet controller.
371553Srgrimes * The KLSI part is controlled via vendor control requests, the structure
381553Srgrimes * of which depend a bit on the firmware running on the internal
391553Srgrimes * microcontroller.  The one exception is the 'send scan data' command,
401553Srgrimes * which is used to load the firmware.
4125276Sjmg */
421553Srgrimes
431553Srgrimes#define	KUE_CMD_GET_ETHER_DESCRIPTOR		0x00
441553Srgrimes#define	KUE_CMD_SET_MCAST_FILTERS		0x01
455367Sjkh#define	KUE_CMD_SET_PKT_FILTER			0x02
465367Sjkh#define	KUE_CMD_GET_ETHERSTATS			0x03
475367Sjkh#define	KUE_CMD_GET_GPIO			0x04
4863795Sdwmalone#define	KUE_CMD_SET_GPIO			0x05
4963795Sdwmalone#define	KUE_CMD_SET_MAC				0x06
50155954Sjulian#define	KUE_CMD_GET_MAC				0x07
515367Sjkh#define	KUE_CMD_SET_URB_SIZE			0x08
521553Srgrimes#define	KUE_CMD_SET_SOFS			0x09
531553Srgrimes#define	KUE_CMD_SET_EVEN_PKTS			0x0A
541553Srgrimes#define	KUE_CMD_SEND_SCAN			0xFF
551553Srgrimes
561553Srgrimesstruct kue_ether_desc {
5756485Scharnier	uint8_t	kue_len;
581553Srgrimes	uint8_t	kue_rsvd0;
591553Srgrimes	uint8_t	kue_rsvd1;
601553Srgrimes	uint8_t	kue_macaddr[ETHER_ADDR_LEN];
611553Srgrimes	uint8_t	kue_etherstats[4];
621553Srgrimes	uint8_t	kue_maxseg[2];
6375169Sru	uint8_t	kue_mcastfilt[2];
641553Srgrimes	uint8_t	kue_rsvd2;
6579755Sdd} __packed;
6682470Scjc
6741498Sjkh#define	KUE_ETHERSTATS(x)	UGETDW((x)->sc_desc.kue_etherstats)
68108247Strhodes#define	KUE_MAXSEG(x)		UGETW((x)->sc_desc.kue_maxseg)
69131500Sru#define	KUE_MCFILTCNT(x)	(UGETW((x)->sc_desc.kue_mcastfilt) & 0x7FFF)
7082470Scjc#define KUE_MCFILT(x, y)	\
7157673Ssheldonh	(char *)&(sc->sc_mcfilters[y * ETHER_ADDR_LEN])
7279755Sdd
73108247Strhodes#define	KUE_STAT_TX_OK			0x00000001
7482470Scjc#define	KUE_STAT_RX_OK			0x00000002
75131500Sru#define	KUE_STAT_TX_ERR			0x00000004
7641498Sjkh#define	KUE_STAT_RX_ERR			0x00000008
771553Srgrimes#define	KUE_STAT_RX_NOBUF		0x00000010
7882470Scjc#define	KUE_STAT_TX_UCAST_BYTES		0x00000020
791553Srgrimes#define	KUE_STAT_TX_UCAST_FRAMES	0x00000040
801553Srgrimes#define	KUE_STAT_TX_MCAST_BYTES		0x00000080
8125276Sjmg#define	KUE_STAT_TX_MCAST_FRAMES	0x00000100
8225276Sjmg#define	KUE_STAT_TX_BCAST_BYTES		0x00000200
8337820Sphk#define	KUE_STAT_TX_BCAST_FRAMES	0x00000400
84107312Sru#define	KUE_STAT_RX_UCAST_BYTES		0x00000800
8525276Sjmg#define	KUE_STAT_RX_UCAST_FRAMES	0x00001000
861553Srgrimes#define	KUE_STAT_RX_MCAST_BYTES		0x00002000
871553Srgrimes#define	KUE_STAT_RX_MCAST_FRAMES	0x00004000
881553Srgrimes#define	KUE_STAT_RX_BCAST_BYTES		0x00008000
891553Srgrimes#define	KUE_STAT_RX_BCAST_FRAMES	0x00010000
901553Srgrimes#define	KUE_STAT_RX_CRCERR		0x00020000
911553Srgrimes#define	KUE_STAT_TX_QUEUE_LENGTH	0x00040000
921553Srgrimes#define	KUE_STAT_RX_ALIGNERR		0x00080000
931553Srgrimes#define	KUE_STAT_TX_SINGLECOLL		0x00100000
941553Srgrimes#define	KUE_STAT_TX_MULTICOLL		0x00200000
951553Srgrimes#define	KUE_STAT_TX_DEFERRED		0x00400000
961553Srgrimes#define	KUE_STAT_TX_MAXCOLLS		0x00800000
97163255Strhodes#define	KUE_STAT_RX_OVERRUN		0x01000000
98163255Strhodes#define	KUE_STAT_TX_UNDERRUN		0x02000000
99163255Strhodes#define	KUE_STAT_TX_SQE_ERR		0x04000000
100163255Strhodes#define	KUE_STAT_TX_CARRLOSS		0x08000000
101163255Strhodes#define	KUE_STAT_RX_LATECOLL		0x10000000
102163255Strhodes
103163255Strhodes#define	KUE_RXFILT_PROMISC		0x0001
104108247Strhodes#define	KUE_RXFILT_ALLMULTI		0x0002
1051553Srgrimes#define	KUE_RXFILT_UNICAST		0x0004
1061553Srgrimes#define	KUE_RXFILT_BROADCAST		0x0008
1071553Srgrimes#define	KUE_RXFILT_MULTICAST		0x0010
1081553Srgrimes
1091553Srgrimes#define	KUE_TIMEOUT		1000
1101553Srgrimes#define	KUE_MIN_FRAMELEN	60
1111553Srgrimes
1121553Srgrimes#define	KUE_CTL_READ		0x01
1131553Srgrimes#define	KUE_CTL_WRITE		0x02
11437820Sphk
11537820Sphk#define	KUE_CONFIG_IDX		0	/* config number 1 */
116108247Strhodes#define	KUE_IFACE_IDX		0
11737820Sphk
11837820Sphk/* The interrupt endpoint is currently unused by the KLSI part. */
11971898Sru#define	KUE_ENDPT_MAX		4
12037820Sphkenum {
12137820Sphk	KUE_BULK_DT_WR,
122108247Strhodes	KUE_BULK_DT_RD,
123108247Strhodes	KUE_N_TRANSFER,
1241553Srgrimes};
12537820Sphk
126102940Sdwmalonestruct kue_softc {
127107312Sru	struct usb_ether	sc_ue;
128102940Sdwmalone	struct mtx		sc_mtx;
129102940Sdwmalone	struct kue_ether_desc	sc_desc;
130102940Sdwmalone	struct usb_xfer	*sc_xfer[KUE_N_TRANSFER];
131102940Sdwmalone	uint8_t			*sc_mcfilters;
132102940Sdwmalone
133102940Sdwmalone	int			sc_flags;
134102940Sdwmalone#define	KUE_FLAG_LINK		0x0001
13537820Sphk
13637820Sphk	uint16_t		sc_rxfilt;
13737820Sphk};
1381553Srgrimes
139163255Strhodes#define	KUE_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
140186440Strhodes#define	KUE_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
141163255Strhodes#define	KUE_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->sc_mtx, t)
142163255Strhodes