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