1184610Salfred/*-
2184610Salfred * Copyright (c) 2003-2005 Craig Boston
3184610Salfred * All rights reserved.
4184610Salfred *
5184610Salfred * Redistribution and use in source and binary forms, with or without
6184610Salfred * modification, are permitted provided that the following conditions
7184610Salfred * are met:
8184610Salfred * 1. Redistributions of source code must retain the above copyright
9184610Salfred *    notice, this list of conditions and the following disclaimer.
10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright
11184610Salfred *    notice, this list of conditions and the following disclaimer in the
12184610Salfred *    documentation and/or other materials provided with the distribution.
13184610Salfred * 3. All advertising materials mentioning features or use of this software
14184610Salfred *    must display the following acknowledgement:
15184610Salfred *      This product includes software developed by Bill Paul.
16184610Salfred * 4. Neither the name of the author nor the names of any co-contributors
17184610Salfred *    may be used to endorse or promote products derived from this software
18184610Salfred *    without specific prior written permission.
19184610Salfred *
20184610Salfred * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23184610Salfred * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul, THE VOICES IN HIS HEAD OR
24184610Salfred * THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25184610Salfred * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26184610Salfred * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27184610Salfred * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28184610Salfred * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29184610Salfred * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30184610Salfred * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31184610Salfred *
32184610Salfred * $FreeBSD$
33184610Salfred */
34184610Salfred
35184610Salfred#ifndef _USB_IF_CDCEREG_H_
36184610Salfred#define	_USB_IF_CDCEREG_H_
37184610Salfred
38188412Sthompsa#define	CDCE_FRAMES_MAX	8		/* units */
39188412Sthompsa#define	CDCE_IND_SIZE_MAX 32            /* bytes */
40184610Salfred
41213809Shselasky#define	CDCE_NCM_TX_MINLEN 512		/* bytes, must be power of two */
42221077Shselasky#define	CDCE_NCM_TX_MAXLEN (16384 + 4)	/* bytes, must be short terminated */
43197563Sthompsa#define	CDCE_NCM_TX_FRAMES_MAX 8	/* units */
44197563Sthompsa
45197563Sthompsa#define	CDCE_NCM_RX_MAXLEN (1UL << 14)	/* bytes */
46197563Sthompsa#define	CDCE_NCM_RX_FRAMES_MAX 1	/* units */
47197563Sthompsa
48197563Sthompsa#define	CDCE_NCM_SUBFRAMES_MAX 32	/* units */
49197563Sthompsa
50213809Shselasky#define	CDCE_NCM_ALIGN(rem,off,mod) \
51213809Shselasky    ((uint32_t)(((uint32_t)(rem)) - \
52213809Shselasky    ((uint32_t)((-(uint32_t)(off)) & (-(uint32_t)(mod))))))
53213809Shselasky
54197563Sthompsa#ifndef CDCE_HAVE_NCM
55197563Sthompsa#define	CDCE_HAVE_NCM 1
56197563Sthompsa#endif
57197563Sthompsa
58187259Sthompsaenum {
59190734Sthompsa	CDCE_BULK_RX,
60190734Sthompsa	CDCE_BULK_TX,
61190734Sthompsa	CDCE_INTR_RX,
62190734Sthompsa	CDCE_INTR_TX,
63188412Sthompsa	CDCE_N_TRANSFER,
64187259Sthompsa};
65187259Sthompsa
66197563Sthompsastruct cdce_ncm {
67197563Sthompsa	struct usb_ncm16_hdr hdr;
68197563Sthompsa	struct usb_ncm16_dpt dpt;
69197563Sthompsa	struct usb_ncm16_dp dp[CDCE_NCM_SUBFRAMES_MAX];
70197563Sthompsa	uint32_t rx_max;
71197563Sthompsa	uint32_t tx_max;
72197563Sthompsa	uint16_t tx_remainder;
73197563Sthompsa	uint16_t tx_modulus;
74197563Sthompsa	uint16_t tx_struct_align;
75197563Sthompsa	uint16_t tx_seq;
76213809Shselasky	uint16_t tx_nframe;
77197563Sthompsa};
78197563Sthompsa
79184610Salfredstruct cdce_softc {
80192984Sthompsa	struct usb_ether	sc_ue;
81188412Sthompsa	struct mtx		sc_mtx;
82197563Sthompsa#if CDCE_HAVE_NCM
83197563Sthompsa	struct cdce_ncm		sc_ncm;
84197563Sthompsa#endif
85192984Sthompsa	struct usb_xfer	*sc_xfer[CDCE_N_TRANSFER];
86188412Sthompsa	struct mbuf		*sc_rx_buf[CDCE_FRAMES_MAX];
87188412Sthompsa	struct mbuf		*sc_tx_buf[CDCE_FRAMES_MAX];
88184610Salfred
89188412Sthompsa	int 			sc_flags;
90184610Salfred#define	CDCE_FLAG_ZAURUS	0x0001
91184610Salfred#define	CDCE_FLAG_NO_UNION	0x0002
92184610Salfred#define	CDCE_FLAG_RX_DATA	0x0010
93184610Salfred
94188412Sthompsa	uint8_t sc_eaddr_str_index;
95184610Salfred	uint8_t	sc_ifaces_index[2];
96277298Sbr	uint8_t sc_notify_state;
97277298Sbr#define	CDCE_NOTIFY_NETWORK_CONNECTION	0
98277298Sbr#define	CDCE_NOTIFY_SPEED_CHANGE	1
99277298Sbr#define	CDCE_NOTIFY_DONE		2
100184610Salfred};
101184610Salfred
102188412Sthompsa#define	CDCE_LOCK(_sc)			mtx_lock(&(_sc)->sc_mtx)
103188412Sthompsa#define	CDCE_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
104188412Sthompsa#define	CDCE_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->sc_mtx, t)
105184610Salfred#endif					/* _USB_IF_CDCEREG_H_ */
106