cppi_dma.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Copyright (C) 2005-2006 by Texas Instruments */
  2. #ifndef _CPPI_DMA_H_
  3. #define _CPPI_DMA_H_
  4. #include <linux/slab.h>
  5. #include <linux/list.h>
  6. #include <linux/smp_lock.h>
  7. #include <linux/errno.h>
  8. #include <linux/dmapool.h>
  9. #include "musb_dma.h"
  10. #include "musb_core.h"
  11. /* FIXME fully isolate CPPI from DaVinci ... the "CPPI generic" registers
  12. * would seem to be shared with the TUSB6020 (over VLYNQ).
  13. */
  14. #include "davinci.h"
  15. /* CPPI RX/TX state RAM */
  16. struct cppi_tx_stateram {
  17. u32 tx_head; /* "DMA packet" head descriptor */
  18. u32 tx_buf;
  19. u32 tx_current; /* current descriptor */
  20. u32 tx_buf_current;
  21. u32 tx_info; /* flags, remaining buflen */
  22. u32 tx_rem_len;
  23. u32 tx_dummy; /* unused */
  24. u32 tx_complete;
  25. };
  26. struct cppi_rx_stateram {
  27. u32 rx_skipbytes;
  28. u32 rx_head;
  29. u32 rx_sop; /* "DMA packet" head descriptor */
  30. u32 rx_current; /* current descriptor */
  31. u32 rx_buf_current;
  32. u32 rx_len_len;
  33. u32 rx_cnt_cnt;
  34. u32 rx_complete;
  35. };
  36. /* hw_options bits in CPPI buffer descriptors */
  37. #define CPPI_SOP_SET ((u32)(1 << 31))
  38. #define CPPI_EOP_SET ((u32)(1 << 30))
  39. #define CPPI_OWN_SET ((u32)(1 << 29)) /* owned by cppi */
  40. #define CPPI_EOQ_MASK ((u32)(1 << 28))
  41. #define CPPI_ZERO_SET ((u32)(1 << 23)) /* rx saw zlp; tx issues one */
  42. #define CPPI_RXABT_MASK ((u32)(1 << 19)) /* need more rx buffers */
  43. #define CPPI_RECV_PKTLEN_MASK 0xFFFF
  44. #define CPPI_BUFFER_LEN_MASK 0xFFFF
  45. #define CPPI_TEAR_READY ((u32)(1 << 31))
  46. /* CPPI data structure definitions */
  47. #define CPPI_DESCRIPTOR_ALIGN 16 /* bytes; 5-dec docs say 4-byte align */
  48. struct cppi_descriptor {
  49. /* hardware overlay */
  50. u32 hw_next; /* next buffer descriptor Pointer */
  51. u32 hw_bufp; /* i/o buffer pointer */
  52. u32 hw_off_len; /* buffer_offset16, buffer_length16 */
  53. u32 hw_options; /* flags: SOP, EOP etc*/
  54. struct cppi_descriptor *next;
  55. dma_addr_t dma; /* address of this descriptor */
  56. u32 buflen; /* for RX: original buffer length */
  57. } __attribute__ ((aligned(CPPI_DESCRIPTOR_ALIGN)));
  58. struct cppi;
  59. /* CPPI Channel Control structure */
  60. struct cppi_channel {
  61. struct dma_channel channel;
  62. /* back pointer to the DMA controller structure */
  63. struct cppi *controller;
  64. /* which direction of which endpoint? */
  65. struct musb_hw_ep *hw_ep;
  66. bool transmit;
  67. u8 index;
  68. /* DMA modes: RNDIS or "transparent" */
  69. u8 is_rndis;
  70. /* book keeping for current transfer request */
  71. dma_addr_t buf_dma;
  72. u32 buf_len;
  73. u32 maxpacket;
  74. u32 offset; /* dma requested */
  75. void __iomem *state_ram; /* CPPI state */
  76. struct cppi_descriptor *freelist;
  77. /* BD management fields */
  78. struct cppi_descriptor *head;
  79. struct cppi_descriptor *tail;
  80. struct cppi_descriptor *last_processed;
  81. /* use tx_complete in host role to track endpoints waiting for
  82. * FIFONOTEMPTY to clear.
  83. */
  84. struct list_head tx_complete;
  85. };
  86. /* CPPI DMA controller object */
  87. struct cppi {
  88. struct dma_controller controller;
  89. struct musb *musb;
  90. void __iomem *mregs; /* Mentor regs */
  91. void __iomem *tibase; /* TI/CPPI regs */
  92. struct cppi_channel tx[MUSB_C_NUM_EPT - 1];
  93. struct cppi_channel rx[MUSB_C_NUM_EPR - 1];
  94. struct dma_pool *pool;
  95. struct list_head tx_complete;
  96. };
  97. /* irq handling hook */
  98. extern void cppi_completion(struct musb *, u32 rx, u32 tx);
  99. #endif /* end of ifndef _CPPI_DMA_H_ */