wl1251.h 10 KB

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