cppi_dma.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/errno.h>
  7. #include <linux/dmapool.h>
  8. #include <linux/dmaengine.h>
  9. #include "musb_core.h"
  10. #include "musb_dma.h"
  11. /* CPPI RX/TX state RAM */
  12. struct cppi_tx_stateram {
  13. u32 tx_head; /* "DMA packet" head descriptor */
  14. u32 tx_buf;
  15. u32 tx_current; /* current descriptor */
  16. u32 tx_buf_current;
  17. u32 tx_info; /* flags, remaining buflen */
  18. u32 tx_rem_len;
  19. u32 tx_dummy; /* unused */
  20. u32 tx_complete;
  21. };
  22. struct cppi_rx_stateram {
  23. u32 rx_skipbytes;
  24. u32 rx_head;
  25. u32 rx_sop; /* "DMA packet" head descriptor */
  26. u32 rx_current; /* current descriptor */
  27. u32 rx_buf_current;
  28. u32 rx_len_len;
  29. u32 rx_cnt_cnt;
  30. u32 rx_complete;
  31. };
  32. /* hw_options bits in CPPI buffer descriptors */
  33. #define CPPI_SOP_SET ((u32)(1 << 31))
  34. #define CPPI_EOP_SET ((u32)(1 << 30))
  35. #define CPPI_OWN_SET ((u32)(1 << 29)) /* owned by cppi */
  36. #define CPPI_EOQ_MASK ((u32)(1 << 28))
  37. #define CPPI_ZERO_SET ((u32)(1 << 23)) /* rx saw zlp; tx issues one */
  38. #define CPPI_RXABT_MASK ((u32)(1 << 19)) /* need more rx buffers */
  39. #define CPPI_RECV_PKTLEN_MASK 0xFFFF
  40. #define CPPI_BUFFER_LEN_MASK 0xFFFF
  41. #define CPPI_TEAR_READY ((u32)(1 << 31))
  42. /* CPPI data structure definitions */
  43. #define CPPI_DESCRIPTOR_ALIGN 16 /* bytes; 5-dec docs say 4-byte align */
  44. struct cppi_descriptor {
  45. /* hardware overlay */
  46. u32 hw_next; /* next buffer descriptor Pointer */
  47. u32 hw_bufp; /* i/o buffer pointer */
  48. u32 hw_off_len; /* buffer_offset16, buffer_length16 */
  49. u32 hw_options; /* flags: SOP, EOP etc*/
  50. struct cppi_descriptor *next;
  51. dma_addr_t dma; /* address of this descriptor */
  52. u32 buflen; /* for RX: original buffer length */
  53. } __attribute__ ((aligned(CPPI_DESCRIPTOR_ALIGN)));
  54. struct cppi;
  55. /* CPPI Channel Control structure */
  56. struct cppi_channel {
  57. struct dma_channel channel;
  58. /* back pointer to the DMA controller structure */
  59. struct cppi *controller;
  60. /* which direction of which endpoint? */
  61. struct musb_hw_ep *hw_ep;
  62. bool transmit;
  63. u8 index;
  64. /* DMA modes: RNDIS or "transparent" */
  65. u8 is_rndis;
  66. /* book keeping for current transfer request */
  67. dma_addr_t buf_dma;
  68. u32 buf_len;
  69. u32 maxpacket;
  70. u32 offset; /* dma requested */
  71. void __iomem *state_ram; /* CPPI state */
  72. struct cppi_descriptor *freelist;
  73. /* BD management fields */
  74. struct cppi_descriptor *head;
  75. struct cppi_descriptor *tail;
  76. struct cppi_descriptor *last_processed;
  77. /* use tx_complete in host role to track endpoints waiting for
  78. * FIFONOTEMPTY to clear.
  79. */
  80. struct list_head tx_complete;
  81. };
  82. /* CPPI DMA controller object */
  83. struct cppi {
  84. struct dma_controller controller;
  85. struct musb *musb;
  86. void __iomem *mregs; /* Mentor regs */
  87. void __iomem *tibase; /* TI/CPPI regs */
  88. int irq;
  89. struct cppi_channel tx[4];
  90. struct cppi_channel rx[4];
  91. struct dma_pool *pool;
  92. struct list_head tx_complete;
  93. };
  94. /* CPPI IRQ handler */
  95. extern irqreturn_t cppi_interrupt(int, void *);
  96. struct cppi41_dma_channel {
  97. struct dma_channel channel;
  98. struct cppi41_dma_controller *controller;
  99. struct musb_hw_ep *hw_ep;
  100. struct dma_chan *dc;
  101. dma_cookie_t cookie;
  102. u8 port_num;
  103. u8 is_tx;
  104. u8 is_allocated;
  105. u8 usb_toggle;
  106. dma_addr_t buf_addr;
  107. u32 total_len;
  108. u32 prog_len;
  109. u32 transferred;
  110. u32 packet_sz;
  111. struct list_head tx_check;
  112. int tx_zlp;
  113. };
  114. #endif /* end of ifndef _CPPI_DMA_H_ */