From nobody Sun Nov 24 22:33:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1720181360; cv=none; d=zohomail.com; s=zohoarc; b=fwinCSeCLFo+fshd999Km8JkzomLEdKkSwkMl5jNlFzx2+Lo9DwRVlhAnfigXoC8rEjEcTrlOMKVRoK1DlAB3sR2eSHvnStv6OuXVbIUYN3/0VmPxGVagbBV0JAO2qcudG1sWyBw6RC6HFnrWow3vS9zY2TVcCAcky4dhyklZG0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720181360; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=mgrNqjikIIy2FVvhmxwUg6+tem+dmEU4Ld1bjow5nHU=; b=K23UIJPnrwhm+PU48SiES6I8z7voomkPbsCQiuxBbrKDLm+r5zkh1PdM0HRWnw+1XkY16fhSY5JZ+NO91Td2+xHmIU49C5RCy5vE5FCgIiYJ5vqd/MKMWphW4gKKdK/62BjAH4zMxKtgHsjjnAf9Jf/Sbs1HOn56f6vrbojpbGk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172018135980812.910754798848984; Fri, 5 Jul 2024 05:09:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPhkD-0000w9-2y; Fri, 05 Jul 2024 08:08:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sPhkA-0000sy-Rk for qemu-devel@nongnu.org; Fri, 05 Jul 2024 08:08:50 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sPhk8-0003tu-AI for qemu-devel@nongnu.org; Fri, 05 Jul 2024 08:08:50 -0400 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WFsjG3Xxzz6HJcc; Fri, 5 Jul 2024 20:08:02 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id A694A140A30; Fri, 5 Jul 2024 20:08:46 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.19.247) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 5 Jul 2024 13:08:46 +0100 To: , , CC: Davidlohr Bueso , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Fan Ni Subject: [PATCH 4/4] hw/cxl: Add get scan media results cmd support Date: Fri, 5 Jul 2024 13:06:43 +0100 Message-ID: <20240705120643.959422-5-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240705120643.959422-1-Jonathan.Cameron@huawei.com> References: <20240705120643.959422-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.19.247] X-ClientProxiedBy: lhrpeml100002.china.huawei.com (7.191.160.241) To lhrpeml500005.china.huawei.com (7.191.163.240) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1720181361588100002 Content-Type: text/plain; charset="utf-8" From: Davidlohr Bueso Iterate over the list keeping the output payload size into account, returning the results from a previous scan media operation. The scan media operation does not fail prematurely due to device being out of storage, so this implementation does not deal with the retry/restart functionality. Signed-off-by: Davidlohr Bueso Link: https://lore.kernel.org/r/20230908073152.4386-5-dave@stgolabs.net Signed-off-by: Jonathan Cameron --- Tweak - update references to point to CXL r3.1 given lack of easy availability of r3.0. --- include/hw/cxl/cxl_device.h | 1 + hw/cxl/cxl-mailbox-utils.c | 85 +++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 0509d961c3..cc98553583 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -499,6 +499,7 @@ struct CXLType3Dev { /* Poison Injection - backup */ CXLPoisonList poison_list_bkp; CXLPoisonList scan_media_results; + bool scan_media_hasrun; =20 struct dynamic_capacity { HostMemoryBackend *host_dc; diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index e3d3575b02..e87089474a 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -85,6 +85,7 @@ enum { #define CLEAR_POISON 0x2 #define GET_SCAN_MEDIA_CAPABILITIES 0x3 #define SCAN_MEDIA 0x4 + #define GET_SCAN_MEDIA_RESULTS 0x5 DCD_CONFIG =3D 0x48, #define GET_DC_CONFIG 0x0 #define GET_DYN_CAP_EXT_LIST 0x1 @@ -1346,6 +1347,8 @@ static void __do_scan_media(CXLType3Dev *ct3d) ct3d->poison_list_cnt =3D=3D results_cnt) { cxl_clear_poison_list_overflowed(ct3d); } + /* scan media has run since last conventional reset */ + ct3d->scan_media_hasrun =3D true; } =20 /* @@ -1450,6 +1453,85 @@ static CXLRetCode cmd_media_scan_media(const struct = cxl_cmd *cmd, return CXL_MBOX_BG_STARTED; } =20 +/* + * CXL r3.1 section 8.2.9.9.4.6: Get Scan Media Results + */ +static CXLRetCode cmd_media_get_scan_media_results(const struct cxl_cmd *c= md, + uint8_t *payload_in, + size_t len_in, + uint8_t *payload_out, + size_t *len_out, + CXLCCI *cci) +{ + struct get_scan_media_results_out_pl { + uint64_t dpa_restart; + uint64_t length; + uint8_t flags; + uint8_t rsvd1; + uint16_t count; + uint8_t rsvd2[0xc]; + struct { + uint64_t addr; + uint32_t length; + uint32_t resv; + } QEMU_PACKED records[]; + } QEMU_PACKED; + + struct get_scan_media_results_out_pl *out =3D (void *)payload_out; + CXLType3Dev *ct3d =3D CXL_TYPE3(cci->d); + CXLPoisonList *scan_media_results =3D &ct3d->scan_media_results; + CXLPoison *ent, *next; + uint16_t total_count =3D 0, record_count =3D 0, i =3D 0; + uint16_t out_pl_len; + + if (!ct3d->scan_media_hasrun) { + return CXL_MBOX_UNSUPPORTED; + } + + /* + * Calculate limits, all entries are within the same address range of = the + * last scan media call. + */ + QLIST_FOREACH(ent, scan_media_results, node) { + size_t rec_size =3D record_count * sizeof(out->records[0]); + + if (sizeof(*out) + rec_size < CXL_MAILBOX_MAX_PAYLOAD_SIZE) { + record_count++; + } + total_count++; + } + + out_pl_len =3D sizeof(*out) + record_count * sizeof(out->records[0]); + assert(out_pl_len <=3D CXL_MAILBOX_MAX_PAYLOAD_SIZE); + + memset(out, 0, out_pl_len); + QLIST_FOREACH_SAFE(ent, scan_media_results, node, next) { + uint64_t start, stop; + + if (i =3D=3D record_count) { + break; + } + + start =3D ROUND_DOWN(ent->start, 64ull); + stop =3D ROUND_DOWN(ent->start, 64ull) + ent->length; + stq_le_p(&out->records[i].addr, start | (ent->type & 0x7)); + stl_le_p(&out->records[i].length, (stop - start) / CXL_CACHE_LINE_= SIZE); + i++; + + /* consume the returning entry */ + QLIST_REMOVE(ent, node); + g_free(ent); + } + + stw_le_p(&out->count, record_count); + if (total_count > record_count) { + out->flags =3D (1 << 0); /* More Media Error Records */ + } + + *len_out =3D out_pl_len; + return CXL_MBOX_SUCCESS; +} + /* * CXL r3.1 section 8.2.9.9.9.1: Get Dynamic Capacity Configuration * (Opcode: 4800h) @@ -2067,6 +2149,9 @@ static const struct cxl_cmd cxl_cmd_set[256][256] =3D= { cmd_media_get_scan_media_capabilities, 16, 0 }, [MEDIA_AND_POISON][SCAN_MEDIA] =3D { "MEDIA_AND_POISON_SCAN_MEDIA", cmd_media_scan_media, 17, BACKGROUND_OPERATION }, + [MEDIA_AND_POISON][GET_SCAN_MEDIA_RESULTS] =3D { + "MEDIA_AND_POISON_GET_SCAN_MEDIA_RESULTS", + cmd_media_get_scan_media_results, 0, 0 }, }; =20 static const struct cxl_cmd cxl_cmd_set_dcd[256][256] =3D { --=20 2.43.0