hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
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
/******************************************************************************
 *
 * Copyright(c) 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 _HAL_USB_C_
#include "hal_headers.h"
#include "hal_usb.h"
 
#ifdef CONFIG_USB_HCI
u8 usb_read8(struct rtw_hal_com_t *hal, u32 addr)
{
   u8 request;
   u8 requesttype;
   u16 wvalue;
   u16 index;
   u16 len;
   u8 data = 0;
 
   request = 0x05;
   requesttype = 0x01;/* read_in */
   index = (u16)((addr & 0x00ff0000) >> 16);
   wvalue = (u16)(addr & 0x0000ffff);
   len = 1;
 
   _os_usbctrl_vendorreq(hal->drv_priv, request, wvalue, index,
               &data, len, requesttype);
 
   return data;
}
 
u16 usb_read16(struct rtw_hal_com_t *hal, u32 addr)
{
   u8 request;
   u8 requesttype;
   u16 wvalue;
   u16 index;
   u16 len;
   u16 data = 0;
 
   request = 0x05;
   requesttype = 0x01;/* read_in */
   index = (u16)((addr & 0x00ff0000) >> 16);
   wvalue = (u16)(addr & 0x0000ffff);
   len = 2;
 
   _os_usbctrl_vendorreq(hal->drv_priv, request, wvalue, index,
               &data, len, requesttype);
   return le16_to_cpu(data);
 
}
 
u32 usb_read32(struct rtw_hal_com_t *hal, u32 addr)
{
   u8 request;
   u8 requesttype;
   u16 wvalue;
   u16 index;
   u16 len;
   u32 data = 0;
 
   request = 0x05;
   requesttype = 0x01;/* read_in */
   index = (u16)((addr & 0x00ff0000) >> 16);
   wvalue = (u16)(addr & 0x0000ffff);
   len = 4;
 
   _os_usbctrl_vendorreq(hal->drv_priv, request, wvalue, index,
               &data, len, requesttype);
   return le32_to_cpu(data);
}
 
int usb_write8(struct rtw_hal_com_t *hal, u32 addr, u8 val)
{
   u8 request;
   u8 requesttype;
   u16 wvalue;
   u16 index;
   u16 len;
   u8 data;
   int ret;
 
 
   request = 0x05;
   requesttype = 0x00;/* write_out */
   index = (u16)((addr & 0x00ff0000) >> 16);
   wvalue = (u16)(addr & 0x0000ffff);
   len = 1;
   data = val;
 
   ret = _os_usbctrl_vendorreq(hal->drv_priv, 
           request, wvalue, index, &data, len, requesttype);
   return ret;
}
 
int usb_write16(struct rtw_hal_com_t *hal, u32 addr, u16 val)
{
   u8 request;
   u8 requesttype;
   u16 wvalue;
   u16 index;
   u16 len;
   u16 data;
   int ret;
 
   request = 0x05;
   requesttype = 0x00;/* write_out */
   index = (u16)((addr & 0x00ff0000) >> 16);
   wvalue = (u16)(addr & 0x0000ffff);
   len = 2;
   data = cpu_to_le16(val);
 
   ret = _os_usbctrl_vendorreq(hal->drv_priv,
           request, wvalue, index,    &data, len, requesttype);
 
   return ret;
 
}
 
int usb_write32(struct rtw_hal_com_t *hal, u32 addr, u32 val)
{
   u8 request;
   u8 requesttype;
   u16 wvalue;
   u16 index;
   u16 len;
   u32 data;
   int ret;
 
   request = 0x05;
   requesttype = 0x00;/* write_out */
   index = (u16)((addr & 0x00ff0000) >> 16);
   wvalue = (u16)(addr & 0x0000ffff);
   len = 4;
   data = cpu_to_le32(val);
 
   ret = _os_usbctrl_vendorreq(hal->drv_priv,
           request, wvalue, index,    &data, len, requesttype);
 
   return ret;
 
}
 
