cppi41dma.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. /**
  2. * \file cppi41dma.h
  3. *
  4. * \brief CPPI 4.1 DMA related function prototypes
  5. *
  6. * This file contains the API prototypes for CPPI 4.1 DMA
  7. */
  8. /*
  9. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  10. */
  11. /*
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the
  22. * distribution.
  23. *
  24. * Neither the name of Texas Instruments Incorporated nor the names of
  25. * its contributors may be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  31. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  35. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  36. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. */
  41. #ifndef __CPPI41DMA_H
  42. #define __CPPI41DMA_H
  43. #ifdef __cplusplus
  44. extern "C"
  45. {
  46. #endif
  47. #include "usb.h"
  48. #include "hw_usb.h"
  49. #ifndef NULL
  50. #define NULL ((void *)0)
  51. #endif
  52. #define USB_TX_MODE_SHIFT(n) (((((n) - 1) << 1) * 2))
  53. #define USB_RX_MODE_SHIFT(n) ((((((n) - 1) << 1) * 2) + 16))
  54. #if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
  55. #define USB_OTGBASE USBSS_BASE
  56. //Interrupt status macros
  57. #define CPDMA_TX_PENDING 0x60000000
  58. #define CPDMA_RX_PENDING 0x00006000
  59. #define NUMOF_USB_INSTANCE 2
  60. #else
  61. #define USB_OTGBASE USB_0_OTGBASE
  62. //Interrupt status macros
  63. #define CPDMA_TX_PENDING 0x03000000
  64. #define CPDMA_RX_PENDING 0x0C000000
  65. #define NUMOF_USB_INSTANCE USB_CONTROLLER_NUM_INSTANCES
  66. #endif
  67. #define CPDMA_STAR_0_PEND 0x1
  68. #define CPDMA_STAR_1_PEND 0x2
  69. //Link RAM size
  70. #define LINK_RAM_SIZE 1024
  71. #define DESC_REGION_SIZE (1024 * 20) + SOC_CACHELINE_SIZE_MAX
  72. // Maximum packet length for GRNDS mode
  73. #define GRNDIS_MAX_PACKET_LENGTH 512 * 8
  74. #define CPDMA_NUMOF_BUFFERS 512
  75. #ifdef USB_MODE_FULLSPEED
  76. #define USB_PACKET_LENGTH 64
  77. #else
  78. #define USB_PACKET_LENGTH 512
  79. #endif /* USB_MODE_FULLSPEED */
  80. #define QUEUE_MGR_DESCSIZE 0x100
  81. #define QUEUE_MGR_REGSIZE 0x3
  82. //Maximum number of data endpoints in one USB Intance
  83. #define MAX_NUM_EP 15
  84. #define MAX_BD_NUM 512
  85. #define NUM_OF_RX_BDs 20
  86. #define BYTE_ALIGNMENT SOC_CACHELINE_SIZE_MAX
  87. #define SCHEDULER_ENABLE_SHFT 31
  88. #define CLAER_INTDO_STATUS 0x03
  89. #define SIZE_OF_SINGLE_BD 0X0A
  90. #define CPDMA_BUFFER_NOT_USED 0
  91. #define CPDMA_BUFFER_USED 1
  92. #define CPDMA_BD_PACKET_TYPE 16
  93. #define SOP 1
  94. #define MOP 2
  95. #define EOP 4
  96. #define DMA_TX_IN_PROGRESS 1
  97. #define DMA_TX_COMPLETED 0
  98. #if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
  99. //DMA registers
  100. #define CPDMA_TX_CHANNEL_CONFIG_REG 0x2800
  101. #define CPDMA_RX_CHANNEL_CONFIG_REG 0x2808
  102. #define CPDMA_RX_CHANNEL_REG_A 0x280C
  103. #define CPDMA_RX_CHANNEL_REG_B 0x2810
  104. #define CPDMA_SCHED_CONTROL_REG 0x3000
  105. #define CPDMA_SCHED_TABLE_0 0x3800
  106. #define CPDMA_SCHED_TABLE_1 0x3804
  107. #define CPDMA_SCHED_TABLE_2 0x3808
  108. #define CPDMA_SCHED_TABLE_3 0x380C
  109. #define NUM_OF_SCHEDULER_ENTRIES 16
  110. #else
  111. //DMA registers
  112. #define CPDMA_TX_CHANNEL_CONFIG_REG 0x1800
  113. #define CPDMA_RX_CHANNEL_CONFIG_REG 0x1808
  114. #define CPDMA_RX_CHANNEL_REG_A 0x180C
  115. #define CPDMA_RX_CHANNEL_REG_B 0x1810
  116. #define CPDMA_SCHED_CONTROL_REG 0x2000
  117. #define CPDMA_SCHED_TABLE_0 0x2800
  118. #define CPDMA_SCHED_TABLE_1 0x2804
  119. #define NUM_OF_SCHEDULER_ENTRIES 8
  120. #endif
  121. #define CPDMA_INTD_0_REGISTER 0x3200
  122. #define CPDMA_CLEAR_INTD_0_STATUS 0x3280
  123. #define CPDMA_LRAM_0_BASE 0x4080
  124. #define CPDMA_LRAM_0_SIZE 0x4084
  125. #define CPDMA_LRAM_1_BASE 0x4088
  126. #define CPDMA_PEND_0_REGISTER 0x4090
  127. #define CPDMA_PEND_1_REGISTER 0x4094
  128. #define CPDMA_PEND_2_REGISTER 0x4098
  129. #define CPDMA_PEND_3_REGISTER 0x409C
  130. #define CPDMA_PEND_4_REGISTER 0x40A0
  131. #define CPDMA_QUEUEMGR_REGION_0 0x5000
  132. #define CPDMA_QUEUEMGR_REGION_0_CONTROL 0x5004
  133. #define CPDMA_QUEUE_REGISTER_D 0x600C
  134. //Bit Fields for Channel Config
  135. #define SCHEDULE_RX_CHANNEL 0x83828180
  136. #define SCHEDULE_TX_CHANNEL 0x03020100
  137. #define SCHEDULE_RX1_CHANNEL 0x9291908F
  138. #define SCHEDULE_TX1_CHANNEL 0x1211100F
  139. #define CPDMA_RX_CHANNEL_ENABLE 0x81004000
  140. #define CPDMA_TX_CHANNEL_ENABLE 0x80000000
  141. //Clear Auto set for TX endpoint
  142. #define CPDMA_TX_CLR_AUTO_SET 0x7FFF
  143. // Set DMAReqEnab & DMAReqMode for TX
  144. #define CPDMA_TX_SET_REQ_ENABLE 0x1400
  145. // Clear AUTOCLEAR and DMAReqMode
  146. #define CPDMA_RX_CLR_AUTO_CLEAR 0x77FF
  147. // Set DMAReqEnab
  148. #define CPDMA_RX_SET_REQ_ENABLE 0x2000
  149. // Clear DMAReqEnab & DMAReqMode
  150. #define CPDMA_RX_CLR_REQ_ENABLE 0xDFFF
  151. // Clear DMAReqEnab & DMAReqMode
  152. #define CPDMA_TX_CLR_REQ_ENABLE 0xEBFF
  153. // Bit fields for Schduler controll reg
  154. #define ENABLE_CPPIDMA 0x1
  155. #define DISABLE_CPPIDMA 0x0
  156. //DMA directions
  157. #define CPDMA_DIR_RX 0x1
  158. #define CPDMA_DIR_TX 0x0
  159. //Bit Fields to set the DMA Mode
  160. #define CPDMA_MODE_ENABLE_GLOBAL_RNDIS 0x00000010
  161. //DMA mode
  162. #define CPDMA_MODE_SET_TRANSPARENT 0x0
  163. #define CPDMA_MODE_SET_RNDIS 0x1
  164. #define CPDMA_MODE_SET_LINUXCDC 0x2
  165. #define CPDMA_MODE_SET_GRNDIS 0x3
  166. #if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
  167. #define NUM_TX_SUBMITQ 60
  168. #define NUM_TX_COMPQ 30
  169. #define NUM_RX_COMPQ 30
  170. //TX submit q
  171. #define TX_SUBMITQ1 32
  172. #define TX_SUBMITQ2 33
  173. #define TX_SUBMITQ3 34
  174. #define TX_SUBMITQ4 35
  175. #define TX_SUBMITQ5 36
  176. #define TX_SUBMITQ6 37
  177. #define TX_SUBMITQ7 38
  178. #define TX_SUBMITQ8 39
  179. #define TX_SUBMITQ9 40
  180. #define TX_SUBMITQ10 41
  181. #define TX_SUBMITQ11 42
  182. #define TX_SUBMITQ12 43
  183. #define TX_SUBMITQ13 44
  184. #define TX_SUBMITQ14 45
  185. #define TX_SUBMITQ15 46
  186. #define TX_SUBMITQ16 47
  187. #define TX_SUBMITQ17 48
  188. #define TX_SUBMITQ18 49
  189. #define TX_SUBMITQ19 50
  190. #define TX_SUBMITQ20 51
  191. #define TX_SUBMITQ21 52
  192. #define TX_SUBMITQ22 53
  193. #define TX_SUBMITQ23 54
  194. #define TX_SUBMITQ24 55
  195. #define TX_SUBMITQ25 56
  196. #define TX_SUBMITQ26 57
  197. #define TX_SUBMITQ27 58
  198. #define TX_SUBMITQ28 59
  199. #define TX_SUBMITQ29 60
  200. #define TX_SUBMITQ30 61
  201. //TX Completion queue
  202. #define TX_COMPQ1 93
  203. #define TX_COMPQ2 94
  204. #define TX_COMPQ3 95
  205. #define TX_COMPQ4 96
  206. #define TX_COMPQ5 97
  207. #define TX_COMPQ6 98
  208. #define TX_COMPQ7 99
  209. #define TX_COMPQ8 100
  210. #define TX_COMPQ9 101
  211. #define TX_COMPQ10 102
  212. #define TX_COMPQ11 103
  213. #define TX_COMPQ12 104
  214. #define TX_COMPQ13 105
  215. #define TX_COMPQ14 106
  216. #define TX_COMPQ15 107
  217. #define TX_COMPQ16 125
  218. //RX Completion queue
  219. #define RX_COMPQ1 109
  220. #define RX_COMPQ2 110
  221. #define RX_COMPQ3 111
  222. #define RX_COMPQ4 112
  223. #define RX_COMPQ5 113
  224. #define RX_COMPQ6 114
  225. #define RX_COMPQ7 115
  226. #define RX_COMPQ8 116
  227. #define RX_COMPQ9 117
  228. #define RX_COMPQ10 118
  229. #define RX_COMPQ11 119
  230. #define RX_COMPQ12 120
  231. #define RX_COMPQ13 121
  232. #define RX_COMPQ14 122
  233. #define RX_COMPQ15 123
  234. #define RX_COMPQ16 141
  235. #else
  236. #define NUM_TX_SUBMITQ 8
  237. #define NUM_TX_COMPQ 4
  238. #define NUM_RX_COMPQ 4
  239. //TX submit q
  240. #define TX_SUBMITQ1 16
  241. #define TX_SUBMITQ2 17
  242. #define TX_SUBMITQ3 18
  243. #define TX_SUBMITQ4 19
  244. #define TX_SUBMITQ5 20
  245. #define TX_SUBMITQ6 21
  246. #define TX_SUBMITQ7 22
  247. #define TX_SUBMITQ8 23
  248. //TX Completion queue
  249. #define TX_COMPQ1 24
  250. #define TX_COMPQ2 25
  251. //RX Completion queue
  252. #define RX_COMPQ1 26
  253. #define RX_COMPQ2 27
  254. #endif
  255. //BD-PD structure
  256. typedef struct {
  257. unsigned int pktLength:22;
  258. unsigned int protSize:5;
  259. unsigned int hostPktType:5; // This should be 16
  260. }hPDWord0;
  261. typedef struct {
  262. unsigned int dstTag:16; //bits[15:0] always Zero
  263. unsigned int srcSubChNum:5; //bits[20:16] always Zero
  264. unsigned int srcChNum:6; //bits[26:21]
  265. unsigned int srcPrtNum:5; //bits[31:27]
  266. }hPDWord1;
  267. typedef struct {
  268. unsigned int pktRetQueue:12; //bits[11:0]
  269. unsigned int pktRetQM:2; //bits[13:12]
  270. unsigned int onChip:1; //bit[14]
  271. unsigned int retPolicy:1; //bit[15]
  272. unsigned int protoSpecific:4; //bits[19:16]
  273. unsigned int rsv:6; //bits[25:20]
  274. unsigned int pktType:5; //bits[30:26]
  275. unsigned int pktErr:1; //bit[31]
  276. }hPDWord2;
  277. typedef struct hostPacketDesc {
  278. hPDWord0 hPDword0;
  279. hPDWord1 hPDword1;
  280. hPDWord2 hPDword2;
  281. unsigned int buffLength;
  282. unsigned int buffAdd;
  283. struct hostPacketDesc *nextHBDptr;
  284. unsigned int gBuffLength;
  285. unsigned int gBuffAdd;
  286. unsigned char packetId;
  287. unsigned short endPoint;
  288. unsigned short channel;
  289. unsigned char devInst;
  290. void * reqContext;
  291. unsigned char reserved[18];
  292. } hostPacketDesc ;
  293. // End point info structure for the application
  294. typedef struct
  295. {
  296. unsigned int endPoint;
  297. unsigned short direction;
  298. unsigned short dmaMode;
  299. }endpointInfo;
  300. //End point inf for internal USB configuration.
  301. typedef struct
  302. {
  303. unsigned int submitq;
  304. unsigned int complettionq;
  305. unsigned short channel;
  306. unsigned short mode;
  307. }configEndPointInfo;
  308. typedef struct
  309. {
  310. unsigned int usbBaseAddress;
  311. unsigned int otgBaseAddress;
  312. configEndPointInfo rxEndPoint[NUM_USB_EP/2];
  313. configEndPointInfo txEndPoint[NUM_USB_EP/2];
  314. }usbInstance;
  315. typedef struct
  316. {
  317. //TX submit queues
  318. unsigned int txSubmitq[NUM_TX_SUBMITQ/2][2];
  319. //TX Completion queues
  320. unsigned int txCompletionq[NUM_TX_COMPQ];
  321. //RX Completion queues
  322. unsigned int rxCompletionq[NUM_RX_COMPQ];
  323. //Pointers for BD Management
  324. hostPacketDesc *tail_bd ;
  325. hostPacketDesc *head_bd;
  326. unsigned int *region0DescriptorAddress;
  327. //Array of USB Instances
  328. usbInstance usbInst[NUMOF_USB_INSTANCE];
  329. }cppi41DmaInfo;
  330. extern endpointInfo epInfo[];
  331. void Cppi41DmaInit(unsigned short usbDevInst, endpointInfo *epInfo, unsigned short numOfEndPoints);
  332. unsigned int dmaTxCompletion(unsigned short usbDevInst, unsigned int ulEndpoint);
  333. unsigned int dmaRxCompletion(unsigned short usbDevInst, unsigned int ulEndpoint);
  334. void doDmaTxTransfer(unsigned short usbDevInst, unsigned char *buff,
  335. unsigned int length, unsigned int endPoint);
  336. void doDmaRxTransfer(unsigned short usbDevInst, unsigned int length,
  337. unsigned char *buff, unsigned int endPoint);
  338. void enableCoreTxDMA(unsigned short usbDevInst, unsigned int ulEndpoint);
  339. void enableCoreRxDMA(unsigned short usbDevInst, unsigned int ulEndpoint);
  340. void disableCoreRxDMA(unsigned short usbDevIns, unsigned int ulEndpoint);
  341. void disableCoreTxDMA(unsigned short usbDevIns, unsigned int ulEndpoint);
  342. unsigned int CppiDmaGetPendStatus(unsigned short usbDevInst);
  343. unsigned int CppiDmaGetINTD0Status(unsigned short usbDevInst);
  344. unsigned int * cppiDmaAllocBuffer();
  345. void cppiDmaFreeBuffer(unsigned int *dataBuffer);
  346. unsigned int * cppiDmaAllocnBuffer(unsigned int numOfBlocks);
  347. void cppiDmaFreenBuffer(unsigned int *dataBuffer);
  348. void cppiDmaHandleError(unsigned int usbDevInst);
  349. #ifdef __cplusplus
  350. }
  351. #endif
  352. #endif