xref: /third_party/FreeBSD/sys/dev/usb/net/if_cdcereg.h (revision f9f848fa)
1/*-
2 * SPDX-License-Identifier: BSD-4-Clause
3 *
4 * Copyright (c) 2003-2005 Craig Boston
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 * 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, THE VOICES IN HIS HEAD OR
26 * THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef _USB_IF_CDCEREG_H_
36#define	_USB_IF_CDCEREG_H_
37
38/*************************************************************/
39#define	ETHER_TYPE_LEN		2			/* length of the Ethernet type field */
40#define	ETHER_HDR_LEN		(NETIF_MAX_HWADDR_LEN*2+ETHER_TYPE_LEN)
41/*
42 * Mbuf adjust factor to force 32-bit alignment of IP header.
43 * Drivers should do m_adj(m, ETHER_ALIGN) when setting up a
44 * receive so the upper layers get the IP header properly aligned
45 * past the 14-byte Ethernet header.
46 */
47#define	ETHER_ALIGN		2				/* driver adjust for IP hdr alignment */
48
49#define CDCE_BIT(x) (1 << (x))
50
51#define	CDCE_FRAMES_MAX	8				/* units */
52#define	CDCE_IND_SIZE_MAX 32			/* bytes */
53
54#define	CDCE_NCM_TX_MINLEN 512			/* bytes, must be power of two */
55#define	CDCE_NCM_TX_MAXLEN	(16384 + 4)	/* bytes, must be short terminated */
56#define	CDCE_NCM_TX_FRAMES_MAX 8		/* units */
57
58#define	CDCE_NCM_RX_MAXLEN	(1UL << 14)	/* bytes */
59#define	CDCE_NCM_RX_FRAMES_MAX 1		/* units */
60
61#define	CDCE_NCM_SUBFRAMES_MAX 32		/* units */
62
63#define	CDCE_NCM_ALIGN(rem,off,mod) \
64	((uint32_t)(((uint32_t)(rem)) - \
65	((uint32_t)((-(uint32_t)(off)) & (-(uint32_t)(mod))))))
66#define	CDCE_HAVE_NCM 0
67
68#ifndef CDCE_HAVE_NCM
69#define	CDCE_HAVE_NCM 1
70#endif
71
72enum {
73	CDCE_BULK_RX,
74	CDCE_BULK_TX,
75	CDCE_INTR_RX,
76	CDCE_INTR_TX,
77	CDCE_N_TRANSFER,
78};
79
80struct cdce_ncm {
81	struct usb_ncm16_hdr hdr;
82	struct usb_ncm16_dpt dpt;
83	struct usb_ncm16_dp dp[CDCE_NCM_SUBFRAMES_MAX];
84	uint32_t rx_max;
85	uint32_t tx_max;
86	uint16_t tx_remainder;
87	uint16_t tx_modulus;
88	uint16_t tx_struct_align;
89	uint16_t tx_seq;
90	uint16_t tx_nframe;
91};
92
93struct cdce_softc {
94	struct usb_ether	sc_ue;
95	struct mtx		sc_mtx;
96#if CDCE_HAVE_NCM
97	struct cdce_ncm		sc_ncm;
98#endif
99	struct usb_xfer	*sc_xfer[CDCE_N_TRANSFER];
100	struct pbuf		*sc_rx_buf[CDCE_FRAMES_MAX];
101	struct pbuf		*sc_tx_buf[CDCE_FRAMES_MAX];
102
103	int			 sc_flags;
104#define	CDCE_FLAG_ZAURUS	0x0001
105#define	CDCE_FLAG_NO_UNION	0x0002
106#define	CDCE_FLAG_RX_DATA	0x0010
107#define	CDCE_FLAG_VLAN		0x0020
108
109	uint8_t sc_eaddr_str_index;
110	uint8_t	sc_ifaces_index[2];
111	uint8_t sc_notify_state;
112#define	CDCE_NOTIFY_NETWORK_CONNECTION  0
113#define	CDCE_NOTIFY_SPEED_CHANGE	1
114#define	CDCE_NOTIFY_DONE	2
115};
116
117/*
118 * Taken from USB CDC Subclass Specification for Ethernet Devices v1.2,
119 * section 6.2.4.
120 */
121
122#define	CDC_SET_ETHERNET_PACKET_FILTER	0x43	/* Command code. */
123
124#define	CDC_PACKET_TYPE_PROMISC		CDCE_BIT(0)
125#define	CDC_PACKET_TYPE_ALL_MULTICAST	CDCE_BIT(1)	/* Allmulti. */
126#define	CDC_PACKET_TYPE_DIRECTED	CDCE_BIT(2)	/* Filter unicast by mac. */
127#define	CDC_PACKET_TYPE_BROADCAST	CDCE_BIT(3)
128#define	CDC_PACKET_TYPE_MULTICAST	CDCE_BIT(4)	/* Multicast filtering, not supported. */
129
130/*
131 * Structure of a DEC/Intel/Xerox or 802.3 Ethernet header.
132 */
133struct	ether_header {
134	uint8_t	ether_dhost[NETIF_MAX_HWADDR_LEN];
135	uint8_t	ether_shost[NETIF_MAX_HWADDR_LEN];
136	uint16_t	ether_type;
137};
138
139#define	CDCE_LOCK(_sc)				mtx_lock(&(_sc)->sc_mtx)
140#define	CDCE_UNLOCK(_sc)			mtx_unlock(&(_sc)->sc_mtx)
141#define	CDCE_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->sc_mtx, t)
142#endif					/* _USB_IF_CDCEREG_H_ */
143