2015-12-16 15:30:45

by Andreas Werner

[permalink] [raw]
Subject: [PATCH 0/4] remove auto exit of production and added sysfs interface

This patch set introduces new sysfs entries for BMC status information
as well as the ABI documention.

The mfd core driver now does not exit the production mode automatically.
The new sysfs entry allows the userland to exit the production mode
if required.

Andreas Werner (4):
mfd/menf21bmc: remove auto exiting of production mode and add sysfs
interface
doc/ABI: added sysfs description for the menf21bmc MFD driver
mfd/menf21bmc.c: add additional sysfs entries for BMC status
information
doc/ABI: add documentation for the additional sysfs status information

.../ABI/testing/sysfs-bus-i2c-devices-menf21bmc | 40 ++++++
drivers/mfd/menf21bmc.c | 158 ++++++++++++++++++---
2 files changed, 177 insertions(+), 21 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c-devices-menf21bmc

--
2.6.2


2015-12-16 15:31:14

by Andreas Werner

[permalink] [raw]
Subject: [PATCH 1/4] mfd/menf21bmc: remove auto exiting of production mode and add sysfs interface

Changed "exit production mode" from automatic exiting to
manually using the sysfs interface.

If the driver exit the production mode automatically, the board will
not start anymore if the bootloader does not already have the "BIOS life sign"
feature.

This patch remove the auto mechanism and add a sysfs interface to manually
exiting the production e.g. during the EOL test of the board.

Signed-off-by: Andreas Werner <[email protected]>
---
drivers/mfd/menf21bmc.c | 65 +++++++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 21 deletions(-)

diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
index 1c27434..742ffe7 100644
--- a/drivers/mfd/menf21bmc.c
+++ b/drivers/mfd/menf21bmc.c
@@ -27,31 +27,57 @@ static struct mfd_cell menf21bmc_cell[] = {
{ .name = "menf21bmc_hwmon", }
};

-static int menf21bmc_wdt_exit_prod_mode(struct i2c_client *client)
+static ssize_t menf21bmc_mode_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
- int val, ret;
+ struct i2c_client *client = to_i2c_client(dev);
+ int val;

val = i2c_smbus_read_byte_data(client, BMC_CMD_WDT_PROD_STAT);
if (val < 0)
return val;

+ return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t menf21bmc_mode_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ unsigned long mode_val;
+ int ret;
+
+ if (kstrtoul(buf, 0, &mode_val))
+ return -EINVAL;
+
/*
- * Production mode should be not active after delivery of the Board.
- * To be sure we check it, inform the user and exit the mode
- * if active.
+ * We cannot set the production mode (0).
+ * This is the default mode. If exited once,
+ * it cannot be set anymore.
*/
- if (val == 0x00) {
- dev_info(&client->dev,
- "BMC in production mode. Exit production mode\n");
+ if (!mode_val)
+ return -EINVAL;

- ret = i2c_smbus_write_byte(client, BMC_CMD_WDT_EXIT_PROD);
- if (ret < 0)
- return ret;
- }
+ ret = i2c_smbus_write_byte(client, BMC_CMD_WDT_EXIT_PROD);
+ if (ret < 0)
+ return ret;

- return 0;
+ return size;
}

+static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, menf21bmc_mode_show,
+ menf21bmc_mode_store);
+
+static struct attribute *menf21bmc_attributes[] = {
+ &dev_attr_mode.attr,
+ NULL
+};
+
+static const struct attribute_group menf21bmc_attr_group = {
+ .attrs = menf21bmc_attributes,
+};
+
static int
menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
{
@@ -86,20 +112,15 @@ menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
dev_info(&client->dev, "FW Revision: %02d.%02d.%02d\n",
rev_major, rev_minor, rev_main);

- /*
- * We have to exit the Production Mode of the BMC to activate the
- * Watchdog functionality and the BIOS life sign monitoring.
- */
- ret = menf21bmc_wdt_exit_prod_mode(client);
- if (ret < 0) {
- dev_err(&client->dev, "failed to leave production mode\n");
+ ret = sysfs_create_group(&client->dev.kobj, &menf21bmc_attr_group);
+ if (ret)
return ret;
- }

ret = mfd_add_devices(&client->dev, 0, menf21bmc_cell,
ARRAY_SIZE(menf21bmc_cell), NULL, 0, NULL);
if (ret < 0) {
dev_err(&client->dev, "failed to add BMC sub-devices\n");
+ sysfs_remove_group(&client->dev.kobj, &menf21bmc_attr_group);
return ret;
}

@@ -108,7 +129,9 @@ menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)

