staging: r8188eu: introduce new include dir for RTL8188eu driver
[linux-2.6-microblaze.git] / drivers / staging / r8188eu / 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 #define MAX_MP_XMITBUF_SZ       2048
103 #define NR_MP_XMITFRAME         8
104
105 struct mp_xmit_frame {
106         struct list_head list;
107         struct pkt_attrib attrib;
108         struct sk_buff *pkt;
109         int frame_tag;
110         struct adapter *padapter;
111         struct urb *pxmit_urb[8];
112         /* insert urb, irp, and irpcnt info below... */
113         u8 *mem_addr;
114         u32 sz[8];
115         u8 bpending[8];
116         int ac_tag[8];
117         int last[8];
118         uint irpcnt;
119         uint fragcnt;
120         uint mem[(MAX_MP_XMITBUF_SZ >> 2)];
121 };
122
123 struct mp_wiparam {
124         u32 bcompleted;
125         u32 act_type;
126         u32 io_offset;
127         u32 io_value;
128 };
129
130 typedef void(*wi_act_func)(void *padapter);
131
132 struct mp_tx {
133         u8 stop;
134         u32 count, sended;
135         u8 payload;
136         struct pkt_attrib attrib;
137         struct tx_desc desc;
138         u8 *pallocated_buf;
139         u8 *buf;
140         u32 buf_size, write_size;
141         void *PktTxThread;
142 };
143
144 #include <Hal8188EPhyCfg.h>
145
146 #define MP_MAX_LINES            1000
147 #define MP_MAX_LINES_BYTES      256
148
149 typedef void (*MPT_WORK_ITEM_HANDLER)(void *Adapter);
150
151 struct mpt_context {
152         /*  Indicate if we have started Mass Production Test. */
153         bool                    bMassProdTest;
154
155         /*  Indicate if the driver is unloading or unloaded. */
156         bool                    bMptDrvUnload;
157
158         struct semaphore MPh2c_Sema;
159         struct timer_list MPh2c_timeout_timer;
160 /*  Event used to sync H2c for BT control */
161
162         bool            MptH2cRspEvent;
163         bool            MptBtC2hEvent;
164         bool            bMPh2c_timeout;
165
166         /* 8190 PCI does not support NDIS_WORK_ITEM. */
167         /*  Work Item for Mass Production Test. */
168         /*  Event used to sync the case unloading driver and MptWorkItem
169          *  is still in progress. */
170         /*  Indicate a MptWorkItem is scheduled and not yet finished. */
171         bool                    bMptWorkItemInProgress;
172         /*  An instance which implements function and context of MptWorkItem. */
173         MPT_WORK_ITEM_HANDLER   CurrMptAct;
174
175         /*  1=Start, 0=Stop from UI. */
176         u32     MptTestStart;
177         /*  _TEST_MODE, defined in MPT_Req2.h */
178         u32     MptTestItem;
179         /*  Variable needed in each implementation of CurrMptAct. */
180         u32     MptActType;     /*  Type of action performed in CurrMptAct. */
181         /*  The Offset of IO operation is depend of MptActType. */
182         u32     MptIoOffset;
183         /*  The Value of IO operation is depend of MptActType. */
184         u32     MptIoValue;
185         /*  The RfPath of IO operation is depend of MptActType. */
186         u32     MptRfPath;
187
188         enum wireless_mode MptWirelessModeToSw; /*  Wireless mode to switch. */
189         u8      MptChannelToSw;         /*  Channel to switch. */
190         u8      MptInitGainToSet;       /*  Initial gain to set. */
191         u32     MptBandWidth;           /*  bandwidth to switch. */
192         u32     MptRateIndex;           /*  rate index. */
193         /*  Register value kept for Single Carrier Tx test. */
194         u8      btMpCckTxPower;
195         /*  Register value kept for Single Carrier Tx test. */
196         u8      btMpOfdmTxPower;
197         /*  For MP Tx Power index */
198         u8      TxPwrLevel[2];  /*  rf-A, rf-B */
199
200         /*  Content of RCR Regsiter for Mass Production Test. */
201         u32     MptRCR;
202         /*  true if we only receive packets with specific pattern. */
203         bool    bMptFilterPattern;
204         /*  Rx OK count, statistics used in Mass Production Test. */
205         u32     MptRxOkCnt;
206         /*  Rx CRC32 error count, statistics used in Mass Production Test. */
207         u32     MptRxCrcErrCnt;
208
209         bool    bCckContTx;     /*  true if we are in CCK Continuous Tx test. */
210         bool    bOfdmContTx;    /*  true if we are in OFDM Continuous Tx test. */
211         bool    bStartContTx;   /*  true if we have start Continuous Tx test. */
212         /*  true if we are in Single Carrier Tx test. */
213         bool    bSingleCarrier;
214         /*  true if we are in Carrier Suppression Tx Test. */
215         bool    bCarrierSuppression;
216         /* true if we are in Single Tone Tx test. */
217         bool    bSingleTone;
218
219         /*  ACK counter asked by K.Y.. */
220         bool    bMptEnableAckCounter;
221         u32     MptAckCounter;
222
223         u8      APK_bound[2];   /* for APK      path A/path B */
224         bool    bMptIndexEven;
225
226         u8      backup0xc50;
227         u8      backup0xc58;
228         u8      backup0xc30;
229         u8      backup0x52_RF_A;
230         u8      backup0x52_RF_B;
231
232         u8      h2cReqNum;
233         u8      c2hBuf[20];
234
235         u8      btInBuf[100];
236         u32     mptOutLen;
237         u8      mptOutBuf[100];
238 };
239
240 enum {
241         WRITE_REG = 1,
242         READ_REG,
243         WRITE_RF,
244         READ_RF,
245         MP_START,
246         MP_STOP,
247         MP_RATE,
248         MP_CHANNEL,
249         MP_BANDWIDTH,
250         MP_TXPOWER,
251         MP_ANT_TX,
252         MP_ANT_RX,
253         MP_CTX,
254         MP_QUERY,
255         MP_ARX,
256         MP_PSD,
257         MP_PWRTRK,
258         MP_THER,
259         MP_IOCTL,
260         EFUSE_GET,
261         EFUSE_SET,
262         MP_RESET_STATS,
263         MP_DUMP,
264         MP_PHYPARA,
265         MP_SetRFPathSwh,
266         MP_QueryDrvStats,
267         MP_SetBT,
268         CTA_TEST,
269         MP_NULL,
270 };
271
272 struct mp_priv {
273         struct adapter *papdater;
274
275         /* Testing Flag */
276         /* 0 for normal type packet, 1 for loopback packet (16bytes TXCMD) */
277         u32 mode;
278
279         u32 prev_fw_state;
280
281         /* OID cmd handler */
282         struct mp_wiparam workparam;
283
284         /* Tx Section */
285         u8 TID;
286         u32 tx_pktcount;
287         struct mp_tx tx;
288
289         /* Rx Section */
290         u32 rx_pktcount;
291         u32 rx_crcerrpktcount;
292         u32 rx_pktloss;
293
294         struct recv_stat rxstat;
295
296         /* RF/BB relative */
297         u8 channel;
298         u8 bandwidth;
299         u8 prime_channel_offset;
300         u8 txpoweridx;
301         u8 txpoweridx_b;
302         u8 rateidx;
303         u32 preamble;
304         u32 CrystalCap;
305
306         u16 antenna_tx;
307         u16 antenna_rx;
308
309         u8 check_mp_pkt;
310
311         u8 bSetTxPower;
312
313         struct wlan_network mp_network;
314         unsigned char network_macaddr[ETH_ALEN];
315
316         u8 *pallocated_mp_xmitframe_buf;
317         u8 *pmp_xmtframe_buf;
318         struct __queue free_mp_xmitqueue;
319         u32 free_mp_xmitframe_cnt;
320
321         struct mpt_context MptCtx;
322 };
323
324 struct iocmd_struct {
325         u8      cmdclass;
326         u16     value;
327         u8      index;
328 };
329
330 struct rf_reg_param {
331         u32 path;
332         u32 offset;
333         u32 value;
334 };
335
336 struct bb_reg_param {
337         u32 offset;
338         u32 value;
339 };
340 /*  */
341
342 #define LOWER   true
343 #define RAISE   false
344
345 /* Hardware Registers */
346 #define BB_REG_BASE_ADDR                0x800
347
348 /* MP variables */
349 enum mp_mode_{
350         MP_OFF,
351         MP_ON,
352         MP_ERR,
353         MP_CONTINUOUS_TX,
354         MP_SINGLE_CARRIER_TX,
355         MP_CARRIER_SUPPRISSION_TX,
356         MP_SINGLE_TONE_TX,
357         MP_PACKET_TX,
358         MP_PACKET_RX
359 };
360
361 extern u8 mpdatarate[NumRates];
362
363 /* MP set force data rate base on the definition. */
364 enum mpt_rate_index {
365         /* CCK rate. */
366         MPT_RATE_1M,    /* 0 */
367         MPT_RATE_2M,
368         MPT_RATE_55M,
369         MPT_RATE_11M,   /* 3 */
370
371         /* OFDM rate. */
372         MPT_RATE_6M,    /* 4 */
373         MPT_RATE_9M,
374         MPT_RATE_12M,
375         MPT_RATE_18M,
376         MPT_RATE_24M,
377         MPT_RATE_36M,
378         MPT_RATE_48M,
379         MPT_RATE_54M,   /* 11 */
380
381         /* HT rate. */
382         MPT_RATE_MCS0,  /* 12 */
383         MPT_RATE_MCS1,
384         MPT_RATE_MCS2,
385         MPT_RATE_MCS3,
386         MPT_RATE_MCS4,
387         MPT_RATE_MCS5,
388         MPT_RATE_MCS6,
389         MPT_RATE_MCS7,  /* 19 */
390         MPT_RATE_MCS8,
391         MPT_RATE_MCS9,
392         MPT_RATE_MCS10,
393         MPT_RATE_MCS11,
394         MPT_RATE_MCS12,
395         MPT_RATE_MCS13,
396         MPT_RATE_MCS14,
397         MPT_RATE_MCS15, /* 27 */
398         MPT_RATE_LAST
399 };
400
401 #define MAX_TX_PWR_INDEX_N_MODE 64      /*  0x3F */
402
403 enum power_mode {
404         POWER_LOW = 0,
405         POWER_NORMAL
406 };
407
408 #define RX_PKT_BROADCAST        1
409 #define RX_PKT_DEST_ADDR        2
410 #define RX_PKT_PHY_MATCH        3
411
412 enum encry_ctrl_state {
413         HW_CONTROL,             /* hw encryption& decryption */
414         SW_CONTROL,             /* sw encryption& decryption */
415         HW_ENCRY_SW_DECRY,      /* hw encryption & sw decryption */
416         SW_ENCRY_HW_DECRY       /* sw encryption & hw decryption */
417 };
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 void    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, struct tx_desc *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 u32     mp_query_psd(struct adapter *pAdapter, u8 *data);
464 void Hal_SetAntenna(struct adapter *pAdapter);
465 void Hal_SetBandwidth(struct adapter *pAdapter);
466 void Hal_SetTxPower(struct adapter *pAdapter);
467 void Hal_SetCarrierSuppressionTx(struct adapter *pAdapter, u8 bStart);
468 void Hal_SetSingleToneTx(struct adapter *pAdapter, u8 bStart);
469 void Hal_SetSingleCarrierTx (struct adapter *pAdapter, u8 bStart);
470 void Hal_SetContinuousTx (struct adapter *pAdapter, u8 bStart);
471 void Hal_SetBandwidth(struct adapter *pAdapter);
472 void Hal_SetDataRate(struct adapter *pAdapter);
473 void Hal_SetChannel(struct adapter *pAdapter);
474 void Hal_SetAntennaPathPower(struct adapter *pAdapter);
475 s32 Hal_SetThermalMeter(struct adapter *pAdapter, u8 target_ther);
476 s32 Hal_SetPowerTracking(struct adapter *padapter, u8 enable);
477 void Hal_GetPowerTracking(struct adapter *padapter, u8 * enable);
478 void Hal_GetThermalMeter(struct adapter *pAdapter, u8 *value);
479 void Hal_mpt_SwitchRfSetting(struct adapter *pAdapter);
480 void Hal_MPT_CCKTxPowerAdjust(struct adapter * Adapter, bool bInCH14);
481 void Hal_MPT_CCKTxPowerAdjustbyIndex(struct adapter *pAdapter, bool beven);
482 void Hal_SetCCKTxPower(struct adapter *pAdapter, u8 * TxPower);
483 void Hal_SetOFDMTxPower(struct adapter *pAdapter, u8 * TxPower);
484 void Hal_TriggerRFThermalMeter(struct adapter *pAdapter);
485 u8 Hal_ReadRFThermalMeter(struct adapter *pAdapter);
486 void Hal_SetCCKContinuousTx(struct adapter *pAdapter, u8 bStart);
487 void Hal_SetOFDMContinuousTx(struct adapter *pAdapter, u8 bStart);
488 void Hal_ProSetCrystalCap (struct adapter *pAdapter , u32 CrystalCapVal);
489 void _rtw_mp_xmit_priv(struct xmit_priv *pxmitpriv);
490 void MP_PHY_SetRFPathSwitch(struct adapter *pAdapter ,bool bMain);
491
492 #endif /* _RTW_MP_H_ */