1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
8 * Purpose: driver entry for initial, open, close, tx and rx.
16 * vt6656_probe - module initial (insmod) driver entry
17 * vnt_free_tx_bufs - free tx buffer function
18 * vnt_init_registers- initial MAC & BBP & RF internal registers.
24 #include <linux/bits.h>
25 #include <linux/etherdevice.h>
26 #include <linux/file.h>
27 #include <linux/kernel.h>
41 * define module options
44 /* version information */
45 #define DRIVER_AUTHOR \
46 "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
47 MODULE_AUTHOR(DRIVER_AUTHOR);
48 MODULE_LICENSE("GPL");
49 MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
51 #define RX_DESC_DEF0 64
52 static int vnt_rx_buffers = RX_DESC_DEF0;
53 module_param_named(rx_buffers, vnt_rx_buffers, int, 0644);
54 MODULE_PARM_DESC(rx_buffers, "Number of receive usb rx buffers");
56 #define TX_DESC_DEF0 64
57 static int vnt_tx_buffers = TX_DESC_DEF0;
58 module_param_named(tx_buffers, vnt_tx_buffers, int, 0644);
59 MODULE_PARM_DESC(tx_buffers, "Number of receive usb tx buffers");
61 #define RTS_THRESH_DEF 2347
62 #define FRAG_THRESH_DEF 2346
63 #define SHORT_RETRY_DEF 8
64 #define LONG_RETRY_DEF 4
66 /* BasebandType[] baseband type selected
67 * 0: indicate 802.11a type
68 * 1: indicate 802.11b type
69 * 2: indicate 802.11g type
72 #define BBP_TYPE_DEF 2
75 * Static vars definitions
78 static const struct usb_device_id vt6656_table[] = {
79 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
83 static void vnt_set_options(struct vnt_private *priv)
85 /* Set number of TX buffers */
86 if (vnt_tx_buffers < CB_MIN_TX_DESC || vnt_tx_buffers > CB_MAX_TX_DESC)
87 priv->num_tx_context = TX_DESC_DEF0;
89 priv->num_tx_context = vnt_tx_buffers;
91 /* Set number of RX buffers */
92 if (vnt_rx_buffers < CB_MIN_RX_DESC || vnt_rx_buffers > CB_MAX_RX_DESC)
93 priv->num_rcb = RX_DESC_DEF0;
95 priv->num_rcb = vnt_rx_buffers;
97 priv->short_retry_limit = SHORT_RETRY_DEF;
98 priv->long_retry_limit = LONG_RETRY_DEF;
99 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
100 priv->bb_type = BBP_TYPE_DEF;
101 priv->packet_type = priv->bb_type;
102 priv->preamble_type = 0;
103 priv->exist_sw_net_addr = false;
107 * initialization of MAC & BBP registers
109 static int vnt_init_registers(struct vnt_private *priv)
112 struct vnt_cmd_card_init *init_cmd = &priv->init_command;
113 struct vnt_rsp_card_init *init_rsp = &priv->init_response;
117 u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
119 dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n",
120 DEVICE_INIT_COLD, priv->packet_type);
122 ret = vnt_check_firmware_version(priv);
124 ret = vnt_download_firmware(priv);
126 dev_dbg(&priv->usb->dev,
127 "Could not download firmware: %d.\n", ret);
131 ret = vnt_firmware_branch_to_sram(priv);
133 dev_dbg(&priv->usb->dev,
134 "Could not branch to SRAM: %d.\n", ret);
139 ret = vnt_vt3184_init(priv);
141 dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n");
145 init_cmd->init_class = DEVICE_INIT_COLD;
146 init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr;
147 for (ii = 0; ii < ARRAY_SIZE(init_cmd->sw_net_addr); ii++)
148 init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii];
149 init_cmd->short_retry_limit = priv->short_retry_limit;
150 init_cmd->long_retry_limit = priv->long_retry_limit;
152 /* issue card_init command to device */
153 ret = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0,
154 sizeof(struct vnt_cmd_card_init),
157 dev_dbg(&priv->usb->dev, "Issue Card init fail\n");
161 ret = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
162 sizeof(struct vnt_rsp_card_init),
165 dev_dbg(&priv->usb->dev, "Cardinit request in status fail!\n");
169 /* local ID for AES functions */
170 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID,
171 MESSAGE_REQUEST_MACREG, 1, &priv->local_id);
175 /* do MACbSoftwareReset in MACvInitialize */
177 priv->top_ofdm_basic_rate = RATE_24M;
178 priv->top_cck_basic_rate = RATE_1M;
180 /* target to IF pin while programming to RF chip */
183 priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK];
184 priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG];
185 /* load power table */
186 for (ii = 0; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) {
187 priv->cck_pwr_tbl[ii] =
188 priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL];
189 if (priv->cck_pwr_tbl[ii] == 0)
190 priv->cck_pwr_tbl[ii] = priv->cck_pwr;
192 priv->ofdm_pwr_tbl[ii] =
193 priv->eeprom[ii + EEP_OFS_OFDM_PWR_TBL];
194 if (priv->ofdm_pwr_tbl[ii] == 0)
195 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_g;
199 * original zonetype is USA, but custom zonetype is Europe,
200 * then need to recover 12, 13, 14 channels with 11 channel
202 for (ii = 11; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) {
203 priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10];
204 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10];
207 priv->ofdm_pwr_a = 0x34; /* same as RFbMA2829SelectChannel */
209 /* load OFDM A power table */
210 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
211 priv->ofdm_a_pwr_tbl[ii] =
212 priv->eeprom[ii + EEP_OFS_OFDMA_PWR_TBL];
214 if (priv->ofdm_a_pwr_tbl[ii] == 0)
215 priv->ofdm_a_pwr_tbl[ii] = priv->ofdm_pwr_a;
218 antenna = priv->eeprom[EEP_OFS_ANTENNA];
220 if (antenna & EEP_ANTINV)
221 priv->tx_rx_ant_inv = true;
223 priv->tx_rx_ant_inv = false;
225 antenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
227 if (antenna == 0) /* if not set default is both */
228 antenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
230 if (antenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
231 priv->tx_antenna_mode = ANT_B;
232 priv->rx_antenna_sel = 1;
234 if (priv->tx_rx_ant_inv)
235 priv->rx_antenna_mode = ANT_A;
237 priv->rx_antenna_mode = ANT_B;
239 priv->rx_antenna_sel = 0;
241 if (antenna & EEP_ANTENNA_AUX) {
242 priv->tx_antenna_mode = ANT_A;
244 if (priv->tx_rx_ant_inv)
245 priv->rx_antenna_mode = ANT_B;
247 priv->rx_antenna_mode = ANT_A;
249 priv->tx_antenna_mode = ANT_B;
251 if (priv->tx_rx_ant_inv)
252 priv->rx_antenna_mode = ANT_A;
254 priv->rx_antenna_mode = ANT_B;
258 /* Set initial antenna mode */
259 ret = vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
263 /* default Auto Mode */
264 priv->bb_type = BB_TYPE_11G;
267 priv->rf_type = init_rsp->rf_type;
269 /* load vt3266 calibration parameters in EEPROM */
270 if (priv->rf_type == RF_VT3226D0) {
271 if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) &&
272 (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) {
273 calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ];
274 calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC];
275 calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ];
276 if (calib_tx_iq || calib_tx_dc || calib_rx_iq) {
277 /* CR255, enable TX/RX IQ and
278 * DC compensation mode
280 ret = vnt_control_out_u8(priv,
281 MESSAGE_REQUEST_BBREG,
286 /* CR251, TX I/Q Imbalance Calibration */
287 ret = vnt_control_out_u8(priv,
288 MESSAGE_REQUEST_BBREG,
293 /* CR252, TX DC-Offset Calibration */
294 ret = vnt_control_out_u8(priv,
295 MESSAGE_REQUEST_BBREG,
300 /* CR253, RX I/Q Imbalance Calibration */
301 ret = vnt_control_out_u8(priv,
302 MESSAGE_REQUEST_BBREG,
308 * BB Calibration compensation
310 ret = vnt_control_out_u8(priv,
311 MESSAGE_REQUEST_BBREG,
319 /* get permanent network address */
320 memcpy(priv->permanent_net_addr, init_rsp->net_addr, 6);
321 ether_addr_copy(priv->current_net_addr, priv->permanent_net_addr);
323 /* if exist SW network address, use it */
324 dev_dbg(&priv->usb->dev, "Network address = %pM\n",
325 priv->current_net_addr);
328 * set BB and packet type at the same time
329 * set Short Slot Time, xIFS, and RSPINF
331 if (priv->bb_type == BB_TYPE_11A)
332 priv->short_slot_time = true;
334 priv->short_slot_time = false;
336 ret = vnt_set_short_slot_time(priv);
340 priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL];
342 if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) {
343 ret = vnt_control_in(priv, MESSAGE_TYPE_READ,
344 MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG,
349 if ((tmp & GPIO3_DATA) == 0) {
350 ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
353 ret = vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
361 ret = vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
365 ret = vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
369 ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, BIT(0));
373 ret = vnt_radio_power_on(priv);
377 dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n");
383 static void vnt_free_tx_bufs(struct vnt_private *priv)
385 struct vnt_usb_send_context *tx_context;
388 for (ii = 0; ii < priv->num_tx_context; ii++) {
389 tx_context = priv->tx_context[ii];
393 /* deallocate URBs */
394 if (tx_context->urb) {
395 usb_kill_urb(tx_context->urb);
396 usb_free_urb(tx_context->urb);
403 static void vnt_free_rx_bufs(struct vnt_private *priv)
408 for (ii = 0; ii < priv->num_rcb; ii++) {
413 /* deallocate URBs */
415 usb_kill_urb(rcb->urb);
416 usb_free_urb(rcb->urb);
421 dev_kfree_skb(rcb->skb);
427 static void vnt_free_int_bufs(struct vnt_private *priv)
429 kfree(priv->int_buf.data_buf);
432 static int vnt_alloc_bufs(struct vnt_private *priv)
435 struct vnt_usb_send_context *tx_context;
439 for (ii = 0; ii < priv->num_tx_context; ii++) {
440 tx_context = kmalloc(sizeof(*tx_context), GFP_KERNEL);
446 priv->tx_context[ii] = tx_context;
447 tx_context->priv = priv;
448 tx_context->pkt_no = ii;
451 tx_context->urb = usb_alloc_urb(0, GFP_KERNEL);
452 if (!tx_context->urb) {
457 tx_context->in_use = false;
460 for (ii = 0; ii < priv->num_rcb; ii++) {
461 priv->rcb[ii] = kzalloc(sizeof(*priv->rcb[ii]), GFP_KERNEL);
462 if (!priv->rcb[ii]) {
472 rcb->urb = usb_alloc_urb(0, GFP_KERNEL);
478 rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
484 ret = vnt_submit_rx_urb(priv, rcb);
489 priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL);
490 if (!priv->interrupt_urb) {
495 priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
496 if (!priv->int_buf.data_buf) {
504 usb_free_urb(priv->interrupt_urb);
506 vnt_free_rx_bufs(priv);
508 vnt_free_tx_bufs(priv);
512 static void vnt_tx_80211(struct ieee80211_hw *hw,
513 struct ieee80211_tx_control *control,
516 struct vnt_private *priv = hw->priv;
518 if (vnt_tx_packet(priv, skb))
519 ieee80211_free_txskb(hw, skb);
522 static int vnt_start(struct ieee80211_hw *hw)
525 struct vnt_private *priv = hw->priv;
527 priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
529 ret = vnt_alloc_bufs(priv);
531 dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n");
535 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
537 ret = vnt_init_registers(priv);
539 dev_dbg(&priv->usb->dev, " init register fail\n");
543 ret = vnt_key_init_table(priv);
547 priv->int_interval = 1; /* bInterval is set to 1 */
549 ret = vnt_start_interrupt_urb(priv);
553 ieee80211_wake_queues(hw);
558 vnt_free_rx_bufs(priv);
559 vnt_free_tx_bufs(priv);
560 vnt_free_int_bufs(priv);
562 usb_kill_urb(priv->interrupt_urb);
563 usb_free_urb(priv->interrupt_urb);
568 static void vnt_stop(struct ieee80211_hw *hw)
570 struct vnt_private *priv = hw->priv;
576 for (i = 0; i < MAX_KEY_TABLE; i++)
577 vnt_mac_disable_keyentry(priv, i);
580 priv->key_entry_inuse = 0;
582 if (!test_bit(DEVICE_FLAGS_UNPLUG, &priv->flags))
583 vnt_mac_shutdown(priv);
585 ieee80211_stop_queues(hw);
587 set_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
589 cancel_delayed_work_sync(&priv->run_command_work);
591 priv->cmd_running = false;
593 vnt_free_tx_bufs(priv);
594 vnt_free_rx_bufs(priv);
595 vnt_free_int_bufs(priv);
597 usb_kill_urb(priv->interrupt_urb);
598 usb_free_urb(priv->interrupt_urb);
601 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
603 struct vnt_private *priv = hw->priv;
608 case NL80211_IFTYPE_STATION:
610 case NL80211_IFTYPE_ADHOC:
611 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
613 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
616 case NL80211_IFTYPE_AP:
617 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
619 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_AP);
626 priv->op_mode = vif->type;
628 vnt_set_bss_mode(priv);
630 /* LED blink on TX */
631 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER);
636 static void vnt_remove_interface(struct ieee80211_hw *hw,
637 struct ieee80211_vif *vif)
639 struct vnt_private *priv = hw->priv;
642 case NL80211_IFTYPE_STATION:
644 case NL80211_IFTYPE_ADHOC:
645 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
646 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
647 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
649 case NL80211_IFTYPE_AP:
650 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
651 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
652 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_AP);
658 vnt_radio_power_off(priv);
660 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
663 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
666 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
668 struct vnt_private *priv = hw->priv;
669 struct ieee80211_conf *conf = &hw->conf;
671 if (changed & IEEE80211_CONF_CHANGE_PS) {
672 if (conf->flags & IEEE80211_CONF_PS)
673 vnt_enable_power_saving(priv, conf->listen_interval);
675 vnt_disable_power_saving(priv);
678 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
679 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
680 vnt_set_channel(priv, conf->chandef.chan->hw_value);
682 if (conf->chandef.chan->band == NL80211_BAND_5GHZ)
683 priv->bb_type = BB_TYPE_11A;
685 priv->bb_type = BB_TYPE_11G;
688 if (changed & IEEE80211_CONF_CHANGE_POWER) {
689 if (priv->bb_type == BB_TYPE_11B)
690 priv->current_rate = RATE_1M;
692 priv->current_rate = RATE_54M;
694 vnt_rf_setpower(priv, priv->current_rate,
695 conf->chandef.chan->hw_value);
701 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
702 struct ieee80211_vif *vif,
703 struct ieee80211_bss_conf *conf, u32 changed)
705 struct vnt_private *priv = hw->priv;
707 priv->current_aid = conf->aid;
709 if (changed & BSS_CHANGED_BSSID && conf->bssid)
710 vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid);
712 if (changed & BSS_CHANGED_BASIC_RATES) {
713 priv->basic_rates = conf->basic_rates;
715 vnt_update_top_rates(priv);
716 vnt_set_bss_mode(priv);
718 dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates);
721 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
722 if (conf->use_short_preamble) {
723 vnt_mac_enable_barker_preamble_mode(priv);
724 priv->preamble_type = true;
726 vnt_mac_disable_barker_preamble_mode(priv);
727 priv->preamble_type = false;
731 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
732 if (conf->use_cts_prot)
733 vnt_mac_enable_protect_mode(priv);
735 vnt_mac_disable_protect_mode(priv);
738 if (changed & BSS_CHANGED_ERP_SLOT) {
739 if (conf->use_short_slot)
740 priv->short_slot_time = true;
742 priv->short_slot_time = false;
744 vnt_set_short_slot_time(priv);
745 vnt_update_ifs(priv);
746 vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
747 vnt_update_pre_ed_threshold(priv, false);
750 if (changed & BSS_CHANGED_TXPOWER)
751 vnt_rf_setpower(priv, priv->current_rate,
752 conf->chandef.chan->hw_value);
754 if (changed & BSS_CHANGED_BEACON_ENABLED) {
755 dev_dbg(&priv->usb->dev,
756 "Beacon enable %d\n", conf->enable_beacon);
758 if (conf->enable_beacon) {
759 vnt_beacon_enable(priv, vif, conf);
761 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
763 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
767 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INFO) &&
768 priv->op_mode != NL80211_IFTYPE_AP) {
769 if (conf->assoc && conf->beacon_rate) {
770 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL,
773 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
775 vnt_reset_next_tbtt(priv, conf->beacon_int);
777 vnt_adjust_tsf(priv, conf->beacon_rate->hw_value,
778 conf->sync_tsf, priv->current_tsf);
780 vnt_update_next_tbtt(priv,
781 conf->sync_tsf, conf->beacon_int);
783 vnt_clear_current_tsf(priv);
785 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL,
791 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
792 struct netdev_hw_addr_list *mc_list)
794 struct vnt_private *priv = hw->priv;
795 struct netdev_hw_addr *ha;
799 netdev_hw_addr_list_for_each(ha, mc_list) {
800 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
801 mc_filter |= BIT_ULL(bit_nr);
804 priv->mc_list_count = mc_list->count;
809 static void vnt_configure(struct ieee80211_hw *hw,
810 unsigned int changed_flags,
811 unsigned int *total_flags, u64 multicast)
813 struct vnt_private *priv = hw->priv;
816 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC;
818 vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
819 MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
821 dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode);
823 if (changed_flags & FIF_ALLMULTI) {
824 if (*total_flags & FIF_ALLMULTI) {
825 if (priv->mc_list_count > 2)
826 vnt_mac_set_filter(priv, ~0);
828 vnt_mac_set_filter(priv, multicast);
830 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
832 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
836 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
837 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
838 rx_mode &= ~RCR_BSSID;
840 rx_mode |= RCR_BSSID;
843 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode);
845 dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode);
848 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
849 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
850 struct ieee80211_key_conf *key)
852 struct vnt_private *priv = hw->priv;
856 return vnt_set_keys(hw, sta, vif, key);
858 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse)) {
859 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
861 vnt_mac_disable_keyentry(priv, key->hw_key_idx);
871 static void vnt_sw_scan_start(struct ieee80211_hw *hw,
872 struct ieee80211_vif *vif,
875 struct vnt_private *priv = hw->priv;
877 /* Set max sensitivity*/
878 vnt_update_pre_ed_threshold(priv, true);
881 static void vnt_sw_scan_complete(struct ieee80211_hw *hw,
882 struct ieee80211_vif *vif)
884 struct vnt_private *priv = hw->priv;
886 /* Return sensitivity to channel level*/
887 vnt_update_pre_ed_threshold(priv, false);
890 static int vnt_get_stats(struct ieee80211_hw *hw,
891 struct ieee80211_low_level_stats *stats)
893 struct vnt_private *priv = hw->priv;
895 memcpy(stats, &priv->low_stats, sizeof(*stats));
900 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
902 struct vnt_private *priv = hw->priv;
904 return priv->current_tsf;
907 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
910 struct vnt_private *priv = hw->priv;
912 vnt_update_next_tbtt(priv, tsf, vif->bss_conf.beacon_int);
915 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
917 struct vnt_private *priv = hw->priv;
919 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
921 vnt_clear_current_tsf(priv);
924 static const struct ieee80211_ops vnt_mac_ops = {
928 .add_interface = vnt_add_interface,
929 .remove_interface = vnt_remove_interface,
930 .config = vnt_config,
931 .bss_info_changed = vnt_bss_info_changed,
932 .prepare_multicast = vnt_prepare_multicast,
933 .configure_filter = vnt_configure,
934 .set_key = vnt_set_key,
935 .sw_scan_start = vnt_sw_scan_start,
936 .sw_scan_complete = vnt_sw_scan_complete,
937 .get_stats = vnt_get_stats,
938 .get_tsf = vnt_get_tsf,
939 .set_tsf = vnt_set_tsf,
940 .reset_tsf = vnt_reset_tsf,
943 int vnt_init(struct vnt_private *priv)
945 if (vnt_init_registers(priv))
948 SET_IEEE80211_PERM_ADDR(priv->hw, priv->permanent_net_addr);
950 vnt_init_bands(priv);
952 if (ieee80211_register_hw(priv->hw))
957 vnt_radio_power_off(priv);
963 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
965 struct usb_device *udev;
966 struct vnt_private *priv;
967 struct ieee80211_hw *hw;
971 udev = usb_get_dev(interface_to_usbdev(intf));
973 dev_notice(&udev->dev, "%s Ver. %s\n",
974 DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
975 dev_notice(&udev->dev,
976 "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
978 hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops);
980 dev_err(&udev->dev, "could not register ieee80211_hw\n");
990 vnt_set_options(priv);
992 spin_lock_init(&priv->lock);
993 mutex_init(&priv->usb_lock);
995 INIT_DELAYED_WORK(&priv->run_command_work, vnt_run_command);
997 usb_set_intfdata(intf, priv);
999 wiphy = priv->hw->wiphy;
1001 wiphy->frag_threshold = FRAG_THRESH_DEF;
1002 wiphy->rts_threshold = RTS_THRESH_DEF;
1003 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1004 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1006 ieee80211_hw_set(priv->hw, TIMING_BEACON_ONLY);
1007 ieee80211_hw_set(priv->hw, SIGNAL_DBM);
1008 ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS);
1009 ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS);
1010 ieee80211_hw_set(priv->hw, SUPPORTS_PS);
1011 ieee80211_hw_set(priv->hw, PS_NULLFUNC_STACK);
1013 priv->hw->max_signal = 100;
1015 SET_IEEE80211_DEV(priv->hw, &intf->dev);
1017 rc = usb_reset_device(priv->usb);
1019 dev_warn(&priv->usb->dev,
1020 "%s reset fail status=%d\n", __func__, rc);
1022 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
1023 vnt_reset_command_timer(priv);
1025 vnt_schedule_command(priv, WLAN_CMD_INIT_MAC80211);
1035 static void vt6656_disconnect(struct usb_interface *intf)
1037 struct vnt_private *priv = usb_get_intfdata(intf);
1043 ieee80211_unregister_hw(priv->hw);
1045 usb_set_intfdata(intf, NULL);
1046 usb_put_dev(interface_to_usbdev(intf));
1048 set_bit(DEVICE_FLAGS_UNPLUG, &priv->flags);
1050 ieee80211_free_hw(priv->hw);
1055 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
1060 static int vt6656_resume(struct usb_interface *intf)
1065 #endif /* CONFIG_PM */
1067 MODULE_DEVICE_TABLE(usb, vt6656_table);
1069 static struct usb_driver vt6656_driver = {
1070 .name = DEVICE_NAME,
1071 .probe = vt6656_probe,
1072 .disconnect = vt6656_disconnect,
1073 .id_table = vt6656_table,
1075 .suspend = vt6656_suspend,
1076 .resume = vt6656_resume,
1077 #endif /* CONFIG_PM */
1080 module_usb_driver(vt6656_driver);