mpc512x_fec.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * (C) Copyright 2003 - 2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Derived from the MPC8xx driver's header file.
  6. */
  7. #ifndef __MPC512X_FEC_H
  8. #define __MPC512X_FEC_H
  9. #include <common.h>
  10. #include <mpc512x.h>
  11. typedef unsigned long uint32;
  12. typedef unsigned short uint16;
  13. typedef unsigned char uint8;
  14. typedef struct ethernet_register_set {
  15. /* [10:2]addr = 00 */
  16. /* Control and status Registers (offset 000-1FF) */
  17. volatile uint32 fec_id; /* MBAR_ETH + 0x000 */
  18. volatile uint32 ievent; /* MBAR_ETH + 0x004 */
  19. volatile uint32 imask; /* MBAR_ETH + 0x008 */
  20. volatile uint32 RES0[1]; /* MBAR_ETH + 0x00C */
  21. volatile uint32 r_des_active; /* MBAR_ETH + 0x010 */
  22. volatile uint32 x_des_active; /* MBAR_ETH + 0x014 */
  23. volatile uint32 RES1[3]; /* MBAR_ETH + 0x018-020 */
  24. volatile uint32 ecntrl; /* MBAR_ETH + 0x024 */
  25. volatile uint32 RES2[6]; /* MBAR_ETH + 0x028-03C */
  26. volatile uint32 mii_data; /* MBAR_ETH + 0x040 */
  27. volatile uint32 mii_speed; /* MBAR_ETH + 0x044 */
  28. volatile uint32 RES3[7]; /* MBAR_ETH + 0x048-060 */
  29. volatile uint32 mib_control; /* MBAR_ETH + 0x064 */
  30. volatile uint32 RES4[7]; /* MBAR_ETH + 0x068-80 */
  31. volatile uint32 r_cntrl; /* MBAR_ETH + 0x084 */
  32. volatile uint32 r_hash; /* MBAR_ETH + 0x088 */
  33. volatile uint32 RES5[14]; /* MBAR_ETH + 0x08c-0C0 */
  34. volatile uint32 x_cntrl; /* MBAR_ETH + 0x0C4 */
  35. volatile uint32 RES6[7]; /* MBAR_ETH + 0x0C8-0E0 */
  36. volatile uint32 paddr1; /* MBAR_ETH + 0x0E4 */
  37. volatile uint32 paddr2; /* MBAR_ETH + 0x0E8 */
  38. volatile uint32 op_pause; /* MBAR_ETH + 0x0EC */
  39. volatile uint32 RES7[10]; /* MBAR_ETH + 0x0F0-114 */
  40. volatile uint32 iaddr1; /* MBAR_ETH + 0x118 */
  41. volatile uint32 iaddr2; /* MBAR_ETH + 0x11C */
  42. volatile uint32 gaddr1; /* MBAR_ETH + 0x120 */
  43. volatile uint32 gaddr2; /* MBAR_ETH + 0x124 */
  44. volatile uint32 RES8[6]; /* MBAR_ETH + 0x128-13C */
  45. volatile uint32 fifo_id; /* MBAR_ETH + 0x140 */
  46. volatile uint32 x_wmrk; /* MBAR_ETH + 0x144 */
  47. volatile uint32 RES9[1]; /* MBAR_ETH + 0x148 */
  48. volatile uint32 r_bound; /* MBAR_ETH + 0x14C */
  49. volatile uint32 r_fstart; /* MBAR_ETH + 0x150 */
  50. volatile uint32 RES10[11]; /* MBAR_ETH + 0x154-17C */
  51. volatile uint32 r_des_start; /* MBAR_ETH + 0x180 */
  52. volatile uint32 x_des_start; /* MBAR_ETH + 0x184 */
  53. volatile uint32 r_buff_size; /* MBAR_ETH + 0x188 */
  54. volatile uint32 RES11[26]; /* MBAR_ETH + 0x18C-1F0 */
  55. volatile uint32 dma_control; /* MBAR_ETH + 0x1F4 */
  56. volatile uint32 RES12[2]; /* MBAR_ETH + 0x1F8-1FC */
  57. /* MIB COUNTERS (Offset 200-2FF) */
  58. volatile uint32 rmon_t_drop; /* MBAR_ETH + 0x200 */
  59. volatile uint32 rmon_t_packets; /* MBAR_ETH + 0x204 */
  60. volatile uint32 rmon_t_bc_pkt; /* MBAR_ETH + 0x208 */
  61. volatile uint32 rmon_t_mc_pkt; /* MBAR_ETH + 0x20C */
  62. volatile uint32 rmon_t_crc_align; /* MBAR_ETH + 0x210 */
  63. volatile uint32 rmon_t_undersize; /* MBAR_ETH + 0x214 */
  64. volatile uint32 rmon_t_oversize; /* MBAR_ETH + 0x218 */
  65. volatile uint32 rmon_t_frag; /* MBAR_ETH + 0x21C */
  66. volatile uint32 rmon_t_jab; /* MBAR_ETH + 0x220 */
  67. volatile uint32 rmon_t_col; /* MBAR_ETH + 0x224 */
  68. volatile uint32 rmon_t_p64; /* MBAR_ETH + 0x228 */
  69. volatile uint32 rmon_t_p65to127; /* MBAR_ETH + 0x22C */
  70. volatile uint32 rmon_t_p128to255; /* MBAR_ETH + 0x230 */
  71. volatile uint32 rmon_t_p256to511; /* MBAR_ETH + 0x234 */
  72. volatile uint32 rmon_t_p512to1023; /* MBAR_ETH + 0x238 */
  73. volatile uint32 rmon_t_p1024to2047; /* MBAR_ETH + 0x23C */
  74. volatile uint32 rmon_t_p_gte2048; /* MBAR_ETH + 0x240 */
  75. volatile uint32 rmon_t_octets; /* MBAR_ETH + 0x244 */
  76. volatile uint32 ieee_t_drop; /* MBAR_ETH + 0x248 */
  77. volatile uint32 ieee_t_frame_ok; /* MBAR_ETH + 0x24C */
  78. volatile uint32 ieee_t_1col; /* MBAR_ETH + 0x250 */
  79. volatile uint32 ieee_t_mcol; /* MBAR_ETH + 0x254 */
  80. volatile uint32 ieee_t_def; /* MBAR_ETH + 0x258 */
  81. volatile uint32 ieee_t_lcol; /* MBAR_ETH + 0x25C */
  82. volatile uint32 ieee_t_excol; /* MBAR_ETH + 0x260 */
  83. volatile uint32 ieee_t_macerr; /* MBAR_ETH + 0x264 */
  84. volatile uint32 ieee_t_cserr; /* MBAR_ETH + 0x268 */
  85. volatile uint32 ieee_t_sqe; /* MBAR_ETH + 0x26C */
  86. volatile uint32 t_fdxfc; /* MBAR_ETH + 0x270 */
  87. volatile uint32 ieee_t_octets_ok; /* MBAR_ETH + 0x274 */
  88. volatile uint32 RES13[2]; /* MBAR_ETH + 0x278-27C */
  89. volatile uint32 rmon_r_drop; /* MBAR_ETH + 0x280 */
  90. volatile uint32 rmon_r_packets; /* MBAR_ETH + 0x284 */
  91. volatile uint32 rmon_r_bc_pkt; /* MBAR_ETH + 0x288 */
  92. volatile uint32 rmon_r_mc_pkt; /* MBAR_ETH + 0x28C */
  93. volatile uint32 rmon_r_crc_align; /* MBAR_ETH + 0x290 */
  94. volatile uint32 rmon_r_undersize; /* MBAR_ETH + 0x294 */
  95. volatile uint32 rmon_r_oversize; /* MBAR_ETH + 0x298 */
  96. volatile uint32 rmon_r_frag; /* MBAR_ETH + 0x29C */
  97. volatile uint32 rmon_r_jab; /* MBAR_ETH + 0x2A0 */
  98. volatile uint32 rmon_r_resvd_0; /* MBAR_ETH + 0x2A4 */
  99. volatile uint32 rmon_r_p64; /* MBAR_ETH + 0x2A8 */
  100. volatile uint32 rmon_r_p65to127; /* MBAR_ETH + 0x2AC */
  101. volatile uint32 rmon_r_p128to255; /* MBAR_ETH + 0x2B0 */
  102. volatile uint32 rmon_r_p256to511; /* MBAR_ETH + 0x2B4 */
  103. volatile uint32 rmon_r_p512to1023; /* MBAR_ETH + 0x2B8 */
  104. volatile uint32 rmon_r_p1024to2047; /* MBAR_ETH + 0x2BC */
  105. volatile uint32 rmon_r_p_gte2048; /* MBAR_ETH + 0x2C0 */
  106. volatile uint32 rmon_r_octets; /* MBAR_ETH + 0x2C4 */
  107. volatile uint32 ieee_r_drop; /* MBAR_ETH + 0x2C8 */
  108. volatile uint32 ieee_r_frame_ok; /* MBAR_ETH + 0x2CC */
  109. volatile uint32 ieee_r_crc; /* MBAR_ETH + 0x2D0 */
  110. volatile uint32 ieee_r_align; /* MBAR_ETH + 0x2D4 */
  111. volatile uint32 r_macerr; /* MBAR_ETH + 0x2D8 */
  112. volatile uint32 r_fdxfc; /* MBAR_ETH + 0x2DC */
  113. volatile uint32 ieee_r_octets_ok; /* MBAR_ETH + 0x2E0 */
  114. volatile uint32 RES14[6]; /* MBAR_ETH + 0x2E4-2FC */
  115. volatile uint32 RES15[64]; /* MBAR_ETH + 0x300-3FF */
  116. } ethernet_regs;
  117. /* Receive & Transmit Buffer Descriptor definitions */
  118. typedef struct BufferDescriptor {
  119. uint16 status;
  120. uint16 dataLength;
  121. uint32 dataPointer;
  122. } FEC_RBD;
  123. typedef struct {
  124. uint16 status;
  125. uint16 dataLength;
  126. uint32 dataPointer;
  127. } FEC_TBD;
  128. /* private structure */
  129. typedef enum {
  130. SEVENWIRE, /* 7-wire */
  131. MII10, /* MII 10Mbps */
  132. MII100 /* MII 100Mbps */
  133. } xceiver_type;
  134. /* BD Numer definitions */
  135. #define FEC_TBD_NUM 48 /* The user can adjust this value */
  136. #define FEC_RBD_NUM 32 /* The user can adjust this value */
  137. /* packet size limit */
  138. #define FEC_MAX_FRAME_LEN 1522 /* recommended default value */
  139. /* Buffer size must be evenly divisible by 16 */
  140. #define FEC_BUFFER_SIZE ((FEC_MAX_FRAME_LEN + 0x10) & (~0xf))
  141. typedef struct {
  142. uint8 frame[FEC_BUFFER_SIZE];
  143. } mpc512x_frame;
  144. typedef struct {
  145. FEC_RBD rbd[FEC_RBD_NUM]; /* RBD ring */
  146. FEC_TBD tbd[FEC_TBD_NUM]; /* TBD ring */
  147. mpc512x_frame recv_frames[FEC_RBD_NUM]; /* receive buff */
  148. } mpc512x_buff_descs;
  149. typedef struct {
  150. ethernet_regs *eth;
  151. xceiver_type xcv_type; /* transceiver type */
  152. mpc512x_buff_descs *bdBase; /* BD rings and recv buffer */
  153. uint16 rbdIndex; /* next receive BD to read */
  154. uint16 tbdIndex; /* next transmit BD to send */
  155. uint16 usedTbdIndex; /* next transmit BD to clean */
  156. uint16 cleanTbdNum; /* the number of available transmit BDs */
  157. } mpc512x_fec_priv;
  158. /* RBD bits definitions */
  159. #define FEC_RBD_EMPTY 0x8000 /* Buffer is empty */
  160. #define FEC_RBD_WRAP 0x2000 /* Last BD in ring */
  161. #define FEC_RBD_LAST 0x0800 /* Buffer is last in frame(useless) */
  162. #define FEC_RBD_MISS 0x0100 /* Miss bit for prom mode */
  163. #define FEC_RBD_BC 0x0080 /* The received frame is broadcast frame */
  164. #define FEC_RBD_MC 0x0040 /* The received frame is multicast frame */
  165. #define FEC_RBD_LG 0x0020 /* Frame length violation */
  166. #define FEC_RBD_NO 0x0010 /* Nonoctet align frame */
  167. #define FEC_RBD_SH 0x0008 /* Short frame */
  168. #define FEC_RBD_CR 0x0004 /* CRC error */
  169. #define FEC_RBD_OV 0x0002 /* Receive FIFO overrun */
  170. #define FEC_RBD_TR 0x0001 /* Frame is truncated */
  171. #define FEC_RBD_ERR (FEC_RBD_LG | FEC_RBD_NO | FEC_RBD_CR | \
  172. FEC_RBD_OV | FEC_RBD_TR)
  173. /* TBD bits definitions */
  174. #define FEC_TBD_READY 0x8000 /* Buffer is ready */
  175. #define FEC_TBD_WRAP 0x2000 /* Last BD in ring */
  176. #define FEC_TBD_LAST 0x0800 /* Buffer is last in frame */
  177. #define FEC_TBD_TC 0x0400 /* Transmit the CRC */
  178. #define FEC_TBD_ABC 0x0200 /* Append bad CRC */
  179. /* MII-related definitios */
  180. #define FEC_MII_DATA_ST 0x40000000 /* Start of frame delimiter */
  181. #define FEC_MII_DATA_OP_RD 0x20000000 /* Perform a read operation */
  182. #define FEC_MII_DATA_OP_WR 0x10000000 /* Perform a write operation */
  183. #define FEC_MII_DATA_PA_MSK 0x0f800000 /* PHY Address field mask */
  184. #define FEC_MII_DATA_RA_MSK 0x007c0000 /* PHY Register field mask */
  185. #define FEC_MII_DATA_TA 0x00020000 /* Turnaround */
  186. #define FEC_MII_DATA_DATAMSK 0x0000ffff /* PHY data field */
  187. #define FEC_MII_DATA_RA_SHIFT 18 /* MII Register address bits */
  188. #define FEC_MII_DATA_PA_SHIFT 23 /* MII PHY address bits */
  189. #endif /* __MPC512X_FEC_H */