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