if_epvar.h revision 330897
1129198Scognet/*-
2129198Scognet * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3139735Simp *
4129198Scognet * Copyright (c) 1993 Herb Peyerl (hpeyerl@novatel.ca) All rights reserved.
5129198Scognet *
6129198Scognet * Redistribution and use in source and binary forms, with or without
7129198Scognet * modification, are permitted provided that the following conditions are
8129198Scognet * met: 1. Redistributions of source code must retain the above copyright
9129198Scognet * notice, this list of conditions and the following disclaimer. 2. The name
10129198Scognet * of the author may not be used to endorse or promote products derived from
11129198Scognet * this software without specific prior written permission
12129198Scognet *
13129198Scognet * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
14129198Scognet * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15129198Scognet * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16129198Scognet * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17129198Scognet * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18129198Scognet * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19129198Scognet * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
20129198Scognet * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21129198Scognet * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22129198Scognet * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23129198Scognet *
24129198Scognet * $FreeBSD: stable/11/sys/dev/ep/if_epvar.h 330897 2018-03-14 03:19:51Z eadler $
25129198Scognet */
26129198Scognet
27129198Scognetstruct ep_board {
28129198Scognet	u_short prod_id;	/* product ID */
29129198Scognet	int cmd_off;		/* command offset (bit shift) */
30129198Scognet	int mii_trans;		/* activate MII transiever */
31129198Scognet	u_short res_cfg;	/* resource configuration */
32129198Scognet};
33129198Scognet
34129198Scognet/*
35129198Scognet * Ethernet software status per interface.
36129198Scognet */
37129198Scognetstruct ep_softc {
38129198Scognet	struct ifnet *ifp;
39129198Scognet	struct ifmedia ifmedia;	/* media info		 */
40129198Scognet	device_t dev;
41129198Scognet
42135650Scognet	struct mtx sc_mtx;
43129198Scognet	struct resource *iobase;
44129198Scognet	struct resource *irq;
45129198Scognet
46135650Scognet	bus_space_handle_t bsh;
47135650Scognet	bus_space_tag_t bst;
48135650Scognet	void *ep_intrhand;
49129198Scognet
50129198Scognet	struct callout watchdog_timer;
51129198Scognet	int tx_timer;
52129198Scognet
53	u_short ep_connectors;	/* Connectors on this card. */
54	u_char ep_connector;	/* Configured connector. */
55
56	struct mbuf *top;
57	struct mbuf *mcur;
58	short cur_len;
59
60	int stat;		/* some flags */
61#define	F_RX_FIRST		0x001
62#define F_ENADDR_SKIP		0x002
63#define	F_PROMISC		0x008
64#define	F_ACCESS_32_BITS	0x100
65#define	F_HAS_TX_PLL		0x200
66
67	int gone;		/* adapter is not present (for PCCARD) */
68	struct ep_board epb;
69	uint8_t eaddr[6];
70
71#ifdef  EP_LOCAL_STATS
72	short tx_underrun;
73	short rx_no_first;
74	short rx_no_mbuf;
75	short rx_overrunf;
76	short rx_overrunl;
77#endif
78};
79
80int ep_alloc(device_t);
81void ep_free(device_t);
82int ep_detach(device_t);
83void ep_get_media(struct ep_softc *);
84int ep_attach(struct ep_softc *);
85void ep_intr(void *);
86int ep_get_e(struct ep_softc *, uint16_t, uint16_t *);
87
88#define CSR_READ_1(sc, off) (bus_space_read_1((sc)->bst, (sc)->bsh, off))
89#define CSR_READ_2(sc, off) (bus_space_read_2((sc)->bst, (sc)->bsh, off))
90#define CSR_WRITE_1(sc, off, val) \
91	bus_space_write_1(sc->bst, sc->bsh, off, val)
92#define CSR_WRITE_2(sc, off, val) \
93	bus_space_write_2(sc->bst, sc->bsh, off, val)
94#define CSR_WRITE_MULTI_1(sc, off, addr, count) \
95	bus_space_write_multi_1(sc->bst, sc->bsh, off, addr, count)
96#define CSR_WRITE_MULTI_2(sc, off, addr, count) \
97	bus_space_write_multi_2(sc->bst, sc->bsh, off, addr, count)
98#define CSR_WRITE_MULTI_4(sc, off, addr, count) \
99	bus_space_write_multi_4(sc->bst, sc->bsh, off, addr, count)
100#define CSR_READ_MULTI_1(sc, off, addr, count) \
101	bus_space_read_multi_1(sc->bst, sc->bsh, off, addr, count)
102#define CSR_READ_MULTI_2(sc, off, addr, count) \
103	bus_space_read_multi_2(sc->bst, sc->bsh, off, addr, count)
104#define CSR_READ_MULTI_4(sc, off, addr, count) \
105	bus_space_read_multi_4(sc->bst, sc->bsh, off, addr, count)
106
107#define EP_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
108#define	EP_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
109#define EP_LOCK_INIT(_sc) \
110	mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->dev), \
111	    MTX_NETWORK_LOCK, MTX_DEF)
112#define EP_LOCK_DESTROY(_sc)	mtx_destroy(&_sc->sc_mtx);
113#define EP_ASSERT_LOCKED(_sc)	mtx_assert(&_sc->sc_mtx, MA_OWNED);
114#define EP_ASSERT_UNLOCKED(_sc)	mtx_assert(&_sc->sc_mtx, MA_NOTOWNED);
115