1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */ 2 /* 3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. 4 * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. 5 */ 6 7 #ifndef ATH11K_HTC_H 8 #define ATH11K_HTC_H 9 10 #include <linux/kernel.h> 11 #include <linux/list.h> 12 #include <linux/bug.h> 13 #include <linux/skbuff.h> 14 #include <linux/timer.h> 15 16 struct ath11k_base; 17 18 #define HTC_HDR_ENDPOINTID GENMASK(7, 0) 19 #define HTC_HDR_FLAGS GENMASK(15, 8) 20 #define HTC_HDR_PAYLOADLEN GENMASK(31, 16) 21 #define HTC_HDR_CONTROLBYTES0 GENMASK(7, 0) 22 #define HTC_HDR_CONTROLBYTES1 GENMASK(15, 8) 23 #define HTC_HDR_RESERVED GENMASK(31, 16) 24 25 #define HTC_SVC_MSG_SERVICE_ID GENMASK(31, 16) 26 #define HTC_SVC_MSG_CONNECTIONFLAGS GENMASK(15, 0) 27 #define HTC_SVC_MSG_SERVICEMETALENGTH GENMASK(23, 16) 28 #define HTC_READY_MSG_CREDITCOUNT GENMASK(31, 16) 29 #define HTC_READY_MSG_CREDITSIZE GENMASK(15, 0) 30 #define HTC_READY_MSG_MAXENDPOINTS GENMASK(23, 16) 31 32 #define HTC_READY_EX_MSG_HTCVERSION GENMASK(7, 0) 33 #define HTC_READY_EX_MSG_MAXMSGSPERHTCBUNDLE GENMASK(15, 8) 34 35 #define HTC_SVC_RESP_MSG_SERVICEID GENMASK(31, 16) 36 #define HTC_SVC_RESP_MSG_STATUS GENMASK(7, 0) 37 #define HTC_SVC_RESP_MSG_ENDPOINTID GENMASK(15, 8) 38 #define HTC_SVC_RESP_MSG_MAXMSGSIZE GENMASK(31, 16) 39 #define HTC_SVC_RESP_MSG_SERVICEMETALENGTH GENMASK(7, 0) 40 41 #define HTC_MSG_MESSAGEID GENMASK(15, 0) 42 #define HTC_SETUP_COMPLETE_EX_MSG_SETUPFLAGS GENMASK(31, 0) 43 #define HTC_SETUP_COMPLETE_EX_MSG_MAXMSGSPERBUNDLEDRECV GENMASK(7, 0) 44 #define HTC_SETUP_COMPLETE_EX_MSG_RSVD0 GENMASK(15, 8) 45 #define HTC_SETUP_COMPLETE_EX_MSG_RSVD1 GENMASK(23, 16) 46 #define HTC_SETUP_COMPLETE_EX_MSG_RSVD2 GENMASK(31, 24) 47 48 enum ath11k_htc_tx_flags { 49 ATH11K_HTC_FLAG_NEED_CREDIT_UPDATE = 0x01, 50 ATH11K_HTC_FLAG_SEND_BUNDLE = 0x02 51 }; 52 53 enum ath11k_htc_rx_flags { 54 ATH11K_HTC_FLAG_TRAILER_PRESENT = 0x02, 55 ATH11K_HTC_FLAG_BUNDLE_MASK = 0xF0 56 }; 57 58 struct ath11k_htc_hdr { 59 u32 htc_info; 60 u32 ctrl_info; 61 } __packed __aligned(4); 62 63 enum ath11k_htc_msg_id { 64 ATH11K_HTC_MSG_READY_ID = 1, 65 ATH11K_HTC_MSG_CONNECT_SERVICE_ID = 2, 66 ATH11K_HTC_MSG_CONNECT_SERVICE_RESP_ID = 3, 67 ATH11K_HTC_MSG_SETUP_COMPLETE_ID = 4, 68 ATH11K_HTC_MSG_SETUP_COMPLETE_EX_ID = 5, 69 ATH11K_HTC_MSG_SEND_SUSPEND_COMPLETE = 6, 70 ATH11K_HTC_MSG_NACK_SUSPEND = 7, 71 ATH11K_HTC_MSG_WAKEUP_FROM_SUSPEND_ID = 8, 72 }; 73 74 enum ath11k_htc_version { 75 ATH11K_HTC_VERSION_2P0 = 0x00, /* 2.0 */ 76 ATH11K_HTC_VERSION_2P1 = 0x01, /* 2.1 */ 77 }; 78 79 #define ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_MASK GENMASK(1, 0) 80 #define ATH11K_HTC_CONN_FLAGS_RECV_ALLOC GENMASK(15, 8) 81 82 enum ath11k_htc_conn_flags { 83 ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_ONE_FOURTH = 0x0, 84 ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_ONE_HALF = 0x1, 85 ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_THREE_FOURTHS = 0x2, 86 ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_UNITY = 0x3, 87 ATH11K_HTC_CONN_FLAGS_REDUCE_CREDIT_DRIBBLE = 0x4, 88 ATH11K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL = 0x8, 89 }; 90 91 enum ath11k_htc_conn_svc_status { 92 ATH11K_HTC_CONN_SVC_STATUS_SUCCESS = 0, 93 ATH11K_HTC_CONN_SVC_STATUS_NOT_FOUND = 1, 94 ATH11K_HTC_CONN_SVC_STATUS_FAILED = 2, 95 ATH11K_HTC_CONN_SVC_STATUS_NO_RESOURCES = 3, 96 ATH11K_HTC_CONN_SVC_STATUS_NO_MORE_EP = 4 97 }; 98 99 struct ath11k_htc_ready { 100 u32 id_credit_count; 101 u32 size_ep; 102 } __packed; 103 104 struct ath11k_htc_ready_extended { 105 struct ath11k_htc_ready base; 106 u32 ver_bundle; 107 } __packed; 108 109 struct ath11k_htc_conn_svc { 110 u32 msg_svc_id; 111 u32 flags_len; 112 } __packed; 113 114 struct ath11k_htc_conn_svc_resp { 115 u32 msg_svc_id; 116 u32 flags_len; 117 u32 svc_meta_pad; 118 } __packed; 119 120 #define ATH11K_GLOBAL_DISABLE_CREDIT_FLOW BIT(1) 121 122 struct ath11k_htc_setup_complete_extended { 123 u32 msg_id; 124 u32 flags; 125 u32 max_msgs_per_bundled_recv; 126 } __packed; 127 128 struct ath11k_htc_msg { 129 u32 msg_svc_id; 130 u32 flags_len; 131 } __packed __aligned(4); 132 133 enum ath11k_htc_record_id { 134 ATH11K_HTC_RECORD_NULL = 0, 135 ATH11K_HTC_RECORD_CREDITS = 1 136 }; 137 138 struct ath11k_htc_record_hdr { 139 u8 id; /* @enum ath11k_htc_record_id */ 140 u8 len; 141 u8 pad0; 142 u8 pad1; 143 } __packed; 144 145 struct ath11k_htc_credit_report { 146 u8 eid; /* @enum ath11k_htc_ep_id */ 147 u8 credits; 148 u8 pad0; 149 u8 pad1; 150 } __packed; 151 152 struct ath11k_htc_record { 153 struct ath11k_htc_record_hdr hdr; 154 union { 155 struct ath11k_htc_credit_report credit_report[0]; 156 u8 pauload[0]; 157 }; 158 } __packed __aligned(4); 159 160 /* note: the trailer offset is dynamic depending 161 * on payload length. this is only a struct layout draft 162 */ 163 struct ath11k_htc_frame { 164 struct ath11k_htc_hdr hdr; 165 union { 166 struct ath11k_htc_msg msg; 167 u8 payload[0]; 168 }; 169 struct ath11k_htc_record trailer[0]; 170 } __packed __aligned(4); 171 172 enum ath11k_htc_svc_gid { 173 ATH11K_HTC_SVC_GRP_RSVD = 0, 174 ATH11K_HTC_SVC_GRP_WMI = 1, 175 ATH11K_HTC_SVC_GRP_NMI = 2, 176 ATH11K_HTC_SVC_GRP_HTT = 3, 177 ATH11K_HTC_SVC_GRP_CFG = 4, 178 ATH11K_HTC_SVC_GRP_IPA = 5, 179 ATH11K_HTC_SVC_GRP_PKTLOG = 6, 180 181 ATH11K_HTC_SVC_GRP_TEST = 254, 182 ATH11K_HTC_SVC_GRP_LAST = 255, 183 }; 184 185 #define SVC(group, idx) \ 186 (int)(((int)(group) << 8) | (int)(idx)) 187 188 enum ath11k_htc_svc_id { 189 /* NOTE: service ID of 0x0000 is reserved and should never be used */ 190 ATH11K_HTC_SVC_ID_RESERVED = 0x0000, 191 ATH11K_HTC_SVC_ID_UNUSED = ATH11K_HTC_SVC_ID_RESERVED, 192 193 ATH11K_HTC_SVC_ID_RSVD_CTRL = SVC(ATH11K_HTC_SVC_GRP_RSVD, 1), 194 ATH11K_HTC_SVC_ID_WMI_CONTROL = SVC(ATH11K_HTC_SVC_GRP_WMI, 0), 195 ATH11K_HTC_SVC_ID_WMI_DATA_BE = SVC(ATH11K_HTC_SVC_GRP_WMI, 1), 196 ATH11K_HTC_SVC_ID_WMI_DATA_BK = SVC(ATH11K_HTC_SVC_GRP_WMI, 2), 197 ATH11K_HTC_SVC_ID_WMI_DATA_VI = SVC(ATH11K_HTC_SVC_GRP_WMI, 3), 198 ATH11K_HTC_SVC_ID_WMI_DATA_VO = SVC(ATH11K_HTC_SVC_GRP_WMI, 4), 199 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1 = SVC(ATH11K_HTC_SVC_GRP_WMI, 5), 200 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 = SVC(ATH11K_HTC_SVC_GRP_WMI, 6), 201 202 ATH11K_HTC_SVC_ID_NMI_CONTROL = SVC(ATH11K_HTC_SVC_GRP_NMI, 0), 203 ATH11K_HTC_SVC_ID_NMI_DATA = SVC(ATH11K_HTC_SVC_GRP_NMI, 1), 204 205 ATH11K_HTC_SVC_ID_HTT_DATA_MSG = SVC(ATH11K_HTC_SVC_GRP_HTT, 0), 206 207 /* raw stream service (i.e. flash, tcmd, calibration apps) */ 208 ATH11K_HTC_SVC_ID_TEST_RAW_STREAMS = SVC(ATH11K_HTC_SVC_GRP_TEST, 0), 209 ATH11K_HTC_SVC_ID_IPA_TX = SVC(ATH11K_HTC_SVC_GRP_IPA, 0), 210 ATH11K_HTC_SVC_ID_PKT_LOG = SVC(ATH11K_HTC_SVC_GRP_PKTLOG, 0), 211 }; 212 213 #undef SVC 214 215 enum ath11k_htc_ep_id { 216 ATH11K_HTC_EP_UNUSED = -1, 217 ATH11K_HTC_EP_0 = 0, 218 ATH11K_HTC_EP_1 = 1, 219 ATH11K_HTC_EP_2, 220 ATH11K_HTC_EP_3, 221 ATH11K_HTC_EP_4, 222 ATH11K_HTC_EP_5, 223 ATH11K_HTC_EP_6, 224 ATH11K_HTC_EP_7, 225 ATH11K_HTC_EP_8, 226 ATH11K_HTC_EP_COUNT, 227 }; 228 229 struct ath11k_htc_ep_ops { 230 void (*ep_tx_complete)(struct ath11k_base *, struct sk_buff *); 231 void (*ep_rx_complete)(struct ath11k_base *, struct sk_buff *); 232 void (*ep_tx_credits)(struct ath11k_base *); 233 }; 234 235 /* service connection information */ 236 struct ath11k_htc_svc_conn_req { 237 u16 service_id; 238 struct ath11k_htc_ep_ops ep_ops; 239 int max_send_queue_depth; 240 }; 241 242 /* service connection response information */ 243 struct ath11k_htc_svc_conn_resp { 244 u8 buffer_len; 245 u8 actual_len; 246 enum ath11k_htc_ep_id eid; 247 unsigned int max_msg_len; 248 u8 connect_resp_code; 249 }; 250 251 #define ATH11K_NUM_CONTROL_TX_BUFFERS 2 252 #define ATH11K_HTC_MAX_LEN 4096 253 #define ATH11K_HTC_MAX_CTRL_MSG_LEN 256 254 #define ATH11K_HTC_WAIT_TIMEOUT_HZ (1 * HZ) 255 #define ATH11K_HTC_CONTROL_BUFFER_SIZE (ATH11K_HTC_MAX_CTRL_MSG_LEN + \ 256 sizeof(struct ath11k_htc_hdr)) 257 #define ATH11K_HTC_CONN_SVC_TIMEOUT_HZ (1 * HZ) 258 #define ATH11K_HTC_MAX_SERVICE_ALLOC_ENTRIES 8 259 260 struct ath11k_htc_ep { 261 struct ath11k_htc *htc; 262 enum ath11k_htc_ep_id eid; 263 enum ath11k_htc_svc_id service_id; 264 struct ath11k_htc_ep_ops ep_ops; 265 266 int max_tx_queue_depth; 267 int max_ep_message_len; 268 u8 ul_pipe_id; 269 u8 dl_pipe_id; 270 271 u8 seq_no; /* for debugging */ 272 int tx_credits; 273 bool tx_credit_flow_enabled; 274 }; 275 276 struct ath11k_htc_svc_tx_credits { 277 u16 service_id; 278 u8 credit_allocation; 279 }; 280 281 struct ath11k_htc { 282 struct ath11k_base *ab; 283 struct ath11k_htc_ep endpoint[ATH11K_HTC_EP_COUNT]; 284 285 /* protects endpoints */ 286 spinlock_t tx_lock; 287 288 u8 control_resp_buffer[ATH11K_HTC_MAX_CTRL_MSG_LEN]; 289 int control_resp_len; 290 291 struct completion ctl_resp; 292 293 int total_transmit_credits; 294 struct ath11k_htc_svc_tx_credits 295 service_alloc_table[ATH11K_HTC_MAX_SERVICE_ALLOC_ENTRIES]; 296 int target_credit_size; 297 u8 wmi_ep_count; 298 }; 299 300 int ath11k_htc_init(struct ath11k_base *ar); 301 int ath11k_htc_wait_target(struct ath11k_htc *htc); 302 int ath11k_htc_start(struct ath11k_htc *htc); 303 int ath11k_htc_connect_service(struct ath11k_htc *htc, 304 struct ath11k_htc_svc_conn_req *conn_req, 305 struct ath11k_htc_svc_conn_resp *conn_resp); 306 int ath11k_htc_send(struct ath11k_htc *htc, enum ath11k_htc_ep_id eid, 307 struct sk_buff *packet); 308 struct sk_buff *ath11k_htc_alloc_skb(struct ath11k_base *ar, int size); 309 void ath11k_htc_rx_completion_handler(struct ath11k_base *ar, 310 struct sk_buff *skb); 311 void ath11k_htc_tx_completion_handler(struct ath11k_base *ab, 312 struct sk_buff *skb); 313 #endif 314