Skip to contentSkip to conversation

Add SSIF BMC driver

PATCH Superseded Quan Nguyen 2 participants 6 messages Sep 29, 2022 – Oct 3, 2022

Subsystems (5)

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v9 cover Add SSIF BMC driver

This series add support the SSIF BMC driver which is to perform in-band IPMI communication with their host in management (BMC) side.

SSIF BMC driver in this series is tested with Aspeed AST2500 and AST2600

Discussion for v8:
https://lore.kernel.org/linux-arm-kernel/20220615090259.1121405-1-quan at os.amperecomputing.com/

v9:
+ Fix dependence with I2C subsystem [Randy]
+ Update missing Reviewed-by tag from v7 [Rob]
+ Remove useless error handling path [CJ]
+ Update comment for SSIF_ABORTING state [CJ]
+ Fix "unknown type name --u8" [kernel test robot]
+ Update commit message and add comment to explain
the effect of issuing RxCmdLast when Slave busy [Quan]

v8:
+ Dropped ssif_bmc.h file and move its content to ssif_bmc.c [Corey]
+ Add struct ipmi_ssif_msg to include/uapi/linux/ipmi_ssif_bmc.h

  header file                                                    [Corey]
  + Use unsigned int for len field in struct ipmi_ssif_msg       [Corey]
  + Avoid using packed structure                                 [Corey]
  + Add comment to clarify the logic flow                        [Corey]
  + Fix multipart read end with len=0 issue                      [Corey]
  + Refactor code handle the too big request message             [Corey]
  + Fix code indentation issue                                   [Corey]

+ Clean buffer before receiving request to avoid garbage [Quan]
+ Fix the license to SPDX-License-Identifier: GPL-2.0-only [Quan]

v7:
+ Remove unnecessary del_timer() in response_timeout() [Corey]
+ Change compatible string from "ampere,ssif-bmc" to "ssif-bmc" [Jae]
+ Dropped the use of ssif_msg_len() macro, use the len directly [Quan]
+ Solve possible issue if both response timer and ssif_bmc_write()
occurred at the same time [Corey]
+ Fix wrong return type of ssif_bmc_poll() [kernel robot test]
+ Refactor and introduce ssif_part_buffer struct to replace the
response_buf to manage each send/receive part of ssif [Quan]
+ Change SSIF_BAD_SMBUS state to SSIF_ABORTING state [Corey]
+ Support abort feature to skip the current bad request/response and
wait until next new request [Corey]
+ Refactor the PEC calculation to avoid the re-calculate the PEC on
each I2C_SLAVE_WRITE_RECEIVED event [Quan]
+ Fix the use of error-proned idx [Corey]
+ Defer the test for valid SMBus command until the read/write part
is determined [Quan]
+ Change/split unsupported_smbus_cmd() to
supported_[write|read]_cmd() [Corey]
+ Abort the request if somehow its size exceeded 255 bytes [Quan]

v6:
+ Drop the use of slave_enable() [Wolfram]
+ Make i2c-aspeed to issue RxCmdLast command on all
I2C_SLAVE_WRITE_REQUESTED event to assert NAK when slave busy [Quan]
+ Make i2c slave to return -EBUSY when it's busy [Quan]
+ Drop the aborting feature as return Completion Code 0xFF may stop

  host to retry and make ipmi_ssif.so fails to load               [Quan]
  + Add timer to recover slave from busy state when no response   [Quan]
  + Clean request/response buffer appropriately                   [Quan]
  + Add some minor change on error and warning messages           [Quan]

v5:
+ Correct the patches order to fix the bisect issue found by kernel build robot

