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 struct zsHpPriv* hpPriv;
34 zmw_get_wlan_dev(dev);
35 hpPriv = (struct zsHpPriv*)(wd->hpPrivate);
37 zmw_declare_for_critical_section();
39 zmw_enter_critical_section(dev);
40 #ifdef ZM_XP_USB_MULTCMD
41 hpPriv->cmdTail = hpPriv->cmdHead = hpPriv->cmdSend = 0;
43 hpPriv->cmdTail = hpPriv->cmdHead = 0;
45 hpPriv->cmdPending = 0;
46 hpPriv->cmd.delayWcmdCount = 0;
47 zmw_leave_critical_section(dev);
50 u16_t zfPutCmd(zdev_t* dev, u32_t* cmd, u16_t cmdLen, u16_t src, u8_t* buf)
53 struct zsHpPriv* hpPriv;
55 zmw_get_wlan_dev(dev);
58 /* Make sure command length < ZM_MAX_CMD_SIZE */
59 zm_assert(cmdLen <= ZM_MAX_CMD_SIZE);
60 /* Make sure command queue not full */
61 //zm_assert(((hpPriv->cmdTail+1) & (ZM_CMD_QUEUE_SIZE-1)) != hpPriv->cmdHead);
62 if (((hpPriv->cmdTail+1) & (ZM_CMD_QUEUE_SIZE-1)) == hpPriv->cmdHead ) {
63 zm_debug_msg0("CMD queue full!!");
67 hpPriv->cmdQ[hpPriv->cmdTail].cmdLen = cmdLen;
68 hpPriv->cmdQ[hpPriv->cmdTail].src = src;
69 hpPriv->cmdQ[hpPriv->cmdTail].buf = buf;
70 for (i=0; i<(cmdLen>>2); i++)
72 hpPriv->cmdQ[hpPriv->cmdTail].cmd[i] = cmd[i];
75 hpPriv->cmdTail = (hpPriv->cmdTail+1) & (ZM_CMD_QUEUE_SIZE-1);
80 u16_t zfGetCmd(zdev_t* dev, u32_t* cmd, u16_t* cmdLen, u16_t* src, u8_t** buf)
83 struct zsHpPriv* hpPriv;
85 zmw_get_wlan_dev(dev);
88 if (hpPriv->cmdTail == hpPriv->cmdHead)
93 *cmdLen = hpPriv->cmdQ[hpPriv->cmdHead].cmdLen;
94 *src = hpPriv->cmdQ[hpPriv->cmdHead].src;
95 *buf = hpPriv->cmdQ[hpPriv->cmdHead].buf;
96 for (i=0; i<((*cmdLen)>>2); i++)
98 cmd[i] = hpPriv->cmdQ[hpPriv->cmdHead].cmd[i];
101 hpPriv->cmdHead = (hpPriv->cmdHead+1) & (ZM_CMD_QUEUE_SIZE-1);
106 #ifdef ZM_XP_USB_MULTCMD
107 void zfSendCmdEx(zdev_t* dev)
109 u32_t ncmd[ZM_MAX_CMD_SIZE/4];
113 struct zsHpPriv* hpPriv;
115 zmw_get_wlan_dev(dev);
116 hpPriv=wd->hpPrivate;
118 zmw_declare_for_critical_section();
120 zmw_enter_critical_section(dev);
122 if (hpPriv->cmdPending == 0)
124 if (hpPriv->cmdTail != hpPriv->cmdSend)
127 /* Get queueing command */
128 ncmdLen= hpPriv->cmdQ[hpPriv->cmdSend].cmdLen;
129 for (i=0; i<(ncmdLen>>2); i++)
131 ncmd[i] = hpPriv->cmdQ[hpPriv->cmdSend].cmd[i];
133 hpPriv->cmdSend = (hpPriv->cmdSend+1) & (ZM_CMD_QUEUE_SIZE-1);
135 hpPriv->cmdPending = 1;
139 zmw_leave_critical_section(dev);
143 zfIdlCmd(dev, ncmd, ncmdLen);
147 void zfiSendCmdComp(zdev_t* dev)
149 struct zsHpPriv* hpPriv;
151 zmw_get_wlan_dev(dev);
152 hpPriv=wd->hpPrivate;
154 zmw_declare_for_critical_section();
156 zmw_enter_critical_section(dev);
157 hpPriv->cmdPending = 0;
158 zmw_leave_critical_section(dev);
164 u16_t zfIssueCmd(zdev_t* dev, u32_t* cmd, u16_t cmdLen, u16_t src, u8_t* buf)
168 struct zsHpPriv* hpPriv;
170 zmw_get_wlan_dev(dev);
171 hpPriv=wd->hpPrivate;
173 zmw_declare_for_critical_section();
175 zm_msg2_mm(ZM_LV_1, "cmdLen=", cmdLen);
177 zmw_enter_critical_section(dev);
179 #ifdef ZM_XP_USB_MULTCMD
180 ret = zfPutCmd(dev, cmd, cmdLen, src, buf);
181 zmw_leave_critical_section(dev);
190 if (hpPriv->cmdPending == 0)
192 hpPriv->cmdPending = 1;
195 ret = zfPutCmd(dev, cmd, cmdLen, src, buf);
197 zmw_leave_critical_section(dev);
206 zfIdlCmd(dev, cmd, cmdLen);
212 void zfIdlRsp(zdev_t* dev, u32_t* rsp, u16_t rspLen)
214 u32_t cmd[ZM_MAX_CMD_SIZE/4];
218 u32_t ncmd[ZM_MAX_CMD_SIZE/4];
225 struct zsHpPriv* hpPriv;
227 zmw_get_wlan_dev(dev);
228 hpPriv=wd->hpPrivate;
231 zmw_declare_for_critical_section();
233 zmw_enter_critical_section(dev);
235 ret = zfGetCmd(dev, cmd, &cmdLen, &src, &buf);
241 zm_debug_msg0("Error IdlRsp because none cmd!!\n");
242 #ifndef ZM_XP_USB_MULTCMD
243 zmw_leave_critical_section(dev);
248 #ifdef ZM_XP_USB_MULTCMD
249 zmw_leave_critical_section(dev);
251 if (hpPriv->cmdTail != hpPriv->cmdHead)
254 /* Get queueing command */
255 ncmdLen= hpPriv->cmdQ[hpPriv->cmdHead].cmdLen;
256 for (i=0; i<(ncmdLen>>2); i++)
258 ncmd[i] = hpPriv->cmdQ[hpPriv->cmdHead].cmd[i];
263 hpPriv->cmdPending = 0;
266 zmw_leave_critical_section(dev);
270 zfIdlCmd(dev, ncmd, ncmdLen);
273 if (src == ZM_OID_READ)
275 ZM_PERFORMANCE_REG(dev, 0x11772c, rsp[1]);
276 zfwDbgReadRegDone(dev, cmd[1], rsp[1]);
278 else if (src == ZM_OID_FLASH_CHKSUM)
280 zfwDbgGetFlashChkSumDone(dev, rsp+1);
282 else if (src == ZM_OID_FLASH_READ)
287 datalen = (rsp[0] & 255);
289 zfwDbgReadFlashDone(dev, cmd[1], rsp+1, datalen);
291 else if (src == ZM_OID_FLASH_PROGRAM)
295 else if (src == ZM_OID_WRITE)
297 zfwDbgWriteRegDone(dev, cmd[1], cmd[2]);
299 else if (src == ZM_OID_TALLY)
301 zfCollectHWTally(dev, rsp, 0);
303 else if (src == ZM_OID_TALLY_APD)
305 zfCollectHWTally(dev, rsp, 1);
306 zfwDbgReadTallyDone(dev);
307 #ifdef ZM_ENABLE_BA_RATECTRL
308 zfRateCtrlAggrSta(dev);
311 else if (src == ZM_OID_DKTX_STATUS)
313 zm_debug_msg0("src = zm_OID_DKTX_STATUS");
314 zfwDbgQueryHwTxBusyDone(dev, rsp[1]);
316 else if (src == ZM_CMD_SET_FREQUENCY)
319 //#ifdef ZM_OTUS_ENABLE_RETRY_FREQ_CHANGE
321 zm_debug_msg1("Retry Set Frequency = ", rsp[1]);
324 // Read the Noise Floor value !
325 nf = ((rsp[2]>>19) & 0x1ff);
326 if ((nf & 0x100) != 0x0)
328 noisefloor[0] = 0 - ((nf ^ 0x1ff) + 1);
335 zm_debug_msg1("Noise Floor[1] = ", noisefloor[0]);
337 nf = ((rsp[3]>>19) & 0x1ff);
338 if ((nf & 0x100) != 0x0)
340 noisefloor[1] = 0 - ((nf ^ 0x1ff) + 1);
347 zm_debug_msg1("Noise Floor[2] = ", noisefloor[1]);
348 zm_debug_msg1("Is Site Survey = ", hpPriv->isSiteSurvey);
351 if ( (rsp[1] && hpPriv->freqRetryCounter == 0) ||
352 (((noisefloor[0]>-60)||(noisefloor[1]>-60)) && hpPriv->freqRetryCounter==0) ||
353 ((abs(noisefloor[0]-noisefloor[1])>=9) && hpPriv->freqRetryCounter==0) )
355 zm_debug_msg0("Retry to issue the frequency change command");
357 if ( hpPriv->recordFreqRetryCounter == 1 )
359 zm_debug_msg0("Cold Reset");
361 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
363 hpPriv->latestExtOffset,
366 if ( hpPriv->isSiteSurvey != 2 )
368 hpPriv->freqRetryCounter++;
370 hpPriv->recordFreqRetryCounter = 0;
374 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
376 hpPriv->latestExtOffset,
379 hpPriv->recordFreqRetryCounter++;
384 /* ret: Bit0: AGC calibration 0=>finish 1=>unfinish */
385 /* Bit1: Noise calibration 0=>finish 1=>unfinish */
386 /* Bit2: Noise calibration finish, but NF value unexcepted => 1 */
387 if ( (rsp[1] & 0x1) || (rsp[1] & 0x4) )
389 zm_debug_msg1("Set Frequency fail : ret = ", rsp[1]);
391 /* 1. AGC Calibration fail */
392 /* 2. Noise Calibration finish but error NoiseFloor value */
393 /* and not in sitesurvey, try more twice */
394 if ( hpPriv->isSiteSurvey == 2 )
396 if ( hpPriv->recordFreqRetryCounter < 2 )
399 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
401 hpPriv->latestExtOffset,
403 hpPriv->recordFreqRetryCounter++;
404 zm_debug_msg1("Retry to issue the frequency change command(cold reset) counter = ", hpPriv->recordFreqRetryCounter);
408 /* Fail : we would not accept this result! */
409 zm_debug_msg0("\n\n\n\n Fail twice cold reset \n\n\n\n");
410 hpPriv->coldResetNeedFreq = 0;
411 hpPriv->recordFreqRetryCounter = 0;
412 zfCoreSetFrequencyComplete(dev);
417 /* in sitesurvey, coldreset in next channel */
418 hpPriv->coldResetNeedFreq = 1;
419 hpPriv->recordFreqRetryCounter = 0;
420 zfCoreSetFrequencyComplete(dev);
423 else if (rsp[1] & 0x2)
425 zm_debug_msg1("Set Frequency fail 2 : ret = ", rsp[1]);
427 /* Noise Calibration un-finish */
428 /* and not in sitesurvey, try more once */
429 if ( hpPriv->isSiteSurvey == 2 )
431 if ( hpPriv->recordFreqRetryCounter < 1 )
434 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
436 hpPriv->latestExtOffset,
438 hpPriv->recordFreqRetryCounter++;
439 zm_debug_msg1("2 Retry to issue the frequency change command(cold reset) counter = ", hpPriv->recordFreqRetryCounter);
443 /* Fail : we would not accept this result! */
444 zm_debug_msg0("\n\n\n\n 2 Fail twice cold reset \n\n\n\n");
445 hpPriv->coldResetNeedFreq = 0;
446 hpPriv->recordFreqRetryCounter = 0;
447 zfCoreSetFrequencyComplete(dev);
452 /* in sitesurvey, skip this frequency */
453 hpPriv->coldResetNeedFreq = 0;
454 hpPriv->recordFreqRetryCounter = 0;
455 zfCoreSetFrequencyComplete(dev);
458 //else if (rsp[1] & 0x4)
460 // zm_debug_msg1("Set Frequency fail 3 : ret = ", rsp[1]);
461 // hpPriv->coldResetNeedFreq = 0;
462 // hpPriv->recordFreqRetryCounter = 0;
463 // zfCoreSetFrequencyComplete(dev);
467 //hpPriv->freqRetryCounter = 0;
468 zm_debug_msg2(" return complete, ret = ", rsp[1]);
470 /* set bb_heavy_clip_enable */
471 if (hpPriv->enableBBHeavyClip && hpPriv->hwBBHeavyClip &&
472 hpPriv->doBBHeavyClip)
474 u32_t setValue = 0x200;
476 setValue |= hpPriv->setValueHeavyClip;
478 //zm_dbg(("Do heavy clip setValue = %d\n", setValue));
480 zfDelayWriteInternalReg(dev, 0x99e0+0x1bc000, setValue);
481 zfFlushDelayWrite(dev);
484 hpPriv->coldResetNeedFreq = 0;
485 hpPriv->recordFreqRetryCounter = 0;
486 zfCoreSetFrequencyComplete(dev);
490 // Read the Noise Floor value !
491 nf = ((rsp[2]>>19) & 0x1ff);
492 if ((nf & 0x100) != 0x0)
494 noisefloor[0] = 0 - ((nf ^ 0x1ff) + 1);
501 //zm_debug_msg1("Noise Floor[1] = ", noisefloor[0]);
503 nf = ((rsp[3]>>19) & 0x1ff);
504 if ((nf & 0x100) != 0x0)
506 noisefloor[1] = 0 - ((nf ^ 0x1ff) + 1);
513 //zm_debug_msg1("Noise Floor[2] = ", noisefloor[1]);
515 nf = ((rsp[5]>>23) & 0x1ff);
516 if ((nf & 0x100) != 0x0)
518 noisefloor[2] = 0 - ((nf ^ 0x1ff) + 1);
525 //zm_debug_msg1("Noise Floor ext[1] = ", noisefloor[2]);
527 nf = ((rsp[6]>>23) & 0x1ff);
528 if ((nf & 0x100) != 0x0)
530 noisefloor[3] = 0 - ((nf ^ 0x1ff) + 1);
537 //zm_debug_msg1("Noise Floor ext[2] = ", noisefloor[3]);
539 //zm_debug_msg1("Is Site Survey = ", hpPriv->isSiteSurvey);
542 else if (src == ZM_CMD_SET_KEY)
544 zfCoreSetKeyComplete(dev);
546 else if (src == ZM_CWM_READ)
548 zm_msg2_mm(ZM_LV_0, "CWM rsp[1]=", rsp[1]);
549 zm_msg2_mm(ZM_LV_0, "CWM rsp[2]=", rsp[2]);
550 zfCoreCwmBusy(dev, zfCwmIsExtChanBusy(rsp[1], rsp[2]));
552 else if (src == ZM_MAC_READ)
554 /* rsp[1] = ZM_SEEPROM_MAC_ADDRESS_OFFSET; */
555 /* rsp[2] = ZM_SEEPROM_MAC_ADDRESS_OFFSET+4; */
556 /* rsp[3] = ZM_SEEPROM_REGDOMAIN_OFFSET; */
557 /* rsp[4] = ZM_SEEPROM_VERISON_OFFSET; */
558 /* rsp[5] = ZM_SEEPROM_HARDWARE_TYPE_OFFSET; */
559 /* rsp[6] = ZM_SEEPROM_HW_HEAVY_CLIP; */
561 u8_t addr[6], CCS, WWR;
562 u16_t CountryDomainCode;
565 //hpPriv->eepromHeavyClipFlag = (u8_t)((rsp[6]>>24) & 0xff); // force enable 8107
566 //zm_msg2_mm(ZM_LV_0, "eepromHeavyClipFlag", hpPriv->eepromHeavyClipFlag);
568 if (hpPriv->hwBBHeavyClip)
570 zm_msg0_mm(ZM_LV_0, "enable BB Heavy Clip");
574 zm_msg0_mm(ZM_LV_0, "Not enable BB Heavy Clip");
577 zm_msg2_mm(ZM_LV_0, "MAC rsp[1]=", rsp[1]);
578 zm_msg2_mm(ZM_LV_0, "MAC rsp[2]=", rsp[2]);
580 addr[0] = (u8_t)(rsp[1] & 0xff);
581 addr[1] = (u8_t)((rsp[1]>>8) & 0xff);
582 addr[2] = (u8_t)((rsp[1]>>16) & 0xff);
583 addr[3] = (u8_t)((rsp[1]>>24) & 0xff);
584 addr[4] = (u8_t)(rsp[2] & 0xff);
585 addr[5] = (u8_t)((rsp[2]>>8) & 0xff);
587 addr[0] = (u8_t)(0 & 0xff);
588 addr[1] = (u8_t)(3 & 0xff);
589 addr[2] = (u8_t)(127 & 0xff);
590 addr[3] = (u8_t)(0 & 0xff);
591 addr[4] = (u8_t)(9 & 0xff);
592 addr[5] = (u8_t)(11 & 0xff);
595 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_L,
596 ((((u32_t)addr[3])<<24) | (((u32_t)addr[2])<<16) | (((u32_t)addr[1])<<8) | addr[0]));
597 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_H,
598 ((((u32_t)addr[5])<<8) | addr[4]));
599 zfFlushDelayWrite(dev);
601 wd->ledStruct.ledMode[0] = (u16_t)(rsp[5]&0xffff);
602 wd->ledStruct.ledMode[1] = (u16_t)(rsp[5]>>16);
603 zm_msg2_mm(ZM_LV_0, "ledMode[0]=", wd->ledStruct.ledMode[0]);
604 zm_msg2_mm(ZM_LV_0, "ledMode[1]=", wd->ledStruct.ledMode[1]);
606 /* Regulatory Related Setting */
607 zm_msg2_mm(ZM_LV_0, "RegDomain rsp=", rsp[3]);
608 zm_msg2_mm(ZM_LV_0, "OpFlags+EepMisc=", rsp[4]);
609 hpPriv->OpFlags = (u8_t)((rsp[4]>>16) & 0xff);
610 if ((rsp[2] >> 24) == 0x1) //Tx mask == 0x1
612 zm_msg0_mm(ZM_LV_0, "OTUS 1x2");
613 hpPriv->halCapability |= ZM_HP_CAP_11N_ONE_TX_STREAM;
617 zm_msg0_mm(ZM_LV_0, "OTUS 2x2");
619 if (hpPriv->OpFlags & 0x1)
621 hpPriv->halCapability |= ZM_HP_CAP_5G;
623 if (hpPriv->OpFlags & 0x2)
625 hpPriv->halCapability |= ZM_HP_CAP_2G;
629 CCS = (u8_t)((rsp[3] & 0x8000) >> 15);
630 WWR = (u8_t)((rsp[3] & 0x4000) >> 14);
631 CountryDomainCode = (u16_t)(rsp[3] & 0x3FFF);
633 if (rsp[3] != 0xffffffff)
637 //zm_debug_msg0("CWY - Get Regulation Table from Country Code");
638 zfHpGetRegulationTablefromCountry(dev, CountryDomainCode);
642 //zm_debug_msg0("CWY - Get Regulation Table from Reg Domain");
643 zfHpGetRegulationTablefromRegionCode(dev, CountryDomainCode);
647 //zm_debug_msg0("CWY - Enable 802.11d");
648 /* below line shall be unmarked after A band is ready */
649 //zfiWlanSetDot11DMode(dev, 1);
654 zfHpGetRegulationTablefromRegionCode(dev, NO_ENUMRD);
657 zfCoreMacAddressNotify(dev, addr);
660 else if (src == ZM_EEPROM_READ)
663 u8_t addr[6], CCS, WWR;
664 u16_t CountryDomainCode;
666 for (i=0; i<ZM_HAL_MAX_EEPROM_PRQ; i++)
668 if (hpPriv->eepromImageIndex < 1024)
670 hpPriv->eepromImage[hpPriv->eepromImageIndex++] = rsp[i+1];
674 if (hpPriv->eepromImageIndex == (ZM_HAL_MAX_EEPROM_REQ*ZM_HAL_MAX_EEPROM_PRQ))
677 for (i=0; i<1024; i++)
679 zm_msg2_mm(ZM_LV_0, "index=", i);
680 zm_msg2_mm(ZM_LV_0, "eepromImage=", hpPriv->eepromImage[i]);
683 zm_msg2_mm(ZM_LV_0, "MAC [1]=", hpPriv->eepromImage[0x20c/4]);
684 zm_msg2_mm(ZM_LV_0, "MAC [2]=", hpPriv->eepromImage[0x210/4]);
686 addr[0] = (u8_t)(hpPriv->eepromImage[0x20c/4] & 0xff);
687 addr[1] = (u8_t)((hpPriv->eepromImage[0x20c/4]>>8) & 0xff);
688 addr[2] = (u8_t)((hpPriv->eepromImage[0x20c/4]>>16) & 0xff);
689 addr[3] = (u8_t)((hpPriv->eepromImage[0x20c/4]>>24) & 0xff);
690 addr[4] = (u8_t)(hpPriv->eepromImage[0x210/4] & 0xff);
691 addr[5] = (u8_t)((hpPriv->eepromImage[0x210/4]>>8) & 0xff);
693 zfCoreMacAddressNotify(dev, addr);
695 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_L,
696 ((((u32_t)addr[3])<<24) | (((u32_t)addr[2])<<16) | (((u32_t)addr[1])<<8) | addr[0]));
697 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_H,
698 ((((u32_t)addr[5])<<8) | addr[4]));
699 zfFlushDelayWrite(dev);
701 /* Regulatory Related Setting */
702 zm_msg2_mm(ZM_LV_0, "RegDomain =", hpPriv->eepromImage[0x208/4]);
703 CCS = (u8_t)((hpPriv->eepromImage[0x208/4] & 0x8000) >> 15);
704 WWR = (u8_t)((hpPriv->eepromImage[0x208/4] & 0x4000) >> 14);
705 /* below line shall be unmarked after A band is ready */
706 //CountryDomainCode = (u16_t)(hpPriv->eepromImage[0x208/4] & 0x3FFF);
707 CountryDomainCode = 8;
710 //zm_debug_msg0("CWY - Get Regulation Table from Country Code");
711 zfHpGetRegulationTablefromCountry(dev, CountryDomainCode);
715 //zm_debug_msg0("CWY - Get Regulation Table from Reg Domain");
716 zfHpGetRegulationTablefromRegionCode(dev, CountryDomainCode);
720 //zm_debug_msg0("CWY - Enable 802.11d");
721 /* below line shall be unmarked after A band is ready */
722 //zfiWlanSetDot11DMode(dev, 1);
725 zfCoreHalInitComplete(dev);
729 hpPriv->eepromImageRdReq++;
730 zfHpLoadEEPROMFromFW(dev);
733 else if (src == ZM_EEPROM_WRITE)
735 zfwDbgWriteEepromDone(dev, cmd[1], cmd[2]);
737 else if (src == ZM_ANI_READ)
739 u32_t cycleTime, ctlClear;
741 zm_msg2_mm(ZM_LV_0, "ANI rsp[1]=", rsp[1]);
742 zm_msg2_mm(ZM_LV_0, "ANI rsp[2]=", rsp[2]);
743 zm_msg2_mm(ZM_LV_0, "ANI rsp[3]=", rsp[3]);
744 zm_msg2_mm(ZM_LV_0, "ANI rsp[4]=", rsp[4]);
746 hpPriv->ctlBusy += rsp[1];
747 hpPriv->extBusy += rsp[2];
749 cycleTime = 100000; //100 miniseconds
751 if (cycleTime > rsp[1])
753 ctlClear = (cycleTime - rsp[1]) / 100;
760 zfHpAniArPoll(dev, ctlClear, rsp[3], rsp[4]);
762 else if (src == ZM_CMD_ECHO)
764 if ( ((struct zsHpPriv*)wd->hpPrivate)->halReInit )
766 zfCoreHalInitComplete(dev);
767 ((struct zsHpPriv*)wd->hpPrivate)->halReInit = 0;
771 zfHpLoadEEPROMFromFW(dev);
774 else if (src == ZM_OID_FW_DL_INIT)
776 zfwDbgDownloadFwInitDone(dev);
782 /************************************************************************/
784 /* FUNCTION DESCRIPTION zfWriteRegInternalReg */
785 /* Write on chip internal register immediately. */
788 /* dev : device pointer */
789 /* addr : register address */
797 /* Stephen Chen ZyDAS Technology Corporation 2005.11 */
799 /************************************************************************/
800 u32_t zfWriteRegInternalReg(zdev_t* dev, u32_t addr, u32_t val)
809 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_INTERNAL_WRITE, NULL);
814 /************************************************************************/
816 /* FUNCTION DESCRIPTION zfDelayWriteInternalReg */
817 /* Write on chip internal register, write operation may be */
818 /* postponed to form a multiple write command. */
821 /* dev : device pointer */
822 /* addr : register address */
826 /* 0 : command been postponed */
827 /* 1 : commands been executed */
830 /* Stephen Chen ZyDAS Technology Corporation 2005.11 */
832 /************************************************************************/
833 u16_t zfDelayWriteInternalReg(zdev_t* dev, u32_t addr, u32_t val)
835 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
838 struct zsHpPriv* hpPriv;
840 zmw_get_wlan_dev(dev);
841 hpPriv=wd->hpPrivate;
843 zmw_declare_for_critical_section();
845 /* enter critical section */
846 zmw_enter_critical_section(dev);
848 /* Store command to global buffer */
849 hpPriv->cmd.delayWcmdAddr[hpPriv->cmd.delayWcmdCount] = addr;
850 hpPriv->cmd.delayWcmdVal[hpPriv->cmd.delayWcmdCount++] = val;
852 /* If pending command reach size limit */
853 if ((hpPriv->cmd.delayWcmdCount) >= ((ZM_MAX_CMD_SIZE - 4) >> 3))
855 cmd[0] = 0x00000100 + (hpPriv->cmd.delayWcmdCount<<3);
857 /* copy command to cmd buffer */
858 for (i=0; i<hpPriv->cmd.delayWcmdCount; i++)
860 cmd[1+(i<<1)] = hpPriv->cmd.delayWcmdAddr[i];
861 cmd[2+(i<<1)] = hpPriv->cmd.delayWcmdVal[i];
863 /* reset pending command */
864 hpPriv->cmd.delayWcmdCount = 0;
866 /* leave critical section */
867 zmw_leave_critical_section(dev);
869 /* issue write command */
870 ret = zfIssueCmd(dev, cmd, 4+(i<<3), ZM_OID_INTERNAL_WRITE, NULL);
876 /* leave critical section */
877 zmw_leave_critical_section(dev);
884 /************************************************************************/
886 /* FUNCTION DESCRIPTION zfFlushDelayWrite */
887 /* Flush pending write command. */
890 /* dev : device pointer */
893 /* 0 : no pending command */
894 /* 1 : commands been executed */
897 /* Stephen Chen ZyDAS Technology Corporation 2005.11 */
899 /************************************************************************/
900 u16_t zfFlushDelayWrite(zdev_t* dev)
902 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
905 struct zsHpPriv* hpPriv;
907 zmw_get_wlan_dev(dev);
908 hpPriv=wd->hpPrivate;
910 zmw_declare_for_critical_section();
912 /* enter critical section */
913 zmw_enter_critical_section(dev);
915 /* If there is pending command */
916 if (hpPriv->cmd.delayWcmdCount > 0)
918 cmd[0] = 0x00000100 + (hpPriv->cmd.delayWcmdCount<<3);
920 /* copy command to cmd buffer */
921 for (i=0; i<hpPriv->cmd.delayWcmdCount; i++)
923 cmd[1+(i<<1)] = hpPriv->cmd.delayWcmdAddr[i];
924 cmd[2+(i<<1)] = hpPriv->cmd.delayWcmdVal[i];
926 /* reset pending command */
927 hpPriv->cmd.delayWcmdCount = 0;
929 /* leave critical section */
930 zmw_leave_critical_section(dev);
932 /* issue write command */
933 ret = zfIssueCmd(dev, cmd, 4+(i<<3), ZM_OID_INTERNAL_WRITE, NULL);
939 /* leave critical section */
940 zmw_leave_critical_section(dev);
947 u32_t zfiDbgDelayWriteReg(zdev_t* dev, u32_t addr, u32_t val)
949 zfDelayWriteInternalReg(dev, addr, val);
953 u32_t zfiDbgFlushDelayWrite(zdev_t* dev)
955 zfFlushDelayWrite(dev);
959 /************************************************************************/
961 /* FUNCTION DESCRIPTION zfiDbgWriteReg */
962 /* Write register. */
965 /* dev : device pointer */
966 /* addr : register address */
974 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
976 /************************************************************************/
977 u32_t zfiDbgWriteReg(zdev_t* dev, u32_t addr, u32_t val)
986 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_WRITE, 0);
989 /************************************************************************/
991 /* FUNCTION DESCRIPTION zfiDbgWriteFlash */
995 /* dev : device pointer */
996 /* addr : register address */
1004 /* Yjsung ZyDAS Technology Corporation 2007.02 */
1006 /************************************************************************/
1007 u32_t zfiDbgWriteFlash(zdev_t* dev, u32_t addr, u32_t val)
1012 //cmd[0] = 0x0000B008;
1013 /* len[0] : type[0xB0] : seq[?] */
1014 cmd[0] = 8 | (ZM_CMD_WFLASH << 8);
1018 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_WRITE, 0);
1022 /************************************************************************/
1024 /* FUNCTION DESCRIPTION zfiDbgWriteEeprom */
1028 /* dev : device pointer */
1029 /* addr : register address */
1037 /* Paul ZyDAS Technology Corporation 2007.06 */
1039 /************************************************************************/
1040 u32_t zfiDbgWriteEeprom(zdev_t* dev, u32_t addr, u32_t val)
1045 //cmd[0] = 0x0000B008;
1046 /* len[0] : type[0xB0] : seq[?] */
1047 cmd[0] = 8 | (ZM_CMD_WREEPROM << 8);
1051 ret = zfIssueCmd(dev, cmd, 12, ZM_EEPROM_WRITE, 0);
1055 /************************************************************************/
1057 /* FUNCTION DESCRIPTION zfiDbgBlockWriteEeprom */
1058 /* Block Write Eeprom. */
1060 /* p.s: now,it will write 16 bytes register data per block (N=4) */
1063 /* dev : device pointer */
1064 /* addr : register address */
1065 /* buf : input data buffer pointer */
1072 /* Paul ZyDAS Technology Corporation 2007.06 */
1074 /************************************************************************/
1075 //#define N buflen/4
1076 //#define SIZE (2*N+1)
1078 u32_t zfiDbgBlockWriteEeprom(zdev_t* dev, u32_t addr, u32_t* buf)
1080 u32_t cmd[9]; //2N+1
1083 //cmd[0] = 0x0000B008;
1084 /* len[0] : type[0xB0] : seq[?] */
1086 //cmd[0] = (8*N) | (ZM_CMD_WFLASH << 8);
1087 cmd[0] = 32 | (ZM_CMD_WREEPROM << 8); //8N
1089 for (i=0; i<4; i++) // i<N
1091 cmd[(2*i)+1] = addr+(4*i);
1092 cmd[(2*i)+2] = *(buf+i);
1095 ret = zfIssueCmd(dev, cmd, 36, ZM_EEPROM_WRITE, 0); //8N+4
1097 // added for EEPROMUpdate, wait a moment for prevent cmd queue full!
1104 /* write EEPROM with wrlen : wrlen must be 4*n */
1105 /* command format : cmd_info(4) + addr(4) + eeprom(wrlen) */
1106 u32_t zfiDbgBlockWriteEeprom_v2(zdev_t* dev, u32_t addr, u32_t* buf, u32_t wrlen)
1111 /* len[0] : type[0xB0] : seq[?] */
1112 /* len = addr(4) + eeprom_block(wrlen) */
1113 cmd[0] = (wrlen+4) | (ZM_CMD_MEM_WREEPROM << 8);
1116 for (i=0; i<(wrlen/4); i++) // i<wrlen/4
1118 cmd[2+i] = *(buf+i);
1120 /* cmd_info(4) + addr(4) + eeprom(wrlen) */
1121 ret = zfIssueCmd(dev, cmd, (u16_t)(wrlen+8), ZM_EEPROM_WRITE, 0);
1126 /************************************************************************/
1128 /* FUNCTION DESCRIPTION zfDbgOpenEeprom */
1132 /* dev : device pointer */
1137 /* Paul ZyDAS Technology Corporation 2007.06 */
1139 /************************************************************************/
1140 void zfDbgOpenEeprom(zdev_t* dev)
1143 zfDelayWriteInternalReg(dev, 0x1D1400, 0x12345678);
1144 zfDelayWriteInternalReg(dev, 0x1D1404, 0x55aa00ff);
1145 zfDelayWriteInternalReg(dev, 0x1D1408, 0x13579ace);
1146 zfDelayWriteInternalReg(dev, 0x1D1414, 0x0);
1147 zfFlushDelayWrite(dev);
1150 /************************************************************************/
1152 /* FUNCTION DESCRIPTION zfDbgCloseEeprom */
1156 /* dev : device pointer */
1161 /* Paul ZyDAS Technology Corporation 2007.05 */
1163 /************************************************************************/
1164 void zfDbgCloseEeprom(zdev_t* dev)
1167 zfDelayWriteInternalReg(dev, 0x1D1400, 0x87654321);
1168 //zfDelayWriteInternalReg(dev, 0x1D1404, 0xffffffff);
1169 //zfDelayWriteInternalReg(dev, 0x1D1408, 0xffffffff);
1170 //zfDelayWriteInternalReg(dev, 0x1D1414, 0x100);
1171 zfFlushDelayWrite(dev);
1174 /************************************************************************/
1176 /* FUNCTION DESCRIPTION zfiSeriallyWriteEeprom */
1177 /* Write EEPROM Serially. */
1180 /* dev : device pointer */
1181 /* addr : start address of writing EEPROM */
1182 /* buf : input data buffer */
1183 /* buflen : size of input data buffer */
1184 /* (length of data write into EEPROM) */
1191 /* Paul ZyDAS Technology Corporation 2007.06 */
1193 /************************************************************************/
1194 u32_t zfiSeriallyWriteEeprom(zdev_t* dev, u32_t addr, u32_t* buf, u32_t buflen)
1197 u16_t i,ret,blocksize;
1200 // per 4 bytes = 1 count
1204 zfDbgOpenEeprom(dev);
1207 for (i=0; i<count; i++)
1209 if (zfwWriteEeprom(dev, (addr+(4*i)), *(buf+i), 0) != 0)
1211 // Update failed, Close EEPROM
1212 zm_debug_msg0("zfwWriteEeprom failed \n");
1213 zfDbgCloseEeprom(dev);
1219 zfDbgCloseEeprom(dev);
1224 /************************************************************************/
1226 /* FUNCTION DESCRIPTION zfiSeriallyBlockWriteEeprom */
1227 /* Block Write EEPROM Serially. */
1228 /* (BlockWrite: per 16bytes write EEPROM once) */
1231 /* dev : device pointer */
1232 /* addr : register address */
1233 /* buf : input data buffer */
1234 /* buflen : access data size of buf */
1241 /* Paul ZyDAS Technology Corporation 2007.05 */
1243 /************************************************************************/
1244 u32_t zfiSeriallyBlockWriteEeprom(zdev_t* dev, u32_t addr, u32_t* buf, u32_t buflen)
1247 u16_t i,ret,blocksize;
1250 // per 4 bytes = 1 count
1254 zfDbgOpenEeprom(dev);
1257 // EEPROM Write start address from: 0x1000!?
1258 // per 16bytes(N=4) block write EEPROM once
1259 for (i=0; i<(count/4); i++) // count/N
1261 //zfiDbgBlockWriteEeprom(dev, (addr+(4*N*i)), buf+(N*i));
1262 //zfiDbgBlockWriteEeprom(dev, (addr+(16*i)), buf+(4*i));
1263 if (zfwBlockWriteEeprom(dev, (addr+(16*i)), buf+(4*i), 0) != 0)
1265 zm_debug_msg0("zfiDbgBlockWriteEeprom failed \n");
1267 zfDbgCloseEeprom(dev);
1273 zfDbgCloseEeprom(dev);
1278 /************************************************************************/
1280 /* FUNCTION DESCRIPTION zfiDbgDumpEeprom */
1284 /* dev : device pointer */
1285 /* addr : start address of dumping EEPROM */
1286 /* datalen : length of access EEPROM data */
1287 /* buf : point of buffer, the buffer saved dump data */
1294 /* Paul ZyDAS Technology Corporation 2007.06 */
1296 /************************************************************************/
1297 u32_t zfiDbgDumpEeprom(zdev_t* dev, u32_t addr, u32_t datalen, u32_t* buf)
1304 // over EEPROM length
1305 if(datalen > 0x2000)
1310 for(i=0; i<count; i++)
1312 buf[i] = zfwReadEeprom(dev, addr+(4*i));
1318 /************************************************************************/
1320 /* FUNCTION DESCRIPTION zfiDbgReadReg */
1321 /* Read register. */
1324 /* dev : device pointer */
1325 /* addr : register address */
1332 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
1334 /************************************************************************/
1335 u32_t zfiDbgReadReg(zdev_t* dev, u32_t addr)
1340 cmd[0] = 0x00000004;
1343 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_READ, 0);
1348 /************************************************************************/
1350 /* FUNCTION DESCRIPTION zfiDbgReadTally */
1351 /* Read register. */
1354 /* dev : device pointer */
1361 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
1363 /************************************************************************/
1364 u32_t zfiDbgReadTally(zdev_t* dev)
1368 zmw_get_wlan_dev(dev);
1370 if ( ((struct zsHpPriv*)wd->hpPrivate)->halReInit )
1375 /* len[0] : type[0x81] : seq[?] */
1376 cmd[0] = 0 | (ZM_CMD_TALLY << 8);
1377 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_TALLY, 0);
1379 /* len[0] : type[0x82] : seq[?] */
1380 cmd[0] = 0 | (ZM_CMD_TALLY_APD << 8);
1381 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_TALLY_APD, 0);
1387 u32_t zfiDbgSetIFSynthesizer(zdev_t* dev, u32_t value)
1392 /* len[4] : type[0x32] : seq[?] */
1393 cmd[0] = 0x4 | (ZM_OID_SYNTH << 8);
1396 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_SYNTH, 0);
1400 u32_t zfiDbgQueryHwTxBusy(zdev_t* dev)
1405 /* len[4] : type[0xC0] : seq[?] */
1406 cmd[0] = 0 | (ZM_CMD_DKTX_STATUS << 8);
1408 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_DKTX_STATUS, 0);
1414 u16_t zfHpBlockEraseFlash(zdev_t *dev, u32_t addr)
1416 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1419 cmd[0] = 0x00000004 | (ZM_CMD_FLASH_ERASE << 8);
1422 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_INTERNAL_WRITE, NULL);
1428 u16_t zfiDbgProgramFlash(zdev_t *dev, u32_t offset, u32_t len, u32_t *data)
1430 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1435 cmd[0] = (ZM_CMD_FLASH_PROG << 8) | ((len+8) & 0xff);
1439 for (i = 0; i < (len >> 2); i++)
1444 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_FLASH_PROGRAM, NULL);
1450 /************************************************************************/
1452 /* FUNCTION DESCRIPTION zfiDbgChipEraseFlash */
1453 /* Chip Erase Flash. */
1456 /* dev : device pointer */
1463 /* Paul Atheros Technology Corporation 2007.09 */
1465 /************************************************************************/
1466 u16_t zfiDbgChipEraseFlash(zdev_t *dev)
1468 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1471 cmd[0] = 0x00000000 | (ZM_CMD_FLASH_ERASE << 8);
1473 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_INTERNAL_WRITE, NULL);
1476 /************************************************************************/
1478 /* FUNCTION DESCRIPTION zfiDbgGetFlashCheckSum */
1479 /* Get FlashCheckSum. */
1482 /* dev : device pointer */
1483 /* addr : Start address of getchksum */
1484 /* len : total lenth of calculate getchksum */
1491 /* Paul Atheros Technology Corporation 2007.08 */
1493 /************************************************************************/
1494 u32_t zfiDbgGetFlashCheckSum(zdev_t *dev, u32_t addr, u32_t len)
1496 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1499 cmd[0] = 0x00000008 | (ZM_CMD_FLASH_CHKSUM << 8);
1503 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_FLASH_CHKSUM, NULL);
1508 /************************************************************************/
1510 /* FUNCTION DESCRIPTION zfiDbgReadFlash */
1514 /* dev : device pointer */
1515 /* addr : Start address of read flash */
1516 /* len : total lenth of read flash data */
1523 /* Paul Atheros Technology Corporation 2007.09 */
1525 /************************************************************************/
1526 u32_t zfiDbgReadFlash(zdev_t *dev, u32_t addr, u32_t len)
1528 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1531 cmd[0] = len | (ZM_CMD_FLASH_READ << 8);
1534 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_FLASH_READ, NULL);
1538 /************************************************************************/
1540 /* FUNCTION DESCRIPTION zfiDownloadFwSet */
1541 /* Before Download FW, */
1542 /* Command FW to Software reset and close watch dog control. */
1546 /* dev : device pointer */
1553 /* Paul Atheros Technology Corporation 2007.09 */
1555 /************************************************************************/
1556 u32_t zfiDownloadFwSet(zdev_t *dev)
1560 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1563 cmd[0] = 0x00000008 | (ZM_CMD_FW_DL_INIT << 8);
1565 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_FW_DL_INIT, NULL);