102ac6454SAndrew Thompson /*- 2df57947fSPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause 3df57947fSPedro F. Giffuni * 402ac6454SAndrew Thompson * Copyright (c) 1997, 1998, 1999, 2000 502ac6454SAndrew Thompson * Bill Paul <wpaul@ee.columbia.edu>. 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 OR THE VOICES IN HIS HEAD 2602ac6454SAndrew Thompson * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2702ac6454SAndrew Thompson * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2802ac6454SAndrew Thompson * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2902ac6454SAndrew Thompson * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3002ac6454SAndrew Thompson * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3102ac6454SAndrew Thompson * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 3202ac6454SAndrew Thompson * THE POSSIBILITY OF SUCH DAMAGE. 3302ac6454SAndrew Thompson */ 3402ac6454SAndrew Thompson 3502ac6454SAndrew Thompson /* 3602ac6454SAndrew Thompson * Definitions for the KLSI KL5KUSB101B USB to ethernet controller. 3702ac6454SAndrew Thompson * The KLSI part is controlled via vendor control requests, the structure 3802ac6454SAndrew Thompson * of which depend a bit on the firmware running on the internal 3902ac6454SAndrew Thompson * microcontroller. The one exception is the 'send scan data' command, 4002ac6454SAndrew Thompson * which is used to load the firmware. 4102ac6454SAndrew Thompson */ 4202ac6454SAndrew Thompson 4302ac6454SAndrew Thompson #define KUE_CMD_GET_ETHER_DESCRIPTOR 0x00 4402ac6454SAndrew Thompson #define KUE_CMD_SET_MCAST_FILTERS 0x01 4502ac6454SAndrew Thompson #define KUE_CMD_SET_PKT_FILTER 0x02 4602ac6454SAndrew Thompson #define KUE_CMD_GET_ETHERSTATS 0x03 4702ac6454SAndrew Thompson #define KUE_CMD_GET_GPIO 0x04 4802ac6454SAndrew Thompson #define KUE_CMD_SET_GPIO 0x05 4902ac6454SAndrew Thompson #define KUE_CMD_SET_MAC 0x06 5002ac6454SAndrew Thompson #define KUE_CMD_GET_MAC 0x07 5102ac6454SAndrew Thompson #define KUE_CMD_SET_URB_SIZE 0x08 5202ac6454SAndrew Thompson #define KUE_CMD_SET_SOFS 0x09 5302ac6454SAndrew Thompson #define KUE_CMD_SET_EVEN_PKTS 0x0A 5402ac6454SAndrew Thompson #define KUE_CMD_SEND_SCAN 0xFF 5502ac6454SAndrew Thompson 5602ac6454SAndrew Thompson struct kue_ether_desc { 5702ac6454SAndrew Thompson uint8_t kue_len; 5802ac6454SAndrew Thompson uint8_t kue_rsvd0; 5902ac6454SAndrew Thompson uint8_t kue_rsvd1; 6002ac6454SAndrew Thompson uint8_t kue_macaddr[ETHER_ADDR_LEN]; 6102ac6454SAndrew Thompson uint8_t kue_etherstats[4]; 6202ac6454SAndrew Thompson uint8_t kue_maxseg[2]; 6302ac6454SAndrew Thompson uint8_t kue_mcastfilt[2]; 6402ac6454SAndrew Thompson uint8_t kue_rsvd2; 6502ac6454SAndrew Thompson } __packed; 6602ac6454SAndrew Thompson 6702ac6454SAndrew Thompson #define KUE_ETHERSTATS(x) UGETDW((x)->sc_desc.kue_etherstats) 6802ac6454SAndrew Thompson #define KUE_MAXSEG(x) UGETW((x)->sc_desc.kue_maxseg) 6902ac6454SAndrew Thompson #define KUE_MCFILTCNT(x) (UGETW((x)->sc_desc.kue_mcastfilt) & 0x7FFF) 7002ac6454SAndrew Thompson #define KUE_MCFILT(x, y) \ 7102ac6454SAndrew Thompson (char *)&(sc->sc_mcfilters[y * ETHER_ADDR_LEN]) 7202ac6454SAndrew Thompson 7302ac6454SAndrew Thompson #define KUE_STAT_TX_OK 0x00000001 7402ac6454SAndrew Thompson #define KUE_STAT_RX_OK 0x00000002 7502ac6454SAndrew Thompson #define KUE_STAT_TX_ERR 0x00000004 7602ac6454SAndrew Thompson #define KUE_STAT_RX_ERR 0x00000008 7702ac6454SAndrew Thompson #define KUE_STAT_RX_NOBUF 0x00000010 7802ac6454SAndrew Thompson #define KUE_STAT_TX_UCAST_BYTES 0x00000020 7902ac6454SAndrew Thompson #define KUE_STAT_TX_UCAST_FRAMES 0x00000040 8002ac6454SAndrew Thompson #define KUE_STAT_TX_MCAST_BYTES 0x00000080 8102ac6454SAndrew Thompson #define KUE_STAT_TX_MCAST_FRAMES 0x00000100 8202ac6454SAndrew Thompson #define KUE_STAT_TX_BCAST_BYTES 0x00000200 8302ac6454SAndrew Thompson #define KUE_STAT_TX_BCAST_FRAMES 0x00000400 8402ac6454SAndrew Thompson #define KUE_STAT_RX_UCAST_BYTES 0x00000800 8502ac6454SAndrew Thompson #define KUE_STAT_RX_UCAST_FRAMES 0x00001000 8602ac6454SAndrew Thompson #define KUE_STAT_RX_MCAST_BYTES 0x00002000 8702ac6454SAndrew Thompson #define KUE_STAT_RX_MCAST_FRAMES 0x00004000 8802ac6454SAndrew Thompson #define KUE_STAT_RX_BCAST_BYTES 0x00008000 8902ac6454SAndrew Thompson #define KUE_STAT_RX_BCAST_FRAMES 0x00010000 9002ac6454SAndrew Thompson #define KUE_STAT_RX_CRCERR 0x00020000 9102ac6454SAndrew Thompson #define KUE_STAT_TX_QUEUE_LENGTH 0x00040000 9202ac6454SAndrew Thompson #define KUE_STAT_RX_ALIGNERR 0x00080000 9302ac6454SAndrew Thompson #define KUE_STAT_TX_SINGLECOLL 0x00100000 9402ac6454SAndrew Thompson #define KUE_STAT_TX_MULTICOLL 0x00200000 9502ac6454SAndrew Thompson #define KUE_STAT_TX_DEFERRED 0x00400000 9602ac6454SAndrew Thompson #define KUE_STAT_TX_MAXCOLLS 0x00800000 9702ac6454SAndrew Thompson #define KUE_STAT_RX_OVERRUN 0x01000000 9802ac6454SAndrew Thompson #define KUE_STAT_TX_UNDERRUN 0x02000000 9902ac6454SAndrew Thompson #define KUE_STAT_TX_SQE_ERR 0x04000000 10002ac6454SAndrew Thompson #define KUE_STAT_TX_CARRLOSS 0x08000000 10102ac6454SAndrew Thompson #define KUE_STAT_RX_LATECOLL 0x10000000 10202ac6454SAndrew Thompson 10302ac6454SAndrew Thompson #define KUE_RXFILT_PROMISC 0x0001 10402ac6454SAndrew Thompson #define KUE_RXFILT_ALLMULTI 0x0002 10502ac6454SAndrew Thompson #define KUE_RXFILT_UNICAST 0x0004 10602ac6454SAndrew Thompson #define KUE_RXFILT_BROADCAST 0x0008 10702ac6454SAndrew Thompson #define KUE_RXFILT_MULTICAST 0x0010 10802ac6454SAndrew Thompson 10902ac6454SAndrew Thompson #define KUE_TIMEOUT 1000 11002ac6454SAndrew Thompson #define KUE_MIN_FRAMELEN 60 11102ac6454SAndrew Thompson 11202ac6454SAndrew Thompson #define KUE_CTL_READ 0x01 11302ac6454SAndrew Thompson #define KUE_CTL_WRITE 0x02 11402ac6454SAndrew Thompson 11502ac6454SAndrew Thompson #define KUE_CONFIG_IDX 0 /* config number 1 */ 11602ac6454SAndrew Thompson #define KUE_IFACE_IDX 0 11702ac6454SAndrew Thompson 11802ac6454SAndrew Thompson /* The interrupt endpoint is currently unused by the KLSI part. */ 11902ac6454SAndrew Thompson #define KUE_ENDPT_MAX 4 12002ac6454SAndrew Thompson enum { 12102ac6454SAndrew Thompson KUE_BULK_DT_WR, 12202ac6454SAndrew Thompson KUE_BULK_DT_RD, 12302ac6454SAndrew Thompson KUE_N_TRANSFER, 12402ac6454SAndrew Thompson }; 12502ac6454SAndrew Thompson 12602ac6454SAndrew Thompson struct kue_softc { 127760bc48eSAndrew Thompson struct usb_ether sc_ue; 12802ac6454SAndrew Thompson struct mtx sc_mtx; 12902ac6454SAndrew Thompson struct kue_ether_desc sc_desc; 130760bc48eSAndrew Thompson struct usb_xfer *sc_xfer[KUE_N_TRANSFER]; 13102ac6454SAndrew Thompson uint8_t *sc_mcfilters; 13202ac6454SAndrew Thompson 13302ac6454SAndrew Thompson int sc_flags; 13402ac6454SAndrew Thompson #define KUE_FLAG_LINK 0x0001 13502ac6454SAndrew Thompson 13602ac6454SAndrew Thompson uint16_t sc_rxfilt; 13702ac6454SAndrew Thompson }; 13802ac6454SAndrew Thompson 13902ac6454SAndrew Thompson #define KUE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 14002ac6454SAndrew Thompson #define KUE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 14102ac6454SAndrew Thompson #define KUE_LOCK_ASSERT(_sc, t) mtx_assert(&(_sc)->sc_mtx, t) 142