1 1.5 andvar /* $NetBSD: aic6915var.h,v 1.5 2022/05/04 07:32:50 andvar Exp $ */ 2 1.1 thorpej 3 1.1 thorpej /*- 4 1.1 thorpej * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 1.1 thorpej * All rights reserved. 6 1.1 thorpej * 7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.1 thorpej * by Jason R. Thorpe. 9 1.1 thorpej * 10 1.1 thorpej * Redistribution and use in source and binary forms, with or without 11 1.1 thorpej * modification, are permitted provided that the following conditions 12 1.1 thorpej * are met: 13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright 14 1.1 thorpej * notice, this list of conditions and the following disclaimer. 15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the 17 1.1 thorpej * documentation and/or other materials provided with the distribution. 18 1.1 thorpej * 19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE. 30 1.1 thorpej */ 31 1.1 thorpej 32 1.1 thorpej #ifndef _DEV_IC_AIC6915VAR_H_ 33 1.1 thorpej #define _DEV_IC_AIC6915VAR_H_ 34 1.1 thorpej 35 1.1 thorpej #include <sys/callout.h> 36 1.1 thorpej 37 1.1 thorpej /* 38 1.1 thorpej * Data structure definitions for the Adaptec AIC-6915 (``Starfire'') 39 1.1 thorpej * PCI 10/100 Ethernet controller driver. 40 1.1 thorpej */ 41 1.1 thorpej 42 1.1 thorpej /* 43 1.1 thorpej * Transmit descriptor list size. 44 1.1 thorpej */ 45 1.1 thorpej #define SF_NTXDESC 256 46 1.1 thorpej #define SF_NTXDESC_MASK (SF_NTXDESC - 1) 47 1.1 thorpej #define SF_NEXTTX(x) ((x + 1) & SF_NTXDESC_MASK) 48 1.1 thorpej 49 1.1 thorpej /* 50 1.1 thorpej * Transmit completion queue size. 1024 is a hardware requirement. 51 1.1 thorpej */ 52 1.1 thorpej #define SF_NTCD 1024 53 1.1 thorpej #define SF_NTCD_MASK (SF_NTCD - 1) 54 1.1 thorpej #define SF_NEXTTCD(x) ((x + 1) & SF_NTCD_MASK) 55 1.1 thorpej 56 1.1 thorpej /* 57 1.1 thorpej * Receive descriptor list size. 58 1.1 thorpej */ 59 1.1 thorpej #define SF_NRXDESC 256 60 1.1 thorpej #define SF_NRXDESC_MASK (SF_NRXDESC - 1) 61 1.1 thorpej #define SF_NEXTRX(x) ((x + 1) & SF_NRXDESC_MASK) 62 1.1 thorpej 63 1.1 thorpej /* 64 1.1 thorpej * Receive completion queue size. 1024 is a hardware requirement. 65 1.1 thorpej */ 66 1.1 thorpej #define SF_NRCD 1024 67 1.1 thorpej #define SF_NRCD_MASK (SF_NRCD - 1) 68 1.1 thorpej #define SF_NEXTRCD(x) ((x + 1) & SF_NRCD_MASK) 69 1.1 thorpej 70 1.1 thorpej /* 71 1.1 thorpej * Control structures are DMA to the Starfire chip. We allocate them in 72 1.1 thorpej * a single clump that maps to a single DMA segment to make several things 73 1.1 thorpej * easier. 74 1.1 thorpej */ 75 1.1 thorpej struct sf_control_data { 76 1.1 thorpej /* 77 1.1 thorpej * The transmit descriptors. 78 1.1 thorpej */ 79 1.1 thorpej struct sf_txdesc0 scd_txdescs[SF_NTXDESC]; 80 1.1 thorpej 81 1.1 thorpej /* 82 1.5 andvar * The transmit completion queue entries. 83 1.1 thorpej */ 84 1.1 thorpej struct sf_tcd scd_txcomp[SF_NTCD]; 85 1.1 thorpej 86 1.1 thorpej /* 87 1.1 thorpej * The receive buffer descriptors. 88 1.1 thorpej */ 89 1.1 thorpej struct sf_rbd32 scd_rxbufdescs[SF_NRXDESC]; 90 1.1 thorpej 91 1.1 thorpej /* 92 1.1 thorpej * The receive completion queue entries. 93 1.1 thorpej */ 94 1.1 thorpej struct sf_rcd_full scd_rxcomp[SF_NRCD]; 95 1.1 thorpej }; 96 1.1 thorpej 97 1.1 thorpej #define SF_CDOFF(x) offsetof(struct sf_control_data, x) 98 1.1 thorpej #define SF_CDTXDOFF(x) SF_CDOFF(scd_txdescs[(x)]) 99 1.1 thorpej #define SF_CDTXCOFF(x) SF_CDOFF(scd_txcomp[(x)]) 100 1.1 thorpej #define SF_CDRXDOFF(x) SF_CDOFF(scd_rxbufdescs[(x)]) 101 1.1 thorpej #define SF_CDRXCOFF(x) SF_CDOFF(scd_rxcomp[(x)]) 102 1.1 thorpej 103 1.1 thorpej /* 104 1.1 thorpej * Software state for transmit and receive descriptors. 105 1.1 thorpej */ 106 1.1 thorpej struct sf_descsoft { 107 1.1 thorpej struct mbuf *ds_mbuf; /* head of mbuf chain */ 108 1.1 thorpej bus_dmamap_t ds_dmamap; /* our DMA map */ 109 1.1 thorpej }; 110 1.1 thorpej 111 1.1 thorpej /* 112 1.1 thorpej * Software state per device. 113 1.1 thorpej */ 114 1.1 thorpej struct sf_softc { 115 1.4 chs device_t sc_dev; /* generic device information */ 116 1.1 thorpej bus_space_tag_t sc_st; /* bus space tag */ 117 1.1 thorpej bus_space_handle_t sc_sh; /* bus space handle */ 118 1.1 thorpej bus_space_handle_t sc_sh_func; /* sub-handle for func regs */ 119 1.1 thorpej bus_dma_tag_t sc_dmat; /* bus DMA tag */ 120 1.1 thorpej struct ethercom sc_ethercom; /* ethernet common data */ 121 1.1 thorpej int sc_iomapped; /* are we I/O mapped? */ 122 1.1 thorpej 123 1.1 thorpej struct mii_data sc_mii; /* MII/media information */ 124 1.1 thorpej struct callout sc_tick_callout; /* MII callout */ 125 1.1 thorpej 126 1.1 thorpej bus_dmamap_t sc_cddmamap; /* control data DMA map */ 127 1.1 thorpej #define sc_cddma sc_cddmamap->dm_segs[0].ds_addr 128 1.1 thorpej 129 1.1 thorpej /* 130 1.1 thorpej * Software state for transmit and receive descriptors. 131 1.1 thorpej */ 132 1.1 thorpej struct sf_descsoft sc_txsoft[SF_NTXDESC]; 133 1.1 thorpej struct sf_descsoft sc_rxsoft[SF_NRXDESC]; 134 1.1 thorpej 135 1.1 thorpej /* 136 1.1 thorpej * Control data structures. 137 1.1 thorpej */ 138 1.1 thorpej struct sf_control_data *sc_control_data; 139 1.1 thorpej #define sc_txdescs sc_control_data->scd_txdescs 140 1.1 thorpej #define sc_txcomp sc_control_data->scd_txcomp 141 1.1 thorpej #define sc_rxbufdescs sc_control_data->scd_rxbufdescs 142 1.1 thorpej #define sc_rxcomp sc_control_data->scd_rxcomp 143 1.1 thorpej 144 1.1 thorpej int sc_txpending; /* number of Tx requests pending */ 145 1.1 thorpej 146 1.1 thorpej uint32_t sc_InterruptEn; /* prototype InterruptEn register */ 147 1.1 thorpej 148 1.1 thorpej uint32_t sc_TransmitFrameCSR; /* prototype TransmitFrameCSR reg */ 149 1.1 thorpej uint32_t sc_TxDescQueueCtrl; /* prototype TxDescQueueCtrl reg */ 150 1.1 thorpej int sc_txthresh; /* current Tx threshold */ 151 1.1 thorpej 152 1.1 thorpej uint32_t sc_MacConfig1; /* prototype MacConfig1 register */ 153 1.1 thorpej 154 1.1 thorpej uint32_t sc_RxAddressFilteringCtl; 155 1.1 thorpej }; 156 1.1 thorpej 157 1.1 thorpej #define SF_CDTXDADDR(sc, x) ((sc)->sc_cddma + SF_CDTXDOFF((x))) 158 1.1 thorpej #define SF_CDTXCADDR(sc, x) ((sc)->sc_cddma + SF_CDTXCOFF((x))) 159 1.1 thorpej #define SF_CDRXDADDR(sc, x) ((sc)->sc_cddma + SF_CDRXDOFF((x))) 160 1.1 thorpej #define SF_CDRXCADDR(sc, x) ((sc)->sc_cddma + SF_CDRXCOFF((x))) 161 1.1 thorpej 162 1.1 thorpej #define SF_CDTXDSYNC(sc, x, ops) \ 163 1.1 thorpej bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ 164 1.1 thorpej SF_CDTXDOFF((x)), sizeof(struct sf_txdesc0), (ops)) 165 1.1 thorpej 166 1.1 thorpej #define SF_CDTXCSYNC(sc, x, ops) \ 167 1.1 thorpej bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ 168 1.1 thorpej SF_CDTXCOFF((x)), sizeof(struct sf_tcd), (ops)) 169 1.1 thorpej 170 1.1 thorpej #define SF_CDRXDSYNC(sc, x, ops) \ 171 1.1 thorpej bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ 172 1.1 thorpej SF_CDRXDOFF((x)), sizeof(struct sf_rbd32), (ops)) 173 1.1 thorpej 174 1.1 thorpej #define SF_CDRXCSYNC(sc, x, ops) \ 175 1.1 thorpej bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ 176 1.1 thorpej SF_CDRXCOFF((x)), sizeof(struct sf_rcd_full), (ops)) 177 1.1 thorpej 178 1.1 thorpej #define SF_INIT_RXDESC(sc, x) \ 179 1.1 thorpej do { \ 180 1.1 thorpej struct sf_descsoft *__ds = &sc->sc_rxsoft[(x)]; \ 181 1.1 thorpej \ 182 1.1 thorpej (sc)->sc_rxbufdescs[(x)].rbd32_addr = \ 183 1.1 thorpej __ds->ds_dmamap->dm_segs[0].ds_addr | RBD_V; \ 184 1.1 thorpej SF_CDRXDSYNC((sc), (x), BUS_DMASYNC_PREWRITE); \ 185 1.1 thorpej } while (/*CONSTCOND*/0) 186 1.1 thorpej 187 1.1 thorpej #ifdef _KERNEL 188 1.1 thorpej void sf_attach(struct sf_softc *); 189 1.1 thorpej int sf_intr(void *); 190 1.1 thorpej #endif /* _KERNEL */ 191 1.1 thorpej 192 1.1 thorpej #endif /* _DEV_IC_AIC6915VAR_H_ */ 193