mal.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * drivers/net/ibm_newemac/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_NEWEMAC_MAL_H
  20. #define __IBM_NEWEMAC_MAL_H
  21. /*
  22. * There are some variations on the MAL, we express them in this driver as
  23. * MAL Version 1 and 2 though that doesn't match any IBM terminology.
  24. *
  25. * We call MAL 1 the version in 405GP, 405GPR, 405EP, 440EP, 440GR and
  26. * NP405H.
  27. *
  28. * We call MAL 2 the version in 440GP, 440GX, 440SP, 440SPE and Axon
  29. *
  30. * The driver expects a "version" property in the emac node containing
  31. * a number 1 or 2. New device-trees for EMAC capable platforms are thus
  32. * required to include that when porting to arch/powerpc.
  33. */
  34. /* MALx DCR registers */
  35. #define MAL_CFG 0x00
  36. #define MAL_CFG_SR 0x80000000
  37. #define MAL_CFG_PLBB 0x00004000
  38. #define MAL_CFG_OPBBL 0x00000080
  39. #define MAL_CFG_EOPIE 0x00000004
  40. #define MAL_CFG_LEA 0x00000002
  41. #define MAL_CFG_SD 0x00000001
  42. /* MAL V1 CFG bits */
  43. #define MAL1_CFG_PLBP_MASK 0x00c00000
  44. #define MAL1_CFG_PLBP_10 0x00800000
  45. #define MAL1_CFG_GA 0x00200000
  46. #define MAL1_CFG_OA 0x00100000
  47. #define MAL1_CFG_PLBLE 0x00080000
  48. #define MAL1_CFG_PLBT_MASK 0x00078000
  49. #define MAL1_CFG_DEFAULT (MAL1_CFG_PLBP_10 | MAL1_CFG_PLBT_MASK)
  50. /* MAL V2 CFG bits */
  51. #define MAL2_CFG_RPP_MASK 0x00c00000
  52. #define MAL2_CFG_RPP_10 0x00800000
  53. #define MAL2_CFG_RMBS_MASK 0x00300000
  54. #define MAL2_CFG_WPP_MASK 0x000c0000
  55. #define MAL2_CFG_WPP_10 0x00080000
  56. #define MAL2_CFG_WMBS_MASK 0x00030000
  57. #define MAL2_CFG_PLBLE 0x00008000
  58. #define MAL2_CFG_DEFAULT (MAL2_CFG_RMBS_MASK | MAL2_CFG_WMBS_MASK | \
  59. MAL2_CFG_RPP_10 | MAL2_CFG_WPP_10)
  60. #define MAL_ESR 0x01
  61. #define MAL_ESR_EVB 0x80000000
  62. #define MAL_ESR_CIDT 0x40000000
  63. #define MAL_ESR_CID_MASK 0x3e000000
  64. #define MAL_ESR_CID_SHIFT 25
  65. #define MAL_ESR_DE 0x00100000
  66. #define MAL_ESR_OTE 0x00040000
  67. #define MAL_ESR_OSE 0x00020000
  68. #define MAL_ESR_PEIN 0x00010000
  69. #define MAL_ESR_DEI 0x00000010
  70. #define MAL_ESR_OTEI 0x00000004
  71. #define MAL_ESR_OSEI 0x00000002
  72. #define MAL_ESR_PBEI 0x00000001
  73. /* MAL V1 ESR bits */
  74. #define MAL1_ESR_ONE 0x00080000
  75. #define MAL1_ESR_ONEI 0x00000008
  76. /* MAL V2 ESR bits */
  77. #define MAL2_ESR_PTE 0x00800000
  78. #define MAL2_ESR_PRE 0x00400000
  79. #define MAL2_ESR_PWE 0x00200000
  80. #define MAL2_ESR_PTEI 0x00000080
  81. #define MAL2_ESR_PREI 0x00000040
  82. #define MAL2_ESR_PWEI 0x00000020
  83. #define MAL_IER 0x02
  84. #define MAL_IER_DE 0x00000010
  85. #define MAL_IER_OTE 0x00000004
  86. #define MAL_IER_OE 0x00000002
  87. #define MAL_IER_PE 0x00000001
  88. /* MAL V1 IER bits */
  89. #define MAL1_IER_NWE 0x00000008
  90. #define MAL1_IER_SOC_EVENTS MAL1_IER_NWE
  91. #define MAL1_IER_EVENTS (MAL1_IER_SOC_EVENTS | MAL_IER_OTE | \
  92. MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE)
  93. /* MAL V2 IER bits */
  94. #define MAL2_IER_PT 0x00000080
  95. #define MAL2_IER_PRE 0x00000040
  96. #define MAL2_IER_PWE 0x00000020
  97. #define MAL2_IER_SOC_EVENTS (MAL2_IER_PT | MAL2_IER_PRE | MAL2_IER_PWE)
  98. #define MAL2_IER_EVENTS (MAL2_IER_SOC_EVENTS | MAL_IER_OTE | \
  99. MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE)
  100. #define MAL_TXCASR 0x04
  101. #define MAL_TXCARR 0x05
  102. #define MAL_TXEOBISR 0x06
  103. #define MAL_TXDEIR 0x07
  104. #define MAL_RXCASR 0x10
  105. #define MAL_RXCARR 0x11
  106. #define MAL_RXEOBISR 0x12
  107. #define MAL_RXDEIR 0x13
  108. #define MAL_TXCTPR(n) ((n) + 0x20)
  109. #define MAL_RXCTPR(n) ((n) + 0x40)
  110. #define MAL_RCBS(n) ((n) + 0x60)
  111. /* In reality MAL can handle TX buffers up to 4095 bytes long,
  112. * but this isn't a good round number :) --ebs
  113. */
  114. #define MAL_MAX_TX_SIZE 4080
  115. #define MAL_MAX_RX_SIZE 4080
  116. static inline int mal_rx_size(int len)
  117. {
  118. len = (len + 0xf) & ~0xf;
  119. return len > MAL_MAX_RX_SIZE ? MAL_MAX_RX_SIZE : len;
  120. }
  121. static inline int mal_tx_chunks(int len)
  122. {
  123. return (len + MAL_MAX_TX_SIZE - 1) / MAL_MAX_TX_SIZE;
  124. }
  125. #define MAL_CHAN_MASK(n) (0x80000000 >> (n))
  126. /* MAL Buffer Descriptor structure */
  127. struct mal_descriptor {
  128. u16 ctrl; /* MAL / Commac status control bits */
  129. u16 data_len; /* Max length is 4K-1 (12 bits) */
  130. u32 data_ptr; /* pointer to actual data buffer */
  131. };
  132. /* the following defines are for the MadMAL status and control registers. */
  133. /* MADMAL transmit and receive status/control bits */
  134. #define MAL_RX_CTRL_EMPTY 0x8000
  135. #define MAL_RX_CTRL_WRAP 0x4000
  136. #define MAL_RX_CTRL_CM 0x2000
  137. #define MAL_RX_CTRL_LAST 0x1000
  138. #define MAL_RX_CTRL_FIRST 0x0800
  139. #define MAL_RX_CTRL_INTR 0x0400
  140. #define MAL_RX_CTRL_SINGLE (MAL_RX_CTRL_LAST | MAL_RX_CTRL_FIRST)
  141. #define MAL_IS_SINGLE_RX(ctrl) (((ctrl) & MAL_RX_CTRL_SINGLE) == MAL_RX_CTRL_SINGLE)
  142. #define MAL_TX_CTRL_READY 0x8000
  143. #define MAL_TX_CTRL_WRAP 0x4000
  144. #define MAL_TX_CTRL_CM 0x2000
  145. #define MAL_TX_CTRL_LAST 0x1000
  146. #define MAL_TX_CTRL_INTR 0x0400
  147. struct mal_commac_ops {
  148. void (*poll_tx) (void *dev);
  149. int (*poll_rx) (void *dev, int budget);
  150. int (*peek_rx) (void *dev);
  151. void (*rxde) (void *dev);
  152. };
  153. struct mal_commac {
  154. struct mal_commac_ops *ops;
  155. void *dev;
  156. struct list_head poll_list;
  157. long flags;
  158. #define MAL_COMMAC_RX_STOPPED 0
  159. #define MAL_COMMAC_POLL_DISABLED 1
  160. u32 tx_chan_mask;
  161. u32 rx_chan_mask;
  162. struct list_head list;
  163. };
  164. struct mal_instance {
  165. int version;
  166. dcr_host_t dcr_host;
  167. int num_tx_chans; /* Number of TX channels */
  168. int num_rx_chans; /* Number of RX channels */
  169. int txeob_irq; /* TX End Of Buffer IRQ */
  170. int rxeob_irq; /* RX End Of Buffer IRQ */
  171. int txde_irq; /* TX Descriptor Error IRQ */
  172. int rxde_irq; /* RX Descriptor Error IRQ */
  173. int serr_irq; /* MAL System Error IRQ */
  174. struct list_head poll_list;
  175. struct napi_struct napi;
  176. struct list_head list;
  177. u32 tx_chan_mask;
  178. u32 rx_chan_mask;
  179. dma_addr_t bd_dma;
  180. struct mal_descriptor *bd_virt;
  181. struct of_device *ofdev;
  182. int index;
  183. spinlock_t lock;
  184. };
  185. static inline u32 get_mal_dcrn(struct mal_instance *mal, int reg)
  186. {
  187. return dcr_read(mal->dcr_host, reg);
  188. }
  189. static inline void set_mal_dcrn(struct mal_instance *mal, int reg, u32 val)
  190. {
  191. dcr_write(mal->dcr_host, reg, val);
  192. }
  193. /* Register MAL devices */
  194. int mal_init(void);
  195. void mal_exit(void);
  196. int mal_register_commac(struct mal_instance *mal,
  197. struct mal_commac *commac);
  198. void mal_unregister_commac(struct mal_instance *mal,
  199. struct mal_commac *commac);
  200. int mal_set_rcbs(struct mal_instance *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 mal_instance *mal, int channel);
  205. int mal_rx_bd_offset(struct mal_instance *mal, int channel);
  206. void mal_enable_tx_channel(struct mal_instance *mal, int channel);
  207. void mal_disable_tx_channel(struct mal_instance *mal, int channel);
  208. void mal_enable_rx_channel(struct mal_instance *mal, int channel);
  209. void mal_disable_rx_channel(struct mal_instance *mal, int channel);
  210. void mal_poll_disable(struct mal_instance *mal, struct mal_commac *commac);
  211. void mal_poll_enable(struct mal_instance *mal, struct mal_commac *commac);
  212. /* Add/remove EMAC to/from MAL polling list */
  213. void mal_poll_add(struct mal_instance *mal, struct mal_commac *commac);
  214. void mal_poll_del(struct mal_instance *mal, struct mal_commac *commac);
  215. /* Ethtool MAL registers */
  216. struct mal_regs {
  217. u32 tx_count;
  218. u32 rx_count;
  219. u32 cfg;
  220. u32 esr;
  221. u32 ier;
  222. u32 tx_casr;
  223. u32 tx_carr;
  224. u32 tx_eobisr;
  225. u32 tx_deir;
  226. u32 rx_casr;
  227. u32 rx_carr;
  228. u32 rx_eobisr;
  229. u32 rx_deir;
  230. u32 tx_ctpr[32];
  231. u32 rx_ctpr[32];
  232. u32 rcbs[32];
  233. };
  234. int mal_get_regs_len(struct mal_instance *mal);
  235. void *mal_dump_regs(struct mal_instance *mal, void *buf);
  236. #endif /* __IBM_NEWEMAC_MAL_H */