From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 DB2571DFEA for ; Mon, 26 Feb 2024 17:48:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969698; cv=none; b=Xs4+aA7ARrHSkuNaE6nE2AqFAEVyzCjWr45B0tXl1FI5KoVU8A7rHz8mjnVm732ApttHyOfs4bVehodiZLmItByDlaCrN9TD9Slei005gXPZJGplZiYIuV8s1daruQePQODmg20oHxO/8lEt55X6SLvvY/6sNcNFeU4E/VsMbmE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969698; c=relaxed/simple; bh=g9eY57cf1saotO5cJrEKwXKnbd7wFsdks7j9RfMfZgU=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QIhOILe/yaxiUNWjaHBcHVarO1l7Vugs5ndnJfuUvXg5jCyhuPpUXIKdcSENTolnMZkXE+TlkyOCenxfIq0RWNH9HZitrcV3LljX9dSA1VphEt2v2twpQ4aXjrZqCF6pe2p8+WOZmVdrxa2QjeeJ1iD9+FJvyUIsd4nhEq97R/U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Tk7Jn6YmVz6K6DN; Tue, 27 Feb 2024 01:43:53 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 27FB4140A35; Tue, 27 Feb 2024 01:48:13 +0800 (CST) Received: from localhost (10.202.227.76) 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.35; Mon, 26 Feb 2024 17:48:12 +0000 Date: Mon, 26 Feb 2024 17:48:11 +0000 From: Jonathan Cameron To: CC: , , , , , , , , , Fan Ni Subject: Re: [PATCH v4 07/10] hw/mem/cxl_type3: Add DC extent list representative and get DC extent list mailbox support Message-ID: <20240226174811.00001549@Huawei.com> In-Reply-To: <20240221182020.1086096-8-nifan.cxl@gmail.com> References: <20240221182020.1086096-1-nifan.cxl@gmail.com> <20240221182020.1086096-8-nifan.cxl@gmail.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml500004.china.huawei.com (7.191.163.9) To lhrpeml500005.china.huawei.com (7.191.163.240) On Wed, 21 Feb 2024 10:16:00 -0800 nifan.cxl@gmail.com wrote: > From: Fan Ni > > Add dynamic capacity extent list representative to the definition of > CXLType3Dev and add get DC extent list mailbox command per > CXL.spec.3.1:.8.2.9.9.9.2. > > Signed-off-by: Fan Ni Follow on from earlier comment on my preference for anonymous structure types when we only use them in one place. > +/* > + * CXL r3.1 section 8.2.9.9.9.2: > + * Get Dynamic Capacity Extent List (Opcode 4801h) > + */ > +static CXLRetCode cmd_dcd_get_dyn_cap_ext_list(const struct cxl_cmd *cmd, > + uint8_t *payload_in, > + size_t len_in, > + uint8_t *payload_out, > + size_t *len_out, > + CXLCCI *cci) > +{ > + CXLType3Dev *ct3d = CXL_TYPE3(cci->d); > + struct get_dyn_cap_ext_list_in_pl { > + uint32_t extent_cnt; > + uint32_t start_extent_id; > + } QEMU_PACKED; > + > + struct get_dyn_cap_ext_list_out_pl { > + uint32_t count; > + uint32_t total_extents; > + uint32_t generation_num; > + uint8_t rsvd[4]; > + CXLDCExtentRaw records[]; > + } QEMU_PACKED; > + > + struct get_dyn_cap_ext_list_in_pl *in = (void *)payload_in; > + struct get_dyn_cap_ext_list_out_pl *out = (void *)payload_out; As for earlier patches, I think anonymous struct types are fine for these and lead to shorter code. > + uint16_t record_count = 0, i = 0, record_done = 0; > + CXLDCExtentList *extent_list = &ct3d->dc.extents; > + CXLDCExtent *ent; > + uint16_t out_pl_len; > + uint32_t start_extent_id = in->start_extent_id; > + > + if (start_extent_id > ct3d->dc.total_extent_count) { > + return CXL_MBOX_INVALID_INPUT; > + } > + > + record_count = MIN(in->extent_cnt, > + ct3d->dc.total_extent_count - start_extent_id); > + > + out_pl_len = sizeof(*out) + record_count * sizeof(out->records[0]); > + assert(out_pl_len <= CXL_MAILBOX_MAX_PAYLOAD_SIZE); > + > + stl_le_p(&out->count, record_count); > + stl_le_p(&out->total_extents, ct3d->dc.total_extent_count); > + stl_le_p(&out->generation_num, ct3d->dc.ext_list_gen_seq); > + > + if (record_count > 0) { > + QTAILQ_FOREACH(ent, extent_list, node) { > + if (i++ < start_extent_id) { > + continue; > + } > + stq_le_p(&out->records[record_done].start_dpa, ent->start_dpa); > + stq_le_p(&out->records[record_done].len, ent->len); > + memcpy(&out->records[record_done].tag, ent->tag, 0x10); > + stw_le_p(&out->records[record_done].shared_seq, ent->shared_seq); > + record_done++; > + if (record_done == record_count) { > + break; > + } > + } > + } > + > + *len_out = out_pl_len; > + return CXL_MBOX_SUCCESS; > +} > +