1 /* Copyright (C) 2005-2006 by Texas Instruments */
6 #include <linux/slab.h>
7 #include <linux/list.h>
8 #include <linux/smp_lock.h>
9 #include <linux/errno.h>
10 #include <linux/dmapool.h>
13 #include "musb_core.h"
17 /* hOptions bit masks for CPPI BDs */
18 #define CPPI_SOP_SET ((u32)(1 << 31))
19 #define CPPI_EOP_SET ((u32)(1 << 30))
20 #define CPPI_OWN_SET ((u32)(1 << 29)) /* owned by cppi */
21 #define CPPI_EOQ_MASK ((u32)(1 << 28))
22 #define CPPI_ZERO_SET ((u32)(1 << 23)) /* rx saw zlp; tx issues one */
23 #define CPPI_RXABT_MASK ((u32)(1 << 19)) /* need more rx buffers */
25 #define CPPI_RECV_PKTLEN_MASK 0xFFFF
26 #define CPPI_BUFFER_LEN_MASK 0xFFFF
28 #define CPPI_TEAR_READY ((u32)(1 << 31))
30 /* CPPI data structure definitions */
32 #define CPPI_DESCRIPTOR_ALIGN 16 /* bytes; 5-dec docs say 4-byte align */
34 struct cppi_descriptor {
35 /* Hardware Overlay */
36 u32 hNext; /* Next(hardware) Buffer Descriptor Pointer */
37 u32 buffPtr; /* Buffer Pointer (dma_addr_t) */
38 u32 bOffBLen; /* Buffer_offset16,buffer_length16 */
39 u32 hOptions; /* Option fields for SOP,EOP etc*/
41 struct cppi_descriptor *next;
42 dma_addr_t dma; /* address of this descriptor */
44 /* for Rx Desc, track original Buffer len to detect short packets */
46 } __attribute__ ((aligned(CPPI_DESCRIPTOR_ALIGN)));
52 * Channel Control Structure
54 * CPPI Channel Control structure. Using he same for Tx/Rx. If need be
55 * derive out of this later.
58 /* First field must be dma_channel for easy type casting
59 * FIXME just use container_of() and be typesafe instead!
61 struct dma_channel Channel;
63 /* back pointer to the Dma Controller structure */
64 struct cppi *controller;
66 /* which direction of which endpoint? */
67 struct musb_hw_ep *hw_ep;
71 /* DMA modes: RNDIS or "transparent" */
74 /* book keeping for current transfer request */
78 u32 currOffset; /* requested segments */
79 u32 actualLen; /* completed (Channel.actual) */
81 void __iomem *stateRam; /* CPPI state */
83 /* BD management fields */
84 struct cppi_descriptor *bdPoolHead;
85 struct cppi_descriptor *activeQueueHead;
86 struct cppi_descriptor *activeQueueTail;
87 struct cppi_descriptor *lastHwBDProcessed;
89 /* use tx_complete in host role to track endpoints waiting for
90 * FIFONOTEMPTY to clear.
92 struct list_head tx_complete;
96 * CPPI Dma Controller Object
98 * CPPI Dma controller object.Encapsulates all bookeeping and Data
99 * structures pertaining to the CPPI Dma Controller.
102 struct dma_controller Controller;
104 void __iomem *pCoreBase;
106 struct cppi_channel txCppi[MUSB_C_NUM_EPT - 1];
107 struct cppi_channel rxCppi[MUSB_C_NUM_EPR - 1];
109 struct dma_pool *pool;
111 struct list_head tx_complete;
114 /* irq handling hook */
115 extern void cppi_completion(struct musb *, u32 rx, u32 tx);
117 #endif /* end of ifndef _CPPI_DMA_H_ */