treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / wireless / ath / ath11k / htc.h
blobf0a3387567cae7fa4b5c00e8479800975db90153
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
71 enum ath11k_htc_version {
72 ATH11K_HTC_VERSION_2P0 = 0x00, /* 2.0 */
73 ATH11K_HTC_VERSION_2P1 = 0x01, /* 2.1 */
76 #define ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_MASK GENMASK(1, 0)
77 #define ATH11K_HTC_CONN_FLAGS_RECV_ALLOC GENMASK(15, 8)
79 enum ath11k_htc_conn_flags {
80 ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_ONE_FOURTH = 0x0,
81 ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_ONE_HALF = 0x1,
82 ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_THREE_FOURTHS = 0x2,
83 ATH11K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_UNITY = 0x3,
84 ATH11K_HTC_CONN_FLAGS_REDUCE_CREDIT_DRIBBLE = 1 << 2,
85 ATH11K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL = 1 << 3
88 enum ath11k_htc_conn_svc_status {
89 ATH11K_HTC_CONN_SVC_STATUS_SUCCESS = 0,
90 ATH11K_HTC_CONN_SVC_STATUS_NOT_FOUND = 1,
91 ATH11K_HTC_CONN_SVC_STATUS_FAILED = 2,
92 ATH11K_HTC_CONN_SVC_STATUS_NO_RESOURCES = 3,
93 ATH11K_HTC_CONN_SVC_STATUS_NO_MORE_EP = 4
96 struct ath11k_htc_ready {
97 u32 id_credit_count;
98 u32 size_ep;
99 } __packed;
101 struct ath11k_htc_ready_extended {
102 struct ath11k_htc_ready base;
103 u32 ver_bundle;
104 } __packed;
106 struct ath11k_htc_conn_svc {
107 u32 msg_svc_id;
108 u32 flags_len;
109 } __packed;
111 struct ath11k_htc_conn_svc_resp {
112 u32 msg_svc_id;
113 u32 flags_len;
114 u32 svc_meta_pad;
115 } __packed;
117 struct ath11k_htc_setup_complete_extended {
118 u32 msg_id;
119 u32 flags;
120 u32 max_msgs_per_bundled_recv;
121 } __packed;
123 struct ath11k_htc_msg {
124 u32 msg_svc_id;
125 u32 flags_len;
126 } __packed __aligned(4);
128 enum ath11k_htc_record_id {
129 ATH11K_HTC_RECORD_NULL = 0,
130 ATH11K_HTC_RECORD_CREDITS = 1
133 struct ath11k_htc_record_hdr {
134 u8 id; /* @enum ath11k_htc_record_id */
135 u8 len;
136 u8 pad0;
137 u8 pad1;
138 } __packed;
140 struct ath11k_htc_credit_report {
141 u8 eid; /* @enum ath11k_htc_ep_id */
142 u8 credits;
143 u8 pad0;
144 u8 pad1;
145 } __packed;
147 struct ath11k_htc_record {
148 struct ath11k_htc_record_hdr hdr;
149 union {
150 struct ath11k_htc_credit_report credit_report[0];
151 u8 pauload[0];
153 } __packed __aligned(4);
155 /* note: the trailer offset is dynamic depending
156 * on payload length. this is only a struct layout draft
158 struct ath11k_htc_frame {
159 struct ath11k_htc_hdr hdr;
160 union {
161 struct ath11k_htc_msg msg;
162 u8 payload[0];
164 struct ath11k_htc_record trailer[0];
165 } __packed __aligned(4);
167 enum ath11k_htc_svc_gid {
168 ATH11K_HTC_SVC_GRP_RSVD = 0,
169 ATH11K_HTC_SVC_GRP_WMI = 1,
170 ATH11K_HTC_SVC_GRP_NMI = 2,
171 ATH11K_HTC_SVC_GRP_HTT = 3,
172 ATH11K_HTC_SVC_GRP_CFG = 4,
173 ATH11K_HTC_SVC_GRP_IPA = 5,
174 ATH11K_HTC_SVC_GRP_PKTLOG = 6,
176 ATH11K_HTC_SVC_GRP_TEST = 254,
177 ATH11K_HTC_SVC_GRP_LAST = 255,
180 #define SVC(group, idx) \
181 (int)(((int)(group) << 8) | (int)(idx))
183 enum ath11k_htc_svc_id {
184 /* NOTE: service ID of 0x0000 is reserved and should never be used */
185 ATH11K_HTC_SVC_ID_RESERVED = 0x0000,
186 ATH11K_HTC_SVC_ID_UNUSED = ATH11K_HTC_SVC_ID_RESERVED,
188 ATH11K_HTC_SVC_ID_RSVD_CTRL = SVC(ATH11K_HTC_SVC_GRP_RSVD, 1),
189 ATH11K_HTC_SVC_ID_WMI_CONTROL = SVC(ATH11K_HTC_SVC_GRP_WMI, 0),
190 ATH11K_HTC_SVC_ID_WMI_DATA_BE = SVC(ATH11K_HTC_SVC_GRP_WMI, 1),
191 ATH11K_HTC_SVC_ID_WMI_DATA_BK = SVC(ATH11K_HTC_SVC_GRP_WMI, 2),
192 ATH11K_HTC_SVC_ID_WMI_DATA_VI = SVC(ATH11K_HTC_SVC_GRP_WMI, 3),
193 ATH11K_HTC_SVC_ID_WMI_DATA_VO = SVC(ATH11K_HTC_SVC_GRP_WMI, 4),
194 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1 = SVC(ATH11K_HTC_SVC_GRP_WMI, 5),
195 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 = SVC(ATH11K_HTC_SVC_GRP_WMI, 6),
197 ATH11K_HTC_SVC_ID_NMI_CONTROL = SVC(ATH11K_HTC_SVC_GRP_NMI, 0),
198 ATH11K_HTC_SVC_ID_NMI_DATA = SVC(ATH11K_HTC_SVC_GRP_NMI, 1),
200 ATH11K_HTC_SVC_ID_HTT_DATA_MSG = SVC(ATH11K_HTC_SVC_GRP_HTT, 0),
202 /* raw stream service (i.e. flash, tcmd, calibration apps) */
203 ATH11K_HTC_SVC_ID_TEST_RAW_STREAMS = SVC(ATH11K_HTC_SVC_GRP_TEST, 0),
204 ATH11K_HTC_SVC_ID_IPA_TX = SVC(ATH11K_HTC_SVC_GRP_IPA, 0),
205 ATH11K_HTC_SVC_ID_PKT_LOG = SVC(ATH11K_HTC_SVC_GRP_PKTLOG, 0),
208 #undef SVC
210 enum ath11k_htc_ep_id {
211 ATH11K_HTC_EP_UNUSED = -1,
212 ATH11K_HTC_EP_0 = 0,
213 ATH11K_HTC_EP_1 = 1,
214 ATH11K_HTC_EP_2,
215 ATH11K_HTC_EP_3,
216 ATH11K_HTC_EP_4,
217 ATH11K_HTC_EP_5,
218 ATH11K_HTC_EP_6,
219 ATH11K_HTC_EP_7,
220 ATH11K_HTC_EP_8,
221 ATH11K_HTC_EP_COUNT,
224 struct ath11k_htc_ops {
225 void (*target_send_suspend_complete)(struct ath11k_base *ar);
228 struct 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 *);
234 /* service connection information */
235 struct ath11k_htc_svc_conn_req {
236 u16 service_id;
237 struct ath11k_htc_ep_ops ep_ops;
238 int max_send_queue_depth;
241 /* service connection response information */
242 struct 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;
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
259 struct 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;
265 int max_tx_queue_depth;
266 int max_ep_message_len;
267 u8 ul_pipe_id;
268 u8 dl_pipe_id;
270 u8 seq_no; /* for debugging */
271 int tx_credits;
272 bool tx_credit_flow_enabled;
275 struct ath11k_htc_svc_tx_credits {
276 u16 service_id;
277 u8 credit_allocation;
280 struct ath11k_htc {
281 struct ath11k_base *ab;
282 struct ath11k_htc_ep endpoint[ATH11K_HTC_EP_COUNT];
284 /* protects endpoints */
285 spinlock_t tx_lock;
287 struct ath11k_htc_ops htc_ops;
289 u8 control_resp_buffer[ATH11K_HTC_MAX_CTRL_MSG_LEN];
290 int control_resp_len;
292 struct completion ctl_resp;
294 int total_transmit_credits;
295 struct ath11k_htc_svc_tx_credits
296 service_alloc_table[ATH11K_HTC_MAX_SERVICE_ALLOC_ENTRIES];
297 int target_credit_size;
298 u8 wmi_ep_count;
301 int ath11k_htc_init(struct ath11k_base *ar);
302 int ath11k_htc_wait_target(struct ath11k_htc *htc);
303 int ath11k_htc_start(struct ath11k_htc *htc);
304 int ath11k_htc_connect_service(struct ath11k_htc *htc,
305 struct ath11k_htc_svc_conn_req *conn_req,
306 struct ath11k_htc_svc_conn_resp *conn_resp);
307 int ath11k_htc_send(struct ath11k_htc *htc, enum ath11k_htc_ep_id eid,
308 struct sk_buff *packet);
309 struct sk_buff *ath11k_htc_alloc_skb(struct ath11k_base *ar, int size);
310 void ath11k_htc_rx_completion_handler(struct ath11k_base *ar,
311 struct sk_buff *skb);
313 #endif