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