5 * Copyright (C) 2004 ZyDAS Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
10 * The contents of this file are subject to the Mozilla Public
11 * License Version 1.1 (the "License"); you may not use this file
12 * except in compliance with the License. You may obtain a copy of
13 * the License at http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU Public License version 2 (the "GPL"), in which
22 * case the provisions of the GPL are applicable instead of the
23 * above. If you wish to allow the use of your version of this file
24 * only under the terms of the GPL and not to allow others to use
25 * your version of this file under the MPL, indicate your decision
26 * by deleting the provisions above and replace them with the notice
27 * and other provisions required by the GPL. If you do not delete
28 * the provisions above, a recipient may use your version of this
29 * file under either the MPL or the GPL.
31 * -------------------------------------------------------------------- */
33 #include <linux/config.h>
34 #include <net/checksum.h>
35 #include <linux/tcp.h>
36 #include <linux/udp.h>
37 #include <linux/hardirq.h>
48 #if ZDCONF_LP_SUPPORT == 1
49 #include "WS11UPhR_Turbo.h"
50 #elif ZDCONF_LP_SUPPORT == 0
53 #error "ZDCONF_LP_SUPPORT isn't defined"
68 u8 WS11Ur2
[(0xEE00 - 0xEC00) * 2] = { 0x0F, 0x9F, 0x00, 0xEE }; // JMP 0xEE00
71 extern zd_80211Obj_t dot11Obj
;
72 extern struct net_device
*g_dev
;
74 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) /* tune me! */
75 # define SUBMIT_URB(u,f) usb_submit_urb(u,f)
76 # define USB_ALLOC_URB(u,f) usb_alloc_urb(u,f)
78 # define SUBMIT_URB(u,f) usb_submit_urb(u)
79 # define USB_ALLOC_URB(u,f) usb_alloc_urb(u)
82 #if defined CONFIG_ARCH_W341 || defined CONFIG_ARCH_W321 || defined CONFIG_ARCH_W311
84 #define MCPU_GPIO_INPUT 0
85 #define MCPU_GPIO_OUTPUT 1
86 #define MCPU_GPIO_HIGH 1
87 #define MCPU_GPIO_LOW 0
89 #elif defined CONFIG_ARCH_W311
90 #define WLAN_LED_REG CPE_WLAN_LED_REG_VA_BASE
103 inline void zd1211_DumpErrorCode(struct zd1205_private
*macp
, int err
)
106 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
108 ZD1211DEBUG(0, "USB_ST_CRC\n");
111 //case USB_ST_BITSTUFF:
112 //ZD1211DEBUG(0, "USB_ST_BITSTUFF\n");
115 //case USB_ST_NORESPONSE:
116 //ZD1211DEBUG(0, "USB_ST_NORESPONSE\n");
119 case USB_ST_DATAOVERRUN
:
120 ZD1211DEBUG(0, "USB_ST_DATAOVERRUN\n");
123 case USB_ST_DATAUNDERRUN
:
124 ZD1211DEBUG(0, "USB_ST_DATAUNDERRUN\n");
127 case USB_ST_BUFFEROVERRUN
:
128 ZD1211DEBUG(0, "USB_ST_BUFFEROVERRUN\n");
131 case USB_ST_BUFFERUNDERRUN
:
132 ZD1211DEBUG(0, "USB_ST_BUFFERUNDERRUN\n");
135 case USB_ST_INTERNALERROR
:
136 ZD1211DEBUG(0, "USB_ST_INTERNALERROR\n");
139 //case USB_ST_SHORT_PACKET:
140 //ZD1211DEBUG(0, "USB_ST_SHORT_PACKET\n");
143 case USB_ST_PARTIAL_ERROR
:
144 ZD1211DEBUG(0, "USB_ST_PARTIAL_ERROR\n");
147 case USB_ST_URB_KILLED
:
148 ZD1211DEBUG(0, "USB_ST_URB_KILLED\n");
151 case USB_ST_URB_PENDING
:
152 ZD1211DEBUG(0, "USB_ST_URB_PENDING\n");
156 ZD1211DEBUG(0, "USB_ST_REMOVED\n");
160 ZD1211DEBUG(0, "USB_ST_TIMEOUT\n");
163 case USB_ST_NOTSUPPORTED
:
164 ZD1211DEBUG(0, "USB_ST_NOTSUPPORTED\n");
171 case USB_ST_BANDWIDTH_ERROR
:
172 ZD1211DEBUG(0, "USB_ST_BANDWIDTH_ERROR\n");
175 case USB_ST_URB_INVALID_ERROR
:
176 ZD1211DEBUG(0, "USB_ST_URB_INVALID_ERROR\n");
179 case USB_ST_URB_REQUEST_ERROR
:
180 ZD1211DEBUG(0, "USB_ST_URB_REQUEST_ERROR\n");
184 ZD1211DEBUG(0, "USB_ST_STALL\n");
188 ZD1211DEBUG(0, "ENOMEM\n");
193 ZD1211DEBUG(0, "USB ST Code = %d\n",err
);
202 void zd1211_DumpReadMultipleReg(struct zd1205_private
*macp
, u16 adr0
)
204 u16 ReadAddr
[cMAX_MULTI_READ_REG_NUM
];
205 u16 ReadData
[cMAX_MULTI_READ_REG_NUM
];
208 FPRINT_V("adr0", adr0
);
210 for (ReadIndex
= 0; ReadIndex
< cMAX_MULTI_READ_REG_NUM
;)
214 mFILL_READ_REGISTER(adr0
++);
216 zd1211_USB_PACKAGE_READ_REGISTER(ReadAddr
, ReadData
, ReadIndex
, false);
218 for (ReadIndex
= 0; ReadIndex
< 8; ReadIndex
++)
219 printk("%04X, ", ReadData
[ReadIndex
]);
224 for (; ReadIndex
< cMAX_MULTI_READ_REG_NUM
; ReadIndex
++)
225 printk("%04X, ", ReadData
[ReadIndex
]);
231 // len0: in word, adr: word offset
232 void zd1211_WriteEEPROM(struct zd1205_private
*macp
, u16 rom_adr
, u16 ram_adr
, u16 len0
)
235 u16 WriteAddr
[cMAX_MULTI_WRITE_REG_NUM
];
236 u16 WriteData
[cMAX_MULTI_WRITE_REG_NUM
];
239 tmpvalue
= zd1211_readl(ZD1211_CLOCK_CTRL
, false);
240 mFILL_WRITE_REGISTER(ZD1211_CLOCK_CTRL
, mSET_BIT((u16
) tmpvalue
, bZD1211_CLOCK_EEPROM
));
241 mFILL_WRITE_REGISTER(UMAC_EPROM_ROM_ADDR
, rom_adr
);
242 mFILL_WRITE_REGISTER(UMAC_EPROM_RAM_ADDR
, ram_adr
);
243 mFILL_WRITE_REGISTER(UMAC_EPROM_DMA_LEN_DIR
, bmEPROM_XFER_DIR
| len0
);
244 mFILL_WRITE_REGISTER(ZD1211_CLOCK_CTRL
, mCLR_BIT((u16
) tmpvalue
, bZD1211_CLOCK_EEPROM
));
245 zd1211_WriteMultiRegister(WriteAddr
, WriteData
, WriteIndex
, false);
250 int zd1211_ChangeToFlashAble(struct zd1205_private
*macp
)
254 if (!macp
->bFlashable
){
257 zd_writel(0x01, FW_SOFT_RESET
);
259 macp
->bDisableTx
= 1;
260 //USB_StopTxEP(macp);
262 macp
->bAllowAccessRegister
= 0;
264 LoadRet
= zd1211_LoadUSBSpecCode(macp
, WS11UPhm
, sizeof(WS11UPhm
),
265 cFIRMWARE_START_ADDR
, true);
267 FPRINT("Load WS11UPhm fail");
271 ZD1211DEBUG(0, "Load WS11UPhm Done\n");
273 //macp->bAllowAccessRegister = 1;
274 macp
->bFlashable
= 1;
276 #if fWRITE_WORD_REG || fREAD_MUL_REG
277 // Must get this information before any register write
278 tmpvalue
= zd1211_readl(cADDR_ENTRY_TABLE
, FALSE
);
279 macp
->AddrEntryTable
= (u16
) tmpvalue
;
289 int zd1211_UpdateBootCode(struct zd1205_private *macp, u16 *pCheckSum, u16 *pEEPROMData,
294 u16 WriteAddr[cMAX_MULTI_WRITE_REG_NUM];
295 u16 WriteData[cMAX_MULTI_WRITE_REG_NUM];
297 u16 ROMBufAdr = cBOOTCODE_START_ADDR;
299 ZD1211DEBUG(0, "UpdateBootCode\n");
301 for (i=0; i<EEPROMLen; i+=(2*WRITE_WORD_TO_EEPROM_PER_TIME)){
302 for (WriteIndex=0; WriteIndex<WRITE_WORD_TO_EEPROM_PER_TIME/2; ){
303 if (ROMBufAdr >= cINT_VECT_ADDR){
304 FPRINT("Exceed max address");
307 mFILL_WRITE_REGISTER(ROMBufAdr ++,
308 pEEPROMData[WriteIndex * 2] | (pEEPROMData[WriteIndex * 2 + 1] << 8));
312 zd1211_WriteMultiRegister(WriteAddr, WriteData, WriteIndex, false);
314 if (ROMBufAdr >= cINT_VECT_ADDR){
315 FPRINT("Exceed max address1");
319 pEEPROMData += WRITE_WORD_TO_EEPROM_PER_TIME;
322 if (EEPROMLen % (2*WRITE_WORD_TO_EEPROM_PER_TIME)){
323 for (WriteIndex = 0; WriteIndex < (EEPROMLen % (2 * WRITE_WORD_TO_EEPROM_PER_TIME)) / 2;){
324 if (ROMBufAdr >= cINT_VECT_ADDR){
325 FPRINT("Exceed max address2");
329 mFILL_WRITE_REGISTER(ROMBufAdr ++,
330 pEEPROMData[WriteIndex * 2] | (pEEPROMData[WriteIndex * 2 + 1] << 8));
334 zd1211_WriteMultiRegister(WriteAddr, WriteData, WriteIndex, false);
344 int zd1211_USB_Write_EEPROM(struct zd1205_private *macp, u16 *pEEPROMData, u32 EEPROMLen) //in bytes
349 ZD1211DEBUG(0, "USB_Write_EEPROM\n");
351 macp->bDisableTx = 1;
353 //USB_StopTxEP(macp);
355 ret = zd1211_UpdateBootCode(macp, &CheckSum, pEEPROMData, EEPROMLen);
359 zd1211_WriteEEPROM(macp, 0, cBOOTCODE_START_ADDR, cEEPROM_SIZE - cLOAD_VECT_LEN);
360 //macp->bDisableTx = 0;
369 int zd1211_USB_WRITE_EEPROM_DATA(struct zd1205_private
*macp
, PUSB_EEPROM_DATA pData
, int DataLen
)
373 //int memflags = GFP_KERNEL;
375 ZD1211DEBUG(0, "USB_WRITE_EEPROM_DATA\n");
377 if (!macp
->bUSBDeveiceAttached
){
381 down(&macp
->reg_sem
);
383 pBuffer
= kmalloc(DataLen
, GFP_KERNEL
);
390 memcpy(pBuffer
, (u8
*)pData
, DataLen
);
392 if (macp
->ep4isIntOut
)
393 usb_fill_int_urb(macp
->reg_urb
, macp
->usb
,
394 usb_sndintpipe(macp
->usb
, EP_REG_OUT
),
396 zd1211_reg_cb
, macp
, 1);
398 usb_fill_bulk_urb(macp
->reg_urb
, macp
->usb
,
399 usb_sndbulkpipe(macp
->usb
, EP_REG_OUT
),
401 zd1211_reg_cb
, macp
);
402 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
403 macp
->reg_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
406 if ((ret
= SUBMIT_URB(macp
->reg_urb
, GFP_ATOMIC
))){
407 printk(KERN_ERR
"zd1211: failed reg_urb\n");
408 zd1211_DumpErrorCode(macp
, ret
);
412 wait_event(macp
->regSet_wait
, test_bit(ZD1211_CMD_FINISH
, &macp
->flags
));
413 clear_bit(ZD1211_CMD_FINISH
, &macp
->flags
);
421 #if fPROG_FLASH_BY_FW
422 int zd1211_USB_ProgramFlash(struct zd1205_private
*macp
, u16
*Value
, u16 RegCount
)
424 u8
*pRegBuffer
= NULL
;
427 u16 size
= sizeof(USB_WRITE_REG
);
432 ZD1211DEBUG(0, "USB_ProgramFlash\n");
434 if ((RegCount
== 0) || (!macp
->bUSBDeveiceAttached
))
437 down(&macp
->reg_sem
);
438 pRegBuffer
= kmalloc(size
, GFP_KERNEL
);
445 memset(pRegBuffer
, 0x0, size
);
447 ((PUSB_WRITE_REG
)pRegBuffer
)->RequestID
= zd_cpu_to_le16(REGID_PROG_FLSH
);
448 ((PUSB_SET_RF
) pRegBuffer
)->Value
= Value
[0];
449 ((PUSB_SET_RF
) pRegBuffer
)->Index
= Value
[1];
451 for (ii
= 2; ii
< RegCount
; ii
++)
452 ((PUSB_SET_RF
)pRegBuffer
)->Data
[ii
- 2] = Value
[ii
];
454 bufSize
= sizeof(u16
) * (1+RegCount
);
456 if (macp
->ep4isIntOut
)
457 usb_fill_int_urb(macp
->reg_urb
, macp
->usb
,
458 usb_sndintpipe(macp
->usb
, EP_REG_OUT
),
460 zd1211_reg_cb
, macp
, 1);
462 usb_fill_bulk_urb(macp
->reg_urb
, macp
->usb
,
463 usb_sndbulkpipe(macp
->usb
, EP_REG_OUT
),
465 zd1211_reg_cb
, macp
);
466 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
467 macp
->reg_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
470 if ((ret
= SUBMIT_URB(macp
->reg_urb
, GFP_KERNEL
))){
471 printk(KERN_ERR
"zd1211: failed reg_urb\n");
472 zd1211_DumpErrorCode(macp
, ret
);
476 wait_event(macp
->regSet_wait
, test_bit(ZD1211_CMD_FINISH
, &macp
->flags
));
477 clear_bit(ZD1211_CMD_FINISH
, &macp
->flags
);
488 int zd1211_USB_PACKAGE_READ_REGISTER(u16
*Address
, u16
*pValue
, u16 RegCount
, u8 bAddUSBCSRAddress
)
490 struct zd1205_private
*macp
= g_dev
->priv
;
491 u8
*pRegBuffer
= NULL
;
493 u16 size
= sizeof(USB_READ_REG_REQ
);
496 //int memflags = GFP_KERNEL;
498 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
504 printk(KERN_ERR
"********zd1211_USB_PACKAGE_READ_REGISTER in_interrupt*********\n");
507 down(&macp
->reg_sem
);
509 if ((RegCount
== 0) || (!macp
->bUSBDeveiceAttached
) || (!test_bit(ZD1211_RUNNING
, &macp
->flags
))){
514 pRegBuffer
= kmalloc(size
, GFP_KERNEL
);
520 memset(pRegBuffer
, 0x0, size
);
522 ((PUSB_READ_REG_REQ
)pRegBuffer
)->RequestID
= zd_cpu_to_le16(REGID_READ
);
524 for (ii
= 0; ii
< RegCount
; ii
++){
525 if ((Address
[ii
] & BASE_ADDR_MASK_HOST
) == USB_BASE_ADDR_HOST
)
526 Address
[ii
] = Address
[ii
] - USB_BASE_ADDR_HOST
+ macp
->AddrEntryTable
;
527 else if ((Address
[ii
] & BASE_ADDR_MASK_HOST
) == USB_BASE_ADDR_EEPROM
)
528 Address
[ii
] = ((Address
[ii
] - USB_BASE_ADDR_EEPROM
) / 2) + cFIRMWARE_EEPROM_OFFSET
;
530 ((PUSB_READ_REG_REQ
) pRegBuffer
)->Address
[ii
] = zd_cpu_to_le16(Address
[ii
]);
533 bufSize
= sizeof(u16
) * (1+RegCount
);
535 if (macp
->ep4isIntOut
)
536 usb_fill_int_urb(macp
->reg_urb
, macp
->usb
,
537 usb_sndintpipe(macp
->usb
, EP_REG_OUT
),
539 zd1211_reg_cb
, macp
, 1);
541 usb_fill_bulk_urb(macp
->reg_urb
, macp
->usb
,
542 usb_sndbulkpipe(macp
->usb
, EP_REG_OUT
),
544 zd1211_reg_cb
, macp
);
545 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
546 macp
->reg_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
549 if ((ret
= SUBMIT_URB(macp
->reg_urb
, GFP_ATOMIC
))){
550 printk(KERN_ERR
"zd1211: failed reg_urb\n");
551 zd1211_DumpErrorCode(macp
, ret
);
557 //wait command complete
558 macp
->regWaitRCompCnt
++;
559 //printk(KERN_ERR "before wait 4\n");
560 wait_event(macp
->regSet_wait
, test_bit(ZD1211_CMD_FINISH
, &macp
->flags
));
561 //printk(KERN_ERR "after wait 4\n");
562 macp
->regRWCompCnt
++;
564 clear_bit(ZD1211_CMD_FINISH
, &macp
->flags
);
570 //wait response complete
571 macp
->regWaitRspCnt
++;
573 #if 0//(LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
574 if (wait_event_interruptible_timeout(macp
->iorwRsp_wait
, test_bit(ZD1211_REQ_COMP
, &macp
->flags
), HZ
/2)){ //use it, we may can't wake up
576 //interrupt by a signal
577 memset(macp
->IntEPBuffer
, 0, MAX_EPINT_BUFFER
);
578 macp
->regUnCompCnt
++;
583 macp
->regRspCompCnt
++;
585 //#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
586 //interruptible_sleep_on_timeout(&macp->iorwRsp_wait, 1); //magic delay
587 //20060809 MZCai. the interruptible... has race condition issue.
588 //We don't use it anymore in 2.6.x.
589 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
590 wait_event_interruptible_timeout(macp
->iorwRsp_wait
, 0, 1);
592 interruptible_sleep_on_timeout(&macp
->iorwRsp_wait
, 1); //magic delay
596 //interruptible_sleep_on_timeout(&macp->iorwRsp_wait, HZ/40); //magic delay
597 if (!test_bit(ZD1211_REQ_COMP
, &macp
->flags
)){
598 //check if Rsp has completed, race condition may happen,
599 macp
->regRdSleepCnt
++;
600 //we waste time_out time
601 //printk(KERN_ERR "before wait 2\n");
602 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
603 wait_event_interruptible_timeout(macp
->iorwRsp_wait
, 0, HZ
/10);
605 interruptible_sleep_on_timeout(&macp
->iorwRsp_wait
, HZ
/10); //magic delay
607 //wake up, check if timeout or ompleted
610 if (test_bit(ZD1211_REQ_COMP
, &macp
->flags
))
611 macp
->regRspCompCnt
++;
613 memset(macp
->IntEPBuffer
, 0x0, MAX_EPINT_BUFFER
);
614 macp
->regUnCompCnt
++;
621 if ((macp
->ReadRegCount
== 0) || (macp
->ReadRegCount
> MAX_EPINT_BUFFER
)){
625 for (ii
= 0; ii
< (macp
->ReadRegCount
-2) / 4; ii
++){
626 pValue
[ii
] = zd_get_LE_U16(macp
->IntEPBuffer2
+(1+ii
*2+1)*2);
632 clear_bit(ZD1211_REQ_COMP
, &macp
->flags
);
637 u32
zd1211_readl(u32 Address
, u8 bAddUSBCSRAddress
)
639 struct zd1205_private
*macp
= g_dev
->priv
;
647 if (bAddUSBCSRAddress
&& Address
< 0x8000){
648 Address
+= macp
->USBCSRAddress
;
650 if ((Address
& BASE_ADDR_MASK_HOST
) == USB_BASE_ADDR_HOST
)
651 ReadAddr
[1] = (u16
) Address
+ 1;
653 ReadAddr
[1] = (u16
) Address
+ 2;
656 ReadAddr
[1] = (u16
) Address
+ 1;
658 ReadAddr
[0] = (u16
) Address
; // Read Low Word first
661 bRet
= zd1211_USB_PACKAGE_READ_REGISTER(ReadAddr
, ReadData
, 2, false);
665 printk(KERN_ERR
"1211_readl failed for 5 attempts...Very Serious");
670 value
= (((u32
) ReadData
[1]) << 16) + ReadData
[0];
675 int zd1211_USB_PACKAGE_WRITE_REGISTER(u16
*Address
, u16
*Value
, u16 RegCount
, u8 bAddUSBCSRAddress
)
677 struct zd1205_private
*macp
= g_dev
->priv
;
678 u8
*pRegBuffer
= NULL
;
680 u16 size
= sizeof(USB_WRITE_REG
);
684 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
689 FPRINT("********zd1211_USB_PACKAGE_WRITE_REGISTER in_interrupt*********");
693 down(&macp
->reg_sem
);
695 if ((RegCount
== 0) || (!macp
->bUSBDeveiceAttached
) || !test_bit(ZD1211_RUNNING
, &macp
->flags
)) {
700 pRegBuffer
= kmalloc(size
, GFP_KERNEL
);
706 memset(pRegBuffer
, 0x0, size
);
708 ((PUSB_WRITE_REG
)pRegBuffer
)->RequestID
= zd_cpu_to_le16(REGID_WRITE
);
710 if (RegCount
> cMIN_MULTI_WRITE_REG_NUM
){
711 for (i
=cMIN_MULTI_WRITE_REG_NUM
; i
<RegCount
; i
++){
712 if (bAddUSBCSRAddress
)
713 Address
[i
] += macp
->USBCSRAddress
;
715 if ((Address
[i
] & BASE_ADDR_MASK_HOST
) == USB_BASE_ADDR_HOST
)
716 Address
[i
] = Address
[i
] - USB_BASE_ADDR_HOST
+ macp
->AddrEntryTable
;
717 else if ((Address
[i
] & BASE_ADDR_MASK_HOST
) == USB_BASE_ADDR_EEPROM
)
718 Address
[i
] = ((Address
[i
] - USB_BASE_ADDR_EEPROM
) / 2) + cFIRMWARE_EEPROM_OFFSET
;
720 ((PUSB_WRITE_REG
)pRegBuffer
)->WritePackage
[i
].Address
= zd_cpu_to_le16(Address
[i
]);
721 ((PUSB_WRITE_REG
)pRegBuffer
)->WritePackage
[i
].WriteData_low
= zd_cpu_to_le16(Value
[i
]);
725 bufSize
= sizeof(u16
) * (1+RegCount
*2);
727 if (macp
->ep4isIntOut
)
728 usb_fill_int_urb(macp
->reg_urb
, macp
->usb
,
729 usb_sndintpipe(macp
->usb
, EP_REG_OUT
),
731 zd1211_reg_cb
, macp
, 1);
733 usb_fill_bulk_urb(macp
->reg_urb
, macp
->usb
,
734 usb_sndbulkpipe(macp
->usb
, EP_REG_OUT
),
736 zd1211_reg_cb
, macp
);
737 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
738 macp
->reg_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
741 if ((ret
= SUBMIT_URB(macp
->reg_urb
, GFP_ATOMIC
))){
742 printk(KERN_ERR
"zd1211: failed reg_urb\n");
743 zd1211_DumpErrorCode(macp
, ret
);
747 macp
->regWaitWCompCnt
++;
748 wait_event(macp
->regSet_wait
, test_bit(ZD1211_CMD_FINISH
, &macp
->flags
));
750 macp
->regRWCompCnt
++;
751 clear_bit(ZD1211_CMD_FINISH
, &macp
->flags
);
759 int zd1211_WriteMultiRegister(u16
*Address
, u16
*Value
, u16 RegCount
, u8 bAddUSBCSRAddress
)
765 ret
= zd1211_USB_PACKAGE_WRITE_REGISTER(Address
, Value
, RegCount
, bAddUSBCSRAddress
);
769 FPRINT("zd1211_WriteMultiRegister failed");
779 int zd1211_writel(u32 Address
, u32 Value
, u8 bAddUSBCSRAddress
)
781 struct zd1205_private
*macp
= g_dev
->priv
;
795 if (bAddUSBCSRAddress
&& (Address
<= ZD1205_PHY_END
))
805 tmpvalue
= zd_readl(CtlReg1
);
808 if (((macp
->USBCSRAddress
+CtlReg1
) & BASE_ADDR_MASK_HOST
) == USB_BASE_ADDR_HOST
)
809 WriteAddr
[0] = (u16
) (macp
->USBCSRAddress
+CtlReg1
) + 1;
812 // must write High word first
813 WriteAddr
[0] = (u16
) (macp
->USBCSRAddress
+CtlReg1
) + 2;
815 WriteData
[0] = (u16
) (tmpvalue
>> 16);
817 WriteAddr
[1] = (u16
) (macp
->USBCSRAddress
+CtlReg1
);
819 WriteData
[1] = (u16
) (tmpvalue
& 0xFFFF);
821 if (bAddUSBCSRAddress
){
822 Address
+= (u16
) (macp
->USBCSRAddress
);
823 if ((Address
& BASE_ADDR_MASK_HOST
) == USB_BASE_ADDR_HOST
)
824 WriteAddr
[2] = (u16
) Address
+ 1;
826 // must write High word first
827 WriteAddr
[2] = (u16
) Address
+ 2;
830 WriteAddr
[2] = (u16
) Address
+ 1;
832 WriteData
[2] = (u16
) (Value
>> 16);
833 WriteAddr
[3] = (u16
) Address
;
835 WriteData
[3] = (u16
) (Value
& 0xFFFF);
841 if (((macp
->USBCSRAddress
+CtlReg1
) & BASE_ADDR_MASK_HOST
) == USB_BASE_ADDR_HOST
)
843 WriteAddr
[4] = (u16
) (macp
->USBCSRAddress
+CtlReg1
) + 1;
845 // must write High word first
846 WriteAddr
[4] = (u16
) (macp
->USBCSRAddress
+CtlReg1
) + 2;
848 WriteData
[4] = (u16
) (tmpvalue
>> 16);
849 WriteAddr
[5] = (u16
) (macp
->USBCSRAddress
+CtlReg1
);
850 WriteData
[5] = (u16
) (tmpvalue
& 0xFFFF);
852 return zd1211_USB_PACKAGE_WRITE_REGISTER(WriteAddr
, WriteData
, 6, false);
857 if (bAddUSBCSRAddress
&& Address
< 0x8000){
858 Address
+= macp
->USBCSRAddress
;
859 if ((Address
& BASE_ADDR_MASK_HOST
) == USB_BASE_ADDR_HOST
)
860 WriteAddr
[0] = (u16
) Address
+ 1;
862 // must write High word first
863 WriteAddr
[0] = (u16
) Address
+ 2;
866 WriteAddr
[0] = (u16
) Address
+ 1;
868 WriteAddr
[1] = (u16
) Address
;
869 WriteData
[0] = (u16
) (Value
>> 16);
870 WriteData
[1] = (u16
) (Value
& 0xFFFF);
874 ret
= zd1211_USB_PACKAGE_WRITE_REGISTER(WriteAddr
, WriteData
, 2, false);
878 printk(KERN_ERR
"zd1211_writel failed for 5 attempts\n");
892 void zd1211_StrongSignalDect(struct zd1205_private
*macp
)
896 if ( (macp
->PHYTestTimerCount
>= macp
->PHYTestTimer
)&&
897 (macp
->PHYTestTimer
) && (macp
->PHYLowPower
& BIT_0
) &&
898 (!dot11Obj
.bContinueTx
) &&
901 macp
->PHYTestTimerCount
= 0;
902 if (macp
->RF_Mode
== RFMD_RF
){
903 if ( (macp
->PHYTestRssi
>= macp
->PHYTestRssiBound
) &&
905 ((!dot11Obj
.CR122Flag
) || (dot11Obj
.CR122Flag
== 2))){
906 LockPhyReg(&dot11Obj
);
907 zd_writel(0xff, ZD1205_CR122
);
909 if ( (macp
->PHYLowPower
& BIT_1
)&&
910 ((!dot11Obj
.CR31Flag
) || (dot11Obj
.CR31Flag
== 2)) ){
913 macp
->bTraceSetPoint
= 0;
915 tmpvalue
= dot11Obj
.IntValue
[dot11Obj
.Channel
-1] - cPWR_STRONG_SIG_DROP
;
917 zd_writel(tmpvalue
, ZD1205_CR31
);
919 dot11Obj
.CR31Flag
= 1;
923 UnLockPhyReg(&dot11Obj
);
925 dot11Obj
.CR122Flag
= 1;
928 else if ( (macp
->PHYTestRssi
< macp
->PHYTestRssiBound
) &&
929 ((dot11Obj
.CR122Flag
) || (dot11Obj
.CR122Flag
== 2)) ){
930 LockPhyReg(&dot11Obj
);
931 zd_writel(0x00, ZD1205_CR122
);
932 UnLockPhyReg(&dot11Obj
);
934 if ( (macp
->PHYLowPower
& BIT_1
) &&
936 ((dot11Obj
.CR31Flag
) || (dot11Obj
.CR31Flag
== 2)) ){
937 macp
->bTraceSetPoint
= 1;
939 HW_UpdateIntegrationValue(&dot11Obj
, dot11Obj
.Channel
, macp
->cardSetting
.MacMode
);
941 dot11Obj
.CR31Flag
= 0;
946 dot11Obj
.CR122Flag
= 0;
950 else if((macp
->RF_Mode
== AL2230_RF
) || (macp
->RF_Mode
== AL2230S_RF
)){
951 if ( (macp
->PHYTestRssi
>= macp
->PHYTestRssiBound
)&&
952 ((!dot11Obj
.CR203Flag
) || (dot11Obj
.CR203Flag
== 2)) ){
954 LockPhyReg(&dot11Obj
);
956 zd_writel(0x0a, ZD1205_CR203
);
957 if ( (macp
->PHYLowPower
& BIT_1
)&&
958 ((!dot11Obj
.CR31Flag
) || (dot11Obj
.CR31Flag
== 2)) ){
962 macp
->bTraceSetPoint
= 0;
964 tmpvalue
= dot11Obj
.IntValue
[dot11Obj
.Channel
-1] - cPWR_STRONG_SIG_DROP
;
965 zd_writel(tmpvalue
, ZD1205_CR31
);
966 dot11Obj
.CR31Flag
= 1;
969 UnLockPhyReg(&dot11Obj
);
970 dot11Obj
.CR203Flag
= 1;
972 else if ( (macp
->PHYTestRssi
< macp
->PHYTestRssiBound
)&&
973 ((dot11Obj
.CR203Flag
) || (dot11Obj
.CR203Flag
== 2)) ){
974 LockPhyReg(&dot11Obj
);
975 zd_writel(0x06, ZD1205_CR203
);
976 UnLockPhyReg(&dot11Obj
);
981 if ( (macp
->PHYLowPower
& BIT_1
)&&
982 ((dot11Obj
.CR31Flag
) || (dot11Obj
.CR31Flag
== 2)) ){
984 macp
->bTraceSetPoint
= 1;
987 HW_UpdateIntegrationValue(&dot11Obj
, dot11Obj
.Channel
, macp
->cardSetting
.MacMode
);
988 dot11Obj
.CR31Flag
= 0;
992 dot11Obj
.CR203Flag
= 0;
997 macp
->PHYTestTimerCount
++;
1003 //================================================================
1004 // Housekeeping Every 0.5 s
1005 //================================================================
1008 void zd1211_TxCalibration(struct zd1205_private
*macp
)
1010 static u32 loop
= 0;
1012 static u16 TrackingLoop
= 0;
1013 static u32 accumulate
= 0;
1018 static u16 TrackingCnt
= 0;
1019 static u32 accumulate_OFDM
= 0;
1020 static u16 TrackingCnt_OFDM
= 0;
1021 u8 PreTxOFDMType
= cTX_CCK
;
1027 if ((loop
% 64) == 0){
1028 if (macp
->bTraceSetPoint
){
1031 LockPhyReg(&dot11Obj
);
1032 if (TrackingLoop
== TRACKING_NUM
) {
1036 if (TrackingCnt
&& PURE_A_MODE
!= macp
->cardSetting
.MacMode
){
1037 average
= (u32
) (accumulate
/ TrackingCnt
);
1038 channel
= dot11Obj
.Channel
;
1039 setpoint
= macp
->EepSetPoint
[channel
-1];
1040 if (macp
->EnableTxPwrCtrl
) {
1041 if (average
< (u32
) (setpoint
- cPWR_CTRL_GUARD
))
1042 zd1205_IncreaseTxPower(macp
, cTX_CCK
);
1043 else if (average
> setpoint
)
1045 zd1205_DecreaseTxPower(macp
, cTX_CCK
);
1051 if (TrackingCnt_OFDM
){
1052 average
= (u32
) (accumulate_OFDM
/ TrackingCnt_OFDM
);
1053 channel
= dot11Obj
.Channel
;
1054 if(PURE_A_MODE
!= macp
->cardSetting
.MacMode
) {
1055 setpoint
= macp
->SetPointOFDM
[macp
->TxOFDMType
- cTX_OFDM
][channel
- 1];
1057 else if (PURE_A_MODE
== macp
->cardSetting
.MacMode
) {
1058 u8 UselessInt
;//Only for store return Integration value that we don't need
1060 ret
= a_OSC_get_cal_int(
1062 macp
->cardSetting
.LastSentTxRate
,
1063 &UselessInt
, &setpoint
);
1064 if(0 != ret
) printk("a_OSC_get_cal_int can't found the channel\n");
1066 //printk("Enter TrackingCnt_OFDM(CH:%d)(SET:%d)(avg:%d)\n",channel,setpoint,average);
1067 if (macp
->EnableTxPwrCtrl
){
1068 if (average
< (u32
) (setpoint
- cPWR_CTRL_GUARD
))
1069 zd1205_IncreaseTxPower(macp
, cTX_OFDM
);
1070 else if (average
> setpoint
)
1071 zd1205_DecreaseTxPower(macp
, cTX_OFDM
);
1073 accumulate_OFDM
= 0;
1074 TrackingCnt_OFDM
= 0;
1080 tmpvalue
= zd_readl(rLED_CTRL
);
1081 if (tmpvalue
& BIT_0
){ // Continuous Tx
1082 if (tmpvalue
& BIT_2
){ // Tx OFDM
1085 macp
->TxOFDMCnt
= cTX_SENT_LEN
+ 1;
1086 tmpvalue
= zd_readl(ZD1205_CR132
);
1088 macp
->TxOFDMType
= cTX_OFDM
;
1089 if (tmpvalue
== 0xC)
1090 macp
->TxOFDMType
= cTX_54M
;
1092 else if (tmpvalue
== 0x8)
1096 macp
->TxOFDMType
= cTX_48M
;
1099 macp
->TxPwrCCK
++; // Tx CCK
1102 if (macp
->TxPwrCCK
){ // New sent after last read
1103 tmpvalue
= zd_readl(ZD1205_CR58
);
1105 accumulate
+= tmpvalue
;
1113 if (macp
->TxPwrOFDM
){
1114 if (macp
->TxOFDMCnt
> cTX_SENT_LEN
){ // make sure Tx by HMAC (for UMAC)
1115 tmpvalue
= zd_readl(ZD1205_CR57
);
1117 accumulate_OFDM
+= tmpvalue
;
1118 TrackingCnt_OFDM
++;
1119 PreTxOFDMType
= macp
->TxOFDMType
;
1122 if (PreTxOFDMType
!= macp
->TxOFDMType
) {
1124 accumulate_OFDM
= 0;
1125 TrackingCnt_OFDM
= 0;
1129 macp
->TxPwrOFDM
= 0;
1132 UnLockPhyReg(&dot11Obj
);
1142 //================================================================
1143 // Housekeeping Every 1s
1146 //================================================================
1147 void zd1211_CheckWithIPC(struct zd1205_private
*macp
)
1149 static u32 loop
= 0;
1150 u8 BssType
= macp
->cardSetting
.BssType
;
1154 if ((loop
% 10) == 0){
1155 // bypass the weak signal in BSS and AP mode
1156 if ( (macp
->bAssoc
) &&
1157 (macp
->PHYTestRssi
<= 0x18) &&
1158 ((BssType
== INDEPENDENT_BSS
) ||
1159 (BssType
== PSEUDO_IBSS
)) ){
1160 if (!macp
->CR138Flag
){
1162 LockPhyReg(&dot11Obj
);
1163 zd_writel(0xa8, ZD1205_CR138
);
1166 UnLockPhyReg(&dot11Obj
);
1167 macp
->CR138Flag
= 1;
1171 else if (macp
->CR138Flag
){
1172 LockPhyReg(&dot11Obj
);
1173 zd_writel(0x28, ZD1205_CR138
);
1174 UnLockPhyReg(&dot11Obj
);
1175 macp
->CR138Flag
= 0;
1179 // solve the throughput problem when communicate with the IPC card
1180 if ( ((macp
->rxDataPerSec
+ macp
->txDataPerSec
) > 50000) &&
1182 (macp
->RF_Mode
== RFMD_RF
) &&
1183 (BssType
!= PSEUDO_IBSS
) &&
1184 (macp
->IPCFlag
!= 4) ){
1187 if ( (macp
->rxDataPerSec
> 3*macp
->txDataPerSec
) &&
1188 (macp
->PHYTestRssi
<= 0x24) ){
1189 if ((!macp
->IPCFlag
) || (macp
->IPCFlag
!=1)){
1190 LockPhyReg(&dot11Obj
);
1191 zd_writel(0x0a, ZD1205_CR87
);
1192 zd_writel(0x04, ZD1205_CR89
);
1193 UnLockPhyReg(&dot11Obj
);
1194 macp
->AdapterMaxRate
= 8; // MAX = 24M
1198 else if ( 3*macp
->rxDataPerSec
< macp
->txDataPerSec
){
1199 if ((!macp
->IPCFlag
) || (macp
->IPCFlag
!= 3)){
1200 LockPhyReg(&dot11Obj
);
1201 zd_writel(0x2A, ZD1205_CR87
);
1202 zd_writel(0x24, ZD1205_CR89
);
1203 UnLockPhyReg(&dot11Obj
);
1204 macp
->AdapterMaxRate
= 0x0B; // MAX = 54M
1211 if ((!macp
->IPCFlag
) || (macp
->IPCFlag
!= 2)){
1212 LockPhyReg(&dot11Obj
);
1213 zd_writel(0x10, ZD1205_CR87
);
1214 zd_writel(0x0C, ZD1205_CR89
);
1215 UnLockPhyReg(&dot11Obj
);
1216 macp
->AdapterMaxRate
= 9; // MAX = 36M
1223 else if ((macp
->RF_Mode
== RFMD_RF
) &&
1225 (BssType
== PSEUDO_IBSS
) &&
1226 (macp
->IPCFlag
!= 4)){
1227 if ((!macp
->IPCFlag
) || (macp
->IPCFlag
!= 3)){
1228 LockPhyReg(&dot11Obj
);
1229 zd_writel(0x2A, ZD1205_CR87
);
1230 zd_writel(0x24, ZD1205_CR89
);
1231 UnLockPhyReg(&dot11Obj
);
1232 macp
->AdapterMaxRate
= 0x0B; // MAX = 54M
1238 else if ((macp
->RF_Mode
== RFMD_RF
) &&
1239 (macp
->IPCFlag
!= 4) ){
1240 if ( (!macp
->IPCFlag
) || (macp
->IPCFlag
!= 2)){
1241 LockPhyReg(&dot11Obj
);
1242 zd_writel(0x10, ZD1205_CR87
);
1243 zd_writel(0x0C, ZD1205_CR89
);
1245 UnLockPhyReg(&dot11Obj
);
1246 macp
->AdapterMaxRate
= 9; // MAX = 36M
1251 macp
->rxDataPerSec
= 0;
1252 macp
->txDataPerSec
= 0;
1255 if (macp
->LinkLEDn
== LED2
)
1256 iLED_OFF(macp
, LED1
);
1261 if ((macp
->LinkTimer
== 1) && (macp
->LinkLED_OnDur
!= 0)){
1262 iLED_ON(macp
, macp
->LinkLEDn
);
1266 if (macp
->LinkTimer
== (macp
->LinkLED_OnDur
+ 1)){
1267 iLED_OFF(macp
, macp
->LinkLEDn
);
1271 if (macp
->LinkTimer
>= (macp
->LinkLED_OnDur
+ macp
->LinkLED_OffDur
))
1272 macp
->LinkTimer
= 0;
1276 if (dot11Obj
.PhyTest
& BIT_8
){
1279 LockPhyReg(&dot11Obj
);
1280 tmpvalue
= zd_readl(ZD1205_CR122
);
1281 if ((tmpvalue
& 0xFF) != 0xFF)
1282 zd_writel(0xFF, ZD1205_CR122
);
1285 zd_writel(0x00, ZD1205_CR122
);
1286 UnLockPhyReg(&dot11Obj
);
1289 }// end of (loop % 10)
1293 // Switch to another antenna
1294 void zd1211_SwitchAntenna(struct zd1205_private
*macp
)
1298 LockPhyReg(&dot11Obj
);
1300 tmpvalue
= zd_readl(ZD1205_CR10
);
1302 zd_writel(tmpvalue
, ZD1205_CR10
);
1304 tmpvalue
= zd_readl(ZD1205_CR9
);
1306 zd_writel(tmpvalue
, ZD1205_CR9
);
1308 UnLockPhyReg(&dot11Obj
);
1311 //-----------------------------------------------------------------------------
1313 // 1:Intel Flash; 0: MXIC, Winbond, AMD, Atmel...
1314 #define cFLASH_MXIC 0
1315 #define cFLASH_INTEL 1
1317 u16
zd1211_SetHighAddr(struct zd1205_private
*macp
, u16 high_addr
)
1320 u16 WriteAddr
[cMAX_MULTI_WRITE_REG_NUM
];
1321 u16 WriteData
[cMAX_MULTI_WRITE_REG_NUM
];
1324 tmp_cr203
= ((high_addr
<< 1) & ~mMASK(2)) + (high_addr
& mBIT(0));
1326 if (macp
->FlashType
== cFLASH_INTEL
){
1327 mFILL_WRITE_REGISTER(rLED_CTRL
, 0);
1328 if (mTEST_BIT(high_addr
, 7))
1329 mFILL_WRITE_REGISTER(rLED_CTRL
, LED2
);
1333 mFILL_WRITE_REGISTER(ZD1205_CR203
, tmp_cr203
);
1334 zd1211_WriteMultiRegister(WriteAddr
, WriteData
, WriteIndex
, true);
1339 /* abs_addr: in word */
1340 u16
zd1211_SetAbsAddr(struct zd1205_private
*macp
, u32 abs_addr
, u16
*get_cr203
)
1343 static u16 pre_high_addr
= 0, pre_cr203
= 0;
1347 high_addr
= (u16
) (abs_addr
>> 14);
1348 if (pre_high_addr
!= high_addr
){
1349 pre_cr203
= zd1211_SetHighAddr(macp
, high_addr
);
1350 pre_high_addr
= high_addr
;
1354 if (get_cr203
!= NULL
)
1355 *get_cr203
= pre_cr203
;
1357 return ((u16
) (abs_addr
& mMASK(14)));
1360 void zd1211_FlashCmdWrite(struct zd1205_private
*macp
, u8 Cmd
)
1363 u16 WriteAddr
[cMAX_MULTI_WRITE_REG_NUM
];
1364 u16 WriteData
[cMAX_MULTI_WRITE_REG_NUM
];
1367 tmpvalue
= zd1211_readl(ZD1205_CR203
, true);
1368 if (macp
->FlashType
== cFLASH_MXIC
){
1369 mFLASH_WRITE_EVEN_ADDR(0xAAA, 0xAA, tmpvalue
);
1370 mFLASH_WRITE_ODD_ADDR(0x555, 0x55, tmpvalue
);
1371 mFLASH_WRITE_EVEN_ADDR(0xAAA, Cmd
, tmpvalue
);
1375 mFLASH_WRITE_EVEN_ADDR(0, Cmd
, tmpvalue
);
1376 zd1211_WriteMultiRegister(WriteAddr
, WriteData
, WriteIndex
, false);
1379 void zd1211_FlashResetCmd(struct zd1205_private
*macp
)
1381 if (macp
->FlashType
== cFLASH_MXIC
)
1382 zd1211_writel(0, 0xF0, false);
1384 zd1211_FlashCmdWrite(macp
, 0xFF);
1389 void zd1211_InitHighAddr(struct zd1205_private
*macp
)
1391 u16 WriteAddr
[cMAX_MULTI_WRITE_REG_NUM
];
1393 u16 WriteData
[cMAX_MULTI_WRITE_REG_NUM
];
1396 mFILL_WRITE_REGISTER(UMAC_WAIT_STATE
, 0x022); // 25ns * 2
1397 mFILL_WRITE_REGISTER(ZD1205_CR11
+ (u16
) (macp
->USBCSRAddress
), 0x15);
1398 // Use AntSel to control VPEN for Intel Flash
1399 mFILL_WRITE_REGISTER(ZD1205_CR10
+ (u16
) (macp
->USBCSRAddress
), 0x82);
1401 mFILL_WRITE_REGISTER(ZD1205_CR9
+ (u16
) (macp
->USBCSRAddress
), 0x24);
1402 mFILL_WRITE_REGISTER(ZD1205_CR204
+ (u16
) (macp
->USBCSRAddress
), 0x7C);
1403 mFILL_WRITE_REGISTER(ZD1205_CR203
+ (u16
) (macp
->USBCSRAddress
), 0);
1404 zd1211_WriteMultiRegister(WriteAddr
, WriteData
, WriteIndex
, false);
1405 if (macp
->FlashType
== 0xFF){
1409 macp
->FlashType
= cFLASH_INTEL
;
1410 zd1211_FlashCmdWrite(macp
, 0x90); // Read Chip ID
1412 tmpvalue
= zd1211_readl(0, false);
1413 if ((tmpvalue
& 0xFFFF) != 0x8989) // Intel Manufacture Code
1414 macp
->FlashType
= cFLASH_MXIC
;
1416 zd1211_SetAbsAddr(macp
, 0, NULL
);
1417 zd1211_FlashResetCmd(macp
);
1423 /* Top: 8k byte / sector ==> 0 - 0x1000 (word address) */
1424 /* ==> sec0 address = 0; sec1 address = 0x1000 ... */
1425 void zd1211_FlashSecErase(struct zd1205_private
*macp
, u16 Sec0
)
1428 u16 WriteAddr
[cMAX_MULTI_WRITE_REG_NUM
];
1429 u16 WriteData
[cMAX_MULTI_WRITE_REG_NUM
];
1432 LockPhyReg(&dot11Obj
);
1433 tmpvalue
= zd1211_readl(ZD1205_CR203
, true);
1434 if (macp
->FlashType
== cFLASH_MXIC
){
1435 zd1211_FlashCmdWrite(macp
, 0x80);
1436 mFLASH_WRITE_EVEN_ADDR(0xAAA, 0xAA, tmpvalue
);
1437 mFLASH_WRITE_ODD_ADDR(0x555, 0x55, tmpvalue
);
1438 mFLASH_WRITE_EVEN_ADDR(Sec0
<< 1, 0x30, tmpvalue
);
1442 mFLASH_SET_EVEN_ADDR(tmpvalue
);
1443 mFILL_WRITE_REGISTER(Sec0
, 0x20);
1445 mFILL_WRITE_REGISTER(Sec0
, 0xD0);
1448 zd1211_WriteMultiRegister(WriteAddr
, WriteData
, WriteIndex
, false);
1449 UnLockPhyReg(&dot11Obj
);
1456 void zd1211_EraseFlash(struct zd1205_private
*macp
)
1462 macp
->bDisableTx
= 1;
1463 //USB_StopTxEP(Adapter);
1464 LockPhyReg(&dot11Obj
);
1465 macp
->bAllowAccessRegister
= 0;
1468 zd1211_InitHighAddr(macp
);
1470 if (macp
->FlashType
== cFLASH_MXIC
)
1473 zd1211_FlashCmdWrite(macp
, 0x80);
1474 zd1211_FlashCmdWrite(macp
, 0x10);
1477 for (ii
= 0; ii
< 0x400000L
; ii
+= 0x10000L
){
1478 low_addr
= zd1211_SetAbsAddr(macp
, ii
, NULL
);
1479 zd1211_FlashSecErase(macp
, low_addr
);
1480 for (jj
= 0; jj
< 100; jj
++){
1481 tmpvalue
= zd1211_readl(0, false);
1482 if (tmpvalue
& 0x8000)
1485 mdelay(10); // Sleep 10ms
1492 //macp->bAllowAccessRegister = 1;
1496 UnLockPhyReg(&dot11Obj
);
1498 //macp->bDisableTx = 0;
1502 #if !fPROG_FLASH_BY_FW
1503 void FlashProgram(struct zd1205_private
*macp
, u16 addr0
, u8
*pbuf
, u16 tmpvalue
)
1505 u16 WriteAddr
[cMAX_MULTI_WRITE_REG_NUM
];
1506 u16 WriteData
[cMAX_MULTI_WRITE_REG_NUM
];
1510 if (macp
->FlashType
== cFLASH_MXIC
){
1511 for (jj
= 0; jj
< 16; jj
++){
1513 mFLASH_SET_EVEN_ADDR(tmpvalue
);
1514 zd1211_FlashCmdWrite(macp
, 0xA0);
1515 mFILL_WRITE_REGISTER(addr0
+ jj
, pbuf
[jj
* 2]);
1516 zd1211_WriteMultiRegister(WriteAddr
, WriteData
, WriteIndex
, false;
1519 for (jj
= 0; jj
< 16; jj
++){
1521 mFLASH_SET_ODD_ADDR(tmpvalue
);
1522 zd1211_FlashCmdWrite(macp
, 0xA0);
1523 mFILL_WRITE_REGISTER(addr0
+ jj
, pbuf
[jj
* 2 + 1]);
1528 mFLASH_SET_EVEN_ADDR(tmpvalue
);
1531 zd1211_WriteMultiRegister(WriteAddr
, WriteData
, WriteIndex
, false);
1536 mFLASH_SET_EVEN_ADDR(tmpvalue
);
1537 mFILL_WRITE_REGISTER(addr0
, 0xE8);
1538 mFILL_WRITE_REGISTER(addr0
, 0x0F);
1539 for (jj
= 0; jj
< 8; jj
++)
1540 mFILL_WRITE_REGISTER(addr0
+ jj
, pbuf
[jj
* 2]);
1541 zd1211_WriteMultiRegister(WriteAddr
, WriteData
, WriteIndex
, false);
1545 for (jj
= 8; jj
< 16; jj
++)
1547 mFILL_WRITE_REGISTER(addr0
+ jj
, pbuf
[jj
* 2]);
1549 mFILL_WRITE_REGISTER(0, 0xD0);
1550 zd1211_WriteMultiRegister(WriteAddr
, WriteData
, WriteIndex
, false);
1553 mFLASH_SET_ODD_ADDR(tmpvalue
);
1554 mFILL_WRITE_REGISTER(addr0
, 0xE8);
1555 mFILL_WRITE_REGISTER(addr0
, 0x0F);
1556 for (jj
= 0; jj
< 8; jj
++)
1557 mFILL_WRITE_REGISTER(addr0
+ jj
, pbuf
[jj
* 2 + 1]);
1558 zd1211_WriteMultiRegister(WriteAddr
, WriteData
, WriteIndex
, false);
1561 for (jj
= 8; jj
< 16; jj
++)
1562 mFILL_WRITE_REGISTER(addr0
+ jj
, pbuf
[jj
* 2 + 1]);
1563 mFILL_WRITE_REGISTER(0, 0xD0);
1564 zd1211_WriteMultiRegister(WriteAddr
, WriteData
, WriteIndex
, false);
1572 int zd1211_ProgFlash(struct zd1205_private
*macp
, u32 StartAddr
,
1573 u32 BufLenInBytes
, u8
*pDownloadBuffer
)
1580 #if fPROG_FLASH_BY_FW
1581 u16 WriteData
[cMAX_MULTI_RF_REG_NUM
];
1586 u16 ReadAddr
[cMAX_MULTI_READ_REG_NUM
];
1587 u16 ReadData
[cMAX_MULTI_READ_REG_NUM
];
1592 macp
->bDisableTx
= 1;
1593 //USB_StopTxEP(Adapter);
1595 LockPhyReg(&dot11Obj
);
1596 macp
->bAllowAccessRegister
= 0;
1598 zd1211_InitHighAddr(macp
);
1599 StartAddr
/= 2; // Convert Byte Addr to Word Addr
1601 for (ii
= 0; ii
< BufLenInBytes
/ 2; ii
+= 16){
1602 if (macp
->FlashType
== cFLASH_MXIC
){
1603 if ((ii
+ StartAddr
) >= 0x200000) // 2M Word = 4M Byte
1607 if ((ii
+ StartAddr
) >= 0x400000) // 4M Word = 8M Byte
1611 low_addr
= zd1211_SetAbsAddr(macp
, ii
+ StartAddr
, &tmpvalue
);
1613 #if fPROG_FLASH_BY_FW
1616 tmpvalue
|= ((macp
->FlashType
) << 8);
1617 mFILL_RF_REGISTER(mCLR_BIT((tmpvalue
), bmFLASH_A0
));
1618 mFILL_RF_REGISTER(low_addr
);
1620 for (jj
= 0; jj
< 16; jj
++)
1621 mFILL_RF_REGISTER((u16
) pDownloadBuffer
[(ii
+ jj
) * 2]);
1623 zd1211_USB_ProgramFlash(macp
, WriteData
, WriteIndex
);
1625 mFILL_RF_REGISTER(mSET_BIT((tmpvalue
), bmFLASH_A0
));
1626 mFILL_RF_REGISTER(low_addr
);
1628 for (jj
= 0; jj
< 16; jj
++)
1629 mFILL_RF_REGISTER((u16
) pDownloadBuffer
[(ii
+ jj
) * 2 + 1]);
1631 for (i
=0; i
<5; i
++){
1632 if (zd1211_USB_ProgramFlash(macp
, WriteData
, WriteIndex
))
1636 zd1211_FlashProgram(macp
, low_addr
, pDownloadBuffer
+ 2 * ii
, tmpvalue
);
1640 //macp->bAllowAccessRegister = 1;
1641 UnLockPhyReg(&dot11Obj
);
1642 //macp->bDisableTx = 0;
1649 int zd1211_USB_SET_RF_REG(u16
*InputValue
, int bIs3683A
)
1651 struct zd1205_private
*macp
= g_dev
->priv
;
1653 u8
*pRegBuffer
= NULL
;
1655 u16 size
= sizeof(USB_SET_RF
);
1657 u32 S_bit_cnt
= dot11Obj
.S_bit_cnt
;
1660 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1661 if (in_interrupt()){
1665 FPRINT("********zd1211_USB_SET_RF_REG in_interrupt*********");
1669 down(&macp
->reg_sem
);
1671 if (!(macp
->bUSBDeveiceAttached
)){
1676 pRegBuffer
= kmalloc(size
, GFP_KERNEL
);
1683 memset(pRegBuffer
, 0x0, size
);
1685 ((PUSB_SET_RF
)pRegBuffer
)->RequestID
= zd_cpu_to_le16(REGID_RFOFDMSET
);
1688 ((PUSB_SET_RF
)pRegBuffer
)->Value
= zd_cpu_to_le16(1);
1690 ((PUSB_SET_RF
)pRegBuffer
)->Value
= zd_cpu_to_le16(2);
1692 ((PUSB_SET_RF
)pRegBuffer
)->Index
= zd_cpu_to_le16((u16
)S_bit_cnt
);
1694 for (i
= 0; i
< S_bit_cnt
; i
++)
1695 ((PUSB_SET_RF
)pRegBuffer
)->Data
[i
] = zd_cpu_to_le16(InputValue
[i
]);
1697 bufSize
= sizeof(u16
) * (3+S_bit_cnt
);
1699 if (macp
->ep4isIntOut
)
1700 usb_fill_int_urb(macp
->reg_urb
, macp
->usb
,
1701 usb_sndintpipe(macp
->usb
, EP_REG_OUT
),
1702 pRegBuffer
, bufSize
,
1703 zd1211_reg_cb
, macp
, 1);
1705 usb_fill_bulk_urb(macp
->reg_urb
, macp
->usb
,
1706 usb_sndbulkpipe(macp
->usb
, EP_REG_OUT
),
1707 pRegBuffer
, bufSize
,
1708 zd1211_reg_cb
, macp
);
1709 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
1710 macp
->reg_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
1713 if ((ret
= SUBMIT_URB(macp
->reg_urb
, GFP_ATOMIC
))){
1714 printk(KERN_ERR
"zd1211: failed rf reg_urb\n");
1715 zd1211_DumpErrorCode(macp
, ret
);
1719 macp
->regWaitWCompCnt
++;
1720 wait_event(macp
->regSet_wait
, test_bit(ZD1211_CMD_FINISH
, &macp
->flags
));
1721 macp
->regRWCompCnt
++;
1722 clear_bit(ZD1211_CMD_FINISH
, &macp
->flags
);
1730 #define bmZD_IF_LE 1
1731 #define bmZD_RF_CLK 2
1732 #define bmZD_RF_DATA 3
1734 HW_Set_IF_Synthesizer(zd_80211Obj_t
*pObj
, U32 InputValue
)
1738 u16 WriteData
[cMAX_MULTI_RF_REG_NUM
];
1741 S_bit_cnt
= pObj
->S_bit_cnt
;
1742 InputValue
= InputValue
<< (31 - S_bit_cnt
);
1744 //to avoid un-necessary register read/write
1746 tmpvalue
= zd_readl(ZD_CR203
);
1747 tmpvalue
= mCLR_BIT(tmpvalue
, bmZD_IF_LE
);
1749 // Configure RF by Software
1750 tmpvalue
= mCLR_BIT(tmpvalue
, bmZD_RF_CLK
);
1753 InputValue
= InputValue
<< 1;
1755 if (InputValue
& 0x80000000){
1756 tmpvalue
= mSET_BIT(tmpvalue
, bmZD_RF_DATA
);
1757 mFILL_RF_REGISTER((u16
) tmpvalue
);
1760 tmpvalue
= mCLR_BIT(tmpvalue
, bmZD_RF_DATA
);
1761 mFILL_RF_REGISTER((u16
) tmpvalue
);
1764 if (WriteIndex
>= cMAX_MULTI_RF_REG_NUM
){
1765 FPRINT_V("S_bit_cnt over range! ", (u32
)pObj
->S_bit_cnt
);
1772 zd1211_USB_SET_RF_REG(WriteData
, 0);
1776 static void zd1211_tx_timeout(struct net_device
*dev
)
1778 struct zd1205_private
*macp
= dev
->priv
;
1783 printk("%s: Tx timed out.\n", dev
->name
);
1784 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,8))
1785 defer_kevent(macp
, KEVENT_USB_KILL_TX_URB
);
1787 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
1788 macp
->tx_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
1790 usb_unlink_urb(macp
->tx_urb
);
1794 zd1205_Ctrl_Set_t *pCtrlSet;
1796 zd1205_SwTcb_t *sw_tcb;
1799 if(macp->activeTxQ->count)
1801 sw_tcb = macp->activeTxQ->first;
1802 pCtrlSet = sw_tcb->pHwCtrlPtr;
1803 Tbd = sw_tcb->pFirstTbd;
1805 printk("##### Control Setting #####\n");
1807 printk("%02x ", *((U8 *)pCtrlSet+i));
1809 printk("##### MAC Header #####\n");
1811 printk("%02x ", *(U8 *)(Tbd->TbdBufferAddrLowPart+i));
1818 int zd1211_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1820 struct zd1205_private
*macp
= dev
->priv
;
1822 memcpy(&macp
->ifreq
, ifr
, sizeof(struct ifreq
));
1824 defer_kevent(macp
, KEVENT_STD_IOCTL
);
1828 #define ZD1211_TX_TIMEOUT (HZ*10)
1829 #define ZD1211_MTU 1500
1830 extern struct iw_handler_def p80211wext_handler_def
;
1832 u8
zd1211_InitSetup(struct net_device
*dev
, struct zd1205_private
*macp
)
1836 //return true; //for debug
1839 init_MUTEX(&macp
->ps_sem
);
1840 init_MUTEX(&macp
->reg_sem
);
1841 init_MUTEX(&macp
->bcn_sem
);
1842 init_MUTEX(&macp
->config_sem
);
1843 init_MUTEX(&macp
->ioctl_sem
);
1845 spin_lock_init(&(macp
->intr_lock
));
1846 spin_lock_init(&(macp
->q_lock
));
1847 spin_lock_init(&(macp
->cs_lock
));
1849 INIT_WORK(&macp
->kevent
, kevent
, macp
);
1850 INIT_WORK(&macp
->scan_tout_event
, kevent
, macp
);
1852 macp
->numTcb
= NUM_TCB
;
1853 macp
->numTbd
= NUM_TBD
;
1854 macp
->numRfd
= NUM_RFD
;
1855 macp
->numTbdPerTcb
= NUM_TBD_PER_TCB
;
1856 macp
->rxOffset
= ZD_RX_OFFSET
;
1857 macp
->rfd_size
= 24; // form CbStatus to NextCbPhyAddrHighPart
1859 init_timer(&macp
->watchdog_timer
);
1860 macp
->watchdog_timer
.data
= (unsigned long) dev
;
1862 macp
->watchdog_timer
.function
= (void *) &zd1205_watchdog_cb
;
1864 init_timer(&macp
->tm_hking_id
);
1865 macp
->tm_hking_id
.data
= (unsigned long) dev
;
1866 macp
->tm_hking_id
.function
= (void *) &HKeepingCB
;
1868 init_timer(&macp
->tm_mgt_id
);
1869 macp
->tm_mgt_id
.data
= (unsigned long) dev
;
1870 macp
->tm_mgt_id
.function
= (void *) &zd1205_mgt_mon_cb
;
1872 #if ZDCONF_LP_SUPPORT == 1
1873 init_timer(&macp
->tm_lp_poll_id
);
1874 macp
->tm_lp_poll_id
.data
= (unsigned long) dev
;
1875 macp
->tm_lp_poll_id
.function
= (void *)&zd1205_lp_poll_cb
;
1879 dot11Obj
.reg
= (void *)0x9000;
1880 macp
->regp
= (void *)0x9000;
1881 macp
->USBCSRAddress
= 0x9000;
1883 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1884 macp
->in_interval
= 10;
1886 macp
->in_interval
= 10;
1889 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1890 usb_fill_int_urb(macp
->intr_urb
, macp
->usb
,
1891 usb_rcvintpipe(macp
->usb
, EP_INT_IN
),
1892 macp
->IntEPBuffer
, MAX_EPINT_BUFFER
,
1893 zd1211_intr_cb
, macp
, macp
->in_interval
);
1895 usb_fill_bulk_urb(macp
->intr_urb
, macp
->usb
,
1896 usb_rcvbulkpipe(macp
->usb
, EP_INT_IN
),
1897 macp
->IntEPBuffer
, MAX_EPINT_BUFFER
,
1898 zd1211_intr_cb
, macp
);
1901 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
1902 macp
->intr_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
1905 macp
->intr_urb
->transfer_dma
= macp
->IntBufferHandle
;
1906 macp
->intr_urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1908 if ((res
= SUBMIT_URB(macp
->intr_urb
, GFP_KERNEL
))){
1909 printk(KERN_ERR
"zd1211: failed intr_urb\n");
1910 zd1211_DumpErrorCode(macp
, res
);
1915 dev
->open
= zd1205_open
;
1916 dev
->stop
= zd1205_close
;
1917 dev
->watchdog_timeo
= ZD1211_TX_TIMEOUT
;
1918 dev
->do_ioctl
= zd1205_ioctl
;
1920 #if WIRELESS_EXT > 12
1921 dev
->wireless_handlers
= (struct iw_handler_def
*)&p80211wext_handler_def
;
1924 dev
->hard_start_xmit
= zd1205_xmit_frame
;
1925 dev
->set_multicast_list
= zd1205_set_multi
;
1926 dev
->get_stats
= zd1205_get_stats
;
1927 #if ZDCONF_WE_STAT_SUPPORT == 1
1928 dev
->get_wireless_stats
= zd1205_iw_getstats
;
1929 #elif !defined(ZDCONF_WE_STAT_SUPPORT)
1930 #error "Undefine ZDCONF_WE_STAT_SUPPORT"
1932 dev
->mtu
= ZD1211_MTU
;
1933 dev
->set_mac_address
= zd1205_set_mac
;
1934 dev
->tx_timeout
= &zd1211_tx_timeout
;
1936 //dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
1937 dev
->flags
|= IFF_MULTICAST
;
1939 //memcpy(macp->ifname, dev->name, IFNAMSIZ);
1940 //macp->ifname[IFNAMSIZ-1] = 0;
1942 //prince add for led
1943 #if 0 // mask by Victor Yu. 04-04-2007
1944 #if defined CONFIG_ARCH_W341 || defined CONFIG_ARCH_W321
1945 mcpu_gpio_inout(1<<WLAN_LED
,MCPU_GPIO_OUTPUT
);
1946 mcpu_gpio_set(1<<WLAN_LED
,MCPU_GPIO_LOW
);
1947 #elif defined CONFIG_ARCH_W311
1948 *(volatile unsigned char *)WLAN_LED_REG
= ( (*(volatile unsigned char *)WLAN_LED_REG
) | (~PIO(WLAN_LED
)) );
1955 int zd1211_alloc_all_urbs(struct zd1205_private
*macp
)
1957 struct usb_interface
*interface
= macp
->interface
;
1958 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1959 struct usb_interface_descriptor
*iface_desc
= &interface
->altsetting
[0];
1962 struct usb_host_interface
*iface_desc
= &interface
->altsetting
[0];
1965 struct usb_endpoint_descriptor
*endpoint
;
1966 struct usb_endpoint_descriptor
*interrupt_in_endpoint
[MAX_NUM_PORTS
];
1967 struct usb_endpoint_descriptor
*interrupt_out_endpoint
[MAX_NUM_PORTS
];
1968 struct usb_endpoint_descriptor
*bulk_in_endpoint
[MAX_NUM_PORTS
];
1970 struct usb_endpoint_descriptor
*bulk_out_endpoint
[MAX_NUM_PORTS
];
1973 u8 num_bulk_out
= 0;
1975 u8 num_interrupt_in
= 0;
1976 u8 num_interrupt_out
= 0;
1981 /* descriptor matches, let's find the endpoints needed */
1982 /* check out the endpoints */
1983 //ZD1211DEBUG(2, "bNumEndpoints = %d\n", iface_desc->bNumEndpoints);
1984 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1985 for (i
= 0; i
< iface_desc
->bNumEndpoints
; ++i
) {
1987 endpoint
= &iface_desc
->endpoint
[i
];
1989 for (i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; ++i
) {
1990 endpoint
= &iface_desc
->endpoint
[i
].desc
;
1993 if ((endpoint
->bEndpointAddress
& 0x80) &&
1996 ((endpoint
->bmAttributes
& 3) == 0x02)) {
1998 /* we found a bulk in endpoint */
1999 bulk_in_endpoint
[num_bulk_in
] = endpoint
;
2003 macp
->wMaxPacketSize
= zd_le16_to_cpu(endpoint
->wMaxPacketSize
);
2004 if(macp
->wMaxPacketSize
!= 64 && macp
->wMaxPacketSize
!= 512)
2006 printk("Something wrong. Mostly, it's a endian issue\n");
2008 ZD1211DEBUG(0, "bulk in: wMaxPacketSize = %x\n", zd_le16_to_cpu(endpoint
->wMaxPacketSize
));
2013 if (((endpoint
->bEndpointAddress
& 0x80) == 0x00) &&
2014 ((endpoint
->bmAttributes
& 3) == 0x02)) {
2015 /* we found a bulk out endpoint */
2016 bulk_out_endpoint
[num_bulk_out
] = endpoint
;
2018 ZD1211DEBUG(0, "bulk out: wMaxPacketSize = %x\n", zd_le16_to_cpu(endpoint
->wMaxPacketSize
));
2022 if ((endpoint
->bEndpointAddress
& 0x80) &&
2025 ((endpoint
->bmAttributes
& 3) == 0x03)) {
2026 /* we found a interrupt in endpoint */
2027 interrupt_in_endpoint
[num_interrupt_in
] = endpoint
;
2029 macp
->in_interval
= endpoint
->bInterval
;
2030 ZD1211DEBUG(0, "interrupt in: wMaxPacketSize = %x\n", zd_le16_to_cpu(endpoint
->wMaxPacketSize
));
2032 ZD1211DEBUG(0, "interrupt in: int_interval = %d\n", endpoint
->bInterval
);
2036 if (((endpoint
->bEndpointAddress
& 0x80) == 0x00) &&
2037 ((endpoint
->bmAttributes
& 3) == 0x03)) {
2038 /* we found a interrupt out endpoint */
2039 interrupt_out_endpoint
[num_interrupt_out
] = endpoint
;
2040 ++num_interrupt_out
;
2041 macp
->ep4isIntOut
= 0;//1;
2043 ZD1211DEBUG(0, "interrupt out: wMaxPacketSize = %x\n", zd_le16_to_cpu(endpoint
->wMaxPacketSize
));
2044 macp
->out_interval
= endpoint
->bInterval
;
2049 macp
->num_bulk_in
= num_bulk_in
;
2050 macp
->num_bulk_out
= num_bulk_out
;
2051 macp
->num_interrupt_in
= num_interrupt_in
;
2053 macp
->num_interrupt_out
= num_interrupt_out
;
2056 macp
->rx_urb
= USB_ALLOC_URB(0, GFP_KERNEL
);
2060 macp
->tx_urb
= USB_ALLOC_URB(0, GFP_KERNEL
);
2061 if (!macp
->tx_urb
) {
2062 usb_free_urb(macp
->rx_urb
);
2067 macp
->intr_urb
= USB_ALLOC_URB(0, GFP_KERNEL
);
2068 if (!macp
->intr_urb
) {
2070 usb_free_urb(macp
->rx_urb
);
2071 usb_free_urb(macp
->tx_urb
);
2075 macp
->ctrl_urb
= USB_ALLOC_URB(0, GFP_KERNEL
);
2076 if (!macp
->ctrl_urb
) {
2077 usb_free_urb(macp
->rx_urb
);
2078 usb_free_urb(macp
->tx_urb
);
2079 usb_free_urb(macp
->intr_urb
);
2086 macp
->reg_urb
= USB_ALLOC_URB(0, GFP_KERNEL
);
2087 if (!macp
->reg_urb
) {
2088 usb_free_urb(macp
->rx_urb
);
2089 usb_free_urb(macp
->tx_urb
);
2090 usb_free_urb(macp
->intr_urb
);
2091 usb_free_urb(macp
->ctrl_urb
);
2095 #if 0//(LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
2097 macp
->IntEPBuffer
= kmalloc(MAX_EPINT_BUFFER
, GFP_KERNEL
);
2099 #else //always failed? why???
2100 macp
->IntEPBuffer
= usb_buffer_alloc(macp
->device
,
2103 &macp
->IntBufferHandle
);
2105 if (!macp
->IntEPBuffer
){
2106 FPRINT("usb_buffer_alloc failed");
2107 usb_free_urb(macp
->rx_urb
);
2108 usb_free_urb(macp
->tx_urb
);
2109 usb_free_urb(macp
->intr_urb
);
2110 usb_free_urb(macp
->ctrl_urb
);
2112 usb_free_urb(macp
->reg_urb
);
2123 void zd1211_free_all_urbs(struct zd1205_private
*macp
)
2129 usb_free_urb(macp
->rx_urb
);
2132 usb_free_urb(macp
->tx_urb
);
2135 usb_free_urb(macp
->intr_urb
);
2137 usb_free_urb(macp
->ctrl_urb
);
2139 usb_free_urb(macp
->reg_urb
);
2141 #if 0//(LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
2142 if (macp
->IntEPBuffer
)
2144 kfree(macp
->IntEPBuffer
);
2146 usb_buffer_free(macp
->device
,
2148 (void *)macp
->IntEPBuffer
,
2150 macp
->IntBufferHandle
);
2156 void zd1211_unlink_all_urbs(struct zd1205_private
*macp
)
2158 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,8))
2159 usb_kill_urb(macp
->rx_urb
);
2160 usb_kill_urb(macp
->tx_urb
);
2161 usb_kill_urb(macp
->ctrl_urb
);
2162 usb_kill_urb(macp
->reg_urb
);
2164 if (test_bit(ZD1211_UNPLUG
, &macp
->flags
))
2165 usb_kill_urb(macp
->intr_urb
);
2168 usb_unlink_urb(macp
->rx_urb
);
2169 usb_unlink_urb(macp
->tx_urb
);
2170 usb_unlink_urb(macp
->ctrl_urb
);
2171 usb_unlink_urb(macp
->reg_urb
);
2173 if (test_bit(ZD1211_UNPLUG
, &macp
->flags
))
2174 usb_unlink_urb(macp
->intr_urb
);
2180 #define MAX_RX_MERGE_PACKET_NUM 3
2181 void zd1211_rx_isr(unsigned long parm
)
2183 struct zd1205_private
*macp
= (struct zd1205_private
*)parm
;
2184 struct urb
*urb
= macp
->read_urb
;
2185 struct rx_list_elem
*rx_struct
;
2187 struct rx_list_elem
*rx_struct_array
[MAX_RX_MERGE_PACKET_NUM
];
2188 int total_rx_struct
= 1, rx_array_cnt
= 0;
2193 u32 TotalLength
= urb
->actual_length
;
2195 struct sk_buff
*skb
;
2196 zd1205_RFD_t
*rfd
= NULL
;
2199 /*if(in_irq())*/spin_lock(&macp
->intr_lock
);
2200 //else spin_lock_irqsave(&macp->intr_lock,flag);
2203 ZD1211DEBUG(4, "actual_length = %x\n", urb
->actual_length
);
2204 rx_struct
= list_entry(macp
->active_rx_list
.next
,
2205 struct rx_list_elem
, list_elem
);
2207 skb
= rx_struct
->skb
;
2208 rfd
= RFD_POINTER(skb
, macp
);
2209 pRxBuffer
= &rfd
->RxBuffer
[macp
->rxOffset
];
2213 zd1205_dump_data("pRxBuffer", (u8
*)pRxBuffer
, TotalLength
);
2214 //zd1211_submit_rx_urb(macp);
2219 if (rx_struct
->UnFinishFrmLen
){
2220 TotalLength
+= rx_struct
->UnFinishFrmLen
;
2221 rx_struct
->UnFinishFrmLen
= 0;
2222 macp
->CompLenInfoCnt
++;
2223 //ZD1211DEBUG(0, "Got Rx Frames Length Info!!\n");
2226 last_pkt_len
= TotalLength
& (macp
->wMaxPacketSize
- 1);
2228 if (last_pkt_len
<= (macp
->wMaxPacketSize
- 4)){
2229 if (zd_get_LE_U16(pRxBuffer
+ (TotalLength
/sizeof(u16
)-1)*2 ) == 0x697E) {
2230 //if (((u16 *) pRxBuffer)[TotalLength / sizeof(u16) - 1] == 0x697E){
2231 total_rx_struct
= 3;
2232 //ZD1211DEBUG(0, "Got merged Rx Frames!!\n");
2233 //zd1205_dump_data("pRxBuffer", (u8 *)pRxBuffer, TotalLength);
2234 macp
->Continue2Rx
++;
2237 macp
->NoMergedRxCnt
++;
2239 //ZD1211DEBUG(3, "last_pkt_len = %x\n", last_pkt_len);
2240 //zd1205_dump_data("pRxBuffer", (u8 *)pRxBuffer, TotalLength);
2242 for (i
=0; i
<total_rx_struct
; i
++){
2245 if (total_rx_struct
> 1){
2246 CurFrmLen
=zd_get_LE_U16(pRxBuffer
+(TotalLength
/sizeof(u16
)+i
-4)*2);
2247 //ZD1211DEBUG(2, "CurFrmLen = %x\n", CurFrmLen);
2250 CurFrmLen
= TotalLength
;
2252 if (CurFrmLen
== 0){
2256 if (list_empty(&(macp
->active_rx_list
)))break;
2258 rx_struct_array
[i
] = list_entry(macp
->active_rx_list
.next
,struct rx_list_elem
, list_elem
);
2259 list_del(&(rx_struct_array
[i
]->list_elem
));
2261 if (list_empty(&(macp->active_rx_list))){
2262 zd1205_add_skb_to_end(macp, rx_struct_array[i]);
2267 if(total_rx_struct>1){
2268 zd1205_add_skb_to_end(macp, rx_struct_array[i]);
2269 if (list_empty(&(macp->active_rx_list)))
2277 ZD1211DEBUG(2, "CurFrmLen = %x\n", CurFrmLen
);
2279 skb
= rx_struct_array
[i
]->skb
;
2280 rfd
= RFD_POINTER(skb
, macp
);
2282 rfd
->CbStatus
= RFD_STATUS_COMPLETE
;
2283 rfd
->ActualCount
= CurFrmLen
;
2286 memcpy(&rfd
->RxBuffer
[macp
->rxOffset
],
2291 tmpLen
+= (rfd
->ActualCount
& ~0x03);
2293 if (rfd
->ActualCount
& 0x03)
2295 rfd
->ActualCount
+= macp
->rxOffset
;
2299 // last_pkt_len = 509, 510, 511
2301 //ZD1211DEBUG(0, "Wait Rx Frames Length Info!!\n");
2302 //ZD1211DEBUG(2, "last_pkt_len = %x\n", last_pkt_len);
2303 macp
->WaitLenInfoCnt
++;
2304 rx_struct
->UnFinishFrmLen
= ((TotalLength
/ macp
->wMaxPacketSize
) + 1)
2305 * (macp
->wMaxPacketSize
);
2306 //zd1205_dump_data("pRxBuffer", (u8 *)pRxBuffer, TotalLength);
2309 if(zd1211_submit_rx_urb(macp
))
2311 //printk("No available buffer. Reallocate\n");
2313 zd1211_alloc_rx((unsigned long)macp
);
2314 if(zd1211_submit_rx_urb(macp
)){
2315 //printk("zd1211_submit_rx_urb fail. Abort\n");
2320 if (!rx_struct
->UnFinishFrmLen
){
2321 macp
->total_rx_cnt
= rx_array_cnt
;
2322 macp
->rx_struct_array
= rx_struct_array
;
2323 zd1205_rx_isr(macp
);
2327 rfd
->CbStatus
= RFD_STATUS_COMPLETE
;
2328 rfd
->ActualCount
= TotalLength
+ macp
->rxOffset
;
2329 zd1205_rx_isr(macp
);
2332 if (dot11Obj
.QueueFlag
& MGT_QUEUE_SET
)
2333 defer_kevent(macp
, KEVENT_PROCESS_SIGNAL
);
2335 /*if(in_irq())*/spin_unlock(&macp
->intr_lock
);
2336 //else spin_unlock_irqrestore(&macp->intr_lock,flag);
2340 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2341 void zd1211_rx_comp_cb(struct urb
*urb
)
2343 void zd1211_rx_comp_cb(struct urb
*urb
, struct pt_regs
*regs
)
2346 struct zd1205_private
*macp
= urb
->context
;
2349 macp
->lastRxComp
= jiffies
;
2350 if ((!macp
) || !test_bit(ZD1211_RUNNING
, &macp
->flags
))
2356 if (!netif_device_present(macp
->device
))
2358 printk("Error2 in %s\n", __FUNCTION__
);
2362 if (urb
->status
!= 0){
2363 /*printk("Error Occur in %s\n", __FUNCTION__);
2364 zd1211_DumpErrorCode(macp, urb->status);*/ //Johnson Liu remove 2009-03-02
2365 if ((urb
->status
!= -ENOENT
) &&
2367 (urb
->status
!= -ECONNRESET
) &&
2369 (urb
->status
!= -ESHUTDOWN
)) {
2370 //printk("nonzero read bulk status received: %d\n", urb->status);
2371 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2372 if (urb
->status
== USB_ST_INTERNALERROR
)
2374 printk("Error3 in %s\n", __FUNCTION__
);
2380 if (urb
->status
== -EPIPE
){
2381 printk("nonzero read bulk status received: -EPIPE\n");
2385 if (urb
->status
== -EPROTO
){
2386 printk("nonzero read bulk status received: -EPROTO\n");
2395 if(zd1211_submit_rx_urb(macp
))
2397 printk("No available buffer. Reallocate\n");
2398 zd1211_alloc_rx((unsigned long)macp
);
2399 if(zd1211_submit_rx_urb(macp
))
2400 printk("zd1211_submit_rx_urb fail. Abort\n");
2409 if (urb
->actual_length
== 0){
2410 FPRINT("Got Length = 0");
2412 if(zd1211_submit_rx_urb(macp
))
2414 printk("No available buffer. Reallocate\n");
2415 zd1211_alloc_rx((unsigned long)macp
);
2416 if(zd1211_submit_rx_urb(macp
))
2417 printk("zd1211_submit_rx_urb fail. Abort\n");
2423 macp
->read_urb
= urb
;
2424 zd1211_rx_isr((unsigned long) macp
);
2432 //callback function for interrupt or response
2433 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2434 void zd1211_intr_cb(struct urb
*urb
)
2436 void zd1211_intr_cb(struct urb
*urb
, struct pt_regs
*regs
)
2439 struct zd1205_private
*macp
= urb
->context
;
2442 u32 actual_length
= urb
->actual_length
;
2447 spin_lock(&macp
->intr_lock
);
2449 if (urb
->status
!= 0){
2450 zd1211_DumpErrorCode(macp
, urb
->status
);
2452 if (urb
->status
== -ENODEV
){ //device was removed
2453 FPRINT("Device was removed!!!");
2454 macp
->bUSBDeveiceAttached
= 0;
2456 wake_up(&macp
->regSet_wait
);
2457 wake_up_interruptible(&macp
->iorwRsp_wait
);
2459 spin_unlock(&macp
->intr_lock
);
2464 switch (urb
->status
){
2468 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
2471 macp
->bUSBDeveiceAttached
= 0;
2472 FPRINT("Device was down!!!");
2473 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
2474 spin_unlock(&macp
->intr_lock
);
2481 //printk("nonzero intr status received: %d\n", urb->status);
2487 if (macp
->IntEPBuffer
[0] != 0x01)
2488 FPRINT("Got unknown packet");
2490 switch (macp
->IntEPBuffer
[1]){
2493 // this is USB_READ_REGISTER response
2494 macp
->ReadRegCount
= (u16
)actual_length
;
2496 //intNum = *(u16 *)(macp->IntEPBuffer+2);
2497 intNum
= zd_get_LE_U16(macp
->IntEPBuffer
+2);
2499 if (intNum
== (InterruptCtrl
| macp
->USBCSRAddress
)){
2500 // Handle non-RxTx interrupt
2501 if (macp
->bHandleNonRxTxRunning
){
2502 printk("Impossible, interrupt happen!!!!! %x\n", intNum
);
2506 // disable non-RxTx interrupt
2507 // No needed to diable interrupt, firmware will do it.
2508 macp
->bHandleNonRxTxRunning
= 1;
2509 memcpy(macp
->IntEPBuffer3
, macp
->IntEPBuffer
, MAX_EPINT_BUFFER
);
2510 //printk("Get NON TX RX INT\n");
2511 defer_kevent(macp
, KEVENT_NON_TX_RX_INT
);
2515 // handle read register
2516 memcpy(macp
->IntEPBuffer2
, macp
->IntEPBuffer
, MAX_EPINT_BUFFER
);
2517 set_bit(ZD1211_REQ_COMP
, &macp
->flags
);
2518 wake_up_interruptible(&macp
->iorwRsp_wait
);
2522 case EPINT_RetryFial_Event
:
2524 u8
*pMacAddr
= macp
->IntEPBuffer
+ 4;
2525 //u8 NewRate = (u8)(*(u16 *)(macp->IntEPBuffer + 2));
2526 //u8 NewRate = macp->IntEPBuffer[2];
2530 if (macp
->TxOFDMType
>= cTX_48M
)
2531 macp
->TxOFDMCnt
= 0;
2534 if ( macp
->IntEPBuffer
[10] & BIT_0
)
2536 macp
->bIBSS_Wakeup_Dest
= 1;
2539 //ZD1211DEBUG(2, "Retry Failed!!!\n");
2540 //ZD1211DEBUG(2, "NewRate = %x\n", NewRate);
2541 aid
= zd_AidLookUp(pMacAddr
);
2542 zd_EventNotify(EVENT_TX_COMPLETE
, ZD_RETRY_FAILED
, 0xff, (U32
)aid
);
2543 //macp->retryFailCnt += *(u16 *)(macp->IntEPBuffer + 10);
2544 macp
->retryFailCnt
+= zd_get_LE_U16(macp
->IntEPBuffer
+ 10);
2551 FPRINT("Got Unknown interrupt!!!");
2557 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
2559 //memset(macp->IntEPBuffer, 0x0, MAX_EPINT_BUFFER);
2561 //use bulk instead of interrupt in
2562 usb_fill_bulk_urb(macp
->intr_urb
, macp
->usb
,
2563 usb_rcvbulkpipe(macp
->usb
, EP_INT_IN
),
2564 macp
->IntEPBuffer
, MAX_EPINT_BUFFER
,
2565 zd1211_intr_cb
, macp
);
2566 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
2567 macp
->intr_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
2569 status
= SUBMIT_URB(macp
->intr_urb
, GFP_ATOMIC
);
2571 status
= SUBMIT_URB(urb
, GFP_ATOMIC
);
2575 FPRINT("Can't resubmit interrupt urb!!!");
2578 spin_unlock(&macp
->intr_lock
);
2584 //callback function for register get/set
2585 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2586 void zd1211_reg_cb(struct urb
*urb
)
2588 void zd1211_reg_cb(struct urb
*urb
, struct pt_regs
*regs
)
2591 struct zd1205_private
*macp
= urb
->context
;
2592 set_bit(ZD1211_CMD_FINISH
, &macp
->flags
);
2593 wake_up(&macp
->regSet_wait
);
2596 void zd1211_handle_non_tx_rx(struct zd1205_private
*macp
)
2599 // in current design, no need to use spinlock
2601 //intr_status = *(u16 *)(macp->IntEPBuffer3+4);
2602 intr_status
= zd_get_LE_U16(macp
->IntEPBuffer3
+4);
2603 //ZD1211DEBUG(2, "intr_status = %x\n", intr_status);
2607 printk("In %s,, intr_status is NULL\n", __FUNCTION__
);
2612 if (intr_status
& WAKE_UP
){
2613 //printk("WAKE_UP\n");
2614 //printk(KERN_ERR "befor1 : %lu\n", jiffies);
2615 down(&macp
->ps_sem
);
2616 //printk(KERN_ERR "before2: %lu\n", jiffies);
2617 if (dot11Obj
.bDeviceInSleep
){
2618 zd1205_process_wakeup(macp
);
2621 //printk(KERN_ERR "after2: %lu\n", jiffies);
2623 //printk(KERN_ERR "after1: %lu\n", jiffies);
2627 if (intr_status
& CFG_NEXT_BCN
){
2628 //ZD1211DEBUG(2, "CFG_NEXT_BCN\n");
2629 if (macp
->config_next_bcn_en
){
2630 if (macp
->cardSetting
.BssType
== AP_BSS
)
2634 down(&macp
->bcn_sem
);
2635 zd_EventNotify(EVENT_TBCN
, 0, 0, 0);
2638 if (macp
->cardSetting
.BssType
== INDEPENDENT_BSS
){
2639 macp
->bFrmRxed1
= 0;
2642 else if (macp
->cardSetting
.BssType
== AP_BSS
){
2643 if (macp
->dtimCount
== 0)
2644 macp
->dtimCount
= macp
->cardSetting
.DtimPeriod
;
2651 if (intr_status
& DTIM_NOTIFY
){
2652 printk("DTIM_NOTIFY\n");
2653 if (macp
->dtim_notify_en
){
2655 zd_EventNotify(EVENT_DTIM_NOTIFY
, 0, 0, 0);
2660 macp
->bHandleNonRxTxRunning
= 0;
2662 // enable non-RxTx interrupt
2663 zd1205_enable_int();
2667 int zd1211_submit_rx_urb(struct zd1205_private
*macp
)
2669 struct rx_list_elem
*rx_struct
= NULL
;
2671 u32 bufLen
= MAX_WLAN_SIZE
- macp
->rxOffset
;
2673 //int memflags = GFP_KERNEL;
2677 rx_struct
= zd1205_start_ru(macp
);
2683 if (rx_struct
->UnFinishFrmLen
){
2684 rx_buff
= (u8
*)(rx_struct
->dma_addr
)+ macp
->rxOffset
+ (rx_struct
->UnFinishFrmLen
);
2685 bufLen
-= (rx_struct
->UnFinishFrmLen
);
2688 rx_buff
= (u8
*)(rx_struct
->dma_addr
) + macp
->rxOffset
;
2693 rx_buff
= (u8
*)(rx_struct
->dma_addr
) + macp
->rxOffset
;
2697 usb_fill_bulk_urb(macp
->rx_urb
, macp
->usb
,
2698 usb_rcvbulkpipe(macp
->usb
, EP_DATA_IN
),
2701 zd1211_rx_comp_cb
, macp
);
2703 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
2704 macp
->rx_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
2706 if ((res
= SUBMIT_URB(macp
->rx_urb
, GFP_ATOMIC
))){
2707 printk(KERN_ERR
"zd1211: failed rx_urb\n");
2708 zd1211_DumpErrorCode(macp
, res
);
2718 void zd1211_tx_isr(unsigned long parm
)
2720 struct zd1205_private
*macp
= (struct zd1205_private
*)parm
;
2721 zd1205_SwTcb_t
*sw_tcb
;
2726 spin_lock(&macp
->intr_lock
);
2728 sw_tcb
= macp
->activeTxQ
->first
;
2730 sw_tcb
->pTcb
->CbStatus
= CB_STATUS_COMPLETE
;
2731 zd1205_tx_isr(macp
);
2734 if (dot11Obj
.QueueFlag
& TX_QUEUE_SET
){
2735 macp
->txQueSetCnt
++;
2737 tasklet_schedule(&macp
->zd1205_tx_tasklet
);
2741 spin_unlock(&macp
->intr_lock
);
2749 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2750 void zd1211_tx_comp_cb(struct urb
*urb
)
2752 void zd1211_tx_comp_cb(struct urb
*urb
, struct pt_regs
*regs
)
2756 struct zd1205_private
*macp
= urb
->context
;
2759 if ((!macp
) || !test_bit(ZD1211_RUNNING
, &macp
->flags
))
2761 printk(KERN_ERR
"macp is NULL or macp.flags.ZD1211_RUNNING\n");
2765 if (!netif_device_present(macp
->device
))
2767 printk(KERN_ERR
"netif_device_present return NULL\n");
2773 printk(KERN_ERR
"Tx status: %d", urb
->status
);
2774 zd1211_DumpErrorCode(macp
, urb
->status
);
2777 macp
->usbTxCompCnt
++;
2778 //Clear here results in race condition on SMP. We move it to zd1205_tx_isr
2779 //clear_bit(ZD1211_TX_BUSY, &macp->flags);
2781 macp
->TxStartTime
= 0;
2783 macp
->write_urb
= urb
;
2785 zd1211_tx_isr((unsigned long) macp
);
2795 // return send_length
2796 int zd1211_submit_tx_urb(struct zd1205_private
*macp
,BOOLEAN LastFrag
)
2798 u8
*dst
= macp
->tx_buff
;
2801 u32 TotalLength
= 0;
2803 zd1205_Ctrl_Set_t
*pCtrlSet
;
2805 zd1205_SwTcb_t
*sw_tcb
;
2808 static U32 lastSetBusy
= 0;
2809 //int memflags = GFP_KERNEL;
2813 if (!macp
->activeTxQ
->count
)
2815 if(macp
->bPSMSupported
)
2816 if(test_bit(ZD1211_TX_BUSY
, &macp
->flags
) == 0)
2817 if(dot11Obj
.bDeviceInSleep
== 0 && mPwrState
== 1)
2818 if(macp
->bAssoc
&& atomic_read(&macp
->DoNotSleep
) == 0)
2819 if(!dot11Obj
.bMoreData
)
2821 //printk("Schedule to Sleep \n");
2822 dot11Obj
.bDeviceInSleep
= 1;
2823 defer_kevent(macp
, KEVENT_FALL_IN_SLEEP
);
2828 if(dot11Obj
.bDeviceInSleep
)
2833 if (test_and_set_bit(ZD1211_TX_BUSY
, &macp
->flags
))
2835 if(jiffies
- lastSetBusy
> 5*HZ
)
2837 printk("ZD1211_TX_BUSY is locked over 5 seconds\n");
2841 lastSetBusy
= jiffies
;
2845 sw_tcb
= macp
->activeTxQ
->first
;
2846 //Not include CtrlSet & MacHdr
2847 TxCbTbdNumber
= sw_tcb
->pTcb
->TxCbTbdNumber
- 2;
2848 pCtrlSet
= sw_tcb
->pHwCtrlPtr
;
2849 Tbd
= sw_tcb
->pFirstTbd
;
2851 // We skip TCB address, Address 1, NextLength = 16 bytes, add 2 bytes for total length
2852 //pCtrlSet->CtrlSetting[23]=0;
2853 //pCtrlSet->CtrlSetting[24]=0;
2855 memcpy(dst
, (u8
*)(pCtrlSet
), 3);
2860 memcpy(dst
, (u8
*)(pCtrlSet
)+(3+8), // 8 mean skip TCB address
2870 dst
+= 2; // reserver 2 bytes for total length
2876 memcpy(dst
, (u8
*)(pCtrlSet
)+(3+8+1+6+2), // 6:skip address 1, 2:skip next length
2883 ZD1211DEBUG(2, "Tx Ctrl Length = %x\n", TotalLength
);
2888 if(*((u8
*)Tbd
->TbdBufferAddrLowPart
) != PS_POLL
)
2890 *(U8
*)(Tbd
->TbdBufferAddrLowPart
+2) = 0;
2891 *(U8
*)(Tbd
->TbdBufferAddrLowPart
+3) = 0;
2895 if(macp
->bPSMSupported
!= 1)
2896 printk("What~~~~PS_POLL & mPwrState ==0\n");
2902 if(macp->bPSMSupported != 1)
2904 *(U8 *)(Tbd->TbdBufferAddrLowPart+2) = 0;
2905 *(U8 *)(Tbd->TbdBufferAddrLowPart+3) = 0;
2909 if( ((*((U8 *)pCtrlSet + 11)) & (BIT_2|BIT_3)) != (BIT_2 | BIT_3))
2911 *(U8 *)(Tbd->TbdBufferAddrLowPart+2) = 0;
2912 *(U8 *)(Tbd->TbdBufferAddrLowPart+3) = 0;
2915 printk("PS_POLL Found\n");
2919 if(*(u8 *)(Tbd->TbdBufferAddrLowPart+2)!=0) {
2920 //if(macp->bPSMSupported != 1)
2921 if(!( (*((U8 *)pCtrlSet + 11)) & BIT_2))
2923 *(U8 *)(Tbd->TbdBufferAddrLowPart+2) = 0;
2924 *(U8 *)(Tbd->TbdBufferAddrLowPart+3) = 0;
2925 // *(u16 *)(Tbd->TbdBufferAddrLowPart+2)=0;
2927 //printk("Non-Zero Duration,%d\n",*(u16 *)(Tbd->TbdBufferAddrLowPart+2));
2928 //printk("\n OK\n");
2930 else if(*(u8 *)(Tbd->TbdBufferAddrLowPart+3)!=0) {
2931 //if(macp->bPSMSupported != 1)
2932 if(!( (*((U8 *)pCtrlSet + 11)) & BIT_2))
2934 *(U8 *)(Tbd->TbdBufferAddrLowPart+2) = 0;
2935 *(U8 *)(Tbd->TbdBufferAddrLowPart+3) = 0;
2936 // *(u16 *)(Tbd->TbdBufferAddrLowPart+2)=0;
2938 //printk("Non-Zero Duration,%d\n",*(u16 *)(Tbd->TbdBufferAddrLowPart+2));
2939 //printk("\n OK\n");
2944 memcpy(dst
, (u8
*)Tbd
->TbdBufferAddrLowPart
, Tbd
->TbdCount
);
2946 ZD1211DEBUG(2, "MAC Header Length = %x\n", Tbd
->TbdCount
);
2947 dst
+= Tbd
->TbdCount
;
2949 TotalLength
+= Tbd
->TbdCount
;
2954 while(TxCbTbdNumber
)
2957 memcpy(dst
, (u8
*)Tbd
->TbdBufferAddrLowPart
, Tbd
->TbdCount
);
2959 ZD1211DEBUG(2, "Tx DATA Length = %x\n", Tbd
->TbdCount
);
2960 dst
+= Tbd
->TbdCount
;
2963 TotalLength
+= Tbd
->TbdCount
;
2966 ZD1211DEBUG(2, "TotalLength = %x\n", TotalLength
);
2968 if(LastFrag
== TRUE
) {
2969 if(TxCbTbdNumber
> 0)
2970 printk("TxCbTbdNumber > 0, This is invalid. It is greater than 0 only in LP_Mode. And LP_Mode doesn't allow fragment\n");
2971 memcpy(dst
-sw_tcb
->MIC_Len
,sw_tcb
->CalMIC
+sw_tcb
->MIC_Start
,sw_tcb
->MIC_Len
);
2977 // write down total length
2979 //*((u16 *)(macp->tx_buff+4)) = (u16)TotalLength + 14;
2980 // For endian-free U16 write
2981 *(macp
->tx_buff
+4) = (U8
)((U16
)TotalLength
+14) ;
2982 *(macp
->tx_buff
+5) = (U8
)(((U16
)TotalLength
+14) >> 8);
2983 #elif defined(ZD1211B)
2984 //*((u16 *)(macp->tx_buff+4)) = sw_tcb->LengthDiff;
2985 *(macp
->tx_buff
+4) = (U8
)(sw_tcb
->LengthDiff
);
2986 *(macp
->tx_buff
+5) = (U8
)(sw_tcb
->LengthDiff
>> 8);
2990 if(TotalLength > 400)
2994 printk("%02x ", *(macp->tx_buff+i));
2995 printk("Total : %d", TotalLength);
3001 ZD1211DEBUG(2, "macp->tx_buff+4 = %x\n", *((u16
*)(macp
->tx_buff
+4)));
3004 usb_fill_bulk_urb(macp
->tx_urb
, macp
->usb
,
3005 usb_sndbulkpipe(macp
->usb
, EP_DATA_OUT
),
3006 macp
->tx_buff
, TotalLength
,
3007 zd1211_tx_comp_cb
, macp
);
3011 macp
->tx_urb
->transfer_buffer_length
= TotalLength
;
3012 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
3013 macp
->tx_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
3015 res
= SUBMIT_URB(macp
->tx_urb
, GFP_ATOMIC
);
3018 printk("error in tx submit urb: %d", res
);
3019 printk("Clear Tx Busy\n");
3020 clear_bit(ZD1211_TX_BUSY
, &macp
->flags
);
3021 zd1211_DumpErrorCode(macp
, res
);
3027 //set_bit(ZD1211_TX_BUSY, &macp->flags);
3044 void zd1211_disable_net_traffic(struct zd1205_private
*macp
)
3047 // When suspend, call this
3048 if ( (macp
->RF_Mode
== AL2230_RF
) || (macp
->RF_Mode
== AL2230S_RF
) )
3049 HW_Set_IF_Synthesizer(&dot11Obj
, 0x71687);
3051 LockPhyReg(&dot11Obj
);
3052 zd_writel(0xFF, ZD_CR252
);
3053 zd_writel(0xc, ZD_CR253
);
3057 zd_writel(0x3, ZD_CR255
);
3058 UnLockPhyReg(&dot11Obj
);
3061 zd_writel(0x0, BCNInterval
);
3064 zd_writel(0x0, rLED_CTRL
);
3067 zd_writel(0x3, PS_Ctrl
);
3072 dot11Obj
.PhyTest
= 0;
3073 macp
->LinkTimer
= 0;
3080 int zd1211_DownLoadUSBCode(struct zd1205_private
*macp
, u8
* filename
, void *ptr
, u16 uCodeOfst
)
3086 struct stat file_info
;
3088 size_t* file_length
;
3092 //FPRINT("DownLoadUSBCode");
3094 // Open the code file
3096 // for file opening temporarily tell the kernel I am not a user for
3097 // memory management segment access
3103 // open the file with the firmware for uploading
3105 if (ifp
= open(filename
, O_RDONLY
, 0 ), ifp
< 0){
3106 // error opening the file
3107 FPRINT("ERROR: File opening did not success");
3115 /* Get information about the file. */
3116 fstat (ifp
, &file_info
);
3117 file_length
= file_info
.st_size
;
3120 buffer
= kmalloc(file_length
, GFP_ATOMIC
);
3122 /* Read the file into the buffer. */
3123 bcount
= read(ifp
, buffer
, file_length
);
3125 if (bcount
!= file_length
)
3126 FPRINT("read failed");
3136 // switch back the segment setting
3142 ret
= zd1211_LoadUSBSpecCode(macp
, buffer
, file_length
, uCodeOfst
, true);
3156 void ZD1211_WriteMultiRegister(u16
*Address
, u16
*Value
, u16 RegCount
, BOOLEAN AddUSBCSRAddress
)
3162 ret
= zd1211_USB_PACKAGE_WRITE_REGISTER(Address
, Value
, RegCount
, AddUSBCSRAddress
);
3166 printk("ZD1211_WriteMultiRegister failed!!\n");
3171 void ZD1211_WRITE_MULTI_REG(u16
*pAddress
, u16
*pValue
, u16
*pRegCount
)
3173 u16 TotalRegCount
= *pRegCount
;
3174 u16
* pWriteAddr
= pAddress
;
3175 u16
* pWriteData
= pValue
;
3177 if(TotalRegCount
> 256)
3178 printk("Reg Count > 256 !!!!!!!!!!!\n");
3179 while (TotalRegCount
> cMAX_MULTI_WRITE_REG_NUM
)
3181 ZD1211_WriteMultiRegister(pWriteAddr
, pWriteData
, cMAX_MULTI_WRITE_REG_NUM
, true);
3183 TotalRegCount
-= cMAX_MULTI_WRITE_REG_NUM
;
3184 pWriteAddr
+= cMAX_MULTI_WRITE_REG_NUM
;
3185 pWriteData
+= cMAX_MULTI_WRITE_REG_NUM
;
3189 ZD1211_WriteMultiRegister(pWriteAddr
, pWriteData
, TotalRegCount
, true);
3195 int zd1211_GetUSBSpecData(struct zd1205_private
*macp
, u8
*pBuffer
,
3196 u32 uImgLength
, u16 uCodeOfst
)
3202 u32 uploadLength
= uImgLength
;
3205 image
= kmalloc(uImgLength
, GFP_KERNEL
);
3208 while (uImgLength
> 0){
3209 uCurLength
= uImgLength
;
3210 if (uCurLength
> 60)
3213 // Get data from device
3214 result
= usb_control_msg(macp
->usb
, usb_rcvctrlpipe(macp
->usb
, 0),
3215 FIRMWARE_READ_DATA
, USB_DIR_IN
| 0x40, uCodeOfst
, 0,
3216 image
, uCurLength
, 1000 * HZ
);
3218 //ZD1211DEBUG(3, "result = %d\n", result);
3220 printk(KERN_ERR
"zd1211: usb_rcvctrlpipe 1 fail: %02X\n", result
);
3223 else if(uCurLength
!= result
)
3225 printk("control msg sends less. If you see this twice, you get troubles\n");
3231 uImgLength
-= uCurLength
;
3232 image
+= uCurLength
;
3234 uCodeOfst
+= (u16
) (uCurLength
/ 2); // in Word (16 bit)
3239 image
-= uploadLength
; //move to buffer head
3240 memcpy(pBuffer
, image
, uploadLength
);
3249 //return 0: success, others: fail
3250 int zd1211_LoadUSBSpecCode(struct zd1205_private
*macp
, u8
*pBuffer
, u32 uImgLength
, u16 uCodeOfst
, u8 bReboot
)
3256 ZD1211DEBUG(0, "uImgLength = %x\n", uImgLength
);
3257 image
= kmalloc(uImgLength
, GFP_KERNEL
);
3259 memcpy(image
, pBuffer
, uImgLength
);
3262 while (uImgLength
> 0) {
3263 int translen
= (uImgLength
> 4096) ? 4096 : uImgLength
;
3265 ZD1211DEBUG(0, "translen = %x\n", translen
);
3266 ZD1211DEBUG(0, "uCodeOfst = %x\n", uCodeOfst
);
3267 result
= usb_control_msg(macp
->usb
, usb_sndctrlpipe(macp
->usb
, 0),
3268 FIRMWARE_DOWNLOAD
, USB_DIR_OUT
| 0x40, uCodeOfst
, 0,
3269 image
, translen
, HZ
);
3271 ZD1211DEBUG(0, "result = %x\n", result
);
3272 if(result
!= translen
) {
3273 printk("##### Warning! ####\n");
3274 printk("usb_control_msg doesn't send all data out\n");
3275 printk("You need to decrease the message amount in each send\n");
3279 printk(KERN_ERR
"zd1211: usb_control_msg 1 fail: %02X\n", result
);
3283 uImgLength
-= translen
;
3285 uCodeOfst
+= (u16
) (translen
/ 2); // in Word (16 bit)
3290 printk("Finish download Firmware. Ready to reboot \n");
3291 result
= usb_control_msg(macp
->usb
, usb_rcvctrlpipe(macp
->usb
, 0),
3292 FIRMWARE_CONFIRM
, USB_DIR_IN
| 0x40, 0, 0,
3293 &ret
, sizeof(ret
), 1000 * HZ
);
3296 printk(KERN_ERR
"zd1211: usb_control_msg 2 fail: %02X\n", result
);
3305 //ZD1211DEBUG(2, "result = %x\n", result);
3307 ZD1211DEBUG(0, "FIRMWARE_CONFIRM = %x\n", ret
);
3312 FPRINT("USB Download Boot code error");
3317 ZD1211DEBUG(0, "USB Download Boot code success\n");
3331 int zd1211_Download_IncludeFile(struct zd1205_private
*macp
)
3336 //return 0; //for debug
3338 EEPVer
= WS11Ub
[cEPDATA_OFFSET
* 2] + (WS11Ub
[cEPDATA_OFFSET
* 2 + 1] << 8);
3339 printk(KERN_NOTICE
"EEPORM Ver = %x\n", EEPVer
);
3342 if (macp
->release
!= EEPVer
){
3343 ZD1211DEBUG(0, "macp->release != EEPVer\n");
3344 if (macp
->release
<= 0x4312)
3345 ret
= zd1211_LoadUSBSpecCode(macp
, WS11Ur2
, sizeof(WS11Ur2
),
3346 cFIRMWARE_OLD_ADDR
, false);
3348 ret
= zd1211_LoadUSBSpecCode(macp
, WS11Ur
, sizeof(WS11Ur
),
3349 cFIRMWARE_START_ADDR
, true);
3351 FPRINT("Load WS11Ur fail");
3355 ret
= zd1211_LoadUSBSpecCode(macp
, WS11Ub
+ (cEPDATA_OFFSET
* 2) + (E2P_END
- E2P_SUBID
),
3356 sizeof(WS11Ub
) - (cEPDATA_OFFSET
* 2) - (E2P_END
- E2P_SUBID
),
3357 cFIRMWARE_EEPROM_OFFSET
+ (E2P_END
- E2P_SUBID
) / 2,
3361 FPRINT("Load WS11Ub fail");
3366 if (macp
->release
== 0x0101)
3367 ret
= zd1211_GetUSBSpecData(macp
, WS11Ub
+ (cEPDATA_OFFSET
* 2),
3368 (E2P_END
- E2P_SUBID
),
3369 cBOOTCODE_START_ADDR
);
3371 ret
= zd1211_GetUSBSpecData(macp
, WS11Ub
+ (cEPDATA_OFFSET
* 2),
3372 (E2P_END
- E2P_SUBID
),
3373 cFIRMWARE_EEPROM_OFFSET
);
3377 FPRINT("Read EEPROM Data fail");
3382 WS11Ub
[(cEPDATA_OFFSET
* 2) + (E2P_DEVICE_VER
- E2P_SUBID
)] = EEPVer
& 0xFF;
3383 WS11Ub
[(cEPDATA_OFFSET
* 2) + (E2P_DEVICE_VER
- E2P_SUBID
) + 1] = EEPVer
>> 8;
3385 ret
= zd1211_LoadUSBSpecCode(macp
, WS11Ub
,
3386 (E2P_END
- E2P_SUBID
) + (cEPDATA_OFFSET
* 2),
3387 cBOOTCODE_START_ADDR
,
3392 FPRINT("Write EEPROM Data fail");
3399 ret
= zd1211_LoadUSBSpecCode(macp
, WS11UPh
, sizeof(WS11UPh
), cFIRMWARE_START_ADDR
, true);
3403 FPRINT("Load WS11UPh fail\n");
3410 // tasklet (work deferred from completions, in_irq) or timer
3411 void defer_kevent(struct zd1205_private
*macp
, int flag
)
3416 if (!macp
->bUSBDeveiceAttached
)
3420 // if (macp->kevent_flags != 0)
3421 // printk("macp->kevent_flags=%08x\n",macp->kevent_flags);
3422 set_bit(flag
, &macp
->kevent_flags
);
3424 if (flag == KEVENT_SCAN_TIMEOUT)
3426 if(!schedule_work(&macp->scan_tout_event))
3428 ZD1211DEBUG(4, "schedule_task failed, flag = %x\n", flag);
3429 if(!schedule_work(&macp->scan_tout_event)) {
3430 dot11Obj.bChScanning = FALSE;
3432 printk(" Schedule task fail \n");
3441 if (!schedule_work(&macp
->kevent
)){
3442 ZD1211DEBUG(4,"schedule_task failed, flag = %x\n", flag
);
3448 unsigned int smp_kevent_Lock
= 0;
3449 void kevent(void *data
)
3451 struct zd1205_private
*macp
= (struct zd1205_private
*) data
;
3453 if (!macp
->bUSBDeveiceAttached
)
3459 if(test_and_set_bit(0, (void *)&smp_kevent_Lock
))
3461 schedule_work(&macp
->kevent
);
3465 down(&macp
->ioctl_sem
);
3467 /*prince add for dis_update_setting
3468 if (test_bit( KEVENT_DIS_UPDATE_SETTING, &macp->kevent_flags)){
3469 if ( zd1205_dis_update_setting(macp) == 1 )
3471 clear_bit( KEVENT_DIS_UPDATE_SETTING, &macp->kevent_flags);
3475 //prince add for moxa_repeat
3476 if (test_bit( KEVENT_MOXA_REPEAT, &macp->kevent_flags)){
3477 if ( zd1205_moxa_repeat(macp) == 1 )
3479 clear_bit( KEVENT_MOXA_REPEAT, &macp->kevent_flags);
3486 //non tx rx interrupt
3487 if (test_bit(KEVENT_FALL_IN_SLEEP
, &macp
->kevent_flags
)){
3488 //printk("Handling FALL IN SLEEP Kevent\n");
3489 zd1205_sleep_reset(macp
);
3490 clear_bit(KEVENT_FALL_IN_SLEEP
,&macp
->kevent_flags
);
3491 up(&macp
->ioctl_sem
);
3492 clear_bit(0, (void *)&smp_kevent_Lock
);
3493 schedule_work(&macp
->kevent
);
3496 if (test_bit(KEVENT_NON_TX_RX_INT
, &macp
->kevent_flags
)){
3497 //printk("Get Non Tx Rx\n");
3498 zd1211_handle_non_tx_rx(macp
);
3499 clear_bit(KEVENT_NON_TX_RX_INT
, &macp
->kevent_flags
);
3502 if(dot11Obj
.bDeviceInSleep
)
3504 up(&macp
->ioctl_sem
);
3505 clear_bit(0, (void *)&smp_kevent_Lock
);
3506 schedule_work(&macp
->kevent
);
3509 dot11Obj
.AcquireDoNotSleep();
3512 if (test_bit(KEVENT_USB_KILL_TX_URB
, &macp
->kevent_flags
)) {
3513 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,8))
3514 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,14))
3515 macp
->tx_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
3517 printk("We are going to usb_kill_urb @ kevent\n");
3518 usb_kill_urb(macp
->tx_urb
);
3520 printk("Why do you call this ?\n");
3522 clear_bit(KEVENT_USB_KILL_TX_URB
, &macp
->kevent_flags
);
3525 if (test_bit(KEVENT_NON_TX_RX_INT, &macp->kevent_flags)){
3526 zd1211_handle_non_tx_rx(macp);
3527 clear_bit(KEVENT_NON_TX_RX_INT, &macp->kevent_flags);
3532 if (test_bit(KEVENT_SCAN_TIMEOUT
, &macp
->kevent_flags
)){
3534 zd_EventNotify(EVENT_SCAN_TIMEOUT
, 0, 0, 0);
3535 clear_bit(KEVENT_SCAN_TIMEOUT
, &macp
->kevent_flags
);
3539 if (test_bit(KEVENT_MGT_MON_TIMEOUT
, &macp
->kevent_flags
)){
3540 //FPRINT("connect_mon");
3541 zd1205_connect_mon(macp
);
3542 clear_bit(KEVENT_MGT_MON_TIMEOUT
, &macp
->kevent_flags
);
3545 //house keeping timeout
3546 if (test_bit(KEVENT_HOUSE_KEEPING
, &macp
->kevent_flags
)){
3547 zd1205_house_keeping(macp
);
3548 clear_bit(KEVENT_HOUSE_KEEPING
, &macp
->kevent_flags
);
3552 if (test_bit(KEVENT_WATCH_DOG
, &macp
->kevent_flags
)){
3553 zd1205_watchdog(macp
);
3554 clear_bit(KEVENT_WATCH_DOG
, &macp
->kevent_flags
);
3558 if (test_bit(KEVENT_AUTH_TIMEOUT
, &macp
->kevent_flags
)){
3559 zd_EventNotify(EVENT_AUTH_TIMEOUT
, 0, 0, 0);
3560 clear_bit(KEVENT_AUTH_TIMEOUT
, &macp
->kevent_flags
);
3564 if (test_bit(KEVENT_ASOC_TIMEOUT
, &macp
->kevent_flags
)){
3565 zd_EventNotify(EVENT_ASOC_TIMEOUT
, 0, 0, 0);
3566 clear_bit(KEVENT_ASOC_TIMEOUT
, &macp
->kevent_flags
);
3570 if (test_bit(KEVENT_TCHAL_TIMEOUT
, &macp
->kevent_flags
)){
3571 zd_EventNotify(EVENT_TCHAL_TIMEOUT
, 0, 0, 0);
3572 clear_bit(KEVENT_TCHAL_TIMEOUT
, &macp
->kevent_flags
);
3576 if (test_bit(KEVENT_ZD_IOCTL
, &macp
->kevent_flags
)){
3578 zd1205_zd_dbg_ioctl(macp
, &macp
->zdreq
);
3579 clear_bit(KEVENT_ZD_IOCTL
, &macp
->kevent_flags
);
3582 //wpa ioctl handling
3583 if (test_bit(KEVENT_ZD_WPA_IOCTL
, &macp
->kevent_flags
)){
3584 zd1205_wpa_ioctl(macp
, &macp
->zd_wpa_req
);
3585 clear_bit(KEVENT_ZD_WPA_IOCTL
, &macp
->kevent_flags
);
3589 if (test_bit(KEVENT_EN_PROTECTION
, &macp
->kevent_flags
)){
3590 zd_EventNotify(EVENT_ENABLE_PROTECTION
, 1, 0, 0);
3591 clear_bit(KEVENT_EN_PROTECTION
, &macp
->kevent_flags
);
3594 //disable protection
3595 if (test_bit(KEVENT_DIS_PROTECTION
, &macp
->kevent_flags
)){
3596 zd_EventNotify(EVENT_ENABLE_PROTECTION
, 0, 0, 0);
3597 clear_bit(KEVENT_DIS_PROTECTION
, &macp
->kevent_flags
);
3600 //update card setting
3601 if (test_bit(KEVENT_UPDATE_SETTING
, &macp
->kevent_flags
)){
3602 zd_UpdateCardSetting(&macp
->cardSetting
);
3603 clear_bit(KEVENT_UPDATE_SETTING
, &macp
->kevent_flags
);
3607 if (test_bit(KEVENT_SET_MULTICAST
, &macp
->kevent_flags
)){
3608 zd1211_set_multicast(macp
);
3609 clear_bit(KEVENT_SET_MULTICAST
, &macp
->kevent_flags
);
3613 if (test_bit(KEVENT_PROCESS_SIGNAL
, &macp
->kevent_flags
)){
3615 clear_bit(KEVENT_PROCESS_SIGNAL
, &macp
->kevent_flags
);
3618 //enable barker preamble
3619 if (test_bit(KEVENT_EN_BARKER
, &macp
->kevent_flags
)){
3620 zd_EventNotify(EVENT_ENABLE_BARKER
, 1, 0, 0);
3621 clear_bit(KEVENT_EN_BARKER
, &macp
->kevent_flags
);
3624 //disable barker preamble
3625 if (test_bit(KEVENT_DIS_BARKER
, &macp
->kevent_flags
)){
3626 zd_EventNotify(EVENT_ENABLE_BARKER
, 0, 0, 0);
3627 clear_bit(KEVENT_DIS_BARKER
, &macp
->kevent_flags
);
3631 if (test_bit(KEVENT_EN_SHORT_SLOT
, &macp
->kevent_flags
)){
3632 zd_EventNotify(EVENT_SHORT_SLOT
, 1, 0, 0);
3633 clear_bit(KEVENT_EN_SHORT_SLOT
, &macp
->kevent_flags
);
3636 //disable short slot
3637 if (test_bit(KEVENT_DIS_SHORT_SLOT
, &macp
->kevent_flags
)){
3638 zd_EventNotify(EVENT_SHORT_SLOT
, 0, 0, 0);
3639 clear_bit(KEVENT_DIS_SHORT_SLOT
, &macp
->kevent_flags
);
3642 //disable short slot
3643 if (test_bit(KEVENT_DIS_CONNECT
, &macp
->kevent_flags
)){
3644 if (!zd1205_dis_connect(macp
)){
3645 zd_CmdProcess(CMD_DIS_CONNECT
, 0, 0);
3646 macp
->NoBcnDetectedCnt
= 0;
3648 clear_bit(KEVENT_DIS_CONNECT
, &macp
->kevent_flags
);
3652 if (test_bit(KEVENT_STD_IOCTL
, &macp
->kevent_flags
)){
3654 zd1205_ioctl(macp
->device
, &macp
->ifreq
, macp
->ifcmd
);
3655 clear_bit(KEVENT_STD_IOCTL
, &macp
->kevent_flags
);
3658 if (test_bit(KEVENT_REGISTER_NET
, &macp
->kevent_flags
)){
3659 register_netdev(macp
->device
);
3660 clear_bit(KEVENT_REGISTER_NET
, &macp
->kevent_flags
);
3663 //prince add for dis_update_setting
3664 if (test_bit( KEVENT_DIS_UPDATE_SETTING
, &macp
->kevent_flags
)){
3665 if ( zd1205_dis_update_setting(macp
) == 1 )
3667 clear_bit( KEVENT_DIS_UPDATE_SETTING
, &macp
->kevent_flags
);
3671 //prince add for moxa_repeat
3672 if (test_bit( KEVENT_MOXA_REPEAT
, &macp
->kevent_flags
)){
3673 if ( zd1205_moxa_repeat(macp
) == 1 )
3675 clear_bit( KEVENT_MOXA_REPEAT
, &macp
->kevent_flags
);
3679 clear_bit(0, (void *)&smp_kevent_Lock
);
3680 up(&macp
->ioctl_sem
);
3681 dot11Obj
.ReleaseDoNotSleep();
3684 void zd1211_alloc_rx(unsigned long parm
)
3686 struct zd1205_private
*macp
= (struct zd1205_private
*) parm
;
3687 unsigned long flags
;
3689 if(!in_irq())spin_lock_irqsave(&macp
->rx_pool_lock
, flags
);
3690 zd1205_alloc_skbs(macp
);
3691 if(!in_irq())spin_unlock_irqrestore(&macp
->rx_pool_lock
, flags
);