1*9860Sgdamore@opensolaris.org /* 2*9860Sgdamore@opensolaris.org * CDDL HEADER START 3*9860Sgdamore@opensolaris.org * 4*9860Sgdamore@opensolaris.org * The contents of this file are subject to the terms of the 5*9860Sgdamore@opensolaris.org * Common Development and Distribution License (the "License"). 6*9860Sgdamore@opensolaris.org * You may not use this file except in compliance with the License. 7*9860Sgdamore@opensolaris.org * 8*9860Sgdamore@opensolaris.org * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*9860Sgdamore@opensolaris.org * or http://www.opensolaris.org/os/licensing. 10*9860Sgdamore@opensolaris.org * See the License for the specific language governing permissions 11*9860Sgdamore@opensolaris.org * and limitations under the License. 12*9860Sgdamore@opensolaris.org * 13*9860Sgdamore@opensolaris.org * When distributing Covered Code, include this CDDL HEADER in each 14*9860Sgdamore@opensolaris.org * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*9860Sgdamore@opensolaris.org * If applicable, add the following below this CDDL HEADER, with the 16*9860Sgdamore@opensolaris.org * fields enclosed by brackets "[]" replaced with your own identifying 17*9860Sgdamore@opensolaris.org * information: Portions Copyright [yyyy] [name of copyright owner] 18*9860Sgdamore@opensolaris.org * 19*9860Sgdamore@opensolaris.org * CDDL HEADER END 20*9860Sgdamore@opensolaris.org */ 21*9860Sgdamore@opensolaris.org /* 22*9860Sgdamore@opensolaris.org * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23*9860Sgdamore@opensolaris.org * Use is subject to license terms. 24*9860Sgdamore@opensolaris.org */ 25*9860Sgdamore@opensolaris.org 26*9860Sgdamore@opensolaris.org /* 27*9860Sgdamore@opensolaris.org * mii.h 28*9860Sgdamore@opensolaris.org * Generic MII/PHY Support for MAC drivers. 29*9860Sgdamore@opensolaris.org * 30*9860Sgdamore@opensolaris.org * Copyrighted as an unpublished work. (c) Copyright 1997 Sun Microsystems, Inc. 31*9860Sgdamore@opensolaris.org * All rights reserved. 32*9860Sgdamore@opensolaris.org */ 33*9860Sgdamore@opensolaris.org 34*9860Sgdamore@opensolaris.org #ifndef _DNET_MII_H 35*9860Sgdamore@opensolaris.org #define _DNET_MII_H 36*9860Sgdamore@opensolaris.org 37*9860Sgdamore@opensolaris.org /* 38*9860Sgdamore@opensolaris.org * NOTES 39*9860Sgdamore@opensolaris.org * All calls to MII functions are assumed to be serialized by the user. 40*9860Sgdamore@opensolaris.org * In the case of the port monitor, which causes asynchronous callbacks, 41*9860Sgdamore@opensolaris.org * you must pass the address of a mutex. MII aquires this before calling 42*9860Sgdamore@opensolaris.org * the user callback, and releases it after the callback returns. 43*9860Sgdamore@opensolaris.org * 44*9860Sgdamore@opensolaris.org * All calls requiring a PHY address must be done AFTER calling 45*9860Sgdamore@opensolaris.org * mii_init_phy() for that PHY, with the exception of mii_phyexists() 46*9860Sgdamore@opensolaris.org * 47*9860Sgdamore@opensolaris.org * mii_rsan() will not accept mii_wait_interrupt as a wait type. Its futile to 48*9860Sgdamore@opensolaris.org * expect autonegotiation to happen fast enough. (You're better off using the 49*9860Sgdamore@opensolaris.org * port monitor to tell you, asynchronously that the link has been 50*9860Sgdamore@opensolaris.org * re-established than waiting at all.) 51*9860Sgdamore@opensolaris.org */ 52*9860Sgdamore@opensolaris.org 53*9860Sgdamore@opensolaris.org /* 54*9860Sgdamore@opensolaris.org * MII programming Interface types 55*9860Sgdamore@opensolaris.org */ 56*9860Sgdamore@opensolaris.org 57*9860Sgdamore@opensolaris.org enum mii_phy_state {phy_state_unknown, phy_state_linkup, phy_state_linkdown}; 58*9860Sgdamore@opensolaris.org enum mii_wait_type {mii_wait_none, mii_wait_user, mii_wait_interrupt}; 59*9860Sgdamore@opensolaris.org typedef ushort_t (*mii_readfunc_t)(dev_info_t *, int phy, int reg); 60*9860Sgdamore@opensolaris.org typedef void (*mii_writefunc_t)(dev_info_t *, int phy, int reg, int value); 61*9860Sgdamore@opensolaris.org typedef void (*mii_linkfunc_t)(dev_info_t *, int phy, enum mii_phy_state state); 62*9860Sgdamore@opensolaris.org 63*9860Sgdamore@opensolaris.org struct mii_info; /* Private to MII! */ 64*9860Sgdamore@opensolaris.org typedef struct mii_info *mii_handle_t; 65*9860Sgdamore@opensolaris.org 66*9860Sgdamore@opensolaris.org /* 67*9860Sgdamore@opensolaris.org * Entrypoints 68*9860Sgdamore@opensolaris.org */ 69*9860Sgdamore@opensolaris.org 70*9860Sgdamore@opensolaris.org int mii_create(dev_info_t *, mii_writefunc_t, mii_readfunc_t, mii_handle_t *); 71*9860Sgdamore@opensolaris.org /* Initialise the PHY interface */ 72*9860Sgdamore@opensolaris.org 73*9860Sgdamore@opensolaris.org int mii_init_phy(mii_handle_t, int phy); 74*9860Sgdamore@opensolaris.org /* Initialise a PHY */ 75*9860Sgdamore@opensolaris.org 76*9860Sgdamore@opensolaris.org int mii_getspeed(mii_handle_t, int phy, int *speed, int *full_duplex); 77*9860Sgdamore@opensolaris.org /* Check operating speed of PHY */ 78*9860Sgdamore@opensolaris.org 79*9860Sgdamore@opensolaris.org int mii_probe_phy(mii_handle_t, int phy); 80*9860Sgdamore@opensolaris.org /* Check if PHY exists at an address */ 81*9860Sgdamore@opensolaris.org 82*9860Sgdamore@opensolaris.org int mii_rsan(mii_handle_t mac, int phy, enum mii_wait_type wait_type); 83*9860Sgdamore@opensolaris.org /* Restart autonegotiation */ 84*9860Sgdamore@opensolaris.org 85*9860Sgdamore@opensolaris.org int mii_fixspeed(mii_handle_t, int phy, int speed, int fullduplex); 86*9860Sgdamore@opensolaris.org /* Fix speed and duplex mode of PHY (disable autoneg) */ 87*9860Sgdamore@opensolaris.org 88*9860Sgdamore@opensolaris.org int mii_autoneg_enab(mii_handle_t mac, int phy); 89*9860Sgdamore@opensolaris.org /* (re-)enable autonegotiation */ 90*9860Sgdamore@opensolaris.org 91*9860Sgdamore@opensolaris.org int mii_reset_phy(mii_handle_t, int phy, enum mii_wait_type wait_type); 92*9860Sgdamore@opensolaris.org /* Force PHY to reset itself */ 93*9860Sgdamore@opensolaris.org 94*9860Sgdamore@opensolaris.org int mii_disable_fullduplex(mii_handle_t, int phy); 95*9860Sgdamore@opensolaris.org /* Stop the PHY advertising full duplex capability */ 96*9860Sgdamore@opensolaris.org 97*9860Sgdamore@opensolaris.org int mii_linkup(mii_handle_t, int phy); 98*9860Sgdamore@opensolaris.org /* Check link status on a phy */ 99*9860Sgdamore@opensolaris.org 100*9860Sgdamore@opensolaris.org int mii_sync(mii_handle_t, int phy); 101*9860Sgdamore@opensolaris.org /* Sync API if something may have affected the PHY */ 102*9860Sgdamore@opensolaris.org 103*9860Sgdamore@opensolaris.org int mii_isolate(mii_handle_t, int phy); 104*9860Sgdamore@opensolaris.org /* Electrically isolate a PHY */ 105*9860Sgdamore@opensolaris.org 106*9860Sgdamore@opensolaris.org int mii_unisolate(mii_handle_t, int phy); 107*9860Sgdamore@opensolaris.org /* Unisolate */ 108*9860Sgdamore@opensolaris.org 109*9860Sgdamore@opensolaris.org int mii_dump_phy(mii_handle_t, int phy); 110*9860Sgdamore@opensolaris.org /* Dump register contents */ 111*9860Sgdamore@opensolaris.org 112*9860Sgdamore@opensolaris.org int mii_start_portmon(mii_handle_t mac, mii_linkfunc_t func, kmutex_t *lock); 113*9860Sgdamore@opensolaris.org /* Monitor initialised PHYs for link state changes */ 114*9860Sgdamore@opensolaris.org 115*9860Sgdamore@opensolaris.org int mii_stop_portmon(mii_handle_t mac); 116*9860Sgdamore@opensolaris.org /* Stop port monitor */ 117*9860Sgdamore@opensolaris.org 118*9860Sgdamore@opensolaris.org void mii_destroy(mii_handle_t mac); 119*9860Sgdamore@opensolaris.org /* Cleanup MII interface */ 120*9860Sgdamore@opensolaris.org 121*9860Sgdamore@opensolaris.org /* 122*9860Sgdamore@opensolaris.org * Errorcodes 123*9860Sgdamore@opensolaris.org */ 124*9860Sgdamore@opensolaris.org #define MII_SUCCESS 0 125*9860Sgdamore@opensolaris.org #define MII_PHYPRESENT 1 /* PHY already exists at specified address */ 126*9860Sgdamore@opensolaris.org #define MII_NOMEM 2 /* Not enough memory */ 127*9860Sgdamore@opensolaris.org #define MII_PARAM 3 /* parameters passed are incorrect */ 128*9860Sgdamore@opensolaris.org #define MII_NOTSUPPORTED 4 /* operation not supported by hardware. */ 129*9860Sgdamore@opensolaris.org #define MII_STATE 5 /* The request is not valid at this time. */ 130*9860Sgdamore@opensolaris.org #define MII_HARDFAIL 6 /* The hardware is not functioning correctly */ 131*9860Sgdamore@opensolaris.org #define MII_TIMEOUT 7 /* Timeout waiting for operation to complete */ 132*9860Sgdamore@opensolaris.org #define MII_PHYNOTPRESENT 8 /* There is no PHY at the specified address */ 133*9860Sgdamore@opensolaris.org 134*9860Sgdamore@opensolaris.org /* Vendor Specific functions */ 135*9860Sgdamore@opensolaris.org typedef void (*phy_genfunc)(mii_handle_t, int phy); 136*9860Sgdamore@opensolaris.org typedef int (*phy_getspeedfunc)(mii_handle_t, int phy, int *speed, int *fd); 137*9860Sgdamore@opensolaris.org 138*9860Sgdamore@opensolaris.org /* per-PHY information. */ 139*9860Sgdamore@opensolaris.org struct phydata 140*9860Sgdamore@opensolaris.org { 141*9860Sgdamore@opensolaris.org ulong_t id; /* ID from MII registers 2,3 */ 142*9860Sgdamore@opensolaris.org char *description; /* Text description from ID */ 143*9860Sgdamore@opensolaris.org phy_genfunc phy_dump; /* how to dump registers this make */ 144*9860Sgdamore@opensolaris.org phy_genfunc phy_postreset; /* What to do after a reset (or init) */ 145*9860Sgdamore@opensolaris.org phy_getspeedfunc phy_getspeed; /* how to find current speed */ 146*9860Sgdamore@opensolaris.org unsigned short control; /* Bits that need to be written ... */ 147*9860Sgdamore@opensolaris.org /* ...to control register */ 148*9860Sgdamore@opensolaris.org enum mii_phy_state state; /* Current state of link at this PHY */ 149*9860Sgdamore@opensolaris.org int fix_speed; /* Speed fixed in conf file */ 150*9860Sgdamore@opensolaris.org int fix_duplex; 151*9860Sgdamore@opensolaris.org /* 152*9860Sgdamore@opensolaris.org * ^^NEEDSWORK: We can only fix speed for the driver, never mind a 153*9860Sgdamore@opensolaris.org * particular PHY on a particular instance, but this is where this 154*9860Sgdamore@opensolaris.org * belongs. 155*9860Sgdamore@opensolaris.org */ 156*9860Sgdamore@opensolaris.org }; 157*9860Sgdamore@opensolaris.org 158*9860Sgdamore@opensolaris.org typedef struct mii_info 159*9860Sgdamore@opensolaris.org { 160*9860Sgdamore@opensolaris.org mii_readfunc_t mii_read; /* How to read an MII register */ 161*9860Sgdamore@opensolaris.org mii_writefunc_t mii_write; /* How to write an MII register */ 162*9860Sgdamore@opensolaris.org mii_linkfunc_t mii_linknotify; /* What to do when link state changes */ 163*9860Sgdamore@opensolaris.org dev_info_t *mii_dip; /* MAC's devinfo */ 164*9860Sgdamore@opensolaris.org timeout_id_t portmon_timer; /* ID of timer for the port monitor */ 165*9860Sgdamore@opensolaris.org kmutex_t *lock; /* Lock to serialise mii calls */ 166*9860Sgdamore@opensolaris.org struct phydata *phys[32]; /* PHY Information indexed by address */ 167*9860Sgdamore@opensolaris.org } mii_info_t; 168*9860Sgdamore@opensolaris.org 169*9860Sgdamore@opensolaris.org #define OUI_NATIONAL_SEMICONDUCTOR 0x80017 170*9860Sgdamore@opensolaris.org #define NS_DP83840 0x00 171*9860Sgdamore@opensolaris.org #define MII_83840_ADDR 25 172*9860Sgdamore@opensolaris.org #define NS83840_ADDR_SPEED10 (1<<6) 173*9860Sgdamore@opensolaris.org #define NS83840_ADDR_CONSTAT (1<<5) 174*9860Sgdamore@opensolaris.org #define NS83840_ADDR_ADDR (0x1f<<0) 175*9860Sgdamore@opensolaris.org 176*9860Sgdamore@opensolaris.org #define OUI_INTEL 0x0aa00 177*9860Sgdamore@opensolaris.org #define INTEL_82553_CSTEP 0x35 /* A and B steps are non-standard */ 178*9860Sgdamore@opensolaris.org #define MII_82553_EX0 16 179*9860Sgdamore@opensolaris.org #define I82553_EX0_FDUPLEX (1<<0) 180*9860Sgdamore@opensolaris.org #define I82553_EX0_100MB (1<<1) 181*9860Sgdamore@opensolaris.org #define I82553_EX0_WAKE (1<<2) 182*9860Sgdamore@opensolaris.org #define I82553_EX0_SQUELCH (3<<3) /* 3:4 */ 183*9860Sgdamore@opensolaris.org #define I82553_EX0_REVCNTR (7<<5) /* 5:7 */ 184*9860Sgdamore@opensolaris.org #define I82553_EX0_FRCFAIL (1<<8) 185*9860Sgdamore@opensolaris.org #define I82553_EX0_TEST (0x1f<<9) /* 13:9 */ 186*9860Sgdamore@opensolaris.org #define I82553_EX0_LINKDIS (1<<14) 187*9860Sgdamore@opensolaris.org #define I82553_EX0_JABDIS (1<<15) 188*9860Sgdamore@opensolaris.org 189*9860Sgdamore@opensolaris.org #define MII_82553_EX1 190*9860Sgdamore@opensolaris.org #define I82553_EX1_RESERVE (0x1ff<<0) /* 0:8 */ 191*9860Sgdamore@opensolaris.org #define I82553_EX1_CH2EOF (1<<9) 192*9860Sgdamore@opensolaris.org #define I82553_EX1_MNCHSTR (1<<10) 193*9860Sgdamore@opensolaris.org #define I82553_EX1_EOP (1<<11) 194*9860Sgdamore@opensolaris.org #define I82553_EX1_BADCODE (1<<12) 195*9860Sgdamore@opensolaris.org #define I82553_EX1_INVALCODE (1<<13) 196*9860Sgdamore@opensolaris.org #define I82553_EX1_DCBALANCE (1<<14) 197*9860Sgdamore@opensolaris.org #define I82553_EX1_PAIRSKEW (1<<15) 198*9860Sgdamore@opensolaris.org 199*9860Sgdamore@opensolaris.org #define INTEL_82555 0x15 200*9860Sgdamore@opensolaris.org #define INTEL_82562_EH 0x33 201*9860Sgdamore@opensolaris.org #define INTEL_82562_ET 0x32 202*9860Sgdamore@opensolaris.org #define INTEL_82562_EM 0x31 203*9860Sgdamore@opensolaris.org 204*9860Sgdamore@opensolaris.org #define OUI_ICS 0x57d 205*9860Sgdamore@opensolaris.org #define ICS_1890 2 206*9860Sgdamore@opensolaris.org #define ICS_1889 1 207*9860Sgdamore@opensolaris.org #define ICS_EXCTRL 16 208*9860Sgdamore@opensolaris.org #define ICS_EXCTRL_CMDOVRD (1<<15) 209*9860Sgdamore@opensolaris.org #define ICS_EXCTRL_PHYADDR (0x1f<<6) 210*9860Sgdamore@opensolaris.org #define ICS_EXCTRL_SCSTEST (1<<5) 211*9860Sgdamore@opensolaris.org #define ICS_EXCTRL_INVECTEST (1<<2) 212*9860Sgdamore@opensolaris.org #define ICS_EXCTRL_SCDISABLE (1<<0) 213*9860Sgdamore@opensolaris.org 214*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL 17 215*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_100MB (1<<15) 216*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_FDUPLEX (1<<14) 217*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_ANPROG (7<<11) 218*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_RSE (1<<10) 219*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_PLLLOCK (1<<9) 220*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_FALSECD (1<<8) 221*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_SYMINVAL (1<<7) 222*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_SYMHALT (1<<6) 223*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_PREMEND (1<<5) 224*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_ANDONE (1<<4) 225*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_RESERVED (1<<3) 226*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_JABBER (1<<2) 227*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_REMFAULT (1<<1) 228*9860Sgdamore@opensolaris.org #define ICS_QUICKPOLL_LINKSTAT (1<<0) 229*9860Sgdamore@opensolaris.org 230*9860Sgdamore@opensolaris.org #define ICS_10BASET 18 231*9860Sgdamore@opensolaris.org #define ICS_10BASET_REMJABBER (1<<15) 232*9860Sgdamore@opensolaris.org #define ICS_10BASET_REVPOLARITY (1<<14) 233*9860Sgdamore@opensolaris.org #define ICS_10BASET_RESERVED (0xff<<6) 234*9860Sgdamore@opensolaris.org #define ICS_10BASET_NOJABBER (1<<5) 235*9860Sgdamore@opensolaris.org #define ICS_10BASET_NORMLOOP (1<<4) 236*9860Sgdamore@opensolaris.org #define ICS_10BASET_NOAUTOPOLL (1<<3) 237*9860Sgdamore@opensolaris.org #define ICS_10BASET_NOSQE (1<<2) 238*9860Sgdamore@opensolaris.org #define ICS_10BASET_NOLINKLOSS (1<<1) 239*9860Sgdamore@opensolaris.org #define ICS_10BASET_NOSQUELCH (1<<0) 240*9860Sgdamore@opensolaris.org 241*9860Sgdamore@opensolaris.org #define ICS_EXCTRL2 19 242*9860Sgdamore@opensolaris.org #define ICS_EXCTRL2_ISREPEATER (1<<15) 243*9860Sgdamore@opensolaris.org #define ICS_EXCTRL2_SOFTPRI (1<<14) 244*9860Sgdamore@opensolaris.org #define ICS_EXCTRL2_LPCANREMF (1<<13) 245*9860Sgdamore@opensolaris.org #define ICS_EXCTRL2_RMFSXMITED (1<<10) 246*9860Sgdamore@opensolaris.org #define ICS_EXCTRL2_ANPWRREMF (1<<4) 247*9860Sgdamore@opensolaris.org #define ICS_EXCTRL2_10BASETQUAL (1<<2) 248*9860Sgdamore@opensolaris.org #define ICS_EXCTRL2_AUTOPWRDN (1<<0) 249*9860Sgdamore@opensolaris.org 250*9860Sgdamore@opensolaris.org #endif /* _DNET_MII_H */ 251