1bdb9230aSGarrett D'Amore /* 2bdb9230aSGarrett D'Amore * CDDL HEADER START 3bdb9230aSGarrett D'Amore * 4bdb9230aSGarrett D'Amore * The contents of this file are subject to the terms of the 5bdb9230aSGarrett D'Amore * Common Development and Distribution License (the "License"). 6bdb9230aSGarrett D'Amore * You may not use this file except in compliance with the License. 7bdb9230aSGarrett D'Amore * 8bdb9230aSGarrett D'Amore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9bdb9230aSGarrett D'Amore * or http://www.opensolaris.org/os/licensing. 10bdb9230aSGarrett D'Amore * See the License for the specific language governing permissions 11bdb9230aSGarrett D'Amore * and limitations under the License. 12bdb9230aSGarrett D'Amore * 13bdb9230aSGarrett D'Amore * When distributing Covered Code, include this CDDL HEADER in each 14bdb9230aSGarrett D'Amore * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15bdb9230aSGarrett D'Amore * If applicable, add the following below this CDDL HEADER, with the 16bdb9230aSGarrett D'Amore * fields enclosed by brackets "[]" replaced with your own identifying 17bdb9230aSGarrett D'Amore * information: Portions Copyright [yyyy] [name of copyright owner] 18bdb9230aSGarrett D'Amore * 19bdb9230aSGarrett D'Amore * CDDL HEADER END 20bdb9230aSGarrett D'Amore */ 21bdb9230aSGarrett D'Amore /* 22*0dc2366fSVenugopal Iyer * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 23bdb9230aSGarrett D'Amore * Use is subject to license terms. 24bdb9230aSGarrett D'Amore */ 25bdb9230aSGarrett D'Amore 26bdb9230aSGarrett D'Amore /* 27bdb9230aSGarrett D'Amore * mii.h 28bdb9230aSGarrett D'Amore * Generic MII/PHY Support for MAC drivers. 29bdb9230aSGarrett D'Amore */ 30bdb9230aSGarrett D'Amore 31bdb9230aSGarrett D'Amore #ifndef _SYS_MII_H 32bdb9230aSGarrett D'Amore #define _SYS_MII_H 33bdb9230aSGarrett D'Amore 34bdb9230aSGarrett D'Amore #include <sys/mac_provider.h> 35bdb9230aSGarrett D'Amore #include <sys/netlb.h> 36bdb9230aSGarrett D'Amore 37bdb9230aSGarrett D'Amore #ifdef __cplusplus 38bdb9230aSGarrett D'Amore extern "C" { 39bdb9230aSGarrett D'Amore #endif 40bdb9230aSGarrett D'Amore 41bdb9230aSGarrett D'Amore /* 42bdb9230aSGarrett D'Amore * NOTES 43bdb9230aSGarrett D'Amore * 44bdb9230aSGarrett D'Amore * The device driver is required to protect its own registers. The 45bdb9230aSGarrett D'Amore * MII common code will call MII entry points asynchronously, from a 46bdb9230aSGarrett D'Amore * taskq, and holds an internal lock across such calls (except the 47bdb9230aSGarrett D'Amore * notify entry point). Therefore, device drivers MUST NOT hold any 48bdb9230aSGarrett D'Amore * locks across calls into the MII framework. 49bdb9230aSGarrett D'Amore * 50bdb9230aSGarrett D'Amore * If a device must be suspended (e.g. due to DDI_SUSPEND) the MII 51bdb9230aSGarrett D'Amore * layer can be suspended by calling mii_stop(). After this point, 52bdb9230aSGarrett D'Amore * the monitoring task will be suspended and the driver can be assured 53bdb9230aSGarrett D'Amore * that MII will not interfere until restarted with mii_start(). 54bdb9230aSGarrett D'Amore * 55bdb9230aSGarrett D'Amore * Note that monitoring is not started until mii_start() is called. 56bdb9230aSGarrett D'Amore * The mii_start() function may be called multiple times. It performs 57bdb9230aSGarrett D'Amore * an implicit reset of the MII bus and PHY. 58bdb9230aSGarrett D'Amore * 59bdb9230aSGarrett D'Amore * Once started, if not already done, a probe of the MII bus is done to 60bdb9230aSGarrett D'Amore * find a suitable PHY. If no PHY is found, then you won't have any 61bdb9230aSGarrett D'Amore * link! Once a suitable PHY is selected, any other PHYs are isolated and 62bdb9230aSGarrett D'Amore * powered down. The device driver can cause MII to re-probe the bus for 63bdb9230aSGarrett D'Amore * changes to the available PHYs by calling mii_probe(). Note that this 64bdb9230aSGarrett D'Amore * will also cause a full reset of all PHYs. 65bdb9230aSGarrett D'Amore * 66bdb9230aSGarrett D'Amore * The mii_reset entry point, which is optional, is used to notify the 67bdb9230aSGarrett D'Amore * driver when the MII layer has reset the device. This can allow 68bdb9230aSGarrett D'Amore * certain drivers the opportunity to "fix up" things after reset. 69bdb9230aSGarrett D'Amore * Note however, that when possible, it is better if the logic is 70bdb9230aSGarrett D'Amore * encoded into a vendor specific PHY module. 71bdb9230aSGarrett D'Amore */ 72bdb9230aSGarrett D'Amore 73bdb9230aSGarrett D'Amore #ifdef _KERNEL 74bdb9230aSGarrett D'Amore 75bdb9230aSGarrett D'Amore typedef struct mii_handle *mii_handle_t; 76bdb9230aSGarrett D'Amore typedef struct mii_ops mii_ops_t; 77bdb9230aSGarrett D'Amore 78bdb9230aSGarrett D'Amore struct mii_ops { 79bdb9230aSGarrett D'Amore int mii_version; 80bdb9230aSGarrett D'Amore uint16_t (*mii_read)(void *, uint8_t, uint8_t); 81bdb9230aSGarrett D'Amore void (*mii_write)(void *, uint8_t, uint8_t, uint16_t); 82bdb9230aSGarrett D'Amore void (*mii_notify)(void *, link_state_t); 83bdb9230aSGarrett D'Amore void (*mii_reset)(void *); 84bdb9230aSGarrett D'Amore }; 85bdb9230aSGarrett D'Amore #define MII_OPS_VERSION 0 86bdb9230aSGarrett D'Amore 87bdb9230aSGarrett D'Amore /* 88bdb9230aSGarrett D'Amore * Support routines. 89bdb9230aSGarrett D'Amore */ 90bdb9230aSGarrett D'Amore 91bdb9230aSGarrett D'Amore /* 92bdb9230aSGarrett D'Amore * mii_alloc 93bdb9230aSGarrett D'Amore * 94bdb9230aSGarrett D'Amore * Allocate an MII handle. Called during driver's attach(9e) 95bdb9230aSGarrett D'Amore * handling, this routine is valid in kernel context only. 96bdb9230aSGarrett D'Amore * 97bdb9230aSGarrett D'Amore * Arguments 98bdb9230aSGarrett D'Amore * 99bdb9230aSGarrett D'Amore * private A private state structure, provided back to 100bdb9230aSGarrett D'Amore * entry points. 101bdb9230aSGarrett D'Amore * dip The dev_info node for the MAC driver. 102bdb9230aSGarrett D'Amore * ops Entry points into the MAC driver. 103bdb9230aSGarrett D'Amore * 104bdb9230aSGarrett D'Amore * Returns 105bdb9230aSGarrett D'Amore * Handle to MII bus on success, NULL on failure. 106bdb9230aSGarrett D'Amore */ 107bdb9230aSGarrett D'Amore mii_handle_t mii_alloc(void *private, dev_info_t *dip, mii_ops_t *ops); 108bdb9230aSGarrett D'Amore 109bdb9230aSGarrett D'Amore /* 110bdb9230aSGarrett D'Amore * mii_alloc 111bdb9230aSGarrett D'Amore * 112bdb9230aSGarrett D'Amore * Allocate an MII handle. Called during driver's attach(9e) 113bdb9230aSGarrett D'Amore * handling, this routine is valid in kernel context only. This 114bdb9230aSGarrett D'Amore * routine is an alternative to mii_alloc() for use when the 115bdb9230aSGarrett D'Amore * instance number (PPA) is not the same as the devinfo instance 116bdb9230aSGarrett D'Amore * number, and hence needs to be overridden. 117bdb9230aSGarrett D'Amore * 118bdb9230aSGarrett D'Amore * Arguments 119bdb9230aSGarrett D'Amore * 120bdb9230aSGarrett D'Amore * private A private state structure, provided back to 121bdb9230aSGarrett D'Amore * entry points. 122bdb9230aSGarrett D'Amore * dip The dev_info node for the MAC driver. 123bdb9230aSGarrett D'Amore * instance The instance (PPA) of the interface. 124bdb9230aSGarrett D'Amore * ops Entry points into the MAC driver. 125bdb9230aSGarrett D'Amore * 126bdb9230aSGarrett D'Amore * Returns 127bdb9230aSGarrett D'Amore * Handle to MII bus on success, NULL on failure. 128bdb9230aSGarrett D'Amore */ 129bdb9230aSGarrett D'Amore mii_handle_t mii_alloc_instance(void *private, dev_info_t *dip, int instance, 130bdb9230aSGarrett D'Amore mii_ops_t *ops); 131bdb9230aSGarrett D'Amore 132bdb9230aSGarrett D'Amore /* 133bdb9230aSGarrett D'Amore * mii_free 134bdb9230aSGarrett D'Amore * 135bdb9230aSGarrett D'Amore * Free an MII handle and associated resources. Call from 136bdb9230aSGarrett D'Amore * detach(9e) handling, this routine is valid in kernel context 137bdb9230aSGarrett D'Amore * only. 138bdb9230aSGarrett D'Amore */ 139bdb9230aSGarrett D'Amore void mii_free(mii_handle_t mii); 140bdb9230aSGarrett D'Amore 141bdb9230aSGarrett D'Amore /* 142bdb9230aSGarrett D'Amore * mii_set_pauseable 143bdb9230aSGarrett D'Amore * 144bdb9230aSGarrett D'Amore * Lets the MII know if the MAC layer can support pause or 145bdb9230aSGarrett D'Amore * asymetric pause capabilities. The MII layer will use this to 146bdb9230aSGarrett D'Amore * determine what capabilities should be negotiated for (along 147bdb9230aSGarrett D'Amore * with user preferences, of course.) If not called, the MII 148bdb9230aSGarrett D'Amore * will assume the device has no support for flow control. 149bdb9230aSGarrett D'Amore * 150bdb9230aSGarrett D'Amore * Arguments 151bdb9230aSGarrett D'Amore * 152bdb9230aSGarrett D'Amore * mii MII handle. 153bdb9230aSGarrett D'Amore * cap B_TRUE if the device supports symmetric of pause. 154bdb9230aSGarrett D'Amore * asym B_TRUE if the device supports asymmetric pause. 155bdb9230aSGarrett D'Amore */ 156bdb9230aSGarrett D'Amore void mii_set_pauseable(mii_handle_t mii, boolean_t cap, boolean_t asym); 157bdb9230aSGarrett D'Amore 158bdb9230aSGarrett D'Amore /* 159bdb9230aSGarrett D'Amore * mii_reset 160bdb9230aSGarrett D'Amore * 161bdb9230aSGarrett D'Amore * Schedules a reset of the MII bus. Normally not needed, but 162bdb9230aSGarrett D'Amore * can be used to perform a full master reset, including 163bdb9230aSGarrett D'Amore * rescanning for PHYs. This function may be called in any 164bdb9230aSGarrett D'Amore * context except high level interrupt context, but must be 165bdb9230aSGarrett D'Amore * called without any locks held. The reset will probably not 166bdb9230aSGarrett D'Amore * be complete until sometime after the call returns. 167bdb9230aSGarrett D'Amore * 168bdb9230aSGarrett D'Amore * Note that if mii_start has not been called, then the reset 169bdb9230aSGarrett D'Amore * will not be performed until _after_ the MII is started. 170bdb9230aSGarrett D'Amore */ 171bdb9230aSGarrett D'Amore void mii_reset(mii_handle_t mii); 172bdb9230aSGarrett D'Amore 173bdb9230aSGarrett D'Amore 174bdb9230aSGarrett D'Amore /* 175bdb9230aSGarrett D'Amore * mii_start 176bdb9230aSGarrett D'Amore * 177bdb9230aSGarrett D'Amore * Starts monitoring of the MII bus. Normally this is called as 178bdb9230aSGarrett D'Amore * a result of a driver's mac_start() entry point, but it may also 179bdb9230aSGarrett D'Amore * be called when a PHY needs to be reset or during handling of 180bdb9230aSGarrett D'Amore * DDI_RESUME. This function may be called in any context except 181bdb9230aSGarrett D'Amore * high level interrupt context, but 182bdb9230aSGarrett D'Amore * must be called without any locks held. 183bdb9230aSGarrett D'Amore */ 184bdb9230aSGarrett D'Amore void mii_start(mii_handle_t mii); 185bdb9230aSGarrett D'Amore 186bdb9230aSGarrett D'Amore /* 187bdb9230aSGarrett D'Amore * mii_stop 188bdb9230aSGarrett D'Amore * 189bdb9230aSGarrett D'Amore * Stops monitoring of the MII bus. Normally this is called as a 190bdb9230aSGarrett D'Amore * result of a driver's mac_stop() entry point. As a side 191bdb9230aSGarrett D'Amore * effect, also isolates and powers down any active PHY. On 192bdb9230aSGarrett D'Amore * return, the MII layer is guaranteed not to be executing any 193bdb9230aSGarrett D'Amore * code in the MII entry points. This function may be called in 194bdb9230aSGarrett D'Amore * any context except high level interrupt context, but must be 195bdb9230aSGarrett D'Amore * called without any locks held. 196bdb9230aSGarrett D'Amore */ 197bdb9230aSGarrett D'Amore void mii_stop(mii_handle_t mii); 198bdb9230aSGarrett D'Amore 199bdb9230aSGarrett D'Amore /* 200bdb9230aSGarrett D'Amore * mii_resume 201bdb9230aSGarrett D'Amore * 202bdb9230aSGarrett D'Amore * Starts monitoring of the MII bus. Normally this is called as 203bdb9230aSGarrett D'Amore * a part of a driver's DDI_RESUME handling. This function may 204bdb9230aSGarrett D'Amore * be called in any context except high level interrupt context, 205bdb9230aSGarrett D'Amore * but must be called without any locks held. 206bdb9230aSGarrett D'Amore */ 207bdb9230aSGarrett D'Amore void mii_resume(mii_handle_t mii); 208bdb9230aSGarrett D'Amore 209bdb9230aSGarrett D'Amore /* 210bdb9230aSGarrett D'Amore * mii_suspend 211bdb9230aSGarrett D'Amore * 212bdb9230aSGarrett D'Amore * Suspends monitoring of the MII bus. Normally this is called 213bdb9230aSGarrett D'Amore * as a part of a driver's DDI_SUSPEND handling. On return, the 214bdb9230aSGarrett D'Amore * MII layer is guaranteed not to be executing any code in the 215bdb9230aSGarrett D'Amore * MII entry points. This function may be called in any context 216bdb9230aSGarrett D'Amore * except high level interrupt context, but must be called 217bdb9230aSGarrett D'Amore * without any locks held. 218bdb9230aSGarrett D'Amore */ 219bdb9230aSGarrett D'Amore void mii_suspend(mii_handle_t mii); 220bdb9230aSGarrett D'Amore 221bdb9230aSGarrett D'Amore /* 222bdb9230aSGarrett D'Amore * mii_probe 223bdb9230aSGarrett D'Amore * 224bdb9230aSGarrett D'Amore * Used to reset the entire MII bus and probe for PHYs. This 225bdb9230aSGarrett D'Amore * routine should be called if the driver has reason to believe that 226bdb9230aSGarrett D'Amore * PHYs have changed. This is implicitly executed the first time 227bdb9230aSGarrett D'Amore * monitoring is started on the MII bus, and normally need not be 228bdb9230aSGarrett D'Amore * explicitly called. This function may be called in any context 229bdb9230aSGarrett D'Amore * except high level interrupt context, but must be called 230bdb9230aSGarrett D'Amore * without any locks held. 231bdb9230aSGarrett D'Amore */ 232bdb9230aSGarrett D'Amore void mii_probe(mii_handle_t mii); 233bdb9230aSGarrett D'Amore 234bdb9230aSGarrett D'Amore /* 235bdb9230aSGarrett D'Amore * mii_check 236bdb9230aSGarrett D'Amore * 237bdb9230aSGarrett D'Amore * Used to alert the MII layer that it should check for changes. 238bdb9230aSGarrett D'Amore * This can be called by drivers in response to link status 239bdb9230aSGarrett D'Amore * interrupts, for example, giving a quicker response to link 240bdb9230aSGarrett D'Amore * status changes without waiting for the MII timer to expire. 241bdb9230aSGarrett D'Amore * This function may be called in any context except high level 242bdb9230aSGarrett D'Amore * interrupt context, but must be called without any locks held. 243bdb9230aSGarrett D'Amore */ 244bdb9230aSGarrett D'Amore void mii_check(mii_handle_t mii); 245bdb9230aSGarrett D'Amore 246bdb9230aSGarrett D'Amore /* 247bdb9230aSGarrett D'Amore * mii_get_addr 248bdb9230aSGarrett D'Amore * 249bdb9230aSGarrett D'Amore * Used to get the PHY address that is currently active for the MII 250bdb9230aSGarrett D'Amore * bus. This function may be called in any context. 251bdb9230aSGarrett D'Amore * 252bdb9230aSGarrett D'Amore * Returns 253bdb9230aSGarrett D'Amore * 254bdb9230aSGarrett D'Amore * The PHY address (0-31) if a PHY is active on the MII bus. If 255bdb9230aSGarrett D'Amore * no PHY is active, -1 is returned. 256bdb9230aSGarrett D'Amore */ 257bdb9230aSGarrett D'Amore int mii_get_addr(mii_handle_t mii); 258bdb9230aSGarrett D'Amore 259bdb9230aSGarrett D'Amore /* 260bdb9230aSGarrett D'Amore * mii_get_id 261bdb9230aSGarrett D'Amore * 262bdb9230aSGarrett D'Amore * Used to get the identifier of the active PHY. This function 263bdb9230aSGarrett D'Amore * may be called in any context. 264bdb9230aSGarrett D'Amore * 265bdb9230aSGarrett D'Amore * Returns 266bdb9230aSGarrett D'Amore * 267bdb9230aSGarrett D'Amore * The PHY identifier register contents, encoded with the high 268bdb9230aSGarrett D'Amore * order (PHYIDH) bits in the upper word and the low order bits 269bdb9230aSGarrett D'Amore * in the lower word. If no PHY is active, the value -1 will be 270bdb9230aSGarrett D'Amore * returned. 271bdb9230aSGarrett D'Amore */ 272bdb9230aSGarrett D'Amore uint32_t mii_get_id(mii_handle_t mii); 273bdb9230aSGarrett D'Amore 274bdb9230aSGarrett D'Amore /* 275bdb9230aSGarrett D'Amore * mii_get_speed 276bdb9230aSGarrett D'Amore * 277bdb9230aSGarrett D'Amore * Used to get the speed of the active PHY. This function may be 278bdb9230aSGarrett D'Amore * called in any context. 279bdb9230aSGarrett D'Amore * 280bdb9230aSGarrett D'Amore * Returns 281bdb9230aSGarrett D'Amore * 282bdb9230aSGarrett D'Amore * The speed, in Mbps, if the active PHY has link (10, 100, or 1000), 283bdb9230aSGarrett D'Amore * otherwise 0. 284bdb9230aSGarrett D'Amore */ 285bdb9230aSGarrett D'Amore int mii_get_speed(mii_handle_t mii); 286bdb9230aSGarrett D'Amore 287bdb9230aSGarrett D'Amore /* 288bdb9230aSGarrett D'Amore * mii_get_duplex 289bdb9230aSGarrett D'Amore * 290bdb9230aSGarrett D'Amore * Used to get the duplex of the active PHY. This function may 291bdb9230aSGarrett D'Amore * be called in any context. 292bdb9230aSGarrett D'Amore * 293bdb9230aSGarrett D'Amore * Returns 294bdb9230aSGarrett D'Amore * 295bdb9230aSGarrett D'Amore * The duplex, if the active PHY has link (LINK_DUPLEX_FULL or 296bdb9230aSGarrett D'Amore * LINK_DUPLEX_HALF), otherwise LINK_DUPLEX_UNKNOWN. 297bdb9230aSGarrett D'Amore */ 298bdb9230aSGarrett D'Amore link_duplex_t mii_get_duplex(mii_handle_t mii); 299bdb9230aSGarrett D'Amore 300bdb9230aSGarrett D'Amore /* 301bdb9230aSGarrett D'Amore * mii_get_state 302bdb9230aSGarrett D'Amore * 303bdb9230aSGarrett D'Amore * Used to get the state of the link on the active PHY. This 304bdb9230aSGarrett D'Amore * function may be called in any context. 305bdb9230aSGarrett D'Amore * 306bdb9230aSGarrett D'Amore * Returns 307bdb9230aSGarrett D'Amore * 308bdb9230aSGarrett D'Amore * The link state (LINK_STATE_UP or LINK_STATE_DOWN), if known, 309bdb9230aSGarrett D'Amore * otherwise LINK_STATE_UNKNOWN. 310bdb9230aSGarrett D'Amore */ 311bdb9230aSGarrett D'Amore link_state_t mii_get_state(mii_handle_t mii); 312bdb9230aSGarrett D'Amore 313bdb9230aSGarrett D'Amore /* 314bdb9230aSGarrett D'Amore * mii_get_flowctrl 315bdb9230aSGarrett D'Amore * 316bdb9230aSGarrett D'Amore * Used to get the state of the negotiated flow control on the 317bdb9230aSGarrett D'Amore * active PHY. This function may be called in any context. 318bdb9230aSGarrett D'Amore * 319bdb9230aSGarrett D'Amore * Returns 320bdb9230aSGarrett D'Amore * 321bdb9230aSGarrett D'Amore * The flowctrl state (LINK_FLOWCTRL_NONE, LINK_FLOWCTRL_RX, 322bdb9230aSGarrett D'Amore * LINK_FLOWCTRL_TX, or LINK_FLOWCTRL_BI. 323bdb9230aSGarrett D'Amore */ 324bdb9230aSGarrett D'Amore link_flowctrl_t mii_get_flowctrl(mii_handle_t mii); 325bdb9230aSGarrett D'Amore 326bdb9230aSGarrett D'Amore /* 327bdb9230aSGarrett D'Amore * mii_get_loopmodes 328bdb9230aSGarrett D'Amore * 329bdb9230aSGarrett D'Amore * This function is used to support the LB_GET_INFO_SIZE and 330bdb9230aSGarrett D'Amore * LB_GET_INFO ioctls. It probably should not be used outside of 331bdb9230aSGarrett D'Amore * that context. The modes supplied are supported by the MII/PHY. 332bdb9230aSGarrett D'Amore * Drivers may wish to add modes for MAC internal loopbacks as well. 333bdb9230aSGarrett D'Amore * See <sys/netlb.h> for more information. 334bdb9230aSGarrett D'Amore * 335bdb9230aSGarrett D'Amore * Note that the first item in the modes array will always be the 336bdb9230aSGarrett D'Amore * mode to disable the MII/PHY loopback, and will have the value 337bdb9230aSGarrett D'Amore * MII_LOOPBACK_NONE. 338bdb9230aSGarrett D'Amore * 339bdb9230aSGarrett D'Amore * Arguments 340bdb9230aSGarrett D'Amore * 341bdb9230aSGarrett D'Amore * mii MII handle. 342bdb9230aSGarrett D'Amore * modes Location to receive an array of loopback modes. 343bdb9230aSGarrett D'Amore * Drivers should ensure that enough room is available. 344bdb9230aSGarrett D'Amore * There will never be more than MII_LOOPBACK_MAX modes 345bdb9230aSGarrett D'Amore * returned. May be NULL, in which case no data will 346bdb9230aSGarrett D'Amore * be returned to the caller. 347bdb9230aSGarrett D'Amore * 348bdb9230aSGarrett D'Amore * Returns 349bdb9230aSGarrett D'Amore * 350bdb9230aSGarrett D'Amore * Count of number of modes available, in no case larger than 351bdb9230aSGarrett D'Amore * MII_LOOPBACK_MAX. 352bdb9230aSGarrett D'Amore */ 353bdb9230aSGarrett D'Amore int mii_get_loopmodes(mii_handle_t mii, lb_property_t *modes); 354bdb9230aSGarrett D'Amore 355bdb9230aSGarrett D'Amore #define MII_LOOPBACK_MAX 16 356bdb9230aSGarrett D'Amore #define MII_LOOPBACK_NONE 0 357bdb9230aSGarrett D'Amore 358bdb9230aSGarrett D'Amore /* 359bdb9230aSGarrett D'Amore * mii_set_loopback 360bdb9230aSGarrett D'Amore * 361bdb9230aSGarrett D'Amore * Sets the loopback mode, intended for use in support of the 362bdb9230aSGarrett D'Amore * LB_SET_MODE ioctl. The mode value will be one of the values 363bdb9230aSGarrett D'Amore * returned in the modes array (see mii_get_loopmodes), or the 364bdb9230aSGarrett D'Amore * special value MII_LOOPBACK_NONE to return to normal operation. 365bdb9230aSGarrett D'Amore * 366bdb9230aSGarrett D'Amore * Arguments 367bdb9230aSGarrett D'Amore * 368bdb9230aSGarrett D'Amore * mii MII handle. 369bdb9230aSGarrett D'Amore * mode New loopback mode number; MII_LOOPBACK_NONE indicates 370bdb9230aSGarrett D'Amore * a return to normal operation. 371bdb9230aSGarrett D'Amore * 372bdb9230aSGarrett D'Amore * Returns 373bdb9230aSGarrett D'Amore * 374bdb9230aSGarrett D'Amore * Zero on success, or EINVAL if the mode is invalid or unsupported. 375bdb9230aSGarrett D'Amore */ 376bdb9230aSGarrett D'Amore int mii_set_loopback(mii_handle_t mii, uint32_t mode); 377bdb9230aSGarrett D'Amore 378bdb9230aSGarrett D'Amore /* 379bdb9230aSGarrett D'Amore * mii_get_loopback 380bdb9230aSGarrett D'Amore * 381bdb9230aSGarrett D'Amore * Queries the loopback mode, intended for use in support of the 382bdb9230aSGarrett D'Amore * LB_GET_MODE ioctl, but may be useful in programming device 383bdb9230aSGarrett D'Amore * settings that are sensitive to loopback setting. 384bdb9230aSGarrett D'Amore * 385bdb9230aSGarrett D'Amore * Returns 386bdb9230aSGarrett D'Amore * 387bdb9230aSGarrett D'Amore * The current mode number (one of the reported by 388bdb9230aSGarrett D'Amore * mii_get_loopmodes), or the special value MII_LOOPBACK_NONE 389bdb9230aSGarrett D'Amore * indicating that loopback is not in use. 390bdb9230aSGarrett D'Amore */ 391bdb9230aSGarrett D'Amore uint32_t mii_get_loopback(mii_handle_t mii); 392bdb9230aSGarrett D'Amore 393bdb9230aSGarrett D'Amore /* 394bdb9230aSGarrett D'Amore * mii_m_loop_ioctl 395bdb9230aSGarrett D'Amore * 396bdb9230aSGarrett D'Amore * Used to support the driver's mc_ioctl() for loopback ioctls. 397bdb9230aSGarrett D'Amore * If the driver is going to use the loopback optons from the 398bdb9230aSGarrett D'Amore * PHY, and isn't adding any MAC level loopback, then this function 399bdb9230aSGarrett D'Amore * can handle the entire set of ioctls, removing yet more code from 400bdb9230aSGarrett D'Amore * the driver. Ultimately, this is a very reasonable thing to do, 401bdb9230aSGarrett D'Amore * since the PHY level loopback should exercise all of the same 402bdb9230aSGarrett D'Amore * MAC level circuitry that a MAC internal loopback would do. 403bdb9230aSGarrett D'Amore * 404bdb9230aSGarrett D'Amore * Arguments 405bdb9230aSGarrett D'Amore * 406bdb9230aSGarrett D'Amore * mii MII handle. 407bdb9230aSGarrett D'Amore * wq The write queue supplied to mc_ioctl(). 408bdb9230aSGarrett D'Amore * msg The mblk from the mc_ioctl (contains an iocblk). 409bdb9230aSGarrett D'Amore * 410bdb9230aSGarrett D'Amore * Returns 411bdb9230aSGarrett D'Amore * 412bdb9230aSGarrett D'Amore * B_TRUE if the ioctl was handled by the driver. 413bdb9230aSGarrett D'Amore * B_FALSE if the ioctl was not handled, and may need to be 414bdb9230aSGarrett D'Amore * handled by the driver. 415bdb9230aSGarrett D'Amore */ 416bdb9230aSGarrett D'Amore boolean_t mii_m_loop_ioctl(mii_handle_t mii, queue_t *wq, mblk_t *msg); 417bdb9230aSGarrett D'Amore 418bdb9230aSGarrett D'Amore /* 419bdb9230aSGarrett D'Amore * mii_m_getprop 420bdb9230aSGarrett D'Amore * 421bdb9230aSGarrett D'Amore * Used to support the driver's mc_getprop() mac callback, 422bdb9230aSGarrett D'Amore * and only to be called from that function (and without any 423bdb9230aSGarrett D'Amore * locks held). This routine will process all of the properties 424bdb9230aSGarrett D'Amore * that are relevant to MII on behalf of the driver. 425bdb9230aSGarrett D'Amore * 426bdb9230aSGarrett D'Amore * Arguments 427bdb9230aSGarrett D'Amore * 428bdb9230aSGarrett D'Amore * mii MII handle. 429bdb9230aSGarrett D'Amore * name Property name. 430bdb9230aSGarrett D'Amore * id Property ID. 431bdb9230aSGarrett D'Amore * sz Size of property in bytes. 432bdb9230aSGarrett D'Amore * val Location to receive property value. 433bdb9230aSGarrett D'Amore * 434bdb9230aSGarrett D'Amore * Returns 435bdb9230aSGarrett D'Amore * 436bdb9230aSGarrett D'Amore * 0 on successful handling of property. 437bdb9230aSGarrett D'Amore * EINVAL if invalid arguments (e.g. a bad size) are supplied. 438bdb9230aSGarrett D'Amore * ENOTSUP if the prooperty is not supported by MII or the PHY. 439bdb9230aSGarrett D'Amore */ 440bdb9230aSGarrett D'Amore int mii_m_getprop(mii_handle_t mii, const char *name, mac_prop_id_t id, 441*0dc2366fSVenugopal Iyer uint_t sz, void *val); 442bdb9230aSGarrett D'Amore 443bdb9230aSGarrett D'Amore /* 444bdb9230aSGarrett D'Amore * mii_m_setprop 445bdb9230aSGarrett D'Amore * 446bdb9230aSGarrett D'Amore * Used to support the driver's mc_setprop() mac callback, 447bdb9230aSGarrett D'Amore * and only to be called from that function (and without any 448bdb9230aSGarrett D'Amore * locks held). This routine will process all of the properties 449bdb9230aSGarrett D'Amore * that are relevant to MII on behalf of the driver. This will 450bdb9230aSGarrett D'Amore * often result in the PHY being reset. 451bdb9230aSGarrett D'Amore * 452bdb9230aSGarrett D'Amore * Arguments 453bdb9230aSGarrett D'Amore * 454bdb9230aSGarrett D'Amore * mii MII handle. 455bdb9230aSGarrett D'Amore * name Property name. 456bdb9230aSGarrett D'Amore * id Property ID. 457bdb9230aSGarrett D'Amore * sz Size of property in bytes. 458bdb9230aSGarrett D'Amore * val Location of property value. 459bdb9230aSGarrett D'Amore * 460bdb9230aSGarrett D'Amore * Returns 461bdb9230aSGarrett D'Amore * 462bdb9230aSGarrett D'Amore * 0 on successful handling of property. 463bdb9230aSGarrett D'Amore * EINVAL if invalid arguments (e.g. a bad size) are supplied. 464bdb9230aSGarrett D'Amore * ENOTSUP if the prooperty is not supported by MII or the PHY, 465bdb9230aSGarrett D'Amore * or if the property is read-only. 466bdb9230aSGarrett D'Amore */ 467bdb9230aSGarrett D'Amore int mii_m_setprop(mii_handle_t mii, const char *name, mac_prop_id_t id, 468bdb9230aSGarrett D'Amore uint_t sz, const void *val); 469bdb9230aSGarrett D'Amore 470bdb9230aSGarrett D'Amore /* 471*0dc2366fSVenugopal Iyer * mii_m_propinfo 472*0dc2366fSVenugopal Iyer * 473*0dc2366fSVenugopal Iyer * Used to support the driver's mc_setprop() mac callback, 474*0dc2366fSVenugopal Iyer * and only to be called from that function (and without any 475*0dc2366fSVenugopal Iyer * locks held). 476*0dc2366fSVenugopal Iyer * 477*0dc2366fSVenugopal Iyer * Arguments 478*0dc2366fSVenugopal Iyer * 479*0dc2366fSVenugopal Iyer * mii MII handle. 480*0dc2366fSVenugopal Iyer * name Property name. 481*0dc2366fSVenugopal Iyer * id Property ID. 482*0dc2366fSVenugopal Iyer * prh Property info handle. 483*0dc2366fSVenugopal Iyer * 484*0dc2366fSVenugopal Iyer */ 485*0dc2366fSVenugopal Iyer void mii_m_propinfo(mii_handle_t mii, const char *name, mac_prop_id_t id, 486*0dc2366fSVenugopal Iyer mac_prop_info_handle_t prh); 487*0dc2366fSVenugopal Iyer 488*0dc2366fSVenugopal Iyer 489*0dc2366fSVenugopal Iyer /* 490bdb9230aSGarrett D'Amore * mii_m_getstat 491bdb9230aSGarrett D'Amore * 492bdb9230aSGarrett D'Amore * Used to support the driver's mc_getstat() mac callback for 493bdb9230aSGarrett D'Amore * statistic collection, and only to be called from that function 494bdb9230aSGarrett D'Amore * (without any locks held). This routine will process all of 495bdb9230aSGarrett D'Amore * the statistics that are relevant to MII on behalf of the 496bdb9230aSGarrett D'Amore * driver. 497bdb9230aSGarrett D'Amore * 498bdb9230aSGarrett D'Amore * Arguments 499bdb9230aSGarrett D'Amore * 500bdb9230aSGarrett D'Amore * mii MII handle. 501bdb9230aSGarrett D'Amore * stat Statistic number. 502bdb9230aSGarrett D'Amore * val Location to receive statistic value. 503bdb9230aSGarrett D'Amore * 504bdb9230aSGarrett D'Amore * Returns 505bdb9230aSGarrett D'Amore * 506bdb9230aSGarrett D'Amore * 0 on successful handling of statistic. 507bdb9230aSGarrett D'Amore * ENOTSUP if the statistic is not supported by MII. 508bdb9230aSGarrett D'Amore */ 509bdb9230aSGarrett D'Amore int mii_m_getstat(mii_handle_t mii, uint_t stat, uint64_t *val); 510bdb9230aSGarrett D'Amore 511bdb9230aSGarrett D'Amore #endif /* _KERNEL */ 512bdb9230aSGarrett D'Amore 513bdb9230aSGarrett D'Amore #ifdef __cplusplus 514bdb9230aSGarrett D'Amore } 515bdb9230aSGarrett D'Amore #endif 516bdb9230aSGarrett D'Amore 517bdb9230aSGarrett D'Amore #endif /* _SYS_MII_H */ 518