Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sw.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2012 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  * The full GNU General Public License is included in this distribution in the
19  * file called LICENSE.
20  *
21  * Contact Information:
22  * wlanfae <[email protected]>
23  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24  * Hsinchu 300, Taiwan.
25  *
26  * Larry Finger <[email protected]>
27  *
28  *****************************************************************************/
29 
30 #include "../wifi.h"
31 #include "../core.h"
32 #include "../usb.h"
33 #include "../efuse.h"
34 #include "reg.h"
35 #include "def.h"
36 #include "phy.h"
37 #include "mac.h"
38 #include "dm.h"
39 #include "rf.h"
40 #include "sw.h"
41 #include "trx.h"
42 #include "led.h"
43 #include "hw.h"
44 #include <linux/module.h>
45 
47 MODULE_AUTHOR("Ziv Huang <[email protected]>");
48 MODULE_AUTHOR("Larry Finger <[email protected]>");
49 MODULE_LICENSE("GPL");
50 MODULE_DESCRIPTION("Realtek 8192C/8188C 802.11n USB wireless");
51 MODULE_FIRMWARE("rtlwifi/rtl8192cufw.bin");
52 
53 static int rtl92cu_init_sw_vars(struct ieee80211_hw *hw)
54 {
55  struct rtl_priv *rtlpriv = rtl_priv(hw);
56  int err;
57 
58  rtlpriv->dm.dm_initialgain_enable = true;
59  rtlpriv->dm.dm_flag = 0;
60  rtlpriv->dm.disable_framebursting = false;
61  rtlpriv->dm.thermalvalue = 0;
62  rtlpriv->dbg.global_debuglevel = rtlpriv->cfg->mod_params->debug;
63 
64  /* for firmware buf */
65  rtlpriv->rtlhal.pfirmware = vzalloc(0x4000);
66  if (!rtlpriv->rtlhal.pfirmware) {
67  RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
68  "Can't alloc buffer for fw\n");
69  return 1;
70  }
71 
72  pr_info("Loading firmware %s\n", rtlpriv->cfg->fw_name);
73  rtlpriv->max_fw_size = 0x4000;
75  rtlpriv->cfg->fw_name, rtlpriv->io.dev,
76  GFP_KERNEL, hw, rtl_fw_cb);
77 
78 
79  return 0;
80 }
81 
82 static void rtl92cu_deinit_sw_vars(struct ieee80211_hw *hw)
83 {
84  struct rtl_priv *rtlpriv = rtl_priv(hw);
85 
86  if (rtlpriv->rtlhal.pfirmware) {
87  vfree(rtlpriv->rtlhal.pfirmware);
88  rtlpriv->rtlhal.pfirmware = NULL;
89  }
90 }
91 
92 static struct rtl_hal_ops rtl8192cu_hal_ops = {
93  .init_sw_vars = rtl92cu_init_sw_vars,
94  .deinit_sw_vars = rtl92cu_deinit_sw_vars,
95  .read_chip_version = rtl92c_read_chip_version,
96  .read_eeprom_info = rtl92cu_read_eeprom_info,
97  .enable_interrupt = rtl92c_enable_interrupt,
98  .disable_interrupt = rtl92c_disable_interrupt,
99  .hw_init = rtl92cu_hw_init,
100  .hw_disable = rtl92cu_card_disable,
101  .set_network_type = rtl92cu_set_network_type,
102  .set_chk_bssid = rtl92cu_set_check_bssid,
103  .set_qos = rtl92c_set_qos,
105  .set_bcn_intv = rtl92cu_set_beacon_interval,
106  .update_interrupt_mask = rtl92cu_update_interrupt_mask,
107  .get_hw_reg = rtl92cu_get_hw_reg,
108  .set_hw_reg = rtl92cu_set_hw_reg,
109  .update_rate_tbl = rtl92cu_update_hal_rate_table,
110  .update_rate_mask = rtl92cu_update_hal_rate_mask,
111  .fill_tx_desc = rtl92cu_tx_fill_desc,
112  .fill_fake_txdesc = rtl92cu_fill_fake_txdesc,
113  .fill_tx_cmddesc = rtl92cu_tx_fill_cmddesc,
114  .cmd_send_packet = rtl92cu_cmd_send_packet,
115  .query_rx_desc = rtl92cu_rx_query_desc,
116  .set_channel_access = rtl92cu_update_channel_access_setting,
117  .radio_onoff_checking = rtl92cu_gpio_radio_on_off_checking,
118  .set_bw_mode = rtl92c_phy_set_bw_mode,
119  .switch_channel = rtl92c_phy_sw_chnl,
120  .dm_watchdog = rtl92c_dm_watchdog,
121  .scan_operation_backup = rtl92c_phy_scan_operation_backup,
122  .set_rf_power_state = rtl92cu_phy_set_rf_power_state,
123  .led_control = rtl92cu_led_control,
124  .enable_hw_sec = rtl92cu_enable_hw_security_config,
125  .set_key = rtl92c_set_key,
126  .init_sw_leds = rtl92cu_init_sw_leds,
127  .deinit_sw_leds = rtl92cu_deinit_sw_leds,
128  .get_bbreg = rtl92c_phy_query_bb_reg,
129  .set_bbreg = rtl92c_phy_set_bb_reg,
130  .get_rfreg = rtl92cu_phy_query_rf_reg,
131  .set_rfreg = rtl92cu_phy_set_rf_reg,
132  .phy_rf6052_config = rtl92cu_phy_rf6052_config,
133  .phy_rf6052_set_cck_txpower = rtl92cu_phy_rf6052_set_cck_txpower,
134  .phy_rf6052_set_ofdm_txpower = rtl92cu_phy_rf6052_set_ofdm_txpower,
135  .config_bb_with_headerfile = _rtl92cu_phy_config_bb_with_headerfile,
136  .config_bb_with_pgheaderfile = _rtl92cu_phy_config_bb_with_pgheaderfile,
137  .phy_lc_calibrate = _rtl92cu_phy_lc_calibrate,
138  .phy_set_bw_mode_callback = rtl92cu_phy_set_bw_mode_callback,
139  .dm_dynamic_txpower = rtl92cu_dm_dynamic_txpower,
140 };
141 
142 static struct rtl_mod_params rtl92cu_mod_params = {
143  .sw_crypto = 0,
144  .debug = DBG_EMERG,
145 };
146 
147 module_param_named(swenc, rtl92cu_mod_params.sw_crypto, bool, 0444);
148 module_param_named(debug, rtl92cu_mod_params.debug, int, 0444);
149 MODULE_PARM_DESC(swenc, "Set to 1 for software crypto (default 0)\n");
150 MODULE_PARM_DESC(debug, "Set debug level (0-5) (default 0)");
151 
152 static struct rtl_hal_usbint_cfg rtl92cu_interface_cfg = {
153  /* rx */
154  .in_ep_num = RTL92C_USB_BULK_IN_NUM,
155  .rx_urb_num = RTL92C_NUM_RX_URBS,
156  .rx_max_size = RTL92C_SIZE_MAX_RX_BUFFER,
157  .usb_rx_hdl = rtl8192cu_rx_hdl,
158  .usb_rx_segregate_hdl = NULL, /* rtl8192c_rx_segregate_hdl; */
159  /* tx */
160  .usb_tx_cleanup = rtl8192c_tx_cleanup,
161  .usb_tx_post_hdl = rtl8192c_tx_post_hdl,
162  .usb_tx_aggregate_hdl = rtl8192c_tx_aggregate_hdl,
163  /* endpoint mapping */
164  .usb_endpoint_mapping = rtl8192cu_endpoint_mapping,
165  .usb_mq_to_hwq = rtl8192cu_mq_to_hwq,
166 };
167 
168 static struct rtl_hal_cfg rtl92cu_hal_cfg = {
169  .name = "rtl92c_usb",
170  .fw_name = "rtlwifi/rtl8192cufw.bin",
171  .ops = &rtl8192cu_hal_ops,
172  .mod_params = &rtl92cu_mod_params,
173  .usb_interface_cfg = &rtl92cu_interface_cfg,
174 
176  .maps[SYS_FUNC_EN] = REG_SYS_FUNC_EN,
177  .maps[SYS_CLK] = REG_SYS_CLKR,
178  .maps[MAC_RCR_AM] = AM,
179  .maps[MAC_RCR_AB] = AB,
180  .maps[MAC_RCR_ACRC32] = ACRC32,
181  .maps[MAC_RCR_ACF] = ACF,
182  .maps[MAC_RCR_AAP] = AAP,
183 
184  .maps[EFUSE_TEST] = REG_EFUSE_TEST,
185  .maps[EFUSE_CTRL] = REG_EFUSE_CTRL,
186  .maps[EFUSE_CLK] = 0,
188  .maps[EFUSE_PWC_EV12V] = PWC_EV12V,
189  .maps[EFUSE_FEN_ELDR] = FEN_ELDR,
191  .maps[EFUSE_ANA8M] = EFUSE_ANA8M,
195 
196  .maps[RWCAM] = REG_CAMCMD,
197  .maps[WCAMI] = REG_CAMWRITE,
198  .maps[RCAMO] = REG_CAMREAD,
199  .maps[CAMDBG] = REG_CAMDBG,
200  .maps[SECR] = REG_SECCFG,
201  .maps[SEC_CAM_NONE] = CAM_NONE,
202  .maps[SEC_CAM_WEP40] = CAM_WEP40,
203  .maps[SEC_CAM_TKIP] = CAM_TKIP,
204  .maps[SEC_CAM_AES] = CAM_AES,
205  .maps[SEC_CAM_WEP104] = CAM_WEP104,
206 
213  .maps[RTL_IMR_BCNDOK8] = IMR_BCNDOK8,
214  .maps[RTL_IMR_BCNDOK7] = IMR_BCNDOK7,
215  .maps[RTL_IMR_BCNDOK6] = IMR_BCNDOK6,
216  .maps[RTL_IMR_BCNDOK5] = IMR_BCNDOK5,
217  .maps[RTL_IMR_BCNDOK4] = IMR_BCNDOK4,
218  .maps[RTL_IMR_BCNDOK3] = IMR_BCNDOK3,
219  .maps[RTL_IMR_BCNDOK2] = IMR_BCNDOK2,
220  .maps[RTL_IMR_BCNDOK1] = IMR_BCNDOK1,
223 
224  .maps[RTL_IMR_TXFOVW] = IMR_TXFOVW,
226  .maps[RTL_IMR_BcnInt] = IMR_BCNINT,
227  .maps[RTL_IMR_RXFOVW] = IMR_RXFOVW,
228  .maps[RTL_IMR_RDU] = IMR_RDU,
229  .maps[RTL_IMR_ATIMEND] = IMR_ATIMEND,
230  .maps[RTL_IMR_BDOK] = IMR_BDOK,
231  .maps[RTL_IMR_MGNTDOK] = IMR_MGNTDOK,
232  .maps[RTL_IMR_TBDER] = IMR_TBDER,
233  .maps[RTL_IMR_HIGHDOK] = IMR_HIGHDOK,
234  .maps[RTL_IMR_TBDOK] = IMR_TBDOK,
235  .maps[RTL_IMR_BKDOK] = IMR_BKDOK,
236  .maps[RTL_IMR_BEDOK] = IMR_BEDOK,
237  .maps[RTL_IMR_VIDOK] = IMR_VIDOK,
238  .maps[RTL_IMR_VODOK] = IMR_VODOK,
239  .maps[RTL_IMR_ROK] = IMR_ROK,
241 
256 };
257 
258 #define USB_VENDER_ID_REALTEK 0x0bda
259 
260 /* 2010-10-19 DID_USB_V3.4 */
261 static struct usb_device_id rtl8192c_usb_ids[] = {
262 
263  /*=== Realtek demoboard ===*/
264  /* Default ID */
265  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8191, rtl92cu_hal_cfg)},
266 
267  /****** 8188CU ********/
268  /* RTL8188CTV */
269  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x018a, rtl92cu_hal_cfg)},
270  /* 8188CE-VAU USB minCard */
271  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8170, rtl92cu_hal_cfg)},
272  /* 8188cu 1*1 dongle */
273  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8176, rtl92cu_hal_cfg)},
274  /* 8188cu 1*1 dongle, (b/g mode only) */
275  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8177, rtl92cu_hal_cfg)},
276  /* 8188cu Slim Solo */
277  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817a, rtl92cu_hal_cfg)},
278  /* 8188cu Slim Combo */
279  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817b, rtl92cu_hal_cfg)},
280  /* 8188RU High-power USB Dongle */
281  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817d, rtl92cu_hal_cfg)},
282  /* 8188CE-VAU USB minCard (b/g mode only) */
283  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817e, rtl92cu_hal_cfg)},
284  /* 8188RU in Alfa AWUS036NHR */
285  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817f, rtl92cu_hal_cfg)},
286  /* RTL8188CUS-VL */
287  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x818a, rtl92cu_hal_cfg)},
288  /* 8188 Combo for BC4 */
289  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8754, rtl92cu_hal_cfg)},
290 
291  /****** 8192CU ********/
292  /* 8192cu 2*2 */
293  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8178, rtl92cu_hal_cfg)},
294  /* 8192CE-VAU USB minCard */
295  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817c, rtl92cu_hal_cfg)},
296 
297  /*=== Customer ID ===*/
298  /****** 8188CU ********/
299  {RTL_USB_DEVICE(0x050d, 0x1102, rtl92cu_hal_cfg)}, /*Belkin - Edimax*/
300  {RTL_USB_DEVICE(0x050d, 0x11f2, rtl92cu_hal_cfg)}, /*Belkin - ISY*/
301  {RTL_USB_DEVICE(0x06f8, 0xe033, rtl92cu_hal_cfg)}, /*Hercules - Edimax*/
302  {RTL_USB_DEVICE(0x07b8, 0x8188, rtl92cu_hal_cfg)}, /*Abocom - Abocom*/
303  {RTL_USB_DEVICE(0x07b8, 0x8189, rtl92cu_hal_cfg)}, /*Funai - Abocom*/
304  {RTL_USB_DEVICE(0x0846, 0x9041, rtl92cu_hal_cfg)}, /*NetGear WNA1000M*/
305  {RTL_USB_DEVICE(0x0bda, 0x5088, rtl92cu_hal_cfg)}, /*Thinkware-CC&C*/
306  {RTL_USB_DEVICE(0x0df6, 0x0052, rtl92cu_hal_cfg)}, /*Sitecom - Edimax*/
307  {RTL_USB_DEVICE(0x0df6, 0x005c, rtl92cu_hal_cfg)}, /*Sitecom - Edimax*/
308  {RTL_USB_DEVICE(0x0eb0, 0x9071, rtl92cu_hal_cfg)}, /*NO Brand - Etop*/
309  {RTL_USB_DEVICE(0x4856, 0x0091, rtl92cu_hal_cfg)}, /*NetweeN - Feixun*/
310  /* HP - Lite-On ,8188CUS Slim Combo */
311  {RTL_USB_DEVICE(0x103c, 0x1629, rtl92cu_hal_cfg)},
312  {RTL_USB_DEVICE(0x13d3, 0x3357, rtl92cu_hal_cfg)}, /* AzureWave */
313  {RTL_USB_DEVICE(0x2001, 0x3308, rtl92cu_hal_cfg)}, /*D-Link - Alpha*/
314  {RTL_USB_DEVICE(0x2019, 0x4902, rtl92cu_hal_cfg)}, /*Planex - Etop*/
315  {RTL_USB_DEVICE(0x2019, 0xab2a, rtl92cu_hal_cfg)}, /*Planex - Abocom*/
316  /*SW-WF02-AD15 -Abocom*/
317  {RTL_USB_DEVICE(0x2019, 0xab2e, rtl92cu_hal_cfg)},
318  {RTL_USB_DEVICE(0x2019, 0xed17, rtl92cu_hal_cfg)}, /*PCI - Edimax*/
319  {RTL_USB_DEVICE(0x20f4, 0x648b, rtl92cu_hal_cfg)}, /*TRENDnet - Cameo*/
320  {RTL_USB_DEVICE(0x7392, 0x7811, rtl92cu_hal_cfg)}, /*Edimax - Edimax*/
321  {RTL_USB_DEVICE(0x13d3, 0x3358, rtl92cu_hal_cfg)}, /*Azwave 8188CE-VAU*/
322  /* Russian customer -Azwave (8188CE-VAU b/g mode only) */
323  {RTL_USB_DEVICE(0x13d3, 0x3359, rtl92cu_hal_cfg)},
324  {RTL_USB_DEVICE(0x4855, 0x0090, rtl92cu_hal_cfg)}, /* Feixun */
325  {RTL_USB_DEVICE(0x4855, 0x0091, rtl92cu_hal_cfg)}, /* NetweeN-Feixun */
326  {RTL_USB_DEVICE(0x9846, 0x9041, rtl92cu_hal_cfg)}, /* Netgear Cameo */
327 
328  /****** 8188 RU ********/
329  /* Netcore */
330  {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x317f, rtl92cu_hal_cfg)},
331 
332  /****** 8188CUS Slim Solo********/
333  {RTL_USB_DEVICE(0x04f2, 0xaff7, rtl92cu_hal_cfg)}, /*Xavi*/
334  {RTL_USB_DEVICE(0x04f2, 0xaff9, rtl92cu_hal_cfg)}, /*Xavi*/
335  {RTL_USB_DEVICE(0x04f2, 0xaffa, rtl92cu_hal_cfg)}, /*Xavi*/
336 
337  /****** 8188CUS Slim Combo ********/
338  {RTL_USB_DEVICE(0x04f2, 0xaff8, rtl92cu_hal_cfg)}, /*Xavi*/
339  {RTL_USB_DEVICE(0x04f2, 0xaffb, rtl92cu_hal_cfg)}, /*Xavi*/
340  {RTL_USB_DEVICE(0x04f2, 0xaffc, rtl92cu_hal_cfg)}, /*Xavi*/
341  {RTL_USB_DEVICE(0x2019, 0x1201, rtl92cu_hal_cfg)}, /*Planex-Vencer*/
342 
343  /****** 8192CU ********/
344  {RTL_USB_DEVICE(0x050d, 0x1004, rtl92cu_hal_cfg)}, /*Belcom-SurfN300*/
345  {RTL_USB_DEVICE(0x050d, 0x2102, rtl92cu_hal_cfg)}, /*Belcom-Sercomm*/
346  {RTL_USB_DEVICE(0x050d, 0x2103, rtl92cu_hal_cfg)}, /*Belcom-Edimax*/
347  {RTL_USB_DEVICE(0x0586, 0x341f, rtl92cu_hal_cfg)}, /*Zyxel -Abocom*/
348  {RTL_USB_DEVICE(0x07aa, 0x0056, rtl92cu_hal_cfg)}, /*ATKK-Gemtek*/
349  {RTL_USB_DEVICE(0x07b8, 0x8178, rtl92cu_hal_cfg)}, /*Funai -Abocom*/
350  {RTL_USB_DEVICE(0x0846, 0x9021, rtl92cu_hal_cfg)}, /*Netgear-Sercomm*/
351  {RTL_USB_DEVICE(0x0b05, 0x17ab, rtl92cu_hal_cfg)}, /*ASUS-Edimax*/
352  {RTL_USB_DEVICE(0x0bda, 0x8186, rtl92cu_hal_cfg)}, /*Realtek 92CE-VAU*/
353  {RTL_USB_DEVICE(0x0df6, 0x0061, rtl92cu_hal_cfg)}, /*Sitecom-Edimax*/
354  {RTL_USB_DEVICE(0x0e66, 0x0019, rtl92cu_hal_cfg)}, /*Hawking-Edimax*/
355  {RTL_USB_DEVICE(0x2001, 0x3307, rtl92cu_hal_cfg)}, /*D-Link-Cameo*/
356  {RTL_USB_DEVICE(0x2001, 0x3309, rtl92cu_hal_cfg)}, /*D-Link-Alpha*/
357  {RTL_USB_DEVICE(0x2001, 0x330a, rtl92cu_hal_cfg)}, /*D-Link-Alpha*/
358  {RTL_USB_DEVICE(0x2019, 0xab2b, rtl92cu_hal_cfg)}, /*Planex -Abocom*/
359  {RTL_USB_DEVICE(0x20f4, 0x624d, rtl92cu_hal_cfg)}, /*TRENDNet*/
360  {RTL_USB_DEVICE(0x7392, 0x7822, rtl92cu_hal_cfg)}, /*Edimax -Edimax*/
361  {}
362 };
363 
364 MODULE_DEVICE_TABLE(usb, rtl8192c_usb_ids);
365 
366 static struct usb_driver rtl8192cu_driver = {
367  .name = "rtl8192cu",
368  .probe = rtl_usb_probe,
369  .disconnect = rtl_usb_disconnect,
370  .id_table = rtl8192c_usb_ids,
371 
372 #ifdef CONFIG_PM
373  /* .suspend = rtl_usb_suspend, */
374  /* .resume = rtl_usb_resume, */
375  /* .reset_resume = rtl8192c_resume, */
376 #endif /* CONFIG_PM */
377 #ifdef CONFIG_AUTOSUSPEND
378  .supports_autosuspend = 1,
379 #endif
380  .disable_hub_initiated_lpm = 1,
381 };
382 
383 module_usb_driver(rtl8192cu_driver);