static int menf21bmc_remove(struct i2c_client *client)
{
+ sysfs_remove_group(&client->dev.kobj, &menf21bmc_attr_group);
mfd_remove_devices(&client->dev);
+
return 0;
}

--
2.6.2

2015-12-16 15:31:22

by Andreas Werner

[permalink] [raw]
Subject: [PATCH 2/4] doc/ABI: added sysfs description for the menf21bmc MFD driver

This patch add the description of the "mode" sysfs interface
for the menf21bmc MFD driver.

Signed-off-by: Andreas Werner <[email protected]>
---
Documentation/ABI/testing/sysfs-bus-i2c-devices-menf21bmc | 14 ++++++++++++++
1 file changed, 14 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c-devices-menf21bmc

diff --git a/Documentation/ABI/testing/sysfs-bus-i2c-devices-menf21bmc b/Documentation/ABI/testing/sysfs-bus-i2c-devices-menf21bmc
new file mode 100644
index 0000000..28d1fa2
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-i2c-devices-menf21bmc
@@ -0,0 +1,14 @@
+What: /sys/bus/i2c/devices/.../mode
+Date: December 2015
+KernelVersion: 4.4
+Contact: Andreas Werner <[email protected]>
+Description: Set and get the mode of the device.
+ The production mode cannot be set again if the device
+ is set to active once.
+
+ In production mode the BMC does not wait for BIOS life sign,
+ did not reset the CPU board on Watchdog timeout and allow the
+ programming of the HW Variant.
+
+ 0 = production mode
+ 1 = active mode
--
2.6.2

2015-12-16 15:31:37

by Andreas Werner

[permalink] [raw]
Subject: [PATCH 3/4] mfd/menf21bmc.c: add additional sysfs entries for BMC status information

This patch adds additional sysfs entries to provide status
information to the userland.

The following informations are now provided:
- Get operation hours counter
- Get board slot address
- Get powercycle counter
- Set/get Hw Variant

Signed-off-by: Andreas Werner <[email protected]>
---
drivers/mfd/menf21bmc.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 96 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
index 742ffe7..dd068c0 100644
--- a/drivers/mfd/menf21bmc.c
+++ b/drivers/mfd/menf21bmc.c
@@ -20,6 +20,10 @@
#define BMC_CMD_REV_MAJOR 0x80
#define BMC_CMD_REV_MINOR 0x81
#define BMC_CMD_REV_MAIN 0x82
+#define BMC_CMD_SLOT_ADDRESS 0x8c
+#define BMC_CMD_HW_VARIANT 0x8f
+#define BMC_CMD_PWRCYCL_CNT 0x93
+#define BMC_CMD_OP_HRS_CNT 0x94

