diff mbox series

[3/4] Bluetooth: btintel: Add helper functions to parse firmware name

Message ID 20200611114526.13594-4-kiran.k@intel.com (mailing list archive)
State New, archived
Headers show
Series Add support for new generation Intel controllers | expand

Commit Message

K, Kiran June 11, 2020, 11:45 a.m. UTC
From: Raghuram Hegde <raghuram.hegde@intel.com>

Define helper functions to construct firmware file name as the format of
legacy differs from new generation Intel controllers

Signed-off-by: Raghuram Hegde <raghuram.hegde@intel.com>
Signed-off-by: Chethan T N <chethan.tumkur.narayan@intel.com>
Signed-off-by: Kiran K <kiran.k@intel.com>
Signed-off-by: Amit K Bag <amit.k.bag@intel.com>
---
 drivers/bluetooth/btintel.c | 75 +++++++++++++++++++++++++++++++++++++
 drivers/bluetooth/btintel.h |  6 +++
 2 files changed, 81 insertions(+)

Comments

kernel test robot June 11, 2020, 8:25 p.m. UTC | #1
Hi Kiran,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on next-20200611]
[cannot apply to bluetooth/master v5.7]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Kiran-K/Add-support-for-new-generation-Intel-controllers/20200611-194619
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: powerpc-randconfig-s031-20200611 (attached as .config)
compiler: powerpc64le-linux-gcc (GCC) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.1-250-g42323db3-dirty
        # save the attached .config to linux build tree
        make W=1 C=1 ARCH=powerpc CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)

>> drivers/bluetooth/btintel.c:418:26: sparse: sparse: cast to restricted __le16
   drivers/bluetooth/btintel.c:427:26: sparse: sparse: cast to restricted __le16
   drivers/bluetooth/btintel.c:428:26: sparse: sparse: cast to restricted __le16
   drivers/bluetooth/btintel.c:429:26: sparse: sparse: cast to restricted __le16

vim +418 drivers/bluetooth/btintel.c

   384	
   385	bool btintel_get_fw_name(struct intel_version *ver,
   386				 struct intel_boot_params *params,
   387				 char *fw_name, size_t len,
   388				 const char *suffix)
   389	{
   390		/* This is for legacy HCI_Intel_Read_Version command.
   391		 *
   392		 * With this Intel bootloader only the hardware variant and device
   393		 * revision information are used to select the right firmware for SfP
   394		 * and WsP.
   395		 *
   396		 * The firmware filename is ibt-<hw_variant>-<dev_revid>.sfi.
   397		 *
   398		 * Currently the supported hardware variants are:
   399		 *   11 (0x0b) for iBT3.0 (LnP/SfP)
   400		 *   12 (0x0c) for iBT3.5 (WsP)
   401		 *
   402		 * For ThP/JfP and for future SKU's, the FW name varies based on HW
   403		 * variant, HW revision and FW revision, as these are dependent on CNVi
   404		 * and RF Combination.
   405		 *
   406		 *   17 (0x11) for iBT3.5 (JfP)
   407		 *   18 (0x12) for iBT3.5 (ThP)
   408		 *
   409		 * The firmware file name for these will be
   410		 * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi.
   411		 *
   412		 */
   413	
   414		switch (ver->hw_variant) {
   415		case 0x0b:	/* SfP */
   416		case 0x0c:	/* WsP */
   417			snprintf(fw_name, len, "intel/ibt-%u-%u.%s",
 > 418				 le16_to_cpu(ver->hw_variant),
   419				 le16_to_cpu(params->dev_revid),
   420				 suffix);
   421			break;
   422		case 0x11:	/* JfP */
   423		case 0x12:	/* ThP */
   424		case 0x13:	/* HrP */
   425		case 0x14:	/* CcP */
   426			snprintf(fw_name, len, "intel/ibt-%u-%u-%u.%s",
   427				 le16_to_cpu(ver->hw_variant),
   428				 le16_to_cpu(ver->hw_revision),
   429				 le16_to_cpu(ver->fw_revision),
   430				 suffix);
   431			break;
   432		default:
   433			return false;
   434		}
   435		return true;
   436	}
   437	EXPORT_SYMBOL_GPL(btintel_get_fw_name);
   438	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot June 12, 2020, 9:42 a.m. UTC | #2
Hi Kiran,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on next-20200611]
[cannot apply to bluetooth/master v5.7]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Kiran-K/Add-support-for-new-generation-Intel-controllers/20200611-194619
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: nds32-randconfig-r014-20200612 (attached as .config)
compiler: nds32le-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=nds32 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>, old ones prefixed by <<):

