wl1271.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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. #include "wl1271_ini.h"
  34. #define DRIVER_NAME "wl1271"
  35. #define DRIVER_PREFIX DRIVER_NAME ": "
  36. enum {
  37. DEBUG_NONE = 0,
  38. DEBUG_IRQ = BIT(0),
  39. DEBUG_SPI = BIT(1),
  40. DEBUG_BOOT = BIT(2),
  41. DEBUG_MAILBOX = BIT(3),
  42. DEBUG_TESTMODE = BIT(4),
  43. DEBUG_EVENT = BIT(5),
  44. DEBUG_TX = BIT(6),
  45. DEBUG_RX = BIT(7),
  46. DEBUG_SCAN = BIT(8),
  47. DEBUG_CRYPT = BIT(9),
  48. DEBUG_PSM = BIT(10),
  49. DEBUG_MAC80211 = BIT(11),
  50. DEBUG_CMD = BIT(12),
  51. DEBUG_ACX = BIT(13),
  52. DEBUG_SDIO = BIT(14),
  53. DEBUG_FILTERS = BIT(15),
  54. DEBUG_ADHOC = BIT(16),
  55. DEBUG_ALL = ~0,
  56. };
  57. #define DEBUG_LEVEL (DEBUG_NONE)
  58. #define DEBUG_DUMP_LIMIT 1024
  59. #define wl1271_error(fmt, arg...) \
  60. printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
  61. #define wl1271_warning(fmt, arg...) \
  62. printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
  63. #define wl1271_notice(fmt, arg...) \
  64. printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
  65. #define wl1271_info(fmt, arg...) \
  66. printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
  67. #define wl1271_debug(level, fmt, arg...) \
  68. do { \
  69. if (level & DEBUG_LEVEL) \
  70. printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
  71. } while (0)
  72. #define wl1271_dump(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. 0); \
  80. } while (0)
  81. #define wl1271_dump_ascii(level, prefix, buf, len) \
  82. do { \
  83. if (level & DEBUG_LEVEL) \
  84. print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
  85. DUMP_PREFIX_OFFSET, 16, 1, \
  86. buf, \
  87. min_t(size_t, len, DEBUG_DUMP_LIMIT), \
  88. true); \
  89. } while (0)
  90. #define WL1271_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
  91. CFG_BSSID_FILTER_EN | \
  92. CFG_MC_FILTER_EN)
  93. #define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \
  94. CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
  95. CFG_RX_CTL_EN | CFG_RX_BCN_EN | \
  96. CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
  97. #define WL1271_FW_NAME "wl1271-fw.bin"
  98. #define WL1271_NVS_NAME "wl1271-nvs.bin"
  99. #define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
  100. #define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
  101. #define WL1271_CIPHER_SUITE_GEM 0x00147201
  102. #define WL1271_BUSY_WORD_CNT 1
  103. #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
  104. #define WL1271_ELP_HW_STATE_ASLEEP 0
  105. #define WL1271_ELP_HW_STATE_IRQ 1
  106. #define WL1271_DEFAULT_BEACON_INT 100
  107. #define WL1271_DEFAULT_DTIM_PERIOD 1
  108. #define ACX_TX_DESCRIPTORS 32
  109. #define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)
  110. enum wl1271_state {
  111. WL1271_STATE_OFF,
  112. WL1271_STATE_ON,
  113. WL1271_STATE_PLT,
  114. };
  115. enum wl1271_partition_type {
  116. PART_DOWN,
  117. PART_WORK,
  118. PART_DRPW,
  119. PART_TABLE_LEN
  120. };
  121. struct wl1271_partition {
  122. u32 size;
  123. u32 start;
  124. };
  125. struct wl1271_partition_set {
  126. struct wl1271_partition mem;
  127. struct wl1271_partition reg;
  128. struct wl1271_partition mem2;
  129. struct wl1271_partition mem3;
  130. };
  131. struct wl1271;
  132. /* FIXME: I'm not sure about this structure name */
  133. struct wl1271_chip {
  134. u32 id;
  135. char fw_ver[21];
  136. };
  137. struct wl1271_stats {
  138. struct acx_statistics *fw_stats;
  139. unsigned long fw_stats_update;
  140. unsigned int retry_count;
  141. unsigned int excessive_retries;
  142. };
  143. struct wl1271_debugfs {
  144. struct dentry *rootdir;
  145. struct dentry *fw_statistics;
  146. struct dentry *tx_internal_desc_overflow;
  147. struct dentry *rx_out_of_mem;
  148. struct dentry *rx_hdr_overflow;
  149. struct dentry *rx_hw_stuck;
  150. struct dentry *rx_dropped;
  151. struct dentry *rx_fcs_err;
  152. struct dentry *rx_xfr_hint_trig;
  153. struct dentry *rx_path_reset;
  154. struct dentry *rx_reset_counter;
  155. struct dentry *dma_rx_requested;
  156. struct dentry *dma_rx_errors;
  157. struct dentry *dma_tx_requested;
  158. struct dentry *dma_tx_errors;
  159. struct dentry *isr_cmd_cmplt;
  160. struct dentry *isr_fiqs;
  161. struct dentry *isr_rx_headers;
  162. struct dentry *isr_rx_mem_overflow;
  163. struct dentry *isr_rx_rdys;
  164. struct dentry *isr_irqs;
  165. struct dentry *isr_tx_procs;
  166. struct dentry *isr_decrypt_done;
  167. struct dentry *isr_dma0_done;
  168. struct dentry *isr_dma1_done;
  169. struct dentry *isr_tx_exch_complete;
  170. struct dentry *isr_commands;
  171. struct dentry *isr_rx_procs;
  172. struct dentry *isr_hw_pm_mode_changes;
  173. struct dentry *isr_host_acknowledges;
  174. struct dentry *isr_pci_pm;
  175. struct dentry *isr_wakeups;
  176. struct dentry *isr_low_rssi;
  177. struct dentry *wep_addr_key_count;
  178. struct dentry *wep_default_key_count;
  179. /* skipping wep.reserved */
  180. struct dentry *wep_key_not_found;
  181. struct dentry *wep_decrypt_fail;
  182. struct dentry *wep_packets;
  183. struct dentry *wep_interrupt;
  184. struct dentry *pwr_ps_enter;
  185. struct dentry *pwr_elp_enter;
  186. struct dentry *pwr_missing_bcns;
  187. struct dentry *pwr_wake_on_host;
  188. struct dentry *pwr_wake_on_timer_exp;
  189. struct dentry *pwr_tx_with_ps;
  190. struct dentry *pwr_tx_without_ps;
  191. struct dentry *pwr_rcvd_beacons;
  192. struct dentry *pwr_power_save_off;
  193. struct dentry *pwr_enable_ps;
  194. struct dentry *pwr_disable_ps;
  195. struct dentry *pwr_fix_tsf_ps;
  196. /* skipping cont_miss_bcns_spread for now */
  197. struct dentry *pwr_rcvd_awake_beacons;
  198. struct dentry *mic_rx_pkts;
  199. struct dentry *mic_calc_failure;
  200. struct dentry *aes_encrypt_fail;
  201. struct dentry *aes_decrypt_fail;
  202. struct dentry *aes_encrypt_packets;
  203. struct dentry *aes_decrypt_packets;
  204. struct dentry *aes_encrypt_interrupt;
  205. struct dentry *aes_decrypt_interrupt;
  206. struct dentry *event_heart_beat;
  207. struct dentry *event_calibration;
  208. struct dentry *event_rx_mismatch;
  209. struct dentry *event_rx_mem_empty;
  210. struct dentry *event_rx_pool;
  211. struct dentry *event_oom_late;
  212. struct dentry *event_phy_transmit_error;
  213. struct dentry *event_tx_stuck;
  214. struct dentry *ps_pspoll_timeouts;
  215. struct dentry *ps_upsd_timeouts;
  216. struct dentry *ps_upsd_max_sptime;
  217. struct dentry *ps_upsd_max_apturn;
  218. struct dentry *ps_pspoll_max_apturn;
  219. struct dentry *ps_pspoll_utilization;
  220. struct dentry *ps_upsd_utilization;
  221. struct dentry *rxpipe_rx_prep_beacon_drop;
  222. struct dentry *rxpipe_descr_host_int_trig_rx_data;
  223. struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
  224. struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
  225. struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
  226. struct dentry *tx_queue_len;
  227. struct dentry *retry_count;
  228. struct dentry *excessive_retries;
  229. struct dentry *gpio_power;
  230. };
  231. #define NUM_TX_QUEUES 4
  232. #define NUM_RX_PKT_DESC 8
  233. /* FW status registers */
  234. struct wl1271_fw_status {
  235. __le32 intr;
  236. u8 fw_rx_counter;
  237. u8 drv_rx_counter;
  238. u8 reserved;
  239. u8 tx_results_counter;
  240. __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
  241. __le32 tx_released_blks[NUM_TX_QUEUES];
  242. __le32 fw_localtime;
  243. __le32 padding[2];
  244. } __packed;
  245. struct wl1271_rx_mem_pool_addr {
  246. u32 addr;
  247. u32 addr_extra;
  248. };
  249. struct wl1271_scan {
  250. struct cfg80211_scan_request *req;
  251. bool *scanned_ch;
  252. bool failed;
  253. u8 state;
  254. u8 ssid[IW_ESSID_MAX_SIZE+1];
  255. size_t ssid_len;
  256. };
  257. struct wl1271_if_operations {
  258. void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len,
  259. bool fixed);
  260. void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len,
  261. bool fixed);
  262. void (*reset)(struct wl1271 *wl);
  263. void (*init)(struct wl1271 *wl);
  264. int (*power)(struct wl1271 *wl, bool enable);
  265. struct device* (*dev)(struct wl1271 *wl);
  266. void (*enable_irq)(struct wl1271 *wl);
  267. void (*disable_irq)(struct wl1271 *wl);
  268. };
  269. struct wl1271 {
  270. struct platform_device *plat_dev;
  271. struct ieee80211_hw *hw;
  272. bool mac80211_registered;
  273. void *if_priv;
  274. struct wl1271_if_operations *if_ops;
  275. void (*set_power)(bool enable);
  276. int irq;
  277. int ref_clock;
  278. spinlock_t wl_lock;
  279. enum wl1271_state state;
  280. struct mutex mutex;
  281. #define WL1271_FLAG_STA_RATES_CHANGED (0)
  282. #define WL1271_FLAG_STA_ASSOCIATED (1)
  283. #define WL1271_FLAG_JOINED (2)
  284. #define WL1271_FLAG_GPIO_POWER (3)
  285. #define WL1271_FLAG_TX_QUEUE_STOPPED (4)
  286. #define WL1271_FLAG_IN_ELP (5)
  287. #define WL1271_FLAG_PSM (6)
  288. #define WL1271_FLAG_PSM_REQUESTED (7)
  289. #define WL1271_FLAG_IRQ_PENDING (8)
  290. #define WL1271_FLAG_IRQ_RUNNING (9)
  291. #define WL1271_FLAG_IDLE (10)
  292. #define WL1271_FLAG_IDLE_REQUESTED (11)
  293. #define WL1271_FLAG_PSPOLL_FAILURE (12)
  294. #define WL1271_FLAG_STA_STATE_SENT (13)
  295. unsigned long flags;
  296. struct wl1271_partition_set part;
  297. struct wl1271_chip chip;
  298. int cmd_box_addr;
  299. int event_box_addr;
  300. u8 *fw;
  301. size_t fw_len;
  302. struct wl1271_nvs_file *nvs;
  303. size_t nvs_len;
  304. s8 hw_pg_ver;
  305. u8 bssid[ETH_ALEN];
  306. u8 mac_addr[ETH_ALEN];
  307. u8 bss_type;
  308. u8 set_bss_type;
  309. u8 ssid[IW_ESSID_MAX_SIZE + 1];
  310. u8 ssid_len;
  311. int channel;
  312. struct wl1271_acx_mem_map *target_mem_map;
  313. /* Accounting for allocated / available TX blocks on HW */
  314. u32 tx_blocks_freed[NUM_TX_QUEUES];
  315. u32 tx_blocks_available;
  316. u32 tx_results_count;
  317. /* Transmitted TX packets counter for chipset interface */
  318. u32 tx_packets_count;
  319. /* Time-offset between host and chipset clocks */
  320. s64 time_offset;
  321. /* Session counter for the chipset */
  322. int session_counter;
  323. /* Frames scheduled for transmission, not handled yet */
  324. struct sk_buff_head tx_queue;
  325. struct work_struct tx_work;
  326. /* Pending TX frames */
  327. struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
  328. int tx_frames_cnt;
  329. /* Security sequence number counters */
  330. u8 tx_security_last_seq;
  331. s64 tx_security_seq;
  332. /* FW Rx counter */
  333. u32 rx_counter;
  334. /* Rx memory pool address */
  335. struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
  336. /* Intermediate buffer, used for packet aggregation */
  337. u8 *aggr_buf;
  338. /* The target interrupt mask */
  339. struct work_struct irq_work;
  340. /* Hardware recovery work */
  341. struct work_struct recovery_work;
  342. /* The mbox event mask */
  343. u32 event_mask;
  344. /* Mailbox pointers */
  345. u32 mbox_ptr[2];
  346. /* Are we currently scanning */
  347. struct wl1271_scan scan;
  348. struct delayed_work scan_complete_work;
  349. /* Our association ID */
  350. u16 aid;
  351. /* currently configured rate set */
  352. u32 sta_rate_set;
  353. u32 basic_rate_set;
  354. u32 basic_rate;
  355. u32 rate_set;
  356. /* The current band */
  357. enum ieee80211_band band;
  358. /* Beaconing interval (needed for ad-hoc) */
  359. u32 beacon_int;
  360. /* Default key (for WEP) */
  361. u32 default_key;
  362. unsigned int filters;
  363. unsigned int rx_config;
  364. unsigned int rx_filter;
  365. struct completion *elp_compl;
  366. struct delayed_work elp_work;
  367. struct delayed_work pspoll_work;
  368. /* counter for ps-poll delivery failures */
  369. int ps_poll_failures;
  370. /* retry counter for PSM entries */
  371. u8 psm_entry_retry;
  372. /* in dBm */
  373. int power_level;
  374. int rssi_thold;
  375. int last_rssi_event;
  376. struct wl1271_stats stats;
  377. struct wl1271_debugfs debugfs;
  378. __le32 buffer_32;
  379. u32 buffer_cmd;
  380. u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
  381. struct wl1271_fw_status *fw_status;
  382. struct wl1271_tx_hw_res_if *tx_res_if;
  383. struct ieee80211_vif *vif;
  384. /* Current chipset configuration */
  385. struct conf_drv_settings conf;
  386. bool sg_enabled;
  387. bool enable_11a;
  388. struct list_head list;
  389. /* Most recently reported noise in dBm */
  390. s8 noise;
  391. };
  392. int wl1271_plt_start(struct wl1271 *wl);
  393. int wl1271_plt_stop(struct wl1271 *wl);
  394. #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
  395. #define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
  396. #define WL1271_DEFAULT_POWER_LEVEL 0
  397. #define WL1271_TX_QUEUE_LOW_WATERMARK 10
  398. #define WL1271_TX_QUEUE_HIGH_WATERMARK 25
  399. /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
  400. on in case is has been shut down shortly before */
  401. #define WL1271_PRE_POWER_ON_SLEEP 20 /* in miliseconds */
  402. #define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
  403. #endif