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