pkg: ship usr/lib/security/amd64/*.so links
[unleashed.git] / include / sys / mii.h
blobc3941affcefb7f7c81adaae5ffee72f73be1e4bd
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * mii.h
28 * Generic MII/PHY Support for MAC drivers.
31 #ifndef _SYS_MII_H
32 #define _SYS_MII_H
34 #include <sys/mac_provider.h>
35 #include <sys/netlb.h>
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
42 * NOTES
44 * The device driver is required to protect its own registers. The
45 * MII common code will call MII entry points asynchronously, from a
46 * taskq, and holds an internal lock across such calls (except the
47 * notify entry point). Therefore, device drivers MUST NOT hold any
48 * locks across calls into the MII framework.
50 * If a device must be suspended (e.g. due to DDI_SUSPEND) the MII
51 * layer can be suspended by calling mii_stop(). After this point,
52 * the monitoring task will be suspended and the driver can be assured
53 * that MII will not interfere until restarted with mii_start().
55 * Note that monitoring is not started until mii_start() is called.
56 * The mii_start() function may be called multiple times. It performs
57 * an implicit reset of the MII bus and PHY.
59 * Once started, if not already done, a probe of the MII bus is done to
60 * find a suitable PHY. If no PHY is found, then you won't have any
61 * link! Once a suitable PHY is selected, any other PHYs are isolated and
62 * powered down. The device driver can cause MII to re-probe the bus for
63 * changes to the available PHYs by calling mii_probe(). Note that this
64 * will also cause a full reset of all PHYs.
66 * The mii_reset entry point, which is optional, is used to notify the
67 * driver when the MII layer has reset the device. This can allow
68 * certain drivers the opportunity to "fix up" things after reset.
69 * Note however, that when possible, it is better if the logic is
70 * encoded into a vendor specific PHY module.
73 #ifdef _KERNEL
75 typedef struct mii_handle *mii_handle_t;
76 typedef struct mii_ops mii_ops_t;
78 struct mii_ops {
79 int mii_version;
80 uint16_t (*mii_read)(void *, uint8_t, uint8_t);
81 void (*mii_write)(void *, uint8_t, uint8_t, uint16_t);
82 void (*mii_notify)(void *, link_state_t);
83 void (*mii_reset)(void *);
85 #define MII_OPS_VERSION 0
88 * Support routines.
92 * mii_alloc
94 * Allocate an MII handle. Called during driver's attach(9e)
95 * handling, this routine is valid in kernel context only.
97 * Arguments
99 * private A private state structure, provided back to
100 * entry points.
101 * dip The dev_info node for the MAC driver.
102 * ops Entry points into the MAC driver.
104 * Returns
105 * Handle to MII bus on success, NULL on failure.
107 mii_handle_t mii_alloc(void *private, dev_info_t *dip, mii_ops_t *ops);
110 * mii_alloc
112 * Allocate an MII handle. Called during driver's attach(9e)
113 * handling, this routine is valid in kernel context only. This
114 * routine is an alternative to mii_alloc() for use when the
115 * instance number (PPA) is not the same as the devinfo instance
116 * number, and hence needs to be overridden.
118 * Arguments
120 * private A private state structure, provided back to
121 * entry points.
122 * dip The dev_info node for the MAC driver.
123 * instance The instance (PPA) of the interface.
124 * ops Entry points into the MAC driver.
126 * Returns
127 * Handle to MII bus on success, NULL on failure.
129 mii_handle_t mii_alloc_instance(void *private, dev_info_t *dip, int instance,
130 mii_ops_t *ops);
133 * mii_free
135 * Free an MII handle and associated resources. Call from
136 * detach(9e) handling, this routine is valid in kernel context
137 * only.
139 void mii_free(mii_handle_t mii);
142 * mii_set_pauseable
144 * Lets the MII know if the MAC layer can support pause or
145 * asymetric pause capabilities. The MII layer will use this to
146 * determine what capabilities should be negotiated for (along
147 * with user preferences, of course.) If not called, the MII
148 * will assume the device has no support for flow control.
150 * Arguments
152 * mii MII handle.
153 * cap B_TRUE if the device supports symmetric of pause.
154 * asym B_TRUE if the device supports asymmetric pause.
156 void mii_set_pauseable(mii_handle_t mii, boolean_t cap, boolean_t asym);
159 * mii_reset
161 * Schedules a reset of the MII bus. Normally not needed, but
162 * can be used to perform a full master reset, including
163 * rescanning for PHYs. This function may be called in any
164 * context except high level interrupt context, but must be
165 * called without any locks held. The reset will probably not
166 * be complete until sometime after the call returns.
168 * Note that if mii_start has not been called, then the reset
169 * will not be performed until _after_ the MII is started.
171 void mii_reset(mii_handle_t mii);
175 * mii_start
177 * Starts monitoring of the MII bus. Normally this is called as
178 * a result of a driver's mac_start() entry point, but it may also
179 * be called when a PHY needs to be reset or during handling of
180 * DDI_RESUME. This function may be called in any context except
181 * high level interrupt context, but
182 * must be called without any locks held.
184 void mii_start(mii_handle_t mii);
187 * mii_stop
189 * Stops monitoring of the MII bus. Normally this is called as a
190 * result of a driver's mac_stop() entry point. As a side
191 * effect, also isolates and powers down any active PHY. On
192 * return, the MII layer is guaranteed not to be executing any
193 * code in the MII entry points. This function may be called in
194 * any context except high level interrupt context, but must be
195 * called without any locks held.
197 void mii_stop(mii_handle_t mii);
200 * mii_resume
202 * Starts monitoring of the MII bus. Normally this is called as
203 * a part of a driver's DDI_RESUME handling. This function may
204 * be called in any context except high level interrupt context,
205 * but must be called without any locks held.
207 void mii_resume(mii_handle_t mii);
210 * mii_suspend
212 * Suspends monitoring of the MII bus. Normally this is called
213 * as a part of a driver's DDI_SUSPEND handling. On return, the
214 * MII layer is guaranteed not to be executing any code in the
215 * MII entry points. This function may be called in any context
216 * except high level interrupt context, but must be called
217 * without any locks held.
219 void mii_suspend(mii_handle_t mii);
222 * mii_probe
224 * Used to reset the entire MII bus and probe for PHYs. This
225 * routine should be called if the driver has reason to believe that
226 * PHYs have changed. This is implicitly executed the first time
227 * monitoring is started on the MII bus, and normally need not be
228 * explicitly called. This function may be called in any context
229 * except high level interrupt context, but must be called
230 * without any locks held.
232 void mii_probe(mii_handle_t mii);
235 * mii_check
237 * Used to alert the MII layer that it should check for changes.
238 * This can be called by drivers in response to link status
239 * interrupts, for example, giving a quicker response to link
240 * status changes without waiting for the MII timer to expire.
241 * This function may be called in any context except high level
242 * interrupt context, but must be called without any locks held.
244 void mii_check(mii_handle_t mii);
247 * mii_get_addr
249 * Used to get the PHY address that is currently active for the MII
250 * bus. This function may be called in any context.
252 * Returns
254 * The PHY address (0-31) if a PHY is active on the MII bus. If
255 * no PHY is active, -1 is returned.
257 int mii_get_addr(mii_handle_t mii);
260 * mii_get_id
262 * Used to get the identifier of the active PHY. This function
263 * may be called in any context.
265 * Returns
267 * The PHY identifier register contents, encoded with the high
268 * order (PHYIDH) bits in the upper word and the low order bits
269 * in the lower word. If no PHY is active, the value -1 will be
270 * returned.
272 uint32_t mii_get_id(mii_handle_t mii);
275 * mii_get_speed
277 * Used to get the speed of the active PHY. This function may be
278 * called in any context.
280 * Returns
282 * The speed, in Mbps, if the active PHY has link (10, 100, or 1000),
283 * otherwise 0.
285 int mii_get_speed(mii_handle_t mii);
288 * mii_get_duplex
290 * Used to get the duplex of the active PHY. This function may
291 * be called in any context.
293 * Returns
295 * The duplex, if the active PHY has link (LINK_DUPLEX_FULL or
296 * LINK_DUPLEX_HALF), otherwise LINK_DUPLEX_UNKNOWN.
298 link_duplex_t mii_get_duplex(mii_handle_t mii);
301 * mii_get_state
303 * Used to get the state of the link on the active PHY. This
304 * function may be called in any context.
306 * Returns
308 * The link state (LINK_STATE_UP or LINK_STATE_DOWN), if known,
309 * otherwise LINK_STATE_UNKNOWN.
311 link_state_t mii_get_state(mii_handle_t mii);
314 * mii_get_flowctrl
316 * Used to get the state of the negotiated flow control on the
317 * active PHY. This function may be called in any context.
319 * Returns
321 * The flowctrl state (LINK_FLOWCTRL_NONE, LINK_FLOWCTRL_RX,
322 * LINK_FLOWCTRL_TX, or LINK_FLOWCTRL_BI.
324 link_flowctrl_t mii_get_flowctrl(mii_handle_t mii);
327 * mii_get_loopmodes
329 * This function is used to support the LB_GET_INFO_SIZE and
330 * LB_GET_INFO ioctls. It probably should not be used outside of
331 * that context. The modes supplied are supported by the MII/PHY.
332 * Drivers may wish to add modes for MAC internal loopbacks as well.
333 * See <sys/netlb.h> for more information.
335 * Note that the first item in the modes array will always be the
336 * mode to disable the MII/PHY loopback, and will have the value
337 * MII_LOOPBACK_NONE.
339 * Arguments
341 * mii MII handle.
342 * modes Location to receive an array of loopback modes.
343 * Drivers should ensure that enough room is available.
344 * There will never be more than MII_LOOPBACK_MAX modes
345 * returned. May be NULL, in which case no data will
346 * be returned to the caller.
348 * Returns
350 * Count of number of modes available, in no case larger than
351 * MII_LOOPBACK_MAX.
353 int mii_get_loopmodes(mii_handle_t mii, lb_property_t *modes);
355 #define MII_LOOPBACK_MAX 16
356 #define MII_LOOPBACK_NONE 0
359 * mii_set_loopback
361 * Sets the loopback mode, intended for use in support of the
362 * LB_SET_MODE ioctl. The mode value will be one of the values
363 * returned in the modes array (see mii_get_loopmodes), or the
364 * special value MII_LOOPBACK_NONE to return to normal operation.
366 * Arguments
368 * mii MII handle.
369 * mode New loopback mode number; MII_LOOPBACK_NONE indicates
370 * a return to normal operation.
372 * Returns
374 * Zero on success, or EINVAL if the mode is invalid or unsupported.
376 int mii_set_loopback(mii_handle_t mii, uint32_t mode);
379 * mii_get_loopback
381 * Queries the loopback mode, intended for use in support of the
382 * LB_GET_MODE ioctl, but may be useful in programming device
383 * settings that are sensitive to loopback setting.
385 * Returns
387 * The current mode number (one of the reported by
388 * mii_get_loopmodes), or the special value MII_LOOPBACK_NONE
389 * indicating that loopback is not in use.
391 uint32_t mii_get_loopback(mii_handle_t mii);
394 * mii_m_loop_ioctl
396 * Used to support the driver's mc_ioctl() for loopback ioctls.
397 * If the driver is going to use the loopback optons from the
398 * PHY, and isn't adding any MAC level loopback, then this function
399 * can handle the entire set of ioctls, removing yet more code from
400 * the driver. Ultimately, this is a very reasonable thing to do,
401 * since the PHY level loopback should exercise all of the same
402 * MAC level circuitry that a MAC internal loopback would do.
404 * Arguments
406 * mii MII handle.
407 * wq The write queue supplied to mc_ioctl().
408 * msg The mblk from the mc_ioctl (contains an iocblk).
410 * Returns
412 * B_TRUE if the ioctl was handled by the driver.
413 * B_FALSE if the ioctl was not handled, and may need to be
414 * handled by the driver.
416 boolean_t mii_m_loop_ioctl(mii_handle_t mii, queue_t *wq, mblk_t *msg);
419 * mii_m_getprop
421 * Used to support the driver's mc_getprop() mac callback,
422 * and only to be called from that function (and without any
423 * locks held). This routine will process all of the properties
424 * that are relevant to MII on behalf of the driver.
426 * Arguments
428 * mii MII handle.
429 * name Property name.
430 * id Property ID.
431 * sz Size of property in bytes.
432 * val Location to receive property value.
434 * Returns
436 * 0 on successful handling of property.
437 * EINVAL if invalid arguments (e.g. a bad size) are supplied.
438 * ENOTSUP if the prooperty is not supported by MII or the PHY.
440 int mii_m_getprop(mii_handle_t mii, const char *name, mac_prop_id_t id,
441 uint_t sz, void *val);
444 * mii_m_setprop
446 * Used to support the driver's mc_setprop() mac callback,
447 * and only to be called from that function (and without any
448 * locks held). This routine will process all of the properties
449 * that are relevant to MII on behalf of the driver. This will
450 * often result in the PHY being reset.
452 * Arguments
454 * mii MII handle.
455 * name Property name.
456 * id Property ID.
457 * sz Size of property in bytes.
458 * val Location of property value.
460 * Returns
462 * 0 on successful handling of property.
463 * EINVAL if invalid arguments (e.g. a bad size) are supplied.
464 * ENOTSUP if the prooperty is not supported by MII or the PHY,
465 * or if the property is read-only.
467 int mii_m_setprop(mii_handle_t mii, const char *name, mac_prop_id_t id,
468 uint_t sz, const void *val);
471 * mii_m_propinfo
473 * Used to support the driver's mc_setprop() mac callback,
474 * and only to be called from that function (and without any
475 * locks held).
477 * Arguments
479 * mii MII handle.
480 * name Property name.
481 * id Property ID.
482 * prh Property info handle.
485 void mii_m_propinfo(mii_handle_t mii, const char *name, mac_prop_id_t id,
486 mac_prop_info_handle_t prh);
490 * mii_m_getstat
492 * Used to support the driver's mc_getstat() mac callback for
493 * statistic collection, and only to be called from that function
494 * (without any locks held). This routine will process all of
495 * the statistics that are relevant to MII on behalf of the
496 * driver.
498 * Arguments
500 * mii MII handle.
501 * stat Statistic number.
502 * val Location to receive statistic value.
504 * Returns
506 * 0 on successful handling of statistic.
507 * ENOTSUP if the statistic is not supported by MII.
509 int mii_m_getstat(mii_handle_t mii, uint_t stat, uint64_t *val);
511 #endif /* _KERNEL */
513 #ifdef __cplusplus
515 #endif
517 #endif /* _SYS_MII_H */