ibm_emac_mal.h 7.5 KB

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