Thomas Gleixner | 4505153 | 2019-05-29 16:57:47 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Bluetooth supports for Qualcomm Atheros chips |
| 4 | * |
| 5 | * Copyright (c) 2015 The Linux Foundation. All rights reserved. |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/firmware.h> |
| 9 | |
| 10 | #include <net/bluetooth/bluetooth.h> |
| 11 | #include <net/bluetooth/hci_core.h> |
| 12 | |
| 13 | #include "btqca.h" |
| 14 | |
| 15 | #define VERSION "0.1" |
| 16 | |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 17 | int qca_read_soc_version(struct hci_dev *hdev, struct qca_btsoc_version *ver, |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 18 | enum qca_btsoc_type soc_type) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 19 | { |
| 20 | struct sk_buff *skb; |
| 21 | struct edl_event_hdr *edl; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 22 | char cmd; |
| 23 | int err = 0; |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 24 | u8 event_type = HCI_EV_VENDOR; |
| 25 | u8 rlen = sizeof(*edl) + sizeof(*ver); |
| 26 | u8 rtype = EDL_APP_VER_RES_EVT; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 27 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 28 | bt_dev_dbg(hdev, "QCA Version Request"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 29 | |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 30 | /* Unlike other SoC's sending version command response as payload to |
| 31 | * VSE event. WCN3991 sends version command response as a payload to |
| 32 | * command complete event. |
| 33 | */ |
Rocky Liao | e5d6468 | 2020-03-25 10:26:37 +0800 | [diff] [blame] | 34 | if (soc_type >= QCA_WCN3991) { |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 35 | event_type = 0; |
| 36 | rlen += 1; |
| 37 | rtype = EDL_PATCH_VER_REQ_CMD; |
| 38 | } |
| 39 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 40 | cmd = EDL_PATCH_VER_REQ_CMD; |
| 41 | skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, EDL_PATCH_CMD_LEN, |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 42 | &cmd, event_type, HCI_INIT_TIMEOUT); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 43 | if (IS_ERR(skb)) { |
| 44 | err = PTR_ERR(skb); |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 45 | bt_dev_err(hdev, "Reading QCA version information failed (%d)", |
| 46 | err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 47 | return err; |
| 48 | } |
| 49 | |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 50 | if (skb->len != rlen) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 51 | bt_dev_err(hdev, "QCA Version size mismatch len %d", skb->len); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 52 | err = -EILSEQ; |
| 53 | goto out; |
| 54 | } |
| 55 | |
| 56 | edl = (struct edl_event_hdr *)(skb->data); |
Colin Ian King | 0676cab | 2016-09-06 13:15:49 +0100 | [diff] [blame] | 57 | if (!edl) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 58 | bt_dev_err(hdev, "QCA TLV with no header"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 59 | err = -EILSEQ; |
| 60 | goto out; |
| 61 | } |
| 62 | |
| 63 | if (edl->cresp != EDL_CMD_REQ_RES_EVT || |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 64 | edl->rtype != rtype) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 65 | bt_dev_err(hdev, "QCA Wrong packet received %d %d", edl->cresp, |
| 66 | edl->rtype); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 67 | err = -EIO; |
| 68 | goto out; |
| 69 | } |
| 70 | |
Rocky Liao | e5d6468 | 2020-03-25 10:26:37 +0800 | [diff] [blame] | 71 | if (soc_type >= QCA_WCN3991) |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 72 | memcpy(ver, edl->data + 1, sizeof(*ver)); |
| 73 | else |
| 74 | memcpy(ver, &edl->data, sizeof(*ver)); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 75 | |
Zijun Hu | 4942857 | 2020-05-29 22:46:13 +0800 | [diff] [blame] | 76 | bt_dev_info(hdev, "QCA Product ID :0x%08x", |
| 77 | le32_to_cpu(ver->product_id)); |
| 78 | bt_dev_info(hdev, "QCA SOC Version :0x%08x", |
| 79 | le32_to_cpu(ver->soc_id)); |
| 80 | bt_dev_info(hdev, "QCA ROM Version :0x%08x", |
| 81 | le16_to_cpu(ver->rom_ver)); |
| 82 | bt_dev_info(hdev, "QCA Patch Version:0x%08x", |
| 83 | le16_to_cpu(ver->patch_ver)); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 84 | |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 85 | if (ver->soc_id == 0 || ver->rom_ver == 0) |
Balakrishna Godavarthi | aadebac | 2018-08-03 17:46:28 +0530 | [diff] [blame] | 86 | err = -EILSEQ; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 87 | |
| 88 | out: |
| 89 | kfree_skb(skb); |
Balakrishna Godavarthi | aadebac | 2018-08-03 17:46:28 +0530 | [diff] [blame] | 90 | if (err) |
| 91 | bt_dev_err(hdev, "QCA Failed to get version (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 92 | |
| 93 | return err; |
| 94 | } |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 95 | EXPORT_SYMBOL_GPL(qca_read_soc_version); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 96 | |
Venkata Lakshmi Narayana Gubba | c0187b0 | 2020-12-08 17:25:29 +0530 | [diff] [blame] | 97 | static int qca_read_fw_build_info(struct hci_dev *hdev) |
| 98 | { |
| 99 | struct sk_buff *skb; |
| 100 | struct edl_event_hdr *edl; |
| 101 | char cmd, build_label[QCA_FW_BUILD_VER_LEN]; |
| 102 | int build_lbl_len, err = 0; |
| 103 | |
| 104 | bt_dev_dbg(hdev, "QCA read fw build info"); |
| 105 | |
| 106 | cmd = EDL_GET_BUILD_INFO_CMD; |
| 107 | skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, EDL_PATCH_CMD_LEN, |
| 108 | &cmd, 0, HCI_INIT_TIMEOUT); |
| 109 | if (IS_ERR(skb)) { |
| 110 | err = PTR_ERR(skb); |
| 111 | bt_dev_err(hdev, "Reading QCA fw build info failed (%d)", |
| 112 | err); |
| 113 | return err; |
| 114 | } |
| 115 | |
| 116 | edl = (struct edl_event_hdr *)(skb->data); |
| 117 | if (!edl) { |
| 118 | bt_dev_err(hdev, "QCA read fw build info with no header"); |
| 119 | err = -EILSEQ; |
| 120 | goto out; |
| 121 | } |
| 122 | |
| 123 | if (edl->cresp != EDL_CMD_REQ_RES_EVT || |
| 124 | edl->rtype != EDL_GET_BUILD_INFO_CMD) { |
| 125 | bt_dev_err(hdev, "QCA Wrong packet received %d %d", edl->cresp, |
| 126 | edl->rtype); |
| 127 | err = -EIO; |
| 128 | goto out; |
| 129 | } |
| 130 | |
| 131 | build_lbl_len = edl->data[0]; |
| 132 | if (build_lbl_len <= QCA_FW_BUILD_VER_LEN - 1) { |
| 133 | memcpy(build_label, edl->data + 1, build_lbl_len); |
| 134 | *(build_label + build_lbl_len) = '\0'; |
| 135 | } |
| 136 | |
| 137 | hci_set_fw_info(hdev, "%s", build_label); |
| 138 | |
| 139 | out: |
| 140 | kfree_skb(skb); |
| 141 | return err; |
| 142 | } |
| 143 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 144 | static int qca_send_reset(struct hci_dev *hdev) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 145 | { |
| 146 | struct sk_buff *skb; |
| 147 | int err; |
| 148 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 149 | bt_dev_dbg(hdev, "QCA HCI_RESET"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 150 | |
| 151 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 152 | if (IS_ERR(skb)) { |
| 153 | err = PTR_ERR(skb); |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 154 | bt_dev_err(hdev, "QCA Reset failed (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 155 | return err; |
| 156 | } |
| 157 | |
| 158 | kfree_skb(skb); |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
Harish Bandi | a278088 | 2019-07-12 10:39:40 +0530 | [diff] [blame] | 163 | int qca_send_pre_shutdown_cmd(struct hci_dev *hdev) |
| 164 | { |
| 165 | struct sk_buff *skb; |
| 166 | int err; |
| 167 | |
| 168 | bt_dev_dbg(hdev, "QCA pre shutdown cmd"); |
| 169 | |
Harish Bandi | 010376a | 2019-08-30 17:58:36 +0530 | [diff] [blame] | 170 | skb = __hci_cmd_sync_ev(hdev, QCA_PRE_SHUTDOWN_CMD, 0, |
| 171 | NULL, HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT); |
| 172 | |
Harish Bandi | a278088 | 2019-07-12 10:39:40 +0530 | [diff] [blame] | 173 | if (IS_ERR(skb)) { |
| 174 | err = PTR_ERR(skb); |
| 175 | bt_dev_err(hdev, "QCA preshutdown_cmd failed (%d)", err); |
| 176 | return err; |
| 177 | } |
| 178 | |
| 179 | kfree_skb(skb); |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | EXPORT_SYMBOL_GPL(qca_send_pre_shutdown_cmd); |
| 184 | |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 185 | static void qca_tlv_check_data(struct hci_dev *hdev, |
| 186 | struct qca_fw_config *config, |
Connor Abbott | b43ca51 | 2021-05-07 14:27:33 +0200 | [diff] [blame] | 187 | u8 *fw_data, enum qca_btsoc_type soc_type) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 188 | { |
| 189 | const u8 *data; |
| 190 | u32 type_len; |
| 191 | u16 tag_id, tag_len; |
| 192 | int idx, length; |
| 193 | struct tlv_type_hdr *tlv; |
| 194 | struct tlv_type_patch *tlv_patch; |
| 195 | struct tlv_type_nvm *tlv_nvm; |
Rocky Liao | b638825 | 2020-03-01 18:11:19 +0800 | [diff] [blame] | 196 | uint8_t nvm_baud_rate = config->user_baud_rate; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 197 | |
Balakrishna Godavarthi | e303d12 | 2019-11-06 15:18:31 +0530 | [diff] [blame] | 198 | config->dnld_mode = QCA_SKIP_EVT_NONE; |
| 199 | config->dnld_type = QCA_SKIP_EVT_NONE; |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 200 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 201 | switch (config->type) { |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 202 | case ELF_TYPE_PATCH: |
| 203 | config->dnld_mode = QCA_SKIP_EVT_VSE_CC; |
| 204 | config->dnld_type = QCA_SKIP_EVT_VSE_CC; |
| 205 | |
| 206 | bt_dev_dbg(hdev, "File Class : 0x%x", fw_data[4]); |
| 207 | bt_dev_dbg(hdev, "Data Encoding : 0x%x", fw_data[5]); |
| 208 | bt_dev_dbg(hdev, "File version : 0x%x", fw_data[6]); |
| 209 | break; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 210 | case TLV_TYPE_PATCH: |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 211 | tlv = (struct tlv_type_hdr *)fw_data; |
| 212 | type_len = le32_to_cpu(tlv->type_len); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 213 | tlv_patch = (struct tlv_type_patch *)tlv->data; |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 214 | |
| 215 | /* For Rome version 1.1 to 3.1, all segment commands |
| 216 | * are acked by a vendor specific event (VSE). |
| 217 | * For Rome >= 3.2, the download mode field indicates |
| 218 | * if VSE is skipped by the controller. |
| 219 | * In case VSE is skipped, only the last segment is acked. |
| 220 | */ |
| 221 | config->dnld_mode = tlv_patch->download_mode; |
Balakrishna Godavarthi | 32646db | 2019-05-28 14:43:22 -0700 | [diff] [blame] | 222 | config->dnld_type = config->dnld_mode; |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 223 | |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 224 | BT_DBG("TLV Type\t\t : 0x%x", type_len & 0x000000ff); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 225 | BT_DBG("Total Length : %d bytes", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 226 | le32_to_cpu(tlv_patch->total_size)); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 227 | BT_DBG("Patch Data Length : %d bytes", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 228 | le32_to_cpu(tlv_patch->data_length)); |
| 229 | BT_DBG("Signing Format Version : 0x%x", |
| 230 | tlv_patch->format_version); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 231 | BT_DBG("Signature Algorithm : 0x%x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 232 | tlv_patch->signature); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 233 | BT_DBG("Download mode : 0x%x", |
| 234 | tlv_patch->download_mode); |
| 235 | BT_DBG("Reserved : 0x%x", |
| 236 | tlv_patch->reserved1); |
| 237 | BT_DBG("Product ID : 0x%04x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 238 | le16_to_cpu(tlv_patch->product_id)); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 239 | BT_DBG("Rom Build Version : 0x%04x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 240 | le16_to_cpu(tlv_patch->rom_build)); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 241 | BT_DBG("Patch Version : 0x%04x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 242 | le16_to_cpu(tlv_patch->patch_version)); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 243 | BT_DBG("Reserved : 0x%x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 244 | le16_to_cpu(tlv_patch->reserved2)); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 245 | BT_DBG("Patch Entry Address : 0x%x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 246 | le32_to_cpu(tlv_patch->entry)); |
| 247 | break; |
| 248 | |
| 249 | case TLV_TYPE_NVM: |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 250 | tlv = (struct tlv_type_hdr *)fw_data; |
| 251 | |
| 252 | type_len = le32_to_cpu(tlv->type_len); |
| 253 | length = (type_len >> 8) & 0x00ffffff; |
| 254 | |
| 255 | BT_DBG("TLV Type\t\t : 0x%x", type_len & 0x000000ff); |
| 256 | BT_DBG("Length\t\t : %d bytes", length); |
| 257 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 258 | idx = 0; |
| 259 | data = tlv->data; |
| 260 | while (idx < length) { |
| 261 | tlv_nvm = (struct tlv_type_nvm *)(data + idx); |
| 262 | |
| 263 | tag_id = le16_to_cpu(tlv_nvm->tag_id); |
| 264 | tag_len = le16_to_cpu(tlv_nvm->tag_len); |
| 265 | |
| 266 | /* Update NVM tags as needed */ |
| 267 | switch (tag_id) { |
| 268 | case EDL_TAG_ID_HCI: |
| 269 | /* HCI transport layer parameters |
| 270 | * enabling software inband sleep |
| 271 | * onto controller side. |
| 272 | */ |
| 273 | tlv_nvm->data[0] |= 0x80; |
| 274 | |
| 275 | /* UART Baud Rate */ |
Rocky Liao | e5d6468 | 2020-03-25 10:26:37 +0800 | [diff] [blame] | 276 | if (soc_type >= QCA_WCN3991) |
Rocky Liao | b638825 | 2020-03-01 18:11:19 +0800 | [diff] [blame] | 277 | tlv_nvm->data[1] = nvm_baud_rate; |
| 278 | else |
| 279 | tlv_nvm->data[2] = nvm_baud_rate; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 280 | |
| 281 | break; |
| 282 | |
| 283 | case EDL_TAG_ID_DEEP_SLEEP: |
| 284 | /* Sleep enable mask |
| 285 | * enabling deep sleep feature on controller. |
| 286 | */ |
| 287 | tlv_nvm->data[0] |= 0x01; |
| 288 | |
| 289 | break; |
| 290 | } |
| 291 | |
| 292 | idx += (sizeof(u16) + sizeof(u16) + 8 + tag_len); |
| 293 | } |
| 294 | break; |
| 295 | |
| 296 | default: |
| 297 | BT_ERR("Unknown TLV type %d", config->type); |
| 298 | break; |
| 299 | } |
| 300 | } |
| 301 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 302 | static int qca_tlv_send_segment(struct hci_dev *hdev, int seg_size, |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 303 | const u8 *data, enum qca_tlv_dnld_mode mode, |
| 304 | enum qca_btsoc_type soc_type) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 305 | { |
| 306 | struct sk_buff *skb; |
| 307 | struct edl_event_hdr *edl; |
| 308 | struct tlv_seg_resp *tlv_resp; |
| 309 | u8 cmd[MAX_SIZE_PER_TLV_SEGMENT + 2]; |
| 310 | int err = 0; |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 311 | u8 event_type = HCI_EV_VENDOR; |
| 312 | u8 rlen = (sizeof(*edl) + sizeof(*tlv_resp)); |
| 313 | u8 rtype = EDL_TVL_DNLD_RES_EVT; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 314 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 315 | cmd[0] = EDL_PATCH_TLV_REQ_CMD; |
| 316 | cmd[1] = seg_size; |
| 317 | memcpy(cmd + 2, data, seg_size); |
| 318 | |
Balakrishna Godavarthi | e303d12 | 2019-11-06 15:18:31 +0530 | [diff] [blame] | 319 | if (mode == QCA_SKIP_EVT_VSE_CC || mode == QCA_SKIP_EVT_VSE) |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 320 | return __hci_cmd_send(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2, |
| 321 | cmd); |
| 322 | |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 323 | /* Unlike other SoC's sending version command response as payload to |
| 324 | * VSE event. WCN3991 sends version command response as a payload to |
| 325 | * command complete event. |
| 326 | */ |
Rocky Liao | e5d6468 | 2020-03-25 10:26:37 +0800 | [diff] [blame] | 327 | if (soc_type >= QCA_WCN3991) { |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 328 | event_type = 0; |
| 329 | rlen = sizeof(*edl); |
| 330 | rtype = EDL_PATCH_TLV_REQ_CMD; |
| 331 | } |
| 332 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 333 | skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2, cmd, |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 334 | event_type, HCI_INIT_TIMEOUT); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 335 | if (IS_ERR(skb)) { |
| 336 | err = PTR_ERR(skb); |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 337 | bt_dev_err(hdev, "QCA Failed to send TLV segment (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 338 | return err; |
| 339 | } |
| 340 | |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 341 | if (skb->len != rlen) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 342 | bt_dev_err(hdev, "QCA TLV response size mismatch"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 343 | err = -EILSEQ; |
| 344 | goto out; |
| 345 | } |
| 346 | |
| 347 | edl = (struct edl_event_hdr *)(skb->data); |
Colin Ian King | 0676cab | 2016-09-06 13:15:49 +0100 | [diff] [blame] | 348 | if (!edl) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 349 | bt_dev_err(hdev, "TLV with no header"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 350 | err = -EILSEQ; |
| 351 | goto out; |
| 352 | } |
| 353 | |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 354 | if (edl->cresp != EDL_CMD_REQ_RES_EVT || edl->rtype != rtype) { |
| 355 | bt_dev_err(hdev, "QCA TLV with error stat 0x%x rtype 0x%x", |
| 356 | edl->cresp, edl->rtype); |
| 357 | err = -EIO; |
| 358 | } |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 359 | |
Rocky Liao | e5d6468 | 2020-03-25 10:26:37 +0800 | [diff] [blame] | 360 | if (soc_type >= QCA_WCN3991) |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 361 | goto out; |
| 362 | |
| 363 | tlv_resp = (struct tlv_seg_resp *)(edl->data); |
| 364 | if (tlv_resp->result) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 365 | bt_dev_err(hdev, "QCA TLV with error stat 0x%x rtype 0x%x (0x%x)", |
| 366 | edl->cresp, edl->rtype, tlv_resp->result); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | out: |
| 370 | kfree_skb(skb); |
| 371 | |
| 372 | return err; |
| 373 | } |
| 374 | |
Balakrishna Godavarthi | 32646db | 2019-05-28 14:43:22 -0700 | [diff] [blame] | 375 | static int qca_inject_cmd_complete_event(struct hci_dev *hdev) |
| 376 | { |
| 377 | struct hci_event_hdr *hdr; |
| 378 | struct hci_ev_cmd_complete *evt; |
| 379 | struct sk_buff *skb; |
| 380 | |
| 381 | skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_KERNEL); |
| 382 | if (!skb) |
| 383 | return -ENOMEM; |
| 384 | |
| 385 | hdr = skb_put(skb, sizeof(*hdr)); |
| 386 | hdr->evt = HCI_EV_CMD_COMPLETE; |
| 387 | hdr->plen = sizeof(*evt) + 1; |
| 388 | |
| 389 | evt = skb_put(skb, sizeof(*evt)); |
| 390 | evt->ncmd = 1; |
Matthias Kaehlcke | 2fde6af | 2019-07-08 14:57:42 -0700 | [diff] [blame] | 391 | evt->opcode = cpu_to_le16(QCA_HCI_CC_OPCODE); |
Balakrishna Godavarthi | 32646db | 2019-05-28 14:43:22 -0700 | [diff] [blame] | 392 | |
| 393 | skb_put_u8(skb, QCA_HCI_CC_SUCCESS); |
| 394 | |
| 395 | hci_skb_pkt_type(skb) = HCI_EVENT_PKT; |
| 396 | |
| 397 | return hci_recv_frame(hdev, skb); |
| 398 | } |
| 399 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 400 | static int qca_download_firmware(struct hci_dev *hdev, |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 401 | struct qca_fw_config *config, |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 402 | enum qca_btsoc_type soc_type, |
| 403 | u8 rom_ver) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 404 | { |
| 405 | const struct firmware *fw; |
Connor Abbott | b43ca51 | 2021-05-07 14:27:33 +0200 | [diff] [blame] | 406 | u8 *data; |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 407 | const u8 *segment; |
Connor Abbott | b43ca51 | 2021-05-07 14:27:33 +0200 | [diff] [blame] | 408 | int ret, size, remain, i = 0; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 409 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 410 | bt_dev_info(hdev, "QCA Downloading %s", config->fwname); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 411 | |
| 412 | ret = request_firmware(&fw, config->fwname, &hdev->dev); |
| 413 | if (ret) { |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 414 | /* For WCN6750, if mbn file is not present then check for |
| 415 | * tlv file. |
| 416 | */ |
| 417 | if (soc_type == QCA_WCN6750 && config->type == ELF_TYPE_PATCH) { |
| 418 | bt_dev_dbg(hdev, "QCA Failed to request file: %s (%d)", |
| 419 | config->fwname, ret); |
| 420 | config->type = TLV_TYPE_PATCH; |
| 421 | snprintf(config->fwname, sizeof(config->fwname), |
| 422 | "qca/msbtfw%02x.tlv", rom_ver); |
| 423 | bt_dev_info(hdev, "QCA Downloading %s", config->fwname); |
| 424 | ret = request_firmware(&fw, config->fwname, &hdev->dev); |
| 425 | if (ret) { |
| 426 | bt_dev_err(hdev, "QCA Failed to request file: %s (%d)", |
| 427 | config->fwname, ret); |
| 428 | return ret; |
| 429 | } |
| 430 | } else { |
| 431 | bt_dev_err(hdev, "QCA Failed to request file: %s (%d)", |
| 432 | config->fwname, ret); |
| 433 | return ret; |
| 434 | } |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Connor Abbott | b43ca51 | 2021-05-07 14:27:33 +0200 | [diff] [blame] | 437 | size = fw->size; |
| 438 | data = vmalloc(fw->size); |
| 439 | if (!data) { |
| 440 | bt_dev_err(hdev, "QCA Failed to allocate memory for file: %s", |
| 441 | config->fwname); |
| 442 | release_firmware(fw); |
| 443 | return -ENOMEM; |
| 444 | } |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 445 | |
Connor Abbott | b43ca51 | 2021-05-07 14:27:33 +0200 | [diff] [blame] | 446 | memcpy(data, fw->data, size); |
| 447 | release_firmware(fw); |
| 448 | |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 449 | qca_tlv_check_data(hdev, config, data, soc_type); |
Connor Abbott | b43ca51 | 2021-05-07 14:27:33 +0200 | [diff] [blame] | 450 | |
| 451 | segment = data; |
| 452 | remain = size; |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 453 | while (remain > 0) { |
| 454 | int segsize = min(MAX_SIZE_PER_TLV_SEGMENT, remain); |
| 455 | |
| 456 | bt_dev_dbg(hdev, "Send segment %d, size %d", i++, segsize); |
| 457 | |
| 458 | remain -= segsize; |
| 459 | /* The last segment is always acked regardless download mode */ |
| 460 | if (!remain || segsize < MAX_SIZE_PER_TLV_SEGMENT) |
Balakrishna Godavarthi | e303d12 | 2019-11-06 15:18:31 +0530 | [diff] [blame] | 461 | config->dnld_mode = QCA_SKIP_EVT_NONE; |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 462 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 463 | ret = qca_tlv_send_segment(hdev, segsize, segment, |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 464 | config->dnld_mode, soc_type); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 465 | if (ret) |
Balakrishna Godavarthi | 32646db | 2019-05-28 14:43:22 -0700 | [diff] [blame] | 466 | goto out; |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 467 | |
| 468 | segment += segsize; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Balakrishna Godavarthi | 32646db | 2019-05-28 14:43:22 -0700 | [diff] [blame] | 471 | /* Latest qualcomm chipsets are not sending a command complete event |
| 472 | * for every fw packet sent. They only respond with a vendor specific |
| 473 | * event for the last packet. This optimization in the chip will |
| 474 | * decrease the BT in initialization time. Here we will inject a command |
| 475 | * complete event to avoid a command timeout error message. |
| 476 | */ |
Balakrishna Godavarthi | e303d12 | 2019-11-06 15:18:31 +0530 | [diff] [blame] | 477 | if (config->dnld_type == QCA_SKIP_EVT_VSE_CC || |
| 478 | config->dnld_type == QCA_SKIP_EVT_VSE) |
Claire Chang | c7c5ae2 | 2019-08-06 17:56:29 +0800 | [diff] [blame] | 479 | ret = qca_inject_cmd_complete_event(hdev); |
Balakrishna Godavarthi | 32646db | 2019-05-28 14:43:22 -0700 | [diff] [blame] | 480 | |
| 481 | out: |
Connor Abbott | b43ca51 | 2021-05-07 14:27:33 +0200 | [diff] [blame] | 482 | vfree(data); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 483 | |
| 484 | return ret; |
| 485 | } |
| 486 | |
Balakrishna Godavarthi | 590decc | 2020-06-12 17:50:28 +0530 | [diff] [blame] | 487 | static int qca_disable_soc_logging(struct hci_dev *hdev) |
| 488 | { |
| 489 | struct sk_buff *skb; |
| 490 | u8 cmd[2]; |
| 491 | int err; |
| 492 | |
| 493 | cmd[0] = QCA_DISABLE_LOGGING_SUB_OP; |
| 494 | cmd[1] = 0x00; |
| 495 | skb = __hci_cmd_sync_ev(hdev, QCA_DISABLE_LOGGING, sizeof(cmd), cmd, |
| 496 | HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT); |
| 497 | if (IS_ERR(skb)) { |
| 498 | err = PTR_ERR(skb); |
| 499 | bt_dev_err(hdev, "QCA Failed to disable soc logging(%d)", err); |
| 500 | return err; |
| 501 | } |
| 502 | |
| 503 | kfree_skb(skb); |
| 504 | |
| 505 | return 0; |
| 506 | } |
| 507 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 508 | int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr) |
| 509 | { |
| 510 | struct sk_buff *skb; |
| 511 | u8 cmd[9]; |
| 512 | int err; |
| 513 | |
| 514 | cmd[0] = EDL_NVM_ACCESS_SET_REQ_CMD; |
| 515 | cmd[1] = 0x02; /* TAG ID */ |
| 516 | cmd[2] = sizeof(bdaddr_t); /* size */ |
| 517 | memcpy(cmd + 3, bdaddr, sizeof(bdaddr_t)); |
| 518 | skb = __hci_cmd_sync_ev(hdev, EDL_NVM_ACCESS_OPCODE, sizeof(cmd), cmd, |
Marcel Holtmann | e4cc5a1 | 2018-08-06 17:58:40 +0200 | [diff] [blame] | 519 | HCI_EV_VENDOR, HCI_INIT_TIMEOUT); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 520 | if (IS_ERR(skb)) { |
| 521 | err = PTR_ERR(skb); |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 522 | bt_dev_err(hdev, "QCA Change address command failed (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 523 | return err; |
| 524 | } |
| 525 | |
| 526 | kfree_skb(skb); |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | EXPORT_SYMBOL_GPL(qca_set_bdaddr_rome); |
| 531 | |
Balakrishna Godavarthi | aadebac | 2018-08-03 17:46:28 +0530 | [diff] [blame] | 532 | int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 533 | enum qca_btsoc_type soc_type, struct qca_btsoc_version ver, |
Rocky Liao | 99c905c | 2019-06-06 17:40:30 +0800 | [diff] [blame] | 534 | const char *firmware_name) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 535 | { |
Balakrishna Godavarthi | e303d12 | 2019-11-06 15:18:31 +0530 | [diff] [blame] | 536 | struct qca_fw_config config; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 537 | int err; |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 538 | u8 rom_ver = 0; |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 539 | u32 soc_ver; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 540 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 541 | bt_dev_dbg(hdev, "QCA setup on UART"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 542 | |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 543 | soc_ver = get_soc_ver(ver.soc_id, ver.rom_ver); |
| 544 | |
| 545 | bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver); |
| 546 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 547 | config.user_baud_rate = baudrate; |
| 548 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 549 | /* Download rampatch file */ |
| 550 | config.type = TLV_TYPE_PATCH; |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 551 | if (qca_is_wcn399x(soc_type)) { |
Balakrishna Godavarthi | 4219d46 | 2018-08-03 17:46:31 +0530 | [diff] [blame] | 552 | /* Firmware files to download are based on ROM version. |
| 553 | * ROM version is derived from last two bytes of soc_ver. |
| 554 | */ |
| 555 | rom_ver = ((soc_ver & 0x00000f00) >> 0x04) | |
| 556 | (soc_ver & 0x0000000f); |
| 557 | snprintf(config.fwname, sizeof(config.fwname), |
| 558 | "qca/crbtfw%02x.tlv", rom_ver); |
Rocky Liao | e5d6468 | 2020-03-25 10:26:37 +0800 | [diff] [blame] | 559 | } else if (soc_type == QCA_QCA6390) { |
| 560 | rom_ver = ((soc_ver & 0x00000f00) >> 0x04) | |
| 561 | (soc_ver & 0x0000000f); |
| 562 | snprintf(config.fwname, sizeof(config.fwname), |
| 563 | "qca/htbtfw%02x.tlv", rom_ver); |
Venkata Lakshmi Narayana Gubba | d8f97da | 2021-05-18 22:04:42 +0530 | [diff] [blame] | 564 | } else if (soc_type == QCA_WCN6750) { |
| 565 | rom_ver = ((soc_ver & 0x00000f00) >> 0x04) | |
| 566 | (soc_ver & 0x0000000f); |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 567 | /* Choose mbn file by default.If mbn file is not found |
| 568 | * then choose tlv file |
| 569 | */ |
| 570 | config.type = ELF_TYPE_PATCH; |
Venkata Lakshmi Narayana Gubba | d8f97da | 2021-05-18 22:04:42 +0530 | [diff] [blame] | 571 | snprintf(config.fwname, sizeof(config.fwname), |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 572 | "qca/msbtfw%02x.mbn", rom_ver); |
Balakrishna Godavarthi | 4219d46 | 2018-08-03 17:46:31 +0530 | [diff] [blame] | 573 | } else { |
| 574 | snprintf(config.fwname, sizeof(config.fwname), |
| 575 | "qca/rampatch_%08x.bin", soc_ver); |
| 576 | } |
| 577 | |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 578 | err = qca_download_firmware(hdev, &config, soc_type, rom_ver); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 579 | if (err < 0) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 580 | bt_dev_err(hdev, "QCA Failed to download patch (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 581 | return err; |
| 582 | } |
| 583 | |
Matthias Kaehlcke | 8059ba0 | 2019-07-09 15:44:50 -0700 | [diff] [blame] | 584 | /* Give the controller some time to get ready to receive the NVM */ |
| 585 | msleep(10); |
| 586 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 587 | /* Download NVM configuration */ |
| 588 | config.type = TLV_TYPE_NVM; |
Rocky Liao | 99c905c | 2019-06-06 17:40:30 +0800 | [diff] [blame] | 589 | if (firmware_name) |
| 590 | snprintf(config.fwname, sizeof(config.fwname), |
| 591 | "qca/%s", firmware_name); |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 592 | else if (qca_is_wcn399x(soc_type)) { |
| 593 | if (ver.soc_id == QCA_WCN3991_SOC_ID) { |
| 594 | snprintf(config.fwname, sizeof(config.fwname), |
| 595 | "qca/crnv%02xu.bin", rom_ver); |
| 596 | } else { |
| 597 | snprintf(config.fwname, sizeof(config.fwname), |
| 598 | "qca/crnv%02x.bin", rom_ver); |
| 599 | } |
| 600 | } |
Rocky Liao | e5d6468 | 2020-03-25 10:26:37 +0800 | [diff] [blame] | 601 | else if (soc_type == QCA_QCA6390) |
| 602 | snprintf(config.fwname, sizeof(config.fwname), |
| 603 | "qca/htnv%02x.bin", rom_ver); |
Venkata Lakshmi Narayana Gubba | d8f97da | 2021-05-18 22:04:42 +0530 | [diff] [blame] | 604 | else if (soc_type == QCA_WCN6750) |
| 605 | snprintf(config.fwname, sizeof(config.fwname), |
| 606 | "qca/msnv%02x.bin", rom_ver); |
Balakrishna Godavarthi | 4219d46 | 2018-08-03 17:46:31 +0530 | [diff] [blame] | 607 | else |
| 608 | snprintf(config.fwname, sizeof(config.fwname), |
| 609 | "qca/nvm_%08x.bin", soc_ver); |
| 610 | |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame^] | 611 | err = qca_download_firmware(hdev, &config, soc_type, rom_ver); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 612 | if (err < 0) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 613 | bt_dev_err(hdev, "QCA Failed to download NVM (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 614 | return err; |
| 615 | } |
| 616 | |
Balakrishna Godavarthi | 590decc | 2020-06-12 17:50:28 +0530 | [diff] [blame] | 617 | if (soc_type >= QCA_WCN3991) { |
| 618 | err = qca_disable_soc_logging(hdev); |
| 619 | if (err < 0) |
| 620 | return err; |
| 621 | } |
| 622 | |
Venkata Lakshmi Narayana Gubba | d8f97da | 2021-05-18 22:04:42 +0530 | [diff] [blame] | 623 | /* WCN399x and WCN6750 supports the Microsoft vendor extension with 0xFD70 as the |
Miao-chen Chou | eaf19b0 | 2020-12-17 14:53:17 -0800 | [diff] [blame] | 624 | * VsMsftOpCode. |
| 625 | */ |
| 626 | switch (soc_type) { |
| 627 | case QCA_WCN3990: |
| 628 | case QCA_WCN3991: |
| 629 | case QCA_WCN3998: |
Venkata Lakshmi Narayana Gubba | d8f97da | 2021-05-18 22:04:42 +0530 | [diff] [blame] | 630 | case QCA_WCN6750: |
Miao-chen Chou | eaf19b0 | 2020-12-17 14:53:17 -0800 | [diff] [blame] | 631 | hci_set_msft_opcode(hdev, 0xFD70); |
| 632 | break; |
| 633 | default: |
| 634 | break; |
| 635 | } |
| 636 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 637 | /* Perform HCI reset */ |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 638 | err = qca_send_reset(hdev); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 639 | if (err < 0) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 640 | bt_dev_err(hdev, "QCA Failed to run HCI_RESET (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 641 | return err; |
| 642 | } |
| 643 | |
Venkata Lakshmi Narayana Gubba | d8f97da | 2021-05-18 22:04:42 +0530 | [diff] [blame] | 644 | if (soc_type == QCA_WCN3991 || soc_type == QCA_WCN6750) { |
Venkata Lakshmi Narayana Gubba | c0187b0 | 2020-12-08 17:25:29 +0530 | [diff] [blame] | 645 | /* get fw build info */ |
| 646 | err = qca_read_fw_build_info(hdev); |
| 647 | if (err < 0) |
| 648 | return err; |
| 649 | } |
| 650 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 651 | bt_dev_info(hdev, "QCA setup on UART is completed"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 652 | |
| 653 | return 0; |
| 654 | } |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 655 | EXPORT_SYMBOL_GPL(qca_uart_setup); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 656 | |
Balakrishna Godavarthi | 5c0a1001 | 2019-01-16 18:01:15 +0530 | [diff] [blame] | 657 | int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr) |
| 658 | { |
| 659 | struct sk_buff *skb; |
| 660 | int err; |
| 661 | |
| 662 | skb = __hci_cmd_sync_ev(hdev, EDL_WRITE_BD_ADDR_OPCODE, 6, bdaddr, |
| 663 | HCI_EV_VENDOR, HCI_INIT_TIMEOUT); |
| 664 | if (IS_ERR(skb)) { |
| 665 | err = PTR_ERR(skb); |
| 666 | bt_dev_err(hdev, "QCA Change address cmd failed (%d)", err); |
| 667 | return err; |
| 668 | } |
| 669 | |
| 670 | kfree_skb(skb); |
| 671 | |
| 672 | return 0; |
| 673 | } |
| 674 | EXPORT_SYMBOL_GPL(qca_set_bdaddr); |
| 675 | |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 676 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 677 | MODULE_AUTHOR("Ben Young Tae Kim <ytkim@qca.qualcomm.com>"); |
| 678 | MODULE_DESCRIPTION("Bluetooth support for Qualcomm Atheros family ver " VERSION); |
| 679 | MODULE_VERSION(VERSION); |
| 680 | MODULE_LICENSE("GPL"); |