xref: /illumos-gate/usr/src/uts/common/io/mii/miipriv.h (revision 24fe0b3b)
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 2009 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 
75 	/*
76 	 * Physical capabilities.  PHY implementations may override
77 	 * the defaults if necessary.
78 	 */
79 	boolean_t	phy_cap_aneg;
80 	boolean_t	phy_cap_10_hdx;
81 	boolean_t	phy_cap_10_fdx;
82 	boolean_t	phy_cap_100_t4;
83 	boolean_t	phy_cap_100_hdx;
84 	boolean_t	phy_cap_100_fdx;
85 	boolean_t	phy_cap_1000_hdx;
86 	boolean_t	phy_cap_1000_fdx;
87 	boolean_t	phy_cap_pause;
88 	boolean_t	phy_cap_asmpause;
89 
90 	/*
91 	 * Local configured settings.  PHY implementations should
92 	 * these as read only.  The MII common layer will limit
93 	 * settings to only those that are sensible per the actual
94 	 * capabilities of the device.  These represent administrator
95 	 * preferences.
96 	 */
97 	boolean_t	phy_en_aneg;
98 	boolean_t	phy_en_10_hdx;
99 	boolean_t	phy_en_10_fdx;
100 	boolean_t	phy_en_100_t4;
101 	boolean_t	phy_en_100_hdx;
102 	boolean_t	phy_en_100_fdx;
103 	boolean_t	phy_en_1000_hdx;
104 	boolean_t	phy_en_1000_fdx;
105 	boolean_t	phy_en_pause;
106 	boolean_t	phy_en_asmpause;
107 	link_flowctrl_t	phy_en_flowctrl;
108 
109 	/*
110 	 * Settings exposed on the hardware.  MII common layer will
111 	 * limit settings to only those that are sensible per the
112 	 * actual capabilities of the device.
113 	 */
114 	boolean_t	phy_adv_aneg;
115 	boolean_t	phy_adv_10_hdx;
116 	boolean_t	phy_adv_10_fdx;
117 	boolean_t	phy_adv_100_t4;
118 	boolean_t	phy_adv_100_hdx;
119 	boolean_t	phy_adv_100_fdx;
120 	boolean_t	phy_adv_1000_hdx;
121 	boolean_t	phy_adv_1000_fdx;
122 	boolean_t	phy_adv_pause;
123 	boolean_t	phy_adv_asmpause;
124 
125 	/*
126 	 * Link partner settings.  PHY implementations should
127 	 * fill these in during phy_check.
128 	 */
129 	boolean_t	phy_lp_aneg;
130 	boolean_t	phy_lp_10_hdx;
131 	boolean_t	phy_lp_10_fdx;
132 	boolean_t	phy_lp_100_t4;
133 	boolean_t	phy_lp_100_hdx;
134 	boolean_t	phy_lp_100_fdx;
135 	boolean_t	phy_lp_1000_hdx;
136 	boolean_t	phy_lp_1000_fdx;
137 	boolean_t	phy_lp_pause;
138 	boolean_t	phy_lp_asmpause;
139 
140 	/*
141 	 * Loopback state.  Loopback state overrides any other settings.
142 	 */
143 	int		phy_loopback;
144 #define	PHY_LB_NONE	0
145 #define	PHY_LB_INT_PHY	1
146 #define	PHY_LB_EXT_10	2
147 #define	PHY_LB_EXT_100	3
148 #define	PHY_LB_EXT_1000	4
149 
150 	/*
151 	 * Resolved link status.  PHY implementations should
152 	 * fill these during phy_check.
153 	 */
154 	link_state_t	phy_link;
155 	uint32_t	phy_speed;
156 	link_duplex_t	phy_duplex;
157 	link_flowctrl_t	phy_flowctrl;
158 };
159 
160 /*
161  * Routines intended to be accessed by PHY specific implementation code.
162  * All of these routines assume that any relevant locks are held by the
163  * famework (which would be true for all of the PHY functions.
164  */
165 
166 uint16_t phy_read(phy_handle_t *, uint8_t);
167 void phy_write(phy_handle_t *, uint8_t, uint16_t);
168 int phy_get_prop(phy_handle_t *, char *, int);
169 const char *phy_get_name(phy_handle_t *);
170 const char *phy_get_driver(phy_handle_t *);
171 void phy_warn(phy_handle_t *, const char *, ...);
172 
173 /*
174  * phy_reset is called when the PHY needs to be reset.  The default
175  * implementation just resets the PHY by toggling the BMCR bit, but it
176  * also unisolates and powers up the PHY.
177  */
178 int phy_reset(phy_handle_t *);
179 
180 /*
181  * phy_start is used to start services on the PHY.  Typically this is
182  * called when autonegotiation should be started.  phy_reset will
183  * already have been called.
184  */
185 int phy_start(phy_handle_t *);
186 
187 /*
188  * phy_stop is used when the phy services should be stopped.  This can
189  * be done, for example, when a different PHY will be used.  The default
190  * implementation isolates the PHY, puts it into loopback, and then powers
191  * it down.
192  */
193 int phy_stop(phy_handle_t *);
194 
195 /*
196  * phy_check is called to check the current state of the link.  It
197  * can be used from the implementations phy_check entry point.
198  */
199 int phy_check(phy_handle_t *);
200 
201 /*
202  * THe following probes are PHY specific, and located here so that
203  * the common PHY layer can find them.
204  */
205 boolean_t phy_intel_probe(phy_handle_t *);
206 boolean_t phy_natsemi_probe(phy_handle_t *);
207 boolean_t phy_qualsemi_probe(phy_handle_t *);
208 boolean_t phy_cicada_probe(phy_handle_t *);
209 boolean_t phy_other_probe(phy_handle_t *);
210 
211 #endif /* _MIIPRIV_H */
212