From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Fan Ni <nifan.cxl@gmail.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>, <dan.j.williams@intel.com>,
<a.manzanares@samsung.com>, <linux-cxl@vger.kernel.org>
Subject: Re: [PATCH 2/3] cxl: Support Get/Set Shutdown State commands
Date: Mon, 23 Dec 2024 19:57:10 +0000 [thread overview]
Message-ID: <20241223195710.00006676@huawei.com> (raw)
In-Reply-To: <Z2cUmMEh433UjgKm@gpd>
On Sat, 21 Dec 2024 11:18:48 -0800
Fan Ni <nifan.cxl@gmail.com> wrote:
> On Fri, Dec 20, 2024 at 08:00:25AM -0800, Davidlohr Bueso wrote:
> > As per the latest spec, add mailbox commands 4203h and 4204h.
> > While upon reboot this operation is obviously a nop (flag is
> > cleared but the dirty shutdown count is not increased), it
> > can still serve to test some basic paths.
> >
> > Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
>
> ...
>
> > ---
> > hw/cxl/cxl-mailbox-utils.c | 49 +++++++++++++++++++++++++++++++++++++
> > include/hw/cxl/cxl_device.h | 2 ++
> > 2 files changed, 51 insertions(+)
> >
> > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> > index f6f993e7bc4f..ff1d3f50610c 100644
> > --- a/hw/cxl/cxl-mailbox-utils.c
> > +++ b/hw/cxl/cxl-mailbox-utils.c
> > @@ -86,6 +86,9 @@ enum {
> > #define GET_PARTITION_INFO 0x0
> > #define GET_LSA 0x2
> > #define SET_LSA 0x3
> > + HEALTH_INFO_ALERTS = 0x42,
> > + #define GET_SHUTDOWN_STATE 0x3
> > + #define SET_SHUTDOWN_STATE 0x4
> > MEDIA_AND_POISON = 0x43,
> > #define GET_POISON_LIST 0x0
> > #define INJECT_POISON 0x1
> > @@ -1721,6 +1724,48 @@ static CXLRetCode cmd_sanitize_overwrite(const struct cxl_cmd *cmd,
> > return CXL_MBOX_BG_STARTED;
> > }
> >
> > +/* CXL r3.2 Section 8.2.10.9.3.4: Get Shutdown State (Opcode 4203h) */
> > +static CXLRetCode cmd_health_get_shutdown_state(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);
> > + CXLDeviceState *cxl_dstate = &ct3d->cxl_dstate;
> > + struct get_shutdown_state_pl {
> > + uint8_t state;
> > + } QEMU_PACKED;
> > + struct get_shutdown_state_pl *out = (void *)payload_out;
> > +
> > + out->state = cxl_dstate->shutdown_state;
> > + *len_out = sizeof(out);
> > +
> > + return CXL_MBOX_SUCCESS;
> > +}
> > +
> > +/* CXL r3.2 Section 8.2.10.9.3.5: Set Shutdown State (Opcode 4204h) */
> > +static CXLRetCode cmd_health_set_shutdown_state(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);
> > + CXLDeviceState *cxl_dstate = &ct3d->cxl_dstate;
> > + struct set_shutdown_state_pl {
> > + uint8_t state;
> > + } QEMU_PACKED;
> > + struct set_shutdown_state_pl *in = (void *)payload_in;
>
> Do we need to check the input size and return invalid input payload
> size?
Not for fixed size commands. See check in cxl_process_cci_message.
It's the variable sized commands that trip us up and need explicit
checks.
>
> > +
> > + cxl_dstate->shutdown_state = in->state;
> > + *len_out = 0;
> > +
> > + return CXL_MBOX_SUCCESS;
> > +}
> > +
> > static CXLRetCode cmd_get_security_state(const struct cxl_cmd *cmd,
> > uint8_t *payload_in,
> > size_t len_in,
> > @@ -2866,6 +2911,10 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
> > CXL_MBOX_BACKGROUND_OPERATION_ABORT)},
> > [PERSISTENT_MEM][GET_SECURITY_STATE] = { "GET_SECURITY_STATE",
> > cmd_get_security_state, 0, 0 },
> > + [HEALTH_INFO_ALERTS][GET_SHUTDOWN_STATE] = { "HEALTH_INFO_ALERTS_GET_SHUTDOWN_STATE",
> > + cmd_health_get_shutdown_state, 0, 0 },
> > + [HEALTH_INFO_ALERTS][SET_SHUTDOWN_STATE] = { "HEALTH_INFO_ALERTS_SET_SHUTDOWN_STATE",
> > + cmd_health_set_shutdown_state, 1, 0 },
>
> Per the spec, I think the return value should be CXL_MBOX_IMMEDIATE_POLICY_CHANGE.
>
> Fan
> > [MEDIA_AND_POISON][GET_POISON_LIST] = { "MEDIA_AND_POISON_GET_POISON_LIST",
> > cmd_media_get_poison_list, 16, 0 },
> > [MEDIA_AND_POISON][INJECT_POISON] = { "MEDIA_AND_POISON_INJECT_POISON",
> > diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
> > index a64739be25e9..69e6330fe66d 100644
> > --- a/include/hw/cxl/cxl_device.h
> > +++ b/include/hw/cxl/cxl_device.h
> > @@ -292,6 +292,8 @@ typedef struct cxl_device_state {
> > CPMUState cpmu[CXL_NUM_CPMU_INSTANCES];
> > CHMUState chmu[1];
> > CXLEventLog event_logs[CXL_EVENT_TYPE_MAX];
> > +
> > + uint8_t shutdown_state;
> > } CXLDeviceState;
> >
> > /* Initialize the register block for a device */
> > --
> > 2.39.5
> >
next prev parent reply other threads:[~2024-12-23 19:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 16:00 [PATCH -qemu 0/3] hw/cxl: Support dirty shutdown Davidlohr Bueso
2024-12-20 16:00 ` [PATCH 1/3] cxl: Fix mbox cmd enum order Davidlohr Bueso
2024-12-21 19:05 ` Fan Ni
2024-12-20 16:00 ` [PATCH 2/3] cxl: Support Get/Set Shutdown State commands Davidlohr Bueso
2024-12-21 19:18 ` Fan Ni
2024-12-23 19:57 ` Jonathan Cameron [this message]
2024-12-23 20:01 ` Jonathan Cameron
2024-12-20 16:00 ` [PATCH 3/3] cxl/type3: Add 'dirty-shutdown' parameter Davidlohr Bueso
2024-12-23 20:08 ` Jonathan Cameron
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=20241223195710.00006676@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=a.manzanares@samsung.com \
--cc=dan.j.williams@intel.com \
--cc=dave@stgolabs.net \
--cc=linux-cxl@vger.kernel.org \
--cc=nifan.cxl@gmail.com \
/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