wl1271.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
  5. * Copyright (C) 2008-2009 Nokia Corporation
  6. *
  7. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #ifndef __WL1271_H__
  25. #define __WL1271_H__
  26. #include <linux/mutex.h>
  27. #include <linux/completion.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/list.h>
  30. #include <linux/bitops.h>
  31. #include <net/mac80211.h>
  32. #define DRIVER_NAME "wl1271"
  33. #define DRIVER_PREFIX DRIVER_NAME ": "
  34. enum {
  35. DEBUG_NONE = 0,
  36. DEBUG_IRQ = BIT(0),
  37. DEBUG_SPI = BIT(1),
  38. DEBUG_BOOT = BIT(2),
  39. DEBUG_MAILBOX = BIT(3),
  40. DEBUG_NETLINK = BIT(4),
  41. DEBUG_EVENT = BIT(5),
  42. DEBUG_TX = BIT(6),
  43. DEBUG_RX = BIT(7),
  44. DEBUG_SCAN = BIT(8),
  45. DEBUG_CRYPT = BIT(9),
  46. DEBUG_PSM = BIT(10),
  47. DEBUG_MAC80211 = BIT(11),
  48. DEBUG_CMD = BIT(12),
  49. DEBUG_ACX = BIT(13),
  50. DEBUG_ALL = ~0,
  51. };
  52. #define DEBUG_LEVEL (DEBUG_NONE)
  53. #define DEBUG_DUMP_LIMIT 1024
  54. #define wl1271_error(fmt, arg...) \
  55. printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
  56. #define wl1271_warning(fmt, arg...) \
  57. printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
  58. #define wl1271_notice(fmt, arg...) \
  59. printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
  60. #define wl1271_info(fmt, arg...) \
  61. printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
  62. #define wl1271_debug(level, fmt, arg...) \
  63. do { \
  64. if (level & DEBUG_LEVEL) \
  65. printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
  66. } while (0)
  67. #define wl1271_dump(level, prefix, buf, len) \
  68. do { \
  69. if (level & DEBUG_LEVEL) \
  70. print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
  71. DUMP_PREFIX_OFFSET, 16, 1, \
  72. buf, \
  73. min_t(size_t, len, DEBUG_DUMP_LIMIT), \
  74. 0); \
  75. } while (0)
  76. #define wl1271_dump_ascii(level, prefix, buf, len) \
  77. do { \
  78. if (level & DEBUG_LEVEL) \
  79. print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
  80. DUMP_PREFIX_OFFSET, 16, 1, \
  81. buf, \
  82. min_t(size_t, len, DEBUG_DUMP_LIMIT), \
  83. true); \
  84. } while (0)
  85. #define WL1271_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
  86. CFG_BSSID_FILTER_EN)
  87. #define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \
  88. CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
  89. CFG_RX_CTL_EN | CFG_RX_BCN_EN | \
  90. CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
  91. #define WL1271_FW_NAME "wl1271-fw.bin"
  92. #define WL1271_NVS_NAME "wl1271-nvs.bin"
  93. #define WL1271_BUSY_WORD_LEN 8
  94. #define WL1271_ELP_HW_STATE_ASLEEP 0
  95. #define WL1271_ELP_HW_STATE_IRQ 1
  96. enum wl1271_state {
  97. WL1271_STATE_OFF,
  98. WL1271_STATE_ON,
  99. WL1271_STATE_PLT,
  100. };
  101. enum wl1271_partition_type {
  102. PART_DOWN,
  103. PART_WORK,
  104. PART_DRPW,
  105. PART_TABLE_LEN
  106. };
  107. struct wl1271_partition {
  108. u32 size;
  109. u32 start;
  110. };
  111. struct wl1271_partition_set {
  112. struct wl1271_partition mem;
  113. struct wl1271_partition reg;
  114. };
  115. struct wl1271;
  116. /* FIXME: I'm not sure about this structure name */
  117. struct wl1271_chip {
  118. u32 id;
  119. char fw_ver[21];
  120. };
  121. struct wl1271_stats {
  122. struct acx_statistics *fw_stats;
  123. unsigned long fw_stats_update;
  124. unsigned int retry_count;
  125. unsigned int excessive_retries;
  126. };
  127. struct wl1271_debugfs {
  128. struct dentry *rootdir;
  129. struct dentry *fw_statistics;
  130. struct dentry *tx_internal_desc_overflow;
  131. struct dentry *rx_out_of_mem;
  132. struct dentry *rx_hdr_overflow;
  133. struct dentry *rx_hw_stuck;
  134. struct dentry *rx_dropped;
  135. struct dentry *rx_fcs_err;
  136. struct dentry *rx_xfr_hint_trig;
  137. struct dentry *rx_path_reset;
  138. struct dentry *rx_reset_counter;
  139. struct dentry *dma_rx_requested;
  140. struct dentry *dma_rx_errors;
  141. struct dentry *dma_tx_requested;
  142. struct dentry *dma_tx_errors;
  143. struct dentry *isr_cmd_cmplt;
  144. struct dentry *isr_fiqs;
  145. struct dentry *isr_rx_headers;
  146. struct dentry *isr_rx_mem_overflow;
  147. struct dentry *isr_rx_rdys;
  148. struct dentry *isr_irqs;
  149. struct dentry *isr_tx_procs;
  150. struct dentry *isr_decrypt_done;
  151. struct dentry *isr_dma0_done;
  152. struct dentry *isr_dma1_done;
  153. struct dentry *isr_tx_exch_complete;
  154. struct dentry *isr_commands;
  155. struct dentry *isr_rx_procs;
  156. struct dentry *isr_hw_pm_mode_changes;
  157. struct dentry *isr_host_acknowledges;
  158. struct dentry *isr_pci_pm;
  159. struct dentry *isr_wakeups;
  160. struct dentry *isr_low_rssi;
  161. struct dentry *wep_addr_key_count;
  162. struct dentry *wep_default_key_count;
  163. /* skipping wep.reserved */
  164. struct dentry *wep_key_not_found;
  165. struct dentry *wep_decrypt_fail;
  166. struct dentry *wep_packets;
  167. struct dentry *wep_interrupt;
  168. struct dentry *pwr_ps_enter;
  169. struct dentry *pwr_elp_enter;
  170. struct dentry *pwr_missing_bcns;
  171. struct dentry *pwr_wake_on_host;
  172. struct dentry *pwr_wake_on_timer_exp;
  173. struct dentry *pwr_tx_with_ps;
  174. struct dentry *pwr_tx_without_ps;
  175. struct dentry *pwr_rcvd_beacons;
  176. struct dentry *pwr_power_save_off;
  177. struct dentry *pwr_enable_ps;
  178. struct dentry *pwr_disable_ps;
  179. struct dentry *pwr_fix_tsf_ps;
  180. /* skipping cont_miss_bcns_spread for now */
  181. struct dentry *pwr_rcvd_awake_beacons;
  182. struct dentry *mic_rx_pkts;
  183. struct dentry *mic_calc_failure;
  184. struct dentry *aes_encrypt_fail;
  185. struct dentry *aes_decrypt_fail;
  186. struct dentry *aes_encrypt_packets;
  187. struct dentry *aes_decrypt_packets;
  188. struct dentry *aes_encrypt_interrupt;
  189. struct dentry *aes_decrypt_interrupt;
  190. struct dentry *event_heart_beat;
  191. struct dentry *event_calibration;
  192. struct dentry *event_rx_mismatch;
  193. struct dentry *event_rx_mem_empty;
  194. struct dentry *event_rx_pool;
  195. struct dentry *event_oom_late;
  196. struct dentry *event_phy_transmit_error;
  197. struct dentry *event_tx_stuck;
  198. struct dentry *ps_pspoll_timeouts;
  199. struct dentry *ps_upsd_timeouts;
  200. struct dentry *ps_upsd_max_sptime;
  201. struct dentry *ps_upsd_max_apturn;
  202. struct dentry *ps_pspoll_max_apturn;
  203. struct dentry *ps_pspoll_utilization;
  204. struct dentry *ps_upsd_utilization;
  205. struct dentry *rxpipe_rx_prep_beacon_drop;
  206. struct dentry *rxpipe_descr_host_int_trig_rx_data;
  207. struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
  208. struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
  209. struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
  210. struct dentry *tx_queue_len;
  211. struct dentry *retry_count;
  212. struct dentry *excessive_retries;
  213. };
  214. #define NUM_TX_QUEUES 4
  215. #define NUM_RX_PKT_DESC 8
  216. /* FW status registers */
  217. struct wl1271_fw_status {
  218. u32 intr;
  219. u8 fw_rx_counter;
  220. u8 drv_rx_counter;
  221. u8 reserved;
  222. u8 tx_results_counter;
  223. u32 rx_pkt_descs[NUM_RX_PKT_DESC];
  224. u32 tx_released_blks[NUM_TX_QUEUES];
  225. u32 fw_localtime;
  226. u32 padding[2];
  227. } __attribute__ ((packed));
  228. struct wl1271_rx_mem_pool_addr {
  229. u32 addr;
  230. u32 addr_extra;
  231. };
  232. struct wl1271 {
  233. struct ieee80211_hw *hw;
  234. bool mac80211_registered;
  235. struct spi_device *spi;
  236. void (*set_power)(bool enable);
  237. int irq;
  238. spinlock_t wl_lock;
  239. enum wl1271_state state;
  240. struct mutex mutex;
  241. int physical_mem_addr;
  242. int physical_reg_addr;
  243. int virtual_mem_addr;
  244. int virtual_reg_addr;
  245. struct wl1271_chip chip;
  246. int cmd_box_addr;
  247. int event_box_addr;
  248. u8 *fw;
  249. size_t fw_len;
  250. u8 *nvs;
  251. size_t nvs_len;
  252. u8 bssid[ETH_ALEN];
  253. u8 mac_addr[ETH_ALEN];
  254. u8 bss_type;
  255. u8 ssid[IW_ESSID_MAX_SIZE + 1];
  256. u8 ssid_len;
  257. u8 listen_int;
  258. int channel;
  259. struct wl1271_acx_mem_map *target_mem_map;
  260. /* Accounting for allocated / available TX blocks on HW */
  261. u32 tx_blocks_freed[NUM_TX_QUEUES];
  262. u32 tx_blocks_available;
  263. u8 tx_results_count;
  264. /* Transmitted TX packets counter for chipset interface */
  265. int tx_packets_count;
  266. /* Time-offset between host and chipset clocks */
  267. int time_offset;
  268. /* Session counter for the chipset */
  269. int session_counter;
  270. /* Frames scheduled for transmission, not handled yet */
  271. struct sk_buff_head tx_queue;
  272. bool tx_queue_stopped;
  273. struct work_struct tx_work;
  274. struct work_struct filter_work;
  275. /* Pending TX frames */
  276. struct sk_buff *tx_frames[16];
  277. /* FW Rx counter */
  278. u32 rx_counter;
  279. /* Rx memory pool address */
  280. struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
  281. /* The target interrupt mask */
  282. struct work_struct irq_work;
  283. /* The mbox event mask */
  284. u32 event_mask;
  285. /* Mailbox pointers */
  286. u32 mbox_ptr[2];
  287. /* Are we currently scanning */
  288. bool scanning;
  289. /* Our association ID */
  290. u16 aid;
  291. /* Default key (for WEP) */
  292. u32 default_key;
  293. unsigned int rx_config;
  294. unsigned int rx_filter;
  295. /* is firmware in elp mode */
  296. bool elp;
  297. struct completion *elp_compl;
  298. /* we can be in psm, but not in elp, we have to differentiate */
  299. bool psm;
  300. /* PSM mode requested */
  301. bool psm_requested;
  302. /* in dBm */
  303. int power_level;
  304. struct wl1271_stats stats;
  305. struct wl1271_debugfs debugfs;
  306. u32 buffer_32;
  307. u32 buffer_cmd;
  308. u8 buffer_busyword[WL1271_BUSY_WORD_LEN];
  309. struct wl1271_rx_descriptor *rx_descriptor;
  310. struct wl1271_fw_status *fw_status;
  311. struct wl1271_tx_hw_res_if *tx_res_if;
  312. };
  313. int wl1271_plt_start(struct wl1271 *wl);
  314. int wl1271_plt_stop(struct wl1271 *wl);
  315. #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
  316. #define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
  317. #define WL1271_DEFAULT_POWER_LEVEL 0
  318. #define WL1271_TX_QUEUE_MAX_LENGTH 20
  319. /* WL1271 needs a 200ms sleep after power on */
  320. #define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
  321. #endif