ibm_emac_mal.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * drivers/net/ibm_emac/ibm_emac_mal.h
  3. *
  4. * Memory Access Layer (MAL) support
  5. *
  6. * Copyright (c) 2004, 2005 Zultys Technologies.
  7. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  8. *
  9. * Based on original work by
  10. * Armin Kuster <akuster@mvista.com>
  11. * Copyright 2002 MontaVista Softare Inc.
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. *
  18. */
  19. #ifndef __IBM_EMAC_MAL_H_
  20. #define __IBM_EMAC_MAL_H_
  21. #include <linux/config.h>
  22. #include <linux/init.h>
  23. #include <linux/list.h>
  24. #include <linux/netdevice.h>
  25. #include <asm/io.h>
  26. /*
  27. * These MAL "versions" probably aren't the real versions IBM uses for these
  28. * MAL cores, I assigned them just to make #ifdefs in this file nicer and
  29. * reflect the fact that 40x and 44x have slightly different MALs. --ebs
  30. */
  31. #if defined(CONFIG_405GP) || defined(CONFIG_405GPR) || defined(CONFIG_405EP) || \
  32. defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_NP405H)
  33. #define MAL_VERSION 1
  34. #elif defined(CONFIG_440GP) || defined(CONFIG_440GX) || defined(CONFIG_440SP) || \
  35. defined(CONFIG_440SPE)
  36. #define MAL_VERSION 2
  37. #else
  38. #error "Unknown SoC, please check chip manual and choose MAL 'version'"
  39. #endif
  40. /* MALx DCR registers */
  41. #define MAL_CFG 0x00
  42. #define MAL_CFG_SR 0x80000000
  43. #define MAL_CFG_PLBB 0x00004000
  44. #define MAL_CFG_OPBBL 0x00000080
  45. #define MAL_CFG_EOPIE 0x00000004
  46. #define MAL_CFG_LEA 0x00000002
  47. #define MAL_CFG_SD 0x00000001
  48. #if MAL_VERSION == 1
  49. #define MAL_CFG_PLBP_MASK 0x00c00000
  50. #define MAL_CFG_PLBP_10 0x00800000
  51. #define MAL_CFG_GA 0x00200000
  52. #define MAL_CFG_OA 0x00100000
  53. #define MAL_CFG_PLBLE 0x00080000
  54. #define MAL_CFG_PLBT_MASK 0x00078000
  55. #define MAL_CFG_DEFAULT (MAL_CFG_PLBP_10 | MAL_CFG_PLBT_MASK)
  56. #elif MAL_VERSION == 2
  57. #define MAL_CFG_RPP_MASK 0x00c00000
  58. #define MAL_CFG_RPP_10 0x00800000
  59. #define MAL_CFG_RMBS_MASK 0x00300000
  60. #define MAL_CFG_WPP_MASK 0x000c0000
  61. #define MAL_CFG_WPP_10 0x00080000
  62. #define MAL_CFG_WMBS_MASK 0x00030000
  63. #define MAL_CFG_PLBLE 0x00008000
  64. #define MAL_CFG_DEFAULT (MAL_CFG_RMBS_MASK | MAL_CFG_WMBS_MASK | \
  65. MAL_CFG_RPP_10 | MAL_CFG_WPP_10)
  66. #else
  67. #error "Unknown MAL version"
  68. #endif
  69. #define MAL_ESR 0x01
  70. #define MAL_ESR_EVB 0x80000000
  71. #define MAL_ESR_CIDT 0x40000000
  72. #define MAL_ESR_CID_MASK 0x3e000000
  73. #define MAL_ESR_CID_SHIFT 25
  74. #define MAL_ESR_DE 0x00100000
  75. #define MAL_ESR_OTE 0x00040000
  76. #define MAL_ESR_OSE 0x00020000
  77. #define MAL_ESR_PEIN 0x00010000
  78. #define MAL_ESR_DEI 0x00000010
  79. #define MAL_ESR_OTEI 0x00000004
  80. #define MAL_ESR_OSEI 0x00000002
  81. #define MAL_ESR_PBEI 0x00000001
  82. #if MAL_VERSION == 1
  83. #define MAL_ESR_ONE 0x00080000
  84. #define MAL_ESR_ONEI 0x00000008
  85. #elif MAL_VERSION == 2
  86. #define MAL_ESR_PTE 0x00800000
  87. #define MAL_ESR_PRE 0x00400000
  88. #define MAL_ESR_PWE 0x00200000
  89. #define MAL_ESR_PTEI 0x00000080
  90. #define MAL_ESR_PREI 0x00000040
  91. #define MAL_ESR_PWEI 0x00000020
  92. #else
  93. #error "Unknown MAL version"
  94. #endif
  95. #define MAL_IER 0x02
  96. #define MAL_IER_DE 0x00000010
  97. #define MAL_IER_OTE 0x00000004
  98. #define MAL_IER_OE 0x00000002
  99. #define MAL_IER_PE 0x00000001
  100. #if MAL_VERSION == 1
  101. #define MAL_IER_NWE 0x00000008
  102. #define MAL_IER_SOC_EVENTS MAL_IER_NWE
  103. #elif MAL_VERSION == 2
  104. #define MAL_IER_PT 0x00000080
  105. #define MAL_IER_PRE 0x00000040
  106. #define MAL_IER_PWE 0x00000020
  107. #define MAL_IER_SOC_EVENTS (MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE)
  108. #else
  109. #error "Unknown MAL version"
  110. #endif
  111. #define MAL_IER_EVENTS (MAL_IER_SOC_EVENTS | MAL_IER_OTE | \
  112. MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE)
  113. #define MAL_TXCASR 0x04
  114. #define MAL_TXCARR 0x05
  115. #define MAL_TXEOBISR 0x06
  116. #define MAL_TXDEIR 0x07
  117. #define MAL_RXCASR 0x10
  118. #define MAL_RXCARR 0x11
  119. #define MAL_RXEOBISR 0x12
  120. #define MAL_RXDEIR 0x13
  121. #define MAL_TXCTPR(n) ((n) + 0x20)
  122. #define MAL_RXCTPR(n) ((n) + 0x40)
  123. #define MAL_RCBS(n) ((n) + 0x60)
  124. /* In reality MAL can handle TX buffers up to 4095 bytes long,
  125. * but this isn't a good round number :) --ebs
  126. */
  127. #define MAL_MAX_TX_SIZE 4080
  128. #define MAL_MAX_RX_SIZE 4080
  129. static inline int mal_rx_size(int len)
  130. {
  131. len = (len + 0xf) & ~0xf;
  132. return len > MAL_MAX_RX_SIZE ? MAL_MAX_RX_SIZE : len;
  133. }
  134. static inline int mal_tx_chunks(int len)
  135. {
  136. return (len + MAL_MAX_TX_SIZE - 1) / MAL_MAX_TX_SIZE;
  137. }
  138. #define MAL_CHAN_MASK(n) (0x80000000 >> (n))
  139. /* MAL Buffer Descriptor structure */
  140. struct mal_descriptor {
  141. u16 ctrl; /* MAL / Commac status control bits */
  142. u16 data_len; /* Max length is 4K-1 (12 bits) */
  143. u32 data_ptr; /* pointer to actual data buffer */
  144. };
  145. /* the following defines are for the MadMAL status and control registers. */
  146. /* MADMAL transmit and receive status/control bits */
  147. #define MAL_RX_CTRL_EMPTY 0x8000
  148. #define MAL_RX_CTRL_WRAP 0x4000
  149. #define MAL_RX_CTRL_CM 0x2000
  150. #define MAL_RX_CTRL_LAST 0x1000
  151. #define MAL_RX_CTRL_FIRST 0x0800
  152. #define MAL_RX_CTRL_INTR 0x0400
  153. #define MAL_RX_CTRL_SINGLE (MAL_RX_CTRL_LAST | MAL_RX_CTRL_FIRST)
  154. #define MAL_IS_SINGLE_RX(ctrl) (((ctrl) & MAL_RX_CTRL_SINGLE) == MAL_RX_CTRL_SINGLE)
  155. #define MAL_TX_CTRL_READY 0x8000
  156. #define MAL_TX_CTRL_WRAP 0x4000
  157. #define MAL_TX_CTRL_CM 0x2000
  158. #define MAL_TX_CTRL_LAST 0x1000
  159. #define MAL_TX_CTRL_INTR 0x0400
  160. struct mal_commac_ops {
  161. void (*poll_tx) (void *dev);
  162. int (*poll_rx) (void *dev, int budget);
  163. int (*peek_rx) (void *dev);
  164. void (*rxde) (void *dev);
  165. };
  166. struct mal_commac {
  167. struct mal_commac_ops *ops;
  168. void *dev;
  169. struct list_head poll_list;
  170. int rx_stopped;
  171. u32 tx_chan_mask;
  172. u32 rx_chan_mask;
  173. struct list_head list;
  174. };
  175. struct ibm_ocp_mal {
  176. int dcrbase;
  177. struct list_head poll_list;
  178. struct net_device poll_dev;
  179. struct list_head list;
  180. u32 tx_chan_mask;
  181. u32 rx_chan_mask;
  182. dma_addr_t bd_dma;
  183. struct mal_descriptor *bd_virt;
  184. struct ocp_def *def;
  185. };
  186. static inline u32 get_mal_dcrn(struct ibm_ocp_mal *mal, int reg)
  187. {
  188. return mfdcr(mal->dcrbase + reg);
  189. }
  190. static inline void set_mal_dcrn(struct ibm_ocp_mal *mal, int reg, u32 val)
  191. {
  192. mtdcr(mal->dcrbase + reg, val);
  193. }
  194. /* Register MAL devices */
  195. int mal_init(void) __init;
  196. void mal_exit(void) __exit;
  197. int mal_register_commac(struct ibm_ocp_mal *mal,
  198. struct mal_commac *commac) __init;
  199. void mal_unregister_commac(struct ibm_ocp_mal *mal,
  200. struct mal_commac *commac) __exit;
  201. int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel, unsigned long size);
  202. /* Returns BD ring offset for a particular channel
  203. (in 'struct mal_descriptor' elements)
  204. */
  205. int mal_tx_bd_offset(struct ibm_ocp_mal *mal, int channel);
  206. int mal_rx_bd_offset(struct ibm_ocp_mal *mal, int channel);
  207. void mal_enable_tx_channel(struct ibm_ocp_mal *mal, int channel);
  208. void mal_disable_tx_channel(struct ibm_ocp_mal *mal, int channel);
  209. void mal_enable_rx_channel(struct ibm_ocp_mal *mal, int channel);
  210. void mal_disable_rx_channel(struct ibm_ocp_mal *mal, int channel);
  211. /* Add/remove EMAC to/from MAL polling list */
  212. void mal_poll_add(struct ibm_ocp_mal *mal, struct mal_commac *commac);
  213. void mal_poll_del(struct ibm_ocp_mal *mal, struct mal_commac *commac);
  214. /* Ethtool MAL registers */
  215. struct ibm_mal_regs {
  216. u32 tx_count;
  217. u32 rx_count;
  218. u32 cfg;
  219. u32 esr;
  220. u32 ier;
  221. u32 tx_casr;
  222. u32 tx_carr;
  223. u32 tx_eobisr;
  224. u32 tx_deir;
  225. u32 rx_casr;
  226. u32 rx_carr;
  227. u32 rx_eobisr;
  228. u32 rx_deir;
  229. u32 tx_ctpr[32];
  230. u32 rx_ctpr[32];
  231. u32 rcbs[32];
  232. };
  233. int mal_get_regs_len(struct ibm_ocp_mal *mal);
  234. void *mal_dump_regs(struct ibm_ocp_mal *mal, void *buf);
  235. #endif /* __IBM_EMAC_MAL_H_ */