Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / net / wireless / ath / ath11k / htc.h
blob6c8a469d7f9dfc24bef95204e1e26bcd38d91339
1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2 /*
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4 */
6 #ifndef ATH11K_HTC_H
7 #define ATH11K_HTC_H
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>
15 struct ath11k_base;
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)
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)
31 #define HTC_READY_EX_MSG_HTCVERSION GENMASK(7, 0)
32 #define HTC_READY_EX_MSG_MAXMSGSPERHTCBUNDLE GENMASK(15, 8)
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)
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)
47 enum ath11k_htc_tx_flags {
48 ATH11K_HTC_FLAG_NEED_CREDIT_UPDATE = 0x01,
49 ATH11K_HTC_FLAG_SEND_BUNDLE = 0x02
52 enum ath11k_htc_rx_flags {
53 ATH11K_HTC_FLAG_TRAILER_PRESENT = 0x02,
54 ATH11K_HTC_FLAG_BUNDLE_MASK = 0xF0
57 struct ath11k_htc_hdr {
58 u32 htc_info;
59 u32 ctrl_info;
60 } __packed __aligned(4);
62 enum 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,
73 enum ath11k_htc_version {
74 ATH11K_HTC_VERSION_2P0 = 0x00, /* 2.0 */
75 ATH11K_HTC_VERSION_2P1 = 0x01, /* 2.1 */
78 #define ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_MASK GENMASK(1, 0)
79 #define ATH11K_HTC_CONN_FLAGS_RECV_ALLOC GENMASK(15, 8)
81 enum 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 = 1 << 2,
87 ATH11K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL = 1 << 3
90 enum 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
98 struct ath11k_htc_ready {
99 u32 id_credit_count;
100 u32 size_ep;
101 } __packed;
103 struct ath11k_htc_ready_extended {
104 struct ath11k_htc_ready base;
105 u32 ver_bundle;
106 } __packed;
108 struct ath11k_htc_conn_svc {
109 u32 msg_svc_id;
110 u32 flags_len;
111 } __packed;
113 struct ath11k_htc_conn_svc_resp {
114 u32 msg_svc_id;
115 u32 flags_len;
116 u32 svc_meta_pad;
117 } __packed;
119 struct ath11k_htc_setup_complete_extended {
120 u32 msg_id;
121 u32 flags;
122 u32 max_msgs_per_bundled_recv;
123 } __packed;
125 struct ath11k_htc_msg {
126 u32 msg_svc_id;
127 u32 flags_len;
128 } __packed __aligned(4);
130 enum ath11k_htc_record_id {
131 ATH11K_HTC_RECORD_NULL = 0,
132 ATH11K_HTC_RECORD_CREDITS = 1
135 struct ath11k_htc_record_hdr {
136 u8 id; /* @enum ath11k_htc_record_id */
137 u8 len;
138 u8 pad0;
139 u8 pad1;
140 } __packed;
142 struct ath11k_htc_credit_report {
143 u8 eid; /* @enum ath11k_htc_ep_id */
144 u8 credits;
145 u8 pad0;
146 u8 pad1;
147 } __packed;
149 struct ath11k_htc_record {
150 struct ath11k_htc_record_hdr hdr;
151 union {
152 struct ath11k_htc_credit_report credit_report[0];
153 u8 pauload[0];
155 } __packed __aligned(4);
157 /* note: the trailer offset is dynamic depending
158 * on payload length. this is only a struct layout draft
160 struct ath11k_htc_frame {
161 struct ath11k_htc_hdr hdr;
162 union {
163 struct ath11k_htc_msg msg;
164 u8 payload[0];
166 struct ath11k_htc_record trailer[0];
167 } __packed __aligned(4);
169 enum ath11k_htc_svc_gid {
170 ATH11K_HTC_SVC_GRP_RSVD = 0,
171 ATH11K_HTC_SVC_GRP_WMI = 1,
172 ATH11K_HTC_SVC_GRP_NMI = 2,
173 ATH11K_HTC_SVC_GRP_HTT = 3,
174 ATH11K_HTC_SVC_GRP_CFG = 4,
175 ATH11K_HTC_SVC_GRP_IPA = 5,
176 ATH11K_HTC_SVC_GRP_PKTLOG = 6,
178 ATH11K_HTC_SVC_GRP_TEST = 254,
179 ATH11K_HTC_SVC_GRP_LAST = 255,
182 #define SVC(group, idx) \
183 (int)(((int)(group) << 8) | (int)(idx))
185 enum ath11k_htc_svc_id {
186 /* NOTE: service ID of 0x0000 is reserved and should never be used */
187 ATH11K_HTC_SVC_ID_RESERVED = 0x0000,
188 ATH11K_HTC_SVC_ID_UNUSED = ATH11K_HTC_SVC_ID_RESERVED,
190 ATH11K_HTC_SVC_ID_RSVD_CTRL = SVC(ATH11K_HTC_SVC_GRP_RSVD, 1),
191 ATH11K_HTC_SVC_ID_WMI_CONTROL = SVC(ATH11K_HTC_SVC_GRP_WMI, 0),
192 ATH11K_HTC_SVC_ID_WMI_DATA_BE = SVC(ATH11K_HTC_SVC_GRP_WMI, 1),
193 ATH11K_HTC_SVC_ID_WMI_DATA_BK = SVC(ATH11K_HTC_SVC_GRP_WMI, 2),
194 ATH11K_HTC_SVC_ID_WMI_DATA_VI = SVC(ATH11K_HTC_SVC_GRP_WMI, 3),
195 ATH11K_HTC_SVC_ID_WMI_DATA_VO = SVC(ATH11K_HTC_SVC_GRP_WMI, 4),
196 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1 = SVC(ATH11K_HTC_SVC_GRP_WMI, 5),
197 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 = SVC(ATH11K_HTC_SVC_GRP_WMI, 6),
199 ATH11K_HTC_SVC_ID_NMI_CONTROL = SVC(ATH11K_HTC_SVC_GRP_NMI, 0),
200 ATH11K_HTC_SVC_ID_NMI_DATA = SVC(ATH11K_HTC_SVC_GRP_NMI, 1),
202 ATH11K_HTC_SVC_ID_HTT_DATA_MSG = SVC(ATH11K_HTC_SVC_GRP_HTT, 0),
204 /* raw stream service (i.e. flash, tcmd, calibration apps) */
205 ATH11K_HTC_SVC_ID_TEST_RAW_STREAMS = SVC(ATH11K_HTC_SVC_GRP_TEST, 0),
206 ATH11K_HTC_SVC_ID_IPA_TX = SVC(ATH11K_HTC_SVC_GRP_IPA, 0),
207 ATH11K_HTC_SVC_ID_PKT_LOG = SVC(ATH11K_HTC_SVC_GRP_PKTLOG, 0),
210 #undef SVC
212 enum ath11k_htc_ep_id {
213 ATH11K_HTC_EP_UNUSED = -1,
214 ATH11K_HTC_EP_0 = 0,
215 ATH11K_HTC_EP_1 = 1,
216 ATH11K_HTC_EP_2,
217 ATH11K_HTC_EP_3,
218 ATH11K_HTC_EP_4,
219 ATH11K_HTC_EP_5,
220 ATH11K_HTC_EP_6,
221 ATH11K_HTC_EP_7,
222 ATH11K_HTC_EP_8,
223 ATH11K_HTC_EP_COUNT,
226 struct ath11k_htc_ep_ops {
227 void (*ep_tx_complete)(struct ath11k_base *, struct sk_buff *);
228 void (*ep_rx_complete)(struct ath11k_base *, struct sk_buff *);
229 void (*ep_tx_credits)(struct ath11k_base *);
232 /* service connection information */
233 struct ath11k_htc_svc_conn_req {
234 u16 service_id;
235 struct ath11k_htc_ep_ops ep_ops;
236 int max_send_queue_depth;
239 /* service connection response information */
240 struct ath11k_htc_svc_conn_resp {
241 u8 buffer_len;
242 u8 actual_len;
243 enum ath11k_htc_ep_id eid;
244 unsigned int max_msg_len;
245 u8 connect_resp_code;
248 #define ATH11K_NUM_CONTROL_TX_BUFFERS 2
249 #define ATH11K_HTC_MAX_LEN 4096
250 #define ATH11K_HTC_MAX_CTRL_MSG_LEN 256
251 #define ATH11K_HTC_WAIT_TIMEOUT_HZ (1 * HZ)
252 #define ATH11K_HTC_CONTROL_BUFFER_SIZE (ATH11K_HTC_MAX_CTRL_MSG_LEN + \
253 sizeof(struct ath11k_htc_hdr))
254 #define ATH11K_HTC_CONN_SVC_TIMEOUT_HZ (1 * HZ)
255 #define ATH11K_HTC_MAX_SERVICE_ALLOC_ENTRIES 8
257 struct ath11k_htc_ep {
258 struct ath11k_htc *htc;
259 enum ath11k_htc_ep_id eid;
260 enum ath11k_htc_svc_id service_id;
261 struct ath11k_htc_ep_ops ep_ops;
263 int max_tx_queue_depth;
264 int max_ep_message_len;
265 u8 ul_pipe_id;
266 u8 dl_pipe_id;
268 u8 seq_no; /* for debugging */
269 int tx_credits;
270 bool tx_credit_flow_enabled;
273 struct ath11k_htc_svc_tx_credits {
274 u16 service_id;
275 u8 credit_allocation;
278 struct ath11k_htc {
279 struct ath11k_base *ab;
280 struct ath11k_htc_ep endpoint[ATH11K_HTC_EP_COUNT];
282 /* protects endpoints */
283 spinlock_t tx_lock;
285 u8 control_resp_buffer[ATH11K_HTC_MAX_CTRL_MSG_LEN];
286 int control_resp_len;
288 struct completion ctl_resp;
290 int total_transmit_credits;
291 struct ath11k_htc_svc_tx_credits
292 service_alloc_table[ATH11K_HTC_MAX_SERVICE_ALLOC_ENTRIES];
293 int target_credit_size;
294 u8 wmi_ep_count;
297 int ath11k_htc_init(struct ath11k_base *ar);
298 int ath11k_htc_wait_target(struct ath11k_htc *htc);
299 int ath11k_htc_start(struct ath11k_htc *htc);
300 int ath11k_htc_connect_service(struct ath11k_htc *htc,
301 struct ath11k_htc_svc_conn_req *conn_req,
302 struct ath11k_htc_svc_conn_resp *conn_resp);
303 int ath11k_htc_send(struct ath11k_htc *htc, enum ath11k_htc_ep_id eid,
304 struct sk_buff *packet);
305 struct sk_buff *ath11k_htc_alloc_skb(struct ath11k_base *ar, int size);
306 void ath11k_htc_rx_completion_handler(struct ath11k_base *ar,
307 struct sk_buff *skb);
309 #endif