hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
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
/* SPDX-License-Identifier: GPL-2.0 */
/******************************************************************************
 *
 * Copyright(c) 2007 - 2017 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_C_
 
#include <rtl8188f_hal.h>
 
#ifdef CONFIG_SUPPORT_USB_INT
void interrupt_handler_8188fu(_adapter *padapter, u16 pkt_len, u8 *pbuf)
{
   HAL_DATA_TYPE    *pHalData = GET_HAL_DATA(padapter);
   struct reportpwrstate_parm pwr_rpt;
 
   if (pkt_len != INTERRUPT_MSG_FORMAT_LEN) {
       RTW_INFO("%s Invalid interrupt content length (%d)!\n", __func__, pkt_len);
       return;
   }
 
   /* HISR */
   _rtw_memcpy(&(pHalData->IntArray[0]), &(pbuf[USB_INTR_CONTENT_HISR_OFFSET]), 4);
   _rtw_memcpy(&(pHalData->IntArray[1]), &(pbuf[USB_INTR_CONTENT_HISRE_OFFSET]), 4);
 
#if 0 /*DBG */
   {
       u32 hisr = 0 , hisr_ex = 0;
 
       _rtw_memcpy(&hisr, &(pHalData->IntArray[0]), 4);
       hisr = le32_to_cpu(hisr);
 
       _rtw_memcpy(&hisr_ex, &(pHalData->IntArray[1]), 4);
       hisr_ex = le32_to_cpu(hisr_ex);
 
       if ((hisr != 0) || (hisr_ex != 0))
           RTW_INFO("===> %s hisr:0x%08x ,hisr_ex:0x%08x\n", __func__, hisr, hisr_ex);
   }
#endif
 
 
#ifdef CONFIG_LPS_LCLK
   if (pHalData->IntArray[0]  & IMR_CPWM_88E) {
       _rtw_memcpy(&pwr_rpt.state, &(pbuf[USB_INTR_CONTENT_CPWM1_OFFSET]), 1);
       /*_rtw_memcpy(&pwr_rpt.state2, &(pbuf[USB_INTR_CONTENT_CPWM2_OFFSET]), 1); */
 
       /*88e's cpwm value only change BIT0, so driver need to add PS_STATE_S2 for LPS flow. */
       pwr_rpt.state |= PS_STATE_S2;
       _set_workitem(&(adapter_to_pwrctl(padapter)->cpwm_event));
   }
#endif/*CONFIG_LPS_LCLK */
 
#ifdef CONFIG_INTERRUPT_BASED_TXBCN
#ifdef CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
   if (pHalData->IntArray[0] & IMR_BCNDMAINT0_8188F)/*only for BCN_0*/
       /* suspect code indent for conditional statements */
#endif
#ifdef CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
       if (pHalData->IntArray[0] & (IMR_TBDER_88E | IMR_TBDOK_88E))
           /* suspect code indent for conditional statements */
#endif
       {
#if 0
           if (pHalData->IntArray[0] & IMR_BCNDMAINT0_88E)
               RTW_INFO("%s: HISR_BCNERLY_INT\n", __func__);
           if (pHalData->IntArray[0] & IMR_TBDOK_88E)
               RTW_INFO("%s: HISR_TXBCNOK\n", __func__);
           if (pHalData->IntArray[0] & IMR_TBDER_88E)
               RTW_INFO("%s: HISR_TXBCNERR\n", __func__);
#endif
           rtw_mi_set_tx_beacon_cmd(padapter);
       }
#endif /*CONFIG_INTERRUPT_BASED_TXBCN */
 
 
 
 
#ifdef DBG_CONFIG_ERROR_DETECT_INT
   if (pHalData->IntArray[1]  & IMR_TXERR_8188F)
       RTW_INFO("===> %s Tx Error Flag Interrupt Status\n", __func__);
   if (pHalData->IntArray[1]  & IMR_RXERR_8188F)
       RTW_INFO("===> %s Rx Error Flag INT Status\n", __func__);
   if (pHalData->IntArray[1]  & IMR_TXFOVW_8188F)
       RTW_INFO("===> %s Transmit FIFO Overflow\n", __func__);
   if (pHalData->IntArray[1]  & IMR_RXFOVW_8188F)
       RTW_INFO("===> %s Receive FIFO Overflow\n", __func__);
#endif/*DBG_CONFIG_ERROR_DETECT_INT */
 
#ifdef CONFIG_FW_C2H_REG
   /* C2H Event */
   if (pbuf[0] != 0)
       usb_c2h_hisr_hdl(padapter, pbuf);
#endif
}
#endif
 
