1 /* 2 * Copyright (c) 2013-2018 The Linux Foundation. All rights reserved. 3 * 4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc. 5 * 6 * 7 * Permission to use, copy, modify, and/or distribute this software for 8 * any purpose with or without fee is hereby granted, provided that the 9 * above copyright notice and this permission notice appear in all 10 * copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 19 * PERFORMANCE OF THIS SOFTWARE. 20 */ 21 22 /* 23 * This file was originally distributed by Qualcomm Atheros, Inc. 24 * under proprietary terms before Copyright ownership was assigned 25 * to the Linux Foundation. 26 */ 27 28 /** 29 * DOC: i_osdep 30 * QCA driver framework OS dependent types 31 */ 32 33 #ifndef _I_OSDEP_H 34 #define _I_OSDEP_H 35 36 #ifdef CONFIG_MCL 37 #include <cds_queue.h> 38 #include <cds_if_upperproto.h> 39 #else 40 #include <sys/queue.h> 41 #endif 42 43 /* 44 * Byte Order stuff 45 */ 46 #define le16toh(_x) le16_to_cpu(_x) 47 #define htole16(_x) cpu_to_le16(_x) 48 #define htobe16(_x) cpu_to_be16(_x) 49 #define le32toh(_x) le32_to_cpu(_x) 50 #define htole32(_x) cpu_to_le32(_x) 51 #define be16toh(_x) be16_to_cpu(_x) 52 #define be32toh(_x) be32_to_cpu(_x) 53 #define htobe32(_x) cpu_to_be32(_x) 54 55 typedef struct timer_list os_timer_t; 56 57 #ifdef CONFIG_SMP 58 /* Undo the one provided by the kernel to debug spin locks */ 59 #undef spin_lock 60 #undef spin_unlock 61 #undef spin_trylock 62 63 #define spin_lock(x) spin_lock_bh(x) 64 65 #define spin_unlock(x) \ 66 do { \ 67 if (!spin_is_locked(x)) { \ 68 WARN_ON(1); \ 69 printk(KERN_EMERG " %s:%d unlock addr=%pK, %s \n", __func__, __LINE__, x, \ 70 !spin_is_locked(x) ? "Not locked" : ""); \ 71 } \ 72 spin_unlock_bh(x); \ 73 } while (0) 74 #define spin_trylock(x) spin_trylock_bh(x) 75 #define OS_SUPPORT_ASYNC_Q 1 /* support for handling asyn function calls */ 76 77 #else 78 #define OS_SUPPORT_ASYNC_Q 0 79 #endif /* ifdef CONFIG_SMP */ 80 81 /** 82 * struct os_mest_t - maintain attributes of message 83 * @mesg_next: pointer to the nexgt message 84 * @mest_type: type of message 85 * @mesg_len: length of the message 86 */ 87 typedef struct _os_mesg_t { 88 STAILQ_ENTRY(_os_mesg_t) mesg_next; 89 uint16_t mesg_type; 90 uint16_t mesg_len; 91 } os_mesg_t; 92 93 /** 94 * struct qdf_bus_context - Bus to hal context handoff 95 * @bc_tag: bus context tag 96 * @cal_in_flash: calibration data stored in flash 97 * @bc_handle: bus context handle 98 * @bc_bustype: bus type 99 */ 100 typedef struct qdf_bus_context { 101 void *bc_tag; 102 int cal_in_flash; 103 char *bc_handle; 104 enum qdf_bus_type bc_bustype; 105 } QDF_BUS_CONTEXT; 106 107 typedef struct _NIC_DEV *osdev_t; 108 109 typedef void (*os_mesg_handler_t)(void *ctx, uint16_t mesg_type, 110 uint16_t mesg_len, 111 void *mesg); 112 113 114 /** 115 * typedef os_mesg_queue_t - Object to maintain message queue 116 * @dev_handle: OS handle 117 * @num_queued: number of queued messages 118 * @mesg_len: message length 119 * @mesg_queue_buf: pointer to message queue buffer 120 * @mesg_head: queued mesg buffers 121 * @mesg_free_head: free mesg buffers 122 * @lock: spinlock object 123 * @ev_handler_lock: spinlock object to event handler 124 * @task: pointer to task 125 * @_timer: instance of timer 126 * @handler: message handler 127 * @ctx: pointer to context 128 * @is_synchronous: bit to save synchronous status 129 * @del_progress: delete in progress 130 */ 131 typedef struct { 132 osdev_t dev_handle; 133 int32_t num_queued; 134 int32_t mesg_len; 135 uint8_t *mesg_queue_buf; 136 137 STAILQ_HEAD(, _os_mesg_t) mesg_head; 138 STAILQ_HEAD(, _os_mesg_t) mesg_free_head; 139 spinlock_t lock; 140 spinlock_t ev_handler_lock; 141 #ifdef USE_SOFTINTR 142 void *_task; 143 #else 144 os_timer_t _timer; 145 #endif 146 os_mesg_handler_t handler; 147 void *ctx; 148 uint8_t is_synchronous:1; 149 uint8_t del_progress; 150 } os_mesg_queue_t; 151 152 /** 153 * struct _NIC_DEV - Definition of OS-dependent device structure. 154 * It'll be opaque to the actual ATH layer. 155 * @qdf_dev: qdf device 156 * @bdev: bus device handle 157 * @netdev: net device handle (wifi%d) 158 * @intr_tq: tasklet 159 * @devstats: net device statistics 160 * @bc: hal bus context 161 * @device: generic device 162 * @event_queue: instance to wait queue 163 * @is_device_asleep: keep device status, sleep or awakei 164 * @acfg_event_list: event list 165 * @acfg_event_queue_lock: queue lock 166 * @acfg_event_os_work: schedule or create work 167 * @acfg_netlink_wq_init_done: Work queue ready 168 * @osdev_acfg_handle: acfg handle 169 * @vap_hardstart: Tx function specific to the radio 170 * initiailzed during VAP create 171 */ 172 struct _NIC_DEV { 173 qdf_device_t qdf_dev; 174 void *bdev; 175 struct net_device *netdev; 176 qdf_bh_t intr_tq; 177 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36) 178 struct rtnl_link_stats64 devstats; 179 #else 180 struct net_device_stats devstats; 181 #endif 182 QDF_BUS_CONTEXT bc; 183 #ifdef ATH_PERF_PWR_OFFLOAD 184 struct device *device; 185 wait_queue_head_t event_queue; 186 #endif /* PERF_PWR_OFFLOAD */ 187 #if OS_SUPPORT_ASYNC_Q 188 os_mesg_queue_t async_q; 189 #endif 190 #ifdef ATH_BUS_PM 191 uint8_t is_device_asleep; 192 #endif /* ATH_BUS_PM */ 193 qdf_nbuf_queue_t acfg_event_list; 194 qdf_spinlock_t acfg_event_queue_lock; 195 qdf_work_t acfg_event_os_work; 196 uint8_t acfg_netlink_wq_init_done; 197 198 #ifdef UMAC_SUPPORT_ACFG 199 #ifdef ACFG_NETLINK_TX 200 void *osdev_acfg_handle; 201 #endif /* ACFG_NETLINK_TX */ 202 #endif /* UMAC_SUPPORT_ACFG */ 203 int (*vap_hardstart)(struct sk_buff *skb, struct net_device *dev); 204 }; 205 206 #define __QDF_SYSCTL_PROC_DOINTVEC(ctl, write, filp, buffer, lenp, ppos) \ 207 proc_dointvec(ctl, write, buffer, lenp, ppos) 208 209 #define __QDF_SYSCTL_PROC_DOSTRING(ctl, write, filp, buffer, lenp, ppos) \ 210 proc_dostring(ctl, write, filp, buffer, lenp, ppos) 211 212 #endif /* _I_OSDEP_H */ 213