device.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. *
  16. * File: device.h
  17. *
  18. * Purpose: MAC Data structure
  19. *
  20. * Author: Tevin Chen
  21. *
  22. * Date: Mar 17, 1997
  23. *
  24. */
  25. #ifndef __DEVICE_H__
  26. #define __DEVICE_H__
  27. #include <linux/module.h>
  28. #include <linux/kernel.h>
  29. #include <linux/slab.h>
  30. #include <linux/delay.h>
  31. #include <linux/device.h>
  32. #include <linux/firmware.h>
  33. #include <linux/suspend.h>
  34. #include <linux/if_arp.h>
  35. #include <linux/wireless.h>
  36. #include <linux/timer.h>
  37. #include <linux/usb.h>
  38. #include <linux/crc32.h>
  39. #include <net/mac80211.h>
  40. #ifdef SIOCETHTOOL
  41. #define DEVICE_ETHTOOL_IOCTL_SUPPORT
  42. #include <linux/ethtool.h>
  43. #else
  44. #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
  45. #endif
  46. #define RATE_1M 0
  47. #define RATE_2M 1
  48. #define RATE_5M 2
  49. #define RATE_11M 3
  50. #define RATE_6M 4
  51. #define RATE_9M 5
  52. #define RATE_12M 6
  53. #define RATE_18M 7
  54. #define RATE_24M 8
  55. #define RATE_36M 9
  56. #define RATE_48M 10
  57. #define RATE_54M 11
  58. #define RATE_AUTO 12
  59. #define MAX_RATE 12
  60. /*
  61. * device specific
  62. */
  63. #include "wcmd.h"
  64. #include "desc.h"
  65. #include "key.h"
  66. #include "card.h"
  67. #define VNT_USB_VENDOR_ID 0x160a
  68. #define VNT_USB_PRODUCT_ID 0x3184
  69. #define DEVICE_NAME "vt6656"
  70. #define DEVICE_FULL_DRV_NAM "VIA Networking Wireless LAN USB Driver"
  71. #define DEVICE_VERSION "mac80211"
  72. #define CONFIG_PATH "/etc/vntconfiguration.dat"
  73. #define MAX_UINTS 8
  74. #define OPTION_DEFAULT { [0 ... MAX_UINTS-1] = -1}
  75. #define DUPLICATE_RX_CACHE_LENGTH 5
  76. #define AUTO_FB_NONE 0
  77. #define AUTO_FB_0 1
  78. #define AUTO_FB_1 2
  79. #define FB_RATE0 0
  80. #define FB_RATE1 1
  81. /* Antenna Mode */
  82. #define ANT_A 0
  83. #define ANT_B 1
  84. #define ANT_DIVERSITY 2
  85. #define ANT_RXD_TXA 3
  86. #define ANT_RXD_TXB 4
  87. #define ANT_UNKNOWN 0xFF
  88. #define ANT_TXA 0
  89. #define ANT_TXB 1
  90. #define ANT_RXA 2
  91. #define ANT_RXB 3
  92. #define BB_VGA_LEVEL 4
  93. #define BB_VGA_CHANGE_THRESHOLD 3
  94. #define EEP_MAX_CONTEXT_SIZE 256
  95. /* Contents in the EEPROM */
  96. #define EEP_OFS_PAR 0x0
  97. #define EEP_OFS_ANTENNA 0x17
  98. #define EEP_OFS_RADIOCTL 0x18
  99. #define EEP_OFS_RFTYPE 0x1b
  100. #define EEP_OFS_MINCHANNEL 0x1c
  101. #define EEP_OFS_MAXCHANNEL 0x1d
  102. #define EEP_OFS_SIGNATURE 0x1e
  103. #define EEP_OFS_ZONETYPE 0x1f
  104. #define EEP_OFS_RFTABLE 0x20
  105. #define EEP_OFS_PWR_CCK 0x20
  106. #define EEP_OFS_SETPT_CCK 0x21
  107. #define EEP_OFS_PWR_OFDMG 0x23
  108. #define EEP_OFS_CALIB_TX_IQ 0x24
  109. #define EEP_OFS_CALIB_TX_DC 0x25
  110. #define EEP_OFS_CALIB_RX_IQ 0x26
  111. #define EEP_OFS_MAJOR_VER 0x2e
  112. #define EEP_OFS_MINOR_VER 0x2f
  113. #define EEP_OFS_CCK_PWR_TBL 0x30
  114. #define EEP_OFS_OFDM_PWR_TBL 0x40
  115. #define EEP_OFS_OFDMA_PWR_TBL 0x50
  116. /* Bits in EEP_OFS_ANTENNA */
  117. #define EEP_ANTENNA_MAIN 0x1
  118. #define EEP_ANTENNA_AUX 0x2
  119. #define EEP_ANTINV 0x4
  120. /* Bits in EEP_OFS_RADIOCTL */
  121. #define EEP_RADIOCTL_ENABLE 0x80
  122. /* control commands */
  123. #define MESSAGE_TYPE_READ 0x1
  124. #define MESSAGE_TYPE_WRITE 0x0
  125. #define MESSAGE_TYPE_LOCK_OR 0x2
  126. #define MESSAGE_TYPE_LOCK_AND 0x3
  127. #define MESSAGE_TYPE_WRITE_MASK 0x4
  128. #define MESSAGE_TYPE_CARDINIT 0x5
  129. #define MESSAGE_TYPE_INIT_RSP 0x6
  130. #define MESSAGE_TYPE_MACSHUTDOWN 0x7
  131. #define MESSAGE_TYPE_SETKEY 0x8
  132. #define MESSAGE_TYPE_CLRKEYENTRY 0x9
  133. #define MESSAGE_TYPE_WRITE_MISCFF 0xa
  134. #define MESSAGE_TYPE_SET_ANTMD 0xb
  135. #define MESSAGE_TYPE_SELECT_CHANNEL 0xc
  136. #define MESSAGE_TYPE_SET_TSFTBTT 0xd
  137. #define MESSAGE_TYPE_SET_SSTIFS 0xe
  138. #define MESSAGE_TYPE_CHANGE_BBTYPE 0xf
  139. #define MESSAGE_TYPE_DISABLE_PS 0x10
  140. #define MESSAGE_TYPE_WRITE_IFRF 0x11
  141. /* command read/write(index) */
  142. #define MESSAGE_REQUEST_MEM 0x1
  143. #define MESSAGE_REQUEST_BBREG 0x2
  144. #define MESSAGE_REQUEST_MACREG 0x3
  145. #define MESSAGE_REQUEST_EEPROM 0x4
  146. #define MESSAGE_REQUEST_TSF 0x5
  147. #define MESSAGE_REQUEST_TBTT 0x6
  148. #define MESSAGE_REQUEST_BBAGC 0x7
  149. #define MESSAGE_REQUEST_VERSION 0x8
  150. #define MESSAGE_REQUEST_RF_INIT 0x9
  151. #define MESSAGE_REQUEST_RF_INIT2 0xa
  152. #define MESSAGE_REQUEST_RF_CH0 0xb
  153. #define MESSAGE_REQUEST_RF_CH1 0xc
  154. #define MESSAGE_REQUEST_RF_CH2 0xd
  155. /* USB registers */
  156. #define USB_REG4 0x604
  157. #define DEVICE_INIT_COLD 0x0 /* cold init */
  158. #define DEVICE_INIT_RESET 0x1 /* reset init or Dx to D0 power remain */
  159. #define DEVICE_INIT_DXPL 0x2 /* Dx to D0 power lost init */
  160. /* Device init */
  161. struct vnt_cmd_card_init {
  162. u8 init_class;
  163. u8 exist_sw_net_addr;
  164. u8 sw_net_addr[6];
  165. u8 short_retry_limit;
  166. u8 long_retry_limit;
  167. };
  168. struct vnt_rsp_card_init {
  169. u8 status;
  170. u8 net_addr[6];
  171. u8 rf_type;
  172. u8 min_channel;
  173. u8 max_channel;
  174. };
  175. /* USB */
  176. /*
  177. * Enum of context types for SendPacket
  178. */
  179. enum {
  180. CONTEXT_DATA_PACKET = 1,
  181. CONTEXT_MGMT_PACKET,
  182. CONTEXT_BEACON_PACKET
  183. };
  184. /* RCB (Receive Control Block) */
  185. struct vnt_rcb {
  186. void *priv;
  187. struct urb *urb;
  188. struct sk_buff *skb;
  189. int in_use;
  190. };
  191. /* used to track bulk out irps */
  192. struct vnt_usb_send_context {
  193. void *priv;
  194. struct sk_buff *skb;
  195. struct urb *urb;
  196. struct ieee80211_hdr *hdr;
  197. unsigned int buf_len;
  198. u32 frame_len;
  199. u16 tx_hdr_size;
  200. u16 tx_rate;
  201. u8 type;
  202. u8 pkt_no;
  203. u8 pkt_type;
  204. u8 need_ack;
  205. u8 fb_option;
  206. bool in_use;
  207. unsigned char data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
  208. };
  209. /*
  210. * Structure to keep track of USB interrupt packets
  211. */
  212. struct vnt_interrupt_buffer {
  213. u8 *data_buf;
  214. bool in_use;
  215. };
  216. /*++ NDIS related */
  217. enum {
  218. STATUS_SUCCESS = 0,
  219. STATUS_FAILURE,
  220. STATUS_RESOURCES,
  221. STATUS_PENDING,
  222. };
  223. /* flags for options */
  224. #define DEVICE_FLAGS_UNPLUG 0
  225. #define DEVICE_FLAGS_DISCONNECTED 1
  226. struct vnt_private {
  227. /* mac80211 */
  228. struct ieee80211_hw *hw;
  229. struct ieee80211_vif *vif;
  230. u8 mac_hw;
  231. /* netdev */
  232. struct usb_device *usb;
  233. u64 tsf_time;
  234. u8 rx_rate;
  235. u32 rx_buf_sz;
  236. int mc_list_count;
  237. spinlock_t lock;
  238. struct mutex usb_lock;
  239. unsigned long flags;
  240. /* USB */
  241. struct urb *interrupt_urb;
  242. u32 int_interval;
  243. /* Variables to track resources for the BULK In Pipe */
  244. struct vnt_rcb *rcb[CB_MAX_RX_DESC];
  245. u32 num_rcb;
  246. /* Variables to track resources for the BULK Out Pipe */
  247. struct vnt_usb_send_context *tx_context[CB_MAX_TX_DESC];
  248. u32 num_tx_context;
  249. /* Variables to track resources for the Interrupt In Pipe */
  250. struct vnt_interrupt_buffer int_buf;
  251. /* Version control */
  252. u16 firmware_version;
  253. u8 local_id;
  254. u8 rf_type;
  255. u8 bb_rx_conf;
  256. struct vnt_cmd_card_init init_command;
  257. struct vnt_rsp_card_init init_response;
  258. u8 current_net_addr[ETH_ALEN] __aligned(2);
  259. u8 permanent_net_addr[ETH_ALEN] __aligned(2);
  260. u8 exist_sw_net_addr;
  261. u64 current_tsf;
  262. /* 802.11 MAC specific */
  263. u32 current_rssi;
  264. /* Antenna Diversity */
  265. int tx_rx_ant_inv;
  266. u32 rx_antenna_sel;
  267. u8 rx_antenna_mode;
  268. u8 tx_antenna_mode;
  269. u8 radio_ctl;
  270. /* IFS & Cw */
  271. u32 sifs; /* Current SIFS */
  272. u32 difs; /* Current DIFS */
  273. u32 eifs; /* Current EIFS */
  274. u32 slot; /* Current SlotTime */
  275. /* Rate */
  276. u8 bb_type; /* 0: 11A, 1:11B, 2:11G */
  277. u8 packet_type; /* 0:11a 1:11b 2:11gb 3:11ga */
  278. u32 basic_rates;
  279. u8 top_ofdm_basic_rate;
  280. u8 top_cck_basic_rate;
  281. u8 eeprom[EEP_MAX_CONTEXT_SIZE]; /*u32 alignment */
  282. u8 preamble_type;
  283. /* For RF Power table */
  284. u8 cck_pwr;
  285. u8 ofdm_pwr_g;
  286. u8 ofdm_pwr_a;
  287. u8 power;
  288. u8 cck_pwr_tbl[14];
  289. u8 ofdm_pwr_tbl[14];
  290. u8 ofdm_a_pwr_tbl[42];
  291. u16 current_rate;
  292. u16 tx_rate_fb0;
  293. u16 tx_rate_fb1;
  294. u8 short_retry_limit;
  295. u8 long_retry_limit;
  296. enum nl80211_iftype op_mode;
  297. int short_slot_time;
  298. /* Power save */
  299. u16 current_aid;
  300. /* Beacon related */
  301. u16 seq_counter;
  302. enum vnt_cmd_state command_state;
  303. enum vnt_cmd command;
  304. /* 802.11 counter */
  305. enum vnt_cmd cmd_queue[CMD_Q_SIZE];
  306. u32 cmd_dequeue_idx;
  307. u32 cmd_enqueue_idx;
  308. u32 free_cmd_queue;
  309. int cmd_running;
  310. unsigned long key_entry_inuse;
  311. u8 auto_fb_ctrl;
  312. /* For Update BaseBand VGA Gain Offset */
  313. u8 bb_vga[BB_VGA_LEVEL];
  314. u8 bb_pre_ed_rssi;
  315. u8 bb_pre_ed_index;
  316. u16 wake_up_count;
  317. /* command timer */
  318. struct delayed_work run_command_work;
  319. struct ieee80211_low_level_stats low_stats;
  320. };
  321. #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
  322. if ((uVar) >= ((uModulo) - 1)) \
  323. (uVar) = 0; \
  324. else \
  325. (uVar)++; \
  326. }
  327. int vnt_init(struct vnt_private *priv);
  328. #endif