xref: /linux/drivers/net/wireless/ath/ath10k/htt.c (revision 005438a8eef063495ac059d128eea71b58de50e5)
1 /*
2  * Copyright (c) 2005-2011 Atheros Communications Inc.
3  * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4  *
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.
8  *
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.
16  */
17 
18 #include <linux/slab.h>
19 #include <linux/if_ether.h>
20 
21 #include "htt.h"
22 #include "core.h"
23 #include "debug.h"
24 
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,
48 };
49 
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,
71 };
72 
73 static const enum htt_t2h_msg_type htt_tlv_t2h_msg_types[] = {
74 	[HTT_TLV_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
75 	[HTT_TLV_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
76 	[HTT_TLV_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
77 	[HTT_TLV_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
78 	[HTT_TLV_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
79 	[HTT_TLV_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
80 	[HTT_TLV_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
81 	[HTT_TLV_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
82 	[HTT_TLV_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
83 	[HTT_TLV_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
84 	[HTT_TLV_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
85 	[HTT_TLV_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
86 	[HTT_TLV_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND,
87 	[HTT_TLV_T2H_MSG_TYPE_TX_INSPECT_IND] = HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
88 	[HTT_TLV_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
89 		HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
90 	[HTT_TLV_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] =
91 		HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND,
92 	[HTT_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,
103 };
104 
105 int ath10k_htt_connect(struct ath10k_htt *htt)
106 {
107 	struct ath10k_htc_svc_conn_req conn_req;
108 	struct ath10k_htc_svc_conn_resp conn_resp;
109 	int status;
110 
111 	memset(&conn_req, 0, sizeof(conn_req));
112 	memset(&conn_resp, 0, sizeof(conn_resp));
113 
114 	conn_req.ep_ops.ep_tx_complete = ath10k_htt_htc_tx_complete;
115 	conn_req.ep_ops.ep_rx_complete = ath10k_htt_t2h_msg_handler;
116 
117 	/* connect to control service */
118 	conn_req.service_id = ATH10K_HTC_SVC_ID_HTT_DATA_MSG;
119 
120 	status = ath10k_htc_connect_service(&htt->ar->htc, &conn_req,
121 					    &conn_resp);
122 
123 	if (status)
124 		return status;
125 
126 	htt->eid = conn_resp.eid;
127 
128 	return 0;
129 }
130 
131 int ath10k_htt_init(struct ath10k *ar)
132 {
133 	struct ath10k_htt *htt = &ar->htt;
134 
135 	htt->ar = ar;
136 
137 	/*
138 	 * Prefetch enough data to satisfy target
139 	 * classification engine.
140 	 * This is for LL chips. HL chips will probably
141 	 * transfer all frame in the tx fragment.
142 	 */
143 	htt->prefetch_len =
144 		36 + /* 802.11 + qos + ht */
145 		4 + /* 802.1q */
146 		8 + /* llc snap */
147 		2; /* ip4 dscp or ip6 priority */
148 
149 	switch (ar->htt.op_version) {
150 	case ATH10K_FW_HTT_OP_VERSION_10_1:
151 		ar->htt.t2h_msg_types = htt_10x_t2h_msg_types;
152 		ar->htt.t2h_msg_types_max = HTT_10X_T2H_NUM_MSGS;
153 		break;
154 	case ATH10K_FW_HTT_OP_VERSION_TLV:
155 		ar->htt.t2h_msg_types = htt_tlv_t2h_msg_types;
156 		ar->htt.t2h_msg_types_max = HTT_TLV_T2H_NUM_MSGS;
157 		break;
158 	case ATH10K_FW_HTT_OP_VERSION_MAIN:
159 		ar->htt.t2h_msg_types = htt_main_t2h_msg_types;
160 		ar->htt.t2h_msg_types_max = HTT_MAIN_T2H_NUM_MSGS;
161 		break;
162 	case ATH10K_FW_HTT_OP_VERSION_MAX:
163 	case ATH10K_FW_HTT_OP_VERSION_UNSET:
164 		WARN_ON(1);
165 		return -EINVAL;
166 	}
167 	return 0;
168 }
169 
170 #define HTT_TARGET_VERSION_TIMEOUT_HZ (3*HZ)
171 
172 static int ath10k_htt_verify_version(struct ath10k_htt *htt)
173 {
174 	struct ath10k *ar = htt->ar;
175 
176 	ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt target version %d.%d\n",
177 		   htt->target_version_major, htt->target_version_minor);
178 
179 	if (htt->target_version_major != 2 &&
180 	    htt->target_version_major != 3) {
181 		ath10k_err(ar, "unsupported htt major version %d. supported versions are 2 and 3\n",
182 			   htt->target_version_major);
183 		return -ENOTSUPP;
184 	}
185 
186 	return 0;
187 }
188 
189 int ath10k_htt_setup(struct ath10k_htt *htt)
190 {
191 	struct ath10k *ar = htt->ar;
192 	int status;
193 
194 	init_completion(&htt->target_version_received);
195 
196 	status = ath10k_htt_h2t_ver_req_msg(htt);
197 	if (status)
198 		return status;
199 
200 	status = wait_for_completion_timeout(&htt->target_version_received,
201 					     HTT_TARGET_VERSION_TIMEOUT_HZ);
202 	if (status == 0) {
203 		ath10k_warn(ar, "htt version request timed out\n");
204 		return -ETIMEDOUT;
205 	}
206 
207 	status = ath10k_htt_verify_version(htt);
208 	if (status)
209 		return status;
210 
211 	return ath10k_htt_send_rx_ring_cfg_ll(htt);
212 }
213