From: "Cheng Jiang (IOE)" <quic_chejiang@quicinc.com>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Marcel Holtmann <marcel@holtmann.org>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
"Balakrishna Godavarthi" <quic_bgodavar@quicinc.com>,
Rocky Liao <quic_rjliao@quicinc.com>,
<linux-bluetooth@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>,
<quic_jiaymao@quicinc.com>, <quic_shuaz@quicinc.com>,
<quic_zijuhu@quicinc.com>, <quic_mohamull@quicinc.com>
Subject: Re: [PATCH v4 2/4] Bluetooth: qca: Add support in firmware-name to load board specific nvm
Date: Wed, 11 Dec 2024 13:53:18 +0800 [thread overview]
Message-ID: <7eb71706-1393-4e49-996e-1cf9d8c98d16@quicinc.com> (raw)
In-Reply-To: <wxb6oo3f7cri27eq3fnqttbl74lkn3rjo5o5rfttbwz7k5v2ug@w4hlrtig2nza>
Hi Dmitry,
On 12/10/2024 11:28 PM, Dmitry Baryshkov wrote:
> On Tue, Dec 10, 2024 at 11:16:34PM +0800, Cheng Jiang wrote:
>> Different connectivity boards may be attached to the same platform. For
>> example, QCA6698-based boards can support either a two-antenna or
>> three-antenna solution, both of which work on the sa8775p-ride platform.
>> Due to differences in connectivity boards and variations in RF
>> performance from different foundries, different NVM configurations are
>> used based on the board ID.
>>
>> Therefore, in the firmware-name property, if the NVM file has an
>> extension, the NVM file will be used. Otherwise, the system will first
>> try the .bNN (board ID) file, and if that fails, it will fall back to
>> the .bin file.
>>
>> Possible configurations:
>> firmware-name = "QCA6698/hpnv21";
>> firmware-name = "QCA6698/hpnv21.bin";
>>
>> Signed-off-by: Cheng Jiang <quic_chejiang@quicinc.com>
>> ---
>> drivers/bluetooth/btqca.c | 67 +++++++++++++++++++++++++++++++++++++--
>> 1 file changed, 65 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c
>> index dfbbac922..deb2b1753 100644
>> --- a/drivers/bluetooth/btqca.c
>> +++ b/drivers/bluetooth/btqca.c
>> @@ -272,6 +272,27 @@ int qca_send_pre_shutdown_cmd(struct hci_dev *hdev)
>> }
>> EXPORT_SYMBOL_GPL(qca_send_pre_shutdown_cmd);
>>
>> +static bool qca_get_alt_nvm_path(char *path, size_t max_size)
>> +{
>> + char fwname[64];
>> + const char *suffix;
>> +
>> + suffix = strrchr(path, '.');
>> +
>> + /* nvm file name has a suffix, replace with .bin */
>> + if (suffix && suffix != path && *(suffix + 1) != '\0' && strchr(suffix, '/') == NULL) {
>> + strscpy(fwname, path, suffix - path + 1);
>> + snprintf(fwname + (suffix - path), sizeof(fwname) - (suffix - path), ".bin");
>> + /* If nvm file is already the default one, return false to skip the retry. */
>> + if (strcmp(fwname, path) == 0)
>> + return false;
>> +
>> + snprintf(path, max_size, "%s", fwname);
>> + return true;
>> + }
>> + return false;
>> +}
>> +
>> static int qca_tlv_check_data(struct hci_dev *hdev,
>> struct qca_fw_config *config,
>> u8 *fw_data, size_t fw_size,
>> @@ -564,6 +585,19 @@ static int qca_download_firmware(struct hci_dev *hdev,
>> config->fwname, ret);
>> return ret;
>> }
>> + }
>> + /* For nvm, if desired nvm file is not present and it's not the
>> + * default nvm file(ends with .bin), try to load the default nvm.
>> + */
>> + else if (config->type == TLV_TYPE_NVM &&
>> + qca_get_alt_nvm_path(config->fwname, sizeof(config->fwname))) {
>> + bt_dev_info(hdev, "QCA Downloading %s", config->fwname);
>> + ret = request_firmware(&fw, config->fwname, &hdev->dev);
>> + if (ret) {
>> + bt_dev_err(hdev, "QCA Failed to request file: %s (%d)",
>> + config->fwname, ret);
>> + return ret;
>> + }
>> } else {
>> bt_dev_err(hdev, "QCA Failed to request file: %s (%d)",
>> config->fwname, ret);
>> @@ -730,6 +764,26 @@ static inline void qca_get_nvm_name_generic(struct qca_fw_config *cfg,
>> "qca/%snv%02x.b%02x", stem, rom_ver, bid);
>> }
>>
>> +static void qca_get_nvm_name_by_board(char *fwname, size_t max_size,
>> + const char *firmware_name, struct qca_btsoc_version ver,
>> + enum qca_btsoc_type soc_type, u16 bid)
>> +{
>> + const char *variant;
>> +
>> + /* Set the variant to empty by default */
>> + variant = "";
>> + /* hsp gf chip */
>> + if (soc_type == QCA_WCN6855) {
>> + if ((le32_to_cpu(ver.soc_id) & QCA_HSP_GF_SOC_MASK) == QCA_HSP_GF_SOC_ID)
>> + variant = "g";
>> + }
>> +
>> + if (bid == 0x0 || bid == 0xffff)
>> + snprintf(fwname, max_size, "qca/%s%s.bin", firmware_name, variant);
>> + else
>> + snprintf(fwname, max_size, "qca/%s%s.b%02x", firmware_name, variant, bid);
>
> So, we have qca_generate_hsp_nvm_name(), qca_get_nvm_name_generic(), now
> you are adding a third one. Can we please have a single function that
> handles that?
>
Ack, will use a single function to handle this.
>> +}
>> +
>> int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
>> enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
>> const char *firmware_name)
>> @@ -739,6 +793,7 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
>> u8 rom_ver = 0;
>> u32 soc_ver;
>> u16 boardid = 0;
>> + const char *suffix;
>>
>> bt_dev_dbg(hdev, "QCA setup on UART");
>>
>> @@ -816,8 +871,16 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
>> /* Download NVM configuration */
>> config.type = TLV_TYPE_NVM;
>> if (firmware_name) {
>> - snprintf(config.fwname, sizeof(config.fwname),
>> - "qca/%s", firmware_name);
>> + /* The firmware name has suffix, use it directly */
>> + suffix = strrchr(firmware_name, '.');
>> + if (suffix && suffix != firmware_name &&
>> + *(suffix + 1) != '\0' && strchr(suffix, '/') == NULL) {
>
> The have-suffix code should be extracted to a helper function. You have
> two copies of it.
>
Ack.
>> + snprintf(config.fwname, sizeof(config.fwname), "qca/%s", firmware_name);
>> + } else {
>> + qca_read_fw_board_id(hdev, &boardid);
>> + qca_get_nvm_name_by_board(config.fwname, sizeof(config.fwname),
>> + firmware_name, ver, soc_type, boardid);
>> + }
>> } else {
>> switch (soc_type) {
>> case QCA_WCN3990:
>> --
>> 2.25.1
>>
>
next prev parent reply other threads:[~2024-12-11 5:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 15:16 [PATCH v4 0/3] Expand firmware-name property to load specific Cheng Jiang
2024-12-10 15:16 ` [PATCH v4 1/4] dt-bindings: net: bluetooth: qca: Expand firmware-name property Cheng Jiang
2024-12-11 8:53 ` Krzysztof Kozlowski
2024-12-11 9:39 ` Cheng Jiang (IOE)
2024-12-11 9:48 ` Krzysztof Kozlowski
2024-12-11 10:16 ` Cheng Jiang (IOE)
2024-12-11 19:28 ` Dmitry Baryshkov
2024-12-12 5:56 ` Cheng Jiang (IOE)
2024-12-12 7:16 ` Krzysztof Kozlowski
2024-12-12 10:16 ` Cheng Jiang (IOE)
2024-12-10 15:16 ` [PATCH v4 2/4] Bluetooth: qca: Add support in firmware-name to load board specific nvm Cheng Jiang
2024-12-10 15:28 ` Dmitry Baryshkov
2024-12-11 5:53 ` Cheng Jiang (IOE) [this message]
2024-12-10 15:16 ` [PATCH v4 3/4] Bluetooth: qca: Expand firmware-name to load specific rampatch Cheng Jiang
2024-12-10 15:16 ` [PATCH v4 4/4] arm64: dts: qcom: sa8775p-ride: Add firmware-name in BT node Cheng Jiang
2024-12-11 8:53 ` [PATCH v4 0/3] Expand firmware-name property to load specific Krzysztof Kozlowski
2024-12-11 9:37 ` Cheng Jiang (IOE)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7eb71706-1393-4e49-996e-1cf9d8c98d16@quicinc.com \
--to=quic_chejiang@quicinc.com \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=quic_bgodavar@quicinc.com \
--cc=quic_jiaymao@quicinc.com \
--cc=quic_mohamull@quicinc.com \
--cc=quic_rjliao@quicinc.com \
--cc=quic_shuaz@quicinc.com \
--cc=quic_zijuhu@quicinc.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®