1 /* $OpenBSD: lemacvar.h,v 1.1 2001/07/13 17:26:44 niklas Exp $ */ 2 /* $NetBSD: lemacvar.h,v 1.6 2001/06/13 10:46:03 wiz Exp $ */ 3 4 /* 5 * Copyright (c) 1997 Matt Thomas <matt@3am-software.com> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef _LEMAC_VAR_H 29 #define _LEMAC_VAR_H 30 31 /* 32 * Ethernet status, per interface. 33 */ 34 struct lemac_softc { 35 struct device sc_dv; 36 void *sc_ih; 37 void *sc_ats; 38 struct arpcom sc_arpcom; /* Ethernet common part */ 39 struct ifmedia sc_ifmedia; 40 bus_space_tag_t sc_iot; 41 bus_space_tag_t sc_memt; 42 bus_space_handle_t sc_ioh; 43 bus_space_handle_t sc_memh; 44 unsigned sc_flags; 45 #define LEMAC_PIO_MODE 0x0000U 46 #define LEMAC_2K_MODE 0x0001U 47 #define LEMAC_WAS_32K_MODE 0x0002U 48 #define LEMAC_WAS_64K_MODE 0x0003U 49 #define LEMAC_MODE_MASK 0x0003U 50 #define LEMAC_ALLMULTI 0x0010U 51 #define LEMAC_ALIVE 0x0020U 52 #define LEMAC_LINKUP 0x0040U 53 unsigned sc_lastpage; /* last 2K page */ 54 unsigned sc_txctl; /* Transmit Control Byte */ 55 unsigned sc_ctlmode; /* media ctl bits */ 56 struct { 57 u_int8_t csr_cs; 58 u_int8_t csr_tqc; 59 u_int8_t csr_fmq; 60 } sc_csr; 61 unsigned sc_laststatus; /* last read of LEMAC_REG_CS */ 62 u_int16_t sc_mctbl[LEMAC_MCTBL_SIZE/sizeof(u_int16_t)]; 63 /* local copy of multicast table */ 64 struct { 65 unsigned cntr_txnospc; /* total # of no trnasmit memory */ 66 unsigned cntr_txfull; /* total # of tranmitter full */ 67 unsigned cntr_tne_intrs;/* total # of tranmit done intrs */ 68 unsigned cntr_rne_intrs;/* total # of receive done intrs */ 69 unsigned cntr_txd_intrs;/* total # of tranmit error intrs */ 70 unsigned cntr_rxd_intrs;/* total # of receive error intrs */ 71 } sc_cntrs; 72 73 /* 74 * We rely on sc_enaddr being aligned on (at least) a 16 bit boundary 75 */ 76 unsigned char sc_enaddr[ETHER_ADDR_LEN];/* current Ethernet address */ 77 char sc_prodname[LEMAC_EEP_PRDNMSZ+1]; /* product name DE20x-xx */ 78 u_int8_t sc_eeprom[LEMAC_EEP_SIZE]; /* local copy eeprom */ 79 }; 80 81 #define sc_if sc_arpcom.ac_if 82 83 #define LEMAC_IFP_TO_SOFTC(ifp) ((struct lemac_softc *)((ifp)->if_softc)) 84 #define LEMAC_USE_PIO_MODE(sc) \ 85 (((sc->sc_flags & LEMAC_MODE_MASK) == LEMAC_PIO_MODE) || \ 86 (sc->sc_if.if_flags & IFF_LINK0)) 87 88 #define LEMAC_OUTB(sc, o, v) \ 89 bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, (o), (v)) 90 #define LEMAC_OUTSB(sc, o, l, p) \ 91 bus_space_write_multi_1((sc)->sc_iot, (sc)->sc_ioh, (o), (p), (l)) 92 #define LEMAC_INB(sc, o) \ 93 bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, (o)) 94 #define LEMAC_INSB(sc, o, l, p) \ 95 bus_space_read_multi_1((sc)->sc_iot, (sc)->sc_ioh, (o), (p), (l)) 96 97 #define LEMAC_PUTBUF8(sc, o, l, p) \ 98 bus_space_write_region_1((sc)->sc_memt, (sc)->sc_memh, (o), (p), (l)) 99 #define LEMAC_PUTBUF16(sc, o, l, p) \ 100 bus_space_write_raw_region_2((sc)->sc_memt, (sc)->sc_memh, (o), (p), \ 101 (l) << 1) 102 #define LEMAC_PUTBUF32(sc, o, l, p) \ 103 bus_space_write_raw_region_4((sc)->sc_memt, (sc)->sc_memh, (o), (p), \ 104 (l) << 2) 105 106 #define LEMAC_PUT8(sc, o, v) \ 107 bus_space_write_1((sc)->sc_memt, (sc)->sc_memh, (o), (v)) 108 #define LEMAC_PUT16(sc, o, v) \ 109 bus_space_write_2((sc)->sc_memt, (sc)->sc_memh, (o), htole16(v)) 110 #define LEMAC_PUT32(sc, o, v) \ 111 bus_space_write_4((sc)->sc_memt, (sc)->sc_memh, (o), htole32(v)) 112 113 #define LEMAC_GETBUF8(sc, o, l, p) \ 114 bus_space_read_region_1((sc)->sc_memt, (sc)->sc_memh, (o), (p), (l)) 115 #define LEMAC_GETBUF16(sc, o, l, p) \ 116 bus_space_read_raw_region_2((sc)->sc_memt, (sc)->sc_memh, (o), (p), \ 117 (l) << 1) 118 #define LEMAC_GETBUF32(sc, o, l, p) \ 119 bus_space_read_raw_region_4((sc)->sc_memt, (sc)->sc_memh, (o), (p), \ 120 (l) << 2) 121 122 #define LEMAC_GET8(sc, o) \ 123 bus_space_read_1((sc)->sc_memt, (sc)->sc_memh, (o)) 124 #define LEMAC_GET16(sc, o) \ 125 letoh16(bus_space_read_2((sc)->sc_memt, (sc)->sc_memh, (o))) 126 #define LEMAC_GET32(sc, o) \ 127 letoh32(bus_space_read_4((sc)->sc_memt, (sc)->sc_memh, (o))) 128 129 #define LEMAC_INTR_ENABLE(sc) \ 130 LEMAC_OUTB(sc, LEMAC_REG_IC, \ 131 LEMAC_INB(sc, LEMAC_REG_IC) | LEMAC_IC_ALL) 132 133 #define LEMAC_INTR_DISABLE(sc) \ 134 LEMAC_OUTB(sc, LEMAC_REG_IC, \ 135 LEMAC_INB(sc, LEMAC_REG_IC) & ~LEMAC_IC_ALL) 136 137 #define LEMAC_IS_64K_MODE(mbase) (((mbase) >= 0x0A) && ((mbase) <= 0x0F)) 138 #define LEMAC_IS_32K_MODE(mbase) (((mbase) >= 0x14) && ((mbase) <= 0x1F)) 139 #define LEMAC_IS_2K_MODE(mbase) ((mbase) >= 0x40) 140 141 #define LEMAC_DECODEIRQ(i) ((0xFBA5 >> ((i) >> 3)) & 0x0F) 142 143 #define LEMAC_ADDREQUAL(a1, a2) \ 144 (((u_int16_t *)a1)[0] == ((u_int16_t *)a2)[0] && \ 145 ((u_int16_t *)a1)[1] == ((u_int16_t *)a2)[1] && \ 146 ((u_int16_t *)a1)[2] == ((u_int16_t *)a2)[2]) 147 148 #define LEMAC_ADDRBRDCST(a1) \ 149 (((u_int16_t *)a1)[0] == 0xFFFFU && \ 150 ((u_int16_t *)a1)[1] == 0xFFFFU && \ 151 ((u_int16_t *)a1)[2] == 0xFFFFU) 152 153 void lemac_ifattach(struct lemac_softc *); 154 void lemac_info_get(const bus_space_tag_t, const bus_space_handle_t, 155 bus_addr_t *, bus_size_t *, int *); 156 int lemac_port_check(const bus_space_tag_t, const bus_space_handle_t); 157 int lemac_intr(void *); 158 void lemac_shutdown(void *); 159 160 #endif /* _LEMACVAR_H */ 161