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/etherdevice.h>
25 #include <linux/file.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->auto_fb_ctrl = AUTO_FB_0;
103 priv->preamble_type = 0;
104 priv->exist_sw_net_addr = false;
108 * initialization of MAC & BBP registers
110 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;
116 int status = STATUS_SUCCESS;
118 u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
120 dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n",
121 DEVICE_INIT_COLD, priv->packet_type);
123 if (!vnt_check_firmware_version(priv)) {
124 if (vnt_download_firmware(priv) == true) {
125 if (vnt_firmware_branch_to_sram(priv) == false) {
126 dev_dbg(&priv->usb->dev,
127 " vnt_firmware_branch_to_sram fail\n");
131 dev_dbg(&priv->usb->dev, "FIRMWAREbDownload fail\n");
136 if (!vnt_vt3184_init(priv)) {
137 dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n");
141 init_cmd->init_class = DEVICE_INIT_COLD;
142 init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr;
143 for (ii = 0; ii < 6; ii++)
144 init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii];
145 init_cmd->short_retry_limit = priv->short_retry_limit;
146 init_cmd->long_retry_limit = priv->long_retry_limit;
148 /* issue card_init command to device */
149 status = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0,
150 sizeof(struct vnt_cmd_card_init),
152 if (status != STATUS_SUCCESS) {
153 dev_dbg(&priv->usb->dev, "Issue Card init fail\n");
157 status = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
158 sizeof(struct vnt_rsp_card_init),
160 if (status != STATUS_SUCCESS) {
161 dev_dbg(&priv->usb->dev,
162 "Cardinit request in status fail!\n");
166 /* local ID for AES functions */
167 status = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID,
168 MESSAGE_REQUEST_MACREG, 1, &priv->local_id);
169 if (status != STATUS_SUCCESS)
172 /* do MACbSoftwareReset in MACvInitialize */
174 priv->top_ofdm_basic_rate = RATE_24M;
175 priv->top_cck_basic_rate = RATE_1M;
177 /* target to IF pin while programming to RF chip */
180 priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK];
181 priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG];
182 /* load power table */
183 for (ii = 0; ii < 14; ii++) {
184 priv->cck_pwr_tbl[ii] =
185 priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL];
186 if (priv->cck_pwr_tbl[ii] == 0)
187 priv->cck_pwr_tbl[ii] = priv->cck_pwr;
189 priv->ofdm_pwr_tbl[ii] =
190 priv->eeprom[ii + EEP_OFS_OFDM_PWR_TBL];
191 if (priv->ofdm_pwr_tbl[ii] == 0)
192 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_g;
196 * original zonetype is USA, but custom zonetype is Europe,
197 * then need to recover 12, 13, 14 channels with 11 channel
199 for (ii = 11; ii < 14; ii++) {
200 priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10];
201 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10];
204 priv->ofdm_pwr_a = 0x34; /* same as RFbMA2829SelectChannel */
206 /* load OFDM A power table */
207 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
208 priv->ofdm_a_pwr_tbl[ii] =
209 priv->eeprom[ii + EEP_OFS_OFDMA_PWR_TBL];
211 if (priv->ofdm_a_pwr_tbl[ii] == 0)
212 priv->ofdm_a_pwr_tbl[ii] = priv->ofdm_pwr_a;
215 antenna = priv->eeprom[EEP_OFS_ANTENNA];
217 if (antenna & EEP_ANTINV)
218 priv->tx_rx_ant_inv = true;
220 priv->tx_rx_ant_inv = false;
222 antenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
224 if (antenna == 0) /* if not set default is both */
225 antenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
227 if (antenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
228 priv->tx_antenna_mode = ANT_B;
229 priv->rx_antenna_sel = 1;
231 if (priv->tx_rx_ant_inv)
232 priv->rx_antenna_mode = ANT_A;
234 priv->rx_antenna_mode = ANT_B;
236 priv->rx_antenna_sel = 0;
238 if (antenna & EEP_ANTENNA_AUX) {
239 priv->tx_antenna_mode = ANT_A;
241 if (priv->tx_rx_ant_inv)
242 priv->rx_antenna_mode = ANT_B;
244 priv->rx_antenna_mode = ANT_A;
246 priv->tx_antenna_mode = ANT_B;
248 if (priv->tx_rx_ant_inv)
249 priv->rx_antenna_mode = ANT_A;
251 priv->rx_antenna_mode = ANT_B;
255 /* Set initial antenna mode */
256 vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
258 /* get Auto Fall Back type */
259 priv->auto_fb_ctrl = AUTO_FB_0;
261 /* default Auto Mode */
262 priv->bb_type = BB_TYPE_11G;
265 priv->rf_type = init_rsp->rf_type;
267 /* load vt3266 calibration parameters in EEPROM */
268 if (priv->rf_type == RF_VT3226D0) {
269 if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) &&
270 (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) {
271 calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ];
272 calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC];
273 calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ];
274 if (calib_tx_iq || calib_tx_dc || calib_rx_iq) {
275 /* CR255, enable TX/RX IQ and
276 * DC compensation mode
278 vnt_control_out_u8(priv,
279 MESSAGE_REQUEST_BBREG,
282 /* CR251, TX I/Q Imbalance Calibration */
283 vnt_control_out_u8(priv,
284 MESSAGE_REQUEST_BBREG,
287 /* CR252, TX DC-Offset Calibration */
288 vnt_control_out_u8(priv,
289 MESSAGE_REQUEST_BBREG,
292 /* CR253, RX I/Q Imbalance Calibration */
293 vnt_control_out_u8(priv,
294 MESSAGE_REQUEST_BBREG,
299 * BB Calibration compensation
301 vnt_control_out_u8(priv,
302 MESSAGE_REQUEST_BBREG,
309 /* get permanent network address */
310 memcpy(priv->permanent_net_addr, init_rsp->net_addr, 6);
311 ether_addr_copy(priv->current_net_addr, priv->permanent_net_addr);
313 /* if exist SW network address, use it */
314 dev_dbg(&priv->usb->dev, "Network address = %pM\n",
315 priv->current_net_addr);
318 * set BB and packet type at the same time
319 * set Short Slot Time, xIFS, and RSPINF
321 if (priv->bb_type == BB_TYPE_11A)
322 priv->short_slot_time = true;
324 priv->short_slot_time = false;
326 vnt_set_short_slot_time(priv);
328 priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL];
330 if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) {
331 status = vnt_control_in(priv, MESSAGE_TYPE_READ,
333 MESSAGE_REQUEST_MACREG, 1, &tmp);
335 if (status != STATUS_SUCCESS)
338 if ((tmp & GPIO3_DATA) == 0)
339 vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
342 vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
346 vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
348 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
350 vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01);
352 vnt_radio_power_on(priv);
354 dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n");
359 static void vnt_free_tx_bufs(struct vnt_private *priv)
361 struct vnt_usb_send_context *tx_context;
364 for (ii = 0; ii < priv->num_tx_context; ii++) {
365 tx_context = priv->tx_context[ii];
366 /* deallocate URBs */
367 if (tx_context->urb) {
368 usb_kill_urb(tx_context->urb);
369 usb_free_urb(tx_context->urb);
376 static void vnt_free_rx_bufs(struct vnt_private *priv)
381 for (ii = 0; ii < priv->num_rcb; ii++) {
386 /* deallocate URBs */
388 usb_kill_urb(rcb->urb);
389 usb_free_urb(rcb->urb);
394 dev_kfree_skb(rcb->skb);
400 static void vnt_free_int_bufs(struct vnt_private *priv)
402 kfree(priv->int_buf.data_buf);
405 static bool vnt_alloc_bufs(struct vnt_private *priv)
407 struct vnt_usb_send_context *tx_context;
411 for (ii = 0; ii < priv->num_tx_context; ii++) {
412 tx_context = kmalloc(sizeof(*tx_context), GFP_KERNEL);
416 priv->tx_context[ii] = tx_context;
417 tx_context->priv = priv;
418 tx_context->pkt_no = ii;
421 tx_context->urb = usb_alloc_urb(0, GFP_KERNEL);
422 if (!tx_context->urb)
425 tx_context->in_use = false;
428 for (ii = 0; ii < priv->num_rcb; ii++) {
429 priv->rcb[ii] = kzalloc(sizeof(*priv->rcb[ii]), GFP_KERNEL);
438 rcb->urb = usb_alloc_urb(0, GFP_KERNEL);
442 rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
449 if (vnt_submit_rx_urb(priv, rcb))
453 priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL);
454 if (!priv->interrupt_urb)
457 priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
458 if (!priv->int_buf.data_buf) {
459 usb_free_urb(priv->interrupt_urb);
466 vnt_free_rx_bufs(priv);
469 vnt_free_tx_bufs(priv);
474 static void vnt_tx_80211(struct ieee80211_hw *hw,
475 struct ieee80211_tx_control *control,
478 struct vnt_private *priv = hw->priv;
480 if (vnt_tx_packet(priv, skb))
481 ieee80211_free_txskb(hw, skb);
484 static int vnt_start(struct ieee80211_hw *hw)
486 struct vnt_private *priv = hw->priv;
488 priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
490 if (!vnt_alloc_bufs(priv)) {
491 dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n");
495 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
497 if (vnt_init_registers(priv) == false) {
498 dev_dbg(&priv->usb->dev, " init register fail\n");
502 if (vnt_key_init_table(priv))
505 priv->int_interval = 1; /* bInterval is set to 1 */
507 vnt_int_start_interrupt(priv);
509 ieee80211_wake_queues(hw);
514 vnt_free_rx_bufs(priv);
515 vnt_free_tx_bufs(priv);
516 vnt_free_int_bufs(priv);
518 usb_kill_urb(priv->interrupt_urb);
519 usb_free_urb(priv->interrupt_urb);
524 static void vnt_stop(struct ieee80211_hw *hw)
526 struct vnt_private *priv = hw->priv;
532 for (i = 0; i < MAX_KEY_TABLE; i++)
533 vnt_mac_disable_keyentry(priv, i);
536 priv->key_entry_inuse = 0;
538 if (!test_bit(DEVICE_FLAGS_UNPLUG, &priv->flags))
539 vnt_mac_shutdown(priv);
541 ieee80211_stop_queues(hw);
543 set_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
545 cancel_delayed_work_sync(&priv->run_command_work);
547 priv->cmd_running = false;
549 vnt_free_tx_bufs(priv);
550 vnt_free_rx_bufs(priv);
551 vnt_free_int_bufs(priv);
553 usb_kill_urb(priv->interrupt_urb);
554 usb_free_urb(priv->interrupt_urb);
557 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
559 struct vnt_private *priv = hw->priv;
564 case NL80211_IFTYPE_STATION:
566 case NL80211_IFTYPE_ADHOC:
567 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
569 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
572 case NL80211_IFTYPE_AP:
573 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
575 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_AP);
582 priv->op_mode = vif->type;
584 vnt_set_bss_mode(priv);
586 /* LED blink on TX */
587 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER);
592 static void vnt_remove_interface(struct ieee80211_hw *hw,
593 struct ieee80211_vif *vif)
595 struct vnt_private *priv = hw->priv;
598 case NL80211_IFTYPE_STATION:
600 case NL80211_IFTYPE_ADHOC:
601 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
602 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
603 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
605 case NL80211_IFTYPE_AP:
606 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
607 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
608 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_AP);
614 vnt_radio_power_off(priv);
616 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
619 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
622 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
624 struct vnt_private *priv = hw->priv;
625 struct ieee80211_conf *conf = &hw->conf;
627 if (changed & IEEE80211_CONF_CHANGE_PS) {
628 if (conf->flags & IEEE80211_CONF_PS)
629 vnt_enable_power_saving(priv, conf->listen_interval);
631 vnt_disable_power_saving(priv);
634 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
635 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
636 vnt_set_channel(priv, conf->chandef.chan->hw_value);
638 if (conf->chandef.chan->band == NL80211_BAND_5GHZ)
639 priv->bb_type = BB_TYPE_11A;
641 priv->bb_type = BB_TYPE_11G;
644 if (changed & IEEE80211_CONF_CHANGE_POWER) {
645 if (priv->bb_type == BB_TYPE_11B)
646 priv->current_rate = RATE_1M;
648 priv->current_rate = RATE_54M;
650 vnt_rf_setpower(priv, priv->current_rate,
651 conf->chandef.chan->hw_value);
657 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
658 struct ieee80211_vif *vif,
659 struct ieee80211_bss_conf *conf, u32 changed)
661 struct vnt_private *priv = hw->priv;
663 priv->current_aid = conf->aid;
665 if (changed & BSS_CHANGED_BSSID && conf->bssid)
666 vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid);
668 if (changed & BSS_CHANGED_BASIC_RATES) {
669 priv->basic_rates = conf->basic_rates;
671 vnt_update_top_rates(priv);
672 vnt_set_bss_mode(priv);
674 dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates);
677 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
678 if (conf->use_short_preamble) {
679 vnt_mac_enable_barker_preamble_mode(priv);
680 priv->preamble_type = true;
682 vnt_mac_disable_barker_preamble_mode(priv);
683 priv->preamble_type = false;
687 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
688 if (conf->use_cts_prot)
689 vnt_mac_enable_protect_mode(priv);
691 vnt_mac_disable_protect_mode(priv);
694 if (changed & BSS_CHANGED_ERP_SLOT) {
695 if (conf->use_short_slot)
696 priv->short_slot_time = true;
698 priv->short_slot_time = false;
700 vnt_set_short_slot_time(priv);
701 vnt_update_ifs(priv);
702 vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
703 vnt_update_pre_ed_threshold(priv, false);
706 if (changed & BSS_CHANGED_TXPOWER)
707 vnt_rf_setpower(priv, priv->current_rate,
708 conf->chandef.chan->hw_value);
710 if (changed & BSS_CHANGED_BEACON_ENABLED) {
711 dev_dbg(&priv->usb->dev,
712 "Beacon enable %d\n", conf->enable_beacon);
714 if (conf->enable_beacon) {
715 vnt_beacon_enable(priv, vif, conf);
717 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
719 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
723 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INFO) &&
724 priv->op_mode != NL80211_IFTYPE_AP) {
725 if (conf->assoc && conf->beacon_rate) {
726 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL,
729 vnt_adjust_tsf(priv, conf->beacon_rate->hw_value,
730 conf->sync_tsf, priv->current_tsf);
732 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
734 vnt_reset_next_tbtt(priv, conf->beacon_int);
736 vnt_clear_current_tsf(priv);
738 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL,
744 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
745 struct netdev_hw_addr_list *mc_list)
747 struct vnt_private *priv = hw->priv;
748 struct netdev_hw_addr *ha;
752 netdev_hw_addr_list_for_each(ha, mc_list) {
753 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
755 mc_filter |= 1ULL << (bit_nr & 0x3f);
758 priv->mc_list_count = mc_list->count;
763 static void vnt_configure(struct ieee80211_hw *hw,
764 unsigned int changed_flags,
765 unsigned int *total_flags, u64 multicast)
767 struct vnt_private *priv = hw->priv;
771 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC;
773 rc = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
774 MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
777 rx_mode = RCR_MULTICAST | RCR_BROADCAST;
779 dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode);
781 if (changed_flags & FIF_ALLMULTI) {
782 if (*total_flags & FIF_ALLMULTI) {
783 if (priv->mc_list_count > 2)
784 vnt_mac_set_filter(priv, ~0);
786 vnt_mac_set_filter(priv, multicast);
788 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
790 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
794 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
795 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
796 rx_mode &= ~RCR_BSSID;
798 rx_mode |= RCR_BSSID;
801 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode);
803 dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode);
806 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
807 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
808 struct ieee80211_key_conf *key)
810 struct vnt_private *priv = hw->priv;
814 if (vnt_set_keys(hw, sta, vif, key))
818 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
819 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
827 static void vnt_sw_scan_start(struct ieee80211_hw *hw,
828 struct ieee80211_vif *vif,
831 struct vnt_private *priv = hw->priv;
833 /* Set max sensitivity*/
834 vnt_update_pre_ed_threshold(priv, true);
837 static void vnt_sw_scan_complete(struct ieee80211_hw *hw,
838 struct ieee80211_vif *vif)
840 struct vnt_private *priv = hw->priv;
842 /* Return sensitivity to channel level*/
843 vnt_update_pre_ed_threshold(priv, false);
846 static int vnt_get_stats(struct ieee80211_hw *hw,
847 struct ieee80211_low_level_stats *stats)
849 struct vnt_private *priv = hw->priv;
851 memcpy(stats, &priv->low_stats, sizeof(*stats));
856 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
858 struct vnt_private *priv = hw->priv;
860 return priv->current_tsf;
863 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
866 struct vnt_private *priv = hw->priv;
868 vnt_update_next_tbtt(priv, tsf, vif->bss_conf.beacon_int);
871 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
873 struct vnt_private *priv = hw->priv;
875 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
877 vnt_clear_current_tsf(priv);
880 static const struct ieee80211_ops vnt_mac_ops = {
884 .add_interface = vnt_add_interface,
885 .remove_interface = vnt_remove_interface,
886 .config = vnt_config,
887 .bss_info_changed = vnt_bss_info_changed,
888 .prepare_multicast = vnt_prepare_multicast,
889 .configure_filter = vnt_configure,
890 .set_key = vnt_set_key,
891 .sw_scan_start = vnt_sw_scan_start,
892 .sw_scan_complete = vnt_sw_scan_complete,
893 .get_stats = vnt_get_stats,
894 .get_tsf = vnt_get_tsf,
895 .set_tsf = vnt_set_tsf,
896 .reset_tsf = vnt_reset_tsf,
899 int vnt_init(struct vnt_private *priv)
901 if (!(vnt_init_registers(priv)))
904 SET_IEEE80211_PERM_ADDR(priv->hw, priv->permanent_net_addr);
906 vnt_init_bands(priv);
908 if (ieee80211_register_hw(priv->hw))
913 vnt_radio_power_off(priv);
919 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
921 struct usb_device *udev;
922 struct vnt_private *priv;
923 struct ieee80211_hw *hw;
927 udev = usb_get_dev(interface_to_usbdev(intf));
929 dev_notice(&udev->dev, "%s Ver. %s\n",
930 DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
931 dev_notice(&udev->dev,
932 "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
934 hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops);
936 dev_err(&udev->dev, "could not register ieee80211_hw\n");
945 vnt_set_options(priv);
947 spin_lock_init(&priv->lock);
948 mutex_init(&priv->usb_lock);
950 INIT_DELAYED_WORK(&priv->run_command_work, vnt_run_command);
952 usb_set_intfdata(intf, priv);
954 wiphy = priv->hw->wiphy;
956 wiphy->frag_threshold = FRAG_THRESH_DEF;
957 wiphy->rts_threshold = RTS_THRESH_DEF;
958 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
959 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
961 ieee80211_hw_set(priv->hw, TIMING_BEACON_ONLY);
962 ieee80211_hw_set(priv->hw, SIGNAL_DBM);
963 ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS);
964 ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS);
965 ieee80211_hw_set(priv->hw, SUPPORTS_PS);
967 priv->hw->max_signal = 100;
969 SET_IEEE80211_DEV(priv->hw, &intf->dev);
971 rc = usb_reset_device(priv->usb);
973 dev_warn(&priv->usb->dev,
974 "%s reset fail status=%d\n", __func__, rc);
976 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
977 vnt_reset_command_timer(priv);
979 vnt_schedule_command(priv, WLAN_CMD_INIT_MAC80211);
989 static void vt6656_disconnect(struct usb_interface *intf)
991 struct vnt_private *priv = usb_get_intfdata(intf);
997 ieee80211_unregister_hw(priv->hw);
999 usb_set_intfdata(intf, NULL);
1000 usb_put_dev(interface_to_usbdev(intf));
1002 set_bit(DEVICE_FLAGS_UNPLUG, &priv->flags);
1004 ieee80211_free_hw(priv->hw);
1009 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
1014 static int vt6656_resume(struct usb_interface *intf)
1019 #endif /* CONFIG_PM */
1021 MODULE_DEVICE_TABLE(usb, vt6656_table);
1023 static struct usb_driver vt6656_driver = {
1024 .name = DEVICE_NAME,
1025 .probe = vt6656_probe,
1026 .disconnect = vt6656_disconnect,
1027 .id_table = vt6656_table,
1029 .suspend = vt6656_suspend,
1030 .resume = vt6656_resume,
1031 #endif /* CONFIG_PM */
1034 module_usb_driver(vt6656_driver);