atm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. typedef unsigned char uint8;
  2. typedef unsigned short uint16;
  3. typedef unsigned int uint32;
  4. typedef volatile unsigned char vuint8;
  5. typedef volatile unsigned short vuint16;
  6. typedef volatile unsigned int vuint32;
  7. #define DPRAM_ATM CONFIG_SYS_IMMR + 0x3000
  8. #define ATM_DPRAM_BEGIN (DPRAM_ATM - CONFIG_SYS_IMMR - 0x2000)
  9. #define NUM_CONNECTIONS 1
  10. #define SAR_RXB_SIZE 1584
  11. #define AM_HMASK 0x0FFFFFF0
  12. #define NUM_CT_ENTRIES (NUM_CONNECTIONS)
  13. #define NUM_TCTE_ENTRIES (NUM_CONNECTIONS)
  14. #define NUM_AM_ENTRIES (NUM_CONNECTIONS+1)
  15. #define NUM_AP_ENTRIES (NUM_CONNECTIONS+1)
  16. #define NUM_MPHYPT_ENTRIES 1
  17. #define NUM_APCP_ENTRIES 1
  18. #define NUM_APCT_PRIO_1_ENTRIES 146 /* Determines minimum rate */
  19. #define NUM_TQ_ENTRIES 12
  20. #define SIZE_OF_CT_ENTRY 64
  21. #define SIZE_OF_TCTE_ENTRY 32
  22. #define SIZE_OF_AM_ENTRY 4
  23. #define SIZE_OF_AP_ENTRY 2
  24. #define SIZE_OF_MPHYPT_ENTRY 2
  25. #define SIZE_OF_APCP_ENTRY 32
  26. #define SIZE_OF_APCT_ENTRY 2
  27. #define SIZE_OF_TQ_ENTRY 2
  28. #define CT_BASE ((ATM_DPRAM_BEGIN + 63) & 0xFFC0) /*64 */
  29. #define TCTE_BASE (CT_BASE + NUM_CT_ENTRIES * SIZE_OF_CT_ENTRY) /*32 */
  30. #define APCP_BASE (TCTE_BASE + NUM_TCTE_ENTRIES * SIZE_OF_TCTE_ENTRY) /*32 */
  31. #define AM_BEGIN (APCP_BASE + NUM_APCP_ENTRIES * SIZE_OF_APCP_ENTRY) /*4 */
  32. #define AM_BASE (AM_BEGIN + (NUM_AM_ENTRIES - 1) * SIZE_OF_AM_ENTRY)
  33. #define AP_BEGIN (AM_BEGIN + NUM_AM_ENTRIES * SIZE_OF_AM_ENTRY) /*2 */
  34. #define AP_BASE (AP_BEGIN + (NUM_AP_ENTRIES - 1) * SIZE_OF_AP_ENTRY)
  35. #define MPHYPT_BASE (AP_BEGIN + NUM_AP_ENTRIES * SIZE_OF_AP_ENTRY) /*2 */
  36. #define APCT_PRIO_1_BASE (MPHYPT_BASE + NUM_MPHYPT_ENTRIES * SIZE_OF_MPHYPT_ENTRY) /*2 */
  37. #define TQ_BASE (APCT_PRIO_1_BASE + NUM_APCT_PRIO_1_ENTRIES * SIZE_OF_APCT_ENTRY) /*2 */
  38. #define ATM_DPRAM_SIZE ((TQ_BASE + NUM_TQ_ENTRIES * SIZE_OF_TQ_ENTRY) - ATM_DPRAM_BEGIN)
  39. #define CT_PTR(base) ((struct ct_entry_t *)((char *)(base) + 0x2000 + CT_BASE))
  40. #define TCTE_PTR(base) ((struct tcte_entry_t *)((char *)(base) + 0x2000 + TCTE_BASE))
  41. #define AM_PTR(base) ((uint32 *)((char *)(base) + 0x2000 + AM_BASE))
  42. #define AP_PTR(base) ((uint16 *)((char *)(base) + 0x2000 + AP_BASE))
  43. #define MPHYPT_PTR(base) ((uint16 *)((char *)(base) + 0x2000 + MPHYPT_BASE))
  44. #define APCP_PTR(base) ((struct apc_params_t *)((char*)(base) + 0x2000 + APCP_BASE))
  45. #define APCT1_PTR(base) ((uint16 *)((char *)(base) + 0x2000 + APCT_PRIO_1_BASE))
  46. #define APCT2_PTR(base) ((uint16 *)((char *)(base) + 0x2000 + APCT_PRIO_2_BASE))
  47. #define APCT3_PTR(base) ((uint16 *)((char *)(base) + 0x2000 + APCT_PRIO_3_BASE))
  48. #define TQ_PTR(base) ((uint16 *)((char *)(base) + 0x2000 + TQ_BASE))
  49. /* SAR registers */
  50. #define RBDBASE(base) ((vuint32 *)(base + 0x3F00)) /* Base address of RxBD-List */
  51. #define SRFCR(base) ((vuint8 *)(base + 0x3F04)) /* DMA Receive function code */
  52. #define SRSTATE(base) ((vuint8 *)(base + 0x3F05)) /* DMA Receive status */
  53. #define MRBLR(base) ((vuint16 *)(base + 0x3F06)) /* Init to 0 for ATM */
  54. #define RSTATE(base) ((vuint32 *)(base + 0x3F08)) /* Do not write to */
  55. #define R_CNT(base) ((vuint16 *)(base + 0x3F10)) /* Do not write to */
  56. #define STFCR(base) ((vuint8 *)(base + 0x3F12)) /* DMA Transmit function code */
  57. #define STSTATE(base) ((vuint8 *)(base + 0x3F13)) /* DMA Transmit status */
  58. #define TBDBASE(base) ((vuint32 *)(base + 0x3F14)) /* Base address of TxBD-List */
  59. #define TSTATE(base) ((vuint32 *)(base + 0x3F18)) /* Do not write to */
  60. #define COMM_CH(base) ((vuint16 *)(base + 0x3F1C)) /* Command channel */
  61. #define STCHNUM(base) ((vuint16 *)(base + 0x3F1E)) /* Do not write to */
  62. #define T_CNT(base) ((vuint16 *)(base + 0x3F20)) /* Do not write to */
  63. #define CTBASE(base) ((vuint16 *)(base + 0x3F22)) /* Base address of Connection-table */
  64. #define ECTBASE(base) ((vuint32 *)(base + 0x3F24)) /* Valid only for external Conn.-table */
  65. #define INTBASE(base) ((vuint32 *)(base + 0x3F28)) /* Base address of Interrupt-table */
  66. #define INTPTR(base) ((vuint32 *)(base + 0x3F2C)) /* Pointer to Interrupt-queue */
  67. #define C_MASK(base) ((vuint32 *)(base + 0x3F30)) /* CRC-mask */
  68. #define SRCHNUM(base) ((vuint16 *)(base + 0x3F34)) /* Do not write to */
  69. #define INT_CNT(base) ((vuint16 *)(base + 0x3F36)) /* Interrupt-Counter */
  70. #define INT_ICNT(base) ((vuint16 *)(base + 0x3F38)) /* Interrupt threshold */
  71. #define TSTA(base) ((vuint16 *)(base + 0x3F3A)) /* Time-stamp-address */
  72. #define OLDLEN(base) ((vuint16 *)(base + 0x3F3C)) /* Do not write to */
  73. #define SMRBLR(base) ((vuint16 *)(base + 0x3F3E)) /* SAR max RXBuffer length */
  74. #define EHEAD(base) ((vuint32 *)(base + 0x3F40)) /* Valid for serial mode */
  75. #define EPAYLOAD(base) ((vuint32 *)(base + 0x3F44)) /* Valid for serial mode */
  76. #define TQBASE(base) ((vuint16 *)(base + 0x3F48)) /* Base address of Tx queue */
  77. #define TQEND(base) ((vuint16 *)(base + 0x3F4A)) /* End address of Tx queue */
  78. #define TQAPTR(base) ((vuint16 *)(base + 0x3F4C)) /* TQ APC pointer */
  79. #define TQTPTR(base) ((vuint16 *)(base + 0x3F4E)) /* TQ Tx pointer */
  80. #define APCST(base) ((vuint16 *)(base + 0x3F50)) /* APC status */
  81. #define APCPTR(base) ((vuint16 *)(base + 0x3F52)) /* APC parameter pointer */
  82. #define HMASK(base) ((vuint32 *)(base + 0x3F54)) /* Header mask */
  83. #define AMBASE(base) ((vuint16 *)(base + 0x3F58)) /* Address match table base */
  84. #define AMEND(base) ((vuint16 *)(base + 0x3F5A)) /* Address match table end */
  85. #define APBASE(base) ((vuint16 *)(base + 0x3F5C)) /* Address match parameter */
  86. #define FLBASE(base) ((vuint32 *)(base + 0x3F54)) /* First-level table base */
  87. #define SLBASE(base) ((vuint32 *)(base + 0x3F58)) /* Second-level table base */
  88. #define FLMASK(base) ((vuint16 *)(base + 0x3F5C)) /* First-level mask */
  89. #define ECSIZE(base) ((vuint16 *)(base + 0x3F5E)) /* Valid for extended mode */
  90. #define APCT_REAL(base) ((vuint32 *)(base + 0x3F60)) /* APC 32 bit counter */
  91. #define R_PTR(base) ((vuint32 *)(base + 0x3F64)) /* Do not write to */
  92. #define RTEMP(base) ((vuint32 *)(base + 0x3F68)) /* Do not write to */
  93. #define T_PTR(base) ((vuint32 *)(base + 0x3F6C)) /* Do not write to */
  94. #define TTEMP(base) ((vuint32 *)(base + 0x3F70)) /* Do not write to */
  95. /* ESAR registers */
  96. #define FMCTIMESTMP(base) ((vuint32 *)(base + 0x3F80)) /* Perf.Mon.Timestamp */
  97. #define FMCTEMPLATE(base) ((vuint32 *)(base + 0x3F84)) /* Perf.Mon.Template */
  98. #define PMPTR(base) ((vuint16 *)(base + 0x3F88)) /* Perf.Mon.Table */
  99. #define PMCHANNEL(base) ((vuint16 *)(base + 0x3F8A)) /* Perf.Mon.Channel */
  100. #define MPHYST(base) ((vuint16 *)(base + 0x3F90)) /* Multi-PHY Status */
  101. #define TCTEBASE(base) ((vuint16 *)(base + 0x3F92)) /* Internal TCT Extension Base */
  102. #define ETCTEBASE(base) ((vuint32 *)(base + 0x3F94)) /* External TCT Extension Base */
  103. #define COMM_CH2(base) ((vuint32 *)(base + 0x3F98)) /* 2nd command channel word */
  104. #define STATBASE(base) ((vuint16 *)(base + 0x3F9C)) /* Statistics table pointer */
  105. /* UTOPIA Mode Register */
  106. #define UTMODE(base) (CAST(vuint32 *)(base + 0x0978))
  107. /* SAR commands */
  108. #define TRANSMIT_CHANNEL_ACTIVATE_CMD 0x0FC1
  109. #define TRANSMIT_CHANNEL_DEACTIVATE_CMD 0x1FC1
  110. #define STOP_TRANSMIT_CMD 0x2FC1
  111. #define RESTART_TRANSMIT_CMD 0x3FC1
  112. #define STOP_RECEIVE_CMD 0x4FC1
  113. #define RESTART_RECEIVE_CMD 0x5FC1
  114. #define APC_BYPASS_CMD 0x6FC1
  115. #define MEM_WRITE_CMD 0x7FC1
  116. #define CPCR_FLG 0x0001
  117. /* INT flags */
  118. #define INT_VALID 0x80000000
  119. #define INT_WRAP 0x40000000
  120. #define INT_APCO 0x00800000
  121. #define INT_TQF 0x00200000
  122. #define INT_RXF 0x00080000
  123. #define INT_BSY 0x00040000
  124. #define INT_TXB 0x00020000
  125. #define INT_RXB 0x00010000
  126. #define NUM_INT_ENTRIES 80
  127. #define SIZE_OF_INT_ENTRY 4
  128. struct apc_params_t {
  129. vuint16 apct_base1; /* APC Table - First Priority Base pointer */
  130. vuint16 apct_end1; /* First APC Table - Length */
  131. vuint16 apct_ptr1; /* First APC Table Pointer */
  132. vuint16 apct_sptr1; /* APC Table First Priority Service pointer */
  133. vuint16 etqbase; /* Enhanced Transmit Queue Base pointer */
  134. vuint16 etqend; /* Enhanced Transmit Queue End pointer */
  135. vuint16 etqaptr; /* Enhanced Transmit Queue APC pointer */
  136. vuint16 etqtptr; /* Enhanced Transmit Queue Transmitter pointer */
  137. vuint16 apc_mi; /* APC - Max Iteration */
  138. vuint16 ncits; /* Number of Cells In TimeSlot */
  139. vuint16 apcnt; /* APC - N Timer */
  140. vuint16 reserved1; /* reserved */
  141. vuint16 eapcst; /* APC status */
  142. vuint16 ptp_counter; /* PTP queue length */
  143. vuint16 ptp_txch; /* PTP channel */
  144. vuint16 reserved2; /* reserved */
  145. };
  146. struct ct_entry_t {
  147. /* RCT */
  148. unsigned fhnt:1;
  149. unsigned pm_rct:1;
  150. unsigned reserved0:6;
  151. unsigned hec:1;
  152. unsigned clp:1;
  153. unsigned cng_ncrc:1;
  154. unsigned inf_rct:1;
  155. unsigned cngi_ptp:1;
  156. unsigned cdis_rct:1;
  157. unsigned aal_rct:2;
  158. uint16 rbalen;
  159. uint32 rcrc;
  160. uint32 rb_ptr;
  161. uint16 rtmlen;
  162. uint16 rbd_ptr;
  163. uint16 rbase;
  164. uint16 tstamp;
  165. uint16 imask;
  166. unsigned ft:2;
  167. unsigned nim:1;
  168. unsigned reserved1:2;
  169. unsigned rpmt:6;
  170. unsigned reserved2:5;
  171. uint8 reserved3[8];
  172. /* TCT */
  173. unsigned reserved4:1;
  174. unsigned pm_tct:1;
  175. unsigned reserved5:6;
  176. unsigned pc:1;
  177. unsigned reserved6:2;
  178. unsigned inf_tct:1;
  179. unsigned cr10:1;
  180. unsigned cdis_tct:1;
  181. unsigned aal_tct:2;
  182. uint16 tbalen;
  183. uint32 tcrc;
  184. uint32 tb_ptr;
  185. uint16 ttmlen;
  186. uint16 tbd_ptr;
  187. uint16 tbase;
  188. unsigned reserved7:5;
  189. unsigned tpmt:6;
  190. unsigned reserved8:3;
  191. unsigned avcf:1;
  192. unsigned act:1;
  193. uint32 chead;
  194. uint16 apcl;
  195. uint16 apcpr;
  196. unsigned out:1;
  197. unsigned bnr:1;
  198. unsigned tservice:2;
  199. unsigned apcp:12;
  200. uint16 apcpf;
  201. };
  202. struct tcte_entry_t {
  203. unsigned res1:4;
  204. unsigned scr:12;
  205. uint16 scrf;
  206. uint16 bt;
  207. uint16 buptrh;
  208. uint32 buptrl;
  209. unsigned vbr2:1;
  210. unsigned res2:15;
  211. uint16 oobr;
  212. uint16 res3[8];
  213. };
  214. #define SIZE_OF_RBD 12
  215. #define SIZE_OF_TBD 12
  216. struct atm_bd_t {
  217. vuint16 flags;
  218. vuint16 length;
  219. unsigned char *buffer_ptr;
  220. vuint16 cpcs_uu_cpi;
  221. vuint16 reserved;
  222. };
  223. /* BD flags */
  224. #define EMPTY 0x8000
  225. #define READY 0x8000
  226. #define WRAP 0x2000
  227. #define INTERRUPT 0x1000
  228. #define LAST 0x0800
  229. #define FIRST 0x0400
  230. #define OAM 0x0400
  231. #define CONTINUOUS 0x0200
  232. #define HEC_ERROR 0x0080
  233. #define CELL_LOSS 0x0040
  234. #define CONGESTION 0x0020
  235. #define ABORT 0x0010
  236. #define LEN_ERROR 0x0002
  237. #define CRC_ERROR 0x0001
  238. struct atm_connection_t {
  239. struct atm_bd_t *rbd_ptr;
  240. int num_rbd;
  241. struct atm_bd_t *tbd_ptr;
  242. int num_tbd;
  243. struct ct_entry_t *ct_ptr;
  244. struct tcte_entry_t *tcte_ptr;
  245. void *drv;
  246. void (*notify) (void *drv, int event);
  247. };
  248. struct atm_driver_t {
  249. int loaded;
  250. int started;
  251. char *csram;
  252. int csram_size;
  253. uint32 *am_top;
  254. uint16 *ap_top;
  255. uint32 *int_reload_ptr;
  256. uint32 *int_serv_ptr;
  257. struct atm_bd_t *rbd_base_ptr;
  258. struct atm_bd_t *tbd_base_ptr;
  259. unsigned linerate_in_bps;
  260. };
  261. extern struct atm_connection_t g_conn[NUM_CONNECTIONS];
  262. extern struct atm_driver_t g_atm;
  263. extern int atmLoad (void);
  264. extern void atmUnload (void);