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