int recvbuf2recvframe(PADAPTER padapter, void *ptr)
{
   u8 *pbuf;
   u8 pkt_cnt = 0;
   u32 pkt_offset;
   s32 transfer_len;
   u8 *pdata;
   union recv_frame *precvframe = NULL;
   struct rx_pkt_attrib *pattrib = NULL;
   PHAL_DATA_TYPE pHalData;
   struct recv_priv *precvpriv;
   _queue *pfree_recv_queue;
   _pkt *pskb;
 
 
   pHalData = GET_HAL_DATA(padapter);
   precvpriv = &padapter->recvpriv;
   pfree_recv_queue = &precvpriv->free_recv_queue;
 
#ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
   pskb = NULL;
   transfer_len = (s32)((struct recv_buf *)ptr)->transfer_len;
   pbuf = ((struct recv_buf *)ptr)->pbuf;
#else /* !CONFIG_USE_USB_BUFFER_ALLOC_RX */
   pskb = (_pkt *)ptr;
   transfer_len = (s32)pskb->len;
   pbuf = pskb->data;
#endif /* !CONFIG_USE_USB_BUFFER_ALLOC_RX */
 
#ifdef CONFIG_USB_RX_AGGREGATION
   pkt_cnt = GET_RX_STATUS_DESC_USB_AGG_PKTNUM_8188F(pbuf);
#endif
 
   do {
       precvframe = rtw_alloc_recvframe(pfree_recv_queue);
       if (precvframe == NULL) {
           RTW_INFO("%s: rtw_alloc_recvframe() failed! RX Drop!\n", __func__);
           goto _exit_recvbuf2recvframe;
       }
 
       if (transfer_len > 1500)
           _rtw_init_listhead(&precvframe->u.hdr.list);
       precvframe->u.hdr.precvbuf = NULL;    /*can't access the precvbuf for new arch. */
       precvframe->u.hdr.len = 0;
 
       rtl8188f_query_rx_desc_status(precvframe, pbuf);
 
       pattrib = &precvframe->u.hdr.attrib;
 
       if ((padapter->registrypriv.mp_mode == 0)
           && ((pattrib->crc_err) || (pattrib->icv_err))) {
           RTW_INFO("%s: RX Warning! crc_err=%d icv_err=%d, skip!\n",
                __func__, pattrib->crc_err, pattrib->icv_err);
 
           rtw_free_recvframe(precvframe, pfree_recv_queue);
           goto _exit_recvbuf2recvframe;
       }
 
       pkt_offset = RXDESC_SIZE + pattrib->drvinfo_sz + pattrib->shift_sz + pattrib->pkt_len;
       if ((pattrib->pkt_len <= 0) || (pkt_offset > transfer_len)) {
           RTW_INFO("%s: RX Error! pkt_len=%d pkt_offset=%d transfer_len=%d\n",
               __func__, pattrib->pkt_len, pkt_offset, transfer_len);
 
           rtw_free_recvframe(precvframe, pfree_recv_queue);
           goto _exit_recvbuf2recvframe;
       }
 
#ifdef CONFIG_RX_PACKET_APPEND_FCS
       if (check_fwstate(&padapter->mlmepriv, WIFI_MONITOR_STATE) == _FALSE)
           if ((pattrib->pkt_rpt_type == NORMAL_RX) && rtw_hal_rcr_check(padapter, RCR_APPFCS))
               pattrib->pkt_len -= IEEE80211_FCS_LEN;
#endif
 
       pdata = pbuf + RXDESC_SIZE + pattrib->drvinfo_sz + pattrib->shift_sz;
       if (rtw_os_alloc_recvframe(padapter, precvframe, pdata, pskb) == _FAIL) {
           RTW_INFO("%s: RX Error! rtw_os_alloc_recvframe FAIL!\n", __func__);
 
           rtw_free_recvframe(precvframe, pfree_recv_queue);
           goto _exit_recvbuf2recvframe;
       }
 
       recvframe_put(precvframe, pattrib->pkt_len);
 
       if (pattrib->pkt_rpt_type == NORMAL_RX)
           pre_recv_entry(precvframe, pattrib->physt ? (pbuf + RXDESC_OFFSET) : NULL);
       else {
#ifdef CONFIG_FW_C2H_PKT
           if (pattrib->pkt_rpt_type == C2H_PACKET)
               rtw_hal_c2h_pkt_pre_hdl(padapter, precvframe->u.hdr.rx_data, pattrib->pkt_len);
           else {
               RTW_INFO("%s: [WARNNING] RX type(%d) not be handled!\n",
                    __func__, pattrib->pkt_rpt_type);
           }
#endif /* CONFIG_FW_C2H_PKT */
           rtw_free_recvframe(precvframe, pfree_recv_queue);
       }
 
#ifdef CONFIG_USB_RX_AGGREGATION
       /* jaguar 8-byte alignment */
       pkt_offset = (u16)_RND8(pkt_offset);
       pkt_cnt--;
       pbuf += pkt_offset;
#endif
       transfer_len -= pkt_offset;
       precvframe = NULL;
   } while (transfer_len > 0);
 
_exit_recvbuf2recvframe:
 
   return _SUCCESS;
}
 
 
void rtl8188fu_xmit_tasklet(void *priv)
{
   int ret = _FALSE;
   _adapter *padapter = (_adapter *)priv;
   struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
 
   while (1) {
       if (RTW_CANNOT_TX(padapter)) {
           RTW_INFO("xmit_tasklet => bDriverStopped or bSurpriseRemoved or bWritePortCancel\n");
           break;
       }
 
       if (rtw_xmit_ac_blocked(padapter) == _TRUE)
           break;
 
       ret = rtl8188fu_xmitframe_complete(padapter, pxmitpriv, NULL);
 
       if (ret == _FALSE)
           break;
 
   }
 
}
 
void rtl8188fu_set_hw_type(struct dvobj_priv *pdvobj)
{
   pdvobj->HardwareType = HARDWARE_TYPE_RTL8188FU;
   RTW_INFO("CHIP TYPE: RTL8188FU\n");
}