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