dhd.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /*
  2. * Header file describing the internal (inter-module) DHD interfaces.
  3. *
  4. * Provides type definitions and function prototypes used to link the
  5. * DHD OS, bus, and protocol modules.
  6. *
  7. * Copyright (C) 1999-2010, Broadcom Corporation
  8. *
  9. * Unless you and Broadcom execute a separate written software license
  10. * agreement governing use of this software, this software is licensed to you
  11. * under the terms of the GNU General Public License version 2 (the "GPL"),
  12. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  13. * following added to such license:
  14. *
  15. * As a special exception, the copyright holders of this software give you
  16. * permission to link this software with independent modules, and to copy and
  17. * distribute the resulting executable under terms of your choice, provided that
  18. * you also meet, for each linked independent module, the terms and conditions of
  19. * the license of that module. An independent module is a module which is not
  20. * derived from this software. The special exception does not apply to any
  21. * modifications of the software.
  22. *
  23. * Notwithstanding the above, under no circumstances may you combine this
  24. * software in any way with any other Broadcom software provided under a license
  25. * other than the GPL, without Broadcom's express prior written consent.
  26. *
  27. * $Id: dhd.h,v 1.32.4.7.2.4.14.49.4.9 2011/01/14 22:40:45 Exp $
  28. */
  29. /****************
  30. * Common types *
  31. */
  32. #ifndef _dhd_h_
  33. #define _dhd_h_
  34. #if defined(LINUX)
  35. #include <linux/init.h>
  36. #include <linux/kernel.h>
  37. #include <linux/slab.h>
  38. #include <linux/skbuff.h>
  39. #include <linux/netdevice.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/random.h>
  42. #include <linux/spinlock.h>
  43. #include <linux/ethtool.h>
  44. #include <linux/sched.h>
  45. #include <asm/uaccess.h>
  46. #include <asm/unaligned.h>
  47. /* The kernel threading is sdio-specific */
  48. #else /* LINUX */
  49. #define ENOMEM 1
  50. #define EFAULT 2
  51. #define EINVAL 3
  52. #define EIO 4
  53. #define ETIMEDOUT 5
  54. #define ERESTARTSYS 6
  55. #endif /* LINUX */
  56. #include <wlioctl.h>
  57. #ifdef DHD_DEBUG
  58. #ifndef DHD_DEBUG_TRAP
  59. #define DHD_DEBUG_TRAP
  60. #endif
  61. #endif
  62. /* Forward decls */
  63. struct dhd_bus;
  64. struct dhd_prot;
  65. struct dhd_info;
  66. /* The level of bus communication with the dongle */
  67. enum dhd_bus_state {
  68. DHD_BUS_DOWN, /* Not ready for frame transfers */
  69. DHD_BUS_LOAD, /* Download access only (CPU reset) */
  70. DHD_BUS_DATA /* Ready for frame transfers */
  71. };
  72. enum dhd_bus_wake_state {
  73. WAKE_LOCK_OFF,
  74. WAKE_LOCK_PRIV,
  75. WAKE_LOCK_DPC,
  76. WAKE_LOCK_IOCTL,
  77. WAKE_LOCK_DOWNLOAD,
  78. WAKE_LOCK_TMOUT,
  79. WAKE_LOCK_WATCHDOG,
  80. WAKE_LOCK_LINK_DOWN_TMOUT,
  81. WAKE_LOCK_PNO_FIND_TMOUT,
  82. WAKE_LOCK_SOFTAP_SET,
  83. WAKE_LOCK_SOFTAP_STOP,
  84. WAKE_LOCK_SOFTAP_START,
  85. WAKE_LOCK_SOFTAP_THREAD,
  86. WAKE_LOCK_MAX
  87. };
  88. enum dhd_prealloc_index {
  89. DHD_PREALLOC_PROT = 0,
  90. DHD_PREALLOC_RXBUF,
  91. DHD_PREALLOC_DATABUF,
  92. DHD_PREALLOC_OSL_BUF
  93. };
  94. #ifdef DHD_USE_STATIC_BUF
  95. extern void * dhd_os_prealloc(int section, unsigned long size);
  96. #endif
  97. /* Common structure for module and instance linkage */
  98. typedef struct dhd_pub {
  99. /* Linkage ponters */
  100. osl_t *osh; /* OSL handle */
  101. struct dhd_bus *bus; /* Bus module handle */
  102. struct dhd_prot *prot; /* Protocol module handle */
  103. struct dhd_info *info; /* Info module handle */
  104. /* Internal dhd items */
  105. bool up; /* Driver up/down (to OS) */
  106. bool txoff; /* Transmit flow-controlled */
  107. bool dongle_reset; /* TRUE = DEVRESET put dongle into reset */
  108. enum dhd_bus_state busstate;
  109. uint hdrlen; /* Total DHD header length (proto + bus) */
  110. uint maxctl; /* Max size rxctl request from proto to bus */
  111. uint rxsz; /* Rx buffer size bus module should use */
  112. uint8 wme_dp; /* wme discard priority */
  113. /* Dongle media info */
  114. bool iswl; /* Dongle-resident driver is wl */
  115. ulong drv_version; /* Version of dongle-resident driver */
  116. struct ether_addr mac; /* MAC address obtained from dongle */
  117. dngl_stats_t dstats; /* Stats for dongle-based data */
  118. /* Additional stats for the bus level */
  119. ulong tx_packets; /* Data packets sent to dongle */
  120. ulong tx_multicast; /* Multicast data packets sent to dongle */
  121. ulong tx_errors; /* Errors in sending data to dongle */
  122. ulong tx_ctlpkts; /* Control packets sent to dongle */
  123. ulong tx_ctlerrs; /* Errors sending control frames to dongle */
  124. ulong rx_packets; /* Packets sent up the network interface */
  125. ulong rx_multicast; /* Multicast packets sent up the network interface */
  126. ulong rx_errors; /* Errors processing rx data packets */
  127. ulong rx_ctlpkts; /* Control frames processed from dongle */
  128. ulong rx_ctlerrs; /* Errors in processing rx control frames */
  129. ulong rx_dropped; /* Packets dropped locally (no memory) */
  130. ulong rx_flushed; /* Packets flushed due to unscheduled sendup thread */
  131. ulong wd_dpc_sched; /* Number of times dhd dpc scheduled by watchdog timer */
  132. ulong rx_readahead_cnt; /* Number of packets where header read-ahead was used. */
  133. ulong tx_realloc; /* Number of tx packets we had to realloc for headroom */
  134. ulong fc_packets; /* Number of flow control pkts recvd */
  135. /* Last error return */
  136. int bcmerror;
  137. uint tickcnt;
  138. /* Last error from dongle */
  139. int dongle_error;
  140. /* Suspend disable flag and "in suspend" flag */
  141. int suspend_disable_flag; /* "1" to disable all extra powersaving during suspend */
  142. int in_suspend; /* flag set to 1 when early suspend called */
  143. int hang_was_sent; /* flag that message was send at least once */
  144. #ifdef PNO_SUPPORT
  145. int pno_enable; /* pno status : "1" is pno enable */
  146. #endif /* PNO_SUPPORT */
  147. int dtim_skip; /* dtim skip , default 0 means wake each dtim */
  148. /* Pkt filter defination */
  149. char * pktfilter[100];
  150. int pktfilter_count;
  151. wl_country_t dhd_cspec; /* Current Locale info */
  152. char eventmask[WL_EVENTING_MASK_LEN];
  153. } dhd_pub_t;
  154. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
  155. #define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
  156. #define _DHD_PM_RESUME_WAIT(a, b) do { \
  157. int retry = 0; \
  158. smp_mb(); \
  159. while (dhd_mmc_suspend && retry++ != b) { \
  160. wait_event_interruptible_timeout(a, FALSE, HZ/100); \
  161. } \
  162. } while (0)
  163. #define DHD_PM_RESUME_WAIT(a) _DHD_PM_RESUME_WAIT(a, 200)
  164. #define DHD_PM_RESUME_WAIT_FOREVER(a) _DHD_PM_RESUME_WAIT(a, ~0)
  165. #define DHD_PM_RESUME_RETURN_ERROR(a) do { if (dhd_mmc_suspend) return a; } while (0)
  166. #define DHD_PM_RESUME_RETURN do { if (dhd_mmc_suspend) return; } while (0)
  167. #define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
  168. #define SPINWAIT_SLEEP(a, exp, us) do { \
  169. uint countdown = (us) + 9999; \
  170. while ((exp) && (countdown >= 10000)) { \
  171. wait_event_interruptible_timeout(a, FALSE, HZ/100); \
  172. countdown -= 10000; \
  173. } \
  174. } while (0)
  175. #else
  176. #define DHD_PM_RESUME_WAIT_INIT(a)
  177. #define DHD_PM_RESUME_WAIT(a)
  178. #define DHD_PM_RESUME_WAIT_FOREVER(a)
  179. #define DHD_PM_RESUME_RETURN_ERROR(a)
  180. #define DHD_PM_RESUME_RETURN
  181. #define DHD_SPINWAIT_SLEEP_INIT(a)
  182. #define SPINWAIT_SLEEP(a, exp, us) do { \
  183. uint countdown = (us) + 9; \
  184. while ((exp) && (countdown >= 10)) { \
  185. OSL_DELAY(10); \
  186. countdown -= 10; \
  187. } \
  188. } while (0)
  189. #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
  190. #define DHD_IF_VIF 0x01 /* Virtual IF (Hidden from user) */
  191. inline static void NETIF_ADDR_LOCK(struct net_device *dev)
  192. {
  193. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  194. netif_addr_lock_bh(dev);
  195. #endif
  196. }
  197. inline static void NETIF_ADDR_UNLOCK(struct net_device *dev)
  198. {
  199. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  200. netif_addr_unlock_bh(dev);
  201. #endif
  202. }
  203. /* Wakelock Functions */
  204. extern int dhd_os_wake_lock(dhd_pub_t *pub);
  205. extern int dhd_os_wake_unlock(dhd_pub_t *pub);
  206. extern int dhd_os_wake_lock_timeout(dhd_pub_t *pub);
  207. extern int dhd_os_wake_lock_timeout_enable(dhd_pub_t *pub);
  208. extern void dhd_os_start_lock(dhd_pub_t *pub);
  209. extern void dhd_os_start_unlock(dhd_pub_t *pub);
  210. extern unsigned long dhd_os_spin_lock(dhd_pub_t *pub);
  211. extern void dhd_os_spin_unlock(dhd_pub_t *pub, unsigned long flags);
  212. typedef struct dhd_if_event {
  213. uint8 ifidx;
  214. uint8 action;
  215. uint8 flags;
  216. uint8 bssidx;
  217. } dhd_if_event_t;
  218. /*
  219. * Exported from dhd OS modules (dhd_linux/dhd_ndis)
  220. */
  221. /* To allow osl_attach/detach calls from os-independent modules */
  222. osl_t *dhd_osl_attach(void *pdev, uint bustype);
  223. void dhd_osl_detach(osl_t *osh);
  224. /* Indication from bus module regarding presence/insertion of dongle.
  225. * Return dhd_pub_t pointer, used as handle to OS module in later calls.
  226. * Returned structure should have bus and prot pointers filled in.
  227. * bus_hdrlen specifies required headroom for bus module header.
  228. */
  229. extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
  230. extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
  231. /* Indication from bus module regarding removal/absence of dongle */
  232. extern void dhd_detach(dhd_pub_t *dhdp);
  233. /* Indication from bus module to change flow-control state */
  234. extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
  235. extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
  236. /* Receive frame for delivery to OS. Callee disposes of rxp. */
  237. extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt);
  238. /* Return pointer to interface name */
  239. extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
  240. /* Request scheduling of the bus dpc */
  241. extern void dhd_sched_dpc(dhd_pub_t *dhdp);
  242. /* Notify tx completion */
  243. extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
  244. /* Query ioctl */
  245. extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len);
  246. /* OS independent layer functions */
  247. extern int dhd_os_proto_block(dhd_pub_t * pub);
  248. extern int dhd_os_proto_unblock(dhd_pub_t * pub);
  249. extern int dhd_os_ioctl_resp_wait(dhd_pub_t * pub, uint * condition, bool * pending);
  250. extern int dhd_os_ioctl_resp_wake(dhd_pub_t * pub);
  251. extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
  252. extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
  253. extern void * dhd_os_open_image(char * filename);
  254. extern int dhd_os_get_image_block(char * buf, int len, void * image);
  255. extern void dhd_os_close_image(void * image);
  256. extern void dhd_os_wd_timer(void *bus, uint wdtick);
  257. extern void dhd_os_sdlock(dhd_pub_t * pub);
  258. extern void dhd_os_sdunlock(dhd_pub_t * pub);
  259. extern void dhd_os_sdlock_txq(dhd_pub_t * pub);
  260. extern void dhd_os_sdunlock_txq(dhd_pub_t * pub);
  261. extern void dhd_os_sdlock_rxq(dhd_pub_t * pub);
  262. extern void dhd_os_sdunlock_rxq(dhd_pub_t * pub);
  263. extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t * pub);
  264. extern void dhd_customer_gpio_wlan_ctrl(int onoff);
  265. extern int dhd_custom_get_mac_address(unsigned char *buf);
  266. extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t * pub);
  267. extern void dhd_os_sdlock_eventq(dhd_pub_t * pub);
  268. extern void dhd_os_sdunlock_eventq(dhd_pub_t * pub);
  269. #ifdef DHD_DEBUG
  270. extern int write_to_file(dhd_pub_t *dhd, uint8 *buf, int size);
  271. #endif /* DHD_DEBUG */
  272. #if defined(OOB_INTR_ONLY)
  273. extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
  274. #endif /* defined(OOB_INTR_ONLY) */
  275. extern void dhd_os_sdtxlock(dhd_pub_t * pub);
  276. extern void dhd_os_sdtxunlock(dhd_pub_t * pub);
  277. int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
  278. typedef struct {
  279. uint32 limit; /* Expiration time (usec) */
  280. uint32 increment; /* Current expiration increment (usec) */
  281. uint32 elapsed; /* Current elapsed time (usec) */
  282. uint32 tick; /* O/S tick time (usec) */
  283. } dhd_timeout_t;
  284. extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
  285. extern int dhd_timeout_expired(dhd_timeout_t *tmo);
  286. extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
  287. extern uint8 *dhd_bssidx2bssid(dhd_pub_t *dhd, int idx);
  288. extern int wl_host_event(struct dhd_info *dhd, int *idx, void *pktdata,
  289. wl_event_msg_t *, void **data_ptr);
  290. extern void wl_event_to_host_order(wl_event_msg_t * evt);
  291. extern void dhd_common_init(void);
  292. extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
  293. char *name, uint8 *mac_addr, uint32 flags, uint8 bssidx);
  294. extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
  295. extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char * name);
  296. extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
  297. extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
  298. extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, uchar *cp, int len);
  299. /* Send packet to dongle via data channel */
  300. extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
  301. /* Send event to host */
  302. extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
  303. extern int dhd_bus_devreset(dhd_pub_t *dhdp, uint8 flag);
  304. extern uint dhd_bus_status(dhd_pub_t *dhdp);
  305. extern int dhd_bus_start(dhd_pub_t *dhdp);
  306. extern void print_buf(void *pbuf, int len, int bytes_per_line);
  307. typedef enum cust_gpio_modes {
  308. WLAN_RESET_ON,
  309. WLAN_RESET_OFF,
  310. WLAN_POWER_ON,
  311. WLAN_POWER_OFF
  312. } cust_gpio_modes_t;
  313. extern int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag);
  314. extern int wl_iw_send_priv_event(struct net_device *dev, char *flag);
  315. extern int net_os_send_hang_message(struct net_device *dev);
  316. /*
  317. * Insmod parameters for debug/test
  318. */
  319. /* Watchdog timer interval */
  320. extern uint dhd_watchdog_ms;
  321. #if defined(DHD_DEBUG)
  322. /* Console output poll interval */
  323. extern uint dhd_console_ms;
  324. #endif /* defined(DHD_DEBUG) */
  325. /* Use interrupts */
  326. extern uint dhd_intr;
  327. /* Use polling */
  328. extern uint dhd_poll;
  329. /* ARP offload agent mode */
  330. extern uint dhd_arp_mode;
  331. /* ARP offload enable */
  332. extern uint dhd_arp_enable;
  333. /* Pkt filte enable control */
  334. extern uint dhd_pkt_filter_enable;
  335. /* Pkt filter init setup */
  336. extern uint dhd_pkt_filter_init;
  337. /* Pkt filter mode control */
  338. extern uint dhd_master_mode;
  339. /* Roaming mode control */
  340. extern uint dhd_roam;
  341. /* Roaming mode control */
  342. extern uint dhd_radio_up;
  343. /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
  344. extern int dhd_idletime;
  345. #define DHD_IDLETIME_TICKS 1
  346. /* SDIO Drive Strength */
  347. extern uint dhd_sdiod_drive_strength;
  348. /* Override to force tx queueing all the time */
  349. extern uint dhd_force_tx_queueing;
  350. /* Default KEEP_ALIVE Period is 55 sec to prevent AP from sending Keep Alive probe frame */
  351. #define KEEP_ALIVE_PERIOD 55000
  352. #define NULL_PKT_STR "null_pkt"
  353. #ifdef SDTEST
  354. /* Echo packet generator (SDIO), pkts/s */
  355. extern uint dhd_pktgen;
  356. /* Echo packet len (0 => sawtooth, max 1800) */
  357. extern uint dhd_pktgen_len;
  358. #define MAX_PKTGEN_LEN 1800
  359. #endif
  360. /* optionally set by a module_param_string() */
  361. #define MOD_PARAM_PATHLEN 2048
  362. extern char fw_path[MOD_PARAM_PATHLEN];
  363. extern char nv_path[MOD_PARAM_PATHLEN];
  364. /* For supporting multiple interfaces */
  365. #define DHD_MAX_IFS 16
  366. #define DHD_DEL_IF -0xe
  367. #define DHD_BAD_IF -0xf
  368. extern void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar);
  369. extern void dhd_wait_event_wakeup(dhd_pub_t*dhd);
  370. /* dhd_commn arp offload wrapers */
  371. extern void dhd_arp_cleanup(dhd_pub_t *dhd);
  372. int dhd_arp_get_arp_hostip_table(dhd_pub_t *dhd, void *buf, int buflen);
  373. void dhd_arp_offload_add_ip(dhd_pub_t *dhd, u32 ipaddr);
  374. #define DHD_UNICAST_FILTER_NUM 0
  375. #define DHD_BROADCAST_FILTER_NUM 1
  376. #define DHD_MULTICAST4_FILTER_NUM 2
  377. #define DHD_MULTICAST6_FILTER_NUM 3
  378. extern int net_os_set_packet_filter(struct net_device *dev, int val);
  379. extern int net_os_rxfilter_add_remove(struct net_device *dev, int val, int num);
  380. #endif /* _dhd_h_ */