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 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * File: main_usb.c |
| 20 | * |
| 21 | * Purpose: driver entry for initial, open, close, tx and rx. |
| 22 | * |
| 23 | * Author: Lyndon Chen |
| 24 | * |
| 25 | * Date: Dec 8, 2005 |
| 26 | * |
| 27 | * Functions: |
| 28 | * |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 29 | * vt6656_probe - module initial (insmod) driver entry |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 30 | * device_remove1 - module remove entry |
| 31 | * device_open - allocate dma/descripter resource & initial mac/bbp function |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 32 | * device_xmit - asynchronous data tx function |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 33 | * device_set_multi - set mac filter |
| 34 | * device_ioctl - ioctl entry |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 35 | * device_close - shutdown mac/bbp & free dma/descriptor resource |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 36 | * device_alloc_frag_buf - rx fragement pre-allocated function |
| 37 | * device_free_tx_bufs - free tx buffer function |
| 38 | * device_dma0_tx_80211- tx 802.11 frame via dma0 |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 39 | * device_dma0_xmit- tx PS buffered frame via dma0 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 40 | * device_init_registers- initial MAC & BBP & RF internal registers. |
| 41 | * device_init_rings- initial tx/rx ring buffer |
| 42 | * device_init_defrag_cb- initial & allocate de-fragement buffer. |
| 43 | * device_tx_srv- tx interrupt service function |
| 44 | * |
| 45 | * Revision History: |
| 46 | */ |
| 47 | #undef __NO_VERSION__ |
| 48 | |
Al Viro | 7c51d17 | 2013-04-06 18:00:07 -0400 | [diff] [blame] | 49 | #include <linux/file.h> |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 50 | #include "device.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 51 | #include "card.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 52 | #include "baseband.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 53 | #include "mac.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 54 | #include "tether.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 55 | #include "wmgr.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 56 | #include "wctl.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 57 | #include "power.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 58 | #include "wcmd.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 59 | #include "iocmd.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 60 | #include "tcrc.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 61 | #include "rxtx.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 62 | #include "bssdb.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 63 | #include "hostap.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 64 | #include "wpactl.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 65 | #include "iwctl.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 66 | #include "dpc.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 67 | #include "datarate.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 68 | #include "rf.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 69 | #include "firmware.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 70 | #include "rndis.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 71 | #include "control.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 72 | #include "channel.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 73 | #include "int.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 74 | #include "iowpa.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 75 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 76 | /* static int msglevel = MSG_LEVEL_DEBUG; */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 77 | static int msglevel =MSG_LEVEL_INFO; |
| 78 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 79 | /* |
| 80 | * define module options |
| 81 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 82 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 83 | /* version information */ |
| 84 | #define DRIVER_AUTHOR \ |
| 85 | "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 86 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 87 | MODULE_LICENSE("GPL"); |
| 88 | MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM); |
| 89 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 90 | #define DEVICE_PARAM(N,D) \ |
| 91 | static int N[MAX_UINTS]=OPTION_DEFAULT;\ |
| 92 | module_param_array(N, int, NULL, 0);\ |
| 93 | MODULE_PARM_DESC(N, D); |
| 94 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 95 | #define RX_DESC_DEF0 64 |
| 96 | DEVICE_PARAM(RxDescriptors0,"Number of receive usb desc buffer"); |
| 97 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 98 | #define TX_DESC_DEF0 64 |
| 99 | DEVICE_PARAM(TxDescriptors0,"Number of transmit usb desc buffer"); |
| 100 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 101 | #define CHANNEL_DEF 6 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 102 | DEVICE_PARAM(Channel, "Channel number"); |
| 103 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 104 | /* PreambleType[] is the preamble length used for transmit. |
| 105 | 0: indicate allows long preamble type |
| 106 | 1: indicate allows short preamble type |
| 107 | */ |
| 108 | |
| 109 | #define PREAMBLE_TYPE_DEF 1 |
| 110 | |
| 111 | DEVICE_PARAM(PreambleType, "Preamble Type"); |
| 112 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 113 | #define RTS_THRESH_DEF 2347 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 114 | DEVICE_PARAM(RTSThreshold, "RTS threshold"); |
| 115 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 116 | #define FRAG_THRESH_DEF 2346 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 117 | DEVICE_PARAM(FragThreshold, "Fragmentation threshold"); |
| 118 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 119 | #define DATA_RATE_DEF 13 |
| 120 | /* datarate[] index |
| 121 | 0: indicate 1 Mbps 0x02 |
| 122 | 1: indicate 2 Mbps 0x04 |
| 123 | 2: indicate 5.5 Mbps 0x0B |
| 124 | 3: indicate 11 Mbps 0x16 |
| 125 | 4: indicate 6 Mbps 0x0c |
| 126 | 5: indicate 9 Mbps 0x12 |
| 127 | 6: indicate 12 Mbps 0x18 |
| 128 | 7: indicate 18 Mbps 0x24 |
| 129 | 8: indicate 24 Mbps 0x30 |
| 130 | 9: indicate 36 Mbps 0x48 |
| 131 | 10: indicate 48 Mbps 0x60 |
| 132 | 11: indicate 54 Mbps 0x6c |
| 133 | 12: indicate 72 Mbps 0x90 |
| 134 | 13: indicate auto rate |
| 135 | */ |
| 136 | |
| 137 | DEVICE_PARAM(ConnectionRate, "Connection data rate"); |
| 138 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 139 | #define OP_MODE_DEF 0 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 140 | DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode "); |
| 141 | |
| 142 | /* OpMode[] is used for transmit. |
| 143 | 0: indicate infrastruct mode used |
| 144 | 1: indicate adhoc mode used |
| 145 | 2: indicate AP mode used |
| 146 | */ |
| 147 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 148 | /* PSMode[] |
| 149 | 0: indicate disable power saving mode |
| 150 | 1: indicate enable power saving mode |
| 151 | */ |
| 152 | |
| 153 | #define PS_MODE_DEF 0 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 154 | DEVICE_PARAM(PSMode, "Power saving mode"); |
| 155 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 156 | #define SHORT_RETRY_DEF 8 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 157 | DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits"); |
| 158 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 159 | #define LONG_RETRY_DEF 4 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 160 | DEVICE_PARAM(LongRetryLimit, "long frame retry limits"); |
| 161 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 162 | /* BasebandType[] baseband type selected |
| 163 | 0: indicate 802.11a type |
| 164 | 1: indicate 802.11b type |
| 165 | 2: indicate 802.11g type |
| 166 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 167 | |
Marcos Paulo de Souza | 24b46f9 | 2012-07-02 23:59:30 -0300 | [diff] [blame] | 168 | #define BBP_TYPE_DEF 2 |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 169 | DEVICE_PARAM(BasebandType, "baseband type"); |
| 170 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 171 | /* 80211hEnable[] |
| 172 | 0: indicate disable 802.11h |
| 173 | 1: indicate enable 802.11h |
| 174 | */ |
| 175 | |
| 176 | #define X80211h_MODE_DEF 0 |
| 177 | |
| 178 | DEVICE_PARAM(b80211hEnable, "802.11h mode"); |
| 179 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 180 | /* |
| 181 | * Static vars definitions |
| 182 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 183 | |
Greg Kroah-Hartman | 4d08887 | 2012-08-17 17:48:33 -0700 | [diff] [blame] | 184 | static struct usb_device_id vt6656_table[] = { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 185 | {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)}, |
| 186 | {} |
| 187 | }; |
| 188 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 189 | /* frequency list (map channels to frequencies) */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 190 | /* |
| 191 | static const long frequency_list[] = { |
| 192 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484, |
| 193 | 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980, |
| 194 | 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240, |
| 195 | 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680, |
| 196 | 5700, 5745, 5765, 5785, 5805, 5825 |
| 197 | }; |
| 198 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 199 | static const struct iw_handler_def iwctl_handler_def; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 200 | */ |
| 201 | |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 202 | static int vt6656_probe(struct usb_interface *intf, |
| 203 | const struct usb_device_id *id); |
| 204 | static void vt6656_disconnect(struct usb_interface *intf); |
| 205 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 206 | #ifdef CONFIG_PM /* Minimal support for suspend and resume */ |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 207 | static int vt6656_suspend(struct usb_interface *intf, pm_message_t message); |
| 208 | static int vt6656_resume(struct usb_interface *intf); |
| 209 | #endif /* CONFIG_PM */ |
| 210 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 211 | static struct net_device_stats *device_get_stats(struct net_device *dev); |
| 212 | static int device_open(struct net_device *dev); |
| 213 | static int device_xmit(struct sk_buff *skb, struct net_device *dev); |
| 214 | static void device_set_multi(struct net_device *dev); |
| 215 | static int device_close(struct net_device *dev); |
| 216 | static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); |
| 217 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 218 | static int device_init_registers(struct vnt_private *pDevice, |
| 219 | DEVICE_INIT_TYPE InitType); |
Andres More | dfdcc42 | 2013-02-12 20:36:28 -0500 | [diff] [blame] | 220 | static bool device_init_defrag_cb(struct vnt_private *pDevice); |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 221 | static void device_init_diversity_timer(struct vnt_private *pDevice); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 222 | static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev); |
| 223 | |
| 224 | static int ethtool_ioctl(struct net_device *dev, void *useraddr); |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 225 | static void device_free_tx_bufs(struct vnt_private *pDevice); |
| 226 | static void device_free_rx_bufs(struct vnt_private *pDevice); |
| 227 | static void device_free_int_bufs(struct vnt_private *pDevice); |
| 228 | static void device_free_frag_bufs(struct vnt_private *pDevice); |
Andres More | dfdcc42 | 2013-02-12 20:36:28 -0500 | [diff] [blame] | 229 | static bool device_alloc_bufs(struct vnt_private *pDevice); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 230 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 231 | static int Read_config_file(struct vnt_private *pDevice); |
| 232 | static unsigned char *Config_FileOperation(struct vnt_private *pDevice); |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 233 | static int Config_FileGetParameter(unsigned char *string, |
| 234 | unsigned char *dest, |
| 235 | unsigned char *source); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 236 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 237 | static void usb_device_reset(struct vnt_private *pDevice); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 238 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 239 | static void |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 240 | device_set_options(struct vnt_private *pDevice) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 241 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 242 | u8 abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 243 | u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 244 | u8 abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 245 | |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 246 | memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN); |
| 247 | memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN); |
| 248 | memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 249 | |
| 250 | pDevice->cbTD = TX_DESC_DEF0; |
| 251 | pDevice->cbRD = RX_DESC_DEF0; |
| 252 | pDevice->uChannel = CHANNEL_DEF; |
| 253 | pDevice->wRTSThreshold = RTS_THRESH_DEF; |
| 254 | pDevice->wFragmentationThreshold = FRAG_THRESH_DEF; |
| 255 | pDevice->byShortRetryLimit = SHORT_RETRY_DEF; |
| 256 | pDevice->byLongRetryLimit = LONG_RETRY_DEF; |
| 257 | pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME; |
| 258 | pDevice->byShortPreamble = PREAMBLE_TYPE_DEF; |
| 259 | pDevice->ePSMode = PS_MODE_DEF; |
| 260 | pDevice->b11hEnable = X80211h_MODE_DEF; |
| 261 | pDevice->eOPMode = OP_MODE_DEF; |
| 262 | pDevice->uConnectionRate = DATA_RATE_DEF; |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 263 | if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 264 | pDevice->byBBType = BBP_TYPE_DEF; |
| 265 | pDevice->byPacketType = pDevice->byBBType; |
| 266 | pDevice->byAutoFBCtrl = AUTO_FB_0; |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 267 | pDevice->bUpdateBBVGA = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 268 | pDevice->byFOETuning = 0; |
| 269 | pDevice->byAutoPwrTunning = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 270 | pDevice->byPreambleType = 0; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 271 | pDevice->bExistSWNetAddr = false; |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 272 | /* pDevice->bDiversityRegCtlON = true; */ |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 273 | pDevice->bDiversityRegCtlON = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 274 | } |
| 275 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 276 | static void device_init_diversity_timer(struct vnt_private *pDevice) |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 277 | { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 278 | init_timer(&pDevice->TimerSQ3Tmax1); |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 279 | pDevice->TimerSQ3Tmax1.data = (unsigned long)pDevice; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 280 | pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack; |
| 281 | pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ); |
| 282 | |
| 283 | init_timer(&pDevice->TimerSQ3Tmax2); |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 284 | pDevice->TimerSQ3Tmax2.data = (unsigned long)pDevice; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 285 | pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack; |
| 286 | pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ); |
| 287 | |
| 288 | init_timer(&pDevice->TimerSQ3Tmax3); |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 289 | pDevice->TimerSQ3Tmax3.data = (unsigned long)pDevice; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 290 | pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerSQ3Tmax3CallBack; |
| 291 | pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ); |
| 292 | |
| 293 | return; |
| 294 | } |
| 295 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 296 | /* |
| 297 | * initialization of MAC & BBP registers |
| 298 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 299 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 300 | static int device_init_registers(struct vnt_private *pDevice, |
| 301 | DEVICE_INIT_TYPE InitType) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 302 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 303 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
| 304 | u8 abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 305 | u8 abySNAP_RFC1042[ETH_ALEN] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00}; |
| 306 | u8 abySNAP_Bridgetunnel[ETH_ALEN] |
| 307 | = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8}; |
| 308 | u8 byAntenna; |
| 309 | int ii; |
| 310 | CMD_CARD_INIT sInitCmd; |
| 311 | int ntStatus = STATUS_SUCCESS; |
| 312 | RSP_CARD_INIT sInitRsp; |
| 313 | u8 byTmp; |
| 314 | u8 byCalibTXIQ = 0, byCalibTXDC = 0, byCalibRXIQ = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 315 | |
| 316 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n", InitType, pDevice->byPacketType); |
| 317 | spin_lock_irq(&pDevice->lock); |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 318 | if (InitType == DEVICE_INIT_COLD) { |
| 319 | memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN); |
| 320 | memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN); |
| 321 | memcpy(pDevice->abySNAP_Bridgetunnel, |
| 322 | abySNAP_Bridgetunnel, |
| 323 | ETH_ALEN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 324 | |
| 325 | if ( !FIRMWAREbCheckVersion(pDevice) ) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 326 | if (FIRMWAREbDownload(pDevice) == true) { |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 327 | if (FIRMWAREbBrach2Sram(pDevice) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 328 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbBrach2Sram fail \n"); |
| 329 | spin_unlock_irq(&pDevice->lock); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 330 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 331 | } |
| 332 | } else { |
| 333 | |
| 334 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbDownload fail \n"); |
| 335 | spin_unlock_irq(&pDevice->lock); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 336 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
| 340 | if ( !BBbVT3184Init(pDevice) ) { |
| 341 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" BBbVT3184Init fail \n"); |
| 342 | spin_unlock_irq(&pDevice->lock); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 343 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 347 | sInitCmd.byInitClass = (u8)InitType; |
| 348 | sInitCmd.bExistSWNetAddr = (u8) pDevice->bExistSWNetAddr; |
Andres More | 33d33e42 | 2010-05-19 23:50:00 -0300 | [diff] [blame] | 349 | for (ii = 0; ii < 6; ii++) |
| 350 | sInitCmd.bySWNetAddr[ii] = pDevice->abyCurrentNetAddr[ii]; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 351 | sInitCmd.byShortRetryLimit = pDevice->byShortRetryLimit; |
| 352 | sInitCmd.byLongRetryLimit = pDevice->byLongRetryLimit; |
| 353 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 354 | /* issue card_init command to device */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 355 | ntStatus = CONTROLnsRequestOut(pDevice, |
| 356 | MESSAGE_TYPE_CARDINIT, |
| 357 | 0, |
| 358 | 0, |
| 359 | sizeof(CMD_CARD_INIT), |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 360 | (u8 *) &(sInitCmd)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 361 | |
| 362 | if ( ntStatus != STATUS_SUCCESS ) { |
| 363 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Issue Card init fail \n"); |
| 364 | spin_unlock_irq(&pDevice->lock); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 365 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 366 | } |
| 367 | if (InitType == DEVICE_INIT_COLD) { |
| 368 | |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 369 | ntStatus = CONTROLnsRequestIn(pDevice,MESSAGE_TYPE_INIT_RSP,0,0,sizeof(RSP_CARD_INIT), (u8 *) &(sInitRsp)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 370 | |
| 371 | if (ntStatus != STATUS_SUCCESS) { |
| 372 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Cardinit request in status fail!\n"); |
| 373 | spin_unlock_irq(&pDevice->lock); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 374 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 375 | } |
| 376 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 377 | /* local ID for AES functions */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 378 | ntStatus = CONTROLnsRequestIn(pDevice, |
| 379 | MESSAGE_TYPE_READ, |
| 380 | MAC_REG_LOCALID, |
| 381 | MESSAGE_REQUEST_MACREG, |
| 382 | 1, |
| 383 | &pDevice->byLocalID); |
| 384 | |
| 385 | if ( ntStatus != STATUS_SUCCESS ) { |
| 386 | spin_unlock_irq(&pDevice->lock); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 387 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 388 | } |
| 389 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 390 | /* do MACbSoftwareReset in MACvInitialize */ |
| 391 | |
| 392 | /* force CCK */ |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 393 | pDevice->bCCK = true; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 394 | pDevice->bProtectMode = false; |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 395 | /* only used in 11g type, sync with ERP IE */ |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 396 | pDevice->bNonERPPresent = false; |
| 397 | pDevice->bBarkerPreambleMd = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 398 | if ( pDevice->bFixRate ) { |
Andres More | 3eaca0d | 2013-02-25 20:32:52 -0500 | [diff] [blame] | 399 | pDevice->wCurrentRate = (u16) pDevice->uConnectionRate; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 400 | } else { |
| 401 | if ( pDevice->byBBType == BB_TYPE_11B ) |
| 402 | pDevice->wCurrentRate = RATE_11M; |
| 403 | else |
| 404 | pDevice->wCurrentRate = RATE_54M; |
| 405 | } |
| 406 | |
| 407 | CHvInitChannelTable(pDevice); |
| 408 | |
| 409 | pDevice->byTopOFDMBasicRate = RATE_24M; |
| 410 | pDevice->byTopCCKBasicRate = RATE_1M; |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 411 | pDevice->byRevId = 0; |
| 412 | /* target to IF pin while programming to RF chip */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 413 | pDevice->byCurPwr = 0xFF; |
| 414 | |
| 415 | pDevice->byCCKPwr = pDevice->abyEEPROM[EEP_OFS_PWR_CCK]; |
| 416 | pDevice->byOFDMPwrG = pDevice->abyEEPROM[EEP_OFS_PWR_OFDMG]; |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 417 | /* load power table */ |
| 418 | for (ii = 0; ii < 14; ii++) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 419 | pDevice->abyCCKPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_CCK_PWR_TBL]; |
| 420 | if (pDevice->abyCCKPwrTbl[ii] == 0) |
| 421 | pDevice->abyCCKPwrTbl[ii] = pDevice->byCCKPwr; |
| 422 | pDevice->abyOFDMPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDM_PWR_TBL]; |
| 423 | if (pDevice->abyOFDMPwrTbl[ii] == 0) |
| 424 | pDevice->abyOFDMPwrTbl[ii] = pDevice->byOFDMPwrG; |
| 425 | } |
| 426 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 427 | /* |
| 428 | * original zonetype is USA, but custom zonetype is Europe, |
| 429 | * then need to recover 12, 13, 14 channels with 11 channel |
| 430 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 431 | if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) || |
| 432 | (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&& |
| 433 | (pDevice->byOriginalZonetype == ZoneType_USA)) { |
Andres More | 33d33e42 | 2010-05-19 23:50:00 -0300 | [diff] [blame] | 434 | for (ii = 11; ii < 14; ii++) { |
| 435 | pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10]; |
| 436 | pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10]; |
| 437 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 438 | } |
| 439 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 440 | pDevice->byOFDMPwrA = 0x34; /* same as RFbMA2829SelectChannel */ |
| 441 | |
| 442 | /* load OFDM A power table */ |
| 443 | for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 444 | pDevice->abyOFDMAPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDMA_PWR_TBL]; |
| 445 | if (pDevice->abyOFDMAPwrTbl[ii] == 0) |
| 446 | pDevice->abyOFDMAPwrTbl[ii] = pDevice->byOFDMPwrA; |
| 447 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 448 | |
| 449 | byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA]; |
| 450 | if (byAntenna & EEP_ANTINV) |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 451 | pDevice->bTxRxAntInv = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 452 | else |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 453 | pDevice->bTxRxAntInv = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 454 | |
| 455 | byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); |
| 456 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 457 | if (byAntenna == 0) /* if not set default is both */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 458 | byAntenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); |
| 459 | |
| 460 | if (byAntenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) { |
| 461 | pDevice->byAntennaCount = 2; |
| 462 | pDevice->byTxAntennaMode = ANT_B; |
| 463 | pDevice->dwTxAntennaSel = 1; |
| 464 | pDevice->dwRxAntennaSel = 1; |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 465 | if (pDevice->bTxRxAntInv == true) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 466 | pDevice->byRxAntennaMode = ANT_A; |
| 467 | else |
| 468 | pDevice->byRxAntennaMode = ANT_B; |
| 469 | |
| 470 | if (pDevice->bDiversityRegCtlON) |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 471 | pDevice->bDiversityEnable = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 472 | else |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 473 | pDevice->bDiversityEnable = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 474 | } else { |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 475 | pDevice->bDiversityEnable = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 476 | pDevice->byAntennaCount = 1; |
| 477 | pDevice->dwTxAntennaSel = 0; |
| 478 | pDevice->dwRxAntennaSel = 0; |
| 479 | if (byAntenna & EEP_ANTENNA_AUX) { |
| 480 | pDevice->byTxAntennaMode = ANT_A; |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 481 | if (pDevice->bTxRxAntInv == true) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 482 | pDevice->byRxAntennaMode = ANT_B; |
| 483 | else |
| 484 | pDevice->byRxAntennaMode = ANT_A; |
| 485 | } else { |
| 486 | pDevice->byTxAntennaMode = ANT_B; |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 487 | if (pDevice->bTxRxAntInv == true) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 488 | pDevice->byRxAntennaMode = ANT_A; |
| 489 | else |
| 490 | pDevice->byRxAntennaMode = ANT_B; |
| 491 | } |
| 492 | } |
| 493 | pDevice->ulDiversityNValue = 100*255; |
| 494 | pDevice->ulDiversityMValue = 100*16; |
| 495 | pDevice->byTMax = 1; |
| 496 | pDevice->byTMax2 = 4; |
| 497 | pDevice->ulSQ3TH = 0; |
| 498 | pDevice->byTMax3 = 64; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 499 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 500 | /* get Auto Fall Back type */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 501 | pDevice->byAutoFBCtrl = AUTO_FB_0; |
| 502 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 503 | /* set SCAN Time */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 504 | pDevice->uScanTime = WLAN_SCAN_MINITIME; |
| 505 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 506 | /* default Auto Mode */ |
| 507 | /* pDevice->NetworkType = Ndis802_11Automode; */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 508 | pDevice->eConfigPHYMode = PHY_TYPE_AUTO; |
| 509 | pDevice->byBBType = BB_TYPE_11G; |
| 510 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 511 | /* initialize BBP registers */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 512 | pDevice->ulTxPower = 25; |
| 513 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 514 | /* get channel range */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 515 | pDevice->byMinChannel = 1; |
| 516 | pDevice->byMaxChannel = CB_MAX_CHANNEL; |
| 517 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 518 | /* get RFType */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 519 | pDevice->byRFType = sInitRsp.byRFType; |
| 520 | |
| 521 | if ((pDevice->byRFType & RF_EMU) != 0) { |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 522 | /* force change RevID for VT3253 emu */ |
| 523 | pDevice->byRevId = 0x80; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 524 | } |
| 525 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 526 | /* load vt3266 calibration parameters in EEPROM */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 527 | if (pDevice->byRFType == RF_VT3226D0) { |
| 528 | if((pDevice->abyEEPROM[EEP_OFS_MAJOR_VER] == 0x1) && |
| 529 | (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) { |
| 530 | byCalibTXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_IQ]; |
| 531 | byCalibTXDC = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_DC]; |
| 532 | byCalibRXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_RX_IQ]; |
| 533 | if( (byCalibTXIQ || byCalibTXDC || byCalibRXIQ) ) { |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 534 | /* CR255, enable TX/RX IQ and DC compensation mode */ |
| 535 | ControlvWriteByte(pDevice, |
| 536 | MESSAGE_REQUEST_BBREG, |
| 537 | 0xFF, |
| 538 | 0x03); |
| 539 | /* CR251, TX I/Q Imbalance Calibration */ |
| 540 | ControlvWriteByte(pDevice, |
| 541 | MESSAGE_REQUEST_BBREG, |
| 542 | 0xFB, |
| 543 | byCalibTXIQ); |
| 544 | /* CR252, TX DC-Offset Calibration */ |
| 545 | ControlvWriteByte(pDevice, |
| 546 | MESSAGE_REQUEST_BBREG, |
| 547 | 0xFC, |
| 548 | byCalibTXDC); |
| 549 | /* CR253, RX I/Q Imbalance Calibration */ |
| 550 | ControlvWriteByte(pDevice, |
| 551 | MESSAGE_REQUEST_BBREG, |
| 552 | 0xFD, |
| 553 | byCalibRXIQ); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 554 | } else { |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 555 | /* CR255, turn off BB Calibration compensation */ |
| 556 | ControlvWriteByte(pDevice, |
| 557 | MESSAGE_REQUEST_BBREG, |
| 558 | 0xFF, |
| 559 | 0x0); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | } |
| 563 | pMgmt->eScanType = WMAC_SCAN_PASSIVE; |
| 564 | pMgmt->uCurrChannel = pDevice->uChannel; |
| 565 | pMgmt->uIBSSChannel = pDevice->uChannel; |
| 566 | CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel); |
| 567 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 568 | /* get permanent network address */ |
Jim Lieb | 3e36259 | 2009-08-12 14:54:11 -0700 | [diff] [blame] | 569 | memcpy(pDevice->abyPermanentNetAddr,&(sInitRsp.byNetAddr[0]),6); |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 570 | memcpy(pDevice->abyCurrentNetAddr, |
| 571 | pDevice->abyPermanentNetAddr, |
| 572 | ETH_ALEN); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 573 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 574 | /* if exist SW network address, use it */ |
Andy Shevchenko | d6a32aa | 2011-07-26 10:35:31 +0300 | [diff] [blame] | 575 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %pM\n", |
| 576 | pDevice->abyCurrentNetAddr); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 577 | } |
| 578 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 579 | /* |
| 580 | * set BB and packet type at the same time |
| 581 | * set Short Slot Time, xIFS, and RSPINF |
| 582 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 583 | if (pDevice->byBBType == BB_TYPE_11A) { |
| 584 | CARDbAddBasicRate(pDevice, RATE_6M); |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 585 | pDevice->bShortSlotTime = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 586 | } else { |
| 587 | CARDbAddBasicRate(pDevice, RATE_1M); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 588 | pDevice->bShortSlotTime = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 589 | } |
| 590 | BBvSetShortSlotTime(pDevice); |
| 591 | CARDvSetBSSMode(pDevice); |
| 592 | |
| 593 | if (pDevice->bUpdateBBVGA) { |
| 594 | pDevice->byBBVGACurrent = pDevice->abyBBVGA[0]; |
| 595 | pDevice->byBBVGANew = pDevice->byBBVGACurrent; |
| 596 | BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]); |
| 597 | } |
| 598 | |
| 599 | pDevice->byRadioCtl = pDevice->abyEEPROM[EEP_OFS_RADIOCTL]; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 600 | pDevice->bHWRadioOff = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 601 | if ( (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) != 0 ) { |
| 602 | ntStatus = CONTROLnsRequestIn(pDevice, |
| 603 | MESSAGE_TYPE_READ, |
| 604 | MAC_REG_GPIOCTL1, |
| 605 | MESSAGE_REQUEST_MACREG, |
| 606 | 1, |
| 607 | &byTmp); |
| 608 | |
| 609 | if ( ntStatus != STATUS_SUCCESS ) { |
| 610 | spin_unlock_irq(&pDevice->lock); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 611 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 612 | } |
| 613 | if ( (byTmp & GPIO3_DATA) == 0 ) { |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 614 | pDevice->bHWRadioOff = true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 615 | MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); |
| 616 | } else { |
| 617 | MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 618 | pDevice->bHWRadioOff = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 619 | } |
| 620 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 621 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 622 | |
| 623 | ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_TMLEN,0x38); |
| 624 | ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); |
| 625 | MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL0,0x01); |
| 626 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 627 | if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 628 | CARDbRadioPowerOff(pDevice); |
| 629 | } else { |
| 630 | CARDbRadioPowerOn(pDevice); |
| 631 | } |
| 632 | |
| 633 | spin_unlock_irq(&pDevice->lock); |
| 634 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----INIbInitAdapter Exit\n"); |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 635 | return true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 636 | } |
| 637 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 638 | #ifdef CONFIG_PM /* Minimal support for suspend and resume */ |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 639 | |
| 640 | static int vt6656_suspend(struct usb_interface *intf, pm_message_t message) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 641 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 642 | struct vnt_private *device = usb_get_intfdata(intf); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 643 | |
Andres More | e54d9eb | 2010-06-21 15:35:43 -0300 | [diff] [blame] | 644 | if (!device || !device->dev) |
| 645 | return -ENODEV; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 646 | |
Andres More | e54d9eb | 2010-06-21 15:35:43 -0300 | [diff] [blame] | 647 | if (device->flags & DEVICE_FLAGS_OPENED) |
| 648 | device_close(device->dev); |
| 649 | |
Andres More | e54d9eb | 2010-06-21 15:35:43 -0300 | [diff] [blame] | 650 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 651 | } |
| 652 | |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 653 | static int vt6656_resume(struct usb_interface *intf) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 654 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 655 | struct vnt_private *device = usb_get_intfdata(intf); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 656 | |
Andres More | e54d9eb | 2010-06-21 15:35:43 -0300 | [diff] [blame] | 657 | if (!device || !device->dev) |
| 658 | return -ENODEV; |
| 659 | |
Andres More | e54d9eb | 2010-06-21 15:35:43 -0300 | [diff] [blame] | 660 | if (!(device->flags & DEVICE_FLAGS_OPENED)) |
| 661 | device_open(device->dev); |
| 662 | |
| 663 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 664 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 665 | |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 666 | #endif /* CONFIG_PM */ |
Forest Bond | dd8db70 | 2009-06-13 07:38:54 -0400 | [diff] [blame] | 667 | |
| 668 | static const struct net_device_ops device_netdev_ops = { |
| 669 | .ndo_open = device_open, |
| 670 | .ndo_stop = device_close, |
| 671 | .ndo_do_ioctl = device_ioctl, |
| 672 | .ndo_get_stats = device_get_stats, |
| 673 | .ndo_start_xmit = device_xmit, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 674 | .ndo_set_rx_mode = device_set_multi, |
Forest Bond | dd8db70 | 2009-06-13 07:38:54 -0400 | [diff] [blame] | 675 | }; |
| 676 | |
Bill Pemberton | 59cb218 | 2012-11-19 13:21:55 -0500 | [diff] [blame] | 677 | static int |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 678 | vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 679 | { |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 680 | u8 fake_mac[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 681 | struct usb_device *udev = interface_to_usbdev(intf); |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 682 | int rc = 0; |
| 683 | struct net_device *netdev = NULL; |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 684 | struct vnt_private *pDevice; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 685 | |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 686 | printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION); |
| 687 | printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 688 | |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 689 | udev = usb_get_dev(udev); |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 690 | netdev = alloc_etherdev(sizeof(struct vnt_private)); |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 691 | if (!netdev) { |
| 692 | printk(KERN_ERR DEVICE_NAME ": allocate net device failed\n"); |
Dan Carpenter | e3a92cd | 2010-08-10 08:00:12 +0200 | [diff] [blame] | 693 | rc = -ENOMEM; |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 694 | goto err_nomem; |
| 695 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 696 | |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 697 | pDevice = netdev_priv(netdev); |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 698 | memset(pDevice, 0, sizeof(struct vnt_private)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 699 | |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 700 | pDevice->dev = netdev; |
| 701 | pDevice->usb = udev; |
Forest Bond | 1e28efa | 2009-06-13 07:38:50 -0400 | [diff] [blame] | 702 | |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 703 | device_set_options(pDevice); |
| 704 | spin_lock_init(&pDevice->lock); |
Malcolm Priestley | 94488a7 | 2013-09-27 16:48:14 +0100 | [diff] [blame] | 705 | INIT_DELAYED_WORK(&pDevice->run_command_work, vRunCommand); |
Malcolm Priestley | bd9a6db | 2013-09-27 16:51:13 +0100 | [diff] [blame^] | 706 | INIT_DELAYED_WORK(&pDevice->second_callback_work, BSSvSecondCallBack); |
Forest Bond | 1e28efa | 2009-06-13 07:38:50 -0400 | [diff] [blame] | 707 | |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 708 | pDevice->tx_80211 = device_dma0_tx_80211; |
Malcolm Priestley | 14c5ef5 | 2013-01-17 23:19:37 +0000 | [diff] [blame] | 709 | pDevice->vnt_mgmt.pAdapter = (void *) pDevice; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 710 | |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 711 | netdev->netdev_ops = &device_netdev_ops; |
| 712 | netdev->wireless_handlers = |
| 713 | (struct iw_handler_def *) &iwctl_handler_def; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 714 | |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 715 | usb_set_intfdata(intf, pDevice); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 716 | SET_NETDEV_DEV(netdev, &intf->dev); |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 717 | memcpy(pDevice->dev->dev_addr, fake_mac, ETH_ALEN); |
| 718 | rc = register_netdev(netdev); |
| 719 | if (rc) { |
| 720 | printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n"); |
Dan Carpenter | e3a92cd | 2010-08-10 08:00:12 +0200 | [diff] [blame] | 721 | goto err_netdev; |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 722 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 723 | |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 724 | usb_device_reset(pDevice); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 725 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 726 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 727 | |
Dan Carpenter | e3a92cd | 2010-08-10 08:00:12 +0200 | [diff] [blame] | 728 | err_netdev: |
| 729 | free_netdev(netdev); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 730 | err_nomem: |
Andres More | 7a8b005 | 2010-07-12 12:40:01 -0300 | [diff] [blame] | 731 | usb_put_dev(udev); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 732 | |
Dan Carpenter | e3a92cd | 2010-08-10 08:00:12 +0200 | [diff] [blame] | 733 | return rc; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 734 | } |
| 735 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 736 | static void device_free_tx_bufs(struct vnt_private *pDevice) |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 737 | { |
Malcolm Priestley | dcdf1d0 | 2013-08-27 12:41:50 +0100 | [diff] [blame] | 738 | struct vnt_usb_send_context *pTxContext; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 739 | int ii; |
| 740 | |
| 741 | for (ii = 0; ii < pDevice->cbTD; ii++) { |
| 742 | |
| 743 | pTxContext = pDevice->apTD[ii]; |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 744 | /* deallocate URBs */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 745 | if (pTxContext->pUrb) { |
Jim Lieb | dad72fe | 2009-08-12 14:54:14 -0700 | [diff] [blame] | 746 | usb_kill_urb(pTxContext->pUrb); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 747 | usb_free_urb(pTxContext->pUrb); |
| 748 | } |
Ilia Mirkin | 1d5c536 | 2011-03-13 00:29:15 -0500 | [diff] [blame] | 749 | kfree(pTxContext); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 750 | } |
| 751 | return; |
| 752 | } |
| 753 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 754 | static void device_free_rx_bufs(struct vnt_private *pDevice) |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 755 | { |
Malcolm Priestley | 115cac2 | 2013-08-28 21:12:35 +0100 | [diff] [blame] | 756 | struct vnt_rcb *pRCB; |
| 757 | int ii; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 758 | |
| 759 | for (ii = 0; ii < pDevice->cbRD; ii++) { |
| 760 | |
| 761 | pRCB = pDevice->apRCB[ii]; |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 762 | /* deallocate URBs */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 763 | if (pRCB->pUrb) { |
Jim Lieb | dad72fe | 2009-08-12 14:54:14 -0700 | [diff] [blame] | 764 | usb_kill_urb(pRCB->pUrb); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 765 | usb_free_urb(pRCB->pUrb); |
| 766 | } |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 767 | /* deallocate skb */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 768 | if (pRCB->skb) |
| 769 | dev_kfree_skb(pRCB->skb); |
| 770 | } |
Ilia Mirkin | 1d5c536 | 2011-03-13 00:29:15 -0500 | [diff] [blame] | 771 | kfree(pDevice->pRCBMem); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 772 | |
| 773 | return; |
| 774 | } |
| 775 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 776 | static void usb_device_reset(struct vnt_private *pDevice) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 777 | { |
| 778 | int status; |
| 779 | status = usb_reset_device(pDevice->usb); |
| 780 | if (status) |
| 781 | printk("usb_device_reset fail status=%d\n",status); |
| 782 | return ; |
| 783 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 784 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 785 | static void device_free_int_bufs(struct vnt_private *pDevice) |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 786 | { |
Ilia Mirkin | 1d5c536 | 2011-03-13 00:29:15 -0500 | [diff] [blame] | 787 | kfree(pDevice->intBuf.pDataBuf); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 788 | return; |
| 789 | } |
| 790 | |
Andres More | dfdcc42 | 2013-02-12 20:36:28 -0500 | [diff] [blame] | 791 | static bool device_alloc_bufs(struct vnt_private *pDevice) |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 792 | { |
Malcolm Priestley | dcdf1d0 | 2013-08-27 12:41:50 +0100 | [diff] [blame] | 793 | struct vnt_usb_send_context *pTxContext; |
Malcolm Priestley | 115cac2 | 2013-08-28 21:12:35 +0100 | [diff] [blame] | 794 | struct vnt_rcb *pRCB; |
| 795 | int ii; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 796 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 797 | for (ii = 0; ii < pDevice->cbTD; ii++) { |
| 798 | |
Malcolm Priestley | dcdf1d0 | 2013-08-27 12:41:50 +0100 | [diff] [blame] | 799 | pTxContext = kmalloc(sizeof(struct vnt_usb_send_context), GFP_KERNEL); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 800 | if (pTxContext == NULL) { |
| 801 | DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate tx usb context failed\n", pDevice->dev->name); |
| 802 | goto free_tx; |
| 803 | } |
| 804 | pDevice->apTD[ii] = pTxContext; |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 805 | pTxContext->pDevice = (void *) pDevice; |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 806 | /* allocate URBs */ |
Jim Lieb | dad72fe | 2009-08-12 14:54:14 -0700 | [diff] [blame] | 807 | pTxContext->pUrb = usb_alloc_urb(0, GFP_ATOMIC); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 808 | if (pTxContext->pUrb == NULL) { |
| 809 | DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "alloc tx urb failed\n"); |
| 810 | goto free_tx; |
| 811 | } |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 812 | pTxContext->bBoolInUse = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 813 | } |
| 814 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 815 | /* allocate RCB mem */ |
Malcolm Priestley | 115cac2 | 2013-08-28 21:12:35 +0100 | [diff] [blame] | 816 | pDevice->pRCBMem = kzalloc((sizeof(struct vnt_rcb) * pDevice->cbRD), |
| 817 | GFP_KERNEL); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 818 | if (pDevice->pRCBMem == NULL) { |
| 819 | DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : alloc rx usb context failed\n", pDevice->dev->name); |
| 820 | goto free_tx; |
| 821 | } |
| 822 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 823 | pDevice->FirstRecvFreeList = NULL; |
| 824 | pDevice->LastRecvFreeList = NULL; |
| 825 | pDevice->FirstRecvMngList = NULL; |
| 826 | pDevice->LastRecvMngList = NULL; |
| 827 | pDevice->NumRecvFreeList = 0; |
Malcolm Priestley | 115cac2 | 2013-08-28 21:12:35 +0100 | [diff] [blame] | 828 | |
| 829 | pRCB = (struct vnt_rcb *)pDevice->pRCBMem; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 830 | |
| 831 | for (ii = 0; ii < pDevice->cbRD; ii++) { |
| 832 | |
| 833 | pDevice->apRCB[ii] = pRCB; |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 834 | pRCB->pDevice = (void *) pDevice; |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 835 | /* allocate URBs */ |
Jim Lieb | dad72fe | 2009-08-12 14:54:14 -0700 | [diff] [blame] | 836 | pRCB->pUrb = usb_alloc_urb(0, GFP_ATOMIC); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 837 | |
| 838 | if (pRCB->pUrb == NULL) { |
| 839 | DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx urb\n"); |
| 840 | goto free_rx_tx; |
| 841 | } |
| 842 | pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); |
| 843 | if (pRCB->skb == NULL) { |
| 844 | DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx skb\n"); |
| 845 | goto free_rx_tx; |
| 846 | } |
| 847 | pRCB->skb->dev = pDevice->dev; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 848 | pRCB->bBoolInUse = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 849 | EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB); |
| 850 | pDevice->NumRecvFreeList++; |
| 851 | pRCB++; |
| 852 | } |
| 853 | |
Jim Lieb | dad72fe | 2009-08-12 14:54:14 -0700 | [diff] [blame] | 854 | pDevice->pControlURB = usb_alloc_urb(0, GFP_ATOMIC); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 855 | if (pDevice->pControlURB == NULL) { |
| 856 | DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc control urb\n"); |
| 857 | goto free_rx_tx; |
| 858 | } |
| 859 | |
Jim Lieb | dad72fe | 2009-08-12 14:54:14 -0700 | [diff] [blame] | 860 | pDevice->pInterruptURB = usb_alloc_urb(0, GFP_ATOMIC); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 861 | if (pDevice->pInterruptURB == NULL) { |
| 862 | DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int urb\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 863 | usb_free_urb(pDevice->pControlURB); |
| 864 | goto free_rx_tx; |
| 865 | } |
| 866 | |
| 867 | pDevice->intBuf.pDataBuf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL); |
| 868 | if (pDevice->intBuf.pDataBuf == NULL) { |
| 869 | DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int buf\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 870 | usb_free_urb(pDevice->pControlURB); |
| 871 | usb_free_urb(pDevice->pInterruptURB); |
| 872 | goto free_rx_tx; |
| 873 | } |
| 874 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 875 | return true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 876 | |
| 877 | free_rx_tx: |
| 878 | device_free_rx_bufs(pDevice); |
| 879 | |
| 880 | free_tx: |
| 881 | device_free_tx_bufs(pDevice); |
| 882 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 883 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 884 | } |
| 885 | |
Andres More | dfdcc42 | 2013-02-12 20:36:28 -0500 | [diff] [blame] | 886 | static bool device_init_defrag_cb(struct vnt_private *pDevice) |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 887 | { |
| 888 | int i; |
| 889 | PSDeFragControlBlock pDeF; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 890 | |
| 891 | /* Init the fragment ctl entries */ |
| 892 | for (i = 0; i < CB_MAX_RX_FRAG; i++) { |
| 893 | pDeF = &(pDevice->sRxDFCB[i]); |
| 894 | if (!device_alloc_frag_buf(pDevice, pDeF)) { |
| 895 | DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n", |
| 896 | pDevice->dev->name); |
| 897 | goto free_frag; |
Joe Perches | 9fc8602 | 2011-04-10 14:31:32 -0700 | [diff] [blame] | 898 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 899 | } |
| 900 | pDevice->cbDFCB = CB_MAX_RX_FRAG; |
| 901 | pDevice->cbFreeDFCB = pDevice->cbDFCB; |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 902 | return true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 903 | |
| 904 | free_frag: |
| 905 | device_free_frag_bufs(pDevice); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 906 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 907 | } |
| 908 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 909 | static void device_free_frag_bufs(struct vnt_private *pDevice) |
| 910 | { |
| 911 | PSDeFragControlBlock pDeF; |
| 912 | int i; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 913 | |
| 914 | for (i = 0; i < CB_MAX_RX_FRAG; i++) { |
| 915 | |
| 916 | pDeF = &(pDevice->sRxDFCB[i]); |
| 917 | |
| 918 | if (pDeF->skb) |
| 919 | dev_kfree_skb(pDeF->skb); |
| 920 | } |
| 921 | } |
| 922 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 923 | int device_alloc_frag_buf(struct vnt_private *pDevice, |
| 924 | PSDeFragControlBlock pDeF) |
| 925 | { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 926 | |
| 927 | pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); |
| 928 | if (pDeF->skb == NULL) |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 929 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 930 | pDeF->skb->dev = pDevice->dev; |
| 931 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 932 | return true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 933 | } |
| 934 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 935 | static int device_open(struct net_device *dev) |
| 936 | { |
| 937 | struct vnt_private *pDevice = netdev_priv(dev); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 938 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 939 | pDevice->fWPA_Authened = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 940 | |
| 941 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n"); |
| 942 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 943 | pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS; |
| 944 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 945 | if (device_alloc_bufs(pDevice) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 946 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n"); |
| 947 | return -ENOMEM; |
| 948 | } |
| 949 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 950 | if (device_init_defrag_cb(pDevice)== false) { |
Justin P. Mattock | a0a1f61 | 2012-08-26 08:16:43 -0700 | [diff] [blame] | 951 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragment cb fail \n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 952 | goto free_rx_tx; |
| 953 | } |
| 954 | |
| 955 | MP_CLEAR_FLAG(pDevice, fMP_DISCONNECTED); |
| 956 | MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS); |
| 957 | MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES); |
| 958 | MP_SET_FLAG(pDevice, fMP_POST_READS); |
| 959 | MP_SET_FLAG(pDevice, fMP_POST_WRITES); |
| 960 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 961 | /* read config file */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 962 | Read_config_file(pDevice); |
| 963 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 964 | if (device_init_registers(pDevice, DEVICE_INIT_COLD) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 965 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n"); |
| 966 | goto free_all; |
| 967 | } |
| 968 | |
| 969 | device_set_multi(pDevice->dev); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 970 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 971 | /* init for key management */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 972 | KeyvInitTable(pDevice,&pDevice->sKey); |
Malcolm Priestley | 14c5ef5 | 2013-01-17 23:19:37 +0000 | [diff] [blame] | 973 | memcpy(pDevice->vnt_mgmt.abyMACAddr, |
| 974 | pDevice->abyCurrentNetAddr, ETH_ALEN); |
Andres More | 9a0e756 | 2010-04-13 21:54:48 -0300 | [diff] [blame] | 975 | memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 976 | pDevice->bStopTx0Pkt = false; |
| 977 | pDevice->bStopDataPkt = false; |
| 978 | pDevice->bRoaming = false; |
| 979 | pDevice->bIsRoaming = false; |
| 980 | pDevice->bEnableRoaming = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 981 | if (pDevice->bDiversityRegCtlON) { |
| 982 | device_init_diversity_timer(pDevice); |
| 983 | } |
| 984 | |
| 985 | vMgrObjectInit(pDevice); |
| 986 | tasklet_init(&pDevice->RxMngWorkItem, (void *)RXvMngWorkItem, (unsigned long)pDevice); |
| 987 | tasklet_init(&pDevice->ReadWorkItem, (void *)RXvWorkItem, (unsigned long)pDevice); |
| 988 | tasklet_init(&pDevice->EventWorkItem, (void *)INTvWorkItem, (unsigned long)pDevice); |
Malcolm Priestley | bd9a6db | 2013-09-27 16:51:13 +0100 | [diff] [blame^] | 989 | |
| 990 | schedule_delayed_work(&pDevice->second_callback_work, HZ); |
| 991 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 992 | pDevice->int_interval = 100; /* max 100 microframes */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 993 | pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; |
| 994 | |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 995 | pDevice->bIsRxWorkItemQueued = true; |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 996 | pDevice->fKillEventPollingThread = false; |
| 997 | pDevice->bEventAvailable = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 998 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 999 | pDevice->bWPADEVUp = false; |
| 1000 | pDevice->bwextstep0 = false; |
| 1001 | pDevice->bwextstep1 = false; |
| 1002 | pDevice->bwextstep2 = false; |
| 1003 | pDevice->bwextstep3 = false; |
| 1004 | pDevice->bWPASuppWextEnabled = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1005 | pDevice->byReAssocCount = 0; |
| 1006 | |
| 1007 | RXvWorkItem(pDevice); |
| 1008 | INTvWorkItem(pDevice); |
| 1009 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1010 | /* if WEP key already set by iwconfig but device not yet open */ |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1011 | if ((pDevice->bEncryptionEnable == true) && (pDevice->bTransmitKey == true)) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1012 | spin_lock_irq(&pDevice->lock); |
| 1013 | KeybSetDefaultKey( pDevice, |
| 1014 | &(pDevice->sKey), |
| 1015 | pDevice->byKeyIndex | (1 << 31), |
| 1016 | pDevice->uKeyLength, |
| 1017 | NULL, |
| 1018 | pDevice->abyKey, |
| 1019 | KEY_CTL_WEP |
| 1020 | ); |
| 1021 | spin_unlock_irq(&pDevice->lock); |
| 1022 | pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; |
| 1023 | } |
| 1024 | |
Malcolm Priestley | 14c5ef5 | 2013-01-17 23:19:37 +0000 | [diff] [blame] | 1025 | if (pDevice->vnt_mgmt.eConfigMode == WMAC_CONFIG_AP) |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 1026 | bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL); |
Malcolm Priestley | 14c5ef5 | 2013-01-17 23:19:37 +0000 | [diff] [blame] | 1027 | else |
| 1028 | bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1029 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1030 | netif_stop_queue(pDevice->dev); |
| 1031 | pDevice->flags |= DEVICE_FLAGS_OPENED; |
| 1032 | |
Malcolm Priestley | 179f823d | 2012-11-24 14:47:11 +0000 | [diff] [blame] | 1033 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success..\n"); |
| 1034 | return 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1035 | |
| 1036 | free_all: |
| 1037 | device_free_frag_bufs(pDevice); |
| 1038 | free_rx_tx: |
| 1039 | device_free_rx_bufs(pDevice); |
| 1040 | device_free_tx_bufs(pDevice); |
| 1041 | device_free_int_bufs(pDevice); |
Jim Lieb | dad72fe | 2009-08-12 14:54:14 -0700 | [diff] [blame] | 1042 | usb_kill_urb(pDevice->pControlURB); |
| 1043 | usb_kill_urb(pDevice->pInterruptURB); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1044 | usb_free_urb(pDevice->pControlURB); |
| 1045 | usb_free_urb(pDevice->pInterruptURB); |
| 1046 | |
| 1047 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open fail.. \n"); |
| 1048 | return -ENOMEM; |
| 1049 | } |
| 1050 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1051 | static int device_close(struct net_device *dev) |
| 1052 | { |
| 1053 | struct vnt_private *pDevice = netdev_priv(dev); |
| 1054 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
| 1055 | int uu; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1056 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1057 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1058 | if (pDevice == NULL) |
| 1059 | return -ENODEV; |
| 1060 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1061 | if (pDevice->bLinkPass) { |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 1062 | bScheduleCommand((void *) pDevice, WLAN_CMD_DISASSOCIATE, NULL); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1063 | mdelay(30); |
| 1064 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1065 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1066 | memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1067 | pMgmt->bShareKeyAlgorithm = false; |
| 1068 | pDevice->bEncryptionEnable = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1069 | pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; |
Andres More | 33d33e42 | 2010-05-19 23:50:00 -0300 | [diff] [blame] | 1070 | spin_lock_irq(&pDevice->lock); |
| 1071 | for (uu = 0; uu < MAX_KEY_TABLE; uu++) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1072 | MACvDisableKeyEntry(pDevice,uu); |
Andres More | 33d33e42 | 2010-05-19 23:50:00 -0300 | [diff] [blame] | 1073 | spin_unlock_irq(&pDevice->lock); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1074 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1075 | if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == false) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1076 | MACbShutdown(pDevice); |
| 1077 | } |
| 1078 | netif_stop_queue(pDevice->dev); |
| 1079 | MP_SET_FLAG(pDevice, fMP_DISCONNECTED); |
| 1080 | MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES); |
| 1081 | MP_CLEAR_FLAG(pDevice, fMP_POST_READS); |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1082 | pDevice->fKillEventPollingThread = true; |
Malcolm Priestley | 94488a7 | 2013-09-27 16:48:14 +0100 | [diff] [blame] | 1083 | |
| 1084 | cancel_delayed_work_sync(&pDevice->run_command_work); |
Malcolm Priestley | bd9a6db | 2013-09-27 16:51:13 +0100 | [diff] [blame^] | 1085 | cancel_delayed_work_sync(&pDevice->second_callback_work); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1086 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1087 | del_timer(&pDevice->sTimerTxData); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1088 | |
| 1089 | if (pDevice->bDiversityRegCtlON) { |
| 1090 | del_timer(&pDevice->TimerSQ3Tmax1); |
| 1091 | del_timer(&pDevice->TimerSQ3Tmax2); |
| 1092 | del_timer(&pDevice->TimerSQ3Tmax3); |
| 1093 | } |
| 1094 | tasklet_kill(&pDevice->RxMngWorkItem); |
| 1095 | tasklet_kill(&pDevice->ReadWorkItem); |
| 1096 | tasklet_kill(&pDevice->EventWorkItem); |
| 1097 | |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1098 | pDevice->bRoaming = false; |
| 1099 | pDevice->bIsRoaming = false; |
| 1100 | pDevice->bEnableRoaming = false; |
| 1101 | pDevice->bCmdRunning = false; |
| 1102 | pDevice->bLinkPass = false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1103 | memset(pMgmt->abyCurrBSSID, 0, 6); |
| 1104 | pMgmt->eCurrState = WMAC_STATE_IDLE; |
| 1105 | |
Malcolm Priestley | e3eb270 | 2013-09-22 19:48:54 +0100 | [diff] [blame] | 1106 | pDevice->flags &= ~DEVICE_FLAGS_OPENED; |
| 1107 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1108 | device_free_tx_bufs(pDevice); |
| 1109 | device_free_rx_bufs(pDevice); |
| 1110 | device_free_int_bufs(pDevice); |
| 1111 | device_free_frag_bufs(pDevice); |
| 1112 | |
Jim Lieb | dad72fe | 2009-08-12 14:54:14 -0700 | [diff] [blame] | 1113 | usb_kill_urb(pDevice->pControlURB); |
| 1114 | usb_kill_urb(pDevice->pInterruptURB); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1115 | usb_free_urb(pDevice->pControlURB); |
| 1116 | usb_free_urb(pDevice->pInterruptURB); |
| 1117 | |
| 1118 | BSSvClearNodeDBTable(pDevice, 0); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1119 | |
| 1120 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close2 \n"); |
| 1121 | |
| 1122 | return 0; |
| 1123 | } |
| 1124 | |
Bill Pemberton | 0d7fe14 | 2012-11-19 13:26:58 -0500 | [diff] [blame] | 1125 | static void vt6656_disconnect(struct usb_interface *intf) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1126 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1127 | struct vnt_private *device = usb_get_intfdata(intf); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1128 | |
Andres More | 6cda24f | 2010-06-22 20:43:39 -0300 | [diff] [blame] | 1129 | if (!device) |
| 1130 | return; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1131 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1132 | usb_set_intfdata(intf, NULL); |
Andres More | 6cda24f | 2010-06-22 20:43:39 -0300 | [diff] [blame] | 1133 | usb_put_dev(interface_to_usbdev(intf)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1134 | |
Andres More | 6cda24f | 2010-06-22 20:43:39 -0300 | [diff] [blame] | 1135 | device->flags |= DEVICE_FLAGS_UNPLUG; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1136 | |
Andres More | 6cda24f | 2010-06-22 20:43:39 -0300 | [diff] [blame] | 1137 | if (device->dev) { |
| 1138 | unregister_netdev(device->dev); |
Andres More | 6cda24f | 2010-06-22 20:43:39 -0300 | [diff] [blame] | 1139 | free_netdev(device->dev); |
| 1140 | } |
Malcolm Priestley | b3a6db9 | 2012-11-24 14:36:12 +0000 | [diff] [blame] | 1141 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1142 | } |
| 1143 | |
Andres More | e1669ed | 2010-07-12 13:10:27 -0300 | [diff] [blame] | 1144 | static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) |
| 1145 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1146 | struct vnt_private *pDevice = netdev_priv(dev); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1147 | |
Andres More | e1669ed | 2010-07-12 13:10:27 -0300 | [diff] [blame] | 1148 | spin_lock_irq(&pDevice->lock); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1149 | |
Andres More | e1669ed | 2010-07-12 13:10:27 -0300 | [diff] [blame] | 1150 | if (unlikely(pDevice->bStopTx0Pkt)) |
| 1151 | dev_kfree_skb_irq(skb); |
| 1152 | else |
| 1153 | vDMA0_tx_80211(pDevice, skb); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1154 | |
Andres More | e1669ed | 2010-07-12 13:10:27 -0300 | [diff] [blame] | 1155 | spin_unlock_irq(&pDevice->lock); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1156 | |
Andres More | e1669ed | 2010-07-12 13:10:27 -0300 | [diff] [blame] | 1157 | return NETDEV_TX_OK; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1158 | } |
| 1159 | |
Andres More | 529e5b3 | 2010-07-12 19:28:25 -0300 | [diff] [blame] | 1160 | static int device_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1161 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1162 | struct vnt_private *pDevice = netdev_priv(dev); |
Andres More | 529e5b3 | 2010-07-12 19:28:25 -0300 | [diff] [blame] | 1163 | struct net_device_stats *stats = &pDevice->stats; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1164 | |
Andres More | 529e5b3 | 2010-07-12 19:28:25 -0300 | [diff] [blame] | 1165 | spin_lock_irq(&pDevice->lock); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1166 | |
Andres More | 529e5b3 | 2010-07-12 19:28:25 -0300 | [diff] [blame] | 1167 | netif_stop_queue(dev); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1168 | |
Andres More | 529e5b3 | 2010-07-12 19:28:25 -0300 | [diff] [blame] | 1169 | if (!pDevice->bLinkPass) { |
| 1170 | dev_kfree_skb_irq(skb); |
| 1171 | goto out; |
| 1172 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1173 | |
Andres More | 529e5b3 | 2010-07-12 19:28:25 -0300 | [diff] [blame] | 1174 | if (pDevice->bStopDataPkt) { |
| 1175 | dev_kfree_skb_irq(skb); |
| 1176 | stats->tx_dropped++; |
| 1177 | goto out; |
| 1178 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1179 | |
Andres More | 529e5b3 | 2010-07-12 19:28:25 -0300 | [diff] [blame] | 1180 | if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb)) { |
| 1181 | if (netif_queue_stopped(dev)) |
| 1182 | netif_wake_queue(dev); |
| 1183 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1184 | |
Andres More | 529e5b3 | 2010-07-12 19:28:25 -0300 | [diff] [blame] | 1185 | out: |
| 1186 | spin_unlock_irq(&pDevice->lock); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1187 | |
Andres More | 529e5b3 | 2010-07-12 19:28:25 -0300 | [diff] [blame] | 1188 | return NETDEV_TX_OK; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1189 | } |
| 1190 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1191 | static unsigned const ethernet_polynomial = 0x04c11db7U; |
| 1192 | static inline u32 ether_crc(int length, unsigned char *data) |
| 1193 | { |
| 1194 | int crc = -1; |
| 1195 | |
| 1196 | while(--length >= 0) { |
| 1197 | unsigned char current_octet = *data++; |
| 1198 | int bit; |
| 1199 | for (bit = 0; bit < 8; bit++, current_octet >>= 1) { |
| 1200 | crc = (crc << 1) ^ |
| 1201 | ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0); |
| 1202 | } |
| 1203 | } |
| 1204 | return crc; |
| 1205 | } |
| 1206 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1207 | /* find out the start position of str2 from str1 */ |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 1208 | static unsigned char *kstrstr(const unsigned char *str1, |
| 1209 | const unsigned char *str2) { |
| 1210 | int str1_len = strlen(str1); |
| 1211 | int str2_len = strlen(str2); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1212 | |
| 1213 | while (str1_len >= str2_len) { |
| 1214 | str1_len--; |
| 1215 | if(memcmp(str1,str2,str2_len)==0) |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 1216 | return (unsigned char *) str1; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1217 | str1++; |
| 1218 | } |
| 1219 | return NULL; |
| 1220 | } |
| 1221 | |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 1222 | static int Config_FileGetParameter(unsigned char *string, |
| 1223 | unsigned char *dest, |
| 1224 | unsigned char *source) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1225 | { |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 1226 | unsigned char buf1[100]; |
| 1227 | unsigned char buf2[100]; |
| 1228 | unsigned char *start_p = NULL, *end_p = NULL, *tmp_p = NULL; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1229 | int ii; |
| 1230 | |
| 1231 | memset(buf1,0,100); |
| 1232 | strcat(buf1, string); |
| 1233 | strcat(buf1, "="); |
| 1234 | source+=strlen(buf1); |
| 1235 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1236 | /* find target string start point */ |
Joe Perches | bfbfeec | 2010-03-24 22:17:06 -0700 | [diff] [blame] | 1237 | start_p = kstrstr(source,buf1); |
| 1238 | if (start_p == NULL) |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1239 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1240 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1241 | /* check if current config line is marked by "#" */ |
Andres More | 33d33e42 | 2010-05-19 23:50:00 -0300 | [diff] [blame] | 1242 | for (ii = 1; ; ii++) { |
| 1243 | if (memcmp(start_p - ii, "\n", 1) == 0) |
| 1244 | break; |
| 1245 | if (memcmp(start_p - ii, "#", 1) == 0) |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1246 | return false; |
Andres More | 33d33e42 | 2010-05-19 23:50:00 -0300 | [diff] [blame] | 1247 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1248 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1249 | /* find target string end point */ |
Joe Perches | bfbfeec | 2010-03-24 22:17:06 -0700 | [diff] [blame] | 1250 | end_p = kstrstr(start_p,"\n"); |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1251 | if (end_p == NULL) { /* can't find "\n", but don't care */ |
| 1252 | end_p = start_p + strlen(start_p); /* no include "\n" */ |
| 1253 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1254 | |
| 1255 | memset(buf2,0,100); |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1256 | memcpy(buf2, start_p, end_p-start_p); /* get the target line */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1257 | buf2[end_p-start_p]='\0'; |
| 1258 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1259 | /* find value */ |
Joe Perches | bfbfeec | 2010-03-24 22:17:06 -0700 | [diff] [blame] | 1260 | start_p = kstrstr(buf2,"="); |
| 1261 | if (start_p == NULL) |
Andres More | e269fc2 | 2013-02-12 20:36:29 -0500 | [diff] [blame] | 1262 | return false; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1263 | memset(buf1,0,100); |
| 1264 | strcpy(buf1,start_p+1); |
| 1265 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1266 | /* except space */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1267 | tmp_p = buf1; |
| 1268 | while(*tmp_p != 0x00) { |
| 1269 | if(*tmp_p==' ') |
| 1270 | tmp_p++; |
| 1271 | else |
| 1272 | break; |
| 1273 | } |
| 1274 | |
| 1275 | memcpy(dest,tmp_p,strlen(tmp_p)); |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1276 | return true; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1277 | } |
| 1278 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1279 | /* if read fails, return NULL, or return data pointer */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1280 | static unsigned char *Config_FileOperation(struct vnt_private *pDevice) |
Andres More | cc856e6 | 2010-05-17 21:34:01 -0300 | [diff] [blame] | 1281 | { |
Al Viro | 7c51d17 | 2013-04-06 18:00:07 -0400 | [diff] [blame] | 1282 | unsigned char *buffer = kmalloc(1024, GFP_KERNEL); |
| 1283 | struct file *file; |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1284 | |
Al Viro | 7c51d17 | 2013-04-06 18:00:07 -0400 | [diff] [blame] | 1285 | if (!buffer) { |
| 1286 | printk("allocate mem for file fail?\n"); |
| 1287 | return NULL; |
| 1288 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1289 | |
Al Viro | 7c51d17 | 2013-04-06 18:00:07 -0400 | [diff] [blame] | 1290 | file = filp_open(CONFIG_PATH, O_RDONLY, 0); |
| 1291 | if (IS_ERR(file)) { |
| 1292 | kfree(buffer); |
| 1293 | printk("Config_FileOperation file Not exist\n"); |
| 1294 | return NULL; |
| 1295 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1296 | |
Al Viro | 7c51d17 | 2013-04-06 18:00:07 -0400 | [diff] [blame] | 1297 | if (kernel_read(file, 0, buffer, 1024) < 0) { |
| 1298 | printk("read file error?\n"); |
| 1299 | kfree(buffer); |
| 1300 | buffer = NULL; |
| 1301 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1302 | |
Al Viro | 7c51d17 | 2013-04-06 18:00:07 -0400 | [diff] [blame] | 1303 | fput(file); |
| 1304 | return buffer; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1305 | } |
| 1306 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1307 | /* return --->-1:fail; >=0:successful */ |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1308 | static int Read_config_file(struct vnt_private *pDevice) |
| 1309 | { |
| 1310 | int result = 0; |
| 1311 | unsigned char tmpbuffer[100]; |
| 1312 | unsigned char *buffer = NULL; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1313 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1314 | /* init config setting */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1315 | pDevice->config_file.ZoneType = -1; |
| 1316 | pDevice->config_file.eAuthenMode = -1; |
| 1317 | pDevice->config_file.eEncryptionStatus = -1; |
| 1318 | |
Joe Perches | bfbfeec | 2010-03-24 22:17:06 -0700 | [diff] [blame] | 1319 | buffer = Config_FileOperation(pDevice); |
| 1320 | if (buffer == NULL) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1321 | result =-1; |
| 1322 | return result; |
| 1323 | } |
| 1324 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1325 | /* get zonetype */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1326 | { |
| 1327 | memset(tmpbuffer,0,sizeof(tmpbuffer)); |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1328 | if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1329 | if(memcmp(tmpbuffer,"USA",3)==0) { |
| 1330 | pDevice->config_file.ZoneType=ZoneType_USA; |
| 1331 | } |
| 1332 | else if(memcmp(tmpbuffer,"JAPAN",5)==0) { |
| 1333 | pDevice->config_file.ZoneType=ZoneType_Japan; |
| 1334 | } |
| 1335 | else if(memcmp(tmpbuffer,"EUROPE",6)==0) { |
| 1336 | pDevice->config_file.ZoneType=ZoneType_Europe; |
| 1337 | } |
| 1338 | else { |
| 1339 | printk("Unknown Zonetype[%s]?\n",tmpbuffer); |
| 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1344 | /* get other parameter */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1345 | { |
| 1346 | memset(tmpbuffer,0,sizeof(tmpbuffer)); |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1347 | if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1348 | pDevice->config_file.eAuthenMode = (int) simple_strtol(tmpbuffer, NULL, 10); |
| 1349 | } |
| 1350 | |
| 1351 | memset(tmpbuffer,0,sizeof(tmpbuffer)); |
Andres More | 4e9b5e2 | 2013-02-12 20:36:30 -0500 | [diff] [blame] | 1352 | if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==true) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1353 | pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10); |
| 1354 | } |
| 1355 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1356 | |
| 1357 | kfree(buffer); |
| 1358 | return result; |
| 1359 | } |
| 1360 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1361 | static void device_set_multi(struct net_device *dev) |
| 1362 | { |
| 1363 | struct vnt_private *pDevice = netdev_priv(dev); |
| 1364 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
| 1365 | struct netdev_hw_addr *ha; |
| 1366 | u32 mc_filter[2]; |
| 1367 | int ii; |
| 1368 | u8 pbyData[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 1369 | u8 byTmpMode = 0; |
| 1370 | int rc; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1371 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1372 | spin_lock_irq(&pDevice->lock); |
| 1373 | rc = CONTROLnsRequestIn(pDevice, |
| 1374 | MESSAGE_TYPE_READ, |
| 1375 | MAC_REG_RCR, |
| 1376 | MESSAGE_REQUEST_MACREG, |
| 1377 | 1, |
| 1378 | &byTmpMode |
| 1379 | ); |
| 1380 | if (rc == 0) pDevice->byRxMode = byTmpMode; |
| 1381 | |
| 1382 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode in= %x\n", pDevice->byRxMode); |
| 1383 | |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1384 | if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1385 | DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name); |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1386 | /* unconditionally log net taps */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1387 | pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST); |
| 1388 | } |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 1389 | else if ((netdev_mc_count(dev) > pDevice->multicast_limit) || |
| 1390 | (dev->flags & IFF_ALLMULTI)) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1391 | CONTROLnsRequestOut(pDevice, |
| 1392 | MESSAGE_TYPE_WRITE, |
| 1393 | MAC_REG_MAR0, |
| 1394 | MESSAGE_REQUEST_MACREG, |
| 1395 | 8, |
| 1396 | pbyData |
| 1397 | ); |
| 1398 | pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST); |
| 1399 | } |
| 1400 | else { |
| 1401 | memset(mc_filter, 0, sizeof(mc_filter)); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1402 | netdev_for_each_mc_addr(ha, dev) { |
| 1403 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1404 | mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31)); |
| 1405 | } |
| 1406 | for (ii = 0; ii < 4; ii++) { |
Andres More | b902fbf | 2013-02-25 20:32:51 -0500 | [diff] [blame] | 1407 | MACvWriteMultiAddr(pDevice, ii, *((u8 *)&mc_filter[0] + ii)); |
| 1408 | MACvWriteMultiAddr(pDevice, ii+ 4, *((u8 *)&mc_filter[1] + ii)); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1409 | } |
| 1410 | pDevice->byRxMode &= ~(RCR_UNICAST); |
| 1411 | pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST); |
| 1412 | } |
| 1413 | |
| 1414 | if (pMgmt->eConfigMode == WMAC_CONFIG_AP) { |
Andres More | ec6e0f6 | 2013-01-31 18:23:07 -0500 | [diff] [blame] | 1415 | /* |
| 1416 | * If AP mode, don't enable RCR_UNICAST since HW only compares |
| 1417 | * addr1 with local MAC |
| 1418 | */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1419 | pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST); |
| 1420 | pDevice->byRxMode &= ~(RCR_UNICAST); |
| 1421 | } |
| 1422 | ControlvWriteByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, pDevice->byRxMode); |
| 1423 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode out= %x\n", pDevice->byRxMode); |
| 1424 | spin_unlock_irq(&pDevice->lock); |
| 1425 | |
| 1426 | } |
| 1427 | |
Malcolm Priestley | 7055a07 | 2012-11-24 14:44:29 +0000 | [diff] [blame] | 1428 | static struct net_device_stats *device_get_stats(struct net_device *dev) |
| 1429 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1430 | struct vnt_private *pDevice = netdev_priv(dev); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1431 | |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1432 | return &pDevice->stats; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1433 | } |
| 1434 | |
Malcolm Priestley | 7055a07 | 2012-11-24 14:44:29 +0000 | [diff] [blame] | 1435 | static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 1436 | { |
Malcolm Priestley | dd0a774 | 2012-12-10 21:59:10 +0000 | [diff] [blame] | 1437 | struct vnt_private *pDevice = netdev_priv(dev); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1438 | struct iwreq *wrq = (struct iwreq *) rq; |
Malcolm Priestley | 848ce51 | 2012-11-13 21:04:36 +0000 | [diff] [blame] | 1439 | int rc = 0; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1440 | |
Malcolm Priestley | 7055a07 | 2012-11-24 14:44:29 +0000 | [diff] [blame] | 1441 | switch (cmd) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1442 | |
Malcolm Priestley | 7055a07 | 2012-11-24 14:44:29 +0000 | [diff] [blame] | 1443 | case IOCTL_CMD_HOSTAPD: |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1444 | |
Malcolm Priestley | 7055a07 | 2012-11-24 14:44:29 +0000 | [diff] [blame] | 1445 | if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) |
| 1446 | rc = -EFAULT; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1447 | |
Forest Bond | c30d797 | 2010-04-17 11:03:38 -0400 | [diff] [blame] | 1448 | rc = vt6656_hostap_ioctl(pDevice, &wrq->u.data); |
Malcolm Priestley | 7055a07 | 2012-11-24 14:44:29 +0000 | [diff] [blame] | 1449 | break; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1450 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1451 | case SIOCETHTOOL: |
Malcolm Priestley | 7055a07 | 2012-11-24 14:44:29 +0000 | [diff] [blame] | 1452 | return ethtool_ioctl(dev, (void *) rq->ifr_data); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1453 | |
Malcolm Priestley | 7055a07 | 2012-11-24 14:44:29 +0000 | [diff] [blame] | 1454 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1455 | |
Malcolm Priestley | 7055a07 | 2012-11-24 14:44:29 +0000 | [diff] [blame] | 1456 | return rc; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1457 | } |
| 1458 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1459 | static int ethtool_ioctl(struct net_device *dev, void *useraddr) |
| 1460 | { |
| 1461 | u32 ethcmd; |
| 1462 | |
| 1463 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
| 1464 | return -EFAULT; |
| 1465 | |
| 1466 | switch (ethcmd) { |
| 1467 | case ETHTOOL_GDRVINFO: { |
| 1468 | struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO}; |
| 1469 | strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1); |
| 1470 | strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1); |
| 1471 | if (copy_to_user(useraddr, &info, sizeof(info))) |
| 1472 | return -EFAULT; |
| 1473 | return 0; |
| 1474 | } |
| 1475 | |
| 1476 | } |
| 1477 | |
| 1478 | return -EOPNOTSUPP; |
| 1479 | } |
| 1480 | |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 1481 | MODULE_DEVICE_TABLE(usb, vt6656_table); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1482 | |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 1483 | static struct usb_driver vt6656_driver = { |
| 1484 | .name = DEVICE_NAME, |
| 1485 | .probe = vt6656_probe, |
| 1486 | .disconnect = vt6656_disconnect, |
| 1487 | .id_table = vt6656_table, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1488 | #ifdef CONFIG_PM |
Andres More | 26e5b65 | 2010-04-13 19:43:07 -0300 | [diff] [blame] | 1489 | .suspend = vt6656_suspend, |
| 1490 | .resume = vt6656_resume, |
| 1491 | #endif /* CONFIG_PM */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1492 | }; |
| 1493 | |
Greg Kroah-Hartman | bac2c12 | 2011-11-18 09:42:11 -0800 | [diff] [blame] | 1494 | module_usb_driver(vt6656_driver); |