1 /******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
4 * Based on the r8180 driver, which is:
5 * Copyright 2004-2005 Andrea Merello <andrea.merello@gmail.com>, et al.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * The full GNU General Public License is included in this distribution in the
16 * file called LICENSE.
18 * Contact Information:
19 * wlanfae <wlanfae@realtek.com>
20 *****************************************************************************/
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/ioport.h>
28 #include <linux/sched.h>
29 #include <linux/types.h>
30 #include <linux/interrupt.h>
31 #include <linux/slab.h>
32 #include <linux/netdevice.h>
33 #include <linux/pci.h>
34 #include <linux/etherdevice.h>
35 #include <linux/delay.h>
36 #include <linux/rtnetlink.h>
37 #include <linux/wireless.h>
38 #include <linux/timer.h>
39 #include <linux/proc_fs.h>
40 #include <linux/if_arp.h>
41 #include <linux/random.h>
44 /* Need this defined before including local include files */
45 #define DRV_NAME "rtl819xE"
47 #include "../rtllib.h"
49 #include "../dot11d.h"
51 #include "r8192E_firmware.h"
52 #include "r8192E_hw.h"
54 #include "r8190P_def.h"
55 #include "r8192E_dev.h"
57 #include "rtl_eeprom.h"
62 #define DRV_COPYRIGHT \
63 "Copyright(c) 2008 - 2010 Realsil Semiconductor Corporation"
64 #define DRV_AUTHOR "<wlanfae@realtek.com>"
65 #define DRV_VERSION "0014.0401.2010"
67 #define IS_HARDWARE_TYPE_8192SE(_priv) \
68 (((struct r8192_priv *)rtllib_priv(dev))->card_8192 == NIC_8192SE)
70 #define RTL_PCI_DEVICE(vend, dev, cfg) \
71 .vendor = (vend), .device = (dev), \
72 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, \
73 .driver_data = (kernel_ulong_t)&(cfg)
75 #define TOTAL_CAM_ENTRY 32
76 #define CAM_CONTENT_COUNT 8
78 #define HAL_HW_PCI_REVISION_ID_8192PCIE 0x01
79 #define HAL_HW_PCI_REVISION_ID_8192SE 0x10
81 #define RTL819X_DEFAULT_RF_TYPE RF_1T2R
83 #define RTLLIB_WATCH_DOG_TIME 2000
85 #define MAX_DEV_ADDR_SIZE 8 /*support till 64 bit bus width OS*/
86 #define MAX_FIRMWARE_INFORMATION_SIZE 32
87 #define MAX_802_11_HEADER_LENGTH (40 + MAX_FIRMWARE_INFORMATION_SIZE)
88 #define ENCRYPTION_MAX_OVERHEAD 128
89 #define MAX_FRAGMENT_COUNT 8
90 #define MAX_TRANSMIT_BUFFER_SIZE \
91 (1600 + (MAX_802_11_HEADER_LENGTH + ENCRYPTION_MAX_OVERHEAD) * \
94 #define CMDPACKET_FRAG_SIZE (4 * (MAX_TRANSMIT_BUFFER_SIZE / 4) - 8)
96 #define DEFAULT_FRAG_THRESHOLD 2342U
97 #define MIN_FRAG_THRESHOLD 256U
98 #define DEFAULT_BEACONINTERVAL 0x64U
100 #define DEFAULT_RETRY_RTS 7
101 #define DEFAULT_RETRY_DATA 7
103 #define PHY_RSSI_SLID_WIN_MAX 100
105 #define TxBBGainTableLength 37
106 #define CCKTxBBGainTableLength 23
108 #define CHANNEL_PLAN_LEN 10
111 #define NIC_SEND_HANG_THRESHOLD_NORMAL 4
112 #define NIC_SEND_HANG_THRESHOLD_POWERSAVE 8
114 #define MAX_TX_QUEUE 9
116 #define MAX_RX_QUEUE 1
118 #define MAX_RX_COUNT 64
119 #define MAX_TX_QUEUE_COUNT 9
134 enum rt_eeprom_type {
140 TXCMD_TXRA_HISTORY_CTRL = 0xFF900000,
141 TXCMD_RESET_TX_PKT_BUFF = 0xFF900001,
142 TXCMD_RESET_RX_PKT_BUFF = 0xFF900002,
143 TXCMD_SET_TX_DURATION = 0xFF900003,
144 TXCMD_SET_RX_RSSI = 0xFF900004,
145 TXCMD_SET_TX_PWR_TRACKING = 0xFF900005,
149 enum rt_rf_type_819xu {
158 enum rt_customer_id {
160 RT_CID_8187_ALPHA0 = 1,
161 RT_CID_8187_SERCOMM_PS = 2,
162 RT_CID_8187_HW_LED = 3,
163 RT_CID_8187_NETGEAR = 4,
165 RT_CID_819x_CAMEO = 6,
166 RT_CID_819x_RUNTOP = 7,
167 RT_CID_819x_Senao = 8,
169 RT_CID_819x_Netcore = 10,
170 RT_CID_Nettronix = 11,
174 RT_CID_819x_ALPHA = 15,
175 RT_CID_819x_Sitecom = 16,
177 RT_CID_819x_Lenovo = 18,
178 RT_CID_819x_QMI = 19,
179 RT_CID_819x_Edimax_Belkin = 20,
180 RT_CID_819x_Sercomm_Belkin = 21,
181 RT_CID_819x_CAMEO1 = 22,
182 RT_CID_819x_MSI = 23,
183 RT_CID_819x_Acer = 24,
185 RT_CID_819x_CLEVO = 28,
186 RT_CID_819x_Arcadyan_Belkin = 29,
187 RT_CID_819x_SAMSUNG = 30,
188 RT_CID_819x_WNC_COREGA = 31,
192 RESET_TYPE_NORESET = 0x00,
193 RESET_TYPE_NORMAL = 0x01,
194 RESET_TYPE_SILENT = 0x02
200 unsigned long rxdatacrcerr;
201 unsigned long rxmgmtcrcerr;
202 unsigned long rxcrcerrmin;
203 unsigned long rxcrcerrmid;
204 unsigned long rxcrcerrmax;
205 unsigned long received_rate_histogram[4][32];
206 unsigned long received_preamble_GI[2][32];
207 unsigned long numpacket_matchbssid;
208 unsigned long numpacket_toself;
209 unsigned long num_process_phyinfo;
210 unsigned long numqry_phystatus;
211 unsigned long numqry_phystatusCCK;
212 unsigned long numqry_phystatusHT;
213 unsigned long received_bwtype[5];
214 unsigned long rxoverflow;
217 unsigned long shints;
218 unsigned long txoverflow;
219 unsigned long txbeokint;
220 unsigned long txbkokint;
221 unsigned long txviokint;
222 unsigned long txvookint;
223 unsigned long txbeaconokint;
224 unsigned long txbeaconerr;
225 unsigned long txmanageokint;
226 unsigned long txcmdpktokint;
227 unsigned long txbytesmulticast;
228 unsigned long txbytesbroadcast;
229 unsigned long txbytesunicast;
230 unsigned long rxbytesunicast;
231 unsigned long txretrycount;
233 unsigned long slide_signal_strength[100];
234 unsigned long slide_evm[100];
235 unsigned long slide_rssi_total;
236 unsigned long slide_evm_total;
237 long signal_strength;
239 long last_signal_strength_inpercent;
240 long recv_signal_power;
241 u8 rx_rssi_percentage[4];
242 u8 rx_evm_percentage[2];
244 u32 Slide_Beacon_pwdb[100];
245 u32 Slide_Beacon_Total;
246 u32 CurrentShowTxate;
249 struct channel_access_setting {
270 struct tx_ring *next;
273 struct rtl8192_tx_ring {
274 struct tx_desc *desc;
277 unsigned int entries;
278 struct sk_buff_head queue;
285 void (*get_eeprom_size)(struct net_device *dev);
286 void (*init_adapter_variable)(struct net_device *dev);
287 void (*init_before_adapter_start)(struct net_device *dev);
288 bool (*initialize_adapter)(struct net_device *dev);
289 void (*link_change)(struct net_device *dev);
290 void (*tx_fill_descriptor)(struct net_device *dev,
291 struct tx_desc *tx_desc,
292 struct cb_desc *cb_desc,
293 struct sk_buff *skb);
294 void (*tx_fill_cmd_descriptor)(struct net_device *dev,
295 struct tx_desc_cmd *entry,
296 struct cb_desc *cb_desc,
297 struct sk_buff *skb);
298 bool (*rx_query_status_descriptor)(struct net_device *dev,
299 struct rtllib_rx_stats *stats,
300 struct rx_desc *pdesc,
301 struct sk_buff *skb);
302 bool (*rx_command_packet_handler)(struct net_device *dev,
304 struct rx_desc *pdesc);
305 void (*stop_adapter)(struct net_device *dev, bool reset);
306 void (*update_ratr_table)(struct net_device *dev);
307 void (*irq_enable)(struct net_device *dev);
308 void (*irq_disable)(struct net_device *dev);
309 void (*irq_clear)(struct net_device *dev);
310 void (*rx_enable)(struct net_device *dev);
311 void (*tx_enable)(struct net_device *dev);
312 void (*interrupt_recognized)(struct net_device *dev,
313 u32 *p_inta, u32 *p_intb);
314 bool (*TxCheckStuckHandler)(struct net_device *dev);
315 bool (*RxCheckStuckHandler)(struct net_device *dev);
319 struct pci_dev *pdev;
320 struct pci_dev *bridge_pdev;
323 bool bfirst_after_down;
324 bool initialized_at_probe;
325 bool being_init_adapter;
326 bool bDriverIsGoingToUnload;
333 struct delayed_work update_beacon_wq;
334 struct delayed_work watch_dog_wq;
335 struct delayed_work txpower_tracking_wq;
336 struct delayed_work rfpath_check_wq;
337 struct delayed_work gpio_change_rf_wq;
339 struct channel_access_setting ChannelAccessSetting;
341 struct rtl819x_ops *ops;
342 struct rtllib_device *rtllib;
344 struct work_struct reset_wq;
346 struct log_int_8190 InterruptLog;
348 enum rt_customer_id CustomerID;
351 enum rt_rf_type_819xu rf_chip;
352 enum ht_channel_width CurrentChannelBW;
353 struct bb_reg_definition PHYRegDef[4];
354 struct rate_adaptive rate_adaptive;
356 enum acm_method AcmMethod;
358 struct rt_firmware *pFirmware;
359 enum rtl819x_loopback LoopbackMode;
361 struct timer_list watch_dog_timer;
362 struct timer_list fsync_timer;
363 struct timer_list gpio_polling_timer;
365 spinlock_t irq_th_lock;
367 spinlock_t rf_ps_lock;
370 struct sk_buff_head skb_queue;
372 struct tasklet_struct irq_rx_tasklet;
373 struct tasklet_struct irq_tx_tasklet;
374 struct tasklet_struct irq_prepare_beacon_tasklet;
376 struct mutex wx_mutex;
377 struct mutex rf_mutex;
380 struct rt_stats stats;
381 struct iw_statistics wstats;
383 short (*rf_set_sens)(struct net_device *dev, short sens);
384 u8 (*rf_set_chan)(struct net_device *dev, u8 ch);
386 struct rx_desc *rx_ring[MAX_RX_QUEUE];
387 struct sk_buff *rx_buf[MAX_RX_QUEUE][MAX_RX_COUNT];
388 dma_addr_t rx_ring_dma[MAX_RX_QUEUE];
389 unsigned int rx_idx[MAX_RX_QUEUE];
400 struct rtl8192_tx_ring tx_ring[MAX_TX_QUEUE_COUNT];
402 atomic_t tx_pending[0x10];
411 /**********************************************************/
418 struct work_struct qos_activate;
432 enum nic_t card_8192;
433 u8 card_8192_version;
437 char nick[IW_ESSID_MAX_SIZE + 1];
438 u8 check_roaming_cnt;
440 u32 SilentResetRxSlotIndex;
441 u32 SilentResetRxStuckEvent[MAX_SILENT_RESET_RX_SLOT_NUM];
445 u8 dot11CurrentPreambleMode;
449 bool AutoloadFailFlag;
454 u8 eeprom_CustomerID;
455 u16 eeprom_ChannelPlan;
457 u8 EEPROMTxPowerLevelCCK[14];
458 u8 EEPROMTxPowerLevelOFDM24G[14];
459 u8 EEPROMRfACCKChnl1TxPwLevel[3];
460 u8 EEPROMRfAOfdmChnlTxPwLevel[3];
461 u8 EEPROMRfCCCKChnl1TxPwLevel[3];
462 u8 EEPROMRfCOfdmChnlTxPwLevel[3];
464 u8 EEPROMThermalMeter;
467 u8 EEPROMLegacyHTTxPowerDiff;
475 u8 SetBWModeInProgress;
481 bool brfpath_rxenable[4];
483 bool bTXPowerDataReadFromEEPORM;
490 bool bInPowerSaveMode;
493 bool RFChangeInProgress;
494 bool SetRFPowerStateInProgress;
502 u8 CCKPresentAttentuation_20Mdefault;
503 u8 CCKPresentAttentuation_40Mdefault;
504 s8 CCKPresentAttentuation_difference;
505 s8 CCKPresentAttentuation;
506 long undecorated_smoothed_pwdb;
508 u32 MCSTxPowerLevelOriginalOffset[6];
509 u8 TxPowerLevelCCK[14];
510 u8 TxPowerLevelCCK_A[14];
511 u8 TxPowerLevelCCK_C[14];
512 u8 TxPowerLevelOFDM24G[14];
513 u8 TxPowerLevelOFDM24G_A[14];
514 u8 TxPowerLevelOFDM24G_C[14];
515 u8 LegacyHTTxPowerDiff;
517 u8 AntennaTxPwDiff[3];
519 bool bDynamicTxHighPower;
520 bool bDynamicTxLowPower;
521 bool bLastDTPFlag_High;
522 bool bLastDTPFlag_Low;
524 u8 rfa_txpowertrackingindex;
525 u8 rfa_txpowertrackingindex_real;
526 u8 rfa_txpowertracking_default;
527 u8 rfc_txpowertrackingindex;
528 u8 rfc_txpowertrackingindex_real;
529 bool btxpower_tracking;
533 bool btxpower_trackingInit;
538 u8 Record_CCK_20Mindex;
539 u8 Record_CCK_40Mindex;
541 struct init_gain initgain_backup;
542 u8 DefaultInitialGain[4];
543 bool bis_any_nonbepkts;
544 bool bcurrent_turbo_EDCA;
545 bool bis_cur_rdlstate;
547 bool bfsync_processing;
549 u32 rateCountDiffRecord;
550 u32 ContinueDiffCount;
558 enum reset_type ResetProgress;
559 bool bForcedSilentReset;
560 bool bDisableNormalResetCheck;
563 bool bResetInProgress;
573 extern const struct ethtool_ops rtl819x_ethtool_ops;
575 u8 rtl92e_readb(struct net_device *dev, int x);
576 u32 rtl92e_readl(struct net_device *dev, int x);
577 u16 rtl92e_readw(struct net_device *dev, int x);
578 void rtl92e_writeb(struct net_device *dev, int x, u8 y);
579 void rtl92e_writew(struct net_device *dev, int x, u16 y);
580 void rtl92e_writel(struct net_device *dev, int x, u32 y);
582 void force_pci_posting(struct net_device *dev);
584 void rtl92e_rx_enable(struct net_device *);
585 void rtl92e_tx_enable(struct net_device *);
587 void rtl92e_hw_sleep_wq(void *data);
588 void rtl92e_commit(struct net_device *dev);
590 void rtl92e_check_rfctrl_gpio_timer(unsigned long data);
592 void rtl92e_hw_wakeup_wq(void *data);
594 void rtl92e_reset_desc_ring(struct net_device *dev);
595 void rtl92e_set_wireless_mode(struct net_device *dev, u8 wireless_mode);
596 void rtl92e_irq_enable(struct net_device *dev);
597 void rtl92e_config_rate(struct net_device *dev, u16 *rate_config);
598 void rtl92e_irq_disable(struct net_device *dev);
600 void rtl92e_update_rx_pkt_timestamp(struct net_device *dev,
601 struct rtllib_rx_stats *stats);
602 long rtl92e_translate_to_dbm(struct r8192_priv *priv, u8 signal_strength_index);
603 void rtl92e_update_rx_statistics(struct r8192_priv *priv,
604 struct rtllib_rx_stats *pprevious_stats);
605 u8 rtl92e_evm_db_to_percent(s8 value);
606 u8 rtl92e_rx_db_to_percent(s8 antpower);
607 void rtl92e_copy_mpdu_stats(struct rtllib_rx_stats *psrc_stats,
608 struct rtllib_rx_stats *ptarget_stats);
609 bool rtl92e_enable_nic(struct net_device *dev);
610 bool rtl92e_disable_nic(struct net_device *dev);
612 bool rtl92e_set_rf_state(struct net_device *dev,
613 enum rt_rf_power_state StateToSet,
614 RT_RF_CHANGE_SOURCE ChangeSource);