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)
113 struct vnt_cmd_card_init *init_cmd = &priv->init_command;
114 struct vnt_rsp_card_init *init_rsp = &priv->init_response;
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 ret = vnt_check_firmware_version(priv);
125 ret = vnt_download_firmware(priv);
127 dev_dbg(&priv->usb->dev,
128 "Could not download firmware: %d.\n", ret);
132 ret = vnt_firmware_branch_to_sram(priv);
134 dev_dbg(&priv->usb->dev,
135 "Could not branch to SRAM: %d.\n", ret);
140 ret = vnt_vt3184_init(priv);
142 dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n");
146 init_cmd->init_class = DEVICE_INIT_COLD;
147 init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr;
148 for (ii = 0; ii < 6; ii++)
149 init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii];
150 init_cmd->short_retry_limit = priv->short_retry_limit;
151 init_cmd->long_retry_limit = priv->long_retry_limit;
153 /* issue card_init command to device */
154 ret = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0,
155 sizeof(struct vnt_cmd_card_init),
158 dev_dbg(&priv->usb->dev, "Issue Card init fail\n");
162 ret = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
163 sizeof(struct vnt_rsp_card_init),
166 dev_dbg(&priv->usb->dev, "Cardinit request in status fail!\n");
170 /* local ID for AES functions */
171 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID,
172 MESSAGE_REQUEST_MACREG, 1, &priv->local_id);
176 /* do MACbSoftwareReset in MACvInitialize */
178 priv->top_ofdm_basic_rate = RATE_24M;
179 priv->top_cck_basic_rate = RATE_1M;
181 /* target to IF pin while programming to RF chip */
184 priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK];
185 priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG];
186 /* load power table */
187 for (ii = 0; ii < 14; ii++) {
188 priv->cck_pwr_tbl[ii] =
189 priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL];
190 if (priv->cck_pwr_tbl[ii] == 0)
191 priv->cck_pwr_tbl[ii] = priv->cck_pwr;
193 priv->ofdm_pwr_tbl[ii] =
194 priv->eeprom[ii + EEP_OFS_OFDM_PWR_TBL];
195 if (priv->ofdm_pwr_tbl[ii] == 0)
196 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_g;
200 * original zonetype is USA, but custom zonetype is Europe,
201 * then need to recover 12, 13, 14 channels with 11 channel
203 for (ii = 11; ii < 14; ii++) {
204 priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10];
205 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10];
208 priv->ofdm_pwr_a = 0x34; /* same as RFbMA2829SelectChannel */
210 /* load OFDM A power table */
211 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
212 priv->ofdm_a_pwr_tbl[ii] =
213 priv->eeprom[ii + EEP_OFS_OFDMA_PWR_TBL];
215 if (priv->ofdm_a_pwr_tbl[ii] == 0)
216 priv->ofdm_a_pwr_tbl[ii] = priv->ofdm_pwr_a;
219 antenna = priv->eeprom[EEP_OFS_ANTENNA];
221 if (antenna & EEP_ANTINV)
222 priv->tx_rx_ant_inv = true;
224 priv->tx_rx_ant_inv = false;
226 antenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
228 if (antenna == 0) /* if not set default is both */
229 antenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
231 if (antenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
232 priv->tx_antenna_mode = ANT_B;
233 priv->rx_antenna_sel = 1;
235 if (priv->tx_rx_ant_inv)
236 priv->rx_antenna_mode = ANT_A;
238 priv->rx_antenna_mode = ANT_B;
240 priv->rx_antenna_sel = 0;
242 if (antenna & EEP_ANTENNA_AUX) {
243 priv->tx_antenna_mode = ANT_A;
245 if (priv->tx_rx_ant_inv)
246 priv->rx_antenna_mode = ANT_B;
248 priv->rx_antenna_mode = ANT_A;
250 priv->tx_antenna_mode = ANT_B;
252 if (priv->tx_rx_ant_inv)
253 priv->rx_antenna_mode = ANT_A;
255 priv->rx_antenna_mode = ANT_B;
259 /* Set initial antenna mode */
260 ret = vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
264 /* get Auto Fall Back type */
265 priv->auto_fb_ctrl = AUTO_FB_0;
267 /* default Auto Mode */
268 priv->bb_type = BB_TYPE_11G;
271 priv->rf_type = init_rsp->rf_type;
273 /* load vt3266 calibration parameters in EEPROM */
274 if (priv->rf_type == RF_VT3226D0) {
275 if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) &&
276 (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) {
277 calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ];
278 calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC];
279 calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ];
280 if (calib_tx_iq || calib_tx_dc || calib_rx_iq) {
281 /* CR255, enable TX/RX IQ and
282 * DC compensation mode
284 ret = vnt_control_out_u8(priv,
285 MESSAGE_REQUEST_BBREG,
290 /* CR251, TX I/Q Imbalance Calibration */
291 ret = vnt_control_out_u8(priv,
292 MESSAGE_REQUEST_BBREG,
297 /* CR252, TX DC-Offset Calibration */
298 ret = vnt_control_out_u8(priv,
299 MESSAGE_REQUEST_BBREG,
304 /* CR253, RX I/Q Imbalance Calibration */
305 ret = vnt_control_out_u8(priv,
306 MESSAGE_REQUEST_BBREG,
312 * BB Calibration compensation
314 ret = vnt_control_out_u8(priv,
315 MESSAGE_REQUEST_BBREG,
323 /* get permanent network address */
324 memcpy(priv->permanent_net_addr, init_rsp->net_addr, 6);
325 ether_addr_copy(priv->current_net_addr, priv->permanent_net_addr);
327 /* if exist SW network address, use it */
328 dev_dbg(&priv->usb->dev, "Network address = %pM\n",
329 priv->current_net_addr);
332 * set BB and packet type at the same time
333 * set Short Slot Time, xIFS, and RSPINF
335 if (priv->bb_type == BB_TYPE_11A)
336 priv->short_slot_time = true;
338 priv->short_slot_time = false;
340 ret = vnt_set_short_slot_time(priv);
344 priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL];
346 if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) {
347 ret = vnt_control_in(priv, MESSAGE_TYPE_READ,
348 MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG,
353 if ((tmp & GPIO3_DATA) == 0) {
354 ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
357 ret = vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
365 ret = vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
369 ret = vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
373 ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01);
377 ret = vnt_radio_power_on(priv);
381 dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n");
387 static void vnt_free_tx_bufs(struct vnt_private *priv)
389 struct vnt_usb_send_context *tx_context;
392 for (ii = 0; ii < priv->num_tx_context; ii++) {
393 tx_context = priv->tx_context[ii];
397 /* deallocate URBs */
398 if (tx_context->urb) {
399 usb_kill_urb(tx_context->urb);
400 usb_free_urb(tx_context->urb);
407 static void vnt_free_rx_bufs(struct vnt_private *priv)
412 for (ii = 0; ii < priv->num_rcb; ii++) {
417 /* deallocate URBs */
419 usb_kill_urb(rcb->urb);
420 usb_free_urb(rcb->urb);
425 dev_kfree_skb(rcb->skb);
431 static void vnt_free_int_bufs(struct vnt_private *priv)
433 kfree(priv->int_buf.data_buf);
436 static int vnt_alloc_bufs(struct vnt_private *priv)
439 struct vnt_usb_send_context *tx_context;
443 for (ii = 0; ii < priv->num_tx_context; ii++) {
444 tx_context = kmalloc(sizeof(*tx_context), GFP_KERNEL);
450 priv->tx_context[ii] = tx_context;
451 tx_context->priv = priv;
452 tx_context->pkt_no = ii;
455 tx_context->urb = usb_alloc_urb(0, GFP_KERNEL);
456 if (!tx_context->urb) {
461 tx_context->in_use = false;
464 for (ii = 0; ii < priv->num_rcb; ii++) {
465 priv->rcb[ii] = kzalloc(sizeof(*priv->rcb[ii]), GFP_KERNEL);
466 if (!priv->rcb[ii]) {
476 rcb->urb = usb_alloc_urb(0, GFP_KERNEL);
482 rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
491 ret = vnt_submit_rx_urb(priv, rcb);
496 priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL);
497 if (!priv->interrupt_urb) {
502 priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
503 if (!priv->int_buf.data_buf) {
511 usb_free_urb(priv->interrupt_urb);
513 vnt_free_rx_bufs(priv);
515 vnt_free_tx_bufs(priv);
519 static void vnt_tx_80211(struct ieee80211_hw *hw,
520 struct ieee80211_tx_control *control,
523 struct vnt_private *priv = hw->priv;
525 if (vnt_tx_packet(priv, skb))
526 ieee80211_free_txskb(hw, skb);
529 static int vnt_start(struct ieee80211_hw *hw)
532 struct vnt_private *priv = hw->priv;
534 priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
536 ret = vnt_alloc_bufs(priv);
538 dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n");
542 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
544 ret = vnt_init_registers(priv);
546 dev_dbg(&priv->usb->dev, " init register fail\n");
550 ret = vnt_key_init_table(priv);
554 priv->int_interval = 1; /* bInterval is set to 1 */
556 ret = vnt_int_start_interrupt(priv);
560 ieee80211_wake_queues(hw);
565 vnt_free_rx_bufs(priv);
566 vnt_free_tx_bufs(priv);
567 vnt_free_int_bufs(priv);
569 usb_kill_urb(priv->interrupt_urb);
570 usb_free_urb(priv->interrupt_urb);
575 static void vnt_stop(struct ieee80211_hw *hw)
577 struct vnt_private *priv = hw->priv;
583 for (i = 0; i < MAX_KEY_TABLE; i++)
584 vnt_mac_disable_keyentry(priv, i);
587 priv->key_entry_inuse = 0;
589 if (!test_bit(DEVICE_FLAGS_UNPLUG, &priv->flags))
590 vnt_mac_shutdown(priv);
592 ieee80211_stop_queues(hw);
594 set_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
596 cancel_delayed_work_sync(&priv->run_command_work);
598 priv->cmd_running = false;
600 vnt_free_tx_bufs(priv);
601 vnt_free_rx_bufs(priv);
602 vnt_free_int_bufs(priv);
604 usb_kill_urb(priv->interrupt_urb);
605 usb_free_urb(priv->interrupt_urb);
608 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
610 struct vnt_private *priv = hw->priv;
615 case NL80211_IFTYPE_STATION:
617 case NL80211_IFTYPE_ADHOC:
618 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
620 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
623 case NL80211_IFTYPE_AP:
624 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
626 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_AP);
633 priv->op_mode = vif->type;
635 vnt_set_bss_mode(priv);
637 /* LED blink on TX */
638 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER);
643 static void vnt_remove_interface(struct ieee80211_hw *hw,
644 struct ieee80211_vif *vif)
646 struct vnt_private *priv = hw->priv;
649 case NL80211_IFTYPE_STATION:
651 case NL80211_IFTYPE_ADHOC:
652 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
653 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
654 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
656 case NL80211_IFTYPE_AP:
657 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
658 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
659 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_AP);
665 vnt_radio_power_off(priv);
667 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
670 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
673 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
675 struct vnt_private *priv = hw->priv;
676 struct ieee80211_conf *conf = &hw->conf;
678 if (changed & IEEE80211_CONF_CHANGE_PS) {
679 if (conf->flags & IEEE80211_CONF_PS)
680 vnt_enable_power_saving(priv, conf->listen_interval);
682 vnt_disable_power_saving(priv);
685 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
686 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
687 vnt_set_channel(priv, conf->chandef.chan->hw_value);
689 if (conf->chandef.chan->band == NL80211_BAND_5GHZ)
690 priv->bb_type = BB_TYPE_11A;
692 priv->bb_type = BB_TYPE_11G;
695 if (changed & IEEE80211_CONF_CHANGE_POWER) {
696 if (priv->bb_type == BB_TYPE_11B)
697 priv->current_rate = RATE_1M;
699 priv->current_rate = RATE_54M;
701 vnt_rf_setpower(priv, priv->current_rate,
702 conf->chandef.chan->hw_value);
708 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
709 struct ieee80211_vif *vif,
710 struct ieee80211_bss_conf *conf, u32 changed)
712 struct vnt_private *priv = hw->priv;
714 priv->current_aid = conf->aid;
716 if (changed & BSS_CHANGED_BSSID && conf->bssid)
717 vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid);
719 if (changed & BSS_CHANGED_BASIC_RATES) {
720 priv->basic_rates = conf->basic_rates;
722 vnt_update_top_rates(priv);
723 vnt_set_bss_mode(priv);
725 dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates);
728 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
729 if (conf->use_short_preamble) {
730 vnt_mac_enable_barker_preamble_mode(priv);
731 priv->preamble_type = true;
733 vnt_mac_disable_barker_preamble_mode(priv);
734 priv->preamble_type = false;
738 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
739 if (conf->use_cts_prot)
740 vnt_mac_enable_protect_mode(priv);
742 vnt_mac_disable_protect_mode(priv);
745 if (changed & BSS_CHANGED_ERP_SLOT) {
746 if (conf->use_short_slot)
747 priv->short_slot_time = true;
749 priv->short_slot_time = false;
751 vnt_set_short_slot_time(priv);
752 vnt_update_ifs(priv);
753 vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
754 vnt_update_pre_ed_threshold(priv, false);
757 if (changed & BSS_CHANGED_TXPOWER)
758 vnt_rf_setpower(priv, priv->current_rate,
759 conf->chandef.chan->hw_value);
761 if (changed & BSS_CHANGED_BEACON_ENABLED) {
762 dev_dbg(&priv->usb->dev,
763 "Beacon enable %d\n", conf->enable_beacon);
765 if (conf->enable_beacon) {
766 vnt_beacon_enable(priv, vif, conf);
768 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
770 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
774 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INFO) &&
775 priv->op_mode != NL80211_IFTYPE_AP) {
776 if (conf->assoc && conf->beacon_rate) {
777 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL,
780 vnt_adjust_tsf(priv, conf->beacon_rate->hw_value,
781 conf->sync_tsf, priv->current_tsf);
783 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
785 vnt_reset_next_tbtt(priv, conf->beacon_int);
787 vnt_clear_current_tsf(priv);
789 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL,
795 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
796 struct netdev_hw_addr_list *mc_list)
798 struct vnt_private *priv = hw->priv;
799 struct netdev_hw_addr *ha;
803 netdev_hw_addr_list_for_each(ha, mc_list) {
804 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
806 mc_filter |= 1ULL << (bit_nr & 0x3f);
809 priv->mc_list_count = mc_list->count;
814 static void vnt_configure(struct ieee80211_hw *hw,
815 unsigned int changed_flags,
816 unsigned int *total_flags, u64 multicast)
818 struct vnt_private *priv = hw->priv;
822 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC;
824 rc = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
825 MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
828 rx_mode = RCR_MULTICAST | RCR_BROADCAST;
830 dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode);
832 if (changed_flags & FIF_ALLMULTI) {
833 if (*total_flags & FIF_ALLMULTI) {
834 if (priv->mc_list_count > 2)
835 vnt_mac_set_filter(priv, ~0);
837 vnt_mac_set_filter(priv, multicast);
839 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
841 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
845 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
846 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
847 rx_mode &= ~RCR_BSSID;
849 rx_mode |= RCR_BSSID;
852 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode);
854 dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode);
857 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
858 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
859 struct ieee80211_key_conf *key)
861 struct vnt_private *priv = hw->priv;
865 if (vnt_set_keys(hw, sta, vif, key))
869 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
870 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
878 static void vnt_sw_scan_start(struct ieee80211_hw *hw,
879 struct ieee80211_vif *vif,
882 struct vnt_private *priv = hw->priv;
884 /* Set max sensitivity*/
885 vnt_update_pre_ed_threshold(priv, true);
888 static void vnt_sw_scan_complete(struct ieee80211_hw *hw,
889 struct ieee80211_vif *vif)
891 struct vnt_private *priv = hw->priv;
893 /* Return sensitivity to channel level*/
894 vnt_update_pre_ed_threshold(priv, false);
897 static int vnt_get_stats(struct ieee80211_hw *hw,
898 struct ieee80211_low_level_stats *stats)
900 struct vnt_private *priv = hw->priv;
902 memcpy(stats, &priv->low_stats, sizeof(*stats));
907 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
909 struct vnt_private *priv = hw->priv;
911 return priv->current_tsf;
914 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
917 struct vnt_private *priv = hw->priv;
919 vnt_update_next_tbtt(priv, tsf, vif->bss_conf.beacon_int);
922 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
924 struct vnt_private *priv = hw->priv;
926 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
928 vnt_clear_current_tsf(priv);
931 static const struct ieee80211_ops vnt_mac_ops = {
935 .add_interface = vnt_add_interface,
936 .remove_interface = vnt_remove_interface,
937 .config = vnt_config,
938 .bss_info_changed = vnt_bss_info_changed,
939 .prepare_multicast = vnt_prepare_multicast,
940 .configure_filter = vnt_configure,
941 .set_key = vnt_set_key,
942 .sw_scan_start = vnt_sw_scan_start,
943 .sw_scan_complete = vnt_sw_scan_complete,
944 .get_stats = vnt_get_stats,
945 .get_tsf = vnt_get_tsf,
946 .set_tsf = vnt_set_tsf,
947 .reset_tsf = vnt_reset_tsf,
950 int vnt_init(struct vnt_private *priv)
952 if (vnt_init_registers(priv))
955 SET_IEEE80211_PERM_ADDR(priv->hw, priv->permanent_net_addr);
957 vnt_init_bands(priv);
959 if (ieee80211_register_hw(priv->hw))
964 vnt_radio_power_off(priv);
970 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
972 struct usb_device *udev;
973 struct vnt_private *priv;
974 struct ieee80211_hw *hw;
978 udev = usb_get_dev(interface_to_usbdev(intf));
980 dev_notice(&udev->dev, "%s Ver. %s\n",
981 DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
982 dev_notice(&udev->dev,
983 "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
985 hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops);
987 dev_err(&udev->dev, "could not register ieee80211_hw\n");
997 vnt_set_options(priv);
999 spin_lock_init(&priv->lock);
1000 mutex_init(&priv->usb_lock);
1002 INIT_DELAYED_WORK(&priv->run_command_work, vnt_run_command);
1004 usb_set_intfdata(intf, priv);
1006 wiphy = priv->hw->wiphy;
1008 wiphy->frag_threshold = FRAG_THRESH_DEF;
1009 wiphy->rts_threshold = RTS_THRESH_DEF;
1010 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1011 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1013 ieee80211_hw_set(priv->hw, TIMING_BEACON_ONLY);
1014 ieee80211_hw_set(priv->hw, SIGNAL_DBM);
1015 ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS);
1016 ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS);
1017 ieee80211_hw_set(priv->hw, SUPPORTS_PS);
1018 ieee80211_hw_set(priv->hw, PS_NULLFUNC_STACK);
1020 priv->hw->max_signal = 100;
1022 SET_IEEE80211_DEV(priv->hw, &intf->dev);
1024 rc = usb_reset_device(priv->usb);
1026 dev_warn(&priv->usb->dev,
1027 "%s reset fail status=%d\n", __func__, rc);
1029 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
1030 vnt_reset_command_timer(priv);
1032 vnt_schedule_command(priv, WLAN_CMD_INIT_MAC80211);
1042 static void vt6656_disconnect(struct usb_interface *intf)
1044 struct vnt_private *priv = usb_get_intfdata(intf);
1050 ieee80211_unregister_hw(priv->hw);
1052 usb_set_intfdata(intf, NULL);
1053 usb_put_dev(interface_to_usbdev(intf));
1055 set_bit(DEVICE_FLAGS_UNPLUG, &priv->flags);
1057 ieee80211_free_hw(priv->hw);
1062 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
1067 static int vt6656_resume(struct usb_interface *intf)
1072 #endif /* CONFIG_PM */
1074 MODULE_DEVICE_TABLE(usb, vt6656_table);
1076 static struct usb_driver vt6656_driver = {
1077 .name = DEVICE_NAME,
1078 .probe = vt6656_probe,
1079 .disconnect = vt6656_disconnect,
1080 .id_table = vt6656_table,
1082 .suspend = vt6656_suspend,
1083 .resume = vt6656_resume,
1084 #endif /* CONFIG_PM */
1087 module_usb_driver(vt6656_driver);