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