1184610Salfred/*-
2184610Salfred * Copyright (c) 1997, 1998, 1999, 2000
3184610Salfred *	Bill Paul <wpaul@ee.columbia.edu>.  All rights reserved.
4184610Salfred *
5184610Salfred * Redistribution and use in source and binary forms, with or without
6184610Salfred * modification, are permitted provided that the following conditions
7184610Salfred * are met:
8184610Salfred * 1. Redistributions of source code must retain the above copyright
9184610Salfred *    notice, this list of conditions and the following disclaimer.
10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright
11184610Salfred *    notice, this list of conditions and the following disclaimer in the
12184610Salfred *    documentation and/or other materials provided with the distribution.
13184610Salfred * 3. All advertising materials mentioning features or use of this software
14184610Salfred *    must display the following acknowledgement:
15184610Salfred *	This product includes software developed by Bill Paul.
16184610Salfred * 4. Neither the name of the author nor the names of any co-contributors
17184610Salfred *    may be used to endorse or promote products derived from this software
18184610Salfred *    without specific prior written permission.
19184610Salfred *
20184610Salfred * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23184610Salfred * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24184610Salfred * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25184610Salfred * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26184610Salfred * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27184610Salfred * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28184610Salfred * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29184610Salfred * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30184610Salfred * THE POSSIBILITY OF SUCH DAMAGE.
31184610Salfred *
32184610Salfred * $FreeBSD$
33184610Salfred */
34184610Salfred
35184610Salfred/*
36184610Salfred * Definitions for the KLSI KL5KUSB101B USB to ethernet controller.
37184610Salfred * The KLSI part is controlled via vendor control requests, the structure
38184610Salfred * of which depend a bit on the firmware running on the internal
39184610Salfred * microcontroller.  The one exception is the 'send scan data' command,
40184610Salfred * which is used to load the firmware.
41184610Salfred */
42184610Salfred
43184610Salfred#define	KUE_CMD_GET_ETHER_DESCRIPTOR		0x00
44184610Salfred#define	KUE_CMD_SET_MCAST_FILTERS		0x01
45184610Salfred#define	KUE_CMD_SET_PKT_FILTER			0x02
46184610Salfred#define	KUE_CMD_GET_ETHERSTATS			0x03
47184610Salfred#define	KUE_CMD_GET_GPIO			0x04
48184610Salfred#define	KUE_CMD_SET_GPIO			0x05
49184610Salfred#define	KUE_CMD_SET_MAC				0x06
50184610Salfred#define	KUE_CMD_GET_MAC				0x07
51184610Salfred#define	KUE_CMD_SET_URB_SIZE			0x08
52184610Salfred#define	KUE_CMD_SET_SOFS			0x09
53184610Salfred#define	KUE_CMD_SET_EVEN_PKTS			0x0A
54184610Salfred#define	KUE_CMD_SEND_SCAN			0xFF
55184610Salfred
56184610Salfredstruct kue_ether_desc {
57184610Salfred	uint8_t	kue_len;
58184610Salfred	uint8_t	kue_rsvd0;
59184610Salfred	uint8_t	kue_rsvd1;
60184610Salfred	uint8_t	kue_macaddr[ETHER_ADDR_LEN];
61184610Salfred	uint8_t	kue_etherstats[4];
62184610Salfred	uint8_t	kue_maxseg[2];
63184610Salfred	uint8_t	kue_mcastfilt[2];
64184610Salfred	uint8_t	kue_rsvd2;
65184610Salfred} __packed;
66184610Salfred
67184610Salfred#define	KUE_ETHERSTATS(x)	UGETDW((x)->sc_desc.kue_etherstats)
68184610Salfred#define	KUE_MAXSEG(x)		UGETW((x)->sc_desc.kue_maxseg)
69184610Salfred#define	KUE_MCFILTCNT(x)	(UGETW((x)->sc_desc.kue_mcastfilt) & 0x7FFF)
70188412Sthompsa#define KUE_MCFILT(x, y)	\
71188412Sthompsa	(char *)&(sc->sc_mcfilters[y * ETHER_ADDR_LEN])
72184610Salfred
73184610Salfred#define	KUE_STAT_TX_OK			0x00000001
74184610Salfred#define	KUE_STAT_RX_OK			0x00000002
75184610Salfred#define	KUE_STAT_TX_ERR			0x00000004
76184610Salfred#define	KUE_STAT_RX_ERR			0x00000008
77184610Salfred#define	KUE_STAT_RX_NOBUF		0x00000010
78184610Salfred#define	KUE_STAT_TX_UCAST_BYTES		0x00000020
79184610Salfred#define	KUE_STAT_TX_UCAST_FRAMES	0x00000040
80184610Salfred#define	KUE_STAT_TX_MCAST_BYTES		0x00000080
81184610Salfred#define	KUE_STAT_TX_MCAST_FRAMES	0x00000100
82184610Salfred#define	KUE_STAT_TX_BCAST_BYTES		0x00000200
83184610Salfred#define	KUE_STAT_TX_BCAST_FRAMES	0x00000400
84184610Salfred#define	KUE_STAT_RX_UCAST_BYTES		0x00000800
85184610Salfred#define	KUE_STAT_RX_UCAST_FRAMES	0x00001000
86184610Salfred#define	KUE_STAT_RX_MCAST_BYTES		0x00002000
87184610Salfred#define	KUE_STAT_RX_MCAST_FRAMES	0x00004000
88184610Salfred#define	KUE_STAT_RX_BCAST_BYTES		0x00008000
89184610Salfred#define	KUE_STAT_RX_BCAST_FRAMES	0x00010000
90184610Salfred#define	KUE_STAT_RX_CRCERR		0x00020000
91184610Salfred#define	KUE_STAT_TX_QUEUE_LENGTH	0x00040000
92184610Salfred#define	KUE_STAT_RX_ALIGNERR		0x00080000
93184610Salfred#define	KUE_STAT_TX_SINGLECOLL		0x00100000
94184610Salfred#define	KUE_STAT_TX_MULTICOLL		0x00200000
95184610Salfred#define	KUE_STAT_TX_DEFERRED		0x00400000
96184610Salfred#define	KUE_STAT_TX_MAXCOLLS		0x00800000
97184610Salfred#define	KUE_STAT_RX_OVERRUN		0x01000000
98184610Salfred#define	KUE_STAT_TX_UNDERRUN		0x02000000
99184610Salfred#define	KUE_STAT_TX_SQE_ERR		0x04000000
100184610Salfred#define	KUE_STAT_TX_CARRLOSS		0x08000000
101184610Salfred#define	KUE_STAT_RX_LATECOLL		0x10000000
102184610Salfred
103184610Salfred#define	KUE_RXFILT_PROMISC		0x0001
104184610Salfred#define	KUE_RXFILT_ALLMULTI		0x0002
105184610Salfred#define	KUE_RXFILT_UNICAST		0x0004
106184610Salfred#define	KUE_RXFILT_BROADCAST		0x0008
107184610Salfred#define	KUE_RXFILT_MULTICAST		0x0010
108184610Salfred
109184610Salfred#define	KUE_TIMEOUT		1000
110184610Salfred#define	KUE_MIN_FRAMELEN	60
111184610Salfred
112184610Salfred#define	KUE_CTL_READ		0x01
113184610Salfred#define	KUE_CTL_WRITE		0x02
114184610Salfred
115184610Salfred#define	KUE_CONFIG_IDX		0	/* config number 1 */
116184610Salfred#define	KUE_IFACE_IDX		0
117184610Salfred
118184610Salfred/* The interrupt endpoint is currently unused by the KLSI part. */
119184610Salfred#define	KUE_ENDPT_MAX		4
120187259Sthompsaenum {
121187259Sthompsa	KUE_BULK_DT_WR,
122187259Sthompsa	KUE_BULK_DT_RD,
123188412Sthompsa	KUE_N_TRANSFER,
124187259Sthompsa};
125184610Salfred
126184610Salfredstruct kue_softc {
127192984Sthompsa	struct usb_ether	sc_ue;
128188412Sthompsa	struct mtx		sc_mtx;
129188412Sthompsa	struct kue_ether_desc	sc_desc;
130192984Sthompsa	struct usb_xfer	*sc_xfer[KUE_N_TRANSFER];
131188412Sthompsa	uint8_t			*sc_mcfilters;
132184610Salfred
133188412Sthompsa	int			sc_flags;
134188412Sthompsa#define	KUE_FLAG_LINK		0x0001
135184610Salfred
136188412Sthompsa	uint16_t		sc_rxfilt;
137188412Sthompsa};
138184610Salfred
139188412Sthompsa#define	KUE_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
140188412Sthompsa#define	KUE_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
141188412Sthompsa#define	KUE_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->sc_mtx, t)
142