Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp1904445rwb; Sun, 4 Sep 2022 04:48:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR6QjvZCdAL63PB2jD7xler5u+dR/Qr6j1UQY8qGFTr6+im6tl4ckVan95xWvk0xo7OkaOQb X-Received: by 2002:a17:907:2bce:b0:73d:dd00:9ced with SMTP id gv14-20020a1709072bce00b0073ddd009cedmr29725433ejc.739.1662292135778; Sun, 04 Sep 2022 04:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662292135; cv=none; d=google.com; s=arc-20160816; b=ZYDUlZgWpywsKnhrV1NPIAJvd0AudZkfr1869oESSPV7hR3qO1z+RigzVw/6u2/DtT jKMAyGYRP5Jz4HQyzl0fiTUOwML0G6ttJGdMGYvAltvDm9fj6YPBfURq9eo6ai4iEbaC jK32HtO3i30gDqfa04RTdks6gslwxZ4lIR/aWrqoZlDIVuuHfBXIGjwBN9JlDuKTAkdn Q8msq1knft5DiKIz6dn2S1ygoPhY/eeNTztwFLF8C8L9wb8uYkv1mE2BvGtOYxH0gmir CNRKmxevmKu1JJy3OAaSUwSNoiUWGv/yODfo9it02wWuoLq20uPRYvaZNH4vz4LzX6dk vReQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=br7pXzgQhl2SQt7PnE2fZl/mRLqwETj128fweUdKq2w=; b=U4bvmjSREhUyBXcb7Rr6OewxVzxtV1WohRykdIuD2ox2hMHGKUGs/ATK8xz+M8oqdx P3NidgLDB+wx31C9Euri5dzmNF/VnApQSP+aRhznNCFgFUuWY8weOSE76jCGNcM9XtqN 8e4DW9ifoQJr3keM1bX8cjpYib8Fqq+MXd+5x1GM1gUF5E6eSTnjvM0US1CK9Y+M0/t8 HfSap/9Ax4p9XGcdIZEYhn4Rx/abTHAV/acc4PbnwA0txgQMr43db4yq0Az4087b6yWj 4XdPYoog6kUP07/ziTbQ/wK6AKHMkC3VaN/QUBAsoFjlfU/cKRloAduvQU4Bmkk5akfv kPBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YE21nnur; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cz23-20020a0564021cb700b0044de73821efsi1870286edb.588.2022.09.04.04.48.30; Sun, 04 Sep 2022 04:48:55 -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=@intel.com header.s=Intel header.b=YE21nnur; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233025AbiIDLjA (ORCPT + 99 others); Sun, 4 Sep 2022 07:39:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229760AbiIDLi6 (ORCPT ); Sun, 4 Sep 2022 07:38:58 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C094B41D1E; Sun, 4 Sep 2022 04:38:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662291536; x=1693827536; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=PjBXyuU0GSqxV+SzW5bu1E+l0xNAPR+t/RTIkbhji6A=; b=YE21nnurie4j8ebnGai9dGIcdKGyReeekipz1ZNfN9w7rWQy7Tw0v4y0 klQytZ36Afy71UqIaNBjN2RpmxuJ+dFJVJGFGUjjEQ53m/HUcexGZ8r8X 94t+es3YYu4eSM9FSuv5kIUVS6JC5DJ6+f2QP/r76xbEj24PObfoQASBd sXzrPZCRZ7TMvlJFjIAt5nbF7EKRp/+skWGfQnDt+hZE6ovcxxZYPQ3pF wDK1nf0l+tTo42QfhcvKtajQUf4eYJza7rnVbYMmcVw8AtQhR/3kT2GaI a7xlRC6okyWdrBb1whpE9cFu70aYZ2GZChBS+jHAwWHP9y4fPcuBA9EPM g==; X-IronPort-AV: E=McAfee;i="6500,9779,10459"; a="294974099" X-IronPort-AV: E=Sophos;i="5.93,289,1654585200"; d="scan'208";a="294974099" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Sep 2022 04:38:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,289,1654585200"; d="scan'208";a="646603052" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 04 Sep 2022 04:38:53 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 76C8486; Sun, 4 Sep 2022 14:39:08 +0300 (EEST) Date: Sun, 4 Sep 2022 14:39:08 +0300 From: Mika Westerberg To: "Limonciello, Mario" Cc: Szuying Chen , gregkh@linuxfoundation.org, andreas.noever@gmail.com, michael.jamet@intel.com, YehezkelShB@gmail.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Yd_Tseng@asmedia.com.tw, Chloe_Chen@asmedia.com.tw, Richard_Hsu@asmedia.com.tw Subject: Re: [PATCH v8 3/3] thunderbolt: To extend ASMedia NVM formats. Message-ID: References: <20220902094010.2170-1-chensiying21@gmail.com> <20220902094010.2170-4-chensiying21@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Mario, On Fri, Sep 02, 2022 at 08:32:41AM -0500, Limonciello, Mario wrote: > On 9/2/2022 04:40, Szuying Chen wrote: > > From: Szuying Chen > > > > The patch add ASMedia NVM formats. > > > > Signed-off-by: Szuying Chen > > --- > > v7->v8: Fix the no_nvm_upgrade bit setting on suggestion by Mika. > > > > drivers/thunderbolt/nvm.c | 40 +++++++++++++++++++++++++++++++++++++++ > > drivers/thunderbolt/tb.c | 2 +- > > 2 files changed, 41 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/thunderbolt/nvm.c b/drivers/thunderbolt/nvm.c > > index 878d705bd0cb..8393d82dd108 100644 > > --- a/drivers/thunderbolt/nvm.c > > +++ b/drivers/thunderbolt/nvm.c > > @@ -12,9 +12,16 @@ > > > > #include "tb.h" > > > > +/* ID of Router */ > > +#define ROUTER_VENDOR_ID_ASMEDIA 0x174c > > + > > /* Switch NVM support */ > > #define NVM_CSS 0x10 > > > > +/* ASMedia specific NVM offsets */ > > +#define ASMEDIA_NVM_DATE 0x1c > > +#define ASMEDIA_NVM_VERSION 0x28 > > + > > static DEFINE_IDA(nvm_ida); > > > > /** > > @@ -120,11 +127,43 @@ static int intel_nvm_validate(struct tb_switch *sw) > > return 0; > > } > > > > +static int asmedia_nvm_version(struct tb_switch *sw) > > +{ > > + struct tb_nvm *nvm = sw->nvm; > > + u32 val; > > + int ret; > > + > > + /* ASMedia get version and date format is xxxxxx.xxxxxx */ > > + ret = nvm_read(sw, ASMEDIA_NVM_VERSION, &val, sizeof(val)); > > + if (ret) > > + return ret; > > + > > + nvm->major = (((u8)val) << 0x10 | ((u8)(val >> 0x8)) << 0x8 | (u8)(val >> 0x10)); > > + > > + ret = nvm_read(sw, ASMEDIA_NVM_DATE, &val, sizeof(val)); > > + if (ret) > > + return ret; > > + > > + nvm->minor = (((u8)val) << 0x10 | ((u8)(val >> 0x8)) << 0x8 | (u8)(val >> 0x10)); > > + > > + /* > > + * Asmedia NVM size fixed on 512K. We currently have no plan > > + * to increase size in the future. > > + */ > > + nvm->nvm_size = SZ_512K; > > Any chance this can also be gleamed from your NVM? It would future proof > the kernel code if you did come up with a need to change it in the future > some day rather than hardcoding. > > > + > > + return 0; > > +} > > + > > static const struct tb_nvm_vendor_ops intel_switch_nvm_ops = { > > .read_version = intel_nvm_version, > > .validate = intel_nvm_validate, > > }; > > > > +static const struct tb_nvm_vendor_ops asmedia_switch_nvm_ops = { > > + .read_version = asmedia_nvm_version, > > I recall an earlier version of your patch series was reading the customer ID > as well. Would it make sense to have an `asmedia_nvm_validate` that checks > this matches? It seems the customer ID was the same 0x28 offset than the ASMEDIA_NVM_VERSION so I guess it was just renamed. > > Or any other safety validation that the image is good the kernel might want > to do? Checksum or signature or anything? > > Even if the hardware does all these verifications it's much easier to debug > problems if the kernel can do a first line verification to tell you what is > wrong with the image instead of trying to trace an error code from the > hardware. I agree.