All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: <dave.jiang@intel.com>, <dan.j.williams@intel.com>,
	<alison.schofield@intel.com>, <vishal.l.verma@intel.com>,
	<ira.weiny@intel.com>, <jgroves@micron.com>,
	<ravis.opensrc@micron.com>, <fan.ni@samsung.com>,
	<anisa.su@samsung.com>, <a.manzanares@samsung.com>,
	<linux-cxl@vger.kernel.org>
Subject: Re: [PATCH 1/7] cxl/mbox: Track background commands from CEL
Date: Mon, 23 Jun 2025 15:16:32 +0100	[thread overview]
Message-ID: <20250623151632.000070d4@huawei.com> (raw)
In-Reply-To: <20250617193611.564668-2-dave@stgolabs.net>

On Tue, 17 Jun 2025 12:36:05 -0700
Davidlohr Bueso <dave@stgolabs.net> wrote:

> Remember whether or not a command is background-capable, per the CEL.
> This will later be used to consult the bitmap to evaluate incoming
> mbox commands.
> 
> Further, "enable" any background commands that didn't fall in the
> uapi, poison or security categories, such as fw related. This prevents
> situations where the command is incorrectly listed as unsupported by
> the driver.
> 
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
> ---
>  drivers/cxl/core/mbox.c | 30 ++++++++++++++++++++++++++++++
>  drivers/cxl/cxlmem.h    | 28 ++++++++++++++++++++++++++++
>  2 files changed, 58 insertions(+)
> 
> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
> index 2689e6453c5a..4ea02f7a5b6b 100644
> --- a/drivers/cxl/core/mbox.c
> +++ b/drivers/cxl/core/mbox.c
> @@ -202,6 +202,31 @@ static void cxl_set_poison_cmd_enabled(struct cxl_poison_state *poison,
>  	}
>  }
>  
> +static bool cxl_set_bgcmd_enabled(struct cxl_background_state *bg, u16 opcode)
> +{
> +	switch (opcode) {
> +	case CXL_MBOX_OP_TRANSFER_FW:
> +		set_bit(CXL_BG_ENABLED_TRANSFER_FW, bg->enabled_cmds);
> +		break;
> +	case CXL_MBOX_OP_ACTIVATE_FW:
> +		set_bit(CXL_BG_ENABLED_ACTIVATE_FW, bg->enabled_cmds);
> +		break;
> +	case CXL_MBOX_OP_DO_MAINTENANCE:
> +		set_bit(CXL_BG_ENABLED_DO_MAINTENANCE, bg->enabled_cmds);
> +		break;
> +	case CXL_MBOX_OP_SCAN_MEDIA:
> +		set_bit(CXL_BG_ENABLED_SCAN_MEDIA, bg->enabled_cmds);
> +		break;
> +	case CXL_MBOX_OP_SANITIZE:
> +		set_bit(CXL_BG_ENABLED_SANITIZE, bg->enabled_cmds);
> +		break;
> +	default:
> +		return false;
> +	}
> +
> +	return true;
> +}
> +
>  static struct cxl_mem_command *cxl_mem_find_command(u16 opcode)
>  {
>  	struct cxl_mem_command *c;
> @@ -757,6 +782,7 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
>  
>  	for (i = 0; i < cel_entries; i++) {
>  		u16 opcode = le16_to_cpu(cel_entry[i].opcode);
> +		u16 effect = le16_to_cpu(cel_entry[i].effect);
>  		struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);
>  		int enabled = 0;
>  
> @@ -778,6 +804,10 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
>  			enabled++;
>  		}
>  
> +		if (effect & CXL_CEL_BACKGROUND_OPERATION)
> +			if (cxl_set_bgcmd_enabled(&mds->bg, opcode))
> +				enabled++; /* might be redundant */

I suspect we'll forget in the long run what 'redundant' means here.
Perhaps make it more explicit.
/* May already have been detected as enabled */

The whole incrementing of enabled pattern hides that we don't really care
about transitions other than 0->1.  Maybe we should consider making it
a bool and using
enabled |= check_features_opcode() a few lines above this.



> +
>  		dev_dbg(dev, "Opcode 0x%04x %s\n", opcode,
>  			enabled ? "enabled" : "unsupported by driver");
>  	}
> diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
> index 551b0ba2caa1..5c7fd4a6704c 100644
> --- a/drivers/cxl/cxlmem.h
> +++ b/drivers/cxl/cxlmem.h
> @@ -248,6 +248,16 @@ enum security_cmd_enabled_bits {
>  	CXL_SEC_ENABLED_MAX
>  };
>  
> +/* Device enabled background commands */