v4:
+ Fix recursive spinlock [Graeme]
+ Send response with Completion code 0xFF when aborting [Quan]
+ Fix warning with dt_binding_check [Rob]
+ Change aspeed-ssif-bmc.yaml to ssif-bmc.yaml [Quan]
+ Added bounding check on SMBus writes and the whole request [Dan]
+ Moved buffer to end of struct ssif_bmc_ctx to avoid context
corruption if somehow buffer is written past the end [Dan]
+ Return -EINVAL if userspace buffer too small, don't
silence truncate [Corey, Joel]
+ Not necessary to check NONBLOCK in lock [Corey]
+ Enforce one user at a time [Joel]
+ Reject write with invalid response length from userspace [Corey]
+ Add state machines for better ssif bmc state handling [Quan]
+ Drop ssif_bmc_aspeed.c and make ssif_bmc.c is generic
SSIF BMC driver [Quan]
+ Change compatible string "aspeed,ast2500-ssif-bmc" to
"ampere,ssif-bmc" [Quan]
+ Toggle Slave enable in i2c-aspeed to turn on/off slave mode [Ryan]
+ Added slave_enable() to struct i2c_algorithm to control
slave mode and to address the recursive spinlock [Graeme, Ryan]
+ Abort current request with invalid SMBus write or

    invalid command                                               [Quan]
  + Abort all request if there is pending response                [Quan]
  + Changed validate_pec() to validate_request()                  [Quan]
  + Add unsupported_smbus_cmd() to handle unknown SMBus command   [Quan]
  + Print internal state string for ease investigating issue      [Quan]
  + Move to READY state on SLAVE_STOP event                       [Quan]
  + Change initilize_transfer() to process_smbus_cmd()            [Quan]
  + Introduce functions for each slave event                      [Quan]

v3:
+ Switched binding doc to use DT schema format [Rob]
+ Splited into generic ssif_bmc and aspeed-specific [Corey, Joel]

  + Removed redundant license info                                [Joel]
  + Switched to use traditional if-else                           [Joel]
  + Removed unused ssif_bmc_ioctl()                               [Joel]
  + Made handle_request()/complete_response() to return void      [Joel]
  + Refactored send_ssif_bmc_response() and
  receive_ssif_bmc_request()                                     [Corey]
  + Remove mutex                                                 [Corey]
  + Use spin_lock/unlock_irqsave/restore in callback             [Corey]
  + Removed the unnecessary memset                               [Corey]
  + Switch to use dev_err()                                      [Corey]
  + Combine mask/unmask two interrupts together                  [Corey]

+ Fixed unhandled Tx done with NAK [Quan]
+ Late ack'ed Tx done w/wo Ack irq [Quan]
+ Use aspeed-specific exported aspeed_set_slave_busy() when
slave busy to fix the deadlock [Graeme, Philipp, Quan]
+ Clean buffer for last multipart read [Quan]
+ Handle unknown incoming command [Quan]

v2:
+ Fixed compiling error with COMPILE_TEST for arc

Quan Nguyen (3):
ipmi: ssif_bmc: Add SSIF BMC driver
bindings: ipmi: Add binding for SSIF BMC driver
i2c: aspeed: Assert NAK when slave is busy

 .../devicetree/bindings/ipmi/ssif-bmc.yaml    |  38 +
 drivers/char/ipmi/Kconfig                     |  10 +
 drivers/char/ipmi/Makefile                    |   1 +
 drivers/char/ipmi/ssif_bmc.c                  | 873 ++++++++++++++++++
 drivers/i2c/busses/i2c-aspeed.c               |   9 +-
 include/uapi/linux/ipmi_ssif_bmc.h            |  18 +
 6 files changed, 948 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/ipmi/ssif-bmc.yaml
 create mode 100644 drivers/char/ipmi/ssif_bmc.c
 create mode 100644 include/uapi/linux/ipmi_ssif_bmc.h
Signature · 1 line
2.35.1
#1 lore raw

PATCH v9 1/3 ipmi: ssif_bmc: Add SSIF BMC driver

The SMBus system interface (SSIF) IPMI BMC driver can be used to perform in-band IPMI communication with their host in management (BMC) side.

Thanks Dan for the copy_from_user() fix in the link below.

