xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8188fu/hal/rtl8188f/usb/usb_ops.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017 Realtek Corporation.
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 _USB_OPS_C_
16 
17 #include <rtl8188f_hal.h>
18 
19 #ifdef CONFIG_SUPPORT_USB_INT
interrupt_handler_8188fu(_adapter * padapter,u16 pkt_len,u8 * pbuf)20 void interrupt_handler_8188fu(_adapter *padapter, u16 pkt_len, u8 *pbuf)
21 {
22 	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(padapter);
23 	struct reportpwrstate_parm pwr_rpt;
24 
25 	if (pkt_len != INTERRUPT_MSG_FORMAT_LEN) {
26 		RTW_INFO("%s Invalid interrupt content length (%d)!\n", __func__, pkt_len);
27 		return;
28 	}
29 
30 	/* HISR */
31 	_rtw_memcpy(&(pHalData->IntArray[0]), &(pbuf[USB_INTR_CONTENT_HISR_OFFSET]), 4);
32 	_rtw_memcpy(&(pHalData->IntArray[1]), &(pbuf[USB_INTR_CONTENT_HISRE_OFFSET]), 4);
33 
34 #if 0 /*DBG */
35 	{
36 		u32 hisr = 0 , hisr_ex = 0;
37 
38 		_rtw_memcpy(&hisr, &(pHalData->IntArray[0]), 4);
39 		hisr = le32_to_cpu(hisr);
40 
41 		_rtw_memcpy(&hisr_ex, &(pHalData->IntArray[1]), 4);
42 		hisr_ex = le32_to_cpu(hisr_ex);
43 
44 		if ((hisr != 0) || (hisr_ex != 0))
45 			RTW_INFO("===> %s hisr:0x%08x ,hisr_ex:0x%08x\n", __func__, hisr, hisr_ex);
46 	}
47 #endif
48 
49 
50 #ifdef CONFIG_LPS_LCLK
51 	if (pHalData->IntArray[0]  & IMR_CPWM_88E) {
52 		_rtw_memcpy(&pwr_rpt.state, &(pbuf[USB_INTR_CONTENT_CPWM1_OFFSET]), 1);
53 		/*_rtw_memcpy(&pwr_rpt.state2, &(pbuf[USB_INTR_CONTENT_CPWM2_OFFSET]), 1); */
54 
55 		/*88e's cpwm value only change BIT0, so driver need to add PS_STATE_S2 for LPS flow. */
56 		pwr_rpt.state |= PS_STATE_S2;
57 		_set_workitem(&(adapter_to_pwrctl(padapter)->cpwm_event));
58 	}
59 #endif/*CONFIG_LPS_LCLK */
60 
61 #ifdef CONFIG_INTERRUPT_BASED_TXBCN
62 #ifdef CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
63 	if (pHalData->IntArray[0] & IMR_BCNDMAINT0_8188F)/*only for BCN_0*/
64 		/* suspect code indent for conditional statements */
65 #endif
66 #ifdef CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
67 		if (pHalData->IntArray[0] & (IMR_TBDER_88E | IMR_TBDOK_88E))
68 			/* suspect code indent for conditional statements */
69 #endif
70 		{
71 #if 0
72 			if (pHalData->IntArray[0] & IMR_BCNDMAINT0_88E)
73 				RTW_INFO("%s: HISR_BCNERLY_INT\n", __func__);
74 			if (pHalData->IntArray[0] & IMR_TBDOK_88E)
75 				RTW_INFO("%s: HISR_TXBCNOK\n", __func__);
76 			if (pHalData->IntArray[0] & IMR_TBDER_88E)
77 				RTW_INFO("%s: HISR_TXBCNERR\n", __func__);
78 #endif
79 			rtw_mi_set_tx_beacon_cmd(padapter);
80 		}
81 #endif /*CONFIG_INTERRUPT_BASED_TXBCN */
82 
83 
84 
85 
86 #ifdef DBG_CONFIG_ERROR_DETECT_INT
87 	if (pHalData->IntArray[1]  & IMR_TXERR_8188F)
88 		RTW_INFO("===> %s Tx Error Flag Interrupt Status\n", __func__);
89 	if (pHalData->IntArray[1]  & IMR_RXERR_8188F)
90 		RTW_INFO("===> %s Rx Error Flag INT Status\n", __func__);
91 	if (pHalData->IntArray[1]  & IMR_TXFOVW_8188F)
92 		RTW_INFO("===> %s Transmit FIFO Overflow\n", __func__);
93 	if (pHalData->IntArray[1]  & IMR_RXFOVW_8188F)
94 		RTW_INFO("===> %s Receive FIFO Overflow\n", __func__);
95 #endif/*DBG_CONFIG_ERROR_DETECT_INT */
96 
97 #ifdef CONFIG_FW_C2H_REG
98 	/* C2H Event */
99 	if (pbuf[0] != 0)
100 		usb_c2h_hisr_hdl(padapter, pbuf);
101 #endif
102 }
103 #endif
104 
recvbuf2recvframe(PADAPTER padapter,void * ptr)105 int recvbuf2recvframe(PADAPTER padapter, void *ptr)
106 {
107 	u8 *pbuf;
108 	u8 pkt_cnt = 0;
109 	u32 pkt_offset;
110 	s32 transfer_len;
111 	u8 *pdata;
112 	union recv_frame *precvframe = NULL;
113 	struct rx_pkt_attrib *pattrib = NULL;
114 	PHAL_DATA_TYPE pHalData;
115 	struct recv_priv *precvpriv;
116 	_queue *pfree_recv_queue;
117 	_pkt *pskb;
118 
119 
120 	pHalData = GET_HAL_DATA(padapter);
121 	precvpriv = &padapter->recvpriv;
122 	pfree_recv_queue = &precvpriv->free_recv_queue;
123 
124 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
125 	pskb = NULL;
126 	transfer_len = (s32)((struct recv_buf *)ptr)->transfer_len;
127 	pbuf = ((struct recv_buf *)ptr)->pbuf;
128 #else /* !CONFIG_USE_USB_BUFFER_ALLOC_RX */
129 	pskb = (_pkt *)ptr;
130 	transfer_len = (s32)pskb->len;
131 	pbuf = pskb->data;
132 #endif /* !CONFIG_USE_USB_BUFFER_ALLOC_RX */
133 
134 #ifdef CONFIG_USB_RX_AGGREGATION
135 	pkt_cnt = GET_RX_STATUS_DESC_USB_AGG_PKTNUM_8188F(pbuf);
136 #endif
137 
138 	do {
139 		precvframe = rtw_alloc_recvframe(pfree_recv_queue);
140 		if (precvframe == NULL) {
141 			RTW_INFO("%s: rtw_alloc_recvframe() failed! RX Drop!\n", __func__);
142 			goto _exit_recvbuf2recvframe;
143 		}
144 
145 		if (transfer_len > 1500)
146 			_rtw_init_listhead(&precvframe->u.hdr.list);
147 		precvframe->u.hdr.precvbuf = NULL;	/*can't access the precvbuf for new arch. */
148 		precvframe->u.hdr.len = 0;
149 
150 		rtl8188f_query_rx_desc_status(precvframe, pbuf);
151 
152 		pattrib = &precvframe->u.hdr.attrib;
153 
154 		if ((padapter->registrypriv.mp_mode == 0)
155 		    && ((pattrib->crc_err) || (pattrib->icv_err))) {
156 			RTW_INFO("%s: RX Warning! crc_err=%d icv_err=%d, skip!\n",
157 				 __func__, pattrib->crc_err, pattrib->icv_err);
158 
159 			rtw_free_recvframe(precvframe, pfree_recv_queue);
160 			goto _exit_recvbuf2recvframe;
161 		}
162 
163 		pkt_offset = RXDESC_SIZE + pattrib->drvinfo_sz + pattrib->shift_sz + pattrib->pkt_len;
164 		if ((pattrib->pkt_len <= 0) || (pkt_offset > transfer_len)) {
165 			RTW_INFO("%s: RX Error! pkt_len=%d pkt_offset=%d transfer_len=%d\n",
166 				__func__, pattrib->pkt_len, pkt_offset, transfer_len);
167 
168 			rtw_free_recvframe(precvframe, pfree_recv_queue);
169 			goto _exit_recvbuf2recvframe;
170 		}
171 
172 #ifdef CONFIG_RX_PACKET_APPEND_FCS
173 		if (check_fwstate(&padapter->mlmepriv, WIFI_MONITOR_STATE) == _FALSE)
174 			if ((pattrib->pkt_rpt_type == NORMAL_RX) && rtw_hal_rcr_check(padapter, RCR_APPFCS))
175 				pattrib->pkt_len -= IEEE80211_FCS_LEN;
176 #endif
177 
178 		pdata = pbuf + RXDESC_SIZE + pattrib->drvinfo_sz + pattrib->shift_sz;
179 		if (rtw_os_alloc_recvframe(padapter, precvframe, pdata, pskb) == _FAIL) {
180 			RTW_INFO("%s: RX Error! rtw_os_alloc_recvframe FAIL!\n", __func__);
181 
182 			rtw_free_recvframe(precvframe, pfree_recv_queue);
183 			goto _exit_recvbuf2recvframe;
184 		}
185 
186 		recvframe_put(precvframe, pattrib->pkt_len);
187 
188 		if (pattrib->pkt_rpt_type == NORMAL_RX)
189 			pre_recv_entry(precvframe, pattrib->physt ? (pbuf + RXDESC_OFFSET) : NULL);
190 		else {
191 #ifdef CONFIG_FW_C2H_PKT
192 			if (pattrib->pkt_rpt_type == C2H_PACKET)
193 				rtw_hal_c2h_pkt_pre_hdl(padapter, precvframe->u.hdr.rx_data, pattrib->pkt_len);
194 			else {
195 				RTW_INFO("%s: [WARNNING] RX type(%d) not be handled!\n",
196 					 __func__, pattrib->pkt_rpt_type);
197 			}
198 #endif /* CONFIG_FW_C2H_PKT */
199 			rtw_free_recvframe(precvframe, pfree_recv_queue);
200 		}
201 
202 #ifdef CONFIG_USB_RX_AGGREGATION
203 		/* jaguar 8-byte alignment */
204 		pkt_offset = (u16)_RND8(pkt_offset);
205 		pkt_cnt--;
206 		pbuf += pkt_offset;
207 #endif
208 		transfer_len -= pkt_offset;
209 		precvframe = NULL;
210 	} while (transfer_len > 0);
211 
212 _exit_recvbuf2recvframe:
213 
214 	return _SUCCESS;
215 }
216 
217 
rtl8188fu_xmit_tasklet(void * priv)218 void rtl8188fu_xmit_tasklet(void *priv)
219 {
220 	int ret = _FALSE;
221 	_adapter *padapter = (_adapter *)priv;
222 	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
223 
224 	while (1) {
225 		if (RTW_CANNOT_TX(padapter)) {
226 			RTW_INFO("xmit_tasklet => bDriverStopped or bSurpriseRemoved or bWritePortCancel\n");
227 			break;
228 		}
229 
230 		if (rtw_xmit_ac_blocked(padapter) == _TRUE)
231 			break;
232 
233 		ret = rtl8188fu_xmitframe_complete(padapter, pxmitpriv, NULL);
234 
235 		if (ret == _FALSE)
236 			break;
237 
238 	}
239 
240 }
241 
rtl8188fu_set_hw_type(struct dvobj_priv * pdvobj)242 void rtl8188fu_set_hw_type(struct dvobj_priv *pdvobj)
243 {
244 	pdvobj->HardwareType = HARDWARE_TYPE_RTL8188FU;
245 	RTW_INFO("CHIP TYPE: RTL8188FU\n");
246 }
247