usb_ops_linux.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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_LINUX_C_
  20. #include <drv_types.h>
  21. #include <hal_data.h>
  22. #include <rtw_sreset.h>
  23. int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u8 request, u16 value, u16 index, void *pdata, u16 len, u8 requesttype)
  24. {
  25. _adapter *padapter = pintfhdl->padapter;
  26. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
  27. struct usb_device *udev=pdvobjpriv->pusbdev;
  28. unsigned int pipe;
  29. int status = 0;
  30. u32 tmp_buflen=0;
  31. u8 reqtype;
  32. u8 *pIo_buf;
  33. int vendorreq_times = 0;
  34. #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
  35. u8 *tmp_buf;
  36. #else // use stack memory
  37. u8 tmp_buf[MAX_USB_IO_CTL_SIZE];
  38. #endif
  39. #ifdef CONFIG_CONCURRENT_MODE
  40. if(padapter->adapter_type > PRIMARY_ADAPTER)
  41. {
  42. padapter = padapter->pbuddy_adapter;
  43. pdvobjpriv = adapter_to_dvobj(padapter);
  44. udev = pdvobjpriv->pusbdev;
  45. }
  46. #endif
  47. //DBG_871X("%s %s:%d\n",__FUNCTION__, current->comm, current->pid);
  48. if((padapter->bSurpriseRemoved) ||(padapter->pwrctrlpriv.pnp_bstop_trx)){
  49. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usbctrl_vendorreq:(padapter->bSurpriseRemoved ||adapter->pwrctrlpriv.pnp_bstop_trx)!!!\n"));
  50. status = -EPERM;
  51. goto exit;
  52. }
  53. if(len>MAX_VENDOR_REQ_CMD_SIZE){
  54. DBG_8192C( "[%s] Buffer len error ,vendor request failed\n", __FUNCTION__ );
  55. status = -EINVAL;
  56. goto exit;
  57. }
  58. #ifdef CONFIG_USB_VENDOR_REQ_MUTEX
  59. _enter_critical_mutex(&pdvobjpriv->usb_vendor_req_mutex, NULL);
  60. #endif
  61. // Acquire IO memory for vendorreq
  62. #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
  63. pIo_buf = pdvobjpriv->usb_vendor_req_buf;
  64. #else
  65. #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
  66. tmp_buf = rtw_malloc( (u32) len + ALIGNMENT_UNIT);
  67. tmp_buflen = (u32)len + ALIGNMENT_UNIT;
  68. #else // use stack memory
  69. tmp_buflen = MAX_USB_IO_CTL_SIZE;
  70. #endif
  71. // Added by Albert 2010/02/09
  72. // For mstar platform, mstar suggests the address for USB IO should be 16 bytes alignment.
  73. // Trying to fix it here.
  74. pIo_buf = (tmp_buf==NULL)?NULL:tmp_buf + ALIGNMENT_UNIT -((SIZE_PTR)(tmp_buf) & 0x0f );
  75. #endif
  76. if ( pIo_buf== NULL) {
  77. DBG_8192C( "[%s] pIo_buf == NULL \n", __FUNCTION__ );
  78. status = -ENOMEM;
  79. goto release_mutex;
  80. }
  81. while(++vendorreq_times<= MAX_USBCTRL_VENDORREQ_TIMES)
  82. {
  83. _rtw_memset(pIo_buf, 0, len);
  84. if (requesttype == 0x01)
  85. {
  86. pipe = usb_rcvctrlpipe(udev, 0);//read_in
  87. reqtype = REALTEK_USB_VENQT_READ;
  88. }
  89. else
  90. {
  91. pipe = usb_sndctrlpipe(udev, 0);//write_out
  92. reqtype = REALTEK_USB_VENQT_WRITE;
  93. _rtw_memcpy( pIo_buf, pdata, len);
  94. }
  95. status = rtw_usb_control_msg(udev, pipe, request, reqtype, value, index, pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
  96. if ( status == len) // Success this control transfer.
  97. {
  98. rtw_reset_continual_urb_error(pdvobjpriv);
  99. if ( requesttype == 0x01 )
  100. { // For Control read transfer, we have to copy the read data from pIo_buf to pdata.
  101. _rtw_memcpy( pdata, pIo_buf, len );
  102. }
  103. }
  104. else { // error cases
  105. DBG_8192C("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n"
  106. , value,(requesttype == 0x01)?"read":"write" , len, status, *(u32*)pdata, vendorreq_times);
  107. if (status < 0) {
  108. if(status == (-ESHUTDOWN) || status == -ENODEV )
  109. {
  110. padapter->bSurpriseRemoved = _TRUE;
  111. } else {
  112. #ifdef DBG_CONFIG_ERROR_DETECT
  113. {
  114. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  115. pHalData->srestpriv.Wifi_Error_Status = USB_VEN_REQ_CMD_FAIL;
  116. }
  117. #endif
  118. }
  119. }
  120. else // status != len && status >= 0
  121. {
  122. if(status > 0) {
  123. if ( requesttype == 0x01 )
  124. { // For Control read transfer, we have to copy the read data from pIo_buf to pdata.
  125. _rtw_memcpy( pdata, pIo_buf, len );
  126. }
  127. }
  128. }
  129. if(rtw_inc_and_chk_continual_urb_error(pdvobjpriv) == _TRUE ){
  130. padapter->bSurpriseRemoved = _TRUE;
  131. break;
  132. }
  133. }
  134. // firmware download is checksumed, don't retry
  135. if( (value >= FW_START_ADDRESS ) || status == len )
  136. break;
  137. }
  138. // release IO memory used by vendorreq
  139. #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
  140. rtw_mfree(tmp_buf, tmp_buflen);
  141. #endif
  142. release_mutex:
  143. #ifdef CONFIG_USB_VENDOR_REQ_MUTEX
  144. _exit_critical_mutex(&pdvobjpriv->usb_vendor_req_mutex, NULL);
  145. #endif
  146. exit:
  147. return status;
  148. }
  149. #ifdef CONFIG_USB_SUPPORT_ASYNC_VDN_REQ
  150. static void _usbctrl_vendorreq_async_callback(struct urb *urb, struct pt_regs *regs)
  151. {
  152. if (urb) {
  153. if (urb->context) {
  154. kfree(urb->context);
  155. }
  156. usb_free_urb(urb);
  157. }
  158. }
  159. static int _usbctrl_vendorreq_async_write(struct usb_device *udev, u8 request,
  160. u16 value, u16 index, void *pdata, u16 len, u8 requesttype)
  161. {
  162. int rc;
  163. unsigned int pipe;
  164. u8 reqtype;
  165. struct usb_ctrlrequest *dr;
  166. struct urb *urb;
  167. struct rtl819x_async_write_data {
  168. u8 data[VENDOR_CMD_MAX_DATA_LEN];
  169. struct usb_ctrlrequest dr;
  170. } *buf;
  171. if (requesttype == VENDOR_READ) {
  172. pipe = usb_rcvctrlpipe(udev, 0);//read_in
  173. reqtype = REALTEK_USB_VENQT_READ;
  174. }
  175. else {
  176. pipe = usb_sndctrlpipe(udev, 0);//write_out
  177. reqtype = REALTEK_USB_VENQT_WRITE;
  178. }
  179. buf = (struct rtl819x_async_write_data *)rtw_zmalloc(sizeof(*buf));
  180. if (!buf) {
  181. rc = -ENOMEM;
  182. goto exit;
  183. }
  184. urb = usb_alloc_urb(0, GFP_ATOMIC);
  185. if (!urb) {
  186. rtw_mfree((u8*)buf, sizeof(*buf));
  187. rc = -ENOMEM;
  188. goto exit;
  189. }
  190. dr = &buf->dr;
  191. dr->bRequestType = reqtype;
  192. dr->bRequest = request;
  193. dr->wValue = cpu_to_le16(value);
  194. dr->wIndex = cpu_to_le16(index);
  195. dr->wLength = cpu_to_le16(len);
  196. _rtw_memcpy(buf, pdata, len);
  197. usb_fill_control_urb(urb, udev, pipe, (unsigned char *)dr, buf, len,
  198. _usbctrl_vendorreq_async_callback, buf);
  199. rc = usb_submit_urb(urb, GFP_ATOMIC);
  200. if (rc < 0) {
  201. rtw_mfree((u8*)buf, sizeof(*buf));
  202. usb_free_urb(urb);
  203. }
  204. exit:
  205. return rc;
  206. }
  207. int usb_write_async(struct usb_device *udev, u32 addr, void *pdata, u16 len)
  208. {
  209. u8 request;
  210. u8 requesttype;
  211. u16 wvalue;
  212. u16 index;
  213. int ret;
  214. requesttype = VENDOR_WRITE;//write_out
  215. request = REALTEK_USB_VENQT_CMD_REQ;
  216. index = REALTEK_USB_VENQT_CMD_IDX;//n/a
  217. wvalue = (u16)(addr&0x0000ffff);
  218. ret = _usbctrl_vendorreq_async_write(udev, request, wvalue, index, pdata, len, requesttype);
  219. return ret;
  220. }
  221. int usb_async_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
  222. {
  223. u8 data;
  224. int ret;
  225. struct dvobj_priv *pdvobjpriv = (struct dvobj_priv *)pintfhdl->pintf_dev;
  226. struct usb_device *udev=pdvobjpriv->pusbdev;
  227. _func_enter_;
  228. data = val;
  229. ret = usb_write_async(udev, addr, &data, 1);
  230. _func_exit_;
  231. return ret;
  232. }
  233. int usb_async_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
  234. {
  235. u16 data;
  236. int ret;
  237. struct dvobj_priv *pdvobjpriv = (struct dvobj_priv *)pintfhdl->pintf_dev;
  238. struct usb_device *udev=pdvobjpriv->pusbdev;
  239. _func_enter_;
  240. data = val;
  241. ret = usb_write_async(udev, addr, &data, 2);
  242. _func_exit_;
  243. return ret;
  244. }
  245. int usb_async_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
  246. {
  247. u32 data;
  248. int ret;
  249. struct dvobj_priv *pdvobjpriv = (struct dvobj_priv *)pintfhdl->pintf_dev;
  250. struct usb_device *udev=pdvobjpriv->pusbdev;
  251. _func_enter_;
  252. data = val;
  253. ret = usb_write_async(udev, addr, &data, 4);
  254. _func_exit_;
  255. return ret;
  256. }
  257. #endif /* CONFIG_USB_SUPPORT_ASYNC_VDN_REQ */
  258. unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, u32 addr)
  259. {
  260. unsigned int pipe=0, ep_num=0;
  261. struct usb_device *pusbd = pdvobj->pusbdev;
  262. if (addr == RECV_BULK_IN_ADDR) {
  263. pipe=usb_rcvbulkpipe(pusbd, pdvobj->RtInPipe[0]);
  264. } else if (addr == RECV_INT_IN_ADDR) {
  265. pipe=usb_rcvbulkpipe(pusbd, pdvobj->RtInPipe[1]);
  266. } else if (addr < HW_QUEUE_ENTRY) {
  267. ep_num = pdvobj->Queue2Pipe[addr];
  268. pipe = usb_sndbulkpipe(pusbd, ep_num);
  269. }
  270. return pipe;
  271. }
  272. struct zero_bulkout_context{
  273. void *pbuf;
  274. void *purb;
  275. void *pirp;
  276. void *padapter;
  277. };
  278. static void usb_bulkout_zero_complete(struct urb *purb, struct pt_regs *regs)
  279. {
  280. struct zero_bulkout_context *pcontext = (struct zero_bulkout_context *)purb->context;
  281. //DBG_8192C("+usb_bulkout_zero_complete\n");
  282. if(pcontext)
  283. {
  284. if(pcontext->pbuf)
  285. {
  286. rtw_mfree(pcontext->pbuf, sizeof(int));
  287. }
  288. if(pcontext->purb && (pcontext->purb==purb))
  289. {
  290. usb_free_urb(pcontext->purb);
  291. }
  292. rtw_mfree((u8*)pcontext, sizeof(struct zero_bulkout_context));
  293. }
  294. }
  295. static u32 usb_bulkout_zero(struct intf_hdl *pintfhdl, u32 addr)
  296. {
  297. int pipe, status, len;
  298. u32 ret;
  299. unsigned char *pbuf;
  300. struct zero_bulkout_context *pcontext;
  301. PURB purb = NULL;
  302. _adapter *padapter = (_adapter *)pintfhdl->padapter;
  303. struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
  304. struct usb_device *pusbd = pdvobj->pusbdev;
  305. //DBG_871X("%s\n", __func__);
  306. if((padapter->bDriverStopped) || (padapter->bSurpriseRemoved) ||(padapter->pwrctrlpriv.pnp_bstop_trx))
  307. {
  308. return _FAIL;
  309. }
  310. pcontext = (struct zero_bulkout_context *)rtw_zmalloc(sizeof(struct zero_bulkout_context));
  311. pbuf = (unsigned char *)rtw_zmalloc(sizeof(int));
  312. purb = usb_alloc_urb(0, GFP_ATOMIC);
  313. len = 0;
  314. pcontext->pbuf = pbuf;
  315. pcontext->purb = purb;
  316. pcontext->pirp = NULL;
  317. pcontext->padapter = padapter;
  318. //translate DMA FIFO addr to pipehandle
  319. //pipe = ffaddr2pipehdl(pdvobj, addr);
  320. usb_fill_bulk_urb(purb, pusbd, pipe,
  321. pbuf,
  322. len,
  323. usb_bulkout_zero_complete,
  324. pcontext);//context is pcontext
  325. status = usb_submit_urb(purb, GFP_ATOMIC);
  326. if (!status)
  327. {
  328. ret= _SUCCESS;
  329. }
  330. else
  331. {
  332. ret= _FAIL;
  333. }
  334. return _SUCCESS;
  335. }
  336. void usb_read_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem)
  337. {
  338. }
  339. void usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
  340. {
  341. }
  342. void usb_read_port_cancel(struct intf_hdl *pintfhdl)
  343. {
  344. int i;
  345. struct recv_buf *precvbuf;
  346. _adapter *padapter = pintfhdl->padapter;
  347. precvbuf = (struct recv_buf *)padapter->recvpriv.precv_buf;
  348. DBG_871X("%s\n", __func__);
  349. padapter->bReadPortCancel = _TRUE;
  350. for (i=0; i < NR_RECVBUFF ; i++) {
  351. precvbuf->reuse = _TRUE;
  352. if (precvbuf->purb) {
  353. //DBG_8192C("usb_read_port_cancel : usb_kill_urb \n");
  354. usb_kill_urb(precvbuf->purb);
  355. }
  356. precvbuf++;
  357. }
  358. #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
  359. usb_kill_urb(padapter->recvpriv.int_in_urb);
  360. #endif
  361. }
  362. static void usb_write_port_complete(struct urb *purb, struct pt_regs *regs)
  363. {
  364. _irqL irqL;
  365. int i;
  366. struct xmit_buf *pxmitbuf = (struct xmit_buf *)purb->context;
  367. //struct xmit_frame *pxmitframe = (struct xmit_frame *)pxmitbuf->priv_data;
  368. //_adapter *padapter = pxmitframe->padapter;
  369. _adapter *padapter = pxmitbuf->padapter;
  370. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  371. //struct pkt_attrib *pattrib = &pxmitframe->attrib;
  372. _func_enter_;
  373. switch(pxmitbuf->flags)
  374. {
  375. case VO_QUEUE_INX:
  376. pxmitpriv->voq_cnt--;
  377. break;
  378. case VI_QUEUE_INX:
  379. pxmitpriv->viq_cnt--;
  380. break;
  381. case BE_QUEUE_INX:
  382. pxmitpriv->beq_cnt--;
  383. break;
  384. case BK_QUEUE_INX:
  385. pxmitpriv->bkq_cnt--;
  386. break;
  387. case HIGH_QUEUE_INX:
  388. #ifdef CONFIG_AP_MODE
  389. rtw_chk_hi_queue_cmd(padapter);
  390. #endif
  391. break;
  392. default:
  393. break;
  394. }
  395. /*
  396. _enter_critical(&pxmitpriv->lock, &irqL);
  397. pxmitpriv->txirp_cnt--;
  398. switch(pattrib->priority)
  399. {
  400. case 1:
  401. case 2:
  402. pxmitpriv->bkq_cnt--;
  403. //DBG_8192C("pxmitpriv->bkq_cnt=%d\n", pxmitpriv->bkq_cnt);
  404. break;
  405. case 4:
  406. case 5:
  407. pxmitpriv->viq_cnt--;
  408. //DBG_8192C("pxmitpriv->viq_cnt=%d\n", pxmitpriv->viq_cnt);
  409. break;
  410. case 6:
  411. case 7:
  412. pxmitpriv->voq_cnt--;
  413. //DBG_8192C("pxmitpriv->voq_cnt=%d\n", pxmitpriv->voq_cnt);
  414. break;
  415. case 0:
  416. case 3:
  417. default:
  418. pxmitpriv->beq_cnt--;
  419. //DBG_8192C("pxmitpriv->beq_cnt=%d\n", pxmitpriv->beq_cnt);
  420. break;
  421. }
  422. _exit_critical(&pxmitpriv->lock, &irqL);
  423. if(pxmitpriv->txirp_cnt==0)
  424. {
  425. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_write_port_complete: txirp_cnt== 0, set allrxreturnevt!\n"));
  426. _rtw_up_sema(&(pxmitpriv->tx_retevt));
  427. }
  428. */
  429. //rtw_free_xmitframe(pxmitpriv, pxmitframe);
  430. if(padapter->bSurpriseRemoved || padapter->bDriverStopped ||padapter->bWritePortCancel)
  431. {
  432. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_write_port_complete:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter->bDriverStopped, padapter->bSurpriseRemoved));
  433. DBG_8192C("%s(): TX Warning! bDriverStopped(%d) OR bSurpriseRemoved(%d) bWritePortCancel(%d) pxmitbuf->buf_tag(%x) \n",
  434. __FUNCTION__,padapter->bDriverStopped, padapter->bSurpriseRemoved,padapter->bReadPortCancel,pxmitbuf->buf_tag);
  435. goto check_completion;
  436. }
  437. if (purb->status==0) {
  438. } else {
  439. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_write_port_complete : purb->status(%d) != 0 \n", purb->status));
  440. DBG_871X("###=> urb_write_port_complete status(%d)\n",purb->status);
  441. if((purb->status==-EPIPE)||(purb->status==-EPROTO))
  442. {
  443. //usb_clear_halt(pusbdev, purb->pipe);
  444. //msleep(10);
  445. sreset_set_wifi_error_status(padapter, USB_WRITE_PORT_FAIL);
  446. } else if (purb->status == -EINPROGRESS) {
  447. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_write_port_complete: EINPROGESS\n"));
  448. goto check_completion;
  449. } else if (purb->status == -ENOENT) {
  450. DBG_871X("%s: -ENOENT\n", __func__);
  451. goto check_completion;
  452. } else if (purb->status == -ECONNRESET) {
  453. DBG_871X("%s: -ECONNRESET\n", __func__);
  454. goto check_completion;
  455. } else if (purb->status == -ESHUTDOWN) {
  456. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_write_port_complete: ESHUTDOWN\n"));
  457. padapter->bDriverStopped=_TRUE;
  458. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_write_port_complete:bDriverStopped=TRUE\n"));
  459. goto check_completion;
  460. }
  461. else
  462. {
  463. padapter->bSurpriseRemoved=_TRUE;
  464. DBG_8192C("bSurpriseRemoved=TRUE\n");
  465. //rtl8192cu_trigger_gpio_0(padapter);
  466. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_write_port_complete:bSurpriseRemoved=TRUE\n"));
  467. goto check_completion;
  468. }
  469. }
  470. #ifdef DBG_CONFIG_ERROR_DETECT
  471. {
  472. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  473. pHalData->srestpriv.last_tx_complete_time = rtw_get_current_time();
  474. }
  475. #endif
  476. check_completion:
  477. _enter_critical(&pxmitpriv->lock_sctx, &irqL);
  478. rtw_sctx_done_err(&pxmitbuf->sctx,
  479. purb->status ? RTW_SCTX_DONE_WRITE_PORT_ERR : RTW_SCTX_DONE_SUCCESS);
  480. _exit_critical(&pxmitpriv->lock_sctx, &irqL);
  481. rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
  482. //if(rtw_txframes_pending(padapter))
  483. {
  484. tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
  485. }
  486. _func_exit_;
  487. }
  488. u32 usb_write_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
  489. {
  490. _irqL irqL;
  491. unsigned int pipe;
  492. int status;
  493. u32 ret = _FAIL, bwritezero = _FALSE;
  494. PURB purb = NULL;
  495. _adapter *padapter = (_adapter *)pintfhdl->padapter;
  496. struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
  497. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  498. struct xmit_buf *pxmitbuf = (struct xmit_buf *)wmem;
  499. struct xmit_frame *pxmitframe = (struct xmit_frame *)pxmitbuf->priv_data;
  500. struct usb_device *pusbd = pdvobj->pusbdev;
  501. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  502. _func_enter_;
  503. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("+usb_write_port\n"));
  504. if ((padapter->bDriverStopped) || (padapter->bSurpriseRemoved) ||(padapter->pwrctrlpriv.pnp_bstop_trx)) {
  505. #ifdef DBG_TX
  506. DBG_871X(" DBG_TX %s:%d bDriverStopped%d, bSurpriseRemoved:%d, pnp_bstop_trx:%d\n",__FUNCTION__, __LINE__
  507. ,padapter->bDriverStopped, padapter->bSurpriseRemoved, padapter->pwrctrlpriv.pnp_bstop_trx );
  508. #endif
  509. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_write_port:( padapter->bDriverStopped ||padapter->bSurpriseRemoved ||adapter->pwrctrlpriv.pnp_bstop_trx)!!!\n"));
  510. rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_TX_DENY);
  511. goto exit;
  512. }
  513. _enter_critical(&pxmitpriv->lock, &irqL);
  514. switch(addr)
  515. {
  516. case VO_QUEUE_INX:
  517. pxmitpriv->voq_cnt++;
  518. pxmitbuf->flags = VO_QUEUE_INX;
  519. break;
  520. case VI_QUEUE_INX:
  521. pxmitpriv->viq_cnt++;
  522. pxmitbuf->flags = VI_QUEUE_INX;
  523. break;
  524. case BE_QUEUE_INX:
  525. pxmitpriv->beq_cnt++;
  526. pxmitbuf->flags = BE_QUEUE_INX;
  527. break;
  528. case BK_QUEUE_INX:
  529. pxmitpriv->bkq_cnt++;
  530. pxmitbuf->flags = BK_QUEUE_INX;
  531. break;
  532. case HIGH_QUEUE_INX:
  533. pxmitbuf->flags = HIGH_QUEUE_INX;
  534. break;
  535. default:
  536. pxmitbuf->flags = MGT_QUEUE_INX;
  537. break;
  538. }
  539. _exit_critical(&pxmitpriv->lock, &irqL);
  540. purb = pxmitbuf->pxmit_urb[0];
  541. //translate DMA FIFO addr to pipehandle
  542. pipe = ffaddr2pipehdl(pdvobj, addr);
  543. #ifdef CONFIG_REDUCE_USB_TX_INT
  544. if ( (pxmitpriv->free_xmitbuf_cnt%NR_XMITBUFF == 0)
  545. || (pxmitbuf->buf_tag > XMITBUF_DATA) )
  546. {
  547. purb->transfer_flags &= (~URB_NO_INTERRUPT);
  548. } else {
  549. purb->transfer_flags |= URB_NO_INTERRUPT;
  550. //DBG_8192C("URB_NO_INTERRUPT ");
  551. }
  552. #endif
  553. usb_fill_bulk_urb(purb, pusbd, pipe,
  554. pxmitframe->buf_addr, //= pxmitbuf->pbuf
  555. cnt,
  556. usb_write_port_complete,
  557. pxmitbuf);//context is pxmitbuf
  558. #ifdef CONFIG_USE_USB_BUFFER_ALLOC_TX
  559. purb->transfer_dma = pxmitbuf->dma_transfer_addr;
  560. purb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  561. purb->transfer_flags |= URB_ZERO_PACKET;
  562. #endif // CONFIG_USE_USB_BUFFER_ALLOC_TX
  563. #if 0
  564. if (bwritezero)
  565. {
  566. purb->transfer_flags |= URB_ZERO_PACKET;
  567. }
  568. #endif
  569. status = usb_submit_urb(purb, GFP_ATOMIC);
  570. if (!status) {
  571. #ifdef DBG_CONFIG_ERROR_DETECT
  572. {
  573. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  574. pHalData->srestpriv.last_tx_time = rtw_get_current_time();
  575. }
  576. #endif
  577. } else {
  578. rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_WRITE_PORT_ERR);
  579. DBG_871X("usb_write_port, status=%d\n", status);
  580. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("usb_write_port(): usb_submit_urb, status=%x\n", status));
  581. switch (status) {
  582. case -ENODEV:
  583. padapter->bDriverStopped=_TRUE;
  584. break;
  585. default:
  586. break;
  587. }
  588. goto exit;
  589. }
  590. ret= _SUCCESS;
  591. // Commented by Albert 2009/10/13
  592. // We add the URB_ZERO_PACKET flag to urb so that the host will send the zero packet automatically.
  593. /*
  594. if(bwritezero == _TRUE)
  595. {
  596. usb_bulkout_zero(pintfhdl, addr);
  597. }
  598. */
  599. RT_TRACE(_module_hci_ops_os_c_,_drv_err_,("-usb_write_port\n"));
  600. exit:
  601. if (ret != _SUCCESS)
  602. rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
  603. _func_exit_;
  604. return ret;
  605. }
  606. void usb_write_port_cancel(struct intf_hdl *pintfhdl)
  607. {
  608. int i, j;
  609. _adapter *padapter = pintfhdl->padapter;
  610. struct xmit_buf *pxmitbuf = (struct xmit_buf *)padapter->xmitpriv.pxmitbuf;
  611. DBG_871X("%s \n", __func__);
  612. padapter->bWritePortCancel = _TRUE;
  613. for (i=0; i<NR_XMITBUFF; i++) {
  614. for (j=0; j<8; j++) {
  615. if (pxmitbuf->pxmit_urb[j]) {
  616. usb_kill_urb(pxmitbuf->pxmit_urb[j]);
  617. }
  618. }
  619. pxmitbuf++;
  620. }
  621. pxmitbuf = (struct xmit_buf*)padapter->xmitpriv.pxmit_extbuf;
  622. for (i = 0; i < NR_XMIT_EXTBUFF; i++) {
  623. for (j=0; j<8; j++) {
  624. if(pxmitbuf->pxmit_urb[j]) {
  625. usb_kill_urb(pxmitbuf->pxmit_urb[j]);
  626. }
  627. }
  628. pxmitbuf++;
  629. }
  630. }