Re: [PATCH v4 3/5] ipmi: kcs: aspeed: Adapt to new LPC DTS layout

2020-12-29 Thread Haiyue Wang

On 12/29/2020 14:31, Chia-Wei, Wang wrote:

Add check against LPC device v2 compatible string to
ensure that the fixed device tree layout is adopted.
The LPC register offsets are also fixed accordingly.

Signed-off-by: Chia-Wei, Wang
---
  drivers/char/ipmi/kcs_bmc_aspeed.c | 27 ---
  1 file changed, 16 insertions(+), 11 deletions(-)


Acked-by: Haiyue Wang 





Re: [PATCH v3 3/5] ipmi: kcs: aspeed: Adapt to new LPC DTS layout

2020-12-21 Thread Haiyue Wang



On 12/21/2020 15:53, Haiyue Wang wrote:

On 12/21/2020 13:56, Chia-Wei, Wang wrote:

Add check against LPC device v2 compatible string to
ensure that the fixed device tree layout is adopted.
The LPC register offsets are also fixed accordingly.

Signed-off-by: Chia-Wei, Wang 
---
  drivers/char/ipmi/kcs_bmc_aspeed.c | 35 ++
  1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c

index a140203c079b..6283bfef4ea7 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -27,7 +27,6 @@
    #define KCS_CHANNEL_MAX 4
  -/* mapped to lpc-bmc@0 IO space */
  #define LPC_HICR0    0x000
  #define LPC_HICR0_LPC3E  BIT(7)
  #define LPC_HICR0_LPC2E  BIT(6)
@@ -52,15 +51,13 @@
  #define LPC_STR1 0x03C
  #define LPC_STR2 0x040
  #define LPC_STR3 0x044
-
-/* mapped to lpc-host@80 IO space */
-#define LPC_HICRB    0x080
+#define LPC_HICRB    0x100
  #define LPC_HICRB_IBFIF4 BIT(1)
  #define LPC_HICRB_LPC4E  BIT(0)
