1 /* 2 * Copyright (c) 2005-2011 Atheros Communications Inc. 3 * Copyright (c) 2011-2017 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_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N_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 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, 142 }; 143 144 int ath10k_htt_connect(struct ath10k_htt *htt) 145 { 146 struct ath10k_htc_svc_conn_req conn_req; 147 struct ath10k_htc_svc_conn_resp conn_resp; 148 int status; 149 150 memset(&conn_req, 0, sizeof(conn_req)); 151 memset(&conn_resp, 0, sizeof(conn_resp)); 152 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; 155 156 /* connect to control service */ 157 conn_req.service_id = ATH10K_HTC_SVC_ID_HTT_DATA_MSG; 158 159 status = ath10k_htc_connect_service(&htt->ar->htc, &conn_req, 160 &conn_resp); 161 162 if (status) 163 return status; 164 165 htt->eid = conn_resp.eid; 166 167 return 0; 168 } 169 170 int ath10k_htt_init(struct ath10k *ar) 171 { 172 struct ath10k_htt *htt = &ar->htt; 173 174 htt->ar = ar; 175 176 /* 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. 181 */ 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 */ 187 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; 209 } 210 ath10k_htt_set_tx_ops(htt); 211 ath10k_htt_set_rx_ops(htt); 212 213 return 0; 214 } 215 216 #define HTT_TARGET_VERSION_TIMEOUT_HZ (3 * HZ) 217 218 static int ath10k_htt_verify_version(struct ath10k_htt *htt) 219 { 220 struct ath10k *ar = htt->ar; 221 222 ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt target version %d.%d\n", 223 htt->target_version_major, htt->target_version_minor); 224 225 if (htt->target_version_major != 2 && 226 htt->target_version_major != 3) { 227 ath10k_err(ar, "unsupported htt major version %d. supported versions are 2 and 3\n", 228 htt->target_version_major); 229 return -ENOTSUPP; 230 } 231 232 return 0; 233 } 234 235 int ath10k_htt_setup(struct ath10k_htt *htt) 236 { 237 struct ath10k *ar = htt->ar; 238 int status; 239 240 init_completion(&htt->target_version_received); 241 242 status = ath10k_htt_h2t_ver_req_msg(htt); 243 if (status) 244 return status; 245 246 status = wait_for_completion_timeout(&htt->target_version_received, 247 HTT_TARGET_VERSION_TIMEOUT_HZ); 248 if (status == 0) { 249 ath10k_warn(ar, "htt version request timed out\n"); 250 return -ETIMEDOUT; 251 } 252 253 status = ath10k_htt_verify_version(htt); 254 if (status) { 255 ath10k_warn(ar, "failed to verify htt version: %d\n", 256 status); 257 return status; 258 } 259 260 status = htt->tx_ops->htt_send_frag_desc_bank_cfg(htt); 261 if (status) 262 return status; 263 264 status = htt->tx_ops->htt_send_rx_ring_cfg(htt); 265 if (status) { 266 ath10k_warn(ar, "failed to setup rx ring: %d\n", 267 status); 268 return status; 269 } 270 271 status = ath10k_htt_h2t_aggr_cfg_msg(htt, 272 htt->max_num_ampdu, 273 htt->max_num_amsdu); 274 if (status) { 275 ath10k_warn(ar, "failed to setup amsdu/ampdu limit: %d\n", 276 status); 277 return status; 278 } 279 280 return 0; 281 } 282