1 /* $NetBSD: if_skvar.h,v 1.18 2015/04/13 16:33:25 riastradh Exp $ */ 2 3 /*- 4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 5 * 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 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 /* $OpenBSD: if_skreg.h,v 1.10 2003/08/12 05:23:06 nate Exp $ */ 29 30 /* 31 * Copyright (c) 1997, 1998, 1999, 2000 32 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 33 * 34 * Redistribution and use in source and binary forms, with or without 35 * modification, are permitted provided that the following conditions 36 * are met: 37 * 1. Redistributions of source code must retain the above copyright 38 * notice, this list of conditions and the following disclaimer. 39 * 2. Redistributions in binary form must reproduce the above copyright 40 * notice, this list of conditions and the following disclaimer in the 41 * documentation and/or other materials provided with the distribution. 42 * 3. All advertising materials mentioning features or use of this software 43 * must display the following acknowledgement: 44 * This product includes software developed by Bill Paul. 45 * 4. Neither the name of the author nor the names of any co-contributors 46 * may be used to endorse or promote products derived from this software 47 * without specific prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 53 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 54 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 55 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 56 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 57 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 59 * THE POSSIBILITY OF SUCH DAMAGE. 60 * 61 * $FreeBSD: /c/ncvs/src/sys/pci/if_skreg.h,v 1.9 2000/04/22 02:16:37 wpaul Exp $ 62 */ 63 64 /* 65 * Copyright (c) 2003 Nathan L. Binkert <binkertn@umich.edu> 66 * 67 * Permission to use, copy, modify, and distribute this software for any 68 * purpose with or without fee is hereby granted, provided that the above 69 * copyright notice and this permission notice appear in all copies. 70 * 71 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 72 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 73 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 74 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 75 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 76 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 77 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 78 */ 79 80 #ifndef _DEV_PCI_IF_SKVAR_H_ 81 #define _DEV_PCI_IF_SKVAR_H_ 82 83 #include <sys/rndsource.h> 84 85 struct sk_jpool_entry { 86 int slot; 87 LIST_ENTRY(sk_jpool_entry) jpool_entries; 88 }; 89 90 struct sk_chain { 91 void *sk_desc; 92 struct mbuf *sk_mbuf; 93 struct sk_chain *sk_next; 94 }; 95 96 /* 97 * Number of DMA segments in a TxCB. Note that this is carefully 98 * chosen to make the total struct size an even power of two. It's 99 * critical that no TxCB be split across a page boundary since 100 * no attempt is made to allocate physically contiguous memory. 101 * 102 */ 103 #define SK_NTXSEG 30 104 105 struct sk_txmap_entry { 106 bus_dmamap_t dmamap; 107 SIMPLEQ_ENTRY(sk_txmap_entry) link; 108 }; 109 110 struct sk_chain_data { 111 struct sk_chain sk_tx_chain[SK_TX_RING_CNT]; 112 struct sk_chain sk_rx_chain[SK_RX_RING_CNT]; 113 struct sk_txmap_entry *sk_tx_map[SK_TX_RING_CNT]; 114 bus_dmamap_t sk_rx_map[SK_RX_RING_CNT]; 115 bus_dmamap_t sk_rx_jumbo_map; 116 int sk_tx_prod; 117 int sk_tx_cons; 118 int sk_tx_cnt; 119 int sk_rx_prod; 120 int sk_rx_cons; 121 int sk_rx_cnt; 122 /* Stick the jumbo mem management stuff here too. */ 123 void * sk_jslots[SK_JSLOTS]; 124 void *sk_jumbo_buf; 125 126 }; 127 128 struct sk_ring_data { 129 struct sk_tx_desc sk_tx_ring[SK_TX_RING_CNT]; 130 struct sk_rx_desc sk_rx_ring[SK_RX_RING_CNT]; 131 }; 132 133 #define SK_TX_RING_ADDR(sc, i) \ 134 ((sc)->sk_ring_map->dm_segs[0].ds_addr + \ 135 offsetof(struct sk_ring_data, sk_tx_ring[(i)])) 136 137 #define SK_RX_RING_ADDR(sc, i) \ 138 ((sc)->sk_ring_map->dm_segs[0].ds_addr + \ 139 offsetof(struct sk_ring_data, sk_rx_ring[(i)])) 140 141 #define SK_CDOFF(x) offsetof(struct sk_ring_data, x) 142 #define SK_CDTXOFF(x) SK_CDOFF(sk_tx_ring[(x)]) 143 #define SK_CDRXOFF(x) SK_CDOFF(sk_rx_ring[(x)]) 144 145 #define SK_CDTXSYNC(sc, x, n, ops) \ 146 do { \ 147 int __x, __n; \ 148 \ 149 __x = (x); \ 150 __n = (n); \ 151 \ 152 /* If it will wrap around, sync to the end of the ring. */ \ 153 if ((__x + __n) > SK_TX_RING_CNT) { \ 154 bus_dmamap_sync((sc)->sk_softc->sc_dmatag, \ 155 (sc)->sk_ring_map, SK_CDTXOFF(__x), \ 156 sizeof(struct sk_tx_desc) * (SK_TX_RING_CNT - __x),\ 157 (ops)); \ 158 __n -= (SK_TX_RING_CNT - __x); \ 159 __x = 0; \ 160 } \ 161 \ 162 /* Now sync whatever is left. */ \ 163 bus_dmamap_sync((sc)->sk_softc->sc_dmatag, (sc)->sk_ring_map, \ 164 SK_CDTXOFF((__x)), sizeof(struct sk_tx_desc) * __n, (ops)); \ 165 } while (/*CONSTCOND*/0) 166 167 #define SK_CDRXSYNC(sc, x, ops) \ 168 do { \ 169 bus_dmamap_sync((sc)->sk_softc->sc_dmatag, (sc)->sk_ring_map, \ 170 SK_CDRXOFF((x)), sizeof(struct sk_rx_desc), (ops)); \ 171 } while (/*CONSTCOND*/0) 172 173 struct sk_bcom_hack { 174 int reg; 175 int val; 176 }; 177 178 #define SK_INC(x, y) (x) = (x + 1) % y 179 180 /* Forward decl. */ 181 struct sk_if_softc; 182 183 /* Softc for the GEnesis controller. */ 184 struct sk_softc { 185 device_t sk_dev; /* generic device */ 186 bus_space_handle_t sk_bhandle; /* bus space handle */ 187 bus_space_tag_t sk_btag; /* bus space tag */ 188 void *sk_intrhand; /* irq handler handle */ 189 u_int8_t sk_type; 190 u_int8_t sk_rev; 191 const char *sk_name; 192 char *sk_vpd_prodname; 193 char *sk_vpd_readonly; 194 u_int32_t sk_rboff; /* RAMbuffer offset */ 195 u_int32_t sk_ramsize; /* amount of RAM on NIC */ 196 u_int32_t sk_pmd; /* physical media type */ 197 u_int32_t sk_intrmask; 198 struct sysctllog *sk_clog; 199 int sk_int_mod; 200 int sk_int_mod_pending; 201 bus_dma_tag_t sc_dmatag; 202 struct sk_if_softc *sk_if[2]; 203 krndsource_t rnd_source; 204 }; 205 206 /* Softc for each logical interface */ 207 struct sk_if_softc { 208 device_t sk_dev; /* generic device */ 209 struct ethercom sk_ethercom; /* interface info */ 210 struct mii_data sk_mii; 211 u_int8_t sk_enaddr[ETHER_ADDR_LEN]; /* station addr */ 212 u_int8_t sk_port; /* port # on controller */ 213 u_int8_t sk_xmac_rev; /* XMAC chip rev (B2 or C1) */ 214 u_int32_t sk_rx_ramstart; 215 u_int32_t sk_rx_ramend; 216 u_int32_t sk_tx_ramstart; 217 u_int32_t sk_tx_ramend; 218 int sk_phytype; 219 int sk_phyaddr; 220 int sk_cnt; 221 int sk_link; 222 struct callout sk_tick_ch; 223 struct sk_chain_data sk_cdata; 224 struct sk_ring_data *sk_rdata; 225 bus_dmamap_t sk_ring_map; 226 struct sk_softc *sk_softc; /* parent controller */ 227 int sk_tx_bmu; /* TX BMU register */ 228 int sk_if_flags; 229 kmutex_t sk_jpool_mtx; 230 LIST_HEAD(__sk_jfreehead, sk_jpool_entry) sk_jfree_listhead; 231 LIST_HEAD(__sk_jinusehead, sk_jpool_entry) sk_jinuse_listhead; 232 SIMPLEQ_HEAD(__sk_txmaphead, sk_txmap_entry) sk_txmap_head; 233 }; 234 235 struct skc_attach_args { 236 u_int16_t skc_port; 237 }; 238 239 #endif /* _DEV_PCI_IF_SKVAR_H_ */ 240