8723BU: Update 8723BU wifi driver to version v4.3.16_14189.20150519_BTCOEX2015119...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / hal / rtl8723b / usb / usb_ops.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 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  #define _USB_OPS_C_
20
21 #include <rtl8723b_hal.h>
22
23 #ifdef CONFIG_SUPPORT_USB_INT
24 void interrupt_handler_8723bu(_adapter *padapter,u16 pkt_len,u8 *pbuf)
25 {
26         HAL_DATA_TYPE   *pHalData=GET_HAL_DATA(padapter);
27         struct reportpwrstate_parm pwr_rpt;
28
29         if ( pkt_len != INTERRUPT_MSG_FORMAT_LEN )
30         {
31                 DBG_8192C("%s Invalid interrupt content length (%d)!\n", __FUNCTION__, pkt_len);
32                 return ;
33         }
34
35         // HISR 
36         _rtw_memcpy(&(pHalData->IntArray[0]), &(pbuf[USB_INTR_CONTENT_HISR_OFFSET]), 4);
37         _rtw_memcpy(&(pHalData->IntArray[1]), &(pbuf[USB_INTR_CONTENT_HISRE_OFFSET]), 4);
38
39         #if 0 //DBG
40         {
41                 u32 hisr=0 ,hisr_ex=0;
42                 _rtw_memcpy(&hisr,&(pHalData->IntArray[0]),4);
43                 hisr = le32_to_cpu(hisr);       
44                 
45                 _rtw_memcpy(&hisr_ex,&(pHalData->IntArray[1]),4);
46                 hisr_ex = le32_to_cpu(hisr_ex);
47                 
48                 if((hisr != 0) || (hisr_ex!=0))
49                         DBG_871X("===> %s hisr:0x%08x ,hisr_ex:0x%08x \n",__FUNCTION__,hisr,hisr_ex);
50         }
51         #endif
52
53
54 #ifdef CONFIG_LPS_LCLK
55         if(  pHalData->IntArray[0]  & IMR_CPWM_88E )
56         {
57                 _rtw_memcpy(&pwr_rpt.state, &(pbuf[USB_INTR_CONTENT_CPWM1_OFFSET]), 1);
58                 //_rtw_memcpy(&pwr_rpt.state2, &(pbuf[USB_INTR_CONTENT_CPWM2_OFFSET]), 1);
59
60                 //88e's cpwm value only change BIT0, so driver need to add PS_STATE_S2 for LPS flow.            
61                 pwr_rpt.state |= PS_STATE_S2;           
62                 _set_workitem(&(adapter_to_pwrctl(padapter)->cpwm_event));
63         }
64 #endif//CONFIG_LPS_LCLK
65
66 #ifdef CONFIG_INTERRUPT_BASED_TXBCN
67
68         #ifdef  CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
69         if (pHalData->IntArray[0] & IMR_BCNDMAINT0_88E)
70         #endif
71         #ifdef  CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
72         if (pHalData->IntArray[0] & (IMR_TBDER_88E|IMR_TBDOK_88E))
73         #endif  
74         {
75                 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
76                 #if 0
77                 if(pHalData->IntArray[0] & IMR_BCNDMAINT0_88E)
78                         DBG_8192C("%s: HISR_BCNERLY_INT\n", __func__);
79                 if(pHalData->IntArray[0] & IMR_TBDOK_88E)
80                         DBG_8192C("%s: HISR_TXBCNOK\n", __func__);
81                 if(pHalData->IntArray[0] & IMR_TBDER_88E)
82                         DBG_8192C("%s: HISR_TXBCNERR\n", __func__);
83                 #endif
84                 
85
86                 if(check_fwstate(pmlmepriv, WIFI_AP_STATE))
87         {
88                         //send_beacon(padapter);
89                         if(pmlmepriv->update_bcn == _TRUE)
90         {
91                                 //tx_beacon_hdl(padapter, NULL);
92                                 set_tx_beacon_cmd(padapter);
93         }
94         }
95 #ifdef CONFIG_CONCURRENT_MODE
96                 if(check_buddy_fwstate(padapter, WIFI_AP_STATE))
97         {
98                         //send_beacon(padapter);
99                         if(padapter->pbuddy_adapter->mlmepriv.update_bcn == _TRUE)
100         {
101                                 //tx_beacon_hdl(padapter, NULL);
102                                 set_tx_beacon_cmd(padapter->pbuddy_adapter);
103         }
104         }
105 #endif
106
107         }
108 #endif //CONFIG_INTERRUPT_BASED_TXBCN
109
110
111
112
113 #ifdef DBG_CONFIG_ERROR_DETECT_INT
114         if(  pHalData->IntArray[1]  & IMR_TXERR_8723B )
115                 DBG_871X("===> %s Tx Error Flag Interrupt Status \n",__FUNCTION__);
116         if(  pHalData->IntArray[1]  & IMR_RXERR_8723B )
117                 DBG_871X("===> %s Rx Error Flag INT Status \n",__FUNCTION__);
118         if(  pHalData->IntArray[1]  & IMR_TXFOVW_8723B )
119                 DBG_871X("===> %s Transmit FIFO Overflow \n",__FUNCTION__);
120         if(  pHalData->IntArray[1]  & IMR_RXFOVW_8723B )
121                 DBG_871X("===> %s Receive FIFO Overflow \n",__FUNCTION__);
122 #endif//DBG_CONFIG_ERROR_DETECT_INT
123
124
125         // C2H Event 
126         if(pbuf[0]!= 0){
127                 _rtw_memcpy(&(pHalData->C2hArray[0]), &(pbuf[USB_INTR_CONTENT_C2H_OFFSET]), 16);                
128                 //rtw_c2h_wk_cmd(padapter); to do..
129         }               
130
131                 }
132 #endif
133
134 #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
135 static void usb_read_interrupt_complete(struct urb *purb, struct pt_regs *regs)
136 {
137         int     err;
138         _adapter                *padapter = (_adapter    *)purb->context;
139
140         if (RTW_CANNOT_RX(padapter))
141         {
142                 DBG_8192C("%s() RX Warning! bDriverStopped(%d) OR bSurpriseRemoved(%d) \n", 
143                 __FUNCTION__,padapter->bDriverStopped, padapter->bSurpriseRemoved);
144
145                 return;
146         }
147
148         if (purb->status == 0)//SUCCESS
149         {
150                 if (purb->actual_length > INTERRUPT_MSG_FORMAT_LEN)
151                 {
152                         DBG_8192C("usb_read_interrupt_complete: purb->actual_length > INTERRUPT_MSG_FORMAT_LEN(%d)\n",INTERRUPT_MSG_FORMAT_LEN);                        
153                 }
154
155                 interrupt_handler_8723bu(padapter, purb->actual_length,purb->transfer_buffer );
156
157                 err = usb_submit_urb(purb, GFP_ATOMIC);
158                 if ((err) && (err != (-EPERM)))
159                 {
160                         DBG_8192C("cannot submit interrupt in-token(err = 0x%08x),urb_status = %d\n",err, purb->status);
161                 }
162         }
163         else
164         {
165                 DBG_8192C("###=> usb_read_interrupt_complete => urb status(%d)\n", purb->status);
166
167                 switch(purb->status) {
168                         case -EINVAL:
169                         case -EPIPE:
170                         case -ENODEV:
171                         case -ESHUTDOWN:
172                                 //padapter->bSurpriseRemoved = _TRUE;
173                                 //RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("usb_read_port_complete:bSurpriseRemoved=TRUE\n"));
174                         case -ENOENT:
175                                 padapter->bDriverStopped = _TRUE;
176                                 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("usb_read_port_complete:bDriverStopped=TRUE\n"));
177                                 break;
178                         case -EPROTO:
179                                 break;
180                         case -EINPROGRESS:
181                                 DBG_8192C("ERROR: URB IS IN PROGRESS!/n");
182                                 break;
183                         default:
184                                 break;
185                 }
186         }
187
188 }
189
190 static u32 usb_read_interrupt(struct intf_hdl *pintfhdl, u32 addr)
191 {
192         int     err;
193         unsigned int pipe;
194         u32     ret = _SUCCESS;
195         _adapter                        *adapter = pintfhdl->padapter;
196         struct dvobj_priv       *pdvobj = adapter_to_dvobj(adapter);
197         struct recv_priv        *precvpriv = &adapter->recvpriv;
198         struct usb_device       *pusbd = pdvobj->pusbdev;
199
200 _func_enter_;
201
202         if (RTW_CANNOT_RX(adapter))
203         {
204                 RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_read_interrupt:( RTW_CANNOT_RX )!!!\n"));
205                 return _FAIL;
206         }
207
208         //translate DMA FIFO addr to pipehandle
209         pipe = ffaddr2pipehdl(pdvobj, addr);
210
211         usb_fill_int_urb(precvpriv->int_in_urb, pusbd, pipe, 
212                                         precvpriv->int_in_buf,
213                                         INTERRUPT_MSG_FORMAT_LEN,
214                                         usb_read_interrupt_complete,
215                                         adapter,
216                                         1);
217
218         err = usb_submit_urb(precvpriv->int_in_urb, GFP_ATOMIC);
219         if((err) && (err != (-EPERM)))
220         {
221                 DBG_8192C("cannot submit interrupt in-token(err = 0x%08x),urb_status = %d\n",err, precvpriv->int_in_urb->status);
222                 ret = _FAIL;
223         }
224
225 _func_exit_;
226
227         return ret;
228 }
229 #endif
230
231
232 static s32 pre_recv_entry(union recv_frame *precvframe, u8 *pphy_status)
233 {
234         s32 ret=_SUCCESS;
235 #ifdef CONFIG_CONCURRENT_MODE
236         u8 *secondary_myid, *paddr1;
237         union recv_frame        *precvframe_if2 = NULL;
238         _adapter *primary_padapter = precvframe->u.hdr.adapter;
239         _adapter *secondary_padapter = primary_padapter->pbuddy_adapter;
240         struct recv_priv *precvpriv = &primary_padapter->recvpriv;
241         _queue *pfree_recv_queue = &precvpriv->free_recv_queue;
242         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(primary_padapter);
243
244         if(!secondary_padapter)
245                 return ret;
246
247         paddr1 = GetAddr1Ptr(precvframe->u.hdr.rx_data);
248
249         if(IS_MCAST(paddr1) == _FALSE)//unicast packets
250         {
251                 secondary_myid = adapter_mac_addr(secondary_padapter);
252
253                 if(_rtw_memcmp(paddr1, secondary_myid, ETH_ALEN))
254                 {
255                         //change to secondary interface
256                         precvframe->u.hdr.adapter = secondary_padapter;
257                 }
258
259                 //ret = recv_entry(precvframe);
260
261         }
262         else // Handle BC/MC Packets
263         {
264                 //clone/copy to if2
265                 _pkt     *pkt_copy = NULL;
266                 struct rx_pkt_attrib *pattrib = NULL;
267
268                 precvframe_if2 = rtw_alloc_recvframe(pfree_recv_queue);
269
270                 if(!precvframe_if2)
271                         return _FAIL;
272
273                 precvframe_if2->u.hdr.adapter = secondary_padapter;
274                 _rtw_memcpy(&precvframe_if2->u.hdr.attrib, &precvframe->u.hdr.attrib, sizeof(struct rx_pkt_attrib));
275                 pattrib = &precvframe_if2->u.hdr.attrib;
276
277                 //driver need to set skb len for skb_copy().
278                 //If skb->len is zero, skb_copy() will not copy data from original skb.
279                 skb_put(precvframe->u.hdr.pkt, pattrib->pkt_len);
280
281                 pkt_copy = rtw_skb_copy( precvframe->u.hdr.pkt);
282                 if (pkt_copy == NULL)
283                 {
284                         if((pattrib->mfrag == 1)&&(pattrib->frag_num == 0))
285                         {
286                                 DBG_8192C("pre_recv_entry(): rtw_skb_copy fail , drop frag frame \n");
287                                 rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue);
288                                 return ret;
289                         }
290
291                         pkt_copy = rtw_skb_clone( precvframe->u.hdr.pkt);
292                         if(pkt_copy == NULL)
293                         {
294                                 DBG_8192C("pre_recv_entry(): rtw_skb_clone fail , drop frame\n");
295                                 rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue);
296                                 return ret;
297                         }
298                 }
299
300                 pkt_copy->dev = secondary_padapter->pnetdev;
301
302                 precvframe_if2->u.hdr.pkt = pkt_copy;
303                 precvframe_if2->u.hdr.rx_head = pkt_copy->head;
304                 precvframe_if2->u.hdr.rx_data = pkt_copy->data;
305                 precvframe_if2->u.hdr.rx_tail = skb_tail_pointer(pkt_copy);
306                 precvframe_if2->u.hdr.rx_end = skb_end_pointer(pkt_copy);
307                 precvframe_if2->u.hdr.len = pkt_copy->len;
308
309                 //recvframe_put(precvframe_if2, pattrib->pkt_len);
310
311                 if ( pHalData->ReceiveConfig & RCR_APPFCS)
312                         recvframe_pull_tail(precvframe_if2, IEEE80211_FCS_LEN);
313
314                 if (pattrib->physt)
315                         rx_query_phy_status(precvframe_if2, pphy_status);
316
317                 if(rtw_recv_entry(precvframe_if2) != _SUCCESS)
318                 {
319                         RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,
320                                 ("recvbuf2recvframe: rtw_recv_entry(precvframe) != _SUCCESS\n"));
321                 }
322         }
323
324         //if (precvframe->u.hdr.attrib.physt)
325         //      rx_query_phy_status(precvframe, pphy_status);
326
327         //ret = rtw_recv_entry(precvframe);
328 #endif
329
330         return ret;
331
332 }
333
334 #if 0
335 static s32 pre_recv_entry(union recv_frame *precvframe, u8 *pphy_status)
336 {       
337         s32 ret=_SUCCESS;
338 #ifdef CONFIG_CONCURRENT_MODE   
339         u8 *secondary_myid, *paddr1;
340         union recv_frame        *precvframe_if2 = NULL;
341         _adapter *primary_padapter = precvframe->u.hdr.adapter;
342         _adapter *secondary_padapter = primary_padapter->pbuddy_adapter;
343         struct recv_priv *precvpriv = &primary_padapter->recvpriv;
344         _queue *pfree_recv_queue = &precvpriv->free_recv_queue;
345         u8      *pbuf = precvframe->u.hdr.rx_data;
346         
347         if(!secondary_padapter)
348                 return ret;
349         
350         paddr1 = GetAddr1Ptr(pbuf);
351
352         if(IS_MCAST(paddr1) == _FALSE)//unicast packets
353         {
354                 secondary_myid = adapter_mac_addr(secondary_padapter);
355
356                 if(_rtw_memcmp(paddr1, secondary_myid, ETH_ALEN))
357                 {                       
358                         //change to secondary interface
359                         precvframe->u.hdr.adapter = secondary_padapter;
360                 }       
361
362                 //ret = recv_entry(precvframe);
363
364         }
365         else // Handle BC/MC Packets    
366         {
367                 
368                 u8 clone = _TRUE;
369 #if 0           
370                 u8 type, subtype, *paddr2, *paddr3;
371         
372                 type =  GetFrameType(pbuf);
373                 subtype = GetFrameSubType(pbuf); //bit(7)~bit(2)
374                 
375                 switch (type)
376                 {
377                         case WIFI_MGT_TYPE: //Handle BC/MC mgnt Packets
378                                 if(subtype == WIFI_BEACON)
379                                 {
380                                         paddr3 = GetAddr3Ptr(precvframe->u.hdr.rx_data);
381                                 
382                                         if (check_fwstate(&secondary_padapter->mlmepriv, _FW_LINKED) &&
383                                                 _rtw_memcmp(paddr3, get_bssid(&secondary_padapter->mlmepriv), ETH_ALEN))
384                                         {
385                                                 //change to secondary interface
386                                                 precvframe->u.hdr.adapter = secondary_padapter;
387                                                 clone = _FALSE;
388                                         }
389
390                                         if(check_fwstate(&primary_padapter->mlmepriv, _FW_LINKED) &&
391                                                 _rtw_memcmp(paddr3, get_bssid(&primary_padapter->mlmepriv), ETH_ALEN))
392                                         {
393                                                 if(clone==_FALSE)
394                                                 {
395                                                         clone = _TRUE;                                                                  
396                                                 }       
397                                                 else
398                                                 {
399                                                         clone = _FALSE;
400                                                 }
401
402                                                 precvframe->u.hdr.adapter = primary_padapter;   
403                                         }
404
405                                         if(check_fwstate(&primary_padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) ||
406                                                 check_fwstate(&secondary_padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING))
407                                         {
408                                                 clone = _TRUE;
409                                                 precvframe->u.hdr.adapter = primary_padapter;   
410                                         }
411                                 
412                                 }
413                                 else if(subtype == WIFI_PROBEREQ)
414                                 {
415                                         //probe req frame is only for interface2
416                                         //change to secondary interface
417                                         precvframe->u.hdr.adapter = secondary_padapter;
418                                         clone = _FALSE;
419                                 }                       
420                                 break;
421                         case WIFI_CTRL_TYPE: // Handle BC/MC ctrl Packets
422                         
423                                 break;
424                         case WIFI_DATA_TYPE: //Handle BC/MC data Packets
425                                         //Notes: AP MODE never rx BC/MC data packets
426                         
427                                 paddr2 = GetAddr2Ptr(precvframe->u.hdr.rx_data);
428
429                                 if(_rtw_memcmp(paddr2, get_bssid(&secondary_padapter->mlmepriv), ETH_ALEN))
430                                 {
431                                         //change to secondary interface
432                                         precvframe->u.hdr.adapter = secondary_padapter;
433                                         clone = _FALSE;
434                                 }
435
436                                 break;
437                         default:
438                         
439                                 break;                  
440                 }
441 #endif
442
443                 if(_TRUE == clone)
444                 {
445                         //clone/copy to if2             
446                         struct rx_pkt_attrib *pattrib = NULL;
447                 
448                         precvframe_if2 = rtw_alloc_recvframe(pfree_recv_queue);
449                         if(precvframe_if2)
450                         {
451                                 precvframe_if2->u.hdr.adapter = secondary_padapter;
452                 
453                                 _rtw_init_listhead(&precvframe_if2->u.hdr.list);        
454                                 precvframe_if2->u.hdr.precvbuf = NULL;  //can't access the precvbuf for new arch.
455                                 precvframe_if2->u.hdr.len=0;
456
457                                 _rtw_memcpy(&precvframe_if2->u.hdr.attrib, &precvframe->u.hdr.attrib, sizeof(struct rx_pkt_attrib));
458
459                                 pattrib = &precvframe_if2->u.hdr.attrib;
460
461                                 if(rtw_os_alloc_recvframe(secondary_padapter, precvframe_if2, pbuf, NULL) == _SUCCESS)                          
462                                 {                                               
463                                         recvframe_put(precvframe_if2, pattrib->pkt_len);
464                                         //recvframe_pull(precvframe_if2, drvinfo_sz + RXDESC_SIZE);
465
466                                         if (pattrib->physt && pphy_status)
467                                                 rx_query_phy_status(precvframe_if2, pphy_status);
468         
469                                         ret = rtw_recv_entry(precvframe_if2);                           
470                                 }       
471                                 else
472                                 {
473                                         rtw_free_recvframe(precvframe_if2, pfree_recv_queue);
474                                         DBG_8192C("%s()-%d: alloc_skb() failed!\n", __FUNCTION__, __LINE__);    
475                                 }
476
477                         }
478                         
479                 }
480                 
481         }
482         //if (precvframe->u.hdr.attrib.physt)
483         //      rx_query_phy_status(precvframe, pphy_status);
484
485         //ret = rtw_recv_entry(precvframe);
486
487 #endif
488
489         return ret;
490
491 }
492 #endif
493
494 int recvbuf2recvframe(PADAPTER padapter, void *ptr)
495 {
496         u8 *pbuf;
497         u8 pkt_cnt = 0;
498         u32 pkt_offset;
499         s32 transfer_len;
500         u8 *pdata, *pphy_status;
501         union recv_frame *precvframe = NULL;
502         struct rx_pkt_attrib *pattrib = NULL;
503         PHAL_DATA_TYPE pHalData;
504         struct recv_priv *precvpriv;
505         _queue *pfree_recv_queue;
506         _pkt *pskb;
507
508
509         pHalData = GET_HAL_DATA(padapter);
510         precvpriv = &padapter->recvpriv;
511         pfree_recv_queue = &precvpriv->free_recv_queue;
512
513 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
514         pskb = NULL;
515         transfer_len = (s32)((struct recv_buf*)ptr)->transfer_len;
516         pbuf = ((struct recv_buf*)ptr)->pbuf;
517 #else // !CONFIG_USE_USB_BUFFER_ALLOC_RX
518         pskb = (_pkt*)ptr;
519         transfer_len = (s32)pskb->len;
520         pbuf = pskb->data;
521 #endif // !CONFIG_USE_USB_BUFFER_ALLOC_RX
522
523 #ifdef CONFIG_USB_RX_AGGREGATION
524         pkt_cnt = GET_RX_STATUS_DESC_USB_AGG_PKTNUM_8723B(pbuf);
525 #endif
526
527         do {
528                 precvframe = rtw_alloc_recvframe(pfree_recv_queue);
529                 if (precvframe == NULL) {
530                         DBG_8192C("%s: rtw_alloc_recvframe() failed! RX Drop!\n", __FUNCTION__);
531                         goto _exit_recvbuf2recvframe;
532                 }
533
534                 if (transfer_len >1500)
535                         _rtw_init_listhead(&precvframe->u.hdr.list);
536                 precvframe->u.hdr.precvbuf = NULL;      //can't access the precvbuf for new arch.
537                 precvframe->u.hdr.len = 0;
538
539                 rtl8723b_query_rx_desc_status(precvframe, pbuf);
540
541                 pattrib = &precvframe->u.hdr.attrib;
542
543                 if ((padapter->registrypriv.mp_mode == 0)
544                    && ((pattrib->crc_err) || (pattrib->icv_err))) {
545                         DBG_8192C("%s: RX Warning! crc_err=%d icv_err=%d, skip!\n",
546                                 __FUNCTION__, pattrib->crc_err, pattrib->icv_err);
547
548                         rtw_free_recvframe(precvframe, pfree_recv_queue);
549                         goto _exit_recvbuf2recvframe;
550                 }
551
552                 pkt_offset = RXDESC_SIZE + pattrib->drvinfo_sz + pattrib->shift_sz + pattrib->pkt_len;
553                 if ((pattrib->pkt_len <= 0) || (pkt_offset > transfer_len)) {
554                         DBG_8192C("%s: RX Error! pkt_len=%d pkt_offset=%d transfer_len=%d\n",
555                                 __FUNCTION__, pattrib->pkt_len, pkt_offset, transfer_len);
556
557                         rtw_free_recvframe(precvframe, pfree_recv_queue);
558                         goto _exit_recvbuf2recvframe;
559                 }
560
561                 pdata = pbuf + RXDESC_SIZE + pattrib->drvinfo_sz + pattrib->shift_sz;
562                 if (rtw_os_alloc_recvframe(padapter, precvframe, pdata, pskb) == _FAIL) {
563                         DBG_8192C("%s: RX Error! rtw_os_alloc_recvframe FAIL!\n", __FUNCTION__);
564
565                         rtw_free_recvframe(precvframe, pfree_recv_queue);
566                         goto _exit_recvbuf2recvframe;
567                 }
568
569                 recvframe_put(precvframe, pattrib->pkt_len);
570
571                 if (pattrib->pkt_rpt_type == NORMAL_RX) {
572                         if (pattrib->physt)
573                                 pphy_status = pbuf + RXDESC_OFFSET;
574                         else
575                                 pphy_status = NULL;
576
577 #ifdef CONFIG_CONCURRENT_MODE
578                         if (rtw_buddy_adapter_up(padapter)) {
579                                 if (pre_recv_entry(precvframe, pphy_status) != _SUCCESS) {
580                                         // Return fail except data frame
581                                         //DBG_8192C("%s: RX Error! (concurrent)pre_recv_entry FAIL!\n", __FUNCTION__);
582                                 }
583                         }
584 #endif // CONFIG_CONCURRENT_MODE
585
586                         if (pphy_status)
587                                 rx_query_phy_status(precvframe, pphy_status);
588
589                         if (rtw_recv_entry(precvframe) != _SUCCESS) {
590                                 // Return fail except data frame
591                                 //DBG_8192C("%s: RX Error! rtw_recv_entry FAIL!\n", __FUNCTION__);
592                         }
593                 }
594                 else {
595 #ifdef CONFIG_C2H_PACKET_EN
596                         if (pattrib->pkt_rpt_type == C2H_PACKET) {
597                                 rtl8723b_c2h_packet_handler(padapter, precvframe->u.hdr.rx_data, pattrib->pkt_len);
598                         }
599                         else {
600                                 DBG_8192C("%s: [WARNNING] RX type(%d) not be handled!\n",
601                                         __FUNCTION__, pattrib->pkt_rpt_type);
602                         }
603 #endif // CONFIG_C2H_PACKET_EN
604                         rtw_free_recvframe(precvframe, pfree_recv_queue);
605                 }
606
607 #ifdef CONFIG_USB_RX_AGGREGATION
608                 // jaguar 8-byte alignment
609                 pkt_offset = (u16)_RND8(pkt_offset);
610                 pkt_cnt--;
611                 pbuf += pkt_offset;
612 #endif
613                 transfer_len -= pkt_offset;
614                 precvframe = NULL;
615         } while (transfer_len > 0);
616
617 _exit_recvbuf2recvframe:
618
619         return _SUCCESS;        
620 }
621
622
623 void rtl8723bu_xmit_tasklet(void *priv)
624 {       
625         int ret = _FALSE;
626         _adapter *padapter = (_adapter*)priv;
627         struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
628
629         while(1)
630         {
631                 if (RTW_CANNOT_TX(padapter))
632                 {
633                         DBG_8192C("xmit_tasklet => bDriverStopped or bSurpriseRemoved or bWritePortCancel\n");
634                         break;
635                 }
636
637                 if(check_fwstate(&padapter->mlmepriv, _FW_UNDER_SURVEY) == _TRUE
638                         #ifdef CONFIG_CONCURRENT_MODE
639                         || check_buddy_fwstate(padapter, _FW_UNDER_SURVEY) == _TRUE
640                         #endif
641                 ) {
642                         break;
643                 }
644
645                 ret = rtl8723bu_xmitframe_complete(padapter, pxmitpriv, NULL);
646
647                 if(ret==_FALSE)
648                         break;
649                 
650         }
651         
652 }
653
654
655
656 void rtl8723bu_set_intf_ops(struct _io_ops      *pops)
657 {
658         _func_enter_;
659         
660         _rtw_memset((u8 *)pops, 0, sizeof(struct _io_ops));     
661
662         pops->_read8 = &usb_read8;
663         pops->_read16 = &usb_read16;
664         pops->_read32 = &usb_read32;
665         pops->_read_mem = &usb_read_mem;
666         pops->_read_port = &usb_read_port;
667         
668         pops->_write8 = &usb_write8;
669         pops->_write16 = &usb_write16;
670         pops->_write32 = &usb_write32;
671         pops->_writeN = &usb_writeN;
672         
673 #ifdef CONFIG_USB_SUPPORT_ASYNC_VDN_REQ 
674         pops->_write8_async= &usb_async_write8;
675         pops->_write16_async = &usb_async_write16;
676         pops->_write32_async = &usb_async_write32;
677 #endif  
678         pops->_write_mem = &usb_write_mem;
679         pops->_write_port = &usb_write_port;
680
681         pops->_read_port_cancel = &usb_read_port_cancel;
682         pops->_write_port_cancel = &usb_write_port_cancel;
683
684 #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
685         pops->_read_interrupt = &usb_read_interrupt;
686 #endif
687
688         _func_exit_;
689
690 }
691 void rtl8723bu_set_hw_type(_adapter *padapter)
692 {
693         padapter->HardwareType = HARDWARE_TYPE_RTL8723BU;
694         DBG_871X("CHIP TYPE: RTL8723BU\n");
695 }