wl1271.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. #include "wl1271_conf.h"
  33. #define DRIVER_NAME "wl1271"
  34. #define DRIVER_PREFIX DRIVER_NAME ": "
  35. enum {
  36. DEBUG_NONE = 0,
  37. DEBUG_IRQ = BIT(0),
  38. DEBUG_SPI = BIT(1),
  39. DEBUG_BOOT = BIT(2),
  40. DEBUG_MAILBOX = BIT(3),
  41. DEBUG_NETLINK = BIT(4),
  42. DEBUG_EVENT = BIT(5),
  43. DEBUG_TX = BIT(6),
  44. DEBUG_RX = BIT(7),
  45. DEBUG_SCAN = BIT(8),
  46. DEBUG_CRYPT = BIT(9),
  47. DEBUG_PSM = BIT(10),
  48. DEBUG_MAC80211 = BIT(11),
  49. DEBUG_CMD = BIT(12),
  50. DEBUG_ACX = BIT(13),
  51. DEBUG_ALL = ~0,
  52. };
  53. #define DEBUG_LEVEL (DEBUG_NONE)
  54. #define DEBUG_DUMP_LIMIT 1024
  55. #define wl1271_error(fmt, arg...) \
  56. printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
  57. #define wl1271_warning(fmt, arg...) \
  58. printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
  59. #define wl1271_notice(fmt, arg...) \
  60. printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
  61. #define wl1271_info(fmt, arg...) \
  62. printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
  63. #define wl1271_debug(level, fmt, arg...) \
  64. do { \
  65. if (level & DEBUG_LEVEL) \
  66. printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
  67. } while (0)
  68. #define wl1271_dump(level, prefix, buf, len) \
  69. do { \
  70. if (level & DEBUG_LEVEL) \
  71. print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
  72. DUMP_PREFIX_OFFSET, 16, 1, \
  73. buf, \
  74. min_t(size_t, len, DEBUG_DUMP_LIMIT), \
  75. 0); \
  76. } while (0)
  77. #define wl1271_dump_ascii(level, prefix, buf, len) \
  78. do { \
  79. if (level & DEBUG_LEVEL) \
  80. print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
  81. DUMP_PREFIX_OFFSET, 16, 1, \
  82. buf, \
  83. min_t(size_t, len, DEBUG_DUMP_LIMIT), \
  84. true); \
  85. } while (0)
  86. #define WL1271_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
  87. CFG_BSSID_FILTER_EN | \
  88. CFG_MC_FILTER_EN)
  89. #define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \
  90. CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
  91. CFG_RX_CTL_EN | CFG_RX_BCN_EN | \
  92. CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
  93. #define WL1271_DEFAULT_BASIC_RATE_SET (CONF_TX_RATE_MASK_ALL)
  94. #define WL1271_FW_NAME "wl1271-fw.bin"
  95. #define WL1271_NVS_NAME "wl1271-nvs.bin"
  96. /*
  97. * Enable/disable 802.11a support for WL1273
  98. */
  99. #undef WL1271_80211A_ENABLED
  100. /*
  101. * FIXME: for the wl1271, a busy word count of 1 here will result in a more
  102. * optimal SPI interface. There is some SPI bug however, causing RXS time outs
  103. * with this mode occasionally on boot, so lets have three for now. A value of
  104. * three should make sure, that the chipset will always be ready, though this
  105. * will impact throughput and latencies slightly.
  106. */
  107. #define WL1271_BUSY_WORD_CNT 3
  108. #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
  109. #define WL1271_ELP_HW_STATE_ASLEEP 0
  110. #define WL1271_ELP_HW_STATE_IRQ 1
  111. #define WL1271_DEFAULT_BEACON_INT 100
  112. #define WL1271_DEFAULT_DTIM_PERIOD 1
  113. #define ACX_TX_DESCRIPTORS 32
  114. enum wl1271_state {
  115. WL1271_STATE_OFF,
  116. WL1271_STATE_ON,
  117. WL1271_STATE_PLT,
  118. };
  119. enum wl1271_partition_type {
  120. PART_DOWN,
  121. PART_WORK,
  122. PART_DRPW,
  123. PART_TABLE_LEN
  124. };
  125. struct wl1271_partition {
  126. u32 size;
  127. u32 start;
  128. };
  129. struct wl1271_partition_set {
  130. struct wl1271_partition mem;
  131. struct wl1271_partition reg;
  132. struct wl1271_partition mem2;
  133. struct wl1271_partition mem3;
  134. };
  135. struct wl1271;
  136. /* FIXME: I'm not sure about this structure name */
  137. struct wl1271_chip {
  138. u32 id;
  139. char fw_ver[21];
  140. };
  141. struct wl1271_stats {
  142. struct acx_statistics *fw_stats;
  143. unsigned long fw_stats_update;
  144. unsigned int retry_count;
  145. unsigned int excessive_retries;
  146. };
  147. struct wl1271_debugfs {
  148. struct dentry *rootdir;
  149. struct dentry *fw_statistics;
  150. struct dentry *tx_internal_desc_overflow;
  151. struct dentry *rx_out_of_mem;
  152. struct dentry *rx_hdr_overflow;
  153. struct dentry *rx_hw_stuck;
  154. struct dentry *rx_dropped;
  155. struct dentry *rx_fcs_err;
  156. struct dentry *rx_xfr_hint_trig;
  157. struct dentry *rx_path_reset;
  158. struct dentry *rx_reset_counter;
  159. struct dentry *dma_rx_requested;
  160. struct dentry *dma_rx_errors;
  161. struct dentry *dma_tx_requested;
  162. struct dentry *dma_tx_errors;
  163. struct dentry *isr_cmd_cmplt;
  164. struct dentry *isr_fiqs;
  165. struct dentry *isr_rx_headers;
  166. struct dentry *isr_rx_mem_overflow;
  167. struct dentry *isr_rx_rdys;
  168. struct dentry *isr_irqs;
  169. struct dentry *isr_tx_procs;
  170. struct dentry *isr_decrypt_done;
  171. struct dentry *isr_dma0_done;
  172. struct dentry *isr_dma1_done;
  173. struct dentry *isr_tx_exch_complete;
  174. struct dentry *isr_commands;
  175. struct dentry *isr_rx_procs;
  176. struct dentry *isr_hw_pm_mode_changes;
  177. struct dentry *isr_host_acknowledges;
  178. struct dentry *isr_pci_pm;
  179. struct dentry *isr_wakeups;
  180. struct dentry *isr_low_rssi;
  181. struct dentry *wep_addr_key_count;
  182. struct dentry *wep_default_key_count;
  183. /* skipping wep.reserved */
  184. struct dentry *wep_key_not_found;
  185. struct dentry *wep_decrypt_fail;
  186. struct dentry *wep_packets;
  187. struct dentry *wep_interrupt;
  188. struct dentry *pwr_ps_enter;
  189. struct dentry *pwr_elp_enter;
  190. struct dentry *pwr_missing_bcns;
  191. struct dentry *pwr_wake_on_host;
  192. struct dentry *pwr_wake_on_timer_exp;
  193. struct dentry *pwr_tx_with_ps;
  194. struct dentry *pwr_tx_without_ps;
  195. struct dentry *pwr_rcvd_beacons;
  196. struct dentry *pwr_power_save_off;
  197. struct dentry *pwr_enable_ps;
  198. struct dentry *pwr_disable_ps;
  199. struct dentry *pwr_fix_tsf_ps;
  200. /* skipping cont_miss_bcns_spread for now */
  201. struct dentry *pwr_rcvd_awake_beacons;
  202. struct dentry *mic_rx_pkts;
  203. struct dentry *mic_calc_failure;
  204. struct dentry *aes_encrypt_fail;
  205. struct dentry *aes_decrypt_fail;
  206. struct dentry *aes_encrypt_packets;
  207. struct dentry *aes_decrypt_packets;
  208. struct dentry *aes_encrypt_interrupt;
  209. struct dentry *aes_decrypt_interrupt;
  210. struct dentry *event_heart_beat;
  211. struct dentry *event_calibration;
  212. struct dentry *event_rx_mismatch;
  213. struct dentry *event_rx_mem_empty;
  214. struct dentry *event_rx_pool;
  215. struct dentry *event_oom_late;
  216. struct dentry *event_phy_transmit_error;
  217. struct dentry *event_tx_stuck;
  218. struct dentry *ps_pspoll_timeouts;
  219. struct dentry *ps_upsd_timeouts;
  220. struct dentry *ps_upsd_max_sptime;
  221. struct dentry *ps_upsd_max_apturn;
  222. struct dentry *ps_pspoll_max_apturn;
  223. struct dentry *ps_pspoll_utilization;
  224. struct dentry *ps_upsd_utilization;
  225. struct dentry *rxpipe_rx_prep_beacon_drop;
  226. struct dentry *rxpipe_descr_host_int_trig_rx_data;
  227. struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
  228. struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
  229. struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
  230. struct dentry *tx_queue_len;
  231. struct dentry *retry_count;
  232. struct dentry *excessive_retries;
  233. };
  234. #define NUM_TX_QUEUES 4
  235. #define NUM_RX_PKT_DESC 8
  236. /* FW status registers */
  237. struct wl1271_fw_status {
  238. __le32 intr;
  239. u8 fw_rx_counter;
  240. u8 drv_rx_counter;
  241. u8 reserved;
  242. u8 tx_results_counter;
  243. __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
  244. __le32 tx_released_blks[NUM_TX_QUEUES];
  245. __le32 fw_localtime;
  246. __le32 padding[2];
  247. } __attribute__ ((packed));
  248. struct wl1271_rx_mem_pool_addr {
  249. u32 addr;
  250. u32 addr_extra;
  251. };
  252. struct wl1271_scan {
  253. u8 state;
  254. u8 ssid[IW_ESSID_MAX_SIZE+1];
  255. size_t ssid_len;
  256. u8 active;
  257. u8 high_prio;
  258. u8 probe_requests;
  259. };
  260. struct wl1271 {
  261. struct ieee80211_hw *hw;
  262. bool mac80211_registered;
  263. struct spi_device *spi;
  264. void (*set_power)(bool enable);
  265. int irq;
  266. spinlock_t wl_lock;
  267. enum wl1271_state state;
  268. struct mutex mutex;
  269. struct wl1271_partition_set part;
  270. struct wl1271_chip chip;
  271. int cmd_box_addr;
  272. int event_box_addr;
  273. u8 *fw;
  274. size_t fw_len;
  275. u8 *nvs;
  276. size_t nvs_len;
  277. u8 bssid[ETH_ALEN];
  278. u8 mac_addr[ETH_ALEN];
  279. u8 bss_type;
  280. u8 ssid[IW_ESSID_MAX_SIZE + 1];
  281. u8 ssid_len;
  282. int channel;
  283. struct wl1271_acx_mem_map *target_mem_map;
  284. /* Accounting for allocated / available TX blocks on HW */
  285. u32 tx_blocks_freed[NUM_TX_QUEUES];
  286. u32 tx_blocks_available;
  287. u8 tx_results_count;
  288. /* Transmitted TX packets counter for chipset interface */
  289. int tx_packets_count;
  290. /* Time-offset between host and chipset clocks */
  291. int time_offset;
  292. /* Session counter for the chipset */
  293. int session_counter;
  294. /* Frames scheduled for transmission, not handled yet */
  295. struct sk_buff_head tx_queue;
  296. bool tx_queue_stopped;
  297. struct work_struct tx_work;
  298. /* Pending TX frames */
  299. struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
  300. /* Security sequence number counters */
  301. u8 tx_security_last_seq;
  302. u16 tx_security_seq_16;
  303. u32 tx_security_seq_32;
  304. /* FW Rx counter */
  305. u32 rx_counter;
  306. /* Rx memory pool address */
  307. struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
  308. /* The target interrupt mask */
  309. struct work_struct irq_work;
  310. /* The mbox event mask */
  311. u32 event_mask;
  312. /* Mailbox pointers */
  313. u32 mbox_ptr[2];
  314. /* Are we currently scanning */
  315. bool scanning;
  316. struct wl1271_scan scan;
  317. /* Our association ID */
  318. u16 aid;
  319. /* currently configured rate set */
  320. u32 basic_rate_set;
  321. /* The current band */
  322. enum ieee80211_band band;
  323. /* Default key (for WEP) */
  324. u32 default_key;
  325. unsigned int rx_config;
  326. unsigned int rx_filter;
  327. /* is firmware in elp mode */
  328. bool elp;
  329. struct completion *elp_compl;
  330. struct delayed_work elp_work;
  331. /* we can be in psm, but not in elp, we have to differentiate */
  332. bool psm;
  333. /* PSM mode requested */
  334. bool psm_requested;
  335. /* retry counter for PSM entries */
  336. u8 psm_entry_retry;
  337. /* in dBm */
  338. int power_level;
  339. struct wl1271_stats stats;
  340. struct wl1271_debugfs debugfs;
  341. u32 buffer_32;
  342. u32 buffer_cmd;
  343. u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
  344. struct wl1271_fw_status *fw_status;
  345. struct wl1271_tx_hw_res_if *tx_res_if;
  346. struct ieee80211_vif *vif;
  347. /* Used for a workaround to send disconnect before rejoining */
  348. bool joined;
  349. /* Current chipset configuration */
  350. struct conf_drv_settings conf;
  351. struct list_head list;
  352. };
  353. int wl1271_plt_start(struct wl1271 *wl);
  354. int wl1271_plt_stop(struct wl1271 *wl);
  355. #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
  356. #define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
  357. #define WL1271_DEFAULT_POWER_LEVEL 0
  358. #define WL1271_TX_QUEUE_MAX_LENGTH 20
  359. /* WL1271 needs a 200ms sleep after power on */
  360. #define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
  361. static inline bool wl1271_11a_enabled(void)
  362. {
  363. #ifdef WL1271_80211A_ENABLED
  364. return true;
  365. #else
  366. return false;
  367. #endif
  368. }
  369. #endif