1 /************************************************************************/
2 /* Copyright (c) 2013 Qualcomm Atheros, All Rights Reserved. */
4 /* Module Name : desc.c */
7 /* This module contains DMA descriptors handle functions. */
11 /* zfDmaInitDescriptor */
13 /* zfDmaReclaimPacket */
19 /************************************************************************/
22 //#include "gv_extr.h"
24 //#include "uart_extr.h"
26 //#include <HIF_api.h>
27 //#include "HIF_usb.h"
28 #include <Magpie_api.h>
29 #include <vdesc_api.h>
32 /* Function prototypes */
33 //void zfDmaInitDescriptor(void);
34 struct zsDmaDesc* zfDmaGetPacket(struct zsDmaQueue* q);
35 void zfDmaReclaimPacket(struct zsDmaQueue* q, struct zsDmaDesc* desc);
36 void zfDmaPutPacket(struct zsDmaQueue* q, struct zsDmaDesc* desc);
38 /************************************************************************/
40 /* FUNCTION DESCRIPTION zfDmaGetPacket */
41 /* Get a completed packet with # descriptors. Return the first */
42 /* descriptor and pointer the head directly by lastAddr->nextAddr */
47 /* struct zsDmaQueue* q */
50 /* struct zsDmaDesc* desc */
53 /* Stephen Chen ZyDAS Communication Corporation 2005.10 */
57 /************************************************************************/
58 struct zsDmaDesc* zfDmaGetPacket(struct zsDmaQueue* q)
60 struct zsDmaDesc* desc = NULL;
62 if(q->head == q->terminator)
65 if (((q->head->status & ZM_OWN_BITS_MASK) == ZM_OWN_BITS_SW)
66 || ((q->head->status & ZM_OWN_BITS_MASK) == ZM_OWN_BITS_SE))
68 //if ( (((q->head->status & ZM_OWN_BITS_MASK) == ZM_OWN_BITS_SW) && ((u32_t)q != (u32_t)&zgDnQ))
69 // || (((q->head->status & ZM_OWN_BITS_MASK) == ZM_OWN_BITS_SE) && ((u32_t)q == (u32_t)&zgDnQ)) )
74 q->head = desc->lastAddr->nextAddr;
79 /************************************************************************/
81 /* FUNCTION DESCRIPTION zfDmaReclaimPacket */
82 /* Free descriptor. */
83 /* Exchange the terminator and the first descriptor of the packet */
84 /* for hardware ascy... . */
89 /* struct zsDmaQueue* q */
90 /* struct zsDmaDesc* desc */
95 /* Stephen Chen ZyDAS Communication Corporation 2005.10 */
99 /************************************************************************/
100 void zfDmaReclaimPacket(struct zsDmaQueue* q, struct zsDmaDesc* desc)
102 struct zsDmaDesc* tmpDesc;
103 struct zsDmaDesc tdesc;
109 /* 1. Set OWN bit to 1 for all TDs to be added, clear ctrl and size */
113 tmpDesc->status = ZM_OWN_BITS_HW;
115 tmpDesc->totalLen = 0;
117 #if ZM_FM_LOOPBACK == 1
118 vdesc = VDESC_HW_TO_VDESC(tmpDesc);
119 tmpDesc->dataSize = vdesc->buf_size;
122 //A_PRINTF("tmpDesc->dataSize = %d\n", (u32_t)tmpDesc->dataSize);
124 /* TODO : Exception handle */
125 if (desc->lastAddr == tmpDesc)
129 tmpDesc = tmpDesc->nextAddr;
132 /* 3. Next address of Last TD to be added = first TD */
133 desc->lastAddr->nextAddr = desc;
135 /* 2. Copy first TD to be added to TTD */
136 //zfMemoryCopyInWord(&tdesc, desc, sizeof(struct zsDmaDesc));
137 A_MEMCPY(&tdesc, desc, sizeof(struct zsDmaDesc));
139 /* 4. set first TD OWN bit to 0 */
140 desc->status &= (~ZM_OWN_BITS_MASK);
142 /* 5. Copy TTD to last TD */
143 tdesc.status &= (~ZM_OWN_BITS_MASK);
145 vdesc = VDESC_HW_TO_VDESC(desc);
146 vtermdesc = VDESC_HW_TO_VDESC(q->terminator);
148 VDESC_swap_vdesc(vtermdesc, vdesc);
150 //zfMemoryCopyInWord((void*)q->terminator, (void*)&tdesc, sizeof(struct zsDmaDesc));
151 A_MEMCPY((void*)q->terminator, (void*)&tdesc, sizeof(struct zsDmaDesc));
153 //desc->dataSize = 0;
154 //desc->dataAddr = 0;
155 q->terminator->status |= ZM_OWN_BITS_HW;
157 /* Update terminator pointer */
158 q->terminator = desc;
161 /************************************************************************/
163 /* FUNCTION DESCRIPTION zfDmaPutPacket */
164 /* Put a complete packet into the tail of the Queue q. */
165 /* Exchange the terminator and the first descriptor of the packet */
166 /* for hardware ascy... . */
168 /* ROUTINES CALLED */
171 /* struct zsDmaQueue* q */
172 /* struct zsDmaDesc* desc */
177 /* Stephen Chen ZyDAS Communication Corporation 2005.10 */
181 /************************************************************************/
182 void zfDmaPutPacket(struct zsDmaQueue* q, struct zsDmaDesc* desc)
184 struct zsDmaDesc* tmpDesc;
185 struct zsDmaDesc tdesc;
191 /* 1. Set OWN bit to 1 for all TDs to be added */
196 ((tmpDesc->status & (~ZM_OWN_BITS_MASK)) | ZM_OWN_BITS_HW);
197 /* TODO : Exception handle */
199 if (desc->lastAddr == tmpDesc)
203 tmpDesc = tmpDesc->nextAddr;
206 /* 3. Next address of Last TD to be added = first TD */
207 desc->lastAddr->nextAddr = desc;
209 /* If there is only one descriptor, update pointer of last descriptor */
210 if (desc->lastAddr == desc)
212 desc->lastAddr = q->terminator;
215 /* 2. Copy first TD to be added to TTD */
216 A_MEMCPY(&tdesc, desc, sizeof(struct zsDmaDesc));
217 //tdesc.dataSize = 0;
218 //tdesc.dataAddr = 0;
220 /* 4. set first TD OWN bit to 0 */
221 desc->status &= (~ZM_OWN_BITS_MASK);
223 /* 5. Copy TTD to last TD */
224 tdesc.status &= (~ZM_OWN_BITS_MASK);
226 vdesc = VDESC_HW_TO_VDESC(desc);
227 vtermdesc = VDESC_HW_TO_VDESC(q->terminator);
229 VDESC_swap_vdesc(vtermdesc, vdesc);
231 A_MEMCPY((void*)q->terminator, (void*)&tdesc, sizeof(struct zsDmaDesc));
232 q->terminator->status |= ZM_OWN_BITS_HW;
233 /* Update terminator pointer */
234 q->terminator = desc;