if_hmevar.h revision 91396
1/*-
2 * Copyright (c) 1999 The NetBSD Foundation, Inc.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Paul Kranenburg.
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 *	from: NetBSD: hmevar.h,v 1.5 2000/06/25 01:10:04 eeh Exp
37 *
38 * $FreeBSD: head/sys/dev/hme/if_hmevar.h 91396 2002-02-27 17:35:48Z tmm $
39 */
40
41#include <sys/callout.h>
42
43/*
44 * Number of receive and transmit descriptors. For each receive descriptor,
45 * an mbuf cluster is allocated and set up to receive a packet, and a dma map
46 * is created. Therefore, this number should not be too high to not waste
47 * memory.
48 * TX descriptors have less static cost (a dma map is allocated which could
49 * cause bounce buffers to be reserved; other that that, the only required
50 * memory is sizeof(struct hme_txdesc)).
51 * Both must be a multiple of 16, and <= 128.
52 */
53#define HME_NRXDESC	32
54#define HME_NTXDESC	64
55
56/* Maximum size of a mapped RX buffer. */
57#define	HME_BUFSZ	1600
58
59/*
60 * RX DMA descriptor. The descriptors are preallocated; the dma map is
61 * reused.
62 */
63struct hme_rxdesc {
64	struct mbuf	*hrx_m;
65	bus_dmamap_t	hrx_dmamap;
66	int		hrx_offs;
67	bus_size_t	hrx_len;
68};
69
70struct hme_txdesc {
71	struct mbuf	*htx_m;
72	bus_dmamap_t	htx_dmamap;
73	int		htx_flags;
74};
75
76/* Value for htx_flags */
77#define	HTXF_MAPPED	1
78
79struct hme_ring {
80	/* Ring Descriptors */
81	caddr_t		rb_membase;	/* Packet buffer: CPU address */
82	bus_addr_t	rb_dmabase;	/* Packet buffer: DMA address */
83	caddr_t		rb_txd;		/* Transmit descriptors */
84	bus_addr_t	rb_txddma;	/* DMA address of same */
85	caddr_t		rb_rxd;		/* Receive descriptors */
86	bus_addr_t	rb_rxddma;	/* DMA address of same */
87
88	/* Ring Descriptor state */
89	int	rb_tdhead, rb_tdtail;
90	int	rb_rdtail;
91	int	rb_td_nbusy;
92
93	/* Descriptors */
94	struct hme_rxdesc rb_rxdesc[HME_NRXDESC];
95	struct hme_txdesc rb_txdesc[HME_NTXDESC];
96
97	bus_dmamap_t	rb_spare_dmamap;
98};
99
100struct hme_softc {
101	struct arpcom	sc_arpcom;
102	struct ifmedia	sc_ifmedia;
103	device_t	sc_dev;
104	device_t	sc_miibus;
105	struct mii_data	*sc_mii;	/* MII media control */
106	struct callout	sc_tick_ch;	/* tick callout */
107
108	/* The following bus handles are to be provided by the bus front-end */
109	bus_dma_tag_t	sc_pdmatag;	/* bus dma parent tag */
110	bus_dma_tag_t	sc_cdmatag;	/* control bus dma tag */
111	bus_dmamap_t	sc_cdmamap;	/* control bus dma handle */
112	bus_dma_tag_t	sc_rdmatag;	/* RX bus dma tag */
113	bus_dma_tag_t	sc_tdmatag;	/* RX bus dma tag */
114	bus_space_handle_t sc_sebh;	/* HME Global registers */
115	bus_space_handle_t sc_erxh;	/* HME ERX registers */
116	bus_space_handle_t sc_etxh;	/* HME ETX registers */
117	bus_space_handle_t sc_mach;	/* HME MAC registers */
118	bus_space_handle_t sc_mifh;	/* HME MIF registers */
119	bus_space_tag_t	sc_sebt;	/* HME Global registers */
120	bus_space_tag_t	sc_erxt;	/* HME ERX registers */
121	bus_space_tag_t	sc_etxt;	/* HME ETX registers */
122	bus_space_tag_t	sc_mact;	/* HME MAC registers */
123	bus_space_tag_t	sc_mift;	/* HME MIF registers */
124	bus_addr_t	sc_sebo;	/* HME Global registers */
125	bus_addr_t	sc_erxo;	/* HME ERX registers */
126	bus_addr_t	sc_etxo;	/* HME ETX registers */
127	bus_addr_t	sc_maco;	/* HME MAC registers */
128	bus_addr_t	sc_mifo;	/* HME MIF registers */
129	int		sc_burst;	/* DVMA burst size in effect */
130	int		sc_phys[2];	/* MII instance -> PHY map */
131
132	int		sc_pci;		/* XXXXX -- PCI buses are LE. */
133
134	/* Ring descriptor */
135	struct hme_ring		sc_rb;
136
137	int			sc_debug;
138
139	/* Special hardware hooks */
140	void	(*sc_hwreset)(struct hme_softc *);
141	void	(*sc_hwinit)(struct hme_softc *);
142};
143
144extern devclass_t hme_devclass;
145
146int	hme_config(struct hme_softc *);
147void	hme_intr(void *);
148
149/* MII methods & callbacks */
150int	hme_mii_readreg(device_t, int, int);
151int	hme_mii_writereg(device_t, int, int, int);
152void	hme_mii_statchg(device_t);
153