1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 #ifndef _RTW_MP_H_
8 #define _RTW_MP_H_
9 
10 #define MAX_MP_XMITBUF_SZ	2048
11 
12 struct mp_xmit_frame {
13 	struct list_head	list;
14 
15 	struct pkt_attrib attrib;
16 
17 	struct sk_buff *pkt;
18 
19 	int frame_tag;
20 
21 	struct adapter *padapter;
22 
23 	uint mem[(MAX_MP_XMITBUF_SZ >> 2)];
24 };
25 
26 struct mp_wiparam {
27 	u32 bcompleted;
28 	u32 act_type;
29 	u32 io_offset;
30 	u32 io_value;
31 };
32 
33 struct mp_tx {
34 	u8 stop;
35 	u32 count, sended;
36 	u8 payload;
37 	struct pkt_attrib attrib;
38 	/* struct tx_desc desc; */
39 	/* u8 resvdtx[7]; */
40 	u8 desc[TXDESC_SIZE];
41 	u8 *pallocated_buf;
42 	u8 *buf;
43 	u32 buf_size, write_size;
44 	void *PktTxThread;
45 };
46 
47 #define MP_MAX_LINES		1000
48 #define MP_MAX_LINES_BYTES	256
49 
50 typedef void (*MPT_WORK_ITEM_HANDLER)(void *Adapter);
51 struct mpt_context {
52 	/*  Indicate if we have started Mass Production Test. */
53 	bool			bMassProdTest;
54 
55 	/*  Indicate if the driver is unloading or unloaded. */
56 	bool			bMptDrvUnload;
57 
58 	struct timer_list			MPh2c_timeout_timer;
59 /*  Event used to sync H2c for BT control */
60 
61 	bool		MptH2cRspEvent;
62 	bool		MptBtC2hEvent;
63 	bool		bMPh2c_timeout;
64 
65 	/* 8190 PCI does not support NDIS_WORK_ITEM. */
66 	/*  Work Item for Mass Production Test. */
67 	/* NDIS_WORK_ITEM	MptWorkItem; */
68 /* 	RT_WORK_ITEM		MptWorkItem; */
69 	/*  Event used to sync the case unloading driver and MptWorkItem is still in progress. */
70 /* 	NDIS_EVENT		MptWorkItemEvent; */
71 	/*  To protect the following variables. */
72 /* 	NDIS_SPIN_LOCK		MptWorkItemSpinLock; */
73 	/*  Indicate a MptWorkItem is scheduled and not yet finished. */
74 	bool			bMptWorkItemInProgress;
75 	/*  An instance which implements function and context of MptWorkItem. */
76 	MPT_WORK_ITEM_HANDLER	CurrMptAct;
77 
78 	/*  1 =Start, 0 =Stop from UI. */
79 	u32 		MptTestStart;
80 	/*  _TEST_MODE, defined in MPT_Req2.h */
81 	u32 		MptTestItem;
82 	/*  Variable needed in each implementation of CurrMptAct. */
83 	u32 		MptActType;	/*  Type of action performed in CurrMptAct. */
84 	/*  The Offset of IO operation is depend of MptActType. */
85 	u32 		MptIoOffset;
86 	/*  The Value of IO operation is depend of MptActType. */
87 	u32 		MptIoValue;
88 	/*  The RfPath of IO operation is depend of MptActType. */
89 	u32 		MptRfPath;
90 
91 	enum wireless_mode		MptWirelessModeToSw;	/*  Wireless mode to switch. */
92 	u8 	MptChannelToSw;		/*  Channel to switch. */
93 	u8 	MptInitGainToSet;	/*  Initial gain to set. */
94 	u32 		MptBandWidth;		/*  bandwidth to switch. */
95 	u32 		MptRateIndex;		/*  rate index. */
96 	/*  Register value kept for Single Carrier Tx test. */
97 	u8 	btMpCckTxPower;
98 	/*  Register value kept for Single Carrier Tx test. */
99 	u8 	btMpOfdmTxPower;
100 	/*  For MP Tx Power index */
101 	u8 	TxPwrLevel[2];	/*  rf-A, rf-B */
102 	u32 		RegTxPwrLimit;
103 	/*  Content of RCR Register for Mass Production Test. */
104 	u32 		MptRCR;
105 	/*  true if we only receive packets with specific pattern. */
106 	bool			bMptFilterPattern;
107 	/*  Rx OK count, statistics used in Mass Production Test. */
108 	u32 		MptRxOkCnt;
109 	/*  Rx CRC32 error count, statistics used in Mass Production Test. */
110 	u32 		MptRxCrcErrCnt;
111 
112 	bool			bCckContTx;	/*  true if we are in CCK Continuous Tx test. */
113 	bool			bOfdmContTx;	/*  true if we are in OFDM Continuous Tx test. */
114 	bool			bStartContTx;	/*  true if we have start Continuous Tx test. */
115 	/*  true if we are in Single Carrier Tx test. */
116 	bool			bSingleCarrier;
117 	/*  true if we are in Carrier Suppression Tx Test. */
118 	bool			bCarrierSuppression;
119 	/* true if we are in Single Tone Tx test. */
120 	bool			bSingleTone;
121 
122 	/*  ACK counter asked by K.Y.. */
123 	bool			bMptEnableAckCounter;
124 	u32 		MptAckCounter;
125 
126 	/*  SD3 Willis For 8192S to save 1T/2T RF table for ACUT	Only fro ACUT delete later ~~~! */
127 	/* s8		BufOfLines[2][MAX_LINES_HWCONFIG_TXT][MAX_BYTES_LINE_HWCONFIG_TXT]; */
128 	/* s8			BufOfLines[2][MP_MAX_LINES][MP_MAX_LINES_BYTES]; */
129 	/* s32			RfReadLine[2]; */
130 
131 	u8 APK_bound[2];	/* for APK	path A/path B */
132 	bool		bMptIndexEven;
133 
134 	u8 backup0xc50;
135 	u8 backup0xc58;
136 	u8 backup0xc30;
137 	u8 backup0x52_RF_A;
138 	u8 backup0x52_RF_B;
139 
140 	u32 		backup0x58_RF_A;
141 	u32 		backup0x58_RF_B;
142 
143 	u8 	h2cReqNum;
144 	u8 	c2hBuf[32];
145 
146     u8          btInBuf[100];
147 	u32 		mptOutLen;
148     u8          mptOutBuf[100];
149 
150 };
151 /* endif */
152 
153 /* define RTPRIV_IOCTL_MP					(SIOCIWFIRSTPRIV + 0x17) */
154 enum {
155 	WRITE_REG = 1,
156 	READ_REG,
157 	WRITE_RF,
158 	READ_RF,
159 	MP_START,
160 	MP_STOP,
161 	MP_RATE,
162 	MP_CHANNEL,
163 	MP_BANDWIDTH,
164 	MP_TXPOWER,
165 	MP_ANT_TX,
166 	MP_ANT_RX,
167 	MP_CTX,
168 	MP_QUERY,
169 	MP_ARX,
170 	MP_PSD,
171 	MP_PWRTRK,
172 	MP_THER,
173 	MP_IOCTL,
174 	EFUSE_GET,
175 	EFUSE_SET,
176 	MP_RESET_STATS,
177 	MP_DUMP,
178 	MP_PHYPARA,
179 	MP_SetRFPathSwh,
180 	MP_QueryDrvStats,
181 	MP_SetBT,
182 	CTA_TEST,
183 	MP_DISABLE_BT_COEXIST,
184 	MP_PwrCtlDM,
185 	MP_NULL,
186 	MP_GET_TXPOWER_INX,
187 };
188 
189 struct mp_priv {
190 	struct adapter *papdater;
191 
192 	/* Testing Flag */
193 	u32 mode;/* 0 for normal type packet, 1 for loopback packet (16bytes TXCMD) */
194 
195 	u32 prev_fw_state;
196 
197 	/* OID cmd handler */
198 	struct mp_wiparam workparam;
199 /* 	u8 act_in_progress; */
200 
201 	/* Tx Section */
202 	u8 TID;
203 	u32 tx_pktcount;
204 	u32 pktInterval;
205 	struct mp_tx tx;
206 
207 	/* Rx Section */
208 	u32 rx_bssidpktcount;
209 	u32 rx_pktcount;
210 	u32 rx_pktcount_filter_out;
211 	u32 rx_crcerrpktcount;
212 	u32 rx_pktloss;
213 	bool  rx_bindicatePkt;
214 	struct recv_stat rxstat;
215 
216 	/* RF/BB relative */
217 	u8 channel;
218 	u8 bandwidth;
219 	u8 prime_channel_offset;
220 	u8 txpoweridx;
221 	u8 txpoweridx_b;
222 	u8 rateidx;
223 	u32 preamble;
224 /* 	u8 modem; */
225 	u32 CrystalCap;
226 /* 	u32 curr_crystalcap; */
227 
228 	u16 antenna_tx;
229 	u16 antenna_rx;
230 /* 	u8 curr_rfpath; */
231 
232 	u8 check_mp_pkt;
233 
234 	u8 bSetTxPower;
235 /* 	uint ForcedDataRate; */
236 	u8 mp_dm;
237 	u8 mac_filter[ETH_ALEN];
238 	u8 bmac_filter;
239 
240 	struct wlan_network mp_network;
241 	NDIS_802_11_MAC_ADDRESS network_macaddr;
242 
243 	u8 *pallocated_mp_xmitframe_buf;
244 	u8 *pmp_xmtframe_buf;
245 	struct __queue free_mp_xmitqueue;
246 	u32 free_mp_xmitframe_cnt;
247 	bool bSetRxBssid;
248 	bool bTxBufCkFail;
249 
250 	struct mpt_context MptCtx;
251 
252 	u8 *TXradomBuffer;
253 };
254 
255 /* Hardware Registers */
256 extern u8 mpdatarate[NumRates];
257 
258 #define MAX_TX_PWR_INDEX_N_MODE 64	/*  0x3F */
259 
260 #define		REG_RF_BB_GAIN_OFFSET	0x7f
261 #define		RF_GAIN_OFFSET_MASK	0xfffff
262 
263 /*  */
264 /* struct mp_xmit_frame *alloc_mp_xmitframe(struct mp_priv *pmp_priv); */
265 /* int free_mp_xmitframe(struct xmit_priv *pxmitpriv, struct mp_xmit_frame *pmp_xmitframe); */
266 
267 s32 init_mp_priv(struct adapter *padapter);
268 void free_mp_priv(struct mp_priv *pmp_priv);
269 s32 MPT_InitializeAdapter(struct adapter *padapter, u8 Channel);
270 void MPT_DeInitAdapter(struct adapter *padapter);
271 s32 mp_start_test(struct adapter *padapter);
272 void mp_stop_test(struct adapter *padapter);
273 
274 u32 _read_rfreg(struct adapter *padapter, u8 rfpath, u32 addr, u32 bitmask);
275 void _write_rfreg(struct adapter *padapter, u8 rfpath, u32 addr, u32 bitmask, u32 val);
276 
277 u32 read_macreg(struct adapter *padapter, u32 addr, u32 sz);
278 void write_macreg(struct adapter *padapter, u32 addr, u32 val, u32 sz);
279 u32 read_bbreg(struct adapter *padapter, u32 addr, u32 bitmask);
280 void write_bbreg(struct adapter *padapter, u32 addr, u32 bitmask, u32 val);
281 u32 read_rfreg(struct adapter *padapter, u8 rfpath, u32 addr);
282 void write_rfreg(struct adapter *padapter, u8 rfpath, u32 addr, u32 val);
283 
284 void SetChannel(struct adapter *padapter);
285 void SetBandwidth(struct adapter *padapter);
286 int SetTxPower(struct adapter *padapter);
287 void SetAntennaPathPower(struct adapter *padapter);
288 void SetDataRate(struct adapter *padapter);
289 
290 void SetAntenna(struct adapter *padapter);
291 
292 s32 SetThermalMeter(struct adapter *padapter, u8 target_ther);
293 void GetThermalMeter(struct adapter *padapter, u8 *value);
294 
295 void SetContinuousTx(struct adapter *padapter, u8 bStart);
296 void SetSingleCarrierTx(struct adapter *padapter, u8 bStart);
297 void SetSingleToneTx(struct adapter *padapter, u8 bStart);
298 void SetCarrierSuppressionTx(struct adapter *padapter, u8 bStart);
299 void PhySetTxPowerLevel(struct adapter *padapter);
300 
301 void fill_txdesc_for_mp(struct adapter *padapter, u8 *ptxdesc);
302 void SetPacketTx(struct adapter *padapter);
303 void SetPacketRx(struct adapter *padapter, u8 bStartRx);
304 
305 void ResetPhyRxPktCount(struct adapter *padapter);
306 u32 GetPhyRxPktReceived(struct adapter *padapter);
307 u32 GetPhyRxPktCRC32Error(struct adapter *padapter);
308 
309 s32	SetPowerTracking(struct adapter *padapter, u8 enable);
310 void GetPowerTracking(struct adapter *padapter, u8 *enable);
311 
312 u32 mp_query_psd(struct adapter *padapter, u8 *data);
313 
314 void Hal_SetAntenna(struct adapter *padapter);
315 void Hal_SetBandwidth(struct adapter *padapter);
316 
317 void Hal_SetTxPower(struct adapter *padapter);
318 void Hal_SetCarrierSuppressionTx(struct adapter *padapter, u8 bStart);
319 void Hal_SetSingleToneTx(struct adapter *padapter, u8 bStart);
320 void Hal_SetSingleCarrierTx(struct adapter *padapter, u8 bStart);
321 void Hal_SetContinuousTx(struct adapter *padapter, u8 bStart);
322 
323 void Hal_SetDataRate(struct adapter *padapter);
324 void Hal_SetChannel(struct adapter *padapter);
325 void Hal_SetAntennaPathPower(struct adapter *padapter);
326 s32 Hal_SetThermalMeter(struct adapter *padapter, u8 target_ther);
327 s32 Hal_SetPowerTracking(struct adapter *padapter, u8 enable);
328 void Hal_GetPowerTracking(struct adapter *padapter, u8 *enable);
329 void Hal_GetThermalMeter(struct adapter *padapter, u8 *value);
330 void Hal_mpt_SwitchRfSetting(struct adapter *padapter);
331 void Hal_MPT_CCKTxPowerAdjust(struct adapter *Adapter, bool bInCH14);
332 void Hal_MPT_CCKTxPowerAdjustbyIndex(struct adapter *padapter, bool beven);
333 void Hal_SetCCKTxPower(struct adapter *padapter, u8 *TxPower);
334 void Hal_SetOFDMTxPower(struct adapter *padapter, u8 *TxPower);
335 void Hal_TriggerRFThermalMeter(struct adapter *padapter);
336 u8 Hal_ReadRFThermalMeter(struct adapter *padapter);
337 void Hal_SetCCKContinuousTx(struct adapter *padapter, u8 bStart);
338 void Hal_SetOFDMContinuousTx(struct adapter *padapter, u8 bStart);
339 void Hal_ProSetCrystalCap(struct adapter *padapter, u32 CrystalCapVal);
340 void MP_PHY_SetRFPathSwitch(struct adapter *padapter, bool bMain);
341 u32 mpt_ProQueryCalTxPower(struct adapter *padapter, u8 RfPath);
342 void MPT_PwrCtlDM(struct adapter *padapter, u32 bstart);
343 u8 MptToMgntRate(u32 MptRateIdx);
344 
345 #endif /* _RTW_MP_H_ */
346