1 //------------------------------------------------------------------------------
2 // <copyright file="common_drv.c" company="Atheros">
3 // Copyright (c) 2004-2010 Atheros Corporation. All rights reserved.
6 // Permission to use, copy, modify, and/or distribute this software for any
7 // purpose with or without fee is hereby granted, provided that the above
8 // copyright notice and this permission notice appear in all copies.
10 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 //------------------------------------------------------------------------------
20 //==============================================================================
21 // Author(s): ="Atheros"
22 //==============================================================================
28 #include "AR6002/hw2.0/hw/mbox_host_reg.h"
29 #include "AR6002/hw2.0/hw/apb_map.h"
30 #include "AR6002/hw2.0/hw/si_reg.h"
31 #include "AR6002/hw2.0/hw/gpio_reg.h"
32 #include "AR6002/hw2.0/hw/rtc_reg.h"
33 #include "AR6002/hw2.0/hw/vmc_reg.h"
34 #include "AR6002/hw2.0/hw/mbox_reg.h"
37 #include "targaddrs.h"
43 #include "common_drv.h"
44 #define ATH_MODULE_NAME misc
46 #include "ar6000_diag.h"
48 static ATH_DEBUG_MODULE_DBG_INFO *g_pModuleInfoHead = NULL;
49 static A_MUTEX_T g_ModuleListLock;
50 static A_BOOL g_ModuleDebugInit = FALSE;
52 #ifdef ATH_DEBUG_MODULE
54 ATH_DEBUG_INSTANTIATE_MODULE_VAR(misc,
56 "Common and misc APIs",
57 ATH_DEBUG_MASK_DEFAULTS,
63 #define HOST_INTEREST_ITEM_ADDRESS(target, item) \
64 ((((target) == TARGET_TYPE_AR6002) ? AR6002_HOST_INTEREST_ITEM_ADDRESS(item) : \
65 (((target) == TARGET_TYPE_AR6003) ? AR6003_HOST_INTEREST_ITEM_ADDRESS(item) : 0)))
68 #define AR6001_LOCAL_COUNT_ADDRESS 0x0c014080
69 #define AR6002_LOCAL_COUNT_ADDRESS 0x00018080
70 #define AR6003_LOCAL_COUNT_ADDRESS 0x00018080
71 #define CPU_DBG_SEL_ADDRESS 0x00000483
72 #define CPU_DBG_ADDRESS 0x00000484
74 static A_UINT8 custDataAR6002[AR6002_CUST_DATA_SIZE];
75 static A_UINT8 custDataAR6003[AR6003_CUST_DATA_SIZE];
77 /* Compile the 4BYTE version of the window register setup routine,
78 * This mitigates host interconnect issues with non-4byte aligned bus requests, some
79 * interconnects use bus adapters that impose strict limitations.
80 * Since diag window access is not intended for performance critical operations, the 4byte mode should
81 * be satisfactory even though it generates 4X the bus activity. */
83 #ifdef USE_4BYTE_REGISTER_ACCESS
85 /* set the window address register (using 4-byte register access ). */
86 A_STATUS ar6000_SetAddressWindowRegister(HIF_DEVICE *hifDevice, A_UINT32 RegisterAddr, A_UINT32 Address)
92 /* write bytes 1,2,3 of the register to set the upper address bytes, the LSB is written
93 * last to initiate the access cycle */
95 for (i = 1; i <= 3; i++) {
96 /* fill the buffer with the address byte value we want to hit 4 times*/
97 addrValue[0] = ((A_UINT8 *)&Address)[i];
98 addrValue[1] = addrValue[0];
99 addrValue[2] = addrValue[0];
100 addrValue[3] = addrValue[0];
102 /* hit each byte of the register address with a 4-byte write operation to the same address,
103 * this is a harmless operation */
104 status = HIFReadWrite(hifDevice,
108 HIF_WR_SYNC_BYTE_FIX,
110 if (status != A_OK) {
115 if (status != A_OK) {
116 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write initial bytes of 0x%x to window reg: 0x%X \n",
117 Address, RegisterAddr));
121 /* write the address register again, this time write the whole 4-byte value.
122 * The effect here is that the LSB write causes the cycle to start, the extra
123 * 3 byte write to bytes 1,2,3 has no effect since we are writing the same values again */
124 status = HIFReadWrite(hifDevice,
126 (A_UCHAR *)(&Address),
128 HIF_WR_SYNC_BYTE_INC,
131 if (status != A_OK) {
132 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write 0x%x to window reg: 0x%X \n",
133 Address, RegisterAddr));
146 /* set the window address register */
147 A_STATUS ar6000_SetAddressWindowRegister(HIF_DEVICE *hifDevice, A_UINT32 RegisterAddr, A_UINT32 Address)
151 /* write bytes 1,2,3 of the register to set the upper address bytes, the LSB is written
152 * last to initiate the access cycle */
153 status = HIFReadWrite(hifDevice,
154 RegisterAddr+1, /* write upper 3 bytes */
155 ((A_UCHAR *)(&Address))+1,
157 HIF_WR_SYNC_BYTE_INC,
160 if (status != A_OK) {
161 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write initial bytes of 0x%x to window reg: 0x%X \n",
162 RegisterAddr, Address));
166 /* write the LSB of the register, this initiates the operation */
167 status = HIFReadWrite(hifDevice,
169 (A_UCHAR *)(&Address),
171 HIF_WR_SYNC_BYTE_INC,
174 if (status != A_OK) {
175 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write 0x%x to window reg: 0x%X \n",
176 RegisterAddr, Address));
186 * Read from the AR6000 through its diagnostic window.
187 * No cooperation from the Target is required for this.
190 ar6000_ReadRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data)
194 /* set window register to start read cycle */
195 status = ar6000_SetAddressWindowRegister(hifDevice,
196 WINDOW_READ_ADDR_ADDRESS,
199 if (status != A_OK) {
204 status = HIFReadWrite(hifDevice,
208 HIF_RD_SYNC_BYTE_INC,
210 if (status != A_OK) {
211 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot read from WINDOW_DATA_ADDRESS\n"));
220 * Write to the AR6000 through its diagnostic window.
221 * No cooperation from the Target is required for this.
224 ar6000_WriteRegDiag(HIF_DEVICE *hifDevice, A_UINT32 *address, A_UINT32 *data)
229 status = HIFReadWrite(hifDevice,
233 HIF_WR_SYNC_BYTE_INC,
235 if (status != A_OK) {
236 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write 0x%x to WINDOW_DATA_ADDRESS\n", *data));
240 /* set window register, which starts the write cycle */
241 return ar6000_SetAddressWindowRegister(hifDevice,
242 WINDOW_WRITE_ADDR_ADDRESS,
247 ar6000_ReadDataDiag(HIF_DEVICE *hifDevice, A_UINT32 address,
248 A_UCHAR *data, A_UINT32 length)
251 A_STATUS status = A_OK;
253 for (count = 0; count < length; count += 4, address += 4) {
254 if ((status = ar6000_ReadRegDiag(hifDevice, &address,
255 (A_UINT32 *)&data[count])) != A_OK)
265 ar6000_WriteDataDiag(HIF_DEVICE *hifDevice, A_UINT32 address,
266 A_UCHAR *data, A_UINT32 length)
269 A_STATUS status = A_OK;
271 for (count = 0; count < length; count += 4, address += 4) {
272 if ((status = ar6000_WriteRegDiag(hifDevice, &address,
273 (A_UINT32 *)&data[count])) != A_OK)
283 ar6k_ReadTargetRegister(HIF_DEVICE *hifDevice, int regsel, A_UINT32 *regval)
287 A_UCHAR register_selection[4];
289 register_selection[0] = register_selection[1] = register_selection[2] = register_selection[3] = (regsel & 0xff);
290 status = HIFReadWrite(hifDevice,
294 HIF_WR_SYNC_BYTE_FIX,
297 if (status != A_OK) {
298 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot write CPU_DBG_SEL (%d)\n", regsel));
302 status = HIFReadWrite(hifDevice,
306 HIF_RD_SYNC_BYTE_INC,
308 if (status != A_OK) {
309 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot read from CPU_DBG_ADDRESS\n"));
313 *regval = vals[0]<<0 | vals[1]<<8 | vals[2]<<16 | vals[3]<<24;
319 ar6k_FetchTargetRegs(HIF_DEVICE *hifDevice, A_UINT32 *targregs)
324 for (i=0; i<AR6003_FETCH_TARG_REGS_COUNT; i++) {
326 (void)ar6k_ReadTargetRegister(hifDevice, i, &val);
333 _do_write_diag(HIF_DEVICE *hifDevice, A_UINT32 addr, A_UINT32 value)
337 status = ar6000_WriteRegDiag(hifDevice, &addr, &value);
340 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Cannot force Target to execute ROM!\n"));
349 * Delay up to wait_msecs millisecs to allow Target to enter BMI phase,
350 * which is a good sign that it's alive and well. This is used after
351 * explicitly forcing the Target to reset.
353 * The wait_msecs time should be sufficiently long to cover any reasonable
354 * boot-time delay. For instance, AR6001 firmware allow one second for a
355 * low frequency crystal to settle before it calibrates the refclk frequency.
357 * TBD: Might want to add special handling for AR6K_OPTION_BMI_DISABLE.
361 _delay_until_target_alive(HIF_DEVICE *hifDevice, A_INT32 wait_msecs, A_UINT32 TargetType)
369 /* Hardcode the address of LOCAL_COUNT_ADDRESS based on the target type */
370 if (TargetType == TARGET_TYPE_AR6002) {
371 address = AR6002_LOCAL_COUNT_ADDRESS;
372 } else if (TargetType == TARGET_TYPE_AR6003) {
373 address = AR6003_LOCAL_COUNT_ADDRESS;
378 for (i=0; actual_wait < wait_msecs; i++) {
385 if (ar6000_ReadRegDiag(hifDevice, &address, &data) != A_OK) {
390 /* No need to wait longer -- we have a BMI credit */
394 return A_ERROR; /* timed out */
398 #define AR6001_RESET_CONTROL_ADDRESS 0x0C000000
399 #define AR6002_RESET_CONTROL_ADDRESS 0x00004000
400 #define AR6003_RESET_CONTROL_ADDRESS 0x00004000
402 A_STATUS ar6000_reset_device(HIF_DEVICE *hifDevice, A_UINT32 TargetType, A_BOOL waitForCompletion, A_BOOL coldReset)
404 A_STATUS status = A_OK;
410 // address = RESET_CONTROL_ADDRESS;
413 data = RESET_CONTROL_COLD_RST_MASK;
416 data = RESET_CONTROL_MBOX_RST_MASK;
419 /* Hardcode the address of RESET_CONTROL_ADDRESS based on the target type */
420 if (TargetType == TARGET_TYPE_AR6002) {
421 address = AR6002_RESET_CONTROL_ADDRESS;
422 } else if (TargetType == TARGET_TYPE_AR6003) {
423 address = AR6003_RESET_CONTROL_ADDRESS;
429 status = ar6000_WriteRegDiag(hifDevice, &address, &data);
431 if (A_FAILED(status)) {
435 if (!waitForCompletion) {
440 /* Up to 2 second delay to allow things to settle down */
441 (void)_delay_until_target_alive(hifDevice, 2000, TargetType);
444 * Read back the RESET CAUSE register to ensure that the cold reset
448 // address = RESET_CAUSE_ADDRESS;
449 /* Hardcode the address of RESET_CAUSE_ADDRESS based on the target type */
450 if (TargetType == TARGET_TYPE_AR6002) {
451 address = 0x000040C0;
452 } else if (TargetType == TARGET_TYPE_AR6003) {
453 address = 0x000040C0;
459 status = ar6000_ReadRegDiag(hifDevice, &address, &data);
461 if (A_FAILED(status)) {
465 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Reset Cause readback: 0x%X \n",data));
466 data &= RESET_CAUSE_LAST_MASK;
468 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Unable to cold reset the target \n"));
475 if (A_FAILED(status)) {
476 AR_DEBUG_PRINTF(ATH_LOG_ERR, ("Failed to reset target \n"));
482 /* This should be called in BMI phase after firmware is downloaded */
484 ar6000_copy_cust_data_from_target(HIF_DEVICE *hifDevice, A_UINT32 TargetType)
486 A_UINT32 eepHeaderAddr;
487 A_UINT8 AR6003CustDataShadow[AR6003_CUST_DATA_SIZE+4];
490 if (BMIReadMemory(hifDevice,
491 HOST_INTEREST_ITEM_ADDRESS(TargetType, hi_board_data),
492 (A_UCHAR *)&eepHeaderAddr,
495 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMIReadMemory for reading board data address failed \n"));
499 if (TargetType == TARGET_TYPE_AR6003) {
500 eepHeaderAddr += 36; /* AR6003 customer data section offset is 37 */
502 for (i=0; i<AR6003_CUST_DATA_SIZE+4; i+=4){
503 if (BMIReadSOCRegister(hifDevice, eepHeaderAddr, (A_UINT32 *)&AR6003CustDataShadow[i])!= A_OK) {
504 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMIReadSOCRegister () failed \n"));
510 memcpy(custDataAR6003, AR6003CustDataShadow+1, AR6003_CUST_DATA_SIZE);
513 if (TargetType == TARGET_TYPE_AR6002) {
514 eepHeaderAddr += 64; /* AR6002 customer data sectioin offset is 64 */
516 for (i=0; i<AR6002_CUST_DATA_SIZE; i+=4){
517 if (BMIReadSOCRegister(hifDevice, eepHeaderAddr, (A_UINT32 *)&custDataAR6002[i])!= A_OK) {
518 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMIReadSOCRegister () failed \n"));
528 /* This is the function to call when need to use the cust data */
530 ar6000_get_cust_data_buffer(A_UINT32 TargetType)
532 if (TargetType == TARGET_TYPE_AR6003)
533 return custDataAR6003;
535 if (TargetType == TARGET_TYPE_AR6002)
536 return custDataAR6002;
541 #define REG_DUMP_COUNT_AR6001 38 /* WORDs, derived from AR600x_regdump.h */
542 #define REG_DUMP_COUNT_AR6002 60
543 #define REG_DUMP_COUNT_AR6003 60
544 #define REGISTER_DUMP_LEN_MAX 60
545 #if REG_DUMP_COUNT_AR6001 > REGISTER_DUMP_LEN_MAX
546 #error "REG_DUMP_COUNT_AR6001 too large"
548 #if REG_DUMP_COUNT_AR6002 > REGISTER_DUMP_LEN_MAX
549 #error "REG_DUMP_COUNT_AR6002 too large"
551 #if REG_DUMP_COUNT_AR6003 > REGISTER_DUMP_LEN_MAX
552 #error "REG_DUMP_COUNT_AR6003 too large"
556 void ar6000_dump_target_assert_info(HIF_DEVICE *hifDevice, A_UINT32 TargetType)
559 A_UINT32 regDumpArea = 0;
561 A_UINT32 regDumpValues[REGISTER_DUMP_LEN_MAX];
562 A_UINT32 regDumpCount = 0;
567 /* the reg dump pointer is copied to the host interest area */
568 address = HOST_INTEREST_ITEM_ADDRESS(TargetType, hi_failure_state);
569 address = TARG_VTOP(TargetType, address);
571 if (TargetType == TARGET_TYPE_AR6002) {
572 regDumpCount = REG_DUMP_COUNT_AR6002;
573 } else if (TargetType == TARGET_TYPE_AR6003) {
574 regDumpCount = REG_DUMP_COUNT_AR6003;
579 /* read RAM location through diagnostic window */
580 status = ar6000_ReadRegDiag(hifDevice, &address, ®DumpArea);
582 if (A_FAILED(status)) {
583 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6K: Failed to get ptr to register dump area \n"));
587 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6K: Location of register dump data: 0x%X \n",regDumpArea));
589 if (regDumpArea == 0) {
594 regDumpArea = TARG_VTOP(TargetType, regDumpArea);
596 /* fetch register dump data */
597 status = ar6000_ReadDataDiag(hifDevice,
599 (A_UCHAR *)®DumpValues[0],
600 regDumpCount * (sizeof(A_UINT32)));
602 if (A_FAILED(status)) {
603 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6K: Failed to get register dump \n"));
606 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("AR6K: Register Dump: \n"));
608 for (i = 0; i < regDumpCount; i++) {
609 //ATHR_DISPLAY_MSG (_T(" %d : 0x%8.8X \n"), i, regDumpValues[i]);
610 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" %d : 0x%8.8X \n",i, regDumpValues[i]));
614 * For Every logPrintf() Open the File so that in case of Crashes
615 * We will have until the Last Message Flushed on to the File
616 * So use logPrintf Sparingly..!!
618 tgtassertPrintf (ATH_DEBUG_TRC," %d: 0x%8.8X \n",i, regDumpValues[i]);
626 /* set HTC/Mbox operational parameters, this can only be called when the target is in the
628 A_STATUS ar6000_set_htc_params(HIF_DEVICE *hifDevice,
630 A_UINT32 MboxIsrYieldValue,
631 A_UINT8 HtcControlBuffers)
634 A_UINT32 blocksizes[HTC_MAILBOX_NUM_MAX];
637 /* get the block sizes */
638 status = HIFConfigureDevice(hifDevice, HIF_DEVICE_GET_MBOX_BLOCK_SIZE,
639 blocksizes, sizeof(blocksizes));
641 if (A_FAILED(status)) {
642 AR_DEBUG_PRINTF(ATH_LOG_ERR,("Failed to get block size info from HIF layer...\n"));
645 /* note: we actually get the block size for mailbox 1, for SDIO the block
646 * size on mailbox 0 is artificially set to 1 */
647 /* must be a power of 2 */
648 A_ASSERT((blocksizes[1] & (blocksizes[1] - 1)) == 0);
650 if (HtcControlBuffers != 0) {
651 /* set override for number of control buffers to use */
652 blocksizes[1] |= ((A_UINT32)HtcControlBuffers) << 16;
655 /* set the host interest area for the block size */
656 status = BMIWriteMemory(hifDevice,
657 HOST_INTEREST_ITEM_ADDRESS(TargetType, hi_mbox_io_block_sz),
658 (A_UCHAR *)&blocksizes[1],
661 if (A_FAILED(status)) {
662 AR_DEBUG_PRINTF(ATH_LOG_ERR,("BMIWriteMemory for IO block size failed \n"));
666 AR_DEBUG_PRINTF(ATH_LOG_INF,("Block Size Set: %d (target address:0x%X)\n",
667 blocksizes[1], HOST_INTEREST_ITEM_ADDRESS(TargetType, hi_mbox_io_block_sz)));
669 if (MboxIsrYieldValue != 0) {
670 /* set the host interest area for the mbox ISR yield limit */
671 status = BMIWriteMemory(hifDevice,
672 HOST_INTEREST_ITEM_ADDRESS(TargetType, hi_mbox_isr_yield_limit),
673 (A_UCHAR *)&MboxIsrYieldValue,
676 if (A_FAILED(status)) {
677 AR_DEBUG_PRINTF(ATH_LOG_ERR,("BMIWriteMemory for yield limit failed \n"));
688 static A_STATUS prepare_ar6002(HIF_DEVICE *hifDevice, A_UINT32 TargetVersion)
690 A_STATUS status = A_OK;
697 static A_STATUS prepare_ar6003(HIF_DEVICE *hifDevice, A_UINT32 TargetVersion)
699 A_STATUS status = A_OK;
706 /* this function assumes the caller has already initialized the BMI APIs */
707 A_STATUS ar6000_prepare_target(HIF_DEVICE *hifDevice,
709 A_UINT32 TargetVersion)
711 if (TargetType == TARGET_TYPE_AR6002) {
712 /* do any preparations for AR6002 devices */
713 return prepare_ar6002(hifDevice,TargetVersion);
714 } else if (TargetType == TARGET_TYPE_AR6003) {
715 return prepare_ar6003(hifDevice,TargetVersion);
721 #if defined(CONFIG_AR6002_REV1_FORCE_HOST)
723 * Call this function just before the call to BMIInit
724 * in order to force* AR6002 rev 1.x firmware to detect a Host.
725 * THIS IS FOR USE ONLY WITH AR6002 REV 1.x.
726 * TBDXXX: Remove this function when REV 1.x is desupported.
729 ar6002_REV1_reset_force_host (HIF_DEVICE *hifDevice)
736 struct forceROM_s *ForceROM;
738 A_STATUS status = A_OK;
742 /* Force AR6002 REV1.x to recognize Host presence.
744 * Note: Use RAM at 0x52df80..0x52dfa0 with ROM Remap entry 0
745 * so that this workaround functions with AR6002.war1.sh. We
746 * could fold that entire workaround into this one, but it's not
747 * worth the effort at this point. This workaround cannot be
748 * merged into the other workaround because this must be done
752 static struct forceROM_s ForceROM_NEW[] = {
753 {0x52df80, 0x20f31c07},
754 {0x52df84, 0x92374420},
755 {0x52df88, 0x1d120c03},
756 {0x52df8c, 0xff8216f0},
757 {0x52df90, 0xf01d120c},
758 {0x52df94, 0x81004136},
759 {0x52df98, 0xbc9100bd},
760 {0x52df9c, 0x00bba100},
762 {0x00008000|MC_TCAM_TARGET_ADDRESS, 0x0012dfe0}, /* Use remap entry 0 */
763 {0x00008000|MC_TCAM_COMPARE_ADDRESS, 0x000e2380},
764 {0x00008000|MC_TCAM_MASK_ADDRESS, 0x00000000},
765 {0x00008000|MC_TCAM_VALID_ADDRESS, 0x00000001},
767 {0x00018000|(LOCAL_COUNT_ADDRESS+0x10), 0}, /* clear BMI credit counter */
769 {0x00004000|AR6002_RESET_CONTROL_ADDRESS, RESET_CONTROL_WARM_RST_MASK},
772 address = 0x004ed4b0; /* REV1 target software ID is stored here */
773 status = ar6000_ReadRegDiag(hifDevice, &address, &data);
774 if (A_FAILED(status) || (data != AR6002_VERSION_REV1)) {
775 return A_ERROR; /* Not AR6002 REV1 */
778 ForceROM = ForceROM_NEW;
779 szForceROM = sizeof(ForceROM_NEW)/sizeof(*ForceROM);
781 ATH_DEBUG_PRINTF (DBG_MISC_DRV, ATH_DEBUG_TRC, ("Force Target to recognize Host....\n"));
782 for (i = 0; i < szForceROM; i++)
784 if (ar6000_WriteRegDiag(hifDevice,
786 &ForceROM[i].data) != A_OK)
788 ATH_DEBUG_PRINTF (DBG_MISC_DRV, ATH_DEBUG_TRC, ("Cannot force Target to recognize Host!\n"));
798 #endif /* CONFIG_AR6002_REV1_FORCE_HOST */
800 void DebugDumpBytes(A_UCHAR *buffer, A_UINT16 length, char *pDescription)
803 A_CHAR byteOffsetStr[10];
805 A_UINT16 offset, count, byteOffset;
807 A_PRINTF("<---------Dumping %d Bytes : %s ------>\n", length, pDescription);
812 for(i = 0; i < length; i++) {
813 A_SPRINTF(stream + offset, "%2.2X ", buffer[i]);
820 A_SPRINTF(byteOffsetStr,"%4.4X",byteOffset);
821 A_PRINTF("[%s]: %s\n", byteOffsetStr, stream);
822 A_MEMZERO(stream, 60);
828 A_SPRINTF(byteOffsetStr,"%4.4X",byteOffset);
829 A_PRINTF("[%s]: %s\n", byteOffsetStr, stream);
832 A_PRINTF("<------------------------------------------------->\n");
835 void a_dump_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo)
838 ATH_DEBUG_MASK_DESCRIPTION *pDesc;
844 pDesc = pInfo->pMaskDescriptions;
846 A_PRINTF("========================================================\n\n");
847 A_PRINTF("Module Debug Info => Name : %s \n", pInfo->ModuleName);
848 A_PRINTF(" => Descr. : %s \n", pInfo->ModuleDescription);
849 A_PRINTF("\n Current mask => 0x%8.8X \n", pInfo->CurrentMask);
850 A_PRINTF("\n Avail. Debug Masks :\n\n");
852 for (i = 0; i < pInfo->MaxDescriptions; i++,pDesc++) {
853 A_PRINTF(" => 0x%8.8X -- %s \n", pDesc->Mask, pDesc->Description);
857 A_PRINTF(" => * none defined * \n");
860 A_PRINTF("\n Standard Debug Masks :\n\n");
861 /* print standard masks */
862 A_PRINTF(" => 0x%8.8X -- Errors \n", ATH_DEBUG_ERR);
863 A_PRINTF(" => 0x%8.8X -- Warnings \n", ATH_DEBUG_WARN);
864 A_PRINTF(" => 0x%8.8X -- Informational \n", ATH_DEBUG_INFO);
865 A_PRINTF(" => 0x%8.8X -- Tracing \n", ATH_DEBUG_TRC);
866 A_PRINTF("\n========================================================\n");
871 static ATH_DEBUG_MODULE_DBG_INFO *FindModule(A_CHAR *module_name)
873 ATH_DEBUG_MODULE_DBG_INFO *pInfo = g_pModuleInfoHead;
875 if (!g_ModuleDebugInit) {
879 while (pInfo != NULL) {
880 /* TODO: need to use something other than strlen */
881 if (A_MEMCMP(pInfo->ModuleName,module_name,strlen(module_name)) == 0) {
884 pInfo = pInfo->pNext;
891 void a_register_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo)
893 if (!g_ModuleDebugInit) {
897 A_MUTEX_LOCK(&g_ModuleListLock);
899 if (!(pInfo->Flags & ATH_DEBUG_INFO_FLAGS_REGISTERED)) {
900 if (g_pModuleInfoHead == NULL) {
901 g_pModuleInfoHead = pInfo;
903 pInfo->pNext = g_pModuleInfoHead;
904 g_pModuleInfoHead = pInfo;
906 pInfo->Flags |= ATH_DEBUG_INFO_FLAGS_REGISTERED;
909 A_MUTEX_UNLOCK(&g_ModuleListLock);
912 void a_dump_module_debug_info_by_name(A_CHAR *module_name)
914 ATH_DEBUG_MODULE_DBG_INFO *pInfo = g_pModuleInfoHead;
916 if (!g_ModuleDebugInit) {
920 if (A_MEMCMP(module_name,"all",3) == 0) {
922 while (pInfo != NULL) {
923 a_dump_module_debug_info(pInfo);
924 pInfo = pInfo->pNext;
929 pInfo = FindModule(module_name);
932 a_dump_module_debug_info(pInfo);
937 A_STATUS a_get_module_mask(A_CHAR *module_name, A_UINT32 *pMask)
939 ATH_DEBUG_MODULE_DBG_INFO *pInfo = FindModule(module_name);
945 *pMask = pInfo->CurrentMask;
949 A_STATUS a_set_module_mask(A_CHAR *module_name, A_UINT32 Mask)
951 ATH_DEBUG_MODULE_DBG_INFO *pInfo = FindModule(module_name);
957 pInfo->CurrentMask = Mask;
958 A_PRINTF("Module %s, new mask: 0x%8.8X \n",module_name,pInfo->CurrentMask);
963 void a_module_debug_support_init(void)
965 if (g_ModuleDebugInit) {
968 A_MUTEX_INIT(&g_ModuleListLock);
969 g_pModuleInfoHead = NULL;
970 g_ModuleDebugInit = TRUE;
971 A_REGISTER_MODULE_DEBUG_INFO(misc);
974 void a_module_debug_support_cleanup(void)
976 ATH_DEBUG_MODULE_DBG_INFO *pInfo = g_pModuleInfoHead;
977 ATH_DEBUG_MODULE_DBG_INFO *pCur;
979 if (!g_ModuleDebugInit) {
983 g_ModuleDebugInit = FALSE;
985 A_MUTEX_LOCK(&g_ModuleListLock);
987 while (pInfo != NULL) {
989 pInfo = pInfo->pNext;
991 /* clear registered flag */
992 pCur->Flags &= ~ATH_DEBUG_INFO_FLAGS_REGISTERED;
995 A_MUTEX_UNLOCK(&g_ModuleListLock);
997 A_MUTEX_DELETE(&g_ModuleListLock);
998 g_pModuleInfoHead = NULL;
1001 /* can only be called during bmi init stage */
1002 A_STATUS ar6000_set_hci_bridge_flags(HIF_DEVICE *hifDevice,
1003 A_UINT32 TargetType,
1006 A_STATUS status = A_OK;
1010 if (TargetType != TARGET_TYPE_AR6003) {
1011 AR_DEBUG_PRINTF(ATH_DEBUG_WARN, ("Target Type:%d, does not support HCI bridging! \n",
1016 /* set hci bridge flags */
1017 status = BMIWriteMemory(hifDevice,
1018 HOST_INTEREST_ITEM_ADDRESS(TargetType, hi_hci_bridge_flags),