Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10129865rwr; Fri, 12 May 2023 04:22:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7tE/V3NgRqG4RBQSMWf6+t/czmKO7nwUx07uELbxWJ/8nLvn4KEO4QUiR5PkTCgU+U2v0g X-Received: by 2002:a17:90b:390e:b0:24d:fcd2:bdad with SMTP id ob14-20020a17090b390e00b0024dfcd2bdadmr23283031pjb.35.1683890542686; Fri, 12 May 2023 04:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683890542; cv=none; d=google.com; s=arc-20160816; b=xbCrcv0argQWkHWrwrn1FJ+7EADPM9Abtsg4OswhQ7KaHlFvjJDiNjxF01Xckaci1Z KoH0pcszdbX0JTvjlOyjm9L4EsMM3w8n+L+INp5UpDbIUXsyn7bcc4VggO5PcctMMwRU WklfnDeW1D9AVvOBwuf9LAx2fsOlaUbTO+f26lNWtIN+AKw+609Z5innnjHwKQhH5ILJ ivd2GalWXOVyN5g9ZcxoJP1h/K2qQGLjn8ZGS0oRx4r+2uF11rHs197wQ3oQKX4DP8yw CTJhqY5dSMaSnqYUzs6MHSUrLrgw7KO2SlSbpmfFYBJHXzdzRm4B3QN3UNiILHsy/H3v VsCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:to:from:subject:cc :message-id:date:content-transfer-encoding:mime-version :dkim-signature; bh=ubvb9p88+qXd6VOrp401GthxX4aOEOtnz4kgi/kUzHM=; b=BFDlAiqEbXRdD97wfOSxkTdVql8wf+OOERC0ZDrAuuGm7jQB4wVfLwbvQ/zfKjx+CD HnYFXOCS1KUiWXZrHb90xC2MxPMKCdbqythyjRbwmT3M5T+g3bjmrYRO7F/uXdp662HB 9pyWqccnu2WgZ9tIyDrxVmPOv7UuGuXpZLWcNxtoYJU/420ad0ViOmY/+VoH8NqZ1Neu Wt4LxwU6ZjU4rEXK+jB7f6oxnoGRqaNCXMk8CCv3OCV94tbKrQDpnRJNNp/Vg/3erf0P ig0TciPVQC7fiwCtIF5cneeNkdxSTMgPk6xWievERocgQGVRmjUeP4LDA3NwArrCGWbH R6Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fairphone.com header.s=fair header.b=0DxQHN51; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fairphone.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q2-20020a63bc02000000b0052c4002eadasi8995022pge.630.2023.05.12.04.22.08; Fri, 12 May 2023 04:22:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@fairphone.com header.s=fair header.b=0DxQHN51; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fairphone.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240869AbjELLO0 (ORCPT + 99 others); Fri, 12 May 2023 07:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241036AbjELLOY (ORCPT ); Fri, 12 May 2023 07:14:24 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9220311B6C for ; Fri, 12 May 2023 04:14:21 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-50bc4ba28cbso17337986a12.0 for ; Fri, 12 May 2023 04:14:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fairphone.com; s=fair; t=1683890060; x=1686482060; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ubvb9p88+qXd6VOrp401GthxX4aOEOtnz4kgi/kUzHM=; b=0DxQHN51nTkhDMihJi78b3ohzJMoM2rXRuga1g6tw0P6qNiVS4sVaDavvwMIT5/iJ0 Gyd4AtWdLZ5WJxMYmdxWl1sgVyeT/fA1AVb4pnZesPs4GAjkzKCCdzj13wDF3ZGCLXgP /cwdnqPJKz2mPmZYNAhyABgUXcoDYYThXQVYyJUox8JCl4sX4QDb29r863JZZN2x5CeK RKkhhEXl7XohTbmdb9Cms9xaWPK4UYp4HK4gfhE8VTjVlxxug2tdQhjIM10LhFv5XJkL XI+ANWqOR1T7qPIYvtmfC7JKuEzDCWvGXQ5LA0LBl7zQmc0N7GhgzmlhRA3//yPTDNA3 znnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683890060; x=1686482060; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ubvb9p88+qXd6VOrp401GthxX4aOEOtnz4kgi/kUzHM=; b=XuYdF0Ei+MoWdx5SiDLEBSn1f5fxZbgqQ/naW31Q8Q98oBoC1mzRIofaIZUyh/kfpK aiiXZUVeEJclMh3OvGUiStdsgVsFj7DJOVuYwsyCil3UWp9OkJqMUd2LAfMkYe7PXIEr g5QL/pJoG0JWHHKN+jmX+dXIottHt9BZRV+hlUZi0oaUl2xA9YsVqJh5p4hKTd7phpDr uEK0pFTjYB2V2AGvHHXzzgFBarO6P8aYRJxHHjOgmSkSlfayjXoStsNfUM9DuqT116rN ITct9lH4dSH29BCIXBa/3QErv6jJ4NdT3RT6c2B9M0hR5GAQStRvpAGOanYfZDW5Qxrl r7xg== X-Gm-Message-State: AC+VfDwdNlUPiGPseAyY6EBhftGQY79ijsnDRd7iraePyrGEFLGWuWa8 mM+qjy/jVl1YR3GgPWuizYVWOg== X-Received: by 2002:a17:907:a0e:b0:94e:e6b9:fef2 with SMTP id bb14-20020a1709070a0e00b0094ee6b9fef2mr20395577ejc.67.1683890060020; Fri, 12 May 2023 04:14:20 -0700 (PDT) Received: from localhost (144-178-202-138.static.ef-service.nl. [144.178.202.138]) by smtp.gmail.com with ESMTPSA id l21-20020a1709062a9500b00969f44bbef3sm4734097eje.11.2023.05.12.04.14.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 May 2023 04:14:19 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 12 May 2023 13:14:18 +0200 Message-Id: Cc: "David S. Miller" , "Eric Dumazet" , "Jakub Kicinski" , "Paolo Abeni" , "Rob Herring" , "Krzysztof Kozlowski" , "Balakrishna Godavarthi" , "Rocky Liao" , "Marcel Holtmann" , "Johan Hedberg" , "Luiz Augusto von Dentz" , "Andy Gross" , "Bjorn Andersson" , "Konrad Dybcio" , <~postmarketos/upstreaming@lists.sr.ht>, , , , , , Subject: Re: [PATCH RFC 2/4] Bluetooth: btqca: Add WCN3988 support From: "Luca Weiss" To: "Simon Horman" X-Mailer: aerc 0.15.1 References: <20230421-fp4-bluetooth-v1-0-0430e3a7e0a2@fairphone.com> <20230421-fp4-bluetooth-v1-2-0430e3a7e0a2@fairphone.com> In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Simon, On Mon May 1, 2023 at 3:11 PM CEST, Simon Horman wrote: > On Fri, Apr 21, 2023 at 04:11:39PM +0200, Luca Weiss wrote: > > Add support for the Bluetooth chip codenamed APACHE which is part of > > WCN3988. > >=20 > > The firmware for this chip has a slightly different naming scheme > > compared to most others. For ROM Version 0x0200 we need to use > > apbtfw10.tlv + apnv10.bin and for ROM version 0x201 apbtfw11.tlv + > > apnv11.bin > >=20 > > Signed-off-by: Luca Weiss > > --- > > drivers/bluetooth/btqca.c | 13 +++++++++++-- > > drivers/bluetooth/btqca.h | 12 ++++++++++-- > > drivers/bluetooth/hci_qca.c | 12 ++++++++++++ > > 3 files changed, 33 insertions(+), 4 deletions(-) > >=20 > > diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c > > index fd0941fe8608..3ee1ef88a640 100644 > > --- a/drivers/bluetooth/btqca.c > > +++ b/drivers/bluetooth/btqca.c > > @@ -594,14 +594,20 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t = baudrate, > > /* Firmware files to download are based on ROM version. > > * ROM version is derived from last two bytes of soc_ver. > > */ > > - rom_ver =3D ((soc_ver & 0x00000f00) >> 0x04) | (soc_ver & 0x0000000f)= ; > > + if (soc_type =3D=3D QCA_WCN3988) > > + rom_ver =3D ((soc_ver & 0x00000f00) >> 0x05) | (soc_ver & 0x0000000f= ); > > + else > > + rom_ver =3D ((soc_ver & 0x00000f00) >> 0x04) | (soc_ver & 0x0000000f= ); > > Hi Luca, > > perhaps it's just me. But I was wondering if this can be improved on a li= ttle. > > * Move the common portion outside of the conditional > * And also, I think it's normal to use decimal for shift values. > > e.g. > unsigned shift; > ... > > shift =3D soc_type =3D=3D QCA_WCN3988 ? 5 : 4; > rom_ver =3D ((soc_ver & 0x00000f00) >> shift) | (soc_ver & 0x0000000f); > > Using some helpers such as GENMASK and FIELD_PREP might also be nice. While I'm not opposed to the idea, I'm not sure it's worth making beautiful macros for this since - to my eyes - how the mapping of soc_ver to firmware name works is rather obscure since the sources from Qualcomm just have a static lookup table of soc_ver to firmware name so doing this dynamically like here is different. And I haven't looked at other chips that are covered there to see if there's a pattern to this, for the most part it seems the original formula works for most chips and the one I added works for WCN3988 (and the other "APACHE" chips, whatever they are). If a third way is added then I would say for sure this line should be made nicer but for now I think it's easier to keep this as I sent it because we don't know what the future will hold. > > > =20 > > if (soc_type =3D=3D QCA_WCN6750) > > qca_send_patch_config_cmd(hdev); > > =20 > > /* Download rampatch file */ > > config.type =3D TLV_TYPE_PATCH; > > - if (qca_is_wcn399x(soc_type)) { > > + if (soc_type =3D=3D QCA_WCN3988) { > > + snprintf(config.fwname, sizeof(config.fwname), > > + "qca/apbtfw%02x.tlv", rom_ver); > > + } else if (qca_is_wcn399x(soc_type)) { > > snprintf(config.fwname, sizeof(config.fwname), > > "qca/crbtfw%02x.tlv", rom_ver); > > } else if (soc_type =3D=3D QCA_QCA6390) { > > @@ -636,6 +642,9 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t ba= udrate, > > if (firmware_name) > > snprintf(config.fwname, sizeof(config.fwname), > > "qca/%s", firmware_name); > > + else if (soc_type =3D=3D QCA_WCN3988) > > + snprintf(config.fwname, sizeof(config.fwname), > > + "qca/apnv%02x.bin", rom_ver); > > else if (qca_is_wcn399x(soc_type)) { > > if (ver.soc_id =3D=3D QCA_WCN3991_SOC_ID) { > > Not strictly related to this patch, but while reviewing this I noticed th= at > ver.soc_id is __le32 but QCA_WCN3991_SOC_ID is in host byteorder. > > Perhaps a cpu_to_le32() or le32_to_cpu() call is in order here? Good catch, as you've seen I sent a patch separately to fix that. :) Regards Luca > > > snprintf(config.fwname, sizeof(config.fwname), > > ...