1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 ******************************************************************************/
15 #define _HCI_OPS_OS_C_
16
17 #include <osdep_service.h>
18 #include <drv_types.h>
19 #include <osdep_intf.h>
20 #include <usb_ops.h>
21 #include <recv_osdep.h>
22 #include <rtl8723a_hal.h>
23 #include <rtl8723a_recv.h>
24
rtl8723au_read8(struct rtw_adapter * padapter,u16 addr)25 u8 rtl8723au_read8(struct rtw_adapter *padapter, u16 addr)
26 {
27 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
28 struct usb_device *udev = pdvobjpriv->pusbdev;
29 int len;
30 u8 data;
31
32 mutex_lock(&pdvobjpriv->usb_vendor_req_mutex);
33 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
34 REALTEK_USB_VENQT_CMD_REQ, REALTEK_USB_VENQT_READ,
35 addr, 0, &pdvobjpriv->usb_buf.val8, sizeof(data),
36 RTW_USB_CONTROL_MSG_TIMEOUT);
37
38 data = pdvobjpriv->usb_buf.val8;
39 mutex_unlock(&pdvobjpriv->usb_vendor_req_mutex);
40
41 return data;
42 }
43
rtl8723au_read16(struct rtw_adapter * padapter,u16 addr)44 u16 rtl8723au_read16(struct rtw_adapter *padapter, u16 addr)
45 {
46 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
47 struct usb_device *udev = pdvobjpriv->pusbdev;
48 int len;
49 u16 data;
50
51 mutex_lock(&pdvobjpriv->usb_vendor_req_mutex);
52 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
53 REALTEK_USB_VENQT_CMD_REQ, REALTEK_USB_VENQT_READ,
54 addr, 0, &pdvobjpriv->usb_buf.val16, sizeof(data),
55 RTW_USB_CONTROL_MSG_TIMEOUT);
56
57 data = le16_to_cpu(pdvobjpriv->usb_buf.val16);
58 mutex_unlock(&pdvobjpriv->usb_vendor_req_mutex);
59
60 return data;
61 }
62
rtl8723au_read32(struct rtw_adapter * padapter,u16 addr)63 u32 rtl8723au_read32(struct rtw_adapter *padapter, u16 addr)
64 {
65 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
66 struct usb_device *udev = pdvobjpriv->pusbdev;
67 int len;
68 u32 data;
69
70 mutex_lock(&pdvobjpriv->usb_vendor_req_mutex);
71 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
72 REALTEK_USB_VENQT_CMD_REQ, REALTEK_USB_VENQT_READ,
73 addr, 0, &pdvobjpriv->usb_buf.val32, sizeof(data),
74 RTW_USB_CONTROL_MSG_TIMEOUT);
75
76 data = le32_to_cpu(pdvobjpriv->usb_buf.val32);
77 mutex_unlock(&pdvobjpriv->usb_vendor_req_mutex);
78
79 return data;
80 }
81
rtl8723au_write8(struct rtw_adapter * padapter,u16 addr,u8 val)82 int rtl8723au_write8(struct rtw_adapter *padapter, u16 addr, u8 val)
83 {
84 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
85 struct usb_device *udev = pdvobjpriv->pusbdev;
86 int ret;
87
88 mutex_lock(&pdvobjpriv->usb_vendor_req_mutex);
89 pdvobjpriv->usb_buf.val8 = val;
90
91 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
92 REALTEK_USB_VENQT_CMD_REQ,
93 REALTEK_USB_VENQT_WRITE,
94 addr, 0, &pdvobjpriv->usb_buf.val8, sizeof(val),
95 RTW_USB_CONTROL_MSG_TIMEOUT);
96
97 if (ret != sizeof(val))
98 ret = _FAIL;
99 else
100 ret = _SUCCESS;
101
102 mutex_unlock(&pdvobjpriv->usb_vendor_req_mutex);
103 return ret;
104 }
105
rtl8723au_write16(struct rtw_adapter * padapter,u16 addr,u16 val)106 int rtl8723au_write16(struct rtw_adapter *padapter, u16 addr, u16 val)
107 {
108 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
109 struct usb_device *udev = pdvobjpriv->pusbdev;
110 int ret;
111
112 mutex_lock(&pdvobjpriv->usb_vendor_req_mutex);
113 pdvobjpriv->usb_buf.val16 = cpu_to_le16(val);
114
115 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
116 REALTEK_USB_VENQT_CMD_REQ,
117 REALTEK_USB_VENQT_WRITE,
118 addr, 0, &pdvobjpriv->usb_buf.val16, sizeof(val),
119 RTW_USB_CONTROL_MSG_TIMEOUT);
120
121 if (ret != sizeof(val))
122 ret = _FAIL;
123 else
124 ret = _SUCCESS;
125
126 mutex_unlock(&pdvobjpriv->usb_vendor_req_mutex);
127 return ret;
128 }
129
rtl8723au_write32(struct rtw_adapter * padapter,u16 addr,u32 val)130 int rtl8723au_write32(struct rtw_adapter *padapter, u16 addr, u32 val)
131 {
132 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
133 struct usb_device *udev = pdvobjpriv->pusbdev;
134 int ret;
135
136 mutex_lock(&pdvobjpriv->usb_vendor_req_mutex);
137 pdvobjpriv->usb_buf.val32 = cpu_to_le32(val);
138
139 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
140 REALTEK_USB_VENQT_CMD_REQ,
141 REALTEK_USB_VENQT_WRITE,
142 addr, 0, &pdvobjpriv->usb_buf.val32, sizeof(val),
143 RTW_USB_CONTROL_MSG_TIMEOUT);
144
145 if (ret != sizeof(val))
146 ret = _FAIL;
147 else
148 ret = _SUCCESS;
149
150 mutex_unlock(&pdvobjpriv->usb_vendor_req_mutex);
151 return ret;
152 }
153
rtl8723au_writeN(struct rtw_adapter * padapter,u16 addr,u16 len,u8 * buf)154 int rtl8723au_writeN(struct rtw_adapter *padapter, u16 addr, u16 len, u8 *buf)
155 {
156 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
157 struct usb_device *udev = pdvobjpriv->pusbdev;
158 int ret;
159
160 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
161 REALTEK_USB_VENQT_CMD_REQ,
162 REALTEK_USB_VENQT_WRITE,
163 addr, 0, buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
164
165 if (ret != len)
166 return _FAIL;
167 return _SUCCESS;
168 }
169
170 /*
171 * Description:
172 * Recognize the interrupt content by reading the interrupt
173 * register or content and masking interrupt mask (IMR)
174 * if it is our NIC's interrupt. After recognizing, we may clear
175 * the all interrupts (ISR).
176 * Arguments:
177 * [in] Adapter -
178 * The adapter context.
179 * [in] pContent -
180 * Under PCI interface, this field is ignord.
181 * Under USB interface, the content is the interrupt
182 * content pointer.
183 * Under SDIO interface, this is the interrupt type which
184 * is Local interrupt or system interrupt.
185 * [in] ContentLen -
186 * The length in byte of pContent.
187 * Return:
188 * If any interrupt matches the mask (IMR), return true, and
189 * return false otherwise.
190 */
191 static bool
InterruptRecognized8723AU(struct rtw_adapter * Adapter,void * pContent,u32 ContentLen)192 InterruptRecognized8723AU(struct rtw_adapter *Adapter, void *pContent,
193 u32 ContentLen)
194 {
195 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
196 u8 *buffer = (u8 *)pContent;
197 struct reportpwrstate_parm report;
198
199 memcpy(&pHalData->IntArray[0], &buffer[USB_INTR_CONTENT_HISR_OFFSET],
200 4);
201 pHalData->IntArray[0] &= pHalData->IntrMask[0];
202
203 /* For HISR extension. Added by tynli. 2009.10.07. */
204 memcpy(&pHalData->IntArray[1],
205 &buffer[USB_INTR_CONTENT_HISRE_OFFSET], 4);
206 pHalData->IntArray[1] &= pHalData->IntrMask[1];
207
208 /* We sholud remove this function later because DDK suggest
209 * not to executing too many operations in MPISR */
210
211 memcpy(&report.state, &buffer[USB_INTR_CPWM_OFFSET], 1);
212
213 return (pHalData->IntArray[0] & pHalData->IntrMask[0]) != 0 ||
214 (pHalData->IntArray[1] & pHalData->IntrMask[1]) != 0;
215 }
216
usb_read_interrupt_complete(struct urb * purb)217 static void usb_read_interrupt_complete(struct urb *purb)
218 {
219 int err;
220 struct rtw_adapter *padapter = (struct rtw_adapter *)purb->context;
221
222 if (padapter->bSurpriseRemoved || padapter->bDriverStopped ||
223 padapter->bReadPortCancel) {
224 DBG_8723A("%s() RX Warning! bDriverStopped(%d) OR "
225 "bSurpriseRemoved(%d) bReadPortCancel(%d)\n",
226 __func__, padapter->bDriverStopped,
227 padapter->bSurpriseRemoved,
228 padapter->bReadPortCancel);
229 return;
230 }
231
232 if (purb->status == 0) {
233 struct c2h_evt_hdr *c2h_evt;
234
235 c2h_evt = (struct c2h_evt_hdr *)purb->transfer_buffer;
236
237 if (purb->actual_length > USB_INTR_CONTENT_LENGTH) {
238 DBG_8723A("usb_read_interrupt_complete: purb->actual_"
239 "length > USB_INTR_CONTENT_LENGTH\n");
240 goto urb_submit;
241 }
242
243 InterruptRecognized8723AU(padapter, purb->transfer_buffer,
244 purb->actual_length);
245
246 if (c2h_evt_exist(c2h_evt)) {
247 if (c2h_id_filter_ccx_8723a(c2h_evt->id)) {
248 /* Handle CCX report here */
249 handle_txrpt_ccx_8723a(padapter, (void *)
250 c2h_evt->payload);
251 schedule_work(&padapter->evtpriv.irq_wk);
252 } else {
253 struct evt_work *c2w;
254 int res;
255
256 c2w = kmalloc(sizeof(struct evt_work),
257 GFP_ATOMIC);
258
259 if (!c2w) {
260 printk(KERN_WARNING "%s: unable to "
261 "allocate work buffer\n",
262 __func__);
263 goto urb_submit;
264 }
265
266 c2w->adapter = padapter;
267 INIT_WORK(&c2w->work, rtw_evt_work);
268 memcpy(c2w->u.buf, purb->transfer_buffer, 16);
269
270 res = queue_work(padapter->evtpriv.wq,
271 &c2w->work);
272
273 if (!res) {
274 printk(KERN_ERR "%s: Call to "
275 "queue_work() failed\n",
276 __func__);
277 kfree(c2w);
278 goto urb_submit;
279 }
280 }
281 }
282
283 urb_submit:
284 err = usb_submit_urb(purb, GFP_ATOMIC);
285 if (err && (err != -EPERM)) {
286 DBG_8723A("cannot submit interrupt in-token(err = "
287 "0x%08x), urb_status = %d\n",
288 err, purb->status);
289 }
290 } else {
291 DBG_8723A("###=> usb_read_interrupt_complete => urb "
292 "status(%d)\n", purb->status);
293
294 switch (purb->status) {
295 case -EINVAL:
296 case -EPIPE:
297 case -ENODEV:
298 case -ESHUTDOWN:
299 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
300 ("usb_read_port_complete:bSurpriseRemoved ="
301 "true\n"));
302 /* Fall Through here */
303 case -ENOENT:
304 padapter->bDriverStopped = true;
305 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
306 ("usb_read_port_complete:bDriverStopped ="
307 "true\n"));
308 break;
309 case -EPROTO:
310 break;
311 case -EINPROGRESS:
312 DBG_8723A("ERROR: URB IS IN PROGRESS!\n");
313 break;
314 default:
315 break;
316 }
317 }
318 }
319
rtl8723au_read_interrupt(struct rtw_adapter * adapter,u32 addr)320 int rtl8723au_read_interrupt(struct rtw_adapter *adapter, u32 addr)
321 {
322 int err;
323 unsigned int pipe;
324 int ret = _SUCCESS;
325 struct dvobj_priv *pdvobj = adapter_to_dvobj(adapter);
326 struct recv_priv *precvpriv = &adapter->recvpriv;
327 struct usb_device *pusbd = pdvobj->pusbdev;
328
329 /* translate DMA FIFO addr to pipehandle */
330 pipe = usb_rcvintpipe(pusbd, pdvobj->RtInPipe[1]);
331
332 usb_fill_int_urb(precvpriv->int_in_urb, pusbd, pipe,
333 precvpriv->int_in_buf, USB_INTR_CONTENT_LENGTH,
334 usb_read_interrupt_complete, adapter, 1);
335
336 err = usb_submit_urb(precvpriv->int_in_urb, GFP_ATOMIC);
337 if (err && (err != -EPERM)) {
338 DBG_8723A("cannot submit interrupt in-token(err = 0x%08x),"
339 "urb_status = %d\n", err,
340 precvpriv->int_in_urb->status);
341 ret = _FAIL;
342 }
343
344 return ret;
345 }
346
recvbuf2recvframe(struct rtw_adapter * padapter,struct sk_buff * pskb)347 static int recvbuf2recvframe(struct rtw_adapter *padapter, struct sk_buff *pskb)
348 {
349 u8 *pbuf;
350 u8 shift_sz = 0;
351 u16 pkt_cnt;
352 u32 pkt_offset, skb_len, alloc_sz;
353 int transfer_len;
354 struct recv_stat *prxstat;
355 struct phy_stat *pphy_info;
356 struct sk_buff *pkt_copy;
357 struct recv_frame *precvframe;
358 struct rx_pkt_attrib *pattrib;
359 struct recv_priv *precvpriv = &padapter->recvpriv;
360 struct rtw_queue *pfree_recv_queue = &precvpriv->free_recv_queue;
361
362 transfer_len = (int)pskb->len;
363 pbuf = pskb->data;
364
365 prxstat = (struct recv_stat *)pbuf;
366 pkt_cnt = (le32_to_cpu(prxstat->rxdw2) >> 16) & 0xff;
367
368 do {
369 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
370 ("recvbuf2recvframe: rxdesc = offsset 0:0x%08x, "
371 "4:0x%08x, 8:0x%08x, C:0x%08x\n", prxstat->rxdw0,
372 prxstat->rxdw1, prxstat->rxdw2, prxstat->rxdw4));
373
374 prxstat = (struct recv_stat *)pbuf;
375
376 precvframe = rtw_alloc_recvframe23a(pfree_recv_queue);
377 if (!precvframe) {
378 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
379 ("recvbuf2recvframe: precvframe == NULL\n"));
380 DBG_8723A("%s()-%d: rtw_alloc_recvframe23a() failed! RX "
381 "Drop!\n", __func__, __LINE__);
382 goto _exit_recvbuf2recvframe;
383 }
384
385 INIT_LIST_HEAD(&precvframe->list);
386
387 update_recvframe_attrib(precvframe, prxstat);
388
389 pattrib = &precvframe->attrib;
390
391 if (pattrib->crc_err) {
392 DBG_8723A("%s()-%d: RX Warning! rx CRC ERROR !!\n",
393 __func__, __LINE__);
394 rtw_free_recvframe23a(precvframe);
395 goto _exit_recvbuf2recvframe;
396 }
397
398 pkt_offset = RXDESC_SIZE + pattrib->drvinfo_sz +
399 pattrib->shift_sz + pattrib->pkt_len;
400
401 if (pattrib->pkt_len <= 0 || pkt_offset > transfer_len) {
402 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
403 ("recvbuf2recvframe: pkt_len<= 0\n"));
404 DBG_8723A("%s()-%d: RX Warning!\n",
405 __func__, __LINE__);
406 rtw_free_recvframe23a(precvframe);
407 goto _exit_recvbuf2recvframe;
408 }
409
410 /* Modified by Albert 20101213 */
411 /* For 8 bytes IP header alignment. */
412 /* Qos data, wireless lan header length is 26 */
413 if (pattrib->qos)
414 shift_sz = 6;
415 else
416 shift_sz = 0;
417
418 skb_len = pattrib->pkt_len;
419
420 /* for first fragment packet, driver need allocate
421 * 1536+drvinfo_sz+RXDESC_SIZE to defrag packet.
422 * modify alloc_sz for recvive crc error packet
423 * by thomas 2011-06-02 */
424 if (pattrib->mfrag == 1 && pattrib->frag_num == 0) {
425 /* alloc_sz = 1664; 1664 is 128 alignment. */
426 if (skb_len <= 1650)
427 alloc_sz = 1664;
428 else
429 alloc_sz = skb_len + 14;
430 } else {
431 alloc_sz = skb_len;
432 /* 6 is for IP header 8 bytes alignment in QoS packet case. */
433 /* 8 is for skb->data 4 bytes alignment. */
434 alloc_sz += 14;
435 }
436
437 pkt_copy = netdev_alloc_skb(padapter->pnetdev, alloc_sz);
438 if (pkt_copy) {
439 pkt_copy->dev = padapter->pnetdev;
440 precvframe->pkt = pkt_copy;
441 /* force pkt_copy->data at 8-byte alignment address */
442 skb_reserve(pkt_copy, 8 -
443 ((unsigned long)(pkt_copy->data) & 7));
444 /*force ip_hdr at 8-byte alignment address
445 according to shift_sz. */
446 skb_reserve(pkt_copy, shift_sz);
447 memcpy(pkt_copy->data, pbuf + pattrib->shift_sz +
448 pattrib->drvinfo_sz + RXDESC_SIZE, skb_len);
449 skb_put(pkt_copy, skb_len);
450 } else {
451 if (pattrib->mfrag == 1 && pattrib->frag_num == 0) {
452 DBG_8723A("recvbuf2recvframe: alloc_skb fail, "
453 "drop frag frame \n");
454 rtw_free_recvframe23a(precvframe);
455 goto _exit_recvbuf2recvframe;
456 }
457
458 precvframe->pkt = skb_clone(pskb, GFP_ATOMIC);
459 if (!precvframe->pkt) {
460 DBG_8723A("recvbuf2recvframe: skb_clone "
461 "fail\n");
462 rtw_free_recvframe23a(precvframe);
463 goto _exit_recvbuf2recvframe;
464 }
465 }
466
467 if (pattrib->physt) {
468 pphy_info = (struct phy_stat *)(pbuf + RXDESC_OFFSET);
469 update_recvframe_phyinfo(precvframe, pphy_info);
470 }
471
472 if (rtw_recv_entry23a(precvframe) != _SUCCESS)
473 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
474 ("recvbuf2recvframe: rtw_recv_entry23a"
475 "(precvframe) != _SUCCESS\n"));
476
477 pkt_cnt--;
478 transfer_len -= pkt_offset;
479 pbuf += pkt_offset;
480 precvframe = NULL;
481 pkt_copy = NULL;
482
483 if (transfer_len > 0 && pkt_cnt == 0)
484 pkt_cnt = (le32_to_cpu(prxstat->rxdw2)>>16) & 0xff;
485
486 } while (transfer_len > 0 && pkt_cnt > 0);
487
488 _exit_recvbuf2recvframe:
489
490 return _SUCCESS;
491 }
492
rtl8723au_recv_tasklet(void * priv)493 void rtl8723au_recv_tasklet(void *priv)
494 {
495 struct sk_buff *pskb;
496 struct rtw_adapter *padapter = (struct rtw_adapter *)priv;
497 struct recv_priv *precvpriv = &padapter->recvpriv;
498
499 while (NULL != (pskb = skb_dequeue(&precvpriv->rx_skb_queue))) {
500 if (padapter->bDriverStopped || padapter->bSurpriseRemoved) {
501 DBG_8723A("recv_tasklet => bDriverStopped or "
502 "bSurpriseRemoved \n");
503 dev_kfree_skb_any(pskb);
504 break;
505 }
506
507 recvbuf2recvframe(padapter, pskb);
508 skb_reset_tail_pointer(pskb);
509
510 pskb->len = 0;
511
512 skb_queue_tail(&precvpriv->free_recv_skb_queue, pskb);
513 }
514 }
515
usb_read_port_complete(struct urb * purb)516 static void usb_read_port_complete(struct urb *purb)
517 {
518 struct recv_buf *precvbuf = (struct recv_buf *)purb->context;
519 struct rtw_adapter *padapter = (struct rtw_adapter *)precvbuf->adapter;
520 struct recv_priv *precvpriv = &padapter->recvpriv;
521
522 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
523 ("usb_read_port_complete!!!\n"));
524
525 precvpriv->rx_pending_cnt--;
526
527 if (padapter->bSurpriseRemoved || padapter->bDriverStopped ||
528 padapter->bReadPortCancel) {
529 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
530 ("usb_read_port_complete:bDriverStopped(%d) OR "
531 "bSurpriseRemoved(%d)\n", padapter->bDriverStopped,
532 padapter->bSurpriseRemoved));
533
534 DBG_8723A("%s()-%d: RX Warning! bDriverStopped(%d) OR "
535 "bSurpriseRemoved(%d) bReadPortCancel(%d)\n",
536 __func__, __LINE__, padapter->bDriverStopped,
537 padapter->bSurpriseRemoved, padapter->bReadPortCancel);
538 return;
539 }
540
541 if (purb->status == 0) {
542 if (purb->actual_length > MAX_RECVBUF_SZ ||
543 purb->actual_length < RXDESC_SIZE) {
544 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
545 ("usb_read_port_complete: (purb->actual_"
546 "length > MAX_RECVBUF_SZ) || (purb->actual_"
547 "length < RXDESC_SIZE)\n"));
548 rtl8723au_read_port(padapter, RECV_BULK_IN_ADDR, 0,
549 precvbuf);
550 DBG_8723A("%s()-%d: RX Warning!\n",
551 __func__, __LINE__);
552 } else {
553 rtw_reset_continual_urb_error(
554 adapter_to_dvobj(padapter));
555
556 skb_put(precvbuf->pskb, purb->actual_length);
557 skb_queue_tail(&precvpriv->rx_skb_queue,
558 precvbuf->pskb);
559
560 if (skb_queue_len(&precvpriv->rx_skb_queue) <= 1)
561 tasklet_schedule(&precvpriv->recv_tasklet);
562
563 precvbuf->pskb = NULL;
564 rtl8723au_read_port(padapter, RECV_BULK_IN_ADDR, 0,
565 precvbuf);
566 }
567 } else {
568 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
569 ("usb_read_port_complete : purb->status(%d) != 0 \n",
570 purb->status));
571 skb_put(precvbuf->pskb, purb->actual_length);
572 precvbuf->pskb = NULL;
573
574 DBG_8723A("###=> usb_read_port_complete => urb status(%d)\n",
575 purb->status);
576
577 if (rtw_inc_and_chk_continual_urb_error(
578 adapter_to_dvobj(padapter))) {
579 padapter->bSurpriseRemoved = true;
580 }
581
582 switch (purb->status) {
583 case -EINVAL:
584 case -EPIPE:
585 case -ENODEV:
586 case -ESHUTDOWN:
587 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
588 ("usb_read_port_complete:bSurprise"
589 "Removed = true\n"));
590 /* Intentional fall through here */
591 case -ENOENT:
592 padapter->bDriverStopped = true;
593 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
594 ("usb_read_port_complete:"
595 "bDriverStopped = true\n"));
596 break;
597 case -EPROTO:
598 case -EOVERFLOW:
599 rtl8723au_read_port(padapter, RECV_BULK_IN_ADDR, 0,
600 precvbuf);
601 break;
602 case -EINPROGRESS:
603 DBG_8723A("ERROR: URB IS IN PROGRESS!\n");
604 break;
605 default:
606 break;
607 }
608 }
609 }
610
rtl8723au_read_port(struct rtw_adapter * adapter,u32 addr,u32 cnt,struct recv_buf * precvbuf)611 int rtl8723au_read_port(struct rtw_adapter *adapter, u32 addr, u32 cnt,
612 struct recv_buf *precvbuf)
613 {
614 int err;
615 unsigned int pipe;
616 unsigned long tmpaddr;
617 unsigned long alignment;
618 int ret = _SUCCESS;
619 struct urb *purb;
620 struct dvobj_priv *pdvobj = adapter_to_dvobj(adapter);
621 struct recv_priv *precvpriv = &adapter->recvpriv;
622 struct usb_device *pusbd = pdvobj->pusbdev;
623
624 if (adapter->bDriverStopped || adapter->bSurpriseRemoved) {
625 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
626 ("usb_read_port:(padapter->bDriverStopped ||"
627 "padapter->bSurpriseRemoved)!!!\n"));
628 return _FAIL;
629 }
630
631 if (!precvbuf) {
632 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
633 ("usb_read_port:precvbuf == NULL\n"));
634 return _FAIL;
635 }
636
637 if (!precvbuf->pskb)
638 precvbuf->pskb = skb_dequeue(&precvpriv->free_recv_skb_queue);
639
640 /* re-assign for linux based on skb */
641 if (!precvbuf->pskb) {
642 precvbuf->pskb = netdev_alloc_skb(adapter->pnetdev, MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ);
643 if (precvbuf->pskb == NULL) {
644 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("init_recvbuf(): alloc_skb fail!\n"));
645 return _FAIL;
646 }
647
648 tmpaddr = (unsigned long)precvbuf->pskb->data;
649 alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1);
650 skb_reserve(precvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
651 }
652
653 precvpriv->rx_pending_cnt++;
654
655 purb = precvbuf->purb;
656
657 /* translate DMA FIFO addr to pipehandle */
658 pipe = usb_rcvbulkpipe(pusbd, pdvobj->RtInPipe[0]);
659
660 usb_fill_bulk_urb(purb, pusbd, pipe, precvbuf->pskb->data,
661 MAX_RECVBUF_SZ, usb_read_port_complete,
662 precvbuf);/* context is precvbuf */
663
664 err = usb_submit_urb(purb, GFP_ATOMIC);
665 if ((err) && (err != -EPERM)) {
666 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
667 ("cannot submit rx in-token(err = 0x%.8x), URB_STATUS "
668 "= 0x%.8x", err, purb->status));
669 DBG_8723A("cannot submit rx in-token(err = 0x%08x), urb_status "
670 "= %d\n", err, purb->status);
671 ret = _FAIL;
672 }
673 return ret;
674 }
675
rtl8723au_xmit_tasklet(void * priv)676 void rtl8723au_xmit_tasklet(void *priv)
677 {
678 int ret;
679 struct rtw_adapter *padapter = (struct rtw_adapter *)priv;
680 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
681
682 if (check_fwstate(&padapter->mlmepriv, _FW_UNDER_SURVEY))
683 return;
684
685 while (1) {
686 if (padapter->bDriverStopped || padapter->bSurpriseRemoved ||
687 padapter->bWritePortCancel) {
688 DBG_8723A("xmit_tasklet => bDriverStopped or "
689 "bSurpriseRemoved or bWritePortCancel\n");
690 break;
691 }
692
693 ret = rtl8723au_xmitframe_complete(padapter, pxmitpriv, NULL);
694
695 if (!ret)
696 break;
697 }
698 }
699
rtl8723au_set_hw_type(struct rtw_adapter * padapter)700 void rtl8723au_set_hw_type(struct rtw_adapter *padapter)
701 {
702 padapter->chip_type = RTL8723A;
703 padapter->HardwareType = HARDWARE_TYPE_RTL8723AU;
704 DBG_8723A("CHIP TYPE: RTL8723A\n");
705 }
706