Skip to content

Commit cbbca60

Browse files
committed
cxl: Enumerate feature commands
Add feature commands enumeration code in order to detect and enumerate the 3 feature related commands "get supported features", "get feature", and "set feature". The enumeration will help determine whether the driver can issue any of the 3 commands to the device. Reviewed-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Li Ming <ming.li@zohomail.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net> Tested-by: Shiju Jose <shiju.jose@huawei.com> Link: https://patch.msgid.link/20250220194438.2281088-2-dave.jiang@intel.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 5666a7e commit cbbca60

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

drivers/cxl/core/mbox.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,35 @@ static int cxl_xfer_log(struct cxl_memdev_state *mds, uuid_t *uuid,
706706
return 0;
707707
}
708708

709+
static int check_features_opcodes(u16 opcode, int *ro_cmds, int *wr_cmds)
710+
{
711+
switch (opcode) {
712+
case CXL_MBOX_OP_GET_SUPPORTED_FEATURES:
713+
case CXL_MBOX_OP_GET_FEATURE:
714+
(*ro_cmds)++;
715+
return 1;
716+
case CXL_MBOX_OP_SET_FEATURE:
717+
(*wr_cmds)++;
718+
return 1;
719+
default:
720+
return 0;
721+
}
722+
}
723+
724+
/* 'Get Supported Features' and 'Get Feature' */
725+
#define MAX_FEATURES_READ_CMDS 2
726+
static void set_features_cap(struct cxl_mailbox *cxl_mbox,
727+
int ro_cmds, int wr_cmds)
728+
{
729+
/* Setting up Features capability while walking the CEL */
730+
if (ro_cmds == MAX_FEATURES_READ_CMDS) {
731+
if (wr_cmds)
732+
cxl_mbox->feat_cap = CXL_FEATURES_RW;
733+
else
734+
cxl_mbox->feat_cap = CXL_FEATURES_RO;
735+
}
736+
}
737+
709738
/**
710739
* cxl_walk_cel() - Walk through the Command Effects Log.
711740
* @mds: The driver data for the operation
@@ -721,7 +750,7 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
721750
struct cxl_cel_entry *cel_entry;
722751
const int cel_entries = size / sizeof(*cel_entry);
723752
struct device *dev = mds->cxlds.dev;
724-
int i;
753+
int i, ro_cmds = 0, wr_cmds = 0;
725754

726755
cel_entry = (struct cxl_cel_entry *) cel;
727756

@@ -735,6 +764,9 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
735764
enabled++;
736765
}
737766

767+
enabled += check_features_opcodes(opcode, &ro_cmds,
768+
&wr_cmds);
769+
738770
if (cxl_is_poison_command(opcode)) {
739771
cxl_set_poison_cmd_enabled(&mds->poison, opcode);
740772
enabled++;
@@ -748,6 +780,8 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
748780
dev_dbg(dev, "Opcode 0x%04x %s\n", opcode,
749781
enabled ? "enabled" : "unsupported by driver");
750782
}
783+
784+
set_features_cap(cxl_mbox, ro_cmds, wr_cmds);
751785
}
752786

753787
static struct cxl_mbox_get_supported_logs *cxl_get_gsl(struct cxl_memdev_state *mds)

drivers/cxl/cxlmem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ enum cxl_opcode {
490490
CXL_MBOX_OP_GET_LOG_CAPS = 0x0402,
491491
CXL_MBOX_OP_CLEAR_LOG = 0x0403,
492492
CXL_MBOX_OP_GET_SUP_LOG_SUBLIST = 0x0405,
493+
CXL_MBOX_OP_GET_SUPPORTED_FEATURES = 0x0500,
494+
CXL_MBOX_OP_GET_FEATURE = 0x0501,
495+
CXL_MBOX_OP_SET_FEATURE = 0x0502,
493496
CXL_MBOX_OP_IDENTIFY = 0x4000,
494497
CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100,
495498
CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101,

include/cxl/features.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/* Copyright(c) 2024-2025 Intel Corporation. */
3+
#ifndef __CXL_FEATURES_H__
4+
#define __CXL_FEATURES_H__
5+
6+
/* Feature commands capability supported by a device */
7+
enum cxl_features_capability {
8+
CXL_FEATURES_NONE = 0,
9+
CXL_FEATURES_RO,
10+
CXL_FEATURES_RW,
11+
};
12+
13+
#endif

include/cxl/mailbox.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifndef __CXL_MBOX_H__
44
#define __CXL_MBOX_H__
55
#include <linux/rcuwait.h>
6+
#include <cxl/features.h>
67
#include <uapi/linux/cxl_mem.h>
78

89
/**
@@ -51,6 +52,7 @@ struct cxl_mbox_cmd {
5152
* @mbox_mutex: mutex protects device mailbox and firmware
5253
* @mbox_wait: rcuwait for mailbox
5354
* @mbox_send: @dev specific transport for transmitting mailbox commands
55+
* @feat_cap: Features capability
5456
*/
5557
struct cxl_mailbox {
5658
struct device *host;
@@ -60,6 +62,7 @@ struct cxl_mailbox {
6062
struct mutex mbox_mutex; /* lock to protect mailbox context */
6163
struct rcuwait mbox_wait;
6264
int (*mbox_send)(struct cxl_mailbox *cxl_mbox, struct cxl_mbox_cmd *cmd);
65+
enum cxl_features_capability feat_cap;
6366
};
6467

6568
int cxl_mailbox_init(struct cxl_mailbox *cxl_mbox, struct device *host);

0 commit comments

Comments
 (0)