device.h 8.7 KB

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