Commit | Line | Data |
---|---|---|
92b96797 FB |
1 | /* |
2 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
92b96797 FB |
15 | * |
16 | * File: main_usb.c | |
17 | * | |
18 | * Purpose: driver entry for initial, open, close, tx and rx. | |
19 | * | |
20 | * Author: Lyndon Chen | |
21 | * | |
22 | * Date: Dec 8, 2005 | |
23 | * | |
24 | * Functions: | |
25 | * | |
26e5b65b | 26 | * vt6656_probe - module initial (insmod) driver entry |
afc7ef64 | 27 | * vnt_free_tx_bufs - free tx buffer function |
500e1fb3 | 28 | * vnt_init_registers- initial MAC & BBP & RF internal registers. |
92b96797 FB |
29 | * |
30 | * Revision History: | |
31 | */ | |
32 | #undef __NO_VERSION__ | |
33 | ||
e2382233 | 34 | #include <linux/etherdevice.h> |
7c51d177 | 35 | #include <linux/file.h> |
92b96797 | 36 | #include "device.h" |
92b96797 | 37 | #include "card.h" |
92b96797 | 38 | #include "baseband.h" |
92b96797 | 39 | #include "mac.h" |
92b96797 | 40 | #include "power.h" |
92b96797 | 41 | #include "wcmd.h" |
92b96797 | 42 | #include "rxtx.h" |
92b96797 | 43 | #include "dpc.h" |
92b96797 | 44 | #include "rf.h" |
92b96797 | 45 | #include "firmware.h" |
62c8526d | 46 | #include "usbpipe.h" |
92b96797 | 47 | #include "channel.h" |
92b96797 | 48 | #include "int.h" |
92b96797 | 49 | |
ec6e0f63 AM |
50 | /* |
51 | * define module options | |
52 | */ | |
92b96797 | 53 | |
ec6e0f63 AM |
54 | /* version information */ |
55 | #define DRIVER_AUTHOR \ | |
56 | "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>" | |
92b96797 FB |
57 | MODULE_AUTHOR(DRIVER_AUTHOR); |
58 | MODULE_LICENSE("GPL"); | |
59 | MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM); | |
60 | ||
dbf0a03b | 61 | #define RX_DESC_DEF0 64 |
2f020ebc MP |
62 | static int vnt_rx_buffers = RX_DESC_DEF0; |
63 | module_param_named(rx_buffers, vnt_rx_buffers, int, 0644); | |
64 | MODULE_PARM_DESC(rx_buffers, "Number of receive usb rx buffers"); | |
92b96797 | 65 | |
dbf0a03b | 66 | #define TX_DESC_DEF0 64 |
3220e3a4 | 67 | static int vnt_tx_buffers = TX_DESC_DEF0; |
1b6953dd | 68 | module_param_named(tx_buffers, vnt_tx_buffers, int, 0644); |
3220e3a4 MP |
69 | MODULE_PARM_DESC(tx_buffers, "Number of receive usb tx buffers"); |
70 | ||
92b96797 | 71 | #define RTS_THRESH_DEF 2347 |
92b96797 | 72 | #define FRAG_THRESH_DEF 2346 |
92b96797 | 73 | #define SHORT_RETRY_DEF 8 |
92b96797 | 74 | #define LONG_RETRY_DEF 4 |
92b96797 | 75 | |
92b96797 | 76 | /* BasebandType[] baseband type selected |
d2713e51 | 77 | * 0: indicate 802.11a type |
78 | * 1: indicate 802.11b type | |
79 | * 2: indicate 802.11g type | |
80 | */ | |
92b96797 | 81 | |
24b46f9e | 82 | #define BBP_TYPE_DEF 2 |
92b96797 | 83 | |
ec6e0f63 AM |
84 | /* |
85 | * Static vars definitions | |
86 | */ | |
92b96797 | 87 | |
4d088876 | 88 | static struct usb_device_id vt6656_table[] = { |
92b96797 FB |
89 | {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)}, |
90 | {} | |
91 | }; | |
92 | ||
7665cf21 | 93 | static void vnt_set_options(struct vnt_private *priv) |
28e067f4 | 94 | { |
3220e3a4 MP |
95 | /* Set number of TX buffers */ |
96 | if (vnt_tx_buffers < CB_MIN_TX_DESC || vnt_tx_buffers > CB_MAX_TX_DESC) | |
03b7e354 | 97 | priv->num_tx_context = TX_DESC_DEF0; |
3220e3a4 | 98 | else |
03b7e354 | 99 | priv->num_tx_context = vnt_tx_buffers; |
2f020ebc MP |
100 | |
101 | /* Set number of RX buffers */ | |
102 | if (vnt_rx_buffers < CB_MIN_RX_DESC || vnt_rx_buffers > CB_MAX_RX_DESC) | |
6da4738f | 103 | priv->num_rcb = RX_DESC_DEF0; |
2f020ebc | 104 | else |
6da4738f | 105 | priv->num_rcb = vnt_rx_buffers; |
2f020ebc | 106 | |
388e5cb8 MP |
107 | priv->short_retry_limit = SHORT_RETRY_DEF; |
108 | priv->long_retry_limit = LONG_RETRY_DEF; | |
da3b67b3 | 109 | priv->op_mode = NL80211_IFTYPE_UNSPECIFIED; |
65df77e2 | 110 | priv->bb_type = BBP_TYPE_DEF; |
e12471db | 111 | priv->packet_type = priv->bb_type; |
a6177aef | 112 | priv->auto_fb_ctrl = AUTO_FB_0; |
98e93fe5 | 113 | priv->preamble_type = 0; |
35cc8f94 | 114 | priv->exist_sw_net_addr = false; |
92b96797 FB |
115 | } |
116 | ||
ec6e0f63 AM |
117 | /* |
118 | * initialization of MAC & BBP registers | |
119 | */ | |
500e1fb3 | 120 | static int vnt_init_registers(struct vnt_private *priv) |
92b96797 | 121 | { |
3ce54934 MP |
122 | struct vnt_cmd_card_init *init_cmd = &priv->init_command; |
123 | struct vnt_rsp_card_init *init_rsp = &priv->init_response; | |
124 | u8 antenna; | |
dd0a774f | 125 | int ii; |
3ce54934 MP |
126 | int status = STATUS_SUCCESS; |
127 | u8 tmp; | |
128 | u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0; | |
92b96797 | 129 | |
4e62dcc9 | 130 | dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n", |
e12471db | 131 | DEVICE_INIT_COLD, priv->packet_type); |
302433da | 132 | |
3ce54934 MP |
133 | if (!vnt_check_firmware_version(priv)) { |
134 | if (vnt_download_firmware(priv) == true) { | |
135 | if (vnt_firmware_branch_to_sram(priv) == false) { | |
4e62dcc9 | 136 | dev_dbg(&priv->usb->dev, |
14321461 | 137 | " vnt_firmware_branch_to_sram fail\n"); |
cbc06fb1 MP |
138 | return false; |
139 | } | |
140 | } else { | |
4e62dcc9 | 141 | dev_dbg(&priv->usb->dev, "FIRMWAREbDownload fail\n"); |
cbc06fb1 MP |
142 | return false; |
143 | } | |
144 | } | |
145 | ||
3ce54934 | 146 | if (!vnt_vt3184_init(priv)) { |
4e62dcc9 | 147 | dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n"); |
cbc06fb1 MP |
148 | return false; |
149 | } | |
92b96797 | 150 | |
748bf69c | 151 | init_cmd->init_class = DEVICE_INIT_COLD; |
35cc8f94 | 152 | init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr; |
3d47a6fb | 153 | for (ii = 0; ii < 6; ii++) |
ebf9b312 | 154 | init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii]; |
388e5cb8 MP |
155 | init_cmd->short_retry_limit = priv->short_retry_limit; |
156 | init_cmd->long_retry_limit = priv->long_retry_limit; | |
3d47a6fb MP |
157 | |
158 | /* issue card_init command to device */ | |
3ce54934 | 159 | status = vnt_control_out(priv, |
3d47a6fb | 160 | MESSAGE_TYPE_CARDINIT, 0, 0, |
748bf69c | 161 | sizeof(struct vnt_cmd_card_init), (u8 *)init_cmd); |
3ce54934 | 162 | if (status != STATUS_SUCCESS) { |
4e62dcc9 | 163 | dev_dbg(&priv->usb->dev, "Issue Card init fail\n"); |
cbc06fb1 MP |
164 | return false; |
165 | } | |
92b96797 | 166 | |
3ce54934 | 167 | status = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0, |
748bf69c | 168 | sizeof(struct vnt_rsp_card_init), (u8 *)init_rsp); |
3ce54934 | 169 | if (status != STATUS_SUCCESS) { |
4e62dcc9 | 170 | dev_dbg(&priv->usb->dev, |
302433da | 171 | "Cardinit request in status fail!\n"); |
302433da MP |
172 | return false; |
173 | } | |
92b96797 | 174 | |
ec6e0f63 | 175 | /* local ID for AES functions */ |
3ce54934 | 176 | status = vnt_control_in(priv, MESSAGE_TYPE_READ, |
302433da | 177 | MAC_REG_LOCALID, MESSAGE_REQUEST_MACREG, 1, |
f1945a15 | 178 | &priv->local_id); |
3ce54934 | 179 | if (status != STATUS_SUCCESS) |
302433da | 180 | return false; |
92b96797 | 181 | |
ec6e0f63 AM |
182 | /* do MACbSoftwareReset in MACvInitialize */ |
183 | ||
3c8a5b25 | 184 | priv->top_ofdm_basic_rate = RATE_24M; |
d80bf43c | 185 | priv->top_cck_basic_rate = RATE_1M; |
2486890a | 186 | |
ec6e0f63 | 187 | /* target to IF pin while programming to RF chip */ |
5a97491c | 188 | priv->power = 0xFF; |
92b96797 | 189 | |
5a97491c MP |
190 | priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK]; |
191 | priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG]; | |
ec6e0f63 AM |
192 | /* load power table */ |
193 | for (ii = 0; ii < 14; ii++) { | |
5a97491c | 194 | priv->cck_pwr_tbl[ii] = |
bbb11263 | 195 | priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL]; |
5a97491c MP |
196 | if (priv->cck_pwr_tbl[ii] == 0) |
197 | priv->cck_pwr_tbl[ii] = priv->cck_pwr; | |
3ce54934 | 198 | |
5a97491c | 199 | priv->ofdm_pwr_tbl[ii] = |
bbb11263 | 200 | priv->eeprom[ii + EEP_OFS_OFDM_PWR_TBL]; |
5a97491c MP |
201 | if (priv->ofdm_pwr_tbl[ii] == 0) |
202 | priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_g; | |
302433da | 203 | } |
92b96797 | 204 | |
ec6e0f63 AM |
205 | /* |
206 | * original zonetype is USA, but custom zonetype is Europe, | |
207 | * then need to recover 12, 13, 14 channels with 11 channel | |
208 | */ | |
9ef2184d | 209 | for (ii = 11; ii < 14; ii++) { |
5a97491c MP |
210 | priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10]; |
211 | priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10]; | |
302433da | 212 | } |
92b96797 | 213 | |
5a97491c | 214 | priv->ofdm_pwr_a = 0x34; /* same as RFbMA2829SelectChannel */ |
ec6e0f63 | 215 | |
302433da MP |
216 | /* load OFDM A power table */ |
217 | for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) { | |
5a97491c | 218 | priv->ofdm_a_pwr_tbl[ii] = |
bbb11263 | 219 | priv->eeprom[ii + EEP_OFS_OFDMA_PWR_TBL]; |
302433da | 220 | |
5a97491c MP |
221 | if (priv->ofdm_a_pwr_tbl[ii] == 0) |
222 | priv->ofdm_a_pwr_tbl[ii] = priv->ofdm_pwr_a; | |
302433da | 223 | } |
92b96797 | 224 | |
bbb11263 | 225 | antenna = priv->eeprom[EEP_OFS_ANTENNA]; |
92b96797 | 226 | |
3ce54934 | 227 | if (antenna & EEP_ANTINV) |
2044dbdb | 228 | priv->tx_rx_ant_inv = true; |
302433da | 229 | else |
2044dbdb | 230 | priv->tx_rx_ant_inv = false; |
302433da | 231 | |
3ce54934 | 232 | antenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); |
92b96797 | 233 | |
3ce54934 MP |
234 | if (antenna == 0) /* if not set default is both */ |
235 | antenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); | |
302433da | 236 | |
3ce54934 | 237 | if (antenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) { |
2044dbdb MP |
238 | priv->tx_antenna_mode = ANT_B; |
239 | priv->rx_antenna_sel = 1; | |
302433da | 240 | |
f72ea988 | 241 | if (priv->tx_rx_ant_inv) |
2044dbdb | 242 | priv->rx_antenna_mode = ANT_A; |
302433da | 243 | else |
2044dbdb | 244 | priv->rx_antenna_mode = ANT_B; |
302433da | 245 | } else { |
2044dbdb | 246 | priv->rx_antenna_sel = 0; |
302433da | 247 | |
3ce54934 | 248 | if (antenna & EEP_ANTENNA_AUX) { |
2044dbdb | 249 | priv->tx_antenna_mode = ANT_A; |
302433da | 250 | |
f72ea988 | 251 | if (priv->tx_rx_ant_inv) |
2044dbdb | 252 | priv->rx_antenna_mode = ANT_B; |
302433da | 253 | else |
2044dbdb | 254 | priv->rx_antenna_mode = ANT_A; |
302433da | 255 | } else { |
2044dbdb | 256 | priv->tx_antenna_mode = ANT_B; |
302433da | 257 | |
f72ea988 | 258 | if (priv->tx_rx_ant_inv) |
2044dbdb | 259 | priv->rx_antenna_mode = ANT_A; |
302433da | 260 | else |
2044dbdb | 261 | priv->rx_antenna_mode = ANT_B; |
302433da MP |
262 | } |
263 | } | |
264 | ||
ed0db513 | 265 | /* Set initial antenna mode */ |
2044dbdb | 266 | vnt_set_antenna_mode(priv, priv->rx_antenna_mode); |
ed0db513 | 267 | |
ec6e0f63 | 268 | /* get Auto Fall Back type */ |
a6177aef | 269 | priv->auto_fb_ctrl = AUTO_FB_0; |
92b96797 | 270 | |
ec6e0f63 | 271 | /* default Auto Mode */ |
65df77e2 | 272 | priv->bb_type = BB_TYPE_11G; |
92b96797 | 273 | |
ec6e0f63 | 274 | /* get RFType */ |
6242ecae | 275 | priv->rf_type = init_rsp->rf_type; |
92b96797 | 276 | |
ec6e0f63 | 277 | /* load vt3266 calibration parameters in EEPROM */ |
6242ecae | 278 | if (priv->rf_type == RF_VT3226D0) { |
bbb11263 MP |
279 | if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) && |
280 | (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) { | |
3ce54934 | 281 | |
bbb11263 MP |
282 | calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ]; |
283 | calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC]; | |
284 | calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ]; | |
3ce54934 | 285 | if (calib_tx_iq || calib_tx_dc || calib_rx_iq) { |
33e9ab3d | 286 | /* CR255, enable TX/RX IQ and |
d2713e51 | 287 | * DC compensation mode |
288 | */ | |
3ce54934 | 289 | vnt_control_out_u8(priv, |
33e9ab3d PST |
290 | MESSAGE_REQUEST_BBREG, |
291 | 0xff, | |
292 | 0x03); | |
293 | /* CR251, TX I/Q Imbalance Calibration */ | |
3ce54934 | 294 | vnt_control_out_u8(priv, |
33e9ab3d PST |
295 | MESSAGE_REQUEST_BBREG, |
296 | 0xfb, | |
3ce54934 | 297 | calib_tx_iq); |
33e9ab3d | 298 | /* CR252, TX DC-Offset Calibration */ |
3ce54934 | 299 | vnt_control_out_u8(priv, |
33e9ab3d PST |
300 | MESSAGE_REQUEST_BBREG, |
301 | 0xfC, | |
3ce54934 | 302 | calib_tx_dc); |
33e9ab3d | 303 | /* CR253, RX I/Q Imbalance Calibration */ |
3ce54934 | 304 | vnt_control_out_u8(priv, |
33e9ab3d PST |
305 | MESSAGE_REQUEST_BBREG, |
306 | 0xfd, | |
3ce54934 | 307 | calib_rx_iq); |
302433da | 308 | } else { |
33e9ab3d | 309 | /* CR255, turn off |
d2713e51 | 310 | * BB Calibration compensation |
311 | */ | |
3ce54934 | 312 | vnt_control_out_u8(priv, |
33e9ab3d PST |
313 | MESSAGE_REQUEST_BBREG, |
314 | 0xff, | |
315 | 0x0); | |
302433da MP |
316 | } |
317 | } | |
318 | } | |
cbc06fb1 | 319 | |
ec6e0f63 | 320 | /* get permanent network address */ |
41e8321a | 321 | memcpy(priv->permanent_net_addr, init_rsp->net_addr, 6); |
e2382233 | 322 | ether_addr_copy(priv->current_net_addr, priv->permanent_net_addr); |
92b96797 | 323 | |
ec6e0f63 | 324 | /* if exist SW network address, use it */ |
4e62dcc9 | 325 | dev_dbg(&priv->usb->dev, "Network address = %pM\n", |
ebf9b312 | 326 | priv->current_net_addr); |
92b96797 | 327 | |
cbc06fb1 MP |
328 | /* |
329 | * set BB and packet type at the same time | |
330 | * set Short Slot Time, xIFS, and RSPINF | |
331 | */ | |
65df77e2 | 332 | if (priv->bb_type == BB_TYPE_11A) |
a641c9ec | 333 | priv->short_slot_time = true; |
d35d5fbb | 334 | else |
a641c9ec | 335 | priv->short_slot_time = false; |
cbc06fb1 | 336 | |
3ce54934 | 337 | vnt_set_short_slot_time(priv); |
cbc06fb1 | 338 | |
bbb11263 | 339 | priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL]; |
cbc06fb1 | 340 | |
2044dbdb | 341 | if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) { |
3ce54934 MP |
342 | status = vnt_control_in(priv, MESSAGE_TYPE_READ, |
343 | MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG, 1, &tmp); | |
cbc06fb1 | 344 | |
3ce54934 | 345 | if (status != STATUS_SUCCESS) |
cbc06fb1 | 346 | return false; |
cbc06fb1 | 347 | |
d7f2d8f6 | 348 | if ((tmp & GPIO3_DATA) == 0) |
3ce54934 | 349 | vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, |
36957537 | 350 | GPIO3_INTMD); |
d7f2d8f6 | 351 | else |
3ce54934 | 352 | vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, |
a9bed1df | 353 | GPIO3_INTMD); |
cbc06fb1 MP |
354 | } |
355 | ||
3ce54934 | 356 | vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38); |
cbc06fb1 | 357 | |
3ce54934 | 358 | vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW); |
cbc06fb1 | 359 | |
3ce54934 | 360 | vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01); |
cbc06fb1 | 361 | |
d7f2d8f6 | 362 | vnt_radio_power_on(priv); |
cbc06fb1 | 363 | |
4e62dcc9 | 364 | dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n"); |
cbc06fb1 MP |
365 | |
366 | return true; | |
92b96797 FB |
367 | } |
368 | ||
afc7ef64 | 369 | static void vnt_free_tx_bufs(struct vnt_private *priv) |
8611a29a | 370 | { |
f2625c24 MP |
371 | struct vnt_usb_send_context *tx_context; |
372 | int ii; | |
373 | ||
03b7e354 | 374 | for (ii = 0; ii < priv->num_tx_context; ii++) { |
f7e4a8f4 | 375 | tx_context = priv->tx_context[ii]; |
f2625c24 | 376 | /* deallocate URBs */ |
30a05b39 MP |
377 | if (tx_context->urb) { |
378 | usb_kill_urb(tx_context->urb); | |
379 | usb_free_urb(tx_context->urb); | |
f2625c24 MP |
380 | } |
381 | ||
382 | kfree(tx_context); | |
383 | } | |
92b96797 FB |
384 | } |
385 | ||
0dd6e68a | 386 | static void vnt_free_rx_bufs(struct vnt_private *priv) |
8611a29a | 387 | { |
afc5eeb8 | 388 | struct vnt_rcb *rcb; |
115cac2e | 389 | int ii; |
92b96797 | 390 | |
6da4738f | 391 | for (ii = 0; ii < priv->num_rcb; ii++) { |
8577011c | 392 | rcb = priv->rcb[ii]; |
8cffb3cf MP |
393 | if (!rcb) |
394 | continue; | |
92b96797 | 395 | |
afc5eeb8 | 396 | /* deallocate URBs */ |
325de984 MP |
397 | if (rcb->urb) { |
398 | usb_kill_urb(rcb->urb); | |
399 | usb_free_urb(rcb->urb); | |
afc5eeb8 | 400 | } |
92b96797 | 401 | |
afc5eeb8 MP |
402 | /* deallocate skb */ |
403 | if (rcb->skb) | |
404 | dev_kfree_skb(rcb->skb); | |
afc5eeb8 | 405 | |
8cffb3cf MP |
406 | kfree(rcb); |
407 | } | |
92b96797 FB |
408 | } |
409 | ||
76d382fc | 410 | static void usb_device_reset(struct vnt_private *priv) |
92b96797 | 411 | { |
42b138d9 PST |
412 | int status; |
413 | ||
76d382fc | 414 | status = usb_reset_device(priv->usb); |
92b96797 | 415 | if (status) |
76d382fc | 416 | dev_warn(&priv->usb->dev, |
d9cf2f9e | 417 | "usb_device_reset fail status=%d\n", status); |
92b96797 | 418 | } |
92b96797 | 419 | |
1c2fd56b | 420 | static void vnt_free_int_bufs(struct vnt_private *priv) |
8611a29a | 421 | { |
1506bf37 | 422 | kfree(priv->int_buf.data_buf); |
92b96797 FB |
423 | } |
424 | ||
ef484423 | 425 | static bool vnt_alloc_bufs(struct vnt_private *priv) |
dd0a774f | 426 | { |
35491de7 MP |
427 | struct vnt_usb_send_context *tx_context; |
428 | struct vnt_rcb *rcb; | |
115cac2e | 429 | int ii; |
92b96797 | 430 | |
03b7e354 | 431 | for (ii = 0; ii < priv->num_tx_context; ii++) { |
35491de7 MP |
432 | tx_context = kmalloc(sizeof(struct vnt_usb_send_context), |
433 | GFP_KERNEL); | |
27f31cf9 | 434 | if (!tx_context) |
35491de7 | 435 | goto free_tx; |
92b96797 | 436 | |
f7e4a8f4 | 437 | priv->tx_context[ii] = tx_context; |
30a05b39 | 438 | tx_context->priv = priv; |
71d764ae | 439 | tx_context->pkt_no = ii; |
35491de7 MP |
440 | |
441 | /* allocate URBs */ | |
3e0f86b3 | 442 | tx_context->urb = usb_alloc_urb(0, GFP_KERNEL); |
68d81dea | 443 | if (!tx_context->urb) |
35491de7 | 444 | goto free_tx; |
92b96797 | 445 | |
30a05b39 | 446 | tx_context->in_use = false; |
35491de7 MP |
447 | } |
448 | ||
6da4738f | 449 | for (ii = 0; ii < priv->num_rcb; ii++) { |
8577011c MP |
450 | priv->rcb[ii] = kzalloc(sizeof(struct vnt_rcb), GFP_KERNEL); |
451 | if (!priv->rcb[ii]) { | |
8cffb3cf MP |
452 | dev_err(&priv->usb->dev, |
453 | "failed to allocate rcb no %d\n", ii); | |
454 | goto free_rx_tx; | |
455 | } | |
115cac2e | 456 | |
8577011c | 457 | rcb = priv->rcb[ii]; |
92b96797 | 458 | |
325de984 | 459 | rcb->priv = priv; |
92b96797 | 460 | |
35491de7 | 461 | /* allocate URBs */ |
3e0f86b3 | 462 | rcb->urb = usb_alloc_urb(0, GFP_KERNEL); |
68d81dea | 463 | if (!rcb->urb) |
35491de7 | 464 | goto free_rx_tx; |
92b96797 | 465 | |
63b9907f | 466 | rcb->skb = dev_alloc_skb(priv->rx_buf_sz); |
27f31cf9 | 467 | if (!rcb->skb) |
35491de7 | 468 | goto free_rx_tx; |
92b96797 | 469 | |
325de984 | 470 | rcb->in_use = false; |
35491de7 | 471 | |
8cffb3cf | 472 | /* submit rx urb */ |
2dc37af0 | 473 | if (vnt_submit_rx_urb(priv, rcb)) |
8cffb3cf | 474 | goto free_rx_tx; |
92b96797 FB |
475 | } |
476 | ||
3e0f86b3 | 477 | priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL); |
68d81dea | 478 | if (!priv->interrupt_urb) |
35491de7 | 479 | goto free_rx_tx; |
92b96797 | 480 | |
35491de7 | 481 | priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL); |
27f31cf9 | 482 | if (!priv->int_buf.data_buf) { |
3d582487 | 483 | usb_free_urb(priv->interrupt_urb); |
35491de7 MP |
484 | goto free_rx_tx; |
485 | } | |
486 | ||
487 | return true; | |
92b96797 FB |
488 | |
489 | free_rx_tx: | |
0dd6e68a | 490 | vnt_free_rx_bufs(priv); |
92b96797 FB |
491 | |
492 | free_tx: | |
afc7ef64 | 493 | vnt_free_tx_bufs(priv); |
92b96797 | 494 | |
e269fc2d | 495 | return false; |
92b96797 FB |
496 | } |
497 | ||
db8f37fa MP |
498 | static void vnt_tx_80211(struct ieee80211_hw *hw, |
499 | struct ieee80211_tx_control *control, struct sk_buff *skb) | |
500 | { | |
501 | struct vnt_private *priv = hw->priv; | |
502 | ||
b914b494 | 503 | if (vnt_tx_packet(priv, skb)) |
db8f37fa | 504 | ieee80211_free_txskb(hw, skb); |
db8f37fa MP |
505 | } |
506 | ||
507 | static int vnt_start(struct ieee80211_hw *hw) | |
508 | { | |
509 | struct vnt_private *priv = hw->priv; | |
510 | ||
511 | priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS; | |
512 | ||
5699c0f4 | 513 | if (!vnt_alloc_bufs(priv)) { |
ef484423 | 514 | dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n"); |
db8f37fa MP |
515 | return -ENOMEM; |
516 | } | |
517 | ||
2ab3d46d | 518 | clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags); |
db8f37fa | 519 | |
500e1fb3 | 520 | if (vnt_init_registers(priv) == false) { |
db8f37fa MP |
521 | dev_dbg(&priv->usb->dev, " init register fail\n"); |
522 | goto free_all; | |
523 | } | |
524 | ||
525 | priv->int_interval = 1; /* bInterval is set to 1 */ | |
526 | ||
62001939 | 527 | vnt_int_start_interrupt(priv); |
db8f37fa | 528 | |
db8f37fa MP |
529 | ieee80211_wake_queues(hw); |
530 | ||
531 | return 0; | |
532 | ||
533 | free_all: | |
0dd6e68a | 534 | vnt_free_rx_bufs(priv); |
afc7ef64 | 535 | vnt_free_tx_bufs(priv); |
1c2fd56b | 536 | vnt_free_int_bufs(priv); |
db8f37fa | 537 | |
3d582487 MP |
538 | usb_kill_urb(priv->interrupt_urb); |
539 | usb_free_urb(priv->interrupt_urb); | |
db8f37fa MP |
540 | |
541 | return -ENOMEM; | |
542 | } | |
543 | ||
544 | static void vnt_stop(struct ieee80211_hw *hw) | |
545 | { | |
546 | struct vnt_private *priv = hw->priv; | |
547 | int i; | |
548 | ||
549 | if (!priv) | |
550 | return; | |
551 | ||
552 | for (i = 0; i < MAX_KEY_TABLE; i++) | |
553 | vnt_mac_disable_keyentry(priv, i); | |
554 | ||
555 | /* clear all keys */ | |
556 | priv->key_entry_inuse = 0; | |
557 | ||
cbcc9a36 | 558 | if (!test_bit(DEVICE_FLAGS_UNPLUG, &priv->flags)) |
db8f37fa MP |
559 | vnt_mac_shutdown(priv); |
560 | ||
561 | ieee80211_stop_queues(hw); | |
562 | ||
4c3b0d45 | 563 | set_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags); |
db8f37fa MP |
564 | |
565 | cancel_delayed_work_sync(&priv->run_command_work); | |
db8f37fa | 566 | |
33a60b87 | 567 | priv->cmd_running = false; |
db8f37fa | 568 | |
afc7ef64 | 569 | vnt_free_tx_bufs(priv); |
0dd6e68a | 570 | vnt_free_rx_bufs(priv); |
1c2fd56b | 571 | vnt_free_int_bufs(priv); |
db8f37fa | 572 | |
3d582487 MP |
573 | usb_kill_urb(priv->interrupt_urb); |
574 | usb_free_urb(priv->interrupt_urb); | |
db8f37fa MP |
575 | } |
576 | ||
577 | static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) | |
578 | { | |
579 | struct vnt_private *priv = hw->priv; | |
580 | ||
581 | priv->vif = vif; | |
582 | ||
583 | switch (vif->type) { | |
584 | case NL80211_IFTYPE_STATION: | |
585 | break; | |
586 | case NL80211_IFTYPE_ADHOC: | |
587 | vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST); | |
588 | ||
589 | vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC); | |
590 | ||
591 | break; | |
592 | case NL80211_IFTYPE_AP: | |
593 | vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST); | |
594 | ||
595 | vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_AP); | |
596 | ||
597 | break; | |
598 | default: | |
599 | return -EOPNOTSUPP; | |
600 | } | |
601 | ||
602 | priv->op_mode = vif->type; | |
603 | ||
1ecd083e MP |
604 | vnt_set_bss_mode(priv); |
605 | ||
db8f37fa MP |
606 | /* LED blink on TX */ |
607 | vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER); | |
608 | ||
609 | return 0; | |
610 | } | |
611 | ||
612 | static void vnt_remove_interface(struct ieee80211_hw *hw, | |
613 | struct ieee80211_vif *vif) | |
614 | { | |
615 | struct vnt_private *priv = hw->priv; | |
616 | ||
617 | switch (vif->type) { | |
618 | case NL80211_IFTYPE_STATION: | |
619 | break; | |
620 | case NL80211_IFTYPE_ADHOC: | |
621 | vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX); | |
622 | vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); | |
623 | vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC); | |
624 | break; | |
625 | case NL80211_IFTYPE_AP: | |
626 | vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX); | |
627 | vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); | |
628 | vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_AP); | |
629 | break; | |
630 | default: | |
631 | break; | |
632 | } | |
633 | ||
634 | vnt_radio_power_off(priv); | |
635 | ||
636 | priv->op_mode = NL80211_IFTYPE_UNSPECIFIED; | |
637 | ||
638 | /* LED slow blink */ | |
639 | vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW); | |
db8f37fa MP |
640 | } |
641 | ||
642 | static int vnt_config(struct ieee80211_hw *hw, u32 changed) | |
643 | { | |
644 | struct vnt_private *priv = hw->priv; | |
645 | struct ieee80211_conf *conf = &hw->conf; | |
646 | u8 bb_type; | |
647 | ||
648 | if (changed & IEEE80211_CONF_CHANGE_PS) { | |
649 | if (conf->flags & IEEE80211_CONF_PS) | |
650 | vnt_enable_power_saving(priv, conf->listen_interval); | |
651 | else | |
652 | vnt_disable_power_saving(priv); | |
653 | } | |
654 | ||
655 | if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || | |
656 | (conf->flags & IEEE80211_CONF_OFFCHANNEL)) { | |
657 | vnt_set_channel(priv, conf->chandef.chan->hw_value); | |
658 | ||
57fbcce3 | 659 | if (conf->chandef.chan->band == NL80211_BAND_5GHZ) |
db8f37fa MP |
660 | bb_type = BB_TYPE_11A; |
661 | else | |
662 | bb_type = BB_TYPE_11G; | |
663 | ||
65df77e2 MP |
664 | if (priv->bb_type != bb_type) { |
665 | priv->bb_type = bb_type; | |
db8f37fa MP |
666 | |
667 | vnt_set_bss_mode(priv); | |
668 | } | |
669 | } | |
670 | ||
671 | if (changed & IEEE80211_CONF_CHANGE_POWER) { | |
65df77e2 | 672 | if (priv->bb_type == BB_TYPE_11B) |
8b84c1da | 673 | priv->current_rate = RATE_1M; |
db8f37fa | 674 | else |
8b84c1da | 675 | priv->current_rate = RATE_54M; |
db8f37fa | 676 | |
8b84c1da | 677 | vnt_rf_setpower(priv, priv->current_rate, |
db8f37fa MP |
678 | conf->chandef.chan->hw_value); |
679 | } | |
680 | ||
681 | return 0; | |
682 | } | |
683 | ||
684 | static void vnt_bss_info_changed(struct ieee80211_hw *hw, | |
685 | struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf, | |
686 | u32 changed) | |
687 | { | |
688 | struct vnt_private *priv = hw->priv; | |
14c5e41f | 689 | |
db8f37fa MP |
690 | priv->current_aid = conf->aid; |
691 | ||
d309509f | 692 | if (changed & BSS_CHANGED_BSSID && conf->bssid) |
db8f37fa MP |
693 | vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid); |
694 | ||
695 | ||
696 | if (changed & BSS_CHANGED_BASIC_RATES) { | |
93a73558 | 697 | priv->basic_rates = conf->basic_rates; |
db8f37fa MP |
698 | |
699 | vnt_update_top_rates(priv); | |
700 | ||
701 | dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates); | |
702 | } | |
703 | ||
704 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | |
705 | if (conf->use_short_preamble) { | |
706 | vnt_mac_enable_barker_preamble_mode(priv); | |
98e93fe5 | 707 | priv->preamble_type = true; |
db8f37fa MP |
708 | } else { |
709 | vnt_mac_disable_barker_preamble_mode(priv); | |
98e93fe5 | 710 | priv->preamble_type = false; |
db8f37fa MP |
711 | } |
712 | } | |
713 | ||
714 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { | |
715 | if (conf->use_cts_prot) | |
716 | vnt_mac_enable_protect_mode(priv); | |
717 | else | |
718 | vnt_mac_disable_protect_mode(priv); | |
719 | } | |
720 | ||
721 | if (changed & BSS_CHANGED_ERP_SLOT) { | |
722 | if (conf->use_short_slot) | |
a641c9ec | 723 | priv->short_slot_time = true; |
db8f37fa | 724 | else |
a641c9ec | 725 | priv->short_slot_time = false; |
db8f37fa | 726 | |
3c956cc0 | 727 | vnt_set_short_slot_time(priv); |
c37cbd37 | 728 | vnt_set_vga_gain_offset(priv, priv->bb_vga[0]); |
80dcc0ae | 729 | vnt_update_pre_ed_threshold(priv, false); |
db8f37fa MP |
730 | } |
731 | ||
732 | if (changed & BSS_CHANGED_TXPOWER) | |
8b84c1da | 733 | vnt_rf_setpower(priv, priv->current_rate, |
db8f37fa MP |
734 | conf->chandef.chan->hw_value); |
735 | ||
736 | if (changed & BSS_CHANGED_BEACON_ENABLED) { | |
737 | dev_dbg(&priv->usb->dev, | |
738 | "Beacon enable %d\n", conf->enable_beacon); | |
739 | ||
740 | if (conf->enable_beacon) { | |
741 | vnt_beacon_enable(priv, vif, conf); | |
742 | ||
743 | vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX); | |
744 | } else { | |
745 | vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX); | |
746 | } | |
747 | } | |
c1515879 MP |
748 | |
749 | if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INFO) && | |
750 | priv->op_mode != NL80211_IFTYPE_AP) { | |
751 | if (conf->assoc && conf->beacon_rate) { | |
752 | vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, | |
753 | TFTCTL_TSFCNTREN); | |
754 | ||
755 | vnt_adjust_tsf(priv, conf->beacon_rate->hw_value, | |
756 | conf->sync_tsf, priv->current_tsf); | |
757 | ||
758 | vnt_mac_set_beacon_interval(priv, conf->beacon_int); | |
759 | ||
760 | vnt_reset_next_tbtt(priv, conf->beacon_int); | |
761 | } else { | |
762 | vnt_clear_current_tsf(priv); | |
763 | ||
764 | vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, | |
765 | TFTCTL_TSFCNTREN); | |
766 | } | |
767 | } | |
db8f37fa MP |
768 | } |
769 | ||
770 | static u64 vnt_prepare_multicast(struct ieee80211_hw *hw, | |
771 | struct netdev_hw_addr_list *mc_list) | |
772 | { | |
773 | struct vnt_private *priv = hw->priv; | |
774 | struct netdev_hw_addr *ha; | |
775 | u64 mc_filter = 0; | |
776 | u32 bit_nr = 0; | |
777 | ||
778 | netdev_hw_addr_list_for_each(ha, mc_list) { | |
779 | bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; | |
780 | ||
781 | mc_filter |= 1ULL << (bit_nr & 0x3f); | |
782 | } | |
783 | ||
784 | priv->mc_list_count = mc_list->count; | |
785 | ||
786 | return mc_filter; | |
787 | } | |
788 | ||
789 | static void vnt_configure(struct ieee80211_hw *hw, | |
790 | unsigned int changed_flags, unsigned int *total_flags, u64 multicast) | |
791 | { | |
792 | struct vnt_private *priv = hw->priv; | |
793 | u8 rx_mode = 0; | |
794 | int rc; | |
795 | ||
df140465 | 796 | *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC; |
db8f37fa MP |
797 | |
798 | rc = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR, | |
799 | MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode); | |
800 | ||
801 | if (!rc) | |
802 | rx_mode = RCR_MULTICAST | RCR_BROADCAST; | |
803 | ||
804 | dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode); | |
805 | ||
db8f37fa MP |
806 | if (changed_flags & FIF_ALLMULTI) { |
807 | if (*total_flags & FIF_ALLMULTI) { | |
808 | if (priv->mc_list_count > 2) | |
809 | vnt_mac_set_filter(priv, ~0); | |
810 | else | |
811 | vnt_mac_set_filter(priv, multicast); | |
812 | ||
813 | rx_mode |= RCR_MULTICAST | RCR_BROADCAST; | |
814 | } else { | |
815 | rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST); | |
816 | } | |
817 | ||
818 | } | |
819 | ||
820 | if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) { | |
821 | if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) | |
822 | rx_mode &= ~RCR_BSSID; | |
823 | else | |
824 | rx_mode |= RCR_BSSID; | |
825 | } | |
826 | ||
827 | vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode); | |
828 | ||
829 | dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode); | |
db8f37fa MP |
830 | } |
831 | ||
832 | static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | |
833 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, | |
834 | struct ieee80211_key_conf *key) | |
835 | { | |
836 | struct vnt_private *priv = hw->priv; | |
837 | ||
838 | switch (cmd) { | |
839 | case SET_KEY: | |
840 | if (vnt_set_keys(hw, sta, vif, key)) | |
841 | return -EOPNOTSUPP; | |
842 | break; | |
843 | case DISABLE_KEY: | |
844 | if (test_bit(key->hw_key_idx, &priv->key_entry_inuse)) | |
845 | clear_bit(key->hw_key_idx, &priv->key_entry_inuse); | |
846 | default: | |
847 | break; | |
848 | } | |
849 | ||
850 | return 0; | |
851 | } | |
852 | ||
a344d677 JB |
853 | static void vnt_sw_scan_start(struct ieee80211_hw *hw, |
854 | struct ieee80211_vif *vif, | |
855 | const u8 *addr) | |
db8f37fa MP |
856 | { |
857 | struct vnt_private *priv = hw->priv; | |
858 | ||
1ecd083e | 859 | vnt_set_bss_mode(priv); |
db8f37fa | 860 | /* Set max sensitivity*/ |
80dcc0ae | 861 | vnt_update_pre_ed_threshold(priv, true); |
db8f37fa MP |
862 | } |
863 | ||
a344d677 JB |
864 | static void vnt_sw_scan_complete(struct ieee80211_hw *hw, |
865 | struct ieee80211_vif *vif) | |
db8f37fa MP |
866 | { |
867 | struct vnt_private *priv = hw->priv; | |
868 | ||
869 | /* Return sensitivity to channel level*/ | |
80dcc0ae | 870 | vnt_update_pre_ed_threshold(priv, false); |
db8f37fa MP |
871 | } |
872 | ||
1786384e MP |
873 | static int vnt_get_stats(struct ieee80211_hw *hw, |
874 | struct ieee80211_low_level_stats *stats) | |
875 | { | |
876 | struct vnt_private *priv = hw->priv; | |
877 | ||
878 | memcpy(stats, &priv->low_stats, sizeof(*stats)); | |
879 | ||
880 | return 0; | |
881 | } | |
882 | ||
db8f37fa MP |
883 | static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
884 | { | |
885 | struct vnt_private *priv = hw->priv; | |
886 | ||
113f0b91 | 887 | return priv->current_tsf; |
db8f37fa MP |
888 | } |
889 | ||
890 | static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, | |
891 | u64 tsf) | |
892 | { | |
893 | struct vnt_private *priv = hw->priv; | |
894 | ||
895 | vnt_update_next_tbtt(priv, tsf, vif->bss_conf.beacon_int); | |
896 | } | |
897 | ||
898 | static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) | |
899 | { | |
900 | struct vnt_private *priv = hw->priv; | |
901 | ||
902 | vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); | |
903 | ||
904 | vnt_clear_current_tsf(priv); | |
905 | } | |
906 | ||
907 | static const struct ieee80211_ops vnt_mac_ops = { | |
908 | .tx = vnt_tx_80211, | |
909 | .start = vnt_start, | |
910 | .stop = vnt_stop, | |
911 | .add_interface = vnt_add_interface, | |
912 | .remove_interface = vnt_remove_interface, | |
913 | .config = vnt_config, | |
914 | .bss_info_changed = vnt_bss_info_changed, | |
915 | .prepare_multicast = vnt_prepare_multicast, | |
916 | .configure_filter = vnt_configure, | |
917 | .set_key = vnt_set_key, | |
918 | .sw_scan_start = vnt_sw_scan_start, | |
919 | .sw_scan_complete = vnt_sw_scan_complete, | |
1786384e | 920 | .get_stats = vnt_get_stats, |
db8f37fa MP |
921 | .get_tsf = vnt_get_tsf, |
922 | .set_tsf = vnt_set_tsf, | |
923 | .reset_tsf = vnt_reset_tsf, | |
924 | }; | |
925 | ||
926 | int vnt_init(struct vnt_private *priv) | |
927 | { | |
928 | ||
500e1fb3 | 929 | if (!(vnt_init_registers(priv))) |
db8f37fa MP |
930 | return -EAGAIN; |
931 | ||
41e8321a | 932 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->permanent_net_addr); |
db8f37fa | 933 | |
110f97e9 MP |
934 | vnt_init_bands(priv); |
935 | ||
db8f37fa MP |
936 | if (ieee80211_register_hw(priv->hw)) |
937 | return -ENODEV; | |
938 | ||
30816f83 MP |
939 | priv->mac_hw = true; |
940 | ||
ba911c9b MP |
941 | vnt_radio_power_off(priv); |
942 | ||
db8f37fa MP |
943 | return 0; |
944 | } | |
945 | ||
946 | static int | |
947 | vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id) | |
948 | { | |
949 | struct usb_device *udev; | |
950 | struct vnt_private *priv; | |
951 | struct ieee80211_hw *hw; | |
952 | struct wiphy *wiphy; | |
953 | int rc = 0; | |
954 | ||
955 | udev = usb_get_dev(interface_to_usbdev(intf)); | |
956 | ||
957 | dev_notice(&udev->dev, "%s Ver. %s\n", | |
958 | DEVICE_FULL_DRV_NAM, DEVICE_VERSION); | |
959 | dev_notice(&udev->dev, | |
960 | "Copyright (c) 2004 VIA Networking Technologies, Inc.\n"); | |
961 | ||
962 | hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops); | |
963 | if (!hw) { | |
964 | dev_err(&udev->dev, "could not register ieee80211_hw\n"); | |
20ff1418 | 965 | rc = -ENOMEM; |
db8f37fa MP |
966 | goto err_nomem; |
967 | } | |
968 | ||
969 | priv = hw->priv; | |
970 | priv->hw = hw; | |
971 | priv->usb = udev; | |
972 | ||
7665cf21 | 973 | vnt_set_options(priv); |
db8f37fa MP |
974 | |
975 | spin_lock_init(&priv->lock); | |
976 | mutex_init(&priv->usb_lock); | |
977 | ||
592365ae | 978 | INIT_DELAYED_WORK(&priv->run_command_work, vnt_run_command); |
db8f37fa | 979 | |
db8f37fa MP |
980 | usb_set_intfdata(intf, priv); |
981 | ||
982 | wiphy = priv->hw->wiphy; | |
983 | ||
984 | wiphy->frag_threshold = FRAG_THRESH_DEF; | |
985 | wiphy->rts_threshold = RTS_THRESH_DEF; | |
986 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
987 | BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP); | |
988 | ||
30686bf7 JB |
989 | ieee80211_hw_set(priv->hw, TIMING_BEACON_ONLY); |
990 | ieee80211_hw_set(priv->hw, SIGNAL_DBM); | |
991 | ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS); | |
992 | ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS); | |
49a315bf | 993 | ieee80211_hw_set(priv->hw, SUPPORTS_PS); |
db8f37fa | 994 | |
db8f37fa MP |
995 | priv->hw->max_signal = 100; |
996 | ||
997 | SET_IEEE80211_DEV(priv->hw, &intf->dev); | |
998 | ||
999 | usb_device_reset(priv); | |
1000 | ||
2ab3d46d | 1001 | clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags); |
68cc161e | 1002 | vnt_reset_command_timer(priv); |
30816f83 | 1003 | |
57981a65 | 1004 | vnt_schedule_command(priv, WLAN_CMD_INIT_MAC80211); |
30816f83 | 1005 | |
db8f37fa MP |
1006 | return 0; |
1007 | ||
1008 | err_nomem: | |
1009 | usb_put_dev(udev); | |
1010 | ||
1011 | return rc; | |
1012 | } | |
1013 | ||
0d7fe14f | 1014 | static void vt6656_disconnect(struct usb_interface *intf) |
92b96797 | 1015 | { |
db8f37fa | 1016 | struct vnt_private *priv = usb_get_intfdata(intf); |
92b96797 | 1017 | |
db8f37fa | 1018 | if (!priv) |
6cda24f5 | 1019 | return; |
92b96797 | 1020 | |
30816f83 MP |
1021 | if (priv->mac_hw) |
1022 | ieee80211_unregister_hw(priv->hw); | |
db8f37fa | 1023 | |
92b96797 | 1024 | usb_set_intfdata(intf, NULL); |
6cda24f5 | 1025 | usb_put_dev(interface_to_usbdev(intf)); |
92b96797 | 1026 | |
4c3b0d45 | 1027 | set_bit(DEVICE_FLAGS_UNPLUG, &priv->flags); |
92b96797 | 1028 | |
db8f37fa | 1029 | ieee80211_free_hw(priv->hw); |
92b96797 FB |
1030 | } |
1031 | ||
db8f37fa MP |
1032 | #ifdef CONFIG_PM |
1033 | ||
1034 | static int vt6656_suspend(struct usb_interface *intf, pm_message_t message) | |
1035 | { | |
1036 | return 0; | |
1037 | } | |
1038 | ||
1039 | static int vt6656_resume(struct usb_interface *intf) | |
1040 | { | |
1041 | return 0; | |
1042 | } | |
1043 | ||
1044 | #endif /* CONFIG_PM */ | |
1045 | ||
26e5b65b | 1046 | MODULE_DEVICE_TABLE(usb, vt6656_table); |
92b96797 | 1047 | |
26e5b65b AM |
1048 | static struct usb_driver vt6656_driver = { |
1049 | .name = DEVICE_NAME, | |
1050 | .probe = vt6656_probe, | |
1051 | .disconnect = vt6656_disconnect, | |
1052 | .id_table = vt6656_table, | |
92b96797 | 1053 | #ifdef CONFIG_PM |
26e5b65b AM |
1054 | .suspend = vt6656_suspend, |
1055 | .resume = vt6656_resume, | |
1056 | #endif /* CONFIG_PM */ | |
92b96797 FB |
1057 | }; |
1058 | ||
bac2c126 | 1059 | module_usb_driver(vt6656_driver); |