wl1251.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /*
  2. * This file is part of wl1251
  3. *
  4. * Copyright (c) 1998-2007 Texas Instruments Incorporated
  5. * Copyright (C) 2008-2009 Nokia Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. *
  21. */
  22. #ifndef __WL1251_H__
  23. #define __WL1251_H__
  24. #include <linux/mutex.h>
  25. #include <linux/list.h>
  26. #include <linux/bitops.h>
  27. #include <net/mac80211.h>
  28. #define DRIVER_NAME "wl1251"
  29. #define DRIVER_PREFIX DRIVER_NAME ": "
  30. enum {
  31. DEBUG_NONE = 0,
  32. DEBUG_IRQ = BIT(0),
  33. DEBUG_SPI = BIT(1),
  34. DEBUG_BOOT = BIT(2),
  35. DEBUG_MAILBOX = BIT(3),
  36. DEBUG_NETLINK = BIT(4),
  37. DEBUG_EVENT = BIT(5),
  38. DEBUG_TX = BIT(6),
  39. DEBUG_RX = BIT(7),
  40. DEBUG_SCAN = BIT(8),
  41. DEBUG_CRYPT = BIT(9),
  42. DEBUG_PSM = BIT(10),
  43. DEBUG_MAC80211 = BIT(11),
  44. DEBUG_CMD = BIT(12),
  45. DEBUG_ACX = BIT(13),
  46. DEBUG_ALL = ~0,
  47. };
  48. #define DEBUG_LEVEL (DEBUG_NONE)
  49. #define DEBUG_DUMP_LIMIT 1024
  50. #define wl1251_error(fmt, arg...) \
  51. printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
  52. #define wl1251_warning(fmt, arg...) \
  53. printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
  54. #define wl1251_notice(fmt, arg...) \
  55. printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
  56. #define wl1251_info(fmt, arg...) \
  57. printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
  58. #define wl1251_debug(level, fmt, arg...) \
  59. do { \
  60. if (level & DEBUG_LEVEL) \
  61. printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
  62. } while (0)
  63. #define wl1251_dump(level, prefix, buf, len) \
  64. do { \
  65. if (level & DEBUG_LEVEL) \
  66. print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
  67. DUMP_PREFIX_OFFSET, 16, 1, \
  68. buf, \
  69. min_t(size_t, len, DEBUG_DUMP_LIMIT), \
  70. 0); \
  71. } while (0)
  72. #define wl1251_dump_ascii(level, prefix, buf, len) \
  73. do { \
  74. if (level & DEBUG_LEVEL) \
  75. print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
  76. DUMP_PREFIX_OFFSET, 16, 1, \
  77. buf, \
  78. min_t(size_t, len, DEBUG_DUMP_LIMIT), \
  79. true); \
  80. } while (0)
  81. #define WL1251_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
  82. CFG_MC_FILTER_EN | \
  83. CFG_BSSID_FILTER_EN)
  84. #define WL1251_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN | \
  85. CFG_RX_MGMT_EN | \
  86. CFG_RX_DATA_EN | \
  87. CFG_RX_CTL_EN | \
  88. CFG_RX_BCN_EN | \
  89. CFG_RX_AUTH_EN | \
  90. CFG_RX_ASSOC_EN)
  91. #define WL1251_BUSY_WORD_LEN 8
  92. struct boot_attr {
  93. u32 radio_type;
  94. u8 mac_clock;
  95. u8 arm_clock;
  96. int firmware_debug;
  97. u32 minor;
  98. u32 major;
  99. u32 bugfix;
  100. };
  101. enum wl1251_state {
  102. WL1251_STATE_OFF,
  103. WL1251_STATE_ON,
  104. WL1251_STATE_PLT,
  105. };
  106. enum wl1251_partition_type {
  107. PART_DOWN,
  108. PART_WORK,
  109. PART_DRPW,
  110. PART_TABLE_LEN
  111. };
  112. enum wl1251_station_mode {
  113. STATION_ACTIVE_MODE,
  114. STATION_POWER_SAVE_MODE,
  115. STATION_IDLE,
  116. };
  117. struct wl1251_partition {
  118. u32 size;
  119. u32 start;
  120. };
  121. struct wl1251_partition_set {
  122. struct wl1251_partition mem;
  123. struct wl1251_partition reg;
  124. };
  125. struct wl1251;
  126. struct wl1251_stats {
  127. struct acx_statistics *fw_stats;
  128. unsigned long fw_stats_update;
  129. unsigned int retry_count;
  130. unsigned int excessive_retries;
  131. };
  132. struct wl1251_debugfs {
  133. struct dentry *rootdir;
  134. struct dentry *fw_statistics;
  135. struct dentry *tx_internal_desc_overflow;
  136. struct dentry *rx_out_of_mem;
  137. struct dentry *rx_hdr_overflow;
  138. struct dentry *rx_hw_stuck;
  139. struct dentry *rx_dropped;
  140. struct dentry *rx_fcs_err;
  141. struct dentry *rx_xfr_hint_trig;
  142. struct dentry *rx_path_reset;
  143. struct dentry *rx_reset_counter;
  144. struct dentry *dma_rx_requested;
  145. struct dentry *dma_rx_errors;
  146. struct dentry *dma_tx_requested;
  147. struct dentry *dma_tx_errors;
  148. struct dentry *isr_cmd_cmplt;
  149. struct dentry *isr_fiqs;
  150. struct dentry *isr_rx_headers;
  151. struct dentry *isr_rx_mem_overflow;
  152. struct dentry *isr_rx_rdys;
  153. struct dentry *isr_irqs;
  154. struct dentry *isr_tx_procs;
  155. struct dentry *isr_decrypt_done;
  156. struct dentry *isr_dma0_done;
  157. struct dentry *isr_dma1_done;
  158. struct dentry *isr_tx_exch_complete;
  159. struct dentry *isr_commands;
  160. struct dentry *isr_rx_procs;
  161. struct dentry *isr_hw_pm_mode_changes;
  162. struct dentry *isr_host_acknowledges;
  163. struct dentry *isr_pci_pm;
  164. struct dentry *isr_wakeups;
  165. struct dentry *isr_low_rssi;
  166. struct dentry *wep_addr_key_count;
  167. struct dentry *wep_default_key_count;
  168. /* skipping wep.reserved */
  169. struct dentry *wep_key_not_found;
  170. struct dentry *wep_decrypt_fail;
  171. struct dentry *wep_packets;
  172. struct dentry *wep_interrupt;
  173. struct dentry *pwr_ps_enter;
  174. struct dentry *pwr_elp_enter;
  175. struct dentry *pwr_missing_bcns;
  176. struct dentry *pwr_wake_on_host;
  177. struct dentry *pwr_wake_on_timer_exp;
  178. struct dentry *pwr_tx_with_ps;
  179. struct dentry *pwr_tx_without_ps;
  180. struct dentry *pwr_rcvd_beacons;
  181. struct dentry *pwr_power_save_off;
  182. struct dentry *pwr_enable_ps;
  183. struct dentry *pwr_disable_ps;
  184. struct dentry *pwr_fix_tsf_ps;
  185. /* skipping cont_miss_bcns_spread for now */
  186. struct dentry *pwr_rcvd_awake_beacons;
  187. struct dentry *mic_rx_pkts;
  188. struct dentry *mic_calc_failure;
  189. struct dentry *aes_encrypt_fail;
  190. struct dentry *aes_decrypt_fail;
  191. struct dentry *aes_encrypt_packets;
  192. struct dentry *aes_decrypt_packets;
  193. struct dentry *aes_encrypt_interrupt;
  194. struct dentry *aes_decrypt_interrupt;
  195. struct dentry *event_heart_beat;
  196. struct dentry *event_calibration;
  197. struct dentry *event_rx_mismatch;
  198. struct dentry *event_rx_mem_empty;
  199. struct dentry *event_rx_pool;
  200. struct dentry *event_oom_late;
  201. struct dentry *event_phy_transmit_error;
  202. struct dentry *event_tx_stuck;
  203. struct dentry *ps_pspoll_timeouts;
  204. struct dentry *ps_upsd_timeouts;
  205. struct dentry *ps_upsd_max_sptime;
  206. struct dentry *ps_upsd_max_apturn;
  207. struct dentry *ps_pspoll_max_apturn;
  208. struct dentry *ps_pspoll_utilization;
  209. struct dentry *ps_upsd_utilization;
  210. struct dentry *rxpipe_rx_prep_beacon_drop;
  211. struct dentry *rxpipe_descr_host_int_trig_rx_data;
  212. struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
  213. struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
  214. struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
  215. struct dentry *tx_queue_len;
  216. struct dentry *tx_queue_status;
  217. struct dentry *retry_count;
  218. struct dentry *excessive_retries;
  219. };
  220. struct wl1251_if_operations {
  221. void (*read)(struct wl1251 *wl, int addr, void *buf, size_t len);
  222. void (*write)(struct wl1251 *wl, int addr, void *buf, size_t len);
  223. void (*read_elp)(struct wl1251 *wl, int addr, u32 *val);
  224. void (*write_elp)(struct wl1251 *wl, int addr, u32 val);
  225. int (*power)(struct wl1251 *wl, bool enable);
  226. void (*reset)(struct wl1251 *wl);
  227. void (*enable_irq)(struct wl1251 *wl);
  228. void (*disable_irq)(struct wl1251 *wl);
  229. };
  230. struct wl1251 {
  231. struct ieee80211_hw *hw;
  232. bool mac80211_registered;
  233. void *if_priv;
  234. const struct wl1251_if_operations *if_ops;
  235. int power_gpio;
  236. int irq;
  237. bool use_eeprom;
  238. struct regulator *vio;
  239. spinlock_t wl_lock;
  240. enum wl1251_state state;
  241. struct mutex mutex;
  242. int physical_mem_addr;
  243. int physical_reg_addr;
  244. int virtual_mem_addr;
  245. int virtual_reg_addr;
  246. int cmd_box_addr;
  247. int event_box_addr;
  248. struct boot_attr boot_attr;
  249. u8 *fw;
  250. size_t fw_len;
  251. u8 *nvs;
  252. size_t nvs_len;
  253. u8 bssid[ETH_ALEN];
  254. u8 mac_addr[ETH_ALEN];
  255. u8 bss_type;
  256. u8 listen_int;
  257. int channel;
  258. bool monitor_present;
  259. bool joined;
  260. void *target_mem_map;
  261. struct acx_data_path_params_resp *data_path;
  262. /* Number of TX packets transferred to the FW, modulo 16 */
  263. u32 data_in_count;
  264. /* Frames scheduled for transmission, not handled yet */
  265. struct sk_buff_head tx_queue;
  266. bool tx_queue_stopped;
  267. struct work_struct tx_work;
  268. /* Pending TX frames */
  269. struct sk_buff *tx_frames[16];
  270. /*
  271. * Index pointing to the next TX complete entry
  272. * in the cyclic XT complete array we get from
  273. * the FW.
  274. */
  275. u32 next_tx_complete;
  276. /* FW Rx counter */
  277. u32 rx_counter;
  278. /* Rx frames handled */
  279. u32 rx_handled;
  280. /* Current double buffer */
  281. u32 rx_current_buffer;
  282. u32 rx_last_id;
  283. /* The target interrupt mask */
  284. u32 intr_mask;
  285. struct work_struct irq_work;
  286. /* The mbox event mask */
  287. u32 event_mask;
  288. /* Mailbox pointers */
  289. u32 mbox_ptr[2];
  290. /* Are we currently scanning */
  291. bool scanning;
  292. /* Default key (for WEP) */
  293. u32 default_key;
  294. unsigned int tx_mgmt_frm_rate;
  295. unsigned int tx_mgmt_frm_mod;
  296. unsigned int rx_config;
  297. unsigned int rx_filter;
  298. /* is firmware in elp mode */
  299. bool elp;
  300. struct delayed_work elp_work;
  301. enum wl1251_station_mode station_mode;
  302. /* PSM mode requested */
  303. bool psm_requested;
  304. /* retry counter for PSM entries */
  305. u8 psm_entry_retry;
  306. u16 beacon_int;
  307. u8 dtim_period;
  308. /* in dBm */
  309. int power_level;
  310. int rssi_thold;
  311. struct wl1251_stats stats;
  312. struct wl1251_debugfs debugfs;
  313. __le32 buffer_32;
  314. u32 buffer_cmd;
  315. u8 buffer_busyword[WL1251_BUSY_WORD_LEN];
  316. struct wl1251_rx_descriptor *rx_descriptor;
  317. struct ieee80211_vif *vif;
  318. u32 chip_id;
  319. char fw_ver[21];
  320. /* Most recently reported noise in dBm */
  321. s8 noise;
  322. };
  323. int wl1251_plt_start(struct wl1251 *wl);
  324. int wl1251_plt_stop(struct wl1251 *wl);
  325. struct ieee80211_hw *wl1251_alloc_hw(void);
  326. int wl1251_free_hw(struct wl1251 *wl);
  327. int wl1251_init_ieee80211(struct wl1251 *wl);
  328. void wl1251_enable_interrupts(struct wl1251 *wl);
  329. void wl1251_disable_interrupts(struct wl1251 *wl);
  330. #define DEFAULT_HW_GEN_MODULATION_TYPE CCK_LONG /* Long Preamble */
  331. #define DEFAULT_HW_GEN_TX_RATE RATE_2MBPS
  332. #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
  333. #define WL1251_DEFAULT_POWER_LEVEL 20
  334. #define WL1251_TX_QUEUE_LOW_WATERMARK 10
  335. #define WL1251_TX_QUEUE_HIGH_WATERMARK 25
  336. #define WL1251_DEFAULT_BEACON_INT 100
  337. #define WL1251_DEFAULT_DTIM_PERIOD 1
  338. #define WL1251_DEFAULT_CHANNEL 0
  339. #define WL1251_DEFAULT_BET_CONSECUTIVE 10
  340. #define CHIP_ID_1251_PG10 (0x7010101)
  341. #define CHIP_ID_1251_PG11 (0x7020101)
  342. #define CHIP_ID_1251_PG12 (0x7030101)
  343. #define CHIP_ID_1271_PG10 (0x4030101)
  344. #define CHIP_ID_1271_PG20 (0x4030111)
  345. #define WL1251_FW_NAME "ti-connectivity/wl1251-fw.bin"
  346. #define WL1251_NVS_NAME "ti-connectivity/wl1251-nvs.bin"
  347. #define WL1251_POWER_ON_SLEEP 10 /* in milliseconds */
  348. #define WL1251_PART_DOWN_MEM_START 0x0
  349. #define WL1251_PART_DOWN_MEM_SIZE 0x16800
  350. #define WL1251_PART_DOWN_REG_START REGISTERS_BASE
  351. #define WL1251_PART_DOWN_REG_SIZE REGISTERS_DOWN_SIZE
  352. #define WL1251_PART_WORK_MEM_START 0x28000
  353. #define WL1251_PART_WORK_MEM_SIZE 0x14000
  354. #define WL1251_PART_WORK_REG_START REGISTERS_BASE
  355. #define WL1251_PART_WORK_REG_SIZE REGISTERS_WORK_SIZE
  356. #define WL1251_DEFAULT_LOW_RSSI_WEIGHT 10
  357. #define WL1251_DEFAULT_LOW_RSSI_DEPTH 10
  358. #endif