int usb_write_mem(struct rtw_hal_com_t *hal, u32 addr, u32 length, u8 *pdata)
{
   u8 request;
   u8 requesttype;
   u16 wvalue;
   u16 index;
   u16 len;
   int ret;
   u8 buf[MAX_VENDOR_REQ_CMD_SIZE] = {0};
 
   request = 0x05;
   requesttype = 0x00;/* write_out */
   index = (u16)((addr & 0x00ff0000) >> 16);
   wvalue = (u16)(addr & 0x0000ffff);
   len = (u16)length;
 
   _os_mem_cpy(hal->drv_priv, buf, pdata, len);
 
   ret = _os_usbctrl_vendorreq(hal->drv_priv,
           request, wvalue, index, pdata, len, requesttype);
 
   return ret;
 
}
#ifdef RTW_WKARD_BUS_WRITE
static int usb_write_post_cfg(struct rtw_hal_com_t *hal, u32 addr, u32 val)
{
   struct hal_info_t    *hal_info = hal->hal_priv;
   struct hal_ops_t    *hal_ops = hal_get_ops(hal_info);
 
   enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
   
   if(NULL != hal_ops->write_reg_post_cfg) {
       hal_status = hal_ops->write_reg_post_cfg(hal_info, addr, val);
   }
 
   return hal_status;
}
#endif
static void hal_usb_set_io_ops_gen(struct rtw_hal_com_t *hal, struct hal_io_ops *pops)
{
   /*_rtw_memset((u8 *)pops, 0, sizeof(struct hal_io_ops));*/
   _os_mem_set(hal->drv_priv, (u8 *)pops, 0, sizeof(struct hal_io_ops));
 
   pops->_read8 = &usb_read8;
   pops->_read16 = &usb_read16;
   pops->_read32 = &usb_read32;
   pops->_read_mem = NULL;
 
   pops->_write8 = &usb_write8;
   pops->_write16 = &usb_write16;
   pops->_write32 = &usb_write32;
   pops->_write_mem = &usb_write_mem;
#ifdef RTW_WKARD_BUS_WRITE
   pops->_write_post_cfg = &usb_write_post_cfg;
#endif
}
 
void hal_usb_set_io_ops(struct rtw_hal_com_t *hal, struct hal_io_ops *pops)
{
   hal_usb_set_io_ops_gen(hal, pops);
   /*hal_usb_set_io_ops_8852au(hal, pops);*/
}
 
 
/* To avoid RX affect TX throughput */
#ifdef CONFIG_PHL_USB_RX_AGGREGATION
void rtw_hal_usb_adjust_txagg(void *h)
{
   #if 0
   struct hal_info_t *hal = (struct hal_info_t *)h;
   struct registry_priv *registry_par = &padapter->registrypriv;
 
   if (!registry_par->dynamic_agg_enable)
       return;
 
   if (IS_HARDWARE_TYPE_8822BU(padapter) || IS_HARDWARE_TYPE_8821CU(padapter)
       || IS_HARDWARE_TYPE_8822CU(padapter) || IS_HARDWARE_TYPE_8814BU(padapter))
       rtw_hal_set_hwreg(padapter, HW_VAR_RXDMA_AGG_PG_TH, NULL);
   #endif
}
#endif /* CONFIG_PHL_USB_RX_AGGREGATION */
 
enum rtw_hal_status rtw_hal_force_usb_switch(void *h, enum usb_type type)
{
   struct hal_info_t *hal = (struct hal_info_t *)h;
   u32 mode = hal_mac_get_cur_usb_mode(hal);
   bool bswitch = false;
 
   bswitch = ((enum usb_type)mode != type) ? (true) : (false);
   PHL_INFO("%s, switch from %d to %d\n", __func__,
                           mode , type);
   if(bswitch)
       return hal_mac_force_usb_switch(hal);
   else
       return RTW_HAL_STATUS_SUCCESS;
}
 
u32 rtwl_hal_get_cur_usb_mode(void *h)
{
   struct hal_info_t *hal = (struct hal_info_t *)h;
   /*refer to enum usb_type*/
   return hal_mac_get_cur_usb_mode(hal);
}
u32 rtwl_hal_get_usb_support_ability(void *h)
{
   struct hal_info_t *hal = (struct hal_info_t *)h;
   /*
   * refers to _usb.h
   * #define SWITCHMODE           0x2
   * #define FORCEUSB3MODE        0x1
   * #define FORCEUSB2MODE        0x0
   */
   return hal_mac_get_usb_support_ability(hal);
}
 
enum rtw_rx_status rtw_hal_get_usb_status(void *h)
{
   struct hal_info_t *hal = (struct hal_info_t *)h;
   struct mac_ax_adapter *mac = hal_to_mac(hal);
   struct mac_ax_ops *hal_mac_ops = mac->ops;
   u32 mac_usb_sts;
   u32 val;
 
   mac_usb_sts = hal_mac_ops->get_hw_value(mac, MAC_AX_HW_GET_USB_STS, &val);
 
   switch (mac_usb_sts) {
   case MACSUCCESS:
   case MACNOITEM:
       return RTW_STATUS_RX_OK;
   case MACRXDMAHANG:
       return RTW_STATUS_RXDMA_HANG;
   case MACUSBRXHANG:
       return RTW_STATUS_RXFIFO_HANG;
   default:
       return RTW_STATUS_RX_OK;
   }
}
#endif /*CONFIG_USB_HCI*/