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