]> Pileus Git - ~andy/linux/blob - drivers/staging/rtl8188eu/include/rtw_mp.h
Merge branch 'linus' into perf/urgent
[~andy/linux] / drivers / staging / rtl8188eu / include / rtw_mp.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #ifndef _RTW_MP_H_
21 #define _RTW_MP_H_
22
23 /*      00 - Success */
24 /*      11 - Error */
25 #define STATUS_SUCCESS                          (0x00000000L)
26 #define STATUS_PENDING                          (0x00000103L)
27
28 #define STATUS_UNSUCCESSFUL                     (0xC0000001L)
29 #define STATUS_INSUFFICIENT_RESOURCES           (0xC000009AL)
30 #define STATUS_NOT_SUPPORTED                    (0xC00000BBL)
31
32 #define NDIS_STATUS_SUCCESS                     ((int)STATUS_SUCCESS)
33 #define NDIS_STATUS_PENDING                     ((int)STATUS_PENDING)
34 #define NDIS_STATUS_NOT_RECOGNIZED              ((int)0x00010001L)
35 #define NDIS_STATUS_NOT_COPIED                  ((int)0x00010002L)
36 #define NDIS_STATUS_NOT_ACCEPTED                ((int)0x00010003L)
37 #define NDIS_STATUS_CALL_ACTIVE                 ((int)0x00010007L)
38
39 #define NDIS_STATUS_FAILURE                     ((int)STATUS_UNSUCCESSFUL)
40 #define NDIS_STATUS_RESOURCES           ((int)STATUS_INSUFFICIENT_RESOURCES)
41 #define NDIS_STATUS_CLOSING                     ((int)0xC0010002L)
42 #define NDIS_STATUS_BAD_VERSION                 ((int)0xC0010004L)
43 #define NDIS_STATUS_BAD_CHARACTERISTICS         ((int)0xC0010005L)
44 #define NDIS_STATUS_ADAPTER_NOT_FOUND           ((int)0xC0010006L)
45 #define NDIS_STATUS_OPEN_FAILED                 ((int)0xC0010007L)
46 #define NDIS_STATUS_DEVICE_FAILED               ((int)0xC0010008L)
47 #define NDIS_STATUS_MULTICAST_FULL              ((int)0xC0010009L)
48 #define NDIS_STATUS_MULTICAST_EXISTS            ((int)0xC001000AL)
49 #define NDIS_STATUS_MULTICAST_NOT_FOUND         ((int)0xC001000BL)
50 #define NDIS_STATUS_REQUEST_ABORTED             ((int)0xC001000CL)
51 #define NDIS_STATUS_RESET_IN_PROGRESS           ((int)0xC001000DL)
52 #define NDIS_STATUS_CLOSING_INDICATING          ((int)0xC001000EL)
53 #define NDIS_STATUS_NOT_SUPPORTED               ((int)STATUS_NOT_SUPPORTED)
54 #define NDIS_STATUS_INVALID_PACKET              ((int)0xC001000FL)
55 #define NDIS_STATUS_OPEN_LIST_FULL              ((int)0xC0010010L)
56 #define NDIS_STATUS_ADAPTER_NOT_READY           ((int)0xC0010011L)
57 #define NDIS_STATUS_ADAPTER_NOT_OPEN            ((int)0xC0010012L)
58 #define NDIS_STATUS_NOT_INDICATING              ((int)0xC0010013L)
59 #define NDIS_STATUS_INVALID_LENGTH              ((int)0xC0010014L)
60 #define NDIS_STATUS_INVALID_DATA                ((int)0xC0010015L)
61 #define NDIS_STATUS_BUFFER_TOO_SHORT            ((int)0xC0010016L)
62 #define NDIS_STATUS_INVALID_OID                 ((int)0xC0010017L)
63 #define NDIS_STATUS_ADAPTER_REMOVED             ((int)0xC0010018L)
64 #define NDIS_STATUS_UNSUPPORTED_MEDIA           ((int)0xC0010019L)
65 #define NDIS_STATUS_GROUP_ADDRESS_IN_USE        ((int)0xC001001AL)
66 #define NDIS_STATUS_FILE_NOT_FOUND              ((int)0xC001001BL)
67 #define NDIS_STATUS_ERROR_READING_FILE          ((int)0xC001001CL)
68 #define NDIS_STATUS_ALREADY_MAPPED              ((int)0xC001001DL)
69 #define NDIS_STATUS_RESOURCE_CONFLICT           ((int)0xC001001EL)
70 #define NDIS_STATUS_NO_CABLE                    ((int)0xC001001FL)
71
72 #define NDIS_STATUS_INVALID_SAP                 ((int)0xC0010020L)
73 #define NDIS_STATUS_SAP_IN_USE                  ((int)0xC0010021L)
74 #define NDIS_STATUS_INVALID_ADDRESS             ((int)0xC0010022L)
75 #define NDIS_STATUS_VC_NOT_ACTIVATED            ((int)0xC0010023L)
76 #define NDIS_STATUS_DEST_OUT_OF_ORDER           ((int)0xC0010024L)  /*cause 27*/
77 #define NDIS_STATUS_VC_NOT_AVAILABLE            ((int)0xC0010025L)  /*cause 35,45 */
78 #define NDIS_STATUS_CELLRATE_NOT_AVAILABLE      ((int)0xC0010026L)  /*cause 37*/
79 #define NDIS_STATUS_INCOMPATABLE_QOS            ((int)0xC0010027L)  /*cause 49*/
80 #define NDIS_STATUS_AAL_PARAMS_UNSUPPORTED      ((int)0xC0010028L)  /*cause 93*/
81 #define NDIS_STATUS_NO_ROUTE_TO_DESTINATION     ((int)0xC0010029L)  /*cause 3 */
82
83 enum antenna_path {
84         ANTENNA_NONE = 0x00,
85         ANTENNA_D,
86         ANTENNA_C,
87         ANTENNA_CD,
88         ANTENNA_B,
89         ANTENNA_BD,
90         ANTENNA_BC,
91         ANTENNA_BCD,
92         ANTENNA_A,
93         ANTENNA_AD,
94         ANTENNA_AC,
95         ANTENNA_ACD,
96         ANTENNA_AB,
97         ANTENNA_ABD,
98         ANTENNA_ABC,
99         ANTENNA_ABCD
100 };
101
102
103 #define MAX_MP_XMITBUF_SZ       2048
104 #define NR_MP_XMITFRAME         8
105
106 struct mp_xmit_frame {
107         struct list_head list;
108         struct pkt_attrib attrib;
109         struct sk_buff *pkt;
110         int frame_tag;
111         struct adapter *padapter;
112         struct urb *pxmit_urb[8];
113         /* insert urb, irp, and irpcnt info below... */
114         u8 *mem_addr;
115         u32 sz[8];
116         u8 bpending[8];
117         int ac_tag[8];
118         int last[8];
119         uint irpcnt;
120         uint fragcnt;
121         uint mem[(MAX_MP_XMITBUF_SZ >> 2)];
122 };
123
124 struct mp_wiparam {
125         u32 bcompleted;
126         u32 act_type;
127         u32 io_offset;
128         u32 io_value;
129 };
130
131 typedef void(*wi_act_func)(void *padapter);
132
133 struct mp_tx {
134         u8 stop;
135         u32 count, sended;
136         u8 payload;
137         struct pkt_attrib attrib;
138         struct tx_desc desc;
139         u8 *pallocated_buf;
140         u8 *buf;
141         u32 buf_size, write_size;
142         void *PktTxThread;
143 };
144
145 #include <Hal8188EPhyCfg.h>
146
147 #define MP_MAX_LINES            1000
148 #define MP_MAX_LINES_BYTES      256
149
150 typedef void (*MPT_WORK_ITEM_HANDLER)(void *Adapter);
151
152 struct mpt_context {
153         /*  Indicate if we have started Mass Production Test. */
154         bool                    bMassProdTest;
155
156         /*  Indicate if the driver is unloading or unloaded. */
157         bool                    bMptDrvUnload;
158
159         struct semaphore MPh2c_Sema;
160         struct timer_list MPh2c_timeout_timer;
161 /*  Event used to sync H2c for BT control */
162
163         bool            MptH2cRspEvent;
164         bool            MptBtC2hEvent;
165         bool            bMPh2c_timeout;
166
167         /* 8190 PCI does not support NDIS_WORK_ITEM. */
168         /*  Work Item for Mass Production Test. */
169         /*  Event used to sync the case unloading driver and MptWorkItem
170          *  is still in progress. */
171         /*  Indicate a MptWorkItem is scheduled and not yet finished. */
172         bool                    bMptWorkItemInProgress;
173         /*  An instance which implements function and context of MptWorkItem. */
174         MPT_WORK_ITEM_HANDLER   CurrMptAct;
175
176         /*  1=Start, 0=Stop from UI. */
177         u32     MptTestStart;
178         /*  _TEST_MODE, defined in MPT_Req2.h */
179         u32     MptTestItem;
180         /*  Variable needed in each implementation of CurrMptAct. */
181         u32     MptActType;     /*  Type of action performed in CurrMptAct. */
182         /*  The Offset of IO operation is depend of MptActType. */
183         u32     MptIoOffset;
184         /*  The Value of IO operation is depend of MptActType. */
185         u32     MptIoValue;
186         /*  The RfPath of IO operation is depend of MptActType. */
187         u32     MptRfPath;
188
189         enum wireless_mode MptWirelessModeToSw; /*  Wireless mode to switch. */
190         u8      MptChannelToSw;         /*  Channel to switch. */
191         u8      MptInitGainToSet;       /*  Initial gain to set. */
192         u32     MptBandWidth;           /*  bandwidth to switch. */
193         u32     MptRateIndex;           /*  rate index. */
194         /*  Register value kept for Single Carrier Tx test. */
195         u8      btMpCckTxPower;
196         /*  Register value kept for Single Carrier Tx test. */
197         u8      btMpOfdmTxPower;
198         /*  For MP Tx Power index */
199         u8      TxPwrLevel[2];  /*  rf-A, rf-B */
200
201         /*  Content of RCR Regsiter for Mass Production Test. */
202         u32     MptRCR;
203         /*  true if we only receive packets with specific pattern. */
204         bool    bMptFilterPattern;
205         /*  Rx OK count, statistics used in Mass Production Test. */
206         u32     MptRxOkCnt;
207         /*  Rx CRC32 error count, statistics used in Mass Production Test. */
208         u32     MptRxCrcErrCnt;
209
210         bool    bCckContTx;     /*  true if we are in CCK Continuous Tx test. */
211         bool    bOfdmContTx;    /*  true if we are in OFDM Continuous Tx test. */
212         bool    bStartContTx;   /*  true if we have start Continuous Tx test. */
213         /*  true if we are in Single Carrier Tx test. */
214         bool    bSingleCarrier;
215         /*  true if we are in Carrier Suppression Tx Test. */
216         bool    bCarrierSuppression;
217         /* true if we are in Single Tone Tx test. */
218         bool    bSingleTone;
219
220         /*  ACK counter asked by K.Y.. */
221         bool    bMptEnableAckCounter;
222         u32     MptAckCounter;
223
224         u8      APK_bound[2];   /* for APK      path A/path B */
225         bool    bMptIndexEven;
226
227         u8      backup0xc50;
228         u8      backup0xc58;
229         u8      backup0xc30;
230         u8      backup0x52_RF_A;
231         u8      backup0x52_RF_B;
232
233         u8      h2cReqNum;
234         u8      c2hBuf[20];
235
236         u8      btInBuf[100];
237         u32     mptOutLen;
238         u8      mptOutBuf[100];
239 };
240
241 enum {
242         WRITE_REG = 1,
243         READ_REG,
244         WRITE_RF,
245         READ_RF,
246         MP_START,
247         MP_STOP,
248         MP_RATE,
249         MP_CHANNEL,
250         MP_BANDWIDTH,
251         MP_TXPOWER,
252         MP_ANT_TX,
253         MP_ANT_RX,
254         MP_CTX,
255         MP_QUERY,
256         MP_ARX,
257         MP_PSD,
258         MP_PWRTRK,
259         MP_THER,
260         MP_IOCTL,
261         EFUSE_GET,
262         EFUSE_SET,
263         MP_RESET_STATS,
264         MP_DUMP,
265         MP_PHYPARA,
266         MP_SetRFPathSwh,
267         MP_QueryDrvStats,
268         MP_SetBT,
269         CTA_TEST,
270         MP_NULL,
271 };
272
273 struct mp_priv {
274         struct adapter *papdater;
275
276         /* Testing Flag */
277         /* 0 for normal type packet, 1 for loopback packet (16bytes TXCMD) */
278         u32 mode;
279
280         u32 prev_fw_state;
281
282         /* OID cmd handler */
283         struct mp_wiparam workparam;
284
285         /* Tx Section */
286         u8 TID;
287         u32 tx_pktcount;
288         struct mp_tx tx;
289
290         /* Rx Section */
291         u32 rx_pktcount;
292         u32 rx_crcerrpktcount;
293         u32 rx_pktloss;
294
295         struct recv_stat rxstat;
296
297         /* RF/BB relative */
298         u8 channel;
299         u8 bandwidth;
300         u8 prime_channel_offset;
301         u8 txpoweridx;
302         u8 txpoweridx_b;
303         u8 rateidx;
304         u32 preamble;
305         u32 CrystalCap;
306
307         u16 antenna_tx;
308         u16 antenna_rx;
309
310         u8 check_mp_pkt;
311
312         u8 bSetTxPower;
313
314         struct wlan_network mp_network;
315         unsigned char network_macaddr[ETH_ALEN];
316
317         u8 *pallocated_mp_xmitframe_buf;
318         u8 *pmp_xmtframe_buf;
319         struct __queue free_mp_xmitqueue;
320         u32 free_mp_xmitframe_cnt;
321
322         struct mpt_context MptCtx;
323 };
324
325 struct iocmd_struct {
326         u8      cmdclass;
327         u16     value;
328         u8      index;
329 };
330
331 struct rf_reg_param {
332         u32 path;
333         u32 offset;
334         u32 value;
335 };
336
337 struct bb_reg_param {
338         u32 offset;
339         u32 value;
340 };
341 /*  */
342
343 #define LOWER   true
344 #define RAISE   false
345
346 /* Hardware Registers */
347 #define BB_REG_BASE_ADDR                0x800
348
349 /* MP variables */
350 enum mp_mode_{
351         MP_OFF,
352         MP_ON,
353         MP_ERR,
354         MP_CONTINUOUS_TX,
355         MP_SINGLE_CARRIER_TX,
356         MP_CARRIER_SUPPRISSION_TX,
357         MP_SINGLE_TONE_TX,
358         MP_PACKET_TX,
359         MP_PACKET_RX
360 };
361
362 #define MAX_RF_PATH_NUMS        RF_PATH_MAX
363
364 extern u8 mpdatarate[NumRates];
365
366 /* MP set force data rate base on the definition. */
367 enum mpt_rate_index {
368         /* CCK rate. */
369         MPT_RATE_1M,    /* 0 */
370         MPT_RATE_2M,
371         MPT_RATE_55M,
372         MPT_RATE_11M,   /* 3 */
373
374         /* OFDM rate. */
375         MPT_RATE_6M,    /* 4 */
376         MPT_RATE_9M,
377         MPT_RATE_12M,
378         MPT_RATE_18M,
379         MPT_RATE_24M,
380         MPT_RATE_36M,
381         MPT_RATE_48M,
382         MPT_RATE_54M,   /* 11 */
383
384         /* HT rate. */
385         MPT_RATE_MCS0,  /* 12 */
386         MPT_RATE_MCS1,
387         MPT_RATE_MCS2,
388         MPT_RATE_MCS3,
389         MPT_RATE_MCS4,
390         MPT_RATE_MCS5,
391         MPT_RATE_MCS6,
392         MPT_RATE_MCS7,  /* 19 */
393         MPT_RATE_MCS8,
394         MPT_RATE_MCS9,
395         MPT_RATE_MCS10,
396         MPT_RATE_MCS11,
397         MPT_RATE_MCS12,
398         MPT_RATE_MCS13,
399         MPT_RATE_MCS14,
400         MPT_RATE_MCS15, /* 27 */
401         MPT_RATE_LAST
402 };
403
404 #define MAX_TX_PWR_INDEX_N_MODE 64      /*  0x3F */
405
406 enum power_mode {
407         POWER_LOW = 0,
408         POWER_NORMAL
409 };
410
411 #define RX_PKT_BROADCAST        1
412 #define RX_PKT_DEST_ADDR        2
413 #define RX_PKT_PHY_MATCH        3
414
415 enum encry_ctrl_state {
416         HW_CONTROL,             /* hw encryption& decryption */
417         SW_CONTROL,             /* sw encryption& decryption */
418         HW_ENCRY_SW_DECRY,      /* hw encryption & sw decryption */
419         SW_ENCRY_HW_DECRY       /* sw encryption & hw decryption */
420 };
421
422 s32 init_mp_priv(struct adapter *padapter);
423 void free_mp_priv(struct mp_priv *pmp_priv);
424 s32 MPT_InitializeAdapter(struct adapter *padapter, u8 Channel);
425 void MPT_DeInitAdapter(struct adapter *padapter);
426 s32 mp_start_test(struct adapter *padapter);
427 void mp_stop_test(struct adapter *padapter);
428
429 u32 _read_rfreg(struct adapter *padapter, u8 rfpath, u32 addr, u32 bitmask);
430 void _write_rfreg(struct adapter *padapter, u8 rfpath, u32 addr, u32 bitmask, u32 val);
431
432 u32 read_macreg(struct adapter *padapter, u32 addr, u32 sz);
433 void write_macreg(struct adapter *padapter, u32 addr, u32 val, u32 sz);
434 u32 read_bbreg(struct adapter *padapter, u32 addr, u32 bitmask);
435 void write_bbreg(struct adapter *padapter, u32 addr, u32 bitmask, u32 val);
436 u32 read_rfreg(struct adapter *padapter, u8 rfpath, u32 addr);
437 void write_rfreg(struct adapter *padapter, u8 rfpath, u32 addr, u32 val);
438
439 void    SetChannel(struct adapter *pAdapter);
440 void    SetBandwidth(struct adapter *pAdapter);
441 void    SetTxPower(struct adapter *pAdapter);
442 void    SetAntennaPathPower(struct adapter *pAdapter);
443 void    SetDataRate(struct adapter *pAdapter);
444
445 void    SetAntenna(struct adapter *pAdapter);
446
447 s32     SetThermalMeter(struct adapter *pAdapter, u8 target_ther);
448 void    GetThermalMeter(struct adapter *pAdapter, u8 *value);
449
450 void    SetContinuousTx(struct adapter *pAdapter, u8 bStart);
451 void    SetSingleCarrierTx(struct adapter *pAdapter, u8 bStart);
452 void    SetSingleToneTx(struct adapter *pAdapter, u8 bStart);
453 void    SetCarrierSuppressionTx(struct adapter *pAdapter, u8 bStart);
454 void PhySetTxPowerLevel(struct adapter *pAdapter);
455
456 void    fill_txdesc_for_mp(struct adapter *padapter, struct tx_desc *ptxdesc);
457 void    SetPacketTx(struct adapter *padapter);
458 void    SetPacketRx(struct adapter *pAdapter, u8 bStartRx);
459
460 void    ResetPhyRxPktCount(struct adapter *pAdapter);
461 u32     GetPhyRxPktReceived(struct adapter *pAdapter);
462 u32     GetPhyRxPktCRC32Error(struct adapter *pAdapter);
463
464 s32     SetPowerTracking(struct adapter *padapter, u8 enable);
465 void    GetPowerTracking(struct adapter *padapter, u8 *enable);
466 u32     mp_query_psd(struct adapter *pAdapter, u8 *data);
467 void Hal_SetAntenna(struct adapter *pAdapter);
468 void Hal_SetBandwidth(struct adapter *pAdapter);
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 void Hal_SetDataRate(struct adapter *pAdapter);
476 void Hal_SetChannel(struct adapter *pAdapter);
477 void Hal_SetAntennaPathPower(struct adapter *pAdapter);
478 s32 Hal_SetThermalMeter(struct adapter *pAdapter, u8 target_ther);
479 s32 Hal_SetPowerTracking(struct adapter *padapter, u8 enable);
480 void Hal_GetPowerTracking(struct adapter *padapter, u8 * enable);
481 void Hal_GetThermalMeter(struct adapter *pAdapter, u8 *value);
482 void Hal_mpt_SwitchRfSetting(struct adapter *pAdapter);
483 void Hal_MPT_CCKTxPowerAdjust(struct adapter * Adapter, bool bInCH14);
484 void Hal_MPT_CCKTxPowerAdjustbyIndex(struct adapter *pAdapter, bool beven);
485 void Hal_SetCCKTxPower(struct adapter *pAdapter, u8 * TxPower);
486 void Hal_SetOFDMTxPower(struct adapter *pAdapter, u8 * TxPower);
487 void Hal_TriggerRFThermalMeter(struct adapter *pAdapter);
488 u8 Hal_ReadRFThermalMeter(struct adapter *pAdapter);
489 void Hal_SetCCKContinuousTx(struct adapter *pAdapter, u8 bStart);
490 void Hal_SetOFDMContinuousTx(struct adapter *pAdapter, u8 bStart);
491 void Hal_ProSetCrystalCap (struct adapter *pAdapter , u32 CrystalCapVal);
492 void _rtw_mp_xmit_priv(struct xmit_priv *pxmitpriv);
493 void MP_PHY_SetRFPathSwitch(struct adapter *pAdapter ,bool bMain);
494
495 #endif /* _RTW_MP_H_ */