xref: /freebsd/sys/dev/usb/net/if_iphethvar.h (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
1 /* $FreeBSD$ */
2 /*-
3  * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
4  * Copyright (c) 2009 Diego Giagio. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 /*
29  * Thanks to Diego Giagio for figuring out the programming details for
30  * the Apple iPhone Ethernet driver.
31  */
32 
33 #ifndef _IF_IPHETHVAR_H_
34 #define	_IF_IPHETHVAR_H_
35 
36 #define	IPHETH_USBINTF_CLASS    255
37 #define	IPHETH_USBINTF_SUBCLASS 253
38 #define	IPHETH_USBINTF_PROTO    1
39 
40 #define	IPHETH_BUF_SIZE         1516
41 #define	IPHETH_TX_TIMEOUT       5000	/* ms */
42 
43 #define	IPHETH_RX_FRAMES_MAX	1
44 #define	IPHETH_TX_FRAMES_MAX	8
45 
46 #define	IPHETH_RX_ADJ		2
47 
48 #define	IPHETH_CFG_INDEX	0
49 #define	IPHETH_IF_INDEX		2
50 #define	IPHETH_ALT_INTFNUM      1
51 
52 #define	IPHETH_CTRL_ENDP        0x00
53 #define	IPHETH_CTRL_BUF_SIZE    0x40
54 #define	IPHETH_CTRL_TIMEOUT     5000	/* ms */
55 
56 #define	IPHETH_CMD_GET_MACADDR   0x00
57 #define	IPHETH_CMD_CARRIER_CHECK 0x45
58 
59 #define	IPHETH_CARRIER_ON       0x04
60 
61 enum {
62 	IPHETH_BULK_TX,
63 	IPHETH_BULK_RX,
64 	IPHETH_N_TRANSFER,
65 };
66 
67 struct ipheth_softc {
68 	struct usb_ether sc_ue;
69 	struct mtx sc_mtx;
70 
71 	struct usb_xfer *sc_xfer[IPHETH_N_TRANSFER];
72 	struct mbuf *sc_rx_buf[IPHETH_RX_FRAMES_MAX];
73 	struct mbuf *sc_tx_buf[IPHETH_TX_FRAMES_MAX];
74 
75 	uint8_t	sc_data[IPHETH_CTRL_BUF_SIZE];
76 	uint8_t	sc_iface_no;
77 	uint8_t	sc_carrier_on;
78 };
79 
80 #define	IPHETH_LOCK(_sc)			mtx_lock(&(_sc)->sc_mtx)
81 #define	IPHETH_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
82 #define	IPHETH_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->sc_mtx, t)
83 
84 #endif					/* _IF_IPHETHVAR_H_ */
85