---
v9:
+ Fix dependence with I2C subsystem [Randy]
+ Remove useless error handling path [CJ]
+ Update comment for SSIF_ABORTING state [CJ]
+ Fix "unknown type name --u8" [kernel test robot]
+ Fix ssif_bmc_remove() to return void to align with recent kernel
change [Quan]

v8:
+ Dropped ssif_bmc.h file and move its content to ssif_bmc.c [Corey]
+ Add struct ipmi_ssif_msg to include/uapi/linux/ipmi_ssif_bmc.h

  header file                                                    [Corey]
  + Use unsigned int for len field in struct ipmi_ssif_msg       [Corey]
  + Avoid using packed structure                                 [Corey]
  + Add comment to clarify the logic flow                        [Corey]
  + Fix multipart read end with len=0 issue                      [Corey]
  + Refactor code handle the too big request message             [Corey]
  + Fix code indentation issue                                   [Corey]

+ Clean buffer before receiving request to avoid garbage [Quan]
+ Fix the license to SPDX-License-Identifier: GPL-2.0-only [Quan]

v7:
+ Remove unneccessary del_timer() in response_timeout() [Corey]
+ Change compatible string from "ampere,ssif-bmc" to "ssif-bmc" [Jae]
+ Add MODULE_DEVICE_TABLE(of, ssif_bmc_match), fix blank line [Jae]
+ Dropped the use of ssif_msg_len() macro, use the len directly [Quan]
+ Solve possible issue if both response timer and ssif_bmc_write()
occurred at the same time [Corey]
+ Fix wrong return type of ssif_bmc_poll() [kernel robot test]
+ Refactor and introduce ssif_part_buffer struct to replace the
response_buf to manage each send/receive part of ssif [Quan]
+ Change SSIF_BAD_SMBUS state to SSIF_ABORTING state [Corey]
+ Support abort feature to skip the current bad request/response and
wait until next new request [Corey]
+ Refactor the PEC calculation to avoid the re-calculate the PEC on
each I2C_SLAVE_WRITE_RECEIVED event [Quan]
+ Fix the use of error-proned idx [Corey]
+ Defer the test for valid SMBus command until the read/write part
is determined [Quan]
+ Change/split unsupported_smbus_cmd() to
supported_[write|read]_cmd() [Corey]
+ Abort the request if somehow its size exceeded 255 bytes [Quan]

v6:
+ Drop the use of slave_enable() [Wolfram]
+ Make i2c-aspeed to issue RxCmdLast command on all
I2C_SLAVE_WRITE_REQUESTED event to assert NAK when slave busy [Quan]
+ Make i2c slave to return -EBUSY when it's busy [Quan]
+ Drop the aborting feature as return Completion Code 0xFF may stop

  host to retry and make ipmi_ssif.so fails to load               [Quan]
  + Add timer to recover slave from busy state when no response   [Quan]
  + Clean request/response buffer appropriately                   [Quan]
  + Add some minor change on error and warning messages           [Quan]

v5:
+ None

v4:
+ Send response with Completion code 0xFF when aborting [Quan]
+ Added bounding check on SMBus writes and the whole request [Dan]
+ Moved buffer to end of struct ssif_bmc_ctx to avoid context
corruption if somehow buffer is written past the end [Dan]
+ Return -EINVAL if userspace buffer too small, dont
silence truncate [Corey, Joel]
+ Not necessary to check NONBLOCK in lock [Corey]
+ Enforce one user at a time [Joel]
+ Reject write with invalid response length from userspace [Corey]
+ Add state machines for better ssif bmc state handling [Quan]
+ Drop ssif_bmc_aspeed.c and make ssif_bmc.c is generic
SSIF BMC driver [Quan]
+ Change compatible string "aspeed,ast2500-ssif-bmc" to
"ampere,ssif-bmc" [Quan]
+ Abort current request with invalid SMBus write or

    invalid command                                               [Quan]
  + Abort all request if there is pending response                [Quan]
  + Changed validate_pec() to validate_request()                  [Quan]
  + Add unsupported_smbus_cmd() to handle unknown SMBus command   [Quan]
  + Print internal state string for ease investigating issue      [Quan]
  + Move to READY state on SLAVE_STOP event                       [Quan]
  + Change initilize_transfer() to process_smbus_cmd()            [Quan]
  + Introduce functions for each slave event                      [Quan]

