void HTCFwEventHandler(void *context) { HTC_TARGET *target = (HTC_TARGET *)context; HTC_INIT_INFO *initInfo = &target->HTCInitInfo; /* * Currently, there's only one event type (Target Failure); * there's no need to discriminate between event types. */ if (target->HTCInitInfo.TargetFailure != NULL) { initInfo->TargetFailure(initInfo->pContext, A_ERROR); } }
/* registered removal callback from the HIF layer */ static A_STATUS HTCTargetRemovedHandler(void *handle, A_STATUS status) { HTC_TARGET *target; AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+HTCTargetRemovedHandler handle:0x%X \n",(A_UINT32)handle)); if (NULL == handle) { /* this could be NULL in the event that target initialization failed */ return A_OK; } target = ((AR6K_DEVICE *)handle)->HTCContext; AR_DEBUG_PRINTF(ATH_DEBUG_TRC, (" removing target:0x%X instance:0x%X ... \n", (A_UINT32)target, (A_UINT32)target->pInstanceContext)); if (target->pInstanceContext != NULL) { /* let upper layer know, it needs to call HTCStop() */ HTCInitInfo.DeleteInstance(target->pInstanceContext); } HIFShutDownDevice(target->Device.HIFDevice); HTCCleanup(target); AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-HTCTargetRemovedHandler \n")); return A_OK; }
/* report a target failure from the device, this is a callback from the device layer * which uses a mechanism to report errors from the target (i.e. special interrupts) */ static void HTCReportFailure(void *Context) { HTC_TARGET *target = (HTC_TARGET *)Context; target->TargetFailure = TRUE; if ((target->pInstanceContext != NULL) && (HTCInitInfo.TargetFailure != NULL)) { /* let upper layer know, it needs to call HTCStop() */ HTCInitInfo.TargetFailure(target->pInstanceContext, A_ERROR); } }
/* registered target arrival callback from the HIF layer */ static A_STATUS HTCTargetInsertedHandler(void *hif_handle) { HTC_TARGET *target = NULL; A_STATUS status; int i; A_UINT32 ctrl_bufsz; A_UINT32 blocksizes[HTC_MAILBOX_NUM_MAX]; AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htcTargetInserted - Enter\n")); do { /* allocate target memory */ if ((target = (HTC_TARGET *)A_MALLOC(sizeof(HTC_TARGET))) == NULL) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to allocate memory\n")); status = A_ERROR; break; } A_MEMZERO(target, sizeof(HTC_TARGET)); A_MUTEX_INIT(&target->HTCLock); A_MUTEX_INIT(&target->HTCRxLock); A_MUTEX_INIT(&target->HTCTxLock); INIT_HTC_PACKET_QUEUE(&target->ControlBufferTXFreeList); INIT_HTC_PACKET_QUEUE(&target->ControlBufferRXFreeList); /* give device layer the hif device handle */ target->Device.HIFDevice = hif_handle; /* give the device layer our context (for event processing) * the device layer will register it's own context with HIF * so we need to set this so we can fetch it in the target remove handler */ target->Device.HTCContext = target; /* set device layer target failure callback */ target->Device.TargetFailureCallback = HTCReportFailure; /* set device layer recv message pending callback */ target->Device.MessagePendingCallback = HTCRecvMessagePendingHandler; target->EpWaitingForBuffers = ENDPOINT_MAX; /* setup device layer */ status = DevSetup(&target->Device); if (A_FAILED(status)) { break; } /* get the block sizes */ status = HIFConfigureDevice(hif_handle, HIF_DEVICE_GET_MBOX_BLOCK_SIZE, blocksizes, sizeof(blocksizes)); if (A_FAILED(status)) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to get block size info from HIF layer...\n")); break; } /* Set the control buffer size based on the block size */ if (blocksizes[1] > HTC_MAX_CONTROL_MESSAGE_LENGTH) { ctrl_bufsz = blocksizes[1] + HTC_HDR_LENGTH; } else { ctrl_bufsz = HTC_MAX_CONTROL_MESSAGE_LENGTH + HTC_HDR_LENGTH; } for (i = 0;i < NUM_CONTROL_BUFFERS;i++) { target->HTCControlBuffers[i].Buffer = A_MALLOC(ctrl_bufsz); if (target->HTCControlBuffers[i].Buffer == NULL) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to allocate memory\n")); status = A_ERROR; break; } } if (A_FAILED(status)) { break; } /* carve up buffers/packets for control messages */ for (i = 0; i < NUM_CONTROL_RX_BUFFERS; i++) { HTC_PACKET *pControlPacket; pControlPacket = &target->HTCControlBuffers[i].HtcPacket; SET_HTC_PACKET_INFO_RX_REFILL(pControlPacket, target, target->HTCControlBuffers[i].Buffer, ctrl_bufsz, ENDPOINT_0); HTC_FREE_CONTROL_RX(target,pControlPacket); } for (;i < NUM_CONTROL_BUFFERS;i++) { HTC_PACKET *pControlPacket; pControlPacket = &target->HTCControlBuffers[i].HtcPacket; INIT_HTC_PACKET_INFO(pControlPacket, target->HTCControlBuffers[i].Buffer, ctrl_bufsz); HTC_FREE_CONTROL_TX(target,pControlPacket); } } while (FALSE); if (A_SUCCESS(status)) { AR_DEBUG_PRINTF(ATH_DEBUG_TRC, (" calling AddInstance callback \n")); /* announce ourselves */ HTCInitInfo.AddInstance((HTC_HANDLE)target); } else { if (target != NULL) { HTCCleanup(target); } } AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htcTargetInserted - Exit\n")); return status; }