1 /* $NetBSD: if_axereg.h,v 1.5 2008/01/19 22:10:20 dyoung Exp $ */ 2 3 /* 4 * Copyright (c) 1997, 1998, 1999, 2000-2003 5 * Bill Paul <wpaul@windriver.com>. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Bill Paul. 18 * 4. Neither the name of the author nor the names of any co-contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 * THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * $FreeBSD: src/sys/dev/usb/if_axereg.h,v 1.2 2003/06/15 21:45:43 wpaul Exp $ 35 */ 36 37 /* 38 * Definitions for the ASIX Electronics AX88172 to ethernet controller. 39 */ 40 41 42 /* 43 * Vendor specific commands 44 * ASIX conveniently doesn't document the 'set NODEID' command in their 45 * datasheet (thanks a lot guys). 46 * To make handling these commands easier, I added some extra data 47 * which is decided by the axe_cmd() routine. Commands are encoded 48 * in 16 bites, with the format: LDCC. L and D are both nibbles in 49 * the high byte. L represents the data length (0 to 15) and D 50 * represents the direction (0 for vendor read, 1 for vendor write). 51 * CC is the command byte, as specified in the manual. 52 */ 53 54 #define AXE_CMD_DIR(x) (((x) & 0x0F00) >> 8) 55 #define AXE_CMD_LEN(x) (((x) & 0xF000) >> 12) 56 #define AXE_CMD_CMD(x) ((x) & 0x00FF) 57 58 #define AXE_CMD_READ_RXTX_SRAM 0x2002 59 #define AXE_CMD_WRITE_RX_SRAM 0x0103 60 #define AXE_CMD_WRITE_TX_SRAM 0x0104 61 #define AXE_CMD_MII_OPMODE_SW 0x0106 62 #define AXE_CMD_MII_READ_REG 0x2007 63 #define AXE_CMD_MII_WRITE_REG 0x2108 64 #define AXE_CMD_MII_READ_OPMODE 0x1009 65 #define AXE_CMD_MII_OPMODE_HW 0x010A 66 #define AXE_CMD_SROM_READ 0x200B 67 #define AXE_CMD_SROM_WRITE 0x010C 68 #define AXE_CMD_SROM_WR_ENABLE 0x010D 69 #define AXE_CMD_SROM_WR_DISABLE 0x010E 70 #define AXE_CMD_RXCTL_READ 0x200F 71 #define AXE_CMD_RXCTL_WRITE 0x0110 72 #define AXE_CMD_READ_IPG012 0x3011 73 #define AXE_CMD_WRITE_IPG0 0x0112 74 #define AXE_CMD_WRITE_IPG1 0x0113 75 #define AXE_CMD_WRITE_IPG2 0x0114 76 #define AXE_CMD_READ_MCAST 0x8015 77 #define AXE_CMD_WRITE_MCAST 0x8116 78 #define AXE_CMD_READ_NODEID 0x6017 79 #define AXE_CMD_WRITE_NODEID 0x6118 80 #define AXE_CMD_READ_PHYID 0x2019 81 #define AXE_CMD_READ_MEDIA 0x101A 82 #define AXE_CMD_WRITE_MEDIA 0x011B 83 #define AXE_CMD_READ_MONITOR_MODE 0x101C 84 #define AXE_CMD_WRITE_MONITOR_MODE 0x011D 85 #define AXE_CMD_READ_GPIO 0x101E 86 #define AXE_CMD_WRITE_GPIO 0x011F 87 88 #define AXE_MEDIA_FULL_DUPLEX 0x02 89 #define AXE_MEDIA_TX_ABORT_ALLOW 0x04 90 #define AXE_MEDIA_FLOW_CONTROL_EN 0x10 91 92 #define AXE_RXCMD_PROMISC 0x0001 93 #define AXE_RXCMD_ALLMULTI 0x0002 94 #define AXE_RXCMD_UNICAST 0x0004 95 #define AXE_RXCMD_BROADCAST 0x0008 96 #define AXE_RXCMD_MULTICAST 0x0010 97 #define AXE_RXCMD_ENABLE 0x0080 98 99 #define AXE_NOPHY 0xE0 100 101 #define AXE_TIMEOUT 1000 102 #define AXE_BUFSZ 1536 103 #define AXE_MIN_FRAMELEN 60 104 #define AXE_RX_FRAMES 1 105 #define AXE_TX_FRAMES 1 106 107 #define AXE_RX_LIST_CNT 1 108 #define AXE_TX_LIST_CNT 1 109 110 #define AXE_CTL_READ 0x01 111 #define AXE_CTL_WRITE 0x02 112 113 #define AXE_CONFIG_NO 1 114 #define AXE_IFACE_IDX 0 115 116 /* 117 * The interrupt endpoint is currently unused 118 * by the ASIX part. 119 */ 120 #define AXE_ENDPT_RX 0x0 121 #define AXE_ENDPT_TX 0x1 122 #define AXE_ENDPT_INTR 0x2 123 #define AXE_ENDPT_MAX 0x3 124 125 struct axe_type { 126 struct usb_devno axe_dev; 127 u_int16_t axe_flags; 128 /* XXX No flags so far */ 129 }; 130 131 struct axe_softc; 132 133 struct axe_chain { 134 struct axe_softc *axe_sc; 135 usbd_xfer_handle axe_xfer; 136 char *axe_buf; 137 struct mbuf *axe_mbuf; 138 int axe_accum; 139 int axe_idx; 140 }; 141 142 struct axe_cdata { 143 struct axe_chain axe_tx_chain[AXE_TX_LIST_CNT]; 144 struct axe_chain axe_rx_chain[AXE_RX_LIST_CNT]; 145 int axe_tx_prod; 146 int axe_tx_cons; 147 int axe_tx_cnt; 148 int axe_rx_prod; 149 }; 150 151 #define AXE_INC(x, y) (x) = (x + 1) % y 152 153 struct axe_softc { 154 USBBASEDEVICE axe_dev; 155 #if defined(__FreeBSD__) 156 struct arpcom arpcom; 157 device_t axe_miibus; 158 #define GET_IFP(sc) (&(sc)->arpcom.ac_if) 159 #define GET_MII(sc) (device_get_softc((sc)->axe_miibus)) 160 #elif defined(__NetBSD__) 161 struct ethercom axe_ec; 162 struct mii_data axe_mii; 163 #if NRND > 0 164 rndsource_element_t rnd_source; 165 #endif 166 #define GET_IFP(sc) (&(sc)->axe_ec.ec_if) 167 #define GET_MII(sc) (&(sc)->axe_mii) 168 #elif defined(__OpenBSD__) 169 struct arpcom arpcom; 170 struct mii_data axe_mii; 171 #if NRND > 0 172 rndsource_element_t rnd_source; 173 #endif 174 #define GET_IFP(sc) (&(sc)->arpcom.ac_if) 175 #define GET_MII(sc) (&(sc)->axe_mii) 176 #endif 177 usbd_device_handle axe_udev; 178 usbd_interface_handle axe_iface; 179 180 u_int16_t axe_vendor; 181 u_int16_t axe_product; 182 183 int axe_ed[AXE_ENDPT_MAX]; 184 usbd_pipe_handle axe_ep[AXE_ENDPT_MAX]; 185 int axe_if_flags; 186 struct axe_cdata axe_cdata; 187 usb_callout_t axe_stat_ch; 188 189 int axe_refcnt; 190 char axe_dying; 191 char axe_attached; 192 193 struct usb_task axe_tick_task; 194 struct usb_task axe_stop_task; 195 196 kmutex_t axe_mii_lock; 197 198 unsigned char axe_ipgs[3]; 199 unsigned char axe_phyaddrs[2]; 200 struct timeval axe_rx_notice; 201 }; 202 203 #if 0 204 #define AXE_LOCK(_sc) mtx_lock(&(_sc)->axe_mtx) 205 #define AXE_UNLOCK(_sc) mtx_unlock(&(_sc)->axe_mtx) 206 #else 207 #define AXE_LOCK(_sc) 208 #define AXE_UNLOCK(_sc) 209 #endif 210 211 #define ETHER_ALIGN 2 212