0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #undef __NO_VERSION__
0021
0022 #include <linux/bits.h>
0023 #include <linux/etherdevice.h>
0024 #include <linux/file.h>
0025 #include <linux/kernel.h>
0026 #include "device.h"
0027 #include "card.h"
0028 #include "baseband.h"
0029 #include "mac.h"
0030 #include "power.h"
0031 #include "wcmd.h"
0032 #include "rxtx.h"
0033 #include "rf.h"
0034 #include "usbpipe.h"
0035 #include "channel.h"
0036
0037
0038
0039
0040
0041
0042 #define DRIVER_AUTHOR \
0043 "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
0044 MODULE_AUTHOR(DRIVER_AUTHOR);
0045 MODULE_LICENSE("GPL");
0046 MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
0047
0048 #define RX_DESC_DEF0 64
0049 static int vnt_rx_buffers = RX_DESC_DEF0;
0050 module_param_named(rx_buffers, vnt_rx_buffers, int, 0644);
0051 MODULE_PARM_DESC(rx_buffers, "Number of receive usb rx buffers");
0052
0053 #define TX_DESC_DEF0 64
0054 static int vnt_tx_buffers = TX_DESC_DEF0;
0055 module_param_named(tx_buffers, vnt_tx_buffers, int, 0644);
0056 MODULE_PARM_DESC(tx_buffers, "Number of receive usb tx buffers");
0057
0058 #define RTS_THRESH_DEF 2347
0059 #define FRAG_THRESH_DEF 2346
0060
0061
0062
0063
0064
0065
0066
0067 #define BBP_TYPE_DEF 2
0068
0069
0070
0071
0072
0073 static const struct usb_device_id vt6656_table[] = {
0074 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
0075 {}
0076 };
0077
0078 static void vnt_set_options(struct vnt_private *priv)
0079 {
0080
0081 if (vnt_tx_buffers < CB_MIN_TX_DESC || vnt_tx_buffers > CB_MAX_TX_DESC)
0082 priv->num_tx_context = TX_DESC_DEF0;
0083 else
0084 priv->num_tx_context = vnt_tx_buffers;
0085
0086
0087 if (vnt_rx_buffers < CB_MIN_RX_DESC || vnt_rx_buffers > CB_MAX_RX_DESC)
0088 priv->num_rcb = RX_DESC_DEF0;
0089 else
0090 priv->num_rcb = vnt_rx_buffers;
0091
0092 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
0093 priv->bb_type = BBP_TYPE_DEF;
0094 priv->packet_type = priv->bb_type;
0095 priv->preamble_type = PREAMBLE_LONG;
0096 priv->exist_sw_net_addr = false;
0097 }
0098
0099 static int vnt_download_firmware(struct vnt_private *priv)
0100 {
0101 struct device *dev = &priv->usb->dev;
0102 const struct firmware *fw;
0103 u16 length;
0104 int ii;
0105 int ret = 0;
0106
0107 dev_dbg(dev, "---->Download firmware\n");
0108
0109 ret = request_firmware(&fw, FIRMWARE_NAME, dev);
0110 if (ret) {
0111 dev_err(dev, "firmware file %s request failed (%d)\n",
0112 FIRMWARE_NAME, ret);
0113 goto end;
0114 }
0115
0116 for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
0117 length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
0118
0119 ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length,
0120 fw->data + ii);
0121 if (ret)
0122 goto free_fw;
0123
0124 dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
0125 }
0126
0127 free_fw:
0128 release_firmware(fw);
0129 end:
0130 return ret;
0131 }
0132
0133 static int vnt_firmware_branch_to_sram(struct vnt_private *priv)
0134 {
0135 dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
0136
0137 return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL);
0138 }
0139
0140 static int vnt_check_firmware_version(struct vnt_private *priv)
0141 {
0142 int ret = 0;
0143
0144 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
0145 MESSAGE_REQUEST_VERSION, 2,
0146 (u8 *)&priv->firmware_version);
0147 if (ret) {
0148 dev_dbg(&priv->usb->dev,
0149 "Could not get firmware version: %d.\n", ret);
0150 goto end;
0151 }
0152
0153 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
0154 priv->firmware_version);
0155
0156 if (priv->firmware_version == 0xFFFF) {
0157 dev_dbg(&priv->usb->dev, "In Loader.\n");
0158 ret = -EINVAL;
0159 goto end;
0160 }
0161
0162 if (priv->firmware_version < FIRMWARE_VERSION) {
0163
0164 ret = vnt_firmware_branch_to_sram(priv);
0165 if (ret) {
0166 dev_dbg(&priv->usb->dev,
0167 "Could not branch to SRAM: %d.\n", ret);
0168 } else {
0169 ret = -EINVAL;
0170 }
0171 }
0172
0173 end:
0174 return ret;
0175 }
0176
0177
0178
0179
0180 static int vnt_init_registers(struct vnt_private *priv)
0181 {
0182 int ret;
0183 struct vnt_cmd_card_init *init_cmd = &priv->init_command;
0184 struct vnt_rsp_card_init *init_rsp = &priv->init_response;
0185 u8 antenna;
0186 int ii;
0187 u8 tmp;
0188 u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
0189
0190 dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n",
0191 DEVICE_INIT_COLD, priv->packet_type);
0192
0193 ret = vnt_check_firmware_version(priv);
0194 if (ret) {
0195 ret = vnt_download_firmware(priv);
0196 if (ret) {
0197 dev_dbg(&priv->usb->dev,
0198 "Could not download firmware: %d.\n", ret);
0199 goto end;
0200 }
0201
0202 ret = vnt_firmware_branch_to_sram(priv);
0203 if (ret) {
0204 dev_dbg(&priv->usb->dev,
0205 "Could not branch to SRAM: %d.\n", ret);
0206 goto end;
0207 }
0208 }
0209
0210 ret = vnt_vt3184_init(priv);
0211 if (ret) {
0212 dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n");
0213 goto end;
0214 }
0215
0216 init_cmd->init_class = DEVICE_INIT_COLD;
0217 init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr;
0218 for (ii = 0; ii < ARRAY_SIZE(init_cmd->sw_net_addr); ii++)
0219 init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii];
0220 init_cmd->short_retry_limit = priv->hw->wiphy->retry_short;
0221 init_cmd->long_retry_limit = priv->hw->wiphy->retry_long;
0222
0223
0224 ret = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0,
0225 sizeof(struct vnt_cmd_card_init),
0226 (u8 *)init_cmd);
0227 if (ret) {
0228 dev_dbg(&priv->usb->dev, "Issue Card init fail\n");
0229 goto end;
0230 }
0231
0232 ret = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
0233 sizeof(struct vnt_rsp_card_init),
0234 (u8 *)init_rsp);
0235 if (ret) {
0236 dev_dbg(&priv->usb->dev, "Cardinit request in status fail!\n");
0237 goto end;
0238 }
0239
0240
0241 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID,
0242 MESSAGE_REQUEST_MACREG, 1, &priv->local_id);
0243 if (ret)
0244 goto end;
0245
0246
0247
0248 priv->top_ofdm_basic_rate = RATE_24M;
0249 priv->top_cck_basic_rate = RATE_1M;
0250
0251
0252 priv->power = 0xFF;
0253
0254 priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK];
0255 priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG];
0256
0257 for (ii = 0; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) {
0258 priv->cck_pwr_tbl[ii] =
0259 priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL];
0260 if (priv->cck_pwr_tbl[ii] == 0)
0261 priv->cck_pwr_tbl[ii] = priv->cck_pwr;
0262
0263 priv->ofdm_pwr_tbl[ii] =
0264 priv->eeprom[ii + EEP_OFS_OFDM_PWR_TBL];
0265 if (priv->ofdm_pwr_tbl[ii] == 0)
0266 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_g;
0267 }
0268
0269
0270
0271
0272
0273 for (ii = 11; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) {
0274 priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10];
0275 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10];
0276 }
0277
0278 priv->ofdm_pwr_a = 0x34;
0279
0280
0281 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
0282 priv->ofdm_a_pwr_tbl[ii] =
0283 priv->eeprom[ii + EEP_OFS_OFDMA_PWR_TBL];
0284
0285 if (priv->ofdm_a_pwr_tbl[ii] == 0)
0286 priv->ofdm_a_pwr_tbl[ii] = priv->ofdm_pwr_a;
0287 }
0288
0289 antenna = priv->eeprom[EEP_OFS_ANTENNA];
0290
0291 if (antenna & EEP_ANTINV)
0292 priv->tx_rx_ant_inv = true;
0293 else
0294 priv->tx_rx_ant_inv = false;
0295
0296 antenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
0297
0298 if (antenna == 0)
0299 antenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
0300
0301 if (antenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
0302 priv->tx_antenna_mode = ANT_B;
0303 priv->rx_antenna_sel = 1;
0304
0305 if (priv->tx_rx_ant_inv)
0306 priv->rx_antenna_mode = ANT_A;
0307 else
0308 priv->rx_antenna_mode = ANT_B;
0309 } else {
0310 priv->rx_antenna_sel = 0;
0311
0312 if (antenna & EEP_ANTENNA_AUX) {
0313 priv->tx_antenna_mode = ANT_A;
0314
0315 if (priv->tx_rx_ant_inv)
0316 priv->rx_antenna_mode = ANT_B;
0317 else
0318 priv->rx_antenna_mode = ANT_A;
0319 } else {
0320 priv->tx_antenna_mode = ANT_B;
0321
0322 if (priv->tx_rx_ant_inv)
0323 priv->rx_antenna_mode = ANT_A;
0324 else
0325 priv->rx_antenna_mode = ANT_B;
0326 }
0327 }
0328
0329
0330 ret = vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
0331 if (ret)
0332 goto end;
0333
0334
0335 priv->bb_type = BB_TYPE_11G;
0336
0337
0338 priv->rf_type = init_rsp->rf_type;
0339
0340
0341 if (priv->rf_type == RF_VT3226D0) {
0342 if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) &&
0343 (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) {
0344 calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ];
0345 calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC];
0346 calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ];
0347 if (calib_tx_iq || calib_tx_dc || calib_rx_iq) {
0348
0349
0350
0351 ret = vnt_control_out_u8(priv,
0352 MESSAGE_REQUEST_BBREG,
0353 0xff, 0x03);
0354 if (ret)
0355 goto end;
0356
0357
0358 ret = vnt_control_out_u8(priv,
0359 MESSAGE_REQUEST_BBREG,
0360 0xfb, calib_tx_iq);
0361 if (ret)
0362 goto end;
0363
0364
0365 ret = vnt_control_out_u8(priv,
0366 MESSAGE_REQUEST_BBREG,
0367 0xfC, calib_tx_dc);
0368 if (ret)
0369 goto end;
0370
0371
0372 ret = vnt_control_out_u8(priv,
0373 MESSAGE_REQUEST_BBREG,
0374 0xfd, calib_rx_iq);
0375 if (ret)
0376 goto end;
0377 } else {
0378
0379
0380
0381 ret = vnt_control_out_u8(priv,
0382 MESSAGE_REQUEST_BBREG,
0383 0xff, 0x0);
0384 if (ret)
0385 goto end;
0386 }
0387 }
0388 }
0389
0390
0391 memcpy(priv->permanent_net_addr, init_rsp->net_addr, 6);
0392 ether_addr_copy(priv->current_net_addr, priv->permanent_net_addr);
0393
0394
0395 dev_dbg(&priv->usb->dev, "Network address = %pM\n",
0396 priv->current_net_addr);
0397
0398 priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL];
0399
0400 if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) {
0401 ret = vnt_control_in(priv, MESSAGE_TYPE_READ,
0402 MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG,
0403 1, &tmp);
0404 if (ret)
0405 goto end;
0406
0407 if ((tmp & GPIO3_DATA) == 0) {
0408 ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
0409 GPIO3_INTMD);
0410 } else {
0411 ret = vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
0412 GPIO3_INTMD);
0413 }
0414
0415 if (ret)
0416 goto end;
0417 }
0418
0419 ret = vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
0420 if (ret)
0421 goto end;
0422
0423 ret = vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
0424 if (ret)
0425 goto end;
0426
0427 ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, BIT(0));
0428 if (ret)
0429 goto end;
0430
0431 ret = vnt_radio_power_on(priv);
0432 if (ret)
0433 goto end;
0434
0435 dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n");
0436
0437 end:
0438 return ret;
0439 }
0440
0441 static void vnt_free_tx_bufs(struct vnt_private *priv)
0442 {
0443 struct vnt_usb_send_context *tx_context;
0444 int ii;
0445
0446 usb_kill_anchored_urbs(&priv->tx_submitted);
0447
0448 for (ii = 0; ii < priv->num_tx_context; ii++) {
0449 tx_context = priv->tx_context[ii];
0450 if (!tx_context)
0451 continue;
0452
0453 kfree(tx_context);
0454 }
0455 }
0456
0457 static void vnt_free_rx_bufs(struct vnt_private *priv)
0458 {
0459 struct vnt_rcb *rcb;
0460 int ii;
0461
0462 for (ii = 0; ii < priv->num_rcb; ii++) {
0463 rcb = priv->rcb[ii];
0464 if (!rcb)
0465 continue;
0466
0467
0468 if (rcb->urb) {
0469 usb_kill_urb(rcb->urb);
0470 usb_free_urb(rcb->urb);
0471 }
0472
0473
0474 if (rcb->skb)
0475 dev_kfree_skb(rcb->skb);
0476
0477 kfree(rcb);
0478 }
0479 }
0480
0481 static void vnt_free_int_bufs(struct vnt_private *priv)
0482 {
0483 kfree(priv->int_buf.data_buf);
0484 }
0485
0486 static int vnt_alloc_bufs(struct vnt_private *priv)
0487 {
0488 int ret;
0489 struct vnt_usb_send_context *tx_context;
0490 struct vnt_rcb *rcb;
0491 int ii;
0492
0493 init_usb_anchor(&priv->tx_submitted);
0494
0495 for (ii = 0; ii < priv->num_tx_context; ii++) {
0496 tx_context = kmalloc(sizeof(*tx_context), GFP_KERNEL);
0497 if (!tx_context) {
0498 ret = -ENOMEM;
0499 goto free_tx;
0500 }
0501
0502 priv->tx_context[ii] = tx_context;
0503 tx_context->priv = priv;
0504 tx_context->pkt_no = ii;
0505 tx_context->in_use = false;
0506 }
0507
0508 for (ii = 0; ii < priv->num_rcb; ii++) {
0509 priv->rcb[ii] = kzalloc(sizeof(*priv->rcb[ii]), GFP_KERNEL);
0510 if (!priv->rcb[ii]) {
0511 ret = -ENOMEM;
0512 goto free_rx_tx;
0513 }
0514
0515 rcb = priv->rcb[ii];
0516
0517 rcb->priv = priv;
0518
0519
0520 rcb->urb = usb_alloc_urb(0, GFP_KERNEL);
0521 if (!rcb->urb) {
0522 ret = -ENOMEM;
0523 goto free_rx_tx;
0524 }
0525
0526 rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
0527 if (!rcb->skb) {
0528 ret = -ENOMEM;
0529 goto free_rx_tx;
0530 }
0531
0532 ret = vnt_submit_rx_urb(priv, rcb);
0533 if (ret)
0534 goto free_rx_tx;
0535 }
0536
0537 priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL);
0538 if (!priv->interrupt_urb) {
0539 ret = -ENOMEM;
0540 goto free_rx_tx;
0541 }
0542
0543 priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
0544 if (!priv->int_buf.data_buf) {
0545 ret = -ENOMEM;
0546 goto free_rx_tx_urb;
0547 }
0548
0549 return 0;
0550
0551 free_rx_tx_urb:
0552 usb_free_urb(priv->interrupt_urb);
0553 free_rx_tx:
0554 vnt_free_rx_bufs(priv);
0555 free_tx:
0556 vnt_free_tx_bufs(priv);
0557 return ret;
0558 }
0559
0560 static void vnt_tx_80211(struct ieee80211_hw *hw,
0561 struct ieee80211_tx_control *control,
0562 struct sk_buff *skb)
0563 {
0564 struct vnt_private *priv = hw->priv;
0565
0566 if (vnt_tx_packet(priv, skb))
0567 ieee80211_free_txskb(hw, skb);
0568 }
0569
0570 static int vnt_start(struct ieee80211_hw *hw)
0571 {
0572 int ret;
0573 struct vnt_private *priv = hw->priv;
0574
0575 priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
0576
0577 ret = vnt_alloc_bufs(priv);
0578 if (ret) {
0579 dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n");
0580 goto err;
0581 }
0582
0583 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
0584
0585 ret = vnt_init_registers(priv);
0586 if (ret) {
0587 dev_dbg(&priv->usb->dev, " init register fail\n");
0588 goto free_all;
0589 }
0590
0591 ret = vnt_key_init_table(priv);
0592 if (ret)
0593 goto free_all;
0594
0595 priv->int_interval = 1;
0596
0597 ret = vnt_start_interrupt_urb(priv);
0598 if (ret)
0599 goto free_all;
0600
0601 ieee80211_wake_queues(hw);
0602
0603 return 0;
0604
0605 free_all:
0606 vnt_free_rx_bufs(priv);
0607 vnt_free_tx_bufs(priv);
0608 vnt_free_int_bufs(priv);
0609
0610 usb_kill_urb(priv->interrupt_urb);
0611 usb_free_urb(priv->interrupt_urb);
0612 err:
0613 return ret;
0614 }
0615
0616 static void vnt_stop(struct ieee80211_hw *hw)
0617 {
0618 struct vnt_private *priv = hw->priv;
0619 int i;
0620
0621 if (!priv)
0622 return;
0623
0624 for (i = 0; i < MAX_KEY_TABLE; i++)
0625 vnt_mac_disable_keyentry(priv, i);
0626
0627
0628 priv->key_entry_inuse = 0;
0629
0630 if (!test_bit(DEVICE_FLAGS_UNPLUG, &priv->flags))
0631 vnt_mac_shutdown(priv);
0632
0633 ieee80211_stop_queues(hw);
0634
0635 set_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
0636
0637 cancel_delayed_work_sync(&priv->run_command_work);
0638
0639 priv->cmd_running = false;
0640
0641 vnt_free_tx_bufs(priv);
0642 vnt_free_rx_bufs(priv);
0643 vnt_free_int_bufs(priv);
0644
0645 usb_kill_urb(priv->interrupt_urb);
0646 usb_free_urb(priv->interrupt_urb);
0647 }
0648
0649 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
0650 {
0651 struct vnt_private *priv = hw->priv;
0652
0653 priv->vif = vif;
0654
0655 switch (vif->type) {
0656 case NL80211_IFTYPE_STATION:
0657 break;
0658 case NL80211_IFTYPE_ADHOC:
0659 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
0660
0661 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
0662
0663 break;
0664 case NL80211_IFTYPE_AP:
0665 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
0666
0667 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_AP);
0668
0669 break;
0670 default:
0671 return -EOPNOTSUPP;
0672 }
0673
0674 priv->op_mode = vif->type;
0675
0676
0677 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER);
0678
0679 return 0;
0680 }
0681
0682 static void vnt_remove_interface(struct ieee80211_hw *hw,
0683 struct ieee80211_vif *vif)
0684 {
0685 struct vnt_private *priv = hw->priv;
0686
0687 switch (vif->type) {
0688 case NL80211_IFTYPE_STATION:
0689 break;
0690 case NL80211_IFTYPE_ADHOC:
0691 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
0692 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
0693 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
0694 break;
0695 case NL80211_IFTYPE_AP:
0696 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
0697 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
0698 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_AP);
0699 break;
0700 default:
0701 break;
0702 }
0703
0704 vnt_radio_power_off(priv);
0705
0706 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
0707
0708
0709 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
0710 }
0711
0712 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
0713 {
0714 struct vnt_private *priv = hw->priv;
0715 struct ieee80211_conf *conf = &hw->conf;
0716
0717 if (changed & IEEE80211_CONF_CHANGE_PS) {
0718 if (conf->flags & IEEE80211_CONF_PS)
0719 vnt_enable_power_saving(priv, conf->listen_interval);
0720 else
0721 vnt_disable_power_saving(priv);
0722 }
0723
0724 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
0725 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
0726 vnt_set_channel(priv, conf->chandef.chan->hw_value);
0727
0728 if (conf->chandef.chan->band == NL80211_BAND_5GHZ)
0729 priv->bb_type = BB_TYPE_11A;
0730 else
0731 priv->bb_type = BB_TYPE_11G;
0732 }
0733
0734 if (changed & IEEE80211_CONF_CHANGE_POWER)
0735 vnt_rf_setpower(priv, conf->chandef.chan);
0736
0737 if (conf->flags & (IEEE80211_CONF_OFFCHANNEL | IEEE80211_CONF_IDLE))
0738
0739 vnt_update_pre_ed_threshold(priv, true);
0740 else
0741 vnt_update_pre_ed_threshold(priv, false);
0742
0743 return 0;
0744 }
0745
0746 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
0747 struct ieee80211_vif *vif,
0748 struct ieee80211_bss_conf *conf, u64 changed)
0749 {
0750 struct vnt_private *priv = hw->priv;
0751
0752 priv->current_aid = vif->cfg.aid;
0753
0754 if (changed & BSS_CHANGED_BSSID && conf->bssid)
0755 vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid);
0756
0757 if (changed & BSS_CHANGED_BASIC_RATES) {
0758 priv->basic_rates = conf->basic_rates;
0759
0760 vnt_update_top_rates(priv);
0761
0762 dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates);
0763 }
0764
0765 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
0766 if (conf->use_short_preamble) {
0767 vnt_mac_enable_barker_preamble_mode(priv);
0768 priv->preamble_type = PREAMBLE_SHORT;
0769 } else {
0770 vnt_mac_disable_barker_preamble_mode(priv);
0771 priv->preamble_type = PREAMBLE_LONG;
0772 }
0773 }
0774
0775 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
0776 if (conf->use_cts_prot)
0777 vnt_mac_enable_protect_mode(priv);
0778 else
0779 vnt_mac_disable_protect_mode(priv);
0780 }
0781
0782 if (changed & BSS_CHANGED_ERP_SLOT) {
0783 if (conf->use_short_slot)
0784 priv->short_slot_time = true;
0785 else
0786 priv->short_slot_time = false;
0787
0788 vnt_set_short_slot_time(priv);
0789 vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
0790 }
0791
0792 if (changed & (BSS_CHANGED_BASIC_RATES | BSS_CHANGED_ERP_PREAMBLE |
0793 BSS_CHANGED_ERP_SLOT))
0794 vnt_set_bss_mode(priv);
0795
0796 if (changed & (BSS_CHANGED_TXPOWER | BSS_CHANGED_BANDWIDTH))
0797 vnt_rf_setpower(priv, conf->chandef.chan);
0798
0799 if (changed & BSS_CHANGED_BEACON_ENABLED) {
0800 dev_dbg(&priv->usb->dev,
0801 "Beacon enable %d\n", conf->enable_beacon);
0802
0803 if (conf->enable_beacon) {
0804 vnt_beacon_enable(priv, vif, conf);
0805
0806 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
0807 } else {
0808 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
0809 }
0810 }
0811
0812 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INFO) &&
0813 priv->op_mode != NL80211_IFTYPE_AP) {
0814 if (vif->cfg.assoc && conf->beacon_rate) {
0815 u16 ps_beacon_int = conf->beacon_int;
0816
0817 if (conf->dtim_period)
0818 ps_beacon_int *= conf->dtim_period;
0819 else if (hw->conf.listen_interval)
0820 ps_beacon_int *= hw->conf.listen_interval;
0821
0822 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL,
0823 TFTCTL_TSFCNTREN);
0824
0825 vnt_mac_set_beacon_interval(priv, ps_beacon_int);
0826
0827 vnt_reset_next_tbtt(priv, conf->beacon_int);
0828
0829 vnt_adjust_tsf(priv, conf->beacon_rate->hw_value,
0830 conf->sync_tsf, priv->current_tsf);
0831
0832 vnt_update_next_tbtt(priv,
0833 conf->sync_tsf, ps_beacon_int);
0834 } else {
0835 vnt_clear_current_tsf(priv);
0836
0837 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL,
0838 TFTCTL_TSFCNTREN);
0839 }
0840 }
0841 }
0842
0843 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
0844 struct netdev_hw_addr_list *mc_list)
0845 {
0846 struct vnt_private *priv = hw->priv;
0847 struct netdev_hw_addr *ha;
0848 u64 mc_filter = 0;
0849 u32 bit_nr;
0850
0851 netdev_hw_addr_list_for_each(ha, mc_list) {
0852 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
0853 mc_filter |= BIT_ULL(bit_nr);
0854 }
0855
0856 priv->mc_list_count = mc_list->count;
0857
0858 return mc_filter;
0859 }
0860
0861 static void vnt_configure(struct ieee80211_hw *hw,
0862 unsigned int changed_flags,
0863 unsigned int *total_flags, u64 multicast)
0864 {
0865 struct vnt_private *priv = hw->priv;
0866 u8 rx_mode = 0;
0867
0868 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC;
0869
0870 vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
0871 MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
0872
0873 dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode);
0874
0875 if (changed_flags & FIF_ALLMULTI) {
0876 if (*total_flags & FIF_ALLMULTI) {
0877 if (priv->mc_list_count > 2)
0878 vnt_mac_set_filter(priv, ~0);
0879 else
0880 vnt_mac_set_filter(priv, multicast);
0881
0882 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
0883 } else {
0884 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
0885 }
0886 }
0887
0888 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
0889 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
0890 rx_mode &= ~RCR_BSSID;
0891 else
0892 rx_mode |= RCR_BSSID;
0893 }
0894
0895 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode);
0896
0897 dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode);
0898 }
0899
0900 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
0901 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
0902 struct ieee80211_key_conf *key)
0903 {
0904 struct vnt_private *priv = hw->priv;
0905
0906 switch (cmd) {
0907 case SET_KEY:
0908 return vnt_set_keys(hw, sta, vif, key);
0909 case DISABLE_KEY:
0910 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse)) {
0911 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
0912
0913 vnt_mac_disable_keyentry(priv, key->hw_key_idx);
0914 }
0915 break;
0916
0917 default:
0918 break;
0919 }
0920
0921 return 0;
0922 }
0923
0924 static int vnt_get_stats(struct ieee80211_hw *hw,
0925 struct ieee80211_low_level_stats *stats)
0926 {
0927 struct vnt_private *priv = hw->priv;
0928
0929 memcpy(stats, &priv->low_stats, sizeof(*stats));
0930
0931 return 0;
0932 }
0933
0934 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
0935 {
0936 struct vnt_private *priv = hw->priv;
0937
0938 return priv->current_tsf;
0939 }
0940
0941 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
0942 u64 tsf)
0943 {
0944 struct vnt_private *priv = hw->priv;
0945
0946 vnt_update_next_tbtt(priv, tsf, vif->bss_conf.beacon_int);
0947 }
0948
0949 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
0950 {
0951 struct vnt_private *priv = hw->priv;
0952
0953 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
0954
0955 vnt_clear_current_tsf(priv);
0956 }
0957
0958 static const struct ieee80211_ops vnt_mac_ops = {
0959 .tx = vnt_tx_80211,
0960 .start = vnt_start,
0961 .stop = vnt_stop,
0962 .add_interface = vnt_add_interface,
0963 .remove_interface = vnt_remove_interface,
0964 .config = vnt_config,
0965 .bss_info_changed = vnt_bss_info_changed,
0966 .prepare_multicast = vnt_prepare_multicast,
0967 .configure_filter = vnt_configure,
0968 .set_key = vnt_set_key,
0969 .get_stats = vnt_get_stats,
0970 .get_tsf = vnt_get_tsf,
0971 .set_tsf = vnt_set_tsf,
0972 .reset_tsf = vnt_reset_tsf,
0973 };
0974
0975 int vnt_init(struct vnt_private *priv)
0976 {
0977 if (vnt_init_registers(priv))
0978 return -EAGAIN;
0979
0980 SET_IEEE80211_PERM_ADDR(priv->hw, priv->permanent_net_addr);
0981
0982 vnt_init_bands(priv);
0983
0984 if (ieee80211_register_hw(priv->hw))
0985 return -ENODEV;
0986
0987 priv->mac_hw = true;
0988
0989 vnt_radio_power_off(priv);
0990
0991 return 0;
0992 }
0993
0994 static int
0995 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
0996 {
0997 struct usb_device *udev;
0998 struct vnt_private *priv;
0999 struct ieee80211_hw *hw;
1000 struct wiphy *wiphy;
1001 int rc;
1002
1003 udev = usb_get_dev(interface_to_usbdev(intf));
1004
1005 dev_notice(&udev->dev, "%s Ver. %s\n",
1006 DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1007 dev_notice(&udev->dev,
1008 "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
1009
1010 hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops);
1011 if (!hw) {
1012 dev_err(&udev->dev, "could not register ieee80211_hw\n");
1013 rc = -ENOMEM;
1014 goto err_nomem;
1015 }
1016
1017 priv = hw->priv;
1018 priv->hw = hw;
1019 priv->usb = udev;
1020 priv->intf = intf;
1021
1022 vnt_set_options(priv);
1023
1024 spin_lock_init(&priv->lock);
1025 mutex_init(&priv->usb_lock);
1026
1027 INIT_DELAYED_WORK(&priv->run_command_work, vnt_run_command);
1028
1029 usb_set_intfdata(intf, priv);
1030
1031 wiphy = priv->hw->wiphy;
1032
1033 wiphy->frag_threshold = FRAG_THRESH_DEF;
1034 wiphy->rts_threshold = RTS_THRESH_DEF;
1035 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1036 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1037
1038 ieee80211_hw_set(priv->hw, TIMING_BEACON_ONLY);
1039 ieee80211_hw_set(priv->hw, SIGNAL_DBM);
1040 ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS);
1041 ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS);
1042 ieee80211_hw_set(priv->hw, SUPPORTS_PS);
1043 ieee80211_hw_set(priv->hw, PS_NULLFUNC_STACK);
1044
1045 priv->hw->extra_tx_headroom =
1046 sizeof(struct vnt_tx_buffer) + sizeof(struct vnt_tx_usb_header);
1047 priv->hw->max_signal = 100;
1048
1049 SET_IEEE80211_DEV(priv->hw, &intf->dev);
1050
1051 rc = usb_reset_device(priv->usb);
1052 if (rc)
1053 dev_warn(&priv->usb->dev,
1054 "%s reset fail status=%d\n", __func__, rc);
1055
1056 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
1057 vnt_reset_command_timer(priv);
1058
1059 vnt_schedule_command(priv, WLAN_CMD_INIT_MAC80211);
1060
1061 return 0;
1062
1063 err_nomem:
1064 usb_put_dev(udev);
1065
1066 return rc;
1067 }
1068
1069 static void vt6656_disconnect(struct usb_interface *intf)
1070 {
1071 struct vnt_private *priv = usb_get_intfdata(intf);
1072
1073 if (!priv)
1074 return;
1075
1076 if (priv->mac_hw)
1077 ieee80211_unregister_hw(priv->hw);
1078
1079 usb_set_intfdata(intf, NULL);
1080 usb_put_dev(interface_to_usbdev(intf));
1081
1082 set_bit(DEVICE_FLAGS_UNPLUG, &priv->flags);
1083
1084 ieee80211_free_hw(priv->hw);
1085 }
1086
1087 #ifdef CONFIG_PM
1088
1089 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
1090 {
1091 return 0;
1092 }
1093
1094 static int vt6656_resume(struct usb_interface *intf)
1095 {
1096 return 0;
1097 }
1098
1099 #endif
1100
1101 MODULE_DEVICE_TABLE(usb, vt6656_table);
1102
1103 static struct usb_driver vt6656_driver = {
1104 .name = DEVICE_NAME,
1105 .probe = vt6656_probe,
1106 .disconnect = vt6656_disconnect,
1107 .id_table = vt6656_table,
1108 #ifdef CONFIG_PM
1109 .suspend = vt6656_suspend,
1110 .resume = vt6656_resume,
1111 #endif
1112 };
1113
1114 module_usb_driver(vt6656_driver);
1115
1116 MODULE_FIRMWARE(FIRMWARE_NAME);