A_STATUS BMIDone(HIF_DEVICE *device) { A_STATUS status; A_UINT32 cid; if (bmiDone) { AR_DEBUG_PRINTF (ATH_DEBUG_BMI, ("BMIDone skipped\n")); return A_OK; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Done: Enter (device: 0x%p)\n", device)); bmiDone = TRUE; cid = BMI_DONE; A_MEMCPY(pBMICmdBuf,&cid,sizeof(cid)); status = HIFExchangeBMIMsg(device, pBMICmdBuf, sizeof(cid), NULL, NULL, 0); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); return A_ERROR; } if (pBMICmdBuf) { A_FREE(pBMICmdBuf); pBMICmdBuf = NULL; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Done: Exit\n")); return A_OK; }
A_STATUS BMIDone(HIF_DEVICE *device, struct ol_ath_softc_net80211 *scn) { A_STATUS status; A_UINT32 cid; if (scn->bmiDone) { AR_DEBUG_PRINTF (ATH_DEBUG_BMI, ("BMIDone skipped\n")); return A_OK; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Done: Enter (device: 0x%p)\n", device)); #if defined(A_SIMOS_DEVHOST) /* Let HIF layer know that BMI phase is done. * Note that this call enqueues a bunch of receive buffers, * so it is important that this complete before we tell the * target about BMI_DONE. */ (void)HIFConfigureDevice(device, HIF_BMI_DONE, NULL, 0); #endif scn->bmiDone = TRUE; cid = BMI_DONE; if (!scn->pBMICmdBuf) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("pBMICmdBuf is NULL\n")); return A_ERROR; } A_MEMCPY(scn->pBMICmdBuf,&cid,sizeof(cid)); status = HIFExchangeBMIMsg(device, scn->pBMICmdBuf, sizeof(cid), NULL, NULL, 0); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); return A_ERROR; } if (scn->pBMICmdBuf) { OS_FREE_CONSISTENT(scn->sc_osdev, MAX_BMI_CMDBUF_SZ, scn->pBMICmdBuf, scn->BMICmd_pa, OS_GET_DMA_MEM_CONTEXT(scn, bmicmd_dmacontext)); scn->pBMICmdBuf = NULL; scn->BMICmd_pa = 0; } if (scn->pBMIRspBuf) { OS_FREE_CONSISTENT(scn->sc_osdev, MAX_BMI_CMDBUF_SZ, scn->pBMIRspBuf, scn->BMIRsp_pa, OS_GET_DMA_MEM_CONTEXT(scn, bmirsp_dmacontext)); scn->pBMIRspBuf = NULL; scn->BMIRsp_pa = 0; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Done: Exit\n")); return A_OK; }
A_STATUS BMIrompatchInstall(HIF_DEVICE *device, A_UINT32 ROM_addr, A_UINT32 RAM_addr, A_UINT32 nbytes, A_UINT32 do_activate, A_UINT32 *rompatch_id) { A_UINT32 cid; A_STATUS status; A_UINT32 offset,responseLen; A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(ROM_addr) + sizeof(RAM_addr) + sizeof(nbytes) + sizeof(do_activate))); memset(pBMICmdBuf, 0, sizeof(cid) + sizeof(ROM_addr) + sizeof(RAM_addr) + sizeof(nbytes) + sizeof(do_activate)); if (bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI rompatch Install: Enter (device: 0x%p, ROMaddr: 0x%x, RAMaddr: 0x%x length: %d activate: %d)\n", device, ROM_addr, RAM_addr, nbytes, do_activate)); cid = BMI_ROMPATCH_INSTALL; offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &ROM_addr, sizeof(ROM_addr)); offset += sizeof(ROM_addr); A_MEMCPY(&(pBMICmdBuf[offset]), &RAM_addr, sizeof(RAM_addr)); offset += sizeof(RAM_addr); A_MEMCPY(&(pBMICmdBuf[offset]), &nbytes, sizeof(nbytes)); offset += sizeof(nbytes); A_MEMCPY(&(pBMICmdBuf[offset]), &do_activate, sizeof(do_activate)); offset += sizeof(do_activate); responseLen = sizeof(*rompatch_id); status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, pBMICmdBuf, &responseLen, BMI_EXCHANGE_TIMEOUT_MS); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to install ROM patch\n")); return A_ERROR; } A_MEMCPY(rompatch_id, pBMICmdBuf, sizeof(*rompatch_id)); AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI rompatch Install: (rompatch_id=%d)\n", *rompatch_id)); return A_OK; }
A_STATUS BMILZData(HIF_DEVICE *device, A_UCHAR *buffer, A_UINT32 length, struct ol_ath_softc_net80211 *scn) { A_UINT32 cid; A_STATUS status; A_UINT32 offset; A_UINT32 remaining, txlen; const A_UINT32 header = sizeof(cid) + sizeof(length); A_UCHAR *pBMICmdBuf = scn->pBMICmdBuf; ASSERT(BMI_COMMAND_FITS(BMI_DATASZ_MAX+header)); memset (pBMICmdBuf, 0, BMI_DATASZ_MAX+header); if (scn->bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Send LZ Data: Enter (device: 0x%p, length: %d)\n", device, length)); cid = BMI_LZ_DATA; remaining = length; while (remaining) { txlen = (remaining < (BMI_DATASZ_MAX - header)) ? remaining : (BMI_DATASZ_MAX - header); offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &txlen, sizeof(txlen)); offset += sizeof(txlen); A_MEMCPY(&(pBMICmdBuf[offset]), &buffer[length - remaining], txlen); offset += txlen; status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); return A_ERROR; } remaining -= txlen; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI LZ Data: Exit\n")); return A_OK; }
A_STATUS BMIExecute(HIF_DEVICE *device, A_UINT32 address, A_UINT32 *param, struct ol_ath_softc_net80211 *scn) { A_UINT32 cid; A_STATUS status; A_UINT32 offset; A_UINT32 paramLen; A_UCHAR *pBMICmdBuf = scn->pBMICmdBuf; A_UCHAR *pBMIRspBuf = scn->pBMIRspBuf; ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(address) + sizeof(param))); memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(address) + sizeof(param)); memset (pBMIRspBuf, 0, sizeof(cid) + sizeof(address) + sizeof(param)); if (scn->bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Execute: Enter (device: 0x%p, address: 0x%x, param: %d)\n", device, address, *param)); cid = BMI_EXECUTE; offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); offset += sizeof(address); A_MEMCPY(&(pBMICmdBuf[offset]), param, sizeof(*param)); offset += sizeof(*param); paramLen = sizeof(*param); status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, pBMIRspBuf, ¶mLen, 0); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read from the device\n")); return A_ERROR; } A_MEMCPY(param, pBMIRspBuf, sizeof(*param)); AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Execute: Exit (param: %d)\n", *param)); return A_OK; }
A_STATUS BMIGetTargetInfo(HIF_DEVICE *device, struct bmi_target_info *targ_info, struct ol_ath_softc_net80211 *scn) { #ifndef HIF_MESSAGE_BASED #else A_STATUS status; A_UCHAR *pBMICmdBuf = scn->pBMICmdBuf; A_UCHAR *pBMIRspBuf = scn->pBMIRspBuf; #endif if (scn->bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI Get Target Info Command disallowed\n")); return A_ERROR; } #ifndef HIF_MESSAGE_BASED /* getting the target ID requires special handling because of the variable length * message */ return HIFRegBasedGetTargetInfo(device,targ_info); #else { A_UINT32 cid; A_UINT32 length; cid = BMI_GET_TARGET_INFO; A_MEMCPY(pBMICmdBuf,&cid,sizeof(cid)); length = sizeof(struct bmi_target_info); status = HIFExchangeBMIMsg(device, pBMICmdBuf, sizeof(cid), (A_UINT8 *)pBMIRspBuf, &length, BMI_EXCHANGE_TIMEOUT_MS); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to get target information from the device\n")); return A_ERROR; } A_MEMCPY(targ_info, pBMIRspBuf, length); return status; } #endif }
static A_STATUS _BMIrompatchChangeActivation(HIF_DEVICE *device, A_UINT32 rompatch_count, A_UINT32 *rompatch_list, A_UINT32 do_activate) { A_UINT32 cid; A_STATUS status; A_UINT32 offset; A_UINT32 length; A_ASSERT(BMI_COMMAND_FITS(BMI_DATASZ_MAX + sizeof(cid) + sizeof(rompatch_count))); memset(pBMICmdBuf, 0, BMI_DATASZ_MAX + sizeof(cid) + sizeof(rompatch_count)); if (bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Change rompatch Activation: Enter (device: 0x%p, count: %d)\n", device, rompatch_count)); cid = do_activate ? BMI_ROMPATCH_ACTIVATE : BMI_ROMPATCH_DEACTIVATE; offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &rompatch_count, sizeof(rompatch_count)); offset += sizeof(rompatch_count); length = rompatch_count * sizeof(*rompatch_list); A_MEMCPY(&(pBMICmdBuf[offset]), rompatch_list, length); offset += length; status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Change rompatch Activation: Exit\n")); return A_OK; }
A_STATUS BMInvramProcess(HIF_DEVICE *device, A_UCHAR *seg_name, A_UINT32 *retval, struct ol_ath_softc_net80211 *scn) { A_UINT32 cid; A_STATUS status; A_UINT32 offset; A_UINT32 retvalLen; A_UCHAR *pBMICmdBuf = scn->pBMICmdBuf; A_UCHAR *pBMIRspBuf = scn->pBMIRspBuf; ASSERT(BMI_COMMAND_FITS(sizeof(cid) + BMI_NVRAM_SEG_NAME_SZ)); if (scn->bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI NVRAM Process: Enter (device: 0x%p, name: %s)\n", device, seg_name)); cid = BMI_NVRAM_PROCESS; offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), seg_name, BMI_NVRAM_SEG_NAME_SZ); offset += BMI_NVRAM_SEG_NAME_SZ; retvalLen = sizeof(*retval); status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, pBMIRspBuf, &retvalLen, 0); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to access the device\n")); return A_ERROR; } A_MEMCPY(retval, pBMIRspBuf, sizeof(*retval)); AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI NVRAM Process: Exit\n")); return A_OK; }
A_STATUS BMIWriteSOCRegister(HIF_DEVICE *device, A_UINT32 address, A_UINT32 param, struct ol_ath_softc_net80211 *scn) { A_UINT32 cid; A_STATUS status; A_UINT32 offset; A_UCHAR *pBMICmdBuf = scn->pBMICmdBuf; ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(address) + sizeof(param))); memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(address) + sizeof(param)); if (scn->bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Write SOC Register: Enter (device: 0x%p, address: 0x%x, param: %d)\n", device, address, param)); cid = BMI_WRITE_SOC_REGISTER; offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); offset += sizeof(address); A_MEMCPY(&(pBMICmdBuf[offset]), ¶m, sizeof(param)); offset += sizeof(param); status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Read SOC Register: Exit\n")); return A_OK; }
A_STATUS BMIReadSOCRegister(HIF_DEVICE *device, A_UINT32 address, A_UINT32 *param) { A_UINT32 cid; A_STATUS status; A_UINT32 offset,paramLen; A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(address))); memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(address)); if (bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Read SOC Register: Enter (device: 0x%p, address: 0x%x)\n", device, address)); cid = BMI_READ_SOC_REGISTER; offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); offset += sizeof(address); paramLen = sizeof(*param); status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, pBMICmdBuf, ¶mLen, BMI_EXCHANGE_TIMEOUT_MS); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read from the device\n")); return A_ERROR; } A_MEMCPY(param, pBMICmdBuf, sizeof(*param)); AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Read SOC Register: Exit (value: %d)\n", *param)); return A_OK; }
A_STATUS BMILZStreamStart(HIF_DEVICE *device, A_UINT32 address, struct ol_ath_softc_net80211 *scn) { A_UINT32 cid; A_STATUS status; A_UINT32 offset; A_UCHAR *pBMICmdBuf = scn->pBMICmdBuf; ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(address))); memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(address)); if (scn->bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI LZ Stream Start: Enter (device: 0x%p, address: 0x%x)\n", device, address)); cid = BMI_LZ_STREAM_START; offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); offset += sizeof(address); status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to Start LZ Stream to the device\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI LZ Stream Start: Exit\n")); return A_OK; }
A_STATUS BMISetAppStart(HIF_DEVICE *device, A_UINT32 address) { A_UINT32 cid; A_STATUS status; A_UINT32 offset; A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(address))); memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(address)); if (bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Set App Start: Enter (device: 0x%p, address: 0x%x)\n", device, address)); cid = BMI_SET_APP_START; offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); offset += sizeof(address); status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Set App Start: Exit\n")); return A_OK; }
A_STATUS BMIrompatchUninstall(HIF_DEVICE *device, A_UINT32 rompatch_id) { A_UINT32 cid; A_STATUS status; A_UINT32 offset; A_ASSERT(BMI_COMMAND_FITS(sizeof(cid) + sizeof(rompatch_id))); memset (pBMICmdBuf, 0, sizeof(cid) + sizeof(rompatch_id)); if (bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI rompatch Uninstall: Enter (device: 0x%p, rompatch_id: %d)\n", device, rompatch_id)); cid = BMI_ROMPATCH_UNINSTALL; offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &rompatch_id, sizeof(rompatch_id)); offset += sizeof(rompatch_id); status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, 0); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI rompatch UNinstall: (rompatch_id=0x%x)\n", rompatch_id)); return A_OK; }
A_STATUS BMIWriteMemory(HIF_DEVICE *device, A_UINT32 address, A_UCHAR *buffer, A_UINT32 length) { A_UINT32 cid; A_STATUS status; A_UINT32 offset; A_UINT32 remaining, txlen; const A_UINT32 header = sizeof(cid) + sizeof(address) + sizeof(length); A_UCHAR alignedBuffer[BMI_DATASZ_MAX]; A_UCHAR *src; A_ASSERT(BMI_COMMAND_FITS(BMI_DATASZ_MAX + header)); memset (pBMICmdBuf, 0, BMI_DATASZ_MAX + header); if (bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Write Memory: Enter (device: 0x%p, address: 0x%x, length: %d)\n", device, address, length)); cid = BMI_WRITE_MEMORY; remaining = length; while (remaining) { src = &buffer[length - remaining]; if (remaining < (BMI_DATASZ_MAX - header)) { if (remaining & 3) { /* align it with 4 bytes */ remaining = remaining + (4 - (remaining & 3)); memcpy(alignedBuffer, src, remaining); src = alignedBuffer; } txlen = remaining; } else { txlen = (BMI_DATASZ_MAX - header); } offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); offset += sizeof(address); A_MEMCPY(&(pBMICmdBuf[offset]), &txlen, sizeof(txlen)); offset += sizeof(txlen); A_MEMCPY(&(pBMICmdBuf[offset]), src, txlen); offset += txlen; status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, NULL, NULL, BMI_EXCHANGE_TIMEOUT_MS); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to write to the device\n")); return A_ERROR; } remaining -= txlen; address += txlen; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Write Memory: Exit\n")); return A_OK; }
A_STATUS BMIReadMemory(HIF_DEVICE *device, A_UINT32 address, A_UCHAR *buffer, A_UINT32 length) { A_UINT32 cid; A_STATUS status; A_UINT32 offset; A_UINT32 remaining, rxlen; A_ASSERT(BMI_COMMAND_FITS(BMI_DATASZ_MAX + sizeof(cid) + sizeof(address) + sizeof(length))); if (!pBMICmdBuf) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Buffer NULL\n")); return A_ERROR; } memset (pBMICmdBuf, 0, BMI_DATASZ_MAX + sizeof(cid) + sizeof(address) + sizeof(length)); if (bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Read Memory: Enter (device: 0x%p, address: 0x%x, length: %d)\n", device, address, length)); cid = BMI_READ_MEMORY; remaining = length; while (remaining) { rxlen = (remaining < BMI_DATASZ_MAX) ? remaining : BMI_DATASZ_MAX; offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); offset += sizeof(address); A_MEMCPY(&(pBMICmdBuf[offset]), &rxlen, sizeof(rxlen)); offset += sizeof(length); status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, pBMICmdBuf, /* note we reuse the same buffer to receive on */ &rxlen, BMI_EXCHANGE_TIMEOUT_MS); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read from the device\n")); return A_ERROR; } A_MEMCPY(&buffer[length - remaining], pBMICmdBuf, rxlen); remaining -= rxlen; address += rxlen; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Read Memory: Exit\n")); return A_OK; }
A_STATUS BMIReadMemory(HIF_DEVICE *device, A_UINT32 address, A_UCHAR *buffer, A_UINT32 length, struct ol_ath_softc_net80211 *scn) { A_UINT32 cid; A_STATUS status; A_UINT32 offset; A_UINT32 remaining, rxlen; A_UCHAR *pBMICmdBuf = scn->pBMICmdBuf; A_UCHAR *pBMIRspBuf = scn->pBMIRspBuf; A_UINT32 align; ASSERT(BMI_COMMAND_FITS(BMI_DATASZ_MAX + sizeof(cid) + sizeof(address) + sizeof(length))); memset (pBMICmdBuf, 0, BMI_DATASZ_MAX + sizeof(cid) + sizeof(address) + sizeof(length)); memset (pBMIRspBuf, 0, BMI_DATASZ_MAX + sizeof(cid) + sizeof(address) + sizeof(length)); if (scn->bmiDone) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Command disallowed\n")); return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Read Memory: Enter (device: 0x%p, address: 0x%x, length: %d)\n", device, address, length)); cid = BMI_READ_MEMORY; #if defined(SDIO_3_0) /* 4bytes align operation */ align = 4 - (length & 3); remaining = length + align; #else align = 0; remaining = length; #endif while (remaining) { rxlen = (remaining < BMI_DATASZ_MAX) ? remaining : BMI_DATASZ_MAX; offset = 0; A_MEMCPY(&(pBMICmdBuf[offset]), &cid, sizeof(cid)); offset += sizeof(cid); A_MEMCPY(&(pBMICmdBuf[offset]), &address, sizeof(address)); offset += sizeof(address); A_MEMCPY(&(pBMICmdBuf[offset]), &rxlen, sizeof(rxlen)); offset += sizeof(length); status = HIFExchangeBMIMsg(device, pBMICmdBuf, offset, pBMIRspBuf, /* note we reuse the same buffer to receive on */ &rxlen, BMI_EXCHANGE_TIMEOUT_MS); if (status != A_OK) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unable to read from the device\n")); return A_ERROR; } if (remaining == rxlen) { A_MEMCPY(&buffer[length - remaining + align], pBMIRspBuf, rxlen - align); /* last align bytes are invalid */ } else { A_MEMCPY(&buffer[length - remaining + align], pBMIRspBuf, rxlen); } remaining -= rxlen; address += rxlen; } AR_DEBUG_PRINTF(ATH_DEBUG_BMI, ("BMI Read Memory: Exit\n")); return A_OK; }