2 * Copyright (c) 2007-2008 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #include "../80211core/cprecomp.h"
20 #include "../80211core/ratectrl.h"
22 extern void zfIdlCmd(zdev_t* dev, u32_t* cmd, u16_t cmdLen);
24 extern void zfCoreCwmBusy(zdev_t* dev, u16_t busy);
25 u16_t zfDelayWriteInternalReg(zdev_t* dev, u32_t addr, u32_t val);
26 u16_t zfFlushDelayWrite(zdev_t* dev);
28 //#define zm_hp_priv(x) struct zsHpPriv* hpPriv=zgWlanDev.hpPrivate;
30 void zfInitCmdQueue(zdev_t* dev)
32 zmw_get_wlan_dev(dev);
33 struct zsHpPriv* hpPriv = (struct zsHpPriv*)(wd->hpPrivate);
35 zmw_declare_for_critical_section();
37 zmw_enter_critical_section(dev);
38 #ifdef ZM_XP_USB_MULTCMD
39 hpPriv->cmdTail = hpPriv->cmdHead = hpPriv->cmdSend = 0;
41 hpPriv->cmdTail = hpPriv->cmdHead = 0;
43 hpPriv->cmdPending = 0;
44 hpPriv->cmd.delayWcmdCount = 0;
45 zmw_leave_critical_section(dev);
48 u16_t zfPutCmd(zdev_t* dev, u32_t* cmd, u16_t cmdLen, u16_t src, u8_t* buf)
52 zmw_get_wlan_dev(dev);
53 struct zsHpPriv* hpPriv=wd->hpPrivate;
55 /* Make sure command length < ZM_MAX_CMD_SIZE */
56 zm_assert(cmdLen <= ZM_MAX_CMD_SIZE);
57 /* Make sure command queue not full */
58 //zm_assert(((hpPriv->cmdTail+1) & (ZM_CMD_QUEUE_SIZE-1)) != hpPriv->cmdHead);
59 if (((hpPriv->cmdTail+1) & (ZM_CMD_QUEUE_SIZE-1)) == hpPriv->cmdHead ) {
60 zm_debug_msg0("CMD queue full!!");
64 hpPriv->cmdQ[hpPriv->cmdTail].cmdLen = cmdLen;
65 hpPriv->cmdQ[hpPriv->cmdTail].src = src;
66 hpPriv->cmdQ[hpPriv->cmdTail].buf = buf;
67 for (i=0; i<(cmdLen>>2); i++)
69 hpPriv->cmdQ[hpPriv->cmdTail].cmd[i] = cmd[i];
72 hpPriv->cmdTail = (hpPriv->cmdTail+1) & (ZM_CMD_QUEUE_SIZE-1);
77 u16_t zfGetCmd(zdev_t* dev, u32_t* cmd, u16_t* cmdLen, u16_t* src, u8_t** buf)
81 zmw_get_wlan_dev(dev);
82 struct zsHpPriv* hpPriv=wd->hpPrivate;
84 if (hpPriv->cmdTail == hpPriv->cmdHead)
89 *cmdLen = hpPriv->cmdQ[hpPriv->cmdHead].cmdLen;
90 *src = hpPriv->cmdQ[hpPriv->cmdHead].src;
91 *buf = hpPriv->cmdQ[hpPriv->cmdHead].buf;
92 for (i=0; i<((*cmdLen)>>2); i++)
94 cmd[i] = hpPriv->cmdQ[hpPriv->cmdHead].cmd[i];
97 hpPriv->cmdHead = (hpPriv->cmdHead+1) & (ZM_CMD_QUEUE_SIZE-1);
102 #ifdef ZM_XP_USB_MULTCMD
103 void zfSendCmdEx(zdev_t* dev)
105 u32_t ncmd[ZM_MAX_CMD_SIZE/4];
110 zmw_get_wlan_dev(dev);
111 struct zsHpPriv* hpPriv=wd->hpPrivate;
113 zmw_declare_for_critical_section();
115 zmw_enter_critical_section(dev);
117 if (hpPriv->cmdPending == 0)
119 if (hpPriv->cmdTail != hpPriv->cmdSend)
122 /* Get queueing command */
123 ncmdLen= hpPriv->cmdQ[hpPriv->cmdSend].cmdLen;
124 for (i=0; i<(ncmdLen>>2); i++)
126 ncmd[i] = hpPriv->cmdQ[hpPriv->cmdSend].cmd[i];
128 hpPriv->cmdSend = (hpPriv->cmdSend+1) & (ZM_CMD_QUEUE_SIZE-1);
130 hpPriv->cmdPending = 1;
134 zmw_leave_critical_section(dev);
138 zfIdlCmd(dev, ncmd, ncmdLen);
142 void zfiSendCmdComp(zdev_t* dev)
144 zmw_get_wlan_dev(dev);
145 struct zsHpPriv* hpPriv=wd->hpPrivate;
147 zmw_declare_for_critical_section();
149 zmw_enter_critical_section(dev);
150 hpPriv->cmdPending = 0;
151 zmw_leave_critical_section(dev);
157 u16_t zfIssueCmd(zdev_t* dev, u32_t* cmd, u16_t cmdLen, u16_t src, u8_t* buf)
162 zmw_get_wlan_dev(dev);
163 struct zsHpPriv* hpPriv=wd->hpPrivate;
165 zmw_declare_for_critical_section();
167 zm_msg2_mm(ZM_LV_1, "cmdLen=", cmdLen);
169 zmw_enter_critical_section(dev);
171 #ifdef ZM_XP_USB_MULTCMD
172 ret = zfPutCmd(dev, cmd, cmdLen, src, buf);
173 zmw_leave_critical_section(dev);
182 if (hpPriv->cmdPending == 0)
184 hpPriv->cmdPending = 1;
187 ret = zfPutCmd(dev, cmd, cmdLen, src, buf);
189 zmw_leave_critical_section(dev);
198 zfIdlCmd(dev, cmd, cmdLen);
204 void zfIdlRsp(zdev_t* dev, u32_t* rsp, u16_t rspLen)
206 u32_t cmd[ZM_MAX_CMD_SIZE/4];
210 u32_t ncmd[ZM_MAX_CMD_SIZE/4];
218 zmw_get_wlan_dev(dev);
219 struct zsHpPriv* hpPriv=wd->hpPrivate;
222 zmw_declare_for_critical_section();
224 zmw_enter_critical_section(dev);
226 ret = zfGetCmd(dev, cmd, &cmdLen, &src, &buf);
232 zm_debug_msg0("Error IdlRsp because none cmd!!\n");
233 #ifndef ZM_XP_USB_MULTCMD
234 zmw_leave_critical_section(dev);
239 #ifdef ZM_XP_USB_MULTCMD
240 zmw_leave_critical_section(dev);
242 if (hpPriv->cmdTail != hpPriv->cmdHead)
245 /* Get queueing command */
246 ncmdLen= hpPriv->cmdQ[hpPriv->cmdHead].cmdLen;
247 for (i=0; i<(ncmdLen>>2); i++)
249 ncmd[i] = hpPriv->cmdQ[hpPriv->cmdHead].cmd[i];
254 hpPriv->cmdPending = 0;
257 zmw_leave_critical_section(dev);
261 zfIdlCmd(dev, ncmd, ncmdLen);
264 if (src == ZM_OID_READ)
266 ZM_PERFORMANCE_REG(dev, 0x11772c, rsp[1]);
267 zfwDbgReadRegDone(dev, cmd[1], rsp[1]);
269 else if (src == ZM_OID_FLASH_CHKSUM)
271 zfwDbgGetFlashChkSumDone(dev, rsp+1);
273 else if (src == ZM_OID_FLASH_READ)
278 datalen = (rsp[0] & 255);
280 zfwDbgReadFlashDone(dev, cmd[1], rsp+1, datalen);
282 else if (src == ZM_OID_FLASH_PROGRAM)
286 else if (src == ZM_OID_WRITE)
288 zfwDbgWriteRegDone(dev, cmd[1], cmd[2]);
290 else if (src == ZM_OID_TALLY)
292 zfCollectHWTally(dev, rsp, 0);
294 else if (src == ZM_OID_TALLY_APD)
296 zfCollectHWTally(dev, rsp, 1);
297 zfwDbgReadTallyDone(dev);
298 #ifdef ZM_ENABLE_BA_RATECTRL
299 zfRateCtrlAggrSta(dev);
302 else if (src == ZM_OID_DKTX_STATUS)
304 zm_debug_msg0("src = zm_OID_DKTX_STATUS");
305 zfwDbgQueryHwTxBusyDone(dev, rsp[1]);
307 else if (src == ZM_CMD_SET_FREQUENCY)
310 //#ifdef ZM_OTUS_ENABLE_RETRY_FREQ_CHANGE
312 zm_debug_msg1("Retry Set Frequency = ", rsp[1]);
315 // Read the Noise Floor value !
316 nf = ((rsp[2]>>19) & 0x1ff);
317 if ((nf & 0x100) != 0x0)
319 noisefloor[0] = 0 - ((nf ^ 0x1ff) + 1);
326 zm_debug_msg1("Noise Floor[1] = ", noisefloor[0]);
328 nf = ((rsp[3]>>19) & 0x1ff);
329 if ((nf & 0x100) != 0x0)
331 noisefloor[1] = 0 - ((nf ^ 0x1ff) + 1);
338 zm_debug_msg1("Noise Floor[2] = ", noisefloor[1]);
339 zm_debug_msg1("Is Site Survey = ", hpPriv->isSiteSurvey);
342 if ( (rsp[1] && hpPriv->freqRetryCounter == 0) ||
343 (((noisefloor[0]>-60)||(noisefloor[1]>-60)) && hpPriv->freqRetryCounter==0) ||
344 ((abs(noisefloor[0]-noisefloor[1])>=9) && hpPriv->freqRetryCounter==0) )
346 zm_debug_msg0("Retry to issue the frequency change command");
348 if ( hpPriv->recordFreqRetryCounter == 1 )
350 zm_debug_msg0("Cold Reset");
352 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
354 hpPriv->latestExtOffset,
357 if ( hpPriv->isSiteSurvey != 2 )
359 hpPriv->freqRetryCounter++;
361 hpPriv->recordFreqRetryCounter = 0;
365 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
367 hpPriv->latestExtOffset,
370 hpPriv->recordFreqRetryCounter++;
375 /* ret: Bit0: AGC calibration 0=>finish 1=>unfinish */
376 /* Bit1: Noise calibration 0=>finish 1=>unfinish */
377 /* Bit2: Noise calibration finish, but NF value unexcepted => 1 */
378 if ( (rsp[1] & 0x1) || (rsp[1] & 0x4) )
380 zm_debug_msg1("Set Frequency fail : ret = ", rsp[1]);
382 /* 1. AGC Calibration fail */
383 /* 2. Noise Calibration finish but error NoiseFloor value */
384 /* and not in sitesurvey, try more twice */
385 if ( hpPriv->isSiteSurvey == 2 )
387 if ( hpPriv->recordFreqRetryCounter < 2 )
390 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
392 hpPriv->latestExtOffset,
394 hpPriv->recordFreqRetryCounter++;
395 zm_debug_msg1("Retry to issue the frequency change command(cold reset) counter = ", hpPriv->recordFreqRetryCounter);
399 /* Fail : we would not accept this result! */
400 zm_debug_msg0("\n\n\n\n Fail twice cold reset \n\n\n\n");
401 hpPriv->coldResetNeedFreq = 0;
402 hpPriv->recordFreqRetryCounter = 0;
403 zfCoreSetFrequencyComplete(dev);
408 /* in sitesurvey, coldreset in next channel */
409 hpPriv->coldResetNeedFreq = 1;
410 hpPriv->recordFreqRetryCounter = 0;
411 zfCoreSetFrequencyComplete(dev);
414 else if (rsp[1] & 0x2)
416 zm_debug_msg1("Set Frequency fail 2 : ret = ", rsp[1]);
418 /* Noise Calibration un-finish */
419 /* and not in sitesurvey, try more once */
420 if ( hpPriv->isSiteSurvey == 2 )
422 if ( hpPriv->recordFreqRetryCounter < 1 )
425 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
427 hpPriv->latestExtOffset,
429 hpPriv->recordFreqRetryCounter++;
430 zm_debug_msg1("2 Retry to issue the frequency change command(cold reset) counter = ", hpPriv->recordFreqRetryCounter);
434 /* Fail : we would not accept this result! */
435 zm_debug_msg0("\n\n\n\n 2 Fail twice cold reset \n\n\n\n");
436 hpPriv->coldResetNeedFreq = 0;
437 hpPriv->recordFreqRetryCounter = 0;
438 zfCoreSetFrequencyComplete(dev);
443 /* in sitesurvey, skip this frequency */
444 hpPriv->coldResetNeedFreq = 0;
445 hpPriv->recordFreqRetryCounter = 0;
446 zfCoreSetFrequencyComplete(dev);
449 //else if (rsp[1] & 0x4)
451 // zm_debug_msg1("Set Frequency fail 3 : ret = ", rsp[1]);
452 // hpPriv->coldResetNeedFreq = 0;
453 // hpPriv->recordFreqRetryCounter = 0;
454 // zfCoreSetFrequencyComplete(dev);
458 //hpPriv->freqRetryCounter = 0;
459 zm_debug_msg2(" return complete, ret = ", rsp[1]);
461 /* set bb_heavy_clip_enable */
462 if (hpPriv->enableBBHeavyClip && hpPriv->hwBBHeavyClip &&
463 hpPriv->doBBHeavyClip)
465 u32_t setValue = 0x200;
467 setValue |= hpPriv->setValueHeavyClip;
469 //zm_dbg(("Do heavy clip setValue = %d\n", setValue));
471 zfDelayWriteInternalReg(dev, 0x99e0+0x1bc000, setValue);
472 zfFlushDelayWrite(dev);
475 hpPriv->coldResetNeedFreq = 0;
476 hpPriv->recordFreqRetryCounter = 0;
477 zfCoreSetFrequencyComplete(dev);
481 // Read the Noise Floor value !
482 nf = ((rsp[2]>>19) & 0x1ff);
483 if ((nf & 0x100) != 0x0)
485 noisefloor[0] = 0 - ((nf ^ 0x1ff) + 1);
492 //zm_debug_msg1("Noise Floor[1] = ", noisefloor[0]);
494 nf = ((rsp[3]>>19) & 0x1ff);
495 if ((nf & 0x100) != 0x0)
497 noisefloor[1] = 0 - ((nf ^ 0x1ff) + 1);
504 //zm_debug_msg1("Noise Floor[2] = ", noisefloor[1]);
506 nf = ((rsp[5]>>23) & 0x1ff);
507 if ((nf & 0x100) != 0x0)
509 noisefloor[2] = 0 - ((nf ^ 0x1ff) + 1);
516 //zm_debug_msg1("Noise Floor ext[1] = ", noisefloor[2]);
518 nf = ((rsp[6]>>23) & 0x1ff);
519 if ((nf & 0x100) != 0x0)
521 noisefloor[3] = 0 - ((nf ^ 0x1ff) + 1);
528 //zm_debug_msg1("Noise Floor ext[2] = ", noisefloor[3]);
530 //zm_debug_msg1("Is Site Survey = ", hpPriv->isSiteSurvey);
533 else if (src == ZM_CMD_SET_KEY)
535 zfCoreSetKeyComplete(dev);
537 else if (src == ZM_CWM_READ)
539 zm_msg2_mm(ZM_LV_0, "CWM rsp[1]=", rsp[1]);
540 zm_msg2_mm(ZM_LV_0, "CWM rsp[2]=", rsp[2]);
541 zfCoreCwmBusy(dev, zfCwmIsExtChanBusy(rsp[1], rsp[2]));
543 else if (src == ZM_MAC_READ)
545 /* rsp[1] = ZM_SEEPROM_MAC_ADDRESS_OFFSET; */
546 /* rsp[2] = ZM_SEEPROM_MAC_ADDRESS_OFFSET+4; */
547 /* rsp[3] = ZM_SEEPROM_REGDOMAIN_OFFSET; */
548 /* rsp[4] = ZM_SEEPROM_VERISON_OFFSET; */
549 /* rsp[5] = ZM_SEEPROM_HARDWARE_TYPE_OFFSET; */
550 /* rsp[6] = ZM_SEEPROM_HW_HEAVY_CLIP; */
552 u8_t addr[6], CCS, WWR;
553 u16_t CountryDomainCode;
556 //hpPriv->eepromHeavyClipFlag = (u8_t)((rsp[6]>>24) & 0xff); // force enable 8107
557 //zm_msg2_mm(ZM_LV_0, "eepromHeavyClipFlag", hpPriv->eepromHeavyClipFlag);
559 if (hpPriv->hwBBHeavyClip)
561 zm_msg0_mm(ZM_LV_0, "enable BB Heavy Clip");
565 zm_msg0_mm(ZM_LV_0, "Not enable BB Heavy Clip");
568 zm_msg2_mm(ZM_LV_0, "MAC rsp[1]=", rsp[1]);
569 zm_msg2_mm(ZM_LV_0, "MAC rsp[2]=", rsp[2]);
571 addr[0] = (u8_t)(rsp[1] & 0xff);
572 addr[1] = (u8_t)((rsp[1]>>8) & 0xff);
573 addr[2] = (u8_t)((rsp[1]>>16) & 0xff);
574 addr[3] = (u8_t)((rsp[1]>>24) & 0xff);
575 addr[4] = (u8_t)(rsp[2] & 0xff);
576 addr[5] = (u8_t)((rsp[2]>>8) & 0xff);
578 addr[0] = (u8_t)(0 & 0xff);
579 addr[1] = (u8_t)(3 & 0xff);
580 addr[2] = (u8_t)(127 & 0xff);
581 addr[3] = (u8_t)(0 & 0xff);
582 addr[4] = (u8_t)(9 & 0xff);
583 addr[5] = (u8_t)(11 & 0xff);
586 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_L,
587 ((((u32_t)addr[3])<<24) | (((u32_t)addr[2])<<16) | (((u32_t)addr[1])<<8) | addr[0]));
588 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_H,
589 ((((u32_t)addr[5])<<8) | addr[4]));
590 zfFlushDelayWrite(dev);
592 wd->ledStruct.ledMode[0] = (u16_t)(rsp[5]&0xffff);
593 wd->ledStruct.ledMode[1] = (u16_t)(rsp[5]>>16);
594 zm_msg2_mm(ZM_LV_0, "ledMode[0]=", wd->ledStruct.ledMode[0]);
595 zm_msg2_mm(ZM_LV_0, "ledMode[1]=", wd->ledStruct.ledMode[1]);
597 /* Regulatory Related Setting */
598 zm_msg2_mm(ZM_LV_0, "RegDomain rsp=", rsp[3]);
599 zm_msg2_mm(ZM_LV_0, "OpFlags+EepMisc=", rsp[4]);
600 hpPriv->OpFlags = (u8_t)((rsp[4]>>16) & 0xff);
601 if ((rsp[2] >> 24) == 0x1) //Tx mask == 0x1
603 zm_msg0_mm(ZM_LV_0, "OTUS 1x2");
604 hpPriv->halCapability |= ZM_HP_CAP_11N_ONE_TX_STREAM;
608 zm_msg0_mm(ZM_LV_0, "OTUS 2x2");
610 if (hpPriv->OpFlags & 0x1)
612 hpPriv->halCapability |= ZM_HP_CAP_5G;
614 if (hpPriv->OpFlags & 0x2)
616 hpPriv->halCapability |= ZM_HP_CAP_2G;
620 CCS = (u8_t)((rsp[3] & 0x8000) >> 15);
621 WWR = (u8_t)((rsp[3] & 0x4000) >> 14);
622 CountryDomainCode = (u16_t)(rsp[3] & 0x3FFF);
624 if (rsp[3] != 0xffffffff)
628 //zm_debug_msg0("CWY - Get Regulation Table from Country Code");
629 zfHpGetRegulationTablefromCountry(dev, CountryDomainCode);
633 //zm_debug_msg0("CWY - Get Regulation Table from Reg Domain");
634 zfHpGetRegulationTablefromRegionCode(dev, CountryDomainCode);
638 //zm_debug_msg0("CWY - Enable 802.11d");
639 /* below line shall be unmarked after A band is ready */
640 //zfiWlanSetDot11DMode(dev, 1);
645 zfHpGetRegulationTablefromRegionCode(dev, NO_ENUMRD);
648 zfCoreMacAddressNotify(dev, addr);
651 else if (src == ZM_EEPROM_READ)
654 u8_t addr[6], CCS, WWR;
655 u16_t CountryDomainCode;
657 for (i=0; i<ZM_HAL_MAX_EEPROM_PRQ; i++)
659 if (hpPriv->eepromImageIndex < 1024)
661 hpPriv->eepromImage[hpPriv->eepromImageIndex++] = rsp[i+1];
665 if (hpPriv->eepromImageIndex == (ZM_HAL_MAX_EEPROM_REQ*ZM_HAL_MAX_EEPROM_PRQ))
668 for (i=0; i<1024; i++)
670 zm_msg2_mm(ZM_LV_0, "index=", i);
671 zm_msg2_mm(ZM_LV_0, "eepromImage=", hpPriv->eepromImage[i]);
674 zm_msg2_mm(ZM_LV_0, "MAC [1]=", hpPriv->eepromImage[0x20c/4]);
675 zm_msg2_mm(ZM_LV_0, "MAC [2]=", hpPriv->eepromImage[0x210/4]);
677 addr[0] = (u8_t)(hpPriv->eepromImage[0x20c/4] & 0xff);
678 addr[1] = (u8_t)((hpPriv->eepromImage[0x20c/4]>>8) & 0xff);
679 addr[2] = (u8_t)((hpPriv->eepromImage[0x20c/4]>>16) & 0xff);
680 addr[3] = (u8_t)((hpPriv->eepromImage[0x20c/4]>>24) & 0xff);
681 addr[4] = (u8_t)(hpPriv->eepromImage[0x210/4] & 0xff);
682 addr[5] = (u8_t)((hpPriv->eepromImage[0x210/4]>>8) & 0xff);
684 zfCoreMacAddressNotify(dev, addr);
686 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_L,
687 ((((u32_t)addr[3])<<24) | (((u32_t)addr[2])<<16) | (((u32_t)addr[1])<<8) | addr[0]));
688 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_H,
689 ((((u32_t)addr[5])<<8) | addr[4]));
690 zfFlushDelayWrite(dev);
692 /* Regulatory Related Setting */
693 zm_msg2_mm(ZM_LV_0, "RegDomain =", hpPriv->eepromImage[0x208/4]);
694 CCS = (u8_t)((hpPriv->eepromImage[0x208/4] & 0x8000) >> 15);
695 WWR = (u8_t)((hpPriv->eepromImage[0x208/4] & 0x4000) >> 14);
696 /* below line shall be unmarked after A band is ready */
697 //CountryDomainCode = (u16_t)(hpPriv->eepromImage[0x208/4] & 0x3FFF);
698 CountryDomainCode = 8;
701 //zm_debug_msg0("CWY - Get Regulation Table from Country Code");
702 zfHpGetRegulationTablefromCountry(dev, CountryDomainCode);
706 //zm_debug_msg0("CWY - Get Regulation Table from Reg Domain");
707 zfHpGetRegulationTablefromRegionCode(dev, CountryDomainCode);
711 //zm_debug_msg0("CWY - Enable 802.11d");
712 /* below line shall be unmarked after A band is ready */
713 //zfiWlanSetDot11DMode(dev, 1);
716 zfCoreHalInitComplete(dev);
720 hpPriv->eepromImageRdReq++;
721 zfHpLoadEEPROMFromFW(dev);
724 else if (src == ZM_EEPROM_WRITE)
726 zfwDbgWriteEepromDone(dev, cmd[1], cmd[2]);
728 else if (src == ZM_ANI_READ)
730 u32_t cycleTime, ctlClear;
732 zm_msg2_mm(ZM_LV_0, "ANI rsp[1]=", rsp[1]);
733 zm_msg2_mm(ZM_LV_0, "ANI rsp[2]=", rsp[2]);
734 zm_msg2_mm(ZM_LV_0, "ANI rsp[3]=", rsp[3]);
735 zm_msg2_mm(ZM_LV_0, "ANI rsp[4]=", rsp[4]);
737 hpPriv->ctlBusy += rsp[1];
738 hpPriv->extBusy += rsp[2];
740 cycleTime = 100000; //100 miniseconds
742 if (cycleTime > rsp[1])
744 ctlClear = (cycleTime - rsp[1]) / 100;
751 zfHpAniArPoll(dev, ctlClear, rsp[3], rsp[4]);
753 else if (src == ZM_CMD_ECHO)
755 if ( ((struct zsHpPriv*)wd->hpPrivate)->halReInit )
757 zfCoreHalInitComplete(dev);
758 ((struct zsHpPriv*)wd->hpPrivate)->halReInit = 0;
762 zfHpLoadEEPROMFromFW(dev);
765 else if (src == ZM_OID_FW_DL_INIT)
767 zfwDbgDownloadFwInitDone(dev);
773 /************************************************************************/
775 /* FUNCTION DESCRIPTION zfWriteRegInternalReg */
776 /* Write on chip internal register immediately. */
779 /* dev : device pointer */
780 /* addr : register address */
788 /* Stephen Chen ZyDAS Technology Corporation 2005.11 */
790 /************************************************************************/
791 u32_t zfWriteRegInternalReg(zdev_t* dev, u32_t addr, u32_t val)
800 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_INTERNAL_WRITE, NULL);
805 /************************************************************************/
807 /* FUNCTION DESCRIPTION zfDelayWriteInternalReg */
808 /* Write on chip internal register, write operation may be */
809 /* postponed to form a multiple write command. */
812 /* dev : device pointer */
813 /* addr : register address */
817 /* 0 : command been postponed */
818 /* 1 : commands been executed */
821 /* Stephen Chen ZyDAS Technology Corporation 2005.11 */
823 /************************************************************************/
824 u16_t zfDelayWriteInternalReg(zdev_t* dev, u32_t addr, u32_t val)
826 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
830 zmw_get_wlan_dev(dev);
831 struct zsHpPriv* hpPriv=wd->hpPrivate;
833 zmw_declare_for_critical_section();
835 /* enter critical section */
836 zmw_enter_critical_section(dev);
838 /* Store command to global buffer */
839 hpPriv->cmd.delayWcmdAddr[hpPriv->cmd.delayWcmdCount] = addr;
840 hpPriv->cmd.delayWcmdVal[hpPriv->cmd.delayWcmdCount++] = val;
842 /* If pending command reach size limit */
843 if ((hpPriv->cmd.delayWcmdCount) >= ((ZM_MAX_CMD_SIZE - 4) >> 3))
845 cmd[0] = 0x00000100 + (hpPriv->cmd.delayWcmdCount<<3);
847 /* copy command to cmd buffer */
848 for (i=0; i<hpPriv->cmd.delayWcmdCount; i++)
850 cmd[1+(i<<1)] = hpPriv->cmd.delayWcmdAddr[i];
851 cmd[2+(i<<1)] = hpPriv->cmd.delayWcmdVal[i];
853 /* reset pending command */
854 hpPriv->cmd.delayWcmdCount = 0;
856 /* leave critical section */
857 zmw_leave_critical_section(dev);
859 /* issue write command */
860 ret = zfIssueCmd(dev, cmd, 4+(i<<3), ZM_OID_INTERNAL_WRITE, NULL);
866 /* leave critical section */
867 zmw_leave_critical_section(dev);
874 /************************************************************************/
876 /* FUNCTION DESCRIPTION zfFlushDelayWrite */
877 /* Flush pending write command. */
880 /* dev : device pointer */
883 /* 0 : no pending command */
884 /* 1 : commands been executed */
887 /* Stephen Chen ZyDAS Technology Corporation 2005.11 */
889 /************************************************************************/
890 u16_t zfFlushDelayWrite(zdev_t* dev)
892 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
895 zmw_get_wlan_dev(dev);
896 struct zsHpPriv* hpPriv=wd->hpPrivate;
898 zmw_declare_for_critical_section();
900 /* enter critical section */
901 zmw_enter_critical_section(dev);
903 /* If there is pending command */
904 if (hpPriv->cmd.delayWcmdCount > 0)
906 cmd[0] = 0x00000100 + (hpPriv->cmd.delayWcmdCount<<3);
908 /* copy command to cmd buffer */
909 for (i=0; i<hpPriv->cmd.delayWcmdCount; i++)
911 cmd[1+(i<<1)] = hpPriv->cmd.delayWcmdAddr[i];
912 cmd[2+(i<<1)] = hpPriv->cmd.delayWcmdVal[i];
914 /* reset pending command */
915 hpPriv->cmd.delayWcmdCount = 0;
917 /* leave critical section */
918 zmw_leave_critical_section(dev);
920 /* issue write command */
921 ret = zfIssueCmd(dev, cmd, 4+(i<<3), ZM_OID_INTERNAL_WRITE, NULL);
927 /* leave critical section */
928 zmw_leave_critical_section(dev);
935 u32_t zfiDbgDelayWriteReg(zdev_t* dev, u32_t addr, u32_t val)
937 zfDelayWriteInternalReg(dev, addr, val);
941 u32_t zfiDbgFlushDelayWrite(zdev_t* dev)
943 zfFlushDelayWrite(dev);
947 /************************************************************************/
949 /* FUNCTION DESCRIPTION zfiDbgWriteReg */
950 /* Write register. */
953 /* dev : device pointer */
954 /* addr : register address */
962 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
964 /************************************************************************/
965 u32_t zfiDbgWriteReg(zdev_t* dev, u32_t addr, u32_t val)
974 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_WRITE, 0);
977 /************************************************************************/
979 /* FUNCTION DESCRIPTION zfiDbgWriteFlash */
983 /* dev : device pointer */
984 /* addr : register address */
992 /* Yjsung ZyDAS Technology Corporation 2007.02 */
994 /************************************************************************/
995 u32_t zfiDbgWriteFlash(zdev_t* dev, u32_t addr, u32_t val)
1000 //cmd[0] = 0x0000B008;
1001 /* len[0] : type[0xB0] : seq[?] */
1002 cmd[0] = 8 | (ZM_CMD_WFLASH << 8);
1006 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_WRITE, 0);
1010 /************************************************************************/
1012 /* FUNCTION DESCRIPTION zfiDbgWriteEeprom */
1016 /* dev : device pointer */
1017 /* addr : register address */
1025 /* Paul ZyDAS Technology Corporation 2007.06 */
1027 /************************************************************************/
1028 u32_t zfiDbgWriteEeprom(zdev_t* dev, u32_t addr, u32_t val)
1033 //cmd[0] = 0x0000B008;
1034 /* len[0] : type[0xB0] : seq[?] */
1035 cmd[0] = 8 | (ZM_CMD_WREEPROM << 8);
1039 ret = zfIssueCmd(dev, cmd, 12, ZM_EEPROM_WRITE, 0);
1043 /************************************************************************/
1045 /* FUNCTION DESCRIPTION zfiDbgBlockWriteEeprom */
1046 /* Block Write Eeprom. */
1048 /* p.s: now,it will write 16 bytes register data per block (N=4) */
1051 /* dev : device pointer */
1052 /* addr : register address */
1053 /* buf : input data buffer pointer */
1060 /* Paul ZyDAS Technology Corporation 2007.06 */
1062 /************************************************************************/
1063 //#define N buflen/4
1064 //#define SIZE (2*N+1)
1066 u32_t zfiDbgBlockWriteEeprom(zdev_t* dev, u32_t addr, u32_t* buf)
1068 u32_t cmd[9]; //2N+1
1071 //cmd[0] = 0x0000B008;
1072 /* len[0] : type[0xB0] : seq[?] */
1074 //cmd[0] = (8*N) | (ZM_CMD_WFLASH << 8);
1075 cmd[0] = 32 | (ZM_CMD_WREEPROM << 8); //8N
1077 for (i=0; i<4; i++) // i<N
1079 cmd[(2*i)+1] = addr+(4*i);
1080 cmd[(2*i)+2] = *(buf+i);
1083 ret = zfIssueCmd(dev, cmd, 36, ZM_EEPROM_WRITE, 0); //8N+4
1085 // added for EEPROMUpdate, wait a moment for prevent cmd queue full!
1092 /* write EEPROM with wrlen : wrlen must be 4*n */
1093 /* command format : cmd_info(4) + addr(4) + eeprom(wrlen) */
1094 u32_t zfiDbgBlockWriteEeprom_v2(zdev_t* dev, u32_t addr, u32_t* buf, u32_t wrlen)
1099 /* len[0] : type[0xB0] : seq[?] */
1100 /* len = addr(4) + eeprom_block(wrlen) */
1101 cmd[0] = (wrlen+4) | (ZM_CMD_MEM_WREEPROM << 8);
1104 for (i=0; i<(wrlen/4); i++) // i<wrlen/4
1106 cmd[2+i] = *(buf+i);
1108 /* cmd_info(4) + addr(4) + eeprom(wrlen) */
1109 ret = zfIssueCmd(dev, cmd, (u16_t)(wrlen+8), ZM_EEPROM_WRITE, 0);
1114 /************************************************************************/
1116 /* FUNCTION DESCRIPTION zfDbgOpenEeprom */
1120 /* dev : device pointer */
1125 /* Paul ZyDAS Technology Corporation 2007.06 */
1127 /************************************************************************/
1128 void zfDbgOpenEeprom(zdev_t* dev)
1131 zfDelayWriteInternalReg(dev, 0x1D1400, 0x12345678);
1132 zfDelayWriteInternalReg(dev, 0x1D1404, 0x55aa00ff);
1133 zfDelayWriteInternalReg(dev, 0x1D1408, 0x13579ace);
1134 zfDelayWriteInternalReg(dev, 0x1D1414, 0x0);
1135 zfFlushDelayWrite(dev);
1138 /************************************************************************/
1140 /* FUNCTION DESCRIPTION zfDbgCloseEeprom */
1144 /* dev : device pointer */
1149 /* Paul ZyDAS Technology Corporation 2007.05 */
1151 /************************************************************************/
1152 void zfDbgCloseEeprom(zdev_t* dev)
1155 zfDelayWriteInternalReg(dev, 0x1D1400, 0x87654321);
1156 //zfDelayWriteInternalReg(dev, 0x1D1404, 0xffffffff);
1157 //zfDelayWriteInternalReg(dev, 0x1D1408, 0xffffffff);
1158 //zfDelayWriteInternalReg(dev, 0x1D1414, 0x100);
1159 zfFlushDelayWrite(dev);
1162 /************************************************************************/
1164 /* FUNCTION DESCRIPTION zfiSeriallyWriteEeprom */
1165 /* Write EEPROM Serially. */
1168 /* dev : device pointer */
1169 /* addr : start address of writing EEPROM */
1170 /* buf : input data buffer */
1171 /* buflen : size of input data buffer */
1172 /* (length of data write into EEPROM) */
1179 /* Paul ZyDAS Technology Corporation 2007.06 */
1181 /************************************************************************/
1182 u32_t zfiSeriallyWriteEeprom(zdev_t* dev, u32_t addr, u32_t* buf, u32_t buflen)
1185 u16_t i,ret,blocksize;
1188 // per 4 bytes = 1 count
1192 zfDbgOpenEeprom(dev);
1195 for (i=0; i<count; i++)
1197 if (zfwWriteEeprom(dev, (addr+(4*i)), *(buf+i), 0) != 0)
1199 // Update failed, Close EEPROM
1200 zm_debug_msg0("zfwWriteEeprom failed \n");
1201 zfDbgCloseEeprom(dev);
1207 zfDbgCloseEeprom(dev);
1212 /************************************************************************/
1214 /* FUNCTION DESCRIPTION zfiSeriallyBlockWriteEeprom */
1215 /* Block Write EEPROM Serially. */
1216 /* (BlockWrite: per 16bytes write EEPROM once) */
1219 /* dev : device pointer */
1220 /* addr : register address */
1221 /* buf : input data buffer */
1222 /* buflen : access data size of buf */
1229 /* Paul ZyDAS Technology Corporation 2007.05 */
1231 /************************************************************************/
1232 u32_t zfiSeriallyBlockWriteEeprom(zdev_t* dev, u32_t addr, u32_t* buf, u32_t buflen)
1235 u16_t i,ret,blocksize;
1238 // per 4 bytes = 1 count
1242 zfDbgOpenEeprom(dev);
1245 // EEPROM Write start address from: 0x1000!?
1246 // per 16bytes(N=4) block write EEPROM once
1247 for (i=0; i<(count/4); i++) // count/N
1249 //zfiDbgBlockWriteEeprom(dev, (addr+(4*N*i)), buf+(N*i));
1250 //zfiDbgBlockWriteEeprom(dev, (addr+(16*i)), buf+(4*i));
1251 if (zfwBlockWriteEeprom(dev, (addr+(16*i)), buf+(4*i), 0) != 0)
1253 zm_debug_msg0("zfiDbgBlockWriteEeprom failed \n");
1255 zfDbgCloseEeprom(dev);
1261 zfDbgCloseEeprom(dev);
1266 /************************************************************************/
1268 /* FUNCTION DESCRIPTION zfiDbgDumpEeprom */
1272 /* dev : device pointer */
1273 /* addr : start address of dumping EEPROM */
1274 /* datalen : length of access EEPROM data */
1275 /* buf : point of buffer, the buffer saved dump data */
1282 /* Paul ZyDAS Technology Corporation 2007.06 */
1284 /************************************************************************/
1285 u32_t zfiDbgDumpEeprom(zdev_t* dev, u32_t addr, u32_t datalen, u32_t* buf)
1292 // over EEPROM length
1293 if(datalen > 0x2000)
1298 for(i=0; i<count; i++)
1300 buf[i] = zfwReadEeprom(dev, addr+(4*i));
1306 /************************************************************************/
1308 /* FUNCTION DESCRIPTION zfiDbgReadReg */
1309 /* Read register. */
1312 /* dev : device pointer */
1313 /* addr : register address */
1320 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
1322 /************************************************************************/
1323 u32_t zfiDbgReadReg(zdev_t* dev, u32_t addr)
1328 cmd[0] = 0x00000004;
1331 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_READ, 0);
1336 /************************************************************************/
1338 /* FUNCTION DESCRIPTION zfiDbgReadTally */
1339 /* Read register. */
1342 /* dev : device pointer */
1349 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
1351 /************************************************************************/
1352 u32_t zfiDbgReadTally(zdev_t* dev)
1356 zmw_get_wlan_dev(dev);
1358 if ( ((struct zsHpPriv*)wd->hpPrivate)->halReInit )
1363 /* len[0] : type[0x81] : seq[?] */
1364 cmd[0] = 0 | (ZM_CMD_TALLY << 8);
1365 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_TALLY, 0);
1367 /* len[0] : type[0x82] : seq[?] */
1368 cmd[0] = 0 | (ZM_CMD_TALLY_APD << 8);
1369 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_TALLY_APD, 0);
1375 u32_t zfiDbgSetIFSynthesizer(zdev_t* dev, u32_t value)
1380 /* len[4] : type[0x32] : seq[?] */
1381 cmd[0] = 0x4 | (ZM_OID_SYNTH << 8);
1384 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_SYNTH, 0);
1388 u32_t zfiDbgQueryHwTxBusy(zdev_t* dev)
1393 /* len[4] : type[0xC0] : seq[?] */
1394 cmd[0] = 0 | (ZM_CMD_DKTX_STATUS << 8);
1396 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_DKTX_STATUS, 0);
1402 u16_t zfHpBlockEraseFlash(zdev_t *dev, u32_t addr)
1404 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1407 cmd[0] = 0x00000004 | (ZM_CMD_FLASH_ERASE << 8);
1410 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_INTERNAL_WRITE, NULL);
1416 u16_t zfiDbgProgramFlash(zdev_t *dev, u32_t offset, u32_t len, u32_t *data)
1418 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1423 cmd[0] = (ZM_CMD_FLASH_PROG << 8) | ((len+8) & 0xff);
1427 for (i = 0; i < (len >> 2); i++)
1432 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_FLASH_PROGRAM, NULL);
1438 /************************************************************************/
1440 /* FUNCTION DESCRIPTION zfiDbgChipEraseFlash */
1441 /* Chip Erase Flash. */
1444 /* dev : device pointer */
1451 /* Paul Atheros Technology Corporation 2007.09 */
1453 /************************************************************************/
1454 u16_t zfiDbgChipEraseFlash(zdev_t *dev)
1456 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1459 cmd[0] = 0x00000000 | (ZM_CMD_FLASH_ERASE << 8);
1461 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_INTERNAL_WRITE, NULL);
1464 /************************************************************************/
1466 /* FUNCTION DESCRIPTION zfiDbgGetFlashCheckSum */
1467 /* Get FlashCheckSum. */
1470 /* dev : device pointer */
1471 /* addr : Start address of getchksum */
1472 /* len : total lenth of calculate getchksum */
1479 /* Paul Atheros Technology Corporation 2007.08 */
1481 /************************************************************************/
1482 u32_t zfiDbgGetFlashCheckSum(zdev_t *dev, u32_t addr, u32_t len)
1484 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1487 cmd[0] = 0x00000008 | (ZM_CMD_FLASH_CHKSUM << 8);
1491 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_FLASH_CHKSUM, NULL);
1496 /************************************************************************/
1498 /* FUNCTION DESCRIPTION zfiDbgReadFlash */
1502 /* dev : device pointer */
1503 /* addr : Start address of read flash */
1504 /* len : total lenth of read flash data */
1511 /* Paul Atheros Technology Corporation 2007.09 */
1513 /************************************************************************/
1514 u32_t zfiDbgReadFlash(zdev_t *dev, u32_t addr, u32_t len)
1516 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1519 cmd[0] = len | (ZM_CMD_FLASH_READ << 8);
1522 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_FLASH_READ, NULL);
1526 /************************************************************************/
1528 /* FUNCTION DESCRIPTION zfiDownloadFwSet */
1529 /* Before Download FW, */
1530 /* Command FW to Software reset and close watch dog control. */
1534 /* dev : device pointer */
1541 /* Paul Atheros Technology Corporation 2007.09 */
1543 /************************************************************************/
1544 u32_t zfiDownloadFwSet(zdev_t *dev)
1548 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1551 cmd[0] = 0x00000008 | (ZM_CMD_FW_DL_INIT << 8);
1553 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_FW_DL_INIT, NULL);