In file included from ./arch/nds32/include/generated/asm/bug.h:1,
from include/linux/bug.h:5,
from include/linux/thread_info.h:12,
from include/asm-generic/preempt.h:5,
from ./arch/nds32/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/seqlock.h:36,
from include/linux/time.h:6,
from include/linux/stat.h:19,
from include/linux/module.h:13,
from drivers/bluetooth/btintel.c:9:
include/linux/dma-mapping.h: In function 'dma_map_resource':
arch/nds32/include/asm/memory.h:82:32: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
82 | #define pfn_valid(pfn)  ((pfn) >= PHYS_PFN_OFFSET && (pfn) < (PHYS_PFN_OFFSET + max_mapnr))
|                                ^~
include/asm-generic/bug.h:139:27: note: in definition of macro 'WARN_ON_ONCE'
139 |  int __ret_warn_once = !!(condition);            |                           ^~~~~~~~~
include/linux/dma-mapping.h:352:19: note: in expansion of macro 'pfn_valid'
352 |  if (WARN_ON_ONCE(pfn_valid(PHYS_PFN(phys_addr))))
|                   ^~~~~~~~~
drivers/bluetooth/btintel.c: At top level:
drivers/bluetooth/btintel.c:229:6: warning: no previous prototype for 'btintel_boot_info' [-Wmissing-prototypes]
229 | void btintel_boot_info(struct hci_dev *hdev,
|      ^~~~~~~~~~~~~~~~~
drivers/bluetooth/btintel.c:252:6: warning: no previous prototype for 'btintel_boot_info_tlv' [-Wmissing-prototypes]
252 | void btintel_boot_info_tlv(struct hci_dev *hdev,
|      ^~~~~~~~~~~~~~~~~~~~~
<<                  from drivers/bluetooth/btintel.c:9:
>> drivers/bluetooth/btintel.c:385:6: warning: no previous prototype for 'btintel_get_fw_name' [-Wmissing-prototypes]
385 | bool btintel_get_fw_name(struct intel_version *ver,
|      ^~~~~~~~~~~~~~~~~~~
<<                  from drivers/bluetooth/btintel.c:9:
>> drivers/bluetooth/btintel.c:439:6: warning: no previous prototype for 'btintel_get_fw_name_tlv' [-Wmissing-prototypes]
439 | void btintel_get_fw_name_tlv(struct intel_version_tlv *ver,
|      ^~~~~~~~~~~~~~~~~~~~~~~

vim +/btintel_get_fw_name +385 drivers/bluetooth/btintel.c

   384	
 > 385	bool btintel_get_fw_name(struct intel_version *ver,
   386				 struct intel_boot_params *params,
   387				 char *fw_name, size_t len,
   388				 const char *suffix)
   389	{
   390		/* This is for legacy HCI_Intel_Read_Version command.
   391		 *
   392		 * With this Intel bootloader only the hardware variant and device
   393		 * revision information are used to select the right firmware for SfP
   394		 * and WsP.
   395		 *
   396		 * The firmware filename is ibt-<hw_variant>-<dev_revid>.sfi.
   397		 *
   398		 * Currently the supported hardware variants are:
   399		 *   11 (0x0b) for iBT3.0 (LnP/SfP)
   400		 *   12 (0x0c) for iBT3.5 (WsP)
   401		 *
   402		 * For ThP/JfP and for future SKU's, the FW name varies based on HW
   403		 * variant, HW revision and FW revision, as these are dependent on CNVi
   404		 * and RF Combination.
   405		 *
   406		 *   17 (0x11) for iBT3.5 (JfP)
   407		 *   18 (0x12) for iBT3.5 (ThP)
   408		 *
   409		 * The firmware file name for these will be
   410		 * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi.
   411		 *
   412		 */
   413	
   414		switch (ver->hw_variant) {
   415		case 0x0b:	/* SfP */
   416		case 0x0c:	/* WsP */
   417			snprintf(fw_name, len, "intel/ibt-%u-%u.%s",
   418				 le16_to_cpu(ver->hw_variant),
   419				 le16_to_cpu(params->dev_revid),
   420				 suffix);
   421			break;
   422		case 0x11:	/* JfP */
   423		case 0x12:	/* ThP */
   424		case 0x13:	/* HrP */
   425		case 0x14:	/* CcP */
   426			snprintf(fw_name, len, "intel/ibt-%u-%u-%u.%s",
   427				 le16_to_cpu(ver->hw_variant),
   428				 le16_to_cpu(ver->hw_revision),
   429				 le16_to_cpu(ver->fw_revision),
   430				 suffix);
   431			break;
   432		default:
   433			return false;
   434		}
   435		return true;
   436	}
   437	EXPORT_SYMBOL_GPL(btintel_get_fw_name);
   438	
 > 439	void btintel_get_fw_name_tlv(struct intel_version_tlv *ver,
   440				     char *fw_name, size_t len,
   441				     const char *suffix)
   442	{
   443		/* This is for legacy HCI_Intel_Read_Version command.
   444		 * The firmware file name for these will be
   445		 * ibt-<cnvi_top type+cnvi_top step>-<cnvr_top type+cnvr_top step>
   446		 *
   447		 * Currently the supported hardware variants are:
   448		 * iBT4.2 23 (0x17) for TyP
   449		 * iBT4.2 24 (0x18) for Solar
   450		 */
   451		snprintf(fw_name, len, "intel/ibt-%04x-%04x.%s",
   452			 INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver->cnvi_top),
   453			 INTEL_CNVX_TOP_STEP(ver->cnvi_top)),
   454			 INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver->cnvr_top),
   455			 INTEL_CNVX_TOP_STEP(ver->cnvr_top)),
   456			 suffix);
   457	}
   458	EXPORT_SYMBOL_GPL(btintel_get_fw_name_tlv);
   459	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
