1/* SPDX-License-Identifier: GPL-2.0 */
2/******************************************************************************
3 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 *
6 * Modifications for inclusion into the Linux staging tree are
7 * Copyright(c) 2010 Larry Finger. All rights reserved.
8 *
9 * Contact information:
10 * WLAN FAE <wlanfae@realtek.com>
11 * Larry Finger <Larry.Finger@lwfinger.net>
12 *
13 ******************************************************************************/
14#ifndef _RTL871X_MP_IOCTL_H
15#define _RTL871X_MP_IOCTL_H
16
17#include "osdep_service.h"
18#include "drv_types.h"
19#include "mp_custom_oid.h"
20#include "rtl871x_ioctl.h"
21#include "rtl871x_ioctl_rtl.h"
22#include "rtl8712_efuse.h"
23
24#define TESTFWCMDNUMBER			1000000
25#define TEST_H2CINT_WAIT_TIME		500
26#define TEST_C2HINT_WAIT_TIME		500
27#define HCI_TEST_SYSCFG_HWMASK		1
28#define _BUSCLK_40M			(4 << 2)
29
30struct CFG_DBG_MSG_STRUCT {
31	u32 DebugLevel;
32	u32 DebugComponent_H32;
33	u32 DebugComponent_L32;
34};
35
36struct mp_rw_reg {
37	uint offset;
38	uint width;
39	u32 value;
40};
41
42/* for OID_RT_PRO_READ16_EEPROM & OID_RT_PRO_WRITE16_EEPROM */
43struct eeprom_rw_param {
44	uint offset;
45	u16 value;
46};
47
48struct EFUSE_ACCESS_STRUCT {
49	u16	start_addr;
50	u16	cnts;
51	u8	data[];
52};
53
54struct burst_rw_reg {
55	uint offset;
56	uint len;
57	u8 Data[256];
58};
59
60struct usb_vendor_req {
61	u8	bRequest;
62	u16	wValue;
63	u16	wIndex;
64	u16	wLength;
65	u8	u8Dir;/*0:OUT, 1:IN */
66	u8	u8InData;
67};
68
69struct DR_VARIABLE_STRUCT {
70	u8 offset;
71	u32 variable;
72};
73
74/* oid_rtl_seg_87_11_00 */
75uint oid_rt_pro_read_register_hdl(struct oid_par_priv *poid_par_priv);
76uint oid_rt_pro_write_register_hdl(struct oid_par_priv *poid_par_priv);
77/* oid_rtl_seg_81_80_00 */
78uint oid_rt_pro_set_data_rate_hdl(
79				struct oid_par_priv *poid_par_priv);
80uint oid_rt_pro_start_test_hdl(struct oid_par_priv *poid_par_priv);
81uint oid_rt_pro_stop_test_hdl(struct oid_par_priv *poid_par_priv);
82uint oid_rt_pro_set_channel_direct_call_hdl(
83				struct oid_par_priv *poid_par_priv);
84uint oid_rt_pro_set_antenna_bb_hdl(
85				struct oid_par_priv *poid_par_priv);
86uint oid_rt_pro_set_tx_power_control_hdl(
87				struct oid_par_priv *poid_par_priv);
88/* oid_rtl_seg_81_80_20 */
89uint oid_rt_pro_query_tx_packet_sent_hdl(
90				struct oid_par_priv *poid_par_priv);
91uint oid_rt_pro_query_rx_packet_received_hdl(
92				struct oid_par_priv *poid_par_priv);
93uint oid_rt_pro_query_rx_packet_crc32_error_hdl(
94				struct oid_par_priv *poid_par_priv);
95uint oid_rt_pro_reset_tx_packet_sent_hdl(
96				struct oid_par_priv *poid_par_priv);
97uint oid_rt_pro_reset_rx_packet_received_hdl(
98				struct oid_par_priv *poid_par_priv);
99uint oid_rt_pro_set_modulation_hdl(struct oid_par_priv *poid_par_priv);
100uint oid_rt_pro_set_continuous_tx_hdl(
101				struct oid_par_priv *poid_par_priv);
102uint oid_rt_pro_set_single_carrier_tx_hdl(
103				struct oid_par_priv *poid_par_priv);
104uint oid_rt_pro_set_carrier_suppression_tx_hdl(
105				struct oid_par_priv *poid_par_priv);
106uint oid_rt_pro_set_single_tone_tx_hdl(
107				struct oid_par_priv *poid_par_priv);
108/* oid_rtl_seg_81_87 */
109uint oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv *poid_par_priv);
110uint oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv *poid_par_priv);
111uint oid_rt_pro_write_rf_reg_hdl(struct oid_par_priv *poid_par_priv);
112uint oid_rt_pro_read_rf_reg_hdl(struct oid_par_priv *poid_par_priv);
113/* oid_rtl_seg_81_85 */
114uint oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv);
115uint oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv);
116uint oid_rt_pro_write_efuse_hdl(struct oid_par_priv *poid_par_priv);
117uint oid_rt_get_efuse_current_size_hdl(
118				struct oid_par_priv *poid_par_priv);
119uint oid_rt_pro_efuse_hdl(struct oid_par_priv *poid_par_priv);
120uint oid_rt_pro_efuse_map_hdl(struct oid_par_priv *poid_par_priv);
121uint oid_rt_set_bandwidth_hdl(struct oid_par_priv *poid_par_priv);
122uint oid_rt_set_rx_packet_type_hdl(struct oid_par_priv *poid_par_priv);
123uint oid_rt_get_efuse_max_size_hdl(struct oid_par_priv *poid_par_priv);
124uint oid_rt_get_thermal_meter_hdl(
125				struct oid_par_priv *poid_par_priv);
126uint oid_rt_reset_phy_rx_packet_count_hdl(
127				struct oid_par_priv *poid_par_priv);
128uint oid_rt_get_phy_rx_packet_received_hdl(
129				struct oid_par_priv *poid_par_priv);
130uint oid_rt_get_phy_rx_packet_crc32_error_hdl(
131				struct oid_par_priv *poid_par_priv);
132uint oid_rt_set_power_down_hdl(
133				struct oid_par_priv *poid_par_priv);
134uint oid_rt_get_power_mode_hdl(
135				struct oid_par_priv *poid_par_priv);
136#ifdef _RTL871X_MP_IOCTL_C_ /* CAUTION!!! */
137/* This ifdef _MUST_ be left in!! */
138
139#else /* _RTL871X_MP_IOCTL_C_ */
140extern struct oid_obj_priv oid_rtl_seg_81_87[5];
141extern struct oid_obj_priv oid_rtl_seg_87_11_00[32];
142extern struct oid_obj_priv oid_rtl_seg_87_11_20[5];
143extern struct oid_obj_priv oid_rtl_seg_87_11_50[2];
144extern struct oid_obj_priv oid_rtl_seg_87_11_80[1];
145extern struct oid_obj_priv oid_rtl_seg_87_11_B0[1];
146extern struct oid_obj_priv oid_rtl_seg_87_11_F0[16];
147extern struct oid_obj_priv oid_rtl_seg_87_12_00[32];
148
149#endif /* _RTL871X_MP_IOCTL_C_ */
150
151enum MP_MODE {
152	MP_START_MODE,
153	MP_STOP_MODE,
154	MP_ERR_MODE
155};
156
157struct rwreg_param {
158	unsigned int offset;
159	unsigned int width;
160	unsigned int value;
161};
162
163struct bbreg_param {
164	unsigned int offset;
165	unsigned int phymask;
166	unsigned int value;
167};
168
169struct txpower_param {
170	unsigned int pwr_index;
171};
172
173struct datarate_param {
174	unsigned int rate_index;
175};
176
177struct rfintfs_parm {
178	unsigned int rfintfs;
179};
180
181struct mp_xmit_packet {
182	unsigned int len;
183};
184
185struct psmode_param {
186	unsigned int ps_mode;
187	unsigned int smart_ps;
188};
189
190struct mp_ioctl_handler {
191	unsigned int paramsize;
192	unsigned int (*handler)(struct oid_par_priv *poid_par_priv);
193	unsigned int oid;
194};
195
196struct mp_ioctl_param {
197	unsigned int subcode;
198	unsigned int len;
199	unsigned char data[];
200};
201
202#define GEN_MP_IOCTL_SUBCODE(code) _MP_IOCTL_ ## code ## _CMD_
203
204enum RTL871X_MP_IOCTL_SUBCODE {
205	GEN_MP_IOCTL_SUBCODE(MP_START),			/*0*/
206	GEN_MP_IOCTL_SUBCODE(MP_STOP),			/*1*/
207	GEN_MP_IOCTL_SUBCODE(READ_REG),			/*2*/
208	GEN_MP_IOCTL_SUBCODE(WRITE_REG),
209	GEN_MP_IOCTL_SUBCODE(SET_CHANNEL),		/*4*/
210	GEN_MP_IOCTL_SUBCODE(SET_TXPOWER),		/*5*/
211	GEN_MP_IOCTL_SUBCODE(SET_DATARATE),		/*6*/
212	GEN_MP_IOCTL_SUBCODE(READ_BB_REG),		/*7*/
213	GEN_MP_IOCTL_SUBCODE(WRITE_BB_REG),
214	GEN_MP_IOCTL_SUBCODE(READ_RF_REG),		/*9*/
215	GEN_MP_IOCTL_SUBCODE(WRITE_RF_REG),
216	GEN_MP_IOCTL_SUBCODE(SET_RF_INTFS),
217	GEN_MP_IOCTL_SUBCODE(IOCTL_XMIT_PACKET),	/*12*/
218	GEN_MP_IOCTL_SUBCODE(PS_STATE),			/*13*/
219	GEN_MP_IOCTL_SUBCODE(READ16_EEPROM),		/*14*/
220	GEN_MP_IOCTL_SUBCODE(WRITE16_EEPROM),		/*15*/
221	GEN_MP_IOCTL_SUBCODE(SET_PTM),			/*16*/
222	GEN_MP_IOCTL_SUBCODE(READ_TSSI),		/*17*/
223	GEN_MP_IOCTL_SUBCODE(CNTU_TX),			/*18*/
224	GEN_MP_IOCTL_SUBCODE(SET_BANDWIDTH),		/*19*/
225	GEN_MP_IOCTL_SUBCODE(SET_RX_PKT_TYPE),		/*20*/
226	GEN_MP_IOCTL_SUBCODE(RESET_PHY_RX_PKT_CNT),	/*21*/
227	GEN_MP_IOCTL_SUBCODE(GET_PHY_RX_PKT_RECV),	/*22*/
228	GEN_MP_IOCTL_SUBCODE(GET_PHY_RX_PKT_ERROR),	/*23*/
229	GEN_MP_IOCTL_SUBCODE(SET_POWER_DOWN),		/*24*/
230	GEN_MP_IOCTL_SUBCODE(GET_THERMAL_METER),	/*25*/
231	GEN_MP_IOCTL_SUBCODE(GET_POWER_MODE),		/*26*/
232	GEN_MP_IOCTL_SUBCODE(EFUSE),			/*27*/
233	GEN_MP_IOCTL_SUBCODE(EFUSE_MAP),		/*28*/
234	GEN_MP_IOCTL_SUBCODE(GET_EFUSE_MAX_SIZE),	/*29*/
235	GEN_MP_IOCTL_SUBCODE(GET_EFUSE_CURRENT_SIZE),	/*30*/
236	GEN_MP_IOCTL_SUBCODE(SC_TX),			/*31*/
237	GEN_MP_IOCTL_SUBCODE(CS_TX),			/*32*/
238	GEN_MP_IOCTL_SUBCODE(ST_TX),			/*33*/
239	GEN_MP_IOCTL_SUBCODE(SET_ANTENNA),		/*34*/
240	MAX_MP_IOCTL_SUBCODE,
241};
242
243unsigned int mp_ioctl_xmit_packet_hdl(struct oid_par_priv *poid_par_priv);
244
245#ifdef _RTL871X_MP_IOCTL_C_ /* CAUTION!!! */
246/* This ifdef _MUST_ be left in!! */
247
248static struct mp_ioctl_handler mp_ioctl_hdl[] = {
249	{sizeof(u32), oid_rt_pro_start_test_hdl,
250			     OID_RT_PRO_START_TEST},/*0*/
251	{sizeof(u32), oid_rt_pro_stop_test_hdl,
252			     OID_RT_PRO_STOP_TEST},/*1*/
253	{sizeof(struct rwreg_param),
254			     oid_rt_pro_read_register_hdl,
255			     OID_RT_PRO_READ_REGISTER},/*2*/
256	{sizeof(struct rwreg_param),
257			     oid_rt_pro_write_register_hdl,
258			     OID_RT_PRO_WRITE_REGISTER},
259	{sizeof(u32),
260			     oid_rt_pro_set_channel_direct_call_hdl,
261			     OID_RT_PRO_SET_CHANNEL_DIRECT_CALL},
262	{sizeof(struct txpower_param),
263			     oid_rt_pro_set_tx_power_control_hdl,
264			     OID_RT_PRO_SET_TX_POWER_CONTROL},
265	{sizeof(u32),
266			     oid_rt_pro_set_data_rate_hdl,
267			     OID_RT_PRO_SET_DATA_RATE},
268	{sizeof(struct bb_reg_param),
269			     oid_rt_pro_read_bb_reg_hdl,
270			     OID_RT_PRO_READ_BB_REG},/*7*/
271	{sizeof(struct bb_reg_param),
272			     oid_rt_pro_write_bb_reg_hdl,
273			     OID_RT_PRO_WRITE_BB_REG},
274	{sizeof(struct rwreg_param),
275			     oid_rt_pro_read_rf_reg_hdl,
276			     OID_RT_PRO_RF_READ_REGISTRY},/*9*/
277	{sizeof(struct rwreg_param),
278			     oid_rt_pro_write_rf_reg_hdl,
279			     OID_RT_PRO_RF_WRITE_REGISTRY},
280	{sizeof(struct rfintfs_parm), NULL, 0},
281	{0, mp_ioctl_xmit_packet_hdl, 0},/*12*/
282	{sizeof(struct psmode_param), NULL, 0},/*13*/
283	{sizeof(struct eeprom_rw_param), NULL, 0},/*14*/
284	{sizeof(struct eeprom_rw_param), NULL, 0},/*15*/
285	{sizeof(unsigned char), NULL, 0},/*16*/
286	{sizeof(u32), NULL, 0},/*17*/
287	{sizeof(u32), oid_rt_pro_set_continuous_tx_hdl,
288			     OID_RT_PRO_SET_CONTINUOUS_TX},/*18*/
289	{sizeof(u32), oid_rt_set_bandwidth_hdl,
290			     OID_RT_SET_BANDWIDTH},/*19*/
291	{sizeof(u32), oid_rt_set_rx_packet_type_hdl,
292			     OID_RT_SET_RX_PACKET_TYPE},/*20*/
293	{0, oid_rt_reset_phy_rx_packet_count_hdl,
294			     OID_RT_RESET_PHY_RX_PACKET_COUNT},/*21*/
295	{sizeof(u32), oid_rt_get_phy_rx_packet_received_hdl,
296			     OID_RT_GET_PHY_RX_PACKET_RECEIVED},/*22*/
297	{sizeof(u32), oid_rt_get_phy_rx_packet_crc32_error_hdl,
298			     OID_RT_GET_PHY_RX_PACKET_CRC32_ERROR},/*23*/
299	{sizeof(unsigned char), oid_rt_set_power_down_hdl,
300			     OID_RT_SET_POWER_DOWN},/*24*/
301	{sizeof(u32), oid_rt_get_thermal_meter_hdl,
302			     OID_RT_PRO_GET_THERMAL_METER},/*25*/
303	{sizeof(u32), oid_rt_get_power_mode_hdl,
304			     OID_RT_GET_POWER_MODE},/*26*/
305	{sizeof(struct EFUSE_ACCESS_STRUCT),
306			     oid_rt_pro_efuse_hdl, OID_RT_PRO_EFUSE},/*27*/
307	{EFUSE_MAP_MAX_SIZE, oid_rt_pro_efuse_map_hdl,
308			     OID_RT_PRO_EFUSE_MAP},/*28*/
309	{sizeof(u32), oid_rt_get_efuse_max_size_hdl,
310			     OID_RT_GET_EFUSE_MAX_SIZE},/*29*/
311	{sizeof(u32), oid_rt_get_efuse_current_size_hdl,
312			     OID_RT_GET_EFUSE_CURRENT_SIZE},/*30*/
313	{sizeof(u32), oid_rt_pro_set_single_carrier_tx_hdl,
314			     OID_RT_PRO_SET_SINGLE_CARRIER_TX},/*31*/
315	{sizeof(u32), oid_rt_pro_set_carrier_suppression_tx_hdl,
316			     OID_RT_PRO_SET_CARRIER_SUPPRESSION_TX},/*32*/
317	{sizeof(u32), oid_rt_pro_set_single_tone_tx_hdl,
318			     OID_RT_PRO_SET_SINGLE_TONE_TX},/*33*/
319	{sizeof(u32), oid_rt_pro_set_antenna_bb_hdl,
320			     OID_RT_PRO_SET_ANTENNA_BB},/*34*/
321};
322
323#else /* _RTL871X_MP_IOCTL_C_ */
324extern struct mp_ioctl_handler mp_ioctl_hdl[];
325#endif /* _RTL871X_MP_IOCTL_C_ */
326
327#endif
328
329