hc
2024-03-25 edb30157bad0c0001c32b854271ace01d3b9a16a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
/******************************************************************************
 *
 * Copyright(c) 2007 - 2019 Realtek Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 *****************************************************************************/
#define _USB_OPS_LINUX_C_
 
#include <drv_types.h>
#include <rtw_sreset.h>
 
int usbctrl_vendorreq(struct dvobj_priv *pdvobjpriv, u8 request, u16 value, u16 index, void *pdata, u16 len, u8 requesttype)
{
   struct usb_device *udev = dvobj_to_usb(pdvobjpriv)->pusbdev;
 
   unsigned int pipe;
   int status = 0;
#ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
   u32 tmp_buflen = 0;
#endif
   u8 reqtype;
   u8 *pIo_buf;
   int vendorreq_times = 0;
 
#ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
   u8 *tmp_buf;
#else /* use stack memory */
   #ifndef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
   u8 tmp_buf[MAX_USB_IO_CTL_SIZE];
   #endif
#endif
 
   /* RTW_INFO("%s %s:%d\n",__FUNCTION__, current->comm, current->pid); */
 
   if (RTW_CANNOT_IO(pdvobjpriv)) {
       status = -EPERM;
       goto exit;
   }
 
   if (len > MAX_VENDOR_REQ_CMD_SIZE) {
       RTW_INFO("[%s] Buffer len error ,vendor request failed\n", __FUNCTION__);
       status = -EINVAL;
       goto exit;
   }
 
#ifdef CONFIG_USB_VENDOR_REQ_MUTEX
   _rtw_mutex_lock(&dvobj_to_usb(pdvobjpriv)->usb_vendor_req_mutex);
#endif
 
 
   /* Acquire IO memory for vendorreq */
#ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
   pIo_buf = dvobj_to_usb(pdvobjpriv)->usb_vendor_req_buf;
#else
   #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
   tmp_buf = rtw_malloc((u32) len + ALIGNMENT_UNIT);
   tmp_buflen = (u32)len + ALIGNMENT_UNIT;
   #else /* use stack memory */
   tmp_buflen = MAX_USB_IO_CTL_SIZE;
   #endif
 
   /* Added by Albert 2010/02/09 */
   /* For mstar platform, mstar suggests the address for USB IO should be 16 bytes alignment. */
   /* Trying to fix it here. */
   pIo_buf = (tmp_buf == NULL) ? NULL : tmp_buf + ALIGNMENT_UNIT - ((SIZE_PTR)(tmp_buf) & 0x0f);
#endif
 
   if (pIo_buf == NULL) {
       RTW_INFO("[%s] pIo_buf == NULL\n", __FUNCTION__);
       status = -ENOMEM;
       goto release_mutex;
   }
 
   while (++vendorreq_times <= MAX_USBCTRL_VENDORREQ_TIMES) {
       _rtw_memset(pIo_buf, 0, len);
 
       if (requesttype == 0x01) {
           pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
           reqtype =  REALTEK_USB_VENQT_READ;
       } else {
           pipe = usb_sndctrlpipe(udev, 0);/* write_out */
           reqtype =  REALTEK_USB_VENQT_WRITE;
           _rtw_memcpy(pIo_buf, pdata, len);
       }
 
       status = rtw_usb_control_msg(udev, pipe, request, reqtype, value, index, pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
 
       if (status == len) {  /* Success this control transfer. */
           rtw_reset_continual_io_error(pdvobjpriv);
           if (requesttype == 0x01) {
               /* For Control read transfer, we have to copy the read data from pIo_buf to pdata. */
               _rtw_memcpy(pdata, pIo_buf,  len);
           }
       } else { /* error cases */
           switch (len) {
               case 1:
                   RTW_INFO("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n"
                       , (index << 16 | value), (requesttype == 0x01) ? "read" : "write" , len, status, *(u8 *)pdata, vendorreq_times);
               break;
               case 2:
                   RTW_INFO("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n"
                       , (index << 16 | value), (requesttype == 0x01) ? "read" : "write" , len, status, *(u16 *)pdata, vendorreq_times);
               break;
               case 4:
                   RTW_INFO("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n"
                       , (index << 16 | value), (requesttype == 0x01) ? "read" : "write" , len, status, *(u32 *)pdata, vendorreq_times);
               break;
               default:
                   RTW_INFO("reg 0x%x, usb %s %u fail, status:%d, vendorreq_times:%d\n"
                       , (index << 16 | value), (requesttype == 0x01) ? "read" : "write" , len, status, vendorreq_times);
               break;
           }
 
           if (status < 0) {
               if (status == (-ESHUTDOWN)    || status == -ENODEV)
                   dev_set_surprise_removed(pdvobjpriv);
               else {
 
               }
           } else { /* status != len && status >= 0 */
               if (status > 0) {
                   if (requesttype == 0x01) {
                       /* For Control read transfer, we have to copy the read data from pIo_buf to pdata. */
                       _rtw_memcpy(pdata, pIo_buf,  len);
                   }
               }
           }
 
           if (rtw_inc_and_chk_continual_io_error(pdvobjpriv) == _TRUE) {
               dev_set_surprise_removed(pdvobjpriv);
               break;
           }
 
       }
 
       if (status == len)
           break;
 
   }
 
   /* release IO memory used by vendorreq */
#ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
   rtw_mfree(tmp_buf, tmp_buflen);
#endif
 
release_mutex:
#ifdef CONFIG_USB_VENDOR_REQ_MUTEX
   _rtw_mutex_unlock(&dvobj_to_usb(pdvobjpriv)->usb_vendor_req_mutex);
#endif
exit:
   return status;
 
}
 
 
 
#if (KERNEL_VERSION(2, 5, 0) > LINUX_VERSION_CODE) ||\
   (KERNEL_VERSION(2, 6, 18) < LINUX_VERSION_CODE)
/*#define _usbctrl_vendorreq_async_callback(urb, regs)\*/
   /*_usbctrl_vendorreq_async_callback(urb)*/
/*#define usb_bulkout_zero_complete(purb, regs)\*/
   /*usb_bulkout_zero_complete(purb)*/
#define rtw_usb_write_port_complete(purb, regs)\
   rtw_usb_write_port_complete(purb)
#define rtw_usb_read_port_complete(purb, regs)\
   rtw_usb_read_port_complete(purb)
#define rtw_usb_read_interrupt_complete(purb, regs)\
   rtw_usb_read_interrupt_complete(purb)
#endif
 
static unsigned int bulkid2pipe(struct dvobj_priv *pdvobj, u32 addr, u8 bulk_out)
{
   unsigned int pipe = 0, ep_num = 0;
   PUSB_DATA usb_data = dvobj_to_usb(pdvobj);
   struct usb_device *usbd = usb_data->pusbdev;
 
   if (!bulk_out) {
       if (usb_data->inpipe_type[addr] == REALTEK_USB_BULK_IN_EP_IDX)
           pipe = usb_rcvbulkpipe(usbd, usb_data->RtInPipe[addr]);
       else if (usb_data->inpipe_type[addr] == REALTEK_USB_IN_INT_EP_IDX)
           pipe = usb_rcvintpipe(usbd, usb_data->RtInPipe[addr]);
   } else if (addr < MAX_BULKOUT_NUM) {
       ep_num = usb_data->RtOutPipe[addr];
       pipe = usb_sndbulkpipe(usbd, ep_num);
   }
   return pipe;
}
 
int rtw_os_urb_resource_alloc(struct data_urb *dataurb)
{
   dataurb->urb= usb_alloc_urb(0, GFP_KERNEL);
 
   if (dataurb->urb == NULL) {
       rtw_msleep_os(10);
       dataurb->urb = usb_alloc_urb(0, GFP_KERNEL);
       if (dataurb->urb == NULL) {
           RTW_ERR("(dataurb->urb == NULL");
           rtw_warn_on(1);
           return _FAIL;
       }
   }
   return _SUCCESS;
}
 
void rtw_os_urb_resource_free(struct data_urb *dataurb)
{
   if (dataurb->urb) {
       usb_free_urb(dataurb->urb);
       dataurb->urb = NULL;
   }
}
 
struct data_urb *rtw_alloc_dataurb(struct trx_urb_buf_q *urb_q)
{
   struct data_urb *urb =  NULL;
   _list *urb_list, *urb_head;
   _queue *free_urb_q = &urb_q->free_urb_buf_queue;
   unsigned long sp_flags;
 
   /* RTW_INFO("+rtw_alloc_litexmitbuf\n"); */
 
   _rtw_spinlock_irq(&free_urb_q->lock, &sp_flags);
 
   if (_rtw_queue_empty(free_urb_q) == _TRUE)
       urb = NULL;
   else {
 
       urb_head = get_list_head(free_urb_q);
 
       urb_list = get_next(urb_head);
 
       urb = LIST_CONTAINOR(urb_list,
           struct data_urb, list);
 
       rtw_list_delete(&(urb->list));
   }
 
   if (urb !=  NULL)
       urb_q->free_urb_buf_cnt--;
 
 
   _rtw_spinunlock_irq(&free_urb_q->lock, &sp_flags);
 
 
   return urb;
}
 
s32 rtw_free_dataurb(struct trx_urb_buf_q *urb_q,
   struct data_urb *urb)
{
   _queue *free_urb_q = &urb_q->free_urb_buf_queue;
   unsigned long sp_flags;
 
   /* RTW_INFO("+rtw_free_xmiturb\n"); */
 
   if (urb_q == NULL)
       return _FAIL;
 
   if (urb == NULL)
       return _FAIL;
 
   _rtw_spinlock_irq(&free_urb_q->lock, &sp_flags);
 
   rtw_list_delete(&urb->list);
 
   rtw_list_insert_tail(&(urb->list),
       get_list_head(free_urb_q));
 
   urb_q->free_urb_buf_cnt++;
 
   _rtw_spinunlock_irq(&free_urb_q->lock, &sp_flags);
 
   return _SUCCESS;
}
 
static void rtw_usb_write_port_complete(struct urb *purb, struct pt_regs *regs)
{
 
   struct lite_data_buf *litexmitbuf =
       (struct lite_data_buf *)purb->context;
   struct data_urb *xmiturb =  litexmitbuf->dataurb;
   struct dvobj_priv *pdvobj = litexmitbuf->dvobj;
   unsigned long sp_flags;
 
   if (RTW_CANNOT_TX(pdvobj)) {
       RTW_INFO(
           "%s(): TX Warning! bDriverStopped(%s) OR bSurpriseRemoved(%s)\n"
            , __func__
            , dev_is_drv_stopped(pdvobj) ? "True" : "False"
            , dev_is_surprise_removed(pdvobj) ? "True" : "False");
 
       goto check_completion;
   }
 
 
   if (purb->status == 0) {
 
   } else {
       RTW_INFO("###=> urb_write_port_complete status(%d)\n",
           purb->status);
       if ((purb->status == -EPIPE) || (purb->status == -EPROTO)) {
           /* usb_clear_halt(pusbdev, purb->pipe);     */
           /* msleep(10); */
           /*sreset_set_wifi_error_status(padapter,*/
               /*USB_WRITE_PORT_FAIL);*/
       } else if (purb->status == -EINPROGRESS) {
           goto check_completion;
 
       } else if (purb->status == -ENOENT) {
           RTW_INFO("%s: -ENOENT\n", __func__);
           goto check_completion;
 
       } else if (purb->status == -ECONNRESET) {
           RTW_INFO("%s: -ECONNRESET\n", __func__);
           goto check_completion;
 
       } else if (purb->status == -ESHUTDOWN) {
           dev_set_drv_stopped(pdvobj);
 
           goto check_completion;
       } else {
           dev_set_surprise_removed(pdvobj);
           RTW_INFO("bSurpriseRemoved=TRUE\n");
 
           goto check_completion;
       }
   }
 
 
check_completion:
 
 
   rtw_sctx_done_err(&litexmitbuf->sctx,
   purb->status ? RTW_SCTX_DONE_WRITE_PORT_ERR : RTW_SCTX_DONE_SUCCESS);
 
   rtw_phl_recycle_tx_buf(pdvobj->phl, litexmitbuf->phl_buf_ptr);
   rtw_free_litedatabuf(&pdvobj->litexmitbuf_q, litexmitbuf);
   rtw_free_dataurb(&pdvobj->xmit_urb_q, xmiturb);
   rtw_phl_tx_req_notify(pdvobj->phl);
 
}
 
 
u32 rtw_usb_write_port(void *d, u8 *phl_tx_buf_ptr,
   u8  bulk_id, u32 len, u8 *pkt_data_buf)
{
 
   int status;
   unsigned int pipe;
   u32 ret = _FAIL;
   struct dvobj_priv *pdvobj = (struct dvobj_priv *)d;
   struct usb_device *pusbd = dvobj_to_usb(pdvobj)->pusbdev;
   struct lite_data_buf *litexmitbuf = NULL;
   struct data_urb *xmiturb = NULL;
 
 
   litexmitbuf = rtw_alloc_litedatabuf(&pdvobj->litexmitbuf_q);
   if (litexmitbuf == NULL) {
       RTW_INFO("%s,%d Can't alloc lite xmit buf\n",
           __func__, __LINE__);
       goto exit;
   }
   xmiturb = rtw_alloc_dataurb(&pdvobj->xmit_urb_q);
   if (xmiturb == NULL) {
       RTW_INFO("%s,%d Can't alloc lite xmit urb\n",
           __func__, __LINE__);
       goto exit;
   }
 
   if (RTW_CANNOT_TX(pdvobj)) {
#ifdef DBG_TX
       RTW_INFO(" DBG_TX %s:%d bDriverStopped:%s, bSurpriseRemoved:%s\n"
           ,__func__, __LINE__,
           dev_is_drv_stopped(pdvobj) ? "True" : "False",
           dev_is_surprise_removed(pdvobj) ? "True" : "False");
#endif
       rtw_sctx_done_err(&litexmitbuf->sctx, RTW_SCTX_DONE_TX_DENY);
       goto exit;
   }
 
   litexmitbuf->dvobj = pdvobj;
   litexmitbuf->pbuf = pkt_data_buf;
   litexmitbuf->dataurb = xmiturb;
   litexmitbuf->phl_buf_ptr = phl_tx_buf_ptr;
 
   pipe = bulkid2pipe(pdvobj, bulk_id, _TRUE);
 
   usb_fill_bulk_urb(xmiturb->urb, pusbd, pipe,
             litexmitbuf->pbuf,
             len,
             rtw_usb_write_port_complete,
             litexmitbuf);
   xmiturb->urb->transfer_flags |= URB_ZERO_PACKET;
   status = usb_submit_urb(xmiturb->urb, GFP_ATOMIC);
   if (!status) {
 
   } else {
       rtw_sctx_done_err(&litexmitbuf->sctx,
           RTW_SCTX_DONE_WRITE_PORT_ERR);
       RTW_INFO("%s, status=%d\n", __func__, status);
 
       switch (status) {
       case -ENODEV:
           dev_set_drv_stopped(pdvobj);
           break;
       default:
           break;
       }
       goto exit;
   }
 
   ret = _SUCCESS;
 
exit:
   if (ret != _SUCCESS) {
       rtw_free_litedatabuf(&pdvobj->litexmitbuf_q, litexmitbuf);
       rtw_free_dataurb(&pdvobj->xmit_urb_q, xmiturb);
   }
 
   if (ret == _SUCCESS)
       ret = RTW_PHL_STATUS_SUCCESS;
   else
       ret = RTW_PHL_STATUS_FAILURE;
 
   return ret;
 
}
 
 
void rtw_usb_write_port_cancel(void *d)
{
   int i, j;
   struct dvobj_priv *dvobj = (struct dvobj_priv *)d;
   struct data_urb *xmiturb = (struct data_urb *)dvobj->xmit_urb_q.urb_buf;
   u32 xmiturb_nr = RTW_XMITURB_NR;
 
 
   if (dvobj == NULL) {
       RTW_ERR("%s dvobj is NULL\n", __func__);
       rtw_warn_on(1);
       return;
   }
 
   RTW_INFO("%s\n", __func__);
 
   for (i = 0; i < xmiturb_nr; i++) {
       usb_kill_urb(xmiturb->urb);
       xmiturb++;
   }
 
 
}
 
static void rtw_usb_read_port_complete(struct urb *urb, struct pt_regs *regs)
{
   struct lite_data_buf *literecvbuf =
       (struct lite_data_buf *)urb->context;
   struct data_urb *recvurb =  literecvbuf->dataurb;
   struct dvobj_priv *dvobj = literecvbuf->dvobj;
   struct trx_data_buf_q *rx_data_buf_q = NULL;
   struct trx_urb_buf_q *rx_urb_q = NULL;
   u32 actual_length = urb->actual_length;
   u32 transfer_buffer_length = urb->transfer_buffer_length;
   u8 bulk_id = recvurb->bulk_id;
   u8 minlen = recvurb->minlen;
   unsigned long sp_flags;
   u8 status = _SUCCESS;
 
 
   if (bulk_id == REALTEK_USB_BULK_IN_EP_IDX) {
       rx_data_buf_q = &dvobj->literecvbuf_q;
       rx_urb_q = &dvobj->recv_urb_q;
       ATOMIC_DEC(&(dvobj->rx_pending_cnt));
   } else {
       #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
       rx_data_buf_q = &dvobj->intin_buf_q;
       rx_urb_q = &dvobj->intin_urb_q;
       #endif
   }
 
   if (RTW_CANNOT_RX(dvobj)) {
       RTW_INFO("%s() RX Warning! bDriverStopped(%s) OR bSurpriseRemoved(%s)\n"
           , __func__
           , dev_is_drv_stopped(dvobj) ? "True" : "False"
           , dev_is_surprise_removed(dvobj) ? "True" : "False");
 
       status = _FAIL;
       goto exit;
   }
 
   if (urb->status == 0) {
       if ((actual_length > transfer_buffer_length) || (actual_length < minlen)) {
           RTW_INFO("%s()-%d: actual_length:%u, transfer_buffer_length:%u, minlen:%u\n"
               , __FUNCTION__, __LINE__, actual_length, transfer_buffer_length, minlen);
 
           status = _FAIL;
           goto exit;
       } else {
           rtw_reset_continual_io_error(dvobj);
           status = _SUCCESS;
           goto exit;
       }
   } if (urb->status == -ENOENT) {
       /*use usb_kill_urb urb status code = -ENOENT*/
       status = _FAIL;
       goto exit;
   } else {
 
       RTW_INFO("###=> %s => urb.status(%d)\n", __func__, urb->status);
       status = _FAIL;
 
       if (rtw_inc_and_chk_continual_io_error(dvobj) == _TRUE)
           dev_set_surprise_removed(dvobj);
 
       switch (urb->status) {
       case -EINVAL:
       case -EPIPE:
       case -ENODEV:
       case -ESHUTDOWN:
           dev_set_drv_stopped(dvobj);
           break;
       case -EPROTO:
       case -EILSEQ:
       case -ETIME:
       case -ECOMM:
       case -EOVERFLOW:
           break;
       case -EINPROGRESS:
           RTW_INFO("ERROR: URB IS IN PROGRESS!/n");
           break;
       default:
           break;
       }
       goto exit;
   }
 
exit:
 
   if (status == _SUCCESS)
       status = RTW_PHL_STATUS_SUCCESS;
   else
       status = RTW_PHL_STATUS_FAILURE;
 
   rtw_phl_post_in_complete(dvobj->phl, literecvbuf->phl_buf_ptr, actual_length, status);
   rtw_free_litedatabuf(rx_data_buf_q, literecvbuf);
   rtw_free_dataurb(rx_urb_q, recvurb);
}
 
u32 rtw_usb_read_port(void *d, void *rxobj,
   u8 *inbuf, u32 inbuf_len, u8 bulk_id, u8 minlen)
{
   int err;
   unsigned int pipe;
   u32 ret = _FAIL;
   struct dvobj_priv *dvobj = (struct dvobj_priv *)d;
   struct usb_device *usbd = dvobj_to_usb(dvobj)->pusbdev;
   struct lite_data_buf *literecvbuf = NULL;
   struct data_urb *recvurb = NULL;
   struct trx_data_buf_q *rx_data_buf_q = NULL;
   struct trx_urb_buf_q *rx_urb_q = NULL;
   struct usb_data *usb_data = dvobj_to_usb(dvobj);
 
   if (RTW_CANNOT_RX(dvobj) || (inbuf == NULL)) {
       goto exit;
   }
 
   if (bulk_id == REALTEK_USB_BULK_IN_EP_IDX) {
       rx_data_buf_q = &dvobj->literecvbuf_q;
       rx_urb_q = &dvobj->recv_urb_q;
   } else if (bulk_id == REALTEK_USB_IN_INT_EP_IDX) {
       #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
       rx_data_buf_q = &dvobj->intin_buf_q;
       rx_urb_q = &dvobj->intin_urb_q;
       #else
       goto exit;
       #endif
   } else {
       RTW_INFO("%s,%d Unkown bulk id:%d\n",
           __func__, __LINE__, bulk_id);
       ret = _FAIL;
       goto exit;
   }
 
   literecvbuf = rtw_alloc_litedatabuf(rx_data_buf_q);
   if (literecvbuf == NULL) {
       RTW_INFO("%s,%d Can't alloc lite recv buf\n",
           __func__, __LINE__);
       goto exit;
   }
   recvurb = rtw_alloc_dataurb(rx_urb_q);
   if (recvurb == NULL) {
       RTW_INFO("%s,%d Can't alloc lite recv urb\n",
           __func__, __LINE__);
       goto exit;
   }
 
   recvurb->bulk_id = bulk_id;
   recvurb->minlen = minlen;
   literecvbuf->dvobj = dvobj;
   literecvbuf->pbuf = inbuf;
   literecvbuf->dataurb = recvurb;
   literecvbuf->phl_buf_ptr = rxobj;
 
   pipe = bulkid2pipe(dvobj, bulk_id, _FALSE);
 
   if (bulk_id == REALTEK_USB_BULK_IN_EP_IDX) {
       usb_fill_bulk_urb(recvurb->urb, usbd, pipe,
           literecvbuf->pbuf,
           inbuf_len,
           rtw_usb_read_port_complete,
           literecvbuf);
   } else {
       #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
       if (usb_data->inpipe_type[bulk_id] == REALTEK_USB_BULK_IN_EP_IDX)
           usb_fill_bulk_urb(recvurb->urb, usbd, pipe,
               literecvbuf->pbuf,
               inbuf_len,
               rtw_usb_read_port_complete,
               literecvbuf);
       else
           usb_fill_int_urb(recvurb->urb, usbd, pipe,
               literecvbuf->pbuf,
               inbuf_len,
               rtw_usb_read_port_complete,
               literecvbuf,
               1);
       #endif
   }
 
   err = usb_submit_urb(recvurb->urb, GFP_ATOMIC);
   if ((err) && (err != (-EPERM))) {
       RTW_INFO("cannot submit rx in-token(err = 0x%08x),urb_status = %d\n", err, recvurb->urb->status);
       ret = _FAIL;
       goto exit;
   }
 
   /* record usb bulk in */
   if (bulk_id == REALTEK_USB_BULK_IN_EP_IDX)
       ATOMIC_INC(&(dvobj->rx_pending_cnt));
 
   ret = _SUCCESS;
exit:
   if (ret != _SUCCESS) {
       rtw_free_litedatabuf(rx_data_buf_q, literecvbuf);
       rtw_free_dataurb(rx_urb_q, recvurb);
   }
 
   if (ret == _SUCCESS)
       ret = RTW_PHL_STATUS_SUCCESS;
   else
       ret = RTW_PHL_STATUS_FAILURE;
 
   return ret;
}
 
void rtw_usb_read_port_cancel(void *d)
{
   int i;
   struct dvobj_priv *dvobj = (struct dvobj_priv *)d;
   struct data_urb *recvurb = (struct data_urb *)dvobj->recv_urb_q.urb_buf;
   /*Elwin_todo need use correct literecvbuf_nr recvurb_nr */
   u32 recvurb_nr = RTW_RECVURB_NR;
#ifdef CONFIG_USB_INTERRUPT_IN_PIPE
   u32 initinurb_nr = RTW_INTINURB_NR;
#endif
 
   if (dvobj == NULL) {
       RTW_ERR("%s dvobj is NULL\n", __func__);
       rtw_warn_on(1);
       return;
   }
   RTW_INFO("%s\n", __func__);
 
   
   for (i = 0; i < recvurb_nr; i++) {
       usb_kill_urb(recvurb->urb);
       recvurb++;
   }
 
 
#ifdef CONFIG_USB_INTERRUPT_IN_PIPE
   recvurb = (struct data_urb *)dvobj->intin_urb_q.urb_buf;
   for (i = 0; i < initinurb_nr; i++) {
       usb_kill_urb(recvurb->urb);
       recvurb++;
   }
#endif
}