misc: Add AMD side band interface(SBI) functionality
Subsystems (3)
v4 cover misc: Add AMD side band interface(SBI) functionality
AMD's Advanced Platform Management Link (APML) interface provides system management functionality accessed by the baseboard management controller (BMC). sbrmi driver under hwmon subsystem, which is probed as an i2c driver and reports power using APML specified protocol.
However, APML interface defines few other protocols to support
full system management functionality out-of-band.
Out-of-band management is term used for BMC talking to system management unit (IP in the processor). AMD's documentation called this link as side band interface.
This patchset is an attempt to add all APML core functionality in one place and provide hwmon and user space interface
1. [Patch 1] Move the i2c client probe, hwmon sensors and sbrmi core functionality from drivers/hwmon to drivers/misc/
2. [Patch 2] Convert i2c to regmap which provides multiple benefits over direct smbus APIs.
a. i2c/i3c support and
b. 1 byte/2 byte RMI register size addressing
3. [Patch 3] Optimize wait condition with regmap API regmap_read_poll_timeout as per suggestion from Arnd
4. [Patch 4, 5] Register a misc device which provides
a. An ioctl interface through node /dev/sbrmiX
b. Register sets is common across APML protocols. IOCTL is providing
synchronization among protocols as transactions may create
race condition.
5. [Subsequent patches 6, 7 and 8] add support for AMD custom protocols a. CPUID
b. MCAMSR
c. Register xfer
6. [Patch 9] AMD side band description document
Open-sourced and widely used https://github.com/amd/esmi_oob_library
will continue to provide user-space programmable API.
Akshay Gupta (9):
hwmon/misc: amd-sbi: Move core sbrmi from hwmon to misc
misc: amd-sbi: Use regmap subsystem
misc: amd-sbi: Optimize the wait condition for mailbox command
completion
misc: amd-sbi: Add support for AMD_SBI IOCTL
misc: amd-sbi: Add support for mailbox error codes
misc: amd-sbi: Add support for CPUID protocol
misc: amd-sbi: Add support for MCA register protocol
misc: amd-sbi: Add supoort for register xfer
misc: amd-sbi: Add document for AMD SB IOCTL description
Documentation/misc-devices/amd-sbi.rst | 84 ++++ Documentation/misc-devices/index.rst | 1 + .../userspace-api/ioctl/ioctl-number.rst | 2 + drivers/hwmon/Kconfig | 10 - drivers/hwmon/sbrmi.c | 357 -------------- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/amd-sbi/Kconfig | 9 + drivers/misc/amd-sbi/Makefile | 3 + drivers/misc/amd-sbi/rmi-core.c | 452 ++++++++++++++++++ drivers/misc/amd-sbi/rmi-core.h | 67 +++ drivers/misc/amd-sbi/rmi-hwmon.c | 122 +++++ drivers/misc/amd-sbi/rmi-i2c.c | 135 ++++++ include/uapi/misc/amd-apml.h | 97 ++++ 14 files changed, 974 insertions(+), 367 deletions(-) create mode 100644 Documentation/misc-devices/amd-sbi.rst delete mode 100644 drivers/hwmon/sbrmi.c create mode 100644 drivers/misc/amd-sbi/Kconfig create mode 100644 drivers/misc/amd-sbi/Makefile create mode 100644 drivers/misc/amd-sbi/rmi-core.c create mode 100644 drivers/misc/amd-sbi/rmi-core.h create mode 100644 drivers/misc/amd-sbi/rmi-hwmon.c create mode 100644 drivers/misc/amd-sbi/rmi-i2c.c create mode 100644 include/uapi/misc/amd-apml.h
Signature · 1 line
2.25.1
PATCH v4 1/9 hwmon/misc: amd-sbi: Move core sbrmi from hwmon to misc
This is done to support other functionality provided by the SBRMI, which does not fit in the hwmon subsystem.
- Move the SBRMI core functionality and I2C device probing part to misc.
- Move hwmon device sensor to misc as only power is reported through hwmon sensor.
---
Changes since v3:
Rebase the patch
Added Acked-by
Changes since v2:
Rebase the patch
Changes since v1:
- File name update
- Add hwmon sensor registration in this patch
- Update Copyright year
drivers/hwmon/Kconfig | 10 - drivers/hwmon/sbrmi.c | 357 ------------------------------- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/amd-sbi/Kconfig | 9 + drivers/misc/amd-sbi/Makefile | 3 + drivers/misc/amd-sbi/rmi-core.c | 115 ++++++++++ drivers/misc/amd-sbi/rmi-core.h | 65 ++++++ drivers/misc/amd-sbi/rmi-hwmon.c | 121 +++++++++++ drivers/misc/amd-sbi/rmi-i2c.c | 111 ++++++++++ 10 files changed, 426 insertions(+), 367 deletions(-) delete mode 100644 drivers/hwmon/sbrmi.c create mode 100644 drivers/misc/amd-sbi/Kconfig create mode 100644 drivers/misc/amd-sbi/Makefile create mode 100644 drivers/misc/amd-sbi/rmi-core.c create mode 100644 drivers/misc/amd-sbi/rmi-core.h create mode 100644 drivers/misc/amd-sbi/rmi-hwmon.c create mode 100644 drivers/misc/amd-sbi/rmi-i2c.c
drivers/hwmon/Kconfig +0 -10
@@ -1823,16 +1823,6 @@ config SENSORS_SBTSI This driver can also be built as a module. If so, the module will be called sbtsi_temp. -config SENSORS_SBRMI - tristate "Emulated SB-RMI sensor" - depends on I2C - help - If you say yes here you get support for emulated RMI - sensors on AMD SoCs with APML interface connected to a BMC device. - - This driver can also be built as a module. If so, the module will - be called sbrmi. - config SENSORS_SHT15 tristate "Sensiron humidity and temperature sensors. SHT15 and compat." depends on GPIOLIB || COMPILE_TEST
drivers/hwmon/sbrmi.c deleted +0 -357
357 lines not on this page · raw message
drivers/misc/Kconfig +1 -0
@@ -618,4 +618,5 @@ source "drivers/misc/uacce/Kconfig" source "drivers/misc/pvpanic/Kconfig" source "drivers/misc/mchp_pci1xxxx/Kconfig" source "drivers/misc/keba/Kconfig" +source "drivers/misc/amd-sbi/Kconfig" endmenu
drivers/misc/Makefile +1 -0
@@ -71,3 +71,4 @@ obj-$(CONFIG_TPS6594_PFSM) += tps6594-pfsm.o obj-$(CONFIG_NSM) += nsm.o obj-$(CONFIG_MARVELL_CN10K_DPI) += mrvl_cn10k_dpi.o obj-y += keba/ +obj-y += amd-sbi/
drivers/misc/amd-sbi/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +config AMD_SBRMI_I2C + tristate "AMD side band RMI support" + depends on I2C + help + Side band RMI over I2C support for AMD out of band management. + + This driver can also be built as a module. If so, the module will + be called sbrmi-i2c.
drivers/misc/amd-sbi/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +sbrmi-i2c-objs := rmi-i2c.o rmi-core.o rmi-hwmon.o +obj-$(CONFIG_AMD_SBRMI_I2C) += sbrmi-i2c.o
drivers/misc/amd-sbi/rmi-core.c new file +115 -0
115 lines not on this page · raw message
drivers/misc/amd-sbi/rmi-core.h new file +65 -0
65 lines not on this page · raw message
drivers/misc/amd-sbi/rmi-hwmon.c new file +121 -0
121 lines not on this page · raw message
drivers/misc/amd-sbi/rmi-i2c.c new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 2/9 misc: amd-sbi: Use regmap subsystem
In reply to Akshay Gupta- regmap subsystem provides multiple benefits over direct smbus APIs
- The susbsytem can be helpful in following cases
- Differnet types of bus (i2c/i3c), we have plans to support i3c.
- Different Register address size (1byte/2byte)
---
Changes since v1:
- Previously patch 3
- Remove "__packed" from data structure
drivers/misc/amd-sbi/rmi-core.c | 29 ++++++++++++----------------- drivers/misc/amd-sbi/rmi-core.h | 3 ++- drivers/misc/amd-sbi/rmi-i2c.c | 25 ++++++++++++++++--------- 3 files changed, 30 insertions(+), 27 deletions(-)
drivers/misc/amd-sbi/rmi-core.c +12 -17
@@ -9,6 +9,7 @@#include <linux/err.h> #include <linux/i2c.h> #include <linux/mutex.h> +#include <linux/regmap.h> #include "rmi-core.h" /* Mask for Status Register bit[1] */
@@ -23,6 +24,7 @@int rmi_mailbox_xfer (struct sbrmi_data *data,struct sbrmi_mailbox_msg *msg) { +unsigned int bytes;int i, ret, retry =10 ;int sw_status;u8 byte;
@@ -30,14 +32,12 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,mutex_lock (&data->lock);/* Indicate firmware a command is to be serviced */ - ret =i2c_smbus_write_byte_data (data->client, -SBRMI_INBNDMSG7 ,START_CMD ); + ret =regmap_write (data->regmap,SBRMI_INBNDMSG7 ,START_CMD );if (ret <0 ) goto exit_unlock;/* Write the command to SBRMI::InBndMsg_inst0 */ - ret =i2c_smbus_write_byte_data (data->client, -SBRMI_INBNDMSG0 , msg->cmd); + ret =regmap_write (data->regmap,SBRMI_INBNDMSG0 , msg->cmd);if (ret <0 ) goto exit_unlock;
@@ -48,8 +48,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,*/ for (i =0 ; i <4 ; i++) { byte = (msg->data_in >> i *8 ) &0xff ; - ret =i2c_smbus_write_byte_data (data->client, -SBRMI_INBNDMSG1 + i, byte); + ret =regmap_write (data->regmap,SBRMI_INBNDMSG1 + i, byte);if (ret <0 ) goto exit_unlock; }
@@ -58,8 +57,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,* Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to * perform the requested read or write command */ - ret =i2c_smbus_write_byte_data (data->client, -SBRMI_SW_INTERRUPT ,TRIGGER_MAILBOX ); + ret =regmap_write (data->regmap,SBRMI_SW_INTERRUPT ,TRIGGER_MAILBOX );if (ret <0 ) goto exit_unlock;
@@ -69,8 +67,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,* of the requested command */ do { - sw_status = i2c_smbus_read_byte_data(data->client, - SBRMI_STATUS); + ret = regmap_read(data->regmap, SBRMI_STATUS, &sw_status); if (sw_status < 0) { ret = sw_status; goto exit_unlock;
@@ -81,8 +78,6 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, }while (retry--);if (retry <0 ) { -dev_err (&data->client->dev, -"Firmware fail to indicate command completion\n" ); ret = -EIO ; goto exit_unlock; }
@@ -94,11 +89,11 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,*/ if (msg->read) {for (i =0 ; i <4 ; i++) { - ret =i2c_smbus_read_byte_data (data->client, -SBRMI_OUTBNDMSG1 + i); + ret =regmap_read (data->regmap, +SBRMI_OUTBNDMSG1 + i, &bytes);if (ret <0 ) goto exit_unlock; - msg->data_out |= ret << i *8 ; + msg->data_out |= bytes << i *8 ; } }
@@ -106,8 +101,8 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,* BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the * ALERT to initiator */ - ret =i2c_smbus_write_byte_data (data->client,SBRMI_STATUS , - sw_status |SW_ALERT_MASK ); + ret =regmap_write (data->regmap,SBRMI_STATUS , + sw_status |SW_ALERT_MASK ); exit_unlock:mutex_unlock (&data->lock);
drivers/misc/amd-sbi/rmi-core.h +2 -1
@@ -9,6 +9,7 @@#include <linux/mutex.h> #include <linux/i2c.h> #include <linux/platform_device.h> +#include <linux/regmap.h> /* SB-RMI registers */ enum sbrmi_reg {
@@ -47,7 +48,7 @@ enum sbrmi_msg_id {/* Each client has this additional data */ struct sbrmi_data { -struct i2c_client *client; +struct regmap *regmap;struct mutex lock;struct platform_device *pdev;u32 pwr_limit_max;
drivers/misc/amd-sbi/rmi-i2c.c +16 -9
@@ -13,26 +13,26 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/of.h> +#include <linux/regmap.h> #include "rmi-core.h" #define SBRMI_CTRL 0x1 -static int sbrmi_enable_alert (struct i2c_client *client) +static int sbrmi_enable_alert (struct sbrmi_data *data) { -int ctrl; +int ctrl, ret;/* * Enable the SB-RMI Software alert status * by writing 0 to bit 4 of Control register(0x1) */ - ctrl =i2c_smbus_read_byte_data (client,SBRMI_CTRL ); -if (ctrl <0 ) -return ctrl; + ret =regmap_read (data->regmap,SBRMI_CTRL , &ctrl); +if (ret <0 ) +return ret;if (ctrl &0x10 ) { ctrl &= ~0x10 ; -return i2c_smbus_write_byte_data (client, -SBRMI_CTRL , ctrl); +return regmap_write (data->regmap,SBRMI_CTRL , ctrl); }return 0 ;
@@ -57,17 +57,24 @@ static int sbrmi_i2c_probe(struct i2c_client *client) {struct device *dev = &client->dev;struct sbrmi_data *data; +struct regmap_config sbrmi_i2c_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + };int ret; data =devm_kzalloc (dev,sizeof (struct sbrmi_data ),GFP_KERNEL );if (!data)return -ENOMEM ; - data->client = client;mutex_init (&data->lock); + data->regmap =devm_regmap_init_i2c (client, &sbrmi_i2c_regmap_config); +if (IS_ERR (data->regmap)) +return PTR_ERR (data->regmap); +/* Enable alert for SB-RMI sequence */ - ret =sbrmi_enable_alert (client); + ret =sbrmi_enable_alert (data);if (ret <0 )return ret;
Signature · 1 line
2.25.1
PATCH v4 3/9 misc: amd-sbi: Optimize the wait condition for mailbox command completion
In reply to Akshay Gupta- optimize the wait condition to indicate command completion by replacing the do while loop with regmap subsystem API regmap_read_poll_timeout()
---
Changes since v3:
- New patch as per suggestion from Arnd
drivers/misc/amd-sbi/rmi-core.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
drivers/misc/amd-sbi/rmi-core.c +4 -15
@@ -25,7 +25,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg) {unsigned int bytes; -int i, ret, retry =10 ; +int i, ret;int sw_status;u8 byte;
@@ -66,21 +66,10 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,* an ALERT (if enabled) to initiator (BMC) to indicate completion * of the requested command */ -do { - ret =regmap_read (data->regmap,SBRMI_STATUS , &sw_status); -if (sw_status <0 ) { - ret = sw_status; - goto exit_unlock; - } -if (sw_status &SW_ALERT_MASK ) -break ; -usleep_range (50 ,100 ); - }while (retry--); - -if (retry <0 ) { - ret = -EIO ; + ret =regmap_read_poll_timeout (data->regmap,SBRMI_STATUS , sw_status, + sw_status &SW_ALERT_MASK ,500 ,2000000 ); +if (ret) goto exit_unlock; - }/* * For a read operation, the initiator (BMC) reads the firmware
Signature · 1 line
2.25.1
PATCH v4 4/9 misc: amd-sbi: Add support for AMD_SBI IOCTL
In reply to Akshay GuptaThe present sbrmi module only support reporting power via hwmon. However, AMD data center range of processors support various system management functionality using custom protocols defined in Advanced Platform Management Link (APML) specification.
Register a miscdevice, which creates a device /dev/sbrmiX with an IOCTL interface for the user space to invoke the APML Mailbox protocol, which is already defined in sbrmi_mailbox_xfer().
The APML protocols depend on a set of RMI registers. Having an IOCTL as a single entry point will help in providing synchronization among these protocols as multiple transactions on RMI register set may create race condition.
Support for other protocols will be added in subsequent patches.
Open-sourced and widely used https://github.com/amd/esmi_oob_library
will continue to provide user-space programmable API.
---
Changes since v3:
- Previously patch 3
- Documentation and comments changes
Changes since v2:
- update the MACROS name as per feedback
Changes since v1:
- Previously patch 5
- Add IOCTL description in ioctl-number.rst
- Split patch as per suggestion.
Documentation/misc-devices/index.rst | 1 + .../userspace-api/ioctl/ioctl-number.rst | 2 + drivers/misc/amd-sbi/rmi-core.c | 89 +++++++++++++++++-- drivers/misc/amd-sbi/rmi-core.h | 16 ++-- drivers/misc/amd-sbi/rmi-hwmon.c | 15 ++-- drivers/misc/amd-sbi/rmi-i2c.c | 25 +++++- include/uapi/misc/amd-apml.h | 66 ++++++++++++++ 7 files changed, 186 insertions(+), 28 deletions(-) create mode 100644 include/uapi/misc/amd-apml.h
Documentation/misc-devices/index.rst +1 -0
@@ -12,6 +12,7 @@ fit into other categories. :maxdepth: 2 ad525x_dpot + amd-sbi apds990x bh1770glc c2port
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
@@ -388,6 +388,8 @@ Code Seq# Include File Comments <mailto:[email protected]> 0xF8 all arch/x86/include/uapi/asm/amd_hsmp.h AMD HSMP EPYC system management interface driver <mailto:[email protected]> +0xF9 00-0F uapi/misc/amd-apml.h AMD side band system management interface driver + <mailto:[email protected]> 0xFD all linux/dm-ioctl.h 0xFE all linux/isst_if.h ==== ===== ======================================================= ================================================================
drivers/misc/amd-sbi/rmi-core.c +81 -8
124 lines not on this page · raw message
drivers/misc/amd-sbi/rmi-core.h +7 -9
@@ -6,10 +6,12 @@#ifndef _SBRMI_CORE_H_#define _SBRMI_CORE_H_ +#include <linux/miscdevice.h> #include <linux/mutex.h> #include <linux/i2c.h> #include <linux/platform_device.h> #include <linux/regmap.h> +#include <uapi/misc/amd-apml.h> /* SB-RMI registers */ enum sbrmi_reg {
@@ -48,19 +50,15 @@ enum sbrmi_msg_id {/* Each client has this additional data */ struct sbrmi_data { +struct miscdevice sbrmi_misc_dev;struct regmap *regmap; +/* Mutex locking */ struct mutex lock; -struct platform_device *pdev;u32 pwr_limit_max; +u8 dev_static_addr; }; -struct sbrmi_mailbox_msg { -u8 cmd; -bool read; -u32 data_in; -u32 data_out; -}; - -int rmi_mailbox_xfer (struct sbrmi_data *data,struct sbrmi_mailbox_msg *msg); +int rmi_mailbox_xfer (struct sbrmi_data *data,struct apml_message *msg);int create_hwmon_sensor_device (struct device *dev,struct sbrmi_data *data); +int create_misc_rmi_device (struct sbrmi_data *data,struct device *dev);#endif /*_SBRMI_CORE_H_*/
drivers/misc/amd-sbi/rmi-hwmon.c +8 -7
@@ -6,6 +6,7 @@*/ #include <linux/err.h> #include <linux/hwmon.h> +#include <uapi/misc/amd-apml.h> #include "rmi-core.h" /* Do not allow setting negative power limit */
@@ -15,7 +16,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { struct sbrmi_data *data = dev_get_drvdata(dev); -struct sbrmi_mailbox_msg msg = {0 }; +struct apml_message msg = {0 };int ret;if (!data)
@@ -24,7 +25,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type,if (type != hwmon_power)return -EINVAL ; - msg.read = true; + msg.data_in.reg_in[AMD_SBI_RD_FLAG_INDEX ] =1 ;switch (attr) {case hwmon_power_input: msg.cmd =SBRMI_READ_PKG_PWR_CONSUMPTION ;
@@ -35,7 +36,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, ret =rmi_mailbox_xfer (data, &msg);break ;case hwmon_power_cap_max: - msg.data_out = data->pwr_limit_max; + msg.data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX ] = data->pwr_limit_max; ret =0 ;break ;default :
@@ -44,7 +45,7 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type,if (ret <0 )return ret;/* hwmon power attributes are in microWatt */ - *val = (long )msg.data_out *1000 ; + *val = (long )msg.data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX ] *1000 ;return ret; }
@@ -52,7 +53,7 @@ static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { struct sbrmi_data *data = dev_get_drvdata(dev); -struct sbrmi_mailbox_msg msg = {0 }; +struct apml_message msg = {0 };if (!data)return -ENODEV ;
@@ -68,8 +69,8 @@ static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, val =clamp_val (val,SBRMI_PWR_MIN , data->pwr_limit_max); msg.cmd =SBRMI_WRITE_PKG_PWR_LIMIT ; - msg.data_in = val; - msg.read = false; + msg.data_in.mb_in[AMD_SBI_RD_WR_DATA_INDEX ] = val; + msg.data_in.reg_in[AMD_SBI_RD_FLAG_INDEX ] =0 ;return rmi_mailbox_xfer (data, &msg); }
drivers/misc/amd-sbi/rmi-i2c.c +21 -4
@@ -40,15 +40,15 @@ static int sbrmi_enable_alert(struct sbrmi_data *data)static int sbrmi_get_max_pwr_limit (struct sbrmi_data *data) { -struct sbrmi_mailbox_msg msg = {0 }; +struct apml_message msg = {0 };int ret; msg.cmd =SBRMI_READ_PKG_MAX_PWR_LIMIT ; - msg.read = true; + msg.data_in.reg_in[AMD_SBI_RD_FLAG_INDEX ] =1 ; ret =rmi_mailbox_xfer (data, &msg);if (ret <0 )return ret; - data->pwr_limit_max = msg.data_out; + data->pwr_limit_max = msg.data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX ];return ret; }
@@ -83,8 +83,24 @@ static int sbrmi_i2c_probe(struct i2c_client *client)if (ret <0 )return ret; + data->dev_static_addr = client->addr;dev_set_drvdata (dev, data); -return create_hwmon_sensor_device (dev, data); + ret =create_hwmon_sensor_device (dev, data); +if (ret <0 ) +return ret; +return create_misc_rmi_device (data, dev); +} + +static void sbrmi_i2c_remove (struct i2c_client *client) +{ +struct sbrmi_data *data =dev_get_drvdata (&client->dev); + +misc_deregister (&data->sbrmi_misc_dev); +/* Assign fops and parent of misc dev to NULL */ + data->sbrmi_misc_dev.fops =NULL ; + data->sbrmi_misc_dev.parent =NULL ; +dev_info (&client->dev,"Removed sbrmi-i2c driver\n" ); +return ; }static const struct i2c_device_id sbrmi_id[] = {
@@ -107,6 +123,7 @@ static struct i2c_driver sbrmi_driver = { .of_match_table = of_match_ptr(sbrmi_of_match), }, .probe = sbrmi_i2c_probe, + .remove = sbrmi_i2c_remove, .id_table = sbrmi_id, };
include/uapi/misc/amd-apml.h new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.25.1
Greg KH
maintainerRe: [PATCH v4 4/9] misc: amd-sbi: Add support for AMD_SBI IOCTL
drivers/misc/amd-sbi/rmi-core.c int rmi_mailbox_xfer(struct sbrmi_data *data, · line 170
Quoted 1 line · Akshay Gupta
drivers/misc/amd-sbi/rmi-core.c +1
-0+dev_info (dev,"register %s device\n" , data->sbrmi_misc_dev.name);
When drivers work properly, they are quiet. Please remove this line.
Re: [PATCH v4 4/9] misc: amd-sbi: Add support for AMD_SBI IOCTL
Quoted 6 lines · Greg KH
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 1 line · Akshay Gupta
+
dev_info(dev, "register %s device\n", data->sbrmi_misc_dev.name);When drivers work properly, they are quiet. Please remove this line.
Thanks, will remove.
Greg KH
maintainerRe: [PATCH v4 4/9] misc: amd-sbi: Add support for AMD_SBI IOCTL
In reply to Akshay Guptadrivers/misc/amd-sbi/rmi-core.c int rmi_mailbox_xfer(struct sbrmi_data *data, · line 130
Quoted 7 lines · Akshay Gupta
drivers/misc/amd-sbi/rmi-core.c +7
-0+switch (msg.cmd) { + case 0 ... 0x999: +/* Mailbox protocol */ + ret =rmi_mailbox_xfer (data, &msg); +break ; +default : +pr_err ("Command:0x%x not recognized\n" , msg.cmd);
You now just allowed userspace to spam the kernel logs for no good reason :(
Also, always use dev_*() calls in a driver, not pr_*() ones, as then you will know exactly what driver/device is sending out the message.
Review
Quoted 1 line
(quoted diff) +1
-0+ break;
And you returned the wrong error code if this happens :(
greg k-h
Re: [PATCH v4 4/9] misc: amd-sbi: Add support for AMD_SBI IOCTL
Quoted 11 lines · Greg KH
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
drivers/misc/amd-sbi/rmi-core.c int rmi_mailbox_xfer(struct sbrmi_data *data, · line 130
Quoted 7 lines · Akshay Gupta
drivers/misc/amd-sbi/rmi-core.c +7
-0+switch (msg.cmd) { + case 0 ... 0x999: +/* Mailbox protocol */ + ret =rmi_mailbox_xfer (data, &msg); +break ; +default : +pr_err ("Command:0x%x not recognized\n" , msg.cmd);
Quoted 2 lines
You now just allowed userspace to spam the kernel logs for no good reason :(
Thanks, will remove the pr_err to not to spam the logs.
Quoted 3 lines
Also, always use dev_*() calls in a driver, not pr_*() ones, as then you will know exactly what driver/device is sending out the message.
Thank you for the input, will do.
Quoted 5 lines
Quoted 2 lines
+ break;
And you returned the wrong error code if this happens :(
greg k-h
my bad, will take care of this.
PATCH v4 5/9 misc: amd-sbi: Add support for mailbox error codes
In reply to Akshay GuptaAPML mailbox protocol returns additional error codes written by SMU firmware in the out-bound register 0x37. These errors include, invalid core, message not supported over platform and others. This additional error codes can be used to provide more details to userspace.
---
Changes since v3:
- update ioctl comment description
Changes since v1:
- bifurcated from previous patch 5
drivers/misc/amd-sbi/rmi-core.c | 12 +++++++++++- include/uapi/misc/amd-apml.h | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-)
drivers/misc/amd-sbi/rmi-core.c +11 -1
@@ -27,13 +27,15 @@int rmi_mailbox_xfer (struct sbrmi_data *data,struct apml_message *msg) { -unsigned int bytes; +unsigned int bytes, ec;int i, ret;int sw_status;u8 byte;mutex_lock (&data->lock); + msg->fw_ret_code =0 ; +/* Indicate firmware a command is to be serviced */ ret =regmap_write (data->regmap,SBRMI_INBNDMSG7 ,START_CMD );if (ret <0 )
@@ -74,6 +76,9 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,if (ret) goto exit_unlock; + ret =regmap_read (data->regmap,SBRMI_OUTBNDMSG7 , &ec); +if (ret || ec) + goto exit_clear_alert;/* * For a read operation, the initiator (BMC) reads the firmware * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1]
@@ -89,12 +94,17 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, } } +exit_clear_alert:/* * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the * ALERT to initiator */ ret =regmap_write (data->regmap,SBRMI_STATUS , sw_status |SW_ALERT_MASK ); +if (ec) { + ret = -EPROTOTYPE ; + msg->fw_ret_code = ec; + } exit_unlock:mutex_unlock (&data->lock);return ret;
include/uapi/misc/amd-apml.h +5 -0
@@ -38,6 +38,10 @@ struct apml_message {__u32 mb_in[2 ];__u8 reg_in[8 ]; } data_in; +/* +* Error code is returned in case of soft mailbox +*/ +__u32 fw_ret_code; } __attribute__((packed));/**
@@ -60,6 +64,7 @@ struct apml_message {* The APML RMI module checks whether the cmd is * - Mailbox message read/write(0x0~0x999) * - returning "-EFAULT" if none of the above +* "-EPROTOTYPE" error is returned to provide additional error details */ #define SBRMI_IOCTL_CMD _IOWR(SB_BASE_IOCTL_NR, 0, struct apml_message)
Signature · 1 line
2.25.1
Greg KH
maintainerRe: [PATCH v4 5/9] misc: amd-sbi: Add support for mailbox error codes
include/uapi/misc/amd-apml.h struct apml_message { · line 45
Quoted 11 lines · Akshay Gupta
include/uapi/misc/amd-apml.h +4
-0@@ -38,6 +38,10 @@ struct apml_message {__u32 mb_in[2 ];__u8 reg_in[8 ]; } data_in; +/* +* Error code is returned in case of soft mailbox +*/ +__u32 fw_ret_code; } __attribute__((packed));
You can not just randomly change the size of a user/kernel structure like this, what just broke because of this?
confused,
greg k-h
Re: [PATCH v4 5/9] misc: amd-sbi: Add support for mailbox error codes
Quoted 18 lines · Greg KH
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
include/uapi/misc/amd-apml.h struct apml_message { · line 45
Quoted 11 lines · Akshay Gupta
include/uapi/misc/amd-apml.h +4
-0@@ -38,6 +38,10 @@ struct apml_message {__u32 mb_in[2 ];__u8 reg_in[8 ]; } data_in; +/* +* Error code is returned in case of soft mailbox +*/ +__u32 fw_ret_code; } __attribute__((packed));You can not just randomly change the size of a user/kernel structure like this, what just broke because of this?
Quoted 1 line
confused,
The changes are not because of anything is broken, we support 3 different protocol under 1 IOCTL using the same structure. I split the patch to make it easy to review. Modification in patch 4, is only for the existing code. This patch (patch 5) has additional functionality, so we do not want add multiple changes in single patch (patch 4).
The changes done in patches are as follows:
Patch 4:
- Adding basic structure as per current protocol in upstream kernel
Patch 5:
- Adding additional error code from PMFW.
Patch 6:
- Add changes required to support CPUID protocol
Patch 7:
- Comments modification for MCAMSR protocol (structure remains same as CPUID)
Quoted 2 lines
greg k-h
Greg KH
maintainerRe: [PATCH v4 5/9] misc: amd-sbi: Add support for mailbox error codes
Quoted 28 lines · Akshay
Quoted 18 lines · Greg KH
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
include/uapi/misc/amd-apml.h struct apml_message { · line 45
Quoted 11 lines · Akshay Gupta
include/uapi/misc/amd-apml.h +4
-0@@ -38,6 +38,10 @@ struct apml_message {__u32 mb_in[2 ];__u8 reg_in[8 ]; } data_in; +/* +* Error code is returned in case of soft mailbox +*/ +__u32 fw_ret_code; } __attribute__((packed));You can not just randomly change the size of a user/kernel structure like this, what just broke because of this?
Quoted 1 line
confused,
The changes are not because of anything is broken, we support 3 different protocol under 1 IOCTL using the same structure. I split the patch to make it easy to review.
Modification in patch 4, is only for the existing code. This patch (patch 5) has additional functionality, so we do not want add multiple changes in single patch (patch 4).
Quoted 5 lines
The changes done in patches are as follows:
Patch 4:
- Adding basic structure as per current protocol in upstream kernel
So what if we only take the first 4 patches? Now any changes after that would change the user/kernel api and break things.
Please don't write changes and then "fix them up" later on, that's not how to do stuff as it makes it very difficult to review. What would you want to see if _you_ had to review this patch series?
thanks,
greg k-h
Re: [PATCH v4 5/9] misc: amd-sbi: Add support for mailbox error codes
Quoted 31 lines · Greg KH
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 27 lines · Akshay
Quoted 18 lines · Greg KH
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
include/uapi/misc/amd-apml.h struct apml_message { · line 45
Quoted 11 lines · Akshay Gupta
include/uapi/misc/amd-apml.h +4
-0@@ -38,6 +38,10 @@ struct apml_message {__u32 mb_in[2 ];__u8 reg_in[8 ]; } data_in; +/* +* Error code is returned in case of soft mailbox +*/ +__u32 fw_ret_code; } __attribute__((packed));You can not just randomly change the size of a user/kernel structure like this, what just broke because of this?
Quoted 1 line
confused,
The changes are not because of anything is broken, we support 3 different protocol under 1 IOCTL using the same structure. I split the patch to make it easy to review.
Modification in patch 4, is only for the existing code. This patch (patch 5) has additional functionality, so we do not want add multiple changes in single patch (patch 4).
Quoted 7 lines
Quoted 5 lines
The changes done in patches are as follows:
Patch 4:
- Adding basic structure as per current protocol in upstream kernel
So what if we only take the first 4 patches? Now any changes after that would change the user/kernel api and break things.
Yes, it will break. We need all the patches to go.
Quoted 4 lines
Please don't write changes and then "fix them up" later on, that's not how to do stuff as it makes it very difficult to review. What would you want to see if _you_ had to review this patch series?
We submitted a single patch in v1, later split the patch based on each functionality for ease of review.
I will squash and submit along with other review comments addressed.
Quoted 4 lines
thanks,
greg k-h
Greg KH
maintainerRe: [PATCH v4 5/9] misc: amd-sbi: Add support for mailbox error codes
Quoted 35 lines · Akshay
Quoted 33 lines · Greg KH
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 29 lines · Akshay
Quoted 18 lines · Greg KH
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
include/uapi/misc/amd-apml.h struct apml_message { · line 45
Quoted 11 lines · Akshay Gupta
include/uapi/misc/amd-apml.h +4
-0@@ -38,6 +38,10 @@ struct apml_message {__u32 mb_in[2 ];__u8 reg_in[8 ]; } data_in; +/* +* Error code is returned in case of soft mailbox +*/ +__u32 fw_ret_code; } __attribute__((packed));You can not just randomly change the size of a user/kernel structure like this, what just broke because of this?
Quoted 1 line
confused,
The changes are not because of anything is broken, we support 3 different protocol under 1 IOCTL using the same structure. I split the patch to make it easy to review.
Modification in patch 4, is only for the existing code. This patch (patch 5) has additional functionality, so we do not want add multiple changes in single patch (patch 4).The changes done in patches are as follows:
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Patch 4:
- Adding basic structure as per current protocol in upstream kernel
So what if we only take the first 4 patches? Now any changes after that would change the user/kernel api and break things.
Yes, it will break. We need all the patches to go.
That's not how to submit a patch series. Please work with the other kernel developers at your company to do this right before resubmitting. You shouldn't rely on the community to point out basic engineering problems like this. Would you want to review a series like this?
Quoted 8 lines
Quoted 3 lines
Please don't write changes and then "fix them up" later on, that's not how to do stuff as it makes it very difficult to review. What would you want to see if _you_ had to review this patch series?
We submitted a single patch in v1, later split the patch based on each functionality for ease of review.
I will squash and submit along with other review comments addressed.
No, don't squash, do it in a patch series, one at a time properly such that if we were to take any moment in time of the series, all would still work correctly. That's the proper way to do any sort of software engineering, this isn't unique to us at all.
thanks,
greg k-h
Re: [PATCH v4 5/9] misc: amd-sbi: Add support for mailbox error codes
Quoted 56 lines · Greg KH
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 32 lines · Akshay
Quoted 31 lines · Greg KH
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 27 lines · Akshay
Quoted 18 lines · Greg KH
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
include/uapi/misc/amd-apml.h struct apml_message { · line 45
Quoted 11 lines · Akshay Gupta
include/uapi/misc/amd-apml.h +4
-0@@ -38,6 +38,10 @@ struct apml_message {__u32 mb_in[2 ];__u8 reg_in[8 ]; } data_in; +/* +* Error code is returned in case of soft mailbox +*/ +__u32 fw_ret_code; } __attribute__((packed));You can not just randomly change the size of a user/kernel structure like this, what just broke because of this?
Quoted 1 line
confused,
The changes are not because of anything is broken, we support 3 different protocol under 1 IOCTL using the same structure. I split the patch to make it easy to review.
Modification in patch 4, is only for the existing code. This patch (patch 5) has additional functionality, so we do not want add multiple changes in single patch (patch 4).Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
The changes done in patches are as follows:
Patch 4:
- Adding basic structure as per current protocol in upstream kernel
So what if we only take the first 4 patches? Now any changes after that would change the user/kernel api and break things.
Yes, it will break. We need all the patches to go.
That's not how to submit a patch series. Please work with the other kernel developers at your company to do this right before resubmitting. You shouldn't rely on the community to point out basic engineering problems like this. Would you want to review a series like this?
Quoted 7 lines
Quoted 3 lines
Please don't write changes and then "fix them up" later on, that's not how to do stuff as it makes it very difficult to review. What would you want to see if _you_ had to review this patch series?
We submitted a single patch in v1, later split the patch based on each functionality for ease of review.
I will squash and submit along with other review comments addressed.
Quoted 8 lines
No, don't squash, do it in a patch series, one at a time properly such that if we were to take any moment in time of the series, all would still work correctly. That's the proper way to do any sort of software engineering, this isn't unique to us at all.
thanks,
greg k-h
Hi Greg,
We have compiled and verified individual patch in the patch-set over reference BMC platforms.
We have an open-sourced user space library https://github.com/amd/esmi_oob_library/ <https://github.com/amd/esmi_oob_library/> which depend on the out-of-tree kernel modules open-sourced https://github.com/amd/apml_modules. <https://github.com/amd/apml_modules.>
This patch-set is an effort to upstream the out-of-tree kernel modules open-sourced at https://github.com/amd/apml_modules <https://github.com/amd/apml_modules>.
After all the patches are accepted into the Linux, we want to update the user-space consumers to move to drivers from Linux kernel and deprecate out-of-tree modules.
Thanks,
Akshay
PATCH v4 6/9 misc: amd-sbi: Add support for CPUID protocol
In reply to Akshay Gupta- AMD provides custom protocol to read Processor feature capabilities and configuration information through side band. The information is accessed by providing CPUID Function, extended function and thread ID to the protocol. Undefined function returns 0.
---
Changes since v3:
- Address review comments:
- update the #define to inline function
- pack the union inside the structure
Changes since v2:
- update the MACROS name as per feedback
Changes since v1:
- bifurcated from previous patch 5
drivers/misc/amd-sbi/rmi-core.c | 148 ++++++++++++++++++++++++++++++++ drivers/misc/amd-sbi/rmi-core.h | 5 +- include/uapi/misc/amd-apml.h | 16 ++++ 3 files changed, 168 insertions(+), 1 deletion(-)
drivers/misc/amd-sbi/rmi-core.c +148 -0
@@ -17,6 +17,8 @@/* Mask for Status Register bit[1] */ #define SW_ALERT_MASK 0x2 +/* Mask to check H/W Alert status bit */ +#define HW_ALERT_MASK 0x80/* Do not allow setting negative power limit */ #define SBRMI_PWR_MIN 0
@@ -24,6 +26,149 @@#define START_CMD 0x80#define TRIGGER_MAILBOX 0x01 +/* Default message lengths as per APML command protocol */ +/* CPUID */ +#define CPUID_RD_DATA_LEN 0x8 +#define CPUID_WR_DATA_LEN 0x8 +#define CPUID_RD_REG_LEN 0xa +#define CPUID_WR_REG_LEN 0x9 + +/* CPUID MSR Command Ids */ +#define CPUID_MCA_CMD 0x73 +#define RD_CPUID_CMD 0x91 + +/* input for bulk write to CPUID protocol */ +struct cpu_msr_indata { +u8 wr_len;/* const value */ +u8 rd_len;/* const value */ +u8 proto_cmd;/* const value */ +u8 thread;/* thread number */ +union { +u8 reg_offset[4 ];/* input value */ +u32 value; + } __packed; +u8 ext;/* extended function */ +}; + +/* output for bulk read from CPUID protocol */ +struct cpu_msr_outdata { +u8 num_bytes;/* number of bytes return */ +u8 status;/* Protocol status code */ +union { +u64 value; +u8 reg_data[8 ]; + } __packed; +}; + +static inline void prepare_cpuid_input_message (struct cpu_msr_indata *input, +u8 thread_id,u32 func, +u8 ext_func) +{ + input->rd_len =CPUID_RD_DATA_LEN ; + input->wr_len =CPUID_WR_DATA_LEN ; + input->proto_cmd =RD_CPUID_CMD ; + input->thread = thread_id <<1 ; + input->value = func; + input->ext = ext_func; +} + +static int sbrmi_get_rev (struct sbrmi_data *data) +{ +struct apml_message msg = {0 }; +int ret; + + msg.data_in.reg_in[AMD_SBI_REG_OFF_INDEX ] =SBRMI_REV ; + msg.data_in.reg_in[AMD_SBI_RD_FLAG_INDEX ] =1 ; + ret =regmap_read (data->regmap, + msg.data_in.reg_in[AMD_SBI_REG_OFF_INDEX ], + &msg.data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX ]); +if (ret <0 ) +return ret; + + data->rev = msg.data_out.reg_out[AMD_SBI_RD_WR_DATA_INDEX ]; +return 0 ; +} + +/* Read CPUID function protocol */ +static int rmi_cpuid_read (struct sbrmi_data *data, +struct apml_message *msg) +{ +struct cpu_msr_indata input = {0 }; +struct cpu_msr_outdata output = {0 }; +int val =0 ; +int ret, hw_status; +u16 thread; + +mutex_lock (&data->lock); +/* cache the rev value to identify if protocol is supported or not */ +if (!data->rev) { + ret =sbrmi_get_rev (data); +if (ret <0 ) + goto exit_unlock; + } +/* CPUID protocol for REV 0x10 is not supported*/ +if (data->rev ==0x10 ) { + ret = -EOPNOTSUPP ; + goto exit_unlock; + } + + thread = msg->data_in.reg_in[AMD_SBI_THREAD_LOW_INDEX ] | + msg->data_in.reg_in[AMD_SBI_THREAD_HI_INDEX ] <<8 ; + +/* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */ +if (thread >127 ) { + thread -=128 ; + val =1 ; + } + ret =regmap_write (data->regmap,SBRMI_THREAD128CS , val); +if (ret <0 ) + goto exit_unlock; + +prepare_cpuid_input_message (&input, thread, + msg->data_in.mb_in[AMD_SBI_RD_WR_DATA_INDEX ], + msg->data_in.reg_in[AMD_SBI_EXT_FUNC_INDEX ]); + + ret =regmap_bulk_write (data->regmap,CPUID_MCA_CMD , + &input,CPUID_WR_REG_LEN ); +if (ret <0 ) + goto exit_unlock; + +/* +* For RMI Rev 0x20, new h/w status bit is introduced. which is used +* by firmware to indicate completion of commands (0x71, 0x72, 0x73). +* wait for the status bit to be set by the hardware before +* reading the data out. +*/ + ret =regmap_read_poll_timeout (data->regmap,SBRMI_STATUS , hw_status, + hw_status &HW_ALERT_MASK ,500 ,2000000 ); +if (ret) + goto exit_unlock; + + ret =regmap_bulk_read (data->regmap,CPUID_MCA_CMD , + &output,CPUID_RD_REG_LEN ); +if (ret <0 ) + goto exit_unlock; + + ret =regmap_write (data->regmap,SBRMI_STATUS , +HW_ALERT_MASK ); +if (ret <0 ) + goto exit_unlock; + +if (output.num_bytes !=CPUID_RD_REG_LEN -1 ) { + ret = -EMSGSIZE ; + goto exit_unlock; + } +if (output.status) { + ret = -EPROTOTYPE ; + msg->fw_ret_code = output.status; + goto exit_unlock; + } + msg->data_out.cpu_msr_out = output.value; +exit_unlock: +mutex_unlock (&data->lock); +return ret; +} +int rmi_mailbox_xfer (struct sbrmi_data *data,struct apml_message *msg) {
@@ -136,6 +281,9 @@ static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)/* Mailbox protocol */ ret =rmi_mailbox_xfer (data, &msg);break ; +case APML_CPUID : + ret =rmi_cpuid_read (data, &msg); +break ;default :pr_err ("Command:0x%x not recognized\n" , msg.cmd);break ;
drivers/misc/amd-sbi/rmi-core.h +4 -1
@@ -15,7 +15,8 @@/* SB-RMI registers */ enum sbrmi_reg { -SBRMI_CTRL =0x01 , +SBRMI_REV =0x00 , +SBRMI_CTRL ,SBRMI_STATUS ,SBRMI_OUTBNDMSG0 =0x30 ,SBRMI_OUTBNDMSG1 ,
@@ -34,6 +35,7 @@ enum sbrmi_reg {SBRMI_INBNDMSG6 ,SBRMI_INBNDMSG7 ,SBRMI_SW_INTERRUPT , + SBRMI_THREAD128CS = 0x4b, };/*
@@ -56,6 +58,7 @@ struct sbrmi_data {struct mutex lock;u32 pwr_limit_max;u8 dev_static_addr; +u8 rev; };int rmi_mailbox_xfer (struct sbrmi_data *data,struct apml_message *msg);
include/uapi/misc/amd-apml.h +16 -0
@@ -7,38 +7,53 @@#include <linux/types.h> +/* command ID to identify CPUID protocol */ +#define APML_CPUID 0x1000/* These are byte indexes into data_in and data_out arrays */ #define AMD_SBI_RD_WR_DATA_INDEX 0#define AMD_SBI_REG_OFF_INDEX 0#define AMD_SBI_REG_VAL_INDEX 4#define AMD_SBI_RD_FLAG_INDEX 7 +#define AMD_SBI_THREAD_LOW_INDEX 4 +#define AMD_SBI_THREAD_HI_INDEX 5 +#define AMD_SBI_EXT_FUNC_INDEX 6#define AMD_SBI_MB_DATA_SIZE 4struct apml_message {/* message ids: * Mailbox Messages: 0x0 ... 0x999 +* APML_CPUID: 0x1000 */ __u32 cmd;/* * 8 bit data for reg read, * 32 bit data in case of mailbox, +* up to 64 bit in case of cpuid */ union { +__u64 cpu_msr_out;__u32 mb_out[2 ];__u8 reg_out[8 ]; } data_out;/* * [0]...[3] mailbox 32bit input +* cpuid, +* [4][5] cpuid: thread +* [6] cpuid: ext function & read eax/ebx or ecx/edx +* [7:0] -> bits [7:4] -> ext function & +* bit [0] read eax/ebx or ecx/edx * [7] read/write functionality */ union { +__u64 cpu_msr_in;__u32 mb_in[2 ];__u8 reg_in[8 ]; } data_in;/* +* Status code is returned in case of CPUID access * Error code is returned in case of soft mailbox */ __u32 fw_ret_code;
@@ -63,6 +78,7 @@ struct apml_message {* The IOCTL provides userspace access to AMD sideband protocols * The APML RMI module checks whether the cmd is * - Mailbox message read/write(0x0~0x999) +* - CPUID read(0x1000) * - returning "-EFAULT" if none of the above * "-EPROTOTYPE" error is returned to provide additional error details */
Signature · 1 line
2.25.1
PATCH v4 7/9 misc: amd-sbi: Add support for MCA register protocol
In reply to Akshay Gupta- AMD provides custom protocol to read Machine Check Architecture(MCA) registers over sideband. The inforamtion is accessed for range of MCA registers by passing register address and thread ID to the protocol. Access is read-only
---
Changes since v3:
- Address review comments:
- update the #define to inline function
- pack the union inside the structure
Changes since v2:
- update the MACROS name as per feedback
Changes since v1:
- bifurcated from previous patch 5
drivers/misc/amd-sbi/rmi-core.c | 100 ++++++++++++++++++++++++++++++++ include/uapi/misc/amd-apml.h | 18 ++++-- 2 files changed, 112 insertions(+), 6 deletions(-)
drivers/misc/amd-sbi/rmi-core.c +100 -0
@@ -32,10 +32,16 @@#define CPUID_WR_DATA_LEN 0x8#define CPUID_RD_REG_LEN 0xa#define CPUID_WR_REG_LEN 0x9 +/* MSR */ +#define MSR_RD_REG_LEN 0xa +#define MSR_WR_REG_LEN 0x8 +#define MSR_RD_DATA_LEN 0x8 +#define MSR_WR_DATA_LEN 0x7/* CPUID MSR Command Ids */ #define CPUID_MCA_CMD 0x73#define RD_CPUID_CMD 0x91 +#define RD_MCA_CMD 0x86/* input for bulk write to CPUID protocol */ struct cpu_msr_indata {
@@ -72,6 +78,16 @@ static inline void prepare_cpuid_input_message(struct cpu_msr_indata *input, input->ext = ext_func; } +static inline void prepare_mca_msr_input_message (struct cpu_msr_indata *input, +u8 thread_id,u32 data_in) +{ + input->rd_len =MSR_RD_DATA_LEN ; + input->wr_len =MSR_WR_DATA_LEN ; + input->proto_cmd =RD_MCA_CMD ; + input->thread = thread_id <<1 ; + input->value = data_in; +} +static int sbrmi_get_rev (struct sbrmi_data *data) {struct apml_message msg = {0 };
@@ -169,6 +185,86 @@ static int rmi_cpuid_read(struct sbrmi_data *data,return ret; } +/* MCA MSR protocol */ +static int rmi_mca_msr_read (struct sbrmi_data *data, +struct apml_message *msg) +{ +struct cpu_msr_outdata output = {0 }; +struct cpu_msr_indata input = {0 }; +int ret, val =0 ; +int hw_status; +u16 thread; + +mutex_lock (&data->lock); +/* cache the rev value to identify if protocol is supported or not */ +if (!data->rev) { + ret =sbrmi_get_rev (data); +if (ret <0 ) + goto exit_unlock; + } +/* MCA MSR protocol for REV 0x10 is not supported*/ +if (data->rev ==0x10 ) { + ret = -EOPNOTSUPP ; + goto exit_unlock; + } + + thread = msg->data_in.reg_in[AMD_SBI_THREAD_LOW_INDEX ] | + msg->data_in.reg_in[AMD_SBI_THREAD_HI_INDEX ] <<8 ; + +/* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */ +if (thread >127 ) { + thread -=128 ; + val =1 ; + } + ret =regmap_write (data->regmap,SBRMI_THREAD128CS , val); +if (ret <0 ) + goto exit_unlock; + +prepare_mca_msr_input_message (&input, thread, + msg->data_in.mb_in[AMD_SBI_RD_WR_DATA_INDEX ]); + + ret =regmap_bulk_write (data->regmap,CPUID_MCA_CMD , + &input,MSR_WR_REG_LEN ); +if (ret <0 ) + goto exit_unlock; + +/* +* For RMI Rev 0x20, new h/w status bit is introduced. which is used +* by firmware to indicate completion of commands (0x71, 0x72, 0x73). +* wait for the status bit to be set by the hardware before +* reading the data out. +*/ + ret =regmap_read_poll_timeout (data->regmap,SBRMI_STATUS , hw_status, + hw_status &HW_ALERT_MASK ,500 ,2000000 ); +if (ret) + goto exit_unlock; + + ret =regmap_bulk_read (data->regmap,CPUID_MCA_CMD , + &output,MSR_RD_REG_LEN ); +if (ret <0 ) + goto exit_unlock; + + ret =regmap_write (data->regmap,SBRMI_STATUS , +HW_ALERT_MASK ); +if (ret <0 ) + goto exit_unlock; + +if (output.num_bytes !=MSR_RD_REG_LEN -1 ) { + ret = -EMSGSIZE ; + goto exit_unlock; + } +if (output.status) { + ret = -EPROTOTYPE ; + msg->fw_ret_code = output.status; + goto exit_unlock; + } + msg->data_out.cpu_msr_out = output.value; + +exit_unlock: +mutex_unlock (&data->lock); +return ret; +} +int rmi_mailbox_xfer (struct sbrmi_data *data,struct apml_message *msg) {
@@ -284,6 +380,10 @@ static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)case APML_CPUID : ret =rmi_cpuid_read (data, &msg);break ; +case APML_MCA_MSR : +/* MCAMSR protocol */ + ret =rmi_mca_msr_read (data, &msg); +break ;default :pr_err ("Command:0x%x not recognized\n" , msg.cmd);break ;
include/uapi/misc/amd-apml.h +12 -6
@@ -7,8 +7,11 @@#include <linux/types.h> -/* command ID to identify CPUID protocol */ -#define APML_CPUID 0x1000 +enum apml_protocol { +APML_CPUID =0x1000 , +APML_MCA_MSR , +}; +/* These are byte indexes into data_in and data_out arrays */ #define AMD_SBI_RD_WR_DATA_INDEX 0#define AMD_SBI_REG_OFF_INDEX 0
@@ -24,13 +27,14 @@ struct apml_message {/* message ids: * Mailbox Messages: 0x0 ... 0x999 * APML_CPUID: 0x1000 +* APML_MCA_MSR: 0x1001 */ __u32 cmd;/* * 8 bit data for reg read, * 32 bit data in case of mailbox, -* up to 64 bit in case of cpuid +* up to 64 bit in case of cpuid and mca msr */ union {__u64 cpu_msr_out;
@@ -40,8 +44,9 @@ struct apml_message {/* * [0]...[3] mailbox 32bit input -* cpuid, -* [4][5] cpuid: thread +* cpuid & mca msr, +* [4][5] cpuid & mca msr: thread +* [4] rmi reg wr: value * [6] cpuid: ext function & read eax/ebx or ecx/edx * [7:0] -> bits [7:4] -> ext function & * bit [0] read eax/ebx or ecx/edx
@@ -53,7 +58,7 @@ struct apml_message {__u8 reg_in[8 ]; } data_in;/* -* Status code is returned in case of CPUID access +* Status code is returned in case of CPUID/MCA access * Error code is returned in case of soft mailbox */ __u32 fw_ret_code;
@@ -79,6 +84,7 @@ struct apml_message {* The APML RMI module checks whether the cmd is * - Mailbox message read/write(0x0~0x999) * - CPUID read(0x1000) +* - MCAMSR read(0x1001) * - returning "-EFAULT" if none of the above * "-EPROTOTYPE" error is returned to provide additional error details */
Signature · 1 line
2.25.1
PATCH v4 8/9 misc: amd-sbi: Add supoort for register xfer
In reply to Akshay Gupta- Provide user register access over IOCTL.
Both register read and write are supported.
- APML interface does not provide a syncronysation method. By defining, a register access path, we use APML modules and library for all APML transactions. Without having to use external tools such as i2c-tools, which may cause race conditions.
---
Changes since v2:
- Add ioctl description comment
Changes since v2:
- update the MACROS name as per feedback
Changes since v1:
- bifurcated from previous patch 5
drivers/misc/amd-sbi/rmi-core.c | 22 ++++++++++++++++++++++ include/uapi/misc/amd-apml.h | 4 ++++ 2 files changed, 26 insertions(+)
drivers/misc/amd-sbi/rmi-core.c +22 -0
@@ -351,6 +351,24 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,return ret; } +static int rmi_register_xfer (struct sbrmi_data *data, +struct apml_message *msg) +{ +int ret; + +mutex_lock (&data->lock); +if (msg->data_in.reg_in[AMD_SBI_RD_FLAG_INDEX ]) + ret =regmap_read (data->regmap, + msg->data_in.reg_in[AMD_SBI_REG_OFF_INDEX ], + &msg->data_out.mb_out[AMD_SBI_RD_WR_DATA_INDEX ]); +else + ret =regmap_write (data->regmap, + msg->data_in.reg_in[AMD_SBI_REG_OFF_INDEX ], + msg->data_in.reg_in[AMD_SBI_REG_VAL_INDEX ]); +mutex_unlock (&data->lock); +return ret; +} +static long sbrmi_ioctl (struct file *fp,unsigned int cmd,unsigned long arg) {int __user *arguser = (int __user *)arg;
@@ -384,6 +402,10 @@ static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)/* MCAMSR protocol */ ret =rmi_mca_msr_read (data, &msg);break ; +case APML_REG : +/* REG R/W */ + ret =rmi_register_xfer (data, &msg); +break ;default :pr_err ("Command:0x%x not recognized\n" , msg.cmd);break ;
include/uapi/misc/amd-apml.h +4 -0
@@ -10,6 +10,7 @@enum apml_protocol {APML_CPUID =0x1000 ,APML_MCA_MSR , +APML_REG , };/* These are byte indexes into data_in and data_out arrays */
@@ -28,6 +29,7 @@ struct apml_message {* Mailbox Messages: 0x0 ... 0x999 * APML_CPUID: 0x1000 * APML_MCA_MSR: 0x1001 +* APML_REG: 0x1002 */ __u32 cmd;
@@ -45,6 +47,7 @@ struct apml_message {/* * [0]...[3] mailbox 32bit input * cpuid & mca msr, +* rmi rd/wr: reg_offset * [4][5] cpuid & mca msr: thread * [4] rmi reg wr: value * [6] cpuid: ext function & read eax/ebx or ecx/edx
@@ -85,6 +88,7 @@ struct apml_message {* - Mailbox message read/write(0x0~0x999) * - CPUID read(0x1000) * - MCAMSR read(0x1001) +* - Register read/write(0x1002) * - returning "-EFAULT" if none of the above * "-EPROTOTYPE" error is returned to provide additional error details */
Signature · 1 line
2.25.1
PATCH v4 9/9 misc: amd-sbi: Add document for AMD SB IOCTL description
In reply to Akshay Gupta- This document provide AMD side band IOCTL description defined for APML and its usage.
Multiple AMD custom protocols defined for side band system management uses this IOCTL.
User space C-APIs are made available by esmi_oob_library, hosted at
https://github.com/amd/esmi_oob_library which is provided by the E-SMS project https://www.amd.com/en/developer/e-sms.html.
---
Changes since v2:
- Address the review comments
Changes since v2:
- update the MACROS name as per feedback
Changes since v1:
- New patch
Documentation/misc-devices/amd-sbi.rst | 84 ++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Documentation/misc-devices/amd-sbi.rst
Documentation/misc-devices/amd-sbi.rst new file +84 -0
@@ -0,0 +1,84 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================= +AMD SIDE BAND interface +======================= + +AMD server line of processors supports system management +functionality via side-band interface (SBI) called +Advanced Platform Management Link (APML). APML is an I2C/I3C +based 2-wire processor target interface. APML is used to +communicate with the Remote Management Interface +(SB Remote Management Interface (SB-RMI) +and SB Temperature Sensor Interface (SB-TSI)). + +More details on the interface can be found in chapter +"5 Advanced Platform Management Link (APML)" of the family/model PPR +Eg: https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/programmer-references/55898_B1_pub_0_50.zip + + +SBRMI device +============ + +apml_sbrmi driver under the drivers/misc/amd-sbi creates miscdevice +/dev/sbrmi-* to let user space programs run APML mailbox, CPUID, +MCAMSR and register xfer commands. + +Register sets is common across APML protocols. IOCTL is providing synchronization +among protocols as transactions may create race condition. + +$ ls -al /dev/sbrmi-3c +crw------- 1 root root 10, 53 Jul 10 11:13 /dev/sbrmi-3c + +apml_sbrmi driver registers hwmon sensors for monitoring power_cap_max, +current power consumption and managing power_cap. + +Characteristics of the dev node: + * message ids are defined to run differnet xfer protocols: + * Mailbox: 0x0 ... 0x999 + * CPUID: 0x1000 + * MCA_MSR: 0x1001 + * Register xfer: 0x1002 + +Access restrictions: + * Only root user is allowed to open the file. + * APML Mailbox messages and Register xfer access are read-write, + * CPUID and MCA_MSR access is read-only. + +Driver IOCTLs +============= + +.. c:macro:: SBRMI_IOCTL_CMD +.. kernel-dec:: include/uapi/misc/amd-apml.h + :doc: SBRMI_IOCTL_CMD + +User-space usage +================ + +To access side band interface from a C program. +First, user need to include the headers:: + + #include <uapi/misc/amd-apml.h> + +Which defines the supported IOCTL and data structure to be passed +from the user space. + +Next thing, open the device file, as follows:: + + int file; + + file = open("/dev/sbrmi-*", O_RDWR); + if (file < 0) { + /* ERROR HANDLING */ + exit(1); + } + +The following IOCTL is defined: + +``#define SB_BASE_IOCTL_NR 0xF9`` +``#define SBRMI_IOCTL_CMD _IOWR(SB_BASE_IOCTL_NR, 0, struct apml_message)`` + + +User space C-APIs are made available by esmi_oob_library, hosted at +https://github.com/amd/esmi_oob_library which is provided by the E-SMS +project https://www.amd.com/en/developer/e-sms.html.
Signature · 1 line
2.25.1
Quoted 33 lines · Akshay Gupta
AMD's Advanced Platform Management Link (APML) interface provides system management functionality accessed by the baseboard management controller (BMC). sbrmi driver under hwmon subsystem, which is probed as an i2c driver and reports power using APML specified protocol.
However, APML interface defines few other protocols to support
full system management functionality out-of-band.
Out-of-band management is term used for BMC talking to system management unit (IP in the processor). AMD's documentation called this link as side band interface.This patchset is an attempt to add all APML core functionality in one place and provide hwmon and user space interface
1. [Patch 1] Move the i2c client probe, hwmon sensors and sbrmi core functionality fromdrivers/hwmontodrivers/misc/
2. [Patch 2] Convert i2c to regmap which provides multiple benefits over direct smbus APIs.
a. i2c/i3c support and
b. 1 byte/2 byte RMI register size addressing
3. [Patch 3] Optimize wait condition with regmap APIregmap_read_poll_timeoutas per suggestion from Arnd
4. [Patch 4, 5] Register a misc device which provides
a. An ioctl interface through node/dev/sbrmiX
b. Register sets is common across APML protocols. IOCTL is providing
synchronization among protocols as transactions may create race condition.
5. [Subsequent patches 6, 7 and 8] add support for AMD custom protocols a. CPUID
b. MCAMSR
c. Register xfer
6. [Patch 9] AMD side band description documentOpen-sourced and widely used https://github.com/amd/esmi_oob_library
will continue to provide user-space programmable API.
Quoted 11 lines
Akshay Gupta (9):
hwmon/misc: amd-sbi: Move core sbrmi from hwmon to misc
misc: amd-sbi: Use regmap subsystem
misc: amd-sbi: Optimize the wait condition for mailbox command
completion
misc: amd-sbi: Add support forAMD_SBIIOCTL
misc: amd-sbi: Add support for mailbox error codes
misc: amd-sbi: Add support for CPUID protocol
misc: amd-sbi: Add support for MCA register protocol
misc: amd-sbi: Add supoort for register xfer
misc: amd-sbi: Add document for AMD SB IOCTL description
Hi Greg, Arnd,
You have previously reviewed v3 of patch set and I have addressed the review comments in v4.
Can you please take review v4 patch set?
Thank you.
Quoted 26 lines
Documentation/misc-devices/amd-sbi.rst | 84 ++++ Documentation/misc-devices/index.rst | 1 + .../userspace-api/ioctl/ioctl-number.rst | 2 + drivers/hwmon/Kconfig | 10 - drivers/hwmon/sbrmi.c | 357 -------------- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/amd-sbi/Kconfig | 9 + drivers/misc/amd-sbi/Makefile | 3 + drivers/misc/amd-sbi/rmi-core.c | 452 ++++++++++++++++++ drivers/misc/amd-sbi/rmi-core.h | 67 +++ drivers/misc/amd-sbi/rmi-hwmon.c | 122 +++++ drivers/misc/amd-sbi/rmi-i2c.c | 135 ++++++ include/uapi/misc/amd-apml.h | 97 ++++ 14 files changed, 974 insertions(+), 367 deletions(-)create mode 100644
Documentation/misc-devices/amd-sbi.rstdelete mode 100644drivers/hwmon/sbrmi.c
create mode 100644drivers/misc/amd-sbi/Kconfigcreate mode 100644drivers/misc/amd-sbi/Makefilecreate mode 100644drivers/misc/amd-sbi/rmi-core.ccreate mode 100644drivers/misc/amd-sbi/rmi-core.hcreate mode 100644drivers/misc/amd-sbi/rmi-hwmon.ccreate mode 100644drivers/misc/amd-sbi/rmi-i2c.ccreate mode 100644include/uapi/misc/amd-apml.h
Greg KH
maintainerQuoted 47 lines · Akshay
Quoted 33 lines · Akshay Gupta
AMD's Advanced Platform Management Link (APML) interface provides system management functionality accessed by the baseboard management controller (BMC). sbrmi driver under hwmon subsystem, which is probed as an i2c driver and reports power using APML specified protocol.
However, APML interface defines few other protocols to support
full system management functionality out-of-band.
Out-of-band management is term used for BMC talking to system management unit (IP in the processor). AMD's documentation called this link as side band interface.This patchset is an attempt to add all APML core functionality in one place and provide hwmon and user space interface
1. [Patch 1] Move the i2c client probe, hwmon sensors and sbrmi core functionality fromdrivers/hwmontodrivers/misc/
2. [Patch 2] Convert i2c to regmap which provides multiple benefits over direct smbus APIs.
a. i2c/i3c support and
b. 1 byte/2 byte RMI register size addressing
3. [Patch 3] Optimize wait condition with regmap APIregmap_read_poll_timeoutas per suggestion from Arnd
4. [Patch 4, 5] Register a misc device which provides
a. An ioctl interface through node/dev/sbrmiX
b. Register sets is common across APML protocols. IOCTL is providing
synchronization among protocols as transactions may create race condition.
5. [Subsequent patches 6, 7 and 8] add support for AMD custom protocols a. CPUID
b. MCAMSR
c. Register xfer
6. [Patch 9] AMD side band description documentOpen-sourced and widely used https://github.com/amd/esmi_oob_library
will continue to provide user-space programmable API.Quoted 11 lines
Akshay Gupta (9):
hwmon/misc: amd-sbi: Move core sbrmi from hwmon to misc
misc: amd-sbi: Use regmap subsystem
misc: amd-sbi: Optimize the wait condition for mailbox command
completion
misc: amd-sbi: Add support forAMD_SBIIOCTL
misc: amd-sbi: Add support for mailbox error codes
misc: amd-sbi: Add support for CPUID protocol
misc: amd-sbi: Add support for MCA register protocol
misc: amd-sbi: Add supoort for register xfer
misc: amd-sbi: Add document for AMD SB IOCTL description
Quoted 6 lines
Hi Greg, Arnd,
You have previously reviewed v3 of patch set and I have addressed the review comments in v4.
Can you please take review v4 patch set?
Please wait until after the merge window is over (i.e. -rc1 is out) as we can't do anything until then as you know. Also remember that most of us are traveling all of this week (and some of us next week) for conferences, and will get to the backlog when we return.
To help us out, please go through the lists and review other submissions for these subsystems so that your changes move to the top of unreviewed ones.
thanks,
greg k-h