Exemplo n.º 1
0
int ar6000_htc_raw_open(AR_SOFTC_T *ar)
{
    A_STATUS status;
    int streamID, endPt, count2;
    raw_htc_buffer *buffer;
    HTC_SERVICE_ID servicepriority;
    AR_RAW_HTC_T *arRaw = ar->arRawHtc;
    if (!arRaw) {
        arRaw = ar->arRawHtc = A_MALLOC(sizeof(AR_RAW_HTC_T));
        if (arRaw) {
            A_MEMZERO(arRaw, sizeof(AR_RAW_HTC_T));
        }
    }
    A_ASSERT(ar->arHtcTarget != NULL);
    if (!arRaw) {
        AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Faile to allocate memory for HTC RAW interface\n"));
        return -ENOMEM;
    }
    /* wait for target */
    status = HTCWaitTarget(ar->arHtcTarget);

    if (A_FAILED(status)) {
        AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HTCWaitTarget failed (%d)\n", status));
        return -ENODEV;
    }

    for (endPt = 0; endPt < ENDPOINT_MAX; endPt++) {
        arRaw->arEp2RawMapping[endPt] = HTC_RAW_STREAM_NOT_MAPPED;
    }

    for (streamID = HTC_RAW_STREAM_0; streamID < HTC_RAW_STREAM_NUM_MAX; streamID++) {
        /* Initialize the data structures */
        init_MUTEX(&arRaw->raw_htc_read_sem[streamID]);
        init_MUTEX(&arRaw->raw_htc_write_sem[streamID]);
        init_waitqueue_head(&arRaw->raw_htc_read_queue[streamID]);
        init_waitqueue_head(&arRaw->raw_htc_write_queue[streamID]);

        /* try to connect to the raw service */
        status = ar6000_connect_raw_service(ar,streamID);

        if (A_FAILED(status)) {
            break;
        }

        if (arRawStream2EndpointID(ar,streamID) == 0) {
            break;
        }

        for (count2 = 0; count2 < RAW_HTC_READ_BUFFERS_NUM; count2 ++) {
            /* Initialize the receive buffers */
            buffer = &arRaw->raw_htc_write_buffer[streamID][count2];
            memset(buffer, 0, sizeof(raw_htc_buffer));
            buffer = &arRaw->raw_htc_read_buffer[streamID][count2];
            memset(buffer, 0, sizeof(raw_htc_buffer));

            SET_HTC_PACKET_INFO_RX_REFILL(&buffer->HTCPacket,
                                          buffer,
                                          buffer->data,
                                          HTC_RAW_BUFFER_SIZE,
                                          arRawStream2EndpointID(ar,streamID));

            /* Queue buffers to HTC for receive */
            if ((status = HTCAddReceivePkt(ar->arHtcTarget, &buffer->HTCPacket)) != A_OK)
            {
                BMIInit();
                return -EIO;
            }
        }

        for (count2 = 0; count2 < RAW_HTC_WRITE_BUFFERS_NUM; count2 ++) {
            /* Initialize the receive buffers */
            buffer = &arRaw->raw_htc_write_buffer[streamID][count2];
            memset(buffer, 0, sizeof(raw_htc_buffer));
        }

        arRaw->read_buffer_available[streamID] = FALSE;
        arRaw->write_buffer_available[streamID] = TRUE;
    }

    if (A_FAILED(status)) {
        return -EIO;
    }

    AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("HTC RAW, number of streams the target supports: %d \n", streamID));

    servicepriority = HTC_RAW_STREAMS_SVC;  /* only 1 */

    /* set callbacks and priority list */
    HTCSetCreditDistribution(ar->arHtcTarget,
                             ar,
                             NULL,  /* use default */
                             NULL,  /* use default */
                             &servicepriority,
                             1);

    /* Start the HTC component */
    if ((status = HTCStart(ar->arHtcTarget)) != A_OK) {
        BMIInit();
        return -EIO;
    }

    (ar)->arRawIfInit = TRUE;

    return 0;
}
int epping_wlan_startup(struct device *parent_dev, v_VOID_t *hif_sc)
{
    int ret = 0;
    epping_context_t *pEpping_ctx = NULL;
    VosContextType *pVosContext = NULL;
    HTC_INIT_INFO  htcInfo;
    struct ol_softc *scn;
    tSirMacAddr adapter_macAddr;
    adf_os_device_t adf_ctx;

    EPPING_LOG(VOS_TRACE_LEVEL_INFO_HIGH, "%s: Enter", __func__);

    pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);

    if(pVosContext == NULL)
    {
        EPPING_LOG(VOS_TRACE_LEVEL_FATAL,
                   "%s: Failed vos_get_global_context", __func__);
        ret = -1;
        return ret;
    }

    pEpping_ctx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
    if(pEpping_ctx == NULL)
    {
        EPPING_LOG(VOS_TRACE_LEVEL_FATAL,
                   "%s: Failed to get pEpping_ctx", __func__);
        ret = -1;
        return ret;
    }
    pEpping_ctx->parent_dev = (void *)parent_dev;
    epping_get_dummy_mac_addr(adapter_macAddr);

    ((VosContextType*)pVosContext)->pHIFContext = hif_sc;

    /* store target type and target version info in hdd ctx */
    pEpping_ctx->target_type = ((struct ol_softc *)hif_sc)->target_type;

    /* Initialize the timer module */
    vos_timer_module_init();

    scn = vos_get_context(VOS_MODULE_ID_HIF, pVosContext);
    if (!scn) {
        VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
                  "%s: scn is null!", __func__);
        return -1;
    }
    scn->enableuartprint = 0;
    scn->enablefwlog     = 0;

    /* Initialize BMI and Download firmware */
    if (bmi_download_firmware(scn)) {
        VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
                  "%s: BMI failed to download target", __func__);
        BMICleanup(scn);
        return -1;
    }

    EPPING_LOG(VOS_TRACE_LEVEL_INFO_HIGH,
               "%s: bmi_download_firmware done", __func__);

    htcInfo.pContext = pVosContext->pHIFContext;
    htcInfo.TargetFailure = ol_target_failure;
    htcInfo.TargetSendSuspendComplete = epping_target_suspend_acknowledge;
    adf_ctx = vos_get_context(VOS_MODULE_ID_ADF, pVosContext);

    /* Create HTC */
    pVosContext->htc_ctx = HTCCreate(htcInfo.pContext, &htcInfo, adf_ctx);
    if (!pVosContext->htc_ctx) {
        VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
                  "%s: Failed to Create HTC", __func__);
        BMICleanup(scn);
        return -1;
    }
    pEpping_ctx->HTCHandle = vos_get_context(VOS_MODULE_ID_HTC, pVosContext);
    if (pEpping_ctx->HTCHandle == NULL) {
        EPPING_LOG(VOS_TRACE_LEVEL_FATAL,
                   "%s: HTCHandle is NULL", __func__);
        return -1;
    }
    scn->htc_handle = pEpping_ctx->HTCHandle;

    HIFClaimDevice(scn->hif_hdl, scn);

    if (bmi_done(scn)) {
        EPPING_LOG(VOS_TRACE_LEVEL_FATAL,
                   "%s: Failed to complete BMI phase", __func__);
        goto error_end;
    }
    /* start HIF */
    if (HTCWaitTarget(scn->htc_handle) != A_OK) {
        EPPING_LOG(VOS_TRACE_LEVEL_FATAL,
                   "%s: HTCWaitTarget error", __func__);
        goto error_end;
    }
    EPPING_LOG(VOS_TRACE_LEVEL_INFO_HIGH,
               "%s: HTC ready", __func__);

    ret = epping_connect_service(pEpping_ctx);
    if (ret != 0) {
        EPPING_LOG(VOS_TRACE_LEVEL_FATAL,
                   "%s: HTCWaitTargetdone", __func__);
        goto error_end;
    }
    if (HTCStart(pEpping_ctx->HTCHandle) != A_OK) {
        goto error_end;
    }
    EPPING_LOG(VOS_TRACE_LEVEL_INFO_HIGH,
               "%s: HTC started", __func__);

    /* init the tx cookie resource */
    ret = epping_cookie_init(pEpping_ctx);
    if (ret == 0) {
        pEpping_ctx->epping_adapter = epping_add_adapter(pEpping_ctx,
                                      adapter_macAddr,
                                      WLAN_HDD_INFRA_STATION);
    }
    if (ret < 0 || pEpping_ctx->epping_adapter == NULL) {
        EPPING_LOG(VOS_TRACE_LEVEL_FATAL,
                   "%s: epping_add_adaptererror error", __func__);
        HTCStop(pEpping_ctx->HTCHandle);
        epping_cookie_cleanup(pEpping_ctx);
        goto error_end;
    }
#ifdef HIF_PCI
    {
        int i;
        for (i = 0; i < EPPING_MAX_NUM_EPIDS; i++) {
            epping_register_tx_copier(i, pEpping_ctx);
        }
    }
#endif /* HIF_PCI */
    EPPING_LOG(VOS_TRACE_LEVEL_INFO_HIGH, "%s: Exit", __func__);
    complete(&pEpping_ctx->wlan_start_comp);
    return ret;

error_end:
    HTCDestroy(pVosContext->htc_ctx);
    pVosContext->htc_ctx = NULL;
    BMICleanup(scn);
    return -1;
}