staging: rtl8192e: Remove entry .rx_query_stat.. from struct rtl819x_ops
[linux-2.6-microblaze.git] / drivers / staging / rtl8192e / rtl8192e / rtl_core.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
4  *
5  * Based on the r8180 driver, which is:
6  * Copyright 2004-2005 Andrea Merello <andrea.merello@gmail.com>, et al.
7  *
8  * Contact Information: wlanfae <wlanfae@realtek.com>
9  */
10 #ifndef _RTL_CORE_H
11 #define _RTL_CORE_H
12
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/ioport.h>
16 #include <linux/sched.h>
17 #include <linux/types.h>
18 #include <linux/interrupt.h>
19 #include <linux/slab.h>
20 #include <linux/netdevice.h>
21 #include <linux/pci.h>
22 #include <linux/etherdevice.h>
23 #include <linux/delay.h>
24 #include <linux/rtnetlink.h>
25 #include <linux/wireless.h>
26 #include <linux/timer.h>
27 #include <linux/proc_fs.h>
28 #include <linux/if_arp.h>
29 #include <linux/random.h>
30 #include <linux/io.h>
31
32 /* Need this defined before including local include files */
33 #define DRV_NAME "rtl819xE"
34
35 #include "../rtllib.h"
36
37 #include "../dot11d.h"
38
39 #include "r8192E_firmware.h"
40 #include "r8192E_hw.h"
41
42 #include "r8190P_def.h"
43 #include "r8192E_dev.h"
44
45 #include "rtl_eeprom.h"
46 #include "rtl_ps.h"
47 #include "rtl_pci.h"
48 #include "rtl_cam.h"
49
50 #define DRV_COPYRIGHT           \
51         "Copyright(c) 2008 - 2010 Realsil Semiconductor Corporation"
52 #define DRV_AUTHOR  "<wlanfae@realtek.com>"
53 #define DRV_VERSION  "0014.0401.2010"
54
55 #define IS_HARDWARE_TYPE_8192SE(_priv)          \
56         (((struct r8192_priv *)rtllib_priv(dev))->card_8192 == NIC_8192SE)
57
58 #define RTL_PCI_DEVICE(vend, dev, cfg) \
59         .vendor = (vend), .device = (dev), \
60         .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, \
61         .driver_data = (kernel_ulong_t)&(cfg)
62
63 #define TOTAL_CAM_ENTRY         32
64 #define CAM_CONTENT_COUNT       8
65
66 #define HAL_HW_PCI_REVISION_ID_8192PCIE         0x01
67 #define HAL_HW_PCI_REVISION_ID_8192SE   0x10
68
69 #define RTL819X_DEFAULT_RF_TYPE         RF_1T2R
70
71 #define RTLLIB_WATCH_DOG_TIME           2000
72
73 #define MAX_DEV_ADDR_SIZE               8  /*support till 64 bit bus width OS*/
74 #define MAX_FIRMWARE_INFORMATION_SIZE   32
75 #define MAX_802_11_HEADER_LENGTH        (40 + MAX_FIRMWARE_INFORMATION_SIZE)
76 #define ENCRYPTION_MAX_OVERHEAD         128
77 #define MAX_FRAGMENT_COUNT              8
78 #define MAX_TRANSMIT_BUFFER_SIZE        \
79         (1600 + (MAX_802_11_HEADER_LENGTH + ENCRYPTION_MAX_OVERHEAD) *  \
80          MAX_FRAGMENT_COUNT)
81
82 #define CMDPACKET_FRAG_SIZE (4 * (MAX_TRANSMIT_BUFFER_SIZE / 4) - 8)
83
84 #define DEFAULT_FRAG_THRESHOLD  2342U
85 #define MIN_FRAG_THRESHOLD      256U
86 #define DEFAULT_BEACONINTERVAL  0x64U
87
88 #define DEFAULT_RETRY_RTS       7
89 #define DEFAULT_RETRY_DATA      7
90
91 #define PHY_RSSI_SLID_WIN_MAX                   100
92
93 #define TX_BB_GAIN_TABLE_LEN                    37
94 #define CCK_TX_BB_GAIN_TABLE_LEN                23
95
96 #define CHANNEL_PLAN_LEN                        10
97 #define S_CRC_LEN                               4
98
99 #define NIC_SEND_HANG_THRESHOLD_NORMAL          4
100 #define NIC_SEND_HANG_THRESHOLD_POWERSAVE       8
101
102 #define MAX_TX_QUEUE                            9
103
104 #define MAX_RX_QUEUE                            1
105
106 #define MAX_RX_COUNT                            64
107 #define MAX_TX_QUEUE_COUNT                      9
108
109 extern int hwwep;
110
111 enum nic_t {
112         NIC_UNKNOWN     = 0,
113         NIC_8192E       = 1,
114         NIC_8190P       = 2,
115         NIC_8192SE      = 4,
116         NIC_8192CE      = 5,
117         NIC_8192CU      = 6,
118         NIC_8192DE      = 7,
119         NIC_8192DU      = 8,
120 };
121
122 enum rt_eeprom_type {
123         EEPROM_93C46,
124         EEPROM_93C56,
125 };
126
127 enum dcmg_txcmd_op {
128         TXCMD_TXRA_HISTORY_CTRL         = 0xFF900000,
129         TXCMD_RESET_TX_PKT_BUFF         = 0xFF900001,
130         TXCMD_RESET_RX_PKT_BUFF         = 0xFF900002,
131         TXCMD_SET_TX_DURATION           = 0xFF900003,
132         TXCMD_SET_RX_RSSI               = 0xFF900004,
133         TXCMD_SET_TX_PWR_TRACKING       = 0xFF900005,
134         TXCMD_XXXX_CTRL,
135 };
136
137 enum rt_rf_type_819xu {
138         RF_TYPE_MIN = 0,
139         RF_8225,
140         RF_8256,
141         RF_8258,
142         RF_6052 = 4,
143         RF_PSEUDO_11N = 5,
144 };
145
146 enum rt_customer_id {
147         RT_CID_DEFAULT    = 0,
148         RT_CID_819x_CAMEO       = 6,
149         RT_CID_819x_RUNTOP      = 7,
150         RT_CID_TOSHIBA    = 9,
151         RT_CID_819X_NETCORE     = 10,
152         RT_CID_Nettronix        = 11,
153         RT_CID_DLINK        = 12,
154         RT_CID_PRONET      = 13,
155 };
156
157 enum reset_type {
158         RESET_TYPE_NORESET = 0x00,
159         RESET_TYPE_NORMAL = 0x01,
160         RESET_TYPE_SILENT = 0x02
161 };
162
163 struct rt_stats {
164         unsigned long received_rate_histogram[4][32];
165         unsigned long txbytesunicast;
166         unsigned long rxbytesunicast;
167         unsigned long txretrycount;
168         u8      last_packet_rate;
169         unsigned long slide_signal_strength[100];
170         unsigned long slide_evm[100];
171         unsigned long   slide_rssi_total;
172         unsigned long slide_evm_total;
173         long signal_strength;
174         long last_signal_strength_inpercent;
175         long    recv_signal_power;
176         u8 rx_rssi_percentage[4];
177         u8 rx_evm_percentage[2];
178         u32 slide_beacon_pwdb[100];
179         u32 slide_beacon_total;
180         u32     CurrentShowTxate;
181 };
182
183 struct init_gain {
184         u8      xaagccore1;
185         u8      xbagccore1;
186         u8      xcagccore1;
187         u8      xdagccore1;
188         u8      cca;
189
190 };
191
192 struct tx_ring {
193         u32 *desc;
194         u8 nStuckCount;
195         struct tx_ring *next;
196 } __packed;
197
198 struct rtl8192_tx_ring {
199         struct tx_desc *desc;
200         dma_addr_t dma;
201         unsigned int idx;
202         unsigned int entries;
203         struct sk_buff_head queue;
204 };
205
206 struct rtl819x_ops {
207         enum nic_t nic_type;
208         void (*init_before_adapter_start)(struct net_device *dev);
209         void (*link_change)(struct net_device *dev);
210         bool (*rx_command_packet_handler)(struct net_device *dev,
211                                           struct sk_buff *skb,
212                                           struct rx_desc *pdesc);
213         void (*stop_adapter)(struct net_device *dev, bool reset);
214         void (*update_ratr_table)(struct net_device *dev);
215         void (*irq_enable)(struct net_device *dev);
216         void (*irq_disable)(struct net_device *dev);
217         void (*irq_clear)(struct net_device *dev);
218         void (*rx_enable)(struct net_device *dev);
219         void (*tx_enable)(struct net_device *dev);
220         void (*interrupt_recognized)(struct net_device *dev,
221                                      u32 *p_inta, u32 *p_intb);
222         bool (*tx_check_stuck_handler)(struct net_device *dev);
223         bool (*rx_check_stuck_handler)(struct net_device *dev);
224 };
225
226 struct r8192_priv {
227         struct pci_dev *pdev;
228         struct pci_dev *bridge_pdev;
229
230         bool            bfirst_after_down;
231         bool            being_init_adapter;
232
233         int             irq;
234         short   irq_enabled;
235
236         short   up;
237         short   up_first_time;
238         struct delayed_work             update_beacon_wq;
239         struct delayed_work             watch_dog_wq;
240         struct delayed_work             txpower_tracking_wq;
241         struct delayed_work             rfpath_check_wq;
242         struct delayed_work             gpio_change_rf_wq;
243         struct rtl819x_ops                      *ops;
244         struct rtllib_device                    *rtllib;
245
246         struct work_struct                              reset_wq;
247
248         enum rt_customer_id customer_id;
249
250         enum rt_rf_type_819xu rf_chip;
251         enum ht_channel_width current_chnl_bw;
252         struct bb_reg_definition phy_reg_def[4];
253         struct rate_adaptive rate_adaptive;
254
255         struct rt_firmware *fw_info;
256         enum rtl819x_loopback loopback_mode;
257
258         struct timer_list                       watch_dog_timer;
259         struct timer_list                       fsync_timer;
260         struct timer_list                       gpio_polling_timer;
261
262         spinlock_t                              irq_th_lock;
263         spinlock_t                              tx_lock;
264         spinlock_t                              rf_ps_lock;
265         spinlock_t                              ps_lock;
266
267         struct sk_buff_head             skb_queue;
268
269         struct tasklet_struct           irq_rx_tasklet;
270         struct tasklet_struct           irq_tx_tasklet;
271         struct tasklet_struct           irq_prepare_beacon_tasklet;
272
273         struct mutex                            wx_mutex;
274         struct mutex                            rf_mutex;
275         struct mutex                            mutex;
276
277         struct rt_stats stats;
278         struct iw_statistics                    wstats;
279
280         short (*rf_set_sens)(struct net_device *dev, short sens);
281         u8 (*rf_set_chan)(struct net_device *dev, u8 ch);
282
283         struct rx_desc *rx_ring[MAX_RX_QUEUE];
284         struct sk_buff  *rx_buf[MAX_RX_QUEUE][MAX_RX_COUNT];
285         dma_addr_t      rx_ring_dma[MAX_RX_QUEUE];
286         unsigned int    rx_idx[MAX_RX_QUEUE];
287         int             rxringcount;
288         u16             rxbuffersize;
289
290         u64 last_rx_desc_tsf;
291
292         u32 receive_config;
293         u8              retry_data;
294         u8              retry_rts;
295         u16             rts;
296
297         struct rtl8192_tx_ring tx_ring[MAX_TX_QUEUE_COUNT];
298         int              txringcount;
299         atomic_t        tx_pending[0x10];
300
301         u16 short_retry_limit;
302         u16 long_retry_limit;
303
304         bool            hw_radio_off;
305         bool            blinked_ingpio;
306         u8              polling_timer_on;
307
308         /**********************************************************/
309
310         enum card_type {
311                 PCI, MINIPCI,
312                 CARDBUS, USB
313         } card_type;
314
315         struct work_struct qos_activate;
316
317         short   promisc;
318
319         short   chan;
320         short   sens;
321         short   max_sens;
322         bool ps_force;
323
324         u32 irq_mask[2];
325
326         u8 rf_mode;
327         enum nic_t card_8192;
328         u8 card_8192_version;
329
330         u8 rf_type;
331         u8 ic_cut;
332         char nick[IW_ESSID_MAX_SIZE + 1];
333         u8 check_roaming_cnt;
334
335         u32 silent_reset_rx_slot_index;
336         u32 silent_reset_rx_stuck_event[MAX_SILENT_RESET_RX_SLOT_NUM];
337
338         u16 basic_rate;
339         u8 short_preamble;
340         u8 dot11_current_preamble_mode;
341         u8 slot_time;
342
343         bool autoload_fail_flag;
344
345         short   epromtype;
346         u16 eeprom_vid;
347         u16 eeprom_did;
348         u8 eeprom_customer_id;
349         u16 eeprom_chnl_plan;
350
351         u8 eeprom_tx_pwr_level_cck[14];
352         u8 eeprom_tx_pwr_level_ofdm24g[14];
353         u16 eeprom_ant_pwr_diff;
354         u8 eeprom_thermal_meter;
355         u8 eeprom_crystal_cap;
356
357         u8 eeprom_legacy_ht_tx_pwr_diff;
358
359         u8 crystal_cap;
360         u8 thermal_meter[2];
361
362         u8 sw_chnl_in_progress;
363         u8 sw_chnl_stage;
364         u8 sw_chnl_step;
365         u8 set_bw_mode_in_progress;
366
367         u8 n_cur_40mhz_prime_sc;
368
369         u32 rf_reg_0value[4];
370         u8 num_total_rf_path;
371         bool brfpath_rxenable[4];
372
373         bool tx_pwr_data_read_from_eeprom;
374
375         u16 reg_chnl_plan;
376         u16 chnl_plan;
377         u8 hw_rf_off_action;
378
379         bool rf_change_in_progress;
380         bool set_rf_pwr_state_in_progress;
381         bool bdisable_nic;
382
383         u8 cck_pwr_enl;
384         u16 tssi_13dBm;
385         u32 pwr_track;
386         u8 cck_present_attn_20m_def;
387         u8 cck_present_attn_40m_def;
388         s8 cck_present_attn_diff;
389         s8 cck_present_attn;
390         long undecorated_smoothed_pwdb;
391
392         u32 mcs_tx_pwr_level_org_offset[6];
393         u8 tx_pwr_level_cck[14];
394         u8 tx_pwr_level_ofdm_24g[14];
395         u8 legacy_ht_tx_pwr_diff;
396         u8 antenna_tx_pwr_diff[3];
397
398         bool            dynamic_tx_high_pwr;
399         bool            dynamic_tx_low_pwr;
400         bool            last_dtp_flag_high;
401         bool            last_dtp_flag_low;
402
403         u8              rfa_txpowertrackingindex;
404         u8              rfa_txpowertrackingindex_real;
405         u8              rfa_txpowertracking_default;
406         u8              rfc_txpowertrackingindex;
407         u8              rfc_txpowertrackingindex_real;
408         bool            btxpower_tracking;
409         bool            bcck_in_ch14;
410
411         u8              txpower_count;
412         bool            tx_pwr_tracking_init;
413
414         u8              ofdm_index[2];
415         u8              cck_index;
416
417         u8              rec_cck_20m_idx;
418         u8              rec_cck_40m_idx;
419
420         struct init_gain initgain_backup;
421         u8              def_initial_gain[4];
422         bool            bis_any_nonbepkts;
423         bool            bcurrent_turbo_EDCA;
424         bool            bis_cur_rdlstate;
425
426         bool            bfsync_processing;
427         u32             rate_record;
428         u32             rate_count_diff_rec;
429         u32             continue_diff_count;
430         bool            bswitch_fsync;
431         u8              framesync;
432         u8              frame_sync_monitor;
433
434         u32             reset_count;
435
436         enum reset_type rst_progress;
437         u16             tx_counter;
438         u16             rx_ctr;
439         bool            reset_in_progress;
440         bool            force_reset;
441         bool            force_lps;
442
443         bool            chan_forced;
444 };
445
446 extern const struct ethtool_ops rtl819x_ethtool_ops;
447
448 u8 rtl92e_readb(struct net_device *dev, int x);
449 u32 rtl92e_readl(struct net_device *dev, int x);
450 u16 rtl92e_readw(struct net_device *dev, int x);
451 void rtl92e_writeb(struct net_device *dev, int x, u8 y);
452 void rtl92e_writew(struct net_device *dev, int x, u16 y);
453 void rtl92e_writel(struct net_device *dev, int x, u32 y);
454
455 void force_pci_posting(struct net_device *dev);
456
457 void rtl92e_rx_enable(struct net_device *dev);
458 void rtl92e_tx_enable(struct net_device *dev);
459
460 void rtl92e_hw_sleep_wq(void *data);
461 void rtl92e_commit(struct net_device *dev);
462
463 void rtl92e_check_rfctrl_gpio_timer(struct timer_list *t);
464
465 void rtl92e_hw_wakeup_wq(void *data);
466
467 void rtl92e_reset_desc_ring(struct net_device *dev);
468 void rtl92e_set_wireless_mode(struct net_device *dev, u8 wireless_mode);
469 void rtl92e_irq_enable(struct net_device *dev);
470 void rtl92e_config_rate(struct net_device *dev, u16 *rate_config);
471 void rtl92e_irq_disable(struct net_device *dev);
472
473 void rtl92e_update_rx_pkt_timestamp(struct net_device *dev,
474                                     struct rtllib_rx_stats *stats);
475 long rtl92e_translate_to_dbm(struct r8192_priv *priv, u8 signal_strength_index);
476 void rtl92e_update_rx_statistics(struct r8192_priv *priv,
477                                  struct rtllib_rx_stats *pprevious_stats);
478 u8 rtl92e_evm_db_to_percent(s8 value);
479 u8 rtl92e_rx_db_to_percent(s8 antpower);
480 void rtl92e_copy_mpdu_stats(struct rtllib_rx_stats *psrc_stats,
481                             struct rtllib_rx_stats *ptarget_stats);
482 bool rtl92e_enable_nic(struct net_device *dev);
483 bool rtl92e_disable_nic(struct net_device *dev);
484
485 bool rtl92e_set_rf_state(struct net_device *dev,
486                          enum rt_rf_power_state state_to_set,
487                          RT_RF_CHANGE_SOURCE change_source);
488 #endif