]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/async_tx
[karo-tx-linux.git] / drivers / net / wireless / rtlwifi / rtl8192cu / sw.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2010  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 <wlanfae@realtek.com>
23  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24  * Hsinchu 300, Taiwan.
25  *
26  * Larry Finger <Larry.Finger@lwfinger.net>
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/vmalloc.h>
45
46 MODULE_AUTHOR("Georgia          <georgia@realtek.com>");
47 MODULE_AUTHOR("Ziv Huang        <ziv_huang@realtek.com>");
48 MODULE_AUTHOR("Larry Finger     <Larry.Finger@lwfinger.net>");
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
57         rtlpriv->dm.dm_initialgain_enable = 1;
58         rtlpriv->dm.dm_flag = 0;
59         rtlpriv->dm.disable_framebursting = 0;
60         rtlpriv->dm.thermalvalue = 0;
61         rtlpriv->rtlhal.pfirmware = vmalloc(0x4000);
62         if (!rtlpriv->rtlhal.pfirmware) {
63                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
64                          ("Can't alloc buffer for fw.\n"));
65                 return 1;
66         }
67         return 0;
68 }
69
70 static void rtl92cu_deinit_sw_vars(struct ieee80211_hw *hw)
71 {
72         struct rtl_priv *rtlpriv = rtl_priv(hw);
73
74         if (rtlpriv->rtlhal.pfirmware) {
75                 vfree(rtlpriv->rtlhal.pfirmware);
76                 rtlpriv->rtlhal.pfirmware = NULL;
77         }
78 }
79
80 static struct rtl_hal_ops rtl8192cu_hal_ops = {
81         .init_sw_vars = rtl92cu_init_sw_vars,
82         .deinit_sw_vars = rtl92cu_deinit_sw_vars,
83         .read_chip_version = rtl92c_read_chip_version,
84         .read_eeprom_info = rtl92cu_read_eeprom_info,
85         .enable_interrupt = rtl92c_enable_interrupt,
86         .disable_interrupt = rtl92c_disable_interrupt,
87         .hw_init = rtl92cu_hw_init,
88         .hw_disable = rtl92cu_card_disable,
89         .set_network_type = rtl92cu_set_network_type,
90         .set_chk_bssid = rtl92cu_set_check_bssid,
91         .set_qos = rtl92c_set_qos,
92         .set_bcn_reg = rtl92cu_set_beacon_related_registers,
93         .set_bcn_intv = rtl92cu_set_beacon_interval,
94         .update_interrupt_mask = rtl92cu_update_interrupt_mask,
95         .get_hw_reg = rtl92cu_get_hw_reg,
96         .set_hw_reg = rtl92cu_set_hw_reg,
97         .update_rate_tbl = rtl92cu_update_hal_rate_table,
98         .update_rate_mask = rtl92cu_update_hal_rate_mask,
99         .fill_tx_desc = rtl92cu_tx_fill_desc,
100         .fill_fake_txdesc = rtl92cu_fill_fake_txdesc,
101         .fill_tx_cmddesc = rtl92cu_tx_fill_cmddesc,
102         .cmd_send_packet = rtl92cu_cmd_send_packet,
103         .query_rx_desc = rtl92cu_rx_query_desc,
104         .set_channel_access = rtl92cu_update_channel_access_setting,
105         .radio_onoff_checking = rtl92cu_gpio_radio_on_off_checking,
106         .set_bw_mode = rtl92c_phy_set_bw_mode,
107         .switch_channel = rtl92c_phy_sw_chnl,
108         .dm_watchdog = rtl92c_dm_watchdog,
109         .scan_operation_backup = rtl92c_phy_scan_operation_backup,
110         .set_rf_power_state = rtl92cu_phy_set_rf_power_state,
111         .led_control = rtl92cu_led_control,
112         .enable_hw_sec = rtl92cu_enable_hw_security_config,
113         .set_key = rtl92c_set_key,
114         .init_sw_leds = rtl92cu_init_sw_leds,
115         .deinit_sw_leds = rtl92cu_deinit_sw_leds,
116         .get_bbreg = rtl92c_phy_query_bb_reg,
117         .set_bbreg = rtl92c_phy_set_bb_reg,
118         .get_rfreg = rtl92cu_phy_query_rf_reg,
119         .set_rfreg = rtl92cu_phy_set_rf_reg,
120         .phy_rf6052_config = rtl92cu_phy_rf6052_config,
121         .phy_rf6052_set_cck_txpower = rtl92cu_phy_rf6052_set_cck_txpower,
122         .phy_rf6052_set_ofdm_txpower = rtl92cu_phy_rf6052_set_ofdm_txpower,
123         .config_bb_with_headerfile = _rtl92cu_phy_config_bb_with_headerfile,
124         .config_bb_with_pgheaderfile = _rtl92cu_phy_config_bb_with_pgheaderfile,
125         .phy_lc_calibrate = _rtl92cu_phy_lc_calibrate,
126         .phy_set_bw_mode_callback = rtl92cu_phy_set_bw_mode_callback,
127         .dm_dynamic_txpower = rtl92cu_dm_dynamic_txpower,
128 };
129
130 static struct rtl_mod_params rtl92cu_mod_params = {
131         .sw_crypto = 0,
132 };
133
134 static struct rtl_hal_usbint_cfg rtl92cu_interface_cfg = {
135         /* rx */
136         .in_ep_num = RTL92C_USB_BULK_IN_NUM,
137         .rx_urb_num = RTL92C_NUM_RX_URBS,
138         .rx_max_size = RTL92C_SIZE_MAX_RX_BUFFER,
139         .usb_rx_hdl = rtl8192cu_rx_hdl,
140         .usb_rx_segregate_hdl = NULL, /* rtl8192c_rx_segregate_hdl; */
141         /* tx */
142         .usb_tx_cleanup = rtl8192c_tx_cleanup,
143         .usb_tx_post_hdl = rtl8192c_tx_post_hdl,
144         .usb_tx_aggregate_hdl = rtl8192c_tx_aggregate_hdl,
145         /* endpoint mapping */
146         .usb_endpoint_mapping = rtl8192cu_endpoint_mapping,
147         .usb_mq_to_hwq = rtl8192cu_mq_to_hwq,
148 };
149
150 static struct rtl_hal_cfg rtl92cu_hal_cfg = {
151         .name = "rtl92c_usb",
152         .fw_name = "rtlwifi/rtl8192cufw.bin",
153         .ops = &rtl8192cu_hal_ops,
154         .mod_params = &rtl92cu_mod_params,
155         .usb_interface_cfg = &rtl92cu_interface_cfg,
156
157         .maps[SYS_ISO_CTRL] = REG_SYS_ISO_CTRL,
158         .maps[SYS_FUNC_EN] = REG_SYS_FUNC_EN,
159         .maps[SYS_CLK] = REG_SYS_CLKR,
160         .maps[MAC_RCR_AM] = AM,
161         .maps[MAC_RCR_AB] = AB,
162         .maps[MAC_RCR_ACRC32] = ACRC32,
163         .maps[MAC_RCR_ACF] = ACF,
164         .maps[MAC_RCR_AAP] = AAP,
165
166         .maps[EFUSE_TEST] = REG_EFUSE_TEST,
167         .maps[EFUSE_CTRL] = REG_EFUSE_CTRL,
168         .maps[EFUSE_CLK] = 0,
169         .maps[EFUSE_CLK_CTRL] = REG_EFUSE_CTRL,
170         .maps[EFUSE_PWC_EV12V] = PWC_EV12V,
171         .maps[EFUSE_FEN_ELDR] = FEN_ELDR,
172         .maps[EFUSE_LOADER_CLK_EN] = LOADER_CLK_EN,
173         .maps[EFUSE_ANA8M] = EFUSE_ANA8M,
174         .maps[EFUSE_HWSET_MAX_SIZE] = HWSET_MAX_SIZE,
175         .maps[EFUSE_MAX_SECTION_MAP] = EFUSE_MAX_SECTION,
176         .maps[EFUSE_REAL_CONTENT_SIZE] = EFUSE_REAL_CONTENT_LEN,
177
178         .maps[RWCAM] = REG_CAMCMD,
179         .maps[WCAMI] = REG_CAMWRITE,
180         .maps[RCAMO] = REG_CAMREAD,
181         .maps[CAMDBG] = REG_CAMDBG,
182         .maps[SECR] = REG_SECCFG,
183         .maps[SEC_CAM_NONE] = CAM_NONE,
184         .maps[SEC_CAM_WEP40] = CAM_WEP40,
185         .maps[SEC_CAM_TKIP] = CAM_TKIP,
186         .maps[SEC_CAM_AES] = CAM_AES,
187         .maps[SEC_CAM_WEP104] = CAM_WEP104,
188
189         .maps[RTL_IMR_BCNDMAINT6] = IMR_BCNDMAINT6,
190         .maps[RTL_IMR_BCNDMAINT5] = IMR_BCNDMAINT5,
191         .maps[RTL_IMR_BCNDMAINT4] = IMR_BCNDMAINT4,
192         .maps[RTL_IMR_BCNDMAINT3] = IMR_BCNDMAINT3,
193         .maps[RTL_IMR_BCNDMAINT2] = IMR_BCNDMAINT2,
194         .maps[RTL_IMR_BCNDMAINT1] = IMR_BCNDMAINT1,
195         .maps[RTL_IMR_BCNDOK8] = IMR_BCNDOK8,
196         .maps[RTL_IMR_BCNDOK7] = IMR_BCNDOK7,
197         .maps[RTL_IMR_BCNDOK6] = IMR_BCNDOK6,
198         .maps[RTL_IMR_BCNDOK5] = IMR_BCNDOK5,
199         .maps[RTL_IMR_BCNDOK4] = IMR_BCNDOK4,
200         .maps[RTL_IMR_BCNDOK3] = IMR_BCNDOK3,
201         .maps[RTL_IMR_BCNDOK2] = IMR_BCNDOK2,
202         .maps[RTL_IMR_BCNDOK1] = IMR_BCNDOK1,
203         .maps[RTL_IMR_TIMEOUT2] = IMR_TIMEOUT2,
204         .maps[RTL_IMR_TIMEOUT1] = IMR_TIMEOUT1,
205
206         .maps[RTL_IMR_TXFOVW] = IMR_TXFOVW,
207         .maps[RTL_IMR_PSTIMEOUT] = IMR_PSTIMEOUT,
208         .maps[RTL_IMR_BcnInt] = IMR_BCNINT,
209         .maps[RTL_IMR_RXFOVW] = IMR_RXFOVW,
210         .maps[RTL_IMR_RDU] = IMR_RDU,
211         .maps[RTL_IMR_ATIMEND] = IMR_ATIMEND,
212         .maps[RTL_IMR_BDOK] = IMR_BDOK,
213         .maps[RTL_IMR_MGNTDOK] = IMR_MGNTDOK,
214         .maps[RTL_IMR_TBDER] = IMR_TBDER,
215         .maps[RTL_IMR_HIGHDOK] = IMR_HIGHDOK,
216         .maps[RTL_IMR_TBDOK] = IMR_TBDOK,
217         .maps[RTL_IMR_BKDOK] = IMR_BKDOK,
218         .maps[RTL_IMR_BEDOK] = IMR_BEDOK,
219         .maps[RTL_IMR_VIDOK] = IMR_VIDOK,
220         .maps[RTL_IMR_VODOK] = IMR_VODOK,
221         .maps[RTL_IMR_ROK] = IMR_ROK,
222         .maps[RTL_IBSS_INT_MASKS] = (IMR_BCNINT | IMR_TBDOK | IMR_TBDER),
223
224         .maps[RTL_RC_CCK_RATE1M] = DESC92C_RATE1M,
225         .maps[RTL_RC_CCK_RATE2M] = DESC92C_RATE2M,
226         .maps[RTL_RC_CCK_RATE5_5M] = DESC92C_RATE5_5M,
227         .maps[RTL_RC_CCK_RATE11M] = DESC92C_RATE11M,
228         .maps[RTL_RC_OFDM_RATE6M] = DESC92C_RATE6M,
229         .maps[RTL_RC_OFDM_RATE9M] = DESC92C_RATE9M,
230         .maps[RTL_RC_OFDM_RATE12M] = DESC92C_RATE12M,
231         .maps[RTL_RC_OFDM_RATE18M] = DESC92C_RATE18M,
232         .maps[RTL_RC_OFDM_RATE24M] = DESC92C_RATE24M,
233         .maps[RTL_RC_OFDM_RATE36M] = DESC92C_RATE36M,
234         .maps[RTL_RC_OFDM_RATE48M] = DESC92C_RATE48M,
235         .maps[RTL_RC_OFDM_RATE54M] = DESC92C_RATE54M,
236         .maps[RTL_RC_HT_RATEMCS7] = DESC92C_RATEMCS7,
237         .maps[RTL_RC_HT_RATEMCS15] = DESC92C_RATEMCS15,
238 };
239
240 #define USB_VENDER_ID_REALTEK           0x0bda
241
242 /* 2010-10-19 DID_USB_V3.4 */
243 static struct usb_device_id rtl8192c_usb_ids[] = {
244
245         /*=== Realtek demoboard ===*/
246         /* Default ID */
247         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8191, rtl92cu_hal_cfg)},
248
249         /****** 8188CU ********/
250         /* 8188CE-VAU USB minCard */
251         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8170, rtl92cu_hal_cfg)},
252         /* 8188cu 1*1 dongle */
253         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8176, rtl92cu_hal_cfg)},
254         /* 8188cu 1*1 dongle, (b/g mode only) */
255         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8177, rtl92cu_hal_cfg)},
256         /* 8188cu Slim Solo */
257         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817a, rtl92cu_hal_cfg)},
258         /* 8188cu Slim Combo */
259         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817b, rtl92cu_hal_cfg)},
260         /* 8188RU High-power USB Dongle */
261         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817d, rtl92cu_hal_cfg)},
262         /* 8188CE-VAU USB minCard (b/g mode only) */
263         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817e, rtl92cu_hal_cfg)},
264         /* 8188 Combo for BC4 */
265         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8754, rtl92cu_hal_cfg)},
266
267         /****** 8192CU ********/
268         /* 8191cu 1*2 */
269         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8177, rtl92cu_hal_cfg)},
270         /* 8192cu 2*2 */
271         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817b, rtl92cu_hal_cfg)},
272         /* 8192CE-VAU USB minCard */
273         {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817c, rtl92cu_hal_cfg)},
274
275         /*=== Customer ID ===*/
276         /****** 8188CU ********/
277         {RTL_USB_DEVICE(0x050d, 0x1102, rtl92cu_hal_cfg)}, /*Belkin - Edimax*/
278         {RTL_USB_DEVICE(0x06f8, 0xe033, rtl92cu_hal_cfg)}, /*Hercules - Edimax*/
279         {RTL_USB_DEVICE(0x07b8, 0x8188, rtl92cu_hal_cfg)}, /*Abocom - Abocom*/
280         {RTL_USB_DEVICE(0x07b8, 0x8189, rtl92cu_hal_cfg)}, /*Funai - Abocom*/
281         {RTL_USB_DEVICE(0x0Df6, 0x0052, rtl92cu_hal_cfg)}, /*Sitecom - Edimax*/
282         {RTL_USB_DEVICE(0x0eb0, 0x9071, rtl92cu_hal_cfg)}, /*NO Brand - Etop*/
283         /* HP - Lite-On ,8188CUS Slim Combo */
284         {RTL_USB_DEVICE(0x103c, 0x1629, rtl92cu_hal_cfg)},
285         {RTL_USB_DEVICE(0x2001, 0x3308, rtl92cu_hal_cfg)}, /*D-Link - Alpha*/
286         {RTL_USB_DEVICE(0x2019, 0xab2a, rtl92cu_hal_cfg)}, /*Planex - Abocom*/
287         {RTL_USB_DEVICE(0x2019, 0xed17, rtl92cu_hal_cfg)}, /*PCI - Edimax*/
288         {RTL_USB_DEVICE(0x20f4, 0x648b, rtl92cu_hal_cfg)}, /*TRENDnet - Cameo*/
289         {RTL_USB_DEVICE(0x7392, 0x7811, rtl92cu_hal_cfg)}, /*Edimax - Edimax*/
290         {RTL_USB_DEVICE(0x3358, 0x13d3, rtl92cu_hal_cfg)}, /*Azwave 8188CE-VAU*/
291         /* Russian customer -Azwave (8188CE-VAU  b/g mode only) */
292         {RTL_USB_DEVICE(0x3359, 0x13d3, rtl92cu_hal_cfg)},
293
294         /****** 8192CU ********/
295         {RTL_USB_DEVICE(0x0586, 0x341f, rtl92cu_hal_cfg)}, /*Zyxel -Abocom*/
296         {RTL_USB_DEVICE(0x07aa, 0x0056, rtl92cu_hal_cfg)}, /*ATKK-Gemtek*/
297         {RTL_USB_DEVICE(0x07b8, 0x8178, rtl92cu_hal_cfg)}, /*Funai -Abocom*/
298         {RTL_USB_DEVICE(0x07b8, 0x8178, rtl92cu_hal_cfg)}, /*Abocom -Abocom*/
299         {RTL_USB_DEVICE(0x2001, 0x3307, rtl92cu_hal_cfg)}, /*D-Link-Cameo*/
300         {RTL_USB_DEVICE(0x2001, 0x3309, rtl92cu_hal_cfg)}, /*D-Link-Alpha*/
301         {RTL_USB_DEVICE(0x2001, 0x330a, rtl92cu_hal_cfg)}, /*D-Link-Alpha*/
302         {RTL_USB_DEVICE(0x2019, 0xab2b, rtl92cu_hal_cfg)}, /*Planex -Abocom*/
303         {RTL_USB_DEVICE(0x7392, 0x7822, rtl92cu_hal_cfg)}, /*Edimax -Edimax*/
304         {}
305 };
306
307 MODULE_DEVICE_TABLE(usb, rtl8192c_usb_ids);
308
309 static struct usb_driver rtl8192cu_driver = {
310         .name = "rtl8192cu",
311         .probe = rtl_usb_probe,
312         .disconnect = rtl_usb_disconnect,
313         .id_table = rtl8192c_usb_ids,
314
315 #ifdef CONFIG_PM
316         /* .suspend = rtl_usb_suspend, */
317         /* .resume = rtl_usb_resume, */
318         /* .reset_resume = rtl8192c_resume, */
319 #endif /* CONFIG_PM */
320 #ifdef CONFIG_AUTOSUSPEND
321         .supports_autosuspend = 1,
322 #endif
323 };
324
325 static int __init rtl8192cu_init(void)
326 {
327         return usb_register(&rtl8192cu_driver);
328 }
329
330 static void __exit rtl8192cu_exit(void)
331 {
332         usb_deregister(&rtl8192cu_driver);
333 }
334
335 module_init(rtl8192cu_init);
336 module_exit(rtl8192cu_exit);