-#define LPC_LADR4    0x090
-#define LPC_IDR4 0x094
-#define LPC_ODR4 0x098
-#define LPC_STR4 0x09C
+#define LPC_LADR4    0x110
+#define LPC_IDR4 0x114
+#define LPC_ODR4 0x118
+#define LPC_STR4 0x11C
    struct aspeed_kcs_bmc {
  struct regmap *map;
@@ -345,15 +342,25 @@ static int aspeed_kcs_probe(struct 
platform_device *pdev)

  {
  struct device *dev = >dev;
  struct kcs_bmc *kcs_bmc;
-    struct device_node *np;
+    struct device_node *kcs_np;
+    struct device_node *lpc_np;
  int rc;


I think you can just use 'np' to do LPC compatible checking:

np = pdev->dev.of_node->parent;

if (!of_device_is_compatible(lpc_np, "aspeed,ast2400-lpc-v2") &&
    !of_device_is_compatible(lpc_np, "aspeed,ast2500-lpc-v2") &&
    !of_device_is_compatible(lpc_np, "aspeed,ast2600-lpc-v2")) {
dev_err(dev, "unsupported LPC device binding\n");
return -ENODEV;
}


Typo:

if (!of_device_is_compatible(np, "aspeed,ast2400-lpc-v2") &&
    !of_device_is_compatible(np, "aspeed,ast2500-lpc-v2") &&
    !of_device_is_compatible(np, "aspeed,ast2600-lpc-v2")) {
dev_err(dev, "unsupported LPC device binding\n");
return -ENODEV;
}




before:

np = pdev->dev.of_node;
if (of_device_is_compatible(np, "aspeed,ast2400-kcs-bmc") ||
    of_device_is_compatible(np, "aspeed,ast2500-kcs-bmc"))

Then the patch is clear. ;-)


-    np = pdev->dev.of_node;
-    if (of_device_is_compatible(np, "aspeed,ast2400-kcs-bmc") ||
-    of_device_is_compatible(np, "aspeed,ast2500-kcs-bmc"))
+    kcs_np = dev->of_node;
+    lpc_np = kcs_np->parent;
+
+    if (!of_device_is_compatible(lpc_np, "aspeed,ast2400-lpc-v2") &&
+    !of_device_is_compatible(lpc_np, "aspeed,ast2500-lpc-v2") &&
+    !of_device_is_compatible(lpc_np, "aspeed,ast2600-lpc-v2")) {
+    dev_err(dev, "unsupported LPC device binding\n");
+    return -ENODEV;
+    }
+
+    if (of_device_is_compatible(kcs_np, "aspeed,ast2400-kcs-bmc") ||
+    of_device_is_compatible(kcs_np, "aspeed,ast2500-kcs-bmc"))
  kcs_bmc = aspeed_kcs_probe_of_v1(pdev);
-    else if (of_device_is_compatible(np, 
"aspeed,ast2400-kcs-bmc-v2") ||

-    of_device_is_compatible(np, "aspeed,ast2500-kcs-bmc-v2"))
+    else if (of_device_is_compatible(kcs_np, 
"aspeed,ast2400-kcs-bmc-v2") ||
+    of_device_is_compatible(kcs_np, 
"aspeed,ast2500-kcs-bmc-v2"))

  kcs_bmc = aspeed_kcs_probe_of_v2(pdev);
  else
  return -EINVAL;


Re: [PATCH v3 3/5] ipmi: kcs: aspeed: Adapt to new LPC DTS layout

2020-12-20 Thread Haiyue Wang

On 12/21/2020 13:56, Chia-Wei, Wang wrote:

Add check against LPC device v2 compatible string to
ensure that the fixed device tree layout is adopted.
The LPC register offsets are also fixed accordingly.

Signed-off-by: Chia-Wei, Wang 
---
  drivers/char/ipmi/kcs_bmc_aspeed.c | 35 ++
  1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index a140203c079b..6283bfef4ea7 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -27,7 +27,6 @@
  
  #define KCS_CHANNEL_MAX 4
  
-/* mapped to lpc-bmc@0 IO space */

  #define LPC_HICR00x000
  #define LPC_HICR0_LPC3E  BIT(7)
  #define LPC_HICR0_LPC2E  BIT(6)
@@ -52,15 +51,13 @@
  #define LPC_STR1 0x03C
  #define LPC_STR2 0x040
  #define LPC_STR3 0x044
-
-/* mapped to lpc-host@80 IO space */
-#define LPC_HICRB0x080
+#define LPC_HICRB0x100
  #define LPC_HICRB_IBFIF4 BIT(1)
  #define LPC_HICRB_LPC4E  BIT(0)
-#define LPC_LADR40x090
-#define LPC_IDR4 0x094
-#define LPC_ODR4 0x098
-#define LPC_STR4 0x09C
+#define LPC_LADR40x110
+#define LPC_IDR4 0x114
+#define LPC_ODR4 0x118
+#define LPC_STR4 0x11C
  
  struct aspeed_kcs_bmc {

struct regmap *map;
@@ -345,15 +342,25 @@ static int aspeed_kcs_probe(struct platform_device *pdev)
  {
struct device *dev = >dev;
struct kcs_bmc *kcs_bmc;
-   struct device_node *np;
+   struct device_node *kcs_np;
+   struct device_node *lpc_np;
int rc;
  


I think you can just use 'np' to do LPC compatible checking:

np = pdev->dev.of_node->parent;

if (!of_device_is_compatible(lpc_np, "aspeed,ast2400-lpc-v2") &&
!of_device_is_compatible(lpc_np, "aspeed,ast2500-lpc-v2") &&
!of_device_is_compatible(lpc_np, "aspeed,ast2600-lpc-v2")) {
dev_err(dev, "unsupported LPC device binding\n");
return -ENODEV;
}


before:

np = pdev->dev.of_node;
if (of_device_is_compatible(np, "aspeed,ast2400-kcs-bmc") ||
of_device_is_compatible(np, "aspeed,ast2500-kcs-bmc"))

Then the patch is clear. ;-)


-   np = pdev->dev.of_node;
-   if (of_device_is_compatible(np, "aspeed,ast2400-kcs-bmc") ||
-   of_device_is_compatible(np, "aspeed,ast2500-kcs-bmc"))
+   kcs_np = dev->of_node;
+   lpc_np = kcs_np->parent;
+
+   if (!of_device_is_compatible(lpc_np, "aspeed,ast2400-lpc-v2") &&
+   !of_device_is_compatible(lpc_np, "aspeed,ast2500-lpc-v2") &&
+   !of_device_is_compatible(lpc_np, "aspeed,ast2600-lpc-v2")) {
+   dev_err(dev, "unsupported LPC device binding\n");
+   return -ENODEV;
+   }
+
+   if (of_device_is_compatible(kcs_np, "aspeed,ast2400-kcs-bmc") ||
+   of_device_is_compatible(kcs_np, 
"aspeed,ast2500-kcs-bmc"))
kcs_bmc = aspeed_kcs_probe_of_v1(pdev);
-   else if (of_device_is_compatible(np, "aspeed,ast2400-kcs-bmc-v2") ||
-   of_device_is_compatible(np, 
"aspeed,ast2500-kcs-bmc-v2"))
+   else if (of_device_is_compatible(kcs_np, "aspeed,ast2400-kcs-bmc-v2") ||
+   of_device_is_compatible(kcs_np, 
"aspeed,ast2500-kcs-bmc-v2"))
kcs_bmc = aspeed_kcs_probe_of_v2(pdev);
else
return -EINVAL;


[PATCH i2c/slave-mqueue v5] i2c: slave-mqueue: add a slave backend to receive and queue messages

2018-04-23 Thread Haiyue Wang
Some protocols over I2C are designed for bi-directional transferring
messages by using I2C Master Write protocol. Like the MCTP (Management
Component Transport Protocol) and IPMB (Intelligent Platform Management
Bus), they both require that the userspace can receive messages from
I2C dirvers under slave mode.

This new slave mqueue backend is used to receive and queue messages, it
will exposes these messages to userspace by sysfs bin file.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
v4 -> v5:
 - Typo: bellowing -> the below

v3 -> v4:
 - Drop the small message after receiving I2C STOP.

v2 -> v3:
 - Just remove the ';' after the end '}' of i2c_slave_mqueue_probe().

v1 -> v2:
 - Change MQ_MSGBUF_SIZE and MQ_QUEUE_SIZE to be configurable by Kconfig.
---
 Documentation/i2c/slave-mqueue-backend.rst | 125 ++
 drivers/i2c/Kconfig|  25 
 drivers/i2c/Makefile   |   1 +
 drivers/i2c/i2c-slave-mqueue.c | 203 +
 4 files changed, 354 insertions(+)
 create mode 100644 Documentation/i2c/slave-mqueue-backend.rst
 create mode 100644 drivers/i2c/i2c-slave-mqueue.c

diff --git a/Documentation/i2c/slave-mqueue-backend.rst 
b/Documentation/i2c/slave-mqueue-backend.rst
new file mode 100644
index 000..3966cf0
--- /dev/null
+++ b/Documentation/i2c/slave-mqueue-backend.rst
@@ -0,0 +1,125 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+Linux I2C slave message queue backend
+=====
+
+:Author: Haiyue Wang <haiyue.w...@linux.intel.com>
+
+Some protocols over I2C/SMBus are designed for bi-directional transferring
+messages by using I2C Master Write protocol. This requires that both sides
+of the communication have slave addresses.
+
+Like MCTP (Management Component Transport Protocol) and IPMB (Intelligent
+Platform Management Bus), they both require that the userspace can receive
+messages from i2c dirvers under slave mode.
+
+This I2C slave mqueue (message queue) backend is used to receive and queue
+messages from the remote i2c intelligent device; and it will add the target
+slave address (with R/W# bit is always 0) into the message at the first byte,
+so that userspace can use this byte to dispatch the messages into different
+handling modules. Also, like IPMB, the address byte is in its message format,
+it needs it to do checksum.
+
+For messages are time related, so this backend will flush the oldest message
+to queue the newest one.
+
+Link
+
+`Intelligent Platform Management Bus
+Communications Protocol Specification
+<https://www.intel.com/content/dam/www/public/us/en/documents/product-briefs/ipmp-spec-v1.0.pdf>`_
+
+`Management Component Transport Protocol (MCTP)
+SMBus/I2C Transport Binding Specification
+<https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.1.0.pdf>`_
+
+How to use
+--
+For example, the I2C5 bus has slave address 0x10, the below command will create
+the related message queue interface:
+
+echo slave-mqueue 0x1010 > /sys/bus/i2c/devices/i2c-5/new_device
+
+Then you can dump the messages like this:
+
+hexdump -C /sys/bus/i2c/devices/5-1010/slave-mqueue
+
+Code Example
+
+*Note: call 'lseek' before 'read', this is a requirement from kernfs' design.*
+
+::
+
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+
+  int main(int argc, char *argv[])
+  {
+  int i, r;
+  struct pollfd pfd;
+  struct timespec ts;
+  unsigned char data[256];
+
+  pfd.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
+  if (pfd.fd < 0)
+  return -1;
+
+  pfd.events = POLLPRI;
+
+  while (1) {
+  r = poll(, 1, 5000);
+
+  if (r < 0)
+  break;
+
+  if (r == 0 || !(pfd.revents & POLLPRI))
+  continue;
+
+  lseek(pfd.fd, 0, SEEK_SET);
+  r = read(pfd.fd, data, sizeof(data));
+  if (r <= 0)
+  continue;
+
+  clock_gettime(CLOCK_MONOTONIC, );
+  printf("[%ld.%.9ld] :", ts.tv_sec, ts.tv_nsec);
+  for (i = 0; i < r; i++)
+  printf(" %02x", data[i]);
+  printf("\n");
+  }
+
+  close(pfd.fd);
+
+  return 0;
+  }
+
+Result
+--
+*./a.out "/sys/bus/i2c/devices/5-1010/slave-mqueue"*
+
+::
+
+  [10183.232500449] : 20 18 c8 2c 78 01 5b
+  [10183.479358348] : 20 18 c8 2c 78 01 5b
+  [10183.726556812] : 20 18 c8 2c 78 01 5b
+  [10183.972605863] : 20 18 c8 2c 78 01 5b
+  [10184.220124772] : 20 18 c8 2c 78 01 5b
+  [10184.467764166] : 20 18 c8 2c 78 01 5b
+  [10193.233421784] : 20 18 c8 2c 7c 01 57
+  [10193.480273460] : 20 18 c

[PATCH i2c/slave-mqueue v5] i2c: slave-mqueue: add a slave backend to receive and queue messages

2018-04-23 Thread Haiyue Wang
Some protocols over I2C are designed for bi-directional transferring
messages by using I2C Master Write protocol. Like the MCTP (Management
Component Transport Protocol) and IPMB (Intelligent Platform Management
Bus), they both require that the userspace can receive messages from
I2C dirvers under slave mode.

This new slave mqueue backend is used to receive and queue messages, it
will exposes these messages to userspace by sysfs bin file.

Signed-off-by: Haiyue Wang 
---
v4 -> v5:
 - Typo: bellowing -> the below

v3 -> v4:
 - Drop the small message after receiving I2C STOP.

v2 -> v3:
 - Just remove the ';' after the end '}' of i2c_slave_mqueue_probe().

v1 -> v2:
 - Change MQ_MSGBUF_SIZE and MQ_QUEUE_SIZE to be configurable by Kconfig.
---
 Documentation/i2c/slave-mqueue-backend.rst | 125 ++
 drivers/i2c/Kconfig|  25 
 drivers/i2c/Makefile   |   1 +
 drivers/i2c/i2c-slave-mqueue.c | 203 +
 4 files changed, 354 insertions(+)
 create mode 100644 Documentation/i2c/slave-mqueue-backend.rst
 create mode 100644 drivers/i2c/i2c-slave-mqueue.c

diff --git a/Documentation/i2c/slave-mqueue-backend.rst 
b/Documentation/i2c/slave-mqueue-backend.rst
new file mode 100644
index 000..3966cf0
--- /dev/null
+++ b/Documentation/i2c/slave-mqueue-backend.rst
@@ -0,0 +1,125 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+Linux I2C slave message queue backend
+=====
+
+:Author: Haiyue Wang 
+
+Some protocols over I2C/SMBus are designed for bi-directional transferring
+messages by using I2C Master Write protocol. This requires that both sides
+of the communication have slave addresses.
+
+Like MCTP (Management Component Transport Protocol) and IPMB (Intelligent
+Platform Management Bus), they both require that the userspace can receive
+messages from i2c dirvers under slave mode.
+
+This I2C slave mqueue (message queue) backend is used to receive and queue
+messages from the remote i2c intelligent device; and it will add the target
+slave address (with R/W# bit is always 0) into the message at the first byte,
+so that userspace can use this byte to dispatch the messages into different
+handling modules. Also, like IPMB, the address byte is in its message format,
+it needs it to do checksum.
+
+For messages are time related, so this backend will flush the oldest message
+to queue the newest one.
+
+Link
+
+`Intelligent Platform Management Bus
+Communications Protocol Specification
+<https://www.intel.com/content/dam/www/public/us/en/documents/product-briefs/ipmp-spec-v1.0.pdf>`_
+
+`Management Component Transport Protocol (MCTP)
+SMBus/I2C Transport Binding Specification
+<https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.1.0.pdf>`_
+
+How to use
+--
+For example, the I2C5 bus has slave address 0x10, the below command will create
+the related message queue interface:
+
+echo slave-mqueue 0x1010 > /sys/bus/i2c/devices/i2c-5/new_device
+
+Then you can dump the messages like this:
+
+hexdump -C /sys/bus/i2c/devices/5-1010/slave-mqueue
+
+Code Example
+
+*Note: call 'lseek' before 'read', this is a requirement from kernfs' design.*
+
+::
+
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+
+  int main(int argc, char *argv[])
+  {
+  int i, r;
+  struct pollfd pfd;
+  struct timespec ts;
+  unsigned char data[256];
+
+  pfd.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
+  if (pfd.fd < 0)
+  return -1;
+
+  pfd.events = POLLPRI;
+
+  while (1) {
+  r = poll(, 1, 5000);
+
+  if (r < 0)
+  break;
+
+  if (r == 0 || !(pfd.revents & POLLPRI))
+  continue;
+
+  lseek(pfd.fd, 0, SEEK_SET);
+  r = read(pfd.fd, data, sizeof(data));
+  if (r <= 0)
+  continue;
+
+  clock_gettime(CLOCK_MONOTONIC, );
+  printf("[%ld.%.9ld] :", ts.tv_sec, ts.tv_nsec);
+  for (i = 0; i < r; i++)
+  printf(" %02x", data[i]);
+  printf("\n");
+  }
+
+  close(pfd.fd);
+
+  return 0;
+  }
+
+Result
+--
+*./a.out "/sys/bus/i2c/devices/5-1010/slave-mqueue"*
+
+::
+
+  [10183.232500449] : 20 18 c8 2c 78 01 5b
+  [10183.479358348] : 20 18 c8 2c 78 01 5b
+  [10183.726556812] : 20 18 c8 2c 78 01 5b
+  [10183.972605863] : 20 18 c8 2c 78 01 5b
+  [10184.220124772] : 20 18 c8 2c 78 01 5b
+  [10184.467764166] : 20 18 c8 2c 78 01 5b
+  [10193.233421784] : 20 18 c8 2c 7c 01 57
+  [10193.480273460] : 20 18 c8 2c 7c 01 57
+  [10193.726788733] : 20 18 c8 2c 7c 01 57
+

[PATCH i2c/slave-mqueue v4] i2c: slave-mqueue: add a slave backend to receive and queue messages

2018-04-02 Thread Haiyue Wang
Some protocols over I2C are designed for bi-directional transferring
messages by using I2C Master Write protocol. Like the MCTP (Management
Component Transport Protocol) and IPMB (Intelligent Platform Management
Bus), they both require that the userspace can receive messages from
I2C dirvers under slave mode.

This new slave mqueue backend is used to receive and queue messages, it
will exposes these messages to userspace by sysfs bin file.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
v3 -> v4:
 - Drop the small message after receiving I2C STOP.

v2 -> v3:
 - Just remove the ';' after the end '}' of i2c_slave_mqueue_probe().

v1 -> v2:
 - Change MQ_MSGBUF_SIZE and MQ_QUEUE_SIZE to be configurable by Kconfig.
---
 Documentation/i2c/slave-mqueue-backend.rst | 125 ++
 drivers/i2c/Kconfig|  25 
 drivers/i2c/Makefile   |   1 +
 drivers/i2c/i2c-slave-mqueue.c | 203 +
 4 files changed, 354 insertions(+)
 create mode 100644 Documentation/i2c/slave-mqueue-backend.rst
 create mode 100644 drivers/i2c/i2c-slave-mqueue.c

diff --git a/Documentation/i2c/slave-mqueue-backend.rst 
b/Documentation/i2c/slave-mqueue-backend.rst
new file mode 100644
index 000..69d6437
--- /dev/null
+++ b/Documentation/i2c/slave-mqueue-backend.rst
@@ -0,0 +1,125 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+Linux I2C slave message queue backend
+=====
+
+:Author: Haiyue Wang <haiyue.w...@linux.intel.com>
+
+Some protocols over I2C/SMBus are designed for bi-directional transferring
+messages by using I2C Master Write protocol. This requires that both sides
+of the communication have slave addresses.
+
+Like MCTP (Management Component Transport Protocol) and IPMB (Intelligent
+Platform Management Bus), they both require that the userspace can receive
+messages from i2c dirvers under slave mode.
+
+This I2C slave mqueue (message queue) backend is used to receive and queue
+messages from the remote i2c intelligent device; and it will add the target
+slave address (with R/W# bit is always 0) into the message at the first byte,
+so that userspace can use this byte to dispatch the messages into different
+handling modules. Also, like IPMB, the address byte is in its message format,
+it needs it to do checksum.
+
+For messages are time related, so this backend will flush the oldest message
+to queue the newest one.
+
+Link
+
+`Intelligent Platform Management Bus
+Communications Protocol Specification
+<https://www.intel.com/content/dam/www/public/us/en/documents/product-briefs/ipmp-spec-v1.0.pdf>`_
+
+`Management Component Transport Protocol (MCTP)
+SMBus/I2C Transport Binding Specification
+<https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.1.0.pdf>`_
+
+How to use
+--
+For example, the I2C5 bus has slave address 0x10, bellowing command will create
+the related message queue interface:
+
+echo slave-mqueue 0x1010 > /sys/bus/i2c/devices/i2c-5/new_device
+
+Then you can dump the messages like this:
+
+hexdump -C /sys/bus/i2c/devices/5-1010/slave-mqueue
+
+Code Example
+
+*Note: call 'lseek' before 'read', this is a requirement from kernfs' design.*
+
+::
+
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+
+  int main(int argc, char *argv[])
+  {
+  int i, r;
+  struct pollfd pfd;
+  struct timespec ts;
+  unsigned char data[256];
+
+  pfd.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
+  if (pfd.fd < 0)
+  return -1;
+
+  pfd.events = POLLPRI;
+
+  while (1) {
+  r = poll(, 1, 5000);
+
+  if (r < 0)
+  break;
+
+  if (r == 0 || !(pfd.revents & POLLPRI))
+  continue;
+
+  lseek(pfd.fd, 0, SEEK_SET);
+  r = read(pfd.fd, data, sizeof(data));
+  if (r <= 0)
+  continue;
+
+  clock_gettime(CLOCK_MONOTONIC, );
+  printf("[%ld.%.9ld] :", ts.tv_sec, ts.tv_nsec);
+  for (i = 0; i < r; i++)
+  printf(" %02x", data[i]);
+  printf("\n");
+  }
+
+  close(pfd.fd);
+
+  return 0;
+  }
+
+Result
+--
+*./a.out "/sys/bus/i2c/devices/5-1010/slave-mqueue"*
+
+::
+
+  [10183.232500449] : 20 18 c8 2c 78 01 5b
+  [10183.479358348] : 20 18 c8 2c 78 01 5b
+  [10183.726556812] : 20 18 c8 2c 78 01 5b
+  [10183.972605863] : 20 18 c8 2c 78 01 5b
+  [10184.220124772] : 20 18 c8 2c 78 01 5b
+  [10184.467764166] : 20 18 c8 2c 78 01 5b
+  [10193.233421784] : 20 18 c8 2c 7c 01 57
+  [10193.480273460] : 20 18 c8 2c 7c 01 57
+  [10193.726788733] : 20 18 c8 2c 7

[PATCH i2c/slave-mqueue v4] i2c: slave-mqueue: add a slave backend to receive and queue messages

2018-04-02 Thread Haiyue Wang
Some protocols over I2C are designed for bi-directional transferring
messages by using I2C Master Write protocol. Like the MCTP (Management
Component Transport Protocol) and IPMB (Intelligent Platform Management
Bus), they both require that the userspace can receive messages from
I2C dirvers under slave mode.

This new slave mqueue backend is used to receive and queue messages, it
will exposes these messages to userspace by sysfs bin file.

Signed-off-by: Haiyue Wang 
---
v3 -> v4:
 - Drop the small message after receiving I2C STOP.

v2 -> v3:
 - Just remove the ';' after the end '}' of i2c_slave_mqueue_probe().

v1 -> v2:
 - Change MQ_MSGBUF_SIZE and MQ_QUEUE_SIZE to be configurable by Kconfig.
---
 Documentation/i2c/slave-mqueue-backend.rst | 125 ++
 drivers/i2c/Kconfig|  25 
 drivers/i2c/Makefile   |   1 +
 drivers/i2c/i2c-slave-mqueue.c | 203 +
 4 files changed, 354 insertions(+)
 create mode 100644 Documentation/i2c/slave-mqueue-backend.rst
 create mode 100644 drivers/i2c/i2c-slave-mqueue.c

diff --git a/Documentation/i2c/slave-mqueue-backend.rst 
b/Documentation/i2c/slave-mqueue-backend.rst
new file mode 100644
index 000..69d6437
--- /dev/null
+++ b/Documentation/i2c/slave-mqueue-backend.rst
@@ -0,0 +1,125 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+Linux I2C slave message queue backend
+=
+
+:Author: Haiyue Wang 
+
+Some protocols over I2C/SMBus are designed for bi-directional transferring
+messages by using I2C Master Write protocol. This requires that both sides
+of the communication have slave addresses.
+
+Like MCTP (Management Component Transport Protocol) and IPMB (Intelligent
+Platform Management Bus), they both require that the userspace can receive
+messages from i2c dirvers under slave mode.
+
+This I2C slave mqueue (message queue) backend is used to receive and queue
+messages from the remote i2c intelligent device; and it will add the target
+slave address (with R/W# bit is always 0) into the message at the first byte,
+so that userspace can use this byte to dispatch the messages into different
+handling modules. Also, like IPMB, the address byte is in its message format,
+it needs it to do checksum.
+
+For messages are time related, so this backend will flush the oldest message
+to queue the newest one.
+
+Link
+
+`Intelligent Platform Management Bus
+Communications Protocol Specification
+<https://www.intel.com/content/dam/www/public/us/en/documents/product-briefs/ipmp-spec-v1.0.pdf>`_
+
+`Management Component Transport Protocol (MCTP)
+SMBus/I2C Transport Binding Specification
+<https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.1.0.pdf>`_
+
+How to use
+--
+For example, the I2C5 bus has slave address 0x10, bellowing command will create
+the related message queue interface:
+
+echo slave-mqueue 0x1010 > /sys/bus/i2c/devices/i2c-5/new_device
+
+Then you can dump the messages like this:
+
+hexdump -C /sys/bus/i2c/devices/5-1010/slave-mqueue
+
+Code Example
+
+*Note: call 'lseek' before 'read', this is a requirement from kernfs' design.*
+
+::
+
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+
+  int main(int argc, char *argv[])
+  {
+  int i, r;
+  struct pollfd pfd;
+  struct timespec ts;
+  unsigned char data[256];
+
+  pfd.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
+  if (pfd.fd < 0)
+  return -1;
+
+  pfd.events = POLLPRI;
+
+  while (1) {
+  r = poll(, 1, 5000);
+
+  if (r < 0)
+  break;
+
+  if (r == 0 || !(pfd.revents & POLLPRI))
+  continue;
+
+  lseek(pfd.fd, 0, SEEK_SET);
+  r = read(pfd.fd, data, sizeof(data));
+  if (r <= 0)
+  continue;
+
+  clock_gettime(CLOCK_MONOTONIC, );
+  printf("[%ld.%.9ld] :", ts.tv_sec, ts.tv_nsec);
+  for (i = 0; i < r; i++)
+  printf(" %02x", data[i]);
+  printf("\n");
+  }
+
+  close(pfd.fd);
+
+  return 0;
+  }
+
+Result
+--
+*./a.out "/sys/bus/i2c/devices/5-1010/slave-mqueue"*
+
+::
+
+  [10183.232500449] : 20 18 c8 2c 78 01 5b
+  [10183.479358348] : 20 18 c8 2c 78 01 5b
+  [10183.726556812] : 20 18 c8 2c 78 01 5b
+  [10183.972605863] : 20 18 c8 2c 78 01 5b
+  [10184.220124772] : 20 18 c8 2c 78 01 5b
+  [10184.467764166] : 20 18 c8 2c 78 01 5b
+  [10193.233421784] : 20 18 c8 2c 7c 01 57
+  [10193.480273460] : 20 18 c8 2c 7c 01 57
+  [10193.726788733] : 20 18 c8 2c 7c 01 57
+  [10193.972781945] : 20 18 c8 2c 7c 01 57
+  [101

[PATCH dts/arm/aspeed-g5 v1] ARM: dts: aspeed-g5: Add IPMI KCS nodes for SMS and SMM mode

2018-03-31 Thread Haiyue Wang
The IPMI KCS device part of the LPC interface and is used for
communication with the host processor.

Keyboard Controller Style Interfaces:
The KCS channel number is assigned by AST_usrGuide_KCS.pdf
Name  | Use  | Address   | KCS Channel |
SMS Interface | SMS  | 0CA2h – 0CA3h | kcs3|
SMM Interface | SMI handling | 0CA4h – 0CA5h | kcs4|

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
The kcs_bmc_aspeed driver is in linux-next now:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/char/ipmi/kcs_bmc_aspeed.c?h=next-20180329
---
 arch/arm/boot/dts/aspeed-g5.dtsi | 25 -
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/aspeed-g5.dtsi b/arch/arm/boot/dts/aspeed-g5.dtsi
index 17ee0fa3..8d6c4af 100644
--- a/arch/arm/boot/dts/aspeed-g5.dtsi
+++ b/arch/arm/boot/dts/aspeed-g5.dtsi
@@ -268,8 +268,22 @@
ranges = <0x0 0x1e789000 0x1000>;
 
lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2500-lpc-bmc";
+   compatible = "aspeed,ast2500-lpc-bmc", 
"simple-mfd", "syscon";
reg = <0x0 0x80>;
+   reg-io-width = <4>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x0 0x80>;
+
+   kcs3: kcs3@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <3>;
+   kcs_addr = <0xca2>;
+   status = "disabled";
+   };
};
 
lpc_host: lpc-host@80 {
@@ -281,6 +295,15 @@
#size-cells = <1>;
ranges = <0x0 0x80 0x1e0>;
 
+   kcs4: kcs4@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0xa0>;
+   interrupts = <8>;
+   kcs_chan = <4>;
+   kcs_addr = <0xca4>;
+   status = "disabled";
+   };
+
lpc_ctrl: lpc-ctrl@0 {
compatible = 
"aspeed,ast2500-lpc-ctrl";
reg = <0x0 0x80>;
-- 
2.7.4



[PATCH dts/arm/aspeed-g5 v1] ARM: dts: aspeed-g5: Add IPMI KCS nodes for SMS and SMM mode

2018-03-31 Thread Haiyue Wang
The IPMI KCS device part of the LPC interface and is used for
communication with the host processor.

Keyboard Controller Style Interfaces:
The KCS channel number is assigned by AST_usrGuide_KCS.pdf
Name  | Use  | Address   | KCS Channel |
SMS Interface | SMS  | 0CA2h – 0CA3h | kcs3|
SMM Interface | SMI handling | 0CA4h – 0CA5h | kcs4|

Signed-off-by: Haiyue Wang 
---
The kcs_bmc_aspeed driver is in linux-next now:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/char/ipmi/kcs_bmc_aspeed.c?h=next-20180329
---
 arch/arm/boot/dts/aspeed-g5.dtsi | 25 -
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/aspeed-g5.dtsi b/arch/arm/boot/dts/aspeed-g5.dtsi
index 17ee0fa3..8d6c4af 100644
--- a/arch/arm/boot/dts/aspeed-g5.dtsi
+++ b/arch/arm/boot/dts/aspeed-g5.dtsi
@@ -268,8 +268,22 @@
ranges = <0x0 0x1e789000 0x1000>;
 
lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2500-lpc-bmc";
+   compatible = "aspeed,ast2500-lpc-bmc", 
"simple-mfd", "syscon";
reg = <0x0 0x80>;
+   reg-io-width = <4>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x0 0x80>;
+
+   kcs3: kcs3@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <3>;
+   kcs_addr = <0xca2>;
+   status = "disabled";
+   };
};
 
lpc_host: lpc-host@80 {
@@ -281,6 +295,15 @@
#size-cells = <1>;
ranges = <0x0 0x80 0x1e0>;
 
+   kcs4: kcs4@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0xa0>;
+   interrupts = <8>;
+   kcs_chan = <4>;
+   kcs_addr = <0xca4>;
+   status = "disabled";
+   };
+
lpc_ctrl: lpc-ctrl@0 {
compatible = 
"aspeed,ast2500-lpc-ctrl";
reg = <0x0 0x80>;
-- 
2.7.4



[PATCH i2c/slave-mqueue v3] i2c: slave-mqueue: add a slave backend to receive and queue messages

2018-03-28 Thread Haiyue Wang
Some protocols over I2C are designed for bi-directional transferring
messages by using I2C Master Write protocol. Like the MCTP (Management
Component Transport Protocol) and IPMB (Intelligent Platform Management
Bus), they both require that the userspace can receive messages from
I2C dirvers under slave mode.

This new slave mqueue backend is used to receive and queue messages, it
will exposes these messages to userspace by sysfs bin file.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
v2 -> v3:
 - Just remove the ';' after the end '}' of i2c_slave_mqueue_probe().

v1 -> v2:
 - Change MQ_MSGBUF_SIZE and MQ_QUEUE_SIZE to be configurable by Kconfig.
---
 Documentation/i2c/slave-mqueue-backend.rst | 125 ++
 drivers/i2c/Kconfig|  25 
 drivers/i2c/Makefile   |   1 +
 drivers/i2c/i2c-slave-mqueue.c | 202 +
 4 files changed, 353 insertions(+)
 create mode 100644 Documentation/i2c/slave-mqueue-backend.rst
 create mode 100644 drivers/i2c/i2c-slave-mqueue.c

diff --git a/Documentation/i2c/slave-mqueue-backend.rst 
b/Documentation/i2c/slave-mqueue-backend.rst
new file mode 100644
index 000..69d6437
--- /dev/null
+++ b/Documentation/i2c/slave-mqueue-backend.rst
@@ -0,0 +1,125 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+Linux I2C slave message queue backend
+=
+
+:Author: Haiyue Wang <haiyue.w...@linux.intel.com>
+
+Some protocols over I2C/SMBus are designed for bi-directional transferring
+messages by using I2C Master Write protocol. This requires that both sides
+of the communication have slave addresses.
+
+Like MCTP (Management Component Transport Protocol) and IPMB (Intelligent
+Platform Management Bus), they both require that the userspace can receive
+messages from i2c dirvers under slave mode.
+
+This I2C slave mqueue (message queue) backend is used to receive and queue
+messages from the remote i2c intelligent device; and it will add the target
+slave address (with R/W# bit is always 0) into the message at the first byte,
+so that userspace can use this byte to dispatch the messages into different
+handling modules. Also, like IPMB, the address byte is in its message format,
+it needs it to do checksum.
+
+For messages are time related, so this backend will flush the oldest message
+to queue the newest one.
+
+Link
+
+`Intelligent Platform Management Bus
+Communications Protocol Specification
+<https://www.intel.com/content/dam/www/public/us/en/documents/product-briefs/ipmp-spec-v1.0.pdf>`_
+
+`Management Component Transport Protocol (MCTP)
+SMBus/I2C Transport Binding Specification
+<https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.1.0.pdf>`_
+
+How to use
+--
+For example, the I2C5 bus has slave address 0x10, bellowing command will create
+the related message queue interface:
+
+echo slave-mqueue 0x1010 > /sys/bus/i2c/devices/i2c-5/new_device
+
+Then you can dump the messages like this:
+
+hexdump -C /sys/bus/i2c/devices/5-1010/slave-mqueue
+
+Code Example
+
+*Note: call 'lseek' before 'read', this is a requirement from kernfs' design.*
+
+::
+
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+
+  int main(int argc, char *argv[])
+  {
+  int i, r;
+  struct pollfd pfd;
+  struct timespec ts;
+  unsigned char data[256];
+
+  pfd.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
+  if (pfd.fd < 0)
+  return -1;
+
+  pfd.events = POLLPRI;
+
+  while (1) {
+  r = poll(, 1, 5000);
+
+  if (r < 0)
+  break;
+
+  if (r == 0 || !(pfd.revents & POLLPRI))
+  continue;
+
+  lseek(pfd.fd, 0, SEEK_SET);
+  r = read(pfd.fd, data, sizeof(data));
+  if (r <= 0)
+  continue;
+
+  clock_gettime(CLOCK_MONOTONIC, );
+  printf("[%ld.%.9ld] :", ts.tv_sec, ts.tv_nsec);
+  for (i = 0; i < r; i++)
+  printf(" %02x", data[i]);
+  printf("\n");
+  }
+
+  close(pfd.fd);
+
+  return 0;
+  }
+
+Result
+--
+*./a.out "/sys/bus/i2c/devices/5-1010/slave-mqueue"*
+
+::
+
+  [10183.232500449] : 20 18 c8 2c 78 01 5b
+  [10183.479358348] : 20 18 c8 2c 78 01 5b
+  [10183.726556812] : 20 18 c8 2c 78 01 5b
+  [10183.972605863] : 20 18 c8 2c 78 01 5b
+  [10184.220124772] : 20 18 c8 2c 78 01 5b
+  [10184.467764166] : 20 18 c8 2c 78 01 5b
+  [10193.233421784] : 20 18 c8 2c 7c 01 57
+  [10193.480273460] : 20 18 c8 2c 7c 01 57
+  [10193.726788733] : 20 18 c8 2c 7c 01 57
+  [10193.972781945] : 20 18 c8 2c 7c 01 5

[PATCH i2c/slave-mqueue v3] i2c: slave-mqueue: add a slave backend to receive and queue messages

2018-03-28 Thread Haiyue Wang
Some protocols over I2C are designed for bi-directional transferring
messages by using I2C Master Write protocol. Like the MCTP (Management
Component Transport Protocol) and IPMB (Intelligent Platform Management
Bus), they both require that the userspace can receive messages from
I2C dirvers under slave mode.

This new slave mqueue backend is used to receive and queue messages, it
will exposes these messages to userspace by sysfs bin file.

Signed-off-by: Haiyue Wang 
---
v2 -> v3:
 - Just remove the ';' after the end '}' of i2c_slave_mqueue_probe().

v1 -> v2:
 - Change MQ_MSGBUF_SIZE and MQ_QUEUE_SIZE to be configurable by Kconfig.
---
 Documentation/i2c/slave-mqueue-backend.rst | 125 ++
 drivers/i2c/Kconfig|  25 
 drivers/i2c/Makefile   |   1 +
 drivers/i2c/i2c-slave-mqueue.c | 202 +
 4 files changed, 353 insertions(+)
 create mode 100644 Documentation/i2c/slave-mqueue-backend.rst
 create mode 100644 drivers/i2c/i2c-slave-mqueue.c

diff --git a/Documentation/i2c/slave-mqueue-backend.rst 
b/Documentation/i2c/slave-mqueue-backend.rst
new file mode 100644
index 000..69d6437
--- /dev/null
+++ b/Documentation/i2c/slave-mqueue-backend.rst
@@ -0,0 +1,125 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+Linux I2C slave message queue backend
+=
+
+:Author: Haiyue Wang 
+
+Some protocols over I2C/SMBus are designed for bi-directional transferring
+messages by using I2C Master Write protocol. This requires that both sides
+of the communication have slave addresses.
+
+Like MCTP (Management Component Transport Protocol) and IPMB (Intelligent
+Platform Management Bus), they both require that the userspace can receive
+messages from i2c dirvers under slave mode.
+
+This I2C slave mqueue (message queue) backend is used to receive and queue
+messages from the remote i2c intelligent device; and it will add the target
+slave address (with R/W# bit is always 0) into the message at the first byte,
+so that userspace can use this byte to dispatch the messages into different
+handling modules. Also, like IPMB, the address byte is in its message format,
+it needs it to do checksum.
+
+For messages are time related, so this backend will flush the oldest message
+to queue the newest one.
+
+Link
+
+`Intelligent Platform Management Bus
+Communications Protocol Specification
+<https://www.intel.com/content/dam/www/public/us/en/documents/product-briefs/ipmp-spec-v1.0.pdf>`_
+
+`Management Component Transport Protocol (MCTP)
+SMBus/I2C Transport Binding Specification
+<https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.1.0.pdf>`_
+
+How to use
+--
+For example, the I2C5 bus has slave address 0x10, bellowing command will create
+the related message queue interface:
+
+echo slave-mqueue 0x1010 > /sys/bus/i2c/devices/i2c-5/new_device
+
+Then you can dump the messages like this:
+
+hexdump -C /sys/bus/i2c/devices/5-1010/slave-mqueue
+
+Code Example
+
+*Note: call 'lseek' before 'read', this is a requirement from kernfs' design.*
+
+::
+
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+
+  int main(int argc, char *argv[])
+  {
+  int i, r;
+  struct pollfd pfd;
+  struct timespec ts;
+  unsigned char data[256];
+
+  pfd.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
+  if (pfd.fd < 0)
+  return -1;
+
+  pfd.events = POLLPRI;
+
+  while (1) {
+  r = poll(, 1, 5000);
+
+  if (r < 0)
+  break;
+
+  if (r == 0 || !(pfd.revents & POLLPRI))
+  continue;
+
+  lseek(pfd.fd, 0, SEEK_SET);
+  r = read(pfd.fd, data, sizeof(data));
+  if (r <= 0)
+  continue;
+
+  clock_gettime(CLOCK_MONOTONIC, );
+  printf("[%ld.%.9ld] :", ts.tv_sec, ts.tv_nsec);
+  for (i = 0; i < r; i++)
+  printf(" %02x", data[i]);
+  printf("\n");
+  }
+
+  close(pfd.fd);
+
+  return 0;
+  }
+
+Result
+--
+*./a.out "/sys/bus/i2c/devices/5-1010/slave-mqueue"*
+
+::
+
+  [10183.232500449] : 20 18 c8 2c 78 01 5b
+  [10183.479358348] : 20 18 c8 2c 78 01 5b
+  [10183.726556812] : 20 18 c8 2c 78 01 5b
+  [10183.972605863] : 20 18 c8 2c 78 01 5b
+  [10184.220124772] : 20 18 c8 2c 78 01 5b
+  [10184.467764166] : 20 18 c8 2c 78 01 5b
+  [10193.233421784] : 20 18 c8 2c 7c 01 57
+  [10193.480273460] : 20 18 c8 2c 7c 01 57
+  [10193.726788733] : 20 18 c8 2c 7c 01 57
+  [10193.972781945] : 20 18 c8 2c 7c 01 57
+  [10194.220487360] : 20 18 c8 2c 7c 01 57
+  [10194.468089259] : 20 18 c8 2c 7c 0

[PATCH i2c/slave-mqueue v2] i2c: slave-mqueue: add a slave backend to receive and queue messages

2018-03-23 Thread Haiyue Wang
Some protocols over I2C are designed for bi-directional transferring
messages by using I2C Master Write protocol. Like the MCTP (Management
Component Transport Protocol) and IPMB (Intelligent Platform Management
Bus), they both require that the userspace can receive messages from
I2C dirvers under slave mode.

This new slave mqueue backend is used to receive and queue messages, it
will exposes these messages to userspace by sysfs bin file.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
v1 -> v2:
 - Change MQ_MSGBUF_SIZE and MQ_QUEUE_SIZE to be configurable by Kconfig.
---
 Documentation/i2c/slave-mqueue-backend.rst | 125 ++
 drivers/i2c/Kconfig|  25 
 drivers/i2c/Makefile   |   1 +
 drivers/i2c/i2c-slave-mqueue.c | 202 +
 4 files changed, 353 insertions(+)
 create mode 100644 Documentation/i2c/slave-mqueue-backend.rst
 create mode 100644 drivers/i2c/i2c-slave-mqueue.c

diff --git a/Documentation/i2c/slave-mqueue-backend.rst 
b/Documentation/i2c/slave-mqueue-backend.rst
new file mode 100644
index 000..69d6437
--- /dev/null
+++ b/Documentation/i2c/slave-mqueue-backend.rst
@@ -0,0 +1,125 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+Linux I2C slave message queue backend
+=
+
+:Author: Haiyue Wang <haiyue.w...@linux.intel.com>
+
+Some protocols over I2C/SMBus are designed for bi-directional transferring
+messages by using I2C Master Write protocol. This requires that both sides
+of the communication have slave addresses.
+
+Like MCTP (Management Component Transport Protocol) and IPMB (Intelligent
+Platform Management Bus), they both require that the userspace can receive
+messages from i2c dirvers under slave mode.
+
+This I2C slave mqueue (message queue) backend is used to receive and queue
+messages from the remote i2c intelligent device; and it will add the target
+slave address (with R/W# bit is always 0) into the message at the first byte,
+so that userspace can use this byte to dispatch the messages into different
+handling modules. Also, like IPMB, the address byte is in its message format,
+it needs it to do checksum.
+
+For messages are time related, so this backend will flush the oldest message
+to queue the newest one.
+
+Link
+
+`Intelligent Platform Management Bus
+Communications Protocol Specification
+<https://www.intel.com/content/dam/www/public/us/en/documents/product-briefs/ipmp-spec-v1.0.pdf>`_
+
+`Management Component Transport Protocol (MCTP)
+SMBus/I2C Transport Binding Specification
+<https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.1.0.pdf>`_
+
+How to use
+--
+For example, the I2C5 bus has slave address 0x10, bellowing command will create
+the related message queue interface:
+
+echo slave-mqueue 0x1010 > /sys/bus/i2c/devices/i2c-5/new_device
+
+Then you can dump the messages like this:
+
+hexdump -C /sys/bus/i2c/devices/5-1010/slave-mqueue
+
+Code Example
+
+*Note: call 'lseek' before 'read', this is a requirement from kernfs' design.*
+
+::
+
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+
+  int main(int argc, char *argv[])
+  {
+  int i, r;
+  struct pollfd pfd;
+  struct timespec ts;
+  unsigned char data[256];
+
+  pfd.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
+  if (pfd.fd < 0)
+  return -1;
+
+  pfd.events = POLLPRI;
+
+  while (1) {
+  r = poll(, 1, 5000);
+
+  if (r < 0)
+  break;
+
+  if (r == 0 || !(pfd.revents & POLLPRI))
+  continue;
+
+  lseek(pfd.fd, 0, SEEK_SET);
+  r = read(pfd.fd, data, sizeof(data));
+  if (r <= 0)
+  continue;
+
+  clock_gettime(CLOCK_MONOTONIC, );
+  printf("[%ld.%.9ld] :", ts.tv_sec, ts.tv_nsec);
+  for (i = 0; i < r; i++)
+  printf(" %02x", data[i]);
+  printf("\n");
+  }
+
+  close(pfd.fd);
+
+  return 0;
+  }
+
+Result
+--
+*./a.out "/sys/bus/i2c/devices/5-1010/slave-mqueue"*
+
+::
+
+  [10183.232500449] : 20 18 c8 2c 78 01 5b
+  [10183.479358348] : 20 18 c8 2c 78 01 5b
+  [10183.726556812] : 20 18 c8 2c 78 01 5b
+  [10183.972605863] : 20 18 c8 2c 78 01 5b
+  [10184.220124772] : 20 18 c8 2c 78 01 5b
+  [10184.467764166] : 20 18 c8 2c 78 01 5b
+  [10193.233421784] : 20 18 c8 2c 7c 01 57
+  [10193.480273460] : 20 18 c8 2c 7c 01 57
+  [10193.726788733] : 20 18 c8 2c 7c 01 57
+  [10193.972781945] : 20 18 c8 2c 7c 01 57
+  [10194.220487360] : 20 18 c8 2c 7c 01 57
+  [10194.468089259] : 20 18 c8 2c 7c 01 57
+

[PATCH i2c/slave-mqueue v2] i2c: slave-mqueue: add a slave backend to receive and queue messages

2018-03-23 Thread Haiyue Wang
Some protocols over I2C are designed for bi-directional transferring
messages by using I2C Master Write protocol. Like the MCTP (Management
Component Transport Protocol) and IPMB (Intelligent Platform Management
Bus), they both require that the userspace can receive messages from
I2C dirvers under slave mode.

This new slave mqueue backend is used to receive and queue messages, it
will exposes these messages to userspace by sysfs bin file.

Signed-off-by: Haiyue Wang 
---
v1 -> v2:
 - Change MQ_MSGBUF_SIZE and MQ_QUEUE_SIZE to be configurable by Kconfig.
---
 Documentation/i2c/slave-mqueue-backend.rst | 125 ++
 drivers/i2c/Kconfig|  25 
 drivers/i2c/Makefile   |   1 +
 drivers/i2c/i2c-slave-mqueue.c | 202 +
 4 files changed, 353 insertions(+)
 create mode 100644 Documentation/i2c/slave-mqueue-backend.rst
 create mode 100644 drivers/i2c/i2c-slave-mqueue.c

diff --git a/Documentation/i2c/slave-mqueue-backend.rst 
b/Documentation/i2c/slave-mqueue-backend.rst
new file mode 100644
index 000..69d6437
--- /dev/null
+++ b/Documentation/i2c/slave-mqueue-backend.rst
@@ -0,0 +1,125 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+Linux I2C slave message queue backend
+=
+
+:Author: Haiyue Wang 
+
+Some protocols over I2C/SMBus are designed for bi-directional transferring
+messages by using I2C Master Write protocol. This requires that both sides
+of the communication have slave addresses.
+
+Like MCTP (Management Component Transport Protocol) and IPMB (Intelligent
+Platform Management Bus), they both require that the userspace can receive
+messages from i2c dirvers under slave mode.
+
+This I2C slave mqueue (message queue) backend is used to receive and queue
+messages from the remote i2c intelligent device; and it will add the target
+slave address (with R/W# bit is always 0) into the message at the first byte,
+so that userspace can use this byte to dispatch the messages into different
+handling modules. Also, like IPMB, the address byte is in its message format,
+it needs it to do checksum.
+
+For messages are time related, so this backend will flush the oldest message
+to queue the newest one.
+
+Link
+
+`Intelligent Platform Management Bus
+Communications Protocol Specification
+<https://www.intel.com/content/dam/www/public/us/en/documents/product-briefs/ipmp-spec-v1.0.pdf>`_
+
+`Management Component Transport Protocol (MCTP)
+SMBus/I2C Transport Binding Specification
+<https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.1.0.pdf>`_
+
+How to use
+--
+For example, the I2C5 bus has slave address 0x10, bellowing command will create
+the related message queue interface:
+
+echo slave-mqueue 0x1010 > /sys/bus/i2c/devices/i2c-5/new_device
+
+Then you can dump the messages like this:
+
+hexdump -C /sys/bus/i2c/devices/5-1010/slave-mqueue
+
+Code Example
+
+*Note: call 'lseek' before 'read', this is a requirement from kernfs' design.*
+
+::
+
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+
+  int main(int argc, char *argv[])
+  {
+  int i, r;
+  struct pollfd pfd;
+  struct timespec ts;
+  unsigned char data[256];
+
+  pfd.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
+  if (pfd.fd < 0)
+  return -1;
+
+  pfd.events = POLLPRI;
+
+  while (1) {
+  r = poll(, 1, 5000);
+
+  if (r < 0)
+  break;
+
+  if (r == 0 || !(pfd.revents & POLLPRI))
+  continue;
+
+  lseek(pfd.fd, 0, SEEK_SET);
+  r = read(pfd.fd, data, sizeof(data));
+  if (r <= 0)
+  continue;
+
+  clock_gettime(CLOCK_MONOTONIC, );
+  printf("[%ld.%.9ld] :", ts.tv_sec, ts.tv_nsec);
+  for (i = 0; i < r; i++)
+  printf(" %02x", data[i]);
+  printf("\n");
+  }
+
+  close(pfd.fd);
+
+  return 0;
+  }
+
+Result
+--
+*./a.out "/sys/bus/i2c/devices/5-1010/slave-mqueue"*
+
+::
+
+  [10183.232500449] : 20 18 c8 2c 78 01 5b
+  [10183.479358348] : 20 18 c8 2c 78 01 5b
+  [10183.726556812] : 20 18 c8 2c 78 01 5b
+  [10183.972605863] : 20 18 c8 2c 78 01 5b
+  [10184.220124772] : 20 18 c8 2c 78 01 5b
+  [10184.467764166] : 20 18 c8 2c 78 01 5b
+  [10193.233421784] : 20 18 c8 2c 7c 01 57
+  [10193.480273460] : 20 18 c8 2c 7c 01 57
+  [10193.726788733] : 20 18 c8 2c 7c 01 57
+  [10193.972781945] : 20 18 c8 2c 7c 01 57
+  [10194.220487360] : 20 18 c8 2c 7c 01 57
+  [10194.468089259] : 20 18 c8 2c 7c 01 57
+  [10203.233433099] : 20 18 c8 2c 80 01 53
+  [10203.481058715] : 20 18 c8 2

[PATCH ipmi/kcs_bmc v1] ipmi: add an NPCM7xx KCS BMC driver

2018-03-22 Thread Haiyue Wang
This driver exposes the Keyboard Controller Style (KCS) interface on
Novoton NPCM7xx SoCs as a character device. Such SOCs are commonly used
as a BaseBoard Management Controller (BMC) on a server board, and KCS
interface is commonly used to perform the in-band IPMI communication
between the server and its BMC.

Signed-off-by: Avi Fishman <avifishma...@gmail.com>
Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 .../devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt   |  39 
 drivers/char/ipmi/Kconfig  |  15 ++
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs_bmc_npcm7xx.c| 204 +
 4 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs_bmc_npcm7xx.c

diff --git a/Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt
new file mode 100644
index 000..3538a21
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt
@@ -0,0 +1,39 @@
+* Nuvoton NPCM7xx KCS (Keyboard Controller Style) IPMI interface
+
+The Nuvoton SOCs (NPCM7xx) are commonly used as BMCs
+(Baseboard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"nuvoton,npcm750-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The KCS channel number in the controller
+
+Example:
+
+lpc_kcs: lpc_kcs@f0007000 {
+compatible = "nuvoton,npcm750-lpc-kcs", "simple-mfd", "syscon";
+reg = <0xf0007000 0x40>;
+reg-io-width = <1>;
+
+#address-cells = <1>;
+#size-cells = <1>;
+ranges = <0x0 0xf0007000 0x40>;
+
+kcs1: kcs1@0 {
+compatible = "nuvoton,npcm750-kcs-bmc";
+reg = <0x0 0x40>;
+interrupts = <0 9 4>;
+kcs_chan = <1>;
+status = "disabled";
+};
+
+kcs2: kcs2@0 {
+compatible = "nuvoton,npcm750-kcs-bmc";
+reg = <0x0 0x40>;
+interrupts = <0 9 4>;
+kcs_chan = <2>;
+status = "disabled";
+};
+};
\ No newline at end of file
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3bda116..470f976 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -111,6 +111,21 @@ config ASPEED_KCS_IPMI_BMC
  The driver implements the BMC side of the KCS contorller, it
  provides the access of KCS IO space for BMC side.
 
+config NPCM7XX_KCS_IPMI_BMC
+   depends on ARCH_NPCM7XX || COMPILE_TEST
+   select IPMI_KCS_BMC
+   select REGMAP_MMIO
+   tristate "NPCM7xx KCS IPMI BMC driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Nuvoton NPCM7xx SOCs.
+
+ The driver implements the BMC side of the KCS contorller, it
+ provides the access of KCS IO space for BMC side.
+
+ This support is also available as a module.  If so, the module
+ will be called kcs_bmc_npcm7xx.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 21e9e87..7a3baf3 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -24,3 +24,4 @@ obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 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
diff --git a/drivers/char/ipmi/kcs_bmc_npcm7xx.c 
b/drivers/char/ipmi/kcs_bmc_npcm7xx.c
new file mode 100644
index 000..7bc898c
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc_npcm7xx.c
@@ -0,0 +1,204 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, Nuvoton Corporation.
+ * Copyright (c) 2018, Intel Corporation.
+ */
+
+#define pr_fmt(fmt) "nuvoton-kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+#define DEVICE_NAME"npcm-kcs-bmc"
+#define KCS_CHANNEL_MAX3
+
+#define KCS1ST 0x0C
+#define KCS2ST 0x1E
+#define KCS3ST 0x30
+
+#define KCS1DO 0x0E
+#define KCS2DO 0x20
+#define KCS3DO 0x32
+
+#define KCS1DI 0x10
+#define KCS2DI 0x22
+#define KCS3DI 0x34
+
+#define KCS1CTL0x18
+#define KCS2CTL0x2A
+#define KCS3CTL  

[PATCH ipmi/kcs_bmc v1] ipmi: add an NPCM7xx KCS BMC driver

2018-03-22 Thread Haiyue Wang
This driver exposes the Keyboard Controller Style (KCS) interface on
Novoton NPCM7xx SoCs as a character device. Such SOCs are commonly used
as a BaseBoard Management Controller (BMC) on a server board, and KCS
interface is commonly used to perform the in-band IPMI communication
between the server and its BMC.

Signed-off-by: Avi Fishman 
Signed-off-by: Haiyue Wang 
---
 .../devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt   |  39 
 drivers/char/ipmi/Kconfig  |  15 ++
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs_bmc_npcm7xx.c| 204 +
 4 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs_bmc_npcm7xx.c

diff --git a/Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt
new file mode 100644
index 000..3538a21
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt
@@ -0,0 +1,39 @@
+* Nuvoton NPCM7xx KCS (Keyboard Controller Style) IPMI interface
+
+The Nuvoton SOCs (NPCM7xx) are commonly used as BMCs
+(Baseboard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"nuvoton,npcm750-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The KCS channel number in the controller
+
+Example:
+
+lpc_kcs: lpc_kcs@f0007000 {
+compatible = "nuvoton,npcm750-lpc-kcs", "simple-mfd", "syscon";
+reg = <0xf0007000 0x40>;
+reg-io-width = <1>;
+
+#address-cells = <1>;
+#size-cells = <1>;
+ranges = <0x0 0xf0007000 0x40>;
+
+kcs1: kcs1@0 {
+compatible = "nuvoton,npcm750-kcs-bmc";
+reg = <0x0 0x40>;
+interrupts = <0 9 4>;
+kcs_chan = <1>;
+status = "disabled";
+};
+
+kcs2: kcs2@0 {
+compatible = "nuvoton,npcm750-kcs-bmc";
+reg = <0x0 0x40>;
+interrupts = <0 9 4>;
+kcs_chan = <2>;
+status = "disabled";
+};
+};
\ No newline at end of file
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3bda116..470f976 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -111,6 +111,21 @@ config ASPEED_KCS_IPMI_BMC
  The driver implements the BMC side of the KCS contorller, it
  provides the access of KCS IO space for BMC side.
 
+config NPCM7XX_KCS_IPMI_BMC
+   depends on ARCH_NPCM7XX || COMPILE_TEST
+   select IPMI_KCS_BMC
+   select REGMAP_MMIO
+   tristate "NPCM7xx KCS IPMI BMC driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Nuvoton NPCM7xx SOCs.
+
+ The driver implements the BMC side of the KCS contorller, it
+ provides the access of KCS IO space for BMC side.
+
+ This support is also available as a module.  If so, the module
+ will be called kcs_bmc_npcm7xx.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 21e9e87..7a3baf3 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -24,3 +24,4 @@ obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 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
diff --git a/drivers/char/ipmi/kcs_bmc_npcm7xx.c 
b/drivers/char/ipmi/kcs_bmc_npcm7xx.c
new file mode 100644
index 000..7bc898c
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc_npcm7xx.c
@@ -0,0 +1,204 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, Nuvoton Corporation.
+ * Copyright (c) 2018, Intel Corporation.
+ */
+
+#define pr_fmt(fmt) "nuvoton-kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+#define DEVICE_NAME"npcm-kcs-bmc"
+#define KCS_CHANNEL_MAX3
+
+#define KCS1ST 0x0C
+#define KCS2ST 0x1E
+#define KCS3ST 0x30
+
+#define KCS1DO 0x0E
+#define KCS2DO 0x20
+#define KCS3DO 0x32
+
+#define KCS1DI 0x10
+#define KCS2DI 0x22
+#define KCS3DI 0x34
+
+#define KCS1CTL0x18
+#define KCS2CTL0x2A
+#define KCS3CTL0x3C
+#defineKCS_CTL_IBFIE   BIT(0)
+
+/*
+ * 7.2.4 Core

[PATCH i2c/slave-mqueue v1] i2c: slave-mqueue: add a slave backend to receive and queue messages

2018-03-16 Thread Haiyue Wang
Some protocols over I2C are designed for bi-directional transferring
messages by using I2C Master Write protocol. Like the MCTP (Management
Component Transport Protocol) and IPMB (Intelligent Platform Management
Bus), they both require that the userspace can receive messages from
I2C dirvers under slave mode.

This new slave mqueue backend is used to receive and queue messages, it
will exposes these messages to userspace by sysfs bin file.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 Documentation/i2c/slave-mqueue-backend.rst | 125 ++
 drivers/i2c/Kconfig|  13 ++
 drivers/i2c/Makefile   |   1 +
 drivers/i2c/i2c-slave-mqueue.c | 202 +
 4 files changed, 341 insertions(+)
 create mode 100644 Documentation/i2c/slave-mqueue-backend.rst
 create mode 100644 drivers/i2c/i2c-slave-mqueue.c

diff --git a/Documentation/i2c/slave-mqueue-backend.rst 
b/Documentation/i2c/slave-mqueue-backend.rst
new file mode 100644
index 000..69d6437
--- /dev/null
+++ b/Documentation/i2c/slave-mqueue-backend.rst
@@ -0,0 +1,125 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+Linux I2C slave message queue backend
+=
+
+:Author: Haiyue Wang <haiyue.w...@linux.intel.com>
+
+Some protocols over I2C/SMBus are designed for bi-directional transferring
+messages by using I2C Master Write protocol. This requires that both sides
+of the communication have slave addresses.
+
+Like MCTP (Management Component Transport Protocol) and IPMB (Intelligent
+Platform Management Bus), they both require that the userspace can receive
+messages from i2c dirvers under slave mode.
+
+This I2C slave mqueue (message queue) backend is used to receive and queue
+messages from the remote i2c intelligent device; and it will add the target
+slave address (with R/W# bit is always 0) into the message at the first byte,
+so that userspace can use this byte to dispatch the messages into different
+handling modules. Also, like IPMB, the address byte is in its message format,
+it needs it to do checksum.
+
+For messages are time related, so this backend will flush the oldest message
+to queue the newest one.
+
+Link
+
+`Intelligent Platform Management Bus
+Communications Protocol Specification
+<https://www.intel.com/content/dam/www/public/us/en/documents/product-briefs/ipmp-spec-v1.0.pdf>`_
+
+`Management Component Transport Protocol (MCTP)
+SMBus/I2C Transport Binding Specification
+<https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.1.0.pdf>`_
+
+How to use
+--
+For example, the I2C5 bus has slave address 0x10, bellowing command will create
+the related message queue interface:
+
+echo slave-mqueue 0x1010 > /sys/bus/i2c/devices/i2c-5/new_device
+
+Then you can dump the messages like this:
+
+hexdump -C /sys/bus/i2c/devices/5-1010/slave-mqueue
+
+Code Example
+
+*Note: call 'lseek' before 'read', this is a requirement from kernfs' design.*
+
+::
+
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+
+  int main(int argc, char *argv[])
+  {
+  int i, r;
+  struct pollfd pfd;
+  struct timespec ts;
+  unsigned char data[256];
+
+  pfd.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
+  if (pfd.fd < 0)
+  return -1;
+
+  pfd.events = POLLPRI;
+
+  while (1) {
+  r = poll(, 1, 5000);
+
+  if (r < 0)
+  break;
+
+  if (r == 0 || !(pfd.revents & POLLPRI))
+  continue;
+
+  lseek(pfd.fd, 0, SEEK_SET);
+  r = read(pfd.fd, data, sizeof(data));
+  if (r <= 0)
+  continue;
+
+  clock_gettime(CLOCK_MONOTONIC, );
+  printf("[%ld.%.9ld] :", ts.tv_sec, ts.tv_nsec);
+  for (i = 0; i < r; i++)
+  printf(" %02x", data[i]);
+  printf("\n");
+  }
+
+  close(pfd.fd);
+
+  return 0;
+  }
+
+Result
+--
+*./a.out "/sys/bus/i2c/devices/5-1010/slave-mqueue"*
+
+::
+
+  [10183.232500449] : 20 18 c8 2c 78 01 5b
+  [10183.479358348] : 20 18 c8 2c 78 01 5b
+  [10183.726556812] : 20 18 c8 2c 78 01 5b
+  [10183.972605863] : 20 18 c8 2c 78 01 5b
+  [10184.220124772] : 20 18 c8 2c 78 01 5b
+  [10184.467764166] : 20 18 c8 2c 78 01 5b
+  [10193.233421784] : 20 18 c8 2c 7c 01 57
+  [10193.480273460] : 20 18 c8 2c 7c 01 57
+  [10193.726788733] : 20 18 c8 2c 7c 01 57
+  [10193.972781945] : 20 18 c8 2c 7c 01 57
+  [10194.220487360] : 20 18 c8 2c 7c 01 57
+  [10194.468089259] : 20 18 c8 2c 7c 01 57
+  [10203.233433099] : 20 18 c8 2c 80 01 53
+  [10203.481058715] : 20 18 c8 2c 80 01 53
+  [

[PATCH i2c/slave-mqueue v1] i2c: slave-mqueue: add a slave backend to receive and queue messages

2018-03-16 Thread Haiyue Wang
Some protocols over I2C are designed for bi-directional transferring
messages by using I2C Master Write protocol. Like the MCTP (Management
Component Transport Protocol) and IPMB (Intelligent Platform Management
Bus), they both require that the userspace can receive messages from
I2C dirvers under slave mode.

This new slave mqueue backend is used to receive and queue messages, it
will exposes these messages to userspace by sysfs bin file.

Signed-off-by: Haiyue Wang 
---
 Documentation/i2c/slave-mqueue-backend.rst | 125 ++
 drivers/i2c/Kconfig|  13 ++
 drivers/i2c/Makefile   |   1 +
 drivers/i2c/i2c-slave-mqueue.c | 202 +
 4 files changed, 341 insertions(+)
 create mode 100644 Documentation/i2c/slave-mqueue-backend.rst
 create mode 100644 drivers/i2c/i2c-slave-mqueue.c

diff --git a/Documentation/i2c/slave-mqueue-backend.rst 
b/Documentation/i2c/slave-mqueue-backend.rst
new file mode 100644
index 000..69d6437
--- /dev/null
+++ b/Documentation/i2c/slave-mqueue-backend.rst
@@ -0,0 +1,125 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+Linux I2C slave message queue backend
+=
+
+:Author: Haiyue Wang 
+
+Some protocols over I2C/SMBus are designed for bi-directional transferring
+messages by using I2C Master Write protocol. This requires that both sides
+of the communication have slave addresses.
+
+Like MCTP (Management Component Transport Protocol) and IPMB (Intelligent
+Platform Management Bus), they both require that the userspace can receive
+messages from i2c dirvers under slave mode.
+
+This I2C slave mqueue (message queue) backend is used to receive and queue
+messages from the remote i2c intelligent device; and it will add the target
+slave address (with R/W# bit is always 0) into the message at the first byte,
+so that userspace can use this byte to dispatch the messages into different
+handling modules. Also, like IPMB, the address byte is in its message format,
+it needs it to do checksum.
+
+For messages are time related, so this backend will flush the oldest message
+to queue the newest one.
+
+Link
+
+`Intelligent Platform Management Bus
+Communications Protocol Specification
+<https://www.intel.com/content/dam/www/public/us/en/documents/product-briefs/ipmp-spec-v1.0.pdf>`_
+
+`Management Component Transport Protocol (MCTP)
+SMBus/I2C Transport Binding Specification
+<https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.1.0.pdf>`_
+
+How to use
+--
+For example, the I2C5 bus has slave address 0x10, bellowing command will create
+the related message queue interface:
+
+echo slave-mqueue 0x1010 > /sys/bus/i2c/devices/i2c-5/new_device
+
+Then you can dump the messages like this:
+
+hexdump -C /sys/bus/i2c/devices/5-1010/slave-mqueue
+
+Code Example
+
+*Note: call 'lseek' before 'read', this is a requirement from kernfs' design.*
+
+::
+
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+  #include 
+
+  int main(int argc, char *argv[])
+  {
+  int i, r;
+  struct pollfd pfd;
+  struct timespec ts;
+  unsigned char data[256];
+
+  pfd.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
+  if (pfd.fd < 0)
+  return -1;
+
+  pfd.events = POLLPRI;
+
+  while (1) {
+  r = poll(, 1, 5000);
+
+  if (r < 0)
+  break;
+
+  if (r == 0 || !(pfd.revents & POLLPRI))
+  continue;
+
+  lseek(pfd.fd, 0, SEEK_SET);
+  r = read(pfd.fd, data, sizeof(data));
+  if (r <= 0)
+  continue;
+
+  clock_gettime(CLOCK_MONOTONIC, );
+  printf("[%ld.%.9ld] :", ts.tv_sec, ts.tv_nsec);
+  for (i = 0; i < r; i++)
+  printf(" %02x", data[i]);
+  printf("\n");
+  }
+
+  close(pfd.fd);
+
+  return 0;
+  }
+
+Result
+--
+*./a.out "/sys/bus/i2c/devices/5-1010/slave-mqueue"*
+
+::
+
+  [10183.232500449] : 20 18 c8 2c 78 01 5b
+  [10183.479358348] : 20 18 c8 2c 78 01 5b
+  [10183.726556812] : 20 18 c8 2c 78 01 5b
+  [10183.972605863] : 20 18 c8 2c 78 01 5b
+  [10184.220124772] : 20 18 c8 2c 78 01 5b
+  [10184.467764166] : 20 18 c8 2c 78 01 5b
+  [10193.233421784] : 20 18 c8 2c 7c 01 57
+  [10193.480273460] : 20 18 c8 2c 7c 01 57
+  [10193.726788733] : 20 18 c8 2c 7c 01 57
+  [10193.972781945] : 20 18 c8 2c 7c 01 57
+  [10194.220487360] : 20 18 c8 2c 7c 01 57
+  [10194.468089259] : 20 18 c8 2c 7c 01 57
+  [10203.233433099] : 20 18 c8 2c 80 01 53
+  [10203.481058715] : 20 18 c8 2c 80 01 53
+  [10203.727610472] : 20 18 c8 2c 80 01 53
+  [10203.974044856] : 20 18 c8 2c 8

[PATCH ipmi/kcs_bmc v1] ipmi: kcs_bmc: optimize the data buffers allocation

2018-03-15 Thread Haiyue Wang
Allocate a continuous memory block for the three KCS data buffers with
related index assignment.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 drivers/char/ipmi/kcs_bmc.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index fbfc05e..dc19c0d 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -435,6 +435,7 @@ static const struct file_operations kcs_bmc_fops = {
 struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 channel)
 {
struct kcs_bmc *kcs_bmc;
+   void *buf;
 
kcs_bmc = devm_kzalloc(dev, sizeof(*kcs_bmc) + sizeof_priv, GFP_KERNEL);
if (!kcs_bmc)
@@ -448,11 +449,12 @@ struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int 
sizeof_priv, u32 channel)
mutex_init(_bmc->mutex);
init_waitqueue_head(_bmc->queue);
 
-   kcs_bmc->data_in = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
-   kcs_bmc->data_out = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
-   kcs_bmc->kbuffer = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
-   if (!kcs_bmc->data_in || !kcs_bmc->data_out || !kcs_bmc->kbuffer)
+   buf = devm_kmalloc_array(dev, 3, KCS_MSG_BUFSIZ, GFP_KERNEL);
+   if (!buf)
return NULL;
+   kcs_bmc->data_in  = buf;
+   kcs_bmc->data_out = buf + KCS_MSG_BUFSIZ;
+   kcs_bmc->kbuffer  = buf + KCS_MSG_BUFSIZ * 2;
 
kcs_bmc->miscdev.minor = MISC_DYNAMIC_MINOR;
kcs_bmc->miscdev.name = dev_name(dev);
-- 
2.7.4



[PATCH ipmi/kcs_bmc v1] ipmi: kcs_bmc: optimize the data buffers allocation

2018-03-15 Thread Haiyue Wang
Allocate a continuous memory block for the three KCS data buffers with
related index assignment.

Signed-off-by: Haiyue Wang 
---
 drivers/char/ipmi/kcs_bmc.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index fbfc05e..dc19c0d 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -435,6 +435,7 @@ static const struct file_operations kcs_bmc_fops = {
 struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 channel)
 {
struct kcs_bmc *kcs_bmc;
+   void *buf;
 
kcs_bmc = devm_kzalloc(dev, sizeof(*kcs_bmc) + sizeof_priv, GFP_KERNEL);
if (!kcs_bmc)
@@ -448,11 +449,12 @@ struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int 
sizeof_priv, u32 channel)
mutex_init(_bmc->mutex);
init_waitqueue_head(_bmc->queue);
 
-   kcs_bmc->data_in = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
-   kcs_bmc->data_out = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
-   kcs_bmc->kbuffer = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
-   if (!kcs_bmc->data_in || !kcs_bmc->data_out || !kcs_bmc->kbuffer)
+   buf = devm_kmalloc_array(dev, 3, KCS_MSG_BUFSIZ, GFP_KERNEL);
+   if (!buf)
return NULL;
+   kcs_bmc->data_in  = buf;
+   kcs_bmc->data_out = buf + KCS_MSG_BUFSIZ;
+   kcs_bmc->kbuffer  = buf + KCS_MSG_BUFSIZ * 2;
 
kcs_bmc->miscdev.minor = MISC_DYNAMIC_MINOR;
kcs_bmc->miscdev.name = dev_name(dev);
-- 
2.7.4



[PATCH dts/arm/aspeed-g5 v1] ARM: dts: aspeed-g5: Add IPMI KCS node

2018-03-06 Thread Haiyue Wang
The IPMI KCS device part of the LPC interface and is used for
communication with the host processor.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 arch/arm/boot/dts/aspeed-g5.dtsi | 43 +++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/aspeed-g5.dtsi b/arch/arm/boot/dts/aspeed-g5.dtsi
index 8eac57c..f443169 100644
--- a/arch/arm/boot/dts/aspeed-g5.dtsi
+++ b/arch/arm/boot/dts/aspeed-g5.dtsi
@@ -267,8 +267,40 @@
ranges = <0x0 0x1e789000 0x1000>;
 
lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2500-lpc-bmc";
+   compatible = "aspeed,ast2500-lpc-bmc", 
"simple-mfd", "syscon";
reg = <0x0 0x80>;
+   reg-io-width = <4>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x0 0x80>;
+
+   kcs1: kcs1@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <1>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
+   kcs2: kcs2@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <2>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
+   kcs3: kcs3@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <3>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
};
 
lpc_host: lpc-host@80 {
@@ -294,6 +326,15 @@
status = "disabled";
};
 
+   kcs4: kcs4@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0xa0>;
+   interrupts = <8>;
+   kcs_chan = <4>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
lhc: lhc@20 {
compatible = 
"aspeed,ast2500-lhc";
reg = <0x20 0x24 0x48 0x8>;
-- 
2.7.4



[PATCH dts/arm/aspeed-g5 v1] ARM: dts: aspeed-g5: Add IPMI KCS node

2018-03-06 Thread Haiyue Wang
The IPMI KCS device part of the LPC interface and is used for
communication with the host processor.

Signed-off-by: Haiyue Wang 
---
 arch/arm/boot/dts/aspeed-g5.dtsi | 43 +++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/aspeed-g5.dtsi b/arch/arm/boot/dts/aspeed-g5.dtsi
index 8eac57c..f443169 100644
--- a/arch/arm/boot/dts/aspeed-g5.dtsi
+++ b/arch/arm/boot/dts/aspeed-g5.dtsi
@@ -267,8 +267,40 @@
ranges = <0x0 0x1e789000 0x1000>;
 
lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2500-lpc-bmc";
+   compatible = "aspeed,ast2500-lpc-bmc", 
"simple-mfd", "syscon";
reg = <0x0 0x80>;
+   reg-io-width = <4>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x0 0x80>;
+
+   kcs1: kcs1@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <1>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
+   kcs2: kcs2@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <2>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
+   kcs3: kcs3@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <3>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
};
 
lpc_host: lpc-host@80 {
@@ -294,6 +326,15 @@
status = "disabled";
};
 
+   kcs4: kcs4@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0xa0>;
+   interrupts = <8>;
+   kcs_chan = <4>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
lhc: lhc@20 {
compatible = 
"aspeed,ast2500-lhc";
reg = <0x20 0x24 0x48 0x8>;
-- 
2.7.4



[PATCH dts/arm/aspeed-g5 v1] ARM: dts: aspeed-g5: Add IPMI KCS node

2018-03-03 Thread Haiyue Wang
The IPMI KCS device part of the LPC interface and is used for
communication with the host processor.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
Hi Joel & Andrew,

The kcs-bmc-aspeed module has been in:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/char/ipmi/kcs_bmc_aspeed.c
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt

I updated the device tree node about kcs-bmc, this is passed on my board.

And the patch is generated by rebasing on:
https://git.kernel.org/pub/scm/linux/kernel/git/joel/aspeed.git
Please help to review.

BR,
Haiyue
---
 arch/arm/boot/dts/aspeed-g5.dtsi | 43 +++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/aspeed-g5.dtsi b/arch/arm/boot/dts/aspeed-g5.dtsi
index 8eac57c..f443169 100644
--- a/arch/arm/boot/dts/aspeed-g5.dtsi
+++ b/arch/arm/boot/dts/aspeed-g5.dtsi
@@ -267,8 +267,40 @@
ranges = <0x0 0x1e789000 0x1000>;
 
lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2500-lpc-bmc";
+   compatible = "aspeed,ast2500-lpc-bmc", 
"simple-mfd", "syscon";
reg = <0x0 0x80>;
+   reg-io-width = <4>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x0 0x80>;
+
+   kcs1: kcs1@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <1>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
+   kcs2: kcs2@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <2>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
+   kcs3: kcs3@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <3>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
};
 
lpc_host: lpc-host@80 {
@@ -294,6 +326,15 @@
status = "disabled";
};
 
+   kcs4: kcs4@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0xa0>;
+   interrupts = <8>;
+   kcs_chan = <4>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
lhc: lhc@20 {
compatible = 
"aspeed,ast2500-lhc";
reg = <0x20 0x24 0x48 0x8>;
-- 
2.7.4



[PATCH dts/arm/aspeed-g5 v1] ARM: dts: aspeed-g5: Add IPMI KCS node

2018-03-03 Thread Haiyue Wang
The IPMI KCS device part of the LPC interface and is used for
communication with the host processor.

Signed-off-by: Haiyue Wang 
---
Hi Joel & Andrew,

The kcs-bmc-aspeed module has been in:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/char/ipmi/kcs_bmc_aspeed.c
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt

I updated the device tree node about kcs-bmc, this is passed on my board.

And the patch is generated by rebasing on:
https://git.kernel.org/pub/scm/linux/kernel/git/joel/aspeed.git
Please help to review.

BR,
Haiyue
---
 arch/arm/boot/dts/aspeed-g5.dtsi | 43 +++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/aspeed-g5.dtsi b/arch/arm/boot/dts/aspeed-g5.dtsi
index 8eac57c..f443169 100644
--- a/arch/arm/boot/dts/aspeed-g5.dtsi
+++ b/arch/arm/boot/dts/aspeed-g5.dtsi
@@ -267,8 +267,40 @@
ranges = <0x0 0x1e789000 0x1000>;
 
lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2500-lpc-bmc";
+   compatible = "aspeed,ast2500-lpc-bmc", 
"simple-mfd", "syscon";
reg = <0x0 0x80>;
+   reg-io-width = <4>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x0 0x80>;
+
+   kcs1: kcs1@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <1>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
+   kcs2: kcs2@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <2>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
+   kcs3: kcs3@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0x80>;
+   interrupts = <8>;
+   kcs_chan = <3>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
};
 
lpc_host: lpc-host@80 {
@@ -294,6 +326,15 @@
status = "disabled";
};
 
+   kcs4: kcs4@0 {
+   compatible = 
"aspeed,ast2500-kcs-bmc";
+   reg = <0x0 0xa0>;
+   interrupts = <8>;
+   kcs_chan = <4>;
+   kcs_addr = <0x0>;
+   status = "disabled";
+   };
+
lhc: lhc@20 {
compatible = 
"aspeed,ast2500-lhc";
reg = <0x20 0x24 0x48 0x8>;
-- 
2.7.4



[PATCH ipmi/kcs_bmc v6] ipmi: kcs_bmc: coding-style fixes and use new poll type

2018-02-26 Thread Haiyue Wang
Many for coding-style fixes, and update the poll API with the new
type '__poll_t', this is new commit from linux-4.16-rc1.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
v5 -> v6:
 - Add the missed change to EPOLLIN.

v4 -> v5:
 - Simplify the commit title and message.
 - Change the 'MODULE_DEVICE_TABLE' position.

v3 -> v4:
 - Correct the header file's macro defination end comment which is old
   file name, I forgot to change it after changing the file name.
 - Remove the space between the comment words and colon.

v2 -> v3:
 - Make the commit message be more understandable.

v1 -> v2:
 - Add 'SPDX-License-Identifier' style for header files modification.
---
 drivers/char/ipmi/kcs_bmc.c| 32 +---
 drivers/char/ipmi/kcs_bmc.h| 36 +++-
 drivers/char/ipmi/kcs_bmc_aspeed.c |  9 +
 include/uapi/linux/ipmi_bmc.h  |  8 +---
 4 files changed, 46 insertions(+), 39 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..fbfc05e 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "kcs-bmc: " fmt
 
@@ -242,14 +244,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,25 +264,25 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
spin_lock_irq(_bmc->lock);
if (kcs_bmc->data_in_avail)
-   mask |= POLLIN;
+   mask |= EPOLLIN;
spin_unlock_irq(_bmc->lock);
 
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +341,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +380,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +412,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index c19501d..eb9ea4c 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -1,31 +1,33 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #ifndef __KCS_BMC_H__
 #define __KCS_BMC_H__
 
 #include 
 
-/* Different phases of the KCS BMC module :
- *  KCS_PHASE_IDLE :
+/* Different phases of the KCS BMC module.
+ *  KCS_PHASE_IDLE:
  *BMC should not be expecting nor sending any data.
- *  KCS_PHASE_WRITE_START :
+ *  KCS_PHASE_

[PATCH ipmi/kcs_bmc v6] ipmi: kcs_bmc: coding-style fixes and use new poll type

2018-02-26 Thread Haiyue Wang
Many for coding-style fixes, and update the poll API with the new
type '__poll_t', this is new commit from linux-4.16-rc1.

Signed-off-by: Haiyue Wang 
---
v5 -> v6:
 - Add the missed change to EPOLLIN.

v4 -> v5:
 - Simplify the commit title and message.
 - Change the 'MODULE_DEVICE_TABLE' position.

v3 -> v4:
 - Correct the header file's macro defination end comment which is old
   file name, I forgot to change it after changing the file name.
 - Remove the space between the comment words and colon.

v2 -> v3:
 - Make the commit message be more understandable.

v1 -> v2:
 - Add 'SPDX-License-Identifier' style for header files modification.
---
 drivers/char/ipmi/kcs_bmc.c| 32 +---
 drivers/char/ipmi/kcs_bmc.h| 36 +++-
 drivers/char/ipmi/kcs_bmc_aspeed.c |  9 +
 include/uapi/linux/ipmi_bmc.h  |  8 +---
 4 files changed, 46 insertions(+), 39 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..fbfc05e 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "kcs-bmc: " fmt
 
@@ -242,14 +244,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,25 +264,25 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
spin_lock_irq(_bmc->lock);
if (kcs_bmc->data_in_avail)
-   mask |= POLLIN;
+   mask |= EPOLLIN;
spin_unlock_irq(_bmc->lock);
 
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +341,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +380,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +412,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index c19501d..eb9ea4c 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -1,31 +1,33 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #ifndef __KCS_BMC_H__
 #define __KCS_BMC_H__
 
 #include 
 
-/* Different phases of the KCS BMC module :
- *  KCS_PHASE_IDLE :
+/* Different phases of the KCS BMC module.
+ *  KCS_PHASE_IDLE:
  *BMC should not be expecting nor sending any data.
- *  KCS_PHASE_WRITE_START :
+ *  KCS_PHASE_WRITE_START:
  *BMC is 

[PATCH ipmi/kcs_bmc v5] ipmi: kcs_bmc: coding-style fixes and use new poll type

2018-02-26 Thread Haiyue Wang
Many for coding-style fixes, and update the poll API with the new
type '__poll_t', this is new commit from linux-4.16-rc1.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
v4 -> v5:
 - Simplify the commit title and message.
 - Change the 'MODULE_DEVICE_TABLE' position.

v3 -> v4:
 - Correct the header file's macro defination end comment which is old
   file name, I forgot to change it after changing the file name.
 - Remove the space between the comment words and colon.

v2 -> v3:
 - Make the commit message be more understandable.

v1 -> v2:
 - Add 'SPDX-License-Identifier' style for header files modification.
---
 drivers/char/ipmi/kcs_bmc.c| 30 --
 drivers/char/ipmi/kcs_bmc.h| 36 +++-
 drivers/char/ipmi/kcs_bmc_aspeed.c |  9 +
 include/uapi/linux/ipmi_bmc.h  |  8 +---
 4 files changed, 45 insertions(+), 38 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..1e51903 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "kcs-bmc: " fmt
 
@@ -242,14 +244,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,10 +264,10 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
@@ -277,10 +279,10 @@ static unsigned int kcs_bmc_poll(struct file *filp, 
poll_table *wait)
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +341,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +380,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +412,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index c19501d..eb9ea4c 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -1,31 +1,33 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #ifndef __KCS_BMC_H__
 #define __KCS_BMC_H__
 
 #include 
 
-/* Different phases of the KCS BMC module :
- *  KCS_PHASE_IDLE :
+/* Different phases of the KCS BMC module.
+ *  KCS_PHASE_IDLE:
  *BMC should not be expecting nor sending any data.
- *  KCS_PHASE_WRITE_START :
+ *  KCS_PHASE_WRITE_START:
  *BMC is receiving a WRITE_START command from system software.
- *  KCS_PHASE_WRITE_DATA :
+ *  KCS_PHASE_WRITE_DATA:
  

[PATCH ipmi/kcs_bmc v5] ipmi: kcs_bmc: coding-style fixes and use new poll type

2018-02-26 Thread Haiyue Wang
Many for coding-style fixes, and update the poll API with the new
type '__poll_t', this is new commit from linux-4.16-rc1.

Signed-off-by: Haiyue Wang 
---
v4 -> v5:
 - Simplify the commit title and message.
 - Change the 'MODULE_DEVICE_TABLE' position.

v3 -> v4:
 - Correct the header file's macro defination end comment which is old
   file name, I forgot to change it after changing the file name.
 - Remove the space between the comment words and colon.

v2 -> v3:
 - Make the commit message be more understandable.

v1 -> v2:
 - Add 'SPDX-License-Identifier' style for header files modification.
---
 drivers/char/ipmi/kcs_bmc.c| 30 --
 drivers/char/ipmi/kcs_bmc.h| 36 +++-
 drivers/char/ipmi/kcs_bmc_aspeed.c |  9 +
 include/uapi/linux/ipmi_bmc.h  |  8 +---
 4 files changed, 45 insertions(+), 38 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..1e51903 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "kcs-bmc: " fmt
 
@@ -242,14 +244,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,10 +264,10 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
@@ -277,10 +279,10 @@ static unsigned int kcs_bmc_poll(struct file *filp, 
poll_table *wait)
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +341,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +380,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +412,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index c19501d..eb9ea4c 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -1,31 +1,33 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #ifndef __KCS_BMC_H__
 #define __KCS_BMC_H__
 
 #include 
 
-/* Different phases of the KCS BMC module :
- *  KCS_PHASE_IDLE :
+/* Different phases of the KCS BMC module.
+ *  KCS_PHASE_IDLE:
  *BMC should not be expecting nor sending any data.
- *  KCS_PHASE_WRITE_START :
+ *  KCS_PHASE_WRITE_START:
  *BMC is receiving a WRITE_START command from system software.
- *  KCS_PHASE_WRITE_DATA :
+ *  KCS_PHASE_WRITE_DATA:
  *BMC is re

[PATCH arm/aspeed/ast2500 v3] eSPI: add ASPEED AST2500 eSPI driver to boot a host with PCH runs on eSPI

2018-02-23 Thread Haiyue Wang
When PCH works under eSPI mode, the PMC (Power Management Controller) in
PCH is waiting for SUS_ACK from BMC after it alerts SUS_WARN. It is in
dead loop if no SUS_ACK assert. This is the basic requirement for the BMC
works as eSPI slave.

Also for the host power on / off actions, from BMC side, the following VW
(Virtual Wire) messages are done in firmware:
1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
2. SUS_ACK
3. OOB_RESET_ACK
4. HOST_RESET_ACK

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
v2 -> v3:
 - Remove the unused header file reference.
 - Change some code lines sequence.

v1 -> v2:
 - Fix the checkpatch.pl warning in file espi-slave.rst
   Missing or malformed SPDX-License-Identifier tag in line 1
   #71: FILE: Documentation/misc-devices/espi-slave.rst:1:
 - Make the Kconfig desciption to be more accurate.
---
 .../devicetree/bindings/misc/aspeed,espi-slave.txt |  20 ++
 Documentation/misc-devices/espi-slave.rst  | 119 ++
 drivers/misc/Kconfig   |   8 +
 drivers/misc/Makefile  |   1 +
 drivers/misc/aspeed-espi-slave.c   | 261 +
 5 files changed, 409 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
 create mode 100644 Documentation/misc-devices/espi-slave.rst
 create mode 100644 drivers/misc/aspeed-espi-slave.c

diff --git a/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt 
b/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
new file mode 100644
index 000..4f5d47e
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
@@ -0,0 +1,20 @@
+ASPEED eSPI Slave Controller
+
+Required properties:
+ - compatible: must be one of:
+   - "aspeed,ast2500-espi-slave"
+
+ - reg: physical base address of the controller and length of memory mapped
+   region
+
+ - interrupts: interrupt generated by the controller
+
+Example:
+
+espi: espi@1e6ee000 {
+compatible = "aspeed,ast2500-espi-slave";
+reg = <0x1e6ee000 0x100>;
+interrupts = <23>;
+status = "disabled";
+};
+
diff --git a/Documentation/misc-devices/espi-slave.rst 
b/Documentation/misc-devices/espi-slave.rst
new file mode 100644
index 000..185acd7
--- /dev/null
+++ b/Documentation/misc-devices/espi-slave.rst
@@ -0,0 +1,119 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==
+eSPI Slave
+==
+
+:Author: Haiyue Wang <haiyue.w...@linux.intel.com>
+
+The PCH (**eSPI master**) provides the eSPI to support connection of a
+BMC (**eSPI slave**) to the platform.
+
+The LPC and eSPI interfaces are mutually exclusive. Both use the same
+pins, but on power-up, a HW strap determines if the eSPI or the LPC bus
+is operational. Once selected, it’s not possible to change to the other
+interface.
+
+``eSPI Channels and Supported Transactions``
+ +--+-+--++
+ | CH # | Channel | Posted Cycles| Non-Posted Cycles  |
+ +==+=+==++
+ |  0   | Peripheral  | Memory Write,| Memory Read,   |
+ |  | | Completions  | I/O Read/Write |
+ +--+-+--++
+ |  1   | Virtual Wire| Virtual Wire GET/PUT | N/A|
+ +--+-+--++
+ |  2   | Out-of-Band Message | SMBus Packet GET/PUT | N/A|
+ +--+-+--++
+ |  3   | Flash Access| N/A  | Flash Read, Write, |
+ |  | |  | Erase  |
+ +--+-+--++
+ |  N/A | General | Register Accesses| N/A|
+ +--+-+--++
+
+Virtual Wire Channel (Channel 1) Overview
+-
+
+The Virtual Wire channel uses a standard message format to communicate
+several types of signals between the components on the platform::
+
+ - Sideband and GPIO Pins: System events and other dedicated signals
+   between the PCH and eSPI slave. These signals are tunneled between the
+   two components over eSPI.
+
+ - Serial IRQ Interrupts: Interrupts are tunneled from the eSPI slave to
+   the PCH. Both edge and triggered interrupts are supported.
+
+When PCH runs on eSPI mode, from BMC side, the following VW messages are
+done in firmware::
+
+ 1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
+ 2. SUS_ACK
+ 3. OOB_RESET_ACK
+ 4. HOST_RESET_ACK
+
+``eSPI Virtual Wires (VW)``
+ +--+-+-

[PATCH arm/aspeed/ast2500 v3] eSPI: add ASPEED AST2500 eSPI driver to boot a host with PCH runs on eSPI

2018-02-23 Thread Haiyue Wang
When PCH works under eSPI mode, the PMC (Power Management Controller) in
PCH is waiting for SUS_ACK from BMC after it alerts SUS_WARN. It is in
dead loop if no SUS_ACK assert. This is the basic requirement for the BMC
works as eSPI slave.

Also for the host power on / off actions, from BMC side, the following VW
(Virtual Wire) messages are done in firmware:
1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
2. SUS_ACK
3. OOB_RESET_ACK
4. HOST_RESET_ACK

Signed-off-by: Haiyue Wang 
---
v2 -> v3:
 - Remove the unused header file reference.
 - Change some code lines sequence.

v1 -> v2:
 - Fix the checkpatch.pl warning in file espi-slave.rst
   Missing or malformed SPDX-License-Identifier tag in line 1
   #71: FILE: Documentation/misc-devices/espi-slave.rst:1:
 - Make the Kconfig desciption to be more accurate.
---
 .../devicetree/bindings/misc/aspeed,espi-slave.txt |  20 ++
 Documentation/misc-devices/espi-slave.rst  | 119 ++
 drivers/misc/Kconfig   |   8 +
 drivers/misc/Makefile  |   1 +
 drivers/misc/aspeed-espi-slave.c   | 261 +
 5 files changed, 409 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
 create mode 100644 Documentation/misc-devices/espi-slave.rst
 create mode 100644 drivers/misc/aspeed-espi-slave.c

diff --git a/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt 
b/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
new file mode 100644
index 000..4f5d47e
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
@@ -0,0 +1,20 @@
+ASPEED eSPI Slave Controller
+
+Required properties:
+ - compatible: must be one of:
+   - "aspeed,ast2500-espi-slave"
+
+ - reg: physical base address of the controller and length of memory mapped
+   region
+
+ - interrupts: interrupt generated by the controller
+
+Example:
+
+espi: espi@1e6ee000 {
+compatible = "aspeed,ast2500-espi-slave";
+reg = <0x1e6ee000 0x100>;
+interrupts = <23>;
+status = "disabled";
+};
+
diff --git a/Documentation/misc-devices/espi-slave.rst 
b/Documentation/misc-devices/espi-slave.rst
new file mode 100644
index 000..185acd7
--- /dev/null
+++ b/Documentation/misc-devices/espi-slave.rst
@@ -0,0 +1,119 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==
+eSPI Slave
+==
+
+:Author: Haiyue Wang 
+
+The PCH (**eSPI master**) provides the eSPI to support connection of a
+BMC (**eSPI slave**) to the platform.
+
+The LPC and eSPI interfaces are mutually exclusive. Both use the same
+pins, but on power-up, a HW strap determines if the eSPI or the LPC bus
+is operational. Once selected, it’s not possible to change to the other
+interface.
+
+``eSPI Channels and Supported Transactions``
+ +--+-+--++
+ | CH # | Channel | Posted Cycles| Non-Posted Cycles  |
+ +==+=+==++
+ |  0   | Peripheral  | Memory Write,| Memory Read,   |
+ |  | | Completions  | I/O Read/Write |
+ +--+-+--++
+ |  1   | Virtual Wire| Virtual Wire GET/PUT | N/A|
+ +--+-+--++
+ |  2   | Out-of-Band Message | SMBus Packet GET/PUT | N/A|
+ +--+-+--++
+ |  3   | Flash Access| N/A  | Flash Read, Write, |
+ |  | |  | Erase  |
+ +--+-+--++
+ |  N/A | General | Register Accesses| N/A|
+ +--+-+--++
+
+Virtual Wire Channel (Channel 1) Overview
+-
+
+The Virtual Wire channel uses a standard message format to communicate
+several types of signals between the components on the platform::
+
+ - Sideband and GPIO Pins: System events and other dedicated signals
+   between the PCH and eSPI slave. These signals are tunneled between the
+   two components over eSPI.
+
+ - Serial IRQ Interrupts: Interrupts are tunneled from the eSPI slave to
+   the PCH. Both edge and triggered interrupts are supported.
+
+When PCH runs on eSPI mode, from BMC side, the following VW messages are
+done in firmware::
+
+ 1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
+ 2. SUS_ACK
+ 3. OOB_RESET_ACK
+ 4. HOST_RESET_ACK
+
+``eSPI Virtual Wires (VW)``
+ +--+-+---+
+ |Virtual Wire  |PCH Pin  |Comments

[PATCH arm/aspeed/ast2500 v2] eSPI: add ASPEED AST2500 eSPI driver to boot a host with PCH runs on eSPI

2018-02-22 Thread Haiyue Wang
When PCH works under eSPI mode, the PMC (Power Management Controller) in
PCH is waiting for SUS_ACK from BMC after it alerts SUS_WARN. It is in
dead loop if no SUS_ACK assert. This is the basic requirement for the BMC
works as eSPI slave.

Also for the host power on / off actions, from BMC side, the following VW
(Virtual Wire) messages are done in firmware:
1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
2. SUS_ACK
3. OOB_RESET_ACK
4. HOST_RESET_ACK

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
v1 -> v2:
 - Fix the checkpatch.pl warning in file espi-slave.rst
   Missing or malformed SPDX-License-Identifier tag in line 1
   #71: FILE: Documentation/misc-devices/espi-slave.rst:1:
 - Make the Kconfig desciption to be more accurate.
---
 .../devicetree/bindings/misc/aspeed,espi-slave.txt |  20 ++
 Documentation/misc-devices/espi-slave.rst  | 119 ++
 drivers/misc/Kconfig   |   7 +
 drivers/misc/Makefile  |   1 +
 drivers/misc/aspeed-espi-slave.c   | 263 +
 5 files changed, 410 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
 create mode 100644 Documentation/misc-devices/espi-slave.rst
 create mode 100644 drivers/misc/aspeed-espi-slave.c

diff --git a/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt 
b/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
new file mode 100644
index 000..35da26f
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
@@ -0,0 +1,20 @@
+Aspeed eSPI Slave Controller
+
+Required properties:
+ - compatible: must be one of:
+   - "aspeed,ast2500-espi-slave"
+
+ - reg: physical base address of the controller and length of memory mapped
+   region
+
+ - interrupts: interrupt generated by the controller
+
+Example:
+
+espi: espi@1e6ee000 {
+compatible = "aspeed,ast2500-espi-slave";
+reg = <0x1e6ee000 0x100>;
+interrupts = <23>;
+status = "disabled";
+};
+
diff --git a/Documentation/misc-devices/espi-slave.rst 
b/Documentation/misc-devices/espi-slave.rst
new file mode 100644
index 000..185acd7
--- /dev/null
+++ b/Documentation/misc-devices/espi-slave.rst
@@ -0,0 +1,119 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+======
+eSPI Slave
+==
+
+:Author: Haiyue Wang <haiyue.w...@linux.intel.com>
+
+The PCH (**eSPI master**) provides the eSPI to support connection of a
+BMC (**eSPI slave**) to the platform.
+
+The LPC and eSPI interfaces are mutually exclusive. Both use the same
+pins, but on power-up, a HW strap determines if the eSPI or the LPC bus
+is operational. Once selected, it’s not possible to change to the other
+interface.
+
+``eSPI Channels and Supported Transactions``
+ +--+-+--++
+ | CH # | Channel | Posted Cycles| Non-Posted Cycles  |
+ +==+=+==++
+ |  0   | Peripheral  | Memory Write,| Memory Read,   |
+ |  | | Completions  | I/O Read/Write |
+ +--+-+--++
+ |  1   | Virtual Wire| Virtual Wire GET/PUT | N/A|
+ +--+-+--++
+ |  2   | Out-of-Band Message | SMBus Packet GET/PUT | N/A|
+ +--+-+--++
+ |  3   | Flash Access| N/A  | Flash Read, Write, |
+ |  | |  | Erase  |
+ +--+-+--++
+ |  N/A | General | Register Accesses| N/A|
+ +--+-+--++
+
+Virtual Wire Channel (Channel 1) Overview
+-
+
+The Virtual Wire channel uses a standard message format to communicate
+several types of signals between the components on the platform::
+
+ - Sideband and GPIO Pins: System events and other dedicated signals
+   between the PCH and eSPI slave. These signals are tunneled between the
+   two components over eSPI.
+
+ - Serial IRQ Interrupts: Interrupts are tunneled from the eSPI slave to
+   the PCH. Both edge and triggered interrupts are supported.
+
+When PCH runs on eSPI mode, from BMC side, the following VW messages are
+done in firmware::
+
+ 1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
+ 2. SUS_ACK
+ 3. OOB_RESET_ACK
+ 4. HOST_RESET_ACK
+
+``eSPI Virtual Wires (VW)``
+ +--+-+---+
+ |Virtual Wire  |PCH Pin  |Comments   

[PATCH arm/aspeed/ast2500 v2] eSPI: add ASPEED AST2500 eSPI driver to boot a host with PCH runs on eSPI

2018-02-22 Thread Haiyue Wang
When PCH works under eSPI mode, the PMC (Power Management Controller) in
PCH is waiting for SUS_ACK from BMC after it alerts SUS_WARN. It is in
dead loop if no SUS_ACK assert. This is the basic requirement for the BMC
works as eSPI slave.

Also for the host power on / off actions, from BMC side, the following VW
(Virtual Wire) messages are done in firmware:
1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
2. SUS_ACK
3. OOB_RESET_ACK
4. HOST_RESET_ACK

Signed-off-by: Haiyue Wang 
---
v1 -> v2:
 - Fix the checkpatch.pl warning in file espi-slave.rst
   Missing or malformed SPDX-License-Identifier tag in line 1
   #71: FILE: Documentation/misc-devices/espi-slave.rst:1:
 - Make the Kconfig desciption to be more accurate.
---
 .../devicetree/bindings/misc/aspeed,espi-slave.txt |  20 ++
 Documentation/misc-devices/espi-slave.rst  | 119 ++
 drivers/misc/Kconfig   |   7 +
 drivers/misc/Makefile  |   1 +
 drivers/misc/aspeed-espi-slave.c   | 263 +
 5 files changed, 410 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
 create mode 100644 Documentation/misc-devices/espi-slave.rst
 create mode 100644 drivers/misc/aspeed-espi-slave.c

diff --git a/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt 
b/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
new file mode 100644
index 000..35da26f
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/aspeed,espi-slave.txt
@@ -0,0 +1,20 @@
+Aspeed eSPI Slave Controller
+
+Required properties:
+ - compatible: must be one of:
+   - "aspeed,ast2500-espi-slave"
+
+ - reg: physical base address of the controller and length of memory mapped
+   region
+
+ - interrupts: interrupt generated by the controller
+
+Example:
+
+espi: espi@1e6ee000 {
+compatible = "aspeed,ast2500-espi-slave";
+reg = <0x1e6ee000 0x100>;
+interrupts = <23>;
+status = "disabled";
+};
+
diff --git a/Documentation/misc-devices/espi-slave.rst 
b/Documentation/misc-devices/espi-slave.rst
new file mode 100644
index 000..185acd7
--- /dev/null
+++ b/Documentation/misc-devices/espi-slave.rst
@@ -0,0 +1,119 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+======
+eSPI Slave
+==
+
+:Author: Haiyue Wang 
+
+The PCH (**eSPI master**) provides the eSPI to support connection of a
+BMC (**eSPI slave**) to the platform.
+
+The LPC and eSPI interfaces are mutually exclusive. Both use the same
+pins, but on power-up, a HW strap determines if the eSPI or the LPC bus
+is operational. Once selected, it’s not possible to change to the other
+interface.
+
+``eSPI Channels and Supported Transactions``
+ +--+-+--++
+ | CH # | Channel | Posted Cycles| Non-Posted Cycles  |
+ +==+=+==++
+ |  0   | Peripheral  | Memory Write,| Memory Read,   |
+ |  | | Completions  | I/O Read/Write |
+ +--+-+--++
+ |  1   | Virtual Wire| Virtual Wire GET/PUT | N/A|
+ +--+-+--++
+ |  2   | Out-of-Band Message | SMBus Packet GET/PUT | N/A|
+ +--+-+--++
+ |  3   | Flash Access| N/A  | Flash Read, Write, |
+ |  | |  | Erase  |
+ +--+-+--++
+ |  N/A | General | Register Accesses| N/A|
+ +--+-+--++
+
+Virtual Wire Channel (Channel 1) Overview
+-
+
+The Virtual Wire channel uses a standard message format to communicate
+several types of signals between the components on the platform::
+
+ - Sideband and GPIO Pins: System events and other dedicated signals
+   between the PCH and eSPI slave. These signals are tunneled between the
+   two components over eSPI.
+
+ - Serial IRQ Interrupts: Interrupts are tunneled from the eSPI slave to
+   the PCH. Both edge and triggered interrupts are supported.
+
+When PCH runs on eSPI mode, from BMC side, the following VW messages are
+done in firmware::
+
+ 1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
+ 2. SUS_ACK
+ 3. OOB_RESET_ACK
+ 4. HOST_RESET_ACK
+
+``eSPI Virtual Wires (VW)``
+ +--+-+---+
+ |Virtual Wire  |PCH Pin  |Comments   

[PATCH ipmi/kcs_bmc v4] ipmi: kcs_bmc: make the code be more clean

2018-02-21 Thread Haiyue Wang
Modify the file read and write operation API's parameter declaration to
meet the name convention.

Rename the helper function by following the to_() name style.

Update the poll API with the new type '__poll_t', this is new commit from
linux-4.16-rc1.

Correct the header file's comment style for 'SPDX-License-Identifier'.

Correct the header file's macro defination end comment which is old file
name.

Remove the space between the comment words and colon by referring other
modules.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
v3 -> v4:
 - Correct the header file's macro defination end comment which is old
   file name, I forgot to change it after changing the file name.
 - Remove the space between the comment words and colon by referring
   other modules.

v2 -> v3:
 - Make the commit message be more understandable.

v1 -> v2:
 - Add 'SPDX-License-Identifier' style for header files modification.
---
 drivers/char/ipmi/kcs_bmc.c| 32 +---
 drivers/char/ipmi/kcs_bmc.h| 36 +++-
 drivers/char/ipmi/kcs_bmc_aspeed.c |  4 +++-
 include/uapi/linux/ipmi_bmc.h  |  8 +---
 4 files changed, 44 insertions(+), 36 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..fbfc05e 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "kcs-bmc: " fmt
 
@@ -242,14 +244,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,25 +264,25 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
spin_lock_irq(_bmc->lock);
if (kcs_bmc->data_in_avail)
-   mask |= POLLIN;
+   mask |= EPOLLIN;
spin_unlock_irq(_bmc->lock);
 
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +341,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +380,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +412,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index c19501d..eb9ea4c 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -1,31 +1,33 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #ifndef __KCS_BMC_H__
 #define __KCS_BMC_H__
 
 #i

[PATCH ipmi/kcs_bmc v4] ipmi: kcs_bmc: make the code be more clean

2018-02-21 Thread Haiyue Wang
Modify the file read and write operation API's parameter declaration to
meet the name convention.

Rename the helper function by following the to_() name style.

Update the poll API with the new type '__poll_t', this is new commit from
linux-4.16-rc1.

Correct the header file's comment style for 'SPDX-License-Identifier'.

Correct the header file's macro defination end comment which is old file
name.

Remove the space between the comment words and colon by referring other
modules.

Signed-off-by: Haiyue Wang 
---
v3 -> v4:
 - Correct the header file's macro defination end comment which is old
   file name, I forgot to change it after changing the file name.
 - Remove the space between the comment words and colon by referring
   other modules.

v2 -> v3:
 - Make the commit message be more understandable.

v1 -> v2:
 - Add 'SPDX-License-Identifier' style for header files modification.
---
 drivers/char/ipmi/kcs_bmc.c| 32 +---
 drivers/char/ipmi/kcs_bmc.h| 36 +++-
 drivers/char/ipmi/kcs_bmc_aspeed.c |  4 +++-
 include/uapi/linux/ipmi_bmc.h  |  8 +---
 4 files changed, 44 insertions(+), 36 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..fbfc05e 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "kcs-bmc: " fmt
 
@@ -242,14 +244,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,25 +264,25 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
spin_lock_irq(_bmc->lock);
if (kcs_bmc->data_in_avail)
-   mask |= POLLIN;
+   mask |= EPOLLIN;
spin_unlock_irq(_bmc->lock);
 
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +341,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +380,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +412,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index c19501d..eb9ea4c 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -1,31 +1,33 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #ifndef __KCS_BMC_H__
 #define __KCS_BMC_H__
 
 #include 
 
-/* Different phases of the KCS BMC modul

[PATCH ipmi/kcs_bmc v3] ipmi: kcs_bmc: make the code be more clean

2018-02-21 Thread Haiyue Wang
Modify the file read and write operation API's parameter declaration to
meet the name convention.

Rename the helper function by following the to_() name style.

Update the poll API with the new type '__poll_t', this is new commit from
linux-4.16-rc1.

Correct the header files comment style for 'SPDX-License-Identifier'.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>

---
v2 -> v3:
 - Make the commit message be more understandable.

v1 -> v2:
 - Add 'SPDX-License-Identifier' style for header files modification.
---
 drivers/char/ipmi/kcs_bmc.c| 32 +---
 drivers/char/ipmi/kcs_bmc.h|  6 --
 drivers/char/ipmi/kcs_bmc_aspeed.c |  4 +++-
 include/uapi/linux/ipmi_bmc.h  |  6 --
 4 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..fbfc05e 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "kcs-bmc: " fmt
 
@@ -242,14 +244,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,25 +264,25 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
spin_lock_irq(_bmc->lock);
if (kcs_bmc->data_in_avail)
-   mask |= POLLIN;
+   mask |= EPOLLIN;
spin_unlock_irq(_bmc->lock);
 
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +341,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +380,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +412,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index c19501d..69d9a70 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -1,5 +1,7 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #ifndef __KCS_BMC_H__
 #define __KCS_BMC_H__
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 0c4d1a3..dba6075 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "aspeed-kcs-bmc: " fmt
 
diff --git a/include/uapi/linux/ipmi_b

[PATCH ipmi/kcs_bmc v3] ipmi: kcs_bmc: make the code be more clean

2018-02-21 Thread Haiyue Wang
Modify the file read and write operation API's parameter declaration to
meet the name convention.

Rename the helper function by following the to_() name style.

Update the poll API with the new type '__poll_t', this is new commit from
linux-4.16-rc1.

Correct the header files comment style for 'SPDX-License-Identifier'.

Signed-off-by: Haiyue Wang 

---
v2 -> v3:
 - Make the commit message be more understandable.

v1 -> v2:
 - Add 'SPDX-License-Identifier' style for header files modification.
---
 drivers/char/ipmi/kcs_bmc.c| 32 +---
 drivers/char/ipmi/kcs_bmc.h|  6 --
 drivers/char/ipmi/kcs_bmc_aspeed.c |  4 +++-
 include/uapi/linux/ipmi_bmc.h  |  6 --
 4 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..fbfc05e 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "kcs-bmc: " fmt
 
@@ -242,14 +244,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,25 +264,25 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
spin_lock_irq(_bmc->lock);
if (kcs_bmc->data_in_avail)
-   mask |= POLLIN;
+   mask |= EPOLLIN;
spin_unlock_irq(_bmc->lock);
 
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +341,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +380,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +412,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index c19501d..69d9a70 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -1,5 +1,7 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #ifndef __KCS_BMC_H__
 #define __KCS_BMC_H__
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 0c4d1a3..dba6075 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "aspeed-kcs-bmc: " fmt
 
diff --git a/include/uapi/linux/ipmi_bmc.h b/include/uapi/linux/ipmi_bmc.h
i

[PATCH ipmi/kcs_bmc v2] ipmi: kcs_bmc: make the code be more clean

2018-02-19 Thread Haiyue Wang
---
v1 -> v2:

Add 'SPDX-License-Identifier' style for header files modification.
---

1. Add the missed key word '__user' for read / write.
2. Remove the prefix 'file' of 'file_to_kcs_bmc', no need this
duplicated word as its parameter has 'struct file *filp'.
3. Change the 'unsigned int' to '__poll_t' to meet the new 'poll'
definition.
4. Correct the 'SPDX-License-Identifier' style for header files.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 drivers/char/ipmi/kcs_bmc.c| 32 +---
 drivers/char/ipmi/kcs_bmc.h|  6 --
 drivers/char/ipmi/kcs_bmc_aspeed.c |  4 +++-
 include/uapi/linux/ipmi_bmc.h  |  6 --
 4 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..fbfc05e 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "kcs-bmc: " fmt
 
@@ -242,14 +244,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,25 +264,25 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
spin_lock_irq(_bmc->lock);
if (kcs_bmc->data_in_avail)
-   mask |= POLLIN;
+   mask |= EPOLLIN;
spin_unlock_irq(_bmc->lock);
 
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +341,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +380,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +412,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index c19501d..69d9a70 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -1,5 +1,7 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #ifndef __KCS_BMC_H__
 #define __KCS_BMC_H__
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 0c4d1a3..dba6075 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "aspeed-kcs-bmc: " fmt
 
diff --git a/include/uapi/linux/ipmi_bmc.h b/include/uapi/linux/ipmi_bmc.h
index 2f9f97e..d3efacd 100644
--- 

[PATCH ipmi/kcs_bmc v2] ipmi: kcs_bmc: make the code be more clean

2018-02-19 Thread Haiyue Wang
---
v1 -> v2:

Add 'SPDX-License-Identifier' style for header files modification.
---

1. Add the missed key word '__user' for read / write.
2. Remove the prefix 'file' of 'file_to_kcs_bmc', no need this
duplicated word as its parameter has 'struct file *filp'.
3. Change the 'unsigned int' to '__poll_t' to meet the new 'poll'
definition.
4. Correct the 'SPDX-License-Identifier' style for header files.

Signed-off-by: Haiyue Wang 
---
 drivers/char/ipmi/kcs_bmc.c| 32 +---
 drivers/char/ipmi/kcs_bmc.h|  6 --
 drivers/char/ipmi/kcs_bmc_aspeed.c |  4 +++-
 include/uapi/linux/ipmi_bmc.h  |  6 --
 4 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..fbfc05e 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "kcs-bmc: " fmt
 
@@ -242,14 +244,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,25 +264,25 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
spin_lock_irq(_bmc->lock);
if (kcs_bmc->data_in_avail)
-   mask |= POLLIN;
+   mask |= EPOLLIN;
spin_unlock_irq(_bmc->lock);
 
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +341,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +380,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +412,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index c19501d..69d9a70 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -1,5 +1,7 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #ifndef __KCS_BMC_H__
 #define __KCS_BMC_H__
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 0c4d1a3..dba6075 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2015-2018, Intel Corporation.
+/*
+ * Copyright (c) 2015-2018, Intel Corporation.
+ */
 
 #define pr_fmt(fmt) "aspeed-kcs-bmc: " fmt
 
diff --git a/include/uapi/linux/ipmi_bmc.h b/include/uapi/linux/ipmi_bmc.h
index 2f9f97e..d3efacd 100644
--- a/include/uapi/linux/ipmi_bmc.

[PATCH ipmi/kcs_bmc v1] ipmi: kcs_bmc: make the code be more clean

2018-02-19 Thread Haiyue Wang
Hi Corey,

I've changed some code style to meet with the whole Linux style. Please help
to review.

BR,
Haiyue

---

1. Add the missed key word '__user' for read / write.
2. Remove the prefix 'file' of 'file_to_kcs_bmc', no need this
duplicated word as its parameter has 'struct file *filp'.
3. Change the 'unsigned int' to '__poll_t' to meet the new 'poll'
definition.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 drivers/char/ipmi/kcs_bmc.c | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..2fe55b0 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -242,14 +242,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,10 +262,10 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
@@ -277,10 +277,10 @@ static unsigned int kcs_bmc_poll(struct file *filp, 
poll_table *wait)
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +339,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +378,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +410,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
-- 
2.7.4



[PATCH ipmi/kcs_bmc v1] ipmi: kcs_bmc: make the code be more clean

2018-02-19 Thread Haiyue Wang
Hi Corey,

I've changed some code style to meet with the whole Linux style. Please help
to review.

BR,
Haiyue

---

1. Add the missed key word '__user' for read / write.
2. Remove the prefix 'file' of 'file_to_kcs_bmc', no need this
duplicated word as its parameter has 'struct file *filp'.
3. Change the 'unsigned int' to '__poll_t' to meet the new 'poll'
definition.

Signed-off-by: Haiyue Wang 
---
 drivers/char/ipmi/kcs_bmc.c | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 6476bfb..2fe55b0 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -242,14 +242,14 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-static inline struct kcs_bmc *file_to_kcs_bmc(struct file *filp)
+static inline struct kcs_bmc *to_kcs_bmc(struct file *filp)
 {
return container_of(filp->private_data, struct kcs_bmc, miscdev);
 }
 
 static int kcs_bmc_open(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
int ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -262,10 +262,10 @@ static int kcs_bmc_open(struct inode *inode, struct file 
*filp)
return ret;
 }
 
-static unsigned int kcs_bmc_poll(struct file *filp, poll_table *wait)
+static __poll_t kcs_bmc_poll(struct file *filp, poll_table *wait)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
-   unsigned int mask = 0;
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
+   __poll_t mask = 0;
 
poll_wait(filp, _bmc->queue, wait);
 
@@ -277,10 +277,10 @@ static unsigned int kcs_bmc_poll(struct file *filp, 
poll_table *wait)
return mask;
 }
 
-static ssize_t kcs_bmc_read(struct file *filp, char *buf,
-   size_t count, loff_t *offset)
+static ssize_t kcs_bmc_read(struct file *filp, char __user *buf,
+   size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
bool data_avail;
size_t data_len;
ssize_t ret;
@@ -339,10 +339,10 @@ static ssize_t kcs_bmc_read(struct file *filp, char *buf,
return ret;
 }
 
-static ssize_t kcs_bmc_write(struct file *filp, const char *buf,
-size_t count, loff_t *offset)
+static ssize_t kcs_bmc_write(struct file *filp, const char __user *buf,
+size_t count, loff_t *ppos)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
ssize_t ret;
 
/* a minimum response size '3' : netfn + cmd + ccode */
@@ -378,7 +378,7 @@ static ssize_t kcs_bmc_write(struct file *filp, const char 
*buf,
 static long kcs_bmc_ioctl(struct file *filp, unsigned int cmd,
  unsigned long arg)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
long ret = 0;
 
spin_lock_irq(_bmc->lock);
@@ -410,7 +410,7 @@ static long kcs_bmc_ioctl(struct file *filp, unsigned int 
cmd,
 
 static int kcs_bmc_release(struct inode *inode, struct file *filp)
 {
-   struct kcs_bmc *kcs_bmc = file_to_kcs_bmc(filp);
+   struct kcs_bmc *kcs_bmc = to_kcs_bmc(filp);
 
spin_lock_irq(_bmc->lock);
kcs_bmc->running = 0;
-- 
2.7.4



[PATCH arm/aspeed/ast2500 v5 2/2] ipmi: add an Aspeed KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a server host and its BMC (BaseBoard Management
Controllers).

This driver exposes the KCS interface on ASpeed SOCs (AST2400 and AST2500)
as a character device. Such SOCs are commonly used as BMCs and this driver
implements the BMC side of the KCS interface.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 .../devicetree/bindings/ipmi/aspeed-kcs-bmc.txt|  26 ++
 drivers/char/ipmi/Kconfig  |  12 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs_bmc_aspeed.c | 319 +
 4 files changed, 358 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs_bmc_aspeed.c

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
new file mode 100644
index 000..613c34c
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
@@ -0,0 +1,26 @@
+* Aspeed KCS (Keyboard Controller Style) IPMI interface
+
+The Aspeed SOCs (AST2400 and AST2500) are commonly used as BMCs
+(Baseboard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"aspeed,ast2400-kcs-bmc"
+"aspeed,ast2500-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The LPC channel number in the controller
+- kcs_addr : The host CPU IO map address
+
+
+Example:
+
+kcs3: kcs3@0 {
+compatible = "aspeed,ast2500-kcs-bmc";
+reg = <0x0 0x80>;
+interrupts = <8>;
+kcs_chan = <3>;
+kcs_addr = <0xCA2>;
+status = "okay";
+};
+
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index aa9bcb1..f72fe56 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,6 +104,18 @@ config IPMI_KCS_BMC
  Management Controllers) side for handling the IPMI request from
  host system software.
 
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+   select IPMI_KCS_BMC
+   select REGMAP_MMIO
+   tristate "Aspeed KCS IPMI BMC driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500).
+
+ The driver implements the BMC side of the KCS contorller, it
+ provides the access of KCS IO space for BMC side.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 2abccb3..21e9e87 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -23,3 +23,4 @@ obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
new file mode 100644
index 000..0c4d1a3
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -0,0 +1,319 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "aspeed-kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+
+#define DEVICE_NAME "ast-kcs-bmc"
+
+#define KCS_CHANNEL_MAX 4
+
+/* mapped to lpc-bmc@0 IO space */
+#define LPC_HICR00x000
+#define LPC_HICR0_LPC3E  BIT(7)
+#define LPC_HICR0_LPC2E  BIT(6)
+#define LPC_HICR0_LPC1E  BIT(5)
+#define LPC_HICR20x008
+#define LPC_HICR2_IBFIF3 BIT(3)
+#define LPC_HICR2_IBFIF2 BIT(2)
+#define LPC_HICR2_IBFIF1 BIT(1)
+#define LPC_HICR40x010
+#define LPC_HICR4_LADR12AS   BIT(7)
+#define LPC_HICR4_KCSENBLBIT(2)
+#define LPC_LADR3H   0x014
+#define LPC_LADR3L   0x018
+#define LPC_LADR12H  0x01C
+#define LPC_LADR12L  0x020
+#define LPC_IDR1 0x024
+#define LPC_IDR2 0x028
+#define LPC_IDR3 0x02C
+#define LPC_ODR1 0x030
+#define LPC_ODR2 0x034
+#define LPC_ODR3 0x038
+#define LPC_STR1 0x03C
+#define LPC_STR2 0x040
+#define LPC_STR3 0x044
+
+/* mapped to lpc-host@80 IO space */
+#define LPC_HICRB0x080
+#define LPC_HICRB_IBFIF4 BIT(1)
+#define

[PATCH arm/aspeed/ast2500 v5 2/2] ipmi: add an Aspeed KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a server host and its BMC (BaseBoard Management
Controllers).

This driver exposes the KCS interface on ASpeed SOCs (AST2400 and AST2500)
as a character device. Such SOCs are commonly used as BMCs and this driver
implements the BMC side of the KCS interface.

Signed-off-by: Haiyue Wang 
---
 .../devicetree/bindings/ipmi/aspeed-kcs-bmc.txt|  26 ++
 drivers/char/ipmi/Kconfig  |  12 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs_bmc_aspeed.c | 319 +
 4 files changed, 358 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs_bmc_aspeed.c

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
new file mode 100644
index 000..613c34c
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
@@ -0,0 +1,26 @@
+* Aspeed KCS (Keyboard Controller Style) IPMI interface
+
+The Aspeed SOCs (AST2400 and AST2500) are commonly used as BMCs
+(Baseboard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"aspeed,ast2400-kcs-bmc"
+"aspeed,ast2500-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The LPC channel number in the controller
+- kcs_addr : The host CPU IO map address
+
+
+Example:
+
+kcs3: kcs3@0 {
+compatible = "aspeed,ast2500-kcs-bmc";
+reg = <0x0 0x80>;
+interrupts = <8>;
+kcs_chan = <3>;
+kcs_addr = <0xCA2>;
+status = "okay";
+};
+
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index aa9bcb1..f72fe56 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,6 +104,18 @@ config IPMI_KCS_BMC
  Management Controllers) side for handling the IPMI request from
  host system software.
 
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+   select IPMI_KCS_BMC
+   select REGMAP_MMIO
+   tristate "Aspeed KCS IPMI BMC driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500).
+
+ The driver implements the BMC side of the KCS contorller, it
+ provides the access of KCS IO space for BMC side.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 2abccb3..21e9e87 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -23,3 +23,4 @@ obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
new file mode 100644
index 000..0c4d1a3
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -0,0 +1,319 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "aspeed-kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+
+#define DEVICE_NAME "ast-kcs-bmc"
+
+#define KCS_CHANNEL_MAX 4
+
+/* mapped to lpc-bmc@0 IO space */
+#define LPC_HICR00x000
+#define LPC_HICR0_LPC3E  BIT(7)
+#define LPC_HICR0_LPC2E  BIT(6)
+#define LPC_HICR0_LPC1E  BIT(5)
+#define LPC_HICR20x008
+#define LPC_HICR2_IBFIF3 BIT(3)
+#define LPC_HICR2_IBFIF2 BIT(2)
+#define LPC_HICR2_IBFIF1 BIT(1)
+#define LPC_HICR40x010
+#define LPC_HICR4_LADR12AS   BIT(7)
+#define LPC_HICR4_KCSENBLBIT(2)
+#define LPC_LADR3H   0x014
+#define LPC_LADR3L   0x018
+#define LPC_LADR12H  0x01C
+#define LPC_LADR12L  0x020
+#define LPC_IDR1 0x024
+#define LPC_IDR2 0x028
+#define LPC_IDR3 0x02C
+#define LPC_ODR1 0x030
+#define LPC_ODR2 0x034
+#define LPC_ODR3 0x038
+#define LPC_STR1 0x03C
+#define LPC_STR2 0x040
+#define LPC_STR3 0x044
+
+/* mapped to lpc-host@80 IO space */
+#define LPC_HICRB0x080
+#define LPC_HICRB_IBFIF4 BIT(1)
+#define LPC_HICRB_LPC4E  BIT

[PATCH arm/aspeed/ast2500 v5 1/2] ipmi: add a KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
---
v4->v5
- Fix -Wdiscarded-qualifiers 'const' compile warning.
- Fix size_t printk compile error.

v3->v4
- Change to accept WRITE_START any time.

v2->v3

- Update the KCS phase state machine.
- Fix the race condition of read/write.

v1->v2

- Divide the driver into two parts, one handles the BMC KCS IPMI 2.0 state;
  the other handles the BMC KCS controller such as AST2500 IO accessing. 
- Use the spin lock APIs to handle the device file operations and BMC chip
  IRQ inferface for accessing the same KCS BMC data structure.
- Enhanced the phases handling of the KCS BMC.
- Unified the IOCTL definition for IPMI BMC, it will be used by KCS and BT.


Provides a device driver for the KCS (Keyboard Controller Style)
IPMI interface which meets the requirement of the BMC (Baseboard
Management Controllers) side for handling the IPMI request from
host system software.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 drivers/char/ipmi/Kconfig |   8 +
 drivers/char/ipmi/Makefile|   1 +
 drivers/char/ipmi/kcs_bmc.c   | 464 ++
 drivers/char/ipmi/kcs_bmc.h   | 106 ++
 include/uapi/linux/ipmi_bmc.h |  14 ++
 5 files changed, 593 insertions(+)
 create mode 100644 drivers/char/ipmi/kcs_bmc.c
 create mode 100644 drivers/char/ipmi/kcs_bmc.h
 create mode 100644 include/uapi/linux/ipmi_bmc.h

diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..aa9bcb1 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -96,6 +96,14 @@ config IPMI_POWEROFF
 
 endif # IPMI_HANDLER
 
+config IPMI_KCS_BMC
+   tristate 'IPMI KCS BMC Interface'
+   help
+ Provides a device driver for the KCS (Keyboard Controller Style)
+ IPMI interface which meets the requirement of the BMC (Baseboard
+ Management Controllers) side for handling the IPMI request from
+ host system software.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..2abccb3 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
 obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
+obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
new file mode 100644
index 000..3a3498a
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -0,0 +1,464 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+#define KCS_MSG_BUFSIZ1000
+
+#define KCS_ZERO_DATA 0
+
+
+/* IPMI 2.0 - Table 9-1, KCS Interface Status Register Bits */
+#define KCS_STATUS_STATE(state) (state << 6)
+#define KCS_STATUS_STATE_MASK   GENMASK(7, 6)
+#define KCS_STATUS_CMD_DAT  BIT(3)
+#define KCS_STATUS_SMS_ATN  BIT(2)
+#define KCS_STATUS_IBF  BIT(1)
+#define KCS_STATUS_OBF  BIT(0)
+
+/* IPMI 2.0 - Table 9-2, KCS Interface State Bits */
+enum kcs_states {
+   IDLE_STATE  = 0,
+   READ_STATE  = 1,
+   WRITE_STATE = 2,
+   ERROR_STATE = 3,
+};
+
+/* IPMI 2.0 - Table 9-3, KCS Interface Control Codes */
+#define KCS_CMD_GET_STATUS_ABORT  0x60
+#define KCS_CMD_WRITE_START   0x61
+#define KCS_CMD_WRITE_END 0x62
+#define KCS_CMD_READ_BYTE 0x68
+
+static inline u8 read_data(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.idr);
+}
+
+static inline void write_data(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.odr, data);
+}
+
+static inline u8 read_status(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.str);
+}
+
+static inline void write_status(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.str, data);
+}
+
+static void update_status_bits(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
+{
+   u8 tmp = read_status(kcs_bmc);
+
+   tmp &= ~mask;
+   tmp |= val & mask;
+
+   write_status(kcs_bmc, tmp);
+}
+
+static inline void set_state(struct kcs_bmc *kcs_bmc, u8 state)
+{
+   update_status_bits(kcs_bmc, KCS_STATUS_STATE_MASK,
+   KCS_STATUS_STATE(state));
+}
+
+static void kcs_force_abort(struct kcs_bmc *kcs_bmc)
+{
+   set_state(kcs_bmc, ERROR_STATE);
+   read_data(kcs_bmc);
+   write_data(kcs_bmc, KCS_ZERO_DATA);
+
+   kcs_bmc->phase = KCS_PHASE_ERROR;
+   kcs_bmc->data_in_avail = fals

[PATCH arm/aspeed/ast2500 v5 1/2] ipmi: add a KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
---
v4->v5
- Fix -Wdiscarded-qualifiers 'const' compile warning.
- Fix size_t printk compile error.

v3->v4
- Change to accept WRITE_START any time.

v2->v3

- Update the KCS phase state machine.
- Fix the race condition of read/write.

v1->v2

- Divide the driver into two parts, one handles the BMC KCS IPMI 2.0 state;
  the other handles the BMC KCS controller such as AST2500 IO accessing. 
- Use the spin lock APIs to handle the device file operations and BMC chip
  IRQ inferface for accessing the same KCS BMC data structure.
- Enhanced the phases handling of the KCS BMC.
- Unified the IOCTL definition for IPMI BMC, it will be used by KCS and BT.


Provides a device driver for the KCS (Keyboard Controller Style)
IPMI interface which meets the requirement of the BMC (Baseboard
Management Controllers) side for handling the IPMI request from
host system software.

Signed-off-by: Haiyue Wang 
---
 drivers/char/ipmi/Kconfig |   8 +
 drivers/char/ipmi/Makefile|   1 +
 drivers/char/ipmi/kcs_bmc.c   | 464 ++
 drivers/char/ipmi/kcs_bmc.h   | 106 ++
 include/uapi/linux/ipmi_bmc.h |  14 ++
 5 files changed, 593 insertions(+)
 create mode 100644 drivers/char/ipmi/kcs_bmc.c
 create mode 100644 drivers/char/ipmi/kcs_bmc.h
 create mode 100644 include/uapi/linux/ipmi_bmc.h

diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..aa9bcb1 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -96,6 +96,14 @@ config IPMI_POWEROFF
 
 endif # IPMI_HANDLER
 
+config IPMI_KCS_BMC
+   tristate 'IPMI KCS BMC Interface'
+   help
+ Provides a device driver for the KCS (Keyboard Controller Style)
+ IPMI interface which meets the requirement of the BMC (Baseboard
+ Management Controllers) side for handling the IPMI request from
+ host system software.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..2abccb3 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
 obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
+obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
new file mode 100644
index 000..3a3498a
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -0,0 +1,464 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+#define KCS_MSG_BUFSIZ1000
+
+#define KCS_ZERO_DATA 0
+
+
+/* IPMI 2.0 - Table 9-1, KCS Interface Status Register Bits */
+#define KCS_STATUS_STATE(state) (state << 6)
+#define KCS_STATUS_STATE_MASK   GENMASK(7, 6)
+#define KCS_STATUS_CMD_DAT  BIT(3)
+#define KCS_STATUS_SMS_ATN  BIT(2)
+#define KCS_STATUS_IBF  BIT(1)
+#define KCS_STATUS_OBF  BIT(0)
+
+/* IPMI 2.0 - Table 9-2, KCS Interface State Bits */
+enum kcs_states {
+   IDLE_STATE  = 0,
+   READ_STATE  = 1,
+   WRITE_STATE = 2,
+   ERROR_STATE = 3,
+};
+
+/* IPMI 2.0 - Table 9-3, KCS Interface Control Codes */
+#define KCS_CMD_GET_STATUS_ABORT  0x60
+#define KCS_CMD_WRITE_START   0x61
+#define KCS_CMD_WRITE_END 0x62
+#define KCS_CMD_READ_BYTE 0x68
+
+static inline u8 read_data(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.idr);
+}
+
+static inline void write_data(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.odr, data);
+}
+
+static inline u8 read_status(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.str);
+}
+
+static inline void write_status(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.str, data);
+}
+
+static void update_status_bits(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
+{
+   u8 tmp = read_status(kcs_bmc);
+
+   tmp &= ~mask;
+   tmp |= val & mask;
+
+   write_status(kcs_bmc, tmp);
+}
+
+static inline void set_state(struct kcs_bmc *kcs_bmc, u8 state)
+{
+   update_status_bits(kcs_bmc, KCS_STATUS_STATE_MASK,
+   KCS_STATUS_STATE(state));
+}
+
+static void kcs_force_abort(struct kcs_bmc *kcs_bmc)
+{
+   set_state(kcs_bmc, ERROR_STATE);
+   read_data(kcs_bmc);
+   write_data(kcs_bmc, KCS_ZERO_DATA);
+
+   kcs_bmc->phase = KCS_PHASE_ERROR;
+   kcs_bmc->data_in_avail = false;
+   kcs_bmc->dat

[PATCH arm/aspeed/ast2500 v4 2/2] ipmi: add an Aspeed KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a server host and its BMC (BaseBoard Management
Controllers).

This driver exposes the KCS interface on ASpeed SOCs (AST2400 and AST2500)
as a character device. Such SOCs are commonly used as BMCs and this driver
implements the BMC side of the KCS interface.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 .../devicetree/bindings/ipmi/aspeed-kcs-bmc.txt|  26 ++
 drivers/char/ipmi/Kconfig  |  12 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs_bmc_aspeed.c | 319 +
 4 files changed, 358 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs_bmc_aspeed.c

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
new file mode 100644
index 000..613c34c
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
@@ -0,0 +1,26 @@
+* Aspeed KCS (Keyboard Controller Style) IPMI interface
+
+The Aspeed SOCs (AST2400 and AST2500) are commonly used as BMCs
+(Baseboard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"aspeed,ast2400-kcs-bmc"
+"aspeed,ast2500-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The LPC channel number in the controller
+- kcs_addr : The host CPU IO map address
+
+
+Example:
+
+kcs3: kcs3@0 {
+compatible = "aspeed,ast2500-kcs-bmc";
+reg = <0x0 0x80>;
+interrupts = <8>;
+kcs_chan = <3>;
+kcs_addr = <0xCA2>;
+status = "okay";
+};
+
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index aa9bcb1..770def0 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,6 +104,18 @@ config IPMI_KCS_BMC
  Management Controllers) side for handling the IPMI request from
  host system software.
 
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+   depends on IPMI_KCS_BMC
+   select REGMAP_MMIO
+   tristate "Aspeed KCS IPMI BMC driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500).
+
+ The driver implements the BMC side of the KCS contorller, it
+ provides the access of KCS IO space for BMC side.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 2abccb3..21e9e87 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -23,3 +23,4 @@ obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
new file mode 100644
index 000..0c4d1a3
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -0,0 +1,319 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "aspeed-kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+
+#define DEVICE_NAME "ast-kcs-bmc"
+
+#define KCS_CHANNEL_MAX 4
+
+/* mapped to lpc-bmc@0 IO space */
+#define LPC_HICR00x000
+#define LPC_HICR0_LPC3E  BIT(7)
+#define LPC_HICR0_LPC2E  BIT(6)
+#define LPC_HICR0_LPC1E  BIT(5)
+#define LPC_HICR20x008
+#define LPC_HICR2_IBFIF3 BIT(3)
+#define LPC_HICR2_IBFIF2 BIT(2)
+#define LPC_HICR2_IBFIF1 BIT(1)
+#define LPC_HICR40x010
+#define LPC_HICR4_LADR12AS   BIT(7)
+#define LPC_HICR4_KCSENBLBIT(2)
+#define LPC_LADR3H   0x014
+#define LPC_LADR3L   0x018
+#define LPC_LADR12H  0x01C
+#define LPC_LADR12L  0x020
+#define LPC_IDR1 0x024
+#define LPC_IDR2 0x028
+#define LPC_IDR3 0x02C
+#define LPC_ODR1 0x030
+#define LPC_ODR2 0x034
+#define LPC_ODR3 0x038
+#define LPC_STR1 0x03C
+#define LPC_STR2 0x040
+#define LPC_STR3 0x044
+
+/* mapped to lpc-host@80 IO space */
+#define LPC_HICRB0x080
+#define LPC_HICRB_IBFIF4 BIT(1)

[PATCH arm/aspeed/ast2500 v4 2/2] ipmi: add an Aspeed KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a server host and its BMC (BaseBoard Management
Controllers).

This driver exposes the KCS interface on ASpeed SOCs (AST2400 and AST2500)
as a character device. Such SOCs are commonly used as BMCs and this driver
implements the BMC side of the KCS interface.

Signed-off-by: Haiyue Wang 
---
 .../devicetree/bindings/ipmi/aspeed-kcs-bmc.txt|  26 ++
 drivers/char/ipmi/Kconfig  |  12 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs_bmc_aspeed.c | 319 +
 4 files changed, 358 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs_bmc_aspeed.c

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
new file mode 100644
index 000..613c34c
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
@@ -0,0 +1,26 @@
+* Aspeed KCS (Keyboard Controller Style) IPMI interface
+
+The Aspeed SOCs (AST2400 and AST2500) are commonly used as BMCs
+(Baseboard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"aspeed,ast2400-kcs-bmc"
+"aspeed,ast2500-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The LPC channel number in the controller
+- kcs_addr : The host CPU IO map address
+
+
+Example:
+
+kcs3: kcs3@0 {
+compatible = "aspeed,ast2500-kcs-bmc";
+reg = <0x0 0x80>;
+interrupts = <8>;
+kcs_chan = <3>;
+kcs_addr = <0xCA2>;
+status = "okay";
+};
+
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index aa9bcb1..770def0 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,6 +104,18 @@ config IPMI_KCS_BMC
  Management Controllers) side for handling the IPMI request from
  host system software.
 
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+   depends on IPMI_KCS_BMC
+   select REGMAP_MMIO
+   tristate "Aspeed KCS IPMI BMC driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500).
+
+ The driver implements the BMC side of the KCS contorller, it
+ provides the access of KCS IO space for BMC side.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 2abccb3..21e9e87 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -23,3 +23,4 @@ obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
new file mode 100644
index 000..0c4d1a3
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -0,0 +1,319 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "aspeed-kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+
+#define DEVICE_NAME "ast-kcs-bmc"
+
+#define KCS_CHANNEL_MAX 4
+
+/* mapped to lpc-bmc@0 IO space */
+#define LPC_HICR00x000
+#define LPC_HICR0_LPC3E  BIT(7)
+#define LPC_HICR0_LPC2E  BIT(6)
+#define LPC_HICR0_LPC1E  BIT(5)
+#define LPC_HICR20x008
+#define LPC_HICR2_IBFIF3 BIT(3)
+#define LPC_HICR2_IBFIF2 BIT(2)
+#define LPC_HICR2_IBFIF1 BIT(1)
+#define LPC_HICR40x010
+#define LPC_HICR4_LADR12AS   BIT(7)
+#define LPC_HICR4_KCSENBLBIT(2)
+#define LPC_LADR3H   0x014
+#define LPC_LADR3L   0x018
+#define LPC_LADR12H  0x01C
+#define LPC_LADR12L  0x020
+#define LPC_IDR1 0x024
+#define LPC_IDR2 0x028
+#define LPC_IDR3 0x02C
+#define LPC_ODR1 0x030
+#define LPC_ODR2 0x034
+#define LPC_ODR3 0x038
+#define LPC_STR1 0x03C
+#define LPC_STR2 0x040
+#define LPC_STR3 0x044
+
+/* mapped to lpc-host@80 IO space */
+#define LPC_HICRB0x080
+#define LPC_HICRB_IBFIF4 BIT(1)
+#define LPC_HICRB_LPC4E

[PATCH arm/aspeed/ast2500 v4 1/2] ipmi: add a KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
---
v3->v4
- Change to accept WRITE_START any time.

v2->v3

- Update the KCS phase state machine.
- Fix the race condition of read/write.

v1->v2

- Divide the driver into two parts, one handles the BMC KCS IPMI 2.0 state;
  the other handles the BMC KCS controller such as AST2500 IO accessing. 
- Use the spin lock APIs to handle the device file operations and BMC chip
  IRQ inferface for accessing the same KCS BMC data structure.
- Enhanced the phases handling of the KCS BMC.
- Unified the IOCTL definition for IPMI BMC, it will be used by KCS and BT.


Provides a device driver for the KCS (Keyboard Controller Style)
IPMI interface which meets the requirement of the BMC (Baseboard
Management Controllers) side for handling the IPMI request from
host system software.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 drivers/char/ipmi/Kconfig |   8 +
 drivers/char/ipmi/Makefile|   1 +
 drivers/char/ipmi/kcs_bmc.c   | 464 ++
 drivers/char/ipmi/kcs_bmc.h   | 106 ++
 include/uapi/linux/ipmi_bmc.h |  14 ++
 5 files changed, 593 insertions(+)
 create mode 100644 drivers/char/ipmi/kcs_bmc.c
 create mode 100644 drivers/char/ipmi/kcs_bmc.h
 create mode 100644 include/uapi/linux/ipmi_bmc.h

diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..aa9bcb1 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -96,6 +96,14 @@ config IPMI_POWEROFF
 
 endif # IPMI_HANDLER
 
+config IPMI_KCS_BMC
+   tristate 'IPMI KCS BMC Interface'
+   help
+ Provides a device driver for the KCS (Keyboard Controller Style)
+ IPMI interface which meets the requirement of the BMC (Baseboard
+ Management Controllers) side for handling the IPMI request from
+ host system software.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..2abccb3 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
 obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
+obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
new file mode 100644
index 000..d1751b4
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -0,0 +1,464 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+#define KCS_MSG_BUFSIZ1000
+
+#define KCS_ZERO_DATA 0
+
+
+/* IPMI 2.0 - Table 9-1, KCS Interface Status Register Bits */
+#define KCS_STATUS_STATE(state) (state << 6)
+#define KCS_STATUS_STATE_MASK   GENMASK(7, 6)
+#define KCS_STATUS_CMD_DAT  BIT(3)
+#define KCS_STATUS_SMS_ATN  BIT(2)
+#define KCS_STATUS_IBF  BIT(1)
+#define KCS_STATUS_OBF  BIT(0)
+
+/* IPMI 2.0 - Table 9-2, KCS Interface State Bits */
+enum kcs_states {
+   IDLE_STATE  = 0,
+   READ_STATE  = 1,
+   WRITE_STATE = 2,
+   ERROR_STATE = 3,
+};
+
+/* IPMI 2.0 - Table 9-3, KCS Interface Control Codes */
+#define KCS_CMD_GET_STATUS_ABORT  0x60
+#define KCS_CMD_WRITE_START   0x61
+#define KCS_CMD_WRITE_END 0x62
+#define KCS_CMD_READ_BYTE 0x68
+
+static inline u8 read_data(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.idr);
+}
+
+static inline void write_data(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.odr, data);
+}
+
+static inline u8 read_status(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.str);
+}
+
+static inline void write_status(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.str, data);
+}
+
+static void update_status_bits(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
+{
+   u8 tmp = read_status(kcs_bmc);
+
+   tmp &= ~mask;
+   tmp |= val & mask;
+
+   write_status(kcs_bmc, tmp);
+}
+
+static inline void set_state(struct kcs_bmc *kcs_bmc, u8 state)
+{
+   update_status_bits(kcs_bmc, KCS_STATUS_STATE_MASK,
+   KCS_STATUS_STATE(state));
+}
+
+static void kcs_force_abort(struct kcs_bmc *kcs_bmc)
+{
+   set_state(kcs_bmc, ERROR_STATE);
+   read_data(kcs_bmc);
+   write_data(kcs_bmc, KCS_ZERO_DATA);
+
+   kcs_bmc->phase = KCS_PHASE_ERROR;
+   kcs_bmc->data_in_avail = false;
+   kcs_bmc->data_in_idx = 0;
+}
+
+static void kcs_bmc_handle_data(struct kcs_bmc *k

[PATCH arm/aspeed/ast2500 v4 1/2] ipmi: add a KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
---
v3->v4
- Change to accept WRITE_START any time.

v2->v3

- Update the KCS phase state machine.
- Fix the race condition of read/write.

v1->v2

- Divide the driver into two parts, one handles the BMC KCS IPMI 2.0 state;
  the other handles the BMC KCS controller such as AST2500 IO accessing. 
- Use the spin lock APIs to handle the device file operations and BMC chip
  IRQ inferface for accessing the same KCS BMC data structure.
- Enhanced the phases handling of the KCS BMC.
- Unified the IOCTL definition for IPMI BMC, it will be used by KCS and BT.


Provides a device driver for the KCS (Keyboard Controller Style)
IPMI interface which meets the requirement of the BMC (Baseboard
Management Controllers) side for handling the IPMI request from
host system software.

Signed-off-by: Haiyue Wang 
---
 drivers/char/ipmi/Kconfig |   8 +
 drivers/char/ipmi/Makefile|   1 +
 drivers/char/ipmi/kcs_bmc.c   | 464 ++
 drivers/char/ipmi/kcs_bmc.h   | 106 ++
 include/uapi/linux/ipmi_bmc.h |  14 ++
 5 files changed, 593 insertions(+)
 create mode 100644 drivers/char/ipmi/kcs_bmc.c
 create mode 100644 drivers/char/ipmi/kcs_bmc.h
 create mode 100644 include/uapi/linux/ipmi_bmc.h

diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..aa9bcb1 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -96,6 +96,14 @@ config IPMI_POWEROFF
 
 endif # IPMI_HANDLER
 
+config IPMI_KCS_BMC
+   tristate 'IPMI KCS BMC Interface'
+   help
+ Provides a device driver for the KCS (Keyboard Controller Style)
+ IPMI interface which meets the requirement of the BMC (Baseboard
+ Management Controllers) side for handling the IPMI request from
+ host system software.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..2abccb3 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
 obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
+obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
new file mode 100644
index 000..d1751b4
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -0,0 +1,464 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+#define KCS_MSG_BUFSIZ1000
+
+#define KCS_ZERO_DATA 0
+
+
+/* IPMI 2.0 - Table 9-1, KCS Interface Status Register Bits */
+#define KCS_STATUS_STATE(state) (state << 6)
+#define KCS_STATUS_STATE_MASK   GENMASK(7, 6)
+#define KCS_STATUS_CMD_DAT  BIT(3)
+#define KCS_STATUS_SMS_ATN  BIT(2)
+#define KCS_STATUS_IBF  BIT(1)
+#define KCS_STATUS_OBF  BIT(0)
+
+/* IPMI 2.0 - Table 9-2, KCS Interface State Bits */
+enum kcs_states {
+   IDLE_STATE  = 0,
+   READ_STATE  = 1,
+   WRITE_STATE = 2,
+   ERROR_STATE = 3,
+};
+
+/* IPMI 2.0 - Table 9-3, KCS Interface Control Codes */
+#define KCS_CMD_GET_STATUS_ABORT  0x60
+#define KCS_CMD_WRITE_START   0x61
+#define KCS_CMD_WRITE_END 0x62
+#define KCS_CMD_READ_BYTE 0x68
+
+static inline u8 read_data(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.idr);
+}
+
+static inline void write_data(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.odr, data);
+}
+
+static inline u8 read_status(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.str);
+}
+
+static inline void write_status(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.str, data);
+}
+
+static void update_status_bits(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
+{
+   u8 tmp = read_status(kcs_bmc);
+
+   tmp &= ~mask;
+   tmp |= val & mask;
+
+   write_status(kcs_bmc, tmp);
+}
+
+static inline void set_state(struct kcs_bmc *kcs_bmc, u8 state)
+{
+   update_status_bits(kcs_bmc, KCS_STATUS_STATE_MASK,
+   KCS_STATUS_STATE(state));
+}
+
+static void kcs_force_abort(struct kcs_bmc *kcs_bmc)
+{
+   set_state(kcs_bmc, ERROR_STATE);
+   read_data(kcs_bmc);
+   write_data(kcs_bmc, KCS_ZERO_DATA);
+
+   kcs_bmc->phase = KCS_PHASE_ERROR;
+   kcs_bmc->data_in_avail = false;
+   kcs_bmc->data_in_idx = 0;
+}
+
+static void kcs_bmc_handle_data(struct kcs_bmc *kcs_bmc)
+{
+   u8 data;
+
+   

[PATCH arm/aspeed/ast2500 v3 1/2] ipmi: add a KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
---
v2->v3

- Update the KCS phase state machine.
- Fix the race condition of read/write.

v1->v2

- Divide the driver into two parts, one handles the BMC KCS IPMI 2.0 state;
  the other handles the BMC KCS controller such as AST2500 IO accessing. 
- Use the spin lock APIs to handle the device file operations and BMC chip
  IRQ inferface for accessing the same KCS BMC data structure.
- Enhanced the phases handling of the KCS BMC.
- Unified the IOCTL definition for IPMI BMC, it will be used by KCS and BT.

Provides a device driver for the KCS (Keyboard Controller Style)
IPMI interface which meets the requirement of the BMC (Baseboard
Management Controllers) side for handling the IPMI request from
host system software.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 drivers/char/ipmi/Kconfig |   8 +
 drivers/char/ipmi/Makefile|   1 +
 drivers/char/ipmi/kcs_bmc.c   | 468 ++
 drivers/char/ipmi/kcs_bmc.h   | 106 ++
 include/uapi/linux/ipmi_bmc.h |  14 ++
 5 files changed, 597 insertions(+)
 create mode 100644 drivers/char/ipmi/kcs_bmc.c
 create mode 100644 drivers/char/ipmi/kcs_bmc.h
 create mode 100644 include/uapi/linux/ipmi_bmc.h

diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..aa9bcb1 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -96,6 +96,14 @@ config IPMI_POWEROFF
 
 endif # IPMI_HANDLER
 
+config IPMI_KCS_BMC
+   tristate 'IPMI KCS BMC Interface'
+   help
+ Provides a device driver for the KCS (Keyboard Controller Style)
+ IPMI interface which meets the requirement of the BMC (Baseboard
+ Management Controllers) side for handling the IPMI request from
+ host system software.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..2abccb3 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
 obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
+obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
new file mode 100644
index 000..c4676e9
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -0,0 +1,468 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+#define KCS_MSG_BUFSIZ1000
+
+#define KCS_ZERO_DATA 0
+
+
+/* IPMI 2.0 - Table 9-1, KCS Interface Status Register Bits */
+#define KCS_STATUS_STATE(state) (state << 6)
+#define KCS_STATUS_STATE_MASK   GENMASK(7, 6)
+#define KCS_STATUS_CMD_DAT  BIT(3)
+#define KCS_STATUS_SMS_ATN  BIT(2)
+#define KCS_STATUS_IBF  BIT(1)
+#define KCS_STATUS_OBF  BIT(0)
+
+/* IPMI 2.0 - Table 9-2, KCS Interface State Bits */
+enum kcs_states {
+   IDLE_STATE  = 0,
+   READ_STATE  = 1,
+   WRITE_STATE = 2,
+   ERROR_STATE = 3,
+};
+
+/* IPMI 2.0 - Table 9-3, KCS Interface Control Codes */
+#define KCS_CMD_GET_STATUS_ABORT  0x60
+#define KCS_CMD_WRITE_START   0x61
+#define KCS_CMD_WRITE_END 0x62
+#define KCS_CMD_READ_BYTE 0x68
+
+static inline u8 read_data(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.idr);
+}
+
+static inline void write_data(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.odr, data);
+}
+
+static inline u8 read_status(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.str);
+}
+
+static inline void write_status(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.str, data);
+}
+
+static void update_status_bits(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
+{
+   u8 tmp = read_status(kcs_bmc);
+
+   tmp &= ~mask;
+   tmp |= val & mask;
+
+   write_status(kcs_bmc, tmp);
+}
+
+static inline void set_state(struct kcs_bmc *kcs_bmc, u8 state)
+{
+   update_status_bits(kcs_bmc, KCS_STATUS_STATE_MASK,
+   KCS_STATUS_STATE(state));
+}
+
+static void kcs_force_abort(struct kcs_bmc *kcs_bmc)
+{
+   set_state(kcs_bmc, ERROR_STATE);
+   read_data(kcs_bmc);
+   write_data(kcs_bmc, KCS_ZERO_DATA);
+
+   kcs_bmc->phase = KCS_PHASE_ERROR;
+   kcs_bmc->data_in_avail = false;
+   kcs_bmc->data_in_idx = 0;
+}
+
+static void kcs_bmc_handle_data(struct kcs_bmc *kcs_bmc)
+{
+   u8 data;
+
+   switch (kcs_bmc->

[PATCH arm/aspeed/ast2500 v3 2/2] ipmi: add an Aspeed KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a server host and its BMC (BaseBoard Management
Controllers).

This driver exposes the KCS interface on ASpeed SOCs (AST2400 and AST2500)
as a character device. Such SOCs are commonly used as BMCs and this driver
implements the BMC side of the KCS interface.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 .../devicetree/bindings/ipmi/aspeed-kcs-bmc.txt|  26 ++
 drivers/char/ipmi/Kconfig  |  12 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs_bmc_aspeed.c | 319 +
 4 files changed, 358 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs_bmc_aspeed.c

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
new file mode 100644
index 000..613c34c
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
@@ -0,0 +1,26 @@
+* Aspeed KCS (Keyboard Controller Style) IPMI interface
+
+The Aspeed SOCs (AST2400 and AST2500) are commonly used as BMCs
+(Baseboard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"aspeed,ast2400-kcs-bmc"
+"aspeed,ast2500-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The LPC channel number in the controller
+- kcs_addr : The host CPU IO map address
+
+
+Example:
+
+kcs3: kcs3@0 {
+compatible = "aspeed,ast2500-kcs-bmc";
+reg = <0x0 0x80>;
+interrupts = <8>;
+kcs_chan = <3>;
+kcs_addr = <0xCA2>;
+status = "okay";
+};
+
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index aa9bcb1..770def0 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,6 +104,18 @@ config IPMI_KCS_BMC
  Management Controllers) side for handling the IPMI request from
  host system software.
 
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+   depends on IPMI_KCS_BMC
+   select REGMAP_MMIO
+   tristate "Aspeed KCS IPMI BMC driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500).
+
+ The driver implements the BMC side of the KCS contorller, it
+ provides the access of KCS IO space for BMC side.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 2abccb3..21e9e87 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -23,3 +23,4 @@ obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
new file mode 100644
index 000..0c4d1a3
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -0,0 +1,319 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "aspeed-kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+
+#define DEVICE_NAME "ast-kcs-bmc"
+
+#define KCS_CHANNEL_MAX 4
+
+/* mapped to lpc-bmc@0 IO space */
+#define LPC_HICR00x000
+#define LPC_HICR0_LPC3E  BIT(7)
+#define LPC_HICR0_LPC2E  BIT(6)
+#define LPC_HICR0_LPC1E  BIT(5)
+#define LPC_HICR20x008
+#define LPC_HICR2_IBFIF3 BIT(3)
+#define LPC_HICR2_IBFIF2 BIT(2)
+#define LPC_HICR2_IBFIF1 BIT(1)
+#define LPC_HICR40x010
+#define LPC_HICR4_LADR12AS   BIT(7)
+#define LPC_HICR4_KCSENBLBIT(2)
+#define LPC_LADR3H   0x014
+#define LPC_LADR3L   0x018
+#define LPC_LADR12H  0x01C
+#define LPC_LADR12L  0x020
+#define LPC_IDR1 0x024
+#define LPC_IDR2 0x028
+#define LPC_IDR3 0x02C
+#define LPC_ODR1 0x030
+#define LPC_ODR2 0x034
+#define LPC_ODR3 0x038
+#define LPC_STR1 0x03C
+#define LPC_STR2 0x040
+#define LPC_STR3 0x044
+
+/* mapped to lpc-host@80 IO space */
+#define LPC_HICRB0x080
+#define LPC_HICRB_IBFIF4 BIT(1)

[PATCH arm/aspeed/ast2500 v3 1/2] ipmi: add a KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
---
v2->v3

- Update the KCS phase state machine.
- Fix the race condition of read/write.

v1->v2

- Divide the driver into two parts, one handles the BMC KCS IPMI 2.0 state;
  the other handles the BMC KCS controller such as AST2500 IO accessing. 
- Use the spin lock APIs to handle the device file operations and BMC chip
  IRQ inferface for accessing the same KCS BMC data structure.
- Enhanced the phases handling of the KCS BMC.
- Unified the IOCTL definition for IPMI BMC, it will be used by KCS and BT.

Provides a device driver for the KCS (Keyboard Controller Style)
IPMI interface which meets the requirement of the BMC (Baseboard
Management Controllers) side for handling the IPMI request from
host system software.

Signed-off-by: Haiyue Wang 
---
 drivers/char/ipmi/Kconfig |   8 +
 drivers/char/ipmi/Makefile|   1 +
 drivers/char/ipmi/kcs_bmc.c   | 468 ++
 drivers/char/ipmi/kcs_bmc.h   | 106 ++
 include/uapi/linux/ipmi_bmc.h |  14 ++
 5 files changed, 597 insertions(+)
 create mode 100644 drivers/char/ipmi/kcs_bmc.c
 create mode 100644 drivers/char/ipmi/kcs_bmc.h
 create mode 100644 include/uapi/linux/ipmi_bmc.h

diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..aa9bcb1 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -96,6 +96,14 @@ config IPMI_POWEROFF
 
 endif # IPMI_HANDLER
 
+config IPMI_KCS_BMC
+   tristate 'IPMI KCS BMC Interface'
+   help
+ Provides a device driver for the KCS (Keyboard Controller Style)
+ IPMI interface which meets the requirement of the BMC (Baseboard
+ Management Controllers) side for handling the IPMI request from
+ host system software.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..2abccb3 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
 obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
+obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
new file mode 100644
index 000..c4676e9
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -0,0 +1,468 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+#define KCS_MSG_BUFSIZ1000
+
+#define KCS_ZERO_DATA 0
+
+
+/* IPMI 2.0 - Table 9-1, KCS Interface Status Register Bits */
+#define KCS_STATUS_STATE(state) (state << 6)
+#define KCS_STATUS_STATE_MASK   GENMASK(7, 6)
+#define KCS_STATUS_CMD_DAT  BIT(3)
+#define KCS_STATUS_SMS_ATN  BIT(2)
+#define KCS_STATUS_IBF  BIT(1)
+#define KCS_STATUS_OBF  BIT(0)
+
+/* IPMI 2.0 - Table 9-2, KCS Interface State Bits */
+enum kcs_states {
+   IDLE_STATE  = 0,
+   READ_STATE  = 1,
+   WRITE_STATE = 2,
+   ERROR_STATE = 3,
+};
+
+/* IPMI 2.0 - Table 9-3, KCS Interface Control Codes */
+#define KCS_CMD_GET_STATUS_ABORT  0x60
+#define KCS_CMD_WRITE_START   0x61
+#define KCS_CMD_WRITE_END 0x62
+#define KCS_CMD_READ_BYTE 0x68
+
+static inline u8 read_data(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.idr);
+}
+
+static inline void write_data(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.odr, data);
+}
+
+static inline u8 read_status(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.str);
+}
+
+static inline void write_status(struct kcs_bmc *kcs_bmc, u8 data)
+{
+   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.str, data);
+}
+
+static void update_status_bits(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
+{
+   u8 tmp = read_status(kcs_bmc);
+
+   tmp &= ~mask;
+   tmp |= val & mask;
+
+   write_status(kcs_bmc, tmp);
+}
+
+static inline void set_state(struct kcs_bmc *kcs_bmc, u8 state)
+{
+   update_status_bits(kcs_bmc, KCS_STATUS_STATE_MASK,
+   KCS_STATUS_STATE(state));
+}
+
+static void kcs_force_abort(struct kcs_bmc *kcs_bmc)
+{
+   set_state(kcs_bmc, ERROR_STATE);
+   read_data(kcs_bmc);
+   write_data(kcs_bmc, KCS_ZERO_DATA);
+
+   kcs_bmc->phase = KCS_PHASE_ERROR;
+   kcs_bmc->data_in_avail = false;
+   kcs_bmc->data_in_idx = 0;
+}
+
+static void kcs_bmc_handle_data(struct kcs_bmc *kcs_bmc)
+{
+   u8 data;
+
+   switch (kcs_bmc->phase) {
+   case 

[PATCH arm/aspeed/ast2500 v3 2/2] ipmi: add an Aspeed KCS IPMI BMC driver

2018-02-01 Thread Haiyue Wang
The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a server host and its BMC (BaseBoard Management
Controllers).

This driver exposes the KCS interface on ASpeed SOCs (AST2400 and AST2500)
as a character device. Such SOCs are commonly used as BMCs and this driver
implements the BMC side of the KCS interface.

Signed-off-by: Haiyue Wang 
---
 .../devicetree/bindings/ipmi/aspeed-kcs-bmc.txt|  26 ++
 drivers/char/ipmi/Kconfig  |  12 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs_bmc_aspeed.c | 319 +
 4 files changed, 358 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs_bmc_aspeed.c

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
new file mode 100644
index 000..613c34c
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
@@ -0,0 +1,26 @@
+* Aspeed KCS (Keyboard Controller Style) IPMI interface
+
+The Aspeed SOCs (AST2400 and AST2500) are commonly used as BMCs
+(Baseboard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"aspeed,ast2400-kcs-bmc"
+"aspeed,ast2500-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The LPC channel number in the controller
+- kcs_addr : The host CPU IO map address
+
+
+Example:
+
+kcs3: kcs3@0 {
+compatible = "aspeed,ast2500-kcs-bmc";
+reg = <0x0 0x80>;
+interrupts = <8>;
+kcs_chan = <3>;
+kcs_addr = <0xCA2>;
+status = "okay";
+};
+
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index aa9bcb1..770def0 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,6 +104,18 @@ config IPMI_KCS_BMC
  Management Controllers) side for handling the IPMI request from
  host system software.
 
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+   depends on IPMI_KCS_BMC
+   select REGMAP_MMIO
+   tristate "Aspeed KCS IPMI BMC driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500).
+
+ The driver implements the BMC side of the KCS contorller, it
+ provides the access of KCS IO space for BMC side.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 2abccb3..21e9e87 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -23,3 +23,4 @@ obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
new file mode 100644
index 000..0c4d1a3
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -0,0 +1,319 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#define pr_fmt(fmt) "aspeed-kcs-bmc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+
+#define DEVICE_NAME "ast-kcs-bmc"
+
+#define KCS_CHANNEL_MAX 4
+
+/* mapped to lpc-bmc@0 IO space */
+#define LPC_HICR00x000
+#define LPC_HICR0_LPC3E  BIT(7)
+#define LPC_HICR0_LPC2E  BIT(6)
+#define LPC_HICR0_LPC1E  BIT(5)
+#define LPC_HICR20x008
+#define LPC_HICR2_IBFIF3 BIT(3)
+#define LPC_HICR2_IBFIF2 BIT(2)
+#define LPC_HICR2_IBFIF1 BIT(1)
+#define LPC_HICR40x010
+#define LPC_HICR4_LADR12AS   BIT(7)
+#define LPC_HICR4_KCSENBLBIT(2)
+#define LPC_LADR3H   0x014
+#define LPC_LADR3L   0x018
+#define LPC_LADR12H  0x01C
+#define LPC_LADR12L  0x020
+#define LPC_IDR1 0x024
+#define LPC_IDR2 0x028
+#define LPC_IDR3 0x02C
+#define LPC_ODR1 0x030
+#define LPC_ODR2 0x034
+#define LPC_ODR3 0x038
+#define LPC_STR1 0x03C
+#define LPC_STR2 0x040
+#define LPC_STR3 0x044
+
+/* mapped to lpc-host@80 IO space */
+#define LPC_HICRB0x080
+#define LPC_HICRB_IBFIF4 BIT(1)
+#define LPC_HICRB_LPC4E

[PATCH arm/aspeed/ast2500 v2] ipmi: add an Aspeed KCS IPMI BMC driver

2018-01-24 Thread Haiyue Wang
The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a server host and its BMC (BaseBoard Management
Controllers).

This driver exposes the KCS interface on ASpeed SOCs (AST2400 and AST2500)
as a character device. Such SOCs are commonly used as BMCs and this driver
implements the BMC side of the KCS interface.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>

---
v1->v2

- Divide the driver into two parts, one handles the BMC KCS IPMI 2.0 state;
  the other handles the BMC KCS controller such as AST2500 IO accessing. 
- Use the spin lock APIs to handle the device file operations and BMC chip
  IRQ inferface for accessing the same KCS BMC data structure.
- Enhanced the phases handling of the KCS BMC.
- Unified the IOCTL definition for IPMI BMC, it will be used by KCS and BT.

---
 .../devicetree/bindings/ipmi/aspeed-kcs-bmc.txt|  26 ++
 drivers/char/ipmi/Kconfig  |  20 +
 drivers/char/ipmi/Makefile |   2 +
 drivers/char/ipmi/kcs_bmc.c| 430 +
 drivers/char/ipmi/kcs_bmc.h|  88 +
 drivers/char/ipmi/kcs_bmc_aspeed.c | 319 +++
 include/uapi/linux/ipmi_bmc.h  |  14 +
 7 files changed, 899 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs_bmc.c
 create mode 100644 drivers/char/ipmi/kcs_bmc.h
 create mode 100644 drivers/char/ipmi/kcs_bmc_aspeed.c
 create mode 100644 include/uapi/linux/ipmi_bmc.h

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
new file mode 100644
index 000..613c34c
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
@@ -0,0 +1,26 @@
+* Aspeed KCS (Keyboard Controller Style) IPMI interface
+
+The Aspeed SOCs (AST2400 and AST2500) are commonly used as BMCs
+(Baseboard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"aspeed,ast2400-kcs-bmc"
+"aspeed,ast2500-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The LPC channel number in the controller
+- kcs_addr : The host CPU IO map address
+
+
+Example:
+
+kcs3: kcs3@0 {
+compatible = "aspeed,ast2500-kcs-bmc";
+reg = <0x0 0x80>;
+interrupts = <8>;
+kcs_chan = <3>;
+kcs_addr = <0xCA2>;
+status = "okay";
+};
+
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..770def0 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -96,6 +96,26 @@ config IPMI_POWEROFF
 
 endif # IPMI_HANDLER
 
+config IPMI_KCS_BMC
+   tristate 'IPMI KCS BMC Interface'
+   help
+ Provides a device driver for the KCS (Keyboard Controller Style)
+ IPMI interface which meets the requirement of the BMC (Baseboard
+ Management Controllers) side for handling the IPMI request from
+ host system software.
+
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+   depends on IPMI_KCS_BMC
+   select REGMAP_MMIO
+   tristate "Aspeed KCS IPMI BMC driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500).
+
+ The driver implements the BMC side of the KCS contorller, it
+ provides the access of KCS IO space for BMC side.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..10c591a 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -21,4 +21,6 @@ obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
 obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
+obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
\ No newline at end of file
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
new file mode 100644
index 000..4ef3c0b
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -0,0 +1,430 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+#define KCS_MSG_BUFSIZ1024
+
+#define KCS_ZERO_DATA 0
+
+
+/* IPMI 2.0 - Table 9-1, KCS Interface Status Register Bits */
+#define KCS_STATUS_STATE(state) (state 

[PATCH arm/aspeed/ast2500 v2] ipmi: add an Aspeed KCS IPMI BMC driver

2018-01-24 Thread Haiyue Wang
The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a server host and its BMC (BaseBoard Management
Controllers).

This driver exposes the KCS interface on ASpeed SOCs (AST2400 and AST2500)
as a character device. Such SOCs are commonly used as BMCs and this driver
implements the BMC side of the KCS interface.

Signed-off-by: Haiyue Wang 

---
v1->v2

- Divide the driver into two parts, one handles the BMC KCS IPMI 2.0 state;
  the other handles the BMC KCS controller such as AST2500 IO accessing. 
- Use the spin lock APIs to handle the device file operations and BMC chip
  IRQ inferface for accessing the same KCS BMC data structure.
- Enhanced the phases handling of the KCS BMC.
- Unified the IOCTL definition for IPMI BMC, it will be used by KCS and BT.

---
 .../devicetree/bindings/ipmi/aspeed-kcs-bmc.txt|  26 ++
 drivers/char/ipmi/Kconfig  |  20 +
 drivers/char/ipmi/Makefile |   2 +
 drivers/char/ipmi/kcs_bmc.c| 430 +
 drivers/char/ipmi/kcs_bmc.h|  88 +
 drivers/char/ipmi/kcs_bmc_aspeed.c | 319 +++
 include/uapi/linux/ipmi_bmc.h  |  14 +
 7 files changed, 899 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs_bmc.c
 create mode 100644 drivers/char/ipmi/kcs_bmc.h
 create mode 100644 drivers/char/ipmi/kcs_bmc_aspeed.c
 create mode 100644 include/uapi/linux/ipmi_bmc.h

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
new file mode 100644
index 000..613c34c
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
@@ -0,0 +1,26 @@
+* Aspeed KCS (Keyboard Controller Style) IPMI interface
+
+The Aspeed SOCs (AST2400 and AST2500) are commonly used as BMCs
+(Baseboard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"aspeed,ast2400-kcs-bmc"
+"aspeed,ast2500-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The LPC channel number in the controller
+- kcs_addr : The host CPU IO map address
+
+
+Example:
+
+kcs3: kcs3@0 {
+compatible = "aspeed,ast2500-kcs-bmc";
+reg = <0x0 0x80>;
+interrupts = <8>;
+kcs_chan = <3>;
+kcs_addr = <0xCA2>;
+status = "okay";
+};
+
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..770def0 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -96,6 +96,26 @@ config IPMI_POWEROFF
 
 endif # IPMI_HANDLER
 
+config IPMI_KCS_BMC
+   tristate 'IPMI KCS BMC Interface'
+   help
+ Provides a device driver for the KCS (Keyboard Controller Style)
+ IPMI interface which meets the requirement of the BMC (Baseboard
+ Management Controllers) side for handling the IPMI request from
+ host system software.
+
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+   depends on IPMI_KCS_BMC
+   select REGMAP_MMIO
+   tristate "Aspeed KCS IPMI BMC driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500).
+
+ The driver implements the BMC side of the KCS contorller, it
+ provides the access of KCS IO space for BMC side.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..10c591a 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -21,4 +21,6 @@ obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
 obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
+obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
\ No newline at end of file
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
new file mode 100644
index 000..4ef3c0b
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -0,0 +1,430 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "kcs_bmc.h"
+
+#define KCS_MSG_BUFSIZ1024
+
+#define KCS_ZERO_DATA 0
+
+
+/* IPMI 2.0 - Table 9-1, KCS Interface Status Register Bits */
+#define KCS_STATUS_STATE(state) (state << 6)
+#define KCS_STATUS_STAT

[PATCH arm/aspeed/ast2500 v1] eSPI: add Aspeed AST2500 eSPI driver to boot a host with PCH runs on eSPI

2018-01-16 Thread Haiyue Wang
When PCH works under eSPI mode, the PMC (Power Management Controller) in
PCH is waiting for SUS_ACK from BMC after it alerts SUS_WARN. It is in
dead loop if no SUS_ACK assert. This is the basic requirement for the BMC
works as eSPI slave.

Also for the host power on / off actions, from BMC side, the following VW
(Virtual Wire) messages are done in firmware:
1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
2. SUS_ACK
3. OOB_RESET_ACK
4. HOST_RESET_ACK

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 .../devicetree/bindings/misc/aspeed-espi-slave.txt |  20 ++
 Documentation/misc-devices/espi-slave.rst  | 114 +
 drivers/misc/Kconfig   |  11 +
 drivers/misc/Makefile  |   1 +
 drivers/misc/aspeed-espi-slave.c   | 266 +
 5 files changed, 412 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
 create mode 100644 Documentation/misc-devices/espi-slave.rst
 create mode 100644 drivers/misc/aspeed-espi-slave.c

diff --git a/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt 
b/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
new file mode 100644
index 000..35da26f
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
@@ -0,0 +1,20 @@
+Aspeed eSPI Slave Controller
+
+Required properties:
+ - compatible: must be one of:
+   - "aspeed,ast2500-espi-slave"
+
+ - reg: physical base address of the controller and length of memory mapped
+   region
+
+ - interrupts: interrupt generated by the controller
+
+Example:
+
+espi: espi@1e6ee000 {
+compatible = "aspeed,ast2500-espi-slave";
+reg = <0x1e6ee000 0x100>;
+interrupts = <23>;
+status = "disabled";
+};
+
diff --git a/Documentation/misc-devices/espi-slave.rst 
b/Documentation/misc-devices/espi-slave.rst
new file mode 100644
index 000..405b619
--- /dev/null
+++ b/Documentation/misc-devices/espi-slave.rst
@@ -0,0 +1,114 @@
+eSPI Slave
+==
+
+The PCH (**eSPI master**) provides the eSPI to support connection of a
+BMC (**eSPI slave**) to the platform.
+
+The LPC and eSPI interfaces are mutually exclusive. Both use the same
+pins, but on power-up, a HW strap determines if the eSPI or the LPC bus
+is operational. Once selected, it’s not possible to change to the other
+interface.
+
+``eSPI Channels and Supported Transactions``
+ +--+-+--++
+ | CH # | Channel | Posted Cycles| Non-Posted Cycles  |
+ +==+=+==++
+ |  0   | Peripheral  | Memory Write,| Memory Read,   |
+ |  | | Completions  | I/O Read/Write |
+ +--+-+--++
+ |  1   | Virtual Wire| Virtual Wire GET/PUT | N/A|
+ +--+-+--++
+ |  2   | Out-of-Band Message | SMBus Packet GET/PUT | N/A|
+ +--+-+--++
+ |  3   | Flash Access| N/A  | Flash Read, Write, |
+ |  | |  | Erase  |
+ +--+-+--++
+ |  N/A | General | Register Accesses| N/A|
+ +--+-+--++
+
+Virtual Wire Channel (Channel 1) Overview
+-
+
+The Virtual Wire channel uses a standard message format to communicate
+several types of signals between the components on the platform::
+
+ - Sideband and GPIO Pins: System events and other dedicated signals
+   between the PCH and eSPI slave. These signals are tunneled between the
+   two components over eSPI.
+
+ - Serial IRQ Interrupts: Interrupts are tunneled from the eSPI slave to
+   the PCH. Both edge and triggered interrupts are supported.
+
+When PCH runs on eSPI mode, from BMC side, the following VW messages are
+done in firmware::
+
+ 1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
+ 2. SUS_ACK
+ 3. OOB_RESET_ACK
+ 4. HOST_RESET_ACK
+
+``eSPI Virtual Wires (VW)``
+ +--+-+---+
+ |Virtual Wire  |PCH Pin  |Comments   |
+ |  |Direction|   |
+ +==+=+===+
+ |SUS_WARN# |Output   |PCH pin is a GPIO when eSPI is enabled.|
+ |  | |eSPI controller receives as VW message.|
+ +--+-+---+
+ |SUS_ACK#

[PATCH arm/aspeed/ast2500 v1] eSPI: add Aspeed AST2500 eSPI driver to boot a host with PCH runs on eSPI

2018-01-16 Thread Haiyue Wang
When PCH works under eSPI mode, the PMC (Power Management Controller) in
PCH is waiting for SUS_ACK from BMC after it alerts SUS_WARN. It is in
dead loop if no SUS_ACK assert. This is the basic requirement for the BMC
works as eSPI slave.

Also for the host power on / off actions, from BMC side, the following VW
(Virtual Wire) messages are done in firmware:
1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
2. SUS_ACK
3. OOB_RESET_ACK
4. HOST_RESET_ACK

Signed-off-by: Haiyue Wang 
---
 .../devicetree/bindings/misc/aspeed-espi-slave.txt |  20 ++
 Documentation/misc-devices/espi-slave.rst  | 114 +
 drivers/misc/Kconfig   |  11 +
 drivers/misc/Makefile  |   1 +
 drivers/misc/aspeed-espi-slave.c   | 266 +
 5 files changed, 412 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
 create mode 100644 Documentation/misc-devices/espi-slave.rst
 create mode 100644 drivers/misc/aspeed-espi-slave.c

diff --git a/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt 
b/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
new file mode 100644
index 000..35da26f
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
@@ -0,0 +1,20 @@
+Aspeed eSPI Slave Controller
+
+Required properties:
+ - compatible: must be one of:
+   - "aspeed,ast2500-espi-slave"
+
+ - reg: physical base address of the controller and length of memory mapped
+   region
+
+ - interrupts: interrupt generated by the controller
+
+Example:
+
+espi: espi@1e6ee000 {
+compatible = "aspeed,ast2500-espi-slave";
+reg = <0x1e6ee000 0x100>;
+interrupts = <23>;
+status = "disabled";
+};
+
diff --git a/Documentation/misc-devices/espi-slave.rst 
b/Documentation/misc-devices/espi-slave.rst
new file mode 100644
index 000..405b619
--- /dev/null
+++ b/Documentation/misc-devices/espi-slave.rst
@@ -0,0 +1,114 @@
+eSPI Slave
+==
+
+The PCH (**eSPI master**) provides the eSPI to support connection of a
+BMC (**eSPI slave**) to the platform.
+
+The LPC and eSPI interfaces are mutually exclusive. Both use the same
+pins, but on power-up, a HW strap determines if the eSPI or the LPC bus
+is operational. Once selected, it’s not possible to change to the other
+interface.
+
+``eSPI Channels and Supported Transactions``
+ +--+-+--++
+ | CH # | Channel | Posted Cycles| Non-Posted Cycles  |
+ +==+=+==++
+ |  0   | Peripheral  | Memory Write,| Memory Read,   |
+ |  | | Completions  | I/O Read/Write |
+ +--+-+--++
+ |  1   | Virtual Wire| Virtual Wire GET/PUT | N/A|
+ +--+-+--++
+ |  2   | Out-of-Band Message | SMBus Packet GET/PUT | N/A|
+ +--+-+--++
+ |  3   | Flash Access| N/A  | Flash Read, Write, |
+ |  | |  | Erase  |
+ +--+-+--++
+ |  N/A | General | Register Accesses| N/A|
+ +--+-+--++
+
+Virtual Wire Channel (Channel 1) Overview
+-
+
+The Virtual Wire channel uses a standard message format to communicate
+several types of signals between the components on the platform::
+
+ - Sideband and GPIO Pins: System events and other dedicated signals
+   between the PCH and eSPI slave. These signals are tunneled between the
+   two components over eSPI.
+
+ - Serial IRQ Interrupts: Interrupts are tunneled from the eSPI slave to
+   the PCH. Both edge and triggered interrupts are supported.
+
+When PCH runs on eSPI mode, from BMC side, the following VW messages are
+done in firmware::
+
+ 1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
+ 2. SUS_ACK
+ 3. OOB_RESET_ACK
+ 4. HOST_RESET_ACK
+
+``eSPI Virtual Wires (VW)``
+ +--+-+---+
+ |Virtual Wire  |PCH Pin  |Comments   |
+ |  |Direction|   |
+ +==+=+===+
+ |SUS_WARN# |Output   |PCH pin is a GPIO when eSPI is enabled.|
+ |  | |eSPI controller receives as VW message.|
+ +--+-+---+
+ |SUS_ACK#  |Input 

[PATCH arm/aspeed/ast2500 v1] ipmi: add an Aspeed KCS IPMI BMC driver

2018-01-16 Thread Haiyue Wang
The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a server host and its BMC (BaseBoard Management
Controllers).

This driver exposes the KCS interface on ASpeed SOCs (AST2400 and AST2500)
as a character device. Such SOCs are commonly used as BMCs and this driver
implements the BMC side of the KCS interface.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 .../devicetree/bindings/ipmi/aspeed-kcs-bmc.txt|  26 +
 drivers/char/ipmi/Kconfig  |   9 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs-bmc.c| 744 +
 include/uapi/linux/kcs-bmc.h   |  14 +
 5 files changed, 794 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs-bmc.c
 create mode 100644 include/uapi/linux/kcs-bmc.h

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
new file mode 100644
index 000..dd0c73d
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
@@ -0,0 +1,26 @@
+* Aspeed KCS (Keyboard Controller Style) IPMI interface
+
+The Aspeed SOCs (AST2400 and AST2500) are commonly used as BMCs
+(BaseBoard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"aspeed,ast2400-kcs-bmc"
+"aspeed,ast2500-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The LPC channel number in the controller
+- kcs_addr : The host CPU IO map address
+
+
+Example:
+
+kcs3: kcs3@0 {
+compatible = "aspeed,ast2500-kcs-bmc";
+reg = <0x0 0x80>;
+interrupts = <8>;
+kcs_chan = <3>;
+kcs_addr = <0xCA2>;
+status = "okay";
+};
+
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..36132f8 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,3 +104,12 @@ config ASPEED_BT_IPMI_BMC
  Provides a driver for the BT (Block Transfer) IPMI interface
  found on Aspeed SOCs (AST2400 and AST2500). The driver
  implements the BMC side of the BT interface.
+
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+   select REGMAP_MMIO
+   tristate "KCS IPMI bmc driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500). The driver
+ implements the BMC side of the KCS interface.
\ No newline at end of file
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..f217bae 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs-bmc.o
\ No newline at end of file
diff --git a/drivers/char/ipmi/kcs-bmc.c b/drivers/char/ipmi/kcs-bmc.c
new file mode 100644
index 000..d6eab0b
--- /dev/null
+++ b/drivers/char/ipmi/kcs-bmc.c
@@ -0,0 +1,744 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define KCS_MSG_BUFSIZ  1024
+#define KCS_CHANNEL_MAX 4
+
+/*
+ * This is a BMC device used to communicate to the host
+ */
+#define DEVICE_NAME "ipmi-kcs-host"
+
+
+/* Different Phases of the KCS Module */
+#define KCS_PHASE_IDLE  0x00
+#define KCS_PHASE_WRITE 0x01
+#define KCS_PHASE_WRITE_END 0x02
+#define KCS_PHASE_READ  0x03
+#define KCS_PHASE_ABORT 0x04
+#define KCS_PHASE_ERROR 0x05
+
+/* Abort Phase */
+#define ABORT_PHASE_ERROR1  0x01
+#define ABORT_PHASE_ERROR2  0x02
+
+/* KCS Command Control codes. */
+#define KCS_GET_STATUS  0x60
+#define KCS_ABORT   0x60
+#define KCS_WRITE_START 0x61
+#define KCS_WRITE_END   0x62
+#define KCS_READ_BYTE   0x68
+
+/* Status bits.:
+ * - IDLE_STATE.  Interface is idle. System software should not be expecting
+ *nor sending any data.
+ * - READ_STATE.  BMC is transferring a packet to system software. System
+ *software should be in the "Read Message" state.
+ * - WRITE_STATE. BMC is receiving a packet from system software. System
+ *software should be writing a command to the BMC.
+ * - ERROR_STATE. BMC has detected a protocol violation at 

[PATCH arm/aspeed/ast2500 v1] ipmi: add an Aspeed KCS IPMI BMC driver

2018-01-16 Thread Haiyue Wang
The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a server host and its BMC (BaseBoard Management
Controllers).

This driver exposes the KCS interface on ASpeed SOCs (AST2400 and AST2500)
as a character device. Such SOCs are commonly used as BMCs and this driver
implements the BMC side of the KCS interface.

Signed-off-by: Haiyue Wang 
---
 .../devicetree/bindings/ipmi/aspeed-kcs-bmc.txt|  26 +
 drivers/char/ipmi/Kconfig  |   9 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs-bmc.c| 744 +
 include/uapi/linux/kcs-bmc.h   |  14 +
 5 files changed, 794 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
 create mode 100644 drivers/char/ipmi/kcs-bmc.c
 create mode 100644 include/uapi/linux/kcs-bmc.h

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
new file mode 100644
index 000..dd0c73d
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
@@ -0,0 +1,26 @@
+* Aspeed KCS (Keyboard Controller Style) IPMI interface
+
+The Aspeed SOCs (AST2400 and AST2500) are commonly used as BMCs
+(BaseBoard Management Controllers) and the KCS interface can be
+used to perform in-band IPMI communication with their host.
+
+Required properties:
+- compatible : should be one of
+"aspeed,ast2400-kcs-bmc"
+"aspeed,ast2500-kcs-bmc"
+- interrupts : interrupt generated by the controller
+- kcs_chan : The LPC channel number in the controller
+- kcs_addr : The host CPU IO map address
+
+
+Example:
+
+kcs3: kcs3@0 {
+compatible = "aspeed,ast2500-kcs-bmc";
+reg = <0x0 0x80>;
+interrupts = <8>;
+kcs_chan = <3>;
+kcs_addr = <0xCA2>;
+status = "okay";
+};
+
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..36132f8 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,3 +104,12 @@ config ASPEED_BT_IPMI_BMC
  Provides a driver for the BT (Block Transfer) IPMI interface
  found on Aspeed SOCs (AST2400 and AST2500). The driver
  implements the BMC side of the BT interface.
+
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+   select REGMAP_MMIO
+   tristate "KCS IPMI bmc driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500). The driver
+ implements the BMC side of the KCS interface.
\ No newline at end of file
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..f217bae 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs-bmc.o
\ No newline at end of file
diff --git a/drivers/char/ipmi/kcs-bmc.c b/drivers/char/ipmi/kcs-bmc.c
new file mode 100644
index 000..d6eab0b
--- /dev/null
+++ b/drivers/char/ipmi/kcs-bmc.c
@@ -0,0 +1,744 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2018, Intel Corporation.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define KCS_MSG_BUFSIZ  1024
+#define KCS_CHANNEL_MAX 4
+
+/*
+ * This is a BMC device used to communicate to the host
+ */
+#define DEVICE_NAME "ipmi-kcs-host"
+
+
+/* Different Phases of the KCS Module */
+#define KCS_PHASE_IDLE  0x00
+#define KCS_PHASE_WRITE 0x01
+#define KCS_PHASE_WRITE_END 0x02
+#define KCS_PHASE_READ  0x03
+#define KCS_PHASE_ABORT 0x04
+#define KCS_PHASE_ERROR 0x05
+
+/* Abort Phase */
+#define ABORT_PHASE_ERROR1  0x01
+#define ABORT_PHASE_ERROR2  0x02
+
+/* KCS Command Control codes. */
+#define KCS_GET_STATUS  0x60
+#define KCS_ABORT   0x60
+#define KCS_WRITE_START 0x61
+#define KCS_WRITE_END   0x62
+#define KCS_READ_BYTE   0x68
+
+/* Status bits.:
+ * - IDLE_STATE.  Interface is idle. System software should not be expecting
+ *nor sending any data.
+ * - READ_STATE.  BMC is transferring a packet to system software. System
+ *software should be in the "Read Message" state.
+ * - WRITE_STATE. BMC is receiving a packet from system software. System
+ *software should be writing a command to the BMC.
+ * - ERROR_STATE. BMC has detected a protocol violation at the interface level,
+ * 

[PATCH v1] eSPI: add Aspeed AST2500 eSPI driver to boot a host with PCH runs on eSPI

2017-12-28 Thread Haiyue Wang
When PCH works under eSPI mode, the PMC (Power Management Controller) in
PCH is waiting for SUS_ACK from BMC after it alerts SUS_WARN. It is in
dead loop if no SUS_ACK assert. This is the basic requirement for the BMC
works as eSPI slave.

Also for the host power on / off actions, from BMC side, the following VW
(Virtual Wire) messages are done in firmware:
1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
2. SUS_ACK
3. OOB_RESET_ACK
4. HOST_RESET_ACK

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 .../devicetree/bindings/misc/aspeed-espi-slave.txt |  20 ++
 Documentation/misc-devices/espi-slave.rst  | 114 +
 drivers/misc/Kconfig   |  11 +
 drivers/misc/Makefile  |   1 +
 drivers/misc/aspeed-espi-slave.c   | 266 +
 5 files changed, 412 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
 create mode 100644 Documentation/misc-devices/espi-slave.rst
 create mode 100644 drivers/misc/aspeed-espi-slave.c

diff --git a/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt 
b/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
new file mode 100644
index 000..35da26f
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
@@ -0,0 +1,20 @@
+Aspeed eSPI Slave Controller
+
+Required properties:
+ - compatible: must be one of:
+   - "aspeed,ast2500-espi-slave"
+
+ - reg: physical base address of the controller and length of memory mapped
+   region
+
+ - interrupts: interrupt generated by the controller
+
+Example:
+
+espi: espi@1e6ee000 {
+compatible = "aspeed,ast2500-espi-slave";
+reg = <0x1e6ee000 0x100>;
+interrupts = <23>;
+status = "disabled";
+};
+
diff --git a/Documentation/misc-devices/espi-slave.rst 
b/Documentation/misc-devices/espi-slave.rst
new file mode 100644
index 000..405b619
--- /dev/null
+++ b/Documentation/misc-devices/espi-slave.rst
@@ -0,0 +1,114 @@
+eSPI Slave
+==
+
+The PCH (**eSPI master**) provides the eSPI to support connection of a
+BMC (**eSPI slave**) to the platform.
+
+The LPC and eSPI interfaces are mutually exclusive. Both use the same
+pins, but on power-up, a HW strap determines if the eSPI or the LPC bus
+is operational. Once selected, it’s not possible to change to the other
+interface.
+
+``eSPI Channels and Supported Transactions``
+ +--+-+--++
+ | CH # | Channel | Posted Cycles| Non-Posted Cycles  |
+ +==+=+==++
+ |  0   | Peripheral  | Memory Write,| Memory Read,   |
+ |  | | Completions  | I/O Read/Write |
+ +--+-+--++
+ |  1   | Virtual Wire| Virtual Wire GET/PUT | N/A|
+ +--+-+--++
+ |  2   | Out-of-Band Message | SMBus Packet GET/PUT | N/A|
+ +--+-+--++
+ |  3   | Flash Access| N/A  | Flash Read, Write, |
+ |  | |  | Erase  |
+ +--+-+--++
+ |  N/A | General | Register Accesses| N/A|
+ +--+-+--++
+
+Virtual Wire Channel (Channel 1) Overview
+-
+
+The Virtual Wire channel uses a standard message format to communicate
+several types of signals between the components on the platform::
+
+ - Sideband and GPIO Pins: System events and other dedicated signals
+   between the PCH and eSPI slave. These signals are tunneled between the
+   two components over eSPI.
+
+ - Serial IRQ Interrupts: Interrupts are tunneled from the eSPI slave to
+   the PCH. Both edge and triggered interrupts are supported.
+
+When PCH runs on eSPI mode, from BMC side, the following VW messages are
+done in firmware::
+
+ 1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
+ 2. SUS_ACK
+ 3. OOB_RESET_ACK
+ 4. HOST_RESET_ACK
+
+``eSPI Virtual Wires (VW)``
+ +--+-+---+
+ |Virtual Wire  |PCH Pin  |Comments   |
+ |  |Direction|   |
+ +==+=+===+
+ |SUS_WARN# |Output   |PCH pin is a GPIO when eSPI is enabled.|
+ |  | |eSPI controller receives as VW message.|
+ +--+-+---+
+ |SUS_ACK#

[PATCH v1] eSPI: add Aspeed AST2500 eSPI driver to boot a host with PCH runs on eSPI

2017-12-28 Thread Haiyue Wang
When PCH works under eSPI mode, the PMC (Power Management Controller) in
PCH is waiting for SUS_ACK from BMC after it alerts SUS_WARN. It is in
dead loop if no SUS_ACK assert. This is the basic requirement for the BMC
works as eSPI slave.

Also for the host power on / off actions, from BMC side, the following VW
(Virtual Wire) messages are done in firmware:
1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
2. SUS_ACK
3. OOB_RESET_ACK
4. HOST_RESET_ACK

Signed-off-by: Haiyue Wang 
---
 .../devicetree/bindings/misc/aspeed-espi-slave.txt |  20 ++
 Documentation/misc-devices/espi-slave.rst  | 114 +
 drivers/misc/Kconfig   |  11 +
 drivers/misc/Makefile  |   1 +
 drivers/misc/aspeed-espi-slave.c   | 266 +
 5 files changed, 412 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
 create mode 100644 Documentation/misc-devices/espi-slave.rst
 create mode 100644 drivers/misc/aspeed-espi-slave.c

diff --git a/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt 
b/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
new file mode 100644
index 000..35da26f
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/aspeed-espi-slave.txt
@@ -0,0 +1,20 @@
+Aspeed eSPI Slave Controller
+
+Required properties:
+ - compatible: must be one of:
+   - "aspeed,ast2500-espi-slave"
+
+ - reg: physical base address of the controller and length of memory mapped
+   region
+
+ - interrupts: interrupt generated by the controller
+
+Example:
+
+espi: espi@1e6ee000 {
+compatible = "aspeed,ast2500-espi-slave";
+reg = <0x1e6ee000 0x100>;
+interrupts = <23>;
+status = "disabled";
+};
+
diff --git a/Documentation/misc-devices/espi-slave.rst 
b/Documentation/misc-devices/espi-slave.rst
new file mode 100644
index 000..405b619
--- /dev/null
+++ b/Documentation/misc-devices/espi-slave.rst
@@ -0,0 +1,114 @@
+eSPI Slave
+==
+
+The PCH (**eSPI master**) provides the eSPI to support connection of a
+BMC (**eSPI slave**) to the platform.
+
+The LPC and eSPI interfaces are mutually exclusive. Both use the same
+pins, but on power-up, a HW strap determines if the eSPI or the LPC bus
+is operational. Once selected, it’s not possible to change to the other
+interface.
+
+``eSPI Channels and Supported Transactions``
+ +--+-+--++
+ | CH # | Channel | Posted Cycles| Non-Posted Cycles  |
+ +==+=+==++
+ |  0   | Peripheral  | Memory Write,| Memory Read,   |
+ |  | | Completions  | I/O Read/Write |
+ +--+-+--++
+ |  1   | Virtual Wire| Virtual Wire GET/PUT | N/A|
+ +--+-+--++
+ |  2   | Out-of-Band Message | SMBus Packet GET/PUT | N/A|
+ +--+-+--++
+ |  3   | Flash Access| N/A  | Flash Read, Write, |
+ |  | |  | Erase  |
+ +--+-+--++
+ |  N/A | General | Register Accesses| N/A|
+ +--+-+--++
+
+Virtual Wire Channel (Channel 1) Overview
+-
+
+The Virtual Wire channel uses a standard message format to communicate
+several types of signals between the components on the platform::
+
+ - Sideband and GPIO Pins: System events and other dedicated signals
+   between the PCH and eSPI slave. These signals are tunneled between the
+   two components over eSPI.
+
+ - Serial IRQ Interrupts: Interrupts are tunneled from the eSPI slave to
+   the PCH. Both edge and triggered interrupts are supported.
+
+When PCH runs on eSPI mode, from BMC side, the following VW messages are
+done in firmware::
+
+ 1. SLAVE_BOOT_LOAD_DONE / SLAVE_BOOT_LOAD_STATUS
+ 2. SUS_ACK
+ 3. OOB_RESET_ACK
+ 4. HOST_RESET_ACK
+
+``eSPI Virtual Wires (VW)``
+ +--+-+---+
+ |Virtual Wire  |PCH Pin  |Comments   |
+ |  |Direction|   |
+ +==+=+===+
+ |SUS_WARN# |Output   |PCH pin is a GPIO when eSPI is enabled.|
+ |  | |eSPI controller receives as VW message.|
+ +--+-+---+
+ |SUS_ACK#  |Input 

RE: [PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI BMC driver

2017-12-15 Thread Haiyue Wang
I can help to maintain this code. :-)

This basic KCS code is running successfully about two years on our boards, 
which uses AST2500 and linux-3.18.
For openbmc project, I kept the KCS function and ported it with linux-4.10 new 
API like bt-bmc.c. It works well
in our board with openbmc project.

- haiyue

-Original Message-
From: Corey Minyard [mailto:tcminy...@gmail.com] On Behalf Of Corey Minyard
Sent: Friday, December 15, 2017 21:06
To: Haiyue Wang <haiyue.w...@linux.intel.com>; 
openipmi-develo...@lists.sourceforge.net; linux-kernel@vger.kernel.org; 'Cédric 
Le Goater' <c...@kaod.org>; 'Jeremy Kerr' <j...@ozlabs.org>; 'Joel Stanley' 
<j...@jms.id.au>; 'Andrew Jeffery' <and...@aj.id.au>
Subject: Re: [PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI BMC driver

On 12/14/2017 09:07 PM, Haiyue Wang wrote:
> Thanks Corey, yes, I ran through checkpatch. Fix most of warnings and 
> errors. I thought 2 and 3 would be acceptable, will fix it in new patch,and 
> together with fix for comments from all of you. And how to fix item 1 ?
>
> 1. WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
> #115:
> new file mode 100644

Are you planning to be maintainer of this code? Does it fall to others in the 
openbmc project?

I technically maintain the files in that directory, but I can't really maintain 
these files.

This comment is asking you to think about that issue.

-corey

> 2. WARNING: Prefer using '"%s...", __func__' to using 'kcs_inb', this 
> function's name, in a string
> #289: FILE: drivers/char/ipmi/kcs-bmc.c:170:
> +   WARN(rc != 0, "kcs_inb failed: %d\n", rc);
>
> 3. WARNING: Prefer using '"%s...", __func__' to using 'kcs_outb', this 
> function's name, in a string
> #299: FILE: drivers/char/ipmi/kcs-bmc.c:180:
> +   WARN(rc != 0, "kcs_outb failed: %d\n", rc);
>
> total: 0 errors, 3 warnings, 836 lines checked
>
>
> -Original Message-
> From: Corey Minyard [mailto:tcminy...@gmail.com] On Behalf Of Corey 
> Minyard
> Sent: Friday, December 15, 2017 10:31
> To: Haiyue Wang <haiyue.w...@linux.intel.com>; 
> openipmi-develo...@lists.sourceforge.net; 
> linux-kernel@vger.kernel.org; Cédric Le Goater <c...@kaod.org>; Jeremy 
> Kerr <j...@ozlabs.org>; Joel Stanley <j...@jms.id.au>; Andrew Jeffery 
> <and...@aj.id.au>
> Subject: Re: [PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI 
> BMC driver
>
> On 12/14/2017 08:03 PM, Haiyue Wang wrote:
>> [based torvalds/linux.git]
>>
>> This patch adds a simple device driver to expose the KCS interface on 
>> Aspeed SOCs (AST2400 and AST2500) as a character device. Such SOCs 
>> are commonly used as BMCs (BaseBoard Management Controllers) and this 
>> driver implements the BMC side of the KCS interface.
>>
>> The KCS (Keyboard Controller Style) interface is used to perform 
>> in-band IPMI communication between a host and its BMC.
>>
>> The device name defaults to '/dev/ipmi-kcsX', X=1,2,3,4.
> Did you run this through checkpatch?  I saw a few things.
>
> I was hoping to see some of the openbmc people comment on this.
>
> -corey
>
>> Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
>> ---
>>.../devicetree/bindings/mfd/aspeed-lpc.txt |  31 +-
>>drivers/char/ipmi/Kconfig  |   9 +
>>drivers/char/ipmi/Makefile |   1 +
>>drivers/char/ipmi/kcs-bmc.c| 759 
>> +
>>include/uapi/linux/kcs-bmc.h   |  13 +
>>5 files changed, 810 insertions(+), 3 deletions(-)
>>create mode 100644 drivers/char/ipmi/kcs-bmc.c
>>create mode 100644 include/uapi/linux/kcs-bmc.h
>>
>> diff --git a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
>> b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
>> index 514d82c..e682000 100644
>> --- a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
>> +++ b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
>> @@ -62,12 +62,24 @@ BMC Node
>>
>>
>>- compatible: One of:
>> -"aspeed,ast2400-lpc-bmc"
>> -"aspeed,ast2500-lpc-bmc"
>> +"aspeed,ast2400-lpc-bmc", "simple-mfd", "syscon"
>> +"aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon"
>>
>>- reg:contains the physical address and length values of the
>>H8S/2168-compatible LPC controller memory region
>>
>> +BMC KCS Node
>> +-

RE: [PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI BMC driver

2017-12-15 Thread Haiyue Wang
I can help to maintain this code. :-)

This basic KCS code is running successfully about two years on our boards, 
which uses AST2500 and linux-3.18.
For openbmc project, I kept the KCS function and ported it with linux-4.10 new 
API like bt-bmc.c. It works well
in our board with openbmc project.

- haiyue

-Original Message-
From: Corey Minyard [mailto:tcminy...@gmail.com] On Behalf Of Corey Minyard
Sent: Friday, December 15, 2017 21:06
To: Haiyue Wang ; 
openipmi-develo...@lists.sourceforge.net; linux-kernel@vger.kernel.org; 'Cédric 
Le Goater' ; 'Jeremy Kerr' ; 'Joel Stanley' 
; 'Andrew Jeffery' 
Subject: Re: [PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI BMC driver

On 12/14/2017 09:07 PM, Haiyue Wang wrote:
> Thanks Corey, yes, I ran through checkpatch. Fix most of warnings and 
> errors. I thought 2 and 3 would be acceptable, will fix it in new patch,and 
> together with fix for comments from all of you. And how to fix item 1 ?
>
> 1. WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
> #115:
> new file mode 100644

Are you planning to be maintainer of this code? Does it fall to others in the 
openbmc project?

I technically maintain the files in that directory, but I can't really maintain 
these files.

This comment is asking you to think about that issue.

-corey

> 2. WARNING: Prefer using '"%s...", __func__' to using 'kcs_inb', this 
> function's name, in a string
> #289: FILE: drivers/char/ipmi/kcs-bmc.c:170:
> +   WARN(rc != 0, "kcs_inb failed: %d\n", rc);
>
> 3. WARNING: Prefer using '"%s...", __func__' to using 'kcs_outb', this 
> function's name, in a string
> #299: FILE: drivers/char/ipmi/kcs-bmc.c:180:
> +   WARN(rc != 0, "kcs_outb failed: %d\n", rc);
>
> total: 0 errors, 3 warnings, 836 lines checked
>
>
> -Original Message-
> From: Corey Minyard [mailto:tcminy...@gmail.com] On Behalf Of Corey 
> Minyard
> Sent: Friday, December 15, 2017 10:31
> To: Haiyue Wang ; 
> openipmi-develo...@lists.sourceforge.net; 
> linux-kernel@vger.kernel.org; Cédric Le Goater ; Jeremy 
> Kerr ; Joel Stanley ; Andrew Jeffery 
> 
> Subject: Re: [PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI 
> BMC driver
>
> On 12/14/2017 08:03 PM, Haiyue Wang wrote:
>> [based torvalds/linux.git]
>>
>> This patch adds a simple device driver to expose the KCS interface on 
>> Aspeed SOCs (AST2400 and AST2500) as a character device. Such SOCs 
>> are commonly used as BMCs (BaseBoard Management Controllers) and this 
>> driver implements the BMC side of the KCS interface.
>>
>> The KCS (Keyboard Controller Style) interface is used to perform 
>> in-band IPMI communication between a host and its BMC.
>>
>> The device name defaults to '/dev/ipmi-kcsX', X=1,2,3,4.
> Did you run this through checkpatch?  I saw a few things.
>
> I was hoping to see some of the openbmc people comment on this.
>
> -corey
>
>> Signed-off-by: Haiyue Wang 
>> ---
>>.../devicetree/bindings/mfd/aspeed-lpc.txt |  31 +-
>>drivers/char/ipmi/Kconfig  |   9 +
>>drivers/char/ipmi/Makefile |   1 +
>>drivers/char/ipmi/kcs-bmc.c| 759 
>> +
>>include/uapi/linux/kcs-bmc.h   |  13 +
>>5 files changed, 810 insertions(+), 3 deletions(-)
>>create mode 100644 drivers/char/ipmi/kcs-bmc.c
>>create mode 100644 include/uapi/linux/kcs-bmc.h
>>
>> diff --git a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
>> b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
>> index 514d82c..e682000 100644
>> --- a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
>> +++ b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
>> @@ -62,12 +62,24 @@ BMC Node
>>
>>
>>- compatible: One of:
>> -"aspeed,ast2400-lpc-bmc"
>> -"aspeed,ast2500-lpc-bmc"
>> +"aspeed,ast2400-lpc-bmc", "simple-mfd", "syscon"
>> +"aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon"
>>
>>- reg:contains the physical address and length values of the
>>H8S/2168-compatible LPC controller memory region
>>
>> +BMC KCS Node
>> +
>> +
>> +- compatible:   One of:
>> +"aspeed,ast2400-kcs-bmc"
>> +"aspeed,ast2500-kcs-bmc"
>> +
>> +- kcs_chan: The LPC channel number
>> +
>> +- kcs_add

[PATCH linux ipmi for BMC v2] ipmi: add an Aspeed KCS IPMI BMC driver

2017-12-14 Thread Haiyue Wang
This patch adds a simple device driver to expose the KCS interface on
Aspeed SOCs (AST2400 and AST2500) as a character device. Such SOCs are
commonly used as BMCs (BaseBoard Management Controllers) and this driver
implements the BMC side of the KCS interface.

The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a host and its BMC.

The device name defaults to '/dev/ipmi-kcsX', X=1,2,3,4.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 .../devicetree/bindings/mfd/aspeed-lpc.txt |  31 +-
 drivers/char/ipmi/Kconfig  |   9 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs-bmc.c| 759 +
 include/uapi/linux/kcs-bmc.h   |  13 +
 5 files changed, 810 insertions(+), 3 deletions(-)
 create mode 100644 drivers/char/ipmi/kcs-bmc.c
 create mode 100644 include/uapi/linux/kcs-bmc.h

diff --git a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt 
b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
index 514d82c..e682000 100644
--- a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
+++ b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
@@ -62,12 +62,24 @@ BMC Node
 
 
 - compatible:  One of:
-   "aspeed,ast2400-lpc-bmc"
-   "aspeed,ast2500-lpc-bmc"
+   "aspeed,ast2400-lpc-bmc", "simple-mfd", "syscon"
+   "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon"
 
 - reg: contains the physical address and length values of the
 H8S/2168-compatible LPC controller memory region
 
+BMC KCS Node
+
+
+- compatible:  One of:
+   "aspeed,ast2400-kcs-bmc"
+   "aspeed,ast2500-kcs-bmc"
+
+- kcs_chan: The LPC channel number
+
+- kcs_addr: The host CPU IO map address
+
+
 Host Node
 -
 
@@ -94,8 +106,21 @@ lpc: lpc@1e789000 {
ranges = <0x0 0x1e789000 0x1000>;
 
lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2500-lpc-bmc";
+   compatible = "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon";
reg = <0x0 0x80>;
+   reg-io-width = <4>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x0 0x80>;
+
+   kcs3: kcs3@0 {
+   compatible = "aspeed,ast2500-kcs-bmc";
+   interrupts = <8>;
+   kcs_chan = <3>;
+   kcs_addr = <0xCA2>;
+   status = "okay";
+   };
};
 
lpc_host: lpc-host@80 {
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..3a9d29b 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,3 +104,12 @@ config ASPEED_BT_IPMI_BMC
  Provides a driver for the BT (Block Transfer) IPMI interface
  found on Aspeed SOCs (AST2400 and AST2500). The driver
  implements the BMC side of the BT interface.
+
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
+   tristate "KCS IPMI bmc driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500). The driver
+ implements the BMC side of the KCS interface.
\ No newline at end of file
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..f217bae 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs-bmc.o
\ No newline at end of file
diff --git a/drivers/char/ipmi/kcs-bmc.c b/drivers/char/ipmi/kcs-bmc.c
new file mode 100644
index 000..256fb00
--- /dev/null
+++ b/drivers/char/ipmi/kcs-bmc.c
@@ -0,0 +1,759 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2017, Intel Corporation.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define KCS_MSG_BUFSIZ  1024
+#define KCS_CHANNEL_MAX 4
+
+/*
+ * This is a BMC device used to communicate to the host
+ */
+#define DEVICE_NAME "ipmi-kcs-host"
+
+
+/* Different Phases of the KCS Module */
+#define KCS_PHASE_IDLE  0x00
+#define KCS_PHASE_WRITE 0x01
+#define KCS_PHASE_WRITE_END 0x02
+#define KCS_PHASE_READ  0x03

[PATCH linux ipmi for BMC v2] ipmi: add an Aspeed KCS IPMI BMC driver

2017-12-14 Thread Haiyue Wang
This patch adds a simple device driver to expose the KCS interface on
Aspeed SOCs (AST2400 and AST2500) as a character device. Such SOCs are
commonly used as BMCs (BaseBoard Management Controllers) and this driver
implements the BMC side of the KCS interface.

The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a host and its BMC.

The device name defaults to '/dev/ipmi-kcsX', X=1,2,3,4.

Signed-off-by: Haiyue Wang 
---
 .../devicetree/bindings/mfd/aspeed-lpc.txt |  31 +-
 drivers/char/ipmi/Kconfig  |   9 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs-bmc.c| 759 +
 include/uapi/linux/kcs-bmc.h   |  13 +
 5 files changed, 810 insertions(+), 3 deletions(-)
 create mode 100644 drivers/char/ipmi/kcs-bmc.c
 create mode 100644 include/uapi/linux/kcs-bmc.h

diff --git a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt 
b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
index 514d82c..e682000 100644
--- a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
+++ b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
@@ -62,12 +62,24 @@ BMC Node
 
 
 - compatible:  One of:
-   "aspeed,ast2400-lpc-bmc"
-   "aspeed,ast2500-lpc-bmc"
+   "aspeed,ast2400-lpc-bmc", "simple-mfd", "syscon"
+   "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon"
 
 - reg: contains the physical address and length values of the
 H8S/2168-compatible LPC controller memory region
 
+BMC KCS Node
+
+
+- compatible:  One of:
+   "aspeed,ast2400-kcs-bmc"
+   "aspeed,ast2500-kcs-bmc"
+
+- kcs_chan: The LPC channel number
+
+- kcs_addr: The host CPU IO map address
+
+
 Host Node
 -
 
@@ -94,8 +106,21 @@ lpc: lpc@1e789000 {
ranges = <0x0 0x1e789000 0x1000>;
 
lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2500-lpc-bmc";
+   compatible = "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon";
reg = <0x0 0x80>;
+   reg-io-width = <4>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x0 0x80>;
+
+   kcs3: kcs3@0 {
+   compatible = "aspeed,ast2500-kcs-bmc";
+   interrupts = <8>;
+   kcs_chan = <3>;
+   kcs_addr = <0xCA2>;
+   status = "okay";
+   };
};
 
lpc_host: lpc-host@80 {
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..3a9d29b 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,3 +104,12 @@ config ASPEED_BT_IPMI_BMC
  Provides a driver for the BT (Block Transfer) IPMI interface
  found on Aspeed SOCs (AST2400 and AST2500). The driver
  implements the BMC side of the BT interface.
+
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
+   tristate "KCS IPMI bmc driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500). The driver
+ implements the BMC side of the KCS interface.
\ No newline at end of file
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..f217bae 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs-bmc.o
\ No newline at end of file
diff --git a/drivers/char/ipmi/kcs-bmc.c b/drivers/char/ipmi/kcs-bmc.c
new file mode 100644
index 000..256fb00
--- /dev/null
+++ b/drivers/char/ipmi/kcs-bmc.c
@@ -0,0 +1,759 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2017, Intel Corporation.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define KCS_MSG_BUFSIZ  1024
+#define KCS_CHANNEL_MAX 4
+
+/*
+ * This is a BMC device used to communicate to the host
+ */
+#define DEVICE_NAME "ipmi-kcs-host"
+
+
+/* Different Phases of the KCS Module */
+#define KCS_PHASE_IDLE  0x00
+#define KCS_PHASE_WRITE 0x01
+#define KCS_PHASE_WRITE_END 0x02
+#define KCS_PHASE_READ  0x03
+#define KCS_PHASE_ABORT 0x04
+#def

RE: [PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI BMC driver

2017-12-14 Thread Haiyue Wang
Thanks Corey, yes, I ran through checkpatch. Fix most of warnings and errors. I 
thought 2 and 3 would be acceptable,
will fix it in new patch,and together with fix for comments from all of you. 
And how to fix item 1 ?

1. WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#115:
new file mode 100644

2. WARNING: Prefer using '"%s...", __func__' to using 'kcs_inb', this 
function's name, in a string
#289: FILE: drivers/char/ipmi/kcs-bmc.c:170:
+   WARN(rc != 0, "kcs_inb failed: %d\n", rc);

3. WARNING: Prefer using '"%s...", __func__' to using 'kcs_outb', this 
function's name, in a string
#299: FILE: drivers/char/ipmi/kcs-bmc.c:180:
+   WARN(rc != 0, "kcs_outb failed: %d\n", rc);

total: 0 errors, 3 warnings, 836 lines checked


-Original Message-
From: Corey Minyard [mailto:tcminy...@gmail.com] On Behalf Of Corey Minyard
Sent: Friday, December 15, 2017 10:31
To: Haiyue Wang <haiyue.w...@linux.intel.com>; 
openipmi-develo...@lists.sourceforge.net; linux-kernel@vger.kernel.org; Cédric 
Le Goater <c...@kaod.org>; Jeremy Kerr <j...@ozlabs.org>; Joel Stanley 
<j...@jms.id.au>; Andrew Jeffery <and...@aj.id.au>
Subject: Re: [PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI BMC driver

On 12/14/2017 08:03 PM, Haiyue Wang wrote:
> [based torvalds/linux.git]
>
> This patch adds a simple device driver to expose the KCS interface on 
> Aspeed SOCs (AST2400 and AST2500) as a character device. Such SOCs are 
> commonly used as BMCs (BaseBoard Management Controllers) and this 
> driver implements the BMC side of the KCS interface.
>
> The KCS (Keyboard Controller Style) interface is used to perform 
> in-band IPMI communication between a host and its BMC.
>
> The device name defaults to '/dev/ipmi-kcsX', X=1,2,3,4.

Did you run this through checkpatch?  I saw a few things.

I was hoping to see some of the openbmc people comment on this.

-corey

> Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
> ---
>   .../devicetree/bindings/mfd/aspeed-lpc.txt |  31 +-
>   drivers/char/ipmi/Kconfig  |   9 +
>   drivers/char/ipmi/Makefile |   1 +
>   drivers/char/ipmi/kcs-bmc.c| 759 
> +
>   include/uapi/linux/kcs-bmc.h   |  13 +
>   5 files changed, 810 insertions(+), 3 deletions(-)
>   create mode 100644 drivers/char/ipmi/kcs-bmc.c
>   create mode 100644 include/uapi/linux/kcs-bmc.h
>
> diff --git a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt 
> b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
> index 514d82c..e682000 100644
> --- a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
> +++ b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
> @@ -62,12 +62,24 @@ BMC Node
>   
>   
>   - compatible:   One of:
> - "aspeed,ast2400-lpc-bmc"
> - "aspeed,ast2500-lpc-bmc"
> + "aspeed,ast2400-lpc-bmc", "simple-mfd", "syscon"
> + "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon"
>   
>   - reg:  contains the physical address and length values of the
>   H8S/2168-compatible LPC controller memory region
>   
> +BMC KCS Node
> +
> +
> +- compatible:One of:
> + "aspeed,ast2400-kcs-bmc"
> + "aspeed,ast2500-kcs-bmc"
> +
> +- kcs_chan: The LPC channel number
> +
> +- kcs_addr: The host CPU IO map address
> +
> +
>   Host Node
>   -
>   
> @@ -94,8 +106,21 @@ lpc: lpc@1e789000 {
>   ranges = <0x0 0x1e789000 0x1000>;
>   
>   lpc_bmc: lpc-bmc@0 {
> - compatible = "aspeed,ast2500-lpc-bmc";
> + compatible = "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon";
>   reg = <0x0 0x80>;
> + reg-io-width = <4>;
> +
> + #address-cells = <1>;
> + #size-cells = <1>;
> + ranges = <0x0 0x0 0x80>;
> +
> + kcs3: kcs3@0 {
> + compatible = "aspeed,ast2500-kcs-bmc";
> + interrupts = <8>;
> + kcs_chan = <3>;
> + kcs_addr = <0xCA2>;
> + status = "okay";
> + };
>   };
>   
>   lpc_host: lpc-host@80 {
> diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig 
> index 3544abc..3a9d29b 100644
> --- a/drivers/char/ipmi/Kconfig
> +++ b/drivers/char/ipmi/Kconfig
> @@ -104,3 +104,12 @@ con

RE: [PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI BMC driver

2017-12-14 Thread Haiyue Wang
Thanks Corey, yes, I ran through checkpatch. Fix most of warnings and errors. I 
thought 2 and 3 would be acceptable,
will fix it in new patch,and together with fix for comments from all of you. 
And how to fix item 1 ?

1. WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#115:
new file mode 100644

2. WARNING: Prefer using '"%s...", __func__' to using 'kcs_inb', this 
function's name, in a string
#289: FILE: drivers/char/ipmi/kcs-bmc.c:170:
+   WARN(rc != 0, "kcs_inb failed: %d\n", rc);

3. WARNING: Prefer using '"%s...", __func__' to using 'kcs_outb', this 
function's name, in a string
#299: FILE: drivers/char/ipmi/kcs-bmc.c:180:
+   WARN(rc != 0, "kcs_outb failed: %d\n", rc);

total: 0 errors, 3 warnings, 836 lines checked


-Original Message-
From: Corey Minyard [mailto:tcminy...@gmail.com] On Behalf Of Corey Minyard
Sent: Friday, December 15, 2017 10:31
To: Haiyue Wang ; 
openipmi-develo...@lists.sourceforge.net; linux-kernel@vger.kernel.org; Cédric 
Le Goater ; Jeremy Kerr ; Joel Stanley 
; Andrew Jeffery 
Subject: Re: [PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI BMC driver

On 12/14/2017 08:03 PM, Haiyue Wang wrote:
> [based torvalds/linux.git]
>
> This patch adds a simple device driver to expose the KCS interface on 
> Aspeed SOCs (AST2400 and AST2500) as a character device. Such SOCs are 
> commonly used as BMCs (BaseBoard Management Controllers) and this 
> driver implements the BMC side of the KCS interface.
>
> The KCS (Keyboard Controller Style) interface is used to perform 
> in-band IPMI communication between a host and its BMC.
>
> The device name defaults to '/dev/ipmi-kcsX', X=1,2,3,4.

Did you run this through checkpatch?  I saw a few things.

I was hoping to see some of the openbmc people comment on this.

-corey

> Signed-off-by: Haiyue Wang 
> ---
>   .../devicetree/bindings/mfd/aspeed-lpc.txt |  31 +-
>   drivers/char/ipmi/Kconfig  |   9 +
>   drivers/char/ipmi/Makefile |   1 +
>   drivers/char/ipmi/kcs-bmc.c| 759 
> +
>   include/uapi/linux/kcs-bmc.h   |  13 +
>   5 files changed, 810 insertions(+), 3 deletions(-)
>   create mode 100644 drivers/char/ipmi/kcs-bmc.c
>   create mode 100644 include/uapi/linux/kcs-bmc.h
>
> diff --git a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt 
> b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
> index 514d82c..e682000 100644
> --- a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
> +++ b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
> @@ -62,12 +62,24 @@ BMC Node
>   
>   
>   - compatible:   One of:
> - "aspeed,ast2400-lpc-bmc"
> - "aspeed,ast2500-lpc-bmc"
> + "aspeed,ast2400-lpc-bmc", "simple-mfd", "syscon"
> + "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon"
>   
>   - reg:  contains the physical address and length values of the
>   H8S/2168-compatible LPC controller memory region
>   
> +BMC KCS Node
> +
> +
> +- compatible:One of:
> + "aspeed,ast2400-kcs-bmc"
> + "aspeed,ast2500-kcs-bmc"
> +
> +- kcs_chan: The LPC channel number
> +
> +- kcs_addr: The host CPU IO map address
> +
> +
>   Host Node
>   -
>   
> @@ -94,8 +106,21 @@ lpc: lpc@1e789000 {
>   ranges = <0x0 0x1e789000 0x1000>;
>   
>   lpc_bmc: lpc-bmc@0 {
> - compatible = "aspeed,ast2500-lpc-bmc";
> + compatible = "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon";
>   reg = <0x0 0x80>;
> + reg-io-width = <4>;
> +
> + #address-cells = <1>;
> + #size-cells = <1>;
> + ranges = <0x0 0x0 0x80>;
> +
> + kcs3: kcs3@0 {
> + compatible = "aspeed,ast2500-kcs-bmc";
> + interrupts = <8>;
> + kcs_chan = <3>;
> + kcs_addr = <0xCA2>;
> + status = "okay";
> + };
>   };
>   
>   lpc_host: lpc-host@80 {
> diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig 
> index 3544abc..3a9d29b 100644
> --- a/drivers/char/ipmi/Kconfig
> +++ b/drivers/char/ipmi/Kconfig
> @@ -104,3 +104,12 @@ config ASPEED_BT_IPMI_BMC
> Provides a driver for the BT (Block Transfer) IPMI interface
> found on Aspeed SOCs (AST2400 and AST2500). The drive

[PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI BMC driver

2017-12-14 Thread Haiyue Wang
[based torvalds/linux.git]

This patch adds a simple device driver to expose the KCS interface on
Aspeed SOCs (AST2400 and AST2500) as a character device. Such SOCs are
commonly used as BMCs (BaseBoard Management Controllers) and this driver
implements the BMC side of the KCS interface.

The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a host and its BMC.

The device name defaults to '/dev/ipmi-kcsX', X=1,2,3,4.

Signed-off-by: Haiyue Wang <haiyue.w...@linux.intel.com>
---
 .../devicetree/bindings/mfd/aspeed-lpc.txt |  31 +-
 drivers/char/ipmi/Kconfig  |   9 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs-bmc.c| 759 +
 include/uapi/linux/kcs-bmc.h   |  13 +
 5 files changed, 810 insertions(+), 3 deletions(-)
 create mode 100644 drivers/char/ipmi/kcs-bmc.c
 create mode 100644 include/uapi/linux/kcs-bmc.h

diff --git a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt 
b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
index 514d82c..e682000 100644
--- a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
+++ b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
@@ -62,12 +62,24 @@ BMC Node
 
 
 - compatible:  One of:
-   "aspeed,ast2400-lpc-bmc"
-   "aspeed,ast2500-lpc-bmc"
+   "aspeed,ast2400-lpc-bmc", "simple-mfd", "syscon"
+   "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon"
 
 - reg: contains the physical address and length values of the
 H8S/2168-compatible LPC controller memory region
 
+BMC KCS Node
+
+
+- compatible:  One of:
+   "aspeed,ast2400-kcs-bmc"
+   "aspeed,ast2500-kcs-bmc"
+
+- kcs_chan: The LPC channel number
+
+- kcs_addr: The host CPU IO map address
+
+
 Host Node
 -
 
@@ -94,8 +106,21 @@ lpc: lpc@1e789000 {
ranges = <0x0 0x1e789000 0x1000>;
 
lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2500-lpc-bmc";
+   compatible = "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon";
reg = <0x0 0x80>;
+   reg-io-width = <4>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x0 0x80>;
+
+   kcs3: kcs3@0 {
+   compatible = "aspeed,ast2500-kcs-bmc";
+   interrupts = <8>;
+   kcs_chan = <3>;
+   kcs_addr = <0xCA2>;
+   status = "okay";
+   };
};
 
lpc_host: lpc-host@80 {
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..3a9d29b 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,3 +104,12 @@ config ASPEED_BT_IPMI_BMC
  Provides a driver for the BT (Block Transfer) IPMI interface
  found on Aspeed SOCs (AST2400 and AST2500). The driver
  implements the BMC side of the BT interface.
+
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
+   tristate "KCS IPMI bmc driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500). The driver
+ implements the BMC side of the KCS interface.
\ No newline at end of file
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..f217bae 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs-bmc.o
\ No newline at end of file
diff --git a/drivers/char/ipmi/kcs-bmc.c b/drivers/char/ipmi/kcs-bmc.c
new file mode 100644
index 000..bcbd2d6
--- /dev/null
+++ b/drivers/char/ipmi/kcs-bmc.c
@@ -0,0 +1,759 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2017, Intel Corporation.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define KCS_MSG_BUFSIZ  1024
+#define KCS_CHANNEL_MAX 4
+
+/*
+ * This is a BMC device used to communicate to the host
+ */
+#define DEVICE_NAME "ipmi-kcs-host"
+
+
+/* Different Phases of the KCS Module */
+#define KCS_PHASE_IDLE  0x00
+#define KCS_PHASE_WRITE 0x01
+#define KCS_PHASE_WRITE_END 0x02
+#define KCS_P

[PATCH linux ipmi for BMC] ipmi: add an Aspeed KCS IPMI BMC driver

2017-12-14 Thread Haiyue Wang
[based torvalds/linux.git]

This patch adds a simple device driver to expose the KCS interface on
Aspeed SOCs (AST2400 and AST2500) as a character device. Such SOCs are
commonly used as BMCs (BaseBoard Management Controllers) and this driver
implements the BMC side of the KCS interface.

The KCS (Keyboard Controller Style) interface is used to perform in-band
IPMI communication between a host and its BMC.

The device name defaults to '/dev/ipmi-kcsX', X=1,2,3,4.

Signed-off-by: Haiyue Wang 
---
 .../devicetree/bindings/mfd/aspeed-lpc.txt |  31 +-
 drivers/char/ipmi/Kconfig  |   9 +
 drivers/char/ipmi/Makefile |   1 +
 drivers/char/ipmi/kcs-bmc.c| 759 +
 include/uapi/linux/kcs-bmc.h   |  13 +
 5 files changed, 810 insertions(+), 3 deletions(-)
 create mode 100644 drivers/char/ipmi/kcs-bmc.c
 create mode 100644 include/uapi/linux/kcs-bmc.h

diff --git a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt 
b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
index 514d82c..e682000 100644
--- a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
+++ b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
@@ -62,12 +62,24 @@ BMC Node
 
 
 - compatible:  One of:
-   "aspeed,ast2400-lpc-bmc"
-   "aspeed,ast2500-lpc-bmc"
+   "aspeed,ast2400-lpc-bmc", "simple-mfd", "syscon"
+   "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon"
 
 - reg: contains the physical address and length values of the
 H8S/2168-compatible LPC controller memory region
 
+BMC KCS Node
+
+
+- compatible:  One of:
+   "aspeed,ast2400-kcs-bmc"
+   "aspeed,ast2500-kcs-bmc"
+
+- kcs_chan: The LPC channel number
+
+- kcs_addr: The host CPU IO map address
+
+
 Host Node
 -
 
@@ -94,8 +106,21 @@ lpc: lpc@1e789000 {
ranges = <0x0 0x1e789000 0x1000>;
 
lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2500-lpc-bmc";
+   compatible = "aspeed,ast2500-lpc-bmc", "simple-mfd", "syscon";
reg = <0x0 0x80>;
+   reg-io-width = <4>;
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x0 0x80>;
+
+   kcs3: kcs3@0 {
+   compatible = "aspeed,ast2500-kcs-bmc";
+   interrupts = <8>;
+   kcs_chan = <3>;
+   kcs_addr = <0xCA2>;
+   status = "okay";
+   };
};
 
lpc_host: lpc-host@80 {
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 3544abc..3a9d29b 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -104,3 +104,12 @@ config ASPEED_BT_IPMI_BMC
  Provides a driver for the BT (Block Transfer) IPMI interface
  found on Aspeed SOCs (AST2400 and AST2500). The driver
  implements the BMC side of the BT interface.
+
+config ASPEED_KCS_IPMI_BMC
+   depends on ARCH_ASPEED || COMPILE_TEST
+depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
+   tristate "KCS IPMI bmc driver"
+   help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on Aspeed SOCs (AST2400 and AST2500). The driver
+ implements the BMC side of the KCS interface.
\ No newline at end of file
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 33b899f..f217bae 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
+obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs-bmc.o
\ No newline at end of file
diff --git a/drivers/char/ipmi/kcs-bmc.c b/drivers/char/ipmi/kcs-bmc.c
new file mode 100644
index 000..bcbd2d6
--- /dev/null
+++ b/drivers/char/ipmi/kcs-bmc.c
@@ -0,0 +1,759 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2015-2017, Intel Corporation.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define KCS_MSG_BUFSIZ  1024
+#define KCS_CHANNEL_MAX 4
+
+/*
+ * This is a BMC device used to communicate to the host
+ */
+#define DEVICE_NAME "ipmi-kcs-host"
+
+
+/* Different Phases of the KCS Module */
+#define KCS_PHASE_IDLE  0x00
+#define KCS_PHASE_WRITE 0x01
+#define KCS_PHASE_WRITE_END 0x02
+#define KCS_PHASE_READ  0x03
+#define KCS_PH