From patchwork Tue Oct 10 19:46:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Harris X-Patchwork-Id: 13415942 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4A4332188 for ; Tue, 10 Oct 2023 19:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="m1D54o1C" Received: from mailout1.w2.samsung.com (mailout1.w2.samsung.com [211.189.100.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12FEC8E for ; Tue, 10 Oct 2023 12:46:56 -0700 (PDT) Received: from uscas1p2.samsung.com (unknown [182.198.245.207]) by mailout1.w2.samsung.com (KnoxPortal) with ESMTP id 20231010194652usoutp01ffc569c0b85556c65795bc457b42df6c~M1rBqGQOy0461504615usoutp015 for ; Tue, 10 Oct 2023 19:46:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w2.samsung.com 20231010194652usoutp01ffc569c0b85556c65795bc457b42df6c~M1rBqGQOy0461504615usoutp015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1696967212; bh=DKulgDOhqDGb2LvRUqQ4oXC0DPFqc7debbS8avsAYFE=; h=From:To:Subject:Date:References:From; b=m1D54o1CjHXJJc/2eceOpzBNU5Zo5QH8j8u1HQWULAsuKPvXZDNrY9vVEX/Xd8M1I ksCUG5ILfZLXBedwXVLStTfhhV8ADnVcROL6gLFGwcWZLUDnJcUMVFrh2FWTSArXGv 5q14dLSnN+f84Rl8cICwdxd+UnZzx8G0aKoXwQJg= Received: from ussmges3new.samsung.com (u112.gpu85.samsung.co.kr [203.254.195.112]) by uscas1p1.samsung.com (KnoxPortal) with ESMTP id 20231010194652uscas1p106d23afab737b076da6eb7ae43578e58~M1rBjnQV81430314303uscas1p1K for ; Tue, 10 Oct 2023 19:46:52 +0000 (GMT) Received: from uscas1p2.samsung.com ( [182.198.245.207]) by ussmges3new.samsung.com (USCPEMTA) with SMTP id BF.00.62237.C2AA5256; Tue, 10 Oct 2023 15:46:52 -0400 (EDT) Received: from ussmgxs3new.samsung.com (u92.gpu85.samsung.co.kr [203.254.195.92]) by uscas1p1.samsung.com (KnoxPortal) with ESMTP id 20231010194652uscas1p18968f3a66d8cbe6d76dd444aa3ec50aa~M1rBUbGkI2995229952uscas1p1R for ; Tue, 10 Oct 2023 19:46:52 +0000 (GMT) X-AuditID: cbfec370-b17ff7000001f31d-ee-6525aa2c0bf7 Received: from SSI-EX1.ssi.samsung.com ( [105.128.2.146]) by ussmgxs3new.samsung.com (USCPEXMTA) with SMTP id 14.79.31410.C2AA5256; Tue, 10 Oct 2023 15:46:52 -0400 (EDT) Received: from SSI-EX2.ssi.samsung.com (105.128.2.227) by SSI-EX1.ssi.samsung.com (105.128.2.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.2375.24; Tue, 10 Oct 2023 12:46:51 -0700 Received: from SSI-EX2.ssi.samsung.com ([105.128.2.227]) by SSI-EX2.ssi.samsung.com ([105.128.2.227]) with mapi id 15.01.2375.024; Tue, 10 Oct 2023 12:46:51 -0700 From: Jim Harris To: "linux-cxl@vger.kernel.org" Subject: [PATCH] cxl/region: Refactor logic around check_last_peer() Thread-Topic: [PATCH] cxl/region: Refactor logic around check_last_peer() Thread-Index: AQHZ+7KD8XRbpEWITUunMxlNnk7zRw== Date: Tue, 10 Oct 2023 19:46:51 +0000 Message-ID: <169696721124.1190606.18028412676865061799.stgit@bgt-140510-bm03.eng.stellus.in> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [105.128.2.176] Content-ID: Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrKIsWRmVeSWpSXmKPExsWy7djX87o6q1RTDXouqVmcn3WKxYHR4/Mm uQDGKC6blNSczLLUIn27BK6MOwsnMBackqvYMvUVYwPjE9kuRg4OCQETieZjUl2MXBxCAisZ JQ5u3MoE4Sxlkmjdv5Sxi5ETrOjInLNsEIm1jBJvvl1lgXA+MUocezKLBaRKSGAZo0TLIwkQ m01AU+LXlTVMILaIgLXEhIYlbCC2sICLxMX9O1gh4p4S/3+cgKrRk/jf+xNsG4uAqsSHQyuY QWxegRiJuzu2gMUZBcQkvp+CmMksIC5x68l8JojrBCUWzd7DDGGLSfzb9ZANwlaUuP/9JTvI m8xA96zfpQ/RaiexcPldFghbUWJK90N2iFWCEidnPmGBaJWUOLjiBtiPEgIv2SW2/t4MDQkX iU3XH7JC2NIS09dchmrIlli5voMJEqQFEg1HgiDC1hIL/6yHOplP4u+vR4wQJbwSHW1CExiV ZiF5ZhbCobOQHDoLyaGzkBy6gJF1FaN4aXFxbnpqsXFearlecWJucWleul5yfu4mRmDKOP3v cMEOxlu3PuodYmTiYDzEKMHBrCTC+yhTJVWINyWxsiq1KD++qDQntfgQozQHi5I4r6HtyWQh gfTEktTs1NSC1CKYLBMHp1QDU1WL7vqIIuamg54rIi++5kzfZGucrLru+MTSRw+OprE52aqf /nPi0cOLV4w2Td61eun5tqymdRW3qy6EzghQXiKhKbv15Mqve+3vxznbPbtQrL9lRrUPr/TK 82FT7BS3hFzZ0crA+yes7umKb5skZ/alJ/LyvUqsyF277qvhDt61P9+LL+XUM62/vPTN5Sb3 rxs4f5xfqh3zoeJtftCWb4x3De8+1ki/OnvW5qZ9niyTyjbu/9vpcjV7ydmSNsVNnaf8PqvX CKhcufDz/Bm9I5v/yGg6WpYINE5juPa2wnbRfJ/K8F+HLh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3ec50aa CMS-TYPE: 301P X-CMS-RootMailID: 20231010194652uscas1p18968f3a66d8cbe6d76dd444aa3ec50aa References: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS,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 'distance' is equivalent to the interleave_ways of the switch decoder of the port we are setting up in cxl_port_setup_targets(). We can also eliminate the special case for passthrough decoders (i.e. interleave_ways == 1) - check_last_peer() will just compare this endpoint's dport with the dport of the immediately preceding endpoint based on position. Signed-off-by: Jim Harris --- drivers/cxl/core/region.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 6d63b8798c29..0dc1c78772f1 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -1043,10 +1043,10 @@ static void cxl_port_detach_region(struct cxl_port *port, } static int check_last_peer(struct cxl_endpoint_decoder *cxled, - struct cxl_ep *ep, struct cxl_region_ref *cxl_rr, - int distance) + struct cxl_ep *ep, struct cxl_region_ref *cxl_rr) { struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); + int switch_iw = cxl_rr->decoder->interleave_ways; struct cxl_region *cxlr = cxl_rr->region; struct cxl_region_params *p = &cxlr->params; struct cxl_endpoint_decoder *cxled_peer; @@ -1057,16 +1057,16 @@ static int check_last_peer(struct cxl_endpoint_decoder *cxled, /* * If this position wants to share a dport with the last endpoint mapped - * then that endpoint, at index 'position - distance', must also be + * then that endpoint, at index 'position - switch_iw', must also be * mapped by this dport. */ - if (pos < distance) { + if (pos < switch_iw) { dev_dbg(&cxlr->dev, "%s:%s: cannot host %s:%s at %d\n", dev_name(port->uport_dev), dev_name(&port->dev), dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), pos); return -ENXIO; } - cxled_peer = p->targets[pos - distance]; + cxled_peer = p->targets[pos - switch_iw]; cxlmd_peer = cxled_to_memdev(cxled_peer); ep_peer = cxl_ep_load(port, cxlmd_peer); if (ep->dport != ep_peer->dport) { @@ -1111,20 +1111,17 @@ static int cxl_port_setup_targets(struct cxl_port *port, cxlsd = to_cxl_switch_decoder(&cxld->dev); if (cxl_rr->nr_targets_set) { - int i, distance; + int i; /* - * Passthrough decoders impose no distance requirements between - * peers + * Check if this endpoint's dport is already in the + * switch decoder's target list, and if so check that + * it is positioned correctly based on the switch's + * interleave. */ - if (cxl_rr->nr_targets == 1) - distance = 0; - else - distance = p->nr_targets / cxl_rr->nr_targets; for (i = 0; i < cxl_rr->nr_targets_set; i++) if (ep->dport == cxlsd->target[i]) { - rc = check_last_peer(cxled, ep, cxl_rr, - distance); + rc = check_last_peer(cxled, ep, cxl_rr); if (rc) return rc; goto out_target_set;