device.h 8.1 KB

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