wl1271.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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_TESTMODE = 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_FW_NAME "wl1271-fw.bin"
  94. #define WL1271_NVS_NAME "wl1271-nvs.bin"
  95. /* NVS data structure */
  96. #define WL1271_NVS_SECTION_SIZE 468
  97. #define WL1271_NVS_GENERAL_PARAMS_SIZE 57
  98. #define WL1271_NVS_GENERAL_PARAMS_SIZE_PADDED \
  99. (WL1271_NVS_GENERAL_PARAMS_SIZE + 1)
  100. #define WL1271_NVS_STAT_RADIO_PARAMS_SIZE 17
  101. #define WL1271_NVS_STAT_RADIO_PARAMS_SIZE_PADDED \
  102. (WL1271_NVS_STAT_RADIO_PARAMS_SIZE + 1)
  103. #define WL1271_NVS_DYN_RADIO_PARAMS_SIZE 65
  104. #define WL1271_NVS_DYN_RADIO_PARAMS_SIZE_PADDED \
  105. (WL1271_NVS_DYN_RADIO_PARAMS_SIZE + 1)
  106. #define WL1271_NVS_FEM_COUNT 2
  107. #define WL1271_NVS_INI_SPARE_SIZE 124
  108. struct wl1271_nvs_file {
  109. /* NVS section */
  110. u8 nvs[WL1271_NVS_SECTION_SIZE];
  111. /* INI section */
  112. u8 general_params[WL1271_NVS_GENERAL_PARAMS_SIZE_PADDED];
  113. u8 stat_radio_params[WL1271_NVS_STAT_RADIO_PARAMS_SIZE_PADDED];
  114. u8 dyn_radio_params[WL1271_NVS_FEM_COUNT]
  115. [WL1271_NVS_DYN_RADIO_PARAMS_SIZE_PADDED];
  116. u8 ini_spare[WL1271_NVS_INI_SPARE_SIZE];
  117. } __attribute__ ((packed));
  118. /*
  119. * Enable/disable 802.11a support for WL1273
  120. */
  121. #undef WL1271_80211A_ENABLED
  122. /*
  123. * FIXME: for the wl1271, a busy word count of 1 here will result in a more
  124. * optimal SPI interface. There is some SPI bug however, causing RXS time outs
  125. * with this mode occasionally on boot, so lets have three for now. A value of
  126. * three should make sure, that the chipset will always be ready, though this
  127. * will impact throughput and latencies slightly.
  128. */
  129. #define WL1271_BUSY_WORD_CNT 3
  130. #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
  131. #define WL1271_ELP_HW_STATE_ASLEEP 0
  132. #define WL1271_ELP_HW_STATE_IRQ 1
  133. #define WL1271_DEFAULT_BEACON_INT 100
  134. #define WL1271_DEFAULT_DTIM_PERIOD 1
  135. #define ACX_TX_DESCRIPTORS 32
  136. enum wl1271_state {
  137. WL1271_STATE_OFF,
  138. WL1271_STATE_ON,
  139. WL1271_STATE_PLT,
  140. };
  141. enum wl1271_partition_type {
  142. PART_DOWN,
  143. PART_WORK,
  144. PART_DRPW,
  145. PART_TABLE_LEN
  146. };
  147. struct wl1271_partition {
  148. u32 size;
  149. u32 start;
  150. };
  151. struct wl1271_partition_set {
  152. struct wl1271_partition mem;
  153. struct wl1271_partition reg;
  154. struct wl1271_partition mem2;
  155. struct wl1271_partition mem3;
  156. };
  157. struct wl1271;
  158. /* FIXME: I'm not sure about this structure name */
  159. struct wl1271_chip {
  160. u32 id;
  161. char fw_ver[21];
  162. };
  163. struct wl1271_stats {
  164. struct acx_statistics *fw_stats;
  165. unsigned long fw_stats_update;
  166. unsigned int retry_count;
  167. unsigned int excessive_retries;
  168. };
  169. struct wl1271_debugfs {
  170. struct dentry *rootdir;
  171. struct dentry *fw_statistics;
  172. struct dentry *tx_internal_desc_overflow;
  173. struct dentry *rx_out_of_mem;
  174. struct dentry *rx_hdr_overflow;
  175. struct dentry *rx_hw_stuck;
  176. struct dentry *rx_dropped;
  177. struct dentry *rx_fcs_err;
  178. struct dentry *rx_xfr_hint_trig;
  179. struct dentry *rx_path_reset;
  180. struct dentry *rx_reset_counter;
  181. struct dentry *dma_rx_requested;
  182. struct dentry *dma_rx_errors;
  183. struct dentry *dma_tx_requested;
  184. struct dentry *dma_tx_errors;
  185. struct dentry *isr_cmd_cmplt;
  186. struct dentry *isr_fiqs;
  187. struct dentry *isr_rx_headers;
  188. struct dentry *isr_rx_mem_overflow;
  189. struct dentry *isr_rx_rdys;
  190. struct dentry *isr_irqs;
  191. struct dentry *isr_tx_procs;
  192. struct dentry *isr_decrypt_done;
  193. struct dentry *isr_dma0_done;
  194. struct dentry *isr_dma1_done;
  195. struct dentry *isr_tx_exch_complete;
  196. struct dentry *isr_commands;
  197. struct dentry *isr_rx_procs;
  198. struct dentry *isr_hw_pm_mode_changes;
  199. struct dentry *isr_host_acknowledges;
  200. struct dentry *isr_pci_pm;
  201. struct dentry *isr_wakeups;
  202. struct dentry *isr_low_rssi;
  203. struct dentry *wep_addr_key_count;
  204. struct dentry *wep_default_key_count;
  205. /* skipping wep.reserved */
  206. struct dentry *wep_key_not_found;
  207. struct dentry *wep_decrypt_fail;
  208. struct dentry *wep_packets;
  209. struct dentry *wep_interrupt;
  210. struct dentry *pwr_ps_enter;
  211. struct dentry *pwr_elp_enter;
  212. struct dentry *pwr_missing_bcns;
  213. struct dentry *pwr_wake_on_host;
  214. struct dentry *pwr_wake_on_timer_exp;
  215. struct dentry *pwr_tx_with_ps;
  216. struct dentry *pwr_tx_without_ps;
  217. struct dentry *pwr_rcvd_beacons;
  218. struct dentry *pwr_power_save_off;
  219. struct dentry *pwr_enable_ps;
  220. struct dentry *pwr_disable_ps;
  221. struct dentry *pwr_fix_tsf_ps;
  222. /* skipping cont_miss_bcns_spread for now */
  223. struct dentry *pwr_rcvd_awake_beacons;
  224. struct dentry *mic_rx_pkts;
  225. struct dentry *mic_calc_failure;
  226. struct dentry *aes_encrypt_fail;
  227. struct dentry *aes_decrypt_fail;
  228. struct dentry *aes_encrypt_packets;
  229. struct dentry *aes_decrypt_packets;
  230. struct dentry *aes_encrypt_interrupt;
  231. struct dentry *aes_decrypt_interrupt;
  232. struct dentry *event_heart_beat;
  233. struct dentry *event_calibration;
  234. struct dentry *event_rx_mismatch;
  235. struct dentry *event_rx_mem_empty;
  236. struct dentry *event_rx_pool;
  237. struct dentry *event_oom_late;
  238. struct dentry *event_phy_transmit_error;
  239. struct dentry *event_tx_stuck;
  240. struct dentry *ps_pspoll_timeouts;
  241. struct dentry *ps_upsd_timeouts;
  242. struct dentry *ps_upsd_max_sptime;
  243. struct dentry *ps_upsd_max_apturn;
  244. struct dentry *ps_pspoll_max_apturn;
  245. struct dentry *ps_pspoll_utilization;
  246. struct dentry *ps_upsd_utilization;
  247. struct dentry *rxpipe_rx_prep_beacon_drop;
  248. struct dentry *rxpipe_descr_host_int_trig_rx_data;
  249. struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
  250. struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
  251. struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
  252. struct dentry *tx_queue_len;
  253. struct dentry *retry_count;
  254. struct dentry *excessive_retries;
  255. struct dentry *gpio_power;
  256. };
  257. #define NUM_TX_QUEUES 4
  258. #define NUM_RX_PKT_DESC 8
  259. /* FW status registers */
  260. struct wl1271_fw_status {
  261. __le32 intr;
  262. u8 fw_rx_counter;
  263. u8 drv_rx_counter;
  264. u8 reserved;
  265. u8 tx_results_counter;
  266. __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
  267. __le32 tx_released_blks[NUM_TX_QUEUES];
  268. __le32 fw_localtime;
  269. __le32 padding[2];
  270. } __attribute__ ((packed));
  271. struct wl1271_rx_mem_pool_addr {
  272. u32 addr;
  273. u32 addr_extra;
  274. };
  275. struct wl1271_scan {
  276. u8 state;
  277. u8 ssid[IW_ESSID_MAX_SIZE+1];
  278. size_t ssid_len;
  279. u8 active;
  280. u8 high_prio;
  281. u8 probe_requests;
  282. };
  283. struct wl1271 {
  284. struct ieee80211_hw *hw;
  285. bool mac80211_registered;
  286. struct spi_device *spi;
  287. void (*set_power)(bool enable);
  288. int irq;
  289. spinlock_t wl_lock;
  290. enum wl1271_state state;
  291. struct mutex mutex;
  292. #define WL1271_FLAG_STA_RATES_CHANGED (0)
  293. #define WL1271_FLAG_STA_ASSOCIATED (1)
  294. #define WL1271_FLAG_JOINED (2)
  295. #define WL1271_FLAG_GPIO_POWER (3)
  296. #define WL1271_FLAG_TX_QUEUE_STOPPED (4)
  297. #define WL1271_FLAG_SCANNING (5)
  298. #define WL1271_FLAG_IN_ELP (6)
  299. #define WL1271_FLAG_PSM (7)
  300. #define WL1271_FLAG_PSM_REQUESTED (8)
  301. unsigned long flags;
  302. struct wl1271_partition_set part;
  303. struct wl1271_chip chip;
  304. int cmd_box_addr;
  305. int event_box_addr;
  306. u8 *fw;
  307. size_t fw_len;
  308. struct wl1271_nvs_file *nvs;
  309. u8 bssid[ETH_ALEN];
  310. u8 mac_addr[ETH_ALEN];
  311. u8 bss_type;
  312. u8 ssid[IW_ESSID_MAX_SIZE + 1];
  313. u8 ssid_len;
  314. int channel;
  315. struct wl1271_acx_mem_map *target_mem_map;
  316. /* Accounting for allocated / available TX blocks on HW */
  317. u32 tx_blocks_freed[NUM_TX_QUEUES];
  318. u32 tx_blocks_available;
  319. u8 tx_results_count;
  320. /* Transmitted TX packets counter for chipset interface */
  321. int tx_packets_count;
  322. /* Time-offset between host and chipset clocks */
  323. int time_offset;
  324. /* Session counter for the chipset */
  325. int session_counter;
  326. /* Frames scheduled for transmission, not handled yet */
  327. struct sk_buff_head tx_queue;
  328. struct work_struct tx_work;
  329. /* Pending TX frames */
  330. struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
  331. /* Security sequence number counters */
  332. u8 tx_security_last_seq;
  333. u16 tx_security_seq_16;
  334. u32 tx_security_seq_32;
  335. /* FW Rx counter */
  336. u32 rx_counter;
  337. /* Rx memory pool address */
  338. struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
  339. /* The target interrupt mask */
  340. struct work_struct irq_work;
  341. /* The mbox event mask */
  342. u32 event_mask;
  343. /* Mailbox pointers */
  344. u32 mbox_ptr[2];
  345. /* Are we currently scanning */
  346. struct wl1271_scan scan;
  347. /* Our association ID */
  348. u16 aid;
  349. /* currently configured rate set */
  350. u32 sta_rate_set;
  351. u32 basic_rate_set;
  352. u32 rate_set;
  353. /* The current band */
  354. enum ieee80211_band band;
  355. /* Default key (for WEP) */
  356. u32 default_key;
  357. unsigned int rx_config;
  358. unsigned int rx_filter;
  359. struct completion *elp_compl;
  360. struct delayed_work elp_work;
  361. /* retry counter for PSM entries */
  362. u8 psm_entry_retry;
  363. /* in dBm */
  364. int power_level;
  365. struct wl1271_stats stats;
  366. struct wl1271_debugfs debugfs;
  367. u32 buffer_32;
  368. u32 buffer_cmd;
  369. u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
  370. struct wl1271_fw_status *fw_status;
  371. struct wl1271_tx_hw_res_if *tx_res_if;
  372. struct ieee80211_vif *vif;
  373. /* Current chipset configuration */
  374. struct conf_drv_settings conf;
  375. struct list_head list;
  376. };
  377. int wl1271_plt_start(struct wl1271 *wl);
  378. int wl1271_plt_stop(struct wl1271 *wl);
  379. #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
  380. #define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
  381. #define WL1271_DEFAULT_POWER_LEVEL 0
  382. #define WL1271_TX_QUEUE_MAX_LENGTH 20
  383. /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
  384. on in case is has been shut down shortly before */
  385. #define WL1271_PRE_POWER_ON_SLEEP 20 /* in miliseconds */
  386. #define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
  387. static inline bool wl1271_11a_enabled(void)
  388. {
  389. /* FIXME: this could be determined based on the NVS-INI file */
  390. #ifdef WL1271_80211A_ENABLED
  391. return true;
  392. #else
  393. return false;
  394. #endif
  395. }
  396. #endif