2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: driver entry for initial, open, close, tx and rx.
29 * vt6656_probe - module initial (insmod) driver entry
30 * vnt_free_tx_bufs - free tx buffer function
31 * vnt_init_registers- initial MAC & BBP & RF internal registers.
37 #include <linux/file.h>
53 * define module options
56 /* version information */
57 #define DRIVER_AUTHOR \
58 "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
59 MODULE_AUTHOR(DRIVER_AUTHOR);
60 MODULE_LICENSE("GPL");
61 MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
63 #define RX_DESC_DEF0 64
64 static int vnt_rx_buffers = RX_DESC_DEF0;
65 module_param_named(rx_buffers, vnt_rx_buffers, int, 0644);
66 MODULE_PARM_DESC(rx_buffers, "Number of receive usb rx buffers");
68 #define TX_DESC_DEF0 64
69 static int vnt_tx_buffers = TX_DESC_DEF0;
70 module_param_named(tx_buffers, vnt_tx_buffers, int, 0644);
71 MODULE_PARM_DESC(tx_buffers, "Number of receive usb tx buffers");
73 #define RTS_THRESH_DEF 2347
74 #define FRAG_THRESH_DEF 2346
75 #define SHORT_RETRY_DEF 8
76 #define LONG_RETRY_DEF 4
78 /* BasebandType[] baseband type selected
79 0: indicate 802.11a type
80 1: indicate 802.11b type
81 2: indicate 802.11g type
84 #define BBP_TYPE_DEF 2
87 * Static vars definitions
90 static struct usb_device_id vt6656_table[] = {
91 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
95 static void vnt_set_options(struct vnt_private *priv)
97 /* Set number of TX buffers */
98 if (vnt_tx_buffers < CB_MIN_TX_DESC || vnt_tx_buffers > CB_MAX_TX_DESC)
99 priv->num_tx_context = TX_DESC_DEF0;
101 priv->num_tx_context = vnt_tx_buffers;
103 /* Set number of RX buffers */
104 if (vnt_rx_buffers < CB_MIN_RX_DESC || vnt_rx_buffers > CB_MAX_RX_DESC)
105 priv->num_rcb = RX_DESC_DEF0;
107 priv->num_rcb = vnt_rx_buffers;
109 priv->short_retry_limit = SHORT_RETRY_DEF;
110 priv->long_retry_limit = LONG_RETRY_DEF;
111 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
112 priv->bb_type = BBP_TYPE_DEF;
113 priv->packet_type = priv->bb_type;
114 priv->auto_fb_ctrl = AUTO_FB_0;
115 priv->preamble_type = 0;
116 priv->exist_sw_net_addr = false;
120 * initialization of MAC & BBP registers
122 static int vnt_init_registers(struct vnt_private *priv)
124 struct vnt_cmd_card_init *init_cmd = &priv->init_command;
125 struct vnt_rsp_card_init *init_rsp = &priv->init_response;
128 int status = STATUS_SUCCESS;
130 u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
132 dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n",
133 DEVICE_INIT_COLD, priv->packet_type);
135 if (!vnt_check_firmware_version(priv)) {
136 if (vnt_download_firmware(priv) == true) {
137 if (vnt_firmware_branch_to_sram(priv) == false) {
138 dev_dbg(&priv->usb->dev,
139 " vnt_firmware_branch_to_sram fail\n");
143 dev_dbg(&priv->usb->dev, "FIRMWAREbDownload fail\n");
148 if (!vnt_vt3184_init(priv)) {
149 dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n");
153 init_cmd->init_class = DEVICE_INIT_COLD;
154 init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr;
155 for (ii = 0; ii < 6; ii++)
156 init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii];
157 init_cmd->short_retry_limit = priv->short_retry_limit;
158 init_cmd->long_retry_limit = priv->long_retry_limit;
160 /* issue card_init command to device */
161 status = vnt_control_out(priv,
162 MESSAGE_TYPE_CARDINIT, 0, 0,
163 sizeof(struct vnt_cmd_card_init), (u8 *)init_cmd);
164 if (status != STATUS_SUCCESS) {
165 dev_dbg(&priv->usb->dev, "Issue Card init fail\n");
169 status = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
170 sizeof(struct vnt_rsp_card_init), (u8 *)init_rsp);
171 if (status != STATUS_SUCCESS) {
172 dev_dbg(&priv->usb->dev,
173 "Cardinit request in status fail!\n");
177 /* local ID for AES functions */
178 status = vnt_control_in(priv, MESSAGE_TYPE_READ,
179 MAC_REG_LOCALID, MESSAGE_REQUEST_MACREG, 1,
181 if (status != STATUS_SUCCESS)
184 /* do MACbSoftwareReset in MACvInitialize */
186 priv->top_ofdm_basic_rate = RATE_24M;
187 priv->top_cck_basic_rate = RATE_1M;
189 /* target to IF pin while programming to RF chip */
192 priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK];
193 priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG];
194 /* load power table */
195 for (ii = 0; ii < 14; ii++) {
196 priv->cck_pwr_tbl[ii] =
197 priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL];
198 if (priv->cck_pwr_tbl[ii] == 0)
199 priv->cck_pwr_tbl[ii] = priv->cck_pwr;
201 priv->ofdm_pwr_tbl[ii] =
202 priv->eeprom[ii + EEP_OFS_OFDM_PWR_TBL];
203 if (priv->ofdm_pwr_tbl[ii] == 0)
204 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_g;
208 * original zonetype is USA, but custom zonetype is Europe,
209 * then need to recover 12, 13, 14 channels with 11 channel
211 for (ii = 11; ii < 14; ii++) {
212 priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10];
213 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10];
216 priv->ofdm_pwr_a = 0x34; /* same as RFbMA2829SelectChannel */
218 /* load OFDM A power table */
219 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
220 priv->ofdm_a_pwr_tbl[ii] =
221 priv->eeprom[ii + EEP_OFS_OFDMA_PWR_TBL];
223 if (priv->ofdm_a_pwr_tbl[ii] == 0)
224 priv->ofdm_a_pwr_tbl[ii] = priv->ofdm_pwr_a;
227 antenna = priv->eeprom[EEP_OFS_ANTENNA];
229 if (antenna & EEP_ANTINV)
230 priv->tx_rx_ant_inv = true;
232 priv->tx_rx_ant_inv = false;
234 antenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
236 if (antenna == 0) /* if not set default is both */
237 antenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
239 if (antenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
240 priv->tx_antenna_mode = ANT_B;
241 priv->rx_antenna_sel = 1;
243 if (priv->tx_rx_ant_inv == true)
244 priv->rx_antenna_mode = ANT_A;
246 priv->rx_antenna_mode = ANT_B;
248 priv->rx_antenna_sel = 0;
250 if (antenna & EEP_ANTENNA_AUX) {
251 priv->tx_antenna_mode = ANT_A;
253 if (priv->tx_rx_ant_inv == true)
254 priv->rx_antenna_mode = ANT_B;
256 priv->rx_antenna_mode = ANT_A;
258 priv->tx_antenna_mode = ANT_B;
260 if (priv->tx_rx_ant_inv == true)
261 priv->rx_antenna_mode = ANT_A;
263 priv->rx_antenna_mode = ANT_B;
267 /* Set initial antenna mode */
268 vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
270 /* get Auto Fall Back type */
271 priv->auto_fb_ctrl = AUTO_FB_0;
273 /* default Auto Mode */
274 priv->bb_type = BB_TYPE_11G;
277 priv->rf_type = init_rsp->rf_type;
279 /* load vt3266 calibration parameters in EEPROM */
280 if (priv->rf_type == RF_VT3226D0) {
281 if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) &&
282 (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) {
284 calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ];
285 calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC];
286 calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ];
287 if (calib_tx_iq || calib_tx_dc || calib_rx_iq) {
288 /* CR255, enable TX/RX IQ and
289 DC compensation mode */
290 vnt_control_out_u8(priv,
291 MESSAGE_REQUEST_BBREG,
294 /* CR251, TX I/Q Imbalance Calibration */
295 vnt_control_out_u8(priv,
296 MESSAGE_REQUEST_BBREG,
299 /* CR252, TX DC-Offset Calibration */
300 vnt_control_out_u8(priv,
301 MESSAGE_REQUEST_BBREG,
304 /* CR253, RX I/Q Imbalance Calibration */
305 vnt_control_out_u8(priv,
306 MESSAGE_REQUEST_BBREG,
311 BB Calibration compensation */
312 vnt_control_out_u8(priv,
313 MESSAGE_REQUEST_BBREG,
320 /* get permanent network address */
321 memcpy(priv->permanent_net_addr, init_rsp->net_addr, 6);
322 memcpy(priv->current_net_addr, priv->permanent_net_addr, ETH_ALEN);
324 /* if exist SW network address, use it */
325 dev_dbg(&priv->usb->dev, "Network address = %pM\n",
326 priv->current_net_addr);
329 * set BB and packet type at the same time
330 * set Short Slot Time, xIFS, and RSPINF
332 if (priv->bb_type == BB_TYPE_11A)
333 priv->short_slot_time = true;
335 priv->short_slot_time = false;
337 vnt_set_short_slot_time(priv);
339 priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL];
341 if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) {
342 status = vnt_control_in(priv, MESSAGE_TYPE_READ,
343 MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG, 1, &tmp);
345 if (status != STATUS_SUCCESS)
348 if ((tmp & GPIO3_DATA) == 0)
349 vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
352 vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
356 vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
358 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
360 vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01);
362 vnt_radio_power_on(priv);
364 dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n");
369 static void vnt_free_tx_bufs(struct vnt_private *priv)
371 struct vnt_usb_send_context *tx_context;
374 for (ii = 0; ii < priv->num_tx_context; ii++) {
375 tx_context = priv->tx_context[ii];
376 /* deallocate URBs */
377 if (tx_context->urb) {
378 usb_kill_urb(tx_context->urb);
379 usb_free_urb(tx_context->urb);
386 static void vnt_free_rx_bufs(struct vnt_private *priv)
391 for (ii = 0; ii < priv->num_rcb; ii++) {
396 /* deallocate URBs */
398 usb_kill_urb(rcb->urb);
399 usb_free_urb(rcb->urb);
404 dev_kfree_skb(rcb->skb);
410 static void usb_device_reset(struct vnt_private *priv)
414 status = usb_reset_device(priv->usb);
416 dev_warn(&priv->usb->dev,
417 "usb_device_reset fail status=%d\n", status);
420 static void vnt_free_int_bufs(struct vnt_private *priv)
422 kfree(priv->int_buf.data_buf);
425 static bool vnt_alloc_bufs(struct vnt_private *priv)
427 struct vnt_usb_send_context *tx_context;
431 for (ii = 0; ii < priv->num_tx_context; ii++) {
432 tx_context = kmalloc(sizeof(struct vnt_usb_send_context),
434 if (tx_context == NULL)
437 priv->tx_context[ii] = tx_context;
438 tx_context->priv = priv;
439 tx_context->pkt_no = ii;
442 tx_context->urb = usb_alloc_urb(0, GFP_ATOMIC);
443 if (!tx_context->urb) {
444 dev_err(&priv->usb->dev, "alloc tx urb failed\n");
448 tx_context->in_use = false;
451 for (ii = 0; ii < priv->num_rcb; ii++) {
452 priv->rcb[ii] = kzalloc(sizeof(struct vnt_rcb), GFP_KERNEL);
453 if (!priv->rcb[ii]) {
454 dev_err(&priv->usb->dev,
455 "failed to allocate rcb no %d\n", ii);
464 rcb->urb = usb_alloc_urb(0, GFP_ATOMIC);
465 if (rcb->urb == NULL) {
466 dev_err(&priv->usb->dev, "Failed to alloc rx urb\n");
470 rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
471 if (rcb->skb == NULL)
477 if (vnt_submit_rx_urb(priv, rcb))
481 priv->interrupt_urb = usb_alloc_urb(0, GFP_ATOMIC);
482 if (priv->interrupt_urb == NULL) {
483 dev_err(&priv->usb->dev, "Failed to alloc int urb\n");
487 priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
488 if (priv->int_buf.data_buf == NULL) {
489 usb_free_urb(priv->interrupt_urb);
496 vnt_free_rx_bufs(priv);
499 vnt_free_tx_bufs(priv);
504 static void vnt_tx_80211(struct ieee80211_hw *hw,
505 struct ieee80211_tx_control *control, struct sk_buff *skb)
507 struct vnt_private *priv = hw->priv;
509 ieee80211_stop_queues(hw);
511 if (vnt_tx_packet(priv, skb)) {
512 ieee80211_free_txskb(hw, skb);
514 ieee80211_wake_queues(hw);
518 static int vnt_start(struct ieee80211_hw *hw)
520 struct vnt_private *priv = hw->priv;
522 priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
524 if (vnt_alloc_bufs(priv) == false) {
525 dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n");
529 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
531 if (vnt_init_registers(priv) == false) {
532 dev_dbg(&priv->usb->dev, " init register fail\n");
536 priv->int_interval = 1; /* bInterval is set to 1 */
538 vnt_int_start_interrupt(priv);
540 ieee80211_wake_queues(hw);
545 vnt_free_rx_bufs(priv);
546 vnt_free_tx_bufs(priv);
547 vnt_free_int_bufs(priv);
549 usb_kill_urb(priv->interrupt_urb);
550 usb_free_urb(priv->interrupt_urb);
555 static void vnt_stop(struct ieee80211_hw *hw)
557 struct vnt_private *priv = hw->priv;
563 for (i = 0; i < MAX_KEY_TABLE; i++)
564 vnt_mac_disable_keyentry(priv, i);
567 priv->key_entry_inuse = 0;
569 if (!test_bit(DEVICE_FLAGS_UNPLUG, &priv->flags))
570 vnt_mac_shutdown(priv);
572 ieee80211_stop_queues(hw);
574 set_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
576 cancel_delayed_work_sync(&priv->run_command_work);
578 priv->cmd_running = false;
580 vnt_free_tx_bufs(priv);
581 vnt_free_rx_bufs(priv);
582 vnt_free_int_bufs(priv);
584 usb_kill_urb(priv->interrupt_urb);
585 usb_free_urb(priv->interrupt_urb);
588 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
590 struct vnt_private *priv = hw->priv;
595 case NL80211_IFTYPE_STATION:
597 case NL80211_IFTYPE_ADHOC:
598 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
600 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
603 case NL80211_IFTYPE_AP:
604 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
606 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_AP);
613 priv->op_mode = vif->type;
615 vnt_set_bss_mode(priv);
617 /* LED blink on TX */
618 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER);
623 static void vnt_remove_interface(struct ieee80211_hw *hw,
624 struct ieee80211_vif *vif)
626 struct vnt_private *priv = hw->priv;
629 case NL80211_IFTYPE_STATION:
631 case NL80211_IFTYPE_ADHOC:
632 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
633 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
634 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
636 case NL80211_IFTYPE_AP:
637 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
638 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
639 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_AP);
645 vnt_radio_power_off(priv);
647 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
650 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
653 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
655 struct vnt_private *priv = hw->priv;
656 struct ieee80211_conf *conf = &hw->conf;
659 if (changed & IEEE80211_CONF_CHANGE_PS) {
660 if (conf->flags & IEEE80211_CONF_PS)
661 vnt_enable_power_saving(priv, conf->listen_interval);
663 vnt_disable_power_saving(priv);
666 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
667 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
668 vnt_set_channel(priv, conf->chandef.chan->hw_value);
670 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
671 bb_type = BB_TYPE_11A;
673 bb_type = BB_TYPE_11G;
675 if (priv->bb_type != bb_type) {
676 priv->bb_type = bb_type;
678 vnt_set_bss_mode(priv);
682 if (changed & IEEE80211_CONF_CHANGE_POWER) {
683 if (priv->bb_type == BB_TYPE_11B)
684 priv->current_rate = RATE_1M;
686 priv->current_rate = RATE_54M;
688 vnt_rf_setpower(priv, priv->current_rate,
689 conf->chandef.chan->hw_value);
695 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
696 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
699 struct vnt_private *priv = hw->priv;
701 priv->current_aid = conf->aid;
703 if (changed & BSS_CHANGED_BSSID)
704 vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid);
707 if (changed & BSS_CHANGED_BASIC_RATES) {
708 priv->basic_rates = conf->basic_rates;
710 vnt_update_top_rates(priv);
712 dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates);
715 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
716 if (conf->use_short_preamble) {
717 vnt_mac_enable_barker_preamble_mode(priv);
718 priv->preamble_type = true;
720 vnt_mac_disable_barker_preamble_mode(priv);
721 priv->preamble_type = false;
725 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
726 if (conf->use_cts_prot)
727 vnt_mac_enable_protect_mode(priv);
729 vnt_mac_disable_protect_mode(priv);
732 if (changed & BSS_CHANGED_ERP_SLOT) {
733 if (conf->use_short_slot)
734 priv->short_slot_time = true;
736 priv->short_slot_time = false;
738 vnt_set_short_slot_time(priv);
739 vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
740 vnt_update_pre_ed_threshold(priv, false);
743 if (changed & BSS_CHANGED_TXPOWER)
744 vnt_rf_setpower(priv, priv->current_rate,
745 conf->chandef.chan->hw_value);
747 if (changed & BSS_CHANGED_BEACON_ENABLED) {
748 dev_dbg(&priv->usb->dev,
749 "Beacon enable %d\n", conf->enable_beacon);
751 if (conf->enable_beacon) {
752 vnt_beacon_enable(priv, vif, conf);
754 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
756 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
761 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
762 struct netdev_hw_addr_list *mc_list)
764 struct vnt_private *priv = hw->priv;
765 struct netdev_hw_addr *ha;
769 netdev_hw_addr_list_for_each(ha, mc_list) {
770 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
772 mc_filter |= 1ULL << (bit_nr & 0x3f);
775 priv->mc_list_count = mc_list->count;
780 static void vnt_configure(struct ieee80211_hw *hw,
781 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
783 struct vnt_private *priv = hw->priv;
787 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_PROMISC_IN_BSS |
788 FIF_BCN_PRBRESP_PROMISC;
790 rc = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
791 MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
794 rx_mode = RCR_MULTICAST | RCR_BROADCAST;
796 dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode);
798 if (changed_flags & FIF_PROMISC_IN_BSS) {
799 /* unconditionally log net taps */
800 if (*total_flags & FIF_PROMISC_IN_BSS)
801 rx_mode |= RCR_UNICAST;
803 rx_mode &= ~RCR_UNICAST;
806 if (changed_flags & FIF_ALLMULTI) {
807 if (*total_flags & FIF_ALLMULTI) {
808 if (priv->mc_list_count > 2)
809 vnt_mac_set_filter(priv, ~0);
811 vnt_mac_set_filter(priv, multicast);
813 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
815 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
820 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
821 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
822 rx_mode &= ~RCR_BSSID;
824 rx_mode |= RCR_BSSID;
827 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode);
829 dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode);
832 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
833 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
834 struct ieee80211_key_conf *key)
836 struct vnt_private *priv = hw->priv;
840 if (vnt_set_keys(hw, sta, vif, key))
844 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
845 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
853 static void vnt_sw_scan_start(struct ieee80211_hw *hw,
854 struct ieee80211_vif *vif,
857 struct vnt_private *priv = hw->priv;
859 vnt_set_bss_mode(priv);
860 /* Set max sensitivity*/
861 vnt_update_pre_ed_threshold(priv, true);
864 static void vnt_sw_scan_complete(struct ieee80211_hw *hw,
865 struct ieee80211_vif *vif)
867 struct vnt_private *priv = hw->priv;
869 /* Return sensitivity to channel level*/
870 vnt_update_pre_ed_threshold(priv, false);
873 static int vnt_get_stats(struct ieee80211_hw *hw,
874 struct ieee80211_low_level_stats *stats)
876 struct vnt_private *priv = hw->priv;
878 memcpy(stats, &priv->low_stats, sizeof(*stats));
883 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
885 struct vnt_private *priv = hw->priv;
887 return priv->current_tsf;
890 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
893 struct vnt_private *priv = hw->priv;
895 vnt_update_next_tbtt(priv, tsf, vif->bss_conf.beacon_int);
898 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
900 struct vnt_private *priv = hw->priv;
902 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
904 vnt_clear_current_tsf(priv);
907 static const struct ieee80211_ops vnt_mac_ops = {
911 .add_interface = vnt_add_interface,
912 .remove_interface = vnt_remove_interface,
913 .config = vnt_config,
914 .bss_info_changed = vnt_bss_info_changed,
915 .prepare_multicast = vnt_prepare_multicast,
916 .configure_filter = vnt_configure,
917 .set_key = vnt_set_key,
918 .sw_scan_start = vnt_sw_scan_start,
919 .sw_scan_complete = vnt_sw_scan_complete,
920 .get_stats = vnt_get_stats,
921 .get_tsf = vnt_get_tsf,
922 .set_tsf = vnt_set_tsf,
923 .reset_tsf = vnt_reset_tsf,
926 int vnt_init(struct vnt_private *priv)
929 if (!(vnt_init_registers(priv)))
932 SET_IEEE80211_PERM_ADDR(priv->hw, priv->permanent_net_addr);
934 vnt_init_bands(priv);
936 if (ieee80211_register_hw(priv->hw))
941 vnt_radio_power_off(priv);
947 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
949 struct usb_device *udev;
950 struct vnt_private *priv;
951 struct ieee80211_hw *hw;
955 udev = usb_get_dev(interface_to_usbdev(intf));
957 dev_notice(&udev->dev, "%s Ver. %s\n",
958 DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
959 dev_notice(&udev->dev,
960 "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
962 hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops);
964 dev_err(&udev->dev, "could not register ieee80211_hw\n");
972 vnt_set_options(priv);
974 spin_lock_init(&priv->lock);
975 mutex_init(&priv->usb_lock);
977 INIT_DELAYED_WORK(&priv->run_command_work, vnt_run_command);
979 usb_set_intfdata(intf, priv);
981 wiphy = priv->hw->wiphy;
983 wiphy->frag_threshold = FRAG_THRESH_DEF;
984 wiphy->rts_threshold = RTS_THRESH_DEF;
985 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
986 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
988 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
989 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
990 IEEE80211_HW_SIGNAL_DBM |
991 IEEE80211_HW_TIMING_BEACON_ONLY;
993 priv->hw->max_signal = 100;
995 SET_IEEE80211_DEV(priv->hw, &intf->dev);
997 usb_device_reset(priv);
999 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
1000 vnt_reset_command_timer(priv);
1002 vnt_schedule_command(priv, WLAN_CMD_INIT_MAC80211);
1012 static void vt6656_disconnect(struct usb_interface *intf)
1014 struct vnt_private *priv = usb_get_intfdata(intf);
1020 ieee80211_unregister_hw(priv->hw);
1022 usb_set_intfdata(intf, NULL);
1023 usb_put_dev(interface_to_usbdev(intf));
1025 set_bit(DEVICE_FLAGS_UNPLUG, &priv->flags);
1027 ieee80211_free_hw(priv->hw);
1032 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
1037 static int vt6656_resume(struct usb_interface *intf)
1042 #endif /* CONFIG_PM */
1044 MODULE_DEVICE_TABLE(usb, vt6656_table);
1046 static struct usb_driver vt6656_driver = {
1047 .name = DEVICE_NAME,
1048 .probe = vt6656_probe,
1049 .disconnect = vt6656_disconnect,
1050 .id_table = vt6656_table,
1052 .suspend = vt6656_suspend,
1053 .resume = vt6656_resume,
1054 #endif /* CONFIG_PM */
1057 module_usb_driver(vt6656_driver);