xref: /illumos-gate/usr/src/uts/common/io/mii/miipriv.h (revision bbb1277b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * miipriv.h
28  *
29  * Private MII header file.
30  */
31 
32 #ifndef _MIIPRIV_H
33 #define	_MIIPRIV_H
34 
35 #define	PHY_SET(phy, reg, bit)		\
36 	phy_write(phy, reg, phy_read(phy, reg) | (bit))
37 #define	PHY_CLR(phy, reg, bit)		\
38 	phy_write(phy, reg, phy_read(phy, reg) & ~(bit))
39 
40 typedef struct phy_ops phy_ops_t;
41 typedef struct phy_handle phy_handle_t;
42 
43 struct phy_handle {
44 	/*
45 	 * Read only fields for PHY implementations, used internally by
46 	 * the framework.
47 	 */
48 	mii_handle_t	phy_mii;
49 	boolean_t	phy_present;
50 	uint8_t		phy_addr;
51 	uint8_t		phy_type;
52 	uint32_t	phy_id;
53 
54 	/*
55 	 * Scratch storage available for PHY implementations.  While
56 	 * perhaps not as "clean" as other solutions with dynamic memory,
57 	 * this avoids having to deal with potential concerns regarding the
58 	 * lifetime of the storage.  It will be zeroed each time the MII
59 	 * bus is reprobed.
60 	 */
61 	uintptr_t	phy_scratch[8];
62 
63 	/*
64 	 * These fields are intended to be overridden by PHY
65 	 * implementations.  If left NULL, then default
66 	 * implementations will be supplied.
67 	 */
68 	const char	*phy_vendor;
69 	const char	*phy_model;
70 	int		(*phy_reset)(phy_handle_t *);
71 	int		(*phy_start)(phy_handle_t *);
72 	int		(*phy_stop)(phy_handle_t *);
73 	int		(*phy_check)(phy_handle_t *);
74 	int		(*phy_loop)(phy_handle_t *);
75 
76 	/*
77 	 * Physical capabilities.  PHY implementations may override
78 	 * the defaults if necessary.
79 	 */
80 	boolean_t	phy_cap_aneg;
81 	boolean_t	phy_cap_10_hdx;
82 	boolean_t	phy_cap_10_fdx;
83 	boolean_t	phy_cap_100_t4;
84 	boolean_t	phy_cap_100_hdx;
85 	boolean_t	phy_cap_100_fdx;
86 	boolean_t	phy_cap_1000_hdx;
87 	boolean_t	phy_cap_1000_fdx;
88 	boolean_t	phy_cap_pause;
89 	boolean_t	phy_cap_asmpause;
90 
91 	/*
92 	 * Local configured settings.  PHY implementations should
93 	 * these as read only.  The MII common layer will limit
94 	 * settings to only those that are sensible per the actual
95 	 * capabilities of the device.  These represent administrator
96 	 * preferences.
97 	 */
98 	boolean_t	phy_en_aneg;
99 	boolean_t	phy_en_10_hdx;
100 	boolean_t	phy_en_10_fdx;
101 	boolean_t	phy_en_100_t4;
102 	boolean_t	phy_en_100_hdx;
103 	boolean_t	phy_en_100_fdx;
104 	boolean_t	phy_en_1000_hdx;
105 	boolean_t	phy_en_1000_fdx;
106 	boolean_t	phy_en_pause;
107 	boolean_t	phy_en_asmpause;
108 	link_flowctrl_t	phy_en_flowctrl;
109 
110 	/*
111 	 * Settings exposed on the hardware.  MII common layer will
112 	 * limit settings to only those that are sensible per the
113 	 * actual capabilities of the device.
114 	 */
115 	boolean_t	phy_adv_aneg;
116 	boolean_t	phy_adv_10_hdx;
117 	boolean_t	phy_adv_10_fdx;
118 	boolean_t	phy_adv_100_t4;
119 	boolean_t	phy_adv_100_hdx;
120 	boolean_t	phy_adv_100_fdx;
121 	boolean_t	phy_adv_1000_hdx;
122 	boolean_t	phy_adv_1000_fdx;
123 	boolean_t	phy_adv_pause;
124 	boolean_t	phy_adv_asmpause;
125 
126 	/*
127 	 * Link partner settings.  PHY implementations should
128 	 * fill these in during phy_check.
129 	 */
130 	boolean_t	phy_lp_aneg;
131 	boolean_t	phy_lp_10_hdx;
132 	boolean_t	phy_lp_10_fdx;
133 	boolean_t	phy_lp_100_t4;
134 	boolean_t	phy_lp_100_hdx;
135 	boolean_t	phy_lp_100_fdx;
136 	boolean_t	phy_lp_1000_hdx;
137 	boolean_t	phy_lp_1000_fdx;
138 	boolean_t	phy_lp_pause;
139 	boolean_t	phy_lp_asmpause;
140 
141 	/*
142 	 * Loopback state.  Loopback state overrides any other settings.
143 	 */
144 	int		phy_loopback;
145 #define	PHY_LB_NONE	0
146 #define	PHY_LB_INT_PHY	1
147 #define	PHY_LB_EXT_10	2
148 #define	PHY_LB_EXT_100	3
149 #define	PHY_LB_EXT_1000	4
150 
151 	/*
152 	 * Resolved link status.  PHY implementations should
153 	 * fill these during phy_check.
154 	 */
155 	link_state_t	phy_link;
156 	uint32_t	phy_speed;
157 	link_duplex_t	phy_duplex;
158 	link_flowctrl_t	phy_flowctrl;
159 };
160 
161 /*
162  * Routines intended to be accessed by PHY specific implementation code.
163  * All of these routines assume that any relevant locks are held by the
164  * famework (which would be true for all of the PHY functions.
165  */
166 
167 uint16_t phy_read(phy_handle_t *, uint8_t);
168 void phy_write(phy_handle_t *, uint8_t, uint16_t);
169 int phy_get_prop(phy_handle_t *, char *, int);
170 const char *phy_get_name(phy_handle_t *);
171 const char *phy_get_driver(phy_handle_t *);
172 void phy_warn(phy_handle_t *, const char *, ...);
173 
174 /*
175  * phy_reset is called when the PHY needs to be reset.  The default
176  * implementation just resets the PHY by toggling the BMCR bit, but it
177  * also unisolates and powers up the PHY.
178  */
179 int phy_reset(phy_handle_t *);
180 
181 /*
182  * phy_start is used to start services on the PHY.  Typically this is
183  * called when autonegotiation should be started.  phy_reset will
184  * already have been called.
185  */
186 int phy_start(phy_handle_t *);
187 
188 /*
189  * phy_stop is used when the phy services should be stopped.  This can
190  * be done, for example, when a different PHY will be used.  The default
191  * implementation isolates the PHY, puts it into loopback, and then powers
192  * it down.
193  */
194 int phy_stop(phy_handle_t *);
195 
196 /*
197  * phy_check is called to check the current state of the link.  It
198  * can be used from the implementations phy_check entry point.
199  */
200 int phy_check(phy_handle_t *);
201 
202 /*
203  * phy_ isoop called to establish loopback mode.  The PHY must
204  * examine the value of phy_loopback.
205  */
206 int phy_loop(phy_handle_t *);
207 
208 /*
209  * The following probes are PHY specific, and located here so that
210  * the common PHY layer can find them.
211  */
212 boolean_t phy_intel_probe(phy_handle_t *);
213 boolean_t phy_natsemi_probe(phy_handle_t *);
214 boolean_t phy_qualsemi_probe(phy_handle_t *);
215 boolean_t phy_cicada_probe(phy_handle_t *);
216 boolean_t phy_marvell_probe(phy_handle_t *);
217 boolean_t phy_realtek_probe(phy_handle_t *);
218 boolean_t phy_other_probe(phy_handle_t *);
219 
220 #endif /* _MIIPRIV_H */
221