Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp944641pxf; Wed, 7 Apr 2021 15:44:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7ivXu4bgw5IjHDnMSo+McOm1KHDBKc3kkPnIa0yu/vbA1V0A+HUcQGr4GUL3rVUmhMvKQ X-Received: by 2002:a05:6402:3493:: with SMTP id v19mr7552929edc.355.1617835478249; Wed, 07 Apr 2021 15:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617835478; cv=none; d=google.com; s=arc-20160816; b=mRBp3SLuahaCu/+VIYkwE97Wt+PkJkV7pdB+eE9skN5UOmdL052fQcy4+FJ5ehBNWJ 94QMllQbdbqOqNoxI9iIIT50+o0fhAX6yAK++hlZcD065Q+YyVtIIN/W/BDBoXgQfzd8 s8fV/DPQq1fUSZL7gJxvV5gPEKUhRTLqHFf++PFy8k1wfz1ZZ1kaovVHDgQOSMBDtxyW 6T8uuJNajRmRRJs3c4vQhmhTWsmgkMVtE1h7p5xJZi7VouAa7h+efYIzOWGE9+EM2Gmw FGCtqp0A76yNHn/qYjHzIKV4BN6OMJtP4ox2C6Os3bb4PIpktKbtVtNGwaVnBS24AJbg bR+A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=0NJnztYTJaoFAIZsBcQ7yvtIWrku1cZ17lKPJor2OqY=; b=UhpYb2tpfHtlmG35UD5aqRW+/oJaPZL0JZob5xTNYoXCb3PXF4B7RILqXcer/iQm88 p1pCWGiKQut5eG9SO1GbdHklAXfRjbIFMuyZ5sUfnVoKBJitOxiF/y/6mwE0eGkWknFH B+v99ikf7Vzl8bsz+0QzaPCBQQPFlyM4L86JCs7cVMIYftZLv2Qax1vOwOZ2oEOBbIWm N0VneCD9bDkOxVAofxbClDHzZdspV3WNl3veqLBOF9n/04ihkGYbDxCsC/usAz5PUzBV fUt9SRAVELg+H7lQEDbIMjMG+O5f16zs2DUwCtqaw9BK7lfCvB5Qwtvnmfxei4E+0XU/ W0bg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l33si22995974ede.161.2021.04.07.15.44.15; Wed, 07 Apr 2021 15:44:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230088AbhDGW12 (ORCPT + 99 others); Wed, 7 Apr 2021 18:27:28 -0400 Received: from mga09.intel.com ([134.134.136.24]:14331 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbhDGW1P (ORCPT ); Wed, 7 Apr 2021 18:27:15 -0400 IronPort-SDR: uUTE5S0JR5LavUcoC3Z3dKFerghBmsoSSXFHhxLyaD7pQGtaxdojyy8oHuTyr7TMGTMfLzkhNZ BvQ+DH7Q6xgQ== X-IronPort-AV: E=McAfee;i="6000,8403,9947"; a="193524933" X-IronPort-AV: E=Sophos;i="5.82,204,1613462400"; d="scan'208";a="193524933" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2021 15:26:40 -0700 IronPort-SDR: dNHa0MOT1sReN41KYCAdZKPnlccO+W8MxQB87GzVASQfR56+bXSuo5naYNAqHVKte7lW8BJjfJ SE+CHQgOxdJQ== X-IronPort-AV: E=Sophos;i="5.82,204,1613462400"; d="scan'208";a="458548554" Received: from hmfaraby-mobl.amr.corp.intel.com (HELO bwidawsk-mobl5.local) ([10.252.128.243]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2021 15:26:39 -0700 From: Ben Widawsky To: linux-cxl@vger.kernel.org Cc: Ben Widawsky , linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, dan.j.williams@intel.com, linux-kernel@vger.kernel.org Subject: [PATCH 6/7] cxl/mem: Create a helper to setup device regs Date: Wed, 7 Apr 2021 15:26:24 -0700 Message-Id: <20210407222625.320177-7-ben.widawsky@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210407222625.320177-1-ben.widawsky@intel.com> References: <20210407222625.320177-1-ben.widawsky@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memory devices have a list of required register regions within the register block, but this isn't required of all CXL components or devices. To make things more tidy, and allow for easily setting up other block types in this loop, the helper is introduced. Signed-off-by: Ben Widawsky --- drivers/cxl/mem.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index 49f651694cb0..b7342aaf38c4 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -974,6 +974,24 @@ static int cxl_mem_dvsec(struct pci_dev *pdev, int dvsec) return 0; } +static int __cxl_setup_device_regs(struct cxl_mem *cxlm, void __iomem *base) +{ + struct cxl_regs *regs = &cxlm->regs; + struct pci_dev *pdev = cxlm->pdev; + struct device *dev = &pdev->dev; + + cxl_setup_device_regs(dev, base, ®s->device_regs); + if (!regs->status || !regs->mbox || !regs->memdev) { + dev_err(dev, "registers not found: %s%s%s\n", + !regs->status ? "status " : "", + !regs->mbox ? "mbox " : "", + !regs->memdev ? "memdev" : ""); + return -ENXIO; + } + + return 0; +} + /** * cxl_mem_setup_regs() - Setup necessary MMIO. * @cxlm: The CXL memory device to communicate with. @@ -986,12 +1004,11 @@ static int cxl_mem_dvsec(struct pci_dev *pdev, int dvsec) */ static int cxl_mem_setup_regs(struct cxl_mem *cxlm) { - struct cxl_regs *regs = &cxlm->regs; struct pci_dev *pdev = cxlm->pdev; struct device *dev = &pdev->dev; u32 regloc_size, regblocks; void __iomem *base; - int regloc, i; + int regloc, i, rc; regloc = cxl_mem_dvsec(pdev, PCI_DVSEC_ID_CXL_REGLOC_OFFSET); if (!regloc) { @@ -1021,23 +1038,14 @@ static int cxl_mem_setup_regs(struct cxl_mem *cxlm) if (IS_ERR(base)) return PTR_ERR(base); - cxl_setup_device_regs(dev, base, ®s->device_regs); - if (!regs->status || !regs->mbox || !regs->memdev) { - dev_err(dev, "registers not found: %s%s%s\n", - !regs->status ? "status " : "", - !regs->mbox ? "mbox " : "", - !regs->memdev ? "memdev" : ""); - return -ENXIO; - } + rc = __cxl_setup_device_regs(cxlm, base); + if (rc) + return rc; + break; } } - if (i == regblocks) { - dev_err(dev, "Missing register locator for device registers\n"); - return -ENXIO; - } - return 0; } -- 2.31.1