cxl: Pull out mailbox bits to be independent of cxl_dev_state
Dave Jiang
maintainerv4 cover cxl: Pull out mailbox bits to be independent of cxl_dev_state
Hi Alejandro,
Please feel free to pull in the patches in this series into your type2 series. Although I may just pull these into the 6.12 merge window to make things easier for you.
The patches pulls out the related mailbox bits and form a 'struct cxl_mailbox'. In v2 Jonathan suggested that we keep cxl_mbox embedded. So I moved it back to be embedded. For the type2 devices that does not use mailbox, it can just not have the mailbox struct at all.
v3
- moved the other cxl headers into the linux/cxl directory.
- Moved rcuwait.h header into mailbox.h (Alison)
v4
- Move headers to include/cxl (Dan)
- Move header moving patch to 1/3 (Dan)
- Fix cxl_mailbox_init input param check. (Alison)
---
Dave Jiang (3):
cxl: move cxl headers to new linux/cxl/ directory
cxl: Move mailbox related bits to the same context
cxl: Convert cxl_internal_send_cmd() to use 'struct cxl_mailbox' as input
MAINTAINERS | 3 +-
drivers/acpi/apei/einj-cxl.c | 2 +-
drivers/acpi/apei/ghes.c | 2 +-
drivers/cxl/core/mbox.c | 91 ++++++++++++++++++++++++++++++++------------------
drivers/cxl/core/memdev.c | 41 +++++++++++++----------
drivers/cxl/core/port.c | 2 +-
drivers/cxl/cxlmem.h | 25 ++++++--------
drivers/cxl/pci.c | 82 ++++++++++++++++++++++++++++++---------------
drivers/cxl/pmem.c | 10 ++++--
drivers/cxl/security.c | 23 +++++++------
include/{linux/einj-cxl.h => cxl/einj.h} | 0
include/{linux/cxl-event.h => cxl/event.h} | 0
include/cxl/mailbox.h | 28 ++++++++++++++++
tools/testing/cxl/test/mem.c | 44 ++++++++++++++++++------
14 files changed, 233 insertions(+), 120 deletions(-)Dave Jiang
maintainerPATCH v4 1/3 cxl: move cxl headers to new include/cxl/ directory
Group all cxl related kernel headers into include/cxl/ directory.
---
v4:
- Move to 1/3 (Dan)
- Move to include/cxl/ (Dan)
---
MAINTAINERS | 3 +--
drivers/acpi/apei/einj-cxl.c | 2 +-
drivers/acpi/apei/ghes.c | 2 +-
drivers/cxl/core/port.c | 2 +-
drivers/cxl/cxlmem.h | 2 +-
include/{linux/einj-cxl.h => cxl/einj.h} | 0
include/{linux/cxl-event.h => cxl/event.h} | 0
7 files changed, 5 insertions(+), 6 deletions(-)
rename include/{linux/einj-cxl.h => cxl/einj.h} (100%)
rename include/{linux/cxl-event.h => cxl/event.h} (100%)MAINTAINERS +1 -2
@@ -5620,8 +5620,7 @@ L: [email protected] S: Maintained F: Documentation/driver-api/cxl F: drivers/cxl/ -F: include/linux/einj-cxl.h -F: include/linux/cxl-event.h +F: include/cxl/ F: include/uapi/linux/cxl_mem.h F: tools/testing/cxl/
drivers/acpi/apei/einj-cxl.c +1 -1
@@ -7,9 +7,9 @@* * Author: Ben Cheatham <[email protected]> */ -#include <linux/einj-cxl.h> #include <linux/seq_file.h> #include <linux/pci.h> +#include <cxl/einj.h> #include "apei-internal.h"
drivers/acpi/apei/ghes.c +1 -1
@@ -27,7 +27,6 @@#include <linux/timer.h> #include <linux/cper.h> #include <linux/cleanup.h> -#include <linux/cxl-event.h> #include <linux/platform_device.h> #include <linux/mutex.h> #include <linux/ratelimit.h>
@@ -50,6 +49,7 @@#include <acpi/apei.h> #include <asm/fixmap.h> #include <asm/tlbflush.h> +#include <cxl/event.h> #include <ras/ras_event.h> #include "apei-internal.h"
drivers/cxl/core/port.c +1 -1
@@ -3,7 +3,6 @@#include <linux/platform_device.h> #include <linux/memregion.h> #include <linux/workqueue.h> -#include <linux/einj-cxl.h> #include <linux/debugfs.h> #include <linux/device.h> #include <linux/module.h>
@@ -11,6 +10,7 @@#include <linux/slab.h> #include <linux/idr.h> #include <linux/node.h> +#include <cxl/einj.h> #include <cxlmem.h> #include <cxlpci.h> #include <cxl.h>
drivers/cxl/cxlmem.h +1 -1
@@ -6,8 +6,8 @@#include <linux/cdev.h> #include <linux/uuid.h> #include <linux/rcuwait.h> -#include <linux/cxl-event.h> #include <linux/node.h> +#include <cxl/event.h> #include "cxl.h" /* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */
include/cxl/einj.h renamed from include/linux/einj-cxl.h +0 -0
include/cxl/event.h renamed from include/linux/cxl-event.h +0 -0
Signature · 1 line
2.46.0
Re: [PATCH v4 1/3] cxl: move cxl headers to new include/cxl/ directory
Quoted 1 line · Dave Jiang
Group all cxl related kernel headers into
include/cxl/directory.
Applied set to rc6 and LGTM!
Quoted 7 lines
Signed-off-by Dave Jiang <[email protected]>---
v4:
- Move to 1/3 (Dan)
- Move toinclude/cxl/(Dan)
---
snip
Quoted 1 line
Re: [PATCH v4 1/3] cxl: move cxl headers to new include/cxl/ directory
In reply to Dave JiangQuoted 3 lines · Dave Jiang
Group all cxl related kernel headers into
include/cxl/directory.Signed-off-by Dave Jiang <[email protected]>
[snip]
Re: [PATCH v4 1/3] cxl: move cxl headers to new include/cxl/ directory
In reply to Dave JiangQuoted 3 lines · On Thu, 5 Sep 2024 15:35:45 -0700 Dave Jiang <[email protected]> wrote:
Group all cxl related kernel headers into
include/cxl/directory.Signed-off-by Dave Jiang <[email protected]>
Dave Jiang
maintainerPATCH v4 2/3 cxl: Move mailbox related bits to the same context
In reply to Dave JiangCreate a new 'struct cxl_mailbox' and move all mailbox related bits to it. This allows isolation of all CXL mailbox data in order to export some of the calls to external kernel callers and avoid exporting of CXL driver specific bits such has device states. The allocation of 'struct cxl_mailbox' is also split out with cxl_mailbox_create() so the mailbox can be created independently.
---
v4:
- cxl_mbox could be NULL in cxl_mailbox_init. (Alison)
- rework after headers moves
--- drivers/cxl/core/mbox.c | 57 +++++++++++++++++++-------- drivers/cxl/core/memdev.c | 18 +++++---- drivers/cxl/cxlmem.h | 21 +++++----- drivers/cxl/pci.c | 76 ++++++++++++++++++++++++------------ drivers/cxl/pmem.c | 4 +- include/cxl/mailbox.h | 28 +++++++++++++ tools/testing/cxl/test/mem.c | 44 +++++++++++++++------ 7 files changed, 176 insertions(+), 72 deletions(-) create mode 100644 include/cxl/mailbox.h
drivers/cxl/core/mbox.c +41 -16
@@ -244,16 +244,17 @@ static const char *cxl_mem_opcode_to_name(u16 opcode)int cxl_internal_send_cmd (struct cxl_memdev_state *mds,struct cxl_mbox_cmd *mbox_cmd) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;size_t out_size, min_out;int rc; -if (mbox_cmd->size_in > mds->payload_size || - mbox_cmd->size_out > mds->payload_size) +if (mbox_cmd->size_in > cxl_mbox->payload_size || + mbox_cmd->size_out > cxl_mbox->payload_size)return -E2BIG ; out_size = mbox_cmd->size_out; min_out = mbox_cmd->min_out; - rc = mds->mbox_send (mds, mbox_cmd); + rc = cxl_mbox->mbox_send (cxl_mbox, mbox_cmd);/* * EIO is reserved for a payload size mismatch and mbox_send() * may not return this error.
@@ -353,6 +354,7 @@ static int cxl_mbox_cmd_ctor(struct cxl_mbox_cmd *mbox, struct cxl_memdev_state *mds, u16 opcode, size_t in_size, size_t out_size, u64 in_payload) { + struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; *mbox = (struct cxl_mbox_cmd) { .opcode = opcode, .size_in = in_size,
@@ -374,7 +376,7 @@ static int cxl_mbox_cmd_ctor(struct cxl_mbox_cmd *mbox,/* Prepare to handle a full payload for variable sized output */ if (out_size ==CXL_VARIABLE_PAYLOAD ) - mbox->size_out = mds->payload_size; + mbox->size_out = cxl_mbox->payload_size;else mbox->size_out = out_size;
@@ -398,6 +400,8 @@ static int cxl_to_mem_cmd_raw(struct cxl_mem_command *mem_cmd,const struct cxl_send_command *send_cmd, struct cxl_memdev_state *mds) { + struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +if (send_cmd->raw.rsvd)return -EINVAL ;
@@ -406,7 +410,7 @@ static int cxl_to_mem_cmd_raw(struct cxl_mem_command *mem_cmd,* gets passed along without further checking, so it must be * validated here. */ -if (send_cmd->out.size > mds->payload_size) +if (send_cmd->out.size > cxl_mbox->payload_size)return -EINVAL ;if (!cxl_mem_raw_command_allowed (send_cmd->raw.opcode))
@@ -494,6 +498,7 @@ static int cxl_validate_cmd_from_user(struct cxl_mbox_cmd *mbox_cmd,struct cxl_memdev_state *mds, const struct cxl_send_command *send_cmd) { + struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mem_command mem_cmd;int rc;
@@ -505,7 +510,7 @@ static int cxl_validate_cmd_from_user(struct cxl_mbox_cmd *mbox_cmd,* supports, but output can be arbitrarily large (simply write out as * much data as the hardware provides). */ -if (send_cmd->in.size > mds->payload_size) +if (send_cmd->in.size > cxl_mbox->payload_size)return -EINVAL ;/* Sanitize and construct a cxl_mem_command */
@@ -591,6 +596,7 @@ static int handle_mailbox_cmd_from_user(struct cxl_memdev_state *mds, u64 out_payload, s32 *size_out, u32 *retval) { + struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct device *dev = mds->cxlds.dev;int rc;
@@ -601,7 +607,7 @@ static int handle_mailbox_cmd_from_user(struct cxl_memdev_state *mds,cxl_mem_opcode_to_name (mbox_cmd->opcode), mbox_cmd->opcode, mbox_cmd->size_in); - rc = mds->mbox_send (mds, mbox_cmd); + rc = cxl_mbox->mbox_send (cxl_mbox, mbox_cmd);if (rc) goto out;
@@ -659,11 +665,12 @@ int cxl_send_cmd(struct cxl_memdev *cxlmd, struct cxl_send_command __user *s)static int cxl_xfer_log (struct cxl_memdev_state *mds,uuid_t *uuid,u32 *size,u8 *out) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;u32 remaining = *size;u32 offset =0 ;while (remaining) { -u32 xfer_size =min_t (u32, remaining, mds->payload_size); +u32 xfer_size =min_t (u32, remaining, cxl_mbox->payload_size);struct cxl_mbox_cmd mbox_cmd;struct cxl_mbox_get_log log;int rc;
@@ -752,17 +759,18 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)static struct cxl_mbox_get_supported_logs *cxl_get_gsl (struct cxl_memdev_state *mds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_get_supported_logs *ret;struct cxl_mbox_cmd mbox_cmd;int rc; - ret =kvmalloc (mds->payload_size,GFP_KERNEL ); + ret =kvmalloc (cxl_mbox->payload_size,GFP_KERNEL );if (!ret)return ERR_PTR (-ENOMEM ); mbox_cmd = (struct cxl_mbox_cmd ) { .opcode =CXL_MBOX_OP_GET_SUPPORTED_LOGS , - .size_out = mds->payload_size, + .size_out = cxl_mbox->payload_size, .payload_out = ret,/* At least the record number field must be valid */ .min_out =2 ,
@@ -910,6 +918,7 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,enum cxl_event_log_type log, struct cxl_get_event_payload *get_pl) { + struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_clear_event_payload *payload;u16 total =le16_to_cpu (get_pl->record_count);u8 max_handles =CXL_CLEAR_EVENT_MAX_HANDLES ;
@@ -920,8 +929,8 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,int i;/* Payload size may limit the max handles */ -if (pl_size > mds->payload_size) { - max_handles = (mds->payload_size -sizeof (*payload)) / +if (pl_size > cxl_mbox->payload_size) { + max_handles = (cxl_mbox->payload_size -sizeof (*payload)) /sizeof (__le16); pl_size =struct_size (payload, handles, max_handles); }
@@ -979,6 +988,7 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,static void cxl_mem_get_records_log (struct cxl_memdev_state *mds,enum cxl_event_log_type type) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_memdev *cxlmd = mds->cxlds.cxlmd;struct device *dev = mds->cxlds.dev;struct cxl_get_event_payload *payload;
@@ -995,7 +1005,7 @@ static void cxl_mem_get_records_log(struct cxl_memdev_state *mds, .payload_in = &log_type, .size_in = sizeof(log_type), .payload_out = payload, - .size_out = mds->payload_size, + .size_out = cxl_mbox->payload_size, .min_out = struct_size(payload, records, 0), };
@@ -1328,6 +1338,7 @@ int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, struct cxl_region *cxlr) {struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_poison_out *po;struct cxl_mbox_poison_in pi;int nr_records =0 ;
@@ -1346,7 +1357,7 @@ int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, .opcode = CXL_MBOX_OP_GET_POISON, .size_in = sizeof(pi), .payload_in = &pi, - .size_out = mds->payload_size, + .size_out = cxl_mbox->payload_size, .payload_out = po, .min_out = struct_size(po, record, 0), };
@@ -1382,7 +1393,9 @@ static void free_poison_buf(void *buf)/* Get Poison List output buffer is protected by mds->poison.lock */ static int cxl_poison_alloc_buf (struct cxl_memdev_state *mds) { - mds->poison.list_out =kvmalloc (mds->payload_size,GFP_KERNEL ); +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; + + mds->poison.list_out =kvmalloc (cxl_mbox->payload_size,GFP_KERNEL );if (!mds->poison.list_out)return -ENOMEM ;
@@ -1408,6 +1421,19 @@ int cxl_poison_state_init(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_poison_state_init,CXL ); +int cxl_mailbox_init (struct cxl_mailbox *cxl_mbox,struct device *host) +{ +if (!cxl_mbox || !host) +return -EINVAL ; + + cxl_mbox->host = host; +mutex_init (&cxl_mbox->mbox_mutex); +rcuwait_init (&cxl_mbox->mbox_wait); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (cxl_mailbox_init,CXL ); +struct cxl_memdev_state *cxl_memdev_state_create (struct device *dev) {struct cxl_memdev_state *mds;
@@ -1418,7 +1444,6 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev)return ERR_PTR (-ENOMEM ); } -mutex_init (&mds->mbox_mutex);mutex_init (&mds->event.log_lock); mds->cxlds.dev = dev; mds->cxlds.reg_map.host = dev;
drivers/cxl/core/memdev.c +11 -7
@@ -58,7 +58,7 @@ static ssize_t payload_max_show(struct device *dev,if (!mds)return sysfs_emit (buf,"\n" ); -return sysfs_emit (buf,"%zu\n" , mds->payload_size); +return sysfs_emit (buf,"%zu\n" , cxlds->cxl_mbox.payload_size); }static DEVICE_ATTR_RO (payload_max);
@@ -124,15 +124,16 @@ static ssize_t security_state_show(struct device *dev, {struct cxl_memdev *cxlmd =to_cxl_memdev (dev);struct cxl_dev_state *cxlds = cxlmd->cxlds; +struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox;struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlds);unsigned long state = mds->security.state;int rc =0 ;/* sync with latest submission state */ -mutex_lock (&mds->mbox_mutex); +mutex_lock (&cxl_mbox->mbox_mutex);if (mds->security.sanitize_active) rc =sysfs_emit (buf,"sanitize\n" ); -mutex_unlock (&mds->mbox_mutex); +mutex_unlock (&cxl_mbox->mbox_mutex);if (rc)return rc;
@@ -829,12 +830,13 @@ static enum fw_upload_err cxl_fw_prepare(struct fw_upload *fwl, const u8 *data, {struct cxl_memdev_state *mds = fwl->dd_handle;struct cxl_mbox_transfer_fw *transfer; +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;if (!size)return FW_UPLOAD_ERR_INVALID_SIZE ; mds->fw.oneshot =struct_size (transfer, data, size) < - mds->payload_size; + cxl_mbox->payload_size;if (cxl_mem_get_fw_info (mds))return FW_UPLOAD_ERR_HW_ERROR ;
@@ -854,6 +856,7 @@ static enum fw_upload_err cxl_fw_write(struct fw_upload *fwl, const u8 *data, {struct cxl_memdev_state *mds = fwl->dd_handle;struct cxl_dev_state *cxlds = &mds->cxlds; +struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox;struct cxl_memdev *cxlmd = cxlds->cxlmd;struct cxl_mbox_transfer_fw *transfer;struct cxl_mbox_cmd mbox_cmd;
@@ -877,7 +880,7 @@ static enum fw_upload_err cxl_fw_write(struct fw_upload *fwl, const u8 *data,* sizeof(*transfer) is 128. These constraints imply that @cur_size * will always be 128b aligned. */ - cur_size =min_t (size_t, size, mds->payload_size -sizeof (*transfer)); + cur_size =min_t (size_t, size, cxl_mbox->payload_size -sizeof (*transfer)); remaining = size - cur_size; size_in =struct_size (transfer, data, cur_size);
@@ -1059,16 +1062,17 @@ EXPORT_SYMBOL_NS_GPL(devm_cxl_add_memdev, CXL);static void sanitize_teardown_notifier (void *data) {struct cxl_memdev_state *mds = data; +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct kernfs_node *state;/* * Prevent new irq triggered invocations of the workqueue and * flush inflight invocations. */ -mutex_lock (&mds->mbox_mutex); +mutex_lock (&cxl_mbox->mbox_mutex); state = mds->security.sanitize_node; mds->security.sanitize_node =NULL ; -mutex_unlock (&mds->mbox_mutex); +mutex_unlock (&cxl_mbox->mbox_mutex);cancel_delayed_work_sync (&mds->security.poll_dwork);sysfs_put (state);
drivers/cxl/cxlmem.h +9 -12
@@ -3,11 +3,12 @@#ifndef __CXL_MEM_H__#define __CXL_MEM_H__#include <uapi/linux/cxl_mem.h> +#include <linux/pci.h> #include <linux/cdev.h> #include <linux/uuid.h> -#include <linux/rcuwait.h> #include <linux/node.h> #include <cxl/event.h> +#include <cxl/mailbox.h> #include "cxl.h" /* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */
@@ -424,6 +425,7 @@ struct cxl_dpa_perf {* @ram_res: Active Volatile memory capacity configuration * @serial: PCIe Device Serial Number * @type: Generic Memory Class device or Vendor Specific Memory device +* @cxl_mbox: CXL mailbox context */ struct cxl_dev_state {struct device *dev;
@@ -438,8 +440,14 @@ struct cxl_dev_state {struct resource ram_res;u64 serial;enum cxl_devtype type; +struct cxl_mailbox cxl_mbox; }; +static inline struct cxl_dev_state *mbox_to_cxlds (struct cxl_mailbox *cxl_mbox) +{ +return dev_get_drvdata (cxl_mbox->host); +} +/** * struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data *
@@ -448,11 +456,8 @@ struct cxl_dev_state {* the functionality related to that like Identify Memory Device and Get * Partition Info * @cxlds: Core driver state common across Type-2 and Type-3 devices -* @payload_size: Size of space for payload -* (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register) * @lsa_size: Size of Label Storage Area * (CXL 2.0 8.2.9.5.1.1 Identify Memory Device) -* @mbox_mutex: Mutex to synchronize mailbox access. * @firmware_version: Firmware version for the memory device. * @enabled_cmds: Hardware commands found enabled in CEL. * @exclusive_cmds: Commands that are kernel-internal only
@@ -470,17 +475,13 @@ struct cxl_dev_state {* @poison: poison driver state info * @security: security driver state info * @fw: firmware upload / activation state -* @mbox_wait: RCU wait for mbox send completely -* @mbox_send: @dev specific transport for transmitting mailbox commands * * See CXL 3.0 8.2.9.8.2 Capacity Configuration and Label Storage for * details on capacity parameters. */ struct cxl_memdev_state {struct cxl_dev_state cxlds; -size_t payload_size;size_t lsa_size; -struct mutex mbox_mutex;/* Protects device mailbox and firmware */ char firmware_version[0x10 ]; DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX); DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX);
@@ -500,10 +501,6 @@ struct cxl_memdev_state {struct cxl_poison_state poison;struct cxl_security_state security;struct cxl_fw_state fw; - -struct rcuwait mbox_wait; -int (*mbox_send)(struct cxl_memdev_state *mds, -struct cxl_mbox_cmd *cmd); }; static inline struct cxl_memdev_state *
drivers/cxl/pci.c +51 -25
190 lines not on this page · raw message
drivers/cxl/pmem.c +3 -1
@@ -102,13 +102,15 @@ static int cxl_pmem_get_config_size(struct cxl_memdev_state *mds, struct nd_cmd_get_config_size *cmd, unsigned int buf_len) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +if (sizeof (*cmd) > buf_len)return -EINVAL ; *cmd = (struct nd_cmd_get_config_size ){ .config_size = mds->lsa_size, .max_xfer = - mds->payload_size -sizeof (struct cxl_mbox_set_lsa ), + cxl_mbox->payload_size -sizeof (struct cxl_mbox_set_lsa ), };return 0 ;
include/cxl/mailbox.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2024 Intel Corporation. */ +#ifndef __CXL_MBOX_H__ +#define __CXL_MBOX_H__ +#include <linux/rcuwait.h> + +struct cxl_mbox_cmd ; + +/** +* struct cxl_mailbox - context for CXL mailbox operations +* @host: device that hosts the mailbox +* @payload_size: Size of space for payload +* (CXL 3.1 8.2.8.4.3 Mailbox Capabilities Register) +* @mbox_mutex: mutex protects device mailbox and firmware +* @mbox_wait: rcuwait for mailbox +* @mbox_send: @dev specific transport for transmitting mailbox commands +*/ +struct cxl_mailbox { +struct device *host; +size_t payload_size; +struct mutex mbox_mutex;/* lock to protect mailbox context */ +struct rcuwait mbox_wait; +int (*mbox_send)(struct cxl_mailbox *cxl_mbox,struct cxl_mbox_cmd *cmd); +}; + +int cxl_mailbox_init (struct cxl_mailbox *cxl_mbox,struct device *host); + +#endif
tools/testing/cxl/test/mem.c +33 -11
121 lines not on this page · raw message
Signature · 1 line
2.46.0
Re: [PATCH v4 2/3] cxl: Move mailbox related bits to the same context
Quoted 5 lines · Dave Jiang
Create a new 'struct
cxl_mailbox' and move all mailbox related bits to it. This allows isolation of all CXL mailbox data in order to export some of the calls to external kernel callers and avoid exporting of CXL driver specific bits such has device states. The allocation of 'structcxl_mailbox' is also split out withcxl_mailbox_create()so the
cxl_mailbox_init()?
Quoted 23 lines
mailbox can be created independently.
Reviewed-by Fan Ni <[email protected]>Reviewed-by Alejandro Lucero <[email protected]>Reviewed-by Alison Schofield <[email protected]>Signed-off-by Dave Jiang <[email protected]>---
v4:
-cxl_mboxcould be NULL incxl_mailbox_init. (Alison)
- rework after headers moves--- drivers/cxl/core/mbox.c | 57 +++++++++++++++++++-------- drivers/cxl/core/memdev.c | 18 +++++---- drivers/cxl/cxlmem.h | 21 +++++----- drivers/cxl/pci.c | 76 ++++++++++++++++++++++++------------ drivers/cxl/pmem.c | 4 +- include/cxl/mailbox.h | 28 +++++++++++++ tools/testing/cxl/test/mem.c | 44 +++++++++++++++------ 7 files changed, 176 insertions(+), 72 deletions(-) create mode 100644 include/cxl/mailbox.h
[snip]
drivers/cxl/core/mbox.c int cxl_poison_state_init(struct cxl_memdev_state *mds) · line 1431
Quoted 9 lines
drivers/cxl/core/mbox.c +8
-0+int cxl_mailbox_init (struct cxl_mailbox *cxl_mbox,struct device *host) +{ +if (!cxl_mbox || !host) +return -EINVAL ; + + cxl_mbox->host = host; +mutex_init (&cxl_mbox->mbox_mutex); +rcuwait_init (&cxl_mbox->mbox_wait);
I would have expected a few more things in here from cxl_pci_setup_mailbox(). For example is irq setup needed? Perhaps deferred for now?
Quoted 16 lines
drivers/cxl/core/mbox.c +5
-1+ +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (cxl_mailbox_init,CXL ); +struct cxl_memdev_state *cxl_memdev_state_create (struct device *dev) {struct cxl_memdev_state *mds;@@ -1418,7 +1444,6 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev)return ERR_PTR (-ENOMEM ); } -mutex_init (&mds->mbox_mutex);mutex_init (&mds->event.log_lock); mds->cxlds.dev = dev; mds->cxlds.reg_map.host = dev;
[snip]
drivers/cxl/pci.c static int cxl_event_config(struct pci_host_bridge *host_bridge, · line 802
Quoted 10 lines
drivers/cxl/pci.c +9
-0+static int cxl_pci_type3_init_mailbox (struct cxl_dev_state *cxlds) +{ +int rc; + +/* +* Fail the init if there's no mailbox. For a type3 this is out of spec. +*/ +if (!cxlds->reg_map.device_map.mbox.valid) +return -ENODEV ;
This seems like new functionality. I don't think it is wrong but it was not checked before right? If I missed the check are we not checking 2x?
Quoted 12 lines
drivers/cxl/pci.c +8
-0+ + rc =cxl_mailbox_init (&cxlds->cxl_mbox, cxlds->dev); +if (rc) +return rc; + +return 0 ; +} +static int cxl_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) {struct pci_host_bridge *host_bridge =pci_find_host_bridge (pdev->bus);
drivers/cxl/pci.c static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 874
Quoted 7 lines
drivers/cxl/pci.c +4
-0@@ -846,6 +868,10 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (rc)dev_dbg (&pdev->dev,"Failed to map RAS capability.\n" ); + rc =cxl_pci_type3_init_mailbox (cxlds); +if (rc) +return rc; +
I feel like this should be just before cxl_pci_setup_mailbox() after alloc irq. Because we are removing some of the setup from cxl_pci_setup_mailbox() and putting it into cxl_pci_type3_init_mailbox() it just flows better in my mind. I don't think there is a requirement to put it there though.
Ira
[snip]
Dave Jiang
maintainerRe: [PATCH v4 2/3] cxl: Move mailbox related bits to the same context
Quoted 8 lines · Ira Weiny
Quoted 5 lines · Dave Jiang
Create a new 'struct
cxl_mailbox' and move all mailbox related bits to it. This allows isolation of all CXL mailbox data in order to export some of the calls to external kernel callers and avoid exporting of CXL driver specific bits such has device states. The allocation of 'structcxl_mailbox' is also split out withcxl_mailbox_create()so thecxl_mailbox_init()?
Yes. Thanks. Leftover from previously.
Quoted 28 lines
Quoted 24 lines
mailbox can be created independently.
Reviewed-by Fan Ni <[email protected]>Reviewed-by Alejandro Lucero <[email protected]>Reviewed-by Alison Schofield <[email protected]>Signed-off-by Dave Jiang <[email protected]>---
v4:
-cxl_mboxcould be NULL incxl_mailbox_init. (Alison)
- rework after headers moves--- drivers/cxl/core/mbox.c | 57 +++++++++++++++++++-------- drivers/cxl/core/memdev.c | 18 +++++---- drivers/cxl/cxlmem.h | 21 +++++----- drivers/cxl/pci.c | 76 ++++++++++++++++++++++++------------ drivers/cxl/pmem.c | 4 +- include/cxl/mailbox.h | 28 +++++++++++++ tools/testing/cxl/test/mem.c | 44 +++++++++++++++------ 7 files changed, 176 insertions(+), 72 deletions(-) create mode 100644 include/cxl/mailbox.h[snip]
Quoted 1 line
Quoted 12 lines
drivers/cxl/core/mbox.c int cxl_poison_state_init(struct cxl_memdev_state *mds) · line 1431
Quoted 8 lines
drivers/cxl/core/mbox.c +8
-0+int cxl_mailbox_init (struct cxl_mailbox *cxl_mbox,struct device *host) +{ +if (!cxl_mbox || !host) +return -EINVAL ; + + cxl_mbox->host = host; +mutex_init (&cxl_mbox->mbox_mutex); +rcuwait_init (&cxl_mbox->mbox_wait);I would have expected a few more things in here from
cxl_pci_setup_mailbox(). For example is irq setup needed? Perhaps deferred for now?
I split out the initialization of data structures and the setup of the hardware. We can further deal with that as things become more clearer what a type2 device that wants a mailbox would look like.
Quoted 21 lines
Quoted 17 lines
drivers/cxl/core/mbox.c +5
-1+ +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (cxl_mailbox_init,CXL ); +struct cxl_memdev_state *cxl_memdev_state_create (struct device *dev) {struct cxl_memdev_state *mds;@@ -1418,7 +1444,6 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev)return ERR_PTR (-ENOMEM ); } -mutex_init (&mds->mbox_mutex);mutex_init (&mds->event.log_lock); mds->cxlds.dev = dev; mds->cxlds.reg_map.host = dev;[snip]
Quoted 1 line
Quoted 12 lines
drivers/cxl/pci.c static int cxl_event_config(struct pci_host_bridge *host_bridge, · line 802
Quoted 9 lines
drivers/cxl/pci.c +9
-0+static int cxl_pci_type3_init_mailbox (struct cxl_dev_state *cxlds) +{ +int rc; + +/* +* Fail the init if there's no mailbox. For a type3 this is out of spec. +*/ +if (!cxlds->reg_map.device_map.mbox.valid) +return -ENODEV ;This seems like new functionality. I don't think it is wrong but it was not checked before right? If I missed the check are we not checking 2x?
Yes this is a new check. Previous code assumed that we never fail when it comes to mailboxes. I'm adding this to fail if mailbox isn't discovered as this is not in compliance with the spec.
Quoted 16 lines
Quoted 16 lines
drivers/cxl/pci.c +8
-0+ + rc =cxl_mailbox_init (&cxlds->cxl_mbox, cxlds->dev); +if (rc) +return rc; + +return 0 ; +} +static int cxl_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) {struct pci_host_bridge *host_bridge =pci_find_host_bridge (pdev->bus);@@ -846,6 +868,10 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (rc)dev_dbg (&pdev->dev,"Failed to map RAS capability.\n" );
Quoted 10 lines
drivers/cxl/pci.c static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 874
Quoted 4 lines
drivers/cxl/pci.c +4
-0+ rc =cxl_pci_type3_init_mailbox (cxlds); +if (rc) +return rc; +I feel like this should be just before
cxl_pci_setup_mailbox()after alloc irq. Because we are removing some of the setup fromcxl_pci_setup_mailbox()and putting it intocxl_pci_type3_init_mailbox()it just flows better in my mind. I don't think there is a requirement to put it there though.
I think I had it running earlier to hit that check in case a mailbox did not exist so we can just bail without doing all the additional work. At least that was my thought process.
Quoted 4 lines
Ira
[snip]
Ira Weiny
Reviewed-byRe: [PATCH v4 2/3] cxl: Move mailbox related bits to the same context
Quoted 10 lines · Dave Jiang
Quoted 7 lines · Ira Weiny
Quoted 5 lines · Dave Jiang
Create a new 'struct
cxl_mailbox' and move all mailbox related bits to it. This allows isolation of all CXL mailbox data in order to export some of the calls to external kernel callers and avoid exporting of CXL driver specific bits such has device states. The allocation of 'structcxl_mailbox' is also split out withcxl_mailbox_create()so the
Quoted 3 lines
Quoted 1 line
cxl_mailbox_init()?Yes. Thanks. Leftover from previously.
Ok with this change.
[snip]
Re: [PATCH v4 2/3] cxl: Move mailbox related bits to the same context
In reply to Dave JiangQuoted 7 lines · On Thu, 5 Sep 2024 15:35:46 -0700 Dave Jiang <[email protected]> wrote:
Create a new 'struct
cxl_mailbox' and move all mailbox related bits to it. This allows isolation of all CXL mailbox data in order to export some of the calls to external kernel callers and avoid exporting of CXL driver specific bits such has device states. The allocation of 'structcxl_mailbox' is also split out withcxl_mailbox_create()so the mailbox can be created independently.
Quoted 5 lines
Reviewed-by Fan Ni <[email protected]>Reviewed-by Alejandro Lucero <[email protected]>Reviewed-by Alison Schofield <[email protected]>Signed-off-by Dave Jiang <[email protected]>
LGTM.
Note this is currently being carried in Shiju's RAS features set as well. What is the merge plan? My preference is an immutable branch that Borislav could pull into the EDAC tree and on which we can base other stuff in CXL
That is a branch based on 6.12-rc1 directly with an appropriate tag that Shiju's patch set can refer to.
Thanks,
Jonathan
Alison Schofield
maintainerRe: [PATCH v4 2/3] cxl: Move mailbox related bits to the same context
Quoted 17 lines · Jonathan Cameron
Quoted 7 lines · On Thu, 5 Sep 2024 15:35:46 -0700 Dave Jiang <[email protected]> wrote:
Create a new 'struct
cxl_mailbox' and move all mailbox related bits to it. This allows isolation of all CXL mailbox data in order to export some of the calls to external kernel callers and avoid exporting of CXL driver specific bits such has device states. The allocation of 'structcxl_mailbox' is also split out withcxl_mailbox_create()so the mailbox can be created independently.Quoted 5 lines
Reviewed-by Fan Ni <[email protected]>Reviewed-by Alejandro Lucero <[email protected]>Reviewed-by Alison Schofield <[email protected]>Signed-off-by Dave Jiang <[email protected]>LGTM.
Quoted 8 lines
Reviewed-by Jonathan Cameron <[email protected]>Note this is currently being carried in Shiju's RAS features set as well. What is the merge plan? My preference is an immutable branch that Borislav could pull into the EDAC tree and on which we can base other stuff in CXL
That is a branch based on 6.12-rc1 directly with an appropriate tag that Shiju's patch set can refer to.
This set was merged in 6.12.
Quoted 4 lines
Thanks,
Jonathan
Re: [PATCH v4 2/3] cxl: Move mailbox related bits to the same context
Quoted 28 lines · On Mon, 14 Oct 2024 11:36:31 -0700 Alison Schofield…
Quoted 17 lines · Jonathan Cameron
Quoted 7 lines · On Thu, 5 Sep 2024 15:35:46 -0700 Dave Jiang <[email protected]> wrote:
Create a new 'struct
cxl_mailbox' and move all mailbox related bits to it. This allows isolation of all CXL mailbox data in order to export some of the calls to external kernel callers and avoid exporting of CXL driver specific bits such has device states. The allocation of 'structcxl_mailbox' is also split out withcxl_mailbox_create()so the mailbox can be created independently.Quoted 5 lines
Reviewed-by Fan Ni <[email protected]>Reviewed-by Alejandro Lucero <[email protected]>Reviewed-by Alison Schofield <[email protected]>Signed-off-by Dave Jiang <[email protected]>LGTM.
Quoted 8 lines
Reviewed-by Jonathan Cameron <[email protected]>Note this is currently being carried in Shiju's RAS features set as well. What is the merge plan? My preference is an immutable branch that Borislav could pull into the EDAC tree and on which we can base other stuff in CXL
That is a branch based on 6.12-rc1 directly with an appropriate tag that Shiju's patch set can refer to.
Quoted 1 line
This set was merged in 6.12.
Ah. Shiju, seems you have an old base. Fix that for next version of the RAS features
Quoted 7 lines
Quoted 5 lines
Thanks,
Jonathan
Dave Jiang
maintainerPATCH v4 3/3 cxl: Convert cxl_internal_send_cmd() to use 'struct cxl_mailbox' as input
In reply to Dave JiangWith the CXL mailbox context split out, cxl_internal_send_cmd() can take 'struct cxl_mailbox' as an input parameter rather than 'struct memdev_dev_state'. Change input parameter for cxl_internal_send_cmd() and fixup all impacted call sites.
--- drivers/cxl/core/mbox.c | 38 ++++++++++++++++++++------------------ drivers/cxl/core/memdev.c | 23 +++++++++++++---------- drivers/cxl/cxlmem.h | 2 +- drivers/cxl/pci.c | 6 ++++-- drivers/cxl/pmem.c | 6 ++++-- drivers/cxl/security.c | 23 ++++++++++++----------- 6 files changed, 54 insertions(+), 44 deletions(-)
drivers/cxl/core/mbox.c +20 -18
@@ -225,7 +225,7 @@ static const char *cxl_mem_opcode_to_name(u16 opcode)/** * cxl_internal_send_cmd() - Kernel internal interface to send a mailbox command -* @mds: The driver data for the operation +* @cxl_mbox: CXL mailbox context * @mbox_cmd: initialized command to execute * * Context: Any context.
@@ -241,10 +241,9 @@ static const char *cxl_mem_opcode_to_name(u16 opcode)* error. While this distinction can be useful for commands from userspace, the * kernel will only be able to use results when both are successful. */ -int cxl_internal_send_cmd (struct cxl_memdev_state *mds, +int cxl_internal_send_cmd (struct cxl_mailbox *cxl_mbox,struct cxl_mbox_cmd *mbox_cmd) { -struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;size_t out_size, min_out;int rc;
@@ -689,7 +688,7 @@ static int cxl_xfer_log(struct cxl_memdev_state *mds, uuid_t *uuid, .payload_out = out, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);/* * The output payload length that indicates the number
@@ -775,7 +774,7 @@ static struct cxl_mbox_get_supported_logs *cxl_get_gsl(struct cxl_memdev_state */* At least the record number field must be valid */ .min_out = 2, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 ) {kvfree (ret);return ERR_PTR (rc);
@@ -964,7 +963,7 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,if (i == max_handles) { payload->nr_recs = i; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc) goto free_pl; i =0 ;
@@ -975,7 +974,7 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,if (i) { payload->nr_recs = i; mbox_cmd.size_in =struct_size (payload, handles, i); - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc) goto free_pl; }
@@ -1009,7 +1008,7 @@ static void cxl_mem_get_records_log(struct cxl_memdev_state *mds, .min_out = struct_size(payload, records, 0), }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc) { dev_err_ratelimited(dev, "Event log '%d': Failed to query event records : %d",
@@ -1080,6 +1079,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_mem_get_event_records, CXL);*/ static int cxl_mem_get_partition_info (struct cxl_memdev_state *mds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_get_partition_info pi;struct cxl_mbox_cmd mbox_cmd;int rc;
@@ -1089,7 +1089,7 @@ static int cxl_mem_get_partition_info(struct cxl_memdev_state *mds) .size_out = sizeof(pi), .payload_out = &pi, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc)return rc;
@@ -1116,6 +1116,7 @@ static int cxl_mem_get_partition_info(struct cxl_memdev_state *mds)*/ int cxl_dev_state_identify (struct cxl_memdev_state *mds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;/* See CXL 2.0 Table 175 Identify Memory Device Output Payload */ struct cxl_mbox_identify id;struct cxl_mbox_cmd mbox_cmd;
@@ -1130,7 +1131,7 @@ int cxl_dev_state_identify(struct cxl_memdev_state *mds) .size_out = sizeof(id), .payload_out = &id, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )return rc;
@@ -1158,6 +1159,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);static int __cxl_mem_sanitize (struct cxl_memdev_state *mds,u16 cmd) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;int rc;u32 sec_out =0 ; struct cxl_get_security_output {
@@ -1169,14 +1171,13 @@ static int __cxl_mem_sanitize(struct cxl_memdev_state *mds, u16 cmd) .size_out = sizeof(out), };struct cxl_mbox_cmd mbox_cmd = { .opcode = cmd }; -struct cxl_dev_state *cxlds = &mds->cxlds;if (cmd !=CXL_MBOX_OP_SANITIZE && cmd !=CXL_MBOX_OP_SECURE_ERASE )return -EINVAL ; - rc =cxl_internal_send_cmd (mds, &sec_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &sec_cmd);if (rc <0 ) { -dev_err (cxlds->dev,"Failed to get security state : %d" , rc); +dev_err (cxl_mbox->host,"Failed to get security state : %d" , rc);return rc; }
@@ -1193,9 +1194,9 @@ static int __cxl_mem_sanitize(struct cxl_memdev_state *mds, u16 cmd) sec_out & CXL_PMEM_SEC_STATE_LOCKED)return -EINVAL ; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 ) { -dev_err (cxlds->dev,"Failed to sanitize device : %d" , rc); +dev_err (cxl_mbox->host,"Failed to sanitize device : %d" , rc);return rc; }
@@ -1310,6 +1311,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_mem_create_range_info, CXL);int cxl_set_timestamp (struct cxl_memdev_state *mds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_cmd mbox_cmd;struct cxl_mbox_set_timestamp_in pi;int rc;
@@ -1321,7 +1323,7 @@ int cxl_set_timestamp(struct cxl_memdev_state *mds) .payload_in = &pi, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);/* * Command is optional. Devices may have another way of providing * a timestamp, or may return all 0s in timestamp fields.
@@ -1338,7 +1340,7 @@ int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, struct cxl_region *cxlr) {struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); -struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_poison_out *po;struct cxl_mbox_poison_in pi;int nr_records =0 ;
@@ -1362,7 +1364,7 @@ int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, .min_out = struct_size(po, record, 0), }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc)break ;
drivers/cxl/core/memdev.c +13 -10
@@ -278,7 +278,7 @@ static int cxl_validate_poison_dpa(struct cxl_memdev *cxlmd, u64 dpa)int cxl_inject_poison (struct cxl_memdev *cxlmd,u64 dpa) { -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_inject_poison inject;struct cxl_poison_record record;struct cxl_mbox_cmd mbox_cmd;
@@ -308,13 +308,13 @@ int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa) .size_in = sizeof(inject), .payload_in = &inject, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc) goto out; cxlr =cxl_dpa_to_region (cxlmd, dpa);if (cxlr) -dev_warn_once (mds->cxlds.dev, +dev_warn_once (cxl_mbox->host,"poison inject dpa:%#llx region: %s\n" , dpa,dev_name (&cxlr->dev));
@@ -333,7 +333,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_inject_poison, CXL);int cxl_clear_poison (struct cxl_memdev *cxlmd,u64 dpa) { -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_clear_poison clear;struct cxl_poison_record record;struct cxl_mbox_cmd mbox_cmd;
@@ -372,13 +372,13 @@ int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa) .payload_in = &clear, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc) goto out; cxlr =cxl_dpa_to_region (cxlmd, dpa);if (cxlr) -dev_warn_once (mds->cxlds.dev, +dev_warn_once (cxl_mbox->host,"poison clear dpa:%#llx region: %s\n" , dpa,dev_name (&cxlr->dev));
@@ -715,6 +715,7 @@ static int cxl_memdev_release_file(struct inode *inode, struct file *file)*/ static int cxl_mem_get_fw_info (struct cxl_memdev_state *mds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_get_fw_info info;struct cxl_mbox_cmd mbox_cmd;int rc;
@@ -725,7 +726,7 @@ static int cxl_mem_get_fw_info(struct cxl_memdev_state *mds) .payload_out = &info, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )return rc;
@@ -749,6 +750,7 @@ static int cxl_mem_get_fw_info(struct cxl_memdev_state *mds)*/ static int cxl_mem_activate_fw (struct cxl_memdev_state *mds,int slot) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_activate_fw activate;struct cxl_mbox_cmd mbox_cmd;
@@ -765,7 +767,7 @@ static int cxl_mem_activate_fw(struct cxl_memdev_state *mds, int slot) activate.action =CXL_FW_ACTIVATE_OFFLINE ; activate.slot = slot; -return cxl_internal_send_cmd (mds, &mbox_cmd); +return cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); }/**
@@ -780,6 +782,7 @@ static int cxl_mem_activate_fw(struct cxl_memdev_state *mds, int slot)*/ static int cxl_mem_abort_fw_xfer (struct cxl_memdev_state *mds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_transfer_fw *transfer;struct cxl_mbox_cmd mbox_cmd;int rc;
@@ -799,7 +802,7 @@ static int cxl_mem_abort_fw_xfer(struct cxl_memdev_state *mds) transfer->action =CXL_FW_TRANSFER_ACTION_ABORT ; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);kfree (transfer);return rc; }
@@ -924,7 +927,7 @@ static enum fw_upload_err cxl_fw_write(struct fw_upload *fwl, const u8 *data, .poll_count = 30, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 ) { rc =FW_UPLOAD_ERR_RW_ERROR ; goto out_free;
drivers/cxl/cxlmem.h +1 -1
@@ -811,7 +811,7 @@ enum { CXL_PMEM_SEC_PASS_USER, }; -int cxl_internal_send_cmd (struct cxl_memdev_state *mds, +int cxl_internal_send_cmd (struct cxl_mailbox *cxl_mbox,struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds);int cxl_await_media_ready (struct cxl_dev_state *cxlds);
drivers/cxl/pci.c +4 -2
@@ -658,6 +658,7 @@ static int cxl_event_req_irq(struct cxl_dev_state *cxlds, u8 setting)static int cxl_event_get_int_policy (struct cxl_memdev_state *mds,struct cxl_event_interrupt_policy *policy) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_cmd mbox_cmd = { .opcode =CXL_MBOX_OP_GET_EVT_INT_POLICY , .payload_out = policy,
@@ -665,7 +666,7 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, };int rc; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )dev_err (mds->cxlds.dev,"Failed to get event interrupt policy : %d" , rc);
@@ -676,6 +677,7 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds,static int cxl_event_config_msgnums (struct cxl_memdev_state *mds,struct cxl_event_interrupt_policy *policy) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_cmd mbox_cmd;int rc;
@@ -692,7 +694,7 @@ static int cxl_event_config_msgnums(struct cxl_memdev_state *mds, .size_in = sizeof(*policy), }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 ) {dev_err (mds->cxlds.dev,"Failed to set event interrupt policy : %d" , rc);
drivers/cxl/pmem.c +4 -2
@@ -120,6 +120,7 @@ static int cxl_pmem_get_config_data(struct cxl_memdev_state *mds, struct nd_cmd_get_config_data_hdr *cmd, unsigned int buf_len) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_get_lsa get_lsa;struct cxl_mbox_cmd mbox_cmd;int rc;
@@ -141,7 +142,7 @@ static int cxl_pmem_get_config_data(struct cxl_memdev_state *mds, .payload_out = cmd->out_buf, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); cmd->status =0 ;return rc;
@@ -151,6 +152,7 @@ static int cxl_pmem_set_config_data(struct cxl_memdev_state *mds, struct nd_cmd_set_config_hdr *cmd, unsigned int buf_len) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_set_lsa *set_lsa;struct cxl_mbox_cmd mbox_cmd;int rc;
@@ -177,7 +179,7 @@ static int cxl_pmem_set_config_data(struct cxl_memdev_state *mds, .size_in = struct_size(set_lsa, data, cmd->in_length), }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);/* * Set "firmware" status (4-packed bytes at the end of the input
drivers/cxl/security.c +12 -11
@@ -14,6 +14,7 @@ static unsigned long cxl_pmem_get_security_flags(struct nvdimm *nvdimm, {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds);unsigned long security_flags =0 ; struct cxl_get_security_output {
@@ -29,7 +30,7 @@ static unsigned long cxl_pmem_get_security_flags(struct nvdimm *nvdimm, .payload_out = &out, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )return 0 ;
@@ -70,7 +71,7 @@ static int cxl_pmem_security_change_key(struct nvdimm *nvdimm, {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_cmd mbox_cmd;struct cxl_set_pass set_pass;
@@ -87,7 +88,7 @@ static int cxl_pmem_security_change_key(struct nvdimm *nvdimm, .payload_in = &set_pass, }; -return cxl_internal_send_cmd (mds, &mbox_cmd); +return cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); } static int __cxl_pmem_security_disable(struct nvdimm *nvdimm,
@@ -96,7 +97,7 @@ static int __cxl_pmem_security_disable(struct nvdimm *nvdimm, {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_disable_pass dis_pass;struct cxl_mbox_cmd mbox_cmd;
@@ -112,7 +113,7 @@ static int __cxl_pmem_security_disable(struct nvdimm *nvdimm, .payload_in = &dis_pass, }; -return cxl_internal_send_cmd (mds, &mbox_cmd); +return cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); } static int cxl_pmem_security_disable(struct nvdimm *nvdimm,
@@ -131,12 +132,12 @@ static int cxl_pmem_security_freeze(struct nvdimm *nvdimm) {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_cmd mbox_cmd = { .opcode =CXL_MBOX_OP_FREEZE_SECURITY , }; -return cxl_internal_send_cmd (mds, &mbox_cmd); +return cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); } static int cxl_pmem_security_unlock(struct nvdimm *nvdimm,
@@ -144,7 +145,7 @@ static int cxl_pmem_security_unlock(struct nvdimm *nvdimm, {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;u8 pass[NVDIMM_PASSPHRASE_LEN ];struct cxl_mbox_cmd mbox_cmd;int rc;
@@ -156,7 +157,7 @@ static int cxl_pmem_security_unlock(struct nvdimm *nvdimm, .payload_in = pass, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )return rc;
@@ -169,7 +170,7 @@ static int cxl_pmem_security_passphrase_erase(struct nvdimm *nvdimm, {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_cmd mbox_cmd;struct cxl_pass_erase erase;int rc;
@@ -185,7 +186,7 @@ static int cxl_pmem_security_passphrase_erase(struct nvdimm *nvdimm, .payload_in = &erase, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )return rc;
Signature · 1 line
2.46.0
Re: [PATCH v4 3/3] cxl: Convert cxl_internal_send_cmd() to use 'struct cxl_mailbox' as input
Quoted 8 lines · Dave Jiang
With the CXL mailbox context split out,
cxl_internal_send_cmd()can take 'structcxl_mailbox' as an input parameter rather than 'structmemdev_dev_state'. Change input parameter forcxl_internal_send_cmd()and fixup all impacted call sites.Reviewed-by Fan Ni <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Alison Schofield <[email protected]>
As a straight forward conversion.
But some calls like cxl_set_timestamp() could also be converted later if needed I think.
Ira
Quoted 501 lines
Signed-off-by Dave Jiang <[email protected]>--- drivers/cxl/core/mbox.c | 38 ++++++++++++++++++++------------------ drivers/cxl/core/memdev.c | 23 +++++++++++++---------- drivers/cxl/cxlmem.h | 2 +- drivers/cxl/pci.c | 6 ++++-- drivers/cxl/pmem.c | 6 ++++-- drivers/cxl/security.c | 23 ++++++++++++----------- 6 files changed, 54 insertions(+), 44 deletions(-)drivers/cxl/core/mbox.c +20
-18@@ -225,7 +225,7 @@ static const char *cxl_mem_opcode_to_name(u16 opcode)/** * cxl_internal_send_cmd() - Kernel internal interface to send a mailbox command -* @mds: The driver data for the operation +* @cxl_mbox: CXL mailbox context * @mbox_cmd: initialized command to execute * * Context: Any context. @@ -241,10 +241,9 @@ static const char *cxl_mem_opcode_to_name(u16 opcode)* error. While this distinction can be useful for commands from userspace, the * kernel will only be able to use results when both are successful. */ -int cxl_internal_send_cmd (struct cxl_memdev_state *mds, +int cxl_internal_send_cmd (struct cxl_mailbox *cxl_mbox,struct cxl_mbox_cmd *mbox_cmd) { -struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;size_t out_size, min_out;int rc;@@ -689,7 +688,7 @@ static int cxl_xfer_log(struct cxl_memdev_state *mds, uuid_t *uuid, .payload_out = out, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);/* * The output payload length that indicates the number @@ -775,7 +774,7 @@ static struct cxl_mbox_get_supported_logs *cxl_get_gsl(struct cxl_memdev_state */* At least the record number field must be valid */ .min_out = 2, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 ) {kvfree (ret);return ERR_PTR (rc);@@ -964,7 +963,7 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,if (i == max_handles) { payload->nr_recs = i; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc) goto free_pl; i =0 ;@@ -975,7 +974,7 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,if (i) { payload->nr_recs = i; mbox_cmd.size_in =struct_size (payload, handles, i); - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc) goto free_pl; }@@ -1009,7 +1008,7 @@ static void cxl_mem_get_records_log(struct cxl_memdev_state *mds, .min_out = struct_size(payload, records, 0), }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc) { dev_err_ratelimited(dev, "Event log '%d': Failed to query event records : %d",@@ -1080,6 +1079,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_mem_get_event_records, CXL);*/ static int cxl_mem_get_partition_info (struct cxl_memdev_state *mds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_get_partition_info pi;struct cxl_mbox_cmd mbox_cmd;int rc;@@ -1089,7 +1089,7 @@ static int cxl_mem_get_partition_info(struct cxl_memdev_state *mds) .size_out = sizeof(pi), .payload_out = &pi, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc)return rc;@@ -1116,6 +1116,7 @@ static int cxl_mem_get_partition_info(struct cxl_memdev_state *mds)*/ int cxl_dev_state_identify (struct cxl_memdev_state *mds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;/* See CXL 2.0 Table 175 Identify Memory Device Output Payload */ struct cxl_mbox_identify id;struct cxl_mbox_cmd mbox_cmd;@@ -1130,7 +1131,7 @@ int cxl_dev_state_identify(struct cxl_memdev_state *mds) .size_out = sizeof(id), .payload_out = &id, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )return rc;@@ -1158,6 +1159,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);static int __cxl_mem_sanitize (struct cxl_memdev_state *mds,u16 cmd) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;int rc;u32 sec_out =0 ; struct cxl_get_security_output {@@ -1169,14 +1171,13 @@ static int __cxl_mem_sanitize(struct cxl_memdev_state *mds, u16 cmd) .size_out = sizeof(out), };struct cxl_mbox_cmd mbox_cmd = { .opcode = cmd }; -struct cxl_dev_state *cxlds = &mds->cxlds;if (cmd !=CXL_MBOX_OP_SANITIZE && cmd !=CXL_MBOX_OP_SECURE_ERASE )return -EINVAL ; - rc =cxl_internal_send_cmd (mds, &sec_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &sec_cmd);if (rc <0 ) { -dev_err (cxlds->dev,"Failed to get security state : %d" , rc); +dev_err (cxl_mbox->host,"Failed to get security state : %d" , rc);return rc; }@@ -1193,9 +1194,9 @@ static int __cxl_mem_sanitize(struct cxl_memdev_state *mds, u16 cmd) sec_out & CXL_PMEM_SEC_STATE_LOCKED)return -EINVAL ; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 ) { -dev_err (cxlds->dev,"Failed to sanitize device : %d" , rc); +dev_err (cxl_mbox->host,"Failed to sanitize device : %d" , rc);return rc; }@@ -1310,6 +1311,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_mem_create_range_info, CXL);int cxl_set_timestamp (struct cxl_memdev_state *mds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_cmd mbox_cmd;struct cxl_mbox_set_timestamp_in pi;int rc;@@ -1321,7 +1323,7 @@ int cxl_set_timestamp(struct cxl_memdev_state *mds) .payload_in = &pi, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);/* * Command is optional. Devices may have another way of providing * a timestamp, or may return all 0s in timestamp fields. @@ -1338,7 +1340,7 @@ int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, struct cxl_region *cxlr) {struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); -struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_poison_out *po;struct cxl_mbox_poison_in pi;int nr_records =0 ;@@ -1362,7 +1364,7 @@ int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, .min_out = struct_size(po, record, 0), }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc)break ;drivers/cxl/core/memdev.c +13
-10@@ -278,7 +278,7 @@ static int cxl_validate_poison_dpa(struct cxl_memdev *cxlmd, u64 dpa)int cxl_inject_poison (struct cxl_memdev *cxlmd,u64 dpa) { -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_inject_poison inject;struct cxl_poison_record record;struct cxl_mbox_cmd mbox_cmd;@@ -308,13 +308,13 @@ int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa) .size_in = sizeof(inject), .payload_in = &inject, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc) goto out; cxlr =cxl_dpa_to_region (cxlmd, dpa);if (cxlr) -dev_warn_once (mds->cxlds.dev, +dev_warn_once (cxl_mbox->host,"poison inject dpa:%#llx region: %s\n" , dpa,dev_name (&cxlr->dev));@@ -333,7 +333,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_inject_poison, CXL);int cxl_clear_poison (struct cxl_memdev *cxlmd,u64 dpa) { -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_clear_poison clear;struct cxl_poison_record record;struct cxl_mbox_cmd mbox_cmd;@@ -372,13 +372,13 @@ int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa) .payload_in = &clear, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc) goto out; cxlr =cxl_dpa_to_region (cxlmd, dpa);if (cxlr) -dev_warn_once (mds->cxlds.dev, +dev_warn_once (cxl_mbox->host,"poison clear dpa:%#llx region: %s\n" , dpa,dev_name (&cxlr->dev));@@ -715,6 +715,7 @@ static int cxl_memdev_release_file(struct inode *inode, struct file *file)*/ static int cxl_mem_get_fw_info (struct cxl_memdev_state *mds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_get_fw_info info;struct cxl_mbox_cmd mbox_cmd;int rc;@@ -725,7 +726,7 @@ static int cxl_mem_get_fw_info(struct cxl_memdev_state *mds) .payload_out = &info, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )return rc;@@ -749,6 +750,7 @@ static int cxl_mem_get_fw_info(struct cxl_memdev_state *mds)*/ static int cxl_mem_activate_fw (struct cxl_memdev_state *mds,int slot) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_activate_fw activate;struct cxl_mbox_cmd mbox_cmd;@@ -765,7 +767,7 @@ static int cxl_mem_activate_fw(struct cxl_memdev_state *mds, int slot) activate.action =CXL_FW_ACTIVATE_OFFLINE ; activate.slot = slot; -return cxl_internal_send_cmd (mds, &mbox_cmd); +return cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); }/** @@ -780,6 +782,7 @@ static int cxl_mem_activate_fw(struct cxl_memdev_state *mds, int slot)*/ static int cxl_mem_abort_fw_xfer (struct cxl_memdev_state *mds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_transfer_fw *transfer;struct cxl_mbox_cmd mbox_cmd;int rc;@@ -799,7 +802,7 @@ static int cxl_mem_abort_fw_xfer(struct cxl_memdev_state *mds) transfer->action =CXL_FW_TRANSFER_ACTION_ABORT ; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);kfree (transfer);return rc; }@@ -924,7 +927,7 @@ static enum fw_upload_err cxl_fw_write(struct fw_upload *fwl, const u8 *data, .poll_count = 30, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 ) { rc =FW_UPLOAD_ERR_RW_ERROR ; goto out_free;drivers/cxl/cxlmem.h +1
-1@@ -811,7 +811,7 @@ enum { CXL_PMEM_SEC_PASS_USER, }; -int cxl_internal_send_cmd (struct cxl_memdev_state *mds, +int cxl_internal_send_cmd (struct cxl_mailbox *cxl_mbox,struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds);int cxl_await_media_ready (struct cxl_dev_state *cxlds);drivers/cxl/pci.c +4
-2@@ -658,6 +658,7 @@ static int cxl_event_req_irq(struct cxl_dev_state *cxlds, u8 setting)static int cxl_event_get_int_policy (struct cxl_memdev_state *mds,struct cxl_event_interrupt_policy *policy) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_cmd mbox_cmd = { .opcode =CXL_MBOX_OP_GET_EVT_INT_POLICY , .payload_out = policy,@@ -665,7 +666,7 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, };int rc; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )dev_err (mds->cxlds.dev,"Failed to get event interrupt policy : %d" , rc);@@ -676,6 +677,7 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds,static int cxl_event_config_msgnums (struct cxl_memdev_state *mds,struct cxl_event_interrupt_policy *policy) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_cmd mbox_cmd;int rc;@@ -692,7 +694,7 @@ static int cxl_event_config_msgnums(struct cxl_memdev_state *mds, .size_in = sizeof(*policy), }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 ) {dev_err (mds->cxlds.dev,"Failed to set event interrupt policy : %d" , rc);drivers/cxl/pmem.c +4
-2@@ -120,6 +120,7 @@ static int cxl_pmem_get_config_data(struct cxl_memdev_state *mds, struct nd_cmd_get_config_data_hdr *cmd, unsigned int buf_len) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_get_lsa get_lsa;struct cxl_mbox_cmd mbox_cmd;int rc;@@ -141,7 +142,7 @@ static int cxl_pmem_get_config_data(struct cxl_memdev_state *mds, .payload_out = cmd->out_buf, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); cmd->status =0 ;return rc;@@ -151,6 +152,7 @@ static int cxl_pmem_set_config_data(struct cxl_memdev_state *mds, struct nd_cmd_set_config_hdr *cmd, unsigned int buf_len) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;struct cxl_mbox_set_lsa *set_lsa;struct cxl_mbox_cmd mbox_cmd;int rc;@@ -177,7 +179,7 @@ static int cxl_pmem_set_config_data(struct cxl_memdev_state *mds, .size_in = struct_size(set_lsa, data, cmd->in_length), }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);/* * Set "firmware" status (4-packed bytes at the end of the input drivers/cxl/security.c +12
-11@@ -14,6 +14,7 @@ static unsigned long cxl_pmem_get_security_flags(struct nvdimm *nvdimm, {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds);unsigned long security_flags =0 ; struct cxl_get_security_output {@@ -29,7 +30,7 @@ static unsigned long cxl_pmem_get_security_flags(struct nvdimm *nvdimm, .payload_out = &out, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )return 0 ;@@ -70,7 +71,7 @@ static int cxl_pmem_security_change_key(struct nvdimm *nvdimm, {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_cmd mbox_cmd;struct cxl_set_pass set_pass;@@ -87,7 +88,7 @@ static int cxl_pmem_security_change_key(struct nvdimm *nvdimm, .payload_in = &set_pass, }; -return cxl_internal_send_cmd (mds, &mbox_cmd); +return cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); } static int __cxl_pmem_security_disable(struct nvdimm *nvdimm,@@ -96,7 +97,7 @@ static int __cxl_pmem_security_disable(struct nvdimm *nvdimm, {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_disable_pass dis_pass;struct cxl_mbox_cmd mbox_cmd;@@ -112,7 +113,7 @@ static int __cxl_pmem_security_disable(struct nvdimm *nvdimm, .payload_in = &dis_pass, }; -return cxl_internal_send_cmd (mds, &mbox_cmd); +return cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); } static int cxl_pmem_security_disable(struct nvdimm *nvdimm,@@ -131,12 +132,12 @@ static int cxl_pmem_security_freeze(struct nvdimm *nvdimm) {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_cmd mbox_cmd = { .opcode =CXL_MBOX_OP_FREEZE_SECURITY , }; -return cxl_internal_send_cmd (mds, &mbox_cmd); +return cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); } static int cxl_pmem_security_unlock(struct nvdimm *nvdimm,@@ -144,7 +145,7 @@ static int cxl_pmem_security_unlock(struct nvdimm *nvdimm, {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;u8 pass[NVDIMM_PASSPHRASE_LEN ];struct cxl_mbox_cmd mbox_cmd;int rc;@@ -156,7 +157,7 @@ static int cxl_pmem_security_unlock(struct nvdimm *nvdimm, .payload_in = pass, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )return rc;@@ -169,7 +170,7 @@ static int cxl_pmem_security_passphrase_erase(struct nvdimm *nvdimm, {struct cxl_nvdimm *cxl_nvd =nvdimm_provider_data (nvdimm);struct cxl_memdev *cxlmd = cxl_nvd->cxlmd; -struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox;struct cxl_mbox_cmd mbox_cmd;struct cxl_pass_erase erase;int rc;@@ -185,7 +186,7 @@ static int cxl_pmem_security_passphrase_erase(struct nvdimm *nvdimm, .payload_in = &erase, }; - rc =cxl_internal_send_cmd (mds, &mbox_cmd); + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);if (rc <0 )return rc;Signature · 1 line
2.46.0
Quoted 9 lines · Dave Jiang
Hi Alejandro,
Please feel free to pull in the patches in this series into your type2 series. Although I may just pull these into the 6.12 merge window to make things easier for you.The patches pulls out the related mailbox bits and form a 'struct
cxl_mailbox'. In v2 Jonathan suggested that we keepcxl_mboxembedded. So I moved it back to be embedded. For the type2 devices that does not use mailbox, it can just not have the mailbox struct at all.
I've been using your v2 for my v3, so I'll adjust it to this v4. However, I do not think it has an impact on my work since the Type2 support I'm adding is for our accel case which has not mailbox and therefore no accessor for initialising a mailbox from an accel driver is added. I guess that will need to wait until another accel driver requires it.
Quoted 32 lines
v3
- moved the other cxl headers into the linux/cxl directory.
- Movedrcuwait.hheader intomailbox.h(Alison)v4
- Move headers toinclude/cxl(Dan)
- Move header moving patch to 1/3 (Dan)
- Fixcxl_mailbox_initinput param check. (Alison)---
Dave Jiang (3):
cxl: move cxl headers to new linux/cxl/ directory
cxl: Move mailbox related bits to the same context
cxl: Convertcxl_internal_send_cmd()to use 'structcxl_mailbox' as inputMAINTAINERS | 3 +- drivers/acpi/apei/einj-cxl.c | 2 +- drivers/acpi/apei/ghes.c | 2 +- drivers/cxl/core/mbox.c | 91 ++++++++++++++++++++++++++++++++------------------ drivers/cxl/core/memdev.c | 41 +++++++++++++---------- drivers/cxl/core/port.c | 2 +- drivers/cxl/cxlmem.h | 25 ++++++-------- drivers/cxl/pci.c | 82 ++++++++++++++++++++++++++++++--------------- drivers/cxl/pmem.c | 10 ++++-- drivers/cxl/security.c | 23 +++++++------ include/{linux/einj-cxl.h => cxl/einj.h} | 0 include/{linux/cxl-event.h => cxl/event.h} | 0 include/cxl/mailbox.h | 28 ++++++++++++++++ tools/testing/cxl/test/mem.c | 44 ++++++++++++++++++------ 14 files changed, 233 insertions(+), 120 deletions(-)