1 /*- 2 * Copyright (c) 2003 The NetBSD Foundation, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the NetBSD 16 * Foundation, Inc. and its contributors. 17 * 4. Neither the name of The NetBSD Foundation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * Copyright (c) 1997, 1998, 1999, 2000 36 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 3. All advertising materials mentioning features or use of this software 47 * must display the following acknowledgement: 48 * This product includes software developed by Bill Paul. 49 * 4. Neither the name of the author nor the names of any co-contributors 50 * may be used to endorse or promote products derived from this software 51 * without specific prior written permission. 52 * 53 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 57 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 58 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 59 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 60 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 61 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 62 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 63 * THE POSSIBILITY OF SUCH DAMAGE. 64 * 65 * 66 * $FreeBSD: /c/ncvs/src/sys/pci/if_skreg.h,v 1.9 2000/04/22 02:16:37 wpaul Exp $ 67 * $NetBSD: if_skvar.h,v 1.6 2005/05/30 04:35:22 christos Exp $ 68 * $OpenBSD: if_skvar.h,v 1.2 2005/12/22 20:54:47 brad Exp $ 69 * $DragonFly: src/sys/dev/netif/sk/if_skvar.h,v 1.4 2007/12/14 11:37:11 sephe 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 _IF_SKVAR_H_ 89 #define _IF_SKVAR_H_ 90 91 struct sk_jpool_entry { 92 struct sk_if_softc *sc_if; 93 int inuse; 94 int slot; 95 void *buf; 96 bus_addr_t paddr; 97 SLIST_ENTRY(sk_jpool_entry) entry_next; 98 }; 99 100 /* 101 * Number of DMA segments in a TxCB. Note that this is carefully 102 * chosen to make the total struct size an even power of two. It's 103 * critical that no TxCB be split across a page boundary since 104 * no attempt is made to allocate physically contiguous memory. 105 */ 106 #define SK_NTXSEG 30 107 108 struct sk_chain_data { 109 bus_dma_tag_t sk_buf_dtag; 110 111 struct mbuf *sk_tx_mbuf[SK_TX_RING_CNT]; 112 bus_dma_tag_t sk_tx_dtag; 113 bus_dmamap_t sk_tx_dmap[SK_TX_RING_CNT]; 114 int sk_tx_prod; 115 int sk_tx_cons; 116 int sk_tx_cnt; 117 118 struct mbuf *sk_rx_mbuf[SK_RX_RING_CNT]; 119 bus_dma_tag_t sk_rx_dtag; 120 bus_dmamap_t sk_rx_dmap[SK_RX_RING_CNT]; 121 bus_dmamap_t sk_rx_dmap_tmp; 122 int sk_rx_prod; 123 int sk_rx_cons; 124 int sk_rx_cnt; 125 126 struct lwkt_serialize sk_jpool_serializer; 127 bus_dma_tag_t sk_jpool_dtag; 128 bus_dmamap_t sk_jpool_dmap; 129 void *sk_jpool; 130 struct sk_jpool_entry sk_jpool_ent[SK_JSLOTS]; 131 SLIST_HEAD(, sk_jpool_entry) sk_jpool_free_ent; 132 }; 133 134 struct sk_ring_data { 135 bus_dma_tag_t sk_ring_dtag; 136 137 bus_dma_tag_t sk_tx_ring_dtag; 138 bus_dmamap_t sk_tx_ring_dmap; 139 bus_addr_t sk_tx_ring_paddr; 140 struct sk_tx_desc *sk_tx_ring; 141 142 bus_dma_tag_t sk_rx_ring_dtag; 143 bus_dmamap_t sk_rx_ring_dmap; 144 bus_addr_t sk_rx_ring_paddr; 145 struct sk_rx_desc *sk_rx_ring; 146 }; 147 148 struct sk_bcom_hack { 149 int reg; 150 int val; 151 }; 152 153 #define SK_INC(x, y) (x) = (x + 1) % y 154 155 /* Forward decl. */ 156 struct sk_if_softc; 157 158 /* Softc for the GEnesis controller. */ 159 struct sk_softc { 160 device_t sk_dev; 161 int sk_res_rid; 162 struct resource *sk_res; 163 bus_space_handle_t sk_bhandle; /* bus space handle */ 164 bus_space_tag_t sk_btag; /* bus space tag */ 165 166 int sk_irq_rid; 167 struct resource *sk_irq; 168 void *sk_intrhand; /* irq handler handle */ 169 170 uint8_t sk_coppertype; 171 uint8_t sk_pmd; /* physical media type */ 172 uint8_t sk_type; 173 uint8_t sk_rev; 174 uint8_t sk_macs; /* # of MACs */ 175 uint32_t sk_rboff; /* RAMbuffer offset */ 176 uint32_t sk_ramsize; /* amount of RAM on NIC */ 177 uint32_t sk_intrmask; 178 uint32_t sk_imtimer_ticks; 179 int sk_imtime; 180 struct sysctl_ctx_list sk_sysctl_ctx; 181 struct sysctl_oid *sk_sysctl_tree; 182 struct lwkt_serialize sk_serializer; 183 struct sk_if_softc *sk_if[2]; 184 device_t sk_devs[2]; 185 }; 186 187 /* Softc for each logical interface */ 188 struct sk_if_softc { 189 struct arpcom arpcom; /* interface info */ 190 device_t sk_miibus; 191 uint8_t sk_port; /* port # on controller */ 192 uint8_t sk_xmac_rev; /* XMAC chip rev (B2 or C1) */ 193 uint32_t sk_rx_ramstart; 194 uint32_t sk_rx_ramend; 195 uint32_t sk_tx_ramstart; 196 uint32_t sk_tx_ramend; 197 uint8_t sk_phytype; 198 int sk_phyaddr; 199 int sk_cnt; 200 int sk_link; 201 struct callout sk_tick_timer; 202 struct sk_chain_data sk_cdata; 203 struct sk_ring_data sk_rdata; 204 bus_dma_tag_t sk_parent_dtag; 205 struct sk_softc *sk_softc; /* parent controller */ 206 int sk_tx_bmu; /* TX BMU register */ 207 int sk_if_flags; 208 int sk_use_jumbo; 209 }; 210 211 #define SK_NDESC_RESERVE 2 212 #define SK_NDESC_SPARE 5 213 214 #define SK_IS_OACTIVE(sc_if) \ 215 ((sc_if)->sk_cdata.sk_tx_cnt + SK_NDESC_RESERVE + SK_NDESC_SPARE > \ 216 SK_TX_RING_CNT) 217 218 #endif /* !_IF_SKVAR_H_ */ 219