/* Makes a buffer available to the HTC module */ A_STATUS HTCAddReceivePkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket) { HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); HTC_ENDPOINT *pEndpoint; A_BOOL unblockRecv = FALSE; A_STATUS status = A_OK; AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+- HTCAddReceivePkt: endPointId: %d, buffer: 0x%X, length: %d\n", pPacket->Endpoint, (A_UINT32)pPacket->pBuffer, pPacket->BufferLength)); do { AR_DEBUG_ASSERT(pPacket->Endpoint < ENDPOINT_MAX); pEndpoint = &target->EndPoint[pPacket->Endpoint]; LOCK_HTC_RX(target); if (HTC_STOPPING(target)) { pPacket->Status = A_ECANCELED; status = A_ECANCELED; UNLOCK_HTC_RX(target); pEndpoint->EpCallBacks.EpRecv(pEndpoint->EpCallBacks.pContext, pPacket); break; } /* store receive packet */ HTC_PACKET_ENQUEUE(&pEndpoint->RxBuffers, pPacket); /* check if we are blocked waiting for a new buffer */ if (target->HTCStateFlags & HTC_STATE_WAIT_BUFFERS) { if (target->EpWaitingForBuffers == pPacket->Endpoint) { AR_DEBUG_PRINTF(ATH_DEBUG_RECV,(" receiver was blocked on ep:%d, unblocking.. \n", target->EpWaitingForBuffers)); target->HTCStateFlags &= ~HTC_STATE_WAIT_BUFFERS; target->EpWaitingForBuffers = ENDPOINT_MAX; unblockRecv = TRUE; } } UNLOCK_HTC_RX(target); if (unblockRecv && !HTC_STOPPING(target)) { /* TODO : implement a buffer threshold count? */ DevEnableRecv(&target->Device,DEV_ENABLE_RECV_SYNC); } } while (FALSE); return status; }
void HTCDisableRecv(HTC_HANDLE HTCHandle) { HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); if (!HTC_STOPPING(target)) { /* disable */ DevStopRecv(&target->Device,DEV_ENABLE_RECV_SYNC); } }
A_STATUS HTCAddReceivePktMultiple(HTC_HANDLE HTCHandle, HTC_PACKET_QUEUE *pPktQueue) { HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); HTC_ENDPOINT *pEndpoint; HTC_PACKET *pFirstPacket; A_STATUS status = A_OK; HTC_PACKET *pPacket; pFirstPacket = HTC_GET_PKT_AT_HEAD(pPktQueue); if (NULL == pFirstPacket) { A_ASSERT(FALSE); return A_EINVAL; } AR_DEBUG_ASSERT(pFirstPacket->Endpoint < ENDPOINT_MAX); AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("+- HTCAddReceivePktMultiple : endPointId: %d, cnt:%d, length: %d\n", pFirstPacket->Endpoint, HTC_PACKET_QUEUE_DEPTH(pPktQueue), pFirstPacket->BufferLength)); pEndpoint = &target->EndPoint[pFirstPacket->Endpoint]; LOCK_HTC_RX(target); do { if (HTC_STOPPING(target)) { status = A_ERROR; break; } /* store receive packets */ HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->RxBufferHoldQueue,pPktQueue); } while (FALSE); UNLOCK_HTC_RX(target); if (A_FAILED(status)) { /* walk through queue and mark each one canceled */ HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue,pPacket) { pPacket->Status = A_ECANCELED; } HTC_PACKET_QUEUE_ITERATE_END; DoRecvCompletion(pEndpoint,pPktQueue); } return status; }
void HTCUnblockRecv(HTC_HANDLE HTCHandle) { HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); A_BOOL unblockRecv = FALSE; LOCK_HTC_RX(target); /* check if we are blocked waiting for a new buffer */ if (target->HTCStateFlags & HTC_STATE_WAIT_BUFFERS) { AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("HTCUnblockRx : receiver was blocked on ep:%d, unblocking.. \n", target->EpWaitingForBuffers)); target->HTCStateFlags &= ~HTC_STATE_WAIT_BUFFERS; target->EpWaitingForBuffers = ENDPOINT_MAX; unblockRecv = TRUE; } UNLOCK_HTC_RX(target); if (unblockRecv && !HTC_STOPPING(target)) { /* re-enable */ DevEnableRecv(&target->Device,DEV_ENABLE_RECV_ASYNC); } }
/* callback when device layer or lookahead report parsing detects a pending message */ A_STATUS HTCRecvMessagePendingHandler(void *Context, A_UINT32 *LookAhead, A_BOOL *pAsyncProc) { HTC_TARGET *target = (HTC_TARGET *)Context; A_STATUS status = A_OK; HTC_PACKET *pPacket = NULL; HTC_FRAME_HDR *pHdr = NULL; HTC_ENDPOINT *pEndpoint = NULL; A_BOOL asyncProc = FALSE; AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HTCRecvMessagePendingHandler LookAhead:0x%X \n", *LookAhead)); if (IS_DEV_IRQ_PROCESSING_ASYNC_ALLOWED(&target->Device)) { /* We use async mode to get the packets if the device layer supports it. * The device layer interfaces with HIF in which HIF may have restrictions on * how interrupts are processed */ asyncProc = TRUE; } if (pAsyncProc != NULL) { /* indicate to caller how we decided to process this */ *pAsyncProc = asyncProc; } while (TRUE) { pHdr = (HTC_FRAME_HDR *)LookAhead; if (pHdr->EndpointID >= ENDPOINT_MAX) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Endpoint in look-ahead: %d \n",pHdr->EndpointID)); /* invalid endpoint */ status = A_EPROTO; break; } if (pHdr->PayloadLen > HTC_MAX_PAYLOAD_LENGTH) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Payload length %d exceeds max HTC : %d !\n", pHdr->PayloadLen, HTC_MAX_PAYLOAD_LENGTH)); status = A_EPROTO; break; } pEndpoint = &target->EndPoint[pHdr->EndpointID]; if (0 == pEndpoint->ServiceID) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Endpoint %d is not connected !\n",pHdr->EndpointID)); /* endpoint isn't even connected */ status = A_EPROTO; break; } if (pEndpoint->EpCallBacks.EpRecvAlloc != NULL) { /* user is using a per-packet allocation callback */ pPacket = pEndpoint->EpCallBacks.EpRecvAlloc(pEndpoint->EpCallBacks.pContext, (HTC_ENDPOINT_ID) pHdr->EndpointID, pHdr->PayloadLen + sizeof(HTC_FRAME_HDR)); /* lock RX, in case this allocation fails, we need to update internal state below */ LOCK_HTC_RX(target); } else { /* user is using a refill handler that can refill multiple HTC buffers */ /* lock RX to get a buffer */ LOCK_HTC_RX(target); /* get a packet from the endpoint recv queue */ pPacket = HTC_PACKET_DEQUEUE(&pEndpoint->RxBuffers); if (NULL == pPacket) { /* check for refill handler */ if (pEndpoint->EpCallBacks.EpRecvRefill != NULL) { UNLOCK_HTC_RX(target); /* call the re-fill handler */ pEndpoint->EpCallBacks.EpRecvRefill(pEndpoint->EpCallBacks.pContext, (HTC_ENDPOINT_ID) pHdr->EndpointID); LOCK_HTC_RX(target); /* check if we have more buffers */ pPacket = HTC_PACKET_DEQUEUE(&pEndpoint->RxBuffers); /* fall through */ } } } if (NULL == pPacket) { /* this is not an error, we simply need to mark that we are waiting for buffers.*/ target->HTCStateFlags |= HTC_STATE_WAIT_BUFFERS; target->EpWaitingForBuffers = (HTC_ENDPOINT_ID) pHdr->EndpointID; status = A_NO_MEMORY; } if (HTC_STOPPING(target)) { status = A_ECANCELED; } UNLOCK_HTC_RX(target); if (A_FAILED(status)) { /* no buffers or stopping */ break; } pPacket->PktInfo.AsRx.IndicationFlags = 0; AR_DEBUG_ASSERT(pPacket->Endpoint == pHdr->EndpointID); /* make sure this message can fit in the endpoint buffer */ if ((pHdr->PayloadLen + HTC_HDR_LENGTH) > pPacket->BufferLength) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Payload Length Error : header reports payload of: %d, endpoint buffer size: %d \n", pHdr->PayloadLen, pPacket->BufferLength)); status = A_EPROTO; break; } pPacket->HTCReserved = *LookAhead; /* set expected look ahead */ /* set the amount of data to fetch */ pPacket->ActualLength = pHdr->PayloadLen + HTC_HDR_LENGTH; if (asyncProc) { /* we use async mode to get the packet if the device layer supports it * set our callback and context */ pPacket->Completion = HTCRecvCompleteHandler; pPacket->pContext = target; } else { /* fully synchronous */ pPacket->Completion = NULL; } /* go fetch the packet */ status = HTCIssueRecv(target, pPacket); if (A_FAILED(status)) { break; } if (asyncProc) { /* we did this asynchronously so we can get out of the loop, the asynch processing * creates a chain of requests to continue processing pending messages in the * context of callbacks */ break; } /* in the sync case, we process the packet, check lookaheads and then repeat */ *LookAhead = 0; status = HTCProcessRecvHeader(target,pPacket,LookAhead); if (A_FAILED(status)) { break; } HTC_RX_STAT_PROFILE(target,pEndpoint,*LookAhead); /* check lookahead to see if we can indicate next packet hint to recv callback */ if (LookAhead != 0) { pHdr = (HTC_FRAME_HDR *)&LookAhead; /* check to see if the "next" packet is from the same endpoint of the completing packet */ if (pHdr->EndpointID == pPacket->Endpoint) { /* check that there is a buffer available to actually fetch it * NOTE: no need to lock RX here , since we are synchronously processing RX * and we are only looking at the queue (not modifying it) */ if (!HTC_QUEUE_EMPTY(&pEndpoint->RxBuffers)) { /* provide a hint that there are more RX packets to fetch */ pPacket->PktInfo.AsRx.IndicationFlags |= HTC_RX_FLAGS_INDICATE_MORE_PKTS; } } } DO_RCV_COMPLETION(target,pPacket,pEndpoint); pPacket = NULL; if (0 == *LookAhead) { break; } /* check whether other OS contexts have queued any WMI command/data for WLAN. * This check is needed only if WLAN Tx and Rx happens in same thread context */ A_CHECK_DRV_TX(); } if (A_NO_MEMORY == status) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, (" Endpoint :%d has no buffers, blocking receiver to prevent overrun.. \n", (pHdr != NULL) ? pHdr->EndpointID : 0xFFFF)); /* try to stop receive at the device layer */ DevStopRecv(&target->Device, asyncProc ? DEV_STOP_RECV_ASYNC : DEV_STOP_RECV_SYNC); status = A_OK; } else if (A_FAILED(status)) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get pending message : LookAhead Value: 0x%X (status = %d) \n", *LookAhead, status)); if (pPacket != NULL) { /* clean up packet on error */ HTC_RECYCLE_RX_PKT(target, pPacket, pEndpoint); } } AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HTCRecvMessagePendingHandler \n")); return status; }