blob: ac4fecb30d0e9c1a38421cf4c67ffba8fa4af35b [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
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.
14 *
Forest Bond92b96792009-06-13 07:38:31 -040015 *
16 * File: main_usb.c
17 *
18 * Purpose: driver entry for initial, open, close, tx and rx.
19 *
20 * Author: Lyndon Chen
21 *
22 * Date: Dec 8, 2005
23 *
24 * Functions:
25 *
Andres More26e5b652010-04-13 19:43:07 -030026 * vt6656_probe - module initial (insmod) driver entry
Malcolm Priestleyafc7ef62014-07-25 20:51:47 +010027 * vnt_free_tx_bufs - free tx buffer function
Malcolm Priestley500e1fb2014-07-25 20:51:46 +010028 * vnt_init_registers- initial MAC & BBP & RF internal registers.
Forest Bond92b96792009-06-13 07:38:31 -040029 *
30 * Revision History:
31 */
32#undef __NO_VERSION__
33
Krzysztof Adamskie2382232014-12-09 12:01:38 +010034#include <linux/etherdevice.h>
Al Viro7c51d172013-04-06 18:00:07 -040035#include <linux/file.h>
Forest Bond92b96792009-06-13 07:38:31 -040036#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040037#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040038#include "baseband.h"
Forest Bond92b96792009-06-13 07:38:31 -040039#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040040#include "power.h"
Forest Bond92b96792009-06-13 07:38:31 -040041#include "wcmd.h"
Forest Bond92b96792009-06-13 07:38:31 -040042#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040043#include "dpc.h"
Forest Bond92b96792009-06-13 07:38:31 -040044#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040045#include "firmware.h"
Malcolm Priestley62c85262014-05-26 13:59:07 +010046#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040047#include "channel.h"
Forest Bond92b96792009-06-13 07:38:31 -040048#include "int.h"
Forest Bond92b96792009-06-13 07:38:31 -040049
Andres Moreec6e0f62013-01-31 18:23:07 -050050/*
51 * define module options
52 */
Forest Bond92b96792009-06-13 07:38:31 -040053
Andres Moreec6e0f62013-01-31 18:23:07 -050054/* version information */
55#define DRIVER_AUTHOR \
56 "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
Forest Bond92b96792009-06-13 07:38:31 -040057MODULE_AUTHOR(DRIVER_AUTHOR);
58MODULE_LICENSE("GPL");
59MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
60
Peter Senna Tschudindbf0a032014-07-15 23:23:24 +020061#define RX_DESC_DEF0 64
Malcolm Priestley2f020eb2014-07-16 22:22:06 +010062static int vnt_rx_buffers = RX_DESC_DEF0;
63module_param_named(rx_buffers, vnt_rx_buffers, int, 0644);
64MODULE_PARM_DESC(rx_buffers, "Number of receive usb rx buffers");
Forest Bond92b96792009-06-13 07:38:31 -040065
Peter Senna Tschudindbf0a032014-07-15 23:23:24 +020066#define TX_DESC_DEF0 64
Malcolm Priestley3220e3a2014-07-16 22:22:07 +010067static int vnt_tx_buffers = TX_DESC_DEF0;
Malcolm Priestley1b6953d2014-07-18 06:36:09 +010068module_param_named(tx_buffers, vnt_tx_buffers, int, 0644);
Malcolm Priestley3220e3a2014-07-16 22:22:07 +010069MODULE_PARM_DESC(tx_buffers, "Number of receive usb tx buffers");
70
Forest Bond92b96792009-06-13 07:38:31 -040071#define RTS_THRESH_DEF 2347
Forest Bond92b96792009-06-13 07:38:31 -040072#define FRAG_THRESH_DEF 2346
Forest Bond92b96792009-06-13 07:38:31 -040073#define SHORT_RETRY_DEF 8
Forest Bond92b96792009-06-13 07:38:31 -040074#define LONG_RETRY_DEF 4
Forest Bond92b96792009-06-13 07:38:31 -040075
Forest Bond92b96792009-06-13 07:38:31 -040076/* BasebandType[] baseband type selected
maomao xud2713e52015-12-31 15:20:53 +080077 * 0: indicate 802.11a type
78 * 1: indicate 802.11b type
79 * 2: indicate 802.11g type
80 */
Forest Bond92b96792009-06-13 07:38:31 -040081
Marcos Paulo de Souza24b46f92012-07-02 23:59:30 -030082#define BBP_TYPE_DEF 2
Forest Bond92b96792009-06-13 07:38:31 -040083
Andres Moreec6e0f62013-01-31 18:23:07 -050084/*
85 * Static vars definitions
86 */
Forest Bond92b96792009-06-13 07:38:31 -040087
Greg Kroah-Hartman4d088872012-08-17 17:48:33 -070088static struct usb_device_id vt6656_table[] = {
Forest Bond92b96792009-06-13 07:38:31 -040089 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
90 {}
91};
92
Malcolm Priestley7665cf22014-07-25 20:51:45 +010093static void vnt_set_options(struct vnt_private *priv)
Malcolm Priestley28e067f2014-07-16 22:21:59 +010094{
Malcolm Priestley3220e3a2014-07-16 22:22:07 +010095 /* Set number of TX buffers */
96 if (vnt_tx_buffers < CB_MIN_TX_DESC || vnt_tx_buffers > CB_MAX_TX_DESC)
Malcolm Priestley03b7e352014-07-19 12:30:04 +010097 priv->num_tx_context = TX_DESC_DEF0;
Malcolm Priestley3220e3a2014-07-16 22:22:07 +010098 else
Malcolm Priestley03b7e352014-07-19 12:30:04 +010099 priv->num_tx_context = vnt_tx_buffers;
Malcolm Priestley2f020eb2014-07-16 22:22:06 +0100100
101 /* Set number of RX buffers */
102 if (vnt_rx_buffers < CB_MIN_RX_DESC || vnt_rx_buffers > CB_MAX_RX_DESC)
Malcolm Priestley6da47382014-07-19 12:30:03 +0100103 priv->num_rcb = RX_DESC_DEF0;
Malcolm Priestley2f020eb2014-07-16 22:22:06 +0100104 else
Malcolm Priestley6da47382014-07-19 12:30:03 +0100105 priv->num_rcb = vnt_rx_buffers;
Malcolm Priestley2f020eb2014-07-16 22:22:06 +0100106
Malcolm Priestley388e5cb2014-07-20 15:33:20 +0100107 priv->short_retry_limit = SHORT_RETRY_DEF;
108 priv->long_retry_limit = LONG_RETRY_DEF;
Malcolm Priestleyda3b67b2014-07-16 22:22:00 +0100109 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100110 priv->bb_type = BBP_TYPE_DEF;
Malcolm Priestleye12471d2014-07-20 15:33:12 +0100111 priv->packet_type = priv->bb_type;
Malcolm Priestleya6177ae2014-07-20 15:33:24 +0100112 priv->auto_fb_ctrl = AUTO_FB_0;
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100113 priv->preamble_type = 0;
Malcolm Priestley35cc8f92014-07-19 12:30:12 +0100114 priv->exist_sw_net_addr = false;
Forest Bond92b96792009-06-13 07:38:31 -0400115}
116
Andres Moreec6e0f62013-01-31 18:23:07 -0500117/*
118 * initialization of MAC & BBP registers
119 */
Malcolm Priestley500e1fb2014-07-25 20:51:46 +0100120static int vnt_init_registers(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400121{
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100122 struct vnt_cmd_card_init *init_cmd = &priv->init_command;
123 struct vnt_rsp_card_init *init_rsp = &priv->init_response;
124 u8 antenna;
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000125 int ii;
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100126 int status = STATUS_SUCCESS;
127 u8 tmp;
128 u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400129
Malcolm Priestley4e62dcc92014-07-16 22:22:02 +0100130 dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n",
Malcolm Priestleye12471d2014-07-20 15:33:12 +0100131 DEVICE_INIT_COLD, priv->packet_type);
Malcolm Priestley302433d2013-11-03 17:40:51 +0000132
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100133 if (!vnt_check_firmware_version(priv)) {
134 if (vnt_download_firmware(priv) == true) {
135 if (vnt_firmware_branch_to_sram(priv) == false) {
Malcolm Priestley4e62dcc92014-07-16 22:22:02 +0100136 dev_dbg(&priv->usb->dev,
Malcolm Priestley14321462014-06-04 18:25:32 +0100137 " vnt_firmware_branch_to_sram fail\n");
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000138 return false;
139 }
140 } else {
Malcolm Priestley4e62dcc92014-07-16 22:22:02 +0100141 dev_dbg(&priv->usb->dev, "FIRMWAREbDownload fail\n");
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000142 return false;
143 }
144 }
Forest Bond92b96792009-06-13 07:38:31 -0400145
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100146 if (!vnt_vt3184_init(priv)) {
Malcolm Priestley4e62dcc92014-07-16 22:22:02 +0100147 dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n");
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000148 return false;
149 }
Forest Bond92b96792009-06-13 07:38:31 -0400150
Malcolm Priestley748bf692013-11-03 17:49:32 +0000151 init_cmd->init_class = DEVICE_INIT_COLD;
Malcolm Priestley35cc8f92014-07-19 12:30:12 +0100152 init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr;
Malcolm Priestley3d47a6f2013-11-03 17:43:23 +0000153 for (ii = 0; ii < 6; ii++)
Malcolm Priestleyebf9b312014-07-19 12:30:10 +0100154 init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii];
Malcolm Priestley388e5cb2014-07-20 15:33:20 +0100155 init_cmd->short_retry_limit = priv->short_retry_limit;
156 init_cmd->long_retry_limit = priv->long_retry_limit;
Forest Bond92b96792009-06-13 07:38:31 -0400157
Malcolm Priestley3d47a6f2013-11-03 17:43:23 +0000158 /* issue card_init command to device */
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100159 status = vnt_control_out(priv,
Malcolm Priestley3d47a6f2013-11-03 17:43:23 +0000160 MESSAGE_TYPE_CARDINIT, 0, 0,
Malcolm Priestley748bf692013-11-03 17:49:32 +0000161 sizeof(struct vnt_cmd_card_init), (u8 *)init_cmd);
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100162 if (status != STATUS_SUCCESS) {
Malcolm Priestley4e62dcc92014-07-16 22:22:02 +0100163 dev_dbg(&priv->usb->dev, "Issue Card init fail\n");
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000164 return false;
165 }
Forest Bond92b96792009-06-13 07:38:31 -0400166
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100167 status = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
Malcolm Priestley748bf692013-11-03 17:49:32 +0000168 sizeof(struct vnt_rsp_card_init), (u8 *)init_rsp);
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100169 if (status != STATUS_SUCCESS) {
Malcolm Priestley4e62dcc92014-07-16 22:22:02 +0100170 dev_dbg(&priv->usb->dev,
Malcolm Priestley302433d2013-11-03 17:40:51 +0000171 "Cardinit request in status fail!\n");
Malcolm Priestley302433d2013-11-03 17:40:51 +0000172 return false;
173 }
Forest Bond92b96792009-06-13 07:38:31 -0400174
Andres Moreec6e0f62013-01-31 18:23:07 -0500175 /* local ID for AES functions */
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100176 status = vnt_control_in(priv, MESSAGE_TYPE_READ,
Malcolm Priestley302433d2013-11-03 17:40:51 +0000177 MAC_REG_LOCALID, MESSAGE_REQUEST_MACREG, 1,
Malcolm Priestleyf1945a12014-07-19 12:30:06 +0100178 &priv->local_id);
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100179 if (status != STATUS_SUCCESS)
Malcolm Priestley302433d2013-11-03 17:40:51 +0000180 return false;
Forest Bond92b96792009-06-13 07:38:31 -0400181
Andres Moreec6e0f62013-01-31 18:23:07 -0500182 /* do MACbSoftwareReset in MACvInitialize */
183
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100184 priv->top_ofdm_basic_rate = RATE_24M;
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100185 priv->top_cck_basic_rate = RATE_1M;
Malcolm Priestley24868902014-05-17 09:50:31 +0100186
Andres Moreec6e0f62013-01-31 18:23:07 -0500187 /* target to IF pin while programming to RF chip */
Malcolm Priestley5a974912014-07-20 15:33:18 +0100188 priv->power = 0xFF;
Forest Bond92b96792009-06-13 07:38:31 -0400189
Malcolm Priestley5a974912014-07-20 15:33:18 +0100190 priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK];
191 priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG];
Andres Moreec6e0f62013-01-31 18:23:07 -0500192 /* load power table */
193 for (ii = 0; ii < 14; ii++) {
Malcolm Priestley5a974912014-07-20 15:33:18 +0100194 priv->cck_pwr_tbl[ii] =
Malcolm Priestleybbb11262014-07-20 15:33:16 +0100195 priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL];
Malcolm Priestley5a974912014-07-20 15:33:18 +0100196 if (priv->cck_pwr_tbl[ii] == 0)
197 priv->cck_pwr_tbl[ii] = priv->cck_pwr;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000198
Malcolm Priestley5a974912014-07-20 15:33:18 +0100199 priv->ofdm_pwr_tbl[ii] =
Malcolm Priestleybbb11262014-07-20 15:33:16 +0100200 priv->eeprom[ii + EEP_OFS_OFDM_PWR_TBL];
Malcolm Priestley5a974912014-07-20 15:33:18 +0100201 if (priv->ofdm_pwr_tbl[ii] == 0)
202 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_g;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000203 }
Forest Bond92b96792009-06-13 07:38:31 -0400204
Andres Moreec6e0f62013-01-31 18:23:07 -0500205 /*
206 * original zonetype is USA, but custom zonetype is Europe,
207 * then need to recover 12, 13, 14 channels with 11 channel
208 */
Malcolm Priestley9ef21842014-06-25 21:19:38 +0100209 for (ii = 11; ii < 14; ii++) {
Malcolm Priestley5a974912014-07-20 15:33:18 +0100210 priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10];
211 priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10];
Malcolm Priestley302433d2013-11-03 17:40:51 +0000212 }
Forest Bond92b96792009-06-13 07:38:31 -0400213
Malcolm Priestley5a974912014-07-20 15:33:18 +0100214 priv->ofdm_pwr_a = 0x34; /* same as RFbMA2829SelectChannel */
Andres Moreec6e0f62013-01-31 18:23:07 -0500215
Malcolm Priestley302433d2013-11-03 17:40:51 +0000216 /* load OFDM A power table */
217 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
Malcolm Priestley5a974912014-07-20 15:33:18 +0100218 priv->ofdm_a_pwr_tbl[ii] =
Malcolm Priestleybbb11262014-07-20 15:33:16 +0100219 priv->eeprom[ii + EEP_OFS_OFDMA_PWR_TBL];
Forest Bond92b96792009-06-13 07:38:31 -0400220
Malcolm Priestley5a974912014-07-20 15:33:18 +0100221 if (priv->ofdm_a_pwr_tbl[ii] == 0)
222 priv->ofdm_a_pwr_tbl[ii] = priv->ofdm_pwr_a;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000223 }
Forest Bond92b96792009-06-13 07:38:31 -0400224
Malcolm Priestleybbb11262014-07-20 15:33:16 +0100225 antenna = priv->eeprom[EEP_OFS_ANTENNA];
Malcolm Priestley302433d2013-11-03 17:40:51 +0000226
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100227 if (antenna & EEP_ANTINV)
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100228 priv->tx_rx_ant_inv = true;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000229 else
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100230 priv->tx_rx_ant_inv = false;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000231
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100232 antenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
Forest Bond92b96792009-06-13 07:38:31 -0400233
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100234 if (antenna == 0) /* if not set default is both */
235 antenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
Forest Bond92b96792009-06-13 07:38:31 -0400236
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100237 if (antenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100238 priv->tx_antenna_mode = ANT_B;
239 priv->rx_antenna_sel = 1;
Forest Bond92b96792009-06-13 07:38:31 -0400240
Parth Sanef72ea982016-03-24 01:08:29 +0530241 if (priv->tx_rx_ant_inv)
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100242 priv->rx_antenna_mode = ANT_A;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000243 else
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100244 priv->rx_antenna_mode = ANT_B;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000245 } else {
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100246 priv->rx_antenna_sel = 0;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000247
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100248 if (antenna & EEP_ANTENNA_AUX) {
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100249 priv->tx_antenna_mode = ANT_A;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000250
Parth Sanef72ea982016-03-24 01:08:29 +0530251 if (priv->tx_rx_ant_inv)
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100252 priv->rx_antenna_mode = ANT_B;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000253 else
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100254 priv->rx_antenna_mode = ANT_A;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000255 } else {
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100256 priv->tx_antenna_mode = ANT_B;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000257
Parth Sanef72ea982016-03-24 01:08:29 +0530258 if (priv->tx_rx_ant_inv)
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100259 priv->rx_antenna_mode = ANT_A;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000260 else
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100261 priv->rx_antenna_mode = ANT_B;
Malcolm Priestley302433d2013-11-03 17:40:51 +0000262 }
263 }
264
Malcolm Priestleyed0db512014-07-14 19:43:06 +0100265 /* Set initial antenna mode */
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100266 vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
Malcolm Priestleyed0db512014-07-14 19:43:06 +0100267
Andres Moreec6e0f62013-01-31 18:23:07 -0500268 /* get Auto Fall Back type */
Malcolm Priestleya6177ae2014-07-20 15:33:24 +0100269 priv->auto_fb_ctrl = AUTO_FB_0;
Forest Bond92b96792009-06-13 07:38:31 -0400270
Andres Moreec6e0f62013-01-31 18:23:07 -0500271 /* default Auto Mode */
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100272 priv->bb_type = BB_TYPE_11G;
Forest Bond92b96792009-06-13 07:38:31 -0400273
Andres Moreec6e0f62013-01-31 18:23:07 -0500274 /* get RFType */
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100275 priv->rf_type = init_rsp->rf_type;
Forest Bond92b96792009-06-13 07:38:31 -0400276
Andres Moreec6e0f62013-01-31 18:23:07 -0500277 /* load vt3266 calibration parameters in EEPROM */
Malcolm Priestley6242eca2014-07-19 12:30:07 +0100278 if (priv->rf_type == RF_VT3226D0) {
Malcolm Priestleybbb11262014-07-20 15:33:16 +0100279 if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) &&
280 (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) {
Malcolm Priestley302433d2013-11-03 17:40:51 +0000281
Malcolm Priestleybbb11262014-07-20 15:33:16 +0100282 calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ];
283 calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC];
284 calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ];
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100285 if (calib_tx_iq || calib_tx_dc || calib_rx_iq) {
Peter Senna Tschudin33e9ab32014-07-15 22:46:48 +0200286 /* CR255, enable TX/RX IQ and
maomao xud2713e52015-12-31 15:20:53 +0800287 * DC compensation mode
288 */
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100289 vnt_control_out_u8(priv,
Peter Senna Tschudin33e9ab32014-07-15 22:46:48 +0200290 MESSAGE_REQUEST_BBREG,
291 0xff,
292 0x03);
293 /* CR251, TX I/Q Imbalance Calibration */
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100294 vnt_control_out_u8(priv,
Peter Senna Tschudin33e9ab32014-07-15 22:46:48 +0200295 MESSAGE_REQUEST_BBREG,
296 0xfb,
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100297 calib_tx_iq);
Peter Senna Tschudin33e9ab32014-07-15 22:46:48 +0200298 /* CR252, TX DC-Offset Calibration */
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100299 vnt_control_out_u8(priv,
Peter Senna Tschudin33e9ab32014-07-15 22:46:48 +0200300 MESSAGE_REQUEST_BBREG,
301 0xfC,
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100302 calib_tx_dc);
Peter Senna Tschudin33e9ab32014-07-15 22:46:48 +0200303 /* CR253, RX I/Q Imbalance Calibration */
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100304 vnt_control_out_u8(priv,
Peter Senna Tschudin33e9ab32014-07-15 22:46:48 +0200305 MESSAGE_REQUEST_BBREG,
306 0xfd,
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100307 calib_rx_iq);
Malcolm Priestley302433d2013-11-03 17:40:51 +0000308 } else {
Peter Senna Tschudin33e9ab32014-07-15 22:46:48 +0200309 /* CR255, turn off
maomao xud2713e52015-12-31 15:20:53 +0800310 * BB Calibration compensation
311 */
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100312 vnt_control_out_u8(priv,
Peter Senna Tschudin33e9ab32014-07-15 22:46:48 +0200313 MESSAGE_REQUEST_BBREG,
314 0xff,
315 0x0);
Malcolm Priestley302433d2013-11-03 17:40:51 +0000316 }
317 }
318 }
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000319
Andres Moreec6e0f62013-01-31 18:23:07 -0500320 /* get permanent network address */
Malcolm Priestley41e83212014-07-19 12:30:11 +0100321 memcpy(priv->permanent_net_addr, init_rsp->net_addr, 6);
Krzysztof Adamskie2382232014-12-09 12:01:38 +0100322 ether_addr_copy(priv->current_net_addr, priv->permanent_net_addr);
Forest Bond92b96792009-06-13 07:38:31 -0400323
Andres Moreec6e0f62013-01-31 18:23:07 -0500324 /* if exist SW network address, use it */
Malcolm Priestley4e62dcc92014-07-16 22:22:02 +0100325 dev_dbg(&priv->usb->dev, "Network address = %pM\n",
Malcolm Priestleyebf9b312014-07-19 12:30:10 +0100326 priv->current_net_addr);
Forest Bond92b96792009-06-13 07:38:31 -0400327
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000328 /*
329 * set BB and packet type at the same time
330 * set Short Slot Time, xIFS, and RSPINF
331 */
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100332 if (priv->bb_type == BB_TYPE_11A)
Malcolm Priestleya641c9e2014-07-20 15:33:21 +0100333 priv->short_slot_time = true;
Malcolm Priestleyd35d5fb2014-06-28 23:55:44 +0100334 else
Malcolm Priestleya641c9e2014-07-20 15:33:21 +0100335 priv->short_slot_time = false;
Forest Bond92b96792009-06-13 07:38:31 -0400336
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100337 vnt_set_short_slot_time(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400338
Malcolm Priestleybbb11262014-07-20 15:33:16 +0100339 priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL];
Forest Bond92b96792009-06-13 07:38:31 -0400340
Malcolm Priestley2044dbd2014-07-19 12:30:16 +0100341 if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) {
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100342 status = vnt_control_in(priv, MESSAGE_TYPE_READ,
343 MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG, 1, &tmp);
Forest Bond92b96792009-06-13 07:38:31 -0400344
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100345 if (status != STATUS_SUCCESS)
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000346 return false;
Forest Bond92b96792009-06-13 07:38:31 -0400347
Malcolm Priestleyd7f2d8f2014-07-18 23:00:54 +0100348 if ((tmp & GPIO3_DATA) == 0)
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100349 vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
Malcolm Priestley36957532014-05-31 11:50:42 +0100350 GPIO3_INTMD);
Malcolm Priestleyd7f2d8f2014-07-18 23:00:54 +0100351 else
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100352 vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
Malcolm Priestleya9bed1d2014-05-31 11:50:41 +0100353 GPIO3_INTMD);
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000354 }
355
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100356 vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000357
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100358 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000359
Malcolm Priestley3ce54932014-07-16 22:22:01 +0100360 vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01);
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000361
Malcolm Priestleyd7f2d8f2014-07-18 23:00:54 +0100362 vnt_radio_power_on(priv);
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000363
Malcolm Priestley4e62dcc92014-07-16 22:22:02 +0100364 dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n");
Malcolm Priestleycbc06fb2013-11-03 17:52:15 +0000365
366 return true;
Forest Bond92b96792009-06-13 07:38:31 -0400367}
368
Malcolm Priestleyafc7ef62014-07-25 20:51:47 +0100369static void vnt_free_tx_bufs(struct vnt_private *priv)
Andres More8611a292010-05-01 14:25:00 -0300370{
Malcolm Priestleyf2625c22014-02-28 23:58:36 +0000371 struct vnt_usb_send_context *tx_context;
372 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400373
Malcolm Priestley03b7e352014-07-19 12:30:04 +0100374 for (ii = 0; ii < priv->num_tx_context; ii++) {
Malcolm Priestleyf7e4a8f2014-07-18 06:36:16 +0100375 tx_context = priv->tx_context[ii];
Malcolm Priestleyf2625c22014-02-28 23:58:36 +0000376 /* deallocate URBs */
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100377 if (tx_context->urb) {
378 usb_kill_urb(tx_context->urb);
379 usb_free_urb(tx_context->urb);
Malcolm Priestleyf2625c22014-02-28 23:58:36 +0000380 }
Forest Bond92b96792009-06-13 07:38:31 -0400381
Malcolm Priestleyf2625c22014-02-28 23:58:36 +0000382 kfree(tx_context);
383 }
Forest Bond92b96792009-06-13 07:38:31 -0400384}
385
Malcolm Priestley0dd6e682014-07-25 20:51:48 +0100386static void vnt_free_rx_bufs(struct vnt_private *priv)
Andres More8611a292010-05-01 14:25:00 -0300387{
Malcolm Priestleyafc5eeb2014-02-28 23:58:35 +0000388 struct vnt_rcb *rcb;
Malcolm Priestley115cac22013-08-28 21:12:35 +0100389 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400390
Malcolm Priestley6da47382014-07-19 12:30:03 +0100391 for (ii = 0; ii < priv->num_rcb; ii++) {
Malcolm Priestley85770112014-07-18 06:36:15 +0100392 rcb = priv->rcb[ii];
Malcolm Priestley8cffb3c2014-06-28 23:55:42 +0100393 if (!rcb)
394 continue;
Forest Bond92b96792009-06-13 07:38:31 -0400395
Malcolm Priestleyafc5eeb2014-02-28 23:58:35 +0000396 /* deallocate URBs */
Malcolm Priestley325de982014-07-18 06:36:11 +0100397 if (rcb->urb) {
398 usb_kill_urb(rcb->urb);
399 usb_free_urb(rcb->urb);
Malcolm Priestleyafc5eeb2014-02-28 23:58:35 +0000400 }
Forest Bond92b96792009-06-13 07:38:31 -0400401
Malcolm Priestleyafc5eeb2014-02-28 23:58:35 +0000402 /* deallocate skb */
403 if (rcb->skb)
404 dev_kfree_skb(rcb->skb);
Malcolm Priestleyafc5eeb2014-02-28 23:58:35 +0000405
Malcolm Priestley8cffb3c2014-06-28 23:55:42 +0100406 kfree(rcb);
407 }
Forest Bond92b96792009-06-13 07:38:31 -0400408}
409
Malcolm Priestley76d382f2014-07-18 06:36:08 +0100410static void usb_device_reset(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400411{
Peter Senna Tschudin42b138d2014-07-15 23:23:26 +0200412 int status;
413
Malcolm Priestley76d382f2014-07-18 06:36:08 +0100414 status = usb_reset_device(priv->usb);
Forest Bond92b96792009-06-13 07:38:31 -0400415 if (status)
Malcolm Priestley76d382f2014-07-18 06:36:08 +0100416 dev_warn(&priv->usb->dev,
Peter Senna Tschudind9cf2f92014-07-16 18:08:02 +0200417 "usb_device_reset fail status=%d\n", status);
Forest Bond92b96792009-06-13 07:38:31 -0400418}
Forest Bond92b96792009-06-13 07:38:31 -0400419
Malcolm Priestley1c2fd562014-07-25 20:51:49 +0100420static void vnt_free_int_bufs(struct vnt_private *priv)
Andres More8611a292010-05-01 14:25:00 -0300421{
Malcolm Priestley1506bf32014-02-28 23:58:37 +0000422 kfree(priv->int_buf.data_buf);
Forest Bond92b96792009-06-13 07:38:31 -0400423}
424
Malcolm Priestleyef484422014-07-25 20:51:50 +0100425static bool vnt_alloc_bufs(struct vnt_private *priv)
Malcolm Priestleydd0a7742012-12-10 21:59:10 +0000426{
Malcolm Priestley35491de2014-02-28 23:58:34 +0000427 struct vnt_usb_send_context *tx_context;
428 struct vnt_rcb *rcb;
Malcolm Priestley115cac22013-08-28 21:12:35 +0100429 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400430
Malcolm Priestley03b7e352014-07-19 12:30:04 +0100431 for (ii = 0; ii < priv->num_tx_context; ii++) {
Malcolm Priestley35491de2014-02-28 23:58:34 +0000432 tx_context = kmalloc(sizeof(struct vnt_usb_send_context),
Malcolm Priestley115cac22013-08-28 21:12:35 +0100433 GFP_KERNEL);
Alison Schofield27f31cf92016-02-10 23:06:45 -0800434 if (!tx_context)
Malcolm Priestley35491de2014-02-28 23:58:34 +0000435 goto free_tx;
Forest Bond92b96792009-06-13 07:38:31 -0400436
Malcolm Priestleyf7e4a8f2014-07-18 06:36:16 +0100437 priv->tx_context[ii] = tx_context;
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100438 tx_context->priv = priv;
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100439 tx_context->pkt_no = ii;
Malcolm Priestley115cac22013-08-28 21:12:35 +0100440
Malcolm Priestley35491de2014-02-28 23:58:34 +0000441 /* allocate URBs */
Alison Schofield3e0f86b2016-02-12 10:05:01 -0800442 tx_context->urb = usb_alloc_urb(0, GFP_KERNEL);
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100443 if (!tx_context->urb) {
Malcolm Priestleyb4ae1352014-07-16 22:22:03 +0100444 dev_err(&priv->usb->dev, "alloc tx urb failed\n");
Malcolm Priestley35491de2014-02-28 23:58:34 +0000445 goto free_tx;
446 }
Forest Bond92b96792009-06-13 07:38:31 -0400447
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100448 tx_context->in_use = false;
Forest Bond92b96792009-06-13 07:38:31 -0400449 }
450
Malcolm Priestley6da47382014-07-19 12:30:03 +0100451 for (ii = 0; ii < priv->num_rcb; ii++) {
Malcolm Priestley85770112014-07-18 06:36:15 +0100452 priv->rcb[ii] = kzalloc(sizeof(struct vnt_rcb), GFP_KERNEL);
453 if (!priv->rcb[ii]) {
Malcolm Priestley8cffb3c2014-06-28 23:55:42 +0100454 dev_err(&priv->usb->dev,
455 "failed to allocate rcb no %d\n", ii);
456 goto free_rx_tx;
457 }
458
Malcolm Priestley85770112014-07-18 06:36:15 +0100459 rcb = priv->rcb[ii];
Malcolm Priestley8cffb3c2014-06-28 23:55:42 +0100460
Malcolm Priestley325de982014-07-18 06:36:11 +0100461 rcb->priv = priv;
Malcolm Priestley35491de2014-02-28 23:58:34 +0000462
463 /* allocate URBs */
Alison Schofield3e0f86b2016-02-12 10:05:01 -0800464 rcb->urb = usb_alloc_urb(0, GFP_KERNEL);
Alison Schofield27f31cf92016-02-10 23:06:45 -0800465 if (!rcb->urb) {
Malcolm Priestleyb4ae1352014-07-16 22:22:03 +0100466 dev_err(&priv->usb->dev, "Failed to alloc rx urb\n");
Malcolm Priestley35491de2014-02-28 23:58:34 +0000467 goto free_rx_tx;
468 }
469
Malcolm Priestley63b99072014-06-25 21:14:22 +0100470 rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
Alison Schofield27f31cf92016-02-10 23:06:45 -0800471 if (!rcb->skb)
Malcolm Priestley35491de2014-02-28 23:58:34 +0000472 goto free_rx_tx;
Malcolm Priestley35491de2014-02-28 23:58:34 +0000473
Malcolm Priestley325de982014-07-18 06:36:11 +0100474 rcb->in_use = false;
Malcolm Priestley35491de2014-02-28 23:58:34 +0000475
Malcolm Priestley8cffb3c2014-06-28 23:55:42 +0100476 /* submit rx urb */
Malcolm Priestley2dc37af2014-07-15 19:54:41 +0100477 if (vnt_submit_rx_urb(priv, rcb))
Malcolm Priestley8cffb3c2014-06-28 23:55:42 +0100478 goto free_rx_tx;
Malcolm Priestley35491de2014-02-28 23:58:34 +0000479 }
480
Alison Schofield3e0f86b2016-02-12 10:05:01 -0800481 priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL);
Alison Schofield27f31cf92016-02-10 23:06:45 -0800482 if (!priv->interrupt_urb) {
Malcolm Priestleyb4ae1352014-07-16 22:22:03 +0100483 dev_err(&priv->usb->dev, "Failed to alloc int urb\n");
Malcolm Priestley35491de2014-02-28 23:58:34 +0000484 goto free_rx_tx;
485 }
486
487 priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
Alison Schofield27f31cf92016-02-10 23:06:45 -0800488 if (!priv->int_buf.data_buf) {
Malcolm Priestley3d582482014-07-18 06:36:14 +0100489 usb_free_urb(priv->interrupt_urb);
Malcolm Priestley35491de2014-02-28 23:58:34 +0000490 goto free_rx_tx;
491 }
492
493 return true;
Forest Bond92b96792009-06-13 07:38:31 -0400494
495free_rx_tx:
Malcolm Priestley0dd6e682014-07-25 20:51:48 +0100496 vnt_free_rx_bufs(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400497
498free_tx:
Malcolm Priestleyafc7ef62014-07-25 20:51:47 +0100499 vnt_free_tx_bufs(priv);
Forest Bond92b96792009-06-13 07:38:31 -0400500
Andres Moree269fc22013-02-12 20:36:29 -0500501 return false;
Forest Bond92b96792009-06-13 07:38:31 -0400502}
503
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100504static void vnt_tx_80211(struct ieee80211_hw *hw,
505 struct ieee80211_tx_control *control, struct sk_buff *skb)
506{
507 struct vnt_private *priv = hw->priv;
508
Malcolm Priestleyb914b492015-09-27 09:17:43 +0100509 if (vnt_tx_packet(priv, skb))
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100510 ieee80211_free_txskb(hw, skb);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100511}
512
513static int vnt_start(struct ieee80211_hw *hw)
514{
515 struct vnt_private *priv = hw->priv;
516
517 priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
518
Abdul Hussain5699c0f2015-06-16 05:43:16 +0000519 if (!vnt_alloc_bufs(priv)) {
Malcolm Priestleyef484422014-07-25 20:51:50 +0100520 dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n");
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100521 return -ENOMEM;
522 }
523
Malcolm Priestley2ab3d462014-07-24 21:13:18 +0100524 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100525
Malcolm Priestley500e1fb2014-07-25 20:51:46 +0100526 if (vnt_init_registers(priv) == false) {
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100527 dev_dbg(&priv->usb->dev, " init register fail\n");
528 goto free_all;
529 }
530
531 priv->int_interval = 1; /* bInterval is set to 1 */
532
Malcolm Priestley62001932014-07-15 19:54:35 +0100533 vnt_int_start_interrupt(priv);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100534
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100535 ieee80211_wake_queues(hw);
536
537 return 0;
538
539free_all:
Malcolm Priestley0dd6e682014-07-25 20:51:48 +0100540 vnt_free_rx_bufs(priv);
Malcolm Priestleyafc7ef62014-07-25 20:51:47 +0100541 vnt_free_tx_bufs(priv);
Malcolm Priestley1c2fd562014-07-25 20:51:49 +0100542 vnt_free_int_bufs(priv);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100543
Malcolm Priestley3d582482014-07-18 06:36:14 +0100544 usb_kill_urb(priv->interrupt_urb);
545 usb_free_urb(priv->interrupt_urb);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100546
547 return -ENOMEM;
548}
549
550static void vnt_stop(struct ieee80211_hw *hw)
551{
552 struct vnt_private *priv = hw->priv;
553 int i;
554
555 if (!priv)
556 return;
557
558 for (i = 0; i < MAX_KEY_TABLE; i++)
559 vnt_mac_disable_keyentry(priv, i);
560
561 /* clear all keys */
562 priv->key_entry_inuse = 0;
563
Malcolm Priestleycbcc9a32014-07-24 21:13:20 +0100564 if (!test_bit(DEVICE_FLAGS_UNPLUG, &priv->flags))
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100565 vnt_mac_shutdown(priv);
566
567 ieee80211_stop_queues(hw);
568
Malcolm Priestley4c3b0d42014-07-24 21:13:17 +0100569 set_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100570
571 cancel_delayed_work_sync(&priv->run_command_work);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100572
Malcolm Priestley33a60b82014-07-13 10:42:45 +0100573 priv->cmd_running = false;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100574
Malcolm Priestleyafc7ef62014-07-25 20:51:47 +0100575 vnt_free_tx_bufs(priv);
Malcolm Priestley0dd6e682014-07-25 20:51:48 +0100576 vnt_free_rx_bufs(priv);
Malcolm Priestley1c2fd562014-07-25 20:51:49 +0100577 vnt_free_int_bufs(priv);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100578
Malcolm Priestley3d582482014-07-18 06:36:14 +0100579 usb_kill_urb(priv->interrupt_urb);
580 usb_free_urb(priv->interrupt_urb);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100581}
582
583static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
584{
585 struct vnt_private *priv = hw->priv;
586
587 priv->vif = vif;
588
589 switch (vif->type) {
590 case NL80211_IFTYPE_STATION:
591 break;
592 case NL80211_IFTYPE_ADHOC:
593 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
594
595 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
596
597 break;
598 case NL80211_IFTYPE_AP:
599 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
600
601 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_AP);
602
603 break;
604 default:
605 return -EOPNOTSUPP;
606 }
607
608 priv->op_mode = vif->type;
609
Malcolm Priestley1ecd0832014-06-28 23:55:46 +0100610 vnt_set_bss_mode(priv);
611
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100612 /* LED blink on TX */
613 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER);
614
615 return 0;
616}
617
618static void vnt_remove_interface(struct ieee80211_hw *hw,
619 struct ieee80211_vif *vif)
620{
621 struct vnt_private *priv = hw->priv;
622
623 switch (vif->type) {
624 case NL80211_IFTYPE_STATION:
625 break;
626 case NL80211_IFTYPE_ADHOC:
627 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
628 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
629 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
630 break;
631 case NL80211_IFTYPE_AP:
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_AP);
635 break;
636 default:
637 break;
638 }
639
640 vnt_radio_power_off(priv);
641
642 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
643
644 /* LED slow blink */
645 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100646}
647
648static int vnt_config(struct ieee80211_hw *hw, u32 changed)
649{
650 struct vnt_private *priv = hw->priv;
651 struct ieee80211_conf *conf = &hw->conf;
652 u8 bb_type;
653
654 if (changed & IEEE80211_CONF_CHANGE_PS) {
655 if (conf->flags & IEEE80211_CONF_PS)
656 vnt_enable_power_saving(priv, conf->listen_interval);
657 else
658 vnt_disable_power_saving(priv);
659 }
660
661 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
662 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
663 vnt_set_channel(priv, conf->chandef.chan->hw_value);
664
Johannes Berg57fbcce2016-04-12 15:56:15 +0200665 if (conf->chandef.chan->band == NL80211_BAND_5GHZ)
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100666 bb_type = BB_TYPE_11A;
667 else
668 bb_type = BB_TYPE_11G;
669
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100670 if (priv->bb_type != bb_type) {
671 priv->bb_type = bb_type;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100672
673 vnt_set_bss_mode(priv);
674 }
675 }
676
677 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100678 if (priv->bb_type == BB_TYPE_11B)
Malcolm Priestley8b84c1d2014-07-20 15:33:19 +0100679 priv->current_rate = RATE_1M;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100680 else
Malcolm Priestley8b84c1d2014-07-20 15:33:19 +0100681 priv->current_rate = RATE_54M;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100682
Malcolm Priestley8b84c1d2014-07-20 15:33:19 +0100683 vnt_rf_setpower(priv, priv->current_rate,
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100684 conf->chandef.chan->hw_value);
685 }
686
687 return 0;
688}
689
690static void vnt_bss_info_changed(struct ieee80211_hw *hw,
691 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
692 u32 changed)
693{
694 struct vnt_private *priv = hw->priv;
Peter Senna Tschudin14c5e412014-07-15 23:23:27 +0200695
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100696 priv->current_aid = conf->aid;
697
Malcolm Priestleyd3095092015-07-09 17:03:57 +0100698 if (changed & BSS_CHANGED_BSSID && conf->bssid)
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100699 vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid);
700
701
702 if (changed & BSS_CHANGED_BASIC_RATES) {
Malcolm Priestley93a73552014-07-20 15:33:13 +0100703 priv->basic_rates = conf->basic_rates;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100704
705 vnt_update_top_rates(priv);
706
707 dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates);
708 }
709
710 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
711 if (conf->use_short_preamble) {
712 vnt_mac_enable_barker_preamble_mode(priv);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100713 priv->preamble_type = true;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100714 } else {
715 vnt_mac_disable_barker_preamble_mode(priv);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100716 priv->preamble_type = false;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100717 }
718 }
719
720 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
721 if (conf->use_cts_prot)
722 vnt_mac_enable_protect_mode(priv);
723 else
724 vnt_mac_disable_protect_mode(priv);
725 }
726
727 if (changed & BSS_CHANGED_ERP_SLOT) {
728 if (conf->use_short_slot)
Malcolm Priestleya641c9e2014-07-20 15:33:21 +0100729 priv->short_slot_time = true;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100730 else
Malcolm Priestleya641c9e2014-07-20 15:33:21 +0100731 priv->short_slot_time = false;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100732
Malcolm Priestley3c956cc2014-07-16 22:21:54 +0100733 vnt_set_short_slot_time(priv);
Malcolm Priestleyc37cbd32014-07-20 15:33:25 +0100734 vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
Malcolm Priestley80dcc0a2014-07-16 22:21:58 +0100735 vnt_update_pre_ed_threshold(priv, false);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100736 }
737
738 if (changed & BSS_CHANGED_TXPOWER)
Malcolm Priestley8b84c1d2014-07-20 15:33:19 +0100739 vnt_rf_setpower(priv, priv->current_rate,
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100740 conf->chandef.chan->hw_value);
741
742 if (changed & BSS_CHANGED_BEACON_ENABLED) {
743 dev_dbg(&priv->usb->dev,
744 "Beacon enable %d\n", conf->enable_beacon);
745
746 if (conf->enable_beacon) {
747 vnt_beacon_enable(priv, vif, conf);
748
749 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
750 } else {
751 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
752 }
753 }
Malcolm Priestleyc1515872015-09-27 09:17:40 +0100754
755 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INFO) &&
756 priv->op_mode != NL80211_IFTYPE_AP) {
757 if (conf->assoc && conf->beacon_rate) {
758 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL,
759 TFTCTL_TSFCNTREN);
760
761 vnt_adjust_tsf(priv, conf->beacon_rate->hw_value,
762 conf->sync_tsf, priv->current_tsf);
763
764 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
765
766 vnt_reset_next_tbtt(priv, conf->beacon_int);
767 } else {
768 vnt_clear_current_tsf(priv);
769
770 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL,
771 TFTCTL_TSFCNTREN);
772 }
773 }
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100774}
775
776static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
777 struct netdev_hw_addr_list *mc_list)
778{
779 struct vnt_private *priv = hw->priv;
780 struct netdev_hw_addr *ha;
781 u64 mc_filter = 0;
782 u32 bit_nr = 0;
783
784 netdev_hw_addr_list_for_each(ha, mc_list) {
785 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
786
787 mc_filter |= 1ULL << (bit_nr & 0x3f);
788 }
789
790 priv->mc_list_count = mc_list->count;
791
792 return mc_filter;
793}
794
795static void vnt_configure(struct ieee80211_hw *hw,
796 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
797{
798 struct vnt_private *priv = hw->priv;
799 u8 rx_mode = 0;
800 int rc;
801
Johannes Bergdf140462015-04-22 14:40:58 +0200802 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100803
804 rc = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
805 MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
806
807 if (!rc)
808 rx_mode = RCR_MULTICAST | RCR_BROADCAST;
809
810 dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode);
811
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100812 if (changed_flags & FIF_ALLMULTI) {
813 if (*total_flags & FIF_ALLMULTI) {
814 if (priv->mc_list_count > 2)
815 vnt_mac_set_filter(priv, ~0);
816 else
817 vnt_mac_set_filter(priv, multicast);
818
819 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
820 } else {
821 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
822 }
823
824 }
825
826 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
827 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
828 rx_mode &= ~RCR_BSSID;
829 else
830 rx_mode |= RCR_BSSID;
831 }
832
833 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode);
834
835 dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100836}
837
838static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
839 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
840 struct ieee80211_key_conf *key)
841{
842 struct vnt_private *priv = hw->priv;
843
844 switch (cmd) {
845 case SET_KEY:
846 if (vnt_set_keys(hw, sta, vif, key))
847 return -EOPNOTSUPP;
848 break;
849 case DISABLE_KEY:
850 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
851 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
852 default:
853 break;
854 }
855
856 return 0;
857}
858
Johannes Berga344d672014-06-12 22:24:31 +0200859static void vnt_sw_scan_start(struct ieee80211_hw *hw,
860 struct ieee80211_vif *vif,
861 const u8 *addr)
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100862{
863 struct vnt_private *priv = hw->priv;
864
Malcolm Priestley1ecd0832014-06-28 23:55:46 +0100865 vnt_set_bss_mode(priv);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100866 /* Set max sensitivity*/
Malcolm Priestley80dcc0a2014-07-16 22:21:58 +0100867 vnt_update_pre_ed_threshold(priv, true);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100868}
869
Johannes Berga344d672014-06-12 22:24:31 +0200870static void vnt_sw_scan_complete(struct ieee80211_hw *hw,
871 struct ieee80211_vif *vif)
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100872{
873 struct vnt_private *priv = hw->priv;
874
875 /* Return sensitivity to channel level*/
Malcolm Priestley80dcc0a2014-07-16 22:21:58 +0100876 vnt_update_pre_ed_threshold(priv, false);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100877}
878
Malcolm Priestley17863842014-06-29 20:39:54 +0100879static int vnt_get_stats(struct ieee80211_hw *hw,
880 struct ieee80211_low_level_stats *stats)
881{
882 struct vnt_private *priv = hw->priv;
883
884 memcpy(stats, &priv->low_stats, sizeof(*stats));
885
886 return 0;
887}
888
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100889static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
890{
891 struct vnt_private *priv = hw->priv;
892
Malcolm Priestley113f0b92014-07-19 12:30:13 +0100893 return priv->current_tsf;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100894}
895
896static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
897 u64 tsf)
898{
899 struct vnt_private *priv = hw->priv;
900
901 vnt_update_next_tbtt(priv, tsf, vif->bss_conf.beacon_int);
902}
903
904static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
905{
906 struct vnt_private *priv = hw->priv;
907
908 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
909
910 vnt_clear_current_tsf(priv);
911}
912
913static const struct ieee80211_ops vnt_mac_ops = {
914 .tx = vnt_tx_80211,
915 .start = vnt_start,
916 .stop = vnt_stop,
917 .add_interface = vnt_add_interface,
918 .remove_interface = vnt_remove_interface,
919 .config = vnt_config,
920 .bss_info_changed = vnt_bss_info_changed,
921 .prepare_multicast = vnt_prepare_multicast,
922 .configure_filter = vnt_configure,
923 .set_key = vnt_set_key,
924 .sw_scan_start = vnt_sw_scan_start,
925 .sw_scan_complete = vnt_sw_scan_complete,
Malcolm Priestley17863842014-06-29 20:39:54 +0100926 .get_stats = vnt_get_stats,
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100927 .get_tsf = vnt_get_tsf,
928 .set_tsf = vnt_set_tsf,
929 .reset_tsf = vnt_reset_tsf,
930};
931
932int vnt_init(struct vnt_private *priv)
933{
934
Malcolm Priestley500e1fb2014-07-25 20:51:46 +0100935 if (!(vnt_init_registers(priv)))
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100936 return -EAGAIN;
937
Malcolm Priestley41e83212014-07-19 12:30:11 +0100938 SET_IEEE80211_PERM_ADDR(priv->hw, priv->permanent_net_addr);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100939
Malcolm Priestley110f97e2014-06-25 21:14:26 +0100940 vnt_init_bands(priv);
941
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100942 if (ieee80211_register_hw(priv->hw))
943 return -ENODEV;
944
Malcolm Priestley30816f82014-06-25 21:14:27 +0100945 priv->mac_hw = true;
946
Malcolm Priestleyba911c92014-07-05 19:24:20 +0100947 vnt_radio_power_off(priv);
948
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100949 return 0;
950}
951
952static int
953vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
954{
955 struct usb_device *udev;
956 struct vnt_private *priv;
957 struct ieee80211_hw *hw;
958 struct wiphy *wiphy;
959 int rc = 0;
960
961 udev = usb_get_dev(interface_to_usbdev(intf));
962
963 dev_notice(&udev->dev, "%s Ver. %s\n",
964 DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
965 dev_notice(&udev->dev,
966 "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
967
968 hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops);
969 if (!hw) {
970 dev_err(&udev->dev, "could not register ieee80211_hw\n");
Alexey Khoroshilov20ff1412015-03-14 01:34:41 +0300971 rc = -ENOMEM;
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100972 goto err_nomem;
973 }
974
975 priv = hw->priv;
976 priv->hw = hw;
977 priv->usb = udev;
978
Malcolm Priestley7665cf22014-07-25 20:51:45 +0100979 vnt_set_options(priv);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100980
981 spin_lock_init(&priv->lock);
982 mutex_init(&priv->usb_lock);
983
Malcolm Priestley592365ae4a2014-07-13 10:42:49 +0100984 INIT_DELAYED_WORK(&priv->run_command_work, vnt_run_command);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100985
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +0100986 usb_set_intfdata(intf, priv);
987
988 wiphy = priv->hw->wiphy;
989
990 wiphy->frag_threshold = FRAG_THRESH_DEF;
991 wiphy->rts_threshold = RTS_THRESH_DEF;
992 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
993 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
994
Johannes Berg30686bf2015-06-02 21:39:54 +0200995 ieee80211_hw_set(priv->hw, TIMING_BEACON_ONLY);
996 ieee80211_hw_set(priv->hw, SIGNAL_DBM);
997 ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS);
998 ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS);
Malcolm Priestley49a315b2015-09-27 09:17:42 +0100999 ieee80211_hw_set(priv->hw, SUPPORTS_PS);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +01001000
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +01001001 priv->hw->max_signal = 100;
1002
1003 SET_IEEE80211_DEV(priv->hw, &intf->dev);
1004
1005 usb_device_reset(priv);
1006
Malcolm Priestley2ab3d462014-07-24 21:13:18 +01001007 clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
Malcolm Priestley68cc1612014-07-13 10:42:51 +01001008 vnt_reset_command_timer(priv);
Malcolm Priestley30816f82014-06-25 21:14:27 +01001009
Malcolm Priestley57981a62014-07-13 10:42:50 +01001010 vnt_schedule_command(priv, WLAN_CMD_INIT_MAC80211);
Malcolm Priestley30816f82014-06-25 21:14:27 +01001011
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +01001012 return 0;
1013
1014err_nomem:
1015 usb_put_dev(udev);
1016
1017 return rc;
1018}
1019
Bill Pemberton0d7fe142012-11-19 13:26:58 -05001020static void vt6656_disconnect(struct usb_interface *intf)
Forest Bond92b96792009-06-13 07:38:31 -04001021{
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +01001022 struct vnt_private *priv = usb_get_intfdata(intf);
Forest Bond92b96792009-06-13 07:38:31 -04001023
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +01001024 if (!priv)
Andres More6cda24f2010-06-22 20:43:39 -03001025 return;
Forest Bond92b96792009-06-13 07:38:31 -04001026
Malcolm Priestley30816f82014-06-25 21:14:27 +01001027 if (priv->mac_hw)
1028 ieee80211_unregister_hw(priv->hw);
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +01001029
Forest Bond92b96792009-06-13 07:38:31 -04001030 usb_set_intfdata(intf, NULL);
Andres More6cda24f2010-06-22 20:43:39 -03001031 usb_put_dev(interface_to_usbdev(intf));
Forest Bond92b96792009-06-13 07:38:31 -04001032
Malcolm Priestley4c3b0d42014-07-24 21:13:17 +01001033 set_bit(DEVICE_FLAGS_UNPLUG, &priv->flags);
Forest Bond92b96792009-06-13 07:38:31 -04001034
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +01001035 ieee80211_free_hw(priv->hw);
Forest Bond92b96792009-06-13 07:38:31 -04001036}
1037
Malcolm Priestleydb8f37f2014-06-25 21:14:25 +01001038#ifdef CONFIG_PM
1039
1040static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
1041{
1042 return 0;
1043}
1044
1045static int vt6656_resume(struct usb_interface *intf)
1046{
1047 return 0;
1048}
1049
1050#endif /* CONFIG_PM */
1051
Andres More26e5b652010-04-13 19:43:07 -03001052MODULE_DEVICE_TABLE(usb, vt6656_table);
Forest Bond92b96792009-06-13 07:38:31 -04001053
Andres More26e5b652010-04-13 19:43:07 -03001054static struct usb_driver vt6656_driver = {
1055 .name = DEVICE_NAME,
1056 .probe = vt6656_probe,
1057 .disconnect = vt6656_disconnect,
1058 .id_table = vt6656_table,
Forest Bond92b96792009-06-13 07:38:31 -04001059#ifdef CONFIG_PM
Andres More26e5b652010-04-13 19:43:07 -03001060 .suspend = vt6656_suspend,
1061 .resume = vt6656_resume,
1062#endif /* CONFIG_PM */
Forest Bond92b96792009-06-13 07:38:31 -04001063};
1064
Greg Kroah-Hartmanbac2c122011-11-18 09:42:11 -08001065module_usb_driver(vt6656_driver);