mal.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * drivers/net/ethernet/ibm/emac/mal.h
  4. *
  5. * Memory Access Layer (MAL) support
  6. *
  7. * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
  8. * <[email protected]>
  9. *
  10. * Based on the arch/ppc version of the driver:
  11. *
  12. * Copyright (c) 2004, 2005 Zultys Technologies.
  13. * Eugene Surovegin <[email protected]> or <[email protected]>
  14. *
  15. * Based on original work by
  16. * Armin Kuster <[email protected]>
  17. * Copyright 2002 MontaVista Softare Inc.
  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. /* MAL IER bits */
  85. #define MAL_IER_DE 0x00000010
  86. #define MAL_IER_OTE 0x00000004
  87. #define MAL_IER_OE 0x00000002
  88. #define MAL_IER_PE 0x00000001
  89. /* PLB read/write/timeout errors */
  90. #define MAL_IER_PTE 0x00000080
  91. #define MAL_IER_PRE 0x00000040
  92. #define MAL_IER_PWE 0x00000020
  93. #define MAL_IER_SOC_EVENTS (MAL_IER_PTE | MAL_IER_PRE | MAL_IER_PWE)
  94. #define MAL_IER_EVENTS (MAL_IER_SOC_EVENTS | MAL_IER_DE | \
  95. MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE)
  96. #define MAL_TXCASR 0x04
  97. #define MAL_TXCARR 0x05
  98. #define MAL_TXEOBISR 0x06
  99. #define MAL_TXDEIR 0x07
  100. #define MAL_RXCASR 0x10
  101. #define MAL_RXCARR 0x11
  102. #define MAL_RXEOBISR 0x12
  103. #define MAL_RXDEIR 0x13
  104. #define MAL_TXCTPR(n) ((n) + 0x20)
  105. #define MAL_RXCTPR(n) ((n) + 0x40)
  106. #define MAL_RCBS(n) ((n) + 0x60)
  107. /* In reality MAL can handle TX buffers up to 4095 bytes long,
  108. * but this isn't a good round number :) --ebs
  109. */
  110. #define MAL_MAX_TX_SIZE 4080
  111. #define MAL_MAX_RX_SIZE 4080
  112. static inline int mal_rx_size(int len)
  113. {
  114. len = (len + 0xf) & ~0xf;
  115. return len > MAL_MAX_RX_SIZE ? MAL_MAX_RX_SIZE : len;
  116. }
  117. static inline int mal_tx_chunks(int len)
  118. {
  119. return DIV_ROUND_UP(len, MAL_MAX_TX_SIZE);
  120. }
  121. #define MAL_CHAN_MASK(n) (0x80000000 >> (n))
  122. /* MAL Buffer Descriptor structure */
  123. struct mal_descriptor {
  124. u16 ctrl; /* MAL / Commac status control bits */
  125. u16 data_len; /* Max length is 4K-1 (12 bits) */
  126. u32 data_ptr; /* pointer to actual data buffer */
  127. };
  128. /* the following defines are for the MadMAL status and control registers. */
  129. /* MADMAL transmit and receive status/control bits */
  130. #define MAL_RX_CTRL_EMPTY 0x8000
  131. #define MAL_RX_CTRL_WRAP 0x4000
  132. #define MAL_RX_CTRL_CM 0x2000
  133. #define MAL_RX_CTRL_LAST 0x1000
  134. #define MAL_RX_CTRL_FIRST 0x0800
  135. #define MAL_RX_CTRL_INTR 0x0400
  136. #define MAL_RX_CTRL_SINGLE (MAL_RX_CTRL_LAST | MAL_RX_CTRL_FIRST)
  137. #define MAL_IS_SINGLE_RX(ctrl) (((ctrl) & MAL_RX_CTRL_SINGLE) == MAL_RX_CTRL_SINGLE)
  138. #define MAL_TX_CTRL_READY 0x8000
  139. #define MAL_TX_CTRL_WRAP 0x4000
  140. #define MAL_TX_CTRL_CM 0x2000
  141. #define MAL_TX_CTRL_LAST 0x1000
  142. #define MAL_TX_CTRL_INTR 0x0400
  143. struct mal_commac_ops {
  144. void (*poll_tx) (void *dev);
  145. int (*poll_rx) (void *dev, int budget);
  146. int (*peek_rx) (void *dev);
  147. void (*rxde) (void *dev);
  148. };
  149. struct mal_commac {
  150. struct mal_commac_ops *ops;
  151. void *dev;
  152. struct list_head poll_list;
  153. long flags;
  154. #define MAL_COMMAC_RX_STOPPED 0
  155. #define MAL_COMMAC_POLL_DISABLED 1
  156. u32 tx_chan_mask;
  157. u32 rx_chan_mask;
  158. struct list_head list;
  159. };
  160. struct mal_instance {
  161. int version;
  162. dcr_host_t dcr_host;
  163. int num_tx_chans; /* Number of TX channels */
  164. int num_rx_chans; /* Number of RX channels */
  165. int txeob_irq; /* TX End Of Buffer IRQ */
  166. int rxeob_irq; /* RX End Of Buffer IRQ */
  167. int txde_irq; /* TX Descriptor Error IRQ */
  168. int rxde_irq; /* RX Descriptor Error IRQ */
  169. int serr_irq; /* MAL System Error IRQ */
  170. struct list_head poll_list;
  171. struct napi_struct napi;
  172. struct list_head list;
  173. u32 tx_chan_mask;
  174. u32 rx_chan_mask;
  175. dma_addr_t bd_dma;
  176. struct mal_descriptor *bd_virt;
  177. struct platform_device *ofdev;
  178. int index;
  179. spinlock_t lock;
  180. struct net_device dummy_dev;
  181. unsigned int features;
  182. };
  183. static inline u32 get_mal_dcrn(struct mal_instance *mal, int reg)
  184. {
  185. return dcr_read(mal->dcr_host, reg);
  186. }
  187. static inline void set_mal_dcrn(struct mal_instance *mal, int reg, u32 val)
  188. {
  189. dcr_write(mal->dcr_host, reg, val);
  190. }
  191. /* Features of various MAL implementations */
  192. /* Set if you have interrupt coalescing and you have to clear the SDR
  193. * register for TXEOB and RXEOB interrupts to work
  194. */
  195. #define MAL_FTR_CLEAR_ICINTSTAT 0x00000001
  196. /* Set if your MAL has SERR, TXDE, and RXDE OR'd into a single UIC
  197. * interrupt
  198. */
  199. #define MAL_FTR_COMMON_ERR_INT 0x00000002
  200. enum {
  201. MAL_FTRS_ALWAYS = 0,
  202. MAL_FTRS_POSSIBLE =
  203. #ifdef CONFIG_IBM_EMAC_MAL_CLR_ICINTSTAT
  204. MAL_FTR_CLEAR_ICINTSTAT |
  205. #endif
  206. #ifdef CONFIG_IBM_EMAC_MAL_COMMON_ERR
  207. MAL_FTR_COMMON_ERR_INT |
  208. #endif
  209. 0,
  210. };
  211. static inline int mal_has_feature(struct mal_instance *dev,
  212. unsigned long feature)
  213. {
  214. return (MAL_FTRS_ALWAYS & feature) ||
  215. (MAL_FTRS_POSSIBLE & dev->features & feature);
  216. }
  217. /* Register MAL devices */
  218. int mal_init(void);
  219. void mal_exit(void);
  220. int mal_register_commac(struct mal_instance *mal,
  221. struct mal_commac *commac);
  222. void mal_unregister_commac(struct mal_instance *mal,
  223. struct mal_commac *commac);
  224. int mal_set_rcbs(struct mal_instance *mal, int channel, unsigned long size);
  225. /* Returns BD ring offset for a particular channel
  226. (in 'struct mal_descriptor' elements)
  227. */
  228. int mal_tx_bd_offset(struct mal_instance *mal, int channel);
  229. int mal_rx_bd_offset(struct mal_instance *mal, int channel);
  230. void mal_enable_tx_channel(struct mal_instance *mal, int channel);
  231. void mal_disable_tx_channel(struct mal_instance *mal, int channel);
  232. void mal_enable_rx_channel(struct mal_instance *mal, int channel);
  233. void mal_disable_rx_channel(struct mal_instance *mal, int channel);
  234. void mal_poll_disable(struct mal_instance *mal, struct mal_commac *commac);
  235. void mal_poll_enable(struct mal_instance *mal, struct mal_commac *commac);
  236. /* Add/remove EMAC to/from MAL polling list */
  237. void mal_poll_add(struct mal_instance *mal, struct mal_commac *commac);
  238. void mal_poll_del(struct mal_instance *mal, struct mal_commac *commac);
  239. /* Ethtool MAL registers */
  240. struct mal_regs {
  241. u32 tx_count;
  242. u32 rx_count;
  243. u32 cfg;
  244. u32 esr;
  245. u32 ier;
  246. u32 tx_casr;
  247. u32 tx_carr;
  248. u32 tx_eobisr;
  249. u32 tx_deir;
  250. u32 rx_casr;
  251. u32 rx_carr;
  252. u32 rx_eobisr;
  253. u32 rx_deir;
  254. u32 tx_ctpr[32];
  255. u32 rx_ctpr[32];
  256. u32 rcbs[32];
  257. };
  258. int mal_get_regs_len(struct mal_instance *mal);
  259. void *mal_dump_regs(struct mal_instance *mal, void *buf);
  260. #endif /* __IBM_NEWEMAC_MAL_H */