Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+54 -1
+35 -1
drivers/cxl/core/mbox.c
··· 706 706 return 0; 707 707 } 708 708 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 + 709 738 /** 710 739 * cxl_walk_cel() - Walk through the Command Effects Log. 711 740 * @mds: The driver data for the operation ··· 750 721 struct cxl_cel_entry *cel_entry; 751 722 const int cel_entries = size / sizeof(*cel_entry); 752 723 struct device *dev = mds->cxlds.dev; 753 - int i; 724 + int i, ro_cmds = 0, wr_cmds = 0; 754 725 755 726 cel_entry = (struct cxl_cel_entry *) cel; 756 727 ··· 763 734 set_bit(cmd->info.id, cxl_mbox->enabled_cmds); 764 735 enabled++; 765 736 } 737 + 738 + enabled += check_features_opcodes(opcode, &ro_cmds, 739 + &wr_cmds); 766 740 767 741 if (cxl_is_poison_command(opcode)) { 768 742 cxl_set_poison_cmd_enabled(&mds->poison, opcode); ··· 780 748 dev_dbg(dev, "Opcode 0x%04x %s\n", opcode, 781 749 enabled ? "enabled" : "unsupported by driver"); 782 750 } 751 + 752 + set_features_cap(cxl_mbox, ro_cmds, wr_cmds); 783 753 } 784 754 785 755 static struct cxl_mbox_get_supported_logs *cxl_get_gsl(struct cxl_memdev_state *mds)
+3
drivers/cxl/cxlmem.h
··· 490 490 CXL_MBOX_OP_GET_LOG_CAPS = 0x0402, 491 491 CXL_MBOX_OP_CLEAR_LOG = 0x0403, 492 492 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, 493 496 CXL_MBOX_OP_IDENTIFY = 0x4000, 494 497 CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100, 495 498 CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101,
+13
include/cxl/features.h
··· 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
+3
include/cxl/mailbox.h
··· 3 3 #ifndef __CXL_MBOX_H__ 4 4 #define __CXL_MBOX_H__ 5 5 #include <linux/rcuwait.h> 6 + #include <cxl/features.h> 6 7 #include <uapi/linux/cxl_mem.h> 7 8 8 9 /** ··· 52 51 * @mbox_mutex: mutex protects device mailbox and firmware 53 52 * @mbox_wait: rcuwait for mailbox 54 53 * @mbox_send: @dev specific transport for transmitting mailbox commands 54 + * @feat_cap: Features capability 55 55 */ 56 56 struct cxl_mailbox { 57 57 struct device *host; ··· 62 60 struct mutex mbox_mutex; /* lock to protect mailbox context */ 63 61 struct rcuwait mbox_wait; 64 62 int (*mbox_send)(struct cxl_mailbox *cxl_mbox, struct cxl_mbox_cmd *cmd); 63 + enum cxl_features_capability feat_cap; 65 64 }; 66 65 67 66 int cxl_mailbox_init(struct cxl_mailbox *cxl_mbox, struct device *host);