index 0139857f6a2c..ae60527e1abd 100644
--- a/drivers/bluetooth/btintel.c
+++ b/drivers/bluetooth/btintel.c
@@ -382,6 +382,81 @@  int btintel_set_event_mask_mfg(struct hci_dev *hdev, bool debug)
 }
 EXPORT_SYMBOL_GPL(btintel_set_event_mask_mfg);
 
+bool btintel_get_fw_name(struct intel_version *ver,
+			 struct intel_boot_params *params,
+			 char *fw_name, size_t len,
+			 const char *suffix)
+{
+	/* This is for legacy HCI_Intel_Read_Version command.
+	 *
+	 * With this Intel bootloader only the hardware variant and device
+	 * revision information are used to select the right firmware for SfP
+	 * and WsP.
+	 *
+	 * The firmware filename is ibt-<hw_variant>-<dev_revid>.sfi.
+	 *
+	 * Currently the supported hardware variants are:
+	 *   11 (0x0b) for iBT3.0 (LnP/SfP)
+	 *   12 (0x0c) for iBT3.5 (WsP)
+	 *
+	 * For ThP/JfP and for future SKU's, the FW name varies based on HW
+	 * variant, HW revision and FW revision, as these are dependent on CNVi
+	 * and RF Combination.
+	 *
+	 *   17 (0x11) for iBT3.5 (JfP)
+	 *   18 (0x12) for iBT3.5 (ThP)
+	 *
+	 * The firmware file name for these will be
+	 * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi.
+	 *
+	 */
+
+	switch (ver->hw_variant) {
+	case 0x0b:	/* SfP */
+	case 0x0c:	/* WsP */
+		snprintf(fw_name, len, "intel/ibt-%u-%u.%s",
+			 le16_to_cpu(ver->hw_variant),
+			 le16_to_cpu(params->dev_revid),
+			 suffix);
+		break;
+	case 0x11:	/* JfP */
+	case 0x12:	/* ThP */
+	case 0x13:	/* HrP */
+	case 0x14:	/* CcP */
+		snprintf(fw_name, len, "intel/ibt-%u-%u-%u.%s",
+			 le16_to_cpu(ver->hw_variant),
+			 le16_to_cpu(ver->hw_revision),
+			 le16_to_cpu(ver->fw_revision),
+			 suffix);
+		break;
+	default:
+		return false;
+	}
+	return true;
+}
+EXPORT_SYMBOL_GPL(btintel_get_fw_name);
+
+void btintel_get_fw_name_tlv(struct intel_version_tlv *ver,
+			     char *fw_name, size_t len,
+			     const char *suffix)
+{
+	/* This is for legacy HCI_Intel_Read_Version command.
+	 * The firmware file name for these will be
+	 * ibt-<cnvi_top type+cnvi_top step>-<cnvr_top type+cnvr_top step>
+	 *
+	 * Currently the supported hardware variants are:
+	 * iBT4.2 23 (0x17) for TyP
+	 * iBT4.2 24 (0x18) for Solar
+	 */
+	snprintf(fw_name, len, "intel/ibt-%04x-%04x.%s",
+		 INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver->cnvi_top),
+		 INTEL_CNVX_TOP_STEP(ver->cnvi_top)),
+		 INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver->cnvr_top),
+		 INTEL_CNVX_TOP_STEP(ver->cnvr_top)),
+		 suffix);
+}
+EXPORT_SYMBOL_GPL(btintel_get_fw_name_tlv);
+
 int btintel_read_version(struct hci_dev *hdev, struct intel_version *ver)
 {
 	struct sk_buff *skb;
diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h
index 32b2cd887bdd..fa4b1b801b13 100644
--- a/drivers/bluetooth/btintel.h
+++ b/drivers/bluetooth/btintel.h
@@ -106,6 +106,12 @@  struct intel_debug_features {
 	__u8    page1[16];
 } __packed;
 
+#define INTEL_CNVX_TOP_TYPE_MASK	0x00000fff
+#define INTEL_CNVX_TOP_STEP_MASK	0x0f000000
+#define INTEL_CNVX_TOP_TYPE(cnvx_top)	((cnvx_top) & INTEL_CNVX_TOP_TYPE_MASK)
+#define INTEL_CNVX_TOP_STEP(cnvx_top)	(((cnvx_top) & INTEL_CNVX_TOP_STEP_MASK) >> 24)
+#define INTEL_CNVX_TOP_PACK_SWAB(t, s)	__swab16(((__u16)(((t) << 4) | (s))))
+
 #if IS_ENABLED(CONFIG_BT_INTEL)
 
 int btintel_check_bdaddr(struct hci_dev *hdev);