ath10k: add per peer htt tx stats support for 10.4
[linux-stable.git] / drivers / net / wireless / ath / ath10k / htt.c
blobcd160b16db1e0c91788ab336445aa98313a53475
1 /*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/slab.h>
19 #include <linux/if_ether.h>
21 #include "htt.h"
22 #include "core.h"
23 #include "debug.h"
25 static const enum htt_t2h_msg_type htt_main_t2h_msg_types[] = {
26 [HTT_MAIN_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
27 [HTT_MAIN_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
28 [HTT_MAIN_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
29 [HTT_MAIN_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
30 [HTT_MAIN_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
31 [HTT_MAIN_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
32 [HTT_MAIN_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
33 [HTT_MAIN_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
34 [HTT_MAIN_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
35 [HTT_MAIN_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
36 [HTT_MAIN_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
37 [HTT_MAIN_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
38 [HTT_MAIN_T2H_MSG_TYPE_TX_INSPECT_IND] =
39 HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
40 [HTT_MAIN_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
41 HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
42 [HTT_MAIN_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] =
43 HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND,
44 [HTT_MAIN_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND,
45 [HTT_MAIN_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] =
46 HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND,
47 [HTT_MAIN_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
50 static const enum htt_t2h_msg_type htt_10x_t2h_msg_types[] = {
51 [HTT_10X_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
52 [HTT_10X_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
53 [HTT_10X_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
54 [HTT_10X_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
55 [HTT_10X_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
56 [HTT_10X_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
57 [HTT_10X_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
58 [HTT_10X_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
59 [HTT_10X_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
60 [HTT_10X_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
61 [HTT_10X_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
62 [HTT_10X_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
63 [HTT_10X_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND,
64 [HTT_10X_T2H_MSG_TYPE_TX_INSPECT_IND] = HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
65 [HTT_10X_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
66 [HTT_10X_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE,
67 [HTT_10X_T2H_MSG_TYPE_AGGR_CONF] = HTT_T2H_MSG_TYPE_AGGR_CONF,
68 [HTT_10X_T2H_MSG_TYPE_STATS_NOUPLOAD] = HTT_T2H_MSG_TYPE_STATS_NOUPLOAD,
69 [HTT_10X_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
70 HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
73 static const enum htt_t2h_msg_type htt_tlv_t2h_msg_types[] =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TLV_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND,
93 [HTT_TLV_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] =
94 HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND,
95 [HTT_TLV_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND] =
96 HTT_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND,
97 [HTT_TLV_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE] =
98 HTT_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE,
99 [HTT_TLV_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE,
100 [HTT_TLV_T2H_MSG_TYPE_RX_OFLD_PKT_ERR] =
101 HTT_T2H_MSG_TYPE_RX_OFLD_PKT_ERR,
102 [HTT_TLV_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
105 static const enum htt_t2h_msg_type htt_10_4_t2h_msg_types[] = {
106 [HTT_10_4_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
107 [HTT_10_4_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
108 [HTT_10_4_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
109 [HTT_10_4_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
110 [HTT_10_4_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
111 [HTT_10_4_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
112 [HTT_10_4_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
113 [HTT_10_4_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
114 [HTT_10_4_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
115 [HTT_10_4_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
116 [HTT_10_4_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
117 [HTT_10_4_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
118 [HTT_10_4_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND,
119 [HTT_10_4_T2H_MSG_TYPE_TX_INSPECT_IND] =
120 HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
121 [HTT_10_4_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
122 HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
123 [HTT_10_4_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE,
124 [HTT_10_4_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] =
125 HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND,
126 [HTT_10_4_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND,
127 [HTT_10_4_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] =
128 HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND,
129 [HTT_10_4_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
130 [HTT_10_4_T2H_MSG_TYPE_EN_STATS] = HTT_T2H_MSG_TYPE_EN_STATS,
131 [HTT_10_4_T2H_MSG_TYPE_AGGR_CONF] = HTT_T2H_MSG_TYPE_AGGR_CONF,
132 [HTT_10_4_T2H_MSG_TYPE_TX_FETCH_IND] =
133 HTT_T2H_MSG_TYPE_TX_FETCH_IND,
134 [HTT_10_4_T2H_MSG_TYPE_TX_FETCH_CONFIRM] =
135 HTT_T2H_MSG_TYPE_TX_FETCH_CONFIRM,
136 [HTT_10_4_T2H_MSG_TYPE_STATS_NOUPLOAD] =
137 HTT_T2H_MSG_TYPE_STATS_NOUPLOAD,
138 [HTT_10_4_T2H_MSG_TYPE_TX_MODE_SWITCH_IND] =
139 HTT_T2H_MSG_TYPE_TX_MODE_SWITCH_IND,
140 [HTT_10_4_T2H_MSG_TYPE_PEER_STATS] =
141 HTT_T2H_MSG_TYPE_PEER_STATS,
144 int ath10k_htt_connect(struct ath10k_htt *htt)
146 struct ath10k_htc_svc_conn_req conn_req;
147 struct ath10k_htc_svc_conn_resp conn_resp;
148 int status;
150 memset(&conn_req, 0, sizeof(conn_req));
151 memset(&conn_resp, 0, sizeof(conn_resp));
153 conn_req.ep_ops.ep_tx_complete = ath10k_htt_htc_tx_complete;
154 conn_req.ep_ops.ep_rx_complete = ath10k_htt_htc_t2h_msg_handler;
156 /* connect to control service */
157 conn_req.service_id = ATH10K_HTC_SVC_ID_HTT_DATA_MSG;
159 status = ath10k_htc_connect_service(&htt->ar->htc, &conn_req,
160 &conn_resp);
162 if (status)
163 return status;
165 htt->eid = conn_resp.eid;
167 return 0;
170 int ath10k_htt_init(struct ath10k *ar)
172 struct ath10k_htt *htt = &ar->htt;
174 htt->ar = ar;
177 * Prefetch enough data to satisfy target
178 * classification engine.
179 * This is for LL chips. HL chips will probably
180 * transfer all frame in the tx fragment.
182 htt->prefetch_len =
183 36 + /* 802.11 + qos + ht */
184 4 + /* 802.1q */
185 8 + /* llc snap */
186 2; /* ip4 dscp or ip6 priority */
188 switch (ar->running_fw->fw_file.htt_op_version) {
189 case ATH10K_FW_HTT_OP_VERSION_10_4:
190 ar->htt.t2h_msg_types = htt_10_4_t2h_msg_types;
191 ar->htt.t2h_msg_types_max = HTT_10_4_T2H_NUM_MSGS;
192 break;
193 case ATH10K_FW_HTT_OP_VERSION_10_1:
194 ar->htt.t2h_msg_types = htt_10x_t2h_msg_types;
195 ar->htt.t2h_msg_types_max = HTT_10X_T2H_NUM_MSGS;
196 break;
197 case ATH10K_FW_HTT_OP_VERSION_TLV:
198 ar->htt.t2h_msg_types = htt_tlv_t2h_msg_types;
199 ar->htt.t2h_msg_types_max = HTT_TLV_T2H_NUM_MSGS;
200 break;
201 case ATH10K_FW_HTT_OP_VERSION_MAIN:
202 ar->htt.t2h_msg_types = htt_main_t2h_msg_types;
203 ar->htt.t2h_msg_types_max = HTT_MAIN_T2H_NUM_MSGS;
204 break;
205 case ATH10K_FW_HTT_OP_VERSION_MAX:
206 case ATH10K_FW_HTT_OP_VERSION_UNSET:
207 WARN_ON(1);
208 return -EINVAL;
210 return 0;
213 #define HTT_TARGET_VERSION_TIMEOUT_HZ (3 * HZ)
215 static int ath10k_htt_verify_version(struct ath10k_htt *htt)
217 struct ath10k *ar = htt->ar;
219 ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt target version %d.%d\n",
220 htt->target_version_major, htt->target_version_minor);
222 if (htt->target_version_major != 2 &&
223 htt->target_version_major != 3) {
224 ath10k_err(ar, "unsupported htt major version %d. supported versions are 2 and 3\n",
225 htt->target_version_major);
226 return -ENOTSUPP;
229 return 0;
232 int ath10k_htt_setup(struct ath10k_htt *htt)
234 struct ath10k *ar = htt->ar;
235 int status;
237 init_completion(&htt->target_version_received);
239 status = ath10k_htt_h2t_ver_req_msg(htt);
240 if (status)
241 return status;
243 status = wait_for_completion_timeout(&htt->target_version_received,
244 HTT_TARGET_VERSION_TIMEOUT_HZ);
245 if (status == 0) {
246 ath10k_warn(ar, "htt version request timed out\n");
247 return -ETIMEDOUT;
250 status = ath10k_htt_verify_version(htt);
251 if (status) {
252 ath10k_warn(ar, "failed to verify htt version: %d\n",
253 status);
254 return status;
257 status = ath10k_htt_send_frag_desc_bank_cfg(htt);
258 if (status)
259 return status;
261 status = ath10k_htt_send_rx_ring_cfg_ll(htt);
262 if (status) {
263 ath10k_warn(ar, "failed to setup rx ring: %d\n",
264 status);
265 return status;
268 status = ath10k_htt_h2t_aggr_cfg_msg(htt,
269 htt->max_num_ampdu,
270 htt->max_num_amsdu);
271 if (status) {
272 ath10k_warn(ar, "failed to setup amsdu/ampdu limit: %d\n",
273 status);
274 return status;
277 return 0;