miiLib.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:15k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* miiLib.h - Media Independent Interface library header */
  2. /* Copyright 1990-2002 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01i,13may02,rcs added pPhyOptRegsRtn field to PHY_INFO. SPR# 76711
  7. 01h,14jun01,rcs moved new registers used by GMII to new struc MII_G_REGS 
  8.                 and placed it at end of PHY_INFO. (SPR# 68502) 
  9. 01g,23feb01,jln add basic GMII support for 1000-T auto-negotiation (SPR# 68502)
  10. 01f,23nov99,cn  added miiLibInit () to make miiLib a component (SPR #29542).
  11. 01e,08nov99,cn  added fields phyLinkDownRtn, pMiiPhyNode, miiPhyPresent
  12. to PHY_INFO structure. New flags MII_ALL_BUS_SCAN,
  13. MII_PHY_MONITOR, and macro MII_MONITOR_DELAY. Also 
  14. added miiPhyUnInit (), miiLibUnInit ().
  15. 01d,27sep99,cn  added definition of MII_CR_DEF_0_MASK.
  16. 01c,13sep99,cn  added definition of MII_MAX_REG_NUM, moved global APIs
  17. from miiLib.c (SPR# 28305).
  18. 01b,15jun99,cn changes after the code review.
  19. 01a,16mar99,cn written from motFccEnd.h, 01b.
  20. */
  21. /*
  22. DESCRIPTION
  23.  
  24. This module implements a Media Independent Interface (MII) library.
  25. INCLUDE FILES:
  26. */
  27. #ifndef __INCmiiLibh
  28. #define __INCmiiLibh
  29. /* includes */
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. #define S_miiLib_PHY_LINK_DOWN (M_miiLib | 1)
  34. #define S_miiLib_PHY_NULL         (M_miiLib | 2)
  35. #define S_miiLib_PHY_NO_ABLE              (M_miiLib | 3)
  36. #define S_miiLib_PHY_AN_FAIL              (M_miiLib | 4)
  37. /* defines */
  38. #define MII_SYS_DELAY(delay)
  39. if (pPhyInfo->phyDelayRtn != NULL)
  40.     ((* (pPhyInfo->phyDelayRtn)) (delay))
  41. #define MII_READ(addr, reg, val1, val2)
  42.     val2 = ((* (pPhyInfo->phyReadRtn)) ((pPhyInfo->pDrvCtrl), 
  43. (addr), (reg), (val1)));
  44. #define MII_WRITE(addr, reg, val1, val2)
  45.     val2 = ((* (pPhyInfo->phyWriteRtn)) ((pPhyInfo->pDrvCtrl), 
  46. (addr), (reg), (val1)));
  47. /* library flags */
  48.  
  49. #define MII_PHY_FLAGS_SET(setBits)                                      
  50.     (pPhyInfo->phyFlags |= (setBits))
  51.  
  52. #define MII_PHY_FLAGS_ARE_SET(setBits)                                  
  53.     (pPhyInfo->phyFlags & (setBits))
  54.  
  55. #define MII_PHY_FLAGS_GET(setBits)                                      
  56.     (pPhyInfo->phyFlags)
  57.  
  58. #define MII_PHY_FLAGS_CLEAR(clearBits)                                  
  59.     (pPhyInfo->phyFlags &= ~(clearBits))
  60.  
  61. /* MII definitions */
  62. #define MII_CRC_LEN 0x4 /* CRC length in bytes */
  63. #define MII_ETH_MAX_PCK_SZ      (ETHERMTU + SIZEOF_ETHERHEADER          
  64.  + MII_CRC_LEN)
  65. #define MII_MAX_PHY_NUM 0x20 /* max number of attached PHYs */
  66. #define MII_MAX_REG_NUM         0x20    /* max number of registers */
  67. #define MII_CTRL_REG 0x0 /* Control Register */
  68. #define MII_STAT_REG 0x1 /* Status Register */
  69. #define MII_PHY_ID1_REG 0x2 /* PHY identifier 1 Register */
  70. #define MII_PHY_ID2_REG 0x3 /* PHY identifier 2 Register */
  71. #define MII_AN_ADS_REG 0x4 /* Auto-Negotiation    */
  72. /* Advertisement Register */
  73. #define MII_AN_PRTN_REG 0x5 /* Auto-Negotiation      */
  74. /* partner ability Register */
  75. #define MII_AN_EXP_REG 0x6 /* Auto-Negotiation   */
  76. /* Expansion Register */
  77. #define MII_AN_NEXT_REG 0x7 /* Auto-Negotiation         */
  78. /* next-page transmit Register */
  79. #define MII_AN_PRTN_NEXT_REG 0x8  /* Link partner received next page */ 
  80. #define MII_MASSLA_CTRL_REG 0x9  /* MATER-SLAVE control register */
  81. #define MII_MASSLA_STAT_REG 0xa  /* MATER-SLAVE status register */
  82. #define MII_EXT_STAT_REG 0xf  /* Extented status register */
  83. /* MII control register bit  */
  84. #define MII_CR_COLL_TEST 0x0080 /* collision test */
  85. #define MII_CR_FDX 0x0100 /* FDX =1, half duplex =0 */
  86. #define MII_CR_RESTART 0x0200 /* restart auto negotiation */
  87. #define MII_CR_ISOLATE 0x0400 /* isolate PHY from MII */
  88. #define MII_CR_POWER_DOWN 0x0800 /* power down */
  89. #define MII_CR_AUTO_EN 0x1000 /* auto-negotiation enable */
  90. #define MII_CR_100 0x2000 /* 0 = 10mb, 1 = 100mb */
  91. #define MII_CR_LOOPBACK 0x4000 /* 0 = normal, 1 = loopback */
  92. #define MII_CR_RESET 0x8000 /* 0 = normal, 1 = PHY reset */
  93. #define MII_CR_NORM_EN 0x0000 /* just enable the PHY */
  94. #define MII_CR_DEF_0_MASK       0xca7f          /* they must return zero */
  95. #define MII_CR_RES_MASK        0x003f          /* reserved bits,return zero */
  96. /* MII Status register bit definitions */
  97. #define MII_SR_LINK_STATUS 0x0004        /* link Status -- 1 = link */
  98. #define MII_SR_AUTO_SEL 0x0008        /* auto speed select capable */
  99. #define MII_SR_REMOTE_FAULT     0x0010       /* Remote fault detect */
  100. #define MII_SR_AUTO_NEG         0x0020       /* auto negotiation complete */
  101. #define MII_SR_10T_HALF_DPX     0x0800      /* 10BaseT HD capable */
  102. #define MII_SR_10T_FULL_DPX     0x1000     /* 10BaseT FD capable */
  103. #define MII_SR_TX_HALF_DPX      0x2000     /* TX HD capable */
  104. #define MII_SR_TX_FULL_DPX      0x4000      /* TX FD capable */
  105. #define MII_SR_T4               0x8000     /* T4 capable */
  106. #define MII_SR_ABIL_MASK        0xff80     /* abilities mask */
  107. #define MII_SR_EXT_CAP          0x0001     /* extended capabilities */
  108. /*  MII ID2 register bit mask */
  109. #define MII_ID2_REVISON_MASK    0x000f
  110. #define MII_ID2_MODE_MASK       0x03f0
  111. /* MII AN advertisement Register bit definition */
  112. #define MII_ANAR_10TX_HD        0x0020
  113. #define MII_ANAR_10TX_FD        0x0040
  114. #define MII_ANAR_100TX_HD       0x0080
  115. #define MII_ANAR_100TX_FD       0x0100
  116. #define MII_ANAR_100T_4         0x0200
  117. #define MII_ANAR_PAUSE          0x0400
  118. #define MII_ANAR_ASM_PAUSE      0x0800
  119. #define MII_ANAR_REMORT_FAULT   0x2000
  120. #define MII_ANAR_NEXT_PAGE      0x8000
  121. #define MII_ANAR_PAUSE_MASK     0x0c00
  122. /* MII Link Code word  bit definitions */
  123. #define MII_BP_FAULT 0x2000        /* remote fault */
  124. #define MII_BP_ACK 0x4000        /* acknowledge */
  125. #define MII_BP_NP 0x8000        /* nexp page is supported */
  126. /* MII Next Page bit definitions */
  127. #define MII_NP_TOGGLE 0x0800        /* toggle bit */
  128. #define MII_NP_ACK2 0x1000        /* acknowledge two */
  129. #define MII_NP_MSG 0x2000        /* message page */
  130. #define MII_NP_ACK1 0x4000        /* acknowledge one */
  131. #define MII_NP_NP 0x8000        /* nexp page will follow */
  132. /* MII Expansion Register bit definitions */
  133. #define MII_EXP_FAULT 0x0010        /* parallel detection fault */
  134. #define MII_EXP_PRTN_NP 0x0008        /* link partner next-page able */
  135. #define MII_EXP_LOC_NP 0x0004        /* local PHY next-page able */
  136. #define MII_EXP_PR 0x0002        /* full page received */
  137. #define MII_EXP_PRT_AN 0x0001        /* link partner auto negotiation able */
  138. /* MII Master-Slave Control register bit definition */
  139. #define MII_MASSLA_CTRL_1000T_HD    0x100
  140. #define MII_MASSLA_CTRL_1000T_FD    0x200
  141. #define MII_MASSLA_CTRL_PORT_TYPE   0x400
  142. #define MII_MASSLA_CTRL_CONFIG_VAL  0x800
  143. #define MII_MASSLA_CTRL_CONFIG_EN   0x1000
  144. /* MII Master-Slave Status register bit definition */
  145. #define MII_MASSLA_STAT_LP1000T_HD  0x400
  146. #define MII_MASSLA_STAT_LP1000T_FD  0x800
  147. #define MII_MASSLA_STAT_REMOTE_RCV  0x1000
  148. #define MII_MASSLA_STAT_LOCAL_RCV   0x2000
  149. #define MII_MASSLA_STAT_CONF_RES    0x4000
  150. #define MII_MASSLA_STAT_CONF_FAULT  0x8000
  151. /* MII Extented Status register bit definition */
  152. #define MII_EXT_STAT_1000T_HD       0x1000
  153. #define MII_EXT_STAT_1000T_FD       0x2000
  154. #define MII_EXT_STAT_1000X_HD       0x4000
  155. #define MII_EXT_STAT_1000X_FD       0x8000
  156. /* technology ability field bit definitions */
  157. #define MII_TECH_10BASE_T 0x0020 /* 10Base-T */
  158. #define MII_TECH_10BASE_FD 0x0040 /* 10Base-T Full Duplex */
  159. #define MII_TECH_100BASE_TX 0x0080 /* 100Base-TX */
  160. #define MII_TECH_100BASE_TX_FD 0x0100 /* 100Base-TX Full Duplex */
  161. #define MII_TECH_100BASE_T4 0x0200 /* 100Base-T4 */
  162. #define MII_TECH_PAUSE 0x0400  /* PAUSE */
  163. #define MII_TECH_ASM_PAUSE 0x0800  /* Asym pause */
  164. #define MII_TECH_PAUSE_MASK 0x0c00 
  165. #define MII_ADS_TECH_MASK 0x1fe0 /* technology abilities mask */
  166. #define MII_TECH_MASK MII_ADS_TECH_MASK
  167. #define MII_ADS_SEL_MASK 0x001f /* selector field mask */
  168. #define MII_AN_FAIL             0x10    /* auto-negotiation fail */
  169. #define MII_STAT_FAIL           0x20    /* errors in the status register */
  170. #define MII_PHY_NO_ABLE      0x40    /* the PHY lacks some abilities */
  171. /* MII management frame structure */
  172. #define MII_MF_PREAMBLE 0xffffffff /* preamble pattern */
  173. #define MII_MF_ST 0x1 /* start of frame pattern */
  174. #define MII_MF_OP_RD 0x2 /* read operation pattern */
  175. #define MII_MF_OP_WR 0x1 /* write operation pattern */
  176. #define MII_MF_PREAMBLE_LEN 0x20 /* preamble lenght in bit */
  177. #define MII_MF_ST_LEN 0x2 /* start frame lenght in bit */
  178. #define MII_MF_OP_LEN 0x2 /* op code lenght in bit */
  179. #define MII_MF_ADDR_LEN 0x5 /* PHY addr lenght in bit */
  180. #define MII_MF_REG_LEN 0x5 /* PHY reg lenght in bit */
  181. #define MII_MF_TA_LEN 0x2 /* turnaround lenght in bit */
  182. #define MII_MF_DATA_LEN 0x10 /* data lenght in bit */
  183. /* defines related to the PHY device */
  184.  
  185. #define MII_PHY_PRE_INIT     0x0001          /* PHY info pre-initialized */
  186. #define MII_PHY_AUTO         0x0010          /* auto-negotiation allowed */
  187. #define MII_PHY_TBL          0x0020          /* use negotiation table */
  188. #define MII_PHY_100          0x0040          /* PHY may use 100Mbit speed */
  189. #define MII_PHY_10           0x0080          /* PHY may use 10Mbit speed */
  190. #define MII_PHY_FD           0x0100          /* PHY may use full duplex */
  191. #define MII_PHY_HD           0x0200          /* PHY may use half duplex */
  192. #define MII_PHY_ISO 0x0400          /* isolate all PHYs */
  193. #define MII_PHY_PWR_DOWN     0x0800          /* power down mode */
  194. #define MII_PHY_DEF_SET 0x1000 /* set a default mode */
  195. #define MII_ALL_BUS_SCAN 0x2000 /* scan the all bus */
  196. #define MII_PHY_MONITOR 0x4000 /* monitor the PHY's status */
  197. #define MII_PHY_INIT 0x8000 /* PHY info initialized */
  198. #define MII_PHY_1000T_FD 0x10000 /* PHY may use 1000-T full duplex */
  199. #define MII_PHY_1000T_HD 0x20000 /* PHY mau use 1000-T half duplex */
  200. #define MII_PHY_TX_FLOW_CTRL 0x40000 /* Transmit flow control */
  201. #define MII_PHY_RX_FLOW_CTRL 0x80000 /* Receive flow control */
  202. #define MII_PHY_GMII_TYPE 0x100000    /* GMII = 1, MII = 0 */
  203. /* miscellaneous defines */
  204. #define MII_PHY_DEF_DELAY   300             /* max delay before link up, etc. */
  205. #define MII_PHY_NO_DELAY    0x0     /* do not delay */
  206. #define MII_PHY_NULL        0xff            /* PHY is not present */
  207. #define MII_PHY_DEF_ADDR    0x0             /* default PHY's logical address */
  208. #ifndef MII_MONITOR_DELAY
  209. #   define MII_MONITOR_DELAY   0x5 /* in seconds */
  210. #endif
  211. #define MII_PHY_LINK_UNKNOWN 0x0       /* link method - Unknown */
  212. #define MII_PHY_LINK_AUTO 0x1       /* link method - Auto-Negotiation */
  213. #define MII_PHY_LINK_FORCE 0x2       /* link method - Force link */
  214. /*
  215.  * these values may be used in the default phy mode field of the load
  216.  * string, since that is used to force the operating mode of the PHY
  217.  * in case any attempt to establish the link failed.
  218.  */
  219.  
  220. #define PHY_10BASE_T            0x00     /* 10 Base-T */
  221. #define PHY_10BASE_T_FDX        0x01     /* 10 Base Tx, full duplex */
  222. #define PHY_100BASE_TX          0x02     /* 100 Base Tx */
  223. #define PHY_100BASE_TX_FDX      0x03     /* 100 Base TX, full duplex */
  224. #define PHY_100BASE_T4          0x04     /* 100 Base T4 */
  225. #define PHY_AN_ENABLE           0x05     /* re-enable auto-negotiation */
  226.  
  227. #define MII_FDX_STR         "full duplex"   /* full duplex mode */
  228. #define MII_FDX_LEN         sizeof (MII_FDX_STR)   /* full duplex mode */
  229. #define MII_HDX_STR         "half duplex"   /* half duplex mode */
  230. #define MII_HDX_LEN         sizeof (MII_HDX_STR)   /* full duplex mode */
  231. #define MII_AN_TBL_MAX 20 /* max number of entries in the table */
  232. /* allowed PHY's speeds */
  233. #define MII_1000MBS         1000000000      /* bits per sec */ 
  234. #define MII_100MBS          100000000       /* bits per sec */
  235. #define MII_10MBS           10000000        /* bits per sec */
  236. /* typedefs */
  237. typedef INT16 MII_AN_ORDER_TBL [MII_AN_TBL_MAX];
  238. typedef BOOL MII_PHY_BUS [MII_MAX_PHY_NUM];
  239. typedef struct mii_phy_node
  240.     {
  241.     NODE               node;
  242.     struct phy_info * pPhyInfo;
  243.     } MII_PHY_NODE;
  244. /* 
  245.  * the structure below only represents the status of the PHY's registers
  246.  * when they were last read through the MII interface
  247.  */
  248. typedef struct mii_regs
  249.     {
  250.     UINT16 phyStatus; /* PHY's status register */
  251.     UINT16 phyCtrl; /* PHY's control register */
  252.     UINT16 phyId1; /* PHY's identifier field 1 */
  253.     UINT16 phyId2; /* PHY's identifier field 2 */
  254.     UINT16 phyAds; /* PHY's advertisement register */
  255.     UINT16 phyPrtn; /* PHY's partner register */
  256.     UINT16 phyExp; /* PHY's expansion register */
  257.     UINT16 phyNext; /* PHY's next page transmit register */
  258.     } MII_REGS;
  259. typedef struct mii_g_regs
  260.     {
  261.     UINT16              phyRcvNext;     /* PHY'S partner received next page */
  262.     UINT16              phyMSCtrl;      /* PHY'S MASTER-SLAVE Control register */
  263.     UINT16              phyMSStatus;    /* PHY'S MASTER-SLAVE Status register */
  264.     UINT16              phyExtStatus;   /* PHY'S extented Status register */
  265.     } MII_G_REGS;
  266. /* 
  267.  * the structure below is to be allocated and filled in by the 
  268.  * driver before it attempts to use the miiPhyInit () routine. Some
  269.  * of its field may be overwritten by miiPhyInit (), since their initial
  270.  * values may not be appropriate. In addition, some field do not have
  271.  * to be initialized by the calling task, since miiPhyInit () may use a
  272.  * default value, whereas some other are mandatory. To help understand this,
  273.  * the comment for each field includes flags stating whether the relevent
  274.  * field in the PHY_INFO structure is an input (I) parameter to miiPhyInit (),
  275.  * an output (O) parameter, or an input-output (I/O) parameter first,
  276.  * and then whether it is optional (O) or mandatory (M). For output 
  277.  * parameters, the second flag is a "don't care" (X).
  278.  */
  279. typedef struct phy_info
  280.     {
  281.     MII_REGS         miiRegs; /* PHY registers - (O|X) */
  282.     UINT8 phyAddr; /* address of a PHY - (I/O)|(O) */
  283.     UINT32 phyFlags; /* some flags - (I/O)|(O) */
  284.     UINT32              phySpeed;    /* 10/100 Mbit/sec  - (O|X) */
  285.     char                phyMode[20];    /* half/full duplex mode  - (O|X) */
  286.     UINT32              phyDefMode;     /* default operating mode  - (I|O) */
  287.     MII_AN_ORDER_TBL * phyAnOrderTbl; /* auto-negotiation table - (I|O) */
  288.     FUNCPTR phyReadRtn; /* phy read routine - (I|M) */
  289.     FUNCPTR phyWriteRtn; /* phy write routine - (I|M) */
  290.     FUNCPTR phyDelayRtn; /* phy delay routine - (I|O) */
  291.     UINT32 phyDelayParm; /* parameter to delay routine - (I|O) */
  292.     UINT32 phyMaxDelay; /* phy max delay - (I|O) */
  293.     void *  pDrvCtrl; /* driver control structure - (I|M) */
  294.     FUNCPTR phyLinkDownRtn; /* phy status down routine - (I|O) */
  295.     MII_PHY_NODE * pMiiPhyNode; /* phy node - O */
  296.     MII_PHY_BUS * miiPhyPresent; /* which PHYs are there - O */
  297.     UINT32 phyLinkMethod; /* phy link method (Auto/Force) - (O|X) */
  298.     UINT32 phyAutoNegotiateFlags; /* flag for auto-negotiation - (O|X) */
  299.     MII_G_REGS miiGRegs;       /* Giga Bit PHY registers - (O|X) */
  300.     FUNCPTR pPhyOptRegsRtn; /* device specific pPhyOptRegsRtn */
  301.     } PHY_INFO;
  302. /* globals */
  303.  
  304. void   miiPhyOptFuncSet (FUNCPTR optRegsFunc);
  305. STATUS          miiPhyInit (PHY_INFO * pPhyInfo);
  306. STATUS          miiLibUnInit (void);
  307. STATUS          miiLibInit (void);
  308. STATUS          miiPhyUnInit (PHY_INFO * pPhyInfo);
  309. void            miiShow (PHY_INFO * pPhyInfo);
  310. STATUS          miiRegsGet (PHY_INFO * pPhyInfo, UINT regNum, UCHAR * buff);
  311. STATUS miiAnCheck (PHY_INFO * pPhyInfo, UINT8 phyAddr);
  312. #ifdef __cplusplus
  313. }
  314. #endif
  315. #endif /* __INCmiiLibh */