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