Linux CXL
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: <anisa.su887@gmail.com>
Cc: <qemu-devel@nongnu.org>, <nifan.cxl@gmail.com>,
	<dave@stgolabs.net>, <linux-cxl@vger.kernel.org>,
	Anisa Su <anisa.su@samsung.com>
Subject: Re: [PATCH 9/9] cxl-mailbox-utils: 0x5605 - FMAPI Initiate DC Release
Date: Thu, 24 Apr 2025 12:23:08 +0100	[thread overview]
Message-ID: <20250424122308.00004e8e@huawei.com> (raw)
In-Reply-To: <20250317164204.2299371-10-anisa.su887@gmail.com>

On Mon, 17 Mar 2025 16:31:36 +0000
anisa.su887@gmail.com wrote:

> From: Anisa Su <anisa.su@samsung.com>
> 
> FM DCD Managment command 0x5605 implemented per CXL r3.2 Spec Section 7.6.7.6.6
> 
> Signed-off-by: Anisa Su <anisa.su@samsung.com>
Similar comments to patch 8 around the double loop.

I'd also like Fan to take a look through these (v2 probably)
as he's messed with DCD a lot more than me!

Thanks,

Jonathan

> ---
>  hw/cxl/cxl-mailbox-utils.c | 94 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 94 insertions(+)
> 
> diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> index 5bcbd434b7..37810d892f 100644
> --- a/hw/cxl/cxl-mailbox-utils.c
> +++ b/hw/cxl/cxl-mailbox-utils.c
> @@ -128,6 +128,7 @@ enum {
>          #define SET_DC_REGION_CONFIG 0x2
>          #define GET_DC_REGION_EXTENT_LIST 0x3
>          #define INITIATE_DC_ADD           0x4
> +        #define INITIATE_DC_RELEASE       0x5
>  
>  };
>  
> @@ -3722,6 +3723,10 @@ static CXLRetCode cxl_mbox_dc_prescriptive_sanity_check(CXLType3Dev *dcd,
>                                                 ext.start_dpa, ext.len)) {
>                  return CXL_MBOX_INVALID_EXTENT_LIST;
>              }
> +        } else if (type == DC_EVENT_RELEASE_CAPACITY) {
> +            if (!ct3_test_region_block_backed(dcd, ext.start_dpa, ext.len)) {
> +                return CXL_MBOX_INVALID_PA;
> +            }
>          }
>      }
>  
> @@ -3835,6 +3840,88 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd,
>      return CXL_MBOX_SUCCESS;
>  }
>  
> +/*
> + * CXL r3.2 Section 7.6.7.6.6 Initiate Dynamic Capacity Release (Opcode 5605h)
> + */
> +static CXLRetCode cmd_fm_initiate_dc_release(const struct cxl_cmd *cmd,
> +                                             uint8_t *payload_in,
> +                                             size_t len_in,
> +                                             uint8_t *payload_out,
> +                                             size_t *len_out,
> +                                             CXLCCI *cci)
> +{
> +    struct {
> +        uint16_t host_id;
> +        uint8_t flags;
> +        uint8_t reg_num;
> +        uint64_t length;
> +        uint8_t tag[0x10];
> +        uint32_t ext_count;
> +        CXLDCExtentRaw extents[];
> +    } QEMU_PACKED *in = (void *)payload_in;
> +    CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
> +    g_autofree CXLDCExtentRaw *event_rec_exts = NULL;
> +    CXLEventDynamicCapacity event_rec = {};
> +    CXLDCExtentRaw ext;
> +    int i, rc = 0;

Prefer not to combine cases where you init and ones where you don't.
Just use 2 lines instead.

> +
> +    switch (in->flags & 0x7) {

That 7 needs a define.

> +    case CXL_EXTENT_REMOVAL_POLICY_PRESCRIPTIVE:
> +        rc = cxl_mbox_dc_prescriptive_sanity_check(ct3d,
> +                                                   in->host_id,
> +                                                   in->ext_count,
> +                                                   in->extents,
> +                                                   DC_EVENT_RELEASE_CAPACITY);
> +        if (rc) {
> +            return rc;
> +        }
> +
> +        /* Create extents for Event Record */
> +        event_rec_exts = g_new0(CXLDCExtentRaw, in->ext_count);
> +        for (i = 0; i < in->ext_count; i++) {
> +            ext = in->extents[i];
> +            event_rec_exts[i].start_dpa = ext.start_dpa;
> +            event_rec_exts[i].len = ext.len;
> +            memset(event_rec_exts[i].tag, 0, 0x10);
> +            event_rec_exts[i].shared_seq = 0;
> +        }

Similar to before. I'm not currently following the reason for the local
storage.

> +
> +        /* Create event record and insert to event log */
> +        cxl_mbox_dc_event_create_record_hdr(ct3d, &event_rec.hdr);
> +        event_rec.type = DC_EVENT_RELEASE_CAPACITY;
> +        /* FIXME: for now, validity flag is cleared */
> +        event_rec.validity_flags = 0;
> +        /* FIXME: Currently only support 1 host */
> +        event_rec.host_id = 0;
> +        /* updated_region_id only valid for DC_EVENT_REGION_CONFIG_UPDATED */
> +        event_rec.updated_region_id = 0;
> +        for (i = 0; i < in->ext_count; i++) {
> +            memcpy(&event_rec.dynamic_capacity_extent,
> +                   &event_rec_exts[i],
> +                   sizeof(CXLDCExtentRaw));
> +
> +            event_rec.flags = 0;
> +            if (i < in->ext_count - 1) {
> +                /* Set "More" flag */
> +                event_rec.flags |= BIT(0);
> +            }
> +
> +            if (cxl_event_insert(&ct3d->cxl_dstate,
> +                                 CXL_EVENT_TYPE_DYNAMIC_CAP,
> +                                 (CXLEventRecordRaw *)&event_rec)) {
> +                cxl_event_irq_assert(ct3d);
> +            }
> +        }
> +        return CXL_MBOX_SUCCESS;
> +    default:
> +        qemu_log_mask(LOG_UNIMP,
> +            "CXL extent selection policy not supported.\n");
> +        return CXL_MBOX_INVALID_INPUT;
> +    }
> +
> +    return CXL_MBOX_SUCCESS;
> +}
> +
>  static const struct cxl_cmd cxl_cmd_set[256][256] = {
>      [INFOSTAT][BACKGROUND_OPERATION_ABORT] = { "BACKGROUND_OPERATION_ABORT",
>          cmd_infostat_bg_op_abort, 0, 0 },
> @@ -3977,6 +4064,13 @@ static const struct cxl_cmd cxl_cmd_set_fm_dcd[256][256] = {
>          CXL_MBOX_CONFIG_CHANGE_CXL_RESET |
>          CXL_MBOX_IMMEDIATE_CONFIG_CHANGE |
>          CXL_MBOX_IMMEDIATE_DATA_CHANGE)},
> +    [FMAPI_DCD_MGMT][INITIATE_DC_RELEASE] = { "INIT_DC_RELEASE",
> +        cmd_fm_initiate_dc_release, ~0,
> +        (CXL_MBOX_CONFIG_CHANGE_COLD_RESET |
> +         CXL_MBOX_CONFIG_CHANGE_CONV_RESET |
> +         CXL_MBOX_CONFIG_CHANGE_CXL_RESET |
> +         CXL_MBOX_IMMEDIATE_CONFIG_CHANGE |
> +         CXL_MBOX_IMMEDIATE_DATA_CHANGE)},
>  };
>  
>  /*


  reply	other threads:[~2025-04-24 11:23 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-17 16:31 [PATCH 0/9] CXL: FMAPI DCD Management Commands 0x5600-0x5605 anisa.su887
2025-03-17 16:31 ` [PATCH 1/9] cxl/type3: Add supported block sizes bitmask to CXLDCRegion struct anisa.su887
2025-04-24 10:11   ` Jonathan Cameron
2025-04-29 17:56     ` Anisa Su
2025-03-17 16:31 ` [PATCH 2/9] cxl-mailbox-utils: 0x5600 - FMAPI Get DCD Info anisa.su887
2025-03-18 15:56   ` Jonathan Cameron
2025-03-31 19:38     ` Anisa Su
2025-04-24 10:21       ` Jonathan Cameron
2025-04-16 21:25     ` Anisa Su
2025-04-24 10:30   ` Jonathan Cameron
2025-03-17 16:31 ` [PATCH 3/9] cxl/type3: Add dsmas_flags to CXLDCRegion struct anisa.su887
2025-04-24 10:42   ` Jonathan Cameron
2025-05-01 20:21     ` Fan Ni
2025-05-02  9:01       ` Jonathan Cameron
2025-05-02 15:57         ` Fan Ni
2025-05-06 16:53           ` Jonathan Cameron
2025-03-17 16:31 ` [PATCH 4/9] cxl-mailbox-utils: 0x5601 - FMAPI Get Host Region Config anisa.su887
2025-04-24 10:53   ` Jonathan Cameron
2025-03-17 16:31 ` [PATCH 5/9] cxl_events.h: move definition for dynamic_capacity_uuid and enum for DC event types anisa.su887
2025-04-24 10:55   ` Jonathan Cameron
2025-03-17 16:31 ` [PATCH 6/9] cxl-mailbox-utils: 0x5602 - FMAPI Set DC Region Config anisa.su887
2025-04-16 21:33   ` Anisa Su
2025-04-24 11:05   ` Jonathan Cameron
2025-03-17 16:31 ` [PATCH 7/9] cxl-mailbox-utils: 0x5603 - FMAPI Get DC Region Extent Lists anisa.su887
2025-04-24 11:10   ` Jonathan Cameron
2025-03-17 16:31 ` [PATCH 8/9] cxl-mailbox-utils: 0x5604 - FMAPI Initiate DC Add anisa.su887
2025-04-24 11:19   ` Jonathan Cameron
2025-04-28 20:41     ` Fan Ni
2025-05-05 16:40     ` Anisa Su
2025-05-06 16:55       ` Jonathan Cameron
2025-03-17 16:31 ` [PATCH 9/9] cxl-mailbox-utils: 0x5605 - FMAPI Initiate DC Release anisa.su887
2025-04-24 11:23   ` Jonathan Cameron [this message]
2025-04-28 20:44     ` Fan Ni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250424122308.00004e8e@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=anisa.su887@gmail.com \
    --cc=anisa.su@samsung.com \
    --cc=dave@stgolabs.net \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nifan.cxl@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox