102ac6454SAndrew Thompson /*- 2df57947fSPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause 3df57947fSPedro F. Giffuni * 402ac6454SAndrew Thompson * Copyright (c) 2003-2005 Craig Boston 502ac6454SAndrew Thompson * All rights reserved. 602ac6454SAndrew Thompson * 702ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 802ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 902ac6454SAndrew Thompson * are met: 1002ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 1102ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1202ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1302ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1402ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1502ac6454SAndrew Thompson * 3. All advertising materials mentioning features or use of this software 1602ac6454SAndrew Thompson * must display the following acknowledgement: 1702ac6454SAndrew Thompson * This product includes software developed by Bill Paul. 1802ac6454SAndrew Thompson * 4. Neither the name of the author nor the names of any co-contributors 1902ac6454SAndrew Thompson * may be used to endorse or promote products derived from this software 2002ac6454SAndrew Thompson * without specific prior written permission. 2102ac6454SAndrew Thompson * 2202ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 2302ac6454SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2402ac6454SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2502ac6454SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul, THE VOICES IN HIS HEAD OR 2602ac6454SAndrew Thompson * THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 2702ac6454SAndrew Thompson * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2802ac6454SAndrew Thompson * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2902ac6454SAndrew Thompson * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 3002ac6454SAndrew Thompson * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3102ac6454SAndrew Thompson * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 3202ac6454SAndrew Thompson * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3302ac6454SAndrew Thompson */ 3402ac6454SAndrew Thompson 3502ac6454SAndrew Thompson #ifndef _USB_IF_CDCEREG_H_ 3602ac6454SAndrew Thompson #define _USB_IF_CDCEREG_H_ 3702ac6454SAndrew Thompson 38*f0c393f7SKornel Duleba #define CDCE_BIT(x) (1 << (x)) 39*f0c393f7SKornel Duleba 4002ac6454SAndrew Thompson #define CDCE_FRAMES_MAX 8 /* units */ 4102ac6454SAndrew Thompson #define CDCE_IND_SIZE_MAX 32 /* bytes */ 4202ac6454SAndrew Thompson 437e05daaeSHans Petter Selasky #define CDCE_NCM_TX_MINLEN 512 /* bytes, must be power of two */ 444309793bSHans Petter Selasky #define CDCE_NCM_TX_MAXLEN (16384 + 4) /* bytes, must be short terminated */ 454076dd23SAndrew Thompson #define CDCE_NCM_TX_FRAMES_MAX 8 /* units */ 464076dd23SAndrew Thompson 474076dd23SAndrew Thompson #define CDCE_NCM_RX_MAXLEN (1UL << 14) /* bytes */ 484076dd23SAndrew Thompson #define CDCE_NCM_RX_FRAMES_MAX 1 /* units */ 494076dd23SAndrew Thompson 504076dd23SAndrew Thompson #define CDCE_NCM_SUBFRAMES_MAX 32 /* units */ 514076dd23SAndrew Thompson 527e05daaeSHans Petter Selasky #define CDCE_NCM_ALIGN(rem,off,mod) \ 537e05daaeSHans Petter Selasky ((uint32_t)(((uint32_t)(rem)) - \ 547e05daaeSHans Petter Selasky ((uint32_t)((-(uint32_t)(off)) & (-(uint32_t)(mod)))))) 557e05daaeSHans Petter Selasky 564076dd23SAndrew Thompson #ifndef CDCE_HAVE_NCM 574076dd23SAndrew Thompson #define CDCE_HAVE_NCM 1 584076dd23SAndrew Thompson #endif 594076dd23SAndrew Thompson 6002ac6454SAndrew Thompson enum { 614eae601eSAndrew Thompson CDCE_BULK_RX, 624eae601eSAndrew Thompson CDCE_BULK_TX, 634eae601eSAndrew Thompson CDCE_INTR_RX, 644eae601eSAndrew Thompson CDCE_INTR_TX, 6502ac6454SAndrew Thompson CDCE_N_TRANSFER, 6602ac6454SAndrew Thompson }; 6702ac6454SAndrew Thompson 684076dd23SAndrew Thompson struct cdce_ncm { 694076dd23SAndrew Thompson struct usb_ncm16_hdr hdr; 704076dd23SAndrew Thompson struct usb_ncm16_dpt dpt; 714076dd23SAndrew Thompson struct usb_ncm16_dp dp[CDCE_NCM_SUBFRAMES_MAX]; 724076dd23SAndrew Thompson uint32_t rx_max; 734076dd23SAndrew Thompson uint32_t tx_max; 744076dd23SAndrew Thompson uint16_t tx_remainder; 754076dd23SAndrew Thompson uint16_t tx_modulus; 764076dd23SAndrew Thompson uint16_t tx_struct_align; 774076dd23SAndrew Thompson uint16_t tx_seq; 787e05daaeSHans Petter Selasky uint16_t tx_nframe; 794076dd23SAndrew Thompson }; 804076dd23SAndrew Thompson 8102ac6454SAndrew Thompson struct cdce_softc { 82760bc48eSAndrew Thompson struct usb_ether sc_ue; 8302ac6454SAndrew Thompson struct mtx sc_mtx; 844076dd23SAndrew Thompson #if CDCE_HAVE_NCM 854076dd23SAndrew Thompson struct cdce_ncm sc_ncm; 864076dd23SAndrew Thompson #endif 87760bc48eSAndrew Thompson struct usb_xfer *sc_xfer[CDCE_N_TRANSFER]; 8802ac6454SAndrew Thompson struct mbuf *sc_rx_buf[CDCE_FRAMES_MAX]; 8902ac6454SAndrew Thompson struct mbuf *sc_tx_buf[CDCE_FRAMES_MAX]; 9002ac6454SAndrew Thompson 91b43d600cSJohn-Mark Gurney struct ifmedia sc_media; 92b43d600cSJohn-Mark Gurney 9302ac6454SAndrew Thompson int sc_flags; 9402ac6454SAndrew Thompson #define CDCE_FLAG_ZAURUS 0x0001 9502ac6454SAndrew Thompson #define CDCE_FLAG_NO_UNION 0x0002 9602ac6454SAndrew Thompson #define CDCE_FLAG_RX_DATA 0x0010 97b43d600cSJohn-Mark Gurney #define CDCE_FLAG_VLAN 0x0020 9802ac6454SAndrew Thompson 9902ac6454SAndrew Thompson uint8_t sc_eaddr_str_index; 10002ac6454SAndrew Thompson uint8_t sc_ifaces_index[2]; 101b0b74fb3SRuslan Bukin uint8_t sc_notify_state; 102b0b74fb3SRuslan Bukin #define CDCE_NOTIFY_NETWORK_CONNECTION 0 103b0b74fb3SRuslan Bukin #define CDCE_NOTIFY_SPEED_CHANGE 1 104b0b74fb3SRuslan Bukin #define CDCE_NOTIFY_DONE 2 10502ac6454SAndrew Thompson }; 10602ac6454SAndrew Thompson 107*f0c393f7SKornel Duleba /* 108*f0c393f7SKornel Duleba * Taken from USB CDC Subclass Specification for Ethernet Devices v1.2, 109*f0c393f7SKornel Duleba * section 6.2.4. 110*f0c393f7SKornel Duleba */ 111*f0c393f7SKornel Duleba 112*f0c393f7SKornel Duleba #define CDC_SET_ETHERNET_PACKET_FILTER 0x43 /* Command code. */ 113*f0c393f7SKornel Duleba 114*f0c393f7SKornel Duleba #define CDC_PACKET_TYPE_PROMISC CDCE_BIT(0) 115*f0c393f7SKornel Duleba #define CDC_PACKET_TYPE_ALL_MULTICAST CDCE_BIT(1) /* Allmulti. */ 116*f0c393f7SKornel Duleba #define CDC_PACKET_TYPE_DIRECTED CDCE_BIT(2) /* Filter unicast by mac. */ 117*f0c393f7SKornel Duleba #define CDC_PACKET_TYPE_BROADCAST CDCE_BIT(3) 118*f0c393f7SKornel Duleba #define CDC_PACKET_TYPE_MULTICAST CDCE_BIT(4) /* Multicast filtering, not supported. */ 119*f0c393f7SKornel Duleba 12002ac6454SAndrew Thompson #define CDCE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 12102ac6454SAndrew Thompson #define CDCE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 12202ac6454SAndrew Thompson #define CDCE_LOCK_ASSERT(_sc, t) mtx_assert(&(_sc)->sc_mtx, t) 12302ac6454SAndrew Thompson #endif /* _USB_IF_CDCEREG_H_ */ 124