v3:

  + Removed redundant license info                                [Joel]
  + Switched to use traditional if-else                           [Joel]
  + Removed unused ssif_bmc_ioctl()                               [Joel]
  + Made handle_request()/complete_response() to return void      [Joel]
  + Refactored send_ssif_bmc_response() and
  receive_ssif_bmc_request()                                     [Corey]
  + Removed mutex                                                [Corey]
  + Use spin_lock/unlock_irqsave/restore in callback             [Corey]
  + Removed the unnecessary memset                               [Corey]
  + Switch to use dev_err()                                      [Corey]

v2:
+ Fixed compiling error with COMPILE_TEST for arc

 drivers/char/ipmi/Kconfig          |  10 +
 drivers/char/ipmi/Makefile         |   1 +
 drivers/char/ipmi/ssif_bmc.c       | 873 +++++++++++++++++++++++++++++
 include/uapi/linux/ipmi_ssif_bmc.h |  18 +
 4 files changed, 902 insertions(+)
 create mode 100644 drivers/char/ipmi/ssif_bmc.c
 create mode 100644 include/uapi/linux/ipmi_ssif_bmc.h
drivers/char/ipmi/Kconfig +10 -0
index 39565cf74b2c..b6c0d35fc1a5 100644
@@ -169,6 +169,16 @@ config ASPEED_BT_IPMI_BMC
 	  found on Aspeed SOCs (AST2400 and AST2500). The driver
 	  implements the BMC side of the BT interface.
 
+config SSIF_IPMI_BMC
+	tristate "SSIF IPMI BMC driver"
+	depends on I2C && I2C_SLAVE
+	help
+	  This enables the IPMI SMBus system interface (SSIF) at the
+	  management (BMC) side.
+
+	  The driver implements the BMC side of the SMBus system
+	  interface (SSIF).
+
 config IPMB_DEVICE_INTERFACE
 	tristate 'IPMB Interface handler'
 	depends on I2C
drivers/char/ipmi/Makefile +1 -0
index 7ce790efad92..cb6138b8ded9 100644
@@ -30,3 +30,4 @@ obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
 obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
 obj-$(CONFIG_NPCM7XX_KCS_IPMI_BMC) += kcs_bmc_npcm7xx.o
 obj-$(CONFIG_IPMB_DEVICE_INTERFACE) += ipmb_dev_int.o
+obj-$(CONFIG_SSIF_IPMI_BMC) += ssif_bmc.o
drivers/char/ipmi/ssif_bmc.c new file +873 -0

873 lines not on this page · raw message

include/uapi/linux/ipmi_ssif_bmc.h new file +18 -0
new file mode 100644
index 000000000000..1c6a753dad08
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note*/
+/*
+ * Copyright (c) 2022, Ampere Computing LLC.
+ */
+
+#ifndef _UAPI_LINUX_IPMI_SSIF_BMC_H
+#define _UAPI_LINUX_IPMI_SSIF_BMC_H
+
+#include <linux/types.h>
+
+/* Max length of ipmi ssif message included netfn and cmd field */
+#define IPMI_SSIF_PAYLOAD_MAX         254
+struct ipmi_ssif_msg {
+	unsigned int len;
+	__u8    payload[IPMI_SSIF_PAYLOAD_MAX];
+};
+
+#endif /* _UAPI_LINUX_IPMI_SSIF_BMC_H */
Signature · 1 line
2.35.1
#2 lore raw

PATCH v9 2/3 bindings: ipmi: Add binding for SSIF BMC driver

In reply to Quan Nguyen

Add device tree binding document for the SSIF BMC driver.

---
v9:
+ Update missing Reviewed-by tag from v7 [Rob]

v8:
+ None

v7:
+ Change compatible string from "ampere,ssif-bmc" to "ssif-bmc" [Jae]