static struct mfd_cell menf21bmc_cell[] = {
{ .name = "menf21bmc_wdt", },
@@ -28,7 +32,7 @@ static struct mfd_cell menf21bmc_cell[] = {
};

static ssize_t menf21bmc_mode_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
int val;
@@ -41,8 +45,8 @@ static ssize_t menf21bmc_mode_show(struct device *dev,
}

static ssize_t menf21bmc_mode_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t size)
+ struct device_attribute *attr,
+ const char *buf, size_t size)
{
struct i2c_client *client = to_i2c_client(dev);
unsigned long mode_val;
@@ -66,11 +70,100 @@ static ssize_t menf21bmc_mode_store(struct device *dev,
return size;
}

+static ssize_t menf21bmc_hw_variant_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ int val;
+
+ val = i2c_smbus_read_word_data(client, BMC_CMD_HW_VARIANT);
+ if (val < 0)
+ return val;
+
+ return sprintf(buf, "0x%04x\n", val);
+
+}
+
+static ssize_t menf21bmc_hw_variant_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ unsigned long hw_variant;
+ int ret;
+
+ if (kstrtoul(buf, 0, &hw_variant))
+ return -EINVAL;
+
+ if (hw_variant < 0 || hw_variant > 0xffff)
+ return -EINVAL;
+
+ ret = i2c_smbus_write_word_data(client, BMC_CMD_HW_VARIANT,
+ hw_variant);
+ if (ret < 0)
+ return ret;
+
+ return size;
+
+}
+
+static ssize_t menf21bmc_pwrcycl_cnt_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ int val;
+
+ val = i2c_smbus_read_word_data(client, BMC_CMD_PWRCYCL_CNT);
+ if (val < 0)
+ return val;
+
+ return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t menf21bmc_op_hrs_cnt_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ int val;
+
+ val = i2c_smbus_read_word_data(client, BMC_CMD_OP_HRS_CNT);
+ if (val < 0)
+ return val;
+
+ return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t menf21bmc_slot_address_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ int val;
+
+ val = i2c_smbus_read_byte_data(client, BMC_CMD_SLOT_ADDRESS);
+ if (val < 0)
+ return val;
+
+ return sprintf(buf, "%d\n", val);
+}
+
static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, menf21bmc_mode_show,
menf21bmc_mode_store);
+static DEVICE_ATTR(hw_variant, S_IRUGO | S_IWUSR, menf21bmc_hw_variant_show,
+ menf21bmc_hw_variant_store);
+static DEVICE_ATTR(pwrcycl_cnt, S_IRUGO, menf21bmc_pwrcycl_cnt_show, NULL);
+static DEVICE_ATTR(op_hrs_cnt, S_IRUGO, menf21bmc_op_hrs_cnt_show, NULL);
+static DEVICE_ATTR(slot_address, S_IRUGO, menf21bmc_slot_address_show, NULL);

static struct attribute *menf21bmc_attributes[] = {
&dev_attr_mode.attr,
+ &dev_attr_hw_variant.attr,
+ &dev_attr_pwrcycl_cnt.attr,
+ &dev_attr_op_hrs_cnt.attr,
+ &dev_attr_slot_address.attr,
NULL
};

--
2.6.2

2015-12-16 15:31:54

by Andreas Werner

[permalink] [raw]
Subject: [PATCH 4/4] doc/ABI: add documentation for the additional sysfs status information

Signed-off-by: Andreas Werner <[email protected]>
---
.../ABI/testing/sysfs-bus-i2c-devices-menf21bmc | 26 ++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-i2c-devices-menf21bmc b/Documentation/ABI/testing/sysfs-bus-i2c-devices-menf21bmc
index 28d1fa2..6defdd3 100644
--- a/Documentation/ABI/testing/sysfs-bus-i2c-devices-menf21bmc
+++ b/Documentation/ABI/testing/sysfs-bus-i2c-devices-menf21bmc
@@ -12,3 +12,29 @@ Description: Set and get the mode of the device.

0 = production mode
1 = active mode
+
+What: /sys/bus/i2c/devices/.../hw_variant
+Date: December 2015
+KernelVersion: 4.4
+Contact: Andreas Werner <[email protected]>
+Description: Set and get the hardware variant ID.
+
+What: /sys/bus/i2c/devices/.../pwrcycl_cnt
+Date: December 2015
+KernelVersion: 4.4
+Contact: Andreas Werner <[email protected]>
+Description: Read the BMC powercycle counter.
+
+What: /sys/bus/i2c/devices/.../op_hrs_cnt
+Date: December 2015
+KernelVersion: 4.4
+Contact: Andreas Werner <[email protected]>
+Description: Read the operation hours counter
+
+What: /sys/bus/i2c/devices/.../slot_address
+Date: December 2015
+KernelVersion: 4.4
+Contact: Andreas Werner <[email protected]>
+Description: Read the slot address of the board.
+ Slot address is the geographical address
+ in a CPCI rack/backplane.
--
2.6.2