Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4757545rwb; Wed, 17 Aug 2022 05:46:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR4oy30DeUlOYysgifsyUgQVt4FOGDAgWOydw2Dx0o2O+EKVvdbeNRRt0aTjcv2oM70cn07T X-Received: by 2002:a17:906:84ef:b0:731:8768:847c with SMTP id zp15-20020a17090684ef00b007318768847cmr16058969ejb.373.1660740369202; Wed, 17 Aug 2022 05:46:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660740369; cv=none; d=google.com; s=arc-20160816; b=rujlblSzqVpFdI0E73yqselL0d/QDtUBAFazdQ6qXiaqzWPsBnPjDiiEuLrQAVbVxx XWrgVoenhoiu1X6u+RnpLmHKO2raGJhss/CZRK6/FErKDCTNYPHM/XApaIISQnwHlY1L TPWKNdzxp2HP/8jZUs1aOoY89VrqejbaTwU+DZlnlfBtv0/bX3WlOM+CirbVRnKgd4SB PMkkN380cfpDeZmScUJEoADfqe8EHfRYVHk7ApPwjkPNo2WN0wVWL0J0+aYmf13EPIdv TPDBC4k18/40X8FKaScIL0EQcbJgr1OkQ1xM8jLGLS4rwG6woEVjQIvD3Oa4IfLy+8nr aZSA== 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=6PtwDytmUyuevN/XXn2fUzt/ojjQoOTi8Gi9NbFvxzg=; b=O17s+Mm8fDvfQza7vN7/1vUU0ZcinUgeBtRCoj3GBAtTjMbgg9/mjkGaSJwcdWB01j mbVoUpXP7jBv32YqYy0KUbWL/Z/5UYffDScs1907xU+9ptNjPH94uKwCoNOWOz1ndu0D wMdLjlubpDiworM07gLku+qbIn3XNxmFOuNdjstwunR7lfGvnQjiDu0a/79RVah5Js9t gl8Ih19e1bWW5boGOysoqersBYJgINcKhedoGtkGIsmJ1rQgSAiLgVSaAZrIXuetFxee ol72LgeK56oQp5toYvTkZMmxQM9DncKEwZ1RmPiOP4yZPH6d5KuaRKHHmv8LPX6osQTx TwaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Wip09kIP; 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 h19-20020a056402281300b0043def0e25c9si14530397ede.20.2022.08.17.05.45.43; Wed, 17 Aug 2022 05:46:09 -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=Wip09kIP; 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 S239185AbiHQMER (ORCPT + 99 others); Wed, 17 Aug 2022 08:04:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236580AbiHQMEP (ORCPT ); Wed, 17 Aug 2022 08:04:15 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 461844C62A; Wed, 17 Aug 2022 05:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660737854; x=1692273854; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Sw03qyNAB0MNEYgJP3KDR/9fx3+F8UT/HeVmqYUt2GE=; b=Wip09kIPrY9+dtHdJJ1xkDqJ88AoZCotBUpwVJ1cbc7lXwkHwEStLNWl nA66f1taTPDa/jQk4A2v4piCtZ+MLBFAKWCWfiLlDkvZAjrqeFgA76d7f tiy0r+f0MSK+Qwxb8GO6U258dCYiN5I/tLZpD2q7hjf3fKDZk0c+iaz76 yNxgdRD3gkOdCD8jv0rQ/txx0/Bq4dZkoAcShncBn4J9wm5LRmOfoaFP7 b7WTS7bthyNuduy+HdmvhRZ0UtvJdNI9gnagQmw53uTriL/lUn2rTXuas ID85G38SR9ScRPX1uUO8aLn4tyxxWULYLOC5c1d0HCycvHZvnf9LttnQA g==; X-IronPort-AV: E=McAfee;i="6400,9594,10441"; a="356471447" X-IronPort-AV: E=Sophos;i="5.93,243,1654585200"; d="scan'208";a="356471447" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2022 05:04:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,243,1654585200"; d="scan'208";a="583742759" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 17 Aug 2022 05:04:09 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 0BF04235; Wed, 17 Aug 2022 15:04:22 +0300 (EEST) Date: Wed, 17 Aug 2022 15:04:22 +0300 From: Mika Westerberg To: Szuying Chen Cc: mario.limonciello@amd.com, 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: RE: [PATCH v4] thunderbolt: thunderbolt: add vendor's NVM formats Message-ID: References: <20220817102450.63514-1-chensiying21@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220817102450.63514-1-chensiying21@gmail.com> 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,URIBL_BLOCKED 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, On Wed, Aug 17, 2022 at 06:24:50PM +0800, Szuying Chen wrote: > From: Szuying Chen > > Signed-off-by: Szuying Chen > --- > Hi, > > >> From: Szuying Chen > >> > > >> +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); > > > >This function does not only "validate" but it also creates the NVMem > >devices and whatnot. > > > >Do you have some public description of the ASMedia format that I could > >take a look? Perhaps we can find some simpler way of validating the > >thing that works accross different vendors. > > > > ASMedia NVM format include rom file, firmware and security > configuration information. And active firmware depend on this > information for processing. We don't need to do any validation during > firmware upgrade, so we haven't public description of the ASMedia > format. > > I think I use "validate" is not fit. This function mainly to create > the NVMem devices and write. I will rename in the next patch. So instead what you now do, I suggest that we move all the vendor support out to nvm.c, that includes Intel too. What I mean by this is that the tb_switch_nvm_add() would then look something like this: tb_switch_nvm_add(sw) { if (!nvm_readable(sw)) return 0; nvm = tb_switch_nvm_alloc(sw); if (IS_ERR(nvm)) { if (PTR_ERR(nvm) == -EOPNOTSUPP) { dev_info(&sw->dev, "NVM format of vendor %#x is not known, disabling NVM upgrade\n", sw->config.vendor_id); return 0; } return PTR_ERR(nvm); } ret = tb_nvm_add_active(nvm, nvm->size, tb_switch_nvm_read); if (ret) ... if (!sw->no_nvm_upgrade) { ret = tb_nvm_add_non_active(nvm, NVM_MAX_SIZE, tb_switch_nvm_write); if (ret) ... } sw->nvm = nvm; ... } And the tb_switch_nvm_alloc() resides in nvm.c and that one goes over an array of supported vendors matching sw->config.vendor_id and if it finds the match it will set nvm->vops to point the vendor specific operations and in addition it will will populate rest of the nvm fields like this: static const struct { u16 vendor; const struct tb_nvm_vendor_ops *vops; } switch_nvm_vendors[] = { { 0x8086, &intel_switch_nvm_ops }, { 0x8087, &intel_switch_nvm_ops }, { 0x174c, &asmedia_switch_nvm_ops }, }; tb_switch_nvm_alloc(sw) { struct tb_nvm_vendor_ops *ops = NULL; int i; for (i = 0; i < ARRAY_SIZE(switch_nvm_vendors); i++) { if (switch_nvm_vendors[i].vendor == sw->config.vendor_id) vops = &switch_nvm_vendors[i].vops; break; } if (!vops) return ERR_PTR(-EOPNOTSUPP); nvm = tb_nvm_alloc(&sw->dev); if (IS_ERR(nvm)) ... nvm->vops = vops; ret = vops->populate(nvm); if (ret) ... ... } Then we would have all the vendor specific things in intel_switch_nvm_ops and asmedia_switch_nvm_ops accordingly and the rest of the code is generic USB4 stuff. We need to do the same for retimers too at some point.