Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1 | /* |
| 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 Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 15 | * |
| 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 More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 26 | * vt6656_probe - module initial (insmod) driver entry |
Malcolm Priestley | afc7ef6 | 2014-07-25 20:51:47 +0100 | [diff] [blame] | 27 | * vnt_free_tx_bufs - free tx buffer function |
Malcolm Priestley | 500e1fb | 2014-07-25 20:51:46 +0100 | [diff] [blame] | 28 | * vnt_init_registers- initial MAC & BBP & RF internal registers. |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 29 | * |
| 30 | * Revision History: |
| 31 | */ |
| 32 | #undef __NO_VERSION__ |
| 33 | |
Krzysztof Adamski | e238223 | 2014-12-09 12:01:38 +0100 | [diff] [blame] | 34 | #include <linux/etherdevice.h> |
Al Viro | 7c51d17 | 2013-04-06 18:00:07 -0400 | [diff] [blame] | 35 | #include <linux/file.h> |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 36 | #include "device.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 37 | #include "card.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 38 | #include "baseband.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 39 | #include "mac.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 40 | #include "power.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 41 | #include "wcmd.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 42 | #include "rxtx.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 43 | #include "dpc.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 44 | #include "rf.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 45 | #include "firmware.h" |
Malcolm Priestley | 62c8526 | 2014-05-26 13:59:07 +0100 | [diff] [blame] | 46 | #include "usbpipe.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 47 | #include "channel.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 48 | #include "int.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 49 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 50 | /* |
| 51 | * define module options |
| 52 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 53 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 54 | /* version information */ |
| 55 | #define DRIVER_AUTHOR \ |
| 56 | "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 57 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 58 | MODULE_LICENSE("GPL"); |
| 59 | MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM); |
| 60 | |
Peter Senna Tschudin | dbf0a03 | 2014-07-15 23:23:24 +0200 | [diff] [blame] | 61 | #define RX_DESC_DEF0 64 |
Malcolm Priestley | 2f020eb | 2014-07-16 22:22:06 +0100 | [diff] [blame] | 62 | static int vnt_rx_buffers = RX_DESC_DEF0; |
| 63 | module_param_named(rx_buffers, vnt_rx_buffers, int, 0644); |
| 64 | MODULE_PARM_DESC(rx_buffers, "Number of receive usb rx buffers"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 65 | |
Peter Senna Tschudin | dbf0a03 | 2014-07-15 23:23:24 +0200 | [diff] [blame] | 66 | #define TX_DESC_DEF0 64 |
Malcolm Priestley | 3220e3a | 2014-07-16 22:22:07 +0100 | [diff] [blame] | 67 | static int vnt_tx_buffers = TX_DESC_DEF0; |
Malcolm Priestley | 1b6953d | 2014-07-18 06:36:09 +0100 | [diff] [blame] | 68 | module_param_named(tx_buffers, vnt_tx_buffers, int, 0644); |
Malcolm Priestley | 3220e3a | 2014-07-16 22:22:07 +0100 | [diff] [blame] | 69 | MODULE_PARM_DESC(tx_buffers, "Number of receive usb tx buffers"); |
| 70 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 71 | #define RTS_THRESH_DEF 2347 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 72 | #define FRAG_THRESH_DEF 2346 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 73 | #define SHORT_RETRY_DEF 8 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 74 | #define LONG_RETRY_DEF 4 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 75 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 76 | /* BasebandType[] baseband type selected |
maomao xu | d2713e5 | 2015-12-31 15:20:53 +0800 | [diff] [blame] | 77 | * 0: indicate 802.11a type |
| 78 | * 1: indicate 802.11b type |
| 79 | * 2: indicate 802.11g type |
| 80 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 81 | |
Marcos Paulo de Souza | 24b46f9 | 2012-07-02 23:59:30 -0300 | [diff] [blame] | 82 | #define BBP_TYPE_DEF 2 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 83 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 84 | /* |
| 85 | * Static vars definitions |
| 86 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 87 | |
Greg Kroah-Hartman | 4d08887 | 2012-08-17 17:48:33 -0700 | [diff] [blame] | 88 | static struct usb_device_id vt6656_table[] = { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 89 | {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)}, |
| 90 | {} |
| 91 | }; |
| 92 | |
Malcolm Priestley | 7665cf2 | 2014-07-25 20:51:45 +0100 | [diff] [blame] | 93 | static void vnt_set_options(struct vnt_private *priv) |
Malcolm Priestley | 28e067f | 2014-07-16 22:21:59 +0100 | [diff] [blame] | 94 | { |
Malcolm Priestley | 3220e3a | 2014-07-16 22:22:07 +0100 | [diff] [blame] | 95 | /* Set number of TX buffers */ |
| 96 | if (vnt_tx_buffers < CB_MIN_TX_DESC || vnt_tx_buffers > CB_MAX_TX_DESC) |
Malcolm Priestley | 03b7e35 | 2014-07-19 12:30:04 +0100 | [diff] [blame] | 97 | priv->num_tx_context = TX_DESC_DEF0; |
Malcolm Priestley | 3220e3a | 2014-07-16 22:22:07 +0100 | [diff] [blame] | 98 | else |
Malcolm Priestley | 03b7e35 | 2014-07-19 12:30:04 +0100 | [diff] [blame] | 99 | priv->num_tx_context = vnt_tx_buffers; |
Malcolm Priestley | 2f020eb | 2014-07-16 22:22:06 +0100 | [diff] [blame] | 100 | |
| 101 | /* Set number of RX buffers */ |
| 102 | if (vnt_rx_buffers < CB_MIN_RX_DESC || vnt_rx_buffers > CB_MAX_RX_DESC) |
Malcolm Priestley | 6da4738 | 2014-07-19 12:30:03 +0100 | [diff] [blame] | 103 | priv->num_rcb = RX_DESC_DEF0; |
Malcolm Priestley | 2f020eb | 2014-07-16 22:22:06 +0100 | [diff] [blame] | 104 | else |
Malcolm Priestley | 6da4738 | 2014-07-19 12:30:03 +0100 | [diff] [blame] | 105 | priv->num_rcb = vnt_rx_buffers; |
Malcolm Priestley | 2f020eb | 2014-07-16 22:22:06 +0100 | [diff] [blame] | 106 | |
Malcolm Priestley | 388e5cb | 2014-07-20 15:33:20 +0100 | [diff] [blame] | 107 | priv->short_retry_limit = SHORT_RETRY_DEF; |
| 108 | priv->long_retry_limit = LONG_RETRY_DEF; |
Malcolm Priestley | da3b67b | 2014-07-16 22:22:00 +0100 | [diff] [blame] | 109 | priv->op_mode = NL80211_IFTYPE_UNSPECIFIED; |
Malcolm Priestley | 65df77e | 2014-07-20 15:33:11 +0100 | [diff] [blame] | 110 | priv->bb_type = BBP_TYPE_DEF; |
Malcolm Priestley | e12471d | 2014-07-20 15:33:12 +0100 | [diff] [blame] | 111 | priv->packet_type = priv->bb_type; |
Malcolm Priestley | a6177ae | 2014-07-20 15:33:24 +0100 | [diff] [blame] | 112 | priv->auto_fb_ctrl = AUTO_FB_0; |
Malcolm Priestley | 98e93fe | 2014-07-20 15:33:17 +0100 | [diff] [blame] | 113 | priv->preamble_type = 0; |
Malcolm Priestley | 35cc8f9 | 2014-07-19 12:30:12 +0100 | [diff] [blame] | 114 | priv->exist_sw_net_addr = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 117 | /* |
| 118 | * initialization of MAC & BBP registers |
| 119 | */ |
Malcolm Priestley | 500e1fb | 2014-07-25 20:51:46 +0100 | [diff] [blame] | 120 | static int vnt_init_registers(struct vnt_private *priv) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 121 | { |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 122 | 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 Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 125 | int ii; |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 126 | int status = STATUS_SUCCESS; |
| 127 | u8 tmp; |
| 128 | u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 129 | |
Malcolm Priestley | 4e62dcc9 | 2014-07-16 22:22:02 +0100 | [diff] [blame] | 130 | dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n", |
Malcolm Priestley | e12471d | 2014-07-20 15:33:12 +0100 | [diff] [blame] | 131 | DEVICE_INIT_COLD, priv->packet_type); |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 132 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 133 | if (!vnt_check_firmware_version(priv)) { |
| 134 | if (vnt_download_firmware(priv) == true) { |
| 135 | if (vnt_firmware_branch_to_sram(priv) == false) { |
Malcolm Priestley | 4e62dcc9 | 2014-07-16 22:22:02 +0100 | [diff] [blame] | 136 | dev_dbg(&priv->usb->dev, |
Malcolm Priestley | 1432146 | 2014-06-04 18:25:32 +0100 | [diff] [blame] | 137 | " vnt_firmware_branch_to_sram fail\n"); |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 138 | return false; |
| 139 | } |
| 140 | } else { |
Malcolm Priestley | 4e62dcc9 | 2014-07-16 22:22:02 +0100 | [diff] [blame] | 141 | dev_dbg(&priv->usb->dev, "FIRMWAREbDownload fail\n"); |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 142 | return false; |
| 143 | } |
| 144 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 145 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 146 | if (!vnt_vt3184_init(priv)) { |
Malcolm Priestley | 4e62dcc9 | 2014-07-16 22:22:02 +0100 | [diff] [blame] | 147 | dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n"); |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 148 | return false; |
| 149 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 150 | |
Malcolm Priestley | 748bf69 | 2013-11-03 17:49:32 +0000 | [diff] [blame] | 151 | init_cmd->init_class = DEVICE_INIT_COLD; |
Malcolm Priestley | 35cc8f9 | 2014-07-19 12:30:12 +0100 | [diff] [blame] | 152 | init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr; |
Malcolm Priestley | 3d47a6f | 2013-11-03 17:43:23 +0000 | [diff] [blame] | 153 | for (ii = 0; ii < 6; ii++) |
Malcolm Priestley | ebf9b31 | 2014-07-19 12:30:10 +0100 | [diff] [blame] | 154 | init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii]; |
Malcolm Priestley | 388e5cb | 2014-07-20 15:33:20 +0100 | [diff] [blame] | 155 | init_cmd->short_retry_limit = priv->short_retry_limit; |
| 156 | init_cmd->long_retry_limit = priv->long_retry_limit; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 157 | |
Malcolm Priestley | 3d47a6f | 2013-11-03 17:43:23 +0000 | [diff] [blame] | 158 | /* issue card_init command to device */ |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 159 | status = vnt_control_out(priv, |
Malcolm Priestley | 3d47a6f | 2013-11-03 17:43:23 +0000 | [diff] [blame] | 160 | MESSAGE_TYPE_CARDINIT, 0, 0, |
Malcolm Priestley | 748bf69 | 2013-11-03 17:49:32 +0000 | [diff] [blame] | 161 | sizeof(struct vnt_cmd_card_init), (u8 *)init_cmd); |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 162 | if (status != STATUS_SUCCESS) { |
Malcolm Priestley | 4e62dcc9 | 2014-07-16 22:22:02 +0100 | [diff] [blame] | 163 | dev_dbg(&priv->usb->dev, "Issue Card init fail\n"); |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 164 | return false; |
| 165 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 166 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 167 | status = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0, |
Malcolm Priestley | 748bf69 | 2013-11-03 17:49:32 +0000 | [diff] [blame] | 168 | sizeof(struct vnt_rsp_card_init), (u8 *)init_rsp); |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 169 | if (status != STATUS_SUCCESS) { |
Malcolm Priestley | 4e62dcc9 | 2014-07-16 22:22:02 +0100 | [diff] [blame] | 170 | dev_dbg(&priv->usb->dev, |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 171 | "Cardinit request in status fail!\n"); |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 172 | return false; |
| 173 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 174 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 175 | /* local ID for AES functions */ |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 176 | status = vnt_control_in(priv, MESSAGE_TYPE_READ, |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 177 | MAC_REG_LOCALID, MESSAGE_REQUEST_MACREG, 1, |
Malcolm Priestley | f1945a1 | 2014-07-19 12:30:06 +0100 | [diff] [blame] | 178 | &priv->local_id); |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 179 | if (status != STATUS_SUCCESS) |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 180 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 181 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 182 | /* do MACbSoftwareReset in MACvInitialize */ |
| 183 | |
Malcolm Priestley | 3c8a5b2 | 2014-07-20 15:33:14 +0100 | [diff] [blame] | 184 | priv->top_ofdm_basic_rate = RATE_24M; |
Malcolm Priestley | d80bf43 | 2014-07-20 15:33:15 +0100 | [diff] [blame] | 185 | priv->top_cck_basic_rate = RATE_1M; |
Malcolm Priestley | 2486890 | 2014-05-17 09:50:31 +0100 | [diff] [blame] | 186 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 187 | /* target to IF pin while programming to RF chip */ |
Malcolm Priestley | 5a97491 | 2014-07-20 15:33:18 +0100 | [diff] [blame] | 188 | priv->power = 0xFF; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 189 | |
Malcolm Priestley | 5a97491 | 2014-07-20 15:33:18 +0100 | [diff] [blame] | 190 | priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK]; |
| 191 | priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG]; |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 192 | /* load power table */ |
| 193 | for (ii = 0; ii < 14; ii++) { |
Malcolm Priestley | 5a97491 | 2014-07-20 15:33:18 +0100 | [diff] [blame] | 194 | priv->cck_pwr_tbl[ii] = |
Malcolm Priestley | bbb1126 | 2014-07-20 15:33:16 +0100 | [diff] [blame] | 195 | priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL]; |
Malcolm Priestley | 5a97491 | 2014-07-20 15:33:18 +0100 | [diff] [blame] | 196 | if (priv->cck_pwr_tbl[ii] == 0) |
| 197 | priv->cck_pwr_tbl[ii] = priv->cck_pwr; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 198 | |
Malcolm Priestley | 5a97491 | 2014-07-20 15:33:18 +0100 | [diff] [blame] | 199 | priv->ofdm_pwr_tbl[ii] = |
Malcolm Priestley | bbb1126 | 2014-07-20 15:33:16 +0100 | [diff] [blame] | 200 | priv->eeprom[ii + EEP_OFS_OFDM_PWR_TBL]; |
Malcolm Priestley | 5a97491 | 2014-07-20 15:33:18 +0100 | [diff] [blame] | 201 | if (priv->ofdm_pwr_tbl[ii] == 0) |
| 202 | priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_g; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 203 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 204 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 205 | /* |
| 206 | * original zonetype is USA, but custom zonetype is Europe, |
| 207 | * then need to recover 12, 13, 14 channels with 11 channel |
| 208 | */ |
Malcolm Priestley | 9ef2184 | 2014-06-25 21:19:38 +0100 | [diff] [blame] | 209 | for (ii = 11; ii < 14; ii++) { |
Malcolm Priestley | 5a97491 | 2014-07-20 15:33:18 +0100 | [diff] [blame] | 210 | priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10]; |
| 211 | priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10]; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 212 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 213 | |
Malcolm Priestley | 5a97491 | 2014-07-20 15:33:18 +0100 | [diff] [blame] | 214 | priv->ofdm_pwr_a = 0x34; /* same as RFbMA2829SelectChannel */ |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 215 | |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 216 | /* load OFDM A power table */ |
| 217 | for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) { |
Malcolm Priestley | 5a97491 | 2014-07-20 15:33:18 +0100 | [diff] [blame] | 218 | priv->ofdm_a_pwr_tbl[ii] = |
Malcolm Priestley | bbb1126 | 2014-07-20 15:33:16 +0100 | [diff] [blame] | 219 | priv->eeprom[ii + EEP_OFS_OFDMA_PWR_TBL]; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 220 | |
Malcolm Priestley | 5a97491 | 2014-07-20 15:33:18 +0100 | [diff] [blame] | 221 | if (priv->ofdm_a_pwr_tbl[ii] == 0) |
| 222 | priv->ofdm_a_pwr_tbl[ii] = priv->ofdm_pwr_a; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 223 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 224 | |
Malcolm Priestley | bbb1126 | 2014-07-20 15:33:16 +0100 | [diff] [blame] | 225 | antenna = priv->eeprom[EEP_OFS_ANTENNA]; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 226 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 227 | if (antenna & EEP_ANTINV) |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 228 | priv->tx_rx_ant_inv = true; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 229 | else |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 230 | priv->tx_rx_ant_inv = false; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 231 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 232 | antenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 233 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 234 | if (antenna == 0) /* if not set default is both */ |
| 235 | antenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 236 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 237 | if (antenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) { |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 238 | priv->tx_antenna_mode = ANT_B; |
| 239 | priv->rx_antenna_sel = 1; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 240 | |
Parth Sane | f72ea98 | 2016-03-24 01:08:29 +0530 | [diff] [blame] | 241 | if (priv->tx_rx_ant_inv) |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 242 | priv->rx_antenna_mode = ANT_A; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 243 | else |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 244 | priv->rx_antenna_mode = ANT_B; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 245 | } else { |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 246 | priv->rx_antenna_sel = 0; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 247 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 248 | if (antenna & EEP_ANTENNA_AUX) { |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 249 | priv->tx_antenna_mode = ANT_A; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 250 | |
Parth Sane | f72ea98 | 2016-03-24 01:08:29 +0530 | [diff] [blame] | 251 | if (priv->tx_rx_ant_inv) |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 252 | priv->rx_antenna_mode = ANT_B; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 253 | else |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 254 | priv->rx_antenna_mode = ANT_A; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 255 | } else { |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 256 | priv->tx_antenna_mode = ANT_B; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 257 | |
Parth Sane | f72ea98 | 2016-03-24 01:08:29 +0530 | [diff] [blame] | 258 | if (priv->tx_rx_ant_inv) |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 259 | priv->rx_antenna_mode = ANT_A; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 260 | else |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 261 | priv->rx_antenna_mode = ANT_B; |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
Malcolm Priestley | ed0db51 | 2014-07-14 19:43:06 +0100 | [diff] [blame] | 265 | /* Set initial antenna mode */ |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 266 | vnt_set_antenna_mode(priv, priv->rx_antenna_mode); |
Malcolm Priestley | ed0db51 | 2014-07-14 19:43:06 +0100 | [diff] [blame] | 267 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 268 | /* get Auto Fall Back type */ |
Malcolm Priestley | a6177ae | 2014-07-20 15:33:24 +0100 | [diff] [blame] | 269 | priv->auto_fb_ctrl = AUTO_FB_0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 270 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 271 | /* default Auto Mode */ |
Malcolm Priestley | 65df77e | 2014-07-20 15:33:11 +0100 | [diff] [blame] | 272 | priv->bb_type = BB_TYPE_11G; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 273 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 274 | /* get RFType */ |
Malcolm Priestley | 6242eca | 2014-07-19 12:30:07 +0100 | [diff] [blame] | 275 | priv->rf_type = init_rsp->rf_type; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 276 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 277 | /* load vt3266 calibration parameters in EEPROM */ |
Malcolm Priestley | 6242eca | 2014-07-19 12:30:07 +0100 | [diff] [blame] | 278 | if (priv->rf_type == RF_VT3226D0) { |
Malcolm Priestley | bbb1126 | 2014-07-20 15:33:16 +0100 | [diff] [blame] | 279 | if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) && |
| 280 | (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) { |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 281 | |
Malcolm Priestley | bbb1126 | 2014-07-20 15:33:16 +0100 | [diff] [blame] | 282 | 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 Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 285 | if (calib_tx_iq || calib_tx_dc || calib_rx_iq) { |
Peter Senna Tschudin | 33e9ab3 | 2014-07-15 22:46:48 +0200 | [diff] [blame] | 286 | /* CR255, enable TX/RX IQ and |
maomao xu | d2713e5 | 2015-12-31 15:20:53 +0800 | [diff] [blame] | 287 | * DC compensation mode |
| 288 | */ |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 289 | vnt_control_out_u8(priv, |
Peter Senna Tschudin | 33e9ab3 | 2014-07-15 22:46:48 +0200 | [diff] [blame] | 290 | MESSAGE_REQUEST_BBREG, |
| 291 | 0xff, |
| 292 | 0x03); |
| 293 | /* CR251, TX I/Q Imbalance Calibration */ |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 294 | vnt_control_out_u8(priv, |
Peter Senna Tschudin | 33e9ab3 | 2014-07-15 22:46:48 +0200 | [diff] [blame] | 295 | MESSAGE_REQUEST_BBREG, |
| 296 | 0xfb, |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 297 | calib_tx_iq); |
Peter Senna Tschudin | 33e9ab3 | 2014-07-15 22:46:48 +0200 | [diff] [blame] | 298 | /* CR252, TX DC-Offset Calibration */ |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 299 | vnt_control_out_u8(priv, |
Peter Senna Tschudin | 33e9ab3 | 2014-07-15 22:46:48 +0200 | [diff] [blame] | 300 | MESSAGE_REQUEST_BBREG, |
| 301 | 0xfC, |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 302 | calib_tx_dc); |
Peter Senna Tschudin | 33e9ab3 | 2014-07-15 22:46:48 +0200 | [diff] [blame] | 303 | /* CR253, RX I/Q Imbalance Calibration */ |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 304 | vnt_control_out_u8(priv, |
Peter Senna Tschudin | 33e9ab3 | 2014-07-15 22:46:48 +0200 | [diff] [blame] | 305 | MESSAGE_REQUEST_BBREG, |
| 306 | 0xfd, |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 307 | calib_rx_iq); |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 308 | } else { |
Peter Senna Tschudin | 33e9ab3 | 2014-07-15 22:46:48 +0200 | [diff] [blame] | 309 | /* CR255, turn off |
maomao xu | d2713e5 | 2015-12-31 15:20:53 +0800 | [diff] [blame] | 310 | * BB Calibration compensation |
| 311 | */ |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 312 | vnt_control_out_u8(priv, |
Peter Senna Tschudin | 33e9ab3 | 2014-07-15 22:46:48 +0200 | [diff] [blame] | 313 | MESSAGE_REQUEST_BBREG, |
| 314 | 0xff, |
| 315 | 0x0); |
Malcolm Priestley | 302433d | 2013-11-03 17:40:51 +0000 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | } |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 319 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 320 | /* get permanent network address */ |
Malcolm Priestley | 41e8321 | 2014-07-19 12:30:11 +0100 | [diff] [blame] | 321 | memcpy(priv->permanent_net_addr, init_rsp->net_addr, 6); |
Krzysztof Adamski | e238223 | 2014-12-09 12:01:38 +0100 | [diff] [blame] | 322 | ether_addr_copy(priv->current_net_addr, priv->permanent_net_addr); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 323 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 324 | /* if exist SW network address, use it */ |
Malcolm Priestley | 4e62dcc9 | 2014-07-16 22:22:02 +0100 | [diff] [blame] | 325 | dev_dbg(&priv->usb->dev, "Network address = %pM\n", |
Malcolm Priestley | ebf9b31 | 2014-07-19 12:30:10 +0100 | [diff] [blame] | 326 | priv->current_net_addr); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 327 | |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 328 | /* |
| 329 | * set BB and packet type at the same time |
| 330 | * set Short Slot Time, xIFS, and RSPINF |
| 331 | */ |
Malcolm Priestley | 65df77e | 2014-07-20 15:33:11 +0100 | [diff] [blame] | 332 | if (priv->bb_type == BB_TYPE_11A) |
Malcolm Priestley | a641c9e | 2014-07-20 15:33:21 +0100 | [diff] [blame] | 333 | priv->short_slot_time = true; |
Malcolm Priestley | d35d5fb | 2014-06-28 23:55:44 +0100 | [diff] [blame] | 334 | else |
Malcolm Priestley | a641c9e | 2014-07-20 15:33:21 +0100 | [diff] [blame] | 335 | priv->short_slot_time = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 336 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 337 | vnt_set_short_slot_time(priv); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 338 | |
Malcolm Priestley | bbb1126 | 2014-07-20 15:33:16 +0100 | [diff] [blame] | 339 | priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL]; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 340 | |
Malcolm Priestley | 2044dbd | 2014-07-19 12:30:16 +0100 | [diff] [blame] | 341 | if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) { |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 342 | status = vnt_control_in(priv, MESSAGE_TYPE_READ, |
| 343 | MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG, 1, &tmp); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 344 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 345 | if (status != STATUS_SUCCESS) |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 346 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 347 | |
Malcolm Priestley | d7f2d8f | 2014-07-18 23:00:54 +0100 | [diff] [blame] | 348 | if ((tmp & GPIO3_DATA) == 0) |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 349 | vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, |
Malcolm Priestley | 3695753 | 2014-05-31 11:50:42 +0100 | [diff] [blame] | 350 | GPIO3_INTMD); |
Malcolm Priestley | d7f2d8f | 2014-07-18 23:00:54 +0100 | [diff] [blame] | 351 | else |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 352 | vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, |
Malcolm Priestley | a9bed1d | 2014-05-31 11:50:41 +0100 | [diff] [blame] | 353 | GPIO3_INTMD); |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 356 | vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38); |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 357 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 358 | vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW); |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 359 | |
Malcolm Priestley | 3ce5493 | 2014-07-16 22:22:01 +0100 | [diff] [blame] | 360 | vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01); |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 361 | |
Malcolm Priestley | d7f2d8f | 2014-07-18 23:00:54 +0100 | [diff] [blame] | 362 | vnt_radio_power_on(priv); |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 363 | |
Malcolm Priestley | 4e62dcc9 | 2014-07-16 22:22:02 +0100 | [diff] [blame] | 364 | dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n"); |
Malcolm Priestley | cbc06fb | 2013-11-03 17:52:15 +0000 | [diff] [blame] | 365 | |
| 366 | return true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 367 | } |
| 368 | |
Malcolm Priestley | afc7ef6 | 2014-07-25 20:51:47 +0100 | [diff] [blame] | 369 | static void vnt_free_tx_bufs(struct vnt_private *priv) |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 370 | { |
Malcolm Priestley | f2625c2 | 2014-02-28 23:58:36 +0000 | [diff] [blame] | 371 | struct vnt_usb_send_context *tx_context; |
| 372 | int ii; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 373 | |
Malcolm Priestley | 03b7e35 | 2014-07-19 12:30:04 +0100 | [diff] [blame] | 374 | for (ii = 0; ii < priv->num_tx_context; ii++) { |
Malcolm Priestley | f7e4a8f | 2014-07-18 06:36:16 +0100 | [diff] [blame] | 375 | tx_context = priv->tx_context[ii]; |
Malcolm Priestley | f2625c2 | 2014-02-28 23:58:36 +0000 | [diff] [blame] | 376 | /* deallocate URBs */ |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 377 | if (tx_context->urb) { |
| 378 | usb_kill_urb(tx_context->urb); |
| 379 | usb_free_urb(tx_context->urb); |
Malcolm Priestley | f2625c2 | 2014-02-28 23:58:36 +0000 | [diff] [blame] | 380 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 381 | |
Malcolm Priestley | f2625c2 | 2014-02-28 23:58:36 +0000 | [diff] [blame] | 382 | kfree(tx_context); |
| 383 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 384 | } |
| 385 | |
Malcolm Priestley | 0dd6e68 | 2014-07-25 20:51:48 +0100 | [diff] [blame] | 386 | static void vnt_free_rx_bufs(struct vnt_private *priv) |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 387 | { |
Malcolm Priestley | afc5eeb | 2014-02-28 23:58:35 +0000 | [diff] [blame] | 388 | struct vnt_rcb *rcb; |
Malcolm Priestley | 115cac2 | 2013-08-28 21:12:35 +0100 | [diff] [blame] | 389 | int ii; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 390 | |
Malcolm Priestley | 6da4738 | 2014-07-19 12:30:03 +0100 | [diff] [blame] | 391 | for (ii = 0; ii < priv->num_rcb; ii++) { |
Malcolm Priestley | 8577011 | 2014-07-18 06:36:15 +0100 | [diff] [blame] | 392 | rcb = priv->rcb[ii]; |
Malcolm Priestley | 8cffb3c | 2014-06-28 23:55:42 +0100 | [diff] [blame] | 393 | if (!rcb) |
| 394 | continue; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 395 | |
Malcolm Priestley | afc5eeb | 2014-02-28 23:58:35 +0000 | [diff] [blame] | 396 | /* deallocate URBs */ |
Malcolm Priestley | 325de98 | 2014-07-18 06:36:11 +0100 | [diff] [blame] | 397 | if (rcb->urb) { |
| 398 | usb_kill_urb(rcb->urb); |
| 399 | usb_free_urb(rcb->urb); |
Malcolm Priestley | afc5eeb | 2014-02-28 23:58:35 +0000 | [diff] [blame] | 400 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 401 | |
Malcolm Priestley | afc5eeb | 2014-02-28 23:58:35 +0000 | [diff] [blame] | 402 | /* deallocate skb */ |
| 403 | if (rcb->skb) |
| 404 | dev_kfree_skb(rcb->skb); |
Malcolm Priestley | afc5eeb | 2014-02-28 23:58:35 +0000 | [diff] [blame] | 405 | |
Malcolm Priestley | 8cffb3c | 2014-06-28 23:55:42 +0100 | [diff] [blame] | 406 | kfree(rcb); |
| 407 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 408 | } |
| 409 | |
Malcolm Priestley | 76d382f | 2014-07-18 06:36:08 +0100 | [diff] [blame] | 410 | static void usb_device_reset(struct vnt_private *priv) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 411 | { |
Peter Senna Tschudin | 42b138d | 2014-07-15 23:23:26 +0200 | [diff] [blame] | 412 | int status; |
| 413 | |
Malcolm Priestley | 76d382f | 2014-07-18 06:36:08 +0100 | [diff] [blame] | 414 | status = usb_reset_device(priv->usb); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 415 | if (status) |
Malcolm Priestley | 76d382f | 2014-07-18 06:36:08 +0100 | [diff] [blame] | 416 | dev_warn(&priv->usb->dev, |
Peter Senna Tschudin | d9cf2f9 | 2014-07-16 18:08:02 +0200 | [diff] [blame] | 417 | "usb_device_reset fail status=%d\n", status); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 418 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 419 | |
Malcolm Priestley | 1c2fd56 | 2014-07-25 20:51:49 +0100 | [diff] [blame] | 420 | static void vnt_free_int_bufs(struct vnt_private *priv) |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 421 | { |
Malcolm Priestley | 1506bf3 | 2014-02-28 23:58:37 +0000 | [diff] [blame] | 422 | kfree(priv->int_buf.data_buf); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 423 | } |
| 424 | |
Malcolm Priestley | ef48442 | 2014-07-25 20:51:50 +0100 | [diff] [blame] | 425 | static bool vnt_alloc_bufs(struct vnt_private *priv) |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 426 | { |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 427 | struct vnt_usb_send_context *tx_context; |
| 428 | struct vnt_rcb *rcb; |
Malcolm Priestley | 115cac2 | 2013-08-28 21:12:35 +0100 | [diff] [blame] | 429 | int ii; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 430 | |
Malcolm Priestley | 03b7e35 | 2014-07-19 12:30:04 +0100 | [diff] [blame] | 431 | for (ii = 0; ii < priv->num_tx_context; ii++) { |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 432 | tx_context = kmalloc(sizeof(struct vnt_usb_send_context), |
Malcolm Priestley | 115cac2 | 2013-08-28 21:12:35 +0100 | [diff] [blame] | 433 | GFP_KERNEL); |
Alison Schofield | 27f31cf9 | 2016-02-10 23:06:45 -0800 | [diff] [blame] | 434 | if (!tx_context) |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 435 | goto free_tx; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 436 | |
Malcolm Priestley | f7e4a8f | 2014-07-18 06:36:16 +0100 | [diff] [blame] | 437 | priv->tx_context[ii] = tx_context; |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 438 | tx_context->priv = priv; |
Malcolm Priestley | 71d764a | 2014-07-05 19:24:27 +0100 | [diff] [blame] | 439 | tx_context->pkt_no = ii; |
Malcolm Priestley | 115cac2 | 2013-08-28 21:12:35 +0100 | [diff] [blame] | 440 | |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 441 | /* allocate URBs */ |
Alison Schofield | 3e0f86b | 2016-02-12 10:05:01 -0800 | [diff] [blame] | 442 | tx_context->urb = usb_alloc_urb(0, GFP_KERNEL); |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 443 | if (!tx_context->urb) { |
Malcolm Priestley | b4ae135 | 2014-07-16 22:22:03 +0100 | [diff] [blame] | 444 | dev_err(&priv->usb->dev, "alloc tx urb failed\n"); |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 445 | goto free_tx; |
| 446 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 447 | |
Malcolm Priestley | 30a05b3 | 2014-05-15 22:49:11 +0100 | [diff] [blame] | 448 | tx_context->in_use = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 449 | } |
| 450 | |
Malcolm Priestley | 6da4738 | 2014-07-19 12:30:03 +0100 | [diff] [blame] | 451 | for (ii = 0; ii < priv->num_rcb; ii++) { |
Malcolm Priestley | 8577011 | 2014-07-18 06:36:15 +0100 | [diff] [blame] | 452 | priv->rcb[ii] = kzalloc(sizeof(struct vnt_rcb), GFP_KERNEL); |
| 453 | if (!priv->rcb[ii]) { |
Malcolm Priestley | 8cffb3c | 2014-06-28 23:55:42 +0100 | [diff] [blame] | 454 | dev_err(&priv->usb->dev, |
| 455 | "failed to allocate rcb no %d\n", ii); |
| 456 | goto free_rx_tx; |
| 457 | } |
| 458 | |
Malcolm Priestley | 8577011 | 2014-07-18 06:36:15 +0100 | [diff] [blame] | 459 | rcb = priv->rcb[ii]; |
Malcolm Priestley | 8cffb3c | 2014-06-28 23:55:42 +0100 | [diff] [blame] | 460 | |
Malcolm Priestley | 325de98 | 2014-07-18 06:36:11 +0100 | [diff] [blame] | 461 | rcb->priv = priv; |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 462 | |
| 463 | /* allocate URBs */ |
Alison Schofield | 3e0f86b | 2016-02-12 10:05:01 -0800 | [diff] [blame] | 464 | rcb->urb = usb_alloc_urb(0, GFP_KERNEL); |
Alison Schofield | 27f31cf9 | 2016-02-10 23:06:45 -0800 | [diff] [blame] | 465 | if (!rcb->urb) { |
Malcolm Priestley | b4ae135 | 2014-07-16 22:22:03 +0100 | [diff] [blame] | 466 | dev_err(&priv->usb->dev, "Failed to alloc rx urb\n"); |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 467 | goto free_rx_tx; |
| 468 | } |
| 469 | |
Malcolm Priestley | 63b9907 | 2014-06-25 21:14:22 +0100 | [diff] [blame] | 470 | rcb->skb = dev_alloc_skb(priv->rx_buf_sz); |
Alison Schofield | 27f31cf9 | 2016-02-10 23:06:45 -0800 | [diff] [blame] | 471 | if (!rcb->skb) |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 472 | goto free_rx_tx; |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 473 | |
Malcolm Priestley | 325de98 | 2014-07-18 06:36:11 +0100 | [diff] [blame] | 474 | rcb->in_use = false; |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 475 | |
Malcolm Priestley | 8cffb3c | 2014-06-28 23:55:42 +0100 | [diff] [blame] | 476 | /* submit rx urb */ |
Malcolm Priestley | 2dc37af | 2014-07-15 19:54:41 +0100 | [diff] [blame] | 477 | if (vnt_submit_rx_urb(priv, rcb)) |
Malcolm Priestley | 8cffb3c | 2014-06-28 23:55:42 +0100 | [diff] [blame] | 478 | goto free_rx_tx; |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Alison Schofield | 3e0f86b | 2016-02-12 10:05:01 -0800 | [diff] [blame] | 481 | priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL); |
Alison Schofield | 27f31cf9 | 2016-02-10 23:06:45 -0800 | [diff] [blame] | 482 | if (!priv->interrupt_urb) { |
Malcolm Priestley | b4ae135 | 2014-07-16 22:22:03 +0100 | [diff] [blame] | 483 | dev_err(&priv->usb->dev, "Failed to alloc int urb\n"); |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 484 | goto free_rx_tx; |
| 485 | } |
| 486 | |
| 487 | priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL); |
Alison Schofield | 27f31cf9 | 2016-02-10 23:06:45 -0800 | [diff] [blame] | 488 | if (!priv->int_buf.data_buf) { |
Malcolm Priestley | 3d58248 | 2014-07-18 06:36:14 +0100 | [diff] [blame] | 489 | usb_free_urb(priv->interrupt_urb); |
Malcolm Priestley | 35491de | 2014-02-28 23:58:34 +0000 | [diff] [blame] | 490 | goto free_rx_tx; |
| 491 | } |
| 492 | |
| 493 | return true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 494 | |
| 495 | free_rx_tx: |
Malcolm Priestley | 0dd6e68 | 2014-07-25 20:51:48 +0100 | [diff] [blame] | 496 | vnt_free_rx_bufs(priv); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 497 | |
| 498 | free_tx: |
Malcolm Priestley | afc7ef6 | 2014-07-25 20:51:47 +0100 | [diff] [blame] | 499 | vnt_free_tx_bufs(priv); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 500 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 501 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 502 | } |
| 503 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 504 | static 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 Priestley | b914b49 | 2015-09-27 09:17:43 +0100 | [diff] [blame] | 509 | if (vnt_tx_packet(priv, skb)) |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 510 | ieee80211_free_txskb(hw, skb); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | static 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 Hussain | 5699c0f | 2015-06-16 05:43:16 +0000 | [diff] [blame] | 519 | if (!vnt_alloc_bufs(priv)) { |
Malcolm Priestley | ef48442 | 2014-07-25 20:51:50 +0100 | [diff] [blame] | 520 | dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n"); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 521 | return -ENOMEM; |
| 522 | } |
| 523 | |
Malcolm Priestley | 2ab3d46 | 2014-07-24 21:13:18 +0100 | [diff] [blame] | 524 | clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 525 | |
Malcolm Priestley | 500e1fb | 2014-07-25 20:51:46 +0100 | [diff] [blame] | 526 | if (vnt_init_registers(priv) == false) { |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 527 | 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 Priestley | 6200193 | 2014-07-15 19:54:35 +0100 | [diff] [blame] | 533 | vnt_int_start_interrupt(priv); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 534 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 535 | ieee80211_wake_queues(hw); |
| 536 | |
| 537 | return 0; |
| 538 | |
| 539 | free_all: |
Malcolm Priestley | 0dd6e68 | 2014-07-25 20:51:48 +0100 | [diff] [blame] | 540 | vnt_free_rx_bufs(priv); |
Malcolm Priestley | afc7ef6 | 2014-07-25 20:51:47 +0100 | [diff] [blame] | 541 | vnt_free_tx_bufs(priv); |
Malcolm Priestley | 1c2fd56 | 2014-07-25 20:51:49 +0100 | [diff] [blame] | 542 | vnt_free_int_bufs(priv); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 543 | |
Malcolm Priestley | 3d58248 | 2014-07-18 06:36:14 +0100 | [diff] [blame] | 544 | usb_kill_urb(priv->interrupt_urb); |
| 545 | usb_free_urb(priv->interrupt_urb); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 546 | |
| 547 | return -ENOMEM; |
| 548 | } |
| 549 | |
| 550 | static 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 Priestley | cbcc9a3 | 2014-07-24 21:13:20 +0100 | [diff] [blame] | 564 | if (!test_bit(DEVICE_FLAGS_UNPLUG, &priv->flags)) |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 565 | vnt_mac_shutdown(priv); |
| 566 | |
| 567 | ieee80211_stop_queues(hw); |
| 568 | |
Malcolm Priestley | 4c3b0d4 | 2014-07-24 21:13:17 +0100 | [diff] [blame] | 569 | set_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 570 | |
| 571 | cancel_delayed_work_sync(&priv->run_command_work); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 572 | |
Malcolm Priestley | 33a60b8 | 2014-07-13 10:42:45 +0100 | [diff] [blame] | 573 | priv->cmd_running = false; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 574 | |
Malcolm Priestley | afc7ef6 | 2014-07-25 20:51:47 +0100 | [diff] [blame] | 575 | vnt_free_tx_bufs(priv); |
Malcolm Priestley | 0dd6e68 | 2014-07-25 20:51:48 +0100 | [diff] [blame] | 576 | vnt_free_rx_bufs(priv); |
Malcolm Priestley | 1c2fd56 | 2014-07-25 20:51:49 +0100 | [diff] [blame] | 577 | vnt_free_int_bufs(priv); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 578 | |
Malcolm Priestley | 3d58248 | 2014-07-18 06:36:14 +0100 | [diff] [blame] | 579 | usb_kill_urb(priv->interrupt_urb); |
| 580 | usb_free_urb(priv->interrupt_urb); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static 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 Priestley | 1ecd083 | 2014-06-28 23:55:46 +0100 | [diff] [blame] | 610 | vnt_set_bss_mode(priv); |
| 611 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 612 | /* LED blink on TX */ |
| 613 | vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER); |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | static 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 Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static 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 Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 665 | if (conf->chandef.chan->band == NL80211_BAND_5GHZ) |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 666 | bb_type = BB_TYPE_11A; |
| 667 | else |
| 668 | bb_type = BB_TYPE_11G; |
| 669 | |
Malcolm Priestley | 65df77e | 2014-07-20 15:33:11 +0100 | [diff] [blame] | 670 | if (priv->bb_type != bb_type) { |
| 671 | priv->bb_type = bb_type; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 672 | |
| 673 | vnt_set_bss_mode(priv); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
Malcolm Priestley | 65df77e | 2014-07-20 15:33:11 +0100 | [diff] [blame] | 678 | if (priv->bb_type == BB_TYPE_11B) |
Malcolm Priestley | 8b84c1d | 2014-07-20 15:33:19 +0100 | [diff] [blame] | 679 | priv->current_rate = RATE_1M; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 680 | else |
Malcolm Priestley | 8b84c1d | 2014-07-20 15:33:19 +0100 | [diff] [blame] | 681 | priv->current_rate = RATE_54M; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 682 | |
Malcolm Priestley | 8b84c1d | 2014-07-20 15:33:19 +0100 | [diff] [blame] | 683 | vnt_rf_setpower(priv, priv->current_rate, |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 684 | conf->chandef.chan->hw_value); |
| 685 | } |
| 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | static 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 Tschudin | 14c5e41 | 2014-07-15 23:23:27 +0200 | [diff] [blame] | 695 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 696 | priv->current_aid = conf->aid; |
| 697 | |
Malcolm Priestley | d309509 | 2015-07-09 17:03:57 +0100 | [diff] [blame] | 698 | if (changed & BSS_CHANGED_BSSID && conf->bssid) |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 699 | vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid); |
| 700 | |
| 701 | |
| 702 | if (changed & BSS_CHANGED_BASIC_RATES) { |
Malcolm Priestley | 93a7355 | 2014-07-20 15:33:13 +0100 | [diff] [blame] | 703 | priv->basic_rates = conf->basic_rates; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 704 | |
| 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 Priestley | 98e93fe | 2014-07-20 15:33:17 +0100 | [diff] [blame] | 713 | priv->preamble_type = true; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 714 | } else { |
| 715 | vnt_mac_disable_barker_preamble_mode(priv); |
Malcolm Priestley | 98e93fe | 2014-07-20 15:33:17 +0100 | [diff] [blame] | 716 | priv->preamble_type = false; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 717 | } |
| 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 Priestley | a641c9e | 2014-07-20 15:33:21 +0100 | [diff] [blame] | 729 | priv->short_slot_time = true; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 730 | else |
Malcolm Priestley | a641c9e | 2014-07-20 15:33:21 +0100 | [diff] [blame] | 731 | priv->short_slot_time = false; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 732 | |
Malcolm Priestley | 3c956cc | 2014-07-16 22:21:54 +0100 | [diff] [blame] | 733 | vnt_set_short_slot_time(priv); |
Malcolm Priestley | c37cbd3 | 2014-07-20 15:33:25 +0100 | [diff] [blame] | 734 | vnt_set_vga_gain_offset(priv, priv->bb_vga[0]); |
Malcolm Priestley | 80dcc0a | 2014-07-16 22:21:58 +0100 | [diff] [blame] | 735 | vnt_update_pre_ed_threshold(priv, false); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | if (changed & BSS_CHANGED_TXPOWER) |
Malcolm Priestley | 8b84c1d | 2014-07-20 15:33:19 +0100 | [diff] [blame] | 739 | vnt_rf_setpower(priv, priv->current_rate, |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 740 | 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 Priestley | c151587 | 2015-09-27 09:17:40 +0100 | [diff] [blame] | 754 | |
| 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 Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | static 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 | |
| 795 | static 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 Berg | df14046 | 2015-04-22 14:40:58 +0200 | [diff] [blame] | 802 | *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 803 | |
| 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 Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 812 | 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 Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | static 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 Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 859 | static void vnt_sw_scan_start(struct ieee80211_hw *hw, |
| 860 | struct ieee80211_vif *vif, |
| 861 | const u8 *addr) |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 862 | { |
| 863 | struct vnt_private *priv = hw->priv; |
| 864 | |
Malcolm Priestley | 1ecd083 | 2014-06-28 23:55:46 +0100 | [diff] [blame] | 865 | vnt_set_bss_mode(priv); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 866 | /* Set max sensitivity*/ |
Malcolm Priestley | 80dcc0a | 2014-07-16 22:21:58 +0100 | [diff] [blame] | 867 | vnt_update_pre_ed_threshold(priv, true); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 868 | } |
| 869 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 870 | static void vnt_sw_scan_complete(struct ieee80211_hw *hw, |
| 871 | struct ieee80211_vif *vif) |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 872 | { |
| 873 | struct vnt_private *priv = hw->priv; |
| 874 | |
| 875 | /* Return sensitivity to channel level*/ |
Malcolm Priestley | 80dcc0a | 2014-07-16 22:21:58 +0100 | [diff] [blame] | 876 | vnt_update_pre_ed_threshold(priv, false); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 877 | } |
| 878 | |
Malcolm Priestley | 1786384 | 2014-06-29 20:39:54 +0100 | [diff] [blame] | 879 | static 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 Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 889 | static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 890 | { |
| 891 | struct vnt_private *priv = hw->priv; |
| 892 | |
Malcolm Priestley | 113f0b9 | 2014-07-19 12:30:13 +0100 | [diff] [blame] | 893 | return priv->current_tsf; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | static 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 | |
| 904 | static 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 | |
| 913 | static 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 Priestley | 1786384 | 2014-06-29 20:39:54 +0100 | [diff] [blame] | 926 | .get_stats = vnt_get_stats, |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 927 | .get_tsf = vnt_get_tsf, |
| 928 | .set_tsf = vnt_set_tsf, |
| 929 | .reset_tsf = vnt_reset_tsf, |
| 930 | }; |
| 931 | |
| 932 | int vnt_init(struct vnt_private *priv) |
| 933 | { |
| 934 | |
Malcolm Priestley | 500e1fb | 2014-07-25 20:51:46 +0100 | [diff] [blame] | 935 | if (!(vnt_init_registers(priv))) |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 936 | return -EAGAIN; |
| 937 | |
Malcolm Priestley | 41e8321 | 2014-07-19 12:30:11 +0100 | [diff] [blame] | 938 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->permanent_net_addr); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 939 | |
Malcolm Priestley | 110f97e | 2014-06-25 21:14:26 +0100 | [diff] [blame] | 940 | vnt_init_bands(priv); |
| 941 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 942 | if (ieee80211_register_hw(priv->hw)) |
| 943 | return -ENODEV; |
| 944 | |
Malcolm Priestley | 30816f8 | 2014-06-25 21:14:27 +0100 | [diff] [blame] | 945 | priv->mac_hw = true; |
| 946 | |
Malcolm Priestley | ba911c9 | 2014-07-05 19:24:20 +0100 | [diff] [blame] | 947 | vnt_radio_power_off(priv); |
| 948 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 949 | return 0; |
| 950 | } |
| 951 | |
| 952 | static int |
| 953 | vt6656_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 Khoroshilov | 20ff141 | 2015-03-14 01:34:41 +0300 | [diff] [blame] | 971 | rc = -ENOMEM; |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 972 | goto err_nomem; |
| 973 | } |
| 974 | |
| 975 | priv = hw->priv; |
| 976 | priv->hw = hw; |
| 977 | priv->usb = udev; |
| 978 | |
Malcolm Priestley | 7665cf2 | 2014-07-25 20:51:45 +0100 | [diff] [blame] | 979 | vnt_set_options(priv); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 980 | |
| 981 | spin_lock_init(&priv->lock); |
| 982 | mutex_init(&priv->usb_lock); |
| 983 | |
Malcolm Priestley | 592365ae4a | 2014-07-13 10:42:49 +0100 | [diff] [blame] | 984 | INIT_DELAYED_WORK(&priv->run_command_work, vnt_run_command); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 985 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 986 | 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 Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 995 | 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 Priestley | 49a315b | 2015-09-27 09:17:42 +0100 | [diff] [blame] | 999 | ieee80211_hw_set(priv->hw, SUPPORTS_PS); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 1000 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 1001 | priv->hw->max_signal = 100; |
| 1002 | |
| 1003 | SET_IEEE80211_DEV(priv->hw, &intf->dev); |
| 1004 | |
| 1005 | usb_device_reset(priv); |
| 1006 | |
Malcolm Priestley | 2ab3d46 | 2014-07-24 21:13:18 +0100 | [diff] [blame] | 1007 | clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags); |
Malcolm Priestley | 68cc161 | 2014-07-13 10:42:51 +0100 | [diff] [blame] | 1008 | vnt_reset_command_timer(priv); |
Malcolm Priestley | 30816f8 | 2014-06-25 21:14:27 +0100 | [diff] [blame] | 1009 | |
Malcolm Priestley | 57981a6 | 2014-07-13 10:42:50 +0100 | [diff] [blame] | 1010 | vnt_schedule_command(priv, WLAN_CMD_INIT_MAC80211); |
Malcolm Priestley | 30816f8 | 2014-06-25 21:14:27 +0100 | [diff] [blame] | 1011 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 1012 | return 0; |
| 1013 | |
| 1014 | err_nomem: |
| 1015 | usb_put_dev(udev); |
| 1016 | |
| 1017 | return rc; |
| 1018 | } |
| 1019 | |
Bill Pemberton | 0d7fe14 | 2012-11-19 13:26:58 -0500 | [diff] [blame] | 1020 | static void vt6656_disconnect(struct usb_interface *intf) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1021 | { |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 1022 | struct vnt_private *priv = usb_get_intfdata(intf); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1023 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 1024 | if (!priv) |
Andres More | 6cda24f | 2010-06-22 20:43:39 -0300 | [diff] [blame] | 1025 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1026 | |
Malcolm Priestley | 30816f8 | 2014-06-25 21:14:27 +0100 | [diff] [blame] | 1027 | if (priv->mac_hw) |
| 1028 | ieee80211_unregister_hw(priv->hw); |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 1029 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1030 | usb_set_intfdata(intf, NULL); |
Andres More | 6cda24f | 2010-06-22 20:43:39 -0300 | [diff] [blame] | 1031 | usb_put_dev(interface_to_usbdev(intf)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1032 | |
Malcolm Priestley | 4c3b0d4 | 2014-07-24 21:13:17 +0100 | [diff] [blame] | 1033 | set_bit(DEVICE_FLAGS_UNPLUG, &priv->flags); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1034 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 1035 | ieee80211_free_hw(priv->hw); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
Malcolm Priestley | db8f37f | 2014-06-25 21:14:25 +0100 | [diff] [blame] | 1038 | #ifdef CONFIG_PM |
| 1039 | |
| 1040 | static int vt6656_suspend(struct usb_interface *intf, pm_message_t message) |
| 1041 | { |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | static int vt6656_resume(struct usb_interface *intf) |
| 1046 | { |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
| 1050 | #endif /* CONFIG_PM */ |
| 1051 | |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 1052 | MODULE_DEVICE_TABLE(usb, vt6656_table); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1053 | |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 1054 | static struct usb_driver vt6656_driver = { |
| 1055 | .name = DEVICE_NAME, |
| 1056 | .probe = vt6656_probe, |
| 1057 | .disconnect = vt6656_disconnect, |
| 1058 | .id_table = vt6656_table, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1059 | #ifdef CONFIG_PM |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 1060 | .suspend = vt6656_suspend, |
| 1061 | .resume = vt6656_resume, |
| 1062 | #endif /* CONFIG_PM */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1063 | }; |
| 1064 | |
Greg Kroah-Hartman | bac2c12 | 2011-11-18 09:42:11 -0800 | [diff] [blame] | 1065 | module_usb_driver(vt6656_driver); |