v6:
+ None

v5:
+ None

v4:
+ Fix warning with dt_binding_check [Rob]
+ Change aspeed-ssif-bmc.yaml to ssif-bmc.yaml [Quan]

v3:
+ Switched to use DT schema format [Rob]

v2:
+ None

 .../devicetree/bindings/ipmi/ssif-bmc.yaml    | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/ssif-bmc.yaml
Documentation/devicetree/bindings/ipmi/ssif-bmc.yaml new file +38 -0
new file mode 100644
index 000000000000..02b662d780bb
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/ipmi/ssif-bmc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SSIF IPMI BMC interface
+
+description: SSIF IPMI BMC device bindings
+
+maintainers:
+  - Quan Nguyen <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - ssif-bmc
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        ssif-bmc at 10 {
+            compatible = "ssif-bmc";
+            reg = <0x10>;
+        };
+    };
Signature · 1 line
2.35.1
#3 lore raw

PATCH v9 3/3 i2c: aspeed: Assert NAK when slave is busy

In reply to Quan Nguyen

On I2C_SLAVE_WRITE_REQUESTED event, Slave already ACK'ed on the address phase. But as the backend driver is busy and unable to process any request from Master, issue RxCmdLast for Slave to auto send NACK on next incoming byte.

---
v9:
+ Update commit message and add comment to explain the effect of issuing RxCmdLast when Slave busy [Quan]

v7 -> v8:
+ None

v6:
+ New introduced in v6 [Quan]

 drivers/i2c/busses/i2c-aspeed.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-aspeed.c +8 -1
index 185dedfebbac..3d70f1ce6c6a 100644
@@ -244,6 +244,7 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status)
 	u32 command, irq_handled = 0;
 	struct i2c_client *slave = bus->slave;
 	u8 value;
+	int ret;
 
 	if (!slave)
 		return 0;
@@ -311,7 +312,13 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status)
 		break;
 	case ASPEED_I2C_SLAVE_WRITE_REQUESTED:
 		bus->slave_state = ASPEED_I2C_SLAVE_WRITE_RECEIVED;
-		i2c_slave_event(slave, I2C_SLAVE_WRITE_REQUESTED, &value);
+		ret = i2c_slave_event(slave, I2C_SLAVE_WRITE_REQUESTED, &value);
+		/*
+		 * Slave ACK's on this address phase already but as the backend driver insists it
+		 * is busy, turn on RxCmdLast for Slave to NACK on the next Rx byte.
+		 */
+		if (ret == -EBUSY)
+			writel(ASPEED_I2CD_M_S_RX_CMD_LAST, bus->base + ASPEED_I2C_CMD_REG);
 		break;
 	case ASPEED_I2C_SLAVE_WRITE_RECEIVED:
 		i2c_slave_event(slave, I2C_SLAVE_WRITE_RECEIVED, &value);
Signature · 1 line
2.35.1
#4 lore raw

Re: [PATCH v9 3/3] i2c: aspeed: Assert NAK when slave is busy

drivers/i2c/busses/i2c-aspeed.c static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) · line 320

Quoted 2 lines
drivers/i2c/busses/i2c-aspeed.c +1 -0
+		if (ret == -EBUSY)

Since we documented this:

"+ 'ret': 0 if the backend is ready, otherwise some errno"

the code above should be '(ret < 0)'

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linux-aspeed/attachments/20221002/06692e4b/attachment.sig>

#5 lore raw

Re: [PATCH v9 3/3] i2c: aspeed: Assert NAK when slave is busy

Quoted 9 lines · Wolfram Sang

drivers/i2c/busses/i2c-aspeed.c static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) · line 320

Quoted 2 lines
drivers/i2c/busses/i2c-aspeed.c +1 -0
+		if (ret == -EBUSY)

Since we documented this:

"+ 'ret': 0 if the backend is ready, otherwise some errno"

the code above should be '(ret < 0)'

Will update.
Thanks a lot for the review.

- Quan