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>
40 * define module options
43 /* version information */
44 #define DRIVER_AUTHOR \
45 "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
46 MODULE_AUTHOR(DRIVER_AUTHOR);
47 MODULE_LICENSE("GPL");
48 MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
50 #define RX_DESC_DEF0 64
51 static int vnt_rx_buffers = RX_DESC_DEF0;
52 module_param_named(rx_buffers, vnt_rx_buffers, int, 0644);
53 MODULE_PARM_DESC(rx_buffers, "Number of receive usb rx buffers");
55 #define TX_DESC_DEF0 64
56 static int vnt_tx_buffers = TX_DESC_DEF0;
57 module_param_named(tx_buffers, vnt_tx_buffers, int, 0644);
58 MODULE_PARM_DESC(tx_buffers, "Number of receive usb tx buffers");
60 #define RTS_THRESH_DEF 2347
61 #define FRAG_THRESH_DEF 2346
63 /* BasebandType[] baseband type selected
64 * 0: indicate 802.11a type
65 * 1: indicate 802.11b type
66 * 2: indicate 802.11g type
69 #define BBP_TYPE_DEF 2
72 * Static vars definitions
75 static const struct usb_device_id vt6656_table[] = {
76 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
80 static void vnt_set_options(struct vnt_private *priv)
82 /* Set number of TX buffers */
83 if (vnt_tx_buffers < CB_MIN_TX_DESC || vnt_tx_buffers > CB_MAX_TX_DESC)
84 priv->num_tx_context = TX_DESC_DEF0;
86 priv->num_tx_context = vnt_tx_buffers;
88 /* Set number of RX buffers */
89 if (vnt_rx_buffers < CB_MIN_RX_DESC || vnt_rx_buffers > CB_MAX_RX_DESC)
90 priv->num_rcb = RX_DESC_DEF0;
92 priv->num_rcb = vnt_rx_buffers;
94 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
95 priv->bb_type = BBP_TYPE_DEF;
96 priv->packet_type = priv->bb_type;
97 priv->preamble_type = PREAMBLE_LONG;
98 priv->exist_sw_net_addr = false;
101 static int vnt_download_firmware(struct vnt_private *priv)
103 struct device *dev = &priv->usb->dev;
104 const struct firmware *fw;
109 dev_dbg(dev, "---->Download firmware\n");
111 ret = request_firmware(&fw, FIRMWARE_NAME, dev);
113 dev_err(dev, "firmware file %s request failed (%d)\n",
118 for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
119 length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
121 ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length,
126 dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
130 release_firmware(fw);
135 static int vnt_firmware_branch_to_sram(struct vnt_private *priv)
137 dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
139 return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL);
142 static int vnt_check_firmware_version(struct vnt_private *priv)
146 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
147 MESSAGE_REQUEST_VERSION, 2,
148 (u8 *)&priv->firmware_version);
150 dev_dbg(&priv->usb->dev,
151 "Could not get firmware version: %d.\n", ret);
155 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
156 priv->firmware_version);
158 if (priv->firmware_version == 0xFFFF) {
159 dev_dbg(&priv->usb->dev, "In Loader.\n");
164 if (priv->firmware_version < FIRMWARE_VERSION) {
165 /* branch to loader for download new firmware */
166 ret = vnt_firmware_branch_to_sram(priv);
168 dev_dbg(&priv->usb->dev,
169 "Could not branch to SRAM: %d.\n", ret);
180 * initialization of MAC & BBP registers
182 static int vnt_init_registers(struct vnt_private *priv)
185 struct vnt_cmd_card_init *init_cmd = &priv->init_command;
186 struct vnt_rsp_card_init *init_rsp = &priv->init_response;
190 u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
192 dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n",
193 DEVICE_INIT_COLD, priv->packet_type);
195 ret = vnt_check_firmware_version(priv);
197 ret = vnt_download_firmware(priv);
199 dev_dbg(&priv->usb->dev,
200 "Could not download firmware: %d.\n", ret);
204 ret = vnt_firmware_branch_to_sram(priv);
206 dev_dbg(&priv->usb->dev,
207 "Could not branch to SRAM: %d.\n", ret);
212 ret = vnt_vt3184_init(priv);
214 dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n");
218 init_cmd->init_class = DEVICE_INIT_COLD;
219 init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr;
220 for (ii = 0; ii < ARRAY_SIZE(init_cmd->sw_net_addr); ii++)
221 init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii];
222 init_cmd->short_retry_limit = priv->hw->wiphy->retry_short;
223 init_cmd->long_retry_limit = priv->hw->wiphy->retry_long;
225 /* issue card_init command to device */
226 ret = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0,
227 sizeof(struct vnt_cmd_card_init),
230 dev_dbg(&priv->usb->dev, "Issue Card init fail\n");
234 ret = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
235 sizeof(struct vnt_rsp_card_init),
238 dev_dbg(&priv->usb->dev, "Cardinit request in status fail!\n");
242 /* local ID for AES functions */
243 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID,
244 MESSAGE_REQUEST_MACREG, 1, &priv->local_id);
248 /* do MACbSoftwareReset in MACvInitialize */
250 priv->top_ofdm_basic_rate = RATE_24M;
251 priv->top_cck_basic_rate = RATE_1M;
253 /* target to IF pin while programming to RF chip */
256 priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK];
257 priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG];
258 /* load power table */
259 for (ii = 0; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) {
260 priv->cck_pwr_tbl[ii] =
261 priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL];
262 if (priv->cck_pwr_tbl[ii] == 0)
263 priv->cck_pwr_tbl[ii] = priv->cck_pwr;
265 priv->ofdm_pwr_tbl[ii] =
266 priv->eeprom[ii + EEP_OFS_OFDM_PWR_TBL];
267 if (priv->ofdm_pwr_tbl[ii] == 0)
268 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_g;
272 * original zonetype is USA, but custom zonetype is Europe,
273 * then need to recover 12, 13, 14 channels with 11 channel
275 for (ii = 11; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) {
276 priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10];
277 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10];
280 priv->ofdm_pwr_a = 0x34; /* same as RFbMA2829SelectChannel */
282 /* load OFDM A power table */
283 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
284 priv->ofdm_a_pwr_tbl[ii] =
285 priv->eeprom[ii + EEP_OFS_OFDMA_PWR_TBL];
287 if (priv->ofdm_a_pwr_tbl[ii] == 0)
288 priv->ofdm_a_pwr_tbl[ii] = priv->ofdm_pwr_a;
291 antenna = priv->eeprom[EEP_OFS_ANTENNA];
293 if (antenna & EEP_ANTINV)
294 priv->tx_rx_ant_inv = true;
296 priv->tx_rx_ant_inv = false;
298 antenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
300 if (antenna == 0) /* if not set default is both */
301 antenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
303 if (antenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
304 priv->tx_antenna_mode = ANT_B;
305 priv->rx_antenna_sel = 1;
307 if (priv->tx_rx_ant_inv)
308 priv->rx_antenna_mode = ANT_A;
310 priv->rx_antenna_mode = ANT_B;
312 priv->rx_antenna_sel = 0;
314 if (antenna & EEP_ANTENNA_AUX) {
315 priv->tx_antenna_mode = ANT_A;
317 if (priv->tx_rx_ant_inv)
318 priv->rx_antenna_mode = ANT_B;
320 priv->rx_antenna_mode = ANT_A;
322 priv->tx_antenna_mode = ANT_B;
324 if (priv->tx_rx_ant_inv)
325 priv->rx_antenna_mode = ANT_A;
327 priv->rx_antenna_mode = ANT_B;
331 /* Set initial antenna mode */
332 ret = vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
336 /* default Auto Mode */
337 priv->bb_type = BB_TYPE_11G;
340 priv->rf_type = init_rsp->rf_type;
342 /* load vt3266 calibration parameters in EEPROM */
343 if (priv->rf_type == RF_VT3226D0) {
344 if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) &&
345 (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) {
346 calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ];
347 calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC];
348 calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ];
349 if (calib_tx_iq || calib_tx_dc || calib_rx_iq) {
350 /* CR255, enable TX/RX IQ and
351 * DC compensation mode
353 ret = vnt_control_out_u8(priv,
354 MESSAGE_REQUEST_BBREG,
359 /* CR251, TX I/Q Imbalance Calibration */
360 ret = vnt_control_out_u8(priv,
361 MESSAGE_REQUEST_BBREG,
366 /* CR252, TX DC-Offset Calibration */
367 ret = vnt_control_out_u8(priv,
368 MESSAGE_REQUEST_BBREG,
373 /* CR253, RX I/Q Imbalance Calibration */
374 ret = vnt_control_out_u8(priv,
375 MESSAGE_REQUEST_BBREG,
381 * BB Calibration compensation
383 ret = vnt_control_out_u8(priv,
384 MESSAGE_REQUEST_BBREG,
392 /* get permanent network address */
393 memcpy(priv->permanent_net_addr, init_rsp->net_addr, 6);
394 ether_addr_copy(priv->current_net_addr, priv->permanent_net_addr);
396 /* if exist SW network address, use it */
397 dev_dbg(&priv->usb->dev, "Network address = %pM\n",
398 priv->current_net_addr);
400 priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL];
402 if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) {
403 ret = vnt_control_in(priv, MESSAGE_TYPE_READ,
404 MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG,
409 if ((tmp & GPIO3_DATA) == 0) {
410 ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
413 ret = vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
421 ret = vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
425 ret = vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
429 ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, BIT(0));
433 ret = vnt_radio_power_on(priv);
437 dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n");
443 static void vnt_free_tx_bufs(struct vnt_private *priv)
445 struct vnt_usb_send_context *tx_context;
448 usb_kill_anchored_urbs(&priv->tx_submitted);
450 for (ii = 0; ii < priv->num_tx_context; ii++) {
451 tx_context = priv->tx_context[ii];
459 static void vnt_free_rx_bufs(struct vnt_private *priv)
464 for (ii = 0; ii < priv->num_rcb; ii++) {
469 /* deallocate URBs */
471 usb_kill_urb(rcb->urb);
472 usb_free_urb(rcb->urb);
477 dev_kfree_skb(rcb->skb);
483 static void vnt_free_int_bufs(struct vnt_private *priv)
485 kfree(priv->int_buf.data_buf);
488 static int vnt_alloc_bufs(struct vnt_private *priv)
491 struct vnt_usb_send_context *tx_context;
495 init_usb_anchor(&priv->tx_submitted);
497 for (ii = 0; ii < priv->num_tx_context; ii++) {
498 tx_context = kmalloc(sizeof(*tx_context), GFP_KERNEL);
504 priv->tx_context[ii] = tx_context;
505 tx_context->priv = priv;
506 tx_context->pkt_no = ii;
507 tx_context->in_use = false;
510 for (ii = 0; ii < priv->num_rcb; ii++) {
511 priv->rcb[ii] = kzalloc(sizeof(*priv->rcb[ii]), GFP_KERNEL);
512 if (!priv->rcb[ii]) {
522 rcb->urb = usb_alloc_urb(0, GFP_KERNEL);
528 rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
534 ret = vnt_submit_rx_urb(priv, rcb);
539 priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL);
540 if (!priv->interrupt_urb) {
545 priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
546 if (!priv->int_buf.data_buf) {
554 usb_free_urb(priv->interrupt_urb);
556 vnt_free_rx_bufs(priv);
558 vnt_free_tx_bufs(priv);
562 static void vnt_tx_80211(struct ieee80211_hw *hw,
563 struct ieee80211_tx_control *control,
566 struct vnt_private *priv = hw->priv;
568 if (vnt_tx_packet(priv, skb))
569 ieee80211_free_txskb(hw, skb);
572 static int vnt_start(struct ieee80211_hw *hw)
575 struct vnt_private *priv = hw->priv;
577 priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
579 ret = vnt_alloc_bufs(priv);
581 dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n");
585 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
587 ret = vnt_init_registers(priv);
589 dev_dbg(&priv->usb->dev, " init register fail\n");
593 ret = vnt_key_init_table(priv);
597 priv->int_interval = 1; /* bInterval is set to 1 */
599 ret = vnt_start_interrupt_urb(priv);
603 ieee80211_wake_queues(hw);
608 vnt_free_rx_bufs(priv);
609 vnt_free_tx_bufs(priv);
610 vnt_free_int_bufs(priv);
612 usb_kill_urb(priv->interrupt_urb);
613 usb_free_urb(priv->interrupt_urb);
618 static void vnt_stop(struct ieee80211_hw *hw)
620 struct vnt_private *priv = hw->priv;
626 for (i = 0; i < MAX_KEY_TABLE; i++)
627 vnt_mac_disable_keyentry(priv, i);
630 priv->key_entry_inuse = 0;
632 if (!test_bit(DEVICE_FLAGS_UNPLUG, &priv->flags))
633 vnt_mac_shutdown(priv);
635 ieee80211_stop_queues(hw);
637 set_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
639 cancel_delayed_work_sync(&priv->run_command_work);
641 priv->cmd_running = false;
643 vnt_free_tx_bufs(priv);
644 vnt_free_rx_bufs(priv);
645 vnt_free_int_bufs(priv);
647 usb_kill_urb(priv->interrupt_urb);
648 usb_free_urb(priv->interrupt_urb);
651 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
653 struct vnt_private *priv = hw->priv;
658 case NL80211_IFTYPE_STATION:
660 case NL80211_IFTYPE_ADHOC:
661 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
663 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
666 case NL80211_IFTYPE_AP:
667 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
669 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_AP);
676 priv->op_mode = vif->type;
678 /* LED blink on TX */
679 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER);
684 static void vnt_remove_interface(struct ieee80211_hw *hw,
685 struct ieee80211_vif *vif)
687 struct vnt_private *priv = hw->priv;
690 case NL80211_IFTYPE_STATION:
692 case NL80211_IFTYPE_ADHOC:
693 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
694 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
695 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
697 case NL80211_IFTYPE_AP:
698 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
699 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
700 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_AP);
706 vnt_radio_power_off(priv);
708 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
711 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
714 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
716 struct vnt_private *priv = hw->priv;
717 struct ieee80211_conf *conf = &hw->conf;
719 if (changed & IEEE80211_CONF_CHANGE_PS) {
720 if (conf->flags & IEEE80211_CONF_PS)
721 vnt_enable_power_saving(priv, conf->listen_interval);
723 vnt_disable_power_saving(priv);
726 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
727 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
728 vnt_set_channel(priv, conf->chandef.chan->hw_value);
730 if (conf->chandef.chan->band == NL80211_BAND_5GHZ)
731 priv->bb_type = BB_TYPE_11A;
733 priv->bb_type = BB_TYPE_11G;
736 if (changed & IEEE80211_CONF_CHANGE_POWER)
737 vnt_rf_setpower(priv, conf->chandef.chan);
739 if (conf->flags & (IEEE80211_CONF_OFFCHANNEL | IEEE80211_CONF_IDLE))
740 /* Set max sensitivity*/
741 vnt_update_pre_ed_threshold(priv, true);
743 vnt_update_pre_ed_threshold(priv, false);
748 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
749 struct ieee80211_vif *vif,
750 struct ieee80211_bss_conf *conf, u32 changed)
752 struct vnt_private *priv = hw->priv;
754 priv->current_aid = conf->aid;
756 if (changed & BSS_CHANGED_BSSID && conf->bssid)
757 vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid);
759 if (changed & BSS_CHANGED_BASIC_RATES) {
760 priv->basic_rates = conf->basic_rates;
762 vnt_update_top_rates(priv);
764 dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates);
767 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
768 if (conf->use_short_preamble) {
769 vnt_mac_enable_barker_preamble_mode(priv);
770 priv->preamble_type = PREAMBLE_SHORT;
772 vnt_mac_disable_barker_preamble_mode(priv);
773 priv->preamble_type = PREAMBLE_LONG;
777 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
778 if (conf->use_cts_prot)
779 vnt_mac_enable_protect_mode(priv);
781 vnt_mac_disable_protect_mode(priv);
784 if (changed & BSS_CHANGED_ERP_SLOT) {
785 if (conf->use_short_slot)
786 priv->short_slot_time = true;
788 priv->short_slot_time = false;
790 vnt_set_short_slot_time(priv);
791 vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
794 if (changed & (BSS_CHANGED_BASIC_RATES | BSS_CHANGED_ERP_PREAMBLE |
795 BSS_CHANGED_ERP_SLOT))
796 vnt_set_bss_mode(priv);
798 if (changed & (BSS_CHANGED_TXPOWER | BSS_CHANGED_BANDWIDTH))
799 vnt_rf_setpower(priv, conf->chandef.chan);
801 if (changed & BSS_CHANGED_BEACON_ENABLED) {
802 dev_dbg(&priv->usb->dev,
803 "Beacon enable %d\n", conf->enable_beacon);
805 if (conf->enable_beacon) {
806 vnt_beacon_enable(priv, vif, conf);
808 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
810 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
814 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INFO) &&
815 priv->op_mode != NL80211_IFTYPE_AP) {
816 if (conf->assoc && conf->beacon_rate) {
817 u16 ps_beacon_int = conf->beacon_int;
819 if (conf->dtim_period)
820 ps_beacon_int *= conf->dtim_period;
821 else if (hw->conf.listen_interval)
822 ps_beacon_int *= hw->conf.listen_interval;
824 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL,
827 vnt_mac_set_beacon_interval(priv, ps_beacon_int);
829 vnt_reset_next_tbtt(priv, conf->beacon_int);
831 vnt_adjust_tsf(priv, conf->beacon_rate->hw_value,
832 conf->sync_tsf, priv->current_tsf);
834 vnt_update_next_tbtt(priv,
835 conf->sync_tsf, ps_beacon_int);
837 vnt_clear_current_tsf(priv);
839 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL,
845 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
846 struct netdev_hw_addr_list *mc_list)
848 struct vnt_private *priv = hw->priv;
849 struct netdev_hw_addr *ha;
853 netdev_hw_addr_list_for_each(ha, mc_list) {
854 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
855 mc_filter |= BIT_ULL(bit_nr);
858 priv->mc_list_count = mc_list->count;
863 static void vnt_configure(struct ieee80211_hw *hw,
864 unsigned int changed_flags,
865 unsigned int *total_flags, u64 multicast)
867 struct vnt_private *priv = hw->priv;
870 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC;
872 vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
873 MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
875 dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode);
877 if (changed_flags & FIF_ALLMULTI) {
878 if (*total_flags & FIF_ALLMULTI) {
879 if (priv->mc_list_count > 2)
880 vnt_mac_set_filter(priv, ~0);
882 vnt_mac_set_filter(priv, multicast);
884 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
886 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
890 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
891 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
892 rx_mode &= ~RCR_BSSID;
894 rx_mode |= RCR_BSSID;
897 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode);
899 dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode);
902 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
903 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
904 struct ieee80211_key_conf *key)
906 struct vnt_private *priv = hw->priv;
910 return vnt_set_keys(hw, sta, vif, key);
912 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse)) {
913 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
915 vnt_mac_disable_keyentry(priv, key->hw_key_idx);
926 static int vnt_get_stats(struct ieee80211_hw *hw,
927 struct ieee80211_low_level_stats *stats)
929 struct vnt_private *priv = hw->priv;
931 memcpy(stats, &priv->low_stats, sizeof(*stats));
936 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
938 struct vnt_private *priv = hw->priv;
940 return priv->current_tsf;
943 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
946 struct vnt_private *priv = hw->priv;
948 vnt_update_next_tbtt(priv, tsf, vif->bss_conf.beacon_int);
951 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
953 struct vnt_private *priv = hw->priv;
955 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
957 vnt_clear_current_tsf(priv);
960 static const struct ieee80211_ops vnt_mac_ops = {
964 .add_interface = vnt_add_interface,
965 .remove_interface = vnt_remove_interface,
966 .config = vnt_config,
967 .bss_info_changed = vnt_bss_info_changed,
968 .prepare_multicast = vnt_prepare_multicast,
969 .configure_filter = vnt_configure,
970 .set_key = vnt_set_key,
971 .get_stats = vnt_get_stats,
972 .get_tsf = vnt_get_tsf,
973 .set_tsf = vnt_set_tsf,
974 .reset_tsf = vnt_reset_tsf,
977 int vnt_init(struct vnt_private *priv)
979 if (vnt_init_registers(priv))
982 SET_IEEE80211_PERM_ADDR(priv->hw, priv->permanent_net_addr);
984 vnt_init_bands(priv);
986 if (ieee80211_register_hw(priv->hw))
991 vnt_radio_power_off(priv);
997 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
999 struct usb_device *udev;
1000 struct vnt_private *priv;
1001 struct ieee80211_hw *hw;
1002 struct wiphy *wiphy;
1005 udev = usb_get_dev(interface_to_usbdev(intf));
1007 dev_notice(&udev->dev, "%s Ver. %s\n",
1008 DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1009 dev_notice(&udev->dev,
1010 "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
1012 hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops);
1014 dev_err(&udev->dev, "could not register ieee80211_hw\n");
1024 vnt_set_options(priv);
1026 spin_lock_init(&priv->lock);
1027 mutex_init(&priv->usb_lock);
1029 INIT_DELAYED_WORK(&priv->run_command_work, vnt_run_command);
1031 usb_set_intfdata(intf, priv);
1033 wiphy = priv->hw->wiphy;
1035 wiphy->frag_threshold = FRAG_THRESH_DEF;
1036 wiphy->rts_threshold = RTS_THRESH_DEF;
1037 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1038 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1040 ieee80211_hw_set(priv->hw, TIMING_BEACON_ONLY);
1041 ieee80211_hw_set(priv->hw, SIGNAL_DBM);
1042 ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS);
1043 ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS);
1044 ieee80211_hw_set(priv->hw, SUPPORTS_PS);
1045 ieee80211_hw_set(priv->hw, PS_NULLFUNC_STACK);
1047 priv->hw->extra_tx_headroom =
1048 sizeof(struct vnt_tx_buffer) + sizeof(struct vnt_tx_usb_header);
1049 priv->hw->max_signal = 100;
1051 SET_IEEE80211_DEV(priv->hw, &intf->dev);
1053 rc = usb_reset_device(priv->usb);
1055 dev_warn(&priv->usb->dev,
1056 "%s reset fail status=%d\n", __func__, rc);
1058 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
1059 vnt_reset_command_timer(priv);
1061 vnt_schedule_command(priv, WLAN_CMD_INIT_MAC80211);
1071 static void vt6656_disconnect(struct usb_interface *intf)
1073 struct vnt_private *priv = usb_get_intfdata(intf);
1079 ieee80211_unregister_hw(priv->hw);
1081 usb_set_intfdata(intf, NULL);
1082 usb_put_dev(interface_to_usbdev(intf));
1084 set_bit(DEVICE_FLAGS_UNPLUG, &priv->flags);
1086 ieee80211_free_hw(priv->hw);
1091 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
1096 static int vt6656_resume(struct usb_interface *intf)
1101 #endif /* CONFIG_PM */
1103 MODULE_DEVICE_TABLE(usb, vt6656_table);
1105 static struct usb_driver vt6656_driver = {
1106 .name = DEVICE_NAME,
1107 .probe = vt6656_probe,
1108 .disconnect = vt6656_disconnect,
1109 .id_table = vt6656_table,
1111 .suspend = vt6656_suspend,
1112 .resume = vt6656_resume,
1113 #endif /* CONFIG_PM */
1116 module_usb_driver(vt6656_driver);
1118 MODULE_FIRMWARE(FIRMWARE_NAME);