Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5768883ioo; Wed, 1 Jun 2022 12:10:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz96ZokV84QOtajlvnJ0wnIvW4r1zQMmuOie9n6wCz3USmOnGUC/Qi706zlDc+5mpvwwChS X-Received: by 2002:a17:902:dac3:b0:164:13b2:4913 with SMTP id q3-20020a170902dac300b0016413b24913mr855493plx.169.1654110612399; Wed, 01 Jun 2022 12:10:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654110612; cv=none; d=google.com; s=arc-20160816; b=gpFavjvxdsc3Rj63fpgQnOtsk6K0bq4twNmLVU3AHmiEUQjlaRDQl+wk92Hk2O5Eu/ AHB/O3CuOyprpE3IQTRXkvLxDGm/+9lQjpvonc0Zba76B8fs62AcvxOzGwG+vOA7o83U mBFsqLrKwPeAv7hvf9lPIOdGw4qtmILlDexa52SojDcYgCiz8Ixw0HeTc0ipgKEbvhot fe/BaBDKSsRF1DJfA1Kynza+6SO7qyu0gkqLl5flgS4XqvO9yPBvA5stsmiFCB0IMQ3a rec1Il9Qw0kD1ZmDTr8bmlCfC0RuuhHqcH9qiPtFjZHLhO/2BMR1REGmrDAobTMCS8LL 9/bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=DWipEofLapUfq1Jdl348i2kmG66454eKMIA2vNBwtJY=; b=PUAxIMK+BpDsYjW8BRKHaRwNuAx4yu9j3qf5A0PK58YsaTDyNtJscHjbzB3tJah8XO pN/cKA3JxZ89vlkjeQKv99r9qiTk8IXzbLbN++ELvEC/b+XapuUqzkKlJT+D4ERG70HP HMEwyN3fq0m1dQ+eQJpar/gc2BLDOwgu8P33rsPdoxOhuiB01i2V5U739Cn6oAdCK5kx zWbi/a0nkuLfxjFom8FmGH5wW/B7u7o/IxiG0EKs6gW1JmbWl+peK4TYlcjWE7uBDW80 HeZUAwAId5ZNpt+RyYxHPp1/z7fJdaZ82pG5H52gbXCvg6cahm3zwwMj4a2e8vEbAve8 3qsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v14-20020a65460e000000b003f672957b81si3308203pgq.585.2022.06.01.12.10.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 12:10:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 91FBF1269AB; Wed, 1 Jun 2022 11:50:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352701AbiFAOgK (ORCPT + 99 others); Wed, 1 Jun 2022 10:36:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235282AbiFAOgI (ORCPT ); Wed, 1 Jun 2022 10:36:08 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3679D2409F; Wed, 1 Jun 2022 07:36:05 -0700 (PDT) Received: from fraeml705-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LCs610H4kz67xBN; Wed, 1 Jun 2022 22:31:37 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml705-chm.china.huawei.com (10.206.15.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.24; Wed, 1 Jun 2022 16:36:02 +0200 Received: from localhost (10.202.226.42) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 1 Jun 2022 15:36:01 +0100 Date: Wed, 1 Jun 2022 15:35:59 +0100 From: Jonathan Cameron To: Ben Widawsky CC: , Dan Williams , "Bjorn Helgaas" , Alison Schofield , Vishal Verma , "Dave Jiang" , , , Subject: Re: [PATCH V9 4/9] cxl/pci: Create PCI DOE mailbox's for memory devices Message-ID: <20220601153559.0000273b@Huawei.com> In-Reply-To: <20220531175020.efqfth7ubbyhoubp@mail.bwidawsk.net> References: <20220531152632.1397976-1-ira.weiny@intel.com> <20220531152632.1397976-5-ira.weiny@intel.com> <20220531175020.efqfth7ubbyhoubp@mail.bwidawsk.net> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.29; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.42] X-ClientProxiedBy: lhreml739-chm.china.huawei.com (10.201.108.189) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Tue, 31 May 2022 10:50:20 -0700 Ben Widawsky wrote: > On 22-05-31 08:26:27, ira.weiny@intel.com wrote: > > From: Ira Weiny > > > > DOE mailbox objects will be needed for various mailbox communications > > with each memory device. > > > > Iterate each DOE mailbox capability and create PCI DOE mailbox objects > > as found. > > > > It is not anticipated that this is the final resting place for the > > iteration of the DOE devices. The support of ports may drive this code > > into the pcie side. In this imagined architecture the CXL port driver > > would then query into the PCI device for the DOE mailbox array. > > Not sure if direction has changed, but initially it would have been the cxl_pci > driver who would query this and pass it along when the port driver probes. > Personally, I've never had an issue with non cxl_pci drivers using PCI > interfaces and semantics, but it is something we've taken specific care to > avoid. > > > > > For now this is good enough for the endpoints and the split is similar > > to the envisioned architecture where getting the mailbox array is > > separated from the various protocol needs. For example, it is not > > anticipated that the CDAT code will need to move because it is only > > needed by the cxl_ports. > > > > Likewise irq's are separated out in a similar design pattern to the > > PCIe port driver. But a much simpler irq enabling flag is used and only > > DOE interrupts are supported. > > > > Signed-off-by: Ira Weiny > > > > --- > > Changes from V8: > > Move PCI_DOE selection to CXL_BUS to support future patches > > which move queries into the port code. > > Remove Auxiliary device arch > > Squash the functionality of the auxiliary driver into this > > patch. > > Split out the irq handling a bit. > > > > Changes from V7: > > Minor code clean ups > > Rebased on cxl-pending > > > > Changes from V6: > > Move all the auxiliary device stuff to the CXL layer > > > > Changes from V5: > > Split the CXL specific stuff off from the PCI DOE create > > auxiliary device code. > > --- > > drivers/cxl/Kconfig | 1 + > > drivers/cxl/cxlmem.h | 6 +++ > > drivers/cxl/pci.c | 111 +++++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 118 insertions(+) > > > > diff --git a/drivers/cxl/Kconfig b/drivers/cxl/Kconfig > > index f64e3984689f..7adaaf80b302 100644 > > --- a/drivers/cxl/Kconfig > > +++ b/drivers/cxl/Kconfig > > @@ -2,6 +2,7 @@ > > menuconfig CXL_BUS > > tristate "CXL (Compute Express Link) Devices Support" > > depends on PCI > > + select PCI_DOE > > help > > CXL is a bus that is electrically compatible with PCI Express, but > > layers three protocols on that signalling (CXL.io, CXL.cache, and > > diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h > > index 60d10ee1e7fc..4d2764b865ab 100644 > > --- a/drivers/cxl/cxlmem.h > > +++ b/drivers/cxl/cxlmem.h > > @@ -191,6 +191,8 @@ struct cxl_endpoint_dvsec_info { > > * @component_reg_phys: register base of component registers > > * @info: Cached DVSEC information about the device. > > * @serial: PCIe Device Serial Number > > + * @doe_mbs: PCI DOE mailbox array > > + * @num_mbs: Number of DOE mailboxes > > * @mbox_send: @dev specific transport for transmitting mailbox commands > > * > > * See section 8.2.9.5.2 Capacity Configuration and Label Storage for > > @@ -224,6 +226,10 @@ struct cxl_dev_state { > > resource_size_t component_reg_phys; > > u64 serial; > > > > + bool doe_use_irq; > > + struct pci_doe_mb **doe_mbs; > > + int num_mbs; > > + > > int (*mbox_send)(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd); > > }; > > > > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c > > index 5a0ae46d4989..131f89dec8e7 100644 > > --- a/drivers/cxl/pci.c > > +++ b/drivers/cxl/pci.c > > @@ -8,6 +8,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include "cxlmem.h" > > #include "cxlpci.h" > > @@ -386,6 +387,113 @@ static int cxl_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type, > > return rc; > > } > > > > +static void cxl_pci_free_irq_vectors(void *data) > > +{ > > + pci_free_irq_vectors(data); > > +} > > + > > +static void cxl_doe_destroy_mb(void *ds) > > +{ > > + struct cxl_dev_state *cxlds = ds; > > + int i; > > + > > + for (i = 0; i < cxlds->num_mbs; i++) { > > + if (cxlds->doe_mbs[i]) > > + pci_doe_destroy_mb(cxlds->doe_mbs[i]); > > + } > > +} > > + > > +static void cxl_alloc_irq_vectors(struct cxl_dev_state *cxlds) > > +{ > > + struct device *dev = cxlds->dev; > > + struct pci_dev *pdev = to_pci_dev(dev); > > + int num_irqs = 0; > > + int off = 0; > > + int rc; > > + > > + /* Account for all the DOE vectors needed */ > > + pci_doe_for_each_off(pdev, off) { > > + int irq = pci_doe_get_irq_num(pdev, off); > > + > > + if (irq < 0) > > + continue; > > + num_irqs = max(num_irqs, irq + 1); > > This seems overly complicated. Isn't it just num_irqs++? nope. There is no guarantee the irq values are near zero or contiguous. If irq is 33 for example, it pretty much implies that there are 34 or more irq vectors used for something on this device, but we don't know what the rest are for. Trick is used in portdrv to deal with enabling all the irqs needed for the various supported services, which might not be all the irqs the hardware provides. Maybe worth renaming num_irqs as max_irq or something like that and postpone the +1 to where it is used? Jonathan > > > + }