1*4b1a56afSjsg /* $OpenBSD: if_udavreg.h,v 1.16 2022/01/09 05:43:00 jsg Exp $ */ 208c86caeSjsg /* $NetBSD: if_udavreg.h,v 1.2 2003/09/04 15:17:39 tsutsui Exp $ */ 308c86caeSjsg /* $nabe: if_udavreg.h,v 1.2 2003/08/21 16:26:40 nabe Exp $ */ 408c86caeSjsg /* 508c86caeSjsg * Copyright (c) 2003 608c86caeSjsg * Shingo WATANABE <nabe@nabechan.org>. All rights reserved. 708c86caeSjsg * 808c86caeSjsg * Redistribution and use in source and binary forms, with or without 908c86caeSjsg * modification, are permitted provided that the following conditions 1008c86caeSjsg * are met: 1108c86caeSjsg * 1. Redistributions of source code must retain the above copyright 1208c86caeSjsg * notice, this list of conditions and the following disclaimer. 1308c86caeSjsg * 2. Redistributions in binary form must reproduce the above copyright 1408c86caeSjsg * notice, this list of conditions and the following disclaimer in the 1508c86caeSjsg * documentation and/or other materials provided with the distribution. 1608c86caeSjsg * 3. Neither the name of the author nor the names of any co-contributors 1708c86caeSjsg * may be used to endorse or promote products derived from this software 1808c86caeSjsg * without specific prior written permission. 1908c86caeSjsg * 2008c86caeSjsg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2108c86caeSjsg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2208c86caeSjsg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2308c86caeSjsg * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2408c86caeSjsg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2508c86caeSjsg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2608c86caeSjsg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2708c86caeSjsg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2808c86caeSjsg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2908c86caeSjsg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3008c86caeSjsg * SUCH DAMAGE. 3108c86caeSjsg * 3208c86caeSjsg */ 3308c86caeSjsg 3408c86caeSjsg #define UDAV_TX_LIST_CNT 1 3508c86caeSjsg #define UDAV_RX_LIST_CNT 1 3608c86caeSjsg 3708c86caeSjsg #define UDAV_TX_TIMEOUT 1000 3808c86caeSjsg #define UDAV_TIMEOUT 10000 3908c86caeSjsg 4008c86caeSjsg 4108c86caeSjsg /* Request */ 4208c86caeSjsg #define UDAV_REQ_REG_READ 0x00 /* Read from register(s) */ 4308c86caeSjsg #define UDAV_REQ_REG_WRITE 0x01 /* Write to register(s) */ 4408c86caeSjsg #define UDAV_REQ_REG_WRITE1 0x03 /* Write to a register */ 4508c86caeSjsg 4608c86caeSjsg #define UDAV_REQ_MEM_READ 0x02 /* Read from memory */ 4708c86caeSjsg #define UDAV_REQ_MEM_WRITE 0x05 /* Write to memory */ 4808c86caeSjsg #define UDAV_REQ_MEM_WRITE1 0x07 /* Write a byte to memory */ 4908c86caeSjsg 5008c86caeSjsg /* Registers */ 5108c86caeSjsg #define UDAV_NCR 0x00 /* Network Control Register */ 5208c86caeSjsg #define UDAV_NCR_EXT_PHY (1<<7) /* Select External PHY */ 5308c86caeSjsg #define UDAV_NCR_WAKEEN (1<<6) /* Wakeup Event Enable */ 5408c86caeSjsg #define UDAV_NCR_FCOL (1<<4) /* Force Collision Mode */ 5508c86caeSjsg #define UDAV_NCR_FDX (1<<3) /* Full-Duplex Mode (RO on Int. PHY) */ 56*4b1a56afSjsg #define UDAV_NCR_LBK1 (1<<2) /* Loopback Mode */ 57*4b1a56afSjsg #define UDAV_NCR_LBK0 (1<<1) /* Loopback Mode */ 5808c86caeSjsg #define UDAV_NCR_RST (1<<0) /* Software reset */ 5908c86caeSjsg 605f772d42Ssasano #define UDAV_NSR 0x01 /* Network Status Register */ 615f772d42Ssasano #define UDAV_NSR_SPEED (1<<7) /* Media Speed (Int. PHY) */ 625f772d42Ssasano #define UDAV_NSR_LINKST (1<<6) /* Link Status (Int. PHY) */ 635f772d42Ssasano #define UDAV_NSR_WAKEST (1<<5) /* Wakeup Status */ 645f772d42Ssasano #define UDAV_NSR_TXFULL (1<<4) /* TX FIFO Full */ 655f772d42Ssasano #define UDAV_NSR_TX2END (1<<3) /* TX Packet 2 Complete Status */ 665f772d42Ssasano #define UDAV_NSR_TX1END (1<<2) /* TX Packet 1 Complete Status */ 675f772d42Ssasano #define UDAV_NSR_RXOV (1<<1) /* RX FIFO Overflow */ 685f772d42Ssasano #define UDAV_NSR_RXRDY (1<<0) /* RX Packet Ready */ 695f772d42Ssasano 7008c86caeSjsg #define UDAV_RCR 0x05 /* RX Control Register */ 7108c86caeSjsg #define UDAV_RCR_WTDIS (1<<6) /* Watchdog Timer Disable */ 7208c86caeSjsg #define UDAV_RCR_DIS_LONG (1<<5) /* Discard Long Packet(over 1522Byte) */ 7308c86caeSjsg #define UDAV_RCR_DIS_CRC (1<<4) /* Discard CRC Error Packet */ 7408c86caeSjsg #define UDAV_RCR_ALL (1<<3) /* Pass All Multicast */ 7508c86caeSjsg #define UDAV_RCR_RUNT (1<<2) /* Pass Runt Packet */ 7608c86caeSjsg #define UDAV_RCR_PRMSC (1<<1) /* Promiscuous Mode */ 7708c86caeSjsg #define UDAV_RCR_RXEN (1<<0) /* RX Enable */ 7808c86caeSjsg 7908c86caeSjsg #define UDAV_RSR 0x06 /* RX Status Register */ 8008c86caeSjsg #define UDAV_RSR_RF (1<<7) /* Runt Frame */ 8108c86caeSjsg #define UDAV_RSR_MF (1<<6) /* Multicast Frame */ 8208c86caeSjsg #define UDAV_RSR_LCS (1<<5) /* Late Collision Seen */ 8308c86caeSjsg #define UDAV_RSR_RWTO (1<<4) /* Receive Watchdog Time-Out */ 8408c86caeSjsg #define UDAV_RSR_PLE (1<<3) /* Physical Layer Error */ 8508c86caeSjsg #define UDAV_RSR_AE (1<<2) /* Alignment Error */ 8608c86caeSjsg #define UDAV_RSR_CE (1<<1) /* CRC Error */ 8708c86caeSjsg #define UDAV_RSR_FOE (1<<0) /* FIFO Overflow Error */ 8808c86caeSjsg #define UDAV_RSR_ERR (UDAV_RSR_RF | UDAV_RSR_LCS | UDAV_RSR_RWTO |\ 8908c86caeSjsg UDAV_RSR_PLE | UDAV_RSR_AE | UDAV_RSR_CE |\ 9008c86caeSjsg UDAV_RSR_FOE) 9108c86caeSjsg 9208c86caeSjsg #define UDAV_EPCR 0x0b /* EEPROM & PHY Control Register */ 9308c86caeSjsg #define UDAV_EPCR_REEP (1<<5) /* Reload EEPROM */ 9408c86caeSjsg #define UDAV_EPCR_WEP (1<<4) /* Write EEPROM enable */ 9508c86caeSjsg #define UDAV_EPCR_EPOS (1<<3) /* EEPROM or PHY Operation Select */ 9608c86caeSjsg #define UDAV_EPCR_ERPRR (1<<2) /* EEPROM/PHY Register Read Command */ 9708c86caeSjsg #define UDAV_EPCR_ERPRW (1<<1) /* EEPROM/PHY Register Write Command */ 9808c86caeSjsg #define UDAV_EPCR_ERRE (1<<0) /* EEPROM/PHY Access Status */ 9908c86caeSjsg 10008c86caeSjsg #define UDAV_EPAR 0x0c /* EEPROM & PHY Control Register */ 10108c86caeSjsg #define UDAV_EPAR_PHY_ADR1 (1<<7) /* PHY Address bit 1 */ 10208c86caeSjsg #define UDAV_EPAR_PHY_ADR0 (1<<6) /* PHY Address bit 0 */ 10308c86caeSjsg #define UDAV_EPAR_EROA (1<<0) /* EEPROM Word/PHY Register Address */ 10408c86caeSjsg #define UDAV_EPAR_EROA_MASK (0x1f) /* [5:0] */ 10508c86caeSjsg 10608c86caeSjsg #define UDAV_EPDRL 0x0d /* EEPROM & PHY Data Register */ 10708c86caeSjsg #define UDAV_EPDRH 0x0e /* EEPROM & PHY Data Register */ 10808c86caeSjsg 10908c86caeSjsg #define UDAV_PAR0 0x10 /* Ethernet Address, load from EEPROM */ 11008c86caeSjsg #define UDAV_PAR1 0x11 /* Ethernet Address, load from EEPROM */ 11108c86caeSjsg #define UDAV_PAR2 0x12 /* Ethernet Address, load from EEPROM */ 11208c86caeSjsg #define UDAV_PAR3 0x13 /* Ethernet Address, load from EEPROM */ 11308c86caeSjsg #define UDAV_PAR4 0x14 /* Ethernet Address, load from EEPROM */ 11408c86caeSjsg #define UDAV_PAR5 0x15 /* Ethernet Address, load from EEPROM */ 11508c86caeSjsg #define UDAV_PAR UDAV_PAR0 11608c86caeSjsg 11708c86caeSjsg #define UDAV_MAR0 0x16 /* Multicast Register */ 11808c86caeSjsg #define UDAV_MAR1 0x17 /* Multicast Register */ 11908c86caeSjsg #define UDAV_MAR2 0x18 /* Multicast Register */ 12008c86caeSjsg #define UDAV_MAR3 0x19 /* Multicast Register */ 12108c86caeSjsg #define UDAV_MAR4 0x1a /* Multicast Register */ 12208c86caeSjsg #define UDAV_MAR5 0x1b /* Multicast Register */ 12308c86caeSjsg #define UDAV_MAR6 0x1c /* Multicast Register */ 12408c86caeSjsg #define UDAV_MAR7 0x1d /* Multicast Register */ 12508c86caeSjsg #define UDAV_MAR UDAV_MAR0 12608c86caeSjsg 12708c86caeSjsg #define UDAV_GPCR 0x1e /* General purpose control register */ 12808c86caeSjsg #define UDAV_GPCR_GEP_CNTL6 (1<<6) /* General purpose control 6 */ 12908c86caeSjsg #define UDAV_GPCR_GEP_CNTL5 (1<<5) /* General purpose control 5 */ 13008c86caeSjsg #define UDAV_GPCR_GEP_CNTL4 (1<<4) /* General purpose control 4 */ 13108c86caeSjsg #define UDAV_GPCR_GEP_CNTL3 (1<<3) /* General purpose control 3 */ 13208c86caeSjsg #define UDAV_GPCR_GEP_CNTL2 (1<<2) /* General purpose control 2 */ 13308c86caeSjsg #define UDAV_GPCR_GEP_CNTL1 (1<<1) /* General purpose control 1 */ 13408c86caeSjsg #define UDAV_GPCR_GEP_CNTL0 (1<<0) /* General purpose control 0 */ 13508c86caeSjsg 13608c86caeSjsg #define UDAV_GPR 0x1f /* General purpose register */ 13708c86caeSjsg #define UDAV_GPR_GEPIO6 (1<<6) /* General purpose 6 */ 13808c86caeSjsg #define UDAV_GPR_GEPIO5 (1<<5) /* General purpose 5 */ 13908c86caeSjsg #define UDAV_GPR_GEPIO4 (1<<4) /* General purpose 4 */ 14008c86caeSjsg #define UDAV_GPR_GEPIO3 (1<<3) /* General purpose 3 */ 14108c86caeSjsg #define UDAV_GPR_GEPIO2 (1<<2) /* General purpose 2 */ 14208c86caeSjsg #define UDAV_GPR_GEPIO1 (1<<1) /* General purpose 1 */ 14308c86caeSjsg #define UDAV_GPR_GEPIO0 (1<<0) /* General purpose 0 */ 14408c86caeSjsg 14508c86caeSjsg #define GET_IFP(sc) (&(sc)->sc_ac.ac_if) 14608c86caeSjsg #define GET_MII(sc) (&(sc)->sc_mii) 14708c86caeSjsg 14808c86caeSjsg struct udav_chain { 14908c86caeSjsg struct udav_softc *udav_sc; 150ab0b1be7Smglocker struct usbd_xfer *udav_xfer; 15108c86caeSjsg char *udav_buf; 15208c86caeSjsg struct mbuf *udav_mbuf; 15308c86caeSjsg int udav_idx; 15408c86caeSjsg }; 15508c86caeSjsg 15608c86caeSjsg struct udav_cdata { 15708c86caeSjsg struct udav_chain udav_tx_chain[UDAV_TX_LIST_CNT]; 15808c86caeSjsg struct udav_chain udav_rx_chain[UDAV_TX_LIST_CNT]; 15908c86caeSjsg #if 0 1607b9c60e5Sjmc /* XXX: Interrupt Endpoint is not yet supported! */ 16108c86caeSjsg struct udav_intrpkg udav_ibuf; 16208c86caeSjsg #endif 16308c86caeSjsg int udav_tx_prod; 16408c86caeSjsg int udav_tx_cons; 16508c86caeSjsg int udav_tx_cnt; 16608c86caeSjsg int udav_rx_prod; 16708c86caeSjsg }; 16808c86caeSjsg 16908c86caeSjsg struct udav_softc { 1708c5d01eeSmk struct device sc_dev; /* base device */ 171ab0b1be7Smglocker struct usbd_device *sc_udev; 17208c86caeSjsg 17308c86caeSjsg /* USB */ 174ab0b1be7Smglocker struct usbd_interface *sc_ctl_iface; 17508c86caeSjsg /* int sc_ctl_iface_no; */ 17608c86caeSjsg int sc_bulkin_no; /* bulk in endpoint */ 17708c86caeSjsg int sc_bulkout_no; /* bulk out endpoint */ 17808c86caeSjsg int sc_intrin_no; /* intr in endpoint */ 179ab0b1be7Smglocker struct usbd_pipe *sc_pipe_rx; 180ab0b1be7Smglocker struct usbd_pipe *sc_pipe_tx; 181ab0b1be7Smglocker struct usbd_pipe *sc_pipe_intr; 18234eef271Smbalmer struct timeout sc_stat_ch; 18308c86caeSjsg u_int sc_rx_errs; 18408c86caeSjsg /* u_int sc_intr_errs; */ 18508c86caeSjsg struct timeval sc_rx_notice; 18608c86caeSjsg 18708c86caeSjsg /* Ethernet */ 18808c86caeSjsg struct arpcom sc_ac; /* ethernet common */ 18908c86caeSjsg struct mii_data sc_mii; 1905be69eafSkrw struct rwlock sc_mii_lock; 19108c86caeSjsg int sc_link; 19208c86caeSjsg #define sc_media udav_mii.mii_media 19308c86caeSjsg struct udav_cdata sc_cdata; 19408c86caeSjsg 19508c86caeSjsg int sc_refcnt; 19608c86caeSjsg 19708c86caeSjsg struct usb_task sc_tick_task; 19808c86caeSjsg struct usb_task sc_stop_task; 19908c86caeSjsg 20008c86caeSjsg u_int16_t sc_flags; 20108c86caeSjsg }; 2020102d82aSdlg 2030102d82aSdlg struct udav_rx_hdr { 2040102d82aSdlg uByte pktstat; 2050102d82aSdlg uWord length; 206298cb86eSmbalmer } __packed; 2070102d82aSdlg #define UDAV_RX_HDRLEN sizeof(struct udav_rx_hdr) 2080102d82aSdlg 209b96f689dSdlg /* Packet length */ 2108f678f09Smk #define UDAV_MAX_MTU 1522 /* According to datasheet */ 211b96f689dSdlg #define UDAV_MIN_FRAME_LEN 60 212b96f689dSdlg #define UDAV_BUFSZ UDAV_MAX_MTU + UDAV_RX_HDRLEN 213