xref: /freebsd/sys/dev/usb/net/if_cdcereg.h (revision b0b74fb366450ac61b7df38daa92bc19cbfc3ecc)
102ac6454SAndrew Thompson /*-
202ac6454SAndrew Thompson  * Copyright (c) 2003-2005 Craig Boston
302ac6454SAndrew Thompson  * All rights reserved.
402ac6454SAndrew Thompson  *
502ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
602ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
702ac6454SAndrew Thompson  * are met:
802ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
902ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1002ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1102ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1202ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1302ac6454SAndrew Thompson  * 3. All advertising materials mentioning features or use of this software
1402ac6454SAndrew Thompson  *    must display the following acknowledgement:
1502ac6454SAndrew Thompson  *      This product includes software developed by Bill Paul.
1602ac6454SAndrew Thompson  * 4. Neither the name of the author nor the names of any co-contributors
1702ac6454SAndrew Thompson  *    may be used to endorse or promote products derived from this software
1802ac6454SAndrew Thompson  *    without specific prior written permission.
1902ac6454SAndrew Thompson  *
2002ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
2102ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2202ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2302ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul, THE VOICES IN HIS HEAD OR
2402ac6454SAndrew Thompson  * THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2502ac6454SAndrew Thompson  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2602ac6454SAndrew Thompson  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2702ac6454SAndrew Thompson  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2802ac6454SAndrew Thompson  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2902ac6454SAndrew Thompson  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3002ac6454SAndrew Thompson  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3102ac6454SAndrew Thompson  *
3202ac6454SAndrew Thompson  * $FreeBSD$
3302ac6454SAndrew Thompson  */
3402ac6454SAndrew Thompson 
3502ac6454SAndrew Thompson #ifndef _USB_IF_CDCEREG_H_
3602ac6454SAndrew Thompson #define	_USB_IF_CDCEREG_H_
3702ac6454SAndrew Thompson 
3802ac6454SAndrew Thompson #define	CDCE_FRAMES_MAX	8		/* units */
3902ac6454SAndrew Thompson #define	CDCE_IND_SIZE_MAX 32            /* bytes */
4002ac6454SAndrew Thompson 
417e05daaeSHans Petter Selasky #define	CDCE_NCM_TX_MINLEN 512		/* bytes, must be power of two */
424309793bSHans Petter Selasky #define	CDCE_NCM_TX_MAXLEN (16384 + 4)	/* bytes, must be short terminated */
434076dd23SAndrew Thompson #define	CDCE_NCM_TX_FRAMES_MAX 8	/* units */
444076dd23SAndrew Thompson 
454076dd23SAndrew Thompson #define	CDCE_NCM_RX_MAXLEN (1UL << 14)	/* bytes */
464076dd23SAndrew Thompson #define	CDCE_NCM_RX_FRAMES_MAX 1	/* units */
474076dd23SAndrew Thompson 
484076dd23SAndrew Thompson #define	CDCE_NCM_SUBFRAMES_MAX 32	/* units */
494076dd23SAndrew Thompson 
507e05daaeSHans Petter Selasky #define	CDCE_NCM_ALIGN(rem,off,mod) \
517e05daaeSHans Petter Selasky     ((uint32_t)(((uint32_t)(rem)) - \
527e05daaeSHans Petter Selasky     ((uint32_t)((-(uint32_t)(off)) & (-(uint32_t)(mod))))))
537e05daaeSHans Petter Selasky 
544076dd23SAndrew Thompson #ifndef CDCE_HAVE_NCM
554076dd23SAndrew Thompson #define	CDCE_HAVE_NCM 1
564076dd23SAndrew Thompson #endif
574076dd23SAndrew Thompson 
5802ac6454SAndrew Thompson enum {
594eae601eSAndrew Thompson 	CDCE_BULK_RX,
604eae601eSAndrew Thompson 	CDCE_BULK_TX,
614eae601eSAndrew Thompson 	CDCE_INTR_RX,
624eae601eSAndrew Thompson 	CDCE_INTR_TX,
6302ac6454SAndrew Thompson 	CDCE_N_TRANSFER,
6402ac6454SAndrew Thompson };
6502ac6454SAndrew Thompson 
664076dd23SAndrew Thompson struct cdce_ncm {
674076dd23SAndrew Thompson 	struct usb_ncm16_hdr hdr;
684076dd23SAndrew Thompson 	struct usb_ncm16_dpt dpt;
694076dd23SAndrew Thompson 	struct usb_ncm16_dp dp[CDCE_NCM_SUBFRAMES_MAX];
704076dd23SAndrew Thompson 	uint32_t rx_max;
714076dd23SAndrew Thompson 	uint32_t tx_max;
724076dd23SAndrew Thompson 	uint16_t tx_remainder;
734076dd23SAndrew Thompson 	uint16_t tx_modulus;
744076dd23SAndrew Thompson 	uint16_t tx_struct_align;
754076dd23SAndrew Thompson 	uint16_t tx_seq;
767e05daaeSHans Petter Selasky 	uint16_t tx_nframe;
774076dd23SAndrew Thompson };
784076dd23SAndrew Thompson 
7902ac6454SAndrew Thompson struct cdce_softc {
80760bc48eSAndrew Thompson 	struct usb_ether	sc_ue;
8102ac6454SAndrew Thompson 	struct mtx		sc_mtx;
824076dd23SAndrew Thompson #if CDCE_HAVE_NCM
834076dd23SAndrew Thompson 	struct cdce_ncm		sc_ncm;
844076dd23SAndrew Thompson #endif
85760bc48eSAndrew Thompson 	struct usb_xfer	*sc_xfer[CDCE_N_TRANSFER];
8602ac6454SAndrew Thompson 	struct mbuf		*sc_rx_buf[CDCE_FRAMES_MAX];
8702ac6454SAndrew Thompson 	struct mbuf		*sc_tx_buf[CDCE_FRAMES_MAX];
8802ac6454SAndrew Thompson 
8902ac6454SAndrew Thompson 	int 			sc_flags;
9002ac6454SAndrew Thompson #define	CDCE_FLAG_ZAURUS	0x0001
9102ac6454SAndrew Thompson #define	CDCE_FLAG_NO_UNION	0x0002
9202ac6454SAndrew Thompson #define	CDCE_FLAG_RX_DATA	0x0010
9302ac6454SAndrew Thompson 
9402ac6454SAndrew Thompson 	uint8_t sc_eaddr_str_index;
9502ac6454SAndrew Thompson 	uint8_t	sc_ifaces_index[2];
96*b0b74fb3SRuslan Bukin 	uint8_t sc_notify_state;
97*b0b74fb3SRuslan Bukin #define	CDCE_NOTIFY_NETWORK_CONNECTION	0
98*b0b74fb3SRuslan Bukin #define	CDCE_NOTIFY_SPEED_CHANGE	1
99*b0b74fb3SRuslan Bukin #define	CDCE_NOTIFY_DONE		2
10002ac6454SAndrew Thompson };
10102ac6454SAndrew Thompson 
10202ac6454SAndrew Thompson #define	CDCE_LOCK(_sc)			mtx_lock(&(_sc)->sc_mtx)
10302ac6454SAndrew Thompson #define	CDCE_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
10402ac6454SAndrew Thompson #define	CDCE_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->sc_mtx, t)
10502ac6454SAndrew Thompson #endif					/* _USB_IF_CDCEREG_H_ */
106