if_hmevar.h revision 137982
191396Stmm/*-
291396Stmm * Copyright (c) 1999 The NetBSD Foundation, Inc.
391396Stmm * All rights reserved.
491396Stmm *
591396Stmm * This code is derived from software contributed to The NetBSD Foundation
691396Stmm * by Paul Kranenburg.
791396Stmm *
891396Stmm * Redistribution and use in source and binary forms, with or without
991396Stmm * modification, are permitted provided that the following conditions
1091396Stmm * are met:
1191396Stmm * 1. Redistributions of source code must retain the above copyright
1291396Stmm *    notice, this list of conditions and the following disclaimer.
1391396Stmm * 2. Redistributions in binary form must reproduce the above copyright
1491396Stmm *    notice, this list of conditions and the following disclaimer in the
1591396Stmm *    documentation and/or other materials provided with the distribution.
1691396Stmm * 3. All advertising materials mentioning features or use of this software
1791396Stmm *    must display the following acknowledgement:
1891396Stmm *        This product includes software developed by the NetBSD
1991396Stmm *        Foundation, Inc. and its contributors.
2091396Stmm * 4. Neither the name of The NetBSD Foundation nor the names of its
2191396Stmm *    contributors may be used to endorse or promote products derived
2291396Stmm *    from this software without specific prior written permission.
2391396Stmm *
2491396Stmm * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2591396Stmm * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2691396Stmm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2791396Stmm * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2891396Stmm * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2991396Stmm * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3091396Stmm * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3191396Stmm * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3291396Stmm * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3391396Stmm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3491396Stmm * POSSIBILITY OF SUCH DAMAGE.
3591396Stmm *
3691396Stmm *	from: NetBSD: hmevar.h,v 1.5 2000/06/25 01:10:04 eeh Exp
3791396Stmm *
3891396Stmm * $FreeBSD: head/sys/dev/hme/if_hmevar.h 137982 2004-11-22 06:46:30Z yongari $
3991396Stmm */
4091396Stmm
4191396Stmm#include <sys/callout.h>
4291396Stmm
4391396Stmm/*
4491396Stmm * Number of receive and transmit descriptors. For each receive descriptor,
4591396Stmm * an mbuf cluster is allocated and set up to receive a packet, and a dma map
4691396Stmm * is created. Therefore, this number should not be too high to not waste
4791396Stmm * memory.
48108834Stmm * TX descriptors have no static cost, except for the memory directly allocated
49108834Stmm * for them. TX queue elements (the number of which is fixed by HME_NTXQ) hold
50108834Stmm * the software state for a transmit job; each has a dmamap allocated for it.
51108834Stmm * There may be multiple descriptors allocated to a single queue element.
52108834Stmm * HME_NTXQ is completely arbitrary.
5391396Stmm */
5493043Stmm#define HME_NRXDESC	128
55108834Stmm#define HME_NTXDESC	128
56108834Stmm#define	HME_NTXQ	(HME_NTXDESC / 2)
5791396Stmm
5891396Stmm/* Maximum size of a mapped RX buffer. */
5991396Stmm#define	HME_BUFSZ	1600
6091396Stmm
6191396Stmm/*
6291396Stmm * RX DMA descriptor. The descriptors are preallocated; the dma map is
6391396Stmm * reused.
6491396Stmm */
6591396Stmmstruct hme_rxdesc {
6691396Stmm	struct mbuf	*hrx_m;
6791396Stmm	bus_dmamap_t	hrx_dmamap;
6891396Stmm};
6991396Stmm
70108834Stmm/* Lazily leave at least one burst size grace space. */
71108834Stmm#define	HME_DESC_RXLEN(sc, d)						\
72108834Stmm	ulmin(HME_BUFSZ, (d)->hrx_m->m_len - (sc)->sc_burst)
73108834Stmm
7491396Stmmstruct hme_txdesc {
7591396Stmm	struct mbuf	*htx_m;
7691396Stmm	bus_dmamap_t	htx_dmamap;
77108834Stmm	int		htx_lastdesc;
78108834Stmm	STAILQ_ENTRY(hme_txdesc) htx_q;
7991396Stmm};
8091396Stmm
81108834StmmSTAILQ_HEAD(hme_txdq, hme_txdesc);
82108834Stmm
8391396Stmm/* Value for htx_flags */
8491396Stmm#define	HTXF_MAPPED	1
8591396Stmm
8691396Stmmstruct hme_ring {
8791396Stmm	/* Ring Descriptors */
8891396Stmm	caddr_t		rb_membase;	/* Packet buffer: CPU address */
8991396Stmm	bus_addr_t	rb_dmabase;	/* Packet buffer: DMA address */
9091396Stmm	caddr_t		rb_txd;		/* Transmit descriptors */
9191396Stmm	bus_addr_t	rb_txddma;	/* DMA address of same */
9291396Stmm	caddr_t		rb_rxd;		/* Receive descriptors */
9391396Stmm	bus_addr_t	rb_rxddma;	/* DMA address of same */
9491396Stmm
9591396Stmm	/* Ring Descriptor state */
96108834Stmm	int		rb_tdhead, rb_tdtail;
97108834Stmm	int		rb_rdtail;
98108834Stmm	int		rb_td_nbusy;
9991396Stmm
10091396Stmm	/* Descriptors */
101108834Stmm	struct hme_rxdesc	rb_rxdesc[HME_NRXDESC];
102108834Stmm	struct hme_txdesc	rb_txdesc[HME_NTXQ];
10391396Stmm
104108834Stmm	struct	hme_txdq	rb_txfreeq;
105108834Stmm	struct	hme_txdq	rb_txbusyq;
106108834Stmm
10791396Stmm	bus_dmamap_t	rb_spare_dmamap;
10891396Stmm};
10991396Stmm
11091396Stmmstruct hme_softc {
11191396Stmm	struct arpcom	sc_arpcom;
11291396Stmm	struct ifmedia	sc_ifmedia;
11391396Stmm	device_t	sc_dev;
11491396Stmm	device_t	sc_miibus;
11591396Stmm	struct mii_data	*sc_mii;	/* MII media control */
11691396Stmm	struct callout	sc_tick_ch;	/* tick callout */
11791396Stmm
11891396Stmm	/* The following bus handles are to be provided by the bus front-end */
11991396Stmm	bus_dma_tag_t	sc_pdmatag;	/* bus dma parent tag */
12091396Stmm	bus_dma_tag_t	sc_cdmatag;	/* control bus dma tag */
12191396Stmm	bus_dmamap_t	sc_cdmamap;	/* control bus dma handle */
12291396Stmm	bus_dma_tag_t	sc_rdmatag;	/* RX bus dma tag */
12391396Stmm	bus_dma_tag_t	sc_tdmatag;	/* RX bus dma tag */
12491396Stmm	bus_space_handle_t sc_sebh;	/* HME Global registers */
12591396Stmm	bus_space_handle_t sc_erxh;	/* HME ERX registers */
12691396Stmm	bus_space_handle_t sc_etxh;	/* HME ETX registers */
12791396Stmm	bus_space_handle_t sc_mach;	/* HME MAC registers */
12891396Stmm	bus_space_handle_t sc_mifh;	/* HME MIF registers */
12991396Stmm	bus_space_tag_t	sc_sebt;	/* HME Global registers */
13091396Stmm	bus_space_tag_t	sc_erxt;	/* HME ERX registers */
13191396Stmm	bus_space_tag_t	sc_etxt;	/* HME ETX registers */
13291396Stmm	bus_space_tag_t	sc_mact;	/* HME MAC registers */
13391396Stmm	bus_space_tag_t	sc_mift;	/* HME MIF registers */
13491396Stmm	int		sc_burst;	/* DVMA burst size in effect */
13591396Stmm	int		sc_phys[2];	/* MII instance -> PHY map */
13691396Stmm
13791396Stmm	int		sc_pci;		/* XXXXX -- PCI buses are LE. */
138133149Syongari	int		sc_csum_features;
13991396Stmm
14091396Stmm	/* Ring descriptor */
141137982Syongari	struct hme_ring	sc_rb;
14291396Stmm
143137982Syongari	int		sc_debug;
144137982Syongari	struct mtx	sc_lock;
14591396Stmm};
14691396Stmm
147137982Syongari#define HME_LOCK(_sc)		mtx_lock(&(_sc)->sc_lock)
148137982Syongari#define HME_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_lock)
149137982Syongari#define HME_LOCK_ASSERT(_sc, _what)	mtx_assert(&(_sc)->sc_lock, (_what))
150137982Syongari
15191396Stmmextern devclass_t hme_devclass;
15291396Stmm
15391396Stmmint	hme_config(struct hme_softc *);
154108976Stmmvoid	hme_detach(struct hme_softc *);
155108976Stmmvoid	hme_suspend(struct hme_softc *);
156108976Stmmvoid	hme_resume(struct hme_softc *);
15791396Stmmvoid	hme_intr(void *);
15891396Stmm
15991396Stmm/* MII methods & callbacks */
16091396Stmmint	hme_mii_readreg(device_t, int, int);
16191396Stmmint	hme_mii_writereg(device_t, int, int, int);
16291396Stmmvoid	hme_mii_statchg(device_t);
163