1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
6 * Purpose: driver entry for initial, open, close, tx and rx.
14 * vt6656_probe - module initial (insmod) driver entry
15 * vnt_free_tx_bufs - free tx buffer function
16 * vnt_init_registers- initial MAC & BBP & RF internal registers.
22 #include <linux/bits.h>
23 #include <linux/etherdevice.h>
24 #include <linux/file.h>
25 #include <linux/kernel.h>
38 * define module options
41 /* version information */
42 #define DRIVER_AUTHOR \
43 "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
44 MODULE_AUTHOR(DRIVER_AUTHOR);
45 MODULE_LICENSE("GPL");
46 MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
48 #define RX_DESC_DEF0 64
49 static int vnt_rx_buffers = RX_DESC_DEF0;
50 module_param_named(rx_buffers, vnt_rx_buffers, int, 0644);
51 MODULE_PARM_DESC(rx_buffers, "Number of receive usb rx buffers");
53 #define TX_DESC_DEF0 64
54 static int vnt_tx_buffers = TX_DESC_DEF0;
55 module_param_named(tx_buffers, vnt_tx_buffers, int, 0644);
56 MODULE_PARM_DESC(tx_buffers, "Number of receive usb tx buffers");
58 #define RTS_THRESH_DEF 2347
59 #define FRAG_THRESH_DEF 2346
61 /* BasebandType[] baseband type selected
62 * 0: indicate 802.11a type
63 * 1: indicate 802.11b type
64 * 2: indicate 802.11g type
67 #define BBP_TYPE_DEF 2
70 * Static vars definitions
73 static const struct usb_device_id vt6656_table[] = {
74 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
78 static void vnt_set_options(struct vnt_private *priv)
80 /* Set number of TX buffers */
81 if (vnt_tx_buffers < CB_MIN_TX_DESC || vnt_tx_buffers > CB_MAX_TX_DESC)
82 priv->num_tx_context = TX_DESC_DEF0;
84 priv->num_tx_context = vnt_tx_buffers;
86 /* Set number of RX buffers */
87 if (vnt_rx_buffers < CB_MIN_RX_DESC || vnt_rx_buffers > CB_MAX_RX_DESC)
88 priv->num_rcb = RX_DESC_DEF0;
90 priv->num_rcb = vnt_rx_buffers;
92 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
93 priv->bb_type = BBP_TYPE_DEF;
94 priv->packet_type = priv->bb_type;
95 priv->preamble_type = PREAMBLE_LONG;
96 priv->exist_sw_net_addr = false;
99 static int vnt_download_firmware(struct vnt_private *priv)
101 struct device *dev = &priv->usb->dev;
102 const struct firmware *fw;
107 dev_dbg(dev, "---->Download firmware\n");
109 ret = request_firmware(&fw, FIRMWARE_NAME, dev);
111 dev_err(dev, "firmware file %s request failed (%d)\n",
116 for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
117 length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
119 ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length,
124 dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
128 release_firmware(fw);
133 static int vnt_firmware_branch_to_sram(struct vnt_private *priv)
135 dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
137 return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL);
140 static int vnt_check_firmware_version(struct vnt_private *priv)
144 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
145 MESSAGE_REQUEST_VERSION, 2,
146 (u8 *)&priv->firmware_version);
148 dev_dbg(&priv->usb->dev,
149 "Could not get firmware version: %d.\n", ret);
153 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
154 priv->firmware_version);
156 if (priv->firmware_version == 0xFFFF) {
157 dev_dbg(&priv->usb->dev, "In Loader.\n");
162 if (priv->firmware_version < FIRMWARE_VERSION) {
163 /* branch to loader for download new firmware */
164 ret = vnt_firmware_branch_to_sram(priv);
166 dev_dbg(&priv->usb->dev,
167 "Could not branch to SRAM: %d.\n", ret);
178 * initialization of MAC & BBP registers
180 static int vnt_init_registers(struct vnt_private *priv)
183 struct vnt_cmd_card_init *init_cmd = &priv->init_command;
184 struct vnt_rsp_card_init *init_rsp = &priv->init_response;
188 u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
190 dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n",
191 DEVICE_INIT_COLD, priv->packet_type);
193 ret = vnt_check_firmware_version(priv);
195 ret = vnt_download_firmware(priv);
197 dev_dbg(&priv->usb->dev,
198 "Could not download firmware: %d.\n", ret);
202 ret = vnt_firmware_branch_to_sram(priv);
204 dev_dbg(&priv->usb->dev,
205 "Could not branch to SRAM: %d.\n", ret);
210 ret = vnt_vt3184_init(priv);
212 dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n");
216 init_cmd->init_class = DEVICE_INIT_COLD;
217 init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr;
218 for (ii = 0; ii < ARRAY_SIZE(init_cmd->sw_net_addr); ii++)
219 init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii];
220 init_cmd->short_retry_limit = priv->hw->wiphy->retry_short;
221 init_cmd->long_retry_limit = priv->hw->wiphy->retry_long;
223 /* issue card_init command to device */
224 ret = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0,
225 sizeof(struct vnt_cmd_card_init),
228 dev_dbg(&priv->usb->dev, "Issue Card init fail\n");
232 ret = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
233 sizeof(struct vnt_rsp_card_init),
236 dev_dbg(&priv->usb->dev, "Cardinit request in status fail!\n");
240 /* local ID for AES functions */
241 ret = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID,
242 MESSAGE_REQUEST_MACREG, 1, &priv->local_id);
246 /* do MACbSoftwareReset in MACvInitialize */
248 priv->top_ofdm_basic_rate = RATE_24M;
249 priv->top_cck_basic_rate = RATE_1M;
251 /* target to IF pin while programming to RF chip */
254 priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK];
255 priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG];
256 /* load power table */
257 for (ii = 0; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) {
258 priv->cck_pwr_tbl[ii] =
259 priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL];
260 if (priv->cck_pwr_tbl[ii] == 0)
261 priv->cck_pwr_tbl[ii] = priv->cck_pwr;
263 priv->ofdm_pwr_tbl[ii] =
264 priv->eeprom[ii + EEP_OFS_OFDM_PWR_TBL];
265 if (priv->ofdm_pwr_tbl[ii] == 0)
266 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_g;
270 * original zonetype is USA, but custom zonetype is Europe,
271 * then need to recover 12, 13, 14 channels with 11 channel
273 for (ii = 11; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) {
274 priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10];
275 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10];
278 priv->ofdm_pwr_a = 0x34; /* same as RFbMA2829SelectChannel */
280 /* load OFDM A power table */
281 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
282 priv->ofdm_a_pwr_tbl[ii] =
283 priv->eeprom[ii + EEP_OFS_OFDMA_PWR_TBL];
285 if (priv->ofdm_a_pwr_tbl[ii] == 0)
286 priv->ofdm_a_pwr_tbl[ii] = priv->ofdm_pwr_a;
289 antenna = priv->eeprom[EEP_OFS_ANTENNA];
291 if (antenna & EEP_ANTINV)
292 priv->tx_rx_ant_inv = true;
294 priv->tx_rx_ant_inv = false;
296 antenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
298 if (antenna == 0) /* if not set default is both */
299 antenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
301 if (antenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
302 priv->tx_antenna_mode = ANT_B;
303 priv->rx_antenna_sel = 1;
305 if (priv->tx_rx_ant_inv)
306 priv->rx_antenna_mode = ANT_A;
308 priv->rx_antenna_mode = ANT_B;
310 priv->rx_antenna_sel = 0;
312 if (antenna & EEP_ANTENNA_AUX) {
313 priv->tx_antenna_mode = ANT_A;
315 if (priv->tx_rx_ant_inv)
316 priv->rx_antenna_mode = ANT_B;
318 priv->rx_antenna_mode = ANT_A;
320 priv->tx_antenna_mode = ANT_B;
322 if (priv->tx_rx_ant_inv)
323 priv->rx_antenna_mode = ANT_A;
325 priv->rx_antenna_mode = ANT_B;
329 /* Set initial antenna mode */
330 ret = vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
334 /* default Auto Mode */
335 priv->bb_type = BB_TYPE_11G;
338 priv->rf_type = init_rsp->rf_type;
340 /* load vt3266 calibration parameters in EEPROM */
341 if (priv->rf_type == RF_VT3226D0) {
342 if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) &&
343 (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) {
344 calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ];
345 calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC];
346 calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ];
347 if (calib_tx_iq || calib_tx_dc || calib_rx_iq) {
348 /* CR255, enable TX/RX IQ and
349 * DC compensation mode
351 ret = vnt_control_out_u8(priv,
352 MESSAGE_REQUEST_BBREG,
357 /* CR251, TX I/Q Imbalance Calibration */
358 ret = vnt_control_out_u8(priv,
359 MESSAGE_REQUEST_BBREG,
364 /* CR252, TX DC-Offset Calibration */
365 ret = vnt_control_out_u8(priv,
366 MESSAGE_REQUEST_BBREG,
371 /* CR253, RX I/Q Imbalance Calibration */
372 ret = vnt_control_out_u8(priv,
373 MESSAGE_REQUEST_BBREG,
379 * BB Calibration compensation
381 ret = vnt_control_out_u8(priv,
382 MESSAGE_REQUEST_BBREG,
390 /* get permanent network address */
391 memcpy(priv->permanent_net_addr, init_rsp->net_addr, 6);
392 ether_addr_copy(priv->current_net_addr, priv->permanent_net_addr);
394 /* if exist SW network address, use it */
395 dev_dbg(&priv->usb->dev, "Network address = %pM\n",
396 priv->current_net_addr);
398 priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL];
400 if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) {
401 ret = vnt_control_in(priv, MESSAGE_TYPE_READ,
402 MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG,
407 if ((tmp & GPIO3_DATA) == 0) {
408 ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
411 ret = vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
419 ret = vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
423 ret = vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
427 ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, BIT(0));
431 ret = vnt_radio_power_on(priv);
435 dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n");
441 static void vnt_free_tx_bufs(struct vnt_private *priv)
443 struct vnt_usb_send_context *tx_context;
446 usb_kill_anchored_urbs(&priv->tx_submitted);
448 for (ii = 0; ii < priv->num_tx_context; ii++) {
449 tx_context = priv->tx_context[ii];
457 static void vnt_free_rx_bufs(struct vnt_private *priv)
462 for (ii = 0; ii < priv->num_rcb; ii++) {
467 /* deallocate URBs */
469 usb_kill_urb(rcb->urb);
470 usb_free_urb(rcb->urb);
475 dev_kfree_skb(rcb->skb);
481 static void vnt_free_int_bufs(struct vnt_private *priv)
483 kfree(priv->int_buf.data_buf);
486 static int vnt_alloc_bufs(struct vnt_private *priv)
489 struct vnt_usb_send_context *tx_context;
493 init_usb_anchor(&priv->tx_submitted);
495 for (ii = 0; ii < priv->num_tx_context; ii++) {
496 tx_context = kmalloc(sizeof(*tx_context), GFP_KERNEL);
502 priv->tx_context[ii] = tx_context;
503 tx_context->priv = priv;
504 tx_context->pkt_no = ii;
505 tx_context->in_use = false;
508 for (ii = 0; ii < priv->num_rcb; ii++) {
509 priv->rcb[ii] = kzalloc(sizeof(*priv->rcb[ii]), GFP_KERNEL);
510 if (!priv->rcb[ii]) {
520 rcb->urb = usb_alloc_urb(0, GFP_KERNEL);
526 rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
532 ret = vnt_submit_rx_urb(priv, rcb);
537 priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL);
538 if (!priv->interrupt_urb) {
543 priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
544 if (!priv->int_buf.data_buf) {
552 usb_free_urb(priv->interrupt_urb);
554 vnt_free_rx_bufs(priv);
556 vnt_free_tx_bufs(priv);
560 static void vnt_tx_80211(struct ieee80211_hw *hw,
561 struct ieee80211_tx_control *control,
564 struct vnt_private *priv = hw->priv;
566 if (vnt_tx_packet(priv, skb))
567 ieee80211_free_txskb(hw, skb);
570 static int vnt_start(struct ieee80211_hw *hw)
573 struct vnt_private *priv = hw->priv;
575 priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
577 ret = vnt_alloc_bufs(priv);
579 dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n");
583 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
585 ret = vnt_init_registers(priv);
587 dev_dbg(&priv->usb->dev, " init register fail\n");
591 ret = vnt_key_init_table(priv);
595 priv->int_interval = 1; /* bInterval is set to 1 */
597 ret = vnt_start_interrupt_urb(priv);
601 ieee80211_wake_queues(hw);
606 vnt_free_rx_bufs(priv);
607 vnt_free_tx_bufs(priv);
608 vnt_free_int_bufs(priv);
610 usb_kill_urb(priv->interrupt_urb);
611 usb_free_urb(priv->interrupt_urb);
616 static void vnt_stop(struct ieee80211_hw *hw)
618 struct vnt_private *priv = hw->priv;
624 for (i = 0; i < MAX_KEY_TABLE; i++)
625 vnt_mac_disable_keyentry(priv, i);
628 priv->key_entry_inuse = 0;
630 if (!test_bit(DEVICE_FLAGS_UNPLUG, &priv->flags))
631 vnt_mac_shutdown(priv);
633 ieee80211_stop_queues(hw);
635 set_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
637 cancel_delayed_work_sync(&priv->run_command_work);
639 priv->cmd_running = false;
641 vnt_free_tx_bufs(priv);
642 vnt_free_rx_bufs(priv);
643 vnt_free_int_bufs(priv);
645 usb_kill_urb(priv->interrupt_urb);
646 usb_free_urb(priv->interrupt_urb);
649 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
651 struct vnt_private *priv = hw->priv;
656 case NL80211_IFTYPE_STATION:
658 case NL80211_IFTYPE_ADHOC:
659 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
661 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
664 case NL80211_IFTYPE_AP:
665 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
667 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_AP);
674 priv->op_mode = vif->type;
676 /* LED blink on TX */
677 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER);
682 static void vnt_remove_interface(struct ieee80211_hw *hw,
683 struct ieee80211_vif *vif)
685 struct vnt_private *priv = hw->priv;
688 case NL80211_IFTYPE_STATION:
690 case NL80211_IFTYPE_ADHOC:
691 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
692 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
693 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
695 case NL80211_IFTYPE_AP:
696 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
697 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
698 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_AP);
704 vnt_radio_power_off(priv);
706 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
709 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
712 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
714 struct vnt_private *priv = hw->priv;
715 struct ieee80211_conf *conf = &hw->conf;
717 if (changed & IEEE80211_CONF_CHANGE_PS) {
718 if (conf->flags & IEEE80211_CONF_PS)
719 vnt_enable_power_saving(priv, conf->listen_interval);
721 vnt_disable_power_saving(priv);
724 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
725 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
726 vnt_set_channel(priv, conf->chandef.chan->hw_value);
728 if (conf->chandef.chan->band == NL80211_BAND_5GHZ)
729 priv->bb_type = BB_TYPE_11A;
731 priv->bb_type = BB_TYPE_11G;
734 if (changed & IEEE80211_CONF_CHANGE_POWER)
735 vnt_rf_setpower(priv, conf->chandef.chan);
737 if (conf->flags & (IEEE80211_CONF_OFFCHANNEL | IEEE80211_CONF_IDLE))
738 /* Set max sensitivity*/
739 vnt_update_pre_ed_threshold(priv, true);
741 vnt_update_pre_ed_threshold(priv, false);
746 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
747 struct ieee80211_vif *vif,
748 struct ieee80211_bss_conf *conf, u64 changed)
750 struct vnt_private *priv = hw->priv;
752 priv->current_aid = vif->cfg.aid;
754 if (changed & BSS_CHANGED_BSSID && conf->bssid)
755 vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid);
757 if (changed & BSS_CHANGED_BASIC_RATES) {
758 priv->basic_rates = conf->basic_rates;
760 vnt_update_top_rates(priv);
762 dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates);
765 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
766 if (conf->use_short_preamble) {
767 vnt_mac_enable_barker_preamble_mode(priv);
768 priv->preamble_type = PREAMBLE_SHORT;
770 vnt_mac_disable_barker_preamble_mode(priv);
771 priv->preamble_type = PREAMBLE_LONG;
775 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
776 if (conf->use_cts_prot)
777 vnt_mac_enable_protect_mode(priv);
779 vnt_mac_disable_protect_mode(priv);
782 if (changed & BSS_CHANGED_ERP_SLOT) {
783 if (conf->use_short_slot)
784 priv->short_slot_time = true;
786 priv->short_slot_time = false;
788 vnt_set_short_slot_time(priv);
789 vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
792 if (changed & (BSS_CHANGED_BASIC_RATES | BSS_CHANGED_ERP_PREAMBLE |
793 BSS_CHANGED_ERP_SLOT))
794 vnt_set_bss_mode(priv);
796 if (changed & (BSS_CHANGED_TXPOWER | BSS_CHANGED_BANDWIDTH))
797 vnt_rf_setpower(priv, conf->chanreq.oper.chan);
799 if (changed & BSS_CHANGED_BEACON_ENABLED) {
800 dev_dbg(&priv->usb->dev,
801 "Beacon enable %d\n", conf->enable_beacon);
803 if (conf->enable_beacon) {
804 vnt_beacon_enable(priv, vif, conf);
806 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
808 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
812 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INFO) &&
813 priv->op_mode != NL80211_IFTYPE_AP) {
814 if (vif->cfg.assoc && conf->beacon_rate) {
815 u16 ps_beacon_int = conf->beacon_int;
817 if (conf->dtim_period)
818 ps_beacon_int *= conf->dtim_period;
819 else if (hw->conf.listen_interval)
820 ps_beacon_int *= hw->conf.listen_interval;
822 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL,
825 vnt_mac_set_beacon_interval(priv, ps_beacon_int);
827 vnt_reset_next_tbtt(priv, conf->beacon_int);
829 vnt_adjust_tsf(priv, conf->beacon_rate->hw_value,
830 conf->sync_tsf, priv->current_tsf);
832 vnt_update_next_tbtt(priv,
833 conf->sync_tsf, ps_beacon_int);
835 vnt_clear_current_tsf(priv);
837 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL,
843 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
844 struct netdev_hw_addr_list *mc_list)
846 struct vnt_private *priv = hw->priv;
847 struct netdev_hw_addr *ha;
851 netdev_hw_addr_list_for_each(ha, mc_list) {
852 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
853 mc_filter |= BIT_ULL(bit_nr);
856 priv->mc_list_count = mc_list->count;
861 static void vnt_configure(struct ieee80211_hw *hw,
862 unsigned int changed_flags,
863 unsigned int *total_flags, u64 multicast)
865 struct vnt_private *priv = hw->priv;
868 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC;
870 vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
871 MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
873 dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode);
875 if (changed_flags & FIF_ALLMULTI) {
876 if (*total_flags & FIF_ALLMULTI) {
877 if (priv->mc_list_count > 2)
878 vnt_mac_set_filter(priv, ~0);
880 vnt_mac_set_filter(priv, multicast);
882 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
884 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
888 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
889 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
890 rx_mode &= ~RCR_BSSID;
892 rx_mode |= RCR_BSSID;
895 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode);
897 dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode);
900 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
901 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
902 struct ieee80211_key_conf *key)
904 struct vnt_private *priv = hw->priv;
908 return vnt_set_keys(hw, sta, vif, key);
910 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse)) {
911 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
913 vnt_mac_disable_keyentry(priv, key->hw_key_idx);
924 static int vnt_get_stats(struct ieee80211_hw *hw,
925 struct ieee80211_low_level_stats *stats)
927 struct vnt_private *priv = hw->priv;
929 memcpy(stats, &priv->low_stats, sizeof(*stats));
934 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
936 struct vnt_private *priv = hw->priv;
938 return priv->current_tsf;
941 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
944 struct vnt_private *priv = hw->priv;
946 vnt_update_next_tbtt(priv, tsf, vif->bss_conf.beacon_int);
949 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
951 struct vnt_private *priv = hw->priv;
953 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
955 vnt_clear_current_tsf(priv);
958 static const struct ieee80211_ops vnt_mac_ops = {
959 .add_chanctx = ieee80211_emulate_add_chanctx,
960 .remove_chanctx = ieee80211_emulate_remove_chanctx,
961 .change_chanctx = ieee80211_emulate_change_chanctx,
962 .switch_vif_chanctx = ieee80211_emulate_switch_vif_chanctx,
964 .wake_tx_queue = ieee80211_handle_wake_tx_queue,
967 .add_interface = vnt_add_interface,
968 .remove_interface = vnt_remove_interface,
969 .config = vnt_config,
970 .bss_info_changed = vnt_bss_info_changed,
971 .prepare_multicast = vnt_prepare_multicast,
972 .configure_filter = vnt_configure,
973 .set_key = vnt_set_key,
974 .get_stats = vnt_get_stats,
975 .get_tsf = vnt_get_tsf,
976 .set_tsf = vnt_set_tsf,
977 .reset_tsf = vnt_reset_tsf,
980 int vnt_init(struct vnt_private *priv)
982 if (vnt_init_registers(priv))
985 SET_IEEE80211_PERM_ADDR(priv->hw, priv->permanent_net_addr);
987 vnt_init_bands(priv);
989 if (ieee80211_register_hw(priv->hw))
994 vnt_radio_power_off(priv);
1000 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
1002 struct usb_device *udev;
1003 struct vnt_private *priv;
1004 struct ieee80211_hw *hw;
1005 struct wiphy *wiphy;
1008 udev = usb_get_dev(interface_to_usbdev(intf));
1010 dev_notice(&udev->dev, "%s Ver. %s\n",
1011 DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1012 dev_notice(&udev->dev,
1013 "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
1015 hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops);
1017 dev_err(&udev->dev, "could not register ieee80211_hw\n");
1027 vnt_set_options(priv);
1029 spin_lock_init(&priv->lock);
1030 mutex_init(&priv->usb_lock);
1032 INIT_DELAYED_WORK(&priv->run_command_work, vnt_run_command);
1034 usb_set_intfdata(intf, priv);
1036 wiphy = priv->hw->wiphy;
1038 wiphy->frag_threshold = FRAG_THRESH_DEF;
1039 wiphy->rts_threshold = RTS_THRESH_DEF;
1040 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1041 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1043 ieee80211_hw_set(priv->hw, TIMING_BEACON_ONLY);
1044 ieee80211_hw_set(priv->hw, SIGNAL_DBM);
1045 ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS);
1046 ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS);
1047 ieee80211_hw_set(priv->hw, SUPPORTS_PS);
1048 ieee80211_hw_set(priv->hw, PS_NULLFUNC_STACK);
1050 priv->hw->extra_tx_headroom =
1051 sizeof(struct vnt_tx_buffer) + sizeof(struct vnt_tx_usb_header);
1052 priv->hw->max_signal = 100;
1054 SET_IEEE80211_DEV(priv->hw, &intf->dev);
1056 rc = usb_reset_device(priv->usb);
1058 dev_warn(&priv->usb->dev,
1059 "%s reset fail status=%d\n", __func__, rc);
1061 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
1062 vnt_reset_command_timer(priv);
1064 vnt_schedule_command(priv, WLAN_CMD_INIT_MAC80211);
1074 static void vt6656_disconnect(struct usb_interface *intf)
1076 struct vnt_private *priv = usb_get_intfdata(intf);
1082 ieee80211_unregister_hw(priv->hw);
1084 usb_set_intfdata(intf, NULL);
1085 usb_put_dev(interface_to_usbdev(intf));
1087 set_bit(DEVICE_FLAGS_UNPLUG, &priv->flags);
1089 ieee80211_free_hw(priv->hw);
1094 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
1099 static int vt6656_resume(struct usb_interface *intf)
1104 #endif /* CONFIG_PM */
1106 MODULE_DEVICE_TABLE(usb, vt6656_table);
1108 static struct usb_driver vt6656_driver = {
1109 .name = DEVICE_NAME,
1110 .probe = vt6656_probe,
1111 .disconnect = vt6656_disconnect,
1112 .id_table = vt6656_table,
1114 .suspend = vt6656_suspend,
1115 .resume = vt6656_resume,
1116 #endif /* CONFIG_PM */
1119 module_usb_driver(vt6656_driver);
1121 MODULE_FIRMWARE(FIRMWARE_NAME);