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