wifi: renew patch drivers/net/wireless
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rtl8723au / hal / rtl8723a / usb / usb_ops_linux.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4  *                                        
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #define _HCI_OPS_OS_C_
21
22 #include <drv_conf.h>
23 #include <osdep_service.h>
24 #include <drv_types.h>
25 #include <osdep_intf.h>
26 #include <usb_ops.h>
27 #include <circ_buf.h>
28 #include <recv_osdep.h>
29 //#include <rtl8192c_hal.h>
30 #include <rtl8723a_hal.h>
31 #include <rtl8723a_recv.h>
32 #if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
33
34 #error "Shall be Linux or Windows, but not both!\n"
35
36 #endif
37
38 static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u8 request, u16 value, u16 index, void *pdata, u16 len, u8 requesttype)
39 {
40         _adapter                *padapter = pintfhdl->padapter ; 
41         struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
42         struct usb_device *udev=pdvobjpriv->pusbdev;
43
44         unsigned int pipe;
45         int status = 0;
46         u32 tmp_buflen=0;
47         u8 reqtype;
48         u8 *pIo_buf;
49         int vendorreq_times = 0;
50
51         #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
52         u8 *tmp_buf;
53         #else // use stack memory
54         u8 tmp_buf[MAX_USB_IO_CTL_SIZE];
55         #endif
56
57 #ifdef CONFIG_CONCURRENT_MODE
58         if(padapter->adapter_type > PRIMARY_ADAPTER)
59         {
60                 padapter = padapter->pbuddy_adapter;
61                 pdvobjpriv = adapter_to_dvobj(padapter);
62                 udev = pdvobjpriv->pusbdev;
63         }
64 #endif
65
66
67         //DBG_871X("%s %s:%d\n",__FUNCTION__, current->comm, current->pid);
68
69         if((padapter->bSurpriseRemoved) ||(dvobj_to_pwrctl(pdvobjpriv)->pnp_bstop_trx)){
70                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usbctrl_vendorreq:(padapter->bSurpriseRemoved ||pwrctl->pnp_bstop_trx)!!!\n"));
71                 status = -EPERM; 
72                 goto exit;
73         }       
74
75         if(len>MAX_VENDOR_REQ_CMD_SIZE){
76                 DBG_8192C( "[%s] Buffer len error ,vendor request failed\n", __FUNCTION__ );
77                 status = -EINVAL;
78                 goto exit;
79         }       
80
81         #ifdef CONFIG_USB_VENDOR_REQ_MUTEX
82         _enter_critical_mutex(&pdvobjpriv->usb_vendor_req_mutex, NULL);
83         #endif
84         
85         
86         // Acquire IO memory for vendorreq
87 #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
88         pIo_buf = pdvobjpriv->usb_vendor_req_buf;
89 #else
90         #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
91         tmp_buf = rtw_malloc( (u32) len + ALIGNMENT_UNIT);
92         tmp_buflen =  (u32)len + ALIGNMENT_UNIT;
93         #else // use stack memory
94         tmp_buflen = MAX_USB_IO_CTL_SIZE;
95         #endif
96
97         // Added by Albert 2010/02/09
98         // For mstar platform, mstar suggests the address for USB IO should be 16 bytes alignment.
99         // Trying to fix it here.
100         pIo_buf = (tmp_buf==NULL)?NULL:tmp_buf + ALIGNMENT_UNIT -((SIZE_PTR)(tmp_buf) & 0x0f ); 
101 #endif
102
103         if ( pIo_buf== NULL) {
104                 DBG_8192C( "[%s] pIo_buf == NULL \n", __FUNCTION__ );
105                 status = -ENOMEM;
106                 goto release_mutex;
107         }
108         
109         while(++vendorreq_times<= MAX_USBCTRL_VENDORREQ_TIMES)
110         {
111                 _rtw_memset(pIo_buf, 0, len);
112                 
113                 if (requesttype == 0x01)
114                 {
115                         pipe = usb_rcvctrlpipe(udev, 0);//read_in
116                         reqtype =  REALTEK_USB_VENQT_READ;              
117                 } 
118                 else 
119                 {
120                         pipe = usb_sndctrlpipe(udev, 0);//write_out
121                         reqtype =  REALTEK_USB_VENQT_WRITE;             
122                         _rtw_memcpy( pIo_buf, pdata, len);
123                 }               
124         
125                 #if 0
126                 //timeout test for firmware downloading
127                 status = rtw_usb_control_msg(udev, pipe, request, reqtype, value, index, pIo_buf, len
128                         , ((value >= FW_8192C_START_ADDRESS && value <= FW_8192C_END_ADDRESS) ||value!=0x1000) ?RTW_USB_CONTROL_MSG_TIMEOUT : RTW_USB_CONTROL_MSG_TIMEOUT_TEST
129                 );
130                 #else
131                 status = rtw_usb_control_msg(udev, pipe, request, reqtype, value, index, pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
132                 #endif
133         
134                 if ( status == len)   // Success this control transfer.
135                 {
136                         rtw_reset_continual_io_error(pdvobjpriv);
137                         if ( requesttype == 0x01 )
138                         {   // For Control read transfer, we have to copy the read data from pIo_buf to pdata.
139                                 _rtw_memcpy( pdata, pIo_buf,  len );
140                         }
141                 }
142                 else { // error cases
143                         DBG_8192C("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n"
144                                 , value,(requesttype == 0x01)?"read":"write" , len, status, *(u32*)pdata, vendorreq_times);
145                         
146                         if (status < 0) {
147                                 if(status == (-ESHUTDOWN)       || status == -ENODEV    )
148                                 {                       
149                                         padapter->bSurpriseRemoved = _TRUE;
150                                 } else {
151                                         #ifdef DBG_CONFIG_ERROR_DETECT
152                                         {
153                                                 HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(padapter);
154                                                 pHalData->srestpriv.Wifi_Error_Status = USB_VEN_REQ_CMD_FAIL;
155                                         }
156                                         #endif
157                                 }
158                         }
159                         else // status != len && status >= 0
160                         {
161                                 if(status > 0) {
162                                         if ( requesttype == 0x01 )
163                                         {   // For Control read transfer, we have to copy the read data from pIo_buf to pdata.
164                                                 _rtw_memcpy( pdata, pIo_buf,  len );
165                                         }
166                                 }
167                         }
168
169                         if(rtw_inc_and_chk_continual_io_error(pdvobjpriv) == _TRUE ){
170                                 padapter->bSurpriseRemoved = _TRUE;
171                                 break;
172                         }
173         
174                 }
175         
176                 // firmware download is checksumed, don't retry
177                 if( (value >= FW_8723A_START_ADDRESS && value <= FW_8723A_END_ADDRESS) || status == len )
178                         break;
179         
180         }
181         
182         // release IO memory used by vendorreq
183         #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
184         rtw_mfree(tmp_buf, tmp_buflen);
185         #endif
186
187 release_mutex:
188         #ifdef CONFIG_USB_VENDOR_REQ_MUTEX
189         _exit_critical_mutex(&pdvobjpriv->usb_vendor_req_mutex, NULL);
190         #endif
191 exit:
192         return status;
193
194 }
195
196 static u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr)
197 {
198         u8 request;
199         u8 requesttype;
200         u16 wvalue;
201         u16 index;
202         u16 len;
203         u8 data=0;
204         
205         _func_enter_;
206
207         request = 0x05;
208         requesttype = 0x01;//read_in
209         index = 0;//n/a
210
211         wvalue = (u16)(addr&0x0000ffff);
212         len = 1;        
213         
214         usbctrl_vendorreq(pintfhdl, request, wvalue, index, &data, len, requesttype);
215
216         _func_exit_;
217
218         return data;
219                 
220 }
221
222 static u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr)
223 {       
224         u8 request;
225         u8 requesttype;
226         u16 wvalue;
227         u16 index;
228         u16 len;
229         u16 data=0;
230         
231         _func_enter_;
232
233         request = 0x05;
234         requesttype = 0x01;//read_in
235         index = 0;//n/a
236
237         wvalue = (u16)(addr&0x0000ffff);
238         len = 2;        
239         
240         usbctrl_vendorreq(pintfhdl, request, wvalue, index, &data, len, requesttype);
241
242         _func_exit_;
243
244         return data;
245         
246 }
247
248 static u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr)
249 {
250         u8 request;
251         u8 requesttype;
252         u16 wvalue;
253         u16 index;
254         u16 len;
255         u32 data=0;
256         
257         _func_enter_;
258
259         request = 0x05;
260         requesttype = 0x01;//read_in
261         index = 0;//n/a
262
263         wvalue = (u16)(addr&0x0000ffff);
264         len = 4;        
265         
266         usbctrl_vendorreq(pintfhdl, request, wvalue, index, &data, len, requesttype);
267
268         _func_exit_;
269
270         return data;
271         
272 }
273
274 static int usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
275 {
276         u8 request;
277         u8 requesttype;
278         u16 wvalue;
279         u16 index;
280         u16 len;
281         u8 data;
282         int ret;
283         
284         _func_enter_;
285
286         request = 0x05;
287         requesttype = 0x00;//write_out
288         index = 0;//n/a
289
290         wvalue = (u16)(addr&0x0000ffff);
291         len = 1;
292         
293         data = val;     
294         
295          ret = usbctrl_vendorreq(pintfhdl, request, wvalue, index, &data, len, requesttype);
296         
297         _func_exit_;
298         
299         return ret;
300         
301 }
302
303 static int usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
304 {       
305         u8 request;
306         u8 requesttype;
307         u16 wvalue;
308         u16 index;
309         u16 len;
310         u16 data;
311         int ret;
312         
313         _func_enter_;
314
315         request = 0x05;
316         requesttype = 0x00;//write_out
317         index = 0;//n/a
318
319         wvalue = (u16)(addr&0x0000ffff);
320         len = 2;
321         
322         data = val;
323                 
324         ret = usbctrl_vendorreq(pintfhdl, request, wvalue, index, &data, len, requesttype);
325         
326         _func_exit_;
327         
328         return ret;
329         
330 }
331
332 static int usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
333 {
334         u8 request;
335         u8 requesttype;
336         u16 wvalue;
337         u16 index;
338         u16 len;
339         u32 data;
340         int ret;
341         
342         _func_enter_;
343
344         request = 0x05;
345         requesttype = 0x00;//write_out
346         index = 0;//n/a
347
348         wvalue = (u16)(addr&0x0000ffff);
349         len = 4;
350         data = val;     
351         
352
353         ret =usbctrl_vendorreq(pintfhdl, request, wvalue, index, &data, len, requesttype);
354         
355         _func_exit_;
356         
357         return ret;
358         
359 }
360
361 static int usb_writeN(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata)
362 {
363         u8 request;
364         u8 requesttype;
365         u16 wvalue;
366         u16 index;
367         u16 len;
368         u8 buf[VENDOR_CMD_MAX_DATA_LEN]={0};
369         int ret;
370         
371         _func_enter_;
372
373         request = 0x05;
374         requesttype = 0x00;//write_out
375         index = 0;//n/a
376
377         wvalue = (u16)(addr&0x0000ffff);
378         len = length;
379          _rtw_memcpy(buf, pdata, len );
380         
381         ret = usbctrl_vendorreq(pintfhdl, request, wvalue, index, buf, len, requesttype);
382         
383         _func_exit_;
384         
385         return ret;
386         
387 }
388
389 #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
390 #if 0
391 /**
392 * Log the Interrupt value and update counter no matter STA is associated or not. It is 
393 * implemented for FPGA verification stage because we need to now whether the current FPGA 
394 * platform is alive
395 *
396 * \param pAdapter                       The adapter context for this minoport
397 * \param        IsrContent              The ISR value read from hardware in MPISR
398 *
399 * We sholud remove this function later because DDK suggest not to executing too many 
400 * operations in MPISR
401 */
402 VOID
403 LogInterruptHistory8723AU(
404         PADAPTER                        Adapter 
405 )
406 {
407         HAL_DATA_TYPE   *pHalData=GET_HAL_DATA(Adapter);
408
409 //      if(pHalData->IntArray[0] & IMR_COMDOK)
410 //              pHalData->InterruptLog.nIMR_COMDOK++;
411         if(pHalData->IntArray[0] & UHIMR_VODOK) 
412         {
413                 pHalData->InterruptLog.nIMR_VODOK++;
414                 DBG_8192C("UHIMR_VODOK %d \n", pHalData->InterruptLog.nIMR_VODOK);
415         }
416         if(pHalData->IntArray[0] & UHIMR_VIDOK) 
417         {
418                 pHalData->InterruptLog.nIMR_VIDOK++;
419                 DBG_8192C("UHIMR_VIDOK %d\n", pHalData->InterruptLog.nIMR_VIDOK);               
420         }
421         if(pHalData->IntArray[0] & UHIMR_MGNTDOK) 
422         {
423                 pHalData->InterruptLog.nIMR_MGNTDOK++;  
424                 DBG_8192C("UHIMR_MGNTDOK %d\n", pHalData->InterruptLog.nIMR_MGNTDOK);                           
425         }
426         if(pHalData->IntArray[0] & UHIMR_BEDOK) 
427         {
428                 pHalData->InterruptLog.nIMR_BEDOK++;
429                 DBG_8192C("UHIMR_BEDOK %d\n", pHalData->InterruptLog.nIMR_BEDOK);                               
430         }
431         if(pHalData->IntArray[0] & UHIMR_BKDOK) 
432         {
433                 pHalData->InterruptLog.nIMR_BKDOK++;
434                 DBG_8192C("UHIMR_BKDOK %d\n", pHalData->InterruptLog.nIMR_BKDOK);                               
435         }
436         if(pHalData->IntArray[0] & UHIMR_ROK)
437         {
438                 pHalData->InterruptLog.nIMR_ROK++;
439                 DBG_8192C("UHIMR_ROK %d\n", pHalData->InterruptLog.nIMR_ROK);                           
440         }
441
442         if(pHalData->IntArray[0] & UHIMR_TXBCNOK) 
443         {
444                 pHalData->InterruptLog.nIMR_TBDOK++;
445                 DBG_8192C("UHIMR_TXBCNOK %d\n", pHalData->InterruptLog.nIMR_TBDOK);                             
446         }
447         if(pHalData->IntArray[0] & UHIMR_BCNDOK0) 
448         {
449                 pHalData->InterruptLog.nIMR_BDOK++;
450                 DBG_8192C("UHIMR_BCNDOK0 %d\n", pHalData->InterruptLog.nIMR_BDOK);                              
451         }
452         if(pHalData->IntArray[0] & UHIMR_C2HCMD) 
453         {
454                 pHalData->InterruptLog.nIMR_C2HCMD++;
455                 DBG_8192C("UHIMR_C2HCMD %d\n", pHalData->InterruptLog.nIMR_C2HCMD);                                             
456         }
457         if(pHalData->IntArray[0] & UHIMR_CPWM) 
458         {
459                 pHalData->InterruptLog.nIMR_C2HCMD++;
460                 DBG_8192C("UHIMR_CPWM %d\n", pHalData->InterruptLog.nIMR_CPWM);                                         
461         }
462
463 //      if(pHalData->IntArray[0] & IMR_RXCMDOK)
464 //              pHalData->InterruptLog.nIMR_RCOK++;
465         if(pHalData->IntArray[0] & UHIMR_RDU)
466         {
467                 pHalData->InterruptLog.nIMR_RDU++;
468                 DBG_8192C("UHIMR_RDU %d\n", pHalData->InterruptLog.nIMR_RDU);                                           
469         }
470
471         if(pHalData->IntArray[1] & UHIMR_RXFOVW)
472         {
473                 pHalData->InterruptLog.nIMR_RXFOVW++;
474                 DBG_8192C("UHIMR_RXFOVW %d\n", pHalData->InterruptLog.nIMR_RXFOVW);                                             
475         }
476
477
478 }
479 #endif
480 //
481 // Description:
482 //      Recognize the interrupt content by reading the interrupt register or content and masking interrupt mask (IMR)
483 //      if it is our NIC's interrupt. After recognizing, we may clear the all interrupts (ISR).
484 // Arguments:
485 //      [in] Adapter -
486 //              The adapter context.
487 //      [in] pContent -
488 //              Under PCI interface, this field is ignord.
489 //              Under USB interface, the content is the interrupt content pointer.
490 //              Under SDIO interface, this is the interrupt type which is Local interrupt or system interrupt.
491 //      [in] ContentLen -
492 //              The length in byte of pContent.
493 // Return:
494 //      If any interrupt matches the mask (IMR), return TRUE, and return FALSE otherwise.
495 //
496 BOOLEAN
497 InterruptRecognized8723AU(
498         IN      PADAPTER                        Adapter,
499         IN      PVOID                           pContent,
500         IN      u32                             ContentLen
501 )
502 {
503         HAL_DATA_TYPE   *pHalData=GET_HAL_DATA(Adapter);
504         u8 *                    buffer = (u8 *)pContent;
505 //      RT_PRINT_DATA(COMP_RECV, DBG_LOUD, ("InterruptRecognized8723AU Interrupt buffer \n"), buffer, MAX_RECEIVE_INTERRUPT_BUFFER_SIZE(Adapter));
506
507         _rtw_memcpy(&(pHalData->IntArray[0]), &(buffer[USB_INTR_CONTENT_HISR_OFFSET]), 4);
508 //      PlatformMoveMemory(&(pHalData->IntArray[0]), &(buffer[USB_INTR_CONTENT_HISR_OFFSET]), sizeof(u4Byte));
509 //      DBG_8192C("InterruptRecognized8723AU HISR = 0x%x HIMR = 0x%x\n", pHalData->IntArray[0],pHalData->IntrMask[0]);  
510         pHalData->IntArray[0] &= pHalData->IntrMask[0];
511
512         //For HISR extension. Added by tynli. 2009.10.07.
513         _rtw_memcpy(&(pHalData->IntArray[1]), &(buffer[USB_INTR_CONTENT_HISRE_OFFSET]), 4);
514 //      PlatformMoveMemory(&(pHalData->IntArray[1]), &(buffer[USB_INTR_CONTENT_HISRE_OFFSET]), sizeof(u4Byte)); 
515 //      DBG_8192C("InterruptRecognized8192CUsb HISRE = 0x%x HIMRE = 0x%x\n", pHalData->IntArray[1], pHalData->IntrMask[1]); 
516         pHalData->IntArray[1] &= pHalData->IntrMask[1]; 
517
518         // We sholud remove this function later because DDK suggest not to executing too many operations in MPISR
519 //      if(pHalData->IntArray[0] != 0)
520 //              LogInterruptHistory8723AU(Adapter);
521
522         {
523                 struct reportpwrstate_parm report;
524                 _rtw_memcpy(&report.state, &(buffer[USB_INTR_CPWM_OFFSET]), 1);
525 #ifdef CONFIG_LPS_LCLK
526                 if( ((pHalData->IntArray[0])&UHIMR_CPWM)){
527 //                      DBG_8192C("%s HIMR=0x%x\n",__func__,pHalData->IntArray[0]);
528                         //cpwm_int_hdl(Adapter, &report);
529                         _set_workitem(&(adapter_to_pwrctl(Adapter)->cpwm_event));
530                         pHalData->IntArray[0]&= ~UHIMR_CPWM;
531 //                      DBG_8192C("%s HIMR=0x%x\n",__func__,pHalData->IntArray[0]);
532                 }
533 #endif
534         }
535         return (((pHalData->IntArray[0])&pHalData->IntrMask[0])!=0 || 
536                 ((pHalData->IntArray[1])&pHalData->IntrMask[1])!=0);
537
538 }
539
540
541 static void usb_read_interrupt_complete(struct urb *purb, struct pt_regs *regs)
542 {
543         int     err;
544         PADAPTER padapter = (PADAPTER)purb->context;
545
546         
547         if(padapter->bSurpriseRemoved || padapter->bDriverStopped||padapter->bReadPortCancel)
548         {
549                 DBG_8192C("%s() RX Warning! bDriverStopped(%d) OR bSurpriseRemoved(%d) bReadPortCancel(%d)\n", 
550                 __FUNCTION__,padapter->bDriverStopped, padapter->bSurpriseRemoved,padapter->bReadPortCancel);
551                 return;
552         }
553
554         if (purb->status == 0)//SUCCESS
555         {
556                 struct c2h_evt_hdr *c2h_evt = (struct c2h_evt_hdr *)purb->transfer_buffer;
557
558                 if (purb->actual_length > USB_INTR_CONTENT_LENGTH) {
559                         DBG_8192C("usb_read_interrupt_complete: purb->actual_length > USB_INTR_CONTENT_LENGTH\n");
560                         goto urb_submit;
561                 }
562
563                 InterruptRecognized8723AU(padapter, purb->transfer_buffer, purb->actual_length);
564
565                 if (c2h_evt_exist(c2h_evt)) {
566                         if (0)
567                                 DBG_871X("%s C2H == %d\n", __func__, c2h_evt->id);
568                         if (c2h_id_filter_ccx_8723a(c2h_evt->id)) {
569                                 /* Handle CCX report here */
570                                 handle_txrpt_ccx_8723a(padapter, (void *)(c2h_evt->payload));
571                                 /* Replace with special pointer to trigger c2h_evt_clear */
572                                 if (rtw_cbuf_push(padapter->evtpriv.c2h_queue, (void*)&padapter->evtpriv) != _SUCCESS)
573                                         DBG_871X("%s rtw_cbuf_push fail\n", __func__);
574                                 _set_workitem(&padapter->evtpriv.c2h_wk);
575                         } else if ((c2h_evt = (struct c2h_evt_hdr *)rtw_malloc(16)) != NULL) {
576                                 _rtw_memcpy(c2h_evt, purb->transfer_buffer, 16);
577                                 if (rtw_cbuf_push(padapter->evtpriv.c2h_queue, (void*)c2h_evt) != _SUCCESS)
578                                         DBG_871X("%s rtw_cbuf_push fail\n", __func__);
579                                 _set_workitem(&padapter->evtpriv.c2h_wk);
580                         } else {
581                                 /* Error handling for malloc fail */
582                                 if (rtw_cbuf_push(padapter->evtpriv.c2h_queue, (void*)NULL) != _SUCCESS)
583                                         DBG_871X("%s rtw_cbuf_push fail\n", __func__);
584                                 _set_workitem(&padapter->evtpriv.c2h_wk);
585                         }
586                 }
587
588 urb_submit:
589                 err = usb_submit_urb(purb, GFP_ATOMIC);
590                 if ((err) && (err != (-EPERM)))
591                 {
592                         DBG_8192C("cannot submit interrupt in-token(err = 0x%08x),urb_status = %d\n",err, purb->status);
593                 }
594         }
595         else
596         {
597                 DBG_8192C("###=> usb_read_interrupt_complete => urb status(%d)\n", purb->status);
598
599                 switch (purb->status)
600                 {
601                         case -EINVAL:
602                         case -EPIPE:
603                         case -ENODEV:
604                         case -ESHUTDOWN:
605                                 //padapter->bSurpriseRemoved = _TRUE;
606                                 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("usb_read_port_complete:bSurpriseRemoved=TRUE\n"));
607                         case -ENOENT:
608                                 padapter->bDriverStopped = _TRUE;
609                                 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("usb_read_port_complete:bDriverStopped=TRUE\n"));
610                                 break;
611                         case -EPROTO:
612                                 break;
613                         case -EINPROGRESS:
614                                 DBG_8192C("ERROR: URB IS IN PROGRESS!/n");
615                                 break;
616                         default:
617                                 break;
618                 }
619         }
620 }
621
622 static u32 usb_read_interrupt(struct intf_hdl *pintfhdl, u32 addr)
623 {
624         int     err;
625         unsigned int pipe;
626         u32     ret = _SUCCESS;
627         _adapter                        *adapter = pintfhdl->padapter;
628         struct dvobj_priv       *pdvobj = adapter_to_dvobj(adapter);
629         struct recv_priv        *precvpriv = &adapter->recvpriv;
630         struct usb_device       *pusbd = pdvobj->pusbdev;
631
632 _func_enter_;
633
634         //translate DMA FIFO addr to pipehandle
635         pipe = ffaddr2pipehdl(pdvobj, addr);
636
637         usb_fill_int_urb(precvpriv->int_in_urb, pusbd, pipe, 
638                                         precvpriv->int_in_buf,
639                                         USB_INTR_CONTENT_LENGTH,
640                                         usb_read_interrupt_complete,
641                                         adapter,
642                                         1);
643
644         err = usb_submit_urb(precvpriv->int_in_urb, GFP_ATOMIC);
645         if((err) && (err != (-EPERM)))
646         {
647                 DBG_8192C("cannot submit interrupt in-token(err = 0x%08x),urb_status = %d\n",err, precvpriv->int_in_urb->status);
648                 ret = _FAIL;
649         }
650
651 _func_exit_;
652
653         return ret;
654 }
655 #endif
656
657 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
658 static int recvbuf2recvframe(_adapter *padapter, struct recv_buf *precvbuf)
659 {
660         u8      *pbuf;
661         u8      shift_sz = 0;
662         u16     pkt_cnt, drvinfo_sz;
663         u32     pkt_offset, skb_len, alloc_sz;
664         s32     transfer_len;
665         struct recv_stat        *prxstat;
666         struct phy_stat *pphy_info = NULL;
667         _pkt                            *pkt_copy = NULL;
668         union recv_frame        *precvframe = NULL;
669         struct rx_pkt_attrib    *pattrib = NULL;
670         HAL_DATA_TYPE           *pHalData = GET_HAL_DATA(padapter);
671         struct recv_priv        *precvpriv = &padapter->recvpriv;
672         _queue                  *pfree_recv_queue = &precvpriv->free_recv_queue;
673
674
675         transfer_len = (s32)precvbuf->transfer_len;     
676         pbuf = precvbuf->pbuf;
677
678         prxstat = (struct recv_stat *)pbuf;     
679         pkt_cnt = (le32_to_cpu(prxstat->rxdw2)>>16) & 0xff;
680         
681 #if 0 //temp remove when disable usb rx aggregation
682         if((pkt_cnt > 10) || (pkt_cnt < 1) || (transfer_len<RXDESC_SIZE) ||(pkt_len<=0))
683         {               
684                 return _FAIL;
685         }
686 #endif
687         
688         do{             
689                 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
690                          ("recvbuf2recvframe: rxdesc=offsset 0:0x%08x, 4:0x%08x, 8:0x%08x, C:0x%08x\n",
691                           prxstat->rxdw0, prxstat->rxdw1, prxstat->rxdw2, prxstat->rxdw4));
692
693                 prxstat = (struct recv_stat *)pbuf;
694
695                 precvframe = rtw_alloc_recvframe(pfree_recv_queue);
696                 if(precvframe==NULL)
697                 {
698                         RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recvbuf2recvframe: precvframe==NULL\n"));
699                         DBG_8192C("%s()-%d: rtw_alloc_recvframe() failed! RX Drop!\n", __FUNCTION__, __LINE__); 
700                         goto _exit_recvbuf2recvframe;
701                 }
702
703                 _rtw_init_listhead(&precvframe->u.hdr.list);    
704                 precvframe->u.hdr.precvbuf = NULL;      //can't access the precvbuf for new arch.
705                 precvframe->u.hdr.len=0;
706
707 //              rtl8192c_query_rx_desc_status(precvframe, prxstat);
708                 update_recvframe_attrib(precvframe, prxstat);
709
710                 pattrib = &precvframe->u.hdr.attrib;
711                 
712                 if(padapter->registrypriv.mp_mode == 0) && (pattrib->crc_err)){
713                         DBG_8192C("%s()-%d: RX Warning! rx CRC ERROR !!\n", __FUNCTION__, __LINE__);    
714                         rtw_free_recvframe(precvframe, pfree_recv_queue);
715                         goto _exit_recvbuf2recvframe;
716                 }                       
717
718                 pkt_offset = RXDESC_SIZE + pattrib->drvinfo_sz + pattrib->shift_sz + pattrib->pkt_len;
719
720                 if((pattrib->pkt_len<=0) || (pkt_offset>transfer_len))
721                 {       
722                         RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("recvbuf2recvframe: pkt_len<=0\n"));
723                         DBG_8192C("%s()-%d: RX Warning!\n", __FUNCTION__, __LINE__);    
724                         rtw_free_recvframe(precvframe, pfree_recv_queue);
725                         goto _exit_recvbuf2recvframe;
726                 }
727
728                 //      Modified by Albert 20101213
729                 //      For 8 bytes IP header alignment.
730                 if (pattrib->qos)       //      Qos data, wireless lan header length is 26
731                 {
732                         shift_sz = 6;
733                 }
734                 else
735                 {
736                         shift_sz = 0;
737                 }
738
739                 skb_len = pattrib->pkt_len;
740
741                 // for first fragment packet, driver need allocate 1536+drvinfo_sz+RXDESC_SIZE to defrag packet.
742                 // modify alloc_sz for recvive crc error packet by thomas 2011-06-02
743                 if((pattrib->mfrag == 1)&&(pattrib->frag_num == 0)){
744                         //alloc_sz = 1664;      //1664 is 128 alignment.
745                         if(skb_len <= 1650)
746                                 alloc_sz = 1664;
747                         else
748                                 alloc_sz = skb_len + 14;
749                 }
750                 else {
751                         alloc_sz = skb_len;
752                         //      6 is for IP header 8 bytes alignment in QoS packet case.
753                         //      8 is for skb->data 4 bytes alignment.
754                         alloc_sz += 14;
755                 }
756
757                 pkt_copy = rtw_skb_alloc(alloc_sz);
758
759                 if(pkt_copy)
760                 {
761                         pkt_copy->dev = padapter->pnetdev;
762                         precvframe->u.hdr.pkt = pkt_copy;
763                         precvframe->u.hdr.rx_head = pkt_copy->data;
764                         precvframe->u.hdr.rx_end = pkt_copy->data + alloc_sz;
765                         skb_reserve( pkt_copy, 8 - ((SIZE_PTR)( pkt_copy->data ) & 7 ));//force pkt_copy->data at 8-byte alignment address
766                         skb_reserve( pkt_copy, shift_sz );//force ip_hdr at 8-byte alignment address according to shift_sz.
767                         _rtw_memcpy(pkt_copy->data, (pbuf + pattrib->shift_sz + pattrib->drvinfo_sz + RXDESC_SIZE), skb_len);
768                         precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail = pkt_copy->data;
769                 }
770                 else
771                 {
772                         DBG_8192C("recvbuf2recvframe:can not allocate memory for skb copy\n");
773                         //precvframe->u.hdr.pkt = rtw_skb_clone(pskb);
774                         //precvframe->u.hdr.rx_head = precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail = pbuf;
775                         //precvframe->u.hdr.rx_end = pbuf + (pkt_offset>1612?pkt_offset:1612);
776
777                         precvframe->u.hdr.pkt = NULL;
778                         rtw_free_recvframe(precvframe, pfree_recv_queue);
779
780                         goto _exit_recvbuf2recvframe;
781                 }
782
783                 recvframe_put(precvframe, skb_len);
784                 //recvframe_pull(precvframe, drvinfo_sz + RXDESC_SIZE); 
785
786                 if (pattrib->physt)
787                 {
788                         pphy_info = (struct phy_stat*)(pbuf + RXDESC_OFFSET);
789                         update_recvframe_phyinfo(precvframe, pphy_info);
790                 }
791
792 #ifdef CONFIG_USB_RX_AGGREGATION
793                 switch(pHalData->UsbRxAggMode)
794                 {
795                         case USB_RX_AGG_DMA:
796                         case USB_RX_AGG_MIX:
797                                 pkt_offset = (u16)_RND128(pkt_offset);
798                                 break;
799                                 case USB_RX_AGG_USB:
800                                 pkt_offset = (u16)_RND4(pkt_offset);
801                                 break;
802                         case USB_RX_AGG_DISABLE:                        
803                         default:                                
804                                 break;
805                 }
806 #endif
807
808                 if(rtw_recv_entry(precvframe) != _SUCCESS)
809                 {
810                         RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recvbuf2recvframe: rtw_recv_entry(precvframe) != _SUCCESS\n"));
811                 }
812
813                 pkt_cnt--;
814                 transfer_len -= pkt_offset;
815                 pbuf += pkt_offset;     
816                 precvframe = NULL;
817                 pkt_copy = NULL;
818
819                 if(transfer_len>0 && pkt_cnt==0)
820                         pkt_cnt = (le32_to_cpu(prxstat->rxdw2)>>16) & 0xff;
821
822         }while((transfer_len>0) && (pkt_cnt>0));
823
824 _exit_recvbuf2recvframe:
825
826         return _SUCCESS;
827 }
828
829 void rtl8192cu_recv_tasklet(void *priv)
830 {       
831         struct recv_buf *precvbuf = NULL;
832         _adapter        *padapter = (_adapter*)priv;
833         struct recv_priv        *precvpriv = &padapter->recvpriv;
834
835         while (NULL != (precvbuf = rtw_dequeue_recvbuf(&precvpriv->recv_buf_pending_queue)))
836         {
837                 if ((padapter->bDriverStopped == _TRUE)||(padapter->bSurpriseRemoved== _TRUE))
838                 {
839                         DBG_8192C("recv_tasklet => bDriverStopped or bSurpriseRemoved \n");
840                         
841                         break;
842                 }
843                 
844
845                 recvbuf2recvframe(padapter, precvbuf);
846
847                 rtw_read_port(padapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf);
848         }       
849         
850 }
851
852 static void usb_read_port_complete(struct urb *purb, struct pt_regs *regs)
853 {       
854         struct recv_buf *precvbuf = (struct recv_buf *)purb->context;   
855         _adapter                        *padapter =(_adapter *)precvbuf->adapter;
856         struct recv_priv        *precvpriv = &padapter->recvpriv;
857
858         RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete!!!\n"));
859         
860         precvpriv->rx_pending_cnt --;
861                 
862         if(padapter->bSurpriseRemoved || padapter->bDriverStopped||padapter->bReadPortCancel)
863         {
864                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete:bDriverStopped(%d) OR bSurpriseRemoved(%d)\n", padapter->bDriverStopped, padapter->bSurpriseRemoved));                
865
866                 goto exit;
867         }
868
869         if(purb->status==0)//SUCCESS
870         {
871                 if ((purb->actual_length > MAX_RECVBUF_SZ) || (purb->actual_length < RXDESC_SIZE))
872                 {
873                         RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete: (purb->actual_length > MAX_RECVBUF_SZ) || (purb->actual_length < RXDESC_SIZE)\n"));
874
875                         rtw_read_port(padapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf);
876                 }
877                 else 
878                 {                       
879                         rtw_reset_continual_io_error(adapter_to_dvobj(padapter));
880                         
881                         precvbuf->transfer_len = purb->actual_length;   
882
883                         //rtw_enqueue_rx_transfer_buffer(precvpriv, rx_transfer_buf);                   
884                         rtw_enqueue_recvbuf(precvbuf, &precvpriv->recv_buf_pending_queue);
885
886                         tasklet_schedule(&precvpriv->recv_tasklet);                     
887                 }               
888         }
889         else
890         {
891                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete : purb->status(%d) != 0 \n", purb->status));
892         
893                 DBG_8192C("###=> usb_read_port_complete => urb status(%d)\n", purb->status);
894
895                 if(rtw_inc_and_chk_continual_io_error(adapter_to_dvobj(padapter)) == _TRUE ){
896                         padapter->bSurpriseRemoved = _TRUE;
897                 }
898
899                 switch(purb->status) {
900                         case -EINVAL:
901                         case -EPIPE:                    
902                         case -ENODEV:
903                         case -ESHUTDOWN:
904                                 //padapter->bSurpriseRemoved=_TRUE;
905                                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete:bSurpriseRemoved=TRUE\n"));
906                         case -ENOENT:
907                                 padapter->bDriverStopped=_TRUE;                 
908                                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete:bDriverStopped=TRUE\n"));
909                                 break;
910                         case -EPROTO:
911                         case -EILSEQ:
912                         case -ETIME:
913                         case -ECOMM:
914                         case -EOVERFLOW:
915                                 #ifdef DBG_CONFIG_ERROR_DETECT  
916                                 {       
917                                         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(padapter);
918                                         pHalData->srestpriv.Wifi_Error_Status = USB_READ_PORT_FAIL;                     
919                                 }
920                                 #endif
921                                 rtw_read_port(padapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf);                    
922                                 break;
923                         case -EINPROGRESS:
924                                 DBG_8192C("ERROR: URB IS IN PROGRESS!/n");
925                                 break;
926                         default:
927                                 break;                          
928                 }
929                 
930         }       
931
932 exit:   
933         
934 _func_exit_;
935         
936 }
937
938 static u32 usb_read_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem)
939 {               
940         int err;
941         unsigned int pipe;
942         u32 ret = _SUCCESS;
943         PURB purb = NULL;       
944         struct recv_buf *precvbuf = (struct recv_buf *)rmem;
945         _adapter                *adapter = pintfhdl->padapter;
946         struct dvobj_priv       *pdvobj = adapter_to_dvobj(adapter);
947         struct recv_priv        *precvpriv = &adapter->recvpriv;
948         struct usb_device       *pusbd = pdvobj->pusbdev;
949
950 _func_enter_;
951         
952         if(adapter->bDriverStopped || adapter->bSurpriseRemoved ||dvobj_to_pwrctl(pdvobj)->pnp_bstop_trx)
953         {
954                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port:( padapter->bDriverStopped ||padapter->bSurpriseRemoved ||pwrctl->pnp_bstop_trx)!!!\n"));
955                 return _FAIL;
956         }
957
958         if(precvbuf !=NULL)
959         {       
960                 rtl8192cu_init_recvbuf(adapter, precvbuf);
961
962                 if(precvbuf->pbuf)
963                 {                       
964                         precvpriv->rx_pending_cnt++;
965                 
966                         purb = precvbuf->purb;          
967
968                         //translate DMA FIFO addr to pipehandle
969                         pipe = ffaddr2pipehdl(pdvobj, addr);    
970
971                         usb_fill_bulk_urb(purb, pusbd, pipe, 
972                                                 precvbuf->pbuf,
973                                                 MAX_RECVBUF_SZ,
974                                                 usb_read_port_complete,
975                                                 precvbuf);//context is precvbuf
976
977                         purb->transfer_dma = precvbuf->dma_transfer_addr;
978                         purb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;                                                                
979
980                         err = usb_submit_urb(purb, GFP_ATOMIC); 
981                         if((err) && (err != (-EPERM)))
982                         {
983                                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("cannot submit rx in-token(err=0x%.8x), URB_STATUS =0x%.8x", err, purb->status));
984                                 DBG_8192C("cannot submit rx in-token(err = 0x%08x),urb_status = %d\n",err,purb->status);
985                                 ret = _FAIL;
986                         }
987                         
988                 }
989                         
990         }
991         else
992         {
993                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port:precvbuf ==NULL\n"));
994                 ret = _FAIL;
995         }
996
997 _func_exit_;
998
999         return ret;
1000 }
1001 #else   // CONFIG_USE_USB_BUFFER_ALLOC_RX
1002 static s32 pre_recv_entry(union recv_frame *precvframe, struct recv_stat *prxstat, struct phy_stat *pphy_info)
1003 {       
1004         s32 ret=_SUCCESS;
1005 #ifdef CONFIG_CONCURRENT_MODE   
1006         u8 *primary_myid, *secondary_myid, *paddr1;
1007         union recv_frame        *precvframe_if2 = NULL;
1008         _adapter *primary_padapter = precvframe->u.hdr.adapter;
1009         _adapter *secondary_padapter = primary_padapter->pbuddy_adapter;
1010         struct recv_priv *precvpriv = &primary_padapter->recvpriv;
1011         _queue *pfree_recv_queue = &precvpriv->free_recv_queue;
1012         u8      *pbuf = precvframe->u.hdr.rx_data;
1013         
1014         if(!secondary_padapter)
1015                 return ret;
1016         
1017         paddr1 = GetAddr1Ptr(precvframe->u.hdr.rx_data);                
1018
1019         if(IS_MCAST(paddr1) == _FALSE)//unicast packets
1020         {
1021                 //primary_myid = myid(&primary_padapter->eeprompriv);
1022                 secondary_myid = myid(&secondary_padapter->eeprompriv);
1023
1024                 if(_rtw_memcmp(paddr1, secondary_myid, ETH_ALEN))
1025                 {                       
1026                         //change to secondary interface
1027                         precvframe->u.hdr.adapter = secondary_padapter;
1028                 }       
1029
1030                 //ret = recv_entry(precvframe);
1031
1032         }
1033         else // Handle BC/MC Packets    
1034         {
1035                 
1036                 u8 clone = _TRUE;
1037 #if 0           
1038                 u8 type, subtype, *paddr2, *paddr3;
1039         
1040                 type =  GetFrameType(pbuf);
1041                 subtype = GetFrameSubType(pbuf); //bit(7)~bit(2)
1042                 
1043                 switch (type)
1044                 {
1045                         case WIFI_MGT_TYPE: //Handle BC/MC mgnt Packets
1046                                 if(subtype == WIFI_BEACON)
1047                                 {
1048                                         paddr3 = GetAddr3Ptr(precvframe->u.hdr.rx_data);
1049                                 
1050                                         if (check_fwstate(&secondary_padapter->mlmepriv, _FW_LINKED) &&
1051                                                 _rtw_memcmp(paddr3, get_bssid(&secondary_padapter->mlmepriv), ETH_ALEN))
1052                                         {
1053                                                 //change to secondary interface
1054                                                 precvframe->u.hdr.adapter = secondary_padapter;
1055                                                 clone = _FALSE;
1056                                         }
1057
1058                                         if(check_fwstate(&primary_padapter->mlmepriv, _FW_LINKED) &&
1059                                                 _rtw_memcmp(paddr3, get_bssid(&primary_padapter->mlmepriv), ETH_ALEN))
1060                                         {
1061                                                 if(clone==_FALSE)
1062                                                 {
1063                                                         clone = _TRUE;                                                                  
1064                                                 }       
1065                                                 else
1066                                                 {
1067                                                         clone = _FALSE;
1068                                                 }
1069
1070                                                 precvframe->u.hdr.adapter = primary_padapter;   
1071                                         }
1072
1073                                         if(check_fwstate(&primary_padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) ||
1074                                                 check_fwstate(&secondary_padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING))
1075                                         {
1076                                                 clone = _TRUE;
1077                                                 precvframe->u.hdr.adapter = primary_padapter;   
1078                                         }
1079                                 
1080                                 }
1081                                 else if(subtype == WIFI_PROBEREQ)
1082                                 {
1083                                         //probe req frame is only for interface2
1084                                         //change to secondary interface
1085                                         precvframe->u.hdr.adapter = secondary_padapter;
1086                                         clone = _FALSE;
1087                                 }                       
1088                                 break;
1089                         case WIFI_CTRL_TYPE: // Handle BC/MC ctrl Packets
1090                         
1091                                 break;
1092                         case WIFI_DATA_TYPE: //Handle BC/MC data Packets
1093                                         //Notes: AP MODE never rx BC/MC data packets
1094                         
1095                                 paddr2 = GetAddr2Ptr(precvframe->u.hdr.rx_data);
1096
1097                                 if(_rtw_memcmp(paddr2, get_bssid(&secondary_padapter->mlmepriv), ETH_ALEN))
1098                                 {
1099                                         //change to secondary interface
1100                                         precvframe->u.hdr.adapter = secondary_padapter;
1101                                         clone = _FALSE;
1102                                 }
1103
1104                                 break;
1105                         default:
1106                         
1107                                 break;                  
1108                 }
1109 #endif
1110
1111                 if(_TRUE == clone)
1112                 {
1113                         //clone/copy to if2
1114                         u8 shift_sz = 0;
1115                         u32 alloc_sz, skb_len;          
1116                         _pkt     *pkt_copy = NULL;
1117                         struct rx_pkt_attrib *pattrib = NULL;
1118                 
1119                         precvframe_if2 = rtw_alloc_recvframe(pfree_recv_queue);
1120                         if(precvframe_if2)
1121                         {
1122                                 precvframe_if2->u.hdr.adapter = secondary_padapter;
1123                 
1124                                 _rtw_init_listhead(&precvframe_if2->u.hdr.list);        
1125                                 precvframe_if2->u.hdr.precvbuf = NULL;  //can't access the precvbuf for new arch.
1126                                 precvframe_if2->u.hdr.len=0;
1127
1128                                 _rtw_memcpy(&precvframe_if2->u.hdr.attrib, &precvframe->u.hdr.attrib, sizeof(struct rx_pkt_attrib));
1129
1130                                 pattrib = &precvframe_if2->u.hdr.attrib;
1131
1132                                 //      Modified by Albert 20101213
1133                                 //      For 8 bytes IP header alignment.
1134                                 if (pattrib->qos)       //      Qos data, wireless lan header length is 26
1135                                 {
1136                                         shift_sz = 6;
1137                                 }
1138                                 else
1139                                 {
1140                                         shift_sz = 0;
1141                                 }
1142
1143                                 skb_len = pattrib->pkt_len;
1144
1145                                 // for first fragment packet, driver need allocate 1536+drvinfo_sz+RXDESC_SIZE to defrag packet.
1146                                 // modify alloc_sz for recvive crc error packet by thomas 2011-06-02
1147                                 if((pattrib->mfrag == 1)&&(pattrib->frag_num == 0)){
1148                                         //alloc_sz = 1664;      //1664 is 128 alignment.
1149                                         if(skb_len <= 1650)
1150                                                 alloc_sz = 1664;
1151                                         else
1152                                                 alloc_sz = skb_len + 14;
1153                                 }
1154                                 else {
1155                                         alloc_sz = skb_len;
1156                                         //      6 is for IP header 8 bytes alignment in QoS packet case.
1157                                         //      8 is for skb->data 4 bytes alignment.
1158                                         alloc_sz += 14;
1159                                 }
1160
1161                                 pkt_copy = rtw_skb_alloc(alloc_sz);
1162
1163                                 if(pkt_copy)
1164                                 {
1165                                         pkt_copy->dev = secondary_padapter->pnetdev;
1166                                         precvframe_if2->u.hdr.pkt = pkt_copy;
1167                                         precvframe_if2->u.hdr.rx_head = pkt_copy->data;
1168                                         precvframe_if2->u.hdr.rx_end = pkt_copy->data + alloc_sz;
1169                                         skb_reserve( pkt_copy, 8 - ((SIZE_PTR)( pkt_copy->data ) & 7 ));//force pkt_copy->data at 8-byte alignment address
1170                                         skb_reserve( pkt_copy, shift_sz );//force ip_hdr at 8-byte alignment address according to shift_sz.
1171                                         _rtw_memcpy(pkt_copy->data, pbuf, skb_len);
1172                                         precvframe_if2->u.hdr.rx_data = precvframe_if2->u.hdr.rx_tail = pkt_copy->data;
1173                                         
1174                         
1175                                         recvframe_put(precvframe_if2, skb_len);
1176                                         //recvframe_pull(precvframe_if2, drvinfo_sz + RXDESC_SIZE);
1177                                         if(pphy_info)
1178                                         update_recvframe_phyinfo(precvframe_if2, pphy_info);
1179                                         //rtl8192c_translate_rx_signal_stuff(precvframe_if2, pphy_info);
1180         
1181                                         ret = rtw_recv_entry(precvframe_if2);
1182
1183                                 } else {
1184                                         rtw_free_recvframe(precvframe_if2, pfree_recv_queue);
1185                                         DBG_8192C("%s()-%d: alloc_skb() failed!\n", __FUNCTION__, __LINE__);    
1186                                 }
1187
1188                         }
1189                         
1190                 }
1191                 
1192         }
1193
1194         ret = rtw_recv_entry(precvframe);
1195
1196 #endif
1197
1198         return ret;
1199
1200 }
1201
1202 static int recvbuf2recvframe(_adapter *padapter, _pkt *pskb)
1203 {
1204         u8      *pbuf;
1205         u8      shift_sz = 0;
1206         u16     pkt_cnt;
1207         u32     pkt_offset, skb_len, alloc_sz;
1208         s32     transfer_len;
1209         struct recv_stat        *prxstat;
1210         struct phy_stat *pphy_info = NULL;
1211         _pkt                            *pkt_copy = NULL;
1212         union recv_frame        *precvframe = NULL;
1213         struct rx_pkt_attrib    *pattrib = NULL;
1214         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(padapter);
1215         struct recv_priv        *precvpriv = &padapter->recvpriv;
1216         _queue                  *pfree_recv_queue = &precvpriv->free_recv_queue;
1217
1218
1219         transfer_len = (s32)pskb->len;  
1220         pbuf = pskb->data;
1221
1222         prxstat = (struct recv_stat *)pbuf;     
1223         pkt_cnt = (le32_to_cpu(prxstat->rxdw2)>>16) & 0xff;
1224
1225 #if 0 //temp remove when disable usb rx aggregation
1226         if((pkt_cnt > 10) || (pkt_cnt < 1) || (transfer_len<RXDESC_SIZE) ||(pkt_len<=0))
1227         {               
1228                 return _FAIL;
1229         }
1230 #endif
1231
1232         do{             
1233                 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
1234                          ("recvbuf2recvframe: rxdesc=offsset 0:0x%08x, 4:0x%08x, 8:0x%08x, C:0x%08x\n",
1235                           prxstat->rxdw0, prxstat->rxdw1, prxstat->rxdw2, prxstat->rxdw4));
1236
1237                 prxstat = (struct recv_stat *)pbuf;
1238
1239                 precvframe = rtw_alloc_recvframe(pfree_recv_queue);
1240                 if(precvframe==NULL)
1241                 {
1242                         RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recvbuf2recvframe: precvframe==NULL\n"));
1243                         DBG_8192C("%s()-%d: rtw_alloc_recvframe() failed! RX Drop!\n", __FUNCTION__, __LINE__); 
1244                         goto _exit_recvbuf2recvframe;
1245                 }
1246
1247                 _rtw_init_listhead(&precvframe->u.hdr.list);    
1248                 precvframe->u.hdr.precvbuf = NULL;      //can't access the precvbuf for new arch.
1249                 precvframe->u.hdr.len=0;
1250
1251 //              rtl8192c_query_rx_desc_status(precvframe, prxstat);
1252                 update_recvframe_attrib(precvframe, prxstat);
1253
1254                 pattrib = &precvframe->u.hdr.attrib;
1255                 
1256                 if ((padapter->registrypriv.mp_mode == 0) && (pattrib->crc_err)){
1257                         DBG_8192C("%s()-%d: RX Warning! rx CRC ERROR !!\n", __FUNCTION__, __LINE__);    
1258                         rtw_free_recvframe(precvframe, pfree_recv_queue);
1259                         goto _exit_recvbuf2recvframe;
1260                 }                       
1261
1262                 pkt_offset = RXDESC_SIZE + pattrib->drvinfo_sz + pattrib->shift_sz + pattrib->pkt_len;
1263
1264                 if((pattrib->pkt_len<=0) || (pkt_offset>transfer_len))
1265                 {       
1266                         RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("recvbuf2recvframe: pkt_len<=0\n"));
1267                         DBG_8192C("%s()-%d: RX Warning!\n", __FUNCTION__, __LINE__);    
1268                         rtw_free_recvframe(precvframe, pfree_recv_queue);
1269                         goto _exit_recvbuf2recvframe;
1270                 }
1271
1272                 //      Modified by Albert 20101213
1273                 //      For 8 bytes IP header alignment.
1274                 if (pattrib->qos)       //      Qos data, wireless lan header length is 26
1275                 {
1276                         shift_sz = 6;
1277                 }
1278                 else
1279                 {
1280                         shift_sz = 0;
1281                 }
1282
1283                 skb_len = pattrib->pkt_len;
1284
1285                 // for first fragment packet, driver need allocate 1536+drvinfo_sz+RXDESC_SIZE to defrag packet.
1286                 // modify alloc_sz for recvive crc error packet by thomas 2011-06-02
1287                 if((pattrib->mfrag == 1)&&(pattrib->frag_num == 0)){
1288                         //alloc_sz = 1664;      //1664 is 128 alignment.
1289                         if(skb_len <= 1650)
1290                                 alloc_sz = 1664;
1291                         else
1292                                 alloc_sz = skb_len + 14;
1293                 }
1294                 else {
1295                         alloc_sz = skb_len;
1296                         //      6 is for IP header 8 bytes alignment in QoS packet case.
1297                         //      8 is for skb->data 4 bytes alignment.
1298                         alloc_sz += 14;
1299                 }
1300
1301                 pkt_copy = rtw_skb_alloc(alloc_sz);
1302
1303                 if(pkt_copy)
1304                 {
1305                         pkt_copy->dev = padapter->pnetdev;
1306                         precvframe->u.hdr.pkt = pkt_copy;
1307                         precvframe->u.hdr.rx_head = pkt_copy->data;
1308                         precvframe->u.hdr.rx_end = pkt_copy->data + alloc_sz;
1309                         skb_reserve( pkt_copy, 8 - ((SIZE_PTR)( pkt_copy->data ) & 7 ));//force pkt_copy->data at 8-byte alignment address
1310                         skb_reserve( pkt_copy, shift_sz );//force ip_hdr at 8-byte alignment address according to shift_sz.
1311                         _rtw_memcpy(pkt_copy->data, (pbuf + pattrib->shift_sz + pattrib->drvinfo_sz + RXDESC_SIZE), skb_len);
1312                         precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail = pkt_copy->data;
1313                 }
1314                 else
1315                 {
1316                         if((pattrib->mfrag == 1)&&(pattrib->frag_num == 0))
1317                         {                               
1318                                 DBG_8192C("recvbuf2recvframe: alloc_skb fail , drop frag frame \n");
1319                                 rtw_free_recvframe(precvframe, pfree_recv_queue);
1320                                 goto _exit_recvbuf2recvframe;
1321                         }
1322                         
1323                         precvframe->u.hdr.pkt = rtw_skb_clone(pskb);
1324                         if(precvframe->u.hdr.pkt)
1325                         {
1326                                 precvframe->u.hdr.rx_head = precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail 
1327                                         = pbuf+ pattrib->drvinfo_sz + RXDESC_SIZE;
1328                                 precvframe->u.hdr.rx_end =  pbuf +pattrib->drvinfo_sz + RXDESC_SIZE+ alloc_sz;
1329                         }
1330                         else
1331                         {
1332                                 DBG_8192C("recvbuf2recvframe: rtw_skb_clone fail\n");
1333                                 rtw_free_recvframe(precvframe, pfree_recv_queue);
1334                                 goto _exit_recvbuf2recvframe;
1335                         }
1336                         
1337                 }
1338
1339                 recvframe_put(precvframe, skb_len);
1340                 //recvframe_pull(precvframe, drvinfo_sz + RXDESC_SIZE); 
1341
1342                 if (pattrib->physt)
1343                 {
1344                         pphy_info = (struct phy_stat*)(pbuf + RXDESC_OFFSET);
1345                         update_recvframe_phyinfo(precvframe, pphy_info);
1346                 }
1347
1348 #ifdef CONFIG_USB_RX_AGGREGATION
1349                 switch(pHalData->UsbRxAggMode)
1350                 {
1351                         case USB_RX_AGG_DMA:
1352                         case USB_RX_AGG_MIX:
1353                                 pkt_offset = (u16)_RND128(pkt_offset);
1354                                 break;
1355                                 case USB_RX_AGG_USB:
1356                                 pkt_offset = (u16)_RND4(pkt_offset);
1357                                 break;
1358                         case USB_RX_AGG_DISABLE:                        
1359                         default:                                
1360                                 break;
1361                 }
1362 #endif
1363
1364 #ifdef CONFIG_CONCURRENT_MODE
1365                 if(pre_recv_entry(precvframe, prxstat, pphy_info) != _SUCCESS)
1366                 {
1367                         RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recvbuf2recvframe: recv_entry(precvframe) != _SUCCESS\n"));
1368                 }
1369 #else
1370                 if(rtw_recv_entry(precvframe) != _SUCCESS)
1371                 {
1372                         RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recvbuf2recvframe: rtw_recv_entry(precvframe) != _SUCCESS\n"));
1373                 }
1374 #endif          
1375
1376                 pkt_cnt--;
1377                 transfer_len -= pkt_offset;
1378                 pbuf += pkt_offset;     
1379                 precvframe = NULL;
1380                 pkt_copy = NULL;
1381
1382                 if(transfer_len>0 && pkt_cnt==0)
1383                         pkt_cnt = (le32_to_cpu(prxstat->rxdw2)>>16) & 0xff;
1384
1385         }while((transfer_len>0) && (pkt_cnt>0));
1386
1387 _exit_recvbuf2recvframe:
1388
1389         return _SUCCESS;        
1390 }
1391
1392 void rtl8192cu_recv_tasklet(void *priv)
1393 {
1394         _pkt                    *pskb;
1395         _adapter                *padapter = (_adapter*)priv;
1396         struct recv_priv        *precvpriv = &padapter->recvpriv;
1397         
1398         while (NULL != (pskb = skb_dequeue(&precvpriv->rx_skb_queue)))
1399         {
1400                 if ((padapter->bDriverStopped == _TRUE)||(padapter->bSurpriseRemoved== _TRUE))
1401                 {
1402                         DBG_8192C("recv_tasklet => bDriverStopped or bSurpriseRemoved \n");
1403                         rtw_skb_free(pskb);
1404                         break;
1405                 }
1406         
1407                 recvbuf2recvframe(padapter, pskb);
1408
1409 #ifdef CONFIG_PREALLOC_RECV_SKB
1410
1411                 skb_reset_tail_pointer(pskb);
1412
1413                 pskb->len = 0;
1414                 
1415                 skb_queue_tail(&precvpriv->free_recv_skb_queue, pskb);
1416                 
1417 #else
1418                 rtw_skb_free(pskb);
1419 #endif
1420                                 
1421         }
1422         
1423 }
1424
1425
1426 static void usb_read_port_complete(struct urb *purb, struct pt_regs *regs)
1427 {
1428         _irqL irqL;
1429         uint isevt, *pbuf;
1430         struct recv_buf *precvbuf = (struct recv_buf *)purb->context;   
1431         _adapter                        *padapter =(_adapter *)precvbuf->adapter;
1432         struct recv_priv        *precvpriv = &padapter->recvpriv;       
1433         
1434         RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete!!!\n"));
1435         
1436         //_enter_critical(&precvpriv->lock, &irqL);
1437         //precvbuf->irp_pending=_FALSE;
1438         //precvpriv->rx_pending_cnt --;
1439         //_exit_critical(&precvpriv->lock, &irqL);
1440                 
1441         precvpriv->rx_pending_cnt --;
1442                 
1443         //if(precvpriv->rx_pending_cnt== 0)
1444         //{             
1445         //      RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete: rx_pending_cnt== 0, set allrxreturnevt!\n"));
1446         //      _rtw_up_sema(&precvpriv->allrxreturnevt);       
1447         //}
1448
1449         if(padapter->bSurpriseRemoved || padapter->bDriverStopped||padapter->bReadPortCancel)
1450         {
1451                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete:bDriverStopped(%d) OR bSurpriseRemoved(%d)\n", padapter->bDriverStopped, padapter->bSurpriseRemoved));                
1452                 
1453         #ifdef CONFIG_PREALLOC_RECV_SKB
1454                 precvbuf->reuse = _TRUE;
1455         #else
1456                 if(precvbuf->pskb){
1457                         DBG_8192C("==> free skb(%p)\n",precvbuf->pskb);
1458                         rtw_skb_free(precvbuf->pskb);
1459                 }       
1460         #endif
1461                 DBG_8192C("%s()-%d: RX Warning! bDriverStopped(%d) OR bSurpriseRemoved(%d) bReadPortCancel(%d)\n", 
1462                 __FUNCTION__, __LINE__,padapter->bDriverStopped, padapter->bSurpriseRemoved,padapter->bReadPortCancel); 
1463                 goto exit;
1464         }
1465
1466         if(purb->status==0)//SUCCESS
1467         {
1468                 if ((purb->actual_length > MAX_RECVBUF_SZ) || (purb->actual_length < RXDESC_SIZE))
1469                 {
1470                         RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete: (purb->actual_length > MAX_RECVBUF_SZ) || (purb->actual_length < RXDESC_SIZE)\n"));
1471                         precvbuf->reuse = _TRUE;
1472                         rtw_read_port(padapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf);
1473                         DBG_8192C("%s()-%d: RX Warning!\n", __FUNCTION__, __LINE__);    
1474                 }
1475                 else 
1476                 {       
1477                         rtw_reset_continual_io_error(adapter_to_dvobj(padapter));
1478                         
1479                         precvbuf->transfer_len = purb->actual_length;                   
1480                         skb_put(precvbuf->pskb, purb->actual_length);   
1481                         skb_queue_tail(&precvpriv->rx_skb_queue, precvbuf->pskb);
1482
1483                         if (skb_queue_len(&precvpriv->rx_skb_queue)<=1)
1484                                 tasklet_schedule(&precvpriv->recv_tasklet);
1485
1486                         precvbuf->pskb = NULL;
1487                         precvbuf->reuse = _FALSE;
1488                         rtw_read_port(padapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf);                    
1489                 }               
1490         }
1491         else
1492         {
1493                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete : purb->status(%d) != 0 \n", purb->status));
1494         
1495                 DBG_8192C("###=> usb_read_port_complete => urb status(%d)\n", purb->status);
1496
1497                 if(rtw_inc_and_chk_continual_io_error(adapter_to_dvobj(padapter)) == _TRUE ){
1498                         padapter->bSurpriseRemoved = _TRUE;
1499                 }
1500
1501                 switch(purb->status) {
1502                         case -EINVAL:
1503                         case -EPIPE:                    
1504                         case -ENODEV:
1505                         case -ESHUTDOWN:
1506                                 //padapter->bSurpriseRemoved=_TRUE;
1507                                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete:bSurpriseRemoved=TRUE\n"));
1508                         case -ENOENT:
1509                                 padapter->bDriverStopped=_TRUE;                 
1510                                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port_complete:bDriverStopped=TRUE\n"));
1511                                 break;
1512                         case -EPROTO:
1513                         case -EILSEQ:
1514                         case -ETIME:
1515                         case -ECOMM:
1516                         case -EOVERFLOW:
1517                                 #ifdef DBG_CONFIG_ERROR_DETECT  
1518                                 {       
1519                                         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(padapter);
1520                                         pHalData->srestpriv.Wifi_Error_Status = USB_READ_PORT_FAIL;                     
1521                                 }
1522                                 #endif
1523                                 precvbuf->reuse = _TRUE;
1524                                 rtw_read_port(padapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf);                    
1525                                 break;
1526                         case -EINPROGRESS:
1527                                 DBG_8192C("ERROR: URB IS IN PROGRESS!/n");
1528                                 break;
1529                         default:
1530                                 break;                          
1531                 }
1532                 
1533         }       
1534
1535 exit:   
1536         
1537 _func_exit_;
1538         
1539 }
1540
1541 static u32 usb_read_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem)
1542 {       
1543         _irqL irqL;
1544         int err;
1545         unsigned int pipe;
1546         SIZE_PTR tmpaddr=0;
1547         SIZE_PTR alignment=0;
1548         u32 ret = _SUCCESS;
1549         PURB purb = NULL;
1550         struct recv_buf *precvbuf = (struct recv_buf *)rmem;
1551         _adapter                *adapter = pintfhdl->padapter;
1552         struct dvobj_priv       *pdvobj = adapter_to_dvobj(adapter);
1553         struct recv_priv        *precvpriv = &adapter->recvpriv;
1554         struct usb_device       *pusbd = pdvobj->pusbdev;
1555         
1556
1557 _func_enter_;
1558         
1559         if(adapter->bDriverStopped || adapter->bSurpriseRemoved ||dvobj_to_pwrctl(pdvobj)->pnp_bstop_trx)
1560         {
1561                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port:( padapter->bDriverStopped ||padapter->bSurpriseRemoved ||pwrctl->pnp_bstop_trx)!!!\n"));
1562                 return _FAIL;
1563         }
1564
1565 #ifdef CONFIG_PREALLOC_RECV_SKB
1566         if((precvbuf->reuse == _FALSE) || (precvbuf->pskb == NULL))
1567         {
1568                 if (NULL != (precvbuf->pskb = skb_dequeue(&precvpriv->free_recv_skb_queue)))
1569                 {
1570                         precvbuf->reuse = _TRUE;
1571                 }
1572         }
1573 #endif
1574         
1575
1576         if(precvbuf !=NULL)
1577         {       
1578                 rtl8192cu_init_recvbuf(adapter, precvbuf);              
1579
1580                 //re-assign for linux based on skb
1581                 if((precvbuf->reuse == _FALSE) || (precvbuf->pskb == NULL))
1582                 {
1583                         precvbuf->pskb = rtw_skb_alloc(MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ);
1584
1585                         if(precvbuf->pskb == NULL)              
1586                         {
1587                                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("init_recvbuf(): alloc_skb fail!\n"));
1588                                 return _FAIL;
1589                         }       
1590
1591                         tmpaddr = (SIZE_PTR)precvbuf->pskb->data;
1592                         alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1);
1593                         skb_reserve(precvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
1594
1595                         precvbuf->phead = precvbuf->pskb->head;
1596                         precvbuf->pdata = precvbuf->pskb->data;
1597                         precvbuf->ptail = skb_tail_pointer(precvbuf->pskb);
1598                         precvbuf->pend = skb_end_pointer(precvbuf->pskb);
1599                         precvbuf->pbuf = precvbuf->pskb->data;
1600                 }       
1601                 else//reuse skb
1602                 {
1603                         precvbuf->phead = precvbuf->pskb->head;
1604                         precvbuf->pdata = precvbuf->pskb->data;
1605                         precvbuf->ptail = skb_tail_pointer(precvbuf->pskb);
1606                         precvbuf->pend = skb_end_pointer(precvbuf->pskb);
1607                 precvbuf->pbuf = precvbuf->pskb->data;
1608
1609                         precvbuf->reuse = _FALSE;
1610                 }
1611
1612                 //_enter_critical(&precvpriv->lock, &irqL);
1613                 //precvpriv->rx_pending_cnt++;
1614                 //precvbuf->irp_pending = _TRUE;
1615                 //_exit_critical(&precvpriv->lock, &irqL);
1616
1617                 precvpriv->rx_pending_cnt++;
1618
1619                 purb = precvbuf->purb;
1620
1621                 //translate DMA FIFO addr to pipehandle
1622                 pipe = ffaddr2pipehdl(pdvobj, addr);
1623
1624                 usb_fill_bulk_urb(purb, pusbd, pipe, 
1625                                                 precvbuf->pbuf,
1626                                                 MAX_RECVBUF_SZ,
1627                                                 usb_read_port_complete,
1628                                                 precvbuf);//context is precvbuf
1629
1630                 err = usb_submit_urb(purb, GFP_ATOMIC);
1631                 if((err) && (err != (-EPERM)))
1632                 {
1633                         RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("cannot submit rx in-token(err=0x%.8x), URB_STATUS =0x%.8x", err, purb->status));
1634                         DBG_8192C("cannot submit rx in-token(err = 0x%08x),urb_status = %d\n",err,purb->status);
1635                         ret = _FAIL;
1636                 }
1637         }
1638         else
1639         {
1640                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_port:precvbuf ==NULL\n"));
1641                 ret = _FAIL;
1642         }
1643
1644 _func_exit_;
1645
1646         return ret;
1647 }
1648 #endif  // CONFIG_USE_USB_BUFFER_ALLOC_RX
1649
1650 void rtl8192cu_xmit_tasklet(void *priv)
1651 {       
1652         int ret = _FALSE;
1653         _adapter *padapter = (_adapter*)priv;
1654         struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1655
1656         if(check_fwstate(&padapter->mlmepriv, _FW_UNDER_SURVEY) == _TRUE)
1657                 return;
1658
1659         while(1)
1660         {
1661                 if ((padapter->bDriverStopped == _TRUE)||(padapter->bSurpriseRemoved== _TRUE) || (padapter->bWritePortCancel == _TRUE))
1662                 {
1663                         DBG_8192C("xmit_tasklet => bDriverStopped or bSurpriseRemoved or bWritePortCancel\n");
1664                         break;
1665                 }
1666
1667                 ret = rtl8192cu_xmitframe_complete(padapter, pxmitpriv, NULL);
1668
1669                 if(ret==_FALSE)
1670                         break;
1671                 
1672         }
1673         
1674 }
1675
1676 void rtl8723au_set_intf_ops(struct _io_ops      *pops)
1677 {
1678         _func_enter_;
1679         
1680         _rtw_memset((u8 *)pops, 0, sizeof(struct _io_ops));     
1681
1682         pops->_read8 = &usb_read8;
1683         pops->_read16 = &usb_read16;
1684         pops->_read32 = &usb_read32;
1685         pops->_read_mem = &usb_read_mem;
1686         pops->_read_port = &usb_read_port;      
1687         
1688         pops->_write8 = &usb_write8;
1689         pops->_write16 = &usb_write16;
1690         pops->_write32 = &usb_write32;
1691         pops->_writeN = &usb_writeN;
1692         
1693 #ifdef CONFIG_USB_SUPPORT_ASYNC_VDN_REQ 
1694         pops->_write8_async= &usb_async_write8;
1695         pops->_write16_async = &usb_async_write16;
1696         pops->_write32_async = &usb_async_write32;
1697 #endif  
1698         pops->_write_mem = &usb_write_mem;
1699         pops->_write_port = &usb_write_port;
1700
1701         pops->_read_port_cancel = &usb_read_port_cancel;
1702         pops->_write_port_cancel = &usb_write_port_cancel;
1703
1704 #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
1705         pops->_read_interrupt = &usb_read_interrupt;
1706 #endif
1707
1708         _func_exit_;
1709
1710 }
1711 void rtl8723au_set_hw_type(_adapter *padapter)
1712 {
1713         padapter->chip_type = RTL8723A;
1714         padapter->HardwareType = HARDWARE_TYPE_RTL8723AU;
1715         DBG_871X("CHIP TYPE: RTL8723A\n");
1716 }