What does 'Device enabled' refer to? Perhaps reword.

> +enum background_cmd_enabled_bits {
> +	CXL_BG_ENABLED_TRANSFER_FW,
> +	CXL_BG_ENABLED_ACTIVATE_FW,
> +	CXL_BG_ENABLED_DO_MAINTENANCE,
> +	CXL_BG_ENABLED_SCAN_MEDIA,
> +	CXL_BG_ENABLED_SANITIZE,
> +	CXL_BG_ENABLED_MAX
> +};
> +
>  /**
>   * struct cxl_poison_state - Driver poison state info
>   *
> @@ -365,6 +375,16 @@ struct cxl_security_state {
>  	struct kernfs_node *sanitize_node;
>  };
>  
> +/**
> + * struct cxl_background_state - Driver background operation state info
> + *
> + * @enabled_cmds: All background commands enabled in the CEL
> + */
> +struct cxl_background_state {
> +	DECLARE_BITMAP(enabled_cmds, CXL_BG_ENABLED_MAX);
> +};
> +
> +
>  /*
>   * enum cxl_devtype - delineate type-2 from a generic type-3 device
>   * @CXL_DEVTYPE_DEVMEM - Vendor specific CXL Type-2 device implementing HDM-D or
> @@ -484,6 +504,7 @@ static inline struct cxl_dev_state *mbox_to_cxlds(struct cxl_mailbox *cxl_mbox)
>   * @poison: poison driver state info
>   * @security: security driver state info
>   * @fw: firmware upload / activation state
> + * @bg: background operation state
>   * @mce_notifier: MCE notifier
>   *
>   * See CXL 3.0 8.2.9.8.2 Capacity Configuration and Label Storage for
> @@ -504,6 +525,7 @@ struct cxl_memdev_state {
>  	struct cxl_poison_state poison;
>  	struct cxl_security_state security;
>  	struct cxl_fw_state fw;
> +	struct cxl_background_state bg;
>  	struct notifier_block mce_notifier;
>  };
>  
> @@ -580,6 +602,12 @@ struct cxl_mbox_get_supported_logs {
>  	} __packed entry[];
>  }  __packed;
>  
> +/*
> + * Command Effects Log (CEL)
> + * CXL 3.2 Section 8.2.10.5.2.1; Table 8-87
> + */
> +#define CXL_CEL_BACKGROUND_OPERATION BIT(6)
> +
>  struct cxl_cel_entry {
>  	__le16 opcode;
>  	__le16 effect;


  reply	other threads:[~2025-06-23 14:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17 19:36 [PATCH 0/7] cxl: Activate FW and userspace bgcmds Davidlohr Bueso
2025-06-17 19:36 ` [PATCH 1/7] cxl/mbox: Track background commands from CEL Davidlohr Bueso
2025-06-23 14:16   ` Jonathan Cameron [this message]
2025-06-23 16:19     ` Davidlohr Bueso
2025-06-17 19:36 ` [PATCH 2/7] cxl/mbox: Handle Activate FW as async bg Davidlohr Bueso
2025-06-23 14:22   ` Jonathan Cameron
2025-06-17 19:36 ` [PATCH 3/7] cxl/pci: Lockless background synchronous polling Davidlohr Bueso
2025-06-23 14:29   ` Jonathan Cameron
2025-06-23 16:23     ` Davidlohr Bueso
2025-06-17 19:36 ` [PATCH 4/7] cxl/mbox: Stronger cxl_mbox_background_complete() semantics Davidlohr Bueso
2025-06-23 14:31   ` Jonathan Cameron
2025-06-17 19:36 ` [PATCH 5/7] cxl/mbox: Allow userspace background commands Davidlohr Bueso
2025-06-23 14:49   ` Jonathan Cameron
2025-06-17 19:36 ` [PATCH 6/7] cxl/mbox: Shout upon async bgcmd race Davidlohr Bueso
2025-06-23 14:50   ` Jonathan Cameron
2025-06-23 16:14     ` Davidlohr Bueso
2025-06-17 21:52 ` [PATCH 0/7] cxl: Activate FW and userspace bgcmds Davidlohr Bueso
2025-06-17 22:15 ` [PATCH 7/7] cxl/mbox: Add Populate Log support Davidlohr Bueso
2025-06-23 14:51   ` 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=20250623151632.000070d4@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=a.manzanares@samsung.com \
    --cc=alison.schofield@intel.com \
    --cc=anisa.su@samsung.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=fan.ni@samsung.com \
    --cc=ira.weiny@intel.com \
    --cc=jgroves@micron.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=ravis.opensrc@micron.com \
    --cc=vishal.l.verma@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.