2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 /************************************************************************/
36 /* Copyright (c) 2013 Qualcomm Atheros, All Rights Reserved. */
38 /* Module Name : desc.c */
41 /* This module contains DMA descriptors handle functions. */
45 /* zfDmaInitDescriptor */
47 /* zfDmaReclaimPacket */
53 /************************************************************************/
56 //#include "gv_extr.h"
58 //#include "uart_extr.h"
60 //#include <HIF_api.h>
61 //#include "HIF_usb.h"
62 #include <Magpie_api.h>
63 #include <vdesc_api.h>
66 /* Function prototypes */
67 //void zfDmaInitDescriptor(void);
68 struct zsDmaDesc* zfDmaGetPacket(struct zsDmaQueue* q);
69 void zfDmaReclaimPacket(struct zsDmaQueue* q, struct zsDmaDesc* desc);
70 void zfDmaPutPacket(struct zsDmaQueue* q, struct zsDmaDesc* desc);
72 /************************************************************************/
74 /* FUNCTION DESCRIPTION zfDmaGetPacket */
75 /* Get a completed packet with # descriptors. Return the first */
76 /* descriptor and pointer the head directly by lastAddr->nextAddr */
81 /* struct zsDmaQueue* q */
84 /* struct zsDmaDesc* desc */
87 /* Stephen Chen ZyDAS Communication Corporation 2005.10 */
91 /************************************************************************/
92 struct zsDmaDesc* zfDmaGetPacket(struct zsDmaQueue* q)
94 struct zsDmaDesc* desc = NULL;
96 if(q->head == q->terminator)
99 if (((q->head->status & ZM_OWN_BITS_MASK) == ZM_OWN_BITS_SW)
100 || ((q->head->status & ZM_OWN_BITS_MASK) == ZM_OWN_BITS_SE))
102 //if ( (((q->head->status & ZM_OWN_BITS_MASK) == ZM_OWN_BITS_SW) && ((u32_t)q != (u32_t)&zgDnQ))
103 // || (((q->head->status & ZM_OWN_BITS_MASK) == ZM_OWN_BITS_SE) && ((u32_t)q == (u32_t)&zgDnQ)) )
108 q->head = desc->lastAddr->nextAddr;
113 /************************************************************************/
115 /* FUNCTION DESCRIPTION zfDmaReclaimPacket */
116 /* Free descriptor. */
117 /* Exchange the terminator and the first descriptor of the packet */
118 /* for hardware ascy... . */
120 /* ROUTINES CALLED */
123 /* struct zsDmaQueue* q */
124 /* struct zsDmaDesc* desc */
129 /* Stephen Chen ZyDAS Communication Corporation 2005.10 */
133 /************************************************************************/
134 void zfDmaReclaimPacket(struct zsDmaQueue* q, struct zsDmaDesc* desc)
136 struct zsDmaDesc* tmpDesc;
137 struct zsDmaDesc tdesc;
143 /* 1. Set OWN bit to 1 for all TDs to be added, clear ctrl and size */
147 tmpDesc->status = ZM_OWN_BITS_HW;
149 tmpDesc->totalLen = 0;
151 #if ZM_FM_LOOPBACK == 1
152 vdesc = VDESC_HW_TO_VDESC(tmpDesc);
153 tmpDesc->dataSize = vdesc->buf_size;
156 //A_PRINTF("tmpDesc->dataSize = %d\n", (u32_t)tmpDesc->dataSize);
158 /* TODO : Exception handle */
159 if (desc->lastAddr == tmpDesc)
163 tmpDesc = tmpDesc->nextAddr;
166 /* 3. Next address of Last TD to be added = first TD */
167 desc->lastAddr->nextAddr = desc;
169 /* 2. Copy first TD to be added to TTD */
170 //zfMemoryCopyInWord(&tdesc, desc, sizeof(struct zsDmaDesc));
171 A_MEMCPY(&tdesc, desc, sizeof(struct zsDmaDesc));
173 /* 4. set first TD OWN bit to 0 */
174 desc->status &= (~ZM_OWN_BITS_MASK);
176 /* 5. Copy TTD to last TD */
177 tdesc.status &= (~ZM_OWN_BITS_MASK);
179 vdesc = VDESC_HW_TO_VDESC(desc);
180 vtermdesc = VDESC_HW_TO_VDESC(q->terminator);
182 VDESC_swap_vdesc(vtermdesc, vdesc);
184 //zfMemoryCopyInWord((void*)q->terminator, (void*)&tdesc, sizeof(struct zsDmaDesc));
185 A_MEMCPY((void*)q->terminator, (void*)&tdesc, sizeof(struct zsDmaDesc));
187 //desc->dataSize = 0;
188 //desc->dataAddr = 0;
189 q->terminator->status |= ZM_OWN_BITS_HW;
191 /* Update terminator pointer */
192 q->terminator = desc;
195 /************************************************************************/
197 /* FUNCTION DESCRIPTION zfDmaPutPacket */
198 /* Put a complete packet into the tail of the Queue q. */
199 /* Exchange the terminator and the first descriptor of the packet */
200 /* for hardware ascy... . */
202 /* ROUTINES CALLED */
205 /* struct zsDmaQueue* q */
206 /* struct zsDmaDesc* desc */
211 /* Stephen Chen ZyDAS Communication Corporation 2005.10 */
215 /************************************************************************/
216 void zfDmaPutPacket(struct zsDmaQueue* q, struct zsDmaDesc* desc)
218 struct zsDmaDesc* tmpDesc;
219 struct zsDmaDesc tdesc;
225 /* 1. Set OWN bit to 1 for all TDs to be added */
230 ((tmpDesc->status & (~ZM_OWN_BITS_MASK)) | ZM_OWN_BITS_HW);
231 /* TODO : Exception handle */
233 if (desc->lastAddr == tmpDesc)
237 tmpDesc = tmpDesc->nextAddr;
240 /* 3. Next address of Last TD to be added = first TD */
241 desc->lastAddr->nextAddr = desc;
243 /* If there is only one descriptor, update pointer of last descriptor */
244 if (desc->lastAddr == desc)
246 desc->lastAddr = q->terminator;
249 /* 2. Copy first TD to be added to TTD */
250 A_MEMCPY(&tdesc, desc, sizeof(struct zsDmaDesc));
251 //tdesc.dataSize = 0;
252 //tdesc.dataAddr = 0;
254 /* 4. set first TD OWN bit to 0 */
255 desc->status &= (~ZM_OWN_BITS_MASK);
257 /* 5. Copy TTD to last TD */
258 tdesc.status &= (~ZM_OWN_BITS_MASK);
260 vdesc = VDESC_HW_TO_VDESC(desc);
261 vtermdesc = VDESC_HW_TO_VDESC(q->terminator);
263 VDESC_swap_vdesc(vtermdesc, vdesc);
265 A_MEMCPY((void*)q->terminator, (void*)&tdesc, sizeof(struct zsDmaDesc));
266 q->terminator->status |= ZM_OWN_BITS_HW;
267 /* Update terminator pointer */
268 q->terminator = desc;