c5dc2682116ffbd7d66049c917fb686479e999ac
[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, struct phy_stat *pphy_status)
233 {
234         s32 ret=_SUCCESS;
235 #ifdef CONFIG_CONCURRENT_MODE
236         u8 *primary_myid, *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                 //primary_myid = myid(&primary_padapter->eeprompriv);
252                 secondary_myid = myid(&secondary_padapter->eeprompriv);
253
254                 if(_rtw_memcmp(paddr1, secondary_myid, ETH_ALEN))
255                 {
256                         //change to secondary interface
257                         precvframe->u.hdr.adapter = secondary_padapter;
258                 }
259
260                 //ret = recv_entry(precvframe);
261
262         }
263         else // Handle BC/MC Packets
264         {
265                 //clone/copy to if2
266                 _pkt     *pkt_copy = NULL;
267                 struct rx_pkt_attrib *pattrib = NULL;
268
269                 precvframe_if2 = rtw_alloc_recvframe(pfree_recv_queue);
270
271                 if(!precvframe_if2)
272                         return _FAIL;
273
274                 precvframe_if2->u.hdr.adapter = secondary_padapter;
275                 _rtw_memcpy(&precvframe_if2->u.hdr.attrib, &precvframe->u.hdr.attrib, sizeof(struct rx_pkt_attrib));
276                 pattrib = &precvframe_if2->u.hdr.attrib;
277
278                 //driver need to set skb len for skb_copy().
279                 //If skb->len is zero, skb_copy() will not copy data from original skb.
280                 skb_put(precvframe->u.hdr.pkt, pattrib->pkt_len);
281
282                 pkt_copy = rtw_skb_copy( precvframe->u.hdr.pkt);
283                 if (pkt_copy == NULL)
284                 {
285                         if((pattrib->mfrag == 1)&&(pattrib->frag_num == 0))
286                         {
287                                 DBG_8192C("pre_recv_entry(): rtw_skb_copy fail , drop frag frame \n");
288                                 rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue);
289                                 return ret;
290                         }
291
292                         pkt_copy = rtw_skb_clone( precvframe->u.hdr.pkt);
293                         if(pkt_copy == NULL)
294                         {
295                                 DBG_8192C("pre_recv_entry(): rtw_skb_clone fail , drop frame\n");
296                                 rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue);
297                                 return ret;
298                         }
299                 }
300
301                 pkt_copy->dev = secondary_padapter->pnetdev;
302
303                 precvframe_if2->u.hdr.pkt = pkt_copy;
304                 precvframe_if2->u.hdr.rx_head = pkt_copy->head;
305                 precvframe_if2->u.hdr.rx_data = pkt_copy->data;
306                 precvframe_if2->u.hdr.rx_tail = skb_tail_pointer(pkt_copy);
307                 precvframe_if2->u.hdr.rx_end = skb_end_pointer(pkt_copy);
308                 precvframe_if2->u.hdr.len = pkt_copy->len;
309
310                 //recvframe_put(precvframe_if2, pattrib->pkt_len);
311
312                 if ( pHalData->ReceiveConfig & RCR_APPFCS)
313                         recvframe_pull_tail(precvframe_if2, IEEE80211_FCS_LEN);
314
315                 if (pattrib->physt)
316                         rtl8723b_query_rx_phy_status(precvframe_if2, pphy_status);
317
318                 if(rtw_recv_entry(precvframe_if2) != _SUCCESS)
319                 {
320                         RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,
321                                 ("recvbuf2recvframe: rtw_recv_entry(precvframe) != _SUCCESS\n"));
322                 }
323         }
324
325         //if (precvframe->u.hdr.attrib.physt)
326         //      rtl8723b_query_rx_phy_status(precvframe, pphy_status);
327
328         //ret = rtw_recv_entry(precvframe);
329 #endif
330
331         return ret;
332
333 }
334
335 #if 0
336 static s32 pre_recv_entry(union recv_frame *precvframe, u8 *pphy_status)
337 {       
338         s32 ret=_SUCCESS;
339 #ifdef CONFIG_CONCURRENT_MODE   
340         u8 *primary_myid, *secondary_myid, *paddr1;
341         union recv_frame        *precvframe_if2 = NULL;
342         _adapter *primary_padapter = precvframe->u.hdr.adapter;
343         _adapter *secondary_padapter = primary_padapter->pbuddy_adapter;
344         struct recv_priv *precvpriv = &primary_padapter->recvpriv;
345         _queue *pfree_recv_queue = &precvpriv->free_recv_queue;
346         u8      *pbuf = precvframe->u.hdr.rx_data;
347         
348         if(!secondary_padapter)
349                 return ret;
350         
351         paddr1 = GetAddr1Ptr(pbuf);
352
353         if(IS_MCAST(paddr1) == _FALSE)//unicast packets
354         {
355                 //primary_myid = myid(&primary_padapter->eeprompriv);
356                 secondary_myid = myid(&secondary_padapter->eeprompriv);
357
358                 if(_rtw_memcmp(paddr1, secondary_myid, ETH_ALEN))
359                 {                       
360                         //change to secondary interface
361                         precvframe->u.hdr.adapter = secondary_padapter;
362                 }       
363
364                 //ret = recv_entry(precvframe);
365
366         }
367         else // Handle BC/MC Packets    
368         {
369                 
370                 u8 clone = _TRUE;
371 #if 0           
372                 u8 type, subtype, *paddr2, *paddr3;
373         
374                 type =  GetFrameType(pbuf);
375                 subtype = GetFrameSubType(pbuf); //bit(7)~bit(2)
376                 
377                 switch (type)
378                 {
379                         case WIFI_MGT_TYPE: //Handle BC/MC mgnt Packets
380                                 if(subtype == WIFI_BEACON)
381                                 {
382                                         paddr3 = GetAddr3Ptr(precvframe->u.hdr.rx_data);
383                                 
384                                         if (check_fwstate(&secondary_padapter->mlmepriv, _FW_LINKED) &&
385                                                 _rtw_memcmp(paddr3, get_bssid(&secondary_padapter->mlmepriv), ETH_ALEN))
386                                         {
387                                                 //change to secondary interface
388                                                 precvframe->u.hdr.adapter = secondary_padapter;
389                                                 clone = _FALSE;
390                                         }
391
392                                         if(check_fwstate(&primary_padapter->mlmepriv, _FW_LINKED) &&
393                                                 _rtw_memcmp(paddr3, get_bssid(&primary_padapter->mlmepriv), ETH_ALEN))
394                                         {
395                                                 if(clone==_FALSE)
396                                                 {
397                                                         clone = _TRUE;                                                                  
398                                                 }       
399                                                 else
400                                                 {
401                                                         clone = _FALSE;
402                                                 }
403
404                                                 precvframe->u.hdr.adapter = primary_padapter;   
405                                         }
406
407                                         if(check_fwstate(&primary_padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) ||
408                                                 check_fwstate(&secondary_padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING))
409                                         {
410                                                 clone = _TRUE;
411                                                 precvframe->u.hdr.adapter = primary_padapter;   
412                                         }
413                                 
414                                 }
415                                 else if(subtype == WIFI_PROBEREQ)
416                                 {
417                                         //probe req frame is only for interface2
418                                         //change to secondary interface
419                                         precvframe->u.hdr.adapter = secondary_padapter;
420                                         clone = _FALSE;
421                                 }                       
422                                 break;
423                         case WIFI_CTRL_TYPE: // Handle BC/MC ctrl Packets
424                         
425                                 break;
426                         case WIFI_DATA_TYPE: //Handle BC/MC data Packets
427                                         //Notes: AP MODE never rx BC/MC data packets
428                         
429                                 paddr2 = GetAddr2Ptr(precvframe->u.hdr.rx_data);
430
431                                 if(_rtw_memcmp(paddr2, get_bssid(&secondary_padapter->mlmepriv), ETH_ALEN))
432                                 {
433                                         //change to secondary interface
434                                         precvframe->u.hdr.adapter = secondary_padapter;
435                                         clone = _FALSE;
436                                 }
437
438                                 break;
439                         default:
440                         
441                                 break;                  
442                 }
443 #endif
444
445                 if(_TRUE == clone)
446                 {
447                         //clone/copy to if2             
448                         struct rx_pkt_attrib *pattrib = NULL;
449                 
450                         precvframe_if2 = rtw_alloc_recvframe(pfree_recv_queue);
451                         if(precvframe_if2)
452                         {
453                                 precvframe_if2->u.hdr.adapter = secondary_padapter;
454                 
455                                 _rtw_init_listhead(&precvframe_if2->u.hdr.list);        
456                                 precvframe_if2->u.hdr.precvbuf = NULL;  //can't access the precvbuf for new arch.
457                                 precvframe_if2->u.hdr.len=0;
458
459                                 _rtw_memcpy(&precvframe_if2->u.hdr.attrib, &precvframe->u.hdr.attrib, sizeof(struct rx_pkt_attrib));
460
461                                 pattrib = &precvframe_if2->u.hdr.attrib;
462
463                                 if(rtw_os_alloc_recvframe(secondary_padapter, precvframe_if2, pbuf, NULL) == _SUCCESS)                          
464                                 {                                               
465                                         recvframe_put(precvframe_if2, pattrib->pkt_len);
466                                         //recvframe_pull(precvframe_if2, drvinfo_sz + RXDESC_SIZE);
467
468                                         if (pattrib->physt && pphy_status)
469                                                 rtl8812_query_rx_phy_status(precvframe_if2, pphy_status);
470         
471                                         ret = rtw_recv_entry(precvframe_if2);                           
472                                 }       
473                                 else
474                                 {
475                                         rtw_free_recvframe(precvframe_if2, pfree_recv_queue);
476                                         DBG_8192C("%s()-%d: alloc_skb() failed!\n", __FUNCTION__, __LINE__);    
477                                 }
478
479                         }
480                         
481                 }
482                 
483         }
484         //if (precvframe->u.hdr.attrib.physt)
485         //      rtl8812_query_rx_phy_status(precvframe, pphy_status);
486
487         //ret = rtw_recv_entry(precvframe);
488
489 #endif
490
491         return ret;
492
493 }
494 #endif
495
496 int recvbuf2recvframe(PADAPTER padapter, void *ptr)
497 {
498         u8 *pbuf;
499         u8 pkt_cnt = 0;
500         u32 pkt_offset;
501         s32 transfer_len;
502         u8 *pdata, *pphy_status;
503         union recv_frame *precvframe = NULL;
504         struct rx_pkt_attrib *pattrib = NULL;
505         PHAL_DATA_TYPE pHalData;
506         struct recv_priv *precvpriv;
507         _queue *pfree_recv_queue;
508         _pkt *pskb;
509
510
511         pHalData = GET_HAL_DATA(padapter);
512         precvpriv = &padapter->recvpriv;
513         pfree_recv_queue = &precvpriv->free_recv_queue;
514
515 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
516         pskb = NULL;
517         transfer_len = (s32)((struct recv_buf*)ptr)->transfer_len;
518         pbuf = ((struct recv_buf*)ptr)->pbuf;
519 #else // !CONFIG_USE_USB_BUFFER_ALLOC_RX
520         pskb = (_pkt*)ptr;
521         transfer_len = (s32)pskb->len;
522         pbuf = pskb->data;
523 #endif // !CONFIG_USE_USB_BUFFER_ALLOC_RX
524
525 #ifdef CONFIG_USB_RX_AGGREGATION
526         pkt_cnt = GET_RX_STATUS_DESC_USB_AGG_PKTNUM_8723B(pbuf);
527 #endif
528
529         do {
530                 precvframe = rtw_alloc_recvframe(pfree_recv_queue);
531                 if (precvframe == NULL) {
532                         DBG_8192C("%s: rtw_alloc_recvframe() failed! RX Drop!\n", __FUNCTION__);
533                         goto _exit_recvbuf2recvframe;
534                 }
535
536                 if (transfer_len >1500)
537                         _rtw_init_listhead(&precvframe->u.hdr.list);
538                 precvframe->u.hdr.precvbuf = NULL;      //can't access the precvbuf for new arch.
539                 precvframe->u.hdr.len = 0;
540
541                 rtl8723b_query_rx_desc_status(precvframe, pbuf);
542
543                 pattrib = &precvframe->u.hdr.attrib;
544
545                 if ((padapter->registrypriv.mp_mode == 0)
546                    && ((pattrib->crc_err) || (pattrib->icv_err))) {
547                         DBG_8192C("%s: RX Warning! crc_err=%d icv_err=%d, skip!\n",
548                                 __FUNCTION__, pattrib->crc_err, pattrib->icv_err);
549
550                         rtw_free_recvframe(precvframe, pfree_recv_queue);
551                         goto _exit_recvbuf2recvframe;
552                 }
553
554                 pkt_offset = RXDESC_SIZE + pattrib->drvinfo_sz + pattrib->shift_sz + pattrib->pkt_len;
555                 if ((pattrib->pkt_len <= 0) || (pkt_offset > transfer_len)) {
556                         DBG_8192C("%s: RX Error! pkt_len=%d pkt_offset=%d transfer_len=%d\n",
557                                 __FUNCTION__, pattrib->pkt_len, pkt_offset, transfer_len);
558
559                         rtw_free_recvframe(precvframe, pfree_recv_queue);
560                         goto _exit_recvbuf2recvframe;
561                 }
562
563                 pdata = pbuf + RXDESC_SIZE + pattrib->drvinfo_sz + pattrib->shift_sz;
564                 if (rtw_os_alloc_recvframe(padapter, precvframe, pdata, pskb) == _FAIL) {
565                         DBG_8192C("%s: RX Error! rtw_os_alloc_recvframe FAIL!\n", __FUNCTION__);
566
567                         rtw_free_recvframe(precvframe, pfree_recv_queue);
568                         goto _exit_recvbuf2recvframe;
569                 }
570
571                 recvframe_put(precvframe, pattrib->pkt_len);
572
573                 if (pattrib->pkt_rpt_type == NORMAL_RX) {
574                         if (pattrib->physt)
575                                 pphy_status = pbuf + RXDESC_OFFSET;
576                         else
577                                 pphy_status = NULL;
578
579 #ifdef CONFIG_CONCURRENT_MODE
580                         if (rtw_buddy_adapter_up(padapter)) {
581                                 if (pre_recv_entry(precvframe, (struct phy_stat*)pphy_status) != _SUCCESS) {
582                                         // Return fail except data frame
583                                         //DBG_8192C("%s: RX Error! (concurrent)pre_recv_entry FAIL!\n", __FUNCTION__);
584                                 }
585                         }
586 #endif // CONFIG_CONCURRENT_MODE
587
588                         if (pphy_status)
589                                 rtl8723b_query_rx_phy_status(precvframe, (struct phy_stat*)pphy_status);
590
591                         if (rtw_recv_entry(precvframe) != _SUCCESS) {
592                                 // Return fail except data frame
593                                 //DBG_8192C("%s: RX Error! rtw_recv_entry FAIL!\n", __FUNCTION__);
594                         }
595                 }
596                 else {
597 #ifdef CONFIG_C2H_PACKET_EN
598                         if (pattrib->pkt_rpt_type == C2H_PACKET) {
599                                 rtl8723b_c2h_packet_handler(padapter, precvframe->u.hdr.rx_data, pattrib->pkt_len);
600                         }
601                         else {
602                                 DBG_8192C("%s: [WARNNING] RX type(%d) not be handled!\n",
603                                         __FUNCTION__, pattrib->pkt_rpt_type);
604                         }
605 #endif // CONFIG_C2H_PACKET_EN
606                         rtw_free_recvframe(precvframe, pfree_recv_queue);
607                 }
608
609 #ifdef CONFIG_USB_RX_AGGREGATION
610                 // jaguar 8-byte alignment
611                 pkt_offset = (u16)_RND8(pkt_offset);
612                 pkt_cnt--;
613                 pbuf += pkt_offset;
614 #endif
615                 transfer_len -= pkt_offset;
616                 precvframe = NULL;
617         } while (transfer_len > 0);
618
619 _exit_recvbuf2recvframe:
620
621         return _SUCCESS;        
622 }
623
624
625 void rtl8723bu_xmit_tasklet(void *priv)
626 {       
627         int ret = _FALSE;
628         _adapter *padapter = (_adapter*)priv;
629         struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
630
631         if(check_fwstate(&padapter->mlmepriv, _FW_UNDER_SURVEY) == _TRUE)
632                 return;
633
634         while(1)
635         {
636                 if (RTW_CANNOT_TX(padapter))
637                 {
638                         DBG_8192C("xmit_tasklet => bDriverStopped or bSurpriseRemoved or bWritePortCancel\n");
639                         break;
640                 }
641
642                 ret = rtl8723bu_xmitframe_complete(padapter, pxmitpriv, NULL);
643
644                 if(ret==_FALSE)
645                         break;
646                 
647         }
648         
649 }
650
651
652
653 void rtl8723bu_set_intf_ops(struct _io_ops      *pops)
654 {
655         _func_enter_;
656         
657         _rtw_memset((u8 *)pops, 0, sizeof(struct _io_ops));     
658
659         pops->_read8 = &usb_read8;
660         pops->_read16 = &usb_read16;
661         pops->_read32 = &usb_read32;
662         pops->_read_mem = &usb_read_mem;
663         pops->_read_port = &usb_read_port;
664         
665         pops->_write8 = &usb_write8;
666         pops->_write16 = &usb_write16;
667         pops->_write32 = &usb_write32;
668         pops->_writeN = &usb_writeN;
669         
670 #ifdef CONFIG_USB_SUPPORT_ASYNC_VDN_REQ 
671         pops->_write8_async= &usb_async_write8;
672         pops->_write16_async = &usb_async_write16;
673         pops->_write32_async = &usb_async_write32;
674 #endif  
675         pops->_write_mem = &usb_write_mem;
676         pops->_write_port = &usb_write_port;
677
678         pops->_read_port_cancel = &usb_read_port_cancel;
679         pops->_write_port_cancel = &usb_write_port_cancel;
680
681 #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
682         pops->_read_interrupt = &usb_read_interrupt;
683 #endif
684
685         _func_exit_;
686
687 }
688 void rtl8723bu_set_hw_type(_adapter *padapter)
689 {
690         padapter->HardwareType = HARDWARE_TYPE_RTL8723BU;
691         DBG_871X("CHIP TYPE: RTL8723BU\n");
692 }