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 #define NR_MP_XMITFRAME		8
12 
13 struct mp_xmit_frame {
14 	struct list_head	list;
15 
16 	struct pkt_attrib attrib;
17 
18 	_pkt *pkt;
19 
20 	int frame_tag;
21 
22 	struct adapter *padapter;
23 
24 	uint mem[(MAX_MP_XMITBUF_SZ >> 2)];
25 };
26 
27 struct mp_wiparam {
28 	u32 bcompleted;
29 	u32 act_type;
30 	u32 io_offset;
31 	u32 io_value;
32 };
33 
34 typedef void(*wi_act_func)(void *padapter);
35 
36 struct mp_tx {
37 	u8 stop;
38 	u32 count, sended;
39 	u8 payload;
40 	struct pkt_attrib attrib;
41 	/* struct tx_desc desc; */
42 	/* u8 resvdtx[7]; */
43 	u8 desc[TXDESC_SIZE];
44 	u8 *pallocated_buf;
45 	u8 *buf;
46 	u32 buf_size, write_size;
47 	void *PktTxThread;
48 };
49 
50 #define MP_MAX_LINES		1000
51 #define MP_MAX_LINES_BYTES	256
52 
53 typedef void (*MPT_WORK_ITEM_HANDLER)(void *Adapter);
54 typedef struct _MPT_CONTEXT {
55 	/*  Indicate if we have started Mass Production Test. */
56 	bool			bMassProdTest;
57 
58 	/*  Indicate if the driver is unloading or unloaded. */
59 	bool			bMptDrvUnload;
60 
61 	_timer			MPh2c_timeout_timer;
62 /*  Event used to sync H2c for BT control */
63 
64 	bool		MptH2cRspEvent;
65 	bool		MptBtC2hEvent;
66 	bool		bMPh2c_timeout;
67 
68 	/* 8190 PCI does not support NDIS_WORK_ITEM. */
69 	/*  Work Item for Mass Production Test. */
70 	/* NDIS_WORK_ITEM	MptWorkItem; */
71 /* 	RT_WORK_ITEM		MptWorkItem; */
72 	/*  Event used to sync the case unloading driver and MptWorkItem is still in progress. */
73 /* 	NDIS_EVENT		MptWorkItemEvent; */
74 	/*  To protect the following variables. */
75 /* 	NDIS_SPIN_LOCK		MptWorkItemSpinLock; */
76 	/*  Indicate a MptWorkItem is scheduled and not yet finished. */
77 	bool			bMptWorkItemInProgress;
78 	/*  An instance which implements function and context of MptWorkItem. */
79 	MPT_WORK_ITEM_HANDLER	CurrMptAct;
80 
81 	/*  1 =Start, 0 =Stop from UI. */
82 	u32 		MptTestStart;
83 	/*  _TEST_MODE, defined in MPT_Req2.h */
84 	u32 		MptTestItem;
85 	/*  Variable needed in each implementation of CurrMptAct. */
86 	u32 		MptActType;	/*  Type of action performed in CurrMptAct. */
87 	/*  The Offset of IO operation is depend of MptActType. */
88 	u32 		MptIoOffset;
89 	/*  The Value of IO operation is depend of MptActType. */
90 	u32 		MptIoValue;
91 	/*  The RfPath of IO operation is depend of MptActType. */
92 	u32 		MptRfPath;
93 
94 	enum WIRELESS_MODE		MptWirelessModeToSw;	/*  Wireless mode to switch. */
95 	u8 	MptChannelToSw;		/*  Channel to switch. */
96 	u8 	MptInitGainToSet;	/*  Initial gain to set. */
97 	u32 		MptBandWidth;		/*  bandwidth to switch. */
98 	u32 		MptRateIndex;		/*  rate index. */
99 	/*  Register value kept for Single Carrier Tx test. */
100 	u8 	btMpCckTxPower;
101 	/*  Register value kept for Single Carrier Tx test. */
102 	u8 	btMpOfdmTxPower;
103 	/*  For MP Tx Power index */
104 	u8 	TxPwrLevel[2];	/*  rf-A, rf-B */
105 	u32 		RegTxPwrLimit;
106 	/*  Content of RCR Regsiter for Mass Production Test. */
107 	u32 		MptRCR;
108 	/*  true if we only receive packets with specific pattern. */
109 	bool			bMptFilterPattern;
110 	/*  Rx OK count, statistics used in Mass Production Test. */
111 	u32 		MptRxOkCnt;
112 	/*  Rx CRC32 error count, statistics used in Mass Production Test. */
113 	u32 		MptRxCrcErrCnt;
114 
115 	bool			bCckContTx;	/*  true if we are in CCK Continuous Tx test. */
116 	bool			bOfdmContTx;	/*  true if we are in OFDM Continuous Tx test. */
117 	bool			bStartContTx;	/*  true if we have start Continuous Tx test. */
118 	/*  true if we are in Single Carrier Tx test. */
119 	bool			bSingleCarrier;
120 	/*  true if we are in Carrier Suppression Tx Test. */
121 	bool			bCarrierSuppression;
122 	/* true if we are in Single Tone Tx test. */
123 	bool			bSingleTone;
124 
125 	/*  ACK counter asked by K.Y.. */
126 	bool			bMptEnableAckCounter;
127 	u32 		MptAckCounter;
128 
129 	/*  SD3 Willis For 8192S to save 1T/2T RF table for ACUT	Only fro ACUT delete later ~~~! */
130 	/* s8		BufOfLines[2][MAX_LINES_HWCONFIG_TXT][MAX_BYTES_LINE_HWCONFIG_TXT]; */
131 	/* s8			BufOfLines[2][MP_MAX_LINES][MP_MAX_LINES_BYTES]; */
132 	/* s32			RfReadLine[2]; */
133 
134 	u8 APK_bound[2];	/* for APK	path A/path B */
135 	bool		bMptIndexEven;
136 
137 	u8 backup0xc50;
138 	u8 backup0xc58;
139 	u8 backup0xc30;
140 	u8 backup0x52_RF_A;
141 	u8 backup0x52_RF_B;
142 
143 	u32 		backup0x58_RF_A;
144 	u32 		backup0x58_RF_B;
145 
146 	u8 	h2cReqNum;
147 	u8 	c2hBuf[32];
148 
149     u8          btInBuf[100];
150 	u32 		mptOutLen;
151     u8          mptOutBuf[100];
152 
153 } MPT_CONTEXT, *PMPT_CONTEXT;
154 /* endif */
155 
156 /* E-Fuse */
157 #define EFUSE_MAP_SIZE		512
158 
159 #define EFUSE_MAX_SIZE		512
160 /* end of E-Fuse */
161 
162 /* define RTPRIV_IOCTL_MP					(SIOCIWFIRSTPRIV + 0x17) */
163 enum {
164 	WRITE_REG = 1,
165 	READ_REG,
166 	WRITE_RF,
167 	READ_RF,
168 	MP_START,
169 	MP_STOP,
170 	MP_RATE,
171 	MP_CHANNEL,
172 	MP_BANDWIDTH,
173 	MP_TXPOWER,
174 	MP_ANT_TX,
175 	MP_ANT_RX,
176 	MP_CTX,
177 	MP_QUERY,
178 	MP_ARX,
179 	MP_PSD,
180 	MP_PWRTRK,
181 	MP_THER,
182 	MP_IOCTL,
183 	EFUSE_GET,
184 	EFUSE_SET,
185 	MP_RESET_STATS,
186 	MP_DUMP,
187 	MP_PHYPARA,
188 	MP_SetRFPathSwh,
189 	MP_QueryDrvStats,
190 	MP_SetBT,
191 	CTA_TEST,
192 	MP_DISABLE_BT_COEXIST,
193 	MP_PwrCtlDM,
194 #ifdef CONFIG_WOWLAN
195 	MP_WOW_ENABLE,
196 #endif
197 #ifdef CONFIG_AP_WOWLAN
198 	MP_AP_WOW_ENABLE,
199 #endif
200 	MP_NULL,
201 	MP_GET_TXPOWER_INX,
202 };
203 
204 struct mp_priv {
205 	struct adapter *papdater;
206 
207 	/* Testing Flag */
208 	u32 mode;/* 0 for normal type packet, 1 for loopback packet (16bytes TXCMD) */
209 
210 	u32 prev_fw_state;
211 
212 	/* OID cmd handler */
213 	struct mp_wiparam workparam;
214 /* 	u8 act_in_progress; */
215 
216 	/* Tx Section */
217 	u8 TID;
218 	u32 tx_pktcount;
219 	u32 pktInterval;
220 	struct mp_tx tx;
221 
222 	/* Rx Section */
223 	u32 rx_bssidpktcount;
224 	u32 rx_pktcount;
225 	u32 rx_pktcount_filter_out;
226 	u32 rx_crcerrpktcount;
227 	u32 rx_pktloss;
228 	bool  rx_bindicatePkt;
229 	struct recv_stat rxstat;
230 
231 	/* RF/BB relative */
232 	u8 channel;
233 	u8 bandwidth;
234 	u8 prime_channel_offset;
235 	u8 txpoweridx;
236 	u8 txpoweridx_b;
237 	u8 rateidx;
238 	u32 preamble;
239 /* 	u8 modem; */
240 	u32 CrystalCap;
241 /* 	u32 curr_crystalcap; */
242 
243 	u16 antenna_tx;
244 	u16 antenna_rx;
245 /* 	u8 curr_rfpath; */
246 
247 	u8 check_mp_pkt;
248 
249 	u8 bSetTxPower;
250 /* 	uint ForcedDataRate; */
251 	u8 mp_dm;
252 	u8 mac_filter[ETH_ALEN];
253 	u8 bmac_filter;
254 
255 	struct wlan_network mp_network;
256 	NDIS_802_11_MAC_ADDRESS network_macaddr;
257 
258 	u8 *pallocated_mp_xmitframe_buf;
259 	u8 *pmp_xmtframe_buf;
260 	struct __queue free_mp_xmitqueue;
261 	u32 free_mp_xmitframe_cnt;
262 	bool bSetRxBssid;
263 	bool bTxBufCkFail;
264 
265 	MPT_CONTEXT MptCtx;
266 
267 	u8 *TXradomBuffer;
268 };
269 
270 typedef struct _IOCMD_STRUCT_ {
271 	u8 cmdclass;
272 	u16 value;
273 	u8 index;
274 } IOCMD_STRUCT;
275 
276 struct rf_reg_param {
277 	u32 path;
278 	u32 offset;
279 	u32 value;
280 };
281 
282 struct bb_reg_param {
283 	u32 offset;
284 	u32 value;
285 };
286 
287 #define LOWER	true
288 #define RAISE	false
289 
290 /* Hardware Registers */
291 #define BB_REG_BASE_ADDR		0x800
292 
293 /* MP variables */
294 enum MP_MODE {
295 	MP_OFF,
296 	MP_ON,
297 	MP_ERR,
298 	MP_CONTINUOUS_TX,
299 	MP_SINGLE_CARRIER_TX,
300 	MP_CARRIER_SUPPRISSION_TX,
301 	MP_SINGLE_TONE_TX,
302 	MP_PACKET_TX,
303 	MP_PACKET_RX
304 };
305 
306 #define MAX_RF_PATH_NUMS	RF_PATH_MAX
307 
308 extern u8 mpdatarate[NumRates];
309 
310 /* MP set force data rate base on the definition. */
311 enum MPT_RATE_INDEX {
312 	/* CCK rate. */
313 	MPT_RATE_1M = 0,	/* 0 */
314 	MPT_RATE_2M,
315 	MPT_RATE_55M,
316 	MPT_RATE_11M,	/* 3 */
317 
318 	/* OFDM rate. */
319 	MPT_RATE_6M,	/* 4 */
320 	MPT_RATE_9M,
321 	MPT_RATE_12M,
322 	MPT_RATE_18M,
323 	MPT_RATE_24M,
324 	MPT_RATE_36M,
325 	MPT_RATE_48M,
326 	MPT_RATE_54M,	/* 11 */
327 
328 	/* HT rate. */
329 	MPT_RATE_MCS0,	/* 12 */
330 	MPT_RATE_MCS1,
331 	MPT_RATE_MCS2,
332 	MPT_RATE_MCS3,
333 	MPT_RATE_MCS4,
334 	MPT_RATE_MCS5,
335 	MPT_RATE_MCS6,
336 	MPT_RATE_MCS7,	/* 19 */
337 	MPT_RATE_MCS8,
338 	MPT_RATE_MCS9,
339 	MPT_RATE_MCS10,
340 	MPT_RATE_MCS11,
341 	MPT_RATE_MCS12,
342 	MPT_RATE_MCS13,
343 	MPT_RATE_MCS14,
344 	MPT_RATE_MCS15,	/* 27 */
345 	/* VHT rate. Total: 20*/
346 	MPT_RATE_VHT1SS_MCS0 = 100,/*  To reserve MCS16~MCS31, the index starts from #100. */
347 	MPT_RATE_VHT1SS_MCS1, /*  #101 */
348 	MPT_RATE_VHT1SS_MCS2,
349 	MPT_RATE_VHT1SS_MCS3,
350 	MPT_RATE_VHT1SS_MCS4,
351 	MPT_RATE_VHT1SS_MCS5,
352 	MPT_RATE_VHT1SS_MCS6, /*  #106 */
353 	MPT_RATE_VHT1SS_MCS7,
354 	MPT_RATE_VHT1SS_MCS8,
355 	MPT_RATE_VHT1SS_MCS9,
356 	MPT_RATE_VHT2SS_MCS0,
357 	MPT_RATE_VHT2SS_MCS1, /*  #111 */
358 	MPT_RATE_VHT2SS_MCS2,
359 	MPT_RATE_VHT2SS_MCS3,
360 	MPT_RATE_VHT2SS_MCS4,
361 	MPT_RATE_VHT2SS_MCS5,
362 	MPT_RATE_VHT2SS_MCS6, /*  #116 */
363 	MPT_RATE_VHT2SS_MCS7,
364 	MPT_RATE_VHT2SS_MCS8,
365 	MPT_RATE_VHT2SS_MCS9,
366 	MPT_RATE_LAST
367 };
368 
369 #define MAX_TX_PWR_INDEX_N_MODE 64	/*  0x3F */
370 
371 enum POWER_MODE {
372 	POWER_LOW = 0,
373 	POWER_NORMAL
374 };
375 
376 /*  The following enumeration is used to define the value of Reg0xD00[30:28] or JaguarReg0x914[18:16]. */
377 enum OFDM_TX_MODE {
378 	OFDM_ALL_OFF		= 0,
379 	OFDM_ContinuousTx	= 1,
380 	OFDM_SingleCarrier	= 2,
381 	OFDM_SingleTone		= 4,
382 };
383 
384 #define RX_PKT_BROADCAST	1
385 #define RX_PKT_DEST_ADDR	2
386 #define RX_PKT_PHY_MATCH	3
387 
388 #define Mac_OFDM_OK			0x00000000
389 #define Mac_OFDM_Fail			0x10000000
390 #define Mac_OFDM_FasleAlarm	0x20000000
391 #define Mac_CCK_OK				0x30000000
392 #define Mac_CCK_Fail			0x40000000
393 #define Mac_CCK_FasleAlarm		0x50000000
394 #define Mac_HT_OK				0x60000000
395 #define Mac_HT_Fail			0x70000000
396 #define Mac_HT_FasleAlarm		0x90000000
397 #define Mac_DropPacket			0xA0000000
398 
399 enum ENCRY_CTRL_STATE {
400 	HW_CONTROL,		/* hw encryption& decryption */
401 	SW_CONTROL,		/* sw encryption& decryption */
402 	HW_ENCRY_SW_DECRY,	/* hw encryption & sw decryption */
403 	SW_ENCRY_HW_DECRY	/* sw encryption & hw decryption */
404 };
405 
406 enum MPT_TXPWR_DEF {
407 	MPT_CCK,
408 	MPT_OFDM, /*  L and HT OFDM */
409 	MPT_VHT_OFDM
410 };
411 
412 #define		REG_RF_BB_GAIN_OFFSET	0x7f
413 #define		RF_GAIN_OFFSET_MASK	0xfffff
414 
415 /*  */
416 /* struct mp_xmit_frame *alloc_mp_xmitframe(struct mp_priv *pmp_priv); */
417 /* int free_mp_xmitframe(struct xmit_priv *pxmitpriv, struct mp_xmit_frame *pmp_xmitframe); */
418 
419 s32 init_mp_priv(struct adapter *padapter);
420 void free_mp_priv(struct mp_priv *pmp_priv);
421 s32 MPT_InitializeAdapter(struct adapter *padapter, u8 Channel);
422 void MPT_DeInitAdapter(struct adapter *padapter);
423 s32 mp_start_test(struct adapter *padapter);
424 void mp_stop_test(struct adapter *padapter);
425 
426 u32 _read_rfreg(struct adapter *padapter, u8 rfpath, u32 addr, u32 bitmask);
427 void _write_rfreg(struct adapter *padapter, u8 rfpath, u32 addr, u32 bitmask, u32 val);
428 
429 u32 read_macreg(struct adapter *padapter, u32 addr, u32 sz);
430 void write_macreg(struct adapter *padapter, u32 addr, u32 val, u32 sz);
431 u32 read_bbreg(struct adapter *padapter, u32 addr, u32 bitmask);
432 void write_bbreg(struct adapter *padapter, u32 addr, u32 bitmask, u32 val);
433 u32 read_rfreg(struct adapter *padapter, u8 rfpath, u32 addr);
434 void write_rfreg(struct adapter *padapter, u8 rfpath, u32 addr, u32 val);
435 
436 void SetChannel(struct adapter *padapter);
437 void SetBandwidth(struct adapter *padapter);
438 int SetTxPower(struct adapter *padapter);
439 void SetAntennaPathPower(struct adapter *padapter);
440 void SetDataRate(struct adapter *padapter);
441 
442 void SetAntenna(struct adapter *padapter);
443 
444 s32 SetThermalMeter(struct adapter *padapter, u8 target_ther);
445 void GetThermalMeter(struct adapter *padapter, u8 *value);
446 
447 void SetContinuousTx(struct adapter *padapter, u8 bStart);
448 void SetSingleCarrierTx(struct adapter *padapter, u8 bStart);
449 void SetSingleToneTx(struct adapter *padapter, u8 bStart);
450 void SetCarrierSuppressionTx(struct adapter *padapter, u8 bStart);
451 void PhySetTxPowerLevel(struct adapter *padapter);
452 
453 void fill_txdesc_for_mp(struct adapter *padapter, u8 *ptxdesc);
454 void SetPacketTx(struct adapter *padapter);
455 void SetPacketRx(struct adapter *padapter, u8 bStartRx);
456 
457 void ResetPhyRxPktCount(struct adapter *padapter);
458 u32 GetPhyRxPktReceived(struct adapter *padapter);
459 u32 GetPhyRxPktCRC32Error(struct adapter *padapter);
460 
461 s32	SetPowerTracking(struct adapter *padapter, u8 enable);
462 void GetPowerTracking(struct adapter *padapter, u8 *enable);
463 
464 u32 mp_query_psd(struct adapter *padapter, u8 *data);
465 
466 void Hal_SetAntenna(struct adapter *padapter);
467 void Hal_SetBandwidth(struct adapter *padapter);
468 
469 void Hal_SetTxPower(struct adapter *padapter);
470 void Hal_SetCarrierSuppressionTx(struct adapter *padapter, u8 bStart);
471 void Hal_SetSingleToneTx(struct adapter *padapter, u8 bStart);
472 void Hal_SetSingleCarrierTx(struct adapter *padapter, u8 bStart);
473 void Hal_SetContinuousTx(struct adapter *padapter, u8 bStart);
474 void Hal_SetBandwidth(struct adapter *padapter);
475 
476 void Hal_SetDataRate(struct adapter *padapter);
477 void Hal_SetChannel(struct adapter *padapter);
478 void Hal_SetAntennaPathPower(struct adapter *padapter);
479 s32 Hal_SetThermalMeter(struct adapter *padapter, u8 target_ther);
480 s32 Hal_SetPowerTracking(struct adapter *padapter, u8 enable);
481 void Hal_GetPowerTracking(struct adapter *padapter, u8 *enable);
482 void Hal_GetThermalMeter(struct adapter *padapter, u8 *value);
483 void Hal_mpt_SwitchRfSetting(struct adapter *padapter);
484 void Hal_MPT_CCKTxPowerAdjust(struct adapter *Adapter, bool bInCH14);
485 void Hal_MPT_CCKTxPowerAdjustbyIndex(struct adapter *padapter, bool beven);
486 void Hal_SetCCKTxPower(struct adapter *padapter, u8 *TxPower);
487 void Hal_SetOFDMTxPower(struct adapter *padapter, u8 *TxPower);
488 void Hal_TriggerRFThermalMeter(struct adapter *padapter);
489 u8 Hal_ReadRFThermalMeter(struct adapter *padapter);
490 void Hal_SetCCKContinuousTx(struct adapter *padapter, u8 bStart);
491 void Hal_SetOFDMContinuousTx(struct adapter *padapter, u8 bStart);
492 void Hal_ProSetCrystalCap(struct adapter *padapter, u32 CrystalCapVal);
493 void MP_PHY_SetRFPathSwitch(struct adapter *padapter, bool bMain);
494 u32 mpt_ProQueryCalTxPower(struct adapter *padapter, u8 RfPath);
495 void MPT_PwrCtlDM(struct adapter *padapter, u32 bstart);
496 u8 MptToMgntRate(u32 MptRateIdx);
497 
498 #endif /* _RTW_MP_H_ */
499