ibm_emac_mal.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #ifndef _IBM_EMAC_MAL_H
  2. #define _IBM_EMAC_MAL_H
  3. #include <linux/list.h>
  4. #define MAL_DT_ALIGN (4096) /* Alignment for each channel's descriptor table */
  5. #define MAL_CHAN_MASK(chan) (0x80000000 >> (chan))
  6. /* MAL Buffer Descriptor structure */
  7. struct mal_descriptor {
  8. unsigned short ctrl; /* MAL / Commac status control bits */
  9. short data_len; /* Max length is 4K-1 (12 bits) */
  10. unsigned char *data_ptr; /* pointer to actual data buffer */
  11. } __attribute__ ((packed));
  12. /* the following defines are for the MadMAL status and control registers. */
  13. /* MADMAL transmit and receive status/control bits */
  14. #define MAL_RX_CTRL_EMPTY 0x8000
  15. #define MAL_RX_CTRL_WRAP 0x4000
  16. #define MAL_RX_CTRL_CM 0x2000
  17. #define MAL_RX_CTRL_LAST 0x1000
  18. #define MAL_RX_CTRL_FIRST 0x0800
  19. #define MAL_RX_CTRL_INTR 0x0400
  20. #define MAL_TX_CTRL_READY 0x8000
  21. #define MAL_TX_CTRL_WRAP 0x4000
  22. #define MAL_TX_CTRL_CM 0x2000
  23. #define MAL_TX_CTRL_LAST 0x1000
  24. #define MAL_TX_CTRL_INTR 0x0400
  25. struct mal_commac_ops {
  26. void (*txeob) (void *dev, u32 chanmask);
  27. void (*txde) (void *dev, u32 chanmask);
  28. void (*rxeob) (void *dev, u32 chanmask);
  29. void (*rxde) (void *dev, u32 chanmask);
  30. };
  31. struct mal_commac {
  32. struct mal_commac_ops *ops;
  33. void *dev;
  34. u32 tx_chan_mask, rx_chan_mask;
  35. struct list_head list;
  36. };
  37. struct ibm_ocp_mal {
  38. int dcrbase;
  39. struct list_head commac;
  40. u32 tx_chan_mask, rx_chan_mask;
  41. dma_addr_t tx_phys_addr;
  42. struct mal_descriptor *tx_virt_addr;
  43. dma_addr_t rx_phys_addr;
  44. struct mal_descriptor *rx_virt_addr;
  45. };
  46. #define GET_MAL_STANZA(base,dcrn) \
  47. case base: \
  48. x = mfdcr(dcrn(base)); \
  49. break;
  50. #define SET_MAL_STANZA(base,dcrn, val) \
  51. case base: \
  52. mtdcr(dcrn(base), (val)); \
  53. break;
  54. #define GET_MAL0_STANZA(dcrn) GET_MAL_STANZA(DCRN_MAL_BASE,dcrn)
  55. #define SET_MAL0_STANZA(dcrn,val) SET_MAL_STANZA(DCRN_MAL_BASE,dcrn,val)
  56. #ifdef DCRN_MAL1_BASE
  57. #define GET_MAL1_STANZA(dcrn) GET_MAL_STANZA(DCRN_MAL1_BASE,dcrn)
  58. #define SET_MAL1_STANZA(dcrn,val) SET_MAL_STANZA(DCRN_MAL1_BASE,dcrn,val)
  59. #else /* ! DCRN_MAL1_BASE */
  60. #define GET_MAL1_STANZA(dcrn)
  61. #define SET_MAL1_STANZA(dcrn,val)
  62. #endif
  63. #define get_mal_dcrn(mal, dcrn) ({ \
  64. u32 x; \
  65. switch ((mal)->dcrbase) { \
  66. GET_MAL0_STANZA(dcrn) \
  67. GET_MAL1_STANZA(dcrn) \
  68. default: \
  69. x = 0; \
  70. BUG(); \
  71. } \
  72. x; })
  73. #define set_mal_dcrn(mal, dcrn, val) do { \
  74. switch ((mal)->dcrbase) { \
  75. SET_MAL0_STANZA(dcrn,val) \
  76. SET_MAL1_STANZA(dcrn,val) \
  77. default: \
  78. BUG(); \
  79. } } while (0)
  80. static inline void mal_enable_tx_channels(struct ibm_ocp_mal *mal, u32 chanmask)
  81. {
  82. set_mal_dcrn(mal, DCRN_MALTXCASR,
  83. get_mal_dcrn(mal, DCRN_MALTXCASR) | chanmask);
  84. }
  85. static inline void mal_disable_tx_channels(struct ibm_ocp_mal *mal,
  86. u32 chanmask)
  87. {
  88. set_mal_dcrn(mal, DCRN_MALTXCARR, chanmask);
  89. }
  90. static inline void mal_enable_rx_channels(struct ibm_ocp_mal *mal, u32 chanmask)
  91. {
  92. set_mal_dcrn(mal, DCRN_MALRXCASR,
  93. get_mal_dcrn(mal, DCRN_MALRXCASR) | chanmask);
  94. }
  95. static inline void mal_disable_rx_channels(struct ibm_ocp_mal *mal,
  96. u32 chanmask)
  97. {
  98. set_mal_dcrn(mal, DCRN_MALRXCARR, chanmask);
  99. }
  100. extern int mal_register_commac(struct ibm_ocp_mal *mal,
  101. struct mal_commac *commac);
  102. extern int mal_unregister_commac(struct ibm_ocp_mal *mal,
  103. struct mal_commac *commac);
  104. extern int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel,
  105. unsigned long size);
  106. #endif /* _IBM_EMAC_MAL_H */