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)
286 datalen = (rsp[0] & 255);
288 zfwDbgReadFlashDone(dev, cmd[1], rsp+1, datalen);
290 else if (src == ZM_OID_FLASH_PROGRAM)
294 else if (src == ZM_OID_WRITE)
296 zfwDbgWriteRegDone(dev, cmd[1], cmd[2]);
298 else if (src == ZM_OID_TALLY)
300 zfCollectHWTally(dev, rsp, 0);
302 else if (src == ZM_OID_TALLY_APD)
304 zfCollectHWTally(dev, rsp, 1);
305 zfwDbgReadTallyDone(dev);
306 #ifdef ZM_ENABLE_BA_RATECTRL
307 zfRateCtrlAggrSta(dev);
310 else if (src == ZM_OID_DKTX_STATUS)
312 zm_debug_msg0("src = zm_OID_DKTX_STATUS");
313 zfwDbgQueryHwTxBusyDone(dev, rsp[1]);
315 else if (src == ZM_CMD_SET_FREQUENCY)
318 //#ifdef ZM_OTUS_ENABLE_RETRY_FREQ_CHANGE
320 zm_debug_msg1("Retry Set Frequency = ", rsp[1]);
323 // Read the Noise Floor value !
324 nf = ((rsp[2]>>19) & 0x1ff);
325 if ((nf & 0x100) != 0x0)
327 noisefloor[0] = 0 - ((nf ^ 0x1ff) + 1);
334 zm_debug_msg1("Noise Floor[1] = ", noisefloor[0]);
336 nf = ((rsp[3]>>19) & 0x1ff);
337 if ((nf & 0x100) != 0x0)
339 noisefloor[1] = 0 - ((nf ^ 0x1ff) + 1);
346 zm_debug_msg1("Noise Floor[2] = ", noisefloor[1]);
347 zm_debug_msg1("Is Site Survey = ", hpPriv->isSiteSurvey);
350 if ( (rsp[1] && hpPriv->freqRetryCounter == 0) ||
351 (((noisefloor[0]>-60)||(noisefloor[1]>-60)) && hpPriv->freqRetryCounter==0) ||
352 ((abs(noisefloor[0]-noisefloor[1])>=9) && hpPriv->freqRetryCounter==0) )
354 zm_debug_msg0("Retry to issue the frequency change command");
356 if ( hpPriv->recordFreqRetryCounter == 1 )
358 zm_debug_msg0("Cold Reset");
360 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
362 hpPriv->latestExtOffset,
365 if ( hpPriv->isSiteSurvey != 2 )
367 hpPriv->freqRetryCounter++;
369 hpPriv->recordFreqRetryCounter = 0;
373 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
375 hpPriv->latestExtOffset,
378 hpPriv->recordFreqRetryCounter++;
383 /* ret: Bit0: AGC calibration 0=>finish 1=>unfinish */
384 /* Bit1: Noise calibration 0=>finish 1=>unfinish */
385 /* Bit2: Noise calibration finish, but NF value unexcepted => 1 */
386 if ( (rsp[1] & 0x1) || (rsp[1] & 0x4) )
388 zm_debug_msg1("Set Frequency fail : ret = ", rsp[1]);
390 /* 1. AGC Calibration fail */
391 /* 2. Noise Calibration finish but error NoiseFloor value */
392 /* and not in sitesurvey, try more twice */
393 if ( hpPriv->isSiteSurvey == 2 )
395 if ( hpPriv->recordFreqRetryCounter < 2 )
398 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
400 hpPriv->latestExtOffset,
402 hpPriv->recordFreqRetryCounter++;
403 zm_debug_msg1("Retry to issue the frequency change command(cold reset) counter = ", hpPriv->recordFreqRetryCounter);
407 /* Fail : we would not accept this result! */
408 zm_debug_msg0("\n\n\n\n Fail twice cold reset \n\n\n\n");
409 hpPriv->coldResetNeedFreq = 0;
410 hpPriv->recordFreqRetryCounter = 0;
411 zfCoreSetFrequencyComplete(dev);
416 /* in sitesurvey, coldreset in next channel */
417 hpPriv->coldResetNeedFreq = 1;
418 hpPriv->recordFreqRetryCounter = 0;
419 zfCoreSetFrequencyComplete(dev);
422 else if (rsp[1] & 0x2)
424 zm_debug_msg1("Set Frequency fail 2 : ret = ", rsp[1]);
426 /* Noise Calibration un-finish */
427 /* and not in sitesurvey, try more once */
428 if ( hpPriv->isSiteSurvey == 2 )
430 if ( hpPriv->recordFreqRetryCounter < 1 )
433 zfHpSetFrequencyEx(dev, hpPriv->latestFrequency,
435 hpPriv->latestExtOffset,
437 hpPriv->recordFreqRetryCounter++;
438 zm_debug_msg1("2 Retry to issue the frequency change command(cold reset) counter = ", hpPriv->recordFreqRetryCounter);
442 /* Fail : we would not accept this result! */
443 zm_debug_msg0("\n\n\n\n 2 Fail twice cold reset \n\n\n\n");
444 hpPriv->coldResetNeedFreq = 0;
445 hpPriv->recordFreqRetryCounter = 0;
446 zfCoreSetFrequencyComplete(dev);
451 /* in sitesurvey, skip this frequency */
452 hpPriv->coldResetNeedFreq = 0;
453 hpPriv->recordFreqRetryCounter = 0;
454 zfCoreSetFrequencyComplete(dev);
457 //else if (rsp[1] & 0x4)
459 // zm_debug_msg1("Set Frequency fail 3 : ret = ", rsp[1]);
460 // hpPriv->coldResetNeedFreq = 0;
461 // hpPriv->recordFreqRetryCounter = 0;
462 // zfCoreSetFrequencyComplete(dev);
466 //hpPriv->freqRetryCounter = 0;
467 zm_debug_msg2(" return complete, ret = ", rsp[1]);
469 /* set bb_heavy_clip_enable */
470 if (hpPriv->enableBBHeavyClip && hpPriv->hwBBHeavyClip &&
471 hpPriv->doBBHeavyClip)
473 u32_t setValue = 0x200;
475 setValue |= hpPriv->setValueHeavyClip;
477 //zm_dbg(("Do heavy clip setValue = %d\n", setValue));
479 zfDelayWriteInternalReg(dev, 0x99e0+0x1bc000, setValue);
480 zfFlushDelayWrite(dev);
483 hpPriv->coldResetNeedFreq = 0;
484 hpPriv->recordFreqRetryCounter = 0;
485 zfCoreSetFrequencyComplete(dev);
489 // Read the Noise Floor value !
490 nf = ((rsp[2]>>19) & 0x1ff);
491 if ((nf & 0x100) != 0x0)
493 noisefloor[0] = 0 - ((nf ^ 0x1ff) + 1);
500 //zm_debug_msg1("Noise Floor[1] = ", noisefloor[0]);
502 nf = ((rsp[3]>>19) & 0x1ff);
503 if ((nf & 0x100) != 0x0)
505 noisefloor[1] = 0 - ((nf ^ 0x1ff) + 1);
512 //zm_debug_msg1("Noise Floor[2] = ", noisefloor[1]);
514 nf = ((rsp[5]>>23) & 0x1ff);
515 if ((nf & 0x100) != 0x0)
517 noisefloor[2] = 0 - ((nf ^ 0x1ff) + 1);
524 //zm_debug_msg1("Noise Floor ext[1] = ", noisefloor[2]);
526 nf = ((rsp[6]>>23) & 0x1ff);
527 if ((nf & 0x100) != 0x0)
529 noisefloor[3] = 0 - ((nf ^ 0x1ff) + 1);
536 //zm_debug_msg1("Noise Floor ext[2] = ", noisefloor[3]);
538 //zm_debug_msg1("Is Site Survey = ", hpPriv->isSiteSurvey);
541 else if (src == ZM_CMD_SET_KEY)
543 zfCoreSetKeyComplete(dev);
545 else if (src == ZM_CWM_READ)
547 zm_msg2_mm(ZM_LV_0, "CWM rsp[1]=", rsp[1]);
548 zm_msg2_mm(ZM_LV_0, "CWM rsp[2]=", rsp[2]);
549 zfCoreCwmBusy(dev, zfCwmIsExtChanBusy(rsp[1], rsp[2]));
551 else if (src == ZM_MAC_READ)
553 /* rsp[1] = ZM_SEEPROM_MAC_ADDRESS_OFFSET; */
554 /* rsp[2] = ZM_SEEPROM_MAC_ADDRESS_OFFSET+4; */
555 /* rsp[3] = ZM_SEEPROM_REGDOMAIN_OFFSET; */
556 /* rsp[4] = ZM_SEEPROM_VERISON_OFFSET; */
557 /* rsp[5] = ZM_SEEPROM_HARDWARE_TYPE_OFFSET; */
558 /* rsp[6] = ZM_SEEPROM_HW_HEAVY_CLIP; */
560 u8_t addr[6], CCS, WWR;
561 u16_t CountryDomainCode;
564 //hpPriv->eepromHeavyClipFlag = (u8_t)((rsp[6]>>24) & 0xff); // force enable 8107
565 //zm_msg2_mm(ZM_LV_0, "eepromHeavyClipFlag", hpPriv->eepromHeavyClipFlag);
567 if (hpPriv->hwBBHeavyClip)
569 zm_msg0_mm(ZM_LV_0, "enable BB Heavy Clip");
573 zm_msg0_mm(ZM_LV_0, "Not enable BB Heavy Clip");
576 zm_msg2_mm(ZM_LV_0, "MAC rsp[1]=", rsp[1]);
577 zm_msg2_mm(ZM_LV_0, "MAC rsp[2]=", rsp[2]);
579 addr[0] = (u8_t)(rsp[1] & 0xff);
580 addr[1] = (u8_t)((rsp[1]>>8) & 0xff);
581 addr[2] = (u8_t)((rsp[1]>>16) & 0xff);
582 addr[3] = (u8_t)((rsp[1]>>24) & 0xff);
583 addr[4] = (u8_t)(rsp[2] & 0xff);
584 addr[5] = (u8_t)((rsp[2]>>8) & 0xff);
586 addr[0] = (u8_t)(0 & 0xff);
587 addr[1] = (u8_t)(3 & 0xff);
588 addr[2] = (u8_t)(127 & 0xff);
589 addr[3] = (u8_t)(0 & 0xff);
590 addr[4] = (u8_t)(9 & 0xff);
591 addr[5] = (u8_t)(11 & 0xff);
594 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_L,
595 ((((u32_t)addr[3])<<24) | (((u32_t)addr[2])<<16) | (((u32_t)addr[1])<<8) | addr[0]));
596 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_H,
597 ((((u32_t)addr[5])<<8) | addr[4]));
598 zfFlushDelayWrite(dev);
600 wd->ledStruct.ledMode[0] = (u16_t)(rsp[5]&0xffff);
601 wd->ledStruct.ledMode[1] = (u16_t)(rsp[5]>>16);
602 zm_msg2_mm(ZM_LV_0, "ledMode[0]=", wd->ledStruct.ledMode[0]);
603 zm_msg2_mm(ZM_LV_0, "ledMode[1]=", wd->ledStruct.ledMode[1]);
605 /* Regulatory Related Setting */
606 zm_msg2_mm(ZM_LV_0, "RegDomain rsp=", rsp[3]);
607 zm_msg2_mm(ZM_LV_0, "OpFlags+EepMisc=", rsp[4]);
608 hpPriv->OpFlags = (u8_t)((rsp[4]>>16) & 0xff);
609 if ((rsp[2] >> 24) == 0x1) //Tx mask == 0x1
611 zm_msg0_mm(ZM_LV_0, "OTUS 1x2");
612 hpPriv->halCapability |= ZM_HP_CAP_11N_ONE_TX_STREAM;
616 zm_msg0_mm(ZM_LV_0, "OTUS 2x2");
618 if (hpPriv->OpFlags & 0x1)
620 hpPriv->halCapability |= ZM_HP_CAP_5G;
622 if (hpPriv->OpFlags & 0x2)
624 hpPriv->halCapability |= ZM_HP_CAP_2G;
628 CCS = (u8_t)((rsp[3] & 0x8000) >> 15);
629 WWR = (u8_t)((rsp[3] & 0x4000) >> 14);
630 CountryDomainCode = (u16_t)(rsp[3] & 0x3FFF);
632 if (rsp[3] != 0xffffffff)
636 //zm_debug_msg0("CWY - Get Regulation Table from Country Code");
637 zfHpGetRegulationTablefromCountry(dev, CountryDomainCode);
641 //zm_debug_msg0("CWY - Get Regulation Table from Reg Domain");
642 zfHpGetRegulationTablefromRegionCode(dev, CountryDomainCode);
646 //zm_debug_msg0("CWY - Enable 802.11d");
647 /* below line shall be unmarked after A band is ready */
648 //zfiWlanSetDot11DMode(dev, 1);
653 zfHpGetRegulationTablefromRegionCode(dev, NO_ENUMRD);
656 zfCoreMacAddressNotify(dev, addr);
659 else if (src == ZM_EEPROM_READ)
662 u8_t addr[6], CCS, WWR;
663 u16_t CountryDomainCode;
665 for (i=0; i<ZM_HAL_MAX_EEPROM_PRQ; i++)
667 if (hpPriv->eepromImageIndex < 1024)
669 hpPriv->eepromImage[hpPriv->eepromImageIndex++] = rsp[i+1];
673 if (hpPriv->eepromImageIndex == (ZM_HAL_MAX_EEPROM_REQ*ZM_HAL_MAX_EEPROM_PRQ))
676 for (i=0; i<1024; i++)
678 zm_msg2_mm(ZM_LV_0, "index=", i);
679 zm_msg2_mm(ZM_LV_0, "eepromImage=", hpPriv->eepromImage[i]);
682 zm_msg2_mm(ZM_LV_0, "MAC [1]=", hpPriv->eepromImage[0x20c/4]);
683 zm_msg2_mm(ZM_LV_0, "MAC [2]=", hpPriv->eepromImage[0x210/4]);
685 addr[0] = (u8_t)(hpPriv->eepromImage[0x20c/4] & 0xff);
686 addr[1] = (u8_t)((hpPriv->eepromImage[0x20c/4]>>8) & 0xff);
687 addr[2] = (u8_t)((hpPriv->eepromImage[0x20c/4]>>16) & 0xff);
688 addr[3] = (u8_t)((hpPriv->eepromImage[0x20c/4]>>24) & 0xff);
689 addr[4] = (u8_t)(hpPriv->eepromImage[0x210/4] & 0xff);
690 addr[5] = (u8_t)((hpPriv->eepromImage[0x210/4]>>8) & 0xff);
692 zfCoreMacAddressNotify(dev, addr);
694 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_L,
695 ((((u32_t)addr[3])<<24) | (((u32_t)addr[2])<<16) | (((u32_t)addr[1])<<8) | addr[0]));
696 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_H,
697 ((((u32_t)addr[5])<<8) | addr[4]));
698 zfFlushDelayWrite(dev);
700 /* Regulatory Related Setting */
701 zm_msg2_mm(ZM_LV_0, "RegDomain =", hpPriv->eepromImage[0x208/4]);
702 CCS = (u8_t)((hpPriv->eepromImage[0x208/4] & 0x8000) >> 15);
703 WWR = (u8_t)((hpPriv->eepromImage[0x208/4] & 0x4000) >> 14);
704 /* below line shall be unmarked after A band is ready */
705 //CountryDomainCode = (u16_t)(hpPriv->eepromImage[0x208/4] & 0x3FFF);
706 CountryDomainCode = 8;
709 //zm_debug_msg0("CWY - Get Regulation Table from Country Code");
710 zfHpGetRegulationTablefromCountry(dev, CountryDomainCode);
714 //zm_debug_msg0("CWY - Get Regulation Table from Reg Domain");
715 zfHpGetRegulationTablefromRegionCode(dev, CountryDomainCode);
719 //zm_debug_msg0("CWY - Enable 802.11d");
720 /* below line shall be unmarked after A band is ready */
721 //zfiWlanSetDot11DMode(dev, 1);
724 zfCoreHalInitComplete(dev);
728 hpPriv->eepromImageRdReq++;
729 zfHpLoadEEPROMFromFW(dev);
732 else if (src == ZM_EEPROM_WRITE)
734 zfwDbgWriteEepromDone(dev, cmd[1], cmd[2]);
736 else if (src == ZM_ANI_READ)
738 u32_t cycleTime, ctlClear;
740 zm_msg2_mm(ZM_LV_0, "ANI rsp[1]=", rsp[1]);
741 zm_msg2_mm(ZM_LV_0, "ANI rsp[2]=", rsp[2]);
742 zm_msg2_mm(ZM_LV_0, "ANI rsp[3]=", rsp[3]);
743 zm_msg2_mm(ZM_LV_0, "ANI rsp[4]=", rsp[4]);
745 hpPriv->ctlBusy += rsp[1];
746 hpPriv->extBusy += rsp[2];
748 cycleTime = 100000; //100 miniseconds
750 if (cycleTime > rsp[1])
752 ctlClear = (cycleTime - rsp[1]) / 100;
759 zfHpAniArPoll(dev, ctlClear, rsp[3], rsp[4]);
761 else if (src == ZM_CMD_ECHO)
763 if ( ((struct zsHpPriv*)wd->hpPrivate)->halReInit )
765 zfCoreHalInitComplete(dev);
766 ((struct zsHpPriv*)wd->hpPrivate)->halReInit = 0;
770 zfHpLoadEEPROMFromFW(dev);
773 else if (src == ZM_OID_FW_DL_INIT)
775 zfwDbgDownloadFwInitDone(dev);
781 /************************************************************************/
783 /* FUNCTION DESCRIPTION zfWriteRegInternalReg */
784 /* Write on chip internal register immediately. */
787 /* dev : device pointer */
788 /* addr : register address */
796 /* Stephen Chen ZyDAS Technology Corporation 2005.11 */
798 /************************************************************************/
799 u32_t zfWriteRegInternalReg(zdev_t* dev, u32_t addr, u32_t val)
808 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_INTERNAL_WRITE, NULL);
813 /************************************************************************/
815 /* FUNCTION DESCRIPTION zfDelayWriteInternalReg */
816 /* Write on chip internal register, write operation may be */
817 /* postponed to form a multiple write command. */
820 /* dev : device pointer */
821 /* addr : register address */
825 /* 0 : command been postponed */
826 /* 1 : commands been executed */
829 /* Stephen Chen ZyDAS Technology Corporation 2005.11 */
831 /************************************************************************/
832 u16_t zfDelayWriteInternalReg(zdev_t* dev, u32_t addr, u32_t val)
834 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
837 struct zsHpPriv* hpPriv;
839 zmw_get_wlan_dev(dev);
840 hpPriv=wd->hpPrivate;
842 zmw_declare_for_critical_section();
844 /* enter critical section */
845 zmw_enter_critical_section(dev);
847 /* Store command to global buffer */
848 hpPriv->cmd.delayWcmdAddr[hpPriv->cmd.delayWcmdCount] = addr;
849 hpPriv->cmd.delayWcmdVal[hpPriv->cmd.delayWcmdCount++] = val;
851 /* If pending command reach size limit */
852 if ((hpPriv->cmd.delayWcmdCount) >= ((ZM_MAX_CMD_SIZE - 4) >> 3))
854 cmd[0] = 0x00000100 + (hpPriv->cmd.delayWcmdCount<<3);
856 /* copy command to cmd buffer */
857 for (i=0; i<hpPriv->cmd.delayWcmdCount; i++)
859 cmd[1+(i<<1)] = hpPriv->cmd.delayWcmdAddr[i];
860 cmd[2+(i<<1)] = hpPriv->cmd.delayWcmdVal[i];
862 /* reset pending command */
863 hpPriv->cmd.delayWcmdCount = 0;
865 /* leave critical section */
866 zmw_leave_critical_section(dev);
868 /* issue write command */
869 ret = zfIssueCmd(dev, cmd, 4+(i<<3), ZM_OID_INTERNAL_WRITE, NULL);
875 /* leave critical section */
876 zmw_leave_critical_section(dev);
883 /************************************************************************/
885 /* FUNCTION DESCRIPTION zfFlushDelayWrite */
886 /* Flush pending write command. */
889 /* dev : device pointer */
892 /* 0 : no pending command */
893 /* 1 : commands been executed */
896 /* Stephen Chen ZyDAS Technology Corporation 2005.11 */
898 /************************************************************************/
899 u16_t zfFlushDelayWrite(zdev_t* dev)
901 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
904 struct zsHpPriv* hpPriv;
906 zmw_get_wlan_dev(dev);
907 hpPriv=wd->hpPrivate;
909 zmw_declare_for_critical_section();
911 /* enter critical section */
912 zmw_enter_critical_section(dev);
914 /* If there is pending command */
915 if (hpPriv->cmd.delayWcmdCount > 0)
917 cmd[0] = 0x00000100 + (hpPriv->cmd.delayWcmdCount<<3);
919 /* copy command to cmd buffer */
920 for (i=0; i<hpPriv->cmd.delayWcmdCount; i++)
922 cmd[1+(i<<1)] = hpPriv->cmd.delayWcmdAddr[i];
923 cmd[2+(i<<1)] = hpPriv->cmd.delayWcmdVal[i];
925 /* reset pending command */
926 hpPriv->cmd.delayWcmdCount = 0;
928 /* leave critical section */
929 zmw_leave_critical_section(dev);
931 /* issue write command */
932 ret = zfIssueCmd(dev, cmd, 4+(i<<3), ZM_OID_INTERNAL_WRITE, NULL);
938 /* leave critical section */
939 zmw_leave_critical_section(dev);
946 u32_t zfiDbgDelayWriteReg(zdev_t* dev, u32_t addr, u32_t val)
948 zfDelayWriteInternalReg(dev, addr, val);
952 u32_t zfiDbgFlushDelayWrite(zdev_t* dev)
954 zfFlushDelayWrite(dev);
958 /************************************************************************/
960 /* FUNCTION DESCRIPTION zfiDbgWriteReg */
961 /* Write register. */
964 /* dev : device pointer */
965 /* addr : register address */
973 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
975 /************************************************************************/
976 u32_t zfiDbgWriteReg(zdev_t* dev, u32_t addr, u32_t val)
985 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_WRITE, 0);
988 /************************************************************************/
990 /* FUNCTION DESCRIPTION zfiDbgWriteFlash */
994 /* dev : device pointer */
995 /* addr : register address */
1003 /* Yjsung ZyDAS Technology Corporation 2007.02 */
1005 /************************************************************************/
1006 u32_t zfiDbgWriteFlash(zdev_t* dev, u32_t addr, u32_t val)
1011 //cmd[0] = 0x0000B008;
1012 /* len[0] : type[0xB0] : seq[?] */
1013 cmd[0] = 8 | (ZM_CMD_WFLASH << 8);
1017 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_WRITE, 0);
1021 /************************************************************************/
1023 /* FUNCTION DESCRIPTION zfiDbgWriteEeprom */
1027 /* dev : device pointer */
1028 /* addr : register address */
1036 /* Paul ZyDAS Technology Corporation 2007.06 */
1038 /************************************************************************/
1039 u32_t zfiDbgWriteEeprom(zdev_t* dev, u32_t addr, u32_t val)
1044 //cmd[0] = 0x0000B008;
1045 /* len[0] : type[0xB0] : seq[?] */
1046 cmd[0] = 8 | (ZM_CMD_WREEPROM << 8);
1050 ret = zfIssueCmd(dev, cmd, 12, ZM_EEPROM_WRITE, 0);
1054 /************************************************************************/
1056 /* FUNCTION DESCRIPTION zfiDbgBlockWriteEeprom */
1057 /* Block Write Eeprom. */
1059 /* p.s: now,it will write 16 bytes register data per block (N=4) */
1062 /* dev : device pointer */
1063 /* addr : register address */
1064 /* buf : input data buffer pointer */
1071 /* Paul ZyDAS Technology Corporation 2007.06 */
1073 /************************************************************************/
1074 //#define N buflen/4
1075 //#define SIZE (2*N+1)
1077 u32_t zfiDbgBlockWriteEeprom(zdev_t* dev, u32_t addr, u32_t* buf)
1079 u32_t cmd[9]; //2N+1
1082 //cmd[0] = 0x0000B008;
1083 /* len[0] : type[0xB0] : seq[?] */
1085 //cmd[0] = (8*N) | (ZM_CMD_WFLASH << 8);
1086 cmd[0] = 32 | (ZM_CMD_WREEPROM << 8); //8N
1088 for (i=0; i<4; i++) // i<N
1090 cmd[(2*i)+1] = addr+(4*i);
1091 cmd[(2*i)+2] = *(buf+i);
1094 ret = zfIssueCmd(dev, cmd, 36, ZM_EEPROM_WRITE, 0); //8N+4
1096 // added for EEPROMUpdate, wait a moment for prevent cmd queue full!
1103 /* write EEPROM with wrlen : wrlen must be 4*n */
1104 /* command format : cmd_info(4) + addr(4) + eeprom(wrlen) */
1105 u32_t zfiDbgBlockWriteEeprom_v2(zdev_t* dev, u32_t addr, u32_t* buf, u32_t wrlen)
1110 /* len[0] : type[0xB0] : seq[?] */
1111 /* len = addr(4) + eeprom_block(wrlen) */
1112 cmd[0] = (wrlen+4) | (ZM_CMD_MEM_WREEPROM << 8);
1115 for (i=0; i<(wrlen/4); i++) // i<wrlen/4
1117 cmd[2+i] = *(buf+i);
1119 /* cmd_info(4) + addr(4) + eeprom(wrlen) */
1120 ret = zfIssueCmd(dev, cmd, (u16_t)(wrlen+8), ZM_EEPROM_WRITE, 0);
1125 /************************************************************************/
1127 /* FUNCTION DESCRIPTION zfDbgOpenEeprom */
1131 /* dev : device pointer */
1136 /* Paul ZyDAS Technology Corporation 2007.06 */
1138 /************************************************************************/
1139 void zfDbgOpenEeprom(zdev_t* dev)
1142 zfDelayWriteInternalReg(dev, 0x1D1400, 0x12345678);
1143 zfDelayWriteInternalReg(dev, 0x1D1404, 0x55aa00ff);
1144 zfDelayWriteInternalReg(dev, 0x1D1408, 0x13579ace);
1145 zfDelayWriteInternalReg(dev, 0x1D1414, 0x0);
1146 zfFlushDelayWrite(dev);
1149 /************************************************************************/
1151 /* FUNCTION DESCRIPTION zfDbgCloseEeprom */
1155 /* dev : device pointer */
1160 /* Paul ZyDAS Technology Corporation 2007.05 */
1162 /************************************************************************/
1163 void zfDbgCloseEeprom(zdev_t* dev)
1166 zfDelayWriteInternalReg(dev, 0x1D1400, 0x87654321);
1167 //zfDelayWriteInternalReg(dev, 0x1D1404, 0xffffffff);
1168 //zfDelayWriteInternalReg(dev, 0x1D1408, 0xffffffff);
1169 //zfDelayWriteInternalReg(dev, 0x1D1414, 0x100);
1170 zfFlushDelayWrite(dev);
1173 /************************************************************************/
1175 /* FUNCTION DESCRIPTION zfiSeriallyWriteEeprom */
1176 /* Write EEPROM Serially. */
1179 /* dev : device pointer */
1180 /* addr : start address of writing EEPROM */
1181 /* buf : input data buffer */
1182 /* buflen : size of input data buffer */
1183 /* (length of data write into EEPROM) */
1190 /* Paul ZyDAS Technology Corporation 2007.06 */
1192 /************************************************************************/
1193 u32_t zfiSeriallyWriteEeprom(zdev_t* dev, u32_t addr, u32_t* buf, u32_t buflen)
1196 u16_t i,ret,blocksize;
1199 // per 4 bytes = 1 count
1203 zfDbgOpenEeprom(dev);
1206 for (i=0; i<count; i++)
1208 if (zfwWriteEeprom(dev, (addr+(4*i)), *(buf+i), 0) != 0)
1210 // Update failed, Close EEPROM
1211 zm_debug_msg0("zfwWriteEeprom failed \n");
1212 zfDbgCloseEeprom(dev);
1218 zfDbgCloseEeprom(dev);
1223 /************************************************************************/
1225 /* FUNCTION DESCRIPTION zfiSeriallyBlockWriteEeprom */
1226 /* Block Write EEPROM Serially. */
1227 /* (BlockWrite: per 16bytes write EEPROM once) */
1230 /* dev : device pointer */
1231 /* addr : register address */
1232 /* buf : input data buffer */
1233 /* buflen : access data size of buf */
1240 /* Paul ZyDAS Technology Corporation 2007.05 */
1242 /************************************************************************/
1243 u32_t zfiSeriallyBlockWriteEeprom(zdev_t* dev, u32_t addr, u32_t* buf, u32_t buflen)
1246 u16_t i,ret,blocksize;
1249 // per 4 bytes = 1 count
1253 zfDbgOpenEeprom(dev);
1256 // EEPROM Write start address from: 0x1000!?
1257 // per 16bytes(N=4) block write EEPROM once
1258 for (i=0; i<(count/4); i++) // count/N
1260 //zfiDbgBlockWriteEeprom(dev, (addr+(4*N*i)), buf+(N*i));
1261 //zfiDbgBlockWriteEeprom(dev, (addr+(16*i)), buf+(4*i));
1262 if (zfwBlockWriteEeprom(dev, (addr+(16*i)), buf+(4*i), 0) != 0)
1264 zm_debug_msg0("zfiDbgBlockWriteEeprom failed \n");
1266 zfDbgCloseEeprom(dev);
1272 zfDbgCloseEeprom(dev);
1277 /************************************************************************/
1279 /* FUNCTION DESCRIPTION zfiDbgDumpEeprom */
1283 /* dev : device pointer */
1284 /* addr : start address of dumping EEPROM */
1285 /* datalen : length of access EEPROM data */
1286 /* buf : point of buffer, the buffer saved dump data */
1293 /* Paul ZyDAS Technology Corporation 2007.06 */
1295 /************************************************************************/
1296 u32_t zfiDbgDumpEeprom(zdev_t* dev, u32_t addr, u32_t datalen, u32_t* buf)
1303 // over EEPROM length
1304 if(datalen > 0x2000)
1309 for(i=0; i<count; i++)
1311 buf[i] = zfwReadEeprom(dev, addr+(4*i));
1317 /************************************************************************/
1319 /* FUNCTION DESCRIPTION zfiDbgReadReg */
1320 /* Read register. */
1323 /* dev : device pointer */
1324 /* addr : register address */
1331 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
1333 /************************************************************************/
1334 u32_t zfiDbgReadReg(zdev_t* dev, u32_t addr)
1339 cmd[0] = 0x00000004;
1342 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_READ, 0);
1347 /************************************************************************/
1349 /* FUNCTION DESCRIPTION zfiDbgReadTally */
1350 /* Read register. */
1353 /* dev : device pointer */
1360 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
1362 /************************************************************************/
1363 u32_t zfiDbgReadTally(zdev_t* dev)
1367 zmw_get_wlan_dev(dev);
1369 if ( ((struct zsHpPriv*)wd->hpPrivate)->halReInit )
1374 /* len[0] : type[0x81] : seq[?] */
1375 cmd[0] = 0 | (ZM_CMD_TALLY << 8);
1376 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_TALLY, 0);
1378 /* len[0] : type[0x82] : seq[?] */
1379 cmd[0] = 0 | (ZM_CMD_TALLY_APD << 8);
1380 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_TALLY_APD, 0);
1386 u32_t zfiDbgSetIFSynthesizer(zdev_t* dev, u32_t value)
1391 /* len[4] : type[0x32] : seq[?] */
1392 cmd[0] = 0x4 | (ZM_OID_SYNTH << 8);
1395 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_SYNTH, 0);
1399 u32_t zfiDbgQueryHwTxBusy(zdev_t* dev)
1404 /* len[4] : type[0xC0] : seq[?] */
1405 cmd[0] = 0 | (ZM_CMD_DKTX_STATUS << 8);
1407 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_DKTX_STATUS, 0);
1413 u16_t zfHpBlockEraseFlash(zdev_t *dev, u32_t addr)
1415 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1418 cmd[0] = 0x00000004 | (ZM_CMD_FLASH_ERASE << 8);
1421 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_INTERNAL_WRITE, NULL);
1427 u16_t zfiDbgProgramFlash(zdev_t *dev, u32_t offset, u32_t len, u32_t *data)
1429 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1434 cmd[0] = (ZM_CMD_FLASH_PROG << 8) | ((len+8) & 0xff);
1438 for (i = 0; i < (len >> 2); i++)
1443 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_FLASH_PROGRAM, NULL);
1449 /************************************************************************/
1451 /* FUNCTION DESCRIPTION zfiDbgChipEraseFlash */
1452 /* Chip Erase Flash. */
1455 /* dev : device pointer */
1462 /* Paul Atheros Technology Corporation 2007.09 */
1464 /************************************************************************/
1465 u16_t zfiDbgChipEraseFlash(zdev_t *dev)
1467 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1470 cmd[0] = 0x00000000 | (ZM_CMD_FLASH_ERASE << 8);
1472 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_INTERNAL_WRITE, NULL);
1475 /************************************************************************/
1477 /* FUNCTION DESCRIPTION zfiDbgGetFlashCheckSum */
1478 /* Get FlashCheckSum. */
1481 /* dev : device pointer */
1482 /* addr : Start address of getchksum */
1483 /* len : total lenth of calculate getchksum */
1490 /* Paul Atheros Technology Corporation 2007.08 */
1492 /************************************************************************/
1493 u32_t zfiDbgGetFlashCheckSum(zdev_t *dev, u32_t addr, u32_t len)
1495 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1498 cmd[0] = 0x00000008 | (ZM_CMD_FLASH_CHKSUM << 8);
1502 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_FLASH_CHKSUM, NULL);
1507 /************************************************************************/
1509 /* FUNCTION DESCRIPTION zfiDbgReadFlash */
1513 /* dev : device pointer */
1514 /* addr : Start address of read flash */
1515 /* len : total lenth of read flash data */
1522 /* Paul Atheros Technology Corporation 2007.09 */
1524 /************************************************************************/
1525 u32_t zfiDbgReadFlash(zdev_t *dev, u32_t addr, u32_t len)
1527 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1530 cmd[0] = len | (ZM_CMD_FLASH_READ << 8);
1533 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_FLASH_READ, NULL);
1537 /************************************************************************/
1539 /* FUNCTION DESCRIPTION zfiDownloadFwSet */
1540 /* Before Download FW, */
1541 /* Command FW to Software reset and close watch dog control. */
1545 /* dev : device pointer */
1552 /* Paul Atheros Technology Corporation 2007.09 */
1554 /************************************************************************/
1555 u32_t zfiDownloadFwSet(zdev_t *dev)
1559 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1562 cmd[0] = 0x00000008 | (ZM_CMD_FW_DL_INIT << 8);
1564 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_FW_DL_INIT, NULL);