Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: vt6656: Remove unused driver

Forest Bond contributed this driver in 2009.

The following reasons lead to the removal:
- This driver generates maintenance workload
- This driver has a maximum 54MBit/s as it supports only 802.11 b/g.
Peak throughput is 3MBytes/s.
- ping times can be 17ms are often above 500ms and worst case 22 seconds.
One other user does not see such long ping times using a rasperry pi.

I suggest deleting the driver as it no longer meets current expectations
for throuput.

Link: https://lore.kernel.org/linux-staging/d18e714d-787f-4d30-a32f-4b0f55d2f5be@gmail.com/T/#t
Signed-off-by: Philipp Hortmann <philipp.g.hortmann@gmail.com>
Link: https://lore.kernel.org/r/20241012164932.26390-1-philipp.g.hortmann@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Philipp Hortmann and committed by
Greg Kroah-Hartman
f6670bae 90003c78

-5849
-5
MAINTAINERS
··· 21982 21982 S: Maintained 21983 21983 F: drivers/staging/sm750fb/ 21984 21984 21985 - STAGING - VIA VT665X DRIVERS 21986 - M: Philipp Hortmann <philipp.g.hortmann@gmail.com> 21987 - S: Odd Fixes 21988 - F: drivers/staging/vt665?/ 21989 - 21990 21985 STAGING SUBSYSTEM 21991 21986 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 21992 21987 L: linux-staging@lists.linux.dev
-2
drivers/staging/Kconfig
··· 32 32 33 33 source "drivers/staging/octeon/Kconfig" 34 34 35 - source "drivers/staging/vt6656/Kconfig" 36 - 37 35 source "drivers/staging/iio/Kconfig" 38 36 39 37 source "drivers/staging/sm750fb/Kconfig"
-1
drivers/staging/Makefile
··· 6 6 obj-$(CONFIG_RTL8723BS) += rtl8723bs/ 7 7 obj-$(CONFIG_R8712U) += rtl8712/ 8 8 obj-$(CONFIG_OCTEON_ETHERNET) += octeon/ 9 - obj-$(CONFIG_VT6656) += vt6656/ 10 9 obj-$(CONFIG_VME_BUS) += vme_user/ 11 10 obj-$(CONFIG_IIO) += iio/ 12 11 obj-$(CONFIG_FB_SM750) += sm750fb/
-7
drivers/staging/vt6656/Kconfig
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - config VT6656 3 - tristate "VIA Technologies VT6656 support" 4 - depends on MAC80211 && USB && WLAN && m 5 - select FW_LOADER 6 - help 7 - This is a vendor-written driver for VIA VT6656.
-15
drivers/staging/vt6656/Makefile
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - 3 - vt6656_stage-y += main_usb.o \ 4 - card.o \ 5 - mac.o \ 6 - baseband.o \ 7 - wcmd.o\ 8 - rxtx.o \ 9 - power.o \ 10 - key.o \ 11 - rf.o \ 12 - usbpipe.o \ 13 - channel.o 14 - 15 - obj-$(CONFIG_VT6656) += vt6656_stage.o
-17
drivers/staging/vt6656/TODO
··· 1 - TODO: 2 - - remove __cplusplus ifdefs -- done 3 - - remove kernel version compatibility wrappers 4 - - remove support for older wireless extensions 5 - - prepare for merge with vt6655 driver: 6 - - remove PRINT_K() macro 7 - - split rf.c 8 - - abstract VT3184 chipset specific code 9 - - add common vt665x infrastructure 10 - - kill ttype.h -- done 11 - - switch to use MAC80211 12 - - use kernel coding style 13 - - sparse fixes 14 - - integrate with drivers/net/wireless 15 - 16 - Please send any patches to Greg Kroah-Hartman <greg@kroah.com> 17 - and Philipp Hortmann <philipp.g.hortmann@gmail.com>.
-455
drivers/staging/vt6656/baseband.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Implement functions to access baseband 7 - * 8 - * Author: Jerry Chen 9 - * 10 - * Date: Jun. 5, 2002 11 - * 12 - * Functions: 13 - * vnt_get_frame_time - Calculate data frame transmitting time 14 - * vnt_get_phy_field - Calculate PhyLength, PhyService and Phy 15 - * Signal parameter for baseband Tx 16 - * vnt_vt3184_init - VIA VT3184 baseband chip init code 17 - * 18 - * Revision History: 19 - * 20 - * 21 - */ 22 - 23 - #include <linux/bits.h> 24 - #include <linux/errno.h> 25 - #include <linux/kernel.h> 26 - #include "device.h" 27 - #include "mac.h" 28 - #include "baseband.h" 29 - #include "rf.h" 30 - #include "usbpipe.h" 31 - 32 - static const u8 vnt_vt3184_agc[] = { 33 - 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x06, 0x06, 34 - 0x08, 0x08, 0x0a, 0x0a, 0x0c, 0x0c, 0x0e, 0x0e, /* 0x0f */ 35 - 0x10, 0x10, 0x12, 0x12, 0x14, 0x14, 0x16, 0x16, 36 - 0x18, 0x18, 0x1a, 0x1a, 0x1c, 0x1c, 0x1e, 0x1e, /* 0x1f */ 37 - 0x20, 0x20, 0x22, 0x22, 0x24, 0x24, 0x26, 0x26, 38 - 0x28, 0x28, 0x2a, 0x2a, 0x2c, 0x2c, 0x2e, 0x2e, /* 0x2f */ 39 - 0x30, 0x30, 0x32, 0x32, 0x34, 0x34, 0x36, 0x36, 40 - 0x38, 0x38, 0x3a, 0x3a, 0x3c, 0x3c, 0x3e, 0x3e /* 0x3f */ 41 - }; 42 - 43 - static u8 vnt_vt3184_al2230[] = { 44 - 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 45 - 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */ 46 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 - 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */ 48 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 49 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */ 50 - 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 51 - 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */ 52 - 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09, 53 - 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */ 54 - 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55 - 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */ 56 - 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a, 57 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */ 58 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */ 60 - 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 61 - 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */ 62 - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb, 63 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */ 64 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 65 - 0x18, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x18, /* 0xaf */ 66 - 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2, 67 - 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */ 68 - 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x0e, 0x0a, 69 - 0x0e, 0x00, 0x82, 0xa7, 0x3c, 0x10, 0x30, 0x05, /* 0xcf */ 70 - 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a, 71 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */ 72 - 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x12, 73 - 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x05, /* 0xef */ 74 - 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 75 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */ 76 - }; 77 - 78 - /* {{RobertYu:20060515, new BB setting for VT3226D0 */ 79 - static const u8 vnt_vt3184_vt3226d0[] = { 80 - 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 81 - 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */ 82 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 83 - 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */ 84 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 85 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */ 86 - 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 87 - 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */ 88 - 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09, 89 - 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */ 90 - 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 91 - 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */ 92 - 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a, 93 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */ 94 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 95 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */ 96 - 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 97 - 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */ 98 - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb, 99 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */ 100 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 101 - 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, /* 0xaf */ 102 - 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2, 103 - 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */ 104 - 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x10, 0x0a, 105 - 0x0e, 0x00, 0x84, 0xa7, 0x3c, 0x10, 0x24, 0x05, /* 0xcf */ 106 - 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a, 107 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */ 108 - 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 109 - 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x08, /* 0xef */ 110 - 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 111 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */ 112 - }; 113 - 114 - struct vnt_threshold { 115 - u8 bb_pre_ed_rssi; 116 - u8 cr_201; 117 - u8 cr_206; 118 - }; 119 - 120 - static const struct vnt_threshold al2230_vnt_threshold[] = { 121 - {0, 0x00, 0x30}, /* Max sensitivity */ 122 - {68, 0x00, 0x36}, 123 - {67, 0x00, 0x43}, 124 - {66, 0x00, 0x51}, 125 - {65, 0x00, 0x62}, 126 - {64, 0x00, 0x79}, 127 - {63, 0x00, 0x93}, 128 - {62, 0x00, 0xb9}, 129 - {61, 0x00, 0xe3}, 130 - {60, 0x01, 0x18}, 131 - {59, 0x01, 0x54}, 132 - {58, 0x01, 0xa0}, 133 - {57, 0x02, 0x20}, 134 - {56, 0x02, 0xa0}, 135 - {55, 0x03, 0x00}, 136 - {53, 0x06, 0x00}, 137 - {51, 0x09, 0x00}, 138 - {49, 0x0e, 0x00}, 139 - {47, 0x15, 0x00}, 140 - {46, 0x1a, 0x00}, 141 - {45, 0xff, 0x00} 142 - }; 143 - 144 - static const struct vnt_threshold vt3226_vnt_threshold[] = { 145 - {0, 0x00, 0x24}, /* Max sensitivity */ 146 - {68, 0x00, 0x2d}, 147 - {67, 0x00, 0x36}, 148 - {66, 0x00, 0x43}, 149 - {65, 0x00, 0x52}, 150 - {64, 0x00, 0x68}, 151 - {63, 0x00, 0x80}, 152 - {62, 0x00, 0x9c}, 153 - {61, 0x00, 0xc0}, 154 - {60, 0x00, 0xea}, 155 - {59, 0x01, 0x30}, 156 - {58, 0x01, 0x70}, 157 - {57, 0x01, 0xb0}, 158 - {56, 0x02, 0x30}, 159 - {55, 0x02, 0xc0}, 160 - {53, 0x04, 0x00}, 161 - {51, 0x07, 0x00}, 162 - {49, 0x0a, 0x00}, 163 - {47, 0x11, 0x00}, 164 - {45, 0x18, 0x00}, 165 - {43, 0x26, 0x00}, 166 - {42, 0x36, 0x00}, 167 - {41, 0xff, 0x00} 168 - }; 169 - 170 - /* 171 - * Description: Set Antenna mode 172 - * 173 - * Parameters: 174 - * In: 175 - * priv - Device Structure 176 - * antenna_mode - Antenna Mode 177 - * Out: 178 - * none 179 - * 180 - * Return Value: none 181 - * 182 - */ 183 - int vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode) 184 - { 185 - switch (antenna_mode) { 186 - case ANT_TXA: 187 - case ANT_TXB: 188 - break; 189 - case ANT_RXA: 190 - priv->bb_rx_conf &= 0xFC; 191 - break; 192 - case ANT_RXB: 193 - priv->bb_rx_conf &= 0xFE; 194 - priv->bb_rx_conf |= 0x02; 195 - break; 196 - } 197 - 198 - return vnt_control_out(priv, MESSAGE_TYPE_SET_ANTMD, 199 - (u16)antenna_mode, 0, 0, NULL); 200 - } 201 - 202 - /* 203 - * Description: Set Antenna mode 204 - * 205 - * Parameters: 206 - * In: 207 - * pDevice - Device Structure 208 - * byAntennaMode - Antenna Mode 209 - * Out: 210 - * none 211 - * 212 - * Return Value: none 213 - * 214 - */ 215 - 216 - int vnt_vt3184_init(struct vnt_private *priv) 217 - { 218 - int ret; 219 - u16 length; 220 - u8 *addr = NULL; 221 - const u8 *c_addr; 222 - u8 data; 223 - 224 - ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0, MESSAGE_REQUEST_EEPROM, 225 - EEP_MAX_CONTEXT_SIZE, priv->eeprom); 226 - if (ret) 227 - goto end; 228 - 229 - priv->rf_type = priv->eeprom[EEP_OFS_RFTYPE]; 230 - 231 - dev_dbg(&priv->usb->dev, "RF Type %d\n", priv->rf_type); 232 - 233 - if ((priv->rf_type == RF_AL2230) || 234 - (priv->rf_type == RF_AL2230S)) { 235 - priv->bb_rx_conf = vnt_vt3184_al2230[10]; 236 - length = sizeof(vnt_vt3184_al2230); 237 - addr = vnt_vt3184_al2230; 238 - 239 - priv->bb_vga[0] = 0x1c; 240 - priv->bb_vga[1] = 0x10; 241 - priv->bb_vga[2] = 0x0; 242 - priv->bb_vga[3] = 0x0; 243 - 244 - } else if ((priv->rf_type == RF_VT3226) || 245 - (priv->rf_type == RF_VT3226D0)) { 246 - priv->bb_rx_conf = vnt_vt3184_vt3226d0[10]; 247 - length = sizeof(vnt_vt3184_vt3226d0); 248 - c_addr = vnt_vt3184_vt3226d0; 249 - 250 - priv->bb_vga[0] = 0x20; 251 - priv->bb_vga[1] = 0x10; 252 - priv->bb_vga[2] = 0x0; 253 - priv->bb_vga[3] = 0x0; 254 - 255 - /* Fix VT3226 DFC system timing issue */ 256 - ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2, 257 - SOFTPWRCTL_RFLEOPT); 258 - if (ret) 259 - goto end; 260 - } else { 261 - goto end; 262 - } 263 - 264 - if (addr) 265 - c_addr = addr; 266 - 267 - ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE, 268 - MESSAGE_REQUEST_BBREG, length, c_addr); 269 - if (ret) 270 - goto end; 271 - 272 - ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0, 273 - MESSAGE_REQUEST_BBAGC, 274 - sizeof(vnt_vt3184_agc), vnt_vt3184_agc); 275 - if (ret) 276 - goto end; 277 - 278 - if ((priv->rf_type == RF_VT3226) || 279 - (priv->rf_type == RF_VT3226D0)) { 280 - data = (priv->rf_type == RF_VT3226D0) ? 0x11 : 0x23; 281 - 282 - ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, 283 - MAC_REG_ITRTMSET, data); 284 - if (ret) 285 - goto end; 286 - 287 - ret = vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, BIT(0)); 288 - if (ret) 289 - goto end; 290 - } 291 - 292 - ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x04, 0x7f); 293 - if (ret) 294 - goto end; 295 - 296 - ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01); 297 - if (ret) 298 - goto end; 299 - 300 - ret = vnt_rf_table_download(priv); 301 - if (ret) 302 - goto end; 303 - 304 - /* Fix for TX USB resets from vendors driver */ 305 - ret = vnt_control_in(priv, MESSAGE_TYPE_READ, USB_REG4, 306 - MESSAGE_REQUEST_MEM, sizeof(data), &data); 307 - if (ret) 308 - goto end; 309 - 310 - data |= 0x2; 311 - 312 - ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, USB_REG4, 313 - MESSAGE_REQUEST_MEM, sizeof(data), &data); 314 - 315 - end: 316 - return ret; 317 - } 318 - 319 - /* 320 - * Description: Set ShortSlotTime mode 321 - * 322 - * Parameters: 323 - * In: 324 - * priv - Device Structure 325 - * Out: 326 - * none 327 - * 328 - * Return Value: none 329 - * 330 - */ 331 - int vnt_set_short_slot_time(struct vnt_private *priv) 332 - { 333 - int ret = 0; 334 - u8 bb_vga = 0; 335 - 336 - if (priv->short_slot_time) 337 - priv->bb_rx_conf &= 0xdf; 338 - else 339 - priv->bb_rx_conf |= 0x20; 340 - 341 - ret = vnt_control_in_u8(priv, MESSAGE_REQUEST_BBREG, 0xe7, &bb_vga); 342 - if (ret) 343 - return ret; 344 - 345 - if (bb_vga == priv->bb_vga[0]) 346 - priv->bb_rx_conf |= 0x20; 347 - 348 - return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, 349 - priv->bb_rx_conf); 350 - } 351 - 352 - int vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data) 353 - { 354 - int ret; 355 - 356 - ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xE7, data); 357 - if (ret) 358 - return ret; 359 - 360 - /* patch for 3253B0 Baseband with Cardbus module */ 361 - if (priv->short_slot_time) 362 - priv->bb_rx_conf &= 0xdf; /* 1101 1111 */ 363 - else 364 - priv->bb_rx_conf |= 0x20; /* 0010 0000 */ 365 - 366 - return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, 367 - priv->bb_rx_conf); 368 - } 369 - 370 - /* 371 - * Description: vnt_set_deep_sleep 372 - * 373 - * Parameters: 374 - * In: 375 - * priv - Device Structure 376 - * Out: 377 - * none 378 - * 379 - * Return Value: none 380 - * 381 - */ 382 - int vnt_set_deep_sleep(struct vnt_private *priv) 383 - { 384 - int ret = 0; 385 - 386 - /* CR12 */ 387 - ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x17); 388 - if (ret) 389 - return ret; 390 - 391 - /* CR13 */ 392 - return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0xB9); 393 - } 394 - 395 - int vnt_exit_deep_sleep(struct vnt_private *priv) 396 - { 397 - int ret = 0; 398 - 399 - /* CR12 */ 400 - ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x00); 401 - if (ret) 402 - return ret; 403 - 404 - /* CR13 */ 405 - return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01); 406 - } 407 - 408 - int vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning) 409 - { 410 - const struct vnt_threshold *threshold = NULL; 411 - u8 length; 412 - u8 cr_201, cr_206; 413 - u8 ed_inx; 414 - int ret; 415 - 416 - switch (priv->rf_type) { 417 - case RF_AL2230: 418 - case RF_AL2230S: 419 - threshold = al2230_vnt_threshold; 420 - length = ARRAY_SIZE(al2230_vnt_threshold); 421 - break; 422 - 423 - case RF_VT3226: 424 - case RF_VT3226D0: 425 - threshold = vt3226_vnt_threshold; 426 - length = ARRAY_SIZE(vt3226_vnt_threshold); 427 - break; 428 - } 429 - 430 - if (!threshold) 431 - return -EINVAL; 432 - 433 - for (ed_inx = scanning ? 0 : length - 1; ed_inx > 0; ed_inx--) { 434 - if (priv->bb_pre_ed_rssi <= threshold[ed_inx].bb_pre_ed_rssi) 435 - break; 436 - } 437 - 438 - cr_201 = threshold[ed_inx].cr_201; 439 - cr_206 = threshold[ed_inx].cr_206; 440 - 441 - if (ed_inx == priv->bb_pre_ed_index && !scanning) 442 - return 0; 443 - 444 - priv->bb_pre_ed_index = ed_inx; 445 - 446 - dev_dbg(&priv->usb->dev, "%s bb_pre_ed_rssi %d\n", 447 - __func__, priv->bb_pre_ed_rssi); 448 - 449 - ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xc9, cr_201); 450 - if (ret) 451 - return ret; 452 - 453 - return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xce, cr_206); 454 - } 455 -
-75
drivers/staging/vt6656/baseband.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Implement functions to access baseband 7 - * 8 - * Author: Jerry Chen 9 - * 10 - * Date: Jun. 5, 2002 11 - * 12 - * Revision History: 13 - * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec. 14 - * 08-26-2003 Kyle Hsu : Add defines of packet type and TX rate. 15 - */ 16 - 17 - #ifndef __BASEBAND_H__ 18 - #define __BASEBAND_H__ 19 - 20 - #include "device.h" 21 - 22 - #define PREAMBLE_LONG 0 23 - #define PREAMBLE_SHORT 1 24 - 25 - /* 26 - * Registers in the BASEBAND 27 - */ 28 - #define BB_MAX_CONTEXT_SIZE 256 29 - 30 - #define C_SIFS_A 16 /* usec */ 31 - #define C_SIFS_BG 10 32 - 33 - #define C_EIFS 80 /* usec */ 34 - 35 - #define C_SLOT_SHORT 9 /* usec */ 36 - #define C_SLOT_LONG 20 37 - 38 - #define C_CWMIN_A 15 /* slot time */ 39 - #define C_CWMIN_B 31 40 - 41 - #define C_CWMAX 1023 /* slot time */ 42 - 43 - /* 0:11A 1:11B 2:11G */ 44 - #define BB_TYPE_11A 0 45 - #define BB_TYPE_11B 1 46 - #define BB_TYPE_11G 2 47 - 48 - /* 0:11a, 1:11b, 2:11gb (only CCK in BasicRate), 3:11ga (OFDM in BasicRate) */ 49 - #define PK_TYPE_11A 0 50 - #define PK_TYPE_11B 1 51 - #define PK_TYPE_11GB 2 52 - #define PK_TYPE_11GA 3 53 - 54 - #define TOP_RATE_54M 0x80000000 55 - #define TOP_RATE_48M 0x40000000 56 - #define TOP_RATE_36M 0x20000000 57 - #define TOP_RATE_24M 0x10000000 58 - #define TOP_RATE_18M 0x08000000 59 - #define TOP_RATE_12M 0x04000000 60 - #define TOP_RATE_11M 0x02000000 61 - #define TOP_RATE_9M 0x01000000 62 - #define TOP_RATE_6M 0x00800000 63 - #define TOP_RATE_55M 0x00400000 64 - #define TOP_RATE_2M 0x00200000 65 - #define TOP_RATE_1M 0x00100000 66 - 67 - int vnt_set_short_slot_time(struct vnt_private *priv); 68 - int vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data); 69 - int vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode); 70 - int vnt_vt3184_init(struct vnt_private *priv); 71 - int vnt_set_deep_sleep(struct vnt_private *priv); 72 - int vnt_exit_deep_sleep(struct vnt_private *priv); 73 - int vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning); 74 - 75 - #endif /* __BASEBAND_H__ */
-456
drivers/staging/vt6656/card.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Provide functions to setup NIC operation mode 7 - * Functions: 8 - * vnt_set_rspinf - Set RSPINF 9 - * vnt_update_ifs - Update slotTime,SIFS,DIFS, and EIFS 10 - * vnt_update_top_rates - Update BasicTopRate 11 - * vnt_add_basic_rate - Add to BasicRateSet 12 - * vnt_ofdm_min_rate - Check if any OFDM rate is in BasicRateSet 13 - * vnt_get_tsf_offset - Calculate TSFOffset 14 - * vnt_get_next_tbtt - Calculate Next Beacon TSF counter 15 - * vnt_reset_next_tbtt - Set NIC Beacon time 16 - * vnt_update_next_tbtt - Sync. NIC Beacon time 17 - * vnt_radio_power_off - Turn Off NIC Radio Power 18 - * vnt_radio_power_on - Turn On NIC Radio Power 19 - * 20 - * Revision History: 21 - * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec. 22 - * 08-26-2003 Kyle Hsu: Modify the definition type of dwIoBase. 23 - * 09-01-2003 Bryan YC Fan: Add vnt_update_ifs(). 24 - * 25 - */ 26 - 27 - #include <linux/bitops.h> 28 - #include <linux/errno.h> 29 - #include "device.h" 30 - #include "card.h" 31 - #include "baseband.h" 32 - #include "mac.h" 33 - #include "desc.h" 34 - #include "rf.h" 35 - #include "power.h" 36 - #include "key.h" 37 - #include "usbpipe.h" 38 - 39 - /* const u16 cw_rxbcntsf_off[MAX_RATE] = 40 - * {17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3}; 41 - */ 42 - 43 - static const u16 cw_rxbcntsf_off[MAX_RATE] = { 44 - 192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3 45 - }; 46 - 47 - int vnt_set_channel(struct vnt_private *priv, u32 connection_channel) 48 - { 49 - int ret; 50 - 51 - if (connection_channel > CB_MAX_CHANNEL || !connection_channel) 52 - return -EINVAL; 53 - 54 - /* clear NAV */ 55 - vnt_mac_reg_bits_on(priv, MAC_REG_MACCR, MACCR_CLRNAV); 56 - 57 - /* Set Channel[7] = 0 to tell H/W channel is changing now. */ 58 - vnt_mac_reg_bits_off(priv, MAC_REG_CHANNEL, 59 - (BIT(7) | BIT(5) | BIT(4))); 60 - 61 - ret = vnt_control_out(priv, MESSAGE_TYPE_SELECT_CHANNEL, 62 - connection_channel, 0, 0, NULL); 63 - if (ret) 64 - return ret; 65 - 66 - return vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_CHANNEL, 67 - (u8)(connection_channel | 0x80)); 68 - } 69 - 70 - static const u8 vnt_rspinf_b_short_table[] = { 71 - 0x70, 0x00, 0x00, 0x00, 0x38, 0x00, 0x09, 0x00, 72 - 0x15, 0x00, 0x0a, 0x00, 0x0b, 0x00, 0x0b, 0x80 73 - }; 74 - 75 - static const u8 vnt_rspinf_b_long_table[] = { 76 - 0x70, 0x00, 0x00, 0x00, 0x38, 0x00, 0x01, 0x00, 77 - 0x15, 0x00, 0x02, 0x00, 0x0b, 0x00, 0x03, 0x80 78 - }; 79 - 80 - static const u8 vnt_rspinf_a_table[] = { 81 - 0x9b, 0x18, 0x9f, 0x10, 0x9a, 0x0a, 0x9e, 0x08, 0x99, 82 - 0x08, 0x9d, 0x04, 0x98, 0x04, 0x9c, 0x04, 0x9c, 0x04 83 - }; 84 - 85 - static const u8 vnt_rspinf_gb_table[] = { 86 - 0x8b, 0x1e, 0x8f, 0x16, 0x8a, 0x12, 0x8e, 0x0e, 0x89, 87 - 0x0e, 0x8d, 0x0a, 0x88, 0x0a, 0x8c, 0x0a, 0x8c, 0x0a 88 - }; 89 - 90 - int vnt_set_rspinf(struct vnt_private *priv, u8 bb_type) 91 - { 92 - const u8 *data; 93 - u16 len; 94 - int ret; 95 - 96 - if (priv->preamble_type) { 97 - data = vnt_rspinf_b_short_table; 98 - len = ARRAY_SIZE(vnt_rspinf_b_short_table); 99 - } else { 100 - data = vnt_rspinf_b_long_table; 101 - len = ARRAY_SIZE(vnt_rspinf_b_long_table); 102 - } 103 - 104 - /* RSPINF_b_1 to RSPINF_b_11 */ 105 - ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_RSPINF_B_1, 106 - MESSAGE_REQUEST_MACREG, len, data); 107 - if (ret) 108 - return ret; 109 - 110 - if (bb_type == BB_TYPE_11A) { 111 - data = vnt_rspinf_a_table; 112 - len = ARRAY_SIZE(vnt_rspinf_a_table); 113 - } else { 114 - data = vnt_rspinf_gb_table; 115 - len = ARRAY_SIZE(vnt_rspinf_gb_table); 116 - } 117 - 118 - /* RSPINF_a_6 to RSPINF_a_72 */ 119 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_RSPINF_A_6, 120 - MESSAGE_REQUEST_MACREG, len, data); 121 - } 122 - 123 - int vnt_update_ifs(struct vnt_private *priv) 124 - { 125 - u8 max_min = 0; 126 - u8 data[4]; 127 - int ret; 128 - 129 - if (priv->packet_type == PK_TYPE_11A) { 130 - priv->slot = C_SLOT_SHORT; 131 - priv->sifs = C_SIFS_A; 132 - priv->difs = C_SIFS_A + 2 * C_SLOT_SHORT; 133 - max_min = 4; 134 - } else { 135 - priv->sifs = C_SIFS_BG; 136 - 137 - if (priv->short_slot_time) { 138 - priv->slot = C_SLOT_SHORT; 139 - max_min = 4; 140 - } else { 141 - priv->slot = C_SLOT_LONG; 142 - max_min = 5; 143 - } 144 - 145 - priv->difs = C_SIFS_BG + 2 * priv->slot; 146 - } 147 - 148 - priv->eifs = C_EIFS; 149 - 150 - data[0] = (u8)priv->sifs; 151 - data[1] = (u8)priv->difs; 152 - data[2] = (u8)priv->eifs; 153 - data[3] = (u8)priv->slot; 154 - 155 - ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_SIFS, 156 - MESSAGE_REQUEST_MACREG, 4, &data[0]); 157 - if (ret) 158 - return ret; 159 - 160 - max_min |= 0xa0; 161 - 162 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_CWMAXMIN0, 163 - MESSAGE_REQUEST_MACREG, 1, &max_min); 164 - } 165 - 166 - void vnt_update_top_rates(struct vnt_private *priv) 167 - { 168 - int pos; 169 - 170 - pos = fls(priv->basic_rates & GENMASK(RATE_54M, RATE_6M)); 171 - priv->top_ofdm_basic_rate = pos ? (pos - 1) : RATE_24M; 172 - 173 - pos = fls(priv->basic_rates & GENMASK(RATE_11M, RATE_1M)); 174 - priv->top_cck_basic_rate = pos ? (pos - 1) : RATE_1M; 175 - } 176 - 177 - bool vnt_ofdm_min_rate(struct vnt_private *priv) 178 - { 179 - return priv->basic_rates & GENMASK(RATE_54M, RATE_6M) ? true : false; 180 - } 181 - 182 - u8 vnt_get_pkt_type(struct vnt_private *priv) 183 - { 184 - if (priv->bb_type == BB_TYPE_11A || priv->bb_type == BB_TYPE_11B) 185 - return (u8)priv->bb_type; 186 - else if (vnt_ofdm_min_rate(priv)) 187 - return PK_TYPE_11GA; 188 - return PK_TYPE_11GB; 189 - } 190 - 191 - /* 192 - * Description: Calculate TSF offset of two TSF input 193 - * Get TSF Offset from RxBCN's TSF and local TSF 194 - * 195 - * Parameters: 196 - * In: 197 - * rx_rate - rx rate. 198 - * tsf1 - Rx BCN's TSF 199 - * tsf2 - Local TSF 200 - * Out: 201 - * none 202 - * 203 - * Return Value: TSF Offset value 204 - * 205 - */ 206 - u64 vnt_get_tsf_offset(u8 rx_rate, u64 tsf1, u64 tsf2) 207 - { 208 - return tsf1 - tsf2 - (u64)cw_rxbcntsf_off[rx_rate % MAX_RATE]; 209 - } 210 - 211 - int vnt_adjust_tsf(struct vnt_private *priv, u8 rx_rate, 212 - u64 time_stamp, u64 local_tsf) 213 - { 214 - u64 tsf_offset = 0; 215 - u8 data[8]; 216 - 217 - tsf_offset = vnt_get_tsf_offset(rx_rate, time_stamp, local_tsf); 218 - 219 - data[0] = (u8)tsf_offset; 220 - data[1] = (u8)(tsf_offset >> 8); 221 - data[2] = (u8)(tsf_offset >> 16); 222 - data[3] = (u8)(tsf_offset >> 24); 223 - data[4] = (u8)(tsf_offset >> 32); 224 - data[5] = (u8)(tsf_offset >> 40); 225 - data[6] = (u8)(tsf_offset >> 48); 226 - data[7] = (u8)(tsf_offset >> 56); 227 - 228 - return vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT, 229 - MESSAGE_REQUEST_TSF, 0, 8, data); 230 - } 231 - 232 - /* 233 - * Description: Clear NIC TSF counter 234 - * Clear local TSF counter 235 - * 236 - * Parameters: 237 - * In: 238 - * priv - The adapter to be read 239 - * 240 - * Return Value: true if success; otherwise false 241 - * 242 - */ 243 - bool vnt_clear_current_tsf(struct vnt_private *priv) 244 - { 245 - vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST); 246 - 247 - priv->current_tsf = 0; 248 - 249 - return true; 250 - } 251 - 252 - /* 253 - * Description: Read NIC TSF counter 254 - * Get NEXTTBTT from adjusted TSF and Beacon Interval 255 - * 256 - * Parameters: 257 - * In: 258 - * tsf - Current TSF counter 259 - * beacon_interval - Beacon Interval 260 - * Out: 261 - * tsf - Current TSF counter 262 - * 263 - * Return Value: TSF value of next Beacon 264 - * 265 - */ 266 - u64 vnt_get_next_tbtt(u64 tsf, u16 beacon_interval) 267 - { 268 - u32 beacon_int; 269 - 270 - beacon_int = beacon_interval * 1024; 271 - 272 - /* Next TBTT = 273 - * ((local_current_TSF / beacon_interval) + 1) * beacon_interval 274 - */ 275 - if (beacon_int) { 276 - do_div(tsf, beacon_int); 277 - tsf += 1; 278 - tsf *= beacon_int; 279 - } 280 - 281 - return tsf; 282 - } 283 - 284 - int vnt_reset_next_tbtt(struct vnt_private *priv, u16 beacon_interval) 285 - { 286 - u64 next_tbtt = 0; 287 - u8 data[8]; 288 - 289 - vnt_clear_current_tsf(priv); 290 - 291 - next_tbtt = vnt_get_next_tbtt(next_tbtt, beacon_interval); 292 - 293 - data[0] = (u8)next_tbtt; 294 - data[1] = (u8)(next_tbtt >> 8); 295 - data[2] = (u8)(next_tbtt >> 16); 296 - data[3] = (u8)(next_tbtt >> 24); 297 - data[4] = (u8)(next_tbtt >> 32); 298 - data[5] = (u8)(next_tbtt >> 40); 299 - data[6] = (u8)(next_tbtt >> 48); 300 - data[7] = (u8)(next_tbtt >> 56); 301 - 302 - return vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT, 303 - MESSAGE_REQUEST_TBTT, 0, 8, data); 304 - } 305 - 306 - int vnt_update_next_tbtt(struct vnt_private *priv, u64 tsf, 307 - u16 beacon_interval) 308 - { 309 - u8 data[8]; 310 - int ret; 311 - 312 - tsf = vnt_get_next_tbtt(tsf, beacon_interval); 313 - 314 - data[0] = (u8)tsf; 315 - data[1] = (u8)(tsf >> 8); 316 - data[2] = (u8)(tsf >> 16); 317 - data[3] = (u8)(tsf >> 24); 318 - data[4] = (u8)(tsf >> 32); 319 - data[5] = (u8)(tsf >> 40); 320 - data[6] = (u8)(tsf >> 48); 321 - data[7] = (u8)(tsf >> 56); 322 - 323 - ret = vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT, 324 - MESSAGE_REQUEST_TBTT, 0, 8, data); 325 - if (ret) 326 - return ret; 327 - 328 - dev_dbg(&priv->usb->dev, "%s TBTT: %8llx\n", __func__, tsf); 329 - return 0; 330 - } 331 - 332 - /* 333 - * Description: Turn off Radio power 334 - * 335 - * Parameters: 336 - * In: 337 - * priv - The adapter to be turned off 338 - * Out: 339 - * none 340 - * 341 - * Return Value: true if success; otherwise false 342 - * 343 - */ 344 - int vnt_radio_power_off(struct vnt_private *priv) 345 - { 346 - int ret = 0; 347 - 348 - switch (priv->rf_type) { 349 - case RF_AL2230: 350 - case RF_AL2230S: 351 - case RF_VT3226: 352 - case RF_VT3226D0: 353 - ret = vnt_mac_reg_bits_off(priv, MAC_REG_SOFTPWRCTL, 354 - (SOFTPWRCTL_SWPE2 | 355 - SOFTPWRCTL_SWPE3)); 356 - break; 357 - } 358 - 359 - if (ret) 360 - goto end; 361 - 362 - ret = vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_RXON); 363 - if (ret) 364 - goto end; 365 - 366 - ret = vnt_set_deep_sleep(priv); 367 - if (ret) 368 - goto end; 369 - 370 - ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD); 371 - 372 - end: 373 - return ret; 374 - } 375 - 376 - /* 377 - * Description: Turn on Radio power 378 - * 379 - * Parameters: 380 - * In: 381 - * priv - The adapter to be turned on 382 - * Out: 383 - * none 384 - * 385 - * Return Value: true if success; otherwise false 386 - * 387 - */ 388 - int vnt_radio_power_on(struct vnt_private *priv) 389 - { 390 - int ret = 0; 391 - 392 - ret = vnt_exit_deep_sleep(priv); 393 - if (ret) 394 - return ret; 395 - 396 - ret = vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON); 397 - if (ret) 398 - return ret; 399 - 400 - switch (priv->rf_type) { 401 - case RF_AL2230: 402 - case RF_AL2230S: 403 - case RF_VT3226: 404 - case RF_VT3226D0: 405 - ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL, 406 - (SOFTPWRCTL_SWPE2 | 407 - SOFTPWRCTL_SWPE3)); 408 - if (ret) 409 - return ret; 410 - } 411 - 412 - return vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD); 413 - } 414 - 415 - int vnt_set_bss_mode(struct vnt_private *priv) 416 - { 417 - int ret; 418 - unsigned char type = priv->bb_type; 419 - unsigned char data = 0; 420 - unsigned char bb_vga_2_3 = 0x00; 421 - 422 - ret = vnt_mac_set_bb_type(priv, type); 423 - if (ret) 424 - return ret; 425 - 426 - priv->packet_type = vnt_get_pkt_type(priv); 427 - 428 - if (priv->bb_type == BB_TYPE_11A) { 429 - data = 0x03; 430 - bb_vga_2_3 = 0x10; 431 - } else if (priv->bb_type == BB_TYPE_11B) { 432 - data = 0x02; 433 - } else if (priv->bb_type == BB_TYPE_11G) { 434 - data = 0x08; 435 - } 436 - 437 - if (data) { 438 - ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 439 - 0x88, data); 440 - if (ret) 441 - return ret; 442 - } 443 - 444 - ret = vnt_update_ifs(priv); 445 - if (ret) 446 - return ret; 447 - 448 - ret = vnt_set_rspinf(priv, priv->bb_type); 449 - if (ret) 450 - return ret; 451 - 452 - priv->bb_vga[2] = bb_vga_2_3; 453 - priv->bb_vga[3] = bb_vga_2_3; 454 - 455 - return vnt_set_vga_gain_offset(priv, priv->bb_vga[0]); 456 - }
-44
drivers/staging/vt6656/card.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Provide functions to setup NIC operation mode 7 - * 8 - * Author: Tevin Chen 9 - * 10 - * Date: May 21, 1996 11 - * 12 - */ 13 - 14 - #ifndef __CARD_H__ 15 - #define __CARD_H__ 16 - #include "device.h" 17 - 18 - /* init card type */ 19 - 20 - #define CB_MAX_CHANNEL_24G 14 21 - #define CB_MAX_CHANNEL_5G 42 /* add channel9(5045MHz), 41==>42 */ 22 - #define CB_MAX_CHANNEL (CB_MAX_CHANNEL_24G + CB_MAX_CHANNEL_5G) 23 - 24 - struct vnt_private; 25 - 26 - int vnt_set_channel(struct vnt_private *priv, u32 connection_channel); 27 - int vnt_set_rspinf(struct vnt_private *priv, u8 bb_type); 28 - int vnt_update_ifs(struct vnt_private *priv); 29 - void vnt_update_top_rates(struct vnt_private *priv); 30 - bool vnt_ofdm_min_rate(struct vnt_private *priv); 31 - int vnt_adjust_tsf(struct vnt_private *priv, u8 rx_rate, 32 - u64 time_stamp, u64 local_tsf); 33 - bool vnt_clear_current_tsf(struct vnt_private *priv); 34 - int vnt_reset_next_tbtt(struct vnt_private *priv, u16 beacon_interval); 35 - int vnt_update_next_tbtt(struct vnt_private *priv, u64 tsf, 36 - u16 beacon_interval); 37 - u64 vnt_get_next_tbtt(u64 tsf, u16 beacon_interval); 38 - u64 vnt_get_tsf_offset(u8 rx_rate, u64 tsf1, u64 tsf2); 39 - int vnt_radio_power_off(struct vnt_private *priv); 40 - int vnt_radio_power_on(struct vnt_private *priv); 41 - u8 vnt_get_pkt_type(struct vnt_private *priv); 42 - int vnt_set_bss_mode(struct vnt_private *priv); 43 - 44 - #endif /* __CARD_H__ */
-77
drivers/staging/vt6656/channel.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Channel number mapping 7 - * 8 - * Author: Lucas Lin 9 - * 10 - * Date: Dec 24, 2004 11 - * 12 - * 13 - * 14 - * Revision History: 15 - * 01-18-2005 RobertYu: remove the for loop searching in 16 - * ChannelValid, change ChannelRuleTab 17 - * to lookup-type, reorder table items. 18 - * 19 - * 20 - */ 21 - 22 - #include "device.h" 23 - #include "channel.h" 24 - #include "rf.h" 25 - 26 - static struct ieee80211_rate vnt_rates_bg[] = { 27 - { .bitrate = 10, .hw_value = RATE_1M }, 28 - { .bitrate = 20, .hw_value = RATE_2M }, 29 - { .bitrate = 55, .hw_value = RATE_5M }, 30 - { .bitrate = 110, .hw_value = RATE_11M }, 31 - { .bitrate = 60, .hw_value = RATE_6M }, 32 - { .bitrate = 90, .hw_value = RATE_9M }, 33 - { .bitrate = 120, .hw_value = RATE_12M }, 34 - { .bitrate = 180, .hw_value = RATE_18M }, 35 - { .bitrate = 240, .hw_value = RATE_24M }, 36 - { .bitrate = 360, .hw_value = RATE_36M }, 37 - { .bitrate = 480, .hw_value = RATE_48M }, 38 - { .bitrate = 540, .hw_value = RATE_54M }, 39 - }; 40 - 41 - static struct ieee80211_channel vnt_channels_2ghz[] = { 42 - { .center_freq = 2412, .hw_value = 1 }, 43 - { .center_freq = 2417, .hw_value = 2 }, 44 - { .center_freq = 2422, .hw_value = 3 }, 45 - { .center_freq = 2427, .hw_value = 4 }, 46 - { .center_freq = 2432, .hw_value = 5 }, 47 - { .center_freq = 2437, .hw_value = 6 }, 48 - { .center_freq = 2442, .hw_value = 7 }, 49 - { .center_freq = 2447, .hw_value = 8 }, 50 - { .center_freq = 2452, .hw_value = 9 }, 51 - { .center_freq = 2457, .hw_value = 10 }, 52 - { .center_freq = 2462, .hw_value = 11 }, 53 - { .center_freq = 2467, .hw_value = 12 }, 54 - { .center_freq = 2472, .hw_value = 13 }, 55 - { .center_freq = 2484, .hw_value = 14 } 56 - }; 57 - 58 - static struct ieee80211_supported_band vnt_supported_2ghz_band = { 59 - .channels = vnt_channels_2ghz, 60 - .n_channels = ARRAY_SIZE(vnt_channels_2ghz), 61 - .bitrates = vnt_rates_bg, 62 - .n_bitrates = ARRAY_SIZE(vnt_rates_bg), 63 - }; 64 - 65 - void vnt_init_bands(struct vnt_private *priv) 66 - { 67 - struct ieee80211_channel *ch; 68 - int i; 69 - 70 - ch = vnt_channels_2ghz; 71 - for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) { 72 - ch[i].max_power = VNT_RF_MAX_POWER; 73 - ch[i].flags = IEEE80211_CHAN_NO_HT40; 74 - } 75 - priv->hw->wiphy->bands[NL80211_BAND_2GHZ] = 76 - &vnt_supported_2ghz_band; 77 - }
-21
drivers/staging/vt6656/channel.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Country Regulation Rules header file 7 - * 8 - * Author: Lucas Lin 9 - * 10 - * Date: Dec 23, 2004 11 - * 12 - */ 13 - 14 - #ifndef _CHANNEL_H_ 15 - #define _CHANNEL_H_ 16 - 17 - #include "device.h" 18 - 19 - void vnt_init_bands(struct vnt_private *priv); 20 - 21 - #endif /* _CHANNEL_H_ */
-91
drivers/staging/vt6656/desc.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose:The header file of descriptor 7 - * 8 - * Revision History: 9 - * 10 - * Author: Tevin Chen 11 - * 12 - * Date: May 21, 1996 13 - * 14 - */ 15 - 16 - #ifndef __DESC_H__ 17 - #define __DESC_H__ 18 - 19 - #include <linux/bits.h> 20 - #include <linux/types.h> 21 - #include <linux/mm.h> 22 - 23 - /* max transmit or receive buffer size */ 24 - #define CB_MAX_BUF_SIZE 2900U /* NOTE: must be multiple of 4 */ 25 - 26 - #define MAX_TOTAL_SIZE_WITH_ALL_HEADERS CB_MAX_BUF_SIZE 27 - 28 - #define MAX_INTERRUPT_SIZE 32 29 - 30 - #define CB_MAX_RX_DESC 128 /* max # of descriptors */ 31 - #define CB_MIN_RX_DESC 16 /* min # of RX descriptors */ 32 - #define CB_MAX_TX_DESC 128 /* max # of descriptors */ 33 - #define CB_MIN_TX_DESC 16 /* min # of TX descriptors */ 34 - 35 - /* 36 - * bits in the RSR register 37 - */ 38 - #define RSR_ADDRBROAD BIT(7) 39 - #define RSR_ADDRMULTI BIT(6) 40 - #define RSR_ADDRUNI 0x00 41 - #define RSR_IVLDTYP BIT(5) /* invalid packet type */ 42 - #define RSR_IVLDLEN BIT(4) /* invalid len (> 2312 byte) */ 43 - #define RSR_BSSIDOK BIT(3) 44 - #define RSR_CRCOK BIT(2) 45 - #define RSR_BCNSSIDOK BIT(1) 46 - #define RSR_ADDROK BIT(0) 47 - 48 - /* 49 - * bits in the new RSR register 50 - */ 51 - #define NEWRSR_DECRYPTOK BIT(4) 52 - #define NEWRSR_CFPIND BIT(3) 53 - #define NEWRSR_HWUTSF BIT(2) 54 - #define NEWRSR_BCNHITAID BIT(1) 55 - #define NEWRSR_BCNHITAID0 BIT(0) 56 - 57 - /* 58 - * bits in the TSR register 59 - */ 60 - #define TSR_RETRYTMO BIT(3) 61 - #define TSR_TMO BIT(2) 62 - #define TSR_ACKDATA BIT(1) 63 - #define TSR_VALID BIT(0) 64 - 65 - #define FIFOCTL_AUTO_FB_1 0x1000 66 - #define FIFOCTL_AUTO_FB_0 0x0800 67 - #define FIFOCTL_GRPACK 0x0400 68 - #define FIFOCTL_11GA 0x0300 69 - #define FIFOCTL_11GB 0x0200 70 - #define FIFOCTL_11B 0x0100 71 - #define FIFOCTL_11A 0x0000 72 - #define FIFOCTL_RTS 0x0080 73 - #define FIFOCTL_ISDMA0 0x0040 74 - #define FIFOCTL_GENINT 0x0020 75 - #define FIFOCTL_TMOEN 0x0010 76 - #define FIFOCTL_LRETRY 0x0008 77 - #define FIFOCTL_CRCDIS 0x0004 78 - #define FIFOCTL_NEEDACK 0x0002 79 - #define FIFOCTL_LHEAD 0x0001 80 - 81 - /* WMAC definition Frag Control */ 82 - #define FRAGCTL_AES 0x0300 83 - #define FRAGCTL_TKIP 0x0200 84 - #define FRAGCTL_LEGACY 0x0100 85 - #define FRAGCTL_NONENCRYPT 0x0000 86 - #define FRAGCTL_ENDFRAG 0x0003 87 - #define FRAGCTL_MIDFRAG 0x0002 88 - #define FRAGCTL_STAFRAG 0x0001 89 - #define FRAGCTL_NONFRAG 0x0000 90 - 91 - #endif /* __DESC_H__ */
-386
drivers/staging/vt6656/device.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: MAC Data structure 7 - * 8 - * Author: Tevin Chen 9 - * 10 - * Date: Mar 17, 1997 11 - * 12 - */ 13 - 14 - #ifndef __DEVICE_H__ 15 - #define __DEVICE_H__ 16 - 17 - #include <linux/bits.h> 18 - #include <linux/module.h> 19 - #include <linux/kernel.h> 20 - #include <linux/slab.h> 21 - #include <linux/delay.h> 22 - #include <linux/device.h> 23 - #include <linux/firmware.h> 24 - #include <linux/suspend.h> 25 - #include <linux/if_arp.h> 26 - #include <linux/wireless.h> 27 - #include <linux/timer.h> 28 - #include <linux/usb.h> 29 - #include <linux/crc32.h> 30 - #include <net/mac80211.h> 31 - 32 - #ifdef SIOCETHTOOL 33 - #define DEVICE_ETHTOOL_IOCTL_SUPPORT 34 - #include <linux/ethtool.h> 35 - #else 36 - #undef DEVICE_ETHTOOL_IOCTL_SUPPORT 37 - #endif 38 - 39 - #define RATE_1M 0 40 - #define RATE_2M 1 41 - #define RATE_5M 2 42 - #define RATE_11M 3 43 - #define RATE_6M 4 44 - #define RATE_9M 5 45 - #define RATE_12M 6 46 - #define RATE_18M 7 47 - #define RATE_24M 8 48 - #define RATE_36M 9 49 - #define RATE_48M 10 50 - #define RATE_54M 11 51 - #define RATE_AUTO 12 52 - 53 - #define MAX_RATE 12 54 - #define VNT_B_RATES (BIT(RATE_1M) | BIT(RATE_2M) |\ 55 - BIT(RATE_5M) | BIT(RATE_11M)) 56 - 57 - /* 58 - * device specific 59 - */ 60 - 61 - #include "wcmd.h" 62 - #include "desc.h" 63 - #include "key.h" 64 - #include "card.h" 65 - 66 - #define VNT_USB_VENDOR_ID 0x160a 67 - #define VNT_USB_PRODUCT_ID 0x3184 68 - 69 - #define DEVICE_NAME "vt6656" 70 - #define DEVICE_FULL_DRV_NAM "VIA Networking Wireless LAN USB Driver" 71 - 72 - #define DEVICE_VERSION "mac80211" 73 - 74 - #define FIRMWARE_VERSION 0x133 /* version 1.51 */ 75 - #define FIRMWARE_NAME "vntwusb.fw" 76 - #define FIRMWARE_CHUNK_SIZE 0x400 77 - 78 - #define MAX_UINTS 8 79 - #define OPTION_DEFAULT { [0 ... MAX_UINTS - 1] = -1} 80 - 81 - #define DUPLICATE_RX_CACHE_LENGTH 5 82 - 83 - #define AUTO_FB_NONE 0 84 - #define AUTO_FB_0 1 85 - #define AUTO_FB_1 2 86 - 87 - #define FB_RATE0 0 88 - #define FB_RATE1 1 89 - 90 - /* Antenna Mode */ 91 - #define ANT_A 0 92 - #define ANT_B 1 93 - #define ANT_DIVERSITY 2 94 - #define ANT_RXD_TXA 3 95 - #define ANT_RXD_TXB 4 96 - #define ANT_UNKNOWN 0xFF 97 - #define ANT_TXA 0 98 - #define ANT_TXB 1 99 - #define ANT_RXA 2 100 - #define ANT_RXB 3 101 - 102 - #define BB_VGA_LEVEL 4 103 - #define BB_VGA_CHANGE_THRESHOLD 3 104 - 105 - #define EEP_MAX_CONTEXT_SIZE 256 106 - 107 - /* Contents in the EEPROM */ 108 - #define EEP_OFS_PAR 0x0 109 - #define EEP_OFS_ANTENNA 0x17 110 - #define EEP_OFS_RADIOCTL 0x18 111 - #define EEP_OFS_RFTYPE 0x1b 112 - #define EEP_OFS_MINCHANNEL 0x1c 113 - #define EEP_OFS_MAXCHANNEL 0x1d 114 - #define EEP_OFS_SIGNATURE 0x1e 115 - #define EEP_OFS_ZONETYPE 0x1f 116 - #define EEP_OFS_RFTABLE 0x20 117 - #define EEP_OFS_PWR_CCK 0x20 118 - #define EEP_OFS_SETPT_CCK 0x21 119 - #define EEP_OFS_PWR_OFDMG 0x23 120 - 121 - #define EEP_OFS_CALIB_TX_IQ 0x24 122 - #define EEP_OFS_CALIB_TX_DC 0x25 123 - #define EEP_OFS_CALIB_RX_IQ 0x26 124 - 125 - #define EEP_OFS_MAJOR_VER 0x2e 126 - #define EEP_OFS_MINOR_VER 0x2f 127 - 128 - #define EEP_OFS_CCK_PWR_TBL 0x30 129 - #define EEP_OFS_OFDM_PWR_TBL 0x40 130 - #define EEP_OFS_OFDMA_PWR_TBL 0x50 131 - 132 - /* Bits in EEP_OFS_ANTENNA */ 133 - #define EEP_ANTENNA_MAIN BIT(0) 134 - #define EEP_ANTENNA_AUX BIT(1) 135 - #define EEP_ANTINV BIT(2) 136 - 137 - /* Bits in EEP_OFS_RADIOCTL */ 138 - #define EEP_RADIOCTL_ENABLE BIT(7) 139 - 140 - /* control commands */ 141 - #define MESSAGE_TYPE_READ 0x1 142 - #define MESSAGE_TYPE_WRITE 0x0 143 - #define MESSAGE_TYPE_LOCK_OR 0x2 144 - #define MESSAGE_TYPE_LOCK_AND 0x3 145 - #define MESSAGE_TYPE_WRITE_MASK 0x4 146 - #define MESSAGE_TYPE_CARDINIT 0x5 147 - #define MESSAGE_TYPE_INIT_RSP 0x6 148 - #define MESSAGE_TYPE_MACSHUTDOWN 0x7 149 - #define MESSAGE_TYPE_SETKEY 0x8 150 - #define MESSAGE_TYPE_CLRKEYENTRY 0x9 151 - #define MESSAGE_TYPE_WRITE_MISCFF 0xa 152 - #define MESSAGE_TYPE_SET_ANTMD 0xb 153 - #define MESSAGE_TYPE_SELECT_CHANNEL 0xc 154 - #define MESSAGE_TYPE_SET_TSFTBTT 0xd 155 - #define MESSAGE_TYPE_SET_SSTIFS 0xe 156 - #define MESSAGE_TYPE_CHANGE_BBTYPE 0xf 157 - #define MESSAGE_TYPE_DISABLE_PS 0x10 158 - #define MESSAGE_TYPE_WRITE_IFRF 0x11 159 - 160 - /* command read/write(index) */ 161 - #define MESSAGE_REQUEST_MEM 0x1 162 - #define MESSAGE_REQUEST_BBREG 0x2 163 - #define MESSAGE_REQUEST_MACREG 0x3 164 - #define MESSAGE_REQUEST_EEPROM 0x4 165 - #define MESSAGE_REQUEST_TSF 0x5 166 - #define MESSAGE_REQUEST_TBTT 0x6 167 - #define MESSAGE_REQUEST_BBAGC 0x7 168 - #define MESSAGE_REQUEST_VERSION 0x8 169 - #define MESSAGE_REQUEST_RF_INIT 0x9 170 - #define MESSAGE_REQUEST_RF_INIT2 0xa 171 - #define MESSAGE_REQUEST_RF_CH0 0xb 172 - #define MESSAGE_REQUEST_RF_CH1 0xc 173 - #define MESSAGE_REQUEST_RF_CH2 0xd 174 - 175 - /* USB registers */ 176 - #define USB_REG4 0x604 177 - 178 - #define DEVICE_INIT_COLD 0x0 /* cold init */ 179 - #define DEVICE_INIT_RESET 0x1 /* reset init or Dx to D0 power remain */ 180 - #define DEVICE_INIT_DXPL 0x2 /* Dx to D0 power lost init */ 181 - 182 - /* Device init */ 183 - struct vnt_cmd_card_init { 184 - u8 init_class; 185 - u8 exist_sw_net_addr; 186 - u8 sw_net_addr[6]; 187 - u8 short_retry_limit; 188 - u8 long_retry_limit; 189 - }; 190 - 191 - struct vnt_rsp_card_init { 192 - u8 status; 193 - u8 net_addr[6]; 194 - u8 rf_type; 195 - u8 min_channel; 196 - u8 max_channel; 197 - }; 198 - 199 - /* USB */ 200 - 201 - /* 202 - * Enum of context types for SendPacket 203 - */ 204 - enum { 205 - CONTEXT_DATA_PACKET = 0, 206 - CONTEXT_BEACON_PACKET 207 - }; 208 - 209 - struct vnt_rx_header { 210 - u32 wbk_status; 211 - u8 rx_sts; 212 - u8 rx_rate; 213 - u16 pay_load_len; 214 - } __packed; 215 - 216 - struct vnt_rx_tail { 217 - __le64 tsf_time; 218 - u8 sq; 219 - u8 new_rsr; 220 - u8 rssi; 221 - u8 rsr; 222 - u8 sq_3; 223 - } __packed; 224 - 225 - /* RCB (Receive Control Block) */ 226 - struct vnt_rcb { 227 - void *priv; 228 - struct urb *urb; 229 - struct sk_buff *skb; 230 - }; 231 - 232 - /* used to track bulk out irps */ 233 - struct vnt_usb_send_context { 234 - void *priv; 235 - struct sk_buff *skb; 236 - void *tx_buffer; 237 - u32 frame_len; 238 - u16 tx_hdr_size; 239 - u16 tx_rate; 240 - u8 type; 241 - u8 pkt_no; 242 - u8 pkt_type; 243 - bool in_use; 244 - }; 245 - 246 - /* 247 - * Structure to keep track of USB interrupt packets 248 - */ 249 - struct vnt_interrupt_buffer { 250 - u8 *data_buf; 251 - }; 252 - 253 - /* flags for options */ 254 - #define DEVICE_FLAGS_UNPLUG 0 255 - #define DEVICE_FLAGS_DISCONNECTED 1 256 - 257 - struct vnt_private { 258 - /* mac80211 */ 259 - struct ieee80211_hw *hw; 260 - struct ieee80211_vif *vif; 261 - u8 mac_hw; 262 - /* netdev */ 263 - struct usb_device *usb; 264 - struct usb_interface *intf; 265 - 266 - u64 tsf_time; 267 - 268 - u32 rx_buf_sz; 269 - int mc_list_count; 270 - 271 - spinlock_t lock; /* prepare tx USB URB */ 272 - struct mutex usb_lock; /* USB control messages */ 273 - 274 - unsigned long flags; 275 - 276 - /* USB */ 277 - struct urb *interrupt_urb; 278 - u32 int_interval; 279 - 280 - /* Variables to track resources for the BULK In Pipe */ 281 - struct vnt_rcb *rcb[CB_MAX_RX_DESC]; 282 - u32 num_rcb; 283 - 284 - /* Variables to track resources for the BULK Out Pipe */ 285 - struct vnt_usb_send_context *tx_context[CB_MAX_TX_DESC]; 286 - struct usb_anchor tx_submitted; 287 - u32 num_tx_context; 288 - 289 - /* Variables to track resources for the Interrupt In Pipe */ 290 - struct vnt_interrupt_buffer int_buf; 291 - 292 - /* Version control */ 293 - u16 firmware_version; 294 - u8 local_id; 295 - u8 rf_type; 296 - u8 bb_rx_conf; 297 - 298 - struct vnt_cmd_card_init init_command; 299 - struct vnt_rsp_card_init init_response; 300 - u8 current_net_addr[ETH_ALEN] __aligned(2); 301 - u8 permanent_net_addr[ETH_ALEN] __aligned(2); 302 - 303 - u8 exist_sw_net_addr; 304 - 305 - u64 current_tsf; 306 - 307 - /* 802.11 MAC specific */ 308 - u32 current_rssi; 309 - 310 - /* Antenna Diversity */ 311 - int tx_rx_ant_inv; 312 - u32 rx_antenna_sel; 313 - u8 rx_antenna_mode; 314 - u8 tx_antenna_mode; 315 - u8 radio_ctl; 316 - 317 - /* IFS & Cw */ 318 - u32 sifs; /* Current SIFS */ 319 - u32 difs; /* Current DIFS */ 320 - u32 eifs; /* Current EIFS */ 321 - u32 slot; /* Current SlotTime */ 322 - 323 - /* Rate */ 324 - u8 bb_type; /* 0: 11A, 1:11B, 2:11G */ 325 - u8 packet_type; /* 0:11a 1:11b 2:11gb 3:11ga */ 326 - u32 basic_rates; 327 - u8 top_ofdm_basic_rate; 328 - u8 top_cck_basic_rate; 329 - 330 - u8 eeprom[EEP_MAX_CONTEXT_SIZE]; /*u32 alignment */ 331 - 332 - u8 preamble_type; 333 - 334 - /* For RF Power table */ 335 - u8 cck_pwr; 336 - u8 ofdm_pwr_g; 337 - u8 ofdm_pwr_a; 338 - u8 power; 339 - u8 cck_pwr_tbl[14]; 340 - u8 ofdm_pwr_tbl[14]; 341 - u8 ofdm_a_pwr_tbl[42]; 342 - 343 - u16 tx_rate_fb0; 344 - u16 tx_rate_fb1; 345 - 346 - enum nl80211_iftype op_mode; 347 - 348 - int short_slot_time; 349 - 350 - /* Power save */ 351 - u16 current_aid; 352 - 353 - /* Beacon related */ 354 - u16 seq_counter; 355 - 356 - enum vnt_cmd_state command_state; 357 - 358 - enum vnt_cmd command; 359 - 360 - /* 802.11 counter */ 361 - 362 - enum vnt_cmd cmd_queue[CMD_Q_SIZE]; 363 - u32 cmd_dequeue_idx; 364 - u32 cmd_enqueue_idx; 365 - u32 free_cmd_queue; 366 - int cmd_running; 367 - 368 - unsigned long key_entry_inuse; 369 - 370 - u8 auto_fb_ctrl; 371 - 372 - /* For Update BaseBand VGA Gain Offset */ 373 - u8 bb_vga[BB_VGA_LEVEL]; 374 - 375 - u8 bb_pre_ed_rssi; 376 - u8 bb_pre_ed_index; 377 - 378 - /* command timer */ 379 - struct delayed_work run_command_work; 380 - 381 - struct ieee80211_low_level_stats low_stats; 382 - }; 383 - 384 - int vnt_init(struct vnt_private *priv); 385 - 386 - #endif
-142
drivers/staging/vt6656/key.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Implement functions for 802.11i Key management 7 - * 8 - * Author: Jerry Chen 9 - * 10 - * Date: May 29, 2003 11 - * 12 - * Functions: 13 - * 14 - * Revision History: 15 - * 16 - */ 17 - 18 - #include "mac.h" 19 - #include "key.h" 20 - #include "usbpipe.h" 21 - 22 - int vnt_key_init_table(struct vnt_private *priv) 23 - { 24 - u8 i; 25 - u8 data[MAX_KEY_TABLE]; 26 - 27 - for (i = 0; i < MAX_KEY_TABLE; i++) 28 - data[i] = i; 29 - 30 - return vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, 31 - 0, 0, ARRAY_SIZE(data), data); 32 - } 33 - 34 - static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr, 35 - struct ieee80211_key_conf *key, u32 key_type, 36 - u32 mode) 37 - { 38 - struct vnt_private *priv = hw->priv; 39 - u8 broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 40 - u16 key_mode = 0; 41 - u32 entry = 0; 42 - u8 *bssid; 43 - u8 key_inx = key->keyidx; 44 - u8 i; 45 - 46 - if (mac_addr) 47 - bssid = mac_addr; 48 - else 49 - bssid = &broadcast[0]; 50 - 51 - if (key_type != VNT_KEY_DEFAULTKEY) { 52 - for (i = 0; i < (MAX_KEY_TABLE - 1); i++) { 53 - if (!test_bit(i, &priv->key_entry_inuse)) { 54 - set_bit(i, &priv->key_entry_inuse); 55 - 56 - key->hw_key_idx = i; 57 - entry = key->hw_key_idx; 58 - break; 59 - } 60 - } 61 - } 62 - 63 - switch (key_type) { 64 - case VNT_KEY_DEFAULTKEY: 65 - /* default key last entry */ 66 - entry = MAX_KEY_TABLE - 1; 67 - key->hw_key_idx = entry; 68 - fallthrough; 69 - case VNT_KEY_GROUP_ADDRESS: 70 - key_mode = mode | (mode << 4); 71 - break; 72 - case VNT_KEY_GROUP: 73 - key_mode = mode << 4; 74 - break; 75 - case VNT_KEY_PAIRWISE: 76 - key_mode |= mode; 77 - key_inx = 4; 78 - break; 79 - default: 80 - return -EINVAL; 81 - } 82 - 83 - key_mode |= key_type; 84 - 85 - if (mode == KEY_CTL_WEP) { 86 - if (key->keylen == WLAN_KEY_LEN_WEP40) 87 - key->key[15] &= 0x7f; 88 - if (key->keylen == WLAN_KEY_LEN_WEP104) 89 - key->key[15] |= 0x80; 90 - } 91 - 92 - return vnt_mac_set_keyentry(priv, key_mode, entry, 93 - key_inx, bssid, key->key); 94 - } 95 - 96 - int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 97 - struct ieee80211_vif *vif, struct ieee80211_key_conf *key) 98 - { 99 - struct vnt_private *priv = hw->priv; 100 - u8 *mac_addr = NULL; 101 - u8 key_dec_mode = 0; 102 - 103 - if (sta) 104 - mac_addr = &sta->addr[0]; 105 - 106 - switch (key->cipher) { 107 - case WLAN_CIPHER_SUITE_WEP40: 108 - case WLAN_CIPHER_SUITE_WEP104: 109 - vnt_set_keymode(hw, mac_addr, key, VNT_KEY_DEFAULTKEY, 110 - KEY_CTL_WEP); 111 - 112 - key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 113 - 114 - return vnt_set_keymode(hw, mac_addr, key, VNT_KEY_DEFAULTKEY, 115 - KEY_CTL_WEP); 116 - 117 - case WLAN_CIPHER_SUITE_TKIP: 118 - key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 119 - key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 120 - 121 - key_dec_mode = KEY_CTL_TKIP; 122 - 123 - break; 124 - case WLAN_CIPHER_SUITE_CCMP: 125 - if (priv->local_id <= MAC_REVISION_A1) 126 - return -EOPNOTSUPP; 127 - 128 - key_dec_mode = KEY_CTL_CCMP; 129 - 130 - key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 131 - break; 132 - default: 133 - return -EOPNOTSUPP; 134 - } 135 - 136 - if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) 137 - return vnt_set_keymode(hw, mac_addr, key, VNT_KEY_PAIRWISE, 138 - key_dec_mode); 139 - 140 - return vnt_set_keymode(hw, mac_addr, key, 141 - VNT_KEY_GROUP_ADDRESS, key_dec_mode); 142 - }
-40
drivers/staging/vt6656/key.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Implement functions for 802.11i Key management 7 - * 8 - * Author: Jerry Chen 9 - * 10 - * Date: May 29, 2003 11 - * 12 - */ 13 - 14 - #ifndef __KEY_H__ 15 - #define __KEY_H__ 16 - 17 - #include "device.h" 18 - 19 - #define MAX_KEY_TABLE 11 20 - 21 - #define KEY_CTL_WEP 0x00 22 - #define KEY_CTL_NONE 0x01 23 - #define KEY_CTL_TKIP 0x02 24 - #define KEY_CTL_CCMP 0x03 25 - 26 - #define VNT_KEY_ONFLY_ALL 0x4000 27 - #define VNT_KEY_ONFLY 0x8000 28 - #define VNT_KEY_ALLGROUP 0x04 29 - #define VNT_KEY_GROUP 0x40 30 - #define VNT_KEY_PAIRWISE VNT_KEY_ONFLY 31 - #define VNT_KEY_GROUP_ADDRESS (VNT_KEY_ALLGROUP | VNT_KEY_GROUP) 32 - #define VNT_KEY_DEFAULTKEY (VNT_KEY_GROUP_ADDRESS | VNT_KEY_ONFLY |\ 33 - VNT_KEY_ONFLY_ALL) 34 - 35 - int vnt_key_init_table(struct vnt_private *priv); 36 - 37 - int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 38 - struct ieee80211_vif *vif, struct ieee80211_key_conf *key); 39 - 40 - #endif /* __KEY_H__ */
-183
drivers/staging/vt6656/mac.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: MAC routines 7 - * 8 - * Author: Tevin Chen 9 - * 10 - * Date: May 21, 1996 11 - * 12 - * Functions: 13 - * 14 - * Revision History: 15 - */ 16 - 17 - #include <linux/etherdevice.h> 18 - 19 - #include "desc.h" 20 - #include "mac.h" 21 - #include "usbpipe.h" 22 - 23 - int vnt_mac_set_filter(struct vnt_private *priv, u64 mc_filter) 24 - { 25 - __le64 le_mc = cpu_to_le64(mc_filter); 26 - 27 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_MAR0, 28 - MESSAGE_REQUEST_MACREG, sizeof(le_mc), 29 - (u8 *)&le_mc); 30 - } 31 - 32 - int vnt_mac_shutdown(struct vnt_private *priv) 33 - { 34 - return vnt_control_out(priv, MESSAGE_TYPE_MACSHUTDOWN, 0, 0, 0, NULL); 35 - } 36 - 37 - int vnt_mac_set_bb_type(struct vnt_private *priv, u8 type) 38 - { 39 - u8 data[2]; 40 - 41 - data[0] = type; 42 - data[1] = EN_CFG_BB_TYPE_MASK; 43 - 44 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0, 45 - MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), 46 - data); 47 - } 48 - 49 - int vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx) 50 - { 51 - return vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, 0, 0, 52 - sizeof(entry_idx), &entry_idx); 53 - } 54 - 55 - int vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx, 56 - u32 key_idx, u8 *addr, u8 *key) 57 - { 58 - struct vnt_mac_set_key set_key; 59 - u16 offset; 60 - 61 - offset = MISCFIFO_KEYETRY0; 62 - offset += entry_idx * MISCFIFO_KEYENTRYSIZE; 63 - 64 - set_key.u.write.key_ctl = cpu_to_le16(key_ctl); 65 - ether_addr_copy(set_key.u.write.addr, addr); 66 - 67 - /* swap over swap[0] and swap[1] to get correct write order */ 68 - swap(set_key.u.swap[0], set_key.u.swap[1]); 69 - 70 - memcpy(set_key.key, key, WLAN_KEY_LEN_CCMP); 71 - 72 - dev_dbg(&priv->usb->dev, "offset %d key ctl %d set key %24ph\n", 73 - offset, key_ctl, (u8 *)&set_key); 74 - 75 - return vnt_control_out(priv, MESSAGE_TYPE_SETKEY, offset, 76 - (u16)key_idx, sizeof(struct vnt_mac_set_key), 77 - (u8 *)&set_key); 78 - } 79 - 80 - int vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits) 81 - { 82 - u8 data[2]; 83 - 84 - data[0] = 0; 85 - data[1] = bits; 86 - 87 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs, 88 - MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 89 - } 90 - 91 - int vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits) 92 - { 93 - u8 data[2]; 94 - 95 - data[0] = bits; 96 - data[1] = bits; 97 - 98 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs, 99 - MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 100 - } 101 - 102 - int vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word) 103 - { 104 - u8 data[2]; 105 - 106 - data[0] = (u8)(word & 0xff); 107 - data[1] = (u8)(word >> 8); 108 - 109 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE, reg_ofs, 110 - MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 111 - } 112 - 113 - int vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr) 114 - { 115 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BSSID0, 116 - MESSAGE_REQUEST_MACREG, ETH_ALEN, addr); 117 - } 118 - 119 - int vnt_mac_enable_protect_mode(struct vnt_private *priv) 120 - { 121 - u8 data[2]; 122 - 123 - data[0] = EN_CFG_PROTECT_MD; 124 - data[1] = EN_CFG_PROTECT_MD; 125 - 126 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0, 127 - MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 128 - } 129 - 130 - int vnt_mac_disable_protect_mode(struct vnt_private *priv) 131 - { 132 - u8 data[2]; 133 - 134 - data[0] = 0; 135 - data[1] = EN_CFG_PROTECT_MD; 136 - 137 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0, 138 - MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 139 - } 140 - 141 - int vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv) 142 - { 143 - u8 data[2]; 144 - 145 - data[0] = EN_CFG_BARKER_PREAM; 146 - data[1] = EN_CFG_BARKER_PREAM; 147 - 148 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2, 149 - MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 150 - } 151 - 152 - int vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv) 153 - { 154 - u8 data[2]; 155 - 156 - data[0] = 0; 157 - data[1] = EN_CFG_BARKER_PREAM; 158 - 159 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2, 160 - MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 161 - } 162 - 163 - int vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval) 164 - { 165 - u8 data[2]; 166 - 167 - data[0] = (u8)(interval & 0xff); 168 - data[1] = (u8)(interval >> 8); 169 - 170 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BI, 171 - MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 172 - } 173 - 174 - int vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led) 175 - { 176 - u8 data[2]; 177 - 178 - data[0] = led; 179 - data[1] = state; 180 - 181 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_PAPEDELAY, 182 - MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 183 - }
-373
drivers/staging/vt6656/mac.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: MAC routines 7 - * 8 - * Author: Tevin Chen 9 - * 10 - * Date: May 21, 1996 11 - * 12 - * Revision History: 13 - * 07-01-2003 Bryan YC Fan: Re-write codes to support VT3253 spec. 14 - * 08-25-2003 Kyle Hsu: Porting MAC functions from sim53. 15 - * 09-03-2003 Bryan YC Fan: Add MACvDisableProtectMD & MACvEnableProtectMD 16 - */ 17 - 18 - #ifndef __MAC_H__ 19 - #define __MAC_H__ 20 - 21 - #include <linux/bits.h> 22 - #include "device.h" 23 - 24 - #define REV_ID_VT3253_A0 0x00 25 - #define REV_ID_VT3253_A1 0x01 26 - #define REV_ID_VT3253_B0 0x08 27 - #define REV_ID_VT3253_B1 0x09 28 - 29 - /* Registers in the MAC */ 30 - #define MAC_REG_BISTCMD 0x04 31 - #define MAC_REG_BISTSR0 0x05 32 - #define MAC_REG_BISTSR1 0x06 33 - #define MAC_REG_BISTSR2 0x07 34 - #define MAC_REG_I2MCSR 0x08 35 - #define MAC_REG_I2MTGID 0x09 36 - #define MAC_REG_I2MTGAD 0x0a 37 - #define MAC_REG_I2MCFG 0x0b 38 - #define MAC_REG_I2MDIPT 0x0c 39 - #define MAC_REG_I2MDOPT 0x0e 40 - #define MAC_REG_USBSUS 0x0f 41 - 42 - #define MAC_REG_LOCALID 0x14 43 - #define MAC_REG_TESTCFG 0x15 44 - #define MAC_REG_JUMPER0 0x16 45 - #define MAC_REG_JUMPER1 0x17 46 - #define MAC_REG_TMCTL 0x18 47 - #define MAC_REG_TMDATA0 0x1c 48 - #define MAC_REG_TMDATA1 0x1d 49 - #define MAC_REG_TMDATA2 0x1e 50 - #define MAC_REG_TMDATA3 0x1f 51 - 52 - /* MAC Parameter related */ 53 - #define MAC_REG_LRT 0x20 54 - #define MAC_REG_SRT 0x21 55 - #define MAC_REG_SIFS 0x22 56 - #define MAC_REG_DIFS 0x23 57 - #define MAC_REG_EIFS 0x24 58 - #define MAC_REG_SLOT 0x25 59 - #define MAC_REG_BI 0x26 60 - #define MAC_REG_CWMAXMIN0 0x28 61 - #define MAC_REG_LINKOFFTOTM 0x2a 62 - #define MAC_REG_SWTMOT 0x2b 63 - #define MAC_REG_RTSOKCNT 0x2c 64 - #define MAC_REG_RTSFAILCNT 0x2d 65 - #define MAC_REG_ACKFAILCNT 0x2e 66 - #define MAC_REG_FCSERRCNT 0x2f 67 - 68 - /* TSF Related */ 69 - #define MAC_REG_TSFCNTR 0x30 70 - #define MAC_REG_NEXTTBTT 0x38 71 - #define MAC_REG_TSFOFST 0x40 72 - #define MAC_REG_TFTCTL 0x48 73 - 74 - /* WMAC Control/Status Related */ 75 - #define MAC_REG_ENCFG0 0x4c 76 - #define MAC_REG_ENCFG1 0x4d 77 - #define MAC_REG_ENCFG2 0x4e 78 - 79 - #define MAC_REG_CFG 0x50 80 - #define MAC_REG_TEST 0x52 81 - #define MAC_REG_HOSTCR 0x54 82 - #define MAC_REG_MACCR 0x55 83 - #define MAC_REG_RCR 0x56 84 - #define MAC_REG_TCR 0x57 85 - #define MAC_REG_IMR 0x58 86 - #define MAC_REG_ISR 0x5c 87 - #define MAC_REG_ISR1 0x5d 88 - 89 - /* Power Saving Related */ 90 - #define MAC_REG_PSCFG 0x60 91 - #define MAC_REG_PSCTL 0x61 92 - #define MAC_REG_PSPWRSIG 0x62 93 - #define MAC_REG_BBCR13 0x63 94 - #define MAC_REG_AIDATIM 0x64 95 - #define MAC_REG_PWBT 0x66 96 - #define MAC_REG_WAKEOKTMR 0x68 97 - #define MAC_REG_CALTMR 0x69 98 - #define MAC_REG_SYNSPACCNT 0x6a 99 - #define MAC_REG_WAKSYNOPT 0x6b 100 - 101 - /* Baseband/IF Control Group */ 102 - #define MAC_REG_BBREGCTL 0x6c 103 - #define MAC_REG_CHANNEL 0x6d 104 - #define MAC_REG_BBREGADR 0x6e 105 - #define MAC_REG_BBREGDATA 0x6f 106 - #define MAC_REG_IFREGCTL 0x70 107 - #define MAC_REG_IFDATA 0x71 108 - #define MAC_REG_ITRTMSET 0x74 109 - #define MAC_REG_PAPEDELAY 0x77 110 - #define MAC_REG_SOFTPWRCTL 0x78 111 - #define MAC_REG_SOFTPWRCTL2 0x79 112 - #define MAC_REG_GPIOCTL0 0x7a 113 - #define MAC_REG_GPIOCTL1 0x7b 114 - 115 - /* MiscFF PIO related */ 116 - #define MAC_REG_MISCFFNDEX 0xbc 117 - #define MAC_REG_MISCFFCTL 0xbe 118 - #define MAC_REG_MISCFFDATA 0xc0 119 - 120 - /* MAC Configuration Group */ 121 - #define MAC_REG_PAR0 0xc4 122 - #define MAC_REG_PAR4 0xc8 123 - #define MAC_REG_BSSID0 0xcc 124 - #define MAC_REG_BSSID4 0xd0 125 - #define MAC_REG_MAR0 0xd4 126 - #define MAC_REG_MAR4 0xd8 127 - 128 - /* MAC RSPPKT INFO Group */ 129 - #define MAC_REG_RSPINF_B_1 0xdC 130 - #define MAC_REG_RSPINF_B_2 0xe0 131 - #define MAC_REG_RSPINF_B_5 0xe4 132 - #define MAC_REG_RSPINF_B_11 0xe8 133 - #define MAC_REG_RSPINF_A_6 0xec 134 - #define MAC_REG_RSPINF_A_9 0xee 135 - #define MAC_REG_RSPINF_A_12 0xf0 136 - #define MAC_REG_RSPINF_A_18 0xf2 137 - #define MAC_REG_RSPINF_A_24 0xf4 138 - #define MAC_REG_RSPINF_A_36 0xf6 139 - #define MAC_REG_RSPINF_A_48 0xf8 140 - #define MAC_REG_RSPINF_A_54 0xfa 141 - #define MAC_REG_RSPINF_A_72 0xfc 142 - 143 - /* Bits in the I2MCFG EEPROM register */ 144 - #define I2MCFG_BOUNDCTL BIT(7) 145 - #define I2MCFG_WAITCTL BIT(5) 146 - #define I2MCFG_SCLOECTL BIT(4) 147 - #define I2MCFG_WBUSYCTL BIT(3) 148 - #define I2MCFG_NORETRY BIT(2) 149 - #define I2MCFG_I2MLDSEQ BIT(1) 150 - #define I2MCFG_I2CMFAST BIT(0) 151 - 152 - /* Bits in the I2MCSR EEPROM register */ 153 - #define I2MCSR_EEMW BIT(7) 154 - #define I2MCSR_EEMR BIT(6) 155 - #define I2MCSR_AUTOLD BIT(3) 156 - #define I2MCSR_NACK BIT(1) 157 - #define I2MCSR_DONE BIT(0) 158 - 159 - /* Bits in the TMCTL register */ 160 - #define TMCTL_TSUSP BIT(2) 161 - #define TMCTL_TMD BIT(1) 162 - #define TMCTL_TE BIT(0) 163 - 164 - /* Bits in the TFTCTL register */ 165 - #define TFTCTL_HWUTSF BIT(7) 166 - #define TFTCTL_TBTTSYNC BIT(6) 167 - #define TFTCTL_HWUTSFEN BIT(5) 168 - #define TFTCTL_TSFCNTRRD BIT(4) 169 - #define TFTCTL_TBTTSYNCEN BIT(3) 170 - #define TFTCTL_TSFSYNCEN BIT(2) 171 - #define TFTCTL_TSFCNTRST BIT(1) 172 - #define TFTCTL_TSFCNTREN BIT(0) 173 - 174 - /* Bits in the EnhanceCFG_0 register */ 175 - #define EN_CFG_BB_TYPE_A 0x00 176 - #define EN_CFG_BB_TYPE_B BIT(0) 177 - #define EN_CFG_BB_TYPE_G BIT(1) 178 - #define EN_CFG_BB_TYPE_MASK (EN_CFG_BB_TYPE_B | EN_CFG_BB_TYPE_G) 179 - #define EN_CFG_PROTECT_MD BIT(5) 180 - 181 - /* Bits in the EnhanceCFG_1 register */ 182 - #define EN_CFG_BCN_SUS_IND BIT(0) 183 - #define EN_CFG_BCN_SUS_CLR BIT(1) 184 - 185 - /* Bits in the EnhanceCFG_2 register */ 186 - #define EN_CFG_NXTBTTCFPSTR BIT(0) 187 - #define EN_CFG_BARKER_PREAM BIT(1) 188 - #define EN_CFG_PKT_BURST_MD BIT(2) 189 - 190 - /* Bits in the CFG register */ 191 - #define CFG_TKIPOPT BIT(7) 192 - #define CFG_RXDMAOPT BIT(6) 193 - #define CFG_TMOT_SW BIT(5) 194 - #define CFG_TMOT_HWLONG BIT(4) 195 - #define CFG_TMOT_HW 0x00 196 - #define CFG_CFPENDOPT BIT(3) 197 - #define CFG_BCNSUSEN BIT(2) 198 - #define CFG_NOTXTIMEOUT BIT(1) 199 - #define CFG_NOBUFOPT BIT(0) 200 - 201 - /* Bits in the TEST register */ 202 - #define TEST_LBEXT BIT(7) 203 - #define TEST_LBINT BIT(6) 204 - #define TEST_LBNONE 0x00 205 - #define TEST_SOFTINT BIT(5) 206 - #define TEST_CONTTX BIT(4) 207 - #define TEST_TXPE BIT(3) 208 - #define TEST_NAVDIS BIT(2) 209 - #define TEST_NOCTS BIT(1) 210 - #define TEST_NOACK BIT(0) 211 - 212 - /* Bits in the HOSTCR register */ 213 - #define HOSTCR_TXONST BIT(7) 214 - #define HOSTCR_RXONST BIT(6) 215 - #define HOSTCR_ADHOC BIT(5) 216 - #define HOSTCR_AP BIT(4) 217 - #define HOSTCR_TXON BIT(3) 218 - #define HOSTCR_RXON BIT(2) 219 - #define HOSTCR_MACEN BIT(1) 220 - #define HOSTCR_SOFTRST BIT(0) 221 - 222 - /* Bits in the MACCR register */ 223 - #define MACCR_SYNCFLUSHOK BIT(2) 224 - #define MACCR_SYNCFLUSH BIT(1) 225 - #define MACCR_CLRNAV BIT(0) 226 - 227 - /* Bits in the RCR register */ 228 - #define RCR_SSID BIT(7) 229 - #define RCR_RXALLTYPE BIT(6) 230 - #define RCR_UNICAST BIT(5) 231 - #define RCR_BROADCAST BIT(4) 232 - #define RCR_MULTICAST BIT(3) 233 - #define RCR_WPAERR BIT(2) 234 - #define RCR_ERRCRC BIT(1) 235 - #define RCR_BSSID BIT(0) 236 - 237 - /* Bits in the TCR register */ 238 - #define TCR_SYNCDCFOPT BIT(1) 239 - #define TCR_AUTOBCNTX BIT(0) 240 - 241 - /* ISR1 */ 242 - #define ISR_GPIO3 BIT(6) 243 - #define ISR_RXNOBUF BIT(3) 244 - #define ISR_MIBNEARFULL BIT(2) 245 - #define ISR_SOFTINT BIT(1) 246 - #define ISR_FETALERR BIT(0) 247 - 248 - #define LEDSTS_STS 0x06 249 - #define LEDSTS_TMLEN 0x78 250 - #define LEDSTS_OFF 0x00 251 - #define LEDSTS_ON 0x02 252 - #define LEDSTS_SLOW 0x04 253 - #define LEDSTS_INTER 0x06 254 - 255 - /* ISR0 */ 256 - #define ISR_WATCHDOG BIT(7) 257 - #define ISR_SOFTTIMER BIT(6) 258 - #define ISR_GPIO0 BIT(5) 259 - #define ISR_TBTT BIT(4) 260 - #define ISR_RXDMA0 BIT(3) 261 - #define ISR_BNTX BIT(2) 262 - #define ISR_ACTX BIT(0) 263 - 264 - /* Bits in the PSCFG register */ 265 - #define PSCFG_PHILIPMD BIT(6) 266 - #define PSCFG_WAKECALEN BIT(5) 267 - #define PSCFG_WAKETMREN BIT(4) 268 - #define PSCFG_BBPSPROG BIT(3) 269 - #define PSCFG_WAKESYN BIT(2) 270 - #define PSCFG_SLEEPSYN BIT(1) 271 - #define PSCFG_AUTOSLEEP BIT(0) 272 - 273 - /* Bits in the PSCTL register */ 274 - #define PSCTL_WAKEDONE BIT(5) 275 - #define PSCTL_PS BIT(4) 276 - #define PSCTL_GO2DOZE BIT(3) 277 - #define PSCTL_LNBCN BIT(2) 278 - #define PSCTL_ALBCN BIT(1) 279 - #define PSCTL_PSEN BIT(0) 280 - 281 - /* Bits in the PSPWSIG register */ 282 - #define PSSIG_WPE3 BIT(7) 283 - #define PSSIG_WPE2 BIT(6) 284 - #define PSSIG_WPE1 BIT(5) 285 - #define PSSIG_WRADIOPE BIT(4) 286 - #define PSSIG_SPE3 BIT(3) 287 - #define PSSIG_SPE2 BIT(2) 288 - #define PSSIG_SPE1 BIT(1) 289 - #define PSSIG_SRADIOPE BIT(0) 290 - 291 - /* Bits in the BBREGCTL register */ 292 - #define BBREGCTL_DONE BIT(2) 293 - #define BBREGCTL_REGR BIT(1) 294 - #define BBREGCTL_REGW BIT(0) 295 - 296 - /* Bits in the IFREGCTL register */ 297 - #define IFREGCTL_DONE BIT(2) 298 - #define IFREGCTL_IFRF BIT(1) 299 - #define IFREGCTL_REGW BIT(0) 300 - 301 - /* Bits in the SOFTPWRCTL register */ 302 - #define SOFTPWRCTL_RFLEOPT BIT(3) 303 - #define SOFTPWRCTL_TXPEINV BIT(1) 304 - #define SOFTPWRCTL_SWPECTI BIT(0) 305 - #define SOFTPWRCTL_SWPAPE BIT(5) 306 - #define SOFTPWRCTL_SWCALEN BIT(4) 307 - #define SOFTPWRCTL_SWRADIO_PE BIT(3) 308 - #define SOFTPWRCTL_SWPE2 BIT(2) 309 - #define SOFTPWRCTL_SWPE1 BIT(1) 310 - #define SOFTPWRCTL_SWPE3 BIT(0) 311 - 312 - /* Bits in the GPIOCTL1 register */ 313 - #define GPIO3_MD BIT(5) 314 - #define GPIO3_DATA BIT(6) 315 - #define GPIO3_INTMD BIT(7) 316 - 317 - /* Bits in the MISCFFCTL register */ 318 - #define MISCFFCTL_WRITE BIT(0) 319 - 320 - /* Loopback mode */ 321 - #define MAC_LB_EXT BIT(1) 322 - #define MAC_LB_INTERNAL BIT(0) 323 - #define MAC_LB_NONE 0x00 324 - 325 - /* Ethernet address filter type */ 326 - #define PKT_TYPE_NONE 0x00 /* turn off receiver */ 327 - #define PKT_TYPE_ALL_MULTICAST BIT(7) 328 - #define PKT_TYPE_PROMISCUOUS BIT(6) 329 - #define PKT_TYPE_DIRECTED BIT(5) /* obselete */ 330 - #define PKT_TYPE_BROADCAST BIT(4) 331 - #define PKT_TYPE_MULTICAST BIT(3) 332 - #define PKT_TYPE_ERROR_WPA BIT(2) 333 - #define PKT_TYPE_ERROR_CRC BIT(1) 334 - #define PKT_TYPE_BSSID BIT(0) 335 - 336 - #define DEFAULT_BI 0x200 337 - 338 - /* MiscFIFO Offset */ 339 - #define MISCFIFO_KEYETRY0 32 340 - #define MISCFIFO_KEYENTRYSIZE 22 341 - 342 - #define MAC_REVISION_A0 0x00 343 - #define MAC_REVISION_A1 0x01 344 - 345 - struct vnt_mac_set_key { 346 - union { 347 - struct { 348 - u8 addr[ETH_ALEN]; 349 - __le16 key_ctl; 350 - } write __packed; 351 - u32 swap[2]; 352 - } u; 353 - u8 key[WLAN_KEY_LEN_CCMP]; 354 - } __packed; 355 - 356 - int vnt_mac_set_filter(struct vnt_private *priv, u64 mc_filter); 357 - int vnt_mac_shutdown(struct vnt_private *priv); 358 - int vnt_mac_set_bb_type(struct vnt_private *priv, u8 type); 359 - int vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx); 360 - int vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx, 361 - u32 key_idx, u8 *addr, u8 *key); 362 - int vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits); 363 - int vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits); 364 - int vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word); 365 - int vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr); 366 - int vnt_mac_enable_protect_mode(struct vnt_private *priv); 367 - int vnt_mac_disable_protect_mode(struct vnt_private *priv); 368 - int vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv); 369 - int vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv); 370 - int vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval); 371 - int vnt_mac_set_led(struct vnt_private *privpriv, u8 state, u8 led); 372 - 373 - #endif /* __MAC_H__ */
-1121
drivers/staging/vt6656/main_usb.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: driver entry for initial, open, close, tx and rx. 7 - * 8 - * Author: Lyndon Chen 9 - * 10 - * Date: Dec 8, 2005 11 - * 12 - * Functions: 13 - * 14 - * vt6656_probe - module initial (insmod) driver entry 15 - * vnt_free_tx_bufs - free tx buffer function 16 - * vnt_init_registers- initial MAC & BBP & RF internal registers. 17 - * 18 - * Revision History: 19 - */ 20 - #undef __NO_VERSION__ 21 - 22 - #include <linux/bits.h> 23 - #include <linux/etherdevice.h> 24 - #include <linux/file.h> 25 - #include <linux/kernel.h> 26 - #include "device.h" 27 - #include "card.h" 28 - #include "baseband.h" 29 - #include "mac.h" 30 - #include "power.h" 31 - #include "wcmd.h" 32 - #include "rxtx.h" 33 - #include "rf.h" 34 - #include "usbpipe.h" 35 - #include "channel.h" 36 - 37 - /* 38 - * define module options 39 - */ 40 - 41 - /* version information */ 42 - #define DRIVER_AUTHOR \ 43 - "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>" 44 - MODULE_AUTHOR(DRIVER_AUTHOR); 45 - MODULE_LICENSE("GPL"); 46 - MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM); 47 - 48 - #define RX_DESC_DEF0 64 49 - static int vnt_rx_buffers = RX_DESC_DEF0; 50 - module_param_named(rx_buffers, vnt_rx_buffers, int, 0644); 51 - MODULE_PARM_DESC(rx_buffers, "Number of receive usb rx buffers"); 52 - 53 - #define TX_DESC_DEF0 64 54 - static int vnt_tx_buffers = TX_DESC_DEF0; 55 - module_param_named(tx_buffers, vnt_tx_buffers, int, 0644); 56 - MODULE_PARM_DESC(tx_buffers, "Number of receive usb tx buffers"); 57 - 58 - #define RTS_THRESH_DEF 2347 59 - #define FRAG_THRESH_DEF 2346 60 - 61 - /* BasebandType[] baseband type selected 62 - * 0: indicate 802.11a type 63 - * 1: indicate 802.11b type 64 - * 2: indicate 802.11g type 65 - */ 66 - 67 - #define BBP_TYPE_DEF 2 68 - 69 - /* 70 - * Static vars definitions 71 - */ 72 - 73 - static const struct usb_device_id vt6656_table[] = { 74 - {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)}, 75 - {} 76 - }; 77 - 78 - static void vnt_set_options(struct vnt_private *priv) 79 - { 80 - /* Set number of TX buffers */ 81 - if (vnt_tx_buffers < CB_MIN_TX_DESC || vnt_tx_buffers > CB_MAX_TX_DESC) 82 - priv->num_tx_context = TX_DESC_DEF0; 83 - else 84 - priv->num_tx_context = vnt_tx_buffers; 85 - 86 - /* Set number of RX buffers */ 87 - if (vnt_rx_buffers < CB_MIN_RX_DESC || vnt_rx_buffers > CB_MAX_RX_DESC) 88 - priv->num_rcb = RX_DESC_DEF0; 89 - else 90 - priv->num_rcb = vnt_rx_buffers; 91 - 92 - priv->op_mode = NL80211_IFTYPE_UNSPECIFIED; 93 - priv->bb_type = BBP_TYPE_DEF; 94 - priv->packet_type = priv->bb_type; 95 - priv->preamble_type = PREAMBLE_LONG; 96 - priv->exist_sw_net_addr = false; 97 - } 98 - 99 - static int vnt_download_firmware(struct vnt_private *priv) 100 - { 101 - struct device *dev = &priv->usb->dev; 102 - const struct firmware *fw; 103 - u16 length; 104 - int ii; 105 - int ret = 0; 106 - 107 - dev_dbg(dev, "---->Download firmware\n"); 108 - 109 - ret = request_firmware(&fw, FIRMWARE_NAME, dev); 110 - if (ret) { 111 - dev_err(dev, "firmware file %s request failed (%d)\n", 112 - FIRMWARE_NAME, ret); 113 - goto end; 114 - } 115 - 116 - for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) { 117 - length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE); 118 - 119 - ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length, 120 - fw->data + ii); 121 - if (ret) 122 - goto free_fw; 123 - 124 - dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size); 125 - } 126 - 127 - free_fw: 128 - release_firmware(fw); 129 - end: 130 - return ret; 131 - } 132 - 133 - static int vnt_firmware_branch_to_sram(struct vnt_private *priv) 134 - { 135 - dev_dbg(&priv->usb->dev, "---->Branch to Sram\n"); 136 - 137 - return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL); 138 - } 139 - 140 - static int vnt_check_firmware_version(struct vnt_private *priv) 141 - { 142 - int ret = 0; 143 - 144 - ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0, 145 - MESSAGE_REQUEST_VERSION, 2, 146 - (u8 *)&priv->firmware_version); 147 - if (ret) { 148 - dev_dbg(&priv->usb->dev, 149 - "Could not get firmware version: %d.\n", ret); 150 - goto end; 151 - } 152 - 153 - dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n", 154 - priv->firmware_version); 155 - 156 - if (priv->firmware_version == 0xFFFF) { 157 - dev_dbg(&priv->usb->dev, "In Loader.\n"); 158 - ret = -EINVAL; 159 - goto end; 160 - } 161 - 162 - if (priv->firmware_version < FIRMWARE_VERSION) { 163 - /* branch to loader for download new firmware */ 164 - ret = vnt_firmware_branch_to_sram(priv); 165 - if (ret) { 166 - dev_dbg(&priv->usb->dev, 167 - "Could not branch to SRAM: %d.\n", ret); 168 - } else { 169 - ret = -EINVAL; 170 - } 171 - } 172 - 173 - end: 174 - return ret; 175 - } 176 - 177 - /* 178 - * initialization of MAC & BBP registers 179 - */ 180 - static int vnt_init_registers(struct vnt_private *priv) 181 - { 182 - int ret; 183 - struct vnt_cmd_card_init *init_cmd = &priv->init_command; 184 - struct vnt_rsp_card_init *init_rsp = &priv->init_response; 185 - u8 antenna; 186 - int ii; 187 - u8 tmp; 188 - u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0; 189 - 190 - dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n", 191 - DEVICE_INIT_COLD, priv->packet_type); 192 - 193 - ret = vnt_check_firmware_version(priv); 194 - if (ret) { 195 - ret = vnt_download_firmware(priv); 196 - if (ret) { 197 - dev_dbg(&priv->usb->dev, 198 - "Could not download firmware: %d.\n", ret); 199 - goto end; 200 - } 201 - 202 - ret = vnt_firmware_branch_to_sram(priv); 203 - if (ret) { 204 - dev_dbg(&priv->usb->dev, 205 - "Could not branch to SRAM: %d.\n", ret); 206 - goto end; 207 - } 208 - } 209 - 210 - ret = vnt_vt3184_init(priv); 211 - if (ret) { 212 - dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n"); 213 - goto end; 214 - } 215 - 216 - init_cmd->init_class = DEVICE_INIT_COLD; 217 - init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr; 218 - for (ii = 0; ii < ARRAY_SIZE(init_cmd->sw_net_addr); ii++) 219 - init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii]; 220 - init_cmd->short_retry_limit = priv->hw->wiphy->retry_short; 221 - init_cmd->long_retry_limit = priv->hw->wiphy->retry_long; 222 - 223 - /* issue card_init command to device */ 224 - ret = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0, 225 - sizeof(struct vnt_cmd_card_init), 226 - (u8 *)init_cmd); 227 - if (ret) { 228 - dev_dbg(&priv->usb->dev, "Issue Card init fail\n"); 229 - goto end; 230 - } 231 - 232 - ret = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0, 233 - sizeof(struct vnt_rsp_card_init), 234 - (u8 *)init_rsp); 235 - if (ret) { 236 - dev_dbg(&priv->usb->dev, "Cardinit request in status fail!\n"); 237 - goto end; 238 - } 239 - 240 - /* local ID for AES functions */ 241 - ret = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID, 242 - MESSAGE_REQUEST_MACREG, 1, &priv->local_id); 243 - if (ret) 244 - goto end; 245 - 246 - /* do MACbSoftwareReset in MACvInitialize */ 247 - 248 - priv->top_ofdm_basic_rate = RATE_24M; 249 - priv->top_cck_basic_rate = RATE_1M; 250 - 251 - /* target to IF pin while programming to RF chip */ 252 - priv->power = 0xFF; 253 - 254 - priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK]; 255 - priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG]; 256 - /* load power table */ 257 - for (ii = 0; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) { 258 - priv->cck_pwr_tbl[ii] = 259 - priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL]; 260 - if (priv->cck_pwr_tbl[ii] == 0) 261 - priv->cck_pwr_tbl[ii] = priv->cck_pwr; 262 - 263 - priv->ofdm_pwr_tbl[ii] = 264 - priv->eeprom[ii + EEP_OFS_OFDM_PWR_TBL]; 265 - if (priv->ofdm_pwr_tbl[ii] == 0) 266 - priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_g; 267 - } 268 - 269 - /* 270 - * original zonetype is USA, but custom zonetype is Europe, 271 - * then need to recover 12, 13, 14 channels with 11 channel 272 - */ 273 - for (ii = 11; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) { 274 - priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10]; 275 - priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10]; 276 - } 277 - 278 - priv->ofdm_pwr_a = 0x34; /* same as RFbMA2829SelectChannel */ 279 - 280 - /* load OFDM A power table */ 281 - for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) { 282 - priv->ofdm_a_pwr_tbl[ii] = 283 - priv->eeprom[ii + EEP_OFS_OFDMA_PWR_TBL]; 284 - 285 - if (priv->ofdm_a_pwr_tbl[ii] == 0) 286 - priv->ofdm_a_pwr_tbl[ii] = priv->ofdm_pwr_a; 287 - } 288 - 289 - antenna = priv->eeprom[EEP_OFS_ANTENNA]; 290 - 291 - if (antenna & EEP_ANTINV) 292 - priv->tx_rx_ant_inv = true; 293 - else 294 - priv->tx_rx_ant_inv = false; 295 - 296 - antenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); 297 - 298 - if (antenna == 0) /* if not set default is both */ 299 - antenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); 300 - 301 - if (antenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) { 302 - priv->tx_antenna_mode = ANT_B; 303 - priv->rx_antenna_sel = 1; 304 - 305 - if (priv->tx_rx_ant_inv) 306 - priv->rx_antenna_mode = ANT_A; 307 - else 308 - priv->rx_antenna_mode = ANT_B; 309 - } else { 310 - priv->rx_antenna_sel = 0; 311 - 312 - if (antenna & EEP_ANTENNA_AUX) { 313 - priv->tx_antenna_mode = ANT_A; 314 - 315 - if (priv->tx_rx_ant_inv) 316 - priv->rx_antenna_mode = ANT_B; 317 - else 318 - priv->rx_antenna_mode = ANT_A; 319 - } else { 320 - priv->tx_antenna_mode = ANT_B; 321 - 322 - if (priv->tx_rx_ant_inv) 323 - priv->rx_antenna_mode = ANT_A; 324 - else 325 - priv->rx_antenna_mode = ANT_B; 326 - } 327 - } 328 - 329 - /* Set initial antenna mode */ 330 - ret = vnt_set_antenna_mode(priv, priv->rx_antenna_mode); 331 - if (ret) 332 - goto end; 333 - 334 - /* default Auto Mode */ 335 - priv->bb_type = BB_TYPE_11G; 336 - 337 - /* get RFType */ 338 - priv->rf_type = init_rsp->rf_type; 339 - 340 - /* load vt3266 calibration parameters in EEPROM */ 341 - if (priv->rf_type == RF_VT3226D0) { 342 - if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) && 343 - (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) { 344 - calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ]; 345 - calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC]; 346 - calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ]; 347 - if (calib_tx_iq || calib_tx_dc || calib_rx_iq) { 348 - /* CR255, enable TX/RX IQ and 349 - * DC compensation mode 350 - */ 351 - ret = vnt_control_out_u8(priv, 352 - MESSAGE_REQUEST_BBREG, 353 - 0xff, 0x03); 354 - if (ret) 355 - goto end; 356 - 357 - /* CR251, TX I/Q Imbalance Calibration */ 358 - ret = vnt_control_out_u8(priv, 359 - MESSAGE_REQUEST_BBREG, 360 - 0xfb, calib_tx_iq); 361 - if (ret) 362 - goto end; 363 - 364 - /* CR252, TX DC-Offset Calibration */ 365 - ret = vnt_control_out_u8(priv, 366 - MESSAGE_REQUEST_BBREG, 367 - 0xfC, calib_tx_dc); 368 - if (ret) 369 - goto end; 370 - 371 - /* CR253, RX I/Q Imbalance Calibration */ 372 - ret = vnt_control_out_u8(priv, 373 - MESSAGE_REQUEST_BBREG, 374 - 0xfd, calib_rx_iq); 375 - if (ret) 376 - goto end; 377 - } else { 378 - /* CR255, turn off 379 - * BB Calibration compensation 380 - */ 381 - ret = vnt_control_out_u8(priv, 382 - MESSAGE_REQUEST_BBREG, 383 - 0xff, 0x0); 384 - if (ret) 385 - goto end; 386 - } 387 - } 388 - } 389 - 390 - /* get permanent network address */ 391 - memcpy(priv->permanent_net_addr, init_rsp->net_addr, 6); 392 - ether_addr_copy(priv->current_net_addr, priv->permanent_net_addr); 393 - 394 - /* if exist SW network address, use it */ 395 - dev_dbg(&priv->usb->dev, "Network address = %pM\n", 396 - priv->current_net_addr); 397 - 398 - priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL]; 399 - 400 - if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) { 401 - ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 402 - MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG, 403 - 1, &tmp); 404 - if (ret) 405 - goto end; 406 - 407 - if ((tmp & GPIO3_DATA) == 0) { 408 - ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, 409 - GPIO3_INTMD); 410 - } else { 411 - ret = vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, 412 - GPIO3_INTMD); 413 - } 414 - 415 - if (ret) 416 - goto end; 417 - } 418 - 419 - ret = vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38); 420 - if (ret) 421 - goto end; 422 - 423 - ret = vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW); 424 - if (ret) 425 - goto end; 426 - 427 - ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, BIT(0)); 428 - if (ret) 429 - goto end; 430 - 431 - ret = vnt_radio_power_on(priv); 432 - if (ret) 433 - goto end; 434 - 435 - dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n"); 436 - 437 - end: 438 - return ret; 439 - } 440 - 441 - static void vnt_free_tx_bufs(struct vnt_private *priv) 442 - { 443 - struct vnt_usb_send_context *tx_context; 444 - int ii; 445 - 446 - usb_kill_anchored_urbs(&priv->tx_submitted); 447 - 448 - for (ii = 0; ii < priv->num_tx_context; ii++) { 449 - tx_context = priv->tx_context[ii]; 450 - if (!tx_context) 451 - continue; 452 - 453 - kfree(tx_context); 454 - } 455 - } 456 - 457 - static void vnt_free_rx_bufs(struct vnt_private *priv) 458 - { 459 - struct vnt_rcb *rcb; 460 - int ii; 461 - 462 - for (ii = 0; ii < priv->num_rcb; ii++) { 463 - rcb = priv->rcb[ii]; 464 - if (!rcb) 465 - continue; 466 - 467 - /* deallocate URBs */ 468 - if (rcb->urb) { 469 - usb_kill_urb(rcb->urb); 470 - usb_free_urb(rcb->urb); 471 - } 472 - 473 - /* deallocate skb */ 474 - if (rcb->skb) 475 - dev_kfree_skb(rcb->skb); 476 - 477 - kfree(rcb); 478 - } 479 - } 480 - 481 - static void vnt_free_int_bufs(struct vnt_private *priv) 482 - { 483 - kfree(priv->int_buf.data_buf); 484 - } 485 - 486 - static int vnt_alloc_bufs(struct vnt_private *priv) 487 - { 488 - int ret; 489 - struct vnt_usb_send_context *tx_context; 490 - struct vnt_rcb *rcb; 491 - int ii; 492 - 493 - init_usb_anchor(&priv->tx_submitted); 494 - 495 - for (ii = 0; ii < priv->num_tx_context; ii++) { 496 - tx_context = kmalloc(sizeof(*tx_context), GFP_KERNEL); 497 - if (!tx_context) { 498 - ret = -ENOMEM; 499 - goto free_tx; 500 - } 501 - 502 - priv->tx_context[ii] = tx_context; 503 - tx_context->priv = priv; 504 - tx_context->pkt_no = ii; 505 - tx_context->in_use = false; 506 - } 507 - 508 - for (ii = 0; ii < priv->num_rcb; ii++) { 509 - priv->rcb[ii] = kzalloc(sizeof(*priv->rcb[ii]), GFP_KERNEL); 510 - if (!priv->rcb[ii]) { 511 - ret = -ENOMEM; 512 - goto free_rx_tx; 513 - } 514 - 515 - rcb = priv->rcb[ii]; 516 - 517 - rcb->priv = priv; 518 - 519 - /* allocate URBs */ 520 - rcb->urb = usb_alloc_urb(0, GFP_KERNEL); 521 - if (!rcb->urb) { 522 - ret = -ENOMEM; 523 - goto free_rx_tx; 524 - } 525 - 526 - rcb->skb = dev_alloc_skb(priv->rx_buf_sz); 527 - if (!rcb->skb) { 528 - ret = -ENOMEM; 529 - goto free_rx_tx; 530 - } 531 - /* submit rx urb */ 532 - ret = vnt_submit_rx_urb(priv, rcb); 533 - if (ret) 534 - goto free_rx_tx; 535 - } 536 - 537 - priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL); 538 - if (!priv->interrupt_urb) { 539 - ret = -ENOMEM; 540 - goto free_rx_tx; 541 - } 542 - 543 - priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL); 544 - if (!priv->int_buf.data_buf) { 545 - ret = -ENOMEM; 546 - goto free_rx_tx_urb; 547 - } 548 - 549 - return 0; 550 - 551 - free_rx_tx_urb: 552 - usb_free_urb(priv->interrupt_urb); 553 - free_rx_tx: 554 - vnt_free_rx_bufs(priv); 555 - free_tx: 556 - vnt_free_tx_bufs(priv); 557 - return ret; 558 - } 559 - 560 - static void vnt_tx_80211(struct ieee80211_hw *hw, 561 - struct ieee80211_tx_control *control, 562 - struct sk_buff *skb) 563 - { 564 - struct vnt_private *priv = hw->priv; 565 - 566 - if (vnt_tx_packet(priv, skb)) 567 - ieee80211_free_txskb(hw, skb); 568 - } 569 - 570 - static int vnt_start(struct ieee80211_hw *hw) 571 - { 572 - int ret; 573 - struct vnt_private *priv = hw->priv; 574 - 575 - priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS; 576 - 577 - ret = vnt_alloc_bufs(priv); 578 - if (ret) { 579 - dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n"); 580 - goto err; 581 - } 582 - 583 - clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags); 584 - 585 - ret = vnt_init_registers(priv); 586 - if (ret) { 587 - dev_dbg(&priv->usb->dev, " init register fail\n"); 588 - goto free_all; 589 - } 590 - 591 - ret = vnt_key_init_table(priv); 592 - if (ret) 593 - goto free_all; 594 - 595 - priv->int_interval = 1; /* bInterval is set to 1 */ 596 - 597 - ret = vnt_start_interrupt_urb(priv); 598 - if (ret) 599 - goto free_all; 600 - 601 - ieee80211_wake_queues(hw); 602 - 603 - return 0; 604 - 605 - free_all: 606 - vnt_free_rx_bufs(priv); 607 - vnt_free_tx_bufs(priv); 608 - vnt_free_int_bufs(priv); 609 - 610 - usb_kill_urb(priv->interrupt_urb); 611 - usb_free_urb(priv->interrupt_urb); 612 - err: 613 - return ret; 614 - } 615 - 616 - static void vnt_stop(struct ieee80211_hw *hw, bool suspend) 617 - { 618 - struct vnt_private *priv = hw->priv; 619 - int i; 620 - 621 - if (!priv) 622 - return; 623 - 624 - for (i = 0; i < MAX_KEY_TABLE; i++) 625 - vnt_mac_disable_keyentry(priv, i); 626 - 627 - /* clear all keys */ 628 - priv->key_entry_inuse = 0; 629 - 630 - if (!test_bit(DEVICE_FLAGS_UNPLUG, &priv->flags)) 631 - vnt_mac_shutdown(priv); 632 - 633 - ieee80211_stop_queues(hw); 634 - 635 - set_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags); 636 - 637 - cancel_delayed_work_sync(&priv->run_command_work); 638 - 639 - priv->cmd_running = false; 640 - 641 - vnt_free_tx_bufs(priv); 642 - vnt_free_rx_bufs(priv); 643 - vnt_free_int_bufs(priv); 644 - 645 - usb_kill_urb(priv->interrupt_urb); 646 - usb_free_urb(priv->interrupt_urb); 647 - } 648 - 649 - static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 650 - { 651 - struct vnt_private *priv = hw->priv; 652 - 653 - priv->vif = vif; 654 - 655 - switch (vif->type) { 656 - case NL80211_IFTYPE_STATION: 657 - break; 658 - case NL80211_IFTYPE_ADHOC: 659 - vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST); 660 - 661 - vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC); 662 - 663 - break; 664 - case NL80211_IFTYPE_AP: 665 - vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST); 666 - 667 - vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_AP); 668 - 669 - break; 670 - default: 671 - return -EOPNOTSUPP; 672 - } 673 - 674 - priv->op_mode = vif->type; 675 - 676 - /* LED blink on TX */ 677 - vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER); 678 - 679 - return 0; 680 - } 681 - 682 - static void vnt_remove_interface(struct ieee80211_hw *hw, 683 - struct ieee80211_vif *vif) 684 - { 685 - struct vnt_private *priv = hw->priv; 686 - 687 - switch (vif->type) { 688 - case NL80211_IFTYPE_STATION: 689 - break; 690 - case NL80211_IFTYPE_ADHOC: 691 - vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX); 692 - vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); 693 - vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC); 694 - break; 695 - case NL80211_IFTYPE_AP: 696 - vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX); 697 - vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); 698 - vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_AP); 699 - break; 700 - default: 701 - break; 702 - } 703 - 704 - vnt_radio_power_off(priv); 705 - 706 - priv->op_mode = NL80211_IFTYPE_UNSPECIFIED; 707 - 708 - /* LED slow blink */ 709 - vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW); 710 - } 711 - 712 - static int vnt_config(struct ieee80211_hw *hw, u32 changed) 713 - { 714 - struct vnt_private *priv = hw->priv; 715 - struct ieee80211_conf *conf = &hw->conf; 716 - 717 - if (changed & IEEE80211_CONF_CHANGE_PS) { 718 - if (conf->flags & IEEE80211_CONF_PS) 719 - vnt_enable_power_saving(priv, conf->listen_interval); 720 - else 721 - vnt_disable_power_saving(priv); 722 - } 723 - 724 - if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || 725 - (conf->flags & IEEE80211_CONF_OFFCHANNEL)) { 726 - vnt_set_channel(priv, conf->chandef.chan->hw_value); 727 - 728 - if (conf->chandef.chan->band == NL80211_BAND_5GHZ) 729 - priv->bb_type = BB_TYPE_11A; 730 - else 731 - priv->bb_type = BB_TYPE_11G; 732 - } 733 - 734 - if (changed & IEEE80211_CONF_CHANGE_POWER) 735 - vnt_rf_setpower(priv, conf->chandef.chan); 736 - 737 - if (conf->flags & (IEEE80211_CONF_OFFCHANNEL | IEEE80211_CONF_IDLE)) 738 - /* Set max sensitivity*/ 739 - vnt_update_pre_ed_threshold(priv, true); 740 - else 741 - vnt_update_pre_ed_threshold(priv, false); 742 - 743 - return 0; 744 - } 745 - 746 - static void vnt_bss_info_changed(struct ieee80211_hw *hw, 747 - struct ieee80211_vif *vif, 748 - struct ieee80211_bss_conf *conf, u64 changed) 749 - { 750 - struct vnt_private *priv = hw->priv; 751 - 752 - priv->current_aid = vif->cfg.aid; 753 - 754 - if (changed & BSS_CHANGED_BSSID && conf->bssid) 755 - vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid); 756 - 757 - if (changed & BSS_CHANGED_BASIC_RATES) { 758 - priv->basic_rates = conf->basic_rates; 759 - 760 - vnt_update_top_rates(priv); 761 - 762 - dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates); 763 - } 764 - 765 - if (changed & BSS_CHANGED_ERP_PREAMBLE) { 766 - if (conf->use_short_preamble) { 767 - vnt_mac_enable_barker_preamble_mode(priv); 768 - priv->preamble_type = PREAMBLE_SHORT; 769 - } else { 770 - vnt_mac_disable_barker_preamble_mode(priv); 771 - priv->preamble_type = PREAMBLE_LONG; 772 - } 773 - } 774 - 775 - if (changed & BSS_CHANGED_ERP_CTS_PROT) { 776 - if (conf->use_cts_prot) 777 - vnt_mac_enable_protect_mode(priv); 778 - else 779 - vnt_mac_disable_protect_mode(priv); 780 - } 781 - 782 - if (changed & BSS_CHANGED_ERP_SLOT) { 783 - if (conf->use_short_slot) 784 - priv->short_slot_time = true; 785 - else 786 - priv->short_slot_time = false; 787 - 788 - vnt_set_short_slot_time(priv); 789 - vnt_set_vga_gain_offset(priv, priv->bb_vga[0]); 790 - } 791 - 792 - if (changed & (BSS_CHANGED_BASIC_RATES | BSS_CHANGED_ERP_PREAMBLE | 793 - BSS_CHANGED_ERP_SLOT)) 794 - vnt_set_bss_mode(priv); 795 - 796 - if (changed & (BSS_CHANGED_TXPOWER | BSS_CHANGED_BANDWIDTH)) 797 - vnt_rf_setpower(priv, conf->chanreq.oper.chan); 798 - 799 - if (changed & BSS_CHANGED_BEACON_ENABLED) { 800 - dev_dbg(&priv->usb->dev, 801 - "Beacon enable %d\n", conf->enable_beacon); 802 - 803 - if (conf->enable_beacon) { 804 - vnt_beacon_enable(priv, vif, conf); 805 - 806 - vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX); 807 - } else { 808 - vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX); 809 - } 810 - } 811 - 812 - if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INFO) && 813 - priv->op_mode != NL80211_IFTYPE_AP) { 814 - if (vif->cfg.assoc && conf->beacon_rate) { 815 - u16 ps_beacon_int = conf->beacon_int; 816 - 817 - if (conf->dtim_period) 818 - ps_beacon_int *= conf->dtim_period; 819 - else if (hw->conf.listen_interval) 820 - ps_beacon_int *= hw->conf.listen_interval; 821 - 822 - vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, 823 - TFTCTL_TSFCNTREN); 824 - 825 - vnt_mac_set_beacon_interval(priv, ps_beacon_int); 826 - 827 - vnt_reset_next_tbtt(priv, conf->beacon_int); 828 - 829 - vnt_adjust_tsf(priv, conf->beacon_rate->hw_value, 830 - conf->sync_tsf, priv->current_tsf); 831 - 832 - vnt_update_next_tbtt(priv, 833 - conf->sync_tsf, ps_beacon_int); 834 - } else { 835 - vnt_clear_current_tsf(priv); 836 - 837 - vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, 838 - TFTCTL_TSFCNTREN); 839 - } 840 - } 841 - } 842 - 843 - static u64 vnt_prepare_multicast(struct ieee80211_hw *hw, 844 - struct netdev_hw_addr_list *mc_list) 845 - { 846 - struct vnt_private *priv = hw->priv; 847 - struct netdev_hw_addr *ha; 848 - u64 mc_filter = 0; 849 - u32 bit_nr; 850 - 851 - netdev_hw_addr_list_for_each(ha, mc_list) { 852 - bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; 853 - mc_filter |= BIT_ULL(bit_nr); 854 - } 855 - 856 - priv->mc_list_count = mc_list->count; 857 - 858 - return mc_filter; 859 - } 860 - 861 - static void vnt_configure(struct ieee80211_hw *hw, 862 - unsigned int changed_flags, 863 - unsigned int *total_flags, u64 multicast) 864 - { 865 - struct vnt_private *priv = hw->priv; 866 - u8 rx_mode = 0; 867 - 868 - *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC; 869 - 870 - vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR, 871 - MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode); 872 - 873 - dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode); 874 - 875 - if (changed_flags & FIF_ALLMULTI) { 876 - if (*total_flags & FIF_ALLMULTI) { 877 - if (priv->mc_list_count > 2) 878 - vnt_mac_set_filter(priv, ~0); 879 - else 880 - vnt_mac_set_filter(priv, multicast); 881 - 882 - rx_mode |= RCR_MULTICAST | RCR_BROADCAST; 883 - } else { 884 - rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST); 885 - } 886 - } 887 - 888 - if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) { 889 - if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) 890 - rx_mode &= ~RCR_BSSID; 891 - else 892 - rx_mode |= RCR_BSSID; 893 - } 894 - 895 - vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode); 896 - 897 - dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode); 898 - } 899 - 900 - static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 901 - struct ieee80211_vif *vif, struct ieee80211_sta *sta, 902 - struct ieee80211_key_conf *key) 903 - { 904 - struct vnt_private *priv = hw->priv; 905 - 906 - switch (cmd) { 907 - case SET_KEY: 908 - return vnt_set_keys(hw, sta, vif, key); 909 - case DISABLE_KEY: 910 - if (test_bit(key->hw_key_idx, &priv->key_entry_inuse)) { 911 - clear_bit(key->hw_key_idx, &priv->key_entry_inuse); 912 - 913 - vnt_mac_disable_keyentry(priv, key->hw_key_idx); 914 - } 915 - break; 916 - 917 - default: 918 - break; 919 - } 920 - 921 - return 0; 922 - } 923 - 924 - static int vnt_get_stats(struct ieee80211_hw *hw, 925 - struct ieee80211_low_level_stats *stats) 926 - { 927 - struct vnt_private *priv = hw->priv; 928 - 929 - memcpy(stats, &priv->low_stats, sizeof(*stats)); 930 - 931 - return 0; 932 - } 933 - 934 - static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 935 - { 936 - struct vnt_private *priv = hw->priv; 937 - 938 - return priv->current_tsf; 939 - } 940 - 941 - static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 942 - u64 tsf) 943 - { 944 - struct vnt_private *priv = hw->priv; 945 - 946 - vnt_update_next_tbtt(priv, tsf, vif->bss_conf.beacon_int); 947 - } 948 - 949 - static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 950 - { 951 - struct vnt_private *priv = hw->priv; 952 - 953 - vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); 954 - 955 - vnt_clear_current_tsf(priv); 956 - } 957 - 958 - static const struct ieee80211_ops vnt_mac_ops = { 959 - .add_chanctx = ieee80211_emulate_add_chanctx, 960 - .remove_chanctx = ieee80211_emulate_remove_chanctx, 961 - .change_chanctx = ieee80211_emulate_change_chanctx, 962 - .switch_vif_chanctx = ieee80211_emulate_switch_vif_chanctx, 963 - .tx = vnt_tx_80211, 964 - .wake_tx_queue = ieee80211_handle_wake_tx_queue, 965 - .start = vnt_start, 966 - .stop = vnt_stop, 967 - .add_interface = vnt_add_interface, 968 - .remove_interface = vnt_remove_interface, 969 - .config = vnt_config, 970 - .bss_info_changed = vnt_bss_info_changed, 971 - .prepare_multicast = vnt_prepare_multicast, 972 - .configure_filter = vnt_configure, 973 - .set_key = vnt_set_key, 974 - .get_stats = vnt_get_stats, 975 - .get_tsf = vnt_get_tsf, 976 - .set_tsf = vnt_set_tsf, 977 - .reset_tsf = vnt_reset_tsf, 978 - }; 979 - 980 - int vnt_init(struct vnt_private *priv) 981 - { 982 - if (vnt_init_registers(priv)) 983 - return -EAGAIN; 984 - 985 - SET_IEEE80211_PERM_ADDR(priv->hw, priv->permanent_net_addr); 986 - 987 - vnt_init_bands(priv); 988 - 989 - if (ieee80211_register_hw(priv->hw)) 990 - return -ENODEV; 991 - 992 - priv->mac_hw = true; 993 - 994 - vnt_radio_power_off(priv); 995 - 996 - return 0; 997 - } 998 - 999 - static int 1000 - vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id) 1001 - { 1002 - struct usb_device *udev; 1003 - struct vnt_private *priv; 1004 - struct ieee80211_hw *hw; 1005 - struct wiphy *wiphy; 1006 - int rc; 1007 - 1008 - udev = usb_get_dev(interface_to_usbdev(intf)); 1009 - 1010 - dev_notice(&udev->dev, "%s Ver. %s\n", 1011 - DEVICE_FULL_DRV_NAM, DEVICE_VERSION); 1012 - dev_notice(&udev->dev, 1013 - "Copyright (c) 2004 VIA Networking Technologies, Inc.\n"); 1014 - 1015 - hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops); 1016 - if (!hw) { 1017 - dev_err(&udev->dev, "could not register ieee80211_hw\n"); 1018 - rc = -ENOMEM; 1019 - goto err_nomem; 1020 - } 1021 - 1022 - priv = hw->priv; 1023 - priv->hw = hw; 1024 - priv->usb = udev; 1025 - priv->intf = intf; 1026 - 1027 - vnt_set_options(priv); 1028 - 1029 - spin_lock_init(&priv->lock); 1030 - mutex_init(&priv->usb_lock); 1031 - 1032 - INIT_DELAYED_WORK(&priv->run_command_work, vnt_run_command); 1033 - 1034 - usb_set_intfdata(intf, priv); 1035 - 1036 - wiphy = priv->hw->wiphy; 1037 - 1038 - wiphy->frag_threshold = FRAG_THRESH_DEF; 1039 - wiphy->rts_threshold = RTS_THRESH_DEF; 1040 - wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 1041 - BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP); 1042 - 1043 - ieee80211_hw_set(priv->hw, TIMING_BEACON_ONLY); 1044 - ieee80211_hw_set(priv->hw, SIGNAL_DBM); 1045 - ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS); 1046 - ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS); 1047 - ieee80211_hw_set(priv->hw, SUPPORTS_PS); 1048 - ieee80211_hw_set(priv->hw, PS_NULLFUNC_STACK); 1049 - 1050 - priv->hw->extra_tx_headroom = 1051 - sizeof(struct vnt_tx_buffer) + sizeof(struct vnt_tx_usb_header); 1052 - priv->hw->max_signal = 100; 1053 - 1054 - SET_IEEE80211_DEV(priv->hw, &intf->dev); 1055 - 1056 - rc = usb_reset_device(priv->usb); 1057 - if (rc) 1058 - dev_warn(&priv->usb->dev, 1059 - "%s reset fail status=%d\n", __func__, rc); 1060 - 1061 - clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags); 1062 - vnt_reset_command_timer(priv); 1063 - 1064 - vnt_schedule_command(priv, WLAN_CMD_INIT_MAC80211); 1065 - 1066 - return 0; 1067 - 1068 - err_nomem: 1069 - usb_put_dev(udev); 1070 - 1071 - return rc; 1072 - } 1073 - 1074 - static void vt6656_disconnect(struct usb_interface *intf) 1075 - { 1076 - struct vnt_private *priv = usb_get_intfdata(intf); 1077 - 1078 - if (!priv) 1079 - return; 1080 - 1081 - if (priv->mac_hw) 1082 - ieee80211_unregister_hw(priv->hw); 1083 - 1084 - usb_set_intfdata(intf, NULL); 1085 - usb_put_dev(interface_to_usbdev(intf)); 1086 - 1087 - set_bit(DEVICE_FLAGS_UNPLUG, &priv->flags); 1088 - 1089 - ieee80211_free_hw(priv->hw); 1090 - } 1091 - 1092 - #ifdef CONFIG_PM 1093 - 1094 - static int vt6656_suspend(struct usb_interface *intf, pm_message_t message) 1095 - { 1096 - return 0; 1097 - } 1098 - 1099 - static int vt6656_resume(struct usb_interface *intf) 1100 - { 1101 - return 0; 1102 - } 1103 - 1104 - #endif /* CONFIG_PM */ 1105 - 1106 - MODULE_DEVICE_TABLE(usb, vt6656_table); 1107 - 1108 - static struct usb_driver vt6656_driver = { 1109 - .name = DEVICE_NAME, 1110 - .probe = vt6656_probe, 1111 - .disconnect = vt6656_disconnect, 1112 - .id_table = vt6656_table, 1113 - #ifdef CONFIG_PM 1114 - .suspend = vt6656_suspend, 1115 - .resume = vt6656_resume, 1116 - #endif /* CONFIG_PM */ 1117 - }; 1118 - 1119 - module_usb_driver(vt6656_driver); 1120 - 1121 - MODULE_FIRMWARE(FIRMWARE_NAME);
-112
drivers/staging/vt6656/power.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Handles 802.11 power management functions 7 - * 8 - * Author: Lyndon Chen 9 - * 10 - * Date: July 17, 2002 11 - * 12 - * Functions: 13 - * vnt_enable_power_saving - Enable Power Saving Mode 14 - * PSvDiasblePowerSaving - Disable Power Saving Mode 15 - * vnt_next_tbtt_wakeup - Decide if we need to wake up at next Beacon 16 - * 17 - * Revision History: 18 - * 19 - */ 20 - 21 - #include "mac.h" 22 - #include "device.h" 23 - #include "power.h" 24 - #include "wcmd.h" 25 - #include "rxtx.h" 26 - #include "card.h" 27 - #include "usbpipe.h" 28 - 29 - /* 30 - * 31 - * Routine Description: 32 - * Enable hw power saving functions 33 - * 34 - * Return Value: 35 - * None. 36 - * 37 - */ 38 - 39 - void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval) 40 - { 41 - u16 aid = priv->current_aid | BIT(14) | BIT(15); 42 - 43 - /* set period of power up before TBTT */ 44 - vnt_mac_write_word(priv, MAC_REG_PWBT, C_PWBT); 45 - 46 - if (priv->op_mode != NL80211_IFTYPE_ADHOC) 47 - /* set AID */ 48 - vnt_mac_write_word(priv, MAC_REG_AIDATIM, aid); 49 - 50 - /* Warren:06-18-2004,the sequence must follow 51 - * PSEN->AUTOSLEEP->GO2DOZE 52 - */ 53 - /* enable power saving hw function */ 54 - vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_PSEN); 55 - 56 - /* Set AutoSleep */ 57 - vnt_mac_reg_bits_on(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); 58 - 59 - /* Warren:MUST turn on this once before turn on AUTOSLEEP ,or the 60 - * AUTOSLEEP doesn't work 61 - */ 62 - vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_GO2DOZE); 63 - 64 - /* always listen beacon */ 65 - vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN); 66 - 67 - dev_dbg(&priv->usb->dev, "PS:Power Saving Mode Enable...\n"); 68 - } 69 - 70 - int vnt_disable_power_saving(struct vnt_private *priv) 71 - { 72 - int ret; 73 - 74 - /* disable power saving hw function */ 75 - ret = vnt_control_out(priv, MESSAGE_TYPE_DISABLE_PS, 0, 76 - 0, 0, NULL); 77 - if (ret) 78 - return ret; 79 - 80 - /* clear AutoSleep */ 81 - vnt_mac_reg_bits_off(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); 82 - 83 - /* set always listen beacon */ 84 - vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN); 85 - 86 - return 0; 87 - } 88 - 89 - /* 90 - * 91 - * Routine Description: 92 - * Check if Next TBTT must wake up 93 - * 94 - * Return Value: 95 - * None. 96 - * 97 - */ 98 - 99 - int vnt_next_tbtt_wakeup(struct vnt_private *priv) 100 - { 101 - struct ieee80211_hw *hw = priv->hw; 102 - struct ieee80211_conf *conf = &hw->conf; 103 - int wake_up = false; 104 - 105 - if (conf->listen_interval > 1) { 106 - /* Turn on wake up to listen next beacon */ 107 - vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN); 108 - wake_up = true; 109 - } 110 - 111 - return wake_up; 112 - }
-23
drivers/staging/vt6656/power.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Handles 802.11 power management functions 7 - * 8 - * Author: Lyndon Chen 9 - * 10 - * Date: July 17, 2002 11 - * 12 - */ 13 - 14 - #ifndef __POWER_H__ 15 - #define __POWER_H__ 16 - 17 - #define C_PWBT 1000 /* micro sec. power up before TBTT */ 18 - 19 - int vnt_disable_power_saving(struct vnt_private *priv); 20 - void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval); 21 - int vnt_next_tbtt_wakeup(struct vnt_private *priv); 22 - 23 - #endif /* __POWER_H__ */
-443
drivers/staging/vt6656/rf.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: rf function code 7 - * 8 - * Author: Jerry Chen 9 - * 10 - * Date: Feb. 19, 2004 11 - * 12 - * Functions: 13 - * vnt_rf_write_embedded - Embedded write RF register via MAC 14 - * 15 - * Revision History: 16 - * RF_VT3226: RobertYu:20051111, VT3226C0 and before 17 - * RF_VT3226D0: RobertYu:20051228 18 - * RF_VT3342A0: RobertYu:20060609 19 - * 20 - */ 21 - 22 - #include <linux/errno.h> 23 - #include "mac.h" 24 - #include "rf.h" 25 - #include "baseband.h" 26 - #include "usbpipe.h" 27 - 28 - #define CB_AL2230_INIT_SEQ 15 29 - #define CB_AL7230_INIT_SEQ 16 30 - #define CB_VT3226_INIT_SEQ 11 31 - #define CB_VT3342_INIT_SEQ 13 32 - 33 - static u8 al2230_init_table[CB_AL2230_INIT_SEQ][3] = { 34 - {0x03, 0xf7, 0x90}, 35 - {0x03, 0x33, 0x31}, 36 - {0x01, 0xb8, 0x02}, 37 - {0x00, 0xff, 0xf3}, 38 - {0x00, 0x05, 0xa4}, 39 - {0x0f, 0x4d, 0xc5}, 40 - {0x08, 0x05, 0xb6}, 41 - {0x01, 0x47, 0xc7}, 42 - {0x00, 0x06, 0x88}, 43 - {0x04, 0x03, 0xb9}, 44 - {0x00, 0xdb, 0xba}, 45 - {0x00, 0x09, 0x9b}, 46 - {0x0b, 0xdf, 0xfc}, 47 - {0x00, 0x00, 0x0d}, 48 - {0x00, 0x58, 0x0f} 49 - }; 50 - 51 - static u8 al2230_channel_table0[CB_MAX_CHANNEL_24G][3] = { 52 - {0x03, 0xf7, 0x90}, 53 - {0x03, 0xf7, 0x90}, 54 - {0x03, 0xe7, 0x90}, 55 - {0x03, 0xe7, 0x90}, 56 - {0x03, 0xf7, 0xa0}, 57 - {0x03, 0xf7, 0xa0}, 58 - {0x03, 0xe7, 0xa0}, 59 - {0x03, 0xe7, 0xa0}, 60 - {0x03, 0xf7, 0xb0}, 61 - {0x03, 0xf7, 0xb0}, 62 - {0x03, 0xe7, 0xb0}, 63 - {0x03, 0xe7, 0xb0}, 64 - {0x03, 0xf7, 0xc0}, 65 - {0x03, 0xe7, 0xc0} 66 - }; 67 - 68 - static u8 al2230_channel_table1[CB_MAX_CHANNEL_24G][3] = { 69 - {0x03, 0x33, 0x31}, 70 - {0x0b, 0x33, 0x31}, 71 - {0x03, 0x33, 0x31}, 72 - {0x0b, 0x33, 0x31}, 73 - {0x03, 0x33, 0x31}, 74 - {0x0b, 0x33, 0x31}, 75 - {0x03, 0x33, 0x31}, 76 - {0x0b, 0x33, 0x31}, 77 - {0x03, 0x33, 0x31}, 78 - {0x0b, 0x33, 0x31}, 79 - {0x03, 0x33, 0x31}, 80 - {0x0b, 0x33, 0x31}, 81 - {0x03, 0x33, 0x31}, 82 - {0x06, 0x66, 0x61} 83 - }; 84 - 85 - static u8 vt3226_init_table[CB_VT3226_INIT_SEQ][3] = { 86 - {0x03, 0xff, 0x80}, 87 - {0x02, 0x82, 0xa1}, 88 - {0x03, 0xc6, 0xa2}, 89 - {0x01, 0x97, 0x93}, 90 - {0x03, 0x66, 0x64}, 91 - {0x00, 0x61, 0xa5}, 92 - {0x01, 0x7b, 0xd6}, 93 - {0x00, 0x80, 0x17}, 94 - {0x03, 0xf8, 0x08}, 95 - {0x00, 0x02, 0x39}, 96 - {0x02, 0x00, 0x2a} 97 - }; 98 - 99 - static u8 vt3226d0_init_table[CB_VT3226_INIT_SEQ][3] = { 100 - {0x03, 0xff, 0x80}, 101 - {0x03, 0x02, 0x21}, 102 - {0x03, 0xc6, 0xa2}, 103 - {0x01, 0x97, 0x93}, 104 - {0x03, 0x66, 0x64}, 105 - {0x00, 0x71, 0xa5}, 106 - {0x01, 0x15, 0xc6}, 107 - {0x01, 0x2e, 0x07}, 108 - {0x00, 0x58, 0x08}, 109 - {0x00, 0x02, 0x79}, 110 - {0x02, 0x01, 0xaa} 111 - }; 112 - 113 - static u8 vt3226_channel_table0[CB_MAX_CHANNEL_24G][3] = { 114 - {0x01, 0x97, 0x83}, 115 - {0x01, 0x97, 0x83}, 116 - {0x01, 0x97, 0x93}, 117 - {0x01, 0x97, 0x93}, 118 - {0x01, 0x97, 0x93}, 119 - {0x01, 0x97, 0x93}, 120 - {0x01, 0x97, 0xa3}, 121 - {0x01, 0x97, 0xa3}, 122 - {0x01, 0x97, 0xa3}, 123 - {0x01, 0x97, 0xa3}, 124 - {0x01, 0x97, 0xb3}, 125 - {0x01, 0x97, 0xb3}, 126 - {0x01, 0x97, 0xb3}, 127 - {0x03, 0x37, 0xc3} 128 - }; 129 - 130 - static u8 vt3226_channel_table1[CB_MAX_CHANNEL_24G][3] = { 131 - {0x02, 0x66, 0x64}, 132 - {0x03, 0x66, 0x64}, 133 - {0x00, 0x66, 0x64}, 134 - {0x01, 0x66, 0x64}, 135 - {0x02, 0x66, 0x64}, 136 - {0x03, 0x66, 0x64}, 137 - {0x00, 0x66, 0x64}, 138 - {0x01, 0x66, 0x64}, 139 - {0x02, 0x66, 0x64}, 140 - {0x03, 0x66, 0x64}, 141 - {0x00, 0x66, 0x64}, 142 - {0x01, 0x66, 0x64}, 143 - {0x02, 0x66, 0x64}, 144 - {0x00, 0xcc, 0xc4} 145 - }; 146 - 147 - static const u32 vt3226d0_lo_current_table[CB_MAX_CHANNEL_24G] = { 148 - 0x0135c600, 149 - 0x0135c600, 150 - 0x0235c600, 151 - 0x0235c600, 152 - 0x0235c600, 153 - 0x0335c600, 154 - 0x0335c600, 155 - 0x0335c600, 156 - 0x0335c600, 157 - 0x0335c600, 158 - 0x0335c600, 159 - 0x0335c600, 160 - 0x0335c600, 161 - 0x0135c600 162 - }; 163 - 164 - enum { 165 - VNT_TABLE_INIT = 0, 166 - VNT_TABLE_INIT_2 = 0, 167 - VNT_TABLE_0 = 1, 168 - VNT_TABLE_1 = 2, 169 - VNT_TABLE_2 = 1 170 - }; 171 - 172 - struct vnt_table_info { 173 - u8 *addr; 174 - int length; 175 - }; 176 - 177 - static const struct vnt_table_info vnt_table_seq[][3] = { 178 - { /* RF_AL2230, RF_AL2230S init table, channel table 0 and 1 */ 179 - {&al2230_init_table[0][0], CB_AL2230_INIT_SEQ * 3}, 180 - {&al2230_channel_table0[0][0], CB_MAX_CHANNEL_24G * 3}, 181 - {&al2230_channel_table1[0][0], CB_MAX_CHANNEL_24G * 3} 182 - }, { /* RF_VT3226 init table, channel table 0 and 1 */ 183 - {&vt3226_init_table[0][0], CB_VT3226_INIT_SEQ * 3}, 184 - {&vt3226_channel_table0[0][0], CB_MAX_CHANNEL_24G * 3}, 185 - {&vt3226_channel_table1[0][0], CB_MAX_CHANNEL_24G * 3} 186 - }, { /* RF_VT3226D0 init table, channel table 0 and 1 */ 187 - {&vt3226d0_init_table[0][0], CB_VT3226_INIT_SEQ * 3}, 188 - {&vt3226_channel_table0[0][0], CB_MAX_CHANNEL_24G * 3}, 189 - {&vt3226_channel_table1[0][0], CB_MAX_CHANNEL_24G * 3} 190 - } 191 - }; 192 - 193 - /* 194 - * Description: Write to IF/RF, by embedded programming 195 - */ 196 - int vnt_rf_write_embedded(struct vnt_private *priv, u32 data) 197 - { 198 - u8 reg_data[4]; 199 - 200 - data |= (VNT_RF_REG_LEN << 3) | IFREGCTL_REGW; 201 - 202 - reg_data[0] = (u8)data; 203 - reg_data[1] = (u8)(data >> 8); 204 - reg_data[2] = (u8)(data >> 16); 205 - reg_data[3] = (u8)(data >> 24); 206 - 207 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE_IFRF, 0, 0, 208 - ARRAY_SIZE(reg_data), reg_data); 209 - } 210 - 211 - static u8 vnt_rf_addpower(struct vnt_private *priv) 212 - { 213 - int base; 214 - s32 rssi = -priv->current_rssi; 215 - 216 - if (!rssi) 217 - return 7; 218 - 219 - if (priv->rf_type == RF_VT3226D0) 220 - base = -60; 221 - else 222 - base = -70; 223 - 224 - if (rssi < base) 225 - return ((rssi - base + 1) / -5) * 2 + 5; 226 - 227 - return 0; 228 - } 229 - 230 - /* Set Tx power by power level and rate */ 231 - static int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, 232 - struct ieee80211_channel *ch) 233 - { 234 - u32 power_setting = 0; 235 - int ret = 0; 236 - 237 - power += vnt_rf_addpower(priv); 238 - if (power > VNT_RF_MAX_POWER) 239 - power = VNT_RF_MAX_POWER; 240 - 241 - if (priv->power == power) 242 - return 0; 243 - 244 - priv->power = power; 245 - 246 - switch (priv->rf_type) { 247 - case RF_AL2230: 248 - power_setting = 0x0404090 | (power << 12); 249 - 250 - ret = vnt_rf_write_embedded(priv, power_setting); 251 - if (ret) 252 - return ret; 253 - 254 - if (ch->flags & IEEE80211_CHAN_NO_OFDM) 255 - ret = vnt_rf_write_embedded(priv, 0x0001b400); 256 - else 257 - ret = vnt_rf_write_embedded(priv, 0x0005a400); 258 - 259 - break; 260 - case RF_AL2230S: 261 - power_setting = 0x0404090 | (power << 12); 262 - 263 - ret = vnt_rf_write_embedded(priv, power_setting); 264 - if (ret) 265 - return ret; 266 - 267 - if (ch->flags & IEEE80211_CHAN_NO_OFDM) { 268 - ret = vnt_rf_write_embedded(priv, 0x040c1400); 269 - if (ret) 270 - return ret; 271 - 272 - ret = vnt_rf_write_embedded(priv, 0x00299b00); 273 - } else { 274 - ret = vnt_rf_write_embedded(priv, 0x0005a400); 275 - if (ret) 276 - return ret; 277 - 278 - ret = vnt_rf_write_embedded(priv, 0x00099b00); 279 - } 280 - 281 - break; 282 - 283 - case RF_VT3226: 284 - power_setting = ((0x3f - power) << 20) | (0x17 << 8); 285 - 286 - ret = vnt_rf_write_embedded(priv, power_setting); 287 - break; 288 - case RF_VT3226D0: 289 - if (ch->flags & IEEE80211_CHAN_NO_OFDM) { 290 - u16 hw_value = ch->hw_value; 291 - 292 - power_setting = ((0x3f - power) << 20) | (0xe07 << 8); 293 - 294 - ret = vnt_rf_write_embedded(priv, power_setting); 295 - if (ret) 296 - return ret; 297 - 298 - ret = vnt_rf_write_embedded(priv, 0x03c6a200); 299 - if (ret) 300 - return ret; 301 - 302 - dev_dbg(&priv->usb->dev, 303 - "%s 11b channel [%d]\n", __func__, hw_value); 304 - 305 - hw_value--; 306 - 307 - if (hw_value < ARRAY_SIZE(vt3226d0_lo_current_table)) { 308 - ret = vnt_rf_write_embedded(priv, 309 - vt3226d0_lo_current_table[hw_value]); 310 - if (ret) 311 - return ret; 312 - } 313 - 314 - ret = vnt_rf_write_embedded(priv, 0x015C0800); 315 - } else { 316 - dev_dbg(&priv->usb->dev, 317 - "@@@@ %s> 11G mode\n", __func__); 318 - 319 - power_setting = ((0x3f - power) << 20) | (0x7 << 8); 320 - 321 - ret = vnt_rf_write_embedded(priv, power_setting); 322 - if (ret) 323 - return ret; 324 - 325 - ret = vnt_rf_write_embedded(priv, 0x00C6A200); 326 - if (ret) 327 - return ret; 328 - 329 - ret = vnt_rf_write_embedded(priv, 0x016BC600); 330 - if (ret) 331 - return ret; 332 - 333 - ret = vnt_rf_write_embedded(priv, 0x00900800); 334 - } 335 - 336 - break; 337 - 338 - default: 339 - break; 340 - } 341 - return ret; 342 - } 343 - 344 - /* Set Tx power by channel number type */ 345 - int vnt_rf_setpower(struct vnt_private *priv, 346 - struct ieee80211_channel *ch) 347 - { 348 - u16 channel; 349 - u8 power = priv->cck_pwr; 350 - 351 - if (!ch) 352 - return -EINVAL; 353 - 354 - /* set channel number to array number */ 355 - channel = ch->hw_value - 1; 356 - 357 - if (ch->flags & IEEE80211_CHAN_NO_OFDM) { 358 - if (channel < ARRAY_SIZE(priv->cck_pwr_tbl)) 359 - power = priv->cck_pwr_tbl[channel]; 360 - } else if (ch->band == NL80211_BAND_5GHZ) { 361 - /* remove 14 channels to array size */ 362 - channel -= 14; 363 - 364 - if (channel < ARRAY_SIZE(priv->ofdm_a_pwr_tbl)) 365 - power = priv->ofdm_a_pwr_tbl[channel]; 366 - } else { 367 - if (channel < ARRAY_SIZE(priv->ofdm_pwr_tbl)) 368 - power = priv->ofdm_pwr_tbl[channel]; 369 - } 370 - 371 - return vnt_rf_set_txpower(priv, power, ch); 372 - } 373 - 374 - /* Convert rssi to dbm */ 375 - void vnt_rf_rssi_to_dbm(struct vnt_private *priv, u8 rssi, long *dbm) 376 - { 377 - u8 idx = ((rssi & 0xc0) >> 6) & 0x03; 378 - long b = rssi & 0x3f; 379 - long a = 0; 380 - u8 airoharf[4] = {0, 18, 0, 40}; 381 - 382 - switch (priv->rf_type) { 383 - case RF_AL2230: 384 - case RF_AL2230S: 385 - case RF_VT3226: 386 - case RF_VT3226D0: 387 - a = airoharf[idx]; 388 - break; 389 - default: 390 - break; 391 - } 392 - 393 - *dbm = -1 * (a + b * 2); 394 - } 395 - 396 - int vnt_rf_table_download(struct vnt_private *priv) 397 - { 398 - int ret; 399 - int idx = -1; 400 - const struct vnt_table_info *table_seq; 401 - 402 - switch (priv->rf_type) { 403 - case RF_AL2230: 404 - case RF_AL2230S: 405 - idx = 0; 406 - break; 407 - case RF_VT3226: 408 - idx = 1; 409 - break; 410 - case RF_VT3226D0: 411 - idx = 2; 412 - break; 413 - } 414 - 415 - if (idx < 0) 416 - return 0; 417 - 418 - table_seq = &vnt_table_seq[idx][0]; 419 - 420 - /* Init Table */ 421 - ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0, 422 - MESSAGE_REQUEST_RF_INIT, 423 - table_seq[VNT_TABLE_INIT].length, 424 - table_seq[VNT_TABLE_INIT].addr); 425 - if (ret) 426 - return ret; 427 - 428 - /* Channel Table 0 */ 429 - ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE, 430 - MESSAGE_REQUEST_RF_CH0, 431 - table_seq[VNT_TABLE_0].length, 432 - table_seq[VNT_TABLE_0].addr); 433 - if (ret) 434 - return ret; 435 - 436 - /* Channel Table 1 */ 437 - ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE, 438 - MESSAGE_REQUEST_RF_CH1, 439 - table_seq[VNT_TABLE_1].length, 440 - table_seq[VNT_TABLE_1].addr); 441 - 442 - return ret; 443 - }
-46
drivers/staging/vt6656/rf.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: 7 - * 8 - * Author: Jerry Chen 9 - * 10 - * Date: Feb. 19, 2004 11 - * 12 - */ 13 - 14 - #ifndef __RF_H__ 15 - #define __RF_H__ 16 - 17 - #include "device.h" 18 - 19 - /* Baseband RF pair definition in eeprom (Bits 6..0) */ 20 - #define RF_RFMD2959 0x01 21 - #define RF_MAXIMAG 0x02 22 - #define RF_AL2230 0x03 23 - #define RF_GCT5103 0x04 24 - #define RF_UW2451 0x05 25 - #define RF_MAXIMG 0x06 26 - #define RF_MAXIM2829 0x07 27 - #define RF_UW2452 0x08 28 - #define RF_VT3226 0x09 29 - #define RF_AIROHA7230 0x0a 30 - #define RF_UW2453 0x0b 31 - #define RF_VT3226D0 0x0c /* RobertYu:20051114 */ 32 - #define RF_VT3342A0 0x0d /* RobertYu:20060609 */ 33 - #define RF_AL2230S 0x0e 34 - 35 - #define RF_EMU 0x80 36 - #define RF_MASK 0x7F 37 - 38 - #define VNT_RF_MAX_POWER 0x3f 39 - #define VNT_RF_REG_LEN 0x17 /* 24 bit length */ 40 - 41 - int vnt_rf_write_embedded(struct vnt_private *priv, u32 data); 42 - int vnt_rf_setpower(struct vnt_private *priv, struct ieee80211_channel *ch); 43 - void vnt_rf_rssi_to_dbm(struct vnt_private *priv, u8 rssi, long *dbm); 44 - int vnt_rf_table_download(struct vnt_private *priv); 45 - 46 - #endif /* __RF_H__ */
-730
drivers/staging/vt6656/rxtx.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: handle WMAC/802.3/802.11 rx & tx functions 7 - * 8 - * Author: Lyndon Chen 9 - * 10 - * Date: May 20, 2003 11 - * 12 - * Functions: 13 - * vnt_generate_tx_parameter - Generate tx dma required parameter. 14 - * vnt_get_rsvtime- get frame reserved time 15 - * vnt_fill_cts_head- fulfill CTS ctl header 16 - * 17 - * Revision History: 18 - * 19 - */ 20 - 21 - #include <linux/etherdevice.h> 22 - #include "device.h" 23 - #include "rxtx.h" 24 - #include "card.h" 25 - #include "mac.h" 26 - #include "rf.h" 27 - #include "usbpipe.h" 28 - 29 - static const u16 vnt_time_stampoff[2][MAX_RATE] = { 30 - /* Long Preamble */ 31 - {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, 32 - 33 - /* Short Preamble */ 34 - {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, 35 - }; 36 - 37 - #define DATADUR_B 10 38 - #define DATADUR_A 11 39 - 40 - static const u8 vnt_phy_signal[] = { 41 - 0x00, /* RATE_1M */ 42 - 0x01, /* RATE_2M */ 43 - 0x02, /* RATE_5M */ 44 - 0x03, /* RATE_11M */ 45 - 0x8b, /* RATE_6M */ 46 - 0x8f, /* RATE_9M */ 47 - 0x8a, /* RATE_12M */ 48 - 0x8e, /* RATE_18M */ 49 - 0x89, /* RATE_24M */ 50 - 0x8d, /* RATE_36M */ 51 - 0x88, /* RATE_48M */ 52 - 0x8c /* RATE_54M */ 53 - }; 54 - 55 - static struct vnt_usb_send_context 56 - *vnt_get_free_context(struct vnt_private *priv) 57 - { 58 - struct vnt_usb_send_context *context = NULL; 59 - int ii; 60 - 61 - for (ii = 0; ii < priv->num_tx_context; ii++) { 62 - if (!priv->tx_context[ii]) 63 - return NULL; 64 - 65 - context = priv->tx_context[ii]; 66 - if (!context->in_use) { 67 - context->in_use = true; 68 - return context; 69 - } 70 - } 71 - 72 - if (ii == priv->num_tx_context) { 73 - dev_dbg(&priv->usb->dev, "%s No Free Tx Context\n", __func__); 74 - 75 - ieee80211_stop_queues(priv->hw); 76 - } 77 - 78 - return NULL; 79 - } 80 - 81 - /* Get Length, Service, and Signal fields of Phy for Tx */ 82 - static void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length, 83 - u16 tx_rate, u8 pkt_type, 84 - struct vnt_phy_field *phy) 85 - { 86 - u32 bit_count; 87 - u32 count = 0; 88 - u32 tmp; 89 - int ext_bit; 90 - int i; 91 - u8 mask = 0; 92 - u8 preamble_type = priv->preamble_type; 93 - 94 - bit_count = frame_length * 8; 95 - ext_bit = false; 96 - 97 - switch (tx_rate) { 98 - case RATE_1M: 99 - count = bit_count; 100 - break; 101 - case RATE_2M: 102 - count = bit_count / 2; 103 - break; 104 - case RATE_5M: 105 - count = DIV_ROUND_UP(bit_count * 10, 55); 106 - break; 107 - case RATE_11M: 108 - count = bit_count / 11; 109 - tmp = count * 11; 110 - 111 - if (tmp != bit_count) { 112 - count++; 113 - 114 - if ((bit_count - tmp) <= 3) 115 - ext_bit = true; 116 - } 117 - 118 - break; 119 - } 120 - 121 - if (tx_rate > RATE_11M) { 122 - if (pkt_type == PK_TYPE_11A) 123 - mask = BIT(4); 124 - } else if (tx_rate > RATE_1M) { 125 - if (preamble_type == PREAMBLE_SHORT) 126 - mask = BIT(3); 127 - } 128 - 129 - i = tx_rate > RATE_54M ? RATE_54M : tx_rate; 130 - phy->signal = vnt_phy_signal[i] | mask; 131 - phy->service = 0x00; 132 - 133 - if (pkt_type == PK_TYPE_11B) { 134 - if (ext_bit) 135 - phy->service |= 0x80; 136 - phy->len = cpu_to_le16((u16)count); 137 - } else { 138 - phy->len = cpu_to_le16((u16)frame_length); 139 - } 140 - } 141 - 142 - static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate) 143 - { 144 - return cpu_to_le16(vnt_time_stampoff[priv->preamble_type % 2] 145 - [rate % MAX_RATE]); 146 - } 147 - 148 - static __le16 vnt_rxtx_rsvtime_le16(struct vnt_usb_send_context *context) 149 - { 150 - struct vnt_private *priv = context->priv; 151 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(context->skb); 152 - struct ieee80211_rate *rate = ieee80211_get_tx_rate(priv->hw, info); 153 - 154 - return ieee80211_generic_frame_duration(priv->hw, 155 - info->control.vif, info->band, 156 - context->frame_len, 157 - rate); 158 - } 159 - 160 - static __le16 vnt_get_rts_duration(struct vnt_usb_send_context *context) 161 - { 162 - struct vnt_private *priv = context->priv; 163 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(context->skb); 164 - 165 - return ieee80211_rts_duration(priv->hw, priv->vif, 166 - context->frame_len, info); 167 - } 168 - 169 - static __le16 vnt_get_cts_duration(struct vnt_usb_send_context *context) 170 - { 171 - struct vnt_private *priv = context->priv; 172 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(context->skb); 173 - 174 - return ieee80211_ctstoself_duration(priv->hw, priv->vif, 175 - context->frame_len, info); 176 - } 177 - 178 - static void vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context, 179 - struct vnt_tx_datahead_g *buf) 180 - { 181 - struct vnt_private *priv = tx_context->priv; 182 - struct ieee80211_hdr *hdr = 183 - (struct ieee80211_hdr *)tx_context->skb->data; 184 - u32 frame_len = tx_context->frame_len; 185 - u16 rate = tx_context->tx_rate; 186 - 187 - /* Get SignalField,ServiceField,Length */ 188 - vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a); 189 - vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate, 190 - PK_TYPE_11B, &buf->b); 191 - 192 - /* Get Duration and TimeStamp */ 193 - buf->duration_a = hdr->duration_id; 194 - buf->duration_b = hdr->duration_id; 195 - buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); 196 - buf->time_stamp_off_b = vnt_time_stamp_off(priv, 197 - priv->top_cck_basic_rate); 198 - } 199 - 200 - static void vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context, 201 - struct vnt_tx_datahead_ab *buf) 202 - { 203 - struct vnt_private *priv = tx_context->priv; 204 - struct ieee80211_hdr *hdr = 205 - (struct ieee80211_hdr *)tx_context->skb->data; 206 - u32 frame_len = tx_context->frame_len; 207 - u16 rate = tx_context->tx_rate; 208 - 209 - /* Get SignalField,ServiceField,Length */ 210 - vnt_get_phy_field(priv, frame_len, rate, 211 - tx_context->pkt_type, &buf->ab); 212 - 213 - /* Get Duration and TimeStampOff */ 214 - buf->duration = hdr->duration_id; 215 - buf->time_stamp_off = vnt_time_stamp_off(priv, rate); 216 - } 217 - 218 - static void vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context, 219 - struct ieee80211_rts *rts, __le16 duration) 220 - { 221 - struct ieee80211_hdr *hdr = 222 - (struct ieee80211_hdr *)tx_context->skb->data; 223 - 224 - rts->duration = duration; 225 - rts->frame_control = 226 - cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS); 227 - 228 - ether_addr_copy(rts->ra, hdr->addr1); 229 - ether_addr_copy(rts->ta, hdr->addr2); 230 - } 231 - 232 - static void vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context, 233 - struct vnt_rts_g *buf) 234 - { 235 - struct vnt_private *priv = tx_context->priv; 236 - u16 rts_frame_len = 20; 237 - 238 - vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate, 239 - PK_TYPE_11B, &buf->b); 240 - vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate, 241 - tx_context->pkt_type, &buf->a); 242 - 243 - buf->duration_bb = vnt_get_rts_duration(tx_context); 244 - buf->duration_aa = buf->duration_bb; 245 - buf->duration_ba = buf->duration_bb; 246 - 247 - vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa); 248 - 249 - vnt_rxtx_datahead_g(tx_context, &buf->data_head); 250 - } 251 - 252 - static void vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context, 253 - struct vnt_rts_ab *buf) 254 - { 255 - struct vnt_private *priv = tx_context->priv; 256 - u16 rts_frame_len = 20; 257 - 258 - vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate, 259 - tx_context->pkt_type, &buf->ab); 260 - 261 - buf->duration = vnt_get_rts_duration(tx_context); 262 - 263 - vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration); 264 - 265 - vnt_rxtx_datahead_ab(tx_context, &buf->data_head); 266 - } 267 - 268 - static void vnt_fill_cts_head(struct vnt_usb_send_context *tx_context, 269 - union vnt_tx_data_head *head) 270 - { 271 - struct vnt_private *priv = tx_context->priv; 272 - struct vnt_cts *buf = &head->cts_g; 273 - u32 cts_frame_len = 14; 274 - 275 - /* Get SignalField,ServiceField,Length */ 276 - vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate, 277 - PK_TYPE_11B, &buf->b); 278 - /* Get CTSDuration_ba */ 279 - buf->duration_ba = vnt_get_cts_duration(tx_context); 280 - /*Get CTS Frame body*/ 281 - buf->data.duration = buf->duration_ba; 282 - buf->data.frame_control = 283 - cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); 284 - 285 - ether_addr_copy(buf->data.ra, priv->current_net_addr); 286 - 287 - vnt_rxtx_datahead_g(tx_context, &buf->data_head); 288 - } 289 - 290 - /* returns true if mic_hdr is needed */ 291 - static bool vnt_fill_txkey(struct vnt_tx_buffer *tx_buffer, struct sk_buff *skb) 292 - { 293 - struct vnt_tx_fifo_head *fifo = &tx_buffer->fifo_head; 294 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 295 - struct ieee80211_key_conf *tx_key = info->control.hw_key; 296 - struct vnt_mic_hdr *mic_hdr; 297 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 298 - u64 pn64; 299 - u16 payload_len = skb->len; 300 - u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb)); 301 - 302 - /* strip header and icv len from payload */ 303 - payload_len -= ieee80211_get_hdrlen_from_skb(skb); 304 - payload_len -= tx_key->icv_len; 305 - 306 - switch (tx_key->cipher) { 307 - case WLAN_CIPHER_SUITE_WEP40: 308 - case WLAN_CIPHER_SUITE_WEP104: 309 - memcpy(fifo->tx_key, iv, 3); 310 - memcpy(fifo->tx_key + 3, tx_key->key, tx_key->keylen); 311 - 312 - if (tx_key->keylen == WLAN_KEY_LEN_WEP40) { 313 - memcpy(fifo->tx_key + 8, iv, 3); 314 - memcpy(fifo->tx_key + 11, 315 - tx_key->key, WLAN_KEY_LEN_WEP40); 316 - } 317 - 318 - fifo->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY); 319 - break; 320 - case WLAN_CIPHER_SUITE_TKIP: 321 - ieee80211_get_tkip_p2k(tx_key, skb, fifo->tx_key); 322 - 323 - fifo->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP); 324 - break; 325 - case WLAN_CIPHER_SUITE_CCMP: 326 - if (info->control.use_cts_prot) { 327 - if (info->control.use_rts) 328 - mic_hdr = &tx_buffer->tx_head.tx_rts.tx.mic.hdr; 329 - else 330 - mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr; 331 - } else { 332 - mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr; 333 - } 334 - 335 - mic_hdr->id = 0x59; 336 - mic_hdr->payload_len = cpu_to_be16(payload_len); 337 - ether_addr_copy(mic_hdr->mic_addr2, hdr->addr2); 338 - 339 - pn64 = atomic64_read(&tx_key->tx_pn); 340 - mic_hdr->ccmp_pn[5] = pn64; 341 - mic_hdr->ccmp_pn[4] = pn64 >> 8; 342 - mic_hdr->ccmp_pn[3] = pn64 >> 16; 343 - mic_hdr->ccmp_pn[2] = pn64 >> 24; 344 - mic_hdr->ccmp_pn[1] = pn64 >> 32; 345 - mic_hdr->ccmp_pn[0] = pn64 >> 40; 346 - 347 - if (ieee80211_has_a4(hdr->frame_control)) 348 - mic_hdr->hlen = cpu_to_be16(28); 349 - else 350 - mic_hdr->hlen = cpu_to_be16(22); 351 - 352 - ether_addr_copy(mic_hdr->addr1, hdr->addr1); 353 - ether_addr_copy(mic_hdr->addr2, hdr->addr2); 354 - ether_addr_copy(mic_hdr->addr3, hdr->addr3); 355 - 356 - mic_hdr->frame_control = cpu_to_le16(le16_to_cpu(hdr->frame_control) & 0xc78f); 357 - mic_hdr->seq_ctrl = cpu_to_le16(le16_to_cpu(hdr->seq_ctrl) & 0xf); 358 - 359 - if (ieee80211_has_a4(hdr->frame_control)) 360 - ether_addr_copy(mic_hdr->addr4, hdr->addr4); 361 - 362 - memcpy(fifo->tx_key, tx_key->key, WLAN_KEY_LEN_CCMP); 363 - 364 - fifo->frag_ctl |= cpu_to_le16(FRAGCTL_AES); 365 - return true; 366 - default: 367 - break; 368 - } 369 - 370 - return false; 371 - } 372 - 373 - static void vnt_rxtx_rts(struct vnt_usb_send_context *tx_context) 374 - { 375 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_context->skb); 376 - struct vnt_tx_buffer *tx_buffer = tx_context->tx_buffer; 377 - union vnt_tx_head *tx_head = &tx_buffer->tx_head; 378 - struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts; 379 - union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head; 380 - 381 - buf->rts_rrv_time_aa = vnt_get_rts_duration(tx_context); 382 - buf->rts_rrv_time_ba = buf->rts_rrv_time_aa; 383 - buf->rts_rrv_time_bb = buf->rts_rrv_time_aa; 384 - 385 - buf->rrv_time_a = vnt_rxtx_rsvtime_le16(tx_context); 386 - buf->rrv_time_b = buf->rrv_time_a; 387 - 388 - if (info->control.hw_key) { 389 - if (vnt_fill_txkey(tx_buffer, tx_context->skb)) 390 - head = &tx_head->tx_rts.tx.mic.head; 391 - } 392 - 393 - vnt_rxtx_rts_g_head(tx_context, &head->rts_g); 394 - } 395 - 396 - static void vnt_rxtx_cts(struct vnt_usb_send_context *tx_context) 397 - { 398 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_context->skb); 399 - struct vnt_tx_buffer *tx_buffer = tx_context->tx_buffer; 400 - union vnt_tx_head *tx_head = &tx_buffer->tx_head; 401 - struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts; 402 - union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head; 403 - 404 - buf->rrv_time_a = vnt_rxtx_rsvtime_le16(tx_context); 405 - buf->rrv_time_b = buf->rrv_time_a; 406 - 407 - buf->cts_rrv_time_ba = vnt_get_cts_duration(tx_context); 408 - 409 - if (info->control.hw_key) { 410 - if (vnt_fill_txkey(tx_buffer, tx_context->skb)) 411 - head = &tx_head->tx_cts.tx.mic.head; 412 - } 413 - 414 - vnt_fill_cts_head(tx_context, head); 415 - } 416 - 417 - static void vnt_rxtx_ab(struct vnt_usb_send_context *tx_context) 418 - { 419 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_context->skb); 420 - struct vnt_tx_buffer *tx_buffer = tx_context->tx_buffer; 421 - union vnt_tx_head *tx_head = &tx_buffer->tx_head; 422 - struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab; 423 - union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head; 424 - 425 - buf->rrv_time = vnt_rxtx_rsvtime_le16(tx_context); 426 - 427 - if (info->control.hw_key) { 428 - if (vnt_fill_txkey(tx_buffer, tx_context->skb)) 429 - head = &tx_head->tx_ab.tx.mic.head; 430 - } 431 - 432 - if (info->control.use_rts) { 433 - buf->rts_rrv_time = vnt_get_rts_duration(tx_context); 434 - 435 - vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab); 436 - 437 - return; 438 - } 439 - 440 - vnt_rxtx_datahead_ab(tx_context, &head->data_head_ab); 441 - } 442 - 443 - static void vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context) 444 - { 445 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_context->skb); 446 - 447 - if (info->control.use_cts_prot) { 448 - if (info->control.use_rts) { 449 - vnt_rxtx_rts(tx_context); 450 - 451 - return; 452 - } 453 - 454 - vnt_rxtx_cts(tx_context); 455 - 456 - return; 457 - } 458 - 459 - vnt_rxtx_ab(tx_context); 460 - } 461 - 462 - static u16 vnt_get_hdr_size(struct ieee80211_tx_info *info) 463 - { 464 - u16 size = sizeof(struct vnt_tx_datahead_ab); 465 - 466 - if (info->control.use_cts_prot) { 467 - if (info->control.use_rts) 468 - size = sizeof(struct vnt_rts_g); 469 - else 470 - size = sizeof(struct vnt_cts); 471 - } else if (info->control.use_rts) { 472 - size = sizeof(struct vnt_rts_ab); 473 - } 474 - 475 - if (info->control.hw_key) { 476 - if (info->control.hw_key->cipher == WLAN_CIPHER_SUITE_CCMP) 477 - size += sizeof(struct vnt_mic_hdr); 478 - } 479 - 480 - /* Get rrv_time header */ 481 - if (info->control.use_cts_prot) { 482 - if (info->control.use_rts) 483 - size += sizeof(struct vnt_rrv_time_rts); 484 - else 485 - size += sizeof(struct vnt_rrv_time_cts); 486 - } else { 487 - size += sizeof(struct vnt_rrv_time_ab); 488 - } 489 - 490 - size += sizeof(struct vnt_tx_fifo_head); 491 - 492 - return size; 493 - } 494 - 495 - int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) 496 - { 497 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 498 - struct ieee80211_tx_rate *tx_rate = &info->control.rates[0]; 499 - struct ieee80211_rate *rate; 500 - struct ieee80211_hdr *hdr; 501 - struct vnt_tx_buffer *tx_buffer; 502 - struct vnt_tx_fifo_head *tx_buffer_head; 503 - struct vnt_usb_send_context *tx_context; 504 - unsigned long flags; 505 - u8 pkt_type; 506 - 507 - hdr = (struct ieee80211_hdr *)(skb->data); 508 - 509 - rate = ieee80211_get_tx_rate(priv->hw, info); 510 - 511 - if (rate->hw_value > RATE_11M) { 512 - if (info->band == NL80211_BAND_5GHZ) { 513 - pkt_type = PK_TYPE_11A; 514 - } else { 515 - if (tx_rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { 516 - if (priv->basic_rates & VNT_B_RATES) 517 - pkt_type = PK_TYPE_11GB; 518 - else 519 - pkt_type = PK_TYPE_11GA; 520 - } else { 521 - pkt_type = PK_TYPE_11A; 522 - } 523 - } 524 - } else { 525 - pkt_type = PK_TYPE_11B; 526 - } 527 - 528 - spin_lock_irqsave(&priv->lock, flags); 529 - 530 - tx_context = vnt_get_free_context(priv); 531 - if (!tx_context) { 532 - dev_dbg(&priv->usb->dev, "%s No free context\n", __func__); 533 - spin_unlock_irqrestore(&priv->lock, flags); 534 - return -ENOMEM; 535 - } 536 - 537 - tx_context->pkt_type = pkt_type; 538 - tx_context->frame_len = skb->len + 4; 539 - tx_context->tx_rate = rate->hw_value; 540 - 541 - spin_unlock_irqrestore(&priv->lock, flags); 542 - 543 - tx_context->skb = skb_clone(skb, GFP_ATOMIC); 544 - if (!tx_context->skb) { 545 - tx_context->in_use = false; 546 - return -ENOMEM; 547 - } 548 - 549 - tx_buffer = skb_push(skb, vnt_get_hdr_size(info)); 550 - tx_context->tx_buffer = tx_buffer; 551 - tx_buffer_head = &tx_buffer->fifo_head; 552 - 553 - tx_context->type = CONTEXT_DATA_PACKET; 554 - 555 - /*Set fifo controls */ 556 - if (pkt_type == PK_TYPE_11A) 557 - tx_buffer_head->fifo_ctl = 0; 558 - else if (pkt_type == PK_TYPE_11B) 559 - tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11B); 560 - else if (pkt_type == PK_TYPE_11GB) 561 - tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GB); 562 - else if (pkt_type == PK_TYPE_11GA) 563 - tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GA); 564 - 565 - if (!ieee80211_is_data(hdr->frame_control)) { 566 - tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT | 567 - FIFOCTL_ISDMA0); 568 - tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_TMOEN); 569 - 570 - tx_buffer_head->time_stamp = 571 - cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); 572 - } else { 573 - tx_buffer_head->time_stamp = 574 - cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us); 575 - } 576 - 577 - if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) 578 - tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_NEEDACK); 579 - 580 - if (ieee80211_has_retry(hdr->frame_control)) 581 - tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LRETRY); 582 - 583 - if (info->control.use_rts) 584 - tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_RTS); 585 - 586 - if (ieee80211_has_a4(hdr->frame_control)) 587 - tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LHEAD); 588 - 589 - tx_buffer_head->frag_ctl = 590 - cpu_to_le16(ieee80211_hdrlen(hdr->frame_control) << 10); 591 - 592 - if (info->control.hw_key) 593 - tx_context->frame_len += info->control.hw_key->icv_len; 594 - 595 - tx_buffer_head->current_rate = cpu_to_le16(rate->hw_value); 596 - 597 - vnt_generate_tx_parameter(tx_context); 598 - 599 - tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG); 600 - 601 - priv->seq_counter = (le16_to_cpu(hdr->seq_ctrl) & 602 - IEEE80211_SCTL_SEQ) >> 4; 603 - 604 - spin_lock_irqsave(&priv->lock, flags); 605 - 606 - if (vnt_tx_context(priv, tx_context, skb)) { 607 - dev_kfree_skb(tx_context->skb); 608 - spin_unlock_irqrestore(&priv->lock, flags); 609 - return -EIO; 610 - } 611 - 612 - dev_kfree_skb(skb); 613 - 614 - spin_unlock_irqrestore(&priv->lock, flags); 615 - 616 - return 0; 617 - } 618 - 619 - static int vnt_beacon_xmit(struct vnt_private *priv, struct sk_buff *skb) 620 - { 621 - struct vnt_tx_short_buf_head *short_head; 622 - struct ieee80211_tx_info *info; 623 - struct vnt_usb_send_context *context; 624 - struct ieee80211_mgmt *mgmt_hdr; 625 - unsigned long flags; 626 - u32 frame_size = skb->len + 4; 627 - u16 current_rate; 628 - 629 - spin_lock_irqsave(&priv->lock, flags); 630 - 631 - context = vnt_get_free_context(priv); 632 - if (!context) { 633 - dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__); 634 - spin_unlock_irqrestore(&priv->lock, flags); 635 - return -ENOMEM; 636 - } 637 - 638 - context->skb = skb; 639 - 640 - spin_unlock_irqrestore(&priv->lock, flags); 641 - 642 - mgmt_hdr = (struct ieee80211_mgmt *)skb->data; 643 - short_head = skb_push(skb, sizeof(*short_head)); 644 - 645 - if (priv->bb_type == BB_TYPE_11A) { 646 - current_rate = RATE_6M; 647 - 648 - /* Get SignalField,ServiceField,Length */ 649 - vnt_get_phy_field(priv, frame_size, current_rate, 650 - PK_TYPE_11A, &short_head->ab); 651 - 652 - /* Get TimeStampOff */ 653 - short_head->time_stamp_off = 654 - vnt_time_stamp_off(priv, current_rate); 655 - } else { 656 - current_rate = RATE_1M; 657 - short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B); 658 - 659 - /* Get SignalField,ServiceField,Length */ 660 - vnt_get_phy_field(priv, frame_size, current_rate, 661 - PK_TYPE_11B, &short_head->ab); 662 - 663 - /* Get TimeStampOff */ 664 - short_head->time_stamp_off = 665 - vnt_time_stamp_off(priv, current_rate); 666 - } 667 - 668 - /* Get Duration */ 669 - short_head->duration = mgmt_hdr->duration; 670 - 671 - /* time stamp always 0 */ 672 - mgmt_hdr->u.beacon.timestamp = 0; 673 - 674 - info = IEEE80211_SKB_CB(skb); 675 - if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { 676 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr; 677 - 678 - hdr->duration_id = 0; 679 - hdr->seq_ctrl = cpu_to_le16(priv->seq_counter << 4); 680 - } 681 - 682 - priv->seq_counter++; 683 - if (priv->seq_counter > 0x0fff) 684 - priv->seq_counter = 0; 685 - 686 - context->type = CONTEXT_BEACON_PACKET; 687 - 688 - spin_lock_irqsave(&priv->lock, flags); 689 - 690 - if (vnt_tx_context(priv, context, skb)) 691 - ieee80211_free_txskb(priv->hw, context->skb); 692 - 693 - spin_unlock_irqrestore(&priv->lock, flags); 694 - 695 - return 0; 696 - } 697 - 698 - int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif) 699 - { 700 - struct sk_buff *beacon; 701 - 702 - beacon = ieee80211_beacon_get(priv->hw, vif, 0); 703 - if (!beacon) 704 - return -ENOMEM; 705 - 706 - if (vnt_beacon_xmit(priv, beacon)) { 707 - ieee80211_free_txskb(priv->hw, beacon); 708 - return -ENODEV; 709 - } 710 - 711 - return 0; 712 - } 713 - 714 - int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif, 715 - struct ieee80211_bss_conf *conf) 716 - { 717 - vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX); 718 - 719 - vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); 720 - 721 - vnt_mac_set_beacon_interval(priv, conf->beacon_int); 722 - 723 - vnt_clear_current_tsf(priv); 724 - 725 - vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); 726 - 727 - vnt_reset_next_tbtt(priv, conf->beacon_int); 728 - 729 - return vnt_beacon_make(priv, vif); 730 - }
-178
drivers/staging/vt6656/rxtx.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: 7 - * 8 - * Author: Jerry Chen 9 - * 10 - * Date: Jun. 27, 2002 11 - * 12 - */ 13 - 14 - #ifndef __RXTX_H__ 15 - #define __RXTX_H__ 16 - 17 - #include "device.h" 18 - #include "wcmd.h" 19 - #include "baseband.h" 20 - 21 - #define DEFAULT_MGN_LIFETIME_RES_64us 125 /* 64us */ 22 - #define DEFAULT_MSDU_LIFETIME_RES_64us 8000 23 - 24 - /* Length, Service, and Signal fields of Phy for Tx */ 25 - struct vnt_phy_field { 26 - u8 signal; 27 - u8 service; 28 - __le16 len; 29 - } __packed; 30 - 31 - /* MIC HDR data header */ 32 - struct vnt_mic_hdr { 33 - u8 id; 34 - u8 tx_priority; 35 - u8 mic_addr2[6]; 36 - u8 ccmp_pn[IEEE80211_CCMP_PN_LEN]; 37 - __be16 payload_len; 38 - __be16 hlen; 39 - __le16 frame_control; 40 - u8 addr1[6]; 41 - u8 addr2[6]; 42 - u8 addr3[6]; 43 - __le16 seq_ctrl; 44 - u8 addr4[6]; 45 - u16 packing; /* packing to 48 bytes */ 46 - } __packed; 47 - 48 - /* RsvTime buffer header */ 49 - struct vnt_rrv_time_rts { 50 - __le16 rts_rrv_time_ba; 51 - __le16 rts_rrv_time_aa; 52 - __le16 rts_rrv_time_bb; 53 - u16 wReserved; 54 - __le16 rrv_time_b; 55 - __le16 rrv_time_a; 56 - } __packed; 57 - 58 - struct vnt_rrv_time_cts { 59 - __le16 cts_rrv_time_ba; 60 - u16 wReserved; 61 - __le16 rrv_time_b; 62 - __le16 rrv_time_a; 63 - } __packed; 64 - 65 - struct vnt_rrv_time_ab { 66 - __le16 rts_rrv_time; 67 - __le16 rrv_time; 68 - } __packed; 69 - 70 - /* TX data header */ 71 - struct vnt_tx_datahead_g { 72 - struct vnt_phy_field b; 73 - struct vnt_phy_field a; 74 - __le16 duration_b; 75 - __le16 duration_a; 76 - __le16 time_stamp_off_b; 77 - __le16 time_stamp_off_a; 78 - } __packed; 79 - 80 - struct vnt_tx_datahead_ab { 81 - struct vnt_phy_field ab; 82 - __le16 duration; 83 - __le16 time_stamp_off; 84 - } __packed; 85 - 86 - /* RTS buffer header */ 87 - struct vnt_rts_g { 88 - struct vnt_phy_field b; 89 - struct vnt_phy_field a; 90 - __le16 duration_ba; 91 - __le16 duration_aa; 92 - __le16 duration_bb; 93 - u16 wReserved; 94 - struct ieee80211_rts data; 95 - struct vnt_tx_datahead_g data_head; 96 - } __packed __aligned(2); 97 - 98 - struct vnt_rts_ab { 99 - struct vnt_phy_field ab; 100 - __le16 duration; 101 - u16 wReserved; 102 - struct ieee80211_rts data; 103 - struct vnt_tx_datahead_ab data_head; 104 - } __packed __aligned(2); 105 - 106 - /* CTS buffer header */ 107 - struct vnt_cts { 108 - struct vnt_phy_field b; 109 - __le16 duration_ba; 110 - u16 wReserved; 111 - struct ieee80211_cts data; 112 - u16 reserved2; 113 - struct vnt_tx_datahead_g data_head; 114 - } __packed __aligned(2); 115 - 116 - union vnt_tx_data_head { 117 - /* rts g */ 118 - struct vnt_rts_g rts_g; 119 - /* rts a/b */ 120 - struct vnt_rts_ab rts_ab; 121 - /* cts g */ 122 - struct vnt_cts cts_g; 123 - /* no rts/cts */ 124 - struct vnt_tx_datahead_ab data_head_ab; 125 - }; 126 - 127 - struct vnt_tx_mic_hdr { 128 - struct vnt_mic_hdr hdr; 129 - union vnt_tx_data_head head; 130 - } __packed; 131 - 132 - union vnt_tx { 133 - struct vnt_tx_mic_hdr mic; 134 - union vnt_tx_data_head head; 135 - }; 136 - 137 - union vnt_tx_head { 138 - struct { 139 - struct vnt_rrv_time_rts rts; 140 - union vnt_tx tx; 141 - } __packed tx_rts; 142 - struct { 143 - struct vnt_rrv_time_cts cts; 144 - union vnt_tx tx; 145 - } __packed tx_cts; 146 - struct { 147 - struct vnt_rrv_time_ab ab; 148 - union vnt_tx tx; 149 - } __packed tx_ab; 150 - }; 151 - 152 - struct vnt_tx_fifo_head { 153 - u8 tx_key[WLAN_KEY_LEN_CCMP]; 154 - __le16 fifo_ctl; 155 - __le16 time_stamp; 156 - __le16 frag_ctl; 157 - __le16 current_rate; 158 - } __packed; 159 - 160 - struct vnt_tx_buffer { 161 - struct vnt_tx_fifo_head fifo_head; 162 - union vnt_tx_head tx_head; 163 - } __packed; 164 - 165 - struct vnt_tx_short_buf_head { 166 - __le16 fifo_ctl; 167 - u16 time_stamp; 168 - struct vnt_phy_field ab; 169 - __le16 duration; 170 - __le16 time_stamp_off; 171 - } __packed; 172 - 173 - int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb); 174 - int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif); 175 - int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif, 176 - struct ieee80211_bss_conf *conf); 177 - 178 - #endif /* __RXTX_H__ */
-506
drivers/staging/vt6656/usbpipe.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Handle USB control endpoint 7 - * 8 - * Author: Warren Hsu 9 - * 10 - * Date: Mar. 29, 2005 11 - * 12 - * Functions: 13 - * vnt_control_out - Write variable length bytes to MEM/BB/MAC/EEPROM 14 - * vnt_control_in - Read variable length bytes from MEM/BB/MAC/EEPROM 15 - * vnt_control_out_u8 - Write one byte to MEM/BB/MAC/EEPROM 16 - * vnt_control_in_u8 - Read one byte from MEM/BB/MAC/EEPROM 17 - * 18 - * Revision History: 19 - * 04-05-2004 Jerry Chen: Initial release 20 - * 11-24-2004 Warren Hsu: Add ControlvWriteByte,ControlvReadByte, 21 - * ControlvMaskByte 22 - * 23 - */ 24 - 25 - #include "rxtx.h" 26 - #include "desc.h" 27 - #include "device.h" 28 - #include "usbpipe.h" 29 - #include "mac.h" 30 - #include "rf.h" 31 - 32 - #define USB_CTL_WAIT 500 /* ms */ 33 - 34 - int vnt_control_out(struct vnt_private *priv, u8 request, u16 value, 35 - u16 index, u16 length, const u8 *buffer) 36 - { 37 - int ret = 0; 38 - u8 *usb_buffer; 39 - 40 - if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags)) { 41 - ret = -EINVAL; 42 - goto end; 43 - } 44 - 45 - mutex_lock(&priv->usb_lock); 46 - 47 - usb_buffer = kmemdup(buffer, length, GFP_KERNEL); 48 - if (!usb_buffer) { 49 - ret = -ENOMEM; 50 - goto end_unlock; 51 - } 52 - 53 - ret = usb_control_msg(priv->usb, 54 - usb_sndctrlpipe(priv->usb, 0), 55 - request, 0x40, value, 56 - index, usb_buffer, length, USB_CTL_WAIT); 57 - 58 - kfree(usb_buffer); 59 - 60 - if (ret == (int)length) 61 - ret = 0; 62 - else 63 - ret = -EIO; 64 - 65 - end_unlock: 66 - mutex_unlock(&priv->usb_lock); 67 - end: 68 - return ret; 69 - } 70 - 71 - int vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 data) 72 - { 73 - return vnt_control_out(priv, MESSAGE_TYPE_WRITE, 74 - reg_off, reg, sizeof(u8), &data); 75 - } 76 - 77 - int vnt_control_out_blocks(struct vnt_private *priv, 78 - u16 block, u8 reg, u16 length, const u8 *data) 79 - { 80 - int ret = 0, i; 81 - 82 - for (i = 0; i < length; i += block) { 83 - u16 len = min_t(int, length - i, block); 84 - 85 - ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 86 - i, reg, len, data + i); 87 - if (ret) 88 - goto end; 89 - } 90 - end: 91 - return ret; 92 - } 93 - 94 - int vnt_control_in(struct vnt_private *priv, u8 request, u16 value, 95 - u16 index, u16 length, u8 *buffer) 96 - { 97 - int ret = 0; 98 - u8 *usb_buffer; 99 - 100 - if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags)) { 101 - ret = -EINVAL; 102 - goto end; 103 - } 104 - 105 - mutex_lock(&priv->usb_lock); 106 - 107 - usb_buffer = kmalloc(length, GFP_KERNEL); 108 - if (!usb_buffer) { 109 - ret = -ENOMEM; 110 - goto end_unlock; 111 - } 112 - 113 - ret = usb_control_msg(priv->usb, 114 - usb_rcvctrlpipe(priv->usb, 0), 115 - request, 0xc0, value, 116 - index, usb_buffer, length, USB_CTL_WAIT); 117 - 118 - if (ret == length) 119 - memcpy(buffer, usb_buffer, length); 120 - 121 - kfree(usb_buffer); 122 - 123 - if (ret == (int)length) 124 - ret = 0; 125 - else 126 - ret = -EIO; 127 - 128 - end_unlock: 129 - mutex_unlock(&priv->usb_lock); 130 - end: 131 - return ret; 132 - } 133 - 134 - int vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data) 135 - { 136 - return vnt_control_in(priv, MESSAGE_TYPE_READ, 137 - reg_off, reg, sizeof(u8), data); 138 - } 139 - 140 - static int vnt_int_report_rate(struct vnt_private *priv, u8 pkt_no, u8 tsr) 141 - { 142 - struct vnt_usb_send_context *context; 143 - struct ieee80211_tx_info *info; 144 - u8 tx_retry = (tsr & 0xf0) >> 4; 145 - s8 idx; 146 - 147 - if (pkt_no >= priv->num_tx_context) 148 - return -EINVAL; 149 - 150 - context = priv->tx_context[pkt_no]; 151 - 152 - if (!context->skb) 153 - return -EINVAL; 154 - 155 - info = IEEE80211_SKB_CB(context->skb); 156 - idx = info->control.rates[0].idx; 157 - 158 - ieee80211_tx_info_clear_status(info); 159 - 160 - info->status.rates[0].count = tx_retry; 161 - 162 - if (!(tsr & TSR_TMO)) { 163 - info->status.rates[0].idx = idx; 164 - 165 - if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) 166 - info->flags |= IEEE80211_TX_STAT_ACK; 167 - } 168 - 169 - ieee80211_tx_status_irqsafe(priv->hw, context->skb); 170 - 171 - context->in_use = false; 172 - 173 - return 0; 174 - } 175 - 176 - static void vnt_int_process_data(struct vnt_private *priv) 177 - { 178 - struct vnt_interrupt_data *int_data; 179 - struct ieee80211_low_level_stats *low_stats = &priv->low_stats; 180 - 181 - dev_dbg(&priv->usb->dev, "---->s_nsInterruptProcessData\n"); 182 - 183 - int_data = (struct vnt_interrupt_data *)priv->int_buf.data_buf; 184 - 185 - if (int_data->tsr0 & TSR_VALID) 186 - vnt_int_report_rate(priv, int_data->pkt0, int_data->tsr0); 187 - 188 - if (int_data->tsr1 & TSR_VALID) 189 - vnt_int_report_rate(priv, int_data->pkt1, int_data->tsr1); 190 - 191 - if (int_data->tsr2 & TSR_VALID) 192 - vnt_int_report_rate(priv, int_data->pkt2, int_data->tsr2); 193 - 194 - if (int_data->tsr3 & TSR_VALID) 195 - vnt_int_report_rate(priv, int_data->pkt3, int_data->tsr3); 196 - 197 - if (!int_data->isr0) 198 - return; 199 - 200 - if (int_data->isr0 & ISR_BNTX && priv->op_mode == NL80211_IFTYPE_AP) 201 - vnt_schedule_command(priv, WLAN_CMD_BECON_SEND); 202 - 203 - priv->current_tsf = le64_to_cpu(int_data->tsf); 204 - 205 - low_stats->dot11RTSSuccessCount += int_data->rts_success; 206 - low_stats->dot11RTSFailureCount += int_data->rts_fail; 207 - low_stats->dot11ACKFailureCount += int_data->ack_fail; 208 - low_stats->dot11FCSErrorCount += int_data->fcs_err; 209 - } 210 - 211 - static void vnt_start_interrupt_urb_complete(struct urb *urb) 212 - { 213 - struct vnt_private *priv = urb->context; 214 - int status = urb->status; 215 - 216 - switch (status) { 217 - case 0: 218 - case -ETIMEDOUT: 219 - break; 220 - case -ECONNRESET: 221 - case -ENOENT: 222 - case -ESHUTDOWN: 223 - return; 224 - default: 225 - break; 226 - } 227 - 228 - if (status) 229 - dev_dbg(&priv->usb->dev, "%s status = %d\n", __func__, status); 230 - else 231 - vnt_int_process_data(priv); 232 - 233 - if (!test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags)) 234 - status = usb_submit_urb(priv->interrupt_urb, GFP_ATOMIC); 235 - 236 - if (status) 237 - dev_dbg(&priv->usb->dev, "Submit int URB failed %d\n", status); 238 - } 239 - 240 - int vnt_start_interrupt_urb(struct vnt_private *priv) 241 - { 242 - int ret = 0; 243 - 244 - dev_dbg(&priv->usb->dev, "---->Interrupt Polling Thread\n"); 245 - 246 - usb_fill_int_urb(priv->interrupt_urb, 247 - priv->usb, 248 - usb_rcvintpipe(priv->usb, 1), 249 - priv->int_buf.data_buf, 250 - MAX_INTERRUPT_SIZE, 251 - vnt_start_interrupt_urb_complete, 252 - priv, 253 - priv->int_interval); 254 - 255 - ret = usb_submit_urb(priv->interrupt_urb, GFP_ATOMIC); 256 - if (ret) 257 - dev_dbg(&priv->usb->dev, "Submit int URB failed %d\n", ret); 258 - 259 - return ret; 260 - } 261 - 262 - static int vnt_rx_data(struct vnt_private *priv, struct vnt_rcb *ptr_rcb, 263 - unsigned long bytes_received) 264 - { 265 - struct ieee80211_hw *hw = priv->hw; 266 - struct ieee80211_supported_band *sband; 267 - struct sk_buff *skb; 268 - struct ieee80211_rx_status *rx_status; 269 - struct vnt_rx_header *head; 270 - struct vnt_rx_tail *tail; 271 - u32 frame_size; 272 - int ii; 273 - u16 rx_bitrate, pay_load_with_padding; 274 - u8 rate_idx = 0; 275 - long rx_dbm; 276 - 277 - skb = ptr_rcb->skb; 278 - rx_status = IEEE80211_SKB_RXCB(skb); 279 - 280 - /* [31:16]RcvByteCount ( not include 4-byte Status ) */ 281 - head = (struct vnt_rx_header *)skb->data; 282 - frame_size = head->wbk_status >> 16; 283 - frame_size += 4; 284 - 285 - if (bytes_received != frame_size) { 286 - dev_dbg(&priv->usb->dev, "------- WRONG Length 1\n"); 287 - return false; 288 - } 289 - 290 - if ((bytes_received > 2372) || (bytes_received <= 40)) { 291 - /* Frame Size error drop this packet.*/ 292 - dev_dbg(&priv->usb->dev, "------ WRONG Length 2\n"); 293 - return false; 294 - } 295 - 296 - /* real Frame Size = USBframe_size -4WbkStatus - 4RxStatus */ 297 - /* -8TSF - 4RSR - 4SQ3 - ?Padding */ 298 - 299 - /* if SQ3 the range is 24~27, if no SQ3 the range is 20~23 */ 300 - 301 - /*Fix hardware bug => PLCP_Length error */ 302 - if (((bytes_received - head->pay_load_len) > 27) || 303 - ((bytes_received - head->pay_load_len) < 24) || 304 - (bytes_received < head->pay_load_len)) { 305 - dev_dbg(&priv->usb->dev, "Wrong PLCP Length %x\n", 306 - head->pay_load_len); 307 - return false; 308 - } 309 - 310 - sband = hw->wiphy->bands[hw->conf.chandef.chan->band]; 311 - rx_bitrate = head->rx_rate * 5; /* rx_rate * 5 */ 312 - 313 - for (ii = 0; ii < sband->n_bitrates; ii++) { 314 - if (sband->bitrates[ii].bitrate == rx_bitrate) { 315 - rate_idx = ii; 316 - break; 317 - } 318 - } 319 - 320 - if (ii == sband->n_bitrates) { 321 - dev_dbg(&priv->usb->dev, "Wrong Rx Bit Rate %d\n", rx_bitrate); 322 - return false; 323 - } 324 - 325 - pay_load_with_padding = ((head->pay_load_len / 4) + 326 - ((head->pay_load_len % 4) ? 1 : 0)) * 4; 327 - 328 - tail = (struct vnt_rx_tail *)(skb->data + 329 - sizeof(*head) + pay_load_with_padding); 330 - priv->tsf_time = le64_to_cpu(tail->tsf_time); 331 - 332 - if (tail->rsr & (RSR_IVLDTYP | RSR_IVLDLEN)) 333 - return false; 334 - 335 - vnt_rf_rssi_to_dbm(priv, tail->rssi, &rx_dbm); 336 - 337 - priv->bb_pre_ed_rssi = (u8)-rx_dbm + 1; 338 - priv->current_rssi = priv->bb_pre_ed_rssi; 339 - 340 - skb_pull(skb, sizeof(*head)); 341 - skb_trim(skb, head->pay_load_len); 342 - 343 - rx_status->mactime = priv->tsf_time; 344 - rx_status->band = hw->conf.chandef.chan->band; 345 - rx_status->signal = rx_dbm; 346 - rx_status->flag = 0; 347 - rx_status->freq = hw->conf.chandef.chan->center_freq; 348 - 349 - if (!(tail->rsr & RSR_CRCOK)) 350 - rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; 351 - 352 - rx_status->rate_idx = rate_idx; 353 - 354 - if (tail->new_rsr & NEWRSR_DECRYPTOK) 355 - rx_status->flag |= RX_FLAG_DECRYPTED; 356 - 357 - ieee80211_rx_irqsafe(priv->hw, skb); 358 - 359 - return true; 360 - } 361 - 362 - static void vnt_submit_rx_urb_complete(struct urb *urb) 363 - { 364 - struct vnt_rcb *rcb = urb->context; 365 - struct vnt_private *priv = rcb->priv; 366 - 367 - switch (urb->status) { 368 - case 0: 369 - break; 370 - case -ECONNRESET: 371 - case -ENOENT: 372 - case -ESHUTDOWN: 373 - return; 374 - case -ETIMEDOUT: 375 - default: 376 - dev_dbg(&priv->usb->dev, "BULK In failed %d\n", urb->status); 377 - break; 378 - } 379 - 380 - if (urb->actual_length) { 381 - if (vnt_rx_data(priv, rcb, urb->actual_length)) { 382 - rcb->skb = dev_alloc_skb(priv->rx_buf_sz); 383 - if (!rcb->skb) 384 - return; 385 - } else { 386 - skb_push(rcb->skb, skb_headroom(rcb->skb)); 387 - skb_trim(rcb->skb, 0); 388 - } 389 - 390 - urb->transfer_buffer = skb_put(rcb->skb, 391 - skb_tailroom(rcb->skb)); 392 - } 393 - 394 - if (usb_submit_urb(urb, GFP_ATOMIC)) 395 - dev_dbg(&priv->usb->dev, "Failed to re submit rx skb\n"); 396 - } 397 - 398 - int vnt_submit_rx_urb(struct vnt_private *priv, struct vnt_rcb *rcb) 399 - { 400 - int ret = 0; 401 - struct urb *urb = rcb->urb; 402 - 403 - if (!rcb->skb) { 404 - dev_dbg(&priv->usb->dev, "rcb->skb is null\n"); 405 - ret = -EINVAL; 406 - goto end; 407 - } 408 - 409 - usb_fill_bulk_urb(urb, 410 - priv->usb, 411 - usb_rcvbulkpipe(priv->usb, 2), 412 - skb_put(rcb->skb, skb_tailroom(rcb->skb)), 413 - MAX_TOTAL_SIZE_WITH_ALL_HEADERS, 414 - vnt_submit_rx_urb_complete, 415 - rcb); 416 - 417 - ret = usb_submit_urb(urb, GFP_ATOMIC); 418 - if (ret) 419 - dev_dbg(&priv->usb->dev, "Submit Rx URB failed %d\n", ret); 420 - end: 421 - return ret; 422 - } 423 - 424 - static void vnt_tx_context_complete(struct urb *urb) 425 - { 426 - struct vnt_usb_send_context *context = urb->context; 427 - struct vnt_private *priv = context->priv; 428 - 429 - switch (urb->status) { 430 - case 0: 431 - dev_dbg(&priv->usb->dev, 432 - "Write %d bytes\n", urb->actual_length); 433 - break; 434 - case -ECONNRESET: 435 - case -ENOENT: 436 - case -ESHUTDOWN: 437 - context->in_use = false; 438 - return; 439 - case -ETIMEDOUT: 440 - default: 441 - dev_dbg(&priv->usb->dev, "BULK Out failed %d\n", urb->status); 442 - break; 443 - } 444 - 445 - if (context->type == CONTEXT_DATA_PACKET) 446 - ieee80211_wake_queues(priv->hw); 447 - 448 - if (urb->status || context->type == CONTEXT_BEACON_PACKET) { 449 - if (context->skb) 450 - ieee80211_free_txskb(priv->hw, context->skb); 451 - 452 - context->in_use = false; 453 - } 454 - } 455 - 456 - int vnt_tx_context(struct vnt_private *priv, 457 - struct vnt_usb_send_context *context, 458 - struct sk_buff *skb) 459 - { 460 - struct vnt_tx_usb_header *usb; 461 - struct urb *urb; 462 - int status; 463 - u16 count = skb->len; 464 - 465 - usb = skb_push(skb, sizeof(*usb)); 466 - usb->tx_byte_count = cpu_to_le16(count); 467 - usb->pkt_no = context->pkt_no; 468 - usb->type = context->type; 469 - 470 - if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags)) { 471 - context->in_use = false; 472 - return -ENODEV; 473 - } 474 - 475 - if (skb->len > MAX_TOTAL_SIZE_WITH_ALL_HEADERS) { 476 - context->in_use = false; 477 - return -E2BIG; 478 - } 479 - 480 - urb = usb_alloc_urb(0, GFP_ATOMIC); 481 - if (!urb) { 482 - context->in_use = false; 483 - return -ENOMEM; 484 - } 485 - 486 - usb_fill_bulk_urb(urb, 487 - priv->usb, 488 - usb_sndbulkpipe(priv->usb, 3), 489 - skb->data, 490 - skb->len, 491 - vnt_tx_context_complete, 492 - context); 493 - 494 - usb_anchor_urb(urb, &priv->tx_submitted); 495 - 496 - status = usb_submit_urb(urb, GFP_ATOMIC); 497 - if (status) { 498 - dev_dbg(&priv->usb->dev, "Submit Tx URB failed %d\n", status); 499 - usb_unanchor_urb(urb); 500 - context->in_use = false; 501 - } 502 - 503 - usb_free_urb(urb); 504 - 505 - return status; 506 - }
-67
drivers/staging/vt6656/usbpipe.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: 7 - * 8 - * Author: Warren Hsu 9 - * 10 - * Date: Mar. 30, 2005 11 - * 12 - */ 13 - 14 - #ifndef __USBPIPE_H__ 15 - #define __USBPIPE_H__ 16 - 17 - #include "device.h" 18 - 19 - struct vnt_interrupt_data { 20 - u8 tsr0; 21 - u8 pkt0; 22 - u16 time0; 23 - u8 tsr1; 24 - u8 pkt1; 25 - u16 time1; 26 - u8 tsr2; 27 - u8 pkt2; 28 - u16 time2; 29 - u8 tsr3; 30 - u8 pkt3; 31 - u16 time3; 32 - __le64 tsf; 33 - u8 isr0; 34 - u8 isr1; 35 - u8 rts_success; 36 - u8 rts_fail; 37 - u8 ack_fail; 38 - u8 fcs_err; 39 - u8 sw[2]; 40 - } __packed; 41 - 42 - struct vnt_tx_usb_header { 43 - u8 type; 44 - u8 pkt_no; 45 - __le16 tx_byte_count; 46 - } __packed; 47 - 48 - #define VNT_REG_BLOCK_SIZE 64 49 - 50 - int vnt_control_out(struct vnt_private *priv, u8 request, u16 value, 51 - u16 index, u16 length, const u8 *buffer); 52 - int vnt_control_in(struct vnt_private *priv, u8 request, u16 value, 53 - u16 index, u16 length, u8 *buffer); 54 - 55 - int vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 ref_off, u8 data); 56 - int vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data); 57 - 58 - int vnt_control_out_blocks(struct vnt_private *priv, 59 - u16 block, u8 reg, u16 len, const u8 *data); 60 - 61 - int vnt_start_interrupt_urb(struct vnt_private *priv); 62 - int vnt_submit_rx_urb(struct vnt_private *priv, struct vnt_rcb *rcb); 63 - int vnt_tx_context(struct vnt_private *priv, 64 - struct vnt_usb_send_context *context, 65 - struct sk_buff *skb); 66 - 67 - #endif /* __USBPIPE_H__ */
-185
drivers/staging/vt6656/wcmd.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Handles the management command interface functions 7 - * 8 - * Author: Lyndon Chen 9 - * 10 - * Date: May 8, 2003 11 - * 12 - * Functions: 13 - * vnt_cmd_complete - Command Complete function 14 - * vnt_schedule_command - Push Command and wait Command Scheduler to do 15 - * vnt_cmd_timer_wait- Call back timer 16 - * 17 - * Revision History: 18 - * 19 - */ 20 - 21 - #include "device.h" 22 - #include "mac.h" 23 - #include "wcmd.h" 24 - #include "power.h" 25 - #include "usbpipe.h" 26 - #include "rxtx.h" 27 - #include "rf.h" 28 - 29 - static void vnt_cmd_timer_wait(struct vnt_private *priv, unsigned long msecs) 30 - { 31 - schedule_delayed_work(&priv->run_command_work, msecs_to_jiffies(msecs)); 32 - } 33 - 34 - static u32 add_one_with_wrap_around(u32 var, u8 modulo) 35 - { 36 - if (var >= (modulo - 1)) 37 - var = 0; 38 - else 39 - var++; 40 - return var; 41 - } 42 - 43 - static int vnt_cmd_complete(struct vnt_private *priv) 44 - { 45 - priv->command_state = WLAN_CMD_IDLE; 46 - if (priv->free_cmd_queue == CMD_Q_SIZE) { 47 - /* Command Queue Empty */ 48 - priv->cmd_running = false; 49 - return true; 50 - } 51 - 52 - priv->command = priv->cmd_queue[priv->cmd_dequeue_idx]; 53 - 54 - priv->cmd_dequeue_idx = add_one_with_wrap_around(priv->cmd_dequeue_idx, CMD_Q_SIZE); 55 - priv->free_cmd_queue++; 56 - priv->cmd_running = true; 57 - 58 - switch (priv->command) { 59 - case WLAN_CMD_INIT_MAC80211: 60 - priv->command_state = WLAN_CMD_INIT_MAC80211_START; 61 - break; 62 - 63 - case WLAN_CMD_TBTT_WAKEUP: 64 - priv->command_state = WLAN_CMD_TBTT_WAKEUP_START; 65 - break; 66 - 67 - case WLAN_CMD_BECON_SEND: 68 - priv->command_state = WLAN_CMD_BECON_SEND_START; 69 - break; 70 - 71 - case WLAN_CMD_SETPOWER: 72 - priv->command_state = WLAN_CMD_SETPOWER_START; 73 - break; 74 - 75 - case WLAN_CMD_CHANGE_ANTENNA: 76 - priv->command_state = WLAN_CMD_CHANGE_ANTENNA_START; 77 - break; 78 - 79 - default: 80 - break; 81 - } 82 - 83 - vnt_cmd_timer_wait(priv, 0); 84 - 85 - return true; 86 - } 87 - 88 - void vnt_run_command(struct work_struct *work) 89 - { 90 - struct vnt_private *priv = 91 - container_of(work, struct vnt_private, run_command_work.work); 92 - 93 - if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags)) 94 - return; 95 - 96 - if (!priv->cmd_running) 97 - return; 98 - 99 - switch (priv->command_state) { 100 - case WLAN_CMD_INIT_MAC80211_START: 101 - if (priv->mac_hw) 102 - break; 103 - 104 - dev_info(&priv->usb->dev, "Starting mac80211\n"); 105 - 106 - if (vnt_init(priv)) { 107 - /* If fail all ends TODO retry */ 108 - dev_err(&priv->usb->dev, "failed to start\n"); 109 - usb_set_intfdata(priv->intf, NULL); 110 - ieee80211_free_hw(priv->hw); 111 - return; 112 - } 113 - 114 - break; 115 - 116 - case WLAN_CMD_TBTT_WAKEUP_START: 117 - vnt_next_tbtt_wakeup(priv); 118 - break; 119 - 120 - case WLAN_CMD_BECON_SEND_START: 121 - if (!priv->vif) 122 - break; 123 - 124 - vnt_beacon_make(priv, priv->vif); 125 - 126 - vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX); 127 - 128 - break; 129 - 130 - case WLAN_CMD_SETPOWER_START: 131 - 132 - vnt_rf_setpower(priv, priv->hw->conf.chandef.chan); 133 - 134 - break; 135 - 136 - case WLAN_CMD_CHANGE_ANTENNA_START: 137 - dev_dbg(&priv->usb->dev, "Change from Antenna%d to", 138 - priv->rx_antenna_sel); 139 - 140 - if (priv->rx_antenna_sel == 0) { 141 - priv->rx_antenna_sel = 1; 142 - if (priv->tx_rx_ant_inv) 143 - vnt_set_antenna_mode(priv, ANT_RXA); 144 - else 145 - vnt_set_antenna_mode(priv, ANT_RXB); 146 - } else { 147 - priv->rx_antenna_sel = 0; 148 - if (priv->tx_rx_ant_inv) 149 - vnt_set_antenna_mode(priv, ANT_RXB); 150 - else 151 - vnt_set_antenna_mode(priv, ANT_RXA); 152 - } 153 - break; 154 - 155 - default: 156 - break; 157 - } 158 - 159 - vnt_cmd_complete(priv); 160 - } 161 - 162 - int vnt_schedule_command(struct vnt_private *priv, enum vnt_cmd command) 163 - { 164 - if (priv->free_cmd_queue == 0) 165 - return false; 166 - 167 - priv->cmd_queue[priv->cmd_enqueue_idx] = command; 168 - 169 - priv->cmd_enqueue_idx = add_one_with_wrap_around(priv->cmd_enqueue_idx, CMD_Q_SIZE); 170 - priv->free_cmd_queue--; 171 - 172 - if (!priv->cmd_running) 173 - vnt_cmd_complete(priv); 174 - 175 - return true; 176 - } 177 - 178 - void vnt_reset_command_timer(struct vnt_private *priv) 179 - { 180 - priv->free_cmd_queue = CMD_Q_SIZE; 181 - priv->cmd_dequeue_idx = 0; 182 - priv->cmd_enqueue_idx = 0; 183 - priv->command_state = WLAN_CMD_IDLE; 184 - priv->cmd_running = false; 185 - }
-48
drivers/staging/vt6656/wcmd.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 - * All rights reserved. 5 - * 6 - * Purpose: Handles the management command interface functions 7 - * 8 - * Author: Lyndon Chen 9 - * 10 - * Date: May 8, 2002 11 - * 12 - */ 13 - 14 - #ifndef __WCMD_H__ 15 - #define __WCMD_H__ 16 - 17 - #include "device.h" 18 - 19 - /* Command code */ 20 - enum vnt_cmd { 21 - WLAN_CMD_INIT_MAC80211, 22 - WLAN_CMD_SETPOWER, 23 - WLAN_CMD_TBTT_WAKEUP, 24 - WLAN_CMD_BECON_SEND, 25 - WLAN_CMD_CHANGE_ANTENNA 26 - }; 27 - 28 - #define CMD_Q_SIZE 32 29 - 30 - /* Command state */ 31 - enum vnt_cmd_state { 32 - WLAN_CMD_INIT_MAC80211_START, 33 - WLAN_CMD_SETPOWER_START, 34 - WLAN_CMD_TBTT_WAKEUP_START, 35 - WLAN_CMD_BECON_SEND_START, 36 - WLAN_CMD_CHANGE_ANTENNA_START, 37 - WLAN_CMD_IDLE 38 - }; 39 - 40 - struct vnt_private; 41 - 42 - void vnt_reset_command_timer(struct vnt_private *priv); 43 - 44 - int vnt_schedule_command(struct vnt_private *priv, enum vnt_cmd); 45 - 46 - void vnt_run_command(struct work_struct *work); 47 - 48 - #endif /* __WCMD_H__ */