xref: /netbsd-src/sys/dev/usb/if_urevar.h (revision f3cfa6f6ce31685c6c4a758bc430e69eb99f50a4)
1 /*	$NetBSD: if_urevar.h,v 1.2 2019/02/07 10:36:20 mlelstv Exp $	*/
2 /*	$OpenBSD: if_urereg.h,v 1.5 2018/11/02 21:32:30 jcs Exp $	*/
3 /*-
4  * Copyright (c) 2015-2016 Kevin Lo <kevlo@FreeBSD.org>
5  * 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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 struct ure_intrpkt {
32 	uint8_t	ure_tsr;
33 	uint8_t	ure_rsr;
34 	uint8_t	ure_gep_msr;
35 	uint8_t	ure_waksr;
36 	uint8_t	ure_txok_cnt;
37 	uint8_t	ure_rxlost_cnt;
38 	uint8_t	ure_crcerr_cnt;
39 	uint8_t	ure_col_cnt;
40 } __packed;
41 
42 struct ure_rxpkt {
43 	uint32_t ure_pktlen;
44 #define	URE_RXPKT_LEN_MASK	0x7fff
45 	uint32_t ure_csum;
46 #define URE_RXPKT_IPV4_CS	__BIT(19)
47 #define URE_RXPKT_IPV6_CS	__BIT(20)
48 #define URE_RXPKT_TCP_CS	__BIT(22)
49 #define URE_RXPKT_UDP_CS	__BIT(23)
50 	uint32_t ure_misc;
51 #define URE_RXPKT_RX_VLAN_TAG	__BIT(16)
52 #define URE_RXPKT_TCP_F		__BIT(21)
53 #define URE_RXPKT_UDP_F		__BIT(22)
54 #define URE_RXPKT_IP_F		__BIT(23)
55 	uint32_t ure_rsvd2;
56 	uint32_t ure_rsvd3;
57 	uint32_t ure_rsvd4;
58 } __packed;
59 
60 struct ure_txpkt {
61 	uint32_t ure_pktlen;
62 #define	URE_TXPKT_TX_FS		__BIT(31)
63 #define	URE_TXPKT_TX_LS		__BIT(30)
64 #define	URE_TXPKT_LEN_MASK	0xffff
65 	uint32_t ure_csum;
66 #define URE_L4_OFFSET_MAX	0x7ff
67 #define URE_L4_OFFSET_SHIFT	17
68 #define URE_TXPKT_IPV6_CS	__BIT(28)
69 #define URE_TXPKT_IPV4_CS	__BIT(29)
70 #define URE_TXPKT_TCP_CS	__BIT(30)
71 #define URE_TXPKT_UDP_CS	__BIT(31)
72 } __packed;
73 
74 #define URE_ENDPT_RX		0
75 #define URE_ENDPT_TX		1
76 #define URE_ENDPT_MAX		2
77 
78 #ifndef URE_TX_LIST_CNT
79 #define URE_TX_LIST_CNT		4
80 #endif
81 #ifndef URE_RX_LIST_CNT
82 #define URE_RX_LIST_CNT		4
83 #endif
84 
85 struct ure_chain {
86 	struct ure_softc	*uc_sc;
87 	struct usbd_xfer	*uc_xfer;
88 	char			*uc_buf;
89 };
90 
91 struct ure_cdata {
92 	struct ure_chain	tx_chain[URE_TX_LIST_CNT];
93 	struct ure_chain	rx_chain[URE_RX_LIST_CNT];
94 	int			tx_prod;
95 	int			tx_cnt;
96 };
97 
98 struct ure_softc {
99 	device_t		ure_dev;
100 	struct usbd_device	*ure_udev;
101 
102 	/* usb */
103 	struct usbd_interface	*ure_iface;
104 	struct usb_task		ure_tick_task;
105 	int			ure_ed[URE_ENDPT_MAX];
106 	struct usbd_pipe	*ure_ep[URE_ENDPT_MAX];
107 
108 	/* ethernet */
109 	struct ethercom		ure_ec;
110 #define GET_IFP(sc)		(&(sc)->ure_ec.ec_if)
111 	struct mii_data		ure_mii;
112 #define GET_MII(sc)		(&(sc)->ure_mii)
113 	kmutex_t		ure_mii_lock;
114 	int			ure_refcnt;
115 
116 	struct ure_cdata	ure_cdata;
117 	callout_t		ure_stat_ch;
118 
119 	struct timeval		ure_rx_notice;
120 	struct timeval		ure_tx_notice;
121 	u_int			ure_bufsz;
122 
123 	int			ure_phyno;
124 
125 	u_int			ure_flags;
126 #define	URE_FLAG_LINK		0x0001
127 #define	URE_FLAG_8152		0x1000	/* RTL8152 */
128 
129 	u_int			ure_chip;
130 #define	URE_CHIP_VER_4C00	0x01
131 #define	URE_CHIP_VER_4C10	0x02
132 #define	URE_CHIP_VER_5C00	0x04
133 #define	URE_CHIP_VER_5C10	0x08
134 #define	URE_CHIP_VER_5C20	0x10
135 #define	URE_CHIP_VER_5C30	0x20
136 
137 	krndsource_t            ure_rnd_source;
138 	bool			ure_dying;
139 };
140