From patchwork Fri Feb 10 09:06:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 13135559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 324D0C6379F for ; Fri, 10 Feb 2023 09:06:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE1D6280004; Fri, 10 Feb 2023 04:06:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B69F7280003; Fri, 10 Feb 2023 04:06:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E3086B012C; Fri, 10 Feb 2023 04:06:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6FA076B0129 for ; Fri, 10 Feb 2023 04:06:37 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0A22A140E8C for ; Fri, 10 Feb 2023 09:06:37 +0000 (UTC) X-FDA: 80450801634.02.97FFA9C Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf24.hostedemail.com (Postfix) with ESMTP id EBE0618001C for ; Fri, 10 Feb 2023 09:06:34 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=DKFgmhDB; spf=pass (imf24.hostedemail.com: domain of dan.j.williams@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676019995; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LZhzV0L5VQceoAk8Yw7eRbPmAiaBjiH42qaw9YHJfuE=; b=1tpFYoNOknCaTplELn9RUDBy60E02WbVBGW9CeKDfpjBGflP8V6rOyT7I3gIuJEhgCjR6B KmQzuyw/VHPk/qq01d4eUyTbOiWGg0dJwdun3FI1HdGkUGuXxB88nGYX4L7/HJtoxofad3 bt8HdU5+6vl9iIXcoqYi/7PS28S+U1Y= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=DKFgmhDB; spf=pass (imf24.hostedemail.com: domain of dan.j.williams@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676019995; a=rsa-sha256; cv=none; b=Wngf4AakTRdhN1wT/do+JR98shI5Lc+yoUplGJUWaETZosien5hQ+i1BqX9FZxgHkrqANe /2y2IxnLuEcy6KizWfts3uuch5Vh+8wSwYNFqNL3FMj+16g13nbZiIxrF7akI7N/P0uBP6 JHKRULgrRb/vYFqBtYTLvyLLXseWHp4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676019995; x=1707555995; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Gr+5ktwk+FAUTV+9ED5wsHL+1owhmcENlu36isQTlcE=; b=DKFgmhDByf00cvxpChvoeCLf27/lmyUwLqTbfbZ2+qebY/snLqfoNCqm DyapwJ7Yq9zAWyCZFA8vQUaVH1GGtWhsQ8GqMHcGe9b071/avLXd1b4Fz yVKQg0uHchCsOX9suSd6gz4izQZQx0n4OB4HruKOMxxE7P4FjJHq9o3/r 56Y2aON2tddl+CRnRwRRSsJ33LRTCxdl43zEnqIeSKuw/J+qnerpktgW7 S/wNGxH4FpPzBwyjWAg/T3URsxHj00+JXZlnwpUztKdSuByaR8lJhKHa+ Xi0mR6FJvhQeDsmy7nVxgb9InCXpBVTrggqsE+nf/V7rIJtihbTPas4UJ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="329003098" X-IronPort-AV: E=Sophos;i="5.97,286,1669104000"; d="scan'208";a="329003098" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2023 01:06:34 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="913463888" X-IronPort-AV: E=Sophos;i="5.97,286,1669104000"; d="scan'208";a="913463888" Received: from hrchavan-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.209.46.42]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2023 01:06:34 -0800 Subject: [PATCH v2 12/20] cxl/port: Split endpoint and switch port probe From: Dan Williams To: linux-cxl@vger.kernel.org Cc: Jonathan Cameron , vishal.l.verma@intel.com, dave.hansen@linux.intel.com, linux-mm@kvack.org, linux-acpi@vger.kernel.org Date: Fri, 10 Feb 2023 01:06:33 -0800 Message-ID: <167601999378.1924368.15071142145866277623.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <167601992097.1924368.18291887895351917895.stgit@dwillia2-xfh.jf.intel.com> References: <167601992097.1924368.18291887895351917895.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 X-Rspamd-Queue-Id: EBE0618001C X-Stat-Signature: hnzxj6wtm1ycofaf84y4af8fwwm4huqt X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1676019994-217366 X-HE-Meta: U2FsdGVkX195pxpqVrofbiSGaVS/OP4uxaj9EcWQky9A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5DDZSTIUmSYG5tDyNMyujej1gxqOxC7LT+vJgDt+y7Qn6wLsms5bj/l+GsVAvzCVkPE1sdGmepn4ky4gBl/QvHuz+w9JzQ2DGcIsRMwz5XZNY+0odJ2rQonFetZHu7T5utvI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Jonathan points out that the shared code between the switch and endpoint case is small. Before adding another is_cxl_endpoint() conditional, just split the two cases. Rather than duplicate the "Couldn't enumerate decoders" error message take the opportunity to improve the error messages in devm_cxl_enumerate_decoders(). Reported-by: Jonathan Cameron Link: http://lore.kernel.org/r/20230208170724.000067ec@Huawei.com Signed-off-by: Dan Williams Reviewed-by: Jonathan Cameron Reviewed-by: Vishal Verma --- drivers/cxl/core/hdm.c | 11 ++++++-- drivers/cxl/port.c | 69 +++++++++++++++++++++++++++--------------------- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index dcc16d7cb8f3..a0891c3464f1 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -826,7 +826,8 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm) cxled = cxl_endpoint_decoder_alloc(port); if (IS_ERR(cxled)) { dev_warn(&port->dev, - "Failed to allocate the decoder\n"); + "Failed to allocate decoder%d.%d\n", + port->id, i); return PTR_ERR(cxled); } cxld = &cxled->cxld; @@ -836,7 +837,8 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm) cxlsd = cxl_switch_decoder_alloc(port, target_count); if (IS_ERR(cxlsd)) { dev_warn(&port->dev, - "Failed to allocate the decoder\n"); + "Failed to allocate decoder%d.%d\n", + port->id, i); return PTR_ERR(cxlsd); } cxld = &cxlsd->cxld; @@ -844,13 +846,16 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm) rc = init_hdm_decoder(port, cxld, target_map, hdm, i, &dpa_base); if (rc) { + dev_warn(&port->dev, + "Failed to initialize decoder%d.%d\n", + port->id, i); put_device(&cxld->dev); return rc; } rc = add_hdm_decoder(port, cxld, target_map); if (rc) { dev_warn(&port->dev, - "Failed to add decoder to port\n"); + "Failed to add decoder%d.%d\n", port->id, i); return rc; } } diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index 5453771bf330..a8d46a67b45e 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -30,55 +30,64 @@ static void schedule_detach(void *cxlmd) schedule_cxl_memdev_detach(cxlmd); } -static int cxl_port_probe(struct device *dev) +static int cxl_switch_port_probe(struct cxl_port *port) { - struct cxl_port *port = to_cxl_port(dev); struct cxl_hdm *cxlhdm; int rc; + rc = devm_cxl_port_enumerate_dports(port); + if (rc < 0) + return rc; - if (!is_cxl_endpoint(port)) { - rc = devm_cxl_port_enumerate_dports(port); - if (rc < 0) - return rc; - if (rc == 1) - return devm_cxl_add_passthrough_decoder(port); - } + if (rc == 1) + return devm_cxl_add_passthrough_decoder(port); cxlhdm = devm_cxl_setup_hdm(port); if (IS_ERR(cxlhdm)) return PTR_ERR(cxlhdm); - if (is_cxl_endpoint(port)) { - struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport); - struct cxl_dev_state *cxlds = cxlmd->cxlds; + return devm_cxl_enumerate_decoders(cxlhdm); +} - /* Cache the data early to ensure is_visible() works */ - read_cdat_data(port); +static int cxl_endpoint_port_probe(struct cxl_port *port) +{ + struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_hdm *cxlhdm; + int rc; + + cxlhdm = devm_cxl_setup_hdm(port); + if (IS_ERR(cxlhdm)) + return PTR_ERR(cxlhdm); - get_device(&cxlmd->dev); - rc = devm_add_action_or_reset(dev, schedule_detach, cxlmd); - if (rc) - return rc; + /* Cache the data early to ensure is_visible() works */ + read_cdat_data(port); - rc = cxl_hdm_decode_init(cxlds, cxlhdm); - if (rc) - return rc; + get_device(&cxlmd->dev); + rc = devm_add_action_or_reset(&port->dev, schedule_detach, cxlmd); + if (rc) + return rc; - rc = cxl_await_media_ready(cxlds); - if (rc) { - dev_err(dev, "Media not active (%d)\n", rc); - return rc; - } - } + rc = cxl_hdm_decode_init(cxlds, cxlhdm); + if (rc) + return rc; - rc = devm_cxl_enumerate_decoders(cxlhdm); + rc = cxl_await_media_ready(cxlds); if (rc) { - dev_err(dev, "Couldn't enumerate decoders (%d)\n", rc); + dev_err(&port->dev, "Media not active (%d)\n", rc); return rc; } - return 0; + return devm_cxl_enumerate_decoders(cxlhdm); +} + +static int cxl_port_probe(struct device *dev) +{ + struct cxl_port *port = to_cxl_port(dev); + + if (is_cxl_endpoint(port)) + return cxl_endpoint_port_probe(port); + return cxl_switch_port_probe(port); } static ssize_t CDAT_read(struct file *filp, struct kobject *kobj,