xref: /freebsd/sys/dev/usb/net/if_kuereg.h (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
1 /*-
2  * SPDX-License-Identifier: BSD-4-Clause
3  *
4  * Copyright (c) 1997, 1998, 1999, 2000
5  *	Bill Paul <wpaul@ee.columbia.edu>.  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 Bill Paul.
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 Bill Paul 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 Bill Paul OR THE VOICES IN HIS HEAD
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $FreeBSD$
35  */
36 
37 /*
38  * Definitions for the KLSI KL5KUSB101B USB to ethernet controller.
39  * The KLSI part is controlled via vendor control requests, the structure
40  * of which depend a bit on the firmware running on the internal
41  * microcontroller.  The one exception is the 'send scan data' command,
42  * which is used to load the firmware.
43  */
44 
45 #define	KUE_CMD_GET_ETHER_DESCRIPTOR		0x00
46 #define	KUE_CMD_SET_MCAST_FILTERS		0x01
47 #define	KUE_CMD_SET_PKT_FILTER			0x02
48 #define	KUE_CMD_GET_ETHERSTATS			0x03
49 #define	KUE_CMD_GET_GPIO			0x04
50 #define	KUE_CMD_SET_GPIO			0x05
51 #define	KUE_CMD_SET_MAC				0x06
52 #define	KUE_CMD_GET_MAC				0x07
53 #define	KUE_CMD_SET_URB_SIZE			0x08
54 #define	KUE_CMD_SET_SOFS			0x09
55 #define	KUE_CMD_SET_EVEN_PKTS			0x0A
56 #define	KUE_CMD_SEND_SCAN			0xFF
57 
58 struct kue_ether_desc {
59 	uint8_t	kue_len;
60 	uint8_t	kue_rsvd0;
61 	uint8_t	kue_rsvd1;
62 	uint8_t	kue_macaddr[ETHER_ADDR_LEN];
63 	uint8_t	kue_etherstats[4];
64 	uint8_t	kue_maxseg[2];
65 	uint8_t	kue_mcastfilt[2];
66 	uint8_t	kue_rsvd2;
67 } __packed;
68 
69 #define	KUE_ETHERSTATS(x)	UGETDW((x)->sc_desc.kue_etherstats)
70 #define	KUE_MAXSEG(x)		UGETW((x)->sc_desc.kue_maxseg)
71 #define	KUE_MCFILTCNT(x)	(UGETW((x)->sc_desc.kue_mcastfilt) & 0x7FFF)
72 #define KUE_MCFILT(x, y)	\
73 	(char *)&(sc->sc_mcfilters[y * ETHER_ADDR_LEN])
74 
75 #define	KUE_STAT_TX_OK			0x00000001
76 #define	KUE_STAT_RX_OK			0x00000002
77 #define	KUE_STAT_TX_ERR			0x00000004
78 #define	KUE_STAT_RX_ERR			0x00000008
79 #define	KUE_STAT_RX_NOBUF		0x00000010
80 #define	KUE_STAT_TX_UCAST_BYTES		0x00000020
81 #define	KUE_STAT_TX_UCAST_FRAMES	0x00000040
82 #define	KUE_STAT_TX_MCAST_BYTES		0x00000080
83 #define	KUE_STAT_TX_MCAST_FRAMES	0x00000100
84 #define	KUE_STAT_TX_BCAST_BYTES		0x00000200
85 #define	KUE_STAT_TX_BCAST_FRAMES	0x00000400
86 #define	KUE_STAT_RX_UCAST_BYTES		0x00000800
87 #define	KUE_STAT_RX_UCAST_FRAMES	0x00001000
88 #define	KUE_STAT_RX_MCAST_BYTES		0x00002000
89 #define	KUE_STAT_RX_MCAST_FRAMES	0x00004000
90 #define	KUE_STAT_RX_BCAST_BYTES		0x00008000
91 #define	KUE_STAT_RX_BCAST_FRAMES	0x00010000
92 #define	KUE_STAT_RX_CRCERR		0x00020000
93 #define	KUE_STAT_TX_QUEUE_LENGTH	0x00040000
94 #define	KUE_STAT_RX_ALIGNERR		0x00080000
95 #define	KUE_STAT_TX_SINGLECOLL		0x00100000
96 #define	KUE_STAT_TX_MULTICOLL		0x00200000
97 #define	KUE_STAT_TX_DEFERRED		0x00400000
98 #define	KUE_STAT_TX_MAXCOLLS		0x00800000
99 #define	KUE_STAT_RX_OVERRUN		0x01000000
100 #define	KUE_STAT_TX_UNDERRUN		0x02000000
101 #define	KUE_STAT_TX_SQE_ERR		0x04000000
102 #define	KUE_STAT_TX_CARRLOSS		0x08000000
103 #define	KUE_STAT_RX_LATECOLL		0x10000000
104 
105 #define	KUE_RXFILT_PROMISC		0x0001
106 #define	KUE_RXFILT_ALLMULTI		0x0002
107 #define	KUE_RXFILT_UNICAST		0x0004
108 #define	KUE_RXFILT_BROADCAST		0x0008
109 #define	KUE_RXFILT_MULTICAST		0x0010
110 
111 #define	KUE_TIMEOUT		1000
112 #define	KUE_MIN_FRAMELEN	60
113 
114 #define	KUE_CTL_READ		0x01
115 #define	KUE_CTL_WRITE		0x02
116 
117 #define	KUE_CONFIG_IDX		0	/* config number 1 */
118 #define	KUE_IFACE_IDX		0
119 
120 /* The interrupt endpoint is currently unused by the KLSI part. */
121 #define	KUE_ENDPT_MAX		4
122 enum {
123 	KUE_BULK_DT_WR,
124 	KUE_BULK_DT_RD,
125 	KUE_N_TRANSFER,
126 };
127 
128 struct kue_softc {
129 	struct usb_ether	sc_ue;
130 	struct mtx		sc_mtx;
131 	struct kue_ether_desc	sc_desc;
132 	struct usb_xfer	*sc_xfer[KUE_N_TRANSFER];
133 	uint8_t			*sc_mcfilters;
134 
135 	int			sc_flags;
136 #define	KUE_FLAG_LINK		0x0001
137 
138 	uint16_t		sc_rxfilt;
139 };
140 
141 #define	KUE_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
142 #define	KUE_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
143 #define	KUE_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->sc_mtx, t)
144