Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rtl_core.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3  *
4  * Based on the r8180 driver, which is:
5  * Copyright 2004-2005 Andrea Merello <[email protected]>, 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.
9  *
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
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18  *
19  * The full GNU General Public License is included in this distribution in the
20  * file called LICENSE.
21  *
22  * Contact Information:
23  * wlanfae <[email protected]>
24 ******************************************************************************/
25 
26 #ifndef _RTL_CORE_H
27 #define _RTL_CORE_H
28 
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/init.h>
32 #include <linux/ioport.h>
33 #include <linux/sched.h>
34 #include <linux/types.h>
35 #include <linux/interrupt.h>
36 #include <linux/slab.h>
37 #include <linux/netdevice.h>
38 #include <linux/pci.h>
39 #include <linux/etherdevice.h>
40 #include <linux/delay.h>
41 #include <linux/rtnetlink.h>
42 #include <linux/wireless.h>
43 #include <linux/timer.h>
44 #include <linux/proc_fs.h>
45 #include <linux/if_arp.h>
46 #include <linux/random.h>
47 #include <linux/io.h>
48 
49 /* Need this defined before including local include files */
50 #define DRV_NAME "rtl819xE"
51 
52 #include "../rtllib.h"
53 
54 #include "../dot11d.h"
55 
56 #include "r8192E_firmware.h"
57 #include "r8192E_hw.h"
58 
59 #include "r8190P_def.h"
60 #include "r8192E_dev.h"
61 
62 #include "rtl_eeprom.h"
63 #include "rtl_ps.h"
64 #include "rtl_pci.h"
65 #include "rtl_cam.h"
66 
67 #define DRV_COPYRIGHT \
68  "Copyright(c) 2008 - 2010 Realsil Semiconductor Corporation"
69 #define DRV_AUTHOR "<[email protected]>"
70 #define DRV_VERSION "0014.0401.2010"
71 
72 #define IS_HARDWARE_TYPE_819xP(_priv) \
73  ((((struct r8192_priv *)rtllib_priv(dev))->card_8192 == NIC_8190P) || \
74  (((struct r8192_priv *)rtllib_priv(dev))->card_8192 == NIC_8192E))
75 #define IS_HARDWARE_TYPE_8192SE(_priv) \
76  (((struct r8192_priv *)rtllib_priv(dev))->card_8192 == NIC_8192SE)
77 #define IS_HARDWARE_TYPE_8192CE(_priv) \
78  (((struct r8192_priv *)rtllib_priv(dev))->card_8192 == NIC_8192CE)
79 #define IS_HARDWARE_TYPE_8192CU(_priv) \
80  (((struct r8192_priv *)rtllib_priv(dev))->card_8192 == NIC_8192CU)
81 #define IS_HARDWARE_TYPE_8192DE(_priv) \
82  (((struct r8192_priv *)rtllib_priv(dev))->card_8192 == NIC_8192DE)
83 #define IS_HARDWARE_TYPE_8192DU(_priv) \
84  (((struct r8192_priv *)rtllib_priv(dev))->card_8192 == NIC_8192DU)
85 
86 #define RTL_PCI_DEVICE(vend, dev, cfg) \
87  .vendor = (vend), .device = (dev), \
88  .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID , \
89  .driver_data = (kernel_ulong_t)&(cfg)
90 
91 #define irqreturn_type irqreturn_t
92 
93 #define rtl8192_interrupt(x, y, z) rtl8192_interrupt_rsl(x, y)
94 
95 #define RTL_MAX_SCAN_SIZE 128
96 
97 #define RTL_RATE_MAX 30
98 
99 #define TOTAL_CAM_ENTRY 32
100 #define CAM_CONTENT_COUNT 8
101 
102 #ifndef BIT
103 #define BIT(_i) (1<<(_i))
104 #endif
105 
106 #define IS_NIC_DOWN(priv) (!(priv)->up)
107 
108 #define IS_ADAPTER_SENDS_BEACON(dev) 0
109 
110 #define IS_UNDER_11N_AES_MODE(_rtllib) \
111  ((_rtllib->pHTInfo->bCurrentHTSupport == true) && \
112  (_rtllib->pairwise_key_type == KEY_TYPE_CCMP))
113 
114 #define HAL_MEMORY_MAPPED_IO_RANGE_8190PCI 0x1000
115 #define HAL_HW_PCI_REVISION_ID_8190PCI 0x00
116 #define HAL_MEMORY_MAPPED_IO_RANGE_8192PCIE 0x4000
117 #define HAL_HW_PCI_REVISION_ID_8192PCIE 0x01
118 #define HAL_MEMORY_MAPPED_IO_RANGE_8192SE 0x4000
119 #define HAL_HW_PCI_REVISION_ID_8192SE 0x10
120 #define HAL_HW_PCI_REVISION_ID_8192CE 0x1
121 #define HAL_MEMORY_MAPPED_IO_RANGE_8192CE 0x4000
122 #define HAL_HW_PCI_REVISION_ID_8192DE 0x0
123 #define HAL_MEMORY_MAPPED_IO_RANGE_8192DE 0x4000
124 
125 #define HAL_HW_PCI_8180_DEVICE_ID 0x8180
126 #define HAL_HW_PCI_8185_DEVICE_ID 0x8185
127 #define HAL_HW_PCI_8188_DEVICE_ID 0x8188
128 #define HAL_HW_PCI_8198_DEVICE_ID 0x8198
129 #define HAL_HW_PCI_8190_DEVICE_ID 0x8190
130 #define HAL_HW_PCI_8192_DEVICE_ID 0x8192
131 #define HAL_HW_PCI_8192SE_DEVICE_ID 0x8192
132 #define HAL_HW_PCI_8174_DEVICE_ID 0x8174
133 #define HAL_HW_PCI_8173_DEVICE_ID 0x8173
134 #define HAL_HW_PCI_8172_DEVICE_ID 0x8172
135 #define HAL_HW_PCI_8171_DEVICE_ID 0x8171
136 #define HAL_HW_PCI_0045_DEVICE_ID 0x0045
137 #define HAL_HW_PCI_0046_DEVICE_ID 0x0046
138 #define HAL_HW_PCI_0044_DEVICE_ID 0x0044
139 #define HAL_HW_PCI_0047_DEVICE_ID 0x0047
140 #define HAL_HW_PCI_700F_DEVICE_ID 0x700F
141 #define HAL_HW_PCI_701F_DEVICE_ID 0x701F
142 #define HAL_HW_PCI_DLINK_DEVICE_ID 0x3304
143 #define HAL_HW_PCI_8192CET_DEVICE_ID 0x8191
144 #define HAL_HW_PCI_8192CE_DEVICE_ID 0x8178
145 #define HAL_HW_PCI_8191CE_DEVICE_ID 0x8177
146 #define HAL_HW_PCI_8188CE_DEVICE_ID 0x8176
147 #define HAL_HW_PCI_8192CU_DEVICE_ID 0x8191
148 #define HAL_HW_PCI_8192DE_DEVICE_ID 0x092D
149 #define HAL_HW_PCI_8192DU_DEVICE_ID 0x092D
150 
151 #define RTL819X_DEFAULT_RF_TYPE RF_1T2R
152 
153 #define RTLLIB_WATCH_DOG_TIME 2000
154 
155 #define MAX_DEV_ADDR_SIZE 8 /*support till 64 bit bus width OS*/
156 #define MAX_FIRMWARE_INFORMATION_SIZE 32
157 #define MAX_802_11_HEADER_LENGTH (40 + MAX_FIRMWARE_INFORMATION_SIZE)
158 #define ENCRYPTION_MAX_OVERHEAD 128
159 #define MAX_FRAGMENT_COUNT 8
160 #define MAX_TRANSMIT_BUFFER_SIZE \
161  (1600 + (MAX_802_11_HEADER_LENGTH + ENCRYPTION_MAX_OVERHEAD) * \
162  MAX_FRAGMENT_COUNT)
163 
164 #define scrclng 4
165 
166 #define DEFAULT_FRAG_THRESHOLD 2342U
167 #define MIN_FRAG_THRESHOLD 256U
168 #define DEFAULT_BEACONINTERVAL 0x64U
169 
170 #define DEFAULT_SSID ""
171 #define DEFAULT_RETRY_RTS 7
172 #define DEFAULT_RETRY_DATA 7
173 #define PRISM_HDR_SIZE 64
174 
175 #define PHY_RSSI_SLID_WIN_MAX 100
176 
177 #define RTL_IOCTL_WPA_SUPPLICANT (SIOCIWFIRSTPRIV + 30)
178 
179 #define TxBBGainTableLength 37
180 #define CCKTxBBGainTableLength 23
181 
182 #define CHANNEL_PLAN_LEN 10
183 #define sCrcLng 4
184 
185 #define NIC_SEND_HANG_THRESHOLD_NORMAL 4
186 #define NIC_SEND_HANG_THRESHOLD_POWERSAVE 8
187 
188 #define MAX_TX_QUEUE 9
189 
190 #define MAX_RX_QUEUE 1
191 
192 #define MAX_RX_COUNT 64
193 #define MAX_TX_QUEUE_COUNT 9
194 
216 };
217 
218 enum nic_t {
227 };
228 
233 };
234 
239  TXCMD_SET_TX_DURATION = 0xFF900003,
240  TXCMD_SET_RX_RSSI = 0xFF900004,
243 };
244 
250  RF_6052 = 4,
252 };
253 
254 enum rf_step {
258 };
259 
260 enum rt_status {
265 };
266 
298 };
299 
304 };
305 
309 };
310 
318 };
319 
320 struct buffer {
321  struct buffer *next;
322  u32 *buf;
323  dma_addr_t dma;
324 
325 };
326 
328  unsigned int cmd;
329  struct {
330  unsigned char type;
331  unsigned char addr;
332  unsigned char page;
333  unsigned char length;
334  } head;
335  unsigned char buf[0xff];
336 };
337 
338 struct rt_tx_rahis {
339  u32 cck[4];
340  u32 ofdm[8];
341  u32 ht_mcs[4][16];
342 };
343 
345  char elements[4][100];
349 };
350 
351 struct rt_stats {
352  unsigned long txrdu;
353  unsigned long rxrdu;
354  unsigned long rxok;
355  unsigned long rxframgment;
356  unsigned long rxurberr;
357  unsigned long rxstaterr;
358  unsigned long rxdatacrcerr;
359  unsigned long rxmgmtcrcerr;
360  unsigned long rxcrcerrmin;
361  unsigned long rxcrcerrmid;
362  unsigned long rxcrcerrmax;
363  unsigned long received_rate_histogram[4][32];
364  unsigned long received_preamble_GI[2][32];
365  unsigned long rx_AMPDUsize_histogram[5];
366  unsigned long rx_AMPDUnum_histogram[5];
367  unsigned long numpacket_matchbssid;
368  unsigned long numpacket_toself;
369  unsigned long num_process_phyinfo;
370  unsigned long numqry_phystatus;
371  unsigned long numqry_phystatusCCK;
372  unsigned long numqry_phystatusHT;
373  unsigned long received_bwtype[5];
374  unsigned long txnperr;
375  unsigned long txnpdrop;
376  unsigned long txresumed;
377  unsigned long rxoverflow;
378  unsigned long rxint;
379  unsigned long txnpokint;
380  unsigned long ints;
381  unsigned long shints;
382  unsigned long txoverflow;
383  unsigned long txlpokint;
384  unsigned long txlpdrop;
385  unsigned long txlperr;
386  unsigned long txbeokint;
387  unsigned long txbedrop;
388  unsigned long txbeerr;
389  unsigned long txbkokint;
390  unsigned long txbkdrop;
391  unsigned long txbkerr;
392  unsigned long txviokint;
393  unsigned long txvidrop;
394  unsigned long txvierr;
395  unsigned long txvookint;
396  unsigned long txvodrop;
397  unsigned long txvoerr;
398  unsigned long txbeaconokint;
399  unsigned long txbeacondrop;
400  unsigned long txbeaconerr;
401  unsigned long txmanageokint;
402  unsigned long txmanagedrop;
403  unsigned long txmanageerr;
404  unsigned long txcmdpktokint;
405  unsigned long txdatapkt;
406  unsigned long txfeedback;
407  unsigned long txfeedbackok;
408  unsigned long txoktotal;
409  unsigned long txokbytestotal;
410  unsigned long txokinperiod;
411  unsigned long txmulticast;
412  unsigned long txbytesmulticast;
413  unsigned long txbroadcast;
414  unsigned long txbytesbroadcast;
415  unsigned long txunicast;
416  unsigned long txbytesunicast;
417  unsigned long rxbytesunicast;
418  unsigned long txfeedbackfail;
419  unsigned long txerrtotal;
420  unsigned long txerrbytestotal;
421  unsigned long txerrmulticast;
422  unsigned long txerrbroadcast;
423  unsigned long txerrunicast;
424  unsigned long txretrycount;
425  unsigned long txfeedbackretry;
427  unsigned long slide_signal_strength[100];
428  unsigned long slide_evm[100];
429  unsigned long slide_rssi_total;
430  unsigned long slide_evm_total;
437  long rxSNRdB[4];
443 };
444 
452 };
453 
461 };
462 
466 };
467 
468 struct ccktxbbgain {
470 };
471 
472 struct init_gain {
473  u8 xaagccore1;
474  u8 xbagccore1;
475  u8 xcagccore1;
476  u8 xdagccore1;
477  u8 cca;
478 
479 };
480 
481 struct tx_ring {
484  struct tx_ring *next;
485 } __packed;
486 
487 struct rtl8192_tx_ring {
488  struct tx_desc *desc;
489  dma_addr_t dma;
490  unsigned int idx;
491  unsigned int entries;
492  struct sk_buff_head queue;
493 };
494 
495 
496 
497 struct rtl819x_ops {
505  struct tx_desc *tx_desc,
506  struct cb_desc *cb_desc,
507  struct sk_buff *skb);
509  struct tx_desc_cmd *entry,
510  struct cb_desc *cb_desc,
511  struct sk_buff *skb);
513  struct rtllib_rx_stats *stats,
514  struct rx_desc *pdesc,
515  struct sk_buff *skb);
517  struct sk_buff *skb,
518  struct rx_desc *pdesc);
519  void (*stop_adapter)(struct net_device *dev, bool reset);
527  u32 *p_inta, u32 *p_intb);
530 };
531 
532 struct r8192_priv {
533  struct pci_dev *pdev;
535 
541 
542  int irq;
543  short irq_enabled;
544 
545  short up;
556 
558 
560 
562 
563  struct rtl819x_ops *ops;
565 
567 
569 
571 
572 
578 
581 
583 
585 
589 
593 
603 
606 
610 
613  struct mutex mutex;
614 
615  struct rt_stats stats;
618 
619  short (*rf_set_sens)(struct net_device *dev, short sens);
620  u8 (*rf_set_chan)(struct net_device *dev, u8 ch);
622  void (*rf_init)(struct net_device *dev);
623 
627  unsigned int rx_idx[MAX_RX_QUEUE];
630 
632 
640 
646 
652 
655  bool pwrdown;
658 
659  /**********************************************************/
660 
661  enum card_type {
664  } card_type;
665 
667 
669 
670  short promisc;
671  short crcmon;
672 
674 
675  short chan;
676  short sens;
677  short max_sens;
679 
681  bool ps_force;
682 
684 
688 
690 
694 
696  bool bHwAntDiv;
697 
700 
702 
704 
709 
710  void *scan_cmd;
712 
715 
718 
724 
726 
731 
737 
739 
742 
746 
747  short epromtype;
755 
759 
772 
778 
779 
788 
790 
793 
796 
801 
803 
807 
809 
813 
814  bool RegRfOff;
815  bool isRFOff;
818 
823 
827 
829 
833 
834  u32 APKoutput[2][2];
835  bool bAPKdone;
836 
837  long RegE94;
838  long RegE9C;
839  long RegEB4;
840  long RegEBC;
841 
847 
850 
852 
854  u8 PwrGroupHT20[2][14];
855  u8 PwrGroupHT40[2][14];
856 
864 
867 
878 
903 
909 
912 
921 
925 
928 
931 
937 
939 
942 
951 
954 
956 
959 
966 
975  bool force_lps;
977 
980  bool RegBoard;
987 
992 
997 
1000 
1001 
1002 };
1003 
1004 extern const struct ethtool_ops rtl819x_ethtool_ops;
1005 
1006 void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb);
1007 short rtl8192_tx(struct net_device *dev, struct sk_buff *skb);
1008 
1009 u8 read_nic_io_byte(struct net_device *dev, int x);
1010 u32 read_nic_io_dword(struct net_device *dev, int x);
1011 u16 read_nic_io_word(struct net_device *dev, int x) ;
1012 void write_nic_io_byte(struct net_device *dev, int x, u8 y);
1013 void write_nic_io_word(struct net_device *dev, int x, u16 y);
1014 void write_nic_io_dword(struct net_device *dev, int x, u32 y);
1015 
1016 u8 read_nic_byte(struct net_device *dev, int x);
1017 u32 read_nic_dword(struct net_device *dev, int x);
1018 u16 read_nic_word(struct net_device *dev, int x) ;
1019 void write_nic_byte(struct net_device *dev, int x, u8 y);
1020 void write_nic_word(struct net_device *dev, int x, u16 y);
1021 void write_nic_dword(struct net_device *dev, int x, u32 y);
1022 
1023 void force_pci_posting(struct net_device *dev);
1024 
1025 void rtl8192_rx_enable(struct net_device *);
1026 void rtl8192_tx_enable(struct net_device *);
1027 
1028 int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev);
1029 void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1030  int rate);
1031 void rtl8192_data_hard_stop(struct net_device *dev);
1033 void rtl8192_restart(void *data);
1034 void rtl819x_watchdog_wqcallback(void *data);
1035 void rtl8192_hw_sleep_wq(void *data);
1036 void watch_dog_timer_callback(unsigned long data);
1037 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
1038 void rtl8192_irq_tx_tasklet(struct r8192_priv *priv);
1039 int rtl8192_down(struct net_device *dev, bool shutdownrf);
1040 int rtl8192_up(struct net_device *dev);
1041 void rtl8192_commit(struct net_device *dev);
1042 void rtl8192_set_chan(struct net_device *dev, short ch);
1043 
1044 void check_rfctrl_gpio_timer(unsigned long data);
1045 
1046 void rtl8192_hw_wakeup_wq(void *data);
1047 irqreturn_type rtl8192_interrupt(int irq, void *netdev, struct pt_regs *regs);
1048 
1049 short rtl8192_pci_initdescring(struct net_device *dev);
1050 
1052 
1053 int _rtl8192_up(struct net_device *dev, bool is_silent_reset);
1054 
1056 void rtl8192_irq_disable(struct net_device *dev);
1057 
1058 void rtl8192_tx_timeout(struct net_device *dev);
1061 void rtl8192_irq_enable(struct net_device *dev);
1062 void rtl8192_config_rate(struct net_device *dev, u16 *rate_config);
1063 void rtl8192_update_cap(struct net_device *dev, u16 cap);
1064 void rtl8192_irq_disable(struct net_device *dev);
1065 
1067  struct rtllib_rx_stats *stats);
1068 long rtl819x_translate_todbm(struct r8192_priv *priv, u8 signal_strength_index);
1070  struct rtllib_rx_stats *pprevious_stats);
1073  struct rtllib_rx_stats *pprevious_stats);
1074 u8 rtl819x_query_rxpwrpercentage(char antpower);
1075 void rtl8192_record_rxdesc_forlateruse(struct rtllib_rx_stats *psrc_stats,
1076  struct rtllib_rx_stats *ptarget_stats);
1077 bool NicIFEnableNIC(struct net_device *dev);
1078 bool NicIFDisableNIC(struct net_device *dev);
1079 
1080 bool MgntActSet_RF_State(struct net_device *dev,
1081  enum rt_rf_power_state StateToSet,
1082  RT_RF_CHANGE_SOURCE ChangeSource,
1083  bool ProtectOrNot);
1085  enum wireless_mode WirelessMode,
1087 
1088 /* proc stuff from rtl_debug.c */
1089 void rtl8192_proc_init_one(struct net_device *dev);
1090 void rtl8192_proc_remove_one(struct net_device *dev);
1091 void rtl8192_proc_module_init(void);
1092 void rtl8192_proc_module_remove(void);
1093 
1094 #endif