All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] thunderbolt: thunderbolt: add vendor's NVM formats
@ 2022-08-16 10:55 Szuying Chen
  2022-08-16 11:23 ` Greg KH
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Szuying Chen @ 2022-08-16 10:55 UTC (permalink / raw)
  To: gregkh, mario.limonciello, mika.westerberg, andreas.noever,
	michael.jamet, YehezkelShB, linux-usb, linux-kernel
  Cc: Yd_Tseng, Chloe_Chen, Richard_Hsu

From: Szuying Chen <Chloe_Chen@asmedia.com.tw>

The patch add tb_nvm_validate() contain an array that has functions
pointers to asmedia_nvm_validate().
And asmedia_nvm_validate() that recognize supported vendor works in one
of the following cases:
Case NVM_UPGRADE: enable nvm's attribute by setting no_nvm_upgrade
flag to create nvm_authenticate file node.
Case NVM_ADD: add active/non-active NVM devices.
Case NVM_WRITE: update firmware to non-ative NVM device.

Signed-off-by: Szuying Chen <Chloe_Chen@asmedia.com.tw>
---Add enum nvm_validate_ops and modify ASMedia NVM Version format.
---Repair file(switch.c) has existed warning, but have 7 warn not fixed.

Note: The three previous submissions accidentally used the same subject
prefix. This changelog is relative to the most recent submission at
https://github.com/intel-lab-lkp/linux/commits/Szuying-Chen/thunderbolt-thunderbolt-add-vendor-s-NVM-formats/20220815-121330

 drivers/thunderbolt/nvm.c    | 148 +++++++++++++++++++++++++++++++++++
 drivers/thunderbolt/switch.c |  28 ++++++-
 drivers/thunderbolt/tb.h     |  23 ++++++
 3 files changed, 196 insertions(+), 3 deletions(-)

diff --git a/drivers/thunderbolt/nvm.c b/drivers/thunderbolt/nvm.c
index b3f310389378..be8cbcfafb80 100644
--- a/drivers/thunderbolt/nvm.c
+++ b/drivers/thunderbolt/nvm.c
@@ -9,11 +9,159 @@
 #include <linux/idr.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/pm_runtime.h>

 #include "tb.h"

 static DEFINE_IDA(nvm_ida);

+static int tb_switch_nvm_read(void *priv, unsigned int offset, void *val,
+			      size_t bytes)
+{
+	struct tb_nvm *nvm = priv;
+	struct tb_switch *sw = tb_to_switch(nvm->dev);
+	int ret;
+
+	pm_runtime_get_sync(&sw->dev);
+	if (!mutex_trylock(&sw->tb->lock)) {
+		ret = restart_syscall();
+		goto out;
+	}
+	ret = usb4_switch_nvm_read(sw, offset, val, bytes);
+	mutex_unlock(&sw->tb->lock);
+
+out:
+	pm_runtime_mark_last_busy(&sw->dev);
+	pm_runtime_put_autosuspend(&sw->dev);
+
+	return ret;
+}
+
+static int tb_switch_nvm_write(void *priv, unsigned int offset, void *val,
+			       size_t bytes)
+{
+	struct tb_nvm *nvm = priv;
+	struct tb_switch *sw = tb_to_switch(nvm->dev);
+	int ret;
+
+	if (!mutex_trylock(&sw->tb->lock))
+		return restart_syscall();
+
+	/*
+	 * Since writing the NVM image might require some special steps,
+	 * for example when CSS headers are written, we cache the image
+	 * locally here and handle the special cases when the user asks
+	 * us to authenticate the image.
+	 */
+	ret = tb_nvm_write_buf(nvm, offset, val, bytes);
+	mutex_unlock(&sw->tb->lock);
+
+	return ret;
+}
+
+static int asmedia_nvm_validate(struct tb_switch *sw, unsigned int mode)
+{
+	struct tb_nvm *nvm;
+	u32 val;
+	u32 nvm_size;
+	int ret = 0;
+	unsigned int image_size;
+
+	switch (mode) {
+	case NVM_UPGRADE:
+		if (sw->no_nvm_upgrade)
+			sw->no_nvm_upgrade = false;
+
+		break;
+
+	case NVM_ADD:
+		nvm = tb_nvm_alloc(&sw->dev);
+		if (IS_ERR(nvm)) {
+			ret = PTR_ERR(nvm);
+			break;
+		}
+
+		ret = usb4_switch_nvm_read(sw, ASMEDIA_NVM_VERSION, &val, sizeof(val));
+		if (ret)
+			break;
+
+		nvm->nvm_asm.major = (((u8)val) << 0x10 | ((u8)(val >> 0x8)) << 0x8 | (u8)(val >> 0x10));
+		ret = usb4_switch_nvm_read(sw, ASMEDIA_NVM_DATE, &val, sizeof(val));
+		if (ret)
+			break;
+
+		nvm->nvm_asm.minor = (((u8)val) << 0x10 | ((u8)(val >> 0x8)) << 0x8 | (u8)(val >> 0x10));
+		nvm_size = SZ_512K;
+		ret = tb_nvm_add_active(nvm, nvm_size, tb_switch_nvm_read);
+		if (ret)
+			break;
+
+		ret = tb_nvm_add_non_active(nvm, NVM_MAX_SIZE, tb_switch_nvm_write);
+		if (ret)
+			break;
+
+		sw->nvm = nvm;
+		break;
+
+	case NVM_WRITE:
+		const u8 *buf = sw->nvm->buf;
+
+		if (!buf) {
+			ret = -EINVAL;
+			break;
+		}
+		image_size = sw->nvm->buf_data_size;
+		if (image_size < NVM_MIN_SIZE || image_size > NVM_MAX_SIZE) {
+			ret = -EINVAL;
+			break;
+		}
+		ret = usb4_switch_nvm_write(sw, 0, buf, image_size);
+		if (!ret)
+			sw->nvm->flushed = true;
+
+		break;
+
+	default:
+		break;
+	}
+
+	if ((mode == NVM_ADD) && (ret != 0))
+		tb_nvm_free(sw->nvm);
+
+	return ret;
+}
+
+struct tb_nvm_id {
+	u16 hw_vendor_id;
+	int (*validate)(struct tb_switch *sw, unsigned int mode);
+};
+
+static const struct tb_nvm_id tb_nvm_vendors[] = {
+	/* ASMedia software CM firmware upgrade */
+	{ 0x174c, asmedia_nvm_validate },
+};
+
+/**
+ * tb_nvm_vendor_handle() - support vendor's NVM format
+ * @sw: Thunderbolt switch
+ * @handle: 0:NvmUpgradeSuppport, 1:NvmAdd, 2:NvmWrite
+ */
+int tb_nvm_validate(struct tb_switch *sw, unsigned int mode)
+{
+	int i;
+	int res = 0;
+
+	for (i = 0; i < ARRAY_SIZE(tb_nvm_vendors); i++) {
+		const struct tb_nvm_id *id = &tb_nvm_vendors[i];
+
+		if (id->hw_vendor_id && id->hw_vendor_id != sw->config.vendor_id)
+			continue;
+
+		 res = id->validate(sw, mode);
+	}
+	return res;
+}
+
 /**
  * tb_nvm_alloc() - Allocate new NVM structure
  * @dev: Device owning the NVM
diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index 244f8cd38b25..de380fb5a166 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -114,6 +114,14 @@ static int nvm_validate_and_write(struct tb_switch *sw)
 	if (image_size < NVM_MIN_SIZE || image_size > NVM_MAX_SIZE)
 		return -EINVAL;

+	/*
+	 * Vendor's nvm write. If the image has been flushed to the
+	 * storage are, nvm write is complete.
+	 */
+	ret = tb_nvm_validate(sw, NVM_WRITE);
+	if (sw->nvm->flushed)
+		return ret;
+
 	/*
 	 * FARB pointer must point inside the image and must at least
 	 * contain parts of the digital section we will be reading here.
@@ -391,10 +399,14 @@ static int tb_switch_nvm_add(struct tb_switch *sw)
 		return 0;

 	/*
-	 * The NVM format of non-Intel hardware is not known so
-	 * currently restrict NVM upgrade for Intel hardware. We may
-	 * relax this in the future when we learn other NVM formats.
+	 * The NVM format of Intel and Asmedia hardware are known so
+	 * currently restrict NVM upgrade for Intel and Asmedia hardware.
+	 * We may relax this in the future when we learn other NVM formats.
 	 */
+	ret = tb_nvm_validate(sw, NVM_ADD);
+	if (ret)
+		return ret;
+
 	if (sw->config.vendor_id != PCI_VENDOR_ID_INTEL &&
 	    sw->config.vendor_id != 0x8087) {
 		dev_info(&sw->dev,
@@ -527,6 +539,7 @@ int tb_port_state(struct tb_port *port)
 {
 	struct tb_cap_phy phy;
 	int res;
+
 	if (port->cap_phy == 0) {
 		tb_port_WARN(port, "does not have a PHY\n");
 		return -EINVAL;
@@ -556,6 +569,7 @@ int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
 {
 	int retries = 10;
 	int state;
+
 	if (!port->cap_phy) {
 		tb_port_WARN(port, "does not have PHY\n");
 		return -EINVAL;
@@ -653,6 +667,7 @@ int tb_port_add_nfc_credits(struct tb_port *port, int credits)
 int tb_port_clear_counter(struct tb_port *port, int counter)
 {
 	u32 zero[3] = { 0, 0, 0 };
+
 	tb_port_dbg(port, "clearing counter %d\n", counter);
 	return tb_port_write(port, zero, TB_CFG_COUNTERS, 3 * counter, 3);
 }
@@ -875,6 +890,7 @@ static inline bool tb_switch_is_reachable(const struct tb_switch *parent,
 					  const struct tb_switch *sw)
 {
 	u64 mask = (1ULL << parent->config.depth * 8) - 1;
+
 	return (tb_route(parent) & mask) == (tb_route(sw) & mask);
 }

@@ -1345,6 +1361,7 @@ bool tb_pci_port_is_enabled(struct tb_port *port)
 int tb_pci_port_enable(struct tb_port *port, bool enable)
 {
 	u32 word = enable ? ADP_PCIE_CS_0_PE : 0x0;
+
 	if (!port->cap_adap)
 		return -ENXIO;
 	return tb_port_write(port, &word, TB_CFG_PORT,
@@ -1918,6 +1935,7 @@ static ssize_t nvm_authenticate_store(struct device *dev,
 	struct device_attribute *attr, const char *buf, size_t count)
 {
 	int ret = nvm_authenticate_sysfs(dev, buf, false);
+
 	if (ret)
 		return ret;
 	return count;
@@ -1953,6 +1971,9 @@ static ssize_t nvm_version_show(struct device *dev,
 		ret = -ENODATA;
 	else if (!sw->nvm)
 		ret = -EAGAIN;
+	/*ASMedia NVM version show format xxxxxx_xxxxxx */
+	else if (sw->config.vendor_id == 0x174C)
+		ret = sprintf(buf, "%06x.%06x\n", sw->nvm->nvm_asm.major, sw->nvm->nvm_asm.minor);
 	else
 		ret = sprintf(buf, "%x.%x\n", sw->nvm->major, sw->nvm->minor);

@@ -2860,6 +2881,7 @@ int tb_switch_add(struct tb_switch *sw)
 		tb_sw_dbg(sw, "uid: %#llx\n", sw->uid);

 		tb_check_quirks(sw);
+		tb_nvm_validate(sw, NVM_UPGRADE);

 		ret = tb_switch_set_uuid(sw);
 		if (ret) {
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index 5db76de40cc1..7f5c8ae731a0 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -28,6 +28,15 @@
 #define NVM_VERSION		0x08
 #define NVM_FLASH_SIZE		0x45

+/* ASMedia specific NVM offsets */
+#define ASMEDIA_NVM_VERSION	0x28
+#define ASMEDIA_NVM_DATE	0x1c
+
+struct nvm_asmedia {
+	u32 major;
+	u32 minor;
+};
+
 /**
  * struct tb_nvm - Structure holding NVM information
  * @dev: Owner of the NVM
@@ -57,6 +66,7 @@ struct tb_nvm {
 	size_t buf_data_size;
 	bool authenticating;
 	bool flushed;
+	struct nvm_asmedia nvm_asm;
 };

 enum tb_nvm_write_ops {
@@ -65,6 +75,18 @@ enum tb_nvm_write_ops {
 	AUTHENTICATE_ONLY = 3,
 };

+/*
+ * enum nvm_validate_ops - Nvm upgrade for each vendor
+ * @NVM_UPGRADE: Not prevent NVM upgrade.
+ * @NVM_ADD: Vendor's NVM device add.
+ * @NVM_WRITE: Vendor's NVM write.
+ */
+enum nvm_validate_ops {
+	NVM_UPGRADE = 0,
+	NVM_ADD = 1,
+	NVM_WRITE = 2,
+};
+
 #define TB_SWITCH_KEY_SIZE		32
 #define TB_SWITCH_MAX_DEPTH		6
 #define USB4_SWITCH_MAX_DEPTH		5
@@ -736,6 +758,7 @@ static inline void tb_domain_put(struct tb *tb)
 	put_device(&tb->dev);
 }

+int tb_nvm_validate(struct tb_switch *sw, unsigned int mode);
 struct tb_nvm *tb_nvm_alloc(struct device *dev);
 int tb_nvm_add_active(struct tb_nvm *nvm, size_t size, nvmem_reg_read_t reg_read);
 int tb_nvm_write_buf(struct tb_nvm *nvm, unsigned int offset, void *val,
--
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread
* Re: [PATCH v4] thunderbolt: thunderbolt: add vendor's NVM formats
@ 2022-08-20 16:54 kernel test robot
  0 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2022-08-20 16:54 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 7979 bytes --]

:::::: 
:::::: Manual check reason: "low confidence static check warning: drivers/thunderbolt/nvm.c:107:17: sparse: sparse: typename in expression"
:::::: 

BCC: lkp(a)intel.com
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20220816105502.9059-1-chensiying21@gmail.com>
References: <20220816105502.9059-1-chensiying21@gmail.com>
TO: Szuying Chen <chensiying21@gmail.com>
TO: gregkh(a)linuxfoundation.org
TO: mario.limonciello(a)amd.com
TO: mika.westerberg(a)linux.intel.com
TO: andreas.noever(a)gmail.com
TO: michael.jamet(a)intel.com
TO: YehezkelShB(a)gmail.com
TO: linux-usb(a)vger.kernel.org
TO: linux-kernel(a)vger.kernel.org
CC: Yd_Tseng(a)asmedia.com.tw
CC: Chloe_Chen(a)asmedia.com.tw
CC: Richard_Hsu(a)asmedia.com.tw

Hi Szuying,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.0-rc1 next-20220819]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Szuying-Chen/thunderbolt-thunderbolt-add-vendor-s-NVM-formats/20220816-193757
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
:::::: branch date: 4 days ago
:::::: commit date: 4 days ago
config: alpha-randconfig-s051-20220820 (https://download.01.org/0day-ci/archive/20220821/202208210009.yPNSc9D5-lkp(a)intel.com/config)
compiler: alpha-linux-gcc (GCC) 12.1.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.4-39-gce1a6720-dirty
        # https://github.com/intel-lab-lkp/linux/commit/16b15f1135451c01b616a6a2bacf2f54a1082a08
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Szuying-Chen/thunderbolt-thunderbolt-add-vendor-s-NVM-formats/20220816-193757
        git checkout 16b15f1135451c01b616a6a2bacf2f54a1082a08
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=alpha SHELL=/bin/bash drivers/thunderbolt/

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

sparse warnings: (new ones prefixed by >>)
>> drivers/thunderbolt/nvm.c:107:17: sparse: sparse: typename in expression
   drivers/thunderbolt/nvm.c:107:23: sparse: sparse: Expected ; at end of statement
   drivers/thunderbolt/nvm.c:107:23: sparse: sparse: got u8
   drivers/thunderbolt/nvm.c:107:17: sparse: sparse: undefined identifier 'const'
   drivers/thunderbolt/nvm.c:109:22: sparse: sparse: undefined identifier 'buf'
   drivers/thunderbolt/nvm.c:118:52: sparse: sparse: undefined identifier 'buf'

vim +107 drivers/thunderbolt/nvm.c

16b15f1135451c Szuying Chen 2022-08-16   61  
16b15f1135451c Szuying Chen 2022-08-16   62  static int asmedia_nvm_validate(struct tb_switch *sw, unsigned int mode)
16b15f1135451c Szuying Chen 2022-08-16   63  {
16b15f1135451c Szuying Chen 2022-08-16   64  	struct tb_nvm *nvm;
16b15f1135451c Szuying Chen 2022-08-16   65  	u32 val;
16b15f1135451c Szuying Chen 2022-08-16   66  	u32 nvm_size;
16b15f1135451c Szuying Chen 2022-08-16   67  	int ret = 0;
16b15f1135451c Szuying Chen 2022-08-16   68  	unsigned int image_size;
16b15f1135451c Szuying Chen 2022-08-16   69  
16b15f1135451c Szuying Chen 2022-08-16   70  	switch (mode) {
16b15f1135451c Szuying Chen 2022-08-16   71  	case NVM_UPGRADE:
16b15f1135451c Szuying Chen 2022-08-16   72  		if (sw->no_nvm_upgrade)
16b15f1135451c Szuying Chen 2022-08-16   73  			sw->no_nvm_upgrade = false;
16b15f1135451c Szuying Chen 2022-08-16   74  
16b15f1135451c Szuying Chen 2022-08-16   75  		break;
16b15f1135451c Szuying Chen 2022-08-16   76  
16b15f1135451c Szuying Chen 2022-08-16   77  	case NVM_ADD:
16b15f1135451c Szuying Chen 2022-08-16   78  		nvm = tb_nvm_alloc(&sw->dev);
16b15f1135451c Szuying Chen 2022-08-16   79  		if (IS_ERR(nvm)) {
16b15f1135451c Szuying Chen 2022-08-16   80  			ret = PTR_ERR(nvm);
16b15f1135451c Szuying Chen 2022-08-16   81  			break;
16b15f1135451c Szuying Chen 2022-08-16   82  		}
16b15f1135451c Szuying Chen 2022-08-16   83  
16b15f1135451c Szuying Chen 2022-08-16   84  		ret = usb4_switch_nvm_read(sw, ASMEDIA_NVM_VERSION, &val, sizeof(val));
16b15f1135451c Szuying Chen 2022-08-16   85  		if (ret)
16b15f1135451c Szuying Chen 2022-08-16   86  			break;
16b15f1135451c Szuying Chen 2022-08-16   87  
16b15f1135451c Szuying Chen 2022-08-16   88  		nvm->nvm_asm.major = (((u8)val) << 0x10 | ((u8)(val >> 0x8)) << 0x8 | (u8)(val >> 0x10));
16b15f1135451c Szuying Chen 2022-08-16   89  		ret = usb4_switch_nvm_read(sw, ASMEDIA_NVM_DATE, &val, sizeof(val));
16b15f1135451c Szuying Chen 2022-08-16   90  		if (ret)
16b15f1135451c Szuying Chen 2022-08-16   91  			break;
16b15f1135451c Szuying Chen 2022-08-16   92  
16b15f1135451c Szuying Chen 2022-08-16   93  		nvm->nvm_asm.minor = (((u8)val) << 0x10 | ((u8)(val >> 0x8)) << 0x8 | (u8)(val >> 0x10));
16b15f1135451c Szuying Chen 2022-08-16   94  		nvm_size = SZ_512K;
16b15f1135451c Szuying Chen 2022-08-16   95  		ret = tb_nvm_add_active(nvm, nvm_size, tb_switch_nvm_read);
16b15f1135451c Szuying Chen 2022-08-16   96  		if (ret)
16b15f1135451c Szuying Chen 2022-08-16   97  			break;
16b15f1135451c Szuying Chen 2022-08-16   98  
16b15f1135451c Szuying Chen 2022-08-16   99  		ret = tb_nvm_add_non_active(nvm, NVM_MAX_SIZE, tb_switch_nvm_write);
16b15f1135451c Szuying Chen 2022-08-16  100  		if (ret)
16b15f1135451c Szuying Chen 2022-08-16  101  			break;
16b15f1135451c Szuying Chen 2022-08-16  102  
16b15f1135451c Szuying Chen 2022-08-16  103  		sw->nvm = nvm;
16b15f1135451c Szuying Chen 2022-08-16  104  		break;
16b15f1135451c Szuying Chen 2022-08-16  105  
16b15f1135451c Szuying Chen 2022-08-16  106  	case NVM_WRITE:
16b15f1135451c Szuying Chen 2022-08-16 @107  		const u8 *buf = sw->nvm->buf;
16b15f1135451c Szuying Chen 2022-08-16  108  
16b15f1135451c Szuying Chen 2022-08-16  109  		if (!buf) {
16b15f1135451c Szuying Chen 2022-08-16  110  			ret = -EINVAL;
16b15f1135451c Szuying Chen 2022-08-16  111  			break;
16b15f1135451c Szuying Chen 2022-08-16  112  		}
16b15f1135451c Szuying Chen 2022-08-16  113  		image_size = sw->nvm->buf_data_size;
16b15f1135451c Szuying Chen 2022-08-16  114  		if (image_size < NVM_MIN_SIZE || image_size > NVM_MAX_SIZE) {
16b15f1135451c Szuying Chen 2022-08-16  115  			ret = -EINVAL;
16b15f1135451c Szuying Chen 2022-08-16  116  			break;
16b15f1135451c Szuying Chen 2022-08-16  117  		}
16b15f1135451c Szuying Chen 2022-08-16  118  		ret = usb4_switch_nvm_write(sw, 0, buf, image_size);
16b15f1135451c Szuying Chen 2022-08-16  119  		if (!ret)
16b15f1135451c Szuying Chen 2022-08-16  120  			sw->nvm->flushed = true;
16b15f1135451c Szuying Chen 2022-08-16  121  
16b15f1135451c Szuying Chen 2022-08-16  122  		break;
16b15f1135451c Szuying Chen 2022-08-16  123  
16b15f1135451c Szuying Chen 2022-08-16  124  	default:
16b15f1135451c Szuying Chen 2022-08-16  125  		break;
16b15f1135451c Szuying Chen 2022-08-16  126  	}
16b15f1135451c Szuying Chen 2022-08-16  127  
16b15f1135451c Szuying Chen 2022-08-16  128  	if ((mode == NVM_ADD) && (ret != 0))
16b15f1135451c Szuying Chen 2022-08-16  129  		tb_nvm_free(sw->nvm);
16b15f1135451c Szuying Chen 2022-08-16  130  
16b15f1135451c Szuying Chen 2022-08-16  131  	return ret;
16b15f1135451c Szuying Chen 2022-08-16  132  }
16b15f1135451c Szuying Chen 2022-08-16  133  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH v4] thunderbolt: thunderbolt: add vendor's NVM formats
@ 2022-08-20 21:08 kernel test robot
  0 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2022-08-20 21:08 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 6697 bytes --]

BCC: lkp(a)intel.com
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20220816105502.9059-1-chensiying21@gmail.com>
References: <20220816105502.9059-1-chensiying21@gmail.com>
TO: Szuying Chen <chensiying21@gmail.com>
TO: gregkh(a)linuxfoundation.org
TO: mario.limonciello(a)amd.com
TO: mika.westerberg(a)linux.intel.com
TO: andreas.noever(a)gmail.com
TO: michael.jamet(a)intel.com
TO: YehezkelShB(a)gmail.com
TO: linux-usb(a)vger.kernel.org
TO: linux-kernel(a)vger.kernel.org
CC: Yd_Tseng(a)asmedia.com.tw
CC: Chloe_Chen(a)asmedia.com.tw
CC: Richard_Hsu(a)asmedia.com.tw

Hi Szuying,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.0-rc1 next-20220819]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Szuying-Chen/thunderbolt-thunderbolt-add-vendor-s-NVM-formats/20220816-193757
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
:::::: branch date: 4 days ago
:::::: commit date: 4 days ago
config: i386-randconfig-m021 (https://download.01.org/0day-ci/archive/20220821/202208210428.twrbg1M9-lkp(a)intel.com/config)
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
drivers/thunderbolt/nvm.c:107 asmedia_nvm_validate() warn: statement has no effect 3

Old smatch warnings:
drivers/thunderbolt/nvm.c:160 tb_nvm_validate() warn: inconsistent indenting

vim +107 drivers/thunderbolt/nvm.c

16b15f1135451c Szuying Chen 2022-08-16   61  
16b15f1135451c Szuying Chen 2022-08-16   62  static int asmedia_nvm_validate(struct tb_switch *sw, unsigned int mode)
16b15f1135451c Szuying Chen 2022-08-16   63  {
16b15f1135451c Szuying Chen 2022-08-16   64  	struct tb_nvm *nvm;
16b15f1135451c Szuying Chen 2022-08-16   65  	u32 val;
16b15f1135451c Szuying Chen 2022-08-16   66  	u32 nvm_size;
16b15f1135451c Szuying Chen 2022-08-16   67  	int ret = 0;
16b15f1135451c Szuying Chen 2022-08-16   68  	unsigned int image_size;
16b15f1135451c Szuying Chen 2022-08-16   69  
16b15f1135451c Szuying Chen 2022-08-16   70  	switch (mode) {
16b15f1135451c Szuying Chen 2022-08-16   71  	case NVM_UPGRADE:
16b15f1135451c Szuying Chen 2022-08-16   72  		if (sw->no_nvm_upgrade)
16b15f1135451c Szuying Chen 2022-08-16   73  			sw->no_nvm_upgrade = false;
16b15f1135451c Szuying Chen 2022-08-16   74  
16b15f1135451c Szuying Chen 2022-08-16   75  		break;
16b15f1135451c Szuying Chen 2022-08-16   76  
16b15f1135451c Szuying Chen 2022-08-16   77  	case NVM_ADD:
16b15f1135451c Szuying Chen 2022-08-16   78  		nvm = tb_nvm_alloc(&sw->dev);
16b15f1135451c Szuying Chen 2022-08-16   79  		if (IS_ERR(nvm)) {
16b15f1135451c Szuying Chen 2022-08-16   80  			ret = PTR_ERR(nvm);
16b15f1135451c Szuying Chen 2022-08-16   81  			break;
16b15f1135451c Szuying Chen 2022-08-16   82  		}
16b15f1135451c Szuying Chen 2022-08-16   83  
16b15f1135451c Szuying Chen 2022-08-16   84  		ret = usb4_switch_nvm_read(sw, ASMEDIA_NVM_VERSION, &val, sizeof(val));
16b15f1135451c Szuying Chen 2022-08-16   85  		if (ret)
16b15f1135451c Szuying Chen 2022-08-16   86  			break;
16b15f1135451c Szuying Chen 2022-08-16   87  
16b15f1135451c Szuying Chen 2022-08-16   88  		nvm->nvm_asm.major = (((u8)val) << 0x10 | ((u8)(val >> 0x8)) << 0x8 | (u8)(val >> 0x10));
16b15f1135451c Szuying Chen 2022-08-16   89  		ret = usb4_switch_nvm_read(sw, ASMEDIA_NVM_DATE, &val, sizeof(val));
16b15f1135451c Szuying Chen 2022-08-16   90  		if (ret)
16b15f1135451c Szuying Chen 2022-08-16   91  			break;
16b15f1135451c Szuying Chen 2022-08-16   92  
16b15f1135451c Szuying Chen 2022-08-16   93  		nvm->nvm_asm.minor = (((u8)val) << 0x10 | ((u8)(val >> 0x8)) << 0x8 | (u8)(val >> 0x10));
16b15f1135451c Szuying Chen 2022-08-16   94  		nvm_size = SZ_512K;
16b15f1135451c Szuying Chen 2022-08-16   95  		ret = tb_nvm_add_active(nvm, nvm_size, tb_switch_nvm_read);
16b15f1135451c Szuying Chen 2022-08-16   96  		if (ret)
16b15f1135451c Szuying Chen 2022-08-16   97  			break;
16b15f1135451c Szuying Chen 2022-08-16   98  
16b15f1135451c Szuying Chen 2022-08-16   99  		ret = tb_nvm_add_non_active(nvm, NVM_MAX_SIZE, tb_switch_nvm_write);
16b15f1135451c Szuying Chen 2022-08-16  100  		if (ret)
16b15f1135451c Szuying Chen 2022-08-16  101  			break;
16b15f1135451c Szuying Chen 2022-08-16  102  
16b15f1135451c Szuying Chen 2022-08-16  103  		sw->nvm = nvm;
16b15f1135451c Szuying Chen 2022-08-16  104  		break;
16b15f1135451c Szuying Chen 2022-08-16  105  
16b15f1135451c Szuying Chen 2022-08-16  106  	case NVM_WRITE:
16b15f1135451c Szuying Chen 2022-08-16 @107  		const u8 *buf = sw->nvm->buf;
16b15f1135451c Szuying Chen 2022-08-16  108  
16b15f1135451c Szuying Chen 2022-08-16  109  		if (!buf) {
16b15f1135451c Szuying Chen 2022-08-16  110  			ret = -EINVAL;
16b15f1135451c Szuying Chen 2022-08-16  111  			break;
16b15f1135451c Szuying Chen 2022-08-16  112  		}
16b15f1135451c Szuying Chen 2022-08-16  113  		image_size = sw->nvm->buf_data_size;
16b15f1135451c Szuying Chen 2022-08-16  114  		if (image_size < NVM_MIN_SIZE || image_size > NVM_MAX_SIZE) {
16b15f1135451c Szuying Chen 2022-08-16  115  			ret = -EINVAL;
16b15f1135451c Szuying Chen 2022-08-16  116  			break;
16b15f1135451c Szuying Chen 2022-08-16  117  		}
16b15f1135451c Szuying Chen 2022-08-16  118  		ret = usb4_switch_nvm_write(sw, 0, buf, image_size);
16b15f1135451c Szuying Chen 2022-08-16  119  		if (!ret)
16b15f1135451c Szuying Chen 2022-08-16  120  			sw->nvm->flushed = true;
16b15f1135451c Szuying Chen 2022-08-16  121  
16b15f1135451c Szuying Chen 2022-08-16  122  		break;
16b15f1135451c Szuying Chen 2022-08-16  123  
16b15f1135451c Szuying Chen 2022-08-16  124  	default:
16b15f1135451c Szuying Chen 2022-08-16  125  		break;
16b15f1135451c Szuying Chen 2022-08-16  126  	}
16b15f1135451c Szuying Chen 2022-08-16  127  
16b15f1135451c Szuying Chen 2022-08-16  128  	if ((mode == NVM_ADD) && (ret != 0))
16b15f1135451c Szuying Chen 2022-08-16  129  		tb_nvm_free(sw->nvm);
16b15f1135451c Szuying Chen 2022-08-16  130  
16b15f1135451c Szuying Chen 2022-08-16  131  	return ret;
16b15f1135451c Szuying Chen 2022-08-16  132  }
16b15f1135451c Szuying Chen 2022-08-16  133  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-08-20 21:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-16 10:55 [PATCH v4] thunderbolt: thunderbolt: add vendor's NVM formats Szuying Chen
2022-08-16 11:23 ` Greg KH
2022-08-16 11:24 ` Greg KH
2022-08-16 11:45 ` Mika Westerberg
2022-08-16 15:05 ` Limonciello, Mario
2022-08-17  0:20 ` kernel test robot
2022-08-20 16:54 kernel test robot
2022-08-20 21:08 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.