mal.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * drivers/net/ethernet/ibm/emac/mal.h
  3. *
  4. * Memory Access Layer (MAL) support
  5. *
  6. * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
  7. * <benh@kernel.crashing.org>
  8. *
  9. * Based on the arch/ppc version of the driver:
  10. *
  11. * Copyright (c) 2004, 2005 Zultys Technologies.
  12. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  13. *
  14. * Based on original work by
  15. * Armin Kuster <akuster@mvista.com>
  16. * Copyright 2002 MontaVista Softare Inc.
  17. *
  18. * This program is free software; you can redistribute it and/or modify it
  19. * under the terms of the GNU General Public License as published by the
  20. * Free Software Foundation; either version 2 of the License, or (at your
  21. * option) any later version.
  22. *
  23. */
  24. #ifndef __IBM_NEWEMAC_MAL_H
  25. #define __IBM_NEWEMAC_MAL_H
  26. /*
  27. * There are some variations on the MAL, we express them in this driver as
  28. * MAL Version 1 and 2 though that doesn't match any IBM terminology.
  29. *
  30. * We call MAL 1 the version in 405GP, 405GPR, 405EP, 440EP, 440GR and
  31. * NP405H.
  32. *
  33. * We call MAL 2 the version in 440GP, 440GX, 440SP, 440SPE and Axon
  34. *
  35. * The driver expects a "version" property in the emac node containing
  36. * a number 1 or 2. New device-trees for EMAC capable platforms are thus
  37. * required to include that when porting to arch/powerpc.
  38. */
  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. /* MAL V1 CFG bits */
  48. #define MAL1_CFG_PLBP_MASK 0x00c00000
  49. #define MAL1_CFG_PLBP_10 0x00800000
  50. #define MAL1_CFG_GA 0x00200000
  51. #define MAL1_CFG_OA 0x00100000
  52. #define MAL1_CFG_PLBLE 0x00080000
  53. #define MAL1_CFG_PLBT_MASK 0x00078000
  54. #define MAL1_CFG_DEFAULT (MAL1_CFG_PLBP_10 | MAL1_CFG_PLBT_MASK)
  55. /* MAL V2 CFG bits */
  56. #define MAL2_CFG_RPP_MASK 0x00c00000
  57. #define MAL2_CFG_RPP_10 0x00800000
  58. #define MAL2_CFG_RMBS_MASK 0x00300000
  59. #define MAL2_CFG_WPP_MASK 0x000c0000
  60. #define MAL2_CFG_WPP_10 0x00080000
  61. #define MAL2_CFG_WMBS_MASK 0x00030000
  62. #define MAL2_CFG_PLBLE 0x00008000
  63. #define MAL2_CFG_DEFAULT (MAL2_CFG_RMBS_MASK | MAL2_CFG_WMBS_MASK | \
  64. MAL2_CFG_RPP_10 | MAL2_CFG_WPP_10)
  65. #define MAL_ESR 0x01
  66. #define MAL_ESR_EVB 0x80000000
  67. #define MAL_ESR_CIDT 0x40000000
  68. #define MAL_ESR_CID_MASK 0x3e000000
  69. #define MAL_ESR_CID_SHIFT 25
  70. #define MAL_ESR_DE 0x00100000
  71. #define MAL_ESR_OTE 0x00040000
  72. #define MAL_ESR_OSE 0x00020000
  73. #define MAL_ESR_PEIN 0x00010000
  74. #define MAL_ESR_DEI 0x00000010
  75. #define MAL_ESR_OTEI 0x00000004
  76. #define MAL_ESR_OSEI 0x00000002
  77. #define MAL_ESR_PBEI 0x00000001
  78. /* MAL V1 ESR bits */
  79. #define MAL1_ESR_ONE 0x00080000
  80. #define MAL1_ESR_ONEI 0x00000008
  81. /* MAL V2 ESR bits */
  82. #define MAL2_ESR_PTE 0x00800000
  83. #define MAL2_ESR_PRE 0x00400000
  84. #define MAL2_ESR_PWE 0x00200000
  85. #define MAL2_ESR_PTEI 0x00000080
  86. #define MAL2_ESR_PREI 0x00000040
  87. #define MAL2_ESR_PWEI 0x00000020
  88. #define MAL_IER 0x02
  89. /* MAL IER bits */
  90. #define MAL_IER_DE 0x00000010
  91. #define MAL_IER_OTE 0x00000004
  92. #define MAL_IER_OE 0x00000002
  93. #define MAL_IER_PE 0x00000001
  94. /* PLB read/write/timeout errors */
  95. #define MAL_IER_PTE 0x00000080
  96. #define MAL_IER_PRE 0x00000040
  97. #define MAL_IER_PWE 0x00000020
  98. #define MAL_IER_SOC_EVENTS (MAL_IER_PTE | MAL_IER_PRE | MAL_IER_PWE)
  99. #define MAL_IER_EVENTS (MAL_IER_SOC_EVENTS | MAL_IER_DE | \
  100. MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE)
  101. #define MAL_TXCASR 0x04
  102. #define MAL_TXCARR 0x05
  103. #define MAL_TXEOBISR 0x06
  104. #define MAL_TXDEIR 0x07
  105. #define MAL_RXCASR 0x10
  106. #define MAL_RXCARR 0x11
  107. #define MAL_RXEOBISR 0x12
  108. #define MAL_RXDEIR 0x13
  109. #define MAL_TXCTPR(n) ((n) + 0x20)
  110. #define MAL_RXCTPR(n) ((n) + 0x40)
  111. #define MAL_RCBS(n) ((n) + 0x60)
  112. /* In reality MAL can handle TX buffers up to 4095 bytes long,
  113. * but this isn't a good round number :) --ebs
  114. */
  115. #define MAL_MAX_TX_SIZE 4080
  116. #define MAL_MAX_RX_SIZE 4080
  117. static inline int mal_rx_size(int len)
  118. {
  119. len = (len + 0xf) & ~0xf;
  120. return len > MAL_MAX_RX_SIZE ? MAL_MAX_RX_SIZE : len;
  121. }
  122. static inline int mal_tx_chunks(int len)
  123. {
  124. return (len + MAL_MAX_TX_SIZE - 1) / MAL_MAX_TX_SIZE;
  125. }
  126. #define MAL_CHAN_MASK(n) (0x80000000 >> (n))
  127. /* MAL Buffer Descriptor structure */
  128. struct mal_descriptor {
  129. u16 ctrl; /* MAL / Commac status control bits */
  130. u16 data_len; /* Max length is 4K-1 (12 bits) */
  131. u32 data_ptr; /* pointer to actual data buffer */
  132. };
  133. /* the following defines are for the MadMAL status and control registers. */
  134. /* MADMAL transmit and receive status/control bits */
  135. #define MAL_RX_CTRL_EMPTY 0x8000
  136. #define MAL_RX_CTRL_WRAP 0x4000
  137. #define MAL_RX_CTRL_CM 0x2000
  138. #define MAL_RX_CTRL_LAST 0x1000
  139. #define MAL_RX_CTRL_FIRST 0x0800
  140. #define MAL_RX_CTRL_INTR 0x0400
  141. #define MAL_RX_CTRL_SINGLE (MAL_RX_CTRL_LAST | MAL_RX_CTRL_FIRST)
  142. #define MAL_IS_SINGLE_RX(ctrl) (((ctrl) & MAL_RX_CTRL_SINGLE) == MAL_RX_CTRL_SINGLE)
  143. #define MAL_TX_CTRL_READY 0x8000
  144. #define MAL_TX_CTRL_WRAP 0x4000
  145. #define MAL_TX_CTRL_CM 0x2000
  146. #define MAL_TX_CTRL_LAST 0x1000
  147. #define MAL_TX_CTRL_INTR 0x0400
  148. struct mal_commac_ops {
  149. void (*poll_tx) (void *dev);
  150. int (*poll_rx) (void *dev, int budget);
  151. int (*peek_rx) (void *dev);
  152. void (*rxde) (void *dev);
  153. };
  154. struct mal_commac {
  155. struct mal_commac_ops *ops;
  156. void *dev;
  157. struct list_head poll_list;
  158. long flags;
  159. #define MAL_COMMAC_RX_STOPPED 0
  160. #define MAL_COMMAC_POLL_DISABLED 1
  161. u32 tx_chan_mask;
  162. u32 rx_chan_mask;
  163. struct list_head list;
  164. };
  165. struct mal_instance {
  166. int version;
  167. dcr_host_t dcr_host;
  168. int num_tx_chans; /* Number of TX channels */
  169. int num_rx_chans; /* Number of RX channels */
  170. int txeob_irq; /* TX End Of Buffer IRQ */
  171. int rxeob_irq; /* RX End Of Buffer IRQ */
  172. int txde_irq; /* TX Descriptor Error IRQ */
  173. int rxde_irq; /* RX Descriptor Error IRQ */
  174. int serr_irq; /* MAL System Error IRQ */
  175. struct list_head poll_list;
  176. struct napi_struct napi;
  177. struct list_head list;
  178. u32 tx_chan_mask;
  179. u32 rx_chan_mask;
  180. dma_addr_t bd_dma;
  181. struct mal_descriptor *bd_virt;
  182. struct platform_device *ofdev;
  183. int index;
  184. spinlock_t lock;
  185. struct net_device dummy_dev;
  186. unsigned int features;
  187. };
  188. static inline u32 get_mal_dcrn(struct mal_instance *mal, int reg)
  189. {
  190. return dcr_read(mal->dcr_host, reg);
  191. }
  192. static inline void set_mal_dcrn(struct mal_instance *mal, int reg, u32 val)
  193. {
  194. dcr_write(mal->dcr_host, reg, val);
  195. }
  196. /* Features of various MAL implementations */
  197. /* Set if you have interrupt coalescing and you have to clear the SDR
  198. * register for TXEOB and RXEOB interrupts to work
  199. */
  200. #define MAL_FTR_CLEAR_ICINTSTAT 0x00000001
  201. /* Set if your MAL has SERR, TXDE, and RXDE OR'd into a single UIC
  202. * interrupt
  203. */
  204. #define MAL_FTR_COMMON_ERR_INT 0x00000002
  205. enum {
  206. MAL_FTRS_ALWAYS = 0,
  207. MAL_FTRS_POSSIBLE =
  208. #ifdef CONFIG_IBM_EMAC_MAL_CLR_ICINTSTAT
  209. MAL_FTR_CLEAR_ICINTSTAT |
  210. #endif
  211. #ifdef CONFIG_IBM_EMAC_MAL_COMMON_ERR
  212. MAL_FTR_COMMON_ERR_INT |
  213. #endif
  214. 0,
  215. };
  216. static inline int mal_has_feature(struct mal_instance *dev,
  217. unsigned long feature)
  218. {
  219. return (MAL_FTRS_ALWAYS & feature) ||
  220. (MAL_FTRS_POSSIBLE & dev->features & feature);
  221. }
  222. /* Register MAL devices */
  223. int mal_init(void);
  224. void mal_exit(void);
  225. int mal_register_commac(struct mal_instance *mal,
  226. struct mal_commac *commac);
  227. void mal_unregister_commac(struct mal_instance *mal,
  228. struct mal_commac *commac);
  229. int mal_set_rcbs(struct mal_instance *mal, int channel, unsigned long size);
  230. /* Returns BD ring offset for a particular channel
  231. (in 'struct mal_descriptor' elements)
  232. */
  233. int mal_tx_bd_offset(struct mal_instance *mal, int channel);
  234. int mal_rx_bd_offset(struct mal_instance *mal, int channel);
  235. void mal_enable_tx_channel(struct mal_instance *mal, int channel);
  236. void mal_disable_tx_channel(struct mal_instance *mal, int channel);
  237. void mal_enable_rx_channel(struct mal_instance *mal, int channel);
  238. void mal_disable_rx_channel(struct mal_instance *mal, int channel);
  239. void mal_poll_disable(struct mal_instance *mal, struct mal_commac *commac);
  240. void mal_poll_enable(struct mal_instance *mal, struct mal_commac *commac);
  241. /* Add/remove EMAC to/from MAL polling list */
  242. void mal_poll_add(struct mal_instance *mal, struct mal_commac *commac);
  243. void mal_poll_del(struct mal_instance *mal, struct mal_commac *commac);
  244. /* Ethtool MAL registers */
  245. struct mal_regs {
  246. u32 tx_count;
  247. u32 rx_count;
  248. u32 cfg;
  249. u32 esr;
  250. u32 ier;
  251. u32 tx_casr;
  252. u32 tx_carr;
  253. u32 tx_eobisr;
  254. u32 tx_deir;
  255. u32 rx_casr;
  256. u32 rx_carr;
  257. u32 rx_eobisr;
  258. u32 rx_deir;
  259. u32 tx_ctpr[32];
  260. u32 rx_ctpr[32];
  261. u32 rcbs[32];
  262. };
  263. int mal_get_regs_len(struct mal_instance *mal);
  264. void *mal_dump_regs(struct mal_instance *mal, void *buf);
  265. #endif /* __IBM_NEWEMAC_MAL_H */