xref: /freebsd/sys/dev/mii/miivar.h (revision 279fe8d1)
1d0027533SBill Paul /*	$NetBSD: miivar.h,v 1.8 1999/04/23 04:24:32 thorpej Exp $	*/
2d0027533SBill Paul 
3d0027533SBill Paul /*-
4d0027533SBill Paul  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
5d0027533SBill Paul  * All rights reserved.
6d0027533SBill Paul  *
7d0027533SBill Paul  * This code is derived from software contributed to The NetBSD Foundation
8d0027533SBill Paul  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9d0027533SBill Paul  * NASA Ames Research Center.
10d0027533SBill Paul  *
11d0027533SBill Paul  * Redistribution and use in source and binary forms, with or without
12d0027533SBill Paul  * modification, are permitted provided that the following conditions
13d0027533SBill Paul  * are met:
14d0027533SBill Paul  * 1. Redistributions of source code must retain the above copyright
15d0027533SBill Paul  *    notice, this list of conditions and the following disclaimer.
16d0027533SBill Paul  * 2. Redistributions in binary form must reproduce the above copyright
17d0027533SBill Paul  *    notice, this list of conditions and the following disclaimer in the
18d0027533SBill Paul  *    documentation and/or other materials provided with the distribution.
19d0027533SBill Paul  * 3. All advertising materials mentioning features or use of this software
20d0027533SBill Paul  *    must display the following acknowledgement:
21d0027533SBill Paul  *	This product includes software developed by the NetBSD
22d0027533SBill Paul  *	Foundation, Inc. and its contributors.
23d0027533SBill Paul  * 4. Neither the name of The NetBSD Foundation nor the names of its
24d0027533SBill Paul  *    contributors may be used to endorse or promote products derived
25d0027533SBill Paul  *    from this software without specific prior written permission.
26d0027533SBill Paul  *
27d0027533SBill Paul  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28d0027533SBill Paul  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29d0027533SBill Paul  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30d0027533SBill Paul  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31d0027533SBill Paul  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32d0027533SBill Paul  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33d0027533SBill Paul  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34d0027533SBill Paul  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35d0027533SBill Paul  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36d0027533SBill Paul  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37d0027533SBill Paul  * POSSIBILITY OF SUCH DAMAGE.
38d0027533SBill Paul  *
39c3aac50fSPeter Wemm  * $FreeBSD$
40d0027533SBill Paul  */
41d0027533SBill Paul 
42d0027533SBill Paul #ifndef _DEV_MII_MIIVAR_H_
43d0027533SBill Paul #define	_DEV_MII_MIIVAR_H_
44d0027533SBill Paul 
45d0027533SBill Paul #include <sys/queue.h>
46d0027533SBill Paul 
47d0027533SBill Paul /*
48a295ccc9SPoul-Henning Kamp  * Media Independent Interface configuration defintions.
49d0027533SBill Paul  */
50d0027533SBill Paul 
51d0027533SBill Paul struct mii_softc;
52d0027533SBill Paul 
53d0027533SBill Paul /*
54d0027533SBill Paul  * Callbacks from MII layer into network interface device driver.
55d0027533SBill Paul  */
56e51a25f8SAlfred Perlstein typedef	int (*mii_readreg_t)(struct device *, int, int);
57e51a25f8SAlfred Perlstein typedef	void (*mii_writereg_t)(struct device *, int, int, int);
58e51a25f8SAlfred Perlstein typedef	void (*mii_statchg_t)(struct device *);
59d0027533SBill Paul 
60d0027533SBill Paul /*
61d0027533SBill Paul  * A network interface driver has one of these structures in its softc.
62d0027533SBill Paul  * It is the interface from the network interface driver to the MII
63d0027533SBill Paul  * layer.
64d0027533SBill Paul  */
65d0027533SBill Paul struct mii_data {
66d0027533SBill Paul 	struct ifmedia mii_media;	/* media information */
67d0027533SBill Paul 	struct ifnet *mii_ifp;		/* pointer back to network interface */
68d0027533SBill Paul 
69d0027533SBill Paul 	/*
70d0027533SBill Paul 	 * For network interfaces with multiple PHYs, a list of all
71d0027533SBill Paul 	 * PHYs is required so they can all be notified when a media
72d0027533SBill Paul 	 * request is made.
73d0027533SBill Paul 	 */
74e3975643SJake Burkholder 	LIST_HEAD(mii_listhead, mii_softc) mii_phys;
75d0027533SBill Paul 	int mii_instance;
76d0027533SBill Paul 
77d0027533SBill Paul 	/*
78d0027533SBill Paul 	 * PHY driver fills this in with active media status.
79d0027533SBill Paul 	 */
80d0027533SBill Paul 	int mii_media_status;
81d0027533SBill Paul 	int mii_media_active;
82d0027533SBill Paul 
83d0027533SBill Paul 	/*
84d0027533SBill Paul 	 * Calls from MII layer into network interface driver.
85d0027533SBill Paul 	 */
86d0027533SBill Paul 	mii_readreg_t mii_readreg;
87d0027533SBill Paul 	mii_writereg_t mii_writereg;
88d0027533SBill Paul 	mii_statchg_t mii_statchg;
89d0027533SBill Paul };
90d0027533SBill Paul typedef struct mii_data mii_data_t;
91d0027533SBill Paul 
92d0027533SBill Paul /*
93d0027533SBill Paul  * This call is used by the MII layer to call into the PHY driver
94d0027533SBill Paul  * to perform a `service request'.
95d0027533SBill Paul  */
96e51a25f8SAlfred Perlstein typedef	int (*mii_downcall_t)(struct mii_softc *, struct mii_data *, int);
97d0027533SBill Paul 
98d0027533SBill Paul /*
99d0027533SBill Paul  * Requests that can be made to the downcall.
100d0027533SBill Paul  */
101d0027533SBill Paul #define	MII_TICK	1	/* once-per-second tick */
102d0027533SBill Paul #define	MII_MEDIACHG	2	/* user changed media; perform the switch */
103d0027533SBill Paul #define	MII_POLLSTAT	3	/* user requested media status; fill it in */
104d0027533SBill Paul 
105d0027533SBill Paul /*
106d0027533SBill Paul  * Each PHY driver's softc has one of these as the first member.
107d0027533SBill Paul  * XXX This would be better named "phy_softc", but this is the name
108d0027533SBill Paul  * XXX BSDI used, and we would like to have the same interface.
109d0027533SBill Paul  */
110d0027533SBill Paul struct mii_softc {
111d0027533SBill Paul 	device_t mii_dev;		/* generic device glue */
112d0027533SBill Paul 
113e3975643SJake Burkholder 	LIST_ENTRY(mii_softc) mii_list;	/* entry on parent's PHY list */
114d0027533SBill Paul 
115d0027533SBill Paul 	int mii_phy;			/* our MII address */
116d0027533SBill Paul 	int mii_inst;			/* instance for ifmedia */
117d0027533SBill Paul 
118d0027533SBill Paul 	mii_downcall_t mii_service;	/* our downcall */
119d0027533SBill Paul 	struct mii_data *mii_pdata;	/* pointer to parent's mii_data */
12034da0ef1SBill Paul 	struct callout_handle mii_auto_ch; /* callout handle for phy autoneg */
121d0027533SBill Paul 
122d0027533SBill Paul 	int mii_flags;			/* misc. flags; see below */
123d0027533SBill Paul 	int mii_capabilities;		/* capabilities from BMSR */
124a295ccc9SPoul-Henning Kamp 	int mii_extcapabilities;	/* extended capabilities */
125d0027533SBill Paul 	int mii_ticks;			/* MII_TICK counter */
126a295ccc9SPoul-Henning Kamp 	int mii_anegticks;		/* ticks before retrying aneg */
127a295ccc9SPoul-Henning Kamp 	int mii_media_active;		/* last active media */
128a295ccc9SPoul-Henning Kamp 	int mii_media_status;		/* last active status */
129d0027533SBill Paul };
130d0027533SBill Paul typedef struct mii_softc mii_softc_t;
131d0027533SBill Paul 
132d0027533SBill Paul /* mii_flags */
133b7dee1dbSPoul-Henning Kamp #define	MIIF_INITDONE	0x0001		/* has been initialized (mii_data) */
134b7dee1dbSPoul-Henning Kamp #define	MIIF_NOISOLATE	0x0002		/* do not isolate the PHY */
135b7dee1dbSPoul-Henning Kamp #define	MIIF_NOLOOP	0x0004		/* no loopback capability */
136b7dee1dbSPoul-Henning Kamp #define	MIIF_DOINGAUTO	0x0008		/* doing autonegotiation (mii_softc) */
137b7dee1dbSPoul-Henning Kamp #define MIIF_AUTOTSLEEP	0x0010		/* use tsleep(), not callout() */
138b7dee1dbSPoul-Henning Kamp #define MIIF_HAVEFIBER	0x0020		/* from parent: has fiber interface */
139b7dee1dbSPoul-Henning Kamp #define	MIIF_HAVE_GTCR	0x0040		/* has 100base-T2/1000base-T CR */
140b7dee1dbSPoul-Henning Kamp #define	MIIF_IS_1000X	0x0080		/* is a 1000BASE-X device */
141b7dee1dbSPoul-Henning Kamp #define	MIIF_DOPAUSE	0x0100		/* advertise PAUSE capability */
142b7dee1dbSPoul-Henning Kamp #define	MIIF_IS_HPNA	0x0200		/* is a HomePNA device */
143b7dee1dbSPoul-Henning Kamp 
144b7dee1dbSPoul-Henning Kamp #define	MIIF_INHERIT_MASK	(MIIF_NOISOLATE|MIIF_NOLOOP|MIIF_AUTOTSLEEP)
145d0027533SBill Paul 
146d0027533SBill Paul /*
147d0027533SBill Paul  * Used to attach a PHY to a parent.
148d0027533SBill Paul  */
149d0027533SBill Paul struct mii_attach_args {
150d0027533SBill Paul 	struct mii_data *mii_data;	/* pointer to parent data */
151d0027533SBill Paul 	int mii_phyno;			/* MII address */
152d0027533SBill Paul 	int mii_id1;			/* PHY ID register 1 */
153d0027533SBill Paul 	int mii_id2;			/* PHY ID register 2 */
154d0027533SBill Paul 	int mii_capmask;		/* capability mask from BMSR */
155d0027533SBill Paul };
156d0027533SBill Paul typedef struct mii_attach_args mii_attach_args_t;
157d0027533SBill Paul 
158b7dee1dbSPoul-Henning Kamp /*
159b7dee1dbSPoul-Henning Kamp  * An array of these structures map MII media types to BMCR/ANAR settings.
160b7dee1dbSPoul-Henning Kamp  */
161b7dee1dbSPoul-Henning Kamp struct mii_media {
162b7dee1dbSPoul-Henning Kamp 	int	mm_bmcr;		/* BMCR settings for this media */
163b7dee1dbSPoul-Henning Kamp 	int	mm_anar;		/* ANAR settings for this media */
164b7dee1dbSPoul-Henning Kamp 	int	mm_gtcr;		/* 100base-T2 or 1000base-T CR */
165b7dee1dbSPoul-Henning Kamp };
166b7dee1dbSPoul-Henning Kamp 
167b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_NONE		0
168b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_10_T		1
169b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_10_T_FDX	2
170b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_100_T4	3
171b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_100_TX	4
172b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_100_TX_FDX	5
173b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_1000_X	6
174b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_1000_X_FDX	7
175b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_1000_T	8
176b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_1000_T_FDX	9
177b7dee1dbSPoul-Henning Kamp #define	MII_NMEDIA		10
178b7dee1dbSPoul-Henning Kamp 
179664a31e4SPeter Wemm #ifdef _KERNEL
180d0027533SBill Paul 
181d0027533SBill Paul #define PHY_READ(p, r) \
182d0027533SBill Paul 	MIIBUS_READREG((p)->mii_dev, (p)->mii_phy, (r))
183d0027533SBill Paul 
184d0027533SBill Paul #define PHY_WRITE(p, r, v) \
185d0027533SBill Paul 	MIIBUS_WRITEREG((p)->mii_dev, (p)->mii_phy, (r), (v))
186d0027533SBill Paul 
187d0027533SBill Paul extern devclass_t	miibus_devclass;
188d0027533SBill Paul extern driver_t		miibus_driver;
189d0027533SBill Paul 
190e51a25f8SAlfred Perlstein int	miibus_probe(device_t);
191e51a25f8SAlfred Perlstein int	miibus_attach(device_t);
192e51a25f8SAlfred Perlstein int	miibus_detach(device_t);
193d0027533SBill Paul 
194e51a25f8SAlfred Perlstein int	mii_anar(int);
195279fe8d1SPoul-Henning Kamp void	mii_down(struct mii_data *);
196e51a25f8SAlfred Perlstein int	mii_mediachg(struct mii_data *);
197e51a25f8SAlfred Perlstein void	mii_tick(struct mii_data *);
198e51a25f8SAlfred Perlstein void	mii_pollstat(struct mii_data *);
199e51a25f8SAlfred Perlstein int	mii_phy_probe(device_t, device_t *, ifm_change_cb_t, ifm_stat_cb_t);
20007dd9383SPoul-Henning Kamp void	mii_add_media(struct mii_softc *);
20178c8c3dbSPoul-Henning Kamp void	mii_phy_add_media(struct mii_softc *);
202d0027533SBill Paul 
203e51a25f8SAlfred Perlstein int	mii_media_from_bmcr(int);
204d0027533SBill Paul 
205e51a25f8SAlfred Perlstein int	mii_phy_auto(struct mii_softc *, int);
206279fe8d1SPoul-Henning Kamp int	mii_phy_detach(device_t dev);
207279fe8d1SPoul-Henning Kamp void	mii_phy_down(struct mii_softc *);
208e51a25f8SAlfred Perlstein void	mii_phy_reset(struct mii_softc *);
209b7dee1dbSPoul-Henning Kamp void	mii_phy_setmedia(struct mii_softc *sc);
210e51a25f8SAlfred Perlstein void	mii_phy_update(struct mii_softc *, int);
211e51a25f8SAlfred Perlstein int	mii_phy_tick(struct mii_softc *);
212d0027533SBill Paul 
213e51a25f8SAlfred Perlstein void	ukphy_status(struct mii_softc *);
214664a31e4SPeter Wemm #endif /* _KERNEL */
215d0027533SBill Paul 
216d0027533SBill Paul #endif /* _DEV_MII_MIIVAR_H_ */
217