xref: /freebsd/sys/dev/mii/miivar.h (revision 1c47c79eb31e8e538724c0c3d080aeac9f5a0c55)
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 */
120d0027533SBill Paul 
121d0027533SBill Paul 	int mii_flags;			/* misc. flags; see below */
122d0027533SBill Paul 	int mii_capabilities;		/* capabilities from BMSR */
123a295ccc9SPoul-Henning Kamp 	int mii_extcapabilities;	/* extended capabilities */
124d0027533SBill Paul 	int mii_ticks;			/* MII_TICK counter */
125a295ccc9SPoul-Henning Kamp 	int mii_anegticks;		/* ticks before retrying aneg */
126a295ccc9SPoul-Henning Kamp 	int mii_media_active;		/* last active media */
127a295ccc9SPoul-Henning Kamp 	int mii_media_status;		/* last active status */
128d0027533SBill Paul };
129d0027533SBill Paul typedef struct mii_softc mii_softc_t;
130d0027533SBill Paul 
131d0027533SBill Paul /* mii_flags */
132b7dee1dbSPoul-Henning Kamp #define	MIIF_INITDONE	0x0001		/* has been initialized (mii_data) */
133b7dee1dbSPoul-Henning Kamp #define	MIIF_NOISOLATE	0x0002		/* do not isolate the PHY */
134b7dee1dbSPoul-Henning Kamp #define	MIIF_NOLOOP	0x0004		/* no loopback capability */
135b7dee1dbSPoul-Henning Kamp #define MIIF_AUTOTSLEEP	0x0010		/* use tsleep(), not callout() */
136b7dee1dbSPoul-Henning Kamp #define MIIF_HAVEFIBER	0x0020		/* from parent: has fiber interface */
137b7dee1dbSPoul-Henning Kamp #define	MIIF_HAVE_GTCR	0x0040		/* has 100base-T2/1000base-T CR */
138b7dee1dbSPoul-Henning Kamp #define	MIIF_IS_1000X	0x0080		/* is a 1000BASE-X device */
139b7dee1dbSPoul-Henning Kamp #define	MIIF_DOPAUSE	0x0100		/* advertise PAUSE capability */
140b7dee1dbSPoul-Henning Kamp #define	MIIF_IS_HPNA	0x0200		/* is a HomePNA device */
141b7dee1dbSPoul-Henning Kamp 
1421c47c79eSOleg Bulyzhin /* Default mii_anegticks values */
1431c47c79eSOleg Bulyzhin #define	MII_ANEGTICKS		5
1441c47c79eSOleg Bulyzhin #define	MII_ANEGTICKS_GIGE	17
1451c47c79eSOleg Bulyzhin 
146b7dee1dbSPoul-Henning Kamp #define	MIIF_INHERIT_MASK	(MIIF_NOISOLATE|MIIF_NOLOOP|MIIF_AUTOTSLEEP)
147d0027533SBill Paul 
148d0027533SBill Paul /*
149d0027533SBill Paul  * Used to attach a PHY to a parent.
150d0027533SBill Paul  */
151d0027533SBill Paul struct mii_attach_args {
152d0027533SBill Paul 	struct mii_data *mii_data;	/* pointer to parent data */
153d0027533SBill Paul 	int mii_phyno;			/* MII address */
154d0027533SBill Paul 	int mii_id1;			/* PHY ID register 1 */
155d0027533SBill Paul 	int mii_id2;			/* PHY ID register 2 */
156d0027533SBill Paul 	int mii_capmask;		/* capability mask from BMSR */
157d0027533SBill Paul };
158d0027533SBill Paul typedef struct mii_attach_args mii_attach_args_t;
159d0027533SBill Paul 
160b7dee1dbSPoul-Henning Kamp /*
161875525d5SPoul-Henning Kamp  * Used to match a PHY.
162875525d5SPoul-Henning Kamp  */
163875525d5SPoul-Henning Kamp struct mii_phydesc {
164875525d5SPoul-Henning Kamp 	u_int32_t mpd_oui;		/* the PHY's OUI */
165875525d5SPoul-Henning Kamp 	u_int32_t mpd_model;		/* the PHY's model */
166875525d5SPoul-Henning Kamp 	const char *mpd_name;		/* the PHY's name */
167875525d5SPoul-Henning Kamp };
168a1039f82SWarner Losh #define MII_PHY_DESC(a, b) { MII_OUI_ ## a, MII_MODEL_ ## a ## _ ## b, \
169a1039f82SWarner Losh 	MII_STR_ ## a ## _ ## b }
170a1039f82SWarner Losh #define MII_PHY_END	{ 0, 0, NULL }
171875525d5SPoul-Henning Kamp 
172875525d5SPoul-Henning Kamp /*
173b7dee1dbSPoul-Henning Kamp  * An array of these structures map MII media types to BMCR/ANAR settings.
174b7dee1dbSPoul-Henning Kamp  */
175b7dee1dbSPoul-Henning Kamp struct mii_media {
176b7dee1dbSPoul-Henning Kamp 	int	mm_bmcr;		/* BMCR settings for this media */
177b7dee1dbSPoul-Henning Kamp 	int	mm_anar;		/* ANAR settings for this media */
178b7dee1dbSPoul-Henning Kamp 	int	mm_gtcr;		/* 100base-T2 or 1000base-T CR */
179b7dee1dbSPoul-Henning Kamp };
180b7dee1dbSPoul-Henning Kamp 
181b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_NONE		0
182b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_10_T		1
183b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_10_T_FDX	2
184b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_100_T4	3
185b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_100_TX	4
186b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_100_TX_FDX	5
187b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_1000_X	6
188b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_1000_X_FDX	7
189b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_1000_T	8
190b7dee1dbSPoul-Henning Kamp #define	MII_MEDIA_1000_T_FDX	9
191b7dee1dbSPoul-Henning Kamp #define	MII_NMEDIA		10
192b7dee1dbSPoul-Henning Kamp 
193664a31e4SPeter Wemm #ifdef _KERNEL
194d0027533SBill Paul 
195d0027533SBill Paul #define PHY_READ(p, r) \
196d0027533SBill Paul 	MIIBUS_READREG((p)->mii_dev, (p)->mii_phy, (r))
197d0027533SBill Paul 
198d0027533SBill Paul #define PHY_WRITE(p, r, v) \
199d0027533SBill Paul 	MIIBUS_WRITEREG((p)->mii_dev, (p)->mii_phy, (r), (v))
200d0027533SBill Paul 
201d0027533SBill Paul extern devclass_t	miibus_devclass;
202d0027533SBill Paul extern driver_t		miibus_driver;
203d0027533SBill Paul 
204e51a25f8SAlfred Perlstein int	miibus_probe(device_t);
205e51a25f8SAlfred Perlstein int	miibus_attach(device_t);
206e51a25f8SAlfred Perlstein int	miibus_detach(device_t);
207d0027533SBill Paul 
208e51a25f8SAlfred Perlstein int	mii_anar(int);
209279fe8d1SPoul-Henning Kamp void	mii_down(struct mii_data *);
210e51a25f8SAlfred Perlstein int	mii_mediachg(struct mii_data *);
211e51a25f8SAlfred Perlstein void	mii_tick(struct mii_data *);
212e51a25f8SAlfred Perlstein void	mii_pollstat(struct mii_data *);
213e51a25f8SAlfred Perlstein int	mii_phy_probe(device_t, device_t *, ifm_change_cb_t, ifm_stat_cb_t);
21407dd9383SPoul-Henning Kamp void	mii_add_media(struct mii_softc *);
21578c8c3dbSPoul-Henning Kamp void	mii_phy_add_media(struct mii_softc *);
216d0027533SBill Paul 
217e51a25f8SAlfred Perlstein int	mii_media_from_bmcr(int);
218d0027533SBill Paul 
219fd94424cSPoul-Henning Kamp int	mii_phy_auto(struct mii_softc *);
220279fe8d1SPoul-Henning Kamp int	mii_phy_detach(device_t dev);
221279fe8d1SPoul-Henning Kamp void	mii_phy_down(struct mii_softc *);
222e51a25f8SAlfred Perlstein void	mii_phy_reset(struct mii_softc *);
223b7dee1dbSPoul-Henning Kamp void	mii_phy_setmedia(struct mii_softc *sc);
224e51a25f8SAlfred Perlstein void	mii_phy_update(struct mii_softc *, int);
225e51a25f8SAlfred Perlstein int	mii_phy_tick(struct mii_softc *);
226d0027533SBill Paul 
22708576af0SWarner Losh const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma,
22808576af0SWarner Losh     const struct mii_phydesc *mpd);
22908576af0SWarner Losh const struct mii_phydesc * mii_phy_match_gen(const struct mii_attach_args *ma,
23008576af0SWarner Losh     const struct mii_phydesc *mpd, size_t endlen);
231875525d5SPoul-Henning Kamp 
232e51a25f8SAlfred Perlstein void	ukphy_status(struct mii_softc *);
233664a31e4SPeter Wemm #endif /* _KERNEL */
234d0027533SBill Paul 
235d0027533SBill Paul #endif /* _DEV_MII_MIIVAR_H_ */
236