xref: /freebsd/sys/dev/usb/net/if_iphethvar.h (revision c992ac6213276f54d868f317cc5092f8aed4ff54)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
5  * Copyright (c) 2009 Diego Giagio. 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 
29 /*
30  * Thanks to Diego Giagio for figuring out the programming details for
31  * the Apple iPhone Ethernet driver.
32  */
33 
34 #ifndef _IF_IPHETHVAR_H_
35 #define	_IF_IPHETHVAR_H_
36 
37 #define	IPHETH_USBINTF_CLASS    255
38 #define	IPHETH_USBINTF_SUBCLASS 253
39 #define	IPHETH_USBINTF_PROTO    1
40 
41 #define	IPHETH_BUF_SIZE         1514
42 #define	IPHETH_TX_TIMEOUT       5000	/* ms */
43 
44 #define	IPHETH_RX_NCM_BUF_SIZE	 65536
45 #define	IPHETH_RX_FRAMES_MAX	1
46 #define	IPHETH_TX_FRAMES_MAX	8
47 
48 #define	IPHETH_RX_ADJ		2
49 
50 #define	IPHETH_CFG_INDEX	0
51 #define	IPHETH_IF_INDEX		2
52 #define	IPHETH_ALT_INTFNUM      1
53 
54 #define	IPHETH_CTRL_ENDP        0x00
55 #define	IPHETH_CTRL_BUF_SIZE    0x40
56 #define	IPHETH_CTRL_TIMEOUT     5000	/* ms */
57 
58 #define	IPHETH_CMD_GET_MACADDR   0x00
59 #define	IPHETH_CMD_ENABLE_NCM	 0x04
60 #define	IPHETH_CMD_CARRIER_CHECK 0x45
61 
62 #define	IPHETH_CARRIER_ON       0x04
63 
64 #define	IPHETH_NCM_DPT_DP_NUM	 22
65 #define	IPHETH_NCM_DPT_HEADER_SIZE      \
66 	(sizeof(struct usb_ncm16_dpt) + \
67 	    IPHETH_NCM_DPT_DP_NUM * sizeof(struct usb_ncm16_dp))
68 #define	IPHETH_NCM_HEADER_SIZE \
69 	(sizeof(struct usb_ncm16_hdr) + IPHETH_NCM_DPT_HEADER_SIZE)
70 
71 typedef void (ipheth_consumer_t)(struct usb_xfer *xfer, int idx);
72 
73 enum {
74 	IPHETH_BULK_TX,
75 	IPHETH_BULK_RX,
76 	IPHETH_N_TRANSFER,
77 };
78 
79 struct ipheth_softc {
80 	struct usb_ether sc_ue;
81 	struct mtx sc_mtx;
82 
83 	struct usb_xfer *sc_xfer[IPHETH_N_TRANSFER];
84 	struct mbuf *sc_rx_buf[IPHETH_RX_FRAMES_MAX];
85 	struct mbuf *sc_tx_buf[IPHETH_TX_FRAMES_MAX];
86 
87 	uint8_t	sc_data[IPHETH_CTRL_BUF_SIZE];
88 	uint8_t	sc_iface_no;
89 	uint8_t	sc_carrier_on;
90 
91 	bool is_ncm;
92 
93 	ipheth_consumer_t *consume;
94 };
95 
96 struct ncm_data_cache {
97 	struct usb_ncm16_hdr hdr;
98 	struct usb_ncm16_dpt dpt;
99 	struct usb_ncm16_dp dp[IPHETH_NCM_DPT_DP_NUM];
100 };
101 
102 #define	IPHETH_LOCK(_sc)			mtx_lock(&(_sc)->sc_mtx)
103 #define	IPHETH_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
104 #define	IPHETH_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->sc_mtx, t)
105 
106 #endif					/* _IF_IPHETHVAR_H_ */
107